@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
package/dist/schema_issues.js
CHANGED
|
@@ -1,110 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Validation issues
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* helpers read either, so the dispatcher, `ActionEvent` and the
|
|
6
|
-
* forward-compatible reads treat a spec the same whichever library it is
|
|
7
|
-
* written in, and an error response carries either library's issues in one
|
|
8
|
-
* shape, `WireIssue`.
|
|
2
|
+
* Validation issues of a `@fuzdev/fuz_schema` parse (`SchemaIssue`) as the
|
|
3
|
+
* stack reads them: on the input or on a field, unknown keys, text, and the
|
|
4
|
+
* one shape every error response carries them in, `WireIssue`.
|
|
9
5
|
*
|
|
10
6
|
* @module
|
|
11
7
|
*/
|
|
12
|
-
import {
|
|
13
|
-
import { array, format_issue, is_schema, loose_object, number, parse, SchemaError, string, union } from '@fuzdev/fuz_schema/schema.ts';
|
|
8
|
+
import { array, format_issue, is_schema, loose_object, number, SchemaError, string, union } from '@fuzdev/fuz_schema/schema.ts';
|
|
14
9
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @param value - any value
|
|
19
|
-
*/
|
|
20
|
-
export const is_zod_schema = (value) => value instanceof z.ZodType;
|
|
21
|
-
/**
|
|
22
|
-
* Throw unless `value` is a Zod schema, naming `label` — what a reader of a
|
|
23
|
-
* spec's schema calls once it has ruled out a `@fuzdev/fuz_schema` schema
|
|
24
|
-
* (`is_schema`), so a value of neither library fails loudly where it is read,
|
|
25
|
-
* rather than as a `TypeError` deeper in or a silent `undefined`.
|
|
26
|
-
*
|
|
27
|
-
* @param value - the schema, known not to be a fuz_schema schema
|
|
28
|
-
* @param label - names the schema in the error, e.g. `` `action 'foo' input` ``
|
|
29
|
-
* @throws Error when `value` is not a Zod schema, saying it is of neither library
|
|
30
|
-
*/
|
|
31
|
-
export function assert_zod_schema(value, label) {
|
|
32
|
-
if (is_zod_schema(value))
|
|
33
|
-
return;
|
|
34
|
-
throw new Error(`${label} is neither a Zod schema nor a @fuzdev/fuz_schema schema`);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Throw unless `value` is a schema of either library (`is_schema` or
|
|
38
|
-
* `is_zod_schema`), naming `label` — what spec registration runs on each
|
|
39
|
-
* schema slot, so a value of neither library fails at registration rather
|
|
40
|
-
* than at request time.
|
|
10
|
+
* Throw unless `value` is a `@fuzdev/fuz_schema` schema (`is_schema`), naming
|
|
11
|
+
* `label` — what spec registration runs on each schema slot, so a value that
|
|
12
|
+
* is no schema fails at registration rather than at request time.
|
|
41
13
|
*
|
|
42
14
|
* @param value - the value a spec declares as a schema
|
|
43
15
|
* @param label - names the spec and slot in the error, e.g. `` `RPC action "foo": input` ``
|
|
44
|
-
* @throws Error when `value` is
|
|
16
|
+
* @throws Error when `value` is not a fuz_schema schema
|
|
45
17
|
*/
|
|
46
18
|
export function assert_validation_schema(value, label) {
|
|
47
19
|
if (is_schema(value))
|
|
48
20
|
return;
|
|
49
|
-
|
|
21
|
+
throw new Error(`${label} is not a @fuzdev/fuz_schema schema`);
|
|
50
22
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Parse `value` with a schema of either library: `parse` for a fuz_schema
|
|
53
|
-
* schema (`is_schema`), `safeParse` for a Zod one.
|
|
54
|
-
*
|
|
55
|
-
* A fuz_schema parse reports at most its first hundred issues, a Zod parse
|
|
56
|
-
* every issue.
|
|
57
|
-
*
|
|
58
|
-
* @param schema - a Zod or fuz_schema schema
|
|
59
|
-
* @param value - the value to validate
|
|
60
|
-
* @returns the output, or the issues
|
|
61
|
-
* @throws Error when `schema` is neither a Zod nor a fuz_schema schema
|
|
62
|
-
*/
|
|
63
|
-
export const parse_any = (schema, value) => {
|
|
64
|
-
if (is_schema(schema)) {
|
|
65
|
-
const result = parse(schema, value);
|
|
66
|
-
return result.ok
|
|
67
|
-
? { ok: true, value: result.value }
|
|
68
|
-
: { ok: false, issues: result.issues };
|
|
69
|
-
}
|
|
70
|
-
assert_zod_schema(schema, 'parse_any: the schema');
|
|
71
|
-
const result = schema.safeParse(value);
|
|
72
|
-
return result.success
|
|
73
|
-
? { ok: true, value: result.data }
|
|
74
|
-
: { ok: false, issues: result.error.issues };
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Whether `issue` is Zod's: every Zod issue has a `code`, a fuz_schema issue a `kind`.
|
|
78
|
-
*/
|
|
79
|
-
export const is_zod_issue = (issue) => 'code' in issue;
|
|
80
23
|
/**
|
|
81
24
|
* Whether `issue` sits on the input itself rather than on one of its fields:
|
|
82
25
|
* a non-object input, or an unknown key on the input object — what the Rust
|
|
83
26
|
* twin refuses before reading any field.
|
|
84
27
|
*
|
|
85
|
-
*
|
|
86
|
-
* fuz_schema reports a non-object at an empty path and each unknown key as an
|
|
28
|
+
* A non-object is reported at an empty path, and each unknown key as an
|
|
87
29
|
* `unknown_key` issue whose path ends at the key, so one on the input has a
|
|
88
|
-
* path of the key alone. An unknown key on a nested object is on that field
|
|
89
|
-
* as Zod's is.
|
|
30
|
+
* path of the key alone. An unknown key on a nested object is on that field.
|
|
90
31
|
*
|
|
91
32
|
* On the wire the `unknown_key` rule changes no answer today: a root
|
|
92
33
|
* `unknown_key` comes from a root `object`, which `resolve_issues_invalid_reason`
|
|
93
34
|
* already answers with none from its check of the input's keys, or from a
|
|
94
35
|
* schema such as a `variant` whose fields resolve no reason. It is kept as the
|
|
95
|
-
* direct statement of
|
|
36
|
+
* direct statement of the rule.
|
|
96
37
|
*
|
|
97
38
|
* @param issue - one issue of a failed parse
|
|
98
39
|
*/
|
|
99
|
-
export const issue_is_on_input = (issue) => issue.path.length === 0 ||
|
|
100
|
-
(!is_zod_issue(issue) && issue.kind === 'unknown_key' && issue.path.length === 1);
|
|
40
|
+
export const issue_is_on_input = (issue) => issue.path.length === 0 || (issue.kind === 'unknown_key' && issue.path.length === 1);
|
|
101
41
|
/**
|
|
102
42
|
* The unknown keys among `issues`, each with the path of its object, or
|
|
103
|
-
* `null` when any issue is something else.
|
|
104
|
-
*
|
|
105
|
-
* A Zod `unrecognized_keys` issue is at its object's path and names every
|
|
106
|
-
* key; a fuz_schema `unknown_key` issue is one key, the last element of its
|
|
107
|
-
* path.
|
|
43
|
+
* `null` when any issue is something else. An `unknown_key` issue is one
|
|
44
|
+
* key, the last element of its path.
|
|
108
45
|
*
|
|
109
46
|
* @param issues - a failed parse's issues
|
|
110
47
|
* @returns a target per issue, or `null` when not every issue is an unknown key
|
|
@@ -112,47 +49,29 @@ export const issue_is_on_input = (issue) => issue.path.length === 0 ||
|
|
|
112
49
|
export const unknown_key_targets = (issues) => {
|
|
113
50
|
const targets = [];
|
|
114
51
|
for (const issue of issues) {
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
targets.push({ path: issue.path, keys: issue.keys });
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
if (issue.kind !== 'unknown_key' || issue.path.length === 0)
|
|
122
|
-
return null;
|
|
123
|
-
targets.push({ path: issue.path.slice(0, -1), keys: [issue.path.at(-1)] });
|
|
124
|
-
}
|
|
52
|
+
if (issue.kind !== 'unknown_key' || issue.path.length === 0)
|
|
53
|
+
return null;
|
|
54
|
+
targets.push({ path: issue.path.slice(0, -1), keys: [issue.path.at(-1)] });
|
|
125
55
|
}
|
|
126
56
|
return targets;
|
|
127
57
|
};
|
|
128
58
|
/**
|
|
129
|
-
* A failed parse's issues as text
|
|
130
|
-
* issues, and for fuz_schema issues their `format_issue` lines.
|
|
59
|
+
* A failed parse's issues as text, a `format_issue` line each.
|
|
131
60
|
*
|
|
132
|
-
* @param issues - a failed parse's issues
|
|
61
|
+
* @param issues - a failed parse's issues
|
|
133
62
|
*/
|
|
134
|
-
export const format_issues = (issues) =>
|
|
135
|
-
const first = issues[0];
|
|
136
|
-
if (!first)
|
|
137
|
-
return '';
|
|
138
|
-
if (is_zod_issue(first)) {
|
|
139
|
-
return z.prettifyError({ issues: issues });
|
|
140
|
-
}
|
|
141
|
-
return issues.map(format_issue).join('\n');
|
|
142
|
-
};
|
|
63
|
+
export const format_issues = (issues) => issues.map(format_issue).join('\n');
|
|
143
64
|
/**
|
|
144
|
-
* Whether `err` is a thrown validation failure
|
|
145
|
-
* `
|
|
146
|
-
* the failed parse's `issues`.
|
|
65
|
+
* Whether `err` is a thrown validation failure, a `SchemaError`
|
|
66
|
+
* (`parse_or_throw`), which carries the failed parse's `issues`.
|
|
147
67
|
*
|
|
148
68
|
* @param err - a caught value
|
|
149
69
|
*/
|
|
150
|
-
export const is_schema_validation_error = (err) => err instanceof
|
|
70
|
+
export const is_schema_validation_error = (err) => err instanceof SchemaError;
|
|
151
71
|
/**
|
|
152
72
|
* A `@fuzdev/fuz_schema` `loose_object`: a validation issue as an error
|
|
153
|
-
* response carries it
|
|
154
|
-
*
|
|
155
|
-
* from either library's issues.
|
|
73
|
+
* response carries it — `SchemaIssue` as JSON, with `message` the text of the
|
|
74
|
+
* issue. `to_wire_issues` builds it.
|
|
156
75
|
*
|
|
157
76
|
* Loose: a client reads it, and a newer server may add fields.
|
|
158
77
|
*/
|
|
@@ -165,223 +84,21 @@ export const WireIssue = loose_object({
|
|
|
165
84
|
expected: string,
|
|
166
85
|
/** The type of the value that failed: `'null'`, `'array'`, `'NaN'`, `'Infinity'`, `'-Infinity'`, or its `typeof`. */
|
|
167
86
|
received: string,
|
|
168
|
-
/** The issue as text
|
|
87
|
+
/** The issue as text, `format_issue`'s. */
|
|
169
88
|
message: string
|
|
170
89
|
});
|
|
171
90
|
/**
|
|
172
|
-
* A failed parse's issues as `WireIssue`s
|
|
91
|
+
* A failed parse's issues as `WireIssue`s: each keeps its `kind`, `path`,
|
|
92
|
+
* `expected` and `received`, and its `message` is `format_issue`'s text, the
|
|
93
|
+
* path included. A symbol key in a path goes as its text.
|
|
173
94
|
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* A Zod issue maps to the kind fuz_schema reports for the same check, its
|
|
178
|
-
* `message` Zod's own text, which names no path:
|
|
179
|
-
*
|
|
180
|
-
* - `invalid_type` — the type's kind (`string`, `number`, `boolean`,
|
|
181
|
-
* `bigint`, `object`, `record`, `array`); `int` is `integer`, a `tuple` an
|
|
182
|
-
* `array`, `null`, `undefined`, `void` and `nan` a `literal` of the value,
|
|
183
|
-
* `nonoptional` a `missing_key`, and a type fuz_schema has no kind for
|
|
184
|
-
* (`date`, `map`, `set`, `file`, `symbol`, `function`, `never`) a `check`
|
|
185
|
-
* expecting the type's name. A missing key is reported as fuz_schema
|
|
186
|
-
* reports it, as the type expected with `received: 'undefined'`.
|
|
187
|
-
* - `too_small` / `too_big` — `min_length` / `max_length` for a string,
|
|
188
|
-
* array, set or file (`length >= N`), `min_value` / `max_value` otherwise
|
|
189
|
-
* (`>= N`); an exclusive bound writes `>` or `<`, which fuz_schema has no
|
|
190
|
-
* check for, and an exact length is reported as the bound it broke.
|
|
191
|
-
* - `invalid_format` — `uuid` for a `uuid` or `guid`, `iso_datetime` for a
|
|
192
|
-
* `datetime`, `regex` for a `regex` (expecting its pattern), and a `check`
|
|
193
|
-
* expecting the format's name for every other format.
|
|
194
|
-
* - `unrecognized_keys` — an `unknown_key` per key, the key appended to the
|
|
195
|
-
* path, as fuz_schema reports them.
|
|
196
|
-
* - `invalid_union` — a `variant` expecting the options when Zod names a
|
|
197
|
-
* discriminator, else a `union` expecting each option as fuz_schema names
|
|
198
|
-
* it: by the type or the values it expected of the value, or by the
|
|
199
|
-
* value's type when the option took the type and failed a refinement or a
|
|
200
|
-
* field below. A union refused because more than one option matched is a
|
|
201
|
-
* `union` expecting `exactly one option`.
|
|
202
|
-
* - `invalid_value` — a `literal` of one value, a `one_of` of more.
|
|
203
|
-
* - `custom` — a `check`; `not_multiple_of` a `check` expecting
|
|
204
|
-
* `multiple of N`; `invalid_key` and `invalid_element` a `check` expecting
|
|
205
|
-
* `a valid key` / `a valid element`.
|
|
206
|
-
*
|
|
207
|
-
* A Zod issue holds no value, so `received` is read from `input` at the
|
|
208
|
-
* issue's path: `'undefined'` where a key is missing or the path leads
|
|
209
|
-
* through something that isn't an object. Where an earlier step of a Zod
|
|
210
|
-
* pipe replaced the value, it names the input's value, not the replacement.
|
|
211
|
-
*
|
|
212
|
-
* @param issues - a failed parse's issues, either library
|
|
213
|
-
* @param input - the value that was parsed
|
|
214
|
-
* @returns the issues, one per issue but for a Zod `unrecognized_keys`, which is one per key
|
|
95
|
+
* @param issues - a failed parse's issues
|
|
96
|
+
* @returns one per issue
|
|
215
97
|
*/
|
|
216
|
-
export const to_wire_issues = (issues
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
wire.push({
|
|
224
|
-
kind: issue.kind,
|
|
225
|
-
path: to_wire_path(issue.path),
|
|
226
|
-
expected: issue.expected,
|
|
227
|
-
received: issue.received,
|
|
228
|
-
message: format_issue(issue)
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return wire;
|
|
233
|
-
};
|
|
234
|
-
// a symbol key has no JSON form, so it goes as its text
|
|
235
|
-
const to_wire_path = (path) => path.map((key) => (typeof key === 'symbol' ? key.toString() : key));
|
|
236
|
-
// the type of a value as fuz_schema's `received` names it
|
|
237
|
-
const to_received = (value) => value === null
|
|
238
|
-
? 'null'
|
|
239
|
-
: Array.isArray(value)
|
|
240
|
-
? 'array'
|
|
241
|
-
: typeof value === 'number' && !Number.isFinite(value)
|
|
242
|
-
? String(value)
|
|
243
|
-
: typeof value;
|
|
244
|
-
// the value at `path` of `value`, by own keys, `undefined` where a key is
|
|
245
|
-
// missing or the path leads through something that isn't an object
|
|
246
|
-
const get_at = (value, path) => {
|
|
247
|
-
let at = value;
|
|
248
|
-
for (const key of path) {
|
|
249
|
-
if (at === null || typeof at !== 'object')
|
|
250
|
-
return undefined;
|
|
251
|
-
at = Object.hasOwn(at, key) ? at[key] : undefined;
|
|
252
|
-
}
|
|
253
|
-
return at;
|
|
254
|
-
};
|
|
255
|
-
// literals as fuz_schema's `expected` writes them, strings quoted
|
|
256
|
-
const format_literals = (values) => values.map((v) => (typeof v === 'string' ? JSON.stringify(v) : String(v))).join(' | ');
|
|
257
|
-
// fuz_schema's kind and `expected` for a Zod `invalid_type` issue's `expected`,
|
|
258
|
-
// where they differ from the type's own name
|
|
259
|
-
const ZOD_TYPE_KINDS = {
|
|
260
|
-
string: { kind: 'string', expected: 'string' },
|
|
261
|
-
number: { kind: 'number', expected: 'number' },
|
|
262
|
-
boolean: { kind: 'boolean', expected: 'boolean' },
|
|
263
|
-
bigint: { kind: 'bigint', expected: 'bigint' },
|
|
264
|
-
int: { kind: 'integer', expected: 'integer' },
|
|
265
|
-
object: { kind: 'object', expected: 'object' },
|
|
266
|
-
record: { kind: 'record', expected: 'object' },
|
|
267
|
-
array: { kind: 'array', expected: 'array' },
|
|
268
|
-
tuple: { kind: 'array', expected: 'array' },
|
|
269
|
-
null: { kind: 'literal', expected: 'null' },
|
|
270
|
-
undefined: { kind: 'literal', expected: 'undefined' },
|
|
271
|
-
void: { kind: 'literal', expected: 'undefined' },
|
|
272
|
-
nan: { kind: 'literal', expected: 'NaN' },
|
|
273
|
-
nonoptional: { kind: 'missing_key', expected: 'a required key' }
|
|
274
|
-
};
|
|
275
|
-
// a Zod length origin, whose bounds fuz_schema checks as `min_length` / `max_length`
|
|
276
|
-
const ZOD_LENGTH_ORIGINS = new Set(['string', 'array', 'set', 'file']);
|
|
277
|
-
// fuz_schema's kind for a Zod `invalid_format` format, a `check` when absent
|
|
278
|
-
const ZOD_FORMAT_KINDS = {
|
|
279
|
-
uuid: 'uuid',
|
|
280
|
-
guid: 'uuid',
|
|
281
|
-
datetime: 'iso_datetime',
|
|
282
|
-
regex: 'regex'
|
|
283
|
-
};
|
|
284
|
-
// pushes the wire form of a Zod issue
|
|
285
|
-
const push_zod_wire_issues = (wire, issue, input) => {
|
|
286
|
-
const { path } = issue;
|
|
287
|
-
if (issue.code === 'unrecognized_keys') {
|
|
288
|
-
// the object holding the keys, read once so the cost is linear in keys
|
|
289
|
-
const holder = get_at(input, path);
|
|
290
|
-
for (const key of issue.keys) {
|
|
291
|
-
wire.push({
|
|
292
|
-
kind: 'unknown_key',
|
|
293
|
-
path: to_wire_path([...path, key]),
|
|
294
|
-
expected: 'no unknown keys',
|
|
295
|
-
received: to_received(get_at(holder, [key])),
|
|
296
|
-
// Zod's text names every key, so a key of several gets the one-key form
|
|
297
|
-
message: issue.keys.length === 1 ? issue.message : `Unrecognized key: ${JSON.stringify(key)}`
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
const { kind, expected } = to_zod_kind(issue, input, path);
|
|
303
|
-
wire.push({
|
|
304
|
-
kind,
|
|
305
|
-
path: to_wire_path(path),
|
|
306
|
-
expected,
|
|
307
|
-
received: to_received(get_at(input, path)),
|
|
308
|
-
message: issue.message
|
|
309
|
-
});
|
|
310
|
-
};
|
|
311
|
-
// fuz_schema's kind and `expected` for a Zod issue other than `unrecognized_keys`
|
|
312
|
-
const to_zod_kind = (issue, input, path) => {
|
|
313
|
-
switch (issue.code) {
|
|
314
|
-
case 'invalid_type':
|
|
315
|
-
return ZOD_TYPE_KINDS[issue.expected] ?? { kind: 'check', expected: issue.expected };
|
|
316
|
-
case 'too_small': {
|
|
317
|
-
const op = issue.inclusive === false ? '>' : '>=';
|
|
318
|
-
return ZOD_LENGTH_ORIGINS.has(issue.origin)
|
|
319
|
-
? { kind: 'min_length', expected: `length ${op} ${issue.minimum}` }
|
|
320
|
-
: { kind: 'min_value', expected: `${op} ${issue.minimum}` };
|
|
321
|
-
}
|
|
322
|
-
case 'too_big': {
|
|
323
|
-
const op = issue.inclusive === false ? '<' : '<=';
|
|
324
|
-
return ZOD_LENGTH_ORIGINS.has(issue.origin)
|
|
325
|
-
? { kind: 'max_length', expected: `length ${op} ${issue.maximum}` }
|
|
326
|
-
: { kind: 'max_value', expected: `${op} ${issue.maximum}` };
|
|
327
|
-
}
|
|
328
|
-
case 'invalid_format': {
|
|
329
|
-
const kind = ZOD_FORMAT_KINDS[issue.format];
|
|
330
|
-
if (kind === undefined)
|
|
331
|
-
return { kind: 'check', expected: issue.format };
|
|
332
|
-
return {
|
|
333
|
-
kind,
|
|
334
|
-
expected: kind === 'regex' ? (issue.pattern ?? 'regex') : kind
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
case 'not_multiple_of':
|
|
338
|
-
return { kind: 'check', expected: `multiple of ${issue.divisor}` };
|
|
339
|
-
case 'invalid_union':
|
|
340
|
-
if (issue.inclusive === false)
|
|
341
|
-
return { kind: 'union', expected: 'exactly one option' };
|
|
342
|
-
if (issue.discriminator !== undefined && issue.options) {
|
|
343
|
-
return { kind: 'variant', expected: format_literals(issue.options) };
|
|
344
|
-
}
|
|
345
|
-
return {
|
|
346
|
-
kind: 'union',
|
|
347
|
-
expected: [...new Set(describe_union_options(issue, input, path))].join(' | ')
|
|
348
|
-
};
|
|
349
|
-
case 'invalid_key':
|
|
350
|
-
return { kind: 'check', expected: 'a valid key' };
|
|
351
|
-
case 'invalid_element':
|
|
352
|
-
return { kind: 'check', expected: 'a valid element' };
|
|
353
|
-
case 'invalid_value':
|
|
354
|
-
return {
|
|
355
|
-
kind: issue.values.length === 1 ? 'literal' : 'one_of',
|
|
356
|
-
expected: format_literals(issue.values)
|
|
357
|
-
};
|
|
358
|
-
case 'custom':
|
|
359
|
-
return { kind: 'check', expected: 'check' };
|
|
360
|
-
default: {
|
|
361
|
-
// a code a newer Zod added fails to compile here; at runtime it is a `check`
|
|
362
|
-
const unmapped = issue;
|
|
363
|
-
return { kind: 'check', expected: unmapped.code };
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
// each option of a failed Zod union as fuz_schema's `expected` names it: by
|
|
368
|
-
// the type or the values its issue on the value itself expected, a union's
|
|
369
|
-
// own options in its place (a discriminated one is an object), and else by
|
|
370
|
-
// the value's type, which the option matched: a refinement failed, or an
|
|
371
|
-
// issue below the value, as an object or array option's (an option's issues
|
|
372
|
-
// are relative to the union)
|
|
373
|
-
const describe_union_options = (issue, input, path) => issue.errors.flatMap((option_issues) => {
|
|
374
|
-
if (!option_issues.length)
|
|
375
|
-
return [];
|
|
376
|
-
const on_value = option_issues.find((i) => i.path.length === 0);
|
|
377
|
-
if (on_value?.code === 'invalid_union' && on_value.inclusive !== false) {
|
|
378
|
-
return on_value.discriminator === undefined
|
|
379
|
-
? describe_union_options(on_value, input, path)
|
|
380
|
-
: ['object'];
|
|
381
|
-
}
|
|
382
|
-
if ((on_value?.code === 'invalid_type' && on_value.expected !== 'int') ||
|
|
383
|
-
on_value?.code === 'invalid_value') {
|
|
384
|
-
return [to_zod_kind(on_value, input, path).expected];
|
|
385
|
-
}
|
|
386
|
-
return [to_received(get_at(input, path))];
|
|
387
|
-
});
|
|
98
|
+
export const to_wire_issues = (issues) => issues.map((issue) => ({
|
|
99
|
+
kind: issue.kind,
|
|
100
|
+
path: issue.path.map((key) => (typeof key === 'symbol' ? key.toString() : key)),
|
|
101
|
+
expected: issue.expected,
|
|
102
|
+
received: issue.received,
|
|
103
|
+
message: format_issue(issue)
|
|
104
|
+
}));
|