prisma-generator-express 1.34.1 → 1.34.3

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.
Files changed (40) hide show
  1. package/dist/bin.d.ts +1 -1
  2. package/dist/bin.js +1 -1
  3. package/dist/bin.js.map +1 -1
  4. package/dist/client/encodeQueryParams.js +2 -2
  5. package/dist/client/encodeQueryParams.js.map +1 -1
  6. package/dist/generators/generateFastifyHandler.js +4 -4
  7. package/dist/generators/generateFastifyHandler.js.map +1 -1
  8. package/dist/generators/generateOperationCore.js +2 -2
  9. package/dist/generators/generateQueryBuilderHelper.js +2 -2
  10. package/dist/generators/generateRouter.js +7 -7
  11. package/dist/generators/generateRouter.js.map +1 -1
  12. package/dist/generators/generateRouterFastify.js +355 -354
  13. package/dist/generators/generateRouterFastify.js.map +1 -1
  14. package/dist/generators/generateUnifiedDocs.d.ts +1 -1
  15. package/dist/generators/generateUnifiedDocs.js +2 -2
  16. package/dist/generators/generateUnifiedDocs.js.map +1 -1
  17. package/dist/generators/generateUnifiedHandler.js +4 -4
  18. package/dist/generators/generateUnifiedHandler.js.map +1 -1
  19. package/dist/generators/generateUnifiedScalarUI.d.ts +1 -1
  20. package/dist/generators/generateUnifiedScalarUI.js +2 -2
  21. package/dist/index.js +30 -30
  22. package/dist/index.js.map +1 -1
  23. package/dist/utils/copyFiles.d.ts +1 -1
  24. package/dist/utils/copyFiles.js +1 -1
  25. package/dist/utils/copyFiles.js.map +1 -1
  26. package/package.json +1 -1
  27. package/src/bin.ts +1 -1
  28. package/src/client/encodeQueryParams.ts +1 -1
  29. package/src/copy/docsRenderer.ts +2 -2
  30. package/src/copy/parseQueryParams.ts +1 -1
  31. package/src/generators/generateFastifyHandler.ts +3 -3
  32. package/src/generators/generateOperationCore.ts +2 -2
  33. package/src/generators/generateQueryBuilderHelper.ts +2 -2
  34. package/src/generators/generateRouter.ts +6 -6
  35. package/src/generators/generateRouterFastify.ts +354 -353
  36. package/src/generators/generateUnifiedDocs.ts +3 -3
  37. package/src/generators/generateUnifiedHandler.ts +3 -3
  38. package/src/generators/generateUnifiedScalarUI.ts +3 -3
  39. package/src/index.ts +12 -12
  40. package/src/utils/copyFiles.ts +2 -2
@@ -1,5 +1,5 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
- import { toCamelCase } from '../utils/strings.js'
2
+ import { toCamelCase } from '../utils/strings'
3
3
 
