@sinclair/typebox 0.34.0 → 0.34.2

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.
Files changed (146) hide show
  1. package/build/cjs/syntax/runtime.d.ts +4 -1
  2. package/build/cjs/syntax/runtime.js +3 -1
  3. package/build/cjs/syntax/static.d.ts +3 -3
  4. package/build/cjs/type/array/array.d.ts +1 -1
  5. package/build/cjs/type/awaited/awaited.d.ts +8 -3
  6. package/build/cjs/type/awaited/awaited.js +20 -20
  7. package/build/cjs/type/computed/computed.d.ts +9 -0
  8. package/build/cjs/type/computed/computed.js +10 -0
  9. package/build/cjs/type/computed/index.d.ts +1 -0
  10. package/build/cjs/type/computed/index.js +18 -0
  11. package/build/cjs/type/guard/kind.d.ts +9 -4
  12. package/build/cjs/type/guard/kind.js +10 -0
  13. package/build/cjs/type/guard/type.d.ts +6 -3
  14. package/build/cjs/type/guard/type.js +6 -0
  15. package/build/cjs/type/indexed/indexed-from-mapped-key.d.ts +6 -6
  16. package/build/cjs/type/indexed/indexed-from-mapped-key.js +10 -10
  17. package/build/cjs/type/indexed/indexed-from-mapped-result.d.ts +5 -5
  18. package/build/cjs/type/indexed/indexed-from-mapped-result.js +11 -10
  19. package/build/cjs/type/indexed/indexed-property-keys.d.ts +6 -6
  20. package/build/cjs/type/indexed/indexed-property-keys.js +14 -14
  21. package/build/cjs/type/indexed/indexed.d.ts +34 -20
  22. package/build/cjs/type/indexed/indexed.js +59 -46
  23. package/build/cjs/type/intersect/intersect-evaluated.d.ts +6 -6
  24. package/build/cjs/type/intersect/intersect-evaluated.js +16 -16
  25. package/build/cjs/type/intersect/intersect.d.ts +2 -2
  26. package/build/cjs/type/intersect/intersect.js +6 -6
  27. package/build/cjs/type/keyof/keyof-from-mapped-result.d.ts +6 -6
  28. package/build/cjs/type/keyof/keyof-from-mapped-result.js +10 -10
  29. package/build/cjs/type/keyof/keyof-property-keys.d.ts +7 -7
  30. package/build/cjs/type/keyof/keyof-property-keys.js +22 -22
  31. package/build/cjs/type/keyof/keyof.d.ts +11 -6
  32. package/build/cjs/type/keyof/keyof.js +22 -13
  33. package/build/cjs/type/module/compute.d.ts +54 -0
  34. package/build/cjs/type/module/compute.js +154 -0
  35. package/build/cjs/type/module/infer.d.ts +43 -0
  36. package/build/cjs/type/module/infer.js +3 -0
  37. package/build/cjs/type/module/module.d.ts +8 -52
  38. package/build/cjs/type/module/module.js +14 -11
  39. package/build/cjs/type/not/not.d.ts +1 -1
  40. package/build/cjs/type/not/not.js +2 -2
  41. package/build/cjs/type/omit/omit-from-mapped-key.d.ts +6 -6
  42. package/build/cjs/type/omit/omit-from-mapped-key.js +10 -12
  43. package/build/cjs/type/omit/omit-from-mapped-result.d.ts +5 -5
  44. package/build/cjs/type/omit/omit-from-mapped-result.js +10 -10
  45. package/build/cjs/type/omit/omit.d.ts +26 -14
  46. package/build/cjs/type/omit/omit.js +46 -35
  47. package/build/cjs/type/partial/partial.d.ts +11 -7
  48. package/build/cjs/type/partial/partial.js +36 -24
  49. package/build/cjs/type/pick/pick-from-mapped-key.d.ts +6 -6
  50. package/build/cjs/type/pick/pick-from-mapped-key.js +10 -10
  51. package/build/cjs/type/pick/pick-from-mapped-result.d.ts +5 -5
  52. package/build/cjs/type/pick/pick-from-mapped-result.js +10 -10
  53. package/build/cjs/type/pick/pick.d.ts +25 -15
  54. package/build/cjs/type/pick/pick.js +47 -36
  55. package/build/cjs/type/record/record.d.ts +4 -2
  56. package/build/cjs/type/record/record.js +31 -28
  57. package/build/cjs/type/required/required.d.ts +12 -8
  58. package/build/cjs/type/required/required.js +37 -25
  59. package/build/cjs/type/tuple/tuple.d.ts +1 -1
  60. package/build/cjs/type/tuple/tuple.js +4 -4
  61. package/build/cjs/type/type/javascript.d.ts +10 -10
  62. package/build/cjs/type/type/javascript.js +6 -6
  63. package/build/cjs/type/type/json.d.ts +41 -51
  64. package/build/cjs/type/type/json.js +40 -40
  65. package/build/cjs/type/union/union-evaluated.d.ts +6 -6
  66. package/build/cjs/type/union/union-evaluated.js +11 -10
  67. package/build/cjs/type/union/union.d.ts +1 -1
  68. package/build/cjs/type/union/union.js +4 -4
  69. package/build/cjs/value/check/check.js +3 -3
  70. package/build/cjs/value/transform/decode.js +7 -7
  71. package/build/cjs/value/transform/encode.js +7 -7
  72. package/build/cjs/value/transform/has.js +18 -18
  73. package/build/esm/syntax/runtime.d.mts +4 -1
  74. package/build/esm/syntax/runtime.mjs +3 -1
  75. package/build/esm/syntax/static.d.mts +3 -3
  76. package/build/esm/type/array/array.d.mts +1 -1
  77. package/build/esm/type/awaited/awaited.d.mts +8 -3
  78. package/build/esm/type/awaited/awaited.mjs +20 -20
  79. package/build/esm/type/computed/computed.d.mts +9 -0
  80. package/build/esm/type/computed/computed.mjs +6 -0
  81. package/build/esm/type/computed/index.d.mts +1 -0
  82. package/build/esm/type/computed/index.mjs +1 -0
  83. package/build/esm/type/guard/kind.d.mts +9 -4
  84. package/build/esm/type/guard/kind.mjs +8 -0
  85. package/build/esm/type/guard/type.d.mts +6 -3
  86. package/build/esm/type/guard/type.mjs +5 -0
  87. package/build/esm/type/indexed/indexed-from-mapped-key.d.mts +6 -6
  88. package/build/esm/type/indexed/indexed-from-mapped-key.mjs +10 -10
  89. package/build/esm/type/indexed/indexed-from-mapped-result.d.mts +5 -5
  90. package/build/esm/type/indexed/indexed-from-mapped-result.mjs +11 -10
  91. package/build/esm/type/indexed/indexed-property-keys.d.mts +6 -6
  92. package/build/esm/type/indexed/indexed-property-keys.mjs +14 -14
  93. package/build/esm/type/indexed/indexed.d.mts +34 -20
  94. package/build/esm/type/indexed/indexed.mjs +55 -42
  95. package/build/esm/type/intersect/intersect-evaluated.d.mts +6 -6
  96. package/build/esm/type/intersect/intersect-evaluated.mjs +16 -16
  97. package/build/esm/type/intersect/intersect.d.mts +2 -2
  98. package/build/esm/type/intersect/intersect.mjs +6 -6
  99. package/build/esm/type/keyof/keyof-from-mapped-result.d.mts +6 -6
  100. package/build/esm/type/keyof/keyof-from-mapped-result.mjs +10 -10
  101. package/build/esm/type/keyof/keyof-property-keys.d.mts +7 -7
  102. package/build/esm/type/keyof/keyof-property-keys.mjs +22 -22
  103. package/build/esm/type/keyof/keyof.d.mts +11 -6
  104. package/build/esm/type/keyof/keyof.mjs +22 -13
  105. package/build/esm/type/module/compute.d.mts +54 -0
  106. package/build/esm/type/module/compute.mjs +148 -0
  107. package/build/esm/type/module/infer.d.mts +43 -0
  108. package/build/esm/type/module/infer.mjs +1 -0
  109. package/build/esm/type/module/module.d.mts +8 -52
  110. package/build/esm/type/module/module.mjs +14 -11
  111. package/build/esm/type/not/not.d.mts +1 -1
  112. package/build/esm/type/not/not.mjs +2 -2
  113. package/build/esm/type/omit/omit-from-mapped-key.d.mts +6 -6
  114. package/build/esm/type/omit/omit-from-mapped-key.mjs +10 -12
  115. package/build/esm/type/omit/omit-from-mapped-result.d.mts +5 -5
  116. package/build/esm/type/omit/omit-from-mapped-result.mjs +10 -10
  117. package/build/esm/type/omit/omit.d.mts +26 -14
  118. package/build/esm/type/omit/omit.mjs +43 -32
  119. package/build/esm/type/partial/partial.d.mts +11 -7
  120. package/build/esm/type/partial/partial.mjs +29 -17
  121. package/build/esm/type/pick/pick-from-mapped-key.d.mts +6 -6
  122. package/build/esm/type/pick/pick-from-mapped-key.mjs +10 -10
  123. package/build/esm/type/pick/pick-from-mapped-result.d.mts +5 -5
  124. package/build/esm/type/pick/pick-from-mapped-result.mjs +10 -10
  125. package/build/esm/type/pick/pick.d.mts +25 -15
  126. package/build/esm/type/pick/pick.mjs +43 -32
  127. package/build/esm/type/record/record.d.mts +4 -2
  128. package/build/esm/type/record/record.mjs +15 -12
  129. package/build/esm/type/required/required.d.mts +12 -8
  130. package/build/esm/type/required/required.mjs +33 -21
  131. package/build/esm/type/tuple/tuple.d.mts +1 -1
  132. package/build/esm/type/tuple/tuple.mjs +4 -4
  133. package/build/esm/type/type/javascript.d.mts +10 -10
  134. package/build/esm/type/type/javascript.mjs +6 -6
  135. package/build/esm/type/type/json.d.mts +41 -51
  136. package/build/esm/type/type/json.mjs +40 -40
  137. package/build/esm/type/union/union-evaluated.d.mts +6 -6
  138. package/build/esm/type/union/union-evaluated.mjs +11 -10
  139. package/build/esm/type/union/union.d.mts +1 -1
  140. package/build/esm/type/union/union.mjs +4 -4
  141. package/build/esm/value/check/check.mjs +2 -2
  142. package/build/esm/value/transform/decode.mjs +2 -2
  143. package/build/esm/value/transform/encode.mjs +2 -2
  144. package/build/esm/value/transform/has.mjs +2 -2
  145. package/package.json +1 -1
  146. 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 {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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 { TObject, TProperties } from '../object/index';
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
- type InferImport<Properties extends TProperties, Key extends keyof Properties, ModuleProperties extends TProperties> = (Infer<Properties[Key], ModuleProperties>);
33
- type InferRef<Ref extends string, Properties extends TProperties> = (Ref extends keyof Properties ? Infer<Properties[Ref], Properties> : never);
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: InferImport<ModuleProperties, Key, ModuleProperties>;
15
+ static: TInferFromModuleKey<ModuleProperties, Key>;
55
16
  $defs: ModuleProperties;
56
17
  $ref: Key;
57
18
  }
