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}(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
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
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
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
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
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
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
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
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
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
|
`;
|