@sinclair/typebox 0.32.0-dev-22 → 0.32.0-dev-24
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/import/compiler/compiler.d.mts +3 -2
- package/build/import/compiler/compiler.mjs +3 -2
- package/build/import/errors/errors.d.mts +2 -1
- package/build/import/errors/errors.mjs +2 -1
- package/build/import/index.d.mts +1 -0
- package/build/import/index.mjs +1 -0
- package/build/import/system/system.d.mts +3 -2
- package/build/import/system/system.mjs +3 -2
- package/build/import/type/error/error.d.mts +4 -0
- package/build/import/type/error/error.mjs +6 -0
- package/build/import/type/error/index.d.mts +1 -0
- package/build/import/type/error/index.mjs +1 -0
- package/build/import/type/extends/extends-check.d.mts +2 -1
- package/build/import/type/extends/extends-check.mjs +2 -1
- package/build/import/type/guard/type.d.mts +2 -1
- package/build/import/type/guard/type.mjs +2 -1
- package/build/import/type/index.d.mts +1 -0
- package/build/import/type/index.mjs +1 -0
- package/build/import/type/record/record.d.mts +1 -1
- package/build/import/type/template-literal/finite.d.mts +2 -1
- package/build/import/type/template-literal/finite.mjs +2 -1
- package/build/import/type/template-literal/generate.d.mts +3 -2
- package/build/import/type/template-literal/generate.mjs +2 -1
- package/build/import/type/template-literal/parse.d.mts +2 -1
- package/build/import/type/template-literal/parse.mjs +2 -1
- package/build/import/type/template-literal/pattern.d.mts +2 -1
- package/build/import/type/template-literal/pattern.mjs +2 -1
- package/build/import/value/cast/cast.d.mts +5 -4
- package/build/import/value/cast/cast.mjs +5 -4
- package/build/import/value/check/check.d.mts +2 -1
- package/build/import/value/check/check.mjs +2 -1
- package/build/import/value/convert/convert.d.mts +2 -1
- package/build/import/value/convert/convert.mjs +2 -1
- package/build/import/value/create/create.d.mts +7 -6
- package/build/import/value/create/create.mjs +7 -6
- package/build/import/value/delta/delta.d.mts +3 -2
- package/build/import/value/delta/delta.mjs +3 -2
- package/build/import/value/deref/deref.d.mts +2 -1
- package/build/import/value/deref/deref.mjs +2 -1
- package/build/import/value/hash/hash.d.mts +2 -1
- package/build/import/value/hash/hash.mjs +2 -1
- package/build/import/value/mutate/mutate.d.mts +3 -2
- package/build/import/value/mutate/mutate.mjs +3 -2
- package/build/import/value/pointer/pointer.d.mts +3 -2
- package/build/import/value/pointer/pointer.mjs +3 -2
- package/build/import/value/transform/decode.d.mts +3 -2
- package/build/import/value/transform/decode.mjs +3 -2
- package/build/import/value/transform/encode.d.mts +3 -2
- package/build/import/value/transform/encode.mjs +3 -2
- package/build/require/compiler/compiler.d.ts +3 -2
- package/build/require/compiler/compiler.js +61 -60
- package/build/require/errors/errors.d.ts +2 -1
- package/build/require/errors/errors.js +34 -33
- package/build/require/index.d.ts +1 -0
- package/build/require/index.js +154 -152
- package/build/require/system/system.d.ts +3 -2
- package/build/require/system/system.js +3 -2
- package/build/require/type/error/error.d.ts +4 -0
- package/build/require/type/error/error.js +11 -0
- package/build/require/type/error/index.d.ts +1 -0
- package/build/require/type/error/index.js +18 -0
- package/build/require/type/extends/extends-check.d.ts +2 -1
- package/build/require/type/extends/extends-check.js +172 -171
- package/build/require/type/guard/type.d.ts +2 -1
- package/build/require/type/guard/type.js +2 -1
- package/build/require/type/index.d.ts +1 -0
- package/build/require/type/index.js +1 -0
- package/build/require/type/record/record.d.ts +1 -1
- package/build/require/type/template-literal/finite.d.ts +2 -1
- package/build/require/type/template-literal/finite.js +2 -1
- package/build/require/type/template-literal/generate.d.ts +3 -2
- package/build/require/type/template-literal/generate.js +2 -1
- package/build/require/type/template-literal/parse.d.ts +2 -1
- package/build/require/type/template-literal/parse.js +3 -2
- package/build/require/type/template-literal/pattern.d.ts +2 -1
- package/build/require/type/template-literal/pattern.js +2 -1
- package/build/require/value/cast/cast.d.ts +5 -4
- package/build/require/value/cast/cast.js +36 -35
- package/build/require/value/check/check.d.ts +2 -1
- package/build/require/value/check/check.js +24 -23
- package/build/require/value/convert/convert.d.ts +2 -1
- package/build/require/value/convert/convert.js +32 -31
- package/build/require/value/create/create.d.ts +7 -6
- package/build/require/value/create/create.js +7 -6
- package/build/require/value/delta/delta.d.ts +3 -2
- package/build/require/value/delta/delta.js +20 -19
- package/build/require/value/deref/deref.d.ts +2 -1
- package/build/require/value/deref/deref.js +2 -1
- package/build/require/value/hash/hash.d.ts +2 -1
- package/build/require/value/hash/hash.js +2 -1
- package/build/require/value/mutate/mutate.d.ts +3 -2
- package/build/require/value/mutate/mutate.js +3 -2
- package/build/require/value/pointer/pointer.d.ts +3 -2
- package/build/require/value/pointer/pointer.js +3 -2
- package/build/require/value/transform/decode.d.ts +3 -2
- package/build/require/value/transform/decode.js +19 -18
- package/build/require/value/transform/encode.d.ts +3 -2
- package/build/require/value/transform/encode.js +20 -19
- package/package.json +1 -1
- package/readme.md +117 -137
|
@@ -10,8 +10,9 @@ const index_5 = require("../unknown/index");
|
|
|
10
10
|
const index_6 = require("../template-literal/index");
|
|
11
11
|
const index_7 = require("../patterns/index");
|
|
12
12
|
const index_8 = require("../symbols/index");
|
|
13
|
-
const index_9 = require("../
|
|
14
|
-
|
|
13
|
+
const index_9 = require("../error/index");
|
|
14
|
+
const index_10 = require("../guard/index");
|
|
15
|
+
class ExtendsResolverError extends index_9.TypeBoxError {
|
|
15
16
|
}
|
|
16
17
|
exports.ExtendsResolverError = ExtendsResolverError;
|
|
17
18
|
var ExtendsResult;
|
|
@@ -39,19 +40,19 @@ function Throw(message) {
|
|
|
39
40
|
// ------------------------------------------------------------------
|
|
40
41
|
// prettier-ignore
|
|
41
42
|
function IsStructuralRight(right) {
|
|
42
|
-
return (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
return (index_10.TypeGuard.IsNever(right) ||
|
|
44
|
+
index_10.TypeGuard.IsIntersect(right) ||
|
|
45
|
+
index_10.TypeGuard.IsUnion(right) ||
|
|
46
|
+
index_10.TypeGuard.IsUnknown(right) ||
|
|
47
|
+
index_10.TypeGuard.IsAny(right));
|
|
47
48
|
}
|
|
48
49
|
// prettier-ignore
|
|
49
50
|
function StructuralRight(left, right) {
|
|
50
|
-
return (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
return (index_10.TypeGuard.IsNever(right) ? TNeverRight(left, right) :
|
|
52
|
+
index_10.TypeGuard.IsIntersect(right) ? TIntersectRight(left, right) :
|
|
53
|
+
index_10.TypeGuard.IsUnion(right) ? TUnionRight(left, right) :
|
|
54
|
+
index_10.TypeGuard.IsUnknown(right) ? TUnknownRight(left, right) :
|
|
55
|
+
index_10.TypeGuard.IsAny(right) ? TAnyRight(left, right) :
|
|
55
56
|
Throw('StructuralRight'));
|
|
56
57
|
}
|
|
57
58
|
// ------------------------------------------------------------------
|
|
@@ -63,11 +64,11 @@ function TAnyRight(left, right) {
|
|
|
63
64
|
}
|
|
64
65
|
// prettier-ignore
|
|
65
66
|
function TAny(left, right) {
|
|
66
|
-
return (
|
|
67
|
-
(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
return (index_10.TypeGuard.IsIntersect(right) ? TIntersectRight(left, right) :
|
|
68
|
+
(index_10.TypeGuard.IsUnion(right) && right.anyOf.some((schema) => index_10.TypeGuard.IsAny(schema) || index_10.TypeGuard.IsUnknown(schema))) ? ExtendsResult.True :
|
|
69
|
+
index_10.TypeGuard.IsUnion(right) ? ExtendsResult.Union :
|
|
70
|
+
index_10.TypeGuard.IsUnknown(right) ? ExtendsResult.True :
|
|
71
|
+
index_10.TypeGuard.IsAny(right) ? ExtendsResult.True :
|
|
71
72
|
ExtendsResult.Union);
|
|
72
73
|
}
|
|
73
74
|
// ------------------------------------------------------------------
|
|
@@ -75,16 +76,16 @@ function TAny(left, right) {
|
|
|
75
76
|
// ------------------------------------------------------------------
|
|
76
77
|
// prettier-ignore
|
|
77
78
|
function TArrayRight(left, right) {
|
|
78
|
-
return (
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
return (index_10.TypeGuard.IsUnknown(left) ? ExtendsResult.False :
|
|
80
|
+
index_10.TypeGuard.IsAny(left) ? ExtendsResult.Union :
|
|
81
|
+
index_10.TypeGuard.IsNever(left) ? ExtendsResult.True :
|
|
81
82
|
ExtendsResult.False);
|
|
82
83
|
}
|
|
83
84
|
// prettier-ignore
|
|
84
85
|
function TArray(left, right) {
|
|
85
|
-
return (
|
|
86
|
+
return (index_10.TypeGuard.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True :
|
|
86
87
|
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
87
|
-
!
|
|
88
|
+
!index_10.TypeGuard.IsArray(right) ? ExtendsResult.False :
|
|
88
89
|
IntoBooleanResult(Visit(left.items, right.items)));
|
|
89
90
|
}
|
|
90
91
|
// ------------------------------------------------------------------
|
|
@@ -93,7 +94,7 @@ function TArray(left, right) {
|
|
|
93
94
|
// prettier-ignore
|
|
94
95
|
function TAsyncIterator(left, right) {
|
|
95
96
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
96
|
-
!
|
|
97
|
+
!index_10.TypeGuard.IsAsyncIterator(right) ? ExtendsResult.False :
|
|
97
98
|
IntoBooleanResult(Visit(left.items, right.items)));
|
|
98
99
|
}
|
|
99
100
|
// ------------------------------------------------------------------
|
|
@@ -102,9 +103,9 @@ function TAsyncIterator(left, right) {
|
|
|
102
103
|
// prettier-ignore
|
|
103
104
|
function TBigInt(left, right) {
|
|
104
105
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
107
|
+
index_10.TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
108
|
+
index_10.TypeGuard.IsBigInt(right) ? ExtendsResult.True :
|
|
108
109
|
ExtendsResult.False);
|
|
109
110
|
}
|
|
110
111
|
// ------------------------------------------------------------------
|
|
@@ -112,16 +113,16 @@ function TBigInt(left, right) {
|
|
|
112
113
|
// ------------------------------------------------------------------
|
|
113
114
|
// prettier-ignore
|
|
114
115
|
function TBooleanRight(left, right) {
|
|
115
|
-
return (
|
|
116
|
-
|
|
116
|
+
return (index_10.TypeGuard.IsLiteralBoolean(left) ? ExtendsResult.True :
|
|
117
|
+
index_10.TypeGuard.IsBoolean(left) ? ExtendsResult.True :
|
|
117
118
|
ExtendsResult.False);
|
|
118
119
|
}
|
|
119
120
|
// prettier-ignore
|
|
120
121
|
function TBoolean(left, right) {
|
|
121
122
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
124
|
+
index_10.TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
125
|
+
index_10.TypeGuard.IsBoolean(right) ? ExtendsResult.True :
|
|
125
126
|
ExtendsResult.False);
|
|
126
127
|
}
|
|
127
128
|
// ------------------------------------------------------------------
|
|
@@ -130,8 +131,8 @@ function TBoolean(left, right) {
|
|
|
130
131
|
// prettier-ignore
|
|
131
132
|
function TConstructor(left, right) {
|
|
132
133
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
133
|
-
|
|
134
|
-
!
|
|
134
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
135
|
+
!index_10.TypeGuard.IsConstructor(right) ? ExtendsResult.False :
|
|
135
136
|
left.parameters.length > right.parameters.length ? ExtendsResult.False :
|
|
136
137
|
(!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === ExtendsResult.True)) ? ExtendsResult.False :
|
|
137
138
|
IntoBooleanResult(Visit(left.returns, right.returns)));
|
|
@@ -142,9 +143,9 @@ function TConstructor(left, right) {
|
|
|
142
143
|
// prettier-ignore
|
|
143
144
|
function TDate(left, right) {
|
|
144
145
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
147
|
+
index_10.TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
148
|
+
index_10.TypeGuard.IsDate(right) ? ExtendsResult.True :
|
|
148
149
|
ExtendsResult.False);
|
|
149
150
|
}
|
|
150
151
|
// ------------------------------------------------------------------
|
|
@@ -153,8 +154,8 @@ function TDate(left, right) {
|
|
|
153
154
|
// prettier-ignore
|
|
154
155
|
function TFunction(left, right) {
|
|
155
156
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
156
|
-
|
|
157
|
-
!
|
|
157
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
158
|
+
!index_10.TypeGuard.IsFunction(right) ? ExtendsResult.False :
|
|
158
159
|
left.parameters.length > right.parameters.length ? ExtendsResult.False :
|
|
159
160
|
(!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === ExtendsResult.True)) ? ExtendsResult.False :
|
|
160
161
|
IntoBooleanResult(Visit(left.returns, right.returns)));
|
|
@@ -164,16 +165,16 @@ function TFunction(left, right) {
|
|
|
164
165
|
// ------------------------------------------------------------------
|
|
165
166
|
// prettier-ignore
|
|
166
167
|
function TIntegerRight(left, right) {
|
|
167
|
-
return (
|
|
168
|
-
|
|
168
|
+
return (index_10.TypeGuard.IsLiteral(left) && index_10.ValueGuard.IsNumber(left.const) ? ExtendsResult.True :
|
|
169
|
+
index_10.TypeGuard.IsNumber(left) || index_10.TypeGuard.IsInteger(left) ? ExtendsResult.True :
|
|
169
170
|
ExtendsResult.False);
|
|
170
171
|
}
|
|
171
172
|
// prettier-ignore
|
|
172
173
|
function TInteger(left, right) {
|
|
173
|
-
return (
|
|
174
|
+
return (index_10.TypeGuard.IsInteger(right) || index_10.TypeGuard.IsNumber(right) ? ExtendsResult.True :
|
|
174
175
|
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
175
|
-
|
|
176
|
-
|
|
176
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
177
|
+
index_10.TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
177
178
|
ExtendsResult.False);
|
|
178
179
|
}
|
|
179
180
|
// ------------------------------------------------------------------
|
|
@@ -197,7 +198,7 @@ function TIntersect(left, right) {
|
|
|
197
198
|
// prettier-ignore
|
|
198
199
|
function TIterator(left, right) {
|
|
199
200
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
200
|
-
!
|
|
201
|
+
!index_10.TypeGuard.IsIterator(right) ? ExtendsResult.False :
|
|
201
202
|
IntoBooleanResult(Visit(left.items, right.items)));
|
|
202
203
|
}
|
|
203
204
|
// ------------------------------------------------------------------
|
|
@@ -205,14 +206,14 @@ function TIterator(left, right) {
|
|
|
205
206
|
// ------------------------------------------------------------------
|
|
206
207
|
// prettier-ignore
|
|
207
208
|
function TLiteral(left, right) {
|
|
208
|
-
return (
|
|
209
|
+
return (index_10.TypeGuard.IsLiteral(right) && right.const === left.const ? ExtendsResult.True :
|
|
209
210
|
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
211
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
212
|
+
index_10.TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
213
|
+
index_10.TypeGuard.IsString(right) ? TStringRight(left, right) :
|
|
214
|
+
index_10.TypeGuard.IsNumber(right) ? TNumberRight(left, right) :
|
|
215
|
+
index_10.TypeGuard.IsInteger(right) ? TIntegerRight(left, right) :
|
|
216
|
+
index_10.TypeGuard.IsBoolean(right) ? TBooleanRight(left, right) :
|
|
216
217
|
ExtendsResult.False);
|
|
217
218
|
}
|
|
218
219
|
// ------------------------------------------------------------------
|
|
@@ -233,7 +234,7 @@ function TNever(left, right) {
|
|
|
233
234
|
function UnwrapTNot(schema) {
|
|
234
235
|
let [current, depth] = [schema, 0];
|
|
235
236
|
while (true) {
|
|
236
|
-
if (!
|
|
237
|
+
if (!index_10.TypeGuard.IsNot(current))
|
|
237
238
|
break;
|
|
238
239
|
current = current.not;
|
|
239
240
|
depth += 1;
|
|
@@ -246,8 +247,8 @@ function TNot(left, right) {
|
|
|
246
247
|
// type at runtime would put TypeBox at odds with TypeScripts ability to statically infer
|
|
247
248
|
// the type. Instead we unwrap to either unknown or T and continue evaluating.
|
|
248
249
|
// prettier-ignore
|
|
249
|
-
return (
|
|
250
|
-
|
|
250
|
+
return (index_10.TypeGuard.IsNot(left) ? Visit(UnwrapTNot(left), right) :
|
|
251
|
+
index_10.TypeGuard.IsNot(right) ? Visit(left, UnwrapTNot(right)) :
|
|
251
252
|
Throw('Invalid fallthrough for Not'));
|
|
252
253
|
}
|
|
253
254
|
// ------------------------------------------------------------------
|
|
@@ -256,9 +257,9 @@ function TNot(left, right) {
|
|
|
256
257
|
// prettier-ignore
|
|
257
258
|
function TNull(left, right) {
|
|
258
259
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
260
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
261
|
+
index_10.TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
262
|
+
index_10.TypeGuard.IsNull(right) ? ExtendsResult.True :
|
|
262
263
|
ExtendsResult.False);
|
|
263
264
|
}
|
|
264
265
|
// ------------------------------------------------------------------
|
|
@@ -266,16 +267,16 @@ function TNull(left, right) {
|
|
|
266
267
|
// ------------------------------------------------------------------
|
|
267
268
|
// prettier-ignore
|
|
268
269
|
function TNumberRight(left, right) {
|
|
269
|
-
return (
|
|
270
|
-
|
|
270
|
+
return (index_10.TypeGuard.IsLiteralNumber(left) ? ExtendsResult.True :
|
|
271
|
+
index_10.TypeGuard.IsNumber(left) || index_10.TypeGuard.IsInteger(left) ? ExtendsResult.True :
|
|
271
272
|
ExtendsResult.False);
|
|
272
273
|
}
|
|
273
274
|
// prettier-ignore
|
|
274
275
|
function TNumber(left, right) {
|
|
275
276
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
277
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
278
|
+
index_10.TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
279
|
+
index_10.TypeGuard.IsInteger(right) || index_10.TypeGuard.IsNumber(right) ? ExtendsResult.True :
|
|
279
280
|
ExtendsResult.False);
|
|
280
281
|
}
|
|
281
282
|
// ------------------------------------------------------------------
|
|
@@ -291,9 +292,9 @@ function IsObjectStringLike(schema) {
|
|
|
291
292
|
}
|
|
292
293
|
// prettier-ignore
|
|
293
294
|
function IsObjectSymbolLike(schema) {
|
|
294
|
-
return IsObjectPropertyCount(schema, 0) || (IsObjectPropertyCount(schema, 1) && 'description' in schema.properties &&
|
|
295
|
-
|
|
296
|
-
|
|
295
|
+
return IsObjectPropertyCount(schema, 0) || (IsObjectPropertyCount(schema, 1) && 'description' in schema.properties && index_10.TypeGuard.IsUnion(schema.properties.description) && schema.properties.description.anyOf.length === 2 && ((index_10.TypeGuard.IsString(schema.properties.description.anyOf[0]) &&
|
|
296
|
+
index_10.TypeGuard.IsUndefined(schema.properties.description.anyOf[1])) || (index_10.TypeGuard.IsString(schema.properties.description.anyOf[1]) &&
|
|
297
|
+
index_10.TypeGuard.IsUndefined(schema.properties.description.anyOf[0]))));
|
|
297
298
|
}
|
|
298
299
|
// prettier-ignore
|
|
299
300
|
function IsObjectNumberLike(schema) {
|
|
@@ -340,33 +341,33 @@ function IsObjectPromiseLike(schema) {
|
|
|
340
341
|
// prettier-ignore
|
|
341
342
|
function Property(left, right) {
|
|
342
343
|
return (Visit(left, right) === ExtendsResult.False ? ExtendsResult.False :
|
|
343
|
-
|
|
344
|
+
index_10.TypeGuard.IsOptional(left) && !index_10.TypeGuard.IsOptional(right) ? ExtendsResult.False :
|
|
344
345
|
ExtendsResult.True);
|
|
345
346
|
}
|
|
346
347
|
// prettier-ignore
|
|
347
348
|
function TObjectRight(left, right) {
|
|
348
|
-
return (
|
|
349
|
-
|
|
350
|
-
(
|
|
351
|
-
(
|
|
352
|
-
(
|
|
353
|
-
(
|
|
354
|
-
(
|
|
355
|
-
(
|
|
356
|
-
(
|
|
357
|
-
(
|
|
358
|
-
(
|
|
359
|
-
(
|
|
360
|
-
(
|
|
361
|
-
(
|
|
362
|
-
(
|
|
363
|
-
(
|
|
364
|
-
(
|
|
349
|
+
return (index_10.TypeGuard.IsUnknown(left) ? ExtendsResult.False :
|
|
350
|
+
index_10.TypeGuard.IsAny(left) ? ExtendsResult.Union : (index_10.TypeGuard.IsNever(left) ||
|
|
351
|
+
(index_10.TypeGuard.IsLiteralString(left) && IsObjectStringLike(right)) ||
|
|
352
|
+
(index_10.TypeGuard.IsLiteralNumber(left) && IsObjectNumberLike(right)) ||
|
|
353
|
+
(index_10.TypeGuard.IsLiteralBoolean(left) && IsObjectBooleanLike(right)) ||
|
|
354
|
+
(index_10.TypeGuard.IsSymbol(left) && IsObjectSymbolLike(right)) ||
|
|
355
|
+
(index_10.TypeGuard.IsBigInt(left) && IsObjectBigIntLike(right)) ||
|
|
356
|
+
(index_10.TypeGuard.IsString(left) && IsObjectStringLike(right)) ||
|
|
357
|
+
(index_10.TypeGuard.IsSymbol(left) && IsObjectSymbolLike(right)) ||
|
|
358
|
+
(index_10.TypeGuard.IsNumber(left) && IsObjectNumberLike(right)) ||
|
|
359
|
+
(index_10.TypeGuard.IsInteger(left) && IsObjectNumberLike(right)) ||
|
|
360
|
+
(index_10.TypeGuard.IsBoolean(left) && IsObjectBooleanLike(right)) ||
|
|
361
|
+
(index_10.TypeGuard.IsUint8Array(left) && IsObjectUint8ArrayLike(right)) ||
|
|
362
|
+
(index_10.TypeGuard.IsDate(left) && IsObjectDateLike(right)) ||
|
|
363
|
+
(index_10.TypeGuard.IsConstructor(left) && IsObjectConstructorLike(right)) ||
|
|
364
|
+
(index_10.TypeGuard.IsFunction(left) && IsObjectFunctionLike(right))) ? ExtendsResult.True :
|
|
365
|
+
(index_10.TypeGuard.IsRecord(left) && index_10.TypeGuard.IsString(RecordKey(left))) ? (() => {
|
|
365
366
|
// When expressing a Record with literal key values, the Record is converted into a Object with
|
|
366
367
|
// the Hint assigned as `Record`. This is used to invert the extends logic.
|
|
367
368
|
return right[index_8.Hint] === 'Record' ? ExtendsResult.True : ExtendsResult.False;
|
|
368
369
|
})() :
|
|
369
|
-
(
|
|
370
|
+
(index_10.TypeGuard.IsRecord(left) && index_10.TypeGuard.IsNumber(RecordKey(left))) ? (() => {
|
|
370
371
|
return IsObjectPropertyCount(right, 0) ? ExtendsResult.True : ExtendsResult.False;
|
|
371
372
|
})() :
|
|
372
373
|
ExtendsResult.False);
|
|
@@ -374,14 +375,14 @@ function TObjectRight(left, right) {
|
|
|
374
375
|
// prettier-ignore
|
|
375
376
|
function TObject(left, right) {
|
|
376
377
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
377
|
-
|
|
378
|
-
!
|
|
378
|
+
index_10.TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
379
|
+
!index_10.TypeGuard.IsObject(right) ? ExtendsResult.False :
|
|
379
380
|
(() => {
|
|
380
381
|
for (const key of Object.getOwnPropertyNames(right.properties)) {
|
|
381
|
-
if (!(key in left.properties) && !
|
|
382
|
+
if (!(key in left.properties) && !index_10.TypeGuard.IsOptional(right.properties[key])) {
|
|
382
383
|
return ExtendsResult.False;
|
|
383
384
|
}
|
|
384
|
-
if (
|
|
385
|
+
if (index_10.TypeGuard.IsOptional(right.properties[key])) {
|
|
385
386
|
return ExtendsResult.True;
|
|
386
387
|
}
|
|
387
388
|
if (Property(left.properties[key], right.properties[key]) === ExtendsResult.False) {
|
|
@@ -397,8 +398,8 @@ function TObject(left, right) {
|
|
|
397
398
|
// prettier-ignore
|
|
398
399
|
function TPromise(left, right) {
|
|
399
400
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
400
|
-
|
|
401
|
-
!
|
|
401
|
+
index_10.TypeGuard.IsObject(right) && IsObjectPromiseLike(right) ? ExtendsResult.True :
|
|
402
|
+
!index_10.TypeGuard.IsPromise(right) ? ExtendsResult.False :
|
|
402
403
|
IntoBooleanResult(Visit(left.item, right.item)));
|
|
403
404
|
}
|
|
404
405
|
// ------------------------------------------------------------------
|
|
@@ -419,11 +420,11 @@ function RecordValue(schema) {
|
|
|
419
420
|
// prettier-ignore
|
|
420
421
|
function TRecordRight(left, right) {
|
|
421
422
|
const [Key, Value] = [RecordKey(right), RecordValue(right)];
|
|
422
|
-
return ((
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
423
|
+
return ((index_10.TypeGuard.IsLiteralString(left) && index_10.TypeGuard.IsNumber(Key) && IntoBooleanResult(Visit(left, Value)) === ExtendsResult.True) ? ExtendsResult.True :
|
|
424
|
+
index_10.TypeGuard.IsUint8Array(left) && index_10.TypeGuard.IsNumber(Key) ? Visit(left, Value) :
|
|
425
|
+
index_10.TypeGuard.IsString(left) && index_10.TypeGuard.IsNumber(Key) ? Visit(left, Value) :
|
|
426
|
+
index_10.TypeGuard.IsArray(left) && index_10.TypeGuard.IsNumber(Key) ? Visit(left, Value) :
|
|
427
|
+
index_10.TypeGuard.IsObject(left) ? (() => {
|
|
427
428
|
for (const key of Object.getOwnPropertyNames(left.properties)) {
|
|
428
429
|
if (Property(Value, left.properties[key]) === ExtendsResult.False) {
|
|
429
430
|
return ExtendsResult.False;
|
|
@@ -436,8 +437,8 @@ function TRecordRight(left, right) {
|
|
|
436
437
|
// prettier-ignore
|
|
437
438
|
function TRecord(left, right) {
|
|
438
439
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
439
|
-
|
|
440
|
-
!
|
|
440
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
441
|
+
!index_10.TypeGuard.IsRecord(right) ? ExtendsResult.False :
|
|
441
442
|
Visit(RecordValue(left), RecordValue(right)));
|
|
442
443
|
}
|
|
443
444
|
// ------------------------------------------------------------------
|
|
@@ -445,16 +446,16 @@ function TRecord(left, right) {
|
|
|
445
446
|
// ------------------------------------------------------------------
|
|
446
447
|
// prettier-ignore
|
|
447
448
|
function TStringRight(left, right) {
|
|
448
|
-
return (
|
|
449
|
-
|
|
449
|
+
return (index_10.TypeGuard.IsLiteral(left) && index_10.ValueGuard.IsString(left.const) ? ExtendsResult.True :
|
|
450
|
+
index_10.TypeGuard.IsString(left) ? ExtendsResult.True :
|
|
450
451
|
ExtendsResult.False);
|
|
451
452
|
}
|
|
452
453
|
// prettier-ignore
|
|
453
454
|
function TString(left, right) {
|
|
454
455
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
456
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
457
|
+
index_10.TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
458
|
+
index_10.TypeGuard.IsString(right) ? ExtendsResult.True :
|
|
458
459
|
ExtendsResult.False);
|
|
459
460
|
}
|
|
460
461
|
// ------------------------------------------------------------------
|
|
@@ -463,9 +464,9 @@ function TString(left, right) {
|
|
|
463
464
|
// prettier-ignore
|
|
464
465
|
function TSymbol(left, right) {
|
|
465
466
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
467
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
468
|
+
index_10.TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
469
|
+
index_10.TypeGuard.IsSymbol(right) ? ExtendsResult.True :
|
|
469
470
|
ExtendsResult.False);
|
|
470
471
|
}
|
|
471
472
|
// ------------------------------------------------------------------
|
|
@@ -476,8 +477,8 @@ function TTemplateLiteral(left, right) {
|
|
|
476
477
|
// TemplateLiteral types are resolved to either unions for finite expressions or string
|
|
477
478
|
// for infinite expressions. Here we call to TemplateLiteralResolver to resolve for
|
|
478
479
|
// either type and continue evaluating.
|
|
479
|
-
return (
|
|
480
|
-
|
|
480
|
+
return (index_10.TypeGuard.IsTemplateLiteral(left) ? Visit((0, index_6.TemplateLiteralToUnion)(left), right) :
|
|
481
|
+
index_10.TypeGuard.IsTemplateLiteral(right) ? Visit(left, (0, index_6.TemplateLiteralToUnion)(right)) :
|
|
481
482
|
Throw('Invalid fallthrough for TemplateLiteral'));
|
|
482
483
|
}
|
|
483
484
|
// ------------------------------------------------------------------
|
|
@@ -485,25 +486,25 @@ function TTemplateLiteral(left, right) {
|
|
|
485
486
|
// ------------------------------------------------------------------
|
|
486
487
|
// prettier-ignore
|
|
487
488
|
function IsArrayOfTuple(left, right) {
|
|
488
|
-
return (
|
|
489
|
+
return (index_10.TypeGuard.IsArray(right) &&
|
|
489
490
|
left.items !== undefined &&
|
|
490
491
|
left.items.every((schema) => Visit(schema, right.items) === ExtendsResult.True));
|
|
491
492
|
}
|
|
492
493
|
// prettier-ignore
|
|
493
494
|
function TTupleRight(left, right) {
|
|
494
|
-
return (
|
|
495
|
-
|
|
496
|
-
|
|
495
|
+
return (index_10.TypeGuard.IsNever(left) ? ExtendsResult.True :
|
|
496
|
+
index_10.TypeGuard.IsUnknown(left) ? ExtendsResult.False :
|
|
497
|
+
index_10.TypeGuard.IsAny(left) ? ExtendsResult.Union :
|
|
497
498
|
ExtendsResult.False);
|
|
498
499
|
}
|
|
499
500
|
// prettier-ignore
|
|
500
501
|
function TTuple(left, right) {
|
|
501
502
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
!
|
|
505
|
-
(
|
|
506
|
-
(
|
|
503
|
+
index_10.TypeGuard.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True :
|
|
504
|
+
index_10.TypeGuard.IsArray(right) && IsArrayOfTuple(left, right) ? ExtendsResult.True :
|
|
505
|
+
!index_10.TypeGuard.IsTuple(right) ? ExtendsResult.False :
|
|
506
|
+
(index_10.ValueGuard.IsUndefined(left.items) && !index_10.ValueGuard.IsUndefined(right.items)) || (!index_10.ValueGuard.IsUndefined(left.items) && index_10.ValueGuard.IsUndefined(right.items)) ? ExtendsResult.False :
|
|
507
|
+
(index_10.ValueGuard.IsUndefined(left.items) && !index_10.ValueGuard.IsUndefined(right.items)) ? ExtendsResult.True :
|
|
507
508
|
left.items.every((schema, index) => Visit(schema, right.items[index]) === ExtendsResult.True) ? ExtendsResult.True :
|
|
508
509
|
ExtendsResult.False);
|
|
509
510
|
}
|
|
@@ -513,9 +514,9 @@ function TTuple(left, right) {
|
|
|
513
514
|
// prettier-ignore
|
|
514
515
|
function TUint8Array(left, right) {
|
|
515
516
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
517
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
518
|
+
index_10.TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
519
|
+
index_10.TypeGuard.IsUint8Array(right) ? ExtendsResult.True :
|
|
519
520
|
ExtendsResult.False);
|
|
520
521
|
}
|
|
521
522
|
// ------------------------------------------------------------------
|
|
@@ -524,10 +525,10 @@ function TUint8Array(left, right) {
|
|
|
524
525
|
// prettier-ignore
|
|
525
526
|
function TUndefined(left, right) {
|
|
526
527
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
528
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
529
|
+
index_10.TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
530
|
+
index_10.TypeGuard.IsVoid(right) ? VoidRight(left, right) :
|
|
531
|
+
index_10.TypeGuard.IsUndefined(right) ? ExtendsResult.True :
|
|
531
532
|
ExtendsResult.False);
|
|
532
533
|
}
|
|
533
534
|
// ------------------------------------------------------------------
|
|
@@ -554,18 +555,18 @@ function TUnknownRight(left, right) {
|
|
|
554
555
|
}
|
|
555
556
|
// prettier-ignore
|
|
556
557
|
function TUnknown(left, right) {
|
|
557
|
-
return (
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
558
|
+
return (index_10.TypeGuard.IsNever(right) ? TNeverRight(left, right) :
|
|
559
|
+
index_10.TypeGuard.IsIntersect(right) ? TIntersectRight(left, right) :
|
|
560
|
+
index_10.TypeGuard.IsUnion(right) ? TUnionRight(left, right) :
|
|
561
|
+
index_10.TypeGuard.IsAny(right) ? TAnyRight(left, right) :
|
|
562
|
+
index_10.TypeGuard.IsString(right) ? TStringRight(left, right) :
|
|
563
|
+
index_10.TypeGuard.IsNumber(right) ? TNumberRight(left, right) :
|
|
564
|
+
index_10.TypeGuard.IsInteger(right) ? TIntegerRight(left, right) :
|
|
565
|
+
index_10.TypeGuard.IsBoolean(right) ? TBooleanRight(left, right) :
|
|
566
|
+
index_10.TypeGuard.IsArray(right) ? TArrayRight(left, right) :
|
|
567
|
+
index_10.TypeGuard.IsTuple(right) ? TTupleRight(left, right) :
|
|
568
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
569
|
+
index_10.TypeGuard.IsUnknown(right) ? ExtendsResult.True :
|
|
569
570
|
ExtendsResult.False);
|
|
570
571
|
}
|
|
571
572
|
// ------------------------------------------------------------------
|
|
@@ -573,53 +574,53 @@ function TUnknown(left, right) {
|
|
|
573
574
|
// ------------------------------------------------------------------
|
|
574
575
|
// prettier-ignore
|
|
575
576
|
function VoidRight(left, right) {
|
|
576
|
-
return (
|
|
577
|
-
|
|
577
|
+
return (index_10.TypeGuard.IsUndefined(left) ? ExtendsResult.True :
|
|
578
|
+
index_10.TypeGuard.IsUndefined(left) ? ExtendsResult.True :
|
|
578
579
|
ExtendsResult.False);
|
|
579
580
|
}
|
|
580
581
|
// prettier-ignore
|
|
581
582
|
function TVoid(left, right) {
|
|
582
|
-
return (
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
583
|
+
return (index_10.TypeGuard.IsIntersect(right) ? TIntersectRight(left, right) :
|
|
584
|
+
index_10.TypeGuard.IsUnion(right) ? TUnionRight(left, right) :
|
|
585
|
+
index_10.TypeGuard.IsUnknown(right) ? TUnknownRight(left, right) :
|
|
586
|
+
index_10.TypeGuard.IsAny(right) ? TAnyRight(left, right) :
|
|
587
|
+
index_10.TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
588
|
+
index_10.TypeGuard.IsVoid(right) ? ExtendsResult.True :
|
|
588
589
|
ExtendsResult.False);
|
|
589
590
|
}
|
|
590
591
|
// prettier-ignore
|
|
591
592
|
function Visit(left, right) {
|
|
592
593
|
return (
|
|
593
594
|
// resolvable
|
|
594
|
-
(
|
|
595
|
-
(
|
|
595
|
+
(index_10.TypeGuard.IsTemplateLiteral(left) || index_10.TypeGuard.IsTemplateLiteral(right)) ? TTemplateLiteral(left, right) :
|
|
596
|
+
(index_10.TypeGuard.IsNot(left) || index_10.TypeGuard.IsNot(right)) ? TNot(left, right) :
|
|
596
597
|
// standard
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
598
|
+
index_10.TypeGuard.IsAny(left) ? TAny(left, right) :
|
|
599
|
+
index_10.TypeGuard.IsArray(left) ? TArray(left, right) :
|
|
600
|
+
index_10.TypeGuard.IsBigInt(left) ? TBigInt(left, right) :
|
|
601
|
+
index_10.TypeGuard.IsBoolean(left) ? TBoolean(left, right) :
|
|
602
|
+
index_10.TypeGuard.IsAsyncIterator(left) ? TAsyncIterator(left, right) :
|
|
603
|
+
index_10.TypeGuard.IsConstructor(left) ? TConstructor(left, right) :
|
|
604
|
+
index_10.TypeGuard.IsDate(left) ? TDate(left, right) :
|
|
605
|
+
index_10.TypeGuard.IsFunction(left) ? TFunction(left, right) :
|
|
606
|
+
index_10.TypeGuard.IsInteger(left) ? TInteger(left, right) :
|
|
607
|
+
index_10.TypeGuard.IsIntersect(left) ? TIntersect(left, right) :
|
|
608
|
+
index_10.TypeGuard.IsIterator(left) ? TIterator(left, right) :
|
|
609
|
+
index_10.TypeGuard.IsLiteral(left) ? TLiteral(left, right) :
|
|
610
|
+
index_10.TypeGuard.IsNever(left) ? TNever(left, right) :
|
|
611
|
+
index_10.TypeGuard.IsNull(left) ? TNull(left, right) :
|
|
612
|
+
index_10.TypeGuard.IsNumber(left) ? TNumber(left, right) :
|
|
613
|
+
index_10.TypeGuard.IsObject(left) ? TObject(left, right) :
|
|
614
|
+
index_10.TypeGuard.IsRecord(left) ? TRecord(left, right) :
|
|
615
|
+
index_10.TypeGuard.IsString(left) ? TString(left, right) :
|
|
616
|
+
index_10.TypeGuard.IsSymbol(left) ? TSymbol(left, right) :
|
|
617
|
+
index_10.TypeGuard.IsTuple(left) ? TTuple(left, right) :
|
|
618
|
+
index_10.TypeGuard.IsPromise(left) ? TPromise(left, right) :
|
|
619
|
+
index_10.TypeGuard.IsUint8Array(left) ? TUint8Array(left, right) :
|
|
620
|
+
index_10.TypeGuard.IsUndefined(left) ? TUndefined(left, right) :
|
|
621
|
+
index_10.TypeGuard.IsUnion(left) ? TUnion(left, right) :
|
|
622
|
+
index_10.TypeGuard.IsUnknown(left) ? TUnknown(left, right) :
|
|
623
|
+
index_10.TypeGuard.IsVoid(left) ? TVoid(left, right) :
|
|
623
624
|
Throw(`Unknown left type operand '${left[index_8.Kind]}'`));
|
|
624
625
|
}
|
|
625
626
|
function ExtendsCheck(left, right) {
|