prisma-generator-express 1.2.0 → 1.3.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 (45) hide show
  1. package/dist/helpers/generateAggregate.js +6 -4
  2. package/dist/helpers/generateAggregate.js.map +1 -1
  3. package/dist/helpers/generateCount.js +6 -4
  4. package/dist/helpers/generateCount.js.map +1 -1
  5. package/dist/helpers/generateCreate.js +2 -1
  6. package/dist/helpers/generateCreate.js.map +1 -1
  7. package/dist/helpers/generateCreateMany.js +2 -1
  8. package/dist/helpers/generateCreateMany.js.map +1 -1
  9. package/dist/helpers/generateDelete.js +2 -1
  10. package/dist/helpers/generateDelete.js.map +1 -1
  11. package/dist/helpers/generateDeleteMany.js +2 -1
  12. package/dist/helpers/generateDeleteMany.js.map +1 -1
  13. package/dist/helpers/generateFindFirst.js +2 -1
  14. package/dist/helpers/generateFindFirst.js.map +1 -1
  15. package/dist/helpers/generateFindMany.js +2 -1
  16. package/dist/helpers/generateFindMany.js.map +1 -1
  17. package/dist/helpers/generateFindUnique.js +2 -1
  18. package/dist/helpers/generateFindUnique.js.map +1 -1
  19. package/dist/helpers/generateGroupBy.js +7 -4
  20. package/dist/helpers/generateGroupBy.js.map +1 -1
  21. package/dist/helpers/generateRouteFile.js +10 -10
  22. package/dist/helpers/generateUpdate.js +2 -4
  23. package/dist/helpers/generateUpdate.js.map +1 -1
  24. package/dist/helpers/generateUpdateMany.js +2 -1
  25. package/dist/helpers/generateUpdateMany.js.map +1 -1
  26. package/dist/helpers/generateUpsert.js +2 -1
  27. package/dist/helpers/generateUpsert.js.map +1 -1
  28. package/dist/utils/strings.js +12 -0
  29. package/dist/utils/strings.js.map +1 -0
  30. package/package.json +2 -2
  31. package/src/helpers/generateAggregate.ts +6 -4
  32. package/src/helpers/generateCount.ts +6 -4
  33. package/src/helpers/generateCreate.ts +2 -2
  34. package/src/helpers/generateCreateMany.ts +2 -2
  35. package/src/helpers/generateDelete.ts +2 -2
  36. package/src/helpers/generateDeleteMany.ts +2 -2
  37. package/src/helpers/generateFindFirst.ts +2 -2
  38. package/src/helpers/generateFindMany.ts +2 -2
  39. package/src/helpers/generateFindUnique.ts +2 -2
  40. package/src/helpers/generateGroupBy.ts +8 -4
  41. package/src/helpers/generateRouteFile.ts +10 -10
  42. package/src/helpers/generateUpdate.ts +2 -5
  43. package/src/helpers/generateUpdateMany.ts +2 -2
  44. package/src/helpers/generateUpsert.ts +2 -2
  45. package/src/utils/strings.ts +7 -0
