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,12 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file schema-predicate.ts
|
|
3
3
|
* @brief Schema-specialized predicate kernels for validation plans.
|
|
4
|
+
* @details Plan helpers keep schema-specialized execution aligned with optimized IR while
|
|
5
|
+
* preserving interpreter parity.
|
|
4
6
|
*/
|
|
5
7
|
import { NumberCheckTag, ObjectModeTag, PresenceTag, SchemaTag, StringCheckTag } from "../kind/index.js";
|
|
6
|
-
import { UUID_PATTERN, resolveLazySchema } from "../schema/index.js";
|
|
7
|
-
import { findDiscriminatedUnionCase, hasObjectKey, isDataPropertyDescriptor, isPlainRecord, readOwnDataProperty } from "../evaluate/shared.js";
|
|
8
|
+
import { UUID_PATTERN, resolveLazySchema, schemaCanAcceptUndefined } from "../schema/index.js";
|
|
9
|
+
import { findDiscriminatedUnionCase, hasObjectKey, isArrayIndexKey, isDataPropertyDescriptor, isPlainRecord, readOwnDataProperty } from "../evaluate/shared.js";
|
|
8
10
|
/**
|
|
9
11
|
* @brief execute schema kernel.
|
|
12
|
+
* @details Plan helpers keep schema-specialized execution aligned with optimized IR while
|
|
13
|
+
* preserving interpreter parity.
|
|
10
14
|
*/
|
|
11
15
|
export function executeSchemaKernel(schema, value, state, runChild) {
|
|
12
16
|
switch (schema.tag) {
|
|
@@ -56,7 +60,12 @@ export function executeSchemaKernel(schema, value, state, runChild) {
|
|
|
56
60
|
}
|
|
57
61
|
}
|
|
58
62
|
/**
|
|
59
|
-
* @brief
|
|
63
|
+
* @brief Execute a string schema against one runtime value.
|
|
64
|
+
* @param schema String schema with normalized checks.
|
|
65
|
+
* @param value Candidate runtime value.
|
|
66
|
+
* @returns True when the value is a string and every string check passes.
|
|
67
|
+
* @details Regex state is reset around each test so global or sticky patterns do
|
|
68
|
+
* not leak `lastIndex` across validation calls.
|
|
60
69
|
*/
|
|
61
70
|
function isStringSchema(schema, value) {
|
|
62
71
|
if (typeof value !== "string") {
|
|
@@ -98,7 +107,12 @@ function isStringSchema(schema, value) {
|
|
|
98
107
|
return true;
|
|
99
108
|
}
|
|
100
109
|
/**
|
|
101
|
-
* @brief
|
|
110
|
+
* @brief Execute a number schema against one runtime value.
|
|
111
|
+
* @details Plan helpers keep schema-specialized execution aligned with optimized IR while
|
|
112
|
+
* preserving interpreter parity.
|
|
113
|
+
* @param schema Number schema with normalized checks.
|
|
114
|
+
* @param value Candidate runtime value.
|
|
115
|
+
* @returns True when the value is finite and satisfies every numeric check.
|
|
102
116
|
*/
|
|
103
117
|
function isNumberSchema(schema, value) {
|
|
104
118
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
@@ -131,12 +145,26 @@ function isNumberSchema(schema, value) {
|
|
|
131
145
|
return true;
|
|
132
146
|
}
|
|
133
147
|
/**
|
|
134
|
-
* @brief
|
|
148
|
+
* @brief Execute array validation with sparse-slot semantics.
|
|
149
|
+
* @details Plan helpers keep schema-specialized execution aligned with optimized IR while
|
|
150
|
+
* preserving interpreter parity.
|
|
151
|
+
* @param item Schema applied to each logical array slot.
|
|
152
|
+
* @param value Candidate value supplied by the caller.
|
|
153
|
+
* @param state Shared recursion and cycle state.
|
|
154
|
+
* @param runChild Dispatcher for nested schema predicates.
|
|
155
|
+
* @returns True when the value satisfies the array schema.
|
|
135
156
|
*/
|
|
136
157
|
function isArraySchema(item, value, state, runChild) {
|
|
137
158
|
if (!Array.isArray(value)) {
|
|
138
159
|
return false;
|
|
139
160
|
}
|
|
161
|
+
if (schemaCanAcceptUndefined(item)) {
|
|
162
|
+
/*
|
|
163
|
+
* Undefined-valid item schemas make holes valid. Use the present-index
|
|
164
|
+
* walker so sparse arrays do not pay for absent slots.
|
|
165
|
+
*/
|
|
166
|
+
return isPresentArraySchema(item, value, state, runChild);
|
|
167
|
+
}
|
|
140
168
|
for (let index = 0; index < value.length; index += 1) {
|
|
141
169
|
const property = readArrayIndexDataProperty(value, index);
|
|
142
170
|
if (property === null ||
|
|
@@ -147,7 +175,42 @@ function isArraySchema(item, value, state, runChild) {
|
|
|
147
175
|
return true;
|
|
148
176
|
}
|
|
149
177
|
/**
|
|
150
|
-
* @brief
|
|
178
|
+
* @brief Validate only present indexes for undefined-accepting item schemas.
|
|
179
|
+
* @details Skips holes only when `undefined` is already accepted by the item schema.
|
|
180
|
+
* @param item Schema applied to each present own index.
|
|
181
|
+
* @param value Array already proven by the caller.
|
|
182
|
+
* @param state Shared recursion and cycle state.
|
|
183
|
+
* @param runChild Dispatcher for nested schema predicates.
|
|
184
|
+
* @returns True when every present own index satisfies the item schema.
|
|
185
|
+
*/
|
|
186
|
+
function isPresentArraySchema(item, value, state, runChild) {
|
|
187
|
+
const keys = Object.getOwnPropertyNames(value);
|
|
188
|
+
for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
|
|
189
|
+
const key = keys[keyIndex];
|
|
190
|
+
if (key === undefined || !isArrayIndexKey(key, value.length)) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
/*
|
|
194
|
+
* Accessor-backed present indexes are rejected here because reading them
|
|
195
|
+
* would run user code and break the safe validation boundary.
|
|
196
|
+
*/
|
|
197
|
+
const property = readArrayKeyDataProperty(value, key);
|
|
198
|
+
if (property === null ||
|
|
199
|
+
(property !== undefined && !runChild(item, property.value, state))) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* @brief Execute fixed-arity tuple validation.
|
|
207
|
+
* @details Plan helpers keep schema-specialized execution aligned with optimized IR while
|
|
208
|
+
* preserving interpreter parity.
|
|
209
|
+
* @param items Schema for each tuple index.
|
|
210
|
+
* @param value Candidate runtime value.
|
|
211
|
+
* @param state Shared recursion and cycle state.
|
|
212
|
+
* @param runChild Dispatcher for nested schema predicates.
|
|
213
|
+
* @returns True when length and every indexed item match exactly.
|
|
151
214
|
*/
|
|
152
215
|
function isTupleSchema(items, value, state, runChild) {
|
|
153
216
|
if (!Array.isArray(value) || value.length !== items.length) {
|
|
@@ -165,10 +228,26 @@ function isTupleSchema(items, value, state, runChild) {
|
|
|
165
228
|
return true;
|
|
166
229
|
}
|
|
167
230
|
/**
|
|
168
|
-
* @brief
|
|
231
|
+
* @brief Read one tuple or dense-array index through a descriptor.
|
|
232
|
+
* @details Plan helpers keep schema-specialized execution aligned with optimized IR while
|
|
233
|
+
* preserving interpreter parity.
|
|
234
|
+
* @param value Array being inspected.
|
|
235
|
+
* @param index Numeric index.
|
|
236
|
+
* @returns Data descriptor, undefined for a hole, or null for an accessor slot.
|
|
169
237
|
*/
|
|
170
238
|
function readArrayIndexDataProperty(value, index) {
|
|
171
|
-
|
|
239
|
+
return readArrayKeyDataProperty(value, String(index));
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* @brief Read one canonical array index key without executing accessors.
|
|
243
|
+
* @details Plan helpers keep schema-specialized execution aligned with optimized IR while
|
|
244
|
+
* preserving interpreter parity.
|
|
245
|
+
* @param value Array being inspected.
|
|
246
|
+
* @param key Canonical array index key.
|
|
247
|
+
* @returns Data descriptor, undefined for a hole, or null for an accessor slot.
|
|
248
|
+
*/
|
|
249
|
+
function readArrayKeyDataProperty(value, key) {
|
|
250
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
172
251
|
if (descriptor === undefined) {
|
|
173
252
|
return undefined;
|
|
174
253
|
}
|
|
@@ -178,7 +257,8 @@ function readArrayIndexDataProperty(value, index) {
|
|
|
178
257
|
return descriptor;
|
|
179
258
|
}
|
|
180
259
|
/**
|
|
181
|
-
* @brief
|
|
260
|
+
* @brief Check record schema.
|
|
261
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
182
262
|
*/
|
|
183
263
|
function isRecordSchema(item, value, state, runChild) {
|
|
184
264
|
if (!isPlainRecord(value)) {
|
|
@@ -198,7 +278,15 @@ function isRecordSchema(item, value, state, runChild) {
|
|
|
198
278
|
return true;
|
|
199
279
|
}
|
|
200
280
|
/**
|
|
201
|
-
* @brief
|
|
281
|
+
* @brief Execute object schema validation.
|
|
282
|
+
* @param schema Object schema with ordered entries and strict-mode lookup.
|
|
283
|
+
* @param value Candidate runtime value.
|
|
284
|
+
* @param state Shared recursion and cycle state.
|
|
285
|
+
* @param runChild Dispatcher for nested property schemas.
|
|
286
|
+
* @returns True when required/optional fields and strict-key rules pass.
|
|
287
|
+
* @details Required properties are read through descriptors. In strict mode, the
|
|
288
|
+
* all-required path can compare own key counts; optional shapes must inspect
|
|
289
|
+
* each key so extra symbol or undeclared string keys fail closed.
|
|
202
290
|
*/
|
|
203
291
|
function isObjectSchema(schema, value, state, runChild) {
|
|
204
292
|
if (!isPlainRecord(value)) {
|
|
@@ -243,7 +331,14 @@ function isObjectSchema(schema, value, state, runChild) {
|
|
|
243
331
|
return true;
|
|
244
332
|
}
|
|
245
333
|
/**
|
|
246
|
-
* @brief
|
|
334
|
+
* @brief Execute a general union by probing options in order.
|
|
335
|
+
* @details Plan helpers keep schema-specialized execution aligned with optimized IR while
|
|
336
|
+
* preserving interpreter parity.
|
|
337
|
+
* @param options Union option schemas.
|
|
338
|
+
* @param value Candidate runtime value.
|
|
339
|
+
* @param state Shared recursion and cycle state.
|
|
340
|
+
* @param runChild Dispatcher for nested option schemas.
|
|
341
|
+
* @returns True when at least one option accepts the value.
|
|
247
342
|
*/
|
|
248
343
|
function isUnionSchema(options, value, state, runChild) {
|
|
249
344
|
for (let index = 0; index < options.length; index += 1) {
|
|
@@ -255,7 +350,15 @@ function isUnionSchema(options, value, state, runChild) {
|
|
|
255
350
|
return false;
|
|
256
351
|
}
|
|
257
352
|
/**
|
|
258
|
-
* @brief
|
|
353
|
+
* @brief Execute a discriminated union through its tag field.
|
|
354
|
+
* @details Plan helpers keep schema-specialized execution aligned with optimized IR while
|
|
355
|
+
* preserving interpreter parity.
|
|
356
|
+
* @param key Discriminant property name.
|
|
357
|
+
* @param cases Closed case table.
|
|
358
|
+
* @param value Candidate runtime value.
|
|
359
|
+
* @param state Shared recursion and cycle state.
|
|
360
|
+
* @param runChild Dispatcher for selected case schema.
|
|
361
|
+
* @returns True when the discriminant is a string and the selected case passes.
|
|
259
362
|
*/
|
|
260
363
|
function isDiscriminatedUnionSchema(key, cases, value, state, runChild) {
|
|
261
364
|
if (!isPlainRecord(value)) {
|
|
@@ -270,7 +373,8 @@ function isDiscriminatedUnionSchema(key, cases, value, state, runChild) {
|
|
|
270
373
|
return selected !== undefined && runChild(selected, value, state);
|
|
271
374
|
}
|
|
272
375
|
/**
|
|
273
|
-
* @brief
|
|
376
|
+
* @brief Check strict true.
|
|
377
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
274
378
|
*/
|
|
275
379
|
function isStrictTrue(value) {
|
|
276
380
|
return value === true;
|
package/dist/plan/types.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file types.ts
|
|
3
3
|
* @brief Optimized validation plan contracts.
|
|
4
|
+
* @details Plan helpers keep schema-specialized execution aligned with optimized IR while
|
|
5
|
+
* preserving interpreter parity.
|
|
4
6
|
*/
|
|
5
7
|
import type { Graph } from "../ir/index.js";
|
|
6
8
|
import type { Schema } from "../schema/index.js";
|
package/dist/plan/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plan/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plan/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;CACrC"}
|
package/dist/plan/types.js
CHANGED
package/dist/result/index.d.ts
CHANGED
|
@@ -1,27 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @brief
|
|
2
|
+
* @brief Explicit success-or-failure value used instead of implicit exceptions.
|
|
3
|
+
* @details Public validators return Result so failure is visible in the type
|
|
4
|
+
* system and callers must handle diagnostics deliberately.
|
|
3
5
|
*/
|
|
4
6
|
export type Result<TValue, TError> = Ok<TValue> | Err<TError>;
|
|
5
7
|
/**
|
|
6
|
-
* @brief
|
|
8
|
+
* @brief Successful Result variant.
|
|
9
|
+
* @details The payload is named `value` so consumers can destructure success
|
|
10
|
+
* without colliding with the failure-side `error` field.
|
|
7
11
|
*/
|
|
8
12
|
export interface Ok<TValue> {
|
|
9
13
|
readonly ok: true;
|
|
10
14
|
readonly value: TValue;
|
|
11
15
|
}
|
|
12
16
|
/**
|
|
13
|
-
* @brief
|
|
17
|
+
* @brief Failed Result variant.
|
|
18
|
+
* @details Errors remain typed payloads rather than thrown control flow, which
|
|
19
|
+
* keeps validation and decoding APIs predictable under composition.
|
|
14
20
|
*/
|
|
15
21
|
export interface Err<TError> {
|
|
16
22
|
readonly ok: false;
|
|
17
23
|
readonly error: TError;
|
|
18
24
|
}
|
|
19
25
|
/**
|
|
20
|
-
* @brief
|
|
26
|
+
* @brief Construct a frozen successful Result.
|
|
27
|
+
* @details Result helpers keep success and failure explicit in value space instead of
|
|
28
|
+
* relying on implicit control flow.
|
|
29
|
+
* @param value Value produced by a successful operation.
|
|
30
|
+
* @returns Immutable success variant.
|
|
21
31
|
*/
|
|
22
32
|
export declare function ok<TValue>(value: TValue): Result<TValue, never>;
|
|
23
33
|
/**
|
|
24
|
-
* @brief
|
|
34
|
+
* @brief Construct a frozen failed Result.
|
|
35
|
+
* @details Result helpers keep success and failure explicit in value space instead of
|
|
36
|
+
* relying on implicit control flow.
|
|
37
|
+
* @param error Typed failure payload.
|
|
38
|
+
* @returns Immutable failure variant.
|
|
25
39
|
*/
|
|
26
40
|
export declare function err<TError>(error: TError): Result<never, TError>;
|
|
27
41
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/result/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/result/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,IAC3B,EAAE,CAAC,MAAM,CAAC,GACV,GAAG,CAAC,MAAM,CAAC,CAAC;AAElB;;;;GAIG;AACH,MAAM,WAAW,EAAE,CAAC,MAAM;IACtB,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CAC1B;AAED;;;;GAIG;AACH,MAAM,WAAW,GAAG,CAAC,MAAM;IACvB,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,wBAAgB,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAM/D;AAED;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAMhE"}
|
package/dist/result/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @brief
|
|
2
|
+
* @brief Construct a frozen successful Result.
|
|
3
|
+
* @details Result helpers keep success and failure explicit in value space instead of
|
|
4
|
+
* relying on implicit control flow.
|
|
5
|
+
* @param value Value produced by a successful operation.
|
|
6
|
+
* @returns Immutable success variant.
|
|
3
7
|
*/
|
|
4
8
|
export function ok(value) {
|
|
5
9
|
const result = {
|
|
@@ -9,7 +13,11 @@ export function ok(value) {
|
|
|
9
13
|
return Object.freeze(result);
|
|
10
14
|
}
|
|
11
15
|
/**
|
|
12
|
-
* @brief
|
|
16
|
+
* @brief Construct a frozen failed Result.
|
|
17
|
+
* @details Result helpers keep success and failure explicit in value space instead of
|
|
18
|
+
* relying on implicit control flow.
|
|
19
|
+
* @param error Typed failure payload.
|
|
20
|
+
* @returns Immutable failure variant.
|
|
13
21
|
*/
|
|
14
22
|
export function err(error) {
|
|
15
23
|
const result = {
|
package/dist/schema/common.d.ts
CHANGED
|
@@ -1,30 +1,93 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file schema/common.ts
|
|
3
3
|
* @brief Private schema shape predicates.
|
|
4
|
+
* @details Schema helpers enforce construction-time invariants before values reach
|
|
5
|
+
* validation, compilation, or export.
|
|
4
6
|
*/
|
|
5
7
|
import type { ObjectKeyLookup } from "./types.js";
|
|
6
8
|
/**
|
|
7
|
-
* @brief
|
|
9
|
+
* @brief Sentinel for a missing own data slot.
|
|
10
|
+
* @details `undefined` is a valid schema literal, so absence needs a distinct
|
|
11
|
+
* value that cannot collide with user-authored schema data.
|
|
12
|
+
*/
|
|
13
|
+
declare const missingDataProperty: unique symbol;
|
|
14
|
+
/**
|
|
15
|
+
* @brief Test whether a schema field read observed the sentinel.
|
|
16
|
+
* @details Schema helpers enforce construction-time invariants before values reach
|
|
17
|
+
* validation, compilation, or export.
|
|
18
|
+
* @param value Candidate field value returned by readOwnDataProperty.
|
|
19
|
+
* @returns True when the caller must treat the schema field as absent.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isMissingDataProperty(value: unknown): value is typeof missingDataProperty;
|
|
22
|
+
/**
|
|
23
|
+
* @brief Check that an object owns a concrete data descriptor.
|
|
24
|
+
* @param value Object whose descriptor table is being inspected.
|
|
25
|
+
* @param key Field name or symbol.
|
|
26
|
+
* @returns True only when the field exists directly on the object as data.
|
|
27
|
+
* @details Schema records are consumed across public boundaries. Descriptor
|
|
28
|
+
* reads avoid invoking accessors and avoid accepting prototype-backed fields.
|
|
29
|
+
*/
|
|
30
|
+
export declare function hasOwnDataProperty(value: object, key: PropertyKey): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* @brief Read one own schema data slot without consulting the prototype chain.
|
|
33
|
+
* @param value Object carrying a schema record.
|
|
34
|
+
* @param key Field name or symbol to read.
|
|
35
|
+
* @returns The stored value, or the missing-data sentinel.
|
|
36
|
+
* @details Callers must not use bracket reads on untrusted schema-like objects:
|
|
37
|
+
* a forged prototype getter could execute code or change validation meaning.
|
|
38
|
+
*/
|
|
39
|
+
export declare function readOwnDataProperty(value: object, key: PropertyKey): unknown;
|
|
40
|
+
/**
|
|
41
|
+
* @brief Accept object records suitable for schema metadata traversal.
|
|
42
|
+
* @details Schema helpers enforce construction-time invariants before values reach
|
|
43
|
+
* validation, compilation, or export.
|
|
44
|
+
* @param value Candidate schema record.
|
|
45
|
+
* @returns True for non-array objects whose own fields are all data slots.
|
|
8
46
|
*/
|
|
9
47
|
export declare function isRecord(value: unknown): value is Readonly<Record<string, unknown>>;
|
|
10
48
|
/**
|
|
11
|
-
* @brief
|
|
49
|
+
* @brief Accept dense arrays whose slots can be read without side effects.
|
|
50
|
+
* @param value Candidate schema vector.
|
|
51
|
+
* @returns True for arrays with only own data descriptors and no holes.
|
|
52
|
+
* @details Schema vectors such as `checks`, `entries`, and `options` are arena
|
|
53
|
+
* metadata. Holes and inherited slots would make validation depend on array
|
|
54
|
+
* prototype state, so they are rejected at the boundary.
|
|
12
55
|
*/
|
|
13
56
|
export declare function isUnknownArray(value: unknown): value is readonly unknown[];
|
|
14
57
|
/**
|
|
15
|
-
* @brief
|
|
58
|
+
* @brief Accept only unmodified RegExp instances in schema records.
|
|
59
|
+
* @param value Candidate pattern object.
|
|
60
|
+
* @returns True for a plain RegExp with no own behavioral overrides.
|
|
61
|
+
* @details Regex checks are copied into generated and interpreted validators.
|
|
62
|
+
* Rejecting own overrides prevents later mutation of `exec`, `test`, `source`,
|
|
63
|
+
* or `flags` from changing stored schema behavior.
|
|
16
64
|
*/
|
|
17
65
|
export declare function isPlainRegExp(value: unknown): value is RegExp;
|
|
18
66
|
/**
|
|
19
|
-
* @brief
|
|
67
|
+
* @brief Validate a dense vector of object shape keys.
|
|
68
|
+
* @details Schema helpers enforce construction-time invariants before values reach
|
|
69
|
+
* validation, compilation, or export.
|
|
70
|
+
* @param value Candidate key vector.
|
|
71
|
+
* @returns True when every slot is a string.
|
|
20
72
|
*/
|
|
21
73
|
export declare function isStringArray(value: unknown): value is readonly string[];
|
|
22
74
|
/**
|
|
23
|
-
* @brief
|
|
75
|
+
* @brief Validate the O(1) lookup table paired with object schema keys.
|
|
76
|
+
* @param value Candidate null or plain object lookup.
|
|
77
|
+
* @param keys Ordered key vector from the same object schema.
|
|
78
|
+
* @returns True when the lookup contains exactly the listed keys mapped to true.
|
|
79
|
+
* @details The lookup and key vector must agree so strict-object validation can
|
|
80
|
+
* reject extra keys without rebuilding a membership set at runtime.
|
|
24
81
|
*/
|
|
25
82
|
export declare function isObjectKeyLookup(value: unknown, keys: readonly string[]): value is ObjectKeyLookup;
|
|
26
83
|
/**
|
|
27
|
-
* @brief
|
|
84
|
+
* @brief Linear membership check for short schema-owned string vectors.
|
|
85
|
+
* @param values Trusted frozen vector.
|
|
86
|
+
* @param value Candidate string.
|
|
87
|
+
* @returns True when the candidate appears in the vector.
|
|
88
|
+
* @details These vectors are small and validation-time only; a loop avoids
|
|
89
|
+
* allocating transient Set objects while preserving deterministic order.
|
|
28
90
|
*/
|
|
29
91
|
export declare function includesString(values: readonly string[], value: string): boolean;
|
|
92
|
+
export {};
|
|
30
93
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/schema/common.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/schema/common.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;GAIG;AACH,QAAA,MAAM,mBAAmB,eAAwC,CAAC;AAElE;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACjC,KAAK,EAAE,OAAO,GACf,KAAK,IAAI,OAAO,mBAAmB,CAErC;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAC9B,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,WAAW,GACjB,OAAO,CAIT;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAC/B,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,WAAW,GACjB,OAAO,CAOT;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAKnF;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,OAAO,EAAE,CAI1E;AA2CD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAO7D;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,MAAM,EAAE,CAUxE;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC7B,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,SAAS,MAAM,EAAE,GACxB,KAAK,IAAI,eAAe,CAqB1B;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAOhF"}
|
package/dist/schema/common.js
CHANGED
|
@@ -1,9 +1,60 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file schema/common.ts
|
|
3
3
|
* @brief Private schema shape predicates.
|
|
4
|
+
* @details Schema helpers enforce construction-time invariants before values reach
|
|
5
|
+
* validation, compilation, or export.
|
|
4
6
|
*/
|
|
5
7
|
/**
|
|
6
|
-
* @brief
|
|
8
|
+
* @brief Sentinel for a missing own data slot.
|
|
9
|
+
* @details `undefined` is a valid schema literal, so absence needs a distinct
|
|
10
|
+
* value that cannot collide with user-authored schema data.
|
|
11
|
+
*/
|
|
12
|
+
const missingDataProperty = Symbol("typesea.missingDataProperty");
|
|
13
|
+
/**
|
|
14
|
+
* @brief Test whether a schema field read observed the sentinel.
|
|
15
|
+
* @details Schema helpers enforce construction-time invariants before values reach
|
|
16
|
+
* validation, compilation, or export.
|
|
17
|
+
* @param value Candidate field value returned by readOwnDataProperty.
|
|
18
|
+
* @returns True when the caller must treat the schema field as absent.
|
|
19
|
+
*/
|
|
20
|
+
export function isMissingDataProperty(value) {
|
|
21
|
+
return value === missingDataProperty;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @brief Check that an object owns a concrete data descriptor.
|
|
25
|
+
* @param value Object whose descriptor table is being inspected.
|
|
26
|
+
* @param key Field name or symbol.
|
|
27
|
+
* @returns True only when the field exists directly on the object as data.
|
|
28
|
+
* @details Schema records are consumed across public boundaries. Descriptor
|
|
29
|
+
* reads avoid invoking accessors and avoid accepting prototype-backed fields.
|
|
30
|
+
*/
|
|
31
|
+
export function hasOwnDataProperty(value, key) {
|
|
32
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
33
|
+
return descriptor !== undefined &&
|
|
34
|
+
Object.prototype.hasOwnProperty.call(descriptor, "value");
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @brief Read one own schema data slot without consulting the prototype chain.
|
|
38
|
+
* @param value Object carrying a schema record.
|
|
39
|
+
* @param key Field name or symbol to read.
|
|
40
|
+
* @returns The stored value, or the missing-data sentinel.
|
|
41
|
+
* @details Callers must not use bracket reads on untrusted schema-like objects:
|
|
42
|
+
* a forged prototype getter could execute code or change validation meaning.
|
|
43
|
+
*/
|
|
44
|
+
export function readOwnDataProperty(value, key) {
|
|
45
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
46
|
+
if (descriptor === undefined ||
|
|
47
|
+
!Object.prototype.hasOwnProperty.call(descriptor, "value")) {
|
|
48
|
+
return missingDataProperty;
|
|
49
|
+
}
|
|
50
|
+
return descriptor.value;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @brief Accept object records suitable for schema metadata traversal.
|
|
54
|
+
* @details Schema helpers enforce construction-time invariants before values reach
|
|
55
|
+
* validation, compilation, or export.
|
|
56
|
+
* @param value Candidate schema record.
|
|
57
|
+
* @returns True for non-array objects whose own fields are all data slots.
|
|
7
58
|
*/
|
|
8
59
|
export function isRecord(value) {
|
|
9
60
|
return typeof value === "object" &&
|
|
@@ -12,14 +63,23 @@ export function isRecord(value) {
|
|
|
12
63
|
hasOnlyDataProperties(value);
|
|
13
64
|
}
|
|
14
65
|
/**
|
|
15
|
-
* @brief
|
|
66
|
+
* @brief Accept dense arrays whose slots can be read without side effects.
|
|
67
|
+
* @param value Candidate schema vector.
|
|
68
|
+
* @returns True for arrays with only own data descriptors and no holes.
|
|
69
|
+
* @details Schema vectors such as `checks`, `entries`, and `options` are arena
|
|
70
|
+
* metadata. Holes and inherited slots would make validation depend on array
|
|
71
|
+
* prototype state, so they are rejected at the boundary.
|
|
16
72
|
*/
|
|
17
73
|
export function isUnknownArray(value) {
|
|
18
|
-
return Array.isArray(value) &&
|
|
74
|
+
return Array.isArray(value) &&
|
|
75
|
+
hasOnlyDataProperties(value) &&
|
|
76
|
+
hasDenseDataSlots(value);
|
|
19
77
|
}
|
|
20
78
|
/**
|
|
21
|
-
* @brief
|
|
22
|
-
* @details
|
|
79
|
+
* @brief Reject accessor descriptors before schema internals read fields.
|
|
80
|
+
* @details Schema helpers enforce construction-time invariants before values reach
|
|
81
|
+
* validation, compilation, or export.
|
|
82
|
+
* @param value Object whose own descriptor table is inspected.
|
|
23
83
|
* @returns True when every own property is backed by a data slot.
|
|
24
84
|
*/
|
|
25
85
|
function hasOnlyDataProperties(value) {
|
|
@@ -40,7 +100,27 @@ function hasOnlyDataProperties(value) {
|
|
|
40
100
|
return true;
|
|
41
101
|
}
|
|
42
102
|
/**
|
|
43
|
-
* @brief
|
|
103
|
+
* @brief Require array indexes from 0 to length - 1 to be own data slots.
|
|
104
|
+
* @details Schema helpers enforce construction-time invariants before values reach
|
|
105
|
+
* validation, compilation, or export.
|
|
106
|
+
* @param value Candidate schema vector.
|
|
107
|
+
* @returns True when no sparse or prototype-backed index is present.
|
|
108
|
+
*/
|
|
109
|
+
function hasDenseDataSlots(value) {
|
|
110
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
111
|
+
if (!hasOwnDataProperty(value, String(index))) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* @brief Accept only unmodified RegExp instances in schema records.
|
|
119
|
+
* @param value Candidate pattern object.
|
|
120
|
+
* @returns True for a plain RegExp with no own behavioral overrides.
|
|
121
|
+
* @details Regex checks are copied into generated and interpreted validators.
|
|
122
|
+
* Rejecting own overrides prevents later mutation of `exec`, `test`, `source`,
|
|
123
|
+
* or `flags` from changing stored schema behavior.
|
|
44
124
|
*/
|
|
45
125
|
export function isPlainRegExp(value) {
|
|
46
126
|
return value instanceof RegExp &&
|
|
@@ -51,7 +131,11 @@ export function isPlainRegExp(value) {
|
|
|
51
131
|
!Object.prototype.hasOwnProperty.call(value, "flags");
|
|
52
132
|
}
|
|
53
133
|
/**
|
|
54
|
-
* @brief
|
|
134
|
+
* @brief Validate a dense vector of object shape keys.
|
|
135
|
+
* @details Schema helpers enforce construction-time invariants before values reach
|
|
136
|
+
* validation, compilation, or export.
|
|
137
|
+
* @param value Candidate key vector.
|
|
138
|
+
* @returns True when every slot is a string.
|
|
55
139
|
*/
|
|
56
140
|
export function isStringArray(value) {
|
|
57
141
|
if (!isUnknownArray(value)) {
|
|
@@ -65,7 +149,12 @@ export function isStringArray(value) {
|
|
|
65
149
|
return true;
|
|
66
150
|
}
|
|
67
151
|
/**
|
|
68
|
-
* @brief
|
|
152
|
+
* @brief Validate the O(1) lookup table paired with object schema keys.
|
|
153
|
+
* @param value Candidate null or plain object lookup.
|
|
154
|
+
* @param keys Ordered key vector from the same object schema.
|
|
155
|
+
* @returns True when the lookup contains exactly the listed keys mapped to true.
|
|
156
|
+
* @details The lookup and key vector must agree so strict-object validation can
|
|
157
|
+
* reject extra keys without rebuilding a membership set at runtime.
|
|
69
158
|
*/
|
|
70
159
|
export function isObjectKeyLookup(value, keys) {
|
|
71
160
|
if (!isRecord(value)) {
|
|
@@ -77,7 +166,7 @@ export function isObjectKeyLookup(value, keys) {
|
|
|
77
166
|
}
|
|
78
167
|
for (let index = 0; index < keys.length; index += 1) {
|
|
79
168
|
const key = keys[index];
|
|
80
|
-
if (key === undefined || value
|
|
169
|
+
if (key === undefined || readOwnDataProperty(value, key) !== true) {
|
|
81
170
|
return false;
|
|
82
171
|
}
|
|
83
172
|
}
|
|
@@ -90,7 +179,12 @@ export function isObjectKeyLookup(value, keys) {
|
|
|
90
179
|
return true;
|
|
91
180
|
}
|
|
92
181
|
/**
|
|
93
|
-
* @brief
|
|
182
|
+
* @brief Linear membership check for short schema-owned string vectors.
|
|
183
|
+
* @param values Trusted frozen vector.
|
|
184
|
+
* @param value Candidate string.
|
|
185
|
+
* @returns True when the candidate appears in the vector.
|
|
186
|
+
* @details These vectors are small and validation-time only; a loop avoids
|
|
187
|
+
* allocating transient Set objects while preserving deterministic order.
|
|
94
188
|
*/
|
|
95
189
|
export function includesString(values, value) {
|
|
96
190
|
for (let index = 0; index < values.length; index += 1) {
|
package/dist/schema/freeze.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file schema/freeze.ts
|
|
3
3
|
* @brief Schema freezing and collection hardening.
|
|
4
|
+
* @details Freezing hardens builder output before execution engines or exporters rely on
|
|
5
|
+
* schema identity and shape stability.
|
|
4
6
|
*/
|
|
5
7
|
import type { Schema } from "./types.js";
|
|
6
8
|
/**
|
|
7
9
|
* @brief freeze schema.
|
|
10
|
+
* @details Freezing hardens builder output before execution engines or exporters rely on
|
|
11
|
+
* schema identity and shape stability.
|
|
8
12
|
*/
|
|
9
13
|
export declare function freezeSchema(schema: Schema): Schema;
|
|
10
14
|
//# sourceMappingURL=freeze.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"freeze.d.ts","sourceRoot":"","sources":["../../src/schema/freeze.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"freeze.d.ts","sourceRoot":"","sources":["../../src/schema/freeze.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAGR,MAAM,EAGT,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD"}
|