@fuzdev/fuz_app 0.154.0 → 0.155.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/CLAUDE.md +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
|
@@ -0,0 +1,96 @@
|
|
|
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.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { SchemaError, type AnySchema, type Infer, type SchemaIssue } from '@fuzdev/fuz_schema/schema.ts';
|
|
13
|
+
import type { Result } from '@fuzdev/fuz_util/result.ts';
|
|
14
|
+
/** A schema of either library: a Zod schema or a `@fuzdev/fuz_schema` one. */
|
|
15
|
+
export type ValidationSchema = z.ZodType | AnySchema;
|
|
16
|
+
/** The output type of a `ValidationSchema`. */
|
|
17
|
+
export type ValidationOutput<T extends ValidationSchema> = T extends z.ZodType ? z.output<T> : T extends AnySchema ? Infer<T> : never;
|
|
18
|
+
/** One issue of a failed parse, in the library's own shape. */
|
|
19
|
+
export type AnyIssue = z.core.$ZodIssue | SchemaIssue;
|
|
20
|
+
/** What `parse_any` returns: the output, or the failed parse's issues in the library's order. */
|
|
21
|
+
export type ParseAnyResult<T> = Result<{
|
|
22
|
+
value: T;
|
|
23
|
+
}, {
|
|
24
|
+
issues: Array<AnyIssue>;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Parse `value` with a schema of either library: `parse` for a fuz_schema
|
|
28
|
+
* schema (`is_schema`), `safeParse` for a Zod one.
|
|
29
|
+
*
|
|
30
|
+
* A fuz_schema parse reports at most its first hundred issues, a Zod parse
|
|
31
|
+
* every issue.
|
|
32
|
+
*
|
|
33
|
+
* @param schema - a Zod or fuz_schema schema
|
|
34
|
+
* @param value - the value to validate
|
|
35
|
+
* @returns the output, or the issues
|
|
36
|
+
*/
|
|
37
|
+
export declare const parse_any: <T extends ValidationSchema>(schema: T, value: unknown) => ParseAnyResult<ValidationOutput<T>>;
|
|
38
|
+
/**
|
|
39
|
+
* Whether `issue` is Zod's: every Zod issue has a `code`, a fuz_schema issue a `kind`.
|
|
40
|
+
*/
|
|
41
|
+
export declare const is_zod_issue: (issue: AnyIssue) => issue is z.core.$ZodIssue;
|
|
42
|
+
/**
|
|
43
|
+
* Whether `issue` sits on the input itself rather than on one of its fields:
|
|
44
|
+
* a non-object input, or an unknown key on the input object — what the Rust
|
|
45
|
+
* twin refuses before reading any field.
|
|
46
|
+
*
|
|
47
|
+
* Zod reports both at an empty path, its `unrecognized_keys` naming the keys.
|
|
48
|
+
* fuz_schema reports a non-object at an empty path and each unknown key as an
|
|
49
|
+
* `unknown_key` issue whose path ends at the key, so one on the input has a
|
|
50
|
+
* path of the key alone. An unknown key on a nested object is on that field,
|
|
51
|
+
* as Zod's is.
|
|
52
|
+
*
|
|
53
|
+
* On the wire the `unknown_key` rule changes no answer today: a root
|
|
54
|
+
* `unknown_key` comes from a root `object`, which `resolve_issues_invalid_reason`
|
|
55
|
+
* already answers with none from its check of the input's keys, or from a
|
|
56
|
+
* schema such as a `variant` whose fields resolve no reason. It is kept as the
|
|
57
|
+
* direct statement of Zod's rule.
|
|
58
|
+
*
|
|
59
|
+
* @param issue - one issue of a failed parse
|
|
60
|
+
*/
|
|
61
|
+
export declare const issue_is_on_input: (issue: AnyIssue) => boolean;
|
|
62
|
+
/** Keys a parse refused as unknown, and the path of the object holding them. */
|
|
63
|
+
export interface UnknownKeyTarget {
|
|
64
|
+
/** The path of the object the keys are on, `[]` for the input itself. */
|
|
65
|
+
path: ReadonlyArray<PropertyKey>;
|
|
66
|
+
/** The unknown keys. */
|
|
67
|
+
keys: ReadonlyArray<PropertyKey>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The unknown keys among `issues`, each with the path of its object, or
|
|
71
|
+
* `null` when any issue is something else.
|
|
72
|
+
*
|
|
73
|
+
* A Zod `unrecognized_keys` issue is at its object's path and names every
|
|
74
|
+
* key; a fuz_schema `unknown_key` issue is one key, the last element of its
|
|
75
|
+
* path.
|
|
76
|
+
*
|
|
77
|
+
* @param issues - a failed parse's issues
|
|
78
|
+
* @returns a target per issue, or `null` when not every issue is an unknown key
|
|
79
|
+
*/
|
|
80
|
+
export declare const unknown_key_targets: (issues: ReadonlyArray<AnyIssue>) => Array<UnknownKeyTarget> | null;
|
|
81
|
+
/**
|
|
82
|
+
* A failed parse's issues as text: Zod's `z.prettifyError` text for Zod
|
|
83
|
+
* issues, and for fuz_schema issues their `format_issue` lines.
|
|
84
|
+
*
|
|
85
|
+
* @param issues - a failed parse's issues, all of one library
|
|
86
|
+
*/
|
|
87
|
+
export declare const format_issues: (issues: ReadonlyArray<AnyIssue>) => string;
|
|
88
|
+
/**
|
|
89
|
+
* Whether `err` is a thrown validation failure of either library: a
|
|
90
|
+
* `z.ZodError` or a fuz_schema `SchemaError` (`parse_or_throw`). Both carry
|
|
91
|
+
* the failed parse's `issues`.
|
|
92
|
+
*
|
|
93
|
+
* @param err - a caught value
|
|
94
|
+
*/
|
|
95
|
+
export declare const is_schema_validation_error: (err: unknown) => err is z.ZodError | SchemaError;
|
|
96
|
+
//# sourceMappingURL=schema_issues.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema_issues.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/schema_issues.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAIN,WAAW,EACX,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,WAAW,EAChB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEzD,8EAA8E;AAC9E,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,OAAO,GAAG,SAAS,CAAC;AAErD,+CAA+C;AAC/C,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,gBAAgB,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,GAC3E,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GACX,CAAC,SAAS,SAAS,GAClB,KAAK,CAAC,CAAC,CAAC,GACR,KAAK,CAAC;AAEV,+DAA+D;AAC/D,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC;AAEtD,iGAAiG;AACjG,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,MAAM,CAAC;IAAE,KAAK,EAAE,CAAC,CAAA;CAAE,EAAE;IAAE,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;CAAE,CAAC,CAAC;AAElF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,gBAAgB,EACnD,QAAQ,CAAC,EACT,OAAO,OAAO,KACZ,cAAc,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAWpC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,QAAQ,KAAG,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,SAA4B,CAAC;AAE5F;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,QAAQ,KAAG,OAE8B,CAAC;AAEnF,gFAAgF;AAChF,MAAM,WAAW,gBAAgB;IAChC,yEAAyE;IACzE,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IACjC,wBAAwB;IACxB,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;CACjC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAC/B,QAAQ,aAAa,CAAC,QAAQ,CAAC,KAC7B,KAAK,CAAC,gBAAgB,CAAC,GAAG,IAY5B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,QAAQ,aAAa,CAAC,QAAQ,CAAC,KAAG,MAO/D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GAAI,KAAK,OAAO,KAAG,GAAG,IAAI,CAAC,CAAC,QAAQ,GAAG,WACtB,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
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.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { format_issue, is_schema, parse, SchemaError } from '@fuzdev/fuz_schema/schema.ts';
|
|
13
|
+
/**
|
|
14
|
+
* Parse `value` with a schema of either library: `parse` for a fuz_schema
|
|
15
|
+
* schema (`is_schema`), `safeParse` for a Zod one.
|
|
16
|
+
*
|
|
17
|
+
* A fuz_schema parse reports at most its first hundred issues, a Zod parse
|
|
18
|
+
* every issue.
|
|
19
|
+
*
|
|
20
|
+
* @param schema - a Zod or fuz_schema schema
|
|
21
|
+
* @param value - the value to validate
|
|
22
|
+
* @returns the output, or the issues
|
|
23
|
+
*/
|
|
24
|
+
export const parse_any = (schema, value) => {
|
|
25
|
+
if (is_schema(schema)) {
|
|
26
|
+
const result = parse(schema, value);
|
|
27
|
+
return result.ok
|
|
28
|
+
? { ok: true, value: result.value }
|
|
29
|
+
: { ok: false, issues: result.issues };
|
|
30
|
+
}
|
|
31
|
+
const result = schema.safeParse(value);
|
|
32
|
+
return result.success
|
|
33
|
+
? { ok: true, value: result.data }
|
|
34
|
+
: { ok: false, issues: result.error.issues };
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Whether `issue` is Zod's: every Zod issue has a `code`, a fuz_schema issue a `kind`.
|
|
38
|
+
*/
|
|
39
|
+
export const is_zod_issue = (issue) => 'code' in issue;
|
|
40
|
+
/**
|
|
41
|
+
* Whether `issue` sits on the input itself rather than on one of its fields:
|
|
42
|
+
* a non-object input, or an unknown key on the input object — what the Rust
|
|
43
|
+
* twin refuses before reading any field.
|
|
44
|
+
*
|
|
45
|
+
* Zod reports both at an empty path, its `unrecognized_keys` naming the keys.
|
|
46
|
+
* fuz_schema reports a non-object at an empty path and each unknown key as an
|
|
47
|
+
* `unknown_key` issue whose path ends at the key, so one on the input has a
|
|
48
|
+
* path of the key alone. An unknown key on a nested object is on that field,
|
|
49
|
+
* as Zod's is.
|
|
50
|
+
*
|
|
51
|
+
* On the wire the `unknown_key` rule changes no answer today: a root
|
|
52
|
+
* `unknown_key` comes from a root `object`, which `resolve_issues_invalid_reason`
|
|
53
|
+
* already answers with none from its check of the input's keys, or from a
|
|
54
|
+
* schema such as a `variant` whose fields resolve no reason. It is kept as the
|
|
55
|
+
* direct statement of Zod's rule.
|
|
56
|
+
*
|
|
57
|
+
* @param issue - one issue of a failed parse
|
|
58
|
+
*/
|
|
59
|
+
export const issue_is_on_input = (issue) => issue.path.length === 0 ||
|
|
60
|
+
(!is_zod_issue(issue) && issue.kind === 'unknown_key' && issue.path.length === 1);
|
|
61
|
+
/**
|
|
62
|
+
* The unknown keys among `issues`, each with the path of its object, or
|
|
63
|
+
* `null` when any issue is something else.
|
|
64
|
+
*
|
|
65
|
+
* A Zod `unrecognized_keys` issue is at its object's path and names every
|
|
66
|
+
* key; a fuz_schema `unknown_key` issue is one key, the last element of its
|
|
67
|
+
* path.
|
|
68
|
+
*
|
|
69
|
+
* @param issues - a failed parse's issues
|
|
70
|
+
* @returns a target per issue, or `null` when not every issue is an unknown key
|
|
71
|
+
*/
|
|
72
|
+
export const unknown_key_targets = (issues) => {
|
|
73
|
+
const targets = [];
|
|
74
|
+
for (const issue of issues) {
|
|
75
|
+
if (is_zod_issue(issue)) {
|
|
76
|
+
if (issue.code !== 'unrecognized_keys')
|
|
77
|
+
return null;
|
|
78
|
+
targets.push({ path: issue.path, keys: issue.keys });
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
if (issue.kind !== 'unknown_key' || issue.path.length === 0)
|
|
82
|
+
return null;
|
|
83
|
+
targets.push({ path: issue.path.slice(0, -1), keys: [issue.path.at(-1)] });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return targets;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* A failed parse's issues as text: Zod's `z.prettifyError` text for Zod
|
|
90
|
+
* issues, and for fuz_schema issues their `format_issue` lines.
|
|
91
|
+
*
|
|
92
|
+
* @param issues - a failed parse's issues, all of one library
|
|
93
|
+
*/
|
|
94
|
+
export const format_issues = (issues) => {
|
|
95
|
+
const first = issues[0];
|
|
96
|
+
if (!first)
|
|
97
|
+
return '';
|
|
98
|
+
if (is_zod_issue(first)) {
|
|
99
|
+
return z.prettifyError({ issues: issues });
|
|
100
|
+
}
|
|
101
|
+
return issues.map(format_issue).join('\n');
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Whether `err` is a thrown validation failure of either library: a
|
|
105
|
+
* `z.ZodError` or a fuz_schema `SchemaError` (`parse_or_throw`). Both carry
|
|
106
|
+
* the failed parse's `issues`.
|
|
107
|
+
*
|
|
108
|
+
* @param err - a caught value
|
|
109
|
+
*/
|
|
110
|
+
export const is_schema_validation_error = (err) => err instanceof z.ZodError || err instanceof SchemaError;
|
package/dist/schema_meta.d.ts
CHANGED
|
@@ -4,12 +4,26 @@
|
|
|
4
4
|
* Cross-cutting metadata shape used by auth and action input schemas,
|
|
5
5
|
* surface generation, and test helpers. The env schemas are
|
|
6
6
|
* `@fuzdev/fuz_schema` and carry the same keys in its `meta`
|
|
7
|
-
* (`sensitivity.ts`, `find_schema_sensitivity`)
|
|
7
|
+
* (`sensitivity.ts`, `find_schema_sensitivity`); this module adds
|
|
8
|
+
* `invalid_reason` to fuz_schema's `SchemaMeta`, so the declared refusal
|
|
9
|
+
* reason of an action input reads the same whichever library its schema is.
|
|
8
10
|
*
|
|
9
11
|
* @module
|
|
10
12
|
*/
|
|
11
13
|
import type { z } from 'zod';
|
|
12
14
|
import type { Sensitivity } from './sensitivity.js';
|
|
15
|
+
import { type AnyIssue, type ValidationSchema } from './schema_issues.js';
|
|
16
|
+
declare module '@fuzdev/fuz_schema/meta.ts' {
|
|
17
|
+
interface SchemaMeta {
|
|
18
|
+
/**
|
|
19
|
+
* The `error.data.reason` an action input refuses this field with, as
|
|
20
|
+
* `SchemaFieldMeta.invalid_reason` declares it on a Zod field. Read
|
|
21
|
+
* through the field's layers (`get_schema_meta`), the outermost
|
|
22
|
+
* declaration winning.
|
|
23
|
+
*/
|
|
24
|
+
invalid_reason?: string;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
13
27
|
/** Zod `.meta()` shape for fuz_app schema metadata conventions. */
|
|
14
28
|
export interface SchemaFieldMeta {
|
|
15
29
|
description?: string;
|
|
@@ -126,24 +140,33 @@ export declare const schema_has_sensitive_field: (schema: z.ZodType) => boolean;
|
|
|
126
140
|
* key) ends the walk, so a fault inside a declared field still resolves to
|
|
127
141
|
* that field's reason. An empty path — a whole-input fault such as an
|
|
128
142
|
* unrecognized key on the input object — resolves to none, as does a schema
|
|
129
|
-
* that is not an object.
|
|
143
|
+
* that is not an object. A `@fuzdev/fuz_schema` schema is walked through its
|
|
144
|
+
* entries (`get_schema_entries`) and reads the reason with `get_schema_meta`.
|
|
130
145
|
*
|
|
131
|
-
* @param input_schema - an action's input schema
|
|
132
|
-
* @param path - the failing issue's path
|
|
146
|
+
* @param input_schema - an action's input schema, Zod or fuz_schema
|
|
147
|
+
* @param path - the failing issue's path
|
|
133
148
|
* @returns the declared reason, or `undefined`
|
|
134
149
|
*/
|
|
135
|
-
export declare const resolve_invalid_reason: (input_schema:
|
|
150
|
+
export declare const resolve_invalid_reason: (input_schema: ValidationSchema, path: ReadonlyArray<PropertyKey>) => string | undefined;
|
|
136
151
|
/**
|
|
137
152
|
* The `error.data.reason` a failed input parse answers: the declared reason
|
|
138
153
|
* of the first issue's field (`resolve_invalid_reason`), or none when any
|
|
139
|
-
* issue sits on the input itself. Such an issue is an
|
|
140
|
-
* input object (or a non-object input), which the Rust
|
|
141
|
-
* reading any field, so a stale client sending an extra
|
|
142
|
-
* answer from both spines whatever else its body gets
|
|
154
|
+
* issue sits on the input itself (`issue_is_on_input`). Such an issue is an
|
|
155
|
+
* unknown key on the input object (or a non-object input), which the Rust
|
|
156
|
+
* twin refuses before reading any field, so a stale client sending an extra
|
|
157
|
+
* key gets the same answer from both spines whatever else its body gets
|
|
158
|
+
* wrong.
|
|
159
|
+
*
|
|
160
|
+
* A `@fuzdev/fuz_schema` parse reports at most a hundred issues, so faults on
|
|
161
|
+
* the fields can crowd an unknown key out of them. For a strict `object`
|
|
162
|
+
* input, `input` is checked for a key the schema doesn't name, as the Rust
|
|
163
|
+
* twin checks it, whatever the issues hold. A Zod parse reports every issue
|
|
164
|
+
* and `input` is not read.
|
|
143
165
|
*
|
|
144
|
-
* @param input_schema - an action's input schema
|
|
145
|
-
* @param issues - the failed parse's issues, in
|
|
166
|
+
* @param input_schema - an action's input schema, Zod or fuz_schema
|
|
167
|
+
* @param issues - the failed parse's issues, in the library's order
|
|
168
|
+
* @param input - the value that was parsed
|
|
146
169
|
* @returns the declared reason, or `undefined`
|
|
147
170
|
*/
|
|
148
|
-
export declare const resolve_issues_invalid_reason: (input_schema:
|
|
171
|
+
export declare const resolve_issues_invalid_reason: (input_schema: ValidationSchema, issues: ReadonlyArray<AnyIssue>, input: unknown) => string | undefined;
|
|
149
172
|
//# sourceMappingURL=schema_meta.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema_meta.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/schema_meta.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"schema_meta.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/schema_meta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQ7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAqB,KAAK,QAAQ,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE7F,OAAO,QAAQ,4BAA4B,CAAC;IAC3C,UAAU,UAAU;QACnB;;;;;WAKG;QACH,cAAc,CAAC,EAAE,MAAM,CAAC;KACxB;CACD;AAED,mEAAmE;AACnE,MAAM,WAAW,eAAe;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B;;;;;;;;;;OAUG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,OACkB,CAAC;AAEtF;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,IAAI,SAAS,MAAM,eAAe,EACnE,QAAQ,CAAC,CAAC,OAAO,EACjB,KAAK,IAAI,KACP,eAAe,CAAC,IAAI,CAAC,GAAG,SAM1B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,MAAM,GAAG,SACvB,CAAC;AA4D7C;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,WAAW,GAAG,SACrC,CAAC;AAEjC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,0BAA0B,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,OAClB,CAAC;AAE9C;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,GAClC,cAAc,gBAAgB,EAC9B,MAAM,aAAa,CAAC,WAAW,CAAC,KAC9B,MAAM,GAAG,SAaX,CAAC;AAoBF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,6BAA6B,GACzC,cAAc,gBAAgB,EAC9B,QAAQ,aAAa,CAAC,QAAQ,CAAC,EAC/B,OAAO,OAAO,KACZ,MAAM,GAAG,SAKX,CAAC"}
|
package/dist/schema_meta.js
CHANGED
|
@@ -4,11 +4,16 @@
|
|
|
4
4
|
* Cross-cutting metadata shape used by auth and action input schemas,
|
|
5
5
|
* surface generation, and test helpers. The env schemas are
|
|
6
6
|
* `@fuzdev/fuz_schema` and carry the same keys in its `meta`
|
|
7
|
-
* (`sensitivity.ts`, `find_schema_sensitivity`)
|
|
7
|
+
* (`sensitivity.ts`, `find_schema_sensitivity`); this module adds
|
|
8
|
+
* `invalid_reason` to fuz_schema's `SchemaMeta`, so the declared refusal
|
|
9
|
+
* reason of an action input reads the same whichever library its schema is.
|
|
8
10
|
*
|
|
9
11
|
* @module
|
|
10
12
|
*/
|
|
13
|
+
import { is_schema } from '@fuzdev/fuz_schema/schema.ts';
|
|
14
|
+
import { get_schema_entries, get_schema_meta, unwrap_schema } from '@fuzdev/fuz_schema/introspect.ts';
|
|
11
15
|
import { zod_get_schema_layers, zod_unwrap_to_object } from './zod.js';
|
|
16
|
+
import { issue_is_on_input } from './schema_issues.js';
|
|
12
17
|
/**
|
|
13
18
|
* Whether `schema` carries `empty_input_handler_guarded: true` in its `.meta()`.
|
|
14
19
|
*
|
|
@@ -157,13 +162,16 @@ export const schema_has_sensitive_field = (schema) => walk_sensitivity(schema, t
|
|
|
157
162
|
* key) ends the walk, so a fault inside a declared field still resolves to
|
|
158
163
|
* that field's reason. An empty path — a whole-input fault such as an
|
|
159
164
|
* unrecognized key on the input object — resolves to none, as does a schema
|
|
160
|
-
* that is not an object.
|
|
165
|
+
* that is not an object. A `@fuzdev/fuz_schema` schema is walked through its
|
|
166
|
+
* entries (`get_schema_entries`) and reads the reason with `get_schema_meta`.
|
|
161
167
|
*
|
|
162
|
-
* @param input_schema - an action's input schema
|
|
163
|
-
* @param path - the failing issue's path
|
|
168
|
+
* @param input_schema - an action's input schema, Zod or fuz_schema
|
|
169
|
+
* @param path - the failing issue's path
|
|
164
170
|
* @returns the declared reason, or `undefined`
|
|
165
171
|
*/
|
|
166
172
|
export const resolve_invalid_reason = (input_schema, path) => {
|
|
173
|
+
if (is_schema(input_schema))
|
|
174
|
+
return resolve_schema_invalid_reason(input_schema, path);
|
|
167
175
|
let reason;
|
|
168
176
|
let schema = input_schema;
|
|
169
177
|
for (const segment of path) {
|
|
@@ -178,21 +186,61 @@ export const resolve_invalid_reason = (input_schema, path) => {
|
|
|
178
186
|
}
|
|
179
187
|
return reason;
|
|
180
188
|
};
|
|
189
|
+
// the fuz_schema walk of `resolve_invalid_reason`
|
|
190
|
+
const resolve_schema_invalid_reason = (input_schema, path) => {
|
|
191
|
+
let reason;
|
|
192
|
+
let schema = input_schema;
|
|
193
|
+
for (const segment of path) {
|
|
194
|
+
if (typeof segment !== 'string')
|
|
195
|
+
break;
|
|
196
|
+
const entries = get_schema_entries(schema);
|
|
197
|
+
if (!entries || !Object.hasOwn(entries, segment))
|
|
198
|
+
break;
|
|
199
|
+
const field = entries[segment];
|
|
200
|
+
reason = get_schema_meta(field, 'invalid_reason') ?? reason;
|
|
201
|
+
schema = field;
|
|
202
|
+
}
|
|
203
|
+
return reason;
|
|
204
|
+
};
|
|
181
205
|
/**
|
|
182
206
|
* The `error.data.reason` a failed input parse answers: the declared reason
|
|
183
207
|
* of the first issue's field (`resolve_invalid_reason`), or none when any
|
|
184
|
-
* issue sits on the input itself. Such an issue is an
|
|
185
|
-
* input object (or a non-object input), which the Rust
|
|
186
|
-
* reading any field, so a stale client sending an extra
|
|
187
|
-
* answer from both spines whatever else its body gets
|
|
208
|
+
* issue sits on the input itself (`issue_is_on_input`). Such an issue is an
|
|
209
|
+
* unknown key on the input object (or a non-object input), which the Rust
|
|
210
|
+
* twin refuses before reading any field, so a stale client sending an extra
|
|
211
|
+
* key gets the same answer from both spines whatever else its body gets
|
|
212
|
+
* wrong.
|
|
213
|
+
*
|
|
214
|
+
* A `@fuzdev/fuz_schema` parse reports at most a hundred issues, so faults on
|
|
215
|
+
* the fields can crowd an unknown key out of them. For a strict `object`
|
|
216
|
+
* input, `input` is checked for a key the schema doesn't name, as the Rust
|
|
217
|
+
* twin checks it, whatever the issues hold. A Zod parse reports every issue
|
|
218
|
+
* and `input` is not read.
|
|
188
219
|
*
|
|
189
|
-
* @param input_schema - an action's input schema
|
|
190
|
-
* @param issues - the failed parse's issues, in
|
|
220
|
+
* @param input_schema - an action's input schema, Zod or fuz_schema
|
|
221
|
+
* @param issues - the failed parse's issues, in the library's order
|
|
222
|
+
* @param input - the value that was parsed
|
|
191
223
|
* @returns the declared reason, or `undefined`
|
|
192
224
|
*/
|
|
193
|
-
export const resolve_issues_invalid_reason = (input_schema, issues) => {
|
|
225
|
+
export const resolve_issues_invalid_reason = (input_schema, issues, input) => {
|
|
194
226
|
const first = issues[0];
|
|
195
|
-
if (!first || issues.some(
|
|
227
|
+
if (!first || issues.some(issue_is_on_input))
|
|
228
|
+
return undefined;
|
|
229
|
+
if (is_schema(input_schema) && has_unknown_root_key(input_schema, input))
|
|
196
230
|
return undefined;
|
|
197
231
|
return resolve_invalid_reason(input_schema, first.path);
|
|
198
232
|
};
|
|
233
|
+
// whether `input` has a key the strict `object` at the root of `schema` doesn't
|
|
234
|
+
// name, read as that object's own check reads it (`for in`, then `Object.hasOwn`)
|
|
235
|
+
const has_unknown_root_key = (schema, input) => {
|
|
236
|
+
const root = unwrap_schema(schema);
|
|
237
|
+
if (root.kind !== 'object')
|
|
238
|
+
return false;
|
|
239
|
+
if (typeof input !== 'object' || input === null || Array.isArray(input))
|
|
240
|
+
return false;
|
|
241
|
+
for (const key in input) {
|
|
242
|
+
if (!Object.hasOwn(root.def, key))
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
return false;
|
|
246
|
+
};
|
package/dist/testing/CLAUDE.md
CHANGED
|
@@ -481,7 +481,7 @@ Support functions:
|
|
|
481
481
|
|
|
482
482
|
Walks Zod schemas to generate valid values for adversarial/round-trip tests.
|
|
483
483
|
|
|
484
|
-
- `to_field_json_schema(field_schema)` — the field's JSON Schema rendered with `io: 'input'`, so a `.transform()` or pipe field (`Username`) yields its input-side bounds and pattern instead of throwing; a `.nullable()` / `.nullish()` field's one non-null `anyOf` branch
|
|
484
|
+
- `to_field_json_schema(field_schema)` — the field's JSON Schema rendered with `io: 'input'`, so a `.transform()` or pipe field (`Username`) yields its input-side bounds and pattern instead of throwing; a `.nullable()` / `.nullish()` field's one non-null `anyOf` branch (or one non-null `type` of a `type` array) is returned. Both libraries render with `unrepresentable: 'any'`, so it is never `null`: a part JSON Schema can't say (a `z.date()`, a `z.custom()`, a fuz_schema `check`) is left out or `{}` and the bounds around it still read; it throws on a schema an emitter refuses even then. A pipe yields its input stage only, and a `.refine()` never appears (a code-point length bound generates nothing). Every JSON Schema read in the generators goes through it.
|
|
485
485
|
- `detect_format(field_schema)` — `detect_json_schema_format` over `to_field_json_schema`: the `format`, `'pattern'` for a regex, or `null`.
|
|
486
486
|
- `generate_valid_value(field, field_schema)` — base-type switch producing a valid sample (UUIDs → nil UUID, strings → `'xxxxxxxxxx'`, numbers → `1`, objects → `generate_valid_object` against the field schema, so a nested refinement is satisfied too, enums → first entry, etc.). For branded-string refinements, walks a fallback chain synthesized from the `pattern` string the JSON Schema representation exposes: fixed-length hex (`^[0-9a-f]{N}$` — blake3 / sha256 / md5 digests; `0`.repeat(N)), prefix-lengthed slug (`^<prefix>_[A-Za-z0-9_-]{N}$` — `ApiTokenId`-style ids; `<prefix>_` + `x`.repeat(N)), absolute path prefix, URL prefix, two `/`-joined segments (an `owner/name` slug). First candidate that `safeParse` accepts is used.
|
|
487
487
|
- `generate_valid_string_param(field, field_schema)` — a string a URL-sourced field (route param, query value) accepts: the nil UUID for a UUID field, else the first of `test_value`, the generated valid value as a string, `1`, `0`, `true`, `false`, the field's JSON Schema `default` or lower bound as a string (a preprocessed integer whose minimum is above one) and a synthesized string the field accepts; `null` when none does. The params and query case generators build their base from it.
|
|
@@ -560,7 +560,10 @@ rather than `ERROR_INVALID_JSON_BODY`.
|
|
|
560
560
|
404 in `error_schemas` + an extractable error code (`z.literal` or first
|
|
561
561
|
`z.enum`), replaces the handler with a stub returning `{error: <code>}`,
|
|
562
562
|
fires with nil-UUID params, asserts 404 + body matches the declared 404 Zod
|
|
563
|
-
schema. No DB needed.
|
|
563
|
+
schema. No DB needed. The code comes from `extract_404_error_code(schema)`,
|
|
564
|
+
which reads the output-side JSON Schema of a Zod or fuz_schema schema with
|
|
565
|
+
`unrepresentable: 'any'`, so a field JSON Schema can't say beside `error`
|
|
566
|
+
(a transform) no longer drops the route from the suite.
|
|
564
567
|
|
|
565
568
|
### `adversarial_headers.ts` — header injection suite
|
|
566
569
|
|
|
@@ -756,8 +759,8 @@ waiter on timeout so the `waiters` array doesn't grow.
|
|
|
756
759
|
Six tests in two top-level groups:
|
|
757
760
|
|
|
758
761
|
1. **schema-level** (3 tests, no DB) — walks JSON Schema representations:
|
|
759
|
-
- `no sensitive fields in any output schema` — `sensitive_field_blocklist`
|
|
760
|
-
- `no admin-only fields in non-admin output schemas` — `admin_only_field_blocklist`
|
|
762
|
+
- `no sensitive fields in any output schema` — `sensitive_field_blocklist`, over every route, RPC method and WS method output, and the params the server pushes over WS (a `remote_notification`'s payload, whose `output` is `z.void()`, and the request of a `request_response` with `initiator` `'backend'` or `'both'`)
|
|
763
|
+
- `no admin-only fields in non-admin output schemas` — `admin_only_field_blocklist`, over the route outputs a non-admin reaches; routes only, since the blocklist matches by name and domain RPC/WS outputs carry `created_by`/`updated_by` legitimately. Admin-gated means every role in an any-of `roles` (or a WS endpoint's `required_roles`) is `admin` or `keeper`, or the daemon token is required
|
|
761
764
|
- `no sensitive fields in any error schema`
|
|
762
765
|
2. **runtime** (3 tests, DB-backed via `create_test_app`):
|
|
763
766
|
- `unauthenticated error responses contain no sensitive fields`
|
|
@@ -765,11 +768,21 @@ Six tests in two top-level groups:
|
|
|
765
768
|
- `all 2xx responses pass field blocklists` — GETs sorted before POSTs so data-returning routes fire before destructive ones (logout, revoke-all) invalidate sessions
|
|
766
769
|
|
|
767
770
|
Support functions: `collect_json_schema_property_names(schema)` (walks
|
|
768
|
-
`properties`/`
|
|
769
|
-
`
|
|
770
|
-
|
|
771
|
+
`properties`/`patternProperties`/`additionalProperties`/`items`/`prefixItems`/`contains`,
|
|
772
|
+
`allOf`/`anyOf`/`oneOf`/`not`/`if`/`then`/`else`, and `$defs`/`definitions`
|
|
773
|
+
values, where a lazy or `.meta({id})` schema's body sits behind a `$ref`),
|
|
774
|
+
`assert_output_schemas_no_sensitive_fields(surface_source, fields?, skip_routes?)`,
|
|
775
|
+
`assert_non_admin_schemas_no_admin_fields(surface_source, fields?, skip_routes?)`.
|
|
776
|
+
Both read each output from its spec on both sides (`schema_to_surface`): the
|
|
777
|
+
output side the surface records, and the input side, since a transform's output
|
|
778
|
+
has no JSON Schema form and a field inside a transformed subtree shows only
|
|
779
|
+
there. The input side is a superset, so a transform that deliberately drops a
|
|
780
|
+
blocklisted field is flagged too — skip that output by its key.
|
|
771
781
|
|
|
772
782
|
Options: `{setup_test, surface_source, sensitive_fields?, admin_only_fields?, skip_routes?}`.
|
|
783
|
+
`skip_routes` keys a route as `'METHOD /path'`, an RPC or WS method output
|
|
784
|
+
as `'/path method_name'`, and pushed WS params as `'/path method_name params'`
|
|
785
|
+
(the schema-level checks only).
|
|
773
786
|
|
|
774
787
|
### `rate_limiting.ts` — `describe_rate_limiting_tests`
|
|
775
788
|
|
|
@@ -1917,7 +1930,7 @@ the option type states whether the bundle is read.
|
|
|
1917
1930
|
pages tiling every row; a `data` that is no `CellData` — a non-object, or a
|
|
1918
1931
|
non-string `label` / `summary` — refused 400 `invalid_params` with the
|
|
1919
1932
|
generic message and no reason (no `data` beyond a TS spine's DEV-only
|
|
1920
|
-
`issues`, an array of
|
|
1933
|
+
`issues`, an array of the schema library's issues) on `cell_create`, on `cell_update` of a
|
|
1921
1934
|
missing and of a hidden cell, and, with `cell_relations`, on `cell_clone`'s
|
|
1922
1935
|
`with_data_patch` — ahead of the 404 mask the same hidden-cell call answers
|
|
1923
1936
|
when well-typed, with the keeper's cell count unchanged; those cases run as
|
|
@@ -2681,7 +2694,7 @@ USERNAME_LENGTH_MAX]` = `[3, 39]` boundary edges (just-outside → 400,
|
|
|
2681
2694
|
`_`/`-` accepted), catching an off-by-one or position bug in the TS Zod
|
|
2682
2695
|
`.min/.max/.regex` vs the Rust byte-scan `is_valid_username_for_creation`.
|
|
2683
2696
|
- **Email format (creation)** — the optional signup `email` validated to the
|
|
2684
|
-
loose `local@domain.tld` shape (TS `Email` `^[^\s@]+@[^\s@]+\.[^\s@]+$` + 254-byte
|
|
2697
|
+
loose `local@domain.tld` shape (TS `Email` `^[^\s\u0085@]+@[^\s\u0085@]+\.[^\s\u0085@]+$` + 254-byte
|
|
2685
2698
|
bound, Rust `is_valid_email`): malformed (no `@` / no domain dot / empty
|
|
2686
2699
|
side / dot at a domain edge / whitespace / over-length) → 400, well-formed →
|
|
2687
2700
|
403 no-invite. Accepted siblings include the single-char-TLD `a@b.c` that
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import './assert_dev_env.js';
|
|
2
|
+
import type { ValidationSchema } from '../schema_issues.js';
|
|
2
3
|
import type { AdversarialTestOptions } from './attack_surface.js';
|
|
4
|
+
/**
|
|
5
|
+
* Extract the error code from a 404 error schema, Zod or `@fuzdev/fuz_schema`,
|
|
6
|
+
* for use in the stub handler.
|
|
7
|
+
*
|
|
8
|
+
* Reads the schema's output-side JSON Schema with `unrepresentable: 'any'`,
|
|
9
|
+
* so a field JSON Schema can't say (a transform, a `z.custom()`) beside
|
|
10
|
+
* `error` doesn't hide the code. Supports a literal (`{const: '...'}`) and an
|
|
11
|
+
* enum (`{enum: [...]}`, uses first value); `null` when `error` is neither.
|
|
12
|
+
* A schema either emitter refuses outright throws.
|
|
13
|
+
*
|
|
14
|
+
* @param schema - a route's declared 404 error schema
|
|
15
|
+
* @returns the code the stub handler answers with, or `null`
|
|
16
|
+
*/
|
|
17
|
+
export declare const extract_404_error_code: (schema: ValidationSchema) => string | null;
|
|
3
18
|
/**
|
|
4
19
|
* Generate adversarial 404 response validation tests.
|
|
5
20
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adversarial_404.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_404.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"adversarial_404.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_404.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAqB7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAOlE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,sBAAsB,GAAI,QAAQ,gBAAgB,KAAG,MAAM,GAAG,IAe1E,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,GAAI,SAAS,sBAAsB,KAAG,IA+E1E,CAAC"}
|
|
@@ -12,31 +12,38 @@ import './assert_dev_env.js';
|
|
|
12
12
|
*/
|
|
13
13
|
import { test, assert, describe } from 'vitest';
|
|
14
14
|
import { z } from 'zod';
|
|
15
|
+
import { is_schema } from '@fuzdev/fuz_schema/schema.ts';
|
|
16
|
+
import { to_json_schema } from '@fuzdev/fuz_schema/json_schema.ts';
|
|
15
17
|
import { is_null_schema } from '../http/schema_helpers.js';
|
|
16
18
|
import { create_auth_test_apps, create_route_skip_filter, select_auth_app } from './auth_apps.js';
|
|
17
19
|
import { resolve_valid_path, generate_valid_body, to_route_content_type } from './schema_generators.js';
|
|
18
20
|
/**
|
|
19
|
-
* Extract the error code from a 404
|
|
21
|
+
* Extract the error code from a 404 error schema, Zod or `@fuzdev/fuz_schema`,
|
|
22
|
+
* for use in the stub handler.
|
|
20
23
|
*
|
|
21
|
-
*
|
|
24
|
+
* Reads the schema's output-side JSON Schema with `unrepresentable: 'any'`,
|
|
25
|
+
* so a field JSON Schema can't say (a transform, a `z.custom()`) beside
|
|
26
|
+
* `error` doesn't hide the code. Supports a literal (`{const: '...'}`) and an
|
|
27
|
+
* enum (`{enum: [...]}`, uses first value); `null` when `error` is neither.
|
|
28
|
+
* A schema either emitter refuses outright throws.
|
|
29
|
+
*
|
|
30
|
+
* @param schema - a route's declared 404 error schema
|
|
31
|
+
* @returns the code the stub handler answers with, or `null`
|
|
22
32
|
*/
|
|
23
|
-
const extract_404_error_code = (schema) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
catch {
|
|
38
|
-
// schema can't be converted
|
|
39
|
-
}
|
|
33
|
+
export const extract_404_error_code = (schema) => {
|
|
34
|
+
const json = (is_schema(schema)
|
|
35
|
+
? to_json_schema(schema, { unrepresentable: 'any' })
|
|
36
|
+
: z.toJSONSchema(schema, { unrepresentable: 'any' }));
|
|
37
|
+
if (json.type !== 'object' || !json.properties || typeof json.properties !== 'object')
|
|
38
|
+
return null;
|
|
39
|
+
const props = json.properties;
|
|
40
|
+
if (!props.error || typeof props.error !== 'object')
|
|
41
|
+
return null;
|
|
42
|
+
const error_schema = props.error;
|
|
43
|
+
if (typeof error_schema.const === 'string')
|
|
44
|
+
return error_schema.const;
|
|
45
|
+
if (Array.isArray(error_schema.enum) && typeof error_schema.enum[0] === 'string')
|
|
46
|
+
return error_schema.enum[0];
|
|
40
47
|
return null;
|
|
41
48
|
};
|
|
42
49
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adversarial_input_cases.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_input_cases.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAmE/F,4EAA4E;AAC5E,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;IACd;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,OAAO,0BAA0B,GAAG,OAAO,uBAAuB,CAAC;CACnF;AAED,8DAA8D;AAC9D,MAAM,WAAW,cAAc;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED,wDAAwD;AACxD,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAID,+CAA+C;AAC/C,MAAM,WAAW,oBAAoB;IACpC;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,iFAAiF;IACjF,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,yBAAyB,GACrC,cAAc,CAAC,CAAC,OAAO,EACvB,UAAU,oBAAoB,KAC5B,KAAK,CAAC,aAAa,
|
|
1
|
+
{"version":3,"file":"adversarial_input_cases.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/adversarial_input_cases.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAmE/F,4EAA4E;AAC5E,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;IACd;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,OAAO,0BAA0B,GAAG,OAAO,uBAAuB,CAAC;CACnF;AAED,8DAA8D;AAC9D,MAAM,WAAW,cAAc;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED,wDAAwD;AACxD,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAID,+CAA+C;AAC/C,MAAM,WAAW,oBAAoB;IACpC;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,iFAAiF;IACjF,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,yBAAyB,GACrC,cAAc,CAAC,CAAC,OAAO,EACvB,UAAU,oBAAoB,KAC5B,KAAK,CAAC,aAAa,CAoOrB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,GACnC,cAAc,CAAC,CAAC,OAAO,EACvB,WAAW,aAAa,KACtB,MAAM,GAAG,SAG+C,CAAC;AAkC5D;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,GAAI,eAAe,CAAC,CAAC,SAAS,KAAG,KAAK,CAAC,cAAc,CAoB3F,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,yBAAyB,GAAI,cAAc,CAAC,CAAC,SAAS,KAAG,KAAK,CAAC,aAAa,CAkCxF,CAAC"}
|
|
@@ -195,11 +195,11 @@ export const generate_input_test_cases = (input_schema, options) => {
|
|
|
195
195
|
if (field.required && !field.nullable && field.base_type !== 'null') {
|
|
196
196
|
push_field_case(`null: ${field.name}`, null, 'type');
|
|
197
197
|
}
|
|
198
|
+
if (!field_base)
|
|
199
|
+
continue; // no body to break a constraint on
|
|
198
200
|
// the field's input-side JSON Schema — format, pattern and bounds, read
|
|
199
201
|
// through a transform or pipe and under a nullable's `anyOf`
|
|
200
202
|
const json = to_field_json_schema(field_schema);
|
|
201
|
-
if (!json || !field_base)
|
|
202
|
-
continue; // no constraints, or no body to break them on
|
|
203
203
|
// format violation for constrained string fields
|
|
204
204
|
const format = detect_json_schema_format(json);
|
|
205
205
|
if (format) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell_crud.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/cross_backend/cell_crud.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AA0E9B,OAAO,KAAK,EAAE,uCAAuC,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"cell_crud.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/cross_backend/cell_crud.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AA0E9B,OAAO,KAAK,EAAE,uCAAuC,EAAE,MAAM,YAAY,CAAC;AAkE1E,eAAO,MAAM,8BAA8B,GAC1C,SAAS,uCAAuC,KAC9C,IA4uBF,CAAC"}
|
|
@@ -79,9 +79,10 @@ const MISTYPED_CELL_DATA = [
|
|
|
79
79
|
const INVALID_PARAMS_MESSAGE = jsonrpc_error_messages.invalid_params().message;
|
|
80
80
|
/**
|
|
81
81
|
* Assert `r` is a schema refusal: 400 `invalid_params` with the generic
|
|
82
|
-
* message and no `data`, save the
|
|
83
|
-
*
|
|
84
|
-
* `
|
|
82
|
+
* message and no `data`, save the issues a TS spine adds under DEV alone —
|
|
83
|
+
* an array of the schema library's issue objects, and never a `reason`. A Zod
|
|
84
|
+
* issue has a string `code` and `message`; a fuz_schema issue a string
|
|
85
|
+
* `kind`, and a `message` only when one was set.
|
|
85
86
|
*/
|
|
86
87
|
const assert_schema_refusal = (r, label) => {
|
|
87
88
|
const detail = `${label}: got ${r.status} ${JSON.stringify(r.error ?? r.result)}`;
|
|
@@ -97,10 +98,11 @@ const assert_schema_refusal = (r, label) => {
|
|
|
97
98
|
const { issues } = data;
|
|
98
99
|
assert.ok(Array.isArray(issues), `${detail} — DEV-only issues that are no array`);
|
|
99
100
|
for (const issue of issues) {
|
|
101
|
+
const { code, kind, message } = (issue ?? {});
|
|
100
102
|
assert.ok(typeof issue === 'object' &&
|
|
101
103
|
issue !== null &&
|
|
102
|
-
typeof
|
|
103
|
-
|
|
104
|
+
((typeof code === 'string' && typeof message === 'string') ||
|
|
105
|
+
(typeof kind === 'string' && (message === undefined || typeof message === 'string'))), `${detail} — a DEV-only issue that is no Zod or fuz_schema issue`);
|
|
104
106
|
}
|
|
105
107
|
};
|
|
106
108
|
/**
|