typesea 0.1.0 → 0.3.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 +85 -6
- package/README.md +143 -28
- 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 +19 -3
- package/dist/aot/index.d.ts.map +1 -1
- package/dist/aot/index.js +115 -17
- 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 +43 -9
- package/dist/builders/composite.d.ts.map +1 -1
- package/dist/builders/composite.js +100 -17
- package/dist/builders/index.d.ts +8 -5
- package/dist/builders/index.d.ts.map +1 -1
- package/dist/builders/index.js +7 -4
- package/dist/builders/modifier.d.ts +36 -5
- package/dist/builders/modifier.d.ts.map +1 -1
- package/dist/builders/modifier.js +52 -5
- package/dist/builders/object/guard.d.ts +72 -24
- package/dist/builders/object/guard.d.ts.map +1 -1
- package/dist/builders/object/guard.js +139 -29
- package/dist/builders/object/index.d.ts +4 -2
- package/dist/builders/object/index.d.ts.map +1 -1
- package/dist/builders/object/index.js +3 -1
- package/dist/builders/object/schema.d.ts +88 -11
- package/dist/builders/object/schema.d.ts.map +1 -1
- package/dist/builders/object/schema.js +290 -23
- package/dist/builders/object/types.d.ts +20 -31
- package/dist/builders/object/types.d.ts.map +1 -1
- package/dist/builders/object/types.js +2 -0
- package/dist/builders/runtime.d.ts +40 -0
- package/dist/builders/runtime.d.ts.map +1 -0
- package/dist/builders/runtime.js +150 -0
- package/dist/builders/scalar.d.ts +49 -9
- package/dist/builders/scalar.d.ts.map +1 -1
- package/dist/builders/scalar.js +87 -9
- package/dist/builders/table.d.ts +35 -5
- package/dist/builders/table.d.ts.map +1 -1
- package/dist/builders/table.js +35 -5
- package/dist/builders/types.d.ts +20 -4
- package/dist/builders/types.d.ts.map +1 -1
- package/dist/builders/types.js +2 -0
- package/dist/compile/check-composite.d.ts +25 -2
- package/dist/compile/check-composite.d.ts.map +1 -1
- package/dist/compile/check-composite.js +699 -27
- package/dist/compile/check-scalar.d.ts +88 -0
- package/dist/compile/check-scalar.d.ts.map +1 -1
- package/dist/compile/check-scalar.js +570 -3
- package/dist/compile/check.d.ts +12 -0
- package/dist/compile/check.d.ts.map +1 -1
- package/dist/compile/check.js +62 -3
- package/dist/compile/context.d.ts +47 -9
- package/dist/compile/context.d.ts.map +1 -1
- package/dist/compile/context.js +53 -8
- package/dist/compile/first.d.ts +26 -0
- package/dist/compile/first.d.ts.map +1 -0
- package/dist/compile/first.js +850 -0
- package/dist/compile/graph-predicate.d.ts +4 -2
- package/dist/compile/graph-predicate.d.ts.map +1 -1
- package/dist/compile/graph-predicate.js +2272 -165
- package/dist/compile/guard.d.ts +16 -24
- package/dist/compile/guard.d.ts.map +1 -1
- package/dist/compile/guard.js +202 -72
- 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 +287 -10
- package/dist/compile/runtime.d.ts +100 -13
- package/dist/compile/runtime.d.ts.map +1 -1
- package/dist/compile/runtime.js +56 -6
- package/dist/compile/source.d.ts +10 -2
- package/dist/compile/source.d.ts.map +1 -1
- package/dist/compile/source.js +385 -26
- package/dist/compile/types.d.ts +22 -0
- package/dist/compile/types.d.ts.map +1 -1
- package/dist/compile/types.js +2 -0
- package/dist/decoder/index.d.ts +92 -46
- package/dist/decoder/index.d.ts.map +1 -1
- package/dist/decoder/index.js +266 -39
- package/dist/evaluate/check-composite.d.ts +111 -2
- package/dist/evaluate/check-composite.d.ts.map +1 -1
- package/dist/evaluate/check-composite.js +343 -8
- package/dist/evaluate/check-scalar.d.ts +25 -0
- package/dist/evaluate/check-scalar.d.ts.map +1 -1
- package/dist/evaluate/check-scalar.js +124 -3
- package/dist/evaluate/check.d.ts +7 -0
- package/dist/evaluate/check.d.ts.map +1 -1
- package/dist/evaluate/check.js +62 -4
- 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 +78 -13
- package/dist/evaluate/shared.d.ts.map +1 -1
- package/dist/evaluate/shared.js +101 -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/array.d.ts +48 -0
- package/dist/guard/array.d.ts.map +1 -0
- package/dist/guard/array.js +84 -0
- package/dist/guard/base.d.ts +111 -31
- package/dist/guard/base.d.ts.map +1 -1
- package/dist/guard/base.js +165 -32
- package/dist/guard/date.d.ts +34 -0
- package/dist/guard/date.d.ts.map +1 -0
- package/dist/guard/date.js +60 -0
- package/dist/guard/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 +4 -0
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +4 -0
- package/dist/guard/number.d.ts +86 -11
- package/dist/guard/number.d.ts.map +1 -1
- package/dist/guard/number.js +159 -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 +115 -10
- package/dist/guard/read.d.ts.map +1 -1
- package/dist/guard/read.js +185 -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 +115 -13
- package/dist/guard/string.d.ts.map +1 -1
- package/dist/guard/string.js +250 -13
- package/dist/guard/types.d.ts +110 -40
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/guard/types.js +2 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- 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 +17 -127
- package/dist/ir/builder.d.ts.map +1 -1
- package/dist/ir/builder.js +80 -137
- package/dist/ir/freeze.d.ts +4 -0
- package/dist/ir/freeze.d.ts.map +1 -1
- package/dist/ir/freeze.js +66 -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 +94 -56
- 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 +511 -61
- package/dist/issue/index.d.ts +42 -10
- package/dist/issue/index.d.ts.map +1 -1
- package/dist/issue/index.js +65 -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 +16 -2
- package/dist/json-schema/emit-composite.d.ts.map +1 -1
- package/dist/json-schema/emit-composite.js +81 -13
- 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 +124 -10
- 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 +23 -3
- 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 +45 -16
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/json-schema/types.js +2 -0
- package/dist/kind/index.d.ts +40 -28
- package/dist/kind/index.d.ts.map +1 -1
- package/dist/kind/index.js +41 -13
- package/dist/lower/index.d.ts +6 -1
- package/dist/lower/index.d.ts.map +1 -1
- package/dist/lower/index.js +462 -46
- package/dist/message/index.d.ts +64 -10
- package/dist/message/index.d.ts.map +1 -1
- package/dist/message/index.js +155 -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 +619 -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 +48 -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 +34 -6
- 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 +298 -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 +382 -19
- 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 +40 -0
- package/dist/schema/index.d.ts +5 -2
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +4 -1
- 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 +109 -100
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js +13 -2
- package/dist/schema/undefined.d.ts +17 -0
- package/dist/schema/undefined.d.ts.map +1 -0
- package/dist/schema/undefined.js +77 -0
- package/dist/schema/validate.d.ts +8 -1
- package/dist/schema/validate.d.ts.map +1 -1
- package/dist/schema/validate.js +255 -57
- package/docs/api.md +128 -8
- package/docs/assets/benchmark-headline.svg +163 -0
- package/docs/engine-notes.md +62 -15
- package/docs/index.html +1340 -702
- package/docs/ko/api.md +375 -0
- package/docs/ko/engine-notes.md +156 -0
- package/docs/ko/readme.md +378 -0
- package/package.json +66 -65
|
@@ -1,44 +1,121 @@
|
|
|
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
|
-
import type { ObjectEntry, ObjectSchema } from "../../schema/index.js";
|
|
8
|
+
import type { ObjectEntry, ObjectSchema, Schema } 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
|
-
export declare function objectSchemaFromEntries(sourceEntries: readonly ObjectEntry[], mode: ObjectModeTag): ObjectSchema;
|
|
21
|
+
export declare function objectSchemaFromEntries(sourceEntries: readonly ObjectEntry[], mode: ObjectModeTag, catchall: Schema | undefined): ObjectSchema;
|
|
16
22
|
/**
|
|
17
|
-
* @brief
|
|
23
|
+
* @brief Rebuild an object schema with a different unknown-key mode.
|
|
24
|
+
* @param schema Source object schema.
|
|
25
|
+
* @param mode Unknown-key policy for the rebuilt schema.
|
|
26
|
+
* @returns Object schema with identical entries and catchall policy.
|
|
27
|
+
*/
|
|
28
|
+
export declare function objectSchemaWithMode(schema: ObjectSchema, mode: ObjectModeTag): ObjectSchema;
|
|
29
|
+
/**
|
|
30
|
+
* @brief Rebuild an object schema with an unknown-key validator.
|
|
31
|
+
* @param schema Source object schema.
|
|
32
|
+
* @param catchall Schema applied to every undeclared own key.
|
|
33
|
+
* @returns Object schema that validates extra keys with the supplied schema.
|
|
34
|
+
*/
|
|
35
|
+
export declare function objectSchemaWithCatchall(schema: ObjectSchema, catchall: Schema): ObjectSchema;
|
|
36
|
+
/**
|
|
37
|
+
* @brief Validate the schema value handed to an ObjectGuard constructor.
|
|
38
|
+
* @details Constructors are public JavaScript entry points, so the guard checks
|
|
39
|
+
* both the TypeSea schema marker and the object-schema tag before storing the
|
|
40
|
+
* value. This prevents forged objects from bypassing builder invariants.
|
|
41
|
+
* @param schema Candidate schema supplied to the constructor.
|
|
42
|
+
* @returns Object schema accepted by the constructor.
|
|
18
43
|
*/
|
|
19
44
|
export declare function readObjectConstructorSchema(schema: unknown): ObjectSchema;
|
|
20
45
|
/**
|
|
21
|
-
* @brief
|
|
46
|
+
* @brief Extract an object schema from another guard for object-only methods.
|
|
47
|
+
* @details Methods such as merge and extension compose object shapes. Accepting
|
|
48
|
+
* a scalar guard here would build an impossible schema, so the check is kept at
|
|
49
|
+
* the API edge with the caller-facing label in the error message.
|
|
50
|
+
* @param guard Candidate TypeSea guard.
|
|
51
|
+
* @param label Human-readable API label used in thrown errors.
|
|
52
|
+
* @returns Object schema owned by the supplied guard.
|
|
22
53
|
*/
|
|
23
54
|
export declare function readObjectMethodSchema(guard: unknown, label: string): ObjectSchema;
|
|
24
55
|
/**
|
|
25
|
-
* @brief
|
|
56
|
+
* @brief Merge two object schemas while letting extension keys override base keys.
|
|
57
|
+
* @details Existing base order is preserved for stable diagnostics and codegen.
|
|
58
|
+
* Extension-only keys are appended afterward, and the base strict/open mode is
|
|
59
|
+
* retained so shape extension does not silently change excess-key policy.
|
|
60
|
+
* @param base Source object schema being extended.
|
|
61
|
+
* @param extension Object schema whose matching keys replace base entries.
|
|
62
|
+
* @returns Rebuilt object schema with fresh lookup metadata.
|
|
26
63
|
*/
|
|
27
64
|
export declare function mergeObjectSchemas(base: ObjectSchema, extension: ObjectSchema): ObjectSchema;
|
|
28
65
|
/**
|
|
29
|
-
* @brief
|
|
66
|
+
* @brief Build an object schema containing only a validated key selection.
|
|
67
|
+
* @details The caller has already checked that keys are known and unique. This
|
|
68
|
+
* function preserves selection order so user-requested projection order is also
|
|
69
|
+
* the order used by diagnostics and generated object checks.
|
|
70
|
+
* @param schema Source object schema.
|
|
71
|
+
* @param keys Validated key selection.
|
|
72
|
+
* @returns Rebuilt object schema containing only selected entries.
|
|
30
73
|
*/
|
|
31
74
|
export declare function pickObjectSchema(schema: ObjectSchema, keys: readonly string[]): ObjectSchema;
|
|
32
75
|
/**
|
|
33
|
-
* @brief
|
|
76
|
+
* @brief Build an object schema with a validated key selection removed.
|
|
77
|
+
* @details Entries not listed for removal keep their original relative order
|
|
78
|
+
* and presence metadata. The object mode is preserved across the rewrite.
|
|
79
|
+
* @param schema Source object schema.
|
|
80
|
+
* @param keys Validated key selection to remove.
|
|
81
|
+
* @returns Rebuilt object schema without the selected entries.
|
|
34
82
|
*/
|
|
35
83
|
export declare function omitObjectSchema(schema: ObjectSchema, keys: readonly string[]): ObjectSchema;
|
|
36
84
|
/**
|
|
37
|
-
* @brief
|
|
85
|
+
* @brief Convert every object entry to optional presence.
|
|
86
|
+
* @details The child schemas are not wrapped or cloned; only field presence is
|
|
87
|
+
* rewritten. This keeps value-domain wrappers such as nullable and brand exactly
|
|
88
|
+
* as they were on the original entries.
|
|
89
|
+
* @param schema Source object schema.
|
|
90
|
+
* @returns Rebuilt object schema with optional entries.
|
|
38
91
|
*/
|
|
39
92
|
export declare function partialObjectSchema(schema: ObjectSchema): ObjectSchema;
|
|
40
93
|
/**
|
|
41
|
-
* @brief
|
|
94
|
+
* @brief Recursively convert object entries to optional presence.
|
|
95
|
+
* @param schema Source object schema.
|
|
96
|
+
* @returns Rebuilt object schema with nested object/container children partialized.
|
|
97
|
+
* @details Lazy and refinement schemas are treated as semantic barriers because
|
|
98
|
+
* their runtime callbacks may depend on the original exact value domain.
|
|
99
|
+
*/
|
|
100
|
+
export declare function deepPartialObjectSchema(schema: ObjectSchema): ObjectSchema;
|
|
101
|
+
/**
|
|
102
|
+
* @brief Convert every object entry to required presence.
|
|
103
|
+
* @param schema Source object schema.
|
|
104
|
+
* @returns Rebuilt object schema with required entries.
|
|
105
|
+
* @details Object construction already stripped Optional wrappers into entry
|
|
106
|
+
* presence metadata. Requiring a field therefore only needs to flip that
|
|
107
|
+
* metadata back to Required while preserving each value-domain schema.
|
|
108
|
+
*/
|
|
109
|
+
export declare function requiredObjectSchema(schema: ObjectSchema): ObjectSchema;
|
|
110
|
+
/**
|
|
111
|
+
* @brief Validate the key list supplied to object pick and omit operations.
|
|
112
|
+
* @details The returned array contains only known, unique string keys. This
|
|
113
|
+
* preflight keeps later schema rewriting simple and prevents silently selecting
|
|
114
|
+
* fields that were never part of the source object schema.
|
|
115
|
+
* @param keys Candidate key list from public API calls.
|
|
116
|
+
* @param schema Object schema whose keys define the valid selection domain.
|
|
117
|
+
* @param label Human-readable API label used in thrown errors.
|
|
118
|
+
* @returns Ordered key selection accepted by the object builder.
|
|
42
119
|
*/
|
|
43
120
|
export declare function readObjectKeySelection(keys: unknown, schema: ObjectSchema, label: string): readonly string[];
|
|
44
121
|
//# 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,EACZ,MAAM,EACT,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,EACnB,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC7B,YAAY,CAwBd;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAChC,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,aAAa,GACpB,YAAY,CAEd;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACpC,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,MAAM,GACjB,YAAY,CAEd;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,CAmBd;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;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAgB1E;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAavE;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAClC,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,MAAM,GACd,SAAS,MAAM,EAAE,CAsBnB"}
|
|
@@ -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)) {
|
|
@@ -27,12 +31,14 @@ export function objectSchema(shape, mode) {
|
|
|
27
31
|
presence: entrySchema.presence
|
|
28
32
|
};
|
|
29
33
|
}
|
|
30
|
-
return objectSchemaFromEntries(entries, mode);
|
|
34
|
+
return objectSchemaFromEntries(entries, mode, undefined);
|
|
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
|
-
export function objectSchemaFromEntries(sourceEntries, mode) {
|
|
41
|
+
export function objectSchemaFromEntries(sourceEntries, mode, catchall) {
|
|
36
42
|
const entries = new Array(sourceEntries.length);
|
|
37
43
|
const keys = new Array(sourceEntries.length);
|
|
38
44
|
const keyLookup = makeObjectKeyLookup();
|
|
@@ -53,11 +59,35 @@ export function objectSchemaFromEntries(sourceEntries, mode) {
|
|
|
53
59
|
entries,
|
|
54
60
|
keys,
|
|
55
61
|
keyLookup,
|
|
56
|
-
mode
|
|
62
|
+
mode,
|
|
63
|
+
catchall
|
|
57
64
|
};
|
|
58
65
|
}
|
|
59
66
|
/**
|
|
60
|
-
* @brief
|
|
67
|
+
* @brief Rebuild an object schema with a different unknown-key mode.
|
|
68
|
+
* @param schema Source object schema.
|
|
69
|
+
* @param mode Unknown-key policy for the rebuilt schema.
|
|
70
|
+
* @returns Object schema with identical entries and catchall policy.
|
|
71
|
+
*/
|
|
72
|
+
export function objectSchemaWithMode(schema, mode) {
|
|
73
|
+
return objectSchemaFromEntries(schema.entries, mode, schema.catchall);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @brief Rebuild an object schema with an unknown-key validator.
|
|
77
|
+
* @param schema Source object schema.
|
|
78
|
+
* @param catchall Schema applied to every undeclared own key.
|
|
79
|
+
* @returns Object schema that validates extra keys with the supplied schema.
|
|
80
|
+
*/
|
|
81
|
+
export function objectSchemaWithCatchall(schema, catchall) {
|
|
82
|
+
return objectSchemaFromEntries(schema.entries, schema.mode, catchall);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @brief Validate the schema value handed to an ObjectGuard constructor.
|
|
86
|
+
* @details Constructors are public JavaScript entry points, so the guard checks
|
|
87
|
+
* both the TypeSea schema marker and the object-schema tag before storing the
|
|
88
|
+
* value. This prevents forged objects from bypassing builder invariants.
|
|
89
|
+
* @param schema Candidate schema supplied to the constructor.
|
|
90
|
+
* @returns Object schema accepted by the constructor.
|
|
61
91
|
*/
|
|
62
92
|
export function readObjectConstructorSchema(schema) {
|
|
63
93
|
if (!isSchemaValue(schema) || schema.tag !== SchemaTag.Object) {
|
|
@@ -66,7 +96,13 @@ export function readObjectConstructorSchema(schema) {
|
|
|
66
96
|
return schema;
|
|
67
97
|
}
|
|
68
98
|
/**
|
|
69
|
-
* @brief
|
|
99
|
+
* @brief Extract an object schema from another guard for object-only methods.
|
|
100
|
+
* @details Methods such as merge and extension compose object shapes. Accepting
|
|
101
|
+
* a scalar guard here would build an impossible schema, so the check is kept at
|
|
102
|
+
* the API edge with the caller-facing label in the error message.
|
|
103
|
+
* @param guard Candidate TypeSea guard.
|
|
104
|
+
* @param label Human-readable API label used in thrown errors.
|
|
105
|
+
* @returns Object schema owned by the supplied guard.
|
|
70
106
|
*/
|
|
71
107
|
export function readObjectMethodSchema(guard, label) {
|
|
72
108
|
const schema = readGuardSchema(guard, label);
|
|
@@ -76,7 +112,13 @@ export function readObjectMethodSchema(guard, label) {
|
|
|
76
112
|
return schema;
|
|
77
113
|
}
|
|
78
114
|
/**
|
|
79
|
-
* @brief
|
|
115
|
+
* @brief Merge two object schemas while letting extension keys override base keys.
|
|
116
|
+
* @details Existing base order is preserved for stable diagnostics and codegen.
|
|
117
|
+
* Extension-only keys are appended afterward, and the base strict/open mode is
|
|
118
|
+
* retained so shape extension does not silently change excess-key policy.
|
|
119
|
+
* @param base Source object schema being extended.
|
|
120
|
+
* @param extension Object schema whose matching keys replace base entries.
|
|
121
|
+
* @returns Rebuilt object schema with fresh lookup metadata.
|
|
80
122
|
*/
|
|
81
123
|
export function mergeObjectSchemas(base, extension) {
|
|
82
124
|
const entries = [];
|
|
@@ -92,10 +134,16 @@ export function mergeObjectSchemas(base, extension) {
|
|
|
92
134
|
entries.push(entry);
|
|
93
135
|
}
|
|
94
136
|
}
|
|
95
|
-
return objectSchemaFromEntries(entries, base.mode);
|
|
137
|
+
return objectSchemaFromEntries(entries, base.mode, extension.catchall ?? base.catchall);
|
|
96
138
|
}
|
|
97
139
|
/**
|
|
98
|
-
* @brief
|
|
140
|
+
* @brief Build an object schema containing only a validated key selection.
|
|
141
|
+
* @details The caller has already checked that keys are known and unique. This
|
|
142
|
+
* function preserves selection order so user-requested projection order is also
|
|
143
|
+
* the order used by diagnostics and generated object checks.
|
|
144
|
+
* @param schema Source object schema.
|
|
145
|
+
* @param keys Validated key selection.
|
|
146
|
+
* @returns Rebuilt object schema containing only selected entries.
|
|
99
147
|
*/
|
|
100
148
|
export function pickObjectSchema(schema, keys) {
|
|
101
149
|
const entries = new Array(keys.length);
|
|
@@ -109,10 +157,15 @@ export function pickObjectSchema(schema, keys) {
|
|
|
109
157
|
}
|
|
110
158
|
entries[index] = entry;
|
|
111
159
|
}
|
|
112
|
-
return objectSchemaFromEntries(entries, schema.mode);
|
|
160
|
+
return objectSchemaFromEntries(entries, schema.mode, schema.catchall);
|
|
113
161
|
}
|
|
114
162
|
/**
|
|
115
|
-
* @brief
|
|
163
|
+
* @brief Build an object schema with a validated key selection removed.
|
|
164
|
+
* @details Entries not listed for removal keep their original relative order
|
|
165
|
+
* and presence metadata. The object mode is preserved across the rewrite.
|
|
166
|
+
* @param schema Source object schema.
|
|
167
|
+
* @param keys Validated key selection to remove.
|
|
168
|
+
* @returns Rebuilt object schema without the selected entries.
|
|
116
169
|
*/
|
|
117
170
|
export function omitObjectSchema(schema, keys) {
|
|
118
171
|
const entries = [];
|
|
@@ -122,10 +175,15 @@ export function omitObjectSchema(schema, keys) {
|
|
|
122
175
|
entries.push(entry);
|
|
123
176
|
}
|
|
124
177
|
}
|
|
125
|
-
return objectSchemaFromEntries(entries, schema.mode);
|
|
178
|
+
return objectSchemaFromEntries(entries, schema.mode, schema.catchall);
|
|
126
179
|
}
|
|
127
180
|
/**
|
|
128
|
-
* @brief
|
|
181
|
+
* @brief Convert every object entry to optional presence.
|
|
182
|
+
* @details The child schemas are not wrapped or cloned; only field presence is
|
|
183
|
+
* rewritten. This keeps value-domain wrappers such as nullable and brand exactly
|
|
184
|
+
* as they were on the original entries.
|
|
185
|
+
* @param schema Source object schema.
|
|
186
|
+
* @returns Rebuilt object schema with optional entries.
|
|
129
187
|
*/
|
|
130
188
|
export function partialObjectSchema(schema) {
|
|
131
189
|
const entries = new Array(schema.entries.length);
|
|
@@ -139,14 +197,70 @@ export function partialObjectSchema(schema) {
|
|
|
139
197
|
};
|
|
140
198
|
}
|
|
141
199
|
}
|
|
142
|
-
return objectSchemaFromEntries(entries, schema.mode);
|
|
200
|
+
return objectSchemaFromEntries(entries, schema.mode, schema.catchall);
|
|
143
201
|
}
|
|
144
202
|
/**
|
|
145
|
-
* @brief
|
|
203
|
+
* @brief Recursively convert object entries to optional presence.
|
|
204
|
+
* @param schema Source object schema.
|
|
205
|
+
* @returns Rebuilt object schema with nested object/container children partialized.
|
|
206
|
+
* @details Lazy and refinement schemas are treated as semantic barriers because
|
|
207
|
+
* their runtime callbacks may depend on the original exact value domain.
|
|
208
|
+
*/
|
|
209
|
+
export function deepPartialObjectSchema(schema) {
|
|
210
|
+
const entries = new Array(schema.entries.length);
|
|
211
|
+
for (let index = 0; index < schema.entries.length; index += 1) {
|
|
212
|
+
const entry = schema.entries[index];
|
|
213
|
+
if (entry !== undefined) {
|
|
214
|
+
entries[index] = {
|
|
215
|
+
key: entry.key,
|
|
216
|
+
schema: deepPartialSchema(entry.schema),
|
|
217
|
+
presence: PresenceTag.Optional
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const catchall = schema.catchall === undefined
|
|
222
|
+
? undefined
|
|
223
|
+
: deepPartialSchema(schema.catchall);
|
|
224
|
+
return objectSchemaFromEntries(entries, schema.mode, catchall);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* @brief Convert every object entry to required presence.
|
|
228
|
+
* @param schema Source object schema.
|
|
229
|
+
* @returns Rebuilt object schema with required entries.
|
|
230
|
+
* @details Object construction already stripped Optional wrappers into entry
|
|
231
|
+
* presence metadata. Requiring a field therefore only needs to flip that
|
|
232
|
+
* metadata back to Required while preserving each value-domain schema.
|
|
233
|
+
*/
|
|
234
|
+
export function requiredObjectSchema(schema) {
|
|
235
|
+
const entries = new Array(schema.entries.length);
|
|
236
|
+
for (let index = 0; index < schema.entries.length; index += 1) {
|
|
237
|
+
const entry = schema.entries[index];
|
|
238
|
+
if (entry !== undefined) {
|
|
239
|
+
entries[index] = {
|
|
240
|
+
key: entry.key,
|
|
241
|
+
schema: entry.schema,
|
|
242
|
+
presence: PresenceTag.Required
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return objectSchemaFromEntries(entries, schema.mode, schema.catchall);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* @brief Validate the key list supplied to object pick and omit operations.
|
|
250
|
+
* @details The returned array contains only known, unique string keys. This
|
|
251
|
+
* preflight keeps later schema rewriting simple and prevents silently selecting
|
|
252
|
+
* fields that were never part of the source object schema.
|
|
253
|
+
* @param keys Candidate key list from public API calls.
|
|
254
|
+
* @param schema Object schema whose keys define the valid selection domain.
|
|
255
|
+
* @param label Human-readable API label used in thrown errors.
|
|
256
|
+
* @returns Ordered key selection accepted by the object builder.
|
|
146
257
|
*/
|
|
147
258
|
export function readObjectKeySelection(keys, schema, label) {
|
|
259
|
+
if (isRecord(keys)) {
|
|
260
|
+
return readObjectKeyMask(keys, schema, label);
|
|
261
|
+
}
|
|
148
262
|
if (!isUnknownArray(keys)) {
|
|
149
|
-
throw new TypeError(`${label} must be an array`);
|
|
263
|
+
throw new TypeError(`${label} must be an array or key mask`);
|
|
150
264
|
}
|
|
151
265
|
const selected = new Array(keys.length);
|
|
152
266
|
for (let index = 0; index < keys.length; index += 1) {
|
|
@@ -165,7 +279,135 @@ export function readObjectKeySelection(keys, schema, label) {
|
|
|
165
279
|
return selected;
|
|
166
280
|
}
|
|
167
281
|
/**
|
|
168
|
-
* @brief
|
|
282
|
+
* @brief Validate a Zod-style object key mask.
|
|
283
|
+
* @param mask Candidate object whose selected keys have value true.
|
|
284
|
+
* @param schema Object schema whose keys define the valid selection domain.
|
|
285
|
+
* @param label Human-readable API label used in thrown errors.
|
|
286
|
+
* @returns Ordered key selection accepted by object pick and omit.
|
|
287
|
+
*/
|
|
288
|
+
function readObjectKeyMask(mask, schema, label) {
|
|
289
|
+
const keys = Object.keys(mask);
|
|
290
|
+
const selected = [];
|
|
291
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
292
|
+
const key = keys[index];
|
|
293
|
+
if (key === undefined) {
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
if (mask[key] !== true) {
|
|
297
|
+
throw new TypeError(`${label} mask values must be true`);
|
|
298
|
+
}
|
|
299
|
+
if (!hasObjectKey(schema.keyLookup, key)) {
|
|
300
|
+
throw new TypeError(`${label} contains unknown object key ${key}`);
|
|
301
|
+
}
|
|
302
|
+
selected.push(key);
|
|
303
|
+
}
|
|
304
|
+
return selected;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* @brief Recursively partialize pure schema containers.
|
|
308
|
+
* @param schema Schema to rewrite.
|
|
309
|
+
* @returns Schema with nested object fields made optional where safe.
|
|
310
|
+
*/
|
|
311
|
+
function deepPartialSchema(schema) {
|
|
312
|
+
switch (schema.tag) {
|
|
313
|
+
case SchemaTag.Object:
|
|
314
|
+
return deepPartialObjectSchema(schema);
|
|
315
|
+
case SchemaTag.Array:
|
|
316
|
+
return {
|
|
317
|
+
tag: SchemaTag.Array,
|
|
318
|
+
item: deepPartialSchema(schema.item),
|
|
319
|
+
checks: schema.checks
|
|
320
|
+
};
|
|
321
|
+
case SchemaTag.Tuple:
|
|
322
|
+
return {
|
|
323
|
+
tag: SchemaTag.Tuple,
|
|
324
|
+
items: mapDeepPartialSchemas(schema.items),
|
|
325
|
+
rest: schema.rest === undefined
|
|
326
|
+
? undefined
|
|
327
|
+
: deepPartialSchema(schema.rest)
|
|
328
|
+
};
|
|
329
|
+
case SchemaTag.Record:
|
|
330
|
+
return {
|
|
331
|
+
tag: SchemaTag.Record,
|
|
332
|
+
value: deepPartialSchema(schema.value)
|
|
333
|
+
};
|
|
334
|
+
case SchemaTag.Map:
|
|
335
|
+
return {
|
|
336
|
+
tag: SchemaTag.Map,
|
|
337
|
+
key: deepPartialSchema(schema.key),
|
|
338
|
+
value: deepPartialSchema(schema.value)
|
|
339
|
+
};
|
|
340
|
+
case SchemaTag.Set:
|
|
341
|
+
return {
|
|
342
|
+
tag: SchemaTag.Set,
|
|
343
|
+
item: deepPartialSchema(schema.item)
|
|
344
|
+
};
|
|
345
|
+
case SchemaTag.Property:
|
|
346
|
+
return {
|
|
347
|
+
tag: SchemaTag.Property,
|
|
348
|
+
base: deepPartialSchema(schema.base),
|
|
349
|
+
key: schema.key,
|
|
350
|
+
value: deepPartialSchema(schema.value)
|
|
351
|
+
};
|
|
352
|
+
case SchemaTag.Union:
|
|
353
|
+
return {
|
|
354
|
+
tag: SchemaTag.Union,
|
|
355
|
+
options: mapDeepPartialSchemas(schema.options)
|
|
356
|
+
};
|
|
357
|
+
case SchemaTag.Intersection:
|
|
358
|
+
return {
|
|
359
|
+
tag: SchemaTag.Intersection,
|
|
360
|
+
left: deepPartialSchema(schema.left),
|
|
361
|
+
right: deepPartialSchema(schema.right)
|
|
362
|
+
};
|
|
363
|
+
case SchemaTag.Optional:
|
|
364
|
+
return {
|
|
365
|
+
tag: SchemaTag.Optional,
|
|
366
|
+
inner: deepPartialSchema(schema.inner)
|
|
367
|
+
};
|
|
368
|
+
case SchemaTag.Undefinedable:
|
|
369
|
+
return {
|
|
370
|
+
tag: SchemaTag.Undefinedable,
|
|
371
|
+
inner: deepPartialSchema(schema.inner)
|
|
372
|
+
};
|
|
373
|
+
case SchemaTag.Nullable:
|
|
374
|
+
return {
|
|
375
|
+
tag: SchemaTag.Nullable,
|
|
376
|
+
inner: deepPartialSchema(schema.inner)
|
|
377
|
+
};
|
|
378
|
+
case SchemaTag.Brand:
|
|
379
|
+
return {
|
|
380
|
+
tag: SchemaTag.Brand,
|
|
381
|
+
inner: deepPartialSchema(schema.inner),
|
|
382
|
+
brand: schema.brand
|
|
383
|
+
};
|
|
384
|
+
default:
|
|
385
|
+
return schema;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* @brief Deep-partialize a schema vector.
|
|
390
|
+
* @param schemas Source schema vector.
|
|
391
|
+
* @returns New schema vector preserving index order.
|
|
392
|
+
*/
|
|
393
|
+
function mapDeepPartialSchemas(schemas) {
|
|
394
|
+
const mapped = new Array(schemas.length);
|
|
395
|
+
for (let index = 0; index < schemas.length; index += 1) {
|
|
396
|
+
const schema = schemas[index];
|
|
397
|
+
if (schema !== undefined) {
|
|
398
|
+
mapped[index] = deepPartialSchema(schema);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return mapped;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* @brief Find an object entry by key using the ordered entry vector.
|
|
405
|
+
* @details The ordered vector is the source of truth for diagnostic and codegen
|
|
406
|
+
* order. The lookup table proves membership, while this helper recovers the
|
|
407
|
+
* full entry payload.
|
|
408
|
+
* @param entries Ordered object entries.
|
|
409
|
+
* @param key Field name to locate.
|
|
410
|
+
* @returns Matching object entry, or undefined when absent.
|
|
169
411
|
*/
|
|
170
412
|
function findObjectEntry(entries, key) {
|
|
171
413
|
for (let index = 0; index < entries.length; index += 1) {
|
|
@@ -177,13 +419,21 @@ function findObjectEntry(entries, key) {
|
|
|
177
419
|
return undefined;
|
|
178
420
|
}
|
|
179
421
|
/**
|
|
180
|
-
* @brief
|
|
422
|
+
* @brief Allocate a null-prototype lookup table for object schema keys.
|
|
423
|
+
* @details User field names may overlap with Object.prototype properties. A
|
|
424
|
+
* null-prototype table keeps membership checks data-only and avoids inherited
|
|
425
|
+
* keys participating in schema construction.
|
|
426
|
+
* @returns Empty key lookup table used by object schemas.
|
|
181
427
|
*/
|
|
182
428
|
function makeObjectKeyLookup() {
|
|
183
429
|
return Object.create(null);
|
|
184
430
|
}
|
|
185
431
|
/**
|
|
186
|
-
* @brief
|
|
432
|
+
* @brief Install one immutable key marker into an object-schema lookup table.
|
|
433
|
+
* @details Object keys are defined as own data properties so membership checks
|
|
434
|
+
* cannot be influenced by prototype state or later mutation of the table.
|
|
435
|
+
* @param target Null-prototype key lookup table.
|
|
436
|
+
* @param key Field name to mark as present.
|
|
187
437
|
*/
|
|
188
438
|
function defineObjectKey(target, key) {
|
|
189
439
|
Object.defineProperty(target, key, {
|
|
@@ -194,13 +444,23 @@ function defineObjectKey(target, key) {
|
|
|
194
444
|
});
|
|
195
445
|
}
|
|
196
446
|
/**
|
|
197
|
-
* @brief
|
|
447
|
+
* @brief Test object-schema key membership through the prepared lookup table.
|
|
448
|
+
* @details The table stores immutable true values, so direct indexed access is
|
|
449
|
+
* sufficient and avoids repeated descriptor allocation during builder work.
|
|
450
|
+
* @param keyLookup Null-prototype lookup table from the object schema.
|
|
451
|
+
* @param key Candidate field name.
|
|
452
|
+
* @returns True when the key belongs to the object schema.
|
|
198
453
|
*/
|
|
199
454
|
function hasObjectKey(keyLookup, key) {
|
|
200
455
|
return keyLookup[key] === true;
|
|
201
456
|
}
|
|
202
457
|
/**
|
|
203
|
-
* @brief
|
|
458
|
+
* @brief Split object-field presence from value-domain schema wrappers.
|
|
459
|
+
* @details Optional is the only wrapper that changes field presence. Other
|
|
460
|
+
* wrappers are rebuilt around the normalized inner schema so optionality can
|
|
461
|
+
* propagate outward without losing nullable, brand, or refinement behavior.
|
|
462
|
+
* @param schema Field schema supplied by the object builder.
|
|
463
|
+
* @returns Normalized child schema and required/optional presence tag.
|
|
204
464
|
*/
|
|
205
465
|
function normalizeObjectEntrySchema(schema) {
|
|
206
466
|
switch (schema.tag) {
|
|
@@ -240,7 +500,14 @@ function normalizeObjectEntrySchema(schema) {
|
|
|
240
500
|
}
|
|
241
501
|
}
|
|
242
502
|
/**
|
|
243
|
-
* @brief
|
|
503
|
+
* @brief Rebuild a wrapper after normalizing its inner object-field schema.
|
|
504
|
+
* @details When the inner schema stays required, the original wrapper can be
|
|
505
|
+
* kept unchanged. When optionality is discovered inside, the wrapper is rebuilt
|
|
506
|
+
* around the normalized child and the field presence becomes optional.
|
|
507
|
+
* @param inner Inner schema carried by the wrapper.
|
|
508
|
+
* @param wrap Function that rebuilds the same wrapper around a new child.
|
|
509
|
+
* @param original Original wrapper schema.
|
|
510
|
+
* @returns Normalized schema and presence tag for the object field.
|
|
244
511
|
*/
|
|
245
512
|
function normalizeWrappedObjectEntrySchema(inner, wrap, original) {
|
|
246
513
|
const normalized = normalizeObjectEntrySchema(inner);
|
|
@@ -1,63 +1,52 @@
|
|
|
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
|
-
|
|
53
|
-
|
|
34
|
+
export type DeepPartialValue<TValue> = TValue extends (infer TItem)[] ? DeepPartialValue<TItem>[] : TValue extends readonly (infer TItem)[] ? readonly DeepPartialValue<TItem>[] : TValue extends object ? {
|
|
35
|
+
readonly [TKey in keyof TValue]?: DeepPartialValue<TValue[TKey]>;
|
|
36
|
+
} : TValue;
|
|
37
|
+
export type DeepPartialObjectShape<TShape extends ObjectShape> = {
|
|
38
|
+
readonly [TKey in keyof TShape]: BaseGuard<DeepPartialValue<GuardValue<TShape[TKey]>>, "optional">;
|
|
39
|
+
};
|
|
40
|
+
export type RequiredObjectShape<TShape extends ObjectShape> = {
|
|
41
|
+
readonly [TKey in keyof TShape]: BaseGuard<GuardValue<TShape[TKey]>>;
|
|
42
|
+
};
|
|
43
|
+
export type ObjectKeyMask<TShape extends ObjectShape> = Partial<Readonly<Record<StringKeyOf<TShape>, true>>>;
|
|
44
|
+
export type MaskSelectedKeys<TShape extends ObjectShape, TMask extends ObjectKeyMask<TShape>> = {
|
|
45
|
+
[TKey in keyof TMask]-?: TMask[TKey] extends true ? TKey : never;
|
|
46
|
+
}[keyof TMask];
|
|
54
47
|
export type PickObjectShape<TShape extends ObjectShape, TKey extends string> = Pick<TShape, Extract<keyof TShape, TKey>>;
|
|
55
|
-
|
|
56
|
-
* @brief omit object shape.
|
|
57
|
-
*/
|
|
48
|
+
export type PickObjectShapeByMask<TShape extends ObjectShape, TMask extends ObjectKeyMask<TShape>> = Pick<TShape, Extract<keyof TShape, MaskSelectedKeys<TShape, TMask>>>;
|
|
58
49
|
export type OmitObjectShape<TShape extends ObjectShape, TKey extends string> = Omit<TShape, Extract<keyof TShape, TKey>>;
|
|
59
|
-
|
|
60
|
-
* @brief string key of.
|
|
61
|
-
*/
|
|
50
|
+
export type OmitObjectShapeByMask<TShape extends ObjectShape, TMask extends ObjectKeyMask<TShape>> = Omit<TShape, Extract<keyof TShape, MaskSelectedKeys<TShape, TMask>>>;
|
|
62
51
|
export type StringKeyOf<TValue> = Extract<keyof TValue, string>;
|
|
63
52
|
//# 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":"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"}
|