@sinclair/typebox 0.32.0-dev-15 → 0.32.0-dev-16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/import/index.d.mts +2 -2
- package/build/import/index.mjs +2 -2
- package/build/import/type/array/array.d.mts +1 -1
- package/build/import/type/constructor/constructor.d.mts +4 -4
- package/build/import/type/exclude/exclude.d.mts +3 -3
- package/build/import/type/extends/extends.mjs +1 -1
- package/build/import/type/extract/extract.d.mts +3 -3
- package/build/import/type/function/function.d.mts +4 -4
- package/build/import/type/indexed/indexed-result.d.mts +6 -6
- package/build/import/type/indexed/indexed-result.mjs +7 -7
- package/build/import/type/indexed/indexed.mjs +1 -1
- package/build/import/type/intersect/index.d.mts +2 -0
- package/build/import/type/intersect/index.mjs +2 -0
- package/build/import/type/intersect/intersect-create.d.mts +3 -0
- package/build/import/type/intersect/intersect-create.mjs +12 -0
- package/build/import/type/intersect/intersect-evaluated.d.mts +16 -0
- package/build/import/type/intersect/intersect-evaluated.mjs +35 -0
- package/build/import/type/intersect/intersect-type.d.mts +15 -0
- package/build/import/type/intersect/intersect-type.mjs +1 -0
- package/build/import/type/intersect/intersect.d.mts +4 -20
- package/build/import/type/intersect/intersect.mjs +5 -17
- package/build/import/type/keyof/keyof.d.mts +2 -2
- package/build/import/type/keyof/keyof.mjs +2 -2
- package/build/import/type/mapped/mapped.mjs +1 -2
- package/build/import/type/object/object.d.mts +5 -5
- package/build/import/type/record/record.d.mts +0 -1
- package/build/import/type/record/record.mjs +1 -1
- package/build/import/type/recursive/recursive.d.mts +3 -2
- package/build/import/type/recursive/recursive.mjs +1 -5
- package/build/import/type/template-literal/syntax.d.mts +4 -4
- package/build/import/type/template-literal/template-literal.d.mts +4 -4
- package/build/import/type/transform/transform.d.mts +3 -2
- package/build/import/type/transform/transform.mjs +1 -1
- package/build/import/type/tuple/tuple.d.mts +3 -3
- package/build/import/type/type/json.d.mts +4 -4
- package/build/import/type/union/index.d.mts +2 -0
- package/build/import/type/union/index.mjs +2 -0
- package/build/import/type/union/union-create.d.mts +3 -0
- package/build/import/type/union/union-create.mjs +5 -0
- package/build/import/type/union/union-evaluated.d.mts +16 -0
- package/build/import/type/union/union-evaluated.mjs +31 -0
- package/build/import/type/union/union-type.d.mts +12 -0
- package/build/import/type/union/union-type.mjs +1 -0
- package/build/import/type/union/union.d.mts +3 -13
- package/build/import/type/union/union.mjs +3 -10
- package/build/import/value/delta/delta.d.mts +1 -1
- package/build/require/index.d.ts +2 -2
- package/build/require/index.js +5 -2
- package/build/require/type/array/array.d.ts +1 -1
- package/build/require/type/constructor/constructor.d.ts +4 -4
- package/build/require/type/exclude/exclude.d.ts +3 -3
- package/build/require/type/extends/extends.js +5 -5
- package/build/require/type/extract/extract.d.ts +3 -3
- package/build/require/type/function/function.d.ts +4 -4
- package/build/require/type/indexed/indexed-result.d.ts +6 -6
- package/build/require/type/indexed/indexed-result.js +4 -4
- package/build/require/type/indexed/indexed.js +4 -4
- package/build/require/type/intersect/index.d.ts +2 -0
- package/build/require/type/intersect/index.js +2 -0
- package/build/require/type/intersect/intersect-create.d.ts +3 -0
- package/build/require/type/intersect/intersect-create.js +16 -0
- package/build/require/type/intersect/intersect-evaluated.d.ts +16 -0
- package/build/require/type/intersect/intersect-evaluated.js +39 -0
- package/build/require/type/intersect/intersect-type.d.ts +15 -0
- package/build/require/type/intersect/intersect-type.js +3 -0
- package/build/require/type/intersect/intersect.d.ts +4 -20
- package/build/require/type/intersect/intersect.js +5 -18
- package/build/require/type/keyof/keyof.d.ts +2 -2
- package/build/require/type/keyof/keyof.js +1 -1
- package/build/require/type/mapped/mapped.js +18 -19
- package/build/require/type/object/object.d.ts +5 -5
- package/build/require/type/record/record.d.ts +0 -1
- package/build/require/type/record/record.js +1 -2
- package/build/require/type/recursive/recursive.d.ts +3 -2
- package/build/require/type/recursive/recursive.js +1 -5
- package/build/require/type/template-literal/syntax.d.ts +4 -4
- package/build/require/type/template-literal/template-literal.d.ts +4 -4
- package/build/require/type/transform/transform.d.ts +3 -2
- package/build/require/type/transform/transform.js +4 -4
- package/build/require/type/tuple/tuple.d.ts +3 -3
- package/build/require/type/type/json.d.ts +4 -4
- package/build/require/type/union/index.d.ts +2 -0
- package/build/require/type/union/index.js +2 -0
- package/build/require/type/union/union-create.d.ts +3 -0
- package/build/require/type/union/union-create.js +9 -0
- package/build/require/type/union/union-evaluated.d.ts +16 -0
- package/build/require/type/union/union-evaluated.js +35 -0
- package/build/require/type/union/union-type.d.ts +12 -0
- package/build/require/type/union/union-type.js +3 -0
- package/build/require/type/union/union.d.ts +3 -13
- package/build/require/type/union/union.js +3 -11
- package/build/require/value/delta/delta.d.ts +1 -1
- package/package.json +1 -1
- package/readme.md +27 -19
package/build/import/index.d.mts
CHANGED
|
@@ -24,7 +24,7 @@ export { Increment, type Assert, type AssertType, type AssertRest, type AssertPr
|
|
|
24
24
|
export { Index, IndexPropertyKeys, IndexFromMappedKey, type TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey } from './type/indexed/index.mjs';
|
|
25
25
|
export { InstanceType, type TInstanceType } from './type/instance-type/index.mjs';
|
|
26
26
|
export { Integer, type TInteger, type IntegerOptions } from './type/integer/index.mjs';
|
|
27
|
-
export { Intersect, type TIntersect, type IntersectOptions } from './type/intersect/index.mjs';
|
|
27
|
+
export { Intersect, IntersectEvaluated, type TIntersect, type IntersectOptions } from './type/intersect/index.mjs';
|
|
28
28
|
export { Iterator, type TIterator } from './type/iterator/index.mjs';
|
|
29
29
|
export { Intrinsic, IntrinsicFromMappedKey, type TIntrinsic, Capitalize, type TCapitalize, Lowercase, type TLowercase, Uncapitalize, type TUncapitalize, Uppercase, type TUppercase } from './type/intrinsic/index.mjs';
|
|
30
30
|
export { KeyOf, type TKeyOf, type KeyOfFromMappedResult, KeyOfPropertyKeys, KeyOfPattern } from './type/keyof/index.mjs';
|
|
@@ -60,7 +60,7 @@ export { Transform, type TTransform, type TransformOptions, type TransformFuncti
|
|
|
60
60
|
export { Tuple, type TTuple } from './type/tuple/index.mjs';
|
|
61
61
|
export { Uint8Array, type TUint8Array, type Uint8ArrayOptions } from './type/uint8array/index.mjs';
|
|
62
62
|
export { Undefined, type TUndefined } from './type/undefined/index.mjs';
|
|
63
|
-
export { Union, type TUnion } from './type/union/index.mjs';
|
|
63
|
+
export { Union, UnionEvaluated, type TUnion } from './type/union/index.mjs';
|
|
64
64
|
export { Unknown, type TUnknown } from './type/unknown/index.mjs';
|
|
65
65
|
export { Unsafe, type TUnsafe } from './type/unsafe/index.mjs';
|
|
66
66
|
export { Void, type TVoid } from './type/void/index.mjs';
|
package/build/import/index.mjs
CHANGED
|
@@ -24,7 +24,7 @@ export { Increment } from './type/helpers/index.mjs';
|
|
|
24
24
|
export { Index, IndexPropertyKeys, IndexFromMappedKey } from './type/indexed/index.mjs';
|
|
25
25
|
export { InstanceType } from './type/instance-type/index.mjs';
|
|
26
26
|
export { Integer } from './type/integer/index.mjs';
|
|
27
|
-
export { Intersect } from './type/intersect/index.mjs';
|
|
27
|
+
export { Intersect, IntersectEvaluated } from './type/intersect/index.mjs';
|
|
28
28
|
export { Iterator } from './type/iterator/index.mjs';
|
|
29
29
|
export { Intrinsic, IntrinsicFromMappedKey, Capitalize, Lowercase, Uncapitalize, Uppercase } from './type/intrinsic/index.mjs';
|
|
30
30
|
export { KeyOf, KeyOfPropertyKeys, KeyOfPattern } from './type/keyof/index.mjs';
|
|
@@ -58,7 +58,7 @@ export { Transform, TransformDecodeBuilder, TransformEncodeBuilder } from './typ
|
|
|
58
58
|
export { Tuple } from './type/tuple/index.mjs';
|
|
59
59
|
export { Uint8Array } from './type/uint8array/index.mjs';
|
|
60
60
|
export { Undefined } from './type/undefined/index.mjs';
|
|
61
|
-
export { Union } from './type/union/index.mjs';
|
|
61
|
+
export { Union, UnionEvaluated } from './type/union/index.mjs';
|
|
62
62
|
export { Unknown } from './type/unknown/index.mjs';
|
|
63
63
|
export { Unsafe } from './type/unsafe/index.mjs';
|
|
64
64
|
export { Void } from './type/void/index.mjs';
|
|
@@ -11,7 +11,7 @@ export interface ArrayOptions extends SchemaOptions {
|
|
|
11
11
|
}
|
|
12
12
|
export interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptions {
|
|
13
13
|
[Kind]: 'Array';
|
|
14
|
-
static: Static<T, this['params']
|
|
14
|
+
static: Array<Static<T, this['params']>>;
|
|
15
15
|
type: 'array';
|
|
16
16
|
items: T;
|
|
17
17
|
}
|
|
@@ -2,12 +2,12 @@ import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
|
2
2
|
import type { Static } from '../static/index.mjs';
|
|
3
3
|
import type { Ensure } from '../helpers/index.mjs';
|
|
4
4
|
import { Kind } from '../symbols/index.mjs';
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
export type
|
|
5
|
+
type TConstructorStaticReturnType<T extends TSchema, P extends unknown[]> = Static<T, P>;
|
|
6
|
+
type TConstructorStaticParameters<T extends TSchema[], P extends unknown[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [Static<L, P>, ...TConstructorStaticParameters<R, P>] : [];
|
|
7
|
+
export type TConstructorStatic<T extends TSchema[], U extends TSchema, P extends unknown[]> = (Ensure<new (...param: TConstructorStaticParameters<T, P>) => TConstructorStaticReturnType<U, P>>);
|
|
8
8
|
export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
9
9
|
[Kind]: 'Constructor';
|
|
10
|
-
static:
|
|
10
|
+
static: TConstructorStatic<T, U, this['params']>;
|
|
11
11
|
type: 'Constructor';
|
|
12
12
|
parameters: T;
|
|
13
13
|
returns: U;
|
|
@@ -6,15 +6,15 @@ import { type TUnion } from '../union/index.mjs';
|
|
|
6
6
|
import { type TNever } from '../never/index.mjs';
|
|
7
7
|
import { type TLiteral } from '../literal/index.mjs';
|
|
8
8
|
import { type Static } from '../static/index.mjs';
|
|
9
|
-
import {
|
|
9
|
+
import { UnionEvaluated } from '../union/index.mjs';
|
|
10
10
|
import { type TExcludeFromMappedResult } from './exclude-from-mapped-result.mjs';
|
|
11
|
-
type ExcludeTemplateLiteralResult<T extends string> =
|
|
11
|
+
type ExcludeTemplateLiteralResult<T extends string> = UnionEvaluated<AssertRest<UnionToTuple<{
|
|
12
12
|
[K in T]: TLiteral<K>;
|
|
13
13
|
}[T]>>>;
|
|
14
14
|
type ExcludeTemplateLiteral<T extends TTemplateLiteral, U extends TSchema> = (Exclude<Static<T>, Static<U>> extends infer S ? ExcludeTemplateLiteralResult<Assert<S, string>> : never);
|
|
15
15
|
type ExcludeArray<T extends TSchema[], U extends TSchema> = AssertRest<UnionToTuple<{
|
|
16
16
|
[K in keyof T]: Static<AssertType<T[K]>> extends Static<U> ? never : T[K];
|
|
17
|
-
}[number]>> extends infer R extends TSchema[] ?
|
|
17
|
+
}[number]>> extends infer R extends TSchema[] ? UnionEvaluated<R> : never;
|
|
18
18
|
type ExcludeResolve<T extends TSchema, U extends TSchema> = T extends TTemplateLiteral ? ExcludeTemplateLiteral<T, U> : T extends TUnion<infer S> ? ExcludeArray<S, U> : T extends U ? TNever : T;
|
|
19
19
|
declare function ExcludeResolve<L extends TSchema, R extends TSchema>(L: L, R: R): ExcludeResolve<L, R>;
|
|
20
20
|
export type TExclude<T extends TSchema, U extends TSchema> = ExcludeResolve<T, U>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { TMappedKey as IsMappedKeyType, TMappedResult as IsMappedResultType } from '../guard/type.mjs';
|
|
2
1
|
import { Union } from '../union/index.mjs';
|
|
3
2
|
import { ExtendsCheck, ExtendsResult } from './extends-check.mjs';
|
|
4
3
|
import { CloneType } from '../clone/type.mjs';
|
|
5
4
|
import { ExtendsFromMappedKey } from './extends-from-mapped-key.mjs';
|
|
6
5
|
import { ExtendsFromMappedResult } from './extends-from-mapped-result.mjs';
|
|
6
|
+
import { TMappedKey as IsMappedKeyType, TMappedResult as IsMappedResultType } from '../guard/type.mjs';
|
|
7
7
|
function ExtendsResolve(left, right, trueType, falseType) {
|
|
8
8
|
const R = ExtendsCheck(left, right);
|
|
9
9
|
return (R === ExtendsResult.Union ? Union([trueType, falseType]) :
|
|
@@ -5,15 +5,15 @@ import { type TTemplateLiteral } from '../template-literal/index.mjs';
|
|
|
5
5
|
import { type TLiteral } from '../literal/index.mjs';
|
|
6
6
|
import { type TUnion } from '../union/index.mjs';
|
|
7
7
|
import { type Static } from '../static/index.mjs';
|
|
8
|
-
import {
|
|
8
|
+
import { UnionEvaluated } from '../union/index.mjs';
|
|
9
9
|
import { type TExtractFromMappedResult } from './extract-from-mapped-result.mjs';
|
|
10
|
-
type FromTemplateLiteralResult<T extends string> =
|
|
10
|
+
type FromTemplateLiteralResult<T extends string> = UnionEvaluated<AssertRest<UnionToTuple<{
|
|
11
11
|
[K in T]: TLiteral<K>;
|
|
12
12
|
}[T]>>>;
|
|
13
13
|
type FromTemplateLiteral<T extends TTemplateLiteral, U extends TSchema> = Extract<Static<T>, Static<U>> extends infer S ? FromTemplateLiteralResult<Assert<S, string>> : never;
|
|
14
14
|
type FromArray<T extends TSchema[], U extends TSchema> = AssertRest<UnionToTuple<{
|
|
15
15
|
[K in keyof T]: Static<AssertType<T[K]>> extends Static<U> ? T[K] : never;
|
|
16
|
-
}[number]>> extends infer R extends TSchema[] ?
|
|
16
|
+
}[number]>> extends infer R extends TSchema[] ? UnionEvaluated<R> : never;
|
|
17
17
|
export type ExtractResolve<T extends TSchema, U extends TSchema> = (T extends TTemplateLiteral ? FromTemplateLiteral<T, U> : T extends TUnion<infer S> ? FromArray<S, U> : T extends U ? T : T);
|
|
18
18
|
export declare function ExtractResolve<L extends TSchema, R extends TSchema>(L: L, R: R): ExtractResolve<L, R>;
|
|
19
19
|
export type TExtract<T extends TSchema, U extends TSchema> = ExtractResolve<T, U>;
|
|
@@ -2,12 +2,12 @@ import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
|
2
2
|
import type { Static } from '../static/index.mjs';
|
|
3
3
|
import type { Ensure } from '../helpers/index.mjs';
|
|
4
4
|
import { Kind } from '../symbols/index.mjs';
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
type
|
|
5
|
+
type FunctionStaticReturnType<T extends TSchema, P extends unknown[]> = Static<T, P>;
|
|
6
|
+
type FunctionStaticParameters<T extends TSchema[], P extends unknown[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [Static<L, P>, ...FunctionStaticParameters<R, P>] : [];
|
|
7
|
+
type FunctionStatic<T extends TSchema[], U extends TSchema, P extends unknown[]> = (Ensure<(...param: FunctionStaticParameters<T, P>) => FunctionStaticReturnType<U, P>>);
|
|
8
8
|
export interface TFunction<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
9
9
|
[Kind]: 'Function';
|
|
10
|
-
static:
|
|
10
|
+
static: FunctionStatic<T, U, this['params']>;
|
|
11
11
|
type: 'Function';
|
|
12
12
|
parameters: T;
|
|
13
13
|
returns: U;
|
|
@@ -6,19 +6,19 @@ import { type TIntersect } from '../intersect/index.mjs';
|
|
|
6
6
|
import { type TUnion } from '../union/index.mjs';
|
|
7
7
|
import { type TTuple } from '../tuple/index.mjs';
|
|
8
8
|
import { type TArray } from '../array/index.mjs';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { IntersectEvaluated } from '../intersect/index.mjs';
|
|
10
|
+
import { UnionEvaluated } from '../union/index.mjs';
|
|
11
11
|
type FromRest<T extends TSchema[], K extends PropertyKey> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [FromKey<L, K>, ...FromRest<R, K>] : []);
|
|
12
12
|
declare function FromRest<T extends TSchema[], K extends PropertyKey>(T: [...T], K: K): FromRest<T, K>;
|
|
13
13
|
type FromIntersectRest<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? [...FromIntersectRest<R>] : [L, ...FromIntersectRest<R>] : []);
|
|
14
14
|
declare function FromIntersectRest<T extends TSchema[]>(T: [...T]): FromIntersectRest<T>;
|
|
15
|
-
type FromIntersect<T extends TSchema[], K extends PropertyKey> = (
|
|
15
|
+
type FromIntersect<T extends TSchema[], K extends PropertyKey> = (IntersectEvaluated<FromIntersectRest<FromRest<T, K>>>);
|
|
16
16
|
declare function FromIntersect<T extends TSchema[], K extends PropertyKey>(T: [...T], K: K): FromIntersect<T, K>;
|
|
17
17
|
type FromUnionRest<T extends TSchema[], S = T> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? [] : FromUnionRest<R, S> : S);
|
|
18
18
|
declare function FromUnionRest<T extends TSchema[]>(T: [...T], S?: [...T]): FromUnionRest<T>;
|
|
19
|
-
type FromUnion<T extends TSchema[], K extends PropertyKey> = (
|
|
19
|
+
type FromUnion<T extends TSchema[], K extends PropertyKey> = (UnionEvaluated<FromUnionRest<FromRest<T, K>>>);
|
|
20
20
|
declare function FromUnion<T extends TSchema[], K extends PropertyKey>(T: [...T], K: K): FromUnion<T, K>;
|
|
21
|
-
type FromTuple<T extends TSchema[], K extends PropertyKey> = (K extends keyof T ? T[K] : K extends '[number]' ?
|
|
21
|
+
type FromTuple<T extends TSchema[], K extends PropertyKey> = (K extends keyof T ? T[K] : K extends '[number]' ? UnionEvaluated<T> : TNever);
|
|
22
22
|
declare function FromTuple<T extends TSchema[], K extends PropertyKey>(T: [...T], K: K): FromTuple<T, K>;
|
|
23
23
|
type FromArray<T extends TSchema, K extends PropertyKey> = (K extends '[number]' ? T : TNever);
|
|
24
24
|
declare function FromArray<T extends TSchema, K extends PropertyKey>(T: T, K: K): FromArray<T, K>;
|
|
@@ -28,6 +28,6 @@ type FromKey<T extends TSchema, K extends PropertyKey> = (T extends TRecursive<i
|
|
|
28
28
|
declare function FromKey<T extends TSchema, K extends PropertyKey>(T: T, K: K): FromKey<T, K>;
|
|
29
29
|
type FromKeys<T extends TSchema, K extends PropertyKey[]> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? [FromKey<T, L>, ...FromKeys<T, R>] : []);
|
|
30
30
|
declare function FromKeys<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): FromKeys<T, K>;
|
|
31
|
-
export type TIndexResult<T extends TSchema, K extends PropertyKey[]> = (
|
|
31
|
+
export type TIndexResult<T extends TSchema, K extends PropertyKey[]> = (UnionEvaluated<FromKeys<T, K>>);
|
|
32
32
|
export declare function IndexResult<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K], options: SchemaOptions): TIndexResult<T, K>;
|
|
33
33
|
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Never } from '../never/index.mjs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { IntersectEvaluated } from '../intersect/index.mjs';
|
|
3
|
+
import { UnionEvaluated } from '../union/index.mjs';
|
|
4
4
|
import { CloneType } from '../clone/type.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import { TArray as IsArrayType, TIntersect as IsIntersectType, TObject as IsObjectType, TNever as IsNeverType, TTuple as IsTupleType, TUnion as IsUnionType } from '../guard/type.mjs';
|
|
6
6
|
function FromRest(T, K) {
|
|
7
7
|
const [L, ...R] = T;
|
|
8
8
|
return (T.length > 0
|
|
@@ -18,7 +18,7 @@ function FromIntersectRest(T) {
|
|
|
18
18
|
: []);
|
|
19
19
|
}
|
|
20
20
|
function FromIntersect(T, K) {
|
|
21
|
-
return (
|
|
21
|
+
return (IntersectEvaluated(FromIntersectRest(FromRest(T, K))));
|
|
22
22
|
}
|
|
23
23
|
function FromUnionRest(T, S = T) {
|
|
24
24
|
const [L, ...R] = T;
|
|
@@ -29,11 +29,11 @@ function FromUnionRest(T, S = T) {
|
|
|
29
29
|
: S);
|
|
30
30
|
}
|
|
31
31
|
function FromUnion(T, K) {
|
|
32
|
-
return (
|
|
32
|
+
return (UnionEvaluated(FromUnionRest(FromRest(T, K))));
|
|
33
33
|
}
|
|
34
34
|
function FromTuple(T, K) {
|
|
35
35
|
return (K in T ? T[K] :
|
|
36
|
-
K === '[number]' ?
|
|
36
|
+
K === '[number]' ? UnionEvaluated(T) :
|
|
37
37
|
Never());
|
|
38
38
|
}
|
|
39
39
|
function FromArray(T, K) {
|
|
@@ -61,5 +61,5 @@ function FromKeys(T, K) {
|
|
|
61
61
|
: []);
|
|
62
62
|
}
|
|
63
63
|
export function IndexResult(T, K, options) {
|
|
64
|
-
return (CloneType(
|
|
64
|
+
return (CloneType(UnionEvaluated(FromKeys(T, K)), options));
|
|
65
65
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { TSchema as IsSchemaType, TMappedKey as IsMappedKey } from '../guard/type.mjs';
|
|
2
1
|
import { IndexResult } from './indexed-result.mjs';
|
|
3
2
|
import { IndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
4
3
|
import { IndexFromMappedKey } from './indexed-from-mapped-key.mjs';
|
|
5
4
|
import { CloneType } from '../clone/type.mjs';
|
|
5
|
+
import { TMappedKey as IsMappedKey, TSchema as IsSchemaType } from '../guard/type.mjs';
|
|
6
6
|
export function Index(T, K, options = {}) {
|
|
7
7
|
return (IsMappedKey(K) ? CloneType(IndexFromMappedKey(T, K, options)) :
|
|
8
8
|
IsSchemaType(K) ? IndexResult(T, IndexPropertyKeys(K), options) :
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Kind } from '../symbols/index.mjs';
|
|
2
|
+
import { CloneType, CloneRest } from '../clone/type.mjs';
|
|
3
|
+
import { TObject as IsObjectType, TSchema as IsSchemaType } from '../guard/type.mjs';
|
|
4
|
+
export function IntersectCreate(T, options) {
|
|
5
|
+
const allObjects = T.every((schema) => IsObjectType(schema));
|
|
6
|
+
const clonedUnevaluatedProperties = IsSchemaType(options.unevaluatedProperties)
|
|
7
|
+
? { unevaluatedProperties: CloneType(options.unevaluatedProperties) }
|
|
8
|
+
: {};
|
|
9
|
+
return ((options.unevaluatedProperties === false || IsSchemaType(options.unevaluatedProperties) || allObjects
|
|
10
|
+
? { ...options, ...clonedUnevaluatedProperties, [Kind]: 'Intersect', type: 'object', allOf: CloneRest(T) }
|
|
11
|
+
: { ...options, ...clonedUnevaluatedProperties, [Kind]: 'Intersect', allOf: CloneRest(T) }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SchemaOptions, TSchema } from '../schema/index.mjs';
|
|
2
|
+
import { type TNever } from '../never/index.mjs';
|
|
3
|
+
import { type TOptional } from '../optional/index.mjs';
|
|
4
|
+
import type { TReadonly } from '../readonly/index.mjs';
|
|
5
|
+
import { TIntersect, IntersectOptions } from './intersect-type.mjs';
|
|
6
|
+
type IsIntersectOptional<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TOptional<TSchema> ? IsIntersectOptional<R> : false : true);
|
|
7
|
+
declare function IsIntersectOptional<T extends TSchema[]>(T: T): IsIntersectOptional<T>;
|
|
8
|
+
type RemoveOptionalFromRest<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TOptional<infer S extends TSchema> ? [RemoveOptionalFromType<S>, ...RemoveOptionalFromRest<R>] : [L, ...RemoveOptionalFromRest<R>] : []);
|
|
9
|
+
declare function RemoveOptionalFromRest<T extends TSchema[]>(T: T): RemoveOptionalFromRest<T>;
|
|
10
|
+
type RemoveOptionalFromType<T extends TSchema> = (T extends TReadonly<infer S extends TSchema> ? TReadonly<RemoveOptionalFromType<S>> : T extends TOptional<infer S extends TSchema> ? RemoveOptionalFromType<S> : T);
|
|
11
|
+
declare function RemoveOptionalFromType<T extends TSchema>(T: T): RemoveOptionalFromType<T>;
|
|
12
|
+
type ResolveIntersect<T extends TSchema[]> = (IsIntersectOptional<T> extends true ? TOptional<TIntersect<RemoveOptionalFromRest<T>>> : TIntersect<RemoveOptionalFromRest<T>>);
|
|
13
|
+
declare function ResolveIntersect<T extends TSchema[]>(T: [...T], options: SchemaOptions): ResolveIntersect<T>;
|
|
14
|
+
export type IntersectEvaluated<T extends TSchema[]> = (T extends [] ? TNever : T extends [TSchema] ? T[0] : ResolveIntersect<T>);
|
|
15
|
+
export declare function IntersectEvaluated<T extends TSchema[], R = IntersectEvaluated<T>>(T: [...T], options?: IntersectOptions): R;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { OptionalKind } from '../symbols/index.mjs';
|
|
2
|
+
import { CloneType } from '../clone/type.mjs';
|
|
3
|
+
import { Discard } from '../discard/index.mjs';
|
|
4
|
+
import { Never } from '../never/index.mjs';
|
|
5
|
+
import { Optional } from '../optional/index.mjs';
|
|
6
|
+
import { IntersectCreate } from './intersect-create.mjs';
|
|
7
|
+
import { TOptional as IsOptionalType, TTransform as IsTransformType, } from '../guard/type.mjs';
|
|
8
|
+
function IsIntersectOptional(T) {
|
|
9
|
+
const [L, ...R] = T;
|
|
10
|
+
return (T.length > 0
|
|
11
|
+
? IsOptionalType(L)
|
|
12
|
+
? IsIntersectOptional(R)
|
|
13
|
+
: false
|
|
14
|
+
: true);
|
|
15
|
+
}
|
|
16
|
+
function RemoveOptionalFromRest(T) {
|
|
17
|
+
return (T.map(T => RemoveOptionalFromType(T)));
|
|
18
|
+
}
|
|
19
|
+
function RemoveOptionalFromType(T) {
|
|
20
|
+
return (Discard(T, [OptionalKind]));
|
|
21
|
+
}
|
|
22
|
+
function ResolveIntersect(T, options) {
|
|
23
|
+
return (IsIntersectOptional(T)
|
|
24
|
+
? Optional(IntersectCreate(RemoveOptionalFromRest(T), options))
|
|
25
|
+
: IntersectCreate(RemoveOptionalFromRest(T), options));
|
|
26
|
+
}
|
|
27
|
+
export function IntersectEvaluated(T, options = {}) {
|
|
28
|
+
if (T.length === 0)
|
|
29
|
+
return Never(options);
|
|
30
|
+
if (T.length === 1)
|
|
31
|
+
return CloneType(T[0], options);
|
|
32
|
+
if (T.some((schema) => IsTransformType(schema)))
|
|
33
|
+
throw new Error('Cannot intersect transform types');
|
|
34
|
+
return ResolveIntersect(T, options);
|
|
35
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
+
import type { Static } from '../static/index.mjs';
|
|
3
|
+
import { Kind } from '../symbols/index.mjs';
|
|
4
|
+
type IntersectStatic<T extends TSchema[], P extends unknown[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? Static<L, P> & IntersectStatic<R, P> : unknown;
|
|
5
|
+
export type TUnevaluatedProperties = undefined | TSchema | boolean;
|
|
6
|
+
export interface IntersectOptions extends SchemaOptions {
|
|
7
|
+
unevaluatedProperties?: TUnevaluatedProperties;
|
|
8
|
+
}
|
|
9
|
+
export interface TIntersect<T extends TSchema[] = TSchema[]> extends TSchema, IntersectOptions {
|
|
10
|
+
[Kind]: 'Intersect';
|
|
11
|
+
static: IntersectStatic<T, this['params']>;
|
|
12
|
+
type?: 'object';
|
|
13
|
+
allOf: [...T];
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { Kind } from '../symbols/index.mjs';
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
3
|
-
import type { Static } from '../static/index.mjs';
|
|
1
|
+
import type { TSchema } from '../schema/index.mjs';
|
|
4
2
|
import { type TNever } from '../never/index.mjs';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
export declare function IntersectResolve<T extends TSchema[]>(T: T): IntersectResolve<T>;
|
|
9
|
-
export type TUnevaluatedProperties = undefined | TSchema | boolean;
|
|
10
|
-
export interface IntersectOptions extends SchemaOptions {
|
|
11
|
-
unevaluatedProperties?: TUnevaluatedProperties;
|
|
12
|
-
}
|
|
13
|
-
export interface TIntersect<T extends TSchema[] = TSchema[]> extends TSchema, IntersectOptions {
|
|
14
|
-
[Kind]: 'Intersect';
|
|
15
|
-
static: TupleToIntersect<{
|
|
16
|
-
[K in keyof T]: Static<AssertType<T[K]>, this['params']>;
|
|
17
|
-
}>;
|
|
18
|
-
type?: 'object';
|
|
19
|
-
allOf: [...T];
|
|
20
|
-
}
|
|
21
|
-
export declare function Intersect<T extends TSchema[]>(T: [...T], options?: IntersectOptions): IntersectResolve<T>;
|
|
3
|
+
import { TIntersect, IntersectOptions } from './intersect-type.mjs';
|
|
4
|
+
export type Intersect<T extends TSchema[]> = (T extends [] ? TNever : T extends [TSchema] ? T[0] : TIntersect<T>);
|
|
5
|
+
export declare function Intersect<T extends TSchema[]>(T: [...T], options?: IntersectOptions): Intersect<T>;
|
|
@@ -1,25 +1,13 @@
|
|
|
1
|
+
import { CloneType } from '../clone/type.mjs';
|
|
1
2
|
import { Never } from '../never/index.mjs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { CloneType, CloneRest } from '../clone/type.mjs';
|
|
5
|
-
import { TTransform as IsTransformType, TObject as IsObjectType, TSchema as IsSchemaType } from '../guard/type.mjs';
|
|
6
|
-
export function IntersectResolve(T) {
|
|
7
|
-
return (T.length === 0
|
|
8
|
-
? Never()
|
|
9
|
-
: T.length === 1
|
|
10
|
-
? T[0]
|
|
11
|
-
: OptionalFromIntersect(T));
|
|
12
|
-
}
|
|
3
|
+
import { IntersectCreate } from './intersect-create.mjs';
|
|
4
|
+
import { TTransform as IsTransformType, } from '../guard/type.mjs';
|
|
13
5
|
export function Intersect(T, options = {}) {
|
|
14
6
|
if (T.length === 0)
|
|
15
|
-
return Never();
|
|
7
|
+
return Never(options);
|
|
16
8
|
if (T.length === 1)
|
|
17
9
|
return CloneType(T[0], options);
|
|
18
10
|
if (T.some((schema) => IsTransformType(schema)))
|
|
19
11
|
throw new Error('Cannot intersect transform types');
|
|
20
|
-
|
|
21
|
-
const clonedUnevaluatedProperties = IsSchemaType(options.unevaluatedProperties) ? { unevaluatedProperties: CloneType(options.unevaluatedProperties) } : {};
|
|
22
|
-
return (options.unevaluatedProperties === false || IsSchemaType(options.unevaluatedProperties) || allObjects
|
|
23
|
-
? { ...options, ...clonedUnevaluatedProperties, [Kind]: 'Intersect', type: 'object', allOf: CloneRest(T) }
|
|
24
|
-
: { ...options, ...clonedUnevaluatedProperties, [Kind]: 'Intersect', allOf: CloneRest(T) });
|
|
12
|
+
return IntersectCreate(T, options);
|
|
25
13
|
}
|
|
@@ -5,11 +5,11 @@ import { type TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
|
5
5
|
import { type TNumber } from '../number/index.mjs';
|
|
6
6
|
import { type SchemaOptions } from '../schema/index.mjs';
|
|
7
7
|
import { KeyOfPropertyKeys } from './keyof-property-keys.mjs';
|
|
8
|
-
import {
|
|
8
|
+
import { UnionEvaluated } from '../union/index.mjs';
|
|
9
9
|
import { type TKeyOfFromMappedResult } from './keyof-from-mapped-result.mjs';
|
|
10
10
|
type FromLiterals<T extends TLiteralValue[]> = (T extends [infer L extends TLiteralValue, ...infer R extends TLiteralValue[]] ? L extends '[number]' ? [TNumber, ...FromLiterals<R>] : [TLiteral<L>, ...FromLiterals<R>] : []);
|
|
11
11
|
declare function FromLiterals<T extends TLiteralValue[]>(T: [...T]): FromLiterals<T>;
|
|
12
|
-
export type TKeyOf<T extends TSchema> = (Ensure<
|
|
12
|
+
export type TKeyOf<T extends TSchema> = (Ensure<UnionEvaluated<FromLiterals<KeyOfPropertyKeys<T>>>>);
|
|
13
13
|
export declare function KeyOf<T extends TMappedResult>(T: T, options?: SchemaOptions): TKeyOfFromMappedResult<T>;
|
|
14
14
|
export declare function KeyOf<T extends TSchema>(T: T, options?: SchemaOptions): TKeyOf<T>;
|
|
15
15
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Literal } from '../literal/index.mjs';
|
|
2
2
|
import { Number } from '../number/index.mjs';
|
|
3
3
|
import { KeyOfPropertyKeys } from './keyof-property-keys.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { UnionEvaluated } from '../union/index.mjs';
|
|
5
5
|
import { CloneType } from '../clone/type.mjs';
|
|
6
6
|
import { KeyOfFromMappedResult } from './keyof-from-mapped-result.mjs';
|
|
7
7
|
import { TMappedResult as IsMappedResultType } from '../guard/type.mjs';
|
|
@@ -18,7 +18,7 @@ export function KeyOf(T, options = {}) {
|
|
|
18
18
|
return KeyOfFromMappedResult(T, options);
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
|
-
const K =
|
|
21
|
+
const K = UnionEvaluated(FromLiterals(KeyOfPropertyKeys(T)));
|
|
22
22
|
return CloneType(K, options);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { TSchema as IsSchemaType } from '../guard/type.mjs';
|
|
2
1
|
import { Kind, OptionalKind, ReadonlyKind } from '../symbols/index.mjs';
|
|
3
2
|
import { CloneType } from '../clone/type.mjs';
|
|
4
3
|
import { Discard } from '../discard/index.mjs';
|
|
@@ -17,7 +16,7 @@ import { Readonly } from '../readonly/index.mjs';
|
|
|
17
16
|
import { Tuple } from '../tuple/index.mjs';
|
|
18
17
|
import { Union } from '../union/index.mjs';
|
|
19
18
|
import { MappedResult } from './mapped-result.mjs';
|
|
20
|
-
import { TArray as IsArrayType, TAsyncIterator as IsAsyncIteratorType, TConstructor as IsConstructorType, TFunction as IsFunctionType, TIntersect as IsIntersectType, TIterator as IsIteratorType, TReadonly as IsReadonlyType, TMappedResult as IsMappedResultType, TMappedKey as IsMappedKeyType, TObject as IsObjectType, TOptional as IsOptionalType, TPromise as IsPromiseType, TTuple as IsTupleType, TUnion as IsUnionType, } from '../guard/type.mjs';
|
|
19
|
+
import { TArray as IsArrayType, TAsyncIterator as IsAsyncIteratorType, TConstructor as IsConstructorType, TFunction as IsFunctionType, TIntersect as IsIntersectType, TIterator as IsIteratorType, TReadonly as IsReadonlyType, TMappedResult as IsMappedResultType, TMappedKey as IsMappedKeyType, TObject as IsObjectType, TOptional as IsOptionalType, TPromise as IsPromiseType, TSchema as IsSchemaType, TTuple as IsTupleType, TUnion as IsUnionType, } from '../guard/type.mjs';
|
|
21
20
|
function FromMappedResult(K, P) {
|
|
22
21
|
return (K in P
|
|
23
22
|
? FromSchemaType(K, P[K])
|
|
@@ -4,8 +4,6 @@ import type { Evaluate } from '../helpers/index.mjs';
|
|
|
4
4
|
import type { TReadonly } from '../readonly/index.mjs';
|
|
5
5
|
import type { TOptional } from '../optional/index.mjs';
|
|
6
6
|
import { Kind } from '../symbols/index.mjs';
|
|
7
|
-
export type TPropertyKey = string | number;
|
|
8
|
-
export type TProperties = Record<TPropertyKey, TSchema>;
|
|
9
7
|
type ReadonlyOptionalPropertyKeys<T extends TProperties> = {
|
|
10
8
|
[K in keyof T]: T[K] extends TReadonly<TSchema> ? (T[K] extends TOptional<T[K]> ? K : never) : never;
|
|
11
9
|
}[keyof T];
|
|
@@ -16,10 +14,12 @@ type OptionalPropertyKeys<T extends TProperties> = {
|
|
|
16
14
|
[K in keyof T]: T[K] extends TOptional<TSchema> ? (T[K] extends TReadonly<T[K]> ? never : K) : never;
|
|
17
15
|
}[keyof T];
|
|
18
16
|
type RequiredPropertyKeys<T extends TProperties> = keyof Omit<T, ReadonlyOptionalPropertyKeys<T> | ReadonlyPropertyKeys<T> | OptionalPropertyKeys<T>>;
|
|
19
|
-
type
|
|
20
|
-
export type
|
|
17
|
+
type ObjectStaticProperties<T extends TProperties, R extends Record<keyof any, unknown>> = Evaluate<(Readonly<Partial<Pick<R, ReadonlyOptionalPropertyKeys<T>>>> & Readonly<Pick<R, ReadonlyPropertyKeys<T>>> & Partial<Pick<R, OptionalPropertyKeys<T>>> & Required<Pick<R, RequiredPropertyKeys<T>>>)>;
|
|
18
|
+
export type ObjectStatic<T extends TProperties, P extends unknown[]> = ObjectStaticProperties<T, {
|
|
21
19
|
[K in keyof T]: Static<T[K], P>;
|
|
22
20
|
}>;
|
|
21
|
+
export type TPropertyKey = string | number;
|
|
22
|
+
export type TProperties = Record<TPropertyKey, TSchema>;
|
|
23
23
|
export type TAdditionalProperties = undefined | TSchema | boolean;
|
|
24
24
|
export interface ObjectOptions extends SchemaOptions {
|
|
25
25
|
additionalProperties?: TAdditionalProperties;
|
|
@@ -28,7 +28,7 @@ export interface ObjectOptions extends SchemaOptions {
|
|
|
28
28
|
}
|
|
29
29
|
export interface TObject<T extends TProperties = TProperties> extends TSchema, ObjectOptions {
|
|
30
30
|
[Kind]: 'Object';
|
|
31
|
-
static:
|
|
31
|
+
static: ObjectStatic<T, this['params']>;
|
|
32
32
|
additionalProperties?: TAdditionalProperties;
|
|
33
33
|
type: 'object';
|
|
34
34
|
properties: T;
|
|
@@ -40,7 +40,6 @@ declare function FromIntegerKey<K extends TInteger, T extends TSchema>(_: K, T:
|
|
|
40
40
|
type FromNumberKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
|
|
41
41
|
declare function FromNumberKey<K extends TNumber, T extends TSchema>(_: K, T: T): FromIntegerKey<K, T>;
|
|
42
42
|
export type RecordResolve<K extends TSchema, T extends TSchema> = K extends TEnum<infer S> ? FromEnumKey<S, T> : K extends TUnion<infer S> ? FromUnionKey<S, T> : K extends TTemplateLiteral ? FromTemplateLiteralKey<K, T> : K extends TLiteral<infer S> ? FromLiteralKey<S, T> : K extends TInteger ? FromIntegerKey<K, T> : K extends TNumber ? FromNumberKey<K, T> : K extends TString ? FromStringKey<K, T> : TNever;
|
|
43
|
-
export declare function RecordResolve<K extends TSchema, T extends TSchema>(K: K, T: T): RecordResolve<K, T>;
|
|
44
43
|
export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchema> extends TSchema {
|
|
45
44
|
[Kind]: 'Record';
|
|
46
45
|
static: Record<Assert<Static<K>, string | number>, Static<T, this['params']>>;
|
|
@@ -37,7 +37,7 @@ function FromIntegerKey(_, T) {
|
|
|
37
37
|
function FromNumberKey(_, T) {
|
|
38
38
|
return FromPattern(PatternNumberExact, T);
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
function RecordResolve(K, T) {
|
|
41
41
|
return (IsUnionType(K) ? FromUnionKey(K.anyOf, T) :
|
|
42
42
|
IsTemplateLiteralType(K) ? FromTemplateLiteralKey(K, T) :
|
|
43
43
|
IsLiteralType(K) ? FromLiteralKey(K.const, T) :
|
|
@@ -6,9 +6,10 @@ export interface TThis extends TSchema {
|
|
|
6
6
|
static: this['params'][0];
|
|
7
7
|
$ref: string;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
type RecursiveStatic<T extends TSchema> = Static<T, [RecursiveStatic<T>]>;
|
|
10
10
|
export interface TRecursive<T extends TSchema> extends TSchema {
|
|
11
11
|
[Hint]: 'Recursive';
|
|
12
|
-
static:
|
|
12
|
+
static: RecursiveStatic<T>;
|
|
13
13
|
}
|
|
14
14
|
export declare function Recursive<T extends TSchema>(callback: (thisType: TThis) => T, options?: SchemaOptions): TRecursive<T>;
|
|
15
|
+
export {};
|
|
@@ -7,9 +7,5 @@ export function Recursive(callback, options = {}) {
|
|
|
7
7
|
options.$id = `T${Ordinal++}`;
|
|
8
8
|
const thisType = callback({ [Kind]: 'This', $ref: `${options.$id}` });
|
|
9
9
|
thisType.$id = options.$id;
|
|
10
|
-
return CloneType({
|
|
11
|
-
...options,
|
|
12
|
-
[Hint]: 'Recursive',
|
|
13
|
-
...thisType,
|
|
14
|
-
});
|
|
10
|
+
return CloneType({ ...options, [Hint]: 'Recursive', ...thisType });
|
|
15
11
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Assert, Trim } from '../helpers/index.mjs';
|
|
2
2
|
import type { TTemplateLiteralKind, TTemplateLiteral } from './index.mjs';
|
|
3
3
|
import { type TLiteral } from '../literal/index.mjs';
|
|
4
4
|
import { type TBoolean } from '../boolean/index.mjs';
|
|
5
5
|
import { type TBigInt } from '../bigint/index.mjs';
|
|
6
6
|
import { type TNumber } from '../number/index.mjs';
|
|
7
7
|
import { type TString } from '../string/index.mjs';
|
|
8
|
-
import {
|
|
8
|
+
import { UnionEvaluated } from '../union/index.mjs';
|
|
9
9
|
declare function FromUnion(syntax: string): IterableIterator<TTemplateLiteralKind>;
|
|
10
10
|
declare function FromTerminal(syntax: string): IterableIterator<TTemplateLiteralKind>;
|
|
11
11
|
type FromUnionLiteral<T extends string> = T extends `${infer L}|${infer R}` ? [TLiteral<Trim<L>>, ...FromUnionLiteral<R>] : T extends `${infer L}` ? [TLiteral<Trim<L>>] : [
|
|
12
12
|
];
|
|
13
|
-
type FromUnion<T extends string> =
|
|
13
|
+
type FromUnion<T extends string> = UnionEvaluated<FromUnionLiteral<T>>;
|
|
14
14
|
type FromTerminal<T extends string> = T extends 'boolean' ? TBoolean : T extends 'bigint' ? TBigInt : T extends 'number' ? TNumber : T extends 'string' ? TString : FromUnion<T>;
|
|
15
15
|
type FromString<T extends string> = T extends `{${infer L}}${infer R}` ? [FromTerminal<L>, ...FromString<R>] : T extends `${infer L}$${infer R}` ? [TLiteral<L>, ...FromString<R>] : T extends `${infer L}` ? [TLiteral<L>] : [
|
|
16
16
|
];
|
|
17
|
-
export type TemplateLiteralSyntax<T extends string> =
|
|
17
|
+
export type TemplateLiteralSyntax<T extends string> = (TTemplateLiteral<Assert<FromString<T>, TTemplateLiteralKind[]>>);
|
|
18
18
|
export declare function TemplateLiteralSyntax(syntax: string): TTemplateLiteralKind[];
|
|
19
19
|
export {};
|
|
@@ -12,14 +12,14 @@ import type { Static } from '../static/index.mjs';
|
|
|
12
12
|
import { TemplateLiteralSyntax } from './syntax.mjs';
|
|
13
13
|
import { EmptyString } from '../helpers/index.mjs';
|
|
14
14
|
import { Kind } from '../symbols/index.mjs';
|
|
15
|
-
type
|
|
16
|
-
[K in keyof U]:
|
|
15
|
+
type TemplateLiteralStaticKind<T, Acc extends string> = T extends TUnion<infer U> ? {
|
|
16
|
+
[K in keyof U]: TemplateLiteralStatic<Assert<[U[K]], TTemplateLiteralKind[]>, Acc>;
|
|
17
17
|
}[number] : T extends TTemplateLiteral ? `${Static<T>}` : T extends TLiteral<infer U> ? `${U}` : T extends TString ? `${string}` : T extends TNumber ? `${number}` : T extends TBigInt ? `${bigint}` : T extends TBoolean ? `${boolean}` : never;
|
|
18
|
-
|
|
18
|
+
type TemplateLiteralStatic<T extends TTemplateLiteralKind[], Acc extends string> = T extends [infer L, ...infer R] ? `${TemplateLiteralStaticKind<L, Acc>}${TemplateLiteralStatic<Assert<R, TTemplateLiteralKind[]>, Acc>}` : Acc;
|
|
19
19
|
export type TTemplateLiteralKind = TTemplateLiteral | TUnion | TLiteral | TInteger | TNumber | TBigInt | TString | TBoolean | TNever;
|
|
20
20
|
export interface TTemplateLiteral<T extends TTemplateLiteralKind[] = TTemplateLiteralKind[]> extends TSchema {
|
|
21
21
|
[Kind]: 'TemplateLiteral';
|
|
22
|
-
static:
|
|
22
|
+
static: TemplateLiteralStatic<T, EmptyString>;
|
|
23
23
|
type: 'string';
|
|
24
24
|
pattern: string;
|
|
25
25
|
}
|
|
@@ -14,15 +14,16 @@ export declare class TransformEncodeBuilder<T extends TSchema, D extends Transfo
|
|
|
14
14
|
private EncodeSchema;
|
|
15
15
|
Encode<E extends TransformFunction<ReturnType<D>, StaticDecode<T>>>(encode: E): TTransform<T, ReturnType<D>>;
|
|
16
16
|
}
|
|
17
|
+
type TransformStatic<T extends TSchema, P extends unknown[] = []> = T extends TTransform<infer _, infer S> ? S : Static<T, P>;
|
|
17
18
|
export type TransformFunction<T = any, U = any> = (value: T) => U;
|
|
18
19
|
export interface TransformOptions<I extends TSchema = TSchema, O extends unknown = unknown> {
|
|
19
20
|
Decode: TransformFunction<StaticDecode<I>, O>;
|
|
20
21
|
Encode: TransformFunction<O, StaticDecode<I>>;
|
|
21
22
|
}
|
|
22
|
-
export type TTransformResolve<T extends TSchema, P extends unknown[] = []> = T extends TTransform<infer _, infer S> ? S : Static<T, P>;
|
|
23
23
|
export interface TTransform<I extends TSchema = TSchema, O extends unknown = unknown> extends TSchema {
|
|
24
|
-
static:
|
|
24
|
+
static: TransformStatic<I, this['params']>;
|
|
25
25
|
[TransformKind]: TransformOptions<I, O>;
|
|
26
26
|
[key: string]: any;
|
|
27
27
|
}
|
|
28
28
|
export declare function Transform<I extends TSchema>(schema: I): TransformDecodeBuilder<I>;
|
|
29
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TTransform as IsTransform } from '../guard/type.mjs';
|
|
2
1
|
import { CloneType } from '../clone/type.mjs';
|
|
3
2
|
import { TransformKind } from '../symbols/index.mjs';
|
|
3
|
+
import { TTransform as IsTransform } from '../guard/type.mjs';
|
|
4
4
|
export class TransformDecodeBuilder {
|
|
5
5
|
schema;
|
|
6
6
|
constructor(schema) {
|