@fuzdev/fuz_app 0.169.0 → 0.171.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 +19 -21
- package/dist/actions/action_codegen.d.ts +27 -18
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +90 -90
- package/dist/actions/action_event.d.ts +0 -8
- package/dist/actions/action_event.d.ts.map +1 -1
- package/dist/actions/action_event.js +7 -6
- package/dist/actions/action_event_data.d.ts +4 -4
- package/dist/actions/action_rpc.d.ts +1 -1
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +6 -7
- package/dist/actions/action_spec.d.ts +8 -10
- package/dist/actions/action_spec.d.ts.map +1 -1
- package/dist/actions/action_spec.js +1 -1
- package/dist/actions/action_types.d.ts +4 -4
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/action_types.js +2 -2
- package/dist/actions/broadcast_api.d.ts +2 -2
- package/dist/actions/broadcast_api.js +4 -4
- package/dist/actions/compile_action_registry.d.ts +6 -7
- package/dist/actions/compile_action_registry.d.ts.map +1 -1
- package/dist/actions/compile_action_registry.js +8 -9
- package/dist/actions/peer_ping.d.ts.map +1 -1
- package/dist/actions/peer_ping.js +3 -2
- package/dist/actions/perform_action.d.ts +6 -6
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +11 -10
- package/dist/actions/socket.svelte.d.ts +1 -1
- package/dist/actions/socket.svelte.js +2 -2
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +2 -1
- package/dist/auth/CLAUDE.md +11 -11
- package/dist/auth/admin_action_specs.d.ts +24 -24
- package/dist/auth/audit_emitter.d.ts +6 -7
- package/dist/auth/audit_emitter.d.ts.map +1 -1
- package/dist/auth/audit_emitter.js +11 -22
- package/dist/auth/audit_log_ddl.d.ts +1 -1
- package/dist/auth/audit_log_ddl.js +1 -1
- package/dist/auth/audit_log_queries.d.ts +0 -13
- package/dist/auth/audit_log_queries.d.ts.map +1 -1
- package/dist/auth/audit_log_queries.js +3 -3
- package/dist/auth/audit_log_schema.d.ts +14 -15
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +1 -1
- package/dist/auth/auth_ddl.d.ts +1 -1
- package/dist/auth/auth_ddl.js +1 -1
- package/dist/auth/cell_action_specs.d.ts +54 -54
- package/dist/auth/cell_actions.d.ts +2 -2
- package/dist/auth/cell_actions.js +5 -5
- package/dist/auth/middleware.d.ts +6 -2
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +14 -2
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +7 -9
- package/dist/auth/role_grant_offer_action_specs.d.ts +6 -6
- package/dist/auth/role_grant_offer_ddl.d.ts +1 -1
- package/dist/auth/role_grant_offer_ddl.js +1 -1
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +2 -3
- package/dist/auth/self_service_role_actions.d.ts +1 -1
- package/dist/auth/self_service_role_actions.js +1 -1
- package/dist/env/env_schemas.d.ts +1 -2
- package/dist/env/env_schemas.d.ts.map +1 -1
- package/dist/env/env_schemas.js +3 -4
- package/dist/http/CLAUDE.md +30 -31
- package/dist/http/auth_shape.d.ts +14 -32
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +14 -49
- package/dist/http/error_schemas.d.ts +18 -18
- package/dist/http/json_text.d.ts +53 -0
- package/dist/http/json_text.d.ts.map +1 -0
- package/dist/http/json_text.js +152 -0
- package/dist/http/jsonrpc_helpers.js +1 -1
- package/dist/http/route_error_check.d.ts +2 -2
- package/dist/http/route_error_check.d.ts.map +1 -1
- package/dist/http/route_error_check.js +2 -3
- package/dist/http/route_errors.d.ts +4 -4
- package/dist/http/route_errors.d.ts.map +1 -1
- package/dist/http/route_errors.js +0 -13
- package/dist/http/route_result.d.ts +2 -1
- package/dist/http/route_result.d.ts.map +1 -1
- package/dist/http/route_spec.d.ts +34 -37
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +31 -31
- package/dist/http/schema_helpers.d.ts +77 -68
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +54 -77
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +6 -8
- package/dist/primitive_schemas.d.ts +9 -17
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas.js +9 -17
- package/dist/realtime/sse.d.ts +3 -3
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +2 -2
- package/dist/schema_issues.d.ts +39 -147
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +39 -352
- package/dist/schema_meta.d.ts +63 -136
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +37 -184
- package/dist/sensitivity.d.ts +3 -5
- package/dist/sensitivity.d.ts.map +1 -1
- package/dist/sensitivity.js +3 -5
- package/dist/testing/CLAUDE.md +20 -22
- package/dist/testing/adversarial_headers.js +2 -2
- package/dist/testing/adversarial_input_cases.d.ts +19 -18
- package/dist/testing/adversarial_input_cases.d.ts.map +1 -1
- package/dist/testing/adversarial_input_cases.js +31 -46
- package/dist/testing/assertions.d.ts +2 -2
- package/dist/testing/assertions.d.ts.map +1 -1
- package/dist/testing/assertions.js +3 -3
- package/dist/testing/cross_backend/account_lifecycle.js +2 -2
- package/dist/testing/cross_backend/action_manifest.d.ts +10 -9
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.js +4 -3
- package/dist/testing/cross_backend/cell_crud.js +1 -1
- package/dist/testing/cross_backend/conformance_rpc_auth.d.ts +0 -62
- package/dist/testing/cross_backend/conformance_rpc_auth.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +3 -3
- package/dist/testing/cross_backend/cross_rpc.d.ts +3 -4
- package/dist/testing/cross_backend/cross_rpc.d.ts.map +1 -1
- package/dist/testing/cross_backend/cross_rpc.js +4 -4
- package/dist/testing/cross_backend/differential.js +2 -2
- package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/identity_parity.js +16 -11
- package/dist/testing/cross_backend/origin_conformance.d.ts +9 -9
- package/dist/testing/cross_backend/query_shape.js +1 -1
- package/dist/testing/cross_backend/rpc_success_fixtures.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +1 -1
- package/dist/testing/cross_backend/setup.d.ts +25 -3
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +4 -4
- package/dist/testing/cross_backend/sse_round_trip.js +2 -2
- package/dist/testing/cross_backend/testing_origin_check.d.ts +4 -4
- package/dist/testing/cross_backend/token_lifetime.js +3 -3
- package/dist/testing/cross_backend/wire_shapes.js +1 -1
- package/dist/testing/cross_backend/ws_envelope.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_envelope.js +8 -0
- package/dist/testing/cross_backend/ws_round_trip.js +1 -1
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +1 -1
- package/dist/testing/integration.js +2 -2
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +2 -2
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +2 -2
- package/dist/testing/rpc_attack_surface.js +1 -1
- package/dist/testing/rpc_envelope_cases.d.ts +10 -3
- package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
- package/dist/testing/rpc_envelope_cases.js +22 -1
- package/dist/testing/rpc_helpers.d.ts +12 -14
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +9 -10
- package/dist/testing/schema_generators.d.ts +67 -60
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +154 -159
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +2 -2
- package/dist/testing/surface_invariants.d.ts +1 -1
- package/dist/testing/surface_invariants.js +1 -1
- package/dist/ui/form_state.svelte.d.ts +1 -1
- package/dist/ui/form_state.svelte.js +1 -1
- package/package.json +5 -7
- package/dist/zod.d.ts +0 -116
- package/dist/zod.d.ts.map +0 -1
- package/dist/zod.js +0 -218
- package/dist/zod_schemas.d.ts +0 -100
- package/dist/zod_schemas.d.ts.map +0 -1
- package/dist/zod_schemas.js +0 -157
|
@@ -7,29 +7,50 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
|
-
import { type
|
|
10
|
+
import { type AnySchema, type Infer, type SchemaKind, type SchemaResult } from '@fuzdev/fuz_schema/schema.ts';
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
* `
|
|
12
|
+
* The kind the testing generators switch on: the innermost layer's
|
|
13
|
+
* `@fuzdev/fuz_schema` kind, with an object schema of any strictness as
|
|
14
|
+
* `'object'`, and a `literal(null)` and a `literal(undefined)` (`s.void`) as
|
|
15
|
+
* `'null'` and `'void'`.
|
|
16
|
+
*/
|
|
17
|
+
export type SchemaFieldBaseType = Exclude<SchemaKind, 'loose_object' | 'strip_object' | 'object_with_rest'> | 'null' | 'void';
|
|
18
|
+
/**
|
|
19
|
+
* What the testing generators read of one field of an object schema
|
|
20
|
+
* (`to_object_schema_view`, `testing/schema_generators.ts`).
|
|
21
|
+
*/
|
|
22
|
+
export interface SchemaFieldInfo {
|
|
23
|
+
/** The field's key. */
|
|
24
|
+
name: string;
|
|
25
|
+
/** The innermost layer's kind, `SchemaFieldBaseType`. */
|
|
26
|
+
base_type: SchemaFieldBaseType;
|
|
27
|
+
/** Whether the key must be present: no `optional` layer. */
|
|
28
|
+
required: boolean;
|
|
29
|
+
/** Whether the parse fills the key in when it is missing. */
|
|
30
|
+
has_default: boolean;
|
|
31
|
+
/** Whether a wrapping layer accepts `null`. */
|
|
32
|
+
nullable: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Check if a schema is exactly `literal(null)`.
|
|
14
36
|
*
|
|
15
37
|
* Reads the schema's kind rather than parsing `null`, to avoid false
|
|
16
|
-
* positives from `
|
|
17
|
-
*
|
|
38
|
+
* positives from `nullable(string)` or similar schemas that accept null but
|
|
39
|
+
* also accept other values.
|
|
18
40
|
*/
|
|
19
|
-
export declare const is_null_schema: (schema:
|
|
41
|
+
export declare const is_null_schema: (schema: AnySchema) => boolean;
|
|
20
42
|
/**
|
|
21
|
-
* Check if a schema is exactly `
|
|
22
|
-
* `
|
|
43
|
+
* Check if a schema is exactly `literal(undefined)` (what `s.void` is,
|
|
44
|
+
* `meta` copies included).
|
|
23
45
|
*
|
|
24
46
|
* RPC action specs use a void schema to declare a parameterless method —
|
|
25
47
|
* JSON-RPC 2.0 forbids `params: null` (params must be omitted or be a
|
|
26
48
|
* Structured value), so void is the correct schema for "no params" and the
|
|
27
49
|
* dispatcher maps absent params to `undefined` for these specs. Like
|
|
28
50
|
* `is_null_schema`, it reads the schema's kind rather than parsing
|
|
29
|
-
* `undefined`, so an optional schema is not void.
|
|
30
|
-
* void either.
|
|
51
|
+
* `undefined`, so an optional schema is not void.
|
|
31
52
|
*/
|
|
32
|
-
export declare const is_void_schema: (schema:
|
|
53
|
+
export declare const is_void_schema: (schema: AnySchema) => boolean;
|
|
33
54
|
/**
|
|
34
55
|
* Normalize the raw `params` of a void input (`is_void_schema`): an absent
|
|
35
56
|
* `params`, an empty object, and the `null` a GET `?params=null` parses to
|
|
@@ -49,18 +70,18 @@ export declare const is_void_schema: (schema: ValidationSchema) => boolean;
|
|
|
49
70
|
export declare const to_void_params: (raw_params: unknown) => unknown;
|
|
50
71
|
/**
|
|
51
72
|
* Normalize the raw `params` of an RPC call for `input` to validate: for a
|
|
52
|
-
* void input (`is_void_schema
|
|
73
|
+
* void input (`is_void_schema`), `to_void_params`; for
|
|
53
74
|
* any other input, an absent or `null` `params` reads as `{}`, so an
|
|
54
75
|
* all-optional object input accepts a call that omits them. Every receiving
|
|
55
76
|
* end — the server dispatch (`perform_action`) and a peer receiving a
|
|
56
77
|
* request or notification (`ActionDispatcher`) — reads params through this,
|
|
57
78
|
* so a peer is never stricter than the server.
|
|
58
79
|
*
|
|
59
|
-
* @param input - the action's input schema
|
|
80
|
+
* @param input - the action's input schema
|
|
60
81
|
* @param raw_params - the call's `params` as parsed off the wire
|
|
61
|
-
* @returns the value the input parse (`
|
|
82
|
+
* @returns the value the input parse (`parse`) reads
|
|
62
83
|
*/
|
|
63
|
-
export declare const to_input_params: (input:
|
|
84
|
+
export declare const to_input_params: (input: AnySchema, raw_params: unknown) => unknown;
|
|
64
85
|
/**
|
|
65
86
|
* Check whether a parsed JSON value holds an own `__proto__` key in any
|
|
66
87
|
* object, at any depth — what the dispatcher refuses in a request's `params`
|
|
@@ -83,9 +104,9 @@ export declare const to_input_params: (input: ValidationSchema, raw_params: unkn
|
|
|
83
104
|
*/
|
|
84
105
|
export declare const json_has_own_proto_key: (value: unknown) => boolean;
|
|
85
106
|
/**
|
|
86
|
-
* `
|
|
107
|
+
* `parse(schema, value)`, except that keys the schema doesn't declare are
|
|
87
108
|
* dropped rather than refused — the forward-compatible read of a payload a
|
|
88
|
-
* remote authored.
|
|
109
|
+
* remote authored.
|
|
89
110
|
*
|
|
90
111
|
* Output schemas are strict so the server's DEV output validation catches a
|
|
91
112
|
* handler leaking fields it shouldn't. The receiving side, though, is often
|
|
@@ -98,56 +119,48 @@ export declare const json_has_own_proto_key: (value: unknown) => boolean;
|
|
|
98
119
|
* never mutated. This matches serde's default on the Rust spine, which
|
|
99
120
|
* ignores unknown fields.
|
|
100
121
|
*
|
|
101
|
-
* A
|
|
122
|
+
* A parse reports at most a hundred issues, so a pass that only
|
|
102
123
|
* deleted the reported keys would take a parse per hundred unknown keys,
|
|
103
124
|
* 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
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
125
|
+
* unknown keys, one schema-guided pass deletes every key a strict `object`
|
|
126
|
+
* doesn't name anywhere the schema reaches — object entries, array items,
|
|
127
|
+
* record values, the `variant` option the discriminator picks — and the next
|
|
128
|
+
* parse usually succeeds. A key under a `union` is never
|
|
108
129
|
* stripped: which option will match isn't known, and the union fails as one
|
|
109
130
|
* issue of its own. A later `pipe` stage is stripped only as reported, as the
|
|
110
131
|
* pass reads only a pipe's first schema, so keys a later stage refuses that
|
|
111
132
|
* the first names still go a hundred a parse. A pass that finds
|
|
112
133
|
* nothing to strip ends it, and the passes are capped at
|
|
113
|
-
* `UNKNOWN_KEY_PASSES_MAX
|
|
134
|
+
* `UNKNOWN_KEY_PASSES_MAX`, past which the last failure is
|
|
114
135
|
* returned, so the work stays linear in the payload whatever its shape.
|
|
115
136
|
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
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.
|
|
137
|
+
* A `union` reports one issue of its own, so a key inside one is not
|
|
138
|
+
* stripped and the parse fails; a `variant` reports its matched option's
|
|
139
|
+
* issues, so those are.
|
|
121
140
|
*
|
|
122
141
|
* Used for a response's `result` (`ActionEvent`) and for a peer's reply to a
|
|
123
142
|
* server-initiated request (`peer/ping`).
|
|
124
143
|
*
|
|
125
|
-
* @param schema - the declared shape
|
|
144
|
+
* @param schema - the declared shape
|
|
126
145
|
* @param value - the remote-authored payload
|
|
127
146
|
* @returns the parse result, with undeclared keys dropped on success
|
|
128
147
|
*/
|
|
129
|
-
export declare const safe_parse_dropping_unknown_keys: <T extends
|
|
148
|
+
export declare const safe_parse_dropping_unknown_keys: <T extends AnySchema>(schema: T, value: unknown) => SchemaResult<Infer<T>>;
|
|
130
149
|
/**
|
|
131
150
|
* The most parses after the first that `safe_parse_dropping_unknown_keys`
|
|
132
151
|
* runs, each after stripping the keys the one before refused.
|
|
133
152
|
*/
|
|
134
153
|
export declare const UNKNOWN_KEY_PASSES_MAX = 4;
|
|
135
154
|
/**
|
|
136
|
-
* Check if a schema is a strict object: `
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* A
|
|
143
|
-
|
|
144
|
-
|
|
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`.
|
|
149
|
-
*/
|
|
150
|
-
export declare const is_strict_object_schema: (schema: ValidationSchema) => boolean;
|
|
155
|
+
* Check if a schema is a strict object: an `object` (which refuses unknown
|
|
156
|
+
* keys, where `strip_object` drops them and `loose_object` keeps them).
|
|
157
|
+
*
|
|
158
|
+
* A refined strict object reads strict: a `pipe` is read through to its first
|
|
159
|
+
* schema when no stage of it is a `transform` (`message`, `flavor`, `brand`
|
|
160
|
+
* and `meta` keep the kind they wrap), so `pipe(O, O)` reads strict through
|
|
161
|
+
* to `O`. A transformed object is not a strict object.
|
|
162
|
+
*/
|
|
163
|
+
export declare const is_strict_object_schema: (schema: AnySchema) => boolean;
|
|
151
164
|
/** Options of `schema_to_surface`. */
|
|
152
165
|
export interface SchemaToSurfaceOptions {
|
|
153
166
|
/**
|
|
@@ -161,16 +174,16 @@ export interface SchemaToSurfaceOptions {
|
|
|
161
174
|
/** Names the schema in a thrown error, e.g. `POST /api/thing input`. */
|
|
162
175
|
source?: string;
|
|
163
176
|
/**
|
|
164
|
-
* Called with the
|
|
177
|
+
* Called with the emitter's message when part of the schema has no JSON
|
|
165
178
|
* Schema form and is left out or written as `{}` there.
|
|
166
179
|
*/
|
|
167
180
|
on_unrepresentable?: (message: string) => void;
|
|
168
181
|
}
|
|
169
182
|
/**
|
|
170
|
-
* Convert a
|
|
171
|
-
*
|
|
183
|
+
* Convert a `@fuzdev/fuz_schema` schema to its JSON Schema for the surface
|
|
184
|
+
* (`to_json_schema`), with `$schema` and `default` stripped at every depth.
|
|
172
185
|
*
|
|
173
|
-
* A value
|
|
186
|
+
* A value that is no schema throws first (`assert_validation_schema`),
|
|
174
187
|
* naming `options.source`, so a slot that surface generation reads before
|
|
175
188
|
* any registration does — a route's, an event's `params`, a `ws_endpoints`
|
|
176
189
|
* action's — fails server assembly naming the slot, as registration refuses
|
|
@@ -178,32 +191,28 @@ export interface SchemaToSurfaceOptions {
|
|
|
178
191
|
* write.
|
|
179
192
|
*
|
|
180
193
|
* Returns `null` for a null schema (`is_null_schema`) and a void schema
|
|
181
|
-
* (`is_void_schema`)
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* message, so the surface describes what it can and records the gap.
|
|
194
|
+
* (`is_void_schema`): no body, no params. Any other schema is written on the
|
|
195
|
+
* side `options.io` names. A part JSON Schema can't say (a transform on the
|
|
196
|
+
* output side, a `check`) is left out or written as `{}` (a
|
|
197
|
+
* `pipe(string, check(…))` writes as `{type: 'string'}`), and
|
|
198
|
+
* `options.on_unrepresentable` hears the emitter's message, so the surface
|
|
199
|
+
* describes what it can and records the gap.
|
|
188
200
|
*
|
|
189
201
|
* It never answers `null` for a schema it failed to write, as that would
|
|
190
202
|
* read as "takes no input" and drop the schema out of every suite reading the
|
|
191
203
|
* surface: a schema with no JSON Schema form at all (`{}` where the schema
|
|
192
|
-
* isn't `
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
* describe it: the output side of a transform is unknown, whatever its input.
|
|
200
|
-
*
|
|
201
|
-
* @param schema - the schema to describe, Zod or fuz_schema
|
|
204
|
+
* isn't `unknown`), and one the emitter refuses outright (an entry named like
|
|
205
|
+
* a member of `Object.prototype`, metadata that isn't JSON), throw. So an
|
|
206
|
+
* output whose root is a transform (`pipe(object(…), transform(…))`) throws,
|
|
207
|
+
* and since `generate_app_surface` runs at server assembly, a route or action
|
|
208
|
+
* declaring one fails the server at boot.
|
|
209
|
+
*
|
|
210
|
+
* @param schema - the schema to describe
|
|
202
211
|
* @param options - the side to describe, the schema's name for errors, and a listener for gaps
|
|
203
212
|
* @returns the JSON Schema, or `null` for a null or void schema
|
|
204
|
-
* @throws Error naming `options.source` when the value is
|
|
213
|
+
* @throws Error naming `options.source` when the value is no schema, when the schema can't be written, or when nothing of it can
|
|
205
214
|
*/
|
|
206
|
-
export declare const schema_to_surface: (schema:
|
|
215
|
+
export declare const schema_to_surface: (schema: AnySchema, options?: SchemaToSurfaceOptions) => unknown;
|
|
207
216
|
/**
|
|
208
217
|
* Check if a middleware path pattern applies to a route path.
|
|
209
218
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/schema_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"schema_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/schema_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAEN,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,MAAM,8BAA8B,CAAC;AAMtC;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAC9B,OAAO,CAAC,UAAU,EAAE,cAAc,GAAG,cAAc,GAAG,kBAAkB,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC;AAE7F;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,uBAAuB;IACvB,IA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I,CAAC;CAC/C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,SAAS,EAAE,UAAU,sBAAsB,KAAG,OA2BvF,CAAC;AAoBF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,EAAE,YAAY,MAAM,KAAG,OAQxE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,OAM/D,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,GACjC,MAAM;IAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAA;CAAE,EAC/E,YAAY,MAAM,KAChB,OACyF,CAAC;AAE7F;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,GACnC,MAAM;IACL,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;CACtE,EACD,YAAY,MAAM,KAChB,OAAgG,CAAC"}
|
|
@@ -8,35 +8,30 @@
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
import { to_error_message } from '@fuzdev/fuz_util/error.ts';
|
|
11
|
-
import {
|
|
11
|
+
import { parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
12
12
|
import { unwrap_schema } from '@fuzdev/fuz_schema/introspect.ts';
|
|
13
13
|
import { to_json_schema } from '@fuzdev/fuz_schema/json_schema.ts';
|
|
14
|
-
import { assert_validation_schema,
|
|
15
|
-
import { zod_has_trait } from '../zod.js';
|
|
14
|
+
import { assert_validation_schema, unknown_key_targets } from '../schema_issues.js';
|
|
16
15
|
/**
|
|
17
|
-
* Check if a schema is exactly `
|
|
18
|
-
* `literal(null)`.
|
|
16
|
+
* Check if a schema is exactly `literal(null)`.
|
|
19
17
|
*
|
|
20
18
|
* Reads the schema's kind rather than parsing `null`, to avoid false
|
|
21
|
-
* positives from `
|
|
22
|
-
*
|
|
19
|
+
* positives from `nullable(string)` or similar schemas that accept null but
|
|
20
|
+
* also accept other values.
|
|
23
21
|
*/
|
|
24
|
-
export const is_null_schema = (schema) =>
|
|
25
|
-
(is_schema(schema) && schema.kind === 'literal' && schema.def === null);
|
|
22
|
+
export const is_null_schema = (schema) => schema.kind === 'literal' && schema.def === null;
|
|
26
23
|
/**
|
|
27
|
-
* Check if a schema is exactly `
|
|
28
|
-
* `
|
|
24
|
+
* Check if a schema is exactly `literal(undefined)` (what `s.void` is,
|
|
25
|
+
* `meta` copies included).
|
|
29
26
|
*
|
|
30
27
|
* RPC action specs use a void schema to declare a parameterless method —
|
|
31
28
|
* JSON-RPC 2.0 forbids `params: null` (params must be omitted or be a
|
|
32
29
|
* Structured value), so void is the correct schema for "no params" and the
|
|
33
30
|
* dispatcher maps absent params to `undefined` for these specs. Like
|
|
34
31
|
* `is_null_schema`, it reads the schema's kind rather than parsing
|
|
35
|
-
* `undefined`, so an optional schema is not void.
|
|
36
|
-
* void either.
|
|
32
|
+
* `undefined`, so an optional schema is not void.
|
|
37
33
|
*/
|
|
38
|
-
export const is_void_schema = (schema) =>
|
|
39
|
-
(is_schema(schema) && schema.kind === 'literal' && schema.def === undefined);
|
|
34
|
+
export const is_void_schema = (schema) => schema.kind === 'literal' && schema.def === undefined;
|
|
40
35
|
/**
|
|
41
36
|
* Normalize the raw `params` of a void input (`is_void_schema`): an absent
|
|
42
37
|
* `params`, an empty object, and the `null` a GET `?params=null` parses to
|
|
@@ -65,16 +60,16 @@ export const to_void_params = (raw_params) => {
|
|
|
65
60
|
};
|
|
66
61
|
/**
|
|
67
62
|
* Normalize the raw `params` of an RPC call for `input` to validate: for a
|
|
68
|
-
* void input (`is_void_schema
|
|
63
|
+
* void input (`is_void_schema`), `to_void_params`; for
|
|
69
64
|
* any other input, an absent or `null` `params` reads as `{}`, so an
|
|
70
65
|
* all-optional object input accepts a call that omits them. Every receiving
|
|
71
66
|
* end — the server dispatch (`perform_action`) and a peer receiving a
|
|
72
67
|
* request or notification (`ActionDispatcher`) — reads params through this,
|
|
73
68
|
* so a peer is never stricter than the server.
|
|
74
69
|
*
|
|
75
|
-
* @param input - the action's input schema
|
|
70
|
+
* @param input - the action's input schema
|
|
76
71
|
* @param raw_params - the call's `params` as parsed off the wire
|
|
77
|
-
* @returns the value the input parse (`
|
|
72
|
+
* @returns the value the input parse (`parse`) reads
|
|
78
73
|
*/
|
|
79
74
|
export const to_input_params = (input, raw_params) => is_void_schema(input) ? to_void_params(raw_params) : (raw_params ?? {});
|
|
80
75
|
/**
|
|
@@ -116,9 +111,9 @@ export const json_has_own_proto_key = (value) => {
|
|
|
116
111
|
return false;
|
|
117
112
|
};
|
|
118
113
|
/**
|
|
119
|
-
* `
|
|
114
|
+
* `parse(schema, value)`, except that keys the schema doesn't declare are
|
|
120
115
|
* dropped rather than refused — the forward-compatible read of a payload a
|
|
121
|
-
* remote authored.
|
|
116
|
+
* remote authored.
|
|
122
117
|
*
|
|
123
118
|
* Output schemas are strict so the server's DEV output validation catches a
|
|
124
119
|
* handler leaking fields it shouldn't. The receiving side, though, is often
|
|
@@ -131,36 +126,34 @@ export const json_has_own_proto_key = (value) => {
|
|
|
131
126
|
* never mutated. This matches serde's default on the Rust spine, which
|
|
132
127
|
* ignores unknown fields.
|
|
133
128
|
*
|
|
134
|
-
* A
|
|
129
|
+
* A parse reports at most a hundred issues, so a pass that only
|
|
135
130
|
* deleted the reported keys would take a parse per hundred unknown keys,
|
|
136
131
|
* quadratic in a payload of many. So after the first parse that reports
|
|
137
|
-
* unknown keys, one schema-guided pass deletes every key a strict
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
132
|
+
* unknown keys, one schema-guided pass deletes every key a strict `object`
|
|
133
|
+
* doesn't name anywhere the schema reaches — object entries, array items,
|
|
134
|
+
* record values, the `variant` option the discriminator picks — and the next
|
|
135
|
+
* parse usually succeeds. A key under a `union` is never
|
|
141
136
|
* stripped: which option will match isn't known, and the union fails as one
|
|
142
137
|
* issue of its own. A later `pipe` stage is stripped only as reported, as the
|
|
143
138
|
* pass reads only a pipe's first schema, so keys a later stage refuses that
|
|
144
139
|
* the first names still go a hundred a parse. A pass that finds
|
|
145
140
|
* nothing to strip ends it, and the passes are capped at
|
|
146
|
-
* `UNKNOWN_KEY_PASSES_MAX
|
|
141
|
+
* `UNKNOWN_KEY_PASSES_MAX`, past which the last failure is
|
|
147
142
|
* returned, so the work stays linear in the payload whatever its shape.
|
|
148
143
|
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* reports one issue of its own, so a key inside one is not stripped and the
|
|
153
|
-
* parse fails; a `variant` reports its matched option's issues, so those are.
|
|
144
|
+
* A `union` reports one issue of its own, so a key inside one is not
|
|
145
|
+
* stripped and the parse fails; a `variant` reports its matched option's
|
|
146
|
+
* issues, so those are.
|
|
154
147
|
*
|
|
155
148
|
* Used for a response's `result` (`ActionEvent`) and for a peer's reply to a
|
|
156
149
|
* server-initiated request (`peer/ping`).
|
|
157
150
|
*
|
|
158
|
-
* @param schema - the declared shape
|
|
151
|
+
* @param schema - the declared shape
|
|
159
152
|
* @param value - the remote-authored payload
|
|
160
153
|
* @returns the parse result, with undeclared keys dropped on success
|
|
161
154
|
*/
|
|
162
155
|
export const safe_parse_dropping_unknown_keys = (schema, value) => {
|
|
163
|
-
let parsed =
|
|
156
|
+
let parsed = parse(schema, value);
|
|
164
157
|
let stripped;
|
|
165
158
|
for (let pass = 0; !parsed.ok && pass < UNKNOWN_KEY_PASSES_MAX; pass++) {
|
|
166
159
|
const targets = unknown_key_targets(parsed.issues);
|
|
@@ -170,8 +163,7 @@ export const safe_parse_dropping_unknown_keys = (schema, value) => {
|
|
|
170
163
|
if (stripped === undefined) {
|
|
171
164
|
stripped = structuredClone(value);
|
|
172
165
|
// once: every key a strict `object` the schema reaches doesn't name
|
|
173
|
-
|
|
174
|
-
removed = strip_unknown_keys_by_schema(schema, stripped);
|
|
166
|
+
removed = strip_unknown_keys_by_schema(schema, stripped);
|
|
175
167
|
}
|
|
176
168
|
for (const { path, keys } of targets) {
|
|
177
169
|
const target = get_at_path(stripped, path);
|
|
@@ -186,7 +178,7 @@ export const safe_parse_dropping_unknown_keys = (schema, value) => {
|
|
|
186
178
|
}
|
|
187
179
|
if (!removed)
|
|
188
180
|
return parsed;
|
|
189
|
-
parsed =
|
|
181
|
+
parsed = parse(schema, stripped);
|
|
190
182
|
}
|
|
191
183
|
return parsed;
|
|
192
184
|
};
|
|
@@ -296,27 +288,18 @@ const get_at_path = (value, path) => {
|
|
|
296
288
|
return current;
|
|
297
289
|
};
|
|
298
290
|
/**
|
|
299
|
-
* Check if a schema is a strict object: `
|
|
300
|
-
*
|
|
301
|
-
* `strip_object` drops them and `loose_object` keeps them).
|
|
291
|
+
* Check if a schema is a strict object: an `object` (which refuses unknown
|
|
292
|
+
* keys, where `strip_object` drops them and `loose_object` keeps them).
|
|
302
293
|
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
* its first schema when no stage of it is a `transform` (`message`, `flavor`,
|
|
308
|
-
* `brand` and `meta` keep the kind they wrap). A transformed object is not a
|
|
309
|
-
* strict object in either: Zod's is a `ZodPipe`. The two libraries differ on a
|
|
310
|
-
* pipe without a transform: Zod's `O.pipe(O)` is a `ZodPipe` and reads not
|
|
311
|
-
* strict, where fuz_schema's `pipe(F, F)` reads strict through to `F`.
|
|
294
|
+
* A refined strict object reads strict: a `pipe` is read through to its first
|
|
295
|
+
* schema when no stage of it is a `transform` (`message`, `flavor`, `brand`
|
|
296
|
+
* and `meta` keep the kind they wrap), so `pipe(O, O)` reads strict through
|
|
297
|
+
* to `O`. A transformed object is not a strict object.
|
|
312
298
|
*/
|
|
313
|
-
export const is_strict_object_schema = (schema) =>
|
|
314
|
-
? fuz_schema_untransformed_head(schema)?.kind === 'object'
|
|
315
|
-
: zod_has_trait(schema, 'ZodObject') &&
|
|
316
|
-
zod_has_trait(schema.def.catchall, 'ZodNever');
|
|
299
|
+
export const is_strict_object_schema = (schema) => untransformed_head(schema)?.kind === 'object';
|
|
317
300
|
// the schema a value reaches first through every `pipe` it starts with, or
|
|
318
301
|
// `null` when any of those pipes has a `transform` stage
|
|
319
|
-
const
|
|
302
|
+
const untransformed_head = (schema) => {
|
|
320
303
|
let s = schema;
|
|
321
304
|
while (s.kind === 'pipe') {
|
|
322
305
|
const stages = s.def;
|
|
@@ -327,10 +310,10 @@ const fuz_schema_untransformed_head = (schema) => {
|
|
|
327
310
|
return s;
|
|
328
311
|
};
|
|
329
312
|
/**
|
|
330
|
-
* Convert a
|
|
331
|
-
*
|
|
313
|
+
* Convert a `@fuzdev/fuz_schema` schema to its JSON Schema for the surface
|
|
314
|
+
* (`to_json_schema`), with `$schema` and `default` stripped at every depth.
|
|
332
315
|
*
|
|
333
|
-
* A value
|
|
316
|
+
* A value that is no schema throws first (`assert_validation_schema`),
|
|
334
317
|
* naming `options.source`, so a slot that surface generation reads before
|
|
335
318
|
* any registration does — a route's, an event's `params`, a `ws_endpoints`
|
|
336
319
|
* action's — fails server assembly naming the slot, as registration refuses
|
|
@@ -338,39 +321,33 @@ const fuz_schema_untransformed_head = (schema) => {
|
|
|
338
321
|
* write.
|
|
339
322
|
*
|
|
340
323
|
* Returns `null` for a null schema (`is_null_schema`) and a void schema
|
|
341
|
-
* (`is_void_schema`)
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
* message, so the surface describes what it can and records the gap.
|
|
324
|
+
* (`is_void_schema`): no body, no params. Any other schema is written on the
|
|
325
|
+
* side `options.io` names. A part JSON Schema can't say (a transform on the
|
|
326
|
+
* output side, a `check`) is left out or written as `{}` (a
|
|
327
|
+
* `pipe(string, check(…))` writes as `{type: 'string'}`), and
|
|
328
|
+
* `options.on_unrepresentable` hears the emitter's message, so the surface
|
|
329
|
+
* describes what it can and records the gap.
|
|
348
330
|
*
|
|
349
331
|
* It never answers `null` for a schema it failed to write, as that would
|
|
350
332
|
* read as "takes no input" and drop the schema out of every suite reading the
|
|
351
333
|
* surface: a schema with no JSON Schema form at all (`{}` where the schema
|
|
352
|
-
* isn't `
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
* runs at server assembly, a route or action declaring one fails the server
|
|
358
|
-
* at boot. That includes `z.unknown().transform(f)`, though `{}` would
|
|
359
|
-
* describe it: the output side of a transform is unknown, whatever its input.
|
|
334
|
+
* isn't `unknown`), and one the emitter refuses outright (an entry named like
|
|
335
|
+
* a member of `Object.prototype`, metadata that isn't JSON), throw. So an
|
|
336
|
+
* output whose root is a transform (`pipe(object(…), transform(…))`) throws,
|
|
337
|
+
* and since `generate_app_surface` runs at server assembly, a route or action
|
|
338
|
+
* declaring one fails the server at boot.
|
|
360
339
|
*
|
|
361
|
-
* @param schema - the schema to describe
|
|
340
|
+
* @param schema - the schema to describe
|
|
362
341
|
* @param options - the side to describe, the schema's name for errors, and a listener for gaps
|
|
363
342
|
* @returns the JSON Schema, or `null` for a null or void schema
|
|
364
|
-
* @throws Error naming `options.source` when the value is
|
|
343
|
+
* @throws Error naming `options.source` when the value is no schema, when the schema can't be written, or when nothing of it can
|
|
365
344
|
*/
|
|
366
345
|
export const schema_to_surface = (schema, options) => {
|
|
367
346
|
assert_validation_schema(schema, options?.source ?? 'schema');
|
|
368
347
|
if (is_null_schema(schema) || is_void_schema(schema))
|
|
369
348
|
return null;
|
|
370
349
|
const io = options?.io ?? 'output';
|
|
371
|
-
const write = (unrepresentable) => strip_json_schema_noise(
|
|
372
|
-
? to_json_schema(schema, { io, unrepresentable })
|
|
373
|
-
: schema.toJSONSchema({ io, unrepresentable }));
|
|
350
|
+
const write = (unrepresentable) => strip_json_schema_noise(to_json_schema(schema, { io, unrepresentable }));
|
|
374
351
|
const fail = (message, cause) => new Error(`${options?.source ?? 'schema'}: ${message}`, { cause });
|
|
375
352
|
let gap;
|
|
376
353
|
try {
|
|
@@ -398,7 +375,7 @@ export const schema_to_surface = (schema, options) => {
|
|
|
398
375
|
* Recursively strip `$schema` and `default` from a JSON Schema value.
|
|
399
376
|
*
|
|
400
377
|
* `$schema` is noise for snapshots. `default` can be non-deterministic
|
|
401
|
-
* when schemas use function defaults (e.g. `
|
|
378
|
+
* when schemas use function defaults (e.g. `with_default_fn(string, () => new Date().toISOString())`),
|
|
402
379
|
* and defaults are runtime behavior, not attack surface structure.
|
|
403
380
|
*/
|
|
404
381
|
const strip_json_schema_noise = (value) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/surface.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,
|
|
1
|
+
{"version":3,"file":"surface.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/surface.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAS,KAAK,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE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AK,CAAC,SAAS,CAAC,CAAC;CAC1B;AAED,0CAA0C;AAC1C,MAAM,WAAW,yBAAyB;IACzC,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAC9B,gBAAgB,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACxC,2FAA2F;IAC3F,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAC/B,aAAa,CAAC,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;IACvC;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;IACrD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CACtD;AAID;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,SAAS,KAAG,KAAK,CAAC,aAAa,CAc5E,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC7B,aAAa,KAAK,CAAC,SAAS,CAAC,EAC7B,cAAc,KAAK,CAAC,oBAAoB,CAAC,KACvC,KAAK,CAAC,eAAe,CAQvB,CAAC;AA2BF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,SAAS,yBAAyB,KAAG,UAuIzE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,GAAI,SAAS,yBAAyB,KAAG,cAa5E,CAAC"}
|
package/dist/http/surface.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
import { get_schema_entries, get_schema_fields } from '@fuzdev/fuz_schema/introspect.ts';
|
|
11
|
-
import {
|
|
11
|
+
import { parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
12
12
|
import { to_error_schemas } from './error_schemas.js';
|
|
13
13
|
import { schema_to_surface, middleware_spec_applies, is_null_schema, is_strict_object_schema } from './schema_helpers.js';
|
|
14
14
|
import { get_route_error_map, resolve_app_route_error_maps } from './route_errors.js';
|
|
@@ -59,7 +59,7 @@ export const events_to_surface = (event_specs, diagnostics) => {
|
|
|
59
59
|
};
|
|
60
60
|
// `schema_to_surface` with its source named, recording each part of a schema
|
|
61
61
|
// with no JSON Schema form as an `info` diagnostic: a transform's output or a
|
|
62
|
-
// `
|
|
62
|
+
// `check` is ordinary, so it's recorded on the surface, not warned at startup
|
|
63
63
|
const create_to_surface = (diagnostics) => (schema, io, source) => schema_to_surface(schema, {
|
|
64
64
|
io,
|
|
65
65
|
source,
|
|
@@ -72,9 +72,9 @@ const create_to_surface = (diagnostics) => (schema, io, source) => schema_to_sur
|
|
|
72
72
|
})
|
|
73
73
|
: undefined
|
|
74
74
|
});
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
const
|
|
75
|
+
// an input that is not a strict `object`: a `strip_object` drops unknown keys
|
|
76
|
+
// and a `loose_object` keeps them, so the text names neither
|
|
77
|
+
const NOT_STRICT_INPUT_MESSAGE = 'Input schema is not a strict object (@fuzdev/fuz_schema `object`) — unknown keys may not be refused';
|
|
78
78
|
/**
|
|
79
79
|
* Generate a JSON-serializable attack surface from middleware, route specs,
|
|
80
80
|
* and optional env/event metadata.
|
|
@@ -90,9 +90,7 @@ export const generate_app_surface = (options) => {
|
|
|
90
90
|
diagnostics.push({
|
|
91
91
|
level: 'warning',
|
|
92
92
|
category: 'schema',
|
|
93
|
-
message:
|
|
94
|
-
? FUZ_SCHEMA_NOT_STRICT_INPUT_MESSAGE
|
|
95
|
-
: 'Input schema is not z.strictObject() — unknown keys will be silently stripped',
|
|
93
|
+
message: NOT_STRICT_INPUT_MESSAGE,
|
|
96
94
|
source: `${r.method} ${r.path} input`
|
|
97
95
|
});
|
|
98
96
|
}
|