prisma-generator-express 1.62.3 → 1.62.4
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.
|
@@ -11,21 +11,55 @@ function pathExpr(basePath, suffix) {
|
|
|
11
11
|
return `'${suffix}'`;
|
|
12
12
|
return `\`\${basePath}${suffix}\``;
|
|
13
13
|
}
|
|
14
|
+
function opKindFor(opName) {
|
|
15
|
+
switch (opName) {
|
|
16
|
+
case 'findUnique':
|
|
17
|
+
case 'findUniqueOrThrow':
|
|
18
|
+
return 'readUnique';
|
|
19
|
+
case 'findMany':
|
|
20
|
+
case 'findFirst':
|
|
21
|
+
case 'findFirstOrThrow':
|
|
22
|
+
case 'findManyPaginated':
|
|
23
|
+
case 'count':
|
|
24
|
+
case 'aggregate':
|
|
25
|
+
case 'groupBy':
|
|
26
|
+
return 'read';
|
|
27
|
+
case 'create':
|
|
28
|
+
return 'create';
|
|
29
|
+
case 'createMany':
|
|
30
|
+
case 'createManyAndReturn':
|
|
31
|
+
return 'createMany';
|
|
32
|
+
case 'update':
|
|
33
|
+
return 'update';
|
|
34
|
+
case 'updateMany':
|
|
35
|
+
case 'updateManyAndReturn':
|
|
36
|
+
return 'updateMany';
|
|
37
|
+
case 'upsert':
|
|
38
|
+
return 'upsert';
|
|
39
|
+
case 'delete':
|
|
40
|
+
return 'delete';
|
|
41
|
+
case 'deleteMany':
|
|
42
|
+
return 'deleteMany';
|
|
43
|
+
default:
|
|
44
|
+
return 'noop';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
14
47
|
function emitReadOp(meta, modelName) {
|
|
15
48
|
const c = meta.name.charAt(0).toUpperCase() + meta.name.slice(1);
|
|
16
49
|
const handlerName = `${modelName}${c}`;
|
|
17
50
|
const pathValue = pathExpr('basePath', meta.pathSuffix);
|
|
51
|
+
const opKind = opKindFor(meta.name);
|
|
18
52
|
const postReadBlock = meta.supportsPostRead
|
|
19
53
|
? ` if (postReadsEnabled) {
|
|
20
54
|
const postPath = ${meta.name === 'findMany' ? "basePath ? `${basePath}/read` : '/read'" : `path`}
|
|
21
|
-
router.post(postPath, parseBodyAsQuery, setShape(opConfig, '
|
|
55
|
+
router.post(postPath, parseBodyAsQuery, setShape(opConfig, '${opKind}'), ...before, ${handlerName} as RequestHandler, ...after, respond)
|
|
22
56
|
}`
|
|
23
57
|
: '';
|
|
24
58
|
return ` if (isEnabled(config.${meta.configKey})) {
|
|
25
59
|
const opConfig: OperationConfigLike = (config.${meta.configKey} as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
26
60
|
const { before = [], after = [] } = opConfig
|
|
27
61
|
const path = ${pathValue}
|
|
28
|
-
router.get(path, parseQuery, setShape(opConfig, '
|
|
62
|
+
router.get(path, parseQuery, setShape(opConfig, '${opKind}'), ...before, maybeProgressiveSSE(opConfig, core.${meta.coreName}, '${meta.name}'), ${handlerName} as RequestHandler, ...after, respond)
|
|
29
63
|
${postReadBlock}
|
|
30
64
|
}`;
|
|
31
65
|
}
|
|
@@ -34,11 +68,12 @@ function emitWriteOp(meta, modelName) {
|
|
|
34
68
|
const handlerName = `${modelName}${c}`;
|
|
35
69
|
const pathValue = pathExpr('basePath', meta.pathSuffix);
|
|
36
70
|
const respondFn = meta.successStatus === 201 ? 'respondCreated' : 'respond';
|
|
71
|
+
const opKind = opKindFor(meta.name);
|
|
37
72
|
return ` if (isEnabled(config.${meta.configKey})) {
|
|
38
73
|
const opConfig: OperationConfigLike = (config.${meta.configKey} as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
39
74
|
const { before = [], after = [] } = opConfig
|
|
40
75
|
const path = ${pathValue}
|
|
41
|
-
router.${meta.method}(path, setShape(opConfig, '
|
|
76
|
+
router.${meta.method}(path, setShape(opConfig, '${opKind}'), ...before, ${handlerName} as RequestHandler, ...after, ${respondFn})
|
|
42
77
|
}`;
|
|
43
78
|
}
|
|
44
79
|
function generateRouterFunction({ model, enums, guardShapesImport, importStyle, writeStrategy, findManyPaginatedMode, dropGuard, }) {
|
|
@@ -86,10 +121,8 @@ import {
|
|
|
86
121
|
} from '../sse${ext}'
|
|
87
122
|
import { relationModels } from '../relationModels${ext}'
|
|
88
123
|
import { runAutoIncludeProgressive } from '../autoIncludeRuntime${ext}'
|
|
89
|
-
import {
|
|
90
|
-
|
|
91
|
-
applyProjectionToTarget,
|
|
92
|
-
} from '../projectionDefaults${ext}'
|
|
124
|
+
import { applyDroppedGuard } from '../projectionDefaults${ext}'
|
|
125
|
+
import type { OpKind } from '../projectionDefaults${ext}'
|
|
93
126
|
import { MODEL_FIELDS, MODEL_ENUMS } from './${modelName}Metadata${ext}'
|
|
94
127
|
|
|
95
128
|
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'RequestHandler', guardShapesImport, importStyle, 'express')}
|
|
@@ -240,7 +273,7 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(config: ${m
|
|
|
240
273
|
next()
|
|
241
274
|
}
|
|
242
275
|
|
|
243
|
-
const setShape = (opConfig: OperationConfigLike,
|
|
276
|
+
const setShape = (opConfig: OperationConfigLike, opKind: OpKind): RequestHandler => {
|
|
244
277
|
return async (req, res, next) => {
|
|
245
278
|
try {
|
|
246
279
|
const locals = readLocals(res)
|
|
@@ -256,25 +289,28 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(config: ${m
|
|
|
256
289
|
if (!DROP_GUARD) {
|
|
257
290
|
locals.guardShape = opConfig.shape
|
|
258
291
|
} else {
|
|
259
|
-
|
|
292
|
+
await applyDroppedGuard(
|
|
260
293
|
opConfig.shape,
|
|
261
294
|
caller,
|
|
262
295
|
buildResolveContext(req),
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
296
|
+
opKind,
|
|
297
|
+
{
|
|
298
|
+
readQuery: locals.parsedQuery,
|
|
299
|
+
writeBody: isPlainObject(req.body)
|
|
300
|
+
? (req.body as Record<string, unknown>)
|
|
301
|
+
: undefined,
|
|
302
|
+
},
|
|
303
|
+
() => {
|
|
266
304
|
if (!locals.parsedQuery) locals.parsedQuery = {}
|
|
267
|
-
|
|
268
|
-
}
|
|
305
|
+
return locals.parsedQuery
|
|
306
|
+
},
|
|
307
|
+
() => {
|
|
269
308
|
if (!isPlainObject(req.body)) {
|
|
270
309
|
req.body = {}
|
|
271
310
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
)
|
|
276
|
-
}
|
|
277
|
-
}
|
|
311
|
+
return req.body as Record<string, unknown>
|
|
312
|
+
},
|
|
313
|
+
)
|
|
278
314
|
}
|
|
279
315
|
}
|
|
280
316
|
next()
|
|
@@ -435,7 +471,7 @@ ${writeOpBlocks}
|
|
|
435
471
|
const path = basePath ? \`\${basePath}/each\` : '/each'
|
|
436
472
|
router.post(
|
|
437
473
|
path,
|
|
438
|
-
setShape(opConfig, '
|
|
474
|
+
setShape(opConfig, 'noop'),
|
|
439
475
|
...before,
|
|
440
476
|
async (req: Request, res: Response, next: NextFunction) => {
|
|
441
477
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouter.js","sourceRoot":"","sources":["../../src/generators/generateRouter.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generateRouter.js","sourceRoot":"","sources":["../../src/generators/generateRouter.ts"],"names":[],"mappings":";;AA0FA,wDAkcC;AA3hBD,uEAAmE;AAEnE,kDAA8C;AAE9C,uEAAiE;AAEjE,SAAS,QAAQ,CAAC,QAAgB,EAAE,MAAc;IAChD,IAAI,CAAC,MAAM;QAAE,OAAO,QAAQ,IAAI,GAAG,CAAA;IACnC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,MAAM,GAAG,CAAA;IACnC,OAAO,iBAAiB,MAAM,IAAI,CAAA;AACpC,CAAC;AAED,SAAS,SAAS,CAAC,MAAc;IAC/B,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,YAAY,CAAC;QAClB,KAAK,mBAAmB;YACtB,OAAO,YAAY,CAAA;QACrB,KAAK,UAAU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DACzB,GAAG;0DACF,GAAG;4DACD,GAAG;sDACT,GAAG;qDACJ,GAAG;sDACF,GAAG;;;;;;;gBAOzC,GAAG;mDACgC,GAAG;kEACY,GAAG;0DACX,GAAG;oDACT,GAAG;+CACR,SAAS,WAAW,GAAG;;EAEpE,IAAA,iDAAuB,EAAC,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,SAAS,CAAC;;;2DAGtC,qBAAqB;qBAC3D,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA+CZ,kBAAkB,2CAA2C,SAAS;8DAC1B,SAAS;;;OAGhE,SAAS;;;;;;;;4DAQ4C,cAAc;;;;;;;;;;;;WAY/D,SAAS;;;;4CAIwB,aAAa;;;;;;;;;WAS9C,SAAS;;;;4CAIwB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BA8J7B,SAAS;8BACP,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+EvC,YAAY;;EAEZ,aAAa;;;;;;YAMH,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCpB,CAAA;AACD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prisma-generator-express",
|
|
3
3
|
"description": "Prisma generator for Express, Fastify, and Hono CRUD APIs with OpenAPI documentation",
|
|
4
|
-
"version": "1.62.
|
|
4
|
+
"version": "1.62.4",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
@@ -11,6 +11,40 @@ function pathExpr(basePath: string, suffix: string): string {
|
|
|
11
11
|
return `\`\${basePath}${suffix}\``
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
function opKindFor(opName: string): string {
|
|
15
|
+
switch (opName) {
|
|
16
|
+
case 'findUnique':
|
|
17
|
+
case 'findUniqueOrThrow':
|
|
18
|
+
return 'readUnique'
|
|
19
|
+
case 'findMany':
|
|
20
|
+
case 'findFirst':
|
|
21
|
+
case 'findFirstOrThrow':
|
|
22
|
+
case 'findManyPaginated':
|
|
23
|
+
case 'count':
|
|
24
|
+
case 'aggregate':
|
|
25
|
+
case 'groupBy':
|
|
26
|
+
return 'read'
|
|
27
|
+
case 'create':
|
|
28
|
+
return 'create'
|
|
29
|
+
case 'createMany':
|
|
30
|
+
case 'createManyAndReturn':
|
|
31
|
+
return 'createMany'
|
|
32
|
+
case 'update':
|
|
33
|
+
return 'update'
|
|
34
|
+
case 'updateMany':
|
|
35
|
+
case 'updateManyAndReturn':
|
|
36
|
+
return 'updateMany'
|
|
37
|
+
case 'upsert':
|
|
38
|
+
return 'upsert'
|
|
39
|
+
case 'delete':
|
|
40
|
+
return 'delete'
|
|
41
|
+
case 'deleteMany':
|
|
42
|
+
return 'deleteMany'
|
|
43
|
+
default:
|
|
44
|
+
return 'noop'
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
14
48
|
function emitReadOp(
|
|
15
49
|
meta: (typeof OPERATION_METADATA)[number],
|
|
16
50
|
modelName: string,
|
|
@@ -18,11 +52,12 @@ function emitReadOp(
|
|
|
18
52
|
const c = meta.name.charAt(0).toUpperCase() + meta.name.slice(1)
|
|
19
53
|
const handlerName = `${modelName}${c}`
|
|
20
54
|
const pathValue = pathExpr('basePath', meta.pathSuffix)
|
|
55
|
+
const opKind = opKindFor(meta.name)
|
|
21
56
|
|
|
22
57
|
const postReadBlock = meta.supportsPostRead
|
|
23
58
|
? ` if (postReadsEnabled) {
|
|
24
59
|
const postPath = ${meta.name === 'findMany' ? "basePath ? `${basePath}/read` : '/read'" : `path`}
|
|
25
|
-
router.post(postPath, parseBodyAsQuery, setShape(opConfig, '
|
|
60
|
+
router.post(postPath, parseBodyAsQuery, setShape(opConfig, '${opKind}'), ...before, ${handlerName} as RequestHandler, ...after, respond)
|
|
26
61
|
}`
|
|
27
62
|
: ''
|
|
28
63
|
|
|
@@ -30,7 +65,7 @@ function emitReadOp(
|
|
|
30
65
|
const opConfig: OperationConfigLike = (config.${meta.configKey} as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
31
66
|
const { before = [], after = [] } = opConfig
|
|
32
67
|
const path = ${pathValue}
|
|
33
|
-
router.get(path, parseQuery, setShape(opConfig, '
|
|
68
|
+
router.get(path, parseQuery, setShape(opConfig, '${opKind}'), ...before, maybeProgressiveSSE(opConfig, core.${meta.coreName}, '${meta.name}'), ${handlerName} as RequestHandler, ...after, respond)
|
|
34
69
|
${postReadBlock}
|
|
35
70
|
}`
|
|
36
71
|
}
|
|
@@ -43,12 +78,13 @@ function emitWriteOp(
|
|
|
43
78
|
const handlerName = `${modelName}${c}`
|
|
44
79
|
const pathValue = pathExpr('basePath', meta.pathSuffix)
|
|
45
80
|
const respondFn = meta.successStatus === 201 ? 'respondCreated' : 'respond'
|
|
81
|
+
const opKind = opKindFor(meta.name)
|
|
46
82
|
|
|
47
83
|
return ` if (isEnabled(config.${meta.configKey})) {
|
|
48
84
|
const opConfig: OperationConfigLike = (config.${meta.configKey} as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
49
85
|
const { before = [], after = [] } = opConfig
|
|
50
86
|
const path = ${pathValue}
|
|
51
|
-
router.${meta.method}(path, setShape(opConfig, '
|
|
87
|
+
router.${meta.method}(path, setShape(opConfig, '${opKind}'), ...before, ${handlerName} as RequestHandler, ...after, ${respondFn})
|
|
52
88
|
}`
|
|
53
89
|
}
|
|
54
90
|
|
|
@@ -124,10 +160,8 @@ import {
|
|
|
124
160
|
} from '../sse${ext}'
|
|
125
161
|
import { relationModels } from '../relationModels${ext}'
|
|
126
162
|
import { runAutoIncludeProgressive } from '../autoIncludeRuntime${ext}'
|
|
127
|
-
import {
|
|
128
|
-
|
|
129
|
-
applyProjectionToTarget,
|
|
130
|
-
} from '../projectionDefaults${ext}'
|
|
163
|
+
import { applyDroppedGuard } from '../projectionDefaults${ext}'
|
|
164
|
+
import type { OpKind } from '../projectionDefaults${ext}'
|
|
131
165
|
import { MODEL_FIELDS, MODEL_ENUMS } from './${modelName}Metadata${ext}'
|
|
132
166
|
|
|
133
167
|
${generateRouteConfigType(modelName, 'RequestHandler', guardShapesImport, importStyle, 'express')}
|
|
@@ -278,7 +312,7 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(config: ${m
|
|
|
278
312
|
next()
|
|
279
313
|
}
|
|
280
314
|
|
|
281
|
-
const setShape = (opConfig: OperationConfigLike,
|
|
315
|
+
const setShape = (opConfig: OperationConfigLike, opKind: OpKind): RequestHandler => {
|
|
282
316
|
return async (req, res, next) => {
|
|
283
317
|
try {
|
|
284
318
|
const locals = readLocals(res)
|
|
@@ -294,25 +328,28 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(config: ${m
|
|
|
294
328
|
if (!DROP_GUARD) {
|
|
295
329
|
locals.guardShape = opConfig.shape
|
|
296
330
|
} else {
|
|
297
|
-
|
|
331
|
+
await applyDroppedGuard(
|
|
298
332
|
opConfig.shape,
|
|
299
333
|
caller,
|
|
300
334
|
buildResolveContext(req),
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
335
|
+
opKind,
|
|
336
|
+
{
|
|
337
|
+
readQuery: locals.parsedQuery,
|
|
338
|
+
writeBody: isPlainObject(req.body)
|
|
339
|
+
? (req.body as Record<string, unknown>)
|
|
340
|
+
: undefined,
|
|
341
|
+
},
|
|
342
|
+
() => {
|
|
304
343
|
if (!locals.parsedQuery) locals.parsedQuery = {}
|
|
305
|
-
|
|
306
|
-
}
|
|
344
|
+
return locals.parsedQuery
|
|
345
|
+
},
|
|
346
|
+
() => {
|
|
307
347
|
if (!isPlainObject(req.body)) {
|
|
308
348
|
req.body = {}
|
|
309
349
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
)
|
|
314
|
-
}
|
|
315
|
-
}
|
|
350
|
+
return req.body as Record<string, unknown>
|
|
351
|
+
},
|
|
352
|
+
)
|
|
316
353
|
}
|
|
317
354
|
}
|
|
318
355
|
next()
|
|
@@ -473,7 +510,7 @@ ${writeOpBlocks}
|
|
|
473
510
|
const path = basePath ? \`\${basePath}/each\` : '/each'
|
|
474
511
|
router.post(
|
|
475
512
|
path,
|
|
476
|
-
setShape(opConfig, '
|
|
513
|
+
setShape(opConfig, 'noop'),
|
|
477
514
|
...before,
|
|
478
515
|
async (req: Request, res: Response, next: NextFunction) => {
|
|
479
516
|
try {
|