typesea 0.2.0 → 0.3.1
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 +40 -0
- package/README.md +104 -41
- package/SECURITY.md +52 -0
- package/dist/aot/index.d.ts +1 -1
- package/dist/aot/index.d.ts.map +1 -1
- package/dist/aot/index.js +22 -3
- package/dist/builders/composite.d.ts +6 -3
- package/dist/builders/composite.d.ts.map +1 -1
- package/dist/builders/composite.js +22 -13
- package/dist/builders/index.d.ts +6 -5
- package/dist/builders/index.d.ts.map +1 -1
- package/dist/builders/index.js +5 -4
- package/dist/builders/modifier.d.ts +6 -0
- package/dist/builders/modifier.d.ts.map +1 -1
- package/dist/builders/modifier.js +14 -0
- package/dist/builders/object/guard.d.ts +54 -2
- package/dist/builders/object/guard.d.ts.map +1 -1
- package/dist/builders/object/guard.js +117 -7
- package/dist/builders/object/index.d.ts +2 -2
- package/dist/builders/object/index.d.ts.map +1 -1
- package/dist/builders/object/index.js +1 -1
- package/dist/builders/object/schema.d.ts +33 -2
- package/dist/builders/object/schema.d.ts.map +1 -1
- package/dist/builders/object/schema.js +198 -8
- package/dist/builders/object/types.d.ts +15 -0
- package/dist/builders/object/types.d.ts.map +1 -1
- 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 +20 -1
- package/dist/builders/scalar.d.ts.map +1 -1
- package/dist/builders/scalar.js +54 -1
- package/dist/builders/table.d.ts +31 -5
- package/dist/builders/table.d.ts.map +1 -1
- package/dist/builders/table.js +31 -5
- package/dist/builders/types.d.ts +6 -0
- package/dist/builders/types.d.ts.map +1 -1
- package/dist/compile/check-composite.d.ts +3 -1
- package/dist/compile/check-composite.d.ts.map +1 -1
- package/dist/compile/check-composite.js +143 -11
- package/dist/compile/check-scalar.d.ts +10 -0
- package/dist/compile/check-scalar.d.ts.map +1 -1
- package/dist/compile/check-scalar.js +138 -2
- package/dist/compile/check.d.ts.map +1 -1
- package/dist/compile/check.js +25 -3
- package/dist/compile/context.d.ts.map +1 -1
- package/dist/compile/context.js +2 -0
- 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.map +1 -1
- package/dist/compile/graph-predicate.js +389 -18
- package/dist/compile/guard.d.ts +2 -1
- package/dist/compile/guard.d.ts.map +1 -1
- package/dist/compile/guard.js +54 -8
- package/dist/compile/predicate.d.ts.map +1 -1
- package/dist/compile/predicate.js +156 -5
- package/dist/compile/runtime.d.ts +20 -1
- package/dist/compile/runtime.d.ts.map +1 -1
- package/dist/compile/runtime.js +31 -0
- package/dist/compile/source.d.ts.map +1 -1
- package/dist/compile/source.js +27 -3
- package/dist/compile/types.d.ts +2 -0
- package/dist/compile/types.d.ts.map +1 -1
- package/dist/decoder/index.d.ts +60 -0
- package/dist/decoder/index.d.ts.map +1 -1
- package/dist/decoder/index.js +164 -1
- package/dist/evaluate/check-composite.d.ts +52 -2
- package/dist/evaluate/check-composite.d.ts.map +1 -1
- package/dist/evaluate/check-composite.js +193 -6
- package/dist/evaluate/check-scalar.d.ts +9 -0
- package/dist/evaluate/check-scalar.d.ts.map +1 -1
- package/dist/evaluate/check-scalar.js +92 -3
- package/dist/evaluate/check.d.ts.map +1 -1
- package/dist/evaluate/check.js +19 -4
- package/dist/evaluate/shared.d.ts +19 -0
- package/dist/evaluate/shared.d.ts.map +1 -1
- package/dist/evaluate/shared.js +35 -0
- 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 +32 -2
- package/dist/guard/base.d.ts.map +1 -1
- package/dist/guard/base.js +74 -3
- 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/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 +60 -0
- package/dist/guard/number.d.ts.map +1 -1
- package/dist/guard/number.js +129 -0
- package/dist/guard/read.d.ts +53 -1
- package/dist/guard/read.d.ts.map +1 -1
- package/dist/guard/read.js +102 -0
- package/dist/guard/string.d.ts +82 -0
- package/dist/guard/string.d.ts.map +1 -1
- package/dist/guard/string.js +213 -0
- package/dist/guard/types.d.ts +18 -0
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/ir/builder.d.ts +3 -3
- package/dist/ir/builder.d.ts.map +1 -1
- package/dist/ir/builder.js +5 -2
- package/dist/ir/freeze.js +7 -0
- package/dist/ir/types.d.ts +4 -1
- package/dist/ir/types.d.ts.map +1 -1
- package/dist/ir/validate.d.ts.map +1 -1
- package/dist/ir/validate.js +35 -1
- package/dist/issue/index.d.ts +1 -1
- package/dist/issue/index.d.ts.map +1 -1
- package/dist/issue/index.js +4 -0
- package/dist/json-schema/emit-composite.d.ts +6 -2
- package/dist/json-schema/emit-composite.d.ts.map +1 -1
- package/dist/json-schema/emit-composite.js +66 -12
- package/dist/json-schema/emit-scalar.d.ts.map +1 -1
- package/dist/json-schema/emit-scalar.js +54 -1
- package/dist/json-schema/emit.d.ts.map +1 -1
- package/dist/json-schema/emit.js +11 -2
- package/dist/json-schema/types.d.ts +7 -1
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/kind/index.d.ts +25 -0
- package/dist/kind/index.d.ts.map +1 -1
- package/dist/kind/index.js +26 -3
- package/dist/lower/index.d.ts.map +1 -1
- package/dist/lower/index.js +52 -3
- package/dist/message/index.d.ts +18 -0
- package/dist/message/index.d.ts.map +1 -1
- package/dist/message/index.js +67 -0
- package/dist/optimize/domain.js +6 -2
- package/dist/optimize/map-node.d.ts.map +1 -1
- package/dist/optimize/map-node.js +3 -0
- package/dist/plan/cache.js +13 -1
- package/dist/plan/predicate.d.ts.map +1 -1
- package/dist/plan/predicate.js +33 -3
- package/dist/plan/schema-predicate.d.ts.map +1 -1
- package/dist/plan/schema-predicate.js +267 -8
- package/dist/schema/freeze.js +22 -0
- package/dist/schema/index.d.ts +2 -2
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +1 -1
- package/dist/schema/types.d.ts +89 -4
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js +8 -1
- package/dist/schema/undefined.d.ts.map +1 -1
- package/dist/schema/undefined.js +5 -0
- package/dist/schema/validate.d.ts.map +1 -1
- package/dist/schema/validate.js +111 -4
- package/docs/api.md +79 -10
- package/docs/assets/benchmark-headline.svg +33 -33
- package/docs/engine-notes.md +9 -5
- package/docs/index.html +1366 -722
- package/docs/ko/api.md +383 -0
- package/docs/ko/engine-notes.md +156 -0
- package/docs/ko/readme.md +404 -0
- package/package.json +6 -2
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
5
5
|
* aligned with compiled behavior.
|
|
6
6
|
*/
|
|
7
|
-
import { ObjectModeTag, PresenceTag, SchemaTag } from "../kind/index.js";
|
|
7
|
+
import { ArrayCheckTag, ObjectModeTag, PresenceTag, SchemaTag } from "../kind/index.js";
|
|
8
8
|
import { schemaCanAcceptUndefined } from "../schema/index.js";
|
|
9
9
|
import { pushIssue } from "./issue.js";
|
|
10
|
-
import { actualType, findDiscriminatedUnionCase, hasObjectKey, isArrayIndexKey, isDataPropertyDescriptor, isPlainRecord, isStrictTrue, literalToExpected, readOwnDataProperty } from "./shared.js";
|
|
10
|
+
import { actualType, findDiscriminatedUnionCase, hasObjectKey, isArrayIndexKey, isDataPropertyDescriptor, isPlainRecord, isStrictTrue, literalToExpected, ordinaryHasInstance, readOwnDataProperty } from "./shared.js";
|
|
11
11
|
/**
|
|
12
12
|
* @brief collect array issues.
|
|
13
13
|
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
@@ -20,11 +20,13 @@ import { actualType, findDiscriminatedUnionCase, hasObjectKey, isArrayIndexKey,
|
|
|
20
20
|
* @param collectChild Dispatcher for nested schema diagnostics.
|
|
21
21
|
* @post Every pushed path segment is popped before return.
|
|
22
22
|
*/
|
|
23
|
-
export function collectArrayIssues(
|
|
23
|
+
export function collectArrayIssues(schema, value, path, issues, state, collectChild) {
|
|
24
24
|
if (!Array.isArray(value)) {
|
|
25
25
|
pushIssue(path, issues, "expected_array", "array", actualType(value));
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
+
collectArrayLengthIssues(schema, value, path, issues);
|
|
29
|
+
const item = schema.item;
|
|
28
30
|
if (schemaCanAcceptUndefined(item)) {
|
|
29
31
|
/*
|
|
30
32
|
* A sparse hole is observationally undefined for this item schema. Walking
|
|
@@ -50,6 +52,36 @@ export function collectArrayIssues(item, value, path, issues, state, collectChil
|
|
|
50
52
|
path.pop();
|
|
51
53
|
}
|
|
52
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* @brief Collect array length diagnostics.
|
|
57
|
+
* @param schema Array schema with normalized checks.
|
|
58
|
+
* @param value Array already proven by the caller.
|
|
59
|
+
* @param path Current diagnostic path.
|
|
60
|
+
* @param issues Output issue buffer.
|
|
61
|
+
* @details Length checks are reported at the array path, not at an item index,
|
|
62
|
+
* because the failure describes the container domain itself.
|
|
63
|
+
*/
|
|
64
|
+
function collectArrayLengthIssues(schema, value, path, issues) {
|
|
65
|
+
const checks = schema.checks;
|
|
66
|
+
for (let index = 0; index < checks.length; index += 1) {
|
|
67
|
+
const check = checks[index];
|
|
68
|
+
if (check === undefined) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
switch (check.tag) {
|
|
72
|
+
case ArrayCheckTag.Min:
|
|
73
|
+
if (value.length < check.value) {
|
|
74
|
+
pushIssue(path, issues, "expected_min_length", `length >= ${String(check.value)}`, `length ${String(value.length)}`);
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
case ArrayCheckTag.Max:
|
|
78
|
+
if (value.length > check.value) {
|
|
79
|
+
pushIssue(path, issues, "expected_max_length", `length <= ${String(check.value)}`, `length ${String(value.length)}`);
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
53
85
|
/**
|
|
54
86
|
* @brief collect present array issues.
|
|
55
87
|
* @details Holes are equivalent to `undefined` when the item schema accepts it,
|
|
@@ -100,14 +132,19 @@ function collectPresentArrayIssues(item, value, path, issues, state, collectChil
|
|
|
100
132
|
* @param collectChild Dispatcher for nested schema diagnostics.
|
|
101
133
|
* @post Every pushed tuple index is popped before return.
|
|
102
134
|
*/
|
|
103
|
-
export function collectTupleIssues(
|
|
135
|
+
export function collectTupleIssues(schema, value, path, issues, state, collectChild) {
|
|
104
136
|
if (!Array.isArray(value)) {
|
|
105
137
|
pushIssue(path, issues, "expected_tuple", "tuple", actualType(value));
|
|
106
138
|
return;
|
|
107
139
|
}
|
|
108
|
-
|
|
140
|
+
const items = schema.items;
|
|
141
|
+
const rest = schema.rest;
|
|
142
|
+
if (rest === undefined && value.length !== items.length) {
|
|
109
143
|
pushIssue(path, issues, "expected_tuple_length", `length ${String(items.length)}`, `length ${String(value.length)}`);
|
|
110
144
|
}
|
|
145
|
+
else if (rest !== undefined && value.length < items.length) {
|
|
146
|
+
pushIssue(path, issues, "expected_tuple_length", `length >= ${String(items.length)}`, `length ${String(value.length)}`);
|
|
147
|
+
}
|
|
111
148
|
const count = value.length < items.length ? value.length : items.length;
|
|
112
149
|
/*
|
|
113
150
|
* Length mismatch is reported once, then overlapping indexes are still
|
|
@@ -128,6 +165,19 @@ export function collectTupleIssues(items, value, path, issues, state, collectChi
|
|
|
128
165
|
}
|
|
129
166
|
path.pop();
|
|
130
167
|
}
|
|
168
|
+
if (rest !== undefined && value.length > items.length) {
|
|
169
|
+
for (let index = items.length; index < value.length; index += 1) {
|
|
170
|
+
const itemValue = readArrayIndexDataProperty(value, index);
|
|
171
|
+
path.push(index);
|
|
172
|
+
if (itemValue === null) {
|
|
173
|
+
pushIssue(path, issues, "expected_tuple", "data property", "accessor");
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
collectChild(rest, itemValue === undefined ? undefined : itemValue.value, path, issues, state);
|
|
177
|
+
}
|
|
178
|
+
path.pop();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
131
181
|
}
|
|
132
182
|
/**
|
|
133
183
|
* @brief Read one array index for diagnostic collection.
|
|
@@ -195,6 +245,107 @@ export function collectRecordIssues(item, value, path, issues, state, collectChi
|
|
|
195
245
|
path.pop();
|
|
196
246
|
}
|
|
197
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* @brief collect Map issues.
|
|
250
|
+
* @param schema Map schema with key and value validators.
|
|
251
|
+
* @param value Candidate runtime value.
|
|
252
|
+
* @param path Mutable diagnostic path stack.
|
|
253
|
+
* @param issues Output issue buffer.
|
|
254
|
+
* @param state Shared recursion and cycle state.
|
|
255
|
+
* @param collectChild Dispatcher for nested schema diagnostics.
|
|
256
|
+
*/
|
|
257
|
+
export function collectMapIssues(schema, value, path, issues, state, collectChild) {
|
|
258
|
+
if (!(value instanceof Map)) {
|
|
259
|
+
pushIssue(path, issues, "expected_map", "Map", actualType(value));
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const iterator = Map.prototype.entries.call(value);
|
|
263
|
+
let index = 0;
|
|
264
|
+
for (;;) {
|
|
265
|
+
const step = iterator.next();
|
|
266
|
+
if (step.done === true) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const pair = step.value;
|
|
270
|
+
path.push(index);
|
|
271
|
+
path.push("key");
|
|
272
|
+
collectChild(schema.key, pair[0], path, issues, state);
|
|
273
|
+
path.pop();
|
|
274
|
+
path.push("value");
|
|
275
|
+
collectChild(schema.value, pair[1], path, issues, state);
|
|
276
|
+
path.pop();
|
|
277
|
+
path.pop();
|
|
278
|
+
index += 1;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* @brief collect Set issues.
|
|
283
|
+
* @param schema Set schema with item validator.
|
|
284
|
+
* @param value Candidate runtime value.
|
|
285
|
+
* @param path Mutable diagnostic path stack.
|
|
286
|
+
* @param issues Output issue buffer.
|
|
287
|
+
* @param state Shared recursion and cycle state.
|
|
288
|
+
* @param collectChild Dispatcher for nested schema diagnostics.
|
|
289
|
+
*/
|
|
290
|
+
export function collectSetIssues(schema, value, path, issues, state, collectChild) {
|
|
291
|
+
if (!(value instanceof Set)) {
|
|
292
|
+
pushIssue(path, issues, "expected_set", "Set", actualType(value));
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const iterator = Set.prototype.values.call(value);
|
|
296
|
+
let index = 0;
|
|
297
|
+
for (;;) {
|
|
298
|
+
const step = iterator.next();
|
|
299
|
+
if (step.done === true) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
path.push(index);
|
|
303
|
+
collectChild(schema.item, step.value, path, issues, state);
|
|
304
|
+
path.pop();
|
|
305
|
+
index += 1;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* @brief collect instanceOf issues.
|
|
310
|
+
* @param schema InstanceOf schema with constructor metadata.
|
|
311
|
+
* @param value Candidate runtime value.
|
|
312
|
+
* @param path Current diagnostic path.
|
|
313
|
+
* @param issues Output issue buffer.
|
|
314
|
+
*/
|
|
315
|
+
export function collectInstanceOfIssues(schema, value, path, issues) {
|
|
316
|
+
if (!ordinaryHasInstance(value, schema.constructor)) {
|
|
317
|
+
pushIssue(path, issues, "expected_instance", schema.name, actualType(value));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* @brief collect property issues.
|
|
322
|
+
* @param schema Property schema with base and own data property validator.
|
|
323
|
+
* @param value Candidate runtime value.
|
|
324
|
+
* @param path Mutable diagnostic path stack.
|
|
325
|
+
* @param issues Output issue buffer.
|
|
326
|
+
* @param state Shared recursion and cycle state.
|
|
327
|
+
* @param collectChild Dispatcher for nested schema diagnostics.
|
|
328
|
+
*/
|
|
329
|
+
export function collectPropertyIssues(schema, value, path, issues, state, collectChild) {
|
|
330
|
+
const before = issues.length;
|
|
331
|
+
collectChild(schema.base, value, path, issues, state);
|
|
332
|
+
if (issues.length !== before) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (((typeof value !== "object" && typeof value !== "function") || value === null)) {
|
|
336
|
+
pushIssue(path, issues, "expected_object", "object with property", actualType(value));
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, schema.key);
|
|
340
|
+
path.push(schema.key);
|
|
341
|
+
if (descriptor === undefined || !isDataPropertyDescriptor(descriptor)) {
|
|
342
|
+
pushIssue(path, issues, "expected_object", "data property", "missing or accessor");
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
collectChild(schema.value, descriptor.value, path, issues, state);
|
|
346
|
+
}
|
|
347
|
+
path.pop();
|
|
348
|
+
}
|
|
198
349
|
/**
|
|
199
350
|
* @brief collect object issues.
|
|
200
351
|
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
@@ -244,7 +395,10 @@ export function collectObjectIssues(schema, value, path, issues, state, collectC
|
|
|
244
395
|
collectChild(entry.schema, property.value, path, issues, state);
|
|
245
396
|
path.pop();
|
|
246
397
|
}
|
|
247
|
-
if (schema.
|
|
398
|
+
if (schema.catchall !== undefined) {
|
|
399
|
+
collectObjectCatchallIssues(schema, record, path, issues, state, collectChild);
|
|
400
|
+
}
|
|
401
|
+
else if (schema.mode === ObjectModeTag.Strict) {
|
|
248
402
|
/*
|
|
249
403
|
* Strict objects reject symbol and non-enumerable extras as well, so
|
|
250
404
|
* Reflect.ownKeys is required instead of Object.keys.
|
|
@@ -261,6 +415,39 @@ export function collectObjectIssues(schema, value, path, issues, state, collectC
|
|
|
261
415
|
}
|
|
262
416
|
}
|
|
263
417
|
}
|
|
418
|
+
/**
|
|
419
|
+
* @brief Collect issues for undeclared own object keys.
|
|
420
|
+
* @param schema Object schema carrying a catchall schema.
|
|
421
|
+
* @param record Runtime object already proven to be a plain record.
|
|
422
|
+
* @param path Mutable diagnostic path stack.
|
|
423
|
+
* @param issues Output issue buffer.
|
|
424
|
+
* @param state Shared recursion and cycle state.
|
|
425
|
+
* @param collectChild Dispatcher used for the catchall value schema.
|
|
426
|
+
*/
|
|
427
|
+
function collectObjectCatchallIssues(schema, record, path, issues, state, collectChild) {
|
|
428
|
+
const catchall = schema.catchall;
|
|
429
|
+
if (catchall === undefined) {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
const keys = Reflect.ownKeys(record);
|
|
433
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
434
|
+
const key = keys[index];
|
|
435
|
+
if (key === undefined ||
|
|
436
|
+
(typeof key === "string" && hasObjectKey(schema.keyLookup, key))) {
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
const pathKey = typeof key === "string" ? key : String(key);
|
|
440
|
+
const descriptor = Object.getOwnPropertyDescriptor(record, key);
|
|
441
|
+
path.push(pathKey);
|
|
442
|
+
if (descriptor === undefined || !isDataPropertyDescriptor(descriptor)) {
|
|
443
|
+
pushIssue(path, issues, "expected_object", "data property", "accessor");
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
collectChild(catchall, descriptor.value, path, issues, state);
|
|
447
|
+
}
|
|
448
|
+
path.pop();
|
|
449
|
+
}
|
|
450
|
+
}
|
|
264
451
|
/**
|
|
265
452
|
* @brief collect discriminated union issues.
|
|
266
453
|
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
@@ -20,6 +20,15 @@ import { type Schema } from "../schema/index.js";
|
|
|
20
20
|
export declare function collectStringIssues(schema: Extract<Schema, {
|
|
21
21
|
readonly tag: typeof SchemaTag.String;
|
|
22
22
|
}>, value: unknown, path: PathSegment[], issues: Issue[]): void;
|
|
23
|
+
/**
|
|
24
|
+
* @brief Collect Date issues.
|
|
25
|
+
* @param value Candidate runtime value.
|
|
26
|
+
* @param path Current diagnostic path.
|
|
27
|
+
* @param issues Output issue buffer.
|
|
28
|
+
*/
|
|
29
|
+
export declare function collectDateIssues(schema: Extract<Schema, {
|
|
30
|
+
readonly tag: typeof SchemaTag.Date;
|
|
31
|
+
}>, value: unknown, path: PathSegment[], issues: Issue[]): void;
|
|
23
32
|
/**
|
|
24
33
|
* @brief collect number issues.
|
|
25
34
|
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-scalar.d.ts","sourceRoot":"","sources":["../../src/evaluate/check-scalar.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"check-scalar.d.ts","sourceRoot":"","sources":["../../src/evaluate/check-scalar.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAGH,SAAS,EAEZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EASH,KAAK,MAAM,EACd,MAAM,oBAAoB,CAAC;AAQ5B;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAC/B,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,OAAO,SAAS,CAAC,MAAM,CAAA;CAAE,CAAC,EAClE,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,KAAK,EAAE,GAChB,IAAI,CAsGN;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC7B,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,OAAO,SAAS,CAAC,IAAI,CAAA;CAAE,CAAC,EAChE,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,KAAK,EAAE,GAChB,IAAI,CAqCN;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAC/B,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,OAAO,SAAS,CAAC,MAAM,CAAA;CAAE,CAAC,EAClE,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,KAAK,EAAE,GAChB,IAAI,CA8EN"}
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
5
5
|
* aligned with compiled behavior.
|
|
6
6
|
*/
|
|
7
|
-
import { NumberCheckTag, SchemaTag, StringCheckTag } from "../kind/index.js";
|
|
8
|
-
import { UUID_PATTERN } from "../schema/index.js";
|
|
7
|
+
import { DateCheckTag, NumberCheckTag, SchemaTag, StringCheckTag } from "../kind/index.js";
|
|
8
|
+
import { EMAIL_PATTERN, IPV4_PATTERN, IPV6_PATTERN, ISO_DATETIME_PATTERN, ISO_DATE_PATTERN, ULID_PATTERN, URL_PATTERN, UUID_PATTERN } from "../schema/index.js";
|
|
9
9
|
import { pushIssue } from "./issue.js";
|
|
10
|
-
import { actualType } from "./shared.js";
|
|
10
|
+
import { actualType, isValidDateObject, readDateTime } from "./shared.js";
|
|
11
11
|
/**
|
|
12
12
|
* @brief collect string issues.
|
|
13
13
|
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
@@ -64,6 +64,80 @@ export function collectStringIssues(schema, value, path, issues) {
|
|
|
64
64
|
pushIssue(path, issues, "expected_pattern", "uuid", "string");
|
|
65
65
|
}
|
|
66
66
|
break;
|
|
67
|
+
case StringCheckTag.Email:
|
|
68
|
+
EMAIL_PATTERN.lastIndex = 0;
|
|
69
|
+
if (!EMAIL_PATTERN.test(value)) {
|
|
70
|
+
pushIssue(path, issues, "expected_pattern", "email", "string");
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
case StringCheckTag.Url:
|
|
74
|
+
URL_PATTERN.lastIndex = 0;
|
|
75
|
+
if (!URL_PATTERN.test(value)) {
|
|
76
|
+
pushIssue(path, issues, "expected_pattern", "url", "string");
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
case StringCheckTag.IsoDate:
|
|
80
|
+
ISO_DATE_PATTERN.lastIndex = 0;
|
|
81
|
+
if (!ISO_DATE_PATTERN.test(value)) {
|
|
82
|
+
pushIssue(path, issues, "expected_pattern", "iso_date", "string");
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
case StringCheckTag.IsoDateTime:
|
|
86
|
+
ISO_DATETIME_PATTERN.lastIndex = 0;
|
|
87
|
+
if (!ISO_DATETIME_PATTERN.test(value)) {
|
|
88
|
+
pushIssue(path, issues, "expected_pattern", "iso_datetime", "string");
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
case StringCheckTag.Ulid:
|
|
92
|
+
ULID_PATTERN.lastIndex = 0;
|
|
93
|
+
if (!ULID_PATTERN.test(value)) {
|
|
94
|
+
pushIssue(path, issues, "expected_pattern", "ulid", "string");
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
case StringCheckTag.Ipv4:
|
|
98
|
+
IPV4_PATTERN.lastIndex = 0;
|
|
99
|
+
if (!IPV4_PATTERN.test(value)) {
|
|
100
|
+
pushIssue(path, issues, "expected_pattern", "ipv4", "string");
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
case StringCheckTag.Ipv6:
|
|
104
|
+
IPV6_PATTERN.lastIndex = 0;
|
|
105
|
+
if (!IPV6_PATTERN.test(value)) {
|
|
106
|
+
pushIssue(path, issues, "expected_pattern", "ipv6", "string");
|
|
107
|
+
}
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @brief Collect Date issues.
|
|
114
|
+
* @param value Candidate runtime value.
|
|
115
|
+
* @param path Current diagnostic path.
|
|
116
|
+
* @param issues Output issue buffer.
|
|
117
|
+
*/
|
|
118
|
+
export function collectDateIssues(schema, value, path, issues) {
|
|
119
|
+
if (!isValidDateObject(value)) {
|
|
120
|
+
pushIssue(path, issues, "expected_date", "valid Date", actualType(value));
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const time = readDateTime(value);
|
|
124
|
+
const checks = schema.checks;
|
|
125
|
+
for (let index = 0; index < checks.length; index += 1) {
|
|
126
|
+
const check = checks[index];
|
|
127
|
+
if (check === undefined) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
switch (check.tag) {
|
|
131
|
+
case DateCheckTag.Min:
|
|
132
|
+
if (time < check.value) {
|
|
133
|
+
pushIssue(path, issues, "expected_gte", `>= ${new Date(check.value).toISOString()}`, new Date(time).toISOString());
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
case DateCheckTag.Max:
|
|
137
|
+
if (time > check.value) {
|
|
138
|
+
pushIssue(path, issues, "expected_lte", `<= ${new Date(check.value).toISOString()}`, new Date(time).toISOString());
|
|
139
|
+
}
|
|
140
|
+
break;
|
|
67
141
|
}
|
|
68
142
|
}
|
|
69
143
|
}
|
|
@@ -108,6 +182,21 @@ export function collectNumberIssues(schema, value, path, issues) {
|
|
|
108
182
|
pushIssue(path, issues, "expected_lte", `<= ${String(check.value)}`, String(value));
|
|
109
183
|
}
|
|
110
184
|
break;
|
|
185
|
+
case NumberCheckTag.Gt:
|
|
186
|
+
if (value <= check.value) {
|
|
187
|
+
pushIssue(path, issues, "expected_gt", `> ${String(check.value)}`, String(value));
|
|
188
|
+
}
|
|
189
|
+
break;
|
|
190
|
+
case NumberCheckTag.Lt:
|
|
191
|
+
if (value >= check.value) {
|
|
192
|
+
pushIssue(path, issues, "expected_lt", `< ${String(check.value)}`, String(value));
|
|
193
|
+
}
|
|
194
|
+
break;
|
|
195
|
+
case NumberCheckTag.MultipleOf:
|
|
196
|
+
if (value % check.value !== 0) {
|
|
197
|
+
pushIssue(path, issues, "expected_multiple_of", `multiple of ${String(check.value)}`, String(value));
|
|
198
|
+
}
|
|
199
|
+
break;
|
|
111
200
|
}
|
|
112
201
|
}
|
|
113
202
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/evaluate/check.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,mBAAmB,CAAC;AAGzE,OAAO,EAEH,KAAK,MAAM,EACd,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/evaluate/check.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,mBAAmB,CAAC;AAGzE,OAAO,EAEH,KAAK,MAAM,EACd,MAAM,oBAAoB,CAAC;AA+B5B;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAC9B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,GACf,WAAW,CAAC,MAAM,CAAC,CAmBrB"}
|
package/dist/evaluate/check.js
CHANGED
|
@@ -8,8 +8,8 @@ import { SchemaTag } from "../kind/index.js";
|
|
|
8
8
|
import { freezeIssueArray } from "../issue/index.js";
|
|
9
9
|
import { err, ok } from "../result/index.js";
|
|
10
10
|
import { resolveLazySchema } from "../schema/index.js";
|
|
11
|
-
import { collectArrayIssues, collectDiscriminatedUnionIssues, collectObjectIssues, collectRecordIssues, collectRefineIssues, collectTupleIssues } from "./check-composite.js";
|
|
12
|
-
import { collectNumberIssues, collectStringIssues } from "./check-scalar.js";
|
|
11
|
+
import { collectArrayIssues, collectDiscriminatedUnionIssues, collectInstanceOfIssues, collectMapIssues, collectObjectIssues, collectPropertyIssues, collectRecordIssues, collectRefineIssues, collectSetIssues, collectTupleIssues } from "./check-composite.js";
|
|
12
|
+
import { collectDateIssues, collectNumberIssues, collectStringIssues } from "./check-scalar.js";
|
|
13
13
|
import { pushIssue } from "./issue.js";
|
|
14
14
|
import { isSchemaWithState, isUnionSchema } from "./predicate.js";
|
|
15
15
|
import { actualType, literalToExpected } from "./shared.js";
|
|
@@ -93,6 +93,9 @@ function collectIssuesInner(schema, value, path, issues, state) {
|
|
|
93
93
|
case SchemaTag.Number:
|
|
94
94
|
collectNumberIssues(schema, value, path, issues);
|
|
95
95
|
return;
|
|
96
|
+
case SchemaTag.Date:
|
|
97
|
+
collectDateIssues(schema, value, path, issues);
|
|
98
|
+
return;
|
|
96
99
|
case SchemaTag.BigInt:
|
|
97
100
|
if (typeof value !== "bigint") {
|
|
98
101
|
pushIssue(path, issues, "expected_bigint", "bigint", actualType(value));
|
|
@@ -114,14 +117,26 @@ function collectIssuesInner(schema, value, path, issues, state) {
|
|
|
114
117
|
}
|
|
115
118
|
return;
|
|
116
119
|
case SchemaTag.Array:
|
|
117
|
-
collectArrayIssues(schema
|
|
120
|
+
collectArrayIssues(schema, value, path, issues, state, collectIssues);
|
|
118
121
|
return;
|
|
119
122
|
case SchemaTag.Tuple:
|
|
120
|
-
collectTupleIssues(schema
|
|
123
|
+
collectTupleIssues(schema, value, path, issues, state, collectIssues);
|
|
121
124
|
return;
|
|
122
125
|
case SchemaTag.Record:
|
|
123
126
|
collectRecordIssues(schema.value, value, path, issues, state, collectIssues);
|
|
124
127
|
return;
|
|
128
|
+
case SchemaTag.Map:
|
|
129
|
+
collectMapIssues(schema, value, path, issues, state, collectIssues);
|
|
130
|
+
return;
|
|
131
|
+
case SchemaTag.Set:
|
|
132
|
+
collectSetIssues(schema, value, path, issues, state, collectIssues);
|
|
133
|
+
return;
|
|
134
|
+
case SchemaTag.InstanceOf:
|
|
135
|
+
collectInstanceOfIssues(schema, value, path, issues);
|
|
136
|
+
return;
|
|
137
|
+
case SchemaTag.Property:
|
|
138
|
+
collectPropertyIssues(schema, value, path, issues, state, collectIssues);
|
|
139
|
+
return;
|
|
125
140
|
case SchemaTag.Object:
|
|
126
141
|
collectObjectIssues(schema, value, path, issues, state, collectIssues);
|
|
127
142
|
return;
|
|
@@ -94,6 +94,25 @@ export declare function isArrayIndexKey(key: string, length: number): boolean;
|
|
|
94
94
|
* @returns Stable diagnostic type label.
|
|
95
95
|
*/
|
|
96
96
|
export declare function actualType(value: unknown): string;
|
|
97
|
+
/**
|
|
98
|
+
* @brief Validate a Date object without reading user-overridable methods.
|
|
99
|
+
* @param value Candidate runtime value.
|
|
100
|
+
* @returns True when value is a Date with a finite time value.
|
|
101
|
+
*/
|
|
102
|
+
export declare function isValidDateObject(value: unknown): value is Date;
|
|
103
|
+
/**
|
|
104
|
+
* @brief Read a Date object's time value through the intrinsic method.
|
|
105
|
+
* @param value Date object already accepted by isValidDateObject.
|
|
106
|
+
* @returns Epoch millisecond value.
|
|
107
|
+
*/
|
|
108
|
+
export declare function readDateTime(value: Date): number;
|
|
109
|
+
/**
|
|
110
|
+
* @brief Execute ordinary instanceof without invoking custom hasInstance hooks.
|
|
111
|
+
* @param value Candidate runtime value.
|
|
112
|
+
* @param constructor Constructor function stored in the schema.
|
|
113
|
+
* @returns True when the ordinary prototype-chain check accepts the value.
|
|
114
|
+
*/
|
|
115
|
+
export declare function ordinaryHasInstance(value: unknown, constructor: abstract new (...args: never[]) => unknown): boolean;
|
|
97
116
|
/**
|
|
98
117
|
* @brief Render a literal schema value for the `expected` diagnostic field.
|
|
99
118
|
* @details String values are JSON-quoted and negative zero is preserved because
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/evaluate/shared.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACR,sBAAsB,EACtB,YAAY,EACZ,eAAe,EACf,MAAM,EACT,MAAM,oBAAoB,CAAC;AAI5B;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IAEnC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAE7E;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAC/B,MAAM,EAAE,aAAa,EACrB,GAAG,EAAE,MAAM,GACZ,sBAAsB,GAAG,SAAS,CAMpC;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACtC,KAAK,EAAE,SAAS,sBAAsB,EAAE,EACxC,KAAK,EAAE,MAAM,GACd,MAAM,GAAG,SAAS,CAQpB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACpC,UAAU,EAAE,kBAAkB,GAC/B,UAAU,IAAI,sBAAsB,CAEtC;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAcpE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/evaluate/shared.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACR,sBAAsB,EACtB,YAAY,EACZ,eAAe,EACf,MAAM,EACT,MAAM,oBAAoB,CAAC;AAI5B;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IAEnC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAE7E;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAC/B,MAAM,EAAE,aAAa,EACrB,GAAG,EAAE,MAAM,GACZ,sBAAsB,GAAG,SAAS,CAMpC;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACtC,KAAK,EAAE,SAAS,sBAAsB,EAAE,EACxC,KAAK,EAAE,MAAM,GACd,MAAM,GAAG,SAAS,CAQpB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACpC,UAAU,EAAE,kBAAkB,GAC/B,UAAU,IAAI,sBAAsB,CAEtC;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAcpE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CA0BjD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAG/D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,CAEhD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAC/B,KAAK,EAAE,OAAO,EACd,WAAW,EAAE,QAAQ,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,GACxD,OAAO,CAET;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAiB7D"}
|
package/dist/evaluate/shared.js
CHANGED
|
@@ -116,6 +116,15 @@ export function actualType(value) {
|
|
|
116
116
|
if (Array.isArray(value)) {
|
|
117
117
|
return "array";
|
|
118
118
|
}
|
|
119
|
+
if (value instanceof Date) {
|
|
120
|
+
return "date";
|
|
121
|
+
}
|
|
122
|
+
if (value instanceof Map) {
|
|
123
|
+
return "map";
|
|
124
|
+
}
|
|
125
|
+
if (value instanceof Set) {
|
|
126
|
+
return "set";
|
|
127
|
+
}
|
|
119
128
|
if (typeof value === "bigint") {
|
|
120
129
|
return "bigint";
|
|
121
130
|
}
|
|
@@ -127,6 +136,32 @@ export function actualType(value) {
|
|
|
127
136
|
}
|
|
128
137
|
return typeof value;
|
|
129
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* @brief Validate a Date object without reading user-overridable methods.
|
|
141
|
+
* @param value Candidate runtime value.
|
|
142
|
+
* @returns True when value is a Date with a finite time value.
|
|
143
|
+
*/
|
|
144
|
+
export function isValidDateObject(value) {
|
|
145
|
+
return value instanceof Date &&
|
|
146
|
+
Number.isFinite(Date.prototype.getTime.call(value));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* @brief Read a Date object's time value through the intrinsic method.
|
|
150
|
+
* @param value Date object already accepted by isValidDateObject.
|
|
151
|
+
* @returns Epoch millisecond value.
|
|
152
|
+
*/
|
|
153
|
+
export function readDateTime(value) {
|
|
154
|
+
return Date.prototype.getTime.call(value);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* @brief Execute ordinary instanceof without invoking custom hasInstance hooks.
|
|
158
|
+
* @param value Candidate runtime value.
|
|
159
|
+
* @param constructor Constructor function stored in the schema.
|
|
160
|
+
* @returns True when the ordinary prototype-chain check accepts the value.
|
|
161
|
+
*/
|
|
162
|
+
export function ordinaryHasInstance(value, constructor) {
|
|
163
|
+
return Function.prototype[Symbol.hasInstance].call(constructor, value);
|
|
164
|
+
}
|
|
130
165
|
/**
|
|
131
166
|
* @brief Render a literal schema value for the `expected` diagnostic field.
|
|
132
167
|
* @details String values are JSON-quoted and negative zero is preserved because
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file array.ts
|
|
3
|
+
* @brief Array guard implementation.
|
|
4
|
+
* @details Array helpers append immutable length constraints while preserving
|
|
5
|
+
* the item schema owned by the original guard.
|
|
6
|
+
*/
|
|
7
|
+
import type { ArraySchema } from "../schema/index.js";
|
|
8
|
+
import { BaseGuard } from "./base.js";
|
|
9
|
+
import type { Presence } from "./types.js";
|
|
10
|
+
/**
|
|
11
|
+
* @brief Persistent builder for homogeneous array predicates.
|
|
12
|
+
* @details Length methods allocate a fresh schema record. The item schema is
|
|
13
|
+
* reused by identity because guard construction has already frozen it.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ArrayGuard<TItem, TPresence extends Presence = "required"> extends BaseGuard<TItem[], TPresence> {
|
|
16
|
+
/**
|
|
17
|
+
* @brief Construct a frozen array guard.
|
|
18
|
+
* @param schema Array schema backing this guard.
|
|
19
|
+
* @post The receiver has no mutable instance state after construction.
|
|
20
|
+
*/
|
|
21
|
+
constructor(schema: ArraySchema);
|
|
22
|
+
/**
|
|
23
|
+
* @brief Require an inclusive minimum array length.
|
|
24
|
+
* @param value Non-negative integer lower bound.
|
|
25
|
+
* @returns Fresh ArrayGuard with an appended minimum length check.
|
|
26
|
+
*/
|
|
27
|
+
min(value: number): ArrayGuard<TItem, TPresence>;
|
|
28
|
+
/**
|
|
29
|
+
* @brief Require an inclusive maximum array length.
|
|
30
|
+
* @param value Non-negative integer upper bound.
|
|
31
|
+
* @returns Fresh ArrayGuard with an appended maximum length check.
|
|
32
|
+
*/
|
|
33
|
+
max(value: number): ArrayGuard<TItem, TPresence>;
|
|
34
|
+
/**
|
|
35
|
+
* @brief Require one exact array length.
|
|
36
|
+
* @param value Non-negative integer exact length.
|
|
37
|
+
* @returns Fresh ArrayGuard with matching minimum and maximum length checks.
|
|
38
|
+
* @details Exact length is represented as two ordinary bounds so every
|
|
39
|
+
* backend can reuse the same comparison and diagnostic paths.
|
|
40
|
+
*/
|
|
41
|
+
length(value: number): ArrayGuard<TItem, TPresence>;
|
|
42
|
+
/**
|
|
43
|
+
* @brief Require at least one array element.
|
|
44
|
+
* @returns Fresh ArrayGuard with a minimum length of one.
|
|
45
|
+
*/
|
|
46
|
+
nonempty(): ArrayGuard<TItem, TPresence>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/guard/array.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACH,SAAS,EAEZ,MAAM,WAAW,CAAC;AAMnB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;GAIG;AACH,qBAAa,UAAU,CACnB,KAAK,EACL,SAAS,SAAS,QAAQ,GAAG,UAAU,CACzC,SAAQ,SAAS,CAAC,KAAK,EAAE,EAAE,SAAS,CAAC;IAEnC;;;;OAIG;gBACgB,MAAM,EAAE,WAAW;IAKtC;;;;OAIG;IACI,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAgBvD;;;;OAIG;IACI,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAgBvD;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAK1D;;;OAGG;IACI,QAAQ,IAAI,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;CAGlD"}
|