prisma-generator-express 1.59.0 → 1.61.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 +150 -14
- package/dist/client/encodeQueryParams.js +19 -23
- package/dist/client/encodeQueryParams.js.map +1 -1
- package/dist/copy/operationDefinitions.d.ts +37 -0
- package/dist/copy/operationDefinitions.js +412 -0
- package/dist/copy/operationDefinitions.js.map +1 -0
- package/dist/generators/generateFastifyHandler.js +10 -41
- package/dist/generators/generateFastifyHandler.js.map +1 -1
- package/dist/generators/generateHonoHandler.js +10 -41
- package/dist/generators/generateHonoHandler.js.map +1 -1
- package/dist/generators/generateModelMetadata.d.ts +8 -0
- package/dist/generators/generateModelMetadata.js +77 -0
- package/dist/generators/generateModelMetadata.js.map +1 -0
- package/dist/generators/generateOperationCore.js +20 -30
- package/dist/generators/generateOperationCore.js.map +1 -1
- package/dist/generators/generateQueryBuilderHelper.js +1 -1
- package/dist/generators/generateQueryBuilderHelper.js.map +1 -1
- package/dist/generators/generateRouteConfigType.js +11 -57
- package/dist/generators/generateRouteConfigType.js.map +1 -1
- package/dist/generators/generateRouter.js +64 -177
- package/dist/generators/generateRouter.js.map +1 -1
- package/dist/generators/generateRouterFastify.js +59 -169
- package/dist/generators/generateRouterFastify.js.map +1 -1
- package/dist/generators/generateRouterHono.js +52 -152
- package/dist/generators/generateRouterHono.js.map +1 -1
- package/dist/generators/generateUnifiedHandler.js +7 -30
- package/dist/generators/generateUnifiedHandler.js.map +1 -1
- package/dist/generators/generateUnifiedScalarUI.js +9 -74
- package/dist/generators/generateUnifiedScalarUI.js.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/copyFiles.js +7 -0
- package/dist/utils/copyFiles.js.map +1 -1
- package/dist/utils/writeFileSafely.js +5 -12
- package/dist/utils/writeFileSafely.js.map +1 -1
- package/package.json +12 -2
- package/src/client/encodeQueryParams.ts +23 -36
- package/src/copy/autoIncludePlanner.ts +14 -23
- package/src/copy/autoIncludePlannerGuarded.ts +477 -0
- package/src/copy/autoIncludeRuntime.ts +269 -261
- package/src/copy/autoIncludeRuntimeGuarded.ts +379 -0
- package/src/copy/buildModelOpenApi.ts +248 -628
- package/src/copy/concurrency.ts +20 -0
- package/src/copy/docsRenderer.ts +63 -333
- package/src/copy/errorMapper.ts +126 -0
- package/src/copy/guardHelpers.ts +56 -0
- package/src/copy/materializedCount.ts +68 -0
- package/src/copy/materializedRouter.ts +33 -29
- package/src/copy/operationDefinitions.ts +359 -35
- package/src/copy/operationRuntime.ts +11 -605
- package/src/copy/pagination.ts +151 -0
- package/src/copy/scalarTypes.ts +2 -0
- package/src/copy/sse.ts +296 -0
- package/src/generators/generateFastifyHandler.ts +13 -47
- package/src/generators/generateHonoHandler.ts +13 -47
- package/src/generators/generateModelMetadata.ts +92 -0
- package/src/generators/generateOperationCore.ts +19 -32
- package/src/generators/generateQueryBuilderHelper.ts +1 -1
- package/src/generators/generateRouteConfigType.ts +9 -60
- package/src/generators/generateRouter.ts +88 -180
- package/src/generators/generateRouterFastify.ts +65 -172
- package/src/generators/generateRouterHono.ts +58 -155
- package/src/generators/generateUnifiedHandler.ts +8 -33
- package/src/generators/generateUnifiedScalarUI.ts +9 -91
- package/src/index.ts +13 -1
- package/src/utils/copyFiles.ts +7 -0
- package/src/utils/writeFileSafely.ts +5 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouter.js","sourceRoot":"","sources":["../../src/generators/generateRouter.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generateRouter.js","sourceRoot":"","sources":["../../src/generators/generateRouter.ts"],"names":[],"mappings":";;AA4DA,wDA4ZC;AAvdD,uEAAmE;AAEnE,kDAA8C;AAE9C,uEAAiE;AAQjE,SAAS,QAAQ,CAAC,QAAgB,EAAE,MAAc;IAChD,IAAI,CAAC,MAAM;QAAE,OAAO,QAAQ,IAAI,GAAG,CAAA;IACnC,IAAI,CAA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;8BACP,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+EvC,YAAY;;EAEZ,aAAa;;;;;;YAMH,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCpB,CAAA;AACD,CAAC"}
|
|
@@ -3,56 +3,62 @@ 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
|
+
const operationDefinitions_1 = require("../copy/operationDefinitions");
|
|
7
|
+
function pathExpr(suffix) {
|
|
8
|
+
if (!suffix)
|
|
9
|
+
return `basePath || '/'`;
|
|
10
|
+
return `\`\${basePath}${suffix}\``;
|
|
11
|
+
}
|
|
12
|
+
function emitReadOp(meta, modelName) {
|
|
13
|
+
const c = meta.name.charAt(0).toUpperCase() + meta.name.slice(1);
|
|
14
|
+
const handlerName = `${modelName}${c}`;
|
|
15
|
+
const pathValue = pathExpr(meta.pathSuffix);
|
|
16
|
+
const postReadLine = meta.supportsPostRead
|
|
17
|
+
? meta.name === 'findMany'
|
|
18
|
+
? ` if (postReadsEnabled) {
|
|
19
|
+
const postPath = basePath ? \`\${basePath}/read\` : '/read'
|
|
20
|
+
instance.post(postPath, handleRead(opConfig, ${handlerName}, parseBodyAsQueryHook))
|
|
21
|
+
}`
|
|
22
|
+
: ` if (postReadsEnabled) instance.post(path, handleRead(opConfig, ${handlerName}, parseBodyAsQueryHook))`
|
|
23
|
+
: '';
|
|
24
|
+
return ` if (isEnabled(config.${meta.configKey})) {
|
|
25
|
+
const opConfig: OperationConfigLike = (config.${meta.configKey} as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
26
|
+
const path = ${pathValue}
|
|
27
|
+
instance.get(path, handleRead(opConfig, ${handlerName}, parseQueryHook))
|
|
28
|
+
${postReadLine}
|
|
29
|
+
}`;
|
|
30
|
+
}
|
|
31
|
+
function emitWriteOp(meta, modelName) {
|
|
32
|
+
const c = meta.name.charAt(0).toUpperCase() + meta.name.slice(1);
|
|
33
|
+
const handlerName = `${modelName}${c}`;
|
|
34
|
+
const pathValue = pathExpr(meta.pathSuffix);
|
|
35
|
+
return ` if (isEnabled(config.${meta.configKey})) {
|
|
36
|
+
const opConfig: OperationConfigLike = (config.${meta.configKey} as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
37
|
+
const path = ${pathValue}
|
|
38
|
+
instance.${meta.method}(path, handleWrite(opConfig, ${handlerName}))
|
|
39
|
+
}`;
|
|
40
|
+
}
|
|
6
41
|
function generateFastifyRouterFunction({ model, enums, guardShapesImport, importStyle, writeStrategy, findManyPaginatedMode, dropGuard, }) {
|
|
7
42
|
const ext = (0, importExt_1.importExt)(importStyle);
|
|
8
43
|
const modelName = model.name;
|
|
9
44
|
const modelNameLower = modelName.toLowerCase();
|
|
10
45
|
const routerFunctionName = `${modelName}Router`;
|
|
11
|
-
const
|
|
12
|
-
name
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
documentation: f.documentation,
|
|
20
|
-
relationFromFields: f.relationFromFields,
|
|
21
|
-
}));
|
|
22
|
-
const referencedEnumTypes = new Set(model.fields.filter((f) => f.kind === 'enum').map((f) => f.type));
|
|
23
|
-
const enumsMeta = enums
|
|
24
|
-
.filter((e) => referencedEnumTypes.has(e.name))
|
|
25
|
-
.map((e) => ({
|
|
26
|
-
name: e.name,
|
|
27
|
-
values: e.values.map((v) => ({ name: v.name })),
|
|
28
|
-
}));
|
|
46
|
+
const handlerImports = operationDefinitions_1.OPERATION_METADATA
|
|
47
|
+
.map((m) => ` ${modelName}${m.name.charAt(0).toUpperCase() + m.name.slice(1)},`)
|
|
48
|
+
.join('\n');
|
|
49
|
+
const readOps = operationDefinitions_1.OPERATION_METADATA.filter((m) => m.kind === 'read');
|
|
50
|
+
const writeOps = operationDefinitions_1.OPERATION_METADATA.filter((m) => m.kind === 'write' || m.kind === 'batch')
|
|
51
|
+
.filter((m) => m.name !== 'updateEach');
|
|
52
|
+
const readOpBlocks = readOps.map((m) => emitReadOp(m, modelName)).join('\n\n');
|
|
53
|
+
const writeOpBlocks = writeOps.map((m) => emitWriteOp(m, modelName)).join('\n\n');
|
|
29
54
|
return `import type { FastifyInstance, FastifyRequest, FastifyReply, FastifyError } from 'fastify'
|
|
30
55
|
import { startQueryBuilder } from '../queryBuilder${ext}'
|
|
31
56
|
import {
|
|
32
|
-
|
|
33
|
-
${modelName}FindUniqueOrThrow,
|
|
34
|
-
${modelName}FindFirst,
|
|
35
|
-
${modelName}FindFirstOrThrow,
|
|
36
|
-
${modelName}FindMany,
|
|
37
|
-
${modelName}FindManyPaginated,
|
|
38
|
-
${modelName}Create,
|
|
39
|
-
${modelName}CreateMany,
|
|
40
|
-
${modelName}CreateManyAndReturn,
|
|
41
|
-
${modelName}Update,
|
|
42
|
-
${modelName}UpdateMany,
|
|
43
|
-
${modelName}UpdateManyAndReturn,
|
|
44
|
-
${modelName}Upsert,
|
|
45
|
-
${modelName}Delete,
|
|
46
|
-
${modelName}DeleteMany,
|
|
47
|
-
${modelName}Aggregate,
|
|
48
|
-
${modelName}Count,
|
|
49
|
-
${modelName}GroupBy,
|
|
50
|
-
${modelName}UpdateEach,
|
|
57
|
+
${handlerImports}
|
|
51
58
|
} from './${modelName}Handlers${ext}'
|
|
52
59
|
import type {
|
|
53
60
|
RouteConfig,
|
|
54
61
|
FastifyHookHandler,
|
|
55
|
-
WriteStrategy,
|
|
56
62
|
FindManyPaginatedMode,
|
|
57
63
|
PaginationConfig,
|
|
58
64
|
} from '../routeConfig.target${ext}'
|
|
@@ -60,19 +66,18 @@ import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
|
60
66
|
import { sanitizeKeys, normalizePrefix, getEnv } from '../misc${ext}'
|
|
61
67
|
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
62
68
|
import { validateCountSourceWhere } from '../routeConfig${ext}'
|
|
63
|
-
import {
|
|
69
|
+
import type { OperationContext } from '../operationRuntime${ext}'
|
|
70
|
+
import { transformResult } from '../operationRuntime${ext}'
|
|
71
|
+
import { HttpError, mapError } from '../errorMapper${ext}'
|
|
72
|
+
import { mergePaginationConfig } from '../pagination${ext}'
|
|
73
|
+
import { MODEL_FIELDS, MODEL_ENUMS } from './${modelName}Metadata${ext}'
|
|
64
74
|
|
|
65
75
|
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'FastifyHookHandler', guardShapesImport, importStyle, 'fastify')}
|
|
66
76
|
const _env = getEnv()
|
|
67
77
|
|
|
68
|
-
const WRITE_STRATEGY: WriteStrategy = '${writeStrategy}'
|
|
69
78
|
const FIND_MANY_PAGINATED_MODE: FindManyPaginatedMode = '${findManyPaginatedMode}'
|
|
70
79
|
const DROP_GUARD = ${dropGuard} || _env.E2E === 'true'
|
|
71
80
|
|
|
72
|
-
const MODEL_FIELDS = ${JSON.stringify(fieldsMeta, null, 2)} as const
|
|
73
|
-
|
|
74
|
-
const MODEL_ENUMS = ${JSON.stringify(enumsMeta, null, 2)} as const
|
|
75
|
-
|
|
76
81
|
type OperationConfigLike = {
|
|
77
82
|
before?: FastifyHookHandler[]
|
|
78
83
|
after?: FastifyHookHandler[]
|
|
@@ -211,7 +216,7 @@ export async function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(
|
|
|
211
216
|
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
212
217
|
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
213
218
|
config,
|
|
214
|
-
{ format: 'json', writeStrategy:
|
|
219
|
+
{ format: 'json', writeStrategy: '${writeStrategy}' },
|
|
215
220
|
)
|
|
216
221
|
}
|
|
217
222
|
return _openApiJsonCache
|
|
@@ -224,7 +229,7 @@ export async function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(
|
|
|
224
229
|
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
225
230
|
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
226
231
|
config,
|
|
227
|
-
{ format: 'yaml', writeStrategy:
|
|
232
|
+
{ format: 'yaml', writeStrategy: '${writeStrategy}' },
|
|
228
233
|
) as string
|
|
229
234
|
}
|
|
230
235
|
return _openApiYamlCache
|
|
@@ -248,11 +253,9 @@ export async function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(
|
|
|
248
253
|
})
|
|
249
254
|
|
|
250
255
|
instance.setErrorHandler((error: FastifyError, _request: FastifyRequest, reply: FastifyReply) => {
|
|
251
|
-
const
|
|
252
|
-
const status = e.status ?? e.statusCode ?? 500
|
|
253
|
-
const message = error.message || 'Internal server error'
|
|
256
|
+
const httpError = mapError(error)
|
|
254
257
|
if (!reply.sent) {
|
|
255
|
-
reply.code(status).send({ message })
|
|
258
|
+
reply.code(httpError.status).send({ message: httpError.message })
|
|
256
259
|
}
|
|
257
260
|
})
|
|
258
261
|
|
|
@@ -269,7 +272,7 @@ export async function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(
|
|
|
269
272
|
})
|
|
270
273
|
}
|
|
271
274
|
|
|
272
|
-
const
|
|
275
|
+
const handleRead = (
|
|
273
276
|
opConfig: OperationConfigLike,
|
|
274
277
|
handlerFn: (req: FastifyRequest, reply: FastifyReply) => Promise<void>,
|
|
275
278
|
parseFn: (req: FastifyRequest) => void,
|
|
@@ -303,125 +306,9 @@ export async function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(
|
|
|
303
306
|
}
|
|
304
307
|
}
|
|
305
308
|
|
|
306
|
-
|
|
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
|
-
}
|
|
312
|
-
|
|
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
|
-
}
|
|
319
|
-
|
|
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
|
-
}
|
|
326
|
-
|
|
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
|
-
}
|
|
333
|
-
|
|
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
|
-
}
|
|
340
|
-
|
|
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
|
-
}
|
|
347
|
-
|
|
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
|
-
}
|
|
354
|
-
|
|
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))
|
|
360
|
-
}
|
|
361
|
-
|
|
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
|
-
}
|
|
371
|
-
|
|
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
|
-
}
|
|
309
|
+
${readOpBlocks}
|
|
377
310
|
|
|
378
|
-
|
|
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
|
-
}
|
|
383
|
-
|
|
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
|
-
}
|
|
389
|
-
|
|
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
|
-
}
|
|
395
|
-
|
|
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
|
-
}
|
|
401
|
-
|
|
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
|
-
}
|
|
407
|
-
|
|
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
|
-
}
|
|
413
|
-
|
|
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
|
-
}
|
|
311
|
+
${writeOpBlocks}
|
|
425
312
|
|
|
426
313
|
if (config.updateEach) {
|
|
427
314
|
const opConfig: OperationConfigLike = (config.updateEach as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
@@ -434,6 +321,9 @@ export async function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(
|
|
|
434
321
|
const path = basePath ? \`\${basePath}/each\` : '/each'
|
|
435
322
|
instance.post(path, async (request: FastifyRequest, reply: FastifyReply) => {
|
|
436
323
|
try {
|
|
324
|
+
if (!Array.isArray(request.body)) {
|
|
325
|
+
throw new HttpError(400, 'updateEach body must be an array of { where, data } items')
|
|
326
|
+
}
|
|
437
327
|
makeShapeHook(config, opConfig)(request)
|
|
438
328
|
const { before = [], after = [] } = opConfig
|
|
439
329
|
if (await runHooks(before, request, reply)) return
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouterFastify.js","sourceRoot":"","sources":["../../src/generators/generateRouterFastify.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generateRouterFastify.js","sourceRoot":"","sources":["../../src/generators/generateRouterFastify.ts"],"names":[],"mappings":";;AA8CA,sEAgUC;AA7WD,uEAAmE;AAEnE,kDAA8C;AAE9C,uEAAiE;AAEjE,SAAS,QAAQ,CAAC,MAAc;IAC9B,IAAI,CAAC,MAAM;QAAE,OAAO,iBAAiB,CAAA;IACrC,OAAO,iBAAiB,MAAM,IAAI,CAAA;AACpC,CAAC;AAED,SAAS,UAAU,CAAC,IAAyC,EAAE,SAAiB;IAC9E,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAChE,MAAM,WAAW,GAAG,GAAG,SAAS,GAAG,CAAC,EAAE,CAAA;IACtC,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IAE3C,MAAM,YAAY,GAAG,IAAI,CAAC,gBAAgB;QACxC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,UAAU;YACxB,CAAC,CAAC;;uDAE+C,WAAW;QAC1D;YACF,CAAC,CAAC,wEAAwE,WAAW,0BAA0B;QACjH,CAAC,CAAC,EAAE,CAAA;IAEN,OAAO,4BAA4B,IAAI,CAAC,SAAS;sDACG,IAAI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,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6EzD,YAAY;;EAEZ,aAAa;;;;;;cAMD,SAAS;;;;;;;;;;;;;kBAaL,SAAS;;;;;;;;;;CAU1B,CAAA;AACD,CAAC"}
|
|
@@ -3,53 +3,60 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateHonoRouterFunction = generateHonoRouterFunction;
|
|
4
4
|
const generateRouteConfigType_1 = require("./generateRouteConfigType");
|
|
5
5
|
const importExt_1 = require("../utils/importExt");
|
|
6
|
+
const operationDefinitions_1 = require("../copy/operationDefinitions");
|
|
7
|
+
function pathExpr(suffix) {
|
|
8
|
+
if (!suffix)
|
|
9
|
+
return `basePath || '/'`;
|
|
10
|
+
return `\`\${basePath}${suffix}\``;
|
|
11
|
+
}
|
|
12
|
+
function emitReadOp(meta, modelName) {
|
|
13
|
+
const c = meta.name.charAt(0).toUpperCase() + meta.name.slice(1);
|
|
14
|
+
const handlerName = `${modelName}${c}`;
|
|
15
|
+
const pathValue = pathExpr(meta.pathSuffix);
|
|
16
|
+
const postReadLine = meta.supportsPostRead
|
|
17
|
+
? meta.name === 'findMany'
|
|
18
|
+
? ` if (postReadsEnabled) {
|
|
19
|
+
const postPath = basePath ? \`\${basePath}/read\` : '/read'
|
|
20
|
+
app.post(postPath, handleRead(opConfig, ${handlerName}, parseBodyAsQueryMiddleware))
|
|
21
|
+
}`
|
|
22
|
+
: ` if (postReadsEnabled) app.post(path, handleRead(opConfig, ${handlerName}, parseBodyAsQueryMiddleware))`
|
|
23
|
+
: '';
|
|
24
|
+
return ` if (isEnabled(config.${meta.configKey})) {
|
|
25
|
+
const opConfig = opFor('${meta.configKey}')
|
|
26
|
+
const path = ${pathValue}
|
|
27
|
+
app.get(path, handleRead(opConfig, ${handlerName}, parseQueryMiddleware))
|
|
28
|
+
${postReadLine}
|
|
29
|
+
}`;
|
|
30
|
+
}
|
|
31
|
+
function emitWriteOp(meta, modelName) {
|
|
32
|
+
const c = meta.name.charAt(0).toUpperCase() + meta.name.slice(1);
|
|
33
|
+
const handlerName = `${modelName}${c}`;
|
|
34
|
+
const pathValue = pathExpr(meta.pathSuffix);
|
|
35
|
+
return ` if (isEnabled(config.${meta.configKey})) {
|
|
36
|
+
const opConfig = opFor('${meta.configKey}')
|
|
37
|
+
const path = ${pathValue}
|
|
38
|
+
app.${meta.method}(path, handleWrite(opConfig, ${handlerName}))
|
|
39
|
+
}`;
|
|
40
|
+
}
|
|
6
41
|
function generateHonoRouterFunction({ model, enums, guardShapesImport, importStyle, writeStrategy, dropGuard, }) {
|
|
7
42
|
const ext = (0, importExt_1.importExt)(importStyle);
|
|
8
43
|
const modelName = model.name;
|
|
9
44
|
const modelNameLower = modelName.toLowerCase();
|
|
10
45
|
const routerFunctionName = `${modelName}Router`;
|
|
11
|
-
const
|
|
12
|
-
name
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
documentation: f.documentation,
|
|
20
|
-
relationFromFields: f.relationFromFields,
|
|
21
|
-
}));
|
|
22
|
-
const referencedEnumTypes = new Set(model.fields.filter((f) => f.kind === 'enum').map((f) => f.type));
|
|
23
|
-
const enumsMeta = enums
|
|
24
|
-
.filter((e) => referencedEnumTypes.has(e.name))
|
|
25
|
-
.map((e) => ({
|
|
26
|
-
name: e.name,
|
|
27
|
-
values: e.values.map((v) => ({ name: v.name })),
|
|
28
|
-
}));
|
|
46
|
+
const handlerImports = operationDefinitions_1.OPERATION_METADATA
|
|
47
|
+
.map((m) => ` ${modelName}${m.name.charAt(0).toUpperCase() + m.name.slice(1)},`)
|
|
48
|
+
.join('\n');
|
|
49
|
+
const readOps = operationDefinitions_1.OPERATION_METADATA.filter((m) => m.kind === 'read');
|
|
50
|
+
const writeOps = operationDefinitions_1.OPERATION_METADATA.filter((m) => m.kind === 'write' || m.kind === 'batch')
|
|
51
|
+
.filter((m) => m.name !== 'updateEach');
|
|
52
|
+
const readOpBlocks = readOps.map((m) => emitReadOp(m, modelName)).join('\n\n');
|
|
53
|
+
const writeOpBlocks = writeOps.map((m) => emitWriteOp(m, modelName)).join('\n\n');
|
|
29
54
|
return `import { Hono } from 'hono'
|
|
30
55
|
import type { Context } from 'hono'
|
|
31
56
|
import type { ContentfulStatusCode } from 'hono/utils/http-status'
|
|
32
57
|
import { HTTPException } from 'hono/http-exception'
|
|
33
58
|
import {
|
|
34
|
-
|
|
35
|
-
${modelName}FindUniqueOrThrow,
|
|
36
|
-
${modelName}FindFirst,
|
|
37
|
-
${modelName}FindFirstOrThrow,
|
|
38
|
-
${modelName}FindMany,
|
|
39
|
-
${modelName}FindManyPaginated,
|
|
40
|
-
${modelName}Create,
|
|
41
|
-
${modelName}CreateMany,
|
|
42
|
-
${modelName}CreateManyAndReturn,
|
|
43
|
-
${modelName}Update,
|
|
44
|
-
${modelName}UpdateMany,
|
|
45
|
-
${modelName}UpdateManyAndReturn,
|
|
46
|
-
${modelName}Upsert,
|
|
47
|
-
${modelName}Delete,
|
|
48
|
-
${modelName}DeleteMany,
|
|
49
|
-
${modelName}Aggregate,
|
|
50
|
-
${modelName}Count,
|
|
51
|
-
${modelName}GroupBy,
|
|
52
|
-
${modelName}UpdateEach,
|
|
59
|
+
${handlerImports}
|
|
53
60
|
} from './${modelName}Handlers${ext}'
|
|
54
61
|
import type {
|
|
55
62
|
RouteConfig,
|
|
@@ -58,23 +65,20 @@ import type {
|
|
|
58
65
|
HonoEnvBase,
|
|
59
66
|
HonoInternalVariables,
|
|
60
67
|
GeneratedHonoEnv,
|
|
61
|
-
WriteStrategy,
|
|
62
68
|
PaginationConfig,
|
|
63
69
|
} from '../routeConfig.target${ext}'
|
|
64
70
|
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
65
71
|
import { normalizePrefix, getEnv, sanitizeKeys } from '../misc${ext}'
|
|
66
72
|
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
67
73
|
import { validateCountSourceWhere } from '../routeConfig${ext}'
|
|
68
|
-
import {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
} from '../operationRuntime${ext}'
|
|
74
|
+
import { transformResult } from '../operationRuntime${ext}'
|
|
75
|
+
import { mapError } from '../errorMapper${ext}'
|
|
76
|
+
import { mergePaginationConfig } from '../pagination${ext}'
|
|
77
|
+
import { MODEL_FIELDS, MODEL_ENUMS } from './${modelName}Metadata${ext}'
|
|
73
78
|
|
|
74
79
|
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'HonoBeforeHook', guardShapesImport, importStyle, 'hono')}
|
|
75
80
|
const _env = getEnv()
|
|
76
81
|
|
|
77
|
-
const WRITE_STRATEGY: WriteStrategy = '${writeStrategy}'
|
|
78
82
|
const DROP_GUARD = ${dropGuard} || _env.E2E === 'true'
|
|
79
83
|
|
|
80
84
|
type JsonLike =
|
|
@@ -85,10 +89,6 @@ type JsonLike =
|
|
|
85
89
|
| JsonLike[]
|
|
86
90
|
| { [k: string]: JsonLike }
|
|
87
91
|
|
|
88
|
-
const MODEL_FIELDS = ${JSON.stringify(fieldsMeta, null, 2)} as const
|
|
89
|
-
|
|
90
|
-
const MODEL_ENUMS = ${JSON.stringify(enumsMeta, null, 2)} as const
|
|
91
|
-
|
|
92
92
|
type OperationConfigLike<TEnv extends HonoEnvBase> = {
|
|
93
93
|
before?: HonoBeforeHook<TEnv>[]
|
|
94
94
|
after?: HonoAfterHook<TEnv>[]
|
|
@@ -238,7 +238,7 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
238
238
|
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
239
239
|
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
240
240
|
config as RouteConfig,
|
|
241
|
-
{ format: 'json', writeStrategy:
|
|
241
|
+
{ format: 'json', writeStrategy: '${writeStrategy}' },
|
|
242
242
|
)
|
|
243
243
|
}
|
|
244
244
|
return _openApiJsonCache
|
|
@@ -251,7 +251,7 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
251
251
|
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
252
252
|
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
253
253
|
config as RouteConfig,
|
|
254
|
-
{ format: 'yaml', writeStrategy:
|
|
254
|
+
{ format: 'yaml', writeStrategy: '${writeStrategy}' },
|
|
255
255
|
) as string
|
|
256
256
|
}
|
|
257
257
|
return _openApiYamlCache
|
|
@@ -322,109 +322,9 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
322
322
|
?? (defaultOpConfig as OperationConfigLike<TEnv>)
|
|
323
323
|
}
|
|
324
324
|
|
|
325
|
-
|
|
326
|
-
const opConfig = opFor('findFirst')
|
|
327
|
-
const path = basePath ? \`\${basePath}/first\` : '/first'
|
|
328
|
-
app.get(path, handleRead(opConfig, ${modelName}FindFirst, parseQueryMiddleware))
|
|
329
|
-
if (postReadsEnabled) app.post(path, handleRead(opConfig, ${modelName}FindFirst, parseBodyAsQueryMiddleware))
|
|
330
|
-
}
|
|
331
|
-
if (isEnabled(config.findFirstOrThrow)) {
|
|
332
|
-
const opConfig = opFor('findFirstOrThrow')
|
|
333
|
-
const path = basePath ? \`\${basePath}/first/strict\` : '/first/strict'
|
|
334
|
-
app.get(path, handleRead(opConfig, ${modelName}FindFirstOrThrow, parseQueryMiddleware))
|
|
335
|
-
if (postReadsEnabled) app.post(path, handleRead(opConfig, ${modelName}FindFirstOrThrow, parseBodyAsQueryMiddleware))
|
|
336
|
-
}
|
|
337
|
-
if (isEnabled(config.findManyPaginated)) {
|
|
338
|
-
const opConfig = opFor('findManyPaginated')
|
|
339
|
-
const path = basePath ? \`\${basePath}/paginated\` : '/paginated'
|
|
340
|
-
app.get(path, handleRead(opConfig, ${modelName}FindManyPaginated, parseQueryMiddleware))
|
|
341
|
-
if (postReadsEnabled) app.post(path, handleRead(opConfig, ${modelName}FindManyPaginated, parseBodyAsQueryMiddleware))
|
|
342
|
-
}
|
|
343
|
-
if (isEnabled(config.aggregate)) {
|
|
344
|
-
const opConfig = opFor('aggregate')
|
|
345
|
-
const path = basePath ? \`\${basePath}/aggregate\` : '/aggregate'
|
|
346
|
-
app.get(path, handleRead(opConfig, ${modelName}Aggregate, parseQueryMiddleware))
|
|
347
|
-
if (postReadsEnabled) app.post(path, handleRead(opConfig, ${modelName}Aggregate, parseBodyAsQueryMiddleware))
|
|
348
|
-
}
|
|
349
|
-
if (isEnabled(config.count)) {
|
|
350
|
-
const opConfig = opFor('count')
|
|
351
|
-
const path = basePath ? \`\${basePath}/count\` : '/count'
|
|
352
|
-
app.get(path, handleRead(opConfig, ${modelName}Count, parseQueryMiddleware))
|
|
353
|
-
if (postReadsEnabled) app.post(path, handleRead(opConfig, ${modelName}Count, parseBodyAsQueryMiddleware))
|
|
354
|
-
}
|
|
355
|
-
if (isEnabled(config.groupBy)) {
|
|
356
|
-
const opConfig = opFor('groupBy')
|
|
357
|
-
const path = basePath ? \`\${basePath}/groupby\` : '/groupby'
|
|
358
|
-
app.get(path, handleRead(opConfig, ${modelName}GroupBy, parseQueryMiddleware))
|
|
359
|
-
if (postReadsEnabled) app.post(path, handleRead(opConfig, ${modelName}GroupBy, parseBodyAsQueryMiddleware))
|
|
360
|
-
}
|
|
361
|
-
if (isEnabled(config.findUniqueOrThrow)) {
|
|
362
|
-
const opConfig = opFor('findUniqueOrThrow')
|
|
363
|
-
const path = basePath ? \`\${basePath}/unique/strict\` : '/unique/strict'
|
|
364
|
-
app.get(path, handleRead(opConfig, ${modelName}FindUniqueOrThrow, parseQueryMiddleware))
|
|
365
|
-
if (postReadsEnabled) app.post(path, handleRead(opConfig, ${modelName}FindUniqueOrThrow, parseBodyAsQueryMiddleware))
|
|
366
|
-
}
|
|
367
|
-
if (isEnabled(config.findUnique)) {
|
|
368
|
-
const opConfig = opFor('findUnique')
|
|
369
|
-
const path = basePath ? \`\${basePath}/unique\` : '/unique'
|
|
370
|
-
app.get(path, handleRead(opConfig, ${modelName}FindUnique, parseQueryMiddleware))
|
|
371
|
-
if (postReadsEnabled) app.post(path, handleRead(opConfig, ${modelName}FindUnique, parseBodyAsQueryMiddleware))
|
|
372
|
-
}
|
|
373
|
-
if (isEnabled(config.findMany)) {
|
|
374
|
-
const opConfig = opFor('findMany')
|
|
375
|
-
const path = basePath || '/'
|
|
376
|
-
app.get(path, handleRead(opConfig, ${modelName}FindMany, parseQueryMiddleware))
|
|
377
|
-
if (postReadsEnabled) {
|
|
378
|
-
const postPath = basePath ? \`\${basePath}/read\` : '/read'
|
|
379
|
-
app.post(postPath, handleRead(opConfig, ${modelName}FindMany, parseBodyAsQueryMiddleware))
|
|
380
|
-
}
|
|
381
|
-
}
|
|
325
|
+
${readOpBlocks}
|
|
382
326
|
|
|
383
|
-
|
|
384
|
-
const opConfig = opFor('createManyAndReturn')
|
|
385
|
-
const path = basePath ? \`\${basePath}/many/return\` : '/many/return'
|
|
386
|
-
app.post(path, handleWrite(opConfig, ${modelName}CreateManyAndReturn))
|
|
387
|
-
}
|
|
388
|
-
if (isEnabled(config.createMany)) {
|
|
389
|
-
const opConfig = opFor('createMany')
|
|
390
|
-
const path = basePath ? \`\${basePath}/many\` : '/many'
|
|
391
|
-
app.post(path, handleWrite(opConfig, ${modelName}CreateMany))
|
|
392
|
-
}
|
|
393
|
-
if (isEnabled(config.create)) {
|
|
394
|
-
const opConfig = opFor('create')
|
|
395
|
-
const path = basePath || '/'
|
|
396
|
-
app.post(path, handleWrite(opConfig, ${modelName}Create))
|
|
397
|
-
}
|
|
398
|
-
if (isEnabled(config.updateManyAndReturn)) {
|
|
399
|
-
const opConfig = opFor('updateManyAndReturn')
|
|
400
|
-
const path = basePath ? \`\${basePath}/many/return\` : '/many/return'
|
|
401
|
-
app.put(path, handleWrite(opConfig, ${modelName}UpdateManyAndReturn))
|
|
402
|
-
}
|
|
403
|
-
if (isEnabled(config.updateMany)) {
|
|
404
|
-
const opConfig = opFor('updateMany')
|
|
405
|
-
const path = basePath ? \`\${basePath}/many\` : '/many'
|
|
406
|
-
app.put(path, handleWrite(opConfig, ${modelName}UpdateMany))
|
|
407
|
-
}
|
|
408
|
-
if (isEnabled(config.update)) {
|
|
409
|
-
const opConfig = opFor('update')
|
|
410
|
-
const path = basePath || '/'
|
|
411
|
-
app.put(path, handleWrite(opConfig, ${modelName}Update))
|
|
412
|
-
}
|
|
413
|
-
if (isEnabled(config.upsert)) {
|
|
414
|
-
const opConfig = opFor('upsert')
|
|
415
|
-
const path = basePath || '/'
|
|
416
|
-
app.patch(path, handleWrite(opConfig, ${modelName}Upsert))
|
|
417
|
-
}
|
|
418
|
-
if (isEnabled(config.deleteMany)) {
|
|
419
|
-
const opConfig = opFor('deleteMany')
|
|
420
|
-
const path = basePath ? \`\${basePath}/many\` : '/many'
|
|
421
|
-
app.delete(path, handleWrite(opConfig, ${modelName}DeleteMany))
|
|
422
|
-
}
|
|
423
|
-
if (isEnabled(config.delete)) {
|
|
424
|
-
const opConfig = opFor('delete')
|
|
425
|
-
const path = basePath || '/'
|
|
426
|
-
app.delete(path, handleWrite(opConfig, ${modelName}Delete))
|
|
427
|
-
}
|
|
327
|
+
${writeOpBlocks}
|
|
428
328
|
|
|
429
329
|
if (config.updateEach) {
|
|
430
330
|
const opConfig = (config.updateEach as unknown as OperationConfigLike<TEnv> | undefined) ?? (defaultOpConfig as OperationConfigLike<TEnv>)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouterHono.js","sourceRoot":"","sources":["../../src/generators/generateRouterHono.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generateRouterHono.js","sourceRoot":"","sources":["../../src/generators/generateRouterHono.ts"],"names":[],"mappings":";;AA8CA,gEA+UC;AA5XD,uEAAmE;AAEnE,kDAA8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