typebox 1.0.73 → 1.0.75
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,5 +1,4 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
-
import { type TIntersect } from '../../types/intersect.mjs';
|
|
3
2
|
import { type TUnion } from '../../types/union.mjs';
|
|
4
3
|
import { type TObject } from '../../types/object.mjs';
|
|
5
4
|
import { type TTuple } from '../../types/tuple.mjs';
|
|
@@ -7,18 +6,29 @@ import { type TComposite } from './composite.mjs';
|
|
|
7
6
|
import { type TNarrow } from './narrow.mjs';
|
|
8
7
|
import { type TEvaluateType } from './evaluate.mjs';
|
|
9
8
|
import { type TEvaluateIntersect } from './evaluate.mjs';
|
|
10
|
-
type
|
|
11
|
-
type
|
|
12
|
-
|
|
9
|
+
type TIsObjectLike<Type extends TSchema> = Type extends TObject | TTuple ? true : false;
|
|
10
|
+
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 = ([
|
|
11
|
+
IsUnionLeft,
|
|
12
|
+
IsUnionRight
|
|
13
|
+
] extends [true, true] ? true : [
|
|
14
|
+
IsUnionLeft,
|
|
15
|
+
IsUnionRight
|
|
16
|
+
] extends [false, true] ? true : [
|
|
17
|
+
IsUnionLeft,
|
|
18
|
+
IsUnionRight
|
|
19
|
+
] extends [true, false] ? true : false)> = Result;
|
|
20
|
+
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 = ([
|
|
21
|
+
IsUnionOperand
|
|
22
|
+
] extends [true] ? TEvaluateIntersect<[EvaluatedLeft, EvaluatedRight]> : [
|
|
13
23
|
IsObjectLeft,
|
|
14
24
|
IsObjectRight
|
|
15
|
-
] extends [true, true] ? TComposite<
|
|
25
|
+
] extends [true, true] ? TComposite<EvaluatedLeft, EvaluatedRight> : [
|
|
16
26
|
IsObjectLeft,
|
|
17
27
|
IsObjectRight
|
|
18
|
-
] extends [true, false] ?
|
|
28
|
+
] extends [true, false] ? EvaluatedLeft : [
|
|
19
29
|
IsObjectLeft,
|
|
20
30
|
IsObjectRight
|
|
21
|
-
] extends [false, true] ?
|
|
31
|
+
] extends [false, true] ? EvaluatedRight : TNarrow<EvaluatedLeft, EvaluatedRight>)> = Result;
|
|
22
32
|
type TDistributeType<Type extends TSchema, Distribution extends TSchema[], Result extends TSchema[] = []> = (Distribution extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TDistributeType<Type, Right, [...Result, TDistributeOperation<Type, Left>]> : Result extends [] ? [Type] : Result);
|
|
23
33
|
type TDistributeUnion<Types extends TSchema[], Distribution extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TDistributeUnion<Right, Distribution, [...Result, ...TDistribute<[Left], Distribution>]> : Result);
|
|
24
34
|
export type TDistribute<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TUnion<infer UnionTypes extends TSchema[]> ? TDistribute<Right, TDistributeUnion<UnionTypes, Result>> : TDistribute<Right, TDistributeType<Left, Result>> : Result);
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// deno-fmt-ignore-file
|
|
3
3
|
import { Guard } from '../../../guard/index.mjs';
|
|
4
4
|
import { IsSchema } from '../../types/schema.mjs';
|
|
5
|
-
import { IsIntersect } from '../../types/intersect.mjs';
|
|
6
5
|
import { IsUnion } from '../../types/union.mjs';
|
|
7
6
|
import { IsObject } from '../../types/object.mjs';
|
|
8
7
|
import { IsTuple } from '../../types/tuple.mjs';
|
|
@@ -10,23 +9,28 @@ import { Composite } from './composite.mjs';
|
|
|
10
9
|
import { Narrow } from './narrow.mjs';
|
|
11
10
|
import { EvaluateType } from './evaluate.mjs';
|
|
12
11
|
import { EvaluateIntersect } from './evaluate.mjs';
|
|
13
|
-
function
|
|
12
|
+
function IsObjectLike(type) {
|
|
14
13
|
return IsObject(type) || IsTuple(type);
|
|
15
14
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
function IsUnionOperand(left, right) {
|
|
16
|
+
const isUnionLeft = IsUnion(left);
|
|
17
|
+
const isUnionRight = IsUnion(right);
|
|
18
|
+
return (isUnionLeft && isUnionRight ? true :
|
|
19
|
+
!isUnionLeft && isUnionRight ? true :
|
|
20
|
+
isUnionLeft && !isUnionRight ? true :
|
|
21
|
+
false);
|
|
20
22
|
}
|
|
21
23
|
function DistributeOperation(left, right) {
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
const evaluatedLeft = EvaluateType(left);
|
|
25
|
+
const evaluatedRight = EvaluateType(right);
|
|
26
|
+
const isUnionOperand = IsUnionOperand(evaluatedLeft, evaluatedRight);
|
|
27
|
+
const isObjectLeft = IsObjectLike(evaluatedLeft);
|
|
28
|
+
const IsObjectRight = IsObjectLike(evaluatedRight);
|
|
29
|
+
const result = (isUnionOperand ? EvaluateIntersect([evaluatedLeft, evaluatedRight]) :
|
|
30
|
+
isObjectLeft && IsObjectRight ? Composite(evaluatedLeft, evaluatedRight) :
|
|
31
|
+
isObjectLeft && !IsObjectRight ? evaluatedLeft :
|
|
32
|
+
!isObjectLeft && IsObjectRight ? evaluatedRight :
|
|
33
|
+
Narrow(evaluatedLeft, evaluatedRight));
|
|
30
34
|
return result;
|
|
31
35
|
}
|
|
32
36
|
function DistributeType(type, types, result = []) {
|
package/license
CHANGED
|
@@ -2,7 +2,7 @@ TypeBox
|
|
|
2
2
|
|
|
3
3
|
The MIT License (MIT)
|
|
4
4
|
|
|
5
|
-
Copyright (c) 2017-
|
|
5
|
+
Copyright (c) 2017-2026 Haydn Paterson
|
|
6
6
|
|
|
7
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
8
|
of this software and associated documentation files (the "Software"), to deal
|