@sinclair/typebox 0.34.0 → 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/syntax/runtime.d.ts +4 -1
- package/build/cjs/syntax/runtime.js +3 -1
- package/build/cjs/syntax/static.d.ts +3 -3
- 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/computed/index.js +18 -0
- package/build/cjs/type/guard/kind.d.ts +9 -4
- package/build/cjs/type/guard/kind.js +10 -0
- package/build/cjs/type/guard/type.d.ts +6 -3
- package/build/cjs/type/guard/type.js +6 -0
- 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/infer.d.ts +43 -0
- package/build/cjs/type/module/infer.js +3 -0
- package/build/cjs/type/module/module.d.ts +8 -52
- package/build/cjs/type/module/module.js +14 -11
- 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/required/required.d.ts +12 -8
- package/build/cjs/type/required/required.js +37 -25
- 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 +41 -51
- package/build/cjs/type/type/json.js +40 -40
- 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/check/check.js +3 -3
- package/build/cjs/value/transform/decode.js +7 -7
- package/build/cjs/value/transform/encode.js +7 -7
- package/build/cjs/value/transform/has.js +18 -18
- package/build/esm/syntax/runtime.d.mts +4 -1
- package/build/esm/syntax/runtime.mjs +3 -1
- package/build/esm/syntax/static.d.mts +3 -3
- 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 +9 -4
- package/build/esm/type/guard/kind.mjs +8 -0
- package/build/esm/type/guard/type.d.mts +6 -3
- package/build/esm/type/guard/type.mjs +5 -0
- 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/infer.d.mts +43 -0
- package/build/esm/type/module/infer.mjs +1 -0
- package/build/esm/type/module/module.d.mts +8 -52
- package/build/esm/type/module/module.mjs +14 -11
- 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/required/required.d.mts +12 -8
- package/build/esm/type/required/required.mjs +33 -21
- 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 +41 -51
- package/build/esm/type/type/json.mjs +40 -40
- 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/check/check.mjs +2 -2
- package/build/esm/value/transform/decode.mjs +2 -2
- package/build/esm/value/transform/encode.mjs +2 -2
- package/build/esm/value/transform/has.mjs +2 -2
- package/package.json +1 -1
- package/readme.md +30 -19
|
@@ -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,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 {};
|
|
@@ -1,48 +1,9 @@
|
|
|
1
|
-
import { Ensure } from '../helpers/index';
|
|
2
1
|
import { Kind } from '../symbols/index';
|
|
3
2
|
import { SchemaOptions, TSchema } from '../schema/index';
|
|
4
|
-
import {
|
|
5
|
-
import { TConstructor } from '../constructor/index';
|
|
6
|
-
import { TFunction } from '../function/index';
|
|
7
|
-
import { TTuple } from '../tuple/index';
|
|
8
|
-
import { TIntersect } from '../intersect/index';
|
|
9
|
-
import { TUnion } from '../union/index';
|
|
10
|
-
import { TArray } from '../array/index';
|
|
11
|
-
import { TAsyncIterator } from '../async-iterator/index';
|
|
12
|
-
import { TIterator } from '../iterator/index';
|
|
13
|
-
import { TLiteral, TLiteralValue } from '../literal/index';
|
|
14
|
-
import { TAny } from '../any/index';
|
|
15
|
-
import { TBigInt } from '../bigint/index';
|
|
16
|
-
import { TBoolean } from '../boolean/index';
|
|
17
|
-
import { TDate } from '../date/index';
|
|
18
|
-
import { TInteger } from '../integer/index';
|
|
19
|
-
import { TNever } from '../never/index';
|
|
20
|
-
import { TNumber } from '../number/index';
|
|
21
|
-
import { TNull } from '../null/index';
|
|
22
|
-
import { TRef } from '../ref/index';
|
|
23
|
-
import { TRegExp } from '../regexp/index';
|
|
24
|
-
import { TString } from '../string/index';
|
|
25
|
-
import { TSymbol } from '../symbol/index';
|
|
26
|
-
import { TTemplateLiteral, TTemplateLiteralKind } from '../template-literal/index';
|
|
27
|
-
import { TUint8Array } from '../uint8array/index';
|
|
28
|
-
import { TUndefined } from '../undefined/index';
|
|
29
|
-
import { TUnknown } from '../unknown/index';
|
|
30
|
-
import { TVoid } from '../void/index';
|
|
3
|
+
import { TProperties } from '../object/index';
|
|
31
4
|
import { Static } from '../static/index';
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
type InferObject<Properties extends TProperties, ModuleProperties extends TProperties> = {
|
|
35
|
-
[K in keyof Properties]: Infer<Properties[K], ModuleProperties>;
|
|
36
|
-
} & {};
|
|
37
|
-
type InferConstructor<Parameters extends TSchema[], InstanceType extends TSchema, Properties extends TProperties> = Ensure<new (...args: InferTuple<Parameters, Properties>) => Infer<InstanceType, Properties>>;
|
|
38
|
-
type InferFunction<Parameters extends TSchema[], ReturnType extends TSchema, Properties extends TProperties> = Ensure<(...args: InferTuple<Parameters, Properties>) => Infer<ReturnType, Properties>>;
|
|
39
|
-
type InferTuple<Types extends TSchema[], Properties extends TProperties, Result extends unknown[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? InferTuple<R, Properties, [...Result, Infer<L, Properties>]> : Result);
|
|
40
|
-
type InferIntersect<Types extends TSchema[], Properties extends TProperties, Result extends unknown = unknown> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? InferIntersect<R, Properties, Result & Infer<L, Properties>> : Result);
|
|
41
|
-
type InferUnion<Types extends TSchema[], Properties extends TProperties, Result extends unknown = never> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? InferUnion<R, Properties, Result | Infer<L, Properties>> : Result);
|
|
42
|
-
type InferArray<Type extends TSchema, Module extends TProperties> = (Ensure<Array<Infer<Type, Module>>>);
|
|
43
|
-
type InferAsyncIterator<Type extends TSchema, Properties extends TProperties> = (Ensure<AsyncIterableIterator<Infer<Type, Properties>>>);
|
|
44
|
-
type InferIterator<Type extends TSchema, Properties extends TProperties> = (Ensure<IterableIterator<Infer<Type, Properties>>>);
|
|
45
|
-
type Infer<Type extends TSchema, Properties extends TProperties = {}> = (Type extends TImport<infer S extends TProperties, infer K extends string> ? InferImport<S, K, S> : Type extends TRef<infer S extends string> ? InferRef<S, Properties> : Type extends TObject<infer S extends TProperties> ? InferObject<S, Properties> : Type extends TConstructor<infer S extends TSchema[], infer R extends TSchema> ? InferConstructor<S, R, Properties> : Type extends TFunction<infer S extends TSchema[], infer R extends TSchema> ? InferFunction<S, R, Properties> : Type extends TTuple<infer S extends TSchema[]> ? InferTuple<S, Properties> : Type extends TIntersect<infer S extends TSchema[]> ? InferIntersect<S, Properties> : Type extends TUnion<infer S extends TSchema[]> ? InferUnion<S, Properties> : Type extends TArray<infer S extends TSchema> ? InferArray<S, Properties> : Type extends TAsyncIterator<infer S extends TSchema> ? InferAsyncIterator<S, Properties> : Type extends TIterator<infer S extends TSchema> ? InferIterator<S, Properties> : Type extends TTemplateLiteral<infer S extends TTemplateLiteralKind[]> ? Static<TTemplateLiteral<S>> : Type extends TLiteral<infer S extends TLiteralValue> ? S : Type extends TAny ? any : Type extends TBigInt ? bigint : Type extends TBoolean ? boolean : Type extends TDate ? Date : Type extends TInteger ? number : Type extends TNever ? never : Type extends TNumber ? number : Type extends TRegExp ? string : Type extends TString ? string : Type extends TSymbol ? symbol : Type extends TNull ? null : Type extends TUint8Array ? Uint8Array : Type extends TUndefined ? undefined : Type extends TUnknown ? unknown : Type extends TVoid ? void : never);
|
|
5
|
+
import { TComputeModuleProperties } from './compute';
|
|
6
|
+
import { TInferFromModuleKey } from './infer';
|
|
46
7
|
export interface TDefinitions<ModuleProperties extends TProperties> extends TSchema {
|
|
47
8
|
static: {
|
|
48
9
|
[K in keyof ModuleProperties]: Static<ModuleProperties[K]>;
|
|
@@ -51,21 +12,16 @@ export interface TDefinitions<ModuleProperties extends TProperties> extends TSch
|
|
|
51
12
|
}
|
|
52
13
|
export interface TImport<ModuleProperties extends TProperties = {}, Key extends keyof ModuleProperties = keyof ModuleProperties> extends TSchema {
|
|
53
14
|
[Kind]: 'Import';
|
|
54
|
-
static:
|
|
15
|
+
static: TInferFromModuleKey<ModuleProperties, Key>;
|
|
55
16
|
$defs: ModuleProperties;
|
|
56
17
|
$ref: Key;
|
|
57
18
|
}
|
|
58
|
-
export declare class TModule<
|
|
19
|
+
export declare class TModule<ModuleProperties extends TProperties, ComputedModuleProperties extends TProperties = TComputeModuleProperties<ModuleProperties>> {
|
|
59
20
|
private readonly $defs;
|
|
60
|
-
|
|
61
|
-
constructor($defs: Properties, options?: SchemaOptions);
|
|
62
|
-
/** `[Json]` Returns the Type definitions for this module */
|
|
63
|
-
Defs(): TDefinitions<Properties>;
|
|
21
|
+
constructor($defs: ModuleProperties);
|
|
64
22
|
/** `[Json]` Imports a Type by Key. */
|
|
65
|
-
Import<Key extends keyof
|
|
66
|
-
|
|
67
|
-
private ResolveDefinitionsWithIdentifiers;
|
|
23
|
+
Import<Key extends keyof ComputedModuleProperties>(key: Key, options?: SchemaOptions): TImport<ComputedModuleProperties, Key>;
|
|
24
|
+
private WithIdentifiers;
|
|
68
25
|
}
|
|
69
26
|
/** `[Json]` Creates a Type Definition Module. */
|
|
70
27
|
export declare function Module<Properties extends TProperties>(properties: Properties): TModule<Properties>;
|
|
71
|
-
export {};
|
|
@@ -6,25 +6,28 @@ exports.Module = Module;
|
|
|
6
6
|
const index_1 = require("../create/index");
|
|
7
7
|
const index_2 = require("../symbols/index");
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
|
+
// Module Infrastructure Types
|
|
10
|
+
// ------------------------------------------------------------------
|
|
11
|
+
const compute_1 = require("./compute");
|
|
12
|
+
// ------------------------------------------------------------------
|
|
9
13
|
// Module
|
|
10
14
|
// ------------------------------------------------------------------
|
|
11
15
|
// prettier-ignore
|
|
12
16
|
class TModule {
|
|
13
|
-
constructor($defs
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/** `[Json]` Returns the Type definitions for this module */
|
|
18
|
-
Defs() {
|
|
19
|
-
return (0, index_1.CreateType)({ $defs: this.ResolveDefinitionsWithIdentifiers() }, this.options);
|
|
17
|
+
constructor($defs) {
|
|
18
|
+
const computed = (0, compute_1.ComputeModuleProperties)($defs);
|
|
19
|
+
const identified = this.WithIdentifiers(computed);
|
|
20
|
+
this.$defs = identified;
|
|
20
21
|
}
|
|
21
22
|
/** `[Json]` Imports a Type by Key. */
|
|
22
23
|
Import(key, options) {
|
|
23
|
-
return (0, index_1.CreateType)({ [index_2.Kind]: 'Import', $defs: this
|
|
24
|
+
return (0, index_1.CreateType)({ [index_2.Kind]: 'Import', $defs: this.$defs, $ref: key }, options);
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return globalThis.Object.getOwnPropertyNames(
|
|
26
|
+
// prettier-ignore
|
|
27
|
+
WithIdentifiers($defs) {
|
|
28
|
+
return globalThis.Object.getOwnPropertyNames($defs).reduce((result, key) => {
|
|
29
|
+
return { ...result, [key]: { ...$defs[key], $id: key } };
|
|
30
|
+
}, {});
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
exports.TModule = TModule;
|
|
@@ -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 {};
|
|
@@ -4,61 +4,72 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.Omit = Omit;
|
|
5
5
|
const type_1 = require("../create/type");
|
|
6
6
|
const discard_1 = require("../discard/discard");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
7
|
+
const symbols_1 = require("../symbols/symbols");
|
|
8
|
+
const index_1 = require("../computed/index");
|
|
9
|
+
const index_2 = require("../literal/index");
|
|
10
|
+
const index_3 = require("../indexed/index");
|
|
11
|
+
const index_4 = require("../intersect/index");
|
|
12
|
+
const index_5 = require("../union/index");
|
|
13
|
+
const index_6 = require("../object/index");
|
|
14
|
+
// ------------------------------------------------------------------
|
|
15
|
+
// Mapped
|
|
16
|
+
// ------------------------------------------------------------------
|
|
11
17
|
const omit_from_mapped_key_1 = require("./omit-from-mapped-key");
|
|
12
18
|
const omit_from_mapped_result_1 = require("./omit-from-mapped-result");
|
|
13
|
-
const symbols_1 = require("../symbols/symbols");
|
|
14
19
|
// ------------------------------------------------------------------
|
|
15
20
|
// TypeGuard
|
|
16
21
|
// ------------------------------------------------------------------
|
|
17
22
|
const kind_1 = require("../guard/kind");
|
|
23
|
+
const value_1 = require("../guard/value");
|
|
18
24
|
// prettier-ignore
|
|
19
|
-
function FromIntersect(
|
|
20
|
-
return
|
|
25
|
+
function FromIntersect(types, propertyKeys) {
|
|
26
|
+
return types.map((type) => OmitResolve(type, propertyKeys));
|
|
21
27
|
}
|
|
22
28
|
// prettier-ignore
|
|
23
|
-
function FromUnion(
|
|
24
|
-
return
|
|
29
|
+
function FromUnion(types, propertyKeys) {
|
|
30
|
+
return types.map((type) => OmitResolve(type, propertyKeys));
|
|
25
31
|
}
|
|
26
32
|
// ------------------------------------------------------------------
|
|
27
33
|
// FromProperty
|
|
28
34
|
// ------------------------------------------------------------------
|
|
29
35
|
// prettier-ignore
|
|
30
|
-
function FromProperty(
|
|
31
|
-
const { [
|
|
36
|
+
function FromProperty(properties, key) {
|
|
37
|
+
const { [key]: _, ...R } = properties;
|
|
32
38
|
return R;
|
|
33
39
|
}
|
|
34
40
|
// prettier-ignore
|
|
35
|
-
function FromProperties(
|
|
36
|
-
return
|
|
41
|
+
function FromProperties(properties, propertyKeys) {
|
|
42
|
+
return propertyKeys.reduce((T, K2) => FromProperty(T, K2), properties);
|
|
37
43
|
}
|
|
38
44
|
// prettier-ignore
|
|
39
|
-
function FromObject(
|
|
40
|
-
const options = (0, discard_1.Discard)(
|
|
41
|
-
const
|
|
42
|
-
return (0,
|
|
45
|
+
function FromObject(properties, propertyKeys) {
|
|
46
|
+
const options = (0, discard_1.Discard)(properties, [symbols_1.TransformKind, '$id', 'required', 'properties']);
|
|
47
|
+
const omittedProperties = FromProperties(properties['properties'], propertyKeys);
|
|
48
|
+
return (0, index_6.Object)(omittedProperties, options);
|
|
49
|
+
}
|
|
50
|
+
// prettier-ignore
|
|
51
|
+
function UnionFromPropertyKeys(propertyKeys) {
|
|
52
|
+
const result = propertyKeys.reduce((result, key) => (0, kind_1.IsLiteralValue)(key) ? [...result, (0, index_2.Literal)(key)] : result, []);
|
|
53
|
+
return (0, index_5.Union)(result);
|
|
43
54
|
}
|
|
44
|
-
// ------------------------------------------------------------------
|
|
45
|
-
// OmitResolve
|
|
46
|
-
// ------------------------------------------------------------------
|
|
47
55
|
// prettier-ignore
|
|
48
|
-
function OmitResolve(
|
|
49
|
-
return ((0, kind_1.IsIntersect)(
|
|
50
|
-
(0, kind_1.IsUnion)(
|
|
51
|
-
(0, kind_1.IsObject)(
|
|
52
|
-
(0,
|
|
56
|
+
function OmitResolve(properties, propertyKeys) {
|
|
57
|
+
return ((0, kind_1.IsIntersect)(properties) ? (0, index_4.Intersect)(FromIntersect(properties.allOf, propertyKeys)) :
|
|
58
|
+
(0, kind_1.IsUnion)(properties) ? (0, index_5.Union)(FromUnion(properties.anyOf, propertyKeys)) :
|
|
59
|
+
(0, kind_1.IsObject)(properties) ? FromObject(properties, propertyKeys) :
|
|
60
|
+
(0, index_6.Object)({}));
|
|
53
61
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
63
|
+
// prettier-ignore
|
|
64
|
+
function Omit(type, key, options) {
|
|
65
|
+
const typeKey = (0, value_1.IsArray)(key) ? UnionFromPropertyKeys(key) : key;
|
|
66
|
+
const propertyKeys = (0, kind_1.IsSchema)(key) ? (0, index_3.IndexPropertyKeys)(key) : key;
|
|
67
|
+
const isTypeRef = (0, kind_1.IsRef)(type);
|
|
68
|
+
const isKeyRef = (0, kind_1.IsRef)(key);
|
|
69
|
+
return ((0, kind_1.IsMappedResult)(type) ? (0, omit_from_mapped_result_1.OmitFromMappedResult)(type, propertyKeys, options) :
|
|
70
|
+
(0, kind_1.IsMappedKey)(key) ? (0, omit_from_mapped_key_1.OmitFromMappedKey)(type, key, options) :
|
|
71
|
+
(isTypeRef && isKeyRef) ? (0, index_1.Computed)('Omit', [type, typeKey], options) :
|
|
72
|
+
(!isTypeRef && isKeyRef) ? (0, index_1.Computed)('Omit', [type, typeKey], options) :
|
|
73
|
+
(isTypeRef && !isKeyRef) ? (0, index_1.Computed)('Omit', [type, typeKey], options) :
|
|
74
|
+
(0, type_1.CreateType)({ ...OmitResolve(type, propertyKeys), ...options }));
|
|
64
75
|
}
|