@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
|
@@ -1,26 +1,35 @@
|
|
|
1
1
|
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
import { Literal } from '../literal/index.mjs';
|
|
3
3
|
import { Number } from '../number/index.mjs';
|
|
4
|
+
import { Computed } from '../computed/index.mjs';
|
|
5
|
+
import { Ref } from '../ref/index.mjs';
|
|
4
6
|
import { KeyOfPropertyKeys } from './keyof-property-keys.mjs';
|
|
5
7
|
import { UnionEvaluated } from '../union/index.mjs';
|
|
6
8
|
import { KeyOfFromMappedResult } from './keyof-from-mapped-result.mjs';
|
|
7
9
|
// ------------------------------------------------------------------
|
|
8
10
|
// TypeGuard
|
|
9
11
|
// ------------------------------------------------------------------
|
|
10
|
-
import { IsMappedResult } from '../guard/kind.mjs';
|
|
12
|
+
import { IsMappedResult, IsRef, IsComputed } from '../guard/kind.mjs';
|
|
11
13
|
// prettier-ignore
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
+
function FromComputed(target, parameters) {
|
|
15
|
+
return Computed('KeyOf', [Computed(target, parameters)]);
|
|
16
|
+
}
|
|
17
|
+
// prettier-ignore
|
|
18
|
+
function FromRef($ref) {
|
|
19
|
+
return Computed('KeyOf', [Ref($ref)]);
|
|
20
|
+
}
|
|
21
|
+
// prettier-ignore
|
|
22
|
+
function KeyOfFromType(type, options) {
|
|
23
|
+
const propertyKeys = KeyOfPropertyKeys(type);
|
|
24
|
+
const propertyKeyTypes = KeyOfPropertyKeysToRest(propertyKeys);
|
|
25
|
+
const result = UnionEvaluated(propertyKeyTypes);
|
|
26
|
+
return CreateType(result, options);
|
|
27
|
+
}
|
|
28
|
+
// prettier-ignore
|
|
29
|
+
export function KeyOfPropertyKeysToRest(propertyKeys) {
|
|
30
|
+
return propertyKeys.map(L => L === '[number]' ? Number() : Literal(L));
|
|
14
31
|
}
|
|
15
32
|
/** `[Json]` Creates a KeyOf type */
|
|
16
|
-
export function KeyOf(
|
|
17
|
-
|
|
18
|
-
return KeyOfFromMappedResult(T, options);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
const K = KeyOfPropertyKeys(T);
|
|
22
|
-
const S = KeyOfPropertyKeysToRest(K);
|
|
23
|
-
const U = UnionEvaluated(S);
|
|
24
|
-
return CreateType(U, options);
|
|
25
|
-
}
|
|
33
|
+
export function KeyOf(type, options) {
|
|
34
|
+
return (IsComputed(type) ? FromComputed(type.target, type.parameters) : IsRef(type) ? FromRef(type.$ref) : IsMappedResult(type) ? KeyOfFromMappedResult(type, options) : KeyOfFromType(type, options));
|
|
26
35
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Ensure, Evaluate } from '../helpers/index.mjs';
|
|
2
|
+
import { type TSchema } from '../schema/index.mjs';
|
|
3
|
+
import { type TArray } from '../array/index.mjs';
|
|
4
|
+
import { type TAwaited } from '../awaited/index.mjs';
|
|
5
|
+
import { type TAsyncIterator } from '../async-iterator/index.mjs';
|
|
6
|
+
import { TComputed } from '../computed/index.mjs';
|
|
7
|
+
import { type TConstructor } from '../constructor/index.mjs';
|
|
8
|
+
import { type TIndex } from '../indexed/index.mjs';
|
|
9
|
+
import { type TFunction } from '../function/index.mjs';
|
|
10
|
+
import { type TIntersect, type TIntersectEvaluated } from '../intersect/index.mjs';
|
|
11
|
+
import { type TIterator } from '../iterator/index.mjs';
|
|
12
|
+
import { type TKeyOf } from '../keyof/index.mjs';
|
|
13
|
+
import { type TObject, type TProperties } from '../object/index.mjs';
|
|
14
|
+
import { type TOmit } from '../omit/index.mjs';
|
|
15
|
+
import { type TPick } from '../pick/index.mjs';
|
|
16
|
+
import { type TNever } from '../never/index.mjs';
|
|
17
|
+
import { TPartial } from '../partial/index.mjs';
|
|
18
|
+
import { type TRecordOrObject } from '../record/index.mjs';
|
|
19
|
+
import { type TRef } from '../ref/index.mjs';
|
|
20
|
+
import { TRequired } from '../required/index.mjs';
|
|
21
|
+
import { type TTuple } from '../tuple/index.mjs';
|
|
22
|
+
import { type TUnion, type TUnionEvaluated } from '../union/index.mjs';
|
|
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,148 @@
|
|
|
1
|
+
import { CreateType } from '../create/index.mjs';
|
|
2
|
+
import { Array } from '../array/index.mjs';
|
|
3
|
+
import { Awaited } from '../awaited/index.mjs';
|
|
4
|
+
import { AsyncIterator } from '../async-iterator/index.mjs';
|
|
5
|
+
import { Constructor } from '../constructor/index.mjs';
|
|
6
|
+
import { Index } from '../indexed/index.mjs';
|
|
7
|
+
import { Function } from '../function/index.mjs';
|
|
8
|
+
import { Intersect } from '../intersect/index.mjs';
|
|
9
|
+
import { Iterator } from '../iterator/index.mjs';
|
|
10
|
+
import { KeyOf } from '../keyof/index.mjs';
|
|
11
|
+
import { Object } from '../object/index.mjs';
|
|
12
|
+
import { Omit } from '../omit/index.mjs';
|
|
13
|
+
import { Pick } from '../pick/index.mjs';
|
|
14
|
+
import { Never } from '../never/index.mjs';
|
|
15
|
+
import { Partial } from '../partial/index.mjs';
|
|
16
|
+
import { Record } from '../record/index.mjs';
|
|
17
|
+
import { Required } from '../required/index.mjs';
|
|
18
|
+
import { Tuple } from '../tuple/index.mjs';
|
|
19
|
+
import { Union } from '../union/index.mjs';
|
|
20
|
+
// ------------------------------------------------------------------
|
|
21
|
+
// KindGuard
|
|
22
|
+
// ------------------------------------------------------------------
|
|
23
|
+
import * as KindGuard from '../guard/kind.mjs';
|
|
24
|
+
// prettier-ignore
|
|
25
|
+
function DerefParameters(moduleProperties, types) {
|
|
26
|
+
return types.map((type) => {
|
|
27
|
+
return KindGuard.IsRef(type)
|
|
28
|
+
? Deref(moduleProperties, type.$ref)
|
|
29
|
+
: FromType(moduleProperties, type);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
// prettier-ignore
|
|
33
|
+
function Deref(moduleProperties, ref) {
|
|
34
|
+
return (ref in moduleProperties
|
|
35
|
+
? KindGuard.IsRef(moduleProperties[ref])
|
|
36
|
+
? Deref(moduleProperties, moduleProperties[ref].$ref)
|
|
37
|
+
: FromType(moduleProperties, moduleProperties[ref])
|
|
38
|
+
: Never());
|
|
39
|
+
}
|
|
40
|
+
// prettier-ignore
|
|
41
|
+
function FromAwaited(parameters) {
|
|
42
|
+
return Awaited(parameters[0]);
|
|
43
|
+
}
|
|
44
|
+
// prettier-ignore
|
|
45
|
+
function FromIndex(parameters) {
|
|
46
|
+
return Index(parameters[0], parameters[1]);
|
|
47
|
+
}
|
|
48
|
+
// prettier-ignore
|
|
49
|
+
function FromKeyOf(parameters) {
|
|
50
|
+
return KeyOf(parameters[0]);
|
|
51
|
+
}
|
|
52
|
+
// prettier-ignore
|
|
53
|
+
function FromPartial(parameters) {
|
|
54
|
+
return Partial(parameters[0]);
|
|
55
|
+
}
|
|
56
|
+
// prettier-ignore
|
|
57
|
+
function FromOmit(parameters) {
|
|
58
|
+
return Omit(parameters[0], parameters[1]);
|
|
59
|
+
}
|
|
60
|
+
// prettier-ignore
|
|
61
|
+
function FromPick(parameters) {
|
|
62
|
+
return Pick(parameters[0], parameters[1]);
|
|
63
|
+
}
|
|
64
|
+
// prettier-ignore
|
|
65
|
+
function FromRecord(parameters) {
|
|
66
|
+
return Record(parameters[0], parameters[1]);
|
|
67
|
+
}
|
|
68
|
+
// prettier-ignore
|
|
69
|
+
function FromRequired(parameters) {
|
|
70
|
+
return Required(parameters[0]);
|
|
71
|
+
}
|
|
72
|
+
// prettier-ignore
|
|
73
|
+
function FromComputed(moduleProperties, target, parameters) {
|
|
74
|
+
const dereferenced = DerefParameters(moduleProperties, parameters);
|
|
75
|
+
return (target === 'Awaited' ? FromAwaited(dereferenced) :
|
|
76
|
+
target === 'Index' ? FromIndex(dereferenced) :
|
|
77
|
+
target === 'KeyOf' ? FromKeyOf(dereferenced) :
|
|
78
|
+
target === 'Partial' ? FromPartial(dereferenced) :
|
|
79
|
+
target === 'Omit' ? FromOmit(dereferenced) :
|
|
80
|
+
target === 'Pick' ? FromPick(dereferenced) :
|
|
81
|
+
target === 'Record' ? FromRecord(dereferenced) :
|
|
82
|
+
target === 'Required' ? FromRequired(dereferenced) :
|
|
83
|
+
Never());
|
|
84
|
+
}
|
|
85
|
+
function FromObject(moduleProperties, properties) {
|
|
86
|
+
return Object(globalThis.Object.keys(properties).reduce((result, key) => {
|
|
87
|
+
return { ...result, [key]: FromType(moduleProperties, properties[key]) };
|
|
88
|
+
}, {}));
|
|
89
|
+
}
|
|
90
|
+
// prettier-ignore
|
|
91
|
+
function FromConstructor(moduleProperties, parameters, instanceType) {
|
|
92
|
+
return Constructor(FromRest(moduleProperties, parameters), FromType(moduleProperties, instanceType));
|
|
93
|
+
}
|
|
94
|
+
// prettier-ignore
|
|
95
|
+
function FromFunction(moduleProperties, parameters, returnType) {
|
|
96
|
+
return Function(FromRest(moduleProperties, parameters), FromType(moduleProperties, returnType));
|
|
97
|
+
}
|
|
98
|
+
function FromTuple(moduleProperties, types) {
|
|
99
|
+
return Tuple(FromRest(moduleProperties, types));
|
|
100
|
+
}
|
|
101
|
+
function FromIntersect(moduleProperties, types) {
|
|
102
|
+
return Intersect(FromRest(moduleProperties, types));
|
|
103
|
+
}
|
|
104
|
+
function FromUnion(moduleProperties, types) {
|
|
105
|
+
return Union(FromRest(moduleProperties, types));
|
|
106
|
+
}
|
|
107
|
+
function FromArray(moduleProperties, type) {
|
|
108
|
+
return Array(FromType(moduleProperties, type));
|
|
109
|
+
}
|
|
110
|
+
function FromAsyncIterator(moduleProperties, type) {
|
|
111
|
+
return AsyncIterator(FromType(moduleProperties, type));
|
|
112
|
+
}
|
|
113
|
+
function FromIterator(moduleProperties, type) {
|
|
114
|
+
return Iterator(FromType(moduleProperties, type));
|
|
115
|
+
}
|
|
116
|
+
function FromRest(moduleProperties, types) {
|
|
117
|
+
return types.map((type) => FromType(moduleProperties, type));
|
|
118
|
+
}
|
|
119
|
+
// prettier-ignore
|
|
120
|
+
export function FromType(moduleProperties, type) {
|
|
121
|
+
return (
|
|
122
|
+
// Note: The 'as never' is required due to excessive resolution of TIndex. In fact TIndex, TPick, TOmit and
|
|
123
|
+
// all need re-implementation to remove the PropertyKey[] selector. Reimplementation of these types should
|
|
124
|
+
// be a priority as there is a potential for the current inference to break on TS compiler changes.
|
|
125
|
+
KindGuard.IsComputed(type) ? CreateType(FromComputed(moduleProperties, type.target, type.parameters)) :
|
|
126
|
+
KindGuard.IsObject(type) ? CreateType(FromObject(moduleProperties, type.properties), type) :
|
|
127
|
+
KindGuard.IsConstructor(type) ? CreateType(FromConstructor(moduleProperties, type.parameters, type.returns), type) :
|
|
128
|
+
KindGuard.IsFunction(type) ? CreateType(FromFunction(moduleProperties, type.parameters, type.returns), type) :
|
|
129
|
+
KindGuard.IsTuple(type) ? CreateType(FromTuple(moduleProperties, type.items || []), type) :
|
|
130
|
+
KindGuard.IsIntersect(type) ? CreateType(FromIntersect(moduleProperties, type.allOf), type) :
|
|
131
|
+
KindGuard.IsUnion(type) ? CreateType(FromUnion(moduleProperties, type.anyOf), type) :
|
|
132
|
+
KindGuard.IsArray(type) ? CreateType(FromArray(moduleProperties, type.items), type) :
|
|
133
|
+
KindGuard.IsAsyncIterator(type) ? CreateType(FromAsyncIterator(moduleProperties, type.items), type) :
|
|
134
|
+
KindGuard.IsIterator(type) ? CreateType(FromIterator(moduleProperties, type.items), type) :
|
|
135
|
+
type);
|
|
136
|
+
}
|
|
137
|
+
// prettier-ignore
|
|
138
|
+
export function ComputeType(moduleProperties, key) {
|
|
139
|
+
return (key in moduleProperties
|
|
140
|
+
? FromType(moduleProperties, moduleProperties[key])
|
|
141
|
+
: Never());
|
|
142
|
+
}
|
|
143
|
+
// prettier-ignore
|
|
144
|
+
export function ComputeModuleProperties(moduleProperties) {
|
|
145
|
+
return globalThis.Object.getOwnPropertyNames(moduleProperties).reduce((result, key) => {
|
|
146
|
+
return { ...result, [key]: ComputeType(moduleProperties, key) };
|
|
147
|
+
}, {});
|
|
148
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './module.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './module.mjs';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Ensure, Evaluate } from '../helpers/index.mjs';
|
|
2
|
+
import { TSchema } from '../schema/index.mjs';
|
|
3
|
+
import { TArray } from '../array/index.mjs';
|
|
4
|
+
import { TAsyncIterator } from '../async-iterator/index.mjs';
|
|
5
|
+
import { TConstructor } from '../constructor/index.mjs';
|
|
6
|
+
import { TFunction } from '../function/index.mjs';
|
|
7
|
+
import { TIntersect } from '../intersect/index.mjs';
|
|
8
|
+
import { TIterator } from '../iterator/index.mjs';
|
|
9
|
+
import { TObject, TProperties } from '../object/index.mjs';
|
|
10
|
+
import { TOptional } from '../optional/index.mjs';
|
|
11
|
+
import { TReadonly } from '../readonly/index.mjs';
|
|
12
|
+
import { TRef } from '../ref/index.mjs';
|
|
13
|
+
import { TTuple } from '../tuple/index.mjs';
|
|
14
|
+
import { TUnion } from '../union/index.mjs';
|
|
15
|
+
import { Static } from '../static/index.mjs';
|
|
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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Kind } from '../symbols/index.mjs';
|
|
2
|
+
import { SchemaOptions, TSchema } from '../schema/index.mjs';
|
|
3
|
+
import { TProperties } from '../object/index.mjs';
|
|
4
|
+
import { Static } from '../static/index.mjs';
|
|
5
|
+
import { TComputeModuleProperties } from './compute.mjs';
|
|
6
|
+
import { TInferFromModuleKey } from './infer.mjs';
|
|
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,31 @@
|
|
|
1
|
+
import { CreateType } from '../create/index.mjs';
|
|
2
|
+
import { Kind } from '../symbols/index.mjs';
|
|
3
|
+
// ------------------------------------------------------------------
|
|
4
|
+
// Module Infrastructure Types
|
|
5
|
+
// ------------------------------------------------------------------
|
|
6
|
+
import { ComputeModuleProperties } from './compute.mjs';
|
|
7
|
+
// ------------------------------------------------------------------
|
|
8
|
+
// Module
|
|
9
|
+
// ------------------------------------------------------------------
|
|
10
|
+
// prettier-ignore
|
|
11
|
+
export class TModule {
|
|
12
|
+
constructor($defs) {
|
|
13
|
+
const computed = ComputeModuleProperties($defs);
|
|
14
|
+
const identified = this.WithIdentifiers(computed);
|
|
15
|
+
this.$defs = identified;
|
|
16
|
+
}
|
|
17
|
+
/** `[Json]` Imports a Type by Key. */
|
|
18
|
+
Import(key, options) {
|
|
19
|
+
return CreateType({ [Kind]: 'Import', $defs: this.$defs, $ref: key }, options);
|
|
20
|
+
}
|
|
21
|
+
// prettier-ignore
|
|
22
|
+
WithIdentifiers($defs) {
|
|
23
|
+
return globalThis.Object.getOwnPropertyNames($defs).reduce((result, key) => {
|
|
24
|
+
return { ...result, [key]: { ...$defs[key], $id: key } };
|
|
25
|
+
}, {});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** `[Json]` Creates a Type Definition Module. */
|
|
29
|
+
export function Module(properties) {
|
|
30
|
+
return new TModule(properties);
|
|
31
|
+
}
|
|
@@ -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>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
import { Kind } from '../symbols/index.mjs';
|
|
3
3
|
/** `[Json]` Creates a Not type */
|
|
4
|
-
export function Not(
|
|
5
|
-
return CreateType({ [Kind]: 'Not', not }, options);
|
|
4
|
+
export function Not(type, options) {
|
|
5
|
+
return CreateType({ [Kind]: 'Not', not: type }, options);
|
|
6
6
|
}
|
|
@@ -2,11 +2,11 @@ import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
|
2
2
|
import type { TProperties } from '../object/index.mjs';
|
|
3
3
|
import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
|
|
4
4
|
import { type TOmit } from './omit.mjs';
|
|
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 {};
|
|
@@ -2,23 +2,21 @@ import { MappedResult } from '../mapped/index.mjs';
|
|
|
2
2
|
import { Omit } from './omit.mjs';
|
|
3
3
|
import { Clone } from '../clone/value.mjs';
|
|
4
4
|
// prettier-ignore
|
|
5
|
-
function FromPropertyKey(
|
|
6
|
-
return {
|
|
7
|
-
[K]: Omit(T, [K], Clone(options))
|
|
8
|
-
};
|
|
5
|
+
function FromPropertyKey(type, key, options) {
|
|
6
|
+
return { [key]: Omit(type, [key], Clone(options)) };
|
|
9
7
|
}
|
|
10
8
|
// prettier-ignore
|
|
11
|
-
function FromPropertyKeys(
|
|
12
|
-
return
|
|
13
|
-
return { ...Acc, ...FromPropertyKey(
|
|
9
|
+
function FromPropertyKeys(type, propertyKeys, options) {
|
|
10
|
+
return propertyKeys.reduce((Acc, LK) => {
|
|
11
|
+
return { ...Acc, ...FromPropertyKey(type, LK, options) };
|
|
14
12
|
}, {});
|
|
15
13
|
}
|
|
16
14
|
// prettier-ignore
|
|
17
|
-
function FromMappedKey(
|
|
18
|
-
return FromPropertyKeys(
|
|
15
|
+
function FromMappedKey(type, mappedKey, options) {
|
|
16
|
+
return FromPropertyKeys(type, mappedKey.keys, options);
|
|
19
17
|
}
|
|
20
18
|
// prettier-ignore
|
|
21
|
-
export function OmitFromMappedKey(
|
|
22
|
-
const
|
|
23
|
-
return MappedResult(
|
|
19
|
+
export function OmitFromMappedKey(type, mappedKey, options) {
|
|
20
|
+
const properties = FromMappedKey(type, mappedKey, options);
|
|
21
|
+
return MappedResult(properties);
|
|
24
22
|
}
|
|
@@ -3,10 +3,10 @@ import type { Ensure, Evaluate } from '../helpers/index.mjs';
|
|
|
3
3
|
import type { TProperties } from '../object/index.mjs';
|
|
4
4
|
import { type TMappedResult } from '../mapped/index.mjs';
|
|
5
5
|
import { type TOmit } from './omit.mjs';
|
|
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 {};
|
|
@@ -2,18 +2,18 @@ import { MappedResult } from '../mapped/index.mjs';
|
|
|
2
2
|
import { Omit } from './omit.mjs';
|
|
3
3
|
import { Clone } from '../clone/value.mjs';
|
|
4
4
|
// prettier-ignore
|
|
5
|
-
function FromProperties(
|
|
6
|
-
const
|
|
7
|
-
for (const K2 of globalThis.Object.getOwnPropertyNames(
|
|
8
|
-
|
|
9
|
-
return
|
|
5
|
+
function FromProperties(properties, propertyKeys, options) {
|
|
6
|
+
const result = {};
|
|
7
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
|
|
8
|
+
result[K2] = Omit(properties[K2], propertyKeys, Clone(options));
|
|
9
|
+
return result;
|
|
10
10
|
}
|
|
11
11
|
// prettier-ignore
|
|
12
|
-
function FromMappedResult(
|
|
13
|
-
return FromProperties(
|
|
12
|
+
function FromMappedResult(mappedResult, propertyKeys, options) {
|
|
13
|
+
return FromProperties(mappedResult.properties, propertyKeys, options);
|
|
14
14
|
}
|
|
15
15
|
// prettier-ignore
|
|
16
|
-
export function OmitFromMappedResult(
|
|
17
|
-
const
|
|
18
|
-
return MappedResult(
|
|
16
|
+
export function OmitFromMappedResult(mappedResult, propertyKeys, options) {
|
|
17
|
+
const properties = FromMappedResult(mappedResult, propertyKeys, options);
|
|
18
|
+
return MappedResult(properties);
|
|
19
19
|
}
|
|
@@ -2,23 +2,35 @@ import type { SchemaOptions, TSchema } from '../schema/index.mjs';
|
|
|
2
2
|
import type { TupleToUnion, Evaluate, Ensure } from '../helpers/index.mjs';
|
|
3
3
|
import { type TRecursive } from '../recursive/index.mjs';
|
|
4
4
|
import type { TMappedKey, TMappedResult } from '../mapped/index.mjs';
|
|
5
|
+
import { TComputed } from '../computed/index.mjs';
|
|
6
|
+
import { TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
7
|
+
import { type TIndexPropertyKeys } from '../indexed/index.mjs';
|
|
5
8
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
6
9
|
import { type TUnion } from '../union/index.mjs';
|
|
7
10
|
import { type TObject, type TProperties } from '../object/index.mjs';
|
|
8
|
-
import { type
|
|
11
|
+
import { type TRef } from '../ref/index.mjs';
|
|
9
12
|
import { type TOmitFromMappedKey } from './omit-from-mapped-key.mjs';
|
|
10
13
|
import { type TOmitFromMappedResult } from './omit-from-mapped-result.mjs';
|
|
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 {};
|