@sinclair/typebox 0.33.22 → 0.34.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/compiler/compiler.d.ts +2 -2
- package/build/cjs/compiler/compiler.js +13 -2
- package/build/cjs/errors/errors.js +7 -0
- package/build/cjs/index.d.ts +1 -2
- package/build/cjs/index.js +1 -2
- package/build/cjs/syntax/parse.d.ts +14 -15
- package/build/cjs/syntax/parse.js +6 -5
- package/build/cjs/syntax/runtime.d.ts +20 -4
- package/build/cjs/syntax/runtime.js +183 -28
- package/build/cjs/syntax/static.d.ts +107 -23
- package/build/cjs/type/array/array.d.ts +1 -1
- package/build/cjs/type/awaited/awaited.d.ts +8 -3
- package/build/cjs/type/awaited/awaited.js +20 -20
- package/build/cjs/type/computed/computed.d.ts +9 -0
- package/build/cjs/type/computed/computed.js +10 -0
- package/build/cjs/type/computed/index.d.ts +1 -0
- package/build/cjs/type/{deref → computed}/index.js +1 -1
- package/build/cjs/type/guard/kind.d.ts +12 -4
- package/build/cjs/type/guard/kind.js +15 -0
- package/build/cjs/type/guard/type.d.ts +9 -3
- package/build/cjs/type/guard/type.js +19 -0
- package/build/cjs/type/index.d.ts +1 -2
- package/build/cjs/type/index.js +1 -2
- package/build/cjs/type/indexed/indexed-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/indexed/indexed-from-mapped-key.js +10 -10
- package/build/cjs/type/indexed/indexed-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/indexed/indexed-from-mapped-result.js +11 -10
- package/build/cjs/type/indexed/indexed-property-keys.d.ts +6 -6
- package/build/cjs/type/indexed/indexed-property-keys.js +14 -14
- package/build/cjs/type/indexed/indexed.d.ts +34 -20
- package/build/cjs/type/indexed/indexed.js +59 -46
- package/build/cjs/type/intersect/intersect-evaluated.d.ts +6 -6
- package/build/cjs/type/intersect/intersect-evaluated.js +16 -16
- package/build/cjs/type/intersect/intersect.d.ts +2 -2
- package/build/cjs/type/intersect/intersect.js +6 -6
- package/build/cjs/type/keyof/keyof-from-mapped-result.d.ts +6 -6
- package/build/cjs/type/keyof/keyof-from-mapped-result.js +10 -10
- package/build/cjs/type/keyof/keyof-property-keys.d.ts +7 -7
- package/build/cjs/type/keyof/keyof-property-keys.js +22 -22
- package/build/cjs/type/keyof/keyof.d.ts +11 -6
- package/build/cjs/type/keyof/keyof.js +22 -13
- package/build/cjs/type/module/compute.d.ts +54 -0
- package/build/cjs/type/module/compute.js +154 -0
- package/build/cjs/type/module/index.d.ts +1 -0
- package/build/cjs/type/{strict → module}/index.js +1 -1
- package/build/cjs/type/module/infer.d.ts +43 -0
- package/build/cjs/type/module/infer.js +3 -0
- package/build/cjs/type/module/module.d.ts +27 -0
- package/build/cjs/type/module/module.js +37 -0
- package/build/cjs/type/not/not.d.ts +1 -1
- package/build/cjs/type/not/not.js +2 -2
- package/build/cjs/type/omit/omit-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/omit/omit-from-mapped-key.js +10 -12
- package/build/cjs/type/omit/omit-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/omit/omit-from-mapped-result.js +10 -10
- package/build/cjs/type/omit/omit.d.ts +26 -14
- package/build/cjs/type/omit/omit.js +46 -35
- package/build/cjs/type/partial/partial.d.ts +11 -7
- package/build/cjs/type/partial/partial.js +36 -24
- package/build/cjs/type/pick/pick-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/pick/pick-from-mapped-key.js +10 -10
- package/build/cjs/type/pick/pick-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/pick/pick-from-mapped-result.js +10 -10
- package/build/cjs/type/pick/pick.d.ts +25 -15
- package/build/cjs/type/pick/pick.js +47 -36
- package/build/cjs/type/record/record.d.ts +4 -2
- package/build/cjs/type/record/record.js +31 -28
- package/build/cjs/type/ref/ref.d.ts +4 -7
- package/build/cjs/type/ref/ref.js +3 -11
- package/build/cjs/type/required/required.d.ts +12 -8
- package/build/cjs/type/required/required.js +37 -25
- package/build/cjs/type/static/static.d.ts +1 -1
- package/build/cjs/type/tuple/tuple.d.ts +1 -1
- package/build/cjs/type/tuple/tuple.js +4 -4
- package/build/cjs/type/type/javascript.d.ts +10 -10
- package/build/cjs/type/type/javascript.js +6 -6
- package/build/cjs/type/type/json.d.ts +45 -68
- package/build/cjs/type/type/json.js +82 -98
- package/build/cjs/type/type/type.d.ts +1 -2
- package/build/cjs/type/type/type.js +55 -57
- package/build/cjs/type/union/union-evaluated.d.ts +6 -6
- package/build/cjs/type/union/union-evaluated.js +11 -10
- package/build/cjs/type/union/union.d.ts +1 -1
- package/build/cjs/type/union/union.js +4 -4
- package/build/cjs/value/cast/cast.js +8 -1
- package/build/cjs/value/check/check.js +11 -4
- package/build/cjs/value/clean/clean.js +8 -1
- package/build/cjs/value/convert/convert.js +7 -0
- package/build/cjs/value/create/create.js +7 -0
- package/build/cjs/value/default/default.js +7 -0
- package/build/cjs/value/transform/decode.js +18 -7
- package/build/cjs/value/transform/encode.js +18 -7
- package/build/cjs/value/transform/has.js +18 -18
- package/build/esm/compiler/compiler.d.mts +2 -2
- package/build/esm/compiler/compiler.mjs +13 -2
- package/build/esm/errors/errors.mjs +7 -0
- package/build/esm/index.d.mts +1 -2
- package/build/esm/index.mjs +1 -2
- package/build/esm/syntax/parse.d.mts +14 -15
- package/build/esm/syntax/parse.mjs +6 -5
- package/build/esm/syntax/runtime.d.mts +20 -4
- package/build/esm/syntax/runtime.mjs +183 -28
- package/build/esm/syntax/static.d.mts +107 -23
- package/build/esm/type/array/array.d.mts +1 -1
- package/build/esm/type/awaited/awaited.d.mts +8 -3
- package/build/esm/type/awaited/awaited.mjs +20 -20
- package/build/esm/type/computed/computed.d.mts +9 -0
- package/build/esm/type/computed/computed.mjs +6 -0
- package/build/esm/type/computed/index.d.mts +1 -0
- package/build/esm/type/computed/index.mjs +1 -0
- package/build/esm/type/guard/kind.d.mts +12 -4
- package/build/esm/type/guard/kind.mjs +12 -0
- package/build/esm/type/guard/type.d.mts +9 -3
- package/build/esm/type/guard/type.mjs +17 -0
- package/build/esm/type/index.d.mts +1 -2
- package/build/esm/type/index.mjs +1 -2
- package/build/esm/type/indexed/indexed-from-mapped-key.d.mts +6 -6
- package/build/esm/type/indexed/indexed-from-mapped-key.mjs +10 -10
- package/build/esm/type/indexed/indexed-from-mapped-result.d.mts +5 -5
- package/build/esm/type/indexed/indexed-from-mapped-result.mjs +11 -10
- package/build/esm/type/indexed/indexed-property-keys.d.mts +6 -6
- package/build/esm/type/indexed/indexed-property-keys.mjs +14 -14
- package/build/esm/type/indexed/indexed.d.mts +34 -20
- package/build/esm/type/indexed/indexed.mjs +55 -42
- package/build/esm/type/intersect/intersect-evaluated.d.mts +6 -6
- package/build/esm/type/intersect/intersect-evaluated.mjs +16 -16
- package/build/esm/type/intersect/intersect.d.mts +2 -2
- package/build/esm/type/intersect/intersect.mjs +6 -6
- package/build/esm/type/keyof/keyof-from-mapped-result.d.mts +6 -6
- package/build/esm/type/keyof/keyof-from-mapped-result.mjs +10 -10
- package/build/esm/type/keyof/keyof-property-keys.d.mts +7 -7
- package/build/esm/type/keyof/keyof-property-keys.mjs +22 -22
- package/build/esm/type/keyof/keyof.d.mts +11 -6
- package/build/esm/type/keyof/keyof.mjs +22 -13
- package/build/esm/type/module/compute.d.mts +54 -0
- package/build/esm/type/module/compute.mjs +148 -0
- package/build/esm/type/module/index.d.mts +1 -0
- package/build/esm/type/module/index.mjs +1 -0
- package/build/esm/type/module/infer.d.mts +43 -0
- package/build/esm/type/module/infer.mjs +1 -0
- package/build/esm/type/module/module.d.mts +27 -0
- package/build/esm/type/module/module.mjs +31 -0
- package/build/esm/type/not/not.d.mts +1 -1
- package/build/esm/type/not/not.mjs +2 -2
- package/build/esm/type/omit/omit-from-mapped-key.d.mts +6 -6
- package/build/esm/type/omit/omit-from-mapped-key.mjs +10 -12
- package/build/esm/type/omit/omit-from-mapped-result.d.mts +5 -5
- package/build/esm/type/omit/omit-from-mapped-result.mjs +10 -10
- package/build/esm/type/omit/omit.d.mts +26 -14
- package/build/esm/type/omit/omit.mjs +43 -32
- package/build/esm/type/partial/partial.d.mts +11 -7
- package/build/esm/type/partial/partial.mjs +29 -17
- package/build/esm/type/pick/pick-from-mapped-key.d.mts +6 -6
- package/build/esm/type/pick/pick-from-mapped-key.mjs +10 -10
- package/build/esm/type/pick/pick-from-mapped-result.d.mts +5 -5
- package/build/esm/type/pick/pick-from-mapped-result.mjs +10 -10
- package/build/esm/type/pick/pick.d.mts +25 -15
- package/build/esm/type/pick/pick.mjs +43 -32
- package/build/esm/type/record/record.d.mts +4 -2
- package/build/esm/type/record/record.mjs +15 -12
- package/build/esm/type/ref/ref.d.mts +4 -7
- package/build/esm/type/ref/ref.mjs +3 -11
- package/build/esm/type/required/required.d.mts +12 -8
- package/build/esm/type/required/required.mjs +33 -21
- package/build/esm/type/static/static.d.mts +1 -1
- package/build/esm/type/tuple/tuple.d.mts +1 -1
- package/build/esm/type/tuple/tuple.mjs +4 -4
- package/build/esm/type/type/javascript.d.mts +10 -10
- package/build/esm/type/type/javascript.mjs +6 -6
- package/build/esm/type/type/json.d.mts +45 -68
- package/build/esm/type/type/json.mjs +47 -63
- package/build/esm/type/type/type.d.mts +1 -2
- package/build/esm/type/type/type.mjs +1 -2
- package/build/esm/type/union/union-evaluated.d.mts +6 -6
- package/build/esm/type/union/union-evaluated.mjs +11 -10
- package/build/esm/type/union/union.d.mts +1 -1
- package/build/esm/type/union/union.mjs +4 -4
- package/build/esm/value/cast/cast.mjs +9 -2
- package/build/esm/value/check/check.mjs +11 -4
- package/build/esm/value/clean/clean.mjs +9 -2
- package/build/esm/value/convert/convert.mjs +7 -0
- package/build/esm/value/create/create.mjs +7 -0
- package/build/esm/value/default/default.mjs +7 -0
- package/build/esm/value/transform/decode.mjs +13 -2
- package/build/esm/value/transform/encode.mjs +13 -2
- package/build/esm/value/transform/has.mjs +2 -2
- package/package.json +1 -1
- package/readme.md +230 -97
- package/build/cjs/type/deref/deref.d.ts +0 -22
- package/build/cjs/type/deref/deref.js +0 -106
- package/build/cjs/type/deref/index.d.ts +0 -1
- package/build/cjs/type/strict/index.d.ts +0 -1
- package/build/cjs/type/strict/strict.d.ts +0 -12
- package/build/cjs/type/strict/strict.js +0 -16
- package/build/esm/type/deref/deref.d.mts +0 -22
- package/build/esm/type/deref/deref.mjs +0 -102
- package/build/esm/type/deref/index.d.mts +0 -1
- package/build/esm/type/deref/index.mjs +0 -1
- package/build/esm/type/strict/index.d.mts +0 -1
- package/build/esm/type/strict/index.mjs +0 -1
- package/build/esm/type/strict/strict.d.mts +0 -12
- package/build/esm/type/strict/strict.mjs +0 -12
|
@@ -3,10 +3,10 @@ import type { TProperties } from '../object/index';
|
|
|
3
3
|
import { type TMappedResult } from '../mapped/index';
|
|
4
4
|
import { type TIndexPropertyKeys } from './indexed-property-keys';
|
|
5
5
|
import { type TIndex } from './index';
|
|
6
|
-
type TFromProperties<
|
|
7
|
-
[K2 in keyof
|
|
6
|
+
type TFromProperties<Type extends TSchema, Properties extends TProperties> = ({
|
|
7
|
+
[K2 in keyof Properties]: TIndex<Type, TIndexPropertyKeys<Properties[K2]>>;
|
|
8
8
|
});
|
|
9
|
-
type TFromMappedResult<
|
|
10
|
-
export type TIndexFromMappedResult<
|
|
11
|
-
export declare function IndexFromMappedResult<
|
|
9
|
+
type TFromMappedResult<Type extends TSchema, MappedResult extends TMappedResult> = (TFromProperties<Type, MappedResult['properties']>);
|
|
10
|
+
export type TIndexFromMappedResult<Type extends TSchema, MappedResult extends TMappedResult, Properties extends TProperties = TFromMappedResult<Type, MappedResult>> = (TMappedResult<Properties>);
|
|
11
|
+
export declare function IndexFromMappedResult<Type extends TSchema, MappedResult extends TMappedResult, Properties extends TProperties = TFromMappedResult<Type, MappedResult>>(type: Type, mappedResult: MappedResult, options?: SchemaOptions): TMappedResult<Properties>;
|
|
12
12
|
export {};
|
|
@@ -6,19 +6,20 @@ const index_1 = require("../mapped/index");
|
|
|
6
6
|
const indexed_property_keys_1 = require("./indexed-property-keys");
|
|
7
7
|
const index_2 = require("./index");
|
|
8
8
|
// prettier-ignore
|
|
9
|
-
function FromProperties(
|
|
10
|
-
const
|
|
11
|
-
for (const K2 of Object.getOwnPropertyNames(
|
|
12
|
-
|
|
9
|
+
function FromProperties(type, properties, options) {
|
|
10
|
+
const result = {};
|
|
11
|
+
for (const K2 of Object.getOwnPropertyNames(properties)) {
|
|
12
|
+
const keys = (0, indexed_property_keys_1.IndexPropertyKeys)(properties[K2]);
|
|
13
|
+
result[K2] = (0, index_2.Index)(type, keys, options);
|
|
13
14
|
}
|
|
14
|
-
return
|
|
15
|
+
return result;
|
|
15
16
|
}
|
|
16
17
|
// prettier-ignore
|
|
17
|
-
function FromMappedResult(
|
|
18
|
-
return FromProperties(
|
|
18
|
+
function FromMappedResult(type, mappedResult, options) {
|
|
19
|
+
return FromProperties(type, mappedResult.properties, options);
|
|
19
20
|
}
|
|
20
21
|
// prettier-ignore
|
|
21
|
-
function IndexFromMappedResult(
|
|
22
|
-
const
|
|
23
|
-
return (0, index_1.MappedResult)(
|
|
22
|
+
function IndexFromMappedResult(type, mappedResult, options) {
|
|
23
|
+
const properties = FromMappedResult(type, mappedResult, options);
|
|
24
|
+
return (0, index_1.MappedResult)(properties);
|
|
24
25
|
}
|
|
@@ -4,11 +4,11 @@ import type { TInteger } from '../integer/index';
|
|
|
4
4
|
import type { TNumber } from '../number/index';
|
|
5
5
|
import type { TSchema } from '../schema/index';
|
|
6
6
|
import type { TUnion } from '../union/index';
|
|
7
|
-
type TFromTemplateLiteral<
|
|
8
|
-
type TFromUnion<
|
|
9
|
-
type TFromLiteral<
|
|
10
|
-
export type TIndexPropertyKeys<
|
|
11
|
-
]);
|
|
7
|
+
type TFromTemplateLiteral<TemplateLiteral extends TTemplateLiteral, Result extends string[] = TTemplateLiteralGenerate<TemplateLiteral>> = Result;
|
|
8
|
+
type TFromUnion<Types extends TSchema[], Result extends string[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromUnion<Right, [...Result, ...TIndexPropertyKeys<Left>]> : Result);
|
|
9
|
+
type TFromLiteral<LiteralValue extends TLiteralValue> = (LiteralValue extends PropertyKey ? [`${LiteralValue}`] : []);
|
|
10
|
+
export type TIndexPropertyKeys<Type extends TSchema, Result extends PropertyKey[] = (Type extends TTemplateLiteral ? TFromTemplateLiteral<Type> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type extends TLiteral<infer LiteralValue extends TLiteralValue> ? TFromLiteral<LiteralValue> : Type extends TNumber ? ['[number]'] : Type extends TInteger ? ['[number]'] : [
|
|
11
|
+
])> = Result;
|
|
12
12
|
/** Returns a tuple of PropertyKeys derived from the given TSchema */
|
|
13
|
-
export declare function IndexPropertyKeys<
|
|
13
|
+
export declare function IndexPropertyKeys<Type extends TSchema>(type: Type): TIndexPropertyKeys<Type>;
|
|
14
14
|
export {};
|
|
@@ -8,16 +8,16 @@ const index_1 = require("../template-literal/index");
|
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
9
|
const kind_1 = require("../guard/kind");
|
|
10
10
|
// prettier-ignore
|
|
11
|
-
function FromTemplateLiteral(
|
|
12
|
-
const
|
|
13
|
-
return
|
|
11
|
+
function FromTemplateLiteral(templateLiteral) {
|
|
12
|
+
const result = (0, index_1.TemplateLiteralGenerate)(templateLiteral);
|
|
13
|
+
return result.map(S => S.toString());
|
|
14
14
|
}
|
|
15
15
|
// prettier-ignore
|
|
16
|
-
function FromUnion(
|
|
17
|
-
const
|
|
18
|
-
for (const
|
|
19
|
-
|
|
20
|
-
return
|
|
16
|
+
function FromUnion(type) {
|
|
17
|
+
const result = [];
|
|
18
|
+
for (const left of type)
|
|
19
|
+
result.push(...IndexPropertyKeys(left));
|
|
20
|
+
return result;
|
|
21
21
|
}
|
|
22
22
|
// prettier-ignore
|
|
23
23
|
function FromLiteral(T) {
|
|
@@ -26,11 +26,11 @@ function FromLiteral(T) {
|
|
|
26
26
|
}
|
|
27
27
|
/** Returns a tuple of PropertyKeys derived from the given TSchema */
|
|
28
28
|
// prettier-ignore
|
|
29
|
-
function IndexPropertyKeys(
|
|
30
|
-
return [...new Set(((0, kind_1.IsTemplateLiteral)(
|
|
31
|
-
(0, kind_1.IsUnion)(
|
|
32
|
-
(0, kind_1.IsLiteral)(
|
|
33
|
-
(0, kind_1.IsNumber)(
|
|
34
|
-
(0, kind_1.IsInteger)(
|
|
29
|
+
function IndexPropertyKeys(type) {
|
|
30
|
+
return [...new Set(((0, kind_1.IsTemplateLiteral)(type) ? FromTemplateLiteral(type) :
|
|
31
|
+
(0, kind_1.IsUnion)(type) ? FromUnion(type.anyOf) :
|
|
32
|
+
(0, kind_1.IsLiteral)(type) ? FromLiteral(type.const) :
|
|
33
|
+
(0, kind_1.IsNumber)(type) ? ['[number]'] :
|
|
34
|
+
(0, kind_1.IsInteger)(type) ? ['[number]'] :
|
|
35
35
|
[]))];
|
|
36
36
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type TSchema, SchemaOptions } from '../schema/index';
|
|
2
|
+
import { type TComputed } from '../computed/index';
|
|
3
|
+
import { type TLiteral, type TLiteralValue } from '../literal/index';
|
|
2
4
|
import { type TObject, type TProperties } from '../object/index';
|
|
3
5
|
import { type Assert } from '../helpers/index';
|
|
4
6
|
import { type TNever } from '../never/index';
|
|
@@ -8,33 +10,45 @@ import { TMappedResult, type TMappedKey } from '../mapped/index';
|
|
|
8
10
|
import { type TUnion } from '../union/index';
|
|
9
11
|
import { type TTuple } from '../tuple/index';
|
|
10
12
|
import { type TArray } from '../array/index';
|
|
13
|
+
import { type TRef } from '../ref/index';
|
|
11
14
|
import { type TIntersectEvaluated } from '../intersect/index';
|
|
12
15
|
import { type TUnionEvaluated } from '../union/index';
|
|
13
16
|
import { type TIndexPropertyKeys } from './indexed-property-keys';
|
|
14
17
|
import { type TIndexFromMappedKey } from './indexed-from-mapped-key';
|
|
15
18
|
import { type TIndexFromMappedResult } from './indexed-from-mapped-result';
|
|
16
|
-
type TFromRest<T extends TSchema[], K extends PropertyKey,
|
|
17
|
-
type TFromIntersectRest<
|
|
18
|
-
type TFromIntersect<
|
|
19
|
-
type TFromUnionRest<
|
|
20
|
-
type TFromUnion<
|
|
21
|
-
type TFromTuple<
|
|
22
|
-
type TFromArray<
|
|
23
|
-
type AssertPropertyKey<T> = Assert<T, string | number>;
|
|
24
|
-
type TFromProperty<
|
|
25
|
-
export type TIndexFromPropertyKey<
|
|
26
|
-
export declare function IndexFromPropertyKey<
|
|
27
|
-
export type TIndexFromPropertyKeys<
|
|
28
|
-
export declare function IndexFromPropertyKeys<
|
|
29
|
-
type
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
type TFromRest<T extends TSchema[], K extends PropertyKey, Result extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, K, [...Result, Assert<TIndexFromPropertyKey<L, K>, TSchema>]> : Result);
|
|
20
|
+
type TFromIntersectRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TNever ? TFromIntersectRest<Right, [...Result]> : TFromIntersectRest<Right, [...Result, Left]> : Result);
|
|
21
|
+
type TFromIntersect<Types extends TSchema[], Key extends PropertyKey> = (TIntersectEvaluated<TFromIntersectRest<TFromRest<Types, Key>>>);
|
|
22
|
+
type TFromUnionRest<Types extends TSchema[], Result extends TSchema[] = []> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TNever ? [] : TFromUnionRest<Right, [Left, ...Result]> : Result;
|
|
23
|
+
type TFromUnion<Types extends TSchema[], Key extends PropertyKey> = (TUnionEvaluated<TFromUnionRest<TFromRest<Types, Key>>>);
|
|
24
|
+
type TFromTuple<Types extends TSchema[], Key extends PropertyKey, Result extends TSchema = (Key extends '[number]' ? TUnionEvaluated<Types> : Key extends keyof Types ? Types[Key] extends infer Type extends TSchema ? Type : TNever : TNever)> = Result;
|
|
25
|
+
type TFromArray<Type extends TSchema, Key extends PropertyKey> = (Key extends '[number]' ? Type : TNever);
|
|
26
|
+
type AssertPropertyKey<T extends unknown> = Assert<T, string | number>;
|
|
27
|
+
type TFromProperty<Properties extends TProperties, Key extends PropertyKey, Result extends TSchema = (Key extends keyof Properties ? Properties[Key] : `${AssertPropertyKey<Key>}` extends `${AssertPropertyKey<keyof Properties>}` ? Properties[AssertPropertyKey<Key>] : TNever)> = Result;
|
|
28
|
+
export type TIndexFromPropertyKey<Type extends TSchema, Key extends PropertyKey> = (Type extends TRecursive<infer S extends TSchema> ? TIndexFromPropertyKey<S, Key> : Type extends TIntersect<infer S extends TSchema[]> ? TFromIntersect<S, Key> : Type extends TUnion<infer S extends TSchema[]> ? TFromUnion<S, Key> : Type extends TTuple<infer S extends TSchema[]> ? TFromTuple<S, Key> : Type extends TArray<infer S extends TSchema> ? TFromArray<S, Key> : Type extends TObject<infer S extends TProperties> ? TFromProperty<S, Key> : TNever);
|
|
29
|
+
export declare function IndexFromPropertyKey<Type extends TSchema, Key extends PropertyKey>(type: Type, key: Key): TIndexFromPropertyKey<Type, Key>;
|
|
30
|
+
export type TIndexFromPropertyKeys<Type extends TSchema, PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = (PropertyKeys extends [infer Left extends PropertyKey, ...infer Right extends PropertyKey[]] ? TIndexFromPropertyKeys<Type, Right, [...Result, Assert<TIndexFromPropertyKey<Type, Left>, TSchema>]> : Result);
|
|
31
|
+
export declare function IndexFromPropertyKeys<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, propertyKeys: [...PropertyKeys]): TIndexFromPropertyKeys<Type, PropertyKeys>;
|
|
32
|
+
type TFromType<Type extends TSchema, PropertyKeys extends PropertyKey[], Result extends TSchema[] = TIndexFromPropertyKeys<Type, PropertyKeys>> = TUnionEvaluated<Result>;
|
|
33
|
+
type TUnionFromPropertyKeys<PropertyKeys extends PropertyKey[], Result extends TLiteral[] = []> = (PropertyKeys extends [infer Key extends PropertyKey, ...infer Rest extends PropertyKey[]] ? Key extends TLiteralValue ? TUnionFromPropertyKeys<Rest, [...Result, TLiteral<Key>]> : TUnionFromPropertyKeys<Rest, [...Result]> : TUnionEvaluated<Result>);
|
|
34
|
+
type TResolvePropertyKeys<Key extends TSchema | PropertyKey[]> = Key extends TSchema ? TIndexPropertyKeys<Key> : Key;
|
|
35
|
+
type TResolveTypeKey<Key extends TSchema | PropertyKey[]> = Key extends PropertyKey[] ? TUnionFromPropertyKeys<Key> : Key;
|
|
36
|
+
export type TIndex<Type extends TSchema, Key extends TSchema | PropertyKey[], IsTypeRef extends boolean = Type extends TRef ? true : false, IsKeyRef extends boolean = Key extends TRef ? true : false> = (Key extends TMappedResult ? TIndexFromMappedResult<Type, Key> : Key extends TMappedKey ? TIndexFromMappedKey<Type, Key> : [
|
|
37
|
+
IsTypeRef,
|
|
38
|
+
IsKeyRef
|
|
39
|
+
] extends [true, true] ? TComputed<'Index', [Type, TResolveTypeKey<Key>]> : [
|
|
40
|
+
IsTypeRef,
|
|
41
|
+
IsKeyRef
|
|
42
|
+
] extends [false, true] ? TComputed<'Index', [Type, TResolveTypeKey<Key>]> : [
|
|
43
|
+
IsTypeRef,
|
|
44
|
+
IsKeyRef
|
|
45
|
+
] extends [true, false] ? TComputed<'Index', [Type, TResolveTypeKey<Key>]> : TFromType<Type, TResolvePropertyKeys<Key>>);
|
|
32
46
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
33
|
-
export declare function Index<
|
|
47
|
+
export declare function Index<Type extends TSchema, Key extends PropertyKey[]>(type: Type, key: readonly [...Key], options?: SchemaOptions): TIndex<Type, Key>;
|
|
34
48
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
35
|
-
export declare function Index<
|
|
49
|
+
export declare function Index<Type extends TSchema, Key extends TMappedKey>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
|
|
36
50
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
37
|
-
export declare function Index<
|
|
51
|
+
export declare function Index<Type extends TSchema, Key extends TMappedResult>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
|
|
38
52
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
39
|
-
export declare function Index<
|
|
53
|
+
export declare function Index<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
|
|
40
54
|
export {};
|
|
@@ -5,80 +5,93 @@ exports.IndexFromPropertyKey = IndexFromPropertyKey;
|
|
|
5
5
|
exports.IndexFromPropertyKeys = IndexFromPropertyKeys;
|
|
6
6
|
exports.Index = Index;
|
|
7
7
|
const type_1 = require("../create/type");
|
|
8
|
-
const index_1 = require("../
|
|
9
|
-
const index_2 = require("../
|
|
10
|
-
const index_3 = require("../
|
|
8
|
+
const index_1 = require("../computed/index");
|
|
9
|
+
const index_2 = require("../literal/index");
|
|
10
|
+
const index_3 = require("../never/index");
|
|
11
|
+
const index_4 = require("../intersect/index");
|
|
12
|
+
const index_5 = require("../union/index");
|
|
13
|
+
// ------------------------------------------------------------------
|
|
14
|
+
// Infrastructure
|
|
15
|
+
// ------------------------------------------------------------------
|
|
11
16
|
const indexed_property_keys_1 = require("./indexed-property-keys");
|
|
12
17
|
const indexed_from_mapped_key_1 = require("./indexed-from-mapped-key");
|
|
13
18
|
const indexed_from_mapped_result_1 = require("./indexed-from-mapped-result");
|
|
14
19
|
// ------------------------------------------------------------------
|
|
15
|
-
//
|
|
20
|
+
// KindGuard
|
|
16
21
|
// ------------------------------------------------------------------
|
|
17
22
|
const kind_1 = require("../guard/kind");
|
|
23
|
+
const value_1 = require("../guard/value");
|
|
18
24
|
// prettier-ignore
|
|
19
|
-
function FromRest(
|
|
20
|
-
return
|
|
25
|
+
function FromRest(types, key) {
|
|
26
|
+
return types.map(left => IndexFromPropertyKey(left, key));
|
|
21
27
|
}
|
|
22
28
|
// prettier-ignore
|
|
23
|
-
function FromIntersectRest(
|
|
24
|
-
return
|
|
29
|
+
function FromIntersectRest(types) {
|
|
30
|
+
return types.filter(left => !(0, kind_1.IsNever)(left));
|
|
25
31
|
}
|
|
26
32
|
// prettier-ignore
|
|
27
|
-
function FromIntersect(
|
|
28
|
-
return ((0,
|
|
33
|
+
function FromIntersect(types, key) {
|
|
34
|
+
return ((0, index_4.IntersectEvaluated)(FromIntersectRest(FromRest(types, key))));
|
|
29
35
|
}
|
|
30
36
|
// prettier-ignore
|
|
31
|
-
function FromUnionRest(
|
|
32
|
-
return (
|
|
37
|
+
function FromUnionRest(types) {
|
|
38
|
+
return (types.some(L => (0, kind_1.IsNever)(L))
|
|
33
39
|
? []
|
|
34
|
-
:
|
|
40
|
+
: types);
|
|
35
41
|
}
|
|
36
42
|
// prettier-ignore
|
|
37
|
-
function FromUnion(
|
|
38
|
-
return ((0,
|
|
43
|
+
function FromUnion(types, key) {
|
|
44
|
+
return ((0, index_5.UnionEvaluated)(FromUnionRest(FromRest(types, key))));
|
|
39
45
|
}
|
|
40
46
|
// prettier-ignore
|
|
41
|
-
function FromTuple(
|
|
42
|
-
return (
|
|
43
|
-
|
|
44
|
-
(0,
|
|
47
|
+
function FromTuple(types, key) {
|
|
48
|
+
return (key === '[number]' ? (0, index_5.UnionEvaluated)(types) :
|
|
49
|
+
key in types ? types[key] :
|
|
50
|
+
(0, index_3.Never)());
|
|
45
51
|
}
|
|
46
52
|
// prettier-ignore
|
|
47
|
-
function FromArray(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
: (0, index_1.Never)());
|
|
53
|
+
function FromArray(type, key) {
|
|
54
|
+
// ... ?
|
|
55
|
+
return (key === '[number]' ? type : (0, index_3.Never)());
|
|
51
56
|
}
|
|
52
57
|
// prettier-ignore
|
|
53
|
-
function FromProperty(
|
|
54
|
-
return (
|
|
58
|
+
function FromProperty(properties, key) {
|
|
59
|
+
return (key in properties ? properties[key] : (0, index_3.Never)());
|
|
55
60
|
}
|
|
56
61
|
// prettier-ignore
|
|
57
|
-
function IndexFromPropertyKey(
|
|
58
|
-
return ((0, kind_1.IsIntersect)(
|
|
59
|
-
(0, kind_1.IsUnion)(
|
|
60
|
-
(0, kind_1.IsTuple)(
|
|
61
|
-
(0, kind_1.IsArray)(
|
|
62
|
-
(0, kind_1.IsObject)(
|
|
63
|
-
(0,
|
|
62
|
+
function IndexFromPropertyKey(type, key) {
|
|
63
|
+
return ((0, kind_1.IsIntersect)(type) ? FromIntersect(type.allOf, key) :
|
|
64
|
+
(0, kind_1.IsUnion)(type) ? FromUnion(type.anyOf, key) :
|
|
65
|
+
(0, kind_1.IsTuple)(type) ? FromTuple(type.items ?? [], key) :
|
|
66
|
+
(0, kind_1.IsArray)(type) ? FromArray(type.items, key) :
|
|
67
|
+
(0, kind_1.IsObject)(type) ? FromProperty(type.properties, key) :
|
|
68
|
+
(0, index_3.Never)());
|
|
64
69
|
}
|
|
65
70
|
// prettier-ignore
|
|
66
|
-
function IndexFromPropertyKeys(
|
|
67
|
-
return
|
|
71
|
+
function IndexFromPropertyKeys(type, propertyKeys) {
|
|
72
|
+
return propertyKeys.map(left => IndexFromPropertyKey(type, left));
|
|
68
73
|
}
|
|
69
74
|
// prettier-ignore
|
|
70
|
-
function
|
|
71
|
-
|
|
75
|
+
function FromType(type, propertyKeys) {
|
|
76
|
+
const result = IndexFromPropertyKeys(type, propertyKeys);
|
|
77
|
+
return (0, index_5.UnionEvaluated)(result);
|
|
78
|
+
}
|
|
79
|
+
// prettier-ignore
|
|
80
|
+
function UnionFromPropertyKeys(propertyKeys) {
|
|
81
|
+
const result = propertyKeys.reduce((result, key) => (0, kind_1.IsLiteralValue)(key) ? [...result, (0, index_2.Literal)(key)] : result, []);
|
|
82
|
+
return (0, index_5.UnionEvaluated)(result);
|
|
72
83
|
}
|
|
73
84
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
85
|
+
// prettier-ignore
|
|
86
|
+
function Index(type, key, options) {
|
|
87
|
+
const typeKey = (0, value_1.IsArray)(key) ? UnionFromPropertyKeys(key) : key;
|
|
88
|
+
const propertyKeys = (0, kind_1.IsSchema)(key) ? (0, indexed_property_keys_1.IndexPropertyKeys)(key) : key;
|
|
89
|
+
const isTypeRef = (0, kind_1.IsRef)(type);
|
|
90
|
+
const isKeyRef = (0, kind_1.IsRef)(key);
|
|
91
|
+
return ((0, kind_1.IsMappedResult)(key) ? (0, indexed_from_mapped_result_1.IndexFromMappedResult)(type, key, options) :
|
|
92
|
+
(0, kind_1.IsMappedKey)(key) ? (0, indexed_from_mapped_key_1.IndexFromMappedKey)(type, key, options) :
|
|
93
|
+
(isTypeRef && isKeyRef) ? (0, index_1.Computed)('Index', [type, typeKey], options) :
|
|
94
|
+
(!isTypeRef && isKeyRef) ? (0, index_1.Computed)('Index', [type, typeKey], options) :
|
|
95
|
+
(isTypeRef && !isKeyRef) ? (0, index_1.Computed)('Index', [type, typeKey], options) :
|
|
96
|
+
(0, type_1.CreateType)(FromType(type, propertyKeys), options));
|
|
84
97
|
}
|
|
@@ -3,11 +3,11 @@ import { type TNever } from '../never/index';
|
|
|
3
3
|
import { type TOptional } from '../optional/index';
|
|
4
4
|
import type { TReadonly } from '../readonly/index';
|
|
5
5
|
import { TIntersect, IntersectOptions } from './intersect-type';
|
|
6
|
-
type TIsIntersectOptional<
|
|
7
|
-
type TRemoveOptionalFromType<
|
|
8
|
-
type TRemoveOptionalFromRest<
|
|
9
|
-
type TResolveIntersect<
|
|
10
|
-
export type TIntersectEvaluated<
|
|
6
|
+
type TIsIntersectOptional<Types extends TSchema[]> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TOptional<TSchema> ? TIsIntersectOptional<Right> : false : true);
|
|
7
|
+
type TRemoveOptionalFromType<Type extends TSchema> = (Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TRemoveOptionalFromType<Type>> : Type extends TOptional<infer Type extends TSchema> ? TRemoveOptionalFromType<Type> : Type);
|
|
8
|
+
type TRemoveOptionalFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TOptional<infer Type extends TSchema> ? TRemoveOptionalFromRest<Right, [...Result, TRemoveOptionalFromType<Type>]> : TRemoveOptionalFromRest<Right, [...Result, Left]> : Result);
|
|
9
|
+
type TResolveIntersect<Types extends TSchema[]> = (TIsIntersectOptional<Types> extends true ? TOptional<TIntersect<TRemoveOptionalFromRest<Types>>> : TIntersect<TRemoveOptionalFromRest<Types>>);
|
|
10
|
+
export type TIntersectEvaluated<Types extends TSchema[]> = (Types extends [TSchema] ? Types[0] : Types extends [] ? TNever : TResolveIntersect<Types>);
|
|
11
11
|
/** `[Json]` Creates an evaluated Intersect type */
|
|
12
|
-
export declare function IntersectEvaluated<
|
|
12
|
+
export declare function IntersectEvaluated<Types extends TSchema[], Result extends TSchema = TIntersectEvaluated<Types>>(types: [...Types], options?: IntersectOptions): Result;
|
|
13
13
|
export {};
|
|
@@ -13,30 +13,30 @@ const intersect_create_1 = require("./intersect-create");
|
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
14
|
const kind_1 = require("../guard/kind");
|
|
15
15
|
// prettier-ignore
|
|
16
|
-
function IsIntersectOptional(
|
|
17
|
-
return
|
|
16
|
+
function IsIntersectOptional(types) {
|
|
17
|
+
return types.every(left => (0, kind_1.IsOptional)(left));
|
|
18
18
|
}
|
|
19
19
|
// prettier-ignore
|
|
20
|
-
function RemoveOptionalFromType(
|
|
21
|
-
return ((0, index_2.Discard)(
|
|
20
|
+
function RemoveOptionalFromType(type) {
|
|
21
|
+
return ((0, index_2.Discard)(type, [index_1.OptionalKind]));
|
|
22
22
|
}
|
|
23
23
|
// prettier-ignore
|
|
24
|
-
function RemoveOptionalFromRest(
|
|
25
|
-
return
|
|
24
|
+
function RemoveOptionalFromRest(types) {
|
|
25
|
+
return types.map(left => (0, kind_1.IsOptional)(left) ? RemoveOptionalFromType(left) : left);
|
|
26
26
|
}
|
|
27
27
|
// prettier-ignore
|
|
28
|
-
function ResolveIntersect(
|
|
29
|
-
return (IsIntersectOptional(
|
|
30
|
-
? (0, index_4.Optional)((0, intersect_create_1.IntersectCreate)(RemoveOptionalFromRest(
|
|
31
|
-
: (0, intersect_create_1.IntersectCreate)(RemoveOptionalFromRest(
|
|
28
|
+
function ResolveIntersect(types, options) {
|
|
29
|
+
return (IsIntersectOptional(types)
|
|
30
|
+
? (0, index_4.Optional)((0, intersect_create_1.IntersectCreate)(RemoveOptionalFromRest(types), options))
|
|
31
|
+
: (0, intersect_create_1.IntersectCreate)(RemoveOptionalFromRest(types), options));
|
|
32
32
|
}
|
|
33
33
|
/** `[Json]` Creates an evaluated Intersect type */
|
|
34
|
-
function IntersectEvaluated(
|
|
35
|
-
if (
|
|
34
|
+
function IntersectEvaluated(types, options = {}) {
|
|
35
|
+
if (types.length === 1)
|
|
36
|
+
return (0, type_1.CreateType)(types[0], options);
|
|
37
|
+
if (types.length === 0)
|
|
36
38
|
return (0, index_3.Never)(options);
|
|
37
|
-
if (
|
|
38
|
-
return (0, type_1.CreateType)(T[0], options);
|
|
39
|
-
if (T.some((schema) => (0, kind_1.IsTransform)(schema)))
|
|
39
|
+
if (types.some((schema) => (0, kind_1.IsTransform)(schema)))
|
|
40
40
|
throw new Error('Cannot intersect transform types');
|
|
41
|
-
return ResolveIntersect(
|
|
41
|
+
return ResolveIntersect(types, options);
|
|
42
42
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TSchema } from '../schema/index';
|
|
2
2
|
import { type TNever } from '../never/index';
|
|
3
3
|
import { TIntersect, IntersectOptions } from './intersect-type';
|
|
4
|
-
export type Intersect<
|
|
4
|
+
export type Intersect<Types extends TSchema[]> = (Types extends [TSchema] ? Types[0] : Types extends [] ? TNever : TIntersect<Types>);
|
|
5
5
|
/** `[Json]` Creates an evaluated Intersect type */
|
|
6
|
-
export declare function Intersect<
|
|
6
|
+
export declare function Intersect<Types extends TSchema[]>(types: [...Types], options?: IntersectOptions): Intersect<Types>;
|
|
@@ -10,12 +10,12 @@ const intersect_create_1 = require("./intersect-create");
|
|
|
10
10
|
// ------------------------------------------------------------------
|
|
11
11
|
const kind_1 = require("../guard/kind");
|
|
12
12
|
/** `[Json]` Creates an evaluated Intersect type */
|
|
13
|
-
function Intersect(
|
|
14
|
-
if (
|
|
13
|
+
function Intersect(types, options) {
|
|
14
|
+
if (types.length === 1)
|
|
15
|
+
return (0, type_1.CreateType)(types[0], options);
|
|
16
|
+
if (types.length === 0)
|
|
15
17
|
return (0, index_1.Never)(options);
|
|
16
|
-
if (
|
|
17
|
-
return (0, type_1.CreateType)(T[0], options);
|
|
18
|
-
if (T.some((schema) => (0, kind_1.IsTransform)(schema)))
|
|
18
|
+
if (types.some((schema) => (0, kind_1.IsTransform)(schema)))
|
|
19
19
|
throw new Error('Cannot intersect transform types');
|
|
20
|
-
return (0, intersect_create_1.IntersectCreate)(
|
|
20
|
+
return (0, intersect_create_1.IntersectCreate)(types, options);
|
|
21
21
|
}
|
|
@@ -2,11 +2,11 @@ import type { SchemaOptions } from '../schema/index';
|
|
|
2
2
|
import type { Ensure, Evaluate } from '../helpers/index';
|
|
3
3
|
import type { TProperties } from '../object/index';
|
|
4
4
|
import { type TMappedResult } from '../mapped/index';
|
|
5
|
-
import { type
|
|
6
|
-
type TFromProperties<
|
|
7
|
-
[K2 in keyof
|
|
5
|
+
import { type TKeyOfFromType } from './keyof';
|
|
6
|
+
type TFromProperties<Properties extends TProperties> = ({
|
|
7
|
+
[K2 in keyof Properties]: TKeyOfFromType<Properties[K2]>;
|
|
8
8
|
});
|
|
9
|
-
type TFromMappedResult<
|
|
10
|
-
export type TKeyOfFromMappedResult<
|
|
11
|
-
export declare function KeyOfFromMappedResult<
|
|
9
|
+
type TFromMappedResult<MappedResult extends TMappedResult> = (Evaluate<TFromProperties<MappedResult['properties']>>);
|
|
10
|
+
export type TKeyOfFromMappedResult<MappedResult extends TMappedResult, Properties extends TProperties = TFromMappedResult<MappedResult>> = (Ensure<TMappedResult<Properties>>);
|
|
11
|
+
export declare function KeyOfFromMappedResult<MappedResult extends TMappedResult, Properties extends TProperties = TFromMappedResult<MappedResult>>(mappedResult: MappedResult, options?: SchemaOptions): TMappedResult<Properties>;
|
|
12
12
|
export {};
|
|
@@ -6,18 +6,18 @@ const index_1 = require("../mapped/index");
|
|
|
6
6
|
const keyof_1 = require("./keyof");
|
|
7
7
|
const value_1 = require("../clone/value");
|
|
8
8
|
// prettier-ignore
|
|
9
|
-
function FromProperties(
|
|
10
|
-
const
|
|
11
|
-
for (const K2 of globalThis.Object.getOwnPropertyNames(
|
|
12
|
-
|
|
13
|
-
return
|
|
9
|
+
function FromProperties(properties, options) {
|
|
10
|
+
const result = {};
|
|
11
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
|
|
12
|
+
result[K2] = (0, keyof_1.KeyOf)(properties[K2], (0, value_1.Clone)(options));
|
|
13
|
+
return result;
|
|
14
14
|
}
|
|
15
15
|
// prettier-ignore
|
|
16
|
-
function FromMappedResult(
|
|
17
|
-
return FromProperties(
|
|
16
|
+
function FromMappedResult(mappedResult, options) {
|
|
17
|
+
return FromProperties(mappedResult.properties, options);
|
|
18
18
|
}
|
|
19
19
|
// prettier-ignore
|
|
20
|
-
function KeyOfFromMappedResult(
|
|
21
|
-
const
|
|
22
|
-
return (0, index_1.MappedResult)(
|
|
20
|
+
function KeyOfFromMappedResult(mappedResult, options) {
|
|
21
|
+
const properties = FromMappedResult(mappedResult, options);
|
|
22
|
+
return (0, index_1.MappedResult)(properties);
|
|
23
23
|
}
|
|
@@ -7,18 +7,18 @@ import type { TTuple } from '../tuple/index';
|
|
|
7
7
|
import type { TArray } from '../array/index';
|
|
8
8
|
import type { TObject, TProperties } from '../object/index';
|
|
9
9
|
import { type TSetUnionMany, type TSetIntersectMany } from '../sets/index';
|
|
10
|
-
type TFromRest<
|
|
11
|
-
type TFromIntersect<
|
|
12
|
-
type TFromUnion<
|
|
13
|
-
type TFromTuple<
|
|
10
|
+
type TFromRest<Types extends TSchema[], Result extends PropertyKey[][] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Result, TKeyOfPropertyKeys<L>]> : Result);
|
|
11
|
+
type TFromIntersect<Types extends TSchema[], PropertyKeysArray extends PropertyKey[][] = TFromRest<Types>, PropertyKeys extends PropertyKey[] = TSetUnionMany<PropertyKeysArray>> = PropertyKeys;
|
|
12
|
+
type TFromUnion<Types extends TSchema[], PropertyKeysArray extends PropertyKey[][] = TFromRest<Types>, PropertyKeys extends PropertyKey[] = TSetIntersectMany<PropertyKeysArray>> = PropertyKeys;
|
|
13
|
+
type TFromTuple<Types extends TSchema[], Indexer extends string = ZeroString, Acc extends PropertyKey[] = []> = Types extends [infer _ extends TSchema, ...infer R extends TSchema[]] ? TFromTuple<R, TIncrement<Indexer>, [...Acc, Indexer]> : Acc;
|
|
14
14
|
type TFromArray<_ extends TSchema> = ([
|
|
15
15
|
'[number]'
|
|
16
16
|
]);
|
|
17
|
-
type TFromProperties<
|
|
18
|
-
export type TKeyOfPropertyKeys<
|
|
17
|
+
type TFromProperties<Properties extends TProperties> = (UnionToTuple<keyof Properties>);
|
|
18
|
+
export type TKeyOfPropertyKeys<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TKeyOfPropertyKeys<Type> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Types> : Type extends TArray<infer Type extends TSchema> ? TFromArray<Type> : Type extends TObject<infer Properties extends TProperties> ? TFromProperties<Properties> : [
|
|
19
19
|
]);
|
|
20
20
|
/** Returns a tuple of PropertyKeys derived from the given TSchema. */
|
|
21
|
-
export declare function KeyOfPropertyKeys<
|
|
21
|
+
export declare function KeyOfPropertyKeys<Type extends TSchema>(type: Type): TKeyOfPropertyKeys<Type>;
|
|
22
22
|
/** Returns a regular expression pattern derived from the given TSchema */
|
|
23
23
|
export declare function KeyOfPattern(schema: TSchema): string;
|
|
24
24
|
export {};
|
|
@@ -9,27 +9,27 @@ const index_1 = require("../sets/index");
|
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
const kind_1 = require("../guard/kind");
|
|
11
11
|
// prettier-ignore
|
|
12
|
-
function FromRest(
|
|
13
|
-
const
|
|
14
|
-
for (const L of
|
|
15
|
-
|
|
16
|
-
return
|
|
12
|
+
function FromRest(types) {
|
|
13
|
+
const result = [];
|
|
14
|
+
for (const L of types)
|
|
15
|
+
result.push(KeyOfPropertyKeys(L));
|
|
16
|
+
return result;
|
|
17
17
|
}
|
|
18
18
|
// prettier-ignore
|
|
19
|
-
function FromIntersect(
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
return
|
|
19
|
+
function FromIntersect(types) {
|
|
20
|
+
const propertyKeysArray = FromRest(types);
|
|
21
|
+
const propertyKeys = (0, index_1.SetUnionMany)(propertyKeysArray);
|
|
22
|
+
return propertyKeys;
|
|
23
23
|
}
|
|
24
24
|
// prettier-ignore
|
|
25
|
-
function FromUnion(
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
return
|
|
25
|
+
function FromUnion(types) {
|
|
26
|
+
const propertyKeysArray = FromRest(types);
|
|
27
|
+
const propertyKeys = (0, index_1.SetIntersectMany)(propertyKeysArray);
|
|
28
|
+
return propertyKeys;
|
|
29
29
|
}
|
|
30
30
|
// prettier-ignore
|
|
31
|
-
function FromTuple(
|
|
32
|
-
return
|
|
31
|
+
function FromTuple(types) {
|
|
32
|
+
return types.map((_, indexer) => indexer.toString());
|
|
33
33
|
}
|
|
34
34
|
// prettier-ignore
|
|
35
35
|
function FromArray(_) {
|
|
@@ -55,13 +55,13 @@ function FromPatternProperties(patternProperties) {
|
|
|
55
55
|
}
|
|
56
56
|
/** Returns a tuple of PropertyKeys derived from the given TSchema. */
|
|
57
57
|
// prettier-ignore
|
|
58
|
-
function KeyOfPropertyKeys(
|
|
59
|
-
return ((0, kind_1.IsIntersect)(
|
|
60
|
-
(0, kind_1.IsUnion)(
|
|
61
|
-
(0, kind_1.IsTuple)(
|
|
62
|
-
(0, kind_1.IsArray)(
|
|
63
|
-
(0, kind_1.IsObject)(
|
|
64
|
-
(0, kind_1.IsRecord)(
|
|
58
|
+
function KeyOfPropertyKeys(type) {
|
|
59
|
+
return ((0, kind_1.IsIntersect)(type) ? FromIntersect(type.allOf) :
|
|
60
|
+
(0, kind_1.IsUnion)(type) ? FromUnion(type.anyOf) :
|
|
61
|
+
(0, kind_1.IsTuple)(type) ? FromTuple(type.items ?? []) :
|
|
62
|
+
(0, kind_1.IsArray)(type) ? FromArray(type.items) :
|
|
63
|
+
(0, kind_1.IsObject)(type) ? FromProperties(type.properties) :
|
|
64
|
+
(0, kind_1.IsRecord)(type) ? FromPatternProperties(type.patternProperties) :
|
|
65
65
|
[]);
|
|
66
66
|
}
|
|
67
67
|
// ----------------------------------------------------------------
|