prisma-generator-express 1.11.4 → 1.13.0

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 (67) hide show
  1. package/README.md +51 -3
  2. package/dist/generator.js +2 -12
  3. package/dist/generator.js.map +1 -1
  4. package/dist/helpers/generateAggregate.js +13 -13
  5. package/dist/helpers/generateAggregate.js.map +1 -1
  6. package/dist/helpers/generateCount.js +12 -13
  7. package/dist/helpers/generateCount.js.map +1 -1
  8. package/dist/helpers/generateCreate.js +13 -15
  9. package/dist/helpers/generateCreate.js.map +1 -1
  10. package/dist/helpers/generateCreateMany.js +13 -15
  11. package/dist/helpers/generateCreateMany.js.map +1 -1
  12. package/dist/helpers/generateDelete.js +12 -15
  13. package/dist/helpers/generateDelete.js.map +1 -1
  14. package/dist/helpers/generateDeleteMany.js +13 -14
  15. package/dist/helpers/generateDeleteMany.js.map +1 -1
  16. package/dist/helpers/generateFindFirst.js +10 -15
  17. package/dist/helpers/generateFindFirst.js.map +1 -1
  18. package/dist/helpers/generateFindMany.js +10 -15
  19. package/dist/helpers/generateFindMany.js.map +1 -1
  20. package/dist/helpers/generateFindUnique.js +10 -15
  21. package/dist/helpers/generateFindUnique.js.map +1 -1
  22. package/dist/helpers/generateGroupBy.js +12 -13
  23. package/dist/helpers/generateGroupBy.js.map +1 -1
  24. package/dist/helpers/generateRouteFile.js +68 -35
  25. package/dist/helpers/generateRouteFile.js.map +1 -1
  26. package/dist/helpers/generateUpdate.js +12 -15
  27. package/dist/helpers/generateUpdate.js.map +1 -1
  28. package/dist/helpers/generateUpdateMany.js +12 -15
  29. package/dist/helpers/generateUpdateMany.js.map +1 -1
  30. package/dist/helpers/generateUpsert.js +12 -15
  31. package/dist/helpers/generateUpsert.js.map +1 -1
  32. package/dist/utils/copyFiles.js +26 -0
  33. package/dist/utils/copyFiles.js.map +1 -0
  34. package/package.json +4 -1
  35. package/src/copy/createOutputValidatorMiddleware.ts +44 -0
  36. package/src/copy/createValidatorMiddleware.ts +55 -0
  37. package/src/copy/encodeQueryParams.spec.ts +303 -0
  38. package/src/copy/encodeQueryParams.ts +44 -0
  39. package/src/copy/misc.spec.ts +62 -0
  40. package/src/copy/misc.ts +25 -0
  41. package/src/copy/parseQueryParams.spec.ts +187 -0
  42. package/src/copy/parseQueryParams.ts +42 -0
  43. package/src/copy/routeConfig.ts +34 -0
  44. package/src/copy/transformZod.spec.ts +556 -0
  45. package/src/copy/transformZod.ts +119 -0
  46. package/src/generator.ts +3 -13
  47. package/src/helpers/generateAggregate.ts +13 -13
  48. package/src/helpers/generateCount.ts +12 -13
  49. package/src/helpers/generateCreate.ts +14 -15
  50. package/src/helpers/generateCreateMany.ts +13 -15
  51. package/src/helpers/generateDelete.ts +13 -15
  52. package/src/helpers/generateDeleteMany.ts +14 -14
  53. package/src/helpers/generateFindFirst.ts +10 -15
  54. package/src/helpers/generateFindMany.ts +10 -15
  55. package/src/helpers/generateFindUnique.ts +10 -15
  56. package/src/helpers/generateGroupBy.ts +12 -13
  57. package/src/helpers/generateRouteFile.ts +68 -35
  58. package/src/helpers/generateUpdate.ts +13 -15
  59. package/src/helpers/generateUpdateMany.ts +13 -15
  60. package/src/helpers/generateUpsert.ts +13 -15
  61. package/src/utils/copyFiles.ts +27 -0
  62. package/dist/helpers/generateQsParser.js +0 -56
  63. package/dist/helpers/generateQsParser.js.map +0 -1
  64. package/dist/helpers/generateRouteConfigType.js +0 -34
  65. package/dist/helpers/generateRouteConfigType.js.map +0 -1
  66. package/src/helpers/generateQsParser.ts +0 -51
  67. package/src/helpers/generateRouteConfigType.ts +0 -29
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Prisma Generator Express
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/prisma-generator-express.svg)](https://www.npmjs.com/package/prisma-generator-express)
3
+ [![npm version](https://badge.fury.io/js/prisma-generator-express.svg)](https://badge.fury.io/js/prisma-generator-express)
4
4
  [![npm](https://img.shields.io/npm/dt/prisma-generator-express.svg)](https://www.npmjs.com/package/prisma-generator-express)
5
- [![npm](https://img.shields.io/npm/types/prisma-generator-express)](https://www.npmjs.com/package/prisma-generator-express)
6
5
  [![HitCount](https://hits.dwyl.com/multipliedtwice/prisma-generator-express.svg?style=flat)](http://hits.dwyl.com/multipliedtwice/prisma-generator-express)
6
+ [![Coverage Status](https://codecov.io/github/multipliedtwice/prisma-generator-express/graph/badge.svg?token=TTJ30HVKB8)](https://codecov.io/github/multipliedtwice/prisma-generator-express)
7
7
  [![npm](https://img.shields.io/npm/l/prisma-generator-express.svg)](LICENSE)
8
8
 
9
9
  This tool helps you quickly create API endpoints in your Express app using your Prisma models.
@@ -115,7 +115,7 @@ import express, { json } from 'express'
115
115
  import type { Response, Request, NextFunction, RequestHandler } from 'express'
116
116
 
117
117
  import { orderItemRouter } from '../prisma/generated/express/orderItem'
118
- import RouteConfig from '../prisma/generated/express/RouteConfig'
118
+ import RouteConfig from '../prisma/generated/express/routeConfig'
119
119
  import { PrismaClient } from '../prisma/generated/client'
120
120
 
121
121
  const app = express()
@@ -208,3 +208,51 @@ The following properties can be attached to the `req` object to control the beha
208
208
  | `aggregate` | `GET` | `/aggregate` |
209
209
  | `count` | `GET` | `/count` |
210
210
  | `groupBy` | `GET` | `/groupby` |
211
+
212
+ ## Helper functions
213
+
214
+ ### createValidatorMiddleware(validatorOptions: ValidatorOptions)
215
+
216
+ Simple wrapper that internally uses `allow` or `forbid` logic for filtering incoming queries and data payloads
217
+
218
+ ```ts
219
+ interface ValidatorOptions {
220
+ schema: ZodSchema<any>
221
+ allowedPaths?: string[] // Fobids all except allowed. For example [`where.user.id`, `select.id`], all other provided inputs will throw an error
222
+ forbiddenPaths?: string[] // Similar, but allows all, except forbidden
223
+ target?: 'body' | 'query'
224
+ }
225
+ ```
226
+
227
+ ### encodeQueryParams(params: Params)
228
+
229
+ Can be used on frontend to encode Prisma compatible queries. Alternatively `qs` can be used, but it probably won't work with `OR: [{ blah: false }, { blah: null }]` or some other edge cases.
230
+
231
+ ```ts
232
+ type RecursiveUrlParams = {
233
+ [key: string]: RecursiveUrlParams | string | boolean | unknown
234
+ }
235
+ type Params = Record<string, RecursiveUrlParams | string>
236
+ ```
237
+
238
+ ### parseQueryParams(params: QueryParams)
239
+
240
+ ```ts
241
+ type QueryParams = string | ParsedQs | string[] | ParsedQs[] | undefined
242
+ ```
243
+
244
+ Recursively converts strings "true", "false", "null", and "number" into correct formats.
245
+
246
+ ### allow<T extends z.ZodTypeAny>( schema: T, allowedPaths: string[] ): ZodEffects<T, any, any>
247
+
248
+ Accepts schema and `['array.of.allowed.paths']`. Throws an error if provided something that doesn't fit allowed schema.
249
+
250
+ ### forbid<T extends z.ZodTypeAny>( schema: T, forbiddenPaths: string[] ): ZodEffects<T, any, any>
251
+
252
+ Same as `allow` but works in opposite way.
253
+
254
+ ---
255
+
256
+ ## Rememo.io [Free Kanban & Chat](https://rememo.io)
257
+
258
+ <img src="https://github.com/multipliedtwice/prisma-generator-express/blob/feat/internal-validation/rememo-192.png?raw=true" alt="Free Kanban & Corporate Chat">
package/dist/generator.js CHANGED
@@ -19,8 +19,7 @@ const generateDeleteMany_1 = require("./helpers/generateDeleteMany");
19
19
  const generateAggregate_1 = require("./helpers/generateAggregate");
20
20
  const generateCount_1 = require("./helpers/generateCount");
21
21
  const generateGroupBy_1 = require("./helpers/generateGroupBy");
22
- const generateRouteConfigType_1 = require("./helpers/generateRouteConfigType");
23
- const generateQsParser_1 = require("./helpers/generateQsParser");
22
+ const copyFiles_1 = require("./utils/copyFiles");
24
23
  const { version } = require('../package.json');
25
24
  (0, generator_helper_1.generatorHandler)({
26
25
  onManifest() {
@@ -158,16 +157,7 @@ const { version } = require('../package.json');
158
157
  operation: 'index',
159
158
  });
160
159
  }
161
- await (0, writeFileSafely_1.writeFileSafely)({
162
- content: (0, generateRouteConfigType_1.generateRouteConfigType)(),
163
- options,
164
- operation: 'RouteConfig',
165
- });
166
- await (0, writeFileSafely_1.writeFileSafely)({
167
- content: (0, generateQsParser_1.generateParseQueryParams)(),
168
- options,
169
- operation: 'ParseQueryParams',
170
- });
160
+ await (0, copyFiles_1.copyFiles)(options);
171
161
  },
172
162
  });
173
163
  //# sourceMappingURL=generator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";;AAAA,+DAA6E;AAC7E,qCAAoC;AACpC,2CAA4C;AAC5C,6DAAyD;AACzD,qEAAyE;AACzE,2FAAuF;AACvF,iEAAqE;AACrE,mEAAuE;AACvE,6DAAiE;AACjE,mEAAoE;AACpE,qEAAyE;AACzE,6DAAiE;AACjE,qEAAyE;AACzE,6DAAiE;AACjE,6DAAiE;AACjE,qEAAyE;AACzE,mEAAuE;AACvE,2DAA+D;AAC/D,+DAAmE;AACnE,+EAA2E;AAC3E,iEAAqE;AAErE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;AAE9C,IAAA,mCAAgB,EAAC;IACf,UAAU;QACR,YAAM,CAAC,IAAI,CAAC,GAAG,0BAAc,aAAa,CAAC,CAAA;QAC3C,OAAO;YACL,OAAO;YACP,aAAa,EAAE,cAAc;YAC7B,UAAU,EAAE,0BAAc;SAC3B,CAAA;IACH,CAAC;IACD,UAAU,EAAE,KAAK,EAAE,OAAyB,EAAE,EAAE;QAC9C,MAAM,qBAAqB,GAAG,IAAA,6DAA6B,EAAC,OAAO,CAAC,CAAA;QAEpE,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;YACxD,MAAM,IAAA,iCAAe,EAAC;gBACpB,OAAO,EAAE,IAAA,+CAA0B,EAAC;oBAClC,KAAK;oBACL,qBAAqB;iBACtB,CAAC;gBACF,OAAO;gBACP,KAAK;gBACL,SAAS,EAAE,YAAY;aACxB,CAAC,CAAA;YAEF,MAAM,IAAA,iCAAe,EAAC;gBACpB,OAAO,EAAE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,CAAC;gBACF,OAAO;gBACP,KAAK;gBACL,SAAS,EAAE,QAAQ;aACpB,CAAC,CAAA;YAEF,MAAM,IAAA,iCAAe,EAAC;gBACpB,OAAO,EAAE,IAAA,+CAA0B,EAAC;oBAClC,KAAK;oBACL,qBAAqB;iBACtB,CAAC;gBACF,OAAO;gBACP,KAAK;gBACL,SAAS,EAAE,YAAY;aACxB,CAAC,CAAA;YAEF,MAAM,IAAA,iCAAe,EAAC;gBACpB,OAAO,EAAE,IAAA,6CAAyB,EAAC;oBACjC,KAAK;oBACL,qBAAqB;iBACtB,CAAC;gBACF,OAAO;gBACP,KAAK;gBACL,SAAS,EAAE,WAAW;aACvB,CAAC,CAAA;YAEF,MAAM,IAAA,iCAAe,EAAC;gBACpB,OAAO,EAAE,IAAA,qCAAqB,EAAC;oBAC7B,KAAK;oBACL,qBAAqB;iBACtB,CAAC;gBACF,OAAO;gBACP,KAAK;gBACL,SAAS,EAAE,OAAO;aACnB,CAAC,CAAA;YAEF,MAAM,IAAA,iCAAe,EAAC;gBACpB,OAAO,EAAE,IAAA,yCAAuB,EAAC;oBAC/B,KAAK;oBACL,qBAAqB;iBACtB,CAAC;gBACF,OAAO;gBACP,KAAK;gBACL,SAAS,EAAE,SAAS;aACrB,CAAC,CAAA;YAEF,MAAM,IAAA,iCAAe,EAAC;gBACpB,OAAO,EAAE,IAAA,0CAAsB,EAAC,EAAE,KAAK,EAAE,CAAC;gBAC1C,OAAO;gBACP,KAAK;gBACL,SAAS,EAAE,OAAO;aACnB,CAAC,CAAA;QACJ,CAAC;QAED,MAAM,IAAA,qBAAS,EAAC,OAAO,CAAC,CAAA;IAC1B,CAAC;CACF,CAAC,CAAA"}
@@ -13,42 +13,42 @@ import { Request, Response, NextFunction } from 'express';
13
13
  import { RequestHandler, ParamsDictionary } from 'express-serve-static-core'
14
14
  import { ParsedQs } from 'qs'
15
15
  import { ZodTypeAny } from 'zod';
16
+ import { ValidatorConfig } from '../routeConfig'
16
17
 
17
18
  interface AggregateRequest extends Request {
18
19
  prisma: PrismaClient;
19
20
  query: Partial<${argsTypeName}> & ParsedQs;
20
21
  outputValidation?: ZodTypeAny;
21
22
  omitOutputValidation?: boolean;
23
+ locals?: {
24
+ outputValidator?: ValidatorConfig;
25
+ };
22
26
  }
23
27
 
24
28
  export type AggregateMiddleware = RequestHandler<ParamsDictionary, any, Partial<${argsTypeName}>, Record<string, any>>;
25
29
 
26
30
  export async function ${functionName}(req: AggregateRequest, res: Response, next: NextFunction) {
27
31
  try {
28
- if (!req.outputValidation && !req.omitOutputValidation) {
32
+ const outputValidator = res.locals.outputValidator?.schema || req.outputValidation;
33
+
34
+ if (!outputValidator && !req.omitOutputValidation) {
29
35
  throw new Error('Output validation schema or omission flag must be provided.');
30
36
  }
31
37
 
32
38
  const result = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.aggregate(req.query as ${argsTypeName});
33
39
 
34
- if (!req.omitOutputValidation && req.outputValidation) {
35
- const validationResult = req.outputValidation.safeParse(result);
40
+ if (!req.omitOutputValidation && outputValidator) {
41
+ const validationResult = outputValidator.safeParse(result);
36
42
  if (validationResult.success) {
37
- res.status(200).json(validationResult.data);
43
+ return res.status(200).json(validationResult.data);
38
44
  } else {
39
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
45
+ return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
40
46
  }
41
47
  } else {
42
- res.status(200).json(result);
48
+ return res.status(200).json(result);
43
49
  }
44
50
  } catch (error: unknown) {
45
- console.error("Error in handling aggregation request:", error);
46
- if (error instanceof Error) {
47
- res.status(500).json({ error: error.message });
48
- } else {
49
- res.status(500).json({ error: "Unknown error occurred" });
50
- }
51
- next(error);
51
+ return next(error);
52
52
  }
53
53
  }`;
54
54
  };
@@ -1 +1 @@
1
- {"version":3,"file":"generateAggregate.js","sourceRoot":"","sources":["../../src/helpers/generateAggregate.ts"],"names":[],"mappings":";;;AACA,8CAAmE;AAS5D,MAAM,yBAAyB,GAAG,CAAC,OAGzC,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,WAAW,CAAA;IAC5C,MAAM,YAAY,GAAG,UAAU,IAAA,oBAAU,EAAC,SAAS,CAAC,eAAe,CAAA;IAEnE,OAAO;EACP,qBAAqB;;;;;;;;mBAQJ,YAAY;;;;;kFAKmD,YAAY;;wBAEtE,YAAY;;;;;;sCAME,IAAA,8BAAoB,EAAC,SAAS,CAAC,2BAA2B,YAAY;;;;;;;;;;;;;;;;;;;;;EAqB1G,CAAA;AACF,CAAC,CAAA;AArDY,QAAA,yBAAyB,6BAqDrC"}
1
+ {"version":3,"file":"generateAggregate.js","sourceRoot":"","sources":["../../src/helpers/generateAggregate.ts"],"names":[],"mappings":";;;AACA,8CAAmE;AAS5D,MAAM,yBAAyB,GAAG,CAAC,OAGzC,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,WAAW,CAAA;IAC5C,MAAM,YAAY,GAAG,UAAU,IAAA,oBAAU,EAAC,SAAS,CAAC,eAAe,CAAA;IAEnE,OAAO;EACP,qBAAqB;;;;;;;;;mBASJ,YAAY;;;;;;;;kFAQmD,YAAY;;wBAEtE,YAAY;;;;;;;;sCAQE,IAAA,8BAAoB,EAAC,SAAS,CAAC,2BAA2B,YAAY;;;;;;;;;;;;;;;EAe1G,CAAA;AACF,CAAC,CAAA;AArDY,QAAA,yBAAyB,6BAqDrC"}
@@ -19,36 +19,35 @@ interface CountRequest extends Request {
19
19
  query: Partial<${argsTypeName}> & ParsedQs;
20
20
  outputValidation?: ZodTypeAny;
21
21
  omitOutputValidation?: boolean;
22
+ locals?: {
23
+ outputValidator?: ZodTypeAny;
24
+ };
22
25
  }
23
26
 
24
27
  export type CountMiddleware = RequestHandler<ParamsDictionary, any, {}, ParsedQs>;
25
28
 
26
29
  export async function ${functionName}(req: CountRequest, res: Response, next: NextFunction) {
27
30
  try {
28
- if (!req.outputValidation && !req.omitOutputValidation) {
31
+ const outputValidator = req.locals?.outputValidator || req.outputValidation;
32
+
33
+ if (!outputValidator && !req.omitOutputValidation) {
29
34
  throw new Error('Output validation schema or omission flag must be provided.');
30
35
  }
31
36
 
32
37
  const result = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.count(req.query as ${argsTypeName});
33
38
 
34
- if (!req.omitOutputValidation && req.outputValidation) {
35
- const validationResult = req.outputValidation.safeParse(result);
39
+ if (!req.omitOutputValidation && outputValidator) {
40
+ const validationResult = outputValidator.safeParse(result);
36
41
  if (validationResult.success) {
37
- res.status(200).json(validationResult.data);
42
+ return res.status(200).json(validationResult.data);
38
43
  } else {
39
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
44
+ return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
40
45
  }
41
46
  } else {
42
- res.status(200).json(result);
47
+ return res.status(200).json(result);
43
48
  }
44
49
  } catch (error: unknown) {
45
- console.error("Error in handling count request:", error);
46
- if (error instanceof Error) {
47
- res.status(500).json({ error: error.message });
48
- } else {
49
- res.status(500).json({ error: "Unknown error occurred" });
50
- }
51
- next(error);
50
+ return next(error);
52
51
  }
53
52
  }`;
54
53
  };
@@ -1 +1 @@
1
- {"version":3,"file":"generateCount.js","sourceRoot":"","sources":["../../src/helpers/generateCount.ts"],"names":[],"mappings":";;;AACA,8CAAuD;AAShD,MAAM,qBAAqB,GAAG,CAAC,OAGrC,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,OAAO,CAAA;IACxC,MAAM,YAAY,GAAG,UAAU,SAAS,WAAW,CAAA;IAEnD,OAAO;EACP,qBAAqB;;;;;;;;mBAQJ,YAAY;;;;;;;wBAOP,YAAY;;;;;;sCAME,IAAA,8BAAoB,EAAC,SAAS,CAAC,uBAAuB,YAAY;;;;;;;;;;;;;;;;;;;;;EAqBtG,CAAA;AACF,CAAC,CAAA;AArDY,QAAA,qBAAqB,yBAqDjC"}
1
+ {"version":3,"file":"generateCount.js","sourceRoot":"","sources":["../../src/helpers/generateCount.ts"],"names":[],"mappings":";;;AACA,8CAAuD;AAShD,MAAM,qBAAqB,GAAG,CAAC,OAGrC,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,OAAO,CAAA;IACxC,MAAM,YAAY,GAAG,UAAU,SAAS,WAAW,CAAA;IAEnD,OAAO;EACP,qBAAqB;;;;;;;;mBAQJ,YAAY;;;;;;;;;;wBAUP,YAAY;;;;;;;;sCAQE,IAAA,8BAAoB,EAAC,SAAS,CAAC,uBAAuB,YAAY;;;;;;;;;;;;;;;EAetG,CAAA;AACF,CAAC,CAAA;AApDY,QAAA,qBAAqB,yBAoDjC"}
@@ -18,37 +18,35 @@ interface CreateRequest extends Request {
18
18
  body: ${argsTypeName};
19
19
  outputValidation?: ZodTypeAny;
20
20
  omitOutputValidation?: boolean;
21
+ locals?: {
22
+ outputValidator?: ZodTypeAny;
23
+ };
21
24
  }
22
25
 
23
26
  export type CreateMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>
24
27
 
25
28
  export async function ${functionName}(req: CreateRequest, res: Response, next: NextFunction) {
26
29
  try {
27
- if (!req.outputValidation && !req.omitOutputValidation) {
30
+ const outputValidator = req.locals?.outputValidator || req.outputValidation;
31
+
32
+ if (!outputValidator && !req.omitOutputValidation) {
28
33
  throw new Error('Output validation schema or omission flag must be provided.');
29
34
  }
30
35
 
31
36
  const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.create(req.body);
32
- if (!req.omitOutputValidation && req.outputValidation) {
33
- const validationResult = req.outputValidation.safeParse(data);
37
+
38
+ if (!req.omitOutputValidation && outputValidator) {
39
+ const validationResult = outputValidator.safeParse(data);
34
40
  if (validationResult.success) {
35
- res.status(201).json(validationResult.data);
41
+ return res.status(201).json(validationResult.data);
36
42
  } else {
37
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
43
+ return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
38
44
  }
39
- } else if (!req.omitOutputValidation) {
40
- throw new Error('Output validation schema must be provided unless explicitly omitted.');
41
45
  } else {
42
- res.status(201).json(data);
46
+ return res.status(201).json(data);
43
47
  }
44
48
  } catch (error: unknown) {
45
- console.error("Error in handling create request:", error);
46
- if (error instanceof Error) {
47
- res.status(500).json({ error: error.message });
48
- } else {
49
- res.status(500).json({ error: "Unknown error occurred" });
50
- }
51
- next(error);
49
+ return next(error);
52
50
  }
53
51
  }`;
54
52
  };
@@ -1 +1 @@
1
- {"version":3,"file":"generateCreate.js","sourceRoot":"","sources":["../../src/helpers/generateCreate.ts"],"names":[],"mappings":";;;AACA,8CAAuD;AAOhD,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;;;;;uEAKiD,YAAY;;wBAE3D,YAAY;;;;;;oCAMA,IAAA,8BAAoB,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;EAsBjE,CAAA;AACF,CAAC,CAAA;AArDY,QAAA,sBAAsB,0BAqDlC"}
1
+ {"version":3,"file":"generateCreate.js","sourceRoot":"","sources":["../../src/helpers/generateCreate.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"}
@@ -18,37 +18,35 @@ interface CreateManyRequest extends Request {
18
18
  body: ${argsTypeName};
19
19
  outputValidation?: ZodTypeAny;
20
20
  omitOutputValidation?: boolean;
21
+ locals?: {
22
+ outputValidator?: ZodTypeAny;
23
+ };
21
24
  }
22
25
 
23
26
  export type CreateManyMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>
24
27
 
25
28
  export async function ${functionName}(req: CreateManyRequest, res: Response, next: NextFunction) {
26
29
  try {
27
- if (!req.outputValidation && !req.omitOutputValidation) {
30
+ const outputValidator = req.locals?.outputValidator || req.outputValidation;
31
+
32
+ if (!outputValidator && !req.omitOutputValidation) {
28
33
  throw new Error('Output validation schema or omission flag must be provided.');
29
34
  }
30
35
 
31
36
  const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.createMany(req.body);
32
- if (!req.omitOutputValidation && req.outputValidation) {
33
- const validationResult = req.outputValidation.safeParse(data);
37
+
38
+ if (!req.omitOutputValidation && outputValidator) {
39
+ const validationResult = outputValidator.safeParse(data);
34
40
  if (validationResult.success) {
35
- res.status(201).json(validationResult.data);
41
+ return res.status(201).json(validationResult.data);
36
42
  } else {
37
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
43
+ return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
38
44
  }
39
- } else if (!req.omitOutputValidation) {
40
- throw new Error('Output validation schema must be provided unless explicitly omitted.');
41
45
  } else {
42
- res.status(201).json(data);
46
+ return res.status(201).json(data);
43
47
  }
44
48
  } catch (error: unknown) {
45
- console.error('Error in handling createMany request:', error);
46
- if (error instanceof Error) {
47
- res.status(500).json({ error: error.message });
48
- } else {
49
- res.status(500).json({ error: "Unknown error occurred" });
50
- }
51
- next(error);
49
+ return next(error);
52
50
  }
53
51
  }`;
54
52
  };
@@ -1 +1 @@
1
- {"version":3,"file":"generateCreateMany.js","sourceRoot":"","sources":["../../src/helpers/generateCreateMany.ts"],"names":[],"mappings":";;;AACA,8CAAuD;AAOhD,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;;;;;2EAKqD,YAAY;;wBAE/D,YAAY;;;;;;oCAMA,IAAA,8BAAoB,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;EAsBjE,CAAA;AACF,CAAC,CAAA;AArDY,QAAA,0BAA0B,8BAqDtC"}
1
+ {"version":3,"file":"generateCreateMany.js","sourceRoot":"","sources":["../../src/helpers/generateCreateMany.ts"],"names":[],"mappings":";;;AACA,8CAAuD;AAOhD,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"}
@@ -18,38 +18,35 @@ interface DeleteRequest extends Request {
18
18
  body: ${argsTypeName};
19
19
  outputValidation?: ZodTypeAny;
20
20
  omitOutputValidation?: boolean;
21
+ locals?: {
22
+ outputValidator?: ZodTypeAny;
23
+ };
21
24
  }
22
25
 
23
26
  export type DeleteMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>
24
27
 
25
28
  export async function ${functionName}(req: DeleteRequest, res: Response, next: NextFunction) {
26
29
  try {
27
- if (!req.outputValidation && !req.omitOutputValidation) {
30
+ const outputValidator = req.locals?.outputValidator || req.outputValidation;
31
+
32
+ if (!outputValidator && !req.omitOutputValidation) {
28
33
  throw new Error('Output validation schema or omission flag must be provided.');
29
34
  }
30
35
 
31
36
  const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.delete(req.body);
32
37
 
33
- if (!req.omitOutputValidation && req.outputValidation) {
34
- const validationResult = req.outputValidation.safeParse(data);
38
+ if (!req.omitOutputValidation && outputValidator) {
39
+ const validationResult = outputValidator.safeParse(data);
35
40
  if (validationResult.success) {
36
- res.status(200).json(validationResult.data);
41
+ return res.status(200).json(validationResult.data);
37
42
  } else {
38
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
43
+ return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
39
44
  }
40
- } else if (!req.omitOutputValidation) {
41
- throw new Error('Output validation schema must be provided unless explicitly omitted.');
42
45
  } else {
43
- res.status(200).json(data);
46
+ return res.status(200).json(data);
44
47
  }
45
48
  } catch (error: unknown) {
46
- console.error('Error in handling delete request:', error);
47
- if (error instanceof Error) {
48
- res.status(500).json({ error: error.message });
49
- } else {
50
- res.status(500).json({ error: "Unknown error occurred" });
51
- }
52
- next(error);
49
+ return next(error);
53
50
  }
54
51
  }`;
55
52
  };
@@ -1 +1 @@
1
- {"version":3,"file":"generateDelete.js","sourceRoot":"","sources":["../../src/helpers/generateDelete.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;;;;;uEAKiD,YAAY;;wBAE3D,YAAY;;;;;;oCAMA,IAAA,8BAAoB,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;EAuBjE,CAAA;AACF,CAAC,CAAA;AAtDY,QAAA,sBAAsB,0BAsDlC"}
1
+ {"version":3,"file":"generateDelete.js","sourceRoot":"","sources":["../../src/helpers/generateDelete.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"}
@@ -18,36 +18,35 @@ interface DeleteManyRequest extends Request {
18
18
  body: ${argsTypeName};
19
19
  outputValidation?: ZodTypeAny;
20
20
  omitOutputValidation?: boolean;
21
+ locals?: {
22
+ outputValidator?: ZodTypeAny;
23
+ };
21
24
  }
22
25
 
23
- export type DeleteManyMiddleware = RequestHandler<ParamsDictionary, any, Prisma.${modelName}DeleteManyArgs, Record<string, any>>;
26
+ export type DeleteManyMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>;
24
27
 
25
28
  export async function ${functionName}(req: DeleteManyRequest, res: Response, next: NextFunction) {
26
29
  try {
27
- if (!req.outputValidation && !req.omitOutputValidation) {
30
+ const outputValidator = req.locals?.outputValidator || req.outputValidation;
31
+
32
+ if (!outputValidator && !req.omitOutputValidation) {
28
33
  throw new Error('Output validation schema or omission flag must be provided.');
29
34
  }
30
35
 
31
36
  const result = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.deleteMany(req.body);
32
37
 
33
- if (!req.omitOutputValidation && req.outputValidation) {
34
- const validationResult = req.outputValidation.safeParse(result);
38
+ if (!req.omitOutputValidation && outputValidator) {
39
+ const validationResult = outputValidator.safeParse(result);
35
40
  if (validationResult.success) {
36
- res.status(200).json(validationResult.data);
41
+ return res.status(200).json(validationResult.data);
37
42
  } else {
38
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
43
+ return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
39
44
  }
40
45
  } else {
41
- res.status(200).json(result);
46
+ return res.status(200).json(result);
42
47
  }
43
48
  } catch (error: unknown) {
44
- console.error('Error in handling batch delete request:', error);
45
- if (error instanceof Error) {
46
- res.status(500).json({ error: error.message });
47
- } else {
48
- res.status(500).json({ error: "Unknown error occurred" });
49
- }
50
- next(error);
49
+ return next(error);
51
50
  }
52
51
  }`;
53
52
  };
@@ -1 +1 @@
1
- {"version":3,"file":"generateDeleteMany.js","sourceRoot":"","sources":["../../src/helpers/generateDeleteMany.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;;;;;kFAK4D,SAAS;;wBAEnE,YAAY;;;;;;sCAME,IAAA,8BAAoB,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;EAqBnE,CAAA;AACF,CAAC,CAAA;AApDY,QAAA,0BAA0B,8BAoDtC"}
1
+ {"version":3,"file":"generateDeleteMany.js","sourceRoot":"","sources":["../../src/helpers/generateDeleteMany.ts"],"names":[],"mappings":";;;AACA,8CAAuD;AAShD,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;;;;;;;;sCAQE,IAAA,8BAAoB,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;EAenE,CAAA;AACF,CAAC,CAAA;AAnDY,QAAA,0BAA0B,8BAmDtC"}
@@ -25,13 +25,16 @@ export interface FindFirstRequest extends Request {
25
25
  passToNext?: boolean;
26
26
  locals?: {
27
27
  data?: ${modelName} | null
28
+ outputValidator?: ZodTypeAny;
28
29
  }
29
30
  }
30
31
  export type FindFirstMiddleware = RequestHandler<ParamsDictionary, any, any, ${queryTypeName} & ParsedQs, Record<string, any>>
31
32
 
32
33
  export async function ${functionName}(req: FindFirstRequest, res: Response, next: NextFunction) {
33
34
  try {
34
- if (!req.outputValidation && !req.omitOutputValidation) {
35
+ const outputValidator = req.locals?.outputValidator || req.outputValidation;
36
+
37
+ if (!outputValidator && !req.omitOutputValidation) {
35
38
  throw new Error('Output validation schema or omission flag must be provided.');
36
39
  }
37
40
 
@@ -39,26 +42,18 @@ export async function ${functionName}(req: FindFirstRequest, res: Response, next
39
42
  if (req.passToNext) {
40
43
  if (req.locals) req.locals.data = data;
41
44
  next();
42
- } else if (!req.omitOutputValidation && req.outputValidation) {
43
- const validationResult = req.outputValidation.safeParse(data);
45
+ } else if (!req.omitOutputValidation && outputValidator) {
46
+ const validationResult = outputValidator.safeParse(data);
44
47
  if (validationResult.success) {
45
- res.status(200).json(validationResult.data);
48
+ return res.status(200).json(validationResult.data);
46
49
  } else {
47
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
50
+ return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
48
51
  }
49
- } else if (!req.omitOutputValidation) {
50
- throw new Error('Output validation schema must be provided unless explicitly omitted. Attach omitOutputValidation = true to request to suppress this error.');
51
52
  } else {
52
- res.status(200).json(data);
53
+ return res.status(200).json(data);
53
54
  }
54
55
  } catch (error: unknown) {
55
- console.error('Error in handling request:', error);
56
- if (error instanceof Error) {
57
- res.status(500).json({ error: error.message });
58
- } else {
59
- res.status(500).json({ error: "Unknown error occurred" });
60
- }
61
- next(error);
56
+ return next(error);
62
57
  }
63
58
  }`;
64
59
  };
@@ -1 +1 @@
1
- {"version":3,"file":"generateFindFirst.js","sourceRoot":"","sources":["../../src/helpers/generateFindFirst.ts"],"names":[],"mappings":";;;AACA,8CAAuD;AAOhD,MAAM,yBAAyB,GAAG,CAAC,OAGzC,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,WAAW,CAAA;IAC5C,MAAM,aAAa,GAAG,UAAU,SAAS,eAAe,CAAA;IAExD,OAAO;EACP,qBAAqB,CAAC,OAAO,CAAC,YAAY,EAAE,aAAa,SAAS,IAAI,CAAC;;;;;;;;;;;WAW9D,aAAa;;;;;aAKX,SAAS;;;+EAGyD,aAAa;;wBAEpE,YAAY;;;;;;oCAMA,IAAA,8BAAoB,EAAC,SAAS,CAAC,2BAA2B,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;EAyBzG,CAAA;AACF,CAAC,CAAA;AA/DY,QAAA,yBAAyB,6BA+DrC"}
1
+ {"version":3,"file":"generateFindFirst.js","sourceRoot":"","sources":["../../src/helpers/generateFindFirst.ts"],"names":[],"mappings":";;;AACA,8CAAuD;AAOhD,MAAM,yBAAyB,GAAG,CAAC,OAGzC,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,WAAW,CAAA;IAC5C,MAAM,aAAa,GAAG,UAAU,SAAS,eAAe,CAAA;IAExD,OAAO;EACP,qBAAqB,CAAC,OAAO,CAAC,YAAY,EAAE,aAAa,SAAS,IAAI,CAAC;;;;;;;;;;;WAW9D,aAAa;;;;;aAKX,SAAS;;;;+EAIyD,aAAa;;wBAEpE,YAAY;;;;;;;;oCAQA,IAAA,8BAAoB,EAAC,SAAS,CAAC,2BAA2B,aAAa;;;;;;;;;;;;;;;;;EAiBzG,CAAA;AACF,CAAC,CAAA;AA1DY,QAAA,yBAAyB,6BA0DrC"}
@@ -25,13 +25,16 @@ export interface FindManyRequest extends Request {
25
25
  passToNext?: boolean;
26
26
  locals?: {
27
27
  data?: ${modelName}[]
28
+ outputValidator?: ZodTypeAny;
28
29
  }
29
30
  }
30
31
  export type FindManyMiddleware = RequestHandler<ParamsDictionary, any, any, ${queryTypeName} & ParsedQs, Record<string, any>>
31
32
 
32
33
  export async function ${functionName}(req: FindManyRequest, res: Response, next: NextFunction) {
33
34
  try {
34
- if (!req.outputValidation && !req.omitOutputValidation) {
35
+ const outputValidator = req.locals?.outputValidator || req.outputValidation;
36
+
37
+ if (!outputValidator && !req.omitOutputValidation) {
35
38
  throw new Error('Output validation schema or omission flag must be provided.');
36
39
  }
37
40
 
@@ -39,26 +42,18 @@ export async function ${functionName}(req: FindManyRequest, res: Response, next:
39
42
  if (req.passToNext) {
40
43
  if (req.locals) req.locals.data = data;
41
44
  next();
42
- } else if (!req.omitOutputValidation && req.outputValidation) {
43
- const validationResult = req.outputValidation.safeParse(data);
45
+ } else if (!req.omitOutputValidation && outputValidator) {
46
+ const validationResult = outputValidator.safeParse(data);
44
47
  if (validationResult.success) {
45
- res.status(200).json(validationResult.data);
48
+ return res.status(200).json(validationResult.data);
46
49
  } else {
47
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
50
+ return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
48
51
  }
49
- } else if (!req.omitOutputValidation) {
50
- throw new Error('Output validation schema must be provided unless explicitly omitted. Attach omitOutputValidation = true to request to suppress this error.');
51
52
  } else {
52
- res.status(200).json(data);
53
+ return res.status(200).json(data);
53
54
  }
54
55
  } catch (error: unknown) {
55
- console.error('Error in handling request:', error);
56
- if (error instanceof Error) {
57
- res.status(500).json({ error: error.message });
58
- } else {
59
- res.status(500).json({ error: "Unknown error occurred" });
60
- }
61
- next(error);
56
+ return next(error);
62
57
  }
63
58
  }`;
64
59
  };
@@ -1 +1 @@
1
- {"version":3,"file":"generateFindMany.js","sourceRoot":"","sources":["../../src/helpers/generateFindMany.ts"],"names":[],"mappings":";;;AACA,8CAAuD;AAOhD,MAAM,wBAAwB,GAAG,CAAC,OAGxC,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,UAAU,CAAA;IAC3C,MAAM,aAAa,GAAG,UAAU,SAAS,cAAc,CAAA;IAEvD,OAAO;EACP,qBAAqB,CAAC,OAAO,CAAC,YAAY,EAAE,aAAa,SAAS,IAAI,CAAC;;;;;;;;;;;WAW9D,aAAa;;;;;aAKX,SAAS;;;8EAGwD,aAAa;;wBAEnE,YAAY;;;;;;oCAMA,IAAA,8BAAoB,EAAC,SAAS,CAAC,0BAA0B,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;EAyBxG,CAAA;AACF,CAAC,CAAA;AA/DY,QAAA,wBAAwB,4BA+DpC"}
1
+ {"version":3,"file":"generateFindMany.js","sourceRoot":"","sources":["../../src/helpers/generateFindMany.ts"],"names":[],"mappings":";;;AACA,8CAAuD;AAOhD,MAAM,wBAAwB,GAAG,CAAC,OAGxC,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,UAAU,CAAA;IAC3C,MAAM,aAAa,GAAG,UAAU,SAAS,cAAc,CAAA;IAEvD,OAAO;EACP,qBAAqB,CAAC,OAAO,CAAC,YAAY,EAAE,aAAa,SAAS,IAAI,CAAC;;;;;;;;;;;WAW9D,aAAa;;;;;aAKX,SAAS;;;;8EAIwD,aAAa;;wBAEnE,YAAY;;;;;;;;oCAQA,IAAA,8BAAoB,EAAC,SAAS,CAAC,0BAA0B,aAAa;;;;;;;;;;;;;;;;;EAiBxG,CAAA;AACF,CAAC,CAAA;AA1DY,QAAA,wBAAwB,4BA0DpC"}
@@ -25,13 +25,16 @@ export interface FindUniqueRequest extends Request {
25
25
  passToNext?: boolean;
26
26
  locals?: {
27
27
  data?: ${modelName} | null
28
+ outputValidator?: ZodTypeAny;
28
29
  }
29
30
  }
30
31
  export type FindUniqueMiddleware = RequestHandler<ParamsDictionary, any, any, ${queryTypeName} & ParsedQs, Record<string, any>>
31
32
 
32
33
  export async function ${functionName}(req: FindUniqueRequest, res: Response, next: NextFunction) {
33
34
  try {
34
- if (!req.outputValidation && !req.omitOutputValidation) {
35
+ const outputValidator = req.locals?.outputValidator || req.outputValidation;
36
+
37
+ if (!outputValidator && !req.omitOutputValidation) {
35
38
  throw new Error('Output validation schema or omission flag must be provided.');
36
39
  }
37
40
 
@@ -39,26 +42,18 @@ export async function ${functionName}(req: FindUniqueRequest, res: Response, nex
39
42
  if (req.passToNext) {
40
43
  if (req.locals) req.locals.data = data;
41
44
  next();
42
- } else if (!req.omitOutputValidation && req.outputValidation) {
43
- const validationResult = req.outputValidation.safeParse(data);
45
+ } else if (!req.omitOutputValidation && outputValidator) {
46
+ const validationResult = outputValidator.safeParse(data);
44
47
  if (validationResult.success) {
45
- res.status(200).json(validationResult.data);
48
+ return res.status(200).json(validationResult.data);
46
49
  } else {
47
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
50
+ return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
48
51
  }
49
- } else if (!req.omitOutputValidation) {
50
- throw new Error('Output validation schema must be provided unless explicitly omitted. Attach omitOutputValidation = true to request to suppress this error.');
51
52
  } else {
52
- res.status(200).json(data);
53
+ return res.status(200).json(data);
53
54
  }
54
55
  } catch (error: unknown) {
55
- console.error("Error in handling findUnique request:", error);
56
- if (error instanceof Error) {
57
- res.status(500).json({ error: error.message });
58
- } else {
59
- res.status(500).json({ error: "Unknown error occurred" });
60
- }
61
- next(error);
56
+ return next(error);
62
57
  }
63
58
  }`;
64
59
  };