@sinclair/typebox 0.32.0-dev-10 → 0.32.0-dev-12
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 +4 -4
- package/build/import/errors/errors.mjs +3 -3
- package/build/import/index.d.mts +3 -3
- package/build/import/index.mjs +2 -2
- package/build/import/type/composite/composite.d.mts +2 -2
- package/build/import/type/composite/composite.mjs +2 -2
- package/build/import/type/extends/extends-mapped-result.d.mts +13 -0
- package/build/import/type/extends/extends-mapped-result.mjs +14 -0
- package/build/import/type/extends/extends-mapped.d.mts +17 -0
- package/build/import/type/extends/extends-mapped.mjs +21 -0
- package/build/import/type/extends/extends.d.mts +8 -2
- package/build/import/type/extends/extends.mjs +7 -3
- package/build/import/type/extends/index.d.mts +2 -0
- package/build/import/type/extends/index.mjs +2 -0
- package/build/import/type/guard/type.d.mts +5 -1
- package/build/import/type/guard/type.mjs +18 -2
- package/build/import/type/indexed/index.d.mts +2 -1
- package/build/import/type/indexed/index.mjs +2 -1
- package/build/import/type/indexed/indexed-mapped.d.mts +16 -0
- package/build/import/type/indexed/indexed-mapped.mjs +18 -0
- package/build/import/type/indexed/{indexed-key.d.mts → indexed-property-keys.d.mts} +3 -3
- package/build/import/type/indexed/{indexed-key.mjs → indexed-property-keys.mjs} +2 -2
- package/build/import/type/indexed/indexed-type.d.mts +2 -2
- package/build/import/type/indexed/indexed-type.mjs +1 -1
- package/build/import/type/indexed/indexed.d.mts +7 -4
- package/build/import/type/indexed/indexed.mjs +7 -6
- package/build/import/type/keyof/index.d.mts +1 -2
- package/build/import/type/keyof/index.mjs +1 -2
- package/build/import/type/keyof/{keyof-string.d.mts → keyof-property-keys.d.mts} +4 -4
- package/build/import/type/keyof/{keyof-string.mjs → keyof-property-keys.mjs} +4 -4
- package/build/import/type/keyof/keyof.d.mts +12 -4
- package/build/import/type/keyof/keyof.mjs +14 -3
- package/build/import/type/mapped/mapped.d.mts +41 -15
- package/build/import/type/mapped/mapped.mjs +75 -11
- package/build/import/type/omit/omit.d.mts +2 -2
- package/build/import/type/omit/omit.mjs +2 -2
- package/build/import/type/pick/pick.d.mts +2 -2
- package/build/import/type/pick/pick.mjs +2 -2
- package/build/import/type/record/record.mjs +3 -3
- package/build/import/type/tuple/tuple.d.mts +3 -1
- package/build/import/type/type/json.d.mts +13 -6
- package/build/import/type/type/json.mjs +6 -2
- package/build/import/value/check/check.mjs +3 -3
- package/build/import/value/clean/clean.mjs +2 -2
- package/build/import/value/index.d.mts +1 -1
- package/build/import/value/index.mjs +1 -1
- package/build/import/value/transform/decode.d.mts +1 -1
- package/build/import/value/transform/decode.mjs +6 -6
- package/build/import/value/transform/encode.d.mts +1 -1
- package/build/import/value/transform/encode.mjs +6 -6
- package/build/import/value/value/value.mjs +3 -3
- package/build/require/compiler/compiler.js +4 -4
- package/build/require/errors/errors.js +2 -2
- package/build/require/index.d.ts +3 -3
- package/build/require/index.js +7 -7
- package/build/require/type/composite/composite.d.ts +2 -2
- package/build/require/type/composite/composite.js +1 -1
- package/build/require/type/extends/extends-mapped-result.d.ts +13 -0
- package/build/require/type/extends/extends-mapped-result.js +18 -0
- package/build/require/type/extends/extends-mapped.d.ts +17 -0
- package/build/require/type/extends/extends-mapped.js +25 -0
- package/build/require/type/extends/extends.d.ts +8 -2
- package/build/require/type/extends/extends.js +8 -5
- package/build/require/type/extends/index.d.ts +2 -0
- package/build/require/type/extends/index.js +2 -0
- package/build/require/type/guard/type.d.ts +5 -1
- package/build/require/type/guard/type.js +53 -34
- package/build/require/type/indexed/index.d.ts +2 -1
- package/build/require/type/indexed/index.js +2 -1
- package/build/require/type/indexed/indexed-mapped.d.ts +16 -0
- package/build/require/type/indexed/indexed-mapped.js +22 -0
- package/build/require/type/indexed/{indexed-key.d.ts → indexed-property-keys.d.ts} +3 -3
- package/build/require/type/indexed/{indexed-key.js → indexed-property-keys.js} +4 -4
- package/build/require/type/indexed/indexed-type.d.ts +2 -2
- package/build/require/type/indexed/indexed-type.js +3 -3
- package/build/require/type/indexed/indexed.d.ts +7 -4
- package/build/require/type/indexed/indexed.js +7 -6
- package/build/require/type/keyof/index.d.ts +1 -2
- package/build/require/type/keyof/index.js +1 -2
- package/build/require/type/keyof/{keyof-string.d.ts → keyof-property-keys.d.ts} +4 -4
- package/build/require/type/keyof/{keyof-string.js → keyof-property-keys.js} +7 -7
- package/build/require/type/keyof/keyof.d.ts +12 -4
- package/build/require/type/keyof/keyof.js +14 -3
- package/build/require/type/mapped/mapped.d.ts +41 -15
- package/build/require/type/mapped/mapped.js +80 -12
- package/build/require/type/omit/omit.d.ts +2 -2
- package/build/require/type/omit/omit.js +1 -1
- package/build/require/type/pick/pick.d.ts +2 -2
- package/build/require/type/pick/pick.js +1 -1
- package/build/require/type/record/record.js +2 -2
- package/build/require/type/tuple/tuple.d.ts +3 -1
- package/build/require/type/type/json.d.ts +13 -6
- package/build/require/type/type/json.js +54 -50
- package/build/require/value/check/check.js +2 -2
- package/build/require/value/clean/clean.js +15 -15
- package/build/require/value/index.d.ts +1 -1
- package/build/require/value/index.js +3 -3
- package/build/require/value/transform/decode.d.ts +1 -1
- package/build/require/value/transform/decode.js +6 -6
- package/build/require/value/transform/encode.d.ts +1 -1
- package/build/require/value/transform/encode.js +6 -6
- package/build/require/value/value/value.js +2 -2
- package/package.json +4 -1
- package/build/import/type/keyof/keyof-type.d.mts +0 -11
- package/build/import/type/keyof/keyof-type.mjs +0 -15
- package/build/require/type/keyof/keyof-type.d.ts +0 -11
- package/build/require/type/keyof/keyof-type.js +0 -19
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TransformEncode, TransformDecode, HasTransform, TransformDecodeCheckError, TransformEncodeCheckError } from '../value/transform/index.mjs';
|
|
2
2
|
import { IsArray, IsString, IsNumber, IsBigInt } from '../value/guard/index.mjs';
|
|
3
3
|
import { Errors } from '../errors/index.mjs';
|
|
4
4
|
import { TypeSystemPolicy } from '../system/index.mjs';
|
|
@@ -7,7 +7,7 @@ import { Hash } from '../value/hash/index.mjs';
|
|
|
7
7
|
import { Kind } from '../type/symbols/index.mjs';
|
|
8
8
|
import { TSchema as IsSchemaType } from '../type/guard/type.mjs';
|
|
9
9
|
import { TypeRegistry, FormatRegistry } from '../type/registry/index.mjs';
|
|
10
|
-
import {
|
|
10
|
+
import { KeyOfPattern } from '../type/keyof/index.mjs';
|
|
11
11
|
import { ExtendsUndefinedCheck } from '../type/extends/extends-undefined.mjs';
|
|
12
12
|
import { Never } from '../type/never/index.mjs';
|
|
13
13
|
export class TypeCheck {
|
|
@@ -238,12 +238,12 @@ export var TypeCompiler;
|
|
|
238
238
|
function* TIntersect(schema, references, value) {
|
|
239
239
|
const check1 = schema.allOf.map((schema) => CreateExpression(schema, references, value)).join(' && ');
|
|
240
240
|
if (schema.unevaluatedProperties === false) {
|
|
241
|
-
const keyCheck = CreateVariable(`${new RegExp(
|
|
241
|
+
const keyCheck = CreateVariable(`${new RegExp(KeyOfPattern(schema))};`);
|
|
242
242
|
const check2 = `Object.getOwnPropertyNames(${value}).every(key => ${keyCheck}.test(key))`;
|
|
243
243
|
yield `(${check1} && ${check2})`;
|
|
244
244
|
}
|
|
245
245
|
else if (IsSchemaType(schema.unevaluatedProperties)) {
|
|
246
|
-
const keyCheck = CreateVariable(`${new RegExp(
|
|
246
|
+
const keyCheck = CreateVariable(`${new RegExp(KeyOfPattern(schema))};`);
|
|
247
247
|
const check2 = `Object.getOwnPropertyNames(${value}).every(key => ${keyCheck}.test(key) || ${CreateExpression(schema.unevaluatedProperties, references, `${value}[key]`)})`;
|
|
248
248
|
yield `(${check1} && ${check2})`;
|
|
249
249
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IsArray, IsUint8Array, IsDate, IsPromise, IsFunction, IsAsyncIterator, IsIterator, IsBoolean, IsNumber, IsBigInt, IsString, IsSymbol, IsInteger, IsNull, IsUndefined } from '../value/guard/index.mjs';
|
|
2
2
|
import { TypeSystemPolicy } from '../system/index.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { KeyOfPattern } from '../type/keyof/index.mjs';
|
|
4
4
|
import { TypeRegistry, FormatRegistry } from '../type/registry/index.mjs';
|
|
5
5
|
import { ExtendsUndefinedCheck } from '../type/extends/extends-undefined.mjs';
|
|
6
6
|
import { GetErrorFunction } from './function.mjs';
|
|
@@ -224,7 +224,7 @@ function* TIntersect(schema, references, path, value) {
|
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
if (schema.unevaluatedProperties === false) {
|
|
227
|
-
const keyCheck = new RegExp(
|
|
227
|
+
const keyCheck = new RegExp(KeyOfPattern(schema));
|
|
228
228
|
for (const valueKey of Object.getOwnPropertyNames(value)) {
|
|
229
229
|
if (!keyCheck.test(valueKey)) {
|
|
230
230
|
yield Create(ValueErrorType.IntersectUnevaluatedProperties, schema, `${path}/${valueKey}`, value);
|
|
@@ -232,7 +232,7 @@ function* TIntersect(schema, references, path, value) {
|
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
if (typeof schema.unevaluatedProperties === 'object') {
|
|
235
|
-
const keyCheck = new RegExp(
|
|
235
|
+
const keyCheck = new RegExp(KeyOfPattern(schema));
|
|
236
236
|
for (const valueKey of Object.getOwnPropertyNames(value)) {
|
|
237
237
|
if (!keyCheck.test(valueKey)) {
|
|
238
238
|
const next = Visit(schema.unevaluatedProperties, references, `${path}/${valueKey}`, value[valueKey]).next();
|
package/build/import/index.d.mts
CHANGED
|
@@ -21,15 +21,15 @@ export { Extends, type TExtends, ExtendsCheck, ExtendsResult, ExtendsUndefinedCh
|
|
|
21
21
|
export { Extract, type TExtract } from './type/extract/index.mjs';
|
|
22
22
|
export { Function, type TFunction } from './type/function/index.mjs';
|
|
23
23
|
export { Increment, type Assert, type AssertType, type AssertRest, type AssertProperties, type Ensure, type Evaluate, type TupleToIntersect, type TupleToUnion, type UnionToTuple } from './type/helpers/index.mjs';
|
|
24
|
-
export { Index, type TIndex,
|
|
24
|
+
export { Index, type TIndex, type TMappedIndex, IndexedPropertyKeys, IndexedType, MappedIndex } 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
27
|
export { Intersect, type TIntersect, type IntersectOptions } from './type/intersect/index.mjs';
|
|
28
28
|
export { Iterator, type TIterator } from './type/iterator/index.mjs';
|
|
29
29
|
export { Capitalize, type TCapitalize, Lowercase, type TLowercase, Uncapitalize, type TUncapitalize, Uppercase, type TUppercase, IntrinsicResolve } from './type/intrinsic/index.mjs';
|
|
30
|
-
export { KeyOf, type TKeyOf,
|
|
30
|
+
export { KeyOf, type TKeyOf, KeyOfPropertyKeys, KeyOfPattern } from './type/keyof/index.mjs';
|
|
31
31
|
export { Literal, type TLiteral } from './type/literal/index.mjs';
|
|
32
|
-
export { Mapped, type TMappedKey, type MappedFunction, type TMappedResult } from './type/mapped/index.mjs';
|
|
32
|
+
export { Mapped, type MappedKey as TMappedKey, type MappedFunction, type TMapped as TMappedResult } from './type/mapped/index.mjs';
|
|
33
33
|
export { Never, type TNever } from './type/never/index.mjs';
|
|
34
34
|
export { Not, type TNot } from './type/not/index.mjs';
|
|
35
35
|
export { Null, type TNull } from './type/null/index.mjs';
|
package/build/import/index.mjs
CHANGED
|
@@ -21,13 +21,13 @@ export { Extends, ExtendsCheck, ExtendsResult, ExtendsUndefinedCheck } from './t
|
|
|
21
21
|
export { Extract } from './type/extract/index.mjs';
|
|
22
22
|
export { Function } from './type/function/index.mjs';
|
|
23
23
|
export { Increment } from './type/helpers/index.mjs';
|
|
24
|
-
export { Index,
|
|
24
|
+
export { Index, IndexedPropertyKeys, IndexedType, MappedIndex } 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
27
|
export { Intersect } from './type/intersect/index.mjs';
|
|
28
28
|
export { Iterator } from './type/iterator/index.mjs';
|
|
29
29
|
export { Capitalize, Lowercase, Uncapitalize, Uppercase, IntrinsicResolve } from './type/intrinsic/index.mjs';
|
|
30
|
-
export { KeyOf,
|
|
30
|
+
export { KeyOf, KeyOfPropertyKeys, KeyOfPattern } from './type/keyof/index.mjs';
|
|
31
31
|
export { Literal } from './type/literal/index.mjs';
|
|
32
32
|
export { Mapped } from './type/mapped/index.mjs';
|
|
33
33
|
export { Never } from './type/never/index.mjs';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { UnionToTuple, Assert, Evaluate } from '../helpers/index.mjs';
|
|
2
2
|
import { type TObject, type ObjectOptions } from '../object/index.mjs';
|
|
3
3
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { IndexedType } from '../indexed/index.mjs';
|
|
5
5
|
type CompositeKeys<T extends TObject[]> = T extends [infer L extends TObject, ...infer R extends TObject[]] ? keyof L['properties'] | CompositeKeys<R> : never;
|
|
6
6
|
type CompositeIndex<T extends TIntersect<TObject[]>, K extends string[]> = K extends [infer L extends string, ...infer R extends string[]] ? {
|
|
7
|
-
[_ in L]:
|
|
7
|
+
[_ in L]: IndexedType<T, [L]>;
|
|
8
8
|
} & CompositeIndex<T, R> : {};
|
|
9
9
|
type CompositeReduce<T extends TObject[]> = UnionToTuple<CompositeKeys<T>> extends infer K ? Evaluate<CompositeIndex<TIntersect<T>, Assert<K, string[]>>> : {};
|
|
10
10
|
export type CompositeResolve<T extends TObject[]> = TIntersect<T> extends TIntersect ? TObject<CompositeReduce<T>> : TObject<{}>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Object } from '../object/index.mjs';
|
|
2
2
|
import { Intersect } from '../intersect/index.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { KeyOfPropertyKeys } from '../keyof/index.mjs';
|
|
4
4
|
import { Index } from '../indexed/index.mjs';
|
|
5
5
|
import { CloneType } from '../clone/type.mjs';
|
|
6
6
|
export function CompositeResolve(T) {
|
|
7
7
|
const intersect = Intersect(T, {});
|
|
8
|
-
const keys =
|
|
8
|
+
const keys = KeyOfPropertyKeys(intersect);
|
|
9
9
|
const properties = keys.reduce((acc, key) => ({ ...acc, [key]: Index(intersect, [key]) }), {});
|
|
10
10
|
return Object(properties);
|
|
11
11
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TSchema } from '../schema/index.mjs';
|
|
2
|
+
import type { TProperties } from '../object/index.mjs';
|
|
3
|
+
import { type TMappedResult } from '../mapped/index.mjs';
|
|
4
|
+
import { type TExtends } from './extends.mjs';
|
|
5
|
+
type MappedResultExtendsPropertyKeys<K extends TProperties, U extends TSchema, L extends TSchema, R extends TSchema> = ({
|
|
6
|
+
[K2 in keyof K]: TExtends<K[K2], U, L, R>;
|
|
7
|
+
});
|
|
8
|
+
declare function MappedResultExtendsPropertyKeys<K extends TProperties, U extends TSchema, L extends TSchema, R extends TSchema>(K: K, U: U, L: L, R: R): MappedResultExtendsPropertyKeys<K, U, L, R>;
|
|
9
|
+
type MappedResultExtendsProperties<K extends TMappedResult, U extends TSchema, L extends TSchema, R extends TSchema> = (MappedResultExtendsPropertyKeys<K['properties'], U, L, R>);
|
|
10
|
+
declare function MappedResultExtendsProperties<K extends TMappedResult, U extends TSchema, L extends TSchema, R extends TSchema>(K: K, U: U, L: L, R: R): MappedResultExtendsProperties<K, U, L, R>;
|
|
11
|
+
export type MappedResultExtends<T extends TMappedResult, U extends TSchema, L extends TSchema, R extends TSchema, P extends TProperties = MappedResultExtendsProperties<T, U, L, R>> = (TMappedResult<P>);
|
|
12
|
+
export declare function MappedResultExtends<T extends TMappedResult, U extends TSchema, L extends TSchema, R extends TSchema, P extends TProperties = MappedResultExtendsProperties<T, U, L, R>>(T: T, U: U, L: L, R: R): TMappedResult<P>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MappedResult } from '../mapped/index.mjs';
|
|
2
|
+
import { Extends } from './extends.mjs';
|
|
3
|
+
function MappedResultExtendsPropertyKeys(K, U, L, R) {
|
|
4
|
+
return globalThis.Object.getOwnPropertyNames(K).reduce((Acc, K2) => {
|
|
5
|
+
return { ...Acc, [K2]: Extends(K[K2], U, L, R) };
|
|
6
|
+
}, {});
|
|
7
|
+
}
|
|
8
|
+
function MappedResultExtendsProperties(K, U, L, R) {
|
|
9
|
+
return MappedResultExtendsPropertyKeys(K.properties, U, L, R);
|
|
10
|
+
}
|
|
11
|
+
export function MappedResultExtends(T, U, L, R) {
|
|
12
|
+
const P = MappedResultExtendsProperties(T, U, L, R);
|
|
13
|
+
return MappedResult(P);
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TSchema } from '../schema/index.mjs';
|
|
2
|
+
import type { TProperties } from '../object/index.mjs';
|
|
3
|
+
import type { Assert } from '../helpers/index.mjs';
|
|
4
|
+
import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
|
|
5
|
+
import { TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
6
|
+
import { type TExtends } from './extends.mjs';
|
|
7
|
+
type MappedExtendsPropertyKey<K extends PropertyKey, U extends TSchema, L extends TSchema, R extends TSchema> = {
|
|
8
|
+
[_ in K]: TExtends<TLiteral<Assert<K, TLiteralValue>>, U, L, R>;
|
|
9
|
+
};
|
|
10
|
+
declare function MappedExtendsPropertyKey<K extends PropertyKey, U extends TSchema, L extends TSchema, R extends TSchema>(K: K, U: U, L: L, R: R): MappedExtendsPropertyKey<K, U, L, R>;
|
|
11
|
+
type MappedExtendsPropertyKeys<K extends PropertyKey[], U extends TSchema, L extends TSchema, R extends TSchema> = (K extends [infer LK extends PropertyKey, ...infer RK extends PropertyKey[]] ? MappedExtendsPropertyKey<LK, U, L, R> & MappedExtendsPropertyKeys<RK, U, L, R> : {});
|
|
12
|
+
declare function MappedExtendsPropertyKeys<K extends PropertyKey[], U extends TSchema, L extends TSchema, R extends TSchema>(K: [...K], U: U, L: L, R: R): MappedExtendsPropertyKeys<K, U, L, R>;
|
|
13
|
+
type MappedExtendsProperties<K extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema> = (MappedExtendsPropertyKeys<K['keys'], U, L, R>);
|
|
14
|
+
declare function MappedExtendsProperties<K extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema>(K: K, U: U, L: L, R: R): MappedExtendsProperties<K, U, L, R>;
|
|
15
|
+
export type MappedExtends<T extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema, P extends TProperties = MappedExtendsProperties<T, U, L, R>> = (TMappedResult<P>);
|
|
16
|
+
export declare function MappedExtends<T extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema, P extends TProperties = MappedExtendsProperties<T, U, L, R>>(T: T, U: U, L: L, R: R): TMappedResult<P>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MappedResult } from '../mapped/index.mjs';
|
|
2
|
+
import { Literal } from '../literal/index.mjs';
|
|
3
|
+
import { Extends } from './extends.mjs';
|
|
4
|
+
function MappedExtendsPropertyKey(K, U, L, R) {
|
|
5
|
+
return {
|
|
6
|
+
[K]: Extends(Literal(K), U, L, R)
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function MappedExtendsPropertyKeys(K, U, L, R) {
|
|
10
|
+
const [LK, ...RK] = K;
|
|
11
|
+
return (K.length > 0
|
|
12
|
+
? { ...MappedExtendsPropertyKey(LK, U, L, R), ...MappedExtendsPropertyKeys(RK, U, L, R) }
|
|
13
|
+
: {});
|
|
14
|
+
}
|
|
15
|
+
function MappedExtendsProperties(K, U, L, R) {
|
|
16
|
+
return MappedExtendsPropertyKeys(K.keys, U, L, R);
|
|
17
|
+
}
|
|
18
|
+
export function MappedExtends(T, U, L, R) {
|
|
19
|
+
const P = MappedExtendsProperties(T, U, L, R);
|
|
20
|
+
return MappedResult(P);
|
|
21
|
+
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
2
|
import type { Static } from '../static/index.mjs';
|
|
3
3
|
import { type TUnion } from '../union/index.mjs';
|
|
4
|
+
import { TMappedKey, TMappedResult } from '../mapped/index.mjs';
|
|
4
5
|
import { UnionToTuple } from '../helpers/index.mjs';
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
import { MappedExtends } from './extends-mapped.mjs';
|
|
7
|
+
import { MappedResultExtends } from './extends-mapped-result.mjs';
|
|
8
|
+
type ExtendsResolve<L extends TSchema, R extends TSchema, T extends TSchema, U extends TSchema> = ((Static<L> extends Static<R> ? T : U) extends infer O extends TSchema ? UnionToTuple<O> extends [infer X extends TSchema, infer Y extends TSchema] ? TUnion<[X, Y]> : O : never);
|
|
9
|
+
declare function ExtendsResolve<L extends TSchema, R extends TSchema, T extends TSchema, U extends TSchema>(left: L, right: R, trueType: T, falseType: U): ExtendsResolve<L, R, T, U>;
|
|
7
10
|
export type TExtends<L extends TSchema, R extends TSchema, T extends TSchema, F extends TSchema> = ExtendsResolve<L, R, T, F>;
|
|
11
|
+
export declare function Extends<L extends TMappedResult, R extends TSchema, T extends TSchema, F extends TSchema>(L: L, R: R, T: T, F: F, options?: SchemaOptions): MappedResultExtends<L, R, T, F>;
|
|
12
|
+
export declare function Extends<L extends TMappedKey, R extends TSchema, T extends TSchema, F extends TSchema>(L: L, R: R, T: T, F: F, options?: SchemaOptions): MappedExtends<L, R, T, F>;
|
|
8
13
|
export declare function Extends<L extends TSchema, R extends TSchema, T extends TSchema, F extends TSchema>(L: L, R: R, T: T, F: F, options?: SchemaOptions): TExtends<L, R, T, F>;
|
|
14
|
+
export {};
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
import { TMappedKey as IsMappedKeyType, TMappedResult as IsMappedResultType } from '../guard/type.mjs';
|
|
1
2
|
import { Union } from '../union/index.mjs';
|
|
2
3
|
import { ExtendsCheck, ExtendsResult } from './extends-check.mjs';
|
|
3
4
|
import { CloneType } from '../clone/type.mjs';
|
|
4
|
-
|
|
5
|
+
import { MappedExtends } from './extends-mapped.mjs';
|
|
6
|
+
import { MappedResultExtends } from './extends-mapped-result.mjs';
|
|
7
|
+
function ExtendsResolve(left, right, trueType, falseType) {
|
|
5
8
|
const R = ExtendsCheck(left, right);
|
|
6
9
|
return (R === ExtendsResult.Union ? Union([trueType, falseType]) :
|
|
7
10
|
R === ExtendsResult.True ? trueType :
|
|
8
11
|
falseType);
|
|
9
12
|
}
|
|
10
13
|
export function Extends(L, R, T, F, options = {}) {
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
return (IsMappedResultType(L) ? CloneType(MappedResultExtends(L, R, T, F), options) :
|
|
15
|
+
IsMappedKeyType(L) ? CloneType(MappedExtends(L, R, T, F), options) :
|
|
16
|
+
CloneType(ExtendsResolve(L, R, T, F), options));
|
|
13
17
|
}
|
|
@@ -15,11 +15,12 @@ import type { TInteger } from '../integer/index.mjs';
|
|
|
15
15
|
import type { TIntersect } from '../intersect/index.mjs';
|
|
16
16
|
import type { TIterator } from '../iterator/index.mjs';
|
|
17
17
|
import type { TLiteral } from '../literal/index.mjs';
|
|
18
|
+
import type { TMappedKey, TMappedResult } from '../mapped/index.mjs';
|
|
18
19
|
import type { TNever } from '../never/index.mjs';
|
|
19
20
|
import type { TNot } from '../not/index.mjs';
|
|
20
21
|
import type { TNull } from '../null/index.mjs';
|
|
21
22
|
import type { TNumber } from '../number/index.mjs';
|
|
22
|
-
import type { TObject } from '../object/index.mjs';
|
|
23
|
+
import type { TObject, TProperties } from '../object/index.mjs';
|
|
23
24
|
import type { TOptional } from '../optional/index.mjs';
|
|
24
25
|
import type { TPromise } from '../promise/index.mjs';
|
|
25
26
|
import type { TReadonly } from '../readonly/index.mjs';
|
|
@@ -47,6 +48,7 @@ export declare function TConstructor(schema: unknown): schema is TConstructor;
|
|
|
47
48
|
export declare function TDate(schema: unknown): schema is TDate;
|
|
48
49
|
export declare function TFunction(schema: unknown): schema is TFunction;
|
|
49
50
|
export declare function TInteger(schema: unknown): schema is TInteger;
|
|
51
|
+
export declare function TProperties(schema: unknown): schema is TProperties;
|
|
50
52
|
export declare function TIntersect(schema: unknown): schema is TIntersect;
|
|
51
53
|
export declare function TIterator(schema: unknown): schema is TIterator;
|
|
52
54
|
export declare function TKindOf<T extends string>(schema: unknown, kind: T): schema is Record<PropertyKey, unknown> & {
|
|
@@ -56,6 +58,8 @@ export declare function TLiteralString(schema: unknown): schema is TLiteral<stri
|
|
|
56
58
|
export declare function TLiteralNumber(schema: unknown): schema is TLiteral<number>;
|
|
57
59
|
export declare function TLiteralBoolean(schema: unknown): schema is TLiteral<boolean>;
|
|
58
60
|
export declare function TLiteral(schema: unknown): schema is TLiteral;
|
|
61
|
+
export declare function TMappedKey(schema: unknown): schema is TMappedKey;
|
|
62
|
+
export declare function TMappedResult(schema: unknown): schema is TMappedResult;
|
|
59
63
|
export declare function TNever(schema: unknown): schema is TNever;
|
|
60
64
|
export declare function TNot(schema: unknown): schema is TNot;
|
|
61
65
|
export declare function TNull(schema: unknown): schema is TNull;
|
|
@@ -16,6 +16,8 @@ const KnownTypes = [
|
|
|
16
16
|
'Intersect',
|
|
17
17
|
'Iterator',
|
|
18
18
|
'Literal',
|
|
19
|
+
'MappedKey',
|
|
20
|
+
'MappedResult',
|
|
19
21
|
'Not',
|
|
20
22
|
'Null',
|
|
21
23
|
'Number',
|
|
@@ -157,6 +159,10 @@ export function TInteger(schema) {
|
|
|
157
159
|
IsOptionalNumber(schema.minimum) &&
|
|
158
160
|
IsOptionalNumber(schema.multipleOf));
|
|
159
161
|
}
|
|
162
|
+
export function TProperties(schema) {
|
|
163
|
+
return (ValueGuard.IsObject(schema) &&
|
|
164
|
+
Object.entries(schema).every(([key, schema]) => IsControlCharacterFree(key) && TSchema(schema)));
|
|
165
|
+
}
|
|
160
166
|
export function TIntersect(schema) {
|
|
161
167
|
return (TKindOf(schema, 'Intersect') &&
|
|
162
168
|
(ValueGuard.IsString(schema.type) && schema.type !== 'object' ? false : true) &&
|
|
@@ -190,6 +196,15 @@ export function TLiteral(schema) {
|
|
|
190
196
|
ValueGuard.IsNumber(schema.const) ||
|
|
191
197
|
ValueGuard.IsString(schema.const)));
|
|
192
198
|
}
|
|
199
|
+
export function TMappedKey(schema) {
|
|
200
|
+
return (TKindOf(schema, 'MappedKey') &&
|
|
201
|
+
ValueGuard.IsArray(schema.keys) &&
|
|
202
|
+
schema.keys.every(key => ValueGuard.IsNumber(key) || ValueGuard.IsString(key)));
|
|
203
|
+
}
|
|
204
|
+
export function TMappedResult(schema) {
|
|
205
|
+
return (TKindOf(schema, 'MappedResult') &&
|
|
206
|
+
TProperties(schema.properties));
|
|
207
|
+
}
|
|
193
208
|
export function TNever(schema) {
|
|
194
209
|
return (TKindOf(schema, 'Never') &&
|
|
195
210
|
ValueGuard.IsObject(schema.not) &&
|
|
@@ -218,8 +233,7 @@ export function TObject(schema) {
|
|
|
218
233
|
return (TKindOf(schema, 'Object') &&
|
|
219
234
|
schema.type === 'object' &&
|
|
220
235
|
IsOptionalString(schema.$id) &&
|
|
221
|
-
|
|
222
|
-
Object.entries(schema.properties).every(([key, schema]) => IsControlCharacterFree(key) && TSchema(schema)) &&
|
|
236
|
+
TProperties(schema.properties) &&
|
|
223
237
|
IsAdditionalProperties(schema.additionalProperties) &&
|
|
224
238
|
IsOptionalNumber(schema.minProperties) &&
|
|
225
239
|
IsOptionalNumber(schema.maxProperties));
|
|
@@ -343,6 +357,8 @@ export function TSchema(schema) {
|
|
|
343
357
|
TIntersect(schema) ||
|
|
344
358
|
TIterator(schema) ||
|
|
345
359
|
TLiteral(schema) ||
|
|
360
|
+
TMappedKey(schema) ||
|
|
361
|
+
TMappedResult(schema) ||
|
|
346
362
|
TNever(schema) ||
|
|
347
363
|
TNot(schema) ||
|
|
348
364
|
TNull(schema) ||
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type TSchema } from '../schema/index.mjs';
|
|
2
|
+
import { type TProperties } from '../object/index.mjs';
|
|
3
|
+
import { IndexedType } from './indexed-type.mjs';
|
|
4
|
+
import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
|
|
5
|
+
import { Evaluate } from '../helpers/index.mjs';
|
|
6
|
+
type MappedIndexPropertyKey<T extends TSchema, K extends PropertyKey> = {
|
|
7
|
+
[_ in K]: IndexedType<T, [K]>;
|
|
8
|
+
};
|
|
9
|
+
declare function MappedIndexPropertyKey<T extends TSchema, K extends PropertyKey>(T: T, K: K): MappedIndexPropertyKey<T, K>;
|
|
10
|
+
type MappedIndexPropertyKeys<T extends TSchema, K extends PropertyKey[]> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? MappedIndexPropertyKey<T, L> & MappedIndexPropertyKeys<T, R> : {});
|
|
11
|
+
declare function MappedIndexPropertyKeys<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): MappedIndexPropertyKeys<T, K>;
|
|
12
|
+
type MappedIndexProperties<T extends TSchema, K extends TMappedKey> = Evaluate<MappedIndexPropertyKeys<T, K['keys']>>;
|
|
13
|
+
declare function MappedIndexProperties<T extends TSchema, K extends TMappedKey>(T: T, K: K): MappedIndexProperties<T, K>;
|
|
14
|
+
export type TMappedIndex<T extends TSchema, K extends TMappedKey, P extends TProperties = MappedIndexProperties<T, K>> = TMappedResult<P>;
|
|
15
|
+
export declare function MappedIndex<T extends TSchema, K extends TMappedKey, P extends TProperties = MappedIndexProperties<T, K>>(T: T, K: K): TMappedResult<P>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IndexedType } from './indexed-type.mjs';
|
|
2
|
+
import { MappedResult } from '../mapped/index.mjs';
|
|
3
|
+
function MappedIndexPropertyKey(T, K) {
|
|
4
|
+
return { [K]: IndexedType(T, [K]) };
|
|
5
|
+
}
|
|
6
|
+
function MappedIndexPropertyKeys(T, K) {
|
|
7
|
+
const [L, ...R] = K;
|
|
8
|
+
return (K.length > 0
|
|
9
|
+
? { ...MappedIndexPropertyKey(T, L), ...MappedIndexPropertyKeys(T, R) }
|
|
10
|
+
: {});
|
|
11
|
+
}
|
|
12
|
+
function MappedIndexProperties(T, K) {
|
|
13
|
+
return MappedIndexPropertyKeys(T, K.keys);
|
|
14
|
+
}
|
|
15
|
+
export function MappedIndex(T, K) {
|
|
16
|
+
const P = MappedIndexProperties(T, K);
|
|
17
|
+
return MappedResult(P);
|
|
18
|
+
}
|
|
@@ -6,11 +6,11 @@ import { type TSchema } from '../schema/index.mjs';
|
|
|
6
6
|
import { type TUnion } from '../union/index.mjs';
|
|
7
7
|
type FromTemplateLiteral<T extends TTemplateLiteral, F = IsTemplateLiteralFinite<T>> = (F extends true ? TemplateLiteralGenerate<T> extends infer R extends string[] ? R : [] : []);
|
|
8
8
|
declare function FromTemplateLiteral<T extends TTemplateLiteral>(T: T): FromTemplateLiteral<T>;
|
|
9
|
-
type FromUnion<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [...
|
|
9
|
+
type FromUnion<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [...IndexedPropertyKeys<L>, ...FromUnion<R>] : []);
|
|
10
10
|
declare function FromUnion<T extends TSchema[]>(T: T): FromUnion<T>;
|
|
11
11
|
type FromLiteral<T extends TLiteralValue> = (T extends PropertyKey ? [`${T}`] : []);
|
|
12
12
|
declare function FromLiteral<T extends TLiteralValue>(T: T): FromLiteral<T>;
|
|
13
|
-
export type
|
|
13
|
+
export type IndexedPropertyKeys<T extends TSchema> = (T extends TTemplateLiteral ? FromTemplateLiteral<T> : T extends TUnion<infer S> ? FromUnion<S> : T extends TLiteral<infer S> ? FromLiteral<S> : T extends TNumber ? ['[number]'] : T extends TInteger ? ['[number]'] : [
|
|
14
14
|
]);
|
|
15
|
-
export declare function
|
|
15
|
+
export declare function IndexedPropertyKeys<T extends TSchema>(T: T): IndexedPropertyKeys<T>;
|
|
16
16
|
export {};
|
|
@@ -13,13 +13,13 @@ function FromTemplateLiteral(T) {
|
|
|
13
13
|
function FromUnion(T) {
|
|
14
14
|
const [L, ...R] = T;
|
|
15
15
|
return (T.length > 0
|
|
16
|
-
? [...
|
|
16
|
+
? [...IndexedPropertyKeys(L), ...FromUnion(R)]
|
|
17
17
|
: []);
|
|
18
18
|
}
|
|
19
19
|
function FromLiteral(T) {
|
|
20
20
|
return ([T.toString()]);
|
|
21
21
|
}
|
|
22
|
-
export function
|
|
22
|
+
export function IndexedPropertyKeys(T) {
|
|
23
23
|
return [...new Set((IsTemplateLiteralType(T) ? FromTemplateLiteral(T) :
|
|
24
24
|
IsUnionType(T) ? FromUnion(T.anyOf) :
|
|
25
25
|
IsLiteralType(T) ? FromLiteral(T.const) :
|
|
@@ -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
|
|
32
|
-
export declare function
|
|
31
|
+
export type IndexedType<T extends TSchema, K extends PropertyKey[]> = (UnionResolve<FromKeys<T, K>>);
|
|
32
|
+
export declare function IndexedType<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): IndexedType<T, K>;
|
|
33
33
|
export {};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { IndexedType } from './indexed-type.mjs';
|
|
3
|
+
import { IndexedPropertyKeys } from './indexed-property-keys.mjs';
|
|
4
|
+
import { type TMappedIndex } from './indexed-mapped.mjs';
|
|
5
|
+
import { TMappedKey } from '../mapped/index.mjs';
|
|
6
|
+
export type TIndex<T extends TSchema, K extends PropertyKey[]> = IndexedType<T, K>;
|
|
7
|
+
export declare function Index<T extends TSchema, K extends TMappedKey>(T: T, K: K): TMappedIndex<T, K>;
|
|
8
|
+
export declare function Index<T extends TSchema, K extends TSchema, I extends PropertyKey[] = IndexedPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TIndex<T, I>;
|
|
6
9
|
export declare function Index<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TIndex<T, K>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { TSchema as IsSchemaType, TMappedKey as IsMappedKey } from '../guard/type.mjs';
|
|
2
|
+
import { IndexedType } from './indexed-type.mjs';
|
|
3
|
+
import { IndexedPropertyKeys } from './indexed-property-keys.mjs';
|
|
4
|
+
import { MappedIndex } from './indexed-mapped.mjs';
|
|
3
5
|
import { CloneType } from '../clone/type.mjs';
|
|
4
|
-
import { TSchema as IsSchemaType } from '../guard/type.mjs';
|
|
5
6
|
export function Index(T, K, options = {}) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
return (IsMappedKey(K) ? CloneType(MappedIndex(T, K), options) :
|
|
8
|
+
IsSchemaType(K) ? CloneType(IndexedType(T, IndexedPropertyKeys(K)), options) :
|
|
9
|
+
CloneType(IndexedType(T, K), options));
|
|
9
10
|
}
|
|
@@ -7,7 +7,7 @@ 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
9
|
import { OperatorUnionMany, OperatorIntersectMany } from '../operators/index.mjs';
|
|
10
|
-
type FromRest<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [
|
|
10
|
+
type FromRest<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [KeyOfPropertyKeys<L>, ...FromRest<R>] : []);
|
|
11
11
|
declare function FromRest<T extends TSchema[]>(T: [...T]): FromRest<T>;
|
|
12
12
|
type FromIntersect<T extends TSchema[], C extends PropertyKey[][] = FromRest<T>> = (OperatorUnionMany<C>);
|
|
13
13
|
declare function FromIntersect<T extends TSchema[]>(T: [...T], C?: FromRest<T>): FromIntersect<T>;
|
|
@@ -21,8 +21,8 @@ type FromArray<_ extends TSchema> = ([
|
|
|
21
21
|
declare function FromArray<_ extends TSchema>(_: _): FromArray<_>;
|
|
22
22
|
type FromProperties<T extends TProperties> = (UnionToTuple<keyof T>);
|
|
23
23
|
declare function FromProperties<T extends TProperties>(T: T): FromProperties<T>;
|
|
24
|
-
export type
|
|
24
|
+
export type KeyOfPropertyKeys<T extends TSchema> = (T extends TRecursive<infer S> ? KeyOfPropertyKeys<S> : T extends TIntersect<infer S> ? FromIntersect<S> : T extends TUnion<infer S> ? FromUnion<S> : T extends TTuple<infer S> ? FromTuple<S> : T extends TArray<infer S> ? FromArray<S> : T extends TObject<infer S> ? FromProperties<S> : [
|
|
25
25
|
]);
|
|
26
|
-
export declare function
|
|
27
|
-
export declare function
|
|
26
|
+
export declare function KeyOfPropertyKeys<T extends TSchema>(T: T): KeyOfPropertyKeys<T>;
|
|
27
|
+
export declare function KeyOfPattern(schema: TSchema): string;
|
|
28
28
|
export {};
|
|
@@ -4,7 +4,7 @@ import { TIntersect as IsIntersectType, TUnion as IsUnionType, TTuple as IsTuple
|
|
|
4
4
|
function FromRest(T) {
|
|
5
5
|
const [L, ...R] = T;
|
|
6
6
|
return (T.length > 0
|
|
7
|
-
? [
|
|
7
|
+
? [KeyOfPropertyKeys(L), ...FromRest(R)]
|
|
8
8
|
: []);
|
|
9
9
|
}
|
|
10
10
|
function FromIntersect(T, C = FromRest(T)) {
|
|
@@ -36,7 +36,7 @@ function FromPatternProperties(patternProperties) {
|
|
|
36
36
|
: key;
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
export function
|
|
39
|
+
export function KeyOfPropertyKeys(T) {
|
|
40
40
|
return (IsIntersectType(T) ? FromIntersect(T.allOf) :
|
|
41
41
|
IsUnionType(T) ? FromUnion(T.anyOf) :
|
|
42
42
|
IsTupleType(T) ? FromTuple(T.items ?? []) :
|
|
@@ -46,9 +46,9 @@ export function KeyOfStringResolve(T) {
|
|
|
46
46
|
[]);
|
|
47
47
|
}
|
|
48
48
|
let includePatternProperties = false;
|
|
49
|
-
export function
|
|
49
|
+
export function KeyOfPattern(schema) {
|
|
50
50
|
includePatternProperties = true;
|
|
51
|
-
const keys =
|
|
51
|
+
const keys = KeyOfPropertyKeys(schema);
|
|
52
52
|
includePatternProperties = false;
|
|
53
53
|
const pattern = keys.map((key) => `(${key})`);
|
|
54
54
|
return `^(${pattern.join('|')})$`;
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import type { TSchema
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { TSchema } from '../schema/index.mjs';
|
|
2
|
+
import type { Ensure } from '../helpers/index.mjs';
|
|
3
|
+
import { type TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
4
|
+
import { type TNumber } from '../number/index.mjs';
|
|
5
|
+
import { type SchemaOptions } from '../schema/index.mjs';
|
|
6
|
+
import { KeyOfPropertyKeys } from './keyof-property-keys.mjs';
|
|
7
|
+
import { UnionResolve } from '../union/index.mjs';
|
|
8
|
+
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>] : []);
|
|
9
|
+
declare function FromLiterals<T extends TLiteralValue[]>(T: [...T]): FromLiterals<T>;
|
|
10
|
+
export type TKeyOf<T extends TSchema> = (Ensure<UnionResolve<FromLiterals<KeyOfPropertyKeys<T>>>>);
|
|
11
|
+
export declare function KeyOf<T extends TSchema>(T: T, options?: SchemaOptions): TKeyOf<T>;
|
|
12
|
+
export {};
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Literal } from '../literal/index.mjs';
|
|
2
|
+
import { Number } from '../number/index.mjs';
|
|
3
|
+
import { KeyOfPropertyKeys } from './keyof-property-keys.mjs';
|
|
4
|
+
import { UnionResolve } from '../union/index.mjs';
|
|
2
5
|
import { CloneType } from '../clone/type.mjs';
|
|
3
|
-
|
|
4
|
-
const
|
|
6
|
+
function FromLiterals(T) {
|
|
7
|
+
const [L, ...R] = T;
|
|
8
|
+
return (T.length > 0
|
|
9
|
+
? L === '[number]'
|
|
10
|
+
? [Number(), ...FromLiterals(R)]
|
|
11
|
+
: [Literal(L), ...FromLiterals(R)]
|
|
12
|
+
: []);
|
|
13
|
+
}
|
|
14
|
+
export function KeyOf(T, options = {}) {
|
|
15
|
+
const K = UnionResolve(FromLiterals(KeyOfPropertyKeys(T)));
|
|
5
16
|
return CloneType(K, options);
|
|
6
17
|
}
|