@sinclair/typebox 0.28.7 → 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/typebox.d.ts +5 -14
- package/typebox.js +4 -38
package/package.json
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
|
}];
|
package/typebox.js
CHANGED
|
@@ -1901,44 +1901,10 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
1901
1901
|
}
|
|
1902
1902
|
/** `[Standard]` Creates a Composite object type. */
|
|
1903
1903
|
Composite(objects, options) {
|
|
1904
|
-
const
|
|
1905
|
-
const
|
|
1906
|
-
const
|
|
1907
|
-
|
|
1908
|
-
for (const key of globalThis.Object.getOwnPropertyNames(object.properties)) {
|
|
1909
|
-
if (isOptionalAll(objects, key))
|
|
1910
|
-
optional.add(key);
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
for (const object of objects) {
|
|
1914
|
-
for (const key of globalThis.Object.getOwnPropertyNames(object.properties)) {
|
|
1915
|
-
if (!optional.has(key))
|
|
1916
|
-
required.add(key);
|
|
1917
|
-
}
|
|
1918
|
-
}
|
|
1919
|
-
const properties = {};
|
|
1920
|
-
for (const object of objects) {
|
|
1921
|
-
for (const [key, schema] of Object.entries(object.properties)) {
|
|
1922
|
-
const property = TypeClone.Clone(schema, {});
|
|
1923
|
-
if (!optional.has(key))
|
|
1924
|
-
delete property[exports.Modifier];
|
|
1925
|
-
if (key in properties) {
|
|
1926
|
-
properties[key] = TypeGuard.TIntersect(properties[key]) ? this.Intersect([...properties[key].allOf, property]) : this.Intersect([properties[key], property]);
|
|
1927
|
-
}
|
|
1928
|
-
else {
|
|
1929
|
-
properties[key] = property;
|
|
1930
|
-
}
|
|
1931
|
-
}
|
|
1932
|
-
}
|
|
1933
|
-
for (const key of globalThis.Object.getOwnPropertyNames(properties)) {
|
|
1934
|
-
properties[key] = optional.has(key) ? this.Optional(properties[key]) : properties[key];
|
|
1935
|
-
}
|
|
1936
|
-
if (required.size > 0) {
|
|
1937
|
-
return this.Create({ ...options, [exports.Kind]: 'Object', type: 'object', properties, required: [...required] });
|
|
1938
|
-
}
|
|
1939
|
-
else {
|
|
1940
|
-
return this.Create({ ...options, [exports.Kind]: 'Object', type: 'object', properties });
|
|
1941
|
-
}
|
|
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);
|
|
1942
1908
|
}
|
|
1943
1909
|
/** `[Standard]` Creates a Enum type */
|
|
1944
1910
|
Enum(item, options = {}) {
|