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
package/dist/guard/types.d.ts
CHANGED
|
@@ -1,103 +1,155 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file types.ts
|
|
3
3
|
* @brief Public guard type contracts.
|
|
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 { BaseGuard } from "./base.js";
|
|
9
|
-
/**
|
|
10
|
-
* @brief type symbol.
|
|
11
|
-
*/
|
|
12
11
|
export declare const TypeSymbol: unique symbol;
|
|
13
|
-
/**
|
|
14
|
-
* @brief presence symbol.
|
|
15
|
-
*/
|
|
16
12
|
export declare const PresenceSymbol: unique symbol;
|
|
17
|
-
/**
|
|
18
|
-
* @brief brand symbol.
|
|
19
|
-
*/
|
|
20
13
|
export declare const BrandSymbol: unique symbol;
|
|
21
14
|
/**
|
|
22
|
-
* @brief presence.
|
|
15
|
+
* @brief Object-property presence mode carried by a guard.
|
|
16
|
+
* @details Presence is a type-level property of guards, not a runtime schema
|
|
17
|
+
* wrapper by itself. Object builders use it to decide required versus optional
|
|
18
|
+
* field semantics during shape construction.
|
|
23
19
|
*/
|
|
24
20
|
export type Presence = "required" | "optional";
|
|
25
21
|
/**
|
|
26
|
-
* @brief
|
|
22
|
+
* @brief Runtime value accepted by a guard after presence is applied.
|
|
23
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
24
|
+
* existing guard instance.
|
|
27
25
|
*/
|
|
28
26
|
export type RuntimeValue<TValue, TPresence extends Presence> = TPresence extends "optional" ? TValue | undefined : TValue;
|
|
29
27
|
/**
|
|
30
|
-
* @brief
|
|
28
|
+
* @brief Infer the runtime value type accepted by a guard.
|
|
29
|
+
* @details Optional guards add undefined at the type level so object shape
|
|
30
|
+
* inference and standalone guard usage agree on accepted values.
|
|
31
31
|
*/
|
|
32
32
|
export type Infer<TGuard> = TGuard extends Guard<infer TValue, infer TPresence> ? RuntimeValue<TValue, TPresence> : never;
|
|
33
33
|
/**
|
|
34
|
-
* @brief
|
|
34
|
+
* @brief Extract the raw value type carried by a guard.
|
|
35
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
36
|
+
* existing guard instance.
|
|
35
37
|
*/
|
|
36
38
|
export type GuardValue<TGuard> = TGuard extends Guard<infer TValue, Presence> ? TValue : never;
|
|
37
39
|
/**
|
|
38
|
-
* @brief
|
|
40
|
+
* @brief Extract the presence mode carried by a guard.
|
|
41
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
42
|
+
* existing guard instance.
|
|
39
43
|
*/
|
|
40
44
|
export type GuardPresence<TGuard> = TGuard extends Guard<unknown, infer TPresence> ? TPresence : never;
|
|
41
45
|
/**
|
|
42
|
-
* @brief
|
|
46
|
+
* @brief Phantom intersection used for compile-time nominal brands.
|
|
47
|
+
* @details No runtime field is materialized; validators keep the same data
|
|
48
|
+
* representation as the unbranded value.
|
|
43
49
|
*/
|
|
44
50
|
export type Brand<TValue, TBrand extends string> = TValue & {
|
|
45
51
|
readonly [BrandSymbol]: TBrand;
|
|
46
52
|
};
|
|
47
53
|
/**
|
|
48
|
-
* @brief guard.
|
|
54
|
+
* @brief Public structural guard contract.
|
|
55
|
+
* @details The symbols carry inference-only type state. The schema property is
|
|
56
|
+
* the runtime handle used by interpreters, compilers, and graph introspection.
|
|
49
57
|
*/
|
|
50
58
|
export interface Guard<TValue, TPresence extends Presence = "required"> {
|
|
51
59
|
readonly [TypeSymbol]: TValue;
|
|
52
60
|
readonly [PresenceSymbol]: TPresence;
|
|
53
61
|
readonly schema: Schema;
|
|
54
62
|
/**
|
|
55
|
-
* @brief is.
|
|
56
|
-
|
|
63
|
+
* @brief Test whether a runtime value is accepted.
|
|
64
|
+
* @details This is the boolean hot path. It avoids diagnostic allocation and
|
|
65
|
+
* is the method used by compiled predicates for tight validation loops.
|
|
66
|
+
* @param value Candidate runtime value.
|
|
67
|
+
* @returns True when the guard accepts the value.
|
|
68
|
+
*/
|
|
57
69
|
is(value: unknown): value is RuntimeValue<TValue, TPresence>;
|
|
58
70
|
/**
|
|
59
|
-
* @brief
|
|
60
|
-
|
|
71
|
+
* @brief Validate a runtime value and return explicit issues on failure.
|
|
72
|
+
* @details Use this path when callers need structured diagnostics. Success
|
|
73
|
+
* returns the original value with the guard's inferred runtime type.
|
|
74
|
+
* @param value Candidate runtime value.
|
|
75
|
+
* @returns Check result with either the accepted value or frozen issues.
|
|
76
|
+
*/
|
|
61
77
|
check(value: unknown): CheckResult<RuntimeValue<TValue, TPresence>>;
|
|
62
78
|
/**
|
|
63
|
-
* @brief
|
|
64
|
-
|
|
79
|
+
* @brief Validate a runtime value or throw TypeSeaAssertionError.
|
|
80
|
+
* @details This convenience wrapper is intentionally explicit in the method
|
|
81
|
+
* name because most TypeSea APIs prefer Result-based control flow.
|
|
82
|
+
* @param value Candidate runtime value.
|
|
83
|
+
*/
|
|
65
84
|
assert(value: unknown): asserts value is RuntimeValue<TValue, TPresence>;
|
|
66
85
|
/**
|
|
67
|
-
* @brief graph.
|
|
68
|
-
|
|
86
|
+
* @brief Return the optimized validation graph for introspection.
|
|
87
|
+
* @details The graph is immutable and may be reused by tooling, debugging,
|
|
88
|
+
* or code generation without exposing schema internals directly.
|
|
89
|
+
* @returns Optimized Sea-of-Nodes validation graph.
|
|
90
|
+
*/
|
|
69
91
|
graph(): Graph;
|
|
70
92
|
/**
|
|
71
|
-
* @brief optional.
|
|
72
|
-
|
|
93
|
+
* @brief Mark this guard optional for object shape usage.
|
|
94
|
+
* @details Optionality changes object field presence and standalone
|
|
95
|
+
* inference by adding undefined; it does not mutate the source guard.
|
|
96
|
+
* @returns New guard carrying optional presence.
|
|
97
|
+
*/
|
|
73
98
|
optional(): BaseGuard<TValue, "optional">;
|
|
74
99
|
/**
|
|
75
|
-
* @brief
|
|
76
|
-
|
|
100
|
+
* @brief Allow the explicit undefined value.
|
|
101
|
+
* @details This widens the value domain while preserving the field presence
|
|
102
|
+
* mode. In object shapes, an undefinedable required field still has to be
|
|
103
|
+
* present.
|
|
104
|
+
* @returns New guard whose value type includes undefined.
|
|
105
|
+
*/
|
|
77
106
|
undefinedable(): BaseGuard<TValue | undefined, TPresence>;
|
|
78
107
|
/**
|
|
79
|
-
* @brief
|
|
80
|
-
|
|
108
|
+
* @brief Allow the explicit null value.
|
|
109
|
+
* @details Nullability is modeled as a value-domain wrapper rather than an
|
|
110
|
+
* object-presence change, so it composes predictably with optional fields.
|
|
111
|
+
* @returns New guard whose value type includes null.
|
|
112
|
+
*/
|
|
81
113
|
nullable(): BaseGuard<TValue | null, TPresence>;
|
|
82
114
|
/**
|
|
83
|
-
* @brief array.
|
|
84
|
-
|
|
115
|
+
* @brief Build an array guard from this guard.
|
|
116
|
+
* @details The item schema is the current guard's runtime value domain after
|
|
117
|
+
* presence has been applied, matching direct `is` semantics.
|
|
118
|
+
* @returns Guard that accepts arrays of values accepted by this guard.
|
|
119
|
+
*/
|
|
85
120
|
array(): BaseGuard<RuntimeValue<TValue, TPresence>[]>;
|
|
86
121
|
/**
|
|
87
|
-
* @brief brand.
|
|
88
|
-
|
|
122
|
+
* @brief Apply a compile-time brand without changing runtime data.
|
|
123
|
+
* @details Brands are phantom types. Validation behavior and emitted IR stay
|
|
124
|
+
* identical to the unbranded guard.
|
|
125
|
+
* @returns New guard carrying the requested nominal brand.
|
|
126
|
+
*/
|
|
89
127
|
brand<TBrand extends string>(): BaseGuard<Brand<TValue, TBrand>, TPresence>;
|
|
90
128
|
/**
|
|
91
|
-
* @brief
|
|
92
|
-
|
|
129
|
+
* @brief Append a user refinement predicate.
|
|
130
|
+
* @details Refinements run after the base schema accepts the value. They are
|
|
131
|
+
* intentionally opaque to JSON Schema and AOT export because the predicate is
|
|
132
|
+
* arbitrary user code.
|
|
133
|
+
* @param predicate Function that returns literal true for success.
|
|
134
|
+
* @param name Diagnostic name for failed refinements.
|
|
135
|
+
* @returns New guard with the refinement appended.
|
|
136
|
+
*/
|
|
93
137
|
refine(predicate: (value: RuntimeValue<TValue, TPresence>) => boolean, name: string): BaseGuard<TValue, TPresence>;
|
|
94
138
|
/**
|
|
95
|
-
* @brief
|
|
96
|
-
|
|
139
|
+
* @brief Build a union with another guard.
|
|
140
|
+
* @details Union order is preserved so diagnostics and generated code follow
|
|
141
|
+
* the same branch precedence as the fluent call chain.
|
|
142
|
+
* @param other Guard accepted as the second union arm.
|
|
143
|
+
* @returns Guard accepting values accepted by either guard.
|
|
144
|
+
*/
|
|
97
145
|
or<TOther extends Guard<unknown, Presence>>(other: TOther): BaseGuard<RuntimeValue<TValue, TPresence> | Infer<TOther>>;
|
|
98
146
|
/**
|
|
99
|
-
* @brief
|
|
100
|
-
|
|
147
|
+
* @brief Build an intersection with another guard.
|
|
148
|
+
* @details Both guards must accept the same value. The resulting type is the
|
|
149
|
+
* TypeScript intersection of their inferred runtime domains.
|
|
150
|
+
* @param other Guard accepted as the second intersection arm.
|
|
151
|
+
* @returns Guard accepting only values accepted by both guards.
|
|
152
|
+
*/
|
|
101
153
|
intersect<TOther extends Guard<unknown, Presence>>(other: TOther): BaseGuard<RuntimeValue<TValue, TPresence> & Infer<TOther>>;
|
|
102
154
|
}
|
|
103
155
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/guard/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/guard/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,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;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,CAAC,OAAO,CAAC,MAAM,UAAU,EAAE,OAAO,MAAM,CAAC;AAE/C,MAAM,CAAC,OAAO,CAAC,MAAM,cAAc,EAAE,OAAO,MAAM,CAAC;AAEnD,MAAM,CAAC,OAAO,CAAC,MAAM,WAAW,EAAE,OAAO,MAAM,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC;AAE/C;;;;GAIG;AACH,MAAM,MAAM,YAAY,CAAC,MAAM,EAAE,SAAS,SAAS,QAAQ,IACvD,SAAS,SAAS,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,KAAK,CAAC,MAAM,IACpB,MAAM,SAAS,KAAK,CAAC,MAAM,MAAM,EAAE,MAAM,SAAS,CAAC,GAC7C,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,GAC/B,KAAK,CAAC;AAEhB;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,MAAM,IACzB,MAAM,SAAS,KAAK,CAAC,MAAM,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC;AAElE;;;;GAIG;AACH,MAAM,MAAM,aAAa,CAAC,MAAM,IAC5B,MAAM,SAAS,KA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CAAC;IAEtD;;;;;OAKG;IACH,KAAK,CAAC,MAAM,SAAS,MAAM,KAAK,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;IAE5E;;;;;;;;OAQG;IACH,MAAM,CACF,SAAS,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,OAAO,EAC9D,IAAI,EAAE,MAAM,GACb,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAEhC;;;;;;OAMG;IACH,EAAE,CAAC,MAAM,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EACtC,KAAK,EAAE,MAAM,GACd,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAE9D;;;;;;OAMG;IACH,SAAS,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,CAAC;CACjE"}
|
package/dist/guard/types.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { t, array, bigintGuard, discriminatedUnion, extend, intersect, lazy, literal, nullable, neverGuard, object, omit, optional, partial, pick, record, refine, strictObject, symbolGuard, tuple, union, unknownGuard, undefinedable, type InferObject, type InferTuple, type MergeObjectShapes, type ObjectGuardMode, type ObjectShape, type OmitObjectShape, ObjectGuard, type PartialObjectShape, type PickObjectShape, type TupleShape } from "./builders/index.js";
|
|
2
2
|
export { BaseGuard, NumberGuard, StringGuard, TypeSeaAssertionError, type Brand, type Guard, type GuardPresence, type GuardValue, type Infer, type Presence, type RuntimeValue } from "./guard/index.js";
|
|
3
|
-
export { CompiledBaseGuard, compile, type CompileOptions, type CompiledGuard } from "./compile/index.js";
|
|
3
|
+
export { CompiledBaseGuard, compile, type CompileMode, type CompileOptions, type CompiledGuard } from "./compile/index.js";
|
|
4
4
|
export { emitAotModule, type AotCompileOptions, type AotIssue, type AotIssueCode, type AotModule } from "./aot/index.js";
|
|
5
5
|
export { toAsyncTrpcParser, toFastifyRouteSchema, toFastifyValidatorCompiler, toReactHookFormResolver, toTrpcParser, type AsyncTrpcParser, type FastifyHttpPart, type FastifyRouteSchema, type FastifyRouteSchemaOptions, type FastifyValidationResult, type FastifyValidator, type FastifyValidatorCompiler, type FastifyValidatorCompilerSource, type FastifyValidatorCompilerSourceMap, type FastifyValidatorRoute, type InferAdapter, type InferSyncAdapter, type ReactHookFormErrors, type ReactHookFormFieldError, type ReactHookFormResolver, type ReactHookFormResolverOptions, type ReactHookFormResolverResult, type SyncAdapterSource, type TrpcParser } from "./adapters/index.js";
|
|
6
6
|
export { BaseAsyncDecoder, asyncDecoder, asyncPipe, asyncRefine, asyncTransform, isAsyncDecoderValue, type AsyncDecodeSource, type AsyncDecoder, type InferAsyncDecoder } from "./async/index.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,CAAC,EACD,KAAK,EACL,WAAW,EACX,kBAAkB,EAClB,MAAM,EACN,SAAS,EACT,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,UAAU,EACV,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,MAAM,EACN,MAAM,EACN,YAAY,EACZ,WAAW,EACX,KAAK,EACL,KAAK,EACL,YAAY,EACZ,aAAa,EACb,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK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;AAE1B,OAAO,EACH,WAAW,EACX,MAAM,EACN,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,cAAc,EACd,IAAI,EACJ,SAAS,EACT,KAAK,YAAY,EACjB,KAAK,OAAO,EACZ,KAAK,YAAY,EACpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACH,kBAAkB,EAClB,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EAC1B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACH,cAAc,EACd,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EACrB,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACnF,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file internal.ts
|
|
3
3
|
* @brief Private helpers shared across TypeSea translation units.
|
|
4
|
+
* @details This declaration records the local invariant that callers rely on after this
|
|
5
|
+
* module boundary.
|
|
4
6
|
*
|
|
5
7
|
* @invariant Values crossing a module boundary stay `unknown` until a local
|
|
6
8
|
* guard proves the shape needed by that module.
|
|
@@ -8,27 +10,61 @@
|
|
|
8
10
|
import type { Guard, Presence } from "../guard/index.js";
|
|
9
11
|
import { type Schema } from "../schema/index.js";
|
|
10
12
|
/**
|
|
11
|
-
* @brief
|
|
13
|
+
* @brief Read a guard schema after proving the receiver shape locally.
|
|
14
|
+
* @param guard Candidate guard-like value.
|
|
15
|
+
* @param label Message prefix for TypeError diagnostics.
|
|
16
|
+
* @returns Valid schema stored in an own data slot.
|
|
17
|
+
* @throws TypeError when the receiver is not structurally a TypeSea guard.
|
|
18
|
+
* @details This helper is used by builders that accept guard-like values rather
|
|
19
|
+
* than constructed guard instances. The schema field is read by descriptor so a
|
|
20
|
+
* forged prototype cannot supply or mutate the schema after admission.
|
|
12
21
|
*/
|
|
13
22
|
export declare function readGuardSchema(guard: unknown, label: string): Schema;
|
|
14
23
|
/**
|
|
15
|
-
* @brief
|
|
24
|
+
* @brief Check record.
|
|
25
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
16
26
|
*/
|
|
17
27
|
export declare function isRecord(value: unknown): value is Readonly<Record<string, unknown>>;
|
|
18
28
|
/**
|
|
19
|
-
* @brief
|
|
29
|
+
* @brief Accept an array before a caller performs local element validation.
|
|
30
|
+
* @details This declaration records the local invariant that callers rely on after this
|
|
31
|
+
* module boundary.
|
|
32
|
+
* @param value Candidate vector.
|
|
33
|
+
* @returns True when the value is an Array instance.
|
|
20
34
|
*/
|
|
21
35
|
export declare function isUnknownArray(value: unknown): value is readonly unknown[];
|
|
22
36
|
/**
|
|
23
|
-
* @brief
|
|
37
|
+
* @brief Linear membership for short builder-owned string vectors.
|
|
38
|
+
* @details This declaration records the local invariant that callers rely on after this
|
|
39
|
+
* module boundary.
|
|
40
|
+
* @param values Candidate set represented as an ordered vector.
|
|
41
|
+
* @param value String being searched.
|
|
42
|
+
* @returns True when the string is present.
|
|
24
43
|
*/
|
|
25
44
|
export declare function includesString(values: readonly string[], value: string): boolean;
|
|
26
45
|
/**
|
|
27
|
-
* @brief
|
|
46
|
+
* @brief Accept only the literal boolean success value from user predicates.
|
|
47
|
+
* @details This declaration records the local invariant that callers rely on after this
|
|
48
|
+
* module boundary.
|
|
49
|
+
* @param value Predicate return value.
|
|
50
|
+
* @returns True only for `true`.
|
|
28
51
|
*/
|
|
29
52
|
export declare function isStrictTrue(value: unknown): boolean;
|
|
30
53
|
/**
|
|
31
|
-
* @brief
|
|
54
|
+
* @brief Check whether a value structurally exposes a TypeSea schema.
|
|
55
|
+
* @details This declaration records the local invariant that callers rely on after this
|
|
56
|
+
* module boundary.
|
|
57
|
+
* @param value Candidate guard-like object.
|
|
58
|
+
* @returns True when a valid schema is stored directly on the object.
|
|
32
59
|
*/
|
|
33
60
|
export declare function isGuardValue(value: unknown): value is Guard<unknown, Presence>;
|
|
61
|
+
/**
|
|
62
|
+
* @brief Read one own data property without running getters.
|
|
63
|
+
* @details This declaration records the local invariant that callers rely on after this
|
|
64
|
+
* module boundary.
|
|
65
|
+
* @param value Object being normalized.
|
|
66
|
+
* @param key Field name or symbol.
|
|
67
|
+
* @returns Stored field value, or undefined when the own data slot is absent.
|
|
68
|
+
*/
|
|
69
|
+
export declare function readOwnDataProperty(value: object, key: PropertyKey): unknown;
|
|
34
70
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/internal/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/internal/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC3B,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,GACd,MAAM,CASR;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CACpB,KAAK,EAAE,OAAO,GACf,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAE5C;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,OAAO,EAAE,CAE1E;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC1B,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,KAAK,EAAE,MAAM,GACd,OAAO,CAOT;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CACxB,KAAK,EAAE,OAAO,GACf,KAAK,IAAI,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAEnC;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAC/B,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,WAAW,GACjB,OAAO,CAOT"}
|
package/dist/internal/index.js
CHANGED
|
@@ -1,38 +1,57 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file internal.ts
|
|
3
3
|
* @brief Private helpers shared across TypeSea translation units.
|
|
4
|
+
* @details This declaration records the local invariant that callers rely on after this
|
|
5
|
+
* module boundary.
|
|
4
6
|
*
|
|
5
7
|
* @invariant Values crossing a module boundary stay `unknown` until a local
|
|
6
8
|
* guard proves the shape needed by that module.
|
|
7
9
|
*/
|
|
8
10
|
import { isSchemaValue } from "../schema/index.js";
|
|
9
11
|
/**
|
|
10
|
-
* @brief
|
|
12
|
+
* @brief Read a guard schema after proving the receiver shape locally.
|
|
13
|
+
* @param guard Candidate guard-like value.
|
|
14
|
+
* @param label Message prefix for TypeError diagnostics.
|
|
15
|
+
* @returns Valid schema stored in an own data slot.
|
|
16
|
+
* @throws TypeError when the receiver is not structurally a TypeSea guard.
|
|
17
|
+
* @details This helper is used by builders that accept guard-like values rather
|
|
18
|
+
* than constructed guard instances. The schema field is read by descriptor so a
|
|
19
|
+
* forged prototype cannot supply or mutate the schema after admission.
|
|
11
20
|
*/
|
|
12
21
|
export function readGuardSchema(guard, label) {
|
|
13
22
|
if (!isRecord(guard)) {
|
|
14
23
|
throw new TypeError(`${label} must be a TypeSea guard`);
|
|
15
24
|
}
|
|
16
|
-
const schema = guard
|
|
25
|
+
const schema = readOwnDataProperty(guard, "schema");
|
|
17
26
|
if (!isSchemaValue(schema)) {
|
|
18
27
|
throw new TypeError(`${label} must contain a valid TypeSea schema`);
|
|
19
28
|
}
|
|
20
29
|
return schema;
|
|
21
30
|
}
|
|
22
31
|
/**
|
|
23
|
-
* @brief
|
|
32
|
+
* @brief Check record.
|
|
33
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
24
34
|
*/
|
|
25
35
|
export function isRecord(value) {
|
|
26
36
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27
37
|
}
|
|
28
38
|
/**
|
|
29
|
-
* @brief
|
|
39
|
+
* @brief Accept an array before a caller performs local element validation.
|
|
40
|
+
* @details This declaration records the local invariant that callers rely on after this
|
|
41
|
+
* module boundary.
|
|
42
|
+
* @param value Candidate vector.
|
|
43
|
+
* @returns True when the value is an Array instance.
|
|
30
44
|
*/
|
|
31
45
|
export function isUnknownArray(value) {
|
|
32
46
|
return Array.isArray(value);
|
|
33
47
|
}
|
|
34
48
|
/**
|
|
35
|
-
* @brief
|
|
49
|
+
* @brief Linear membership for short builder-owned string vectors.
|
|
50
|
+
* @details This declaration records the local invariant that callers rely on after this
|
|
51
|
+
* module boundary.
|
|
52
|
+
* @param values Candidate set represented as an ordered vector.
|
|
53
|
+
* @param value String being searched.
|
|
54
|
+
* @returns True when the string is present.
|
|
36
55
|
*/
|
|
37
56
|
export function includesString(values, value) {
|
|
38
57
|
for (let index = 0; index < values.length; index += 1) {
|
|
@@ -43,14 +62,38 @@ export function includesString(values, value) {
|
|
|
43
62
|
return false;
|
|
44
63
|
}
|
|
45
64
|
/**
|
|
46
|
-
* @brief
|
|
65
|
+
* @brief Accept only the literal boolean success value from user predicates.
|
|
66
|
+
* @details This declaration records the local invariant that callers rely on after this
|
|
67
|
+
* module boundary.
|
|
68
|
+
* @param value Predicate return value.
|
|
69
|
+
* @returns True only for `true`.
|
|
47
70
|
*/
|
|
48
71
|
export function isStrictTrue(value) {
|
|
49
72
|
return value === true;
|
|
50
73
|
}
|
|
51
74
|
/**
|
|
52
|
-
* @brief
|
|
75
|
+
* @brief Check whether a value structurally exposes a TypeSea schema.
|
|
76
|
+
* @details This declaration records the local invariant that callers rely on after this
|
|
77
|
+
* module boundary.
|
|
78
|
+
* @param value Candidate guard-like object.
|
|
79
|
+
* @returns True when a valid schema is stored directly on the object.
|
|
53
80
|
*/
|
|
54
81
|
export function isGuardValue(value) {
|
|
55
|
-
return isRecord(value) && isSchemaValue(value
|
|
82
|
+
return isRecord(value) && isSchemaValue(readOwnDataProperty(value, "schema"));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @brief Read one own data property without running getters.
|
|
86
|
+
* @details This declaration records the local invariant that callers rely on after this
|
|
87
|
+
* module boundary.
|
|
88
|
+
* @param value Object being normalized.
|
|
89
|
+
* @param key Field name or symbol.
|
|
90
|
+
* @returns Stored field value, or undefined when the own data slot is absent.
|
|
91
|
+
*/
|
|
92
|
+
export function readOwnDataProperty(value, key) {
|
|
93
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
94
|
+
if (descriptor === undefined ||
|
|
95
|
+
!Object.prototype.hasOwnProperty.call(descriptor, "value")) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
return descriptor.value;
|
|
56
99
|
}
|
package/dist/ir/builder.d.ts
CHANGED
|
@@ -1,173 +1,63 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file builder.ts
|
|
3
3
|
* @brief Dense graph builder with structural node interning.
|
|
4
|
+
* @details IR helpers preserve Sea-of-Nodes invariants before graphs cross optimizer,
|
|
5
|
+
* compiler, or public introspection boundaries.
|
|
4
6
|
*/
|
|
7
|
+
import { type ObjectModeTag } from "../kind/index.js";
|
|
5
8
|
import type { LiteralValue, Schema } from "../schema/index.js";
|
|
6
|
-
import type { Graph, NodeId } from "./types.js";
|
|
9
|
+
import type { Graph, NodeId, ObjectShapeEntry, UnionDispatchMask } from "./types.js";
|
|
7
10
|
/**
|
|
8
|
-
* @brief graph
|
|
9
|
-
* @details
|
|
10
|
-
*
|
|
11
|
+
* @brief Dense Sea-of-Nodes graph construction arena.
|
|
12
|
+
* @details The builder interns pure scalar nodes so later optimization passes see
|
|
13
|
+
* one canonical id for equivalent predicates. Composite nodes are deliberately
|
|
14
|
+
* appended instead: their embedded child graphs and schema payloads are owned
|
|
15
|
+
* values, and pointer-level interning would make aliasing harder to audit.
|
|
11
16
|
*/
|
|
12
17
|
export declare class GraphBuilder {
|
|
13
18
|
private readonly nodes;
|
|
14
19
|
private readonly hash;
|
|
15
|
-
/**
|
|
16
|
-
* @brief constructor.
|
|
17
|
-
* @post The receiver is initialized according to the class invariant before it can be observed.
|
|
18
|
-
*/
|
|
19
20
|
constructor();
|
|
20
|
-
/**
|
|
21
|
-
* @brief start.
|
|
22
|
-
*/
|
|
23
21
|
start(): NodeId;
|
|
24
|
-
/**
|
|
25
|
-
* @brief param.
|
|
26
|
-
*/
|
|
27
22
|
param(name: string): NodeId;
|
|
28
|
-
/**
|
|
29
|
-
* @brief constant.
|
|
30
|
-
*/
|
|
31
23
|
constant(value: LiteralValue): NodeId;
|
|
32
|
-
/**
|
|
33
|
-
* @brief get prop.
|
|
34
|
-
*/
|
|
35
24
|
getProp(object: NodeId, key: string): NodeId;
|
|
36
|
-
/**
|
|
37
|
-
* @brief is string.
|
|
38
|
-
*/
|
|
39
25
|
isString(value: NodeId): NodeId;
|
|
40
|
-
/**
|
|
41
|
-
* @brief is number.
|
|
42
|
-
*/
|
|
43
26
|
isNumber(value: NodeId): NodeId;
|
|
44
|
-
/**
|
|
45
|
-
* @brief is boolean.
|
|
46
|
-
*/
|
|
47
27
|
isBoolean(value: NodeId): NodeId;
|
|
48
|
-
/**
|
|
49
|
-
* @brief is big int.
|
|
50
|
-
*/
|
|
51
28
|
isBigInt(value: NodeId): NodeId;
|
|
52
|
-
/**
|
|
53
|
-
* @brief is symbol.
|
|
54
|
-
*/
|
|
55
29
|
isSymbol(value: NodeId): NodeId;
|
|
56
|
-
/**
|
|
57
|
-
* @brief is object.
|
|
58
|
-
*/
|
|
59
30
|
isObject(value: NodeId): NodeId;
|
|
60
|
-
/**
|
|
61
|
-
* @brief is array.
|
|
62
|
-
*/
|
|
63
31
|
isArray(value: NodeId): NodeId;
|
|
64
|
-
/**
|
|
65
|
-
* @brief is undefined.
|
|
66
|
-
*/
|
|
67
32
|
isUndefined(value: NodeId): NodeId;
|
|
68
|
-
/**
|
|
69
|
-
* @brief is null.
|
|
70
|
-
*/
|
|
71
33
|
isNull(value: NodeId): NodeId;
|
|
72
|
-
/**
|
|
73
|
-
* @brief is integer.
|
|
74
|
-
*/
|
|
75
34
|
isInteger(value: NodeId): NodeId;
|
|
76
|
-
/**
|
|
77
|
-
* @brief not.
|
|
78
|
-
*/
|
|
79
35
|
not(value: NodeId): NodeId;
|
|
80
|
-
/**
|
|
81
|
-
* @brief equals.
|
|
82
|
-
*/
|
|
83
36
|
equals(left: NodeId, right: NodeId): NodeId;
|
|
84
|
-
/**
|
|
85
|
-
* @brief gte.
|
|
86
|
-
*/
|
|
87
37
|
gte(left: NodeId, right: NodeId): NodeId;
|
|
88
|
-
/**
|
|
89
|
-
* @brief lte.
|
|
90
|
-
*/
|
|
91
38
|
lte(left: NodeId, right: NodeId): NodeId;
|
|
92
|
-
/**
|
|
93
|
-
* @brief string min.
|
|
94
|
-
*/
|
|
95
39
|
stringMin(value: NodeId, bound: number): NodeId;
|
|
96
|
-
/**
|
|
97
|
-
* @brief string max.
|
|
98
|
-
*/
|
|
99
40
|
stringMax(value: NodeId, bound: number): NodeId;
|
|
100
|
-
/**
|
|
101
|
-
* @brief regex.
|
|
102
|
-
*/
|
|
103
41
|
regex(value: NodeId, regex: RegExp, name: string): NodeId;
|
|
104
|
-
/**
|
|
105
|
-
* @brief has own.
|
|
106
|
-
*/
|
|
107
42
|
hasOwn(object: NodeId, key: string): NodeId;
|
|
108
|
-
/**
|
|
109
|
-
* @brief has own data.
|
|
110
|
-
*/
|
|
111
43
|
hasOwnData(object: NodeId, key: string): NodeId;
|
|
112
|
-
/**
|
|
113
|
-
* @brief strict keys.
|
|
114
|
-
*/
|
|
115
44
|
strictKeys(object: NodeId, keys: readonly string[]): NodeId;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
tupleItems(value: NodeId, items: readonly Schema[]): NodeId;
|
|
124
|
-
/**
|
|
125
|
-
* @brief record every.
|
|
126
|
-
*/
|
|
127
|
-
recordEvery(value: NodeId, item: Schema): NodeId;
|
|
128
|
-
/**
|
|
129
|
-
* @brief discriminant dispatch.
|
|
130
|
-
*/
|
|
131
|
-
discriminantDispatch(value: NodeId, key: string, literals: readonly string[], schemas: readonly Schema[]): NodeId;
|
|
132
|
-
/**
|
|
133
|
-
* @brief schema check.
|
|
134
|
-
*/
|
|
45
|
+
arrayEvery(value: NodeId, item: Schema, itemGraph: Graph): NodeId;
|
|
46
|
+
tupleItems(value: NodeId, items: readonly Schema[], itemGraphs: readonly Graph[]): NodeId;
|
|
47
|
+
recordEvery(value: NodeId, item: Schema, itemGraph: Graph): NodeId;
|
|
48
|
+
discriminantDispatch(value: NodeId, key: string, literals: readonly string[], schemas: readonly Schema[], graphs: readonly Graph[]): NodeId;
|
|
49
|
+
objectShape(value: NodeId, entries: readonly ObjectShapeEntry[], keys: readonly string[], mode: ObjectModeTag): NodeId;
|
|
50
|
+
unionDispatch(value: NodeId, options: readonly Schema[], graphs: readonly Graph[], masks: readonly UnionDispatchMask[]): NodeId;
|
|
51
|
+
primitiveUnion(value: NodeId, graphs: readonly Graph[], masks: readonly UnionDispatchMask[]): NodeId;
|
|
135
52
|
schemaCheck(value: NodeId, schema: Schema): NodeId;
|
|
136
|
-
/**
|
|
137
|
-
* @brief and.
|
|
138
|
-
*/
|
|
139
53
|
and(values: readonly NodeId[]): NodeId;
|
|
140
|
-
/**
|
|
141
|
-
* @brief or.
|
|
142
|
-
*/
|
|
143
54
|
or(values: readonly NodeId[]): NodeId;
|
|
144
|
-
/**
|
|
145
|
-
* @brief ret.
|
|
146
|
-
*/
|
|
147
55
|
ret(control: NodeId, value: NodeId): NodeId;
|
|
148
|
-
/**
|
|
149
|
-
* @brief finish.
|
|
150
|
-
*/
|
|
151
56
|
finish(entry: NodeId, result: NodeId): Graph;
|
|
152
|
-
/**
|
|
153
|
-
* @brief unary.
|
|
154
|
-
*/
|
|
155
57
|
private unary;
|
|
156
|
-
/**
|
|
157
|
-
* @brief numeric.
|
|
158
|
-
*/
|
|
159
58
|
private numeric;
|
|
160
|
-
/**
|
|
161
|
-
* @brief string bound.
|
|
162
|
-
*/
|
|
163
59
|
private stringBound;
|
|
164
|
-
/**
|
|
165
|
-
* @brief intern.
|
|
166
|
-
*/
|
|
167
60
|
private intern;
|
|
168
|
-
/**
|
|
169
|
-
* @brief push.
|
|
170
|
-
*/
|
|
171
61
|
private push;
|
|
172
62
|
}
|
|
173
63
|
//# sourceMappingURL=builder.d.ts.map
|
package/dist/ir/builder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/ir/builder.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/ir/builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG/D,OAAO,KAAK,EAQR,KAAK,EAIL,MAAM,EACN,gBAAg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