4
4
  export function generateFastifyRouterFunction({
5
5
  model,
@@ -56,11 +56,11 @@ import {
56
56
  ${prefix}Aggregate,
57
57
  ${prefix}Count,
58
58
  ${prefix}GroupBy,
59
- } from './${modelName}Handlers.js'
60
- import type { RouteConfig, FastifyHookHandler } from '../routeConfig.target.js'
61
- import { parseQueryParams } from '../parseQueryParams.js'
62
- import { buildModelOpenApi } from '../buildModelOpenApi.js'
63
- import { mapError, transformResult } from '../operationRuntime.js'
59
+ } from './${modelName}Handlers'
60
+ import type { RouteConfig, FastifyHookHandler } from '../routeConfig.target'
61
+ import { parseQueryParams } from '../parseQueryParams'
62
+ import { buildModelOpenApi } from '../buildModelOpenApi'
63
+ import { mapError, transformResult } from '../operationRuntime'
64
64
 
65
65
  const _env = typeof process !== 'undefined' && process.env ? process.env : {} as Record<string, string | undefined>
66
66
 
@@ -147,376 +147,377 @@ function sendError(reply: FastifyReply, error: unknown): void {
147
147
  reply.code(httpError.status).send({ message: httpError.message })
148
148
  }
149
149
 
150
- export function ${routerFunctionName}(config: RouteConfig = {}) {
151
- return async function(fastify: FastifyInstance) {
152
- const customPrefix = normalizePrefix(config.customUrlPrefix || '')
153
- const modelPrefix = config.addModelPrefix !== false ? '/${modelNameLower}' : ''
154
- const basePath = customPrefix + modelPrefix
150
+ export async function ${routerFunctionName}(
151
+ fastify: FastifyInstance,
152
+ config: RouteConfig = {},
153
+ ) {
154
+ const customPrefix = normalizePrefix(config.customUrlPrefix || '')
155
+ const modelPrefix = config.addModelPrefix !== false ? '/${modelNameLower}' : ''
156
+ const basePath = customPrefix + modelPrefix
157
+
158
+ const openApiDisabled = config.disableOpenApi === true
159
+ || (config.disableOpenApi !== false && (
160
+ _env.DISABLE_OPENAPI === 'true'
161
+ || _env.NODE_ENV === 'production'
162
+ ))
163
+
164
+ const qbEnabled = isQueryBuilderEnabled(config)
165
+
166
+ if (qbEnabled) {
167
+ const qbConfig = getQueryBuilderConfig(config)
168
+ if (qbConfig) {
169
+ try { require('../queryBuilder').startQueryBuilder(qbConfig) } catch (err) { if (_env.NODE_ENV !== 'production') console.warn('[query-builder]', err) }
170
+ }
171
+ }
155
172
 
156
- const openApiDisabled = config.disableOpenApi === true
157
- || (config.disableOpenApi !== false && (
158
- _env.DISABLE_OPENAPI === 'true'
159
- || _env.NODE_ENV === 'production'
160
- ))
173
+ fastify.setErrorHandler((error: FastifyError, _request: FastifyRequest, reply: FastifyReply) => {
174
+ const status = (error as any).status ?? error.statusCode ?? 500
175
+ const message = error.message || 'Internal server error'
176
+ if (!reply.sent) {
177
+ reply.code(status).send({ message })
178
+ }
179
+ })
180
+
181
+ if (!openApiDisabled) {
182
+ const openapiJsonPath = basePath ? \`\${basePath}/openapi.json\` : '/openapi.json'
183
+ const openapiYamlPath = basePath ? \`\${basePath}/openapi.yaml\` : '/openapi.yaml'
184
+
185
+ fastify.get(openapiJsonPath, async (_request, reply) => {
186
+ const spec = buildModelOpenApi(
187
+ '${modelName}',
188
+ MODEL_FIELDS as any,
189
+ MODEL_ENUMS as any,
190
+ config,
191
+ { format: 'json' },
192
+ )
193
+ return reply.send(spec)
194
+ })
161
195
 
162
- const qbEnabled = isQueryBuilderEnabled(config)
196
+ fastify.get(openapiYamlPath, async (_request, reply) => {
197
+ const spec = buildModelOpenApi(
198
+ '${modelName}',
199
+ MODEL_FIELDS as any,
200
+ MODEL_ENUMS as any,
201
+ config,
202
+ { format: 'yaml' },
203
+ )
204
+ return reply.type('application/yaml').send(spec as string)
205
+ })
206
+ }
163
207
 
164
- if (qbEnabled) {
165
- const qbConfig = getQueryBuilderConfig(config)
166
- if (qbConfig) {
167
- try { require('../queryBuilder').startQueryBuilder(qbConfig) } catch (err) { if (_env.NODE_ENV !== 'production') console.warn('[query-builder]', err) }
208
+ if (config.enableAll || config.findFirst) {
209
+ const opConfig = config.findFirst || defaultOpConfig
210
+ const { before = [], after = [] } = opConfig
211
+ const path = basePath ? \`\${basePath}/first\` : '/first'
212
+ fastify.get(path, async (request, reply) => {
213
+ try {
214
+ parseQueryHook(request)
215
+ makeShapeHook(config, opConfig)(request)
216
+ if (await runHooks(before, request, reply)) return
217
+ await ${prefix}FindFirst(request, reply)
218
+ if (await runHooks(after, request, reply)) return
219
+ sendResult(request, reply)
220
+ } catch (error: unknown) {
221
+ sendError(reply, error)
168
222
  }
169
- }
223
+ })
224
+ }
170
225
 
171
- fastify.setErrorHandler((error: FastifyError, _request: FastifyRequest, reply: FastifyReply) => {
172
- const status = (error as any).status ?? error.statusCode ?? 500
173
- const message = error.message || 'Internal server error'
174
- if (!reply.sent) {
175
- reply.code(status).send({ message })
226
+ if (config.enableAll || config.findFirstOrThrow) {
227
+ const opConfig = config.findFirstOrThrow || defaultOpConfig
228
+ const { before = [], after = [] } = opConfig
229
+ const path = basePath ? \`\${basePath}/first/strict\` : '/first/strict'
230
+ fastify.get(path, async (request, reply) => {
231
+ try {
232
+ parseQueryHook(request)
233
+ makeShapeHook(config, opConfig)(request)
234
+ if (await runHooks(before, request, reply)) return
235
+ await ${prefix}FindFirstOrThrow(request, reply)
236
+ if (await runHooks(after, request, reply)) return
237
+ sendResult(request, reply)
238
+ } catch (error: unknown) {
239
+ sendError(reply, error)
176
240
  }
177
241
  })
242
+ }
178
243
 
179
- if (!openApiDisabled) {
180
- const openapiJsonPath = basePath ? \`\${basePath}/openapi.json\` : '/openapi.json'
181
- const openapiYamlPath = basePath ? \`\${basePath}/openapi.yaml\` : '/openapi.yaml'
182
-
183
- fastify.get(openapiJsonPath, async (_request, reply) => {
184
- const spec = buildModelOpenApi(
185
- '${modelName}',
186
- MODEL_FIELDS as any,
187
- MODEL_ENUMS as any,
188
- config,
189
- { format: 'json' },
190
- )
191
- return reply.send(spec)
192
- })
193
-
194
- fastify.get(openapiYamlPath, async (_request, reply) => {
195
- const spec = buildModelOpenApi(
196
- '${modelName}',
197
- MODEL_FIELDS as any,
198
- MODEL_ENUMS as any,
199
- config,
200
- { format: 'yaml' },
201
- )
202
- return reply.type('application/yaml').send(spec as string)
203
- })
204
- }
205
-
206
- if (config.enableAll || config.findFirst) {
207
- const opConfig = config.findFirst || defaultOpConfig
208
- const { before = [], after = [] } = opConfig
209
- const path = basePath ? \`\${basePath}/first\` : '/first'
210
- fastify.get(path, async (request, reply) => {
211
- try {
212
- parseQueryHook(request)
213
- makeShapeHook(config, opConfig)(request)
214
- if (await runHooks(before, request, reply)) return
215
- await ${prefix}FindFirst(request, reply)
216
- if (await runHooks(after, request, reply)) return
217
- sendResult(request, reply)
218
- } catch (error: unknown) {
219
- sendError(reply, error)
220
- }
221
- })
222
- }
223
-
224
- if (config.enableAll || config.findFirstOrThrow) {
225
- const opConfig = config.findFirstOrThrow || defaultOpConfig
226
- const { before = [], after = [] } = opConfig
227
- const path = basePath ? \`\${basePath}/first/strict\` : '/first/strict'
228
- fastify.get(path, async (request, reply) => {
229
- try {
230
- parseQueryHook(request)
231
- makeShapeHook(config, opConfig)(request)
232
- if (await runHooks(before, request, reply)) return
233
- await ${prefix}FindFirstOrThrow(request, reply)
234
- if (await runHooks(after, request, reply)) return
235
- sendResult(request, reply)
236
- } catch (error: unknown) {
237
- sendError(reply, error)
238
- }
239
- })
240
- }
241
-
242
- if (config.enableAll || config.findManyPaginated) {
243
- const opConfig = config.findManyPaginated || defaultOpConfig
244
- const { before = [], after = [] } = opConfig
245
- const path = basePath ? \`\${basePath}/paginated\` : '/paginated'
246
- fastify.get(path, async (request, reply) => {
247
- try {
248
- parseQueryHook(request)
249
- makeShapeHook(config, opConfig)(request)
250
- if (await runHooks(before, request, reply)) return
251
- await ${prefix}FindManyPaginated(request, reply)
252
- if (await runHooks(after, request, reply)) return
253
- sendResult(request, reply)
254
- } catch (error: unknown) {
255
- sendError(reply, error)
256
- }
257
- })
258
- }
244
+ if (config.enableAll || config.findManyPaginated) {
245
+ const opConfig = config.findManyPaginated || defaultOpConfig
246
+ const { before = [], after = [] } = opConfig
247
+ const path = basePath ? \`\${basePath}/paginated\` : '/paginated'
248
+ fastify.get(path, async (request, reply) => {
249
+ try {
250
+ parseQueryHook(request)
251
+ makeShapeHook(config, opConfig)(request)
252
+ if (await runHooks(before, request, reply)) return
253
+ await ${prefix}FindManyPaginated(request, reply)
254
+ if (await runHooks(after, request, reply)) return
255
+ sendResult(request, reply)
256
+ } catch (error: unknown) {
257
+ sendError(reply, error)
258
+ }
259
+ })
260
+ }
259
261
 
260
- if (config.enableAll || config.aggregate) {
261
- const opConfig = config.aggregate || defaultOpConfig
262
- const { before = [], after = [] } = opConfig
263
- const path = basePath ? \`\${basePath}/aggregate\` : '/aggregate'
264
- fastify.get(path, async (request, reply) => {
265
- try {
266
- parseQueryHook(request)
267
- makeShapeHook(config, opConfig)(request)
268
- if (await runHooks(before, request, reply)) return
269
- await ${prefix}Aggregate(request, reply)
270
- if (await runHooks(after, request, reply)) return
271
- sendResult(request, reply)
272
- } catch (error: unknown) {
273
- sendError(reply, error)
274
- }
275
- })
276
- }
262
+ if (config.enableAll || config.aggregate) {
263
+ const opConfig = config.aggregate || defaultOpConfig
264
+ const { before = [], after = [] } = opConfig
265
+ const path = basePath ? \`\${basePath}/aggregate\` : '/aggregate'
266
+ fastify.get(path, async (request, reply) => {
267
+ try {
268
+ parseQueryHook(request)
269
+ makeShapeHook(config, opConfig)(request)
270
+ if (await runHooks(before, request, reply)) return
271
+ await ${prefix}Aggregate(request, reply)
272
+ if (await runHooks(after, request, reply)) return
273
+ sendResult(request, reply)
274
+ } catch (error: unknown) {
275
+ sendError(reply, error)
276
+ }
277
+ })
278
+ }
277
279
 
278
- if (config.enableAll || config.count) {
279
- const opConfig = config.count || defaultOpConfig
280
- const { before = [], after = [] } = opConfig
281
- const path = basePath ? \`\${basePath}/count\` : '/count'
282
- fastify.get(path, async (request, reply) => {
283
- try {
284
- parseQueryHook(request)
285
- makeShapeHook(config, opConfig)(request)
286
- if (await runHooks(before, request, reply)) return
287
- await ${prefix}Count(request, reply)
288
- if (await runHooks(after, request, reply)) return
289
- sendResult(request, reply)
290
- } catch (error: unknown) {
291
- sendError(reply, error)
292
- }
293
- })
294
- }
280
+ if (config.enableAll || config.count) {
281
+ const opConfig = config.count || defaultOpConfig
282
+ const { before = [], after = [] } = opConfig
283
+ const path = basePath ? \`\${basePath}/count\` : '/count'
284
+ fastify.get(path, async (request, reply) => {
285
+ try {
286
+ parseQueryHook(request)
287
+ makeShapeHook(config, opConfig)(request)
288
+ if (await runHooks(before, request, reply)) return
289
+ await ${prefix}Count(request, reply)
290
+ if (await runHooks(after, request, reply)) return
291
+ sendResult(request, reply)
292
+ } catch (error: unknown) {
293
+ sendError(reply, error)
294
+ }
295
+ })
296
+ }
295
297
 
296
- if (config.enableAll || config.groupBy) {
297
- const opConfig = config.groupBy || defaultOpConfig
298
- const { before = [], after = [] } = opConfig
299
- const path = basePath ? \`\${basePath}/groupby\` : '/groupby'
300
- fastify.get(path, async (request, reply) => {
301
- try {
302
- parseQueryHook(request)
303
- makeShapeHook(config, opConfig)(request)
304
- if (await runHooks(before, request, reply)) return
305
- await ${prefix}GroupBy(request, reply)
306
- if (await runHooks(after, request, reply)) return
307
- sendResult(request, reply)
308
- } catch (error: unknown) {
309
- sendError(reply, error)
310
- }
311
- })
312
- }
298
+ if (config.enableAll || config.groupBy) {
299
+ const opConfig = config.groupBy || defaultOpConfig
300
+ const { before = [], after = [] } = opConfig
301
+ const path = basePath ? \`\${basePath}/groupby\` : '/groupby'
302
+ fastify.get(path, async (request, reply) => {
303
+ try {
304
+ parseQueryHook(request)
305
+ makeShapeHook(config, opConfig)(request)
306
+ if (await runHooks(before, request, reply)) return
307
+ await ${prefix}GroupBy(request, reply)
308
+ if (await runHooks(after, request, reply)) return
309
+ sendResult(request, reply)
310
+ } catch (error: unknown) {
311
+ sendError(reply, error)
312
+ }
313
+ })
314
+ }
313
315
 
314
- if (config.enableAll || config.findUniqueOrThrow) {
315
- const opConfig = config.findUniqueOrThrow || defaultOpConfig
316
- const { before = [], after = [] } = opConfig
317
- const path = basePath ? \`\${basePath}/unique/strict\` : '/unique/strict'
318
- fastify.get(path, async (request, reply) => {
319
- try {
320
- parseQueryHook(request)
321
- makeShapeHook(config, opConfig)(request)
322
- if (await runHooks(before, request, reply)) return
323
- await ${prefix}FindUniqueOrThrow(request, reply)
324
- if (await runHooks(after, request, reply)) return
325
- sendResult(request, reply)
326
- } catch (error: unknown) {
327
- sendError(reply, error)
328
- }
329
- })
330
- }
316
+ if (config.enableAll || config.findUniqueOrThrow) {
317
+ const opConfig = config.findUniqueOrThrow || defaultOpConfig
318
+ const { before = [], after = [] } = opConfig
319
+ const path = basePath ? \`\${basePath}/unique/strict\` : '/unique/strict'
320
+ fastify.get(path, async (request, reply) => {
321
+ try {
322
+ parseQueryHook(request)
323
+ makeShapeHook(config, opConfig)(request)
324
+ if (await runHooks(before, request, reply)) return
325
+ await ${prefix}FindUniqueOrThrow(request, reply)
326
+ if (await runHooks(after, request, reply)) return
327
+ sendResult(request, reply)
328
+ } catch (error: unknown) {
329
+ sendError(reply, error)
330
+ }
331
+ })
332
+ }
331
333
 
332
- if (config.enableAll || config.findUnique) {
333
- const opConfig = config.findUnique || defaultOpConfig
334
- const { before = [], after = [] } = opConfig
335
- const path = basePath ? \`\${basePath}/unique\` : '/unique'
336
- fastify.get(path, async (request, reply) => {
337
- try {
338
- parseQueryHook(request)
339
- makeShapeHook(config, opConfig)(request)
340
- if (await runHooks(before, request, reply)) return
341
- await ${prefix}FindUnique(request, reply)
342
- if (await runHooks(after, request, reply)) return
343
- sendResult(request, reply)
344
- } catch (error: unknown) {
345
- sendError(reply, error)
346
- }
347
- })
348
- }
334
+ if (config.enableAll || config.findUnique) {
335
+ const opConfig = config.findUnique || defaultOpConfig
336
+ const { before = [], after = [] } = opConfig
337
+ const path = basePath ? \`\${basePath}/unique\` : '/unique'
338
+ fastify.get(path, async (request, reply) => {
339
+ try {
340
+ parseQueryHook(request)
341
+ makeShapeHook(config, opConfig)(request)
342
+ if (await runHooks(before, request, reply)) return
343
+ await ${prefix}FindUnique(request, reply)
344
+ if (await runHooks(after, request, reply)) return
345
+ sendResult(request, reply)
346
+ } catch (error: unknown) {
347
+ sendError(reply, error)
348
+ }
349
+ })
350
+ }
349
351
 
350
- if (config.enableAll || config.findMany) {
351
- const opConfig = config.findMany || defaultOpConfig
352
- const { before = [], after = [] } = opConfig
353
- const path = basePath || '/'
354
- fastify.get(path, async (request, reply) => {
355
- try {
356
- parseQueryHook(request)
357
- makeShapeHook(config, opConfig)(request)
358
- if (await runHooks(before, request, reply)) return
359
- await ${prefix}FindMany(request, reply)
360
- if (await runHooks(after, request, reply)) return
361
- sendResult(request, reply)
362
- } catch (error: unknown) {
363
- sendError(reply, error)
364
- }
365
- })
366
- }
352
+ if (config.enableAll || config.findMany) {
353
+ const opConfig = config.findMany || defaultOpConfig
354
+ const { before = [], after = [] } = opConfig
355
+ const path = basePath || '/'
356
+ fastify.get(path, async (request, reply) => {
357
+ try {
358
+ parseQueryHook(request)
359
+ makeShapeHook(config, opConfig)(request)
360
+ if (await runHooks(before, request, reply)) return
361
+ await ${prefix}FindMany(request, reply)
362
+ if (await runHooks(after, request, reply)) return
363
+ sendResult(request, reply)
364
+ } catch (error: unknown) {
365
+ sendError(reply, error)
366
+ }
367
+ })
368
+ }
367
369
 
368
- if (config.enableAll || config.createManyAndReturn) {
369
- const opConfig = config.createManyAndReturn || defaultOpConfig
370
- const { before = [], after = [] } = opConfig
371
- const path = basePath ? \`\${basePath}/many/return\` : '/many/return'
372
- fastify.post(path, async (request, reply) => {
373
- try {
374
- makeShapeHook(config, opConfig)(request)
375
- if (await runHooks(before, request, reply)) return
376
- await ${prefix}CreateManyAndReturn(request, reply)
377
- if (await runHooks(after, request, reply)) return
378
- sendResult(request, reply)
379
- } catch (error: unknown) {
380
- sendError(reply, error)
381
- }
382
- })
383
- }
370
+ if (config.enableAll || config.createManyAndReturn) {
371
+ const opConfig = config.createManyAndReturn || defaultOpConfig
372
+ const { before = [], after = [] } = opConfig
373
+ const path = basePath ? \`\${basePath}/many/return\` : '/many/return'
374
+ fastify.post(path, async (request, reply) => {
375
+ try {
376
+ makeShapeHook(config, opConfig)(request)
377
+ if (await runHooks(before, request, reply)) return
378
+ await ${prefix}CreateManyAndReturn(request, reply)
379
+ if (await runHooks(after, request, reply)) return
380
+ sendResult(request, reply)
381
+ } catch (error: unknown) {
382
+ sendError(reply, error)
383
+ }
384
+ })
385
+ }
384
386
 
385
- if (config.enableAll || config.createMany) {
386
- const opConfig = config.createMany || defaultOpConfig
387
- const { before = [], after = [] } = opConfig
388
- const path = basePath ? \`\${basePath}/many\` : '/many'
389
- fastify.post(path, async (request, reply) => {
390
- try {
391
- makeShapeHook(config, opConfig)(request)
392
- if (await runHooks(before, request, reply)) return
393
- await ${prefix}CreateMany(request, reply)
394
- if (await runHooks(after, request, reply)) return
395
- sendResult(request, reply)
396
- } catch (error: unknown) {
397
- sendError(reply, error)
398
- }
399
- })
400
- }
387
+ if (config.enableAll || config.createMany) {
388
+ const opConfig = config.createMany || defaultOpConfig
389
+ const { before = [], after = [] } = opConfig
390
+ const path = basePath ? \`\${basePath}/many\` : '/many'
391
+ fastify.post(path, async (request, reply) => {
392
+ try {
393
+ makeShapeHook(config, opConfig)(request)
394
+ if (await runHooks(before, request, reply)) return
395
+ await ${prefix}CreateMany(request, reply)
396
+ if (await runHooks(after, request, reply)) return
397
+ sendResult(request, reply)
398
+ } catch (error: unknown) {
399
+ sendError(reply, error)
400
+ }
401
+ })
402
+ }
401
403
 
402
- if (config.enableAll || config.create) {
403
- const opConfig = config.create || defaultOpConfig
404
- const { before = [], after = [] } = opConfig
405
- const path = basePath || '/'
406
- fastify.post(path, async (request, reply) => {
407
- try {
408
- makeShapeHook(config, opConfig)(request)
409
- if (await runHooks(before, request, reply)) return
410
- await ${prefix}Create(request, reply)
411
- if (await runHooks(after, request, reply)) return
412
- sendResult(request, reply)
413
- } catch (error: unknown) {
414
- sendError(reply, error)
415
- }
416
- })
417
- }
404
+ if (config.enableAll || config.create) {
405
+ const opConfig = config.create || defaultOpConfig
406
+ const { before = [], after = [] } = opConfig
407
+ const path = basePath || '/'
408
+ fastify.post(path, async (request, reply) => {
409
+ try {
410
+ makeShapeHook(config, opConfig)(request)
411
+ if (await runHooks(before, request, reply)) return
412
+ await ${prefix}Create(request, reply)
413
+ if (await runHooks(after, request, reply)) return
414
+ sendResult(request, reply)
415
+ } catch (error: unknown) {
416
+ sendError(reply, error)
417
+ }
418
+ })
419
+ }
418
420
 
419
- if (config.enableAll || config.updateManyAndReturn) {
420
- const opConfig = config.updateManyAndReturn || defaultOpConfig
421
- const { before = [], after = [] } = opConfig
422
- const path = basePath ? \`\${basePath}/many/return\` : '/many/return'
423
- fastify.put(path, async (request, reply) => {
424
- try {
425
- makeShapeHook(config, opConfig)(request)
426
- if (await runHooks(before, request, reply)) return
427
- await ${prefix}UpdateManyAndReturn(request, reply)
428
- if (await runHooks(after, request, reply)) return
429
- sendResult(request, reply)
430
- } catch (error: unknown) {
431
- sendError(reply, error)
432
- }
433
- })
434
- }
421
+ if (config.enableAll || config.updateManyAndReturn) {
422
+ const opConfig = config.updateManyAndReturn || defaultOpConfig
423
+ const { before = [], after = [] } = opConfig
424
+ const path = basePath ? \`\${basePath}/many/return\` : '/many/return'
425
+ fastify.put(path, async (request, reply) => {
426
+ try {
427
+ makeShapeHook(config, opConfig)(request)
428
+ if (await runHooks(before, request, reply)) return
429
+ await ${prefix}UpdateManyAndReturn(request, reply)
430
+ if (await runHooks(after, request, reply)) return
431
+ sendResult(request, reply)
432
+ } catch (error: unknown) {
433
+ sendError(reply, error)
434
+ }
435
+ })
436
+ }
435
437
 
436
- if (config.enableAll || config.updateMany) {
437
- const opConfig = config.updateMany || defaultOpConfig
438
- const { before = [], after = [] } = opConfig
439
- const path = basePath ? \`\${basePath}/many\` : '/many'
440
- fastify.put(path, async (request, reply) => {
441
- try {
442
- makeShapeHook(config, opConfig)(request)
443
- if (await runHooks(before, request, reply)) return
444
- await ${prefix}UpdateMany(request, reply)
445
- if (await runHooks(after, request, reply)) return
446
- sendResult(request, reply)
447
- } catch (error: unknown) {
448
- sendError(reply, error)
449
- }
450
- })
451
- }
438
+ if (config.enableAll || config.updateMany) {
439
+ const opConfig = config.updateMany || defaultOpConfig
440
+ const { before = [], after = [] } = opConfig
441
+ const path = basePath ? \`\${basePath}/many\` : '/many'
442
+ fastify.put(path, async (request, reply) => {
443
+ try {
444
+ makeShapeHook(config, opConfig)(request)
445
+ if (await runHooks(before, request, reply)) return
446
+ await ${prefix}UpdateMany(request, reply)
447
+ if (await runHooks(after, request, reply)) return
448
+ sendResult(request, reply)
449
+ } catch (error: unknown) {
450
+ sendError(reply, error)
451
+ }
452
+ })
453
+ }
452
454
 
453
- if (config.enableAll || config.update) {
454
- const opConfig = config.update || defaultOpConfig
455
- const { before = [], after = [] } = opConfig
456
- const path = basePath || '/'
457
- fastify.put(path, async (request, reply) => {
458
- try {
459
- makeShapeHook(config, opConfig)(request)
460
- if (await runHooks(before, request, reply)) return
461
- await ${prefix}Update(request, reply)
462
- if (await runHooks(after, request, reply)) return
463
- sendResult(request, reply)
464
- } catch (error: unknown) {
465
- sendError(reply, error)
466
- }
467
- })
468
- }
455
+ if (config.enableAll || config.update) {
456
+ const opConfig = config.update || defaultOpConfig
457
+ const { before = [], after = [] } = opConfig
458
+ const path = basePath || '/'
459
+ fastify.put(path, async (request, reply) => {
460
+ try {
461
+ makeShapeHook(config, opConfig)(request)
462
+ if (await runHooks(before, request, reply)) return
463
+ await ${prefix}Update(request, reply)
464
+ if (await runHooks(after, request, reply)) return
465
+ sendResult(request, reply)
466
+ } catch (error: unknown) {
467
+ sendError(reply, error)
468
+ }
469
+ })
470
+ }
469
471
 
470
- if (config.enableAll || config.upsert) {
471
- const opConfig = config.upsert || defaultOpConfig
472
- const { before = [], after = [] } = opConfig
473
- const path = basePath || '/'
474
- fastify.patch(path, async (request, reply) => {
475
- try {
476
- makeShapeHook(config, opConfig)(request)
477
- if (await runHooks(before, request, reply)) return
478
- await ${prefix}Upsert(request, reply)
479
- if (await runHooks(after, request, reply)) return
480
- sendResult(request, reply)
481
- } catch (error: unknown) {
482
- sendError(reply, error)
483
- }
484
- })
485
- }
472
+ if (config.enableAll || config.upsert) {
473
+ const opConfig = config.upsert || defaultOpConfig
474
+ const { before = [], after = [] } = opConfig
475
+ const path = basePath || '/'
476
+ fastify.patch(path, async (request, reply) => {
477
+ try {
478
+ makeShapeHook(config, opConfig)(request)
479
+ if (await runHooks(before, request, reply)) return
480
+ await ${prefix}Upsert(request, reply)
481
+ if (await runHooks(after, request, reply)) return
482
+ sendResult(request, reply)
483
+ } catch (error: unknown) {
484
+ sendError(reply, error)
485
+ }
486
+ })
487
+ }
486
488
 
487
- if (config.enableAll || config.deleteMany) {
488
- const opConfig = config.deleteMany || defaultOpConfig
489
- const { before = [], after = [] } = opConfig
490
- const path = basePath ? \`\${basePath}/many\` : '/many'
491
- fastify.delete(path, async (request, reply) => {
492
- try {
493
- makeShapeHook(config, opConfig)(request)
494
- if (await runHooks(before, request, reply)) return
495
- await ${prefix}DeleteMany(request, reply)
496
- if (await runHooks(after, request, reply)) return
497
- sendResult(request, reply)
498
- } catch (error: unknown) {
499
- sendError(reply, error)
500
- }
501
- })
502
- }
489
+ if (config.enableAll || config.deleteMany) {
490
+ const opConfig = config.deleteMany || defaultOpConfig
491
+ const { before = [], after = [] } = opConfig
492
+ const path = basePath ? \`\${basePath}/many\` : '/many'
493
+ fastify.delete(path, async (request, reply) => {
494
+ try {
495
+ makeShapeHook(config, opConfig)(request)
496
+ if (await runHooks(before, request, reply)) return
497
+ await ${prefix}DeleteMany(request, reply)
498
+ if (await runHooks(after, request, reply)) return
499
+ sendResult(request, reply)
500
+ } catch (error: unknown) {
501
+ sendError(reply, error)
502
+ }
503
+ })
504
+ }
503
505
 
504
- if (config.enableAll || config.delete) {
505
- const opConfig = config.delete || defaultOpConfig
506
- const { before = [], after = [] } = opConfig
507
- const path = basePath || '/'
508
- fastify.delete(path, async (request, reply) => {
509
- try {
510
- makeShapeHook(config, opConfig)(request)
511
- if (await runHooks(before, request, reply)) return
512
- await ${prefix}Delete(request, reply)
513
- if (await runHooks(after, request, reply)) return
514
- sendResult(request, reply)
515
- } catch (error: unknown) {
516
- sendError(reply, error)
517
- }
518
- })
519
- }
506
+ if (config.enableAll || config.delete) {
507
+ const opConfig = config.delete || defaultOpConfig
508
+ const { before = [], after = [] } = opConfig
509
+ const path = basePath || '/'
510
+ fastify.delete(path, async (request, reply) => {
511
+ try {
512
+ makeShapeHook(config, opConfig)(request)
513
+ if (await runHooks(before, request, reply)) return
514
+ await ${prefix}Delete(request, reply)
515
+ if (await runHooks(after, request, reply)) return
516
+ sendResult(request, reply)
517
+ } catch (error: unknown) {
518
+ sendError(reply, error)
519
+ }
520
+ })
520
521
  }
521
522
  }
522
523
  `