typesea 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -6
- package/README.md +98 -17
- package/dist/adapters/index.d.ts +50 -8
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +169 -48
- package/dist/aot/index.d.ts +18 -2
- package/dist/aot/index.d.ts.map +1 -1
- package/dist/aot/index.js +93 -14
- package/dist/async/index.d.ts +28 -56
- package/dist/async/index.d.ts.map +1 -1
- package/dist/async/index.js +94 -37
- package/dist/builders/composite.d.ts +37 -6
- package/dist/builders/composite.d.ts.map +1 -1
- package/dist/builders/composite.js +84 -10
- package/dist/builders/index.d.ts +2 -0
- package/dist/builders/index.d.ts.map +1 -1
- package/dist/builders/index.js +2 -0
- package/dist/builders/modifier.d.ts +30 -5
- package/dist/builders/modifier.d.ts.map +1 -1
- package/dist/builders/modifier.js +38 -5
- package/dist/builders/object/guard.d.ts +18 -22
- package/dist/builders/object/guard.d.ts.map +1 -1
- package/dist/builders/object/guard.js +26 -26
- package/dist/builders/object/index.d.ts +2 -0
- package/dist/builders/object/index.d.ts.map +1 -1
- package/dist/builders/object/index.js +2 -0
- package/dist/builders/object/schema.d.ts +55 -9
- package/dist/builders/object/schema.d.ts.map +1 -1
- package/dist/builders/object/schema.js +92 -15
- package/dist/builders/object/types.d.ts +5 -31
- package/dist/builders/object/types.d.ts.map +1 -1
- package/dist/builders/object/types.js +2 -0
- package/dist/builders/scalar.d.ts +29 -8
- package/dist/builders/scalar.d.ts.map +1 -1
- package/dist/builders/scalar.js +33 -8
- package/dist/builders/table.d.ts +4 -0
- package/dist/builders/table.d.ts.map +1 -1
- package/dist/builders/table.js +4 -0
- package/dist/builders/types.d.ts +14 -4
- package/dist/builders/types.d.ts.map +1 -1
- package/dist/builders/types.js +2 -0
- package/dist/compile/check-composite.d.ts +22 -1
- package/dist/compile/check-composite.d.ts.map +1 -1
- package/dist/compile/check-composite.js +564 -24
- package/dist/compile/check-scalar.d.ts +78 -0
- package/dist/compile/check-scalar.d.ts.map +1 -1
- package/dist/compile/check-scalar.js +432 -1
- package/dist/compile/check.d.ts +12 -0
- package/dist/compile/check.d.ts.map +1 -1
- package/dist/compile/check.js +37 -0
- package/dist/compile/context.d.ts +47 -9
- package/dist/compile/context.d.ts.map +1 -1
- package/dist/compile/context.js +51 -8
- package/dist/compile/graph-predicate.d.ts +4 -2
- package/dist/compile/graph-predicate.d.ts.map +1 -1
- package/dist/compile/graph-predicate.js +1907 -171
- package/dist/compile/guard.d.ts +15 -24
- package/dist/compile/guard.d.ts.map +1 -1
- package/dist/compile/guard.js +158 -74
- package/dist/compile/index.d.ts +3 -1
- package/dist/compile/index.d.ts.map +1 -1
- package/dist/compile/index.js +2 -0
- package/dist/compile/issue.d.ts +110 -0
- package/dist/compile/issue.d.ts.map +1 -1
- package/dist/compile/issue.js +184 -1
- package/dist/compile/names.d.ts +12 -2
- package/dist/compile/names.d.ts.map +1 -1
- package/dist/compile/names.js +19 -3
- package/dist/compile/predicate.d.ts +24 -0
- package/dist/compile/predicate.d.ts.map +1 -1
- package/dist/compile/predicate.js +131 -5
- package/dist/compile/runtime.d.ts +80 -12
- package/dist/compile/runtime.d.ts.map +1 -1
- package/dist/compile/runtime.js +25 -6
- package/dist/compile/source.d.ts +10 -2
- package/dist/compile/source.d.ts.map +1 -1
- package/dist/compile/source.js +361 -26
- package/dist/compile/types.d.ts +20 -0
- package/dist/compile/types.d.ts.map +1 -1
- package/dist/compile/types.js +2 -0
- package/dist/decoder/index.d.ts +32 -46
- package/dist/decoder/index.d.ts.map +1 -1
- package/dist/decoder/index.js +102 -38
- package/dist/evaluate/check-composite.d.ts +59 -0
- package/dist/evaluate/check-composite.d.ts.map +1 -1
- package/dist/evaluate/check-composite.js +151 -3
- package/dist/evaluate/check-scalar.d.ts +16 -0
- package/dist/evaluate/check-scalar.d.ts.map +1 -1
- package/dist/evaluate/check-scalar.js +32 -0
- package/dist/evaluate/check.d.ts +7 -0
- package/dist/evaluate/check.d.ts.map +1 -1
- package/dist/evaluate/check.js +43 -0
- package/dist/evaluate/index.d.ts +2 -0
- package/dist/evaluate/index.d.ts.map +1 -1
- package/dist/evaluate/index.js +2 -0
- package/dist/evaluate/issue.d.ts +11 -1
- package/dist/evaluate/issue.d.ts.map +1 -1
- package/dist/evaluate/issue.js +15 -1
- package/dist/evaluate/predicate.d.ts +16 -5
- package/dist/evaluate/predicate.d.ts.map +1 -1
- package/dist/evaluate/predicate.js +20 -5
- package/dist/evaluate/shared.d.ts +59 -13
- package/dist/evaluate/shared.d.ts.map +1 -1
- package/dist/evaluate/shared.js +66 -8
- package/dist/evaluate/state.d.ts +35 -13
- package/dist/evaluate/state.d.ts.map +1 -1
- package/dist/evaluate/state.js +35 -2
- package/dist/guard/base.d.ts +79 -29
- package/dist/guard/base.d.ts.map +1 -1
- package/dist/guard/base.js +91 -29
- package/dist/guard/error.d.ts +10 -5
- package/dist/guard/error.d.ts.map +1 -1
- package/dist/guard/error.js +10 -5
- package/dist/guard/index.d.ts +2 -0
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +2 -0
- package/dist/guard/number.d.ts +26 -11
- package/dist/guard/number.d.ts.map +1 -1
- package/dist/guard/number.js +30 -11
- package/dist/guard/props.d.ts +27 -3
- package/dist/guard/props.d.ts.map +1 -1
- package/dist/guard/props.js +27 -3
- package/dist/guard/read.d.ts +62 -9
- package/dist/guard/read.d.ts.map +1 -1
- package/dist/guard/read.js +83 -10
- package/dist/guard/registry.d.ts +12 -2
- package/dist/guard/registry.d.ts.map +1 -1
- package/dist/guard/registry.js +15 -3
- package/dist/guard/string.d.ts +33 -13
- package/dist/guard/string.d.ts.map +1 -1
- package/dist/guard/string.js +37 -13
- package/dist/guard/types.d.ts +92 -40
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/guard/types.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/internal/index.d.ts +42 -6
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +51 -8
- package/dist/ir/builder.d.ts +16 -126
- package/dist/ir/builder.d.ts.map +1 -1
- package/dist/ir/builder.js +77 -137
- package/dist/ir/freeze.d.ts +4 -0
- package/dist/ir/freeze.d.ts.map +1 -1
- package/dist/ir/freeze.js +59 -0
- package/dist/ir/index.d.ts +3 -1
- package/dist/ir/index.d.ts.map +1 -1
- package/dist/ir/index.js +2 -0
- package/dist/ir/regexp.d.ts +2 -0
- package/dist/ir/regexp.d.ts.map +1 -1
- package/dist/ir/regexp.js +2 -0
- package/dist/ir/types.d.ts +90 -55
- package/dist/ir/types.d.ts.map +1 -1
- package/dist/ir/types.js +2 -0
- package/dist/ir/validate.d.ts +8 -1
- package/dist/ir/validate.d.ts.map +1 -1
- package/dist/ir/validate.js +477 -61
- package/dist/issue/index.d.ts +41 -9
- package/dist/issue/index.d.ts.map +1 -1
- package/dist/issue/index.js +61 -11
- package/dist/json-schema/emit-combinator.d.ts +44 -4
- package/dist/json-schema/emit-combinator.d.ts.map +1 -1
- package/dist/json-schema/emit-combinator.js +44 -4
- package/dist/json-schema/emit-composite.d.ts +10 -0
- package/dist/json-schema/emit-composite.d.ts.map +1 -1
- package/dist/json-schema/emit-composite.js +15 -1
- package/dist/json-schema/emit-scalar.d.ts +26 -3
- package/dist/json-schema/emit-scalar.d.ts.map +1 -1
- package/dist/json-schema/emit-scalar.js +70 -9
- package/dist/json-schema/emit-types.d.ts +11 -1
- package/dist/json-schema/emit-types.d.ts.map +1 -1
- package/dist/json-schema/emit-types.js +2 -0
- package/dist/json-schema/emit.d.ts +12 -1
- package/dist/json-schema/emit.d.ts.map +1 -1
- package/dist/json-schema/emit.js +12 -1
- package/dist/json-schema/freeze.d.ts +13 -2
- package/dist/json-schema/freeze.d.ts.map +1 -1
- package/dist/json-schema/freeze.js +41 -8
- package/dist/json-schema/index.d.ts +16 -2
- package/dist/json-schema/index.d.ts.map +1 -1
- package/dist/json-schema/index.js +23 -3
- package/dist/json-schema/issue.d.ts +4 -1
- package/dist/json-schema/issue.d.ts.map +1 -1
- package/dist/json-schema/issue.js +4 -1
- package/dist/json-schema/read.d.ts +24 -3
- package/dist/json-schema/read.d.ts.map +1 -1
- package/dist/json-schema/read.js +59 -12
- package/dist/json-schema/types.d.ts +38 -15
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/json-schema/types.js +2 -0
- package/dist/kind/index.d.ts +15 -28
- package/dist/kind/index.d.ts.map +1 -1
- package/dist/kind/index.js +15 -10
- package/dist/lower/index.d.ts +6 -1
- package/dist/lower/index.d.ts.map +1 -1
- package/dist/lower/index.js +411 -44
- package/dist/message/index.d.ts +46 -10
- package/dist/message/index.d.ts.map +1 -1
- package/dist/message/index.js +88 -17
- package/dist/optimize/algebraic.d.ts +54 -0
- package/dist/optimize/algebraic.d.ts.map +1 -0
- package/dist/optimize/algebraic.js +314 -0
- package/dist/optimize/compact.d.ts +8 -1
- package/dist/optimize/compact.d.ts.map +1 -1
- package/dist/optimize/compact.js +13 -2
- package/dist/optimize/domain.d.ts +16 -0
- package/dist/optimize/domain.d.ts.map +1 -0
- package/dist/optimize/domain.js +615 -0
- package/dist/optimize/fold-boolean.d.ts +17 -2
- package/dist/optimize/fold-boolean.d.ts.map +1 -1
- package/dist/optimize/fold-boolean.js +59 -14
- package/dist/optimize/fold-common.d.ts +43 -8
- package/dist/optimize/fold-common.d.ts.map +1 -1
- package/dist/optimize/fold-common.js +37 -6
- package/dist/optimize/fold-constraints.d.ts +33 -0
- package/dist/optimize/fold-constraints.d.ts.map +1 -0
- package/dist/optimize/fold-constraints.js +484 -0
- package/dist/optimize/fold-scalar.d.ts +98 -13
- package/dist/optimize/fold-scalar.d.ts.map +1 -1
- package/dist/optimize/fold-scalar.js +98 -13
- package/dist/optimize/fold.d.ts +8 -1
- package/dist/optimize/fold.d.ts.map +1 -1
- package/dist/optimize/fold.js +22 -2
- package/dist/optimize/index.d.ts +9 -1
- package/dist/optimize/index.d.ts.map +1 -1
- package/dist/optimize/index.js +18 -3
- package/dist/optimize/map-node.d.ts +3 -1
- package/dist/optimize/map-node.d.ts.map +1 -1
- package/dist/optimize/map-node.js +45 -3
- package/dist/optimize/peephole.d.ts +16 -0
- package/dist/optimize/peephole.d.ts.map +1 -0
- package/dist/optimize/peephole.js +254 -0
- package/dist/optimize/remap.d.ts +2 -0
- package/dist/optimize/remap.d.ts.map +1 -1
- package/dist/optimize/remap.js +2 -0
- package/dist/optimize/rewrite.d.ts +13 -8
- package/dist/optimize/rewrite.d.ts.map +1 -1
- package/dist/optimize/rewrite.js +13 -8
- package/dist/plan/cache.d.ts +9 -3
- package/dist/plan/cache.d.ts.map +1 -1
- package/dist/plan/cache.js +21 -5
- package/dist/plan/index.d.ts +2 -0
- package/dist/plan/index.d.ts.map +1 -1
- package/dist/plan/index.js +2 -0
- package/dist/plan/predicate.d.ts +2 -0
- package/dist/plan/predicate.d.ts.map +1 -1
- package/dist/plan/predicate.js +268 -29
- package/dist/plan/schema-predicate.d.ts +6 -0
- package/dist/plan/schema-predicate.d.ts.map +1 -1
- package/dist/plan/schema-predicate.js +117 -13
- package/dist/plan/types.d.ts +2 -0
- package/dist/plan/types.d.ts.map +1 -1
- package/dist/plan/types.js +2 -0
- package/dist/result/index.d.ts +19 -5
- package/dist/result/index.d.ts.map +1 -1
- package/dist/result/index.js +10 -2
- package/dist/schema/common.d.ts +69 -6
- package/dist/schema/common.d.ts.map +1 -1
- package/dist/schema/common.js +104 -10
- package/dist/schema/freeze.d.ts +4 -0
- package/dist/schema/freeze.d.ts.map +1 -1
- package/dist/schema/freeze.js +18 -0
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +3 -0
- package/dist/schema/lazy.d.ts +4 -0
- package/dist/schema/lazy.d.ts.map +1 -1
- package/dist/schema/lazy.js +4 -0
- package/dist/schema/literal.d.ts +7 -1
- package/dist/schema/literal.d.ts.map +1 -1
- package/dist/schema/literal.js +7 -1
- package/dist/schema/types.d.ts +20 -96
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js +5 -1
- package/dist/schema/undefined.d.ts +17 -0
- package/dist/schema/undefined.d.ts.map +1 -0
- package/dist/schema/undefined.js +72 -0
- package/dist/schema/validate.d.ts +8 -1
- package/dist/schema/validate.d.ts.map +1 -1
- package/dist/schema/validate.js +146 -55
- package/docs/api.md +57 -0
- package/docs/assets/benchmark-headline.svg +163 -0
- package/docs/engine-notes.md +58 -15
- package/docs/index.html +130 -110
- package/package.json +65 -65
|
@@ -1,95 +1,93 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file guard.ts
|
|
3
3
|
* @brief Object guard class and object builder API.
|
|
4
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
5
|
+
* with stable metadata.
|
|
4
6
|
*/
|
|
5
7
|
import { ObjectModeTag } from "../../kind/index.js";
|
|
6
8
|
import { BaseGuard } from "../../guard/index.js";
|
|
7
9
|
import { mergeObjectSchemas, objectSchema, omitObjectSchema, partialObjectSchema, pickObjectSchema, readObjectConstructorSchema, readObjectKeySelection, readObjectMethodSchema } from "./schema.js";
|
|
8
10
|
/**
|
|
9
11
|
* @brief Guard subclass with object-specific shape operations.
|
|
12
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
13
|
+
* with stable metadata.
|
|
10
14
|
*
|
|
11
15
|
* @invariant Methods preserve the original object mode. Strict schemas stay
|
|
12
16
|
* strict after shape edits; passthrough schemas stay passthrough.
|
|
13
17
|
*/
|
|
14
18
|
export class ObjectGuard extends BaseGuard {
|
|
15
|
-
/**
|
|
16
|
-
* @brief constructor.
|
|
17
|
-
* @post The receiver is initialized according to the class invariant before it can be observed.
|
|
18
|
-
*/
|
|
19
19
|
constructor(schema) {
|
|
20
20
|
super(readObjectConstructorSchema(schema));
|
|
21
21
|
Object.freeze(this);
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
* @brief extend.
|
|
25
|
-
*/
|
|
26
23
|
extend(extension) {
|
|
27
24
|
return extendObjectGuard(this, extension);
|
|
28
25
|
}
|
|
29
|
-
/**
|
|
30
|
-
* @brief pick.
|
|
31
|
-
*/
|
|
32
26
|
pick(keys) {
|
|
33
27
|
return pickObjectGuard(this, keys);
|
|
34
28
|
}
|
|
35
|
-
/**
|
|
36
|
-
* @brief omit.
|
|
37
|
-
*/
|
|
38
29
|
omit(keys) {
|
|
39
30
|
return omitObjectGuard(this, keys);
|
|
40
31
|
}
|
|
41
|
-
/**
|
|
42
|
-
* @brief partial.
|
|
43
|
-
*/
|
|
44
32
|
partial() {
|
|
45
33
|
return partialObjectGuard(this);
|
|
46
34
|
}
|
|
47
35
|
}
|
|
48
36
|
/**
|
|
49
|
-
* @brief object.
|
|
37
|
+
* @brief Build an object guard that accepts unspecified enumerable keys.
|
|
38
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
39
|
+
* with stable metadata.
|
|
50
40
|
*/
|
|
51
41
|
export function object(shape) {
|
|
52
42
|
return new ObjectGuard(objectSchema(shape, ObjectModeTag.Passthrough));
|
|
53
43
|
}
|
|
54
44
|
/**
|
|
55
|
-
* @brief
|
|
45
|
+
* @brief Build an object guard that rejects unspecified own keys.
|
|
46
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
47
|
+
* with stable metadata.
|
|
56
48
|
*/
|
|
57
49
|
export function strictObject(shape) {
|
|
58
50
|
return new ObjectGuard(objectSchema(shape, ObjectModeTag.Strict));
|
|
59
51
|
}
|
|
60
52
|
/**
|
|
61
|
-
* @brief extend.
|
|
53
|
+
* @brief Execute extend.
|
|
54
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
62
55
|
*/
|
|
63
56
|
export function extend(guard, extension) {
|
|
64
57
|
return extendObjectGuard(guard, extension);
|
|
65
58
|
}
|
|
66
59
|
/**
|
|
67
|
-
* @brief pick.
|
|
60
|
+
* @brief Execute pick.
|
|
61
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
68
62
|
*/
|
|
69
63
|
export function pick(guard, keys) {
|
|
70
64
|
return pickObjectGuard(guard, keys);
|
|
71
65
|
}
|
|
72
66
|
/**
|
|
73
|
-
* @brief omit.
|
|
67
|
+
* @brief Execute omit.
|
|
68
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
74
69
|
*/
|
|
75
70
|
export function omit(guard, keys) {
|
|
76
71
|
return omitObjectGuard(guard, keys);
|
|
77
72
|
}
|
|
78
73
|
/**
|
|
79
|
-
* @brief partial.
|
|
74
|
+
* @brief Execute partial.
|
|
75
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
80
76
|
*/
|
|
81
77
|
export function partial(guard) {
|
|
82
78
|
return partialObjectGuard(guard);
|
|
83
79
|
}
|
|
84
80
|
/**
|
|
85
|
-
* @brief extend object guard.
|
|
81
|
+
* @brief Execute extend object guard.
|
|
82
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
86
83
|
*/
|
|
87
84
|
function extendObjectGuard(guard, extension) {
|
|
88
85
|
const schema = readObjectMethodSchema(guard, "object extend receiver");
|
|
89
86
|
return new ObjectGuard(mergeObjectSchemas(schema, objectSchema(extension, schema.mode)));
|
|
90
87
|
}
|
|
91
88
|
/**
|
|
92
|
-
* @brief pick object guard.
|
|
89
|
+
* @brief Execute pick object guard.
|
|
90
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
93
91
|
*/
|
|
94
92
|
function pickObjectGuard(guard, keys) {
|
|
95
93
|
const schema = readObjectMethodSchema(guard, "object pick receiver");
|
|
@@ -97,7 +95,8 @@ function pickObjectGuard(guard, keys) {
|
|
|
97
95
|
return new ObjectGuard(pickObjectSchema(schema, selection));
|
|
98
96
|
}
|
|
99
97
|
/**
|
|
100
|
-
* @brief omit object guard.
|
|
98
|
+
* @brief Execute omit object guard.
|
|
99
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
101
100
|
*/
|
|
102
101
|
function omitObjectGuard(guard, keys) {
|
|
103
102
|
const schema = readObjectMethodSchema(guard, "object omit receiver");
|
|
@@ -105,7 +104,8 @@ function omitObjectGuard(guard, keys) {
|
|
|
105
104
|
return new ObjectGuard(omitObjectSchema(schema, selection));
|
|
106
105
|
}
|
|
107
106
|
/**
|
|
108
|
-
* @brief partial object guard.
|
|
107
|
+
* @brief Execute partial object guard.
|
|
108
|
+
* @details This helper keeps a local invariant explicit at the module boundary.
|
|
109
109
|
*/
|
|
110
110
|
function partialObjectGuard(guard) {
|
|
111
111
|
const schema = readObjectMethodSchema(guard, "object partial receiver");
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file index.ts
|
|
3
3
|
* @brief Public object builder aggregation.
|
|
4
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
5
|
+
* with stable metadata.
|
|
4
6
|
*/
|
|
5
7
|
export { ObjectGuard, extend, object, omit, partial, pick, strictObject } from "./guard.js";
|
|
6
8
|
export type { InferObject, MergeObjectShapes, ObjectGuardMode, ObjectShape, OmitObjectShape, PartialObjectShape, PickObjectShape } from "./types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/builders/object/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/builders/object/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACH,WAAW,EACX,MAAM,EACN,MAAM,EACN,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,YAAY,EACf,MAAM,YAAY,CAAC;AACpB,YAAY,EACR,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,eAAe,EAClB,MAAM,YAAY,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file index.ts
|
|
3
3
|
* @brief Public object builder aggregation.
|
|
4
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
5
|
+
* with stable metadata.
|
|
4
6
|
*/
|
|
5
7
|
export { ObjectGuard, extend, object, omit, partial, pick, strictObject } from "./guard.js";
|
|
@@ -1,44 +1,90 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file schema.ts
|
|
3
3
|
* @brief Object schema construction and shape rewrites.
|
|
4
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
5
|
+
* with stable metadata.
|
|
4
6
|
*/
|
|
5
7
|
import { ObjectModeTag } from "../../kind/index.js";
|
|
6
8
|
import type { ObjectEntry, ObjectSchema } from "../../schema/index.js";
|
|
7
9
|
import type { ObjectShape } from "./types.js";
|
|
8
10
|
/**
|
|
9
|
-
* @brief object
|
|
11
|
+
* @brief Normalize an object shape into ordered entries and lookup metadata.
|
|
12
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
13
|
+
* with stable metadata.
|
|
10
14
|
*/
|
|
11
15
|
export declare function objectSchema(shape: ObjectShape, mode: ObjectModeTag): ObjectSchema;
|
|
12
16
|
/**
|
|
13
|
-
* @brief object
|
|
17
|
+
* @brief Rebuild object metadata after shape transformations.
|
|
18
|
+
* @details Duplicate keys are rejected here so pick/omit/extend cannot create
|
|
19
|
+
* a schema that disagrees with its strict-key lookup table.
|
|
14
20
|
*/
|
|
15
21
|
export declare function objectSchemaFromEntries(sourceEntries: readonly ObjectEntry[], mode: ObjectModeTag): ObjectSchema;
|
|
16
22
|
/**
|
|
17
|
-
* @brief
|
|
23
|
+
* @brief Validate the schema value handed to an ObjectGuard constructor.
|
|
24
|
+
* @details Constructors are public JavaScript entry points, so the guard checks
|
|
25
|
+
* both the TypeSea schema marker and the object-schema tag before storing the
|
|
26
|
+
* value. This prevents forged objects from bypassing builder invariants.
|
|
27
|
+
* @param schema Candidate schema supplied to the constructor.
|
|
28
|
+
* @returns Object schema accepted by the constructor.
|
|
18
29
|
*/
|
|
19
30
|
export declare function readObjectConstructorSchema(schema: unknown): ObjectSchema;
|
|
20
31
|
/**
|
|
21
|
-
* @brief
|
|
32
|
+
* @brief Extract an object schema from another guard for object-only methods.
|
|
33
|
+
* @details Methods such as merge and extension compose object shapes. Accepting
|
|
34
|
+
* a scalar guard here would build an impossible schema, so the check is kept at
|
|
35
|
+
* the API edge with the caller-facing label in the error message.
|
|
36
|
+
* @param guard Candidate TypeSea guard.
|
|
37
|
+
* @param label Human-readable API label used in thrown errors.
|
|
38
|
+
* @returns Object schema owned by the supplied guard.
|
|
22
39
|
*/
|
|
23
40
|
export declare function readObjectMethodSchema(guard: unknown, label: string): ObjectSchema;
|
|
24
41
|
/**
|
|
25
|
-
* @brief
|
|
42
|
+
* @brief Merge two object schemas while letting extension keys override base keys.
|
|
43
|
+
* @details Existing base order is preserved for stable diagnostics and codegen.
|
|
44
|
+
* Extension-only keys are appended afterward, and the base strict/open mode is
|
|
45
|
+
* retained so shape extension does not silently change excess-key policy.
|
|
46
|
+
* @param base Source object schema being extended.
|
|
47
|
+
* @param extension Object schema whose matching keys replace base entries.
|
|
48
|
+
* @returns Rebuilt object schema with fresh lookup metadata.
|
|
26
49
|
*/
|
|
27
50
|
export declare function mergeObjectSchemas(base: ObjectSchema, extension: ObjectSchema): ObjectSchema;
|
|
28
51
|
/**
|
|
29
|
-
* @brief
|
|
52
|
+
* @brief Build an object schema containing only a validated key selection.
|
|
53
|
+
* @details The caller has already checked that keys are known and unique. This
|
|
54
|
+
* function preserves selection order so user-requested projection order is also
|
|
55
|
+
* the order used by diagnostics and generated object checks.
|
|
56
|
+
* @param schema Source object schema.
|
|
57
|
+
* @param keys Validated key selection.
|
|
58
|
+
* @returns Rebuilt object schema containing only selected entries.
|
|
30
59
|
*/
|
|
31
60
|
export declare function pickObjectSchema(schema: ObjectSchema, keys: readonly string[]): ObjectSchema;
|
|
32
61
|
/**
|
|
33
|
-
* @brief
|
|
62
|
+
* @brief Build an object schema with a validated key selection removed.
|
|
63
|
+
* @details Entries not listed for removal keep their original relative order
|
|
64
|
+
* and presence metadata. The object mode is preserved across the rewrite.
|
|
65
|
+
* @param schema Source object schema.
|
|
66
|
+
* @param keys Validated key selection to remove.
|
|
67
|
+
* @returns Rebuilt object schema without the selected entries.
|
|
34
68
|
*/
|
|
35
69
|
export declare function omitObjectSchema(schema: ObjectSchema, keys: readonly string[]): ObjectSchema;
|
|
36
70
|
/**
|
|
37
|
-
* @brief
|
|
71
|
+
* @brief Convert every object entry to optional presence.
|
|
72
|
+
* @details The child schemas are not wrapped or cloned; only field presence is
|
|
73
|
+
* rewritten. This keeps value-domain wrappers such as nullable and brand exactly
|
|
74
|
+
* as they were on the original entries.
|
|
75
|
+
* @param schema Source object schema.
|
|
76
|
+
* @returns Rebuilt object schema with optional entries.
|
|
38
77
|
*/
|
|
39
78
|
export declare function partialObjectSchema(schema: ObjectSchema): ObjectSchema;
|
|
40
79
|
/**
|
|
41
|
-
* @brief
|
|
80
|
+
* @brief Validate the key list supplied to object pick and omit operations.
|
|
81
|
+
* @details The returned array contains only known, unique string keys. This
|
|
82
|
+
* preflight keeps later schema rewriting simple and prevents silently selecting
|
|
83
|
+
* fields that were never part of the source object schema.
|
|
84
|
+
* @param keys Candidate key list from public API calls.
|
|
85
|
+
* @param schema Object schema whose keys define the valid selection domain.
|
|
86
|
+
* @param label Human-readable API label used in thrown errors.
|
|
87
|
+
* @returns Ordered key selection accepted by the object builder.
|
|
42
88
|
*/
|
|
43
89
|
export declare function readObjectKeySelection(keys: unknown, schema: ObjectSchema, label: string): readonly string[];
|
|
44
90
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/builders/object/schema.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/builders/object/schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACH,aAAa,EAGhB,MAAM,qBAAqB,CAAC;AAO7B,OAAO,KAAK,EACR,WAAW,EAEX,YAAY,EAEf,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAY9C;;;;GAIG;AACH,wBAAgB,YAAY,CACxB,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,aAAa,GACpB,YAAY,CAsBd;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACnC,aAAa,EAAE,SAAS,WAAW,EAAE,EACrC,IAAI,EAAE,aAAa,GACpB,YAAY,CAuBd;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAKzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAMlF;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAC9B,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,YAAY,GACxB,YAAY,CAed;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC5B,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,SAAS,MAAM,EAAE,GACxB,YAAY,CAad;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC5B,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,SAAS,MAAM,EAAE,GACxB,YAAY,CASd;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAatE;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAClC,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,MAAM,GACd,SAAS,MAAM,EAAE,CAmBnB"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file schema.ts
|
|
3
3
|
* @brief Object schema construction and shape rewrites.
|
|
4
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
5
|
+
* with stable metadata.
|
|
4
6
|
*/
|
|
5
7
|
import { ObjectModeTag, PresenceTag, SchemaTag } from "../../kind/index.js";
|
|
6
8
|
import { includesString, isRecord, isUnknownArray, readGuardSchema } from "../../internal/index.js";
|
|
7
9
|
import { isSchemaValue } from "../../schema/index.js";
|
|
8
10
|
/**
|
|
9
|
-
* @brief object
|
|
11
|
+
* @brief Normalize an object shape into ordered entries and lookup metadata.
|
|
12
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
13
|
+
* with stable metadata.
|
|
10
14
|
*/
|
|
11
15
|
export function objectSchema(shape, mode) {
|
|
12
16
|
if (!isRecord(shape)) {
|
|
@@ -30,7 +34,9 @@ export function objectSchema(shape, mode) {
|
|
|
30
34
|
return objectSchemaFromEntries(entries, mode);
|
|
31
35
|
}
|
|
32
36
|
/**
|
|
33
|
-
* @brief object
|
|
37
|
+
* @brief Rebuild object metadata after shape transformations.
|
|
38
|
+
* @details Duplicate keys are rejected here so pick/omit/extend cannot create
|
|
39
|
+
* a schema that disagrees with its strict-key lookup table.
|
|
34
40
|
*/
|
|
35
41
|
export function objectSchemaFromEntries(sourceEntries, mode) {
|
|
36
42
|
const entries = new Array(sourceEntries.length);
|
|
@@ -57,7 +63,12 @@ export function objectSchemaFromEntries(sourceEntries, mode) {
|
|
|
57
63
|
};
|
|
58
64
|
}
|
|
59
65
|
/**
|
|
60
|
-
* @brief
|
|
66
|
+
* @brief Validate the schema value handed to an ObjectGuard constructor.
|
|
67
|
+
* @details Constructors are public JavaScript entry points, so the guard checks
|
|
68
|
+
* both the TypeSea schema marker and the object-schema tag before storing the
|
|
69
|
+
* value. This prevents forged objects from bypassing builder invariants.
|
|
70
|
+
* @param schema Candidate schema supplied to the constructor.
|
|
71
|
+
* @returns Object schema accepted by the constructor.
|
|
61
72
|
*/
|
|
62
73
|
export function readObjectConstructorSchema(schema) {
|
|
63
74
|
if (!isSchemaValue(schema) || schema.tag !== SchemaTag.Object) {
|
|
@@ -66,7 +77,13 @@ export function readObjectConstructorSchema(schema) {
|
|
|
66
77
|
return schema;
|
|
67
78
|
}
|
|
68
79
|
/**
|
|
69
|
-
* @brief
|
|
80
|
+
* @brief Extract an object schema from another guard for object-only methods.
|
|
81
|
+
* @details Methods such as merge and extension compose object shapes. Accepting
|
|
82
|
+
* a scalar guard here would build an impossible schema, so the check is kept at
|
|
83
|
+
* the API edge with the caller-facing label in the error message.
|
|
84
|
+
* @param guard Candidate TypeSea guard.
|
|
85
|
+
* @param label Human-readable API label used in thrown errors.
|
|
86
|
+
* @returns Object schema owned by the supplied guard.
|
|
70
87
|
*/
|
|
71
88
|
export function readObjectMethodSchema(guard, label) {
|
|
72
89
|
const schema = readGuardSchema(guard, label);
|
|
@@ -76,7 +93,13 @@ export function readObjectMethodSchema(guard, label) {
|
|
|
76
93
|
return schema;
|
|
77
94
|
}
|
|
78
95
|
/**
|
|
79
|
-
* @brief
|
|
96
|
+
* @brief Merge two object schemas while letting extension keys override base keys.
|
|
97
|
+
* @details Existing base order is preserved for stable diagnostics and codegen.
|
|
98
|
+
* Extension-only keys are appended afterward, and the base strict/open mode is
|
|
99
|
+
* retained so shape extension does not silently change excess-key policy.
|
|
100
|
+
* @param base Source object schema being extended.
|
|
101
|
+
* @param extension Object schema whose matching keys replace base entries.
|
|
102
|
+
* @returns Rebuilt object schema with fresh lookup metadata.
|
|
80
103
|
*/
|
|
81
104
|
export function mergeObjectSchemas(base, extension) {
|
|
82
105
|
const entries = [];
|
|
@@ -95,7 +118,13 @@ export function mergeObjectSchemas(base, extension) {
|
|
|
95
118
|
return objectSchemaFromEntries(entries, base.mode);
|
|
96
119
|
}
|
|
97
120
|
/**
|
|
98
|
-
* @brief
|
|
121
|
+
* @brief Build an object schema containing only a validated key selection.
|
|
122
|
+
* @details The caller has already checked that keys are known and unique. This
|
|
123
|
+
* function preserves selection order so user-requested projection order is also
|
|
124
|
+
* the order used by diagnostics and generated object checks.
|
|
125
|
+
* @param schema Source object schema.
|
|
126
|
+
* @param keys Validated key selection.
|
|
127
|
+
* @returns Rebuilt object schema containing only selected entries.
|
|
99
128
|
*/
|
|
100
129
|
export function pickObjectSchema(schema, keys) {
|
|
101
130
|
const entries = new Array(keys.length);
|
|
@@ -112,7 +141,12 @@ export function pickObjectSchema(schema, keys) {
|
|
|
112
141
|
return objectSchemaFromEntries(entries, schema.mode);
|
|
113
142
|
}
|
|
114
143
|
/**
|
|
115
|
-
* @brief
|
|
144
|
+
* @brief Build an object schema with a validated key selection removed.
|
|
145
|
+
* @details Entries not listed for removal keep their original relative order
|
|
146
|
+
* and presence metadata. The object mode is preserved across the rewrite.
|
|
147
|
+
* @param schema Source object schema.
|
|
148
|
+
* @param keys Validated key selection to remove.
|
|
149
|
+
* @returns Rebuilt object schema without the selected entries.
|
|
116
150
|
*/
|
|
117
151
|
export function omitObjectSchema(schema, keys) {
|
|
118
152
|
const entries = [];
|
|
@@ -125,7 +159,12 @@ export function omitObjectSchema(schema, keys) {
|
|
|
125
159
|
return objectSchemaFromEntries(entries, schema.mode);
|
|
126
160
|
}
|
|
127
161
|
/**
|
|
128
|
-
* @brief
|
|
162
|
+
* @brief Convert every object entry to optional presence.
|
|
163
|
+
* @details The child schemas are not wrapped or cloned; only field presence is
|
|
164
|
+
* rewritten. This keeps value-domain wrappers such as nullable and brand exactly
|
|
165
|
+
* as they were on the original entries.
|
|
166
|
+
* @param schema Source object schema.
|
|
167
|
+
* @returns Rebuilt object schema with optional entries.
|
|
129
168
|
*/
|
|
130
169
|
export function partialObjectSchema(schema) {
|
|
131
170
|
const entries = new Array(schema.entries.length);
|
|
@@ -142,7 +181,14 @@ export function partialObjectSchema(schema) {
|
|
|
142
181
|
return objectSchemaFromEntries(entries, schema.mode);
|
|
143
182
|
}
|
|
144
183
|
/**
|
|
145
|
-
* @brief
|
|
184
|
+
* @brief Validate the key list supplied to object pick and omit operations.
|
|
185
|
+
* @details The returned array contains only known, unique string keys. This
|
|
186
|
+
* preflight keeps later schema rewriting simple and prevents silently selecting
|
|
187
|
+
* fields that were never part of the source object schema.
|
|
188
|
+
* @param keys Candidate key list from public API calls.
|
|
189
|
+
* @param schema Object schema whose keys define the valid selection domain.
|
|
190
|
+
* @param label Human-readable API label used in thrown errors.
|
|
191
|
+
* @returns Ordered key selection accepted by the object builder.
|
|
146
192
|
*/
|
|
147
193
|
export function readObjectKeySelection(keys, schema, label) {
|
|
148
194
|
if (!isUnknownArray(keys)) {
|
|
@@ -165,7 +211,13 @@ export function readObjectKeySelection(keys, schema, label) {
|
|
|
165
211
|
return selected;
|
|
166
212
|
}
|
|
167
213
|
/**
|
|
168
|
-
* @brief
|
|
214
|
+
* @brief Find an object entry by key using the ordered entry vector.
|
|
215
|
+
* @details The ordered vector is the source of truth for diagnostic and codegen
|
|
216
|
+
* order. The lookup table proves membership, while this helper recovers the
|
|
217
|
+
* full entry payload.
|
|
218
|
+
* @param entries Ordered object entries.
|
|
219
|
+
* @param key Field name to locate.
|
|
220
|
+
* @returns Matching object entry, or undefined when absent.
|
|
169
221
|
*/
|
|
170
222
|
function findObjectEntry(entries, key) {
|
|
171
223
|
for (let index = 0; index < entries.length; index += 1) {
|
|
@@ -177,13 +229,21 @@ function findObjectEntry(entries, key) {
|
|
|
177
229
|
return undefined;
|
|
178
230
|
}
|
|
179
231
|
/**
|
|
180
|
-
* @brief
|
|
232
|
+
* @brief Allocate a null-prototype lookup table for object schema keys.
|
|
233
|
+
* @details User field names may overlap with Object.prototype properties. A
|
|
234
|
+
* null-prototype table keeps membership checks data-only and avoids inherited
|
|
235
|
+
* keys participating in schema construction.
|
|
236
|
+
* @returns Empty key lookup table used by object schemas.
|
|
181
237
|
*/
|
|
182
238
|
function makeObjectKeyLookup() {
|
|
183
239
|
return Object.create(null);
|
|
184
240
|
}
|
|
185
241
|
/**
|
|
186
|
-
* @brief
|
|
242
|
+
* @brief Install one immutable key marker into an object-schema lookup table.
|
|
243
|
+
* @details Object keys are defined as own data properties so membership checks
|
|
244
|
+
* cannot be influenced by prototype state or later mutation of the table.
|
|
245
|
+
* @param target Null-prototype key lookup table.
|
|
246
|
+
* @param key Field name to mark as present.
|
|
187
247
|
*/
|
|
188
248
|
function defineObjectKey(target, key) {
|
|
189
249
|
Object.defineProperty(target, key, {
|
|
@@ -194,13 +254,23 @@ function defineObjectKey(target, key) {
|
|
|
194
254
|
});
|
|
195
255
|
}
|
|
196
256
|
/**
|
|
197
|
-
* @brief
|
|
257
|
+
* @brief Test object-schema key membership through the prepared lookup table.
|
|
258
|
+
* @details The table stores immutable true values, so direct indexed access is
|
|
259
|
+
* sufficient and avoids repeated descriptor allocation during builder work.
|
|
260
|
+
* @param keyLookup Null-prototype lookup table from the object schema.
|
|
261
|
+
* @param key Candidate field name.
|
|
262
|
+
* @returns True when the key belongs to the object schema.
|
|
198
263
|
*/
|
|
199
264
|
function hasObjectKey(keyLookup, key) {
|
|
200
265
|
return keyLookup[key] === true;
|
|
201
266
|
}
|
|
202
267
|
/**
|
|
203
|
-
* @brief
|
|
268
|
+
* @brief Split object-field presence from value-domain schema wrappers.
|
|
269
|
+
* @details Optional is the only wrapper that changes field presence. Other
|
|
270
|
+
* wrappers are rebuilt around the normalized inner schema so optionality can
|
|
271
|
+
* propagate outward without losing nullable, brand, or refinement behavior.
|
|
272
|
+
* @param schema Field schema supplied by the object builder.
|
|
273
|
+
* @returns Normalized child schema and required/optional presence tag.
|
|
204
274
|
*/
|
|
205
275
|
function normalizeObjectEntrySchema(schema) {
|
|
206
276
|
switch (schema.tag) {
|
|
@@ -240,7 +310,14 @@ function normalizeObjectEntrySchema(schema) {
|
|
|
240
310
|
}
|
|
241
311
|
}
|
|
242
312
|
/**
|
|
243
|
-
* @brief
|
|
313
|
+
* @brief Rebuild a wrapper after normalizing its inner object-field schema.
|
|
314
|
+
* @details When the inner schema stays required, the original wrapper can be
|
|
315
|
+
* kept unchanged. When optionality is discovered inside, the wrapper is rebuilt
|
|
316
|
+
* around the normalized child and the field presence becomes optional.
|
|
317
|
+
* @param inner Inner schema carried by the wrapper.
|
|
318
|
+
* @param wrap Function that rebuilds the same wrapper around a new child.
|
|
319
|
+
* @param original Original wrapper schema.
|
|
320
|
+
* @returns Normalized schema and presence tag for the object field.
|
|
244
321
|
*/
|
|
245
322
|
function normalizeWrappedObjectEntrySchema(inner, wrap, original) {
|
|
246
323
|
const normalized = normalizeObjectEntrySchema(inner);
|
|
@@ -1,63 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file types.ts
|
|
3
3
|
* @brief Object builder type algebra.
|
|
4
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
5
|
+
* with stable metadata.
|
|
4
6
|
*/
|
|
5
7
|
import type { BaseGuard, Guard, GuardPresence, GuardValue, Infer, Presence } from "../../guard/index.js";
|
|
6
8
|
import type { ObjectModeTag } from "../../kind/index.js";
|
|
7
|
-
/**
|
|
8
|
-
* @brief object shape.
|
|
9
|
-
*/
|
|
10
9
|
export type ObjectShape = Readonly<Record<string, Guard<unknown, Presence>>>;
|
|
11
|
-
/**
|
|
12
|
-
* @brief object guard mode.
|
|
13
|
-
*/
|
|
14
10
|
export type ObjectGuardMode = typeof ObjectModeTag.Passthrough | typeof ObjectModeTag.Strict;
|
|
15
|
-
/**
|
|
16
|
-
* @brief optional keys.
|
|
17
|
-
*/
|
|
18
11
|
export type OptionalKeys<TShape extends ObjectShape> = {
|
|
19
12
|
[TKey in keyof TShape]-?: GuardPresence<TShape[TKey]> extends "optional" ? TKey : never;
|
|
20
13
|
}[keyof TShape];
|
|
21
|
-
/**
|
|
22
|
-
* @brief required keys.
|
|
23
|
-
*/
|
|
24
14
|
export type RequiredKeys<TShape extends ObjectShape> = {
|
|
25
15
|
[TKey in keyof TShape]-?: GuardPresence<TShape[TKey]> extends "optional" ? never : TKey;
|
|
26
16
|
}[keyof TShape];
|
|
27
17
|
/**
|
|
28
|
-
* @brief
|
|
18
|
+
* @brief Infer required and optional object fields from guard presence tags.
|
|
19
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
20
|
+
* with stable metadata.
|
|
29
21
|
*/
|
|
30
22
|
export type InferObject<TShape extends ObjectShape> = Simplify<{
|
|
31
23
|
readonly [TKey in RequiredKeys<TShape>]: Infer<TShape[TKey]>;
|
|
32
24
|
} & {
|
|
33
25
|
readonly [TKey in OptionalKeys<TShape>]?: GuardValue<TShape[TKey]>;
|
|
34
26
|
}>;
|
|
35
|
-
/**
|
|
36
|
-
* @brief simplify.
|
|
37
|
-
*/
|
|
38
27
|
export type Simplify<TValue> = {
|
|
39
28
|
readonly [TKey in keyof TValue]: TValue[TKey];
|
|
40
29
|
} & {};
|
|
41
|
-
/**
|
|
42
|
-
* @brief merge object shapes.
|
|
43
|
-
*/
|
|
44
30
|
export type MergeObjectShapes<TBase extends ObjectShape, TExtension extends ObjectShape> = Simplify<Omit<TBase, keyof TExtension> & TExtension>;
|
|
45
|
-
/**
|
|
46
|
-
* @brief partial object shape.
|
|
47
|
-
*/
|
|
48
31
|
export type PartialObjectShape<TShape extends ObjectShape> = {
|
|
49
32
|
readonly [TKey in keyof TShape]: BaseGuard<GuardValue<TShape[TKey]>, "optional">;
|
|
50
33
|
};
|
|
51
|
-
/**
|
|
52
|
-
* @brief pick object shape.
|
|
53
|
-
*/
|
|
54
34
|
export type PickObjectShape<TShape extends ObjectShape, TKey extends string> = Pick<TShape, Extract<keyof TShape, TKey>>;
|
|
55
|
-
/**
|
|
56
|
-
* @brief omit object shape.
|
|
57
|
-
*/
|
|
58
35
|
export type OmitObjectShape<TShape extends ObjectShape, TKey extends string> = Omit<TShape, Extract<keyof TShape, TKey>>;
|
|
59
|
-
/**
|
|
60
|
-
* @brief string key of.
|
|
61
|
-
*/
|
|
62
36
|
export type StringKeyOf<TValue> = Extract<keyof TValue, string>;
|
|
63
37
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/object/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/object/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACR,SAAS,EACT,KAAK,EACL,aAAa,EACb,UAAU,EACV,KAAK,EACL,QAAQ,EACX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;AAE7E,MAAM,MAAM,eAAe,GACrB,OAAO,aAAa,CAAC,WAAW,GAChC,OAAO,aAAa,CAAC,MAAM,CAAC;AAElC,MAAM,MAAM,YAAY,CAAC,MAAM,SAAS,WAAW,IAAI;KAClD,IAAI,IAAI,MAAM,MAAM,CAAC,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,UAAU,GAClE,IAAI,GACJ,KAAK;CACd,CAAC,MAAM,MAAM,CAAC,CAAC;AAEhB,MAAM,MAAM,YAAY,CAAC,MAAM,SAAS,WAAW,IAAI;KAClD,IAAI,IAAI,MAAM,MAAM,CAAC,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,UAAU,GAClE,KAAK,GACL,IAAI;CACb,CAAC,MAAM,MAAM,CAAC,CAAC;AAEhB;;;;GAIG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,WAAW,IAAI,QAAQ,CAC1D;IACI,QAAQ,EAAE,IAAI,IAAI,YAAY,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CAC/D,GAAG;IACA,QAAQ,EAAE,IAAI,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CACrE,CACJ,CAAC;AAEF,MAAM,MAAM,QAAQ,CAAC,MAAM,IAAI;IAC3B,QAAQ,EAAE,IAAI,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC;CAChD,GAAG,EAAE,CAAC;AAEP,MAAM,MAAM,iBAAiB,CACzB,KAAK,SAAS,WAAW,EACzB,UAAU,SAAS,WAAW,IAC9B,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,UAAU,CAAC,GAAG,UAAU,CAAC,CAAC;AAEzD,MAAM,MAAM,kBAAkB,CAAC,MAAM,SAAS,WAAW,IAAI;IACzD,QAAQ,EAAE,IAAI,IAAI,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC;CACnF,CAAC;AAEF,MAAM,MAAM,eAAe,CACvB,MAAM,SAAS,WAAW,EAC1B,IAAI,SAAS,MAAM,IACnB,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AAE9C,MAAM,MAAM,eAAe,CACvB,MAAM,SAAS,WAAW,EAC1B,IAAI,SAAS,MAAM,IACnB,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AAE9C,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,MAAM,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -1,39 +1,60 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file scalar.ts
|
|
3
3
|
* @brief Primitive and literal guard builders.
|
|
4
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
5
|
+
* with stable metadata.
|
|
4
6
|
*/
|
|
5
7
|
import { BaseGuard, NumberGuard, StringGuard } from "../guard/index.js";
|
|
6
8
|
import type { LiteralValue } from "../schema/index.js";
|
|
7
9
|
/**
|
|
8
|
-
* @brief string guard.
|
|
10
|
+
* @brief Shared string guard singleton.
|
|
11
|
+
* @details Primitive guards are immutable, so exporting one instance avoids
|
|
12
|
+
* allocation for the common `t.string` path.
|
|
9
13
|
*/
|
|
10
14
|
export declare const stringGuard: StringGuard<"required">;
|
|
11
15
|
/**
|
|
12
|
-
* @brief unknown guard.
|
|
16
|
+
* @brief Shared unknown guard singleton.
|
|
17
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
18
|
+
* with stable metadata.
|
|
13
19
|
*/
|
|
14
20
|
export declare const unknownGuard: BaseGuard<unknown, "required">;
|
|
15
21
|
/**
|
|
16
|
-
* @brief never guard.
|
|
22
|
+
* @brief Shared never guard singleton.
|
|
23
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
24
|
+
* with stable metadata.
|
|
17
25
|
*/
|
|
18
26
|
export declare const neverGuard: BaseGuard<never, "required">;
|
|
19
27
|
/**
|
|
20
|
-
* @brief number guard.
|
|
28
|
+
* @brief Shared finite number guard singleton.
|
|
29
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
30
|
+
* with stable metadata.
|
|
21
31
|
*/
|
|
22
32
|
export declare const numberGuard: NumberGuard<"required">;
|
|
23
33
|
/**
|
|
24
|
-
* @brief bigint guard.
|
|
34
|
+
* @brief Shared bigint guard singleton.
|
|
35
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
36
|
+
* with stable metadata.
|
|
25
37
|
*/
|
|
26
38
|
export declare const bigintGuard: BaseGuard<bigint, "required">;
|
|
27
39
|
/**
|
|
28
|
-
* @brief symbol guard.
|
|
40
|
+
* @brief Shared symbol guard singleton.
|
|
41
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
42
|
+
* with stable metadata.
|
|
29
43
|
*/
|
|
30
44
|
export declare const symbolGuard: BaseGuard<symbol, "required">;
|
|
31
45
|
/**
|
|
32
|
-
* @brief boolean guard.
|
|
46
|
+
* @brief Shared boolean guard singleton.
|
|
47
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
48
|
+
* with stable metadata.
|
|
33
49
|
*/
|
|
34
50
|
export declare const booleanGuard: BaseGuard<boolean, "required">;
|
|
35
51
|
/**
|
|
36
|
-
* @brief literal.
|
|
52
|
+
* @brief Build a literal guard after rejecting non-literal runtime values.
|
|
53
|
+
* @details Builder helpers normalize user-facing fluent calls into immutable schema nodes
|
|
54
|
+
* with stable metadata.
|
|
55
|
+
* @param value Literal value to match with Object.is.
|
|
56
|
+
* @returns Fresh guard for exactly the supplied literal.
|
|
57
|
+
* @throws TypeError when the value cannot be represented as a TypeSea literal.
|
|
37
58
|
*/
|
|
38
59
|
export declare function literal<const TValue extends LiteralValue>(value: TValue): BaseGuard<TValue>;
|
|
39
60
|
//# sourceMappingURL=scalar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../../src/builders/scalar.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../../src/builders/scalar.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACH,SAAS,EACT,WAAW,EACX,WAAW,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD;;;;GAIG;AACH,eAAO,MAAM,WAAW,yBAGtB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,YAAY,gCAEvB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,UAAU,8BAErB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,WAAW,yBAGtB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,WAAW,+BAEtB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,WAAW,+BAEtB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,YAAY,gCAEvB,CAAC;AAEH;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,KAAK,CAAC,MAAM,SAAS,YAAY,EACrD,KAAK,EAAE,MAAM,GACd,SAAS,CAAC,MAAM,CAAC,CAYnB"}
|