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 Adams2mo 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
Nurul2mo 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 Adams2mo ago
Thanks!
Tyler Benfield
Tyler Benfield2mo 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 Adams4w 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
A lot of the docs and integrations seemed out of date
Prisma docs or database vendor docs?
Sabin Adams
Sabin Adams4w ago
Prisma docs
Ankur Datta
Ankur Datta4w 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 Adams4w 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 Datta4w ago
Thanks @Sabin Adams !
Want results from more Discord servers?
Add your server