@sinclair/typebox 0.28.6 → 0.28.8
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/package.json +1 -1
- package/readme.md +1 -1
- package/typebox.d.ts +6 -15
- package/typebox.js +6 -39
package/package.json
CHANGED
package/readme.md
CHANGED
package/typebox.d.ts
CHANGED
|
@@ -96,20 +96,11 @@ export interface TBoolean extends TSchema {
|
|
|
96
96
|
}
|
|
97
97
|
export type TConstructorParameters<T extends TConstructor<TSchema[], TSchema>> = TTuple<T['parameters']>;
|
|
98
98
|
export type TInstanceType<T extends TConstructor<TSchema[], TSchema>> = T['returns'];
|
|
99
|
-
export type
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
export type
|
|
103
|
-
export type
|
|
104
|
-
export type TCompositePropertiesWithKey1<T extends TObject, K extends Key> = K extends keyof T['properties'] ? [T['properties'][K]] : [];
|
|
105
|
-
export type TCompositePropertiesWithKey2<T extends TObject[], K extends Key> = T extends [infer L, ...infer R] ? [...TCompositePropertiesWithKey1<Assert<L, TObject>, K>, ...TCompositePropertiesWithKey2<Assert<R, TObject[]>, K>] : [];
|
|
106
|
-
export type TCompositeObjectProperty<T extends TObject[], K extends Key> = TCompositePropertiesWithKey2<T, K> extends infer S ? TCompositeOptional<AssertRest<S>> extends true ? {
|
|
107
|
-
[_ in K]: TOptional<IntersectType<AssertRest<S>>>;
|
|
108
|
-
} : {
|
|
109
|
-
[_ in K]: IntersectType<AssertRest<S>>;
|
|
110
|
-
} : {};
|
|
111
|
-
export type TCompositeObjectsWithKeys<T extends TObject[], K extends Key[]> = K extends [infer L, ...infer R] ? L extends Key ? TCompositeObjectProperty<T, L> & TCompositeObjectsWithKeys<T, Assert<R, Key[]>> : {} : {};
|
|
112
|
-
export type TComposite<T extends TObject[]> = Ensure<TObject<Evaluate<TCompositeObjectsWithKeys<T, Assert<TCompositeKeyOf<T>, Key[]>>>>>;
|
|
99
|
+
export type TCompositeReduce<T extends TIntersect<TObject[]>, K extends string[]> = K extends [infer L, ...infer R] ? {
|
|
100
|
+
[_ in Assert<L, string>]: TIndexType<T, Assert<L, string>>;
|
|
101
|
+
} & TCompositeReduce<T, Assert<R, string[]>> : {};
|
|
102
|
+
export type TCompositeSelect<T extends TIntersect<TObject[]>> = UnionToTuple<keyof Static<T>> extends infer K ? Evaluate<TCompositeReduce<T, Assert<K, string[]>>> : {};
|
|
103
|
+
export type TComposite<T extends TObject[]> = TIntersect<T> extends infer R ? TObject<TCompositeSelect<Assert<R, TIntersect<TObject[]>>>> : TObject<{}>;
|
|
113
104
|
export type TConstructorParameterArray<T extends readonly TSchema[], P extends unknown[]> = [...{
|
|
114
105
|
[K in keyof T]: Static<AssertType<T[K]>, P>;
|
|
115
106
|
}];
|
|
@@ -203,7 +194,7 @@ export interface TIntersect<T extends TSchema[] = TSchema[]> extends TSchema, In
|
|
|
203
194
|
allOf: [...T];
|
|
204
195
|
}
|
|
205
196
|
export type TKeyOfProperties<T extends TSchema> = Static<T> extends infer S ? UnionToTuple<{
|
|
206
|
-
[K in keyof S]: TLiteral
|
|
197
|
+
[K in keyof S]: TLiteral<Assert<K, TLiteralValue>>;
|
|
207
198
|
}[keyof S]> : [];
|
|
208
199
|
export type TKeyOfIndicesArray<T extends TSchema[]> = UnionToTuple<keyof T & `${number}`>;
|
|
209
200
|
export type TKeyOfIndices<T extends TSchema[]> = AssertRest<TKeyOfIndicesArray<T> extends infer R ? {
|
package/typebox.js
CHANGED
|
@@ -1440,7 +1440,8 @@ var IndexedAccessor;
|
|
|
1440
1440
|
return exports.Type.Never();
|
|
1441
1441
|
}
|
|
1442
1442
|
function Resolve(schema, keys, options = {}) {
|
|
1443
|
-
|
|
1443
|
+
// prettier-ignore
|
|
1444
|
+
return exports.Type.Union(keys.map((key) => Visit(schema, key.toString())), options);
|
|
1444
1445
|
}
|
|
1445
1446
|
IndexedAccessor.Resolve = Resolve;
|
|
1446
1447
|
})(IndexedAccessor = exports.IndexedAccessor || (exports.IndexedAccessor = {}));
|
|
@@ -1900,44 +1901,10 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
1900
1901
|
}
|
|
1901
1902
|
/** `[Standard]` Creates a Composite object type. */
|
|
1902
1903
|
Composite(objects, options) {
|
|
1903
|
-
const
|
|
1904
|
-
const
|
|
1905
|
-
const
|
|
1906
|
-
|
|
1907
|
-
for (const key of globalThis.Object.getOwnPropertyNames(object.properties)) {
|
|
1908
|
-
if (isOptionalAll(objects, key))
|
|
1909
|
-
optional.add(key);
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
for (const object of objects) {
|
|
1913
|
-
for (const key of globalThis.Object.getOwnPropertyNames(object.properties)) {
|
|
1914
|
-
if (!optional.has(key))
|
|
1915
|
-
required.add(key);
|
|
1916
|
-
}
|
|
1917
|
-
}
|
|
1918
|
-
const properties = {};
|
|
1919
|
-
for (const object of objects) {
|
|
1920
|
-
for (const [key, schema] of Object.entries(object.properties)) {
|
|
1921
|
-
const property = TypeClone.Clone(schema, {});
|
|
1922
|
-
if (!optional.has(key))
|
|
1923
|
-
delete property[exports.Modifier];
|
|
1924
|
-
if (key in properties) {
|
|
1925
|
-
properties[key] = TypeGuard.TIntersect(properties[key]) ? this.Intersect([...properties[key].allOf, property]) : this.Intersect([properties[key], property]);
|
|
1926
|
-
}
|
|
1927
|
-
else {
|
|
1928
|
-
properties[key] = property;
|
|
1929
|
-
}
|
|
1930
|
-
}
|
|
1931
|
-
}
|
|
1932
|
-
for (const key of globalThis.Object.getOwnPropertyNames(properties)) {
|
|
1933
|
-
properties[key] = optional.has(key) ? this.Optional(properties[key]) : properties[key];
|
|
1934
|
-
}
|
|
1935
|
-
if (required.size > 0) {
|
|
1936
|
-
return this.Create({ ...options, [exports.Kind]: 'Object', type: 'object', properties, required: [...required] });
|
|
1937
|
-
}
|
|
1938
|
-
else {
|
|
1939
|
-
return this.Create({ ...options, [exports.Kind]: 'Object', type: 'object', properties });
|
|
1940
|
-
}
|
|
1904
|
+
const intersect = exports.Type.Intersect(objects, {});
|
|
1905
|
+
const keys = KeyResolver.ResolveKeys(intersect, { includePatterns: false });
|
|
1906
|
+
const properties = keys.reduce((acc, key) => ({ ...acc, [key]: exports.Type.Index(intersect, [key]) }), {});
|
|
1907
|
+
return exports.Type.Object(properties, options);
|
|
1941
1908
|
}
|
|
1942
1909
|
/** `[Standard]` Creates a Enum type */
|
|
1943
1910
|
Enum(item, options = {}) {
|