typesea 0.1.0 → 0.3.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 +85 -6
- package/README.md +143 -28
- 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 +19 -3
- package/dist/aot/index.d.ts.map +1 -1
- package/dist/aot/index.js +115 -17
- 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 +43 -9
- package/dist/builders/composite.d.ts.map +1 -1
- package/dist/builders/composite.js +100 -17
- package/dist/builders/index.d.ts +8 -5
- package/dist/builders/index.d.ts.map +1 -1
- package/dist/builders/index.js +7 -4
- package/dist/builders/modifier.d.ts +36 -5
- package/dist/builders/modifier.d.ts.map +1 -1
- package/dist/builders/modifier.js +52 -5
- package/dist/builders/object/guard.d.ts +72 -24
- package/dist/builders/object/guard.d.ts.map +1 -1
- package/dist/builders/object/guard.js +139 -29
- package/dist/builders/object/index.d.ts +4 -2
- package/dist/builders/object/index.d.ts.map +1 -1
- package/dist/builders/object/index.js +3 -1
- package/dist/builders/object/schema.d.ts +88 -11
- package/dist/builders/object/schema.d.ts.map +1 -1
- package/dist/builders/object/schema.js +290 -23
- package/dist/builders/object/types.d.ts +20 -31
- package/dist/builders/object/types.d.ts.map +1 -1
- package/dist/builders/object/types.js +2 -0
- package/dist/builders/runtime.d.ts +40 -0
- package/dist/builders/runtime.d.ts.map +1 -0
- package/dist/builders/runtime.js +150 -0
- package/dist/builders/scalar.d.ts +49 -9
- package/dist/builders/scalar.d.ts.map +1 -1
- package/dist/builders/scalar.js +87 -9
- package/dist/builders/table.d.ts +35 -5
- package/dist/builders/table.d.ts.map +1 -1
- package/dist/builders/table.js +35 -5
- package/dist/builders/types.d.ts +20 -4
- package/dist/builders/types.d.ts.map +1 -1
- package/dist/builders/types.js +2 -0
- package/dist/compile/check-composite.d.ts +25 -2
- package/dist/compile/check-composite.d.ts.map +1 -1
- package/dist/compile/check-composite.js +699 -27
- package/dist/compile/check-scalar.d.ts +88 -0
- package/dist/compile/check-scalar.d.ts.map +1 -1
- package/dist/compile/check-scalar.js +570 -3
- package/dist/compile/check.d.ts +12 -0
- package/dist/compile/check.d.ts.map +1 -1
- package/dist/compile/check.js +62 -3
- package/dist/compile/context.d.ts +47 -9
- package/dist/compile/context.d.ts.map +1 -1
- package/dist/compile/context.js +53 -8
- package/dist/compile/first.d.ts +26 -0
- package/dist/compile/first.d.ts.map +1 -0
- package/dist/compile/first.js +850 -0
- 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 +2272 -165
- package/dist/compile/guard.d.ts +16 -24
- package/dist/compile/guard.d.ts.map +1 -1
- package/dist/compile/guard.js +202 -72
- 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 +287 -10
- package/dist/compile/runtime.d.ts +100 -13
- package/dist/compile/runtime.d.ts.map +1 -1
- package/dist/compile/runtime.js +56 -6
- package/dist/compile/source.d.ts +10 -2
- package/dist/compile/source.d.ts.map +1 -1
- package/dist/compile/source.js +385 -26
- package/dist/compile/types.d.ts +22 -0
- package/dist/compile/types.d.ts.map +1 -1
- package/dist/compile/types.js +2 -0
- package/dist/decoder/index.d.ts +92 -46
- package/dist/decoder/index.d.ts.map +1 -1
- package/dist/decoder/index.js +266 -39
- package/dist/evaluate/check-composite.d.ts +111 -2
- package/dist/evaluate/check-composite.d.ts.map +1 -1
- package/dist/evaluate/check-composite.js +343 -8
- package/dist/evaluate/check-scalar.d.ts +25 -0
- package/dist/evaluate/check-scalar.d.ts.map +1 -1
- package/dist/evaluate/check-scalar.js +124 -3
- package/dist/evaluate/check.d.ts +7 -0
- package/dist/evaluate/check.d.ts.map +1 -1
- package/dist/evaluate/check.js +62 -4
- 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 +78 -13
- package/dist/evaluate/shared.d.ts.map +1 -1
- package/dist/evaluate/shared.js +101 -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/array.d.ts +48 -0
- package/dist/guard/array.d.ts.map +1 -0
- package/dist/guard/array.js +84 -0
- package/dist/guard/base.d.ts +111 -31
- package/dist/guard/base.d.ts.map +1 -1
- package/dist/guard/base.js +165 -32
- package/dist/guard/date.d.ts +34 -0
- package/dist/guard/date.d.ts.map +1 -0
- package/dist/guard/date.js +60 -0
- 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 +4 -0
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +4 -0
- package/dist/guard/number.d.ts +86 -11
- package/dist/guard/number.d.ts.map +1 -1
- package/dist/guard/number.js +159 -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 +115 -10
- package/dist/guard/read.d.ts.map +1 -1
- package/dist/guard/read.js +185 -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 +115 -13
- package/dist/guard/string.d.ts.map +1 -1
- package/dist/guard/string.js +250 -13
- package/dist/guard/types.d.ts +110 -40
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/guard/types.js +2 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- 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 +17 -127
- package/dist/ir/builder.d.ts.map +1 -1
- package/dist/ir/builder.js +80 -137
- package/dist/ir/freeze.d.ts +4 -0
- package/dist/ir/freeze.d.ts.map +1 -1
- package/dist/ir/freeze.js +66 -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 +94 -56
- 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 +511 -61
- package/dist/issue/index.d.ts +42 -10
- package/dist/issue/index.d.ts.map +1 -1
- package/dist/issue/index.js +65 -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 +16 -2
- package/dist/json-schema/emit-composite.d.ts.map +1 -1
- package/dist/json-schema/emit-composite.js +81 -13
- 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 +124 -10
- 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 +23 -3
- 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 +45 -16
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/json-schema/types.js +2 -0
- package/dist/kind/index.d.ts +40 -28
- package/dist/kind/index.d.ts.map +1 -1
- package/dist/kind/index.js +41 -13
- package/dist/lower/index.d.ts +6 -1
- package/dist/lower/index.d.ts.map +1 -1
- package/dist/lower/index.js +462 -46
- package/dist/message/index.d.ts +64 -10
- package/dist/message/index.d.ts.map +1 -1
- package/dist/message/index.js +155 -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 +619 -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 +48 -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 +34 -6
- 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 +298 -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 +382 -19
- 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 +40 -0
- package/dist/schema/index.d.ts +5 -2
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +4 -1
- 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 +109 -100
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js +13 -2
- package/dist/schema/undefined.d.ts +17 -0
- package/dist/schema/undefined.d.ts.map +1 -0
- package/dist/schema/undefined.js +77 -0
- package/dist/schema/validate.d.ts +8 -1
- package/dist/schema/validate.d.ts.map +1 -1
- package/dist/schema/validate.js +255 -57
- package/docs/api.md +128 -8
- package/docs/assets/benchmark-headline.svg +163 -0
- package/docs/engine-notes.md +62 -15
- package/docs/index.html +1340 -702
- package/docs/ko/api.md +375 -0
- package/docs/ko/engine-notes.md +156 -0
- package/docs/ko/readme.md +378 -0
- package/package.json +66 -65
package/dist/compile/check.js
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file compile/check.ts
|
|
3
3
|
* @brief Diagnostic validator function table emitter.
|
|
4
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
5
|
+
* stable across runtime and AOT emission.
|
|
4
6
|
*/
|
|
5
7
|
import { SchemaTag } from "../kind/index.js";
|
|
6
8
|
import { emitArrayCheck, emitDiscriminatedUnionCheck, emitObjectCheck, emitRecordCheck, emitTupleCheck } from "./check-composite.js";
|
|
7
|
-
import { emitLiteralCheck, emitNumberCheck, emitStringCheck } from "./check-scalar.js";
|
|
9
|
+
import { emitDateCheck, emitLiteralCheck, emitNumberCheck, emitStringCheck } from "./check-scalar.js";
|
|
8
10
|
import { pushSchema } from "./context.js";
|
|
9
11
|
import { emitIssue } from "./issue.js";
|
|
10
12
|
import { emitUnion } from "./predicate.js";
|
|
11
13
|
/**
|
|
12
14
|
* @brief emit check function.
|
|
15
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
16
|
+
* stable across runtime and AOT emission.
|
|
17
|
+
* @param schema Schema whose diagnostics should be emitted.
|
|
18
|
+
* @param context Shared code-generation context.
|
|
19
|
+
* @returns Generated diagnostic function name.
|
|
20
|
+
* @invariant The same schema object maps to one diagnostic function per bundle.
|
|
13
21
|
*/
|
|
14
22
|
export function emitCheckFunction(schema, context) {
|
|
15
23
|
const cached = context.checkFunctionNames.get(schema);
|
|
16
24
|
if (cached !== undefined) {
|
|
17
25
|
return cached;
|
|
18
26
|
}
|
|
27
|
+
/*
|
|
28
|
+
* Insert the placeholder before emitting the body. Recursive schemas can
|
|
29
|
+
* request this same function while the current body is still being built.
|
|
30
|
+
*/
|
|
19
31
|
const name = `c${String(context.checkFunctions.length)}`;
|
|
20
32
|
const source = {
|
|
21
33
|
name,
|
|
@@ -28,6 +40,10 @@ export function emitCheckFunction(schema, context) {
|
|
|
28
40
|
}
|
|
29
41
|
/**
|
|
30
42
|
* @brief emit check functions.
|
|
43
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
44
|
+
* stable across runtime and AOT emission.
|
|
45
|
+
* @param context Shared code-generation context with accumulated check sources.
|
|
46
|
+
* @returns Concatenated JavaScript function declarations.
|
|
31
47
|
*/
|
|
32
48
|
export function emitCheckFunctions(context) {
|
|
33
49
|
const chunks = new Array(context.checkFunctions.length);
|
|
@@ -42,6 +58,14 @@ export function emitCheckFunctions(context) {
|
|
|
42
58
|
}
|
|
43
59
|
/**
|
|
44
60
|
* @brief emit check body.
|
|
61
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
62
|
+
* stable across runtime and AOT emission.
|
|
63
|
+
* @param schema Schema represented by this diagnostic body.
|
|
64
|
+
* @param value Generated expression for the candidate value.
|
|
65
|
+
* @param path Generated expression for the mutable path stack.
|
|
66
|
+
* @param issues Generated expression for the issue buffer.
|
|
67
|
+
* @param context Shared code-generation context.
|
|
68
|
+
* @returns JavaScript source for diagnostic collection.
|
|
45
69
|
*/
|
|
46
70
|
function emitCheckBody(schema, value, path, issues, context) {
|
|
47
71
|
switch (schema.tag) {
|
|
@@ -53,6 +77,8 @@ function emitCheckBody(schema, value, path, issues, context) {
|
|
|
53
77
|
return emitStringCheck(schema, value, path, issues, context);
|
|
54
78
|
case SchemaTag.Number:
|
|
55
79
|
return emitNumberCheck(schema, value, path, issues);
|
|
80
|
+
case SchemaTag.Date:
|
|
81
|
+
return emitDateCheck(schema, value, path, issues);
|
|
56
82
|
case SchemaTag.BigInt:
|
|
57
83
|
return `if(typeof ${value}!=="bigint"){${emitIssue(issues, path, "expected_bigint", "bigint", `a(${value})`)}}`;
|
|
58
84
|
case SchemaTag.Symbol:
|
|
@@ -62,11 +88,19 @@ function emitCheckBody(schema, value, path, issues, context) {
|
|
|
62
88
|
case SchemaTag.Literal:
|
|
63
89
|
return emitLiteralCheck(schema.value, value, path, issues, context);
|
|
64
90
|
case SchemaTag.Array:
|
|
65
|
-
return emitArrayCheck(schema
|
|
91
|
+
return emitArrayCheck(schema, value, path, issues, context, emitCheckFunction);
|
|
66
92
|
case SchemaTag.Tuple:
|
|
93
|
+
if (schema.rest !== undefined) {
|
|
94
|
+
return emitDynamicCheck(schema, value, path, issues, context);
|
|
95
|
+
}
|
|
67
96
|
return emitTupleCheck(schema.items, value, path, issues, context, emitCheckFunction);
|
|
68
97
|
case SchemaTag.Record:
|
|
69
98
|
return emitRecordCheck(schema.value, value, path, issues, context, emitCheckFunction);
|
|
99
|
+
case SchemaTag.Map:
|
|
100
|
+
case SchemaTag.Set:
|
|
101
|
+
case SchemaTag.InstanceOf:
|
|
102
|
+
case SchemaTag.Property:
|
|
103
|
+
return emitDynamicCheck(schema, value, path, issues, context);
|
|
70
104
|
case SchemaTag.Object:
|
|
71
105
|
return emitObjectCheck(schema, value, path, issues, context, emitCheckFunction);
|
|
72
106
|
case SchemaTag.Union:
|
|
@@ -87,11 +121,36 @@ function emitCheckBody(schema, value, path, issues, context) {
|
|
|
87
121
|
return emitCheckCall(schema.inner, value, path, issues, context);
|
|
88
122
|
case SchemaTag.Lazy:
|
|
89
123
|
case SchemaTag.Refine:
|
|
90
|
-
|
|
124
|
+
/*
|
|
125
|
+
* Lazy and refine schemas execute runtime logic that cannot be safely
|
|
126
|
+
* inlined into generated source. The `m` helper calls the interpreter
|
|
127
|
+
* diagnostic path through the dynamic schema side table.
|
|
128
|
+
*/
|
|
129
|
+
return emitDynamicCheck(schema, value, path, issues, context);
|
|
91
130
|
}
|
|
92
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* @brief Emit a diagnostic fallback call for runtime-only schema nodes.
|
|
134
|
+
* @param schema Schema captured in the dynamic side table.
|
|
135
|
+
* @param value Generated candidate value expression.
|
|
136
|
+
* @param path Generated path expression.
|
|
137
|
+
* @param issues Generated issue buffer expression.
|
|
138
|
+
* @param context Shared emission context.
|
|
139
|
+
* @returns JavaScript source delegating diagnostics to the interpreter.
|
|
140
|
+
*/
|
|
141
|
+
function emitDynamicCheck(schema, value, path, issues, context) {
|
|
142
|
+
return `m(${String(pushSchema(context, schema))},${value},${path},${issues});`;
|
|
143
|
+
}
|
|
93
144
|
/**
|
|
94
145
|
* @brief emit check call.
|
|
146
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
147
|
+
* stable across runtime and AOT emission.
|
|
148
|
+
* @param schema Child schema to dispatch to.
|
|
149
|
+
* @param value Generated expression for the child value.
|
|
150
|
+
* @param path Generated expression for the mutable path stack.
|
|
151
|
+
* @param issues Generated expression for the issue buffer.
|
|
152
|
+
* @param context Shared code-generation context.
|
|
153
|
+
* @returns JavaScript source for invoking the child diagnostic function.
|
|
95
154
|
*/
|
|
96
155
|
function emitCheckCall(schema, value, path, issues, context) {
|
|
97
156
|
return `${emitCheckFunction(schema, context)}(${value},${path},${issues});`;
|
|
@@ -1,35 +1,73 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file compile/context.ts
|
|
3
3
|
* @brief Generated-source emitter side-table context.
|
|
4
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
5
|
+
* stable across runtime and AOT emission.
|
|
4
6
|
*/
|
|
5
7
|
import type { LiteralValue, Schema } from "../schema/index.js";
|
|
6
|
-
import type { EmitContext } from "./types.js";
|
|
8
|
+
import type { CompileMode, EmitContext } from "./types.js";
|
|
7
9
|
/**
|
|
8
|
-
* @brief
|
|
10
|
+
* @brief Create one mutable source-emission context.
|
|
11
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
12
|
+
* stable across runtime and AOT emission.
|
|
13
|
+
* @param mode Compile mode that controls safety and allocation tradeoffs.
|
|
14
|
+
* @returns Fresh side-table context consumed by predicate and diagnostic emitters.
|
|
15
|
+
* @invariant Side tables are append-only during one bundle emission.
|
|
9
16
|
*/
|
|
10
|
-
export declare function createEmitContext(): EmitContext;
|
|
17
|
+
export declare function createEmitContext(mode: CompileMode): EmitContext;
|
|
11
18
|
/**
|
|
12
|
-
* @brief
|
|
19
|
+
* @brief Append a literal to the generated factory side table.
|
|
20
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
21
|
+
* stable across runtime and AOT emission.
|
|
22
|
+
* @param context Mutable emission context.
|
|
23
|
+
* @param value Literal value referenced by generated source.
|
|
24
|
+
* @returns Index used by generated code to read `l[index]`.
|
|
13
25
|
*/
|
|
14
26
|
export declare function pushLiteral(context: EmitContext, value: LiteralValue): number;
|
|
15
27
|
/**
|
|
16
|
-
* @brief
|
|
28
|
+
* @brief Append a regular expression to the generated factory side table.
|
|
29
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
30
|
+
* stable across runtime and AOT emission.
|
|
31
|
+
* @param context Mutable emission context.
|
|
32
|
+
* @param value Source RegExp from the schema.
|
|
33
|
+
* @returns Index used by generated code to read `r[index]`.
|
|
34
|
+
* @post The stored RegExp is cloned so generated validation does not mutate user state.
|
|
17
35
|
*/
|
|
18
36
|
export declare function pushRegex(context: EmitContext, value: RegExp): number;
|
|
19
37
|
/**
|
|
20
|
-
* @brief
|
|
38
|
+
* @brief Append a keyset to the generated factory side table.
|
|
39
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
40
|
+
* stable across runtime and AOT emission.
|
|
41
|
+
* @param context Mutable emission context.
|
|
42
|
+
* @param value Frozen or caller-owned key list used by object checks.
|
|
43
|
+
* @returns Index used by generated code to read `k[index]`.
|
|
21
44
|
*/
|
|
22
45
|
export declare function pushKeyset(context: EmitContext, value: readonly string[]): number;
|
|
23
46
|
/**
|
|
24
|
-
* @brief string
|
|
47
|
+
* @brief Return a generated expression for a string side-table entry.
|
|
48
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
49
|
+
* stable across runtime and AOT emission.
|
|
50
|
+
* @param context Mutable emission context.
|
|
51
|
+
* @param value String value to intern.
|
|
52
|
+
* @returns Generated expression of the form `u[index]`.
|
|
25
53
|
*/
|
|
26
54
|
export declare function stringRef(context: EmitContext, value: string): string;
|
|
27
55
|
/**
|
|
28
|
-
* @brief
|
|
56
|
+
* @brief Intern a string in the generated factory side table.
|
|
57
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
58
|
+
* stable across runtime and AOT emission.
|
|
59
|
+
* @param context Mutable emission context.
|
|
60
|
+
* @param value String value referenced by generated source.
|
|
61
|
+
* @returns Stable side-table index for the string.
|
|
29
62
|
*/
|
|
30
63
|
export declare function pushString(context: EmitContext, value: string): number;
|
|
31
64
|
/**
|
|
32
|
-
* @brief
|
|
65
|
+
* @brief Append a dynamic schema to the generated factory side table.
|
|
66
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
67
|
+
* stable across runtime and AOT emission.
|
|
68
|
+
* @param context Mutable emission context.
|
|
69
|
+
* @param value Schema used by fallback or lazy generated paths.
|
|
70
|
+
* @returns Index used by generated code to read `d[index]`.
|
|
33
71
|
*/
|
|
34
72
|
export declare function pushSchema(context: EmitContext, value: Schema): number;
|
|
35
73
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/compile/context.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/compile/context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3D;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAgBhE;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,GAAG,MAAM,CAI7E;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAIrE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAIjF;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAErE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAatE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAItE"}
|
package/dist/compile/context.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file compile/context.ts
|
|
3
3
|
* @brief Generated-source emitter side-table context.
|
|
4
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
5
|
+
* stable across runtime and AOT emission.
|
|
4
6
|
*/
|
|
5
7
|
/**
|
|
6
|
-
* @brief
|
|
8
|
+
* @brief Create one mutable source-emission context.
|
|
9
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
10
|
+
* stable across runtime and AOT emission.
|
|
11
|
+
* @param mode Compile mode that controls safety and allocation tradeoffs.
|
|
12
|
+
* @returns Fresh side-table context consumed by predicate and diagnostic emitters.
|
|
13
|
+
* @invariant Side tables are append-only during one bundle emission.
|
|
7
14
|
*/
|
|
8
|
-
export function createEmitContext() {
|
|
15
|
+
export function createEmitContext(mode) {
|
|
9
16
|
return {
|
|
17
|
+
mode,
|
|
10
18
|
literals: [],
|
|
11
19
|
regexps: [],
|
|
12
20
|
keysets: [],
|
|
@@ -16,11 +24,18 @@ export function createEmitContext() {
|
|
|
16
24
|
functionNames: new Map(),
|
|
17
25
|
checkFunctions: [],
|
|
18
26
|
checkFunctionNames: new Map(),
|
|
27
|
+
firstFunctions: [],
|
|
28
|
+
firstFunctionNames: new Map(),
|
|
19
29
|
stringIndexes: new Map()
|
|
20
30
|
};
|
|
21
31
|
}
|
|
22
32
|
/**
|
|
23
|
-
* @brief
|
|
33
|
+
* @brief Append a literal to the generated factory side table.
|
|
34
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
35
|
+
* stable across runtime and AOT emission.
|
|
36
|
+
* @param context Mutable emission context.
|
|
37
|
+
* @param value Literal value referenced by generated source.
|
|
38
|
+
* @returns Index used by generated code to read `l[index]`.
|
|
24
39
|
*/
|
|
25
40
|
export function pushLiteral(context, value) {
|
|
26
41
|
const index = context.literals.length;
|
|
@@ -28,7 +43,13 @@ export function pushLiteral(context, value) {
|
|
|
28
43
|
return index;
|
|
29
44
|
}
|
|
30
45
|
/**
|
|
31
|
-
* @brief
|
|
46
|
+
* @brief Append a regular expression to the generated factory side table.
|
|
47
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
48
|
+
* stable across runtime and AOT emission.
|
|
49
|
+
* @param context Mutable emission context.
|
|
50
|
+
* @param value Source RegExp from the schema.
|
|
51
|
+
* @returns Index used by generated code to read `r[index]`.
|
|
52
|
+
* @post The stored RegExp is cloned so generated validation does not mutate user state.
|
|
32
53
|
*/
|
|
33
54
|
export function pushRegex(context, value) {
|
|
34
55
|
const index = context.regexps.length;
|
|
@@ -36,7 +57,12 @@ export function pushRegex(context, value) {
|
|
|
36
57
|
return index;
|
|
37
58
|
}
|
|
38
59
|
/**
|
|
39
|
-
* @brief
|
|
60
|
+
* @brief Append a keyset to the generated factory side table.
|
|
61
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
62
|
+
* stable across runtime and AOT emission.
|
|
63
|
+
* @param context Mutable emission context.
|
|
64
|
+
* @param value Frozen or caller-owned key list used by object checks.
|
|
65
|
+
* @returns Index used by generated code to read `k[index]`.
|
|
40
66
|
*/
|
|
41
67
|
export function pushKeyset(context, value) {
|
|
42
68
|
const index = context.keysets.length;
|
|
@@ -44,26 +70,45 @@ export function pushKeyset(context, value) {
|
|
|
44
70
|
return index;
|
|
45
71
|
}
|
|
46
72
|
/**
|
|
47
|
-
* @brief string
|
|
73
|
+
* @brief Return a generated expression for a string side-table entry.
|
|
74
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
75
|
+
* stable across runtime and AOT emission.
|
|
76
|
+
* @param context Mutable emission context.
|
|
77
|
+
* @param value String value to intern.
|
|
78
|
+
* @returns Generated expression of the form `u[index]`.
|
|
48
79
|
*/
|
|
49
80
|
export function stringRef(context, value) {
|
|
50
81
|
return `u[${String(pushString(context, value))}]`;
|
|
51
82
|
}
|
|
52
83
|
/**
|
|
53
|
-
* @brief
|
|
84
|
+
* @brief Intern a string in the generated factory side table.
|
|
85
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
86
|
+
* stable across runtime and AOT emission.
|
|
87
|
+
* @param context Mutable emission context.
|
|
88
|
+
* @param value String value referenced by generated source.
|
|
89
|
+
* @returns Stable side-table index for the string.
|
|
54
90
|
*/
|
|
55
91
|
export function pushString(context, value) {
|
|
56
92
|
const cached = context.stringIndexes.get(value);
|
|
57
93
|
if (cached !== undefined) {
|
|
58
94
|
return cached;
|
|
59
95
|
}
|
|
96
|
+
/*
|
|
97
|
+
* String interning keeps generated source small and lets repeated object
|
|
98
|
+
* keys reuse the same frozen path segment cache.
|
|
99
|
+
*/
|
|
60
100
|
const index = context.strings.length;
|
|
61
101
|
context.strings.push(value);
|
|
62
102
|
context.stringIndexes.set(value, index);
|
|
63
103
|
return index;
|
|
64
104
|
}
|
|
65
105
|
/**
|
|
66
|
-
* @brief
|
|
106
|
+
* @brief Append a dynamic schema to the generated factory side table.
|
|
107
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
108
|
+
* stable across runtime and AOT emission.
|
|
109
|
+
* @param context Mutable emission context.
|
|
110
|
+
* @param value Schema used by fallback or lazy generated paths.
|
|
111
|
+
* @returns Index used by generated code to read `d[index]`.
|
|
67
112
|
*/
|
|
68
113
|
export function pushSchema(context, value) {
|
|
69
114
|
const index = context.schemas.length;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file first.ts
|
|
3
|
+
* @brief First-fault diagnostic validator function table emitter.
|
|
4
|
+
* @details Generated first-fault helpers return one frozen issue immediately,
|
|
5
|
+
* keeping hot rejection diagnostics out of the full issue collector.
|
|
6
|
+
*/
|
|
7
|
+
import { type Schema } from "../schema/index.js";
|
|
8
|
+
import type { EmitContext } from "./types.js";
|
|
9
|
+
/**
|
|
10
|
+
* @brief Emit or reuse a first-fault diagnostic function.
|
|
11
|
+
* @details Each schema identity maps to one generated first-fault function so
|
|
12
|
+
* recursive and shared schemas keep stable function identities in source.
|
|
13
|
+
* @param schema Schema whose first diagnostic should be emitted.
|
|
14
|
+
* @param context Shared code-generation context.
|
|
15
|
+
* @returns Generated first-fault function name.
|
|
16
|
+
*/
|
|
17
|
+
export declare function emitFirstFunction(schema: Schema, context: EmitContext): string;
|
|
18
|
+
/**
|
|
19
|
+
* @brief Emit all first-fault diagnostic functions.
|
|
20
|
+
* @details Generated functions return undefined on success or one frozen issue
|
|
21
|
+
* on failure. They never allocate an issue array.
|
|
22
|
+
* @param context Shared code-generation context with accumulated sources.
|
|
23
|
+
* @returns Concatenated JavaScript function declarations.
|
|
24
|
+
*/
|
|
25
|
+
export declare function emitFirstFunctions(context: EmitContext): string;
|
|
26
|
+
//# sourceMappingURL=first.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"first.d.ts","sourceRoot":"","sources":["../../src/compile/first.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,OAAO,EAYH,KAAK,MAAM,EACd,MAAM,oBAAoB,CAAC;AAS5B,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,YAAY,CAAC;AAE9D;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAc9E;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAS/D"}
|