prisma-generator-express 1.15.0 → 1.16.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.
- package/README.md +0 -2
- package/dist/helpers/generateAggregate.js +4 -9
- package/dist/helpers/generateAggregate.js.map +1 -1
- package/dist/helpers/generateCount.js +4 -9
- package/dist/helpers/generateCount.js.map +1 -1
- package/dist/helpers/generateCreate.js +4 -9
- package/dist/helpers/generateCreate.js.map +1 -1
- package/dist/helpers/generateCreateMany.js +4 -9
- package/dist/helpers/generateCreateMany.js.map +1 -1
- package/dist/helpers/generateDelete.js +4 -9
- package/dist/helpers/generateDelete.js.map +1 -1
- package/dist/helpers/generateDeleteMany.js +4 -9
- package/dist/helpers/generateDeleteMany.js.map +1 -1
- package/dist/helpers/generateFindFirst.js +4 -9
- package/dist/helpers/generateFindFirst.js.map +1 -1
- package/dist/helpers/generateFindMany.js +4 -9
- package/dist/helpers/generateFindMany.js.map +1 -1
- package/dist/helpers/generateFindUnique.js +4 -9
- package/dist/helpers/generateFindUnique.js.map +1 -1
- package/dist/helpers/generateGroupBy.js +4 -9
- package/dist/helpers/generateGroupBy.js.map +1 -1
- package/dist/helpers/generateRouteFile.js +28 -28
- package/dist/helpers/generateUpdate.js +4 -9
- package/dist/helpers/generateUpdate.js.map +1 -1
- package/dist/helpers/generateUpdateMany.js +4 -9
- package/dist/helpers/generateUpdateMany.js.map +1 -1
- package/dist/helpers/generateUpsert.js +4 -9
- package/dist/helpers/generateUpsert.js.map +1 -1
- package/dist/utils/strings.js +3 -3
- package/dist/utils/strings.js.map +1 -1
- package/package.json +6 -6
- package/src/copy/routeConfig.ts +2 -2
- package/src/helpers/generateAggregate.ts +5 -10
- package/src/helpers/generateCount.ts +5 -10
- package/src/helpers/generateCreate.ts +5 -10
- package/src/helpers/generateCreateMany.ts +5 -10
- package/src/helpers/generateDelete.ts +5 -10
- package/src/helpers/generateDeleteMany.ts +5 -10
- package/src/helpers/generateFindFirst.ts +5 -10
- package/src/helpers/generateFindMany.ts +5 -10
- package/src/helpers/generateFindUnique.ts +5 -10
- package/src/helpers/generateGroupBy.ts +5 -10
- package/src/helpers/generateRouteFile.ts +28 -28
- package/src/helpers/generateUpdate.ts +5 -10
- package/src/helpers/generateUpdateMany.ts +5 -10
- package/src/helpers/generateUpsert.ts +5 -10
- package/src/utils/strings.ts +1 -1
|
@@ -17,7 +17,6 @@ interface UpdateManyRequest extends Request {
|
|
|
17
17
|
prisma: PrismaClient;
|
|
18
18
|
body: ${argsTypeName};
|
|
19
19
|
outputValidation?: ZodTypeAny;
|
|
20
|
-
omitOutputValidation?: boolean;
|
|
21
20
|
locals?: {
|
|
22
21
|
outputValidator?: ZodTypeAny;
|
|
23
22
|
};
|
|
@@ -29,13 +28,9 @@ export async function ${functionName}(req: UpdateManyRequest, res: Response, nex
|
|
|
29
28
|
try {
|
|
30
29
|
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
throw new Error('Output validation schema or omission flag must be provided.');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.updateMany(req.body);
|
|
31
|
+
const data = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.updateMany(req.body);
|
|
37
32
|
|
|
38
|
-
if (
|
|
33
|
+
if (outputValidator) {
|
|
39
34
|
const validationResult = outputValidator.safeParse(data);
|
|
40
35
|
if (validationResult.success) {
|
|
41
36
|
return res.status(200).json({ count: validationResult.data.count });
|
|
@@ -45,8 +40,8 @@ export async function ${functionName}(req: UpdateManyRequest, res: Response, nex
|
|
|
45
40
|
} else {
|
|
46
41
|
return res.status(200).json({ count: data.count });
|
|
47
42
|
}
|
|
48
|
-
} catch
|
|
49
|
-
|
|
43
|
+
} catch(error: unknown) {
|
|
44
|
+
next(error)
|
|
50
45
|
}
|
|
51
46
|
}`;
|
|
52
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateUpdateMany.js","sourceRoot":"","sources":["../../src/helpers/generateUpdateMany.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"generateUpdateMany.js","sourceRoot":"","sources":["../../src/helpers/generateUpdateMany.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AAQxC,MAAM,0BAA0B,GAAG,CAAC,OAG1C,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,YAAY,CAAA;IAC7C,MAAM,YAAY,GAAG,UAAU,SAAS,gBAAgB,CAAA;IAExD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;;;2EAOqD,YAAY;;wBAE/D,YAAY;;;;oCAIA,IAAA,sBAAY,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;EAezD,CAAA;AACF,CAAC,CAAA;AA9CY,QAAA,0BAA0B,8BA8CtC"}
|
|
@@ -17,7 +17,6 @@ interface UpsertRequest extends Request {
|
|
|
17
17
|
prisma: PrismaClient;
|
|
18
18
|
body: ${argsTypeName};
|
|
19
19
|
outputValidation?: ZodTypeAny;
|
|
20
|
-
omitOutputValidation?: boolean;
|
|
21
20
|
locals?: {
|
|
22
21
|
outputValidator?: ZodTypeAny;
|
|
23
22
|
};
|
|
@@ -29,13 +28,9 @@ export async function ${functionName}(req: UpsertRequest, res: Response, next: N
|
|
|
29
28
|
try {
|
|
30
29
|
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
throw new Error('Output validation schema or omission flag must be provided.');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const data = await req.prisma.${(0, strings_1.lowercaseFirstLetter)(modelName)}.upsert(req.body);
|
|
31
|
+
const data = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.upsert(req.body);
|
|
37
32
|
|
|
38
|
-
if (
|
|
33
|
+
if (outputValidator) {
|
|
39
34
|
const validationResult = outputValidator.safeParse(data);
|
|
40
35
|
if (validationResult.success) {
|
|
41
36
|
return res.status(200).json(validationResult.data);
|
|
@@ -45,8 +40,8 @@ export async function ${functionName}(req: UpsertRequest, res: Response, next: N
|
|
|
45
40
|
} else {
|
|
46
41
|
return res.status(200).json(data);
|
|
47
42
|
}
|
|
48
|
-
} catch
|
|
49
|
-
|
|
43
|
+
} catch(error: unknown) {
|
|
44
|
+
next(error)
|
|
50
45
|
}
|
|
51
46
|
}`;
|
|
52
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateUpsert.js","sourceRoot":"","sources":["../../src/helpers/generateUpsert.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"generateUpsert.js","sourceRoot":"","sources":["../../src/helpers/generateUpsert.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AASxC,MAAM,sBAAsB,GAAG,CAAC,OAGtC,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,QAAQ,CAAA;IACzC,MAAM,YAAY,GAAG,UAAU,SAAS,YAAY,CAAA;IAEpD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;;;uEAOiD,YAAY;;wBAE3D,YAAY;;;;oCAIA,IAAA,sBAAY,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;EAezD,CAAA;AACF,CAAC,CAAA;AA9CY,QAAA,sBAAsB,0BA8ClC"}
|
package/dist/utils/strings.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.toPascalCase = exports.capitalize = void 0;
|
|
4
4
|
const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
5
5
|
exports.capitalize = capitalize;
|
|
6
|
-
function
|
|
6
|
+
function toPascalCase(str) {
|
|
7
7
|
if (!str)
|
|
8
8
|
return str;
|
|
9
9
|
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
10
10
|
}
|
|
11
|
-
exports.
|
|
11
|
+
exports.toPascalCase = toPascalCase;
|
|
12
12
|
//# sourceMappingURL=strings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strings.js","sourceRoot":"","sources":["../../src/utils/strings.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE,CACxC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAD/B,QAAA,UAAU,cACqB;AAE5C,SAAgB,
|
|
1
|
+
{"version":3,"file":"strings.js","sourceRoot":"","sources":["../../src/utils/strings.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE,CACxC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAD/B,QAAA,UAAU,cACqB;AAE5C,SAAgB,YAAY,CAAC,GAAW;IACtC,IAAI,CAAC,GAAG;QAAE,OAAO,GAAG,CAAA;IACpB,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AACnD,CAAC;AAHD,oCAGC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prisma-generator-express",
|
|
3
3
|
"description": "Prisma generator of Express CRUD API",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.16.0",
|
|
5
5
|
"main": "dist/generator.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"prepublishOnly": "node copy.js "
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@prisma/client": "5.
|
|
24
|
-
"@prisma/generator-helper": "5.
|
|
23
|
+
"@prisma/client": "5.15.0",
|
|
24
|
+
"@prisma/generator-helper": "5.15.0",
|
|
25
25
|
"@prisma/sdk": "4.0.0",
|
|
26
26
|
"express": "^4.19.2",
|
|
27
27
|
"lodash": "^4.17.21",
|
|
28
|
-
"prettier": "3.3.
|
|
28
|
+
"prettier": "3.3.2",
|
|
29
29
|
"zod": "^3.23.8"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"@types/express": "^4.17.21",
|
|
36
36
|
"@types/jest": "29.5.12",
|
|
37
37
|
"@types/lodash": "^4.17.4",
|
|
38
|
-
"@types/node": "20.14.
|
|
38
|
+
"@types/node": "20.14.2",
|
|
39
39
|
"@types/prettier": "3.0.0",
|
|
40
40
|
"jest": "29.7.0",
|
|
41
|
-
"prisma": "5.
|
|
41
|
+
"prisma": "5.15.0",
|
|
42
42
|
"semantic-release": "^24.0.0",
|
|
43
43
|
"ts-jest": "29.1.4",
|
|
44
44
|
"typescript": "5.4.5"
|
package/src/copy/routeConfig.ts
CHANGED
|
@@ -10,8 +10,8 @@ export interface ValidatorConfig {
|
|
|
10
10
|
interface MiddlewareConfig<M> {
|
|
11
11
|
before?: M[]
|
|
12
12
|
after?: RequestHandler[]
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
inputValidatior?: ValidatorConfig
|
|
14
|
+
outputValidatior?: ValidatorConfig
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export interface RouteConfig<M> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper'
|
|
2
|
-
import { capitalize,
|
|
2
|
+
import { capitalize, toPascalCase } from '../utils/strings'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Generates an Express middleware function that handles aggregation queries
|
|
@@ -29,7 +29,6 @@ interface AggregateRequest extends Request {
|
|
|
29
29
|
prisma: PrismaClient;
|
|
30
30
|
query: Partial<${argsTypeName}> & ParsedQs;
|
|
31
31
|
outputValidation?: ZodTypeAny;
|
|
32
|
-
omitOutputValidation?: boolean;
|
|
33
32
|
locals?: {
|
|
34
33
|
outputValidator?: ValidatorConfig;
|
|
35
34
|
};
|
|
@@ -41,13 +40,9 @@ export async function ${functionName}(req: AggregateRequest, res: Response, next
|
|
|
41
40
|
try {
|
|
42
41
|
const outputValidator = res.locals.outputValidator?.schema || req.outputValidation;
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
throw new Error('Output validation schema or omission flag must be provided.');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const result = await req.prisma.${lowercaseFirstLetter(modelName)}.aggregate(req.query as ${argsTypeName});
|
|
43
|
+
const result = await req.prisma.${toPascalCase(modelName)}.aggregate(req.query as ${argsTypeName});
|
|
49
44
|
|
|
50
|
-
if (
|
|
45
|
+
if (outputValidator) {
|
|
51
46
|
const validationResult = outputValidator.safeParse(result);
|
|
52
47
|
if (validationResult.success) {
|
|
53
48
|
return res.status(200).json(validationResult.data);
|
|
@@ -57,8 +52,8 @@ export async function ${functionName}(req: AggregateRequest, res: Response, next
|
|
|
57
52
|
} else {
|
|
58
53
|
return res.status(200).json(result);
|
|
59
54
|
}
|
|
60
|
-
} catch
|
|
61
|
-
|
|
55
|
+
} catch(error: unknown) {
|
|
56
|
+
next(error)
|
|
62
57
|
}
|
|
63
58
|
}`
|
|
64
59
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper'
|
|
2
|
-
import {
|
|
2
|
+
import { toPascalCase } from '../utils/strings'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Generates an Express middleware function that handles count queries
|
|
@@ -28,7 +28,6 @@ interface CountRequest extends Request {
|
|
|
28
28
|
prisma: PrismaClient;
|
|
29
29
|
query: Partial<${argsTypeName}> & ParsedQs;
|
|
30
30
|
outputValidation?: ZodTypeAny;
|
|
31
|
-
omitOutputValidation?: boolean;
|
|
32
31
|
locals?: {
|
|
33
32
|
outputValidator?: ZodTypeAny;
|
|
34
33
|
};
|
|
@@ -40,13 +39,9 @@ export async function ${functionName}(req: CountRequest, res: Response, next: Ne
|
|
|
40
39
|
try {
|
|
41
40
|
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
throw new Error('Output validation schema or omission flag must be provided.');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const result = await req.prisma.${lowercaseFirstLetter(modelName)}.count(req.query as ${argsTypeName});
|
|
42
|
+
const result = await req.prisma.${toPascalCase(modelName)}.count(req.query as ${argsTypeName});
|
|
48
43
|
|
|
49
|
-
if (
|
|
44
|
+
if (outputValidator) {
|
|
50
45
|
const validationResult = outputValidator.safeParse(result);
|
|
51
46
|
if (validationResult.success) {
|
|
52
47
|
return res.status(200).json(validationResult.data);
|
|
@@ -56,8 +51,8 @@ export async function ${functionName}(req: CountRequest, res: Response, next: Ne
|
|
|
56
51
|
} else {
|
|
57
52
|
return res.status(200).json(result);
|
|
58
53
|
}
|
|
59
|
-
} catch
|
|
60
|
-
|
|
54
|
+
} catch(error: unknown) {
|
|
55
|
+
next(error)
|
|
61
56
|
}
|
|
62
57
|
}`
|
|
63
58
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper'
|
|
2
|
-
import {
|
|
2
|
+
import { toPascalCase } from '../utils/strings'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Generates an Express middleware function that handles creation of records and includes conditional output validation with Zod.
|
|
@@ -26,7 +26,6 @@ interface CreateRequest extends Request {
|
|
|
26
26
|
prisma: PrismaClient;
|
|
27
27
|
body: ${argsTypeName};
|
|
28
28
|
outputValidation?: ZodTypeAny;
|
|
29
|
-
omitOutputValidation?: boolean;
|
|
30
29
|
locals?: {
|
|
31
30
|
outputValidator?: ZodTypeAny;
|
|
32
31
|
};
|
|
@@ -38,13 +37,9 @@ export async function ${functionName}(req: CreateRequest, res: Response, next: N
|
|
|
38
37
|
try {
|
|
39
38
|
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
throw new Error('Output validation schema or omission flag must be provided.');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const data = await req.prisma.${lowercaseFirstLetter(modelName)}.create(req.body);
|
|
40
|
+
const data = await req.prisma.${toPascalCase(modelName)}.create(req.body);
|
|
46
41
|
|
|
47
|
-
if (
|
|
42
|
+
if (outputValidator) {
|
|
48
43
|
const validationResult = outputValidator.safeParse(data);
|
|
49
44
|
if (validationResult.success) {
|
|
50
45
|
return res.status(201).json(validationResult.data);
|
|
@@ -54,8 +49,8 @@ export async function ${functionName}(req: CreateRequest, res: Response, next: N
|
|
|
54
49
|
} else {
|
|
55
50
|
return res.status(201).json(data);
|
|
56
51
|
}
|
|
57
|
-
} catch
|
|
58
|
-
|
|
52
|
+
} catch(error: unknown) {
|
|
53
|
+
next(error)
|
|
59
54
|
}
|
|
60
55
|
}`
|
|
61
56
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper'
|
|
2
|
-
import {
|
|
2
|
+
import { toPascalCase } from '../utils/strings'
|
|
3
3
|
/**
|
|
4
4
|
* Generates an Express middleware function that handles the creation of multiple records and includes conditional output validation with Zod.
|
|
5
5
|
* This version dynamically includes the correct type for the arguments based on the Prisma model.
|
|
@@ -25,7 +25,6 @@ interface CreateManyRequest extends Request {
|
|
|
25
25
|
prisma: PrismaClient;
|
|
26
26
|
body: ${argsTypeName};
|
|
27
27
|
outputValidation?: ZodTypeAny;
|
|
28
|
-
omitOutputValidation?: boolean;
|
|
29
28
|
locals?: {
|
|
30
29
|
outputValidator?: ZodTypeAny;
|
|
31
30
|
};
|
|
@@ -37,13 +36,9 @@ export async function ${functionName}(req: CreateManyRequest, res: Response, nex
|
|
|
37
36
|
try {
|
|
38
37
|
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
throw new Error('Output validation schema or omission flag must be provided.');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const data = await req.prisma.${lowercaseFirstLetter(modelName)}.createMany(req.body);
|
|
39
|
+
const data = await req.prisma.${toPascalCase(modelName)}.createMany(req.body);
|
|
45
40
|
|
|
46
|
-
if (
|
|
41
|
+
if (outputValidator) {
|
|
47
42
|
const validationResult = outputValidator.safeParse(data);
|
|
48
43
|
if (validationResult.success) {
|
|
49
44
|
return res.status(201).json(validationResult.data);
|
|
@@ -53,8 +48,8 @@ export async function ${functionName}(req: CreateManyRequest, res: Response, nex
|
|
|
53
48
|
} else {
|
|
54
49
|
return res.status(201).json(data);
|
|
55
50
|
}
|
|
56
|
-
} catch
|
|
57
|
-
|
|
51
|
+
} catch(error: unknown) {
|
|
52
|
+
next(error)
|
|
58
53
|
}
|
|
59
54
|
}`
|
|
60
55
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper'
|
|
2
|
-
import {
|
|
2
|
+
import { toPascalCase } from '../utils/strings'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Generates an Express middleware function that handles deleting records
|
|
@@ -27,7 +27,6 @@ interface DeleteRequest extends Request {
|
|
|
27
27
|
prisma: PrismaClient;
|
|
28
28
|
body: ${argsTypeName};
|
|
29
29
|
outputValidation?: ZodTypeAny;
|
|
30
|
-
omitOutputValidation?: boolean;
|
|
31
30
|
locals?: {
|
|
32
31
|
outputValidator?: ZodTypeAny;
|
|
33
32
|
};
|
|
@@ -39,13 +38,9 @@ export async function ${functionName}(req: DeleteRequest, res: Response, next: N
|
|
|
39
38
|
try {
|
|
40
39
|
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
throw new Error('Output validation schema or omission flag must be provided.');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const data = await req.prisma.${lowercaseFirstLetter(modelName)}.delete(req.body);
|
|
41
|
+
const data = await req.prisma.${toPascalCase(modelName)}.delete(req.body);
|
|
47
42
|
|
|
48
|
-
if (
|
|
43
|
+
if (outputValidator) {
|
|
49
44
|
const validationResult = outputValidator.safeParse(data);
|
|
50
45
|
if (validationResult.success) {
|
|
51
46
|
return res.status(200).json(validationResult.data);
|
|
@@ -55,8 +50,8 @@ export async function ${functionName}(req: DeleteRequest, res: Response, next: N
|
|
|
55
50
|
} else {
|
|
56
51
|
return res.status(200).json(data);
|
|
57
52
|
}
|
|
58
|
-
} catch
|
|
59
|
-
|
|
53
|
+
} catch(error: unknown) {
|
|
54
|
+
next(error)
|
|
60
55
|
}
|
|
61
56
|
}`
|
|
62
57
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper'
|
|
2
|
-
import {
|
|
2
|
+
import { toPascalCase } from '../utils/strings'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Generates an Express middleware function that handles batch deleting records
|
|
@@ -27,7 +27,6 @@ interface DeleteManyRequest extends Request {
|
|
|
27
27
|
prisma: PrismaClient;
|
|
28
28
|
body: ${argsTypeName};
|
|
29
29
|
outputValidation?: ZodTypeAny;
|
|
30
|
-
omitOutputValidation?: boolean;
|
|
31
30
|
locals?: {
|
|
32
31
|
outputValidator?: ZodTypeAny;
|
|
33
32
|
};
|
|
@@ -39,13 +38,9 @@ export async function ${functionName}(req: DeleteManyRequest, res: Response, nex
|
|
|
39
38
|
try {
|
|
40
39
|
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
throw new Error('Output validation schema or omission flag must be provided.');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const result = await req.prisma.${lowercaseFirstLetter(modelName)}.deleteMany(req.body);
|
|
41
|
+
const result = await req.prisma.${toPascalCase(modelName)}.deleteMany(req.body);
|
|
47
42
|
|
|
48
|
-
if (
|
|
43
|
+
if (outputValidator) {
|
|
49
44
|
const validationResult = outputValidator.safeParse(result);
|
|
50
45
|
if (validationResult.success) {
|
|
51
46
|
return res.status(200).json(validationResult.data);
|
|
@@ -55,8 +50,8 @@ export async function ${functionName}(req: DeleteManyRequest, res: Response, nex
|
|
|
55
50
|
} else {
|
|
56
51
|
return res.status(200).json(result);
|
|
57
52
|
}
|
|
58
|
-
} catch
|
|
59
|
-
|
|
53
|
+
} catch(error: unknown) {
|
|
54
|
+
next(error)
|
|
60
55
|
}
|
|
61
56
|
}`
|
|
62
57
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper'
|
|
2
|
-
import {
|
|
2
|
+
import { toPascalCase } 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.
|
|
@@ -29,7 +29,6 @@ export interface FindFirstRequest extends Request {
|
|
|
29
29
|
prisma: PrismaClient;
|
|
30
30
|
query: ${queryTypeName} & ParsedQs;
|
|
31
31
|
outputValidation?: ZodTypeAny;
|
|
32
|
-
omitOutputValidation?: boolean;
|
|
33
32
|
passToNext?: boolean;
|
|
34
33
|
locals?: {
|
|
35
34
|
data?: ${modelName} | null
|
|
@@ -42,15 +41,11 @@ export async function ${functionName}(req: FindFirstRequest, res: Response, next
|
|
|
42
41
|
try {
|
|
43
42
|
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
throw new Error('Output validation schema or omission flag must be provided.');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const data = await req.prisma.${lowercaseFirstLetter(modelName)}.findFirst(req.query as ${queryTypeName});
|
|
44
|
+
const data = await req.prisma.${toPascalCase(modelName)}.findFirst(req.query as ${queryTypeName});
|
|
50
45
|
if (req.passToNext) {
|
|
51
46
|
if (req.locals) req.locals.data = data;
|
|
52
47
|
next();
|
|
53
|
-
} else if (
|
|
48
|
+
} else if (outputValidator) {
|
|
54
49
|
const validationResult = outputValidator.safeParse(data);
|
|
55
50
|
if (validationResult.success) {
|
|
56
51
|
return res.status(200).json(validationResult.data);
|
|
@@ -60,8 +55,8 @@ export async function ${functionName}(req: FindFirstRequest, res: Response, next
|
|
|
60
55
|
} else {
|
|
61
56
|
return res.status(200).json(data);
|
|
62
57
|
}
|
|
63
|
-
} catch
|
|
64
|
-
|
|
58
|
+
} catch(error: unknown) {
|
|
59
|
+
next(error)
|
|
65
60
|
}
|
|
66
61
|
}`
|
|
67
62
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper'
|
|
2
|
-
import {
|
|
2
|
+
import { toPascalCase } 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.
|
|
@@ -29,7 +29,6 @@ export interface FindManyRequest extends Request {
|
|
|
29
29
|
prisma: PrismaClient;
|
|
30
30
|
query: ${queryTypeName} & ParsedQs;
|
|
31
31
|
outputValidation?: ZodTypeAny;
|
|
32
|
-
omitOutputValidation?: boolean;
|
|
33
32
|
passToNext?: boolean;
|
|
34
33
|
locals?: {
|
|
35
34
|
data?: ${modelName}[]
|
|
@@ -42,15 +41,11 @@ export async function ${functionName}(req: FindManyRequest, res: Response, next:
|
|
|
42
41
|
try {
|
|
43
42
|
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
throw new Error('Output validation schema or omission flag must be provided.');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const data = await req.prisma.${lowercaseFirstLetter(modelName)}.findMany(req.query as ${queryTypeName});
|
|
44
|
+
const data = await req.prisma.${toPascalCase(modelName)}.findMany(req.query as ${queryTypeName});
|
|
50
45
|
if (req.passToNext) {
|
|
51
46
|
if (req.locals) req.locals.data = data;
|
|
52
47
|
next();
|
|
53
|
-
} else if (
|
|
48
|
+
} else if (outputValidator) {
|
|
54
49
|
const validationResult = outputValidator.safeParse(data);
|
|
55
50
|
if (validationResult.success) {
|
|
56
51
|
return res.status(200).json(validationResult.data);
|
|
@@ -60,8 +55,8 @@ export async function ${functionName}(req: FindManyRequest, res: Response, next:
|
|
|
60
55
|
} else {
|
|
61
56
|
return res.status(200).json(data);
|
|
62
57
|
}
|
|
63
|
-
} catch
|
|
64
|
-
|
|
58
|
+
} catch(error: unknown) {
|
|
59
|
+
next(error)
|
|
65
60
|
}
|
|
66
61
|
}`
|
|
67
62
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper'
|
|
2
|
-
import {
|
|
2
|
+
import { toPascalCase } 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.
|
|
@@ -29,7 +29,6 @@ export interface FindUniqueRequest extends Request {
|
|
|
29
29
|
prisma: PrismaClient;
|
|
30
30
|
query: ${queryTypeName} & ParsedQs;
|
|
31
31
|
outputValidation?: ZodTypeAny;
|
|
32
|
-
omitOutputValidation?: boolean;
|
|
33
32
|
passToNext?: boolean;
|
|
34
33
|
locals?: {
|
|
35
34
|
data?: ${modelName} | null
|
|
@@ -42,15 +41,11 @@ export async function ${functionName}(req: FindUniqueRequest, res: Response, nex
|
|
|
42
41
|
try {
|
|
43
42
|
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
throw new Error('Output validation schema or omission flag must be provided.');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const data = await req.prisma.${lowercaseFirstLetter(modelName)}.findUnique(req.query as ${queryTypeName});
|
|
44
|
+
const data = await req.prisma.${toPascalCase(modelName)}.findUnique(req.query as ${queryTypeName});
|
|
50
45
|
if (req.passToNext) {
|
|
51
46
|
if (req.locals) req.locals.data = data;
|
|
52
47
|
next();
|
|
53
|
-
} else if (
|
|
48
|
+
} else if (outputValidator) {
|
|
54
49
|
const validationResult = outputValidator.safeParse(data);
|
|
55
50
|
if (validationResult.success) {
|
|
56
51
|
return res.status(200).json(validationResult.data);
|
|
@@ -60,8 +55,8 @@ export async function ${functionName}(req: FindUniqueRequest, res: Response, nex
|
|
|
60
55
|
} else {
|
|
61
56
|
return res.status(200).json(data);
|
|
62
57
|
}
|
|
63
|
-
} catch
|
|
64
|
-
|
|
58
|
+
} catch(error: unknown) {
|
|
59
|
+
next(error)
|
|
65
60
|
}
|
|
66
61
|
}`
|
|
67
62
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper'
|
|
2
|
-
import {
|
|
2
|
+
import { toPascalCase } from '../utils/strings'
|
|
3
3
|
import { PrismaClient, Prisma } from '@prisma/client'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -29,7 +29,6 @@ interface GroupByRequest extends Request {
|
|
|
29
29
|
prisma: PrismaClient;
|
|
30
30
|
query: Partial<${argsTypeName}> & ParsedQs;
|
|
31
31
|
outputValidation?: ZodTypeAny;
|
|
32
|
-
omitOutputValidation?: boolean;
|
|
33
32
|
locals?: {
|
|
34
33
|
outputValidator?: ZodTypeAny;
|
|
35
34
|
};
|
|
@@ -41,14 +40,10 @@ export async function ${functionName}(req: GroupByRequest, res: Response, next:
|
|
|
41
40
|
try {
|
|
42
41
|
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
43
42
|
|
|
44
|
-
if (!outputValidator && !req.omitOutputValidation) {
|
|
45
|
-
throw new Error('Output validation schema or omission flag must be provided.');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
43
|
// @ts-ignore
|
|
49
|
-
const result = await req.prisma.${
|
|
44
|
+
const result = await req.prisma.${toPascalCase(modelName)}.groupBy(req.query);
|
|
50
45
|
|
|
51
|
-
if (
|
|
46
|
+
if (outputValidator) {
|
|
52
47
|
const validationResult = outputValidator.safeParse(result);
|
|
53
48
|
if (validationResult.success) {
|
|
54
49
|
return res.status(200).json(validationResult.data);
|
|
@@ -58,8 +53,8 @@ export async function ${functionName}(req: GroupByRequest, res: Response, next:
|
|
|
58
53
|
} else {
|
|
59
54
|
return res.status(200).json(result);
|
|
60
55
|
}
|
|
61
|
-
} catch
|
|
62
|
-
|
|
56
|
+
} catch(error: unknown) {
|
|
57
|
+
next(error)
|
|
63
58
|
}
|
|
64
59
|
}`
|
|
65
60
|
}
|