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