@sinclair/typebox 0.32.0-dev-27 → 0.32.0
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.mjs +7 -0
- package/build/import/errors/errors.d.mts +16 -15
- package/build/import/errors/errors.mjs +24 -15
- package/build/import/errors/function.mjs +2 -0
- package/build/import/type/clone/value.mjs +6 -2
- package/build/import/type/extends/extends-check.mjs +137 -125
- package/build/import/type/guard/type.d.mts +3 -0
- package/build/import/type/guard/type.mjs +10 -0
- package/build/import/type/guard/value.d.mts +2 -0
- package/build/import/type/guard/value.mjs +4 -0
- package/build/import/type/indexed/indexed-property-keys.d.mts +1 -1
- package/build/import/type/record/record.d.mts +3 -1
- package/build/import/type/record/record.mjs +10 -5
- package/build/import/type/regexp/regexp.d.mts +11 -4
- package/build/import/type/regexp/regexp.mjs +3 -3
- package/build/import/type/schema/anyschema.d.mts +2 -1
- package/build/import/type/type/javascript.d.mts +2 -2
- package/build/import/type/type/javascript.mjs +1 -1
- package/build/import/value/cast/cast.d.mts +2 -15
- package/build/import/value/cast/cast.mjs +5 -28
- package/build/import/value/check/check.mjs +6 -1
- package/build/import/value/convert/convert.d.mts +0 -5
- package/build/import/value/convert/convert.mjs +0 -12
- package/build/import/value/create/create.d.mts +2 -23
- package/build/import/value/create/create.mjs +30 -53
- package/build/import/value/default/default.mjs +0 -2
- package/build/import/value/delta/delta.d.mts +4 -4
- package/build/import/value/delta/delta.mjs +12 -12
- package/build/import/value/index.d.mts +7 -7
- package/build/import/value/index.mjs +6 -6
- package/build/import/value/mutate/mutate.d.mts +2 -5
- package/build/import/value/mutate/mutate.mjs +5 -10
- package/build/require/compiler/compiler.js +7 -0
- package/build/require/errors/errors.d.ts +16 -15
- package/build/require/errors/errors.js +24 -15
- package/build/require/errors/function.js +2 -0
- package/build/require/type/clone/value.js +6 -2
- package/build/require/type/extends/extends-check.js +137 -125
- package/build/require/type/guard/type.d.ts +3 -0
- package/build/require/type/guard/type.js +12 -1
- package/build/require/type/guard/value.d.ts +2 -0
- package/build/require/type/guard/value.js +6 -1
- package/build/require/type/indexed/indexed-property-keys.d.ts +1 -1
- package/build/require/type/record/record.d.ts +3 -1
- package/build/require/type/record/record.js +9 -4
- package/build/require/type/regexp/regexp.d.ts +11 -4
- package/build/require/type/regexp/regexp.js +3 -3
- package/build/require/type/schema/anyschema.d.ts +2 -1
- package/build/require/type/type/javascript.d.ts +2 -2
- package/build/require/type/type/javascript.js +1 -1
- package/build/require/value/cast/cast.d.ts +2 -15
- package/build/require/value/cast/cast.js +7 -29
- package/build/require/value/check/check.js +6 -1
- package/build/require/value/convert/convert.d.ts +0 -5
- package/build/require/value/convert/convert.js +31 -43
- package/build/require/value/create/create.d.ts +2 -23
- package/build/require/value/create/create.js +32 -54
- package/build/require/value/default/default.js +0 -2
- package/build/require/value/delta/delta.d.ts +4 -4
- package/build/require/value/delta/delta.js +14 -14
- package/build/require/value/index.d.ts +7 -7
- package/build/require/value/index.js +8 -19
- package/build/require/value/mutate/mutate.d.ts +2 -5
- package/build/require/value/mutate/mutate.js +7 -13
- package/package.json +1 -1
- package/readme.md +43 -36
|
@@ -43,23 +43,23 @@ function IsStructuralRight(right) {
|
|
|
43
43
|
}
|
|
44
44
|
// prettier-ignore
|
|
45
45
|
function StructuralRight(left, right) {
|
|
46
|
-
return (TypeGuard.IsNever(right) ?
|
|
47
|
-
TypeGuard.IsIntersect(right) ?
|
|
48
|
-
TypeGuard.IsUnion(right) ?
|
|
49
|
-
TypeGuard.IsUnknown(right) ?
|
|
50
|
-
TypeGuard.IsAny(right) ?
|
|
46
|
+
return (TypeGuard.IsNever(right) ? FromNeverRight(left, right) :
|
|
47
|
+
TypeGuard.IsIntersect(right) ? FromIntersectRight(left, right) :
|
|
48
|
+
TypeGuard.IsUnion(right) ? FromUnionRight(left, right) :
|
|
49
|
+
TypeGuard.IsUnknown(right) ? FromUnknownRight(left, right) :
|
|
50
|
+
TypeGuard.IsAny(right) ? FromAnyRight(left, right) :
|
|
51
51
|
Throw('StructuralRight'));
|
|
52
52
|
}
|
|
53
53
|
// ------------------------------------------------------------------
|
|
54
54
|
// Any
|
|
55
55
|
// ------------------------------------------------------------------
|
|
56
56
|
// prettier-ignore
|
|
57
|
-
function
|
|
57
|
+
function FromAnyRight(left, right) {
|
|
58
58
|
return ExtendsResult.True;
|
|
59
59
|
}
|
|
60
60
|
// prettier-ignore
|
|
61
|
-
function
|
|
62
|
-
return (TypeGuard.IsIntersect(right) ?
|
|
61
|
+
function FromAny(left, right) {
|
|
62
|
+
return (TypeGuard.IsIntersect(right) ? FromIntersectRight(left, right) :
|
|
63
63
|
(TypeGuard.IsUnion(right) && right.anyOf.some((schema) => TypeGuard.IsAny(schema) || TypeGuard.IsUnknown(schema))) ? ExtendsResult.True :
|
|
64
64
|
TypeGuard.IsUnion(right) ? ExtendsResult.Union :
|
|
65
65
|
TypeGuard.IsUnknown(right) ? ExtendsResult.True :
|
|
@@ -70,14 +70,14 @@ function TAny(left, right) {
|
|
|
70
70
|
// Array
|
|
71
71
|
// ------------------------------------------------------------------
|
|
72
72
|
// prettier-ignore
|
|
73
|
-
function
|
|
73
|
+
function FromArrayRight(left, right) {
|
|
74
74
|
return (TypeGuard.IsUnknown(left) ? ExtendsResult.False :
|
|
75
75
|
TypeGuard.IsAny(left) ? ExtendsResult.Union :
|
|
76
76
|
TypeGuard.IsNever(left) ? ExtendsResult.True :
|
|
77
77
|
ExtendsResult.False);
|
|
78
78
|
}
|
|
79
79
|
// prettier-ignore
|
|
80
|
-
function
|
|
80
|
+
function FromArray(left, right) {
|
|
81
81
|
return (TypeGuard.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True :
|
|
82
82
|
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
83
83
|
!TypeGuard.IsArray(right) ? ExtendsResult.False :
|
|
@@ -87,7 +87,7 @@ function TArray(left, right) {
|
|
|
87
87
|
// AsyncIterator
|
|
88
88
|
// ------------------------------------------------------------------
|
|
89
89
|
// prettier-ignore
|
|
90
|
-
function
|
|
90
|
+
function FromAsyncIterator(left, right) {
|
|
91
91
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
92
92
|
!TypeGuard.IsAsyncIterator(right) ? ExtendsResult.False :
|
|
93
93
|
IntoBooleanResult(Visit(left.items, right.items)));
|
|
@@ -96,10 +96,10 @@ function TAsyncIterator(left, right) {
|
|
|
96
96
|
// BigInt
|
|
97
97
|
// ------------------------------------------------------------------
|
|
98
98
|
// prettier-ignore
|
|
99
|
-
function
|
|
99
|
+
function FromBigInt(left, right) {
|
|
100
100
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
101
|
-
TypeGuard.IsObject(right) ?
|
|
102
|
-
TypeGuard.IsRecord(right) ?
|
|
101
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
102
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
103
103
|
TypeGuard.IsBigInt(right) ? ExtendsResult.True :
|
|
104
104
|
ExtendsResult.False);
|
|
105
105
|
}
|
|
@@ -107,16 +107,16 @@ function TBigInt(left, right) {
|
|
|
107
107
|
// Boolean
|
|
108
108
|
// ------------------------------------------------------------------
|
|
109
109
|
// prettier-ignore
|
|
110
|
-
function
|
|
110
|
+
function FromBooleanRight(left, right) {
|
|
111
111
|
return (TypeGuard.IsLiteralBoolean(left) ? ExtendsResult.True :
|
|
112
112
|
TypeGuard.IsBoolean(left) ? ExtendsResult.True :
|
|
113
113
|
ExtendsResult.False);
|
|
114
114
|
}
|
|
115
115
|
// prettier-ignore
|
|
116
|
-
function
|
|
116
|
+
function FromBoolean(left, right) {
|
|
117
117
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
118
|
-
TypeGuard.IsObject(right) ?
|
|
119
|
-
TypeGuard.IsRecord(right) ?
|
|
118
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
119
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
120
120
|
TypeGuard.IsBoolean(right) ? ExtendsResult.True :
|
|
121
121
|
ExtendsResult.False);
|
|
122
122
|
}
|
|
@@ -124,9 +124,9 @@ function TBoolean(left, right) {
|
|
|
124
124
|
// Constructor
|
|
125
125
|
// ------------------------------------------------------------------
|
|
126
126
|
// prettier-ignore
|
|
127
|
-
function
|
|
127
|
+
function FromConstructor(left, right) {
|
|
128
128
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
129
|
-
TypeGuard.IsObject(right) ?
|
|
129
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
130
130
|
!TypeGuard.IsConstructor(right) ? ExtendsResult.False :
|
|
131
131
|
left.parameters.length > right.parameters.length ? ExtendsResult.False :
|
|
132
132
|
(!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === ExtendsResult.True)) ? ExtendsResult.False :
|
|
@@ -136,10 +136,10 @@ function TConstructor(left, right) {
|
|
|
136
136
|
// Date
|
|
137
137
|
// ------------------------------------------------------------------
|
|
138
138
|
// prettier-ignore
|
|
139
|
-
function
|
|
139
|
+
function FromDate(left, right) {
|
|
140
140
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
141
|
-
TypeGuard.IsObject(right) ?
|
|
142
|
-
TypeGuard.IsRecord(right) ?
|
|
141
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
142
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
143
143
|
TypeGuard.IsDate(right) ? ExtendsResult.True :
|
|
144
144
|
ExtendsResult.False);
|
|
145
145
|
}
|
|
@@ -147,9 +147,9 @@ function TDate(left, right) {
|
|
|
147
147
|
// Function
|
|
148
148
|
// ------------------------------------------------------------------
|
|
149
149
|
// prettier-ignore
|
|
150
|
-
function
|
|
150
|
+
function FromFunction(left, right) {
|
|
151
151
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
152
|
-
TypeGuard.IsObject(right) ?
|
|
152
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
153
153
|
!TypeGuard.IsFunction(right) ? ExtendsResult.False :
|
|
154
154
|
left.parameters.length > right.parameters.length ? ExtendsResult.False :
|
|
155
155
|
(!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === ExtendsResult.True)) ? ExtendsResult.False :
|
|
@@ -159,30 +159,30 @@ function TFunction(left, right) {
|
|
|
159
159
|
// Integer
|
|
160
160
|
// ------------------------------------------------------------------
|
|
161
161
|
// prettier-ignore
|
|
162
|
-
function
|
|
162
|
+
function FromIntegerRight(left, right) {
|
|
163
163
|
return (TypeGuard.IsLiteral(left) && ValueGuard.IsNumber(left.const) ? ExtendsResult.True :
|
|
164
164
|
TypeGuard.IsNumber(left) || TypeGuard.IsInteger(left) ? ExtendsResult.True :
|
|
165
165
|
ExtendsResult.False);
|
|
166
166
|
}
|
|
167
167
|
// prettier-ignore
|
|
168
|
-
function
|
|
168
|
+
function FromInteger(left, right) {
|
|
169
169
|
return (TypeGuard.IsInteger(right) || TypeGuard.IsNumber(right) ? ExtendsResult.True :
|
|
170
170
|
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
171
|
-
TypeGuard.IsObject(right) ?
|
|
172
|
-
TypeGuard.IsRecord(right) ?
|
|
171
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
172
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
173
173
|
ExtendsResult.False);
|
|
174
174
|
}
|
|
175
175
|
// ------------------------------------------------------------------
|
|
176
176
|
// Intersect
|
|
177
177
|
// ------------------------------------------------------------------
|
|
178
178
|
// prettier-ignore
|
|
179
|
-
function
|
|
179
|
+
function FromIntersectRight(left, right) {
|
|
180
180
|
return right.allOf.every((schema) => Visit(left, schema) === ExtendsResult.True)
|
|
181
181
|
? ExtendsResult.True
|
|
182
182
|
: ExtendsResult.False;
|
|
183
183
|
}
|
|
184
184
|
// prettier-ignore
|
|
185
|
-
function
|
|
185
|
+
function FromIntersect(left, right) {
|
|
186
186
|
return left.allOf.some((schema) => Visit(schema, right) === ExtendsResult.True)
|
|
187
187
|
? ExtendsResult.True
|
|
188
188
|
: ExtendsResult.False;
|
|
@@ -191,7 +191,7 @@ function TIntersect(left, right) {
|
|
|
191
191
|
// Iterator
|
|
192
192
|
// ------------------------------------------------------------------
|
|
193
193
|
// prettier-ignore
|
|
194
|
-
function
|
|
194
|
+
function FromIterator(left, right) {
|
|
195
195
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
196
196
|
!TypeGuard.IsIterator(right) ? ExtendsResult.False :
|
|
197
197
|
IntoBooleanResult(Visit(left.items, right.items)));
|
|
@@ -200,26 +200,26 @@ function TIterator(left, right) {
|
|
|
200
200
|
// Literal
|
|
201
201
|
// ------------------------------------------------------------------
|
|
202
202
|
// prettier-ignore
|
|
203
|
-
function
|
|
203
|
+
function FromLiteral(left, right) {
|
|
204
204
|
return (TypeGuard.IsLiteral(right) && right.const === left.const ? ExtendsResult.True :
|
|
205
205
|
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
206
|
-
TypeGuard.IsObject(right) ?
|
|
207
|
-
TypeGuard.IsRecord(right) ?
|
|
208
|
-
TypeGuard.IsString(right) ?
|
|
209
|
-
TypeGuard.IsNumber(right) ?
|
|
210
|
-
TypeGuard.IsInteger(right) ?
|
|
211
|
-
TypeGuard.IsBoolean(right) ?
|
|
206
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
207
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
208
|
+
TypeGuard.IsString(right) ? FromStringRight(left, right) :
|
|
209
|
+
TypeGuard.IsNumber(right) ? FromNumberRight(left, right) :
|
|
210
|
+
TypeGuard.IsInteger(right) ? FromIntegerRight(left, right) :
|
|
211
|
+
TypeGuard.IsBoolean(right) ? FromBooleanRight(left, right) :
|
|
212
212
|
ExtendsResult.False);
|
|
213
213
|
}
|
|
214
214
|
// ------------------------------------------------------------------
|
|
215
215
|
// Never
|
|
216
216
|
// ------------------------------------------------------------------
|
|
217
217
|
// prettier-ignore
|
|
218
|
-
function
|
|
218
|
+
function FromNeverRight(left, right) {
|
|
219
219
|
return ExtendsResult.False;
|
|
220
220
|
}
|
|
221
221
|
// prettier-ignore
|
|
222
|
-
function
|
|
222
|
+
function FromNever(left, right) {
|
|
223
223
|
return ExtendsResult.True;
|
|
224
224
|
}
|
|
225
225
|
// ------------------------------------------------------------------
|
|
@@ -237,7 +237,7 @@ function UnwrapTNot(schema) {
|
|
|
237
237
|
return depth % 2 === 0 ? current : Unknown();
|
|
238
238
|
}
|
|
239
239
|
// prettier-ignore
|
|
240
|
-
function
|
|
240
|
+
function FromNot(left, right) {
|
|
241
241
|
// TypeScript has no concept of negated types, and attempts to correctly check the negated
|
|
242
242
|
// type at runtime would put TypeBox at odds with TypeScripts ability to statically infer
|
|
243
243
|
// the type. Instead we unwrap to either unknown or T and continue evaluating.
|
|
@@ -250,10 +250,10 @@ function TNot(left, right) {
|
|
|
250
250
|
// Null
|
|
251
251
|
// ------------------------------------------------------------------
|
|
252
252
|
// prettier-ignore
|
|
253
|
-
function
|
|
253
|
+
function FromNull(left, right) {
|
|
254
254
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
255
|
-
TypeGuard.IsObject(right) ?
|
|
256
|
-
TypeGuard.IsRecord(right) ?
|
|
255
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
256
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
257
257
|
TypeGuard.IsNull(right) ? ExtendsResult.True :
|
|
258
258
|
ExtendsResult.False);
|
|
259
259
|
}
|
|
@@ -261,16 +261,16 @@ function TNull(left, right) {
|
|
|
261
261
|
// Number
|
|
262
262
|
// ------------------------------------------------------------------
|
|
263
263
|
// prettier-ignore
|
|
264
|
-
function
|
|
264
|
+
function FromNumberRight(left, right) {
|
|
265
265
|
return (TypeGuard.IsLiteralNumber(left) ? ExtendsResult.True :
|
|
266
266
|
TypeGuard.IsNumber(left) || TypeGuard.IsInteger(left) ? ExtendsResult.True :
|
|
267
267
|
ExtendsResult.False);
|
|
268
268
|
}
|
|
269
269
|
// prettier-ignore
|
|
270
|
-
function
|
|
270
|
+
function FromNumber(left, right) {
|
|
271
271
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
272
|
-
TypeGuard.IsObject(right) ?
|
|
273
|
-
TypeGuard.IsRecord(right) ?
|
|
272
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
273
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
274
274
|
TypeGuard.IsInteger(right) || TypeGuard.IsNumber(right) ? ExtendsResult.True :
|
|
275
275
|
ExtendsResult.False);
|
|
276
276
|
}
|
|
@@ -340,7 +340,7 @@ function Property(left, right) {
|
|
|
340
340
|
ExtendsResult.True);
|
|
341
341
|
}
|
|
342
342
|
// prettier-ignore
|
|
343
|
-
function
|
|
343
|
+
function FromObjectRight(left, right) {
|
|
344
344
|
return (TypeGuard.IsUnknown(left) ? ExtendsResult.False :
|
|
345
345
|
TypeGuard.IsAny(left) ? ExtendsResult.Union : (TypeGuard.IsNever(left) ||
|
|
346
346
|
(TypeGuard.IsLiteralString(left) && IsObjectStringLike(right)) ||
|
|
@@ -368,9 +368,9 @@ function TObjectRight(left, right) {
|
|
|
368
368
|
ExtendsResult.False);
|
|
369
369
|
}
|
|
370
370
|
// prettier-ignore
|
|
371
|
-
function
|
|
371
|
+
function FromObject(left, right) {
|
|
372
372
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
373
|
-
TypeGuard.IsRecord(right) ?
|
|
373
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
374
374
|
!TypeGuard.IsObject(right) ? ExtendsResult.False :
|
|
375
375
|
(() => {
|
|
376
376
|
for (const key of Object.getOwnPropertyNames(right.properties)) {
|
|
@@ -391,7 +391,7 @@ function TObject(left, right) {
|
|
|
391
391
|
// Promise
|
|
392
392
|
// ------------------------------------------------------------------
|
|
393
393
|
// prettier-ignore
|
|
394
|
-
function
|
|
394
|
+
function FromPromise(left, right) {
|
|
395
395
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
396
396
|
TypeGuard.IsObject(right) && IsObjectPromiseLike(right) ? ExtendsResult.True :
|
|
397
397
|
!TypeGuard.IsPromise(right) ? ExtendsResult.False :
|
|
@@ -413,7 +413,7 @@ function RecordValue(schema) {
|
|
|
413
413
|
Throw('Unable to get record value schema'));
|
|
414
414
|
}
|
|
415
415
|
// prettier-ignore
|
|
416
|
-
function
|
|
416
|
+
function FromRecordRight(left, right) {
|
|
417
417
|
const [Key, Value] = [RecordKey(right), RecordValue(right)];
|
|
418
418
|
return ((TypeGuard.IsLiteralString(left) && TypeGuard.IsNumber(Key) && IntoBooleanResult(Visit(left, Value)) === ExtendsResult.True) ? ExtendsResult.True :
|
|
419
419
|
TypeGuard.IsUint8Array(left) && TypeGuard.IsNumber(Key) ? Visit(left, Value) :
|
|
@@ -430,26 +430,37 @@ function TRecordRight(left, right) {
|
|
|
430
430
|
ExtendsResult.False);
|
|
431
431
|
}
|
|
432
432
|
// prettier-ignore
|
|
433
|
-
function
|
|
433
|
+
function FromRecord(left, right) {
|
|
434
434
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
435
|
-
TypeGuard.IsObject(right) ?
|
|
435
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
436
436
|
!TypeGuard.IsRecord(right) ? ExtendsResult.False :
|
|
437
437
|
Visit(RecordValue(left), RecordValue(right)));
|
|
438
438
|
}
|
|
439
439
|
// ------------------------------------------------------------------
|
|
440
|
+
// RegExp
|
|
441
|
+
// ------------------------------------------------------------------
|
|
442
|
+
// prettier-ignore
|
|
443
|
+
function FromRegExp(left, right) {
|
|
444
|
+
// Note: RegExp types evaluate as strings, not RegExp objects.
|
|
445
|
+
// Here we remap either into string and continue evaluating.
|
|
446
|
+
const L = TypeGuard.IsRegExp(left) ? String() : left;
|
|
447
|
+
const R = TypeGuard.IsRegExp(right) ? String() : right;
|
|
448
|
+
return Visit(L, R);
|
|
449
|
+
}
|
|
450
|
+
// ------------------------------------------------------------------
|
|
440
451
|
// String
|
|
441
452
|
// ------------------------------------------------------------------
|
|
442
453
|
// prettier-ignore
|
|
443
|
-
function
|
|
454
|
+
function FromStringRight(left, right) {
|
|
444
455
|
return (TypeGuard.IsLiteral(left) && ValueGuard.IsString(left.const) ? ExtendsResult.True :
|
|
445
456
|
TypeGuard.IsString(left) ? ExtendsResult.True :
|
|
446
457
|
ExtendsResult.False);
|
|
447
458
|
}
|
|
448
459
|
// prettier-ignore
|
|
449
|
-
function
|
|
460
|
+
function FromString(left, right) {
|
|
450
461
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
451
|
-
TypeGuard.IsObject(right) ?
|
|
452
|
-
TypeGuard.IsRecord(right) ?
|
|
462
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
463
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
453
464
|
TypeGuard.IsString(right) ? ExtendsResult.True :
|
|
454
465
|
ExtendsResult.False);
|
|
455
466
|
}
|
|
@@ -457,10 +468,10 @@ function TString(left, right) {
|
|
|
457
468
|
// Symbol
|
|
458
469
|
// ------------------------------------------------------------------
|
|
459
470
|
// prettier-ignore
|
|
460
|
-
function
|
|
471
|
+
function FromSymbol(left, right) {
|
|
461
472
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
462
|
-
TypeGuard.IsObject(right) ?
|
|
463
|
-
TypeGuard.IsRecord(right) ?
|
|
473
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
474
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
464
475
|
TypeGuard.IsSymbol(right) ? ExtendsResult.True :
|
|
465
476
|
ExtendsResult.False);
|
|
466
477
|
}
|
|
@@ -468,7 +479,7 @@ function TSymbol(left, right) {
|
|
|
468
479
|
// TemplateLiteral
|
|
469
480
|
// ------------------------------------------------------------------
|
|
470
481
|
// prettier-ignore
|
|
471
|
-
function
|
|
482
|
+
function FromTemplateLiteral(left, right) {
|
|
472
483
|
// TemplateLiteral types are resolved to either unions for finite expressions or string
|
|
473
484
|
// for infinite expressions. Here we call to TemplateLiteralResolver to resolve for
|
|
474
485
|
// either type and continue evaluating.
|
|
@@ -486,14 +497,14 @@ function IsArrayOfTuple(left, right) {
|
|
|
486
497
|
left.items.every((schema) => Visit(schema, right.items) === ExtendsResult.True));
|
|
487
498
|
}
|
|
488
499
|
// prettier-ignore
|
|
489
|
-
function
|
|
500
|
+
function FromTupleRight(left, right) {
|
|
490
501
|
return (TypeGuard.IsNever(left) ? ExtendsResult.True :
|
|
491
502
|
TypeGuard.IsUnknown(left) ? ExtendsResult.False :
|
|
492
503
|
TypeGuard.IsAny(left) ? ExtendsResult.Union :
|
|
493
504
|
ExtendsResult.False);
|
|
494
505
|
}
|
|
495
506
|
// prettier-ignore
|
|
496
|
-
function
|
|
507
|
+
function FromTuple(left, right) {
|
|
497
508
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
498
509
|
TypeGuard.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True :
|
|
499
510
|
TypeGuard.IsArray(right) && IsArrayOfTuple(left, right) ? ExtendsResult.True :
|
|
@@ -507,10 +518,10 @@ function TTuple(left, right) {
|
|
|
507
518
|
// Uint8Array
|
|
508
519
|
// ------------------------------------------------------------------
|
|
509
520
|
// prettier-ignore
|
|
510
|
-
function
|
|
521
|
+
function FromUint8Array(left, right) {
|
|
511
522
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
512
|
-
TypeGuard.IsObject(right) ?
|
|
513
|
-
TypeGuard.IsRecord(right) ?
|
|
523
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
524
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
514
525
|
TypeGuard.IsUint8Array(right) ? ExtendsResult.True :
|
|
515
526
|
ExtendsResult.False);
|
|
516
527
|
}
|
|
@@ -518,11 +529,11 @@ function TUint8Array(left, right) {
|
|
|
518
529
|
// Undefined
|
|
519
530
|
// ------------------------------------------------------------------
|
|
520
531
|
// prettier-ignore
|
|
521
|
-
function
|
|
532
|
+
function FromUndefined(left, right) {
|
|
522
533
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
523
|
-
TypeGuard.IsObject(right) ?
|
|
524
|
-
TypeGuard.IsRecord(right) ?
|
|
525
|
-
TypeGuard.IsVoid(right) ?
|
|
534
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
535
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
536
|
+
TypeGuard.IsVoid(right) ? FromVoidRight(left, right) :
|
|
526
537
|
TypeGuard.IsUndefined(right) ? ExtendsResult.True :
|
|
527
538
|
ExtendsResult.False);
|
|
528
539
|
}
|
|
@@ -530,13 +541,13 @@ function TUndefined(left, right) {
|
|
|
530
541
|
// Union
|
|
531
542
|
// ------------------------------------------------------------------
|
|
532
543
|
// prettier-ignore
|
|
533
|
-
function
|
|
544
|
+
function FromUnionRight(left, right) {
|
|
534
545
|
return right.anyOf.some((schema) => Visit(left, schema) === ExtendsResult.True)
|
|
535
546
|
? ExtendsResult.True
|
|
536
547
|
: ExtendsResult.False;
|
|
537
548
|
}
|
|
538
549
|
// prettier-ignore
|
|
539
|
-
function
|
|
550
|
+
function FromUnion(left, right) {
|
|
540
551
|
return left.anyOf.every((schema) => Visit(schema, right) === ExtendsResult.True)
|
|
541
552
|
? ExtendsResult.True
|
|
542
553
|
: ExtendsResult.False;
|
|
@@ -545,22 +556,22 @@ function TUnion(left, right) {
|
|
|
545
556
|
// Unknown
|
|
546
557
|
// ------------------------------------------------------------------
|
|
547
558
|
// prettier-ignore
|
|
548
|
-
function
|
|
559
|
+
function FromUnknownRight(left, right) {
|
|
549
560
|
return ExtendsResult.True;
|
|
550
561
|
}
|
|
551
562
|
// prettier-ignore
|
|
552
|
-
function
|
|
553
|
-
return (TypeGuard.IsNever(right) ?
|
|
554
|
-
TypeGuard.IsIntersect(right) ?
|
|
555
|
-
TypeGuard.IsUnion(right) ?
|
|
556
|
-
TypeGuard.IsAny(right) ?
|
|
557
|
-
TypeGuard.IsString(right) ?
|
|
558
|
-
TypeGuard.IsNumber(right) ?
|
|
559
|
-
TypeGuard.IsInteger(right) ?
|
|
560
|
-
TypeGuard.IsBoolean(right) ?
|
|
561
|
-
TypeGuard.IsArray(right) ?
|
|
562
|
-
TypeGuard.IsTuple(right) ?
|
|
563
|
-
TypeGuard.IsObject(right) ?
|
|
563
|
+
function FromUnknown(left, right) {
|
|
564
|
+
return (TypeGuard.IsNever(right) ? FromNeverRight(left, right) :
|
|
565
|
+
TypeGuard.IsIntersect(right) ? FromIntersectRight(left, right) :
|
|
566
|
+
TypeGuard.IsUnion(right) ? FromUnionRight(left, right) :
|
|
567
|
+
TypeGuard.IsAny(right) ? FromAnyRight(left, right) :
|
|
568
|
+
TypeGuard.IsString(right) ? FromStringRight(left, right) :
|
|
569
|
+
TypeGuard.IsNumber(right) ? FromNumberRight(left, right) :
|
|
570
|
+
TypeGuard.IsInteger(right) ? FromIntegerRight(left, right) :
|
|
571
|
+
TypeGuard.IsBoolean(right) ? FromBooleanRight(left, right) :
|
|
572
|
+
TypeGuard.IsArray(right) ? FromArrayRight(left, right) :
|
|
573
|
+
TypeGuard.IsTuple(right) ? FromTupleRight(left, right) :
|
|
574
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
564
575
|
TypeGuard.IsUnknown(right) ? ExtendsResult.True :
|
|
565
576
|
ExtendsResult.False);
|
|
566
577
|
}
|
|
@@ -568,18 +579,18 @@ function TUnknown(left, right) {
|
|
|
568
579
|
// Void
|
|
569
580
|
// ------------------------------------------------------------------
|
|
570
581
|
// prettier-ignore
|
|
571
|
-
function
|
|
582
|
+
function FromVoidRight(left, right) {
|
|
572
583
|
return (TypeGuard.IsUndefined(left) ? ExtendsResult.True :
|
|
573
584
|
TypeGuard.IsUndefined(left) ? ExtendsResult.True :
|
|
574
585
|
ExtendsResult.False);
|
|
575
586
|
}
|
|
576
587
|
// prettier-ignore
|
|
577
|
-
function
|
|
578
|
-
return (TypeGuard.IsIntersect(right) ?
|
|
579
|
-
TypeGuard.IsUnion(right) ?
|
|
580
|
-
TypeGuard.IsUnknown(right) ?
|
|
581
|
-
TypeGuard.IsAny(right) ?
|
|
582
|
-
TypeGuard.IsObject(right) ?
|
|
588
|
+
function FromVoid(left, right) {
|
|
589
|
+
return (TypeGuard.IsIntersect(right) ? FromIntersectRight(left, right) :
|
|
590
|
+
TypeGuard.IsUnion(right) ? FromUnionRight(left, right) :
|
|
591
|
+
TypeGuard.IsUnknown(right) ? FromUnknownRight(left, right) :
|
|
592
|
+
TypeGuard.IsAny(right) ? FromAnyRight(left, right) :
|
|
593
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
583
594
|
TypeGuard.IsVoid(right) ? ExtendsResult.True :
|
|
584
595
|
ExtendsResult.False);
|
|
585
596
|
}
|
|
@@ -587,36 +598,37 @@ function TVoid(left, right) {
|
|
|
587
598
|
function Visit(left, right) {
|
|
588
599
|
return (
|
|
589
600
|
// resolvable
|
|
590
|
-
(TypeGuard.IsTemplateLiteral(left) || TypeGuard.IsTemplateLiteral(right)) ?
|
|
591
|
-
(TypeGuard.
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
TypeGuard.
|
|
595
|
-
TypeGuard.
|
|
596
|
-
TypeGuard.
|
|
597
|
-
TypeGuard.
|
|
598
|
-
TypeGuard.
|
|
599
|
-
TypeGuard.
|
|
600
|
-
TypeGuard.
|
|
601
|
-
TypeGuard.
|
|
602
|
-
TypeGuard.
|
|
603
|
-
TypeGuard.
|
|
604
|
-
TypeGuard.
|
|
605
|
-
TypeGuard.
|
|
606
|
-
TypeGuard.
|
|
607
|
-
TypeGuard.
|
|
608
|
-
TypeGuard.
|
|
609
|
-
TypeGuard.
|
|
610
|
-
TypeGuard.
|
|
611
|
-
TypeGuard.
|
|
612
|
-
TypeGuard.
|
|
613
|
-
TypeGuard.
|
|
614
|
-
TypeGuard.
|
|
615
|
-
TypeGuard.
|
|
616
|
-
TypeGuard.
|
|
617
|
-
TypeGuard.
|
|
618
|
-
TypeGuard.
|
|
619
|
-
|
|
601
|
+
(TypeGuard.IsTemplateLiteral(left) || TypeGuard.IsTemplateLiteral(right)) ? FromTemplateLiteral(left, right) :
|
|
602
|
+
(TypeGuard.IsRegExp(left) || TypeGuard.IsRegExp(right)) ? FromRegExp(left, right) :
|
|
603
|
+
(TypeGuard.IsNot(left) || TypeGuard.IsNot(right)) ? FromNot(left, right) :
|
|
604
|
+
// standard
|
|
605
|
+
TypeGuard.IsAny(left) ? FromAny(left, right) :
|
|
606
|
+
TypeGuard.IsArray(left) ? FromArray(left, right) :
|
|
607
|
+
TypeGuard.IsBigInt(left) ? FromBigInt(left, right) :
|
|
608
|
+
TypeGuard.IsBoolean(left) ? FromBoolean(left, right) :
|
|
609
|
+
TypeGuard.IsAsyncIterator(left) ? FromAsyncIterator(left, right) :
|
|
610
|
+
TypeGuard.IsConstructor(left) ? FromConstructor(left, right) :
|
|
611
|
+
TypeGuard.IsDate(left) ? FromDate(left, right) :
|
|
612
|
+
TypeGuard.IsFunction(left) ? FromFunction(left, right) :
|
|
613
|
+
TypeGuard.IsInteger(left) ? FromInteger(left, right) :
|
|
614
|
+
TypeGuard.IsIntersect(left) ? FromIntersect(left, right) :
|
|
615
|
+
TypeGuard.IsIterator(left) ? FromIterator(left, right) :
|
|
616
|
+
TypeGuard.IsLiteral(left) ? FromLiteral(left, right) :
|
|
617
|
+
TypeGuard.IsNever(left) ? FromNever(left, right) :
|
|
618
|
+
TypeGuard.IsNull(left) ? FromNull(left, right) :
|
|
619
|
+
TypeGuard.IsNumber(left) ? FromNumber(left, right) :
|
|
620
|
+
TypeGuard.IsObject(left) ? FromObject(left, right) :
|
|
621
|
+
TypeGuard.IsRecord(left) ? FromRecord(left, right) :
|
|
622
|
+
TypeGuard.IsString(left) ? FromString(left, right) :
|
|
623
|
+
TypeGuard.IsSymbol(left) ? FromSymbol(left, right) :
|
|
624
|
+
TypeGuard.IsTuple(left) ? FromTuple(left, right) :
|
|
625
|
+
TypeGuard.IsPromise(left) ? FromPromise(left, right) :
|
|
626
|
+
TypeGuard.IsUint8Array(left) ? FromUint8Array(left, right) :
|
|
627
|
+
TypeGuard.IsUndefined(left) ? FromUndefined(left, right) :
|
|
628
|
+
TypeGuard.IsUnion(left) ? FromUnion(left, right) :
|
|
629
|
+
TypeGuard.IsUnknown(left) ? FromUnknown(left, right) :
|
|
630
|
+
TypeGuard.IsVoid(left) ? FromVoid(left, right) :
|
|
631
|
+
Throw(`Unknown left type operand '${left[Kind]}'`));
|
|
620
632
|
}
|
|
621
633
|
export function ExtendsCheck(left, right) {
|
|
622
634
|
return Visit(left, right);
|
|
@@ -26,6 +26,7 @@ import type { TOptional } from '../optional/index.mjs';
|
|
|
26
26
|
import type { TPromise } from '../promise/index.mjs';
|
|
27
27
|
import type { TReadonly } from '../readonly/index.mjs';
|
|
28
28
|
import type { TRef } from '../ref/index.mjs';
|
|
29
|
+
import type { TRegExp } from '../regexp/index.mjs';
|
|
29
30
|
import type { TSchema } from '../schema/index.mjs';
|
|
30
31
|
import type { TSymbol } from '../symbol/index.mjs';
|
|
31
32
|
import type { TTuple } from '../tuple/index.mjs';
|
|
@@ -104,6 +105,8 @@ export declare function IsRecursive(value: unknown): value is {
|
|
|
104
105
|
};
|
|
105
106
|
/** Returns true if the given value is TRef */
|
|
106
107
|
export declare function IsRef(value: unknown): value is TRef;
|
|
108
|
+
/** Returns true if the given value is TRegExp */
|
|
109
|
+
export declare function IsRegExp(value: unknown): value is TRegExp;
|
|
107
110
|
/** Returns true if the given value is TString */
|
|
108
111
|
export declare function IsString(value: unknown): value is TString;
|
|
109
112
|
/** Returns true if the given value is TSymbol */
|
|
@@ -26,6 +26,7 @@ const KnownTypes = [
|
|
|
26
26
|
'Promise',
|
|
27
27
|
'Record',
|
|
28
28
|
'Ref',
|
|
29
|
+
'RegExp',
|
|
29
30
|
'String',
|
|
30
31
|
'Symbol',
|
|
31
32
|
'TemplateLiteral',
|
|
@@ -324,6 +325,14 @@ export function IsRef(value) {
|
|
|
324
325
|
IsOptionalString(value.$id) &&
|
|
325
326
|
ValueGuard.IsString(value.$ref));
|
|
326
327
|
}
|
|
328
|
+
/** Returns true if the given value is TRegExp */
|
|
329
|
+
export function IsRegExp(value) {
|
|
330
|
+
// prettier-ignore
|
|
331
|
+
return (IsKindOf(value, 'RegExp') &&
|
|
332
|
+
IsOptionalString(value.$id) &&
|
|
333
|
+
ValueGuard.IsString(value.source) &&
|
|
334
|
+
ValueGuard.IsString(value.flags));
|
|
335
|
+
}
|
|
327
336
|
/** Returns true if the given value is TString */
|
|
328
337
|
export function IsString(value) {
|
|
329
338
|
// prettier-ignore
|
|
@@ -452,6 +461,7 @@ export function IsSchema(value) {
|
|
|
452
461
|
IsPromise(value) ||
|
|
453
462
|
IsRecord(value) ||
|
|
454
463
|
IsRef(value) ||
|
|
464
|
+
IsRegExp(value) ||
|
|
455
465
|
IsString(value) ||
|
|
456
466
|
IsSymbol(value) ||
|
|
457
467
|
IsTemplateLiteral(value) ||
|
|
@@ -18,6 +18,8 @@ export declare function IsNull(value: unknown): value is null;
|
|
|
18
18
|
export declare function IsNumber(value: unknown): value is number;
|
|
19
19
|
/** Returns true if this value is an object */
|
|
20
20
|
export declare function IsObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
21
|
+
/** Returns true if this value is RegExp */
|
|
22
|
+
export declare function IsRegExp(value: unknown): value is RegExp;
|
|
21
23
|
/** Returns true if this value is string */
|
|
22
24
|
export declare function IsString(value: unknown): value is string;
|
|
23
25
|
/** Returns true if this value is symbol */
|
|
@@ -38,6 +38,10 @@ export function IsNumber(value) {
|
|
|
38
38
|
export function IsObject(value) {
|
|
39
39
|
return typeof value === 'object' && value !== null;
|
|
40
40
|
}
|
|
41
|
+
/** Returns true if this value is RegExp */
|
|
42
|
+
export function IsRegExp(value) {
|
|
43
|
+
return value instanceof globalThis.RegExp;
|
|
44
|
+
}
|
|
41
45
|
/** Returns true if this value is string */
|
|
42
46
|
export function IsString(value) {
|
|
43
47
|
return typeof value === 'string';
|
|
@@ -5,7 +5,7 @@ import type { TNumber } from '../number/index.mjs';
|
|
|
5
5
|
import type { TSchema } from '../schema/index.mjs';
|
|
6
6
|
import type { TUnion } from '../union/index.mjs';
|
|
7
7
|
type TFromTemplateLiteral<T extends TTemplateLiteral, R extends string[] = TTemplateLiteralGenerate<T>> = (R);
|
|
8
|
-
type TFromUnion<T extends TSchema[], Acc extends string[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, [...TIndexPropertyKeys<L
|
|
8
|
+
type TFromUnion<T extends TSchema[], Acc extends string[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, [...Acc, ...TIndexPropertyKeys<L>]> : Acc);
|
|
9
9
|
type TFromLiteral<T extends TLiteralValue> = (T extends PropertyKey ? [`${T}`] : []);
|
|
10
10
|
export type TIndexPropertyKeys<T extends TSchema> = (T extends TTemplateLiteral ? TFromTemplateLiteral<T> : T extends TUnion<infer S> ? TFromUnion<S> : T extends TLiteral<infer S> ? TFromLiteral<S> : T extends TNumber ? ['[number]'] : T extends TInteger ? ['[number]'] : [
|
|
11
11
|
]);
|