prisma-generator-express 1.45.1 → 1.47.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/dist/client/encodeQueryParams.js +4 -0
- package/dist/client/encodeQueryParams.js.map +1 -1
- package/dist/copy/misc.d.ts +4 -2
- package/dist/copy/misc.js +35 -24
- package/dist/copy/misc.js.map +1 -1
- package/dist/generators/generateFastifyHandler.js +2 -4
- package/dist/generators/generateFastifyHandler.js.map +1 -1
- package/dist/generators/generateHonoHandler.js +2 -4
- package/dist/generators/generateHonoHandler.js.map +1 -1
- package/dist/generators/generateImportPrismaStatement.d.ts +0 -1
- package/dist/generators/generateImportPrismaStatement.js +2 -20
- package/dist/generators/generateImportPrismaStatement.js.map +1 -1
- package/dist/generators/generateOperationCore.js +37 -1
- package/dist/generators/generateOperationCore.js.map +1 -1
- package/dist/generators/generateQueryBuilderHelper.js +9 -0
- package/dist/generators/generateQueryBuilderHelper.js.map +1 -1
- package/dist/generators/generateRelationMeta.js +0 -10
- package/dist/generators/generateRelationMeta.js.map +1 -1
- package/dist/generators/generateRouteConfigType.js +33 -12
- package/dist/generators/generateRouteConfigType.js.map +1 -1
- package/dist/generators/generateRouter.d.ts +0 -1
- package/dist/generators/generateRouter.js +96 -70
- package/dist/generators/generateRouter.js.map +1 -1
- package/dist/generators/generateRouterFastify.js +83 -89
- package/dist/generators/generateRouterFastify.js.map +1 -1
- package/dist/generators/generateRouterHono.js +257 -237
- package/dist/generators/generateRouterHono.js.map +1 -1
- package/dist/generators/generateUnifiedDocs.d.ts +2 -2
- package/dist/generators/generateUnifiedDocs.js +90 -252
- package/dist/generators/generateUnifiedDocs.js.map +1 -1
- package/dist/generators/generateUnifiedHandler.js +2 -4
- package/dist/generators/generateUnifiedHandler.js.map +1 -1
- package/dist/index.js +16 -8
- package/dist/index.js.map +1 -1
- package/dist/utils/copyFiles.js +3 -2
- package/dist/utils/copyFiles.js.map +1 -1
- package/dist/utils/strings.d.ts +0 -1
- package/dist/utils/strings.js +0 -9
- package/dist/utils/strings.js.map +1 -1
- package/package.json +1 -1
- package/src/client/encodeQueryParams.ts +7 -15
- package/src/copy/autoIncludePlanner.ts +4 -17
- package/src/copy/autoIncludeRuntime.ts +11 -19
- package/src/copy/buildModelOpenApi.ts +11 -14
- package/src/copy/docsRenderer.ts +8 -14
- package/src/copy/misc.ts +28 -23
- package/src/copy/operationRuntime.ts +61 -43
- package/src/copy/parseQueryParams.ts +5 -14
- package/src/copy/routeConfig.express.ts +24 -18
- package/src/copy/routeConfig.fastify.ts +1 -1
- package/src/copy/routeConfig.hono.ts +34 -6
- package/src/copy/routeConfig.ts +3 -2
- package/src/generators/generateFastifyHandler.ts +2 -5
- package/src/generators/generateHonoHandler.ts +2 -5
- package/src/generators/generateImportPrismaStatement.ts +3 -35
- package/src/generators/generateOperationCore.ts +37 -1
- package/src/generators/generateQueryBuilderHelper.ts +9 -0
- package/src/generators/generateRelationMeta.ts +0 -10
- package/src/generators/generateRouteConfigType.ts +34 -10
- package/src/generators/generateRouter.ts +96 -71
- package/src/generators/generateRouterFastify.ts +83 -89
- package/src/generators/generateRouterHono.ts +257 -237
- package/src/generators/generateUnifiedDocs.ts +89 -267
- package/src/generators/generateUnifiedHandler.ts +2 -4
- package/src/index.ts +45 -14
- package/src/utils/copyFiles.ts +2 -2
- package/src/utils/strings.ts +0 -8
- package/src/copy/createOutputValidatorMiddleware.ts +0 -47
- package/src/copy/createValidatorMiddleware.ts +0 -62
- package/src/copy/transformZod.ts +0 -139
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper'
|
|
2
|
-
import { toCamelCase } from '../utils/strings'
|
|
3
2
|
import { generateRouteConfigType } from './generateRouteConfigType'
|
|
4
3
|
import { ImportStyle } from '../utils/resolveImportStyle'
|
|
5
4
|
import { importExt } from '../utils/importExt'
|
|
@@ -12,16 +11,14 @@ export function generateRouterFunction({
|
|
|
12
11
|
}: {
|
|
13
12
|
model: DMMF.Model
|
|
14
13
|
enums: DMMF.DatamodelEnum[]
|
|
15
|
-
relativeClientPath?: string
|
|
16
14
|
guardShapesImport: string | null
|
|
17
15
|
importStyle: ImportStyle
|
|
18
16
|
}): string {
|
|
19
17
|
const ext = importExt(importStyle)
|
|
20
18
|
const modelName = model.name
|
|
21
|
-
const prefix = toCamelCase(modelName)
|
|
22
19
|
const modelNameLower = modelName.toLowerCase()
|
|
23
20
|
const delegateKey = modelName.charAt(0).toLowerCase() + modelName.slice(1)
|
|
24
|
-
const routerFunctionName = `${
|
|
21
|
+
const routerFunctionName = `${modelName}Router`
|
|
25
22
|
|
|
26
23
|
const fieldsMeta = model.fields.map((f) => ({
|
|
27
24
|
name: f.name,
|
|
@@ -50,29 +47,29 @@ export function generateRouterFunction({
|
|
|
50
47
|
import type { Request, Response, NextFunction, RequestHandler } from 'express'
|
|
51
48
|
import { startQueryBuilder } from '../queryBuilder${ext}'
|
|
52
49
|
import {
|
|
53
|
-
${
|
|
54
|
-
${
|
|
55
|
-
${
|
|
56
|
-
${
|
|
57
|
-
${
|
|
58
|
-
${
|
|
59
|
-
${
|
|
60
|
-
${
|
|
61
|
-
${
|
|
62
|
-
${
|
|
63
|
-
${
|
|
64
|
-
${
|
|
65
|
-
${
|
|
66
|
-
${
|
|
67
|
-
${
|
|
68
|
-
${
|
|
69
|
-
${
|
|
70
|
-
${
|
|
50
|
+
${modelName}FindUnique,
|
|
51
|
+
${modelName}FindUniqueOrThrow,
|
|
52
|
+
${modelName}FindFirst,
|
|
53
|
+
${modelName}FindFirstOrThrow,
|
|
54
|
+
${modelName}FindMany,
|
|
55
|
+
${modelName}FindManyPaginated,
|
|
56
|
+
${modelName}Create,
|
|
57
|
+
${modelName}CreateMany,
|
|
58
|
+
${modelName}CreateManyAndReturn,
|
|
59
|
+
${modelName}Update,
|
|
60
|
+
${modelName}UpdateMany,
|
|
61
|
+
${modelName}UpdateManyAndReturn,
|
|
62
|
+
${modelName}Upsert,
|
|
63
|
+
${modelName}Delete,
|
|
64
|
+
${modelName}DeleteMany,
|
|
65
|
+
${modelName}Aggregate,
|
|
66
|
+
${modelName}Count,
|
|
67
|
+
${modelName}GroupBy,
|
|
71
68
|
} from './${modelName}Handlers${ext}'
|
|
72
69
|
import * as core from './${modelName}Core${ext}'
|
|
73
70
|
import type { RouteConfig, QueryBuilderConfig } from '../routeConfig.target${ext}'
|
|
74
71
|
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
75
|
-
import { sanitizeKeys } from '../misc${ext}'
|
|
72
|
+
import { sanitizeKeys, normalizePrefix, getEnv } from '../misc${ext}'
|
|
76
73
|
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
77
74
|
import type { OperationContext } from '../operationRuntime${ext}'
|
|
78
75
|
import {
|
|
@@ -89,7 +86,7 @@ import { relationModels } from '../relationModels${ext}'
|
|
|
89
86
|
import { runAutoIncludeProgressive } from '../autoIncludeRuntime${ext}'
|
|
90
87
|
|
|
91
88
|
${generateRouteConfigType(modelName, 'RequestHandler', guardShapesImport, importStyle, 'express')}
|
|
92
|
-
const _env =
|
|
89
|
+
const _env = getEnv()
|
|
93
90
|
|
|
94
91
|
const MODEL_FIELDS = ${JSON.stringify(fieldsMeta, null, 2)} as const
|
|
95
92
|
const MODEL_ENUMS = ${JSON.stringify(enumsMeta, null, 2)} as const
|
|
@@ -116,19 +113,10 @@ type LocalsBag = {
|
|
|
116
113
|
data?: unknown
|
|
117
114
|
}
|
|
118
115
|
|
|
119
|
-
const defaultOpConfig: OperationConfigLike = {
|
|
120
|
-
before: [],
|
|
121
|
-
after: [],
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function normalizePrefix(p: string): string {
|
|
125
|
-
if (!p) return ''
|
|
126
|
-
let result = p
|
|
127
|
-
if (!result.startsWith('/')) result = '/' + result
|
|
128
|
-
while (result.length > 1 && result.endsWith('/')) result = result.slice(0, -1)
|
|
129
|
-
if (result === '/') return ''
|
|
130
|
-
return result
|
|
131
|
-
}
|
|
116
|
+
const defaultOpConfig: OperationConfigLike = Object.freeze({
|
|
117
|
+
before: Object.freeze([]) as unknown as RequestHandler[],
|
|
118
|
+
after: Object.freeze([]) as unknown as RequestHandler[],
|
|
119
|
+
})
|
|
132
120
|
|
|
133
121
|
function isQueryBuilderEnabled(config: { queryBuilder?: QueryBuilderConfig | false }): boolean {
|
|
134
122
|
if (config.queryBuilder === false) return false
|
|
@@ -147,9 +135,8 @@ function readLocals(res: Response): LocalsBag {
|
|
|
147
135
|
return res.locals as LocalsBag
|
|
148
136
|
}
|
|
149
137
|
|
|
150
|
-
export function ${routerFunctionName}<TCtx = unknown>(config: ${modelName}RouteConfig<TCtx> = {}) {
|
|
138
|
+
export function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(config: ${modelName}RouteConfig<TCtx, TPrisma> = {}) {
|
|
151
139
|
const router = express.Router()
|
|
152
|
-
router.use(express.json())
|
|
153
140
|
|
|
154
141
|
const customPrefix = normalizePrefix(config.customUrlPrefix || '')
|
|
155
142
|
const modelPrefix = config.addModelPrefix !== false ? '/${modelNameLower}' : ''
|
|
@@ -160,6 +147,25 @@ export function ${routerFunctionName}<TCtx = unknown>(config: ${modelName}RouteC
|
|
|
160
147
|
|
|
161
148
|
const postReadsEnabled = !config.disablePostReads
|
|
162
149
|
|
|
150
|
+
const openApiJsonSpec = openApiDisabled
|
|
151
|
+
? null
|
|
152
|
+
: buildModelOpenApi(
|
|
153
|
+
'${modelName}',
|
|
154
|
+
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
155
|
+
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
156
|
+
config as unknown as Parameters<typeof buildModelOpenApi>[3],
|
|
157
|
+
{ format: 'json' },
|
|
158
|
+
)
|
|
159
|
+
const openApiYamlSpec = openApiDisabled
|
|
160
|
+
? null
|
|
161
|
+
: buildModelOpenApi(
|
|
162
|
+
'${modelName}',
|
|
163
|
+
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
164
|
+
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
165
|
+
config as unknown as Parameters<typeof buildModelOpenApi>[3],
|
|
166
|
+
{ format: 'yaml' },
|
|
167
|
+
)
|
|
168
|
+
|
|
163
169
|
const qbEnabled = isQueryBuilderEnabled(config)
|
|
164
170
|
if (qbEnabled) {
|
|
165
171
|
const qbConfig = getQueryBuilderConfig(config)
|
|
@@ -219,7 +225,7 @@ export function ${routerFunctionName}<TCtx = unknown>(config: ${modelName}RouteC
|
|
|
219
225
|
}
|
|
220
226
|
}
|
|
221
227
|
|
|
222
|
-
const maybeProgressiveSSE = (
|
|
228
|
+
const maybeProgressiveSSE = (
|
|
223
229
|
opConfig: OperationConfigLike,
|
|
224
230
|
coreFn: (ctx: OperationContext) => Promise<unknown>,
|
|
225
231
|
baseOp: string,
|
|
@@ -342,12 +348,10 @@ const maybeProgressiveSSE = (
|
|
|
342
348
|
const openapiJsonPath = basePath ? \`\${basePath}/openapi.json\` : '/openapi.json'
|
|
343
349
|
const openapiYamlPath = basePath ? \`\${basePath}/openapi.yaml\` : '/openapi.yaml'
|
|
344
350
|
router.get(openapiJsonPath, (_req, res) => {
|
|
345
|
-
|
|
346
|
-
res.json(spec)
|
|
351
|
+
res.json(openApiJsonSpec)
|
|
347
352
|
})
|
|
348
353
|
router.get(openapiYamlPath, (_req, res) => {
|
|
349
|
-
|
|
350
|
-
res.type('application/yaml').send(spec as string)
|
|
354
|
+
res.type('application/yaml').send(openApiYamlSpec as string)
|
|
351
355
|
})
|
|
352
356
|
}
|
|
353
357
|
|
|
@@ -355,66 +359,66 @@ const maybeProgressiveSSE = (
|
|
|
355
359
|
const opConfig: OperationConfigLike = (config.findFirst as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
356
360
|
const { before = [], after = [] } = opConfig
|
|
357
361
|
const path = basePath ? \`\${basePath}/first\` : '/first'
|
|
358
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findFirst, 'findFirst'), ${
|
|
359
|
-
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${
|
|
362
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findFirst, 'findFirst'), ${modelName}FindFirst as RequestHandler, ...after, respond)
|
|
363
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${modelName}FindFirst as RequestHandler, ...after, respond)
|
|
360
364
|
}
|
|
361
365
|
if (config.enableAll || config.findFirstOrThrow) {
|
|
362
366
|
const opConfig: OperationConfigLike = (config.findFirstOrThrow as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
363
367
|
const { before = [], after = [] } = opConfig
|
|
364
368
|
const path = basePath ? \`\${basePath}/first/strict\` : '/first/strict'
|
|
365
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findFirstOrThrow, 'findFirstOrThrow'), ${
|
|
366
|
-
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${
|
|
369
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findFirstOrThrow, 'findFirstOrThrow'), ${modelName}FindFirstOrThrow as RequestHandler, ...after, respond)
|
|
370
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${modelName}FindFirstOrThrow as RequestHandler, ...after, respond)
|
|
367
371
|
}
|
|
368
372
|
if (config.enableAll || config.findManyPaginated) {
|
|
369
373
|
const opConfig: OperationConfigLike = (config.findManyPaginated as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
370
374
|
const { before = [], after = [] } = opConfig
|
|
371
375
|
const path = basePath ? \`\${basePath}/paginated\` : '/paginated'
|
|
372
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findManyPaginated, 'findManyPaginated'), ${
|
|
373
|
-
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${
|
|
376
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findManyPaginated, 'findManyPaginated'), ${modelName}FindManyPaginated as RequestHandler, ...after, respond)
|
|
377
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${modelName}FindManyPaginated as RequestHandler, ...after, respond)
|
|
374
378
|
}
|
|
375
379
|
if (config.enableAll || config.aggregate) {
|
|
376
380
|
const opConfig: OperationConfigLike = (config.aggregate as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
377
381
|
const { before = [], after = [] } = opConfig
|
|
378
382
|
const path = basePath ? \`\${basePath}/aggregate\` : '/aggregate'
|
|
379
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.aggregate, 'aggregate'), ${
|
|
380
|
-
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${
|
|
383
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.aggregate, 'aggregate'), ${modelName}Aggregate as RequestHandler, ...after, respond)
|
|
384
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${modelName}Aggregate as RequestHandler, ...after, respond)
|
|
381
385
|
}
|
|
382
386
|
if (config.enableAll || config.count) {
|
|
383
387
|
const opConfig: OperationConfigLike = (config.count as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
384
388
|
const { before = [], after = [] } = opConfig
|
|
385
389
|
const path = basePath ? \`\${basePath}/count\` : '/count'
|
|
386
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.count, 'count'), ${
|
|
387
|
-
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${
|
|
390
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.count, 'count'), ${modelName}Count as RequestHandler, ...after, respond)
|
|
391
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${modelName}Count as RequestHandler, ...after, respond)
|
|
388
392
|
}
|
|
389
393
|
if (config.enableAll || config.groupBy) {
|
|
390
394
|
const opConfig: OperationConfigLike = (config.groupBy as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
391
395
|
const { before = [], after = [] } = opConfig
|
|
392
396
|
const path = basePath ? \`\${basePath}/groupby\` : '/groupby'
|
|
393
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.groupBy, 'groupBy'), ${
|
|
394
|
-
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${
|
|
397
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.groupBy, 'groupBy'), ${modelName}GroupBy as RequestHandler, ...after, respond)
|
|
398
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${modelName}GroupBy as RequestHandler, ...after, respond)
|
|
395
399
|
}
|
|
396
400
|
if (config.enableAll || config.findUniqueOrThrow) {
|
|
397
401
|
const opConfig: OperationConfigLike = (config.findUniqueOrThrow as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
398
402
|
const { before = [], after = [] } = opConfig
|
|
399
403
|
const path = basePath ? \`\${basePath}/unique/strict\` : '/unique/strict'
|
|
400
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findUniqueOrThrow, 'findUniqueOrThrow'), ${
|
|
401
|
-
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${
|
|
404
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findUniqueOrThrow, 'findUniqueOrThrow'), ${modelName}FindUniqueOrThrow as RequestHandler, ...after, respond)
|
|
405
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${modelName}FindUniqueOrThrow as RequestHandler, ...after, respond)
|
|
402
406
|
}
|
|
403
407
|
if (config.enableAll || config.findUnique) {
|
|
404
408
|
const opConfig: OperationConfigLike = (config.findUnique as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
405
409
|
const { before = [], after = [] } = opConfig
|
|
406
410
|
const path = basePath ? \`\${basePath}/unique\` : '/unique'
|
|
407
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findUnique, 'findUnique'), ${
|
|
408
|
-
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${
|
|
411
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findUnique, 'findUnique'), ${modelName}FindUnique as RequestHandler, ...after, respond)
|
|
412
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${modelName}FindUnique as RequestHandler, ...after, respond)
|
|
409
413
|
}
|
|
410
414
|
if (config.enableAll || config.findMany) {
|
|
411
415
|
const opConfig: OperationConfigLike = (config.findMany as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
412
416
|
const { before = [], after = [] } = opConfig
|
|
413
417
|
const path = basePath || '/'
|
|
414
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findMany, 'findMany'), ${
|
|
418
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findMany, 'findMany'), ${modelName}FindMany as RequestHandler, ...after, respond)
|
|
415
419
|
if (postReadsEnabled) {
|
|
416
420
|
const postPath = basePath ? \`\${basePath}/read\` : '/read'
|
|
417
|
-
router.post(postPath, parseBodyAsQuery, setShape(opConfig), ...before, ${
|
|
421
|
+
router.post(postPath, parseBodyAsQuery, setShape(opConfig), ...before, ${modelName}FindMany as RequestHandler, ...after, respond)
|
|
418
422
|
}
|
|
419
423
|
}
|
|
420
424
|
|
|
@@ -422,55 +426,76 @@ const maybeProgressiveSSE = (
|
|
|
422
426
|
const opConfig: OperationConfigLike = (config.createManyAndReturn as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
423
427
|
const { before = [], after = [] } = opConfig
|
|
424
428
|
const path = basePath ? \`\${basePath}/many/return\` : '/many/return'
|
|
425
|
-
router.post(path, setShape(opConfig), ...before, ${
|
|
429
|
+
router.post(path, setShape(opConfig), ...before, ${modelName}CreateManyAndReturn as RequestHandler, ...after, respondCreated)
|
|
426
430
|
}
|
|
427
431
|
if (config.enableAll || config.createMany) {
|
|
428
432
|
const opConfig: OperationConfigLike = (config.createMany as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
429
433
|
const { before = [], after = [] } = opConfig
|
|
430
434
|
const path = basePath ? \`\${basePath}/many\` : '/many'
|
|
431
|
-
router.post(path, setShape(opConfig), ...before, ${
|
|
435
|
+
router.post(path, setShape(opConfig), ...before, ${modelName}CreateMany as RequestHandler, ...after, respondCreated)
|
|
432
436
|
}
|
|
433
437
|
if (config.enableAll || config.create) {
|
|
434
438
|
const opConfig: OperationConfigLike = (config.create as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
435
439
|
const { before = [], after = [] } = opConfig
|
|
436
440
|
const path = basePath || '/'
|
|
437
|
-
router.post(path, setShape(opConfig), ...before, ${
|
|
441
|
+
router.post(path, setShape(opConfig), ...before, ${modelName}Create as RequestHandler, ...after, respondCreated)
|
|
438
442
|
}
|
|
439
443
|
if (config.enableAll || config.updateManyAndReturn) {
|
|
440
444
|
const opConfig: OperationConfigLike = (config.updateManyAndReturn as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
441
445
|
const { before = [], after = [] } = opConfig
|
|
442
446
|
const path = basePath ? \`\${basePath}/many/return\` : '/many/return'
|
|
443
|
-
router.put(path, setShape(opConfig), ...before, ${
|
|
447
|
+
router.put(path, setShape(opConfig), ...before, ${modelName}UpdateManyAndReturn as RequestHandler, ...after, respond)
|
|
444
448
|
}
|
|
445
449
|
if (config.enableAll || config.updateMany) {
|
|
446
450
|
const opConfig: OperationConfigLike = (config.updateMany as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
447
451
|
const { before = [], after = [] } = opConfig
|
|
448
452
|
const path = basePath ? \`\${basePath}/many\` : '/many'
|
|
449
|
-
router.put(path, setShape(opConfig), ...before, ${
|
|
453
|
+
router.put(path, setShape(opConfig), ...before, ${modelName}UpdateMany as RequestHandler, ...after, respond)
|
|
450
454
|
}
|
|
451
455
|
if (config.enableAll || config.update) {
|
|
452
456
|
const opConfig: OperationConfigLike = (config.update as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
453
457
|
const { before = [], after = [] } = opConfig
|
|
454
458
|
const path = basePath || '/'
|
|
455
|
-
router.put(path, setShape(opConfig), ...before, ${
|
|
459
|
+
router.put(path, setShape(opConfig), ...before, ${modelName}Update as RequestHandler, ...after, respond)
|
|
456
460
|
}
|
|
457
461
|
if (config.enableAll || config.upsert) {
|
|
458
462
|
const opConfig: OperationConfigLike = (config.upsert as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
459
463
|
const { before = [], after = [] } = opConfig
|
|
460
464
|
const path = basePath || '/'
|
|
461
|
-
router.patch(path, setShape(opConfig), ...before, ${
|
|
465
|
+
router.patch(path, setShape(opConfig), ...before, ${modelName}Upsert as RequestHandler, ...after, respond)
|
|
462
466
|
}
|
|
463
467
|
if (config.enableAll || config.deleteMany) {
|
|
464
468
|
const opConfig: OperationConfigLike = (config.deleteMany as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
465
469
|
const { before = [], after = [] } = opConfig
|
|
466
470
|
const path = basePath ? \`\${basePath}/many\` : '/many'
|
|
467
|
-
router.delete(path, setShape(opConfig), ...before, ${
|
|
471
|
+
router.delete(path, setShape(opConfig), ...before, ${modelName}DeleteMany as RequestHandler, ...after, respond)
|
|
468
472
|
}
|
|
469
473
|
if (config.enableAll || config.delete) {
|
|
470
474
|
const opConfig: OperationConfigLike = (config.delete as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
471
475
|
const { before = [], after = [] } = opConfig
|
|
472
476
|
const path = basePath || '/'
|
|
473
|
-
router.delete(path, setShape(opConfig), ...before, ${
|
|
477
|
+
router.delete(path, setShape(opConfig), ...before, ${modelName}Delete as RequestHandler, ...after, respond)
|
|
478
|
+
}
|
|
479
|
+
if (config.updateEach) {
|
|
480
|
+
const opConfig: OperationConfigLike = (config.batch as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
481
|
+
const { before = [], after = [] } = opConfig
|
|
482
|
+
const path = basePath ? \`\${basePath}/batch\` : '/batch'
|
|
483
|
+
router.post(
|
|
484
|
+
path,
|
|
485
|
+
setShape(opConfig),
|
|
486
|
+
...before,
|
|
487
|
+
async (req: Request, res: Response, next: NextFunction) => {
|
|
488
|
+
try {
|
|
489
|
+
const atomic = req.get('x-batch-atomic') === 'true'
|
|
490
|
+
readLocals(res).data = await core.batch(buildContext(req, res), atomic)
|
|
491
|
+
next()
|
|
492
|
+
} catch (err) {
|
|
493
|
+
next(mapError(err))
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
...after,
|
|
497
|
+
respond,
|
|
498
|
+
)
|
|
474
499
|
}
|
|
475
500
|
|
|
476
501
|
router.use((err: unknown, _req: Request, res: Response, next: NextFunction) => {
|