typebox 1.1.29 → 1.1.30
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.
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { type TProperties } from '../../types/properties.mjs';
|
|
2
2
|
import { type TSchema } from '../../types/schema.mjs';
|
|
3
3
|
import { type TNumber } from '../../types/number.mjs';
|
|
4
|
+
import { type TNever } from '../../types/never.mjs';
|
|
4
5
|
import { type TPropertyKeys } from '../../types/properties.mjs';
|
|
5
6
|
import { type TEvaluateUnion } from '../evaluate/evaluate.mjs';
|
|
6
7
|
import { type TToIndexableKeys } from '../indexable/to-indexable-keys.mjs';
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
type
|
|
8
|
+
import { type TExpandThis } from '../this/expand-this.mjs';
|
|
9
|
+
type TIndexProperty<Properties extends TProperties, Key extends string, CanonicalKey extends string = keyof Properties extends string | number ? `${keyof Properties}` : never, SelectedType extends TSchema = Key extends CanonicalKey ? Properties[Key] : TNever, Result extends TSchema = TExpandThis<Properties, SelectedType>> = Result;
|
|
10
|
+
type TIndexProperties<Properties extends TProperties, Keys extends string[], Result extends TSchema[] = []> = (Keys extends [infer Left extends string, ...infer Right extends string[]] ? TIndexProperties<Properties, Right, [...Result, TIndexProperty<Properties, Left>]> : Result);
|
|
11
|
+
type TFromIndexer<Properties extends TProperties, Indexer extends TSchema, Keys extends string[] = TToIndexableKeys<Indexer>, Variants extends TSchema[] = TIndexProperties<Properties, Keys>, Result extends TSchema = TEvaluateUnion<Variants>> = Result;
|
|
10
12
|
type TNumericKeys<Keys extends string[], Result extends string[] = []> = (Keys extends [infer Left extends string, ...infer Right extends string[]] ? Left extends `${infer _ extends number}` ? TNumericKeys<Right, [...Result, Left]> : TNumericKeys<Right, Result> : Result);
|
|
11
|
-
type TFromIndexerNumber<Properties extends TProperties, Keys extends string[] = TPropertyKeys<Properties>, NumericKeys extends string[] = TNumericKeys<Keys>, Variants extends TSchema[] =
|
|
13
|
+
type TFromIndexerNumber<Properties extends TProperties, Keys extends string[] = TPropertyKeys<Properties>, NumericKeys extends string[] = TNumericKeys<Keys>, Variants extends TSchema[] = TIndexProperties<Properties, NumericKeys>, Result extends TSchema = TEvaluateUnion<Variants>> = Result;
|
|
12
14
|
export type TFromObject<Properties extends TProperties, Indexer extends TSchema, Result extends TSchema = Indexer extends TNumber ? TFromIndexerNumber<Properties> : TFromIndexer<Properties, Indexer>> = Result;
|
|
13
15
|
export declare function FromObject<Properties extends TProperties, Indexer extends TSchema>(properties: Properties, indexer: Indexer): TFromObject<Properties, Indexer>;
|
|
14
16
|
export {};
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { IsNumber } from '../../types/number.mjs';
|
|
3
|
+
import { Never } from '../../types/never.mjs';
|
|
3
4
|
import { PropertyKeys } from '../../types/properties.mjs';
|
|
4
5
|
import { EvaluateUnion } from '../evaluate/evaluate.mjs';
|
|
5
6
|
import { ToIndexableKeys } from '../indexable/to-indexable-keys.mjs';
|
|
6
7
|
import { IntegerKey } from '../../types/record.mjs';
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
import { ExpandThis } from '../this/expand-this.mjs';
|
|
9
|
+
function IndexProperty(properties, key) {
|
|
10
|
+
const selectedType = key in properties ? properties[key] : Never();
|
|
11
|
+
const result = ExpandThis(properties, selectedType);
|
|
9
12
|
return result;
|
|
10
13
|
}
|
|
11
|
-
function
|
|
14
|
+
function IndexProperties(properties, keys) {
|
|
12
15
|
return keys.reduce((result, left) => {
|
|
13
|
-
return [...result,
|
|
16
|
+
return [...result, IndexProperty(properties, left)];
|
|
14
17
|
}, []);
|
|
15
18
|
}
|
|
16
19
|
function FromIndexer(properties, indexer) {
|
|
17
20
|
const keys = ToIndexableKeys(indexer);
|
|
18
|
-
const variants =
|
|
21
|
+
const variants = IndexProperties(properties, keys);
|
|
19
22
|
const result = EvaluateUnion(variants);
|
|
20
23
|
return result;
|
|
21
24
|
}
|
|
@@ -27,7 +30,7 @@ function NumericKeys(keys) {
|
|
|
27
30
|
function FromIndexerNumber(properties) {
|
|
28
31
|
const keys = PropertyKeys(properties);
|
|
29
32
|
const numericKeys = NumericKeys(keys);
|
|
30
|
-
const variants =
|
|
33
|
+
const variants = IndexProperties(properties, numericKeys);
|
|
31
34
|
const result = EvaluateUnion(variants);
|
|
32
35
|
return result;
|
|
33
36
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type TArray } from '../../types/array.mjs';
|
|
2
|
+
import { type TAsyncIterator } from '../../types/async-iterator.mjs';
|
|
3
|
+
import { type TConstructor } from '../../types/constructor.mjs';
|
|
4
|
+
import { type TFunction } from '../../types/function.mjs';
|
|
5
|
+
import { type TIterator } from '../../types/iterator.mjs';
|
|
6
|
+
import { type TIntersect } from '../../types/intersect.mjs';
|
|
7
|
+
import { type TObject } from '../../types/object.mjs';
|
|
8
|
+
import { type TProperties } from '../../types/properties.mjs';
|
|
9
|
+
import { type TSchema } from '../../types/schema.mjs';
|
|
10
|
+
import { type TPromise } from '../../types/promise.mjs';
|
|
11
|
+
import { type TTuple } from '../../types/tuple.mjs';
|
|
12
|
+
import { type TThis } from '../../types/this.mjs';
|
|
13
|
+
import { type TUnion } from '../../types/union.mjs';
|
|
14
|
+
type TFromTypes<Properties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromTypes<Properties, Right, [...Result, TFromType<Properties, Left>]> : Result);
|
|
15
|
+
export type TFromType<Properties extends TProperties, Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TArray<TFromType<Properties, Type>> : Type extends TAsyncIterator<infer Type extends TSchema> ? TAsyncIterator<TFromType<Properties, Type>> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TConstructor<TFromTypes<Properties, Parameters>, TFromType<Properties, InstanceType>> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TFromTypes<Properties, Parameters>, TFromType<Properties, ReturnType>> : Type extends TIterator<infer Type extends TSchema> ? TIterator<TFromType<Properties, Type>> : Type extends TPromise<infer Type extends TSchema> ? TPromise<TFromType<Properties, Type>> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TFromTypes<Properties, Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromTypes<Properties, Types>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromTypes<Properties, Types>> : Type extends TThis ? TObject<Properties> : Type);
|
|
16
|
+
export declare function FromType<Properties extends TProperties, Type extends TSchema>(properties: Properties, type: Type): TFromType<Properties, Type>;
|
|
17
|
+
export type TExpandThis<Properties extends TProperties, Type extends TSchema, Result extends TSchema = TFromType<Properties, Type>> = Result;
|
|
18
|
+
export declare function ExpandThis<Properties extends TProperties, Type extends TSchema>(properties: TProperties, type: Type): TExpandThis<Properties, Type>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
import { IsArray, Array } from '../../types/array.mjs';
|
|
3
|
+
import { IsAsyncIterator, AsyncIterator } from '../../types/async-iterator.mjs';
|
|
4
|
+
import { IsConstructor, Constructor } from '../../types/constructor.mjs';
|
|
5
|
+
import { IsFunction, Function } from '../../types/function.mjs';
|
|
6
|
+
import { IsIterator, Iterator } from '../../types/iterator.mjs';
|
|
7
|
+
import { IsIntersect, Intersect } from '../../types/intersect.mjs';
|
|
8
|
+
import { Object } from '../../types/object.mjs';
|
|
9
|
+
import { IsPromise, Promise } from '../../types/promise.mjs';
|
|
10
|
+
import { IsTuple, Tuple } from '../../types/tuple.mjs';
|
|
11
|
+
import { IsThis } from '../../types/this.mjs';
|
|
12
|
+
import { IsUnion, Union } from '../../types/union.mjs';
|
|
13
|
+
function FromTypes(properties, types) {
|
|
14
|
+
return types.map(type => FromType(properties, type));
|
|
15
|
+
}
|
|
16
|
+
export function FromType(properties, type) {
|
|
17
|
+
return (IsArray(type) ? Array(FromType(properties, type.items)) :
|
|
18
|
+
IsAsyncIterator(type) ? AsyncIterator(FromType(properties, type.iteratorItems)) :
|
|
19
|
+
IsConstructor(type) ? Constructor(FromTypes(properties, type.parameters), FromType(properties, type.instanceType)) :
|
|
20
|
+
IsFunction(type) ? Function(FromTypes(properties, type.parameters), FromType(properties, type.returnType)) :
|
|
21
|
+
IsIterator(type) ? Iterator(FromType(properties, type.iteratorItems)) :
|
|
22
|
+
IsPromise(type) ? Promise(FromType(properties, type.item)) :
|
|
23
|
+
IsTuple(type) ? Tuple(FromTypes(properties, type.items)) :
|
|
24
|
+
IsUnion(type) ? Union(FromTypes(properties, type.anyOf)) :
|
|
25
|
+
IsIntersect(type) ? Intersect(FromTypes(properties, type.allOf)) :
|
|
26
|
+
IsThis(type) ? Object(properties) :
|
|
27
|
+
type);
|
|
28
|
+
}
|
|
29
|
+
export function ExpandThis(properties, type) {
|
|
30
|
+
const result = FromType(properties, type);
|
|
31
|
+
return result;
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typebox",
|
|
3
3
|
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.30",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
7
7
|
"jsonschema"
|
|
@@ -16,37 +16,37 @@
|
|
|
16
16
|
"types": "./build/index.d.mts",
|
|
17
17
|
"module": "./build/index.mjs",
|
|
18
18
|
"exports": {
|
|
19
|
+
"./value": {
|
|
20
|
+
"import": "./build/value/index.mjs",
|
|
21
|
+
"default": "./build/value/index.mjs"
|
|
22
|
+
},
|
|
19
23
|
"./guard": {
|
|
20
24
|
"import": "./build/guard/index.mjs",
|
|
21
25
|
"default": "./build/guard/index.mjs"
|
|
22
26
|
},
|
|
23
|
-
"./
|
|
24
|
-
"import": "./build/
|
|
25
|
-
"default": "./build/
|
|
26
|
-
},
|
|
27
|
-
"./compile": {
|
|
28
|
-
"import": "./build/compile/index.mjs",
|
|
29
|
-
"default": "./build/compile/index.mjs"
|
|
27
|
+
"./schema": {
|
|
28
|
+
"import": "./build/schema/index.mjs",
|
|
29
|
+
"default": "./build/schema/index.mjs"
|
|
30
30
|
},
|
|
31
31
|
"./system": {
|
|
32
32
|
"import": "./build/system/index.mjs",
|
|
33
33
|
"default": "./build/system/index.mjs"
|
|
34
34
|
},
|
|
35
|
-
"./format": {
|
|
36
|
-
"import": "./build/format/index.mjs",
|
|
37
|
-
"default": "./build/format/index.mjs"
|
|
38
|
-
},
|
|
39
35
|
"./type": {
|
|
40
36
|
"import": "./build/type/index.mjs",
|
|
41
37
|
"default": "./build/type/index.mjs"
|
|
42
38
|
},
|
|
43
|
-
"./
|
|
44
|
-
"import": "./build/
|
|
45
|
-
"default": "./build/
|
|
39
|
+
"./compile": {
|
|
40
|
+
"import": "./build/compile/index.mjs",
|
|
41
|
+
"default": "./build/compile/index.mjs"
|
|
46
42
|
},
|
|
47
|
-
"./
|
|
48
|
-
"import": "./build/
|
|
49
|
-
"default": "./build/
|
|
43
|
+
"./error": {
|
|
44
|
+
"import": "./build/error/index.mjs",
|
|
45
|
+
"default": "./build/error/index.mjs"
|
|
46
|
+
},
|
|
47
|
+
"./format": {
|
|
48
|
+
"import": "./build/format/index.mjs",
|
|
49
|
+
"default": "./build/format/index.mjs"
|
|
50
50
|
},
|
|
51
51
|
".": {
|
|
52
52
|
"import": "./build/index.mjs",
|
|
@@ -55,29 +55,29 @@
|
|
|
55
55
|
},
|
|
56
56
|
"typesVersions": {
|
|
57
57
|
"*": {
|
|
58
|
+
"value": [
|
|
59
|
+
"./build/value/index.d.mts"
|
|
60
|
+
],
|
|
58
61
|
"guard": [
|
|
59
62
|
"./build/guard/index.d.mts"
|
|
60
63
|
],
|
|
61
|
-
"
|
|
62
|
-
"./build/
|
|
63
|
-
],
|
|
64
|
-
"compile": [
|
|
65
|
-
"./build/compile/index.d.mts"
|
|
64
|
+
"schema": [
|
|
65
|
+
"./build/schema/index.d.mts"
|
|
66
66
|
],
|
|
67
67
|
"system": [
|
|
68
68
|
"./build/system/index.d.mts"
|
|
69
69
|
],
|
|
70
|
-
"format": [
|
|
71
|
-
"./build/format/index.d.mts"
|
|
72
|
-
],
|
|
73
70
|
"type": [
|
|
74
71
|
"./build/type/index.d.mts"
|
|
75
72
|
],
|
|
76
|
-
"
|
|
77
|
-
"./build/
|
|
73
|
+
"compile": [
|
|
74
|
+
"./build/compile/index.d.mts"
|
|
78
75
|
],
|
|
79
|
-
"
|
|
80
|
-
"./build/
|
|
76
|
+
"error": [
|
|
77
|
+
"./build/error/index.d.mts"
|
|
78
|
+
],
|
|
79
|
+
"format": [
|
|
80
|
+
"./build/format/index.d.mts"
|
|
81
81
|
],
|
|
82
82
|
".": [
|
|
83
83
|
"./build/index.d.mts"
|