@sinclair/typebox 0.32.0-dev-26 → 0.32.0-dev-28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/import/compiler/compiler.mjs +7 -0
- package/build/import/errors/errors.d.mts +16 -15
- package/build/import/errors/errors.mjs +24 -15
- package/build/import/errors/function.mjs +2 -0
- package/build/import/index.d.mts +2 -2
- package/build/import/type/awaited/awaited.mjs +2 -6
- package/build/import/type/clone/value.mjs +6 -2
- package/build/import/type/composite/composite.d.mts +1 -2
- package/build/import/type/composite/composite.mjs +2 -2
- package/build/import/type/const/const.mjs +6 -6
- package/build/import/type/constructor/constructor.d.mts +1 -1
- package/build/import/type/constructor/constructor.mjs +1 -1
- package/build/import/type/deref/deref.mjs +1 -2
- package/build/import/type/discard/discard.mjs +2 -2
- package/build/import/type/enum/enum.mjs +3 -0
- package/build/import/type/exclude/exclude-from-mapped-result.d.mts +5 -5
- package/build/import/type/exclude/exclude-from-mapped-result.mjs +7 -7
- package/build/import/type/exclude/exclude.mjs +0 -1
- package/build/import/type/extends/extends-check.mjs +137 -125
- package/build/import/type/extends/extends-from-mapped-key.d.mts +1 -1
- package/build/import/type/extends/extends-from-mapped-key.mjs +4 -5
- package/build/import/type/extends/extends-from-mapped-result.d.mts +5 -5
- package/build/import/type/extends/extends-from-mapped-result.mjs +7 -7
- package/build/import/type/extends/extends.mjs +0 -1
- package/build/import/type/extract/extract-from-mapped-result.d.mts +5 -5
- package/build/import/type/extract/extract-from-mapped-result.mjs +7 -7
- package/build/import/type/extract/extract.d.mts +1 -2
- package/build/import/type/extract/extract.mjs +4 -2
- package/build/import/type/guard/type.d.mts +3 -0
- package/build/import/type/guard/type.mjs +10 -0
- package/build/import/type/guard/value.d.mts +2 -0
- package/build/import/type/guard/value.mjs +4 -0
- package/build/import/type/index.d.mts +1 -1
- package/build/import/type/index.mjs +1 -1
- package/build/import/type/indexed/indexed-from-mapped-key.d.mts +2 -2
- package/build/import/type/indexed/indexed-from-mapped-key.mjs +4 -5
- package/build/import/type/indexed/indexed-from-mapped-result.d.mts +1 -1
- package/build/import/type/indexed/indexed-property-keys.d.mts +6 -6
- package/build/import/type/indexed/indexed-property-keys.mjs +3 -5
- package/build/import/type/indexed/indexed.d.mts +1 -1
- package/build/import/type/indexed/indexed.mjs +9 -27
- package/build/import/type/intersect/intersect-evaluated.mjs +3 -13
- package/build/import/type/intrinsic/capitalize.d.mts +2 -2
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.d.mts +1 -1
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.mjs +4 -5
- package/build/import/type/intrinsic/intrinsic.d.mts +2 -3
- package/build/import/type/intrinsic/intrinsic.mjs +2 -5
- package/build/import/type/intrinsic/lowercase.d.mts +2 -2
- package/build/import/type/intrinsic/uncapitalize.d.mts +2 -2
- package/build/import/type/intrinsic/uppercase.d.mts +2 -2
- package/build/import/type/iterator/iterator.mjs +1 -1
- package/build/import/type/keyof/keyof-from-mapped-result.d.mts +3 -3
- package/build/import/type/keyof/keyof-from-mapped-result.mjs +4 -4
- package/build/import/type/keyof/keyof-property-keys.d.mts +3 -3
- package/build/import/type/keyof/keyof-property-keys.mjs +9 -15
- package/build/import/type/keyof/keyof.mjs +2 -8
- package/build/import/type/mapped/mapped.d.mts +6 -1
- package/build/import/type/mapped/mapped.mjs +21 -14
- package/build/import/type/not/not.mjs +1 -1
- package/build/import/type/object/object.d.mts +1 -1
- package/build/import/type/object/object.mjs +0 -1
- package/build/import/type/omit/index.d.mts +1 -0
- package/build/import/type/omit/index.mjs +1 -0
- package/build/import/type/omit/omit-from-mapped-key.mjs +4 -5
- package/build/import/type/omit/omit-from-mapped-result.d.mts +11 -0
- package/build/import/type/omit/omit-from-mapped-result.mjs +17 -0
- package/build/import/type/omit/omit.d.mts +6 -3
- package/build/import/type/omit/omit.mjs +11 -9
- package/build/import/type/optional/optional-from-mapped-result.d.mts +5 -5
- package/build/import/type/optional/optional-from-mapped-result.mjs +7 -7
- package/build/import/type/partial/partial-from-mapped-result.d.mts +5 -5
- package/build/import/type/partial/partial-from-mapped-result.mjs +4 -4
- package/build/import/type/partial/partial.d.mts +2 -3
- package/build/import/type/partial/partial.mjs +8 -21
- package/build/import/type/pick/index.d.mts +1 -0
- package/build/import/type/pick/index.mjs +1 -0
- package/build/import/type/pick/pick-from-mapped-key.mjs +4 -5
- package/build/import/type/pick/pick-from-mapped-result.d.mts +11 -0
- package/build/import/type/pick/pick-from-mapped-result.mjs +17 -0
- package/build/import/type/pick/pick.d.mts +5 -2
- package/build/import/type/pick/pick.mjs +11 -10
- package/build/import/type/promise/promise.mjs +1 -1
- package/build/import/type/readonly/readonly-from-mapped-result.d.mts +5 -5
- package/build/import/type/readonly/readonly-from-mapped-result.mjs +4 -4
- package/build/import/type/record/record.d.mts +5 -3
- package/build/import/type/record/record.mjs +13 -5
- package/build/import/type/ref/ref.mjs +1 -1
- package/build/import/type/regexp/regexp.d.mts +11 -4
- package/build/import/type/regexp/regexp.mjs +3 -3
- package/build/import/type/required/required-from-mapped-result.d.mts +5 -5
- package/build/import/type/required/required-from-mapped-result.mjs +7 -7
- package/build/import/type/required/required.d.mts +2 -3
- package/build/import/type/required/required.mjs +4 -14
- package/build/import/type/rest/rest.d.mts +2 -2
- package/build/import/type/rest/rest.mjs +1 -2
- package/build/import/type/schema/anyschema.d.mts +2 -1
- package/build/import/type/sets/index.d.mts +1 -0
- package/build/import/type/sets/index.mjs +1 -0
- package/build/import/type/sets/set.d.mts +24 -0
- package/build/import/type/sets/set.mjs +35 -0
- package/build/import/type/strict/strict.d.mts +1 -1
- package/build/import/type/strict/strict.mjs +1 -1
- package/build/import/type/template-literal/syntax.d.mts +1 -1
- package/build/import/type/template-literal/template-literal.d.mts +1 -1
- package/build/import/type/transform/transform.mjs +1 -1
- package/build/import/type/type/javascript.d.mts +2 -2
- package/build/import/type/type/javascript.mjs +1 -1
- package/build/import/type/type/json.d.mts +6 -2
- package/build/import/type/union/union-evaluated.mjs +3 -14
- package/build/import/value/cast/cast.d.mts +2 -15
- package/build/import/value/cast/cast.mjs +5 -28
- package/build/import/value/check/check.mjs +6 -1
- package/build/import/value/convert/convert.d.mts +0 -5
- package/build/import/value/convert/convert.mjs +0 -12
- package/build/import/value/create/create.d.mts +2 -23
- package/build/import/value/create/create.mjs +30 -53
- package/build/import/value/default/default.mjs +0 -2
- package/build/import/value/delta/delta.d.mts +4 -4
- package/build/import/value/delta/delta.mjs +12 -12
- package/build/import/value/index.d.mts +7 -7
- package/build/import/value/index.mjs +6 -6
- package/build/import/value/mutate/mutate.d.mts +2 -5
- package/build/import/value/mutate/mutate.mjs +5 -10
- package/build/require/compiler/compiler.js +7 -0
- package/build/require/errors/errors.d.ts +16 -15
- package/build/require/errors/errors.js +24 -15
- package/build/require/errors/function.js +2 -0
- package/build/require/index.d.ts +2 -2
- package/build/require/type/awaited/awaited.js +2 -6
- package/build/require/type/clone/value.js +6 -2
- package/build/require/type/composite/composite.d.ts +1 -2
- package/build/require/type/composite/composite.js +5 -6
- package/build/require/type/const/const.js +6 -6
- package/build/require/type/constructor/constructor.d.ts +1 -1
- package/build/require/type/constructor/constructor.js +1 -1
- package/build/require/type/deref/deref.js +0 -1
- package/build/require/type/discard/discard.js +2 -2
- package/build/require/type/enum/enum.js +3 -0
- package/build/require/type/exclude/exclude-from-mapped-result.d.ts +5 -5
- package/build/require/type/exclude/exclude-from-mapped-result.js +7 -7
- package/build/require/type/exclude/exclude.js +0 -1
- package/build/require/type/extends/extends-check.js +137 -125
- package/build/require/type/extends/extends-from-mapped-key.d.ts +1 -1
- package/build/require/type/extends/extends-from-mapped-key.js +4 -5
- package/build/require/type/extends/extends-from-mapped-result.d.ts +5 -5
- package/build/require/type/extends/extends-from-mapped-result.js +7 -7
- package/build/require/type/extends/extends.js +0 -1
- package/build/require/type/extract/extract-from-mapped-result.d.ts +5 -5
- package/build/require/type/extract/extract-from-mapped-result.js +7 -7
- package/build/require/type/extract/extract.d.ts +1 -2
- package/build/require/type/extract/extract.js +4 -3
- package/build/require/type/guard/type.d.ts +3 -0
- package/build/require/type/guard/type.js +12 -1
- package/build/require/type/guard/value.d.ts +2 -0
- package/build/require/type/guard/value.js +6 -1
- package/build/require/type/index.d.ts +1 -1
- package/build/require/type/index.js +1 -1
- package/build/require/type/indexed/indexed-from-mapped-key.d.ts +2 -2
- package/build/require/type/indexed/indexed-from-mapped-key.js +4 -5
- package/build/require/type/indexed/indexed-from-mapped-result.d.ts +1 -1
- package/build/require/type/indexed/indexed-property-keys.d.ts +6 -6
- package/build/require/type/indexed/indexed-property-keys.js +3 -5
- package/build/require/type/indexed/indexed.d.ts +1 -1
- package/build/require/type/indexed/indexed.js +9 -27
- package/build/require/type/intersect/intersect-evaluated.js +3 -13
- package/build/require/type/intrinsic/capitalize.d.ts +2 -2
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.d.ts +1 -1
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.js +4 -5
- package/build/require/type/intrinsic/intrinsic.d.ts +2 -3
- package/build/require/type/intrinsic/intrinsic.js +2 -5
- package/build/require/type/intrinsic/lowercase.d.ts +2 -2
- package/build/require/type/intrinsic/uncapitalize.d.ts +2 -2
- package/build/require/type/intrinsic/uppercase.d.ts +2 -2
- package/build/require/type/iterator/iterator.js +1 -1
- package/build/require/type/keyof/keyof-from-mapped-result.d.ts +3 -3
- package/build/require/type/keyof/keyof-from-mapped-result.js +4 -4
- package/build/require/type/keyof/keyof-property-keys.d.ts +3 -3
- package/build/require/type/keyof/keyof-property-keys.js +9 -15
- package/build/require/type/keyof/keyof.js +2 -8
- package/build/require/type/mapped/mapped.d.ts +6 -1
- package/build/require/type/mapped/mapped.js +21 -14
- package/build/require/type/not/not.js +1 -1
- package/build/require/type/object/object.d.ts +1 -1
- package/build/require/type/object/object.js +0 -1
- package/build/require/type/omit/index.d.ts +1 -0
- package/build/require/type/omit/index.js +1 -0
- package/build/require/type/omit/omit-from-mapped-key.js +4 -5
- package/build/require/type/omit/omit-from-mapped-result.d.ts +11 -0
- package/build/require/type/omit/omit-from-mapped-result.js +22 -0
- package/build/require/type/omit/omit.d.ts +6 -3
- package/build/require/type/omit/omit.js +10 -8
- package/build/require/type/optional/optional-from-mapped-result.d.ts +5 -5
- package/build/require/type/optional/optional-from-mapped-result.js +7 -7
- package/build/require/type/partial/partial-from-mapped-result.d.ts +5 -5
- package/build/require/type/partial/partial-from-mapped-result.js +4 -4
- package/build/require/type/partial/partial.d.ts +2 -3
- package/build/require/type/partial/partial.js +8 -21
- package/build/require/type/pick/index.d.ts +1 -0
- package/build/require/type/pick/index.js +1 -0
- package/build/require/type/pick/pick-from-mapped-key.js +4 -5
- package/build/require/type/pick/pick-from-mapped-result.d.ts +11 -0
- package/build/require/type/pick/pick-from-mapped-result.js +22 -0
- package/build/require/type/pick/pick.d.ts +5 -2
- package/build/require/type/pick/pick.js +10 -9
- package/build/require/type/promise/promise.js +1 -1
- package/build/require/type/readonly/readonly-from-mapped-result.d.ts +5 -5
- package/build/require/type/readonly/readonly-from-mapped-result.js +4 -4
- package/build/require/type/record/record.d.ts +5 -3
- package/build/require/type/record/record.js +12 -4
- package/build/require/type/ref/ref.js +1 -1
- package/build/require/type/regexp/regexp.d.ts +11 -4
- package/build/require/type/regexp/regexp.js +3 -3
- package/build/require/type/required/required-from-mapped-result.d.ts +5 -5
- package/build/require/type/required/required-from-mapped-result.js +7 -7
- package/build/require/type/required/required.d.ts +2 -3
- package/build/require/type/required/required.js +4 -14
- package/build/require/type/rest/rest.d.ts +2 -2
- package/build/require/type/rest/rest.js +1 -3
- package/build/require/type/schema/anyschema.d.ts +2 -1
- package/build/require/type/sets/index.d.ts +1 -0
- package/build/require/type/{operators → sets}/index.js +1 -1
- package/build/require/type/sets/set.d.ts +24 -0
- package/build/require/type/sets/set.js +47 -0
- package/build/require/type/strict/strict.d.ts +1 -1
- package/build/require/type/strict/strict.js +1 -1
- package/build/require/type/template-literal/parse.js +1 -1
- package/build/require/type/template-literal/syntax.d.ts +1 -1
- package/build/require/type/template-literal/template-literal.d.ts +1 -1
- package/build/require/type/transform/transform.js +1 -1
- package/build/require/type/type/javascript.d.ts +2 -2
- package/build/require/type/type/javascript.js +1 -1
- package/build/require/type/type/json.d.ts +6 -2
- package/build/require/type/union/union-evaluated.js +3 -14
- package/build/require/value/cast/cast.d.ts +2 -15
- package/build/require/value/cast/cast.js +7 -29
- package/build/require/value/check/check.js +6 -1
- package/build/require/value/convert/convert.d.ts +0 -5
- package/build/require/value/convert/convert.js +31 -43
- package/build/require/value/create/create.d.ts +2 -23
- package/build/require/value/create/create.js +32 -54
- package/build/require/value/default/default.js +0 -2
- package/build/require/value/delta/delta.d.ts +4 -4
- package/build/require/value/delta/delta.js +14 -14
- package/build/require/value/index.d.ts +7 -7
- package/build/require/value/index.js +8 -19
- package/build/require/value/mutate/mutate.d.ts +2 -5
- package/build/require/value/mutate/mutate.js +7 -13
- package/package.json +1 -1
- package/readme.md +68 -67
- package/build/import/type/operators/index.d.mts +0 -1
- package/build/import/type/operators/index.mjs +0 -1
- package/build/import/type/operators/operators.d.mts +0 -24
- package/build/import/type/operators/operators.mjs +0 -77
- package/build/require/type/operators/index.d.ts +0 -1
- package/build/require/type/operators/operators.d.ts +0 -24
- package/build/require/type/operators/operators.js +0 -89
|
@@ -2,10 +2,10 @@ import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
|
2
2
|
import type { TProperties } from '../object/index.mjs';
|
|
3
3
|
import { type TMappedResult } from '../mapped/index.mjs';
|
|
4
4
|
import { type TExtract } from './extract.mjs';
|
|
5
|
-
type TFromProperties<
|
|
6
|
-
[K2 in keyof
|
|
5
|
+
type TFromProperties<P extends TProperties, T extends TSchema> = ({
|
|
6
|
+
[K2 in keyof P]: TExtract<P[K2], T>;
|
|
7
7
|
});
|
|
8
|
-
type TFromMappedResult<
|
|
9
|
-
export type TExtractFromMappedResult<
|
|
10
|
-
export declare function ExtractFromMappedResult<
|
|
8
|
+
type TFromMappedResult<R extends TMappedResult, T extends TSchema> = (TFromProperties<R['properties'], T>);
|
|
9
|
+
export type TExtractFromMappedResult<R extends TMappedResult, T extends TSchema, P extends TProperties = TFromMappedResult<R, T>> = (TMappedResult<P>);
|
|
10
|
+
export declare function ExtractFromMappedResult<R extends TMappedResult, T extends TSchema, P extends TProperties = TFromMappedResult<R, T>>(R: R, T: T, options: SchemaOptions): TMappedResult<P>;
|
|
11
11
|
export {};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { MappedResult } from '../mapped/index.mjs';
|
|
2
2
|
import { Extract } from './extract.mjs';
|
|
3
3
|
// prettier-ignore
|
|
4
|
-
function FromProperties(
|
|
5
|
-
return globalThis.Object.getOwnPropertyNames(
|
|
6
|
-
return { ...Acc, [K2]: Extract(
|
|
4
|
+
function FromProperties(P, T, options) {
|
|
5
|
+
return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
|
|
6
|
+
return { ...Acc, [K2]: Extract(P[K2], T, options) };
|
|
7
7
|
}, {});
|
|
8
8
|
}
|
|
9
9
|
// prettier-ignore
|
|
10
|
-
function FromMappedResult(
|
|
11
|
-
return FromProperties(
|
|
10
|
+
function FromMappedResult(R, T, options) {
|
|
11
|
+
return FromProperties(R.properties, T, options);
|
|
12
12
|
}
|
|
13
13
|
// prettier-ignore
|
|
14
|
-
export function ExtractFromMappedResult(
|
|
15
|
-
const P = FromMappedResult(
|
|
14
|
+
export function ExtractFromMappedResult(R, T, options) {
|
|
15
|
+
const P = FromMappedResult(R, T, options);
|
|
16
16
|
return MappedResult(P);
|
|
17
17
|
}
|
|
@@ -14,8 +14,7 @@ type TFromTemplateLiteral<T extends TTemplateLiteral, U extends TSchema> = Extra
|
|
|
14
14
|
type TFromArray<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
16
|
}[number]>> extends infer R extends TSchema[] ? TUnionEvaluated<R> : never;
|
|
17
|
-
|
|
18
|
-
export declare function ExtractResolve<L extends TSchema, R extends TSchema>(L: L, R: R): TExtractResolve<L, R>;
|
|
17
|
+
type TExtractResolve<T extends TSchema, U extends TSchema> = (T extends TTemplateLiteral ? TFromTemplateLiteral<T, U> : T extends TUnion<infer S> ? TFromArray<S, U> : T);
|
|
19
18
|
export type TExtract<T extends TSchema, U extends TSchema> = TExtractResolve<T, U>;
|
|
20
19
|
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
21
20
|
export declare function Extract<L extends TMappedResult, R extends TSchema>(type: L, union: R, options?: SchemaOptions): TExtractFromMappedResult<L, R>;
|
|
@@ -4,10 +4,12 @@ import { Never } from '../never/index.mjs';
|
|
|
4
4
|
import { ExtendsCheck, ExtendsResult } from '../extends/index.mjs';
|
|
5
5
|
import { CloneType } from '../clone/type.mjs';
|
|
6
6
|
import { ExtractFromMappedResult } from './extract-from-mapped-result.mjs';
|
|
7
|
-
//
|
|
7
|
+
// ------------------------------------------------------------------
|
|
8
|
+
// TypeGuard
|
|
9
|
+
// ------------------------------------------------------------------
|
|
8
10
|
import { IsMappedResult, IsTemplateLiteral, IsUnion } from '../guard/type.mjs';
|
|
9
11
|
// prettier-ignore
|
|
10
|
-
|
|
12
|
+
function ExtractResolve(L, R) {
|
|
11
13
|
return (IsTemplateLiteral(L) ? ExtractResolve(TemplateLiteralToUnion(L), R) :
|
|
12
14
|
IsTemplateLiteral(R) ? ExtractResolve(L, TemplateLiteralToUnion(R)) :
|
|
13
15
|
IsUnion(L) ? (() => {
|
|
@@ -26,6 +26,7 @@ import type { TOptional } from '../optional/index.mjs';
|
|
|
26
26
|
import type { TPromise } from '../promise/index.mjs';
|
|
27
27
|
import type { TReadonly } from '../readonly/index.mjs';
|
|
28
28
|
import type { TRef } from '../ref/index.mjs';
|
|
29
|
+
import type { TRegExp } from '../regexp/index.mjs';
|
|
29
30
|
import type { TSchema } from '../schema/index.mjs';
|
|
30
31
|
import type { TSymbol } from '../symbol/index.mjs';
|
|
31
32
|
import type { TTuple } from '../tuple/index.mjs';
|
|
@@ -104,6 +105,8 @@ export declare function IsRecursive(value: unknown): value is {
|
|
|
104
105
|
};
|
|
105
106
|
/** Returns true if the given value is TRef */
|
|
106
107
|
export declare function IsRef(value: unknown): value is TRef;
|
|
108
|
+
/** Returns true if the given value is TRegExp */
|
|
109
|
+
export declare function IsRegExp(value: unknown): value is TRegExp;
|
|
107
110
|
/** Returns true if the given value is TString */
|
|
108
111
|
export declare function IsString(value: unknown): value is TString;
|
|
109
112
|
/** Returns true if the given value is TSymbol */
|
|
@@ -26,6 +26,7 @@ const KnownTypes = [
|
|
|
26
26
|
'Promise',
|
|
27
27
|
'Record',
|
|
28
28
|
'Ref',
|
|
29
|
+
'RegExp',
|
|
29
30
|
'String',
|
|
30
31
|
'Symbol',
|
|
31
32
|
'TemplateLiteral',
|
|
@@ -324,6 +325,14 @@ export function IsRef(value) {
|
|
|
324
325
|
IsOptionalString(value.$id) &&
|
|
325
326
|
ValueGuard.IsString(value.$ref));
|
|
326
327
|
}
|
|
328
|
+
/** Returns true if the given value is TRegExp */
|
|
329
|
+
export function IsRegExp(value) {
|
|
330
|
+
// prettier-ignore
|
|
331
|
+
return (IsKindOf(value, 'RegExp') &&
|
|
332
|
+
IsOptionalString(value.$id) &&
|
|
333
|
+
ValueGuard.IsString(value.source) &&
|
|
334
|
+
ValueGuard.IsString(value.flags));
|
|
335
|
+
}
|
|
327
336
|
/** Returns true if the given value is TString */
|
|
328
337
|
export function IsString(value) {
|
|
329
338
|
// prettier-ignore
|
|
@@ -452,6 +461,7 @@ export function IsSchema(value) {
|
|
|
452
461
|
IsPromise(value) ||
|
|
453
462
|
IsRecord(value) ||
|
|
454
463
|
IsRef(value) ||
|
|
464
|
+
IsRegExp(value) ||
|
|
455
465
|
IsString(value) ||
|
|
456
466
|
IsSymbol(value) ||
|
|
457
467
|
IsTemplateLiteral(value) ||
|
|
@@ -18,6 +18,8 @@ export declare function IsNull(value: unknown): value is null;
|
|
|
18
18
|
export declare function IsNumber(value: unknown): value is number;
|
|
19
19
|
/** Returns true if this value is an object */
|
|
20
20
|
export declare function IsObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
21
|
+
/** Returns true if this value is RegExp */
|
|
22
|
+
export declare function IsRegExp(value: unknown): value is RegExp;
|
|
21
23
|
/** Returns true if this value is string */
|
|
22
24
|
export declare function IsString(value: unknown): value is string;
|
|
23
25
|
/** Returns true if this value is symbol */
|
|
@@ -38,6 +38,10 @@ export function IsNumber(value) {
|
|
|
38
38
|
export function IsObject(value) {
|
|
39
39
|
return typeof value === 'object' && value !== null;
|
|
40
40
|
}
|
|
41
|
+
/** Returns true if this value is RegExp */
|
|
42
|
+
export function IsRegExp(value) {
|
|
43
|
+
return value instanceof globalThis.RegExp;
|
|
44
|
+
}
|
|
41
45
|
/** Returns true if this value is string */
|
|
42
46
|
export function IsString(value) {
|
|
43
47
|
return typeof value === 'string';
|
|
@@ -35,7 +35,6 @@ export * from './null/index.mjs';
|
|
|
35
35
|
export * from './number/index.mjs';
|
|
36
36
|
export * from './object/index.mjs';
|
|
37
37
|
export * from './omit/index.mjs';
|
|
38
|
-
export * from './operators/index.mjs';
|
|
39
38
|
export * from './optional/index.mjs';
|
|
40
39
|
export * from './parameters/index.mjs';
|
|
41
40
|
export * from './partial/index.mjs';
|
|
@@ -53,6 +52,7 @@ export * from './required/index.mjs';
|
|
|
53
52
|
export * from './rest/index.mjs';
|
|
54
53
|
export * from './return-type/index.mjs';
|
|
55
54
|
export * from './schema/index.mjs';
|
|
55
|
+
export * from './sets/index.mjs';
|
|
56
56
|
export * from './static/index.mjs';
|
|
57
57
|
export * from './strict/index.mjs';
|
|
58
58
|
export * from './string/index.mjs';
|
|
@@ -35,7 +35,6 @@ export * from './null/index.mjs';
|
|
|
35
35
|
export * from './number/index.mjs';
|
|
36
36
|
export * from './object/index.mjs';
|
|
37
37
|
export * from './omit/index.mjs';
|
|
38
|
-
export * from './operators/index.mjs';
|
|
39
38
|
export * from './optional/index.mjs';
|
|
40
39
|
export * from './parameters/index.mjs';
|
|
41
40
|
export * from './partial/index.mjs';
|
|
@@ -53,6 +52,7 @@ export * from './required/index.mjs';
|
|
|
53
52
|
export * from './rest/index.mjs';
|
|
54
53
|
export * from './return-type/index.mjs';
|
|
55
54
|
export * from './schema/index.mjs';
|
|
55
|
+
export * from './sets/index.mjs';
|
|
56
56
|
export * from './static/index.mjs';
|
|
57
57
|
export * from './strict/index.mjs';
|
|
58
58
|
export * from './string/index.mjs';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import type { Evaluate } from '../helpers/index.mjs';
|
|
3
|
+
import type { TProperties } from '../object/index.mjs';
|
|
3
4
|
import { type TIndex } from './indexed.mjs';
|
|
4
5
|
import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
|
|
5
|
-
import { Evaluate } from '../helpers/index.mjs';
|
|
6
6
|
type TMappedIndexPropertyKey<T extends TSchema, K extends PropertyKey> = {
|
|
7
7
|
[_ in K]: TIndex<T, [K]>;
|
|
8
8
|
};
|
|
@@ -5,11 +5,10 @@ function MappedIndexPropertyKey(T, K, options) {
|
|
|
5
5
|
return { [K]: Index(T, [K], options) };
|
|
6
6
|
}
|
|
7
7
|
// prettier-ignore
|
|
8
|
-
function MappedIndexPropertyKeys(T, K, options
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
: Acc);
|
|
8
|
+
function MappedIndexPropertyKeys(T, K, options) {
|
|
9
|
+
return K.reduce((Acc, L) => {
|
|
10
|
+
return { ...Acc, ...MappedIndexPropertyKey(T, L, options) };
|
|
11
|
+
}, {});
|
|
13
12
|
}
|
|
14
13
|
// prettier-ignore
|
|
15
14
|
function MappedIndexProperties(T, K, options) {
|
|
@@ -6,7 +6,7 @@ import { type TIndex } from './index.mjs';
|
|
|
6
6
|
type TFromProperties<T extends TSchema, P extends TProperties> = ({
|
|
7
7
|
[K2 in keyof P]: TIndex<T, TIndexPropertyKeys<P[K2]>>;
|
|
8
8
|
});
|
|
9
|
-
type TFromMappedResult<T extends TSchema,
|
|
9
|
+
type TFromMappedResult<T extends TSchema, R extends TMappedResult> = (TFromProperties<T, R['properties']>);
|
|
10
10
|
export type TIndexFromMappedResult<T extends TSchema, R extends TMappedResult, P extends TProperties = TFromMappedResult<T, R>> = (TMappedResult<P>);
|
|
11
11
|
export declare function IndexFromMappedResult<T extends TSchema, R extends TMappedResult, P extends TProperties = TFromMappedResult<T, R>>(T: T, R: R, options: SchemaOptions): TMappedResult<P>;
|
|
12
12
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { type TTemplateLiteralGenerate, type TTemplateLiteral } from '../template-literal/index.mjs';
|
|
2
|
+
import type { TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
3
|
+
import type { TInteger } from '../integer/index.mjs';
|
|
4
|
+
import type { TNumber } from '../number/index.mjs';
|
|
5
|
+
import type { TSchema } from '../schema/index.mjs';
|
|
6
|
+
import type { TUnion } from '../union/index.mjs';
|
|
7
7
|
type TFromTemplateLiteral<T extends TTemplateLiteral, R extends string[] = TTemplateLiteralGenerate<T>> = (R);
|
|
8
8
|
type TFromUnion<T extends TSchema[], Acc extends string[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, [...TIndexPropertyKeys<L>, ...Acc]> : Acc);
|
|
9
9
|
type TFromLiteral<T extends TLiteralValue> = (T extends PropertyKey ? [`${T}`] : []);
|
|
@@ -2,7 +2,6 @@ import { TemplateLiteralGenerate } from '../template-literal/index.mjs';
|
|
|
2
2
|
// ------------------------------------------------------------------
|
|
3
3
|
// TypeGuard
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
|
-
// prettier-ignore
|
|
6
5
|
import { IsTemplateLiteral, IsUnion, IsLiteral, IsNumber, IsInteger } from '../guard/type.mjs';
|
|
7
6
|
// prettier-ignore
|
|
8
7
|
function FromTemplateLiteral(T) {
|
|
@@ -11,10 +10,9 @@ function FromTemplateLiteral(T) {
|
|
|
11
10
|
}
|
|
12
11
|
// prettier-ignore
|
|
13
12
|
function FromUnion(T) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
: []);
|
|
13
|
+
return T.reduce((Acc, L) => {
|
|
14
|
+
return [...Acc, ...IndexPropertyKeys(L)];
|
|
15
|
+
}, []);
|
|
18
16
|
}
|
|
19
17
|
// prettier-ignore
|
|
20
18
|
function FromLiteral(T) {
|
|
@@ -16,7 +16,7 @@ import { type TIndexFromMappedResult } from './indexed-from-mapped-result.mjs';
|
|
|
16
16
|
type TFromRest<T extends TSchema[], K extends PropertyKey, Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, K, [...Acc, Assert<TFromKey<L, K>, TSchema>]> : Acc);
|
|
17
17
|
type TFromIntersectRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? TFromIntersectRest<R, [...Acc]> : TFromIntersectRest<R, [...Acc, L]> : Acc);
|
|
18
18
|
type TFromIntersect<T extends TSchema[], K extends PropertyKey> = (TIntersectEvaluated<TFromIntersectRest<TFromRest<T, K>>>);
|
|
19
|
-
type TFromUnionRest<T extends TSchema[]
|
|
19
|
+
type TFromUnionRest<T extends TSchema[]> = T;
|
|
20
20
|
type TFromUnion<T extends TSchema[], K extends PropertyKey> = (TUnionEvaluated<TFromUnionRest<TFromRest<T, K>>>);
|
|
21
21
|
type TFromTuple<T extends TSchema[], K extends PropertyKey> = (K extends keyof T ? T[K] : K extends '[number]' ? TUnionEvaluated<T> : TNever);
|
|
22
22
|
type TFromArray<T extends TSchema, K extends PropertyKey> = (K extends '[number]' ? T : TNever);
|
|
@@ -10,33 +10,20 @@ import { IndexFromMappedResult } from './indexed-from-mapped-result.mjs';
|
|
|
10
10
|
// ------------------------------------------------------------------
|
|
11
11
|
import { IsArray, IsIntersect, IsObject, IsMappedKey, IsMappedResult, IsNever, IsSchema, IsTuple, IsUnion } from '../guard/type.mjs';
|
|
12
12
|
// prettier-ignore
|
|
13
|
-
function FromRest(T, K
|
|
14
|
-
|
|
15
|
-
return (T.length > 0
|
|
16
|
-
? FromRest(R, K, [...Acc, FromKey(L, K)])
|
|
17
|
-
: Acc);
|
|
13
|
+
function FromRest(T, K) {
|
|
14
|
+
return T.map(L => FromKey(L, K));
|
|
18
15
|
}
|
|
19
16
|
// prettier-ignore
|
|
20
|
-
function FromIntersectRest(T
|
|
21
|
-
|
|
22
|
-
return (T.length > 0
|
|
23
|
-
? IsNever(L)
|
|
24
|
-
? FromIntersectRest(R, [...Acc])
|
|
25
|
-
: FromIntersectRest(R, [...Acc, L])
|
|
26
|
-
: Acc);
|
|
17
|
+
function FromIntersectRest(T) {
|
|
18
|
+
return T.filter(L => !IsNever(L));
|
|
27
19
|
}
|
|
28
20
|
// prettier-ignore
|
|
29
21
|
function FromIntersect(T, K) {
|
|
30
22
|
return (IntersectEvaluated(FromIntersectRest(FromRest(T, K))));
|
|
31
23
|
}
|
|
32
24
|
// prettier-ignore
|
|
33
|
-
function FromUnionRest(T
|
|
34
|
-
|
|
35
|
-
return (T.length > 0
|
|
36
|
-
? IsNever(L)
|
|
37
|
-
? []
|
|
38
|
-
: FromUnionRest(R, Acc)
|
|
39
|
-
: Acc);
|
|
25
|
+
function FromUnionRest(T) {
|
|
26
|
+
return T; // review this
|
|
40
27
|
}
|
|
41
28
|
// prettier-ignore
|
|
42
29
|
function FromUnion(T, K) {
|
|
@@ -56,9 +43,7 @@ function FromArray(T, K) {
|
|
|
56
43
|
}
|
|
57
44
|
// prettier-ignore
|
|
58
45
|
function FromProperty(T, K) {
|
|
59
|
-
return (K in T
|
|
60
|
-
? T[K]
|
|
61
|
-
: Never());
|
|
46
|
+
return (K in T ? T[K] : Never());
|
|
62
47
|
}
|
|
63
48
|
// prettier-ignore
|
|
64
49
|
function FromKey(T, K) {
|
|
@@ -70,11 +55,8 @@ function FromKey(T, K) {
|
|
|
70
55
|
Never());
|
|
71
56
|
}
|
|
72
57
|
// prettier-ignore
|
|
73
|
-
function FromKeys(T, K
|
|
74
|
-
|
|
75
|
-
return (K.length > 0
|
|
76
|
-
? FromKeys(T, R, [...Acc, FromKey(T, L)])
|
|
77
|
-
: Acc);
|
|
58
|
+
function FromKeys(T, K) {
|
|
59
|
+
return K.map(L => FromKey(T, L));
|
|
78
60
|
}
|
|
79
61
|
// prettier-ignore
|
|
80
62
|
function FromSchema(T, K) {
|
|
@@ -11,25 +11,15 @@ import { IntersectCreate } from './intersect-create.mjs';
|
|
|
11
11
|
import { IsOptional, IsTransform, } from '../guard/type.mjs';
|
|
12
12
|
// prettier-ignore
|
|
13
13
|
function IsIntersectOptional(T) {
|
|
14
|
-
|
|
15
|
-
return (T.length > 0
|
|
16
|
-
? IsOptional(L)
|
|
17
|
-
? IsIntersectOptional(R)
|
|
18
|
-
: false
|
|
19
|
-
: true);
|
|
14
|
+
return T.every(L => IsOptional(L));
|
|
20
15
|
}
|
|
21
16
|
// prettier-ignore
|
|
22
17
|
function RemoveOptionalFromType(T) {
|
|
23
18
|
return (Discard(T, [OptionalKind]));
|
|
24
19
|
}
|
|
25
20
|
// prettier-ignore
|
|
26
|
-
function RemoveOptionalFromRest(T
|
|
27
|
-
|
|
28
|
-
return (T.length > 0
|
|
29
|
-
? IsOptional(L)
|
|
30
|
-
? RemoveOptionalFromRest(R, [...Acc, RemoveOptionalFromType(L)])
|
|
31
|
-
: RemoveOptionalFromRest(R, [...Acc, L])
|
|
32
|
-
: Acc);
|
|
21
|
+
function RemoveOptionalFromRest(T) {
|
|
22
|
+
return T.map(L => IsOptional(L) ? RemoveOptionalFromType(L) : L);
|
|
33
23
|
}
|
|
34
24
|
// prettier-ignore
|
|
35
25
|
function ResolveIntersect(T, options) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
-
import { TIntrinsic } from './intrinsic.mjs';
|
|
1
|
+
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
+
import { type TIntrinsic } from './intrinsic.mjs';
|
|
3
3
|
export type TCapitalize<T extends TSchema> = TIntrinsic<T, 'Capitalize'>;
|
|
4
4
|
/** `[Json]` Intrinsic function to Capitalize LiteralString types */
|
|
5
5
|
export declare function Capitalize<T extends TSchema>(T: T, options?: SchemaOptions): TCapitalize<T>;
|
|
@@ -3,7 +3,7 @@ import type { TProperties } from '../object/index.mjs';
|
|
|
3
3
|
import { Assert } from '../helpers/index.mjs';
|
|
4
4
|
import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
|
|
5
5
|
import { type TIntrinsic, type IntrinsicMode } from './intrinsic.mjs';
|
|
6
|
-
import { TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
6
|
+
import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
|
|
7
7
|
type TMappedIntrinsicPropertyKey<K extends PropertyKey, M extends IntrinsicMode> = {
|
|
8
8
|
[_ in K]: TIntrinsic<TLiteral<Assert<K, TLiteralValue>>, M>;
|
|
9
9
|
};
|
|
@@ -8,11 +8,10 @@ function MappedIntrinsicPropertyKey(K, M, options) {
|
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
// prettier-ignore
|
|
11
|
-
function MappedIntrinsicPropertyKeys(K, M, options
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
: Acc);
|
|
11
|
+
function MappedIntrinsicPropertyKeys(K, M, options) {
|
|
12
|
+
return K.reduce((Acc, L) => {
|
|
13
|
+
return { ...Acc, ...MappedIntrinsicPropertyKey(L, M, options) };
|
|
14
|
+
}, {});
|
|
16
15
|
}
|
|
17
16
|
// prettier-ignore
|
|
18
17
|
function MappedIntrinsicProperties(T, M, options) {
|
|
@@ -7,9 +7,8 @@ import { type TMappedKey } from '../mapped/index.mjs';
|
|
|
7
7
|
export type IntrinsicMode = 'Uppercase' | 'Lowercase' | 'Capitalize' | 'Uncapitalize';
|
|
8
8
|
type TFromTemplateLiteral<T extends TTemplateLiteralKind[], M extends IntrinsicMode> = M extends IntrinsicMode ? T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? [TIntrinsic<L, M>, ...TFromTemplateLiteral<R, M>] : T : T;
|
|
9
9
|
type TFromLiteralValue<T, M extends IntrinsicMode> = (T extends string ? M extends 'Uncapitalize' ? Uncapitalize<T> : M extends 'Capitalize' ? Capitalize<T> : M extends 'Uppercase' ? Uppercase<T> : M extends 'Lowercase' ? Lowercase<T> : string : T);
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
export type TIntrinsic<T extends TSchema, M extends IntrinsicMode> = T extends TMappedKey ? TIntrinsicFromMappedKey<T, M> : T extends TTemplateLiteral<infer S> ? TTemplateLiteral<TFromTemplateLiteral<S, M>> : T extends TUnion<infer S> ? TUnion<FromRest<S, M>> : T extends TLiteral<infer S> ? TLiteral<TFromLiteralValue<S, M>> : T;
|
|
10
|
+
type TFromRest<T extends TSchema[], M extends IntrinsicMode, Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, M, [...Acc, TIntrinsic<L, M>]> : Acc;
|
|
11
|
+
export type TIntrinsic<T extends TSchema, M extends IntrinsicMode> = T extends TMappedKey ? TIntrinsicFromMappedKey<T, M> : T extends TTemplateLiteral<infer S> ? TTemplateLiteral<TFromTemplateLiteral<S, M>> : T extends TUnion<infer S> ? TUnion<TFromRest<S, M>> : T extends TLiteral<infer S> ? TLiteral<TFromLiteralValue<S, M>> : T;
|
|
13
12
|
/** Applies an intrinsic string manipulation to the given type. */
|
|
14
13
|
export declare function Intrinsic<T extends TMappedKey, M extends IntrinsicMode>(schema: T, mode: M, options?: SchemaOptions): TIntrinsicFromMappedKey<T, M>;
|
|
15
14
|
/** Applies an intrinsic string manipulation to the given type. */
|
|
@@ -45,11 +45,8 @@ function FromLiteralValue(value, mode) {
|
|
|
45
45
|
value) : value.toString());
|
|
46
46
|
}
|
|
47
47
|
// prettier-ignore
|
|
48
|
-
function FromRest(T, M
|
|
49
|
-
|
|
50
|
-
return (T.length > 0
|
|
51
|
-
? FromRest(R, M, [...Acc, Intrinsic(L, M)])
|
|
52
|
-
: Acc);
|
|
48
|
+
function FromRest(T, M) {
|
|
49
|
+
return T.map(L => Intrinsic(L, M));
|
|
53
50
|
}
|
|
54
51
|
/** Applies an intrinsic string manipulation to the given type. */
|
|
55
52
|
export function Intrinsic(schema, mode, options = {}) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
-
import { TIntrinsic } from './intrinsic.mjs';
|
|
1
|
+
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
+
import { type TIntrinsic } from './intrinsic.mjs';
|
|
3
3
|
export type TLowercase<T extends TSchema> = TIntrinsic<T, 'Lowercase'>;
|
|
4
4
|
/** `[Json]` Intrinsic function to Lowercase LiteralString types */
|
|
5
5
|
export declare function Lowercase<T extends TSchema>(T: T, options?: SchemaOptions): TLowercase<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
-
import { TIntrinsic } from './intrinsic.mjs';
|
|
1
|
+
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
+
import { type TIntrinsic } from './intrinsic.mjs';
|
|
3
3
|
export type TUncapitalize<T extends TSchema> = TIntrinsic<T, 'Uncapitalize'>;
|
|
4
4
|
/** `[Json]` Intrinsic function to Uncapitalize LiteralString types */
|
|
5
5
|
export declare function Uncapitalize<T extends TSchema>(T: T, options?: SchemaOptions): TUncapitalize<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
-
import { TIntrinsic } from './intrinsic.mjs';
|
|
1
|
+
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
+
import { type TIntrinsic } from './intrinsic.mjs';
|
|
3
3
|
export type TUppercase<T extends TSchema> = TIntrinsic<T, 'Uppercase'>;
|
|
4
4
|
/** `[Json]` Intrinsic function to Uppercase LiteralString types */
|
|
5
5
|
export declare function Uppercase<T extends TSchema>(T: T, options?: SchemaOptions): TUppercase<T>;
|
|
@@ -5,7 +5,7 @@ import { type TKeyOf } from './keyof.mjs';
|
|
|
5
5
|
type TFromProperties<K extends TProperties> = ({
|
|
6
6
|
[K2 in keyof K]: TKeyOf<K[K2]>;
|
|
7
7
|
});
|
|
8
|
-
type TFromMappedResult<
|
|
9
|
-
export type TKeyOfFromMappedResult<
|
|
10
|
-
export declare function KeyOfFromMappedResult<
|
|
8
|
+
type TFromMappedResult<R extends TMappedResult> = (TFromProperties<R['properties']>);
|
|
9
|
+
export type TKeyOfFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>> = (TMappedResult<P>);
|
|
10
|
+
export declare function KeyOfFromMappedResult<R extends TMappedResult, P extends TProperties = TFromMappedResult<R>>(R: R, options: SchemaOptions): TMappedResult<P>;
|
|
11
11
|
export {};
|
|
@@ -7,11 +7,11 @@ function FromProperties(K, options) {
|
|
|
7
7
|
}, {});
|
|
8
8
|
}
|
|
9
9
|
// prettier-ignore
|
|
10
|
-
function FromMappedResult(
|
|
11
|
-
return FromProperties(
|
|
10
|
+
function FromMappedResult(R, options) {
|
|
11
|
+
return FromProperties(R.properties, options);
|
|
12
12
|
}
|
|
13
13
|
// prettier-ignore
|
|
14
|
-
export function KeyOfFromMappedResult(
|
|
15
|
-
const P = FromMappedResult(
|
|
14
|
+
export function KeyOfFromMappedResult(R, options) {
|
|
15
|
+
const P = FromMappedResult(R, options);
|
|
16
16
|
return MappedResult(P);
|
|
17
17
|
}
|
|
@@ -6,11 +6,11 @@ import type { TUnion } from '../union/index.mjs';
|
|
|
6
6
|
import type { TTuple } from '../tuple/index.mjs';
|
|
7
7
|
import type { TArray } from '../array/index.mjs';
|
|
8
8
|
import type { TObject, TProperties } from '../object/index.mjs';
|
|
9
|
-
import {
|
|
9
|
+
import { type TSetUnionMany, type TSetIntersectMany } from '../sets/index.mjs';
|
|
10
10
|
type TFromRest<T extends TSchema[], Acc extends PropertyKey[][] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Acc, TKeyOfPropertyKeys<L>]> : Acc);
|
|
11
|
-
type FromIntersect<T extends TSchema[], C extends PropertyKey[][] = TFromRest<T>, R extends PropertyKey[] =
|
|
11
|
+
type FromIntersect<T extends TSchema[], C extends PropertyKey[][] = TFromRest<T>, R extends PropertyKey[] = TSetUnionMany<C>> = R;
|
|
12
12
|
declare function FromIntersect<T extends TSchema[]>(T: [...T]): FromIntersect<T>;
|
|
13
|
-
type FromUnion<T extends TSchema[], C extends PropertyKey[][] = TFromRest<T>, R extends PropertyKey[] =
|
|
13
|
+
type FromUnion<T extends TSchema[], C extends PropertyKey[][] = TFromRest<T>, R extends PropertyKey[] = TSetIntersectMany<C>> = R;
|
|
14
14
|
declare function FromUnion<T extends TSchema[]>(T: [...T]): FromUnion<T>;
|
|
15
15
|
type TFromTuple<T extends TSchema[], I extends string = ZeroString, Acc extends PropertyKey[] = []> = T extends [infer _ extends TSchema, ...infer R extends TSchema[]] ? TFromTuple<R, Increment<I>, [...Acc, I]> : Acc;
|
|
16
16
|
type TFromArray<_ extends TSchema> = ([
|
|
@@ -1,35 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { OperatorUnionMany, OperatorIntersectMany } from '../operators/index.mjs';
|
|
1
|
+
import { SetUnionMany, SetIntersectMany } from '../sets/index.mjs';
|
|
3
2
|
// ------------------------------------------------------------------
|
|
4
3
|
// TypeGuard
|
|
5
4
|
// ------------------------------------------------------------------
|
|
6
|
-
// prettier-ignore
|
|
7
5
|
import { IsIntersect, IsUnion, IsTuple, IsArray, IsObject, IsRecord } from '../guard/type.mjs';
|
|
8
6
|
// prettier-ignore
|
|
9
|
-
function FromRest(T
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
: Acc);
|
|
7
|
+
function FromRest(T) {
|
|
8
|
+
return T.reduce((Acc, L) => {
|
|
9
|
+
return [...Acc, KeyOfPropertyKeys(L)];
|
|
10
|
+
}, []);
|
|
14
11
|
}
|
|
15
12
|
// prettier-ignore
|
|
16
13
|
function FromIntersect(T) {
|
|
17
14
|
const C = FromRest(T);
|
|
18
|
-
const R =
|
|
15
|
+
const R = SetUnionMany(C);
|
|
19
16
|
return R;
|
|
20
17
|
}
|
|
21
18
|
// prettier-ignore
|
|
22
19
|
function FromUnion(T) {
|
|
23
20
|
const C = FromRest(T);
|
|
24
|
-
const R =
|
|
21
|
+
const R = SetIntersectMany(C);
|
|
25
22
|
return R;
|
|
26
23
|
}
|
|
27
24
|
// prettier-ignore
|
|
28
|
-
function FromTuple(T
|
|
29
|
-
|
|
30
|
-
return (T.length > 0
|
|
31
|
-
? FromTuple(R, Increment(I), [...Acc, I])
|
|
32
|
-
: Acc);
|
|
25
|
+
function FromTuple(T) {
|
|
26
|
+
return T.map((_, I) => I.toString());
|
|
33
27
|
}
|
|
34
28
|
// prettier-ignore
|
|
35
29
|
function FromArray(_) {
|
|
@@ -7,16 +7,10 @@ import { KeyOfFromMappedResult } from './keyof-from-mapped-result.mjs';
|
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
8
|
// TypeGuard
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
|
-
// prettier-ignore
|
|
11
10
|
import { IsMappedResult } from '../guard/type.mjs';
|
|
12
11
|
// prettier-ignore
|
|
13
|
-
function FromPropertyKeys(T
|
|
14
|
-
|
|
15
|
-
return (T.length > 0
|
|
16
|
-
? L === '[number]'
|
|
17
|
-
? FromPropertyKeys(R, [...Acc, Number()])
|
|
18
|
-
: FromPropertyKeys(R, [...Acc, Literal(L)])
|
|
19
|
-
: Acc);
|
|
12
|
+
function FromPropertyKeys(T) {
|
|
13
|
+
return T.map(L => L === '[number]' ? Number() : Literal(L));
|
|
20
14
|
}
|
|
21
15
|
/** `[Json]` Creates a KeyOf type */
|
|
22
16
|
export function KeyOf(T, options = {}) {
|
|
@@ -14,12 +14,17 @@ import { type TPromise } from '../promise/index.mjs';
|
|
|
14
14
|
import { type TReadonly } from '../readonly/index.mjs';
|
|
15
15
|
import { type TTuple } from '../tuple/index.mjs';
|
|
16
16
|
import { type TUnion } from '../union/index.mjs';
|
|
17
|
+
import { type TSetIncludes } from '../sets/index.mjs';
|
|
17
18
|
import { type TMappedResult } from './mapped-result.mjs';
|
|
18
19
|
import type { TMappedKey } from './mapped-key.mjs';
|
|
19
20
|
type TFromMappedResult<K extends PropertyKey, P extends TProperties> = (K extends keyof P ? FromSchemaType<K, P[K]> : TMappedResult<P>);
|
|
20
|
-
type
|
|
21
|
+
type TMappedKeyToKnownMappedResultProperties<K extends PropertyKey> = {
|
|
22
|
+
[_ in K]: TLiteral<Assert<K, TLiteralValue>>;
|
|
23
|
+
};
|
|
24
|
+
type TMappedKeyToUnknownMappedResultProperties<P extends PropertyKey[], Acc extends TProperties = {}> = (P extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TMappedKeyToUnknownMappedResultProperties<R, Acc & {
|
|
21
25
|
[_ in L]: TLiteral<Assert<L, TLiteralValue>>;
|
|
22
26
|
}> : Acc);
|
|
27
|
+
type TMappedKeyToMappedResultProperties<K extends PropertyKey, P extends PropertyKey[]> = (TSetIncludes<P, K> extends true ? TMappedKeyToKnownMappedResultProperties<K> : TMappedKeyToUnknownMappedResultProperties<P>);
|
|
23
28
|
type TFromMappedKey<K extends PropertyKey, P extends PropertyKey[], R extends TProperties = TMappedKeyToMappedResultProperties<K, P>> = (TFromMappedResult<K, R>);
|
|
24
29
|
type TFromRest<K extends PropertyKey, T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<K, R, [...Acc, FromSchemaType<K, L>]> : Acc);
|
|
25
30
|
type FromProperties<K extends PropertyKey, T extends TProperties, R extends TProperties = Evaluate<{
|