@sinclair/typebox 0.32.0-dev-19 → 0.32.0-dev-21
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 +62 -62
- package/build/import/errors/errors.mjs +62 -62
- package/build/import/index.d.mts +6 -6
- package/build/import/index.mjs +3 -3
- package/build/import/type/indexed/indexed-property-keys.d.mts +2 -2
- package/build/import/type/indexed/indexed-property-keys.mjs +6 -11
- package/build/import/type/intrinsic/intrinsic.mjs +3 -3
- package/build/import/type/optional/index.d.mts +1 -0
- package/build/import/type/optional/index.mjs +1 -0
- package/build/import/type/optional/optional-from-mapped-result.d.mts +12 -0
- package/build/import/type/optional/optional-from-mapped-result.mjs +17 -0
- package/build/import/type/optional/optional.d.mts +19 -2
- package/build/import/type/optional/optional.mjs +18 -2
- package/build/import/type/readonly/index.d.mts +1 -0
- package/build/import/type/readonly/index.mjs +1 -0
- package/build/import/type/readonly/readonly-from-mapped-result.d.mts +12 -0
- package/build/import/type/readonly/readonly-from-mapped-result.mjs +17 -0
- package/build/import/type/readonly/readonly.d.mts +18 -1
- package/build/import/type/readonly/readonly.mjs +18 -2
- package/build/import/type/record/record.d.mts +2 -2
- package/build/import/type/record/record.mjs +2 -3
- package/build/import/type/schema/schema.d.mts +1 -1
- package/build/import/type/symbol/symbol.d.mts +1 -1
- package/build/import/type/template-literal/finite.d.mts +7 -5
- package/build/import/type/template-literal/finite.mjs +14 -5
- package/build/import/type/template-literal/generate.d.mts +14 -8
- package/build/import/type/template-literal/generate.mjs +19 -9
- package/build/import/type/template-literal/index.d.mts +1 -1
- package/build/import/type/template-literal/index.mjs +1 -1
- package/build/import/type/template-literal/{parser.mjs → parse.mjs} +7 -2
- package/build/import/type/template-literal/syntax.d.mts +1 -1
- package/build/import/type/template-literal/syntax.mjs +0 -1
- package/build/import/type/template-literal/template-literal.d.mts +2 -2
- package/build/import/type/template-literal/template-literal.mjs +1 -1
- package/build/import/type/template-literal/union.d.mts +2 -2
- package/build/import/type/template-literal/union.mjs +5 -10
- package/build/import/type/type/json.d.mts +19 -7
- package/build/import/type/type/json.mjs +5 -5
- package/build/import/value/cast/cast.mjs +20 -20
- package/build/import/value/check/check.mjs +62 -62
- package/build/import/value/clean/clean.mjs +16 -16
- package/build/import/value/convert/convert.mjs +36 -36
- package/build/import/value/create/create.mjs +66 -67
- package/build/import/value/default/default.mjs +16 -16
- package/build/import/value/transform/decode.mjs +18 -18
- package/build/import/value/transform/encode.mjs +18 -18
- package/build/import/value/transform/has.mjs +28 -28
- package/build/require/compiler/compiler.js +62 -62
- package/build/require/errors/errors.js +62 -62
- package/build/require/index.d.ts +6 -6
- package/build/require/index.js +6 -2
- package/build/require/type/indexed/indexed-property-keys.d.ts +2 -2
- package/build/require/type/indexed/indexed-property-keys.js +4 -9
- package/build/require/type/intrinsic/intrinsic.js +2 -2
- package/build/require/type/optional/index.d.ts +1 -0
- package/build/require/type/optional/index.js +1 -0
- package/build/require/type/optional/optional-from-mapped-result.d.ts +12 -0
- package/build/require/type/optional/optional-from-mapped-result.js +22 -0
- package/build/require/type/optional/optional.d.ts +19 -2
- package/build/require/type/optional/optional.js +18 -2
- package/build/require/type/readonly/index.d.ts +1 -0
- package/build/require/type/readonly/index.js +1 -0
- package/build/require/type/readonly/readonly-from-mapped-result.d.ts +12 -0
- package/build/require/type/readonly/readonly-from-mapped-result.js +22 -0
- package/build/require/type/readonly/readonly.d.ts +18 -1
- package/build/require/type/readonly/readonly.js +18 -2
- package/build/require/type/record/record.d.ts +2 -2
- package/build/require/type/record/record.js +1 -2
- package/build/require/type/schema/schema.d.ts +1 -1
- package/build/require/type/symbol/symbol.d.ts +1 -1
- package/build/require/type/template-literal/finite.d.ts +7 -5
- package/build/require/type/template-literal/finite.js +16 -6
- package/build/require/type/template-literal/generate.d.ts +14 -8
- package/build/require/type/template-literal/generate.js +22 -11
- package/build/require/type/template-literal/index.d.ts +1 -1
- package/build/require/type/template-literal/index.js +1 -1
- package/build/require/type/template-literal/{parser.js → parse.js} +7 -2
- package/build/require/type/template-literal/syntax.d.ts +1 -1
- package/build/require/type/template-literal/syntax.js +0 -1
- package/build/require/type/template-literal/template-literal.d.ts +2 -2
- package/build/require/type/template-literal/template-literal.js +1 -1
- package/build/require/type/template-literal/union.d.ts +2 -2
- package/build/require/type/template-literal/union.js +5 -10
- package/build/require/type/type/json.d.ts +19 -7
- package/build/require/type/type/json.js +5 -5
- package/build/require/value/cast/cast.js +20 -20
- package/build/require/value/check/check.js +62 -62
- package/build/require/value/clean/clean.js +16 -16
- package/build/require/value/convert/convert.js +36 -36
- package/build/require/value/create/create.js +65 -66
- package/build/require/value/default/default.js +16 -16
- package/build/require/value/transform/decode.js +18 -18
- package/build/require/value/transform/encode.js +18 -18
- package/build/require/value/transform/has.js +28 -28
- package/package.json +1 -1
- package/readme.md +52 -52
- /package/build/import/type/template-literal/{parser.d.mts → parse.d.mts} +0 -0
- /package/build/require/type/template-literal/{parser.d.ts → parse.d.ts} +0 -0
|
@@ -196,10 +196,10 @@ export var TypeCompiler;
|
|
|
196
196
|
// ----------------------------------------------------------------
|
|
197
197
|
// Types
|
|
198
198
|
// ----------------------------------------------------------------
|
|
199
|
-
function*
|
|
199
|
+
function* FromAny(schema, references, value) {
|
|
200
200
|
yield 'true';
|
|
201
201
|
}
|
|
202
|
-
function*
|
|
202
|
+
function* FromArray(schema, references, value) {
|
|
203
203
|
yield `Array.isArray(${value})`;
|
|
204
204
|
const [parameter, accumulator] = [CreateParameter('value', 'any'), CreateParameter('acc', 'number')];
|
|
205
205
|
if (IsNumber(schema.maxItems))
|
|
@@ -223,10 +223,10 @@ export var TypeCompiler;
|
|
|
223
223
|
yield `((${parameter}) => { ${block} )(${value})`;
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
|
-
function*
|
|
226
|
+
function* FromAsyncIterator(schema, references, value) {
|
|
227
227
|
yield `(typeof value === 'object' && Symbol.asyncIterator in ${value})`;
|
|
228
228
|
}
|
|
229
|
-
function*
|
|
229
|
+
function* FromBigInt(schema, references, value) {
|
|
230
230
|
yield `(typeof ${value} === 'bigint')`;
|
|
231
231
|
if (IsBigInt(schema.exclusiveMaximum))
|
|
232
232
|
yield `${value} < BigInt(${schema.exclusiveMaximum})`;
|
|
@@ -239,13 +239,13 @@ export var TypeCompiler;
|
|
|
239
239
|
if (IsBigInt(schema.multipleOf))
|
|
240
240
|
yield `(${value} % BigInt(${schema.multipleOf})) === 0`;
|
|
241
241
|
}
|
|
242
|
-
function*
|
|
242
|
+
function* FromBoolean(schema, references, value) {
|
|
243
243
|
yield `(typeof ${value} === 'boolean')`;
|
|
244
244
|
}
|
|
245
|
-
function*
|
|
245
|
+
function* FromConstructor(schema, references, value) {
|
|
246
246
|
yield* Visit(schema.returns, references, `${value}.prototype`);
|
|
247
247
|
}
|
|
248
|
-
function*
|
|
248
|
+
function* FromDate(schema, references, value) {
|
|
249
249
|
yield `(${value} instanceof Date) && Number.isFinite(${value}.getTime())`;
|
|
250
250
|
if (IsNumber(schema.exclusiveMaximumTimestamp))
|
|
251
251
|
yield `${value}.getTime() < ${schema.exclusiveMaximumTimestamp}`;
|
|
@@ -258,10 +258,10 @@ export var TypeCompiler;
|
|
|
258
258
|
if (IsNumber(schema.multipleOfTimestamp))
|
|
259
259
|
yield `(${value}.getTime() % ${schema.multipleOfTimestamp}) === 0`;
|
|
260
260
|
}
|
|
261
|
-
function*
|
|
261
|
+
function* FromFunction(schema, references, value) {
|
|
262
262
|
yield `(typeof ${value} === 'function')`;
|
|
263
263
|
}
|
|
264
|
-
function*
|
|
264
|
+
function* FromInteger(schema, references, value) {
|
|
265
265
|
yield `(typeof ${value} === 'number' && Number.isInteger(${value}))`;
|
|
266
266
|
if (IsNumber(schema.exclusiveMaximum))
|
|
267
267
|
yield `${value} < ${schema.exclusiveMaximum}`;
|
|
@@ -274,7 +274,7 @@ export var TypeCompiler;
|
|
|
274
274
|
if (IsNumber(schema.multipleOf))
|
|
275
275
|
yield `(${value} % ${schema.multipleOf}) === 0`;
|
|
276
276
|
}
|
|
277
|
-
function*
|
|
277
|
+
function* FromIntersect(schema, references, value) {
|
|
278
278
|
const check1 = schema.allOf.map((schema) => CreateExpression(schema, references, value)).join(' && ');
|
|
279
279
|
if (schema.unevaluatedProperties === false) {
|
|
280
280
|
const keyCheck = CreateVariable(`${new RegExp(KeyOfPattern(schema))};`);
|
|
@@ -290,10 +290,10 @@ export var TypeCompiler;
|
|
|
290
290
|
yield `(${check1})`;
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
|
-
function*
|
|
293
|
+
function* FromIterator(schema, references, value) {
|
|
294
294
|
yield `(typeof value === 'object' && Symbol.iterator in ${value})`;
|
|
295
295
|
}
|
|
296
|
-
function*
|
|
296
|
+
function* FromLiteral(schema, references, value) {
|
|
297
297
|
if (typeof schema.const === 'number' || typeof schema.const === 'boolean') {
|
|
298
298
|
yield `(${value} === ${schema.const})`;
|
|
299
299
|
}
|
|
@@ -301,17 +301,17 @@ export var TypeCompiler;
|
|
|
301
301
|
yield `(${value} === '${LiteralString.Escape(schema.const)}')`;
|
|
302
302
|
}
|
|
303
303
|
}
|
|
304
|
-
function*
|
|
304
|
+
function* FromNever(schema, references, value) {
|
|
305
305
|
yield `false`;
|
|
306
306
|
}
|
|
307
|
-
function*
|
|
307
|
+
function* FromNot(schema, references, value) {
|
|
308
308
|
const expression = CreateExpression(schema.not, references, value);
|
|
309
309
|
yield `(!${expression})`;
|
|
310
310
|
}
|
|
311
|
-
function*
|
|
311
|
+
function* FromNull(schema, references, value) {
|
|
312
312
|
yield `(${value} === null)`;
|
|
313
313
|
}
|
|
314
|
-
function*
|
|
314
|
+
function* FromNumber(schema, references, value) {
|
|
315
315
|
yield Policy.IsNumberLike(value);
|
|
316
316
|
if (IsNumber(schema.exclusiveMaximum))
|
|
317
317
|
yield `${value} < ${schema.exclusiveMaximum}`;
|
|
@@ -324,7 +324,7 @@ export var TypeCompiler;
|
|
|
324
324
|
if (IsNumber(schema.multipleOf))
|
|
325
325
|
yield `(${value} % ${schema.multipleOf}) === 0`;
|
|
326
326
|
}
|
|
327
|
-
function*
|
|
327
|
+
function* FromObject(schema, references, value) {
|
|
328
328
|
yield Policy.IsObjectLike(value);
|
|
329
329
|
if (IsNumber(schema.minProperties))
|
|
330
330
|
yield `Object.getOwnPropertyNames(${value}).length >= ${schema.minProperties}`;
|
|
@@ -359,10 +359,10 @@ export var TypeCompiler;
|
|
|
359
359
|
yield `(Object.getOwnPropertyNames(${value}).every(key => ${keys}.includes(key) || ${expression}))`;
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
|
-
function*
|
|
362
|
+
function* FromPromise(schema, references, value) {
|
|
363
363
|
yield `(typeof value === 'object' && typeof ${value}.then === 'function')`;
|
|
364
364
|
}
|
|
365
|
-
function*
|
|
365
|
+
function* FromRecord(schema, references, value) {
|
|
366
366
|
yield Policy.IsRecordLike(value);
|
|
367
367
|
if (IsNumber(schema.minProperties))
|
|
368
368
|
yield `Object.getOwnPropertyNames(${value}).length >= ${schema.minProperties}`;
|
|
@@ -375,7 +375,7 @@ export var TypeCompiler;
|
|
|
375
375
|
const expression = `(${variable}.test(key) ? ${check1} : ${check2})`;
|
|
376
376
|
yield `(Object.entries(${value}).every(([key, value]) => ${expression}))`;
|
|
377
377
|
}
|
|
378
|
-
function*
|
|
378
|
+
function* FromRef(schema, references, value) {
|
|
379
379
|
const target = Deref(schema, references);
|
|
380
380
|
// Reference: If we have seen this reference before we can just yield and return the function call.
|
|
381
381
|
// If this isn't the case we defer to visit to generate and set the function for subsequent passes.
|
|
@@ -383,7 +383,7 @@ export var TypeCompiler;
|
|
|
383
383
|
return yield `${CreateFunctionName(schema.$ref)}(${value})`;
|
|
384
384
|
yield* Visit(target, references, value);
|
|
385
385
|
}
|
|
386
|
-
function*
|
|
386
|
+
function* FromString(schema, references, value) {
|
|
387
387
|
yield `(typeof ${value} === 'string')`;
|
|
388
388
|
if (IsNumber(schema.maxLength))
|
|
389
389
|
yield `${value}.length <= ${schema.maxLength}`;
|
|
@@ -397,19 +397,19 @@ export var TypeCompiler;
|
|
|
397
397
|
yield `format('${schema.format}', ${value})`;
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
|
-
function*
|
|
400
|
+
function* FromSymbol(schema, references, value) {
|
|
401
401
|
yield `(typeof ${value} === 'symbol')`;
|
|
402
402
|
}
|
|
403
|
-
function*
|
|
403
|
+
function* FromTemplateLiteral(schema, references, value) {
|
|
404
404
|
yield `(typeof ${value} === 'string')`;
|
|
405
405
|
const variable = CreateVariable(`${new RegExp(schema.pattern)};`);
|
|
406
406
|
yield `${variable}.test(${value})`;
|
|
407
407
|
}
|
|
408
|
-
function*
|
|
408
|
+
function* FromThis(schema, references, value) {
|
|
409
409
|
// Note: This types are assured to be hoisted prior to this call. Just yield the function.
|
|
410
410
|
yield `${CreateFunctionName(schema.$ref)}(${value})`;
|
|
411
411
|
}
|
|
412
|
-
function*
|
|
412
|
+
function* FromTuple(schema, references, value) {
|
|
413
413
|
yield `Array.isArray(${value})`;
|
|
414
414
|
if (schema.items === undefined)
|
|
415
415
|
return yield `${value}.length === 0`;
|
|
@@ -419,27 +419,27 @@ export var TypeCompiler;
|
|
|
419
419
|
yield `${expression}`;
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
|
-
function*
|
|
422
|
+
function* FromUndefined(schema, references, value) {
|
|
423
423
|
yield `${value} === undefined`;
|
|
424
424
|
}
|
|
425
|
-
function*
|
|
425
|
+
function* FromUnion(schema, references, value) {
|
|
426
426
|
const expressions = schema.anyOf.map((schema) => CreateExpression(schema, references, value));
|
|
427
427
|
yield `(${expressions.join(' || ')})`;
|
|
428
428
|
}
|
|
429
|
-
function*
|
|
429
|
+
function* FromUint8Array(schema, references, value) {
|
|
430
430
|
yield `${value} instanceof Uint8Array`;
|
|
431
431
|
if (IsNumber(schema.maxByteLength))
|
|
432
432
|
yield `(${value}.length <= ${schema.maxByteLength})`;
|
|
433
433
|
if (IsNumber(schema.minByteLength))
|
|
434
434
|
yield `(${value}.length >= ${schema.minByteLength})`;
|
|
435
435
|
}
|
|
436
|
-
function*
|
|
436
|
+
function* FromUnknown(schema, references, value) {
|
|
437
437
|
yield 'true';
|
|
438
438
|
}
|
|
439
|
-
function*
|
|
439
|
+
function* FromVoid(schema, references, value) {
|
|
440
440
|
yield Policy.IsVoidLike(value);
|
|
441
441
|
}
|
|
442
|
-
function*
|
|
442
|
+
function* FromKind(schema, references, value) {
|
|
443
443
|
const instance = state.instances.size;
|
|
444
444
|
state.instances.set(instance, schema);
|
|
445
445
|
yield `kind('${schema[Kind]}', ${instance}, ${value})`;
|
|
@@ -463,69 +463,69 @@ export var TypeCompiler;
|
|
|
463
463
|
}
|
|
464
464
|
switch (schema_[Kind]) {
|
|
465
465
|
case 'Any':
|
|
466
|
-
return yield*
|
|
466
|
+
return yield* FromAny(schema_, references_, value);
|
|
467
467
|
case 'Array':
|
|
468
|
-
return yield*
|
|
468
|
+
return yield* FromArray(schema_, references_, value);
|
|
469
469
|
case 'AsyncIterator':
|
|
470
|
-
return yield*
|
|
470
|
+
return yield* FromAsyncIterator(schema_, references_, value);
|
|
471
471
|
case 'BigInt':
|
|
472
|
-
return yield*
|
|
472
|
+
return yield* FromBigInt(schema_, references_, value);
|
|
473
473
|
case 'Boolean':
|
|
474
|
-
return yield*
|
|
474
|
+
return yield* FromBoolean(schema_, references_, value);
|
|
475
475
|
case 'Constructor':
|
|
476
|
-
return yield*
|
|
476
|
+
return yield* FromConstructor(schema_, references_, value);
|
|
477
477
|
case 'Date':
|
|
478
|
-
return yield*
|
|
478
|
+
return yield* FromDate(schema_, references_, value);
|
|
479
479
|
case 'Function':
|
|
480
|
-
return yield*
|
|
480
|
+
return yield* FromFunction(schema_, references_, value);
|
|
481
481
|
case 'Integer':
|
|
482
|
-
return yield*
|
|
482
|
+
return yield* FromInteger(schema_, references_, value);
|
|
483
483
|
case 'Intersect':
|
|
484
|
-
return yield*
|
|
484
|
+
return yield* FromIntersect(schema_, references_, value);
|
|
485
485
|
case 'Iterator':
|
|
486
|
-
return yield*
|
|
486
|
+
return yield* FromIterator(schema_, references_, value);
|
|
487
487
|
case 'Literal':
|
|
488
|
-
return yield*
|
|
488
|
+
return yield* FromLiteral(schema_, references_, value);
|
|
489
489
|
case 'Never':
|
|
490
|
-
return yield*
|
|
490
|
+
return yield* FromNever(schema_, references_, value);
|
|
491
491
|
case 'Not':
|
|
492
|
-
return yield*
|
|
492
|
+
return yield* FromNot(schema_, references_, value);
|
|
493
493
|
case 'Null':
|
|
494
|
-
return yield*
|
|
494
|
+
return yield* FromNull(schema_, references_, value);
|
|
495
495
|
case 'Number':
|
|
496
|
-
return yield*
|
|
496
|
+
return yield* FromNumber(schema_, references_, value);
|
|
497
497
|
case 'Object':
|
|
498
|
-
return yield*
|
|
498
|
+
return yield* FromObject(schema_, references_, value);
|
|
499
499
|
case 'Promise':
|
|
500
|
-
return yield*
|
|
500
|
+
return yield* FromPromise(schema_, references_, value);
|
|
501
501
|
case 'Record':
|
|
502
|
-
return yield*
|
|
502
|
+
return yield* FromRecord(schema_, references_, value);
|
|
503
503
|
case 'Ref':
|
|
504
|
-
return yield*
|
|
504
|
+
return yield* FromRef(schema_, references_, value);
|
|
505
505
|
case 'String':
|
|
506
|
-
return yield*
|
|
506
|
+
return yield* FromString(schema_, references_, value);
|
|
507
507
|
case 'Symbol':
|
|
508
|
-
return yield*
|
|
508
|
+
return yield* FromSymbol(schema_, references_, value);
|
|
509
509
|
case 'TemplateLiteral':
|
|
510
|
-
return yield*
|
|
510
|
+
return yield* FromTemplateLiteral(schema_, references_, value);
|
|
511
511
|
case 'This':
|
|
512
|
-
return yield*
|
|
512
|
+
return yield* FromThis(schema_, references_, value);
|
|
513
513
|
case 'Tuple':
|
|
514
|
-
return yield*
|
|
514
|
+
return yield* FromTuple(schema_, references_, value);
|
|
515
515
|
case 'Undefined':
|
|
516
|
-
return yield*
|
|
516
|
+
return yield* FromUndefined(schema_, references_, value);
|
|
517
517
|
case 'Union':
|
|
518
|
-
return yield*
|
|
518
|
+
return yield* FromUnion(schema_, references_, value);
|
|
519
519
|
case 'Uint8Array':
|
|
520
|
-
return yield*
|
|
520
|
+
return yield* FromUint8Array(schema_, references_, value);
|
|
521
521
|
case 'Unknown':
|
|
522
|
-
return yield*
|
|
522
|
+
return yield* FromUnknown(schema_, references_, value);
|
|
523
523
|
case 'Void':
|
|
524
|
-
return yield*
|
|
524
|
+
return yield* FromVoid(schema_, references_, value);
|
|
525
525
|
default:
|
|
526
526
|
if (!TypeRegistry.Has(schema_[Kind]))
|
|
527
527
|
throw new TypeCompilerUnknownTypeError(schema);
|
|
528
|
-
return yield*
|
|
528
|
+
return yield* FromKind(schema_, references_, value);
|
|
529
529
|
}
|
|
530
530
|
}
|
|
531
531
|
// ----------------------------------------------------------------
|
|
@@ -129,8 +129,8 @@ function Create(type, schema, path, value) {
|
|
|
129
129
|
// --------------------------------------------------------------------------
|
|
130
130
|
// Types
|
|
131
131
|
// --------------------------------------------------------------------------
|
|
132
|
-
function*
|
|
133
|
-
function*
|
|
132
|
+
function* FromAny(schema, references, path, value) { }
|
|
133
|
+
function* FromArray(schema, references, path, value) {
|
|
134
134
|
if (!IsArray(value)) {
|
|
135
135
|
return yield Create(ValueErrorType.Array, schema, path, value);
|
|
136
136
|
}
|
|
@@ -171,11 +171,11 @@ function* TArray(schema, references, path, value) {
|
|
|
171
171
|
yield Create(ValueErrorType.ArrayMaxContains, schema, path, value);
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
function*
|
|
174
|
+
function* FromAsyncIterator(schema, references, path, value) {
|
|
175
175
|
if (!IsAsyncIterator(value))
|
|
176
176
|
yield Create(ValueErrorType.AsyncIterator, schema, path, value);
|
|
177
177
|
}
|
|
178
|
-
function*
|
|
178
|
+
function* FromBigInt(schema, references, path, value) {
|
|
179
179
|
if (!IsBigInt(value))
|
|
180
180
|
return yield Create(ValueErrorType.BigInt, schema, path, value);
|
|
181
181
|
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
@@ -194,14 +194,14 @@ function* TBigInt(schema, references, path, value) {
|
|
|
194
194
|
yield Create(ValueErrorType.BigIntMultipleOf, schema, path, value);
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
|
-
function*
|
|
197
|
+
function* FromBoolean(schema, references, path, value) {
|
|
198
198
|
if (!IsBoolean(value))
|
|
199
199
|
yield Create(ValueErrorType.Boolean, schema, path, value);
|
|
200
200
|
}
|
|
201
|
-
function*
|
|
201
|
+
function* FromConstructor(schema, references, path, value) {
|
|
202
202
|
yield* Visit(schema.returns, references, path, value.prototype);
|
|
203
203
|
}
|
|
204
|
-
function*
|
|
204
|
+
function* FromDate(schema, references, path, value) {
|
|
205
205
|
if (!IsDate(value))
|
|
206
206
|
return yield Create(ValueErrorType.Date, schema, path, value);
|
|
207
207
|
if (IsDefined(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
@@ -220,11 +220,11 @@ function* TDate(schema, references, path, value) {
|
|
|
220
220
|
yield Create(ValueErrorType.DateMultipleOfTimestamp, schema, path, value);
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
|
-
function*
|
|
223
|
+
function* FromFunction(schema, references, path, value) {
|
|
224
224
|
if (!IsFunction(value))
|
|
225
225
|
yield Create(ValueErrorType.Function, schema, path, value);
|
|
226
226
|
}
|
|
227
|
-
function*
|
|
227
|
+
function* FromInteger(schema, references, path, value) {
|
|
228
228
|
if (!IsInteger(value))
|
|
229
229
|
return yield Create(ValueErrorType.Integer, schema, path, value);
|
|
230
230
|
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
@@ -243,7 +243,7 @@ function* TInteger(schema, references, path, value) {
|
|
|
243
243
|
yield Create(ValueErrorType.IntegerMultipleOf, schema, path, value);
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
|
-
function*
|
|
246
|
+
function* FromIntersect(schema, references, path, value) {
|
|
247
247
|
for (const inner of schema.allOf) {
|
|
248
248
|
const next = Visit(inner, references, path, value).next();
|
|
249
249
|
if (!next.done) {
|
|
@@ -270,26 +270,26 @@ function* TIntersect(schema, references, path, value) {
|
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
|
-
function*
|
|
273
|
+
function* FromIterator(schema, references, path, value) {
|
|
274
274
|
if (!IsIterator(value))
|
|
275
275
|
yield Create(ValueErrorType.Iterator, schema, path, value);
|
|
276
276
|
}
|
|
277
|
-
function*
|
|
277
|
+
function* FromLiteral(schema, references, path, value) {
|
|
278
278
|
if (!(value === schema.const))
|
|
279
279
|
yield Create(ValueErrorType.Literal, schema, path, value);
|
|
280
280
|
}
|
|
281
|
-
function*
|
|
281
|
+
function* FromNever(schema, references, path, value) {
|
|
282
282
|
yield Create(ValueErrorType.Never, schema, path, value);
|
|
283
283
|
}
|
|
284
|
-
function*
|
|
284
|
+
function* FromNot(schema, references, path, value) {
|
|
285
285
|
if (Visit(schema.not, references, path, value).next().done === true)
|
|
286
286
|
yield Create(ValueErrorType.Not, schema, path, value);
|
|
287
287
|
}
|
|
288
|
-
function*
|
|
288
|
+
function* FromNull(schema, references, path, value) {
|
|
289
289
|
if (!IsNull(value))
|
|
290
290
|
yield Create(ValueErrorType.Null, schema, path, value);
|
|
291
291
|
}
|
|
292
|
-
function*
|
|
292
|
+
function* FromNumber(schema, references, path, value) {
|
|
293
293
|
if (!TypeSystemPolicy.IsNumberLike(value))
|
|
294
294
|
return yield Create(ValueErrorType.Number, schema, path, value);
|
|
295
295
|
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
@@ -308,7 +308,7 @@ function* TNumber(schema, references, path, value) {
|
|
|
308
308
|
yield Create(ValueErrorType.NumberMultipleOf, schema, path, value);
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
|
-
function*
|
|
311
|
+
function* FromObject(schema, references, path, value) {
|
|
312
312
|
if (!TypeSystemPolicy.IsObjectLike(value))
|
|
313
313
|
return yield Create(ValueErrorType.Object, schema, path, value);
|
|
314
314
|
if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
@@ -354,11 +354,11 @@ function* TObject(schema, references, path, value) {
|
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
|
-
function*
|
|
357
|
+
function* FromPromise(schema, references, path, value) {
|
|
358
358
|
if (!IsPromise(value))
|
|
359
359
|
yield Create(ValueErrorType.Promise, schema, path, value);
|
|
360
360
|
}
|
|
361
|
-
function*
|
|
361
|
+
function* FromRecord(schema, references, path, value) {
|
|
362
362
|
if (!TypeSystemPolicy.IsRecordLike(value))
|
|
363
363
|
return yield Create(ValueErrorType.Object, schema, path, value);
|
|
364
364
|
if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
@@ -387,10 +387,10 @@ function* TRecord(schema, references, path, value) {
|
|
|
387
387
|
}
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
|
-
function*
|
|
390
|
+
function* FromRef(schema, references, path, value) {
|
|
391
391
|
yield* Visit(Deref(schema, references), references, path, value);
|
|
392
392
|
}
|
|
393
|
-
function*
|
|
393
|
+
function* FromString(schema, references, path, value) {
|
|
394
394
|
if (!IsString(value))
|
|
395
395
|
return yield Create(ValueErrorType.String, schema, path, value);
|
|
396
396
|
if (IsDefined(schema.minLength) && !(value.length >= schema.minLength)) {
|
|
@@ -417,11 +417,11 @@ function* TString(schema, references, path, value) {
|
|
|
417
417
|
}
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
|
-
function*
|
|
420
|
+
function* FromSymbol(schema, references, path, value) {
|
|
421
421
|
if (!IsSymbol(value))
|
|
422
422
|
yield Create(ValueErrorType.Symbol, schema, path, value);
|
|
423
423
|
}
|
|
424
|
-
function*
|
|
424
|
+
function* FromTemplateLiteral(schema, references, path, value) {
|
|
425
425
|
if (!IsString(value))
|
|
426
426
|
return yield Create(ValueErrorType.String, schema, path, value);
|
|
427
427
|
const regex = new RegExp(schema.pattern);
|
|
@@ -429,10 +429,10 @@ function* TTemplateLiteral(schema, references, path, value) {
|
|
|
429
429
|
yield Create(ValueErrorType.StringPattern, schema, path, value);
|
|
430
430
|
}
|
|
431
431
|
}
|
|
432
|
-
function*
|
|
432
|
+
function* FromThis(schema, references, path, value) {
|
|
433
433
|
yield* Visit(Deref(schema, references), references, path, value);
|
|
434
434
|
}
|
|
435
|
-
function*
|
|
435
|
+
function* FromTuple(schema, references, path, value) {
|
|
436
436
|
if (!IsArray(value))
|
|
437
437
|
return yield Create(ValueErrorType.Tuple, schema, path, value);
|
|
438
438
|
if (schema.items === undefined && !(value.length === 0)) {
|
|
@@ -448,11 +448,11 @@ function* TTuple(schema, references, path, value) {
|
|
|
448
448
|
yield* Visit(schema.items[i], references, `${path}/${i}`, value[i]);
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
|
-
function*
|
|
451
|
+
function* FromUndefined(schema, references, path, value) {
|
|
452
452
|
if (!IsUndefined(value))
|
|
453
453
|
yield Create(ValueErrorType.Undefined, schema, path, value);
|
|
454
454
|
}
|
|
455
|
-
function*
|
|
455
|
+
function* FromUnion(schema, references, path, value) {
|
|
456
456
|
let count = 0;
|
|
457
457
|
for (const subschema of schema.anyOf) {
|
|
458
458
|
const errors = [...Visit(subschema, references, path, value)];
|
|
@@ -464,7 +464,7 @@ function* TUnion(schema, references, path, value) {
|
|
|
464
464
|
yield Create(ValueErrorType.Union, schema, path, value);
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
|
-
function*
|
|
467
|
+
function* FromUint8Array(schema, references, path, value) {
|
|
468
468
|
if (!IsUint8Array(value))
|
|
469
469
|
return yield Create(ValueErrorType.Uint8Array, schema, path, value);
|
|
470
470
|
if (IsDefined(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
|
|
@@ -474,12 +474,12 @@ function* TUint8Array(schema, references, path, value) {
|
|
|
474
474
|
yield Create(ValueErrorType.Uint8ArrayMinByteLength, schema, path, value);
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
|
-
function*
|
|
478
|
-
function*
|
|
477
|
+
function* FromUnknown(schema, references, path, value) { }
|
|
478
|
+
function* FromVoid(schema, references, path, value) {
|
|
479
479
|
if (!TypeSystemPolicy.IsVoidLike(value))
|
|
480
480
|
yield Create(ValueErrorType.Void, schema, path, value);
|
|
481
481
|
}
|
|
482
|
-
function*
|
|
482
|
+
function* FromKind(schema, references, path, value) {
|
|
483
483
|
const check = TypeRegistry.Get(schema[Kind]);
|
|
484
484
|
if (!check(schema, value))
|
|
485
485
|
yield Create(ValueErrorType.Kind, schema, path, value);
|
|
@@ -489,69 +489,69 @@ function* Visit(schema, references, path, value) {
|
|
|
489
489
|
const schema_ = schema;
|
|
490
490
|
switch (schema_[Kind]) {
|
|
491
491
|
case 'Any':
|
|
492
|
-
return yield*
|
|
492
|
+
return yield* FromAny(schema_, references_, path, value);
|
|
493
493
|
case 'Array':
|
|
494
|
-
return yield*
|
|
494
|
+
return yield* FromArray(schema_, references_, path, value);
|
|
495
495
|
case 'AsyncIterator':
|
|
496
|
-
return yield*
|
|
496
|
+
return yield* FromAsyncIterator(schema_, references_, path, value);
|
|
497
497
|
case 'BigInt':
|
|
498
|
-
return yield*
|
|
498
|
+
return yield* FromBigInt(schema_, references_, path, value);
|
|
499
499
|
case 'Boolean':
|
|
500
|
-
return yield*
|
|
500
|
+
return yield* FromBoolean(schema_, references_, path, value);
|
|
501
501
|
case 'Constructor':
|
|
502
|
-
return yield*
|
|
502
|
+
return yield* FromConstructor(schema_, references_, path, value);
|
|
503
503
|
case 'Date':
|
|
504
|
-
return yield*
|
|
504
|
+
return yield* FromDate(schema_, references_, path, value);
|
|
505
505
|
case 'Function':
|
|
506
|
-
return yield*
|
|
506
|
+
return yield* FromFunction(schema_, references_, path, value);
|
|
507
507
|
case 'Integer':
|
|
508
|
-
return yield*
|
|
508
|
+
return yield* FromInteger(schema_, references_, path, value);
|
|
509
509
|
case 'Intersect':
|
|
510
|
-
return yield*
|
|
510
|
+
return yield* FromIntersect(schema_, references_, path, value);
|
|
511
511
|
case 'Iterator':
|
|
512
|
-
return yield*
|
|
512
|
+
return yield* FromIterator(schema_, references_, path, value);
|
|
513
513
|
case 'Literal':
|
|
514
|
-
return yield*
|
|
514
|
+
return yield* FromLiteral(schema_, references_, path, value);
|
|
515
515
|
case 'Never':
|
|
516
|
-
return yield*
|
|
516
|
+
return yield* FromNever(schema_, references_, path, value);
|
|
517
517
|
case 'Not':
|
|
518
|
-
return yield*
|
|
518
|
+
return yield* FromNot(schema_, references_, path, value);
|
|
519
519
|
case 'Null':
|
|
520
|
-
return yield*
|
|
520
|
+
return yield* FromNull(schema_, references_, path, value);
|
|
521
521
|
case 'Number':
|
|
522
|
-
return yield*
|
|
522
|
+
return yield* FromNumber(schema_, references_, path, value);
|
|
523
523
|
case 'Object':
|
|
524
|
-
return yield*
|
|
524
|
+
return yield* FromObject(schema_, references_, path, value);
|
|
525
525
|
case 'Promise':
|
|
526
|
-
return yield*
|
|
526
|
+
return yield* FromPromise(schema_, references_, path, value);
|
|
527
527
|
case 'Record':
|
|
528
|
-
return yield*
|
|
528
|
+
return yield* FromRecord(schema_, references_, path, value);
|
|
529
529
|
case 'Ref':
|
|
530
|
-
return yield*
|
|
530
|
+
return yield* FromRef(schema_, references_, path, value);
|
|
531
531
|
case 'String':
|
|
532
|
-
return yield*
|
|
532
|
+
return yield* FromString(schema_, references_, path, value);
|
|
533
533
|
case 'Symbol':
|
|
534
|
-
return yield*
|
|
534
|
+
return yield* FromSymbol(schema_, references_, path, value);
|
|
535
535
|
case 'TemplateLiteral':
|
|
536
|
-
return yield*
|
|
536
|
+
return yield* FromTemplateLiteral(schema_, references_, path, value);
|
|
537
537
|
case 'This':
|
|
538
|
-
return yield*
|
|
538
|
+
return yield* FromThis(schema_, references_, path, value);
|
|
539
539
|
case 'Tuple':
|
|
540
|
-
return yield*
|
|
540
|
+
return yield* FromTuple(schema_, references_, path, value);
|
|
541
541
|
case 'Undefined':
|
|
542
|
-
return yield*
|
|
542
|
+
return yield* FromUndefined(schema_, references_, path, value);
|
|
543
543
|
case 'Union':
|
|
544
|
-
return yield*
|
|
544
|
+
return yield* FromUnion(schema_, references_, path, value);
|
|
545
545
|
case 'Uint8Array':
|
|
546
|
-
return yield*
|
|
546
|
+
return yield* FromUint8Array(schema_, references_, path, value);
|
|
547
547
|
case 'Unknown':
|
|
548
|
-
return yield*
|
|
548
|
+
return yield* FromUnknown(schema_, references_, path, value);
|
|
549
549
|
case 'Void':
|
|
550
|
-
return yield*
|
|
550
|
+
return yield* FromVoid(schema_, references_, path, value);
|
|
551
551
|
default:
|
|
552
552
|
if (!TypeRegistry.Has(schema_[Kind]))
|
|
553
553
|
throw new ValueErrorsUnknownTypeError(schema);
|
|
554
|
-
return yield*
|
|
554
|
+
return yield* FromKind(schema_, references_, path, value);
|
|
555
555
|
}
|
|
556
556
|
}
|
|
557
557
|
/** Returns an iterator for each error in this value. */
|
package/build/import/index.d.mts
CHANGED
|
@@ -7,7 +7,7 @@ export { Any, type TAny } from './type/any/index.mjs';
|
|
|
7
7
|
export { Array, type TArray, type ArrayOptions } from './type/array/index.mjs';
|
|
8
8
|
export { AsyncIterator, type TAsyncIterator } from './type/async-iterator/index.mjs';
|
|
9
9
|
export { Awaited, type TAwaited } from './type/awaited/index.mjs';
|
|
10
|
-
export { BigInt, type TBigInt, BigIntOptions } from './type/bigint/index.mjs';
|
|
10
|
+
export { BigInt, type TBigInt, type BigIntOptions } from './type/bigint/index.mjs';
|
|
11
11
|
export { Boolean, type TBoolean } from './type/boolean/index.mjs';
|
|
12
12
|
export { Composite, type TComposite } from './type/composite/index.mjs';
|
|
13
13
|
export { Const, type TConst } from './type/const/index.mjs';
|
|
@@ -36,12 +36,12 @@ export { Null, type TNull } from './type/null/index.mjs';
|
|
|
36
36
|
export { Number, type TNumber, type NumberOptions } from './type/number/index.mjs';
|
|
37
37
|
export { Object, type TObject, type TProperties, type ObjectOptions } from './type/object/index.mjs';
|
|
38
38
|
export { Omit, type TOmit, type TOmitFromMappedKey } from './type/omit/index.mjs';
|
|
39
|
-
export { Optional, type TOptional } from './type/optional/index.mjs';
|
|
39
|
+
export { Optional, OptionalFromMappedResult, type TOptional, type TOptionalWithFlag, type TOptionalFromMappedResult } from './type/optional/index.mjs';
|
|
40
40
|
export { Parameters, type TParameters } from './type/parameters/index.mjs';
|
|
41
41
|
export { Partial, PartialFromMappedResult, type TPartial, type TPartialFromMappedResult } from './type/partial/index.mjs';
|
|
42
42
|
export { Pick, type TPick, type TPickFromMappedKey } from './type/pick/index.mjs';
|
|
43
43
|
export { Promise, type TPromise } from './type/promise/index.mjs';
|
|
44
|
-
export { Readonly, type TReadonly } from './type/readonly/index.mjs';
|
|
44
|
+
export { Readonly, ReadonlyFromMappedResult, type TReadonly, type TReadonlyWithFlag, type TReadonlyFromMappedResult } from './type/readonly/index.mjs';
|
|
45
45
|
export { ReadonlyOptional, type TReadonlyOptional } from './type/readonly-optional/index.mjs';
|
|
46
46
|
export { Record, type TRecord } from './type/record/index.mjs';
|
|
47
47
|
export { Recursive, type TRecursive, type TThis } from './type/recursive/index.mjs';
|
|
@@ -54,9 +54,9 @@ export { type TSchema, type TKind, type SchemaOptions, type TAnySchema } from '.
|
|
|
54
54
|
export { type Static, type StaticDecode, type StaticEncode } from './type/static/index.mjs';
|
|
55
55
|
export { Strict } from './type/strict/index.mjs';
|
|
56
56
|
export { String, type TString, type StringOptions, type StringFormatOption, type StringContentEncodingOption } from './type/string/index.mjs';
|
|
57
|
-
export { Symbol, type TSymbol, type SymbolValue } from './type/symbol/index.mjs';
|
|
58
|
-
export { TemplateLiteral, IsTemplateLiteralFinite, TemplateLiteralParse, TemplateLiteralParseExact, TemplateLiteralGenerate, type TTemplateLiteral, type TTemplateLiteralKind } from './type/template-literal/index.mjs';
|
|
59
|
-
export { Transform, type TTransform, type TransformOptions, type TransformFunction
|
|
57
|
+
export { Symbol, type TSymbol, type TSymbolValue as SymbolValue } from './type/symbol/index.mjs';
|
|
58
|
+
export { TemplateLiteral, IsTemplateLiteralFinite, IsTemplateLiteralExpressionFinite, TemplateLiteralParse, TemplateLiteralParseExact, TemplateLiteralGenerate, TemplateLiteralExpressionGenerate, type TTemplateLiteral, type TIsTemplateLiteralFinite, type TTemplateLiteralGenerate, type TTemplateLiteralKind, } from './type/template-literal/index.mjs';
|
|
59
|
+
export { Transform, TransformDecodeBuilder, TransformEncodeBuilder, type TTransform, type TransformOptions, type TransformFunction } from './type/transform/index.mjs';
|
|
60
60
|
export { Tuple, type TTuple } from './type/tuple/index.mjs';
|
|
61
61
|
export { Uint8Array, type TUint8Array, type Uint8ArrayOptions } from './type/uint8array/index.mjs';
|
|
62
62
|
export { Undefined, type TUndefined } from './type/undefined/index.mjs';
|