@fuzdev/fuz_app 0.154.0 → 0.155.1

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 (47) hide show
  1. package/dist/actions/CLAUDE.md +2 -2
  2. package/dist/actions/action_event.d.ts.map +1 -1
  3. package/dist/actions/action_event.js +14 -14
  4. package/dist/actions/peer_ping.js +3 -3
  5. package/dist/actions/perform_action.d.ts +12 -10
  6. package/dist/actions/perform_action.d.ts.map +1 -1
  7. package/dist/actions/perform_action.js +19 -16
  8. package/dist/auth/cell_actions.d.ts +6 -4
  9. package/dist/auth/cell_actions.d.ts.map +1 -1
  10. package/dist/auth/cell_actions.js +10 -9
  11. package/dist/http/CLAUDE.md +14 -8
  12. package/dist/http/schema_helpers.d.ts +102 -23
  13. package/dist/http/schema_helpers.d.ts.map +1 -1
  14. package/dist/http/schema_helpers.js +241 -38
  15. package/dist/http/surface.d.ts +7 -2
  16. package/dist/http/surface.d.ts.map +1 -1
  17. package/dist/http/surface.js +37 -14
  18. package/dist/primitive_schemas.d.ts +13 -4
  19. package/dist/primitive_schemas.d.ts.map +1 -1
  20. package/dist/primitive_schemas.js +13 -4
  21. package/dist/schema_issues.d.ts +96 -0
  22. package/dist/schema_issues.d.ts.map +1 -0
  23. package/dist/schema_issues.js +110 -0
  24. package/dist/schema_meta.d.ts +35 -12
  25. package/dist/schema_meta.d.ts.map +1 -1
  26. package/dist/schema_meta.js +60 -12
  27. package/dist/testing/CLAUDE.md +22 -9
  28. package/dist/testing/adversarial_404.d.ts +15 -0
  29. package/dist/testing/adversarial_404.d.ts.map +1 -1
  30. package/dist/testing/adversarial_404.js +26 -19
  31. package/dist/testing/adversarial_input_cases.d.ts.map +1 -1
  32. package/dist/testing/adversarial_input_cases.js +2 -2
  33. package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
  34. package/dist/testing/cross_backend/cell_crud.js +7 -5
  35. package/dist/testing/cross_backend/identity_parity.js +2 -2
  36. package/dist/testing/cross_backend/standard.d.ts +3 -2
  37. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  38. package/dist/testing/daemon_info.d.ts +7 -2
  39. package/dist/testing/daemon_info.d.ts.map +1 -1
  40. package/dist/testing/daemon_info.js +8 -3
  41. package/dist/testing/data_exposure.d.ts +43 -9
  42. package/dist/testing/data_exposure.d.ts.map +1 -1
  43. package/dist/testing/data_exposure.js +151 -35
  44. package/dist/testing/schema_generators.d.ts +21 -9
  45. package/dist/testing/schema_generators.d.ts.map +1 -1
  46. package/dist/testing/schema_generators.js +52 -47
  47. package/package.json +3 -3
@@ -9,43 +9,57 @@ import './assert_dev_env.js';
9
9
  * @module
10
10
  */
11
11
  import { z } from 'zod';
12
+ import { is_schema } from '@fuzdev/fuz_schema/schema.ts';
13
+ import { to_json_schema } from '@fuzdev/fuz_schema/json_schema.ts';
12
14
  import { zod_unwrap_def, zod_get_base_type, zod_unwrap_to_object, zod_extract_fields } from '../zod.js';
13
15
  import { is_null_schema } from '../http/schema_helpers.js';
