@fuzdev/fuz_app 0.153.0 → 0.155.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/dist/actions/CLAUDE.md +2 -2
- package/dist/actions/action_event.d.ts.map +1 -1
- package/dist/actions/action_event.js +14 -14
- package/dist/actions/peer_ping.js +3 -3
- package/dist/actions/perform_action.d.ts +12 -10
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +19 -16
- package/dist/auth/cell_actions.d.ts +6 -4
- package/dist/auth/cell_actions.d.ts.map +1 -1
- package/dist/auth/cell_actions.js +10 -9
- package/dist/env/env_schemas.d.ts +41 -0
- package/dist/env/env_schemas.d.ts.map +1 -0
- package/dist/env/env_schemas.js +55 -0
- package/dist/env/load.d.ts +23 -15
- package/dist/env/load.d.ts.map +1 -1
- package/dist/env/load.js +38 -22
- package/dist/http/CLAUDE.md +14 -8
- package/dist/http/schema_helpers.d.ts +102 -23
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +241 -38
- package/dist/http/surface.d.ts +20 -11
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +59 -32
- package/dist/primitive_schemas.d.ts +13 -4
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas.js +13 -4
- package/dist/schema_issues.d.ts +96 -0
- package/dist/schema_issues.d.ts.map +1 -0
- package/dist/schema_issues.js +110 -0
- package/dist/schema_meta.d.ts +38 -13
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +63 -13
- package/dist/sensitivity.d.ts +34 -1
- package/dist/sensitivity.d.ts.map +1 -1
- package/dist/sensitivity.js +32 -2
- package/dist/server/app_server.d.ts +6 -5
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +0 -1
- package/dist/server/env.d.ts +52 -30
- package/dist/server/env.d.ts.map +1 -1
- package/dist/server/env.js +38 -43
- package/dist/testing/CLAUDE.md +23 -10
- package/dist/testing/adversarial_404.d.ts +15 -0
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +26 -19
- package/dist/testing/adversarial_input_cases.d.ts.map +1 -1
- package/dist/testing/adversarial_input_cases.js +2 -2
- package/dist/testing/app_server.js +2 -2
- package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_crud.js +7 -5
- package/dist/testing/cross_backend/identity_parity.js +2 -2
- package/dist/testing/cross_backend/standard.d.ts +3 -2
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/daemon_info.d.ts +7 -2
- package/dist/testing/daemon_info.d.ts.map +1 -1
- package/dist/testing/daemon_info.js +8 -3
- package/dist/testing/data_exposure.d.ts +43 -9
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +151 -35
- package/dist/testing/schema_generators.d.ts +21 -9
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +52 -47
- package/dist/testing/stubs.d.ts +2 -2
- package/dist/testing/stubs.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/env/load.js
CHANGED
|
@@ -1,43 +1,45 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generic environment loading from
|
|
2
|
+
* Generic environment loading from `@fuzdev/fuz_schema` object schemas.
|
|
3
3
|
*
|
|
4
|
-
* Provides `load_env
|
|
5
|
-
* Apps handle error messages themselves
|
|
4
|
+
* Provides `load_env`, which reads each key of an object schema with a
|
|
5
|
+
* getter and validates the values. Apps handle error messages themselves
|
|
6
|
+
* (they're always app-specific).
|
|
6
7
|
*
|
|
7
8
|
* @module
|
|
8
9
|
*/
|
|
9
|
-
import {
|
|
10
|
+
import { get_schema_entries } from '@fuzdev/fuz_schema/introspect.ts';
|
|
11
|
+
import { format_issue, parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
10
12
|
/**
|
|
11
13
|
* Error thrown when environment validation fails.
|
|
12
14
|
*
|
|
13
15
|
* Contains structured information for apps to format their own error messages.
|
|
14
16
|
*/
|
|
15
17
|
export class EnvValidationError extends Error {
|
|
16
|
-
/** The raw env values that were read
|
|
18
|
+
/** The raw env values that were read, every key of the schema, unset ones as `undefined`. */
|
|
17
19
|
raw;
|
|
18
|
-
/** The
|
|
19
|
-
|
|
20
|
+
/** The validation issues, which hold no env value, only the keys in their paths. */
|
|
21
|
+
issues;
|
|
20
22
|
/** True if every env var was undefined (nothing loaded). */
|
|
21
23
|
all_undefined;
|
|
22
|
-
constructor(raw,
|
|
24
|
+
constructor(raw, issues) {
|
|
23
25
|
super('Environment validation failed');
|
|
24
26
|
this.raw = raw;
|
|
25
|
-
this.
|
|
27
|
+
this.issues = issues;
|
|
26
28
|
this.all_undefined = Object.values(raw).every((v) => v === undefined);
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
|
-
* Format
|
|
31
|
+
* Format the validation issues as human-readable strings.
|
|
30
32
|
*
|
|
31
|
-
* @returns array of formatted issue strings like `"PORT:
|
|
33
|
+
* @returns array of formatted issue strings like `"PORT: expected decimal digits, received string"`
|
|
32
34
|
*/
|
|
33
35
|
format_issues() {
|
|
34
|
-
return this.
|
|
36
|
+
return this.issues.map(format_issue);
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
/**
|
|
38
40
|
* Log formatted env validation issues to stderr.
|
|
39
41
|
*
|
|
40
|
-
* Handles the common case: labels each
|
|
42
|
+
* Handles the common case: labels each issue with an optional prefix.
|
|
41
43
|
* Callers who want app-specific "getting started" instructions should check
|
|
42
44
|
* `error.all_undefined` before calling this.
|
|
43
45
|
*
|
|
@@ -57,21 +59,35 @@ export const log_env_validation_error = (error, label) => {
|
|
|
57
59
|
}
|
|
58
60
|
};
|
|
59
61
|
/**
|
|
60
|
-
* Load and validate env vars against a
|
|
62
|
+
* Load and validate env vars against a `@fuzdev/fuz_schema` object schema.
|
|
61
63
|
*
|
|
62
|
-
*
|
|
64
|
+
* Reads every key of the schema's entries with `get_env`. An unset var is
|
|
65
|
+
* left out of the object parsed, not given as `undefined`, so it reads as a
|
|
66
|
+
* missing key: a `pipe` that starts with an `optional` runs none of its
|
|
67
|
+
* steps for it, as it would for an absent key of any object. `raw` still
|
|
68
|
+
* lists it, as `undefined`.
|
|
69
|
+
*
|
|
70
|
+
* @param schema - an object schema (`object`, `strip_object`, ..., under any wrappers) of the expected env vars
|
|
63
71
|
* @param get_env - function to read an env var by key
|
|
64
72
|
* @returns validated env object
|
|
65
|
-
* @throws
|
|
73
|
+
* @throws TypeError if `schema` is not an object schema
|
|
74
|
+
* @throws EnvValidationError if validation fails
|
|
66
75
|
*/
|
|
67
76
|
export const load_env = (schema, get_env) => {
|
|
77
|
+
const entries = get_schema_entries(schema);
|
|
78
|
+
if (!entries)
|
|
79
|
+
throw new TypeError(`load_env requires an object schema, got '${schema.kind}'`);
|
|
68
80
|
const raw = {};
|
|
69
|
-
|
|
70
|
-
|
|
81
|
+
const present = {};
|
|
82
|
+
for (const key in entries) {
|
|
83
|
+
const value = get_env(key);
|
|
84
|
+
raw[key] = value;
|
|
85
|
+
if (value !== undefined)
|
|
86
|
+
present[key] = value;
|
|
71
87
|
}
|
|
72
|
-
const result = schema
|
|
73
|
-
if (!result.
|
|
74
|
-
throw new EnvValidationError(raw, result.
|
|
88
|
+
const result = parse(schema, present);
|
|
89
|
+
if (!result.ok) {
|
|
90
|
+
throw new EnvValidationError(raw, result.issues);
|
|
75
91
|
}
|
|
76
|
-
return result.
|
|
92
|
+
return result.value;
|
|
77
93
|
};
|
package/dist/http/CLAUDE.md
CHANGED
|
@@ -222,7 +222,7 @@ confirmation.
|
|
|
222
222
|
|
|
223
223
|
## Schema Helpers
|
|
224
224
|
|
|
225
|
-
`http/schema_helpers.ts` is the canonical home for shared Zod
|
|
225
|
+
`http/schema_helpers.ts` is the canonical home for shared schema introspection (Zod, and fuz_schema where a helper takes either)
|
|
226
226
|
— extracted to break a circular dependency between `http/route_spec.ts`
|
|
227
227
|
(input validation) and `http/surface.ts` (surface generation).
|
|
228
228
|
|
|
@@ -233,14 +233,14 @@ only imports and re-uses them for generation logic.
|
|
|
233
233
|
|
|
234
234
|
Key helpers:
|
|
235
235
|
|
|
236
|
-
- `is_null_schema(schema)` — `instanceof z.ZodNull` (not parse-null, to avoid false positives from `z.nullable(z.string())`)
|
|
237
|
-
- `is_void_schema(schema)` — `instanceof z.ZodVoid`; a `z.void()` input declares a parameterless RPC method
|
|
236
|
+
- `is_null_schema(schema)` — `instanceof z.ZodNull`, or a fuz_schema `literal(null)` (a kind check, not parse-null, to avoid false positives from `z.nullable(z.string())`)
|
|
237
|
+
- `is_void_schema(schema)` — `instanceof z.ZodVoid`; a `z.void()` input declares a parameterless RPC method (false for any fuz_schema schema, which has no void kind)
|
|
238
238
|
- `to_void_params(raw_params)` — reads absent, `null`, and `{}` params of a `z.void()` input as the no-arg call (`undefined`), passing any other shape through for `z.void()` to refuse — the twin of the Rust spine's `require_void_params`
|
|
239
|
-
- `to_input_params(input, raw_params)` — the one params normalizer every receiving end runs before
|
|
239
|
+
- `to_input_params(input, raw_params)` — the one params normalizer every receiving end runs before the input parse (`parse_any`): `to_void_params` for a `z.void()` input, else absent/`null` → `{}`; used by both the server dispatch core (`perform_action`) and the peer receive path (`ActionDispatcher`)
|
|
240
240
|
- `json_has_own_proto_key(value)` — whether any object in a parsed JSON value has an own `__proto__` key, by an iterative walk (no recursion — `JSON.parse` nests deeper than the call stack); the dispatcher refuses such params with `ERROR_PARAMS_PROTO_KEY`. Twin of the Rust `fuz_http::json_has_own_proto_key`
|
|
241
|
-
- `safe_parse_dropping_unknown_keys(schema, value)` — the forward-compatible read of a remote-authored payload:
|
|
242
|
-
- `is_strict_object_schema(schema)` — detects `z.strictObject()` by checking `schema.def.catchall instanceof z.ZodNever`
|
|
243
|
-
- `schema_to_surface(schema)` — Zod → JSON Schema, with `$schema` and `default` keys stripped recursively (defaults may be non-deterministic; `$schema` is snapshot noise)
|
|
241
|
+
- `safe_parse_dropping_unknown_keys(schema, value)` — the forward-compatible read of a remote-authored payload, Zod or fuz_schema, returning `parse_any`'s `{ok, value}` / `{ok: false, issues}`: while every issue is an unknown key (`unknown_key_targets`), strips them from a copy and reparses — after the first parse that reports unknown keys, one schema-guided pass deletes every key a strict fuz_schema `object` doesn't name anywhere the schema reaches (entries, array items, record values, the `variant` option), as a fuz_schema parse reports at most a hundred issues; a key under a fuz_schema `union` is never stripped (the union fails as one issue of its own), and a later `pipe` stage is stripped only as reported — until nothing is left to strip, capped at `UNKNOWN_KEY_PASSES_MAX` passes (the last failure returned past it); any other issue still fails. A Zod union of strict objects reports the key and is stripped, a fuz_schema `union` reports one issue of its own and is not. Used for response `result`s (`ActionEvent`) and peer replies (`peer/ping`); matches serde's ignore-unknown-fields default on the Rust spine
|
|
242
|
+
- `is_strict_object_schema(schema)` — detects `z.strictObject()` by checking `schema.def.catchall instanceof z.ZodNever`, or a fuz_schema `object` (not `strip_object` / `loose_object`); a fuz_schema `pipe` is read through to its first schema when no stage is a `transform` (so a refined `object` reads strict), while any Zod `ZodPipe` — even `O.pipe(O)` with no transform — reads not strict
|
|
243
|
+
- `schema_to_surface(schema, {io?, source?, on_unrepresentable?}?)` — Zod or fuz_schema → JSON Schema (`z.toJSONSchema` or fuz_schema's `to_json_schema`, by `is_schema`), on the side `io` names (`'output'` by default), with `$schema` and `default` keys stripped recursively (defaults may be non-deterministic; `$schema` is snapshot noise). `null` for a null or void schema. A part JSON Schema can't say (an output-side transform, a `z.custom()`, a fuz_schema `check`) is left out or written as `{}` (`unrepresentable: 'any'`) and reported to `on_unrepresentable`; a schema with nothing describable (`{}` from a schema other than `z.unknown()` / `z.any()`) or one an emitter refuses outright throws, prefixed with `source` — so a root-level transform output (`z.unknown().transform(f)` included), `z.custom()` or `z.date()` fails server assembly. It never answers `null` for a failure, which would read as "no input" and drop the schema from every suite that reads the surface
|
|
244
244
|
- `middleware_applies(mw_path, route_path)` — Hono pattern matching: `'*'`, exact, `'/api/*'` prefix (handles `prefix.slice(0, -1)` so `/api/*` also matches the bare `/api`)
|
|
245
245
|
- `middleware_spec_applies(spec, route_path)` — the layer runs on the route: its `path` applies and none of its `carve_outs` does; what surface generation merges middleware errors by
|
|
246
246
|
- `merge_error_schemas(spec, middleware_errors?)` — the three-layer merge described above
|
|
@@ -263,7 +263,13 @@ policy invariants.
|
|
|
263
263
|
|
|
264
264
|
`generate_app_surface(options)` emits a `warning` diagnostic for every
|
|
265
265
|
input schema that's not strict (unknown keys silently strip under
|
|
266
|
-
`z.object()`),
|
|
266
|
+
`z.object()`), writes every schema through `schema_to_surface` — inputs,
|
|
267
|
+
params and query on the input side (what the server accepts, so a
|
|
268
|
+
`Username` transform keeps its bounds and pattern), outputs, error bodies and
|
|
269
|
+
event params on the output side — with an `info` diagnostic (category
|
|
270
|
+
`schema`, `source` naming the route or method and side) for each schema
|
|
271
|
+
part of which is left out or written as `{}`, throws naming the same source for one
|
|
272
|
+
that can't be written, runs the three-layer merge per route, derives `is_mutation`
|
|
267
273
|
and `transaction` from method/spec, and surfaces RPC methods with their
|
|
268
274
|
`RouteAuth` directly (same shape on both `ActionSpec.auth` and
|
|
269
275
|
`RouteSpec.auth`, no translation step).
|
|
@@ -11,14 +11,16 @@ import { z } from 'zod';
|
|
|
11
11
|
import type { RouteAuth } from './auth_shape.js';
|
|
12
12
|
import type { RouteMethod } from './route_spec.js';
|
|
13
13
|
import { type RateLimitKey, type RouteErrorSchemas } from './error_schemas.js';
|
|
14
|
+
import { type ParseAnyResult, type ValidationOutput, type ValidationSchema } from '../schema_issues.js';
|
|
14
15
|
/**
|
|
15
|
-
* Check if a schema is exactly `z.null()
|
|
16
|
+
* Check if a schema is exactly `z.null()`, or a `@fuzdev/fuz_schema`
|
|
17
|
+
* `literal(null)`.
|
|
16
18
|
*
|
|
17
|
-
*
|
|
18
|
-
* from `z.nullable(z.string())` or similar schemas that accept
|
|
19
|
-
* but also accept other values.
|
|
19
|
+
* Reads the schema's kind rather than parsing `null`, to avoid false
|
|
20
|
+
* positives from `z.nullable(z.string())` or similar schemas that accept
|
|
21
|
+
* null but also accept other values.
|
|
20
22
|
*/
|
|
21
|
-
export declare const is_null_schema: (schema:
|
|
23
|
+
export declare const is_null_schema: (schema: ValidationSchema) => boolean;
|
|
22
24
|
/**
|
|
23
25
|
* Check if a schema is exactly `z.void()`.
|
|
24
26
|
*
|
|
@@ -27,7 +29,7 @@ export declare const is_null_schema: (schema: z.ZodType) => boolean;
|
|
|
27
29
|
* Structured value), so `z.void()` is the correct schema for "no params"
|
|
28
30
|
* and the dispatcher maps absent params to `undefined` for these specs.
|
|
29
31
|
*/
|
|
30
|
-
export declare const is_void_schema: (schema:
|
|
32
|
+
export declare const is_void_schema: (schema: ValidationSchema) => boolean;
|
|
31
33
|
/**
|
|
32
34
|
* Normalize the raw `params` of a `z.void()` input: an absent `params`, an
|
|
33
35
|
* empty object, and the `null` a GET `?params=null` parses to are all the
|
|
@@ -56,7 +58,7 @@ export declare const to_void_params: (raw_params: unknown) => unknown;
|
|
|
56
58
|
*
|
|
57
59
|
* @param input - the action's input schema
|
|
58
60
|
* @param raw_params - the call's `params` as parsed off the wire
|
|
59
|
-
* @returns the value
|
|
61
|
+
* @returns the value the input parse (`parse_any`) reads
|
|
60
62
|
*/
|
|
61
63
|
export declare const to_input_params: (input: z.ZodType, raw_params: unknown) => unknown;
|
|
62
64
|
/**
|
|
@@ -81,43 +83,120 @@ export declare const to_input_params: (input: z.ZodType, raw_params: unknown) =>
|
|
|
81
83
|
*/
|
|
82
84
|
export declare const json_has_own_proto_key: (value: unknown) => boolean;
|
|
83
85
|
/**
|
|
84
|
-
* `schema
|
|
86
|
+
* `parse_any(schema, value)`, except that keys the schema doesn't declare are
|
|
85
87
|
* dropped rather than refused — the forward-compatible read of a payload a
|
|
86
|
-
* remote authored.
|
|
88
|
+
* remote authored. Takes a Zod or a `@fuzdev/fuz_schema` schema.
|
|
87
89
|
*
|
|
88
90
|
* Output schemas are strict so the server's DEV output validation catches a
|
|
89
91
|
* handler leaking fields it shouldn't. The receiving side, though, is often
|
|
90
92
|
* older than the remote it talks to — a deploy lands before open tabs reload
|
|
91
93
|
* — and a remote that adds a field is making a compatible change. So when
|
|
92
|
-
* every issue is an
|
|
93
|
-
* `value` and it's parsed again
|
|
94
|
+
* every issue is an unknown key (`unknown_key_targets`), those keys are
|
|
95
|
+
* stripped from a copy of `value` and it's parsed again, until a parse
|
|
96
|
+
* succeeds or reports anything else; any other issue (a wrong type, a missing
|
|
94
97
|
* field, `null` where a value is required) still fails. `value` itself is
|
|
95
98
|
* never mutated. This matches serde's default on the Rust spine, which
|
|
96
|
-
* ignores unknown fields.
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
+
* ignores unknown fields.
|
|
100
|
+
*
|
|
101
|
+
* A fuz_schema parse reports at most a hundred issues, so a pass that only
|
|
102
|
+
* deleted the reported keys would take a parse per hundred unknown keys,
|
|
103
|
+
* quadratic in a payload of many. So after the first parse that reports
|
|
104
|
+
* unknown keys, one schema-guided pass deletes every key a strict fuz_schema
|
|
105
|
+
* `object` doesn't name anywhere the schema reaches — object entries, array
|
|
106
|
+
* items, record values, the `variant` option the discriminator picks — and
|
|
107
|
+
* the next parse usually succeeds. A key under a fuz_schema `union` is never
|
|
108
|
+
* stripped: which option will match isn't known, and the union fails as one
|
|
109
|
+
* issue of its own. A later `pipe` stage is stripped only as reported, as the
|
|
110
|
+
* pass reads only a pipe's first schema, so keys a later stage refuses that
|
|
111
|
+
* the first names still go a hundred a parse. A pass that finds
|
|
112
|
+
* nothing to strip ends it, and the passes are capped at
|
|
113
|
+
* `UNKNOWN_KEY_PASSES_MAX` for both libraries, past which the last failure is
|
|
114
|
+
* returned, so the work stays linear in the payload whatever its shape.
|
|
115
|
+
*
|
|
116
|
+
* Unions differ by library. A Zod `z.union` of strict objects reports the
|
|
117
|
+
* unknown key itself (`unrecognized_keys` on the object), so it is stripped,
|
|
118
|
+
* as are a `z.discriminatedUnion`'s matched-branch keys. A fuz_schema `union`
|
|
119
|
+
* reports one issue of its own, so a key inside one is not stripped and the
|
|
120
|
+
* parse fails; a `variant` reports its matched option's issues, so those are.
|
|
99
121
|
*
|
|
100
122
|
* Used for a response's `result` (`ActionEvent`) and for a peer's reply to a
|
|
101
123
|
* server-initiated request (`peer/ping`).
|
|
102
124
|
*
|
|
103
|
-
* @param schema - the declared shape
|
|
125
|
+
* @param schema - the declared shape, Zod or fuz_schema
|
|
104
126
|
* @param value - the remote-authored payload
|
|
105
127
|
* @returns the parse result, with undeclared keys dropped on success
|
|
106
128
|
*/
|
|
107
|
-
export declare const safe_parse_dropping_unknown_keys: <T extends
|
|
129
|
+
export declare const safe_parse_dropping_unknown_keys: <T extends ValidationSchema>(schema: T, value: unknown) => ParseAnyResult<ValidationOutput<T>>;
|
|
108
130
|
/**
|
|
109
|
-
*
|
|
131
|
+
* The most parses after the first that `safe_parse_dropping_unknown_keys`
|
|
132
|
+
* runs, each after stripping the keys the one before refused.
|
|
133
|
+
*/
|
|
134
|
+
export declare const UNKNOWN_KEY_PASSES_MAX = 4;
|
|
135
|
+
/**
|
|
136
|
+
* Check if a schema is a strict object: `z.strictObject()`, or a
|
|
137
|
+
* `@fuzdev/fuz_schema` `object` (which refuses unknown keys, where
|
|
138
|
+
* `strip_object` drops them and `loose_object` keeps them).
|
|
110
139
|
*
|
|
111
|
-
* Strict objects set `catchall` to `ZodNever` to reject unknown keys.
|
|
140
|
+
* Strict Zod objects set `catchall` to `ZodNever` to reject unknown keys.
|
|
112
141
|
* Regular `z.object()` has `catchall: undefined` (strips unknown keys in Zod 4).
|
|
142
|
+
* A refined strict object reads strict in both libraries: Zod keeps a
|
|
143
|
+
* `.refine()` on the `ZodObject`, and a fuz_schema `pipe` is read through to
|
|
144
|
+
* its first schema when no stage of it is a `transform` (`message`, `flavor`,
|
|
145
|
+
* `brand` and `meta` keep the kind they wrap). A transformed object is not a
|
|
146
|
+
* strict object in either: Zod's is a `ZodPipe`. The two libraries differ on a
|
|
147
|
+
* pipe without a transform: Zod's `O.pipe(O)` is a `ZodPipe` and reads not
|
|
148
|
+
* strict, where fuz_schema's `pipe(F, F)` reads strict through to `F`.
|
|
113
149
|
*/
|
|
114
|
-
export declare const is_strict_object_schema: (schema:
|
|
150
|
+
export declare const is_strict_object_schema: (schema: ValidationSchema) => boolean;
|
|
151
|
+
/** Options of `schema_to_surface`. */
|
|
152
|
+
export interface SchemaToSurfaceOptions {
|
|
153
|
+
/**
|
|
154
|
+
* Which side of a parse to describe: `'input'`, what it accepts (a
|
|
155
|
+
* request body, params, query), or `'output'`, what it returns (a
|
|
156
|
+
* response, an error body, a pushed event).
|
|
157
|
+
*
|
|
158
|
+
* @default 'output'
|
|
159
|
+
*/
|
|
160
|
+
io?: 'input' | 'output';
|
|
161
|
+
/** Names the schema in a thrown error, e.g. `POST /api/thing input`. */
|
|
162
|
+
source?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Called with the library's message when part of the schema has no JSON
|
|
165
|
+
* Schema form and is left out or written as `{}` there.
|
|
166
|
+
*/
|
|
167
|
+
on_unrepresentable?: (message: string) => void;
|
|
168
|
+
}
|
|
115
169
|
/**
|
|
116
|
-
* Convert a Zod schema to
|
|
117
|
-
*
|
|
118
|
-
*
|
|
170
|
+
* Convert a Zod or `@fuzdev/fuz_schema` schema to its JSON Schema for the
|
|
171
|
+
* surface, with `$schema` and `default` stripped at every depth.
|
|
172
|
+
*
|
|
173
|
+
* Returns `null` for a null schema (`is_null_schema`) and a `z.void()`
|
|
174
|
+
* (`is_void_schema`): no body, no params. Any other schema is written with
|
|
175
|
+
* its library's emitter (`to_json_schema` for fuz_schema, `z.toJSONSchema`
|
|
176
|
+
* for Zod) on the side `options.io` names. A part JSON Schema can't say (a
|
|
177
|
+
* transform on the output side, a `z.custom()`, a fuz_schema `check`) is left
|
|
178
|
+
* out or written as `{}` (a `pipe(string, check(…))` writes as
|
|
179
|
+
* `{type: 'string'}`), and `options.on_unrepresentable` hears the library's
|
|
180
|
+
* message, so the surface describes what it can and records the gap.
|
|
181
|
+
*
|
|
182
|
+
* It never answers `null` for a schema it failed to write, as that would
|
|
183
|
+
* read as "takes no input" and drop the schema out of every suite reading the
|
|
184
|
+
* surface: a schema with no JSON Schema form at all (`{}` where the schema
|
|
185
|
+
* isn't `z.unknown()` or `z.any()`), and one either emitter refuses outright
|
|
186
|
+
* (a fuz_schema entry named like a member of `Object.prototype`, metadata
|
|
187
|
+
* that isn't JSON), throw. So an output whose root is a transform (a Zod
|
|
188
|
+
* `.transform()`, a fuz_schema `pipe(object(…), transform(…))`), a
|
|
189
|
+
* `z.custom()`, or a `z.date()` throws, and since `generate_app_surface`
|
|
190
|
+
* runs at server assembly, a route or action declaring one fails the server
|
|
191
|
+
* at boot. That includes `z.unknown().transform(f)`, though `{}` would
|
|
192
|
+
* describe it: the output side of a transform is unknown, whatever its input.
|
|
193
|
+
*
|
|
194
|
+
* @param schema - the schema to describe, Zod or fuz_schema
|
|
195
|
+
* @param options - the side to describe, the schema's name for errors, and a listener for gaps
|
|
196
|
+
* @returns the JSON Schema, or `null` for a null or void schema
|
|
197
|
+
* @throws Error naming `options.source` when the schema can't be written, or nothing of it can
|
|
119
198
|
*/
|
|
120
|
-
export declare const schema_to_surface: (schema:
|
|
199
|
+
export declare const schema_to_surface: (schema: ValidationSchema, options?: SchemaToSurfaceOptions) => unknown;
|
|
121
200
|
/**
|
|
122
201
|
* Check if a middleware path pattern applies to a route path.
|
|
123
202
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/schema_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schema_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/schema_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAA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