typebox 1.2.8 → 1.2.10
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,9 +1,8 @@
|
|
|
1
|
-
import { type TUnreachable } from '../../../system/unreachable/index.mjs';
|
|
2
1
|
import { type TProperties, type TPropertyKeys } from '../../types/properties.mjs';
|
|
3
2
|
import { type TCyclicCheck } from './check.mjs';
|
|
4
|
-
type TResolveCandidateKeys<Context extends TProperties, Keys extends
|
|
3
|
+
type TResolveCandidateKeys<Context extends TProperties, Keys extends (keyof Context)[], Result extends (keyof Context)[] = []> = (Keys extends [infer Left extends keyof Context, ...infer Right extends (keyof Context)[]] ? TCyclicCheck<[Left], Context, Context[Left]> extends true ? TResolveCandidateKeys<Context, Right, [...Result, Left]> : TResolveCandidateKeys<Context, Right, Result> : Result);
|
|
5
4
|
/** Returns keys for context types that need to be transformed to TCyclic. */
|
|
6
|
-
export type TCyclicCandidates<Context extends TProperties, Keys extends
|
|
5
|
+
export type TCyclicCandidates<Context extends TProperties, Keys extends (keyof Context)[] = TPropertyKeys<Context>, Result extends (keyof Context)[] = TResolveCandidateKeys<Context, Keys>> = Result;
|
|
7
6
|
/** Returns keys for context types that need to be transformed to TCyclic. */
|
|
8
7
|
export declare function CyclicCandidates<Context extends TProperties>(context: Context): TCyclicCandidates<Context>;
|
|
9
8
|
export {};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import { Unreachable } from '../../../system/unreachable/index.mjs';
|
|
3
2
|
import { PropertyKeys } from '../../types/properties.mjs';
|
|
4
3
|
import { CyclicCheck } from './check.mjs';
|
|
5
4
|
function ResolveCandidateKeys(context, keys) {
|
|
6
5
|
return keys.reduce((result, left) => {
|
|
7
|
-
return left
|
|
8
|
-
?
|
|
9
|
-
|
|
10
|
-
: result
|
|
11
|
-
: Unreachable();
|
|
6
|
+
return CyclicCheck([left], context, context[left])
|
|
7
|
+
? [...result, left]
|
|
8
|
+
: result;
|
|
12
9
|
}, []);
|
|
13
10
|
}
|
|
14
11
|
/** Returns keys for context types that need to be transformed to TCyclic. */
|
|
@@ -13,12 +13,12 @@ import { type TTuple } from '../../types/tuple.mjs';
|
|
|
13
13
|
import { type TUnion } from '../../types/union.mjs';
|
|
14
14
|
import { type TRef } from '../../types/ref.mjs';
|
|
15
15
|
import { type TInterfaceDeferred } from '../../action/interface.mjs';
|
|
16
|
-
type TFromRef<Stack extends
|
|
17
|
-
type TFromProperties<Stack extends
|
|
18
|
-
type TFromTypes<Stack extends
|
|
19
|
-
type TFromType<Stack extends
|
|
16
|
+
type TFromRef<Stack extends (keyof Context)[], Context extends TProperties, Ref extends (keyof Context)> = Ref extends Stack[number] ? true : TFromType<[...Stack, Ref], Context, Context[Ref]>;
|
|
17
|
+
type TFromProperties<Stack extends (keyof Context)[], Context extends TProperties, Properties extends TProperties, Types extends TSchema[] = TPropertyValues<Properties>> = TFromTypes<Stack, Context, Types>;
|
|
18
|
+
type TFromTypes<Stack extends (keyof Context)[], Context extends TProperties, Types extends TSchema[]> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromType<Stack, Context, Left> extends true ? true : TFromTypes<Stack, Context, Right> : false;
|
|
19
|
+
type TFromType<Stack extends (keyof Context)[], Context extends TProperties, Type extends TSchema> = (Type extends TRef<infer Ref extends string> ? TFromRef<Stack, Context, Ref> : Type extends TArray<infer Type extends TSchema> ? TFromType<Stack, Context, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromType<Stack, Context, Type> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromTypes<Stack, Context, [...Parameters, InstanceType]> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromTypes<Stack, Context, [...Parameters, ReturnType]> : Type extends TInterfaceDeferred<TSchema[], infer Properties extends TProperties> ? TFromProperties<Stack, Context, Properties> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromTypes<Stack, Context, Types> : Type extends TIterator<infer Type extends TSchema> ? TFromType<Stack, Context, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromProperties<Stack, Context, Properties> : Type extends TPromise<infer Type extends TSchema> ? TFromType<Stack, Context, Type> : Type extends TUnion<infer Types extends TSchema[]> ? TFromTypes<Stack, Context, Types> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTypes<Stack, Context, Types> : Type extends TRecord<string, infer Type extends TSchema> ? TFromType<Stack, Context, Type> : false);
|
|
20
20
|
/** Performs a cyclic check on the given type. Initial key stack can be empty, but faster if specified */
|
|
21
|
-
export type TCyclicCheck<Stack extends
|
|
21
|
+
export type TCyclicCheck<Stack extends (keyof Context)[], Context extends TProperties, Type extends TSchema, Result extends boolean = TFromType<Stack, Context, Type>> = Result;
|
|
22
22
|
/** Performs a cyclic check on the given type. Initial key stack can be empty, but faster if specified */
|
|
23
|
-
export declare function CyclicCheck<Stack extends
|
|
23
|
+
export declare function CyclicCheck<Stack extends (keyof Context)[], Context extends TProperties, Type extends TSchema>(stack: [...Stack], context: Context, type: Type): TCyclicCheck<Stack, Context, Type>;
|
|
24
24
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
+
import { type TProperties } from '../../types/properties.mjs';
|
|
2
3
|
import { type TUnion } from '../../types/union.mjs';
|
|
3
4
|
import { type TObject } from '../../types/object.mjs';
|
|
4
5
|
import { type TTuple } from '../../types/tuple.mjs';
|
|
@@ -6,7 +7,7 @@ import { type TComposite } from './composite.mjs';
|
|
|
6
7
|
import { type TNarrow } from './narrow.mjs';
|
|
7
8
|
import { type TEvaluateType } from './evaluate.mjs';
|
|
8
9
|
import { type TEvaluateIntersect } from './evaluate.mjs';
|
|
9
|
-
type TIsObjectLike<Type extends TSchema> = Type extends TObject
|
|
10
|
+
type TIsObjectLike<Type extends TSchema> = (Type extends TObject<infer _ extends TProperties> ? true : Type extends TTuple<infer _ extends TSchema[]> ? true : false);
|
|
10
11
|
type TIsUnionOperand<Left extends TSchema, Right extends TSchema, IsUnionLeft extends boolean = Left extends TUnion ? true : false, IsUnionRight extends boolean = Right extends TUnion ? true : false, Result extends boolean = IsUnionLeft extends true ? true : IsUnionRight extends true ? true : false> = Result;
|
|
11
12
|
type TDistributeOperation<Left extends TSchema, Right extends TSchema, EvaluatedLeft extends TSchema = TEvaluateType<Left>, EvaluatedRight extends TSchema = TEvaluateType<Right>, IsUnionOperand extends boolean = TIsUnionOperand<EvaluatedLeft, EvaluatedRight>, IsObjectLeft extends boolean = TIsObjectLike<EvaluatedLeft>, IsObjectRight extends boolean = TIsObjectLike<EvaluatedRight>, Result extends TSchema = ([
|
|
12
13
|
IsUnionOperand
|