burger-api 0.9.6 → 1.0.0-beta
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 +84 -241
- package/dist/src/adapter/bun/index.d.ts +14 -0
- package/dist/src/adapter/bun/index.js +73 -0
- package/dist/src/adapter/bun/types.d.ts +15 -0
- package/dist/src/adapter/bun/types.js +1 -0
- package/dist/src/adapter/index.d.ts +1 -0
- package/dist/src/adapter/index.js +1 -0
- package/dist/src/adapter/types.d.ts +49 -0
- package/dist/src/adapter/types.js +1 -0
- package/dist/src/adapter/web-standard/fetch-handler.d.ts +39 -0
- package/dist/src/adapter/web-standard/fetch-handler.js +54 -0
- package/dist/src/adapter/web-standard/index.d.ts +8 -0
- package/dist/src/adapter/web-standard/index.js +7 -0
- package/dist/src/analysis/route-access-analyzer.d.ts +10 -0
- package/dist/src/analysis/route-access-analyzer.js +287 -0
- package/dist/src/chain/chain.d.ts +16 -0
- package/dist/src/chain/chain.js +17 -0
- package/dist/src/chain/flattener.d.ts +3 -0
- package/dist/src/chain/flattener.js +78 -0
- package/dist/src/chain/node.d.ts +25 -0
- package/dist/src/chain/node.js +1 -0
- package/dist/src/compiler/conventions.d.ts +67 -0
- package/dist/src/compiler/conventions.js +129 -0
- package/dist/src/compiler/index.d.ts +13 -0
- package/dist/src/compiler/index.js +11 -0
- package/dist/src/compiler/module-loader.d.ts +75 -0
- package/dist/src/compiler/module-loader.js +276 -0
- package/dist/src/compiler/route-module.d.ts +97 -0
- package/dist/src/compiler/route-module.js +1 -0
- package/dist/src/compiler/route-tree.d.ts +19 -0
- package/dist/src/compiler/route-tree.js +28 -0
- package/dist/src/compiler/scanner.d.ts +42 -0
- package/dist/src/compiler/scanner.js +201 -0
- package/dist/src/context/context-set.d.ts +26 -0
- package/dist/src/context/context-set.js +45 -0
- package/dist/src/context/context.d.ts +357 -0
- package/dist/src/context/context.js +401 -0
- package/dist/src/context/query-parser.d.ts +23 -0
- package/dist/src/context/query-parser.js +132 -0
- package/dist/src/context/route-access.d.ts +7 -0
- package/dist/src/context/route-access.js +18 -0
- package/dist/src/context/types.d.ts +62 -0
- package/dist/src/context/types.js +5 -0
- package/dist/src/core/asset-mime.d.ts +9 -0
- package/dist/src/core/asset-mime.js +35 -0
- package/dist/src/core/assets.d.ts +30 -0
- package/dist/src/core/assets.js +67 -0
- package/dist/src/core/docs-providers.d.ts +13 -0
- package/dist/src/core/docs-providers.js +89 -0
- package/dist/src/core/embedded-assets.d.ts +18 -0
- package/dist/src/core/embedded-assets.js +13 -0
- package/dist/src/core/openapi.d.ts +9 -10
- package/dist/src/core/openapi.js +333 -127
- package/dist/src/core/page-router.d.ts +13 -17
- package/dist/src/core/page-router.js +86 -55
- package/dist/src/core/server.d.ts +20 -11
- package/dist/src/core/server.js +41 -45
- package/dist/src/errors/forbidden.d.ts +14 -0
- package/dist/src/errors/forbidden.js +16 -0
- package/dist/src/errors/http-error.d.ts +47 -0
- package/dist/src/errors/http-error.js +146 -0
- package/dist/src/errors/method-not-allowed.d.ts +13 -0
- package/dist/src/errors/method-not-allowed.js +15 -0
- package/dist/src/errors/not-found.d.ts +14 -0
- package/dist/src/errors/not-found.js +16 -0
- package/dist/src/errors/unauthorized.d.ts +14 -0
- package/dist/src/errors/unauthorized.js +16 -0
- package/dist/src/index.d.ts +263 -50
- package/dist/src/index.js +919 -332
- package/dist/src/lifecycle/executor.d.ts +64 -0
- package/dist/src/lifecycle/executor.js +201 -0
- package/dist/src/lifecycle/hook-runner.d.ts +11 -0
- package/dist/src/lifecycle/hook-runner.js +156 -0
- package/dist/src/lifecycle/jit.d.ts +50 -0
- package/dist/src/lifecycle/jit.js +258 -0
- package/dist/src/lifecycle/transform.d.ts +26 -0
- package/dist/src/lifecycle/transform.js +99 -0
- package/dist/src/lifecycle/types.d.ts +135 -0
- package/dist/src/lifecycle/types.js +1 -0
- package/dist/src/plugin/composer.d.ts +3 -0
- package/dist/src/plugin/composer.js +28 -0
- package/dist/src/plugin/registry.d.ts +25 -0
- package/dist/src/plugin/registry.js +107 -0
- package/dist/src/plugin/types.d.ts +20 -0
- package/dist/src/plugin/types.js +1 -0
- package/dist/src/router/allow-cache.d.ts +20 -0
- package/dist/src/router/allow-cache.js +26 -0
- package/dist/src/router/compiler.d.ts +39 -0
- package/dist/src/router/compiler.js +817 -0
- package/dist/src/router/define.d.ts +67 -0
- package/dist/src/router/define.js +34 -0
- package/dist/src/router/index.d.ts +6 -0
- package/dist/src/router/index.js +5 -0
- package/dist/src/router/param-extract.d.ts +33 -0
- package/dist/src/router/param-extract.js +87 -0
- package/dist/src/router/regex-matcher.d.ts +42 -0
- package/dist/src/router/regex-matcher.js +216 -0
- package/dist/src/router/router.d.ts +201 -0
- package/dist/src/router/router.js +600 -0
- package/dist/src/router/static-map.d.ts +39 -0
- package/dist/src/router/static-map.js +48 -0
- package/dist/src/router/trie.d.ts +69 -0
- package/dist/src/router/trie.js +572 -0
- package/dist/src/router/types.d.ts +104 -0
- package/dist/src/router/types.js +1 -0
- package/dist/src/runtime/capabilities.d.ts +29 -0
- package/dist/src/runtime/capabilities.js +48 -0
- package/dist/src/types/index.d.ts +260 -109
- package/dist/src/types/index.js +1 -1
- package/dist/src/types/inference.d.ts +78 -0
- package/dist/src/types/inference.js +20 -0
- package/dist/src/types/openapi-config.d.ts +164 -0
- package/dist/src/types/openapi-config.js +8 -0
- package/dist/src/utils/env.d.ts +13 -0
- package/dist/src/utils/env.js +24 -0
- package/dist/src/utils/fs.d.ts +29 -0
- package/dist/src/utils/fs.js +75 -0
- package/dist/src/utils/index.d.ts +1 -1
- package/dist/src/utils/index.js +2 -2
- package/dist/src/utils/pathConversion.js +13 -7
- package/dist/src/utils/response.d.ts +42 -6
- package/dist/src/utils/response.js +172 -7
- package/dist/src/utils/routing.d.ts +32 -13
- package/dist/src/utils/routing.js +41 -18
- package/dist/src/utils/thenable.d.ts +8 -0
- package/dist/src/utils/thenable.js +12 -0
- package/dist/src/utils/timing-safe.d.ts +9 -0
- package/dist/src/utils/timing-safe.js +20 -0
- package/dist/src/utils/wildcard.d.ts +2 -9
- package/dist/src/utils/wildcard.js +20 -58
- package/dist/src/validation/adapter.d.ts +54 -0
- package/dist/src/validation/adapter.js +75 -0
- package/dist/src/validation/adapters/standard.d.ts +11 -0
- package/dist/src/validation/adapters/standard.js +110 -0
- package/dist/src/validation/adapters/zod.d.ts +9 -0
- package/dist/src/validation/adapters/zod.js +128 -0
- package/dist/src/validation/cache.d.ts +26 -0
- package/dist/src/validation/cache.js +35 -0
- package/dist/src/validation/coerce.d.ts +28 -0
- package/dist/src/validation/coerce.js +176 -0
- package/dist/src/validation/compiler.d.ts +27 -0
- package/dist/src/validation/compiler.js +191 -0
- package/dist/src/validation/error.d.ts +69 -0
- package/dist/src/validation/error.js +137 -0
- package/dist/src/validation/index.d.ts +16 -0
- package/dist/src/validation/index.js +12 -0
- package/dist/src/validation/response.d.ts +25 -0
- package/dist/src/validation/response.js +79 -0
- package/dist/src/validation/types.d.ts +148 -0
- package/dist/src/validation/types.js +6 -0
- package/dist/src/validation/validator.d.ts +39 -0
- package/dist/src/validation/validator.js +441 -0
- package/dist/src/ws/adapter.d.ts +219 -0
- package/dist/src/ws/adapter.js +623 -0
- package/dist/src/ws/compiler.d.ts +37 -0
- package/dist/src/ws/compiler.js +156 -0
- package/dist/src/ws/index.d.ts +11 -0
- package/dist/src/ws/index.js +8 -0
- package/dist/src/ws/platform.d.ts +81 -0
- package/dist/src/ws/platform.js +113 -0
- package/dist/src/ws/router.d.ts +48 -0
- package/dist/src/ws/router.js +174 -0
- package/dist/src/ws/scanner.d.ts +97 -0
- package/dist/src/ws/scanner.js +193 -0
- package/dist/src/ws/types.d.ts +380 -0
- package/dist/src/ws/types.js +213 -0
- package/package.json +72 -59
- package/dist/src/core/api-router.d.ts +0 -65
- package/dist/src/core/api-router.js +0 -264
- package/dist/src/core/swagger-ui.d.ts +0 -1
- package/dist/src/core/swagger-ui.js +0 -33
- package/dist/src/middleware/validator.d.ts +0 -14
- package/dist/src/middleware/validator.js +0 -133
- package/dist/src/utils/error.d.ts +0 -17
- package/dist/src/utils/error.js +0 -63
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The schema preparation component — compiles a `RouteSchema` into
|
|
3
|
+
* `CompiledRouteValidators`.
|
|
4
|
+
*
|
|
5
|
+
* Walks each slot, detects its adapter, computes identity, and consults the
|
|
6
|
+
* cache; builds coercion plans and response validators when present. Runs
|
|
7
|
+
* ONCE per route when it is set up (before `serve()`), never per request.
|
|
8
|
+
* Identical schemas (by reference) share one cached validator.
|
|
9
|
+
*/
|
|
10
|
+
import { ValidatorCache } from './cache.js';
|
|
11
|
+
import { detectAdapter, __setZodAdapter, __setStandardAdapter, } from './adapter.js';
|
|
12
|
+
// Explicit adapter registration — value imports (not side-effect imports) so
|
|
13
|
+
// registration survives tree-shaking under `sideEffects: false`.
|
|
14
|
+
import { ZodAdapter } from './adapters/zod.js';
|
|
15
|
+
import { StandardAdapter } from './adapters/standard.js';
|
|
16
|
+
__setZodAdapter(ZodAdapter);
|
|
17
|
+
__setStandardAdapter(StandardAdapter);
|
|
18
|
+
import { buildPlan as buildCoercionPlan } from './coerce.js';
|
|
19
|
+
/** The shared, process-lifetime validator cache. */
|
|
20
|
+
export const validatorCache = new ValidatorCache();
|
|
21
|
+
/** Request slots that can carry a schema in `RouteSchema`. */
|
|
22
|
+
const REQUEST_SLOTS = [
|
|
23
|
+
'params',
|
|
24
|
+
'query',
|
|
25
|
+
'headers',
|
|
26
|
+
'cookies',
|
|
27
|
+
'body',
|
|
28
|
+
];
|
|
29
|
+
/**
|
|
30
|
+
* Compiles a route's `schema` into `CompiledRouteValidators`.
|
|
31
|
+
*
|
|
32
|
+
* @param schema - the raw route schema.
|
|
33
|
+
* @param config - the validator configuration (coercion / response flags).
|
|
34
|
+
* @param cache - the validator cache (shared instance by default).
|
|
35
|
+
*/
|
|
36
|
+
export function compileRouteSchema(schema, config = {}, cache = validatorCache, route) {
|
|
37
|
+
const methods = {};
|
|
38
|
+
// `export const coerce = true` in schema.ts enables coercion for every
|
|
39
|
+
// method in the file (a per-method `coerce` still works the same).
|
|
40
|
+
const topLevelCoerce = schema.coerce === true;
|
|
41
|
+
for (const rawMethod of Object.keys(schema)) {
|
|
42
|
+
const method = rawMethod.toLowerCase();
|
|
43
|
+
// The top-level `coerce` flag is not a method.
|
|
44
|
+
if (method === 'coerce')
|
|
45
|
+
continue;
|
|
46
|
+
// Schema keys are typed as the method union; a module export is still
|
|
47
|
+
// a runtime string, so index via the widened record.
|
|
48
|
+
const m = schema[rawMethod] ?? {};
|
|
49
|
+
const compiledMethod = {};
|
|
50
|
+
// Coercion is opt-in: app-level config.coerce, top-level schema
|
|
51
|
+
// `coerce`, OR per-route schema[method].coerce override.
|
|
52
|
+
const coerceEnabled = config.coerce === true || topLevelCoerce || m.coerce === true;
|
|
53
|
+
for (const slot of REQUEST_SLOTS) {
|
|
54
|
+
const raw = m[slot];
|
|
55
|
+
if (raw === undefined)
|
|
56
|
+
continue;
|
|
57
|
+
if (slot === 'headers') {
|
|
58
|
+
assertLowercaseHeaderKeys(raw, rawMethod.toUpperCase(), route);
|
|
59
|
+
}
|
|
60
|
+
compiledMethod[slot] = compileSlot(raw, slot, cache);
|
|
61
|
+
}
|
|
62
|
+
// Build coercion plans only when coercion is enabled.
|
|
63
|
+
if (coerceEnabled) {
|
|
64
|
+
const coercion = {};
|
|
65
|
+
for (const slot of [
|
|
66
|
+
'query',
|
|
67
|
+
'params',
|
|
68
|
+
'headers',
|
|
69
|
+
'cookies',
|
|
70
|
+
]) {
|
|
71
|
+
const raw = m[slot];
|
|
72
|
+
if (raw === undefined)
|
|
73
|
+
continue;
|
|
74
|
+
// Self-coercing schemas (e.g. z.coerce.* / ~standard.coercible)
|
|
75
|
+
// transform their own input — framework coercion must not run.
|
|
76
|
+
if (compiledMethod[slot]?.coercible)
|
|
77
|
+
continue;
|
|
78
|
+
const plan = buildCoercionPlan(raw, slot);
|
|
79
|
+
if (plan)
|
|
80
|
+
coercion[slot] = plan;
|
|
81
|
+
}
|
|
82
|
+
if (Object.keys(coercion).length > 0) {
|
|
83
|
+
compiledMethod.coercion = coercion;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Method keys are lowercased at runtime before storage; the compiled
|
|
87
|
+
// map is union-keyed, so write via the widened record.
|
|
88
|
+
methods[method] =
|
|
89
|
+
compiledMethod;
|
|
90
|
+
}
|
|
91
|
+
// Compile response schemas (per-status) when present.
|
|
92
|
+
const response = compileResponseSchemas(schema, cache, route);
|
|
93
|
+
const result = { methods };
|
|
94
|
+
if (response)
|
|
95
|
+
result.response = response;
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Keys a schema exposes structurally (a Zod object's `.shape`, or a Standard
|
|
100
|
+
* Schema value carrying a `shape` record). Opaque schemas (`records`, maps)
|
|
101
|
+
* expose nothing, so they are skipped.
|
|
102
|
+
*/
|
|
103
|
+
function exposedShapeKeys(schema) {
|
|
104
|
+
const shape = schema.shape;
|
|
105
|
+
if (shape === null || typeof shape !== 'object')
|
|
106
|
+
return undefined;
|
|
107
|
+
return Object.keys(shape);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Header names are lowercased at runtime (`x-api-key`), so a schema key with
|
|
111
|
+
* uppercase letters can never match. Fails startup naming the key and the
|
|
112
|
+
* lowercase form. Only enforced when the schema exposes its keys structurally.
|
|
113
|
+
*/
|
|
114
|
+
function assertLowercaseHeaderKeys(schema, method, route) {
|
|
115
|
+
const keys = exposedShapeKeys(schema);
|
|
116
|
+
if (!keys)
|
|
117
|
+
return;
|
|
118
|
+
for (const key of keys) {
|
|
119
|
+
const lower = key.toLowerCase();
|
|
120
|
+
if (key !== lower) {
|
|
121
|
+
throw new Error(`Header schema key "${key}" for ` +
|
|
122
|
+
`${method}${route ? ` ${route}` : ''} can never match: ` +
|
|
123
|
+
`header names are lowercased at runtime. Use "${lower}" instead.`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** An exact status code (`200`) — the selected form. */
|
|
128
|
+
const STATUS_CODE_KEY = /^[1-5]\d\d$/;
|
|
129
|
+
/** A status class (`2xx`) — the fallback form, lowercase only. */
|
|
130
|
+
const STATUS_CLASS_KEY = /^[1-5]xx$/;
|
|
131
|
+
/**
|
|
132
|
+
* Compiles per-status `response` schemas into a map of `CompiledValidator`s.
|
|
133
|
+
* Returns undefined when no `response` schemas are declared.
|
|
134
|
+
*
|
|
135
|
+
* A key that is neither a status code nor a lowercase status class can never
|
|
136
|
+
* be selected at request time, so it fails startup naming the route, method
|
|
137
|
+
* and key instead of silently never running.
|
|
138
|
+
*/
|
|
139
|
+
function compileResponseSchemas(schema, cache, route) {
|
|
140
|
+
const response = {};
|
|
141
|
+
let any = false;
|
|
142
|
+
for (const rawMethod of Object.keys(schema)) {
|
|
143
|
+
const method = rawMethod.toLowerCase();
|
|
144
|
+
if (method === 'coerce')
|
|
145
|
+
continue;
|
|
146
|
+
const m = schema[rawMethod] ?? {};
|
|
147
|
+
const responseSchemas = m.response;
|
|
148
|
+
if (!responseSchemas)
|
|
149
|
+
continue;
|
|
150
|
+
const byStatus = {};
|
|
151
|
+
for (const statusKey of Object.keys(responseSchemas)) {
|
|
152
|
+
if (!STATUS_CODE_KEY.test(statusKey) &&
|
|
153
|
+
!STATUS_CLASS_KEY.test(statusKey)) {
|
|
154
|
+
throw new Error(`Invalid response schema key "${statusKey}" for ` +
|
|
155
|
+
`${rawMethod.toUpperCase()}${route ? ` ${route}` : ''}: ` +
|
|
156
|
+
'use a status code ("200") or a status class ("2xx").');
|
|
157
|
+
}
|
|
158
|
+
byStatus[statusKey] = compileSlot(responseSchemas[statusKey], 'body', cache);
|
|
159
|
+
any = true;
|
|
160
|
+
}
|
|
161
|
+
response[method] = byStatus;
|
|
162
|
+
}
|
|
163
|
+
return any ? response : undefined;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Compiles a single slot schema into a `CompiledValidator`, consulting the
|
|
167
|
+
* cache by identity first.
|
|
168
|
+
*/
|
|
169
|
+
function compileSlot(slotSchema, slot, cache) {
|
|
170
|
+
const adapter = detectAdapter(slotSchema);
|
|
171
|
+
if (adapter.cacheable?.(slotSchema) === false) {
|
|
172
|
+
// Semantics that the structural identity cannot capture (refinements,
|
|
173
|
+
// self-coercion) — compile fresh so no other route can reuse this
|
|
174
|
+
// validator's behavior.
|
|
175
|
+
return adapter.compile(slotSchema, slot);
|
|
176
|
+
}
|
|
177
|
+
const identity = adapter.identity(slotSchema);
|
|
178
|
+
const cached = cache.get(identity);
|
|
179
|
+
if (cached)
|
|
180
|
+
return cached;
|
|
181
|
+
const compiled = adapter.compile(slotSchema, slot);
|
|
182
|
+
cache.set(identity, compiled);
|
|
183
|
+
return compiled;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Clears the shared cache (dev hot reload). The next compile pass repopulates
|
|
187
|
+
* it wholesale.
|
|
188
|
+
*/
|
|
189
|
+
export function clearValidatorCache() {
|
|
190
|
+
validatorCache.clear();
|
|
191
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The validation error system — structured `ValidationError` + mode-gated
|
|
3
|
+
* renderers.
|
|
4
|
+
*
|
|
5
|
+
* `ValidationError` extends `HTTPError` (status 422) and carries structured
|
|
6
|
+
* `ValidationIssue[]` per slot. Renders RFC 9457 Problem Details by default;
|
|
7
|
+
* dev shows full issues, production strips internals. A custom
|
|
8
|
+
* `errorRenderer` overrides rendering. Production bodies never leak stacks or
|
|
9
|
+
* schema internals.
|
|
10
|
+
*/
|
|
11
|
+
import { HTTPError } from '../errors/http-error.js';
|
|
12
|
+
import type { ValidationIssue, ValidationResult, ValidatorConfig, ValidationSlot } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* A structured validation error thrown when request validation fails.
|
|
15
|
+
*
|
|
16
|
+
* Extends `HTTPError` with status 422. Carries the failing slot and
|
|
17
|
+
* normalized issues. Enters the `onError` pipeline; if no user hook
|
|
18
|
+
* handles it, the framework renders an RFC 9457 response.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ValidationError extends HTTPError {
|
|
21
|
+
readonly name = "ValidationError";
|
|
22
|
+
readonly status: number;
|
|
23
|
+
/** The primary request slot that failed validation. */
|
|
24
|
+
readonly slot: ValidationSlot | 'response';
|
|
25
|
+
/** Normalized field-level issues (all slots combined). */
|
|
26
|
+
readonly issues: ValidationIssue[];
|
|
27
|
+
/** Per-slot grouping of issues, when available. */
|
|
28
|
+
readonly errorsBySlot?: Record<string, ValidationIssue[]>;
|
|
29
|
+
constructor(slot: ValidationSlot | 'response', issues: ValidationIssue[], options?: ErrorOptions & {
|
|
30
|
+
errorsBySlot?: Record<string, ValidationIssue[]>;
|
|
31
|
+
/** Custom status code; defaults to 422 (ValidatorConfig.status). */
|
|
32
|
+
status?: number;
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* Creates a `ValidationError` from a failed `ValidationResult`.
|
|
36
|
+
*/
|
|
37
|
+
static from(slot: ValidationSlot | 'response', result: ValidationResult): ValidationError | null;
|
|
38
|
+
/**
|
|
39
|
+
* Renders this error into an RFC 9457 Problem Details response.
|
|
40
|
+
*
|
|
41
|
+
* Dev mode includes full issue details; production strips internal path
|
|
42
|
+
* information. A custom `errorRenderer` takes precedence when provided.
|
|
43
|
+
*/
|
|
44
|
+
toResponse(isDev: boolean, config?: ValidatorConfig): Response;
|
|
45
|
+
}
|
|
46
|
+
/** Flattens a `ValidationResult` failure into per-slot `ValidationError`s. */
|
|
47
|
+
export declare function toValidationErrors(result: ValidationResult, slot: string): ValidationError[];
|
|
48
|
+
export interface RenderContext {
|
|
49
|
+
status: number;
|
|
50
|
+
/** Whether to include dev diagnostics (stack/path detail). */
|
|
51
|
+
isDev: boolean;
|
|
52
|
+
/** The slot that produced the error (request) or 'response' (enforce). */
|
|
53
|
+
slot?: ValidationSlot | 'response';
|
|
54
|
+
/** Per-slot issues for request validation (all failing slots). When
|
|
55
|
+
* present, the plain renderer emits one key per slot instead of
|
|
56
|
+
* collapsing every issue under a single slot name. */
|
|
57
|
+
errorsBySlot?: Record<string, ValidationIssue[]>;
|
|
58
|
+
/** The validator config (mode + custom renderer). */
|
|
59
|
+
config: ValidatorConfig;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Renders a failed `ValidationResult` into a `Response`.
|
|
63
|
+
*
|
|
64
|
+
* A custom `errorRenderer` fully controls the body. `problem+json` emits the
|
|
65
|
+
* RFC 9457 shape (path/message only); `plain` emits `{ errors: { slot: issues } }`.
|
|
66
|
+
* Production emits only `path`/`message` (and `code`) — no stacks, source
|
|
67
|
+
* paths, or schema internals.
|
|
68
|
+
*/
|
|
69
|
+
export declare function renderValidationError(result: ValidationResult, ctx: RenderContext): Response;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The validation error system — structured `ValidationError` + mode-gated
|
|
3
|
+
* renderers.
|
|
4
|
+
*
|
|
5
|
+
* `ValidationError` extends `HTTPError` (status 422) and carries structured
|
|
6
|
+
* `ValidationIssue[]` per slot. Renders RFC 9457 Problem Details by default;
|
|
7
|
+
* dev shows full issues, production strips internals. A custom
|
|
8
|
+
* `errorRenderer` overrides rendering. Production bodies never leak stacks or
|
|
9
|
+
* schema internals.
|
|
10
|
+
*/
|
|
11
|
+
import { HTTPError, renderHTTPError } from '../errors/http-error.js';
|
|
12
|
+
/**
|
|
13
|
+
* A structured validation error thrown when request validation fails.
|
|
14
|
+
*
|
|
15
|
+
* Extends `HTTPError` with status 422. Carries the failing slot and
|
|
16
|
+
* normalized issues. Enters the `onError` pipeline; if no user hook
|
|
17
|
+
* handles it, the framework renders an RFC 9457 response.
|
|
18
|
+
*/
|
|
19
|
+
export class ValidationError extends HTTPError {
|
|
20
|
+
name = 'ValidationError';
|
|
21
|
+
status;
|
|
22
|
+
/** The primary request slot that failed validation. */
|
|
23
|
+
slot;
|
|
24
|
+
/** Normalized field-level issues (all slots combined). */
|
|
25
|
+
issues;
|
|
26
|
+
/** Per-slot grouping of issues, when available. */
|
|
27
|
+
errorsBySlot;
|
|
28
|
+
constructor(slot, issues, options) {
|
|
29
|
+
const summary = issues.length === 1
|
|
30
|
+
? issues[0].message
|
|
31
|
+
: `${issues.length} validation errors`;
|
|
32
|
+
const status = options?.status ?? 422;
|
|
33
|
+
super(status, `${slot}: ${summary}`, options);
|
|
34
|
+
this.status = status;
|
|
35
|
+
this.slot = slot;
|
|
36
|
+
this.issues = issues;
|
|
37
|
+
this.errorsBySlot = options?.errorsBySlot;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a `ValidationError` from a failed `ValidationResult`.
|
|
41
|
+
*/
|
|
42
|
+
static from(slot, result) {
|
|
43
|
+
if (result.success)
|
|
44
|
+
return null;
|
|
45
|
+
return new ValidationError(slot, result.issues);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Renders this error into an RFC 9457 Problem Details response.
|
|
49
|
+
*
|
|
50
|
+
* Dev mode includes full issue details; production strips internal path
|
|
51
|
+
* information. A custom `errorRenderer` takes precedence when provided.
|
|
52
|
+
*/
|
|
53
|
+
toResponse(isDev, config = {}) {
|
|
54
|
+
if (config.errorRenderer) {
|
|
55
|
+
return config.errorRenderer({ success: false, issues: this.issues }, { slot: this.slot, status: this.status });
|
|
56
|
+
}
|
|
57
|
+
const format = config.errorFormat ?? 'problem+json';
|
|
58
|
+
// Use stored errorsBySlot if available, otherwise group by this.slot.
|
|
59
|
+
const grouped = this.errorsBySlot ?? { [this.slot]: this.issues };
|
|
60
|
+
if (format === 'problem+json') {
|
|
61
|
+
// Delegate to the single RFC 9457 renderer so ValidationError and
|
|
62
|
+
// HTTPError share one body shape (this adds the standard `detail`
|
|
63
|
+
// member alongside the per-slot `errors` grouping).
|
|
64
|
+
return renderHTTPError(this, isDev, {
|
|
65
|
+
title: 'Validation Error',
|
|
66
|
+
errors: grouped,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// Plain format fallback.
|
|
70
|
+
const body = { errors: grouped };
|
|
71
|
+
if (isDev) {
|
|
72
|
+
body.dev = true;
|
|
73
|
+
}
|
|
74
|
+
return new Response(JSON.stringify(body), {
|
|
75
|
+
status: this.status,
|
|
76
|
+
headers: { 'content-type': 'application/json' },
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Flattens a `ValidationResult` failure into per-slot `ValidationError`s. */
|
|
81
|
+
export function toValidationErrors(result, slot) {
|
|
82
|
+
if (result.success)
|
|
83
|
+
return [];
|
|
84
|
+
return [new ValidationError(slot, result.issues)];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Renders a failed `ValidationResult` into a `Response`.
|
|
88
|
+
*
|
|
89
|
+
* A custom `errorRenderer` fully controls the body. `problem+json` emits the
|
|
90
|
+
* RFC 9457 shape (path/message only); `plain` emits `{ errors: { slot: issues } }`.
|
|
91
|
+
* Production emits only `path`/`message` (and `code`) — no stacks, source
|
|
92
|
+
* paths, or schema internals.
|
|
93
|
+
*/
|
|
94
|
+
export function renderValidationError(result, ctx) {
|
|
95
|
+
if (result.success) {
|
|
96
|
+
throw new Error('[burger-api] renderValidationError called with a successful ' +
|
|
97
|
+
'validation result; it only renders failures.');
|
|
98
|
+
}
|
|
99
|
+
if (ctx.config.errorRenderer) {
|
|
100
|
+
return ctx.config.errorRenderer(result, {
|
|
101
|
+
slot: ctx.slot,
|
|
102
|
+
status: ctx.status,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const issues = result.issues;
|
|
106
|
+
if (ctx.config.errorFormat === 'problem+json') {
|
|
107
|
+
return new Response(JSON.stringify({
|
|
108
|
+
type: 'about:blank',
|
|
109
|
+
title: 'Validation Error',
|
|
110
|
+
status: ctx.status,
|
|
111
|
+
detail: 'Request validation failed.',
|
|
112
|
+
errors: issues.map((i) => ({
|
|
113
|
+
path: i.path,
|
|
114
|
+
message: i.message,
|
|
115
|
+
})),
|
|
116
|
+
}), {
|
|
117
|
+
status: ctx.status,
|
|
118
|
+
headers: { 'content-type': 'application/problem+json' },
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
// Default plain format. Only normalized issue data
|
|
122
|
+
// (path/message/code) is emitted.
|
|
123
|
+
const body = {
|
|
124
|
+
errors: ctx.errorsBySlot
|
|
125
|
+
? ctx.errorsBySlot
|
|
126
|
+
: ctx.slot
|
|
127
|
+
? { [ctx.slot]: issues }
|
|
128
|
+
: { message: issues[0]?.message ?? 'Validation failed' },
|
|
129
|
+
};
|
|
130
|
+
if (ctx.isDev) {
|
|
131
|
+
body.dev = true;
|
|
132
|
+
}
|
|
133
|
+
return new Response(JSON.stringify(body), {
|
|
134
|
+
status: ctx.status,
|
|
135
|
+
headers: { 'content-type': 'application/json' },
|
|
136
|
+
});
|
|
137
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation module for BurgerAPI.
|
|
3
|
+
*
|
|
4
|
+
* Precompiled request validation (identity-cached per schema), opt-in
|
|
5
|
+
* coercion, and RFC 9457 error rendering.
|
|
6
|
+
*/
|
|
7
|
+
export { compileRouteSchema, validatorCache, clearValidatorCache } from './compiler.js';
|
|
8
|
+
export { createValidationHook } from './validator.js';
|
|
9
|
+
export { ValidationError, renderValidationError, toValidationErrors, } from './error.js';
|
|
10
|
+
export type { RenderContext } from './error.js';
|
|
11
|
+
export { ValidatorCache } from './cache.js';
|
|
12
|
+
export { registerAdapter, detectAdapter, } from './adapter.js';
|
|
13
|
+
export type { MethodSchema, RouteSchema } from '../types/index.js';
|
|
14
|
+
export type { ValidatorAdapter } from './adapter.js';
|
|
15
|
+
export { buildPlan, apply } from './coerce.js';
|
|
16
|
+
export type { SchemaInput, ValidatorKind, ValidationSlot, ValidationIssue, ValidatorConfig, CompiledValidator, CompiledRouteValidators, CoercionOp, CoercionPlan, StandardSchemaV1, StandardSchemaV1Result, } from './types.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation module for BurgerAPI.
|
|
3
|
+
*
|
|
4
|
+
* Precompiled request validation (identity-cached per schema), opt-in
|
|
5
|
+
* coercion, and RFC 9457 error rendering.
|
|
6
|
+
*/
|
|
7
|
+
export { compileRouteSchema, validatorCache, clearValidatorCache } from './compiler.js';
|
|
8
|
+
export { createValidationHook } from './validator.js';
|
|
9
|
+
export { ValidationError, renderValidationError, toValidationErrors, } from './error.js';
|
|
10
|
+
export { ValidatorCache } from './cache.js';
|
|
11
|
+
export { registerAdapter, detectAdapter, } from './adapter.js';
|
|
12
|
+
export { buildPlan, apply } from './coerce.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The response validator — validates a handler's return against declared
|
|
3
|
+
* per-status schemas.
|
|
4
|
+
*
|
|
5
|
+
* Selects the schema by status (exact code, then class `2xx`), validates the
|
|
6
|
+
* body, and applies `dev` (observe/log) vs `enforce` (safe 500/422). Runs
|
|
7
|
+
* after the handler in the same request flow; invisible to apps that declare
|
|
8
|
+
* no `response` schema.
|
|
9
|
+
*/
|
|
10
|
+
import type { CompiledRouteValidators, ValidatorConfig } from './types.js';
|
|
11
|
+
export interface ResponseValidationOutcome {
|
|
12
|
+
ok: boolean;
|
|
13
|
+
/** Safe error body (no internals) when enforce fails. */
|
|
14
|
+
errorResponse?: Response;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Validates a handler result against the `response` schema for `status`.
|
|
18
|
+
*
|
|
19
|
+
* @param validators - the route's compiled validators.
|
|
20
|
+
* @param status - the HTTP status of the handler response.
|
|
21
|
+
* @param value - the response body value to validate.
|
|
22
|
+
* @param config - the validator config (mode + enforce status).
|
|
23
|
+
* @param isDev - whether to run in dev mode (observe-only).
|
|
24
|
+
*/
|
|
25
|
+
export declare function validateResponse(validators: CompiledRouteValidators, method: string, status: number, value: unknown, config: ValidatorConfig, isDev: boolean): ResponseValidationOutcome;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The response validator — validates a handler's return against declared
|
|
3
|
+
* per-status schemas.
|
|
4
|
+
*
|
|
5
|
+
* Selects the schema by status (exact code, then class `2xx`), validates the
|
|
6
|
+
* body, and applies `dev` (observe/log) vs `enforce` (safe 500/422). Runs
|
|
7
|
+
* after the handler in the same request flow; invisible to apps that declare
|
|
8
|
+
* no `response` schema.
|
|
9
|
+
*/
|
|
10
|
+
import { renderValidationError } from './error.js';
|
|
11
|
+
import { HTTPError, renderHTTPError } from '../errors/http-error.js';
|
|
12
|
+
/** Resolves the response validator for a status (exact, then class). */
|
|
13
|
+
function selectResponseValidator(validators, method, status) {
|
|
14
|
+
// The response map only has lowercase-method keys; the caller's runtime
|
|
15
|
+
// method string may be any case, so index via the widened record.
|
|
16
|
+
const methodResponses = validators.response?.[method];
|
|
17
|
+
if (!methodResponses)
|
|
18
|
+
return undefined;
|
|
19
|
+
if (methodResponses[String(status)])
|
|
20
|
+
return methodResponses[String(status)];
|
|
21
|
+
const cls = `${Math.floor(status / 100)}xx`;
|
|
22
|
+
if (methodResponses[cls])
|
|
23
|
+
return methodResponses[cls];
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validates a handler result against the `response` schema for `status`.
|
|
28
|
+
*
|
|
29
|
+
* @param validators - the route's compiled validators.
|
|
30
|
+
* @param status - the HTTP status of the handler response.
|
|
31
|
+
* @param value - the response body value to validate.
|
|
32
|
+
* @param config - the validator config (mode + enforce status).
|
|
33
|
+
* @param isDev - whether to run in dev mode (observe-only).
|
|
34
|
+
*/
|
|
35
|
+
export function validateResponse(validators, method, status, value, config, isDev) {
|
|
36
|
+
const validator = selectResponseValidator(validators, method, status);
|
|
37
|
+
if (!validator) {
|
|
38
|
+
return { ok: true };
|
|
39
|
+
}
|
|
40
|
+
const result = validator.validate(value);
|
|
41
|
+
if (result.success) {
|
|
42
|
+
return { ok: true };
|
|
43
|
+
}
|
|
44
|
+
const mode = config.responseValidation ?? 'dev';
|
|
45
|
+
if (mode === 'off') {
|
|
46
|
+
return { ok: true };
|
|
47
|
+
}
|
|
48
|
+
if (mode === 'dev') {
|
|
49
|
+
// Observe only: log and pass the handler response through untouched.
|
|
50
|
+
if (isDev) {
|
|
51
|
+
console.warn(`[burger-api] Response validation mismatch (status ${status}):`, result.issues);
|
|
52
|
+
}
|
|
53
|
+
return { ok: true };
|
|
54
|
+
}
|
|
55
|
+
// enforce: the handler broke its own contract — a server bug. Always
|
|
56
|
+
// log it; answer with RFC 9457 Problem Details: issue details in dev,
|
|
57
|
+
// a generic 500 in production (never leak schema internals).
|
|
58
|
+
const enforceStatus = status === 422 ? 422 : 500;
|
|
59
|
+
console.error(`[burger-api] Response validation failed (status ${status}):`, result.issues);
|
|
60
|
+
if (config.errorRenderer) {
|
|
61
|
+
return {
|
|
62
|
+
ok: false,
|
|
63
|
+
errorResponse: renderValidationError(result, {
|
|
64
|
+
status: enforceStatus,
|
|
65
|
+
isDev,
|
|
66
|
+
slot: 'response',
|
|
67
|
+
config,
|
|
68
|
+
}),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
// No stack: the synthetic error's trace is noise. Dev adds the issues.
|
|
72
|
+
const errorResponse = renderHTTPError(new HTTPError(enforceStatus, 'Response validation failed'), false, isDev
|
|
73
|
+
? {
|
|
74
|
+
detail: 'Response validation failed',
|
|
75
|
+
errors: { response: result.issues },
|
|
76
|
+
}
|
|
77
|
+
: undefined);
|
|
78
|
+
return { ok: false, errorResponse };
|
|
79
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central type definitions for the validation subsystem.
|
|
3
|
+
*
|
|
4
|
+
* Types only — no runtime logic, no adapter implementations, no I/O.
|
|
5
|
+
*/
|
|
6
|
+
import type { z } from 'zod';
|
|
7
|
+
import type { LowercaseHTTPMethod } from '../utils/routing.js';
|
|
8
|
+
/**
|
|
9
|
+
* Minimal structural type for a Standard Schema V1 validator — the common
|
|
10
|
+
* shape shared by libraries like Valibot and ArkType so they work with
|
|
11
|
+
* BurgerAPI. Only the stable `~standard` contract is used. `vendor` names the
|
|
12
|
+
* producing library (e.g. "valibot", "arktype", "zod").
|
|
13
|
+
*/
|
|
14
|
+
export interface StandardSchemaV1 {
|
|
15
|
+
readonly '~standard': {
|
|
16
|
+
readonly version: 1;
|
|
17
|
+
readonly vendor: string;
|
|
18
|
+
readonly validate: (value: unknown) => StandardSchemaV1Result | Promise<StandardSchemaV1Result>;
|
|
19
|
+
/** True when the schema transforms (coerces) its input during validate. */
|
|
20
|
+
readonly coercible?: boolean;
|
|
21
|
+
readonly types?: {
|
|
22
|
+
readonly input?: unknown;
|
|
23
|
+
readonly output?: unknown;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export type StandardSchemaV1Result = StandardSchemaV1SuccessResult | StandardSchemaV1FailureResult;
|
|
28
|
+
export interface StandardSchemaV1SuccessResult {
|
|
29
|
+
readonly value: unknown;
|
|
30
|
+
readonly issues?: undefined;
|
|
31
|
+
}
|
|
32
|
+
export interface StandardSchemaV1FailureResult {
|
|
33
|
+
readonly issues: ReadonlyArray<StandardSchemaV1Issue>;
|
|
34
|
+
}
|
|
35
|
+
export interface StandardSchemaV1Issue {
|
|
36
|
+
readonly message: string;
|
|
37
|
+
readonly path?: ReadonlyArray<PropertyKey | {
|
|
38
|
+
readonly key: PropertyKey;
|
|
39
|
+
}>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Any value accepted in a schema slot. Zod is the default provider; Standard
|
|
43
|
+
* Schema libraries are also accepted.
|
|
44
|
+
*/
|
|
45
|
+
export type SchemaInput = z.ZodTypeAny | StandardSchemaV1;
|
|
46
|
+
/** The five request slots that can carry a schema. */
|
|
47
|
+
export type ValidationSlot = 'params' | 'query' | 'headers' | 'cookies' | 'body';
|
|
48
|
+
/** The kinds of validator providers known to the adapter layer. */
|
|
49
|
+
export type ValidatorKind = 'zod' | 'standard';
|
|
50
|
+
/**
|
|
51
|
+
* A common result shape shared by every adapter, so Zod and other libraries
|
|
52
|
+
* report success or failure the same way.
|
|
53
|
+
*/
|
|
54
|
+
export type ValidationResult = {
|
|
55
|
+
success: true;
|
|
56
|
+
data: unknown;
|
|
57
|
+
} | {
|
|
58
|
+
success: false;
|
|
59
|
+
issues: ValidationIssue[];
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* A single field-level failure.
|
|
63
|
+
*/
|
|
64
|
+
export interface ValidationIssue {
|
|
65
|
+
path: (string | number)[];
|
|
66
|
+
message: string;
|
|
67
|
+
code?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The runtime unit produced when a schema is prepared: one reusable
|
|
71
|
+
* `validate` call plus metadata. Prepared once per unique identity before
|
|
72
|
+
* `serve()`.
|
|
73
|
+
*/
|
|
74
|
+
export interface CompiledValidator {
|
|
75
|
+
kind: ValidatorKind;
|
|
76
|
+
slot: ValidationSlot;
|
|
77
|
+
identity: string;
|
|
78
|
+
validate: (value: unknown) => ValidationResult;
|
|
79
|
+
/**
|
|
80
|
+
* True when the schema transforms (coerces) its own input during
|
|
81
|
+
* `validate` (e.g. Zod `z.coerce.*`, Valibot `v.coerce`, or a
|
|
82
|
+
* `~standard.coercible` schema). Framework coercion is skipped for these —
|
|
83
|
+
* pre-coercing would double-apply type conversion.
|
|
84
|
+
*/
|
|
85
|
+
coercible: boolean;
|
|
86
|
+
}
|
|
87
|
+
/** Coercion operations supported by the coercer. */
|
|
88
|
+
export type CoercionOp = 'number' | 'boolean' | 'date' | 'none';
|
|
89
|
+
/**
|
|
90
|
+
* A per-slot, per-field plan built when the route is set up. Applied at
|
|
91
|
+
* runtime with no extra checks on each request.
|
|
92
|
+
*/
|
|
93
|
+
export interface CoercionPlan {
|
|
94
|
+
slot: 'query' | 'params' | 'headers' | 'cookies';
|
|
95
|
+
fields: Record<string, CoercionOp>;
|
|
96
|
+
/**
|
|
97
|
+
* Array fields (`z.array(...)`) → element op. A single value is wrapped
|
|
98
|
+
* into a one-element array; each element is coerced with the op.
|
|
99
|
+
*/
|
|
100
|
+
arrays?: Record<string, CoercionOp>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Per-status-code map of response validators.
|
|
104
|
+
*/
|
|
105
|
+
export type ResponseSchema = Record<string, SchemaInput>;
|
|
106
|
+
/**
|
|
107
|
+
* Configuration surfaced from `ServerOptions` into the compilation step.
|
|
108
|
+
* Defaults: status 422, errorFormat 'problem+json' (RFC 9457),
|
|
109
|
+
* responseValidation 'dev'.
|
|
110
|
+
*/
|
|
111
|
+
export interface ValidatorConfig {
|
|
112
|
+
/** Opt-in string→type coercion. Default false. */
|
|
113
|
+
coerce?: boolean;
|
|
114
|
+
/** Response validation mode. Default 'dev'. */
|
|
115
|
+
responseValidation?: 'off' | 'dev' | 'enforce';
|
|
116
|
+
/** Error body shape. Default 'problem+json' (RFC 9457). */
|
|
117
|
+
errorFormat?: 'plain' | 'problem+json';
|
|
118
|
+
/** Default HTTP status for validation errors. Default 422. */
|
|
119
|
+
status?: number;
|
|
120
|
+
/** Custom renderer that fully controls the error body. */
|
|
121
|
+
errorRenderer?: (result: ValidationResult, ctx: {
|
|
122
|
+
slot?: ValidationSlot | 'response';
|
|
123
|
+
status: number;
|
|
124
|
+
}) => Response;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The per-route bundle of prepared slot validators + conversion plans +
|
|
128
|
+
* response validators, attached to the route when it is prepared.
|
|
129
|
+
* Method keys are lowercase (the form the compiler emits and the validator
|
|
130
|
+
* looks up at request time).
|
|
131
|
+
*/
|
|
132
|
+
export interface CompiledRouteValidators {
|
|
133
|
+
methods: Partial<Record<LowercaseHTTPMethod, {
|
|
134
|
+
params?: CompiledValidator;
|
|
135
|
+
query?: CompiledValidator;
|
|
136
|
+
headers?: CompiledValidator;
|
|
137
|
+
cookies?: CompiledValidator;
|
|
138
|
+
body?: CompiledValidator;
|
|
139
|
+
coercion?: {
|
|
140
|
+
query?: CoercionPlan;
|
|
141
|
+
params?: CoercionPlan;
|
|
142
|
+
headers?: CoercionPlan;
|
|
143
|
+
cookies?: CoercionPlan;
|
|
144
|
+
};
|
|
145
|
+
}>>;
|
|
146
|
+
/** Per-method, per-status-code map of response validators. */
|
|
147
|
+
response?: Partial<Record<LowercaseHTTPMethod, Record<string, CompiledValidator>>>;
|
|
148
|
+
}
|