@sinclair/typebox 0.32.0-dev-22 → 0.32.0-dev-24
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 +1 -0
- package/build/import/index.mjs +1 -0
- 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/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 +3 -2
- 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/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 +1 -0
- package/build/require/index.js +154 -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/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 +3 -2
- 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/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
|
@@ -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;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { TypeBoxError } from '../../type/error/index';
|
|
1
2
|
import { ValueError } from '../../errors/index';
|
|
2
3
|
import type { TSchema } from '../../type/schema/index';
|
|
3
|
-
export declare class TransformDecodeCheckError extends
|
|
4
|
+
export declare class TransformDecodeCheckError extends TypeBoxError {
|
|
4
5
|
readonly schema: TSchema;
|
|
5
6
|
readonly value: unknown;
|
|
6
7
|
readonly error: ValueError;
|
|
7
8
|
constructor(schema: TSchema, value: unknown, error: ValueError);
|
|
8
9
|
}
|
|
9
|
-
export declare class TransformDecodeError extends
|
|
10
|
+
export declare class TransformDecodeError extends TypeBoxError {
|
|
10
11
|
readonly schema: TSchema;
|
|
11
12
|
readonly value: unknown;
|
|
12
13
|
constructor(schema: TSchema, value: unknown, error: any);
|
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.TransformDecode = exports.TransformDecodeError = exports.TransformDecodeCheckError = void 0;
|
|
5
5
|
const index_1 = require("../../type/symbols/index");
|
|
6
|
-
const index_2 = require("../../type/
|
|
7
|
-
const index_3 = require("../../type/
|
|
8
|
-
const index_4 = require("
|
|
9
|
-
const index_5 = require("../
|
|
6
|
+
const index_2 = require("../../type/error/index");
|
|
7
|
+
const index_3 = require("../../type/keyof/index");
|
|
8
|
+
const index_4 = require("../../type/indexed/index");
|
|
9
|
+
const index_5 = require("../deref/index");
|
|
10
|
+
const index_6 = require("../check/index");
|
|
10
11
|
// ------------------------------------------------------------------
|
|
11
12
|
// ValueGuard
|
|
12
13
|
// ------------------------------------------------------------------
|
|
13
|
-
const
|
|
14
|
+
const index_7 = require("../guard/index");
|
|
14
15
|
// ------------------------------------------------------------------
|
|
15
16
|
// TypeGuard
|
|
16
17
|
// ------------------------------------------------------------------
|
|
@@ -19,7 +20,7 @@ const type_1 = require("../../type/guard/type");
|
|
|
19
20
|
// Errors
|
|
20
21
|
// ------------------------------------------------------------------
|
|
21
22
|
// thrown externally
|
|
22
|
-
class TransformDecodeCheckError extends
|
|
23
|
+
class TransformDecodeCheckError extends index_2.TypeBoxError {
|
|
23
24
|
constructor(schema, value, error) {
|
|
24
25
|
super(`Unable to decode due to invalid value`);
|
|
25
26
|
this.schema = schema;
|
|
@@ -28,7 +29,7 @@ class TransformDecodeCheckError extends Error {
|
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
exports.TransformDecodeCheckError = TransformDecodeCheckError;
|
|
31
|
-
class TransformDecodeError extends
|
|
32
|
+
class TransformDecodeError extends index_2.TypeBoxError {
|
|
32
33
|
constructor(schema, value, error) {
|
|
33
34
|
super(`${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
34
35
|
this.schema = schema;
|
|
@@ -50,18 +51,18 @@ function Default(schema, value) {
|
|
|
50
51
|
}
|
|
51
52
|
// prettier-ignore
|
|
52
53
|
function FromArray(schema, references, value) {
|
|
53
|
-
return ((0,
|
|
54
|
+
return ((0, index_7.IsArray)(value))
|
|
54
55
|
? Default(schema, value.map((value) => Visit(schema.items, references, value)))
|
|
55
56
|
: Default(schema, value);
|
|
56
57
|
}
|
|
57
58
|
// prettier-ignore
|
|
58
59
|
function FromIntersect(schema, references, value) {
|
|
59
|
-
if (!(0,
|
|
60
|
+
if (!(0, index_7.IsPlainObject)(value) || (0, index_7.IsValueType)(value))
|
|
60
61
|
return Default(schema, value);
|
|
61
|
-
const knownKeys = (0,
|
|
62
|
+
const knownKeys = (0, index_3.KeyOfPropertyKeys)(schema);
|
|
62
63
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
63
64
|
return (key in value)
|
|
64
|
-
? { ...value, [key]: Visit((0,
|
|
65
|
+
? { ...value, [key]: Visit((0, index_4.Index)(schema, [key]), references, value[key]) }
|
|
65
66
|
: value;
|
|
66
67
|
}, value);
|
|
67
68
|
if (!(0, type_1.IsTransform)(schema.unevaluatedProperties)) {
|
|
@@ -81,9 +82,9 @@ function FromNot(schema, references, value) {
|
|
|
81
82
|
}
|
|
82
83
|
// prettier-ignore
|
|
83
84
|
function FromObject(schema, references, value) {
|
|
84
|
-
if (!(0,
|
|
85
|
+
if (!(0, index_7.IsPlainObject)(value))
|
|
85
86
|
return Default(schema, value);
|
|
86
|
-
const knownKeys = (0,
|
|
87
|
+
const knownKeys = (0, index_3.KeyOfPropertyKeys)(schema);
|
|
87
88
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
88
89
|
return (key in value)
|
|
89
90
|
? { ...value, [key]: Visit(schema.properties[key], references, value[key]) }
|
|
@@ -103,7 +104,7 @@ function FromObject(schema, references, value) {
|
|
|
103
104
|
}
|
|
104
105
|
// prettier-ignore
|
|
105
106
|
function FromRecord(schema, references, value) {
|
|
106
|
-
if (!(0,
|
|
107
|
+
if (!(0, index_7.IsPlainObject)(value))
|
|
107
108
|
return Default(schema, value);
|
|
108
109
|
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
109
110
|
const knownKeys = new RegExp(pattern);
|
|
@@ -126,24 +127,24 @@ function FromRecord(schema, references, value) {
|
|
|
126
127
|
}
|
|
127
128
|
// prettier-ignore
|
|
128
129
|
function FromRef(schema, references, value) {
|
|
129
|
-
const target = (0,
|
|
130
|
+
const target = (0, index_5.Deref)(schema, references);
|
|
130
131
|
return Default(schema, Visit(target, references, value));
|
|
131
132
|
}
|
|
132
133
|
// prettier-ignore
|
|
133
134
|
function FromThis(schema, references, value) {
|
|
134
|
-
const target = (0,
|
|
135
|
+
const target = (0, index_5.Deref)(schema, references);
|
|
135
136
|
return Default(schema, Visit(target, references, value));
|
|
136
137
|
}
|
|
137
138
|
// prettier-ignore
|
|
138
139
|
function FromTuple(schema, references, value) {
|
|
139
|
-
return ((0,
|
|
140
|
+
return ((0, index_7.IsArray)(value) && (0, index_7.IsArray)(schema.items))
|
|
140
141
|
? Default(schema, schema.items.map((schema, index) => Visit(schema, references, value[index])))
|
|
141
142
|
: Default(schema, value);
|
|
142
143
|
}
|
|
143
144
|
// prettier-ignore
|
|
144
145
|
function FromUnion(schema, references, value) {
|
|
145
146
|
for (const subschema of schema.anyOf) {
|
|
146
|
-
if (!(0,
|
|
147
|
+
if (!(0, index_6.Check)(subschema, references, value))
|
|
147
148
|
continue;
|
|
148
149
|
// note: ensure interior is decoded first
|
|
149
150
|
const decoded = Visit(subschema, references, value);
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { TypeBoxError } from '../../type/error/index';
|
|
1
2
|
import { ValueError } from '../../errors/index';
|
|
2
3
|
import type { TSchema } from '../../type/schema/index';
|
|
3
|
-
export declare class TransformEncodeCheckError extends
|
|
4
|
+
export declare class TransformEncodeCheckError extends TypeBoxError {
|
|
4
5
|
readonly schema: TSchema;
|
|
5
6
|
readonly value: unknown;
|
|
6
7
|
readonly error: ValueError;
|
|
7
8
|
constructor(schema: TSchema, value: unknown, error: ValueError);
|
|
8
9
|
}
|
|
9
|
-
export declare class TransformEncodeError extends
|
|
10
|
+
export declare class TransformEncodeError extends TypeBoxError {
|
|
10
11
|
readonly schema: TSchema;
|
|
11
12
|
readonly value: unknown;
|
|
12
13
|
constructor(schema: TSchema, value: unknown, error: any);
|