P
Prismaโ€ข3mo ago
Sabin Adams

Pulse Type

Is there a good way to get the type of a Prisma Client instance with Pulse before instantiating it? For context, I have a class that will eventually have a member populated with a Pulse DB instance:
@Module({})
export class VendorModule implements OnModuleInit {
private pulse: typeof pulseType;
constructor(@Inject('PRISMA') private prisma: PrismaClient) {}

async onModuleInit() {
this.pulse = this.prisma.$extends(
withPulse({
apiKey: process.env.PULSE_API_KEY,
}),
);
await this.setupListeners();
}

private async setupListeners() {
this.pulse.user.stream(/*...*/);
}
}
@Module({})
export class VendorModule implements OnModuleInit {
private pulse: typeof pulseType;
constructor(@Inject('PRISMA') private prisma: PrismaClient) {}

async onModuleInit() {
this.pulse = this.prisma.$extends(
withPulse({
apiKey: process.env.PULSE_API_KEY,
}),
);
await this.setupListeners();
}

private async setupListeners() {
this.pulse.user.stream(/*...*/);
}
}
10 Replies
Sabin Adams
Sabin AdamsOPโ€ข3mo ago
Currently I'm doing this to get that type but am not sure if this is a good way to do it:
const pulseType = new PrismaClient().$extends(withPulse({ apiKey: 'random-string' }));
const pulseType = new PrismaClient().$extends(withPulse({ apiKey: 'random-string' }));
Nurul
Nurulโ€ข3mo ago
Hey @Sabin Adams ๐Ÿ‘‹ Hope you are doing great! ๐Ÿ™‚ Your approach looks good. I am not aware of any other way. An alternative you may consider is doing something like:
// Function to get the extended client type
const getExtendedClientType = () => {
return new PrismaClient().$extends(
withPulse({
apiKey: process.env.PULSE_API_KEY,
})
);
};

// Type of the extended client
type ExtendedPrismaClient = ReturnType<typeof getExtendedClientType>;
// Function to get the extended client type
const getExtendedClientType = () => {
return new PrismaClient().$extends(
withPulse({
apiKey: process.env.PULSE_API_KEY,
})
);
};

// Type of the extended client
type ExtendedPrismaClient = ReturnType<typeof getExtendedClientType>;
Sabin Adams
Sabin AdamsOPโ€ข3mo ago
Thanks!
Tyler Benfield
Tyler Benfieldโ€ข3mo ago
The ReturnType approach is my go-to for getting the type of any extended Prisma Client. Let us know what you think of Pulse ๐Ÿ˜‰
Sabin Adams
Sabin AdamsOPโ€ข3mo ago
Thanks! Itโ€™s powering my dbchange service that keeps the db and Algolia in sync ๐Ÿ˜ No problems so far other than spending a bunch of time with different dbโ€™s trying to get it to work with pulse. A lot of the docs and integrations seemed out of date Finally got it working with Supabase (not sure how, just started working ๐Ÿคท๐Ÿป)
Tyler Benfield
Tyler Benfieldโ€ข3mo ago
A lot of the docs and integrations seemed out of date
Prisma docs or database vendor docs?
Sabin Adams
Sabin AdamsOPโ€ข3mo ago
Prisma docs
Ankur Datta
Ankur Dattaโ€ข3mo ago
Hey @Sabin Adams ๐Ÿ‘‹๐Ÿพ , hope you're doing well ๐Ÿ˜ƒ !
A lot of the docs and integrations seemed out of date
Could you share which part of the docs did you find out to be outdated ๐Ÿ™๐Ÿพ ?
Sabin Adams
Sabin AdamsOPโ€ข3mo ago
Mostly the integration docs for Pulse. Specifically for Neon and Railway. The Railway integration doesnโ€™t run (unless I goofed) and the Neon UI is different from whatโ€™s shown in the docs I can give more specifics when Iโ€™m at a computer ๐Ÿ˜… For the record, once I got things working itโ€™s been seamless :heart:
Ankur Datta
Ankur Dattaโ€ข3mo ago
Thanks @Sabin Adams !
Want results from more Discord servers?
Add your server