@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
@@ -2,59 +2,56 @@ import './assert_dev_env.js';
2
2
  /**
3
3
  * Schema-driven value generation helpers for testing.
4
4
  *
5
- * Walks Zod and `@fuzdev/fuz_schema` schemas to generate valid values for
6
- * route params, request bodies, and URL paths. Used by adversarial input,
7
- * adversarial 404, and round-trip validation test suites. A schema of
8
- * neither library throws, and so does an input no body can be generated
9
- * for, rather than yielding no body.
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 { z } from 'zod';
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 { assert_zod_schema, format_issues, parse_any } from '../schema_issues.js';
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. Takes a Zod or a `@fuzdev/fuz_schema` field.
21
+ * bounds live.
24
22
  *
25
- * Rendered with `io: 'input'`, so a field carrying a `.transform()` or a pipe
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
- * `.nullable()` / `.nullish()` field renders as
30
- * `anyOf: [{…}, {type: 'null'}]`, or a bare type as `type: [type, 'null']`;
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
- * Either library renders with `unrepresentable: 'any'`: a part JSON Schema
37
- * can't say (a `z.date()`, a `z.custom()`, a fuz_schema `check` or `bigint`)
38
- * is left out or `{}`, and the bounds around it still read, so a
39
- * `pipe(string, max_length(n), check(…))` keeps its `maxLength` and a union
40
- * with a `z.date()` branch keeps its other branches — every case the
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 `.refine()` is never here: JSON Schema can't express one, so a bound a
47
- * refinement enforces (a code-point length, a cross-field rule) generates no
48
- * boundary case.
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 = is_schema(field_schema)
56
- ? to_json_schema(field_schema, { io: 'input', unrepresentable: 'any' })
57
- : z.toJSONSchema(field_schema, { io: 'input', unrepresentable: 'any' });
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]` (Zod passes
115
- * the regex source through verbatim — no character-class reordering).
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_-]` (Zod passes the regex
144
- * source through verbatim — no character-class reordering).
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 of either library ---
169
- /** Whether `schema` accepts `value`, a parse of either library (`parse_any`). */
170
- const accepts = (schema, value) => parse_any(schema, value).ok;
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 `@fuzdev/fuz_schema` schema, from the schema itself through
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 fuz_schema_layers = (schema) => {
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 for a `@fuzdev/fuz_schema` schema,
204
- * in Zod's vocabulary (`zod_get_base_type`): its innermost layer's kind, with
205
- * an object schema of any strictness `'object'`, a `literal(null)` `'null'`,
206
- * a `literal(undefined)` (`s.void`) `'void'`, a `one_of` `'enum'`, and a
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 fuz_schema_base_type = (schema) => {
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 type name the generators switch on, of either library
228
- const to_base_type = (schema) => is_schema(schema) ? fuz_schema_base_type(schema) : zod_get_base_type(schema);
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
- if (is_schema(schema)) {
233
- const entries = get_schema_entries(schema);
234
- if (!entries)
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: zod_extract_fields(object_schema),
257
- field_schema: (name) => (Object.hasOwn(shape, name) ? shape[name] : undefined)
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 of either library and the schema of each,
262
- * through its wrappers: the `ZodObject` inside a Zod schema
263
- * (`zod_unwrap_to_object`, `zod_extract_fields`), or a `@fuzdev/fuz_schema`
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, Zod or fuz_schema
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 of neither library
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 `z.string().regex()` form exposes a `pattern`, not the
312
- // `format: 'email'` the `case 'email'` switch arm keys on.
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, of either library
312
+ // the element schema of an array field
331
313
  const to_array_element = (field_schema) => {
332
- if (is_schema(field_schema)) {
333
- const base = unwrap_schema(field_schema);
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, of either library
317
+ // the first option of a union field
339
318
  const to_first_union_option = (field_schema) => {
340
- if (is_schema(field_schema)) {
341
- const base = unwrap_schema(field_schema);
342
- if (base.kind === 'union')
343
- return base.def[0];
344
- if (base.kind === 'variant')
345
- return base.def.options[0];
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, of either library, in declared order
326
+ // the values a literal or enum field accepts, in declared order
353
327
  const to_literal_values = (field_schema) => {
354
- if (is_schema(field_schema)) {
355
- const base = unwrap_schema(field_schema);
356
- if (base.kind === 'literal')
357
- return [base.def];
358
- if (base.kind === 'one_of')
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` or `zod_extract_fields`
379
- * @param field_schema - the field's schema, Zod or `@fuzdev/fuz_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: a Zod or
485
- * `@fuzdev/fuz_schema` object schema, possibly wrapped
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 `parse_any` result — the caller
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 either schema is
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 = parse_any(schema, start);
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 = parse_any(schema, value);
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 = parse_any(schema, value);
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, Zod or
550
- * `@fuzdev/fuz_schema`, possibly wrapped
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 either schema is
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 (a preprocessed
596
- * integer whose minimum is above one), and a string synthesized from the
597
- * field's constraints.
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` or `zod_extract_fields`
600
- * @param field_schema - the field's schema, Zod or `@fuzdev/fuz_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
- if (typeof json.exclusiveMinimum === 'number') {
625
- candidates.push(String(Math.floor(json.exclusiveMinimum) + 1));
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, Zod or `@fuzdev/fuz_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 of neither library, or 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 \`z.void()\` or \`s.void\``);
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, a Zod or `@fuzdev/fuz_schema` object 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 of neither library;
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, Zod or `@fuzdev/fuz_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 of neither library, or is neither void, null,
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