@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
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { MappedResult } from '../mapped/index.mjs';
|
|
2
2
|
import { Omit } from './omit.mjs';
|
|
3
|
+
import { Clone } from '../clone/value.mjs';
|
|
3
4
|
// prettier-ignore
|
|
4
5
|
function FromPropertyKey(T, K, options) {
|
|
5
6
|
return {
|
|
6
|
-
[K]: Omit(T, [K], options)
|
|
7
|
+
[K]: Omit(T, [K], Clone(options))
|
|
7
8
|
};
|
|
8
9
|
}
|
|
9
10
|
// prettier-ignore
|
|
@@ -8,5 +8,5 @@ type TFromProperties<P extends TProperties, K extends PropertyKey[]> = ({
|
|
|
8
8
|
});
|
|
9
9
|
type TFromMappedResult<R extends TMappedResult, K extends PropertyKey[]> = (Evaluate<TFromProperties<R['properties'], K>>);
|
|
10
10
|
export type TOmitFromMappedResult<T extends TMappedResult, K extends PropertyKey[], P extends TProperties = TFromMappedResult<T, K>> = (Ensure<TMappedResult<P>>);
|
|
11
|
-
export declare function OmitFromMappedResult<R extends TMappedResult, K extends PropertyKey[], P extends TProperties = TFromMappedResult<R, K>>(R: R, K: [...K], options
|
|
11
|
+
export declare function OmitFromMappedResult<R extends TMappedResult, K extends PropertyKey[], P extends TProperties = TFromMappedResult<R, K>>(R: R, K: [...K], options?: SchemaOptions): TMappedResult<P>;
|
|
12
12
|
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { MappedResult } from '../mapped/index.mjs';
|
|
2
2
|
import { Omit } from './omit.mjs';
|
|
3
|
+
import { Clone } from '../clone/value.mjs';
|
|
3
4
|
// prettier-ignore
|
|
4
5
|
function FromProperties(P, K, options) {
|
|
5
6
|
const Acc = {};
|
|
6
7
|
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
7
|
-
Acc[K2] = Omit(P[K2], K, options);
|
|
8
|
+
Acc[K2] = Omit(P[K2], K, Clone(options));
|
|
8
9
|
return Acc;
|
|
9
10
|
}
|
|
10
11
|
// prettier-ignore
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Intersect } from '../intersect/index.mjs';
|
|
2
3
|
import { Union } from '../union/index.mjs';
|
|
3
4
|
import { Object } from '../object/index.mjs';
|
|
4
5
|
import { IndexPropertyKeys } from '../indexed/index.mjs';
|
|
5
6
|
import { Discard } from '../discard/index.mjs';
|
|
6
7
|
import { TransformKind } from '../symbols/index.mjs';
|
|
7
|
-
import { CloneType } from '../clone/type.mjs';
|
|
8
8
|
import { OmitFromMappedKey } from './omit-from-mapped-key.mjs';
|
|
9
9
|
import { OmitFromMappedResult } from './omit-from-mapped-result.mjs';
|
|
10
10
|
// ------------------------------------------------------------------
|
|
@@ -41,7 +41,7 @@ function OmitResolve(T, K) {
|
|
|
41
41
|
IsObject(T) ? Object(FromProperties(T.properties, K)) :
|
|
42
42
|
Object({}));
|
|
43
43
|
}
|
|
44
|
-
export function Omit(T, K, options
|
|
44
|
+
export function Omit(T, K, options) {
|
|
45
45
|
// mapped
|
|
46
46
|
if (IsMappedKey(K))
|
|
47
47
|
return OmitFromMappedKey(T, K, options);
|
|
@@ -50,6 +50,6 @@ export function Omit(T, K, options = {}) {
|
|
|
50
50
|
// non-mapped
|
|
51
51
|
const I = IsSchema(K) ? IndexPropertyKeys(K) : K;
|
|
52
52
|
const D = Discard(T, [TransformKind, '$id', 'required']);
|
|
53
|
-
const R =
|
|
54
|
-
return { ...D, ...R };
|
|
53
|
+
const R = OmitResolve(T, I);
|
|
54
|
+
return CreateType({ ...D, ...R }, options);
|
|
55
55
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { OptionalKind } from '../symbols/index.mjs';
|
|
2
|
-
import { CloneType } from '../clone/type.mjs';
|
|
3
3
|
import { Discard } from '../discard/index.mjs';
|
|
4
4
|
import { OptionalFromMappedResult } from './optional-from-mapped-result.mjs';
|
|
5
5
|
import { IsMappedResult } from '../guard/kind.mjs';
|
|
6
6
|
function RemoveOptional(schema) {
|
|
7
|
-
return Discard(
|
|
7
|
+
return CreateType(Discard(schema, [OptionalKind]));
|
|
8
8
|
}
|
|
9
9
|
function AddOptional(schema) {
|
|
10
|
-
return { ...
|
|
10
|
+
return CreateType({ ...schema, [OptionalKind]: 'Optional' });
|
|
11
11
|
}
|
|
12
12
|
// prettier-ignore
|
|
13
13
|
function OptionalWithFlag(schema, F) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Tuple } from '../tuple/index.mjs';
|
|
2
|
-
import { CloneRest } from '../clone/type.mjs';
|
|
3
2
|
/** `[JavaScript]` Extracts the Parameters from the given Function type */
|
|
4
|
-
export function Parameters(schema, options
|
|
5
|
-
return Tuple(
|
|
3
|
+
export function Parameters(schema, options) {
|
|
4
|
+
return Tuple(schema.parameters, options);
|
|
6
5
|
}
|
|
@@ -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 TPartialFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>> = (Ensure<TMappedResult<P>>);
|
|
11
|
-
export declare function PartialFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>>(R: R, options
|
|
11
|
+
export declare function PartialFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>>(R: R, options?: SchemaOptions): TMappedResult<P>;
|
|
12
12
|
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { MappedResult } from '../mapped/index.mjs';
|
|
2
2
|
import { Partial } from './partial.mjs';
|
|
3
|
+
import { Clone } from '../clone/value.mjs';
|
|
3
4
|
// prettier-ignore
|
|
4
5
|
function FromProperties(K, options) {
|
|
5
6
|
const Acc = {};
|
|
6
7
|
for (const K2 of globalThis.Object.getOwnPropertyNames(K))
|
|
7
|
-
Acc[K2] = Partial(K[K2], options);
|
|
8
|
+
Acc[K2] = Partial(K[K2], Clone(options));
|
|
8
9
|
return Acc;
|
|
9
10
|
}
|
|
10
11
|
// prettier-ignore
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Optional } from '../optional/index.mjs';
|
|
2
3
|
import { Object } from '../object/index.mjs';
|
|
3
4
|
import { Intersect } from '../intersect/index.mjs';
|
|
4
5
|
import { Union } from '../union/index.mjs';
|
|
5
6
|
import { Discard } from '../discard/index.mjs';
|
|
6
7
|
import { TransformKind } from '../symbols/index.mjs';
|
|
7
|
-
import { CloneType } from '../clone/type.mjs';
|
|
8
8
|
import { PartialFromMappedResult } from './partial-from-mapped-result.mjs';
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
// TypeGuard
|
|
@@ -32,10 +32,10 @@ function PartialResolve(T) {
|
|
|
32
32
|
Object({}));
|
|
33
33
|
}
|
|
34
34
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
35
|
-
export function Partial(T, options
|
|
35
|
+
export function Partial(T, options) {
|
|
36
36
|
if (IsMappedResult(T))
|
|
37
37
|
return PartialFromMappedResult(T, options);
|
|
38
38
|
const D = Discard(T, [TransformKind, '$id', 'required']);
|
|
39
|
-
const R =
|
|
40
|
-
return { ...D, ...R };
|
|
39
|
+
const R = PartialResolve(T);
|
|
40
|
+
return CreateType({ ...options, ...D, ...R });
|
|
41
41
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const PatternBoolean = "(true|false)";
|
|
2
2
|
export declare const PatternNumber = "(0|[1-9][0-9]*)";
|
|
3
3
|
export declare const PatternString = "(.*)";
|
|
4
|
+
export declare const PatternNever = "(?!.*)";
|
|
4
5
|
export declare const PatternBooleanExact = "^(true|false)$";
|
|
5
6
|
export declare const PatternNumberExact = "^(0|[1-9][0-9]*)$";
|
|
6
7
|
export declare const PatternStringExact = "^(.*)$";
|
|
8
|
+
export declare const PatternNeverExact = "^(?!.*)$";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export const PatternBoolean = '(true|false)';
|
|
2
2
|
export const PatternNumber = '(0|[1-9][0-9]*)';
|
|
3
3
|
export const PatternString = '(.*)';
|
|
4
|
+
export const PatternNever = '(?!.*)';
|
|
4
5
|
export const PatternBooleanExact = `^${PatternBoolean}$`;
|
|
5
6
|
export const PatternNumberExact = `^${PatternNumber}$`;
|
|
6
7
|
export const PatternStringExact = `^${PatternString}$`;
|
|
8
|
+
export const PatternNeverExact = `^${PatternNever}$`;
|
|
@@ -8,5 +8,5 @@ type TFromPropertyKey<T extends TSchema, K extends PropertyKey> = {
|
|
|
8
8
|
type TFromPropertyKeys<T extends TSchema, K extends PropertyKey[], Acc extends TProperties = {}> = (K extends [infer LK extends PropertyKey, ...infer RK extends PropertyKey[]] ? TFromPropertyKeys<T, RK, Acc & TFromPropertyKey<T, LK>> : Acc);
|
|
9
9
|
type TFromMappedKey<T extends TSchema, K extends TMappedKey> = (TFromPropertyKeys<T, K['keys']>);
|
|
10
10
|
export type TPickFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>> = (TMappedResult<P>);
|
|
11
|
-
export declare function PickFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>>(T: T, K: K, options
|
|
11
|
+
export declare function PickFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>>(T: T, K: K, options?: SchemaOptions): TMappedResult<P>;
|
|
12
12
|
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { MappedResult } from '../mapped/index.mjs';
|
|
2
2
|
import { Pick } from './pick.mjs';
|
|
3
|
+
import { Clone } from '../clone/value.mjs';
|
|
3
4
|
// prettier-ignore
|
|
4
5
|
function FromPropertyKey(T, K, options) {
|
|
5
6
|
return {
|
|
6
|
-
[K]: Pick(T, [K], options)
|
|
7
|
+
[K]: Pick(T, [K], Clone(options))
|
|
7
8
|
};
|
|
8
9
|
}
|
|
9
10
|
// prettier-ignore
|
|
@@ -8,5 +8,5 @@ type TFromProperties<P extends TProperties, K extends PropertyKey[]> = ({
|
|
|
8
8
|
});
|
|
9
9
|
type TFromMappedResult<R extends TMappedResult, K extends PropertyKey[]> = (Evaluate<TFromProperties<R['properties'], K>>);
|
|
10
10
|
export type TPickFromMappedResult<T extends TMappedResult, K extends PropertyKey[], P extends TProperties = TFromMappedResult<T, K>> = (Ensure<TMappedResult<P>>);
|
|
11
|
-
export declare function PickFromMappedResult<R extends TMappedResult, K extends PropertyKey[], P extends TProperties = TFromMappedResult<R, K>>(R: R, K: [...K], options
|
|
11
|
+
export declare function PickFromMappedResult<R extends TMappedResult, K extends PropertyKey[], P extends TProperties = TFromMappedResult<R, K>>(R: R, K: [...K], options?: SchemaOptions): TMappedResult<P>;
|
|
12
12
|
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { MappedResult } from '../mapped/index.mjs';
|
|
2
2
|
import { Pick } from './pick.mjs';
|
|
3
|
+
import { Clone } from '../clone/value.mjs';
|
|
3
4
|
// prettier-ignore
|
|
4
5
|
function FromProperties(P, K, options) {
|
|
5
6
|
const Acc = {};
|
|
6
7
|
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
7
|
-
Acc[K2] = Pick(P[K2], K, options);
|
|
8
|
+
Acc[K2] = Pick(P[K2], K, Clone(options));
|
|
8
9
|
return Acc;
|
|
9
10
|
}
|
|
10
11
|
// prettier-ignore
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Intersect } from '../intersect/index.mjs';
|
|
2
3
|
import { Union } from '../union/index.mjs';
|
|
3
4
|
import { Object } from '../object/index.mjs';
|
|
4
5
|
import { IndexPropertyKeys } from '../indexed/index.mjs';
|
|
5
6
|
import { Discard } from '../discard/index.mjs';
|
|
6
7
|
import { TransformKind } from '../symbols/index.mjs';
|
|
7
|
-
import { CloneType } from '../clone/type.mjs';
|
|
8
8
|
import { PickFromMappedKey } from './pick-from-mapped-key.mjs';
|
|
9
9
|
import { PickFromMappedResult } from './pick-from-mapped-result.mjs';
|
|
10
10
|
// ------------------------------------------------------------------
|
|
@@ -36,7 +36,7 @@ function PickResolve(T, K) {
|
|
|
36
36
|
IsObject(T) ? Object(FromProperties(T.properties, K)) :
|
|
37
37
|
Object({}));
|
|
38
38
|
}
|
|
39
|
-
export function Pick(T, K, options
|
|
39
|
+
export function Pick(T, K, options) {
|
|
40
40
|
// mapped
|
|
41
41
|
if (IsMappedKey(K))
|
|
42
42
|
return PickFromMappedKey(T, K, options);
|
|
@@ -45,6 +45,6 @@ export function Pick(T, K, options = {}) {
|
|
|
45
45
|
// non-mapped
|
|
46
46
|
const I = IsSchema(K) ? IndexPropertyKeys(K) : K;
|
|
47
47
|
const D = Discard(T, [TransformKind, '$id', 'required']);
|
|
48
|
-
const R =
|
|
49
|
-
return { ...D, ...R };
|
|
48
|
+
const R = PickResolve(T, I);
|
|
49
|
+
return CreateType({ ...D, ...R }, options);
|
|
50
50
|
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
import { Kind } from '../symbols/index.mjs';
|
|
3
3
|
/** `[JavaScript]` Creates a Promise type */
|
|
4
|
-
export function Promise(item, options
|
|
5
|
-
return {
|
|
6
|
-
...options,
|
|
7
|
-
[Kind]: 'Promise',
|
|
8
|
-
type: 'Promise',
|
|
9
|
-
item: CloneType(item),
|
|
10
|
-
};
|
|
4
|
+
export function Promise(item, options) {
|
|
5
|
+
return CreateType({ [Kind]: 'Promise', type: 'Promise', item }, options);
|
|
11
6
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { ReadonlyKind } from '../symbols/index.mjs';
|
|
2
|
-
import { CloneType } from '../clone/type.mjs';
|
|
3
3
|
import { Discard } from '../discard/index.mjs';
|
|
4
4
|
import { ReadonlyFromMappedResult } from './readonly-from-mapped-result.mjs';
|
|
5
5
|
import { IsMappedResult } from '../guard/kind.mjs';
|
|
6
6
|
function RemoveReadonly(schema) {
|
|
7
|
-
return Discard(
|
|
7
|
+
return CreateType(Discard(schema, [ReadonlyKind]));
|
|
8
8
|
}
|
|
9
9
|
function AddReadonly(schema) {
|
|
10
|
-
return { ...
|
|
10
|
+
return CreateType({ ...schema, [ReadonlyKind]: 'Readonly' });
|
|
11
11
|
}
|
|
12
12
|
// prettier-ignore
|
|
13
13
|
function ReadonlyWithFlag(schema, F) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TSchema } from '../schema/index.mjs';
|
|
2
2
|
import type { Static } from '../static/index.mjs';
|
|
3
3
|
import type { Evaluate, Ensure, Assert } from '../helpers/index.mjs';
|
|
4
|
+
import { type TAny } from '../any/index.mjs';
|
|
4
5
|
import { type TObject, type TProperties, type TAdditionalProperties, type ObjectOptions } from '../object/index.mjs';
|
|
5
6
|
import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
|
|
6
7
|
import { type TNever } from '../never/index.mjs';
|
|
@@ -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 {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Object } from '../object/index.mjs';
|
|
2
3
|
import { Never } from '../never/index.mjs';
|
|
3
4
|
import { Union } from '../union/index.mjs';
|
|
4
5
|
import { IsTemplateLiteralFinite } from '../template-literal/index.mjs';
|
|
5
|
-
import { PatternStringExact, PatternNumberExact } from '../patterns/index.mjs';
|
|
6
|
+
import { PatternStringExact, PatternNumberExact, PatternNeverExact } from '../patterns/index.mjs';
|
|
6
7
|
import { IndexPropertyKeys } from '../indexed/index.mjs';
|
|
7
8
|
import { Kind, Hint } from '../symbols/index.mjs';
|
|
8
|
-
import { CloneType } from '../clone/type.mjs';
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
// ValueGuard
|
|
11
11
|
// ------------------------------------------------------------------
|
|
@@ -13,18 +13,17 @@ import { IsUndefined } from '../guard/value.mjs';
|
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
14
|
// TypeGuard
|
|
15
15
|
// ------------------------------------------------------------------
|
|
16
|
-
import { IsInteger, IsLiteral, IsNumber, IsString, IsRegExp, IsTemplateLiteral, IsUnion } from '../guard/kind.mjs';
|
|
16
|
+
import { IsInteger, IsLiteral, IsAny, IsNever, IsNumber, IsString, IsRegExp, IsTemplateLiteral, IsUnion } from '../guard/kind.mjs';
|
|
17
17
|
// ------------------------------------------------------------------
|
|
18
18
|
// RecordCreateFromPattern
|
|
19
19
|
// ------------------------------------------------------------------
|
|
20
20
|
// prettier-ignore
|
|
21
21
|
function RecordCreateFromPattern(pattern, T, options) {
|
|
22
|
-
return {
|
|
23
|
-
...options,
|
|
22
|
+
return CreateType({
|
|
24
23
|
[Kind]: 'Record',
|
|
25
24
|
type: 'object',
|
|
26
|
-
patternProperties: { [pattern]:
|
|
27
|
-
};
|
|
25
|
+
patternProperties: { [pattern]: T }
|
|
26
|
+
}, options);
|
|
28
27
|
}
|
|
29
28
|
// ------------------------------------------------------------------
|
|
30
29
|
// RecordCreateFromKeys
|
|
@@ -33,7 +32,7 @@ function RecordCreateFromPattern(pattern, T, options) {
|
|
|
33
32
|
function RecordCreateFromKeys(K, T, options) {
|
|
34
33
|
const Acc = {};
|
|
35
34
|
for (const K2 of K)
|
|
36
|
-
Acc[K2] =
|
|
35
|
+
Acc[K2] = T;
|
|
37
36
|
return Object(Acc, { ...options, [Hint]: 'Record' });
|
|
38
37
|
}
|
|
39
38
|
// prettier-ignore
|
|
@@ -60,6 +59,14 @@ function FromStringKey(K, T, options) {
|
|
|
60
59
|
return RecordCreateFromPattern(pattern, T, options);
|
|
61
60
|
}
|
|
62
61
|
// prettier-ignore
|
|
62
|
+
function FromAnyKey(K, T, options) {
|
|
63
|
+
return RecordCreateFromPattern(PatternStringExact, T, options);
|
|
64
|
+
}
|
|
65
|
+
// prettier-ignore
|
|
66
|
+
function FromNeverKey(K, T, options) {
|
|
67
|
+
return RecordCreateFromPattern(PatternNeverExact, T, options);
|
|
68
|
+
}
|
|
69
|
+
// prettier-ignore
|
|
63
70
|
function FromIntegerKey(_, T, options) {
|
|
64
71
|
return RecordCreateFromPattern(PatternNumberExact, T, options);
|
|
65
72
|
}
|
|
@@ -80,5 +87,7 @@ export function Record(K, T, options = {}) {
|
|
|
80
87
|
IsNumber(K) ? FromNumberKey(K, T, options) :
|
|
81
88
|
IsRegExp(K) ? FromRegExpKey(K, T, options) :
|
|
82
89
|
IsString(K) ? FromStringKey(K, T, options) :
|
|
83
|
-
|
|
90
|
+
IsAny(K) ? FromAnyKey(K, T, options) :
|
|
91
|
+
IsNever(K) ? FromNeverKey(K, T, options) :
|
|
92
|
+
Never(options));
|
|
84
93
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CloneType } from '../clone/type.mjs';
|
|
2
|
+
import { CreateType } from '../create/type.mjs';
|
|
2
3
|
import { IsUndefined } from '../guard/value.mjs';
|
|
3
4
|
import { Kind, Hint } from '../symbols/index.mjs';
|
|
4
5
|
// Auto Tracked For Recursive Types without ID's
|
|
@@ -7,8 +8,8 @@ let Ordinal = 0;
|
|
|
7
8
|
export function Recursive(callback, options = {}) {
|
|
8
9
|
if (IsUndefined(options.$id))
|
|
9
10
|
options.$id = `T${Ordinal++}`;
|
|
10
|
-
const thisType = callback({ [Kind]: 'This', $ref: `${options.$id}` });
|
|
11
|
+
const thisType = CloneType(callback({ [Kind]: 'This', $ref: `${options.$id}` }));
|
|
11
12
|
thisType.$id = options.$id;
|
|
12
13
|
// prettier-ignore
|
|
13
|
-
return
|
|
14
|
+
return CreateType({ [Hint]: 'Recursive', ...thisType }, options);
|
|
14
15
|
}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Kind } from '../symbols/index.mjs';
|
|
2
3
|
// ------------------------------------------------------------------
|
|
3
4
|
// ValueGuard
|
|
4
5
|
// ------------------------------------------------------------------
|
|
5
6
|
import { IsString, IsUndefined } from '../guard/value.mjs';
|
|
6
7
|
/** `[Json]` Creates a Ref type. */
|
|
7
|
-
export function Ref(unresolved, options
|
|
8
|
+
export function Ref(unresolved, options) {
|
|
8
9
|
if (IsString(unresolved))
|
|
9
|
-
return {
|
|
10
|
+
return CreateType({ [Kind]: 'Ref', $ref: unresolved }, options);
|
|
10
11
|
if (IsUndefined(unresolved.$id))
|
|
11
12
|
throw new Error('Reference target type must specify an $id');
|
|
12
|
-
return {
|
|
13
|
-
...options,
|
|
14
|
-
[Kind]: 'Ref',
|
|
15
|
-
$ref: unresolved.$id,
|
|
16
|
-
};
|
|
13
|
+
return CreateType({ [Kind]: 'Ref', $ref: unresolved.$id }, options);
|
|
17
14
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { IsString } from '../guard/value.mjs';
|
|
2
3
|
import { Kind } from '../symbols/index.mjs';
|
|
3
4
|
/** `[JavaScript]` Creates a RegExp type */
|
|
4
|
-
export function RegExp(unresolved, options
|
|
5
|
+
export function RegExp(unresolved, options) {
|
|
5
6
|
const expr = IsString(unresolved) ? new globalThis.RegExp(unresolved) : unresolved;
|
|
6
|
-
return {
|
|
7
|
+
return CreateType({ [Kind]: 'RegExp', type: 'RegExp', source: expr.source, flags: expr.flags }, options);
|
|
7
8
|
}
|
|
@@ -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 {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Intersect } from '../intersect/index.mjs';
|
|
2
3
|
import { Union } from '../union/index.mjs';
|
|
3
4
|
import { Object } from '../object/index.mjs';
|
|
4
5
|
import { OptionalKind, TransformKind } from '../symbols/index.mjs';
|
|
5
|
-
import { CloneType } from '../clone/type.mjs';
|
|
6
6
|
import { Discard } from '../discard/index.mjs';
|
|
7
7
|
import { RequiredFromMappedResult } from './required-from-mapped-result.mjs';
|
|
8
8
|
// ------------------------------------------------------------------
|
|
@@ -31,13 +31,13 @@ function RequiredResolve(T) {
|
|
|
31
31
|
Object({}));
|
|
32
32
|
}
|
|
33
33
|
/** `[Json]` Constructs a type where all properties are required */
|
|
34
|
-
export function Required(T, options
|
|
34
|
+
export function Required(T, options) {
|
|
35
35
|
if (IsMappedResult(T)) {
|
|
36
36
|
return RequiredFromMappedResult(T, options);
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
39
|
const D = Discard(T, [TransformKind, '$id', 'required']);
|
|
40
|
-
const R =
|
|
41
|
-
return { ...D, ...R };
|
|
40
|
+
const R = RequiredResolve(T);
|
|
41
|
+
return CreateType({ ...D, ...R }, options);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -2,7 +2,7 @@ import type { TSchema } from '../schema/index.mjs';
|
|
|
2
2
|
import type { TIntersect } from '../intersect/index.mjs';
|
|
3
3
|
import type { TUnion } from '../union/index.mjs';
|
|
4
4
|
import type { TTuple } from '../tuple/index.mjs';
|
|
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 */
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { CloneRest } from '../clone/type.mjs';
|
|
2
1
|
// ------------------------------------------------------------------
|
|
3
2
|
// TypeGuard
|
|
4
3
|
// ------------------------------------------------------------------
|
|
5
4
|
import { IsIntersect, IsUnion, IsTuple } from '../guard/kind.mjs';
|
|
6
5
|
// prettier-ignore
|
|
7
6
|
function RestResolve(T) {
|
|
8
|
-
return (IsIntersect(T) ?
|
|
9
|
-
IsUnion(T) ?
|
|
10
|
-
IsTuple(T) ?
|
|
7
|
+
return (IsIntersect(T) ? T.allOf :
|
|
8
|
+
IsUnion(T) ? T.anyOf :
|
|
9
|
+
IsTuple(T) ? T.items ?? [] :
|
|
11
10
|
[]);
|
|
12
11
|
}
|
|
13
12
|
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
14
13
|
export function Rest(T) {
|
|
15
|
-
return
|
|
14
|
+
return RestResolve(T);
|
|
16
15
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
3
|
-
export function ReturnType(schema, options
|
|
4
|
-
return
|
|
3
|
+
export function ReturnType(schema, options) {
|
|
4
|
+
return CreateType(schema.returns, options);
|
|
5
5
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Kind } from '../symbols/index.mjs';
|
|
2
3
|
/** `[Json]` Creates a String type */
|
|
3
|
-
export function String(options
|
|
4
|
-
return {
|
|
4
|
+
export function String(options) {
|
|
5
|
+
return CreateType({ [Kind]: 'String', type: 'string' }, options);
|
|
5
6
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { Kind } from '../symbols/index.mjs';
|
|
2
3
|
/** `[JavaScript]` Creates a Symbol type */
|
|
3
4
|
export function Symbol(options) {
|
|
4
|
-
return {
|
|
5
|
+
return CreateType({ [Kind]: 'Symbol', type: 'symbol' }, options);
|
|
5
6
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
1
2
|
import { TemplateLiteralSyntax } from './syntax.mjs';
|
|
2
3
|
import { TemplateLiteralPattern } from './pattern.mjs';
|
|
3
4
|
import { IsString } from '../guard/value.mjs';
|
|
4
5
|
import { Kind } from '../symbols/index.mjs';
|
|
5
6
|
/** `[Json]` Creates a TemplateLiteral type */
|
|
6
7
|
// prettier-ignore
|
|
7
|
-
export function TemplateLiteral(unresolved, options
|
|
8
|
+
export function TemplateLiteral(unresolved, options) {
|
|
8
9
|
const pattern = IsString(unresolved)
|
|
9
10
|
? TemplateLiteralPattern(TemplateLiteralSyntax(unresolved))
|
|
10
11
|
: TemplateLiteralPattern(unresolved);
|
|
11
|
-
return {
|
|
12
|
+
return CreateType({ [Kind]: 'TemplateLiteral', type: 'string', pattern }, options);
|
|
12
13
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { TransformKind } from '../symbols/index.mjs';
|
|
2
|
-
import { CloneType } from '../clone/type.mjs';
|
|
3
2
|
// ------------------------------------------------------------------
|
|
4
3
|
// TypeGuard
|
|
5
4
|
// ------------------------------------------------------------------
|
|
@@ -32,8 +31,7 @@ export class TransformEncodeBuilder {
|
|
|
32
31
|
return { ...schema, [TransformKind]: Codec };
|
|
33
32
|
}
|
|
34
33
|
Encode(encode) {
|
|
35
|
-
|
|
36
|
-
return (IsTransform(schema) ? this.EncodeTransform(encode, schema) : this.EncodeSchema(encode, schema));
|
|
34
|
+
return (IsTransform(this.schema) ? this.EncodeTransform(encode, this.schema) : this.EncodeSchema(encode, this.schema));
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
/** `[Json]` Creates a Transform type */
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
import { Kind } from '../symbols/index.mjs';
|
|
3
3
|
/** `[Json]` Creates a Tuple type */
|
|
4
|
-
export function Tuple(items, options
|
|
5
|
-
// return TupleResolver.Resolve(T)
|
|
6
|
-
const [additionalItems, minItems, maxItems] = [false, items.length, items.length];
|
|
4
|
+
export function Tuple(items, options) {
|
|
7
5
|
// prettier-ignore
|
|
8
|
-
return (items.length > 0 ?
|
|
9
|
-
{
|
|
10
|
-
{
|
|
6
|
+
return CreateType(items.length > 0 ?
|
|
7
|
+
{ [Kind]: 'Tuple', type: 'array', items, additionalItems: false, minItems: items.length, maxItems: items.length } :
|
|
8
|
+
{ [Kind]: 'Tuple', type: 'array', minItems: items.length, maxItems: items.length }, options);
|
|
11
9
|
}
|