@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.
- package/dist/actions/CLAUDE.md +2 -2
- package/dist/actions/action_event.d.ts.map +1 -1
- package/dist/actions/action_event.js +14 -14
- package/dist/actions/peer_ping.js +3 -3
- package/dist/actions/perform_action.d.ts +12 -10
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +19 -16
- package/dist/auth/cell_actions.d.ts +6 -4
- package/dist/auth/cell_actions.d.ts.map +1 -1
- package/dist/auth/cell_actions.js +10 -9
- package/dist/http/CLAUDE.md +14 -8
- package/dist/http/schema_helpers.d.ts +102 -23
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +241 -38
- package/dist/http/surface.d.ts +7 -2
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +37 -14
- package/dist/primitive_schemas.d.ts +13 -4
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas.js +13 -4
- package/dist/schema_issues.d.ts +96 -0
- package/dist/schema_issues.d.ts.map +1 -0
- package/dist/schema_issues.js +110 -0
- package/dist/schema_meta.d.ts +35 -12
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +60 -12
- package/dist/testing/CLAUDE.md +22 -9
- package/dist/testing/adversarial_404.d.ts +15 -0
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +26 -19
- package/dist/testing/adversarial_input_cases.d.ts.map +1 -1
- package/dist/testing/adversarial_input_cases.js +2 -2
- package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_crud.js +7 -5
- package/dist/testing/cross_backend/identity_parity.js +2 -2
- package/dist/testing/cross_backend/standard.d.ts +3 -2
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/daemon_info.d.ts +7 -2
- package/dist/testing/daemon_info.d.ts.map +1 -1
- package/dist/testing/daemon_info.js +8 -3
- package/dist/testing/data_exposure.d.ts +43 -9
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +151 -35
- package/dist/testing/schema_generators.d.ts +21 -9
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +52 -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
|
|
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'}]
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
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
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
|
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
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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",
|