prisma-generator-express 1.33.0 → 1.34.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generators/generateFastifyHandler.js +12 -4
- package/dist/generators/generateFastifyHandler.js.map +1 -1
- package/dist/generators/generateOperationCore.js +1 -1
- package/dist/generators/generateOperationCore.js.map +1 -1
- package/dist/generators/generateRouter.js +39 -37
- package/dist/generators/generateRouter.js.map +1 -1
- package/dist/generators/generateRouterFastify.js +369 -368
- package/dist/generators/generateRouterFastify.js.map +1 -1
- package/dist/generators/generateUnifiedHandler.js +10 -2
- package/dist/generators/generateUnifiedHandler.js.map +1 -1
- package/dist/index.js +9 -12
- package/dist/index.js.map +1 -1
- package/dist/utils/strings.js +4 -1
- package/dist/utils/strings.js.map +1 -1
- package/package.json +1 -1
- package/src/generators/generateFastifyHandler.ts +14 -4
- package/src/generators/generateOperationCore.ts +1 -1
- package/src/generators/generateRouter.ts +39 -37
- package/src/generators/generateRouterFastify.ts +369 -368
- package/src/generators/generateUnifiedHandler.ts +12 -2
- package/src/index.ts +10 -15
- package/src/utils/strings.ts +4 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper'
|
|
2
|
+
import { toCamelCase } from '../utils/strings.js'
|
|
2
3
|
|
|
3
4
|
export function generateFastifyRouterFunction({
|
|
4
5
|
model,
|
|
@@ -8,8 +9,9 @@ export function generateFastifyRouterFunction({
|
|
|
8
9
|
enums: DMMF.DatamodelEnum[]
|
|
9
10
|
}): string {
|
|
10
11
|
const modelName = model.name
|
|
12
|
+
const prefix = toCamelCase(modelName)
|
|
11
13
|
const modelNameLower = modelName.toLowerCase()
|
|
12
|
-
const routerFunctionName = `${
|
|
14
|
+
const routerFunctionName = `${prefix}Router`
|
|
13
15
|
|
|
14
16
|
const fieldsMeta = model.fields.map((f) => ({
|
|
15
17
|
name: f.name,
|
|
@@ -34,26 +36,26 @@ export function generateFastifyRouterFunction({
|
|
|
34
36
|
values: e.values.map((v) => ({ name: v.name })),
|
|
35
37
|
}))
|
|
36
38
|
|
|
37
|
-
return `import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'
|
|
39
|
+
return `import type { FastifyInstance, FastifyRequest, FastifyReply, FastifyError } from 'fastify'
|
|
38
40
|
import {
|
|
39
|
-
${
|
|
40
|
-
${
|
|
41
|
-
${
|
|
42
|
-
${
|
|
43
|
-
${
|
|
44
|
-
${
|
|
45
|
-
${
|
|
46
|
-
${
|
|
47
|
-
${
|
|
48
|
-
${
|
|
49
|
-
${
|
|
50
|
-
${
|
|
51
|
-
${
|
|
52
|
-
${
|
|
53
|
-
${
|
|
54
|
-
${
|
|
55
|
-
${
|
|
56
|
-
${
|
|
41
|
+
${prefix}FindUnique,
|
|
42
|
+
${prefix}FindUniqueOrThrow,
|
|
43
|
+
${prefix}FindFirst,
|
|
44
|
+
${prefix}FindFirstOrThrow,
|
|
45
|
+
${prefix}FindMany,
|
|
46
|
+
${prefix}FindManyPaginated,
|
|
47
|
+
${prefix}Create,
|
|
48
|
+
${prefix}CreateMany,
|
|
49
|
+
${prefix}CreateManyAndReturn,
|
|
50
|
+
${prefix}Update,
|
|
51
|
+
${prefix}UpdateMany,
|
|
52
|
+
${prefix}UpdateManyAndReturn,
|
|
53
|
+
${prefix}Upsert,
|
|
54
|
+
${prefix}Delete,
|
|
55
|
+
${prefix}DeleteMany,
|
|
56
|
+
${prefix}Aggregate,
|
|
57
|
+
${prefix}Count,
|
|
58
|
+
${prefix}GroupBy,
|
|
57
59
|
} from './${modelName}Handlers.js'
|
|
58
60
|
import type { RouteConfig, FastifyHookHandler } from '../routeConfig.target.js'
|
|
59
61
|
import { parseQueryParams } from '../parseQueryParams.js'
|
|
@@ -145,377 +147,376 @@ function sendError(reply: FastifyReply, error: unknown): void {
|
|
|
145
147
|
reply.code(httpError.status).send({ message: httpError.message })
|
|
146
148
|
}
|
|
147
149
|
|
|
148
|
-
export
|
|
149
|
-
fastify: FastifyInstance
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const modelPrefix = config.addModelPrefix !== false ? '/${modelNameLower}' : ''
|
|
154
|
-
const basePath = customPrefix + modelPrefix
|
|
155
|
-
|
|
156
|
-
const openApiDisabled = config.disableOpenApi === true
|
|
157
|
-
|| (config.disableOpenApi !== false && (
|
|
158
|
-
_env.DISABLE_OPENAPI === 'true'
|
|
159
|
-
|| _env.NODE_ENV === 'production'
|
|
160
|
-
))
|
|
161
|
-
|
|
162
|
-
const qbEnabled = isQueryBuilderEnabled(config)
|
|
163
|
-
|
|
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) }
|
|
168
|
-
}
|
|
169
|
-
}
|
|
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
|
|
170
155
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
})
|
|
178
|
-
|
|
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
|
-
})
|
|
156
|
+
const openApiDisabled = config.disableOpenApi === true
|
|
157
|
+
|| (config.disableOpenApi !== false && (
|
|
158
|
+
_env.DISABLE_OPENAPI === 'true'
|
|
159
|
+
|| _env.NODE_ENV === 'production'
|
|
160
|
+
))
|
|
193
161
|
|
|
194
|
-
|
|
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
|
-
}
|
|
162
|
+
const qbEnabled = isQueryBuilderEnabled(config)
|
|
205
163
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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 ${modelName}FindFirst(request, reply)
|
|
216
|
-
if (await runHooks(after, request, reply)) return
|
|
217
|
-
sendResult(request, reply)
|
|
218
|
-
} catch (error: unknown) {
|
|
219
|
-
sendError(reply, error)
|
|
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) }
|
|
220
168
|
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
169
|
+
}
|
|
223
170
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
try {
|
|
230
|
-
parseQueryHook(request)
|
|
231
|
-
makeShapeHook(config, opConfig)(request)
|
|
232
|
-
if (await runHooks(before, request, reply)) return
|
|
233
|
-
await ${modelName}FindFirstOrThrow(request, reply)
|
|
234
|
-
if (await runHooks(after, request, reply)) return
|
|
235
|
-
sendResult(request, reply)
|
|
236
|
-
} catch (error: unknown) {
|
|
237
|
-
sendError(reply, error)
|
|
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 })
|
|
238
176
|
}
|
|
239
177
|
})
|
|
240
|
-
}
|
|
241
178
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
+
}
|
|
259
205
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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
|
+
}
|
|
277
223
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
+
}
|
|
295
241
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
+
}
|
|
313
259
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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
|
+
}
|
|
331
277
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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
|
+
}
|
|
349
295
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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
|
+
}
|
|
367
313
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
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
|
+
}
|
|
384
331
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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
|
+
}
|
|
401
349
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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
|
+
}
|
|
418
367
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
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
|
+
}
|
|
435
384
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
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
|
+
}
|
|
452
401
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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
|
+
}
|
|
469
418
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
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
|
+
}
|
|
486
435
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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
|
+
}
|
|
503
452
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
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
|
+
}
|
|
469
|
+
|
|
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
|
+
}
|
|
486
|
+
|
|
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
|
+
}
|
|
503
|
+
|
|
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
|
+
}
|
|
519
520
|
}
|
|
520
521
|
}
|
|
521
522
|
`
|