@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
|
@@ -4,13 +4,18 @@ import type { TMappedResult } from '../mapped/index';
|
|
|
4
4
|
import type { SchemaOptions } from '../schema/index';
|
|
5
5
|
import { type TLiteral, type TLiteralValue } from '../literal/index';
|
|
6
6
|
import { type TNumber } from '../number/index';
|
|
7
|
+
import { TComputed } from '../computed/index';
|
|
8
|
+
import { type TRef } from '../ref/index';
|
|
7
9
|
import { type TKeyOfPropertyKeys } from './keyof-property-keys';
|
|
8
10
|
import { type TUnionEvaluated } from '../union/index';
|
|
9
11
|
import { type TKeyOfFromMappedResult } from './keyof-from-mapped-result';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
type TFromComputed<Target extends string, Parameters extends TSchema[]> = Ensure<TComputed<'KeyOf', [TComputed<Target, Parameters>]>>;
|
|
13
|
+
type TFromRef<Ref extends string> = Ensure<TComputed<'KeyOf', [TRef<Ref>]>>;
|
|
14
|
+
/** `[Internal]` Used by KeyOfFromMappedResult */
|
|
15
|
+
export type TKeyOfFromType<Type extends TSchema, PropertyKeys extends PropertyKey[] = TKeyOfPropertyKeys<Type>, PropertyKeyTypes extends TSchema[] = TKeyOfPropertyKeysToRest<PropertyKeys>, Result = TUnionEvaluated<PropertyKeyTypes>> = Ensure<Result>;
|
|
16
|
+
export type TKeyOfPropertyKeysToRest<PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = (PropertyKeys extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? L extends '[number]' ? TKeyOfPropertyKeysToRest<R, [...Result, TNumber]> : TKeyOfPropertyKeysToRest<R, [...Result, TLiteral<Assert<L, TLiteralValue>>]> : Result);
|
|
17
|
+
export declare function KeyOfPropertyKeysToRest<PropertyKeys extends PropertyKey[]>(propertyKeys: [...PropertyKeys]): TKeyOfPropertyKeysToRest<PropertyKeys>;
|
|
18
|
+
export type TKeyOf<Type extends TSchema> = (Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TMappedResult ? TKeyOfFromMappedResult<Type> : TKeyOfFromType<Type>);
|
|
13
19
|
/** `[Json]` Creates a KeyOf type */
|
|
14
|
-
export declare function KeyOf<
|
|
15
|
-
|
|
16
|
-
export declare function KeyOf<T extends TSchema>(T: T, options?: SchemaOptions): TKeyOf<T>;
|
|
20
|
+
export declare function KeyOf<Type extends TSchema>(type: Type, options?: SchemaOptions): TKeyOf<Type>;
|
|
21
|
+
export {};
|
|
@@ -6,26 +6,35 @@ exports.KeyOf = KeyOf;
|
|
|
6
6
|
const type_1 = require("../create/type");
|
|
7
7
|
const index_1 = require("../literal/index");
|
|
8
8
|
const index_2 = require("../number/index");
|
|
9
|
+
const index_3 = require("../computed/index");
|
|
10
|
+
const index_4 = require("../ref/index");
|
|
9
11
|
const keyof_property_keys_1 = require("./keyof-property-keys");
|
|
10
|
-
const
|
|
12
|
+
const index_5 = require("../union/index");
|
|
11
13
|
const keyof_from_mapped_result_1 = require("./keyof-from-mapped-result");
|
|
12
14
|
// ------------------------------------------------------------------
|
|
13
15
|
// TypeGuard
|
|
14
16
|
// ------------------------------------------------------------------
|
|
15
17
|
const kind_1 = require("../guard/kind");
|
|
16
18
|
// prettier-ignore
|
|
17
|
-
function
|
|
18
|
-
return
|
|
19
|
+
function FromComputed(target, parameters) {
|
|
20
|
+
return (0, index_3.Computed)('KeyOf', [(0, index_3.Computed)(target, parameters)]);
|
|
21
|
+
}
|
|
22
|
+
// prettier-ignore
|
|
23
|
+
function FromRef($ref) {
|
|
24
|
+
return (0, index_3.Computed)('KeyOf', [(0, index_4.Ref)($ref)]);
|
|
25
|
+
}
|
|
26
|
+
// prettier-ignore
|
|
27
|
+
function KeyOfFromType(type, options) {
|
|
28
|
+
const propertyKeys = (0, keyof_property_keys_1.KeyOfPropertyKeys)(type);
|
|
29
|
+
const propertyKeyTypes = KeyOfPropertyKeysToRest(propertyKeys);
|
|
30
|
+
const result = (0, index_5.UnionEvaluated)(propertyKeyTypes);
|
|
31
|
+
return (0, type_1.CreateType)(result, options);
|
|
32
|
+
}
|
|
33
|
+
// prettier-ignore
|
|
34
|
+
function KeyOfPropertyKeysToRest(propertyKeys) {
|
|
35
|
+
return propertyKeys.map(L => L === '[number]' ? (0, index_2.Number)() : (0, index_1.Literal)(L));
|
|
19
36
|
}
|
|
20
37
|
/** `[Json]` Creates a KeyOf type */
|
|
21
|
-
function KeyOf(
|
|
22
|
-
|
|
23
|
-
return (0, keyof_from_mapped_result_1.KeyOfFromMappedResult)(T, options);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
const K = (0, keyof_property_keys_1.KeyOfPropertyKeys)(T);
|
|
27
|
-
const S = KeyOfPropertyKeysToRest(K);
|
|
28
|
-
const U = (0, index_3.UnionEvaluated)(S);
|
|
29
|
-
return (0, type_1.CreateType)(U, options);
|
|
30
|
-
}
|
|
38
|
+
function KeyOf(type, options) {
|
|
39
|
+
return ((0, kind_1.IsComputed)(type) ? FromComputed(type.target, type.parameters) : (0, kind_1.IsRef)(type) ? FromRef(type.$ref) : (0, kind_1.IsMappedResult)(type) ? (0, keyof_from_mapped_result_1.KeyOfFromMappedResult)(type, options) : KeyOfFromType(type, options));
|
|
31
40
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Ensure, Evaluate } from '../helpers/index';
|
|
2
|
+
import { type TSchema } from '../schema/index';
|
|
3
|
+
import { type TArray } from '../array/index';
|
|
4
|
+
import { type TAwaited } from '../awaited/index';
|
|
5
|
+
import { type TAsyncIterator } from '../async-iterator/index';
|
|
6
|
+
import { TComputed } from '../computed/index';
|
|
7
|
+
import { type TConstructor } from '../constructor/index';
|
|
8
|
+
import { type TIndex } from '../indexed/index';
|
|
9
|
+
import { type TFunction } from '../function/index';
|
|
10
|
+
import { type TIntersect, type TIntersectEvaluated } from '../intersect/index';
|
|
11
|
+
import { type TIterator } from '../iterator/index';
|
|
12
|
+
import { type TKeyOf } from '../keyof/index';
|
|
13
|
+
import { type TObject, type TProperties } from '../object/index';
|
|
14
|
+
import { type TOmit } from '../omit/index';
|
|
15
|
+
import { type TPick } from '../pick/index';
|
|
16
|
+
import { type TNever } from '../never/index';
|
|
17
|
+
import { TPartial } from '../partial/index';
|
|
18
|
+
import { type TRecordOrObject } from '../record/index';
|
|
19
|
+
import { type TRef } from '../ref/index';
|
|
20
|
+
import { TRequired } from '../required/index';
|
|
21
|
+
import { type TTuple } from '../tuple/index';
|
|
22
|
+
import { type TUnion, type TUnionEvaluated } from '../union/index';
|
|
23
|
+
type TDerefParameters<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TRef<infer Key extends string> ? TDerefParameters<ModuleProperties, Right, [...Result, TDeref<ModuleProperties, Key>]> : TDerefParameters<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
|
|
24
|
+
type TDeref<ModuleProperties extends TProperties, Ref extends string, Result extends TSchema = (Ref extends keyof ModuleProperties ? ModuleProperties[Ref] extends TRef<infer Ref2 extends string> ? TDeref<ModuleProperties, Ref2> : TFromType<ModuleProperties, ModuleProperties[Ref]> : TNever)> = Result;
|
|
25
|
+
type TFromAwaited<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TAwaited<T0> : never);
|
|
26
|
+
type TFromIndex<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TIndex<T0, T1> : never);
|
|
27
|
+
type TFromKeyOf<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TKeyOf<T0> : never);
|
|
28
|
+
type TFromPartial<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TPartial<T0> : never);
|
|
29
|
+
type TFromOmit<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TOmit<T0, T1> : never);
|
|
30
|
+
type TFromPick<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TPick<T0, T1> : never);
|
|
31
|
+
type TFromRecord<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TRecordOrObject<T0, T1> : never);
|
|
32
|
+
type TFromRequired<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TRequired<T0> : never);
|
|
33
|
+
type TFromComputed<ModuleProperties extends TProperties, Target extends string, Parameters extends TSchema[], Dereferenced extends TSchema[] = TDerefParameters<ModuleProperties, Parameters>> = (Target extends 'Awaited' ? TFromAwaited<Dereferenced> : Target extends 'Index' ? TFromIndex<Dereferenced> : Target extends 'KeyOf' ? TFromKeyOf<Dereferenced> : Target extends 'Partial' ? TFromPartial<Dereferenced> : Target extends 'Omit' ? TFromOmit<Dereferenced> : Target extends 'Pick' ? TFromPick<Dereferenced> : Target extends 'Record' ? TFromRecord<Dereferenced> : Target extends 'Required' ? TFromRequired<Dereferenced> : TNever);
|
|
34
|
+
type TFromObject<ModuleProperties extends TProperties, Properties extends TProperties> = Ensure<TObject<Evaluate<{
|
|
35
|
+
[Key in keyof Properties]: TFromType<ModuleProperties, Properties[Key]>;
|
|
36
|
+
}>>>;
|
|
37
|
+
type TFromConstructor<ModuleProperties extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema> = (TConstructor<TFromRest<ModuleProperties, Parameters>, TFromType<ModuleProperties, InstanceType>>);
|
|
38
|
+
type TFromFunction<ModuleProperties extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema> = Ensure<Ensure<TFunction<TFromRest<ModuleProperties, Parameters>, TFromType<ModuleProperties, ReturnType>>>>;
|
|
39
|
+
type TFromTuple<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TTuple<TFromRest<ModuleProperties, Types>>>);
|
|
40
|
+
type TFromIntersect<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TIntersectEvaluated<TFromRest<ModuleProperties, Types>>>);
|
|
41
|
+
type TFromUnion<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TUnionEvaluated<TFromRest<ModuleProperties, Types>>>);
|
|
42
|
+
type TFromArray<ModuleProperties extends TProperties, Type extends TSchema> = (Ensure<TArray<TFromType<ModuleProperties, Type>>>);
|
|
43
|
+
type TFromAsyncIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TAsyncIterator<TFromType<ModuleProperties, Type>>);
|
|
44
|
+
type TFromIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TIterator<TFromType<ModuleProperties, Type>>);
|
|
45
|
+
type TFromRest<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromRest<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
|
|
46
|
+
export type TFromType<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TComputed<infer T extends string, infer S extends TSchema[]> ? TFromComputed<ModuleProperties, T, S> : Type extends TObject<infer S extends TProperties> ? TFromObject<ModuleProperties, S> : Type extends TConstructor<infer S extends TSchema[], infer R extends TSchema> ? TFromConstructor<ModuleProperties, S, R> : Type extends TFunction<infer S extends TSchema[], infer R extends TSchema> ? TFromFunction<ModuleProperties, S, R> : Type extends TTuple<infer S extends TSchema[]> ? TFromTuple<ModuleProperties, S> : Type extends TIntersect<infer S extends TSchema[]> ? TFromIntersect<ModuleProperties, S> : Type extends TUnion<infer S extends TSchema[]> ? TFromUnion<ModuleProperties, S> : Type extends TArray<infer S extends TSchema> ? TFromArray<ModuleProperties, S> : Type extends TAsyncIterator<infer S extends TSchema> ? TFromAsyncIterator<ModuleProperties, S> : Type extends TIterator<infer S extends TSchema> ? TFromIterator<ModuleProperties, S> : Type);
|
|
47
|
+
export declare function FromType<ModuleProperties extends TProperties, Type extends TSchema>(moduleProperties: ModuleProperties, type: Type): TFromType<ModuleProperties, Type>;
|
|
48
|
+
export type TComputeType<ModuleProperties extends TProperties, Key extends PropertyKey> = (Key extends keyof ModuleProperties ? TFromType<ModuleProperties, ModuleProperties[Key]> : TNever);
|
|
49
|
+
export declare function ComputeType<ModuleProperties extends TProperties, Key extends PropertyKey>(moduleProperties: ModuleProperties, key: Key): TComputeType<ModuleProperties, Key>;
|
|
50
|
+
export type TComputeModuleProperties<ModuleProperties extends TProperties> = Evaluate<{
|
|
51
|
+
[Key in keyof ModuleProperties]: TComputeType<ModuleProperties, Key>;
|
|
52
|
+
}>;
|
|
53
|
+
export declare function ComputeModuleProperties<ModuleProperties extends TProperties>(moduleProperties: ModuleProperties): TComputeModuleProperties<ModuleProperties>;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.FromType = FromType;
|
|
5
|
+
exports.ComputeType = ComputeType;
|
|
6
|
+
exports.ComputeModuleProperties = ComputeModuleProperties;
|
|
7
|
+
const index_1 = require("../create/index");
|
|
8
|
+
const index_2 = require("../array/index");
|
|
9
|
+
const index_3 = require("../awaited/index");
|
|
10
|
+
const index_4 = require("../async-iterator/index");
|
|
11
|
+
const index_5 = require("../constructor/index");
|
|
12
|
+
const index_6 = require("../indexed/index");
|
|
13
|
+
const index_7 = require("../function/index");
|
|
14
|
+
const index_8 = require("../intersect/index");
|
|
15
|
+
const index_9 = require("../iterator/index");
|
|
16
|
+
const index_10 = require("../keyof/index");
|
|
17
|
+
const index_11 = require("../object/index");
|
|
18
|
+
const index_12 = require("../omit/index");
|
|
19
|
+
const index_13 = require("../pick/index");
|
|
20
|
+
const index_14 = require("../never/index");
|
|
21
|
+
const index_15 = require("../partial/index");
|
|
22
|
+
const index_16 = require("../record/index");
|
|
23
|
+
const index_17 = require("../required/index");
|
|
24
|
+
const index_18 = require("../tuple/index");
|
|
25
|
+
const index_19 = require("../union/index");
|
|
26
|
+
// ------------------------------------------------------------------
|
|
27
|
+
// KindGuard
|
|
28
|
+
// ------------------------------------------------------------------
|
|
29
|
+
const KindGuard = require("../guard/kind");
|
|
30
|
+
// prettier-ignore
|
|
31
|
+
function DerefParameters(moduleProperties, types) {
|
|
32
|
+
return types.map((type) => {
|
|
33
|
+
return KindGuard.IsRef(type)
|
|
34
|
+
? Deref(moduleProperties, type.$ref)
|
|
35
|
+
: FromType(moduleProperties, type);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
// prettier-ignore
|
|
39
|
+
function Deref(moduleProperties, ref) {
|
|
40
|
+
return (ref in moduleProperties
|
|
41
|
+
? KindGuard.IsRef(moduleProperties[ref])
|
|
42
|
+
? Deref(moduleProperties, moduleProperties[ref].$ref)
|
|
43
|
+
: FromType(moduleProperties, moduleProperties[ref])
|
|
44
|
+
: (0, index_14.Never)());
|
|
45
|
+
}
|
|
46
|
+
// prettier-ignore
|
|
47
|
+
function FromAwaited(parameters) {
|
|
48
|
+
return (0, index_3.Awaited)(parameters[0]);
|
|
49
|
+
}
|
|
50
|
+
// prettier-ignore
|
|
51
|
+
function FromIndex(parameters) {
|
|
52
|
+
return (0, index_6.Index)(parameters[0], parameters[1]);
|
|
53
|
+
}
|
|
54
|
+
// prettier-ignore
|
|
55
|
+
function FromKeyOf(parameters) {
|
|
56
|
+
return (0, index_10.KeyOf)(parameters[0]);
|
|
57
|
+
}
|
|
58
|
+
// prettier-ignore
|
|
59
|
+
function FromPartial(parameters) {
|
|
60
|
+
return (0, index_15.Partial)(parameters[0]);
|
|
61
|
+
}
|
|
62
|
+
// prettier-ignore
|
|
63
|
+
function FromOmit(parameters) {
|
|
64
|
+
return (0, index_12.Omit)(parameters[0], parameters[1]);
|
|
65
|
+
}
|
|
66
|
+
// prettier-ignore
|
|
67
|
+
function FromPick(parameters) {
|
|
68
|
+
return (0, index_13.Pick)(parameters[0], parameters[1]);
|
|
69
|
+
}
|
|
70
|
+
// prettier-ignore
|
|
71
|
+
function FromRecord(parameters) {
|
|
72
|
+
return (0, index_16.Record)(parameters[0], parameters[1]);
|
|
73
|
+
}
|
|
74
|
+
// prettier-ignore
|
|
75
|
+
function FromRequired(parameters) {
|
|
76
|
+
return (0, index_17.Required)(parameters[0]);
|
|
77
|
+
}
|
|
78
|
+
// prettier-ignore
|
|
79
|
+
function FromComputed(moduleProperties, target, parameters) {
|
|
80
|
+
const dereferenced = DerefParameters(moduleProperties, parameters);
|
|
81
|
+
return (target === 'Awaited' ? FromAwaited(dereferenced) :
|
|
82
|
+
target === 'Index' ? FromIndex(dereferenced) :
|
|
83
|
+
target === 'KeyOf' ? FromKeyOf(dereferenced) :
|
|
84
|
+
target === 'Partial' ? FromPartial(dereferenced) :
|
|
85
|
+
target === 'Omit' ? FromOmit(dereferenced) :
|
|
86
|
+
target === 'Pick' ? FromPick(dereferenced) :
|
|
87
|
+
target === 'Record' ? FromRecord(dereferenced) :
|
|
88
|
+
target === 'Required' ? FromRequired(dereferenced) :
|
|
89
|
+
(0, index_14.Never)());
|
|
90
|
+
}
|
|
91
|
+
function FromObject(moduleProperties, properties) {
|
|
92
|
+
return (0, index_11.Object)(globalThis.Object.keys(properties).reduce((result, key) => {
|
|
93
|
+
return { ...result, [key]: FromType(moduleProperties, properties[key]) };
|
|
94
|
+
}, {}));
|
|
95
|
+
}
|
|
96
|
+
// prettier-ignore
|
|
97
|
+
function FromConstructor(moduleProperties, parameters, instanceType) {
|
|
98
|
+
return (0, index_5.Constructor)(FromRest(moduleProperties, parameters), FromType(moduleProperties, instanceType));
|
|
99
|
+
}
|
|
100
|
+
// prettier-ignore
|
|
101
|
+
function FromFunction(moduleProperties, parameters, returnType) {
|
|
102
|
+
return (0, index_7.Function)(FromRest(moduleProperties, parameters), FromType(moduleProperties, returnType));
|
|
103
|
+
}
|
|
104
|
+
function FromTuple(moduleProperties, types) {
|
|
105
|
+
return (0, index_18.Tuple)(FromRest(moduleProperties, types));
|
|
106
|
+
}
|
|
107
|
+
function FromIntersect(moduleProperties, types) {
|
|
108
|
+
return (0, index_8.Intersect)(FromRest(moduleProperties, types));
|
|
109
|
+
}
|
|
110
|
+
function FromUnion(moduleProperties, types) {
|
|
111
|
+
return (0, index_19.Union)(FromRest(moduleProperties, types));
|
|
112
|
+
}
|
|
113
|
+
function FromArray(moduleProperties, type) {
|
|
114
|
+
return (0, index_2.Array)(FromType(moduleProperties, type));
|
|
115
|
+
}
|
|
116
|
+
function FromAsyncIterator(moduleProperties, type) {
|
|
117
|
+
return (0, index_4.AsyncIterator)(FromType(moduleProperties, type));
|
|
118
|
+
}
|
|
119
|
+
function FromIterator(moduleProperties, type) {
|
|
120
|
+
return (0, index_9.Iterator)(FromType(moduleProperties, type));
|
|
121
|
+
}
|
|
122
|
+
function FromRest(moduleProperties, types) {
|
|
123
|
+
return types.map((type) => FromType(moduleProperties, type));
|
|
124
|
+
}
|
|
125
|
+
// prettier-ignore
|
|
126
|
+
function FromType(moduleProperties, type) {
|
|
127
|
+
return (
|
|
128
|
+
// Note: The 'as never' is required due to excessive resolution of TIndex. In fact TIndex, TPick, TOmit and
|
|
129
|
+
// all need re-implementation to remove the PropertyKey[] selector. Reimplementation of these types should
|
|
130
|
+
// be a priority as there is a potential for the current inference to break on TS compiler changes.
|
|
131
|
+
KindGuard.IsComputed(type) ? (0, index_1.CreateType)(FromComputed(moduleProperties, type.target, type.parameters)) :
|
|
132
|
+
KindGuard.IsObject(type) ? (0, index_1.CreateType)(FromObject(moduleProperties, type.properties), type) :
|
|
133
|
+
KindGuard.IsConstructor(type) ? (0, index_1.CreateType)(FromConstructor(moduleProperties, type.parameters, type.returns), type) :
|
|
134
|
+
KindGuard.IsFunction(type) ? (0, index_1.CreateType)(FromFunction(moduleProperties, type.parameters, type.returns), type) :
|
|
135
|
+
KindGuard.IsTuple(type) ? (0, index_1.CreateType)(FromTuple(moduleProperties, type.items || []), type) :
|
|
136
|
+
KindGuard.IsIntersect(type) ? (0, index_1.CreateType)(FromIntersect(moduleProperties, type.allOf), type) :
|
|
137
|
+
KindGuard.IsUnion(type) ? (0, index_1.CreateType)(FromUnion(moduleProperties, type.anyOf), type) :
|
|
138
|
+
KindGuard.IsArray(type) ? (0, index_1.CreateType)(FromArray(moduleProperties, type.items), type) :
|
|
139
|
+
KindGuard.IsAsyncIterator(type) ? (0, index_1.CreateType)(FromAsyncIterator(moduleProperties, type.items), type) :
|
|
140
|
+
KindGuard.IsIterator(type) ? (0, index_1.CreateType)(FromIterator(moduleProperties, type.items), type) :
|
|
141
|
+
type);
|
|
142
|
+
}
|
|
143
|
+
// prettier-ignore
|
|
144
|
+
function ComputeType(moduleProperties, key) {
|
|
145
|
+
return (key in moduleProperties
|
|
146
|
+
? FromType(moduleProperties, moduleProperties[key])
|
|
147
|
+
: (0, index_14.Never)());
|
|
148
|
+
}
|
|
149
|
+
// prettier-ignore
|
|
150
|
+
function ComputeModuleProperties(moduleProperties) {
|
|
151
|
+
return globalThis.Object.getOwnPropertyNames(moduleProperties).reduce((result, key) => {
|
|
152
|
+
return { ...result, [key]: ComputeType(moduleProperties, key) };
|
|
153
|
+
}, {});
|
|
154
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './module';
|
|
@@ -15,4 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./module"), exports);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Ensure, Evaluate } from '../helpers/index';
|
|
2
|
+
import { TSchema } from '../schema/index';
|
|
3
|
+
import { TArray } from '../array/index';
|
|
4
|
+
import { TAsyncIterator } from '../async-iterator/index';
|
|
5
|
+
import { TConstructor } from '../constructor/index';
|
|
6
|
+
import { TFunction } from '../function/index';
|
|
7
|
+
import { TIntersect } from '../intersect/index';
|
|
8
|
+
import { TIterator } from '../iterator/index';
|
|
9
|
+
import { TObject, TProperties } from '../object/index';
|
|
10
|
+
import { TOptional } from '../optional/index';
|
|
11
|
+
import { TReadonly } from '../readonly/index';
|
|
12
|
+
import { TRef } from '../ref/index';
|
|
13
|
+
import { TTuple } from '../tuple/index';
|
|
14
|
+
import { TUnion } from '../union/index';
|
|
15
|
+
import { Static } from '../static/index';
|
|
16
|
+
type TInferArray<ModuleProperties extends TProperties, Type extends TSchema> = (Ensure<Array<TInfer<ModuleProperties, Type>>>);
|
|
17
|
+
type TInferAsyncIterator<ModuleProperties extends TProperties, Type extends TSchema> = (Ensure<AsyncIterableIterator<TInfer<ModuleProperties, Type>>>);
|
|
18
|
+
type TInferConstructor<ModuleProperties extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema> = Ensure<new (...args: TInferTuple<ModuleProperties, Parameters>) => TInfer<ModuleProperties, InstanceType>>;
|
|
19
|
+
type TInferFunction<ModuleProperties extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema> = Ensure<(...args: TInferTuple<ModuleProperties, Parameters>) => TInfer<ModuleProperties, ReturnType>>;
|
|
20
|
+
type TInferIterator<ModuleProperties extends TProperties, Type extends TSchema> = (Ensure<IterableIterator<TInfer<ModuleProperties, Type>>>);
|
|
21
|
+
type TInferIntersect<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown = unknown> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TInferIntersect<ModuleProperties, R, Result & TInfer<ModuleProperties, L>> : Result);
|
|
22
|
+
type ReadonlyOptionalPropertyKeys<Properties extends TProperties> = {
|
|
23
|
+
[K in keyof Properties]: Properties[K] extends TReadonly<TSchema> ? (Properties[K] extends TOptional<Properties[K]> ? K : never) : never;
|
|
24
|
+
}[keyof Properties];
|
|
25
|
+
type ReadonlyPropertyKeys<Source extends TProperties> = {
|
|
26
|
+
[K in keyof Source]: Source[K] extends TReadonly<TSchema> ? (Source[K] extends TOptional<Source[K]> ? never : K) : never;
|
|
27
|
+
}[keyof Source];
|
|
28
|
+
type OptionalPropertyKeys<Source extends TProperties> = {
|
|
29
|
+
[K in keyof Source]: Source[K] extends TOptional<TSchema> ? (Source[K] extends TReadonly<Source[K]> ? never : K) : never;
|
|
30
|
+
}[keyof Source];
|
|
31
|
+
type RequiredPropertyKeys<Source extends TProperties> = keyof Omit<Source, ReadonlyOptionalPropertyKeys<Source> | ReadonlyPropertyKeys<Source> | OptionalPropertyKeys<Source>>;
|
|
32
|
+
type InferPropertiesWithModifiers<Properties extends TProperties, Source extends Record<keyof any, unknown>> = Evaluate<(Readonly<Partial<Pick<Source, ReadonlyOptionalPropertyKeys<Properties>>>> & Readonly<Pick<Source, ReadonlyPropertyKeys<Properties>>> & Partial<Pick<Source, OptionalPropertyKeys<Properties>>> & Required<Pick<Source, RequiredPropertyKeys<Properties>>>)>;
|
|
33
|
+
type InferProperties<ModuleProperties extends TProperties, Properties extends TProperties> = InferPropertiesWithModifiers<Properties, {
|
|
34
|
+
[K in keyof Properties]: TInfer<ModuleProperties, Properties[K]>;
|
|
35
|
+
}>;
|
|
36
|
+
type TInferObject<ModuleProperties extends TProperties, Properties extends TProperties> = (InferProperties<ModuleProperties, Properties>);
|
|
37
|
+
type TInferTuple<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TInferTuple<ModuleProperties, R, [...Result, TInfer<ModuleProperties, L>]> : Result);
|
|
38
|
+
type TInferRef<ModuleProperties extends TProperties, Ref extends string> = (Ref extends keyof ModuleProperties ? TInfer<ModuleProperties, ModuleProperties[Ref]> : unknown);
|
|
39
|
+
type TInferUnion<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown = never> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TInferUnion<ModuleProperties, R, Result | TInfer<ModuleProperties, L>> : Result);
|
|
40
|
+
type TInfer<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TInferArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TInferAsyncIterator<ModuleProperties, Type> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TInferConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TInferFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TInferIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TInferIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TInferObject<ModuleProperties, Properties> : Type extends TRef<infer Ref extends string> ? TInferRef<ModuleProperties, Ref> : Type extends TTuple<infer Types extends TSchema[]> ? TInferTuple<ModuleProperties, Types> : Type extends TUnion<infer Types extends TSchema[]> ? TInferUnion<ModuleProperties, Types> : Static<Type>);
|
|
41
|
+
/** Inference Path for Imports. This type is used to compute TImport `static` */
|
|
42
|
+
export type TInferFromModuleKey<ModuleProperties extends TProperties, Key extends PropertyKey> = (Key extends keyof ModuleProperties ? TInfer<ModuleProperties, ModuleProperties[Key]> : never);
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Kind } from '../symbols/index';
|
|
2
|
+
import { SchemaOptions, TSchema } from '../schema/index';
|
|
3
|
+
import { TProperties } from '../object/index';
|
|
4
|
+
import { Static } from '../static/index';
|
|
5
|
+
import { TComputeModuleProperties } from './compute';
|
|
6
|
+
import { TInferFromModuleKey } from './infer';
|
|
7
|
+
export interface TDefinitions<ModuleProperties extends TProperties> extends TSchema {
|
|
8
|
+
static: {
|
|
9
|
+
[K in keyof ModuleProperties]: Static<ModuleProperties[K]>;
|
|
10
|
+
};
|
|
11
|
+
$defs: ModuleProperties;
|
|
12
|
+
}
|
|
13
|
+
export interface TImport<ModuleProperties extends TProperties = {}, Key extends keyof ModuleProperties = keyof ModuleProperties> extends TSchema {
|
|
14
|
+
[Kind]: 'Import';
|
|
15
|
+
static: TInferFromModuleKey<ModuleProperties, Key>;
|
|
16
|
+
$defs: ModuleProperties;
|
|
17
|
+
$ref: Key;
|
|
18
|
+
}
|
|
19
|
+
export declare class TModule<ModuleProperties extends TProperties, ComputedModuleProperties extends TProperties = TComputeModuleProperties<ModuleProperties>> {
|
|
20
|
+
private readonly $defs;
|
|
21
|
+
constructor($defs: ModuleProperties);
|
|
22
|
+
/** `[Json]` Imports a Type by Key. */
|
|
23
|
+
Import<Key extends keyof ComputedModuleProperties>(key: Key, options?: SchemaOptions): TImport<ComputedModuleProperties, Key>;
|
|
24
|
+
private WithIdentifiers;
|
|
25
|
+
}
|
|
26
|
+
/** `[Json]` Creates a Type Definition Module. */
|
|
27
|
+
export declare function Module<Properties extends TProperties>(properties: Properties): TModule<Properties>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.TModule = void 0;
|
|
5
|
+
exports.Module = Module;
|
|
6
|
+
const index_1 = require("../create/index");
|
|
7
|
+
const index_2 = require("../symbols/index");
|
|
8
|
+
// ------------------------------------------------------------------
|
|
9
|
+
// Module Infrastructure Types
|
|
10
|
+
// ------------------------------------------------------------------
|
|
11
|
+
const compute_1 = require("./compute");
|
|
12
|
+
// ------------------------------------------------------------------
|
|
13
|
+
// Module
|
|
14
|
+
// ------------------------------------------------------------------
|
|
15
|
+
// prettier-ignore
|
|
16
|
+
class TModule {
|
|
17
|
+
constructor($defs) {
|
|
18
|
+
const computed = (0, compute_1.ComputeModuleProperties)($defs);
|
|
19
|
+
const identified = this.WithIdentifiers(computed);
|
|
20
|
+
this.$defs = identified;
|
|
21
|
+
}
|
|
22
|
+
/** `[Json]` Imports a Type by Key. */
|
|
23
|
+
Import(key, options) {
|
|
24
|
+
return (0, index_1.CreateType)({ [index_2.Kind]: 'Import', $defs: this.$defs, $ref: key }, options);
|
|
25
|
+
}
|
|
26
|
+
// prettier-ignore
|
|
27
|
+
WithIdentifiers($defs) {
|
|
28
|
+
return globalThis.Object.getOwnPropertyNames($defs).reduce((result, key) => {
|
|
29
|
+
return { ...result, [key]: { ...$defs[key], $id: key } };
|
|
30
|
+
}, {});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.TModule = TModule;
|
|
34
|
+
/** `[Json]` Creates a Type Definition Module. */
|
|
35
|
+
function Module(properties) {
|
|
36
|
+
return new TModule(properties);
|
|
37
|
+
}
|
|
@@ -7,4 +7,4 @@ export interface TNot<T extends TSchema = TSchema> extends TSchema {
|
|
|
7
7
|
not: T;
|
|
8
8
|
}
|
|
9
9
|
/** `[Json]` Creates a Not type */
|
|
10
|
-
export declare function Not<
|
|
10
|
+
export declare function Not<Type extends TSchema>(type: Type, options?: SchemaOptions): TNot<Type>;
|
|
@@ -5,6 +5,6 @@ exports.Not = Not;
|
|
|
5
5
|
const type_1 = require("../create/type");
|
|
6
6
|
const index_1 = require("../symbols/index");
|
|
7
7
|
/** `[Json]` Creates a Not type */
|
|
8
|
-
function Not(
|
|
9
|
-
return (0, type_1.CreateType)({ [index_1.Kind]: 'Not', not }, options);
|
|
8
|
+
function Not(type, options) {
|
|
9
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'Not', not: type }, options);
|
|
10
10
|
}
|
|
@@ -2,11 +2,11 @@ import type { TSchema, SchemaOptions } from '../schema/index';
|
|
|
2
2
|
import type { TProperties } from '../object/index';
|
|
3
3
|
import { type TMappedResult, type TMappedKey } from '../mapped/index';
|
|
4
4
|
import { type TOmit } from './omit';
|
|
5
|
-
type TFromPropertyKey<
|
|
6
|
-
[_ in
|
|
5
|
+
type TFromPropertyKey<Type extends TSchema, Key extends PropertyKey> = {
|
|
6
|
+
[_ in Key]: TOmit<Type, [Key]>;
|
|
7
7
|
};
|
|
8
|
-
type TFromPropertyKeys<
|
|
9
|
-
type TFromMappedKey<
|
|
10
|
-
export type TOmitFromMappedKey<
|
|
11
|
-
export declare function OmitFromMappedKey<
|
|
8
|
+
type TFromPropertyKeys<Type extends TSchema, PropertyKeys extends PropertyKey[], Result extends TProperties = {}> = (PropertyKeys extends [infer LK extends PropertyKey, ...infer RK extends PropertyKey[]] ? TFromPropertyKeys<Type, RK, Result & TFromPropertyKey<Type, LK>> : Result);
|
|
9
|
+
type TFromMappedKey<Type extends TSchema, MappedKey extends TMappedKey> = (TFromPropertyKeys<Type, MappedKey['keys']>);
|
|
10
|
+
export type TOmitFromMappedKey<Type extends TSchema, MappedKey extends TMappedKey, Properties extends TProperties = TFromMappedKey<Type, MappedKey>> = (TMappedResult<Properties>);
|
|
11
|
+
export declare function OmitFromMappedKey<Type extends TSchema, MappedKey extends TMappedKey, Properties extends TProperties = TFromMappedKey<Type, MappedKey>>(type: Type, mappedKey: MappedKey, options?: SchemaOptions): TMappedResult<Properties>;
|
|
12
12
|
export {};
|
|
@@ -6,23 +6,21 @@ const index_1 = require("../mapped/index");
|
|
|
6
6
|
const omit_1 = require("./omit");
|
|
7
7
|
const value_1 = require("../clone/value");
|
|
8
8
|
// prettier-ignore
|
|
9
|
-
function FromPropertyKey(
|
|
10
|
-
return {
|
|
11
|
-
[K]: (0, omit_1.Omit)(T, [K], (0, value_1.Clone)(options))
|
|
12
|
-
};
|
|
9
|
+
function FromPropertyKey(type, key, options) {
|
|
10
|
+
return { [key]: (0, omit_1.Omit)(type, [key], (0, value_1.Clone)(options)) };
|
|
13
11
|
}
|
|
14
12
|
// prettier-ignore
|
|
15
|
-
function FromPropertyKeys(
|
|
16
|
-
return
|
|
17
|
-
return { ...Acc, ...FromPropertyKey(
|
|
13
|
+
function FromPropertyKeys(type, propertyKeys, options) {
|
|
14
|
+
return propertyKeys.reduce((Acc, LK) => {
|
|
15
|
+
return { ...Acc, ...FromPropertyKey(type, LK, options) };
|
|
18
16
|
}, {});
|
|
19
17
|
}
|
|
20
18
|
// prettier-ignore
|
|
21
|
-
function FromMappedKey(
|
|
22
|
-
return FromPropertyKeys(
|
|
19
|
+
function FromMappedKey(type, mappedKey, options) {
|
|
20
|
+
return FromPropertyKeys(type, mappedKey.keys, options);
|
|
23
21
|
}
|
|
24
22
|
// prettier-ignore
|
|
25
|
-
function OmitFromMappedKey(
|
|
26
|
-
const
|
|
27
|
-
return (0, index_1.MappedResult)(
|
|
23
|
+
function OmitFromMappedKey(type, mappedKey, options) {
|
|
24
|
+
const properties = FromMappedKey(type, mappedKey, options);
|
|
25
|
+
return (0, index_1.MappedResult)(properties);
|
|
28
26
|
}
|
|
@@ -3,10 +3,10 @@ import type { Ensure, Evaluate } from '../helpers/index';
|
|
|
3
3
|
import type { TProperties } from '../object/index';
|
|
4
4
|
import { type TMappedResult } from '../mapped/index';
|
|
5
5
|
import { type TOmit } from './omit';
|
|
6
|
-
type TFromProperties<
|
|
7
|
-
[K2 in keyof
|
|
6
|
+
type TFromProperties<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = ({
|
|
7
|
+
[K2 in keyof Properties]: TOmit<Properties[K2], PropertyKeys>;
|
|
8
8
|
});
|
|
9
|
-
type TFromMappedResult<
|
|
10
|
-
export type TOmitFromMappedResult<
|
|
11
|
-
export declare function OmitFromMappedResult<
|
|
9
|
+
type TFromMappedResult<MappedResult extends TMappedResult, PropertyKeys extends PropertyKey[]> = (Evaluate<TFromProperties<MappedResult['properties'], PropertyKeys>>);
|
|
10
|
+
export type TOmitFromMappedResult<MappedResult extends TMappedResult, PropertyKeys extends PropertyKey[], Properties extends TProperties = TFromMappedResult<MappedResult, PropertyKeys>> = (Ensure<TMappedResult<Properties>>);
|
|
11
|
+
export declare function OmitFromMappedResult<MappedResult extends TMappedResult, PropertyKeys extends PropertyKey[], Properties extends TProperties = TFromMappedResult<MappedResult, PropertyKeys>>(mappedResult: MappedResult, propertyKeys: [...PropertyKeys], options?: SchemaOptions): TMappedResult<Properties>;
|
|
12
12
|
export {};
|
|
@@ -6,18 +6,18 @@ const index_1 = require("../mapped/index");
|
|
|
6
6
|
const omit_1 = require("./omit");
|
|
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, propertyKeys, options) {
|
|
10
|
+
const result = {};
|
|
11
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
|
|
12
|
+
result[K2] = (0, omit_1.Omit)(properties[K2], propertyKeys, (0, value_1.Clone)(options));
|
|
13
|
+
return result;
|
|
14
14
|
}
|
|
15
15
|
// prettier-ignore
|
|
16
|
-
function FromMappedResult(
|
|
17
|
-
return FromProperties(
|
|
16
|
+
function FromMappedResult(mappedResult, propertyKeys, options) {
|
|
17
|
+
return FromProperties(mappedResult.properties, propertyKeys, options);
|
|
18
18
|
}
|
|
19
19
|
// prettier-ignore
|
|
20
|
-
function OmitFromMappedResult(
|
|
21
|
-
const
|
|
22
|
-
return (0, index_1.MappedResult)(
|
|
20
|
+
function OmitFromMappedResult(mappedResult, propertyKeys, options) {
|
|
21
|
+
const properties = FromMappedResult(mappedResult, propertyKeys, options);
|
|
22
|
+
return (0, index_1.MappedResult)(properties);
|
|
23
23
|
}
|
|
@@ -2,23 +2,35 @@ import type { SchemaOptions, TSchema } from '../schema/index';
|
|
|
2
2
|
import type { TupleToUnion, Evaluate, Ensure } from '../helpers/index';
|
|
3
3
|
import { type TRecursive } from '../recursive/index';
|
|
4
4
|
import type { TMappedKey, TMappedResult } from '../mapped/index';
|
|
5
|
+
import { TComputed } from '../computed/index';
|
|
6
|
+
import { TLiteral, TLiteralValue } from '../literal/index';
|
|
7
|
+
import { type TIndexPropertyKeys } from '../indexed/index';
|
|
5
8
|
import { type TIntersect } from '../intersect/index';
|
|
6
9
|
import { type TUnion } from '../union/index';
|
|
7
10
|
import { type TObject, type TProperties } from '../object/index';
|
|
8
|
-
import { type
|
|
11
|
+
import { type TRef } from '../ref/index';
|
|
9
12
|
import { type TOmitFromMappedKey } from './omit-from-mapped-key';
|
|
10
13
|
import { type TOmitFromMappedResult } from './omit-from-mapped-result';
|
|
11
|
-
type TFromIntersect<
|
|
12
|
-
type TFromUnion<T extends TSchema[], K extends PropertyKey[],
|
|
13
|
-
type TFromProperties<
|
|
14
|
-
type TFromObject<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
type TFromIntersect<Types extends TSchema[], PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect<R, PropertyKeys, [...Result, TOmit<L, PropertyKeys>]> : Result);
|
|
15
|
+
type TFromUnion<T extends TSchema[], K extends PropertyKey[], Result extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, K, [...Result, TOmit<L, K>]> : Result);
|
|
16
|
+
type TFromProperties<Properties extends TProperties, PropertyKeys extends PropertyKey[], UnionKey extends PropertyKey = TupleToUnion<PropertyKeys>> = (Evaluate<Omit<Properties, UnionKey>>);
|
|
17
|
+
type TFromObject<Type extends TObject, PropertyKeys extends PropertyKey[], Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties, PropertyKeys>)>>;
|
|
18
|
+
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]> : TUnion<Result>);
|
|
19
|
+
export type TOmitResolve<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = (Properties extends TRecursive<infer Types extends TSchema> ? TRecursive<TOmitResolve<Types, PropertyKeys>> : Properties extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromIntersect<Types, PropertyKeys>> : Properties extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromUnion<Types, PropertyKeys>> : Properties extends TObject<infer Types extends TProperties> ? TFromObject<TObject<Types>, PropertyKeys> : TObject<{}>);
|
|
20
|
+
type TResolvePropertyKeys<Key extends TSchema | PropertyKey[]> = Key extends TSchema ? TIndexPropertyKeys<Key> : Key;
|
|
21
|
+
type TResolveTypeKey<Key extends TSchema | PropertyKey[]> = Key extends PropertyKey[] ? TUnionFromPropertyKeys<Key> : Key;
|
|
22
|
+
export type TOmit<Type extends TSchema, Key extends TSchema | PropertyKey[], IsTypeRef extends boolean = Type extends TRef ? true : false, IsKeyRef extends boolean = Key extends TRef ? true : false> = (Type extends TMappedResult ? TOmitFromMappedResult<Type, TResolvePropertyKeys<Key>> : Key extends TMappedKey ? TOmitFromMappedKey<Type, Key> : [
|
|
23
|
+
IsTypeRef,
|
|
24
|
+
IsKeyRef
|
|
25
|
+
] extends [true, true] ? TComputed<'Omit', [Type, TResolveTypeKey<Key>]> : [
|
|
26
|
+
IsTypeRef,
|
|
27
|
+
IsKeyRef
|
|
28
|
+
] extends [false, true] ? TComputed<'Omit', [Type, TResolveTypeKey<Key>]> : [
|
|
29
|
+
IsTypeRef,
|
|
30
|
+
IsKeyRef
|
|
31
|
+
] extends [true, false] ? TComputed<'Omit', [Type, TResolveTypeKey<Key>]> : TOmitResolve<Type, TResolvePropertyKeys<Key>>);
|
|
32
|
+
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
33
|
+
export declare function Omit<Type extends TSchema, Key extends PropertyKey[]>(type: Type, key: readonly [...Key], options?: SchemaOptions): TOmit<Type, Key>;
|
|
34
|
+
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
35
|
+
export declare function Omit<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TOmit<Type, Key>;
|
|
24
36
|
export {};
|