prisma-generator-express 1.14.3 → 1.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +17 -7
  2. package/dist/generator.js +5 -0
  3. package/dist/generator.js.map +1 -1
  4. package/dist/helpers/generateAggregate.js +4 -9
  5. package/dist/helpers/generateAggregate.js.map +1 -1
  6. package/dist/helpers/generateCount.js +4 -9
  7. package/dist/helpers/generateCount.js.map +1 -1
  8. package/dist/helpers/generateCreate.js +4 -9
  9. package/dist/helpers/generateCreate.js.map +1 -1
  10. package/dist/helpers/generateCreateMany.js +4 -9
  11. package/dist/helpers/generateCreateMany.js.map +1 -1
  12. package/dist/helpers/generateDelete.js +4 -9
  13. package/dist/helpers/generateDelete.js.map +1 -1
  14. package/dist/helpers/generateDeleteMany.js +4 -9
  15. package/dist/helpers/generateDeleteMany.js.map +1 -1
  16. package/dist/helpers/generateFindFirst.js +4 -9
  17. package/dist/helpers/generateFindFirst.js.map +1 -1
  18. package/dist/helpers/generateFindMany.js +4 -9
  19. package/dist/helpers/generateFindMany.js.map +1 -1
  20. package/dist/helpers/generateFindUnique.js +4 -9
  21. package/dist/helpers/generateFindUnique.js.map +1 -1
  22. package/dist/helpers/generateGroupBy.js +4 -9
  23. package/dist/helpers/generateGroupBy.js.map +1 -1
  24. package/dist/helpers/generateRouteFile.js +30 -34
  25. package/dist/helpers/generateRouteFile.js.map +1 -1
  26. package/dist/helpers/generateUpdate.js +4 -9
  27. package/dist/helpers/generateUpdate.js.map +1 -1
  28. package/dist/helpers/generateUpdateMany.js +4 -9
  29. package/dist/helpers/generateUpdateMany.js.map +1 -1
  30. package/dist/helpers/generateUpsert.js +4 -9
  31. package/dist/helpers/generateUpsert.js.map +1 -1
  32. package/dist/utils/strings.js +3 -3
  33. package/dist/utils/strings.js.map +1 -1
  34. package/package.json +7 -7
  35. package/src/generator.ts +10 -0
  36. package/src/helpers/generateAggregate.ts +5 -10
  37. package/src/helpers/generateCount.ts +5 -10
  38. package/src/helpers/generateCreate.ts +5 -10
  39. package/src/helpers/generateCreateMany.ts +5 -10
  40. package/src/helpers/generateDelete.ts +5 -10
  41. package/src/helpers/generateDeleteMany.ts +5 -10
  42. package/src/helpers/generateFindFirst.ts +5 -10
  43. package/src/helpers/generateFindMany.ts +5 -10
  44. package/src/helpers/generateFindUnique.ts +5 -10
  45. package/src/helpers/generateGroupBy.ts +5 -10
  46. package/src/helpers/generateRouteFile.ts +30 -34
  47. package/src/helpers/generateUpdate.ts +5 -10
  48. package/src/helpers/generateUpdateMany.ts +5 -10
  49. package/src/helpers/generateUpsert.ts +5 -10
  50. package/src/utils/strings.ts +1 -1
