prisma-generator-express 1.62.0 → 1.62.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.
- package/dist/generators/generateRouter.js +54 -17
- package/dist/generators/generateRouter.js.map +1 -1
- package/dist/generators/generateRouterFastify.js +43 -8
- package/dist/generators/generateRouterFastify.js.map +1 -1
- package/dist/generators/generateRouterHono.js +43 -7
- package/dist/generators/generateRouterHono.js.map +1 -1
- package/dist/utils/copyFiles.js +1 -0
- package/dist/utils/copyFiles.js.map +1 -1
- package/package.json +1 -1
- package/src/copy/autoIncludeRuntimeGuarded.ts +3 -3
- package/src/copy/projectionDefaults.ts +380 -0
- package/src/generators/generateRouter.ts +55 -24
- package/src/generators/generateRouterFastify.ts +43 -8
- package/src/generators/generateRouterHono.ts +43 -7
- package/src/utils/copyFiles.ts +1 -0
|
@@ -18,14 +18,14 @@ function emitReadOp(meta, modelName) {
|
|
|
18
18
|
const postReadBlock = meta.supportsPostRead
|
|
19
19
|
? ` if (postReadsEnabled) {
|
|
20
20
|
const postPath = ${meta.name === 'findMany' ? "basePath ? `${basePath}/read` : '/read'" : `path`}
|
|
21
|
-
router.post(postPath, parseBodyAsQuery, setShape(opConfig), ...before, ${handlerName} as RequestHandler, ...after, respond)
|
|
21
|
+
router.post(postPath, parseBodyAsQuery, setShape(opConfig, 'read'), ...before, ${handlerName} as RequestHandler, ...after, respond)
|
|
22
22
|
}`
|
|
23
23
|
: '';
|
|
24
24
|
return ` if (isEnabled(config.${meta.configKey})) {
|
|
25
25
|
const opConfig: OperationConfigLike = (config.${meta.configKey} as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
26
26
|
const { before = [], after = [] } = opConfig
|
|
27
27
|
const path = ${pathValue}
|
|
28
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.${meta.coreName}, '${meta.name}'), ${handlerName} as RequestHandler, ...after, respond)
|
|
28
|
+
router.get(path, parseQuery, setShape(opConfig, 'read'), ...before, maybeProgressiveSSE(opConfig, core.${meta.coreName}, '${meta.name}'), ${handlerName} as RequestHandler, ...after, respond)
|
|
29
29
|
${postReadBlock}
|
|
30
30
|
}`;
|
|
31
31
|
}
|
|
@@ -38,7 +38,7 @@ function emitWriteOp(meta, modelName) {
|
|
|
38
38
|
const opConfig: OperationConfigLike = (config.${meta.configKey} as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
39
39
|
const { before = [], after = [] } = opConfig
|
|
40
40
|
const path = ${pathValue}
|
|
41
|
-
router.${meta.method}(path, setShape(opConfig), ...before, ${handlerName} as RequestHandler, ...after, ${respondFn})
|
|
41
|
+
router.${meta.method}(path, setShape(opConfig, 'write'), ...before, ${handlerName} as RequestHandler, ...after, ${respondFn})
|
|
42
42
|
}`;
|
|
43
43
|
}
|
|
44
44
|
function generateRouterFunction({ model, enums, guardShapesImport, importStyle, writeStrategy, findManyPaginatedMode, dropGuard, }) {
|
|
@@ -70,7 +70,7 @@ import type {
|
|
|
70
70
|
PaginationConfig,
|
|
71
71
|
} from '../routeConfig.target${ext}'
|
|
72
72
|
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
73
|
-
import { sanitizeKeys, normalizePrefix, getEnv } from '../misc${ext}'
|
|
73
|
+
import { sanitizeKeys, normalizePrefix, getEnv, isPlainObject } from '../misc${ext}'
|
|
74
74
|
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
75
75
|
import { validateCountSourceWhere } from '../routeConfig${ext}'
|
|
76
76
|
import type { OperationContext } from '../operationRuntime${ext}'
|
|
@@ -86,6 +86,10 @@ import {
|
|
|
86
86
|
} from '../sse${ext}'
|
|
87
87
|
import { relationModels } from '../relationModels${ext}'
|
|
88
88
|
import { runAutoIncludeProgressive } from '../autoIncludeRuntime${ext}'
|
|
89
|
+
import {
|
|
90
|
+
resolveDroppedGuardProjection,
|
|
91
|
+
applyProjectionToTarget,
|
|
92
|
+
} from '../projectionDefaults${ext}'
|
|
89
93
|
import { MODEL_FIELDS, MODEL_ENUMS } from './${modelName}Metadata${ext}'
|
|
90
94
|
|
|
91
95
|
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'RequestHandler', guardShapesImport, importStyle, 'express')}
|
|
@@ -214,6 +218,11 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(config: ${m
|
|
|
214
218
|
}
|
|
215
219
|
}
|
|
216
220
|
|
|
221
|
+
const buildResolveContext = (req: Request): (() => unknown | Promise<unknown>) | undefined => {
|
|
222
|
+
if (typeof config.resolveContext !== 'function') return undefined
|
|
223
|
+
return () => (config.resolveContext as (r: Request) => unknown | Promise<unknown>)(req)
|
|
224
|
+
}
|
|
225
|
+
|
|
217
226
|
const parseQuery: RequestHandler = (req, res, next) => {
|
|
218
227
|
const rawQuery = req.query
|
|
219
228
|
if (rawQuery && Object.keys(rawQuery).length > 0) {
|
|
@@ -231,19 +240,47 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(config: ${m
|
|
|
231
240
|
next()
|
|
232
241
|
}
|
|
233
242
|
|
|
234
|
-
const setShape = (opConfig: OperationConfigLike): RequestHandler => {
|
|
235
|
-
return (req, res, next) => {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
243
|
+
const setShape = (opConfig: OperationConfigLike, kind: 'read' | 'write'): RequestHandler => {
|
|
244
|
+
return async (req, res, next) => {
|
|
245
|
+
try {
|
|
246
|
+
const locals = readLocals(res)
|
|
247
|
+
const merged = mergePaginationConfig(config.pagination, opConfig.pagination)
|
|
248
|
+
if (merged) {
|
|
249
|
+
locals.routeConfig = { pagination: merged }
|
|
250
|
+
}
|
|
251
|
+
const headerName = config.guard?.variantHeader || 'x-api-variant'
|
|
252
|
+
const headerValue = req.get(headerName)
|
|
253
|
+
const caller = config.guard?.resolveVariant?.(req) ?? headerValue ?? undefined
|
|
254
|
+
if (caller) locals.guardCaller = caller
|
|
255
|
+
if (opConfig.shape) {
|
|
256
|
+
if (!DROP_GUARD) {
|
|
257
|
+
locals.guardShape = opConfig.shape
|
|
258
|
+
} else {
|
|
259
|
+
const projection = await resolveDroppedGuardProjection(
|
|
260
|
+
opConfig.shape,
|
|
261
|
+
caller,
|
|
262
|
+
buildResolveContext(req),
|
|
263
|
+
)
|
|
264
|
+
if (projection) {
|
|
265
|
+
if (kind === 'read') {
|
|
266
|
+
if (!locals.parsedQuery) locals.parsedQuery = {}
|
|
267
|
+
applyProjectionToTarget(locals.parsedQuery, projection)
|
|
268
|
+
} else {
|
|
269
|
+
if (!isPlainObject(req.body)) {
|
|
270
|
+
req.body = {}
|
|
271
|
+
}
|
|
272
|
+
applyProjectionToTarget(
|
|
273
|
+
req.body as Record<string, unknown>,
|
|
274
|
+
projection,
|
|
275
|
+
)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
next()
|
|
281
|
+
} catch (err) {
|
|
282
|
+
next(mapError(err))
|
|
240
283
|
}
|
|
241
|
-
const headerName = config.guard?.variantHeader || 'x-api-variant'
|
|
242
|
-
const headerValue = req.get(headerName)
|
|
243
|
-
const caller = config.guard?.resolveVariant?.(req) ?? headerValue ?? undefined
|
|
244
|
-
if (caller) locals.guardCaller = caller
|
|
245
|
-
if (opConfig.shape && !DROP_GUARD) locals.guardShape = opConfig.shape
|
|
246
|
-
next()
|
|
247
284
|
}
|
|
248
285
|
}
|
|
249
286
|
|
|
@@ -398,7 +435,7 @@ ${writeOpBlocks}
|
|
|
398
435
|
const path = basePath ? \`\${basePath}/each\` : '/each'
|
|
399
436
|
router.post(
|
|
400
437
|
path,
|
|
401
|
-
setShape(opConfig),
|
|
438
|
+
setShape(opConfig, 'write'),
|
|
402
439
|
...before,
|
|
403
440
|
async (req: Request, res: Response, next: NextFunction) => {
|
|
404
441
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouter.js","sourceRoot":"","sources":["../../src/generators/generateRouter.ts"],"names":[],"mappings":";;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AS;;;OAGhE,SAAS;;;;;;;;4DAQ4C,cAAc;;;;;;;;;;;;WAY/D,SAAS;;;;4CAIwB,aAAa;;;;;;;;;WAS9C,SAAS;;;;4CAIwB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BA2J7B,SAAS;8BACP,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+EvC,YAAY;;EAEZ,aAAa;;;;;;YAMH,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCpB,CAAA;AACD,CAAC"}
|
|
@@ -63,13 +63,17 @@ import type {
|
|
|
63
63
|
PaginationConfig,
|
|
64
64
|
} from '../routeConfig.target${ext}'
|
|
65
65
|
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
66
|
-
import { sanitizeKeys, normalizePrefix, getEnv } from '../misc${ext}'
|
|
66
|
+
import { sanitizeKeys, normalizePrefix, getEnv, isPlainObject } from '../misc${ext}'
|
|
67
67
|
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
68
68
|
import { validateCountSourceWhere } from '../routeConfig${ext}'
|
|
69
69
|
import type { OperationContext } from '../operationRuntime${ext}'
|
|
70
70
|
import { transformResult } from '../operationRuntime${ext}'
|
|
71
71
|
import { HttpError, mapError } from '../errorMapper${ext}'
|
|
72
72
|
import { mergePaginationConfig } from '../pagination${ext}'
|
|
73
|
+
import {
|
|
74
|
+
resolveDroppedGuardProjection,
|
|
75
|
+
applyProjectionToTarget,
|
|
76
|
+
} from '../projectionDefaults${ext}'
|
|
73
77
|
import { MODEL_FIELDS, MODEL_ENUMS } from './${modelName}Metadata${ext}'
|
|
74
78
|
|
|
75
79
|
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'FastifyHookHandler', guardShapesImport, importStyle, 'fastify')}
|
|
@@ -130,11 +134,20 @@ function parseBodyAsQueryHook(request: FastifyRequest): void {
|
|
|
130
134
|
(request as FastifyExtended).parsedQuery = sanitizeKeys(body as Record<string, unknown>)
|
|
131
135
|
}
|
|
132
136
|
|
|
137
|
+
function buildResolveContext(
|
|
138
|
+
config: ${modelName}RouteConfig,
|
|
139
|
+
request: FastifyRequest,
|
|
140
|
+
): (() => unknown | Promise<unknown>) | undefined {
|
|
141
|
+
if (typeof config.resolveContext !== 'function') return undefined
|
|
142
|
+
return () => (config.resolveContext as (r: FastifyRequest) => unknown | Promise<unknown>)(request)
|
|
143
|
+
}
|
|
144
|
+
|
|
133
145
|
function makeShapeHook(
|
|
134
146
|
config: ${modelName}RouteConfig,
|
|
135
147
|
opConfig: OperationConfigLike,
|
|
136
|
-
|
|
137
|
-
|
|
148
|
+
kind: 'read' | 'write',
|
|
149
|
+
): (request: FastifyRequest) => Promise<void> {
|
|
150
|
+
return async (request: FastifyRequest) => {
|
|
138
151
|
const fx = request as FastifyExtended
|
|
139
152
|
const merged = mergePaginationConfig(config.pagination, opConfig.pagination)
|
|
140
153
|
if (merged) {
|
|
@@ -148,8 +161,30 @@ function makeShapeHook(
|
|
|
148
161
|
if (caller) {
|
|
149
162
|
fx.guardCaller = caller
|
|
150
163
|
}
|
|
151
|
-
if (opConfig.shape
|
|
152
|
-
|
|
164
|
+
if (opConfig.shape) {
|
|
165
|
+
if (!DROP_GUARD) {
|
|
166
|
+
fx.guardShape = opConfig.shape
|
|
167
|
+
} else {
|
|
168
|
+
const projection = await resolveDroppedGuardProjection(
|
|
169
|
+
opConfig.shape,
|
|
170
|
+
caller,
|
|
171
|
+
buildResolveContext(config, request),
|
|
172
|
+
)
|
|
173
|
+
if (projection) {
|
|
174
|
+
if (kind === 'read') {
|
|
175
|
+
if (!fx.parsedQuery) fx.parsedQuery = {}
|
|
176
|
+
applyProjectionToTarget(fx.parsedQuery, projection)
|
|
177
|
+
} else {
|
|
178
|
+
if (!isPlainObject(request.body)) {
|
|
179
|
+
;(request as unknown as { body: unknown }).body = {}
|
|
180
|
+
}
|
|
181
|
+
applyProjectionToTarget(
|
|
182
|
+
request.body as Record<string, unknown>,
|
|
183
|
+
projection,
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
153
188
|
}
|
|
154
189
|
}
|
|
155
190
|
}
|
|
@@ -279,7 +314,7 @@ export async function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(
|
|
|
279
314
|
) => async (request: FastifyRequest, reply: FastifyReply) => {
|
|
280
315
|
try {
|
|
281
316
|
parseFn(request)
|
|
282
|
-
makeShapeHook(config, opConfig)(request)
|
|
317
|
+
await makeShapeHook(config, opConfig, 'read')(request)
|
|
283
318
|
const { before = [], after = [] } = opConfig
|
|
284
319
|
if (await runHooks(before, request, reply)) return
|
|
285
320
|
await handlerFn(request, reply)
|
|
@@ -295,7 +330,7 @@ export async function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(
|
|
|
295
330
|
handlerFn: (req: FastifyRequest, reply: FastifyReply) => Promise<void>,
|
|
296
331
|
) => async (request: FastifyRequest, reply: FastifyReply) => {
|
|
297
332
|
try {
|
|
298
|
-
makeShapeHook(config, opConfig)(request)
|
|
333
|
+
await makeShapeHook(config, opConfig, 'write')(request)
|
|
299
334
|
const { before = [], after = [] } = opConfig
|
|
300
335
|
if (await runHooks(before, request, reply)) return
|
|
301
336
|
await handlerFn(request, reply)
|
|
@@ -324,7 +359,7 @@ ${writeOpBlocks}
|
|
|
324
359
|
if (!Array.isArray(request.body)) {
|
|
325
360
|
throw new HttpError(400, 'updateEach body must be an array of { where, data } items')
|
|
326
361
|
}
|
|
327
|
-
makeShapeHook(config, opConfig)(request)
|
|
362
|
+
await makeShapeHook(config, opConfig, 'write')(request)
|
|
328
363
|
const { before = [], after = [] } = opConfig
|
|
329
364
|
if (await runHooks(before, request, reply)) return
|
|
330
365
|
await ${modelName}UpdateEach(request, reply)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouterFastify.js","sourceRoot":"","sources":["../../src/generators/generateRouterFastify.ts"],"names":[],"mappings":";;AA8CA,
|
|
1
|
+
{"version":3,"file":"generateRouterFastify.js","sourceRoot":"","sources":["../../src/generators/generateRouterFastify.ts"],"names":[],"mappings":";;AA8CA,sEAmWC;AAhZD,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,CAAC,SAAS;qBAC/C,SAAS;gDACkB,WAAW;EACzD,YAAY;MACR,CAAA;AACN,CAAC;AAED,SAAS,WAAW,CAAC,IAAyC,EAAE,SAAiB;IAC/E,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC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AY;;EAEZ,aAAa;;;;;;cAMD,SAAS;;;;;;;;;;;;;kBAaL,SAAS;;;;;;;;;;CAU1B,CAAA;AACD,CAAC"}
|
|
@@ -68,12 +68,16 @@ import type {
|
|
|
68
68
|
PaginationConfig,
|
|
69
69
|
} from '../routeConfig.target${ext}'
|
|
70
70
|
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
71
|
-
import { normalizePrefix, getEnv, sanitizeKeys } from '../misc${ext}'
|
|
71
|
+
import { normalizePrefix, getEnv, sanitizeKeys, isPlainObject } from '../misc${ext}'
|
|
72
72
|
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
73
73
|
import { validateCountSourceWhere } from '../routeConfig${ext}'
|
|
74
74
|
import { transformResult } from '../operationRuntime${ext}'
|
|
75
75
|
import { mapError } from '../errorMapper${ext}'
|
|
76
76
|
import { mergePaginationConfig } from '../pagination${ext}'
|
|
77
|
+
import {
|
|
78
|
+
resolveDroppedGuardProjection,
|
|
79
|
+
applyProjectionToTarget,
|
|
80
|
+
} from '../projectionDefaults${ext}'
|
|
77
81
|
import { MODEL_FIELDS, MODEL_ENUMS } from './${modelName}Metadata${ext}'
|
|
78
82
|
|
|
79
83
|
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'HonoBeforeHook', guardShapesImport, importStyle, 'hono')}
|
|
@@ -152,8 +156,9 @@ async function parseUpdateEachBodyMiddleware(c: HandlerContext): Promise<void> {
|
|
|
152
156
|
function makeShapeMiddleware<TCtx, TPrisma, TEnv extends HonoEnvBase>(
|
|
153
157
|
config: ${modelName}RouteConfig<TCtx, TPrisma, TEnv>,
|
|
154
158
|
opConfig: OperationConfigLike<TEnv>,
|
|
159
|
+
kind: 'read' | 'write',
|
|
155
160
|
) {
|
|
156
|
-
return (c: Context<GeneratedHonoEnv<TEnv>>): void => {
|
|
161
|
+
return async (c: Context<GeneratedHonoEnv<TEnv>>): Promise<void> => {
|
|
157
162
|
const merged = mergePaginationConfig(config.pagination, opConfig.pagination)
|
|
158
163
|
if (merged) {
|
|
159
164
|
c.set('routeConfig', { pagination: merged })
|
|
@@ -162,8 +167,39 @@ function makeShapeMiddleware<TCtx, TPrisma, TEnv extends HonoEnvBase>(
|
|
|
162
167
|
const headerValue = c.req.header(headerName)
|
|
163
168
|
const caller = config.guard?.resolveVariant?.(c) ?? headerValue ?? undefined
|
|
164
169
|
if (caller) c.set('guardCaller', caller)
|
|
165
|
-
if (opConfig.shape
|
|
166
|
-
|
|
170
|
+
if (opConfig.shape) {
|
|
171
|
+
if (!DROP_GUARD) {
|
|
172
|
+
c.set('guardShape', opConfig.shape)
|
|
173
|
+
} else {
|
|
174
|
+
const resolveCtx = typeof config.resolveContext === 'function'
|
|
175
|
+
? () => (config.resolveContext as (ctx: Context<GeneratedHonoEnv<TEnv>>) => unknown | Promise<unknown>)(c)
|
|
176
|
+
: undefined
|
|
177
|
+
const projection = await resolveDroppedGuardProjection(
|
|
178
|
+
opConfig.shape,
|
|
179
|
+
caller,
|
|
180
|
+
resolveCtx,
|
|
181
|
+
)
|
|
182
|
+
if (projection) {
|
|
183
|
+
if (kind === 'read') {
|
|
184
|
+
let target = c.get('parsedQuery')
|
|
185
|
+
if (!target) {
|
|
186
|
+
target = {}
|
|
187
|
+
c.set('parsedQuery', target)
|
|
188
|
+
}
|
|
189
|
+
applyProjectionToTarget(target, projection)
|
|
190
|
+
} else {
|
|
191
|
+
let target = c.get('body')
|
|
192
|
+
if (!isPlainObject(target)) {
|
|
193
|
+
target = {}
|
|
194
|
+
c.set('body', target)
|
|
195
|
+
}
|
|
196
|
+
applyProjectionToTarget(
|
|
197
|
+
target as Record<string, unknown>,
|
|
198
|
+
projection,
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
167
203
|
}
|
|
168
204
|
}
|
|
169
205
|
}
|
|
@@ -285,7 +321,7 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
285
321
|
) => async (c: Context<GeneratedHonoEnv<TEnv>>): Promise<Response> => {
|
|
286
322
|
try {
|
|
287
323
|
await parseFn(c as unknown as HandlerContext)
|
|
288
|
-
makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig)(c)
|
|
324
|
+
await makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig, 'read')(c)
|
|
289
325
|
const { before = [], after = [] } = opConfig
|
|
290
326
|
const beforeResp = await runBeforeHooks<TEnv>(before, c)
|
|
291
327
|
if (beforeResp) return beforeResp
|
|
@@ -304,7 +340,7 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
304
340
|
) => async (c: Context<GeneratedHonoEnv<TEnv>>): Promise<Response> => {
|
|
305
341
|
try {
|
|
306
342
|
await parseWriteBodyMiddleware(c as unknown as HandlerContext)
|
|
307
|
-
makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig)(c)
|
|
343
|
+
await makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig, 'write')(c)
|
|
308
344
|
const { before = [], after = [] } = opConfig
|
|
309
345
|
const beforeResp = await runBeforeHooks<TEnv>(before, c)
|
|
310
346
|
if (beforeResp) return beforeResp
|
|
@@ -338,7 +374,7 @@ ${writeOpBlocks}
|
|
|
338
374
|
app.post(path, async (c: Context<GeneratedHonoEnv<TEnv>>): Promise<Response> => {
|
|
339
375
|
try {
|
|
340
376
|
await parseUpdateEachBodyMiddleware(c as unknown as HandlerContext)
|
|
341
|
-
makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig)(c)
|
|
377
|
+
await makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig, 'write')(c)
|
|
342
378
|
const { before = [], after = [] } = opConfig
|
|
343
379
|
const beforeResp = await runBeforeHooks<TEnv>(before, c)
|
|
344
380
|
if (beforeResp) return beforeResp
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouterHono.js","sourceRoot":"","sources":["../../src/generators/generateRouterHono.ts"],"names":[],"mappings":";;AA8CA,
|
|
1
|
+
{"version":3,"file":"generateRouterHono.js","sourceRoot":"","sources":["../../src/generators/generateRouterHono.ts"],"names":[],"mappings":";;AA8CA,gEAmXC;AAhaD,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;;gDAEwC,WAAW;MACrD;YACA,CAAC,CAAC,iEAAiE,WAAW,gCAAgC;QAChH,CAAC,CAAC,EAAE,CAAA;IAEN,OAAO,0BAA0B,IAAI,CAAC,SAAS;8BACnB,IAAI,CAAC,SAAS;mBACzB,SAAS;yCACa,WAAW;EAClD,YAAY;IACV,CAAA;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,IAAyC,EAAE,SAAiB;IAC/E,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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les.js","sourceRoot":"","sources":["../../src/utils/copyFiles.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"copyFiles.js","sourceRoot":"","sources":["../../src/utils/copyFiles.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkHA,8BAmDC;AApKD,uCAAwB;AACxB,2CAA4B;AAG5B,2CAAuC;AAEvC,MAAM,YAAY,GAAG;IACnB,qBAAqB;IACrB,sBAAsB;IACtB,yBAAyB;IACzB,SAAS;IACT,gBAAgB;IAChB,iBAAiB;IACjB,qBAAqB;IACrB,gBAAgB;IAChB,QAAQ;IACR,eAAe;IACf,sBAAsB;IACtB,iBAAiB;IACjB,gBAAgB;IAChB,gBAAgB;IAChB,uBAAuB;CACxB,CAAA;AAED,MAAM,kBAAkB,GAAG;IACzB,uBAAuB;IACvB,8BAA8B;IAC9B,uBAAuB;IACvB,8BAA8B;IAC9B,uBAAuB;CACxB,CAAA;AAQD,SAAS,kBAAkB,CAAC,OAAe;IACzC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;IAChE,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAA;IAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IACpD,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAA;IAC5C,MAAM,IAAI,KAAK,CACb,sBAAsB,GAAG,OAAO,GAAG,iCAAiC;QACpE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,iBAAiB,GAAG,SAAS,CAC9D,CAAA;AACH,CAAC;AAED,SAAS,WAAW,CAAC,GAAW;IAC9B,OAAO,GAAG,CAAC,O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YAAY,EAAE,SAAS,EAAE,sBAAsB,EAAE,WAAW,EAAE;QAC3F,QAAQ,EAAE,IAAI;QACd,cAAc,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC;KAC1D,CAAC,CAAA;IACF,IAAI,SAAS;QAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAErC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,iBAAiB,GAAG,MAAM,CAAC,MAAM,GAAG,sBAAsB;YAC1D,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YACxC,gBAAgB,GAAG,QAAQ,GAAG,iBAAiB,GAAG,SAAS,CAC5D,CAAA;IACH,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAA;AACtD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prisma-generator-express",
|
|
3
3
|
"description": "Prisma generator for Express, Fastify, and Hono CRUD APIs with OpenAPI documentation",
|
|
4
|
-
"version": "1.62.
|
|
4
|
+
"version": "1.62.2",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
@@ -157,7 +157,7 @@ async function runRootQuery(
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
async function runStage(
|
|
160
|
-
|
|
160
|
+
base: unknown,
|
|
161
161
|
models: Record<string, ModelRelationMap>,
|
|
162
162
|
stage: GuardedAutoIncludeStage,
|
|
163
163
|
parentValue: unknown,
|
|
@@ -196,7 +196,7 @@ async function runStage(
|
|
|
196
196
|
[childKey]: { in: [linkVal] },
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
const stageDelegate = getDelegate(
|
|
199
|
+
const stageDelegate = getDelegate(base, targetModel.delegateKey)
|
|
200
200
|
const g = guarded(stageDelegate, stage.stageShape, caller)
|
|
201
201
|
|
|
202
202
|
if (rel.isList) {
|
|
@@ -268,7 +268,7 @@ async function runGuardedAutoIncludeSingle(
|
|
|
268
268
|
if (isAborted()) return
|
|
269
269
|
try {
|
|
270
270
|
const stageResult = await runStage(
|
|
271
|
-
|
|
271
|
+
ctx.prisma,
|
|
272
272
|
models,
|
|
273
273
|
stage,
|
|
274
274
|
internal,
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { isPlainObject } from './misc'
|
|
2
|
+
|
|
3
|
+
const SHAPE_KEYS = new Set([
|
|
4
|
+
'where',
|
|
5
|
+
'select',
|
|
6
|
+
'include',
|
|
7
|
+
'orderBy',
|
|
8
|
+
'cursor',
|
|
9
|
+
'take',
|
|
10
|
+
'skip',
|
|
11
|
+
'distinct',
|
|
12
|
+
'having',
|
|
13
|
+
'_count',
|
|
14
|
+
'_avg',
|
|
15
|
+
'_sum',
|
|
16
|
+
'_min',
|
|
17
|
+
'_max',
|
|
18
|
+
'by',
|
|
19
|
+
'data',
|
|
20
|
+
'create',
|
|
21
|
+
'update',
|
|
22
|
+
])
|
|
23
|
+
|
|
24
|
+
const COMBINATOR_KEYS = new Set(['AND', 'OR', 'NOT'])
|
|
25
|
+
const TO_ONE_RELATION_OPS = new Set(['is', 'isNot'])
|
|
26
|
+
const TO_MANY_RELATION_OPS = new Set(['some', 'every', 'none'])
|
|
27
|
+
const ALL_RELATION_OPS = new Set([
|
|
28
|
+
...TO_ONE_RELATION_OPS,
|
|
29
|
+
...TO_MANY_RELATION_OPS,
|
|
30
|
+
])
|
|
31
|
+
|
|
32
|
+
const FORCED_MARKER = Symbol.for('prisma-guard.forced')
|
|
33
|
+
|
|
34
|
+
function isForcedValue(v: unknown): v is { value: unknown } {
|
|
35
|
+
return (
|
|
36
|
+
v !== null &&
|
|
37
|
+
typeof v === 'object' &&
|
|
38
|
+
(v as Record<PropertyKey, unknown>)[FORCED_MARKER] === true
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type ContextResolver = () => unknown | Promise<unknown>
|
|
43
|
+
|
|
44
|
+
export type OpKind =
|
|
45
|
+
| 'read'
|
|
46
|
+
| 'readUnique'
|
|
47
|
+
| 'create'
|
|
48
|
+
| 'createMany'
|
|
49
|
+
| 'update'
|
|
50
|
+
| 'updateMany'
|
|
51
|
+
| 'upsert'
|
|
52
|
+
| 'delete'
|
|
53
|
+
| 'deleteMany'
|
|
54
|
+
| 'noop'
|
|
55
|
+
|
|
56
|
+
interface WhereForced {
|
|
57
|
+
conditions: Record<string, unknown>
|
|
58
|
+
relations: Record<string, Record<string, WhereForced>>
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function emptyForced(): WhereForced {
|
|
62
|
+
return { conditions: {}, relations: {} }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function hasForced(f: WhereForced): boolean {
|
|
66
|
+
return (
|
|
67
|
+
Object.keys(f.conditions).length > 0 ||
|
|
68
|
+
Object.keys(f.relations).length > 0
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function isDirectGuardShape(input: Record<string, unknown>): boolean {
|
|
73
|
+
const keys = Object.keys(input)
|
|
74
|
+
if (keys.length === 0) return true
|
|
75
|
+
return keys.every((k) => SHAPE_KEYS.has(k))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function callShapeFn(
|
|
79
|
+
fn: (ctx: unknown) => unknown,
|
|
80
|
+
resolveContext: ContextResolver | undefined,
|
|
81
|
+
): Promise<Record<string, unknown> | null> {
|
|
82
|
+
if (!resolveContext) return null
|
|
83
|
+
const ctx = await resolveContext()
|
|
84
|
+
const result = fn(ctx)
|
|
85
|
+
if (!isPlainObject(result)) return null
|
|
86
|
+
return result
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function resolveShape(
|
|
90
|
+
input: unknown,
|
|
91
|
+
caller: string | undefined,
|
|
92
|
+
resolveContext: ContextResolver | undefined,
|
|
93
|
+
): Promise<Record<string, unknown> | null> {
|
|
94
|
+
if (!input) return null
|
|
95
|
+
|
|
96
|
+
if (typeof input === 'function') {
|
|
97
|
+
return callShapeFn(input as (ctx: unknown) => unknown, resolveContext)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!isPlainObject(input)) return null
|
|
101
|
+
if (isDirectGuardShape(input)) return input
|
|
102
|
+
|
|
103
|
+
let entry: unknown = undefined
|
|
104
|
+
if (caller !== undefined && caller in input) entry = input[caller]
|
|
105
|
+
if (entry === undefined && 'default' in input) entry = input['default']
|
|
106
|
+
if (entry === undefined) return null
|
|
107
|
+
|
|
108
|
+
if (typeof entry === 'function') {
|
|
109
|
+
return callShapeFn(entry as (ctx: unknown) => unknown, resolveContext)
|
|
110
|
+
}
|
|
111
|
+
if (!isPlainObject(entry)) return null
|
|
112
|
+
return entry
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function buildDefaultCount(config: unknown): unknown {
|
|
116
|
+
if (config === true) return true
|
|
117
|
+
if (!isPlainObject(config)) return true
|
|
118
|
+
const selectVal = config.select
|
|
119
|
+
if (!isPlainObject(selectVal)) return true
|
|
120
|
+
const result: Record<string, unknown> = {}
|
|
121
|
+
for (const key of Object.keys(selectVal)) result[key] = true
|
|
122
|
+
return { select: result }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function buildRelSkeleton(
|
|
126
|
+
config: Record<string, unknown>,
|
|
127
|
+
): Record<string, unknown> {
|
|
128
|
+
const skel: Record<string, unknown> = {}
|
|
129
|
+
if (isPlainObject(config.select)) {
|
|
130
|
+
skel.select = buildDefaultProjectionInput(config.select)
|
|
131
|
+
}
|
|
132
|
+
if (isPlainObject(config.include)) {
|
|
133
|
+
skel.include = buildDefaultProjectionInput(config.include)
|
|
134
|
+
}
|
|
135
|
+
return skel
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function buildDefaultProjectionInput(
|
|
139
|
+
config: Record<string, unknown>,
|
|
140
|
+
): Record<string, unknown> {
|
|
141
|
+
const result: Record<string, unknown> = {}
|
|
142
|
+
for (const [key, value] of Object.entries(config)) {
|
|
143
|
+
if (key === '_count') {
|
|
144
|
+
result[key] = buildDefaultCount(value)
|
|
145
|
+
continue
|
|
146
|
+
}
|
|
147
|
+
if (value === true) {
|
|
148
|
+
result[key] = true
|
|
149
|
+
continue
|
|
150
|
+
}
|
|
151
|
+
if (isPlainObject(value)) {
|
|
152
|
+
result[key] = buildRelSkeleton(value)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return result
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function buildDefaultProjectionBody(
|
|
159
|
+
shape: Record<string, unknown>,
|
|
160
|
+
): Record<string, unknown> | null {
|
|
161
|
+
if (isPlainObject(shape.select)) {
|
|
162
|
+
return { select: buildDefaultProjectionInput(shape.select) }
|
|
163
|
+
}
|
|
164
|
+
if (isPlainObject(shape.include)) {
|
|
165
|
+
return { include: buildDefaultProjectionInput(shape.include) }
|
|
166
|
+
}
|
|
167
|
+
return null
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function extractForcedFromWhereConfig(
|
|
171
|
+
whereConfig: Record<string, unknown>,
|
|
172
|
+
): WhereForced {
|
|
173
|
+
const forced = emptyForced()
|
|
174
|
+
|
|
175
|
+
for (const [key, value] of Object.entries(whereConfig)) {
|
|
176
|
+
if (COMBINATOR_KEYS.has(key)) continue
|
|
177
|
+
|
|
178
|
+
if (isForcedValue(value)) {
|
|
179
|
+
forced.conditions[key] = value.value
|
|
180
|
+
continue
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (isPlainObject(value)) {
|
|
184
|
+
const relOps: Record<string, WhereForced> = {}
|
|
185
|
+
let hasRelOp = false
|
|
186
|
+
|
|
187
|
+
for (const [op, opValue] of Object.entries(value)) {
|
|
188
|
+
if (!ALL_RELATION_OPS.has(op)) continue
|
|
189
|
+
if (opValue === null) continue
|
|
190
|
+
if (!isPlainObject(opValue)) continue
|
|
191
|
+
const nested = extractForcedFromWhereConfig(opValue)
|
|
192
|
+
if (hasForced(nested)) {
|
|
193
|
+
relOps[op] = nested
|
|
194
|
+
hasRelOp = true
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (hasRelOp) {
|
|
199
|
+
forced.relations[key] = relOps
|
|
200
|
+
continue
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const forcedOps: Record<string, unknown> = {}
|
|
204
|
+
let hasForcedOp = false
|
|
205
|
+
for (const [op, opValue] of Object.entries(value)) {
|
|
206
|
+
if (isForcedValue(opValue)) {
|
|
207
|
+
forcedOps[op] = opValue.value
|
|
208
|
+
hasForcedOp = true
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (hasForcedOp) {
|
|
212
|
+
forced.conditions[key] = forcedOps
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return forced
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function extractForcedFromDataConfig(
|
|
221
|
+
dataConfig: Record<string, unknown>,
|
|
222
|
+
): Record<string, unknown> {
|
|
223
|
+
const forced: Record<string, unknown> = {}
|
|
224
|
+
for (const [key, value] of Object.entries(dataConfig)) {
|
|
225
|
+
if (isForcedValue(value)) {
|
|
226
|
+
forced[key] = value.value
|
|
227
|
+
continue
|
|
228
|
+
}
|
|
229
|
+
if (typeof value === 'function') continue
|
|
230
|
+
if (value === true) continue
|
|
231
|
+
if (isPlainObject(value)) continue
|
|
232
|
+
forced[key] = value
|
|
233
|
+
}
|
|
234
|
+
return forced
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function mergeWhereForced(
|
|
238
|
+
where: Record<string, unknown> | undefined,
|
|
239
|
+
forced: WhereForced,
|
|
240
|
+
): Record<string, unknown> {
|
|
241
|
+
if (!hasForced(forced)) return where ?? {}
|
|
242
|
+
|
|
243
|
+
let result: Record<string, unknown> = where ? { ...where } : {}
|
|
244
|
+
|
|
245
|
+
for (const [relName, opMap] of Object.entries(forced.relations)) {
|
|
246
|
+
if (!isPlainObject(result[relName])) {
|
|
247
|
+
result[relName] = {}
|
|
248
|
+
}
|
|
249
|
+
const relObj = { ...(result[relName] as Record<string, unknown>) }
|
|
250
|
+
for (const [op, nestedForced] of Object.entries(opMap)) {
|
|
251
|
+
relObj[op] = mergeWhereForced(
|
|
252
|
+
isPlainObject(relObj[op])
|
|
253
|
+
? (relObj[op] as Record<string, unknown>)
|
|
254
|
+
: undefined,
|
|
255
|
+
nestedForced,
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
result[relName] = relObj
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (Object.keys(forced.conditions).length > 0) {
|
|
262
|
+
const remaining: Record<string, unknown> = {}
|
|
263
|
+
for (const [field, forcedValue] of Object.entries(forced.conditions)) {
|
|
264
|
+
const existing = result[field]
|
|
265
|
+
|
|
266
|
+
if (existing === undefined) {
|
|
267
|
+
remaining[field] = forcedValue
|
|
268
|
+
continue
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (isPlainObject(existing) && isPlainObject(forcedValue)) {
|
|
272
|
+
result[field] = { ...existing, ...forcedValue }
|
|
273
|
+
continue
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (isPlainObject(existing) && !isPlainObject(forcedValue)) {
|
|
277
|
+
result[field] = { ...existing, equals: forcedValue }
|
|
278
|
+
continue
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (!isPlainObject(existing) && isPlainObject(forcedValue)) {
|
|
282
|
+
result[field] = { equals: existing, ...forcedValue }
|
|
283
|
+
continue
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
remaining[field] = forcedValue
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (Object.keys(remaining).length > 0) {
|
|
290
|
+
if (Object.keys(result).length === 0) {
|
|
291
|
+
result = remaining
|
|
292
|
+
} else {
|
|
293
|
+
result = { AND: [result, remaining] }
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return result
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function mergeUniqueWhereForced(
|
|
302
|
+
where: Record<string, unknown> | undefined,
|
|
303
|
+
forced: WhereForced,
|
|
304
|
+
): Record<string, unknown> {
|
|
305
|
+
if (!hasForced(forced)) return where ?? {}
|
|
306
|
+
|
|
307
|
+
const result: Record<string, unknown> = where ? { ...where } : {}
|
|
308
|
+
|
|
309
|
+
for (const [key, value] of Object.entries(forced.conditions)) {
|
|
310
|
+
if (!(key in result)) {
|
|
311
|
+
result[key] = value
|
|
312
|
+
continue
|
|
313
|
+
}
|
|
314
|
+
if (isPlainObject(result[key]) && isPlainObject(value)) {
|
|
315
|
+
result[key] = {
|
|
316
|
+
...(result[key] as Record<string, unknown>),
|
|
317
|
+
...(value as Record<string, unknown>),
|
|
318
|
+
}
|
|
319
|
+
} else {
|
|
320
|
+
result[key] = value
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return result
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function applyProjectionToTarget(
|
|
328
|
+
target: Record<string, unknown>,
|
|
329
|
+
projection: Record<string, unknown>,
|
|
330
|
+
): void {
|
|
331
|
+
if ('select' in target || 'include' in target) return
|
|
332
|
+
Object.assign(target, projection)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function mergeForcedData(
|
|
336
|
+
targetData: unknown,
|
|
337
|
+
forced: Record<string, unknown>,
|
|
338
|
+
): Record<string, unknown> | unknown[] {
|
|
339
|
+
if (Array.isArray(targetData)) {
|
|
340
|
+
return targetData.map((item) => {
|
|
341
|
+
if (!isPlainObject(item)) return { ...forced }
|
|
342
|
+
return { ...item, ...forced }
|
|
343
|
+
})
|
|
344
|
+
}
|
|
345
|
+
if (isPlainObject(targetData)) {
|
|
346
|
+
return { ...targetData, ...forced }
|
|
347
|
+
}
|
|
348
|
+
return { ...forced }
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
interface WhereMergeOptions {
|
|
352
|
+
targetContainer: Record<string, unknown>
|
|
353
|
+
whereKey: string
|
|
354
|
+
forced: WhereForced
|
|
355
|
+
isUnique: boolean
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function applyForcedWhere(opts: WhereMergeOptions): void {
|
|
359
|
+
if (!hasForced(opts.forced)) return
|
|
360
|
+
const existing = opts.targetContainer[opts.whereKey]
|
|
361
|
+
const merged = opts.isUnique
|
|
362
|
+
? mergeUniqueWhereForced(
|
|
363
|
+
isPlainObject(existing)
|
|
364
|
+
? (existing as Record<string, unknown>)
|
|
365
|
+
: undefined,
|
|
366
|
+
opts.forced,
|
|
367
|
+
)
|
|
368
|
+
: mergeWhereForced(
|
|
369
|
+
isPlainObject(existing)
|
|
370
|
+
? (existing as Record<string, unknown>)
|
|
371
|
+
: undefined,
|
|
372
|
+
opts.forced,
|
|
373
|
+
)
|
|
374
|
+
opts.targetContainer[opts.whereKey] = merged
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export async function applyDroppedGuard(
|
|
378
|
+
shape: unknown,
|
|
379
|
+
caller: string | undefined,
|
|
380
|
+
resolveContext: ContextResolver |
|
|
@@ -5,12 +5,6 @@ import { importExt } from '../utils/importExt'
|
|
|
5
5
|
import { WriteStrategy, FindManyPaginatedMode } from '../constants'
|
|
6
6
|
import { OPERATION_METADATA } from '../copy/operationDefinitions'
|
|
7
7
|
|
|
8
|
-
interface OpEmitContext {
|
|
9
|
-
modelName: string
|
|
10
|
-
basePath: string
|
|
11
|
-
postReadsEnabled: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
8
|
function pathExpr(basePath: string, suffix: string): string {
|
|
15
9
|
if (!suffix) return basePath || '/'
|
|
16
10
|
if (!basePath) return `'${suffix}'`
|
|
@@ -28,7 +22,7 @@ function emitReadOp(
|
|
|
28
22
|
const postReadBlock = meta.supportsPostRead
|
|
29
23
|
? ` if (postReadsEnabled) {
|
|
30
24
|
const postPath = ${meta.name === 'findMany' ? "basePath ? `${basePath}/read` : '/read'" : `path`}
|
|
31
|
-
router.post(postPath, parseBodyAsQuery, setShape(opConfig), ...before, ${handlerName} as RequestHandler, ...after, respond)
|
|
25
|
+
router.post(postPath, parseBodyAsQuery, setShape(opConfig, 'read'), ...before, ${handlerName} as RequestHandler, ...after, respond)
|
|
32
26
|
}`
|
|
33
27
|
: ''
|
|
34
28
|
|
|
@@ -36,7 +30,7 @@ function emitReadOp(
|
|
|
36
30
|
const opConfig: OperationConfigLike = (config.${meta.configKey} as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
37
31
|
const { before = [], after = [] } = opConfig
|
|
38
32
|
const path = ${pathValue}
|
|
39
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.${meta.coreName}, '${meta.name}'), ${handlerName} as RequestHandler, ...after, respond)
|
|
33
|
+
router.get(path, parseQuery, setShape(opConfig, 'read'), ...before, maybeProgressiveSSE(opConfig, core.${meta.coreName}, '${meta.name}'), ${handlerName} as RequestHandler, ...after, respond)
|
|
40
34
|
${postReadBlock}
|
|
41
35
|
}`
|
|
42
36
|
}
|
|
@@ -54,7 +48,7 @@ function emitWriteOp(
|
|
|
54
48
|
const opConfig: OperationConfigLike = (config.${meta.configKey} as OperationConfigLike | undefined) ?? defaultOpConfig
|
|
55
49
|
const { before = [], after = [] } = opConfig
|
|
56
50
|
const path = ${pathValue}
|
|
57
|
-
router.${meta.method}(path, setShape(opConfig), ...before, ${handlerName} as RequestHandler, ...after, ${respondFn})
|
|
51
|
+
router.${meta.method}(path, setShape(opConfig, 'write'), ...before, ${handlerName} as RequestHandler, ...after, ${respondFn})
|
|
58
52
|
}`
|
|
59
53
|
}
|
|
60
54
|
|
|
@@ -114,7 +108,7 @@ import type {
|
|
|
114
108
|
PaginationConfig,
|
|
115
109
|
} from '../routeConfig.target${ext}'
|
|
116
110
|
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
117
|
-
import { sanitizeKeys, normalizePrefix, getEnv } from '../misc${ext}'
|
|
111
|
+
import { sanitizeKeys, normalizePrefix, getEnv, isPlainObject } from '../misc${ext}'
|
|
118
112
|
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
119
113
|
import { validateCountSourceWhere } from '../routeConfig${ext}'
|
|
120
114
|
import type { OperationContext } from '../operationRuntime${ext}'
|
|
@@ -130,6 +124,10 @@ import {
|
|
|
130
124
|
} from '../sse${ext}'
|
|
131
125
|
import { relationModels } from '../relationModels${ext}'
|
|
132
126
|
import { runAutoIncludeProgressive } from '../autoIncludeRuntime${ext}'
|
|
127
|
+
import {
|
|
128
|
+
resolveDroppedGuardProjection,
|
|
129
|
+
applyProjectionToTarget,
|
|
130
|
+
} from '../projectionDefaults${ext}'
|
|
133
131
|
import { MODEL_FIELDS, MODEL_ENUMS } from './${modelName}Metadata${ext}'
|
|
134
132
|
|
|
135
133
|
${generateRouteConfigType(modelName, 'RequestHandler', guardShapesImport, importStyle, 'express')}
|
|
@@ -258,6 +256,11 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(config: ${m
|
|
|
258
256
|
}
|
|
259
257
|
}
|
|
260
258
|
|
|
259
|
+
const buildResolveContext = (req: Request): (() => unknown | Promise<unknown>) | undefined => {
|
|
260
|
+
if (typeof config.resolveContext !== 'function') return undefined
|
|
261
|
+
return () => (config.resolveContext as (r: Request) => unknown | Promise<unknown>)(req)
|
|
262
|
+
}
|
|
263
|
+
|
|
261
264
|
const parseQuery: RequestHandler = (req, res, next) => {
|
|
262
265
|
const rawQuery = req.query
|
|
263
266
|
if (rawQuery && Object.keys(rawQuery).length > 0) {
|
|
@@ -275,19 +278,47 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(config: ${m
|
|
|
275
278
|
next()
|
|
276
279
|
}
|
|
277
280
|
|
|
278
|
-
const setShape = (opConfig: OperationConfigLike): RequestHandler => {
|
|
279
|
-
return (req, res, next) => {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
281
|
+
const setShape = (opConfig: OperationConfigLike, kind: 'read' | 'write'): RequestHandler => {
|
|
282
|
+
return async (req, res, next) => {
|
|
283
|
+
try {
|
|
284
|
+
const locals = readLocals(res)
|
|
285
|
+
const merged = mergePaginationConfig(config.pagination, opConfig.pagination)
|
|
286
|
+
if (merged) {
|
|
287
|
+
locals.routeConfig = { pagination: merged }
|
|
288
|
+
}
|
|
289
|
+
const headerName = config.guard?.variantHeader || 'x-api-variant'
|
|
290
|
+
const headerValue = req.get(headerName)
|
|
291
|
+
const caller = config.guard?.resolveVariant?.(req) ?? headerValue ?? undefined
|
|
292
|
+
if (caller) locals.guardCaller = caller
|
|
293
|
+
if (opConfig.shape) {
|
|
294
|
+
if (!DROP_GUARD) {
|
|
295
|
+
locals.guardShape = opConfig.shape
|
|
296
|
+
} else {
|
|
297
|
+
const projection = await resolveDroppedGuardProjection(
|
|
298
|
+
opConfig.shape,
|
|
299
|
+
caller,
|
|
300
|
+
buildResolveContext(req),
|
|
301
|
+
)
|
|
302
|
+
if (projection) {
|
|
303
|
+
if (kind === 'read') {
|
|
304
|
+
if (!locals.parsedQuery) locals.parsedQuery = {}
|
|
305
|
+
applyProjectionToTarget(locals.parsedQuery, projection)
|
|
306
|
+
} else {
|
|
307
|
+
if (!isPlainObject(req.body)) {
|
|
308
|
+
req.body = {}
|
|
309
|
+
}
|
|
310
|
+
applyProjectionToTarget(
|
|
311
|
+
req.body as Record<string, unknown>,
|
|
312
|
+
projection,
|
|
313
|
+
)
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
next()
|
|
319
|
+
} catch (err) {
|
|
320
|
+
next(mapError(err))
|
|
284
321
|
}
|
|
285
|
-
const headerName = config.guard?.variantHeader || 'x-api-variant'
|
|
286
|
-
const headerValue = req.get(headerName)
|
|
287
|
-
const caller = config.guard?.resolveVariant?.(req) ?? headerValue ?? undefined
|
|
288
|
-
if (caller) locals.guardCaller = caller
|
|
289
|
-
if (opConfig.shape && !DROP_GUARD) locals.guardShape = opConfig.shape
|
|
290
|
-
next()
|
|
291
322
|
}
|
|
292
323
|
}
|
|
293
324
|
|
|
@@ -442,7 +473,7 @@ ${writeOpBlocks}
|
|
|
442
473
|
const path = basePath ? \`\${basePath}/each\` : '/each'
|
|
443
474
|
router.post(
|
|
444
475
|
path,
|
|
445
|
-
setShape(opConfig),
|
|
476
|
+
setShape(opConfig, 'write'),
|
|
446
477
|
...before,
|
|
447
478
|
async (req: Request, res: Response, next: NextFunction) => {
|
|
448
479
|
try {
|
|
@@ -470,4 +501,4 @@ ${writeOpBlocks}
|
|
|
470
501
|
return router
|
|
471
502
|
}
|
|
472
503
|
`
|
|
473
|
-
}
|
|
504
|
+
}
|
|
@@ -89,13 +89,17 @@ import type {
|
|
|
89
89
|
PaginationConfig,
|
|
90
90
|
} from '../routeConfig.target${ext}'
|
|
91
91
|
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
92
|
-
import { sanitizeKeys, normalizePrefix, getEnv } from '../misc${ext}'
|
|
92
|
+
import { sanitizeKeys, normalizePrefix, getEnv, isPlainObject } from '../misc${ext}'
|
|
93
93
|
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
94
94
|
import { validateCountSourceWhere } from '../routeConfig${ext}'
|
|
95
95
|
import type { OperationContext } from '../operationRuntime${ext}'
|
|
96
96
|
import { transformResult } from '../operationRuntime${ext}'
|
|
97
97
|
import { HttpError, mapError } from '../errorMapper${ext}'
|
|
98
98
|
import { mergePaginationConfig } from '../pagination${ext}'
|
|
99
|
+
import {
|
|
100
|
+
resolveDroppedGuardProjection,
|
|
101
|
+
applyProjectionToTarget,
|
|
102
|
+
} from '../projectionDefaults${ext}'
|
|
99
103
|
import { MODEL_FIELDS, MODEL_ENUMS } from './${modelName}Metadata${ext}'
|
|
100
104
|
|
|
101
105
|
${generateRouteConfigType(modelName, 'FastifyHookHandler', guardShapesImport, importStyle, 'fastify')}
|
|
@@ -156,11 +160,20 @@ function parseBodyAsQueryHook(request: FastifyRequest): void {
|
|
|
156
160
|
(request as FastifyExtended).parsedQuery = sanitizeKeys(body as Record<string, unknown>)
|
|
157
161
|
}
|
|
158
162
|
|
|
163
|
+
function buildResolveContext(
|
|
164
|
+
config: ${modelName}RouteConfig,
|
|
165
|
+
request: FastifyRequest,
|
|
166
|
+
): (() => unknown | Promise<unknown>) | undefined {
|
|
167
|
+
if (typeof config.resolveContext !== 'function') return undefined
|
|
168
|
+
return () => (config.resolveContext as (r: FastifyRequest) => unknown | Promise<unknown>)(request)
|
|
169
|
+
}
|
|
170
|
+
|
|
159
171
|
function makeShapeHook(
|
|
160
172
|
config: ${modelName}RouteConfig,
|
|
161
173
|
opConfig: OperationConfigLike,
|
|
162
|
-
|
|
163
|
-
|
|
174
|
+
kind: 'read' | 'write',
|
|
175
|
+
): (request: FastifyRequest) => Promise<void> {
|
|
176
|
+
return async (request: FastifyRequest) => {
|
|
164
177
|
const fx = request as FastifyExtended
|
|
165
178
|
const merged = mergePaginationConfig(config.pagination, opConfig.pagination)
|
|
166
179
|
if (merged) {
|
|
@@ -174,8 +187,30 @@ function makeShapeHook(
|
|
|
174
187
|
if (caller) {
|
|
175
188
|
fx.guardCaller = caller
|
|
176
189
|
}
|
|
177
|
-
if (opConfig.shape
|
|
178
|
-
|
|
190
|
+
if (opConfig.shape) {
|
|
191
|
+
if (!DROP_GUARD) {
|
|
192
|
+
fx.guardShape = opConfig.shape
|
|
193
|
+
} else {
|
|
194
|
+
const projection = await resolveDroppedGuardProjection(
|
|
195
|
+
opConfig.shape,
|
|
196
|
+
caller,
|
|
197
|
+
buildResolveContext(config, request),
|
|
198
|
+
)
|
|
199
|
+
if (projection) {
|
|
200
|
+
if (kind === 'read') {
|
|
201
|
+
if (!fx.parsedQuery) fx.parsedQuery = {}
|
|
202
|
+
applyProjectionToTarget(fx.parsedQuery, projection)
|
|
203
|
+
} else {
|
|
204
|
+
if (!isPlainObject(request.body)) {
|
|
205
|
+
;(request as unknown as { body: unknown }).body = {}
|
|
206
|
+
}
|
|
207
|
+
applyProjectionToTarget(
|
|
208
|
+
request.body as Record<string, unknown>,
|
|
209
|
+
projection,
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
179
214
|
}
|
|
180
215
|
}
|
|
181
216
|
}
|
|
@@ -305,7 +340,7 @@ export async function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(
|
|
|
305
340
|
) => async (request: FastifyRequest, reply: FastifyReply) => {
|
|
306
341
|
try {
|
|
307
342
|
parseFn(request)
|
|
308
|
-
makeShapeHook(config, opConfig)(request)
|
|
343
|
+
await makeShapeHook(config, opConfig, 'read')(request)
|
|
309
344
|
const { before = [], after = [] } = opConfig
|
|
310
345
|
if (await runHooks(before, request, reply)) return
|
|
311
346
|
await handlerFn(request, reply)
|
|
@@ -321,7 +356,7 @@ export async function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(
|
|
|
321
356
|
handlerFn: (req: FastifyRequest, reply: FastifyReply) => Promise<void>,
|
|
322
357
|
) => async (request: FastifyRequest, reply: FastifyReply) => {
|
|
323
358
|
try {
|
|
324
|
-
makeShapeHook(config, opConfig)(request)
|
|
359
|
+
await makeShapeHook(config, opConfig, 'write')(request)
|
|
325
360
|
const { before = [], after = [] } = opConfig
|
|
326
361
|
if (await runHooks(before, request, reply)) return
|
|
327
362
|
await handlerFn(request, reply)
|
|
@@ -350,7 +385,7 @@ ${writeOpBlocks}
|
|
|
350
385
|
if (!Array.isArray(request.body)) {
|
|
351
386
|
throw new HttpError(400, 'updateEach body must be an array of { where, data } items')
|
|
352
387
|
}
|
|
353
|
-
makeShapeHook(config, opConfig)(request)
|
|
388
|
+
await makeShapeHook(config, opConfig, 'write')(request)
|
|
354
389
|
const { before = [], after = [] } = opConfig
|
|
355
390
|
if (await runHooks(before, request, reply)) return
|
|
356
391
|
await ${modelName}UpdateEach(request, reply)
|
|
@@ -92,12 +92,16 @@ import type {
|
|
|
92
92
|
PaginationConfig,
|
|
93
93
|
} from '../routeConfig.target${ext}'
|
|
94
94
|
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
95
|
-
import { normalizePrefix, getEnv, sanitizeKeys } from '../misc${ext}'
|
|
95
|
+
import { normalizePrefix, getEnv, sanitizeKeys, isPlainObject } from '../misc${ext}'
|
|
96
96
|
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
97
97
|
import { validateCountSourceWhere } from '../routeConfig${ext}'
|
|
98
98
|
import { transformResult } from '../operationRuntime${ext}'
|
|
99
99
|
import { mapError } from '../errorMapper${ext}'
|
|
100
100
|
import { mergePaginationConfig } from '../pagination${ext}'
|
|
101
|
+
import {
|
|
102
|
+
resolveDroppedGuardProjection,
|
|
103
|
+
applyProjectionToTarget,
|
|
104
|
+
} from '../projectionDefaults${ext}'
|
|
101
105
|
import { MODEL_FIELDS, MODEL_ENUMS } from './${modelName}Metadata${ext}'
|
|
102
106
|
|
|
103
107
|
${generateRouteConfigType(modelName, 'HonoBeforeHook', guardShapesImport, importStyle, 'hono')}
|
|
@@ -176,8 +180,9 @@ async function parseUpdateEachBodyMiddleware(c: HandlerContext): Promise<void> {
|
|
|
176
180
|
function makeShapeMiddleware<TCtx, TPrisma, TEnv extends HonoEnvBase>(
|
|
177
181
|
config: ${modelName}RouteConfig<TCtx, TPrisma, TEnv>,
|
|
178
182
|
opConfig: OperationConfigLike<TEnv>,
|
|
183
|
+
kind: 'read' | 'write',
|
|
179
184
|
) {
|
|
180
|
-
return (c: Context<GeneratedHonoEnv<TEnv>>): void => {
|
|
185
|
+
return async (c: Context<GeneratedHonoEnv<TEnv>>): Promise<void> => {
|
|
181
186
|
const merged = mergePaginationConfig(config.pagination, opConfig.pagination)
|
|
182
187
|
if (merged) {
|
|
183
188
|
c.set('routeConfig', { pagination: merged })
|
|
@@ -186,8 +191,39 @@ function makeShapeMiddleware<TCtx, TPrisma, TEnv extends HonoEnvBase>(
|
|
|
186
191
|
const headerValue = c.req.header(headerName)
|
|
187
192
|
const caller = config.guard?.resolveVariant?.(c) ?? headerValue ?? undefined
|
|
188
193
|
if (caller) c.set('guardCaller', caller)
|
|
189
|
-
if (opConfig.shape
|
|
190
|
-
|
|
194
|
+
if (opConfig.shape) {
|
|
195
|
+
if (!DROP_GUARD) {
|
|
196
|
+
c.set('guardShape', opConfig.shape)
|
|
197
|
+
} else {
|
|
198
|
+
const resolveCtx = typeof config.resolveContext === 'function'
|
|
199
|
+
? () => (config.resolveContext as (ctx: Context<GeneratedHonoEnv<TEnv>>) => unknown | Promise<unknown>)(c)
|
|
200
|
+
: undefined
|
|
201
|
+
const projection = await resolveDroppedGuardProjection(
|
|
202
|
+
opConfig.shape,
|
|
203
|
+
caller,
|
|
204
|
+
resolveCtx,
|
|
205
|
+
)
|
|
206
|
+
if (projection) {
|
|
207
|
+
if (kind === 'read') {
|
|
208
|
+
let target = c.get('parsedQuery')
|
|
209
|
+
if (!target) {
|
|
210
|
+
target = {}
|
|
211
|
+
c.set('parsedQuery', target)
|
|
212
|
+
}
|
|
213
|
+
applyProjectionToTarget(target, projection)
|
|
214
|
+
} else {
|
|
215
|
+
let target = c.get('body')
|
|
216
|
+
if (!isPlainObject(target)) {
|
|
217
|
+
target = {}
|
|
218
|
+
c.set('body', target)
|
|
219
|
+
}
|
|
220
|
+
applyProjectionToTarget(
|
|
221
|
+
target as Record<string, unknown>,
|
|
222
|
+
projection,
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
191
227
|
}
|
|
192
228
|
}
|
|
193
229
|
}
|
|
@@ -309,7 +345,7 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
309
345
|
) => async (c: Context<GeneratedHonoEnv<TEnv>>): Promise<Response> => {
|
|
310
346
|
try {
|
|
311
347
|
await parseFn(c as unknown as HandlerContext)
|
|
312
|
-
makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig)(c)
|
|
348
|
+
await makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig, 'read')(c)
|
|
313
349
|
const { before = [], after = [] } = opConfig
|
|
314
350
|
const beforeResp = await runBeforeHooks<TEnv>(before, c)
|
|
315
351
|
if (beforeResp) return beforeResp
|
|
@@ -328,7 +364,7 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
328
364
|
) => async (c: Context<GeneratedHonoEnv<TEnv>>): Promise<Response> => {
|
|
329
365
|
try {
|
|
330
366
|
await parseWriteBodyMiddleware(c as unknown as HandlerContext)
|
|
331
|
-
makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig)(c)
|
|
367
|
+
await makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig, 'write')(c)
|
|
332
368
|
const { before = [], after = [] } = opConfig
|
|
333
369
|
const beforeResp = await runBeforeHooks<TEnv>(before, c)
|
|
334
370
|
if (beforeResp) return beforeResp
|
|
@@ -362,7 +398,7 @@ ${writeOpBlocks}
|
|
|
362
398
|
app.post(path, async (c: Context<GeneratedHonoEnv<TEnv>>): Promise<Response> => {
|
|
363
399
|
try {
|
|
364
400
|
await parseUpdateEachBodyMiddleware(c as unknown as HandlerContext)
|
|
365
|
-
makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig)(c)
|
|
401
|
+
await makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig, 'write')(c)
|
|
366
402
|
const { before = [], after = [] } = opConfig
|
|
367
403
|
const beforeResp = await runBeforeHooks<TEnv>(before, c)
|
|
368
404
|
if (beforeResp) return beforeResp
|