@sinclair/typebox 0.32.34 → 0.33.0
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/errors/function.js +1 -1
- package/build/cjs/index.d.ts +1 -0
- package/build/cjs/index.js +1 -0
- package/build/cjs/system/policy.d.ts +9 -1
- package/build/cjs/system/policy.js +13 -2
- package/build/cjs/type/any/any.js +4 -3
- package/build/cjs/type/array/array.d.ts +1 -1
- package/build/cjs/type/array/array.js +3 -8
- package/build/cjs/type/async-iterator/async-iterator.js +3 -8
- package/build/cjs/type/awaited/awaited.js +3 -3
- package/build/cjs/type/bigint/bigint.js +3 -6
- package/build/cjs/type/boolean/boolean.js +3 -6
- package/build/cjs/type/clone/type.d.ts +1 -1
- package/build/cjs/type/clone/type.js +2 -2
- package/build/cjs/type/composite/composite.js +1 -1
- package/build/cjs/type/const/const.js +3 -3
- package/build/cjs/type/constructor/constructor.js +2 -8
- package/build/cjs/type/constructor-parameters/constructor-parameters.js +2 -3
- package/build/cjs/type/create/immutable.d.ts +2 -0
- package/build/cjs/type/create/immutable.js +41 -0
- package/build/cjs/type/create/index.d.ts +1 -0
- package/build/cjs/type/create/index.js +18 -0
- package/build/cjs/type/create/type.d.ts +3 -0
- package/build/cjs/type/create/type.js +19 -0
- package/build/cjs/type/date/date.js +3 -6
- package/build/cjs/type/discard/discard.d.ts +1 -0
- package/build/cjs/type/discard/discard.js +1 -0
- package/build/cjs/type/enum/enum.js +1 -1
- package/build/cjs/type/exclude/exclude.js +4 -4
- package/build/cjs/type/extends/extends-from-mapped-key.d.ts +1 -1
- package/build/cjs/type/extends/extends-from-mapped-key.js +2 -1
- package/build/cjs/type/extends/extends-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/extends/extends-from-mapped-result.js +2 -1
- package/build/cjs/type/extends/extends.js +4 -4
- package/build/cjs/type/extract/extract.js +5 -5
- package/build/cjs/type/function/function.js +2 -8
- package/build/cjs/type/guard/value.js +3 -0
- package/build/cjs/type/indexed/indexed-from-mapped-key.d.ts +1 -1
- package/build/cjs/type/indexed/indexed-from-mapped-key.js +2 -1
- package/build/cjs/type/indexed/indexed-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/indexed/indexed.js +10 -6
- package/build/cjs/type/instance-type/instance-type.js +3 -3
- package/build/cjs/type/integer/integer.js +3 -6
- package/build/cjs/type/intersect/intersect-create.d.ts +1 -1
- package/build/cjs/type/intersect/intersect-create.js +6 -6
- package/build/cjs/type/intersect/intersect-evaluated.js +2 -2
- package/build/cjs/type/intersect/intersect.js +3 -3
- package/build/cjs/type/intrinsic/intrinsic-from-mapped-key.js +4 -2
- package/build/cjs/type/intrinsic/intrinsic.js +3 -1
- package/build/cjs/type/iterator/iterator.js +3 -8
- package/build/cjs/type/keyof/keyof-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/keyof/keyof-from-mapped-result.js +2 -1
- package/build/cjs/type/keyof/keyof.js +3 -3
- package/build/cjs/type/literal/literal.js +4 -4
- package/build/cjs/type/mapped/mapped-key.js +3 -2
- package/build/cjs/type/mapped/mapped-result.js +3 -2
- package/build/cjs/type/mapped/mapped.js +2 -3
- package/build/cjs/type/never/never.js +3 -6
- package/build/cjs/type/not/not.d.ts +1 -1
- package/build/cjs/type/not/not.js +3 -7
- package/build/cjs/type/null/null.js +3 -6
- package/build/cjs/type/number/number.js +3 -6
- package/build/cjs/type/object/object.js +13 -12
- package/build/cjs/type/omit/omit-from-mapped-key.d.ts +1 -1
- package/build/cjs/type/omit/omit-from-mapped-key.js +2 -1
- package/build/cjs/type/omit/omit-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/omit/omit-from-mapped-result.js +2 -1
- package/build/cjs/type/omit/omit.js +4 -4
- package/build/cjs/type/optional/optional.js +3 -3
- package/build/cjs/type/parameters/parameters.js +2 -3
- package/build/cjs/type/partial/partial-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/partial/partial-from-mapped-result.js +2 -1
- package/build/cjs/type/partial/partial.js +4 -4
- package/build/cjs/type/patterns/patterns.d.ts +2 -0
- package/build/cjs/type/patterns/patterns.js +3 -1
- package/build/cjs/type/pick/pick-from-mapped-key.d.ts +1 -1
- package/build/cjs/type/pick/pick-from-mapped-key.js +2 -1
- package/build/cjs/type/pick/pick-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/pick/pick-from-mapped-result.js +2 -1
- package/build/cjs/type/pick/pick.js +4 -4
- package/build/cjs/type/promise/promise.js +3 -8
- package/build/cjs/type/readonly/readonly.js +3 -3
- package/build/cjs/type/record/record.d.ts +4 -1
- package/build/cjs/type/record/record.js +16 -7
- package/build/cjs/type/recursive/recursive.js +3 -2
- package/build/cjs/type/ref/ref.js +4 -7
- package/build/cjs/type/regexp/regexp.js +3 -2
- package/build/cjs/type/required/required-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/required/required.js +4 -4
- package/build/cjs/type/rest/rest.d.ts +1 -1
- package/build/cjs/type/rest/rest.js +4 -5
- package/build/cjs/type/return-type/return-type.js +3 -3
- package/build/cjs/type/string/string.js +3 -2
- package/build/cjs/type/symbol/symbol.js +2 -1
- package/build/cjs/type/template-literal/template-literal.js +3 -2
- package/build/cjs/type/transform/transform.js +1 -3
- package/build/cjs/type/tuple/tuple.js +5 -7
- package/build/cjs/type/type/javascript.js +13 -13
- package/build/cjs/type/type/json.js +35 -35
- package/build/cjs/type/uint8array/uint8array.js +3 -2
- package/build/cjs/type/undefined/undefined.js +3 -2
- package/build/cjs/type/union/union-create.d.ts +1 -1
- package/build/cjs/type/union/union-create.js +2 -2
- package/build/cjs/type/union/union-evaluated.js +3 -3
- package/build/cjs/type/union/union.js +3 -3
- package/build/cjs/type/unknown/unknown.js +3 -5
- package/build/cjs/type/unsafe/unsafe.js +2 -4
- package/build/cjs/type/void/void.js +3 -6
- package/build/cjs/value/convert/convert.js +3 -0
- package/build/esm/errors/function.mjs +1 -1
- package/build/esm/index.d.mts +1 -0
- package/build/esm/index.mjs +1 -0
- package/build/esm/system/policy.d.mts +9 -1
- package/build/esm/system/policy.mjs +13 -2
- package/build/esm/type/any/any.mjs +3 -2
- package/build/esm/type/array/array.d.mts +1 -1
- package/build/esm/type/array/array.mjs +3 -8
- package/build/esm/type/async-iterator/async-iterator.mjs +3 -8
- package/build/esm/type/awaited/awaited.mjs +3 -3
- package/build/esm/type/bigint/bigint.mjs +3 -6
- package/build/esm/type/boolean/boolean.mjs +3 -6
- package/build/esm/type/clone/type.d.mts +1 -1
- package/build/esm/type/clone/type.mjs +2 -2
- package/build/esm/type/composite/composite.mjs +1 -1
- package/build/esm/type/const/const.mjs +3 -3
- package/build/esm/type/constructor/constructor.mjs +2 -8
- package/build/esm/type/constructor-parameters/constructor-parameters.mjs +2 -3
- package/build/esm/type/create/immutable.d.mts +2 -0
- package/build/esm/type/create/immutable.mjs +37 -0
- package/build/esm/type/create/index.d.mts +1 -0
- package/build/esm/type/create/index.mjs +1 -0
- package/build/esm/type/create/type.d.mts +3 -0
- package/build/esm/type/create/type.mjs +15 -0
- package/build/esm/type/date/date.mjs +3 -6
- package/build/esm/type/discard/discard.d.mts +1 -0
- package/build/esm/type/discard/discard.mjs +1 -0
- package/build/esm/type/enum/enum.mjs +1 -1
- package/build/esm/type/exclude/exclude.mjs +4 -4
- package/build/esm/type/extends/extends-from-mapped-key.d.mts +1 -1
- package/build/esm/type/extends/extends-from-mapped-key.mjs +2 -1
- package/build/esm/type/extends/extends-from-mapped-result.d.mts +1 -1
- package/build/esm/type/extends/extends-from-mapped-result.mjs +2 -1
- package/build/esm/type/extends/extends.mjs +4 -4
- package/build/esm/type/extract/extract.mjs +5 -5
- package/build/esm/type/function/function.mjs +2 -8
- package/build/esm/type/guard/value.mjs +3 -0
- package/build/esm/type/indexed/indexed-from-mapped-key.d.mts +1 -1
- package/build/esm/type/indexed/indexed-from-mapped-key.mjs +2 -1
- package/build/esm/type/indexed/indexed-from-mapped-result.d.mts +1 -1
- package/build/esm/type/indexed/indexed.mjs +10 -6
- package/build/esm/type/instance-type/instance-type.mjs +3 -3
- package/build/esm/type/integer/integer.mjs +3 -6
- package/build/esm/type/intersect/intersect-create.d.mts +1 -1
- package/build/esm/type/intersect/intersect-create.mjs +6 -6
- package/build/esm/type/intersect/intersect-evaluated.mjs +2 -2
- package/build/esm/type/intersect/intersect.mjs +3 -3
- package/build/esm/type/intrinsic/intrinsic-from-mapped-key.mjs +4 -2
- package/build/esm/type/intrinsic/intrinsic.mjs +3 -1
- package/build/esm/type/iterator/iterator.mjs +3 -8
- package/build/esm/type/keyof/keyof-from-mapped-result.d.mts +1 -1
- package/build/esm/type/keyof/keyof-from-mapped-result.mjs +2 -1
- package/build/esm/type/keyof/keyof.mjs +3 -3
- package/build/esm/type/literal/literal.mjs +4 -4
- package/build/esm/type/mapped/mapped-key.mjs +3 -2
- package/build/esm/type/mapped/mapped-result.mjs +3 -2
- package/build/esm/type/mapped/mapped.mjs +2 -3
- package/build/esm/type/never/never.mjs +3 -6
- package/build/esm/type/not/not.d.mts +1 -1
- package/build/esm/type/not/not.mjs +3 -7
- package/build/esm/type/null/null.mjs +3 -6
- package/build/esm/type/number/number.mjs +3 -6
- package/build/esm/type/object/object.mjs +14 -13
- package/build/esm/type/omit/omit-from-mapped-key.d.mts +1 -1
- package/build/esm/type/omit/omit-from-mapped-key.mjs +2 -1
- package/build/esm/type/omit/omit-from-mapped-result.d.mts +1 -1
- package/build/esm/type/omit/omit-from-mapped-result.mjs +2 -1
- package/build/esm/type/omit/omit.mjs +4 -4
- package/build/esm/type/optional/optional.mjs +3 -3
- package/build/esm/type/parameters/parameters.mjs +2 -3
- package/build/esm/type/partial/partial-from-mapped-result.d.mts +1 -1
- package/build/esm/type/partial/partial-from-mapped-result.mjs +2 -1
- package/build/esm/type/partial/partial.mjs +4 -4
- package/build/esm/type/patterns/patterns.d.mts +2 -0
- package/build/esm/type/patterns/patterns.mjs +2 -0
- package/build/esm/type/pick/pick-from-mapped-key.d.mts +1 -1
- package/build/esm/type/pick/pick-from-mapped-key.mjs +2 -1
- package/build/esm/type/pick/pick-from-mapped-result.d.mts +1 -1
- package/build/esm/type/pick/pick-from-mapped-result.mjs +2 -1
- package/build/esm/type/pick/pick.mjs +4 -4
- package/build/esm/type/promise/promise.mjs +3 -8
- package/build/esm/type/readonly/readonly.mjs +3 -3
- package/build/esm/type/record/record.d.mts +4 -1
- package/build/esm/type/record/record.mjs +18 -9
- package/build/esm/type/recursive/recursive.mjs +3 -2
- package/build/esm/type/ref/ref.mjs +4 -7
- package/build/esm/type/regexp/regexp.mjs +3 -2
- package/build/esm/type/required/required-from-mapped-result.d.mts +1 -1
- package/build/esm/type/required/required.mjs +4 -4
- package/build/esm/type/rest/rest.d.mts +1 -1
- package/build/esm/type/rest/rest.mjs +4 -5
- package/build/esm/type/return-type/return-type.mjs +3 -3
- package/build/esm/type/string/string.mjs +3 -2
- package/build/esm/type/symbol/symbol.mjs +2 -1
- package/build/esm/type/template-literal/template-literal.mjs +3 -2
- package/build/esm/type/transform/transform.mjs +1 -3
- package/build/esm/type/tuple/tuple.mjs +5 -7
- package/build/esm/type/type/javascript.mjs +13 -13
- package/build/esm/type/type/json.mjs +35 -35
- package/build/esm/type/uint8array/uint8array.mjs +3 -2
- package/build/esm/type/undefined/undefined.mjs +3 -2
- package/build/esm/type/union/union-create.d.mts +1 -1
- package/build/esm/type/union/union-create.mjs +2 -2
- package/build/esm/type/union/union-evaluated.mjs +3 -3
- package/build/esm/type/union/union.mjs +3 -3
- package/build/esm/type/unknown/unknown.mjs +3 -5
- package/build/esm/type/unsafe/unsafe.mjs +2 -4
- package/build/esm/type/void/void.mjs +3 -6
- package/build/esm/value/convert/convert.mjs +3 -0
- package/package.json +1 -1
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Pick = Pick;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../intersect/index");
|
|
6
7
|
const index_2 = require("../union/index");
|
|
7
8
|
const index_3 = require("../object/index");
|
|
8
9
|
const index_4 = require("../indexed/index");
|
|
9
10
|
const index_5 = require("../discard/index");
|
|
10
11
|
const index_6 = require("../symbols/index");
|
|
11
|
-
const type_1 = require("../clone/type");
|
|
12
12
|
const pick_from_mapped_key_1 = require("./pick-from-mapped-key");
|
|
13
13
|
const pick_from_mapped_result_1 = require("./pick-from-mapped-result");
|
|
14
14
|
// ------------------------------------------------------------------
|
|
@@ -40,7 +40,7 @@ function PickResolve(T, K) {
|
|
|
40
40
|
(0, kind_1.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties, K)) :
|
|
41
41
|
(0, index_3.Object)({}));
|
|
42
42
|
}
|
|
43
|
-
function Pick(T, K, options
|
|
43
|
+
function Pick(T, K, options) {
|
|
44
44
|
// mapped
|
|
45
45
|
if ((0, kind_1.IsMappedKey)(K))
|
|
46
46
|
return (0, pick_from_mapped_key_1.PickFromMappedKey)(T, K, options);
|
|
@@ -49,6 +49,6 @@ function Pick(T, K, options = {}) {
|
|
|
49
49
|
// non-mapped
|
|
50
50
|
const I = (0, kind_1.IsSchema)(K) ? (0, index_4.IndexPropertyKeys)(K) : K;
|
|
51
51
|
const D = (0, index_5.Discard)(T, [index_6.TransformKind, '$id', 'required']);
|
|
52
|
-
const R =
|
|
53
|
-
return { ...D, ...R };
|
|
52
|
+
const R = PickResolve(T, I);
|
|
53
|
+
return (0, type_1.CreateType)({ ...D, ...R }, options);
|
|
54
54
|
}
|
|
@@ -2,14 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Promise = Promise;
|
|
5
|
-
const type_1 = require("../
|
|
5
|
+
const type_1 = require("../create/type");
|
|
6
6
|
const index_1 = require("../symbols/index");
|
|
7
7
|
/** `[JavaScript]` Creates a Promise type */
|
|
8
|
-
function Promise(item, options
|
|
9
|
-
return {
|
|
10
|
-
...options,
|
|
11
|
-
[index_1.Kind]: 'Promise',
|
|
12
|
-
type: 'Promise',
|
|
13
|
-
item: (0, type_1.CloneType)(item),
|
|
14
|
-
};
|
|
8
|
+
function Promise(item, options) {
|
|
9
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'Promise', type: 'Promise', item }, options);
|
|
15
10
|
}
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Readonly = Readonly;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../symbols/index");
|
|
6
|
-
const type_1 = require("../clone/type");
|
|
7
7
|
const index_2 = require("../discard/index");
|
|
8
8
|
const readonly_from_mapped_result_1 = require("./readonly-from-mapped-result");
|
|
9
9
|
const kind_1 = require("../guard/kind");
|
|
10
10
|
function RemoveReadonly(schema) {
|
|
11
|
-
return (0,
|
|
11
|
+
return (0, type_1.CreateType)((0, index_2.Discard)(schema, [index_1.ReadonlyKind]));
|
|
12
12
|
}
|
|
13
13
|
function AddReadonly(schema) {
|
|
14
|
-
return
|
|
14
|
+
return (0, type_1.CreateType)({ ...schema, [index_1.ReadonlyKind]: 'Readonly' });
|
|
15
15
|
}
|
|
16
16
|
// prettier-ignore
|
|
17
17
|
function ReadonlyWithFlag(schema, F) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TSchema } from '../schema/index';
|
|
2
2
|
import type { Static } from '../static/index';
|
|
3
3
|
import type { Evaluate, Ensure, Assert } from '../helpers/index';
|
|
4
|
+
import { type TAny } from '../any/index';
|
|
4
5
|
import { type TObject, type TProperties, type TAdditionalProperties, type ObjectOptions } from '../object/index';
|
|
5
6
|
import { type TLiteral, type TLiteralValue } from '../literal/index';
|
|
6
7
|
import { type TNever } from '../never/index';
|
|
@@ -33,6 +34,8 @@ type TFromLiteralKey<K extends TLiteralValue, T extends TSchema> = (Ensure<TObje
|
|
|
33
34
|
}>>);
|
|
34
35
|
type TFromRegExpKey<_ extends TRegExp, T extends TSchema> = (Ensure<TRecord<TRegExp, T>>);
|
|
35
36
|
type TFromStringKey<_ extends TString, T extends TSchema> = (Ensure<TRecord<TString, T>>);
|
|
37
|
+
type TFromAnyKey<_ extends TAny, T extends TSchema> = (Ensure<TRecord<TAny, T>>);
|
|
38
|
+
type TFromNeverKey<_ extends TNever, T extends TSchema> = (Ensure<TRecord<TNever, T>>);
|
|
36
39
|
type TFromIntegerKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
|
|
37
40
|
type TFromNumberKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
|
|
38
41
|
type RecordStatic<K extends TSchema, T extends TSchema, P extends unknown[]> = (Evaluate<{
|
|
@@ -47,7 +50,7 @@ export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchem
|
|
|
47
50
|
};
|
|
48
51
|
additionalProperties: TAdditionalProperties;
|
|
49
52
|
}
|
|
50
|
-
export type TRecordOrObject<K extends TSchema, T extends TSchema> = K extends TTemplateLiteral ? TFromTemplateLiteralKey<K, T> : K extends TEnum<infer S> ? TFromEnumKey<S, T> : K extends TUnion<infer S> ? TFromUnionKey<S, T> : K extends TLiteral<infer S> ? TFromLiteralKey<S, T> : K extends TInteger ? TFromIntegerKey<K, T> : K extends TNumber ? TFromNumberKey<K, T> : K extends TRegExp ? TFromRegExpKey<K, T> : K extends TString ? TFromStringKey<K, T> : TNever;
|
|
53
|
+
export type TRecordOrObject<K extends TSchema, T extends TSchema> = K extends TTemplateLiteral ? TFromTemplateLiteralKey<K, T> : K extends TEnum<infer S> ? TFromEnumKey<S, T> : K extends TUnion<infer S> ? TFromUnionKey<S, T> : K extends TLiteral<infer S> ? TFromLiteralKey<S, T> : K extends TInteger ? TFromIntegerKey<K, T> : K extends TNumber ? TFromNumberKey<K, T> : K extends TRegExp ? TFromRegExpKey<K, T> : K extends TString ? TFromStringKey<K, T> : K extends TAny ? TFromAnyKey<K, T> : K extends TNever ? TFromNeverKey<K, T> : TNever;
|
|
51
54
|
/** `[Json]` Creates a Record type */
|
|
52
55
|
export declare function Record<K extends TSchema, T extends TSchema>(K: K, T: T, options?: ObjectOptions): TRecordOrObject<K, T>;
|
|
53
56
|
export {};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Record = Record;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../object/index");
|
|
6
7
|
const index_2 = require("../never/index");
|
|
7
8
|
const index_3 = require("../union/index");
|
|
@@ -9,7 +10,6 @@ const index_4 = require("../template-literal/index");
|
|
|
9
10
|
const index_5 = require("../patterns/index");
|
|
10
11
|
const index_6 = require("../indexed/index");
|
|
11
12
|
const index_7 = require("../symbols/index");
|
|
12
|
-
const type_1 = require("../clone/type");
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
14
|
// ValueGuard
|
|
15
15
|
// ------------------------------------------------------------------
|
|
@@ -23,12 +23,11 @@ const kind_1 = require("../guard/kind");
|
|
|
23
23
|
// ------------------------------------------------------------------
|
|
24
24
|
// prettier-ignore
|
|
25
25
|
function RecordCreateFromPattern(pattern, T, options) {
|
|
26
|
-
return {
|
|
27
|
-
...options,
|
|
26
|
+
return (0, type_1.CreateType)({
|
|
28
27
|
[index_7.Kind]: 'Record',
|
|
29
28
|
type: 'object',
|
|
30
|
-
patternProperties: { [pattern]:
|
|
31
|
-
};
|
|
29
|
+
patternProperties: { [pattern]: T }
|
|
30
|
+
}, options);
|
|
32
31
|
}
|
|
33
32
|
// ------------------------------------------------------------------
|
|
34
33
|
// RecordCreateFromKeys
|
|
@@ -37,7 +36,7 @@ function RecordCreateFromPattern(pattern, T, options) {
|
|
|
37
36
|
function RecordCreateFromKeys(K, T, options) {
|
|
38
37
|
const Acc = {};
|
|
39
38
|
for (const K2 of K)
|
|
40
|
-
Acc[K2] =
|
|
39
|
+
Acc[K2] = T;
|
|
41
40
|
return (0, index_1.Object)(Acc, { ...options, [index_7.Hint]: 'Record' });
|
|
42
41
|
}
|
|
43
42
|
// prettier-ignore
|
|
@@ -64,6 +63,14 @@ function FromStringKey(K, T, options) {
|
|
|
64
63
|
return RecordCreateFromPattern(pattern, T, options);
|
|
65
64
|
}
|
|
66
65
|
// prettier-ignore
|
|
66
|
+
function FromAnyKey(K, T, options) {
|
|
67
|
+
return RecordCreateFromPattern(index_5.PatternStringExact, T, options);
|
|
68
|
+
}
|
|
69
|
+
// prettier-ignore
|
|
70
|
+
function FromNeverKey(K, T, options) {
|
|
71
|
+
return RecordCreateFromPattern(index_5.PatternNeverExact, T, options);
|
|
72
|
+
}
|
|
73
|
+
// prettier-ignore
|
|
67
74
|
function FromIntegerKey(_, T, options) {
|
|
68
75
|
return RecordCreateFromPattern(index_5.PatternNumberExact, T, options);
|
|
69
76
|
}
|
|
@@ -84,5 +91,7 @@ function Record(K, T, options = {}) {
|
|
|
84
91
|
(0, kind_1.IsNumber)(K) ? FromNumberKey(K, T, options) :
|
|
85
92
|
(0, kind_1.IsRegExp)(K) ? FromRegExpKey(K, T, options) :
|
|
86
93
|
(0, kind_1.IsString)(K) ? FromStringKey(K, T, options) :
|
|
87
|
-
(0,
|
|
94
|
+
(0, kind_1.IsAny)(K) ? FromAnyKey(K, T, options) :
|
|
95
|
+
(0, kind_1.IsNever)(K) ? FromNeverKey(K, T, options) :
|
|
96
|
+
(0, index_2.Never)(options));
|
|
88
97
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Recursive = Recursive;
|
|
5
5
|
const type_1 = require("../clone/type");
|
|
6
|
+
const type_2 = require("../create/type");
|
|
6
7
|
const value_1 = require("../guard/value");
|
|
7
8
|
const index_1 = require("../symbols/index");
|
|
8
9
|
// Auto Tracked For Recursive Types without ID's
|
|
@@ -11,8 +12,8 @@ let Ordinal = 0;
|
|
|
11
12
|
function Recursive(callback, options = {}) {
|
|
12
13
|
if ((0, value_1.IsUndefined)(options.$id))
|
|
13
14
|
options.$id = `T${Ordinal++}`;
|
|
14
|
-
const thisType = callback({ [index_1.Kind]: 'This', $ref: `${options.$id}` });
|
|
15
|
+
const thisType = (0, type_1.CloneType)(callback({ [index_1.Kind]: 'This', $ref: `${options.$id}` }));
|
|
15
16
|
thisType.$id = options.$id;
|
|
16
17
|
// prettier-ignore
|
|
17
|
-
return (0,
|
|
18
|
+
return (0, type_2.CreateType)({ [index_1.Hint]: 'Recursive', ...thisType }, options);
|
|
18
19
|
}
|
|
@@ -2,20 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Ref = Ref;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../symbols/index");
|
|
6
7
|
// ------------------------------------------------------------------
|
|
7
8
|
// ValueGuard
|
|
8
9
|
// ------------------------------------------------------------------
|
|
9
10
|
const value_1 = require("../guard/value");
|
|
10
11
|
/** `[Json]` Creates a Ref type. */
|
|
11
|
-
function Ref(unresolved, options
|
|
12
|
+
function Ref(unresolved, options) {
|
|
12
13
|
if ((0, value_1.IsString)(unresolved))
|
|
13
|
-
return {
|
|
14
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'Ref', $ref: unresolved }, options);
|
|
14
15
|
if ((0, value_1.IsUndefined)(unresolved.$id))
|
|
15
16
|
throw new Error('Reference target type must specify an $id');
|
|
16
|
-
return {
|
|
17
|
-
...options,
|
|
18
|
-
[index_1.Kind]: 'Ref',
|
|
19
|
-
$ref: unresolved.$id,
|
|
20
|
-
};
|
|
17
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'Ref', $ref: unresolved.$id }, options);
|
|
21
18
|
}
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.RegExp = RegExp;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const value_1 = require("../guard/value");
|
|
6
7
|
const index_1 = require("../symbols/index");
|
|
7
8
|
/** `[JavaScript]` Creates a RegExp type */
|
|
8
|
-
function RegExp(unresolved, options
|
|
9
|
+
function RegExp(unresolved, options) {
|
|
9
10
|
const expr = (0, value_1.IsString)(unresolved) ? new globalThis.RegExp(unresolved) : unresolved;
|
|
10
|
-
return {
|
|
11
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'RegExp', type: 'RegExp', source: expr.source, flags: expr.flags }, options);
|
|
11
12
|
}
|
|
@@ -8,5 +8,5 @@ type TFromProperties<P extends TProperties> = ({
|
|
|
8
8
|
});
|
|
9
9
|
type TFromMappedResult<R extends TMappedResult> = (Evaluate<TFromProperties<R['properties']>>);
|
|
10
10
|
export type TRequiredFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>> = (Ensure<TMappedResult<P>>);
|
|
11
|
-
export declare function RequiredFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>>(R: R, options
|
|
11
|
+
export declare function RequiredFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>>(R: R, options?: SchemaOptions): TMappedResult<P>;
|
|
12
12
|
export {};
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Required = Required;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../intersect/index");
|
|
6
7
|
const index_2 = require("../union/index");
|
|
7
8
|
const index_3 = require("../object/index");
|
|
8
9
|
const index_4 = require("../symbols/index");
|
|
9
|
-
const type_1 = require("../clone/type");
|
|
10
10
|
const index_5 = require("../discard/index");
|
|
11
11
|
const required_from_mapped_result_1 = require("./required-from-mapped-result");
|
|
12
12
|
// ------------------------------------------------------------------
|
|
@@ -35,13 +35,13 @@ function RequiredResolve(T) {
|
|
|
35
35
|
(0, index_3.Object)({}));
|
|
36
36
|
}
|
|
37
37
|
/** `[Json]` Constructs a type where all properties are required */
|
|
38
|
-
function Required(T, options
|
|
38
|
+
function Required(T, options) {
|
|
39
39
|
if ((0, kind_1.IsMappedResult)(T)) {
|
|
40
40
|
return (0, required_from_mapped_result_1.RequiredFromMappedResult)(T, options);
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
43
|
const D = (0, index_5.Discard)(T, [index_4.TransformKind, '$id', 'required']);
|
|
44
|
-
const R =
|
|
45
|
-
return { ...D, ...R };
|
|
44
|
+
const R = RequiredResolve(T);
|
|
45
|
+
return (0, type_1.CreateType)({ ...D, ...R }, options);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -2,7 +2,7 @@ import type { TSchema } from '../schema/index';
|
|
|
2
2
|
import type { TIntersect } from '../intersect/index';
|
|
3
3
|
import type { TUnion } from '../union/index';
|
|
4
4
|
import type { TTuple } from '../tuple/index';
|
|
5
|
-
type TRestResolve<T extends TSchema> = T extends TIntersect<infer S> ?
|
|
5
|
+
type TRestResolve<T extends TSchema> = T extends TIntersect<infer S extends TSchema[]> ? S : T extends TUnion<infer S extends TSchema[]> ? S : T extends TTuple<infer S extends TSchema[]> ? S : [
|
|
6
6
|
];
|
|
7
7
|
export type TRest<T extends TSchema> = TRestResolve<T>;
|
|
8
8
|
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
@@ -2,19 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Rest = Rest;
|
|
5
|
-
const type_1 = require("../clone/type");
|
|
6
5
|
// ------------------------------------------------------------------
|
|
7
6
|
// TypeGuard
|
|
8
7
|
// ------------------------------------------------------------------
|
|
9
8
|
const kind_1 = require("../guard/kind");
|
|
10
9
|
// prettier-ignore
|
|
11
10
|
function RestResolve(T) {
|
|
12
|
-
return ((0, kind_1.IsIntersect)(T) ?
|
|
13
|
-
(0, kind_1.IsUnion)(T) ?
|
|
14
|
-
(0, kind_1.IsTuple)(T) ?
|
|
11
|
+
return ((0, kind_1.IsIntersect)(T) ? T.allOf :
|
|
12
|
+
(0, kind_1.IsUnion)(T) ? T.anyOf :
|
|
13
|
+
(0, kind_1.IsTuple)(T) ? T.items ?? [] :
|
|
15
14
|
[]);
|
|
16
15
|
}
|
|
17
16
|
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
18
17
|
function Rest(T) {
|
|
19
|
-
return
|
|
18
|
+
return RestResolve(T);
|
|
20
19
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.ReturnType = ReturnType;
|
|
5
|
-
const type_1 = require("../
|
|
5
|
+
const type_1 = require("../create/type");
|
|
6
6
|
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
7
|
-
function ReturnType(schema, options
|
|
8
|
-
return (0, type_1.
|
|
7
|
+
function ReturnType(schema, options) {
|
|
8
|
+
return (0, type_1.CreateType)(schema.returns, options);
|
|
9
9
|
}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.String = String;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../symbols/index");
|
|
6
7
|
/** `[Json]` Creates a String type */
|
|
7
|
-
function String(options
|
|
8
|
-
return {
|
|
8
|
+
function String(options) {
|
|
9
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'String', type: 'string' }, options);
|
|
9
10
|
}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Symbol = Symbol;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../symbols/index");
|
|
6
7
|
/** `[JavaScript]` Creates a Symbol type */
|
|
7
8
|
function Symbol(options) {
|
|
8
|
-
return {
|
|
9
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'Symbol', type: 'symbol' }, options);
|
|
9
10
|
}
|
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.TemplateLiteral = TemplateLiteral;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const syntax_1 = require("./syntax");
|
|
6
7
|
const pattern_1 = require("./pattern");
|
|
7
8
|
const value_1 = require("../guard/value");
|
|
8
9
|
const index_1 = require("../symbols/index");
|
|
9
10
|
/** `[Json]` Creates a TemplateLiteral type */
|
|
10
11
|
// prettier-ignore
|
|
11
|
-
function TemplateLiteral(unresolved, options
|
|
12
|
+
function TemplateLiteral(unresolved, options) {
|
|
12
13
|
const pattern = (0, value_1.IsString)(unresolved)
|
|
13
14
|
? (0, pattern_1.TemplateLiteralPattern)((0, syntax_1.TemplateLiteralSyntax)(unresolved))
|
|
14
15
|
: (0, pattern_1.TemplateLiteralPattern)(unresolved);
|
|
15
|
-
return {
|
|
16
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'TemplateLiteral', type: 'string', pattern }, options);
|
|
16
17
|
}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.TransformEncodeBuilder = exports.TransformDecodeBuilder = void 0;
|
|
5
5
|
exports.Transform = Transform;
|
|
6
6
|
const index_1 = require("../symbols/index");
|
|
7
|
-
const type_1 = require("../clone/type");
|
|
8
7
|
// ------------------------------------------------------------------
|
|
9
8
|
// TypeGuard
|
|
10
9
|
// ------------------------------------------------------------------
|
|
@@ -38,8 +37,7 @@ class TransformEncodeBuilder {
|
|
|
38
37
|
return { ...schema, [index_1.TransformKind]: Codec };
|
|
39
38
|
}
|
|
40
39
|
Encode(encode) {
|
|
41
|
-
|
|
42
|
-
return ((0, kind_1.IsTransform)(schema) ? this.EncodeTransform(encode, schema) : this.EncodeSchema(encode, schema));
|
|
40
|
+
return ((0, kind_1.IsTransform)(this.schema) ? this.EncodeTransform(encode, this.schema) : this.EncodeSchema(encode, this.schema));
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
exports.TransformEncodeBuilder = TransformEncodeBuilder;
|
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Tuple = Tuple;
|
|
5
|
-
const type_1 = require("../
|
|
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(items, options
|
|
9
|
-
// return TupleResolver.Resolve(T)
|
|
10
|
-
const [additionalItems, minItems, maxItems] = [false, items.length, items.length];
|
|
8
|
+
function Tuple(items, options) {
|
|
11
9
|
// prettier-ignore
|
|
12
|
-
return (items.length > 0 ?
|
|
13
|
-
{
|
|
14
|
-
{
|
|
10
|
+
return (0, type_1.CreateType)(items.length > 0 ?
|
|
11
|
+
{ [index_1.Kind]: 'Tuple', type: 'array', items, additionalItems: false, minItems: items.length, maxItems: items.length } :
|
|
12
|
+
{ [index_1.Kind]: 'Tuple', type: 'array', minItems: items.length, maxItems: items.length }, options);
|
|
15
13
|
}
|
|
@@ -23,19 +23,19 @@ const index_17 = require("../void/index");
|
|
|
23
23
|
/** JavaScript Type Builder with Static Resolution for TypeScript */
|
|
24
24
|
class JavaScriptTypeBuilder extends json_1.JsonTypeBuilder {
|
|
25
25
|
/** `[JavaScript]` Creates a AsyncIterator type */
|
|
26
|
-
AsyncIterator(items, options
|
|
26
|
+
AsyncIterator(items, options) {
|
|
27
27
|
return (0, index_1.AsyncIterator)(items, options);
|
|
28
28
|
}
|
|
29
29
|
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
30
|
-
Awaited(schema, options
|
|
30
|
+
Awaited(schema, options) {
|
|
31
31
|
return (0, index_2.Awaited)(schema, options);
|
|
32
32
|
}
|
|
33
33
|
/** `[JavaScript]` Creates a BigInt type */
|
|
34
|
-
BigInt(options
|
|
34
|
+
BigInt(options) {
|
|
35
35
|
return (0, index_3.BigInt)(options);
|
|
36
36
|
}
|
|
37
37
|
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
38
|
-
ConstructorParameters(schema, options
|
|
38
|
+
ConstructorParameters(schema, options) {
|
|
39
39
|
return (0, index_5.ConstructorParameters)(schema, options);
|
|
40
40
|
}
|
|
41
41
|
/** `[JavaScript]` Creates a Constructor type */
|
|
@@ -51,27 +51,27 @@ class JavaScriptTypeBuilder extends json_1.JsonTypeBuilder {
|
|
|
51
51
|
return (0, index_7.Function)(parameters, returns, options);
|
|
52
52
|
}
|
|
53
53
|
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
54
|
-
InstanceType(schema, options
|
|
54
|
+
InstanceType(schema, options) {
|
|
55
55
|
return (0, index_8.InstanceType)(schema, options);
|
|
56
56
|
}
|
|
57
57
|
/** `[JavaScript]` Creates an Iterator type */
|
|
58
|
-
Iterator(items, options
|
|
58
|
+
Iterator(items, options) {
|
|
59
59
|
return (0, index_9.Iterator)(items, options);
|
|
60
60
|
}
|
|
61
61
|
/** `[JavaScript]` Extracts the Parameters from the given Function type */
|
|
62
|
-
Parameters(schema, options
|
|
62
|
+
Parameters(schema, options) {
|
|
63
63
|
return (0, index_10.Parameters)(schema, options);
|
|
64
64
|
}
|
|
65
65
|
/** `[JavaScript]` Creates a Promise type */
|
|
66
|
-
Promise(item, options
|
|
66
|
+
Promise(item, options) {
|
|
67
67
|
return (0, index_11.Promise)(item, options);
|
|
68
68
|
}
|
|
69
69
|
/** `[JavaScript]` Creates a RegExp type */
|
|
70
|
-
RegExp(unresolved, options
|
|
70
|
+
RegExp(unresolved, options) {
|
|
71
71
|
return (0, index_12.RegExp)(unresolved, options);
|
|
72
72
|
}
|
|
73
73
|
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
74
|
-
ReturnType(schema, options
|
|
74
|
+
ReturnType(schema, options) {
|
|
75
75
|
return (0, index_13.ReturnType)(schema, options);
|
|
76
76
|
}
|
|
77
77
|
/** `[JavaScript]` Creates a Symbol type */
|
|
@@ -79,15 +79,15 @@ class JavaScriptTypeBuilder extends json_1.JsonTypeBuilder {
|
|
|
79
79
|
return (0, index_14.Symbol)(options);
|
|
80
80
|
}
|
|
81
81
|
/** `[JavaScript]` Creates a Undefined type */
|
|
82
|
-
Undefined(options
|
|
82
|
+
Undefined(options) {
|
|
83
83
|
return (0, index_16.Undefined)(options);
|
|
84
84
|
}
|
|
85
85
|
/** `[JavaScript]` Creates a Uint8Array type */
|
|
86
|
-
Uint8Array(options
|
|
86
|
+
Uint8Array(options) {
|
|
87
87
|
return (0, index_15.Uint8Array)(options);
|
|
88
88
|
}
|
|
89
89
|
/** `[JavaScript]` Creates a Void type */
|
|
90
|
-
Void(options
|
|
90
|
+
Void(options) {
|
|
91
91
|
return (0, index_17.Void)(options);
|
|
92
92
|
}
|
|
93
93
|
}
|