typebox 1.3.11 → 1.3.13
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/date.d.mts +1 -1
- package/build/format/date.mjs +1 -1
- package/build/format/date_time.d.mts +2 -2
- package/build/format/date_time.mjs +3 -3
- package/build/format/email.d.mts +1 -1
- package/build/format/email.mjs +2 -2
- package/build/format/hostname.mjs +2 -10
- package/build/format/idn_email.d.mts +1 -1
- package/build/format/idn_email.mjs +3 -3
- package/build/format/idn_hostname.d.mts +1 -0
- package/build/format/idn_hostname.mjs +3 -11
- package/build/format/idna/format/bidi.d.mts +3 -0
- package/build/format/idna/format/bidi.mjs +98 -0
- package/build/format/idna/format/puny.d.mts +3 -0
- package/build/format/idna/format/puny.mjs +144 -0
- package/build/format/idna/hostname.d.mts +1 -0
- package/build/format/idna/hostname.mjs +16 -0
- package/build/format/idna/idn-hostname.d.mts +1 -0
- package/build/format/idna/idn-hostname.mjs +23 -0
- package/build/format/idna/index.d.mts +2 -0
- package/build/format/idna/index.mjs +2 -0
- package/build/format/idna/label/ascii.d.mts +1 -0
- package/build/format/idna/label/ascii.mjs +9 -0
- package/build/format/idna/label/puny.d.mts +1 -0
- package/build/format/idna/label/puny.mjs +28 -0
- package/build/format/idna/label/unicode.d.mts +1 -0
- package/build/format/idna/label/unicode.mjs +106 -0
- package/build/format/idna/pattern/pattern.d.mts +30 -0
- package/build/format/idna/pattern/pattern.mjs +70 -0
- package/build/format/ipv4.d.mts +0 -1
- package/build/format/ipv4.mjs +2 -32
- package/build/format/ipv6.mjs +2 -61
- package/build/format/iri.d.mts +1 -1
- package/build/format/iri.mjs +2 -8
- package/build/format/iri_reference.d.mts +2 -2
- package/build/format/iri_reference.mjs +9 -55
- package/build/format/regex.d.mts +1 -2
- package/build/format/regex.mjs +2 -6
- package/build/format/time.d.mts +2 -2
- package/build/format/time.mjs +19 -14
- package/build/format/uri.mjs +2 -129
- package/build/format/uri_template.d.mts +0 -1
- package/build/format/uri_template.mjs +1 -2
- package/build/format/url.d.mts +2 -2
- package/build/format/url.mjs +3 -4
- package/build/guard/guard.mjs +2 -2
- package/build/guard/string.d.mts +2 -2
- package/build/guard/string.mjs +7 -7
- package/build/schema/engine/_regexp.d.mts +2 -0
- package/build/schema/engine/_regexp.mjs +4 -0
- package/build/schema/engine/_stack.mjs +1 -1
- package/build/schema/engine/additionalProperties.mjs +4 -3
- package/build/schema/engine/pattern.mjs +3 -2
- package/build/schema/engine/patternProperties.mjs +4 -3
- package/build/schema/engine/schema.mjs +13 -4
- package/build/schema/resolve/ref.d.mts +1 -0
- package/build/schema/resolve/ref.mjs +13 -3
- package/build/schema/types/index.d.mts +0 -2
- package/build/schema/types/index.mjs +0 -2
- 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 +3 -4
- package/build/format/_idna.d.mts +0 -2
- package/build/format/_idna.mjs +0 -246
- package/build/format/_puny.d.mts +0 -1
- package/build/format/_puny.mjs +0 -77
- package/build/schema/types/contentEncoding.d.mts +0 -9
- package/build/schema/types/contentEncoding.mjs +0 -13
- package/build/schema/types/contentMediaType.d.mts +0 -9
- package/build/schema/types/contentMediaType.mjs +0 -13
|
@@ -22,7 +22,7 @@ export class Stack {
|
|
|
22
22
|
// Base
|
|
23
23
|
// ----------------------------------------------------------------
|
|
24
24
|
BaseURL() {
|
|
25
|
-
return this.ids.reduce((result, schema) => new URL(schema.$id, result),
|
|
25
|
+
return this.ids.reduce((result, schema) => new URL(schema.$id, result), Resolve.DefaultBase);
|
|
26
26
|
}
|
|
27
27
|
Base() {
|
|
28
28
|
return this.ids[this.ids.length - 1] ?? this.schema;
|
|
@@ -3,6 +3,7 @@ import * as S from '../types/index.mjs';
|
|
|
3
3
|
import * as V from './_externals.mjs';
|
|
4
4
|
import { Unique } from './_unique.mjs';
|
|
5
5
|
import { AccumulatedErrorContext } from './_context.mjs';
|
|
6
|
+
import { UnicodeRegExp } from './_regexp.mjs';
|
|
6
7
|
import { EmitGuard as E, Guard as G } from '../../guard/index.mjs';
|
|
7
8
|
import { BuildSchemaPushStack, CheckSchemaPushStack, ErrorSchemaPushStack } from './schema.mjs';
|
|
8
9
|
// ------------------------------------------------------------------
|
|
@@ -58,7 +59,7 @@ export function BuildAdditionalPropertiesFast(_context, schema, value) {
|
|
|
58
59
|
// ------------------------------------------------------------------
|
|
59
60
|
export function BuildAdditionalPropertiesStandard(stack, context, schema, value) {
|
|
60
61
|
const [key, _index] = [Unique(), Unique()];
|
|
61
|
-
const regexp = V.CreateVariable(
|
|
62
|
+
const regexp = V.CreateVariable(UnicodeRegExp(GetPropertiesPattern(schema)));
|
|
62
63
|
const isSchema = BuildSchemaPushStack(stack, context, schema.additionalProperties, `${value}[${key}]`);
|
|
63
64
|
const isKey = E.Call(E.Member(regexp, 'test'), [key]);
|
|
64
65
|
const addKey = context.AddKey(key);
|
|
@@ -78,7 +79,7 @@ export function BuildAdditionalProperties(stack, context, schema, value) {
|
|
|
78
79
|
// Check
|
|
79
80
|
// ------------------------------------------------------------------
|
|
80
81
|
export function CheckAdditionalProperties(stack, context, schema, value) {
|
|
81
|
-
const regexp =
|
|
82
|
+
const regexp = UnicodeRegExp(GetPropertiesPattern(schema));
|
|
82
83
|
const isAdditionalProperties = G.Every(G.Keys(value), 0, (key, _index) => {
|
|
83
84
|
return regexp.test(key) ||
|
|
84
85
|
(CheckSchemaPushStack(stack, context, schema.additionalProperties, value[key]) && context.AddKey(key));
|
|
@@ -89,7 +90,7 @@ export function CheckAdditionalProperties(stack, context, schema, value) {
|
|
|
89
90
|
// Error
|
|
90
91
|
// ------------------------------------------------------------------
|
|
91
92
|
export function ErrorAdditionalProperties(stack, context, schemaPath, instancePath, schema, value) {
|
|
92
|
-
const regexp =
|
|
93
|
+
const regexp = UnicodeRegExp(GetPropertiesPattern(schema));
|
|
93
94
|
const additionalProperties = [];
|
|
94
95
|
const isAdditionalProperties = G.EveryAll(G.Keys(value), 0, (key, _index) => {
|
|
95
96
|
const nextSchemaPath = `${schemaPath}/additionalProperties`;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import * as Externals from './_externals.mjs';
|
|
3
3
|
import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
|
|
4
|
+
import { UnicodeRegExp } from './_regexp.mjs';
|
|
4
5
|
// ------------------------------------------------------------------
|
|
5
6
|
// Build
|
|
6
7
|
// ------------------------------------------------------------------
|
|
7
8
|
export function BuildPattern(_stack, _context, schema, value) {
|
|
8
|
-
const regexp = Externals.CreateVariable(G.IsString(schema.pattern) ?
|
|
9
|
+
const regexp = Externals.CreateVariable(G.IsString(schema.pattern) ? UnicodeRegExp(schema.pattern) : schema.pattern);
|
|
9
10
|
return E.Call(E.Member(regexp, 'test'), [value]);
|
|
10
11
|
}
|
|
11
12
|
// ------------------------------------------------------------------
|
|
12
13
|
// Check
|
|
13
14
|
// ------------------------------------------------------------------
|
|
14
15
|
export function CheckPattern(_stack, _context, schema, value) {
|
|
15
|
-
const regexp = G.IsString(schema.pattern) ?
|
|
16
|
+
const regexp = G.IsString(schema.pattern) ? UnicodeRegExp(schema.pattern) : schema.pattern;
|
|
16
17
|
return regexp.test(value);
|
|
17
18
|
}
|
|
18
19
|
// ------------------------------------------------------------------
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import * as Externals from './_externals.mjs';
|
|
3
3
|
import { Unique } from './_unique.mjs';
|
|
4
|
+
import { UnicodeRegExp } from './_regexp.mjs';
|
|
4
5
|
import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
|
|
5
6
|
import { BuildSchemaPushStack, CheckSchemaPushStack, ErrorSchemaPushStack } from './schema.mjs';
|
|
6
7
|
// ------------------------------------------------------------------
|
|
@@ -9,7 +10,7 @@ import { BuildSchemaPushStack, CheckSchemaPushStack, ErrorSchemaPushStack } from
|
|
|
9
10
|
export function BuildPatternProperties(stack, context, schema, value) {
|
|
10
11
|
return E.ReduceAnd(G.Entries(schema.patternProperties).map(([pattern, schema]) => {
|
|
11
12
|
const [key, prop] = [Unique(), Unique()];
|
|
12
|
-
const regexp = Externals.CreateVariable(
|
|
13
|
+
const regexp = Externals.CreateVariable(UnicodeRegExp(pattern));
|
|
13
14
|
const notKey = E.Not(E.Call(E.Member(regexp, 'test'), [key]));
|
|
14
15
|
const isSchema = BuildSchemaPushStack(stack, context, schema, prop);
|
|
15
16
|
const addKey = context.AddKey(key);
|
|
@@ -22,7 +23,7 @@ export function BuildPatternProperties(stack, context, schema, value) {
|
|
|
22
23
|
// ------------------------------------------------------------------
|
|
23
24
|
export function CheckPatternProperties(stack, context, schema, value) {
|
|
24
25
|
return G.Every(G.Entries(schema.patternProperties), 0, ([pattern, schema]) => {
|
|
25
|
-
const regexp =
|
|
26
|
+
const regexp = UnicodeRegExp(pattern);
|
|
26
27
|
return G.Every(G.Entries(value), 0, ([key, prop]) => {
|
|
27
28
|
return !regexp.test(key) || CheckSchemaPushStack(stack, context, schema, prop) && context.AddKey(key);
|
|
28
29
|
});
|
|
@@ -34,7 +35,7 @@ export function CheckPatternProperties(stack, context, schema, value) {
|
|
|
34
35
|
export function ErrorPatternProperties(stack, context, schemaPath, instancePath, schema, value) {
|
|
35
36
|
return G.EveryAll(G.Entries(schema.patternProperties), 0, ([pattern, schema]) => {
|
|
36
37
|
const nextSchemaPath = `${schemaPath}/patternProperties/${pattern}`;
|
|
37
|
-
const regexp =
|
|
38
|
+
const regexp = UnicodeRegExp(pattern);
|
|
38
39
|
return G.EveryAll(G.Entries(value), 0, ([key, value]) => {
|
|
39
40
|
const nextInstancePath = `${instancePath}/${key}`;
|
|
40
41
|
const notKey = !regexp.test(key);
|
|
@@ -45,12 +45,21 @@ import { BuildUnevaluatedItems, CheckUnevaluatedItems, ErrorUnevaluatedItems } f
|
|
|
45
45
|
import { BuildUnevaluatedProperties, CheckUnevaluatedProperties, ErrorUnevaluatedProperties } from './unevaluatedProperties.mjs';
|
|
46
46
|
import { BuildUniqueItems, CheckUniqueItems, ErrorUniqueItems } from './uniqueItems.mjs';
|
|
47
47
|
// ----------------------------------------------------------------
|
|
48
|
-
// HasTypeName
|
|
48
|
+
// HasTypeName (Optimization)
|
|
49
|
+
//
|
|
50
|
+
// We only consider a schema as having a type name when the schema
|
|
51
|
+
// has a single type string, or when every element in the type
|
|
52
|
+
// array is the same. For a type array, we must treat multi-variant
|
|
53
|
+
// types as unions and therefore can NOT use an optimized forward
|
|
54
|
+
// type check.
|
|
55
|
+
//
|
|
49
56
|
// ----------------------------------------------------------------
|
|
50
57
|
function HasTypeName(schema, typename) {
|
|
51
|
-
return Schema.IsType(schema) &&
|
|
52
|
-
(G.IsArray(schema.type) &&
|
|
53
|
-
G.
|
|
58
|
+
return (Schema.IsType(schema) &&
|
|
59
|
+
((G.IsArray(schema.type) &&
|
|
60
|
+
G.IsGreaterThan(schema.type.length, 0) &&
|
|
61
|
+
G.Every(schema.type, 0, type => G.IsEqual(type, typename))) ||
|
|
62
|
+
G.IsEqual(schema.type, typename)));
|
|
54
63
|
}
|
|
55
64
|
// ----------------------------------------------------------------
|
|
56
65
|
// HasObject
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import * as Schema from '../types/index.mjs';
|
|
2
|
+
export declare const DefaultBase: URL;
|
|
2
3
|
export declare function Ref(schema: Schema.XSchemaObject, ref: string): Schema.XSchema | undefined;
|
|
3
4
|
export declare function DynamicRef(root: Schema.XSchemaObject, base: Schema.XSchemaObject, dynamicRef: Schema.XDynamicRef, dynamicAnchors: Schema.XDynamicAnchor[]): Schema.XSchema | undefined;
|
|
@@ -3,6 +3,10 @@ import { Guard } from '../../guard/index.mjs';
|
|
|
3
3
|
import { Pointer } from '../pointer/index.mjs';
|
|
4
4
|
import * as Schema from '../types/index.mjs';
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
|
+
// DefaultBase
|
|
7
|
+
// ------------------------------------------------------------------
|
|
8
|
+
export const DefaultBase = new URL('https://json-schema.org');
|
|
9
|
+
// ------------------------------------------------------------------
|
|
6
10
|
// Match: Id
|
|
7
11
|
// ------------------------------------------------------------------
|
|
8
12
|
function MatchId(schema, base, ref) {
|
|
@@ -83,8 +87,15 @@ function FromArray(schema, base, ref) {
|
|
|
83
87
|
// ------------------------------------------------------------------
|
|
84
88
|
// FromObject
|
|
85
89
|
// ------------------------------------------------------------------
|
|
90
|
+
function SkipProperty(key) {
|
|
91
|
+
// these are explicit data encoded in a schema, they should not
|
|
92
|
+
// be considered valid targets used for de-referencing.
|
|
93
|
+
return Guard.IsEqual(key, 'const') || Guard.IsEqual(key, 'enum');
|
|
94
|
+
}
|
|
86
95
|
function FromObject(schema, base, ref) {
|
|
87
96
|
return Guard.Keys(schema).reduce((result, key) => {
|
|
97
|
+
if (SkipProperty(key))
|
|
98
|
+
return result;
|
|
88
99
|
const match = FromValue(schema[key], base, ref);
|
|
89
100
|
return !Guard.IsUndefined(match) ? match : result;
|
|
90
101
|
}, undefined);
|
|
@@ -111,8 +122,7 @@ function FromValue(schema, base, ref) {
|
|
|
111
122
|
// Ref
|
|
112
123
|
// ------------------------------------------------------------------
|
|
113
124
|
export function Ref(schema, ref) {
|
|
114
|
-
const
|
|
115
|
-
const initialBase = Schema.IsId(schema) ? new URL(schema.$id, defaultBase.href) : defaultBase;
|
|
125
|
+
const initialBase = Schema.IsId(schema) ? new URL(schema.$id, DefaultBase.href) : DefaultBase;
|
|
116
126
|
const initialRef = new URL(ref, initialBase.href);
|
|
117
127
|
return FromValue(schema, initialBase, initialRef);
|
|
118
128
|
}
|
|
@@ -134,7 +144,7 @@ export function DynamicRef(root, base, dynamicRef, dynamicAnchors) {
|
|
|
134
144
|
// Extract the fragment portion of the reference. According to the test suite,
|
|
135
145
|
// only plain fragment names (e.g., "#foo") trigger the dynamic scope; JSON
|
|
136
146
|
// Pointer fragments (e.g., "#/definitions/foo") bypass dynamic resolution.
|
|
137
|
-
const fragment = new URL(dynamicRef.$dynamicRef,
|
|
147
|
+
const fragment = new URL(dynamicRef.$dynamicRef, DefaultBase).hash;
|
|
138
148
|
if (fragment.startsWith('#/'))
|
|
139
149
|
return fragmentTarget;
|
|
140
150
|
// Search the live dynamic anchor stack for a schema whose $dynamicAnchor matches the
|
|
@@ -6,8 +6,6 @@ export * from './anchor.mjs';
|
|
|
6
6
|
export * from './anyOf.mjs';
|
|
7
7
|
export * from './const.mjs';
|
|
8
8
|
export * from './contains.mjs';
|
|
9
|
-
export * from './contentEncoding.mjs';
|
|
10
|
-
export * from './contentMediaType.mjs';
|
|
11
9
|
export * from './default.mjs';
|
|
12
10
|
export * from './defs.mjs';
|
|
13
11
|
export * from './dependencies.mjs';
|
|
@@ -12,8 +12,6 @@ export * from './anchor.mjs';
|
|
|
12
12
|
export * from './anyOf.mjs';
|
|
13
13
|
export * from './const.mjs';
|
|
14
14
|
export * from './contains.mjs';
|
|
15
|
-
export * from './contentEncoding.mjs';
|
|
16
|
-
export * from './contentMediaType.mjs';
|
|
17
15
|
export * from './default.mjs';
|
|
18
16
|
export * from './defs.mjs';
|
|
19
17
|
export * from './dependencies.mjs';
|
|
@@ -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>;
|