@sinclair/typebox 0.32.0-dev-23 → 0.32.0-dev-25
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.d.mts +3 -2
- package/build/import/compiler/compiler.mjs +3 -2
- package/build/import/errors/errors.d.mts +2 -1
- package/build/import/errors/errors.mjs +2 -1
- package/build/import/index.d.mts +2 -1
- package/build/import/index.mjs +2 -1
- package/build/import/system/system.d.mts +3 -2
- package/build/import/system/system.mjs +3 -2
- package/build/import/type/error/error.d.mts +4 -0
- package/build/import/type/error/error.mjs +6 -0
- package/build/import/type/error/index.d.mts +1 -0
- package/build/import/type/error/index.mjs +1 -0
- package/build/import/type/extends/extends-check.d.mts +2 -1
- package/build/import/type/extends/extends-check.mjs +2 -1
- package/build/import/type/guard/type.d.mts +2 -1
- package/build/import/type/guard/type.mjs +2 -1
- package/build/import/type/index.d.mts +1 -0
- package/build/import/type/index.mjs +1 -0
- package/build/import/type/indexed/index.d.mts +1 -0
- package/build/import/type/indexed/index.mjs +1 -0
- package/build/import/type/indexed/indexed-from-mapped-result.d.mts +12 -0
- package/build/import/type/indexed/indexed-from-mapped-result.mjs +18 -0
- package/build/import/type/indexed/indexed.d.mts +4 -1
- package/build/import/type/indexed/indexed.mjs +6 -5
- package/build/import/type/record/record.d.mts +1 -1
- package/build/import/type/template-literal/finite.d.mts +2 -1
- package/build/import/type/template-literal/finite.mjs +2 -1
- package/build/import/type/template-literal/generate.d.mts +2 -1
- package/build/import/type/template-literal/generate.mjs +2 -1
- package/build/import/type/template-literal/parse.d.mts +2 -1
- package/build/import/type/template-literal/parse.mjs +2 -1
- package/build/import/type/template-literal/pattern.d.mts +2 -1
- package/build/import/type/template-literal/pattern.mjs +2 -1
- package/build/import/type/type/json.d.mts +3 -1
- package/build/import/value/cast/cast.d.mts +5 -4
- package/build/import/value/cast/cast.mjs +5 -4
- package/build/import/value/check/check.d.mts +2 -1
- package/build/import/value/check/check.mjs +2 -1
- package/build/import/value/convert/convert.d.mts +2 -1
- package/build/import/value/convert/convert.mjs +2 -1
- package/build/import/value/create/create.d.mts +7 -6
- package/build/import/value/create/create.mjs +7 -6
- package/build/import/value/delta/delta.d.mts +3 -2
- package/build/import/value/delta/delta.mjs +3 -2
- package/build/import/value/deref/deref.d.mts +2 -1
- package/build/import/value/deref/deref.mjs +2 -1
- package/build/import/value/hash/hash.d.mts +2 -1
- package/build/import/value/hash/hash.mjs +2 -1
- package/build/import/value/mutate/mutate.d.mts +3 -2
- package/build/import/value/mutate/mutate.mjs +3 -2
- package/build/import/value/pointer/pointer.d.mts +3 -2
- package/build/import/value/pointer/pointer.mjs +3 -2
- package/build/import/value/transform/decode.d.mts +3 -2
- package/build/import/value/transform/decode.mjs +3 -2
- package/build/import/value/transform/encode.d.mts +3 -2
- package/build/import/value/transform/encode.mjs +3 -2
- package/build/require/compiler/compiler.d.ts +3 -2
- package/build/require/compiler/compiler.js +61 -60
- package/build/require/errors/errors.d.ts +2 -1
- package/build/require/errors/errors.js +34 -33
- package/build/require/index.d.ts +2 -1
- package/build/require/index.js +155 -152
- package/build/require/system/system.d.ts +3 -2
- package/build/require/system/system.js +3 -2
- package/build/require/type/error/error.d.ts +4 -0
- package/build/require/type/error/error.js +11 -0
- package/build/require/type/error/index.d.ts +1 -0
- package/build/require/type/error/index.js +18 -0
- package/build/require/type/extends/extends-check.d.ts +2 -1
- package/build/require/type/extends/extends-check.js +172 -171
- package/build/require/type/guard/type.d.ts +2 -1
- package/build/require/type/guard/type.js +2 -1
- package/build/require/type/index.d.ts +1 -0
- package/build/require/type/index.js +1 -0
- package/build/require/type/indexed/index.d.ts +1 -0
- package/build/require/type/indexed/index.js +1 -0
- package/build/require/type/indexed/indexed-from-mapped-result.d.ts +12 -0
- package/build/require/type/indexed/indexed-from-mapped-result.js +23 -0
- package/build/require/type/indexed/indexed.d.ts +4 -1
- package/build/require/type/indexed/indexed.js +5 -4
- package/build/require/type/record/record.d.ts +1 -1
- package/build/require/type/template-literal/finite.d.ts +2 -1
- package/build/require/type/template-literal/finite.js +2 -1
- package/build/require/type/template-literal/generate.d.ts +2 -1
- package/build/require/type/template-literal/generate.js +2 -1
- package/build/require/type/template-literal/parse.d.ts +2 -1
- package/build/require/type/template-literal/parse.js +3 -2
- package/build/require/type/template-literal/pattern.d.ts +2 -1
- package/build/require/type/template-literal/pattern.js +2 -1
- package/build/require/type/type/json.d.ts +3 -1
- package/build/require/value/cast/cast.d.ts +5 -4
- package/build/require/value/cast/cast.js +36 -35
- package/build/require/value/check/check.d.ts +2 -1
- package/build/require/value/check/check.js +24 -23
- package/build/require/value/convert/convert.d.ts +2 -1
- package/build/require/value/convert/convert.js +32 -31
- package/build/require/value/create/create.d.ts +7 -6
- package/build/require/value/create/create.js +7 -6
- package/build/require/value/delta/delta.d.ts +3 -2
- package/build/require/value/delta/delta.js +20 -19
- package/build/require/value/deref/deref.d.ts +2 -1
- package/build/require/value/deref/deref.js +2 -1
- package/build/require/value/hash/hash.d.ts +2 -1
- package/build/require/value/hash/hash.js +2 -1
- package/build/require/value/mutate/mutate.d.ts +3 -2
- package/build/require/value/mutate/mutate.js +3 -2
- package/build/require/value/pointer/pointer.d.ts +3 -2
- package/build/require/value/pointer/pointer.js +3 -2
- package/build/require/value/transform/decode.d.ts +3 -2
- package/build/require/value/transform/decode.js +19 -18
- package/build/require/value/transform/encode.d.ts +3 -2
- package/build/require/value/transform/encode.js +20 -19
- package/package.json +1 -1
- package/readme.md +117 -137
|
@@ -7,15 +7,16 @@ const index_2 = require("../type/keyof/index");
|
|
|
7
7
|
const index_3 = require("../type/registry/index");
|
|
8
8
|
const extends_undefined_1 = require("../type/extends/extends-undefined");
|
|
9
9
|
const function_1 = require("./function");
|
|
10
|
-
const index_4 = require("../
|
|
11
|
-
const index_5 = require("../value/
|
|
12
|
-
const index_6 = require("../
|
|
13
|
-
const index_7 = require("../type/
|
|
10
|
+
const index_4 = require("../type/error/index");
|
|
11
|
+
const index_5 = require("../value/deref/index");
|
|
12
|
+
const index_6 = require("../value/hash/index");
|
|
13
|
+
const index_7 = require("../type/symbols/index");
|
|
14
|
+
const index_8 = require("../type/never/index");
|
|
14
15
|
// ------------------------------------------------------------------
|
|
15
16
|
// ValueGuard
|
|
16
17
|
// ------------------------------------------------------------------
|
|
17
18
|
// prettier-ignore
|
|
18
|
-
const
|
|
19
|
+
const index_9 = require("../value/guard/index");
|
|
19
20
|
// ------------------------------------------------------------------
|
|
20
21
|
// ValueErrorType
|
|
21
22
|
// ------------------------------------------------------------------
|
|
@@ -88,7 +89,7 @@ var ValueErrorType;
|
|
|
88
89
|
// ------------------------------------------------------------------
|
|
89
90
|
// ValueErrors
|
|
90
91
|
// ------------------------------------------------------------------
|
|
91
|
-
class ValueErrorsUnknownTypeError extends
|
|
92
|
+
class ValueErrorsUnknownTypeError extends index_4.TypeBoxError {
|
|
92
93
|
constructor(schema) {
|
|
93
94
|
super('Unknown type');
|
|
94
95
|
this.schema = schema;
|
|
@@ -135,7 +136,7 @@ function Create(type, schema, path, value) {
|
|
|
135
136
|
// --------------------------------------------------------------------------
|
|
136
137
|
function* FromAny(schema, references, path, value) { }
|
|
137
138
|
function* FromArray(schema, references, path, value) {
|
|
138
|
-
if (!(0,
|
|
139
|
+
if (!(0, index_9.IsArray)(value)) {
|
|
139
140
|
return yield Create(ValueErrorType.Array, schema, path, value);
|
|
140
141
|
}
|
|
141
142
|
if (IsDefined(schema.minItems) && !(value.length >= schema.minItems)) {
|
|
@@ -149,7 +150,7 @@ function* FromArray(schema, references, path, value) {
|
|
|
149
150
|
}
|
|
150
151
|
// prettier-ignore
|
|
151
152
|
if (schema.uniqueItems === true && !((function () { const set = new Set(); for (const element of value) {
|
|
152
|
-
const hashed = (0,
|
|
153
|
+
const hashed = (0, index_6.Hash)(element);
|
|
153
154
|
if (set.has(hashed)) {
|
|
154
155
|
return false;
|
|
155
156
|
}
|
|
@@ -163,24 +164,24 @@ function* FromArray(schema, references, path, value) {
|
|
|
163
164
|
if (!(IsDefined(schema.contains) || IsDefined(schema.minContains) || IsDefined(schema.maxContains))) {
|
|
164
165
|
return;
|
|
165
166
|
}
|
|
166
|
-
const containsSchema = IsDefined(schema.contains) ? schema.contains : (0,
|
|
167
|
+
const containsSchema = IsDefined(schema.contains) ? schema.contains : (0, index_8.Never)();
|
|
167
168
|
const containsCount = value.reduce((acc, value, index) => (Visit(containsSchema, references, `${path}${index}`, value).next().done === true ? acc + 1 : acc), 0);
|
|
168
169
|
if (containsCount === 0) {
|
|
169
170
|
yield Create(ValueErrorType.ArrayContains, schema, path, value);
|
|
170
171
|
}
|
|
171
|
-
if ((0,
|
|
172
|
+
if ((0, index_9.IsNumber)(schema.minContains) && containsCount < schema.minContains) {
|
|
172
173
|
yield Create(ValueErrorType.ArrayMinContains, schema, path, value);
|
|
173
174
|
}
|
|
174
|
-
if ((0,
|
|
175
|
+
if ((0, index_9.IsNumber)(schema.maxContains) && containsCount > schema.maxContains) {
|
|
175
176
|
yield Create(ValueErrorType.ArrayMaxContains, schema, path, value);
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
179
|
function* FromAsyncIterator(schema, references, path, value) {
|
|
179
|
-
if (!(0,
|
|
180
|
+
if (!(0, index_9.IsAsyncIterator)(value))
|
|
180
181
|
yield Create(ValueErrorType.AsyncIterator, schema, path, value);
|
|
181
182
|
}
|
|
182
183
|
function* FromBigInt(schema, references, path, value) {
|
|
183
|
-
if (!(0,
|
|
184
|
+
if (!(0, index_9.IsBigInt)(value))
|
|
184
185
|
return yield Create(ValueErrorType.BigInt, schema, path, value);
|
|
185
186
|
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
186
187
|
yield Create(ValueErrorType.BigIntExclusiveMaximum, schema, path, value);
|
|
@@ -199,14 +200,14 @@ function* FromBigInt(schema, references, path, value) {
|
|
|
199
200
|
}
|
|
200
201
|
}
|
|
201
202
|
function* FromBoolean(schema, references, path, value) {
|
|
202
|
-
if (!(0,
|
|
203
|
+
if (!(0, index_9.IsBoolean)(value))
|
|
203
204
|
yield Create(ValueErrorType.Boolean, schema, path, value);
|
|
204
205
|
}
|
|
205
206
|
function* FromConstructor(schema, references, path, value) {
|
|
206
207
|
yield* Visit(schema.returns, references, path, value.prototype);
|
|
207
208
|
}
|
|
208
209
|
function* FromDate(schema, references, path, value) {
|
|
209
|
-
if (!(0,
|
|
210
|
+
if (!(0, index_9.IsDate)(value))
|
|
210
211
|
return yield Create(ValueErrorType.Date, schema, path, value);
|
|
211
212
|
if (IsDefined(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
212
213
|
yield Create(ValueErrorType.DateExclusiveMaximumTimestamp, schema, path, value);
|
|
@@ -225,11 +226,11 @@ function* FromDate(schema, references, path, value) {
|
|
|
225
226
|
}
|
|
226
227
|
}
|
|
227
228
|
function* FromFunction(schema, references, path, value) {
|
|
228
|
-
if (!(0,
|
|
229
|
+
if (!(0, index_9.IsFunction)(value))
|
|
229
230
|
yield Create(ValueErrorType.Function, schema, path, value);
|
|
230
231
|
}
|
|
231
232
|
function* FromInteger(schema, references, path, value) {
|
|
232
|
-
if (!(0,
|
|
233
|
+
if (!(0, index_9.IsInteger)(value))
|
|
233
234
|
return yield Create(ValueErrorType.Integer, schema, path, value);
|
|
234
235
|
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
235
236
|
yield Create(ValueErrorType.IntegerExclusiveMaximum, schema, path, value);
|
|
@@ -275,7 +276,7 @@ function* FromIntersect(schema, references, path, value) {
|
|
|
275
276
|
}
|
|
276
277
|
}
|
|
277
278
|
function* FromIterator(schema, references, path, value) {
|
|
278
|
-
if (!(0,
|
|
279
|
+
if (!(0, index_9.IsIterator)(value))
|
|
279
280
|
yield Create(ValueErrorType.Iterator, schema, path, value);
|
|
280
281
|
}
|
|
281
282
|
function* FromLiteral(schema, references, path, value) {
|
|
@@ -290,7 +291,7 @@ function* FromNot(schema, references, path, value) {
|
|
|
290
291
|
yield Create(ValueErrorType.Not, schema, path, value);
|
|
291
292
|
}
|
|
292
293
|
function* FromNull(schema, references, path, value) {
|
|
293
|
-
if (!(0,
|
|
294
|
+
if (!(0, index_9.IsNull)(value))
|
|
294
295
|
yield Create(ValueErrorType.Null, schema, path, value);
|
|
295
296
|
}
|
|
296
297
|
function* FromNumber(schema, references, path, value) {
|
|
@@ -359,7 +360,7 @@ function* FromObject(schema, references, path, value) {
|
|
|
359
360
|
}
|
|
360
361
|
}
|
|
361
362
|
function* FromPromise(schema, references, path, value) {
|
|
362
|
-
if (!(0,
|
|
363
|
+
if (!(0, index_9.IsPromise)(value))
|
|
363
364
|
yield Create(ValueErrorType.Promise, schema, path, value);
|
|
364
365
|
}
|
|
365
366
|
function* FromRecord(schema, references, path, value) {
|
|
@@ -392,10 +393,10 @@ function* FromRecord(schema, references, path, value) {
|
|
|
392
393
|
}
|
|
393
394
|
}
|
|
394
395
|
function* FromRef(schema, references, path, value) {
|
|
395
|
-
yield* Visit((0,
|
|
396
|
+
yield* Visit((0, index_5.Deref)(schema, references), references, path, value);
|
|
396
397
|
}
|
|
397
398
|
function* FromString(schema, references, path, value) {
|
|
398
|
-
if (!(0,
|
|
399
|
+
if (!(0, index_9.IsString)(value))
|
|
399
400
|
return yield Create(ValueErrorType.String, schema, path, value);
|
|
400
401
|
if (IsDefined(schema.minLength) && !(value.length >= schema.minLength)) {
|
|
401
402
|
yield Create(ValueErrorType.StringMinLength, schema, path, value);
|
|
@@ -403,13 +404,13 @@ function* FromString(schema, references, path, value) {
|
|
|
403
404
|
if (IsDefined(schema.maxLength) && !(value.length <= schema.maxLength)) {
|
|
404
405
|
yield Create(ValueErrorType.StringMaxLength, schema, path, value);
|
|
405
406
|
}
|
|
406
|
-
if ((0,
|
|
407
|
+
if ((0, index_9.IsString)(schema.pattern)) {
|
|
407
408
|
const regex = new RegExp(schema.pattern);
|
|
408
409
|
if (!regex.test(value)) {
|
|
409
410
|
yield Create(ValueErrorType.StringPattern, schema, path, value);
|
|
410
411
|
}
|
|
411
412
|
}
|
|
412
|
-
if ((0,
|
|
413
|
+
if ((0, index_9.IsString)(schema.format)) {
|
|
413
414
|
if (!index_3.FormatRegistry.Has(schema.format)) {
|
|
414
415
|
yield Create(ValueErrorType.StringFormatUnknown, schema, path, value);
|
|
415
416
|
}
|
|
@@ -422,11 +423,11 @@ function* FromString(schema, references, path, value) {
|
|
|
422
423
|
}
|
|
423
424
|
}
|
|
424
425
|
function* FromSymbol(schema, references, path, value) {
|
|
425
|
-
if (!(0,
|
|
426
|
+
if (!(0, index_9.IsSymbol)(value))
|
|
426
427
|
yield Create(ValueErrorType.Symbol, schema, path, value);
|
|
427
428
|
}
|
|
428
429
|
function* FromTemplateLiteral(schema, references, path, value) {
|
|
429
|
-
if (!(0,
|
|
430
|
+
if (!(0, index_9.IsString)(value))
|
|
430
431
|
return yield Create(ValueErrorType.String, schema, path, value);
|
|
431
432
|
const regex = new RegExp(schema.pattern);
|
|
432
433
|
if (!regex.test(value)) {
|
|
@@ -434,10 +435,10 @@ function* FromTemplateLiteral(schema, references, path, value) {
|
|
|
434
435
|
}
|
|
435
436
|
}
|
|
436
437
|
function* FromThis(schema, references, path, value) {
|
|
437
|
-
yield* Visit((0,
|
|
438
|
+
yield* Visit((0, index_5.Deref)(schema, references), references, path, value);
|
|
438
439
|
}
|
|
439
440
|
function* FromTuple(schema, references, path, value) {
|
|
440
|
-
if (!(0,
|
|
441
|
+
if (!(0, index_9.IsArray)(value))
|
|
441
442
|
return yield Create(ValueErrorType.Tuple, schema, path, value);
|
|
442
443
|
if (schema.items === undefined && !(value.length === 0)) {
|
|
443
444
|
return yield Create(ValueErrorType.TupleLength, schema, path, value);
|
|
@@ -453,7 +454,7 @@ function* FromTuple(schema, references, path, value) {
|
|
|
453
454
|
}
|
|
454
455
|
}
|
|
455
456
|
function* FromUndefined(schema, references, path, value) {
|
|
456
|
-
if (!(0,
|
|
457
|
+
if (!(0, index_9.IsUndefined)(value))
|
|
457
458
|
yield Create(ValueErrorType.Undefined, schema, path, value);
|
|
458
459
|
}
|
|
459
460
|
function* FromUnion(schema, references, path, value) {
|
|
@@ -469,7 +470,7 @@ function* FromUnion(schema, references, path, value) {
|
|
|
469
470
|
}
|
|
470
471
|
}
|
|
471
472
|
function* FromUint8Array(schema, references, path, value) {
|
|
472
|
-
if (!(0,
|
|
473
|
+
if (!(0, index_9.IsUint8Array)(value))
|
|
473
474
|
return yield Create(ValueErrorType.Uint8Array, schema, path, value);
|
|
474
475
|
if (IsDefined(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
|
|
475
476
|
yield Create(ValueErrorType.Uint8ArrayMaxByteLength, schema, path, value);
|
|
@@ -484,14 +485,14 @@ function* FromVoid(schema, references, path, value) {
|
|
|
484
485
|
yield Create(ValueErrorType.Void, schema, path, value);
|
|
485
486
|
}
|
|
486
487
|
function* FromKind(schema, references, path, value) {
|
|
487
|
-
const check = index_3.TypeRegistry.Get(schema[
|
|
488
|
+
const check = index_3.TypeRegistry.Get(schema[index_7.Kind]);
|
|
488
489
|
if (!check(schema, value))
|
|
489
490
|
yield Create(ValueErrorType.Kind, schema, path, value);
|
|
490
491
|
}
|
|
491
492
|
function* Visit(schema, references, path, value) {
|
|
492
493
|
const references_ = IsDefined(schema.$id) ? [...references, schema] : references;
|
|
493
494
|
const schema_ = schema;
|
|
494
|
-
switch (schema_[
|
|
495
|
+
switch (schema_[index_7.Kind]) {
|
|
495
496
|
case 'Any':
|
|
496
497
|
return yield* FromAny(schema_, references_, path, value);
|
|
497
498
|
case 'Array':
|
|
@@ -553,7 +554,7 @@ function* Visit(schema, references, path, value) {
|
|
|
553
554
|
case 'Void':
|
|
554
555
|
return yield* FromVoid(schema_, references_, path, value);
|
|
555
556
|
default:
|
|
556
|
-
if (!index_3.TypeRegistry.Has(schema_[
|
|
557
|
+
if (!index_3.TypeRegistry.Has(schema_[index_7.Kind]))
|
|
557
558
|
throw new ValueErrorsUnknownTypeError(schema);
|
|
558
559
|
return yield* FromKind(schema_, references_, path, value);
|
|
559
560
|
}
|
package/build/require/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { PatternBoolean, PatternBooleanExact, PatternNumber, PatternNumberExact,
|
|
|
3
3
|
export { TypeRegistry, FormatRegistry } from './type/registry/index';
|
|
4
4
|
export { TypeGuard, ValueGuard } from './type/guard/index';
|
|
5
5
|
export { CloneType, CloneRest } from './type/clone/type';
|
|
6
|
+
export { TypeBoxError } from './type/error/index';
|
|
6
7
|
export { Any, type TAny } from './type/any/index';
|
|
7
8
|
export { Array, type TArray, type ArrayOptions } from './type/array/index';
|
|
8
9
|
export { AsyncIterator, type TAsyncIterator } from './type/async-iterator/index';
|
|
@@ -21,7 +22,7 @@ export { Extends, type TExtends, type ExtendsFromMappedResult, type ExtendsFromM
|
|
|
21
22
|
export { Extract, type TExtract, type TExtractFromMappedResult } from './type/extract/index';
|
|
22
23
|
export { Function, type TFunction } from './type/function/index';
|
|
23
24
|
export { Increment, type Assert, type AssertType, type AssertRest, type AssertProperties, type Ensure, type Evaluate, type TupleToIntersect, type TupleToUnion, type UnionToTuple } from './type/helpers/index';
|
|
24
|
-
export { Index, IndexPropertyKeys, IndexFromMappedKey, type TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey } from './type/indexed/index';
|
|
25
|
+
export { Index, IndexPropertyKeys, IndexFromMappedKey, IndexFromMappedResult, type TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey, type TIndexFromMappedResult } from './type/indexed/index';
|
|
25
26
|
export { InstanceType, type TInstanceType } from './type/instance-type/index';
|
|
26
27
|
export { Integer, type TInteger, type IntegerOptions } from './type/integer/index';
|
|
27
28
|
export { Intersect, IntersectEvaluated, type TIntersect, type TIntersectEvaluated, type IntersectOptions } from './type/intersect/index';
|