@sinclair/typebox 0.33.22 → 0.34.1
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/cjs/compiler/compiler.d.ts +2 -2
- package/build/cjs/compiler/compiler.js +13 -2
- package/build/cjs/errors/errors.js +7 -0
- package/build/cjs/index.d.ts +1 -2
- package/build/cjs/index.js +1 -2
- package/build/cjs/syntax/parse.d.ts +14 -15
- package/build/cjs/syntax/parse.js +6 -5
- package/build/cjs/syntax/runtime.d.ts +20 -4
- package/build/cjs/syntax/runtime.js +183 -28
- package/build/cjs/syntax/static.d.ts +107 -23
- package/build/cjs/type/array/array.d.ts +1 -1
- package/build/cjs/type/awaited/awaited.d.ts +8 -3
- package/build/cjs/type/awaited/awaited.js +20 -20
- package/build/cjs/type/computed/computed.d.ts +9 -0
- package/build/cjs/type/computed/computed.js +10 -0
- package/build/cjs/type/computed/index.d.ts +1 -0
- package/build/cjs/type/{deref → computed}/index.js +1 -1
- package/build/cjs/type/guard/kind.d.ts +12 -4
- package/build/cjs/type/guard/kind.js +15 -0
- package/build/cjs/type/guard/type.d.ts +9 -3
- package/build/cjs/type/guard/type.js +19 -0
- package/build/cjs/type/index.d.ts +1 -2
- package/build/cjs/type/index.js +1 -2
- package/build/cjs/type/indexed/indexed-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/indexed/indexed-from-mapped-key.js +10 -10
- package/build/cjs/type/indexed/indexed-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/indexed/indexed-from-mapped-result.js +11 -10
- package/build/cjs/type/indexed/indexed-property-keys.d.ts +6 -6
- package/build/cjs/type/indexed/indexed-property-keys.js +14 -14
- package/build/cjs/type/indexed/indexed.d.ts +34 -20
- package/build/cjs/type/indexed/indexed.js +59 -46
- package/build/cjs/type/intersect/intersect-evaluated.d.ts +6 -6
- package/build/cjs/type/intersect/intersect-evaluated.js +16 -16
- package/build/cjs/type/intersect/intersect.d.ts +2 -2
- package/build/cjs/type/intersect/intersect.js +6 -6
- package/build/cjs/type/keyof/keyof-from-mapped-result.d.ts +6 -6
- package/build/cjs/type/keyof/keyof-from-mapped-result.js +10 -10
- package/build/cjs/type/keyof/keyof-property-keys.d.ts +7 -7
- package/build/cjs/type/keyof/keyof-property-keys.js +22 -22
- package/build/cjs/type/keyof/keyof.d.ts +11 -6
- package/build/cjs/type/keyof/keyof.js +22 -13
- package/build/cjs/type/module/compute.d.ts +54 -0
- package/build/cjs/type/module/compute.js +154 -0
- package/build/cjs/type/module/index.d.ts +1 -0
- package/build/cjs/type/{strict → module}/index.js +1 -1
- package/build/cjs/type/module/infer.d.ts +43 -0
- package/build/cjs/type/module/infer.js +3 -0
- package/build/cjs/type/module/module.d.ts +27 -0
- package/build/cjs/type/module/module.js +37 -0
- package/build/cjs/type/not/not.d.ts +1 -1
- package/build/cjs/type/not/not.js +2 -2
- package/build/cjs/type/omit/omit-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/omit/omit-from-mapped-key.js +10 -12
- package/build/cjs/type/omit/omit-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/omit/omit-from-mapped-result.js +10 -10
- package/build/cjs/type/omit/omit.d.ts +26 -14
- package/build/cjs/type/omit/omit.js +46 -35
- package/build/cjs/type/partial/partial.d.ts +11 -7
- package/build/cjs/type/partial/partial.js +36 -24
- package/build/cjs/type/pick/pick-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/pick/pick-from-mapped-key.js +10 -10
- package/build/cjs/type/pick/pick-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/pick/pick-from-mapped-result.js +10 -10
- package/build/cjs/type/pick/pick.d.ts +25 -15
- package/build/cjs/type/pick/pick.js +47 -36
- package/build/cjs/type/record/record.d.ts +4 -2
- package/build/cjs/type/record/record.js +31 -28
- package/build/cjs/type/ref/ref.d.ts +4 -7
- package/build/cjs/type/ref/ref.js +3 -11
- package/build/cjs/type/required/required.d.ts +12 -8
- package/build/cjs/type/required/required.js +37 -25
- package/build/cjs/type/static/static.d.ts +1 -1
- package/build/cjs/type/tuple/tuple.d.ts +1 -1
- package/build/cjs/type/tuple/tuple.js +4 -4
- package/build/cjs/type/type/javascript.d.ts +10 -10
- package/build/cjs/type/type/javascript.js +6 -6
- package/build/cjs/type/type/json.d.ts +45 -68
- package/build/cjs/type/type/json.js +82 -98
- package/build/cjs/type/type/type.d.ts +1 -2
- package/build/cjs/type/type/type.js +55 -57
- package/build/cjs/type/union/union-evaluated.d.ts +6 -6
- package/build/cjs/type/union/union-evaluated.js +11 -10
- package/build/cjs/type/union/union.d.ts +1 -1
- package/build/cjs/type/union/union.js +4 -4
- package/build/cjs/value/cast/cast.js +8 -1
- package/build/cjs/value/check/check.js +11 -4
- package/build/cjs/value/clean/clean.js +8 -1
- package/build/cjs/value/convert/convert.js +7 -0
- package/build/cjs/value/create/create.js +7 -0
- package/build/cjs/value/default/default.js +7 -0
- package/build/cjs/value/transform/decode.js +18 -7
- package/build/cjs/value/transform/encode.js +18 -7
- package/build/cjs/value/transform/has.js +18 -18
- package/build/esm/compiler/compiler.d.mts +2 -2
- package/build/esm/compiler/compiler.mjs +13 -2
- package/build/esm/errors/errors.mjs +7 -0
- package/build/esm/index.d.mts +1 -2
- package/build/esm/index.mjs +1 -2
- package/build/esm/syntax/parse.d.mts +14 -15
- package/build/esm/syntax/parse.mjs +6 -5
- package/build/esm/syntax/runtime.d.mts +20 -4
- package/build/esm/syntax/runtime.mjs +183 -28
- package/build/esm/syntax/static.d.mts +107 -23
- package/build/esm/type/array/array.d.mts +1 -1
- package/build/esm/type/awaited/awaited.d.mts +8 -3
- package/build/esm/type/awaited/awaited.mjs +20 -20
- package/build/esm/type/computed/computed.d.mts +9 -0
- package/build/esm/type/computed/computed.mjs +6 -0
- package/build/esm/type/computed/index.d.mts +1 -0
- package/build/esm/type/computed/index.mjs +1 -0
- package/build/esm/type/guard/kind.d.mts +12 -4
- package/build/esm/type/guard/kind.mjs +12 -0
- package/build/esm/type/guard/type.d.mts +9 -3
- package/build/esm/type/guard/type.mjs +17 -0
- package/build/esm/type/index.d.mts +1 -2
- package/build/esm/type/index.mjs +1 -2
- package/build/esm/type/indexed/indexed-from-mapped-key.d.mts +6 -6
- package/build/esm/type/indexed/indexed-from-mapped-key.mjs +10 -10
- package/build/esm/type/indexed/indexed-from-mapped-result.d.mts +5 -5
- package/build/esm/type/indexed/indexed-from-mapped-result.mjs +11 -10
- package/build/esm/type/indexed/indexed-property-keys.d.mts +6 -6
- package/build/esm/type/indexed/indexed-property-keys.mjs +14 -14
- package/build/esm/type/indexed/indexed.d.mts +34 -20
- package/build/esm/type/indexed/indexed.mjs +55 -42
- package/build/esm/type/intersect/intersect-evaluated.d.mts +6 -6
- package/build/esm/type/intersect/intersect-evaluated.mjs +16 -16
- package/build/esm/type/intersect/intersect.d.mts +2 -2
- package/build/esm/type/intersect/intersect.mjs +6 -6
- package/build/esm/type/keyof/keyof-from-mapped-result.d.mts +6 -6
- package/build/esm/type/keyof/keyof-from-mapped-result.mjs +10 -10
- package/build/esm/type/keyof/keyof-property-keys.d.mts +7 -7
- package/build/esm/type/keyof/keyof-property-keys.mjs +22 -22
- package/build/esm/type/keyof/keyof.d.mts +11 -6
- package/build/esm/type/keyof/keyof.mjs +22 -13
- package/build/esm/type/module/compute.d.mts +54 -0
- package/build/esm/type/module/compute.mjs +148 -0
- package/build/esm/type/module/index.d.mts +1 -0
- package/build/esm/type/module/index.mjs +1 -0
- package/build/esm/type/module/infer.d.mts +43 -0
- package/build/esm/type/module/infer.mjs +1 -0
- package/build/esm/type/module/module.d.mts +27 -0
- package/build/esm/type/module/module.mjs +31 -0
- package/build/esm/type/not/not.d.mts +1 -1
- package/build/esm/type/not/not.mjs +2 -2
- package/build/esm/type/omit/omit-from-mapped-key.d.mts +6 -6
- package/build/esm/type/omit/omit-from-mapped-key.mjs +10 -12
- package/build/esm/type/omit/omit-from-mapped-result.d.mts +5 -5
- package/build/esm/type/omit/omit-from-mapped-result.mjs +10 -10
- package/build/esm/type/omit/omit.d.mts +26 -14
- package/build/esm/type/omit/omit.mjs +43 -32
- package/build/esm/type/partial/partial.d.mts +11 -7
- package/build/esm/type/partial/partial.mjs +29 -17
- package/build/esm/type/pick/pick-from-mapped-key.d.mts +6 -6
- package/build/esm/type/pick/pick-from-mapped-key.mjs +10 -10
- package/build/esm/type/pick/pick-from-mapped-result.d.mts +5 -5
- package/build/esm/type/pick/pick-from-mapped-result.mjs +10 -10
- package/build/esm/type/pick/pick.d.mts +25 -15
- package/build/esm/type/pick/pick.mjs +43 -32
- package/build/esm/type/record/record.d.mts +4 -2
- package/build/esm/type/record/record.mjs +15 -12
- package/build/esm/type/ref/ref.d.mts +4 -7
- package/build/esm/type/ref/ref.mjs +3 -11
- package/build/esm/type/required/required.d.mts +12 -8
- package/build/esm/type/required/required.mjs +33 -21
- package/build/esm/type/static/static.d.mts +1 -1
- package/build/esm/type/tuple/tuple.d.mts +1 -1
- package/build/esm/type/tuple/tuple.mjs +4 -4
- package/build/esm/type/type/javascript.d.mts +10 -10
- package/build/esm/type/type/javascript.mjs +6 -6
- package/build/esm/type/type/json.d.mts +45 -68
- package/build/esm/type/type/json.mjs +47 -63
- package/build/esm/type/type/type.d.mts +1 -2
- package/build/esm/type/type/type.mjs +1 -2
- package/build/esm/type/union/union-evaluated.d.mts +6 -6
- package/build/esm/type/union/union-evaluated.mjs +11 -10
- package/build/esm/type/union/union.d.mts +1 -1
- package/build/esm/type/union/union.mjs +4 -4
- package/build/esm/value/cast/cast.mjs +9 -2
- package/build/esm/value/check/check.mjs +11 -4
- package/build/esm/value/clean/clean.mjs +9 -2
- package/build/esm/value/convert/convert.mjs +7 -0
- package/build/esm/value/create/create.mjs +7 -0
- package/build/esm/value/default/default.mjs +7 -0
- package/build/esm/value/transform/decode.mjs +13 -2
- package/build/esm/value/transform/encode.mjs +13 -2
- package/build/esm/value/transform/has.mjs +2 -2
- package/package.json +1 -1
- package/readme.md +230 -97
- package/build/cjs/type/deref/deref.d.ts +0 -22
- package/build/cjs/type/deref/deref.js +0 -106
- package/build/cjs/type/deref/index.d.ts +0 -1
- package/build/cjs/type/strict/index.d.ts +0 -1
- package/build/cjs/type/strict/strict.d.ts +0 -12
- package/build/cjs/type/strict/strict.js +0 -16
- package/build/esm/type/deref/deref.d.mts +0 -22
- package/build/esm/type/deref/deref.mjs +0 -102
- package/build/esm/type/deref/index.d.mts +0 -1
- package/build/esm/type/deref/index.mjs +0 -1
- package/build/esm/type/strict/index.d.mts +0 -1
- package/build/esm/type/strict/index.mjs +0 -1
- package/build/esm/type/strict/strict.d.mts +0 -12
- package/build/esm/type/strict/strict.mjs +0 -12
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Record = Record;
|
|
5
5
|
const type_1 = require("../create/type");
|
|
6
|
-
const index_1 = require("../
|
|
7
|
-
const index_2 = require("../
|
|
8
|
-
const index_3 = require("../
|
|
9
|
-
const index_4 = require("../
|
|
10
|
-
const index_5 = require("../
|
|
11
|
-
const index_6 = require("../
|
|
12
|
-
const index_7 = require("../
|
|
6
|
+
const index_1 = require("../computed/index");
|
|
7
|
+
const index_2 = require("../object/index");
|
|
8
|
+
const index_3 = require("../never/index");
|
|
9
|
+
const index_4 = require("../union/index");
|
|
10
|
+
const index_5 = require("../template-literal/index");
|
|
11
|
+
const index_6 = require("../patterns/index");
|
|
12
|
+
const index_7 = require("../indexed/index");
|
|
13
|
+
const index_8 = require("../symbols/index");
|
|
13
14
|
// ------------------------------------------------------------------
|
|
14
15
|
// ValueGuard
|
|
15
16
|
// ------------------------------------------------------------------
|
|
@@ -24,7 +25,7 @@ const kind_1 = require("../guard/kind");
|
|
|
24
25
|
// prettier-ignore
|
|
25
26
|
function RecordCreateFromPattern(pattern, T, options) {
|
|
26
27
|
return (0, type_1.CreateType)({
|
|
27
|
-
[
|
|
28
|
+
[index_8.Kind]: 'Record',
|
|
28
29
|
type: 'object',
|
|
29
30
|
patternProperties: { [pattern]: T }
|
|
30
31
|
}, options);
|
|
@@ -37,17 +38,17 @@ function RecordCreateFromKeys(K, T, options) {
|
|
|
37
38
|
const Acc = {};
|
|
38
39
|
for (const K2 of K)
|
|
39
40
|
Acc[K2] = T;
|
|
40
|
-
return (0,
|
|
41
|
+
return (0, index_2.Object)(Acc, { ...options, [index_8.Hint]: 'Record' });
|
|
41
42
|
}
|
|
42
43
|
// prettier-ignore
|
|
43
44
|
function FromTemplateLiteralKey(K, T, options) {
|
|
44
|
-
return ((0,
|
|
45
|
-
? RecordCreateFromKeys((0,
|
|
45
|
+
return ((0, index_5.IsTemplateLiteralFinite)(K)
|
|
46
|
+
? RecordCreateFromKeys((0, index_7.IndexPropertyKeys)(K), T, options)
|
|
46
47
|
: RecordCreateFromPattern(K.pattern, T, options));
|
|
47
48
|
}
|
|
48
49
|
// prettier-ignore
|
|
49
50
|
function FromUnionKey(K, T, options) {
|
|
50
|
-
return RecordCreateFromKeys((0,
|
|
51
|
+
return RecordCreateFromKeys((0, index_7.IndexPropertyKeys)((0, index_4.Union)(K)), T, options);
|
|
51
52
|
}
|
|
52
53
|
// prettier-ignore
|
|
53
54
|
function FromLiteralKey(K, T, options) {
|
|
@@ -59,39 +60,41 @@ function FromRegExpKey(K, T, options) {
|
|
|
59
60
|
}
|
|
60
61
|
// prettier-ignore
|
|
61
62
|
function FromStringKey(K, T, options) {
|
|
62
|
-
const pattern = (0, value_1.IsUndefined)(K.pattern) ?
|
|
63
|
+
const pattern = (0, value_1.IsUndefined)(K.pattern) ? index_6.PatternStringExact : K.pattern;
|
|
63
64
|
return RecordCreateFromPattern(pattern, T, options);
|
|
64
65
|
}
|
|
65
66
|
// prettier-ignore
|
|
66
67
|
function FromAnyKey(K, T, options) {
|
|
67
|
-
return RecordCreateFromPattern(
|
|
68
|
+
return RecordCreateFromPattern(index_6.PatternStringExact, T, options);
|
|
68
69
|
}
|
|
69
70
|
// prettier-ignore
|
|
70
71
|
function FromNeverKey(K, T, options) {
|
|
71
|
-
return RecordCreateFromPattern(
|
|
72
|
+
return RecordCreateFromPattern(index_6.PatternNeverExact, T, options);
|
|
72
73
|
}
|
|
73
74
|
// prettier-ignore
|
|
74
75
|
function FromIntegerKey(_, T, options) {
|
|
75
|
-
return RecordCreateFromPattern(
|
|
76
|
+
return RecordCreateFromPattern(index_6.PatternNumberExact, T, options);
|
|
76
77
|
}
|
|
77
78
|
// prettier-ignore
|
|
78
79
|
function FromNumberKey(_, T, options) {
|
|
79
|
-
return RecordCreateFromPattern(
|
|
80
|
+
return RecordCreateFromPattern(index_6.PatternNumberExact, T, options);
|
|
80
81
|
}
|
|
81
82
|
// ------------------------------------------------------------------
|
|
82
83
|
// TRecordOrObject
|
|
83
84
|
// ------------------------------------------------------------------
|
|
84
85
|
/** `[Json]` Creates a Record type */
|
|
85
|
-
function Record(
|
|
86
|
+
function Record(key, type, options = {}) {
|
|
86
87
|
// prettier-ignore
|
|
87
|
-
return ((0, kind_1.
|
|
88
|
-
(0, kind_1.
|
|
89
|
-
(0, kind_1.
|
|
90
|
-
(0, kind_1.
|
|
91
|
-
(0, kind_1.
|
|
92
|
-
(0, kind_1.
|
|
93
|
-
(0, kind_1.
|
|
94
|
-
(0, kind_1.
|
|
95
|
-
(0, kind_1.
|
|
96
|
-
(0,
|
|
88
|
+
return ((0, kind_1.IsRef)(type) ? (0, index_1.Computed)('Record', [key, type]) :
|
|
89
|
+
(0, kind_1.IsRef)(key) ? (0, index_1.Computed)('Record', [key, type]) :
|
|
90
|
+
(0, kind_1.IsUnion)(key) ? FromUnionKey(key.anyOf, type, options) :
|
|
91
|
+
(0, kind_1.IsTemplateLiteral)(key) ? FromTemplateLiteralKey(key, type, options) :
|
|
92
|
+
(0, kind_1.IsLiteral)(key) ? FromLiteralKey(key.const, type, options) :
|
|
93
|
+
(0, kind_1.IsInteger)(key) ? FromIntegerKey(key, type, options) :
|
|
94
|
+
(0, kind_1.IsNumber)(key) ? FromNumberKey(key, type, options) :
|
|
95
|
+
(0, kind_1.IsRegExp)(key) ? FromRegExpKey(key, type, options) :
|
|
96
|
+
(0, kind_1.IsString)(key) ? FromStringKey(key, type, options) :
|
|
97
|
+
(0, kind_1.IsAny)(key) ? FromAnyKey(key, type, options) :
|
|
98
|
+
(0, kind_1.IsNever)(key) ? FromNeverKey(key, type, options) :
|
|
99
|
+
(0, index_3.Never)(options));
|
|
97
100
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index';
|
|
2
|
-
import type { Static } from '../static/index';
|
|
3
2
|
import { Kind } from '../symbols/index';
|
|
4
|
-
export interface TRef<
|
|
3
|
+
export interface TRef<Ref extends string = string> extends TSchema {
|
|
5
4
|
[Kind]: 'Ref';
|
|
6
|
-
static:
|
|
7
|
-
$ref:
|
|
5
|
+
static: unknown;
|
|
6
|
+
$ref: Ref;
|
|
8
7
|
}
|
|
9
8
|
/** `[Json]` Creates a Ref type. The referenced type must contain a $id */
|
|
10
|
-
export declare function Ref<
|
|
11
|
-
/** `[Json]` Creates a Ref type. */
|
|
12
|
-
export declare function Ref<T extends TSchema>($ref: string, options?: SchemaOptions): TRef<T>;
|
|
9
|
+
export declare function Ref<Ref extends string>($ref: Ref, options?: SchemaOptions): TRef<Ref>;
|
|
@@ -4,15 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.Ref = Ref;
|
|
5
5
|
const type_1 = require("../create/type");
|
|
6
6
|
const index_1 = require("../symbols/index");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const value_1 = require("../guard/value");
|
|
11
|
-
/** `[Json]` Creates a Ref type. */
|
|
12
|
-
function Ref(unresolved, options) {
|
|
13
|
-
if ((0, value_1.IsString)(unresolved))
|
|
14
|
-
return (0, type_1.CreateType)({ [index_1.Kind]: 'Ref', $ref: unresolved }, options);
|
|
15
|
-
if ((0, value_1.IsUndefined)(unresolved.$id))
|
|
16
|
-
throw new Error('Reference target type must specify an $id');
|
|
17
|
-
return (0, type_1.CreateType)({ [index_1.Kind]: 'Ref', $ref: unresolved.$id }, options);
|
|
7
|
+
/** `[Json]` Creates a Ref type. The referenced type must contain a $id */
|
|
8
|
+
function Ref($ref, options) {
|
|
9
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'Ref', $ref }, options);
|
|
18
10
|
}
|
|
@@ -2,21 +2,25 @@ import type { TSchema, SchemaOptions } from '../schema/index';
|
|
|
2
2
|
import type { Evaluate, Ensure } from '../helpers/index';
|
|
3
3
|
import type { TMappedResult } from '../mapped/index';
|
|
4
4
|
import { type TReadonlyOptional } from '../readonly-optional/index';
|
|
5
|
+
import { type TComputed } from '../computed/index';
|
|
5
6
|
import { type TOptional } from '../optional/index';
|
|
6
7
|
import { type TReadonly } from '../readonly/index';
|
|
7
8
|
import { type TRecursive } from '../recursive/index';
|
|
9
|
+
import { type TObject, type TProperties } from '../object/index';
|
|
8
10
|
import { type TIntersect } from '../intersect/index';
|
|
9
11
|
import { type TUnion } from '../union/index';
|
|
10
|
-
import { type
|
|
12
|
+
import { type TRef } from '../ref/index';
|
|
11
13
|
import { type TRequiredFromMappedResult } from './required-from-mapped-result';
|
|
12
|
-
type
|
|
13
|
-
type
|
|
14
|
-
|
|
14
|
+
type TFromComputed<Target extends string, Parameters extends TSchema[]> = Ensure<TComputed<'Required', [TComputed<Target, Parameters>]>>;
|
|
15
|
+
type TFromRef<Ref extends string> = Ensure<TComputed<'Required', [TRef<Ref>]>>;
|
|
16
|
+
type TFromProperties<Properties extends TProperties> = Evaluate<{
|
|
17
|
+
[K in keyof Properties]: Properties[K] extends (TReadonlyOptional<infer S>) ? TReadonly<S> : Properties[K] extends (TReadonly<infer S>) ? TReadonly<S> : Properties[K] extends (TOptional<infer S>) ? S : Properties[K];
|
|
15
18
|
}>;
|
|
16
|
-
type TFromObject<
|
|
17
|
-
|
|
19
|
+
type TFromObject<Type extends TObject, Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties>)>>;
|
|
20
|
+
type TFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Result, TRequired<L>]> : Result);
|
|
21
|
+
export type TRequired<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TRequired<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject<Properties>> : TObject<{}>);
|
|
18
22
|
/** `[Json]` Constructs a type where all properties are required */
|
|
19
|
-
export declare function Required<
|
|
23
|
+
export declare function Required<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TRequiredFromMappedResult<MappedResult>;
|
|
20
24
|
/** `[Json]` Constructs a type where all properties are required */
|
|
21
|
-
export declare function Required<
|
|
25
|
+
export declare function Required<Type extends TSchema>(type: Type, options?: SchemaOptions): TRequired<Type>;
|
|
22
26
|
export {};
|
|
@@ -3,50 +3,62 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Required = Required;
|
|
5
5
|
const type_1 = require("../create/type");
|
|
6
|
-
const index_1 = require("../
|
|
7
|
-
const index_2 = require("../
|
|
8
|
-
const index_3 = require("../
|
|
9
|
-
const index_4 = require("../
|
|
10
|
-
const index_5 = require("../
|
|
6
|
+
const index_1 = require("../computed/index");
|
|
7
|
+
const index_2 = require("../object/index");
|
|
8
|
+
const index_3 = require("../intersect/index");
|
|
9
|
+
const index_4 = require("../union/index");
|
|
10
|
+
const index_5 = require("../ref/index");
|
|
11
|
+
const index_6 = require("../symbols/index");
|
|
12
|
+
const index_7 = require("../discard/index");
|
|
11
13
|
const required_from_mapped_result_1 = require("./required-from-mapped-result");
|
|
12
14
|
// ------------------------------------------------------------------
|
|
13
15
|
// TypeGuard
|
|
14
16
|
// ------------------------------------------------------------------
|
|
15
17
|
const kind_1 = require("../guard/kind");
|
|
16
18
|
// prettier-ignore
|
|
17
|
-
function
|
|
18
|
-
return
|
|
19
|
+
function FromComputed(target, parameters) {
|
|
20
|
+
return (0, index_1.Computed)('Required', [(0, index_1.Computed)(target, parameters)]);
|
|
19
21
|
}
|
|
20
22
|
// prettier-ignore
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
for (const K of globalThis.Object.getOwnPropertyNames(T))
|
|
24
|
-
Acc[K] = (0, index_5.Discard)(T[K], [index_4.OptionalKind]);
|
|
25
|
-
return Acc;
|
|
23
|
+
function FromRef($ref) {
|
|
24
|
+
return (0, index_1.Computed)('Required', [(0, index_5.Ref)($ref)]);
|
|
26
25
|
}
|
|
27
26
|
// prettier-ignore
|
|
28
|
-
function
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
27
|
+
function FromProperties(properties) {
|
|
28
|
+
const requiredProperties = {};
|
|
29
|
+
for (const K of globalThis.Object.getOwnPropertyNames(properties))
|
|
30
|
+
requiredProperties[K] = (0, index_7.Discard)(properties[K], [index_6.OptionalKind]);
|
|
31
|
+
return requiredProperties;
|
|
32
|
+
}
|
|
33
|
+
// prettier-ignore
|
|
34
|
+
function FromObject(type) {
|
|
35
|
+
const options = (0, index_7.Discard)(type, [index_6.TransformKind, '$id', 'required', 'properties']);
|
|
36
|
+
const properties = FromProperties(type['properties']);
|
|
37
|
+
return (0, index_2.Object)(properties, options);
|
|
38
|
+
}
|
|
39
|
+
// prettier-ignore
|
|
40
|
+
function FromRest(types) {
|
|
41
|
+
return types.map(type => RequiredResolve(type));
|
|
32
42
|
}
|
|
33
43
|
// ------------------------------------------------------------------
|
|
34
44
|
// RequiredResolve
|
|
35
45
|
// ------------------------------------------------------------------
|
|
36
46
|
// prettier-ignore
|
|
37
|
-
function RequiredResolve(
|
|
38
|
-
return ((0, kind_1.
|
|
39
|
-
(0, kind_1.
|
|
40
|
-
(0, kind_1.
|
|
41
|
-
(0,
|
|
47
|
+
function RequiredResolve(type) {
|
|
48
|
+
return ((0, kind_1.IsComputed)(type) ? FromComputed(type.target, type.parameters) :
|
|
49
|
+
(0, kind_1.IsRef)(type) ? FromRef(type.$ref) :
|
|
50
|
+
(0, kind_1.IsIntersect)(type) ? (0, index_3.Intersect)(FromRest(type.allOf)) :
|
|
51
|
+
(0, kind_1.IsUnion)(type) ? (0, index_4.Union)(FromRest(type.anyOf)) :
|
|
52
|
+
(0, kind_1.IsObject)(type) ? FromObject(type) :
|
|
53
|
+
(0, index_2.Object)({}));
|
|
42
54
|
}
|
|
43
55
|
/** `[Json]` Constructs a type where all properties are required */
|
|
44
|
-
function Required(
|
|
45
|
-
if ((0, kind_1.IsMappedResult)(
|
|
46
|
-
return (0, required_from_mapped_result_1.RequiredFromMappedResult)(
|
|
56
|
+
function Required(type, options) {
|
|
57
|
+
if ((0, kind_1.IsMappedResult)(type)) {
|
|
58
|
+
return (0, required_from_mapped_result_1.RequiredFromMappedResult)(type, options);
|
|
47
59
|
}
|
|
48
60
|
else {
|
|
49
61
|
// special: mapping types require overridable options
|
|
50
|
-
return (0, type_1.CreateType)({ ...RequiredResolve(
|
|
62
|
+
return (0, type_1.CreateType)({ ...RequiredResolve(type), ...options });
|
|
51
63
|
}
|
|
52
64
|
}
|
|
@@ -23,7 +23,7 @@ export type TDecodeProperties<T extends TProperties> = {
|
|
|
23
23
|
[K in keyof T]: TDecodeType<T[K]>;
|
|
24
24
|
};
|
|
25
25
|
export type TDecodeRest<T extends TSchema[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TDecodeRest<R, [...Acc, TDecodeType<L>]> : Acc;
|
|
26
|
-
export type TDecodeType<T extends TSchema> = (T extends TOptional<infer S extends TSchema> ? TOptional<TDecodeType<S>> : T extends TReadonly<infer S extends TSchema> ? TReadonly<TDecodeType<S>> : T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S extends TSchema> ? TArray<TDecodeType<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<TDecodeType<S>> : T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<TDecodeRest<P>, TDecodeType<R>> : T extends TEnum<infer S> ? TEnum<S> : T extends TFunction<infer P extends TSchema[], infer R extends TSchema> ? TFunction<TDecodeRest<P>, TDecodeType<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<TDecodeRest<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<TDecodeType<S>> : T extends TNot<infer S extends TSchema> ? TNot<TDecodeType<S>> : T extends TObject<infer S> ? TObject<Evaluate<TDecodeProperties<S>>> : T extends TPromise<infer S extends TSchema> ? TPromise<TDecodeType<S>> : T extends TRecord<infer K, infer S> ? TRecord<K, TDecodeType<S>> : T extends TRecursive<infer S extends TSchema> ? TRecursive<TDecodeType<S>> : T extends TRef<infer S extends
|
|
26
|
+
export type TDecodeType<T extends TSchema> = (T extends TOptional<infer S extends TSchema> ? TOptional<TDecodeType<S>> : T extends TReadonly<infer S extends TSchema> ? TReadonly<TDecodeType<S>> : T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S extends TSchema> ? TArray<TDecodeType<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<TDecodeType<S>> : T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<TDecodeRest<P>, TDecodeType<R>> : T extends TEnum<infer S> ? TEnum<S> : T extends TFunction<infer P extends TSchema[], infer R extends TSchema> ? TFunction<TDecodeRest<P>, TDecodeType<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<TDecodeRest<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<TDecodeType<S>> : T extends TNot<infer S extends TSchema> ? TNot<TDecodeType<S>> : T extends TObject<infer S> ? TObject<Evaluate<TDecodeProperties<S>>> : T extends TPromise<infer S extends TSchema> ? TPromise<TDecodeType<S>> : T extends TRecord<infer K, infer S> ? TRecord<K, TDecodeType<S>> : T extends TRecursive<infer S extends TSchema> ? TRecursive<TDecodeType<S>> : T extends TRef<infer S extends string> ? TRef<S> : T extends TTuple<infer S extends TSchema[]> ? TTuple<TDecodeRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<TDecodeRest<S>> : T);
|
|
27
27
|
export type StaticDecodeIsAny<T> = boolean extends (T extends TSchema ? true : false) ? true : false;
|
|
28
28
|
/** Creates an decoded static type from a TypeBox type */
|
|
29
29
|
export type StaticDecode<T extends TSchema, P extends unknown[] = []> = StaticDecodeIsAny<T> extends true ? unknown : Static<TDecodeType<T>, P>;
|
|
@@ -12,5 +12,5 @@ export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
|
|
|
12
12
|
maxItems: number;
|
|
13
13
|
}
|
|
14
14
|
/** `[Json]` Creates a Tuple type */
|
|
15
|
-
export declare function Tuple<
|
|
15
|
+
export declare function Tuple<Types extends TSchema[]>(types: [...Types], options?: SchemaOptions): TTuple<Types>;
|
|
16
16
|
export {};
|
|
@@ -5,9 +5,9 @@ exports.Tuple = Tuple;
|
|
|
5
5
|
const type_1 = require("../create/type");
|
|
6
6
|
const index_1 = require("../symbols/index");
|
|
7
7
|
/** `[Json]` Creates a Tuple type */
|
|
8
|
-
function Tuple(
|
|
8
|
+
function Tuple(types, options) {
|
|
9
9
|
// prettier-ignore
|
|
10
|
-
return (0, type_1.CreateType)(
|
|
11
|
-
{ [index_1.Kind]: 'Tuple', type: 'array', items, additionalItems: false, minItems:
|
|
12
|
-
{ [index_1.Kind]: 'Tuple', type: 'array', minItems:
|
|
10
|
+
return (0, type_1.CreateType)(types.length > 0 ?
|
|
11
|
+
{ [index_1.Kind]: 'Tuple', type: 'array', items: types, additionalItems: false, minItems: types.length, maxItems: types.length } :
|
|
12
|
+
{ [index_1.Kind]: 'Tuple', type: 'array', minItems: types.length, maxItems: types.length }, options);
|
|
13
13
|
}
|
|
@@ -20,33 +20,33 @@ import { type TVoid } from '../void/index';
|
|
|
20
20
|
/** JavaScript Type Builder with Static Resolution for TypeScript */
|
|
21
21
|
export declare class JavaScriptTypeBuilder extends JsonTypeBuilder {
|
|
22
22
|
/** `[JavaScript]` Creates a AsyncIterator type */
|
|
23
|
-
AsyncIterator<
|
|
23
|
+
AsyncIterator<Type extends TSchema>(items: Type, options?: SchemaOptions): TAsyncIterator<Type>;
|
|
24
24
|
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
25
|
-
Awaited<
|
|
25
|
+
Awaited<Type extends TSchema>(schema: Type, options?: SchemaOptions): TAwaited<Type>;
|
|
26
26
|
/** `[JavaScript]` Creates a BigInt type */
|
|
27
27
|
BigInt(options?: BigIntOptions): TBigInt;
|
|
28
28
|
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
29
|
-
ConstructorParameters<
|
|
29
|
+
ConstructorParameters<Type extends TConstructor>(schema: Type, options?: SchemaOptions): TConstructorParameters<Type>;
|
|
30
30
|
/** `[JavaScript]` Creates a Constructor type */
|
|
31
|
-
Constructor<
|
|
31
|
+
Constructor<Parameters extends TSchema[], InstanceType extends TSchema>(parameters: [...Parameters], instanceType: InstanceType, options?: SchemaOptions): TConstructor<Parameters, InstanceType>;
|
|
32
32
|
/** `[JavaScript]` Creates a Date type */
|
|
33
33
|
Date(options?: DateOptions): TDate;
|
|
34
34
|
/** `[JavaScript]` Creates a Function type */
|
|
35
|
-
Function<
|
|
35
|
+
Function<Parameters extends TSchema[], ReturnType extends TSchema>(parameters: [...Parameters], returnType: ReturnType, options?: SchemaOptions): TFunction<Parameters, ReturnType>;
|
|
36
36
|
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
37
|
-
InstanceType<
|
|
37
|
+
InstanceType<Type extends TConstructor>(schema: Type, options?: SchemaOptions): TInstanceType<Type>;
|
|
38
38
|
/** `[JavaScript]` Creates an Iterator type */
|
|
39
|
-
Iterator<
|
|
39
|
+
Iterator<Type extends TSchema>(items: Type, options?: SchemaOptions): TIterator<Type>;
|
|
40
40
|
/** `[JavaScript]` Extracts the Parameters from the given Function type */
|
|
41
|
-
Parameters<
|
|
41
|
+
Parameters<Type extends TFunction>(schema: Type, options?: SchemaOptions): TParameters<Type>;
|
|
42
42
|
/** `[JavaScript]` Creates a Promise type */
|
|
43
|
-
Promise<
|
|
43
|
+
Promise<Type extends TSchema>(item: Type, options?: SchemaOptions): TPromise<Type>;
|
|
44
44
|
/** `[JavaScript]` Creates a RegExp type */
|
|
45
45
|
RegExp(pattern: string, options?: RegExpOptions): TRegExp;
|
|
46
46
|
/** `[JavaScript]` Creates a RegExp type */
|
|
47
47
|
RegExp(regex: RegExp, options?: RegExpOptions): TRegExp;
|
|
48
48
|
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
49
|
-
ReturnType<
|
|
49
|
+
ReturnType<Type extends TFunction>(type: Type, options?: SchemaOptions): TReturnType<Type>;
|
|
50
50
|
/** `[JavaScript]` Creates a Symbol type */
|
|
51
51
|
Symbol(options?: SchemaOptions): TSymbol;
|
|
52
52
|
/** `[JavaScript]` Creates a Undefined type */
|
|
@@ -39,16 +39,16 @@ class JavaScriptTypeBuilder extends json_1.JsonTypeBuilder {
|
|
|
39
39
|
return (0, index_5.ConstructorParameters)(schema, options);
|
|
40
40
|
}
|
|
41
41
|
/** `[JavaScript]` Creates a Constructor type */
|
|
42
|
-
Constructor(parameters,
|
|
43
|
-
return (0, index_4.Constructor)(parameters,
|
|
42
|
+
Constructor(parameters, instanceType, options) {
|
|
43
|
+
return (0, index_4.Constructor)(parameters, instanceType, options);
|
|
44
44
|
}
|
|
45
45
|
/** `[JavaScript]` Creates a Date type */
|
|
46
46
|
Date(options = {}) {
|
|
47
47
|
return (0, index_6.Date)(options);
|
|
48
48
|
}
|
|
49
49
|
/** `[JavaScript]` Creates a Function type */
|
|
50
|
-
Function(parameters,
|
|
51
|
-
return (0, index_7.Function)(parameters,
|
|
50
|
+
Function(parameters, returnType, options) {
|
|
51
|
+
return (0, index_7.Function)(parameters, returnType, options);
|
|
52
52
|
}
|
|
53
53
|
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
54
54
|
InstanceType(schema, options) {
|
|
@@ -71,8 +71,8 @@ class JavaScriptTypeBuilder extends json_1.JsonTypeBuilder {
|
|
|
71
71
|
return (0, index_12.RegExp)(unresolved, options);
|
|
72
72
|
}
|
|
73
73
|
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
74
|
-
ReturnType(
|
|
75
|
-
return (0, index_13.ReturnType)(
|
|
74
|
+
ReturnType(type, options) {
|
|
75
|
+
return (0, index_13.ReturnType)(type, options);
|
|
76
76
|
}
|
|
77
77
|
/** `[JavaScript]` Creates a Symbol type */
|
|
78
78
|
Symbol(options) {
|