14
16
  /**
15
17
  * The JSON Schema of a field's input side — where its format, pattern and
16
- * bounds live — or `null` when JSON Schema can't render the field or any part
17
- * of it (`z.date()`, `z.custom()`, a union with a `z.date()` branch).
18
+ * bounds live. Takes a Zod or a `@fuzdev/fuz_schema` field.
18
19
  *
19
20
  * Rendered with `io: 'input'`, so a field carrying a `.transform()` or a pipe
20
21
  * (`Username`) still yields the constraints its input is checked against;
21
22
  * the default output side throws on a transform. A pipe yields its input
22
23
  * side only, so constraints of the stage after it are not here. A
23
24
  * `.nullable()` / `.nullish()` field renders as
24
- * `anyOf: [{…}, {type: 'null'}]`; its one non-null branch is returned, so
25
- * the bounds and pattern read the same as on the bare field. A union of two
26
- * or more non-null branches returns the whole schema — its branches' bounds
27
- * are no single field's bounds.
25
+ * `anyOf: [{…}, {type: 'null'}]`, or a bare type as `type: [type, 'null']`;
26
+ * its one non-null branch or type is returned, so the bounds, pattern and
27
+ * `type` read the same as on the bare field. A union of two or more non-null
28
+ * branches returns the whole schema — its branches' bounds are no single
29
+ * field's bounds.
30
+ *
31
+ * Either library renders with `unrepresentable: 'any'`: a part JSON Schema
32
+ * can't say (a `z.date()`, a `z.custom()`, a fuz_schema `check` or `bigint`)
33
+ * is left out or `{}`, and the bounds around it still read, so a
34
+ * `pipe(string, max_length(n), check(…))` keeps its `maxLength` and a union
35
+ * with a `z.date()` branch keeps its other branches — every case the
36
+ * generators build from it is checked against the field itself before it's
37
+ * used. What an emitter refuses even then (a fuz_schema entry named like a
38
+ * member of `Object.prototype`, metadata that isn't JSON) throws: a mistake in
39
+ * the schema, not a gap in JSON Schema.
28
40
  *
29
41
  * A `.refine()` is never here: JSON Schema can't express one, so a bound a
30
42
  * refinement enforces (a code-point length, a cross-field rule) generates no
31
43
  * boundary case.
32
44
  *
33
45
  * @param field_schema - the field to read
34
- * @returns the field's input-side JSON Schema, or `null` when it can't be rendered
46
+ * @returns the field's input-side JSON Schema
47
+ * @throws Error when the emitter refuses `field_schema` with `unrepresentable: 'any'`
35
48
  */
36
49
  export const to_field_json_schema = (field_schema) => {
37
- let json;
38
- try {
39
- json = z.toJSONSchema(field_schema, { io: 'input' });
40
- }
41
- catch {
42
- return null; // a type JSON Schema can't represent
43
- }
50
+ const json = is_schema(field_schema)
51
+ ? to_json_schema(field_schema, { io: 'input', unrepresentable: 'any' })
52
+ : z.toJSONSchema(field_schema, { io: 'input', unrepresentable: 'any' });
44
53
  if (Array.isArray(json.anyOf)) {
45
54
  const branches = json.anyOf.filter((branch) => branch.type !== 'null');
46
55
  if (branches.length === 1)
47
56
  return branches[0];
48
57
  }
58
+ if (Array.isArray(json.type)) {
59
+ const types = json.type.filter((t) => t !== 'null');
60
+ if (types.length === 1)
61
+ return { ...json, type: types[0] };
62
+ }
49
63
  return json;
50
64
  };
51
65
  /**
@@ -80,10 +94,7 @@ export const detect_json_schema_format = (json) => {
80
94
  * (`to_field_json_schema`). Returns the format string (e.g. `'uuid'`,
81
95
  * `'email'`), `'pattern'` for a regex, or `null`.
82
96
  */
