@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.
Files changed (239) hide show
  1. package/dist/actions/CLAUDE.md +17 -19
  2. package/dist/actions/action_codegen.d.ts +32 -23
  3. package/dist/actions/action_codegen.d.ts.map +1 -1
  4. package/dist/actions/action_codegen.js +101 -80
  5. package/dist/actions/action_event.d.ts +0 -8
  6. package/dist/actions/action_event.d.ts.map +1 -1
  7. package/dist/actions/action_event.js +7 -6
  8. package/dist/actions/action_event_data.d.ts +18 -18
  9. package/dist/actions/action_rpc.d.ts +1 -1
  10. package/dist/actions/action_rpc.js +1 -1
  11. package/dist/actions/action_spec.d.ts +8 -10
  12. package/dist/actions/action_spec.d.ts.map +1 -1
  13. package/dist/actions/action_spec.js +1 -1
  14. package/dist/actions/action_types.d.ts +4 -4
  15. package/dist/actions/action_types.d.ts.map +1 -1
  16. package/dist/actions/action_types.js +2 -2
  17. package/dist/actions/broadcast_api.d.ts +2 -2
  18. package/dist/actions/broadcast_api.js +4 -4
  19. package/dist/actions/compile_action_registry.d.ts +6 -7
  20. package/dist/actions/compile_action_registry.d.ts.map +1 -1
  21. package/dist/actions/compile_action_registry.js +8 -9
  22. package/dist/actions/perform_action.d.ts +6 -6
  23. package/dist/actions/perform_action.d.ts.map +1 -1
  24. package/dist/actions/perform_action.js +11 -10
  25. package/dist/actions/socket.svelte.d.ts +1 -1
  26. package/dist/actions/socket.svelte.js +2 -2
  27. package/dist/auth/CLAUDE.md +11 -11
  28. package/dist/auth/account_action_specs.d.ts +11 -11
  29. package/dist/auth/account_action_specs.js +1 -1
  30. package/dist/auth/account_route_schema.d.ts +18 -18
  31. package/dist/auth/account_route_schema.js +1 -1
  32. package/dist/auth/account_routes.js +1 -1
  33. package/dist/auth/account_schema.d.ts +38 -40
  34. package/dist/auth/account_schema.d.ts.map +1 -1
  35. package/dist/auth/account_schema.js +7 -8
  36. package/dist/auth/actor_lookup_action_specs.d.ts +7 -7
  37. package/dist/auth/actor_lookup_action_specs.js +1 -1
  38. package/dist/auth/actor_search_action_specs.d.ts +6 -6
  39. package/dist/auth/actor_search_action_specs.js +1 -1
  40. package/dist/auth/admin_action_specs.d.ts +166 -166
  41. package/dist/auth/admin_action_specs.js +1 -1
  42. package/dist/auth/app_settings_schema.d.ts +3 -3
  43. package/dist/auth/app_settings_schema.d.ts.map +1 -1
  44. package/dist/auth/app_settings_schema.js +1 -1
  45. package/dist/auth/audit_emitter.d.ts +6 -7
  46. package/dist/auth/audit_emitter.d.ts.map +1 -1
  47. package/dist/auth/audit_emitter.js +11 -22
  48. package/dist/auth/audit_log_ddl.d.ts +1 -1
  49. package/dist/auth/audit_log_ddl.js +1 -1
  50. package/dist/auth/audit_log_queries.d.ts +0 -13
  51. package/dist/auth/audit_log_queries.d.ts.map +1 -1
  52. package/dist/auth/audit_log_queries.js +3 -3
  53. package/dist/auth/audit_log_route_schema.d.ts +1 -1
  54. package/dist/auth/audit_log_route_schema.js +1 -1
  55. package/dist/auth/audit_log_schema.d.ts +69 -70
  56. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  57. package/dist/auth/audit_log_schema.js +2 -2
  58. package/dist/auth/auth_ddl.d.ts +1 -1
  59. package/dist/auth/auth_ddl.js +1 -1
  60. package/dist/auth/bootstrap_route_schema.d.ts +4 -4
  61. package/dist/auth/bootstrap_route_schema.js +1 -1
  62. package/dist/auth/cell_action_specs.d.ts +466 -466
  63. package/dist/auth/cell_action_specs.js +1 -1
  64. package/dist/auth/cell_actions.d.ts +2 -2
  65. package/dist/auth/cell_actions.js +5 -5
  66. package/dist/auth/cell_audit_action_specs.d.ts +14 -14
  67. package/dist/auth/cell_audit_action_specs.js +1 -1
  68. package/dist/auth/cell_audit_metadata.d.ts +8 -8
  69. package/dist/auth/cell_audit_metadata.js +1 -1
  70. package/dist/auth/cell_field_action_specs.d.ts +55 -55
  71. package/dist/auth/cell_field_action_specs.js +1 -1
  72. package/dist/auth/cell_field_audit_metadata.d.ts +4 -4
  73. package/dist/auth/cell_field_audit_metadata.js +1 -1
  74. package/dist/auth/cell_grant_action_specs.d.ts +61 -61
  75. package/dist/auth/cell_grant_action_specs.js +1 -1
  76. package/dist/auth/cell_grant_audit_metadata.d.ts +10 -10
  77. package/dist/auth/cell_grant_audit_metadata.js +1 -1
  78. package/dist/auth/cell_item_action_specs.d.ts +76 -76
  79. package/dist/auth/cell_item_action_specs.js +1 -1
  80. package/dist/auth/cell_item_audit_metadata.d.ts +5 -5
  81. package/dist/auth/cell_item_audit_metadata.js +1 -1
  82. package/dist/auth/invite_schema.d.ts +11 -11
  83. package/dist/auth/invite_schema.d.ts.map +1 -1
  84. package/dist/auth/invite_schema.js +1 -1
  85. package/dist/auth/name_schema.js +1 -1
  86. package/dist/auth/password.js +1 -1
  87. package/dist/auth/request_context.js +2 -2
  88. package/dist/auth/role_grant_offer_action_specs.d.ts +182 -182
  89. package/dist/auth/role_grant_offer_action_specs.js +1 -1
  90. package/dist/auth/role_grant_offer_ddl.d.ts +1 -1
  91. package/dist/auth/role_grant_offer_ddl.js +1 -1
  92. package/dist/auth/role_grant_offer_notifications.d.ts +107 -107
  93. package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
  94. package/dist/auth/role_grant_offer_notifications.js +3 -4
  95. package/dist/auth/role_grant_offer_schema.d.ts +9 -9
  96. package/dist/auth/role_grant_offer_schema.d.ts.map +1 -1
  97. package/dist/auth/role_grant_offer_schema.js +1 -1
  98. package/dist/auth/self_service_role_action_specs.d.ts +2 -2
  99. package/dist/auth/self_service_role_action_specs.js +1 -1
  100. package/dist/auth/self_service_role_actions.d.ts +1 -1
  101. package/dist/auth/self_service_role_actions.js +1 -1
  102. package/dist/auth/signup_route_schema.d.ts +2 -2
  103. package/dist/auth/signup_route_schema.js +1 -1
  104. package/dist/auth/token_scope.d.ts +8 -8
  105. package/dist/db/file_fact_url.d.ts +1 -1
  106. package/dist/env/env_schemas.d.ts +1 -2
  107. package/dist/env/env_schemas.d.ts.map +1 -1
  108. package/dist/env/env_schemas.js +3 -4
  109. package/dist/http/CLAUDE.md +30 -32
  110. package/dist/http/auth_shape.d.ts +17 -52
  111. package/dist/http/auth_shape.d.ts.map +1 -1
  112. package/dist/http/auth_shape.js +19 -61
  113. package/dist/http/db_routes.d.ts +1 -1
  114. package/dist/http/db_routes.d.ts.map +1 -1
  115. package/dist/http/db_routes.js +1 -1
  116. package/dist/http/error_schemas.d.ts +36 -36
  117. package/dist/http/jsonrpc.d.ts +11 -11
  118. package/dist/http/jsonrpc_helpers.js +1 -1
  119. package/dist/http/route_error_check.d.ts +2 -2
  120. package/dist/http/route_error_check.d.ts.map +1 -1
  121. package/dist/http/route_error_check.js +2 -3
  122. package/dist/http/route_errors.d.ts +4 -4
  123. package/dist/http/route_errors.d.ts.map +1 -1
  124. package/dist/http/route_errors.js +0 -13
  125. package/dist/http/route_spec.d.ts +33 -36
  126. package/dist/http/route_spec.d.ts.map +1 -1
  127. package/dist/http/route_spec.js +21 -22
  128. package/dist/http/schema_helpers.d.ts +75 -67
  129. package/dist/http/schema_helpers.d.ts.map +1 -1
  130. package/dist/http/schema_helpers.js +54 -76
  131. package/dist/http/surface.d.ts.map +1 -1
  132. package/dist/http/surface.js +6 -8
  133. package/dist/primitive_schemas.d.ts +162 -112
  134. package/dist/primitive_schemas.d.ts.map +1 -1
  135. package/dist/primitive_schemas.js +129 -161
  136. package/dist/realtime/sse.d.ts +3 -3
  137. package/dist/realtime/sse.d.ts.map +1 -1
  138. package/dist/realtime/sse.js +2 -2
  139. package/dist/schema_issues.d.ts +41 -146
  140. package/dist/schema_issues.d.ts.map +1 -1
  141. package/dist/schema_issues.js +39 -322
  142. package/dist/schema_meta.d.ts +63 -136
  143. package/dist/schema_meta.d.ts.map +1 -1
  144. package/dist/schema_meta.js +37 -184
  145. package/dist/sensitivity.d.ts +3 -5
  146. package/dist/sensitivity.d.ts.map +1 -1
  147. package/dist/sensitivity.js +3 -5
  148. package/dist/server/serve_fact_route.js +1 -1
  149. package/dist/server/surface_route.js +1 -1
  150. package/dist/testing/CLAUDE.md +23 -25
  151. package/dist/testing/adversarial_headers.js +2 -2
  152. package/dist/testing/adversarial_input_cases.d.ts +19 -18
  153. package/dist/testing/adversarial_input_cases.d.ts.map +1 -1
  154. package/dist/testing/adversarial_input_cases.js +29 -42
  155. package/dist/testing/assertions.d.ts +2 -2
  156. package/dist/testing/assertions.d.ts.map +1 -1
  157. package/dist/testing/assertions.js +3 -3
  158. package/dist/testing/cross_backend/account_lifecycle.js +2 -2
  159. package/dist/testing/cross_backend/action_manifest.d.ts +10 -9
  160. package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
  161. package/dist/testing/cross_backend/action_manifest.js +4 -3
  162. package/dist/testing/cross_backend/cell_crud.js +1 -1
  163. package/dist/testing/cross_backend/conformance_case.d.ts +96 -114
  164. package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
  165. package/dist/testing/cross_backend/conformance_case.js +0 -256
  166. package/dist/testing/cross_backend/conformance_rpc_auth.d.ts +0 -62
  167. package/dist/testing/cross_backend/conformance_rpc_auth.d.ts.map +1 -1
  168. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  169. package/dist/testing/cross_backend/conformance_table.js +3 -3
  170. package/dist/testing/cross_backend/cross_rpc.d.ts +3 -4
  171. package/dist/testing/cross_backend/cross_rpc.d.ts.map +1 -1
  172. package/dist/testing/cross_backend/cross_rpc.js +4 -4
  173. package/dist/testing/cross_backend/differential.js +2 -2
  174. package/dist/testing/cross_backend/fact_serving.js +1 -1
  175. package/dist/testing/cross_backend/identity_parity.js +9 -9
  176. package/dist/testing/cross_backend/origin_conformance.d.ts +9 -9
  177. package/dist/testing/cross_backend/query_shape.js +1 -1
  178. package/dist/testing/cross_backend/rpc_success_fixtures.d.ts.map +1 -1
  179. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +1 -1
  180. package/dist/testing/cross_backend/setup.d.ts +26 -4
  181. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  182. package/dist/testing/cross_backend/setup.js +7 -8
  183. package/dist/testing/cross_backend/sse_round_trip.js +2 -2
  184. package/dist/testing/cross_backend/testing_origin_check.d.ts +12 -12
  185. package/dist/testing/cross_backend/testing_reset_actions.d.ts +608 -201
  186. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  187. package/dist/testing/cross_backend/testing_reset_actions.js +46 -55
  188. package/dist/testing/cross_backend/token_lifetime.js +3 -3
  189. package/dist/testing/cross_backend/wire_shapes.js +1 -1
  190. package/dist/testing/cross_backend/ws_outbound_overflow.d.ts.map +1 -1
  191. package/dist/testing/cross_backend/ws_outbound_overflow.js +35 -0
  192. package/dist/testing/cross_backend/ws_round_trip.js +1 -1
  193. package/dist/testing/data_exposure.d.ts.map +1 -1
  194. package/dist/testing/data_exposure.js +1 -1
  195. package/dist/testing/integration.js +2 -2
  196. package/dist/testing/integration_helpers.d.ts.map +1 -1
  197. package/dist/testing/integration_helpers.js +2 -2
  198. package/dist/testing/middleware.d.ts.map +1 -1
  199. package/dist/testing/middleware.js +2 -2
  200. package/dist/testing/rpc_attack_surface.js +1 -1
  201. package/dist/testing/rpc_envelope_cases.d.ts +3 -3
  202. package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
  203. package/dist/testing/rpc_envelope_cases.js +1 -1
  204. package/dist/testing/rpc_helpers.d.ts +12 -14
  205. package/dist/testing/rpc_helpers.d.ts.map +1 -1
  206. package/dist/testing/rpc_helpers.js +9 -11
  207. package/dist/testing/schema_generators.d.ts +67 -60
  208. package/dist/testing/schema_generators.d.ts.map +1 -1
  209. package/dist/testing/schema_generators.js +144 -151
  210. package/dist/testing/schema_introspect.d.ts +438 -78
  211. package/dist/testing/schema_introspect.d.ts.map +1 -1
  212. package/dist/testing/schema_introspect.js +26 -26
  213. package/dist/testing/sse_round_trip.d.ts.map +1 -1
  214. package/dist/testing/sse_round_trip.js +2 -2
  215. package/dist/testing/surface_invariants.d.ts +1 -1
  216. package/dist/testing/surface_invariants.js +1 -1
  217. package/dist/testing/transports/bootstrap.d.ts +1 -1
  218. package/dist/testing/transports/bootstrap.d.ts.map +1 -1
  219. package/dist/testing/transports/bootstrap.js +1 -1
  220. package/dist/ui/BootstrapForm.svelte +1 -2
  221. package/dist/ui/BootstrapForm.svelte.d.ts.map +1 -1
  222. package/dist/ui/SignupForm.svelte +1 -2
  223. package/dist/ui/SignupForm.svelte.d.ts.map +1 -1
  224. package/dist/ui/admin_accounts_state.svelte.d.ts +5 -5
  225. package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -1
  226. package/dist/ui/admin_invites_state.svelte.d.ts +1 -1
  227. package/dist/ui/admin_invites_state.svelte.d.ts.map +1 -1
  228. package/dist/ui/admin_sessions_state.svelte.d.ts +2 -2
  229. package/dist/ui/admin_sessions_state.svelte.d.ts.map +1 -1
  230. package/dist/ui/form_state.svelte.d.ts +1 -1
  231. package/dist/ui/form_state.svelte.js +1 -1
  232. package/dist/ui/role_grant_offers_state.svelte.d.ts +1 -1
  233. package/package.json +7 -9
  234. package/dist/primitive_schemas_fuz.d.ts +0 -178
  235. package/dist/primitive_schemas_fuz.d.ts.map +0 -1
  236. package/dist/primitive_schemas_fuz.js +0 -149
  237. package/dist/zod.d.ts +0 -101
  238. package/dist/zod.d.ts.map +0 -1
  239. package/dist/zod.js +0 -195
