prisma-generator-express 1.57.0 → 1.58.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 +111 -29
- package/dist/copy/misc.js +25 -6
- package/dist/copy/misc.js.map +1 -1
- package/dist/generators/generateFastifyHandler.js +11 -0
- package/dist/generators/generateFastifyHandler.js.map +1 -1
- package/dist/generators/generateHonoHandler.js +14 -20
- package/dist/generators/generateHonoHandler.js.map +1 -1
- package/dist/generators/generateImportPrismaStatement.js +7 -1
- package/dist/generators/generateImportPrismaStatement.js.map +1 -1
- package/dist/generators/generateOperationCore.js +58 -17
- package/dist/generators/generateOperationCore.js.map +1 -1
- package/dist/generators/generateRouteConfigType.js +12 -7
- package/dist/generators/generateRouteConfigType.js.map +1 -1
- package/dist/generators/generateRouter.js +57 -32
- package/dist/generators/generateRouter.js.map +1 -1
- package/dist/generators/generateRouterFastify.js +235 -191
- package/dist/generators/generateRouterFastify.js.map +1 -1
- package/dist/generators/generateRouterHono.js +121 -87
- package/dist/generators/generateRouterHono.js.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/copy/autoIncludeRuntime.ts +9 -5
- package/src/copy/buildModelOpenApi.ts +96 -0
- package/src/copy/docsRenderer.ts +577 -174
- package/src/copy/materializedRouter.ts +40 -1
- package/src/copy/misc.ts +23 -6
- package/src/copy/operationDefinitions.ts +10 -0
- package/src/copy/operationRuntime.ts +28 -9
- package/src/copy/routeConfig.express.ts +9 -9
- package/src/copy/routeConfig.hono.ts +63 -5
- package/src/copy/routeConfig.ts +44 -22
- package/src/generators/generateFastifyHandler.ts +12 -0
- package/src/generators/generateHonoHandler.ts +15 -20
- package/src/generators/generateImportPrismaStatement.ts +10 -1
- package/src/generators/generateOperationCore.ts +58 -17
- package/src/generators/generateRouteConfigType.ts +13 -8
- package/src/generators/generateRouter.ts +57 -32
- package/src/generators/generateRouterFastify.ts +235 -191
- package/src/generators/generateRouterHono.ts +121 -87
- package/src/index.ts +6 -4
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
${modelName}Aggregate,
|
|
48
48
|
${modelName}Count,
|
|
49
49
|
${modelName}GroupBy,
|
|
50
|
+
${modelName}UpdateEach,
|
|
50
51
|
} from './${modelName}Handlers${ext}'
|
|
51
52
|
import type {
|
|
52
53
|
RouteConfig,
|
|
@@ -58,6 +59,7 @@ import type {
|
|
|
58
59
|
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
59
60
|
import { sanitizeKeys, normalizePrefix, getEnv } from '../misc${ext}'
|
|
60
61
|
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
62
|
+
import { validateCountSourceWhere } from '../routeConfig${ext}'
|
|
61
63
|
import { mapError, transformResult, mergePaginationConfig, HttpError, type OperationContext } from '../operationRuntime${ext}'
|
|
62
64
|
|
|
63
65
|
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'FastifyHookHandler', guardShapesImport, importStyle, 'fastify')}
|
|
@@ -171,6 +173,7 @@ function sendResult(request: FastifyRequest, reply: FastifyReply): void {
|
|
|
171
173
|
}
|
|
172
174
|
|
|
173
175
|
function sendError(reply: FastifyReply, error: unknown): void {
|
|
176
|
+
if (reply.sent) return
|
|
174
177
|
const httpError = mapError(error)
|
|
175
178
|
reply.code(httpError.status).send({ message: httpError.message })
|
|
176
179
|
}
|
|
@@ -179,229 +182,270 @@ export async function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(
|
|
|
179
182
|
fastify: FastifyInstance,
|
|
180
183
|
config: ${modelName}RouteConfig<TCtx, TPrisma> = {},
|
|
181
184
|
) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
'
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const qbEnabled = isQueryBuilderEnabled(config)
|
|
214
|
-
|
|
215
|
-
if (qbEnabled) {
|
|
216
|
-
const qbConfig = getQueryBuilderConfig(config)
|
|
217
|
-
if (qbConfig) {
|
|
218
|
-
try {
|
|
219
|
-
startQueryBuilder(qbConfig)
|
|
220
|
-
} catch (err) {
|
|
221
|
-
if (_env.NODE_ENV !== 'production') console.warn('[query-builder]', err)
|
|
185
|
+
validateCountSourceWhere(config.pagination?.countSource, '${modelName} pagination')
|
|
186
|
+
validateCountSourceWhere(
|
|
187
|
+
(config.findManyPaginated && typeof config.findManyPaginated === 'object' ? config.findManyPaginated : undefined)?.pagination?.countSource,
|
|
188
|
+
'${modelName} findManyPaginated pagination',
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
await fastify.register(async (instance) => {
|
|
192
|
+
const isEnabled = (value: unknown): boolean => value !== false && !!(config.enableAll || value)
|
|
193
|
+
|
|
194
|
+
const customPrefix = normalizePrefix(config.customUrlPrefix || '')
|
|
195
|
+
const modelPrefix = config.addModelPrefix !== false ? '/${modelNameLower}' : ''
|
|
196
|
+
const basePath = customPrefix + modelPrefix
|
|
197
|
+
|
|
198
|
+
const openApiDisabled = config.disableOpenApi === true
|
|
199
|
+
|| (config.disableOpenApi !== false && (
|
|
200
|
+
_env.NODE_ENV === 'production'
|
|
201
|
+
|| _env.DISABLE_OPENAPI === 'true'
|
|
202
|
+
))
|
|
203
|
+
|
|
204
|
+
const postReadsEnabled = !config.disablePostReads
|
|
205
|
+
|
|
206
|
+
let _openApiJsonCache: unknown = undefined
|
|
207
|
+
const getOpenApiJson = (): unknown => {
|
|
208
|
+
if (_openApiJsonCache === undefined) {
|
|
209
|
+
_openApiJsonCache = buildModelOpenApi(
|
|
210
|
+
'${modelName}',
|
|
211
|
+
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
212
|
+
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
213
|
+
config,
|
|
214
|
+
{ format: 'json', writeStrategy: WRITE_STRATEGY },
|
|
215
|
+
)
|
|
222
216
|
}
|
|
217
|
+
return _openApiJsonCache
|
|
218
|
+
}
|
|
219
|
+
let _openApiYamlCache: string | undefined = undefined
|
|
220
|
+
const getOpenApiYaml = (): string => {
|
|
221
|
+
if (_openApiYamlCache === undefined) {
|
|
222
|
+
_openApiYamlCache = buildModelOpenApi(
|
|
223
|
+
'${modelName}',
|
|
224
|
+
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
225
|
+
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
226
|
+
config,
|
|
227
|
+
{ format: 'yaml', writeStrategy: WRITE_STRATEGY },
|
|
228
|
+
) as string
|
|
229
|
+
}
|
|
230
|
+
return _openApiYamlCache
|
|
223
231
|
}
|
|
224
|
-
}
|
|
225
232
|
|
|
226
|
-
|
|
227
|
-
(request as FastifyExtended & { findManyPaginatedMode?: FindManyPaginatedMode }).findManyPaginatedMode = FIND_MANY_PAGINATED_MODE
|
|
228
|
-
})
|
|
233
|
+
const qbEnabled = isQueryBuilderEnabled(config)
|
|
229
234
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
235
|
+
if (qbEnabled) {
|
|
236
|
+
const qbConfig = getQueryBuilderConfig(config)
|
|
237
|
+
if (qbConfig) {
|
|
238
|
+
try {
|
|
239
|
+
startQueryBuilder(qbConfig)
|
|
240
|
+
} catch (err) {
|
|
241
|
+
if (_env.NODE_ENV !== 'production') console.warn('[query-builder]', err)
|
|
242
|
+
}
|
|
243
|
+
}
|
|
236
244
|
}
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
if (!openApiDisabled) {
|
|
240
|
-
const openapiJsonPath = basePath ? \`\${basePath}/openapi.json\` : '/openapi.json'
|
|
241
|
-
const openapiYamlPath = basePath ? \`\${basePath}/openapi.yaml\` : '/openapi.yaml'
|
|
242
245
|
|
|
243
|
-
|
|
244
|
-
|
|
246
|
+
instance.addHook('onRequest', async (request: FastifyRequest) => {
|
|
247
|
+
(request as FastifyExtended & { findManyPaginatedMode?: FindManyPaginatedMode }).findManyPaginatedMode = FIND_MANY_PAGINATED_MODE
|
|
245
248
|
})
|
|
246
249
|
|
|
247
|
-
|
|
248
|
-
|
|
250
|
+
instance.setErrorHandler((error: FastifyError, _request: FastifyRequest, reply: FastifyReply) => {
|
|
251
|
+
const e = error as { status?: number; statusCode?: number; message?: string }
|
|
252
|
+
const status = e.status ?? e.statusCode ?? 500
|
|
253
|
+
const message = error.message || 'Internal server error'
|
|
254
|
+
if (!reply.sent) {
|
|
255
|
+
reply.code(status).send({ message })
|
|
256
|
+
}
|
|
249
257
|
})
|
|
250
|
-
}
|
|
251
258
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if (await runHooks(after, request, reply)) return
|
|
264
|
-
sendResult(request, reply)
|
|
265
|
-
} catch (error: unknown) {
|
|
266
|
-
sendError(reply, error)
|
|
259
|
+
if (!openApiDisabled) {
|
|
260
|
+
const openapiJsonPath = basePath ? \`\${basePath}/openapi.json\` : '/openapi.json'
|
|
261
|
+
const openapiYamlPath = basePath ? \`\${basePath}/openapi.yaml\` : '/openapi.yaml'
|
|
262
|
+
|
|
263
|
+
instance.get(openapiJsonPath, async (_request, reply) => {
|
|
264
|
+
return reply.send(getOpenApiJson())
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
instance.get(openapiYamlPath, async (_request, reply) => {
|
|
268
|
+
return reply.type('application/yaml').send(getOpenApiYaml())
|
|
269
|
+
})
|
|
267
270
|
}
|
|
268
|
-
}
|
|
269
271
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
272
|
+
const handleGet = (
|
|
273
|
+
opConfig: OperationConfigLike,
|
|
274
|
+
handlerFn: (req: FastifyRequest, reply: FastifyReply) => Promise<void>,
|
|
275
|
+
parseFn: (req: FastifyRequest) => void,
|
|
276
|
+
) => async (request: FastifyRequest, reply: FastifyReply) => {
|
|
277
|
+
try {
|
|
278
|
+
parseFn(request)
|
|
279
|
+
makeShapeHook(config, opConfig)(request)
|
|
280
|
+
const { before = [], after = [] } = opConfig
|
|
281
|
+
if (await runHooks(before, request, reply)) return
|
|
282
|
+
await handlerFn(request, reply)
|
|
283
|
+
if (await runHooks(after, request, reply)) return
|
|
284
|
+
sendResult(request, reply)
|
|
285
|
+
} catch (error: unknown) {
|
|
286
|
+
sendError(reply, error)
|
|
287
|
+
}
|
|
283
288
|
}
|
|
284
|
-
}
|
|
285
289
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
290
|
+
const handleWrite = (
|
|
291
|
+
opConfig: OperationConfigLike,
|
|
292
|
+
handlerFn: (req: FastifyRequest, reply: FastifyReply) => Promise<void>,
|
|
293
|
+
) => async (request: FastifyRequest, reply: FastifyReply) => {
|
|
294
|
+
try {
|
|
295
|
+
makeShapeHook(config, opConfig)(request)
|
|
296
|
+
const { before = [], after = [] } = opConfig
|
|
297
|
+
if (await runHooks(before, request, reply)) return
|
|
298
|
+
await handlerFn(request, reply)
|
|
299
|
+
if (await runHooks(after, request, reply)) return
|
|
300
|
+
sendResult(request, reply)
|
|
301
|
+
} catch (error: unknown) {
|
|
302
|
+
sendError(reply, error)
|
|
303
|
+
}
|
|
304
|
+
}
|
|
292
305
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
306
|
+
if (isEnabled(config.findFirst)) {
|
|
307
|
+
const opConfig: OperationConfigLike = (config.findFirst as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
308
|
+
const path = basePath ? \`\${basePath}/first\` : '/first'
|
|
309
|
+
instance.get(path, handleGet(opConfig, ${modelName}FindFirst, parseQueryHook))
|
|
310
|
+
if (postReadsEnabled) instance.post(path, handleGet(opConfig, ${modelName}FindFirst, parseBodyAsQueryHook))
|
|
311
|
+
}
|
|
299
312
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
313
|
+
if (isEnabled(config.findFirstOrThrow)) {
|
|
314
|
+
const opConfig: OperationConfigLike = (config.findFirstOrThrow as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
315
|
+
const path = basePath ? \`\${basePath}/first/strict\` : '/first/strict'
|
|
316
|
+
instance.get(path, handleGet(opConfig, ${modelName}FindFirstOrThrow, parseQueryHook))
|
|
317
|
+
if (postReadsEnabled) instance.post(path, handleGet(opConfig, ${modelName}FindFirstOrThrow, parseBodyAsQueryHook))
|
|
318
|
+
}
|
|
306
319
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
320
|
+
if (isEnabled(config.findManyPaginated)) {
|
|
321
|
+
const opConfig: OperationConfigLike = (config.findManyPaginated as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
322
|
+
const path = basePath ? \`\${basePath}/paginated\` : '/paginated'
|
|
323
|
+
instance.get(path, handleGet(opConfig, ${modelName}FindManyPaginated, parseQueryHook))
|
|
324
|
+
if (postReadsEnabled) instance.post(path, handleGet(opConfig, ${modelName}FindManyPaginated, parseBodyAsQueryHook))
|
|
325
|
+
}
|
|
313
326
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
327
|
+
if (isEnabled(config.aggregate)) {
|
|
328
|
+
const opConfig: OperationConfigLike = (config.aggregate as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
329
|
+
const path = basePath ? \`\${basePath}/aggregate\` : '/aggregate'
|
|
330
|
+
instance.get(path, handleGet(opConfig, ${modelName}Aggregate, parseQueryHook))
|
|
331
|
+
if (postReadsEnabled) instance.post(path, handleGet(opConfig, ${modelName}Aggregate, parseBodyAsQueryHook))
|
|
332
|
+
}
|
|
320
333
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
334
|
+
if (isEnabled(config.count)) {
|
|
335
|
+
const opConfig: OperationConfigLike = (config.count as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
336
|
+
const path = basePath ? \`\${basePath}/count\` : '/count'
|
|
337
|
+
instance.get(path, handleGet(opConfig, ${modelName}Count, parseQueryHook))
|
|
338
|
+
if (postReadsEnabled) instance.post(path, handleGet(opConfig, ${modelName}Count, parseBodyAsQueryHook))
|
|
339
|
+
}
|
|
327
340
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
341
|
+
if (isEnabled(config.groupBy)) {
|
|
342
|
+
const opConfig: OperationConfigLike = (config.groupBy as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
343
|
+
const path = basePath ? \`\${basePath}/groupby\` : '/groupby'
|
|
344
|
+
instance.get(path, handleGet(opConfig, ${modelName}GroupBy, parseQueryHook))
|
|
345
|
+
if (postReadsEnabled) instance.post(path, handleGet(opConfig, ${modelName}GroupBy, parseBodyAsQueryHook))
|
|
346
|
+
}
|
|
334
347
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
348
|
+
if (isEnabled(config.findUniqueOrThrow)) {
|
|
349
|
+
const opConfig: OperationConfigLike = (config.findUniqueOrThrow as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
350
|
+
const path = basePath ? \`\${basePath}/unique/strict\` : '/unique/strict'
|
|
351
|
+
instance.get(path, handleGet(opConfig, ${modelName}FindUniqueOrThrow, parseQueryHook))
|
|
352
|
+
if (postReadsEnabled) instance.post(path, handleGet(opConfig, ${modelName}FindUniqueOrThrow, parseBodyAsQueryHook))
|
|
353
|
+
}
|
|
341
354
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const postPath = basePath ? \`\${basePath}/read\` : '/read'
|
|
348
|
-
fastify.post(postPath, handleGet(opConfig, ${modelName}FindMany, parseBodyAsQueryHook))
|
|
355
|
+
if (isEnabled(config.findUnique)) {
|
|
356
|
+
const opConfig: OperationConfigLike = (config.findUnique as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
357
|
+
const path = basePath ? \`\${basePath}/unique\` : '/unique'
|
|
358
|
+
instance.get(path, handleGet(opConfig, ${modelName}FindUnique, parseQueryHook))
|
|
359
|
+
if (postReadsEnabled) instance.post(path, handleGet(opConfig, ${modelName}FindUnique, parseBodyAsQueryHook))
|
|
349
360
|
}
|
|
350
|
-
}
|
|
351
361
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
362
|
+
if (isEnabled(config.findMany)) {
|
|
363
|
+
const opConfig: OperationConfigLike = (config.findMany as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
364
|
+
const path = basePath || '/'
|
|
365
|
+
instance.get(path, handleGet(opConfig, ${modelName}FindMany, parseQueryHook))
|
|
366
|
+
if (postReadsEnabled) {
|
|
367
|
+
const postPath = basePath ? \`\${basePath}/read\` : '/read'
|
|
368
|
+
instance.post(postPath, handleGet(opConfig, ${modelName}FindMany, parseBodyAsQueryHook))
|
|
369
|
+
}
|
|
370
|
+
}
|
|
357
371
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
372
|
+
if (isEnabled(config.createManyAndReturn)) {
|
|
373
|
+
const opConfig: OperationConfigLike = (config.createManyAndReturn as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
374
|
+
const path = basePath ? \`\${basePath}/many/return\` : '/many/return'
|
|
375
|
+
instance.post(path, handleWrite(opConfig, ${modelName}CreateManyAndReturn))
|
|
376
|
+
}
|
|
363
377
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
378
|
+
if (isEnabled(config.createMany)) {
|
|
379
|
+
const opConfig: OperationConfigLike = (config.createMany as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
380
|
+
const path = basePath ? \`\${basePath}/many\` : '/many'
|
|
381
|
+
instance.post(path, handleWrite(opConfig, ${modelName}CreateMany))
|
|
382
|
+
}
|
|
369
383
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
384
|
+
if (isEnabled(config.create)) {
|
|
385
|
+
const opConfig: OperationConfigLike = (config.create as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
386
|
+
const path = basePath || '/'
|
|
387
|
+
instance.post(path, handleWrite(opConfig, ${modelName}Create))
|
|
388
|
+
}
|
|
375
389
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
390
|
+
if (isEnabled(config.updateManyAndReturn)) {
|
|
391
|
+
const opConfig: OperationConfigLike = (config.updateManyAndReturn as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
392
|
+
const path = basePath ? \`\${basePath}/many/return\` : '/many/return'
|
|
393
|
+
instance.put(path, handleWrite(opConfig, ${modelName}UpdateManyAndReturn))
|
|
394
|
+
}
|
|
381
395
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
396
|
+
if (isEnabled(config.updateMany)) {
|
|
397
|
+
const opConfig: OperationConfigLike = (config.updateMany as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
398
|
+
const path = basePath ? \`\${basePath}/many\` : '/many'
|
|
399
|
+
instance.put(path, handleWrite(opConfig, ${modelName}UpdateMany))
|
|
400
|
+
}
|
|
387
401
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
402
|
+
if (isEnabled(config.update)) {
|
|
403
|
+
const opConfig: OperationConfigLike = (config.update as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
404
|
+
const path = basePath || '/'
|
|
405
|
+
instance.put(path, handleWrite(opConfig, ${modelName}Update))
|
|
406
|
+
}
|
|
393
407
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
408
|
+
if (isEnabled(config.upsert)) {
|
|
409
|
+
const opConfig: OperationConfigLike = (config.upsert as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
410
|
+
const path = basePath || '/'
|
|
411
|
+
instance.patch(path, handleWrite(opConfig, ${modelName}Upsert))
|
|
412
|
+
}
|
|
399
413
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
414
|
+
if (isEnabled(config.deleteMany)) {
|
|
415
|
+
const opConfig: OperationConfigLike = (config.deleteMany as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
416
|
+
const path = basePath ? \`\${basePath}/many\` : '/many'
|
|
417
|
+
instance.delete(path, handleWrite(opConfig, ${modelName}DeleteMany))
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (isEnabled(config.delete)) {
|
|
421
|
+
const opConfig: OperationConfigLike = (config.delete as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
422
|
+
const path = basePath || '/'
|
|
423
|
+
instance.delete(path, handleWrite(opConfig, ${modelName}Delete))
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (config.updateEach) {
|
|
427
|
+
const opConfig: OperationConfigLike = (config.updateEach as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
428
|
+
if ((!opConfig.before || opConfig.before.length === 0) && _env.NODE_ENV !== 'production') {
|
|
429
|
+
console.warn(
|
|
430
|
+
'[${modelName}Router] updateEach is enabled without a before hook. ' +
|
|
431
|
+
'This endpoint bypasses guard shapes and should be protected by authentication middleware.',
|
|
432
|
+
)
|
|
433
|
+
}
|
|
434
|
+
const path = basePath ? \`\${basePath}/each\` : '/each'
|
|
435
|
+
instance.post(path, async (request: FastifyRequest, reply: FastifyReply) => {
|
|
436
|
+
try {
|
|
437
|
+
makeShapeHook(config, opConfig)(request)
|
|
438
|
+
const { before = [], after = [] } = opConfig
|
|
439
|
+
if (await runHooks(before, request, reply)) return
|
|
440
|
+
await ${modelName}UpdateEach(request, reply)
|
|
441
|
+
if (await runHooks(after, request, reply)) return
|
|
442
|
+
sendResult(request, reply)
|
|
443
|
+
} catch (error: unknown) {
|
|
444
|
+
sendError(reply, error)
|
|
445
|
+
}
|
|
446
|
+
})
|
|
447
|
+
}
|
|
448
|
+
})
|
|
405
449
|
}
|
|
406
450
|
`;
|
|
407
451
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouterFastify.js","sourceRoot":"","sources":["../../src/generators/generateRouterFastify.ts"],"names":[],"mappings":";;AAMA,
|
|
1
|
+
{"version":3,"file":"generateRouterFastify.js","sourceRoot":"","sources":["../../src/generators/generateRouterFastify.ts"],"names":[],"mappings":";;AAMA,sEAmdC;AAxdD,uEAAmE;AAEnE,kDAA8C;AAG9C,SAAgB,6BAA6B,CAAC,EAC5C,KAAK,EACL,KAAK,EACL,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,SAAS,GASV;IACC,MAAM,GAAG,GAAG,IAAA,qBAAS,EAAC,WAAW,CAAC,CAAA;IAClC,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IA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