prisma-generator-express 1.34.1 → 1.34.2

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