typesea 0.1.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 +9 -0
- package/LICENSE +21 -0
- package/README.md +320 -0
- package/dist/adapters/index.d.ts +152 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +396 -0
- package/dist/aot/index.d.ts +33 -0
- package/dist/aot/index.d.ts.map +1 -0
- package/dist/aot/index.js +295 -0
- package/dist/async/index.d.ts +111 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/async/index.js +221 -0
- package/dist/builders/composite.d.ts +31 -0
- package/dist/builders/composite.d.ts.map +1 -0
- package/dist/builders/composite.js +165 -0
- package/dist/builders/index.d.ts +11 -0
- package/dist/builders/index.d.ts.map +1 -0
- package/dist/builders/index.js +9 -0
- package/dist/builders/modifier.d.ts +26 -0
- package/dist/builders/modifier.d.ts.map +1 -0
- package/dist/builders/modifier.js +67 -0
- package/dist/builders/object/guard.d.ts +62 -0
- package/dist/builders/object/guard.d.ts.map +1 -0
- package/dist/builders/object/guard.js +113 -0
- package/dist/builders/object/index.d.ts +7 -0
- package/dist/builders/object/index.d.ts.map +1 -0
- package/dist/builders/object/index.js +5 -0
- package/dist/builders/object/schema.d.ts +44 -0
- package/dist/builders/object/schema.d.ts.map +1 -0
- package/dist/builders/object/schema.js +257 -0
- package/dist/builders/object/types.d.ts +63 -0
- package/dist/builders/object/types.d.ts.map +1 -0
- package/dist/builders/object/types.js +5 -0
- package/dist/builders/scalar.d.ts +39 -0
- package/dist/builders/scalar.d.ts.map +1 -0
- package/dist/builders/scalar.js +63 -0
- package/dist/builders/table.d.ts +53 -0
- package/dist/builders/table.d.ts.map +1 -0
- package/dist/builders/table.js +48 -0
- package/dist/builders/types.d.ts +26 -0
- package/dist/builders/types.d.ts.map +1 -0
- package/dist/builders/types.js +5 -0
- package/dist/compile/check-composite.d.ts +34 -0
- package/dist/compile/check-composite.d.ts.map +1 -0
- package/dist/compile/check-composite.js +117 -0
- package/dist/compile/check-scalar.d.ts +24 -0
- package/dist/compile/check-scalar.d.ts.map +1 -0
- package/dist/compile/check-scalar.js +73 -0
- package/dist/compile/check.d.ts +15 -0
- package/dist/compile/check.d.ts.map +1 -0
- package/dist/compile/check.js +98 -0
- package/dist/compile/context.d.ts +35 -0
- package/dist/compile/context.d.ts.map +1 -0
- package/dist/compile/context.js +72 -0
- package/dist/compile/graph-predicate.d.ts +19 -0
- package/dist/compile/graph-predicate.d.ts.map +1 -0
- package/dist/compile/graph-predicate.js +460 -0
- package/dist/compile/guard.d.ts +41 -0
- package/dist/compile/guard.d.ts.map +1 -0
- package/dist/compile/guard.js +180 -0
- package/dist/compile/index.d.ts +8 -0
- package/dist/compile/index.d.ts.map +1 -0
- package/dist/compile/index.js +6 -0
- package/dist/compile/issue.d.ts +18 -0
- package/dist/compile/issue.d.ts.map +1 -0
- package/dist/compile/issue.js +28 -0
- package/dist/compile/names.d.ts +16 -0
- package/dist/compile/names.d.ts.map +1 -0
- package/dist/compile/names.js +82 -0
- package/dist/compile/predicate.d.ts +23 -0
- package/dist/compile/predicate.d.ts.map +1 -0
- package/dist/compile/predicate.js +317 -0
- package/dist/compile/runtime.d.ts +55 -0
- package/dist/compile/runtime.d.ts.map +1 -0
- package/dist/compile/runtime.js +63 -0
- package/dist/compile/source.d.ts +11 -0
- package/dist/compile/source.d.ts.map +1 -0
- package/dist/compile/source.js +51 -0
- package/dist/compile/types.d.ts +52 -0
- package/dist/compile/types.d.ts.map +1 -0
- package/dist/compile/types.js +5 -0
- package/dist/decoder/index.d.ts +106 -0
- package/dist/decoder/index.d.ts.map +1 -0
- package/dist/decoder/index.js +262 -0
- package/dist/evaluate/check-composite.d.ts +39 -0
- package/dist/evaluate/check-composite.d.ts.map +1 -0
- package/dist/evaluate/check-composite.js +184 -0
- package/dist/evaluate/check-scalar.d.ts +20 -0
- package/dist/evaluate/check-scalar.d.ts.map +1 -0
- package/dist/evaluate/check-scalar.js +81 -0
- package/dist/evaluate/check.d.ts +11 -0
- package/dist/evaluate/check.d.ts.map +1 -0
- package/dist/evaluate/check.js +126 -0
- package/dist/evaluate/index.d.ts +7 -0
- package/dist/evaluate/index.d.ts.map +1 -0
- package/dist/evaluate/index.js +6 -0
- package/dist/evaluate/issue.d.ts +10 -0
- package/dist/evaluate/issue.d.ts.map +1 -0
- package/dist/evaluate/issue.js +11 -0
- package/dist/evaluate/predicate.d.ts +26 -0
- package/dist/evaluate/predicate.d.ts.map +1 -0
- package/dist/evaluate/predicate.js +37 -0
- package/dist/evaluate/shared.d.ts +59 -0
- package/dist/evaluate/shared.d.ts.map +1 -0
- package/dist/evaluate/shared.js +96 -0
- package/dist/evaluate/state.d.ts +65 -0
- package/dist/evaluate/state.d.ts.map +1 -0
- package/dist/evaluate/state.js +66 -0
- package/dist/guard/base.d.ts +72 -0
- package/dist/guard/base.d.ts.map +1 -0
- package/dist/guard/base.js +136 -0
- package/dist/guard/error.d.ts +19 -0
- package/dist/guard/error.d.ts.map +1 -0
- package/dist/guard/error.js +22 -0
- package/dist/guard/index.d.ts +10 -0
- package/dist/guard/index.d.ts.map +1 -0
- package/dist/guard/index.js +8 -0
- package/dist/guard/number.d.ts +32 -0
- package/dist/guard/number.d.ts.map +1 -0
- package/dist/guard/number.js +71 -0
- package/dist/guard/props.d.ts +18 -0
- package/dist/guard/props.d.ts.map +1 -0
- package/dist/guard/props.js +35 -0
- package/dist/guard/read.d.ts +42 -0
- package/dist/guard/read.d.ts.map +1 -0
- package/dist/guard/read.js +114 -0
- package/dist/guard/registry.d.ts +15 -0
- package/dist/guard/registry.d.ts.map +1 -0
- package/dist/guard/registry.js +21 -0
- package/dist/guard/string.d.ts +36 -0
- package/dist/guard/string.d.ts.map +1 -0
- package/dist/guard/string.js +95 -0
- package/dist/guard/types.d.ts +103 -0
- package/dist/guard/types.d.ts.map +1 -0
- package/dist/guard/types.js +5 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/internal/index.d.ts +34 -0
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/index.js +56 -0
- package/dist/ir/builder.d.ts +173 -0
- package/dist/ir/builder.d.ts.map +1 -0
- package/dist/ir/builder.js +481 -0
- package/dist/ir/freeze.d.ts +10 -0
- package/dist/ir/freeze.d.ts.map +1 -0
- package/dist/ir/freeze.js +102 -0
- package/dist/ir/index.d.ts +9 -0
- package/dist/ir/index.d.ts.map +1 -0
- package/dist/ir/index.js +7 -0
- package/dist/ir/regexp.d.ts +6 -0
- package/dist/ir/regexp.d.ts.map +1 -0
- package/dist/ir/regexp.js +12 -0
- package/dist/ir/types.d.ts +215 -0
- package/dist/ir/types.d.ts.map +1 -0
- package/dist/ir/types.js +5 -0
- package/dist/ir/validate.d.ts +10 -0
- package/dist/ir/validate.d.ts.map +1 -0
- package/dist/ir/validate.js +271 -0
- package/dist/issue/index.d.ts +44 -0
- package/dist/issue/index.d.ts.map +1 -0
- package/dist/issue/index.js +152 -0
- package/dist/json-schema/emit-combinator.d.ts +28 -0
- package/dist/json-schema/emit-combinator.d.ts.map +1 -0
- package/dist/json-schema/emit-combinator.js +96 -0
- package/dist/json-schema/emit-composite.d.ts +28 -0
- package/dist/json-schema/emit-composite.d.ts.map +1 -0
- package/dist/json-schema/emit-composite.js +127 -0
- package/dist/json-schema/emit-scalar.d.ts +25 -0
- package/dist/json-schema/emit-scalar.d.ts.map +1 -0
- package/dist/json-schema/emit-scalar.js +104 -0
- package/dist/json-schema/emit-types.d.ts +12 -0
- package/dist/json-schema/emit-types.d.ts.map +1 -0
- package/dist/json-schema/emit-types.js +5 -0
- package/dist/json-schema/emit.d.ts +12 -0
- package/dist/json-schema/emit.d.ts.map +1 -0
- package/dist/json-schema/emit.js +62 -0
- package/dist/json-schema/freeze.d.ts +14 -0
- package/dist/json-schema/freeze.d.ts.map +1 -0
- package/dist/json-schema/freeze.js +114 -0
- package/dist/json-schema/index.d.ts +20 -0
- package/dist/json-schema/index.d.ts.map +1 -0
- package/dist/json-schema/index.js +76 -0
- package/dist/json-schema/issue.d.ts +11 -0
- package/dist/json-schema/issue.d.ts.map +1 -0
- package/dist/json-schema/issue.js +14 -0
- package/dist/json-schema/read.d.ts +29 -0
- package/dist/json-schema/read.d.ts.map +1 -0
- package/dist/json-schema/read.js +87 -0
- package/dist/json-schema/types.d.ts +106 -0
- package/dist/json-schema/types.d.ts.map +1 -0
- package/dist/json-schema/types.js +5 -0
- package/dist/kind/index.d.ts +119 -0
- package/dist/kind/index.d.ts.map +1 -0
- package/dist/kind/index.js +94 -0
- package/dist/lower/index.d.ts +7 -0
- package/dist/lower/index.d.ts.map +1 -0
- package/dist/lower/index.js +199 -0
- package/dist/message/index.d.ts +51 -0
- package/dist/message/index.d.ts.map +1 -0
- package/dist/message/index.js +269 -0
- package/dist/optimize/compact.d.ts +10 -0
- package/dist/optimize/compact.d.ts.map +1 -0
- package/dist/optimize/compact.js +60 -0
- package/dist/optimize/fold-boolean.d.ts +15 -0
- package/dist/optimize/fold-boolean.d.ts.map +1 -0
- package/dist/optimize/fold-boolean.js +75 -0
- package/dist/optimize/fold-common.d.ts +45 -0
- package/dist/optimize/fold-common.d.ts.map +1 -0
- package/dist/optimize/fold-common.js +71 -0
- package/dist/optimize/fold-scalar.d.ts +59 -0
- package/dist/optimize/fold-scalar.d.ts.map +1 -0
- package/dist/optimize/fold-scalar.js +174 -0
- package/dist/optimize/fold.d.ts +10 -0
- package/dist/optimize/fold.d.ts.map +1 -0
- package/dist/optimize/fold.js +103 -0
- package/dist/optimize/index.d.ts +10 -0
- package/dist/optimize/index.d.ts.map +1 -0
- package/dist/optimize/index.js +23 -0
- package/dist/optimize/map-node.d.ts +21 -0
- package/dist/optimize/map-node.d.ts.map +1 -0
- package/dist/optimize/map-node.js +222 -0
- package/dist/optimize/remap.d.ts +30 -0
- package/dist/optimize/remap.d.ts.map +1 -0
- package/dist/optimize/remap.js +46 -0
- package/dist/optimize/rewrite.d.ts +22 -0
- package/dist/optimize/rewrite.d.ts.map +1 -0
- package/dist/optimize/rewrite.js +34 -0
- package/dist/plan/cache.d.ts +20 -0
- package/dist/plan/cache.d.ts.map +1 -0
- package/dist/plan/cache.js +122 -0
- package/dist/plan/index.d.ts +8 -0
- package/dist/plan/index.d.ts.map +1 -0
- package/dist/plan/index.js +6 -0
- package/dist/plan/predicate.d.ts +27 -0
- package/dist/plan/predicate.d.ts.map +1 -0
- package/dist/plan/predicate.js +415 -0
- package/dist/plan/schema-predicate.d.ts +15 -0
- package/dist/plan/schema-predicate.d.ts.map +1 -0
- package/dist/plan/schema-predicate.js +277 -0
- package/dist/plan/types.d.ts +18 -0
- package/dist/plan/types.d.ts.map +1 -0
- package/dist/plan/types.js +5 -0
- package/dist/result/index.d.ts +27 -0
- package/dist/result/index.d.ts.map +1 -0
- package/dist/result/index.js +20 -0
- package/dist/schema/common.d.ts +30 -0
- package/dist/schema/common.d.ts.map +1 -0
- package/dist/schema/common.js +102 -0
- package/dist/schema/freeze.d.ts +10 -0
- package/dist/schema/freeze.d.ts.map +1 -0
- package/dist/schema/freeze.js +163 -0
- package/dist/schema/index.d.ts +11 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +9 -0
- package/dist/schema/lazy.d.ts +10 -0
- package/dist/schema/lazy.d.ts.map +1 -0
- package/dist/schema/lazy.js +25 -0
- package/dist/schema/literal.d.ts +10 -0
- package/dist/schema/literal.d.ts.map +1 -0
- package/dist/schema/literal.js +17 -0
- package/dist/schema/types.d.ts +243 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/types.js +9 -0
- package/dist/schema/validate.d.ts +10 -0
- package/dist/schema/validate.d.ts.map +1 -0
- package/dist/schema/validate.js +268 -0
- package/docs/api.md +301 -0
- package/docs/engine-notes.md +153 -0
- package/docs/index.html +1242 -0
- package/package.json +68 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file schema.ts
|
|
3
|
+
* @brief Object schema construction and shape rewrites.
|
|
4
|
+
*/
|
|
5
|
+
import { ObjectModeTag, PresenceTag, SchemaTag } from "../../kind/index.js";
|
|
6
|
+
import { includesString, isRecord, isUnknownArray, readGuardSchema } from "../../internal/index.js";
|
|
7
|
+
import { isSchemaValue } from "../../schema/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* @brief object schema.
|
|
10
|
+
*/
|
|
11
|
+
export function objectSchema(shape, mode) {
|
|
12
|
+
if (!isRecord(shape)) {
|
|
13
|
+
throw new TypeError("object shape must be an object");
|
|
14
|
+
}
|
|
15
|
+
const keys = Object.keys(shape);
|
|
16
|
+
const entries = new Array(keys.length);
|
|
17
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
18
|
+
const key = keys[index];
|
|
19
|
+
if (key === undefined) {
|
|
20
|
+
throw new TypeError("Object key disappeared during construction");
|
|
21
|
+
}
|
|
22
|
+
const guard = shape[key];
|
|
23
|
+
const entrySchema = normalizeObjectEntrySchema(readGuardSchema(guard, `object property ${key}`));
|
|
24
|
+
entries[index] = {
|
|
25
|
+
key,
|
|
26
|
+
schema: entrySchema.schema,
|
|
27
|
+
presence: entrySchema.presence
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return objectSchemaFromEntries(entries, mode);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @brief object schema from entries.
|
|
34
|
+
*/
|
|
35
|
+
export function objectSchemaFromEntries(sourceEntries, mode) {
|
|
36
|
+
const entries = new Array(sourceEntries.length);
|
|
37
|
+
const keys = new Array(sourceEntries.length);
|
|
38
|
+
const keyLookup = makeObjectKeyLookup();
|
|
39
|
+
for (let index = 0; index < sourceEntries.length; index += 1) {
|
|
40
|
+
const entry = sourceEntries[index];
|
|
41
|
+
if (entry === undefined) {
|
|
42
|
+
throw new TypeError("object entry disappeared during construction");
|
|
43
|
+
}
|
|
44
|
+
if (hasObjectKey(keyLookup, entry.key)) {
|
|
45
|
+
throw new TypeError(`object key ${entry.key} is duplicated`);
|
|
46
|
+
}
|
|
47
|
+
defineObjectKey(keyLookup, entry.key);
|
|
48
|
+
entries[index] = entry;
|
|
49
|
+
keys[index] = entry.key;
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
tag: SchemaTag.Object,
|
|
53
|
+
entries,
|
|
54
|
+
keys,
|
|
55
|
+
keyLookup,
|
|
56
|
+
mode
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @brief read object constructor schema.
|
|
61
|
+
*/
|
|
62
|
+
export function readObjectConstructorSchema(schema) {
|
|
63
|
+
if (!isSchemaValue(schema) || schema.tag !== SchemaTag.Object) {
|
|
64
|
+
throw new TypeError("ObjectGuard constructor requires an object schema");
|
|
65
|
+
}
|
|
66
|
+
return schema;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @brief read object method schema.
|
|
70
|
+
*/
|
|
71
|
+
export function readObjectMethodSchema(guard, label) {
|
|
72
|
+
const schema = readGuardSchema(guard, label);
|
|
73
|
+
if (schema.tag !== SchemaTag.Object) {
|
|
74
|
+
throw new TypeError(`${label} must be an object TypeSea guard`);
|
|
75
|
+
}
|
|
76
|
+
return schema;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @brief merge object schemas.
|
|
80
|
+
*/
|
|
81
|
+
export function mergeObjectSchemas(base, extension) {
|
|
82
|
+
const entries = [];
|
|
83
|
+
for (let index = 0; index < base.entries.length; index += 1) {
|
|
84
|
+
const entry = base.entries[index];
|
|
85
|
+
if (entry !== undefined) {
|
|
86
|
+
entries.push(findObjectEntry(extension.entries, entry.key) ?? entry);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
for (let index = 0; index < extension.entries.length; index += 1) {
|
|
90
|
+
const entry = extension.entries[index];
|
|
91
|
+
if (entry !== undefined && !hasObjectKey(base.keyLookup, entry.key)) {
|
|
92
|
+
entries.push(entry);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return objectSchemaFromEntries(entries, base.mode);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @brief pick object schema.
|
|
99
|
+
*/
|
|
100
|
+
export function pickObjectSchema(schema, keys) {
|
|
101
|
+
const entries = new Array(keys.length);
|
|
102
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
103
|
+
const key = keys[index];
|
|
104
|
+
const entry = key === undefined
|
|
105
|
+
? undefined
|
|
106
|
+
: findObjectEntry(schema.entries, key);
|
|
107
|
+
if (entry === undefined) {
|
|
108
|
+
throw new TypeError("picked object key disappeared during construction");
|
|
109
|
+
}
|
|
110
|
+
entries[index] = entry;
|
|
111
|
+
}
|
|
112
|
+
return objectSchemaFromEntries(entries, schema.mode);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* @brief omit object schema.
|
|
116
|
+
*/
|
|
117
|
+
export function omitObjectSchema(schema, keys) {
|
|
118
|
+
const entries = [];
|
|
119
|
+
for (let index = 0; index < schema.entries.length; index += 1) {
|
|
120
|
+
const entry = schema.entries[index];
|
|
121
|
+
if (entry !== undefined && !includesString(keys, entry.key)) {
|
|
122
|
+
entries.push(entry);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return objectSchemaFromEntries(entries, schema.mode);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* @brief partial object schema.
|
|
129
|
+
*/
|
|
130
|
+
export function partialObjectSchema(schema) {
|
|
131
|
+
const entries = new Array(schema.entries.length);
|
|
132
|
+
for (let index = 0; index < schema.entries.length; index += 1) {
|
|
133
|
+
const entry = schema.entries[index];
|
|
134
|
+
if (entry !== undefined) {
|
|
135
|
+
entries[index] = {
|
|
136
|
+
key: entry.key,
|
|
137
|
+
schema: entry.schema,
|
|
138
|
+
presence: PresenceTag.Optional
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return objectSchemaFromEntries(entries, schema.mode);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* @brief read object key selection.
|
|
146
|
+
*/
|
|
147
|
+
export function readObjectKeySelection(keys, schema, label) {
|
|
148
|
+
if (!isUnknownArray(keys)) {
|
|
149
|
+
throw new TypeError(`${label} must be an array`);
|
|
150
|
+
}
|
|
151
|
+
const selected = new Array(keys.length);
|
|
152
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
153
|
+
const key = keys[index];
|
|
154
|
+
if (typeof key !== "string") {
|
|
155
|
+
throw new TypeError(`${label} must contain only strings`);
|
|
156
|
+
}
|
|
157
|
+
if (!hasObjectKey(schema.keyLookup, key)) {
|
|
158
|
+
throw new TypeError(`${label} contains unknown object key ${key}`);
|
|
159
|
+
}
|
|
160
|
+
if (includesString(selected, key)) {
|
|
161
|
+
throw new TypeError(`${label} contains duplicate object key ${key}`);
|
|
162
|
+
}
|
|
163
|
+
selected[index] = key;
|
|
164
|
+
}
|
|
165
|
+
return selected;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* @brief find object entry.
|
|
169
|
+
*/
|
|
170
|
+
function findObjectEntry(entries, key) {
|
|
171
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
172
|
+
const entry = entries[index];
|
|
173
|
+
if (entry?.key === key) {
|
|
174
|
+
return entry;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* @brief make object key lookup.
|
|
181
|
+
*/
|
|
182
|
+
function makeObjectKeyLookup() {
|
|
183
|
+
return Object.create(null);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* @brief define object key.
|
|
187
|
+
*/
|
|
188
|
+
function defineObjectKey(target, key) {
|
|
189
|
+
Object.defineProperty(target, key, {
|
|
190
|
+
configurable: false,
|
|
191
|
+
enumerable: true,
|
|
192
|
+
value: true,
|
|
193
|
+
writable: false
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* @brief has object key.
|
|
198
|
+
*/
|
|
199
|
+
function hasObjectKey(keyLookup, key) {
|
|
200
|
+
return keyLookup[key] === true;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* @brief normalize object entry schema.
|
|
204
|
+
*/
|
|
205
|
+
function normalizeObjectEntrySchema(schema) {
|
|
206
|
+
switch (schema.tag) {
|
|
207
|
+
case SchemaTag.Optional:
|
|
208
|
+
return {
|
|
209
|
+
schema: normalizeObjectEntrySchema(schema.inner).schema,
|
|
210
|
+
presence: PresenceTag.Optional
|
|
211
|
+
};
|
|
212
|
+
case SchemaTag.Undefinedable:
|
|
213
|
+
return normalizeWrappedObjectEntrySchema(schema.inner, (inner) => ({
|
|
214
|
+
tag: SchemaTag.Undefinedable,
|
|
215
|
+
inner
|
|
216
|
+
}), schema);
|
|
217
|
+
case SchemaTag.Nullable:
|
|
218
|
+
return normalizeWrappedObjectEntrySchema(schema.inner, (inner) => ({
|
|
219
|
+
tag: SchemaTag.Nullable,
|
|
220
|
+
inner
|
|
221
|
+
}), schema);
|
|
222
|
+
case SchemaTag.Brand:
|
|
223
|
+
return normalizeWrappedObjectEntrySchema(schema.inner, (inner) => ({
|
|
224
|
+
tag: SchemaTag.Brand,
|
|
225
|
+
inner,
|
|
226
|
+
brand: schema.brand
|
|
227
|
+
}), schema);
|
|
228
|
+
case SchemaTag.Refine:
|
|
229
|
+
return normalizeWrappedObjectEntrySchema(schema.inner, (inner) => ({
|
|
230
|
+
tag: SchemaTag.Refine,
|
|
231
|
+
inner,
|
|
232
|
+
predicate: schema.predicate,
|
|
233
|
+
name: schema.name
|
|
234
|
+
}), schema);
|
|
235
|
+
default:
|
|
236
|
+
return {
|
|
237
|
+
schema,
|
|
238
|
+
presence: PresenceTag.Required
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* @brief normalize wrapped object entry schema.
|
|
244
|
+
*/
|
|
245
|
+
function normalizeWrappedObjectEntrySchema(inner, wrap, original) {
|
|
246
|
+
const normalized = normalizeObjectEntrySchema(inner);
|
|
247
|
+
if (normalized.presence === PresenceTag.Required) {
|
|
248
|
+
return {
|
|
249
|
+
schema: original,
|
|
250
|
+
presence: PresenceTag.Required
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
schema: wrap(normalized.schema),
|
|
255
|
+
presence: PresenceTag.Optional
|
|
256
|
+
};
|
|
257
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file types.ts
|
|
3
|
+
* @brief Object builder type algebra.
|
|
4
|
+
*/
|
|
5
|
+
import type { BaseGuard, Guard, GuardPresence, GuardValue, Infer, Presence } from "../../guard/index.js";
|
|
6
|
+
import type { ObjectModeTag } from "../../kind/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* @brief object shape.
|
|
9
|
+
*/
|
|
10
|
+
export type ObjectShape = Readonly<Record<string, Guard<unknown, Presence>>>;
|
|
11
|
+
/**
|
|
12
|
+
* @brief object guard mode.
|
|
13
|
+
*/
|
|
14
|
+
export type ObjectGuardMode = typeof ObjectModeTag.Passthrough | typeof ObjectModeTag.Strict;
|
|
15
|
+
/**
|
|
16
|
+
* @brief optional keys.
|
|
17
|
+
*/
|
|
18
|
+
export type OptionalKeys<TShape extends ObjectShape> = {
|
|
19
|
+
[TKey in keyof TShape]-?: GuardPresence<TShape[TKey]> extends "optional" ? TKey : never;
|
|
20
|
+
}[keyof TShape];
|
|
21
|
+
/**
|
|
22
|
+
* @brief required keys.
|
|
23
|
+
*/
|
|
24
|
+
export type RequiredKeys<TShape extends ObjectShape> = {
|
|
25
|
+
[TKey in keyof TShape]-?: GuardPresence<TShape[TKey]> extends "optional" ? never : TKey;
|
|
26
|
+
}[keyof TShape];
|
|
27
|
+
/**
|
|
28
|
+
* @brief infer object.
|
|
29
|
+
*/
|
|
30
|
+
export type InferObject<TShape extends ObjectShape> = Simplify<{
|
|
31
|
+
readonly [TKey in RequiredKeys<TShape>]: Infer<TShape[TKey]>;
|
|
32
|
+
} & {
|
|
33
|
+
readonly [TKey in OptionalKeys<TShape>]?: GuardValue<TShape[TKey]>;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* @brief simplify.
|
|
37
|
+
*/
|
|
38
|
+
export type Simplify<TValue> = {
|
|
39
|
+
readonly [TKey in keyof TValue]: TValue[TKey];
|
|
40
|
+
} & {};
|
|
41
|
+
/**
|
|
42
|
+
* @brief merge object shapes.
|
|
43
|
+
*/
|
|
44
|
+
export type MergeObjectShapes<TBase extends ObjectShape, TExtension extends ObjectShape> = Simplify<Omit<TBase, keyof TExtension> & TExtension>;
|
|
45
|
+
/**
|
|
46
|
+
* @brief partial object shape.
|
|
47
|
+
*/
|
|
48
|
+
export type PartialObjectShape<TShape extends ObjectShape> = {
|
|
49
|
+
readonly [TKey in keyof TShape]: BaseGuard<GuardValue<TShape[TKey]>, "optional">;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* @brief pick object shape.
|
|
53
|
+
*/
|
|
54
|
+
export type PickObjectShape<TShape extends ObjectShape, TKey extends string> = Pick<TShape, Extract<keyof TShape, TKey>>;
|
|
55
|
+
/**
|
|
56
|
+
* @brief omit object shape.
|
|
57
|
+
*/
|
|
58
|
+
export type OmitObjectShape<TShape extends ObjectShape, TKey extends string> = Omit<TShape, Extract<keyof TShape, TKey>>;
|
|
59
|
+
/**
|
|
60
|
+
* @brief string key of.
|
|
61
|
+
*/
|
|
62
|
+
export type StringKeyOf<TValue> = Extract<keyof TValue, string>;
|
|
63
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/builders/object/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,KAAK,EACL,aAAa,EACb,UAAU,EACV,KAAK,EACL,QAAQ,EACT,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;AAE7E;;GAEG;AACH,MAAM,MAAM,eAAe,GACvB,OAAO,aAAa,CAAC,WAAW,GAChC,OAAO,aAAa,CAAC,MAAM,CAAC;AAEhC;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,MAAM,SAAS,WAAW,IAAI;KACpD,IAAI,IAAI,MAAM,MAAM,CAAC,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,UAAU,GACpE,IAAI,GACJ,KAAK;CACV,CAAC,MAAM,MAAM,CAAC,CAAC;AAEhB;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,MAAM,SAAS,WAAW,IAAI;KACpD,IAAI,IAAI,MAAM,MAAM,CAAC,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,UAAU,GACpE,KAAK,GACL,IAAI;CACT,CAAC,MAAM,MAAM,CAAC,CAAC;AAEhB;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,WAAW,IAAI,QAAQ,CAC5D;IACE,QAAQ,EAAE,IAAI,IAAI,YAAY,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CAC7D,GAAG;IACF,QAAQ,EAAE,IAAI,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CACnE,CACF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,MAAM,IAAI;IAC7B,QAAQ,EAAE,IAAI,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC;CAC9C,GAAG,EAAE,CAAC;AAEP;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAC3B,KAAK,SAAS,WAAW,EACzB,UAAU,SAAS,WAAW,IAC5B,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,UAAU,CAAC,GAAG,UAAU,CAAC,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,MAAM,SAAS,WAAW,IAAI;IAC3D,QAAQ,EAAE,IAAI,IAAI,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC;CACjF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,CACzB,MAAM,SAAS,WAAW,EAC1B,IAAI,SAAS,MAAM,IACjB,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,eAAe,CACzB,MAAM,SAAS,WAAW,EAC1B,IAAI,SAAS,MAAM,IACjB,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,MAAM,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file scalar.ts
|
|
3
|
+
* @brief Primitive and literal guard builders.
|
|
4
|
+
*/
|
|
5
|
+
import { BaseGuard, NumberGuard, StringGuard } from "../guard/index.js";
|
|
6
|
+
import type { LiteralValue } from "../schema/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* @brief string guard.
|
|
9
|
+
*/
|
|
10
|
+
export declare const stringGuard: StringGuard<"required">;
|
|
11
|
+
/**
|
|
12
|
+
* @brief unknown guard.
|
|
13
|
+
*/
|
|
14
|
+
export declare const unknownGuard: BaseGuard<unknown, "required">;
|
|
15
|
+
/**
|
|
16
|
+
* @brief never guard.
|
|
17
|
+
*/
|
|
18
|
+
export declare const neverGuard: BaseGuard<never, "required">;
|
|
19
|
+
/**
|
|
20
|
+
* @brief number guard.
|
|
21
|
+
*/
|
|
22
|
+
export declare const numberGuard: NumberGuard<"required">;
|
|
23
|
+
/**
|
|
24
|
+
* @brief bigint guard.
|
|
25
|
+
*/
|
|
26
|
+
export declare const bigintGuard: BaseGuard<bigint, "required">;
|
|
27
|
+
/**
|
|
28
|
+
* @brief symbol guard.
|
|
29
|
+
*/
|
|
30
|
+
export declare const symbolGuard: BaseGuard<symbol, "required">;
|
|
31
|
+
/**
|
|
32
|
+
* @brief boolean guard.
|
|
33
|
+
*/
|
|
34
|
+
export declare const booleanGuard: BaseGuard<boolean, "required">;
|
|
35
|
+
/**
|
|
36
|
+
* @brief literal.
|
|
37
|
+
*/
|
|
38
|
+
export declare function literal<const TValue extends LiteralValue>(value: TValue): BaseGuard<TValue>;
|
|
39
|
+
//# sourceMappingURL=scalar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../../src/builders/scalar.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,SAAS,EACT,WAAW,EACX,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD;;GAEG;AACH,eAAO,MAAM,WAAW,yBAGtB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,YAAY,gCAEvB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,UAAU,8BAErB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,WAAW,yBAGtB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,WAAW,+BAEtB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,WAAW,+BAEtB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,YAAY,gCAEvB,CAAC;AAEH;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,CAAC,MAAM,SAAS,YAAY,EACvD,KAAK,EAAE,MAAM,GACZ,SAAS,CAAC,MAAM,CAAC,CAQnB"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file scalar.ts
|
|
3
|
+
* @brief Primitive and literal guard builders.
|
|
4
|
+
*/
|
|
5
|
+
import { SchemaTag } from "../kind/index.js";
|
|
6
|
+
import { BaseGuard, NumberGuard, StringGuard } from "../guard/index.js";
|
|
7
|
+
import { isLiteralValue } from "../schema/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* @brief string guard.
|
|
10
|
+
*/
|
|
11
|
+
export const stringGuard = new StringGuard({
|
|
12
|
+
tag: SchemaTag.String,
|
|
13
|
+
checks: []
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* @brief unknown guard.
|
|
17
|
+
*/
|
|
18
|
+
export const unknownGuard = new BaseGuard({
|
|
19
|
+
tag: SchemaTag.Unknown
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* @brief never guard.
|
|
23
|
+
*/
|
|
24
|
+
export const neverGuard = new BaseGuard({
|
|
25
|
+
tag: SchemaTag.Never
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* @brief number guard.
|
|
29
|
+
*/
|
|
30
|
+
export const numberGuard = new NumberGuard({
|
|
31
|
+
tag: SchemaTag.Number,
|
|
32
|
+
checks: []
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* @brief bigint guard.
|
|
36
|
+
*/
|
|
37
|
+
export const bigintGuard = new BaseGuard({
|
|
38
|
+
tag: SchemaTag.BigInt
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* @brief symbol guard.
|
|
42
|
+
*/
|
|
43
|
+
export const symbolGuard = new BaseGuard({
|
|
44
|
+
tag: SchemaTag.Symbol
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* @brief boolean guard.
|
|
48
|
+
*/
|
|
49
|
+
export const booleanGuard = new BaseGuard({
|
|
50
|
+
tag: SchemaTag.Boolean
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* @brief literal.
|
|
54
|
+
*/
|
|
55
|
+
export function literal(value) {
|
|
56
|
+
if (!isLiteralValue(value)) {
|
|
57
|
+
throw new TypeError("literal value must be a primitive literal");
|
|
58
|
+
}
|
|
59
|
+
return new BaseGuard({
|
|
60
|
+
tag: SchemaTag.Literal,
|
|
61
|
+
value
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file table.ts
|
|
3
|
+
* @brief Frozen public builder table.
|
|
4
|
+
*/
|
|
5
|
+
import { asyncDecoder, asyncPipe, asyncRefine, asyncTransform } from "../async/index.js";
|
|
6
|
+
import { decoder, pipe, transform } from "../decoder/index.js";
|
|
7
|
+
import { array, discriminatedUnion, intersect, record, tuple, union } from "./composite.js";
|
|
8
|
+
import { lazy, nullable, optional, refine, undefinedable } from "./modifier.js";
|
|
9
|
+
import { extend, object, omit, partial, pick, strictObject } from "./object/index.js";
|
|
10
|
+
import { literal } from "./scalar.js";
|
|
11
|
+
/**
|
|
12
|
+
* @brief t.
|
|
13
|
+
*/
|
|
14
|
+
export declare const t: Readonly<{
|
|
15
|
+
readonly unknown: import("../index.js").BaseGuard<unknown, "required">;
|
|
16
|
+
readonly never: import("../index.js").BaseGuard<never, "required">;
|
|
17
|
+
readonly string: import("../index.js").StringGuard<"required">;
|
|
18
|
+
readonly number: import("../index.js").NumberGuard<"required">;
|
|
19
|
+
readonly bigint: import("../index.js").BaseGuard<bigint, "required">;
|
|
20
|
+
readonly symbol: import("../index.js").BaseGuard<symbol, "required">;
|
|
21
|
+
readonly boolean: import("../index.js").BaseGuard<boolean, "required">;
|
|
22
|
+
readonly literal: typeof literal;
|
|
23
|
+
readonly array: typeof array;
|
|
24
|
+
readonly tuple: typeof tuple;
|
|
25
|
+
readonly record: typeof record;
|
|
26
|
+
readonly decoder: typeof decoder;
|
|
27
|
+
readonly object: typeof object;
|
|
28
|
+
readonly strictObject: typeof strictObject;
|
|
29
|
+
readonly extend: typeof extend;
|
|
30
|
+
readonly pick: typeof pick;
|
|
31
|
+
readonly omit: typeof omit;
|
|
32
|
+
readonly partial: typeof partial;
|
|
33
|
+
readonly union: typeof union;
|
|
34
|
+
readonly intersect: typeof intersect;
|
|
35
|
+
readonly discriminatedUnion: typeof discriminatedUnion;
|
|
36
|
+
readonly optional: typeof optional;
|
|
37
|
+
readonly undefinedable: typeof undefinedable;
|
|
38
|
+
readonly nullable: typeof nullable;
|
|
39
|
+
readonly lazy: typeof lazy;
|
|
40
|
+
readonly refine: typeof refine;
|
|
41
|
+
readonly transform: typeof transform;
|
|
42
|
+
readonly pipe: typeof pipe;
|
|
43
|
+
readonly coerce: Readonly<{
|
|
44
|
+
readonly string: typeof import("../decoder/index.js").coerceString;
|
|
45
|
+
readonly number: typeof import("../decoder/index.js").coerceNumber;
|
|
46
|
+
readonly boolean: typeof import("../decoder/index.js").coerceBoolean;
|
|
47
|
+
}>;
|
|
48
|
+
readonly asyncDecoder: typeof asyncDecoder;
|
|
49
|
+
readonly asyncRefine: typeof asyncRefine;
|
|
50
|
+
readonly asyncTransform: typeof asyncTransform;
|
|
51
|
+
readonly asyncPipe: typeof asyncPipe;
|
|
52
|
+
}>;
|
|
53
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../src/builders/table.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EAAU,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EACL,KAAK,EACL,kBAAkB,EAClB,SAAS,EACT,MAAM,EACN,KAAK,EACL,KAAK,EACN,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,MAAM,EACN,MAAM,EACN,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,YAAY,EACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAGL,OAAO,EAMR,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,eAAO,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkCH,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file table.ts
|
|
3
|
+
* @brief Frozen public builder table.
|
|
4
|
+
*/
|
|
5
|
+
import { asyncDecoder, asyncPipe, asyncRefine, asyncTransform } from "../async/index.js";
|
|
6
|
+
import { coerce, decoder, pipe, transform } from "../decoder/index.js";
|
|
7
|
+
import { array, discriminatedUnion, intersect, record, tuple, union } from "./composite.js";
|
|
8
|
+
import { lazy, nullable, optional, refine, undefinedable } from "./modifier.js";
|
|
9
|
+
import { extend, object, omit, partial, pick, strictObject } from "./object/index.js";
|
|
10
|
+
import { bigintGuard, booleanGuard, literal, neverGuard, numberGuard, stringGuard, symbolGuard, unknownGuard } from "./scalar.js";
|
|
11
|
+
/**
|
|
12
|
+
* @brief t.
|
|
13
|
+
*/
|
|
14
|
+
export const t = Object.freeze({
|
|
15
|
+
unknown: unknownGuard,
|
|
16
|
+
never: neverGuard,
|
|
17
|
+
string: stringGuard,
|
|
18
|
+
number: numberGuard,
|
|
19
|
+
bigint: bigintGuard,
|
|
20
|
+
symbol: symbolGuard,
|
|
21
|
+
boolean: booleanGuard,
|
|
22
|
+
literal,
|
|
23
|
+
array,
|
|
24
|
+
tuple,
|
|
25
|
+
record,
|
|
26
|
+
decoder,
|
|
27
|
+
object,
|
|
28
|
+
strictObject,
|
|
29
|
+
extend,
|
|
30
|
+
pick,
|
|
31
|
+
omit,
|
|
32
|
+
partial,
|
|
33
|
+
union,
|
|
34
|
+
intersect,
|
|
35
|
+
discriminatedUnion,
|
|
36
|
+
optional,
|
|
37
|
+
undefinedable,
|
|
38
|
+
nullable,
|
|
39
|
+
lazy,
|
|
40
|
+
refine,
|
|
41
|
+
transform,
|
|
42
|
+
pipe,
|
|
43
|
+
coerce,
|
|
44
|
+
asyncDecoder,
|
|
45
|
+
asyncRefine,
|
|
46
|
+
asyncTransform,
|
|
47
|
+
asyncPipe
|
|
48
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file types.ts
|
|
3
|
+
* @brief Shared builder type algebra.
|
|
4
|
+
*/
|
|
5
|
+
import type { Guard, Infer, Presence } from "../guard/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* @brief tuple shape.
|
|
8
|
+
*/
|
|
9
|
+
export type TupleShape = readonly Guard<unknown, Presence>[];
|
|
10
|
+
/**
|
|
11
|
+
* @brief infer tuple.
|
|
12
|
+
*/
|
|
13
|
+
export type InferTuple<TShape extends TupleShape> = {
|
|
14
|
+
readonly [TKey in keyof TShape]: Infer<TShape[TKey]>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* @brief union input.
|
|
18
|
+
*/
|
|
19
|
+
export type UnionInput = readonly [Guard<unknown, Presence>, ...Guard<unknown, Presence>[]];
|
|
20
|
+
/**
|
|
21
|
+
* @brief discriminated union cases.
|
|
22
|
+
*/
|
|
23
|
+
export type DiscriminatedUnionCases<TKey extends string, TCases extends Readonly<Record<string, Guard<unknown, Presence>>>> = string extends TKey ? TCases : {
|
|
24
|
+
readonly [TCase in keyof TCases]: TCase extends string ? Infer<TCases[TCase]> extends Readonly<Record<TKey, TCase>> ? TCases[TCase] : never : never;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/builders/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,KAAK,EACL,KAAK,EACL,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,MAAM,SAAS,UAAU,IAAI;IAClD,QAAQ,EAAE,IAAI,IAAI,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CACrD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GACpB,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;AAErE;;GAEG;AACH,MAAM,MAAM,uBAAuB,CACjC,IAAI,SAAS,MAAM,EACnB,MAAM,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,IAC/D,MAAM,SAAS,IAAI,GACnB,MAAM,GACN;IACE,QAAQ,EAAE,KAAK,IAAI,MAAM,MAAM,GAAG,KAAK,SAAS,MAAM,GAClD,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,GACxD,MAAM,CAAC,KAAK,CAAC,GACb,KAAK,GACT,KAAK;CACR,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file compile/check-composite.ts
|
|
3
|
+
* @brief Composite diagnostic validator snippets.
|
|
4
|
+
*/
|
|
5
|
+
import { SchemaTag } from "../kind/index.js";
|
|
6
|
+
import type { DiscriminatedUnionCase, Schema } from "../schema/index.js";
|
|
7
|
+
import type { EmitContext } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* @brief check function emitter.
|
|
10
|
+
*/
|
|
11
|
+
export type CheckFunctionEmitter = (schema: Schema, context: EmitContext) => string;
|
|
12
|
+
/**
|
|
13
|
+
* @brief emit array check.
|
|
14
|
+
*/
|
|
15
|
+
export declare function emitArrayCheck(item: Schema, value: string, path: string, issues: string, context: EmitContext, emitChild: CheckFunctionEmitter): string;
|
|
16
|
+
/**
|
|
17
|
+
* @brief emit tuple check.
|
|
18
|
+
*/
|
|
19
|
+
export declare function emitTupleCheck(items: readonly Schema[], value: string, path: string, issues: string, context: EmitContext, emitChild: CheckFunctionEmitter): string;
|
|
20
|
+
/**
|
|
21
|
+
* @brief emit record check.
|
|
22
|
+
*/
|
|
23
|
+
export declare function emitRecordCheck(item: Schema, value: string, path: string, issues: string, context: EmitContext, emitChild: CheckFunctionEmitter): string;
|
|
24
|
+
/**
|
|
25
|
+
* @brief emit object check.
|
|
26
|
+
*/
|
|
27
|
+
export declare function emitObjectCheck(schema: Extract<Schema, {
|
|
28
|
+
readonly tag: typeof SchemaTag.Object;
|
|
29
|
+
}>, value: string, path: string, issues: string, context: EmitContext, emitChild: CheckFunctionEmitter): string;
|
|
30
|
+
/**
|
|
31
|
+
* @brief emit discriminated union check.
|
|
32
|
+
*/
|
|
33
|
+
export declare function emitDiscriminatedUnionCheck(key: string, cases: readonly DiscriminatedUnionCase[], value: string, path: string, issues: string, context: EmitContext, emitChild: CheckFunctionEmitter): string;
|
|
34
|
+
//# sourceMappingURL=check-composite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-composite.d.ts","sourceRoot":"","sources":["../../src/compile/check-composite.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAGL,SAAS,EACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,sBAAsB,EACtB,MAAM,EACP,MAAM,oBAAoB,CAAC;AAW5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CACjC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,WAAW,KACjB,MAAM,CAAC;AAEZ;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,oBAAoB,GAC9B,MAAM,CAuBR;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,oBAAoB,GAC9B,MAAM,CAiCR;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,oBAAoB,GAC9B,MAAM,CAsBR;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,OAAO,SAAS,CAAC,MAAM,CAAA;CAAE,CAAC,EAClE,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,oBAAoB,GAC9B,MAAM,CAqDR;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,SAAS,sBAAsB,EAAE,EACxC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,oBAAoB,GAC9B,MAAM,CA+CR"}
|