typebox 1.1.26 → 1.1.27
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/schema/static/properties.d.mts +27 -6
- package/build/schema/static/required.d.mts +1 -11
- package/build/schema/static/schema.d.mts +3 -2
- package/build/schema/static/static.d.mts +2 -2
- package/build/schema/static/~canonical.d.mts +7 -0
- package/package.json +1 -1
- package/readme.md +1 -1
- package/build/schema/static/~non-readonly.d.mts +0 -7
- package/build/schema/static/~readonly.d.mts +0 -6
- package/build/schema/static/~readonly.mjs +0 -2
- /package/build/schema/static/{~non-readonly.mjs → ~canonical.mjs} +0 -0
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
import type { XSchema } from '../types/schema.mjs';
|
|
2
|
+
import type { XRequired } from '../types/required.mjs';
|
|
2
3
|
import type { XStaticSchema } from './schema.mjs';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type XIsReadonly<Schema extends XSchema> = (Schema extends {
|
|
5
|
+
readOnly: true;
|
|
6
|
+
} ? true : Schema extends {
|
|
7
|
+
'~readonly': true;
|
|
8
|
+
} ? true : false);
|
|
9
|
+
type XRequiredArray<Schema extends XSchema, Result extends PropertyKey[] = Schema extends XRequired<infer Keys extends string[]> ? Keys : []> = Result;
|
|
10
|
+
type XReadonlyKeys<Properties extends Record<PropertyKey, XSchema>, ReadonlyProperties extends Record<PropertyKey, unknown> = {
|
|
11
|
+
[Key in keyof Properties as XIsReadonly<Properties[Key]> extends true ? Key : never]: unknown;
|
|
12
|
+
}, Result extends PropertyKey = keyof ReadonlyProperties> = Result;
|
|
13
|
+
type XRequiredKeys<Properties extends Record<PropertyKey, XSchema>, RequiredArray extends string[], Result extends PropertyKey = RequiredArray extends [] ? never : Extract<keyof Properties, RequiredArray[number]>> = Result;
|
|
14
|
+
type XUnknownKeys<Properties extends Record<PropertyKey, XSchema>, RequiredArray extends string[], Result extends PropertyKey = Exclude<RequiredArray[number], keyof Properties>> = Result;
|
|
15
|
+
type XOptionalKeys<Properties extends Record<PropertyKey, XSchema>, RequiredArray extends string[], Result extends PropertyKey = RequiredArray extends [] ? keyof Properties : Exclude<keyof Properties, RequiredArray[number]>> = Result;
|
|
16
|
+
type XReadonlyOptionalProperties<Stack extends string[], Root extends XSchema, OptionalKeys extends PropertyKey, Properties extends Record<PropertyKey, XSchema>> = {
|
|
17
|
+
readonly [Key in Extract<keyof Properties, OptionalKeys>]?: XStaticSchema<Stack, Root, Properties[Key]>;
|
|
6
18
|
};
|
|
7
|
-
type
|
|
8
|
-
[Key in keyof Properties
|
|
19
|
+
type XReadonlyRequiredProperties<Stack extends string[], Root extends XSchema, RequiredKeys extends PropertyKey, Properties extends Record<PropertyKey, XSchema>> = {
|
|
20
|
+
readonly [Key in Extract<keyof Properties, RequiredKeys>]: XStaticSchema<Stack, Root, Properties[Key]>;
|
|
9
21
|
};
|
|
10
|
-
|
|
22
|
+
type XOptionalProperties<Stack extends string[], Root extends XSchema, OptionalKeys extends PropertyKey, Properties extends Record<PropertyKey, XSchema>> = {
|
|
23
|
+
[Key in Extract<keyof Properties, OptionalKeys>]?: XStaticSchema<Stack, Root, Properties[Key]>;
|
|
24
|
+
};
|
|
25
|
+
type XRequiredProperties<Stack extends string[], Root extends XSchema, RequiredKeys extends PropertyKey, Properties extends Record<PropertyKey, XSchema>> = {
|
|
26
|
+
[Key in Extract<keyof Properties, RequiredKeys>]: XStaticSchema<Stack, Root, Properties[Key]>;
|
|
27
|
+
};
|
|
28
|
+
type XUnknownProperties<UnknownKeys extends PropertyKey> = {
|
|
29
|
+
[Key in UnknownKeys]: unknown;
|
|
30
|
+
};
|
|
31
|
+
export type XStaticProperties<Stack extends string[], Root extends XSchema, Schema extends XSchema, Properties extends Record<PropertyKey, XSchema>, RequiredArray extends string[] = XRequiredArray<Schema>, ReadonlyKeys extends PropertyKey = XReadonlyKeys<Properties>, OptionalKeys extends PropertyKey = XOptionalKeys<Properties, RequiredArray>, RequiredKeys extends PropertyKey = XRequiredKeys<Properties, RequiredArray>, UnknownKeys extends PropertyKey = XUnknownKeys<Properties, RequiredArray>, ReadonlyOptionalProperties extends Record<PropertyKey, unknown> = XReadonlyOptionalProperties<Stack, Root, Extract<OptionalKeys, ReadonlyKeys>, Properties>, ReadonlyRequiredProperties extends Record<PropertyKey, unknown> = XReadonlyRequiredProperties<Stack, Root, Extract<RequiredKeys, ReadonlyKeys>, Properties>, OptionalProperties extends Record<PropertyKey, unknown> = XOptionalProperties<Stack, Root, Exclude<OptionalKeys, ReadonlyKeys>, Properties>, RequiredProperties extends Record<PropertyKey, unknown> = XRequiredProperties<Stack, Root, Exclude<RequiredKeys, ReadonlyKeys>, Properties>, UnknownProperties extends Record<PropertyKey, unknown> = XUnknownProperties<UnknownKeys>, Result extends Record<PropertyKey, unknown> = (ReadonlyOptionalProperties & ReadonlyRequiredProperties & OptionalProperties & RequiredProperties & UnknownProperties)> = Result;
|
|
11
32
|
export {};
|
|
@@ -1,13 +1,3 @@
|
|
|
1
1
|
import type { XSchema } from '../types/schema.mjs';
|
|
2
2
|
import type { XProperties } from '../types/properties.mjs';
|
|
3
|
-
|
|
4
|
-
import type { XStaticSchema } from './schema.mjs';
|
|
5
|
-
type XResolveProperties<Schema extends XSchema, Result extends Record<PropertyKey, XSchema> = (Schema extends XProperties<infer Properties extends Record<PropertyKey, XSchema>> ? Properties : {})> = Result;
|
|
6
|
-
type XFromKey<Stack extends string[], Root extends XSchema, Properties extends Record<PropertyKey, XSchema>, Key extends string, Readonly extends boolean = Key extends keyof Properties ? XIsReadonly<Properties[Key]> : false, Value extends unknown = Key extends keyof Properties ? XStaticSchema<Stack, Root, Properties[Key]> : unknown, Result extends Record<PropertyKey, unknown> = (Readonly extends true ? {
|
|
7
|
-
readonly [_ in Key]: Value;
|
|
8
|
-
} : {
|
|
9
|
-
[_ in Key]: Value;
|
|
10
|
-
})> = Result;
|
|
11
|
-
type XFromKeys<Stack extends string[], Root extends XSchema, Properties extends Record<PropertyKey, XSchema>, Keys extends string[], Result extends Record<PropertyKey, unknown> = {}> = (Keys extends [infer Left extends string, ...infer Right extends string[]] ? XFromKeys<Stack, Root, Properties, Right, Result & XFromKey<Stack, Root, Properties, Left>> : Result);
|
|
12
|
-
export type XStaticRequired<Stack extends string[], Root extends XSchema, Schema extends XSchema, Keys extends string[], Properties extends Record<PropertyKey, XSchema> = XResolveProperties<Schema>, Result extends Record<PropertyKey, unknown> = XFromKeys<Stack, Root, Properties, Keys>> = Result;
|
|
13
|
-
export {};
|
|
3
|
+
export type XStaticRequired<Stack extends string[], Root extends XSchema, Schema extends XSchema, Keys extends string[], Result extends Record<PropertyKey, unknown> = Schema extends XProperties ? {} : Record<Keys[number], unknown>> = Result;
|
|
@@ -34,12 +34,13 @@ type XFromKeywords<Stack extends string[], Root extends XSchema, Schema extends
|
|
|
34
34
|
Schema extends XAllOf<infer Types extends XSchema[]> ? XStaticAllOf<Stack, Root, Types> : unknown,
|
|
35
35
|
Schema extends XAnyOf<infer Types extends XSchema[]> ? XStaticAnyOf<Stack, Root, Types> : unknown,
|
|
36
36
|
Schema extends XConst<infer Value extends unknown> ? XStaticConst<Value> : unknown,
|
|
37
|
-
Schema extends XIf<infer Type extends XSchema> ? XStaticIf<Stack, Root, Schema, Type> :
|
|
37
|
+
Schema extends XIf<infer Type extends XSchema> ? XStaticIf<Stack, Root, Schema, Type> : unknown,
|
|
38
|
+
Schema extends XEnum<infer Values extends unknown[]> ? XStaticEnum<Values> : unknown,
|
|
38
39
|
Schema extends XItems<infer Types extends XSchema[] | XSchema> ? XStaticItems<Stack, Root, Schema, Types> : unknown,
|
|
39
40
|
Schema extends XOneOf<infer Types extends XSchema[]> ? XStaticOneOf<Stack, Root, Types> : unknown,
|
|
40
41
|
Schema extends XPatternProperties<infer Properties extends Record<PropertyKey, XSchema>> ? XStaticPatternProperties<Stack, Root, Properties> : unknown,
|
|
41
42
|
Schema extends XPrefixItems<infer Types extends XSchema[]> ? XStaticPrefixItems<Stack, Root, Schema, Types> : unknown,
|
|
42
|
-
Schema extends XProperties<infer Properties extends Record<PropertyKey, XSchema>> ? XStaticProperties<Stack, Root, Properties> : unknown,
|
|
43
|
+
Schema extends XProperties<infer Properties extends Record<PropertyKey, XSchema>> ? XStaticProperties<Stack, Root, Schema, Properties> : unknown,
|
|
43
44
|
Schema extends XRef<infer Ref extends string> ? XStaticRef<Stack, Root, Ref> : unknown,
|
|
44
45
|
Schema extends XRequired<infer Keys extends string[]> ? XStaticRequired<Stack, Root, Schema, Keys> : unknown,
|
|
45
46
|
Schema extends XType<infer TypeName extends string[] | string> ? XStaticType<TypeName> : unknown,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { XSchema } from '../types/schema.mjs';
|
|
2
|
-
import type {
|
|
2
|
+
import type { XCanonical } from './~canonical.mjs';
|
|
3
3
|
import type { XStaticSchema } from './schema.mjs';
|
|
4
|
-
export type XStatic<Value extends unknown, Schema extends XSchema = Value extends XSchema ? Value : {},
|
|
4
|
+
export type XStatic<Value extends unknown, Schema extends XSchema = Value extends XSchema ? Value : {}, Canonical extends XSchema = XCanonical<Schema>, Result extends unknown = XStaticSchema<[], Canonical, Canonical>> = Result;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type XCanonicalTuple<Value extends readonly unknown[]> = (Value extends [infer Left, ...infer Right extends unknown[]] ? [XCanonical<Left>, ...XCanonicalTuple<Right>] : []);
|
|
2
|
+
type XCanonicalArray<Value extends unknown, Result extends unknown[] = XCanonical<Value>[]> = Result;
|
|
3
|
+
type XCanonicalObject<Value extends object, Result extends Record<PropertyKey, unknown> = {
|
|
4
|
+
-readonly [Key in keyof Value]: XCanonical<Value[Key]>;
|
|
5
|
+
}> = Result;
|
|
6
|
+
export type XCanonical<Schema extends unknown> = (Schema extends readonly [...infer Schemas extends unknown[]] ? XCanonicalTuple<Schemas> : Schema extends readonly (infer Schema)[] ? XCanonicalArray<Schema> : Schema extends object ? XCanonicalObject<Schema> : Schema);
|
|
7
|
+
export {};
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -196,7 +196,7 @@ type UserUpdate = Type.Static<typeof UserUpdate> // type UserUpdate = {
|
|
|
196
196
|
|
|
197
197
|
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/schema/overview) | [Example 1](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAZQMYAsCmICGcBmUIhwDkMAnmGgEYQAeA9AM6oaZEBQokscAKuWrnyES-ajXZs6dOAFo58hYqXKVqteo0zJ0gMIEwwADZptszeYuWr8tmyQQAdg3gBVBmihwAvImZYAdHrgRmgAFHwU-gDylABWaEgwoQDebHBwwAAmAFy8-P4IMFDADgDmoQCUADRpcA6YIGi5EWgFRSXl1bUsRs35hcVlKbjQWDC5RD2GRHAAvhVs8wum1qtr61pScAAKmFDuKxtHx6q29k7wAK7unj5uHv67+2HJ6W-vH5-vW+fOcNceXKpdJZCYANgArDgAIyYABMlAAzEgACyZCFoME4ADsmAAHJQAJxIAAMmWhRCqX2pcC2IJycGcg1KNXS9UaEwBUEpNN5fO+0jZDSajPaZVZcCmnJuAAFMgRMCV-PYQDN+by6ZKsL1RczFhV1YajR8trNvHB-JagA) | [Example 2](https://www.typescriptlang.org/play/#code/JYWwDg9gTgLgBAZQMYAsCmICGcBmUIhwDkMAnmGgEYQAeA9AM6oaZEBQbddcAtH-wMFDhI0WPESenbgGECYYABs003pPUbNW-hyQQAdg3gBVBmihwAvImZYAdHPBK0ACgDebOHDIUAXMQhKACs0JBgiABpPODB8ClhgNAZ-Dy8vYAATFO9yNH8iIyhgfQBzIjgAXyi0uH1MEDy4Nxy-YkLissrqtJYlbJ9Ggpgi0sjcaCwYfN7FcoroquioNABHAFdgZay4AG1oryJMsf3iOobjmqIZ9i8AXTYKgEoOLjVtd4+P1QAFTCgzVSfIHAyS6AxGOBrMwWaymcx2X7-VzNGqotHouCvPSGeBQ8wpaKZfIANgArDgAIyYABMlAAzEgACwZUloYk4ADsmAAHJQAJxIAAMGQpYwx6Ne6W27VK3TOgzxUDF4pVqq8ktq9UaMpK3Rm+UVAAEMgRMMU7HoQOU1SqNfq4DqHo8bS7XajXhUrHA7D6gA) | [Specification](https://sinclairzx81.github.io/typebox/#/docs/schema/1_spec)
|
|
198
198
|
|
|
199
|
-
TypeBox
|
|
199
|
+
TypeBox includes a high-performance JSON Schema compiler with support for drafts 3 through to 2020-12. The compiler is designed to be a lightweight industry-grade alternative to Ajv and offers improved compilation and validation performance. The compiler also offers automatic fallback to dynamic checking in JIT-restricted environments such as Cloudflare Workers.
|
|
200
200
|
|
|
201
201
|
### Example
|
|
202
202
|
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
type XFromTuple<Value extends readonly unknown[]> = (Value extends [infer Left, ...infer Right extends unknown[]] ? [XNonReadonly<Left>, ...XFromTuple<Right>] : []);
|
|
2
|
-
type XFromArray<Value extends unknown, Result extends unknown[] = XNonReadonly<Value>[]> = Result;
|
|
3
|
-
type XFromObject<Value extends object, Result extends Record<PropertyKey, unknown> = {
|
|
4
|
-
-readonly [K in keyof Value]: XNonReadonly<Value[K]>;
|
|
5
|
-
}> = Result;
|
|
6
|
-
export type XNonReadonly<Value extends unknown> = (Value extends readonly [...infer Schemas extends unknown[]] ? XFromTuple<Schemas> : Value extends readonly (infer Schema)[] ? XFromArray<Schema> : Value extends object ? XFromObject<Value> : Value);
|
|
7
|
-
export {};
|
|
File without changes
|