prisma-generator-express 1.16.7 → 1.19.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 +399 -194
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +1 -1
- package/dist/bin.js.map +1 -1
- package/dist/client/encodeQueryParams.d.ts +1 -0
- package/dist/client/encodeQueryParams.js +33 -0
- package/dist/client/encodeQueryParams.js.map +1 -0
- package/dist/constants.d.ts +1 -0
- package/dist/copy/misc.d.ts +5 -0
- package/dist/copy/misc.js +52 -0
- package/dist/copy/misc.js.map +1 -0
- package/dist/generators/generateImportPrismaStatement.d.ts +3 -0
- package/dist/generators/generateImportPrismaStatement.js +55 -0
- package/dist/generators/generateImportPrismaStatement.js.map +1 -0
- package/dist/generators/generateQueryBuilderHelper.d.ts +2 -0
- package/dist/generators/generateQueryBuilderHelper.js +139 -0
- package/dist/generators/generateQueryBuilderHelper.js.map +1 -0
- package/dist/generators/generateRouter.d.ts +6 -0
- package/dist/generators/generateRouter.js +340 -0
- package/dist/generators/generateRouter.js.map +1 -0
- package/dist/generators/generateUnifiedDocs.d.ts +1 -0
- package/dist/generators/generateUnifiedDocs.js +171 -0
- package/dist/generators/generateUnifiedDocs.js.map +1 -0
- package/dist/generators/generateUnifiedHandler.d.ts +6 -0
- package/dist/generators/generateUnifiedHandler.js +444 -0
- package/dist/generators/generateUnifiedHandler.js.map +1 -0
- package/dist/generators/generateUnifiedScalarUI.d.ts +5 -0
- package/dist/generators/generateUnifiedScalarUI.js +1390 -0
- package/dist/generators/generateUnifiedScalarUI.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/copyFiles.d.ts +6 -0
- package/dist/utils/copyFiles.js +123 -21
- package/dist/utils/copyFiles.js.map +1 -1
- package/dist/utils/strings.d.ts +2 -0
- package/dist/utils/writeFileSafely.d.ts +10 -0
- package/dist/utils/writeFileSafely.js +86 -14
- package/dist/utils/writeFileSafely.js.map +1 -1
- package/package.json +64 -31
- package/src/client/encodeQueryParams.ts +56 -0
- package/src/copy/buildModelOpenApi.ts +1569 -0
- package/src/copy/createOutputValidatorMiddleware.ts +1 -1
- package/src/copy/createValidatorMiddleware.ts +1 -1
- package/src/copy/misc.ts +22 -1
- package/src/copy/operationDefinitions.ts +96 -0
- package/src/copy/parseQueryParams.ts +36 -21
- package/src/copy/routeConfig.ts +69 -27
- package/src/copy/transformZod.ts +15 -16
- package/dist/generator.js +0 -168
- package/dist/generator.js.map +0 -1
- package/dist/helpers/generateAggregate.js +0 -51
- package/dist/helpers/generateAggregate.js.map +0 -1
- package/dist/helpers/generateCount.js +0 -50
- package/dist/helpers/generateCount.js.map +0 -1
- package/dist/helpers/generateCreate.js +0 -49
- package/dist/helpers/generateCreate.js.map +0 -1
- package/dist/helpers/generateCreateMany.js +0 -49
- package/dist/helpers/generateCreateMany.js.map +0 -1
- package/dist/helpers/generateDelete.js +0 -49
- package/dist/helpers/generateDelete.js.map +0 -1
- package/dist/helpers/generateDeleteMany.js +0 -49
- package/dist/helpers/generateDeleteMany.js.map +0 -1
- package/dist/helpers/generateFindFirst.js +0 -56
- package/dist/helpers/generateFindFirst.js.map +0 -1
- package/dist/helpers/generateFindMany.js +0 -56
- package/dist/helpers/generateFindMany.js.map +0 -1
- package/dist/helpers/generateFindUnique.js +0 -56
- package/dist/helpers/generateFindUnique.js.map +0 -1
- package/dist/helpers/generateGroupBy.js +0 -51
- package/dist/helpers/generateGroupBy.js.map +0 -1
- package/dist/helpers/generateImportPrismaStatement.js +0 -25
- package/dist/helpers/generateImportPrismaStatement.js.map +0 -1
- package/dist/helpers/generateRouteFile.js +0 -192
- package/dist/helpers/generateRouteFile.js.map +0 -1
- package/dist/helpers/generateUpdate.js +0 -49
- package/dist/helpers/generateUpdate.js.map +0 -1
- package/dist/helpers/generateUpdateMany.js +0 -49
- package/dist/helpers/generateUpdateMany.js.map +0 -1
- package/dist/helpers/generateUpsert.js +0 -49
- package/dist/helpers/generateUpsert.js.map +0 -1
- package/dist/utils/formatFile.js +0 -26
- package/dist/utils/formatFile.js.map +0 -1
- package/src/bin.ts +0 -2
- package/src/constants.ts +0 -1
- package/src/copy/encodeQueryParams.spec.ts +0 -303
- package/src/copy/encodeQueryParams.ts +0 -44
- package/src/copy/misc.spec.ts +0 -62
- package/src/copy/parseQueryParams.spec.ts +0 -187
- package/src/copy/transformZod.spec.ts +0 -763
- package/src/generator.ts +0 -188
- package/src/helpers/generateAggregate.ts +0 -59
- package/src/helpers/generateCount.ts +0 -58
- package/src/helpers/generateCreate.ts +0 -56
- package/src/helpers/generateCreateMany.ts +0 -55
- package/src/helpers/generateDelete.ts +0 -57
- package/src/helpers/generateDeleteMany.ts +0 -57
- package/src/helpers/generateFindFirst.ts +0 -62
- package/src/helpers/generateFindMany.ts +0 -62
- package/src/helpers/generateFindUnique.ts +0 -62
- package/src/helpers/generateGroupBy.ts +0 -60
- package/src/helpers/generateImportPrismaStatement.ts +0 -38
- package/src/helpers/generateRouteFile.ts +0 -195
- package/src/helpers/generateUpdate.ts +0 -56
- package/src/helpers/generateUpdateMany.ts +0 -56
- package/src/helpers/generateUpsert.ts +0 -57
- package/src/utils/copyFiles.ts +0 -27
- package/src/utils/formatFile.ts +0 -22
- package/src/utils/strings.ts +0 -7
- package/src/utils/writeFileSafely.ts +0 -29
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateRouterFunction = generateRouterFunction;
|
|
4
|
-
function generateRouterFunction({ model, }) {
|
|
5
|
-
const modelName = model.name;
|
|
6
|
-
const routerFunctionName = `${modelName}Router`;
|
|
7
|
-
return `import express, {
|
|
8
|
-
RequestHandler
|
|
9
|
-
} from 'express'
|
|
10
|
-
import { ParsedQs } from 'qs'
|
|
11
|
-
import { ${modelName}FindFirst } from './${modelName}FindFirst';
|
|
12
|
-
import { ${modelName}FindMany } from './${modelName}FindMany';
|
|
13
|
-
import { ${modelName}FindUnique } from './${modelName}FindUnique';
|
|
14
|
-
import { ${modelName}Create } from './${modelName}Create';
|
|
15
|
-
import { ${modelName}CreateMany } from './${modelName}CreateMany';
|
|
16
|
-
import { ${modelName}Update } from './${modelName}Update';
|
|
17
|
-
import { ${modelName}UpdateMany } from './${modelName}UpdateMany';
|
|
18
|
-
import { ${modelName}Upsert } from './${modelName}Upsert';
|
|
19
|
-
import { ${modelName}Delete } from './${modelName}Delete';
|
|
20
|
-
import { ${modelName}DeleteMany } from './${modelName}DeleteMany';
|
|
21
|
-
import { ${modelName}Aggregate } from './${modelName}Aggregate';
|
|
22
|
-
import { ${modelName}Count } from './${modelName}Count';
|
|
23
|
-
import { ${modelName}GroupBy } from './${modelName}GroupBy';
|
|
24
|
-
import { createValidatorMiddleware, removeTrailingSlash } from '../createValidatorMiddleware'
|
|
25
|
-
import { RouteConfig, ValidatorConfig } from '../routeConfig'
|
|
26
|
-
import { parseQueryParams } from "../parseQueryParams";
|
|
27
|
-
|
|
28
|
-
const defaultBeforeAfter = {
|
|
29
|
-
before: [] as RequestHandler[],
|
|
30
|
-
after: [] as RequestHandler[],
|
|
31
|
-
inputValidator: undefined,
|
|
32
|
-
outputValidator: undefined,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Generates an Express router for ${modelName} model.
|
|
37
|
-
* @param config Contains optional middleware to enable routes.
|
|
38
|
-
* @param customUrlPrefix Optional custom URL prefix for the routes.
|
|
39
|
-
* @returns {express.Router}
|
|
40
|
-
*/
|
|
41
|
-
export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
42
|
-
const router = express.Router();
|
|
43
|
-
const basePath = removeTrailingSlash(config.customUrlPrefix || '') +
|
|
44
|
-
removeTrailingSlash(config.addModelPrefix !== false ? '/${modelName.toLowerCase()}' : '');
|
|
45
|
-
|
|
46
|
-
const setupRoute = (
|
|
47
|
-
path: string,
|
|
48
|
-
method: "all" | "get" | "post" | "put" | "delete" | "patch" | "options" | "head",
|
|
49
|
-
middlewares: RequestHandler[],
|
|
50
|
-
handler: RequestHandler,
|
|
51
|
-
inputValidator?: ValidatorConfig,
|
|
52
|
-
outputValidator?: ValidatorConfig
|
|
53
|
-
) => {
|
|
54
|
-
const middlewaresWithValidators: RequestHandler[] = [
|
|
55
|
-
(req, res, next) => {
|
|
56
|
-
if (req.query) {
|
|
57
|
-
req.query = parseQueryParams(req.query as Record<string, string>) as ParsedQs;
|
|
58
|
-
}
|
|
59
|
-
next();
|
|
60
|
-
},
|
|
61
|
-
...middlewares
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
if (inputValidator) {
|
|
65
|
-
middlewaresWithValidators.push(createValidatorMiddleware({
|
|
66
|
-
schema: inputValidator.schema,
|
|
67
|
-
allowedPaths: inputValidator.allow,
|
|
68
|
-
forbiddenPaths: inputValidator.forbid,
|
|
69
|
-
target: method === 'get' ? 'query' : 'body',
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
middlewaresWithValidators.push((req, res, next) => {
|
|
74
|
-
res.locals.outputValidator = outputValidator;
|
|
75
|
-
next();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
middlewaresWithValidators.push(handler);
|
|
79
|
-
|
|
80
|
-
router[method](removeTrailingSlash(basePath + path), ...middlewaresWithValidators);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (config.enableAll || config?.findFirst) {
|
|
85
|
-
const { before = [], after = [], inputValidator, outputValidator } = config.findFirst || defaultBeforeAfter;
|
|
86
|
-
setupRoute('/first', 'get', before, ${modelName}FindFirst as RequestHandler, inputValidator, outputValidator);
|
|
87
|
-
if (after.length) {
|
|
88
|
-
router.use(removeTrailingSlash(basePath) + '/first', ...after);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (config.enableAll || config?.findMany) {
|
|
93
|
-
const { before = [], after = [], inputValidator, outputValidator } = config.findMany || defaultBeforeAfter;
|
|
94
|
-
setupRoute('/', 'get', before, ${modelName}FindMany as RequestHandler, inputValidator, outputValidator);
|
|
95
|
-
if (after.length) {
|
|
96
|
-
router.use(removeTrailingSlash(basePath + '/'), ...after);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (config.enableAll || config?.findUnique) {
|
|
101
|
-
const { before = [], after = [], inputValidator, outputValidator } = config.findUnique || defaultBeforeAfter;
|
|
102
|
-
setupRoute('/:id', 'get', before, ${modelName}FindUnique as any, inputValidator, outputValidator);
|
|
103
|
-
if (after.length) {
|
|
104
|
-
router.use(removeTrailingSlash(basePath) + '/:id', ...after);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (config.enableAll || config?.create) {
|
|
109
|
-
const { before = [], after = [], inputValidator, outputValidator } = config.create || defaultBeforeAfter;
|
|
110
|
-
setupRoute('/', 'post', before, ${modelName}Create as RequestHandler, inputValidator, outputValidator);
|
|
111
|
-
if (after.length) {
|
|
112
|
-
router.use(removeTrailingSlash(basePath + '/'), ...after);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (config.enableAll || config?.createMany) {
|
|
117
|
-
const { before = [], after = [], inputValidator, outputValidator } = config.createMany || defaultBeforeAfter;
|
|
118
|
-
setupRoute('/many', 'post', before, ${modelName}CreateMany as RequestHandler, inputValidator, outputValidator);
|
|
119
|
-
if (after.length) {
|
|
120
|
-
router.use(removeTrailingSlash(basePath) + '/many', ...after);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (config.enableAll || config?.update) {
|
|
125
|
-
const { before = [], after = [], inputValidator, outputValidator } = config.update || defaultBeforeAfter;
|
|
126
|
-
setupRoute('/', 'put', before, ${modelName}Update as RequestHandler, inputValidator, outputValidator);
|
|
127
|
-
if (after.length) {
|
|
128
|
-
router.use(removeTrailingSlash(basePath + '/'), ...after);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (config.enableAll || config?.updateMany) {
|
|
133
|
-
const { before = [], after = [], inputValidator, outputValidator } = config.updateMany || defaultBeforeAfter;
|
|
134
|
-
setupRoute('/many', 'put', before, ${modelName}UpdateMany as RequestHandler, inputValidator, outputValidator);
|
|
135
|
-
if (after.length) {
|
|
136
|
-
router.use(removeTrailingSlash(basePath) + '/many', ...after);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (config.enableAll || config?.upsert) {
|
|
141
|
-
const { before = [], after = [], inputValidator, outputValidator } = config.upsert || defaultBeforeAfter;
|
|
142
|
-
setupRoute('/', 'patch', before, ${modelName}Upsert as RequestHandler, inputValidator, outputValidator);
|
|
143
|
-
if (after.length) {
|
|
144
|
-
router.use(removeTrailingSlash(basePath + '/'), ...after);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (config.enableAll || config?.delete) {
|
|
149
|
-
const { before = [], after = [], inputValidator, outputValidator } = config.delete || defaultBeforeAfter;
|
|
150
|
-
setupRoute('/', 'delete', before, ${modelName}Delete as RequestHandler, inputValidator, outputValidator);
|
|
151
|
-
if (after.length) {
|
|
152
|
-
router.use(removeTrailingSlash(basePath + '/'), ...after);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (config.enableAll || config?.deleteMany) {
|
|
157
|
-
const { before = [], after = [], inputValidator, outputValidator } = config.deleteMany || defaultBeforeAfter;
|
|
158
|
-
setupRoute('/many', 'delete', before, ${modelName}DeleteMany as RequestHandler, inputValidator, outputValidator);
|
|
159
|
-
if (after.length) {
|
|
160
|
-
router.use(removeTrailingSlash(basePath) + '/many', ...after);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (config.enableAll || config?.aggregate) {
|
|
165
|
-
const { before = [], after = [], inputValidator, outputValidator } = config.aggregate || defaultBeforeAfter;
|
|
166
|
-
setupRoute('/aggregate', 'get', before, ${modelName}Aggregate as RequestHandler, inputValidator, outputValidator);
|
|
167
|
-
if (after.length) {
|
|
168
|
-
router.use(removeTrailingSlash(basePath) + '/aggregate', ...after);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (config.enableAll || config?.count) {
|
|
173
|
-
const { before = [], after = [], inputValidator, outputValidator } = config.count || defaultBeforeAfter;
|
|
174
|
-
setupRoute('/count', 'get', before, ${modelName}Count as RequestHandler, inputValidator, outputValidator);
|
|
175
|
-
if (after.length) {
|
|
176
|
-
router.use(removeTrailingSlash(basePath) + '/count', ...after);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (config.enableAll || config?.groupBy) {
|
|
181
|
-
const { before = [], after = [], inputValidator, outputValidator } = config.groupBy || defaultBeforeAfter;
|
|
182
|
-
setupRoute('/groupby', 'get', before, ${modelName}GroupBy as RequestHandler, inputValidator, outputValidator);
|
|
183
|
-
if (after.length) {
|
|
184
|
-
router.use(removeTrailingSlash(basePath) + '/groupby', ...after);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return router;
|
|
189
|
-
}
|
|
190
|
-
`;
|
|
191
|
-
}
|
|
192
|
-
//# sourceMappingURL=generateRouteFile.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouteFile.js","sourceRoot":"","sources":["../../src/helpers/generateRouteFile.ts"],"names":[],"mappings":";;AAEA,wDAgMC;AAhMD,SAAgB,sBAAsB,CAAC,EACrC,KAAK,GAGN;IACC,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,kBAAkB,GAAG,GAAG,SAAS,QAAQ,CAAA;IAE/C,OAAO;;;;WAIE,SAAS,uBAAuB,SAAS;WACzC,SAAS,sBAAsB,SAAS;WACxC,SAAS,wBAAwB,SAAS;WAC1C,SAAS,oBAAoB,SAAS;WACtC,SAAS,wBAAwB,SAAS;WAC1C,SAAS,oBAAoB,SAAS;WACtC,SAAS,wBAAwB,SAAS;WAC1C,SAAS,oBAAoB,SAAS;WACtC,SAAS,oBAAoB,SAAS;WACtC,SAAS,wBAAwB,SAAS;WAC1C,SAAS,uBAAuB,SAAS;WACzC,SAAS,mBAAmB,SAAS;WACrC,SAAS,qBAAqB,SAAS;;;;;;;;;;;;;qCAab,SAAS;;;;;kBAK5B,kBAAkB;;;4EAGwC,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0CA0CzD,SAAS;;;;;;;;qCAQd,SAAS;;;;;;;;wCAQN,SAAS;;;;;;;;sCAQX,SAAS;;;;;;;;0CAQL,SAAS;;;;;;;;qCAQd,SAAS;;;;;;;;yCAQL,SAAS;;;;;;;;uCAQX,SAAS;;;;;;;;wCAQR,SAAS;;;;;;;;4CAQL,SAAS;;;;;;;;8CAQP,SAAS;;;;;;;;0CAQb,SAAS;;;;;;;;4CAQP,SAAS;;;;;;;;CAQpD,CAAA;AACD,CAAC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateUpdateFunction = void 0;
|
|
4
|
-
const strings_1 = require("../utils/strings");
|
|
5
|
-
const generateUpdateFunction = (options) => {
|
|
6
|
-
const { model, prismaImportStatement } = options;
|
|
7
|
-
const modelName = model.name;
|
|
8
|
-
const functionName = `${modelName}Update`;
|
|
9
|
-
const argsTypeName = `Prisma.${modelName}UpdateArgs`;
|
|
10
|
-
return `
|
|
11
|
-
${prismaImportStatement}
|
|
12
|
-
import { Request, Response, NextFunction } from 'express';
|
|
13
|
-
import { RequestHandler, ParamsDictionary } from 'express-serve-static-core';
|
|
14
|
-
import { ZodTypeAny } from 'zod';
|
|
15
|
-
|
|
16
|
-
interface UpdateRequest extends Request {
|
|
17
|
-
prisma: PrismaClient;
|
|
18
|
-
body: ${argsTypeName};
|
|
19
|
-
outputValidation?: ZodTypeAny;
|
|
20
|
-
locals?: {
|
|
21
|
-
outputValidator?: ZodTypeAny;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type UpdateMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>
|
|
26
|
-
|
|
27
|
-
export async function ${functionName}(req: UpdateRequest, res: Response, next: NextFunction) {
|
|
28
|
-
try {
|
|
29
|
-
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
30
|
-
|
|
31
|
-
const data = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.update(req.body);
|
|
32
|
-
|
|
33
|
-
if (outputValidator) {
|
|
34
|
-
const validationResult = outputValidator.safeParse(data);
|
|
35
|
-
if (validationResult.success) {
|
|
36
|
-
return res.status(200).json(validationResult.data);
|
|
37
|
-
} else {
|
|
38
|
-
return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
return res.status(200).json(data);
|
|
42
|
-
}
|
|
43
|
-
} catch(error: unknown) {
|
|
44
|
-
next(error)
|
|
45
|
-
}
|
|
46
|
-
}`;
|
|
47
|
-
};
|
|
48
|
-
exports.generateUpdateFunction = generateUpdateFunction;
|
|
49
|
-
//# sourceMappingURL=generateUpdate.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateUpdate.js","sourceRoot":"","sources":["../../src/helpers/generateUpdate.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AAQxC,MAAM,sBAAsB,GAAG,CAAC,OAGtC,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,QAAQ,CAAA;IACzC,MAAM,YAAY,GAAG,UAAU,SAAS,YAAY,CAAA;IAEpD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;;;uEAOiD,YAAY;;wBAE3D,YAAY;;;;oCAIA,IAAA,sBAAY,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;EAezD,CAAA;AACF,CAAC,CAAA;AA9CY,QAAA,sBAAsB,0BA8ClC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateUpdateManyFunction = void 0;
|
|
4
|
-
const strings_1 = require("../utils/strings");
|
|
5
|
-
const generateUpdateManyFunction = (options) => {
|
|
6
|
-
const { model, prismaImportStatement } = options;
|
|
7
|
-
const modelName = model.name;
|
|
8
|
-
const functionName = `${modelName}UpdateMany`;
|
|
9
|
-
const argsTypeName = `Prisma.${modelName}UpdateManyArgs`;
|
|
10
|
-
return `
|
|
11
|
-
${prismaImportStatement}
|
|
12
|
-
import { Request, Response, NextFunction } from 'express';
|
|
13
|
-
import { RequestHandler, ParamsDictionary } from 'express-serve-static-core';
|
|
14
|
-
import { ZodTypeAny } from 'zod';
|
|
15
|
-
|
|
16
|
-
interface UpdateManyRequest extends Request {
|
|
17
|
-
prisma: PrismaClient;
|
|
18
|
-
body: ${argsTypeName};
|
|
19
|
-
outputValidation?: ZodTypeAny;
|
|
20
|
-
locals?: {
|
|
21
|
-
outputValidator?: ZodTypeAny;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type UpdateManyMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>
|
|
26
|
-
|
|
27
|
-
export async function ${functionName}(req: UpdateManyRequest, res: Response, next: NextFunction) {
|
|
28
|
-
try {
|
|
29
|
-
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
30
|
-
|
|
31
|
-
const data = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.updateMany(req.body);
|
|
32
|
-
|
|
33
|
-
if (outputValidator) {
|
|
34
|
-
const validationResult = outputValidator.safeParse(data);
|
|
35
|
-
if (validationResult.success) {
|
|
36
|
-
return res.status(200).json({ count: validationResult.data.count });
|
|
37
|
-
} else {
|
|
38
|
-
return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
return res.status(200).json({ count: data.count });
|
|
42
|
-
}
|
|
43
|
-
} catch(error: unknown) {
|
|
44
|
-
next(error)
|
|
45
|
-
}
|
|
46
|
-
}`;
|
|
47
|
-
};
|
|
48
|
-
exports.generateUpdateManyFunction = generateUpdateManyFunction;
|
|
49
|
-
//# sourceMappingURL=generateUpdateMany.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateUpsertFunction = void 0;
|
|
4
|
-
const strings_1 = require("../utils/strings");
|
|
5
|
-
const generateUpsertFunction = (options) => {
|
|
6
|
-
const { model, prismaImportStatement } = options;
|
|
7
|
-
const modelName = model.name;
|
|
8
|
-
const functionName = `${modelName}Upsert`;
|
|
9
|
-
const argsTypeName = `Prisma.${modelName}UpsertArgs`;
|
|
10
|
-
return `
|
|
11
|
-
${prismaImportStatement}
|
|
12
|
-
import { Request, Response, NextFunction } from 'express';
|
|
13
|
-
import { RequestHandler, ParamsDictionary } from 'express-serve-static-core';
|
|
14
|
-
import { ZodTypeAny } from 'zod';
|
|
15
|
-
|
|
16
|
-
interface UpsertRequest extends Request {
|
|
17
|
-
prisma: PrismaClient;
|
|
18
|
-
body: ${argsTypeName};
|
|
19
|
-
outputValidation?: ZodTypeAny;
|
|
20
|
-
locals?: {
|
|
21
|
-
outputValidator?: ZodTypeAny;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type UpsertMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>
|
|
26
|
-
|
|
27
|
-
export async function ${functionName}(req: UpsertRequest, res: Response, next: NextFunction) {
|
|
28
|
-
try {
|
|
29
|
-
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
30
|
-
|
|
31
|
-
const data = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.upsert(req.body);
|
|
32
|
-
|
|
33
|
-
if (outputValidator) {
|
|
34
|
-
const validationResult = outputValidator.safeParse(data);
|
|
35
|
-
if (validationResult.success) {
|
|
36
|
-
return res.status(200).json(validationResult.data);
|
|
37
|
-
} else {
|
|
38
|
-
return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
return res.status(200).json(data);
|
|
42
|
-
}
|
|
43
|
-
} catch(error: unknown) {
|
|
44
|
-
next(error)
|
|
45
|
-
}
|
|
46
|
-
}`;
|
|
47
|
-
};
|
|
48
|
-
exports.generateUpsertFunction = generateUpsertFunction;
|
|
49
|
-
//# sourceMappingURL=generateUpsert.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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/formatFile.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.formatFile = void 0;
|
|
7
|
-
const prettier_1 = __importDefault(require("prettier"));
|
|
8
|
-
const formatFile = (content) => {
|
|
9
|
-
return new Promise((res, rej) => prettier_1.default.resolveConfig(process.cwd()).then((options) => {
|
|
10
|
-
if (!options) {
|
|
11
|
-
res(content);
|
|
12
|
-
}
|
|
13
|
-
try {
|
|
14
|
-
const formatted = prettier_1.default.format(content, {
|
|
15
|
-
...options,
|
|
16
|
-
parser: 'typescript',
|
|
17
|
-
});
|
|
18
|
-
res(formatted);
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
rej(error);
|
|
22
|
-
}
|
|
23
|
-
}));
|
|
24
|
-
};
|
|
25
|
-
exports.formatFile = formatFile;
|
|
26
|
-
//# sourceMappingURL=formatFile.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatFile.js","sourceRoot":"","sources":["../../src/utils/formatFile.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA+B;AAExB,MAAM,UAAU,GAAG,CAAC,OAAe,EAAmB,EAAE;IAC7D,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAC9B,kBAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QACrD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,GAAG,CAAC,OAAO,CAAC,CAAA;QACd,CAAC;QAED,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,kBAAQ,CAAC,MAAM,CAAC,OAAO,EAAE;gBACzC,GAAG,OAAO;gBACV,MAAM,EAAE,YAAY;aACrB,CAAC,CAAA;YAEF,GAAG,CAAC,SAAS,CAAC,CAAA;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,KAAK,CAAC,CAAA;QACZ,CAAC;IACH,CAAC,CAAC,CACH,CAAA;AACH,CAAC,CAAA;AAnBY,QAAA,UAAU,cAmBtB"}
|
package/src/bin.ts
DELETED
package/src/constants.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const GENERATOR_NAME = 'prisma-generator-express'
|