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/compile/types.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file compile/types.ts
|
|
3
3
|
* @brief Shared compile-time data contracts.
|
|
4
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
5
|
+
* stable across runtime and AOT emission.
|
|
4
6
|
*/
|
|
5
7
|
import type { Guard, Presence } from "../guard/index.js";
|
|
6
8
|
import type { LiteralValue, Schema } from "../schema/index.js";
|
|
7
9
|
/**
|
|
8
10
|
* @brief emit context.
|
|
11
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
12
|
+
* stable across runtime and AOT emission.
|
|
9
13
|
*/
|
|
10
14
|
export interface EmitContext {
|
|
15
|
+
readonly mode: CompileMode;
|
|
11
16
|
readonly literals: LiteralValue[];
|
|
12
17
|
readonly regexps: RegExp[];
|
|
13
18
|
readonly keysets: (readonly string[])[];
|
|
@@ -19,8 +24,16 @@ export interface EmitContext {
|
|
|
19
24
|
readonly checkFunctionNames: Map<Schema, string>;
|
|
20
25
|
readonly stringIndexes: Map<string, number>;
|
|
21
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* @brief compile mode.
|
|
29
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
30
|
+
* stable across runtime and AOT emission.
|
|
31
|
+
*/
|
|
32
|
+
export type CompileMode = "safe" | "unsafe" | "unchecked";
|
|
22
33
|
/**
|
|
23
34
|
* @brief function source.
|
|
35
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
36
|
+
* stable across runtime and AOT emission.
|
|
24
37
|
*/
|
|
25
38
|
export interface FunctionSource {
|
|
26
39
|
readonly name: string;
|
|
@@ -28,6 +41,8 @@ export interface FunctionSource {
|
|
|
28
41
|
}
|
|
29
42
|
/**
|
|
30
43
|
* @brief compiled source bundle.
|
|
44
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
45
|
+
* stable across runtime and AOT emission.
|
|
31
46
|
*/
|
|
32
47
|
export interface CompiledSourceBundle {
|
|
33
48
|
readonly source: string;
|
|
@@ -39,14 +54,19 @@ export interface CompiledSourceBundle {
|
|
|
39
54
|
}
|
|
40
55
|
/**
|
|
41
56
|
* @brief compiled guard.
|
|
57
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
58
|
+
* stable across runtime and AOT emission.
|
|
42
59
|
*/
|
|
43
60
|
export interface CompiledGuard<TValue, TPresence extends Presence = "required"> extends Guard<TValue, TPresence> {
|
|
44
61
|
readonly source: string;
|
|
45
62
|
}
|
|
46
63
|
/**
|
|
47
64
|
* @brief compile options.
|
|
65
|
+
* @details Generated-source helpers keep the side-table ABI and JavaScript source shape
|
|
66
|
+
* stable across runtime and AOT emission.
|
|
48
67
|
*/
|
|
49
68
|
export interface CompileOptions {
|
|
50
69
|
readonly name: string | undefined;
|
|
70
|
+
readonly mode: CompileMode | undefined;
|
|
51
71
|
}
|
|
52
72
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/compile/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/compile/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,KAAK,EAA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AC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC;IACjD,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa,CAC1B,MAAM,EACN,SAAS,SAAS,QAAQ,GAAG,UAAU,CACzC,SAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CAC3B;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,SAAS,CAAC;CAC1C"}
|
package/dist/compile/types.js
CHANGED
package/dist/decoder/index.d.ts
CHANGED
|
@@ -1,85 +1,67 @@
|
|
|
1
1
|
import type { Guard, Presence, RuntimeValue } from "../guard/index.js";
|
|
2
2
|
import type { CheckResult } from "../issue/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* @brief decode runner.
|
|
5
|
-
*/
|
|
6
3
|
type DecodeRunner<TValue> = (value: unknown) => CheckResult<TValue>;
|
|
7
4
|
/**
|
|
8
|
-
* @brief decoder
|
|
5
|
+
* @brief Private runner slot for decoder instances.
|
|
6
|
+
* @details A symbol slot keeps the public object small while avoiding accidental
|
|
7
|
+
* collision with user-visible properties.
|
|
9
8
|
*/
|
|
10
9
|
declare const DecoderRunSymbol: unique symbol;
|
|
11
|
-
/**
|
|
12
|
-
* @brief decode source.
|
|
13
|
-
*/
|
|
14
10
|
export type DecodeSource = Guard<unknown, Presence> | Decoder<unknown>;
|
|
15
|
-
/**
|
|
16
|
-
* @brief infer decoder.
|
|
17
|
-
*/
|
|
18
11
|
export type InferDecoder<TSource> = TSource extends Decoder<infer TValue> ? TValue : TSource extends Guard<infer TValue, infer TPresence> ? RuntimeValue<TValue, TPresence> : never;
|
|
19
12
|
/**
|
|
20
|
-
* @brief
|
|
13
|
+
* @brief Synchronous decode pipeline.
|
|
14
|
+
* @details Decoders are explicit Result producers; they do not throw for data
|
|
15
|
+
* validation failure.
|
|
21
16
|
*/
|
|
22
17
|
export interface Decoder<TValue> {
|
|
23
|
-
/**
|
|
24
|
-
* @brief decode.
|
|
25
|
-
*/
|
|
26
18
|
decode(value: unknown): CheckResult<TValue>;
|
|
27
|
-
/**
|
|
28
|
-
* @brief transform.
|
|
29
|
-
*/
|
|
30
19
|
transform<TNext>(mapper: (value: TValue) => TNext): BaseDecoder<TNext>;
|
|
31
|
-
/**
|
|
32
|
-
* @brief pipe.
|
|
33
|
-
*/
|
|
34
20
|
pipe<TNext extends DecodeSource>(next: TNext): BaseDecoder<InferDecoder<TNext>>;
|
|
35
21
|
}
|
|
36
22
|
/**
|
|
37
|
-
* @brief
|
|
38
|
-
* @details
|
|
39
|
-
*
|
|
23
|
+
* @brief Frozen decoder wrapper around one runner function.
|
|
24
|
+
* @details Methods re-read the symbol runner from the receiver so detached
|
|
25
|
+
* method calls fail with TypeSea errors instead of touching undefined state.
|
|
40
26
|
*/
|
|
41
27
|
export declare class BaseDecoder<TValue> implements Decoder<TValue> {
|
|
42
28
|
private readonly [DecoderRunSymbol];
|
|
43
|
-
/**
|
|
44
|
-
* @brief constructor.
|
|
45
|
-
* @post The receiver is initialized according to the class invariant before it can be observed.
|
|
46
|
-
*/
|
|
47
29
|
constructor(run: DecodeRunner<TValue>);
|
|
48
|
-
/**
|
|
49
|
-
* @brief decode.
|
|
50
|
-
*/
|
|
51
30
|
decode(this: unknown, value: unknown): CheckResult<TValue>;
|
|
52
|
-
/**
|
|
53
|
-
* @brief transform.
|
|
54
|
-
*/
|
|
55
31
|
transform<TNext>(mapper: (value: TValue) => TNext): BaseDecoder<TNext>;
|
|
56
|
-
/**
|
|
57
|
-
* @brief pipe.
|
|
58
|
-
*/
|
|
59
32
|
pipe<TNext extends DecodeSource>(next: TNext): BaseDecoder<InferDecoder<TNext>>;
|
|
60
33
|
}
|
|
61
34
|
/**
|
|
62
|
-
* @brief decoder.
|
|
35
|
+
* @brief Wrap a guard or decoder as a synchronous decoder pipeline.
|
|
36
|
+
* @details Decoder helpers keep validation failures explicit in Result values while
|
|
37
|
+
* preserving the original input value.
|
|
63
38
|
*/
|
|
64
39
|
export declare function decoder<TValue, TPresence extends Presence>(source: Guard<TValue, TPresence>): BaseDecoder<RuntimeValue<TValue, TPresence>>;
|
|
65
40
|
/**
|
|
66
|
-
* @brief decoder.
|
|
41
|
+
* @brief Execute decoder.
|
|
42
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
67
43
|
*/
|
|
68
44
|
export declare function decoder<TValue>(source: Decoder<TValue>): BaseDecoder<TValue>;
|
|
69
45
|
/**
|
|
70
|
-
* @brief
|
|
46
|
+
* @brief Build a decoder and append a synchronous mapper.
|
|
47
|
+
* @details Decoder helpers keep validation failures explicit in Result values while
|
|
48
|
+
* preserving the original input value.
|
|
71
49
|
*/
|
|
72
50
|
export declare function transform<TValue, TPresence extends Presence, TNext>(source: Guard<TValue, TPresence>, mapper: (value: RuntimeValue<TValue, TPresence>) => TNext): BaseDecoder<TNext>;
|
|
73
51
|
/**
|
|
74
|
-
* @brief transform.
|
|
52
|
+
* @brief Execute transform.
|
|
53
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
75
54
|
*/
|
|
76
55
|
export declare function transform<TValue, TNext>(source: Decoder<TValue>, mapper: (value: TValue) => TNext): BaseDecoder<TNext>;
|
|
77
56
|
/**
|
|
78
|
-
* @brief pipe.
|
|
57
|
+
* @brief Execute pipe.
|
|
58
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
79
59
|
*/
|
|
80
60
|
export declare function pipe<TNext extends DecodeSource>(source: DecodeSource, next: TNext): BaseDecoder<InferDecoder<TNext>>;
|
|
81
61
|
/**
|
|
82
|
-
* @brief
|
|
62
|
+
* @brief Primitive coercion decoders with explicit failure issues.
|
|
63
|
+
* @details Decoder helpers keep validation failures explicit in Result values while
|
|
64
|
+
* preserving the original input value.
|
|
83
65
|
*/
|
|
84
66
|
export declare const coerce: Readonly<{
|
|
85
67
|
readonly string: typeof coerceString;
|
|
@@ -87,19 +69,23 @@ export declare const coerce: Readonly<{
|
|
|
87
69
|
readonly boolean: typeof coerceBoolean;
|
|
88
70
|
}>;
|
|
89
71
|
/**
|
|
90
|
-
* @brief coerce string.
|
|
72
|
+
* @brief Execute coerce string.
|
|
73
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
91
74
|
*/
|
|
92
75
|
export declare function coerceString(): BaseDecoder<string>;
|
|
93
76
|
/**
|
|
94
|
-
* @brief coerce number.
|
|
77
|
+
* @brief Execute coerce number.
|
|
78
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
95
79
|
*/
|
|
96
80
|
export declare function coerceNumber(): BaseDecoder<number>;
|
|
97
81
|
/**
|
|
98
|
-
* @brief coerce boolean.
|
|
82
|
+
* @brief Execute coerce boolean.
|
|
83
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
99
84
|
*/
|
|
100
85
|
export declare function coerceBoolean(): BaseDecoder<boolean>;
|
|
101
86
|
/**
|
|
102
|
-
* @brief
|
|
87
|
+
* @brief Check decoder value.
|
|
88
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
103
89
|
*/
|
|
104
90
|
export declare function isDecoderValue(value: unknown): value is Decoder<unknown>;
|
|
105
91
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decoder/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAa,MAAM,mBAAmB,CAAC;AAMhE
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decoder/index.ts"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AEZ;;;GAGG;AACH,wBAAgB,YAAY,IAAI,WAAW,CAAC,MAAM,CAAC,CAkBlD;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,WAAW,CAAC,MAAM,CAAC,CAclD;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,WAAW,CAAC,OAAO,CAAC,CAiBpD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC,CAExE"}
|
package/dist/decoder/index.js
CHANGED
|
@@ -4,23 +4,23 @@ import { SchemaTag } from "../kind/index.js";
|
|
|
4
4
|
import { err } from "../result/index.js";
|
|
5
5
|
import { freezeSchema, isSchemaValue } from "../schema/index.js";
|
|
6
6
|
/**
|
|
7
|
-
* @brief decoder
|
|
7
|
+
* @brief Private runner slot for decoder instances.
|
|
8
|
+
* @details A symbol slot keeps the public object small while avoiding accidental
|
|
9
|
+
* collision with user-visible properties.
|
|
8
10
|
*/
|
|
9
11
|
const DecoderRunSymbol = Symbol("TypeSea.decoder.run");
|
|
10
12
|
/**
|
|
11
|
-
* @brief
|
|
13
|
+
* @brief Real decoder instances tracked without extending object lifetime.
|
|
14
|
+
* @details Decoder helpers keep validation failures explicit in Result values while
|
|
15
|
+
* preserving the original input value.
|
|
12
16
|
*/
|
|
13
17
|
const constructedDecoders = new WeakSet();
|
|
14
18
|
/**
|
|
15
|
-
* @brief
|
|
16
|
-
* @details
|
|
17
|
-
*
|
|
19
|
+
* @brief Frozen decoder wrapper around one runner function.
|
|
20
|
+
* @details Methods re-read the symbol runner from the receiver so detached
|
|
21
|
+
* method calls fail with TypeSea errors instead of touching undefined state.
|
|
18
22
|
*/
|
|
19
23
|
export class BaseDecoder {
|
|
20
|
-
/**
|
|
21
|
-
* @brief constructor.
|
|
22
|
-
* @post The receiver is initialized according to the class invariant before it can be observed.
|
|
23
|
-
*/
|
|
24
24
|
constructor(run) {
|
|
25
25
|
if (typeof run !== "function") {
|
|
26
26
|
throw new TypeError("decoder run must be a function");
|
|
@@ -29,15 +29,9 @@ export class BaseDecoder {
|
|
|
29
29
|
constructedDecoders.add(this);
|
|
30
30
|
Object.freeze(this);
|
|
31
31
|
}
|
|
32
|
-
/**
|
|
33
|
-
* @brief decode.
|
|
34
|
-
*/
|
|
35
32
|
decode(value) {
|
|
36
33
|
return readDecoderRunner(this, "decoder receiver")(value);
|
|
37
34
|
}
|
|
38
|
-
/**
|
|
39
|
-
* @brief transform.
|
|
40
|
-
*/
|
|
41
35
|
transform(mapper) {
|
|
42
36
|
if (typeof mapper !== "function") {
|
|
43
37
|
throw new TypeError("decoder transform mapper must be a function");
|
|
@@ -51,9 +45,6 @@ export class BaseDecoder {
|
|
|
51
45
|
return okResult(mapper(decoded.value));
|
|
52
46
|
});
|
|
53
47
|
}
|
|
54
|
-
/**
|
|
55
|
-
* @brief pipe.
|
|
56
|
-
*/
|
|
57
48
|
pipe(next) {
|
|
58
49
|
const run = readDecoderRunner(this, "decoder pipe receiver");
|
|
59
50
|
const nextRun = readDecodeSourceRunner(next, "decoder pipe target");
|
|
@@ -67,32 +58,38 @@ export class BaseDecoder {
|
|
|
67
58
|
}
|
|
68
59
|
}
|
|
69
60
|
/**
|
|
70
|
-
* @brief decoder.
|
|
61
|
+
* @brief Execute decoder.
|
|
62
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
71
63
|
*/
|
|
72
64
|
export function decoder(source) {
|
|
73
65
|
return makeDecoder(source);
|
|
74
66
|
}
|
|
75
67
|
/**
|
|
76
|
-
* @brief
|
|
68
|
+
* @brief Build decoder.
|
|
69
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
77
70
|
*/
|
|
78
71
|
function makeDecoder(source) {
|
|
79
72
|
const run = readDecodeSourceRunner(source, "decoder source");
|
|
80
73
|
return new BaseDecoder(run);
|
|
81
74
|
}
|
|
82
75
|
/**
|
|
83
|
-
* @brief transform.
|
|
76
|
+
* @brief Execute transform.
|
|
77
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
84
78
|
*/
|
|
85
79
|
export function transform(source, mapper) {
|
|
86
80
|
return makeDecoder(source).transform(mapper);
|
|
87
81
|
}
|
|
88
82
|
/**
|
|
89
|
-
* @brief pipe.
|
|
83
|
+
* @brief Execute pipe.
|
|
84
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
90
85
|
*/
|
|
91
86
|
export function pipe(source, next) {
|
|
92
87
|
return makeDecoder(source).pipe(next);
|
|
93
88
|
}
|
|
94
89
|
/**
|
|
95
|
-
* @brief
|
|
90
|
+
* @brief Primitive coercion decoders with explicit failure issues.
|
|
91
|
+
* @details Decoder helpers keep validation failures explicit in Result values while
|
|
92
|
+
* preserving the original input value.
|
|
96
93
|
*/
|
|
97
94
|
export const coerce = Object.freeze({
|
|
98
95
|
string: coerceString,
|
|
@@ -100,7 +97,8 @@ export const coerce = Object.freeze({
|
|
|
100
97
|
boolean: coerceBoolean
|
|
101
98
|
});
|
|
102
99
|
/**
|
|
103
|
-
* @brief coerce string.
|
|
100
|
+
* @brief Execute coerce string.
|
|
101
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
104
102
|
*/
|
|
105
103
|
export function coerceString() {
|
|
106
104
|
return new BaseDecoder((value) => {
|
|
@@ -122,7 +120,8 @@ export function coerceString() {
|
|
|
122
120
|
});
|
|
123
121
|
}
|
|
124
122
|
/**
|
|
125
|
-
* @brief coerce number.
|
|
123
|
+
* @brief Execute coerce number.
|
|
124
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
126
125
|
*/
|
|
127
126
|
export function coerceNumber() {
|
|
128
127
|
return new BaseDecoder((value) => {
|
|
@@ -140,7 +139,8 @@ export function coerceNumber() {
|
|
|
140
139
|
});
|
|
141
140
|
}
|
|
142
141
|
/**
|
|
143
|
-
* @brief coerce boolean.
|
|
142
|
+
* @brief Execute coerce boolean.
|
|
143
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
144
144
|
*/
|
|
145
145
|
export function coerceBoolean() {
|
|
146
146
|
return new BaseDecoder((value) => {
|
|
@@ -161,19 +161,29 @@ export function coerceBoolean() {
|
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
* @brief
|
|
164
|
+
* @brief Check decoder value.
|
|
165
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
165
166
|
*/
|
|
166
167
|
export function isDecoderValue(value) {
|
|
167
168
|
return isConstructedDecoder(value);
|
|
168
169
|
}
|
|
169
170
|
/**
|
|
170
|
-
* @brief
|
|
171
|
+
* @brief Test decoder identity through the private registry.
|
|
172
|
+
* @details Decoder helpers keep validation failures explicit in Result values while
|
|
173
|
+
* preserving the original input value.
|
|
174
|
+
* @param value Candidate decoder.
|
|
175
|
+
* @returns True when TypeSea constructed the decoder instance.
|
|
171
176
|
*/
|
|
172
177
|
function isConstructedDecoder(value) {
|
|
173
178
|
return isRecord(value) && constructedDecoders.has(value);
|
|
174
179
|
}
|
|
175
180
|
/**
|
|
176
|
-
* @brief
|
|
181
|
+
* @brief Resolve a decode source into an executable runner.
|
|
182
|
+
* @param source Decoder or guard-like value supplied by the caller.
|
|
183
|
+
* @param label Message prefix for TypeError diagnostics.
|
|
184
|
+
* @returns Function that validates one runtime value.
|
|
185
|
+
* @details Real decoders keep a private runner symbol. Guard-like values are
|
|
186
|
+
* lowered to schema checks after hardened schema normalization.
|
|
177
187
|
*/
|
|
178
188
|
function readDecodeSourceRunner(source, label) {
|
|
179
189
|
if (isConstructedDecoder(source)) {
|
|
@@ -183,7 +193,13 @@ function readDecodeSourceRunner(source, label) {
|
|
|
183
193
|
return (value) => checkSchema(schema, value);
|
|
184
194
|
}
|
|
185
195
|
/**
|
|
186
|
-
* @brief
|
|
196
|
+
* @brief Read the private runner from a constructed decoder.
|
|
197
|
+
* @details Decoder helpers keep validation failures explicit in Result values while
|
|
198
|
+
* preserving the original input value.
|
|
199
|
+
* @param value Candidate decoder object.
|
|
200
|
+
* @param label Message prefix for TypeError diagnostics.
|
|
201
|
+
* @returns Stored decode runner.
|
|
202
|
+
* @throws TypeError when the value was not registered by a decoder constructor.
|
|
187
203
|
*/
|
|
188
204
|
function readDecoderRunner(value, label) {
|
|
189
205
|
if (!isConstructedDecoder(value)) {
|
|
@@ -192,20 +208,30 @@ function readDecoderRunner(value, label) {
|
|
|
192
208
|
return value[DecoderRunSymbol];
|
|
193
209
|
}
|
|
194
210
|
/**
|
|
195
|
-
* @brief
|
|
211
|
+
* @brief Normalize a guard-like value used as a decode source.
|
|
212
|
+
* @param value Candidate guard-like source.
|
|
213
|
+
* @param label Message prefix for TypeError diagnostics.
|
|
214
|
+
* @returns Frozen schema used by the generated decode runner.
|
|
215
|
+
* @throws TypeError when the schema slot is absent or malformed.
|
|
216
|
+
* @details Descriptor reads keep inherited schema getters out of the decode
|
|
217
|
+
* pipeline before the schema is frozen for repeated use.
|
|
196
218
|
*/
|
|
197
219
|
function readGuardSchema(value, label) {
|
|
198
220
|
if (!isRecord(value)) {
|
|
199
221
|
throw new TypeError(`${label} must be a TypeSea guard or decoder`);
|
|
200
222
|
}
|
|
201
|
-
const schema = value
|
|
223
|
+
const schema = readOwnDataProperty(value, "schema");
|
|
202
224
|
if (!isSchemaValue(schema)) {
|
|
203
225
|
throw new TypeError(`${label} must contain a valid TypeSea schema`);
|
|
204
226
|
}
|
|
205
227
|
return freezeSchema(schema);
|
|
206
228
|
}
|
|
207
229
|
/**
|
|
208
|
-
* @brief
|
|
230
|
+
* @brief Build a frozen success Result for decoder transforms.
|
|
231
|
+
* @details Decoder helpers keep validation failures explicit in Result values while
|
|
232
|
+
* preserving the original input value.
|
|
233
|
+
* @param value Decoded value.
|
|
234
|
+
* @returns Frozen ok result.
|
|
209
235
|
*/
|
|
210
236
|
function okResult(value) {
|
|
211
237
|
return Object.freeze({
|
|
@@ -214,7 +240,13 @@ function okResult(value) {
|
|
|
214
240
|
});
|
|
215
241
|
}
|
|
216
242
|
/**
|
|
217
|
-
* @brief
|
|
243
|
+
* @brief Build a frozen single-issue failure Result.
|
|
244
|
+
* @details Decoder helpers keep validation failures explicit in Result values while
|
|
245
|
+
* preserving the original input value.
|
|
246
|
+
* @param code Issue code.
|
|
247
|
+
* @param expected Expected value description.
|
|
248
|
+
* @param value Runtime value that failed validation.
|
|
249
|
+
* @returns Failure result with a root-level issue.
|
|
218
250
|
*/
|
|
219
251
|
function fail(code, expected, value) {
|
|
220
252
|
return err(freezeIssueArray([
|
|
@@ -222,7 +254,11 @@ function fail(code, expected, value) {
|
|
|
222
254
|
]));
|
|
223
255
|
}
|
|
224
256
|
/**
|
|
225
|
-
* @brief
|
|
257
|
+
* @brief Produce the compact runtime type label used in decoder issues.
|
|
258
|
+
* @details Decoder helpers keep validation failures explicit in Result values while
|
|
259
|
+
* preserving the original input value.
|
|
260
|
+
* @param value Runtime value.
|
|
261
|
+
* @returns Stable diagnostic type name.
|
|
226
262
|
*/
|
|
227
263
|
function actualType(value) {
|
|
228
264
|
if (value === null) {
|
|
@@ -237,7 +273,13 @@ function actualType(value) {
|
|
|
237
273
|
return typeof value;
|
|
238
274
|
}
|
|
239
275
|
/**
|
|
240
|
-
* @brief
|
|
276
|
+
* @brief Define one immutable decoder instance slot.
|
|
277
|
+
* @details Decoder helpers keep validation failures explicit in Result values while
|
|
278
|
+
* preserving the original input value.
|
|
279
|
+
* @param target Decoder instance.
|
|
280
|
+
* @param key Public key or private symbol.
|
|
281
|
+
* @param value Stored field value.
|
|
282
|
+
* @param enumerable Whether the field should appear in enumeration.
|
|
241
283
|
*/
|
|
242
284
|
function defineReadonlyProperty(target, key, value, enumerable) {
|
|
243
285
|
Object.defineProperty(target, key, {
|
|
@@ -248,13 +290,35 @@ function defineReadonlyProperty(target, key, value, enumerable) {
|
|
|
248
290
|
});
|
|
249
291
|
}
|
|
250
292
|
/**
|
|
251
|
-
* @brief
|
|
293
|
+
* @brief Accept objects that can carry decoder or guard fields.
|
|
294
|
+
* @details Decoder helpers keep validation failures explicit in Result values while
|
|
295
|
+
* preserving the original input value.
|
|
296
|
+
* @param value Candidate object.
|
|
297
|
+
* @returns True for non-array objects.
|
|
252
298
|
*/
|
|
253
299
|
function isRecord(value) {
|
|
254
300
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
255
301
|
}
|
|
256
302
|
/**
|
|
257
|
-
* @brief
|
|
303
|
+
* @brief Read one own data slot from a decode source.
|
|
304
|
+
* @details Decoder helpers keep validation failures explicit in Result values while
|
|
305
|
+
* preserving the original input value.
|
|
306
|
+
* @param value Object being normalized.
|
|
307
|
+
* @param key Field name or symbol.
|
|
308
|
+
* @returns Stored field value, or undefined when absent.
|
|
309
|
+
*/
|
|
310
|
+
function readOwnDataProperty(value, key) {
|
|
311
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
312
|
+
if (descriptor === undefined ||
|
|
313
|
+
!Object.prototype.hasOwnProperty.call(descriptor, "value")) {
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
316
|
+
return descriptor.value;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* @brief Reused finite-number schema for string-to-number coercion.
|
|
320
|
+
* @details Decoder helpers keep validation failures explicit in Result values while
|
|
321
|
+
* preserving the original input value.
|
|
258
322
|
*/
|
|
259
323
|
const numberSchema = Object.freeze({
|
|
260
324
|
tag: SchemaTag.Number,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file check-composite.ts
|
|
3
3
|
* @brief Composite diagnostic schema interpreters.
|
|
4
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
5
|
+
* aligned with compiled behavior.
|
|
4
6
|
*/
|
|
5
7
|
import { SchemaTag } from "../kind/index.js";
|
|
6
8
|
import type { Issue, PathSegment } from "../issue/index.js";
|
|
@@ -8,32 +10,89 @@ import type { DiscriminatedUnionCase, Schema } from "../schema/index.js";
|
|
|
8
10
|
import type { ValidationState } from "./state.js";
|
|
9
11
|
/**
|
|
10
12
|
* @brief issue collector.
|
|
13
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
14
|
+
* aligned with compiled behavior.
|
|
11
15
|
*/
|
|
12
16
|
export type IssueCollector = (schema: Schema, value: unknown, path: PathSegment[], issues: Issue[], state: ValidationState) => void;
|
|
13
17
|
/**
|
|
14
18
|
* @brief collect array issues.
|
|
19
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
20
|
+
* aligned with compiled behavior.
|
|
21
|
+
* @param item Schema applied to each logical array slot.
|
|
22
|
+
* @param value Candidate value supplied by the caller.
|
|
23
|
+
* @param path Mutable path stack reused by the diagnostic walker.
|
|
24
|
+
* @param issues Output issue buffer.
|
|
25
|
+
* @param state Shared recursion and cycle state.
|
|
26
|
+
* @param collectChild Dispatcher for nested schema diagnostics.
|
|
27
|
+
* @post Every pushed path segment is popped before return.
|
|
15
28
|
*/
|
|
16
29
|
export declare function collectArrayIssues(item: Schema, value: unknown, path: PathSegment[], issues: Issue[], state: ValidationState, collectChild: IssueCollector): void;
|
|
17
30
|
/**
|
|
18
31
|
* @brief collect tuple issues.
|
|
32
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
33
|
+
* aligned with compiled behavior.
|
|
34
|
+
* @param items Tuple item schemas.
|
|
35
|
+
* @param value Candidate runtime value.
|
|
36
|
+
* @param path Mutable path stack reused by the diagnostic walker.
|
|
37
|
+
* @param issues Output issue buffer.
|
|
38
|
+
* @param state Shared recursion and cycle state.
|
|
39
|
+
* @param collectChild Dispatcher for nested schema diagnostics.
|
|
40
|
+
* @post Every pushed tuple index is popped before return.
|
|
19
41
|
*/
|
|
20
42
|
export declare function collectTupleIssues(items: readonly Schema[], value: unknown, path: PathSegment[], issues: Issue[], state: ValidationState, collectChild: IssueCollector): void;
|
|
21
43
|
/**
|
|
22
44
|
* @brief collect record issues.
|
|
45
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
46
|
+
* aligned with compiled behavior.
|
|
47
|
+
* @param item Schema applied to each own enumerable record value.
|
|
48
|
+
* @param value Candidate runtime value.
|
|
49
|
+
* @param path Mutable path stack reused by the diagnostic walker.
|
|
50
|
+
* @param issues Output issue buffer.
|
|
51
|
+
* @param state Shared recursion and cycle state.
|
|
52
|
+
* @param collectChild Dispatcher for nested schema diagnostics.
|
|
53
|
+
* @post Every pushed record key is popped before return.
|
|
23
54
|
*/
|
|
24
55
|
export declare function collectRecordIssues(item: Schema, value: unknown, path: PathSegment[], issues: Issue[], state: ValidationState, collectChild: IssueCollector): void;
|
|
25
56
|
/**
|
|
26
57
|
* @brief collect object issues.
|
|
58
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
59
|
+
* aligned with compiled behavior.
|
|
60
|
+
* @param schema Object schema with entries and object mode.
|
|
61
|
+
* @param value Candidate runtime value.
|
|
62
|
+
* @param path Mutable path stack reused by the diagnostic walker.
|
|
63
|
+
* @param issues Output issue buffer.
|
|
64
|
+
* @param state Shared recursion and cycle state.
|
|
65
|
+
* @param collectChild Dispatcher for nested schema diagnostics.
|
|
66
|
+
* @post Every pushed object key is popped before return.
|
|
27
67
|
*/
|
|
28
68
|
export declare function collectObjectIssues(schema: Extract<Schema, {
|
|
29
69
|
readonly tag: typeof SchemaTag.Object;
|
|
30
70
|
}>, value: unknown, path: PathSegment[], issues: Issue[], state: ValidationState, collectChild: IssueCollector): void;
|
|
31
71
|
/**
|
|
32
72
|
* @brief collect discriminated union issues.
|
|
73
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
74
|
+
* aligned with compiled behavior.
|
|
75
|
+
* @param key Discriminant property key.
|
|
76
|
+
* @param cases Closed discriminated union cases.
|
|
77
|
+
* @param value Candidate runtime value.
|
|
78
|
+
* @param path Mutable path stack reused by the diagnostic walker.
|
|
79
|
+
* @param issues Output issue buffer.
|
|
80
|
+
* @param state Shared recursion and cycle state.
|
|
81
|
+
* @param collectChild Dispatcher for nested schema diagnostics.
|
|
33
82
|
*/
|
|
34
83
|
export declare function collectDiscriminatedUnionIssues(key: string, cases: readonly DiscriminatedUnionCase[], value: unknown, path: PathSegment[], issues: Issue[], state: ValidationState, collectChild: IssueCollector): void;
|
|
35
84
|
/**
|
|
36
85
|
* @brief collect refine issues.
|
|
86
|
+
* @details Interpreter helpers keep safe descriptor-based reads and diagnostic collection
|
|
87
|
+
* aligned with compiled behavior.
|
|
88
|
+
* @param inner Schema validated before the predicate runs.
|
|
89
|
+
* @param predicate User predicate that must return true.
|
|
90
|
+
* @param name Refinement name used in diagnostics.
|
|
91
|
+
* @param value Candidate runtime value.
|
|
92
|
+
* @param path Mutable path stack reused by the diagnostic walker.
|
|
93
|
+
* @param issues Output issue buffer.
|
|
94
|
+
* @param state Shared recursion and cycle state.
|
|
95
|
+
* @param collectChild Dispatcher for nested schema diagnostics.
|
|
37
96
|
*/
|
|
38
97
|
export declare function collectRefineIssues(inner: Schema, predicate: (value: unknown) => boolean, name: string, value: unknown, path: PathSegment[], issues: Issue[], state: ValidationState, collectChild: IssueCollector): void;
|
|
39
98
|
//# sourceMappingURL=check-composite.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-composite.d.ts","sourceRoot":"","sources":["../../src/evaluate/check-composite.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"check-composite.d.ts","sourceRoot":"","sources":["../../src/evaluate/check-composite.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAGH,SAAS,EACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EACR,sBAAsB,EACtB,MAAM,EACT,MAAM,oBAAoB,CAAC;AAe5B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,CACzB,MAAM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