@@ -1,25 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateAggregateFunction = void 0;
4
+ const strings_1 = require("../utils/strings");
4
5
  const generateAggregateFunction = (options) => {
5
6
  const { model, prismaImportStatement } = options;
6
7
  const modelName = model.name;
7
8
  const functionName = `${modelName}Aggregate`;
8
- const argsTypeName = `Prisma.${modelName}AggregateArgs`;
9
+ const argsTypeName = `Prisma.${(0, strings_1.capitalize)(modelName)}AggregateArgs`;
9
10
  return `
10
11
  ${prismaImportStatement}
11
12
  import { Request, Response, NextFunction } from 'express';
12
13
  import { RequestHandler, ParamsDictionary } from 'express-serve-static-core'
14
+ import { ParsedQs } from 'qs'
13
15
  import { ZodTypeAny } from 'zod';
14
16
 
15
17
  interface AggregateRequest extends Request {
16
18
  prisma: PrismaClient;
17
- body: ${argsTypeName};
19
+ query: Partial<${argsTypeName}> & ParsedQs;
18
20
  outputValidation?: ZodTypeAny;
19
21
  omitOutputValidation?: boolean;
20
22
  }
21
23
 
22
- export type AggregateMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>;
24
+ export type AggregateMiddleware = RequestHandler<ParamsDictionary, any, Partial<${argsTypeName}>, Record<string, any>>;
23
25
 
24
26
  export async function ${functionName}(req: AggregateRequest, res: Response, next: NextFunction) {
25
27
  try {
@@ -27,7 +29,7 @@ export async function ${functionName}(req: AggregateRequest, res: Response, next
27
29
  throw new Error('Output validation schema or omission flag must be provided.');
28
30
  }
29
31
 
30
- const result = await req.prisma.${modelName.toLowerCase()}.aggregate(req.body);
32
+ const result = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.aggregate(req.query as ${argsTypeName});
31
33
 
32
34
  if (!req.omitOutputValidation && req.outputValidation) {
33
35
  const validationResult = req.outputValidation.safeParse(result);
@@ -1 +1 @@
1
- {"version":3,"file":"generateAggregate.js","sourceRoot":"","sources":["../../src/helpers/generateAggregate.ts"],"names":[],"mappings":";;;AASO,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,SAAS,eAAe,CAAA;IAEvD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;0EAKoD,YAAY;;wBAE9D,YAAY;;;;;;sCAME,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;EAiB3D,CAAA;AACF,CAAC,CAAA;AAhDY,QAAA,yBAAyB,6BAgDrC"}
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;;;;;;;;;;;;;;;;;EAiB1G,CAAA;AACF,CAAC,CAAA;AAjDY,QAAA,yBAAyB,6BAiDrC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateCountFunction = void 0;
4
+ const strings_1 = require("../utils/strings");
4
5
  const generateCountFunction = (options) => {
5
6
  const { model, prismaImportStatement } = options;
6
7
  const modelName = model.name;
@@ -9,17 +10,18 @@ const generateCountFunction = (options) => {
9
10
  return `
10
11
  ${prismaImportStatement}
11
12
  import { Request, Response, NextFunction } from 'express';
12
- import { RequestHandler, ParamsDictionary } from 'express-serve-static-core'
13
+ import { RequestHandler, ParamsDictionary } from 'express-serve-static-core';
14
+ import { ParsedQs } from 'qs';
13
15
  import { ZodTypeAny } from 'zod';
14
16
 
15
17
  interface CountRequest extends Request {
16
18
  prisma: PrismaClient;
17
- body: ${argsTypeName};
19
+ query: Partial<${argsTypeName}> & ParsedQs;
18
20
  outputValidation?: ZodTypeAny;
19
21
  omitOutputValidation?: boolean;
20
22
  }
21
23
 
22
- export type CountMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>;
24
+ export type CountMiddleware = RequestHandler<ParamsDictionary, any, {}, ParsedQs>;
23
25
 
24
26
  export async function ${functionName}(req: CountRequest, res: Response, next: NextFunction) {
25
27
  try {
@@ -27,7 +29,7 @@ export async function ${functionName}(req: CountRequest, res: Response, next: Ne
27
29
  throw new Error('Output validation schema or omission flag must be provided.');
28
30
  }
29
31
 
30
- const result = await req.prisma.${modelName.toLowerCase()}.count(req.body);
32
+ const result = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.count(req.query as ${argsTypeName});
31
33
 
32
34
  if (!req.omitOutputValidation && req.outputValidation) {
33
35
  const validationResult = req.outputValidation.safeParse(result);
@@ -1 +1 @@
1
- {"version":3,"file":"generateCount.js","sourceRoot":"","sources":["../../src/helpers/generateCount.ts"],"names":[],"mappings":";;;AASO,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;;;;;;;UAOb,YAAY;;;;;sEAKgD,YAAY;;wBAE1D,YAAY;;;;;;sCAME,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;EAiB3D,CAAA;AACF,CAAC,CAAA;AAhDY,QAAA,qBAAqB,yBAgDjC"}
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;;;;;;;;;;;;;;;;;EAiBtG,CAAA;AACF,CAAC,CAAA;AAjDY,QAAA,qBAAqB,yBAiDjC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateCreateFunction = void 0;
4
+ const strings_1 = require("../utils/strings");
4
5
  const generateCreateFunction = (options) => {
5
6
  const { model, prismaImportStatement } = options;
6
7
  const modelName = model.name;
@@ -27,7 +28,7 @@ export async function ${functionName}(req: CreateRequest, res: Response, next: N
27
28
  throw new Error('Output validation schema or omission flag must be provided.');
28
29
  }
29
30
 
30
- const data = await req.prisma.${modelName.toLowerCase()}.create(req.body);
31
+ const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.create(req.body);
31
32
  if (!req.omitOutputValidation && req.outputValidation) {
32
33
  const validationResult = req.outputValidation.safeParse(data);
33
34
  if (validationResult.success) {
@@ -1 +1 @@
1
- {"version":3,"file":"generateCreate.js","sourceRoot":"","sources":["../../src/helpers/generateCreate.ts"],"names":[],"mappings":";;;AAQO,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,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;;EAkBzD,CAAA;AACF,CAAC,CAAA;AAjDY,QAAA,sBAAsB,0BAiDlC"}
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;;;;;;;;;;;;;;;;;;EAkBjE,CAAA;AACF,CAAC,CAAA;AAjDY,QAAA,sBAAsB,0BAiDlC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateCreateManyFunction = void 0;
4
+ const strings_1 = require("../utils/strings");
4
5
  const generateCreateManyFunction = (options) => {
5
6
  const { model, prismaImportStatement } = options;
6
7
  const modelName = model.name;
@@ -27,7 +28,7 @@ export async function ${functionName}(req: CreateManyRequest, res: Response, nex
27
28
  throw new Error('Output validation schema or omission flag must be provided.');
28
29
  }
29
30
 
30
- const data = await req.prisma.${modelName.toLowerCase()}.createMany(req.body);
31
+ const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.createMany(req.body);
31
32
  if (!req.omitOutputValidation && req.outputValidation) {
32
33
  const validationResult = req.outputValidation.safeParse(data);
33
34
  if (validationResult.success) {
@@ -1 +1 @@
1
- {"version":3,"file":"generateCreateMany.js","sourceRoot":"","sources":["../../src/helpers/generateCreateMany.ts"],"names":[],"mappings":";;;AAQO,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,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;;EAkBzD,CAAA;AACF,CAAC,CAAA;AAjDY,QAAA,0BAA0B,8BAiDtC"}
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;;;;;;;;;;;;;;;;;;EAkBjE,CAAA;AACF,CAAC,CAAA;AAjDY,QAAA,0BAA0B,8BAiDtC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateDeleteFunction = void 0;
4
+ const strings_1 = require("../utils/strings");
4
5
  const generateDeleteFunction = (options) => {
5
6
  const { model, prismaImportStatement } = options;
6
7
  const modelName = model.name;
@@ -27,7 +28,7 @@ export async function ${functionName}(req: DeleteRequest, res: Response, next: N
27
28
  throw new Error('Output validation schema or omission flag must be provided.');
28
29
  }
29
30
 
30
- const data = await req.prisma.${modelName.toLowerCase()}.delete(req.body);
31
+ const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.delete(req.body);
31
32
 
32
33
  if (!req.omitOutputValidation && req.outputValidation) {
33
34
  const validationResult = req.outputValidation.safeParse(data);
@@ -1 +1 @@
1
- {"version":3,"file":"generateDelete.js","sourceRoot":"","sources":["../../src/helpers/generateDelete.ts"],"names":[],"mappings":";;;AASO,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,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;;;EAmBzD,CAAA;AACF,CAAC,CAAA;AAlDY,QAAA,sBAAsB,0BAkDlC"}
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;;;;;;;;;;;;;;;;;;;EAmBjE,CAAA;AACF,CAAC,CAAA;AAlDY,QAAA,sBAAsB,0BAkDlC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateDeleteManyFunction = void 0;
4
+ const strings_1 = require("../utils/strings");
4
5
  const generateDeleteManyFunction = (options) => {
5
6
  const { model, prismaImportStatement } = options;
6
7
  const modelName = model.name;
@@ -27,7 +28,7 @@ export async function ${functionName}(req: DeleteManyRequest, res: Response, nex
27
28
  throw new Error('Output validation schema or omission flag must be provided.');
28
29
  }
29
30
 
30
- const result = await req.prisma.${modelName.toLowerCase()}.deleteMany(req.body);
31
+ const result = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.deleteMany(req.body);
31
32
 
32
33
  if (!req.omitOutputValidation && req.outputValidation) {
33
34
  const validationResult = req.outputValidation.safeParse(result);
@@ -1 +1 @@
1
- {"version":3,"file":"generateDeleteMany.js","sourceRoot":"","sources":["../../src/helpers/generateDeleteMany.ts"],"names":[],"mappings":";;;AASO,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,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;EAiB3D,CAAA;AACF,CAAC,CAAA;AAhDY,QAAA,0BAA0B,8BAgDtC"}
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;;;;;;;;;;;;;;;;;EAiBnE,CAAA;AACF,CAAC,CAAA;AAhDY,QAAA,0BAA0B,8BAgDtC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateFindFirstFunction = void 0;
4
+ const strings_1 = require("../utils/strings");
4
5
  const generateFindFirstFunction = (options) => {
5
6
  const { model, prismaImportStatement } = options;
6
7
  const modelName = model.name;
@@ -34,7 +35,7 @@ export async function ${functionName}(req: FindFirstRequest, res: Response, next
34
35
  throw new Error('Output validation schema or omission flag must be provided.');
35
36
  }
36
37
 
37
- const data = await req.prisma.${modelName.toLowerCase()}.findFirst(req.query as ${queryTypeName});
38
+ const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.findFirst(req.query as ${queryTypeName});
38
39
  if (req.passToNext) {
39
40
  req.locals.data = data;
40
41
  next();
@@ -1 +1 @@
1
- {"version":3,"file":"generateFindFirst.js","sourceRoot":"","sources":["../../src/helpers/generateFindFirst.ts"],"names":[],"mappings":";;;AAQO,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,SAAS,CAAC,WAAW,EAAE,2BAA2B,aAAa;;;;;;;;;;;;;;;;;;;;;EAqBjG,CAAA;AACF,CAAC,CAAA;AA3DY,QAAA,yBAAyB,6BA2DrC"}
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;;;;;;;;;;;;;;;;;;;;;EAqBzG,CAAA;AACF,CAAC,CAAA;AA3DY,QAAA,yBAAyB,6BA2DrC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateFindManyFunction = void 0;
4
+ const strings_1 = require("../utils/strings");
4
5
  const generateFindManyFunction = (options) => {
5
6
  const { model, prismaImportStatement } = options;
6
7
  const modelName = model.name;
@@ -34,7 +35,7 @@ export async function ${functionName}(req: FindManyRequest, res: Response, next:
34
35
  throw new Error('Output validation schema or omission flag must be provided.');
35
36
  }
36
37
 
37
- const data = await req.prisma.${modelName.toLowerCase()}.findMany(req.query as ${queryTypeName});
38
+ const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.findMany(req.query as ${queryTypeName});
38
39
  if (req.passToNext) {
39
40
  req.locals.data = data;
40
41
  next();
@@ -1 +1 @@
1
- {"version":3,"file":"generateFindMany.js","sourceRoot":"","sources":["../../src/helpers/generateFindMany.ts"],"names":[],"mappings":";;;AAQO,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,SAAS,CAAC,WAAW,EAAE,0BAA0B,aAAa;;;;;;;;;;;;;;;;;;;;;EAqBhG,CAAA;AACF,CAAC,CAAA;AA3DY,QAAA,wBAAwB,4BA2DpC"}
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;;;;;;;;;;;;;;;;;;;;;EAqBxG,CAAA;AACF,CAAC,CAAA;AA3DY,QAAA,wBAAwB,4BA2DpC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateFindUniqueFunction = void 0;
4
+ const strings_1 = require("../utils/strings");
4
5
  const generateFindUniqueFunction = (options) => {
5
6
  const { model, prismaImportStatement } = options;
6
7
  const modelName = model.name;
@@ -34,7 +35,7 @@ export async function ${functionName}(req: FindUniqueRequest, res: Response, nex
34
35
  throw new Error('Output validation schema or omission flag must be provided.');
35
36
  }
36
37
 
37
- const data = await req.prisma.${modelName.toLowerCase()}.findUnique(req.query as ${queryTypeName});
38
+ const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.findUnique(req.query as ${queryTypeName});
38
39
  if (req.passToNext) {
39
40
  req.locals.data = data;
40
41
  next();
@@ -1 +1 @@
1
- {"version":3,"file":"generateFindUnique.js","sourceRoot":"","sources":["../../src/helpers/generateFindUnique.ts"],"names":[],"mappings":";;;AAQO,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,aAAa,GAAG,UAAU,SAAS,gBAAgB,CAAA;IAEzD,OAAO;EACP,qBAAqB,CAAC,OAAO,CAAC,YAAY,EAAE,aAAa,SAAS,IAAI,CAAC;;;;;;;;;;;WAW9D,aAAa;;;;;aAKX,SAAS;;;gFAG0D,aAAa;;wBAErE,YAAY;;;;;;oCAMA,SAAS,CAAC,WAAW,EAAE,4BAA4B,aAAa;;;;;;;;;;;;;;;;;;;;;EAqBlG,CAAA;AACF,CAAC,CAAA;AA3DY,QAAA,0BAA0B,8BA2DtC"}
1
+ {"version":3,"file":"generateFindUnique.js","sourceRoot":"","sources":["../../src/helpers/generateFindUnique.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,aAAa,GAAG,UAAU,SAAS,gBAAgB,CAAA;IAEzD,OAAO;EACP,qBAAqB,CAAC,OAAO,CAAC,YAAY,EAAE,aAAa,SAAS,IAAI,CAAC;;;;;;;;;;;WAW9D,aAAa;;;;;aAKX,SAAS;;;gFAG0D,aAAa;;wBAErE,YAAY;;;;;;oCAMA,IAAA,8BAAoB,EAAC,SAAS,CAAC,4BAA4B,aAAa;;;;;;;;;;;;;;;;;;;;;EAqB1G,CAAA;AACF,CAAC,CAAA;AA3DY,QAAA,0BAA0B,8BA2DtC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateGroupByFunction = void 0;
4
+ const strings_1 = require("../utils/strings");
4
5
  const generateGroupByFunction = (options) => {
5
6
  const { model, prismaImportStatement } = options;
6
7
  const modelName = model.name;
@@ -9,17 +10,18 @@ const generateGroupByFunction = (options) => {
9
10
  return `
10
11
  ${prismaImportStatement}
11
12
  import { Request, Response, NextFunction } from 'express';
12
- import { RequestHandler, ParamsDictionary } from 'express-serve-static-core'
13
+ import { RequestHandler, ParamsDictionary } from 'express-serve-static-core';
14
+ import { ParsedQs } from 'qs';
13
15
  import { ZodTypeAny } from 'zod';
14
16
 
15
17
  interface GroupByRequest extends Request {
16
18
  prisma: PrismaClient;
17
- body: ${argsTypeName};
19
+ query: Partial<${argsTypeName}> & ParsedQs;
18
20
  outputValidation?: ZodTypeAny;
19
21
  omitOutputValidation?: boolean;
20
22
  }
21
23
 
22
- export type GroupByMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>;
24
+ export type GroupByMiddleware = RequestHandler<ParamsDictionary, any, {}, ParsedQs>;
23
25
 
24
26
  export async function ${functionName}(req: GroupByRequest, res: Response, next: NextFunction) {
25
27
  try {
@@ -27,7 +29,8 @@ export async function ${functionName}(req: GroupByRequest, res: Response, next:
27
29
  throw new Error('Output validation schema or omission flag must be provided.');
28
30
  }
29
31
 
30
- const result = await req.prisma.${modelName.toLowerCase()}.groupBy(req.body);
32
+ // @ts-ignore
33
+ const result = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.groupBy(req.query);
31
34
 
32
35
  if (!req.omitOutputValidation && req.outputValidation) {
33
36
  const validationResult = req.outputValidation.safeParse(result);
@@ -1 +1 @@
1
- {"version":3,"file":"generateGroupBy.js","sourceRoot":"","sources":["../../src/helpers/generateGroupBy.ts"],"names":[],"mappings":";;;AASO,MAAM,uBAAuB,GAAG,CAAC,OAGvC,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,SAAS,CAAA;IAC1C,MAAM,YAAY,GAAG,UAAU,SAAS,aAAa,CAAA;IAErD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;wEAKkD,YAAY;;wBAE5D,YAAY;;;;;;sCAME,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;EAiB3D,CAAA;AACF,CAAC,CAAA;AAhDY,QAAA,uBAAuB,2BAgDnC"}
1
+ {"version":3,"file":"generateGroupBy.js","sourceRoot":"","sources":["../../src/helpers/generateGroupBy.ts"],"names":[],"mappings":";;;AACA,8CAAuD;AAUhD,MAAM,uBAAuB,GAAG,CAAC,OAGvC,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,SAAS,CAAA;IAC1C,MAAM,YAAY,GAAG,UAAU,SAAS,aAAa,CAAA;IAErD,OAAO;EACP,qBAAqB;;;;;;;;mBAQJ,YAAY;;;;;;;wBAOP,YAAY;;;;;;;sCAOE,IAAA,8BAAoB,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;;;EAiBnE,CAAA;AACF,CAAC,CAAA;AAlDY,QAAA,uBAAuB,2BAkDnC"}
@@ -98,7 +98,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
98
98
  if (config.createNextMiddleware) {
99
99
  middlewares.push(...config.createNextMiddleware);
100
100
  }
101
- router.post('/', ...middlewares);
101
+ router.post('/', ...middlewares as CreateMiddleware[]);
102
102
  }
103
103
 
104
104
  if (config?.createManyMiddleware && config?.createManyMiddleware.length) {
@@ -106,7 +106,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
106
106
  if (config.createManyNextMiddleware) {
107
107
  middlewares.push(...config.createManyNextMiddleware);
108
108
  }
109
- router.post('/many', ...middlewares);
109
+ router.post('/many', ...middlewares as CreateManyMiddleware[]);
110
110
  }
111
111
 
112
112
  if (config?.updateMiddleware && config?.updateMiddleware.length) {
@@ -114,7 +114,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
114
114
  if (config.updateNextMiddleware) {
115
115
  middlewares.push(...config.updateNextMiddleware);
116
116
  }
117
- router.put('/', ...middlewares);
117
+ router.put('/', ...middlewares as UpdateMiddleware[]);
118
118
  }
119
119
 
120
120
  if (config?.updateManyMiddleware && config?.updateManyMiddleware.length) {
@@ -122,7 +122,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
122
122
  if (config.updateManyNextMiddleware) {
123
123
  middlewares.push(...config.updateManyNextMiddleware);
124
124
  }
125
- router.put('/many', ...middlewares);
125
+ router.put('/many', ...middlewares as UpdateManyMiddleware[]);
126
126
  }
127
127
 
128
128
  if (config?.upsertMiddleware && config?.upsertMiddleware.length) {
@@ -130,7 +130,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
130
130
  if (config.upsertNextMiddleware) {
131
131
  middlewares.push(...config.upsertNextMiddleware);
132
132
  }
133
- router.patch('/', ...middlewares);
133
+ router.patch('/', ...middlewares as UpsertMiddleware[]);
134
134
  }
135
135
 
136
136
  if (config?.deleteMiddleware && config?.deleteMiddleware.length) {
@@ -138,7 +138,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
138
138
  if (config.deleteNextMiddleware) {
139
139
  middlewares.push(...config.deleteNextMiddleware);
140
140
  }
141
- router.delete('/', ...middlewares);
141
+ router.delete('/', ...middlewares as DeleteMiddleware[]);
142
142
  }
143
143
 
144
144
  if (config?.deleteManyMiddleware && config?.deleteManyMiddleware.length) {
@@ -146,7 +146,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
146
146
  if (config.deleteManyNextMiddleware) {
147
147
  middlewares.push(...config.deleteManyNextMiddleware);
148
148
  }
149
- router.delete('/many', ...middlewares);
149
+ router.delete('/many', ...middlewares as DeleteManyMiddleware[]);
150
150
  }
151
151
 
152
152
  if (config?.aggregateMiddleware && config?.aggregateMiddleware.length) {
@@ -154,7 +154,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
154
154
  if (config.aggregateNextMiddleware) {
155
155
  middlewares.push(...config.aggregateNextMiddleware);
156
156
  }
157
- router.get('/aggregate', ...middlewares);
157
+ router.get('/aggregate', ...middlewares as AggregateMiddleware[]);
158
158
  }
159
159
 
160
160
  if (config?.countMiddleware && config?.countMiddleware.length) {
@@ -162,7 +162,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
162
162
  if (config.countNextMiddleware) {
163
163
  middlewares.push(...config.countNextMiddleware);
164
164
  }
165
- router.get('/count', ...middlewares);
165
+ router.get('/count', ...middlewares as CountMiddleware[]);
166
166
  }
167
167
 
168
168
  if (config?.groupByMiddleware && config?.groupByMiddleware.length) {
@@ -170,7 +170,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
170
170
  if (config.groupByNextMiddleware) {
171
171
  middlewares.push(...config.groupByNextMiddleware);
172
172
  }
173
- router.get('/groupby', ...middlewares);
173
+ router.get('/groupby', ...middlewares as GroupByMiddleware[]);
174
174
  }
175
175
 
176
176
  return router;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateUpdateFunction = void 0;
4
+ const strings_1 = require("../utils/strings");
4
5
  const generateUpdateFunction = (options) => {
5
6
  const { model, prismaImportStatement } = options;
6
7
  const modelName = model.name;
@@ -27,10 +28,7 @@ export async function ${functionName}(req: UpdateRequest, res: Response, next: N
27
28
  throw new Error('Output validation schema or omission flag must be provided.');
28
29
  }
29
30
 
30
- const data = await req.prisma.${modelName.toLowerCase()}.update({
31
- where: { id: parseInt(req.params.id) },
32
- data: req.body
33
- });
31
+ const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.update(req.body);
34
32
 
35
33
  if (!req.omitOutputValidation && req.outputValidation) {
36
34
  const validationResult = req.outputValidation.safeParse(data);
@@ -1 +1 @@
1
- {"version":3,"file":"generateUpdate.js","sourceRoot":"","sources":["../../src/helpers/generateUpdate.ts"],"names":[],"mappings":";;;AAQO,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,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;EAsBzD,CAAA;AACF,CAAC,CAAA;AArDY,QAAA,sBAAsB,0BAqDlC"}
1
+ {"version":3,"file":"generateUpdate.js","sourceRoot":"","sources":["../../src/helpers/generateUpdate.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;;;;;;;;;;;;;;;;;;;EAmBjE,CAAA;AACF,CAAC,CAAA;AAlDY,QAAA,sBAAsB,0BAkDlC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateUpdateManyFunction = void 0;
4
+ const strings_1 = require("../utils/strings");
4
5
  const generateUpdateManyFunction = (options) => {
5
6
  const { model, prismaImportStatement } = options;
6
7
  const modelName = model.name;
@@ -27,7 +28,7 @@ export async function ${functionName}(req: UpdateManyRequest, res: Response, nex
27
28
  throw new Error('Output validation schema or omission flag must be provided.');
28
29
  }
29
30
 
30
- const data = await req.prisma.${modelName.toLowerCase()}.updateMany(req.body);
31
+ const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.updateMany(req.body);
31
32
 
32
33
  if (!req.omitOutputValidation && req.outputValidation) {
33
34
  const validationResult = req.outputValidation.safeParse(data);
@@ -1 +1 @@
1
- {"version":3,"file":"generateUpdateMany.js","sourceRoot":"","sources":["../../src/helpers/generateUpdateMany.ts"],"names":[],"mappings":";;;AAQO,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,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;;;EAmBzD,CAAA;AACF,CAAC,CAAA;AAlDY,QAAA,0BAA0B,8BAkDtC"}
1
+ {"version":3,"file":"generateUpdateMany.js","sourceRoot":"","sources":["../../src/helpers/generateUpdateMany.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;;;;;;;;;;;;;;;;;;;EAmBjE,CAAA;AACF,CAAC,CAAA;AAlDY,QAAA,0BAA0B,8BAkDtC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateUpsertFunction = void 0;
4
+ const strings_1 = require("../utils/strings");
4
5
  const generateUpsertFunction = (options) => {
5
6
  const { model, prismaImportStatement } = options;
6
7
  const modelName = model.name;
@@ -27,7 +28,7 @@ export async function ${functionName}(req: UpsertRequest, res: Response, next: N
27
28
  throw new Error('Output validation schema or omission flag must be provided.');
28
29
  }
29
30
 
30
- const data = await req.prisma.${modelName.toLowerCase()}.upsert(req.body);
31
+ const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.upsert(req.body);
31
32
 
32
33
  if (!req.omitOutputValidation && req.outputValidation) {
33
34
  const validationResult = req.outputValidation.safeParse(data);
@@ -1 +1 @@
1
- {"version":3,"file":"generateUpsert.js","sourceRoot":"","sources":["../../src/helpers/generateUpsert.ts"],"names":[],"mappings":";;;AASO,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,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;;;EAmBzD,CAAA;AACF,CAAC,CAAA;AAlDY,QAAA,sBAAsB,0BAkDlC"}
1
+ {"version":3,"file":"generateUpsert.js","sourceRoot":"","sources":["../../src/helpers/generateUpsert.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;;;;;;;;;;;;;;;;;;;EAmBjE,CAAA;AACF,CAAC,CAAA;AAlDY,QAAA,sBAAsB,0BAkDlC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lowercaseFirstLetter = exports.capitalize = void 0;
4
+ const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
5
+ exports.capitalize = capitalize;
6
+ function lowercaseFirstLetter(str) {
7
+ if (!str)
8
+ return str;
9
+ return str.charAt(0).toLowerCase() + str.slice(1);
10
+ }
11
+ exports.lowercaseFirstLetter = lowercaseFirstLetter;
12
+ //# sourceMappingURL=strings.js.map
@@ -0,0 +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"}
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.2.0",
4
+ "version": "1.3.0",
5
5
  "main": "dist/generator.js",
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -27,6 +27,7 @@
27
27
  "zod": "^3.23.8"
28
28
  },
29
29
  "devDependencies": {
30
+ "@prisma/internals": "^5.14.0",
30
31
  "@semantic-release/changelog": "^6.0.3",
31
32
  "@semantic-release/git": "^10.0.1",
32
33
  "@types/express": "^4.17.21",
@@ -37,7 +38,6 @@
37
38
  "prisma": "5.14.0",
38
39
  "semantic-release": "^23.1.1",
39
40
  "ts-jest": "29.1.2",
40
- "shx": "^0.3.4",
41
41
  "typescript": "5.4.5"
42
42
  },
43
43
  "homepage": "https://github.com/multipliedtwice/prisma-generator-express/blob/master/README.md",
@@ -1,4 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
+ import { capitalize, lowercaseFirstLetter } from '../utils/strings'
2
3
 
3
4
  /**
4
5
  * Generates an Express middleware function that handles aggregation queries
@@ -14,22 +15,23 @@ export const generateAggregateFunction = (options: {
14
15
  const { model, prismaImportStatement } = options
15
16
  const modelName = model.name
16
17
  const functionName = `${modelName}Aggregate`
17
- const argsTypeName = `Prisma.${modelName}AggregateArgs`
18
+ const argsTypeName = `Prisma.${capitalize(modelName)}AggregateArgs`
18
19
 
19
20
  return `
20
21
  ${prismaImportStatement}
21
22
  import { Request, Response, NextFunction } from 'express';
22
23
  import { RequestHandler, ParamsDictionary } from 'express-serve-static-core'
24
+ import { ParsedQs } from 'qs'
23
25
  import { ZodTypeAny } from 'zod';
24
26
 
25
27
  interface AggregateRequest extends Request {
26
28
  prisma: PrismaClient;
27
- body: ${argsTypeName};
29
+ query: Partial<${argsTypeName}> & ParsedQs;
28
30
  outputValidation?: ZodTypeAny;
29
31
  omitOutputValidation?: boolean;
30
32
  }
31
33
 
32
- export type AggregateMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>;
34
+ export type AggregateMiddleware = RequestHandler<ParamsDictionary, any, Partial<${argsTypeName}>, Record<string, any>>;
33
35
 
34
36
  export async function ${functionName}(req: AggregateRequest, res: Response, next: NextFunction) {
35
37
  try {
@@ -37,7 +39,7 @@ export async function ${functionName}(req: AggregateRequest, res: Response, next
37
39
  throw new Error('Output validation schema or omission flag must be provided.');
38
40
  }
39
41
 
40
- const result = await req.prisma.${modelName.toLowerCase()}.aggregate(req.body);
42
+ const result = await req.prisma.${lowercaseFirstLetter(modelName)}.aggregate(req.query as ${argsTypeName});
41
43
 
42
44
  if (!req.omitOutputValidation && req.outputValidation) {
43
45
  const validationResult = req.outputValidation.safeParse(result);
@@ -1,4 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
+ import { lowercaseFirstLetter } from '../utils/strings'
2
3
 
3
4
  /**
4
5
  * Generates an Express middleware function that handles count queries
@@ -19,17 +20,18 @@ export const generateCountFunction = (options: {
19
20
  return `
20
21
  ${prismaImportStatement}
21
22
  import { Request, Response, NextFunction } from 'express';
22
- import { RequestHandler, ParamsDictionary } from 'express-serve-static-core'
23
+ import { RequestHandler, ParamsDictionary } from 'express-serve-static-core';
24
+ import { ParsedQs } from 'qs';
23
25
  import { ZodTypeAny } from 'zod';
24
26
 
25
27
  interface CountRequest extends Request {
26
28
  prisma: PrismaClient;
27
- body: ${argsTypeName};
29
+ query: Partial<${argsTypeName}> & ParsedQs;
28
30
  outputValidation?: ZodTypeAny;
29
31
  omitOutputValidation?: boolean;
30
32
  }
31
33
 
32
- export type CountMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>;
34
+ export type CountMiddleware = RequestHandler<ParamsDictionary, any, {}, ParsedQs>;
33
35
 
34
36
  export async function ${functionName}(req: CountRequest, res: Response, next: NextFunction) {
35
37
  try {
@@ -37,7 +39,7 @@ export async function ${functionName}(req: CountRequest, res: Response, next: Ne
37
39
  throw new Error('Output validation schema or omission flag must be provided.');
38
40
  }
39
41
 
40
- const result = await req.prisma.${modelName.toLowerCase()}.count(req.body);
42
+ const result = await req.prisma.${lowercaseFirstLetter(modelName)}.count(req.query as ${argsTypeName});
41
43
 
42
44
  if (!req.omitOutputValidation && req.outputValidation) {
43
45
  const validationResult = req.outputValidation.safeParse(result);
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
-
2
+ import { lowercaseFirstLetter } from '../utils/strings'
3
3
  /**
4
4
  * Generates an Express middleware function that handles creation of 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.
@@ -36,7 +36,7 @@ export async function ${functionName}(req: CreateRequest, res: Response, next: N
36
36
  throw new Error('Output validation schema or omission flag must be provided.');
37
37
  }
38
38
 
39
- const data = await req.prisma.${modelName.toLowerCase()}.create(req.body);
39
+ const data = await req.prisma.${lowercaseFirstLetter(modelName)}.create(req.body);
40
40
  if (!req.omitOutputValidation && req.outputValidation) {
41
41
  const validationResult = req.outputValidation.safeParse(data);
42
42
  if (validationResult.success) {
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
-
2
+ import { lowercaseFirstLetter } 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.
@@ -36,7 +36,7 @@ export async function ${functionName}(req: CreateManyRequest, res: Response, nex
36
36
  throw new Error('Output validation schema or omission flag must be provided.');
37
37
  }
38
38
 
39
- const data = await req.prisma.${modelName.toLowerCase()}.createMany(req.body);
39
+ const data = await req.prisma.${lowercaseFirstLetter(modelName)}.createMany(req.body);
40
40
  if (!req.omitOutputValidation && req.outputValidation) {
41
41
  const validationResult = req.outputValidation.safeParse(data);
42
42
  if (validationResult.success) {
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
-
2
+ import { lowercaseFirstLetter } from '../utils/strings'
3
3
  /**
4
4
  * Generates an Express middleware function that handles deleting records
5
5
  * and includes conditional output validation with Zod.
@@ -37,7 +37,7 @@ export async function ${functionName}(req: DeleteRequest, res: Response, next: N
37
37
  throw new Error('Output validation schema or omission flag must be provided.');
38
38
  }
39
39
 
40
- const data = await req.prisma.${modelName.toLowerCase()}.delete(req.body);
40
+ const data = await req.prisma.${lowercaseFirstLetter(modelName)}.delete(req.body);
41
41
 
42
42
  if (!req.omitOutputValidation && req.outputValidation) {
43
43
  const validationResult = req.outputValidation.safeParse(data);
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
-
2
+ import { lowercaseFirstLetter } from '../utils/strings'
3
3
  /**
4
4
  * Generates an Express middleware function that handles batch deleting records
5
5
  * and includes conditional output validation with Zod.
@@ -37,7 +37,7 @@ export async function ${functionName}(req: DeleteManyRequest, res: Response, nex
37
37
  throw new Error('Output validation schema or omission flag must be provided.');
38
38
  }
39
39
 
40
- const result = await req.prisma.${modelName.toLowerCase()}.deleteMany(req.body);
40
+ const result = await req.prisma.${lowercaseFirstLetter(modelName)}.deleteMany(req.body);
41
41
 
42
42
  if (!req.omitOutputValidation && req.outputValidation) {
43
43
  const validationResult = req.outputValidation.safeParse(result);
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
-
2
+ import { lowercaseFirstLetter } from '../utils/strings'
3
3
  /**
4
4
  * Generates an Express middleware function that includes conditional output validation with Zod.
5
5
  * This version dynamically includes the correct type for the query parameter based on the Prisma model.
@@ -43,7 +43,7 @@ export async function ${functionName}(req: FindFirstRequest, res: Response, next
43
43
  throw new Error('Output validation schema or omission flag must be provided.');
44
44
  }
45
45
 
46
- const data = await req.prisma.${modelName.toLowerCase()}.findFirst(req.query as ${queryTypeName});
46
+ const data = await req.prisma.${lowercaseFirstLetter(modelName)}.findFirst(req.query as ${queryTypeName});
47
47
  if (req.passToNext) {
48
48
  req.locals.data = data;
49
49
  next();
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
-
2
+ import { lowercaseFirstLetter } from '../utils/strings'
3
3
  /**
4
4
  * Generates an Express middleware function that handles multiple record retrieval with optional output validation using Zod.
5
5
  * This version dynamically includes the correct type for the query parameter based on the Prisma model.
@@ -43,7 +43,7 @@ export async function ${functionName}(req: FindManyRequest, res: Response, next:
43
43
  throw new Error('Output validation schema or omission flag must be provided.');
44
44
  }
45
45
 
46
- const data = await req.prisma.${modelName.toLowerCase()}.findMany(req.query as ${queryTypeName});
46
+ const data = await req.prisma.${lowercaseFirstLetter(modelName)}.findMany(req.query as ${queryTypeName});
47
47
  if (req.passToNext) {
48
48
  req.locals.data = data;
49
49
  next();
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
-
2
+ import { lowercaseFirstLetter } from '../utils/strings'
3
3
  /**
4
4
  * Generates an Express middleware function that includes conditional output validation with Zod.
5
5
  * This version dynamically includes the correct type for the query parameter based on the Prisma model.
@@ -43,7 +43,7 @@ export async function ${functionName}(req: FindUniqueRequest, res: Response, nex
43
43
  throw new Error('Output validation schema or omission flag must be provided.');
44
44
  }
45
45
 
46
- const data = await req.prisma.${modelName.toLowerCase()}.findUnique(req.query as ${queryTypeName});
46
+ const data = await req.prisma.${lowercaseFirstLetter(modelName)}.findUnique(req.query as ${queryTypeName});
47
47
  if (req.passToNext) {
48
48
  req.locals.data = data;
49
49
  next();
@@ -1,4 +1,6 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
+ import { lowercaseFirstLetter } from '../utils/strings'
3
+ import { PrismaClient, Prisma } from '@prisma/client'
2
4
 
3
5
  /**
4
6
  * Generates an Express middleware function that handles groupBy queries
@@ -19,17 +21,18 @@ export const generateGroupByFunction = (options: {
19
21
  return `
20
22
  ${prismaImportStatement}
21
23
  import { Request, Response, NextFunction } from 'express';
22
- import { RequestHandler, ParamsDictionary } from 'express-serve-static-core'
24
+ import { RequestHandler, ParamsDictionary } from 'express-serve-static-core';
25
+ import { ParsedQs } from 'qs';
23
26
  import { ZodTypeAny } from 'zod';
24
27
 
25
28
  interface GroupByRequest extends Request {
26
29
  prisma: PrismaClient;
27
- body: ${argsTypeName};
30
+ query: Partial<${argsTypeName}> & ParsedQs;
28
31
  outputValidation?: ZodTypeAny;
29
32
  omitOutputValidation?: boolean;
30
33
  }
31
34
 
32
- export type GroupByMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>;
35
+ export type GroupByMiddleware = RequestHandler<ParamsDictionary, any, {}, ParsedQs>;
33
36
 
34
37
  export async function ${functionName}(req: GroupByRequest, res: Response, next: NextFunction) {
35
38
  try {
@@ -37,7 +40,8 @@ export async function ${functionName}(req: GroupByRequest, res: Response, next:
37
40
  throw new Error('Output validation schema or omission flag must be provided.');
38
41
  }
39
42
 
40
- const result = await req.prisma.${modelName.toLowerCase()}.groupBy(req.body);
43
+ // @ts-ignore
44
+ const result = await req.prisma.${lowercaseFirstLetter(modelName)}.groupBy(req.query);
41
45
 
42
46
  if (!req.omitOutputValidation && req.outputValidation) {
43
47
  const validationResult = req.outputValidation.safeParse(result);
@@ -102,7 +102,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
102
102
  if (config.createNextMiddleware) {
103
103
  middlewares.push(...config.createNextMiddleware);
104
104
  }
105
- router.post('/', ...middlewares);
105
+ router.post('/', ...middlewares as CreateMiddleware[]);
106
106
  }
107
107
 
108
108
  if (config?.createManyMiddleware && config?.createManyMiddleware.length) {
@@ -110,7 +110,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
110
110
  if (config.createManyNextMiddleware) {
111
111
  middlewares.push(...config.createManyNextMiddleware);
112
112
  }
113
- router.post('/many', ...middlewares);
113
+ router.post('/many', ...middlewares as CreateManyMiddleware[]);
114
114
  }
115
115
 
116
116
  if (config?.updateMiddleware && config?.updateMiddleware.length) {
@@ -118,7 +118,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
118
118
  if (config.updateNextMiddleware) {
119
119
  middlewares.push(...config.updateNextMiddleware);
120
120
  }
121
- router.put('/', ...middlewares);
121
+ router.put('/', ...middlewares as UpdateMiddleware[]);
122
122
  }
123
123
 
124
124
  if (config?.updateManyMiddleware && config?.updateManyMiddleware.length) {
@@ -126,7 +126,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
126
126
  if (config.updateManyNextMiddleware) {
127
127
  middlewares.push(...config.updateManyNextMiddleware);
128
128
  }
129
- router.put('/many', ...middlewares);
129
+ router.put('/many', ...middlewares as UpdateManyMiddleware[]);
130
130
  }
131
131
 
132
132
  if (config?.upsertMiddleware && config?.upsertMiddleware.length) {
@@ -134,7 +134,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
134
134
  if (config.upsertNextMiddleware) {
135
135
  middlewares.push(...config.upsertNextMiddleware);
136
136
  }
137
- router.patch('/', ...middlewares);
137
+ router.patch('/', ...middlewares as UpsertMiddleware[]);
138
138
  }
139
139
 
140
140
  if (config?.deleteMiddleware && config?.deleteMiddleware.length) {
@@ -142,7 +142,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
142
142
  if (config.deleteNextMiddleware) {
143
143
  middlewares.push(...config.deleteNextMiddleware);
144
144
  }
145
- router.delete('/', ...middlewares);
145
+ router.delete('/', ...middlewares as DeleteMiddleware[]);
146
146
  }
147
147
 
148
148
  if (config?.deleteManyMiddleware && config?.deleteManyMiddleware.length) {
@@ -150,7 +150,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
150
150
  if (config.deleteManyNextMiddleware) {
151
151
  middlewares.push(...config.deleteManyNextMiddleware);
152
152
  }
153
- router.delete('/many', ...middlewares);
153
+ router.delete('/many', ...middlewares as DeleteManyMiddleware[]);
154
154
  }
155
155
 
156
156
  if (config?.aggregateMiddleware && config?.aggregateMiddleware.length) {
@@ -158,7 +158,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
158
158
  if (config.aggregateNextMiddleware) {
159
159
  middlewares.push(...config.aggregateNextMiddleware);
160
160
  }
161
- router.get('/aggregate', ...middlewares);
161
+ router.get('/aggregate', ...middlewares as AggregateMiddleware[]);
162
162
  }
163
163
 
164
164
  if (config?.countMiddleware && config?.countMiddleware.length) {
@@ -166,7 +166,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
166
166
  if (config.countNextMiddleware) {
167
167
  middlewares.push(...config.countNextMiddleware);
168
168
  }
169
- router.get('/count', ...middlewares);
169
+ router.get('/count', ...middlewares as CountMiddleware[]);
170
170
  }
171
171
 
172
172
  if (config?.groupByMiddleware && config?.groupByMiddleware.length) {
@@ -174,7 +174,7 @@ export function ${routerFunctionName}(config: RouteConfig) {
174
174
  if (config.groupByNextMiddleware) {
175
175
  middlewares.push(...config.groupByNextMiddleware);
176
176
  }
177
- router.get('/groupby', ...middlewares);
177
+ router.get('/groupby', ...middlewares as GroupByMiddleware[]);
178
178
  }
179
179
 
180
180
  return router;
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
-
2
+ import { lowercaseFirstLetter } from '../utils/strings'
3
3
  /**
4
4
  * Generates an Express middleware function that handles updating 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.
@@ -36,10 +36,7 @@ export async function ${functionName}(req: UpdateRequest, res: Response, next: N
36
36
  throw new Error('Output validation schema or omission flag must be provided.');
37
37
  }
38
38
 
39
- const data = await req.prisma.${modelName.toLowerCase()}.update({
40
- where: { id: parseInt(req.params.id) },
41
- data: req.body
42
- });
39
+ const data = await req.prisma.${lowercaseFirstLetter(modelName)}.update(req.body);
43
40
 
44
41
  if (!req.omitOutputValidation && req.outputValidation) {
45
42
  const validationResult = req.outputValidation.safeParse(data);
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
-
2
+ import { lowercaseFirstLetter } from '../utils/strings'
3
3
  /**
4
4
  * Generates an Express middleware function that handles updating 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.
@@ -36,7 +36,7 @@ export async function ${functionName}(req: UpdateManyRequest, res: Response, nex
36
36
  throw new Error('Output validation schema or omission flag must be provided.');
37
37
  }
38
38
 
39
- const data = await req.prisma.${modelName.toLowerCase()}.updateMany(req.body);
39
+ const data = await req.prisma.${lowercaseFirstLetter(modelName)}.updateMany(req.body);
40
40
 
41
41
  if (!req.omitOutputValidation && req.outputValidation) {
42
42
  const validationResult = req.outputValidation.safeParse(data);
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
-
2
+ import { lowercaseFirstLetter } from '../utils/strings'
3
3
  /**
4
4
  * Generates an Express middleware function that handles the upsert operation (create or update)
5
5
  * and includes conditional output validation with Zod.
@@ -37,7 +37,7 @@ export async function ${functionName}(req: UpsertRequest, res: Response, next: N
37
37
  throw new Error('Output validation schema or omission flag must be provided.');
38
38
  }
39
39
 
40
- const data = await req.prisma.${modelName.toLowerCase()}.upsert(req.body);
40
+ const data = await req.prisma.${lowercaseFirstLetter(modelName)}.upsert(req.body);
41
41
 
42
42
  if (!req.omitOutputValidation && req.outputValidation) {
43
43
  const validationResult = req.outputValidation.safeParse(data);
@@ -0,0 +1,7 @@
1
+ export const capitalize = (str: string) =>
2
+ str.charAt(0).toUpperCase() + str.slice(1)
3
+
4
+ export function lowercaseFirstLetter(str: string) {
5
+ if (!str) return str
6
+ return str.charAt(0).toLowerCase() + str.slice(1)
7
+ }