@@ -5,10 +5,7 @@ function generateRouterFunction({ model, }) {
5
5
  const modelName = model.name;
6
6
  const routerFunctionName = `${modelName}Router`;
7
7
  return `import express, {
8
- NextFunction,
9
- RequestHandler,
10
- Request,
11
- Response,
8
+ RequestHandler
12
9
  } from 'express'
13
10
  import { ParsedQs } from 'qs'
14
11
  import { ${modelName}FindFirst } from './${modelName}FindFirst';
@@ -24,16 +21,15 @@ import { ${modelName}DeleteMany } from './${modelName}DeleteMany';
24
21
  import { ${modelName}Aggregate } from './${modelName}Aggregate';
25
22
  import { ${modelName}Count } from './${modelName}Count';
26
23
  import { ${modelName}GroupBy } from './${modelName}GroupBy';
27
- import { createValidatorMiddleware, ValidatorOptions } from '../createValidatorMiddleware'
28
- import { createOutputValidatorMiddleware } from '../createOutputValidatorMiddleware'
24
+ import { createValidatorMiddleware } from '../createValidatorMiddleware'
29
25
  import { RouteConfig, ValidatorConfig } from '../routeConfig'
30
26
  import { parseQueryParams } from "../parseQueryParams";
31
27
 
32
28
  const defaultBeforeAfter = {
33
29
  before: [] as RequestHandler[],
34
30
  after: [] as RequestHandler[],
35
- input: undefined,
36
- output: undefined,
31
+ inputValidator: undefined,
32
+ outputValidator: undefined,
37
33
  };
38
34
 
39
35
  /**
@@ -85,104 +81,104 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
85
81
 
86
82
 
87
83
  if (config.enableAll || config?.findFirst) {
88
- const { before = [], after = [], input, output } = config.findFirst || defaultBeforeAfter;
89
- setupRoute('/first', 'get', before, ${modelName}FindFirst as RequestHandler, input, output);
84
+ const { before = [], after = [], inputValidator, outputValidator) = config.findFirst || defaultBeforeAfter;
85
+ setupRoute('/first', 'get', before, ${modelName}FindFirst as RequestHandler, inputValidator, outputValidator);
90
86
  if (after.length) {
91
87
  router.use(basePath + '/first', ...after);
92
88
  }
93
89
  }
94
90
 
95
91
  if (config.enableAll || config?.findMany) {
96
- const { before = [], after = [], input, output } = config.findMany || defaultBeforeAfter;
97
- setupRoute('/', 'get', before, ${modelName}FindMany as RequestHandler, input, output);
92
+ const { before = [], after = [], inputValidator, outputValidator) = config.findMany || defaultBeforeAfter;
93
+ setupRoute('/', 'get', before, ${modelName}FindMany as RequestHandler, inputValidator, outputValidator);
98
94
  if (after.length) {
99
95
  router.use(basePath + '/', ...after);
100
96
  }
101
97
  }
102
98
 
103
99
  if (config.enableAll || config?.findUnique) {
104
- const { before = [], after = [], input, output } = config.findUnique || defaultBeforeAfter;
105
- setupRoute('/:id', 'get', before, ${modelName}FindUnique as any, input, output);
100
+ const { before = [], after = [], inputValidator, outputValidator) = config.findUnique || defaultBeforeAfter;
101
+ setupRoute('/:id', 'get', before, ${modelName}FindUnique as any, inputValidator, outputValidator);
106
102
  if (after.length) {
107
103
  router.use(basePath + '/:id', ...after);
108
104
  }
109
105
  }
110
106
 
111
107
  if (config.enableAll || config?.create) {
112
- const { before = [], after = [], input, output } = config.create || defaultBeforeAfter;
113
- setupRoute('/', 'post', before, ${modelName}Create as RequestHandler, input, output);
108
+ const { before = [], after = [], inputValidator, outputValidator) = config.create || defaultBeforeAfter;
109
+ setupRoute('/', 'post', before, ${modelName}Create as RequestHandler, inputValidator, outputValidator);
114
110
  if (after.length) {
115
111
  router.use(basePath + '/', ...after);
116
112
  }
117
113
  }
118
114
 
119
115
  if (config.enableAll || config?.createMany) {
120
- const { before = [], after = [], input, output } = config.createMany || defaultBeforeAfter;
121
- setupRoute('/many', 'post', before, ${modelName}CreateMany as RequestHandler, input, output);
116
+ const { before = [], after = [], inputValidator, outputValidator) = config.createMany || defaultBeforeAfter;
117
+ setupRoute('/many', 'post', before, ${modelName}CreateMany as RequestHandler, inputValidator, outputValidator);
122
118
  if (after.length) {
123
119
  router.use(basePath + '/many', ...after);
124
120
  }
125
121
  }
126
122
 
127
123
  if (config.enableAll || config?.update) {
128
- const { before = [], after = [], input, output } = config.update || defaultBeforeAfter;
129
- setupRoute('/', 'put', before, ${modelName}Update as RequestHandler, input, output);
124
+ const { before = [], after = [], inputValidator, outputValidator) = config.update || defaultBeforeAfter;
125
+ setupRoute('/', 'put', before, ${modelName}Update as RequestHandler, inputValidator, outputValidator);
130
126
  if (after.length) {
131
127
  router.use(basePath + '/', ...after);
132
128
  }
133
129
  }
134
130
 
135
131
  if (config.enableAll || config?.updateMany) {
136
- const { before = [], after = [], input, output } = config.updateMany || defaultBeforeAfter;
137
- setupRoute('/many', 'put', before, ${modelName}UpdateMany as RequestHandler, input, output);
132
+ const { before = [], after = [], inputValidator, outputValidator) = config.updateMany || defaultBeforeAfter;
133
+ setupRoute('/many', 'put', before, ${modelName}UpdateMany as RequestHandler, inputValidator, outputValidator);
138
134
  if (after.length) {
139
135
  router.use(basePath + '/many', ...after);
140
136
  }
141
137
  }
142
138
 
143
139
  if (config.enableAll || config?.upsert) {
144
- const { before = [], after = [], input, output } = config.upsert || defaultBeforeAfter;
145
- setupRoute('/', 'patch', before, ${modelName}Upsert as RequestHandler, input, output);
140
+ const { before = [], after = [], inputValidator, outputValidator) = config.upsert || defaultBeforeAfter;
141
+ setupRoute('/', 'patch', before, ${modelName}Upsert as RequestHandler, inputValidator, outputValidator);
146
142
  if (after.length) {
147
143
  router.use(basePath + '/', ...after);
148
144
  }
149
145
  }
150
146
 
151
147
  if (config.enableAll || config?.delete) {
152
- const { before = [], after = [], input, output } = config.delete || defaultBeforeAfter;
153
- setupRoute('/', 'delete', before, ${modelName}Delete as RequestHandler, input, output);
148
+ const { before = [], after = [], inputValidator, outputValidator) = config.delete || defaultBeforeAfter;
149
+ setupRoute('/', 'delete', before, ${modelName}Delete as RequestHandler, inputValidator, outputValidator);
154
150
  if (after.length) {
155
151
  router.use(basePath + '/', ...after);
156
152
  }
157
153
  }
158
154
 
159
155
  if (config.enableAll || config?.deleteMany) {
160
- const { before = [], after = [], input, output } = config.deleteMany || defaultBeforeAfter;
161
- setupRoute('/many', 'delete', before, ${modelName}DeleteMany as RequestHandler, input, output);
156
+ const { before = [], after = [], inputValidator, outputValidator) = config.deleteMany || defaultBeforeAfter;
157
+ setupRoute('/many', 'delete', before, ${modelName}DeleteMany as RequestHandler, inputValidator, outputValidator);
162
158
  if (after.length) {
163
159
  router.use(basePath + '/many', ...after);
164
160
  }
165
161
  }
166
162
 
167
163
  if (config.enableAll || config?.aggregate) {
168
- const { before = [], after = [], input, output } = config.aggregate || defaultBeforeAfter;
169
- setupRoute('/aggregate', 'get', before, ${modelName}Aggregate as RequestHandler, input, output);
164
+ const { before = [], after = [], inputValidator, outputValidator) = config.aggregate || defaultBeforeAfter;
165
+ setupRoute('/aggregate', 'get', before, ${modelName}Aggregate as RequestHandler, inputValidator, outputValidator);
170
166
  if (after.length) {
171
167
  router.use(basePath + '/aggregate', ...after);
172
168
  }
173
169
  }
174
170
 
175
171
  if (config.enableAll || config?.count) {
176
- const { before = [], after = [], input, output } = config.count || defaultBeforeAfter;
177
- setupRoute('/count', 'get', before, ${modelName}Count as RequestHandler, input, output);
172
+ const { before = [], after = [], inputValidator, outputValidator) = config.count || defaultBeforeAfter;
173
+ setupRoute('/count', 'get', before, ${modelName}Count as RequestHandler, inputValidator, outputValidator);
178
174
  if (after.length) {
179
175
  router.use(basePath + '/count', ...after);
180
176
  }
181
177
  }
182
178
 
183
179
  if (config.enableAll || config?.groupBy) {
184
- const { before = [], after = [], input, output } = config.groupBy || defaultBeforeAfter;
185
- setupRoute('/groupby', 'get', before, ${modelName}GroupBy as RequestHandler, input, output);
180
+ const { before = [], after = [], inputValidator, outputValidator) = config.groupBy || defaultBeforeAfter;
181
+ setupRoute('/groupby', 'get', before, ${modelName}GroupBy as RequestHandler, inputValidator, outputValidator);
186
182
  if (after.length) {
187
183
  router.use(basePath + '/groupby', ...after);
188
184
  }
@@ -1 +1 @@
1
- {"version":3,"file":"generateRouteFile.js","sourceRoot":"","sources":["../../src/helpers/generateRouteFile.ts"],"names":[],"mappings":";;;AAEA,SAAgB,sBAAsB,CAAC,EACrC,KAAK,GAGN;IACC,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,kBAAkB,GAAG,GAAG,SAAS,QAAQ,CAAA;IAE/C,OAAO;;;;;;;WAOE,SAAS,uBAAuB,SAAS;WACzC,SAAS,sBAAsB,SAAS;WACxC,SAAS,wBAAwB,SAAS;WAC1C,SAAS,oBAAoB,SAAS;WACtC,SAAS,wBAAwB,SAAS;WAC1C,SAAS,oBAAoB,SAAS;WACtC,SAAS,wBAAwB,SAAS;WAC1C,SAAS,oBAAoB,SAAS;WACtC,SAAS,oBAAoB,SAAS;WACtC,SAAS,wBAAwB,SAAS;WAC1C,SAAS,uBAAuB,SAAS;WACzC,SAAS,mBAAmB,SAAS;WACrC,SAAS,qBAAqB,SAAS;;;;;;;;;;;;;;qCAcb,SAAS;;;;;kBAK5B,kBAAkB;;iFAE6C,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0CA0C9D,SAAS;;;;;;;;qCAQd,SAAS;;;;;;;;wCAQN,SAAS;;;;;;;;sCAQX,SAAS;;;;;;;;0CAQL,SAAS;;;;;;;;qCAQd,SAAS;;;;;;;;yCAQL,SAAS;;;;;;;;uCAQX,SAAS;;;;;;;;wCAQR,SAAS;;;;;;;;4CAQL,SAAS;;;;;;;;8CAQP,SAAS;;;;;;;;0CAQb,SAAS;;;;;;;;4CAQP,SAAS;;;;;;;;CAQpD,CAAA;AACD,CAAC;AAnMD,wDAmMC"}
1
+ {"version":3,"file":"generateRouteFile.js","sourceRoot":"","sources":["../../src/helpers/generateRouteFile.ts"],"names":[],"mappings":";;;AAEA,SAAgB,sBAAsB,CAAC,EACrC,KAAK,GAGN;IACC,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,kBAAkB,GAAG,GAAG,SAAS,QAAQ,CAAA;IAE/C,OAAO;;;;WAIE,SAAS,uBAAuB,SAAS;WACzC,SAAS,sBAAsB,SAAS;WACxC,SAAS,wBAAwB,SAAS;WAC1C,SAAS,oBAAoB,SAAS;WACtC,SAAS,wBAAwB,SAAS;WAC1C,SAAS,oBAAoB,SAAS;WACtC,SAAS,wBAAwB,SAAS;WAC1C,SAAS,oBAAoB,SAAS;WACtC,SAAS,oBAAoB,SAAS;WACtC,SAAS,wBAAwB,SAAS;WAC1C,SAAS,uBAAuB,SAAS;WACzC,SAAS,mBAAmB,SAAS;WACrC,SAAS,qBAAqB,SAAS;;;;;;;;;;;;;qCAab,SAAS;;;;;kBAK5B,kBAAkB;;iFAE6C,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0CA0C9D,SAAS;;;;;;;;qCAQd,SAAS;;;;;;;;wCAQN,SAAS;;;;;;;;sCAQX,SAAS;;;;;;;;0CAQL,SAAS;;;;;;;;qCAQd,SAAS;;;;;;;;yCAQL,SAAS;;;;;;;;uCAQX,SAAS;;;;;;;;wCAQR,SAAS;;;;;;;;4CAQL,SAAS;;;;;;;;8CAQP,SAAS;;;;;;;;0CAQb,SAAS;;;;;;;;4CAQP,SAAS;;;;;;;;CAQpD,CAAA;AACD,CAAC;AA/LD,wDA+LC"}
@@ -17,7 +17,6 @@ interface UpdateRequest extends Request {
17
17
  prisma: PrismaClient;
18
18
  body: ${argsTypeName};
19
19
  outputValidation?: ZodTypeAny;
20
- omitOutputValidation?: boolean;
21
20
  locals?: {
22
21
  outputValidator?: ZodTypeAny;
23
22
  };
@@ -29,13 +28,9 @@ export async function ${functionName}(req: UpdateRequest, res: Response, next: N
29
28
  try {
30
29
  const outputValidator = req.locals?.outputValidator || req.outputValidation;
31
30
 
32
- if (!outputValidator && !req.omitOutputValidation) {
33
- throw new Error('Output validation schema or omission flag must be provided.');
34
- }
35
-
36
- const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.update(req.body);
31
+ const data = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.update(req.body);
37
32
 
38
- if (!req.omitOutputValidation && outputValidator) {
33
+ if (outputValidator) {
39
34
  const validationResult = outputValidator.safeParse(data);
40
35
  if (validationResult.success) {
41
36
  return res.status(200).json(validationResult.data);
@@ -45,8 +40,8 @@ export async function ${functionName}(req: UpdateRequest, res: Response, next: N
45
40
  } else {
46
41
  return res.status(200).json(data);
47
42
  }
48
- } catch (error: unknown) {
49
- return next(error);
43
+ } catch(error: unknown) {
44
+ next(error)
50
45
  }
51
46
  }`;
52
47
  };
