@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
|
@@ -9,12 +9,13 @@ const index_4 = require("../../type/symbols/index");
|
|
|
9
9
|
const index_5 = require("../../type/keyof/index");
|
|
10
10
|
const index_6 = require("../../type/extends/index");
|
|
11
11
|
const index_7 = require("../../type/registry/index");
|
|
12
|
-
const index_8 = require("../../type/
|
|
12
|
+
const index_8 = require("../../type/error/index");
|
|
13
|
+
const index_9 = require("../../type/never/index");
|
|
13
14
|
// ------------------------------------------------------------------
|
|
14
15
|
// ValueGuard
|
|
15
16
|
// ------------------------------------------------------------------
|
|
16
17
|
// prettier-ignore
|
|
17
|
-
const
|
|
18
|
+
const index_10 = require("../guard/index");
|
|
18
19
|
// ------------------------------------------------------------------
|
|
19
20
|
// TypeGuard
|
|
20
21
|
// ------------------------------------------------------------------
|
|
@@ -22,7 +23,7 @@ const type_1 = require("../../type/guard/type");
|
|
|
22
23
|
// ------------------------------------------------------------------
|
|
23
24
|
// Errors
|
|
24
25
|
// ------------------------------------------------------------------
|
|
25
|
-
class ValueCheckUnknownTypeError extends
|
|
26
|
+
class ValueCheckUnknownTypeError extends index_8.TypeBoxError {
|
|
26
27
|
constructor(schema) {
|
|
27
28
|
super(`Unknown type`);
|
|
28
29
|
this.schema = schema;
|
|
@@ -48,7 +49,7 @@ function FromAny(schema, references, value) {
|
|
|
48
49
|
return true;
|
|
49
50
|
}
|
|
50
51
|
function FromArray(schema, references, value) {
|
|
51
|
-
if (!(0,
|
|
52
|
+
if (!(0, index_10.IsArray)(value))
|
|
52
53
|
return false;
|
|
53
54
|
if (IsDefined(schema.minItems) && !(value.length >= schema.minItems)) {
|
|
54
55
|
return false;
|
|
@@ -72,27 +73,27 @@ function FromArray(schema, references, value) {
|
|
|
72
73
|
return false;
|
|
73
74
|
}
|
|
74
75
|
// contains
|
|
75
|
-
if (!(IsDefined(schema.contains) || (0,
|
|
76
|
+
if (!(IsDefined(schema.contains) || (0, index_10.IsNumber)(schema.minContains) || (0, index_10.IsNumber)(schema.maxContains))) {
|
|
76
77
|
return true; // exit
|
|
77
78
|
}
|
|
78
|
-
const containsSchema = IsDefined(schema.contains) ? schema.contains : (0,
|
|
79
|
+
const containsSchema = IsDefined(schema.contains) ? schema.contains : (0, index_9.Never)();
|
|
79
80
|
const containsCount = value.reduce((acc, value) => (Visit(containsSchema, references, value) ? acc + 1 : acc), 0);
|
|
80
81
|
if (containsCount === 0) {
|
|
81
82
|
return false;
|
|
82
83
|
}
|
|
83
|
-
if ((0,
|
|
84
|
+
if ((0, index_10.IsNumber)(schema.minContains) && containsCount < schema.minContains) {
|
|
84
85
|
return false;
|
|
85
86
|
}
|
|
86
|
-
if ((0,
|
|
87
|
+
if ((0, index_10.IsNumber)(schema.maxContains) && containsCount > schema.maxContains) {
|
|
87
88
|
return false;
|
|
88
89
|
}
|
|
89
90
|
return true;
|
|
90
91
|
}
|
|
91
92
|
function FromAsyncIterator(schema, references, value) {
|
|
92
|
-
return (0,
|
|
93
|
+
return (0, index_10.IsAsyncIterator)(value);
|
|
93
94
|
}
|
|
94
95
|
function FromBigInt(schema, references, value) {
|
|
95
|
-
if (!(0,
|
|
96
|
+
if (!(0, index_10.IsBigInt)(value))
|
|
96
97
|
return false;
|
|
97
98
|
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
98
99
|
return false;
|
|
@@ -112,13 +113,13 @@ function FromBigInt(schema, references, value) {
|
|
|
112
113
|
return true;
|
|
113
114
|
}
|
|
114
115
|
function FromBoolean(schema, references, value) {
|
|
115
|
-
return (0,
|
|
116
|
+
return (0, index_10.IsBoolean)(value);
|
|
116
117
|
}
|
|
117
118
|
function FromConstructor(schema, references, value) {
|
|
118
119
|
return Visit(schema.returns, references, value.prototype);
|
|
119
120
|
}
|
|
120
121
|
function FromDate(schema, references, value) {
|
|
121
|
-
if (!(0,
|
|
122
|
+
if (!(0, index_10.IsDate)(value))
|
|
122
123
|
return false;
|
|
123
124
|
if (IsDefined(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
124
125
|
return false;
|
|
@@ -138,10 +139,10 @@ function FromDate(schema, references, value) {
|
|
|
138
139
|
return true;
|
|
139
140
|
}
|
|
140
141
|
function FromFunction(schema, references, value) {
|
|
141
|
-
return (0,
|
|
142
|
+
return (0, index_10.IsFunction)(value);
|
|
142
143
|
}
|
|
143
144
|
function FromInteger(schema, references, value) {
|
|
144
|
-
if (!(0,
|
|
145
|
+
if (!(0, index_10.IsInteger)(value)) {
|
|
145
146
|
return false;
|
|
146
147
|
}
|
|
147
148
|
if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
@@ -178,7 +179,7 @@ function FromIntersect(schema, references, value) {
|
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
181
|
function FromIterator(schema, references, value) {
|
|
181
|
-
return (0,
|
|
182
|
+
return (0, index_10.IsIterator)(value);
|
|
182
183
|
}
|
|
183
184
|
function FromLiteral(schema, references, value) {
|
|
184
185
|
return value === schema.const;
|
|
@@ -190,7 +191,7 @@ function FromNot(schema, references, value) {
|
|
|
190
191
|
return !Visit(schema.not, references, value);
|
|
191
192
|
}
|
|
192
193
|
function FromNull(schema, references, value) {
|
|
193
|
-
return (0,
|
|
194
|
+
return (0, index_10.IsNull)(value);
|
|
194
195
|
}
|
|
195
196
|
function FromNumber(schema, references, value) {
|
|
196
197
|
if (!index_1.TypeSystemPolicy.IsNumberLike(value))
|
|
@@ -257,7 +258,7 @@ function FromObject(schema, references, value) {
|
|
|
257
258
|
}
|
|
258
259
|
}
|
|
259
260
|
function FromPromise(schema, references, value) {
|
|
260
|
-
return (0,
|
|
261
|
+
return (0, index_10.IsPromise)(value);
|
|
261
262
|
}
|
|
262
263
|
function FromRecord(schema, references, value) {
|
|
263
264
|
if (!index_1.TypeSystemPolicy.IsRecordLike(value)) {
|
|
@@ -290,7 +291,7 @@ function FromRef(schema, references, value) {
|
|
|
290
291
|
return Visit((0, index_2.Deref)(schema, references), references, value);
|
|
291
292
|
}
|
|
292
293
|
function FromString(schema, references, value) {
|
|
293
|
-
if (!(0,
|
|
294
|
+
if (!(0, index_10.IsString)(value)) {
|
|
294
295
|
return false;
|
|
295
296
|
}
|
|
296
297
|
if (IsDefined(schema.minLength)) {
|
|
@@ -315,16 +316,16 @@ function FromString(schema, references, value) {
|
|
|
315
316
|
return true;
|
|
316
317
|
}
|
|
317
318
|
function FromSymbol(schema, references, value) {
|
|
318
|
-
return (0,
|
|
319
|
+
return (0, index_10.IsSymbol)(value);
|
|
319
320
|
}
|
|
320
321
|
function FromTemplateLiteral(schema, references, value) {
|
|
321
|
-
return (0,
|
|
322
|
+
return (0, index_10.IsString)(value) && new RegExp(schema.pattern).test(value);
|
|
322
323
|
}
|
|
323
324
|
function FromThis(schema, references, value) {
|
|
324
325
|
return Visit((0, index_2.Deref)(schema, references), references, value);
|
|
325
326
|
}
|
|
326
327
|
function FromTuple(schema, references, value) {
|
|
327
|
-
if (!(0,
|
|
328
|
+
if (!(0, index_10.IsArray)(value)) {
|
|
328
329
|
return false;
|
|
329
330
|
}
|
|
330
331
|
if (schema.items === undefined && !(value.length === 0)) {
|
|
@@ -343,13 +344,13 @@ function FromTuple(schema, references, value) {
|
|
|
343
344
|
return true;
|
|
344
345
|
}
|
|
345
346
|
function FromUndefined(schema, references, value) {
|
|
346
|
-
return (0,
|
|
347
|
+
return (0, index_10.IsUndefined)(value);
|
|
347
348
|
}
|
|
348
349
|
function FromUnion(schema, references, value) {
|
|
349
350
|
return schema.anyOf.some((inner) => Visit(inner, references, value));
|
|
350
351
|
}
|
|
351
352
|
function FromUint8Array(schema, references, value) {
|
|
352
|
-
if (!(0,
|
|
353
|
+
if (!(0, index_10.IsUint8Array)(value)) {
|
|
353
354
|
return false;
|
|
354
355
|
}
|
|
355
356
|
if (IsDefined(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { TypeBoxError } from '../../type/error/index';
|
|
1
2
|
import type { TSchema } from '../../type/schema/index';
|
|
2
|
-
export declare class ValueConvertUnknownTypeError extends
|
|
3
|
+
export declare class ValueConvertUnknownTypeError extends TypeBoxError {
|
|
3
4
|
readonly schema: TSchema;
|
|
4
5
|
constructor(schema: TSchema);
|
|
5
6
|
}
|
|
@@ -5,18 +5,19 @@ exports.Convert = exports.ValueConvertUnknownTypeError = void 0;
|
|
|
5
5
|
const index_1 = require("../clone/index");
|
|
6
6
|
const index_2 = require("../check/index");
|
|
7
7
|
const index_3 = require("../deref/index");
|
|
8
|
+
const index_4 = require("../../type/error/index");
|
|
8
9
|
const type_1 = require("../../type/guard/type");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
10
|
+
const index_5 = require("../../type/symbols/index");
|
|
11
|
+
const index_6 = require("../../type/composite/index");
|
|
11
12
|
// ------------------------------------------------------------------
|
|
12
13
|
// ValueGuard
|
|
13
14
|
// ------------------------------------------------------------------
|
|
14
15
|
// prettier-ignore
|
|
15
|
-
const
|
|
16
|
+
const index_7 = require("../guard/index");
|
|
16
17
|
// ------------------------------------------------------------------
|
|
17
18
|
// Errors
|
|
18
19
|
// ------------------------------------------------------------------
|
|
19
|
-
class ValueConvertUnknownTypeError extends
|
|
20
|
+
class ValueConvertUnknownTypeError extends index_4.TypeBoxError {
|
|
20
21
|
constructor(schema) {
|
|
21
22
|
super('Unknown type');
|
|
22
23
|
this.schema = schema;
|
|
@@ -27,31 +28,31 @@ exports.ValueConvertUnknownTypeError = ValueConvertUnknownTypeError;
|
|
|
27
28
|
// Conversions
|
|
28
29
|
// ------------------------------------------------------------------
|
|
29
30
|
function IsStringNumeric(value) {
|
|
30
|
-
return (0,
|
|
31
|
+
return (0, index_7.IsString)(value) && !isNaN(value) && !isNaN(parseFloat(value));
|
|
31
32
|
}
|
|
32
33
|
function IsValueToString(value) {
|
|
33
|
-
return (0,
|
|
34
|
+
return (0, index_7.IsBigInt)(value) || (0, index_7.IsBoolean)(value) || (0, index_7.IsNumber)(value);
|
|
34
35
|
}
|
|
35
36
|
function IsValueTrue(value) {
|
|
36
|
-
return value === true || ((0,
|
|
37
|
+
return value === true || ((0, index_7.IsNumber)(value) && value === 1) || ((0, index_7.IsBigInt)(value) && value === BigInt('1')) || ((0, index_7.IsString)(value) && (value.toLowerCase() === 'true' || value === '1'));
|
|
37
38
|
}
|
|
38
39
|
function IsValueFalse(value) {
|
|
39
|
-
return value === false || ((0,
|
|
40
|
+
return value === false || ((0, index_7.IsNumber)(value) && (value === 0 || Object.is(value, -0))) || ((0, index_7.IsBigInt)(value) && value === BigInt('0')) || ((0, index_7.IsString)(value) && (value.toLowerCase() === 'false' || value === '0' || value === '-0'));
|
|
40
41
|
}
|
|
41
42
|
function IsTimeStringWithTimeZone(value) {
|
|
42
|
-
return (0,
|
|
43
|
+
return (0, index_7.IsString)(value) && /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i.test(value);
|
|
43
44
|
}
|
|
44
45
|
function IsTimeStringWithoutTimeZone(value) {
|
|
45
|
-
return (0,
|
|
46
|
+
return (0, index_7.IsString)(value) && /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)?$/i.test(value);
|
|
46
47
|
}
|
|
47
48
|
function IsDateTimeStringWithTimeZone(value) {
|
|
48
|
-
return (0,
|
|
49
|
+
return (0, index_7.IsString)(value) && /^\d\d\d\d-[0-1]\d-[0-3]\dt(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i.test(value);
|
|
49
50
|
}
|
|
50
51
|
function IsDateTimeStringWithoutTimeZone(value) {
|
|
51
|
-
return (0,
|
|
52
|
+
return (0, index_7.IsString)(value) && /^\d\d\d\d-[0-1]\d-[0-3]\dt(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)?$/i.test(value);
|
|
52
53
|
}
|
|
53
54
|
function IsDateString(value) {
|
|
54
|
-
return (0,
|
|
55
|
+
return (0, index_7.IsString)(value) && /^\d\d\d\d-[0-1]\d-[0-3]\d$/i.test(value);
|
|
55
56
|
}
|
|
56
57
|
// ------------------------------------------------------------------
|
|
57
58
|
// Convert
|
|
@@ -70,31 +71,31 @@ function TryConvertLiteralBoolean(value, target) {
|
|
|
70
71
|
}
|
|
71
72
|
// prettier-ignore
|
|
72
73
|
function TryConvertLiteral(schema, value) {
|
|
73
|
-
return ((0,
|
|
74
|
-
(0,
|
|
75
|
-
(0,
|
|
74
|
+
return ((0, index_7.IsString)(schema.const) ? TryConvertLiteralString(value, schema.const) :
|
|
75
|
+
(0, index_7.IsNumber)(schema.const) ? TryConvertLiteralNumber(value, schema.const) :
|
|
76
|
+
(0, index_7.IsBoolean)(schema.const) ? TryConvertLiteralBoolean(value, schema.const) :
|
|
76
77
|
(0, index_1.Clone)(value));
|
|
77
78
|
}
|
|
78
79
|
function TryConvertBoolean(value) {
|
|
79
80
|
return IsValueTrue(value) ? true : IsValueFalse(value) ? false : value;
|
|
80
81
|
}
|
|
81
82
|
function TryConvertBigInt(value) {
|
|
82
|
-
return IsStringNumeric(value) ? BigInt(parseInt(value)) : (0,
|
|
83
|
+
return IsStringNumeric(value) ? BigInt(parseInt(value)) : (0, index_7.IsNumber)(value) ? BigInt(value | 0) : IsValueFalse(value) ? BigInt(0) : IsValueTrue(value) ? BigInt(1) : value;
|
|
83
84
|
}
|
|
84
85
|
function TryConvertString(value) {
|
|
85
|
-
return IsValueToString(value) ? value.toString() : (0,
|
|
86
|
+
return IsValueToString(value) ? value.toString() : (0, index_7.IsSymbol)(value) && value.description !== undefined ? value.description.toString() : value;
|
|
86
87
|
}
|
|
87
88
|
function TryConvertNumber(value) {
|
|
88
89
|
return IsStringNumeric(value) ? parseFloat(value) : IsValueTrue(value) ? 1 : IsValueFalse(value) ? 0 : value;
|
|
89
90
|
}
|
|
90
91
|
function TryConvertInteger(value) {
|
|
91
|
-
return IsStringNumeric(value) ? parseInt(value) : (0,
|
|
92
|
+
return IsStringNumeric(value) ? parseInt(value) : (0, index_7.IsNumber)(value) ? value | 0 : IsValueTrue(value) ? 1 : IsValueFalse(value) ? 0 : value;
|
|
92
93
|
}
|
|
93
94
|
function TryConvertNull(value) {
|
|
94
|
-
return (0,
|
|
95
|
+
return (0, index_7.IsString)(value) && value.toLowerCase() === 'null' ? null : value;
|
|
95
96
|
}
|
|
96
97
|
function TryConvertUndefined(value) {
|
|
97
|
-
return (0,
|
|
98
|
+
return (0, index_7.IsString)(value) && value === 'undefined' ? undefined : value;
|
|
98
99
|
}
|
|
99
100
|
// ------------------------------------------------------------------
|
|
100
101
|
// note: this function may return an invalid dates for the regex
|
|
@@ -105,8 +106,8 @@ function TryConvertUndefined(value) {
|
|
|
105
106
|
// ------------------------------------------------------------------
|
|
106
107
|
// prettier-ignore
|
|
107
108
|
function TryConvertDate(value) {
|
|
108
|
-
return ((0,
|
|
109
|
-
(0,
|
|
109
|
+
return ((0, index_7.IsDate)(value) ? value :
|
|
110
|
+
(0, index_7.IsNumber)(value) ? new Date(value) :
|
|
110
111
|
IsValueTrue(value) ? new Date(1) :
|
|
111
112
|
IsValueFalse(value) ? new Date(0) :
|
|
112
113
|
IsStringNumeric(value) ? new Date(parseInt(value)) :
|
|
@@ -127,7 +128,7 @@ function Default(value) {
|
|
|
127
128
|
// Convert
|
|
128
129
|
// ------------------------------------------------------------------
|
|
129
130
|
function FromArray(schema, references, value) {
|
|
130
|
-
if ((0,
|
|
131
|
+
if ((0, index_7.IsArray)(value)) {
|
|
131
132
|
return value.map((value) => Visit(schema.items, references, value));
|
|
132
133
|
}
|
|
133
134
|
return value;
|
|
@@ -148,7 +149,7 @@ function FromInteger(schema, references, value) {
|
|
|
148
149
|
function FromIntersect(schema, references, value) {
|
|
149
150
|
const allObjects = schema.allOf.every(schema => (0, type_1.IsObject)(schema));
|
|
150
151
|
if (allObjects)
|
|
151
|
-
return Visit((0,
|
|
152
|
+
return Visit((0, index_6.Composite)(schema.allOf), references, value);
|
|
152
153
|
return Visit(schema.allOf[0], references, value); // todo: fix this
|
|
153
154
|
}
|
|
154
155
|
function FromLiteral(schema, references, value) {
|
|
@@ -162,11 +163,11 @@ function FromNumber(schema, references, value) {
|
|
|
162
163
|
}
|
|
163
164
|
// prettier-ignore
|
|
164
165
|
function FromObject(schema, references, value) {
|
|
165
|
-
const isConvertable = (0,
|
|
166
|
+
const isConvertable = (0, index_7.IsObject)(value);
|
|
166
167
|
if (!isConvertable)
|
|
167
168
|
return value;
|
|
168
169
|
return Object.getOwnPropertyNames(schema.properties).reduce((value, key) => {
|
|
169
|
-
return !(0,
|
|
170
|
+
return !(0, index_7.IsUndefined)(value[key])
|
|
170
171
|
? ({ ...value, [key]: Visit(schema.properties[key], references, value[key]) })
|
|
171
172
|
: ({ ...value });
|
|
172
173
|
}, value);
|
|
@@ -187,14 +188,14 @@ function FromString(schema, references, value) {
|
|
|
187
188
|
return TryConvertString(value);
|
|
188
189
|
}
|
|
189
190
|
function FromSymbol(schema, references, value) {
|
|
190
|
-
return (0,
|
|
191
|
+
return (0, index_7.IsString)(value) || (0, index_7.IsNumber)(value) ? Symbol(value) : value;
|
|
191
192
|
}
|
|
192
193
|
function FromThis(schema, references, value) {
|
|
193
194
|
return Visit((0, index_3.Deref)(schema, references), references, value);
|
|
194
195
|
}
|
|
195
196
|
// prettier-ignore
|
|
196
197
|
function FromTuple(schema, references, value) {
|
|
197
|
-
const isConvertable = (0,
|
|
198
|
+
const isConvertable = (0, index_7.IsArray)(value) && !(0, index_7.IsUndefined)(schema.items);
|
|
198
199
|
if (!isConvertable)
|
|
199
200
|
return value;
|
|
200
201
|
return value.map((value, index) => {
|
|
@@ -216,9 +217,9 @@ function FromUnion(schema, references, value) {
|
|
|
216
217
|
return value;
|
|
217
218
|
}
|
|
218
219
|
function Visit(schema, references, value) {
|
|
219
|
-
const references_ = (0,
|
|
220
|
+
const references_ = (0, index_7.IsString)(schema.$id) ? [...references, schema] : references;
|
|
220
221
|
const schema_ = schema;
|
|
221
|
-
switch (schema[
|
|
222
|
+
switch (schema[index_5.Kind]) {
|
|
222
223
|
case 'Array':
|
|
223
224
|
return FromArray(schema_, references_, value);
|
|
224
225
|
case 'BigInt':
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
+
import { TypeBoxError } from '../../type/error/index';
|
|
1
2
|
import type { TSchema } from '../../type/schema/index';
|
|
2
3
|
import type { Static } from '../../type/static/index';
|
|
3
|
-
export declare class ValueCreateUnknownTypeError extends
|
|
4
|
+
export declare class ValueCreateUnknownTypeError extends TypeBoxError {
|
|
4
5
|
readonly schema: TSchema;
|
|
5
6
|
constructor(schema: TSchema);
|
|
6
7
|
}
|
|
7
|
-
export declare class ValueCreateNeverTypeError extends
|
|
8
|
+
export declare class ValueCreateNeverTypeError extends TypeBoxError {
|
|
8
9
|
readonly schema: TSchema;
|
|
9
10
|
constructor(schema: TSchema);
|
|
10
11
|
}
|
|
11
|
-
export declare class ValueCreateNotTypeError extends
|
|
12
|
+
export declare class ValueCreateNotTypeError extends TypeBoxError {
|
|
12
13
|
readonly schema: TSchema;
|
|
13
14
|
constructor(schema: TSchema);
|
|
14
15
|
}
|
|
15
|
-
export declare class ValueCreateIntersectTypeError extends
|
|
16
|
+
export declare class ValueCreateIntersectTypeError extends TypeBoxError {
|
|
16
17
|
readonly schema: TSchema;
|
|
17
18
|
constructor(schema: TSchema);
|
|
18
19
|
}
|
|
19
|
-
export declare class ValueCreateTempateLiteralTypeError extends
|
|
20
|
+
export declare class ValueCreateTempateLiteralTypeError extends TypeBoxError {
|
|
20
21
|
readonly schema: TSchema;
|
|
21
22
|
constructor(schema: TSchema);
|
|
22
23
|
}
|
|
23
|
-
export declare class ValueCreateRecursiveInstantiationError extends
|
|
24
|
+
export declare class ValueCreateRecursiveInstantiationError extends TypeBoxError {
|
|
24
25
|
readonly schema: TSchema;
|
|
25
26
|
readonly recursiveMaxDepth: number;
|
|
26
27
|
constructor(schema: TSchema, recursiveMaxDepth: number);
|
|
@@ -9,45 +9,46 @@ const index_4 = require("../../type/template-literal/index");
|
|
|
9
9
|
const index_5 = require("../../type/patterns/index");
|
|
10
10
|
const index_6 = require("../../type/registry/index");
|
|
11
11
|
const index_7 = require("../../type/symbols/index");
|
|
12
|
+
const index_8 = require("../../type/error/index");
|
|
12
13
|
// ------------------------------------------------------------------
|
|
13
14
|
// Errors
|
|
14
15
|
// ------------------------------------------------------------------
|
|
15
|
-
class ValueCreateUnknownTypeError extends
|
|
16
|
+
class ValueCreateUnknownTypeError extends index_8.TypeBoxError {
|
|
16
17
|
constructor(schema) {
|
|
17
18
|
super('Unknown type');
|
|
18
19
|
this.schema = schema;
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
exports.ValueCreateUnknownTypeError = ValueCreateUnknownTypeError;
|
|
22
|
-
class ValueCreateNeverTypeError extends
|
|
23
|
+
class ValueCreateNeverTypeError extends index_8.TypeBoxError {
|
|
23
24
|
constructor(schema) {
|
|
24
25
|
super('Never types cannot be created');
|
|
25
26
|
this.schema = schema;
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
exports.ValueCreateNeverTypeError = ValueCreateNeverTypeError;
|
|
29
|
-
class ValueCreateNotTypeError extends
|
|
30
|
+
class ValueCreateNotTypeError extends index_8.TypeBoxError {
|
|
30
31
|
constructor(schema) {
|
|
31
32
|
super('Not types must have a default value');
|
|
32
33
|
this.schema = schema;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
exports.ValueCreateNotTypeError = ValueCreateNotTypeError;
|
|
36
|
-
class ValueCreateIntersectTypeError extends
|
|
37
|
+
class ValueCreateIntersectTypeError extends index_8.TypeBoxError {
|
|
37
38
|
constructor(schema) {
|
|
38
39
|
super('Intersect produced invalid value. Consider using a default value.');
|
|
39
40
|
this.schema = schema;
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
exports.ValueCreateIntersectTypeError = ValueCreateIntersectTypeError;
|
|
43
|
-
class ValueCreateTempateLiteralTypeError extends
|
|
44
|
+
class ValueCreateTempateLiteralTypeError extends index_8.TypeBoxError {
|
|
44
45
|
constructor(schema) {
|
|
45
46
|
super('Can only create template literal values from patterns that produce finite sequences. Consider using a default value.');
|
|
46
47
|
this.schema = schema;
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
exports.ValueCreateTempateLiteralTypeError = ValueCreateTempateLiteralTypeError;
|
|
50
|
-
class ValueCreateRecursiveInstantiationError extends
|
|
51
|
+
class ValueCreateRecursiveInstantiationError extends index_8.TypeBoxError {
|
|
51
52
|
constructor(schema, recursiveMaxDepth) {
|
|
52
53
|
super('Value cannot be created as recursive type may produce value of infinite size. Consider using a default.');
|
|
53
54
|
this.schema = schema;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Static } from '../../type/static/index';
|
|
2
|
+
import { TypeBoxError } from '../../type/error/index';
|
|
2
3
|
export type Insert = Static<typeof Insert>;
|
|
3
4
|
export declare const Insert: import("../../type/object/object").TObject<{
|
|
4
5
|
type: import("../../type/literal/literal").TLiteral<"insert">;
|
|
@@ -29,11 +30,11 @@ export declare const Edit: import("../../type/union/union-type").TUnion<[import(
|
|
|
29
30
|
type: import("../../type/literal/literal").TLiteral<"delete">;
|
|
30
31
|
path: import("../../type/string/string").TString;
|
|
31
32
|
}>]>;
|
|
32
|
-
export declare class ValueDeltaObjectWithSymbolKeyError extends
|
|
33
|
+
export declare class ValueDeltaObjectWithSymbolKeyError extends TypeBoxError {
|
|
33
34
|
readonly key: unknown;
|
|
34
35
|
constructor(key: unknown);
|
|
35
36
|
}
|
|
36
|
-
export declare class ValueDeltaUnableToDiffUnknownValue extends
|
|
37
|
+
export declare class ValueDeltaUnableToDiffUnknownValue extends TypeBoxError {
|
|
37
38
|
readonly value: unknown;
|
|
38
39
|
constructor(value: unknown);
|
|
39
40
|
}
|
|
@@ -5,37 +5,38 @@ exports.Patch = exports.Diff = exports.ValueDeltaUnableToDiffUnknownValue = expo
|
|
|
5
5
|
const index_1 = require("../guard/index");
|
|
6
6
|
const index_2 = require("../pointer/index");
|
|
7
7
|
const index_3 = require("../clone/index");
|
|
8
|
-
const index_4 = require("../../type/
|
|
9
|
-
const index_5 = require("../../type/
|
|
10
|
-
const index_6 = require("../../type/
|
|
11
|
-
const index_7 = require("../../type/
|
|
12
|
-
const index_8 = require("../../type/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
const index_4 = require("../../type/error/index");
|
|
9
|
+
const index_5 = require("../../type/literal/index");
|
|
10
|
+
const index_6 = require("../../type/object/index");
|
|
11
|
+
const index_7 = require("../../type/string/index");
|
|
12
|
+
const index_8 = require("../../type/unknown/index");
|
|
13
|
+
const index_9 = require("../../type/union/index");
|
|
14
|
+
exports.Insert = (0, index_6.Object)({
|
|
15
|
+
type: (0, index_5.Literal)('insert'),
|
|
16
|
+
path: (0, index_7.String)(),
|
|
17
|
+
value: (0, index_8.Unknown)(),
|
|
17
18
|
});
|
|
18
|
-
exports.Update = (0,
|
|
19
|
-
type: (0,
|
|
20
|
-
path: (0,
|
|
21
|
-
value: (0,
|
|
19
|
+
exports.Update = (0, index_6.Object)({
|
|
20
|
+
type: (0, index_5.Literal)('update'),
|
|
21
|
+
path: (0, index_7.String)(),
|
|
22
|
+
value: (0, index_8.Unknown)(),
|
|
22
23
|
});
|
|
23
|
-
exports.Delete = (0,
|
|
24
|
-
type: (0,
|
|
25
|
-
path: (0,
|
|
24
|
+
exports.Delete = (0, index_6.Object)({
|
|
25
|
+
type: (0, index_5.Literal)('delete'),
|
|
26
|
+
path: (0, index_7.String)(),
|
|
26
27
|
});
|
|
27
|
-
exports.Edit = (0,
|
|
28
|
+
exports.Edit = (0, index_9.Union)([exports.Insert, exports.Update, exports.Delete]);
|
|
28
29
|
// ------------------------------------------------------------------
|
|
29
30
|
// Errors
|
|
30
31
|
// ------------------------------------------------------------------
|
|
31
|
-
class ValueDeltaObjectWithSymbolKeyError extends
|
|
32
|
+
class ValueDeltaObjectWithSymbolKeyError extends index_4.TypeBoxError {
|
|
32
33
|
constructor(key) {
|
|
33
34
|
super('Cannot diff objects with symbol keys');
|
|
34
35
|
this.key = key;
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
exports.ValueDeltaObjectWithSymbolKeyError = ValueDeltaObjectWithSymbolKeyError;
|
|
38
|
-
class ValueDeltaUnableToDiffUnknownValue extends
|
|
39
|
+
class ValueDeltaUnableToDiffUnknownValue extends index_4.TypeBoxError {
|
|
39
40
|
constructor(value) {
|
|
40
41
|
super('Unable to create diff edits for unknown value');
|
|
41
42
|
this.value = value;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { TSchema } from '../../type/schema/index';
|
|
2
2
|
import type { TRef } from '../../type/ref/index';
|
|
3
3
|
import type { TThis } from '../../type/recursive/index';
|
|
4
|
-
|
|
4
|
+
import { TypeBoxError } from '../../type/error/index';
|
|
5
|
+
export declare class TypeDereferenceError extends TypeBoxError {
|
|
5
6
|
readonly schema: TRef | TThis;
|
|
6
7
|
constructor(schema: TRef | TThis);
|
|
7
8
|
}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Deref = exports.TypeDereferenceError = void 0;
|
|
5
|
-
|
|
5
|
+
const index_1 = require("../../type/error/index");
|
|
6
|
+
class TypeDereferenceError extends index_1.TypeBoxError {
|
|
6
7
|
constructor(schema) {
|
|
7
8
|
super(`Unable to dereference schema with $id '${schema.$id}'`);
|
|
8
9
|
this.schema = schema;
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Hash = exports.ValueHashError = void 0;
|
|
5
5
|
const index_1 = require("../guard/index");
|
|
6
|
+
const index_2 = require("../../type/error/index");
|
|
6
7
|
// ------------------------------------------------------------------
|
|
7
8
|
// Errors
|
|
8
9
|
// ------------------------------------------------------------------
|
|
9
|
-
class ValueHashError extends
|
|
10
|
+
class ValueHashError extends index_2.TypeBoxError {
|
|
10
11
|
constructor(value) {
|
|
11
12
|
super(`Unable to hash value`);
|
|
12
13
|
this.value = value;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { TypeBoxError } from '../../type/error/index';
|
|
2
|
+
export declare class ValueMutateTypeMismatchError extends TypeBoxError {
|
|
2
3
|
constructor();
|
|
3
4
|
}
|
|
4
|
-
export declare class ValueMutateInvalidRootMutationError extends
|
|
5
|
+
export declare class ValueMutateInvalidRootMutationError extends TypeBoxError {
|
|
5
6
|
constructor();
|
|
6
7
|
}
|
|
7
8
|
export type Mutable = {
|
|
@@ -5,16 +5,17 @@ exports.Mutate = exports.ValueMutateInvalidRootMutationError = exports.ValueMuta
|
|
|
5
5
|
const index_1 = require("../guard/index");
|
|
6
6
|
const index_2 = require("../pointer/index");
|
|
7
7
|
const index_3 = require("../clone/index");
|
|
8
|
+
const index_4 = require("../../type/error/index");
|
|
8
9
|
// ------------------------------------------------------------------
|
|
9
10
|
// Errors
|
|
10
11
|
// ------------------------------------------------------------------
|
|
11
|
-
class ValueMutateTypeMismatchError extends
|
|
12
|
+
class ValueMutateTypeMismatchError extends index_4.TypeBoxError {
|
|
12
13
|
constructor() {
|
|
13
14
|
super('Cannot assign due type mismatch of assignable values');
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
exports.ValueMutateTypeMismatchError = ValueMutateTypeMismatchError;
|
|
17
|
-
class ValueMutateInvalidRootMutationError extends
|
|
18
|
+
class ValueMutateInvalidRootMutationError extends index_4.TypeBoxError {
|
|
18
19
|
constructor() {
|
|
19
20
|
super('Only object and array types can be mutated at the root level');
|
|
20
21
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { TypeBoxError } from '../../type/error/index';
|
|
2
|
+
export declare class ValuePointerRootSetError extends TypeBoxError {
|
|
2
3
|
readonly value: unknown;
|
|
3
4
|
readonly path: string;
|
|
4
5
|
readonly update: unknown;
|
|
5
6
|
constructor(value: unknown, path: string, update: unknown);
|
|
6
7
|
}
|
|
7
|
-
export declare class ValuePointerRootDeleteError extends
|
|
8
|
+
export declare class ValuePointerRootDeleteError extends TypeBoxError {
|
|
8
9
|
readonly value: unknown;
|
|
9
10
|
readonly path: string;
|
|
10
11
|
constructor(value: unknown, path: string);
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Get = exports.Has = exports.Delete = exports.Set = exports.Format = exports.ValuePointerRootDeleteError = exports.ValuePointerRootSetError = void 0;
|
|
5
|
+
const index_1 = require("../../type/error/index");
|
|
5
6
|
// ------------------------------------------------------------------
|
|
6
7
|
// Errors
|
|
7
8
|
// ------------------------------------------------------------------
|
|
8
|
-
class ValuePointerRootSetError extends
|
|
9
|
+
class ValuePointerRootSetError extends index_1.TypeBoxError {
|
|
9
10
|
constructor(value, path, update) {
|
|
10
11
|
super('Cannot set root value');
|
|
11
12
|
this.value = value;
|
|
@@ -14,7 +15,7 @@ class ValuePointerRootSetError extends Error {
|
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
exports.ValuePointerRootSetError = ValuePointerRootSetError;
|
|
17
|
-
class ValuePointerRootDeleteError extends
|
|
18
|
+
class ValuePointerRootDeleteError extends index_1.TypeBoxError {
|
|
18
19
|
constructor(value, path) {
|
|
19
20
|
super('Cannot delete root value');
|
|
20
21
|
this.value = value;
|