typesea 0.1.0 → 0.2.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/CHANGELOG.md +67 -6
- package/README.md +98 -17
- package/dist/adapters/index.d.ts +50 -8
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +169 -48
- package/dist/aot/index.d.ts +18 -2
- package/dist/aot/index.d.ts.map +1 -1
- package/dist/aot/index.js +93 -14
- package/dist/async/index.d.ts +28 -56
- package/dist/async/index.d.ts.map +1 -1
- package/dist/async/index.js +94 -37
- package/dist/builders/composite.d.ts +37 -6
- package/dist/builders/composite.d.ts.map +1 -1
- package/dist/builders/composite.js +84 -10
- package/dist/builders/index.d.ts +2 -0
- package/dist/builders/index.d.ts.map +1 -1
- package/dist/builders/index.js +2 -0
- package/dist/builders/modifier.d.ts +30 -5
- package/dist/builders/modifier.d.ts.map +1 -1
- package/dist/builders/modifier.js +38 -5
- package/dist/builders/object/guard.d.ts +18 -22
- package/dist/builders/object/guard.d.ts.map +1 -1
- package/dist/builders/object/guard.js +26 -26
- package/dist/builders/object/index.d.ts +2 -0
- package/dist/builders/object/index.d.ts.map +1 -1
- package/dist/builders/object/index.js +2 -0
- package/dist/builders/object/schema.d.ts +55 -9
- package/dist/builders/object/schema.d.ts.map +1 -1
- package/dist/builders/object/schema.js +92 -15
- package/dist/builders/object/types.d.ts +5 -31
- package/dist/builders/object/types.d.ts.map +1 -1
- package/dist/builders/object/types.js +2 -0
- package/dist/builders/scalar.d.ts +29 -8
- package/dist/builders/scalar.d.ts.map +1 -1
- package/dist/builders/scalar.js +33 -8
- package/dist/builders/table.d.ts +4 -0
- package/dist/builders/table.d.ts.map +1 -1
- package/dist/builders/table.js +4 -0
- package/dist/builders/types.d.ts +14 -4
- package/dist/builders/types.d.ts.map +1 -1
- package/dist/builders/types.js +2 -0
- package/dist/compile/check-composite.d.ts +22 -1
- package/dist/compile/check-composite.d.ts.map +1 -1
- package/dist/compile/check-composite.js +564 -24
- package/dist/compile/check-scalar.d.ts +78 -0
- package/dist/compile/check-scalar.d.ts.map +1 -1
- package/dist/compile/check-scalar.js +432 -1
- package/dist/compile/check.d.ts +12 -0
- package/dist/compile/check.d.ts.map +1 -1
- package/dist/compile/check.js +37 -0
- package/dist/compile/context.d.ts +47 -9
- package/dist/compile/context.d.ts.map +1 -1
- package/dist/compile/context.js +51 -8
- package/dist/compile/graph-predicate.d.ts +4 -2
- package/dist/compile/graph-predicate.d.ts.map +1 -1
- package/dist/compile/graph-predicate.js +1907 -171
- package/dist/compile/guard.d.ts +15 -24
- package/dist/compile/guard.d.ts.map +1 -1
- package/dist/compile/guard.js +158 -74
- package/dist/compile/index.d.ts +3 -1
- package/dist/compile/index.d.ts.map +1 -1
- package/dist/compile/index.js +2 -0
- package/dist/compile/issue.d.ts +110 -0
- package/dist/compile/issue.d.ts.map +1 -1
- package/dist/compile/issue.js +184 -1
- package/dist/compile/names.d.ts +12 -2
- package/dist/compile/names.d.ts.map +1 -1
- package/dist/compile/names.js +19 -3
- package/dist/compile/predicate.d.ts +24 -0
- package/dist/compile/predicate.d.ts.map +1 -1
- package/dist/compile/predicate.js +131 -5
- package/dist/compile/runtime.d.ts +80 -12
- package/dist/compile/runtime.d.ts.map +1 -1
- package/dist/compile/runtime.js +25 -6
- package/dist/compile/source.d.ts +10 -2
- package/dist/compile/source.d.ts.map +1 -1
- package/dist/compile/source.js +361 -26
- package/dist/compile/types.d.ts +20 -0
- package/dist/compile/types.d.ts.map +1 -1
- package/dist/compile/types.js +2 -0
- package/dist/decoder/index.d.ts +32 -46
- package/dist/decoder/index.d.ts.map +1 -1
- package/dist/decoder/index.js +102 -38
- package/dist/evaluate/check-composite.d.ts +59 -0
- package/dist/evaluate/check-composite.d.ts.map +1 -1
- package/dist/evaluate/check-composite.js +151 -3
- package/dist/evaluate/check-scalar.d.ts +16 -0
- package/dist/evaluate/check-scalar.d.ts.map +1 -1
- package/dist/evaluate/check-scalar.js +32 -0
- package/dist/evaluate/check.d.ts +7 -0
- package/dist/evaluate/check.d.ts.map +1 -1
- package/dist/evaluate/check.js +43 -0
- package/dist/evaluate/index.d.ts +2 -0
- package/dist/evaluate/index.d.ts.map +1 -1
- package/dist/evaluate/index.js +2 -0
- package/dist/evaluate/issue.d.ts +11 -1
- package/dist/evaluate/issue.d.ts.map +1 -1
- package/dist/evaluate/issue.js +15 -1
- package/dist/evaluate/predicate.d.ts +16 -5
- package/dist/evaluate/predicate.d.ts.map +1 -1
- package/dist/evaluate/predicate.js +20 -5
- package/dist/evaluate/shared.d.ts +59 -13
- package/dist/evaluate/shared.d.ts.map +1 -1
- package/dist/evaluate/shared.js +66 -8
- package/dist/evaluate/state.d.ts +35 -13
- package/dist/evaluate/state.d.ts.map +1 -1
- package/dist/evaluate/state.js +35 -2
- package/dist/guard/base.d.ts +79 -29
- package/dist/guard/base.d.ts.map +1 -1
- package/dist/guard/base.js +91 -29
- package/dist/guard/error.d.ts +10 -5
- package/dist/guard/error.d.ts.map +1 -1
- package/dist/guard/error.js +10 -5
- package/dist/guard/index.d.ts +2 -0
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +2 -0
- package/dist/guard/number.d.ts +26 -11
- package/dist/guard/number.d.ts.map +1 -1
- package/dist/guard/number.js +30 -11
- package/dist/guard/props.d.ts +27 -3
- package/dist/guard/props.d.ts.map +1 -1
- package/dist/guard/props.js +27 -3
- package/dist/guard/read.d.ts +62 -9
- package/dist/guard/read.d.ts.map +1 -1
- package/dist/guard/read.js +83 -10
- package/dist/guard/registry.d.ts +12 -2
- package/dist/guard/registry.d.ts.map +1 -1
- package/dist/guard/registry.js +15 -3
- package/dist/guard/string.d.ts +33 -13
- package/dist/guard/string.d.ts.map +1 -1
- package/dist/guard/string.js +37 -13
- package/dist/guard/types.d.ts +92 -40
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/guard/types.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/internal/index.d.ts +42 -6
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +51 -8
- package/dist/ir/builder.d.ts +16 -126
- package/dist/ir/builder.d.ts.map +1 -1
- package/dist/ir/builder.js +77 -137
- package/dist/ir/freeze.d.ts +4 -0
- package/dist/ir/freeze.d.ts.map +1 -1
- package/dist/ir/freeze.js +59 -0
- package/dist/ir/index.d.ts +3 -1
- package/dist/ir/index.d.ts.map +1 -1
- package/dist/ir/index.js +2 -0
- package/dist/ir/regexp.d.ts +2 -0
- package/dist/ir/regexp.d.ts.map +1 -1
- package/dist/ir/regexp.js +2 -0
- package/dist/ir/types.d.ts +90 -55
- package/dist/ir/types.d.ts.map +1 -1
- package/dist/ir/types.js +2 -0
- package/dist/ir/validate.d.ts +8 -1
- package/dist/ir/validate.d.ts.map +1 -1
- package/dist/ir/validate.js +477 -61
- package/dist/issue/index.d.ts +41 -9
- package/dist/issue/index.d.ts.map +1 -1
- package/dist/issue/index.js +61 -11
- package/dist/json-schema/emit-combinator.d.ts +44 -4
- package/dist/json-schema/emit-combinator.d.ts.map +1 -1
- package/dist/json-schema/emit-combinator.js +44 -4
- package/dist/json-schema/emit-composite.d.ts +10 -0
- package/dist/json-schema/emit-composite.d.ts.map +1 -1
- package/dist/json-schema/emit-composite.js +15 -1
- package/dist/json-schema/emit-scalar.d.ts +26 -3
- package/dist/json-schema/emit-scalar.d.ts.map +1 -1
- package/dist/json-schema/emit-scalar.js +70 -9
- package/dist/json-schema/emit-types.d.ts +11 -1
- package/dist/json-schema/emit-types.d.ts.map +1 -1
- package/dist/json-schema/emit-types.js +2 -0
- package/dist/json-schema/emit.d.ts +12 -1
- package/dist/json-schema/emit.d.ts.map +1 -1
- package/dist/json-schema/emit.js +12 -1
- package/dist/json-schema/freeze.d.ts +13 -2
- package/dist/json-schema/freeze.d.ts.map +1 -1
- package/dist/json-schema/freeze.js +41 -8
- package/dist/json-schema/index.d.ts +16 -2
- package/dist/json-schema/index.d.ts.map +1 -1
- package/dist/json-schema/index.js +23 -3
- package/dist/json-schema/issue.d.ts +4 -1
- package/dist/json-schema/issue.d.ts.map +1 -1
- package/dist/json-schema/issue.js +4 -1
- package/dist/json-schema/read.d.ts +24 -3
- package/dist/json-schema/read.d.ts.map +1 -1
- package/dist/json-schema/read.js +59 -12
- package/dist/json-schema/types.d.ts +38 -15
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/json-schema/types.js +2 -0
- package/dist/kind/index.d.ts +15 -28
- package/dist/kind/index.d.ts.map +1 -1
- package/dist/kind/index.js +15 -10
- package/dist/lower/index.d.ts +6 -1
- package/dist/lower/index.d.ts.map +1 -1
- package/dist/lower/index.js +411 -44
- package/dist/message/index.d.ts +46 -10
- package/dist/message/index.d.ts.map +1 -1
- package/dist/message/index.js +88 -17
- package/dist/optimize/algebraic.d.ts +54 -0
- package/dist/optimize/algebraic.d.ts.map +1 -0
- package/dist/optimize/algebraic.js +314 -0
- package/dist/optimize/compact.d.ts +8 -1
- package/dist/optimize/compact.d.ts.map +1 -1
- package/dist/optimize/compact.js +13 -2
- package/dist/optimize/domain.d.ts +16 -0
- package/dist/optimize/domain.d.ts.map +1 -0
- package/dist/optimize/domain.js +615 -0
- package/dist/optimize/fold-boolean.d.ts +17 -2
- package/dist/optimize/fold-boolean.d.ts.map +1 -1
- package/dist/optimize/fold-boolean.js +59 -14
- package/dist/optimize/fold-common.d.ts +43 -8
- package/dist/optimize/fold-common.d.ts.map +1 -1
- package/dist/optimize/fold-common.js +37 -6
- package/dist/optimize/fold-constraints.d.ts +33 -0
- package/dist/optimize/fold-constraints.d.ts.map +1 -0
- package/dist/optimize/fold-constraints.js +484 -0
- package/dist/optimize/fold-scalar.d.ts +98 -13
- package/dist/optimize/fold-scalar.d.ts.map +1 -1
- package/dist/optimize/fold-scalar.js +98 -13
- package/dist/optimize/fold.d.ts +8 -1
- package/dist/optimize/fold.d.ts.map +1 -1
- package/dist/optimize/fold.js +22 -2
- package/dist/optimize/index.d.ts +9 -1
- package/dist/optimize/index.d.ts.map +1 -1
- package/dist/optimize/index.js +18 -3
- package/dist/optimize/map-node.d.ts +3 -1
- package/dist/optimize/map-node.d.ts.map +1 -1
- package/dist/optimize/map-node.js +45 -3
- package/dist/optimize/peephole.d.ts +16 -0
- package/dist/optimize/peephole.d.ts.map +1 -0
- package/dist/optimize/peephole.js +254 -0
- package/dist/optimize/remap.d.ts +2 -0
- package/dist/optimize/remap.d.ts.map +1 -1
- package/dist/optimize/remap.js +2 -0
- package/dist/optimize/rewrite.d.ts +13 -8
- package/dist/optimize/rewrite.d.ts.map +1 -1
- package/dist/optimize/rewrite.js +13 -8
- package/dist/plan/cache.d.ts +9 -3
- package/dist/plan/cache.d.ts.map +1 -1
- package/dist/plan/cache.js +21 -5
- package/dist/plan/index.d.ts +2 -0
- package/dist/plan/index.d.ts.map +1 -1
- package/dist/plan/index.js +2 -0
- package/dist/plan/predicate.d.ts +2 -0
- package/dist/plan/predicate.d.ts.map +1 -1
- package/dist/plan/predicate.js +268 -29
- package/dist/plan/schema-predicate.d.ts +6 -0
- package/dist/plan/schema-predicate.d.ts.map +1 -1
- package/dist/plan/schema-predicate.js +117 -13
- package/dist/plan/types.d.ts +2 -0
- package/dist/plan/types.d.ts.map +1 -1
- package/dist/plan/types.js +2 -0
- package/dist/result/index.d.ts +19 -5
- package/dist/result/index.d.ts.map +1 -1
- package/dist/result/index.js +10 -2
- package/dist/schema/common.d.ts +69 -6
- package/dist/schema/common.d.ts.map +1 -1
- package/dist/schema/common.js +104 -10
- package/dist/schema/freeze.d.ts +4 -0
- package/dist/schema/freeze.d.ts.map +1 -1
- package/dist/schema/freeze.js +18 -0
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +3 -0
- package/dist/schema/lazy.d.ts +4 -0
- package/dist/schema/lazy.d.ts.map +1 -1
- package/dist/schema/lazy.js +4 -0
- package/dist/schema/literal.d.ts +7 -1
- package/dist/schema/literal.d.ts.map +1 -1
- package/dist/schema/literal.js +7 -1
- package/dist/schema/types.d.ts +20 -96
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js +5 -1
- package/dist/schema/undefined.d.ts +17 -0
- package/dist/schema/undefined.d.ts.map +1 -0
- package/dist/schema/undefined.js +72 -0
- package/dist/schema/validate.d.ts +8 -1
- package/dist/schema/validate.d.ts.map +1 -1
- package/dist/schema/validate.js +146 -55
- package/docs/api.md +57 -0
- package/docs/assets/benchmark-headline.svg +163 -0
- package/docs/engine-notes.md +58 -15
- package/docs/index.html +130 -110
- package/package.json +65 -65
|
@@ -1,28 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file predicate.ts
|
|
3
3
|
* @brief Compatibility entry points for IR-backed predicate execution.
|
|
4
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
5
|
+
* aligned with compiled behavior.
|
|
4
6
|
*/
|
|
5
7
|
import { executeSchemaPredicate, executeSchemaPredicateWithState } from "../plan/index.js";
|
|
6
8
|
/**
|
|
7
|
-
* @brief
|
|
8
|
-
* @details
|
|
9
|
+
* @brief Execute a schema predicate through its optimized validation plan.
|
|
10
|
+
* @details This is the compatibility entry point used by guards that need a
|
|
11
|
+
* boolean answer without diagnostics.
|
|
12
|
+
* @param schema Schema used to validate the input.
|
|
13
|
+
* @param value Candidate runtime value.
|
|
9
14
|
* @returns True when the input satisfies the schema.
|
|
10
15
|
*/
|
|
11
16
|
export function isSchema(schema, value) {
|
|
12
17
|
return executeSchemaPredicate(schema, value);
|
|
13
18
|
}
|
|
14
19
|
/**
|
|
15
|
-
* @brief
|
|
20
|
+
* @brief Execute a schema predicate with caller-owned recursion state.
|
|
16
21
|
* @details Shares recursion and cycle tracking with nested IR nodes.
|
|
17
|
-
* @
|
|
22
|
+
* @param schema Schema used to validate the input.
|
|
23
|
+
* @param value Candidate runtime value.
|
|
24
|
+
* @param state Validation state from an outer diagnostic or predicate run.
|
|
25
|
+
* @returns True when the input satisfies the schema under the shared state.
|
|
18
26
|
*/
|
|
19
27
|
export function isSchemaWithState(schema, value, state) {
|
|
20
28
|
return executeSchemaPredicateWithState(schema, value, state);
|
|
21
29
|
}
|
|
22
30
|
/**
|
|
23
|
-
* @brief
|
|
31
|
+
* @brief Execute union probing with shared recursion state.
|
|
24
32
|
* @details Preserves the historical helper used by diagnostic generation while
|
|
25
33
|
* routing each union option through IR-backed validation.
|
|
34
|
+
* @param options Union option schemas.
|
|
35
|
+
* @param value Candidate runtime value.
|
|
36
|
+
* @param state Validation state shared across option probes.
|
|
26
37
|
* @returns True when at least one option accepts the value.
|
|
27
38
|
*/
|
|
28
39
|
export function isUnionSchema(options, value, state) {
|
|
@@ -30,6 +41,10 @@ export function isUnionSchema(options, value, state) {
|
|
|
30
41
|
const option = options[index];
|
|
31
42
|
if (option !== undefined &&
|
|
32
43
|
executeSchemaPredicateWithState(option, value, state)) {
|
|
44
|
+
/*
|
|
45
|
+
* Union diagnostics only need to know whether at least one branch
|
|
46
|
+
* accepts. Detailed branch diagnostics would allocate on a hot helper.
|
|
47
|
+
*/
|
|
33
48
|
return true;
|
|
34
49
|
}
|
|
35
50
|
}
|
|
@@ -1,59 +1,105 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file shared.ts
|
|
3
3
|
* @brief Shared scalar helpers for schema evaluation.
|
|
4
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
5
|
+
* aligned with compiled behavior.
|
|
4
6
|
*/
|
|
5
7
|
import type { DiscriminatedUnionCase, LiteralValue, ObjectKeyLookup, Schema } from "../schema/index.js";
|
|
6
8
|
/**
|
|
7
|
-
* @brief
|
|
9
|
+
* @brief Object shape accepted by object and record validators.
|
|
10
|
+
* @details Values stay indexed by string keys only after the caller proves the
|
|
11
|
+
* input is not null and not an array.
|
|
8
12
|
*/
|
|
9
13
|
export type UnknownRecord = Readonly<Record<string, unknown>>;
|
|
10
14
|
/**
|
|
11
|
-
* @brief
|
|
12
|
-
* @details
|
|
15
|
+
* @brief Descriptor subset safe for validation reads.
|
|
16
|
+
* @details Only data descriptors are accepted because accessor descriptors can
|
|
17
|
+
* execute user code and can return different values across reads.
|
|
13
18
|
* @invariant Accessor descriptors never match this contract.
|
|
14
19
|
*/
|
|
15
20
|
export interface DataPropertyDescriptor {
|
|
16
21
|
/**
|
|
17
|
-
* @brief value.
|
|
18
|
-
* @details The
|
|
22
|
+
* @brief Captured property value.
|
|
23
|
+
* @details The value remains unknown until a schema-specific validator consumes it.
|
|
19
24
|
* @invariant Accessing this field does not execute user getter code.
|
|
20
25
|
*/
|
|
21
26
|
readonly value: unknown;
|
|
22
27
|
}
|
|
23
28
|
/**
|
|
24
|
-
* @brief
|
|
29
|
+
* @brief Check membership in an object schema key lookup.
|
|
30
|
+
* @param keyLookup Null-prototype lookup generated by object schema construction.
|
|
31
|
+
* @param key Candidate own key.
|
|
32
|
+
* @returns True when the key belongs to the schema shape.
|
|
33
|
+
* @details The lookup is used instead of `in` so prototype pollution cannot make
|
|
34
|
+
* an undeclared key appear valid.
|
|
25
35
|
*/
|
|
26
36
|
export declare function hasObjectKey(keyLookup: ObjectKeyLookup, key: string): boolean;
|
|
27
37
|
/**
|
|
28
|
-
* @brief
|
|
38
|
+
* @brief Read one own data property from a runtime object.
|
|
29
39
|
* @details Reads one own property through its descriptor so getters are not executed.
|
|
40
|
+
* @param record Plain object being validated.
|
|
41
|
+
* @param key Own key to inspect.
|
|
30
42
|
* @returns Own data descriptor, or undefined for missing/accessor properties.
|
|
31
43
|
*/
|
|
32
44
|
export declare function readOwnDataProperty(record: UnknownRecord, key: string): DataPropertyDescriptor | undefined;
|
|
33
45
|
/**
|
|
34
|
-
* @brief
|
|
46
|
+
* @brief Select a discriminated-union branch by its literal tag value.
|
|
47
|
+
* @details The case list is already builder-validated for unique literals, so a
|
|
48
|
+
* linear scan is enough for interpreter diagnostics while preserving declaration
|
|
49
|
+
* order and avoiding a per-schema map allocation.
|
|
50
|
+
* @param cases Closed discriminated union case list.
|
|
51
|
+
* @param value Discriminant string read from input.
|
|
52
|
+
* @returns Matching case schema, or undefined when the value is unknown.
|
|
35
53
|
*/
|
|
36
54
|
export declare function findDiscriminatedUnionCase(cases: readonly DiscriminatedUnionCase[], value: string): Schema | undefined;
|
|
37
55
|
/**
|
|
38
|
-
* @brief
|
|
56
|
+
* @brief Test for the only accepted refinement success value.
|
|
57
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
58
|
+
* aligned with compiled behavior.
|
|
59
|
+
* @param value Predicate return value.
|
|
60
|
+
* @returns True only for the boolean literal true.
|
|
39
61
|
*/
|
|
40
62
|
export declare function isStrictTrue(value: unknown): boolean;
|
|
41
63
|
/**
|
|
42
|
-
* @brief
|
|
64
|
+
* @brief Test whether a value can host object-schema properties.
|
|
65
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
66
|
+
* aligned with compiled behavior.
|
|
67
|
+
* @param value Candidate runtime value.
|
|
68
|
+
* @returns True for non-array object values.
|
|
43
69
|
*/
|
|
44
70
|
export declare function isPlainRecord(value: unknown): value is UnknownRecord;
|
|
45
71
|
/**
|
|
46
|
-
* @brief
|
|
72
|
+
* @brief Test whether a descriptor carries a stable data slot.
|
|
47
73
|
* @details Checks that a descriptor contains a data value instead of getter/setter code.
|
|
74
|
+
* @param descriptor Descriptor returned by Object.getOwnPropertyDescriptor.
|
|
48
75
|
* @returns True when the descriptor has a stable value slot.
|
|
49
76
|
*/
|
|
50
77
|
export declare function isDataPropertyDescriptor(descriptor: PropertyDescriptor): descriptor is DataPropertyDescriptor;
|
|
51
78
|
/**
|
|
52
|
-
* @brief
|
|
79
|
+
* @brief Test whether a property name is an in-bounds array index.
|
|
80
|
+
* @details Array validation ignores non-index own properties exactly as indexed
|
|
81
|
+
* loops do, but this helper lets sparse arrays avoid scanning every hole.
|
|
82
|
+
* @param key Own property name returned from an array object.
|
|
83
|
+
* @param length Current array length used as the upper bound.
|
|
84
|
+
* @returns True for canonical own array-index names below the current length.
|
|
85
|
+
* @invariant The result matches the indexes visited by a `0..length` loop.
|
|
86
|
+
*/
|
|
87
|
+
export declare function isArrayIndexKey(key: string, length: number): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* @brief Convert a runtime value into TypeSea's diagnostic type label.
|
|
90
|
+
* @details JavaScript reports null as object and NaN as number. Diagnostics use
|
|
91
|
+
* more precise labels so failure reports describe the actual value shape seen by
|
|
92
|
+
* validators.
|
|
93
|
+
* @param value Candidate runtime value.
|
|
94
|
+
* @returns Stable diagnostic type label.
|
|
53
95
|
*/
|
|
54
96
|
export declare function actualType(value: unknown): string;
|
|
55
97
|
/**
|
|
56
|
-
* @brief literal
|
|
98
|
+
* @brief Render a literal schema value for the `expected` diagnostic field.
|
|
99
|
+
* @details String values are JSON-quoted and negative zero is preserved because
|
|
100
|
+
* both cases are otherwise easy to misread in generated messages.
|
|
101
|
+
* @param value Literal value from a schema.
|
|
102
|
+
* @returns Stable expected-value label for diagnostics.
|
|
57
103
|
*/
|
|
58
104
|
export declare function literalToExpected(value: LiteralValue): string;
|
|
59
105
|
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/evaluate/shared.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/evaluate/shared.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACR,sBAAsB,EACtB,YAAY,EACZ,eAAe,EACf,MAAM,EACT,MAAM,oBAAoB,CAAC;AAI5B;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IAEnC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAE7E;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAC/B,MAAM,EAAE,aAAa,EACrB,GAAG,EAAE,MAAM,GACZ,sBAAsB,GAAG,SAAS,CAMpC;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACtC,KAAK,EAAE,SAAS,sBAAsB,EAAE,EACxC,KAAK,EAAE,MAAM,GACd,MAAM,GAAG,SAAS,CAQpB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACpC,UAAU,EAAE,kBAAkB,GAC/B,UAAU,IAAI,sBAAsB,CAEtC;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAcpE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAiBjD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAiB7D"}
|
package/dist/evaluate/shared.js
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file shared.ts
|
|
3
3
|
* @brief Shared scalar helpers for schema evaluation.
|
|
4
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
5
|
+
* aligned with compiled behavior.
|
|
4
6
|
*/
|
|
7
|
+
const MAX_ARRAY_INDEX = 4_294_967_294;
|
|
5
8
|
/**
|
|
6
|
-
* @brief
|
|
9
|
+
* @brief Check membership in an object schema key lookup.
|
|
10
|
+
* @param keyLookup Null-prototype lookup generated by object schema construction.
|
|
11
|
+
* @param key Candidate own key.
|
|
12
|
+
* @returns True when the key belongs to the schema shape.
|
|
13
|
+
* @details The lookup is used instead of `in` so prototype pollution cannot make
|
|
14
|
+
* an undeclared key appear valid.
|
|
7
15
|
*/
|
|
8
16
|
export function hasObjectKey(keyLookup, key) {
|
|
9
17
|
return Object.prototype.hasOwnProperty.call(keyLookup, key);
|
|
10
18
|
}
|
|
11
19
|
/**
|
|
12
|
-
* @brief
|
|
20
|
+
* @brief Read one own data property from a runtime object.
|
|
13
21
|
* @details Reads one own property through its descriptor so getters are not executed.
|
|
22
|
+
* @param record Plain object being validated.
|
|
23
|
+
* @param key Own key to inspect.
|
|
14
24
|
* @returns Own data descriptor, or undefined for missing/accessor properties.
|
|
15
25
|
*/
|
|
16
26
|
export function readOwnDataProperty(record, key) {
|
|
@@ -21,7 +31,13 @@ export function readOwnDataProperty(record, key) {
|
|
|
21
31
|
return descriptor;
|
|
22
32
|
}
|
|
23
33
|
/**
|
|
24
|
-
* @brief
|
|
34
|
+
* @brief Select a discriminated-union branch by its literal tag value.
|
|
35
|
+
* @details The case list is already builder-validated for unique literals, so a
|
|
36
|
+
* linear scan is enough for interpreter diagnostics while preserving declaration
|
|
37
|
+
* order and avoiding a per-schema map allocation.
|
|
38
|
+
* @param cases Closed discriminated union case list.
|
|
39
|
+
* @param value Discriminant string read from input.
|
|
40
|
+
* @returns Matching case schema, or undefined when the value is unknown.
|
|
25
41
|
*/
|
|
26
42
|
export function findDiscriminatedUnionCase(cases, value) {
|
|
27
43
|
for (let index = 0; index < cases.length; index += 1) {
|
|
@@ -33,27 +49,65 @@ export function findDiscriminatedUnionCase(cases, value) {
|
|
|
33
49
|
return undefined;
|
|
34
50
|
}
|
|
35
51
|
/**
|
|
36
|
-
* @brief
|
|
52
|
+
* @brief Test for the only accepted refinement success value.
|
|
53
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
54
|
+
* aligned with compiled behavior.
|
|
55
|
+
* @param value Predicate return value.
|
|
56
|
+
* @returns True only for the boolean literal true.
|
|
37
57
|
*/
|
|
38
58
|
export function isStrictTrue(value) {
|
|
39
59
|
return value === true;
|
|
40
60
|
}
|
|
41
61
|
/**
|
|
42
|
-
* @brief
|
|
62
|
+
* @brief Test whether a value can host object-schema properties.
|
|
63
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
64
|
+
* aligned with compiled behavior.
|
|
65
|
+
* @param value Candidate runtime value.
|
|
66
|
+
* @returns True for non-array object values.
|
|
43
67
|
*/
|
|
44
68
|
export function isPlainRecord(value) {
|
|
45
69
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
46
70
|
}
|
|
47
71
|
/**
|
|
48
|
-
* @brief
|
|
72
|
+
* @brief Test whether a descriptor carries a stable data slot.
|
|
49
73
|
* @details Checks that a descriptor contains a data value instead of getter/setter code.
|
|
74
|
+
* @param descriptor Descriptor returned by Object.getOwnPropertyDescriptor.
|
|
50
75
|
* @returns True when the descriptor has a stable value slot.
|
|
51
76
|
*/
|
|
52
77
|
export function isDataPropertyDescriptor(descriptor) {
|
|
53
78
|
return Object.prototype.hasOwnProperty.call(descriptor, "value");
|
|
54
79
|
}
|
|
55
80
|
/**
|
|
56
|
-
* @brief
|
|
81
|
+
* @brief Test whether a property name is an in-bounds array index.
|
|
82
|
+
* @details Array validation ignores non-index own properties exactly as indexed
|
|
83
|
+
* loops do, but this helper lets sparse arrays avoid scanning every hole.
|
|
84
|
+
* @param key Own property name returned from an array object.
|
|
85
|
+
* @param length Current array length used as the upper bound.
|
|
86
|
+
* @returns True for canonical own array-index names below the current length.
|
|
87
|
+
* @invariant The result matches the indexes visited by a `0..length` loop.
|
|
88
|
+
*/
|
|
89
|
+
export function isArrayIndexKey(key, length) {
|
|
90
|
+
if (key.length === 0 || key === "length") {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
/*
|
|
94
|
+
* Enumeration APIs expose array indexes as strings. Round-tripping through
|
|
95
|
+
* Number rejects aliases such as "01", floats, negative keys, and length.
|
|
96
|
+
*/
|
|
97
|
+
const index = Number(key);
|
|
98
|
+
return Number.isInteger(index) &&
|
|
99
|
+
index >= 0 &&
|
|
100
|
+
index <= MAX_ARRAY_INDEX &&
|
|
101
|
+
index < length &&
|
|
102
|
+
String(index) === key;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* @brief Convert a runtime value into TypeSea's diagnostic type label.
|
|
106
|
+
* @details JavaScript reports null as object and NaN as number. Diagnostics use
|
|
107
|
+
* more precise labels so failure reports describe the actual value shape seen by
|
|
108
|
+
* validators.
|
|
109
|
+
* @param value Candidate runtime value.
|
|
110
|
+
* @returns Stable diagnostic type label.
|
|
57
111
|
*/
|
|
58
112
|
export function actualType(value) {
|
|
59
113
|
if (value === null) {
|
|
@@ -74,7 +128,11 @@ export function actualType(value) {
|
|
|
74
128
|
return typeof value;
|
|
75
129
|
}
|
|
76
130
|
/**
|
|
77
|
-
* @brief literal
|
|
131
|
+
* @brief Render a literal schema value for the `expected` diagnostic field.
|
|
132
|
+
* @details String values are JSON-quoted and negative zero is preserved because
|
|
133
|
+
* both cases are otherwise easy to misread in generated messages.
|
|
134
|
+
* @param value Literal value from a schema.
|
|
135
|
+
* @returns Stable expected-value label for diagnostics.
|
|
78
136
|
*/
|
|
79
137
|
export function literalToExpected(value) {
|
|
80
138
|
if (value === null) {
|
package/dist/evaluate/state.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file state.ts
|
|
3
3
|
* @brief Recursive validation state for cyclic input graphs.
|
|
4
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
5
|
+
* aligned with compiled behavior.
|
|
4
6
|
*/
|
|
5
7
|
import type { Schema } from "../schema/index.js";
|
|
6
8
|
/**
|
|
@@ -11,6 +13,8 @@ import type { Schema } from "../schema/index.js";
|
|
|
11
13
|
export type ValidationEnterResult = "entered" | "cycle" | "budget";
|
|
12
14
|
/**
|
|
13
15
|
* @brief default max validation depth.
|
|
16
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
17
|
+
* aligned with compiled behavior.
|
|
14
18
|
* @invariant The value stays below the V8 stack depth that recursive lazy schemas can exhaust.
|
|
15
19
|
*/
|
|
16
20
|
export declare const DEFAULT_MAX_VALIDATION_DEPTH = 256;
|
|
@@ -26,40 +30,58 @@ export interface GraphEvaluationFrame {
|
|
|
26
30
|
}
|
|
27
31
|
/**
|
|
28
32
|
* @brief validation state.
|
|
33
|
+
* @details Bundles recursion guards, lazy-resolution guards, and reusable graph
|
|
34
|
+
* frames so interpreter and IR execution observe the same limits.
|
|
29
35
|
*/
|
|
30
36
|
export interface ValidationState {
|
|
31
37
|
readonly active: WeakMap<object, WeakSet<Schema>>;
|
|
32
38
|
readonly graphFrames: GraphEvaluationFrame[];
|
|
33
39
|
readonly resolving: WeakSet<object>;
|
|
34
40
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
* @brief depth.
|
|
42
|
+
* @details Counts active recursive validator frames owned by this state object.
|
|
43
|
+
* @invariant The value is incremented only after budget admission and decremented by `leaveValidation`.
|
|
44
|
+
*/
|
|
39
45
|
depth: number;
|
|
40
46
|
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
* @brief graph depth.
|
|
48
|
+
* @details Counts active nested graph executions using `graphFrames` as a stack.
|
|
49
|
+
* @invariant Incremented by IR execution before frame use and decremented after it.
|
|
50
|
+
*/
|
|
45
51
|
graphDepth: number;
|
|
46
52
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
* @brief max depth.
|
|
54
|
+
* @details Hard cap for recursive validator frames.
|
|
55
|
+
* @invariant Entering past this limit returns `budget` instead of recursing.
|
|
56
|
+
*/
|
|
51
57
|
readonly maxDepth: number;
|
|
52
58
|
}
|
|
53
59
|
/**
|
|
54
|
-
* @brief
|
|
60
|
+
* @brief Allocate recursion and graph-frame state for one validation run.
|
|
61
|
+
* @returns Fresh validation state for one top-level validation operation.
|
|
62
|
+
* @details State is allocated per call so cycle tracking cannot leak between
|
|
63
|
+
* unrelated inputs.
|
|
55
64
|
*/
|
|
56
65
|
export declare function makeValidationState(): ValidationState;
|
|
57
66
|
/**
|
|
58
67
|
* @brief enter validation.
|
|
68
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
69
|
+
* aligned with compiled behavior.
|
|
70
|
+
* @param schema Schema being entered.
|
|
71
|
+
* @param value Candidate runtime value.
|
|
72
|
+
* @param state Shared validation state.
|
|
73
|
+
* @returns Enter result describing cycle, budget, or admitted recursion.
|
|
74
|
+
* @post `state.depth` is incremented only for the entered result.
|
|
59
75
|
*/
|
|
60
76
|
export declare function enterValidation(schema: Schema, value: unknown, state: ValidationState): ValidationEnterResult;
|
|
61
77
|
/**
|
|
62
78
|
* @brief leave validation.
|
|
79
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
80
|
+
* aligned with compiled behavior.
|
|
81
|
+
* @param schema Schema leaving validation.
|
|
82
|
+
* @param value Candidate runtime value.
|
|
83
|
+
* @param state Shared validation state.
|
|
84
|
+
* @post Reverses the depth and active-pair effects of `enterValidation`.
|
|
63
85
|
*/
|
|
64
86
|
export declare function leaveValidation(schema: Schema, value: unknown, state: ValidationState): void;
|
|
65
87
|
//# sourceMappingURL=state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/evaluate/state.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/evaluate/state.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAC3B,SAAS,GACT,OAAO,GACP,QAAQ,CAAC;AAEf;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAEhD;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACjC,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC5B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,QAAQ,CAAC,WAAW,EAAE,oBAAoB,EAAE,CAAC;IAC7C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAEpC;;;;KAIC;IACD,KAAK,EAAE,MAAM,CAAC;IAEd;;;;KAIC;IACD,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;KAIC;IACD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,IAAI,eAAe,CASrD;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC3B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,eAAe,GACvB,qBAAqB,CA6BvB;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC3B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,eAAe,GACvB,IAAI,CAUN"}
|
package/dist/evaluate/state.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file state.ts
|
|
3
3
|
* @brief Recursive validation state for cyclic input graphs.
|
|
4
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
5
|
+
* aligned with compiled behavior.
|
|
4
6
|
*/
|
|
5
7
|
/**
|
|
6
8
|
* @brief default max validation depth.
|
|
9
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
10
|
+
* aligned with compiled behavior.
|
|
7
11
|
* @invariant The value stays below the V8 stack depth that recursive lazy schemas can exhaust.
|
|
8
12
|
*/
|
|
9
13
|
export const DEFAULT_MAX_VALIDATION_DEPTH = 256;
|
|
10
14
|
/**
|
|
11
|
-
* @brief
|
|
15
|
+
* @brief Allocate recursion and graph-frame state for one validation run.
|
|
16
|
+
* @returns Fresh validation state for one top-level validation operation.
|
|
17
|
+
* @details State is allocated per call so cycle tracking cannot leak between
|
|
18
|
+
* unrelated inputs.
|
|
12
19
|
*/
|
|
13
20
|
export function makeValidationState() {
|
|
14
21
|
return {
|
|
@@ -22,10 +29,22 @@ export function makeValidationState() {
|
|
|
22
29
|
}
|
|
23
30
|
/**
|
|
24
31
|
* @brief enter validation.
|
|
32
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
33
|
+
* aligned with compiled behavior.
|
|
34
|
+
* @param schema Schema being entered.
|
|
35
|
+
* @param value Candidate runtime value.
|
|
36
|
+
* @param state Shared validation state.
|
|
37
|
+
* @returns Enter result describing cycle, budget, or admitted recursion.
|
|
38
|
+
* @post `state.depth` is incremented only for the entered result.
|
|
25
39
|
*/
|
|
26
40
|
export function enterValidation(schema, value, state) {
|
|
27
41
|
const cached = isReferenceValue(value) ? state.active.get(value) : undefined;
|
|
28
42
|
if (cached?.has(schema) === true) {
|
|
43
|
+
/*
|
|
44
|
+
* The same schema/value pair is already active. Returning cycle prevents
|
|
45
|
+
* infinite recursion on cyclic object graphs while preserving success for
|
|
46
|
+
* the already-open branch.
|
|
47
|
+
*/
|
|
29
48
|
return "cycle";
|
|
30
49
|
}
|
|
31
50
|
if (state.depth >= state.maxDepth) {
|
|
@@ -36,6 +55,10 @@ export function enterValidation(schema, value, state) {
|
|
|
36
55
|
return "entered";
|
|
37
56
|
}
|
|
38
57
|
if (cached !== undefined) {
|
|
58
|
+
/*
|
|
59
|
+
* WeakSet membership is per object identity. Adding the schema marks this
|
|
60
|
+
* exact pair as active until leaveValidation removes it.
|
|
61
|
+
*/
|
|
39
62
|
cached.add(schema);
|
|
40
63
|
return "entered";
|
|
41
64
|
}
|
|
@@ -46,6 +69,12 @@ export function enterValidation(schema, value, state) {
|
|
|
46
69
|
}
|
|
47
70
|
/**
|
|
48
71
|
* @brief leave validation.
|
|
72
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
73
|
+
* aligned with compiled behavior.
|
|
74
|
+
* @param schema Schema leaving validation.
|
|
75
|
+
* @param value Candidate runtime value.
|
|
76
|
+
* @param state Shared validation state.
|
|
77
|
+
* @post Reverses the depth and active-pair effects of `enterValidation`.
|
|
49
78
|
*/
|
|
50
79
|
export function leaveValidation(schema, value, state) {
|
|
51
80
|
if (!isReferenceValue(value)) {
|
|
@@ -59,7 +88,11 @@ export function leaveValidation(schema, value, state) {
|
|
|
59
88
|
state.depth -= 1;
|
|
60
89
|
}
|
|
61
90
|
/**
|
|
62
|
-
* @brief
|
|
91
|
+
* @brief Test whether a value can participate in object graph cycles.
|
|
92
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
93
|
+
* aligned with compiled behavior.
|
|
94
|
+
* @param value Candidate runtime value.
|
|
95
|
+
* @returns True for objects and functions that can participate in cycles.
|
|
63
96
|
*/
|
|
64
97
|
function isReferenceValue(value) {
|
|
65
98
|
return (typeof value === "object" && value !== null) || typeof value === "function";
|
package/dist/guard/base.d.ts
CHANGED
|
@@ -1,72 +1,122 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file base.ts
|
|
3
3
|
* @brief Base guard implementation.
|
|
4
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
5
|
+
* existing guard instance.
|
|
4
6
|
*/
|
|
5
7
|
import type { CheckResult } from "../issue/index.js";
|
|
6
8
|
import type { Graph } from "../ir/index.js";
|
|
7
9
|
import type { Schema } from "../schema/index.js";
|
|
8
10
|
import type { Brand, Guard, Infer, Presence, PresenceSymbol, RuntimeValue, TypeSymbol } from "./types.js";
|
|
9
11
|
/**
|
|
10
|
-
* @brief
|
|
11
|
-
* @details
|
|
12
|
-
*
|
|
12
|
+
* @brief Schema-backed guard base.
|
|
13
|
+
* @details Methods accept an unknown receiver on purpose. Public JavaScript can
|
|
14
|
+
* detach or forge methods, so every entry point re-reads the runtime schema
|
|
15
|
+
* before executing validation.
|
|
16
|
+
* @invariant The stored schema is immutable after construction.
|
|
13
17
|
*/
|
|
14
18
|
export declare class BaseGuard<TValue, TPresence extends Presence = "required"> implements Guard<TValue, TPresence> {
|
|
15
19
|
readonly [TypeSymbol]: TValue;
|
|
16
20
|
readonly [PresenceSymbol]: TPresence;
|
|
17
21
|
readonly schema: Schema;
|
|
18
22
|
/**
|
|
19
|
-
* @brief
|
|
20
|
-
|
|
23
|
+
* @brief Construct a schema-backed guard.
|
|
24
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
25
|
+
* existing guard instance.
|
|
26
|
+
* @param schema Runtime schema owned by the guard.
|
|
27
|
+
* @post The schema slot is frozen and the receiver is registered for fast checks.
|
|
21
28
|
*/
|
|
22
29
|
constructor(schema: Schema);
|
|
23
30
|
/**
|
|
24
|
-
* @brief
|
|
25
|
-
|
|
31
|
+
* @brief Test whether a value satisfies this guard.
|
|
32
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
33
|
+
* existing guard instance.
|
|
34
|
+
* @param value Candidate runtime value.
|
|
35
|
+
* @returns True when the value is accepted by the guard schema.
|
|
36
|
+
*/
|
|
26
37
|
is(this: unknown, value: unknown): value is RuntimeValue<TValue, TPresence>;
|
|
27
38
|
/**
|
|
28
|
-
* @brief
|
|
29
|
-
|
|
39
|
+
* @brief Validate a value and return explicit diagnostics.
|
|
40
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
41
|
+
* existing guard instance.
|
|
42
|
+
* @param value Candidate runtime value.
|
|
43
|
+
* @returns Result carrying the value on success or frozen issues on failure.
|
|
44
|
+
*/
|
|
30
45
|
check(this: unknown, value: unknown): CheckResult<RuntimeValue<TValue, TPresence>>;
|
|
31
46
|
/**
|
|
32
|
-
* @brief
|
|
33
|
-
|
|
47
|
+
* @brief Validate a value and throw TypeSeaAssertionError on failure.
|
|
48
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
49
|
+
* existing guard instance.
|
|
50
|
+
* @param value Candidate runtime value.
|
|
51
|
+
* @throws TypeSeaAssertionError when validation fails.
|
|
52
|
+
*/
|
|
34
53
|
assert(this: unknown, value: unknown): asserts value is RuntimeValue<TValue, TPresence>;
|
|
35
54
|
/**
|
|
36
|
-
* @brief graph.
|
|
37
|
-
|
|
55
|
+
* @brief Return the optimized validation graph for introspection.
|
|
56
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
57
|
+
* existing guard instance.
|
|
58
|
+
* @returns Sea-of-Nodes graph derived from the guard schema.
|
|
59
|
+
*/
|
|
38
60
|
graph(this: unknown): Graph;
|
|
39
61
|
/**
|
|
40
|
-
* @brief optional.
|
|
41
|
-
|
|
62
|
+
* @brief Mark this guard as optional in object shapes.
|
|
63
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
64
|
+
* existing guard instance.
|
|
65
|
+
* @returns Fresh guard whose runtime value also allows absent object keys.
|
|
66
|
+
*/
|
|
42
67
|
optional(): BaseGuard<TValue, "optional">;
|
|
43
68
|
/**
|
|
44
|
-
* @brief
|
|
45
|
-
|
|
69
|
+
* @brief Allow the explicit undefined value.
|
|
70
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
71
|
+
* existing guard instance.
|
|
72
|
+
* @returns Fresh guard wrapping this schema in Undefinedable.
|
|
73
|
+
*/
|
|
46
74
|
undefinedable(): BaseGuard<TValue | undefined, TPresence>;
|
|
47
75
|
/**
|
|
48
|
-
* @brief
|
|
49
|
-
|
|
76
|
+
* @brief Allow the explicit null value.
|
|
77
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
78
|
+
* existing guard instance.
|
|
79
|
+
* @returns Fresh guard wrapping this schema in Nullable.
|
|
80
|
+
*/
|
|
50
81
|
nullable(): BaseGuard<TValue | null, TPresence>;
|
|
51
82
|
/**
|
|
52
|
-
* @brief array.
|
|
53
|
-
|
|
83
|
+
* @brief Build an array guard using this guard as the item schema.
|
|
84
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
85
|
+
* existing guard instance.
|
|
86
|
+
* @returns Fresh array guard.
|
|
87
|
+
*/
|
|
54
88
|
array(): BaseGuard<RuntimeValue<TValue, TPresence>[]>;
|
|
55
89
|
/**
|
|
56
|
-
* @brief brand.
|
|
57
|
-
|
|
90
|
+
* @brief Attach a compile-time brand without changing runtime validation.
|
|
91
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
92
|
+
* existing guard instance.
|
|
93
|
+
* @returns Fresh branded guard with the same runtime schema.
|
|
94
|
+
*/
|
|
58
95
|
brand<TBrand extends string>(): BaseGuard<Brand<TValue, TBrand>, TPresence>;
|
|
59
96
|
/**
|
|
60
|
-
* @brief
|
|
61
|
-
|
|
97
|
+
* @brief Append a user refinement predicate after this guard succeeds.
|
|
98
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
99
|
+
* existing guard instance.
|
|
100
|
+
* @param predicate Function that must return the boolean literal true.
|
|
101
|
+
* @param name Diagnostic name for refinement failure.
|
|
102
|
+
* @returns Fresh refined guard.
|
|
103
|
+
*/
|
|
62
104
|
refine(predicate: (value: RuntimeValue<TValue, TPresence>) => boolean, name: string): BaseGuard<TValue, TPresence>;
|
|
63
105
|
/**
|
|
64
|
-
* @brief
|
|
65
|
-
|
|
106
|
+
* @brief Build a union of this guard and another guard.
|
|
107
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
108
|
+
* existing guard instance.
|
|
109
|
+
* @param other Right-hand guard.
|
|
110
|
+
* @returns Fresh union guard preserving both runtime schemas.
|
|
111
|
+
*/
|
|
66
112
|
or<TOther extends Guard<unknown, Presence>>(other: TOther): BaseGuard<RuntimeValue<TValue, TPresence> | Infer<TOther>>;
|
|
67
113
|
/**
|
|
68
|
-
* @brief
|
|
69
|
-
|
|
114
|
+
* @brief Build an intersection of this guard and another guard.
|
|
115
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
116
|
+
* existing guard instance.
|
|
117
|
+
* @param other Right-hand guard.
|
|
118
|
+
* @returns Fresh intersection guard requiring both schemas to pass.
|
|
119
|
+
*/
|
|
70
120
|
intersect<TOther extends Guard<unknown, Presence>>(other: TOther): BaseGuard<RuntimeValue<TValue, TPresence> & Infer<TOther>>;
|
|
71
121
|
}
|
|
72
122
|
//# sourceMappingURL=base.d.ts.map
|
package/dist/guard/base.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/guard/base.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/guard/base.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AASjD,OAAO,KAAK,EACR,KAAK,EACL,KAAK,EACL,KAAK,EACL,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,UAAU,EACb,MAAM,YAAY,CAAC;AAEpB;;;;;;GAMG;AACH,qBAAa,SAAS,CAClB,MAAM,EACN,SAAS,SAAS,QAAQ,GAAG,UAAU,CACzC,YAAW,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC;IACjC,SAAwB,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7C,SAAwB,CAAC,cAAc,CAAC,EAAE,SAAS,CAAC;IACpD,SAAwB,MAAM,EAAE,MAAM,CAAC;IAEvC;;;;;;OAMG;gBACgB,MAAM,EAAE,MAAM;IAYjC;;;;;;OAMG;IACI,EAAE,CACL,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,OAAO,GACf,KAAK,IAAI,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC;IAQ3C;;;;;;OAMG;IACI,KAAK,CACR,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,OAAO,GACf,WAAW,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAO/C;;;;;;OAMG;IACI,MAAM,CACT,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,OAAO,GACf,OAAO,CAAC,KAAK,IAAI,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC;IAUnD;;;;;OAKG;IACI,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,KAAK;IAIlC;;;;;OAKG;IACI,QAAQ,IAAI,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;IAOhD;;;;;OAKG;IACI,aAAa,IAAI,SAAS,CAAC,MAAM,GAAG,SAAS,EAAE,SAAS,CAAC;IAOhE;;;;;OAKG;IACI,QAAQ,IAAI,SAAS,CAAC,MAAM,GAAG,IAAI,EAAE,SAAS,CAAC;IAOtD;;;;;OAKG;IACI,KAAK,IAAI,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC;IAO5D;;;;;OAKG;IACI,KAAK,CAAC,MAAM,SAAS,MAAM,KAAK,SAAS,CAC5C,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,EACrB,SAAS,CACZ;IAQD;;;;;;;OAOG;IACI,MAAM,CACT,SAAS,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,OAAO,EAC9D,IAAI,EAAE,MAAM,GACb,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC;IAe/B;;;;;;OAMG;IACI,EAAE,CAAC,MAAM,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EAC7C,KAAK,EAAE,MAAM,GACd,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAY7D;;;;;;OAMG;IACI,SAAS,CAAC,MAAM,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EACpD,KAAK,EAAE,MAAM,GACd,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;CAOhE"}
|