@@ -1 +1 @@
1
- {"version":3,"file":"generateUpdate.js","sourceRoot":"","sources":["../../src/helpers/generateUpdate.ts"],"names":[],"mappings":";;;AACA,8CAAuD;AAQhD,MAAM,sBAAsB,GAAG,CAAC,OAGtC,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,QAAQ,CAAA;IACzC,MAAM,YAAY,GAAG,UAAU,SAAS,YAAY,CAAA;IAEpD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;;;;uEAQiD,YAAY;;wBAE3D,YAAY;;;;;;;;oCAQA,IAAA,8BAAoB,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;EAejE,CAAA;AACF,CAAC,CAAA;AAnDY,QAAA,sBAAsB,0BAmDlC"}
1
+ {"version":3,"file":"generateUpdate.js","sourceRoot":"","sources":["../../src/helpers/generateUpdate.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AAQxC,MAAM,sBAAsB,GAAG,CAAC,OAGtC,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,QAAQ,CAAA;IACzC,MAAM,YAAY,GAAG,UAAU,SAAS,YAAY,CAAA;IAEpD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;;;uEAOiD,YAAY;;wBAE3D,YAAY;;;;oCAIA,IAAA,sBAAY,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;EAezD,CAAA;AACF,CAAC,CAAA;AA9CY,QAAA,sBAAsB,0BA8ClC"}
@@ -17,7 +17,6 @@ interface UpdateManyRequest extends Request {
17
17
  prisma: PrismaClient;
18
18
  body: ${argsTypeName};
19
19
  outputValidation?: ZodTypeAny;
20
- omitOutputValidation?: boolean;
21
20
  locals?: {
22
21
  outputValidator?: ZodTypeAny;
23
22
  };
@@ -29,13 +28,9 @@ export async function ${functionName}(req: UpdateManyRequest, res: Response, nex
29
28
  try {
30
29
  const outputValidator = req.locals?.outputValidator || req.outputValidation;
31
30
 
32
- if (!outputValidator && !req.omitOutputValidation) {
33
- throw new Error('Output validation schema or omission flag must be provided.');
34
- }
35
-
36
- const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.updateMany(req.body);
31
+ const data = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.updateMany(req.body);
37
32
 
38
- if (!req.omitOutputValidation && outputValidator) {
33
+ if (outputValidator) {
39
34
  const validationResult = outputValidator.safeParse(data);
40
35
  if (validationResult.success) {
41
36
  return res.status(200).json({ count: validationResult.data.count });
@@ -45,8 +40,8 @@ export async function ${functionName}(req: UpdateManyRequest, res: Response, nex
45
40
  } else {
46
41
  return res.status(200).json({ count: data.count });
47
42
  }
48
- } catch (error: unknown) {
49
- return next(error);
43
+ } catch(error: unknown) {
44
+ next(error)
50
45
  }
51
46
  }`;
52
47
  };
@@ -1 +1 @@
1
- {"version":3,"file":"generateUpdateMany.js","sourceRoot":"","sources":["../../src/helpers/generateUpdateMany.ts"],"names":[],"mappings":";;;AACA,8CAAuD;AAQhD,MAAM,0BAA0B,GAAG,CAAC,OAG1C,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,YAAY,CAAA;IAC7C,MAAM,YAAY,GAAG,UAAU,SAAS,gBAAgB,CAAA;IAExD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;;;;2EAQqD,YAAY;;wBAE/D,YAAY;;;;;;;;oCAQA,IAAA,8BAAoB,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;EAejE,CAAA;AACF,CAAC,CAAA;AAnDY,QAAA,0BAA0B,8BAmDtC"}
1
+ {"version":3,"file":"generateUpdateMany.js","sourceRoot":"","sources":["../../src/helpers/generateUpdateMany.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AAQxC,MAAM,0BAA0B,GAAG,CAAC,OAG1C,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,YAAY,CAAA;IAC7C,MAAM,YAAY,GAAG,UAAU,SAAS,gBAAgB,CAAA;IAExD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;;;2EAOqD,YAAY;;wBAE/D,YAAY;;;;oCAIA,IAAA,sBAAY,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;EAezD,CAAA;AACF,CAAC,CAAA;AA9CY,QAAA,0BAA0B,8BA8CtC"}
@@ -17,7 +17,6 @@ interface UpsertRequest extends Request {
17
17
  prisma: PrismaClient;
18
18
  body: ${argsTypeName};
19
19
  outputValidation?: ZodTypeAny;
20
- omitOutputValidation?: boolean;
21
20
  locals?: {
22
21
  outputValidator?: ZodTypeAny;
23
22
  };
@@ -29,13 +28,9 @@ export async function ${functionName}(req: UpsertRequest, res: Response, next: N
29
28
  try {
30
29
  const outputValidator = req.locals?.outputValidator || req.outputValidation;
31
30
 
32
- if (!outputValidator && !req.omitOutputValidation) {
33
- throw new Error('Output validation schema or omission flag must be provided.');
34
- }
35
-
36
- const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.upsert(req.body);
31
+ const data = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.upsert(req.body);
37
32
 
38
- if (!req.omitOutputValidation && outputValidator) {
33
+ if (outputValidator) {
39
34
  const validationResult = outputValidator.safeParse(data);
40
35
  if (validationResult.success) {
41
36
  return res.status(200).json(validationResult.data);
@@ -45,8 +40,8 @@ export async function ${functionName}(req: UpsertRequest, res: Response, next: N
45
40
  } else {
46
41
  return res.status(200).json(data);
47
42
  }
48
- } catch (error: unknown) {
49
- return next(error);
43
+ } catch(error: unknown) {
44
+ next(error)
50
45
  }
51
46
  }`;
52
47
  };
@@ -1 +1 @@
1
- {"version":3,"file":"generateUpsert.js","sourceRoot":"","sources":["../../src/helpers/generateUpsert.ts"],"names":[],"mappings":";;;AACA,8CAAuD;AAShD,MAAM,sBAAsB,GAAG,CAAC,OAGtC,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,QAAQ,CAAA;IACzC,MAAM,YAAY,GAAG,UAAU,SAAS,YAAY,CAAA;IAEpD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;;;;uEAQiD,YAAY;;wBAE3D,YAAY;;;;;;;;oCAQA,IAAA,8BAAoB,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;EAejE,CAAA;AACF,CAAC,CAAA;AAnDY,QAAA,sBAAsB,0BAmDlC"}
1
+ {"version":3,"file":"generateUpsert.js","sourceRoot":"","sources":["../../src/helpers/generateUpsert.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AASxC,MAAM,sBAAsB,GAAG,CAAC,OAGtC,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,QAAQ,CAAA;IACzC,MAAM,YAAY,GAAG,UAAU,SAAS,YAAY,CAAA;IAEpD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;;;uEAOiD,YAAY;;wBAE3D,YAAY;;;;oCAIA,IAAA,sBAAY,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;EAezD,CAAA;AACF,CAAC,CAAA;AA9CY,QAAA,sBAAsB,0BA8ClC"}
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lowercaseFirstLetter = exports.capitalize = void 0;
3
+ exports.toPascalCase = exports.capitalize = void 0;
4
4
  const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
5
5
  exports.capitalize = capitalize;
6
- function lowercaseFirstLetter(str) {
6
+ function toPascalCase(str) {
7
7
  if (!str)
8
8
  return str;
9
9
  return str.charAt(0).toLowerCase() + str.slice(1);
10
10
  }
11
- exports.lowercaseFirstLetter = lowercaseFirstLetter;
11
+ exports.toPascalCase = toPascalCase;
12
12
  //# sourceMappingURL=strings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"strings.js","sourceRoot":"","sources":["../../src/utils/strings.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE,CACxC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAD/B,QAAA,UAAU,cACqB;AAE5C,SAAgB,oBAAoB,CAAC,GAAW;IAC9C,IAAI,CAAC,GAAG;QAAE,OAAO,GAAG,CAAA;IACpB,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AACnD,CAAC;AAHD,oDAGC"}
1
+ {"version":3,"file":"strings.js","sourceRoot":"","sources":["../../src/utils/strings.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE,CACxC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAD/B,QAAA,UAAU,cACqB;AAE5C,SAAgB,YAAY,CAAC,GAAW;IACtC,IAAI,CAAC,GAAG;QAAE,OAAO,GAAG,CAAA;IACpB,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AACnD,CAAC;AAHD,oCAGC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "prisma-generator-express",
3
3
  "description": "Prisma generator of Express CRUD API",
4
- "version": "1.14.3",
4
+ "version": "1.15.1",
5
5
  "main": "dist/generator.js",
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -20,12 +20,12 @@
20
20
  "prepublishOnly": "node copy.js "
21
21
  },
22
22
  "dependencies": {
23
- "@prisma/client": "5.14.0",
24
- "@prisma/generator-helper": "5.14.0",
23
+ "@prisma/client": "5.15.0",
24
+ "@prisma/generator-helper": "5.15.0",
25
25
  "@prisma/sdk": "4.0.0",
26
26
  "express": "^4.19.2",
27
27
  "lodash": "^4.17.21",
28
- "prettier": "3.2.5",
28
+ "prettier": "3.3.2",
29
29
  "zod": "^3.23.8"
30
30
  },
31
31
  "devDependencies": {
@@ -35,11 +35,11 @@
35
35
  "@types/express": "^4.17.21",
36
36
  "@types/jest": "29.5.12",
37
37
  "@types/lodash": "^4.17.4",
38
- "@types/node": "20.12.13",
38
+ "@types/node": "20.14.2",
39
39
  "@types/prettier": "3.0.0",
40
40
  "jest": "29.7.0",
41
- "prisma": "5.14.0",
42
- "semantic-release": "^23.1.1",
41
+ "prisma": "5.15.0",
42
+ "semantic-release": "^24.0.0",
43
43
  "ts-jest": "29.1.4",
44
44
  "typescript": "5.4.5"
45
45
  },
package/src/generator.ts CHANGED
@@ -35,6 +35,16 @@ generatorHandler({
35
35
  const prismaImportStatement = generateImportPrismaStatement(options)
36
36
 
37
37
  for await (const model of options.dmmf.datamodel.models) {
38
+ if (
39
+ model.documentation &&
40
+ model.documentation.includes('generator off')
41
+ ) {
42
+ logger.info(
43
+ `Skipping generation for model ${model.name} as it is marked with 'generator off'.`,
44
+ )
45
+ continue
46
+ }
47
+
38
48
  await writeFileSafely({
39
49
  content: generateFindUniqueFunction({
40
50
  model,
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
- import { capitalize, lowercaseFirstLetter } from '../utils/strings'
2
+ import { capitalize, toPascalCase } from '../utils/strings'
3
3
 
4
4
  /**
5
5
  * Generates an Express middleware function that handles aggregation queries
@@ -29,7 +29,6 @@ interface AggregateRequest extends Request {
29
29
  prisma: PrismaClient;
30
30
  query: Partial<${argsTypeName}> & ParsedQs;
31
31
  outputValidation?: ZodTypeAny;
32
- omitOutputValidation?: boolean;
33
32
  locals?: {
34
33
  outputValidator?: ValidatorConfig;
35
34
  };
@@ -41,13 +40,9 @@ export async function ${functionName}(req: AggregateRequest, res: Response, next
41
40
  try {
42
41
  const outputValidator = res.locals.outputValidator?.schema || req.outputValidation;
43
42
 
44
- if (!outputValidator && !req.omitOutputValidation) {
45
- throw new Error('Output validation schema or omission flag must be provided.');
46
- }
47
-
48
- const result = await req.prisma.${lowercaseFirstLetter(modelName)}.aggregate(req.query as ${argsTypeName});
43
+ const result = await req.prisma.${toPascalCase(modelName)}.aggregate(req.query as ${argsTypeName});
49
44
 
50
- if (!req.omitOutputValidation && outputValidator) {
45
+ if (outputValidator) {
51
46
  const validationResult = outputValidator.safeParse(result);
52
47
  if (validationResult.success) {
53
48
  return res.status(200).json(validationResult.data);
@@ -57,8 +52,8 @@ export async function ${functionName}(req: AggregateRequest, res: Response, next
57
52
  } else {
58
53
  return res.status(200).json(result);
59
54
  }
60
- } catch (error: unknown) {
61
- return next(error);
55
+ } catch(error: unknown) {
56
+ next(error)
62
57
  }
63
58
  }`
64
59
  }
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
- import { lowercaseFirstLetter } from '../utils/strings'
2
+ import { toPascalCase } from '../utils/strings'
3
3
 
4
4
  /**
5
5
  * Generates an Express middleware function that handles count queries
@@ -28,7 +28,6 @@ interface CountRequest extends Request {
28
28
  prisma: PrismaClient;
29
29
  query: Partial<${argsTypeName}> & ParsedQs;
30
30
  outputValidation?: ZodTypeAny;
31
- omitOutputValidation?: boolean;
32
31
  locals?: {
33
32
  outputValidator?: ZodTypeAny;
34
33
  };
@@ -40,13 +39,9 @@ export async function ${functionName}(req: CountRequest, res: Response, next: Ne
40
39
  try {
41
40
  const outputValidator = req.locals?.outputValidator || req.outputValidation;
42
41
 
43
- if (!outputValidator && !req.omitOutputValidation) {
44
- throw new Error('Output validation schema or omission flag must be provided.');
45
- }
46
-
47
- const result = await req.prisma.${lowercaseFirstLetter(modelName)}.count(req.query as ${argsTypeName});
42
+ const result = await req.prisma.${toPascalCase(modelName)}.count(req.query as ${argsTypeName});
48
43
 
49
- if (!req.omitOutputValidation && outputValidator) {
44
+ if (outputValidator) {
50
45
  const validationResult = outputValidator.safeParse(result);
51
46
  if (validationResult.success) {
52
47
  return res.status(200).json(validationResult.data);
@@ -56,8 +51,8 @@ export async function ${functionName}(req: CountRequest, res: Response, next: Ne
56
51
  } else {
57
52
  return res.status(200).json(result);
58
53
  }
59
- } catch (error: unknown) {
60
- return next(error);
54
+ } catch(error: unknown) {
55
+ next(error)
61
56
  }
62
57
  }`
63
58
  }
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
- import { lowercaseFirstLetter } from '../utils/strings'
2
+ import { toPascalCase } from '../utils/strings'
3
3
 
4
4
  /**
5
5
  * Generates an Express middleware function that handles creation of records and includes conditional output validation with Zod.
@@ -26,7 +26,6 @@ interface CreateRequest extends Request {
26
26
  prisma: PrismaClient;
27
27
  body: ${argsTypeName};
28
28
  outputValidation?: ZodTypeAny;
29
- omitOutputValidation?: boolean;
30
29
  locals?: {
31
30
  outputValidator?: ZodTypeAny;
32
31
  };
@@ -38,13 +37,9 @@ export async function ${functionName}(req: CreateRequest, res: Response, next: N
38
37
  try {
39
38
  const outputValidator = req.locals?.outputValidator || req.outputValidation;
40
39
 
41
- if (!outputValidator && !req.omitOutputValidation) {
42
- throw new Error('Output validation schema or omission flag must be provided.');
43
- }
44
-
45
- const data = await req.prisma.${lowercaseFirstLetter(modelName)}.create(req.body);
40
+ const data = await req.prisma.${toPascalCase(modelName)}.create(req.body);
46
41
 
47
- if (!req.omitOutputValidation && outputValidator) {
42
+ if (outputValidator) {
48
43
  const validationResult = outputValidator.safeParse(data);
49
44
  if (validationResult.success) {
50
45
  return res.status(201).json(validationResult.data);
@@ -54,8 +49,8 @@ export async function ${functionName}(req: CreateRequest, res: Response, next: N
54
49
  } else {
55
50
  return res.status(201).json(data);
56
51
  }
57
- } catch (error: unknown) {
58
- return next(error);
52
+ } catch(error: unknown) {
53
+ next(error)
59
54
  }
60
55
  }`
61
56
  }
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
- import { lowercaseFirstLetter } from '../utils/strings'
2
+ import { toPascalCase } from '../utils/strings'
3
3
  /**
4
4
  * Generates an Express middleware function that handles the creation of multiple records and includes conditional output validation with Zod.
5
5
  * This version dynamically includes the correct type for the arguments based on the Prisma model.
@@ -25,7 +25,6 @@ interface CreateManyRequest extends Request {
25
25
  prisma: PrismaClient;
26
26
  body: ${argsTypeName};
27
27
  outputValidation?: ZodTypeAny;
28
- omitOutputValidation?: boolean;
29
28
  locals?: {
30
29
  outputValidator?: ZodTypeAny;
31
30
  };
@@ -37,13 +36,9 @@ export async function ${functionName}(req: CreateManyRequest, res: Response, nex
37
36
  try {
38
37
  const outputValidator = req.locals?.outputValidator || req.outputValidation;
39
38
 
40
- if (!outputValidator && !req.omitOutputValidation) {
41
- throw new Error('Output validation schema or omission flag must be provided.');
42
- }
43
-
44
- const data = await req.prisma.${lowercaseFirstLetter(modelName)}.createMany(req.body);
39
+ const data = await req.prisma.${toPascalCase(modelName)}.createMany(req.body);
45
40
 
46
- if (!req.omitOutputValidation && outputValidator) {
41
+ if (outputValidator) {
47
42
  const validationResult = outputValidator.safeParse(data);
48
43
  if (validationResult.success) {
49
44
  return res.status(201).json(validationResult.data);
@@ -53,8 +48,8 @@ export async function ${functionName}(req: CreateManyRequest, res: Response, nex
53
48
  } else {
54
49
  return res.status(201).json(data);
55
50
  }
56
- } catch (error: unknown) {
57
- return next(error);
51
+ } catch(error: unknown) {
52
+ next(error)
58
53
  }
59
54
  }`
60
55
  }
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
- import { lowercaseFirstLetter } from '../utils/strings'
2
+ import { toPascalCase } from '../utils/strings'
3
3
 
4
4
  /**
5
5
  * Generates an Express middleware function that handles deleting records
@@ -27,7 +27,6 @@ interface DeleteRequest extends Request {
27
27
  prisma: PrismaClient;
28
28
  body: ${argsTypeName};
29
29
  outputValidation?: ZodTypeAny;
30
- omitOutputValidation?: boolean;
31
30
  locals?: {
32
31
  outputValidator?: ZodTypeAny;
33
32
  };
@@ -39,13 +38,9 @@ export async function ${functionName}(req: DeleteRequest, res: Response, next: N
39
38
  try {
40
39
  const outputValidator = req.locals?.outputValidator || req.outputValidation;
41
40
 
42
- if (!outputValidator && !req.omitOutputValidation) {
43
- throw new Error('Output validation schema or omission flag must be provided.');
44
- }
45
-
46
- const data = await req.prisma.${lowercaseFirstLetter(modelName)}.delete(req.body);
41
+ const data = await req.prisma.${toPascalCase(modelName)}.delete(req.body);
47
42
 
48
- if (!req.omitOutputValidation && outputValidator) {
43
+ if (outputValidator) {
49
44
  const validationResult = outputValidator.safeParse(data);
50
45
  if (validationResult.success) {
51
46
  return res.status(200).json(validationResult.data);
@@ -55,8 +50,8 @@ export async function ${functionName}(req: DeleteRequest, res: Response, next: N
55
50
  } else {
56
51
  return res.status(200).json(data);
57
52
  }
58
- } catch (error: unknown) {
59
- return next(error);
53
+ } catch(error: unknown) {
54
+ next(error)
60
55
  }
61
56
  }`
62
57
  }
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
- import { lowercaseFirstLetter } from '../utils/strings'
2
+ import { toPascalCase } from '../utils/strings'
3
3
 
4
4
  /**
5
5
  * Generates an Express middleware function that handles batch deleting records
@@ -27,7 +27,6 @@ interface DeleteManyRequest extends Request {
27
27
  prisma: PrismaClient;
28
28
  body: ${argsTypeName};
29
29
  outputValidation?: ZodTypeAny;
30
- omitOutputValidation?: boolean;
31
30
  locals?: {
32
31
  outputValidator?: ZodTypeAny;
33
32
  };
@@ -39,13 +38,9 @@ export async function ${functionName}(req: DeleteManyRequest, res: Response, nex
39
38
  try {
40
39
  const outputValidator = req.locals?.outputValidator || req.outputValidation;
41
40
 
42
- if (!outputValidator && !req.omitOutputValidation) {
43
- throw new Error('Output validation schema or omission flag must be provided.');
44
- }
45
-
46
- const result = await req.prisma.${lowercaseFirstLetter(modelName)}.deleteMany(req.body);
41
+ const result = await req.prisma.${toPascalCase(modelName)}.deleteMany(req.body);
47
42
 
48
- if (!req.omitOutputValidation && outputValidator) {
43
+ if (outputValidator) {
49
44
  const validationResult = outputValidator.safeParse(result);
50
45
  if (validationResult.success) {
51
46
  return res.status(200).json(validationResult.data);
@@ -55,8 +50,8 @@ export async function ${functionName}(req: DeleteManyRequest, res: Response, nex
55
50
  } else {
56
51
  return res.status(200).json(result);
57
52
  }
58
- } catch (error: unknown) {
59
- return next(error);
53
+ } catch(error: unknown) {
54
+ next(error)
60
55
  }
61
56
  }`
62
57
  }