@fuzdev/fuz_app 0.168.1 → 0.170.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 +17 -19
- package/dist/actions/action_codegen.d.ts +32 -23
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +101 -80
- 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 +18 -18
- package/dist/actions/action_rpc.d.ts +1 -1
- package/dist/actions/action_rpc.js +1 -1
- 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/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/auth/CLAUDE.md +11 -11
- package/dist/auth/account_action_specs.d.ts +11 -11
- package/dist/auth/account_action_specs.js +1 -1
- package/dist/auth/account_route_schema.d.ts +18 -18
- package/dist/auth/account_route_schema.js +1 -1
- package/dist/auth/account_routes.js +1 -1
- package/dist/auth/account_schema.d.ts +38 -40
- package/dist/auth/account_schema.d.ts.map +1 -1
- package/dist/auth/account_schema.js +7 -8
- package/dist/auth/actor_lookup_action_specs.d.ts +7 -7
- package/dist/auth/actor_lookup_action_specs.js +1 -1
- package/dist/auth/actor_search_action_specs.d.ts +6 -6
- package/dist/auth/actor_search_action_specs.js +1 -1
- package/dist/auth/admin_action_specs.d.ts +166 -166
- package/dist/auth/admin_action_specs.js +1 -1
- package/dist/auth/app_settings_schema.d.ts +3 -3
- package/dist/auth/app_settings_schema.d.ts.map +1 -1
- package/dist/auth/app_settings_schema.js +1 -1
- 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_route_schema.d.ts +1 -1
- package/dist/auth/audit_log_route_schema.js +1 -1
- package/dist/auth/audit_log_schema.d.ts +69 -70
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +2 -2
- package/dist/auth/auth_ddl.d.ts +1 -1
- package/dist/auth/auth_ddl.js +1 -1
- package/dist/auth/bootstrap_route_schema.d.ts +4 -4
- package/dist/auth/bootstrap_route_schema.js +1 -1
- package/dist/auth/cell_action_specs.d.ts +466 -466
- package/dist/auth/cell_action_specs.js +1 -1
- package/dist/auth/cell_actions.d.ts +2 -2
- package/dist/auth/cell_actions.js +5 -5
- package/dist/auth/cell_audit_action_specs.d.ts +14 -14
- package/dist/auth/cell_audit_action_specs.js +1 -1
- package/dist/auth/cell_audit_metadata.d.ts +8 -8
- package/dist/auth/cell_audit_metadata.js +1 -1
- package/dist/auth/cell_field_action_specs.d.ts +55 -55
- package/dist/auth/cell_field_action_specs.js +1 -1
- package/dist/auth/cell_field_audit_metadata.d.ts +4 -4
- package/dist/auth/cell_field_audit_metadata.js +1 -1
- package/dist/auth/cell_grant_action_specs.d.ts +61 -61
- package/dist/auth/cell_grant_action_specs.js +1 -1
- package/dist/auth/cell_grant_audit_metadata.d.ts +10 -10
- package/dist/auth/cell_grant_audit_metadata.js +1 -1
- package/dist/auth/cell_item_action_specs.d.ts +76 -76
- package/dist/auth/cell_item_action_specs.js +1 -1
- package/dist/auth/cell_item_audit_metadata.d.ts +5 -5
- package/dist/auth/cell_item_audit_metadata.js +1 -1
- package/dist/auth/invite_schema.d.ts +11 -11
- package/dist/auth/invite_schema.d.ts.map +1 -1
- package/dist/auth/invite_schema.js +1 -1
- package/dist/auth/name_schema.js +1 -1
- package/dist/auth/password.js +1 -1
- package/dist/auth/request_context.js +2 -2
- package/dist/auth/role_grant_offer_action_specs.d.ts +182 -182
- package/dist/auth/role_grant_offer_action_specs.js +1 -1
- 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 +107 -107
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +3 -4
- package/dist/auth/role_grant_offer_schema.d.ts +9 -9
- package/dist/auth/role_grant_offer_schema.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_schema.js +1 -1
- package/dist/auth/self_service_role_action_specs.d.ts +2 -2
- package/dist/auth/self_service_role_action_specs.js +1 -1
- package/dist/auth/self_service_role_actions.d.ts +1 -1
- package/dist/auth/self_service_role_actions.js +1 -1
- package/dist/auth/signup_route_schema.d.ts +2 -2
- package/dist/auth/signup_route_schema.js +1 -1
- package/dist/auth/token_scope.d.ts +8 -8
- package/dist/db/file_fact_url.d.ts +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 -32
- package/dist/http/auth_shape.d.ts +17 -52
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +19 -61
- package/dist/http/db_routes.d.ts +1 -1
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +1 -1
- package/dist/http/error_schemas.d.ts +36 -36
- package/dist/http/jsonrpc.d.ts +11 -11
- 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_spec.d.ts +33 -36
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +21 -22
- package/dist/http/schema_helpers.d.ts +75 -67
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +54 -76
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +6 -8
- package/dist/primitive_schemas.d.ts +162 -112
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas.js +129 -161
- 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 +41 -146
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +39 -322
- 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/server/serve_fact_route.js +1 -1
- package/dist/server/surface_route.js +1 -1
- package/dist/testing/CLAUDE.md +23 -25
- 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 +29 -42
- 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_case.d.ts +96 -114
- package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_case.js +0 -256
- 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/fact_serving.js +1 -1
- package/dist/testing/cross_backend/identity_parity.js +9 -9
- 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 +26 -4
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +7 -8
- package/dist/testing/cross_backend/sse_round_trip.js +2 -2
- package/dist/testing/cross_backend/testing_origin_check.d.ts +12 -12
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +608 -201
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +46 -55
- 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_outbound_overflow.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_outbound_overflow.js +35 -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 +3 -3
- package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
- package/dist/testing/rpc_envelope_cases.js +1 -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 -11
- 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 +144 -151
- package/dist/testing/schema_introspect.d.ts +438 -78
- package/dist/testing/schema_introspect.d.ts.map +1 -1
- package/dist/testing/schema_introspect.js +26 -26
- 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/testing/transports/bootstrap.d.ts +1 -1
- package/dist/testing/transports/bootstrap.d.ts.map +1 -1
- package/dist/testing/transports/bootstrap.js +1 -1
- package/dist/ui/BootstrapForm.svelte +1 -2
- package/dist/ui/BootstrapForm.svelte.d.ts.map +1 -1
- package/dist/ui/SignupForm.svelte +1 -2
- package/dist/ui/SignupForm.svelte.d.ts.map +1 -1
- package/dist/ui/admin_accounts_state.svelte.d.ts +5 -5
- package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_invites_state.svelte.d.ts +1 -1
- package/dist/ui/admin_invites_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_sessions_state.svelte.d.ts +2 -2
- package/dist/ui/admin_sessions_state.svelte.d.ts.map +1 -1
- package/dist/ui/form_state.svelte.d.ts +1 -1
- package/dist/ui/form_state.svelte.js +1 -1
- package/dist/ui/role_grant_offers_state.svelte.d.ts +1 -1
- package/package.json +7 -9
- package/dist/primitive_schemas_fuz.d.ts +0 -178
- package/dist/primitive_schemas_fuz.d.ts.map +0 -1
- package/dist/primitive_schemas_fuz.js +0 -149
- package/dist/zod.d.ts +0 -101
- package/dist/zod.d.ts.map +0 -1
- package/dist/zod.js +0 -195
|
@@ -2,59 +2,56 @@ import './assert_dev_env.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Schema-driven value generation helpers for testing.
|
|
4
4
|
*
|
|
5
|
-
* Walks
|
|
6
|
-
*
|
|
7
|
-
* adversarial 404, and round-trip validation test suites. A
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* Walks `@fuzdev/fuz_schema` schemas to generate valid values for route
|
|
6
|
+
* params, request bodies, and URL paths. Used by adversarial input,
|
|
7
|
+
* adversarial 404, and round-trip validation test suites. A value that is no
|
|
8
|
+
* schema throws, and so does an input no body can be generated for, rather
|
|
9
|
+
* than yielding no body.
|
|
10
10
|
*
|
|
11
11
|
* @module
|
|
12
12
|
*/
|
|
13
|
-
import {
|
|
14
|
-
import { is_schema } from '@fuzdev/fuz_schema/schema.ts';
|
|
13
|
+
import { parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
15
14
|
import { get_schema_entries, get_schema_fields, unwrap_schema } from '@fuzdev/fuz_schema/introspect.ts';
|
|
16
15
|
import { to_json_schema } from '@fuzdev/fuz_schema/json_schema.ts';
|
|
17
|
-
import { zod_unwrap_def, zod_get_base_type, zod_unwrap_to_object, zod_extract_fields } from '../zod.js';
|
|
18
16
|
import { is_null_schema, is_void_schema } from '../http/schema_helpers.js';
|
|
19
17
|
import { compile_route_param_pattern, decode_route_path, parse_route_param, split_route_template } from '../http/route_error_check.js';
|
|
20
|
-
import {
|
|
18
|
+
import { assert_validation_schema, format_issues } from '../schema_issues.js';
|
|
21
19
|
/**
|
|
22
20
|
* The JSON Schema of a field's input side — where its format, pattern and
|
|
23
|
-
* bounds live.
|
|
21
|
+
* bounds live.
|
|
24
22
|
*
|
|
25
|
-
* Rendered with `io: 'input'`, so a field carrying a
|
|
23
|
+
* Rendered with `io: 'input'`, so a field carrying a `transform` in a pipe
|
|
26
24
|
* (`Username`) still yields the constraints its input is checked against;
|
|
27
25
|
* the default output side throws on a transform. A pipe yields its input
|
|
28
26
|
* side only, so constraints of the stage after it are not here. A
|
|
29
|
-
*
|
|
30
|
-
*
|
|
27
|
+
* `nullable` field renders as `anyOf: [{…}, {type: 'null'}]`, or a bare
|
|
28
|
+
* type as `type: [type, 'null']`;
|
|
31
29
|
* its one non-null branch or type is returned, so the bounds, pattern and
|
|
32
30
|
* `type` read the same as on the bare field. A union of two or more non-null
|
|
33
31
|
* branches returns the whole schema — its branches' bounds are no single
|
|
34
32
|
* field's bounds.
|
|
35
33
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* generators build from it is checked against the field itself before it's
|
|
42
|
-
* used. What an emitter refuses even then (a fuz_schema entry named like a
|
|
34
|
+
* It renders with `unrepresentable: 'any'`: a part JSON Schema can't say (a
|
|
35
|
+
* `check` or a `bigint`) is left out or `{}`, and the bounds around it still
|
|
36
|
+
* read, so a `pipe(string, max_length(n), check(…))` keeps its `maxLength` —
|
|
37
|
+
* every case the generators build from it is checked against the field itself
|
|
38
|
+
* before it's used. What the emitter refuses even then (an entry named like a
|
|
43
39
|
* member of `Object.prototype`, metadata that isn't JSON) throws: a mistake in
|
|
44
40
|
* the schema, not a gap in JSON Schema.
|
|
45
41
|
*
|
|
46
|
-
* A
|
|
47
|
-
*
|
|
48
|
-
*
|
|
42
|
+
* A `check` is never here: JSON Schema can't express one, so a bound a check
|
|
43
|
+
* enforces (a code-point length, a cross-field rule) generates no boundary
|
|
44
|
+
* case.
|
|
49
45
|
*
|
|
50
46
|
* @param field_schema - the field to read
|
|
51
47
|
* @returns the field's input-side JSON Schema
|
|
52
48
|
* @throws Error when the emitter refuses `field_schema` with `unrepresentable: 'any'`
|
|
53
49
|
*/
|
|
54
50
|
export const to_field_json_schema = (field_schema) => {
|
|
55
|
-
const json =
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
const json = to_json_schema(field_schema, {
|
|
52
|
+
io: 'input',
|
|
53
|
+
unrepresentable: 'any'
|
|
54
|
+
});
|
|
58
55
|
if (Array.isArray(json.anyOf)) {
|
|
59
56
|
const branches = json.anyOf.filter((branch) => branch.type !== 'null');
|
|
60
57
|
if (branches.length === 1)
|
|
@@ -111,8 +108,8 @@ export const detect_format = (field_schema) => detect_json_schema_format(to_fiel
|
|
|
111
108
|
* - Optional prefix: alphanumeric, starting with a letter, ending in `:`
|
|
112
109
|
* (`blake3:`, `sha256:`). A `_`-joined prefix over a base64url class is
|
|
113
110
|
* the sibling shape — see `generate_prefix_slug_pattern_value`.
|
|
114
|
-
* - Character class must be exactly `[0-9a-f]` or `[0-9a-fA-F]` (
|
|
115
|
-
* the regex source
|
|
111
|
+
* - Character class must be exactly `[0-9a-f]` or `[0-9a-fA-F]` (the JSON
|
|
112
|
+
* Schema carries the regex source verbatim — no character-class reordering).
|
|
116
113
|
* - Fixed-length quantifier `{N}`.
|
|
117
114
|
*
|
|
118
115
|
* Returns `null` when the pattern doesn't match the expected shape; the
|
|
@@ -140,8 +137,8 @@ const generate_hex_pattern_value = (pattern) => {
|
|
|
140
137
|
*
|
|
141
138
|
* Coverage today:
|
|
142
139
|
* - Prefix must start with a letter and be alphanumeric (e.g. `tok_`, `ses_`).
|
|
143
|
-
* - Character class must be exactly `[A-Za-z0-9_-]` (
|
|
144
|
-
* source
|
|
140
|
+
* - Character class must be exactly `[A-Za-z0-9_-]` (the JSON Schema carries
|
|
141
|
+
* the regex source verbatim — no character-class reordering).
|
|
145
142
|
* - Fixed-length quantifier `{N}`.
|
|
146
143
|
*
|
|
147
144
|
* Known gaps (will fall through to the absolute-path / URL candidates or
|
|
@@ -165,16 +162,16 @@ const generate_prefix_slug_pattern_value = (pattern) => {
|
|
|
165
162
|
return null;
|
|
166
163
|
return `${prefix}_${'x'.repeat(n)}`;
|
|
167
164
|
};
|
|
168
|
-
// --- reading a schema
|
|
169
|
-
/** Whether `schema` accepts `value
|
|
170
|
-
const accepts = (schema, value) =>
|
|
165
|
+
// --- reading a schema ---
|
|
166
|
+
/** Whether `schema` accepts `value`. */
|
|
167
|
+
const accepts = (schema, value) => parse(schema, value).ok;
|
|
171
168
|
/**
|
|
172
|
-
* Every layer of a
|
|
169
|
+
* Every layer of a schema, from the schema itself through
|
|
173
170
|
* each `optional`, `nullable`, `with_default`, `with_default_fn`, the first
|
|
174
171
|
* schema of a `pipe`, and a `lazy`'s schema, to what the value is — the
|
|
175
172
|
* layers `unwrap_schema` walks.
|
|
176
173
|
*/
|
|
177
|
-
const
|
|
174
|
+
const schema_layers = (schema) => {
|
|
178
175
|
const layers = [];
|
|
179
176
|
const seen = new Set();
|
|
180
177
|
let s = schema;
|
|
@@ -200,13 +197,12 @@ const fuz_schema_layers = (schema) => {
|
|
|
200
197
|
return layers;
|
|
201
198
|
};
|
|
202
199
|
/**
|
|
203
|
-
* The type name the generators switch on
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* `variant` `'union'`.
|
|
200
|
+
* The type name the generators switch on (`SchemaFieldInfo.base_type`): the
|
|
201
|
+
* schema's innermost layer's kind, with an object schema of any strictness
|
|
202
|
+
* `'object'`, a `literal(null)` `'null'`, a `literal(undefined)` (`s.void`)
|
|
203
|
+
* `'void'`, a `one_of` `'enum'`, and a `variant` `'union'`.
|
|
208
204
|
*/
|
|
209
|
-
const
|
|
205
|
+
const to_base_type = (schema) => {
|
|
210
206
|
const base = unwrap_schema(schema);
|
|
211
207
|
switch (base.kind) {
|
|
212
208
|
case 'object':
|
|
@@ -224,49 +220,35 @@ const fuz_schema_base_type = (schema) => {
|
|
|
224
220
|
return base.kind;
|
|
225
221
|
}
|
|
226
222
|
};
|
|
227
|
-
// the
|
|
228
|
-
|
|
229
|
-
// the fields of `schema` when its innermost layer is an object schema, else `null`;
|
|
230
|
-
// throws for a schema of neither library
|
|
223
|
+
// the fields of `schema` when its innermost layer is an object schema, else
|
|
224
|
+
// `null`; throws for a value that is no schema
|
|
231
225
|
const to_object_view = (schema, label) => {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return null;
|
|
236
|
-
return {
|
|
237
|
-
fields: get_schema_fields(schema).map((field) => {
|
|
238
|
-
const layers = fuz_schema_layers(field.schema);
|
|
239
|
-
return {
|
|
240
|
-
name: field.name,
|
|
241
|
-
base_type: fuz_schema_base_type(field.schema),
|
|
242
|
-
required: !layers.some((l) => l.kind === 'optional'),
|
|
243
|
-
has_default: field.has_default,
|
|
244
|
-
nullable: layers.some((l) => l.kind === 'nullable')
|
|
245
|
-
};
|
|
246
|
-
}),
|
|
247
|
-
field_schema: (name) => (Object.hasOwn(entries, name) ? entries[name] : undefined)
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
assert_zod_schema(schema, label);
|
|
251
|
-
const object_schema = zod_unwrap_to_object(schema);
|
|
252
|
-
if (!object_schema)
|
|
226
|
+
assert_validation_schema(schema, label);
|
|
227
|
+
const entries = get_schema_entries(schema);
|
|
228
|
+
if (!entries)
|
|
253
229
|
return null;
|
|
254
|
-
const shape = object_schema.shape;
|
|
255
230
|
return {
|
|
256
|
-
fields:
|
|
257
|
-
|
|
231
|
+
fields: get_schema_fields(schema).map((field) => {
|
|
232
|
+
const layers = schema_layers(field.schema);
|
|
233
|
+
return {
|
|
234
|
+
name: field.name,
|
|
235
|
+
base_type: to_base_type(field.schema),
|
|
236
|
+
required: !layers.some((l) => l.kind === 'optional'),
|
|
237
|
+
has_default: field.has_default,
|
|
238
|
+
nullable: layers.some((l) => l.kind === 'nullable')
|
|
239
|
+
};
|
|
240
|
+
}),
|
|
241
|
+
field_schema: (name) => (Object.hasOwn(entries, name) ? entries[name] : undefined)
|
|
258
242
|
};
|
|
259
243
|
};
|
|
260
244
|
/**
|
|
261
|
-
* The fields of an object schema
|
|
262
|
-
*
|
|
263
|
-
* (`
|
|
264
|
-
* schema whose innermost layer is an object schema (`get_schema_entries`,
|
|
265
|
-
* `get_schema_fields`).
|
|
245
|
+
* The fields of an object schema and the schema of each, through its
|
|
246
|
+
* wrappers: a schema whose innermost layer is an object schema
|
|
247
|
+
* (`get_schema_entries`, `get_schema_fields`).
|
|
266
248
|
*
|
|
267
|
-
* @param schema - an object schema, possibly wrapped
|
|
249
|
+
* @param schema - an object schema, possibly wrapped
|
|
268
250
|
* @param label - names the schema in the error
|
|
269
|
-
* @throws Error naming `label` when `schema` is no object schema, or
|
|
251
|
+
* @throws Error naming `label` when `schema` is no object schema, or no schema
|
|
270
252
|
*/
|
|
271
253
|
export const to_object_schema_view = (schema, label) => {
|
|
272
254
|
const view = to_object_view(schema, label);
|
|
@@ -308,8 +290,8 @@ const generate_valid_string = (field_schema) => {
|
|
|
308
290
|
}
|
|
309
291
|
// Email-shaped refinement (the `Email` primitive: loose `local@domain.tld`).
|
|
310
292
|
// The base `x`-fill has no `@`, so an email-pattern field needs a shaped
|
|
311
|
-
// candidate — the
|
|
312
|
-
//
|
|
293
|
+
// candidate — the regex form exposes a `pattern`, not the `format: 'email'`
|
|
294
|
+
// the `case 'email'` switch arm keys on.
|
|
313
295
|
const as_email = 'test@example.com';
|
|
314
296
|
if (accepts(field_schema, as_email))
|
|
315
297
|
return as_email;
|
|
@@ -327,56 +309,34 @@ const generate_valid_string = (field_schema) => {
|
|
|
327
309
|
return segments;
|
|
328
310
|
return base; // fall through — generate_valid_body will report the failure
|
|
329
311
|
};
|
|
330
|
-
// the element schema of an array field
|
|
312
|
+
// the element schema of an array field
|
|
331
313
|
const to_array_element = (field_schema) => {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
return base.kind === 'array' ? base.def : undefined;
|
|
335
|
-
}
|
|
336
|
-
return zod_unwrap_def(field_schema).element;
|
|
314
|
+
const base = unwrap_schema(field_schema);
|
|
315
|
+
return base.kind === 'array' ? base.def : undefined;
|
|
337
316
|
};
|
|
338
|
-
// the first option of a union field
|
|
317
|
+
// the first option of a union field
|
|
339
318
|
const to_first_union_option = (field_schema) => {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
return undefined;
|
|
347
|
-
}
|
|
348
|
-
// Zod 4 represents `z.union` and `z.discriminatedUnion` alike, `def.type ===
|
|
349
|
-
// 'union'` with a `def.options` array
|
|
350
|
-
return zod_unwrap_def(field_schema).options?.[0];
|
|
319
|
+
const base = unwrap_schema(field_schema);
|
|
320
|
+
if (base.kind === 'union')
|
|
321
|
+
return base.def[0];
|
|
322
|
+
if (base.kind === 'variant')
|
|
323
|
+
return base.def.options[0];
|
|
324
|
+
return undefined;
|
|
351
325
|
};
|
|
352
|
-
// the values a literal or enum field accepts,
|
|
326
|
+
// the values a literal or enum field accepts, in declared order
|
|
353
327
|
const to_literal_values = (field_schema) => {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
return base.def;
|
|
360
|
-
return [];
|
|
361
|
-
}
|
|
362
|
-
const def = zod_unwrap_def(field_schema);
|
|
363
|
-
// Zod 4 stores literal values on `def.values` (always an array, even for
|
|
364
|
-
// single-valued literals), and enum entries as an object `{key: value}`
|
|
365
|
-
if ('values' in def && Array.isArray(def.values))
|
|
366
|
-
return def.values;
|
|
367
|
-
if ('entries' in def) {
|
|
368
|
-
const entries = def.entries;
|
|
369
|
-
if (entries && typeof entries === 'object') {
|
|
370
|
-
return Object.values(entries);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
328
|
+
const base = unwrap_schema(field_schema);
|
|
329
|
+
if (base.kind === 'literal')
|
|
330
|
+
return [base.def];
|
|
331
|
+
if (base.kind === 'one_of')
|
|
332
|
+
return base.def;
|
|
373
333
|
return [];
|
|
374
334
|
};
|
|
375
335
|
/**
|
|
376
336
|
* Generate a valid-ish value for a field based on its base type.
|
|
377
337
|
*
|
|
378
|
-
* @param field - the field's info, from `to_object_schema_view`
|
|
379
|
-
* @param field_schema - the field's schema
|
|
338
|
+
* @param field - the field's info, from `to_object_schema_view`
|
|
339
|
+
* @param field_schema - the field's schema
|
|
380
340
|
* @returns the value, checked by the caller against the whole schema
|
|
381
341
|
*/
|
|
382
342
|
export const generate_valid_value = (field, field_schema) => {
|
|
@@ -394,8 +354,7 @@ export const generate_valid_value = (field, field_schema) => {
|
|
|
394
354
|
if (format === 'date-time')
|
|
395
355
|
return '2020-01-01T00:00:00.000Z';
|
|
396
356
|
return generate_valid_string(field_schema);
|
|
397
|
-
case 'number':
|
|
398
|
-
case 'int': {
|
|
357
|
+
case 'number': {
|
|
399
358
|
// 1, unless the schema's bounds rule it out (`.negative()`, `.min(10)`)
|
|
400
359
|
for (const candidate of [1, -1, 0]) {
|
|
401
360
|
if (accepts(field_schema, candidate))
|
|
@@ -404,12 +363,8 @@ export const generate_valid_value = (field, field_schema) => {
|
|
|
404
363
|
const json = to_field_json_schema(field_schema);
|
|
405
364
|
if (typeof json.minimum === 'number')
|
|
406
365
|
return Math.ceil(json.minimum);
|
|
407
|
-
if (typeof json.exclusiveMinimum === 'number')
|
|
408
|
-
return Math.floor(json.exclusiveMinimum) + 1;
|
|
409
366
|
if (typeof json.maximum === 'number')
|
|
410
367
|
return Math.floor(json.maximum);
|
|
411
|
-
if (typeof json.exclusiveMaximum === 'number')
|
|
412
|
-
return Math.ceil(json.exclusiveMaximum) - 1;
|
|
413
368
|
return 1; // fall through — generate_valid_body will report the failure
|
|
414
369
|
}
|
|
415
370
|
case 'boolean':
|
|
@@ -481,14 +436,13 @@ export const generate_valid_value = (field, field_schema) => {
|
|
|
481
436
|
* Shared by the top-level body generators and `generate_valid_value`'s
|
|
482
437
|
* nested-object case, so a refined object validates the same way at any depth.
|
|
483
438
|
*
|
|
484
|
-
* @param object_schema - the object whose fields are generated:
|
|
485
|
-
*
|
|
439
|
+
* @param object_schema - the object whose fields are generated: an object
|
|
440
|
+
* schema, possibly wrapped
|
|
486
441
|
* @param schema - the schema the object must satisfy, refinements included
|
|
487
442
|
* (`object_schema` or a schema wrapping it)
|
|
488
|
-
* @returns the generated object and its last `
|
|
443
|
+
* @returns the generated object and its last `parse` result — the caller
|
|
489
444
|
* decides whether a failure throws
|
|
490
|
-
* @throws Error when `object_schema` is no object schema, or
|
|
491
|
-
* of neither library
|
|
445
|
+
* @throws Error when `object_schema` is no object schema, or no schema
|
|
492
446
|
*/
|
|
493
447
|
export const generate_valid_object = (object_schema, schema) => generate_valid_object_from_view(to_object_schema_view(object_schema, 'generate_valid_object: the object schema'), schema);
|
|
494
448
|
const generate_valid_object_from_view = (view, schema) => {
|
|
@@ -516,13 +470,13 @@ const is_optional_field = (field) => !field.required && !field.has_default;
|
|
|
516
470
|
* @returns the object and its last parse
|
|
517
471
|
*/
|
|
518
472
|
const fill_optional_fields = (schema, start, candidates) => {
|
|
519
|
-
let result =
|
|
473
|
+
let result = parse(schema, start);
|
|
520
474
|
if (result.ok)
|
|
521
475
|
return { value: start, result };
|
|
522
476
|
// each optional field alone, so one the refinement doesn't need stays out
|
|
523
477
|
for (const [name, field_value] of candidates) {
|
|
524
478
|
const value = { ...start, [name]: field_value };
|
|
525
|
-
const single_result =
|
|
479
|
+
const single_result = parse(schema, value);
|
|
526
480
|
if (single_result.ok)
|
|
527
481
|
return { value, result: single_result };
|
|
528
482
|
}
|
|
@@ -530,7 +484,7 @@ const fill_optional_fields = (schema, start, candidates) => {
|
|
|
530
484
|
const value = { ...start };
|
|
531
485
|
for (const [name, field_value] of candidates) {
|
|
532
486
|
value[name] = field_value;
|
|
533
|
-
result =
|
|
487
|
+
result = parse(schema, value);
|
|
534
488
|
if (result.ok)
|
|
535
489
|
break;
|
|
536
490
|
}
|
|
@@ -546,15 +500,14 @@ const fill_optional_fields = (schema, start, candidates) => {
|
|
|
546
500
|
* replaces `base`'s optional fields, refilled the same way around it (an
|
|
547
501
|
* exactly-one-of rule: adding `slug` means dropping `id`).
|
|
548
502
|
*
|
|
549
|
-
* @param object_schema - the object schema `base` is an instance of,
|
|
550
|
-
*
|
|
503
|
+
* @param object_schema - the object schema `base` is an instance of,
|
|
504
|
+
* possibly wrapped
|
|
551
505
|
* @param schema - the schema the object must satisfy, refinements included
|
|
552
506
|
* @param base - a valid object, the generated or seeded base
|
|
553
507
|
* @param field - the field the object must carry
|
|
554
508
|
* @returns the object, or `null` when no object the generator can build
|
|
555
509
|
* carries the field and passes `schema`
|
|
556
|
-
* @throws Error when `object_schema` is no object schema, or
|
|
557
|
-
* of neither library
|
|
510
|
+
* @throws Error when `object_schema` is no object schema, or no schema
|
|
558
511
|
*/
|
|
559
512
|
export const generate_valid_object_with_field = (object_schema, schema, base, field) => {
|
|
560
513
|
if (Object.hasOwn(base, field.name))
|
|
@@ -587,17 +540,55 @@ export const generate_valid_object_with_field = (object_schema, schema, base, fi
|
|
|
587
540
|
return replaced.result.ok ? replaced.value : null;
|
|
588
541
|
};
|
|
589
542
|
const NIL_UUID = '00000000-0000-0000-0000-000000000000';
|
|
543
|
+
/**
|
|
544
|
+
* The bounds of every `min_value` and `max_value` a schema holds, in every
|
|
545
|
+
* stage of every `pipe` and through its wrappers — including the stages after
|
|
546
|
+
* a `transform`, which its JSON Schema can't say: a URL string parsed into a
|
|
547
|
+
* number is bounded only there (`db_routes`' `query_int`).
|
|
548
|
+
*/
|
|
549
|
+
const to_numeric_bounds = (schema) => {
|
|
550
|
+
const bounds = { min: [], max: [] };
|
|
551
|
+
const seen = new Set();
|
|
552
|
+
const pending = [schema];
|
|
553
|
+
while (pending.length > 0) {
|
|
554
|
+
const s = pending.pop();
|
|
555
|
+
if (seen.has(s))
|
|
556
|
+
continue;
|
|
557
|
+
seen.add(s);
|
|
558
|
+
if (s.kind === 'optional' ||
|
|
559
|
+
s.kind === 'nullable' ||
|
|
560
|
+
s.kind === 'with_default' ||
|
|
561
|
+
s.kind === 'with_default_fn') {
|
|
562
|
+
pending.push(s.def.schema);
|
|
563
|
+
}
|
|
564
|
+
else if (s.kind === 'pipe') {
|
|
565
|
+
pending.push(...s.def);
|
|
566
|
+
}
|
|
567
|
+
else if (s.kind === 'lazy') {
|
|
568
|
+
pending.push(s.def());
|
|
569
|
+
}
|
|
570
|
+
else if (s.kind === 'min_value' && typeof s.def === 'number') {
|
|
571
|
+
bounds.min.push(s.def);
|
|
572
|
+
}
|
|
573
|
+
else if (s.kind === 'max_value' && typeof s.def === 'number') {
|
|
574
|
+
bounds.max.push(s.def);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
return bounds;
|
|
578
|
+
};
|
|
590
579
|
/**
|
|
591
580
|
* A string a URL-sourced field accepts — a route param or a query value, which
|
|
592
581
|
* arrive as strings whatever the schema parses them into. The nil UUID for a
|
|
593
582
|
* UUID field; else the first the field accepts of `test_value`, the generated
|
|
594
583
|
* valid value written as a string, `1`, `0`, `true` and `false`, the field's
|
|
595
|
-
* JSON Schema `default` or lower bound written as a string
|
|
596
|
-
*
|
|
597
|
-
*
|
|
584
|
+
* JSON Schema `default` or lower bound written as a string, each
|
|
585
|
+
* `min_value` and `max_value` bound anywhere in the schema written as an
|
|
586
|
+
* integer (a string parsed into an integer whose range excludes the small
|
|
587
|
+
* candidates, `to_numeric_bounds`), and a string synthesized from the field's
|
|
588
|
+
* constraints.
|
|
598
589
|
*
|
|
599
|
-
* @param field - the field's info, from `to_object_schema_view`
|
|
600
|
-
* @param field_schema - the field's schema
|
|
590
|
+
* @param field - the field's info, from `to_object_schema_view`
|
|
591
|
+
* @param field_schema - the field's schema
|
|
601
592
|
* @returns the string, or `null` when no candidate passes
|
|
602
593
|
*/
|
|
603
594
|
export const generate_valid_string_param = (field, field_schema) => {
|
|
@@ -621,9 +612,11 @@ export const generate_valid_string_param = (field, field_schema) => {
|
|
|
621
612
|
}
|
|
622
613
|
if (typeof json.minimum === 'number')
|
|
623
614
|
candidates.push(String(Math.ceil(json.minimum)));
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
615
|
+
const bounds = to_numeric_bounds(field_schema);
|
|
616
|
+
for (const min of bounds.min)
|
|
617
|
+
candidates.push(String(Math.ceil(min)));
|
|
618
|
+
for (const max of bounds.max)
|
|
619
|
+
candidates.push(String(Math.floor(max)));
|
|
627
620
|
candidates.push(generate_valid_string(field_schema));
|
|
628
621
|
return candidates.find((c) => accepts(field_schema, c)) ?? null;
|
|
629
622
|
};
|
|
@@ -632,9 +625,9 @@ export const generate_valid_string_param = (field, field_schema) => {
|
|
|
632
625
|
* (`is_void_schema`, `is_null_schema`), which takes no body, else its object
|
|
633
626
|
* view (`to_object_schema_view`).
|
|
634
627
|
*
|
|
635
|
-
* @param input_schema - a route's or action's input schema
|
|
628
|
+
* @param input_schema - a route's or action's input schema
|
|
636
629
|
* @param label - names the input in the error
|
|
637
|
-
* @throws Error naming `label` when the input is
|
|
630
|
+
* @throws Error naming `label` when the input is no schema, or is
|
|
638
631
|
* neither void, null, nor an object schema — no body can be generated for
|
|
639
632
|
* it, and no body is not the same as one the generator can't build
|
|
640
633
|
*/
|
|
@@ -644,7 +637,7 @@ export const to_body_input = (input_schema, label) => {
|
|
|
644
637
|
const view = to_object_view(input_schema, label);
|
|
645
638
|
if (!view) {
|
|
646
639
|
if (to_base_type(input_schema) === 'void') {
|
|
647
|
-
throw new Error(`${label} is a void under wrappers, which dispatch does not read as void (\`is_void_schema\` is exact): absent params reach it as \`{}\`, which it refuses — declare the input as a bare \`
|
|
640
|
+
throw new Error(`${label} is a void under wrappers, which dispatch does not read as void (\`is_void_schema\` is exact): absent params reach it as \`{}\`, which it refuses — declare the input as a bare \`s.void\``);
|
|
648
641
|
}
|
|
649
642
|
throw new Error(`${label} is no object, void or null schema (its innermost type is '${to_base_type(input_schema)}'), so no body can be generated for it`);
|
|
650
643
|
}
|
|
@@ -693,9 +686,9 @@ export const to_route_content_type = (route) => route.raw_body ? 'application/oc
|
|
|
693
686
|
* (`''`, `.`, `..`) is refused by name.
|
|
694
687
|
*
|
|
695
688
|
* @param path - the route's path template
|
|
696
|
-
* @param params_schema - the route's params schema,
|
|
689
|
+
* @param params_schema - the route's params schema, an object schema
|
|
697
690
|
* @param param_values - the route's supplied param values by name, its entry of `RouteParamValues`
|
|
698
|
-
* @throws Error when `params_schema` is no object schema, or
|
|
691
|
+
* @throws Error when `params_schema` is no object schema, or no schema;
|
|
699
692
|
* when `param_values` names no param of the path; when a supplied value is
|
|
700
693
|
* `''`, `.` or `..`, or holds a lone surrogate, which can't be encoded; and
|
|
701
694
|
* when a `{re}` param's value is one its pattern refuses, naming the route
|
|
@@ -762,10 +755,10 @@ export const resolve_valid_path = (path, params_schema, param_values) => {
|
|
|
762
755
|
/**
|
|
763
756
|
* Generate a valid request body for a route's or action's input schema.
|
|
764
757
|
*
|
|
765
|
-
* @param input_schema - the input schema
|
|
758
|
+
* @param input_schema - the input schema
|
|
766
759
|
* @returns a generated body that passes the schema, or `undefined` for a void
|
|
767
760
|
* or null input, which takes no body
|
|
768
|
-
* @throws Error if the input is
|
|
761
|
+
* @throws Error if the input is no schema, or is neither void, null,
|
|
769
762
|
* nor an object schema, or if the generated body fails the input — catching
|
|
770
763
|
* broken `generate_valid_value` logic early with the parse's issues instead
|
|
771
764
|
* of a confusing 400 in downstream tests
|