@sinclair/typebox 0.32.0-dev-26 → 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/index.d.mts +2 -2
- package/build/import/type/awaited/awaited.mjs +2 -6
- package/build/import/type/clone/value.mjs +6 -2
- package/build/import/type/composite/composite.d.mts +1 -2
- package/build/import/type/composite/composite.mjs +2 -2
- package/build/import/type/const/const.mjs +6 -6
- package/build/import/type/constructor/constructor.d.mts +1 -1
- package/build/import/type/constructor/constructor.mjs +1 -1
- package/build/import/type/deref/deref.mjs +1 -2
- package/build/import/type/discard/discard.mjs +2 -2
- package/build/import/type/enum/enum.mjs +3 -0
- package/build/import/type/exclude/exclude-from-mapped-result.d.mts +5 -5
- package/build/import/type/exclude/exclude-from-mapped-result.mjs +7 -7
- package/build/import/type/exclude/exclude.mjs +0 -1
- package/build/import/type/extends/extends-check.mjs +137 -125
- package/build/import/type/extends/extends-from-mapped-key.d.mts +1 -1
- package/build/import/type/extends/extends-from-mapped-key.mjs +4 -5
- package/build/import/type/extends/extends-from-mapped-result.d.mts +5 -5
- package/build/import/type/extends/extends-from-mapped-result.mjs +7 -7
- package/build/import/type/extends/extends.mjs +0 -1
- package/build/import/type/extract/extract-from-mapped-result.d.mts +5 -5
- package/build/import/type/extract/extract-from-mapped-result.mjs +7 -7
- package/build/import/type/extract/extract.d.mts +1 -2
- package/build/import/type/extract/extract.mjs +4 -2
- 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/index.d.mts +1 -1
- package/build/import/type/index.mjs +1 -1
- package/build/import/type/indexed/indexed-from-mapped-key.d.mts +2 -2
- package/build/import/type/indexed/indexed-from-mapped-key.mjs +4 -5
- package/build/import/type/indexed/indexed-from-mapped-result.d.mts +1 -1
- package/build/import/type/indexed/indexed-property-keys.d.mts +6 -6
- package/build/import/type/indexed/indexed-property-keys.mjs +3 -5
- package/build/import/type/indexed/indexed.d.mts +1 -1
- package/build/import/type/indexed/indexed.mjs +9 -27
- package/build/import/type/intersect/intersect-evaluated.mjs +3 -13
- package/build/import/type/intrinsic/capitalize.d.mts +2 -2
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.d.mts +1 -1
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.mjs +4 -5
- package/build/import/type/intrinsic/intrinsic.d.mts +2 -3
- package/build/import/type/intrinsic/intrinsic.mjs +2 -5
- package/build/import/type/intrinsic/lowercase.d.mts +2 -2
- package/build/import/type/intrinsic/uncapitalize.d.mts +2 -2
- package/build/import/type/intrinsic/uppercase.d.mts +2 -2
- package/build/import/type/iterator/iterator.mjs +1 -1
- package/build/import/type/keyof/keyof-from-mapped-result.d.mts +3 -3
- package/build/import/type/keyof/keyof-from-mapped-result.mjs +4 -4
- package/build/import/type/keyof/keyof-property-keys.d.mts +3 -3
- package/build/import/type/keyof/keyof-property-keys.mjs +9 -15
- package/build/import/type/keyof/keyof.mjs +2 -8
- package/build/import/type/mapped/mapped.d.mts +6 -1
- package/build/import/type/mapped/mapped.mjs +21 -14
- package/build/import/type/not/not.mjs +1 -1
- package/build/import/type/object/object.d.mts +1 -1
- package/build/import/type/object/object.mjs +0 -1
- package/build/import/type/omit/index.d.mts +1 -0
- package/build/import/type/omit/index.mjs +1 -0
- package/build/import/type/omit/omit-from-mapped-key.mjs +4 -5
- package/build/import/type/omit/omit-from-mapped-result.d.mts +11 -0
- package/build/import/type/omit/omit-from-mapped-result.mjs +17 -0
- package/build/import/type/omit/omit.d.mts +6 -3
- package/build/import/type/omit/omit.mjs +11 -9
- package/build/import/type/optional/optional-from-mapped-result.d.mts +5 -5
- package/build/import/type/optional/optional-from-mapped-result.mjs +7 -7
- package/build/import/type/partial/partial-from-mapped-result.d.mts +5 -5
- package/build/import/type/partial/partial-from-mapped-result.mjs +4 -4
- package/build/import/type/partial/partial.d.mts +2 -3
- package/build/import/type/partial/partial.mjs +8 -21
- package/build/import/type/pick/index.d.mts +1 -0
- package/build/import/type/pick/index.mjs +1 -0
- package/build/import/type/pick/pick-from-mapped-key.mjs +4 -5
- package/build/import/type/pick/pick-from-mapped-result.d.mts +11 -0
- package/build/import/type/pick/pick-from-mapped-result.mjs +17 -0
- package/build/import/type/pick/pick.d.mts +5 -2
- package/build/import/type/pick/pick.mjs +11 -10
- package/build/import/type/promise/promise.mjs +1 -1
- package/build/import/type/readonly/readonly-from-mapped-result.d.mts +5 -5
- package/build/import/type/readonly/readonly-from-mapped-result.mjs +4 -4
- package/build/import/type/record/record.d.mts +5 -3
- package/build/import/type/record/record.mjs +13 -5
- package/build/import/type/ref/ref.mjs +1 -1
- package/build/import/type/regexp/regexp.d.mts +11 -4
- package/build/import/type/regexp/regexp.mjs +3 -3
- package/build/import/type/required/required-from-mapped-result.d.mts +5 -5
- package/build/import/type/required/required-from-mapped-result.mjs +7 -7
- package/build/import/type/required/required.d.mts +2 -3
- package/build/import/type/required/required.mjs +4 -14
- package/build/import/type/rest/rest.d.mts +2 -2
- package/build/import/type/rest/rest.mjs +1 -2
- package/build/import/type/schema/anyschema.d.mts +2 -1
- package/build/import/type/sets/index.d.mts +1 -0
- package/build/import/type/sets/index.mjs +1 -0
- package/build/import/type/sets/set.d.mts +24 -0
- package/build/import/type/sets/set.mjs +35 -0
- package/build/import/type/strict/strict.d.mts +1 -1
- package/build/import/type/strict/strict.mjs +1 -1
- package/build/import/type/template-literal/syntax.d.mts +1 -1
- package/build/import/type/template-literal/template-literal.d.mts +1 -1
- package/build/import/type/transform/transform.mjs +1 -1
- package/build/import/type/type/javascript.d.mts +2 -2
- package/build/import/type/type/javascript.mjs +1 -1
- package/build/import/type/type/json.d.mts +6 -2
- package/build/import/type/union/union-evaluated.mjs +3 -14
- 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/index.d.ts +2 -2
- package/build/require/type/awaited/awaited.js +2 -6
- package/build/require/type/clone/value.js +6 -2
- package/build/require/type/composite/composite.d.ts +1 -2
- package/build/require/type/composite/composite.js +5 -6
- package/build/require/type/const/const.js +6 -6
- package/build/require/type/constructor/constructor.d.ts +1 -1
- package/build/require/type/constructor/constructor.js +1 -1
- package/build/require/type/deref/deref.js +0 -1
- package/build/require/type/discard/discard.js +2 -2
- package/build/require/type/enum/enum.js +3 -0
- package/build/require/type/exclude/exclude-from-mapped-result.d.ts +5 -5
- package/build/require/type/exclude/exclude-from-mapped-result.js +7 -7
- package/build/require/type/exclude/exclude.js +0 -1
- package/build/require/type/extends/extends-check.js +137 -125
- package/build/require/type/extends/extends-from-mapped-key.d.ts +1 -1
- package/build/require/type/extends/extends-from-mapped-key.js +4 -5
- package/build/require/type/extends/extends-from-mapped-result.d.ts +5 -5
- package/build/require/type/extends/extends-from-mapped-result.js +7 -7
- package/build/require/type/extends/extends.js +0 -1
- package/build/require/type/extract/extract-from-mapped-result.d.ts +5 -5
- package/build/require/type/extract/extract-from-mapped-result.js +7 -7
- package/build/require/type/extract/extract.d.ts +1 -2
- package/build/require/type/extract/extract.js +4 -3
- 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/index.d.ts +1 -1
- package/build/require/type/index.js +1 -1
- package/build/require/type/indexed/indexed-from-mapped-key.d.ts +2 -2
- package/build/require/type/indexed/indexed-from-mapped-key.js +4 -5
- package/build/require/type/indexed/indexed-from-mapped-result.d.ts +1 -1
- package/build/require/type/indexed/indexed-property-keys.d.ts +6 -6
- package/build/require/type/indexed/indexed-property-keys.js +3 -5
- package/build/require/type/indexed/indexed.d.ts +1 -1
- package/build/require/type/indexed/indexed.js +9 -27
- package/build/require/type/intersect/intersect-evaluated.js +3 -13
- package/build/require/type/intrinsic/capitalize.d.ts +2 -2
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.d.ts +1 -1
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.js +4 -5
- package/build/require/type/intrinsic/intrinsic.d.ts +2 -3
- package/build/require/type/intrinsic/intrinsic.js +2 -5
- package/build/require/type/intrinsic/lowercase.d.ts +2 -2
- package/build/require/type/intrinsic/uncapitalize.d.ts +2 -2
- package/build/require/type/intrinsic/uppercase.d.ts +2 -2
- package/build/require/type/iterator/iterator.js +1 -1
- package/build/require/type/keyof/keyof-from-mapped-result.d.ts +3 -3
- package/build/require/type/keyof/keyof-from-mapped-result.js +4 -4
- package/build/require/type/keyof/keyof-property-keys.d.ts +3 -3
- package/build/require/type/keyof/keyof-property-keys.js +9 -15
- package/build/require/type/keyof/keyof.js +2 -8
- package/build/require/type/mapped/mapped.d.ts +6 -1
- package/build/require/type/mapped/mapped.js +21 -14
- package/build/require/type/not/not.js +1 -1
- package/build/require/type/object/object.d.ts +1 -1
- package/build/require/type/object/object.js +0 -1
- package/build/require/type/omit/index.d.ts +1 -0
- package/build/require/type/omit/index.js +1 -0
- package/build/require/type/omit/omit-from-mapped-key.js +4 -5
- package/build/require/type/omit/omit-from-mapped-result.d.ts +11 -0
- package/build/require/type/omit/omit-from-mapped-result.js +22 -0
- package/build/require/type/omit/omit.d.ts +6 -3
- package/build/require/type/omit/omit.js +10 -8
- package/build/require/type/optional/optional-from-mapped-result.d.ts +5 -5
- package/build/require/type/optional/optional-from-mapped-result.js +7 -7
- package/build/require/type/partial/partial-from-mapped-result.d.ts +5 -5
- package/build/require/type/partial/partial-from-mapped-result.js +4 -4
- package/build/require/type/partial/partial.d.ts +2 -3
- package/build/require/type/partial/partial.js +8 -21
- package/build/require/type/pick/index.d.ts +1 -0
- package/build/require/type/pick/index.js +1 -0
- package/build/require/type/pick/pick-from-mapped-key.js +4 -5
- package/build/require/type/pick/pick-from-mapped-result.d.ts +11 -0
- package/build/require/type/pick/pick-from-mapped-result.js +22 -0
- package/build/require/type/pick/pick.d.ts +5 -2
- package/build/require/type/pick/pick.js +10 -9
- package/build/require/type/promise/promise.js +1 -1
- package/build/require/type/readonly/readonly-from-mapped-result.d.ts +5 -5
- package/build/require/type/readonly/readonly-from-mapped-result.js +4 -4
- package/build/require/type/record/record.d.ts +5 -3
- package/build/require/type/record/record.js +12 -4
- package/build/require/type/ref/ref.js +1 -1
- package/build/require/type/regexp/regexp.d.ts +11 -4
- package/build/require/type/regexp/regexp.js +3 -3
- package/build/require/type/required/required-from-mapped-result.d.ts +5 -5
- package/build/require/type/required/required-from-mapped-result.js +7 -7
- package/build/require/type/required/required.d.ts +2 -3
- package/build/require/type/required/required.js +4 -14
- package/build/require/type/rest/rest.d.ts +2 -2
- package/build/require/type/rest/rest.js +1 -3
- package/build/require/type/schema/anyschema.d.ts +2 -1
- package/build/require/type/sets/index.d.ts +1 -0
- package/build/require/type/{operators → sets}/index.js +1 -1
- package/build/require/type/sets/set.d.ts +24 -0
- package/build/require/type/sets/set.js +47 -0
- package/build/require/type/strict/strict.d.ts +1 -1
- package/build/require/type/strict/strict.js +1 -1
- package/build/require/type/template-literal/parse.js +1 -1
- package/build/require/type/template-literal/syntax.d.ts +1 -1
- package/build/require/type/template-literal/template-literal.d.ts +1 -1
- package/build/require/type/transform/transform.js +1 -1
- package/build/require/type/type/javascript.d.ts +2 -2
- package/build/require/type/type/javascript.js +1 -1
- package/build/require/type/type/json.d.ts +6 -2
- package/build/require/type/union/union-evaluated.js +3 -14
- 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 +68 -67
- package/build/import/type/operators/index.d.mts +0 -1
- package/build/import/type/operators/index.mjs +0 -1
- package/build/import/type/operators/operators.d.mts +0 -24
- package/build/import/type/operators/operators.mjs +0 -77
- package/build/require/type/operators/index.d.ts +0 -1
- package/build/require/type/operators/operators.d.ts +0 -24
- package/build/require/type/operators/operators.js +0 -89
|
@@ -9,50 +9,13 @@ import { TypeBoxError } from '../../type/error/index.mjs';
|
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
// Errors
|
|
11
11
|
// ------------------------------------------------------------------
|
|
12
|
-
export class
|
|
12
|
+
export class ValueCreateError extends TypeBoxError {
|
|
13
13
|
schema;
|
|
14
|
-
constructor(schema) {
|
|
15
|
-
super(
|
|
14
|
+
constructor(schema, message) {
|
|
15
|
+
super(message);
|
|
16
16
|
this.schema = schema;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
export class ValueCreateNeverTypeError extends TypeBoxError {
|
|
20
|
-
schema;
|
|
21
|
-
constructor(schema) {
|
|
22
|
-
super('Never types cannot be created');
|
|
23
|
-
this.schema = schema;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export class ValueCreateNotTypeError extends TypeBoxError {
|
|
27
|
-
schema;
|
|
28
|
-
constructor(schema) {
|
|
29
|
-
super('Not types must have a default value');
|
|
30
|
-
this.schema = schema;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export class ValueCreateIntersectTypeError extends TypeBoxError {
|
|
34
|
-
schema;
|
|
35
|
-
constructor(schema) {
|
|
36
|
-
super('Intersect produced invalid value. Consider using a default value.');
|
|
37
|
-
this.schema = schema;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
export class ValueCreateTempateLiteralTypeError extends TypeBoxError {
|
|
41
|
-
schema;
|
|
42
|
-
constructor(schema) {
|
|
43
|
-
super('Can only create template literal values from patterns that produce finite sequences. Consider using a default value.');
|
|
44
|
-
this.schema = schema;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export class ValueCreateRecursiveInstantiationError extends TypeBoxError {
|
|
48
|
-
schema;
|
|
49
|
-
recursiveMaxDepth;
|
|
50
|
-
constructor(schema, recursiveMaxDepth) {
|
|
51
|
-
super('Value cannot be created as recursive type may produce value of infinite size. Consider using a default.');
|
|
52
|
-
this.schema = schema;
|
|
53
|
-
this.recursiveMaxDepth = recursiveMaxDepth;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
19
|
// ------------------------------------------------------------------
|
|
57
20
|
// Create
|
|
58
21
|
// ------------------------------------------------------------------
|
|
@@ -66,10 +29,10 @@ function FromAny(schema, references) {
|
|
|
66
29
|
}
|
|
67
30
|
function FromArray(schema, references) {
|
|
68
31
|
if (schema.uniqueItems === true && !HasPropertyKey(schema, 'default')) {
|
|
69
|
-
throw new
|
|
32
|
+
throw new ValueCreateError(schema, 'Array with the uniqueItems constraint requires a default value');
|
|
70
33
|
}
|
|
71
34
|
else if ('contains' in schema && !HasPropertyKey(schema, 'default')) {
|
|
72
|
-
throw new
|
|
35
|
+
throw new ValueCreateError(schema, 'Array with the contains constraint requires a default value');
|
|
73
36
|
}
|
|
74
37
|
else if ('default' in schema) {
|
|
75
38
|
return schema.default;
|
|
@@ -176,7 +139,7 @@ function FromIntersect(schema, references) {
|
|
|
176
139
|
return typeof next === 'object' ? { ...acc, ...next } : next;
|
|
177
140
|
}, {});
|
|
178
141
|
if (!Check(schema, references, value))
|
|
179
|
-
throw new
|
|
142
|
+
throw new ValueCreateError(schema, 'Intersect produced invalid value. Consider using a default value.');
|
|
180
143
|
return value;
|
|
181
144
|
}
|
|
182
145
|
}
|
|
@@ -197,14 +160,19 @@ function FromLiteral(schema, references) {
|
|
|
197
160
|
}
|
|
198
161
|
}
|
|
199
162
|
function FromNever(schema, references) {
|
|
200
|
-
|
|
163
|
+
if (HasPropertyKey(schema, 'default')) {
|
|
164
|
+
return schema.default;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
throw new ValueCreateError(schema, 'Never types cannot be created. Consider using a default value.');
|
|
168
|
+
}
|
|
201
169
|
}
|
|
202
170
|
function FromNot(schema, references) {
|
|
203
171
|
if (HasPropertyKey(schema, 'default')) {
|
|
204
172
|
return schema.default;
|
|
205
173
|
}
|
|
206
174
|
else {
|
|
207
|
-
throw new
|
|
175
|
+
throw new ValueCreateError(schema, 'Not types must have a default value');
|
|
208
176
|
}
|
|
209
177
|
}
|
|
210
178
|
function FromNull(schema, references) {
|
|
@@ -269,10 +237,18 @@ function FromRef(schema, references) {
|
|
|
269
237
|
return Visit(Deref(schema, references), references);
|
|
270
238
|
}
|
|
271
239
|
}
|
|
240
|
+
function FromRegExp(schema, references) {
|
|
241
|
+
if (HasPropertyKey(schema, 'default')) {
|
|
242
|
+
return schema.default;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
throw new ValueCreateError(schema, 'RegExp types cannot be created. Consider using a default value.');
|
|
246
|
+
}
|
|
247
|
+
}
|
|
272
248
|
function FromString(schema, references) {
|
|
273
249
|
if (schema.pattern !== undefined) {
|
|
274
250
|
if (!HasPropertyKey(schema, 'default')) {
|
|
275
|
-
throw new
|
|
251
|
+
throw new ValueCreateError(schema, 'String types with patterns must specify a default value');
|
|
276
252
|
}
|
|
277
253
|
else {
|
|
278
254
|
return schema.default;
|
|
@@ -280,7 +256,7 @@ function FromString(schema, references) {
|
|
|
280
256
|
}
|
|
281
257
|
else if (schema.format !== undefined) {
|
|
282
258
|
if (!HasPropertyKey(schema, 'default')) {
|
|
283
|
-
throw new
|
|
259
|
+
throw new ValueCreateError(schema, 'String types with formats must specify a default value');
|
|
284
260
|
}
|
|
285
261
|
else {
|
|
286
262
|
return schema.default;
|
|
@@ -291,9 +267,8 @@ function FromString(schema, references) {
|
|
|
291
267
|
return schema.default;
|
|
292
268
|
}
|
|
293
269
|
else if (schema.minLength !== undefined) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
.join('');
|
|
270
|
+
// prettier-ignore
|
|
271
|
+
return Array.from({ length: schema.minLength }).map(() => ' ').join('');
|
|
297
272
|
}
|
|
298
273
|
else {
|
|
299
274
|
return '';
|
|
@@ -316,13 +291,13 @@ function FromTemplateLiteral(schema, references) {
|
|
|
316
291
|
return schema.default;
|
|
317
292
|
}
|
|
318
293
|
if (!IsTemplateLiteralFinite(schema))
|
|
319
|
-
throw new
|
|
294
|
+
throw new ValueCreateError(schema, 'Can only create template literals that produce a finite variants. Consider using a default value.');
|
|
320
295
|
const generated = TemplateLiteralGenerate(schema);
|
|
321
296
|
return generated[0];
|
|
322
297
|
}
|
|
323
298
|
function FromThis(schema, references) {
|
|
324
299
|
if (recursiveDepth++ > recursiveMaxDepth)
|
|
325
|
-
throw new
|
|
300
|
+
throw new ValueCreateError(schema, 'Cannot create recursive type as it appears possibly infinite. Consider using a default.');
|
|
326
301
|
if (HasPropertyKey(schema, 'default')) {
|
|
327
302
|
return schema.default;
|
|
328
303
|
}
|
|
@@ -439,6 +414,8 @@ function Visit(schema, references) {
|
|
|
439
414
|
return FromRecord(schema_, references_);
|
|
440
415
|
case 'Ref':
|
|
441
416
|
return FromRef(schema_, references_);
|
|
417
|
+
case 'RegExp':
|
|
418
|
+
return FromRegExp(schema_, references_);
|
|
442
419
|
case 'String':
|
|
443
420
|
return FromString(schema_, references_);
|
|
444
421
|
case 'Symbol':
|
|
@@ -461,7 +438,7 @@ function Visit(schema, references) {
|
|
|
461
438
|
return FromVoid(schema_, references_);
|
|
462
439
|
default:
|
|
463
440
|
if (!TypeRegistry.Has(schema_[Kind]))
|
|
464
|
-
throw new
|
|
441
|
+
throw new ValueCreateError(schema_, 'Unknown type');
|
|
465
442
|
return FromKind(schema_, references_);
|
|
466
443
|
}
|
|
467
444
|
}
|
|
@@ -4,12 +4,10 @@ import { Kind } from '../../type/symbols/index.mjs';
|
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
5
|
// ValueGuard
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
|
-
// prettier-ignore
|
|
8
7
|
import { IsString, IsObject, IsArray, IsUndefined } from '../guard/index.mjs';
|
|
9
8
|
// ------------------------------------------------------------------
|
|
10
9
|
// TypeGuard
|
|
11
10
|
// ------------------------------------------------------------------
|
|
12
|
-
// prettier-ignore
|
|
13
11
|
import { IsSchema } from '../../type/guard/type.mjs';
|
|
14
12
|
// ------------------------------------------------------------------
|
|
15
13
|
// ValueOrDefault
|
|
@@ -30,11 +30,11 @@ export declare const Edit: import("../../type/union/union-type.mjs").TUnion<[imp
|
|
|
30
30
|
type: import("../../type/literal/literal.mjs").TLiteral<"delete">;
|
|
31
31
|
path: import("../../type/string/string.mjs").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
|
}
|
|
@@ -25,17 +25,17 @@ export const Edit = CreateUnion([Insert, Update, Delete]);
|
|
|
25
25
|
// ------------------------------------------------------------------
|
|
26
26
|
// Errors
|
|
27
27
|
// ------------------------------------------------------------------
|
|
28
|
-
export class
|
|
29
|
-
|
|
30
|
-
constructor(
|
|
31
|
-
super(
|
|
32
|
-
this.
|
|
28
|
+
export class ValueDeltaError extends TypeBoxError {
|
|
29
|
+
value;
|
|
30
|
+
constructor(value, message) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.value = value;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
export class
|
|
35
|
+
export class ValueDeltaSymbolError extends ValueDeltaError {
|
|
36
36
|
value;
|
|
37
37
|
constructor(value) {
|
|
38
|
-
super('
|
|
38
|
+
super(value, 'Cannot diff objects with symbol keys');
|
|
39
39
|
this.value = value;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -61,7 +61,7 @@ function* ObjectType(path, current, next) {
|
|
|
61
61
|
const nextKeys = [...globalThis.Object.keys(next), ...globalThis.Object.getOwnPropertySymbols(next)];
|
|
62
62
|
for (const key of currentKeys) {
|
|
63
63
|
if (IsSymbol(key))
|
|
64
|
-
throw new
|
|
64
|
+
throw new ValueDeltaSymbolError(key);
|
|
65
65
|
if (IsUndefined(next[key]) && nextKeys.includes(key))
|
|
66
66
|
yield CreateUpdate(`${path}/${globalThis.String(key)}`, undefined);
|
|
67
67
|
}
|
|
@@ -69,18 +69,18 @@ function* ObjectType(path, current, next) {
|
|
|
69
69
|
if (IsUndefined(current[key]) || IsUndefined(next[key]))
|
|
70
70
|
continue;
|
|
71
71
|
if (IsSymbol(key))
|
|
72
|
-
throw new
|
|
72
|
+
throw new ValueDeltaSymbolError(key);
|
|
73
73
|
yield* Visit(`${path}/${globalThis.String(key)}`, current[key], next[key]);
|
|
74
74
|
}
|
|
75
75
|
for (const key of nextKeys) {
|
|
76
76
|
if (IsSymbol(key))
|
|
77
|
-
throw new
|
|
77
|
+
throw new ValueDeltaSymbolError(key);
|
|
78
78
|
if (IsUndefined(current[key]))
|
|
79
79
|
yield CreateInsert(`${path}/${globalThis.String(key)}`, next[key]);
|
|
80
80
|
}
|
|
81
81
|
for (const key of currentKeys.reverse()) {
|
|
82
82
|
if (IsSymbol(key))
|
|
83
|
-
throw new
|
|
83
|
+
throw new ValueDeltaSymbolError(key);
|
|
84
84
|
if (IsUndefined(next[key]) && !nextKeys.includes(key))
|
|
85
85
|
yield CreateDelete(`${path}/${globalThis.String(key)}`);
|
|
86
86
|
}
|
|
@@ -123,7 +123,7 @@ function* Visit(path, current, next) {
|
|
|
123
123
|
return yield* TypedArrayType(path, current, next);
|
|
124
124
|
if (IsValueType(current))
|
|
125
125
|
return yield* ValueType(path, current, next);
|
|
126
|
-
throw new
|
|
126
|
+
throw new ValueDeltaError(current, 'Unable to create diff edits for unknown value');
|
|
127
127
|
}
|
|
128
128
|
// ------------------------------------------------------------------
|
|
129
129
|
// Diff
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export { ValueError, ValueErrorType, ValueErrorIterator } from '../errors/index.mjs';
|
|
2
|
-
export { Cast,
|
|
2
|
+
export { Cast, ValueCastError } from './cast/index.mjs';
|
|
3
3
|
export { Check } from './check/index.mjs';
|
|
4
4
|
export { Clean } from './clean/index.mjs';
|
|
5
5
|
export { Clone } from './clone/index.mjs';
|
|
6
|
-
export { Convert
|
|
7
|
-
export { Create,
|
|
6
|
+
export { Convert } from './convert/index.mjs';
|
|
7
|
+
export { Create, ValueCreateError } from './create/index.mjs';
|
|
8
8
|
export { Default } from './default/index.mjs';
|
|
9
|
-
export { Diff, Patch, Edit, Delete, Insert, Update,
|
|
9
|
+
export { Diff, Patch, Edit, Delete, Insert, Update, ValueDeltaError } from './delta/index.mjs';
|
|
10
10
|
export { Equal } from './equal/index.mjs';
|
|
11
11
|
export { Hash, ValueHashError } from './hash/index.mjs';
|
|
12
|
-
export { Mutate, type Mutable
|
|
12
|
+
export { Mutate, ValueMutateError, type Mutable } from './mutate/index.mjs';
|
|
13
13
|
export { ValuePointer } from './pointer/index.mjs';
|
|
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.mjs';
|
|
14
|
+
export { TransformDecode, TransformEncode, HasTransform, TransformDecodeCheckError, TransformDecodeError, TransformEncodeCheckError, TransformEncodeError } from './transform/index.mjs';
|
|
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.mjs';
|
|
16
16
|
export { Value } from './value/index.mjs';
|
|
@@ -5,19 +5,19 @@ export { ValueErrorType, ValueErrorIterator } from '../errors/index.mjs';
|
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
6
|
// Value Operators
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
|
-
export { Cast,
|
|
8
|
+
export { Cast, ValueCastError } from './cast/index.mjs';
|
|
9
9
|
export { Check } from './check/index.mjs';
|
|
10
10
|
export { Clean } from './clean/index.mjs';
|
|
11
11
|
export { Clone } from './clone/index.mjs';
|
|
12
|
-
export { Convert
|
|
13
|
-
export { Create,
|
|
12
|
+
export { Convert } from './convert/index.mjs';
|
|
13
|
+
export { Create, ValueCreateError } from './create/index.mjs';
|
|
14
14
|
export { Default } from './default/index.mjs';
|
|
15
|
-
export { Diff, Patch, Edit, Delete, Insert, Update,
|
|
15
|
+
export { Diff, Patch, Edit, Delete, Insert, Update, ValueDeltaError } from './delta/index.mjs';
|
|
16
16
|
export { Equal } from './equal/index.mjs';
|
|
17
17
|
export { Hash, ValueHashError } from './hash/index.mjs';
|
|
18
|
-
export { Mutate,
|
|
18
|
+
export { Mutate, ValueMutateError } from './mutate/index.mjs';
|
|
19
19
|
export { ValuePointer } from './pointer/index.mjs';
|
|
20
|
-
export { TransformDecode
|
|
20
|
+
export { TransformDecode, TransformEncode, HasTransform, TransformDecodeCheckError, TransformDecodeError, TransformEncodeCheckError, TransformEncodeError } from './transform/index.mjs';
|
|
21
21
|
// ------------------------------------------------------------------
|
|
22
22
|
// Value Guards
|
|
23
23
|
// ------------------------------------------------------------------
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { TypeBoxError } from '../../type/error/index.mjs';
|
|
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;
|
|
@@ -5,14 +5,9 @@ import { TypeBoxError } from '../../type/error/index.mjs';
|
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
6
|
// Errors
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
|
-
export class
|
|
9
|
-
constructor() {
|
|
10
|
-
super(
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export class ValueMutateInvalidRootMutationError extends TypeBoxError {
|
|
14
|
-
constructor() {
|
|
15
|
-
super('Only object and array types can be mutated at the root level');
|
|
8
|
+
export class ValueMutateError extends TypeBoxError {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
16
11
|
}
|
|
17
12
|
}
|
|
18
13
|
function ObjectType(root, path, current, next) {
|
|
@@ -90,8 +85,8 @@ function IsMismatchedValue(current, next) {
|
|
|
90
85
|
/** `[Mutable]` Performs a deep mutable value assignment while retaining internal references */
|
|
91
86
|
export function Mutate(current, next) {
|
|
92
87
|
if (IsNonMutableValue(current) || IsNonMutableValue(next))
|
|
93
|
-
throw new
|
|
88
|
+
throw new ValueMutateError('Only object and array types can be mutated at the root level');
|
|
94
89
|
if (IsMismatchedValue(current, next))
|
|
95
|
-
throw new
|
|
90
|
+
throw new ValueMutateError('Cannot assign due type mismatch of assignable values');
|
|
96
91
|
Visit(current, '', current, next);
|
|
97
92
|
}
|
|
@@ -384,6 +384,11 @@ var TypeCompiler;
|
|
|
384
384
|
return yield `${CreateFunctionName(schema.$ref)}(${value})`;
|
|
385
385
|
yield* Visit(target, references, value);
|
|
386
386
|
}
|
|
387
|
+
function* FromRegExp(schema, references, value) {
|
|
388
|
+
const variable = CreateVariable(`${new RegExp(schema.source, schema.flags)};`);
|
|
389
|
+
yield `(typeof ${value} === 'string')`;
|
|
390
|
+
yield `${variable}.test(${value})`;
|
|
391
|
+
}
|
|
387
392
|
function* FromString(schema, references, value) {
|
|
388
393
|
yield `(typeof ${value} === 'string')`;
|
|
389
394
|
if ((0, index_11.IsNumber)(schema.maxLength))
|
|
@@ -503,6 +508,8 @@ var TypeCompiler;
|
|
|
503
508
|
return yield* FromRecord(schema_, references_, value);
|
|
504
509
|
case 'Ref':
|
|
505
510
|
return yield* FromRef(schema_, references_, value);
|
|
511
|
+
case 'RegExp':
|
|
512
|
+
return yield* FromRegExp(schema_, references_, value);
|
|
506
513
|
case 'String':
|
|
507
514
|
return yield* FromString(schema_, references_, value);
|
|
508
515
|
case 'Symbol':
|
|
@@ -49,21 +49,22 @@ export declare enum ValueErrorType {
|
|
|
49
49
|
ObjectRequiredProperty = 45,
|
|
50
50
|
Object = 46,
|
|
51
51
|
Promise = 47,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
52
|
+
RegExp = 48,
|
|
53
|
+
StringFormatUnknown = 49,
|
|
54
|
+
StringFormat = 50,
|
|
55
|
+
StringMaxLength = 51,
|
|
56
|
+
StringMinLength = 52,
|
|
57
|
+
StringPattern = 53,
|
|
58
|
+
String = 54,
|
|
59
|
+
Symbol = 55,
|
|
60
|
+
TupleLength = 56,
|
|
61
|
+
Tuple = 57,
|
|
62
|
+
Uint8ArrayMaxByteLength = 58,
|
|
63
|
+
Uint8ArrayMinByteLength = 59,
|
|
64
|
+
Uint8Array = 60,
|
|
65
|
+
Undefined = 61,
|
|
66
|
+
Union = 62,
|
|
67
|
+
Void = 63
|
|
67
68
|
}
|
|
68
69
|
export interface ValueError {
|
|
69
70
|
type: ValueErrorType;
|
|
@@ -70,21 +70,22 @@ var ValueErrorType;
|
|
|
70
70
|
ValueErrorType[ValueErrorType["ObjectRequiredProperty"] = 45] = "ObjectRequiredProperty";
|
|
71
71
|
ValueErrorType[ValueErrorType["Object"] = 46] = "Object";
|
|
72
72
|
ValueErrorType[ValueErrorType["Promise"] = 47] = "Promise";
|
|
73
|
-
ValueErrorType[ValueErrorType["
|
|
74
|
-
ValueErrorType[ValueErrorType["
|
|
75
|
-
ValueErrorType[ValueErrorType["
|
|
76
|
-
ValueErrorType[ValueErrorType["
|
|
77
|
-
ValueErrorType[ValueErrorType["
|
|
78
|
-
ValueErrorType[ValueErrorType["
|
|
79
|
-
ValueErrorType[ValueErrorType["
|
|
80
|
-
ValueErrorType[ValueErrorType["
|
|
81
|
-
ValueErrorType[ValueErrorType["
|
|
82
|
-
ValueErrorType[ValueErrorType["
|
|
83
|
-
ValueErrorType[ValueErrorType["
|
|
84
|
-
ValueErrorType[ValueErrorType["
|
|
85
|
-
ValueErrorType[ValueErrorType["
|
|
86
|
-
ValueErrorType[ValueErrorType["
|
|
87
|
-
ValueErrorType[ValueErrorType["
|
|
73
|
+
ValueErrorType[ValueErrorType["RegExp"] = 48] = "RegExp";
|
|
74
|
+
ValueErrorType[ValueErrorType["StringFormatUnknown"] = 49] = "StringFormatUnknown";
|
|
75
|
+
ValueErrorType[ValueErrorType["StringFormat"] = 50] = "StringFormat";
|
|
76
|
+
ValueErrorType[ValueErrorType["StringMaxLength"] = 51] = "StringMaxLength";
|
|
77
|
+
ValueErrorType[ValueErrorType["StringMinLength"] = 52] = "StringMinLength";
|
|
78
|
+
ValueErrorType[ValueErrorType["StringPattern"] = 53] = "StringPattern";
|
|
79
|
+
ValueErrorType[ValueErrorType["String"] = 54] = "String";
|
|
80
|
+
ValueErrorType[ValueErrorType["Symbol"] = 55] = "Symbol";
|
|
81
|
+
ValueErrorType[ValueErrorType["TupleLength"] = 56] = "TupleLength";
|
|
82
|
+
ValueErrorType[ValueErrorType["Tuple"] = 57] = "Tuple";
|
|
83
|
+
ValueErrorType[ValueErrorType["Uint8ArrayMaxByteLength"] = 58] = "Uint8ArrayMaxByteLength";
|
|
84
|
+
ValueErrorType[ValueErrorType["Uint8ArrayMinByteLength"] = 59] = "Uint8ArrayMinByteLength";
|
|
85
|
+
ValueErrorType[ValueErrorType["Uint8Array"] = 60] = "Uint8Array";
|
|
86
|
+
ValueErrorType[ValueErrorType["Undefined"] = 61] = "Undefined";
|
|
87
|
+
ValueErrorType[ValueErrorType["Union"] = 62] = "Union";
|
|
88
|
+
ValueErrorType[ValueErrorType["Void"] = 63] = "Void";
|
|
88
89
|
})(ValueErrorType || (exports.ValueErrorType = ValueErrorType = {}));
|
|
89
90
|
// ------------------------------------------------------------------
|
|
90
91
|
// ValueErrors
|
|
@@ -395,6 +396,12 @@ function* FromRecord(schema, references, path, value) {
|
|
|
395
396
|
function* FromRef(schema, references, path, value) {
|
|
396
397
|
yield* Visit((0, index_5.Deref)(schema, references), references, path, value);
|
|
397
398
|
}
|
|
399
|
+
function* FromRegExp(schema, references, path, value) {
|
|
400
|
+
const regex = new RegExp(schema.source, schema.flags);
|
|
401
|
+
if (!regex.test(value)) {
|
|
402
|
+
return yield Create(ValueErrorType.RegExp, schema, path, value);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
398
405
|
function* FromString(schema, references, path, value) {
|
|
399
406
|
if (!(0, index_9.IsString)(value))
|
|
400
407
|
return yield Create(ValueErrorType.String, schema, path, value);
|
|
@@ -533,6 +540,8 @@ function* Visit(schema, references, path, value) {
|
|
|
533
540
|
return yield* FromRecord(schema_, references_, path, value);
|
|
534
541
|
case 'Ref':
|
|
535
542
|
return yield* FromRef(schema_, references_, path, value);
|
|
543
|
+
case 'RegExp':
|
|
544
|
+
return yield* FromRegExp(schema_, references_, path, value);
|
|
536
545
|
case 'String':
|
|
537
546
|
return yield* FromString(schema_, references_, path, value);
|
|
538
547
|
case 'Symbol':
|
|
@@ -101,6 +101,8 @@ function DefaultErrorFunction(error) {
|
|
|
101
101
|
return 'Required property';
|
|
102
102
|
case errors_1.ValueErrorType.Promise:
|
|
103
103
|
return 'Expected Promise';
|
|
104
|
+
case errors_1.ValueErrorType.RegExp:
|
|
105
|
+
return 'Expected string to match regular expression';
|
|
104
106
|
case errors_1.ValueErrorType.StringFormatUnknown:
|
|
105
107
|
return `Unknown format '${error.schema.format}'`;
|
|
106
108
|
case errors_1.ValueErrorType.StringFormat:
|
package/build/require/index.d.ts
CHANGED
|
@@ -36,11 +36,11 @@ export { Not, type TNot } from './type/not/index';
|
|
|
36
36
|
export { Null, type TNull } from './type/null/index';
|
|
37
37
|
export { Number, type TNumber, type NumberOptions } from './type/number/index';
|
|
38
38
|
export { Object, type TObject, type TProperties, type ObjectOptions } from './type/object/index';
|
|
39
|
-
export { Omit, type TOmit, type TOmitFromMappedKey } from './type/omit/index';
|
|
39
|
+
export { Omit, type TOmit, type TOmitFromMappedKey, type TOmitFromMappedResult } from './type/omit/index';
|
|
40
40
|
export { Optional, OptionalFromMappedResult, type TOptional, type TOptionalWithFlag, type TOptionalFromMappedResult } from './type/optional/index';
|
|
41
41
|
export { Parameters, type TParameters } from './type/parameters/index';
|
|
42
42
|
export { Partial, PartialFromMappedResult, type TPartial, type TPartialFromMappedResult } from './type/partial/index';
|
|
43
|
-
export { Pick, type TPick, type TPickFromMappedKey } from './type/pick/index';
|
|
43
|
+
export { Pick, type TPick, type TPickFromMappedKey, type TPickFromMappedResult } from './type/pick/index';
|
|
44
44
|
export { Promise, type TPromise } from './type/promise/index';
|
|
45
45
|
export { Readonly, ReadonlyFromMappedResult, type TReadonly, type TReadonlyWithFlag, type TReadonlyFromMappedResult } from './type/readonly/index';
|
|
46
46
|
export { ReadonlyOptional, type TReadonlyOptional } from './type/readonly-optional/index';
|
|
@@ -8,14 +8,10 @@ const type_1 = require("../clone/type");
|
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
9
|
// TypeGuard
|
|
10
10
|
// ------------------------------------------------------------------
|
|
11
|
-
// prettier-ignore
|
|
12
11
|
const type_2 = require("../guard/type");
|
|
13
12
|
// prettier-ignore
|
|
14
|
-
function FromRest(T
|
|
15
|
-
|
|
16
|
-
return (T.length > 0
|
|
17
|
-
? FromRest(R, [...Acc, FromSchema(L)])
|
|
18
|
-
: Acc);
|
|
13
|
+
function FromRest(T) {
|
|
14
|
+
return T.map(L => FromSchema(L));
|
|
19
15
|
}
|
|
20
16
|
// prettier-ignore
|
|
21
17
|
function FromIntersect(T) {
|
|
@@ -12,6 +12,9 @@ function DateType(value) {
|
|
|
12
12
|
function Uint8ArrayType(value) {
|
|
13
13
|
return new Uint8Array(value);
|
|
14
14
|
}
|
|
15
|
+
function RegExpType(value) {
|
|
16
|
+
return new RegExp(value.source, value.flags);
|
|
17
|
+
}
|
|
15
18
|
function ObjectType(value) {
|
|
16
19
|
const clonedProperties = Object.getOwnPropertyNames(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), {});
|
|
17
20
|
const clonedSymbols = Object.getOwnPropertySymbols(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), {});
|
|
@@ -22,8 +25,9 @@ function Visit(value) {
|
|
|
22
25
|
return (ValueGuard.IsArray(value) ? ArrayType(value) :
|
|
23
26
|
ValueGuard.IsDate(value) ? DateType(value) :
|
|
24
27
|
ValueGuard.IsUint8Array(value) ? Uint8ArrayType(value) :
|
|
25
|
-
ValueGuard.
|
|
26
|
-
value)
|
|
28
|
+
ValueGuard.IsRegExp(value) ? RegExpType(value) :
|
|
29
|
+
ValueGuard.IsObject(value) ? ObjectType(value) :
|
|
30
|
+
value);
|
|
27
31
|
}
|
|
28
32
|
/** Clones a value */
|
|
29
33
|
function Clone(value) {
|
|
@@ -7,8 +7,7 @@ type TCompositeIndex<T extends TIntersect<TObject[]>, K extends string[], Acc ex
|
|
|
7
7
|
[_ in L]: TIndex<T, [L]>;
|
|
8
8
|
}> : Acc;
|
|
9
9
|
type TCompositeReduce<T extends TObject[]> = UnionToTuple<TCompositeKeys<T>> extends infer K ? Evaluate<TCompositeIndex<TIntersect<T>, Assert<K, string[]>>> : {};
|
|
10
|
-
|
|
11
|
-
export declare function CompositeResolve<T extends TObject[]>(T: [...T]): TCompositeResolve<T>;
|
|
10
|
+
type TCompositeResolve<T extends TObject[]> = TIntersect<T> extends TIntersect ? TObject<TCompositeReduce<T>> : TObject<{}>;
|
|
12
11
|
export type TComposite<T extends TObject[]> = TCompositeResolve<T>;
|
|
13
12
|
/** `[Json]` Creates a Composite object type */
|
|
14
13
|
export declare function Composite<T extends TObject[]>(T: [...T], options?: ObjectOptions): TComposite<T>;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Composite =
|
|
4
|
+
exports.Composite = void 0;
|
|
5
5
|
const index_1 = require("../object/index");
|
|
6
6
|
const index_2 = require("../intersect/index");
|
|
7
|
-
const index_3 = require("../
|
|
8
|
-
const index_4 = require("../
|
|
7
|
+
const index_3 = require("../indexed/index");
|
|
8
|
+
const index_4 = require("../keyof/index");
|
|
9
9
|
const type_1 = require("../clone/type");
|
|
10
10
|
function CompositeResolve(T) {
|
|
11
11
|
const intersect = (0, index_2.Intersect)(T, {});
|
|
12
|
-
const keys = (0,
|
|
13
|
-
const properties = keys.reduce((acc, key) => ({ ...acc, [key]: (0,
|
|
12
|
+
const keys = (0, index_4.KeyOfPropertyKeys)(intersect);
|
|
13
|
+
const properties = keys.reduce((acc, key) => ({ ...acc, [key]: (0, index_3.Index)(intersect, [key]) }), {});
|
|
14
14
|
return (0, index_1.Object)(properties);
|
|
15
15
|
}
|
|
16
|
-
exports.CompositeResolve = CompositeResolve;
|
|
17
16
|
/** `[Json]` Creates a Composite object type */
|
|
18
17
|
function Composite(T, options) {
|
|
19
18
|
return (0, type_1.CloneType)(CompositeResolve(T), options);
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Const = void 0;
|
|
5
|
-
const value_1 = require("../guard/value");
|
|
6
5
|
const index_1 = require("../any/index");
|
|
7
6
|
const index_2 = require("../bigint/index");
|
|
8
7
|
const index_3 = require("../date/index");
|
|
@@ -17,12 +16,13 @@ const index_11 = require("../undefined/index");
|
|
|
17
16
|
const index_12 = require("../uint8array/index");
|
|
18
17
|
const index_13 = require("../unknown/index");
|
|
19
18
|
const index_14 = require("../clone/index");
|
|
19
|
+
// ------------------------------------------------------------------
|
|
20
|
+
// ValueGuard
|
|
21
|
+
// ------------------------------------------------------------------
|
|
22
|
+
const value_1 = require("../guard/value");
|
|
20
23
|
// prettier-ignore
|
|
21
24
|
function FromArray(T) {
|
|
22
|
-
|
|
23
|
-
return (T.length > 0
|
|
24
|
-
? [FromValue(L, false), ...FromArray(R)]
|
|
25
|
-
: []);
|
|
25
|
+
return T.map(L => FromValue(L, false));
|
|
26
26
|
}
|
|
27
27
|
// prettier-ignore
|
|
28
28
|
function FromProperties(value) {
|
|
@@ -37,7 +37,7 @@ function ConditionalReadonly(T, root) {
|
|
|
37
37
|
function FromValue(value, root) {
|
|
38
38
|
return ((0, value_1.IsAsyncIterator)(value) ? ConditionalReadonly((0, index_1.Any)(), root) :
|
|
39
39
|
(0, value_1.IsIterator)(value) ? ConditionalReadonly((0, index_1.Any)(), root) :
|
|
40
|
-
(0, value_1.IsArray)(value) ? (0, index_10.Readonly)((0, index_9.Tuple)(FromArray(value))) :
|
|
40
|
+
(0, value_1.IsArray)(value) ? (0, index_10.Readonly)((0, index_9.Tuple)(FromArray(value))) :
|
|
41
41
|
(0, value_1.IsUint8Array)(value) ? (0, index_12.Uint8Array)() :
|
|
42
42
|
(0, value_1.IsDate)(value) ? (0, index_3.Date)() :
|
|
43
43
|
(0, value_1.IsObject)(value) ? ConditionalReadonly((0, index_7.Object)(FromProperties(value)), root) :
|
|
@@ -4,7 +4,7 @@ import type { Ensure } from '../helpers/index';
|
|
|
4
4
|
import { Kind } from '../symbols/index';
|
|
5
5
|
type ConstructorStaticReturnType<T extends TSchema, P extends unknown[]> = Static<T, P>;
|
|
6
6
|
type ConstructorStaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? ConstructorStaticParameters<R, P, [...Acc, Static<L, P>]> : Acc;
|
|
7
|
-
|
|
7
|
+
type ConstructorStatic<T extends TSchema[], U extends TSchema, P extends unknown[]> = (Ensure<new (...param: ConstructorStaticParameters<T, P>) => ConstructorStaticReturnType<U, P>>);
|
|
8
8
|
export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
9
9
|
[Kind]: 'Constructor';
|
|
10
10
|
static: ConstructorStatic<T, U, this['params']>;
|