prisma-generator-express 1.65.2 → 1.67.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 +51 -3480
- package/dist/client/encodeQueryParams.js +3 -1
- package/dist/client/encodeQueryParams.js.map +1 -1
- package/dist/copy/misc.d.ts +1 -0
- package/dist/copy/misc.js +14 -0
- package/dist/copy/misc.js.map +1 -1
- package/dist/copy/operationDefinitions.js +69 -6
- package/dist/copy/operationDefinitions.js.map +1 -1
- package/dist/generators/generateFastifyHandler.d.ts +2 -2
- package/dist/generators/generateFastifyHandler.js +15 -5
- package/dist/generators/generateFastifyHandler.js.map +1 -1
- package/dist/generators/generateHonoHandler.d.ts +2 -2
- package/dist/generators/generateHonoHandler.js +12 -5
- package/dist/generators/generateHonoHandler.js.map +1 -1
- package/dist/generators/generateImportPrismaStatement.d.ts +1 -0
- package/dist/generators/generateImportPrismaStatement.js +6 -0
- package/dist/generators/generateImportPrismaStatement.js.map +1 -1
- package/dist/generators/generateModelMetadata.js +20 -10
- package/dist/generators/generateModelMetadata.js.map +1 -1
- package/dist/generators/generateOperationCore.d.ts +3 -3
- package/dist/generators/generateOperationCore.js +51 -16
- package/dist/generators/generateOperationCore.js.map +1 -1
- package/dist/generators/generateQueryBuilderHelper.d.ts +1 -1
- package/dist/generators/generateQueryBuilderHelper.js +2 -4
- package/dist/generators/generateQueryBuilderHelper.js.map +1 -1
- package/dist/generators/generateRelationMeta.js +2 -2
- package/dist/generators/generateRelationMeta.js.map +1 -1
- package/dist/generators/generateRouteConfigType.d.ts +2 -2
- package/dist/generators/generateRouteConfigType.js +29 -11
- package/dist/generators/generateRouteConfigType.js.map +1 -1
- package/dist/generators/generateRouter.d.ts +7 -4
- package/dist/generators/generateRouter.js +107 -14
- package/dist/generators/generateRouter.js.map +1 -1
- package/dist/generators/generateRouterFastify.d.ts +7 -4
- package/dist/generators/generateRouterFastify.js +56 -28
- package/dist/generators/generateRouterFastify.js.map +1 -1
- package/dist/generators/generateRouterHono.d.ts +7 -4
- package/dist/generators/generateRouterHono.js +84 -53
- package/dist/generators/generateRouterHono.js.map +1 -1
- package/dist/generators/generateUnifiedDocs.d.ts +1 -1
- package/dist/generators/generateUnifiedDocs.js +15 -8
- package/dist/generators/generateUnifiedDocs.js.map +1 -1
- package/dist/generators/generateUnifiedHandler.d.ts +2 -2
- package/dist/generators/generateUnifiedHandler.js +11 -3
- package/dist/generators/generateUnifiedHandler.js.map +1 -1
- package/dist/guardOptions.js +12 -7
- package/dist/guardOptions.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/copyFiles.js +22 -6
- package/dist/utils/copyFiles.js.map +1 -1
- package/dist/utils/importExt.d.ts +1 -1
- package/dist/utils/pathCasing.d.ts +4 -0
- package/dist/utils/pathCasing.js +40 -0
- package/dist/utils/pathCasing.js.map +1 -0
- package/dist/utils/resolveImportStyle.js +13 -5
- package/dist/utils/resolveImportStyle.js.map +1 -1
- package/dist/utils/writeFileSafely.js.map +1 -1
- package/package.json +16 -3
- package/src/bin.ts +1 -1
- package/src/client/encodeQueryParams.ts +39 -35
- package/src/constants.ts +1 -1
- package/src/copy/autoIncludePlanner.ts +93 -27
- package/src/copy/autoIncludePlannerGuarded.ts +171 -48
- package/src/copy/autoIncludeRuntimeGuarded.ts +25 -7
- package/src/copy/buildModelOpenApi.ts +153 -50
- package/src/copy/concurrency.ts +10 -8
- package/src/copy/errorMapper.ts +68 -19
- package/src/copy/guardHelpers.ts +30 -9
- package/src/copy/materializedCount.ts +17 -5
- package/src/copy/misc.ts +88 -68
- package/src/copy/ndjson.ts +72 -0
- package/src/copy/operationDefinitions.ts +99 -21
- package/src/copy/operationRuntime.ts +100 -12
- package/src/copy/pagination.ts +25 -11
- package/src/copy/parseQueryParams.ts +47 -48
- package/src/copy/projectionDefaults.ts +6 -4
- package/src/copy/routeConfig.express.ts +16 -4
- package/src/copy/routeConfig.fastify.ts +16 -2
- package/src/copy/routeConfig.hono.ts +19 -9
- package/src/copy/routeConfig.ts +174 -39
- package/src/copy/scalarTypes.ts +7 -2
- package/src/copy/sse.ts +72 -19
- package/src/generators/generateFastifyHandler.ts +24 -13
- package/src/generators/generateHonoHandler.ts +21 -13
- package/src/generators/generateImportPrismaStatement.ts +93 -81
- package/src/generators/generateModelMetadata.ts +24 -12
- package/src/generators/generateOperationCore.ts +81 -33
- package/src/generators/generateQueryBuilderHelper.ts +20 -4
- package/src/generators/generateRelationMeta.ts +23 -11
- package/src/generators/generateRouteConfigType.ts +39 -13
- package/src/generators/generateRouter.ts +114 -17
- package/src/generators/generateRouterFastify.ts +67 -31
- package/src/generators/generateRouterHono.ts +108 -60
- package/src/generators/generateUnifiedDocs.ts +29 -8
- package/src/generators/generateUnifiedHandler.ts +16 -8
- package/src/generators/generateUnifiedScalarUI.ts +1 -1
- package/src/guardOptions.ts +105 -92
- package/src/index.ts +46 -4
- package/src/utils/copyFiles.ts +199 -168
- package/src/utils/importExt.ts +2 -2
- package/src/utils/pathCasing.ts +42 -0
- package/src/utils/resolveImportStyle.ts +37 -15
- package/src/utils/strings.ts +2 -2
- package/src/utils/writeFileSafely.ts +6 -2
|
@@ -3,6 +3,7 @@ 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 pathCasing_1 = require("../utils/pathCasing");
|
|
6
7
|
const operationDefinitions_1 = require("../copy/operationDefinitions");
|
|
7
8
|
function pathExpr(suffix) {
|
|
8
9
|
if (!suffix)
|
|
@@ -49,11 +50,11 @@ function emitReadOp(meta, modelName) {
|
|
|
49
50
|
const opKind = opKindFor(meta.name);
|
|
50
51
|
const postReadLine = meta.supportsPostRead
|
|
51
52
|
? meta.name === 'findMany'
|
|
52
|
-
? ` if (
|
|
53
|
+
? ` if (resolvePostReadsEnabled(config.disablePostReads, opConfig.disablePostReads)) {
|
|
53
54
|
const postPath = basePath ? \`\${basePath}/read\` : '/read'
|
|
54
55
|
app.post(postPath, handleRead(opConfig, ${handlerName}, parseBodyAsQueryMiddleware, '${opKind}'))
|
|
55
56
|
}`
|
|
56
|
-
: ` if (
|
|
57
|
+
: ` if (resolvePostReadsEnabled(config.disablePostReads, opConfig.disablePostReads)) app.post(path, handleRead(opConfig, ${handlerName}, parseBodyAsQueryMiddleware, '${opKind}'))`
|
|
57
58
|
: '';
|
|
58
59
|
return ` if (isEnabled(config.${meta.configKey})) {
|
|
59
60
|
const opConfig = opFor('${meta.configKey}')
|
|
@@ -73,19 +74,18 @@ function emitWriteOp(meta, modelName) {
|
|
|
73
74
|
app.${meta.method}(path, handleWrite(opConfig, ${handlerName}, '${opKind}'))
|
|
74
75
|
}`;
|
|
75
76
|
}
|
|
76
|
-
function generateHonoRouterFunction({ model, enums, guardShapesImport, importStyle, writeStrategy, dropGuard, }) {
|
|
77
|
+
function generateHonoRouterFunction({ model, enums, guardShapesImport, clientImport, importStyle, writeStrategy, dropGuard, pathCase, }) {
|
|
77
78
|
const ext = (0, importExt_1.importExt)(importStyle);
|
|
78
79
|
const modelName = model.name;
|
|
79
|
-
const
|
|
80
|
+
const modelSegment = (0, pathCasing_1.modelPathSegment)(modelName, pathCase);
|
|
80
81
|
const routerFunctionName = `${modelName}Router`;
|
|
81
|
-
const handlerImports = operationDefinitions_1.OPERATION_METADATA
|
|
82
|
-
.map((m) => ` ${modelName}${m.name.charAt(0).toUpperCase() + m.name.slice(1)},`)
|
|
83
|
-
.join('\n');
|
|
82
|
+
const handlerImports = operationDefinitions_1.OPERATION_METADATA.map((m) => ` ${modelName}${m.name.charAt(0).toUpperCase() + m.name.slice(1)},`).join('\n');
|
|
84
83
|
const readOps = operationDefinitions_1.OPERATION_METADATA.filter((m) => m.kind === 'read');
|
|
85
|
-
const writeOps = operationDefinitions_1.OPERATION_METADATA.filter((m) => m.kind === 'write' || m.kind === 'batch')
|
|
86
|
-
.filter((m) => m.name !== 'updateEach');
|
|
84
|
+
const writeOps = operationDefinitions_1.OPERATION_METADATA.filter((m) => m.kind === 'write' || m.kind === 'batch').filter((m) => m.name !== 'updateEach');
|
|
87
85
|
const readOpBlocks = readOps.map((m) => emitReadOp(m, modelName)).join('\n\n');
|
|
88
|
-
const writeOpBlocks = writeOps
|
|
86
|
+
const writeOpBlocks = writeOps
|
|
87
|
+
.map((m) => emitWriteOp(m, modelName))
|
|
88
|
+
.join('\n\n');
|
|
89
89
|
return `import { Hono } from 'hono'
|
|
90
90
|
import type { Context } from 'hono'
|
|
91
91
|
import type { ContentfulStatusCode } from 'hono/utils/http-status'
|
|
@@ -101,9 +101,10 @@ import type {
|
|
|
101
101
|
HonoInternalVariables,
|
|
102
102
|
GeneratedHonoEnv,
|
|
103
103
|
PaginationConfig,
|
|
104
|
+
PrismaClientLike,
|
|
104
105
|
} from '../routeConfig.target${ext}'
|
|
105
106
|
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
106
|
-
import { normalizePrefix, getEnv, sanitizeKeys, isPlainObject } from '../misc${ext}'
|
|
107
|
+
import { normalizePrefix, getEnv, sanitizeKeys, isPlainObject, resolveDropGuardEnv } from '../misc${ext}'
|
|
107
108
|
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
108
109
|
import {
|
|
109
110
|
normalizeOperation,
|
|
@@ -113,7 +114,10 @@ import {
|
|
|
113
114
|
validateCountSourceWhere,
|
|
114
115
|
validateOperationConfig,
|
|
115
116
|
validateUpdateEachConfig,
|
|
117
|
+
resolvePostReadsEnabled,
|
|
118
|
+
warnIfUnguardedRoutes,
|
|
116
119
|
} from '../routeConfig${ext}'
|
|
120
|
+
import type { RuntimeOperationOverride } from '../operationRuntime${ext}'
|
|
117
121
|
import type { NormalizedOperationConfig } from '../routeConfig${ext}'
|
|
118
122
|
import { transformResult } from '../operationRuntime${ext}'
|
|
119
123
|
import { mapError } from '../errorMapper${ext}'
|
|
@@ -123,7 +127,7 @@ import { applyDroppedGuard } from '../projectionDefaults${ext}'
|
|
|
123
127
|
import type { OpKind } from '../projectionDefaults${ext}'
|
|
124
128
|
import { MODEL_FIELDS, MODEL_ENUMS } from './${modelName}Metadata${ext}'
|
|
125
129
|
|
|
126
|
-
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'HonoBeforeHook', guardShapesImport, importStyle, 'hono')}
|
|
130
|
+
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'HonoBeforeHook', guardShapesImport, importStyle, 'hono', clientImport)}
|
|
127
131
|
const _env = getEnv()
|
|
128
132
|
|
|
129
133
|
// Fixed at generation time. The \`allowE2EGuardBypass\` control decides whether the
|
|
@@ -131,15 +135,19 @@ const _env = getEnv()
|
|
|
131
135
|
// which is upstream behaviour. See generateRouterHono.ts.
|
|
132
136
|
const DROP_GUARD = ${dropGuard}
|
|
133
137
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
/**
|
|
139
|
+
* DELIBERATELY NOT RECURSIVE.
|
|
140
|
+
*
|
|
141
|
+
* A self-referential JSON type sent through \`c.json()\` makes Hono's response
|
|
142
|
+
* inference instantiate without a fixed point, and TypeScript answers
|
|
143
|
+
* "type instantiation is excessively deep" — in the emitted file, for every
|
|
144
|
+
* consumer. One level is all this needs: the value is serialised, not walked.
|
|
145
|
+
*/
|
|
146
|
+
type JsonLike = string | number | boolean | null | unknown[] | Record<string, unknown>
|
|
141
147
|
|
|
142
148
|
type OperationConfigLike<TEnv extends HonoEnvBase> = {
|
|
149
|
+
authorize?: HonoBeforeHook<TEnv>
|
|
150
|
+
override?: RuntimeOperationOverride
|
|
143
151
|
before?: HonoBeforeHook<TEnv>[]
|
|
144
152
|
after?: HonoAfterHook<TEnv>[]
|
|
145
153
|
shape?: unknown
|
|
@@ -213,7 +221,7 @@ async function parseWriteBodyMiddleware(c: HandlerContext): Promise<void> {
|
|
|
213
221
|
c.set('body', body)
|
|
214
222
|
}
|
|
215
223
|
|
|
216
|
-
function makeShapeMiddleware<TCtx, TPrisma, TEnv extends HonoEnvBase>(
|
|
224
|
+
function makeShapeMiddleware<TCtx, TPrisma extends PrismaClientLike, TEnv extends HonoEnvBase>(
|
|
217
225
|
config: ${modelName}RouteConfig<TCtx, TPrisma, TEnv>,
|
|
218
226
|
opConfig: NormalizedOp<TEnv>,
|
|
219
227
|
opKind: OpKind,
|
|
@@ -223,24 +231,40 @@ function makeShapeMiddleware<TCtx, TPrisma, TEnv extends HonoEnvBase>(
|
|
|
223
231
|
/**
|
|
224
232
|
* The environment bypass, honoured unless the consumer turned it off.
|
|
225
233
|
*
|
|
226
|
-
* \`
|
|
227
|
-
* hazard, and it is also upstream behaviour
|
|
228
|
-
* decision made here.
|
|
234
|
+
* \`PGE_DROP_GUARD=true\` downgrading enforcement in a deployed environment is
|
|
235
|
+
* a real hazard, and it is also upstream behaviour (under its deprecated
|
|
236
|
+
* \`E2E=true\` spelling) — so it is a control, not a decision made here.
|
|
229
237
|
*/
|
|
230
|
-
const dropGuard = DROP_GUARD || (policy.allowE2EGuardBypass && _env
|
|
238
|
+
const dropGuard = DROP_GUARD || (policy.allowE2EGuardBypass && resolveDropGuardEnv(_env))
|
|
231
239
|
|
|
232
240
|
return async (c: Context<GeneratedHonoEnv<TEnv>>): Promise<void> => {
|
|
241
|
+
/**
|
|
242
|
+
* INTERNAL REQUEST STATE IS SET THROUGH A CONCRETE CONTEXT.
|
|
243
|
+
*
|
|
244
|
+
* \`GeneratedHonoEnv<TEnv>['Variables']\` is \`HonoInternalVariables & TEnv['Variables']\`,
|
|
245
|
+
* and inside this generic function TypeScript cannot know that the consumer's
|
|
246
|
+
* half does not also declare \`routeConfig\` — so setting that key straight
|
|
247
|
+
* onto \`c\` is unassignable to the intersection and the emitted router does not
|
|
248
|
+
* typecheck under \`strict\` for ANY consumer. These keys belong to this
|
|
249
|
+
* router, so they are written through the internal shape they were declared
|
|
250
|
+
* in.
|
|
251
|
+
*/
|
|
252
|
+
const vars = c as unknown as HandlerContext
|
|
253
|
+
vars.set('operationOverride', opConfig.override)
|
|
254
|
+
let context: Promise<unknown> | undefined
|
|
255
|
+
vars.set('resolveOperationContext', () => context ??= Promise.resolve(config.resolveContext?.(c)))
|
|
256
|
+
|
|
233
257
|
const merged = mergePaginationConfig(config.pagination, opConfig.pagination)
|
|
234
|
-
if (merged)
|
|
258
|
+
if (merged) vars.set('routeConfig', { pagination: merged })
|
|
235
259
|
|
|
236
260
|
const headerName = config.guard?.variantHeader || 'x-api-variant'
|
|
237
261
|
const headerValue = c.req.header(headerName)
|
|
238
262
|
const caller = config.guard?.resolveVariant?.(c) ?? headerValue ?? undefined
|
|
239
|
-
if (typeof caller === 'string')
|
|
263
|
+
if (typeof caller === 'string') vars.set('guardCaller', caller)
|
|
240
264
|
|
|
241
265
|
const resolution = resolveOperationVariantKey(opConfig.guardRouting, caller)
|
|
242
266
|
if (!resolution.ok) {
|
|
243
|
-
|
|
267
|
+
vars.set('guardVariantFailure', resolution)
|
|
244
268
|
return
|
|
245
269
|
}
|
|
246
270
|
|
|
@@ -248,11 +272,11 @@ function makeShapeMiddleware<TCtx, TPrisma, TEnv extends HonoEnvBase>(
|
|
|
248
272
|
opConfig.guardRouting.kind === 'named'
|
|
249
273
|
? resolution.key
|
|
250
274
|
: undefined
|
|
251
|
-
if (resolvedKey !== undefined)
|
|
275
|
+
if (resolvedKey !== undefined) vars.set('guardVariantKey', resolvedKey)
|
|
252
276
|
|
|
253
277
|
if (opConfig.guardShape) {
|
|
254
278
|
const resolveCtx = typeof config.resolveContext === 'function'
|
|
255
|
-
?
|
|
279
|
+
? vars.get('resolveOperationContext')
|
|
256
280
|
: undefined
|
|
257
281
|
|
|
258
282
|
/**
|
|
@@ -265,18 +289,20 @@ function makeShapeMiddleware<TCtx, TPrisma, TEnv extends HonoEnvBase>(
|
|
|
265
289
|
* behaviour: it is resolved at the point of use, and a function returning
|
|
266
290
|
* something unusable is not this router's business to refuse.
|
|
267
291
|
*/
|
|
268
|
-
let effectiveShape: unknown = opConfig.guardShape
|
|
292
|
+
let effectiveShape: Record<string, unknown> | undefined = opConfig.guardShape
|
|
269
293
|
if (policy.validateResolvedShapes) {
|
|
270
294
|
const resolution = await resolveGuardShapeOnce(opConfig.guardShape, resolvedKey, resolveCtx)
|
|
271
295
|
if (!resolution.ok) {
|
|
272
|
-
|
|
296
|
+
vars.set('guardShapeFailure', resolution.problem)
|
|
273
297
|
return
|
|
274
298
|
}
|
|
275
|
-
|
|
299
|
+
// \`ok\` means the resolved value is a shape object; the fallback keeps the
|
|
300
|
+
// declared shape rather than storing something the context cannot hold.
|
|
301
|
+
effectiveShape = isPlainObject(resolution.shape) ? resolution.shape : opConfig.guardShape
|
|
276
302
|
}
|
|
277
303
|
|
|
278
304
|
if (!dropGuard) {
|
|
279
|
-
|
|
305
|
+
vars.set('guardShape', effectiveShape)
|
|
280
306
|
} else {
|
|
281
307
|
await applyDroppedGuard(
|
|
282
308
|
effectiveShape,
|
|
@@ -284,24 +310,24 @@ function makeShapeMiddleware<TCtx, TPrisma, TEnv extends HonoEnvBase>(
|
|
|
284
310
|
resolveCtx,
|
|
285
311
|
opKind,
|
|
286
312
|
{
|
|
287
|
-
readQuery:
|
|
288
|
-
writeBody: isPlainObject(
|
|
289
|
-
? (
|
|
313
|
+
readQuery: vars.get('parsedQuery'),
|
|
314
|
+
writeBody: isPlainObject(vars.get('body'))
|
|
315
|
+
? (vars.get('body') as Record<string, unknown>)
|
|
290
316
|
: undefined,
|
|
291
317
|
},
|
|
292
318
|
() => {
|
|
293
|
-
let target =
|
|
319
|
+
let target = vars.get('parsedQuery')
|
|
294
320
|
if (!target) {
|
|
295
321
|
target = {}
|
|
296
|
-
|
|
322
|
+
vars.set('parsedQuery', target)
|
|
297
323
|
}
|
|
298
324
|
return target
|
|
299
325
|
},
|
|
300
326
|
() => {
|
|
301
|
-
let target =
|
|
327
|
+
let target = vars.get('body')
|
|
302
328
|
if (!isPlainObject(target)) {
|
|
303
329
|
target = {}
|
|
304
|
-
|
|
330
|
+
vars.set('body', target)
|
|
305
331
|
}
|
|
306
332
|
return target as Record<string, unknown>
|
|
307
333
|
},
|
|
@@ -350,7 +376,7 @@ function sendError(c: HandlerContext, error: unknown): Response {
|
|
|
350
376
|
return c.json({ message: httpError.message }, httpError.status as ContentfulStatusCode)
|
|
351
377
|
}
|
|
352
378
|
|
|
353
|
-
export function ${routerFunctionName}<TCtx = unknown, TPrisma =
|
|
379
|
+
export function ${routerFunctionName}<TCtx = unknown, TPrisma extends PrismaClientLike = PrismaClientLike, TEnv extends HonoEnvBase = HonoEnvBase>(config: ${modelName}RouteConfig<TCtx, TPrisma, TEnv> = {}): Hono<GeneratedHonoEnv<TEnv>> {
|
|
354
380
|
validateCountSourceWhere(config.pagination?.countSource, '${modelName} pagination')
|
|
355
381
|
validateCountSourceWhere(
|
|
356
382
|
(config.findManyPaginated && typeof config.findManyPaginated === 'object' ? config.findManyPaginated : undefined)?.pagination?.countSource,
|
|
@@ -360,9 +386,10 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
360
386
|
const app = new Hono<GeneratedHonoEnv<TEnv>>()
|
|
361
387
|
|
|
362
388
|
const isEnabled = (value: unknown): boolean => value !== false && !!(config.enableAll || value)
|
|
389
|
+
warnIfUnguardedRoutes('${modelName}', ['findMany', 'findUnique', 'findUniqueOrThrow', 'findFirst', 'findFirstOrThrow', 'findManyPaginated', 'count', 'aggregate', 'groupBy', 'create', 'createMany', 'createManyAndReturn', 'update', 'updateMany', 'updateManyAndReturn', 'upsert', 'delete', 'deleteMany'], config, isEnabled)
|
|
363
390
|
|
|
364
391
|
const customPrefix = normalizePrefix(config.customUrlPrefix || '')
|
|
365
|
-
|
|
392
|
+
const modelPrefix = config.addModelPrefix !== false ? '/${modelSegment}' : ''
|
|
366
393
|
const basePath = customPrefix + modelPrefix
|
|
367
394
|
|
|
368
395
|
const openApiDisabled = config.disableOpenApi === true
|
|
@@ -371,7 +398,6 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
371
398
|
|| _env.DISABLE_OPENAPI === 'true'
|
|
372
399
|
))
|
|
373
400
|
|
|
374
|
-
const postReadsEnabled = !config.disablePostReads
|
|
375
401
|
|
|
376
402
|
let _openApiJsonCache: unknown = undefined
|
|
377
403
|
const getOpenApiJson = (): unknown => {
|
|
@@ -380,8 +406,8 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
380
406
|
'${modelName}',
|
|
381
407
|
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
382
408
|
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
383
|
-
config as
|
|
384
|
-
{ format: 'json', writeStrategy: '${writeStrategy}' },
|
|
409
|
+
config as unknown as Parameters<typeof buildModelOpenApi>[3],
|
|
410
|
+
{ format: 'json', writeStrategy: '${writeStrategy}', pathSegment: '${modelSegment}' },
|
|
385
411
|
)
|
|
386
412
|
}
|
|
387
413
|
return _openApiJsonCache
|
|
@@ -393,14 +419,14 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
393
419
|
'${modelName}',
|
|
394
420
|
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
395
421
|
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
396
|
-
config as
|
|
397
|
-
{ format: 'yaml', writeStrategy: '${writeStrategy}' },
|
|
422
|
+
config as unknown as Parameters<typeof buildModelOpenApi>[3],
|
|
423
|
+
{ format: 'yaml', writeStrategy: '${writeStrategy}', pathSegment: '${modelSegment}' },
|
|
398
424
|
) as string
|
|
399
425
|
}
|
|
400
426
|
return _openApiYamlCache
|
|
401
427
|
}
|
|
402
428
|
|
|
403
|
-
if (config.queryBuilder &&
|
|
429
|
+
if (config.queryBuilder && _env.NODE_ENV !== 'production') {
|
|
404
430
|
console.warn(
|
|
405
431
|
'[${modelName}Router] queryBuilder config is present but Hono target does not auto-start it. ' +
|
|
406
432
|
'Run \`npx prisma-query-builder-ui\` in a separate process.',
|
|
@@ -408,7 +434,7 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
408
434
|
}
|
|
409
435
|
|
|
410
436
|
app.onError((err, c) => {
|
|
411
|
-
return sendError(c as HandlerContext, err)
|
|
437
|
+
return sendError(c as unknown as HandlerContext, err)
|
|
412
438
|
})
|
|
413
439
|
|
|
414
440
|
if (!openApiDisabled) {
|
|
@@ -438,14 +464,15 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
438
464
|
* that branch is inert rather than merely unreached when it is off.
|
|
439
465
|
*/
|
|
440
466
|
const settleGuard = (c: Context<GeneratedHonoEnv<TEnv>>): void => {
|
|
441
|
-
const
|
|
467
|
+
const vars = c as unknown as HandlerContext
|
|
468
|
+
const failure = vars.get('guardVariantFailure')
|
|
442
469
|
if (failure) {
|
|
443
470
|
throw new HTTPException(400, {
|
|
444
471
|
message: formatGuardVariantResolutionError(failure),
|
|
445
472
|
})
|
|
446
473
|
}
|
|
447
474
|
|
|
448
|
-
const shapeFailure =
|
|
475
|
+
const shapeFailure = vars.get('guardShapeFailure')
|
|
449
476
|
if (shapeFailure) {
|
|
450
477
|
throw new HTTPException(500, {
|
|
451
478
|
message: 'guard shape could not be resolved: ' + shapeFailure,
|
|
@@ -460,6 +487,8 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
460
487
|
opKind: OpKind,
|
|
461
488
|
) => async (c: Context<GeneratedHonoEnv<TEnv>>): Promise<Response> => {
|
|
462
489
|
try {
|
|
490
|
+
const authorized = await runBeforeHooks<TEnv>(opConfig.authorize ? [opConfig.authorize] : [], c)
|
|
491
|
+
if (authorized) return authorized
|
|
463
492
|
await parseFn(c as unknown as HandlerContext)
|
|
464
493
|
await makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig, opKind)(c)
|
|
465
494
|
|
|
@@ -472,7 +501,7 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
472
501
|
// Upstream order: hooks first, guard failure after.
|
|
473
502
|
if (!SETTLE_BEFORE_HOOKS) settleGuard(c)
|
|
474
503
|
|
|
475
|
-
const key = c.get('guardVariantKey')
|
|
504
|
+
const key = (c as unknown as HandlerContext).get('guardVariantKey')
|
|
476
505
|
const variantHooks =
|
|
477
506
|
key !== undefined ? opConfig.variantHooks[key] : undefined
|
|
478
507
|
|
|
@@ -495,6 +524,8 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
495
524
|
opKind: OpKind,
|
|
496
525
|
) => async (c: Context<GeneratedHonoEnv<TEnv>>): Promise<Response> => {
|
|
497
526
|
try {
|
|
527
|
+
const authorized = await runBeforeHooks<TEnv>(opConfig.authorize ? [opConfig.authorize] : [], c)
|
|
528
|
+
if (authorized) return authorized
|
|
498
529
|
await parseWriteBodyMiddleware(c as unknown as HandlerContext)
|
|
499
530
|
await makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig, opKind)(c)
|
|
500
531
|
|
|
@@ -507,7 +538,7 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
507
538
|
// Upstream order: hooks first, guard failure after.
|
|
508
539
|
if (!SETTLE_BEFORE_HOOKS) settleGuard(c)
|
|
509
540
|
|
|
510
|
-
const key = c.get('guardVariantKey')
|
|
541
|
+
const key = (c as unknown as HandlerContext).get('guardVariantKey')
|
|
511
542
|
const variantHooks =
|
|
512
543
|
key !== undefined ? opConfig.variantHooks[key] : undefined
|
|
513
544
|
|
|
@@ -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":";;AA6IA,gEAwjBC;AApsBD,uEAAmE;AAEnE,kDAA8C;AAE9C,oDAAqE;AACrE,uEAAiE;AAEjE,SAAS,QAAQ,CAAC,MAAc;IAC9B,IAAI,CAAC,MAAM;QAAE,OAAO,iBAAiB,CAAA;IACrC,OAAO,iBAAiB,MAAM,IAAI,CAAA;AACpC,CAAC;AAED,SAAS,SAAS,CAAC,MAAc;IAC/B,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,YAAY,CAAC;QAClB,KAAK,mBAAmB;YACtB,OAAO,YAAY,CAAA;QACrB,KAAK,UAAU,CAAC;QAChB,KAAK,WAAW,CAAC;QACjB,KAAK,kBAAkB,CAAC;QACxB,KAAK,mBAAmB,CAAC;QACzB,KAAK,OAAO,CAAC;QACb,KAAK,WAAW,CAAC;QACjB,KAAK,SAAS;YACZ,OAAO,MAAM,CAAA;QACf,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAA;QACjB,KAAK,YAAY,CAAC;QAClB,KAAK,qBAAqB;YACxB,OAAO,YAAY,CAAA;QACrB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAA;QACjB,KAAK,YAAY,CAAC;QAClB,KAAK,qBAAqB;YACxB,OAAO,YAAY,CAAA;QACrB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAA;QACjB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAA;QACjB,KAAK,YAAY;YACf,OAAO,YAAY,CAAA;QACrB;YACE,OAAO,MAAM,CAAA;IACjB,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CACjB,IAAyC,EACzC,SAAiB;IAEjB,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;I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,CAAA;AACD,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ImportStyle } from '../utils/resolveImportStyle';
|
|
2
2
|
import type { Target } from '../constants';
|
|
3
|
-
export declare function generateUnifiedDocs(modelNames: string[], target: Target, importStyle: ImportStyle): string;
|
|
3
|
+
export declare function generateUnifiedDocs(modelNames: string[], pathSegments: Record<string, string>, target: Target, importStyle: ImportStyle): string;
|
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateUnifiedDocs = generateUnifiedDocs;
|
|
4
4
|
const importExt_1 = require("../utils/importExt");
|
|
5
|
-
function generateUnifiedDocs(modelNames, target, importStyle) {
|
|
5
|
+
function generateUnifiedDocs(modelNames, pathSegments, target, importStyle) {
|
|
6
6
|
const ext = (0, importExt_1.importExt)(importStyle);
|
|
7
7
|
if (target === 'fastify')
|
|
8
|
-
return generateFastify(modelNames, ext);
|
|
8
|
+
return generateFastify(modelNames, pathSegments, ext);
|
|
9
9
|
if (target === 'hono')
|
|
10
|
-
return generateHono(modelNames, ext);
|
|
11
|
-
return generateExpress(modelNames, ext);
|
|
10
|
+
return generateHono(modelNames, pathSegments, ext);
|
|
11
|
+
return generateExpress(modelNames, pathSegments, ext);
|
|
12
12
|
}
|
|
13
13
|
const renderIndexFn = `function renderIndex(title: string, modelNames: string[], basePath: string): string {
|
|
14
|
+
const segments = MODEL_PATH_SEGMENTS as Record<string, string>
|
|
14
15
|
const links = modelNames
|
|
15
|
-
.map((n) => '<li><a href="' + basePath + '/' + n.toLowerCase() + '">' + n + '</a></li>')
|
|
16
|
+
.map((n) => '<li><a href="' + basePath + '/' + (segments[n] ?? n.toLowerCase()) + '">' + n + '</a></li>')
|
|
16
17
|
.join('')
|
|
17
18
|
|
|
18
19
|
return '<!DOCTYPE html><html><head><meta charset="utf-8" /><title>' + title +
|
|
@@ -23,7 +24,7 @@ const renderIndexFn = `function renderIndex(title: string, modelNames: string[],
|
|
|
23
24
|
'<ul class="mt-4 list-disc pl-6 text-sm">' + links + '</ul>' +
|
|
24
25
|
'</div></body></html>'
|
|
25
26
|
}`;
|
|
26
|
-
function generateExpress(modelNames, ext) {
|
|
27
|
+
function generateExpress(modelNames, pathSegments, ext) {
|
|
27
28
|
return `import type { Router } from 'express'
|
|
28
29
|
import { getEnv, removeTrailingSlash } from './misc${ext}'
|
|
29
30
|
|
|
@@ -31,6 +32,8 @@ const _env = getEnv()
|
|
|
31
32
|
|
|
32
33
|
const MODELS = ${JSON.stringify(modelNames)} as const
|
|
33
34
|
|
|
35
|
+
const MODEL_PATH_SEGMENTS = ${JSON.stringify(pathSegments)} as const
|
|
36
|
+
|
|
34
37
|
interface UnifiedDocsConfig {
|
|
35
38
|
title?: string
|
|
36
39
|
basePath?: string
|
|
@@ -57,7 +60,7 @@ ${renderIndexFn}
|
|
|
57
60
|
export default registerUnifiedDocs
|
|
58
61
|
`;
|
|
59
62
|
}
|
|
60
|
-
function generateFastify(modelNames, ext) {
|
|
63
|
+
function generateFastify(modelNames, pathSegments, ext) {
|
|
61
64
|
return `import type { FastifyInstance } from 'fastify'
|
|
62
65
|
import { getEnv, removeTrailingSlash } from './misc${ext}'
|
|
63
66
|
|
|
@@ -65,6 +68,8 @@ const _env = getEnv()
|
|
|
65
68
|
|
|
66
69
|
const MODELS = ${JSON.stringify(modelNames)} as const
|
|
67
70
|
|
|
71
|
+
const MODEL_PATH_SEGMENTS = ${JSON.stringify(pathSegments)} as const
|
|
72
|
+
|
|
68
73
|
interface UnifiedDocsConfig {
|
|
69
74
|
title?: string
|
|
70
75
|
basePath?: string
|
|
@@ -94,7 +99,7 @@ ${renderIndexFn}
|
|
|
94
99
|
export default registerUnifiedDocs
|
|
95
100
|
`;
|
|
96
101
|
}
|
|
97
|
-
function generateHono(modelNames, ext) {
|
|
102
|
+
function generateHono(modelNames, pathSegments, ext) {
|
|
98
103
|
return `import type { Hono } from 'hono'
|
|
99
104
|
import { getEnv, removeTrailingSlash } from './misc${ext}'
|
|
100
105
|
|
|
@@ -102,6 +107,8 @@ const _env = getEnv()
|
|
|
102
107
|
|
|
103
108
|
const MODELS = ${JSON.stringify(modelNames)} as const
|
|
104
109
|
|
|
110
|
+
const MODEL_PATH_SEGMENTS = ${JSON.stringify(pathSegments)} as const
|
|
111
|
+
|
|
105
112
|
interface UnifiedDocsConfig {
|
|
106
113
|
title?: string
|
|
107
114
|
basePath?: string
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateUnifiedDocs.js","sourceRoot":"","sources":["../../src/generators/generateUnifiedDocs.ts"],"names":[],"mappings":";;AAIA,
|
|
1
|
+
{"version":3,"file":"generateUnifiedDocs.js","sourceRoot":"","sources":["../../src/generators/generateUnifiedDocs.ts"],"names":[],"mappings":";;AAIA,kDAWC;AAdD,kDAA8C;AAG9C,SAAgB,mBAAmB,CACjC,UAAoB,EACpB,YAAoC,EACpC,MAAc,EACd,WAAwB;IAExB,MAAM,GAAG,GAAG,IAAA,qBAAS,EAAC,WAAW,CAAC,CAAA;IAClC,IAAI,MAAM,KAAK,SAAS;QACtB,OAAO,eAAe,CAAC,UAAU,EAAE,YAAY,EAAE,GAAG,CAAC,CAAA;IACvD,IAAI,MAAM,KAAK,MAAM;QAAE,OAAO,YAAY,CAAC,UAAU,EAAE,YAAY,EAAE,GAAG,CAAC,CAAA;IACzE,OAAO,eAAe,CAAC,UAAU,EAAE,YAAY,EAAE,GAAG,CAAC,CAAA;AACvD,CAAC;AAED,MAAM,aAAa,GAAG;;;;;;;;;;;;;EAapB,CAAA;AAEF,SAAS,eAAe,CACtB,UAAoB,EACpB,YAAoC,EACpC,GAAW;IAEX,OAAO;qDAC4C,GAAG;;;;iBAIvC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;;8BAEb,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;EAuBxD,aAAa;;;CAGd,CAAA;AACD,CAAC;AAED,SAAS,eAAe,CACtB,UAAoB,EACpB,YAAoC,EACpC,GAAW;IAEX,OAAO;qDAC4C,GAAG;;;;iBAIvC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;;8BAEb,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BxD,aAAa;;;CAGd,CAAA;AACD,CAAC;AAED,SAAS,YAAY,CACnB,UAAoB,EACpB,YAAoC,EACpC,GAAW;IAEX,OAAO;qDAC4C,GAAG;;;;iBAIvC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;;8BAEb,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;EAuBxD,aAAa;;;CAGd,CAAA;AACD,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DMMF } from '@prisma/generator-helper';
|
|
2
|
-
import { ImportStyle } from '../utils/resolveImportStyle';
|
|
1
|
+
import type { DMMF } from '@prisma/generator-helper';
|
|
2
|
+
import type { ImportStyle } from '../utils/resolveImportStyle';
|
|
3
3
|
export interface UnifiedHandlerOptions {
|
|
4
4
|
model: DMMF.Model;
|
|
5
5
|
importStyle: ImportStyle;
|
|
@@ -7,7 +7,8 @@ function generateUnifiedHandler(options) {
|
|
|
7
7
|
const ext = (0, importExt_1.importExt)(options.importStyle);
|
|
8
8
|
const modelName = options.model.name;
|
|
9
9
|
const dispatchOps = operationDefinitions_1.OPERATION_METADATA.filter((m) => m.name !== 'updateEach');
|
|
10
|
-
const handlers = dispatchOps
|
|
10
|
+
const handlers = dispatchOps
|
|
11
|
+
.map((meta) => {
|
|
11
12
|
const exportName = `${modelName}${meta.name.charAt(0).toUpperCase() + meta.name.slice(1)}`;
|
|
12
13
|
return `
|
|
13
14
|
export async function ${exportName}(
|
|
@@ -22,10 +23,11 @@ export async function ${exportName}(
|
|
|
22
23
|
next(mapError(error))
|
|
23
24
|
}
|
|
24
25
|
}`;
|
|
25
|
-
})
|
|
26
|
+
})
|
|
27
|
+
.join('\n');
|
|
26
28
|
return `import type { Request, Response, NextFunction } from 'express'
|
|
27
29
|
import * as core from './${modelName}Core${ext}'
|
|
28
|
-
import { OperationContext } from '../operationRuntime${ext}'
|
|
30
|
+
import type { OperationContext, RuntimeOperationOverride } from '../operationRuntime${ext}'
|
|
29
31
|
import { mapError } from '../errorMapper${ext}'
|
|
30
32
|
|
|
31
33
|
type ExtendedRequest = Request & {
|
|
@@ -39,6 +41,9 @@ type LocalsBag = {
|
|
|
39
41
|
routeConfig?: { pagination?: unknown }
|
|
40
42
|
guardShape?: Record<string, unknown>
|
|
41
43
|
guardCaller?: string
|
|
44
|
+
guardVariantKey?: string
|
|
45
|
+
operationOverride?: RuntimeOperationOverride
|
|
46
|
+
resolveOperationContext?: () => unknown | Promise<unknown>
|
|
42
47
|
data?: unknown
|
|
43
48
|
}
|
|
44
49
|
|
|
@@ -46,6 +51,8 @@ function buildContext(req: Request, res: Response): OperationContext {
|
|
|
46
51
|
const extReq = req as ExtendedRequest
|
|
47
52
|
const locals = res.locals as LocalsBag
|
|
48
53
|
return {
|
|
54
|
+
operationOverride: locals.operationOverride,
|
|
55
|
+
resolveOperationContext: locals.resolveOperationContext,
|
|
49
56
|
prisma: extReq.prisma,
|
|
50
57
|
postgres: extReq.postgres,
|
|
51
58
|
sqlite: extReq.sqlite,
|
|
@@ -53,6 +60,7 @@ function buildContext(req: Request, res: Response): OperationContext {
|
|
|
53
60
|
body: req.body,
|
|
54
61
|
guardShape: locals.guardShape,
|
|
55
62
|
guardCaller: locals.guardCaller,
|
|
63
|
+
guardVariantKey: locals.guardVariantKey,
|
|
56
64
|
paginationConfig: (locals.routeConfig?.pagination) as OperationContext['paginationConfig'],
|
|
57
65
|
}
|
|
58
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateUnifiedHandler.js","sourceRoot":"","sources":["../../src/generators/generateUnifiedHandler.ts"],"names":[],"mappings":";;AAUA,
|
|
1
|
+
{"version":3,"file":"generateUnifiedHandler.js","sourceRoot":"","sources":["../../src/generators/generateUnifiedHandler.ts"],"names":[],"mappings":";;AAUA,wDAmEC;AA3ED,kDAA8C;AAC9C,uEAAiE;AAOjE,SAAgB,sBAAsB,CAAC,OAA8B;IACnE,MAAM,GAAG,GAAG,IAAA,qBAAS,EAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IAC1C,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAA;IAEpC,MAAM,WAAW,GAAG,yCAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,YAAY,CAAC,CAAA;IAE7E,MAAM,QAAQ,GAAG,WAAW;SACzB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,MAAM,UAAU,GAAG,GAAG,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;QAE1F,OAAO;wBACW,UAAU;;;;;;mDAMiB,IAAI,CAAC,QAAQ;;;;;EAK9D,CAAA;IACE,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,OAAO;2BACkB,SAAS,OAAO,GAAG;sFACwC,GAAG;0CAC/C,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoC3C,QAAQ;CACT,CAAA;AACD,CAAC"}
|
package/dist/guardOptions.js
CHANGED
|
@@ -77,8 +77,8 @@ exports.GUARD_OPTION_METADATA = Object.freeze([
|
|
|
77
77
|
type: 'boolean',
|
|
78
78
|
default: exports.UPSTREAM_GUARD_DEFAULTS.allowE2EGuardBypass,
|
|
79
79
|
hardened: exports.HARDENED_GUARD_PROFILE.allowE2EGuardBypass,
|
|
80
|
-
label: 'Honour the
|
|
81
|
-
description: 'Treats
|
|
80
|
+
label: 'Honour the PGE_DROP_GUARD environment guard bypass',
|
|
81
|
+
description: 'Treats PGE_DROP_GUARD=true in the environment as a request to drop the guard. Deprecated alias: E2E=true.',
|
|
82
82
|
warning: 'A runtime variable can weaken a deployed artifact after generation. On an edge runtime this is an ordinary config var.',
|
|
83
83
|
target: 'hono',
|
|
84
84
|
},
|
|
@@ -112,12 +112,17 @@ exports.GUARD_METADATA_SCOPE = Object.freeze({
|
|
|
112
112
|
function resolveGuardPolicy(config) {
|
|
113
113
|
return {
|
|
114
114
|
requireGuardShape: config?.requireGuardShape ?? exports.UPSTREAM_GUARD_DEFAULTS.requireGuardShape,
|
|
115
|
-
validateGuardShapes: config?.validateGuardShapes ??
|
|
116
|
-
|
|
115
|
+
validateGuardShapes: config?.validateGuardShapes ??
|
|
116
|
+
exports.UPSTREAM_GUARD_DEFAULTS.validateGuardShapes,
|
|
117
|
+
requireDefaultVariantOptIn: config?.requireDefaultVariantOptIn ??
|
|
118
|
+
exports.UPSTREAM_GUARD_DEFAULTS.requireDefaultVariantOptIn,
|
|
117
119
|
enableUpdateEach: config?.enableUpdateEach ?? exports.UPSTREAM_GUARD_DEFAULTS.enableUpdateEach,
|
|
118
|
-
guardResolutionOrder: config?.guardResolutionOrder ??
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
guardResolutionOrder: config?.guardResolutionOrder ??
|
|
121
|
+
exports.UPSTREAM_GUARD_DEFAULTS.guardResolutionOrder,
|
|
122
|
+
allowE2EGuardBypass: config?.allowE2EGuardBypass ??
|
|
123
|
+
exports.UPSTREAM_GUARD_DEFAULTS.allowE2EGuardBypass,
|
|
124
|
+
validateResolvedShapes: config?.validateResolvedShapes ??
|
|
125
|
+
exports.UPSTREAM_GUARD_DEFAULTS.validateResolvedShapes,
|
|
121
126
|
};
|
|
122
127
|
}
|
|
123
128
|
//# sourceMappingURL=guardOptions.js.map
|
package/dist/guardOptions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guardOptions.js","sourceRoot":"","sources":["../src/guardOptions.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"guardOptions.js","sourceRoot":"","sources":["../src/guardOptions.ts"],"names":[],"mappings":";;;AAsNA,gDAwBC;AA5LY,QAAA,uBAAuB,GAA0B,MAAM,CAAC,MAAM,CAAC;IAC1E,iBAAiB,EAAE,KAAK;IACxB,mBAAmB,EAAE,KAAK;IAC1B,0BAA0B,EAAE,KAAK;IACjC,gBAAgB,EAAE,IAAI;IACtB,oBAAoB,EAAE,aAAa;IACnC,mBAAmB,EAAE,IAAI;IACzB,sBAAsB,EAAE,KAAK;CAC9B,CAAC,CAAA;AAUW,QAAA,sBAAsB,GAA0B,MAAM,CAAC,MAAM,CAAC;IACzE,iBAAiB,EAAE,IAAI;IACvB,mBAAmB,EAAE,IAAI;IACzB,0BAA0B,EAAE,IAAI;IAChC,gBAAgB,EAAE,KAAK;IACvB,oBAAoB,EAAE,cAAc;IACpC,mBAAmB,EAAE,KAAK;IAC1B,sBAAsB,EAAE,IAAI;CAC7B,CAAC,CAAA;AAwBW,QAAA,qBAAqB,GAChC,MAAM,CAAC,MAAM,CAAC;IACZ;QACE,IAAI,EAAE,mBAAmB;QACzB,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,+BAAuB,CAAC,iBAAiB;QAClD,QAAQ,EAAE,8BAAsB,CAAC,iBAAiB;QAClD,KAAK,EAAE,4CAA4C;QACnD,WAAW,EACT,0FAA0F;QAC5F,OAAO,EACL,sGAAsG;QACxG,MAAM,EAAE,MAAM;KACf;IACD;QACE,IAAI,EAAE,qBAAqB;QAC3B,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,+BAAuB,CAAC,mBAAmB;QACpD,QAAQ,EAAE,8BAAsB,CAAC,mBAAmB;QACpD,KAAK,EAAE,uBAAuB;QAC9B,WAAW,EACT,8GAA8G;QAChH,OAAO,EACL,oHAAoH;QACtH,MAAM,EAAE,MAAM;KACf;IACD;QACE,IAAI,EAAE,4BAA4B;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O,EACL,iGAAiG;QACnG,MAAM,EAAE,MAAM;KACf;CACF,CAAC,CAAA;AASS,QAAA,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC;IAChD,MAAM,EAAE,kDAAkD;IAC1D,QAAQ,EAAE,KAAK;IACf,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC;QAC7B,WAAW;QACX,QAAQ;QACR,eAAe;QACf,qCAAqC;QACrC,wBAAwB;QACxB,iDAAiD;QACjD,iDAAiD;QACjD,kBAAkB;QAClB,cAAc;QACd,4CAA4C;KAC7C,CAAC;CACH,CAAC,CAAA;AAGF,SAAgB,kBAAkB,CAChC,MAAwC;IAExC,OAAO;QACL,iBAAiB,EACf,MAAM,EAAE,iBAAiB,IAAI,+BAAuB,CAAC,iBAAiB;QACxE,mBAAmB,EACjB,MAAM,EAAE,mBAAmB;YAC3B,+BAAuB,CAAC,mBAAmB;QAC7C,0BAA0B,EACxB,MAAM,EAAE,0BAA0B;YAClC,+BAAuB,CAAC,0BAA0B;QACpD,gBAAgB,EACd,MAAM,EAAE,gBAAgB,IAAI,+BAAuB,CAAC,gBAAgB;QACtE,oBAAoB,EAClB,MAAM,EAAE,oBAAoB;YAC5B,+BAAuB,CAAC,oBAAoB;QAC9C,mBAAmB,EACjB,MAAM,EAAE,mBAAmB;YAC3B,+BAAuB,CAAC,mBAAmB;QAC7C,sBAAsB,EACpB,MAAM,EAAE,sBAAsB;YAC9B,+BAAuB,CAAC,sBAAsB;KACjD,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { GUARD_OPTION_METADATA, GUARD_METADATA_SCOPE, UPSTREAM_GUARD_DEFAULTS, HARDENED_GUARD_PROFILE, resolveGuardPolicy, } from './guardOptions';
|
|
2
|
-
export type { GuardPolicy, GuardOptionMetadata, GuardResolutionOrder } from './guardOptions';
|
|
2
|
+
export type { GuardPolicy, GuardOptionMetadata, GuardResolutionOrder, } from './guardOptions';
|