@sinclair/typebox 0.33.22 → 0.34.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/build/cjs/compiler/compiler.d.ts +2 -2
- package/build/cjs/compiler/compiler.js +13 -2
- package/build/cjs/errors/errors.js +7 -0
- package/build/cjs/index.d.ts +1 -2
- package/build/cjs/index.js +1 -2
- package/build/cjs/syntax/parse.d.ts +14 -15
- package/build/cjs/syntax/parse.js +6 -5
- package/build/cjs/syntax/runtime.d.ts +17 -4
- package/build/cjs/syntax/runtime.js +180 -27
- package/build/cjs/syntax/static.d.ts +104 -20
- package/build/cjs/type/guard/kind.d.ts +3 -0
- package/build/cjs/type/guard/kind.js +5 -0
- package/build/cjs/type/guard/type.d.ts +3 -0
- package/build/cjs/type/guard/type.js +13 -0
- package/build/cjs/type/index.d.ts +1 -2
- package/build/cjs/type/index.js +1 -2
- package/build/cjs/type/module/index.d.ts +1 -0
- package/build/cjs/type/{strict → module}/index.js +1 -1
- package/build/cjs/type/module/module.d.ts +71 -0
- package/build/cjs/type/module/module.js +34 -0
- package/build/cjs/type/ref/ref.d.ts +4 -7
- package/build/cjs/type/ref/ref.js +3 -11
- package/build/cjs/type/static/static.d.ts +1 -1
- package/build/cjs/type/type/json.d.ts +4 -17
- package/build/cjs/type/type/json.js +52 -68
- package/build/cjs/type/type/type.d.ts +1 -2
- package/build/cjs/type/type/type.js +55 -57
- package/build/cjs/value/cast/cast.js +8 -1
- package/build/cjs/value/check/check.js +8 -1
- package/build/cjs/value/clean/clean.js +8 -1
- package/build/cjs/value/convert/convert.js +7 -0
- package/build/cjs/value/create/create.js +7 -0
- package/build/cjs/value/default/default.js +7 -0
- package/build/cjs/value/transform/decode.js +11 -0
- package/build/cjs/value/transform/encode.js +11 -0
- package/build/esm/compiler/compiler.d.mts +2 -2
- package/build/esm/compiler/compiler.mjs +13 -2
- package/build/esm/errors/errors.mjs +7 -0
- package/build/esm/index.d.mts +1 -2
- package/build/esm/index.mjs +1 -2
- package/build/esm/syntax/parse.d.mts +14 -15
- package/build/esm/syntax/parse.mjs +6 -5
- package/build/esm/syntax/runtime.d.mts +17 -4
- package/build/esm/syntax/runtime.mjs +180 -27
- package/build/esm/syntax/static.d.mts +104 -20
- package/build/esm/type/guard/kind.d.mts +3 -0
- package/build/esm/type/guard/kind.mjs +4 -0
- package/build/esm/type/guard/type.d.mts +3 -0
- package/build/esm/type/guard/type.mjs +12 -0
- package/build/esm/type/index.d.mts +1 -2
- package/build/esm/type/index.mjs +1 -2
- package/build/esm/type/module/index.d.mts +1 -0
- package/build/esm/type/module/index.mjs +1 -0
- package/build/esm/type/module/module.d.mts +71 -0
- package/build/esm/type/module/module.mjs +28 -0
- package/build/esm/type/ref/ref.d.mts +4 -7
- package/build/esm/type/ref/ref.mjs +3 -11
- package/build/esm/type/static/static.d.mts +1 -1
- package/build/esm/type/type/json.d.mts +4 -17
- package/build/esm/type/type/json.mjs +7 -23
- package/build/esm/type/type/type.d.mts +1 -2
- package/build/esm/type/type/type.mjs +1 -2
- package/build/esm/value/cast/cast.mjs +9 -2
- package/build/esm/value/check/check.mjs +9 -2
- package/build/esm/value/clean/clean.mjs +9 -2
- package/build/esm/value/convert/convert.mjs +7 -0
- package/build/esm/value/create/create.mjs +7 -0
- package/build/esm/value/default/default.mjs +7 -0
- package/build/esm/value/transform/decode.mjs +11 -0
- package/build/esm/value/transform/encode.mjs +11 -0
- package/package.json +1 -1
- package/readme.md +219 -97
- package/build/cjs/type/deref/deref.d.ts +0 -22
- package/build/cjs/type/deref/deref.js +0 -106
- package/build/cjs/type/deref/index.d.ts +0 -1
- package/build/cjs/type/deref/index.js +0 -18
- package/build/cjs/type/strict/index.d.ts +0 -1
- package/build/cjs/type/strict/strict.d.ts +0 -12
- package/build/cjs/type/strict/strict.js +0 -16
- package/build/esm/type/deref/deref.d.mts +0 -22
- package/build/esm/type/deref/deref.mjs +0 -102
- package/build/esm/type/deref/index.d.mts +0 -1
- package/build/esm/type/deref/index.mjs +0 -1
- package/build/esm/type/strict/index.d.mts +0 -1
- package/build/esm/type/strict/index.mjs +0 -1
- package/build/esm/type/strict/strict.d.mts +0 -12
- package/build/esm/type/strict/strict.mjs +0 -12
|
@@ -7,21 +7,21 @@ const index_2 = require("../array/index");
|
|
|
7
7
|
const index_3 = require("../boolean/index");
|
|
8
8
|
const index_4 = require("../composite/index");
|
|
9
9
|
const index_5 = require("../const/index");
|
|
10
|
-
const index_6 = require("../
|
|
11
|
-
const index_7 = require("../
|
|
12
|
-
const index_8 = require("../
|
|
13
|
-
const index_9 = require("../
|
|
14
|
-
const index_10 = require("../
|
|
15
|
-
const index_11 = require("../
|
|
16
|
-
const index_12 = require("../
|
|
17
|
-
const index_13 = require("../
|
|
18
|
-
const index_14 = require("../
|
|
19
|
-
const index_15 = require("../
|
|
20
|
-
const index_16 = require("../
|
|
21
|
-
const index_17 = require("../
|
|
22
|
-
const index_18 = require("../
|
|
23
|
-
const index_19 = require("../
|
|
24
|
-
const index_20 = require("../
|
|
10
|
+
const index_6 = require("../enum/index");
|
|
11
|
+
const index_7 = require("../exclude/index");
|
|
12
|
+
const index_8 = require("../extends/index");
|
|
13
|
+
const index_9 = require("../extract/index");
|
|
14
|
+
const index_10 = require("../indexed/index");
|
|
15
|
+
const index_11 = require("../integer/index");
|
|
16
|
+
const index_12 = require("../intersect/index");
|
|
17
|
+
const index_13 = require("../intrinsic/index");
|
|
18
|
+
const index_14 = require("../keyof/index");
|
|
19
|
+
const index_15 = require("../literal/index");
|
|
20
|
+
const index_16 = require("../mapped/index");
|
|
21
|
+
const index_17 = require("../never/index");
|
|
22
|
+
const index_18 = require("../not/index");
|
|
23
|
+
const index_19 = require("../null/index");
|
|
24
|
+
const index_20 = require("../module/index");
|
|
25
25
|
const index_21 = require("../number/index");
|
|
26
26
|
const index_22 = require("../object/index");
|
|
27
27
|
const index_23 = require("../omit/index");
|
|
@@ -35,31 +35,15 @@ const index_30 = require("../recursive/index");
|
|
|
35
35
|
const index_31 = require("../ref/index");
|
|
36
36
|
const index_32 = require("../required/index");
|
|
37
37
|
const index_33 = require("../rest/index");
|
|
38
|
-
const index_34 = require("../
|
|
39
|
-
const index_35 = require("../
|
|
40
|
-
const index_36 = require("../
|
|
41
|
-
const index_37 = require("../
|
|
42
|
-
const index_38 = require("../
|
|
43
|
-
const index_39 = require("../
|
|
44
|
-
const index_40 = require("../
|
|
45
|
-
const index_41 = require("../unsafe/index");
|
|
38
|
+
const index_34 = require("../string/index");
|
|
39
|
+
const index_35 = require("../template-literal/index");
|
|
40
|
+
const index_36 = require("../transform/index");
|
|
41
|
+
const index_37 = require("../tuple/index");
|
|
42
|
+
const index_38 = require("../union/index");
|
|
43
|
+
const index_39 = require("../unknown/index");
|
|
44
|
+
const index_40 = require("../unsafe/index");
|
|
46
45
|
/** Json Type Builder with Static Resolution for TypeScript */
|
|
47
46
|
class JsonTypeBuilder {
|
|
48
|
-
// ------------------------------------------------------------------------
|
|
49
|
-
// Strict
|
|
50
|
-
// ------------------------------------------------------------------------
|
|
51
|
-
/**
|
|
52
|
-
* @deprecated `[Json]` Omits compositing symbols from this schema. It is recommended
|
|
53
|
-
* to use the JSON parse/stringify to remove compositing symbols if needed. This
|
|
54
|
-
* is how Strict works internally.
|
|
55
|
-
*
|
|
56
|
-
* ```typescript
|
|
57
|
-
* JSON.parse(JSON.stringify(Type.String()))
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
Strict(schema) {
|
|
61
|
-
return (0, index_34.Strict)(schema);
|
|
62
|
-
}
|
|
63
47
|
// ------------------------------------------------------------------------
|
|
64
48
|
// Modifiers
|
|
65
49
|
// ------------------------------------------------------------------------
|
|
@@ -92,7 +76,7 @@ class JsonTypeBuilder {
|
|
|
92
76
|
}
|
|
93
77
|
/** `[Json]` Intrinsic function to Capitalize LiteralString types */
|
|
94
78
|
Capitalize(schema, options) {
|
|
95
|
-
return (0,
|
|
79
|
+
return (0, index_13.Capitalize)(schema, options);
|
|
96
80
|
}
|
|
97
81
|
/** `[Json]` Creates a Composite object type */
|
|
98
82
|
Composite(schemas, options) {
|
|
@@ -102,65 +86,65 @@ class JsonTypeBuilder {
|
|
|
102
86
|
Const(value, options) {
|
|
103
87
|
return (0, index_5.Const)(value, options);
|
|
104
88
|
}
|
|
105
|
-
/** `[Json]` Creates a dereferenced type */
|
|
106
|
-
Deref(schema, references) {
|
|
107
|
-
return (0, index_6.Deref)(schema, references);
|
|
108
|
-
}
|
|
109
89
|
/** `[Json]` Creates a Enum type */
|
|
110
90
|
Enum(item, options) {
|
|
111
|
-
return (0,
|
|
91
|
+
return (0, index_6.Enum)(item, options);
|
|
112
92
|
}
|
|
113
93
|
/** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
|
|
114
94
|
Exclude(unionType, excludedMembers, options) {
|
|
115
|
-
return (0,
|
|
95
|
+
return (0, index_7.Exclude)(unionType, excludedMembers, options);
|
|
116
96
|
}
|
|
117
97
|
/** `[Json]` Creates a Conditional type */
|
|
118
98
|
Extends(L, R, T, F, options) {
|
|
119
|
-
return (0,
|
|
99
|
+
return (0, index_8.Extends)(L, R, T, F, options);
|
|
120
100
|
}
|
|
121
101
|
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
122
102
|
Extract(type, union, options) {
|
|
123
|
-
return (0,
|
|
103
|
+
return (0, index_9.Extract)(type, union, options);
|
|
124
104
|
}
|
|
125
105
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
126
106
|
Index(schema, unresolved, options) {
|
|
127
|
-
return (0,
|
|
107
|
+
return (0, index_10.Index)(schema, unresolved, options);
|
|
128
108
|
}
|
|
129
109
|
/** `[Json]` Creates an Integer type */
|
|
130
110
|
Integer(options) {
|
|
131
|
-
return (0,
|
|
111
|
+
return (0, index_11.Integer)(options);
|
|
132
112
|
}
|
|
133
113
|
/** `[Json]` Creates an Intersect type */
|
|
134
114
|
Intersect(T, options) {
|
|
135
|
-
return (0,
|
|
115
|
+
return (0, index_12.Intersect)(T, options);
|
|
136
116
|
}
|
|
137
117
|
/** `[Json]` Creates a KeyOf type */
|
|
138
118
|
KeyOf(schema, options) {
|
|
139
|
-
return (0,
|
|
119
|
+
return (0, index_14.KeyOf)(schema, options);
|
|
140
120
|
}
|
|
141
121
|
/** `[Json]` Creates a Literal type */
|
|
142
122
|
Literal(value, options) {
|
|
143
|
-
return (0,
|
|
123
|
+
return (0, index_15.Literal)(value, options);
|
|
144
124
|
}
|
|
145
125
|
/** `[Json]` Intrinsic function to Lowercase LiteralString types */
|
|
146
126
|
Lowercase(schema, options) {
|
|
147
|
-
return (0,
|
|
127
|
+
return (0, index_13.Lowercase)(schema, options);
|
|
148
128
|
}
|
|
149
129
|
/** `[Json]` Creates a Mapped object type */
|
|
150
130
|
Mapped(key, map, options) {
|
|
151
|
-
return (0,
|
|
131
|
+
return (0, index_16.Mapped)(key, map, options);
|
|
132
|
+
}
|
|
133
|
+
/** `[Json]` Creates a Type Definition Module. */
|
|
134
|
+
Module(properties) {
|
|
135
|
+
return (0, index_20.Module)(properties);
|
|
152
136
|
}
|
|
153
137
|
/** `[Json]` Creates a Never type */
|
|
154
138
|
Never(options) {
|
|
155
|
-
return (0,
|
|
139
|
+
return (0, index_17.Never)(options);
|
|
156
140
|
}
|
|
157
141
|
/** `[Json]` Creates a Not type */
|
|
158
142
|
Not(schema, options) {
|
|
159
|
-
return (0,
|
|
143
|
+
return (0, index_18.Not)(schema, options);
|
|
160
144
|
}
|
|
161
145
|
/** `[Json]` Creates a Null type */
|
|
162
146
|
Null(options) {
|
|
163
|
-
return (0,
|
|
147
|
+
return (0, index_19.Null)(options);
|
|
164
148
|
}
|
|
165
149
|
/** `[Json]` Creates a Number type */
|
|
166
150
|
Number(options) {
|
|
@@ -191,8 +175,8 @@ class JsonTypeBuilder {
|
|
|
191
175
|
return (0, index_30.Recursive)(callback, options);
|
|
192
176
|
}
|
|
193
177
|
/** `[Json]` Creates a Ref type. */
|
|
194
|
-
Ref(
|
|
195
|
-
return (0, index_31.Ref)(
|
|
178
|
+
Ref($ref, options) {
|
|
179
|
+
return (0, index_31.Ref)($ref, options);
|
|
196
180
|
}
|
|
197
181
|
/** `[Json]` Constructs a type where all properties are required */
|
|
198
182
|
Required(schema, options) {
|
|
@@ -204,39 +188,39 @@ class JsonTypeBuilder {
|
|
|
204
188
|
}
|
|
205
189
|
/** `[Json]` Creates a String type */
|
|
206
190
|
String(options) {
|
|
207
|
-
return (0,
|
|
191
|
+
return (0, index_34.String)(options);
|
|
208
192
|
}
|
|
209
193
|
/** `[Json]` Creates a TemplateLiteral type */
|
|
210
194
|
TemplateLiteral(unresolved, options) {
|
|
211
|
-
return (0,
|
|
195
|
+
return (0, index_35.TemplateLiteral)(unresolved, options);
|
|
212
196
|
}
|
|
213
197
|
/** `[Json]` Creates a Transform type */
|
|
214
198
|
Transform(schema) {
|
|
215
|
-
return (0,
|
|
199
|
+
return (0, index_36.Transform)(schema);
|
|
216
200
|
}
|
|
217
201
|
/** `[Json]` Creates a Tuple type */
|
|
218
202
|
Tuple(items, options) {
|
|
219
|
-
return (0,
|
|
203
|
+
return (0, index_37.Tuple)(items, options);
|
|
220
204
|
}
|
|
221
205
|
/** `[Json]` Intrinsic function to Uncapitalize LiteralString types */
|
|
222
206
|
Uncapitalize(schema, options) {
|
|
223
|
-
return (0,
|
|
207
|
+
return (0, index_13.Uncapitalize)(schema, options);
|
|
224
208
|
}
|
|
225
209
|
/** `[Json]` Creates a Union type */
|
|
226
210
|
Union(schemas, options) {
|
|
227
|
-
return (0,
|
|
211
|
+
return (0, index_38.Union)(schemas, options);
|
|
228
212
|
}
|
|
229
213
|
/** `[Json]` Creates an Unknown type */
|
|
230
214
|
Unknown(options) {
|
|
231
|
-
return (0,
|
|
215
|
+
return (0, index_39.Unknown)(options);
|
|
232
216
|
}
|
|
233
217
|
/** `[Json]` Creates a Unsafe type that will infers as the generic argument T */
|
|
234
218
|
Unsafe(options) {
|
|
235
|
-
return (0,
|
|
219
|
+
return (0, index_40.Unsafe)(options);
|
|
236
220
|
}
|
|
237
221
|
/** `[Json]` Intrinsic function to Uppercase LiteralString types */
|
|
238
222
|
Uppercase(schema, options) {
|
|
239
|
-
return (0,
|
|
223
|
+
return (0, index_13.Uppercase)(schema, options);
|
|
240
224
|
}
|
|
241
225
|
}
|
|
242
226
|
exports.JsonTypeBuilder = JsonTypeBuilder;
|
|
@@ -9,7 +9,6 @@ export { Const } from '../const/index';
|
|
|
9
9
|
export { Constructor } from '../constructor/index';
|
|
10
10
|
export { ConstructorParameters } from '../constructor-parameters/index';
|
|
11
11
|
export { Date } from '../date/index';
|
|
12
|
-
export { Deref } from '../deref/index';
|
|
13
12
|
export { Enum } from '../enum/index';
|
|
14
13
|
export { Exclude } from '../exclude/index';
|
|
15
14
|
export { Extends } from '../extends/index';
|
|
@@ -24,6 +23,7 @@ export { Iterator } from '../iterator/index';
|
|
|
24
23
|
export { KeyOf } from '../keyof/index';
|
|
25
24
|
export { Literal } from '../literal/index';
|
|
26
25
|
export { Mapped } from '../mapped/index';
|
|
26
|
+
export { Module } from '../module/index';
|
|
27
27
|
export { Never } from '../never/index';
|
|
28
28
|
export { Not } from '../not/index';
|
|
29
29
|
export { Null } from '../null/index';
|
|
@@ -45,7 +45,6 @@ export { Required } from '../required/index';
|
|
|
45
45
|
export { Rest } from '../rest/index';
|
|
46
46
|
export { ReturnType } from '../return-type/index';
|
|
47
47
|
export { String } from '../string/index';
|
|
48
|
-
export { Strict } from '../strict/index';
|
|
49
48
|
export { Symbol } from '../symbol/index';
|
|
50
49
|
export { TemplateLiteral } from '../template-literal/index';
|
|
51
50
|
export { Transform } from '../transform/index';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.String = exports.ReturnType = exports.Rest = exports.Required = exports.RegExp = exports.Ref = exports.Recursive = exports.Record = exports.ReadonlyOptional = exports.Readonly = exports.Promise = exports.Pick = exports.Partial = exports.Parameters = exports.Optional = exports.Omit = exports.Object = exports.Number = exports.Null = exports.Not = exports.Never = exports.Mapped = exports.Literal = exports.KeyOf = exports.Iterator = exports.Uppercase = exports.Lowercase = exports.Uncapitalize = exports.Capitalize = exports.Intersect = exports.Integer = exports.InstanceType = exports.Index = exports.Function = exports.Extract = exports.Extends = exports.Exclude = exports.Enum = exports.
|
|
5
|
-
exports.Void = exports.Unsafe = exports.Unknown = exports.Union = exports.Undefined = exports.Uint8Array = exports.Tuple = exports.Transform = exports.TemplateLiteral = exports.Symbol =
|
|
4
|
+
exports.String = exports.ReturnType = exports.Rest = exports.Required = exports.RegExp = exports.Ref = exports.Recursive = exports.Record = exports.ReadonlyOptional = exports.Readonly = exports.Promise = exports.Pick = exports.Partial = exports.Parameters = exports.Optional = exports.Omit = exports.Object = exports.Number = exports.Null = exports.Not = exports.Never = exports.Module = exports.Mapped = exports.Literal = exports.KeyOf = exports.Iterator = exports.Uppercase = exports.Lowercase = exports.Uncapitalize = exports.Capitalize = exports.Intersect = exports.Integer = exports.InstanceType = exports.Index = exports.Function = exports.Extract = exports.Extends = exports.Exclude = exports.Enum = exports.Date = exports.ConstructorParameters = exports.Constructor = exports.Const = exports.Composite = exports.Boolean = exports.BigInt = exports.Awaited = exports.AsyncIterator = exports.Array = exports.Any = void 0;
|
|
5
|
+
exports.Void = exports.Unsafe = exports.Unknown = exports.Union = exports.Undefined = exports.Uint8Array = exports.Tuple = exports.Transform = exports.TemplateLiteral = exports.Symbol = void 0;
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
7
|
// Type: Module
|
|
8
8
|
// ------------------------------------------------------------------
|
|
@@ -28,39 +28,39 @@ var index_10 = require("../constructor-parameters/index");
|
|
|
28
28
|
Object.defineProperty(exports, "ConstructorParameters", { enumerable: true, get: function () { return index_10.ConstructorParameters; } });
|
|
29
29
|
var index_11 = require("../date/index");
|
|
30
30
|
Object.defineProperty(exports, "Date", { enumerable: true, get: function () { return index_11.Date; } });
|
|
31
|
-
var index_12 = require("../
|
|
32
|
-
Object.defineProperty(exports, "
|
|
33
|
-
var index_13 = require("../
|
|
34
|
-
Object.defineProperty(exports, "
|
|
35
|
-
var index_14 = require("../
|
|
36
|
-
Object.defineProperty(exports, "
|
|
37
|
-
var index_15 = require("../
|
|
38
|
-
Object.defineProperty(exports, "
|
|
39
|
-
var index_16 = require("../
|
|
40
|
-
Object.defineProperty(exports, "
|
|
41
|
-
var index_17 = require("../
|
|
42
|
-
Object.defineProperty(exports, "
|
|
43
|
-
var index_18 = require("../
|
|
44
|
-
Object.defineProperty(exports, "
|
|
45
|
-
var index_19 = require("../
|
|
46
|
-
Object.defineProperty(exports, "
|
|
47
|
-
var index_20 = require("../
|
|
48
|
-
Object.defineProperty(exports, "
|
|
49
|
-
var index_21 = require("../
|
|
50
|
-
Object.defineProperty(exports, "
|
|
51
|
-
|
|
52
|
-
Object.defineProperty(exports, "
|
|
53
|
-
Object.defineProperty(exports, "
|
|
54
|
-
|
|
55
|
-
Object.defineProperty(exports, "
|
|
56
|
-
var index_23 = require("../
|
|
57
|
-
Object.defineProperty(exports, "
|
|
58
|
-
var index_24 = require("../
|
|
59
|
-
Object.defineProperty(exports, "
|
|
60
|
-
var index_25 = require("../
|
|
61
|
-
Object.defineProperty(exports, "
|
|
62
|
-
var index_26 = require("../
|
|
63
|
-
Object.defineProperty(exports, "
|
|
31
|
+
var index_12 = require("../enum/index");
|
|
32
|
+
Object.defineProperty(exports, "Enum", { enumerable: true, get: function () { return index_12.Enum; } });
|
|
33
|
+
var index_13 = require("../exclude/index");
|
|
34
|
+
Object.defineProperty(exports, "Exclude", { enumerable: true, get: function () { return index_13.Exclude; } });
|
|
35
|
+
var index_14 = require("../extends/index");
|
|
36
|
+
Object.defineProperty(exports, "Extends", { enumerable: true, get: function () { return index_14.Extends; } });
|
|
37
|
+
var index_15 = require("../extract/index");
|
|
38
|
+
Object.defineProperty(exports, "Extract", { enumerable: true, get: function () { return index_15.Extract; } });
|
|
39
|
+
var index_16 = require("../function/index");
|
|
40
|
+
Object.defineProperty(exports, "Function", { enumerable: true, get: function () { return index_16.Function; } });
|
|
41
|
+
var index_17 = require("../indexed/index");
|
|
42
|
+
Object.defineProperty(exports, "Index", { enumerable: true, get: function () { return index_17.Index; } });
|
|
43
|
+
var index_18 = require("../instance-type/index");
|
|
44
|
+
Object.defineProperty(exports, "InstanceType", { enumerable: true, get: function () { return index_18.InstanceType; } });
|
|
45
|
+
var index_19 = require("../integer/index");
|
|
46
|
+
Object.defineProperty(exports, "Integer", { enumerable: true, get: function () { return index_19.Integer; } });
|
|
47
|
+
var index_20 = require("../intersect/index");
|
|
48
|
+
Object.defineProperty(exports, "Intersect", { enumerable: true, get: function () { return index_20.Intersect; } });
|
|
49
|
+
var index_21 = require("../intrinsic/index");
|
|
50
|
+
Object.defineProperty(exports, "Capitalize", { enumerable: true, get: function () { return index_21.Capitalize; } });
|
|
51
|
+
Object.defineProperty(exports, "Uncapitalize", { enumerable: true, get: function () { return index_21.Uncapitalize; } });
|
|
52
|
+
Object.defineProperty(exports, "Lowercase", { enumerable: true, get: function () { return index_21.Lowercase; } });
|
|
53
|
+
Object.defineProperty(exports, "Uppercase", { enumerable: true, get: function () { return index_21.Uppercase; } });
|
|
54
|
+
var index_22 = require("../iterator/index");
|
|
55
|
+
Object.defineProperty(exports, "Iterator", { enumerable: true, get: function () { return index_22.Iterator; } });
|
|
56
|
+
var index_23 = require("../keyof/index");
|
|
57
|
+
Object.defineProperty(exports, "KeyOf", { enumerable: true, get: function () { return index_23.KeyOf; } });
|
|
58
|
+
var index_24 = require("../literal/index");
|
|
59
|
+
Object.defineProperty(exports, "Literal", { enumerable: true, get: function () { return index_24.Literal; } });
|
|
60
|
+
var index_25 = require("../mapped/index");
|
|
61
|
+
Object.defineProperty(exports, "Mapped", { enumerable: true, get: function () { return index_25.Mapped; } });
|
|
62
|
+
var index_26 = require("../module/index");
|
|
63
|
+
Object.defineProperty(exports, "Module", { enumerable: true, get: function () { return index_26.Module; } });
|
|
64
64
|
var index_27 = require("../never/index");
|
|
65
65
|
Object.defineProperty(exports, "Never", { enumerable: true, get: function () { return index_27.Never; } });
|
|
66
66
|
var index_28 = require("../not/index");
|
|
@@ -103,25 +103,23 @@ var index_46 = require("../return-type/index");
|
|
|
103
103
|
Object.defineProperty(exports, "ReturnType", { enumerable: true, get: function () { return index_46.ReturnType; } });
|
|
104
104
|
var index_47 = require("../string/index");
|
|
105
105
|
Object.defineProperty(exports, "String", { enumerable: true, get: function () { return index_47.String; } });
|
|
106
|
-
var index_48 = require("../
|
|
107
|
-
Object.defineProperty(exports, "
|
|
108
|
-
var index_49 = require("../
|
|
109
|
-
Object.defineProperty(exports, "
|
|
110
|
-
var index_50 = require("../
|
|
111
|
-
Object.defineProperty(exports, "
|
|
112
|
-
var index_51 = require("../
|
|
113
|
-
Object.defineProperty(exports, "
|
|
114
|
-
var index_52 = require("../
|
|
115
|
-
Object.defineProperty(exports, "
|
|
116
|
-
var index_53 = require("../
|
|
117
|
-
Object.defineProperty(exports, "
|
|
118
|
-
var index_54 = require("../
|
|
119
|
-
Object.defineProperty(exports, "
|
|
120
|
-
var index_55 = require("../
|
|
121
|
-
Object.defineProperty(exports, "
|
|
122
|
-
var index_56 = require("../
|
|
123
|
-
Object.defineProperty(exports, "
|
|
124
|
-
var index_57 = require("../
|
|
125
|
-
Object.defineProperty(exports, "
|
|
126
|
-
var index_58 = require("../void/index");
|
|
127
|
-
Object.defineProperty(exports, "Void", { enumerable: true, get: function () { return index_58.Void; } });
|
|
106
|
+
var index_48 = require("../symbol/index");
|
|
107
|
+
Object.defineProperty(exports, "Symbol", { enumerable: true, get: function () { return index_48.Symbol; } });
|
|
108
|
+
var index_49 = require("../template-literal/index");
|
|
109
|
+
Object.defineProperty(exports, "TemplateLiteral", { enumerable: true, get: function () { return index_49.TemplateLiteral; } });
|
|
110
|
+
var index_50 = require("../transform/index");
|
|
111
|
+
Object.defineProperty(exports, "Transform", { enumerable: true, get: function () { return index_50.Transform; } });
|
|
112
|
+
var index_51 = require("../tuple/index");
|
|
113
|
+
Object.defineProperty(exports, "Tuple", { enumerable: true, get: function () { return index_51.Tuple; } });
|
|
114
|
+
var index_52 = require("../uint8array/index");
|
|
115
|
+
Object.defineProperty(exports, "Uint8Array", { enumerable: true, get: function () { return index_52.Uint8Array; } });
|
|
116
|
+
var index_53 = require("../undefined/index");
|
|
117
|
+
Object.defineProperty(exports, "Undefined", { enumerable: true, get: function () { return index_53.Undefined; } });
|
|
118
|
+
var index_54 = require("../union/index");
|
|
119
|
+
Object.defineProperty(exports, "Union", { enumerable: true, get: function () { return index_54.Union; } });
|
|
120
|
+
var index_55 = require("../unknown/index");
|
|
121
|
+
Object.defineProperty(exports, "Unknown", { enumerable: true, get: function () { return index_55.Unknown; } });
|
|
122
|
+
var index_56 = require("../unsafe/index");
|
|
123
|
+
Object.defineProperty(exports, "Unsafe", { enumerable: true, get: function () { return index_56.Unsafe; } });
|
|
124
|
+
var index_57 = require("../void/index");
|
|
125
|
+
Object.defineProperty(exports, "Void", { enumerable: true, get: function () { return index_57.Void; } });
|
|
@@ -104,6 +104,11 @@ function FromConstructor(schema, references, value) {
|
|
|
104
104
|
}
|
|
105
105
|
return result;
|
|
106
106
|
}
|
|
107
|
+
function FromImport(schema, references, value) {
|
|
108
|
+
const definitions = globalThis.Object.values(schema.$defs);
|
|
109
|
+
const target = schema.$defs[schema.$ref];
|
|
110
|
+
return Visit(target, [...references, ...definitions], value);
|
|
111
|
+
}
|
|
107
112
|
function FromIntersect(schema, references, value) {
|
|
108
113
|
const created = (0, index_4.Create)(schema, references);
|
|
109
114
|
const mapped = (0, index_1.IsObject)(created) && (0, index_1.IsObject)(value) ? { ...created, ...value } : value;
|
|
@@ -167,7 +172,7 @@ function FromUnion(schema, references, value) {
|
|
|
167
172
|
return (0, index_5.Check)(schema, references, value) ? (0, index_6.Clone)(value) : CastUnion(schema, references, value);
|
|
168
173
|
}
|
|
169
174
|
function Visit(schema, references, value) {
|
|
170
|
-
const references_ = (0, index_1.IsString)(schema.$id) ?
|
|
175
|
+
const references_ = (0, index_1.IsString)(schema.$id) ? (0, index_7.Pushref)(schema, references) : references;
|
|
171
176
|
const schema_ = schema;
|
|
172
177
|
switch (schema[index_3.Kind]) {
|
|
173
178
|
// --------------------------------------------------------------
|
|
@@ -177,6 +182,8 @@ function Visit(schema, references, value) {
|
|
|
177
182
|
return FromArray(schema_, references_, value);
|
|
178
183
|
case 'Constructor':
|
|
179
184
|
return FromConstructor(schema_, references_, value);
|
|
185
|
+
case 'Import':
|
|
186
|
+
return FromImport(schema_, references_, value);
|
|
180
187
|
case 'Intersect':
|
|
181
188
|
return FromIntersect(schema_, references_, value);
|
|
182
189
|
case 'Never':
|
|
@@ -141,6 +141,11 @@ function FromDate(schema, references, value) {
|
|
|
141
141
|
function FromFunction(schema, references, value) {
|
|
142
142
|
return (0, index_10.IsFunction)(value);
|
|
143
143
|
}
|
|
144
|
+
function FromImport(schema, references, value) {
|
|
145
|
+
const definitions = globalThis.Object.values(schema.$defs);
|
|
146
|
+
const target = schema.$defs[schema.$ref];
|
|
147
|
+
return Visit(target, [...references, ...definitions], value);
|
|
148
|
+
}
|
|
144
149
|
function FromInteger(schema, references, value) {
|
|
145
150
|
if (!(0, index_10.IsInteger)(value)) {
|
|
146
151
|
return false;
|
|
@@ -386,7 +391,7 @@ function FromKind(schema, references, value) {
|
|
|
386
391
|
return func(schema, value);
|
|
387
392
|
}
|
|
388
393
|
function Visit(schema, references, value) {
|
|
389
|
-
const references_ = IsDefined(schema.$id) ?
|
|
394
|
+
const references_ = IsDefined(schema.$id) ? (0, index_2.Pushref)(schema, references) : references;
|
|
390
395
|
const schema_ = schema;
|
|
391
396
|
switch (schema_[index_4.Kind]) {
|
|
392
397
|
case 'Any':
|
|
@@ -405,6 +410,8 @@ function Visit(schema, references, value) {
|
|
|
405
410
|
return FromDate(schema_, references_, value);
|
|
406
411
|
case 'Function':
|
|
407
412
|
return FromFunction(schema_, references_, value);
|
|
413
|
+
case 'Import':
|
|
414
|
+
return FromImport(schema_, references_, value);
|
|
408
415
|
case 'Integer':
|
|
409
416
|
return FromInteger(schema_, references_, value);
|
|
410
417
|
case 'Intersect':
|
|
@@ -31,6 +31,11 @@ function FromArray(schema, references, value) {
|
|
|
31
31
|
return value;
|
|
32
32
|
return value.map((value) => Visit(schema.items, references, value));
|
|
33
33
|
}
|
|
34
|
+
function FromImport(schema, references, value) {
|
|
35
|
+
const definitions = globalThis.Object.values(schema.$defs);
|
|
36
|
+
const target = schema.$defs[schema.$ref];
|
|
37
|
+
return Visit(target, [...references, ...definitions], value);
|
|
38
|
+
}
|
|
34
39
|
function FromIntersect(schema, references, value) {
|
|
35
40
|
const unevaluatedProperties = schema.unevaluatedProperties;
|
|
36
41
|
const intersections = schema.allOf.map((schema) => Visit(schema, references, (0, index_3.Clone)(value)));
|
|
@@ -113,11 +118,13 @@ function FromUnion(schema, references, value) {
|
|
|
113
118
|
return value;
|
|
114
119
|
}
|
|
115
120
|
function Visit(schema, references, value) {
|
|
116
|
-
const references_ = (0, index_6.IsString)(schema.$id) ?
|
|
121
|
+
const references_ = (0, index_6.IsString)(schema.$id) ? (0, index_4.Pushref)(schema, references) : references;
|
|
117
122
|
const schema_ = schema;
|
|
118
123
|
switch (schema_[index_5.Kind]) {
|
|
119
124
|
case 'Array':
|
|
120
125
|
return FromArray(schema_, references_, value);
|
|
126
|
+
case 'Import':
|
|
127
|
+
return FromImport(schema_, references_, value);
|
|
121
128
|
case 'Intersect':
|
|
122
129
|
return FromIntersect(schema_, references_, value);
|
|
123
130
|
case 'Object':
|
|
@@ -127,6 +127,11 @@ function FromBoolean(schema, references, value) {
|
|
|
127
127
|
function FromDate(schema, references, value) {
|
|
128
128
|
return TryConvertDate(value);
|
|
129
129
|
}
|
|
130
|
+
function FromImport(schema, references, value) {
|
|
131
|
+
const definitions = globalThis.Object.values(schema.$defs);
|
|
132
|
+
const target = schema.$defs[schema.$ref];
|
|
133
|
+
return Visit(target, [...references, ...definitions], value);
|
|
134
|
+
}
|
|
130
135
|
function FromInteger(schema, references, value) {
|
|
131
136
|
return TryConvertInteger(value);
|
|
132
137
|
}
|
|
@@ -211,6 +216,8 @@ function Visit(schema, references, value) {
|
|
|
211
216
|
return FromBoolean(schema_, references_, value);
|
|
212
217
|
case 'Date':
|
|
213
218
|
return FromDate(schema_, references_, value);
|
|
219
|
+
case 'Import':
|
|
220
|
+
return FromImport(schema_, references_, value);
|
|
214
221
|
case 'Integer':
|
|
215
222
|
return FromInteger(schema_, references_, value);
|
|
216
223
|
case 'Intersect':
|
|
@@ -124,6 +124,11 @@ function FromFunction(schema, references) {
|
|
|
124
124
|
return () => Visit(schema.returns, references);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
+
function FromImport(schema, references) {
|
|
128
|
+
const definitions = globalThis.Object.values(schema.$defs);
|
|
129
|
+
const target = schema.$defs[schema.$ref];
|
|
130
|
+
return Visit(target, [...references, ...definitions]);
|
|
131
|
+
}
|
|
127
132
|
function FromInteger(schema, references) {
|
|
128
133
|
if ((0, index_1.HasPropertyKey)(schema, 'default')) {
|
|
129
134
|
return FromDefault(schema.default);
|
|
@@ -407,6 +412,8 @@ function Visit(schema, references) {
|
|
|
407
412
|
return FromDate(schema_, references_);
|
|
408
413
|
case 'Function':
|
|
409
414
|
return FromFunction(schema_, references_);
|
|
415
|
+
case 'Import':
|
|
416
|
+
return FromImport(schema_, references_);
|
|
410
417
|
case 'Integer':
|
|
411
418
|
return FromInteger(schema_, references_);
|
|
412
419
|
case 'Intersect':
|
|
@@ -44,6 +44,11 @@ function FromDate(schema, references, value) {
|
|
|
44
44
|
// special case intercept for dates
|
|
45
45
|
return (0, index_5.IsDate)(value) ? value : ValueOrDefault(schema, value);
|
|
46
46
|
}
|
|
47
|
+
function FromImport(schema, references, value) {
|
|
48
|
+
const definitions = globalThis.Object.values(schema.$defs);
|
|
49
|
+
const target = schema.$defs[schema.$ref];
|
|
50
|
+
return Visit(target, [...references, ...definitions], value);
|
|
51
|
+
}
|
|
47
52
|
function FromIntersect(schema, references, value) {
|
|
48
53
|
const defaulted = ValueOrDefault(schema, value);
|
|
49
54
|
return schema.allOf.reduce((acc, schema) => {
|
|
@@ -137,6 +142,8 @@ function Visit(schema, references, value) {
|
|
|
137
142
|
return FromArray(schema_, references_, value);
|
|
138
143
|
case 'Date':
|
|
139
144
|
return FromDate(schema_, references_, value);
|
|
145
|
+
case 'Import':
|
|
146
|
+
return FromImport(schema_, references_, value);
|
|
140
147
|
case 'Intersect':
|
|
141
148
|
return FromIntersect(schema_, references_, value);
|
|
142
149
|
case 'Object':
|
|
@@ -83,6 +83,15 @@ function FromIntersect(schema, references, path, value) {
|
|
|
83
83
|
}
|
|
84
84
|
return Default(schema, path, unknownProperties);
|
|
85
85
|
}
|
|
86
|
+
// prettier-ignore
|
|
87
|
+
function FromImport(schema, references, path, value) {
|
|
88
|
+
const definitions = globalThis.Object.values(schema.$defs);
|
|
89
|
+
const target = schema.$defs[schema.$ref];
|
|
90
|
+
const transform = schema[index_1.TransformKind];
|
|
91
|
+
// Note: we need to re-spec the target as TSchema + [TransformKind]
|
|
92
|
+
const transformTarget = { [index_1.TransformKind]: transform, ...target };
|
|
93
|
+
return Visit(transformTarget, [...references, ...definitions], path, value);
|
|
94
|
+
}
|
|
86
95
|
function FromNot(schema, references, path, value) {
|
|
87
96
|
return Default(schema, path, Visit(schema.not, references, path, value));
|
|
88
97
|
}
|
|
@@ -173,6 +182,8 @@ function Visit(schema, references, path, value) {
|
|
|
173
182
|
switch (schema[index_1.Kind]) {
|
|
174
183
|
case 'Array':
|
|
175
184
|
return FromArray(schema_, references_, path, value);
|
|
185
|
+
case 'Import':
|
|
186
|
+
return FromImport(schema_, references_, path, value);
|
|
176
187
|
case 'Intersect':
|
|
177
188
|
return FromIntersect(schema_, references_, path, value);
|
|
178
189
|
case 'Not':
|
|
@@ -61,6 +61,15 @@ function FromArray(schema, references, path, value) {
|
|
|
61
61
|
: defaulted;
|
|
62
62
|
}
|
|
63
63
|
// prettier-ignore
|
|
64
|
+
function FromImport(schema, references, path, value) {
|
|
65
|
+
const definitions = globalThis.Object.values(schema.$defs);
|
|
66
|
+
const target = schema.$defs[schema.$ref];
|
|
67
|
+
const transform = schema[index_1.TransformKind];
|
|
68
|
+
// Note: we need to re-spec the target as TSchema + [TransformKind]
|
|
69
|
+
const transformTarget = { [index_1.TransformKind]: transform, ...target };
|
|
70
|
+
return Visit(transformTarget, [...references, ...definitions], path, value);
|
|
71
|
+
}
|
|
72
|
+
// prettier-ignore
|
|
64
73
|
function FromIntersect(schema, references, path, value) {
|
|
65
74
|
const defaulted = Default(schema, path, value);
|
|
66
75
|
if (!(0, index_6.IsObject)(value) || (0, index_6.IsValueType)(value))
|
|
@@ -185,6 +194,8 @@ function Visit(schema, references, path, value) {
|
|
|
185
194
|
switch (schema[index_1.Kind]) {
|
|
186
195
|
case 'Array':
|
|
187
196
|
return FromArray(schema_, references_, path, value);
|
|
197
|
+
case 'Import':
|
|
198
|
+
return FromImport(schema_, references_, path, value);
|
|
188
199
|
case 'Intersect':
|
|
189
200
|
return FromIntersect(schema_, references_, path, value);
|
|
190
201
|
case 'Not':
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ValueErrorIterator } from '../errors/index.mjs';
|
|
2
2
|
import { TypeBoxError } from '../type/error/index.mjs';
|
|
3
3
|
import type { TSchema } from '../type/schema/index.mjs';
|
|
4
|
-
import type { Static, StaticDecode } from '../type/static/index.mjs';
|
|
4
|
+
import type { Static, StaticDecode, StaticEncode } from '../type/static/index.mjs';
|
|
5
5
|
export type CheckFunction = (value: unknown) => boolean;
|
|
6
6
|
export declare class TypeCheck<T extends TSchema> {
|
|
7
7
|
private readonly schema;
|
|
@@ -19,7 +19,7 @@ export declare class TypeCheck<T extends TSchema> {
|
|
|
19
19
|
/** Decodes a value or throws if error */
|
|
20
20
|
Decode<Static = StaticDecode<T>, Result extends Static = Static>(value: unknown): Result;
|
|
21
21
|
/** Encodes a value or throws if error */
|
|
22
|
-
Encode<Static =
|
|
22
|
+
Encode<Static = StaticEncode<T>, Result extends Static = Static>(value: unknown): Result;
|
|
23
23
|
}
|
|
24
24
|
export declare class TypeCompilerUnknownTypeError extends TypeBoxError {
|
|
25
25
|
readonly schema: TSchema;
|