83
- export const detect_format = (field_schema) => {
84
- const json = to_field_json_schema(field_schema);
85
- return json && detect_json_schema_format(json);
86
- };
97
+ export const detect_format = (field_schema) => detect_json_schema_format(to_field_json_schema(field_schema));
87
98
  /**
88
99
  * Extract a candidate value from a JSON Schema `pattern` when the shape is a
89
100
  * fixed-length hex character class, optionally behind a literal prefix —
@@ -155,14 +166,12 @@ const generate_valid_string = (field_schema) => {
155
166
  let max_length = Infinity;
156
167
  let pattern = null;
157
168
  const json = to_field_json_schema(field_schema);
158
- if (json) {
159
- if (typeof json.minLength === 'number')
160
- min_length = json.minLength;
161
- if (typeof json.maxLength === 'number')
162
- max_length = json.maxLength;
163
- if (typeof json.pattern === 'string')
164
- pattern = json.pattern;
165
- }
169
+ if (typeof json.minLength === 'number')
170
+ min_length = json.minLength;
171
+ if (typeof json.maxLength === 'number')
172
+ max_length = json.maxLength;
173
+ if (typeof json.pattern === 'string')
174
+ pattern = json.pattern;
166
175
  const target = Math.max(min_length, Math.min(10, max_length));
167
176
  const base = 'x'.repeat(target) || 'test_value';
168
177
  // Validate against the full schema (including refinements/brands).
@@ -226,23 +235,21 @@ export const generate_valid_value = (field, field_schema) => {
226
235
  return candidate;
227
236
  }
228
237
  const json = to_field_json_schema(field_schema);
229
- if (json) {
230
- if (typeof json.minimum === 'number')
231
- return Math.ceil(json.minimum);
232
- if (typeof json.exclusiveMinimum === 'number')
233
- return Math.floor(json.exclusiveMinimum) + 1;
234
- if (typeof json.maximum === 'number')
235
- return Math.floor(json.maximum);
236
- if (typeof json.exclusiveMaximum === 'number')
237
- return Math.ceil(json.exclusiveMaximum) - 1;
238
- }
238
+ if (typeof json.minimum === 'number')
239
+ return Math.ceil(json.minimum);
240
+ if (typeof json.exclusiveMinimum === 'number')
241
+ return Math.floor(json.exclusiveMinimum) + 1;
242
+ if (typeof json.maximum === 'number')
243
+ return Math.floor(json.maximum);
244
+ if (typeof json.exclusiveMaximum === 'number')
245
+ return Math.ceil(json.exclusiveMaximum) - 1;
239
246
  return 1; // fall through — generate_valid_body will report the failure
240
247
  }
241
248
  case 'boolean':
242
249
  return true;
243
250
  case 'array': {
244
251
  const json = to_field_json_schema(field_schema);
245
- const min_items = typeof json?.minItems === 'number' ? json.minItems : 0;
252
+ const min_items = typeof json.minItems === 'number' ? json.minItems : 0;
246
253
  if (min_items === 0)
247
254
  return [];
248
255
  const def = zod_unwrap_def(field_schema);
@@ -453,16 +460,14 @@ export const generate_valid_string_param = (field, field_schema) => {
453
460
  candidates.push('1', '0', 'true', 'false');
454
461
  // a number the URL string is preprocessed into: its default or its lower bound
455
462
  const json = to_field_json_schema(field_schema);
456
- if (json) {
457
- const fallback = json.default;
458
- if (typeof fallback === 'number' || typeof fallback === 'string') {
459
- candidates.push(String(fallback));
460
- }
461
- if (typeof json.minimum === 'number')
462
- candidates.push(String(Math.ceil(json.minimum)));
463
- if (typeof json.exclusiveMinimum === 'number') {
464
- candidates.push(String(Math.floor(json.exclusiveMinimum) + 1));
465
- }
463
+ const fallback = json.default;
464
+ if (typeof fallback === 'number' || typeof fallback === 'string') {
465
+ candidates.push(String(fallback));
466
+ }
467
+ if (typeof json.minimum === 'number')
468
+ candidates.push(String(Math.ceil(json.minimum)));
469
+ if (typeof json.exclusiveMinimum === 'number') {
470
+ candidates.push(String(Math.floor(json.exclusiveMinimum) + 1));
466
471
  }
467
472
  candidates.push(generate_valid_string(field_schema));
468
473
  return candidates.find((c) => field_schema.safeParse(c).success) ?? null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fuzdev/fuz_app",
3
- "version": "0.154.0",
3
+ "version": "0.155.1",
4
4
  "description": "fullstack app library",
5
5
  "glyph": "🗝",
6
6
  "logo": "logo.svg",
@@ -37,7 +37,7 @@
37
37
  "@electric-sql/pglite": ">=0.4",
38
38
  "@fuzdev/blake3-wasm": ">=0.2.0",
39
39
  "@fuzdev/fuz_css": ">=0.72.0",
40
- "@fuzdev/fuz_schema": "^0.5.1",
40
+ "@fuzdev/fuz_schema": "^0.5.3",
41
41
  "@fuzdev/fuz_util": ">=0.79.0",
42
42
  "@fuzdev/pglet-wasm": ">=0.1.2",
43
43
  "@hono/bun": ">=1",
@@ -96,7 +96,7 @@
96
96
  "@fuzdev/blake3-wasm": "^0.2.0",
97
97
  "@fuzdev/fuz_code": "^0.56.0",
98
98
  "@fuzdev/fuz_css": "^0.72.0",
99
- "@fuzdev/fuz_schema": "^0.5.1",
99
+ "@fuzdev/fuz_schema": "^0.5.3",
100
100
  "@fuzdev/fuz_ui": "^0.221.0",
101
101
  "@fuzdev/fuz_util": "^0.79.0",
102
102
  "@fuzdev/gro": "^0.224.0",