@sinclair/typebox 0.32.0-dev-27 → 0.32.0-dev-28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/import/compiler/compiler.mjs +7 -0
- package/build/import/errors/errors.d.mts +16 -15
- package/build/import/errors/errors.mjs +24 -15
- package/build/import/errors/function.mjs +2 -0
- package/build/import/type/clone/value.mjs +6 -2
- package/build/import/type/extends/extends-check.mjs +137 -125
- package/build/import/type/guard/type.d.mts +3 -0
- package/build/import/type/guard/type.mjs +10 -0
- package/build/import/type/guard/value.d.mts +2 -0
- package/build/import/type/guard/value.mjs +4 -0
- package/build/import/type/record/record.d.mts +3 -1
- package/build/import/type/record/record.mjs +10 -5
- package/build/import/type/regexp/regexp.d.mts +11 -4
- package/build/import/type/regexp/regexp.mjs +3 -3
- package/build/import/type/schema/anyschema.d.mts +2 -1
- package/build/import/type/type/javascript.d.mts +2 -2
- package/build/import/type/type/javascript.mjs +1 -1
- package/build/import/value/cast/cast.d.mts +2 -15
- package/build/import/value/cast/cast.mjs +5 -28
- package/build/import/value/check/check.mjs +6 -1
- package/build/import/value/convert/convert.d.mts +0 -5
- package/build/import/value/convert/convert.mjs +0 -12
- package/build/import/value/create/create.d.mts +2 -23
- package/build/import/value/create/create.mjs +30 -53
- package/build/import/value/default/default.mjs +0 -2
- package/build/import/value/delta/delta.d.mts +4 -4
- package/build/import/value/delta/delta.mjs +12 -12
- package/build/import/value/index.d.mts +7 -7
- package/build/import/value/index.mjs +6 -6
- package/build/import/value/mutate/mutate.d.mts +2 -5
- package/build/import/value/mutate/mutate.mjs +5 -10
- package/build/require/compiler/compiler.js +7 -0
- package/build/require/errors/errors.d.ts +16 -15
- package/build/require/errors/errors.js +24 -15
- package/build/require/errors/function.js +2 -0
- package/build/require/type/clone/value.js +6 -2
- package/build/require/type/extends/extends-check.js +137 -125
- package/build/require/type/guard/type.d.ts +3 -0
- package/build/require/type/guard/type.js +12 -1
- package/build/require/type/guard/value.d.ts +2 -0
- package/build/require/type/guard/value.js +6 -1
- package/build/require/type/record/record.d.ts +3 -1
- package/build/require/type/record/record.js +9 -4
- package/build/require/type/regexp/regexp.d.ts +11 -4
- package/build/require/type/regexp/regexp.js +3 -3
- package/build/require/type/schema/anyschema.d.ts +2 -1
- package/build/require/type/type/javascript.d.ts +2 -2
- package/build/require/type/type/javascript.js +1 -1
- package/build/require/value/cast/cast.d.ts +2 -15
- package/build/require/value/cast/cast.js +7 -29
- package/build/require/value/check/check.js +6 -1
- package/build/require/value/convert/convert.d.ts +0 -5
- package/build/require/value/convert/convert.js +31 -43
- package/build/require/value/create/create.d.ts +2 -23
- package/build/require/value/create/create.js +32 -54
- package/build/require/value/default/default.js +0 -2
- package/build/require/value/delta/delta.d.ts +4 -4
- package/build/require/value/delta/delta.js +14 -14
- package/build/require/value/index.d.ts +7 -7
- package/build/require/value/index.js +8 -19
- package/build/require/value/mutate/mutate.d.ts +2 -5
- package/build/require/value/mutate/mutate.js +7 -13
- package/package.json +1 -1
- package/readme.md +8 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Create = exports.
|
|
4
|
+
exports.Create = exports.ValueCreateError = void 0;
|
|
5
5
|
const index_1 = require("../guard/index");
|
|
6
6
|
const index_2 = require("../check/index");
|
|
7
7
|
const index_3 = require("../deref/index");
|
|
@@ -13,49 +13,13 @@ const index_8 = require("../../type/error/index");
|
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
14
|
// Errors
|
|
15
15
|
// ------------------------------------------------------------------
|
|
16
|
-
class
|
|
17
|
-
constructor(schema) {
|
|
18
|
-
super(
|
|
16
|
+
class ValueCreateError extends index_8.TypeBoxError {
|
|
17
|
+
constructor(schema, message) {
|
|
18
|
+
super(message);
|
|
19
19
|
this.schema = schema;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
exports.
|
|
23
|
-
class ValueCreateNeverTypeError extends index_8.TypeBoxError {
|
|
24
|
-
constructor(schema) {
|
|
25
|
-
super('Never types cannot be created');
|
|
26
|
-
this.schema = schema;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.ValueCreateNeverTypeError = ValueCreateNeverTypeError;
|
|
30
|
-
class ValueCreateNotTypeError extends index_8.TypeBoxError {
|
|
31
|
-
constructor(schema) {
|
|
32
|
-
super('Not types must have a default value');
|
|
33
|
-
this.schema = schema;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.ValueCreateNotTypeError = ValueCreateNotTypeError;
|
|
37
|
-
class ValueCreateIntersectTypeError extends index_8.TypeBoxError {
|
|
38
|
-
constructor(schema) {
|
|
39
|
-
super('Intersect produced invalid value. Consider using a default value.');
|
|
40
|
-
this.schema = schema;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.ValueCreateIntersectTypeError = ValueCreateIntersectTypeError;
|
|
44
|
-
class ValueCreateTempateLiteralTypeError extends index_8.TypeBoxError {
|
|
45
|
-
constructor(schema) {
|
|
46
|
-
super('Can only create template literal values from patterns that produce finite sequences. Consider using a default value.');
|
|
47
|
-
this.schema = schema;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.ValueCreateTempateLiteralTypeError = ValueCreateTempateLiteralTypeError;
|
|
51
|
-
class ValueCreateRecursiveInstantiationError extends index_8.TypeBoxError {
|
|
52
|
-
constructor(schema, recursiveMaxDepth) {
|
|
53
|
-
super('Value cannot be created as recursive type may produce value of infinite size. Consider using a default.');
|
|
54
|
-
this.schema = schema;
|
|
55
|
-
this.recursiveMaxDepth = recursiveMaxDepth;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.ValueCreateRecursiveInstantiationError = ValueCreateRecursiveInstantiationError;
|
|
22
|
+
exports.ValueCreateError = ValueCreateError;
|
|
59
23
|
// ------------------------------------------------------------------
|
|
60
24
|
// Create
|
|
61
25
|
// ------------------------------------------------------------------
|
|
@@ -69,10 +33,10 @@ function FromAny(schema, references) {
|
|
|
69
33
|
}
|
|
70
34
|
function FromArray(schema, references) {
|
|
71
35
|
if (schema.uniqueItems === true && !(0, index_1.HasPropertyKey)(schema, 'default')) {
|
|
72
|
-
throw new
|
|
36
|
+
throw new ValueCreateError(schema, 'Array with the uniqueItems constraint requires a default value');
|
|
73
37
|
}
|
|
74
38
|
else if ('contains' in schema && !(0, index_1.HasPropertyKey)(schema, 'default')) {
|
|
75
|
-
throw new
|
|
39
|
+
throw new ValueCreateError(schema, 'Array with the contains constraint requires a default value');
|
|
76
40
|
}
|
|
77
41
|
else if ('default' in schema) {
|
|
78
42
|
return schema.default;
|
|
@@ -179,7 +143,7 @@ function FromIntersect(schema, references) {
|
|
|
179
143
|
return typeof next === 'object' ? { ...acc, ...next } : next;
|
|
180
144
|
}, {});
|
|
181
145
|
if (!(0, index_2.Check)(schema, references, value))
|
|
182
|
-
throw new
|
|
146
|
+
throw new ValueCreateError(schema, 'Intersect produced invalid value. Consider using a default value.');
|
|
183
147
|
return value;
|
|
184
148
|
}
|
|
185
149
|
}
|
|
@@ -200,14 +164,19 @@ function FromLiteral(schema, references) {
|
|
|
200
164
|
}
|
|
201
165
|
}
|
|
202
166
|
function FromNever(schema, references) {
|
|
203
|
-
|
|
167
|
+
if ((0, index_1.HasPropertyKey)(schema, 'default')) {
|
|
168
|
+
return schema.default;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
throw new ValueCreateError(schema, 'Never types cannot be created. Consider using a default value.');
|
|
172
|
+
}
|
|
204
173
|
}
|
|
205
174
|
function FromNot(schema, references) {
|
|
206
175
|
if ((0, index_1.HasPropertyKey)(schema, 'default')) {
|
|
207
176
|
return schema.default;
|
|
208
177
|
}
|
|
209
178
|
else {
|
|
210
|
-
throw new
|
|
179
|
+
throw new ValueCreateError(schema, 'Not types must have a default value');
|
|
211
180
|
}
|
|
212
181
|
}
|
|
213
182
|
function FromNull(schema, references) {
|
|
@@ -272,10 +241,18 @@ function FromRef(schema, references) {
|
|
|
272
241
|
return Visit((0, index_3.Deref)(schema, references), references);
|
|
273
242
|
}
|
|
274
243
|
}
|
|
244
|
+
function FromRegExp(schema, references) {
|
|
245
|
+
if ((0, index_1.HasPropertyKey)(schema, 'default')) {
|
|
246
|
+
return schema.default;
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
throw new ValueCreateError(schema, 'RegExp types cannot be created. Consider using a default value.');
|
|
250
|
+
}
|
|
251
|
+
}
|
|
275
252
|
function FromString(schema, references) {
|
|
276
253
|
if (schema.pattern !== undefined) {
|
|
277
254
|
if (!(0, index_1.HasPropertyKey)(schema, 'default')) {
|
|
278
|
-
throw new
|
|
255
|
+
throw new ValueCreateError(schema, 'String types with patterns must specify a default value');
|
|
279
256
|
}
|
|
280
257
|
else {
|
|
281
258
|
return schema.default;
|
|
@@ -283,7 +260,7 @@ function FromString(schema, references) {
|
|
|
283
260
|
}
|
|
284
261
|
else if (schema.format !== undefined) {
|
|
285
262
|
if (!(0, index_1.HasPropertyKey)(schema, 'default')) {
|
|
286
|
-
throw new
|
|
263
|
+
throw new ValueCreateError(schema, 'String types with formats must specify a default value');
|
|
287
264
|
}
|
|
288
265
|
else {
|
|
289
266
|
return schema.default;
|
|
@@ -294,9 +271,8 @@ function FromString(schema, references) {
|
|
|
294
271
|
return schema.default;
|
|
295
272
|
}
|
|
296
273
|
else if (schema.minLength !== undefined) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
.join('');
|
|
274
|
+
// prettier-ignore
|
|
275
|
+
return Array.from({ length: schema.minLength }).map(() => ' ').join('');
|
|
300
276
|
}
|
|
301
277
|
else {
|
|
302
278
|
return '';
|
|
@@ -319,13 +295,13 @@ function FromTemplateLiteral(schema, references) {
|
|
|
319
295
|
return schema.default;
|
|
320
296
|
}
|
|
321
297
|
if (!(0, index_4.IsTemplateLiteralFinite)(schema))
|
|
322
|
-
throw new
|
|
298
|
+
throw new ValueCreateError(schema, 'Can only create template literals that produce a finite variants. Consider using a default value.');
|
|
323
299
|
const generated = (0, index_4.TemplateLiteralGenerate)(schema);
|
|
324
300
|
return generated[0];
|
|
325
301
|
}
|
|
326
302
|
function FromThis(schema, references) {
|
|
327
303
|
if (recursiveDepth++ > recursiveMaxDepth)
|
|
328
|
-
throw new
|
|
304
|
+
throw new ValueCreateError(schema, 'Cannot create recursive type as it appears possibly infinite. Consider using a default.');
|
|
329
305
|
if ((0, index_1.HasPropertyKey)(schema, 'default')) {
|
|
330
306
|
return schema.default;
|
|
331
307
|
}
|
|
@@ -442,6 +418,8 @@ function Visit(schema, references) {
|
|
|
442
418
|
return FromRecord(schema_, references_);
|
|
443
419
|
case 'Ref':
|
|
444
420
|
return FromRef(schema_, references_);
|
|
421
|
+
case 'RegExp':
|
|
422
|
+
return FromRegExp(schema_, references_);
|
|
445
423
|
case 'String':
|
|
446
424
|
return FromString(schema_, references_);
|
|
447
425
|
case 'Symbol':
|
|
@@ -464,7 +442,7 @@ function Visit(schema, references) {
|
|
|
464
442
|
return FromVoid(schema_, references_);
|
|
465
443
|
default:
|
|
466
444
|
if (!index_6.TypeRegistry.Has(schema_[index_7.Kind]))
|
|
467
|
-
throw new
|
|
445
|
+
throw new ValueCreateError(schema_, 'Unknown type');
|
|
468
446
|
return FromKind(schema_, references_);
|
|
469
447
|
}
|
|
470
448
|
}
|
|
@@ -8,12 +8,10 @@ const index_3 = require("../../type/symbols/index");
|
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
9
|
// ValueGuard
|
|
10
10
|
// ------------------------------------------------------------------
|
|
11
|
-
// prettier-ignore
|
|
12
11
|
const index_4 = require("../guard/index");
|
|
13
12
|
// ------------------------------------------------------------------
|
|
14
13
|
// TypeGuard
|
|
15
14
|
// ------------------------------------------------------------------
|
|
16
|
-
// prettier-ignore
|
|
17
15
|
const type_1 = require("../../type/guard/type");
|
|
18
16
|
// ------------------------------------------------------------------
|
|
19
17
|
// ValueOrDefault
|
|
@@ -30,11 +30,11 @@ export declare const Edit: import("../../type/union/union-type").TUnion<[import(
|
|
|
30
30
|
type: import("../../type/literal/literal").TLiteral<"delete">;
|
|
31
31
|
path: import("../../type/string/string").TString;
|
|
32
32
|
}>]>;
|
|
33
|
-
export declare class
|
|
34
|
-
readonly
|
|
35
|
-
constructor(
|
|
33
|
+
export declare class ValueDeltaError extends TypeBoxError {
|
|
34
|
+
readonly value: unknown;
|
|
35
|
+
constructor(value: unknown, message: string);
|
|
36
36
|
}
|
|
37
|
-
export declare class
|
|
37
|
+
export declare class ValueDeltaSymbolError extends ValueDeltaError {
|
|
38
38
|
readonly value: unknown;
|
|
39
39
|
constructor(value: unknown);
|
|
40
40
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Patch = exports.Diff = exports.
|
|
4
|
+
exports.Patch = exports.Diff = exports.ValueDeltaSymbolError = exports.ValueDeltaError = exports.Edit = exports.Delete = exports.Update = exports.Insert = void 0;
|
|
5
5
|
const index_1 = require("../guard/index");
|
|
6
6
|
const index_2 = require("../pointer/index");
|
|
7
7
|
const index_3 = require("../clone/index");
|
|
@@ -29,20 +29,20 @@ exports.Edit = (0, index_9.Union)([exports.Insert, exports.Update, exports.Delet
|
|
|
29
29
|
// ------------------------------------------------------------------
|
|
30
30
|
// Errors
|
|
31
31
|
// ------------------------------------------------------------------
|
|
32
|
-
class
|
|
33
|
-
constructor(
|
|
34
|
-
super(
|
|
35
|
-
this.
|
|
32
|
+
class ValueDeltaError extends index_4.TypeBoxError {
|
|
33
|
+
constructor(value, message) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.value = value;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
exports.
|
|
39
|
-
class
|
|
38
|
+
exports.ValueDeltaError = ValueDeltaError;
|
|
39
|
+
class ValueDeltaSymbolError extends ValueDeltaError {
|
|
40
40
|
constructor(value) {
|
|
41
|
-
super('
|
|
41
|
+
super(value, 'Cannot diff objects with symbol keys');
|
|
42
42
|
this.value = value;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
exports.
|
|
45
|
+
exports.ValueDeltaSymbolError = ValueDeltaSymbolError;
|
|
46
46
|
// ------------------------------------------------------------------
|
|
47
47
|
// Command Factory
|
|
48
48
|
// ------------------------------------------------------------------
|
|
@@ -65,7 +65,7 @@ function* ObjectType(path, current, next) {
|
|
|
65
65
|
const nextKeys = [...globalThis.Object.keys(next), ...globalThis.Object.getOwnPropertySymbols(next)];
|
|
66
66
|
for (const key of currentKeys) {
|
|
67
67
|
if ((0, index_1.IsSymbol)(key))
|
|
68
|
-
throw new
|
|
68
|
+
throw new ValueDeltaSymbolError(key);
|
|
69
69
|
if ((0, index_1.IsUndefined)(next[key]) && nextKeys.includes(key))
|
|
70
70
|
yield CreateUpdate(`${path}/${globalThis.String(key)}`, undefined);
|
|
71
71
|
}
|
|
@@ -73,18 +73,18 @@ function* ObjectType(path, current, next) {
|
|
|
73
73
|
if ((0, index_1.IsUndefined)(current[key]) || (0, index_1.IsUndefined)(next[key]))
|
|
74
74
|
continue;
|
|
75
75
|
if ((0, index_1.IsSymbol)(key))
|
|
76
|
-
throw new
|
|
76
|
+
throw new ValueDeltaSymbolError(key);
|
|
77
77
|
yield* Visit(`${path}/${globalThis.String(key)}`, current[key], next[key]);
|
|
78
78
|
}
|
|
79
79
|
for (const key of nextKeys) {
|
|
80
80
|
if ((0, index_1.IsSymbol)(key))
|
|
81
|
-
throw new
|
|
81
|
+
throw new ValueDeltaSymbolError(key);
|
|
82
82
|
if ((0, index_1.IsUndefined)(current[key]))
|
|
83
83
|
yield CreateInsert(`${path}/${globalThis.String(key)}`, next[key]);
|
|
84
84
|
}
|
|
85
85
|
for (const key of currentKeys.reverse()) {
|
|
86
86
|
if ((0, index_1.IsSymbol)(key))
|
|
87
|
-
throw new
|
|
87
|
+
throw new ValueDeltaSymbolError(key);
|
|
88
88
|
if ((0, index_1.IsUndefined)(next[key]) && !nextKeys.includes(key))
|
|
89
89
|
yield CreateDelete(`${path}/${globalThis.String(key)}`);
|
|
90
90
|
}
|
|
@@ -127,7 +127,7 @@ function* Visit(path, current, next) {
|
|
|
127
127
|
return yield* TypedArrayType(path, current, next);
|
|
128
128
|
if ((0, index_1.IsValueType)(current))
|
|
129
129
|
return yield* ValueType(path, current, next);
|
|
130
|
-
throw new
|
|
130
|
+
throw new ValueDeltaError(current, 'Unable to create diff edits for unknown value');
|
|
131
131
|
}
|
|
132
132
|
// ------------------------------------------------------------------
|
|
133
133
|
// Diff
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export { ValueError, ValueErrorType, ValueErrorIterator } from '../errors/index';
|
|
2
|
-
export { Cast,
|
|
2
|
+
export { Cast, ValueCastError } from './cast/index';
|
|
3
3
|
export { Check } from './check/index';
|
|
4
4
|
export { Clean } from './clean/index';
|
|
5
5
|
export { Clone } from './clone/index';
|
|
6
|
-
export { Convert
|
|
7
|
-
export { Create,
|
|
6
|
+
export { Convert } from './convert/index';
|
|
7
|
+
export { Create, ValueCreateError } from './create/index';
|
|
8
8
|
export { Default } from './default/index';
|
|
9
|
-
export { Diff, Patch, Edit, Delete, Insert, Update,
|
|
9
|
+
export { Diff, Patch, Edit, Delete, Insert, Update, ValueDeltaError } from './delta/index';
|
|
10
10
|
export { Equal } from './equal/index';
|
|
11
11
|
export { Hash, ValueHashError } from './hash/index';
|
|
12
|
-
export { Mutate, type Mutable
|
|
12
|
+
export { Mutate, ValueMutateError, type Mutable } from './mutate/index';
|
|
13
13
|
export { ValuePointer } from './pointer/index';
|
|
14
|
-
export { TransformDecode
|
|
15
|
-
export { ArrayType, HasPropertyKey, IsArray, IsAsyncIterator, IsBigInt, IsBoolean, IsDate, IsFunction, IsInteger, IsIterator, IsNull, IsNumber, IsObject, IsPlainObject, IsPromise, IsString, IsSymbol, IsTypedArray, IsUint8Array, IsUndefined, IsValueType, ObjectType, TypedArrayType, ValueType, } from './guard/index';
|
|
14
|
+
export { TransformDecode, TransformEncode, HasTransform, TransformDecodeCheckError, TransformDecodeError, TransformEncodeCheckError, TransformEncodeError } from './transform/index';
|
|
15
|
+
export { ArrayType, HasPropertyKey, IsArray, IsAsyncIterator, IsBigInt, IsBoolean, IsDate, IsFunction, IsInteger, IsIterator, IsNull, IsNumber, IsObject, IsPlainObject, IsPromise, IsString, IsSymbol, IsTypedArray, IsUint8Array, IsUndefined, IsValueType, type ObjectType, type TypedArrayType, type ValueType, } from './guard/index';
|
|
16
16
|
export { Value } from './value/index';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
5
|
-
exports.Value = exports.IsValueType =
|
|
4
|
+
exports.IsUndefined = exports.IsUint8Array = exports.IsTypedArray = exports.IsSymbol = exports.IsString = exports.IsPromise = exports.IsPlainObject = exports.IsObject = exports.IsNumber = exports.IsNull = exports.IsIterator = exports.IsInteger = exports.IsFunction = exports.IsDate = exports.IsBoolean = exports.IsBigInt = exports.IsAsyncIterator = exports.IsArray = exports.HasPropertyKey = exports.TransformEncodeError = exports.TransformEncodeCheckError = exports.TransformDecodeError = exports.TransformDecodeCheckError = exports.HasTransform = exports.TransformEncode = exports.TransformDecode = exports.ValuePointer = exports.ValueMutateError = exports.Mutate = exports.ValueHashError = exports.Hash = exports.Equal = exports.ValueDeltaError = exports.Update = exports.Insert = exports.Delete = exports.Edit = exports.Patch = exports.Diff = exports.Default = exports.ValueCreateError = exports.Create = exports.Convert = exports.Clone = exports.Clean = exports.Check = exports.ValueCastError = exports.Cast = exports.ValueErrorIterator = exports.ValueErrorType = void 0;
|
|
5
|
+
exports.Value = exports.IsValueType = void 0;
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
7
|
// Value Errors (re-export)
|
|
8
8
|
// ------------------------------------------------------------------
|
|
@@ -14,10 +14,7 @@ Object.defineProperty(exports, "ValueErrorIterator", { enumerable: true, get: fu
|
|
|
14
14
|
// ------------------------------------------------------------------
|
|
15
15
|
var index_2 = require("./cast/index");
|
|
16
16
|
Object.defineProperty(exports, "Cast", { enumerable: true, get: function () { return index_2.Cast; } });
|
|
17
|
-
Object.defineProperty(exports, "
|
|
18
|
-
Object.defineProperty(exports, "ValueCastNeverTypeError", { enumerable: true, get: function () { return index_2.ValueCastNeverTypeError; } });
|
|
19
|
-
Object.defineProperty(exports, "ValueCastRecursiveTypeError", { enumerable: true, get: function () { return index_2.ValueCastRecursiveTypeError; } });
|
|
20
|
-
Object.defineProperty(exports, "ValueCastUnknownTypeError", { enumerable: true, get: function () { return index_2.ValueCastUnknownTypeError; } });
|
|
17
|
+
Object.defineProperty(exports, "ValueCastError", { enumerable: true, get: function () { return index_2.ValueCastError; } });
|
|
21
18
|
var index_3 = require("./check/index");
|
|
22
19
|
Object.defineProperty(exports, "Check", { enumerable: true, get: function () { return index_3.Check; } });
|
|
23
20
|
var index_4 = require("./clean/index");
|
|
@@ -26,15 +23,9 @@ var index_5 = require("./clone/index");
|
|
|
26
23
|
Object.defineProperty(exports, "Clone", { enumerable: true, get: function () { return index_5.Clone; } });
|
|
27
24
|
var index_6 = require("./convert/index");
|
|
28
25
|
Object.defineProperty(exports, "Convert", { enumerable: true, get: function () { return index_6.Convert; } });
|
|
29
|
-
Object.defineProperty(exports, "ValueConvertUnknownTypeError", { enumerable: true, get: function () { return index_6.ValueConvertUnknownTypeError; } });
|
|
30
26
|
var index_7 = require("./create/index");
|
|
31
27
|
Object.defineProperty(exports, "Create", { enumerable: true, get: function () { return index_7.Create; } });
|
|
32
|
-
Object.defineProperty(exports, "
|
|
33
|
-
Object.defineProperty(exports, "ValueCreateNeverTypeError", { enumerable: true, get: function () { return index_7.ValueCreateNeverTypeError; } });
|
|
34
|
-
Object.defineProperty(exports, "ValueCreateNotTypeError", { enumerable: true, get: function () { return index_7.ValueCreateNotTypeError; } });
|
|
35
|
-
Object.defineProperty(exports, "ValueCreateRecursiveInstantiationError", { enumerable: true, get: function () { return index_7.ValueCreateRecursiveInstantiationError; } });
|
|
36
|
-
Object.defineProperty(exports, "ValueCreateTempateLiteralTypeError", { enumerable: true, get: function () { return index_7.ValueCreateTempateLiteralTypeError; } });
|
|
37
|
-
Object.defineProperty(exports, "ValueCreateUnknownTypeError", { enumerable: true, get: function () { return index_7.ValueCreateUnknownTypeError; } });
|
|
28
|
+
Object.defineProperty(exports, "ValueCreateError", { enumerable: true, get: function () { return index_7.ValueCreateError; } });
|
|
38
29
|
var index_8 = require("./default/index");
|
|
39
30
|
Object.defineProperty(exports, "Default", { enumerable: true, get: function () { return index_8.Default; } });
|
|
40
31
|
var index_9 = require("./delta/index");
|
|
@@ -44,8 +35,7 @@ Object.defineProperty(exports, "Edit", { enumerable: true, get: function () { re
|
|
|
44
35
|
Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return index_9.Delete; } });
|
|
45
36
|
Object.defineProperty(exports, "Insert", { enumerable: true, get: function () { return index_9.Insert; } });
|
|
46
37
|
Object.defineProperty(exports, "Update", { enumerable: true, get: function () { return index_9.Update; } });
|
|
47
|
-
Object.defineProperty(exports, "
|
|
48
|
-
Object.defineProperty(exports, "ValueDeltaUnableToDiffUnknownValue", { enumerable: true, get: function () { return index_9.ValueDeltaUnableToDiffUnknownValue; } });
|
|
38
|
+
Object.defineProperty(exports, "ValueDeltaError", { enumerable: true, get: function () { return index_9.ValueDeltaError; } });
|
|
49
39
|
var index_10 = require("./equal/index");
|
|
50
40
|
Object.defineProperty(exports, "Equal", { enumerable: true, get: function () { return index_10.Equal; } });
|
|
51
41
|
var index_11 = require("./hash/index");
|
|
@@ -53,13 +43,12 @@ Object.defineProperty(exports, "Hash", { enumerable: true, get: function () { re
|
|
|
53
43
|
Object.defineProperty(exports, "ValueHashError", { enumerable: true, get: function () { return index_11.ValueHashError; } });
|
|
54
44
|
var index_12 = require("./mutate/index");
|
|
55
45
|
Object.defineProperty(exports, "Mutate", { enumerable: true, get: function () { return index_12.Mutate; } });
|
|
56
|
-
Object.defineProperty(exports, "
|
|
57
|
-
Object.defineProperty(exports, "ValueMutateTypeMismatchError", { enumerable: true, get: function () { return index_12.ValueMutateTypeMismatchError; } });
|
|
46
|
+
Object.defineProperty(exports, "ValueMutateError", { enumerable: true, get: function () { return index_12.ValueMutateError; } });
|
|
58
47
|
var index_13 = require("./pointer/index");
|
|
59
48
|
Object.defineProperty(exports, "ValuePointer", { enumerable: true, get: function () { return index_13.ValuePointer; } });
|
|
60
49
|
var index_14 = require("./transform/index");
|
|
61
|
-
Object.defineProperty(exports, "
|
|
62
|
-
Object.defineProperty(exports, "
|
|
50
|
+
Object.defineProperty(exports, "TransformDecode", { enumerable: true, get: function () { return index_14.TransformDecode; } });
|
|
51
|
+
Object.defineProperty(exports, "TransformEncode", { enumerable: true, get: function () { return index_14.TransformEncode; } });
|
|
63
52
|
Object.defineProperty(exports, "HasTransform", { enumerable: true, get: function () { return index_14.HasTransform; } });
|
|
64
53
|
Object.defineProperty(exports, "TransformDecodeCheckError", { enumerable: true, get: function () { return index_14.TransformDecodeCheckError; } });
|
|
65
54
|
Object.defineProperty(exports, "TransformDecodeError", { enumerable: true, get: function () { return index_14.TransformDecodeError; } });
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { TypeBoxError } from '../../type/error/index';
|
|
2
|
-
export declare class
|
|
3
|
-
constructor();
|
|
4
|
-
}
|
|
5
|
-
export declare class ValueMutateInvalidRootMutationError extends TypeBoxError {
|
|
6
|
-
constructor();
|
|
2
|
+
export declare class ValueMutateError extends TypeBoxError {
|
|
3
|
+
constructor(message: string);
|
|
7
4
|
}
|
|
8
5
|
export type Mutable = {
|
|
9
6
|
[key: string]: unknown;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Mutate = exports.
|
|
4
|
+
exports.Mutate = exports.ValueMutateError = void 0;
|
|
5
5
|
const index_1 = require("../guard/index");
|
|
6
6
|
const index_2 = require("../pointer/index");
|
|
7
7
|
const index_3 = require("../clone/index");
|
|
@@ -9,18 +9,12 @@ const index_4 = require("../../type/error/index");
|
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
// Errors
|
|
11
11
|
// ------------------------------------------------------------------
|
|
12
|
-
class
|
|
13
|
-
constructor() {
|
|
14
|
-
super(
|
|
12
|
+
class ValueMutateError extends index_4.TypeBoxError {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
exports.
|
|
18
|
-
class ValueMutateInvalidRootMutationError extends index_4.TypeBoxError {
|
|
19
|
-
constructor() {
|
|
20
|
-
super('Only object and array types can be mutated at the root level');
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.ValueMutateInvalidRootMutationError = ValueMutateInvalidRootMutationError;
|
|
17
|
+
exports.ValueMutateError = ValueMutateError;
|
|
24
18
|
function ObjectType(root, path, current, next) {
|
|
25
19
|
if (!(0, index_1.IsPlainObject)(current)) {
|
|
26
20
|
index_2.ValuePointer.Set(root, path, (0, index_3.Clone)(next));
|
|
@@ -96,9 +90,9 @@ function IsMismatchedValue(current, next) {
|
|
|
96
90
|
/** `[Mutable]` Performs a deep mutable value assignment while retaining internal references */
|
|
97
91
|
function Mutate(current, next) {
|
|
98
92
|
if (IsNonMutableValue(current) || IsNonMutableValue(next))
|
|
99
|
-
throw new
|
|
93
|
+
throw new ValueMutateError('Only object and array types can be mutated at the root level');
|
|
100
94
|
if (IsMismatchedValue(current, next))
|
|
101
|
-
throw new
|
|
95
|
+
throw new ValueMutateError('Cannot assign due type mismatch of assignable values');
|
|
102
96
|
Visit(current, '', current, next);
|
|
103
97
|
}
|
|
104
98
|
exports.Mutate = Mutate;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -605,9 +605,10 @@ TypeBox provides an extended type set that can be used to create schematics for
|
|
|
605
605
|
│ │ │ } │
|
|
606
606
|
│ │ │ │
|
|
607
607
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
608
|
-
│ const T = Type.RegExp(/abc/)
|
|
609
|
-
│ │ │ type: '
|
|
610
|
-
│ │ │
|
|
608
|
+
│ const T = Type.RegExp(/abc/i) │ type T = string │ const T = { │
|
|
609
|
+
│ │ │ type: 'RegExp' │
|
|
610
|
+
│ │ │ source: 'abc' │
|
|
611
|
+
│ │ │ flags: 'i' │
|
|
611
612
|
│ │ │ } │
|
|
612
613
|
│ │ │ │
|
|
613
614
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
@@ -1795,11 +1796,11 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
|
|
|
1795
1796
|
┌──────────────────────┬────────────┬────────────┬─────────────┐
|
|
1796
1797
|
│ (index) │ Compiled │ Minified │ Compression │
|
|
1797
1798
|
├──────────────────────┼────────────┼────────────┼─────────────┤
|
|
1798
|
-
│ typebox/compiler │ '
|
|
1799
|
-
│ typebox/errors │ ' 55.
|
|
1799
|
+
│ typebox/compiler │ '120.6 kb' │ ' 52.9 kb' │ '2.28 x' │
|
|
1800
|
+
│ typebox/errors │ ' 55.7 kb' │ ' 25.5 kb' │ '2.19 x' │
|
|
1800
1801
|
│ typebox/system │ ' 4.7 kb' │ ' 2.0 kb' │ '2.33 x' │
|
|
1801
|
-
│ typebox/value │ '146.
|
|
1802
|
-
│ typebox │ '
|
|
1802
|
+
│ typebox/value │ '146.2 kb' │ ' 62.0 kb' │ '2.36 x' │
|
|
1803
|
+
│ typebox │ ' 91.4 kb' │ ' 37.8 kb' │ '2.42 x' │
|
|
1803
1804
|
└──────────────────────┴────────────┴────────────┴─────────────┘
|
|
1804
1805
|
```
|
|
1805
1806
|
|