typebox 1.3.12 → 1.3.14
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/format/iri.d.mts +1 -1
- package/build/format/iri.mjs +26 -2
- package/build/format/uri.d.mts +1 -1
- package/build/format/uri.mjs +2 -2
- package/build/format/uri_reference.d.mts +1 -1
- package/build/format/uri_reference.mjs +2 -3
- package/build/format/uri_template.d.mts +2 -2
- package/build/format/uri_template.mjs +4 -4
- package/build/format/url.d.mts +1 -1
- package/build/format/url.mjs +1 -1
- package/build/guard/string.mjs +1 -1
- package/build/system/memory/clone.mjs +1 -1
- package/build/system/memory/discard.mjs +2 -1
- package/build/type/engine/evaluate/broaden.d.mts +5 -5
- package/build/type/engine/evaluate/broaden.mjs +20 -26
- package/build/type/engine/evaluate/compare.d.mts +6 -10
- package/build/type/engine/evaluate/compare.mjs +9 -13
- package/build/type/engine/evaluate/composite.d.mts +7 -4
- package/build/type/engine/evaluate/composite.mjs +12 -19
- package/build/type/engine/evaluate/distribute.d.mts +4 -20
- package/build/type/engine/evaluate/distribute.mjs +8 -20
- package/build/type/engine/evaluate/evaluate.d.mts +4 -4
- package/build/type/engine/evaluate/evaluate.mjs +11 -8
- package/build/type/engine/evaluate/flatten.d.mts +1 -1
- package/build/type/engine/evaluate/flatten.mjs +3 -4
- package/build/type/engine/evaluate/narrow.d.mts +17 -2
- package/build/type/engine/evaluate/narrow.mjs +26 -6
- package/build/type/engine/exclude/operation.mjs +3 -4
- package/build/type/engine/extract/operation.d.mts +1 -1
- package/build/type/engine/extract/operation.mjs +3 -4
- package/build/type/engine/priority/priority.d.mts +2 -2
- package/build/type/engine/priority/priority.mjs +3 -4
- package/build/type/script/parser.mjs +8 -1
- package/package.json +1 -1
- package/readme.md +10 -8
package/build/format/iri.d.mts
CHANGED
package/build/format/iri.mjs
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
1
|
+
// deno-lint-ignore-file no-control-regex
|
|
2
|
+
const IpvFutureMatchMaxLength = 2048;
|
|
3
|
+
const IpvFutureMatch = /\[[vV][0-9a-fA-F]+\.[^\]]+\]/; // Guarded By IpvFutureMatchMaxLength
|
|
4
|
+
const InvalidIriChars = /[\x00-\x20<>\^`{|}\\]/;
|
|
5
|
+
// ------------------------------------------------------------------
|
|
6
|
+
// NarrowIpvFuture
|
|
7
|
+
//
|
|
8
|
+
// Substitutes an IPvFuture address with a standard IPv6 loopback
|
|
9
|
+
// address ([::1]). We do this because the native URL.canParse
|
|
10
|
+
// (WHATWG standard) rejects IPvFuture literals, which are
|
|
11
|
+
// otherwise valid in RFC 3987. Because regex substitution can
|
|
12
|
+
// be expensive on large strings, this operation is strictly
|
|
13
|
+
// limited to inputs under a defined length threshold.
|
|
14
|
+
//
|
|
15
|
+
// (review-optimization)
|
|
16
|
+
//
|
|
17
|
+
// ------------------------------------------------------------------
|
|
18
|
+
function NarrowIpvFuture(value) {
|
|
19
|
+
return value.length < IpvFutureMatchMaxLength ? value.replace(IpvFutureMatch, '[::1]') : value;
|
|
20
|
+
}
|
|
1
21
|
/**
|
|
2
|
-
* Returns true if the value is a
|
|
22
|
+
* Returns true if the value is a valid Internationalized Resource Identifier.
|
|
3
23
|
* @specification https://datatracker.ietf.org/doc/html/rfc3987
|
|
4
24
|
*/
|
|
5
25
|
export function IsIri(value) {
|
|
6
|
-
|
|
26
|
+
// 1. Reject strings containing unencoded whitespace or illegal control characters.
|
|
27
|
+
if (InvalidIriChars.test(value))
|
|
28
|
+
return false;
|
|
29
|
+
// 2. Delegate to the native URL parser, patching the IPvFuture edge case beforehand.
|
|
30
|
+
return URL.canParse(NarrowIpvFuture(value));
|
|
7
31
|
}
|
package/build/format/uri.d.mts
CHANGED
package/build/format/uri.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const Uri = /^[a-z][a-z0-9+\-.]*:(?:\/\/(?:(?:[a-z0-9
|
|
1
|
+
const Uri = /^[a-z][a-z0-9+\-.]*:(?:\/\/(?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4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,5}[\da-f]{1,4})?::[\da-f]{1,4}|(?:(?:[\da-f]{1,4}:){0,6}[\da-f]{1,4})?::)|v[0-9a-f]+\.[-a-z0-9._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)|(?:[-a-z0-9._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[-a-z0-9._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[-a-z0-9._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
2
2
|
/**
|
|
3
|
-
* Returns true if the value
|
|
3
|
+
* Returns true if the value is a valid Uniform Resource Identifier.
|
|
4
4
|
* @specification https://tools.ietf.org/html/rfc3986
|
|
5
5
|
*/
|
|
6
6
|
export function IsUri(value) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
const UriReference = /^(?!.*[^\x00-\x7F])(?!.*\\)(?:(?:[a-z][a-z0-9+\-.]*:)?(?:\/\/[^\s[\]{}<>^`|]*)?|[^\s[\]{}<>^`|]*)(?:\?[^\s[\]{}<>^`|]*)?(?:#[^\s[\]{}<>^`|]*)?$/i;
|
|
1
|
+
const UriReference = /^(?:[a-z][a-z0-9+\-.]*:(?:\/\/(?:(?:[-a-z0-9._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?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:[-a-z0-9._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
3
2
|
/**
|
|
4
|
-
* Returns true if the value is a valid
|
|
3
|
+
* Returns true if the value is a valid Uri Reference.
|
|
5
4
|
* @specification https://tools.ietf.org/html/rfc3986
|
|
6
5
|
*/
|
|
7
6
|
export function IsUriReference(value) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// deno-lint-ignore-file
|
|
2
|
-
const UriTemplate = /^(?:(?:[^\x00-\x20"<>%\\^`{|}\x7f]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9]
|
|
1
|
+
// deno-lint-ignore-file no-control-regex
|
|
2
|
+
const UriTemplate = /^(?:(?:[^\x00-\x20"<>%\\^`{|}\x7f]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9]\d{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9]\d{0,3}|\*)?)*\})*$/i;
|
|
3
3
|
/**
|
|
4
|
-
* Returns true if the value is a
|
|
5
|
-
* @specification
|
|
4
|
+
* Returns true if the value is a valid Uri Template
|
|
5
|
+
* @specification https://datatracker.ietf.org/doc/html/rfc6570
|
|
6
6
|
*/
|
|
7
7
|
export function IsUriTemplate(value) {
|
|
8
8
|
return UriTemplate.test(value);
|
package/build/format/url.d.mts
CHANGED
package/build/format/url.mjs
CHANGED
package/build/guard/string.mjs
CHANGED
|
@@ -67,7 +67,7 @@ function NextGraphemeClusterIndex(value, clusterStart) {
|
|
|
67
67
|
// Consume combining marks & variation selectors
|
|
68
68
|
clusterEnd = ConsumeModifiers(value, clusterEnd);
|
|
69
69
|
// Handle multi-ZWJ sequences
|
|
70
|
-
while (clusterEnd < value.length - 1 && value
|
|
70
|
+
while (clusterEnd < value.length - 1 && IsZeroWidthJoiner(value.codePointAt(clusterEnd))) {
|
|
71
71
|
const nextCP = value.codePointAt(clusterEnd + 1);
|
|
72
72
|
clusterEnd += 1 + CodePointLength(nextCP);
|
|
73
73
|
clusterEnd = ConsumeModifiers(value, clusterEnd);
|
|
@@ -24,7 +24,7 @@ function IsSchemaObject(value) {
|
|
|
24
24
|
}
|
|
25
25
|
function FromSchemaObject(value) {
|
|
26
26
|
const result = {};
|
|
27
|
-
for (const key of
|
|
27
|
+
for (const key of Guard.Keys(value)) {
|
|
28
28
|
if (Guard.IsUnsafePropertyKey(key))
|
|
29
29
|
continue; // (ignore: prototype-pollution)
|
|
30
30
|
const descriptor = Object.getOwnPropertyDescriptor(value, key); // safe-name!
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// deno-lint-ignore-file no-explicit-any
|
|
2
2
|
// deno-fmt-ignore-file
|
|
3
|
+
import { Guard } from '../../guard/index.mjs';
|
|
3
4
|
import { Metrics } from './metrics.mjs';
|
|
4
5
|
import { Clone } from './clone.mjs';
|
|
5
6
|
/** Discards multiple property keys from the given object value */
|
|
6
7
|
export function Discard(value, propertyKeys) {
|
|
7
8
|
Metrics.discard += 1;
|
|
8
9
|
const result = {};
|
|
9
|
-
for (const key of
|
|
10
|
+
for (const key of Guard.Keys(value)) {
|
|
10
11
|
if (propertyKeys.includes(key))
|
|
11
12
|
continue;
|
|
12
13
|
const descriptor = Object.getOwnPropertyDescriptor(value, key); // safe-name!
|
|
@@ -2,13 +2,13 @@ import { type TSchema } from '../../types/schema.mjs';
|
|
|
2
2
|
import { type TAny } from '../../types/any.mjs';
|
|
3
3
|
import { type TNever } from '../../types/never.mjs';
|
|
4
4
|
import { type TObject } from '../../types/object.mjs';
|
|
5
|
-
import { type
|
|
5
|
+
import { type TUnknown } from '../../types/unknown.mjs';
|
|
6
|
+
import { type TCompare, CompareResultLeftInside, CompareResultEqual, CompareResultDisjoint } from './compare.mjs';
|
|
6
7
|
import { type TFlatten } from './flatten.mjs';
|
|
7
8
|
import { type TEvaluateType } from './evaluate.mjs';
|
|
8
|
-
type
|
|
9
|
-
type
|
|
10
|
-
type
|
|
11
|
-
type TBroadenTypes<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? (Left extends TObject ? TBroadenTypes<Right, [...Result, Left]> : Left extends TNever ? TBroadenTypes<Right, Result> : TBroadenTypes<Right, TBroadenType<Left, Result>>) : Result);
|
|
9
|
+
type TBroadenFilter<Type extends TSchema, Types extends TSchema[], Result extends TSchema[] = [], All extends TSchema[] = Types> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TCompare<Type, Left> extends typeof CompareResultLeftInside | typeof CompareResultEqual ? All : TCompare<Type, Left> extends typeof CompareResultDisjoint ? TBroadenFilter<Type, Right, [...Result, Left], All> : TBroadenFilter<Type, Right, Result, All> : [...Result, Type]);
|
|
10
|
+
type TBroadenType<Type extends TSchema, Types extends TSchema[], Result extends TSchema[], Evaluated extends TSchema = TEvaluateType<Type>> = (Evaluated extends TAny ? [Evaluated] : Evaluated extends TUnknown ? [Evaluated] : Evaluated extends TNever ? TBroadenTypes<Types, Result> : Evaluated extends TObject ? TBroadenTypes<Types, [...Result, Evaluated]> : TBroadenTypes<Types, TBroadenFilter<Evaluated, Result>>);
|
|
11
|
+
type TBroadenTypes<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TBroadenType<Left, Right, Result> : Result);
|
|
12
12
|
export type TBroaden<Types extends TSchema[], Broadened extends TSchema[] = TBroadenTypes<Types>, Flattened extends TSchema[] = TFlatten<Broadened>> = Flattened;
|
|
13
13
|
/** Broadens a set of types and returns either the most broad type, or union or disjoint types. */
|
|
14
14
|
export declare function Broaden<Types extends TSchema[]>(types: [...Types]): TBroaden<Types>;
|
|
@@ -3,37 +3,31 @@ import { Guard } from '../../../guard/index.mjs';
|
|
|
3
3
|
import { IsAny } from '../../types/any.mjs';
|
|
4
4
|
import { IsNever } from '../../types/never.mjs';
|
|
5
5
|
import { IsObject } from '../../types/object.mjs';
|
|
6
|
-
import {
|
|
6
|
+
import { IsUnknown } from '../../types/unknown.mjs';
|
|
7
|
+
import { Compare, CompareResultLeftInside, CompareResultEqual, CompareResultDisjoint } from './compare.mjs';
|
|
7
8
|
import { Flatten } from './flatten.mjs';
|
|
8
9
|
import { EvaluateType } from './evaluate.mjs';
|
|
9
|
-
function
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return Guard.IsEqual(result, ResultLeftInside) || Guard.IsEqual(result, ResultEqual);
|
|
20
|
-
});
|
|
21
|
-
return Guard.IsEqual(result, false);
|
|
10
|
+
function BroadenFilter(type, types, result = [], all = types) {
|
|
11
|
+
return Guard.ShiftLeft(types, (left, right) => {
|
|
12
|
+
const compare = Compare(type, left);
|
|
13
|
+
return ((Guard.IsEqual(compare, CompareResultLeftInside) || Guard.IsEqual(compare, CompareResultEqual))
|
|
14
|
+
? all // Left in set. Return original All set.
|
|
15
|
+
: Guard.IsEqual(compare, CompareResultDisjoint)
|
|
16
|
+
? BroadenFilter(type, right, [...result, left], all) // Left is disjoint, keep it
|
|
17
|
+
: BroadenFilter(type, right, result, all) // Left in Type, drop it
|
|
18
|
+
);
|
|
19
|
+
}, () => [...result, type]); // Type broadest in set
|
|
22
20
|
}
|
|
23
|
-
function BroadenType(type, types) {
|
|
21
|
+
function BroadenType(type, types, result) {
|
|
24
22
|
const evaluated = EvaluateType(type);
|
|
25
|
-
return (IsAny(evaluated) ? [evaluated] :
|
|
26
|
-
|
|
27
|
-
?
|
|
28
|
-
|
|
23
|
+
return (IsAny(evaluated) ? [evaluated] : // terminate (always the most broad)
|
|
24
|
+
IsUnknown(evaluated) ? [evaluated] : // terminate (always the most broad)
|
|
25
|
+
IsNever(evaluated) ? BroadenTypes(types, result) : // ignored: never is dropped
|
|
26
|
+
IsObject(evaluated) ? BroadenTypes(types, [...result, evaluated]) : // objects are always considered (too expensive to compare)
|
|
27
|
+
BroadenTypes(types, BroadenFilter(evaluated, result)));
|
|
29
28
|
}
|
|
30
|
-
function BroadenTypes(types) {
|
|
31
|
-
return
|
|
32
|
-
return (IsObject(left) ? [...result, left] : // push
|
|
33
|
-
IsNever(left) ? result : // ignore
|
|
34
|
-
BroadenType(left, result) // broaden
|
|
35
|
-
);
|
|
36
|
-
}, []);
|
|
29
|
+
function BroadenTypes(types, result = []) {
|
|
30
|
+
return Guard.ShiftLeft(types, (left, right) => (BroadenType(left, right, result)), () => result);
|
|
37
31
|
}
|
|
38
32
|
/** Broadens a set of types and returns either the most broad type, or union or disjoint types. */
|
|
39
33
|
export function Broaden(types) {
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/index.mjs';
|
|
2
|
-
import { type TUnknown } from '../../types/unknown.mjs';
|
|
3
2
|
import { type TExtends, ExtendsResult } from "../../extends/index.mjs";
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export type TCompareResult = typeof
|
|
3
|
+
export declare const CompareResultEqual = 0;
|
|
4
|
+
export declare const CompareResultDisjoint = 1;
|
|
5
|
+
export declare const CompareResultLeftInside = 2;
|
|
6
|
+
export declare const CompareResultRightInside = 3;
|
|
7
|
+
export type TCompareResult = (typeof CompareResultEqual | typeof CompareResultDisjoint | typeof CompareResultLeftInside | typeof CompareResultRightInside);
|
|
9
8
|
/** Compares left and right types and determines their set relationship */
|
|
10
|
-
export type TCompare<Left extends TSchema, Right extends TSchema, Extends extends [ExtendsResult.TResult, ExtendsResult.TResult] = [
|
|
11
|
-
Left extends TUnknown ? ExtendsResult.TExtendsFalse : TExtends<{}, Left, Right>,
|
|
12
|
-
Left extends TUnknown ? ExtendsResult.TExtendsTrue : TExtends<{}, Right, Left>
|
|
13
|
-
]> = (Extends extends [ExtendsResult.TExtendsTrueLike, ExtendsResult.TExtendsTrueLike] ? typeof ResultEqual : Extends extends [ExtendsResult.TExtendsTrueLike, ExtendsResult.TExtendsFalse] ? typeof ResultLeftInside : Extends extends [ExtendsResult.TExtendsFalse, ExtendsResult.TExtendsTrueLike] ? typeof ResultRightInside : typeof ResultDisjoint);
|
|
9
|
+
export type TCompare<Left extends TSchema, Right extends TSchema, Extends extends [ExtendsResult.TResult, ExtendsResult.TResult] = [TExtends<{}, Left, Right>, TExtends<{}, Right, Left>]> = (Extends extends [ExtendsResult.TExtendsTrueLike, ExtendsResult.TExtendsTrueLike] ? typeof CompareResultEqual : Extends extends [ExtendsResult.TExtendsTrueLike, ExtendsResult.TExtendsFalse] ? typeof CompareResultLeftInside : Extends extends [ExtendsResult.TExtendsFalse, ExtendsResult.TExtendsTrueLike] ? typeof CompareResultRightInside : typeof CompareResultDisjoint);
|
|
14
10
|
/** Compares left and right types and determines their set relationship. */
|
|
15
11
|
export declare function Compare<Left extends TSchema, Right extends TSchema>(left: Left, right: Right): TCompare<Left, Right>;
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
// deno-lint-ignore-file ban-types
|
|
2
2
|
// deno-fmt-ignore-file
|
|
3
|
-
import { IsUnknown } from '../../types/unknown.mjs';
|
|
4
3
|
import { Extends, ExtendsResult } from "../../extends/index.mjs";
|
|
5
4
|
// ------------------------------------------------------------------
|
|
6
5
|
// TCompare
|
|
7
6
|
// ------------------------------------------------------------------
|
|
8
|
-
export const
|
|
9
|
-
export const
|
|
10
|
-
export const
|
|
11
|
-
export const
|
|
7
|
+
export const CompareResultEqual = 0; // 'equal'
|
|
8
|
+
export const CompareResultDisjoint = 1; // 'disjoint'
|
|
9
|
+
export const CompareResultLeftInside = 2; // 'left-inside'
|
|
10
|
+
export const CompareResultRightInside = 3; // 'right-inside'
|
|
12
11
|
/** Compares left and right types and determines their set relationship. */
|
|
13
12
|
export function Compare(left, right) {
|
|
14
|
-
const extendsCheck = [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
ExtendsResult.IsExtendsTrueLike(extendsCheck[0]) && ExtendsResult.IsExtendsFalse(extendsCheck[1]) ? ResultLeftInside :
|
|
20
|
-
ExtendsResult.IsExtendsFalse(extendsCheck[0]) && ExtendsResult.IsExtendsTrueLike(extendsCheck[1]) ? ResultRightInside :
|
|
21
|
-
ResultDisjoint);
|
|
13
|
+
const extendsCheck = [Extends({}, left, right), Extends({}, right, left)];
|
|
14
|
+
return (ExtendsResult.IsExtendsTrueLike(extendsCheck[0]) && ExtendsResult.IsExtendsTrueLike(extendsCheck[1]) ? CompareResultEqual :
|
|
15
|
+
ExtendsResult.IsExtendsTrueLike(extendsCheck[0]) && ExtendsResult.IsExtendsFalse(extendsCheck[1]) ? CompareResultLeftInside :
|
|
16
|
+
ExtendsResult.IsExtendsFalse(extendsCheck[0]) && ExtendsResult.IsExtendsTrueLike(extendsCheck[1]) ? CompareResultRightInside :
|
|
17
|
+
CompareResultDisjoint);
|
|
22
18
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type TUnreachable } from '../../../system/unreachable/index.mjs';
|
|
2
1
|
import { type TReadonly } from '../../types/_readonly.mjs';
|
|
3
2
|
import { type TOptional } from '../../types/_optional.mjs';
|
|
4
3
|
import { type TSchema } from '../../types/schema.mjs';
|
|
@@ -12,6 +11,10 @@ import { type TRemoveReadonly } from '../../action/_remove_readonly.mjs';
|
|
|
12
11
|
import { type TRemoveOptional } from '../../action/_remove_optional.mjs';
|
|
13
12
|
import { type TTupleElementsToProperties } from '../tuple/to_object.mjs';
|
|
14
13
|
import { type TEvaluateIntersect } from './evaluate.mjs';
|
|
14
|
+
/** Returns true if the type is a valid operand to Composite. */
|
|
15
|
+
export type TCanComposite<Type extends TSchema> = (Type extends TObject<infer _ extends TProperties> ? true : Type extends TTuple<infer _ extends TSchema[]> ? true : false);
|
|
16
|
+
/** Returns true if the type is a valid operand to Composite. */
|
|
17
|
+
export declare function CanComposite<Type extends TSchema>(type: Type): TCanComposite<Type>;
|
|
15
18
|
type TIsReadonlyProperty<Left extends TSchema, Right extends TSchema> = (Left extends TReadonly<Left> ? Right extends TReadonly<Right> ? true : false : false);
|
|
16
19
|
type TIsOptionalProperty<Left extends TSchema, Right extends TSchema> = (Left extends TOptional<Left> ? Right extends TOptional<Right> ? true : false : false);
|
|
17
20
|
type TCompositeProperty<Left extends TSchema, Right extends TSchema, IsReadonly extends boolean = TIsReadonlyProperty<Left, Right>, IsOptional extends boolean = TIsOptionalProperty<Left, Right>, Evaluated extends TSchema = TEvaluateIntersect<[Left, Right]>, Property extends TSchema = TRemoveReadonly<TRemoveOptional<Evaluated>>> = ([
|
|
@@ -25,10 +28,10 @@ type TCompositeProperty<Left extends TSchema, Right extends TSchema, IsReadonly
|
|
|
25
28
|
IsOptional
|
|
26
29
|
] extends [false, true] ? TAddOptional<Property> : Property);
|
|
27
30
|
type TCompositePropertyKey<Left extends TProperties, Right extends TProperties, Key extends PropertyKey, Result extends TSchema = (Key extends keyof Left ? Key extends keyof Right ? TCompositeProperty<Left[Key], Right[Key]> : Left[Key] : Key extends keyof Right ? Right[Key] : TNever)> = Result;
|
|
28
|
-
type TCompositeProperties<Left extends TProperties, Right extends TProperties, Result extends TProperties = {
|
|
29
|
-
[Key in
|
|
31
|
+
type TCompositeProperties<Left extends TProperties, Right extends TProperties, Keys extends PropertyKey = keyof (Left & Right), Result extends TProperties = {
|
|
32
|
+
[Key in Keys]: TCompositePropertyKey<Left, Right, Key>;
|
|
30
33
|
}> = Result;
|
|
31
|
-
type TGetProperties<Type extends TSchema, Result extends TProperties = (Type extends TObject<infer Properties extends TProperties> ? Properties : Type extends TTuple<infer Types extends TSchema[]> ? TTupleElementsToProperties<Types> :
|
|
34
|
+
type TGetProperties<Type extends TSchema, Result extends TProperties = (Type extends TObject<infer Properties extends TProperties> ? Properties : Type extends TTuple<infer Types extends TSchema[]> ? TTupleElementsToProperties<Types> : {})> = Result;
|
|
32
35
|
export type TComposite<Left extends TSchema, Right extends TSchema, LeftProperties extends TProperties = TGetProperties<Left>, RightProperties extends TProperties = TGetProperties<Right>, Properties extends TProperties = TCompositeProperties<LeftProperties, RightProperties>, Result extends TSchema = TObject<Properties>> = Result;
|
|
33
36
|
export declare function Composite<Left extends TSchema, Right extends TSchema>(left: Left, right: Right): TComposite<Left, Right>;
|
|
34
37
|
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
// deno-lint-ignore-file
|
|
3
|
-
import { Unreachable } from '../../../system/unreachable/index.mjs';
|
|
4
3
|
import { Guard } from '../../../guard/index.mjs';
|
|
5
4
|
import { IsReadonly } from '../../types/_readonly.mjs';
|
|
6
5
|
import { IsOptional } from '../../types/_optional.mjs';
|
|
@@ -13,6 +12,10 @@ import { RemoveReadonly } from '../../action/_remove_readonly.mjs';
|
|
|
13
12
|
import { RemoveOptional } from '../../action/_remove_optional.mjs';
|
|
14
13
|
import { TupleElementsToProperties } from '../tuple/to_object.mjs';
|
|
15
14
|
import { EvaluateIntersect } from './evaluate.mjs';
|
|
15
|
+
/** Returns true if the type is a valid operand to Composite. */
|
|
16
|
+
export function CanComposite(type) {
|
|
17
|
+
return (IsObject(type) || IsTuple(type));
|
|
18
|
+
}
|
|
16
19
|
function IsReadonlyProperty(left, right) {
|
|
17
20
|
return (IsReadonly(left) ? IsReadonly(right) ? true : false : false);
|
|
18
21
|
}
|
|
@@ -32,36 +35,26 @@ function CompositeProperty(left, right) {
|
|
|
32
35
|
}
|
|
33
36
|
function CompositePropertyKey(left, right, key) {
|
|
34
37
|
return (key in left
|
|
35
|
-
? key in right
|
|
36
|
-
|
|
37
|
-
: left[key]
|
|
38
|
-
: key in right
|
|
39
|
-
? right[key]
|
|
40
|
-
: Never());
|
|
38
|
+
? key in right ? CompositeProperty(left[key], right[key]) : left[key]
|
|
39
|
+
: key in right ? right[key] : Never());
|
|
41
40
|
}
|
|
42
41
|
function CompositeProperties(left, right) {
|
|
43
|
-
const keys = new Set([...Guard.Keys(
|
|
44
|
-
|
|
42
|
+
const keys = new Set([...Guard.Keys(left), ...Guard.Keys(right)]);
|
|
43
|
+
const result = [...keys].reduce((result, key) => {
|
|
45
44
|
return { ...result, [key]: CompositePropertyKey(left, right, key) };
|
|
46
45
|
}, {});
|
|
46
|
+
return result;
|
|
47
47
|
}
|
|
48
|
-
// ------------------------------------------------------------------
|
|
49
|
-
// deno-coverage-ignore-start - symmetric unreachable | internal
|
|
50
|
-
//
|
|
51
|
-
// Composite is called by Distribute which provisions the type as
|
|
52
|
-
// either TObject ot TTuple. Fall-through unreachable.
|
|
53
|
-
//
|
|
54
|
-
// ------------------------------------------------------------------
|
|
55
48
|
function GetProperties(type) {
|
|
56
49
|
const result = (IsObject(type) ? type.properties :
|
|
57
50
|
IsTuple(type) ? TupleElementsToProperties(type.items) :
|
|
58
|
-
|
|
59
|
-
);
|
|
51
|
+
{});
|
|
60
52
|
return result;
|
|
61
53
|
}
|
|
62
54
|
export function Composite(left, right) {
|
|
63
55
|
const leftProperties = GetProperties(left);
|
|
64
56
|
const rightProperties = GetProperties(right);
|
|
65
57
|
const properties = CompositeProperties(leftProperties, rightProperties);
|
|
66
|
-
|
|
58
|
+
const result = Object(properties);
|
|
59
|
+
return result;
|
|
67
60
|
}
|
|
@@ -1,27 +1,11 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
-
import { type TProperties } from '../../types/properties.mjs';
|
|
3
2
|
import { type TUnion } from '../../types/union.mjs';
|
|
4
|
-
import { type TObject } from '../../types/object.mjs';
|
|
5
|
-
import { type TTuple } from '../../types/tuple.mjs';
|
|
6
|
-
import { type TComposite } from './composite.mjs';
|
|
7
3
|
import { type TNarrow } from './narrow.mjs';
|
|
8
|
-
import { type TEvaluateType } from './evaluate.mjs';
|
|
9
4
|
import { type TEvaluateIntersect } from './evaluate.mjs';
|
|
10
|
-
|
|
11
|
-
type
|
|
12
|
-
type TDistributeOperation<Left extends TSchema, Right extends TSchema, EvaluatedLeft extends TSchema = TEvaluateType<Left>, EvaluatedRight extends TSchema = TEvaluateType<Right>,
|
|
13
|
-
|
|
14
|
-
] extends [true] ? TEvaluateIntersect<[EvaluatedLeft, EvaluatedRight]> : [
|
|
15
|
-
IsObjectLeft,
|
|
16
|
-
IsObjectRight
|
|
17
|
-
] extends [true, true] ? TComposite<EvaluatedLeft, EvaluatedRight> : [
|
|
18
|
-
IsObjectLeft,
|
|
19
|
-
IsObjectRight
|
|
20
|
-
] extends [true, false] ? EvaluatedLeft : [
|
|
21
|
-
IsObjectLeft,
|
|
22
|
-
IsObjectRight
|
|
23
|
-
] extends [false, true] ? EvaluatedRight : TNarrow<EvaluatedLeft, EvaluatedRight>)> = Result;
|
|
24
|
-
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);
|
|
5
|
+
import { type TEvaluateType } from './evaluate.mjs';
|
|
6
|
+
type TShouldEvaluate<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;
|
|
7
|
+
type TDistributeOperation<Left extends TSchema, Right extends TSchema, EvaluatedLeft extends TSchema = TEvaluateType<Left>, EvaluatedRight extends TSchema = TEvaluateType<Right>, ShouldEvaluate extends boolean = TShouldEvaluate<EvaluatedLeft, EvaluatedRight>, Result extends TSchema = [ShouldEvaluate] extends [true] ? TEvaluateIntersect<[EvaluatedLeft, EvaluatedRight]> : TNarrow<EvaluatedLeft, EvaluatedRight>> = Result;
|
|
8
|
+
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<Left, Type>]> : Result extends [] ? [Type] : Result);
|
|
25
9
|
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);
|
|
26
10
|
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);
|
|
27
11
|
export declare function Distribute<Types extends TSchema[]>(types: [...Types], result?: TSchema[]): TDistribute<Types>;
|
|
@@ -2,36 +2,24 @@
|
|
|
2
2
|
// deno-fmt-ignore-file
|
|
3
3
|
import { Guard } from '../../../guard/index.mjs';
|
|
4
4
|
import { IsUnion } from '../../types/union.mjs';
|
|
5
|
-
import { IsObject } from '../../types/object.mjs';
|
|
6
|
-
import { IsTuple } from '../../types/tuple.mjs';
|
|
7
|
-
import { Composite } from './composite.mjs';
|
|
8
5
|
import { Narrow } from './narrow.mjs';
|
|
9
|
-
import { EvaluateType } from './evaluate.mjs';
|
|
10
6
|
import { EvaluateIntersect } from './evaluate.mjs';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function IsUnionOperand(left, right) {
|
|
15
|
-
const isUnionLeft = IsUnion(left);
|
|
16
|
-
const isUnionRight = IsUnion(right);
|
|
17
|
-
const result = isUnionLeft || isUnionRight;
|
|
7
|
+
import { EvaluateType } from './evaluate.mjs';
|
|
8
|
+
function ShouldEvaluate(left, right) {
|
|
9
|
+
const result = IsUnion(left) || IsUnion(right);
|
|
18
10
|
return result;
|
|
19
11
|
}
|
|
20
12
|
function DistributeOperation(left, right) {
|
|
21
13
|
const evaluatedLeft = EvaluateType(left);
|
|
22
14
|
const evaluatedRight = EvaluateType(right);
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
isObjectLeft && IsObjectRight ? Composite(evaluatedLeft, evaluatedRight) :
|
|
28
|
-
isObjectLeft && !IsObjectRight ? evaluatedLeft :
|
|
29
|
-
!isObjectLeft && IsObjectRight ? evaluatedRight :
|
|
30
|
-
Narrow(evaluatedLeft, evaluatedRight));
|
|
15
|
+
const shouldEvaluate = ShouldEvaluate(evaluatedLeft, evaluatedRight);
|
|
16
|
+
const result = shouldEvaluate
|
|
17
|
+
? EvaluateIntersect([evaluatedLeft, evaluatedRight])
|
|
18
|
+
: Narrow(evaluatedLeft, evaluatedRight);
|
|
31
19
|
return result;
|
|
32
20
|
}
|
|
33
21
|
function DistributeType(type, types, result = []) {
|
|
34
|
-
return Guard.ShiftLeft(types, (left, right) => DistributeType(type, right, [...result, DistributeOperation(
|
|
22
|
+
return Guard.ShiftLeft(types, (left, right) => DistributeType(type, right, [...result, DistributeOperation(left, type)]), () => Guard.IsEqual(result.length, 0)
|
|
35
23
|
? [type]
|
|
36
24
|
: result);
|
|
37
25
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
2
|
import { type TDependent } from '../../types/dependent.mjs';
|
|
3
3
|
import { type TEnum, type TEnumValue } from '../../types/enum.mjs';
|
|
4
|
-
import { type TLiteral } from '../../types/literal.mjs';
|
|
5
4
|
import { type TIntersect } from '../../types/intersect.mjs';
|
|
5
|
+
import { type TLiteral } from '../../types/literal.mjs';
|
|
6
6
|
import { type TNever } from '../../types/never.mjs';
|
|
7
7
|
import { type TTemplateLiteral } from '../../types/template_literal.mjs';
|
|
8
8
|
import { type TUnion } from '../../types/union.mjs';
|
|
@@ -10,11 +10,11 @@ import { type TDistribute } from './distribute.mjs';
|
|
|
10
10
|
import { type TBroaden } from './broaden.mjs';
|
|
11
11
|
import { type TExcludeOperation } from '../exclude/operation.mjs';
|
|
12
12
|
import { type TTemplateLiteralDecode } from '../template_literal/decode.mjs';
|
|
13
|
-
export type TEvaluateDependent<If extends TSchema, Then extends TSchema, Else extends TSchema,
|
|
13
|
+
export type TEvaluateDependent<If extends TSchema, Then extends TSchema, Else extends TSchema, Intersected extends TSchema = TEvaluateIntersect<[If, Then]>, Excluded extends TSchema = TExcludeOperation<Else, If>, Result extends TSchema = TEvaluateUnion<[Intersected, Excluded]>> = Result;
|
|
14
14
|
export declare function EvaluateDependent<If extends TSchema, Then extends TSchema, Else extends TSchema>(if_: If, then_: Then, else_: Else): TEvaluateDependent<If, Then, Else>;
|
|
15
15
|
export type TEvaluateEnum<Values extends TEnumValue[], Result extends TSchema[] = []> = (Values extends [infer Left extends TEnumValue, ...infer Right extends TEnumValue[]] ? TEvaluateEnum<Right, [...Result, TLiteral<Left>]> : TEvaluateUnion<Result>);
|
|
16
|
-
export declare function EvaluateEnum<Values extends TEnumValue[]>(values: [...Values]): TEvaluateEnum<Values>;
|
|
17
|
-
export type TEvaluateIntersect<Types extends TSchema[], Distribution extends TSchema[] = TDistribute<Types>, Broadend extends TSchema[] = TBroaden<Distribution>, Result extends TSchema =
|
|
16
|
+
export declare function EvaluateEnum<Values extends TEnumValue[]>(values: [...Values], result?: TSchema[]): TEvaluateEnum<Values>;
|
|
17
|
+
export type TEvaluateIntersect<Types extends TSchema[], Distribution extends TSchema[] = TDistribute<Types>, Broadend extends TSchema[] = TBroaden<Distribution>, Result extends TSchema = TEvaluateUnion<Broadend>> = Result;
|
|
18
18
|
export declare function EvaluateIntersect<Types extends TSchema[]>(types: [...Types]): TEvaluateIntersect<Types>;
|
|
19
19
|
export type TEvaluateTemplateLiteral<Pattern extends string, Evaluated extends TSchema = TTemplateLiteralDecode<Pattern>, Result extends TSchema = TEvaluateType<Evaluated>> = Result;
|
|
20
20
|
export declare function EvaluateTemplateLiteral<Pattern extends string>(pattern: Pattern): TEvaluateTemplateLiteral<Pattern>;
|
|
@@ -2,29 +2,31 @@
|
|
|
2
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
3
3
|
import { IsDependent } from '../../types/dependent.mjs';
|
|
4
4
|
import { IsEnum } from '../../types/enum.mjs';
|
|
5
|
+
import { IsIntersect } from '../../types/intersect.mjs';
|
|
5
6
|
import { Literal } from '../../types/literal.mjs';
|
|
6
|
-
import { IsIntersect, Intersect } from '../../types/intersect.mjs';
|
|
7
7
|
import { Never } from '../../types/never.mjs';
|
|
8
8
|
import { IsTemplateLiteral } from '../../types/template_literal.mjs';
|
|
9
9
|
import { Union, IsUnion } from '../../types/union.mjs';
|
|
10
|
+
// ------------------------------------------------------------------
|
|
11
|
+
// Infrastructure
|
|
12
|
+
// ------------------------------------------------------------------
|
|
10
13
|
import { Distribute } from './distribute.mjs';
|
|
11
14
|
import { Broaden } from './broaden.mjs';
|
|
12
15
|
import { ExcludeOperation } from '../exclude/operation.mjs';
|
|
13
16
|
import { TemplateLiteralDecode } from '../template_literal/decode.mjs';
|
|
14
17
|
export function EvaluateDependent(if_, then_, else_) {
|
|
15
|
-
const
|
|
18
|
+
const intersected = EvaluateIntersect([if_, then_]);
|
|
16
19
|
const excluded = ExcludeOperation(else_, if_);
|
|
17
|
-
const result = EvaluateUnion([
|
|
20
|
+
const result = EvaluateUnion([intersected, excluded]);
|
|
18
21
|
return result;
|
|
19
22
|
}
|
|
20
|
-
export function EvaluateEnum(values) {
|
|
21
|
-
|
|
22
|
-
return EvaluateUnion(result);
|
|
23
|
+
export function EvaluateEnum(values, result = []) {
|
|
24
|
+
return Guard.ShiftLeft(values, (left, right) => EvaluateEnum(right, [...result, Literal(left)]), () => EvaluateUnion(result));
|
|
23
25
|
}
|
|
24
26
|
export function EvaluateIntersect(types) {
|
|
25
27
|
const distribution = Distribute(types);
|
|
26
28
|
const broadend = Broaden(distribution);
|
|
27
|
-
const result =
|
|
29
|
+
const result = EvaluateUnion(broadend);
|
|
28
30
|
return result;
|
|
29
31
|
}
|
|
30
32
|
export function EvaluateTemplateLiteral(pattern) {
|
|
@@ -38,12 +40,13 @@ export function EvaluateUnion(types) {
|
|
|
38
40
|
return result;
|
|
39
41
|
}
|
|
40
42
|
export function EvaluateType(type) {
|
|
41
|
-
|
|
43
|
+
const result = (IsDependent(type) ? EvaluateDependent(type.if, type.then, type.else) :
|
|
42
44
|
IsEnum(type) ? EvaluateEnum(type.enum) :
|
|
43
45
|
IsIntersect(type) ? EvaluateIntersect(type.allOf) :
|
|
44
46
|
IsTemplateLiteral(type) ? EvaluateTemplateLiteral(type.pattern) :
|
|
45
47
|
IsUnion(type) ? EvaluateUnion(type.anyOf) :
|
|
46
48
|
type);
|
|
49
|
+
return result;
|
|
47
50
|
}
|
|
48
51
|
export function EvaluateUnionFast(types) {
|
|
49
52
|
const result = (Guard.IsEqual(types.length, 1) ? types[0] :
|
|
@@ -2,5 +2,5 @@ import { type TSchema } from '../../types/schema.mjs';
|
|
|
2
2
|
import { type TUnion } from '../../types/union.mjs';
|
|
3
3
|
type TFlattenType<Type extends TSchema, Result extends TSchema[] = Type extends TUnion<infer Types extends TSchema[]> ? TFlatten<Types> : [Type]> = Result;
|
|
4
4
|
export type TFlatten<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFlatten<Right, [...Result, ...TFlattenType<Left>]> : Result);
|
|
5
|
-
export declare function Flatten<Types extends TSchema[]>(types: [...Types]): TFlatten<Types>;
|
|
5
|
+
export declare function Flatten<Types extends TSchema[]>(types: [...Types], result?: TSchema[]): TFlatten<Types>;
|
|
6
6
|
export {};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
+
import { Guard } from '../../../guard/index.mjs';
|
|
2
3
|
import { IsUnion } from '../../types/union.mjs';
|
|
3
4
|
function FlattenType(type) {
|
|
4
5
|
const result = IsUnion(type) ? Flatten(type.anyOf) : [type];
|
|
5
6
|
return result;
|
|
6
7
|
}
|
|
7
|
-
export function Flatten(types) {
|
|
8
|
-
return
|
|
9
|
-
return [...result, ...FlattenType(type)];
|
|
10
|
-
}, []);
|
|
8
|
+
export function Flatten(types, result = []) {
|
|
9
|
+
return Guard.ShiftLeft(types, (left, right) => Flatten(right, [...result, ...FlattenType(left)]), () => result);
|
|
11
10
|
}
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
+
import { type TAny } from '../../types/any.mjs';
|
|
2
3
|
import { type TNever } from '../../types/never.mjs';
|
|
3
|
-
import { type
|
|
4
|
-
|
|
4
|
+
import { type TUnknown } from '../../types/unknown.mjs';
|
|
5
|
+
import { type TCompare, type TCompareResult, CompareResultLeftInside, CompareResultRightInside, CompareResultEqual } from './compare.mjs';
|
|
6
|
+
import { type TComposite, type TCanComposite } from './composite.mjs';
|
|
7
|
+
type TNarrowCompareRule<Left extends TSchema, Right extends TSchema, Result extends TCompareResult = TCompare<Left, Right>> = (Result extends typeof CompareResultLeftInside ? Left : Result extends typeof CompareResultRightInside ? Right : Result extends typeof CompareResultEqual ? Right : TNever);
|
|
8
|
+
type TNarrowCompositeRule<Left extends TSchema, Right extends TSchema, CanCompositeLeft extends boolean = TCanComposite<Left>, CanCompositeRight extends boolean = TCanComposite<Right>> = ([
|
|
9
|
+
CanCompositeLeft,
|
|
10
|
+
CanCompositeRight
|
|
11
|
+
] extends [true, true] ? TComposite<Left, Right> : [
|
|
12
|
+
CanCompositeLeft,
|
|
13
|
+
CanCompositeRight
|
|
14
|
+
] extends [true, false] ? Left : [
|
|
15
|
+
CanCompositeLeft,
|
|
16
|
+
CanCompositeRight
|
|
17
|
+
] extends [false, true] ? Right : TNarrowCompareRule<Left, Right>);
|
|
18
|
+
export type TNarrow<Left extends TSchema, Right extends TSchema> = (Left extends TNever ? TNever : Left extends TAny ? TAny : Left extends TUnknown ? Right : Right extends TNever ? TNever : Right extends TAny ? TAny : Right extends TUnknown ? Left : TNarrowCompositeRule<Left, Right>);
|
|
5
19
|
export declare function Narrow<Left extends TSchema, Right extends TSchema>(left: Left, right: Right): TNarrow<Left, Right>;
|
|
20
|
+
export {};
|
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import { IsAny } from '../../types/any.mjs';
|
|
4
|
+
import { Never, IsNever } from '../../types/never.mjs';
|
|
5
|
+
import { IsUnknown } from '../../types/unknown.mjs';
|
|
6
|
+
import { Compare, CompareResultLeftInside, CompareResultRightInside, CompareResultEqual } from './compare.mjs';
|
|
7
|
+
import { Composite, CanComposite } from './composite.mjs';
|
|
8
|
+
function NarrowCompareRule(left, right) {
|
|
6
9
|
const result = Compare(left, right);
|
|
7
|
-
return (Guard.IsEqual(result,
|
|
8
|
-
Guard.IsEqual(result,
|
|
9
|
-
Guard.IsEqual(result,
|
|
10
|
+
return (Guard.IsEqual(result, CompareResultLeftInside) ? left :
|
|
11
|
+
Guard.IsEqual(result, CompareResultRightInside) ? right :
|
|
12
|
+
Guard.IsEqual(result, CompareResultEqual) ? right :
|
|
10
13
|
Never());
|
|
11
14
|
}
|
|
15
|
+
function NarrowCompositeRule(left, right) {
|
|
16
|
+
const canCompositeLeft = CanComposite(left);
|
|
17
|
+
const canCompositeRight = CanComposite(right);
|
|
18
|
+
return (canCompositeLeft && canCompositeRight ? Composite(left, right) :
|
|
19
|
+
canCompositeLeft && !canCompositeRight ? left :
|
|
20
|
+
!canCompositeLeft && canCompositeRight ? right :
|
|
21
|
+
NarrowCompareRule(left, right));
|
|
22
|
+
}
|
|
23
|
+
export function Narrow(left, right) {
|
|
24
|
+
return (IsNever(left) ? left :
|
|
25
|
+
IsAny(left) ? left :
|
|
26
|
+
IsUnknown(left) ? right :
|
|
27
|
+
IsNever(right) ? right :
|
|
28
|
+
IsAny(right) ? right :
|
|
29
|
+
IsUnknown(right) ? left :
|
|
30
|
+
NarrowCompositeRule(left, right));
|
|
31
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// deno-lint-ignore-file ban-types
|
|
2
2
|
// deno-fmt-ignore-file
|
|
3
|
+
import { Guard } from '../../../guard/index.mjs';
|
|
3
4
|
import { IsUnion } from '../../types/union.mjs';
|
|
4
5
|
import { Extends, ExtendsResult } from '../../extends/index.mjs';
|
|
5
6
|
import { EvaluateType } from '../evaluate/evaluate.mjs';
|
|
@@ -9,10 +10,8 @@ function ExcludeType(left, right) {
|
|
|
9
10
|
const result = ExtendsResult.IsExtendsTrueLike(check) ? [] : [left];
|
|
10
11
|
return result;
|
|
11
12
|
}
|
|
12
|
-
function ExcludeUnion(
|
|
13
|
-
return
|
|
14
|
-
return [...result, ...ExcludeType(head, right)];
|
|
15
|
-
}, []);
|
|
13
|
+
function ExcludeUnion(left, right, result = []) {
|
|
14
|
+
return Guard.ShiftLeft(left, (head, tail) => ExcludeUnion(tail, right, [...result, ...ExcludeType(head, right)]), () => result);
|
|
16
15
|
}
|
|
17
16
|
export function ExcludeOperation(left, right) {
|
|
18
17
|
const evaluated = EvaluateType(left);
|
|
@@ -4,7 +4,7 @@ import { type TExtends, ExtendsResult } from '../../extends/index.mjs';
|
|
|
4
4
|
import { type TEvaluateType } from '../evaluate/evaluate.mjs';
|
|
5
5
|
import { type TEvaluateUnion } from '../evaluate/evaluate.mjs';
|
|
6
6
|
type TExtractType<Left extends TSchema, Right extends TSchema, Check extends ExtendsResult.TResult = TExtends<{}, Left, Right>, Result extends TSchema[] = Check extends ExtendsResult.TExtendsTrueLike ? [Left] : []> = Result;
|
|
7
|
-
type TExtractUnion<
|
|
7
|
+
type TExtractUnion<Left extends TSchema[], Right extends TSchema, Result extends TSchema[] = []> = (Left extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExtractUnion<Tail, Right, [...Result, ...TExtractType<Head, Right>]> : Result);
|
|
8
8
|
export type TExtractOperation<Left extends TSchema, Right extends TSchema, Evaluated extends TSchema = TEvaluateType<Left>, Canonical extends TSchema[] = Evaluated extends TUnion<infer Types extends TSchema[]> ? Types : [Evaluated], Remaining extends TSchema[] = TExtractUnion<Canonical, Right>, Result extends TSchema = TEvaluateUnion<Remaining>> = Result;
|
|
9
9
|
export declare function ExtractOperation<Left extends TSchema, Right extends TSchema>(left: Left, right: Right): TExtractOperation<Left, Right>;
|
|
10
10
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// deno-lint-ignore-file ban-types
|
|
2
2
|
// deno-fmt-ignore-file
|
|
3
|
+
import { Guard } from '../../../guard/index.mjs';
|
|
3
4
|
import { IsUnion } from '../../types/union.mjs';
|
|
4
5
|
import { Extends, ExtendsResult } from '../../extends/index.mjs';
|
|
5
6
|
import { EvaluateType } from '../evaluate/evaluate.mjs';
|
|
@@ -9,10 +10,8 @@ function ExtractType(left, right) {
|
|
|
9
10
|
const result = ExtendsResult.IsExtendsTrueLike(check) ? [left] : [];
|
|
10
11
|
return result;
|
|
11
12
|
}
|
|
12
|
-
function ExtractUnion(
|
|
13
|
-
return
|
|
14
|
-
return [...result, ...ExtractType(head, right)];
|
|
15
|
-
}, []);
|
|
13
|
+
function ExtractUnion(left, right, result = []) {
|
|
14
|
+
return Guard.ShiftLeft(left, (head, tail) => ExtractUnion(tail, right, [...result, ...ExtractType(head, right)]), () => result);
|
|
16
15
|
}
|
|
17
16
|
export function ExtractOperation(left, right) {
|
|
18
17
|
const evaluated = EvaluateType(left);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
-
import { type TCompare, type TCompareResult } from '../evaluate/compare.mjs';
|
|
3
|
-
type TComparer<Left extends TSchema, Right extends TSchema, CompareResult extends TCompareResult = TCompare<Left, Right>, Result extends 0 | 1 = (CompareResult extends
|
|
2
|
+
import { type TCompare, type TCompareResult, CompareResultRightInside, CompareResultDisjoint } from '../evaluate/compare.mjs';
|
|
3
|
+
type TComparer<Left extends TSchema, Right extends TSchema, CompareResult extends TCompareResult = TCompare<Left, Right>, Result extends 0 | 1 = (CompareResult extends typeof CompareResultRightInside ? 1 : CompareResult extends typeof CompareResultDisjoint ? 1 : 0)> = Result;
|
|
4
4
|
type TInsert<Type extends TSchema, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TComparer<Type, Left> extends 1 ? TInsert<Type, Right, [...Result, Left]> : [...Result, Type, ...Types] : [...Result, Type]);
|
|
5
5
|
type TSort<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TSort<Right, TInsert<Left, Result>> : Result);
|
|
6
6
|
/**
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
3
|
-
import { Compare } from '../evaluate/compare.mjs';
|
|
3
|
+
import { Compare, CompareResultRightInside, CompareResultDisjoint } from '../evaluate/compare.mjs';
|
|
4
4
|
function Comparer(left, right) {
|
|
5
5
|
const compareResult = Compare(left, right);
|
|
6
|
-
|
|
7
|
-
Guard.IsEqual(compareResult,
|
|
6
|
+
return (Guard.IsEqual(compareResult, CompareResultRightInside) ? 1 :
|
|
7
|
+
Guard.IsEqual(compareResult, CompareResultDisjoint) ? 1 :
|
|
8
8
|
0);
|
|
9
|
-
return result;
|
|
10
9
|
}
|
|
11
10
|
function Insert(type, types, result = []) {
|
|
12
11
|
return Guard.ShiftLeft(types, (left, right) => Guard.IsEqual(Comparer(type, left), 1)
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
// deno-lint-ignore-file
|
|
3
|
-
//
|
|
3
|
+
// ------------------------------------------------------------------
|
|
4
|
+
//
|
|
5
|
+
// This module was auto-generated by TypeBox's parser compiler
|
|
6
|
+
// infrastructure (ParseBox). The source grammar is located at:
|
|
7
|
+
//
|
|
8
|
+
// Source: ./design/syntax/syntax.ts
|
|
9
|
+
//
|
|
10
|
+
// ------------------------------------------------------------------
|
|
4
11
|
import * as S from './mapping.mjs';
|
|
5
12
|
import * as Token from './token/index.mjs';
|
|
6
13
|
const If = (result, left, right = () => []) => result.length === 2 ? left(result) : right();
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -113,11 +113,11 @@ type User = Type.Static<typeof User> // type User = {
|
|
|
113
113
|
|
|
114
114
|
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFkBDGAC0YgBMBXAG1WoBjCADsAzvGZs4AXkREAdAGVBUYGBgAKAAaU4cQmjgA1VIJjQALLLgBvOGQBccEdxDFUUADRwkz1+6ePgBe-m4e3nAA7mGBUHAAvnoGRCZmFlAAzDb2Ti7hQb6xESHFnonJhuim5tAATDkOZZF++XEV2gCU1HRwAOJQTGCswIJiHDz8QqIS-YPDo+NyyGjKqupaUqw+uvpVabCoZDnJ+pBiwDDAos41GZZepy7QIEy8t+nQmY-6+twAbh9alA6skkntUn1UDhUDAoEgTr84P9PFdBKgxB9DmQANoAXR+v2AIk4owxzXxYMqqSknmAb0RvyY7mAqBEMCB90J+lJGAw3DEqE5Vm5cDEaEEfCYUGFUEsVIhRgYGPYclsTwA5tCQLD4c4oTC4UhRa8YHS3s5aWo3lSutR9sqxKr5KslDAWKMADxVCAYOZDEZjHF4R2sPB4gB8+l6DpVjKRCcTSeTKZTvX0WsNerscAUecSotTReLJfTcFN5veObzCgqJfrDeTvQSQA) | [Example 2](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFkBDGAC0YgBMBXAG1WoBjCADsAzvABqqQTGgAWOAF5ERAHQB5YgCsZMABQBvOGQBcqtGoBy3EMVRR9ASgA0cJOeSWbdh87cAXp7qPvaOrnAA7sHetmHOcAC+TpTC4lJ60ADMyhaomjp6RiYx+aF+ER551nEVgaU1vuFJKWkScNKy0ABMuV75WrqyxWbV5eFuVf2N8U4t1HRwAOJQTGCswIJiHDz8QqLt0rCoZH3qg0WGlHBwkGLAMMCi5p1yUPIu13Ai0CBMvC9MlAsp8btwAG6ArpQbqUZKpA7wJaoHCoGBQJBnSwXYZXG7ghyPQSoMQNACCUFWSH0RxgJ1cX2AIk4mxJ5MpTGp03GzhS8La8GYdKgwH+WIGhVxXyYdmAqBEMChbw+XxZGAw3DEqCVClBcDEaEEfCYUB170+-MRjBJ7BU0xxBjxcAA5iiQGiMeZkaj0Ug9X9haKAYwWA4g3CUpRCGhrWJbdUAMowFibAA80ZRGFjrAAfDd8wXC4sM9nck7CxXK1XqzX84sbq6fZ64MY1G2knra13u1363AA2H-uZW+3El8exPJ3X6IkgA)
|
|
115
115
|
|
|
116
|
-
TypeBox includes a
|
|
116
|
+
TypeBox includes a micro TypeScript engine that can transform TypeScript definitions to JSON Schema. The engine is fully type-safe and supports many programmable constructs including Conditional, Mapped, Indexed, Generics, Distributive Generics, and more.
|
|
117
117
|
|
|
118
118
|
### Example
|
|
119
119
|
|
|
120
|
-
Syntax highlighting is available via the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=sinclairzx81.typebox-script)
|
|
120
|
+
Syntax highlighting is available via the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=sinclairzx81.typebox-script).
|
|
121
121
|
|
|
122
122
|
```typescript
|
|
123
123
|
import Type from 'typebox'
|
|
@@ -229,9 +229,9 @@ const result = Vector.Parse({ x: 1, y: 0, z: 0 }) // const result: {
|
|
|
229
229
|
|
|
230
230
|
### Coverage
|
|
231
231
|
|
|
232
|
-
|
|
232
|
+
[JSON Schema Test Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite) | [JSON Schema Compliance Suite](https://github.com/sinclairzx81/json-schema-compliance-suite)
|
|
233
233
|
|
|
234
|
-
|
|
234
|
+
TypeBox supports all major JSON Schema draft versions and tracks compliance against the official JSON Schema Test Suite. It also maintains a separate JavaScript compliance suite to track ecosystem adoption as JSON Schema moves toward the Version 1 candidate. The following table shows TypeBox specification coverage.
|
|
235
235
|
|
|
236
236
|
| Spec | 3 | 4 | 6 | 7 | 2019-09 | 2020-12 | v1 |
|
|
237
237
|
|:-----|:--|:--|:--|:--|:--|:--|:--|
|
|
@@ -281,10 +281,13 @@ The following table shows specification coverage implemented by TypeBox.
|
|
|
281
281
|
| unevaluatedProperties | - | - | - | - | ✅ | ✅ | 128/129 |
|
|
282
282
|
| uniqueItems | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
283
283
|
|
|
284
|
-
|
|
285
284
|
### Performance
|
|
286
285
|
|
|
287
|
-
|
|
286
|
+
TypeBox tracks comparative performance against AJV8 as the de facto JSON Schema performance standard. For broader comparative benchmarks, refer to the community maintained projects below.
|
|
287
|
+
|
|
288
|
+
[Runtime Benchmarks](https://moltar.github.io/typescript-runtime-type-benchmarks/) | [Schema Benchmarks](https://schemabenchmarks.dev/)
|
|
289
|
+
|
|
290
|
+
The following table shows compilation performance for various JSON Schema structures. These benchmarks measure the time required to JIT compile schematics, with faster compilation resulting in faster application startup.
|
|
288
291
|
|
|
289
292
|
```python
|
|
290
293
|
┌──────────────────────┬─────────────┬─────────────┐
|
|
@@ -316,8 +319,7 @@ The following table shows compile performance for various JSON Schema structures
|
|
|
316
319
|
└──────────────────────┴─────────────┴─────────────┘
|
|
317
320
|
```
|
|
318
321
|
|
|
319
|
-
|
|
320
|
-
The following tables shows validation performance for various JSON Schema structures using AJV8 as a basis for comparison.
|
|
322
|
+
The following tables shows validation performance for various JSON Schema structures. These benchmarks measure overall validation throughput for JIT compiled schematics.
|
|
321
323
|
|
|
322
324
|
```python
|
|
323
325
|
┌──────────────────────┬──────────────┬──────────────┐
|