Installations
npm install prisma-client-lib-hooks
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
10.16.0
NPM Version
6.9.0
Score
57.8
Supply Chain
93
Quality
71
Maintenance
50
Vulnerability
98.2
License
Releases
Unable to fetch releases
Love this project? Help keep it running — sponsor us today! 🚀
Download Statistics
Total Downloads
2,087
Last Day
1
Last Week
2
Last Month
16
Last Year
100
Bundle Size
8.49 kB
Minified
2.36 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.0.6
Package Id
prisma-client-lib-hooks@0.0.6
Unpacked Size
50.72 kB
Size
9.44 kB
File Count
21
NPM Version
6.9.0
Node Version
10.16.0
Total Downloads
Cumulative downloads
Total Downloads
2,087
Last Day
0%
1
Compared to previous day
Last Week
-33.3%
2
Compared to previous week
Last Month
166.7%
16
Compared to previous month
Last Year
-51%
100
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Dev Dependencies
3
Prisma Client Lib Hooks
This package is to add hook functionality to prisma-client-lib package.
IMPORTANT: Prisma Photon will have these capabilities built in, but until it's a full release I ended up creating this for myself.
I built this package mainly for synchronization. I prefer to keep any validations, permission or query variable changes specific to a graphql resolver. This allows me to see the uni-direction of the data. The main purpose was if a model is used throughout the app and the CUD operation might come from multiple places. Primary use case is synchronization with other datasources.
Installation
1$ npm install prisma-client-lib prisma-client-lib-hooks
Context
Context that gets passed has the model name, and the parsed ending of the crud operation so that you can concatenate it with another method if needed
1export interface BaseCtx<T extends string> { 2 modelName: T; 3 modelNameFnEnding: string; 4}
Other Info
The create method didn't have a before because I cannot get the id prior to the operation.
Examples
Take a look at ./examples/src/hooks
Example of hook:
1// hook.ts 2import { prisma } from "../generated/prisma-client"; 3import { Hook, BaseCtx } from "../../../"; 4 5interface Ctx extends BaseCtx<string> { 6 addToContext: boolean; 7} 8 9export class ExampleHook extends Hook { 10 models: { [k: string]: boolean } = { 11 Post: true, 12 }; 13 createAfter = async (ids: string[], ctx: Ctx) => { 14 // do something here 15 }; 16 deleteBefore = async (ids: string[], ctx: Ctx) => { 17 // do something here 18 ctx.addToContext = true; 19 }; 20 21 deleteAfter = async (ids: string[], ctx: Ctx) => { 22 // do something here 23 console.log(ctx.addToContext); 24 // result: true; 25 // ctx state is passed per hook, per CUD 26 }; 27 updateAfter = async (ids: string[], ctx: Ctx) => { 28 /* 29 you should use the original initiated prisma that 30 was generated for doing CRUD actions inside of hooks, 31 this will prevent circular function calls and keep 32 it unidirectional 33 */ 34 if (ctx.modelName === 'User') { 35 await prisma.deleteManyPosts({}) 36 } 37 }; 38 updateBefore = async (ids: string[], ctx: Ctx) => { 39 // do something here 40 }; 41} 42}
Example of initiating prisma with hooks:
1// index.ts 2import { ExampleHook } from './hook' 3import { Prisma, models, ClientConstructor } from "../generated/prisma-client/index"; 4import { typeDefs } from "../generated/prisma-client/prisma-schema"; 5 6import { makePrismaClientClass } from "../../../"; 7 8 9export const HookedPrisma = makePrismaClientClass<ClientConstructor<Prisma>>({ 10 typeDefs, 11 models, 12 endpoint: `${process.env["PRISMA_ENDPOINT"]}`, 13 hooks: [new ExampleHook()] 14}); 15export const hookedPrisma = new HookedPrisma(); 16

No vulnerabilities found.

No security vulnerabilities found.