@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
|
@@ -384,6 +384,11 @@ export 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 (IsNumber(schema.maxLength))
|
|
@@ -503,6 +508,8 @@ export 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;
|
|
@@ -66,21 +66,22 @@ export var ValueErrorType;
|
|
|
66
66
|
ValueErrorType[ValueErrorType["ObjectRequiredProperty"] = 45] = "ObjectRequiredProperty";
|
|
67
67
|
ValueErrorType[ValueErrorType["Object"] = 46] = "Object";
|
|
68
68
|
ValueErrorType[ValueErrorType["Promise"] = 47] = "Promise";
|
|
69
|
-
ValueErrorType[ValueErrorType["
|
|
70
|
-
ValueErrorType[ValueErrorType["
|
|
71
|
-
ValueErrorType[ValueErrorType["
|
|
72
|
-
ValueErrorType[ValueErrorType["
|
|
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["
|
|
69
|
+
ValueErrorType[ValueErrorType["RegExp"] = 48] = "RegExp";
|
|
70
|
+
ValueErrorType[ValueErrorType["StringFormatUnknown"] = 49] = "StringFormatUnknown";
|
|
71
|
+
ValueErrorType[ValueErrorType["StringFormat"] = 50] = "StringFormat";
|
|
72
|
+
ValueErrorType[ValueErrorType["StringMaxLength"] = 51] = "StringMaxLength";
|
|
73
|
+
ValueErrorType[ValueErrorType["StringMinLength"] = 52] = "StringMinLength";
|
|
74
|
+
ValueErrorType[ValueErrorType["StringPattern"] = 53] = "StringPattern";
|
|
75
|
+
ValueErrorType[ValueErrorType["String"] = 54] = "String";
|
|
76
|
+
ValueErrorType[ValueErrorType["Symbol"] = 55] = "Symbol";
|
|
77
|
+
ValueErrorType[ValueErrorType["TupleLength"] = 56] = "TupleLength";
|
|
78
|
+
ValueErrorType[ValueErrorType["Tuple"] = 57] = "Tuple";
|
|
79
|
+
ValueErrorType[ValueErrorType["Uint8ArrayMaxByteLength"] = 58] = "Uint8ArrayMaxByteLength";
|
|
80
|
+
ValueErrorType[ValueErrorType["Uint8ArrayMinByteLength"] = 59] = "Uint8ArrayMinByteLength";
|
|
81
|
+
ValueErrorType[ValueErrorType["Uint8Array"] = 60] = "Uint8Array";
|
|
82
|
+
ValueErrorType[ValueErrorType["Undefined"] = 61] = "Undefined";
|
|
83
|
+
ValueErrorType[ValueErrorType["Union"] = 62] = "Union";
|
|
84
|
+
ValueErrorType[ValueErrorType["Void"] = 63] = "Void";
|
|
84
85
|
})(ValueErrorType || (ValueErrorType = {}));
|
|
85
86
|
// ------------------------------------------------------------------
|
|
86
87
|
// ValueErrors
|
|
@@ -391,6 +392,12 @@ function* FromRecord(schema, references, path, value) {
|
|
|
391
392
|
function* FromRef(schema, references, path, value) {
|
|
392
393
|
yield* Visit(Deref(schema, references), references, path, value);
|
|
393
394
|
}
|
|
395
|
+
function* FromRegExp(schema, references, path, value) {
|
|
396
|
+
const regex = new RegExp(schema.source, schema.flags);
|
|
397
|
+
if (!regex.test(value)) {
|
|
398
|
+
return yield Create(ValueErrorType.RegExp, schema, path, value);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
394
401
|
function* FromString(schema, references, path, value) {
|
|
395
402
|
if (!IsString(value))
|
|
396
403
|
return yield Create(ValueErrorType.String, schema, path, value);
|
|
@@ -529,6 +536,8 @@ function* Visit(schema, references, path, value) {
|
|
|
529
536
|
return yield* FromRecord(schema_, references_, path, value);
|
|
530
537
|
case 'Ref':
|
|
531
538
|
return yield* FromRef(schema_, references_, path, value);
|
|
539
|
+
case 'RegExp':
|
|
540
|
+
return yield* FromRegExp(schema_, references_, path, value);
|
|
532
541
|
case 'String':
|
|
533
542
|
return yield* FromString(schema_, references_, path, value);
|
|
534
543
|
case 'Symbol':
|
|
@@ -97,6 +97,8 @@ export function DefaultErrorFunction(error) {
|
|
|
97
97
|
return 'Required property';
|
|
98
98
|
case ValueErrorType.Promise:
|
|
99
99
|
return 'Expected Promise';
|
|
100
|
+
case ValueErrorType.RegExp:
|
|
101
|
+
return 'Expected string to match regular expression';
|
|
100
102
|
case ValueErrorType.StringFormatUnknown:
|
|
101
103
|
return `Unknown format '${error.schema.format}'`;
|
|
102
104
|
case ValueErrorType.StringFormat:
|
package/build/import/index.d.mts
CHANGED
|
@@ -36,11 +36,11 @@ export { Not, type TNot } from './type/not/index.mjs';
|
|
|
36
36
|
export { Null, type TNull } from './type/null/index.mjs';
|
|
37
37
|
export { Number, type TNumber, type NumberOptions } from './type/number/index.mjs';
|
|
38
38
|
export { Object, type TObject, type TProperties, type ObjectOptions } from './type/object/index.mjs';
|
|
39
|
-
export { Omit, type TOmit, type TOmitFromMappedKey } from './type/omit/index.mjs';
|
|
39
|
+
export { Omit, type TOmit, type TOmitFromMappedKey, type TOmitFromMappedResult } from './type/omit/index.mjs';
|
|
40
40
|
export { Optional, OptionalFromMappedResult, type TOptional, type TOptionalWithFlag, type TOptionalFromMappedResult } from './type/optional/index.mjs';
|
|
41
41
|
export { Parameters, type TParameters } from './type/parameters/index.mjs';
|
|
42
42
|
export { Partial, PartialFromMappedResult, type TPartial, type TPartialFromMappedResult } from './type/partial/index.mjs';
|
|
43
|
-
export { Pick, type TPick, type TPickFromMappedKey } from './type/pick/index.mjs';
|
|
43
|
+
export { Pick, type TPick, type TPickFromMappedKey, type TPickFromMappedResult } from './type/pick/index.mjs';
|
|
44
44
|
export { Promise, type TPromise } from './type/promise/index.mjs';
|
|
45
45
|
export { Readonly, ReadonlyFromMappedResult, type TReadonly, type TReadonlyWithFlag, type TReadonlyFromMappedResult } from './type/readonly/index.mjs';
|
|
46
46
|
export { ReadonlyOptional, type TReadonlyOptional } from './type/readonly-optional/index.mjs';
|
|
@@ -4,14 +4,10 @@ import { CloneType } from '../clone/type.mjs';
|
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
5
|
// TypeGuard
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
|
-
// prettier-ignore
|
|
8
7
|
import { IsIntersect, IsUnion, IsPromise } from '../guard/type.mjs';
|
|
9
8
|
// prettier-ignore
|
|
10
|
-
function FromRest(T
|
|
11
|
-
|
|
12
|
-
return (T.length > 0
|
|
13
|
-
? FromRest(R, [...Acc, FromSchema(L)])
|
|
14
|
-
: Acc);
|
|
9
|
+
function FromRest(T) {
|
|
10
|
+
return T.map(L => FromSchema(L));
|
|
15
11
|
}
|
|
16
12
|
// prettier-ignore
|
|
17
13
|
function FromIntersect(T) {
|
|
@@ -8,6 +8,9 @@ function DateType(value) {
|
|
|
8
8
|
function Uint8ArrayType(value) {
|
|
9
9
|
return new Uint8Array(value);
|
|
10
10
|
}
|
|
11
|
+
function RegExpType(value) {
|
|
12
|
+
return new RegExp(value.source, value.flags);
|
|
13
|
+
}
|
|
11
14
|
function ObjectType(value) {
|
|
12
15
|
const clonedProperties = Object.getOwnPropertyNames(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), {});
|
|
13
16
|
const clonedSymbols = Object.getOwnPropertySymbols(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), {});
|
|
@@ -18,8 +21,9 @@ function Visit(value) {
|
|
|
18
21
|
return (ValueGuard.IsArray(value) ? ArrayType(value) :
|
|
19
22
|
ValueGuard.IsDate(value) ? DateType(value) :
|
|
20
23
|
ValueGuard.IsUint8Array(value) ? Uint8ArrayType(value) :
|
|
21
|
-
ValueGuard.
|
|
22
|
-
value)
|
|
24
|
+
ValueGuard.IsRegExp(value) ? RegExpType(value) :
|
|
25
|
+
ValueGuard.IsObject(value) ? ObjectType(value) :
|
|
26
|
+
value);
|
|
23
27
|
}
|
|
24
28
|
/** Clones a value */
|
|
25
29
|
export 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,9 +1,9 @@
|
|
|
1
1
|
import { Object } from '../object/index.mjs';
|
|
2
2
|
import { Intersect } from '../intersect/index.mjs';
|
|
3
|
-
import { KeyOfPropertyKeys } from '../keyof/index.mjs';
|
|
4
3
|
import { Index } from '../indexed/index.mjs';
|
|
4
|
+
import { KeyOfPropertyKeys } from '../keyof/index.mjs';
|
|
5
5
|
import { CloneType } from '../clone/type.mjs';
|
|
6
|
-
|
|
6
|
+
function CompositeResolve(T) {
|
|
7
7
|
const intersect = Intersect(T, {});
|
|
8
8
|
const keys = KeyOfPropertyKeys(intersect);
|
|
9
9
|
const properties = keys.reduce((acc, key) => ({ ...acc, [key]: Index(intersect, [key]) }), {});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { IsArray, IsNumber, IsBigInt, IsUint8Array, IsDate, IsIterator, IsObject, IsAsyncIterator, IsFunction, IsUndefined, IsNull, IsSymbol, IsBoolean, IsString } from '../guard/value.mjs';
|
|
2
1
|
import { Any } from '../any/index.mjs';
|
|
3
2
|
import { BigInt } from '../bigint/index.mjs';
|
|
4
3
|
import { Date } from '../date/index.mjs';
|
|
@@ -13,12 +12,13 @@ import { Undefined } from '../undefined/index.mjs';
|
|
|
13
12
|
import { Uint8Array } from '../uint8array/index.mjs';
|
|
14
13
|
import { Unknown } from '../unknown/index.mjs';
|
|
15
14
|
import { TypeClone } from '../clone/index.mjs';
|
|
15
|
+
// ------------------------------------------------------------------
|
|
16
|
+
// ValueGuard
|
|
17
|
+
// ------------------------------------------------------------------
|
|
18
|
+
import { IsArray, IsNumber, IsBigInt, IsUint8Array, IsDate, IsIterator, IsObject, IsAsyncIterator, IsFunction, IsUndefined, IsNull, IsSymbol, IsBoolean, IsString } from '../guard/value.mjs';
|
|
16
19
|
// prettier-ignore
|
|
17
20
|
function FromArray(T) {
|
|
18
|
-
|
|
19
|
-
return (T.length > 0
|
|
20
|
-
? [FromValue(L, false), ...FromArray(R)]
|
|
21
|
-
: []);
|
|
21
|
+
return T.map(L => FromValue(L, false));
|
|
22
22
|
}
|
|
23
23
|
// prettier-ignore
|
|
24
24
|
function FromProperties(value) {
|
|
@@ -33,7 +33,7 @@ function ConditionalReadonly(T, root) {
|
|
|
33
33
|
function FromValue(value, root) {
|
|
34
34
|
return (IsAsyncIterator(value) ? ConditionalReadonly(Any(), root) :
|
|
35
35
|
IsIterator(value) ? ConditionalReadonly(Any(), root) :
|
|
36
|
-
IsArray(value) ? Readonly(Tuple(FromArray(value))) :
|
|
36
|
+
IsArray(value) ? Readonly(Tuple(FromArray(value))) :
|
|
37
37
|
IsUint8Array(value) ? Uint8Array() :
|
|
38
38
|
IsDate(value) ? Date() :
|
|
39
39
|
IsObject(value) ? ConditionalReadonly(Object(FromProperties(value)), root) :
|
|
@@ -4,7 +4,7 @@ import type { Ensure } from '../helpers/index.mjs';
|
|
|
4
4
|
import { Kind } from '../symbols/index.mjs';
|
|
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']>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Kind } from '../symbols/index.mjs';
|
|
2
1
|
import { CloneType, CloneRest } from '../clone/type.mjs';
|
|
2
|
+
import { Kind } from '../symbols/index.mjs';
|
|
3
3
|
/** `[JavaScript]` Creates a Constructor type */
|
|
4
4
|
export function Constructor(parameters, returns, options) {
|
|
5
5
|
return {
|
|
@@ -4,8 +4,7 @@ import { IsUndefined } from '../guard/value.mjs';
|
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
5
|
// TypeGuard
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
|
-
|
|
8
|
-
import { IsConstructor, IsFunction, IsIntersect, IsUnion, IsTuple, IsArray, IsObject, IsPromise, IsAsyncIterator, IsIterator, IsRef, } from '../guard/type.mjs';
|
|
7
|
+
import { IsConstructor, IsFunction, IsIntersect, IsUnion, IsTuple, IsArray, IsObject, IsPromise, IsAsyncIterator, IsIterator, IsRef } from '../guard/type.mjs';
|
|
9
8
|
function FromRest(schema, references) {
|
|
10
9
|
return schema.map((schema) => Deref(schema, references));
|
|
11
10
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
function
|
|
1
|
+
function DiscardKey(value, key) {
|
|
2
2
|
const { [key]: _, ...rest } = value;
|
|
3
3
|
return rest;
|
|
4
4
|
}
|
|
5
5
|
export function Discard(value, keys) {
|
|
6
|
-
return keys.reduce((acc, key) =>
|
|
6
|
+
return keys.reduce((acc, key) => DiscardKey(acc, key), value);
|
|
7
7
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Literal } from '../literal/index.mjs';
|
|
2
2
|
import { Kind, Hint } from '../symbols/index.mjs';
|
|
3
3
|
import { Union } from '../union/index.mjs';
|
|
4
|
+
// ------------------------------------------------------------------
|
|
5
|
+
// ValueGuard
|
|
6
|
+
// ------------------------------------------------------------------
|
|
4
7
|
import { IsUndefined } from '../guard/value.mjs';
|
|
5
8
|
/** `[Json]` Creates a Enum type */
|
|
6
9
|
export function Enum(item, options = {}) {
|
|
@@ -2,10 +2,10 @@ import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
|
2
2
|
import type { TProperties } from '../object/index.mjs';
|
|
3
3
|
import { type TMappedResult } from '../mapped/index.mjs';
|
|
4
4
|
import { type TExclude } from './exclude.mjs';
|
|
5
|
-
type TFromProperties<K extends TProperties,
|
|
6
|
-
[K2 in keyof K]: TExclude<K[K2],
|
|
5
|
+
type TFromProperties<K extends TProperties, T extends TSchema> = ({
|
|
6
|
+
[K2 in keyof K]: TExclude<K[K2], T>;
|
|
7
7
|
});
|
|
8
|
-
type TFromMappedResult<
|
|
9
|
-
export type TExcludeFromMappedResult<
|
|
10
|
-
export declare function ExcludeFromMappedResult<
|
|
8
|
+
type TFromMappedResult<R extends TMappedResult, T extends TSchema> = (TFromProperties<R['properties'], T>);
|
|
9
|
+
export type TExcludeFromMappedResult<R extends TMappedResult, T extends TSchema, P extends TProperties = TFromMappedResult<R, T>> = (TMappedResult<P>);
|
|
10
|
+
export declare function ExcludeFromMappedResult<R extends TMappedResult, T extends TSchema, P extends TProperties = TFromMappedResult<R, T>>(R: R, T: T, options: SchemaOptions): TMappedResult<P>;
|
|
11
11
|
export {};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { MappedResult } from '../mapped/index.mjs';
|
|
2
2
|
import { Exclude } from './exclude.mjs';
|
|
3
3
|
// prettier-ignore
|
|
4
|
-
function FromProperties(
|
|
5
|
-
return globalThis.Object.getOwnPropertyNames(
|
|
6
|
-
return { ...Acc, [K2]: Exclude(
|
|
4
|
+
function FromProperties(P, U, options) {
|
|
5
|
+
return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
|
|
6
|
+
return { ...Acc, [K2]: Exclude(P[K2], U, options) };
|
|
7
7
|
}, {});
|
|
8
8
|
}
|
|
9
9
|
// prettier-ignore
|
|
10
|
-
function FromMappedResult(
|
|
11
|
-
return FromProperties(
|
|
10
|
+
function FromMappedResult(R, T, options) {
|
|
11
|
+
return FromProperties(R.properties, T, options);
|
|
12
12
|
}
|
|
13
13
|
// prettier-ignore
|
|
14
|
-
export function ExcludeFromMappedResult(
|
|
15
|
-
const P = FromMappedResult(
|
|
14
|
+
export function ExcludeFromMappedResult(R, T, options) {
|
|
15
|
+
const P = FromMappedResult(R, T, options);
|
|
16
16
|
return MappedResult(P);
|
|
17
17
|
}
|
|
@@ -7,7 +7,6 @@ import { ExcludeFromMappedResult } from './exclude-from-mapped-result.mjs';
|
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
8
|
// TypeGuard
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
|
-
// prettier-ignore
|
|
11
10
|
import { IsMappedResult, IsTemplateLiteral, IsUnion } from '../guard/type.mjs';
|
|
12
11
|
// prettier-ignore
|
|
13
12
|
function ExcludeResolve(L, R) {
|