@@ -1,110 +1,47 @@
1
1
  /**
2
- * Validation issues from either schema library the stack's specs use: Zod
3
- * (`z.core.$ZodIssue`) and `@fuzdev/fuz_schema` (`SchemaIssue`). A schema is
4
- * wholly one library, so one parse's issues are all of one kind; these
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 { z } from 'zod';
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
- * Whether `value` is a Zod schema. Zod's `instanceof` reads the schema's
16
- * traits, so a schema made by another copy of Zod is one too.
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 neither a Zod nor a fuz_schema schema
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
- assert_zod_schema(value, label);
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
- * Zod reports both at an empty path, its `unrecognized_keys` naming the keys.
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 Zod's rule.
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 (is_zod_issue(issue)) {
116
- if (issue.code !== 'unrecognized_keys')
117
- return null;
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: Zod's `z.prettifyError` text for Zod
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, all of one library
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 of either library: a
145
- * `z.ZodError` or a fuz_schema `SchemaError` (`parse_or_throw`). Both carry
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 z.ZodError || err instanceof SchemaError;
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, for either schema library — fuz_schema's `SchemaIssue`
154
- * as JSON, with `message` the text of the issue. `to_wire_issues` builds it
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: `format_issue` for a fuz_schema issue, Zod's own message for a Zod one. */
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, whichever library made them.
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
- * A fuz_schema issue keeps its `kind`, `path`, `expected` and `received`, and
175
- * its `message` is `format_issue`'s text, the path included.
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, input) => {
217
- const wire = [];
218
- for (const issue of issues) {
219
- if (is_zod_issue(issue)) {
220
- push_zod_wire_issues(wire, issue, input);
221
- }
222
- else {
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
+ }));