typesea 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -6
- package/README.md +98 -17
- package/dist/adapters/index.d.ts +50 -8
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +169 -48
- package/dist/aot/index.d.ts +18 -2
- package/dist/aot/index.d.ts.map +1 -1
- package/dist/aot/index.js +93 -14
- package/dist/async/index.d.ts +28 -56
- package/dist/async/index.d.ts.map +1 -1
- package/dist/async/index.js +94 -37
- package/dist/builders/composite.d.ts +37 -6
- package/dist/builders/composite.d.ts.map +1 -1
- package/dist/builders/composite.js +84 -10
- package/dist/builders/index.d.ts +2 -0
- package/dist/builders/index.d.ts.map +1 -1
- package/dist/builders/index.js +2 -0
- package/dist/builders/modifier.d.ts +30 -5
- package/dist/builders/modifier.d.ts.map +1 -1
- package/dist/builders/modifier.js +38 -5
- package/dist/builders/object/guard.d.ts +18 -22
- package/dist/builders/object/guard.d.ts.map +1 -1
- package/dist/builders/object/guard.js +26 -26
- package/dist/builders/object/index.d.ts +2 -0
- package/dist/builders/object/index.d.ts.map +1 -1
- package/dist/builders/object/index.js +2 -0
- package/dist/builders/object/schema.d.ts +55 -9
- package/dist/builders/object/schema.d.ts.map +1 -1
- package/dist/builders/object/schema.js +92 -15
- package/dist/builders/object/types.d.ts +5 -31
- package/dist/builders/object/types.d.ts.map +1 -1
- package/dist/builders/object/types.js +2 -0
- package/dist/builders/scalar.d.ts +29 -8
- package/dist/builders/scalar.d.ts.map +1 -1
- package/dist/builders/scalar.js +33 -8
- package/dist/builders/table.d.ts +4 -0
- package/dist/builders/table.d.ts.map +1 -1
- package/dist/builders/table.js +4 -0
- package/dist/builders/types.d.ts +14 -4
- package/dist/builders/types.d.ts.map +1 -1
- package/dist/builders/types.js +2 -0
- package/dist/compile/check-composite.d.ts +22 -1
- package/dist/compile/check-composite.d.ts.map +1 -1
- package/dist/compile/check-composite.js +564 -24
- package/dist/compile/check-scalar.d.ts +78 -0
- package/dist/compile/check-scalar.d.ts.map +1 -1
- package/dist/compile/check-scalar.js +432 -1
- package/dist/compile/check.d.ts +12 -0
- package/dist/compile/check.d.ts.map +1 -1
- package/dist/compile/check.js +37 -0
- package/dist/compile/context.d.ts +47 -9
- package/dist/compile/context.d.ts.map +1 -1
- package/dist/compile/context.js +51 -8
- package/dist/compile/graph-predicate.d.ts +4 -2
- package/dist/compile/graph-predicate.d.ts.map +1 -1
- package/dist/compile/graph-predicate.js +1907 -171
- package/dist/compile/guard.d.ts +15 -24
- package/dist/compile/guard.d.ts.map +1 -1
- package/dist/compile/guard.js +158 -74
- package/dist/compile/index.d.ts +3 -1
- package/dist/compile/index.d.ts.map +1 -1
- package/dist/compile/index.js +2 -0
- package/dist/compile/issue.d.ts +110 -0
- package/dist/compile/issue.d.ts.map +1 -1
- package/dist/compile/issue.js +184 -1
- package/dist/compile/names.d.ts +12 -2
- package/dist/compile/names.d.ts.map +1 -1
- package/dist/compile/names.js +19 -3
- package/dist/compile/predicate.d.ts +24 -0
- package/dist/compile/predicate.d.ts.map +1 -1
- package/dist/compile/predicate.js +131 -5
- package/dist/compile/runtime.d.ts +80 -12
- package/dist/compile/runtime.d.ts.map +1 -1
- package/dist/compile/runtime.js +25 -6
- package/dist/compile/source.d.ts +10 -2
- package/dist/compile/source.d.ts.map +1 -1
- package/dist/compile/source.js +361 -26
- package/dist/compile/types.d.ts +20 -0
- package/dist/compile/types.d.ts.map +1 -1
- package/dist/compile/types.js +2 -0
- package/dist/decoder/index.d.ts +32 -46
- package/dist/decoder/index.d.ts.map +1 -1
- package/dist/decoder/index.js +102 -38
- package/dist/evaluate/check-composite.d.ts +59 -0
- package/dist/evaluate/check-composite.d.ts.map +1 -1
- package/dist/evaluate/check-composite.js +151 -3
- package/dist/evaluate/check-scalar.d.ts +16 -0
- package/dist/evaluate/check-scalar.d.ts.map +1 -1
- package/dist/evaluate/check-scalar.js +32 -0
- package/dist/evaluate/check.d.ts +7 -0
- package/dist/evaluate/check.d.ts.map +1 -1
- package/dist/evaluate/check.js +43 -0
- package/dist/evaluate/index.d.ts +2 -0
- package/dist/evaluate/index.d.ts.map +1 -1
- package/dist/evaluate/index.js +2 -0
- package/dist/evaluate/issue.d.ts +11 -1
- package/dist/evaluate/issue.d.ts.map +1 -1
- package/dist/evaluate/issue.js +15 -1
- package/dist/evaluate/predicate.d.ts +16 -5
- package/dist/evaluate/predicate.d.ts.map +1 -1
- package/dist/evaluate/predicate.js +20 -5
- package/dist/evaluate/shared.d.ts +59 -13
- package/dist/evaluate/shared.d.ts.map +1 -1
- package/dist/evaluate/shared.js +66 -8
- package/dist/evaluate/state.d.ts +35 -13
- package/dist/evaluate/state.d.ts.map +1 -1
- package/dist/evaluate/state.js +35 -2
- package/dist/guard/base.d.ts +79 -29
- package/dist/guard/base.d.ts.map +1 -1
- package/dist/guard/base.js +91 -29
- package/dist/guard/error.d.ts +10 -5
- package/dist/guard/error.d.ts.map +1 -1
- package/dist/guard/error.js +10 -5
- package/dist/guard/index.d.ts +2 -0
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +2 -0
- package/dist/guard/number.d.ts +26 -11
- package/dist/guard/number.d.ts.map +1 -1
- package/dist/guard/number.js +30 -11
- package/dist/guard/props.d.ts +27 -3
- package/dist/guard/props.d.ts.map +1 -1
- package/dist/guard/props.js +27 -3
- package/dist/guard/read.d.ts +62 -9
- package/dist/guard/read.d.ts.map +1 -1
- package/dist/guard/read.js +83 -10
- package/dist/guard/registry.d.ts +12 -2
- package/dist/guard/registry.d.ts.map +1 -1
- package/dist/guard/registry.js +15 -3
- package/dist/guard/string.d.ts +33 -13
- package/dist/guard/string.d.ts.map +1 -1
- package/dist/guard/string.js +37 -13
- package/dist/guard/types.d.ts +92 -40
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/guard/types.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/internal/index.d.ts +42 -6
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +51 -8
- package/dist/ir/builder.d.ts +16 -126
- package/dist/ir/builder.d.ts.map +1 -1
- package/dist/ir/builder.js +77 -137
- package/dist/ir/freeze.d.ts +4 -0
- package/dist/ir/freeze.d.ts.map +1 -1
- package/dist/ir/freeze.js +59 -0
- package/dist/ir/index.d.ts +3 -1
- package/dist/ir/index.d.ts.map +1 -1
- package/dist/ir/index.js +2 -0
- package/dist/ir/regexp.d.ts +2 -0
- package/dist/ir/regexp.d.ts.map +1 -1
- package/dist/ir/regexp.js +2 -0
- package/dist/ir/types.d.ts +90 -55
- package/dist/ir/types.d.ts.map +1 -1
- package/dist/ir/types.js +2 -0
- package/dist/ir/validate.d.ts +8 -1
- package/dist/ir/validate.d.ts.map +1 -1
- package/dist/ir/validate.js +477 -61
- package/dist/issue/index.d.ts +41 -9
- package/dist/issue/index.d.ts.map +1 -1
- package/dist/issue/index.js +61 -11
- package/dist/json-schema/emit-combinator.d.ts +44 -4
- package/dist/json-schema/emit-combinator.d.ts.map +1 -1
- package/dist/json-schema/emit-combinator.js +44 -4
- package/dist/json-schema/emit-composite.d.ts +10 -0
- package/dist/json-schema/emit-composite.d.ts.map +1 -1
- package/dist/json-schema/emit-composite.js +15 -1
- package/dist/json-schema/emit-scalar.d.ts +26 -3
- package/dist/json-schema/emit-scalar.d.ts.map +1 -1
- package/dist/json-schema/emit-scalar.js +70 -9
- package/dist/json-schema/emit-types.d.ts +11 -1
- package/dist/json-schema/emit-types.d.ts.map +1 -1
- package/dist/json-schema/emit-types.js +2 -0
- package/dist/json-schema/emit.d.ts +12 -1
- package/dist/json-schema/emit.d.ts.map +1 -1
- package/dist/json-schema/emit.js +12 -1
- package/dist/json-schema/freeze.d.ts +13 -2
- package/dist/json-schema/freeze.d.ts.map +1 -1
- package/dist/json-schema/freeze.js +41 -8
- package/dist/json-schema/index.d.ts +16 -2
- package/dist/json-schema/index.d.ts.map +1 -1
- package/dist/json-schema/index.js +23 -3
- package/dist/json-schema/issue.d.ts +4 -1
- package/dist/json-schema/issue.d.ts.map +1 -1
- package/dist/json-schema/issue.js +4 -1
- package/dist/json-schema/read.d.ts +24 -3
- package/dist/json-schema/read.d.ts.map +1 -1
- package/dist/json-schema/read.js +59 -12
- package/dist/json-schema/types.d.ts +38 -15
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/json-schema/types.js +2 -0
- package/dist/kind/index.d.ts +15 -28
- package/dist/kind/index.d.ts.map +1 -1
- package/dist/kind/index.js +15 -10
- package/dist/lower/index.d.ts +6 -1
- package/dist/lower/index.d.ts.map +1 -1
- package/dist/lower/index.js +411 -44
- package/dist/message/index.d.ts +46 -10
- package/dist/message/index.d.ts.map +1 -1
- package/dist/message/index.js +88 -17
- package/dist/optimize/algebraic.d.ts +54 -0
- package/dist/optimize/algebraic.d.ts.map +1 -0
- package/dist/optimize/algebraic.js +314 -0
- package/dist/optimize/compact.d.ts +8 -1
- package/dist/optimize/compact.d.ts.map +1 -1
- package/dist/optimize/compact.js +13 -2
- package/dist/optimize/domain.d.ts +16 -0
- package/dist/optimize/domain.d.ts.map +1 -0
- package/dist/optimize/domain.js +615 -0
- package/dist/optimize/fold-boolean.d.ts +17 -2
- package/dist/optimize/fold-boolean.d.ts.map +1 -1
- package/dist/optimize/fold-boolean.js +59 -14
- package/dist/optimize/fold-common.d.ts +43 -8
- package/dist/optimize/fold-common.d.ts.map +1 -1
- package/dist/optimize/fold-common.js +37 -6
- package/dist/optimize/fold-constraints.d.ts +33 -0
- package/dist/optimize/fold-constraints.d.ts.map +1 -0
- package/dist/optimize/fold-constraints.js +484 -0
- package/dist/optimize/fold-scalar.d.ts +98 -13
- package/dist/optimize/fold-scalar.d.ts.map +1 -1
- package/dist/optimize/fold-scalar.js +98 -13
- package/dist/optimize/fold.d.ts +8 -1
- package/dist/optimize/fold.d.ts.map +1 -1
- package/dist/optimize/fold.js +22 -2
- package/dist/optimize/index.d.ts +9 -1
- package/dist/optimize/index.d.ts.map +1 -1
- package/dist/optimize/index.js +18 -3
- package/dist/optimize/map-node.d.ts +3 -1
- package/dist/optimize/map-node.d.ts.map +1 -1
- package/dist/optimize/map-node.js +45 -3
- package/dist/optimize/peephole.d.ts +16 -0
- package/dist/optimize/peephole.d.ts.map +1 -0
- package/dist/optimize/peephole.js +254 -0
- package/dist/optimize/remap.d.ts +2 -0
- package/dist/optimize/remap.d.ts.map +1 -1
- package/dist/optimize/remap.js +2 -0
- package/dist/optimize/rewrite.d.ts +13 -8
- package/dist/optimize/rewrite.d.ts.map +1 -1
- package/dist/optimize/rewrite.js +13 -8
- package/dist/plan/cache.d.ts +9 -3
- package/dist/plan/cache.d.ts.map +1 -1
- package/dist/plan/cache.js +21 -5
- package/dist/plan/index.d.ts +2 -0
- package/dist/plan/index.d.ts.map +1 -1
- package/dist/plan/index.js +2 -0
- package/dist/plan/predicate.d.ts +2 -0
- package/dist/plan/predicate.d.ts.map +1 -1
- package/dist/plan/predicate.js +268 -29
- package/dist/plan/schema-predicate.d.ts +6 -0
- package/dist/plan/schema-predicate.d.ts.map +1 -1
- package/dist/plan/schema-predicate.js +117 -13
- package/dist/plan/types.d.ts +2 -0
- package/dist/plan/types.d.ts.map +1 -1
- package/dist/plan/types.js +2 -0
- package/dist/result/index.d.ts +19 -5
- package/dist/result/index.d.ts.map +1 -1
- package/dist/result/index.js +10 -2
- package/dist/schema/common.d.ts +69 -6
- package/dist/schema/common.d.ts.map +1 -1
- package/dist/schema/common.js +104 -10
- package/dist/schema/freeze.d.ts +4 -0
- package/dist/schema/freeze.d.ts.map +1 -1
- package/dist/schema/freeze.js +18 -0
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +3 -0
- package/dist/schema/lazy.d.ts +4 -0
- package/dist/schema/lazy.d.ts.map +1 -1
- package/dist/schema/lazy.js +4 -0
- package/dist/schema/literal.d.ts +7 -1
- package/dist/schema/literal.d.ts.map +1 -1
- package/dist/schema/literal.js +7 -1
- package/dist/schema/types.d.ts +20 -96
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js +5 -1
- package/dist/schema/undefined.d.ts +17 -0
- package/dist/schema/undefined.d.ts.map +1 -0
- package/dist/schema/undefined.js +72 -0
- package/dist/schema/validate.d.ts +8 -1
- package/dist/schema/validate.d.ts.map +1 -1
- package/dist/schema/validate.js +146 -55
- package/docs/api.md +57 -0
- package/docs/assets/benchmark-headline.svg +163 -0
- package/docs/engine-notes.md +58 -15
- package/docs/index.html +130 -110
- package/package.json +65 -65
package/dist/guard/read.d.ts
CHANGED
|
@@ -1,42 +1,95 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file read.ts
|
|
3
3
|
* @brief Guard receiver and constructor validation.
|
|
4
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
5
|
+
* existing guard instance.
|
|
4
6
|
*/
|
|
5
7
|
import type { NumberSchema, Schema, StringSchema } from "../schema/index.js";
|
|
6
8
|
/**
|
|
7
|
-
* @brief
|
|
9
|
+
* @brief Read schema from a verified guard receiver.
|
|
10
|
+
* @details Constructed guards take the WeakSet fast path; forged structural
|
|
11
|
+
* guards must expose a valid own data schema before use. The fallback exists
|
|
12
|
+
* because public methods can be detached from their instance in JavaScript.
|
|
13
|
+
* @param guard Candidate receiver or guard-like value.
|
|
14
|
+
* @param label Human-readable label used in TypeError messages.
|
|
15
|
+
* @returns Valid runtime schema carried by the guard.
|
|
16
|
+
* @throws TypeError when the receiver is not a valid TypeSea guard.
|
|
8
17
|
*/
|
|
9
18
|
export declare function readGuardSchema(guard: unknown, label: string): Schema;
|
|
10
19
|
/**
|
|
11
|
-
* @brief
|
|
20
|
+
* @brief Read and require a string schema from a method receiver.
|
|
21
|
+
* @param guard Candidate receiver.
|
|
22
|
+
* @param label Human-readable label used in TypeError messages.
|
|
23
|
+
* @returns String schema carried by the receiver.
|
|
24
|
+
* @throws TypeError when the receiver is not a string guard.
|
|
25
|
+
* @details StringGuard methods share this gate so subtype-specific helpers do
|
|
26
|
+
* not duplicate receiver validation or accept forged schemas.
|
|
12
27
|
*/
|
|
13
28
|
export declare function readStringMethodSchema(guard: unknown, label: string): StringSchema;
|
|
14
29
|
/**
|
|
15
|
-
* @brief
|
|
30
|
+
* @brief Read and require a number schema from a method receiver.
|
|
31
|
+
* @param guard Candidate receiver.
|
|
32
|
+
* @param label Human-readable label used in TypeError messages.
|
|
33
|
+
* @returns Number schema carried by the receiver.
|
|
34
|
+
* @throws TypeError when the receiver is not a number guard.
|
|
35
|
+
* @details NumberGuard methods must fail before reading numeric check vectors
|
|
36
|
+
* when a receiver is detached or structurally forged.
|
|
16
37
|
*/
|
|
17
38
|
export declare function readNumberMethodSchema(guard: unknown, label: string): NumberSchema;
|
|
18
39
|
/**
|
|
19
|
-
* @brief
|
|
40
|
+
* @brief Validate and freeze a generic guard constructor schema.
|
|
41
|
+
* @param schema Candidate runtime schema.
|
|
42
|
+
* @returns Frozen schema accepted by BaseGuard.
|
|
43
|
+
* @throws TypeError when the schema is malformed.
|
|
44
|
+
* @details Constructors are the only place that accepts mutable schema records.
|
|
45
|
+
* Freezing here lets normal method calls use the registry fast path later.
|
|
20
46
|
*/
|
|
21
47
|
export declare function readConstructorSchema(schema: unknown): Schema;
|
|
22
48
|
/**
|
|
23
|
-
* @brief
|
|
49
|
+
* @brief Validate a StringGuard constructor schema.
|
|
50
|
+
* @param schema Candidate runtime schema.
|
|
51
|
+
* @returns String schema accepted by StringGuard.
|
|
52
|
+
* @throws TypeError when the schema is not a string schema.
|
|
53
|
+
* @details Specialized guards keep their schema tag invariant at construction,
|
|
54
|
+
* so hot method calls only need to verify receiver identity.
|
|
24
55
|
*/
|
|
25
56
|
export declare function readStringConstructorSchema(schema: unknown): StringSchema;
|
|
26
57
|
/**
|
|
27
|
-
* @brief
|
|
58
|
+
* @brief Validate a NumberGuard constructor schema.
|
|
59
|
+
* @param schema Candidate runtime schema.
|
|
60
|
+
* @returns Number schema accepted by NumberGuard.
|
|
61
|
+
* @throws TypeError when the schema is not a number schema.
|
|
62
|
+
* @details Rejecting non-number schemas at construction prevents mixed scalar
|
|
63
|
+
* helper methods from observing incompatible check vectors.
|
|
28
64
|
*/
|
|
29
65
|
export declare function readNumberConstructorSchema(schema: unknown): NumberSchema;
|
|
30
66
|
/**
|
|
31
|
-
* @brief
|
|
67
|
+
* @brief Validate refinement API inputs.
|
|
68
|
+
* @param predicate Candidate refinement predicate.
|
|
69
|
+
* @param name Candidate diagnostic name.
|
|
70
|
+
* @throws TypeError when either input has the wrong runtime type.
|
|
71
|
+
* @details Refinements execute user code by design. This gate narrows the call
|
|
72
|
+
* target and diagnostic label before the schema stores them.
|
|
32
73
|
*/
|
|
33
74
|
export declare function checkRefinementInput(predicate: unknown, name: unknown): asserts predicate is (value: unknown) => boolean;
|
|
34
75
|
/**
|
|
35
|
-
* @brief
|
|
76
|
+
* @brief Validate a non-negative string length bound.
|
|
77
|
+
* @param value Candidate bound.
|
|
78
|
+
* @param label Bound label used in RangeError messages.
|
|
79
|
+
* @returns The validated bound.
|
|
80
|
+
* @throws RangeError when the bound is negative or non-integer.
|
|
81
|
+
* @details Bounds are checked once at builder time so generated validators can
|
|
82
|
+
* emit straight comparisons without defensive range checks.
|
|
36
83
|
*/
|
|
37
84
|
export declare function checkStringLengthBound(value: number, label: string): number;
|
|
38
85
|
/**
|
|
39
|
-
* @brief
|
|
86
|
+
* @brief Validate a finite numeric bound.
|
|
87
|
+
* @param value Candidate bound.
|
|
88
|
+
* @param label Bound label used in RangeError messages.
|
|
89
|
+
* @returns The validated bound.
|
|
90
|
+
* @throws RangeError when the bound is not finite.
|
|
91
|
+
* @details Finite bounds keep interpreter, plan, and emitted code semantics
|
|
92
|
+
* aligned for comparisons such as gte and lte.
|
|
40
93
|
*/
|
|
41
94
|
export declare function checkFiniteNumberBound(value: number, label: string): number;
|
|
42
95
|
//# sourceMappingURL=read.d.ts.map
|
package/dist/guard/read.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/guard/read.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/guard/read.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAK7E;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC3B,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,GACd,MAAM,CAgBR;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAalF;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAalF;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAK7D;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAKzE;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAKzE;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAChC,SAAS,EAAE,OAAO,EAClB,IAAI,EAAE,OAAO,GACd,OAAO,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAOlD;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAK3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAK3E"}
|
package/dist/guard/read.js
CHANGED
|
@@ -1,29 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file read.ts
|
|
3
3
|
* @brief Guard receiver and constructor validation.
|
|
4
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
5
|
+
* existing guard instance.
|
|
4
6
|
*/
|
|
5
7
|
import { SchemaTag } from "../kind/index.js";
|
|
6
8
|
import { freezeSchema, isSchemaValue } from "../schema/index.js";
|
|
7
9
|
import { isRecord } from "./props.js";
|
|
8
10
|
import { isConstructedGuard } from "./registry.js";
|
|
9
11
|
/**
|
|
10
|
-
* @brief
|
|
12
|
+
* @brief Read schema from a verified guard receiver.
|
|
13
|
+
* @details Constructed guards take the WeakSet fast path; forged structural
|
|
14
|
+
* guards must expose a valid own data schema before use. The fallback exists
|
|
15
|
+
* because public methods can be detached from their instance in JavaScript.
|
|
16
|
+
* @param guard Candidate receiver or guard-like value.
|
|
17
|
+
* @param label Human-readable label used in TypeError messages.
|
|
18
|
+
* @returns Valid runtime schema carried by the guard.
|
|
19
|
+
* @throws TypeError when the receiver is not a valid TypeSea guard.
|
|
11
20
|
*/
|
|
12
21
|
export function readGuardSchema(guard, label) {
|
|
13
22
|
if (isConstructedGuard(guard)) {
|
|
23
|
+
/*
|
|
24
|
+
* Constructed guards have already frozen their schema, so the registry
|
|
25
|
+
* path avoids repeating structural schema validation for normal calls.
|
|
26
|
+
*/
|
|
14
27
|
return guard.schema;
|
|
15
28
|
}
|
|
16
29
|
if (!isRecord(guard)) {
|
|
17
30
|
throw new TypeError(`${label} must be a TypeSea guard`);
|
|
18
31
|
}
|
|
19
|
-
const schema = guard
|
|
32
|
+
const schema = readOwnDataProperty(guard, "schema");
|
|
20
33
|
if (!isSchemaValue(schema)) {
|
|
21
34
|
throw new TypeError(`${label} must contain a valid TypeSea schema`);
|
|
22
35
|
}
|
|
23
36
|
return schema;
|
|
24
37
|
}
|
|
25
38
|
/**
|
|
26
|
-
* @brief
|
|
39
|
+
* @brief Read and require a string schema from a method receiver.
|
|
40
|
+
* @param guard Candidate receiver.
|
|
41
|
+
* @param label Human-readable label used in TypeError messages.
|
|
42
|
+
* @returns String schema carried by the receiver.
|
|
43
|
+
* @throws TypeError when the receiver is not a string guard.
|
|
44
|
+
* @details StringGuard methods share this gate so subtype-specific helpers do
|
|
45
|
+
* not duplicate receiver validation or accept forged schemas.
|
|
27
46
|
*/
|
|
28
47
|
export function readStringMethodSchema(guard, label) {
|
|
29
48
|
if (isConstructedGuard(guard)) {
|
|
@@ -40,7 +59,13 @@ export function readStringMethodSchema(guard, label) {
|
|
|
40
59
|
return schema;
|
|
41
60
|
}
|
|
42
61
|
/**
|
|
43
|
-
* @brief
|
|
62
|
+
* @brief Read and require a number schema from a method receiver.
|
|
63
|
+
* @param guard Candidate receiver.
|
|
64
|
+
* @param label Human-readable label used in TypeError messages.
|
|
65
|
+
* @returns Number schema carried by the receiver.
|
|
66
|
+
* @throws TypeError when the receiver is not a number guard.
|
|
67
|
+
* @details NumberGuard methods must fail before reading numeric check vectors
|
|
68
|
+
* when a receiver is detached or structurally forged.
|
|
44
69
|
*/
|
|
45
70
|
export function readNumberMethodSchema(guard, label) {
|
|
46
71
|
if (isConstructedGuard(guard)) {
|
|
@@ -57,7 +82,12 @@ export function readNumberMethodSchema(guard, label) {
|
|
|
57
82
|
return schema;
|
|
58
83
|
}
|
|
59
84
|
/**
|
|
60
|
-
* @brief
|
|
85
|
+
* @brief Validate and freeze a generic guard constructor schema.
|
|
86
|
+
* @param schema Candidate runtime schema.
|
|
87
|
+
* @returns Frozen schema accepted by BaseGuard.
|
|
88
|
+
* @throws TypeError when the schema is malformed.
|
|
89
|
+
* @details Constructors are the only place that accepts mutable schema records.
|
|
90
|
+
* Freezing here lets normal method calls use the registry fast path later.
|
|
61
91
|
*/
|
|
62
92
|
export function readConstructorSchema(schema) {
|
|
63
93
|
if (!isSchemaValue(schema)) {
|
|
@@ -66,7 +96,12 @@ export function readConstructorSchema(schema) {
|
|
|
66
96
|
return freezeSchema(schema);
|
|
67
97
|
}
|
|
68
98
|
/**
|
|
69
|
-
* @brief
|
|
99
|
+
* @brief Validate a StringGuard constructor schema.
|
|
100
|
+
* @param schema Candidate runtime schema.
|
|
101
|
+
* @returns String schema accepted by StringGuard.
|
|
102
|
+
* @throws TypeError when the schema is not a string schema.
|
|
103
|
+
* @details Specialized guards keep their schema tag invariant at construction,
|
|
104
|
+
* so hot method calls only need to verify receiver identity.
|
|
70
105
|
*/
|
|
71
106
|
export function readStringConstructorSchema(schema) {
|
|
72
107
|
if (!isSchemaValue(schema) || schema.tag !== SchemaTag.String) {
|
|
@@ -75,7 +110,12 @@ export function readStringConstructorSchema(schema) {
|
|
|
75
110
|
return schema;
|
|
76
111
|
}
|
|
77
112
|
/**
|
|
78
|
-
* @brief
|
|
113
|
+
* @brief Validate a NumberGuard constructor schema.
|
|
114
|
+
* @param schema Candidate runtime schema.
|
|
115
|
+
* @returns Number schema accepted by NumberGuard.
|
|
116
|
+
* @throws TypeError when the schema is not a number schema.
|
|
117
|
+
* @details Rejecting non-number schemas at construction prevents mixed scalar
|
|
118
|
+
* helper methods from observing incompatible check vectors.
|
|
79
119
|
*/
|
|
80
120
|
export function readNumberConstructorSchema(schema) {
|
|
81
121
|
if (!isSchemaValue(schema) || schema.tag !== SchemaTag.Number) {
|
|
@@ -84,7 +124,12 @@ export function readNumberConstructorSchema(schema) {
|
|
|
84
124
|
return schema;
|
|
85
125
|
}
|
|
86
126
|
/**
|
|
87
|
-
* @brief
|
|
127
|
+
* @brief Validate refinement API inputs.
|
|
128
|
+
* @param predicate Candidate refinement predicate.
|
|
129
|
+
* @param name Candidate diagnostic name.
|
|
130
|
+
* @throws TypeError when either input has the wrong runtime type.
|
|
131
|
+
* @details Refinements execute user code by design. This gate narrows the call
|
|
132
|
+
* target and diagnostic label before the schema stores them.
|
|
88
133
|
*/
|
|
89
134
|
export function checkRefinementInput(predicate, name) {
|
|
90
135
|
if (typeof predicate !== "function") {
|
|
@@ -95,7 +140,13 @@ export function checkRefinementInput(predicate, name) {
|
|
|
95
140
|
}
|
|
96
141
|
}
|
|
97
142
|
/**
|
|
98
|
-
* @brief
|
|
143
|
+
* @brief Validate a non-negative string length bound.
|
|
144
|
+
* @param value Candidate bound.
|
|
145
|
+
* @param label Bound label used in RangeError messages.
|
|
146
|
+
* @returns The validated bound.
|
|
147
|
+
* @throws RangeError when the bound is negative or non-integer.
|
|
148
|
+
* @details Bounds are checked once at builder time so generated validators can
|
|
149
|
+
* emit straight comparisons without defensive range checks.
|
|
99
150
|
*/
|
|
100
151
|
export function checkStringLengthBound(value, label) {
|
|
101
152
|
if (!Number.isInteger(value) || value < 0) {
|
|
@@ -104,7 +155,13 @@ export function checkStringLengthBound(value, label) {
|
|
|
104
155
|
return value;
|
|
105
156
|
}
|
|
106
157
|
/**
|
|
107
|
-
* @brief
|
|
158
|
+
* @brief Validate a finite numeric bound.
|
|
159
|
+
* @param value Candidate bound.
|
|
160
|
+
* @param label Bound label used in RangeError messages.
|
|
161
|
+
* @returns The validated bound.
|
|
162
|
+
* @throws RangeError when the bound is not finite.
|
|
163
|
+
* @details Finite bounds keep interpreter, plan, and emitted code semantics
|
|
164
|
+
* aligned for comparisons such as gte and lte.
|
|
108
165
|
*/
|
|
109
166
|
export function checkFiniteNumberBound(value, label) {
|
|
110
167
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
@@ -112,3 +169,19 @@ export function checkFiniteNumberBound(value, label) {
|
|
|
112
169
|
}
|
|
113
170
|
return value;
|
|
114
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* @brief Read one own data slot from a structural guard receiver.
|
|
174
|
+
* @param value Candidate receiver.
|
|
175
|
+
* @param key Field name or symbol.
|
|
176
|
+
* @returns Stored field value, or undefined when the slot is absent.
|
|
177
|
+
* @details Structural guard support is intentionally narrow: inherited schema
|
|
178
|
+
* getters must not execute while validating detached method receivers.
|
|
179
|
+
*/
|
|
180
|
+
function readOwnDataProperty(value, key) {
|
|
181
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
182
|
+
if (descriptor === undefined ||
|
|
183
|
+
!Object.prototype.hasOwnProperty.call(descriptor, "value")) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
return descriptor.value;
|
|
187
|
+
}
|
package/dist/guard/registry.d.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file registry.ts
|
|
3
3
|
* @brief Constructed guard receiver registry.
|
|
4
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
5
|
+
* existing guard instance.
|
|
4
6
|
*/
|
|
5
7
|
import type { BaseGuard } from "./base.js";
|
|
6
8
|
import type { Presence } from "./types.js";
|
|
7
9
|
/**
|
|
8
|
-
* @brief
|
|
10
|
+
* @brief Mark a guard instance as constructor-owned.
|
|
11
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
12
|
+
* existing guard instance.
|
|
13
|
+
* @param value Guard instance created by TypeSea constructors.
|
|
14
|
+
* @post The value can use the fast receiver validation path.
|
|
9
15
|
*/
|
|
10
16
|
export declare function registerConstructedGuard(value: object): void;
|
|
11
17
|
/**
|
|
12
|
-
* @brief
|
|
18
|
+
* @brief Test whether a receiver was built by a TypeSea guard constructor.
|
|
19
|
+
* @param value Candidate receiver.
|
|
20
|
+
* @returns True when the value was registered by a TypeSea guard constructor.
|
|
21
|
+
* @details Public methods use this check to skip structural schema validation
|
|
22
|
+
* only for receivers whose schema slot was already frozen during construction.
|
|
13
23
|
*/
|
|
14
24
|
export declare function isConstructedGuard(value: unknown): value is BaseGuard<unknown, Presence>;
|
|
15
25
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/guard/registry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/guard/registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAU3C;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAE5D;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAC9B,KAAK,EAAE,OAAO,GACf,KAAK,IAAI,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,CAEvC"}
|
package/dist/guard/registry.js
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file registry.ts
|
|
3
3
|
* @brief Constructed guard receiver registry.
|
|
4
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
5
|
+
* existing guard instance.
|
|
4
6
|
*/
|
|
5
7
|
import { isRecord } from "./props.js";
|
|
6
8
|
/**
|
|
7
|
-
* @brief constructed
|
|
9
|
+
* @brief Receiver identity table for guards constructed by TypeSea.
|
|
10
|
+
* @details Weak membership proves that a receiver passed a TypeSea constructor
|
|
11
|
+
* without adding public marker fields that user code could forge.
|
|
8
12
|
*/
|
|
9
13
|
const constructedGuards = new WeakSet();
|
|
10
14
|
/**
|
|
11
|
-
* @brief
|
|
15
|
+
* @brief Mark a guard instance as constructor-owned.
|
|
16
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
17
|
+
* existing guard instance.
|
|
18
|
+
* @param value Guard instance created by TypeSea constructors.
|
|
19
|
+
* @post The value can use the fast receiver validation path.
|
|
12
20
|
*/
|
|
13
21
|
export function registerConstructedGuard(value) {
|
|
14
22
|
constructedGuards.add(value);
|
|
15
23
|
}
|
|
16
24
|
/**
|
|
17
|
-
* @brief
|
|
25
|
+
* @brief Test whether a receiver was built by a TypeSea guard constructor.
|
|
26
|
+
* @param value Candidate receiver.
|
|
27
|
+
* @returns True when the value was registered by a TypeSea guard constructor.
|
|
28
|
+
* @details Public methods use this check to skip structural schema validation
|
|
29
|
+
* only for receivers whose schema slot was already frozen during construction.
|
|
18
30
|
*/
|
|
19
31
|
export function isConstructedGuard(value) {
|
|
20
32
|
return isRecord(value) && constructedGuards.has(value);
|
package/dist/guard/string.d.ts
CHANGED
|
@@ -1,36 +1,56 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file string.ts
|
|
3
3
|
* @brief String guard implementation.
|
|
4
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
5
|
+
* existing guard instance.
|
|
4
6
|
*/
|
|
5
7
|
import type { StringSchema } from "../schema/index.js";
|
|
6
8
|
import { BaseGuard } from "./base.js";
|
|
7
9
|
import type { Presence } from "./types.js";
|
|
8
10
|
/**
|
|
9
|
-
* @brief string
|
|
10
|
-
* @details
|
|
11
|
-
*
|
|
11
|
+
* @brief Persistent builder for string predicates.
|
|
12
|
+
* @details Refinement methods append schema checks and return fresh frozen
|
|
13
|
+
* guards, so shared guard values cannot be mutated by later chains.
|
|
12
14
|
*/
|
|
13
15
|
export declare class StringGuard<TPresence extends Presence = "required"> extends BaseGuard<string, TPresence> {
|
|
14
16
|
/**
|
|
15
|
-
* @brief
|
|
16
|
-
|
|
17
|
+
* @brief Construct a frozen string guard.
|
|
18
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
19
|
+
* existing guard instance.
|
|
20
|
+
* @param schema String schema backing this guard.
|
|
17
21
|
*/
|
|
18
22
|
constructor(schema: StringSchema);
|
|
19
23
|
/**
|
|
20
|
-
* @brief
|
|
21
|
-
|
|
24
|
+
* @brief Add a minimum string length.
|
|
25
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
26
|
+
* existing guard instance.
|
|
27
|
+
* @param value Non-negative integer lower length bound.
|
|
28
|
+
* @returns Fresh StringGuard with an appended min check.
|
|
29
|
+
*/
|
|
22
30
|
min(value: number): StringGuard<TPresence>;
|
|
23
31
|
/**
|
|
24
|
-
* @brief
|
|
25
|
-
|
|
32
|
+
* @brief Add a maximum string length.
|
|
33
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
34
|
+
* existing guard instance.
|
|
35
|
+
* @param value Non-negative integer upper length bound.
|
|
36
|
+
* @returns Fresh StringGuard with an appended max check.
|
|
37
|
+
*/
|
|
26
38
|
max(value: number): StringGuard<TPresence>;
|
|
27
39
|
/**
|
|
28
|
-
* @brief
|
|
29
|
-
|
|
40
|
+
* @brief Add a regular expression check.
|
|
41
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
42
|
+
* existing guard instance.
|
|
43
|
+
* @param pattern Plain RegExp instance to clone into the schema.
|
|
44
|
+
* @param name Diagnostic name for pattern failures.
|
|
45
|
+
* @returns Fresh StringGuard with an appended regex check.
|
|
46
|
+
*/
|
|
30
47
|
regex(pattern: RegExp, name: string): StringGuard<TPresence>;
|
|
31
48
|
/**
|
|
32
|
-
* @brief
|
|
33
|
-
|
|
49
|
+
* @brief Add the built-in UUID string check.
|
|
50
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
51
|
+
* existing guard instance.
|
|
52
|
+
* @returns Fresh StringGuard with an appended uuid check.
|
|
53
|
+
*/
|
|
34
54
|
uuid(): StringGuard<TPresence>;
|
|
35
55
|
}
|
|
36
56
|
//# sourceMappingURL=string.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/guard/string.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/guard/string.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAOtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;GAIG;AACH,qBAAa,WAAW,CACpB,SAAS,SAAS,QAAQ,GAAG,UAAU,CACzC,SAAQ,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC;IAElC;;;;;OAKG;gBACgB,MAAM,EAAE,YAAY;IAKvC;;;;;;OAMG;IACI,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC;IAejD;;;;;;OAMG;IACI,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC;IAejD;;;;;;;OAOG;IACI,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC;IAyBnE;;;;;OAKG;IACI,IAAI,IAAI,WAAW,CAAC,SAAS,CAAC;CAYxC"}
|
package/dist/guard/string.js
CHANGED
|
@@ -1,28 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file string.ts
|
|
3
3
|
* @brief String guard implementation.
|
|
4
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
5
|
+
* existing guard instance.
|
|
4
6
|
*/
|
|
5
7
|
import { SchemaTag, StringCheckTag } from "../kind/index.js";
|
|
6
8
|
import { BaseGuard } from "./base.js";
|
|
7
9
|
import { isPlainRegExp } from "./props.js";
|
|
8
10
|
import { checkStringLengthBound, readStringConstructorSchema, readStringMethodSchema } from "./read.js";
|
|
9
11
|
/**
|
|
10
|
-
* @brief string
|
|
11
|
-
* @details
|
|
12
|
-
*
|
|
12
|
+
* @brief Persistent builder for string predicates.
|
|
13
|
+
* @details Refinement methods append schema checks and return fresh frozen
|
|
14
|
+
* guards, so shared guard values cannot be mutated by later chains.
|
|
13
15
|
*/
|
|
14
16
|
export class StringGuard extends BaseGuard {
|
|
15
17
|
/**
|
|
16
|
-
* @brief
|
|
17
|
-
|
|
18
|
+
* @brief Construct a frozen string guard.
|
|
19
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
20
|
+
* existing guard instance.
|
|
21
|
+
* @param schema String schema backing this guard.
|
|
18
22
|
*/
|
|
19
23
|
constructor(schema) {
|
|
20
24
|
super(readStringConstructorSchema(schema));
|
|
21
25
|
Object.freeze(this);
|
|
22
26
|
}
|
|
23
27
|
/**
|
|
24
|
-
* @brief
|
|
25
|
-
|
|
28
|
+
* @brief Add a minimum string length.
|
|
29
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
30
|
+
* existing guard instance.
|
|
31
|
+
* @param value Non-negative integer lower length bound.
|
|
32
|
+
* @returns Fresh StringGuard with an appended min check.
|
|
33
|
+
*/
|
|
26
34
|
min(value) {
|
|
27
35
|
const schema = readStringMethodSchema(this, "string min receiver");
|
|
28
36
|
const bound = checkStringLengthBound(value, "min");
|
|
@@ -38,8 +46,12 @@ export class StringGuard extends BaseGuard {
|
|
|
38
46
|
});
|
|
39
47
|
}
|
|
40
48
|
/**
|
|
41
|
-
* @brief
|
|
42
|
-
|
|
49
|
+
* @brief Add a maximum string length.
|
|
50
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
51
|
+
* existing guard instance.
|
|
52
|
+
* @param value Non-negative integer upper length bound.
|
|
53
|
+
* @returns Fresh StringGuard with an appended max check.
|
|
54
|
+
*/
|
|
43
55
|
max(value) {
|
|
44
56
|
const schema = readStringMethodSchema(this, "string max receiver");
|
|
45
57
|
const bound = checkStringLengthBound(value, "max");
|
|
@@ -55,8 +67,13 @@ export class StringGuard extends BaseGuard {
|
|
|
55
67
|
});
|
|
56
68
|
}
|
|
57
69
|
/**
|
|
58
|
-
* @brief
|
|
59
|
-
|
|
70
|
+
* @brief Add a regular expression check.
|
|
71
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
72
|
+
* existing guard instance.
|
|
73
|
+
* @param pattern Plain RegExp instance to clone into the schema.
|
|
74
|
+
* @param name Diagnostic name for pattern failures.
|
|
75
|
+
* @returns Fresh StringGuard with an appended regex check.
|
|
76
|
+
*/
|
|
60
77
|
regex(pattern, name) {
|
|
61
78
|
if (!isPlainRegExp(pattern)) {
|
|
62
79
|
throw new TypeError("regex pattern must be a plain RegExp");
|
|
@@ -65,6 +82,10 @@ export class StringGuard extends BaseGuard {
|
|
|
65
82
|
throw new TypeError("regex name must be a string");
|
|
66
83
|
}
|
|
67
84
|
const schema = readStringMethodSchema(this, "string regex receiver");
|
|
85
|
+
/*
|
|
86
|
+
* Clone the pattern so later mutation of lastIndex or subclass state on
|
|
87
|
+
* the caller-owned RegExp cannot affect validation.
|
|
88
|
+
*/
|
|
68
89
|
return new StringGuard({
|
|
69
90
|
tag: SchemaTag.String,
|
|
70
91
|
checks: [
|
|
@@ -78,8 +99,11 @@ export class StringGuard extends BaseGuard {
|
|
|
78
99
|
});
|
|
79
100
|
}
|
|
80
101
|
/**
|
|
81
|
-
* @brief
|
|
82
|
-
|
|
102
|
+
* @brief Add the built-in UUID string check.
|
|
103
|
+
* @details Guard helpers build new immutable schema wrappers so fluent APIs never mutate an
|
|
104
|
+
* existing guard instance.
|
|
105
|
+
* @returns Fresh StringGuard with an appended uuid check.
|
|
106
|
+
*/
|
|
83
107
|
uuid() {
|
|
84
108
|
const schema = readStringMethodSchema(this, "string uuid receiver");
|
|
85
109
|
return new StringGuard({
|