@sinclair/typebox 0.32.0-dev-18 → 0.32.0-dev-19
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/import/compiler/compiler.mjs +14 -8
- package/build/import/errors/errors.mjs +15 -11
- package/build/import/type/awaited/awaited.mjs +4 -4
- package/build/import/type/deref/deref.mjs +12 -12
- package/build/import/type/exclude/exclude.mjs +8 -5
- package/build/import/type/extends/extends-check.mjs +167 -167
- package/build/import/type/extends/extends.mjs +3 -3
- package/build/import/type/extract/extract.mjs +5 -5
- package/build/import/type/guard/type.d.mts +50 -50
- package/build/import/type/guard/type.mjs +136 -136
- package/build/import/type/indexed/indexed-property-keys.mjs +7 -7
- package/build/import/type/indexed/indexed.mjs +9 -9
- package/build/import/type/intersect/intersect-create.mjs +4 -4
- package/build/import/type/intersect/intersect-evaluated.mjs +1 -1
- package/build/import/type/intersect/intersect.mjs +2 -2
- package/build/import/type/intrinsic/intrinsic.mjs +5 -5
- package/build/import/type/keyof/keyof-property-keys.mjs +7 -7
- package/build/import/type/keyof/keyof.mjs +2 -2
- package/build/import/type/mapped/mapped.mjs +16 -16
- package/build/import/type/modifiers/modifiers.mjs +3 -3
- package/build/import/type/object/object.mjs +3 -3
- package/build/import/type/omit/omit.mjs +6 -6
- package/build/import/type/partial/partial.mjs +5 -5
- package/build/import/type/pick/pick.mjs +6 -6
- package/build/import/type/record/record.mjs +7 -7
- package/build/import/type/required/required.mjs +5 -5
- package/build/import/type/rest/rest.mjs +6 -2
- package/build/import/type/template-literal/pattern.mjs +9 -9
- package/build/import/type/transform/transform.mjs +1 -1
- package/build/import/type/union/union-evaluated.mjs +2 -2
- package/build/import/value/check/check.mjs +18 -11
- package/build/import/value/clean/clean.mjs +9 -7
- package/build/import/value/clone/clone.mjs +7 -4
- package/build/import/value/convert/convert.mjs +6 -2
- package/build/import/value/default/default.mjs +12 -4
- package/build/import/value/transform/decode.mjs +12 -6
- package/build/import/value/transform/encode.mjs +12 -6
- package/build/import/value/transform/has.mjs +24 -18
- package/build/require/compiler/compiler.js +77 -71
- package/build/require/errors/errors.js +58 -54
- package/build/require/type/awaited/awaited.js +3 -3
- package/build/require/type/deref/deref.js +11 -11
- package/build/require/type/exclude/exclude.js +7 -4
- package/build/require/type/extends/extends-check.js +167 -167
- package/build/require/type/extends/extends.js +2 -2
- package/build/require/type/extract/extract.js +4 -4
- package/build/require/type/guard/type.d.ts +50 -50
- package/build/require/type/guard/type.js +184 -184
- package/build/require/type/indexed/indexed-property-keys.js +6 -6
- package/build/require/type/indexed/indexed.js +9 -9
- package/build/require/type/intersect/intersect-create.js +3 -3
- package/build/require/type/intersect/intersect-evaluated.js +2 -2
- package/build/require/type/intersect/intersect.js +1 -1
- package/build/require/type/intrinsic/intrinsic.js +4 -4
- package/build/require/type/keyof/keyof-property-keys.js +6 -6
- package/build/require/type/keyof/keyof.js +1 -1
- package/build/require/type/mapped/mapped.js +15 -15
- package/build/require/type/modifiers/modifiers.js +2 -2
- package/build/require/type/object/object.js +2 -2
- package/build/require/type/omit/omit.js +5 -5
- package/build/require/type/partial/partial.js +4 -4
- package/build/require/type/pick/pick.js +5 -5
- package/build/require/type/record/record.js +6 -6
- package/build/require/type/required/required.js +4 -4
- package/build/require/type/rest/rest.js +5 -1
- package/build/require/type/template-literal/pattern.js +8 -8
- package/build/require/type/transform/transform.js +1 -1
- package/build/require/type/union/union-evaluated.js +1 -1
- package/build/require/value/check/check.js +63 -56
- package/build/require/value/clean/clean.js +31 -29
- package/build/require/value/clone/clone.js +7 -4
- package/build/require/value/convert/convert.js +42 -38
- package/build/require/value/default/default.js +24 -16
- package/build/require/value/transform/decode.js +27 -21
- package/build/require/value/transform/encode.js +28 -22
- package/build/require/value/transform/has.js +29 -23
- package/package.json +1 -1
- package/readme.md +5 -5
|
@@ -2,19 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Errors = exports.ValueErrorIterator = exports.ValueErrorsUnknownTypeError = exports.ValueErrorType = void 0;
|
|
5
|
-
const index_1 = require("../
|
|
6
|
-
const index_2 = require("../
|
|
7
|
-
const index_3 = require("../type/
|
|
8
|
-
const index_4 = require("../type/registry/index");
|
|
5
|
+
const index_1 = require("../system/index");
|
|
6
|
+
const index_2 = require("../type/keyof/index");
|
|
7
|
+
const index_3 = require("../type/registry/index");
|
|
9
8
|
const extends_undefined_1 = require("../type/extends/extends-undefined");
|
|
10
9
|
const function_1 = require("./function");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
//
|
|
10
|
+
const index_4 = require("../value/deref/index");
|
|
11
|
+
const index_5 = require("../value/hash/index");
|
|
12
|
+
const index_6 = require("../type/symbols/index");
|
|
13
|
+
const index_7 = require("../type/never/index");
|
|
14
|
+
// ------------------------------------------------------------------
|
|
15
|
+
// ValueGuard
|
|
16
|
+
// ------------------------------------------------------------------
|
|
17
|
+
// prettier-ignore
|
|
18
|
+
const index_8 = require("../value/guard/index");
|
|
19
|
+
// ------------------------------------------------------------------
|
|
16
20
|
// ValueErrorType
|
|
17
|
-
//
|
|
21
|
+
// ------------------------------------------------------------------
|
|
18
22
|
var ValueErrorType;
|
|
19
23
|
(function (ValueErrorType) {
|
|
20
24
|
ValueErrorType[ValueErrorType["ArrayContains"] = 0] = "ArrayContains";
|
|
@@ -81,9 +85,9 @@ var ValueErrorType;
|
|
|
81
85
|
ValueErrorType[ValueErrorType["Union"] = 61] = "Union";
|
|
82
86
|
ValueErrorType[ValueErrorType["Void"] = 62] = "Void";
|
|
83
87
|
})(ValueErrorType || (exports.ValueErrorType = ValueErrorType = {}));
|
|
84
|
-
//
|
|
88
|
+
// ------------------------------------------------------------------
|
|
85
89
|
// ValueErrors
|
|
86
|
-
//
|
|
90
|
+
// ------------------------------------------------------------------
|
|
87
91
|
class ValueErrorsUnknownTypeError extends Error {
|
|
88
92
|
constructor(schema) {
|
|
89
93
|
super('Unknown type');
|
|
@@ -91,21 +95,21 @@ class ValueErrorsUnknownTypeError extends Error {
|
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
97
|
exports.ValueErrorsUnknownTypeError = ValueErrorsUnknownTypeError;
|
|
94
|
-
//
|
|
98
|
+
// ------------------------------------------------------------------
|
|
95
99
|
// EscapeKey
|
|
96
|
-
//
|
|
100
|
+
// ------------------------------------------------------------------
|
|
97
101
|
function EscapeKey(key) {
|
|
98
102
|
return key.replace(/~/g, '~0').replace(/\//g, '~1'); // RFC6901 Path
|
|
99
103
|
}
|
|
100
|
-
//
|
|
104
|
+
// ------------------------------------------------------------------
|
|
101
105
|
// Guards
|
|
102
|
-
//
|
|
106
|
+
// ------------------------------------------------------------------
|
|
103
107
|
function IsDefined(value) {
|
|
104
108
|
return value !== undefined;
|
|
105
109
|
}
|
|
106
|
-
//
|
|
110
|
+
// ------------------------------------------------------------------
|
|
107
111
|
// ValueErrorIterator
|
|
108
|
-
//
|
|
112
|
+
// ------------------------------------------------------------------
|
|
109
113
|
class ValueErrorIterator {
|
|
110
114
|
constructor(iterator) {
|
|
111
115
|
this.iterator = iterator;
|
|
@@ -131,7 +135,7 @@ function Create(type, schema, path, value) {
|
|
|
131
135
|
// --------------------------------------------------------------------------
|
|
132
136
|
function* TAny(schema, references, path, value) { }
|
|
133
137
|
function* TArray(schema, references, path, value) {
|
|
134
|
-
if (!(0,
|
|
138
|
+
if (!(0, index_8.IsArray)(value)) {
|
|
135
139
|
return yield Create(ValueErrorType.Array, schema, path, value);
|
|
136
140
|
}
|
|
137
141
|
if (IsDefined(schema.minItems) && !(value.length >= schema.minItems)) {
|
|
@@ -145,7 +149,7 @@ function* TArray(schema, references, path, value) {
|
|
|
145
149
|
}
|
|
146
150
|
// prettier-ignore
|
|
147
151
|
if (schema.uniqueItems === true && !((function () { const set = new Set(); for (const element of value) {
|
|
148
|
-
const hashed = (0,
|
|
152
|
+
const hashed = (0, index_5.Hash)(element);
|
|
149
153
|
if (set.has(hashed)) {
|
|
150
154
|
return false;
|
|
151
155
|
}
|
|
@@ -159,24 +163,24 @@ function* TArray(schema, references, path, value) {
|
|
|
159
163
|
if (!(IsDefined(schema.contains) || IsDefined(schema.minContains) || IsDefined(schema.maxContains))) {
|
|
160
164
|
return;
|
|
161
165
|
}
|
|
162
|
-
const containsSchema = IsDefined(schema.contains) ? schema.contains : (0,
|
|
166
|
+
const containsSchema = IsDefined(schema.contains) ? schema.contains : (0, index_7.Never)();
|
|
163
167
|
const containsCount = value.reduce((acc, value, index) => (Visit(containsSchema, references, `${path}${index}`, value).next().done === true ? acc + 1 : acc), 0);
|
|
164
168
|
if (containsCount === 0) {
|
|
165
169
|
yield Create(ValueErrorType.ArrayContains, schema, path, value);
|
|
166
170
|
}
|
|
167
|
-
if ((0,
|
|
171
|
+
if ((0, index_8.IsNumber)(schema.minContains) && containsCount < schema.minContains) {
|
|
168
172
|
yield Create(ValueErrorType.ArrayMinContains, schema, path, value);
|
|
169
173
|
}
|
|
170
|
-
if ((0,
|
|
174
|
+
if ((0, index_8.IsNumber)(schema.maxContains) && containsCount > schema.maxContains) {
|
|
171
175
|
yield Create(ValueErrorType.ArrayMaxContains, schema, path, value);
|
|
172
176
|
}
|
|
173
177
|
}
|
|
174
178
|
function* TAsyncIterator(schema, references, path, value) {
|
|
175
|
-
if (!(0,
|
|
179
|
+
if (!(0, index_8.IsAsyncIterator)(value))
|
|
176
180
|
yield Create(ValueErrorType.AsyncIterator, schema, path, value);
|
|
177
181
|
}
|
|
178
182
|
function* TBigInt(schema, references, path, value) {
|
|
179
|
-
if (!(0,
|
|
183
|
+
if (!(0, index_8.IsBigInt)(value))
|
|
180
184
|
return yield Create(ValueErrorType.BigInt, schema, path, value);
|
|
181
185
|
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
182
186
|
yield Create(ValueErrorType.BigIntExclusiveMaximum, schema, path, value);
|
|
@@ -195,14 +199,14 @@ function* TBigInt(schema, references, path, value) {
|
|
|
195
199
|
}
|
|
196
200
|
}
|
|
197
201
|
function* TBoolean(schema, references, path, value) {
|
|
198
|
-
if (!(0,
|
|
202
|
+
if (!(0, index_8.IsBoolean)(value))
|
|
199
203
|
yield Create(ValueErrorType.Boolean, schema, path, value);
|
|
200
204
|
}
|
|
201
205
|
function* TConstructor(schema, references, path, value) {
|
|
202
206
|
yield* Visit(schema.returns, references, path, value.prototype);
|
|
203
207
|
}
|
|
204
208
|
function* TDate(schema, references, path, value) {
|
|
205
|
-
if (!(0,
|
|
209
|
+
if (!(0, index_8.IsDate)(value))
|
|
206
210
|
return yield Create(ValueErrorType.Date, schema, path, value);
|
|
207
211
|
if (IsDefined(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
208
212
|
yield Create(ValueErrorType.DateExclusiveMaximumTimestamp, schema, path, value);
|
|
@@ -221,11 +225,11 @@ function* TDate(schema, references, path, value) {
|
|
|
221
225
|
}
|
|
222
226
|
}
|
|
223
227
|
function* TFunction(schema, references, path, value) {
|
|
224
|
-
if (!(0,
|
|
228
|
+
if (!(0, index_8.IsFunction)(value))
|
|
225
229
|
yield Create(ValueErrorType.Function, schema, path, value);
|
|
226
230
|
}
|
|
227
231
|
function* TInteger(schema, references, path, value) {
|
|
228
|
-
if (!(0,
|
|
232
|
+
if (!(0, index_8.IsInteger)(value))
|
|
229
233
|
return yield Create(ValueErrorType.Integer, schema, path, value);
|
|
230
234
|
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
231
235
|
yield Create(ValueErrorType.IntegerExclusiveMaximum, schema, path, value);
|
|
@@ -252,7 +256,7 @@ function* TIntersect(schema, references, path, value) {
|
|
|
252
256
|
}
|
|
253
257
|
}
|
|
254
258
|
if (schema.unevaluatedProperties === false) {
|
|
255
|
-
const keyCheck = new RegExp((0,
|
|
259
|
+
const keyCheck = new RegExp((0, index_2.KeyOfPattern)(schema));
|
|
256
260
|
for (const valueKey of Object.getOwnPropertyNames(value)) {
|
|
257
261
|
if (!keyCheck.test(valueKey)) {
|
|
258
262
|
yield Create(ValueErrorType.IntersectUnevaluatedProperties, schema, `${path}/${valueKey}`, value);
|
|
@@ -260,7 +264,7 @@ function* TIntersect(schema, references, path, value) {
|
|
|
260
264
|
}
|
|
261
265
|
}
|
|
262
266
|
if (typeof schema.unevaluatedProperties === 'object') {
|
|
263
|
-
const keyCheck = new RegExp((0,
|
|
267
|
+
const keyCheck = new RegExp((0, index_2.KeyOfPattern)(schema));
|
|
264
268
|
for (const valueKey of Object.getOwnPropertyNames(value)) {
|
|
265
269
|
if (!keyCheck.test(valueKey)) {
|
|
266
270
|
const next = Visit(schema.unevaluatedProperties, references, `${path}/${valueKey}`, value[valueKey]).next();
|
|
@@ -271,7 +275,7 @@ function* TIntersect(schema, references, path, value) {
|
|
|
271
275
|
}
|
|
272
276
|
}
|
|
273
277
|
function* TIterator(schema, references, path, value) {
|
|
274
|
-
if (!(0,
|
|
278
|
+
if (!(0, index_8.IsIterator)(value))
|
|
275
279
|
yield Create(ValueErrorType.Iterator, schema, path, value);
|
|
276
280
|
}
|
|
277
281
|
function* TLiteral(schema, references, path, value) {
|
|
@@ -286,11 +290,11 @@ function* TNot(schema, references, path, value) {
|
|
|
286
290
|
yield Create(ValueErrorType.Not, schema, path, value);
|
|
287
291
|
}
|
|
288
292
|
function* TNull(schema, references, path, value) {
|
|
289
|
-
if (!(0,
|
|
293
|
+
if (!(0, index_8.IsNull)(value))
|
|
290
294
|
yield Create(ValueErrorType.Null, schema, path, value);
|
|
291
295
|
}
|
|
292
296
|
function* TNumber(schema, references, path, value) {
|
|
293
|
-
if (!
|
|
297
|
+
if (!index_1.TypeSystemPolicy.IsNumberLike(value))
|
|
294
298
|
return yield Create(ValueErrorType.Number, schema, path, value);
|
|
295
299
|
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
296
300
|
yield Create(ValueErrorType.NumberExclusiveMaximum, schema, path, value);
|
|
@@ -309,7 +313,7 @@ function* TNumber(schema, references, path, value) {
|
|
|
309
313
|
}
|
|
310
314
|
}
|
|
311
315
|
function* TObject(schema, references, path, value) {
|
|
312
|
-
if (!
|
|
316
|
+
if (!index_1.TypeSystemPolicy.IsObjectLike(value))
|
|
313
317
|
return yield Create(ValueErrorType.Object, schema, path, value);
|
|
314
318
|
if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
315
319
|
yield Create(ValueErrorType.ObjectMinProperties, schema, path, value);
|
|
@@ -348,18 +352,18 @@ function* TObject(schema, references, path, value) {
|
|
|
348
352
|
}
|
|
349
353
|
}
|
|
350
354
|
else {
|
|
351
|
-
if (
|
|
355
|
+
if (index_1.TypeSystemPolicy.IsExactOptionalProperty(value, knownKey)) {
|
|
352
356
|
yield* Visit(property, references, `${path}/${EscapeKey(knownKey)}`, value[knownKey]);
|
|
353
357
|
}
|
|
354
358
|
}
|
|
355
359
|
}
|
|
356
360
|
}
|
|
357
361
|
function* TPromise(schema, references, path, value) {
|
|
358
|
-
if (!(0,
|
|
362
|
+
if (!(0, index_8.IsPromise)(value))
|
|
359
363
|
yield Create(ValueErrorType.Promise, schema, path, value);
|
|
360
364
|
}
|
|
361
365
|
function* TRecord(schema, references, path, value) {
|
|
362
|
-
if (!
|
|
366
|
+
if (!index_1.TypeSystemPolicy.IsRecordLike(value))
|
|
363
367
|
return yield Create(ValueErrorType.Object, schema, path, value);
|
|
364
368
|
if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
365
369
|
yield Create(ValueErrorType.ObjectMinProperties, schema, path, value);
|
|
@@ -388,10 +392,10 @@ function* TRecord(schema, references, path, value) {
|
|
|
388
392
|
}
|
|
389
393
|
}
|
|
390
394
|
function* TRef(schema, references, path, value) {
|
|
391
|
-
yield* Visit((0,
|
|
395
|
+
yield* Visit((0, index_4.Deref)(schema, references), references, path, value);
|
|
392
396
|
}
|
|
393
397
|
function* TString(schema, references, path, value) {
|
|
394
|
-
if (!(0,
|
|
398
|
+
if (!(0, index_8.IsString)(value))
|
|
395
399
|
return yield Create(ValueErrorType.String, schema, path, value);
|
|
396
400
|
if (IsDefined(schema.minLength) && !(value.length >= schema.minLength)) {
|
|
397
401
|
yield Create(ValueErrorType.StringMinLength, schema, path, value);
|
|
@@ -399,18 +403,18 @@ function* TString(schema, references, path, value) {
|
|
|
399
403
|
if (IsDefined(schema.maxLength) && !(value.length <= schema.maxLength)) {
|
|
400
404
|
yield Create(ValueErrorType.StringMaxLength, schema, path, value);
|
|
401
405
|
}
|
|
402
|
-
if ((0,
|
|
406
|
+
if ((0, index_8.IsString)(schema.pattern)) {
|
|
403
407
|
const regex = new RegExp(schema.pattern);
|
|
404
408
|
if (!regex.test(value)) {
|
|
405
409
|
yield Create(ValueErrorType.StringPattern, schema, path, value);
|
|
406
410
|
}
|
|
407
411
|
}
|
|
408
|
-
if ((0,
|
|
409
|
-
if (!
|
|
412
|
+
if ((0, index_8.IsString)(schema.format)) {
|
|
413
|
+
if (!index_3.FormatRegistry.Has(schema.format)) {
|
|
410
414
|
yield Create(ValueErrorType.StringFormatUnknown, schema, path, value);
|
|
411
415
|
}
|
|
412
416
|
else {
|
|
413
|
-
const format =
|
|
417
|
+
const format = index_3.FormatRegistry.Get(schema.format);
|
|
414
418
|
if (!format(value)) {
|
|
415
419
|
yield Create(ValueErrorType.StringFormat, schema, path, value);
|
|
416
420
|
}
|
|
@@ -418,11 +422,11 @@ function* TString(schema, references, path, value) {
|
|
|
418
422
|
}
|
|
419
423
|
}
|
|
420
424
|
function* TSymbol(schema, references, path, value) {
|
|
421
|
-
if (!(0,
|
|
425
|
+
if (!(0, index_8.IsSymbol)(value))
|
|
422
426
|
yield Create(ValueErrorType.Symbol, schema, path, value);
|
|
423
427
|
}
|
|
424
428
|
function* TTemplateLiteral(schema, references, path, value) {
|
|
425
|
-
if (!(0,
|
|
429
|
+
if (!(0, index_8.IsString)(value))
|
|
426
430
|
return yield Create(ValueErrorType.String, schema, path, value);
|
|
427
431
|
const regex = new RegExp(schema.pattern);
|
|
428
432
|
if (!regex.test(value)) {
|
|
@@ -430,10 +434,10 @@ function* TTemplateLiteral(schema, references, path, value) {
|
|
|
430
434
|
}
|
|
431
435
|
}
|
|
432
436
|
function* TThis(schema, references, path, value) {
|
|
433
|
-
yield* Visit((0,
|
|
437
|
+
yield* Visit((0, index_4.Deref)(schema, references), references, path, value);
|
|
434
438
|
}
|
|
435
439
|
function* TTuple(schema, references, path, value) {
|
|
436
|
-
if (!(0,
|
|
440
|
+
if (!(0, index_8.IsArray)(value))
|
|
437
441
|
return yield Create(ValueErrorType.Tuple, schema, path, value);
|
|
438
442
|
if (schema.items === undefined && !(value.length === 0)) {
|
|
439
443
|
return yield Create(ValueErrorType.TupleLength, schema, path, value);
|
|
@@ -449,7 +453,7 @@ function* TTuple(schema, references, path, value) {
|
|
|
449
453
|
}
|
|
450
454
|
}
|
|
451
455
|
function* TUndefined(schema, references, path, value) {
|
|
452
|
-
if (!(0,
|
|
456
|
+
if (!(0, index_8.IsUndefined)(value))
|
|
453
457
|
yield Create(ValueErrorType.Undefined, schema, path, value);
|
|
454
458
|
}
|
|
455
459
|
function* TUnion(schema, references, path, value) {
|
|
@@ -465,7 +469,7 @@ function* TUnion(schema, references, path, value) {
|
|
|
465
469
|
}
|
|
466
470
|
}
|
|
467
471
|
function* TUint8Array(schema, references, path, value) {
|
|
468
|
-
if (!(0,
|
|
472
|
+
if (!(0, index_8.IsUint8Array)(value))
|
|
469
473
|
return yield Create(ValueErrorType.Uint8Array, schema, path, value);
|
|
470
474
|
if (IsDefined(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
|
|
471
475
|
yield Create(ValueErrorType.Uint8ArrayMaxByteLength, schema, path, value);
|
|
@@ -476,18 +480,18 @@ function* TUint8Array(schema, references, path, value) {
|
|
|
476
480
|
}
|
|
477
481
|
function* TUnknown(schema, references, path, value) { }
|
|
478
482
|
function* TVoid(schema, references, path, value) {
|
|
479
|
-
if (!
|
|
483
|
+
if (!index_1.TypeSystemPolicy.IsVoidLike(value))
|
|
480
484
|
yield Create(ValueErrorType.Void, schema, path, value);
|
|
481
485
|
}
|
|
482
486
|
function* TKind(schema, references, path, value) {
|
|
483
|
-
const check =
|
|
487
|
+
const check = index_3.TypeRegistry.Get(schema[index_6.Kind]);
|
|
484
488
|
if (!check(schema, value))
|
|
485
489
|
yield Create(ValueErrorType.Kind, schema, path, value);
|
|
486
490
|
}
|
|
487
491
|
function* Visit(schema, references, path, value) {
|
|
488
492
|
const references_ = IsDefined(schema.$id) ? [...references, schema] : references;
|
|
489
493
|
const schema_ = schema;
|
|
490
|
-
switch (schema_[
|
|
494
|
+
switch (schema_[index_6.Kind]) {
|
|
491
495
|
case 'Any':
|
|
492
496
|
return yield* TAny(schema_, references_, path, value);
|
|
493
497
|
case 'Array':
|
|
@@ -549,7 +553,7 @@ function* Visit(schema, references, path, value) {
|
|
|
549
553
|
case 'Void':
|
|
550
554
|
return yield* TVoid(schema_, references_, path, value);
|
|
551
555
|
default:
|
|
552
|
-
if (!
|
|
556
|
+
if (!index_3.TypeRegistry.Has(schema_[index_6.Kind]))
|
|
553
557
|
throw new ValueErrorsUnknownTypeError(schema);
|
|
554
558
|
return yield* TKind(schema_, references_, path, value);
|
|
555
559
|
}
|
|
@@ -31,9 +31,9 @@ function FromPromise(T) {
|
|
|
31
31
|
}
|
|
32
32
|
// prettier-ignore
|
|
33
33
|
function FromSchema(T) {
|
|
34
|
-
return ((0, type_2.
|
|
35
|
-
(0, type_2.
|
|
36
|
-
(0, type_2.
|
|
34
|
+
return ((0, type_2.IsIntersect)(T) ? FromIntersect(T.allOf) :
|
|
35
|
+
(0, type_2.IsUnion)(T) ? FromUnion(T.anyOf) :
|
|
36
|
+
(0, type_2.IsPromise)(T) ? FromPromise(T.item) :
|
|
37
37
|
T);
|
|
38
38
|
}
|
|
39
39
|
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
@@ -93,17 +93,17 @@ function FromRef(schema, references) {
|
|
|
93
93
|
}
|
|
94
94
|
// prettier-ignore
|
|
95
95
|
function DerefResolve(schema, references) {
|
|
96
|
-
return ((0, type_2.
|
|
97
|
-
(0, type_2.
|
|
98
|
-
(0, type_2.
|
|
99
|
-
(0, type_2.
|
|
100
|
-
(0, type_2.
|
|
101
|
-
(0, type_2.
|
|
102
|
-
(0, type_2.
|
|
103
|
-
(0, type_2.
|
|
104
|
-
(0, type_2.
|
|
105
|
-
(0, type_2.
|
|
106
|
-
(0, type_2.
|
|
96
|
+
return ((0, type_2.IsConstructor)(schema) ? FromConstructor(schema, references) :
|
|
97
|
+
(0, type_2.IsFunction)(schema) ? FromFunction(schema, references) :
|
|
98
|
+
(0, type_2.IsIntersect)(schema) ? FromIntersect(schema, references) :
|
|
99
|
+
(0, type_2.IsUnion)(schema) ? FromUnion(schema, references) :
|
|
100
|
+
(0, type_2.IsTuple)(schema) ? FromTuple(schema, references) :
|
|
101
|
+
(0, type_2.IsArray)(schema) ? FromArray(schema, references) :
|
|
102
|
+
(0, type_2.IsObject)(schema) ? FromObject(schema, references) :
|
|
103
|
+
(0, type_2.IsPromise)(schema) ? FromPromise(schema, references) :
|
|
104
|
+
(0, type_2.IsAsyncIterator)(schema) ? FromAsyncIterator(schema, references) :
|
|
105
|
+
(0, type_2.IsIterator)(schema) ? FromIterator(schema, references) :
|
|
106
|
+
(0, type_2.IsRef)(schema) ? FromRef(schema, references) :
|
|
107
107
|
schema);
|
|
108
108
|
}
|
|
109
109
|
exports.DerefResolve = DerefResolve;
|
|
@@ -8,13 +8,16 @@ const index_3 = require("../never/index");
|
|
|
8
8
|
const index_4 = require("../extends/index");
|
|
9
9
|
const type_1 = require("../clone/type");
|
|
10
10
|
const exclude_from_mapped_result_1 = require("./exclude-from-mapped-result");
|
|
11
|
+
// ------------------------------------------------------------------
|
|
12
|
+
// TypeGuard
|
|
13
|
+
// ------------------------------------------------------------------
|
|
11
14
|
// prettier-ignore
|
|
12
15
|
const type_2 = require("../guard/type");
|
|
13
16
|
// prettier-ignore
|
|
14
17
|
function ExcludeResolve(L, R) {
|
|
15
|
-
return ((0, type_2.
|
|
16
|
-
(0, type_2.
|
|
17
|
-
(0, type_2.
|
|
18
|
+
return ((0, type_2.IsTemplateLiteral)(L) ? ExcludeResolve((0, index_1.TemplateLiteralToUnion)(L), R) :
|
|
19
|
+
(0, type_2.IsTemplateLiteral)(R) ? ExcludeResolve(L, (0, index_1.TemplateLiteralToUnion)(R)) :
|
|
20
|
+
(0, type_2.IsUnion)(L) ? (() => {
|
|
18
21
|
const narrowed = L.anyOf.filter((inner) => (0, index_4.ExtendsCheck)(inner, R) === index_4.ExtendsResult.False);
|
|
19
22
|
return (narrowed.length === 1 ? narrowed[0] : (0, index_2.Union)(narrowed));
|
|
20
23
|
})() :
|
|
@@ -23,7 +26,7 @@ function ExcludeResolve(L, R) {
|
|
|
23
26
|
}
|
|
24
27
|
/** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
|
|
25
28
|
function Exclude(unionType, excludedMembers, options = {}) {
|
|
26
|
-
if ((0, type_2.
|
|
29
|
+
if ((0, type_2.IsMappedResult)(unionType)) {
|
|
27
30
|
return (0, exclude_from_mapped_result_1.ExcludeFromMappedResult)(unionType, excludedMembers, options);
|
|
28
31
|
}
|
|
29
32
|
else {
|