58
- export declare class TModule<Properties extends TProperties> {
19
+ export declare class TModule<ModuleProperties extends TProperties, ComputedModuleProperties extends TProperties = TComputeModuleProperties<ModuleProperties>> {
59
20
  private readonly $defs;
60
- private readonly options;
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 Properties>(key: Key, options?: SchemaOptions): TImport<Properties, Key>;
66
- /** `[Internal]` For each definition, assign an `$id` property. */
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, options = {}) {
14
- this.$defs = $defs;
15
- this.options = options;
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.ResolveDefinitionsWithIdentifiers(), $ref: key }, options);
24
+ return (0, index_1.CreateType)({ [index_2.Kind]: 'Import', $defs: this.$defs, $ref: key }, options);
24
25
  }
25
- /** `[Internal]` For each definition, assign an `$id` property. */
26
- ResolveDefinitionsWithIdentifiers() {
27
- return globalThis.Object.getOwnPropertyNames(this.$defs).reduce((Result, Key) => ({ ...Result, [Key]: { ...this.$defs[Key], $id: Key } }), {});
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<T extends TSchema>(not: T, options?: SchemaOptions): TNot<T>;
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(not, options) {
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<T extends TSchema, K extends PropertyKey> = {
6
- [_ in K]: TOmit<T, [K]>;
5
+ type TFromPropertyKey<Type extends TSchema, Key extends PropertyKey> = {
6
+ [_ in Key]: TOmit<Type, [Key]>;
7
7
  };
8
- type TFromPropertyKeys<T extends TSchema, K extends PropertyKey[], Acc extends TProperties = {}> = (K extends [infer LK extends PropertyKey, ...infer RK extends PropertyKey[]] ? TFromPropertyKeys<T, RK, Acc & TFromPropertyKey<T, LK>> : Acc);
9
- type TFromMappedKey<T extends TSchema, K extends TMappedKey> = (TFromPropertyKeys<T, K['keys']>);
10
- export type TOmitFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>> = (TMappedResult<P>);
11
- export declare function OmitFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TFromMappedKey<T, K>>(T: T, K: K, options?: SchemaOptions): TMappedResult<P>;
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(T, K, options) {
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(T, K, options) {
16
- return K.reduce((Acc, LK) => {
17
- return { ...Acc, ...FromPropertyKey(T, LK, options) };
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(T, K, options) {
22
- return FromPropertyKeys(T, K.keys, options);
19
+ function FromMappedKey(type, mappedKey, options) {
20
+ return FromPropertyKeys(type, mappedKey.keys, options);
23
21
  }
24
22
  // prettier-ignore
25
- function OmitFromMappedKey(T, K, options) {
26
- const P = FromMappedKey(T, K, options);
27
- return (0, index_1.MappedResult)(P);
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<P extends TProperties, K extends PropertyKey[]> = ({
7
- [K2 in keyof P]: TOmit<P[K2], K>;
6
+ type TFromProperties<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = ({
7
+ [K2 in keyof Properties]: TOmit<Properties[K2], PropertyKeys>;
8
8
  });
9
- type TFromMappedResult<R extends TMappedResult, K extends PropertyKey[]> = (Evaluate<TFromProperties<R['properties'], K>>);
10
- export type TOmitFromMappedResult<T extends TMappedResult, K extends PropertyKey[], P extends TProperties = TFromMappedResult<T, K>> = (Ensure<TMappedResult<P>>);
11
- export declare function OmitFromMappedResult<R extends TMappedResult, K extends PropertyKey[], P extends TProperties = TFromMappedResult<R, K>>(R: R, K: [...K], options?: SchemaOptions): TMappedResult<P>;
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(P, K, options) {
10
- const Acc = {};
11
- for (const K2 of globalThis.Object.getOwnPropertyNames(P))
12
- Acc[K2] = (0, omit_1.Omit)(P[K2], K, (0, value_1.Clone)(options));
13
- return Acc;
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(R, K, options) {
17
- return FromProperties(R.properties, K, options);
16
+ function FromMappedResult(mappedResult, propertyKeys, options) {
17
+ return FromProperties(mappedResult.properties, propertyKeys, options);
18
18
  }
19
19
  // prettier-ignore
20
- function OmitFromMappedResult(R, K, options) {
21
- const P = FromMappedResult(R, K, options);
22
- return (0, index_1.MappedResult)(P);
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 TIndexPropertyKeys } from '../indexed/index';
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<T extends TSchema[], K extends PropertyKey[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect<R, K, [...Acc, TOmit<L, K>]> : Acc);
12
- type TFromUnion<T extends TSchema[], K extends PropertyKey[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, K, [...Acc, TOmit<L, K>]> : Acc);
13
- type TFromProperties<T extends TProperties, K extends PropertyKey[], I extends PropertyKey = TupleToUnion<K>> = Evaluate<Omit<T, I>>;
14
- type TFromObject<T extends TObject, K extends PropertyKey[], Properties extends TProperties = T['properties']> = Ensure<TObject<(TFromProperties<Properties, K>)>>;
15
- export type TOmit<T extends TProperties, K extends PropertyKey[]> = (T extends TRecursive<infer S extends TSchema> ? TRecursive<TOmit<S, K>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<TFromIntersect<S, K>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<TFromUnion<S, K>> : T extends TObject<infer S extends TProperties> ? TFromObject<TObject<S>, K> : TObject<{}>);
16
- /** `[Json]` Constructs a type whose keys are omitted from the given type */
17
- export declare function Omit<T extends TMappedResult, K extends PropertyKey[]>(T: T, K: [...K], options?: SchemaOptions): TOmitFromMappedResult<T, K>;
18
- /** `[Json]` Constructs a type whose keys are omitted from the given type */
19
- export declare function Omit<T extends TSchema, K extends TMappedKey>(T: T, K: K, options?: SchemaOptions): TOmitFromMappedKey<T, K>;
20
- /** `[Json]` Constructs a type whose keys are omitted from the given type */
21
- export declare function Omit<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TOmit<T, I>;
22
- /** `[Json]` Constructs a type whose keys are omitted from the given type */
23
- export declare function Omit<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TOmit<T, K>;
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 index_1 = require("../intersect/index");
8
- const index_2 = require("../union/index");
9
- const index_3 = require("../object/index");
10
- const index_4 = require("../indexed/index");
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(T, K) {
20
- return T.map((T) => OmitResolve(T, K));
25
+ function FromIntersect(types, propertyKeys) {
26
+ return types.map((type) => OmitResolve(type, propertyKeys));
21
27
  }
22
28
  // prettier-ignore
23
- function FromUnion(T, K) {
24
- return T.map((T) => OmitResolve(T, K));
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(T, K) {
31
- const { [K]: _, ...R } = T;
36
+ function FromProperty(properties, key) {
37
+ const { [key]: _, ...R } = properties;
32
38
  return R;
33
39
  }
34
40
  // prettier-ignore
35
- function FromProperties(T, K) {
36
- return K.reduce((T, K2) => FromProperty(T, K2), T);
41
+ function FromProperties(properties, propertyKeys) {
42
+ return propertyKeys.reduce((T, K2) => FromProperty(T, K2), properties);
37
43
  }
38
44
  // prettier-ignore
39
- function FromObject(T, K) {
40
- const options = (0, discard_1.Discard)(T, [symbols_1.TransformKind, '$id', 'required', 'properties']);
41
- const properties = FromProperties(T['properties'], K);
42
- return (0, index_3.Object)(properties, options);
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(T, K) {
49
- return ((0, kind_1.IsIntersect)(T) ? (0, index_1.Intersect)(FromIntersect(T.allOf, K)) :
50
- (0, kind_1.IsUnion)(T) ? (0, index_2.Union)(FromUnion(T.anyOf, K)) :
51
- (0, kind_1.IsObject)(T) ? FromObject(T, K) :
52
- (0, index_3.Object)({}));
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
- function Omit(T, K, options) {
55
- // mapped
56
- if ((0, kind_1.IsMappedKey)(K))
57
- return (0, omit_from_mapped_key_1.OmitFromMappedKey)(T, K, options);
58
- if ((0, kind_1.IsMappedResult)(T))
59
- return (0, omit_from_mapped_result_1.OmitFromMappedResult)(T, K, options);
60
- // non-mapped
61
- const I = (0, kind_1.IsSchema)(K) ? (0, index_4.IndexPropertyKeys)(K) : K;
62
- // special: mapping types require overridable options
63
- return (0, type_1.CreateType)({ ...OmitResolve(T, I), ...options });
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
  }