@sinclair/typebox 0.30.4 → 0.31.0-dev-1
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/compiler/compiler.d.ts +22 -14
- package/compiler/compiler.js +133 -106
- package/compiler/index.d.ts +1 -1
- package/compiler/index.js +2 -1
- package/errors/errors.d.ts +56 -61
- package/errors/errors.js +222 -279
- package/package.json +5 -3
- package/readme.md +588 -507
- package/system/system.d.ts +34 -8
- package/system/system.js +214 -11
- package/typebox.d.ts +180 -106
- package/typebox.js +794 -907
- package/value/cast.d.ts +6 -12
- package/value/cast.js +81 -163
- package/value/check.d.ts +1 -5
- package/value/check.js +59 -103
- package/value/clone.js +6 -29
- package/value/convert.d.ts +2 -5
- package/value/convert.js +55 -106
- package/value/create.d.ts +6 -10
- package/value/create.js +54 -68
- package/value/delta.js +22 -22
- package/value/deref.d.ts +7 -0
- package/value/deref.js +46 -0
- package/value/equal.js +10 -10
- package/value/guard.js +1 -1
- package/value/hash.js +14 -14
- package/value/mutate.js +17 -17
- package/value/pointer.js +2 -2
- package/value/transform.d.ts +42 -0
- package/value/transform.js +512 -0
- package/value/value.d.ts +8 -0
- package/value/value.js +18 -0
package/typebox.js
CHANGED
|
@@ -27,10 +27,11 @@ THE SOFTWARE.
|
|
|
27
27
|
|
|
28
28
|
---------------------------------------------------------------------------*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.Type = exports.
|
|
30
|
+
exports.Type = exports.JsonType = exports.JavaScriptTypeBuilder = exports.JsonTypeBuilder = exports.TypeBuilder = exports.TypeBuilderError = exports.TransformEncodeBuilder = exports.TransformDecodeBuilder = exports.TemplateLiteralDslParser = exports.TemplateLiteralGenerator = exports.TemplateLiteralGeneratorError = exports.TemplateLiteralFinite = exports.TemplateLiteralFiniteError = exports.TemplateLiteralParser = exports.TemplateLiteralParserError = exports.TemplateLiteralResolver = exports.TemplateLiteralPattern = exports.TemplateLiteralPatternError = exports.UnionResolver = exports.KeyArrayResolver = exports.KeyArrayResolverError = exports.KeyResolver = exports.ObjectMap = exports.Intrinsic = exports.IndexedAccessor = exports.TypeClone = exports.TypeExtends = exports.TypeExtendsResult = exports.TypeExtendsError = exports.ExtendsUndefined = exports.TypeGuard = exports.TypeGuardUnknownTypeError = exports.ValueGuard = exports.FormatRegistry = exports.TypeBoxError = exports.TypeRegistry = exports.PatternStringExact = exports.PatternNumberExact = exports.PatternBooleanExact = exports.PatternString = exports.PatternNumber = exports.PatternBoolean = exports.Kind = exports.Hint = exports.Optional = exports.Readonly = exports.Transform = void 0;
|
|
31
31
|
// --------------------------------------------------------------------------
|
|
32
32
|
// Symbols
|
|
33
33
|
// --------------------------------------------------------------------------
|
|
34
|
+
exports.Transform = Symbol.for('TypeBox.Transform');
|
|
34
35
|
exports.Readonly = Symbol.for('TypeBox.Readonly');
|
|
35
36
|
exports.Optional = Symbol.for('TypeBox.Optional');
|
|
36
37
|
exports.Hint = Symbol.for('TypeBox.Hint');
|
|
@@ -79,6 +80,15 @@ var TypeRegistry;
|
|
|
79
80
|
}
|
|
80
81
|
TypeRegistry.Get = Get;
|
|
81
82
|
})(TypeRegistry || (exports.TypeRegistry = TypeRegistry = {}));
|
|
83
|
+
// --------------------------------------------------------------------------
|
|
84
|
+
// TypeBoxError
|
|
85
|
+
// --------------------------------------------------------------------------
|
|
86
|
+
class TypeBoxError extends Error {
|
|
87
|
+
constructor(message) {
|
|
88
|
+
super(message);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.TypeBoxError = TypeBoxError;
|
|
82
92
|
/** A registry for user defined string formats */
|
|
83
93
|
var FormatRegistry;
|
|
84
94
|
(function (FormatRegistry) {
|
|
@@ -117,49 +127,54 @@ var FormatRegistry;
|
|
|
117
127
|
// --------------------------------------------------------------------------
|
|
118
128
|
// ValueGuard
|
|
119
129
|
// --------------------------------------------------------------------------
|
|
130
|
+
/** Provides functions to type guard raw JavaScript values */
|
|
120
131
|
var ValueGuard;
|
|
121
132
|
(function (ValueGuard) {
|
|
122
|
-
|
|
123
|
-
return typeof value === 'object' && value !== null;
|
|
124
|
-
}
|
|
125
|
-
ValueGuard.IsObject = IsObject;
|
|
133
|
+
/** Returns true if this value is an array */
|
|
126
134
|
function IsArray(value) {
|
|
127
135
|
return Array.isArray(value);
|
|
128
136
|
}
|
|
129
137
|
ValueGuard.IsArray = IsArray;
|
|
138
|
+
/** Returns true if this value is bigint */
|
|
139
|
+
function IsBigInt(value) {
|
|
140
|
+
return typeof value === 'bigint';
|
|
141
|
+
}
|
|
142
|
+
ValueGuard.IsBigInt = IsBigInt;
|
|
143
|
+
/** Returns true if this value is a boolean */
|
|
130
144
|
function IsBoolean(value) {
|
|
131
145
|
return typeof value === 'boolean';
|
|
132
146
|
}
|
|
133
147
|
ValueGuard.IsBoolean = IsBoolean;
|
|
148
|
+
/** Returns true if this value is null */
|
|
134
149
|
function IsNull(value) {
|
|
135
150
|
return value === null;
|
|
136
151
|
}
|
|
137
152
|
ValueGuard.IsNull = IsNull;
|
|
138
|
-
|
|
139
|
-
return value === undefined;
|
|
140
|
-
}
|
|
141
|
-
ValueGuard.IsUndefined = IsUndefined;
|
|
142
|
-
function IsBigInt(value) {
|
|
143
|
-
return typeof value === 'bigint';
|
|
144
|
-
}
|
|
145
|
-
ValueGuard.IsBigInt = IsBigInt;
|
|
153
|
+
/** Returns true if this value is number */
|
|
146
154
|
function IsNumber(value) {
|
|
147
155
|
return typeof value === 'number';
|
|
148
156
|
}
|
|
149
157
|
ValueGuard.IsNumber = IsNumber;
|
|
158
|
+
/** Returns true if this value is an object */
|
|
159
|
+
function IsObject(value) {
|
|
160
|
+
return typeof value === 'object' && value !== null;
|
|
161
|
+
}
|
|
162
|
+
ValueGuard.IsObject = IsObject;
|
|
163
|
+
/** Returns true if this value is string */
|
|
150
164
|
function IsString(value) {
|
|
151
165
|
return typeof value === 'string';
|
|
152
166
|
}
|
|
153
167
|
ValueGuard.IsString = IsString;
|
|
168
|
+
/** Returns true if this value is undefined */
|
|
169
|
+
function IsUndefined(value) {
|
|
170
|
+
return value === undefined;
|
|
171
|
+
}
|
|
172
|
+
ValueGuard.IsUndefined = IsUndefined;
|
|
154
173
|
})(ValueGuard || (exports.ValueGuard = ValueGuard = {}));
|
|
155
174
|
// --------------------------------------------------------------------------
|
|
156
175
|
// TypeGuard
|
|
157
176
|
// --------------------------------------------------------------------------
|
|
158
|
-
class TypeGuardUnknownTypeError extends
|
|
159
|
-
constructor(schema) {
|
|
160
|
-
super('TypeGuard: Unknown type');
|
|
161
|
-
this.schema = schema;
|
|
162
|
-
}
|
|
177
|
+
class TypeGuardUnknownTypeError extends TypeBoxError {
|
|
163
178
|
}
|
|
164
179
|
exports.TypeGuardUnknownTypeError = TypeGuardUnknownTypeError;
|
|
165
180
|
/** Provides functions to test if JavaScript values are TypeBox types */
|
|
@@ -245,11 +260,11 @@ var TypeGuard;
|
|
|
245
260
|
return (TKindOf(schema, 'BigInt') &&
|
|
246
261
|
schema.type === 'bigint' &&
|
|
247
262
|
IsOptionalString(schema.$id) &&
|
|
248
|
-
IsOptionalBigInt(schema.
|
|
249
|
-
IsOptionalBigInt(schema.minimum) &&
|
|
250
|
-
IsOptionalBigInt(schema.maximum) &&
|
|
263
|
+
IsOptionalBigInt(schema.exclusiveMaximum) &&
|
|
251
264
|
IsOptionalBigInt(schema.exclusiveMinimum) &&
|
|
252
|
-
IsOptionalBigInt(schema.
|
|
265
|
+
IsOptionalBigInt(schema.maximum) &&
|
|
266
|
+
IsOptionalBigInt(schema.minimum) &&
|
|
267
|
+
IsOptionalBigInt(schema.multipleOf));
|
|
253
268
|
}
|
|
254
269
|
TypeGuard.TBigInt = TBigInt;
|
|
255
270
|
/** Returns true if the given schema is TBoolean */
|
|
@@ -263,18 +278,12 @@ var TypeGuard;
|
|
|
263
278
|
/** Returns true if the given schema is TConstructor */
|
|
264
279
|
function TConstructor(schema) {
|
|
265
280
|
// prettier-ignore
|
|
266
|
-
|
|
281
|
+
return (TKindOf(schema, 'Constructor') &&
|
|
267
282
|
schema.type === 'constructor' &&
|
|
268
283
|
IsOptionalString(schema.$id) &&
|
|
269
284
|
ValueGuard.IsArray(schema.parameters) &&
|
|
270
|
-
TSchema(schema
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
for (const parameter of schema.parameters) {
|
|
274
|
-
if (!TSchema(parameter))
|
|
275
|
-
return false;
|
|
276
|
-
}
|
|
277
|
-
return true;
|
|
285
|
+
schema.parameters.every(schema => TSchema(schema)) &&
|
|
286
|
+
TSchema(schema.returns));
|
|
278
287
|
}
|
|
279
288
|
TypeGuard.TConstructor = TConstructor;
|
|
280
289
|
/** Returns true if the given schema is TDate */
|
|
@@ -282,27 +291,22 @@ var TypeGuard;
|
|
|
282
291
|
return (TKindOf(schema, 'Date') &&
|
|
283
292
|
schema.type === 'Date' &&
|
|
284
293
|
IsOptionalString(schema.$id) &&
|
|
285
|
-
IsOptionalNumber(schema.
|
|
286
|
-
IsOptionalNumber(schema.maximumTimestamp) &&
|
|
294
|
+
IsOptionalNumber(schema.exclusiveMaximumTimestamp) &&
|
|
287
295
|
IsOptionalNumber(schema.exclusiveMinimumTimestamp) &&
|
|
288
|
-
IsOptionalNumber(schema.
|
|
296
|
+
IsOptionalNumber(schema.maximumTimestamp) &&
|
|
297
|
+
IsOptionalNumber(schema.minimumTimestamp) &&
|
|
298
|
+
IsOptionalNumber(schema.multipleOfTimestamp));
|
|
289
299
|
}
|
|
290
300
|
TypeGuard.TDate = TDate;
|
|
291
301
|
/** Returns true if the given schema is TFunction */
|
|
292
302
|
function TFunction(schema) {
|
|
293
303
|
// prettier-ignore
|
|
294
|
-
|
|
304
|
+
return (TKindOf(schema, 'Function') &&
|
|
295
305
|
schema.type === 'function' &&
|
|
296
306
|
IsOptionalString(schema.$id) &&
|
|
297
307
|
ValueGuard.IsArray(schema.parameters) &&
|
|
298
|
-
TSchema(schema
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
for (const parameter of schema.parameters) {
|
|
302
|
-
if (!TSchema(parameter))
|
|
303
|
-
return false;
|
|
304
|
-
}
|
|
305
|
-
return true;
|
|
308
|
+
schema.parameters.every(schema => TSchema(schema)) &&
|
|
309
|
+
TSchema(schema.returns));
|
|
306
310
|
}
|
|
307
311
|
TypeGuard.TFunction = TFunction;
|
|
308
312
|
/** Returns true if the given schema is TInteger */
|
|
@@ -310,31 +314,23 @@ var TypeGuard;
|
|
|
310
314
|
return (TKindOf(schema, 'Integer') &&
|
|
311
315
|
schema.type === 'integer' &&
|
|
312
316
|
IsOptionalString(schema.$id) &&
|
|
313
|
-
IsOptionalNumber(schema.
|
|
314
|
-
IsOptionalNumber(schema.minimum) &&
|
|
315
|
-
IsOptionalNumber(schema.maximum) &&
|
|
317
|
+
IsOptionalNumber(schema.exclusiveMaximum) &&
|
|
316
318
|
IsOptionalNumber(schema.exclusiveMinimum) &&
|
|
317
|
-
IsOptionalNumber(schema.
|
|
319
|
+
IsOptionalNumber(schema.maximum) &&
|
|
320
|
+
IsOptionalNumber(schema.minimum) &&
|
|
321
|
+
IsOptionalNumber(schema.multipleOf));
|
|
318
322
|
}
|
|
319
323
|
TypeGuard.TInteger = TInteger;
|
|
320
324
|
/** Returns true if the given schema is TIntersect */
|
|
321
325
|
function TIntersect(schema) {
|
|
322
326
|
// prettier-ignore
|
|
323
|
-
|
|
327
|
+
return (TKindOf(schema, 'Intersect') &&
|
|
328
|
+
(ValueGuard.IsString(schema.type) && schema.type !== 'object' ? false : true) &&
|
|
324
329
|
ValueGuard.IsArray(schema.allOf) &&
|
|
330
|
+
schema.allOf.every(schema => TSchema(schema) && !TTransform(schema)) &&
|
|
325
331
|
IsOptionalString(schema.type) &&
|
|
326
332
|
(IsOptionalBoolean(schema.unevaluatedProperties) || IsOptionalSchema(schema.unevaluatedProperties)) &&
|
|
327
|
-
IsOptionalString(schema.$id))
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
if ('type' in schema && schema.type !== 'object') {
|
|
331
|
-
return false;
|
|
332
|
-
}
|
|
333
|
-
for (const inner of schema.allOf) {
|
|
334
|
-
if (!TSchema(inner))
|
|
335
|
-
return false;
|
|
336
|
-
}
|
|
337
|
-
return true;
|
|
333
|
+
IsOptionalString(schema.$id));
|
|
338
334
|
}
|
|
339
335
|
TypeGuard.TIntersect = TIntersect;
|
|
340
336
|
/** Returns true if the given schema is TIterator */
|
|
@@ -408,31 +404,24 @@ var TypeGuard;
|
|
|
408
404
|
return (TKindOf(schema, 'Number') &&
|
|
409
405
|
schema.type === 'number' &&
|
|
410
406
|
IsOptionalString(schema.$id) &&
|
|
411
|
-
IsOptionalNumber(schema.
|
|
412
|
-
IsOptionalNumber(schema.minimum) &&
|
|
413
|
-
IsOptionalNumber(schema.maximum) &&
|
|
407
|
+
IsOptionalNumber(schema.exclusiveMaximum) &&
|
|
414
408
|
IsOptionalNumber(schema.exclusiveMinimum) &&
|
|
415
|
-
IsOptionalNumber(schema.
|
|
409
|
+
IsOptionalNumber(schema.maximum) &&
|
|
410
|
+
IsOptionalNumber(schema.minimum) &&
|
|
411
|
+
IsOptionalNumber(schema.multipleOf));
|
|
416
412
|
}
|
|
417
413
|
TypeGuard.TNumber = TNumber;
|
|
418
414
|
/** Returns true if the given schema is TObject */
|
|
419
415
|
function TObject(schema) {
|
|
420
|
-
|
|
416
|
+
// prettier-ignore
|
|
417
|
+
return (TKindOf(schema, 'Object') &&
|
|
421
418
|
schema.type === 'object' &&
|
|
422
419
|
IsOptionalString(schema.$id) &&
|
|
423
420
|
ValueGuard.IsObject(schema.properties) &&
|
|
424
421
|
IsAdditionalProperties(schema.additionalProperties) &&
|
|
425
422
|
IsOptionalNumber(schema.minProperties) &&
|
|
426
|
-
IsOptionalNumber(schema.maxProperties)
|
|
427
|
-
|
|
428
|
-
}
|
|
429
|
-
for (const [key, value] of Object.entries(schema.properties)) {
|
|
430
|
-
if (!IsControlCharacterFree(key))
|
|
431
|
-
return false;
|
|
432
|
-
if (!TSchema(value))
|
|
433
|
-
return false;
|
|
434
|
-
}
|
|
435
|
-
return true;
|
|
423
|
+
IsOptionalNumber(schema.maxProperties) &&
|
|
424
|
+
Object.entries(schema.properties).every(([key, schema]) => IsControlCharacterFree(key) && TSchema(schema)));
|
|
436
425
|
}
|
|
437
426
|
TypeGuard.TObject = TObject;
|
|
438
427
|
/** Returns true if the given schema is TPromise */
|
|
@@ -447,26 +436,25 @@ var TypeGuard;
|
|
|
447
436
|
/** Returns true if the given schema is TRecord */
|
|
448
437
|
function TRecord(schema) {
|
|
449
438
|
// prettier-ignore
|
|
450
|
-
|
|
439
|
+
return (TKindOf(schema, 'Record') &&
|
|
451
440
|
schema.type === 'object' &&
|
|
452
441
|
IsOptionalString(schema.$id) &&
|
|
453
442
|
IsAdditionalProperties(schema.additionalProperties) &&
|
|
454
|
-
ValueGuard.IsObject(schema.patternProperties)
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
return false;
|
|
463
|
-
}
|
|
464
|
-
if (!TSchema(schema.patternProperties[keys[0]])) {
|
|
465
|
-
return false;
|
|
466
|
-
}
|
|
467
|
-
return true;
|
|
443
|
+
ValueGuard.IsObject(schema.patternProperties) &&
|
|
444
|
+
((schema) => {
|
|
445
|
+
const keys = Object.getOwnPropertyNames(schema.patternProperties);
|
|
446
|
+
return (keys.length === 1 &&
|
|
447
|
+
IsPattern(keys[0]) &&
|
|
448
|
+
ValueGuard.IsObject(schema.patternProperties) &&
|
|
449
|
+
TSchema(schema.patternProperties[keys[0]]));
|
|
450
|
+
})(schema));
|
|
468
451
|
}
|
|
469
452
|
TypeGuard.TRecord = TRecord;
|
|
453
|
+
/** Returns true if this schema is TRecursive */
|
|
454
|
+
function TRecursive(schema) {
|
|
455
|
+
return ValueGuard.IsObject(schema) && exports.Hint in schema && schema[exports.Hint] === 'Recursive';
|
|
456
|
+
}
|
|
457
|
+
TypeGuard.TRecursive = TRecursive;
|
|
470
458
|
/** Returns true if the given schema is TRef */
|
|
471
459
|
function TRef(schema) {
|
|
472
460
|
// prettier-ignore
|
|
@@ -513,28 +501,25 @@ var TypeGuard;
|
|
|
513
501
|
ValueGuard.IsString(schema.$ref));
|
|
514
502
|
}
|
|
515
503
|
TypeGuard.TThis = TThis;
|
|
504
|
+
/** Returns true of this schema is TTransform */
|
|
505
|
+
function TTransform(schema) {
|
|
506
|
+
return ValueGuard.IsObject(schema) && exports.Transform in schema;
|
|
507
|
+
}
|
|
508
|
+
TypeGuard.TTransform = TTransform;
|
|
516
509
|
/** Returns true if the given schema is TTuple */
|
|
517
510
|
function TTuple(schema) {
|
|
518
511
|
// prettier-ignore
|
|
519
|
-
|
|
512
|
+
return (TKindOf(schema, 'Tuple') &&
|
|
520
513
|
schema.type === 'array' &&
|
|
521
514
|
IsOptionalString(schema.$id) &&
|
|
522
515
|
ValueGuard.IsNumber(schema.minItems) &&
|
|
523
516
|
ValueGuard.IsNumber(schema.maxItems) &&
|
|
524
|
-
schema.minItems === schema.maxItems
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
if (!ValueGuard.IsArray(schema.items)) {
|
|
531
|
-
return false;
|
|
532
|
-
}
|
|
533
|
-
for (const inner of schema.items) {
|
|
534
|
-
if (!TSchema(inner))
|
|
535
|
-
return false;
|
|
536
|
-
}
|
|
537
|
-
return true;
|
|
517
|
+
schema.minItems === schema.maxItems &&
|
|
518
|
+
(( // empty
|
|
519
|
+
ValueGuard.IsUndefined(schema.items) &&
|
|
520
|
+
ValueGuard.IsUndefined(schema.additionalItems) &&
|
|
521
|
+
schema.minItems === 0) || (ValueGuard.IsArray(schema.items) &&
|
|
522
|
+
schema.items.every(schema => TSchema(schema)))));
|
|
538
523
|
}
|
|
539
524
|
TypeGuard.TTuple = TTuple;
|
|
540
525
|
/** Returns true if the given schema is TUndefined */
|
|
@@ -553,16 +538,11 @@ var TypeGuard;
|
|
|
553
538
|
/** Returns true if the given schema is TUnion */
|
|
554
539
|
function TUnion(schema) {
|
|
555
540
|
// prettier-ignore
|
|
556
|
-
|
|
541
|
+
return (TKindOf(schema, 'Union') &&
|
|
542
|
+
IsOptionalString(schema.$id) &&
|
|
543
|
+
ValueGuard.IsObject(schema) &&
|
|
557
544
|
ValueGuard.IsArray(schema.anyOf) &&
|
|
558
|
-
|
|
559
|
-
return false;
|
|
560
|
-
}
|
|
561
|
-
for (const inner of schema.anyOf) {
|
|
562
|
-
if (!TSchema(inner))
|
|
563
|
-
return false;
|
|
564
|
-
}
|
|
565
|
-
return true;
|
|
545
|
+
schema.anyOf.every(schema => TSchema(schema)));
|
|
566
546
|
}
|
|
567
547
|
TypeGuard.TUnion = TUnion;
|
|
568
548
|
/** Returns true if the given schema is TUint8Array */
|
|
@@ -650,26 +630,24 @@ var TypeGuard;
|
|
|
650
630
|
var ExtendsUndefined;
|
|
651
631
|
(function (ExtendsUndefined) {
|
|
652
632
|
function Check(schema) {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
if (schema[exports.Kind] === 'Union') {
|
|
663
|
-
const union = schema;
|
|
664
|
-
return union.anyOf.some((schema) => Check(schema));
|
|
665
|
-
}
|
|
666
|
-
return false;
|
|
633
|
+
return schema[exports.Kind] === 'Intersect'
|
|
634
|
+
? schema.allOf.every((schema) => Check(schema))
|
|
635
|
+
: schema[exports.Kind] === 'Union'
|
|
636
|
+
? schema.anyOf.some((schema) => Check(schema))
|
|
637
|
+
: schema[exports.Kind] === 'Undefined'
|
|
638
|
+
? true
|
|
639
|
+
: schema[exports.Kind] === 'Not'
|
|
640
|
+
? !Check(schema.not)
|
|
641
|
+
: false;
|
|
667
642
|
}
|
|
668
643
|
ExtendsUndefined.Check = Check;
|
|
669
644
|
})(ExtendsUndefined || (exports.ExtendsUndefined = ExtendsUndefined = {}));
|
|
670
645
|
// --------------------------------------------------------------------------
|
|
671
646
|
// TypeExtends
|
|
672
647
|
// --------------------------------------------------------------------------
|
|
648
|
+
class TypeExtendsError extends TypeBoxError {
|
|
649
|
+
}
|
|
650
|
+
exports.TypeExtendsError = TypeExtendsError;
|
|
673
651
|
var TypeExtendsResult;
|
|
674
652
|
(function (TypeExtendsResult) {
|
|
675
653
|
TypeExtendsResult[TypeExtendsResult["Union"] = 0] = "Union";
|
|
@@ -682,7 +660,13 @@ var TypeExtends;
|
|
|
682
660
|
// IntoBooleanResult
|
|
683
661
|
// --------------------------------------------------------------------------
|
|
684
662
|
function IntoBooleanResult(result) {
|
|
685
|
-
return result === TypeExtendsResult.False ?
|
|
663
|
+
return result === TypeExtendsResult.False ? result : TypeExtendsResult.True;
|
|
664
|
+
}
|
|
665
|
+
// --------------------------------------------------------------------------
|
|
666
|
+
// Throw
|
|
667
|
+
// --------------------------------------------------------------------------
|
|
668
|
+
function Throw(message) {
|
|
669
|
+
throw new TypeExtendsError(message);
|
|
686
670
|
}
|
|
687
671
|
// --------------------------------------------------------------------------
|
|
688
672
|
// StructuralRight
|
|
@@ -696,17 +680,13 @@ var TypeExtends;
|
|
|
696
680
|
TypeGuard.TAny(right));
|
|
697
681
|
}
|
|
698
682
|
function StructuralRight(left, right) {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
return TUnknownRight(left, right);
|
|
707
|
-
if (TypeGuard.TAny(right))
|
|
708
|
-
return TAnyRight(left, right);
|
|
709
|
-
throw Error('TypeExtends: StructuralRight');
|
|
683
|
+
// prettier-ignore
|
|
684
|
+
return (TypeGuard.TNever(right) ? TNeverRight(left, right) :
|
|
685
|
+
TypeGuard.TIntersect(right) ? TIntersectRight(left, right) :
|
|
686
|
+
TypeGuard.TUnion(right) ? TUnionRight(left, right) :
|
|
687
|
+
TypeGuard.TUnknown(right) ? TUnknownRight(left, right) :
|
|
688
|
+
TypeGuard.TAny(right) ? TAnyRight(left, right) :
|
|
689
|
+
Throw('StructuralRight'));
|
|
710
690
|
}
|
|
711
691
|
// --------------------------------------------------------------------------
|
|
712
692
|
// Any
|
|
@@ -715,179 +695,155 @@ var TypeExtends;
|
|
|
715
695
|
return TypeExtendsResult.True;
|
|
716
696
|
}
|
|
717
697
|
function TAny(left, right) {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
return TypeExtendsResult.True;
|
|
726
|
-
if (TypeGuard.TAny(right))
|
|
727
|
-
return TypeExtendsResult.True;
|
|
728
|
-
return TypeExtendsResult.Union;
|
|
698
|
+
// prettier-ignore
|
|
699
|
+
return (TypeGuard.TIntersect(right) ? TIntersectRight(left, right) :
|
|
700
|
+
(TypeGuard.TUnion(right) && right.anyOf.some((schema) => TypeGuard.TAny(schema) || TypeGuard.TUnknown(schema))) ? TypeExtendsResult.True :
|
|
701
|
+
TypeGuard.TUnion(right) ? TypeExtendsResult.Union :
|
|
702
|
+
TypeGuard.TUnknown(right) ? TypeExtendsResult.True :
|
|
703
|
+
TypeGuard.TAny(right) ? TypeExtendsResult.True :
|
|
704
|
+
TypeExtendsResult.Union);
|
|
729
705
|
}
|
|
730
706
|
// --------------------------------------------------------------------------
|
|
731
707
|
// Array
|
|
732
708
|
// --------------------------------------------------------------------------
|
|
733
709
|
function TArrayRight(left, right) {
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
return TypeExtendsResult.True;
|
|
740
|
-
return TypeExtendsResult.False;
|
|
710
|
+
// prettier-ignore
|
|
711
|
+
return (TypeGuard.TUnknown(left) ? TypeExtendsResult.False :
|
|
712
|
+
TypeGuard.TAny(left) ? TypeExtendsResult.Union :
|
|
713
|
+
TypeGuard.TNever(left) ? TypeExtendsResult.True :
|
|
714
|
+
TypeExtendsResult.False);
|
|
741
715
|
}
|
|
742
716
|
function TArray(left, right) {
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
return TypeExtendsResult.False;
|
|
749
|
-
return IntoBooleanResult(Visit(left.items, right.items));
|
|
717
|
+
// prettier-ignore
|
|
718
|
+
return (TypeGuard.TObject(right) && IsObjectArrayLike(right) ? TypeExtendsResult.True :
|
|
719
|
+
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
720
|
+
!TypeGuard.TArray(right) ? TypeExtendsResult.False :
|
|
721
|
+
IntoBooleanResult(Visit(left.items, right.items)));
|
|
750
722
|
}
|
|
751
723
|
// --------------------------------------------------------------------------
|
|
752
724
|
// AsyncIterator
|
|
753
725
|
// --------------------------------------------------------------------------
|
|
754
726
|
function TAsyncIterator(left, right) {
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
return IntoBooleanResult(Visit(left.items, right.items));
|
|
727
|
+
// prettier-ignore
|
|
728
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
729
|
+
!TypeGuard.TAsyncIterator(right) ? TypeExtendsResult.False :
|
|
730
|
+
IntoBooleanResult(Visit(left.items, right.items)));
|
|
760
731
|
}
|
|
761
732
|
// --------------------------------------------------------------------------
|
|
762
733
|
// BigInt
|
|
763
734
|
// --------------------------------------------------------------------------
|
|
764
735
|
function TBigInt(left, right) {
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
return TypeGuard.TBigInt(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
736
|
+
// prettier-ignore
|
|
737
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
738
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
739
|
+
TypeGuard.TRecord(right) ? TRecordRight(left, right) :
|
|
740
|
+
TypeGuard.TBigInt(right) ? TypeExtendsResult.True :
|
|
741
|
+
TypeExtendsResult.False);
|
|
772
742
|
}
|
|
773
743
|
// --------------------------------------------------------------------------
|
|
774
744
|
// Boolean
|
|
775
745
|
// --------------------------------------------------------------------------
|
|
776
746
|
function TBooleanRight(left, right) {
|
|
777
|
-
|
|
778
|
-
return TypeExtendsResult.True;
|
|
779
|
-
return TypeGuard.TBoolean(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
747
|
+
return TypeGuard.TLiteral(left) && ValueGuard.IsBoolean(left.const) ? TypeExtendsResult.True : TypeGuard.TBoolean(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
780
748
|
}
|
|
781
749
|
function TBoolean(left, right) {
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
return TypeGuard.TBoolean(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
750
|
+
// prettier-ignore
|
|
751
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
752
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
753
|
+
TypeGuard.TRecord(right) ? TRecordRight(left, right) :
|
|
754
|
+
TypeGuard.TBoolean(right) ? TypeExtendsResult.True :
|
|
755
|
+
TypeExtendsResult.False);
|
|
789
756
|
}
|
|
790
757
|
// --------------------------------------------------------------------------
|
|
791
758
|
// Constructor
|
|
792
759
|
// --------------------------------------------------------------------------
|
|
793
760
|
function TConstructor(left, right) {
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
return TypeExtendsResult.False;
|
|
802
|
-
if (!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === TypeExtendsResult.True)) {
|
|
803
|
-
return TypeExtendsResult.False;
|
|
804
|
-
}
|
|
805
|
-
return IntoBooleanResult(Visit(left.returns, right.returns));
|
|
761
|
+
// prettier-ignore
|
|
762
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
763
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
764
|
+
!TypeGuard.TConstructor(right) ? TypeExtendsResult.False :
|
|
765
|
+
left.parameters.length > right.parameters.length ? TypeExtendsResult.False :
|
|
766
|
+
(!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === TypeExtendsResult.True)) ? TypeExtendsResult.False :
|
|
767
|
+
IntoBooleanResult(Visit(left.returns, right.returns)));
|
|
806
768
|
}
|
|
807
769
|
// --------------------------------------------------------------------------
|
|
808
770
|
// Date
|
|
809
771
|
// --------------------------------------------------------------------------
|
|
810
772
|
function TDate(left, right) {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
return TypeGuard.TDate(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
773
|
+
// prettier-ignore
|
|
774
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
775
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
776
|
+
TypeGuard.TRecord(right) ? TRecordRight(left, right) :
|
|
777
|
+
TypeGuard.TDate(right) ? TypeExtendsResult.True :
|
|
778
|
+
TypeExtendsResult.False);
|
|
818
779
|
}
|
|
819
780
|
// --------------------------------------------------------------------------
|
|
820
781
|
// Function
|
|
821
782
|
// --------------------------------------------------------------------------
|
|
822
783
|
function TFunction(left, right) {
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
return TypeExtendsResult.False;
|
|
831
|
-
if (!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === TypeExtendsResult.True)) {
|
|
832
|
-
return TypeExtendsResult.False;
|
|
833
|
-
}
|
|
834
|
-
return IntoBooleanResult(Visit(left.returns, right.returns));
|
|
784
|
+
// prettier-ignore
|
|
785
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
786
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
787
|
+
!TypeGuard.TFunction(right) ? TypeExtendsResult.False :
|
|
788
|
+
left.parameters.length > right.parameters.length ? TypeExtendsResult.False :
|
|
789
|
+
(!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === TypeExtendsResult.True)) ? TypeExtendsResult.False :
|
|
790
|
+
IntoBooleanResult(Visit(left.returns, right.returns)));
|
|
835
791
|
}
|
|
836
792
|
// --------------------------------------------------------------------------
|
|
837
793
|
// Integer
|
|
838
794
|
// --------------------------------------------------------------------------
|
|
839
795
|
function TIntegerRight(left, right) {
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
796
|
+
// prettier-ignore
|
|
797
|
+
return (TypeGuard.TLiteral(left) && ValueGuard.IsNumber(left.const) ? TypeExtendsResult.True :
|
|
798
|
+
TypeGuard.TNumber(left) || TypeGuard.TInteger(left) ? TypeExtendsResult.True :
|
|
799
|
+
TypeExtendsResult.False);
|
|
843
800
|
}
|
|
844
801
|
function TInteger(left, right) {
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
return TypeGuard.TInteger(right) || TypeGuard.TNumber(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
802
|
+
// prettier-ignore
|
|
803
|
+
return (TypeGuard.TInteger(right) || TypeGuard.TNumber(right) ? TypeExtendsResult.True :
|
|
804
|
+
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
805
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
806
|
+
TypeGuard.TRecord(right) ? TRecordRight(left, right) :
|
|
807
|
+
TypeExtendsResult.False);
|
|
852
808
|
}
|
|
853
809
|
// --------------------------------------------------------------------------
|
|
854
810
|
// Intersect
|
|
855
811
|
// --------------------------------------------------------------------------
|
|
856
812
|
function TIntersectRight(left, right) {
|
|
857
|
-
|
|
813
|
+
// prettier-ignore
|
|
814
|
+
return right.allOf.every((schema) => Visit(left, schema) === TypeExtendsResult.True)
|
|
815
|
+
? TypeExtendsResult.True
|
|
816
|
+
: TypeExtendsResult.False;
|
|
858
817
|
}
|
|
859
818
|
function TIntersect(left, right) {
|
|
860
|
-
|
|
819
|
+
// prettier-ignore
|
|
820
|
+
return left.allOf.some((schema) => Visit(schema, right) === TypeExtendsResult.True)
|
|
821
|
+
? TypeExtendsResult.True
|
|
822
|
+
: TypeExtendsResult.False;
|
|
861
823
|
}
|
|
862
824
|
// --------------------------------------------------------------------------
|
|
863
825
|
// Iterator
|
|
864
826
|
// --------------------------------------------------------------------------
|
|
865
827
|
function TIterator(left, right) {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
return IntoBooleanResult(Visit(left.items, right.items));
|
|
828
|
+
// prettier-ignore
|
|
829
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
830
|
+
!TypeGuard.TIterator(right) ? TypeExtendsResult.False :
|
|
831
|
+
IntoBooleanResult(Visit(left.items, right.items)));
|
|
871
832
|
}
|
|
872
833
|
// --------------------------------------------------------------------------
|
|
873
834
|
// Literal
|
|
874
835
|
// --------------------------------------------------------------------------
|
|
875
836
|
function TLiteral(left, right) {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
if (TypeGuard.TInteger(right))
|
|
887
|
-
return TIntegerRight(left, right);
|
|
888
|
-
if (TypeGuard.TBoolean(right))
|
|
889
|
-
return TBooleanRight(left, right);
|
|
890
|
-
return TypeGuard.TLiteral(right) && right.const === left.const ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
837
|
+
// prettier-ignore
|
|
838
|
+
return (TypeGuard.TLiteral(right) && right.const === left.const ? TypeExtendsResult.True :
|
|
839
|
+
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
840
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
841
|
+
TypeGuard.TRecord(right) ? TRecordRight(left, right) :
|
|
842
|
+
TypeGuard.TString(right) ? TStringRight(left, right) :
|
|
843
|
+
TypeGuard.TNumber(right) ? TNumberRight(left, right) :
|
|
844
|
+
TypeGuard.TInteger(right) ? TIntegerRight(left, right) :
|
|
845
|
+
TypeGuard.TBoolean(right) ? TBooleanRight(left, right) :
|
|
846
|
+
TypeExtendsResult.False);
|
|
891
847
|
}
|
|
892
848
|
// --------------------------------------------------------------------------
|
|
893
849
|
// Never
|
|
@@ -915,40 +871,38 @@ var TypeExtends;
|
|
|
915
871
|
// TypeScript has no concept of negated types, and attempts to correctly check the negated
|
|
916
872
|
// type at runtime would put TypeBox at odds with TypeScripts ability to statically infer
|
|
917
873
|
// the type. Instead we unwrap to either unknown or T and continue evaluating.
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
throw new Error(`TypeExtends: Invalid fallthrough for Not`);
|
|
874
|
+
// prettier-ignore
|
|
875
|
+
return (TypeGuard.TNot(left) ? Visit(UnwrapTNot(left), right) :
|
|
876
|
+
TypeGuard.TNot(right) ? Visit(left, UnwrapTNot(right)) :
|
|
877
|
+
Throw('Invalid fallthrough for Not'));
|
|
923
878
|
}
|
|
924
879
|
// --------------------------------------------------------------------------
|
|
925
880
|
// Null
|
|
926
881
|
// --------------------------------------------------------------------------
|
|
927
882
|
function TNull(left, right) {
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
return TypeGuard.TNull(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
883
|
+
// prettier-ignore
|
|
884
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
885
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
886
|
+
TypeGuard.TRecord(right) ? TRecordRight(left, right) :
|
|
887
|
+
TypeGuard.TNull(right) ? TypeExtendsResult.True :
|
|
888
|
+
TypeExtendsResult.False);
|
|
935
889
|
}
|
|
936
890
|
// --------------------------------------------------------------------------
|
|
937
891
|
// Number
|
|
938
892
|
// --------------------------------------------------------------------------
|
|
939
893
|
function TNumberRight(left, right) {
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
894
|
+
// prettier-ignore
|
|
895
|
+
return (TypeGuard.TLiteralNumber(left) ? TypeExtendsResult.True :
|
|
896
|
+
TypeGuard.TNumber(left) || TypeGuard.TInteger(left) ? TypeExtendsResult.True :
|
|
897
|
+
TypeExtendsResult.False);
|
|
943
898
|
}
|
|
944
899
|
function TNumber(left, right) {
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
return TypeGuard.TInteger(right) || TypeGuard.TNumber(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
900
|
+
// prettier-ignore
|
|
901
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
902
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
903
|
+
TypeGuard.TRecord(right) ? TRecordRight(left, right) :
|
|
904
|
+
TypeGuard.TInteger(right) || TypeGuard.TNumber(right) ? TypeExtendsResult.True :
|
|
905
|
+
TypeExtendsResult.False);
|
|
952
906
|
}
|
|
953
907
|
// --------------------------------------------------------------------------
|
|
954
908
|
// Object
|
|
@@ -999,161 +953,133 @@ var TypeExtends;
|
|
|
999
953
|
// Property
|
|
1000
954
|
// --------------------------------------------------------------------------
|
|
1001
955
|
function Property(left, right) {
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
return TypeExtendsResult.True;
|
|
956
|
+
// prettier-ignore
|
|
957
|
+
return (Visit(left, right) === TypeExtendsResult.False ? TypeExtendsResult.False :
|
|
958
|
+
TypeGuard.TOptional(left) && !TypeGuard.TOptional(right) ? TypeExtendsResult.False :
|
|
959
|
+
TypeExtendsResult.True);
|
|
1007
960
|
}
|
|
1008
961
|
function TObjectRight(left, right) {
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
if (TypeGuard.TDate(left) && IsObjectDateLike(right))
|
|
1038
|
-
return TypeExtendsResult.True;
|
|
1039
|
-
if (TypeGuard.TConstructor(left) && IsObjectConstructorLike(right))
|
|
1040
|
-
return TypeExtendsResult.True;
|
|
1041
|
-
if (TypeGuard.TFunction(left) && IsObjectFunctionLike(right))
|
|
1042
|
-
return TypeExtendsResult.True;
|
|
1043
|
-
if (TypeGuard.TRecord(left) && TypeGuard.TString(RecordKey(left))) {
|
|
1044
|
-
// When expressing a Record with literal key values, the Record is converted into a Object with
|
|
1045
|
-
// the Hint assigned as `Record`. This is used to invert the extends logic.
|
|
1046
|
-
return right[exports.Hint] === 'Record' ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1047
|
-
}
|
|
1048
|
-
if (TypeGuard.TRecord(left) && TypeGuard.TNumber(RecordKey(left))) {
|
|
1049
|
-
return IsObjectPropertyCount(right, 0) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1050
|
-
}
|
|
1051
|
-
return TypeExtendsResult.False;
|
|
962
|
+
// prettier-ignore
|
|
963
|
+
return (TypeGuard.TUnknown(left) ? TypeExtendsResult.False :
|
|
964
|
+
TypeGuard.TAny(left) ? TypeExtendsResult.Union : (TypeGuard.TNever(left) ||
|
|
965
|
+
(TypeGuard.TLiteralString(left) && IsObjectStringLike(right)) ||
|
|
966
|
+
(TypeGuard.TLiteralNumber(left) && IsObjectNumberLike(right)) ||
|
|
967
|
+
(TypeGuard.TLiteralBoolean(left) && IsObjectBooleanLike(right)) ||
|
|
968
|
+
(TypeGuard.TSymbol(left) && IsObjectSymbolLike(right)) ||
|
|
969
|
+
(TypeGuard.TBigInt(left) && IsObjectBigIntLike(right)) ||
|
|
970
|
+
(TypeGuard.TString(left) && IsObjectStringLike(right)) ||
|
|
971
|
+
(TypeGuard.TSymbol(left) && IsObjectSymbolLike(right)) ||
|
|
972
|
+
(TypeGuard.TNumber(left) && IsObjectNumberLike(right)) ||
|
|
973
|
+
(TypeGuard.TInteger(left) && IsObjectNumberLike(right)) ||
|
|
974
|
+
(TypeGuard.TBoolean(left) && IsObjectBooleanLike(right)) ||
|
|
975
|
+
(TypeGuard.TUint8Array(left) && IsObjectUint8ArrayLike(right)) ||
|
|
976
|
+
(TypeGuard.TDate(left) && IsObjectDateLike(right)) ||
|
|
977
|
+
(TypeGuard.TConstructor(left) && IsObjectConstructorLike(right)) ||
|
|
978
|
+
(TypeGuard.TFunction(left) && IsObjectFunctionLike(right))) ? TypeExtendsResult.True :
|
|
979
|
+
(TypeGuard.TRecord(left) && TypeGuard.TString(RecordKey(left))) ? (() => {
|
|
980
|
+
// When expressing a Record with literal key values, the Record is converted into a Object with
|
|
981
|
+
// the Hint assigned as `Record`. This is used to invert the extends logic.
|
|
982
|
+
return right[exports.Hint] === 'Record' ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
983
|
+
})() :
|
|
984
|
+
(TypeGuard.TRecord(left) && TypeGuard.TNumber(RecordKey(left))) ? (() => {
|
|
985
|
+
return IsObjectPropertyCount(right, 0)
|
|
986
|
+
? TypeExtendsResult.True
|
|
987
|
+
: TypeExtendsResult.False;
|
|
988
|
+
})() :
|
|
989
|
+
TypeExtendsResult.False);
|
|
1052
990
|
}
|
|
1053
991
|
function TObject(left, right) {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
992
|
+
// prettier-ignore
|
|
993
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
994
|
+
TypeGuard.TRecord(right) ? TRecordRight(left, right) :
|
|
995
|
+
!TypeGuard.TObject(right) ? TypeExtendsResult.False :
|
|
996
|
+
(() => {
|
|
997
|
+
for (const key of Object.getOwnPropertyNames(right.properties)) {
|
|
998
|
+
if (!(key in left.properties))
|
|
999
|
+
return TypeExtendsResult.False;
|
|
1000
|
+
if (Property(left.properties[key], right.properties[key]) === TypeExtendsResult.False) {
|
|
1001
|
+
return TypeExtendsResult.False;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
return TypeExtendsResult.True;
|
|
1005
|
+
})());
|
|
1068
1006
|
}
|
|
1069
1007
|
// --------------------------------------------------------------------------
|
|
1070
1008
|
// Promise
|
|
1071
1009
|
// --------------------------------------------------------------------------
|
|
1072
1010
|
function TPromise(left, right) {
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
return TypeExtendsResult.False;
|
|
1079
|
-
return IntoBooleanResult(Visit(left.item, right.item));
|
|
1011
|
+
// prettier-ignore
|
|
1012
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
1013
|
+
TypeGuard.TObject(right) && IsObjectPromiseLike(right) ? TypeExtendsResult.True :
|
|
1014
|
+
!TypeGuard.TPromise(right) ? TypeExtendsResult.False :
|
|
1015
|
+
IntoBooleanResult(Visit(left.item, right.item)));
|
|
1080
1016
|
}
|
|
1081
1017
|
// --------------------------------------------------------------------------
|
|
1082
1018
|
// Record
|
|
1083
1019
|
// --------------------------------------------------------------------------
|
|
1084
1020
|
function RecordKey(schema) {
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
throw Error('TypeExtends: Cannot get record key');
|
|
1021
|
+
// prettier-ignore
|
|
1022
|
+
return (exports.PatternNumberExact in schema.patternProperties ? exports.Type.Number() :
|
|
1023
|
+
exports.PatternStringExact in schema.patternProperties ? exports.Type.String() :
|
|
1024
|
+
Throw('Unknown record key pattern'));
|
|
1090
1025
|
}
|
|
1091
1026
|
function RecordValue(schema) {
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
throw Error('TypeExtends: Cannot get record value');
|
|
1027
|
+
// prettier-ignore
|
|
1028
|
+
return (exports.PatternNumberExact in schema.patternProperties ? schema.patternProperties[exports.PatternNumberExact] :
|
|
1029
|
+
exports.PatternStringExact in schema.patternProperties ? schema.patternProperties[exports.PatternStringExact] :
|
|
1030
|
+
Throw('Unable to get record value schema'));
|
|
1097
1031
|
}
|
|
1098
1032
|
function TRecordRight(left, right) {
|
|
1099
|
-
const Key = RecordKey(right);
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
}
|
|
1115
|
-
return TypeExtendsResult.True;
|
|
1116
|
-
}
|
|
1117
|
-
return TypeExtendsResult.False;
|
|
1033
|
+
const [Key, Value] = [RecordKey(right), RecordValue(right)];
|
|
1034
|
+
// prettier-ignore
|
|
1035
|
+
return ((TypeGuard.TLiteralString(left) && TypeGuard.TNumber(Key) && IntoBooleanResult(Visit(left, Value)) === TypeExtendsResult.True) ? TypeExtendsResult.True :
|
|
1036
|
+
TypeGuard.TUint8Array(left) && TypeGuard.TNumber(Key) ? Visit(left, Value) :
|
|
1037
|
+
TypeGuard.TString(left) && TypeGuard.TNumber(Key) ? Visit(left, Value) :
|
|
1038
|
+
TypeGuard.TArray(left) && TypeGuard.TNumber(Key) ? Visit(left, Value) :
|
|
1039
|
+
TypeGuard.TObject(left) ? (() => {
|
|
1040
|
+
for (const key of Object.getOwnPropertyNames(left.properties)) {
|
|
1041
|
+
if (Property(Value, left.properties[key]) === TypeExtendsResult.False) {
|
|
1042
|
+
return TypeExtendsResult.False;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
return TypeExtendsResult.True;
|
|
1046
|
+
})() :
|
|
1047
|
+
TypeExtendsResult.False);
|
|
1118
1048
|
}
|
|
1119
1049
|
function TRecord(left, right) {
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
if (!TypeGuard.TRecord(right))
|
|
1126
|
-
return TypeExtendsResult.False;
|
|
1127
|
-
return Visit(Value, RecordValue(right));
|
|
1050
|
+
// prettier-ignore
|
|
1051
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
1052
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
1053
|
+
!TypeGuard.TRecord(right) ? TypeExtendsResult.False :
|
|
1054
|
+
Visit(RecordValue(left), RecordValue(right)));
|
|
1128
1055
|
}
|
|
1129
1056
|
// --------------------------------------------------------------------------
|
|
1130
1057
|
// String
|
|
1131
1058
|
// --------------------------------------------------------------------------
|
|
1132
1059
|
function TStringRight(left, right) {
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1060
|
+
// prettier-ignore
|
|
1061
|
+
return (TypeGuard.TLiteral(left) && ValueGuard.IsString(left.const) ? TypeExtendsResult.True :
|
|
1062
|
+
TypeGuard.TString(left) ? TypeExtendsResult.True :
|
|
1063
|
+
TypeExtendsResult.False);
|
|
1136
1064
|
}
|
|
1137
1065
|
function TString(left, right) {
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
return TypeGuard.TString(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1066
|
+
// prettier-ignore
|
|
1067
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
1068
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
1069
|
+
TypeGuard.TRecord(right) ? TRecordRight(left, right) :
|
|
1070
|
+
TypeGuard.TString(right) ? TypeExtendsResult.True :
|
|
1071
|
+
TypeExtendsResult.False);
|
|
1145
1072
|
}
|
|
1146
1073
|
// --------------------------------------------------------------------------
|
|
1147
1074
|
// Symbol
|
|
1148
1075
|
// --------------------------------------------------------------------------
|
|
1149
1076
|
function TSymbol(left, right) {
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
return TypeGuard.TSymbol(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1077
|
+
// prettier-ignore
|
|
1078
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
1079
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
1080
|
+
TypeGuard.TRecord(right) ? TRecordRight(left, right) :
|
|
1081
|
+
TypeGuard.TSymbol(right) ? TypeExtendsResult.True :
|
|
1082
|
+
TypeExtendsResult.False);
|
|
1157
1083
|
}
|
|
1158
1084
|
// --------------------------------------------------------------------------
|
|
1159
1085
|
// TemplateLiteral
|
|
@@ -1162,11 +1088,10 @@ var TypeExtends;
|
|
|
1162
1088
|
// TemplateLiteral types are resolved to either unions for finite expressions or string
|
|
1163
1089
|
// for infinite expressions. Here we call to TemplateLiteralResolver to resolve for
|
|
1164
1090
|
// either type and continue evaluating.
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
throw new Error(`TypeExtends: Invalid fallthrough for TemplateLiteral`);
|
|
1091
|
+
// prettier-ignore
|
|
1092
|
+
return (TypeGuard.TTemplateLiteral(left) ? Visit(TemplateLiteralResolver.Resolve(left), right) :
|
|
1093
|
+
TypeGuard.TTemplateLiteral(right) ? Visit(left, TemplateLiteralResolver.Resolve(right)) :
|
|
1094
|
+
Throw('Invalid fallthrough for TemplateLiteral'));
|
|
1170
1095
|
}
|
|
1171
1096
|
// --------------------------------------------------------------------------
|
|
1172
1097
|
// Tuple
|
|
@@ -1178,63 +1103,60 @@ var TypeExtends;
|
|
|
1178
1103
|
left.items.every((schema) => Visit(schema, right.items) === TypeExtendsResult.True));
|
|
1179
1104
|
}
|
|
1180
1105
|
function TTupleRight(left, right) {
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
return TypeExtendsResult.Union;
|
|
1187
|
-
return TypeExtendsResult.False;
|
|
1106
|
+
// prettier-ignore
|
|
1107
|
+
return (TypeGuard.TNever(left) ? TypeExtendsResult.True :
|
|
1108
|
+
TypeGuard.TUnknown(left) ? TypeExtendsResult.False :
|
|
1109
|
+
TypeGuard.TAny(left) ? TypeExtendsResult.Union :
|
|
1110
|
+
TypeExtendsResult.False);
|
|
1188
1111
|
}
|
|
1189
1112
|
function TTuple(left, right) {
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
return TypeExtendsResult.False;
|
|
1200
|
-
if (ValueGuard.IsUndefined(left.items) && !ValueGuard.IsUndefined(right.items))
|
|
1201
|
-
return TypeExtendsResult.True;
|
|
1202
|
-
return left.items.every((schema, index) => Visit(schema, right.items[index]) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1113
|
+
// prettier-ignore
|
|
1114
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
1115
|
+
TypeGuard.TObject(right) && IsObjectArrayLike(right) ? TypeExtendsResult.True :
|
|
1116
|
+
TypeGuard.TArray(right) && IsArrayOfTuple(left, right) ? TypeExtendsResult.True :
|
|
1117
|
+
!TypeGuard.TTuple(right) ? TypeExtendsResult.False :
|
|
1118
|
+
(ValueGuard.IsUndefined(left.items) && !ValueGuard.IsUndefined(right.items)) || (!ValueGuard.IsUndefined(left.items) && ValueGuard.IsUndefined(right.items)) ? TypeExtendsResult.False :
|
|
1119
|
+
(ValueGuard.IsUndefined(left.items) && !ValueGuard.IsUndefined(right.items)) ? TypeExtendsResult.True :
|
|
1120
|
+
left.items.every((schema, index) => Visit(schema, right.items[index]) === TypeExtendsResult.True) ? TypeExtendsResult.True :
|
|
1121
|
+
TypeExtendsResult.False);
|
|
1203
1122
|
}
|
|
1204
1123
|
// --------------------------------------------------------------------------
|
|
1205
1124
|
// Uint8Array
|
|
1206
1125
|
// --------------------------------------------------------------------------
|
|
1207
1126
|
function TUint8Array(left, right) {
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
return TypeGuard.TUint8Array(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1127
|
+
// prettier-ignore
|
|
1128
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
1129
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
1130
|
+
TypeGuard.TRecord(right) ? TRecordRight(left, right) :
|
|
1131
|
+
TypeGuard.TUint8Array(right) ? TypeExtendsResult.True :
|
|
1132
|
+
TypeExtendsResult.False);
|
|
1215
1133
|
}
|
|
1216
1134
|
// --------------------------------------------------------------------------
|
|
1217
1135
|
// Undefined
|
|
1218
1136
|
// --------------------------------------------------------------------------
|
|
1219
1137
|
function TUndefined(left, right) {
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
return VoidRight(left, right);
|
|
1228
|
-
return TypeGuard.TUndefined(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1138
|
+
// prettier-ignore
|
|
1139
|
+
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
1140
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
1141
|
+
TypeGuard.TRecord(right) ? TRecordRight(left, right) :
|
|
1142
|
+
TypeGuard.TVoid(right) ? VoidRight(left, right) :
|
|
1143
|
+
TypeGuard.TUndefined(right) ? TypeExtendsResult.True :
|
|
1144
|
+
TypeExtendsResult.False);
|
|
1229
1145
|
}
|
|
1230
1146
|
// --------------------------------------------------------------------------
|
|
1231
1147
|
// Union
|
|
1232
1148
|
// --------------------------------------------------------------------------
|
|
1233
1149
|
function TUnionRight(left, right) {
|
|
1234
|
-
|
|
1150
|
+
// prettier-ignore
|
|
1151
|
+
return right.anyOf.some((schema) => Visit(left, schema) === TypeExtendsResult.True)
|
|
1152
|
+
? TypeExtendsResult.True
|
|
1153
|
+
: TypeExtendsResult.False;
|
|
1235
1154
|
}
|
|
1236
1155
|
function TUnion(left, right) {
|
|
1237
|
-
|
|
1156
|
+
// prettier-ignore
|
|
1157
|
+
return left.anyOf.every((schema) => Visit(schema, right) === TypeExtendsResult.True)
|
|
1158
|
+
? TypeExtendsResult.True
|
|
1159
|
+
: TypeExtendsResult.False;
|
|
1238
1160
|
}
|
|
1239
1161
|
// --------------------------------------------------------------------------
|
|
1240
1162
|
// Unknown
|
|
@@ -1243,111 +1165,74 @@ var TypeExtends;
|
|
|
1243
1165
|
return TypeExtendsResult.True;
|
|
1244
1166
|
}
|
|
1245
1167
|
function TUnknown(left, right) {
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
if (TypeGuard.TBoolean(right))
|
|
1261
|
-
return TBooleanRight(left, right);
|
|
1262
|
-
if (TypeGuard.TArray(right))
|
|
1263
|
-
return TArrayRight(left, right);
|
|
1264
|
-
if (TypeGuard.TTuple(right))
|
|
1265
|
-
return TTupleRight(left, right);
|
|
1266
|
-
if (TypeGuard.TObject(right))
|
|
1267
|
-
return TObjectRight(left, right);
|
|
1268
|
-
return TypeGuard.TUnknown(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1168
|
+
// prettier-ignore
|
|
1169
|
+
return (TypeGuard.TNever(right) ? TNeverRight(left, right) :
|
|
1170
|
+
TypeGuard.TIntersect(right) ? TIntersectRight(left, right) :
|
|
1171
|
+
TypeGuard.TUnion(right) ? TUnionRight(left, right) :
|
|
1172
|
+
TypeGuard.TAny(right) ? TAnyRight(left, right) :
|
|
1173
|
+
TypeGuard.TString(right) ? TStringRight(left, right) :
|
|
1174
|
+
TypeGuard.TNumber(right) ? TNumberRight(left, right) :
|
|
1175
|
+
TypeGuard.TInteger(right) ? TIntegerRight(left, right) :
|
|
1176
|
+
TypeGuard.TBoolean(right) ? TBooleanRight(left, right) :
|
|
1177
|
+
TypeGuard.TArray(right) ? TArrayRight(left, right) :
|
|
1178
|
+
TypeGuard.TTuple(right) ? TTupleRight(left, right) :
|
|
1179
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
1180
|
+
TypeGuard.TUnknown(right) ? TypeExtendsResult.True :
|
|
1181
|
+
TypeExtendsResult.False);
|
|
1269
1182
|
}
|
|
1270
1183
|
// --------------------------------------------------------------------------
|
|
1271
1184
|
// Void
|
|
1272
1185
|
// --------------------------------------------------------------------------
|
|
1273
1186
|
function VoidRight(left, right) {
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1187
|
+
// prettier-ignore
|
|
1188
|
+
return TypeGuard.TUndefined(left) ? TypeExtendsResult.True :
|
|
1189
|
+
TypeGuard.TUndefined(left) ? TypeExtendsResult.True :
|
|
1190
|
+
TypeExtendsResult.False;
|
|
1277
1191
|
}
|
|
1278
1192
|
function TVoid(left, right) {
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
if (TypeGuard.TObject(right))
|
|
1288
|
-
return TObjectRight(left, right);
|
|
1289
|
-
return TypeGuard.TVoid(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1193
|
+
// prettier-ignore
|
|
1194
|
+
return TypeGuard.TIntersect(right) ? TIntersectRight(left, right) :
|
|
1195
|
+
TypeGuard.TUnion(right) ? TUnionRight(left, right) :
|
|
1196
|
+
TypeGuard.TUnknown(right) ? TUnknownRight(left, right) :
|
|
1197
|
+
TypeGuard.TAny(right) ? TAnyRight(left, right) :
|
|
1198
|
+
TypeGuard.TObject(right) ? TObjectRight(left, right) :
|
|
1199
|
+
TypeGuard.TVoid(right) ? TypeExtendsResult.True :
|
|
1200
|
+
TypeExtendsResult.False;
|
|
1290
1201
|
}
|
|
1291
1202
|
function Visit(left, right) {
|
|
1292
|
-
//
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
return TNull(left, right);
|
|
1326
|
-
if (TypeGuard.TNumber(left))
|
|
1327
|
-
return TNumber(left, right);
|
|
1328
|
-
if (TypeGuard.TObject(left))
|
|
1329
|
-
return TObject(left, right);
|
|
1330
|
-
if (TypeGuard.TRecord(left))
|
|
1331
|
-
return TRecord(left, right);
|
|
1332
|
-
if (TypeGuard.TString(left))
|
|
1333
|
-
return TString(left, right);
|
|
1334
|
-
if (TypeGuard.TSymbol(left))
|
|
1335
|
-
return TSymbol(left, right);
|
|
1336
|
-
if (TypeGuard.TTuple(left))
|
|
1337
|
-
return TTuple(left, right);
|
|
1338
|
-
if (TypeGuard.TPromise(left))
|
|
1339
|
-
return TPromise(left, right);
|
|
1340
|
-
if (TypeGuard.TUint8Array(left))
|
|
1341
|
-
return TUint8Array(left, right);
|
|
1342
|
-
if (TypeGuard.TUndefined(left))
|
|
1343
|
-
return TUndefined(left, right);
|
|
1344
|
-
if (TypeGuard.TUnion(left))
|
|
1345
|
-
return TUnion(left, right);
|
|
1346
|
-
if (TypeGuard.TUnknown(left))
|
|
1347
|
-
return TUnknown(left, right);
|
|
1348
|
-
if (TypeGuard.TVoid(left))
|
|
1349
|
-
return TVoid(left, right);
|
|
1350
|
-
throw Error(`TypeExtends: Unknown left type operand '${left[exports.Kind]}'`);
|
|
1203
|
+
// prettier-ignore
|
|
1204
|
+
return (
|
|
1205
|
+
// resolvable
|
|
1206
|
+
(TypeGuard.TTemplateLiteral(left) || TypeGuard.TTemplateLiteral(right)) ? TTemplateLiteral(left, right) :
|
|
1207
|
+
(TypeGuard.TNot(left) || TypeGuard.TNot(right)) ? TNot(left, right) :
|
|
1208
|
+
// standard
|
|
1209
|
+
TypeGuard.TAny(left) ? TAny(left, right) :
|
|
1210
|
+
TypeGuard.TArray(left) ? TArray(left, right) :
|
|
1211
|
+
TypeGuard.TBigInt(left) ? TBigInt(left, right) :
|
|
1212
|
+
TypeGuard.TBoolean(left) ? TBoolean(left, right) :
|
|
1213
|
+
TypeGuard.TAsyncIterator(left) ? TAsyncIterator(left, right) :
|
|
1214
|
+
TypeGuard.TConstructor(left) ? TConstructor(left, right) :
|
|
1215
|
+
TypeGuard.TDate(left) ? TDate(left, right) :
|
|
1216
|
+
TypeGuard.TFunction(left) ? TFunction(left, right) :
|
|
1217
|
+
TypeGuard.TInteger(left) ? TInteger(left, right) :
|
|
1218
|
+
TypeGuard.TIntersect(left) ? TIntersect(left, right) :
|
|
1219
|
+
TypeGuard.TIterator(left) ? TIterator(left, right) :
|
|
1220
|
+
TypeGuard.TLiteral(left) ? TLiteral(left, right) :
|
|
1221
|
+
TypeGuard.TNever(left) ? TNever(left, right) :
|
|
1222
|
+
TypeGuard.TNull(left) ? TNull(left, right) :
|
|
1223
|
+
TypeGuard.TNumber(left) ? TNumber(left, right) :
|
|
1224
|
+
TypeGuard.TObject(left) ? TObject(left, right) :
|
|
1225
|
+
TypeGuard.TRecord(left) ? TRecord(left, right) :
|
|
1226
|
+
TypeGuard.TString(left) ? TString(left, right) :
|
|
1227
|
+
TypeGuard.TSymbol(left) ? TSymbol(left, right) :
|
|
1228
|
+
TypeGuard.TTuple(left) ? TTuple(left, right) :
|
|
1229
|
+
TypeGuard.TPromise(left) ? TPromise(left, right) :
|
|
1230
|
+
TypeGuard.TUint8Array(left) ? TUint8Array(left, right) :
|
|
1231
|
+
TypeGuard.TUndefined(left) ? TUndefined(left, right) :
|
|
1232
|
+
TypeGuard.TUnion(left) ? TUnion(left, right) :
|
|
1233
|
+
TypeGuard.TUnknown(left) ? TUnknown(left, right) :
|
|
1234
|
+
TypeGuard.TVoid(left) ? TVoid(left, right) :
|
|
1235
|
+
Throw(`Unknown left type operand '${left[exports.Kind]}'`));
|
|
1351
1236
|
}
|
|
1352
1237
|
function Extends(left, right) {
|
|
1353
1238
|
return Visit(left, right);
|
|
@@ -1369,17 +1254,21 @@ var TypeClone;
|
|
|
1369
1254
|
return value.map((value) => Visit(value));
|
|
1370
1255
|
}
|
|
1371
1256
|
function Visit(value) {
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1257
|
+
// prettier-ignore
|
|
1258
|
+
return ValueGuard.IsArray(value) ? ArrayType(value) :
|
|
1259
|
+
ValueGuard.IsObject(value) ? ObjectType(value) :
|
|
1260
|
+
value;
|
|
1261
|
+
}
|
|
1262
|
+
/** Clones a Rest */
|
|
1263
|
+
function Rest(schemas) {
|
|
1264
|
+
return schemas.map((schema) => Type(schema));
|
|
1265
|
+
}
|
|
1266
|
+
TypeClone.Rest = Rest;
|
|
1267
|
+
/** Clones a Type */
|
|
1268
|
+
function Type(schema, options = {}) {
|
|
1380
1269
|
return { ...Visit(schema), ...options };
|
|
1381
1270
|
}
|
|
1382
|
-
TypeClone.
|
|
1271
|
+
TypeClone.Type = Type;
|
|
1383
1272
|
})(TypeClone || (exports.TypeClone = TypeClone = {}));
|
|
1384
1273
|
// --------------------------------------------------------------------------
|
|
1385
1274
|
// IndexedAccessor
|
|
@@ -1388,7 +1277,7 @@ var IndexedAccessor;
|
|
|
1388
1277
|
(function (IndexedAccessor) {
|
|
1389
1278
|
function OptionalUnwrap(schema) {
|
|
1390
1279
|
return schema.map((schema) => {
|
|
1391
|
-
const { [exports.Optional]: _, ...clone } = TypeClone.
|
|
1280
|
+
const { [exports.Optional]: _, ...clone } = TypeClone.Type(schema);
|
|
1392
1281
|
return clone;
|
|
1393
1282
|
});
|
|
1394
1283
|
}
|
|
@@ -1399,19 +1288,16 @@ var IndexedAccessor;
|
|
|
1399
1288
|
return schema.some((schema) => TypeGuard.TOptional(schema));
|
|
1400
1289
|
}
|
|
1401
1290
|
function ResolveIntersect(schema) {
|
|
1402
|
-
|
|
1403
|
-
return optional ? exports.Type.Optional(exports.Type.Intersect(OptionalUnwrap(schema.allOf))) : schema;
|
|
1291
|
+
return IsIntersectOptional(schema.allOf) ? exports.Type.Optional(exports.Type.Intersect(OptionalUnwrap(schema.allOf))) : schema;
|
|
1404
1292
|
}
|
|
1405
1293
|
function ResolveUnion(schema) {
|
|
1406
|
-
|
|
1407
|
-
return optional ? exports.Type.Optional(exports.Type.Union(OptionalUnwrap(schema.anyOf))) : schema;
|
|
1294
|
+
return IsUnionOptional(schema.anyOf) ? exports.Type.Optional(exports.Type.Union(OptionalUnwrap(schema.anyOf))) : schema;
|
|
1408
1295
|
}
|
|
1409
1296
|
function ResolveOptional(schema) {
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
return schema;
|
|
1297
|
+
// prettier-ignore
|
|
1298
|
+
return schema[exports.Kind] === 'Intersect' ? ResolveIntersect(schema) :
|
|
1299
|
+
schema[exports.Kind] === 'Union' ? ResolveUnion(schema) :
|
|
1300
|
+
schema;
|
|
1415
1301
|
}
|
|
1416
1302
|
function TIntersect(schema, key) {
|
|
1417
1303
|
const resolved = schema.allOf.reduce((acc, schema) => {
|
|
@@ -1438,15 +1324,12 @@ var IndexedAccessor;
|
|
|
1438
1324
|
return element;
|
|
1439
1325
|
}
|
|
1440
1326
|
function Visit(schema, key) {
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
if (schema[exports.Kind] === 'Tuple')
|
|
1448
|
-
return TTuple(schema, key);
|
|
1449
|
-
return exports.Type.Never();
|
|
1327
|
+
// prettier-ignore
|
|
1328
|
+
return schema[exports.Kind] === 'Intersect' ? TIntersect(schema, key) :
|
|
1329
|
+
schema[exports.Kind] === 'Union' ? TUnion(schema, key) :
|
|
1330
|
+
schema[exports.Kind] === 'Object' ? TObject(schema, key) :
|
|
1331
|
+
schema[exports.Kind] === 'Tuple' ? TTuple(schema, key) :
|
|
1332
|
+
exports.Type.Never();
|
|
1450
1333
|
}
|
|
1451
1334
|
function Resolve(schema, keys, options = {}) {
|
|
1452
1335
|
const resolved = keys.map((key) => Visit(schema, key.toString()));
|
|
@@ -1501,13 +1384,11 @@ var Intrinsic;
|
|
|
1501
1384
|
return [Map(L, mode), ...IntrinsicRest(R, mode)];
|
|
1502
1385
|
}
|
|
1503
1386
|
function Visit(schema, mode) {
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
return exports.Type.Literal(IntrinsicLiteral(schema.const, mode));
|
|
1510
|
-
return schema;
|
|
1387
|
+
// prettier-ignore
|
|
1388
|
+
return TypeGuard.TTemplateLiteral(schema) ? IntrinsicTemplateLiteral(schema, mode) :
|
|
1389
|
+
TypeGuard.TUnion(schema) ? exports.Type.Union(IntrinsicRest(schema.anyOf, mode)) :
|
|
1390
|
+
TypeGuard.TLiteral(schema) ? exports.Type.Literal(IntrinsicLiteral(schema.const, mode)) :
|
|
1391
|
+
schema;
|
|
1511
1392
|
}
|
|
1512
1393
|
/** Applies an intrinsic string manipulation to the given type. */
|
|
1513
1394
|
function Map(schema, mode) {
|
|
@@ -1536,16 +1417,14 @@ var ObjectMap;
|
|
|
1536
1417
|
// prevent sub schema mapping as unregistered kinds will not pass TSchema checks. This is notable in the
|
|
1537
1418
|
// case of TObject where unregistered property kinds cause the TObject check to fail. As mapping is only
|
|
1538
1419
|
// used for composition, we use explicit checks instead.
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
return TObject(schema, callback);
|
|
1545
|
-
return schema;
|
|
1420
|
+
// prettier-ignore
|
|
1421
|
+
return (schema[exports.Kind] === 'Intersect' ? TIntersect(schema, callback) :
|
|
1422
|
+
schema[exports.Kind] === 'Union' ? TUnion(schema, callback) :
|
|
1423
|
+
schema[exports.Kind] === 'Object' ? TObject(schema, callback) :
|
|
1424
|
+
schema);
|
|
1546
1425
|
}
|
|
1547
1426
|
function Map(schema, callback, options) {
|
|
1548
|
-
return { ...Visit(TypeClone.
|
|
1427
|
+
return { ...Visit(TypeClone.Type(schema), callback), ...options };
|
|
1549
1428
|
}
|
|
1550
1429
|
ObjectMap.Map = Map;
|
|
1551
1430
|
})(ObjectMap || (exports.ObjectMap = ObjectMap = {}));
|
|
@@ -1568,15 +1447,12 @@ var KeyResolver;
|
|
|
1568
1447
|
return options.includePatterns ? Object.getOwnPropertyNames(schema.patternProperties) : [];
|
|
1569
1448
|
}
|
|
1570
1449
|
function Visit(schema, options) {
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
if (TypeGuard.TRecord(schema))
|
|
1578
|
-
return TRecord(schema, options);
|
|
1579
|
-
return [];
|
|
1450
|
+
// prettier-ignore
|
|
1451
|
+
return (TypeGuard.TIntersect(schema) ? TIntersect(schema, options) :
|
|
1452
|
+
TypeGuard.TUnion(schema) ? TUnion(schema, options) :
|
|
1453
|
+
TypeGuard.TObject(schema) ? TObject(schema, options) :
|
|
1454
|
+
TypeGuard.TRecord(schema) ? TRecord(schema, options) :
|
|
1455
|
+
[]);
|
|
1580
1456
|
}
|
|
1581
1457
|
/** Resolves an array of keys in this schema */
|
|
1582
1458
|
function ResolveKeys(schema, options) {
|
|
@@ -1594,23 +1470,23 @@ var KeyResolver;
|
|
|
1594
1470
|
// --------------------------------------------------------------------------
|
|
1595
1471
|
// KeyArrayResolver
|
|
1596
1472
|
// --------------------------------------------------------------------------
|
|
1473
|
+
class KeyArrayResolverError extends TypeBoxError {
|
|
1474
|
+
}
|
|
1475
|
+
exports.KeyArrayResolverError = KeyArrayResolverError;
|
|
1597
1476
|
var KeyArrayResolver;
|
|
1598
1477
|
(function (KeyArrayResolver) {
|
|
1599
1478
|
/** Resolves an array of string[] keys from the given schema or array type. */
|
|
1600
1479
|
function Resolve(schema) {
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
return [...TemplateLiteralGenerator.Generate(expression)];
|
|
1612
|
-
}
|
|
1613
|
-
return [];
|
|
1480
|
+
// prettier-ignore
|
|
1481
|
+
return Array.isArray(schema) ? schema :
|
|
1482
|
+
TypeGuard.TUnionLiteral(schema) ? schema.anyOf.map((schema) => schema.const.toString()) :
|
|
1483
|
+
TypeGuard.TLiteral(schema) ? [schema.const] :
|
|
1484
|
+
TypeGuard.TTemplateLiteral(schema) ? (() => {
|
|
1485
|
+
const expression = TemplateLiteralParser.ParseExact(schema.pattern);
|
|
1486
|
+
if (!TemplateLiteralFinite.Check(expression))
|
|
1487
|
+
throw new KeyArrayResolverError('Cannot resolve keys from infinite template expression');
|
|
1488
|
+
return [...TemplateLiteralGenerator.Generate(expression)];
|
|
1489
|
+
})() : [];
|
|
1614
1490
|
}
|
|
1615
1491
|
KeyArrayResolver.Resolve = Resolve;
|
|
1616
1492
|
})(KeyArrayResolver || (exports.KeyArrayResolver = KeyArrayResolver = {}));
|
|
@@ -1638,42 +1514,28 @@ var UnionResolver;
|
|
|
1638
1514
|
// --------------------------------------------------------------------------
|
|
1639
1515
|
// TemplateLiteralPattern
|
|
1640
1516
|
// --------------------------------------------------------------------------
|
|
1517
|
+
class TemplateLiteralPatternError extends TypeBoxError {
|
|
1518
|
+
}
|
|
1519
|
+
exports.TemplateLiteralPatternError = TemplateLiteralPatternError;
|
|
1641
1520
|
var TemplateLiteralPattern;
|
|
1642
1521
|
(function (TemplateLiteralPattern) {
|
|
1522
|
+
function Throw(message) {
|
|
1523
|
+
throw new TemplateLiteralPatternError(message);
|
|
1524
|
+
}
|
|
1643
1525
|
function Escape(value) {
|
|
1644
1526
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1645
1527
|
}
|
|
1646
1528
|
function Visit(schema, acc) {
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
return `${acc}${exports.PatternNumber}`;
|
|
1658
|
-
}
|
|
1659
|
-
else if (TypeGuard.TBigInt(schema)) {
|
|
1660
|
-
return `${acc}${exports.PatternNumber}`;
|
|
1661
|
-
}
|
|
1662
|
-
else if (TypeGuard.TString(schema)) {
|
|
1663
|
-
return `${acc}${exports.PatternString}`;
|
|
1664
|
-
}
|
|
1665
|
-
else if (TypeGuard.TLiteral(schema)) {
|
|
1666
|
-
return `${acc}${Escape(schema.const.toString())}`;
|
|
1667
|
-
}
|
|
1668
|
-
else if (TypeGuard.TBoolean(schema)) {
|
|
1669
|
-
return `${acc}${exports.PatternBoolean}`;
|
|
1670
|
-
}
|
|
1671
|
-
else if (TypeGuard.TNever(schema)) {
|
|
1672
|
-
throw Error('TemplateLiteralPattern: TemplateLiteral cannot operate on types of TNever');
|
|
1673
|
-
}
|
|
1674
|
-
else {
|
|
1675
|
-
throw Error(`TemplateLiteralPattern: Unexpected Kind '${schema[exports.Kind]}'`);
|
|
1676
|
-
}
|
|
1529
|
+
// prettier-ignore
|
|
1530
|
+
return (TypeGuard.TTemplateLiteral(schema) ? schema.pattern.slice(1, schema.pattern.length - 1) :
|
|
1531
|
+
TypeGuard.TUnion(schema) ? `(${schema.anyOf.map((schema) => Visit(schema, acc)).join('|')})` :
|
|
1532
|
+
TypeGuard.TNumber(schema) ? `${acc}${exports.PatternNumber}` :
|
|
1533
|
+
TypeGuard.TInteger(schema) ? `${acc}${exports.PatternNumber}` :
|
|
1534
|
+
TypeGuard.TBigInt(schema) ? `${acc}${exports.PatternNumber}` :
|
|
1535
|
+
TypeGuard.TString(schema) ? `${acc}${exports.PatternString}` :
|
|
1536
|
+
TypeGuard.TLiteral(schema) ? `${acc}${Escape(schema.const.toString())}` :
|
|
1537
|
+
TypeGuard.TBoolean(schema) ? `${acc}${exports.PatternBoolean}` :
|
|
1538
|
+
Throw(`Unexpected Kind '${schema[exports.Kind]}'`));
|
|
1677
1539
|
}
|
|
1678
1540
|
function Create(kinds) {
|
|
1679
1541
|
return `^${kinds.map((schema) => Visit(schema, '')).join('')}\$`;
|
|
@@ -1698,10 +1560,7 @@ var TemplateLiteralResolver;
|
|
|
1698
1560
|
// --------------------------------------------------------------------------------------
|
|
1699
1561
|
// TemplateLiteralParser
|
|
1700
1562
|
// --------------------------------------------------------------------------------------
|
|
1701
|
-
class TemplateLiteralParserError extends
|
|
1702
|
-
constructor(message) {
|
|
1703
|
-
super(message);
|
|
1704
|
-
}
|
|
1563
|
+
class TemplateLiteralParserError extends TypeBoxError {
|
|
1705
1564
|
}
|
|
1706
1565
|
exports.TemplateLiteralParserError = TemplateLiteralParserError;
|
|
1707
1566
|
var TemplateLiteralParser;
|
|
@@ -1816,21 +1675,18 @@ var TemplateLiteralParser;
|
|
|
1816
1675
|
index = end - 1;
|
|
1817
1676
|
}
|
|
1818
1677
|
}
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
return { type: 'and', expr: expressions };
|
|
1678
|
+
// prettier-ignore
|
|
1679
|
+
return (expressions.length === 0) ? { type: 'const', const: '' } :
|
|
1680
|
+
(expressions.length === 1) ? expressions[0] :
|
|
1681
|
+
{ type: 'and', expr: expressions };
|
|
1824
1682
|
}
|
|
1825
1683
|
/** Parses a pattern and returns an expression tree */
|
|
1826
1684
|
function Parse(pattern) {
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
return And(pattern);
|
|
1833
|
-
return { type: 'const', const: pattern };
|
|
1685
|
+
// prettier-ignore
|
|
1686
|
+
return IsGroup(pattern) ? Parse(InGroup(pattern)) :
|
|
1687
|
+
IsPrecedenceOr(pattern) ? Or(pattern) :
|
|
1688
|
+
IsPrecedenceAnd(pattern) ? And(pattern) :
|
|
1689
|
+
{ type: 'const', const: pattern };
|
|
1834
1690
|
}
|
|
1835
1691
|
TemplateLiteralParser.Parse = Parse;
|
|
1836
1692
|
/** Parses a pattern and strips forward and trailing ^ and $ */
|
|
@@ -1842,8 +1698,14 @@ var TemplateLiteralParser;
|
|
|
1842
1698
|
// --------------------------------------------------------------------------------------
|
|
1843
1699
|
// TemplateLiteralFinite
|
|
1844
1700
|
// --------------------------------------------------------------------------------------
|
|
1701
|
+
class TemplateLiteralFiniteError extends TypeBoxError {
|
|
1702
|
+
}
|
|
1703
|
+
exports.TemplateLiteralFiniteError = TemplateLiteralFiniteError;
|
|
1845
1704
|
var TemplateLiteralFinite;
|
|
1846
1705
|
(function (TemplateLiteralFinite) {
|
|
1706
|
+
function Throw(message) {
|
|
1707
|
+
throw new TemplateLiteralFiniteError(message);
|
|
1708
|
+
}
|
|
1847
1709
|
function IsNumber(expression) {
|
|
1848
1710
|
// prettier-ignore
|
|
1849
1711
|
return (expression.type === 'or' &&
|
|
@@ -1866,23 +1728,22 @@ var TemplateLiteralFinite;
|
|
|
1866
1728
|
return expression.type === 'const' && expression.const === '.*';
|
|
1867
1729
|
}
|
|
1868
1730
|
function Check(expression) {
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
return expression.expr.every((expr) => Check(expr));
|
|
1877
|
-
if (expression.type === 'const')
|
|
1878
|
-
return true;
|
|
1879
|
-
throw Error(`TemplateLiteralFinite: Unknown expression type`);
|
|
1731
|
+
// prettier-ignore
|
|
1732
|
+
return IsBoolean(expression) ? true :
|
|
1733
|
+
IsNumber(expression) || IsString(expression) ? false :
|
|
1734
|
+
(expression.type === 'and') ? expression.expr.every((expr) => Check(expr)) :
|
|
1735
|
+
(expression.type === 'or') ? expression.expr.every((expr) => Check(expr)) :
|
|
1736
|
+
(expression.type === 'const') ? true :
|
|
1737
|
+
Throw(`Unknown expression type`);
|
|
1880
1738
|
}
|
|
1881
1739
|
TemplateLiteralFinite.Check = Check;
|
|
1882
1740
|
})(TemplateLiteralFinite || (exports.TemplateLiteralFinite = TemplateLiteralFinite = {}));
|
|
1883
1741
|
// --------------------------------------------------------------------------------------
|
|
1884
1742
|
// TemplateLiteralGenerator
|
|
1885
1743
|
// --------------------------------------------------------------------------------------
|
|
1744
|
+
class TemplateLiteralGeneratorError extends TypeBoxError {
|
|
1745
|
+
}
|
|
1746
|
+
exports.TemplateLiteralGeneratorError = TemplateLiteralGeneratorError;
|
|
1886
1747
|
var TemplateLiteralGenerator;
|
|
1887
1748
|
(function (TemplateLiteralGenerator) {
|
|
1888
1749
|
function* Reduce(buffer) {
|
|
@@ -1905,13 +1766,11 @@ var TemplateLiteralGenerator;
|
|
|
1905
1766
|
return yield expression.const;
|
|
1906
1767
|
}
|
|
1907
1768
|
function* Generate(expression) {
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
return yield* Const(expression);
|
|
1914
|
-
throw Error('TemplateLiteralGenerator: Unknown expression');
|
|
1769
|
+
// prettier-ignore
|
|
1770
|
+
return (expression.type === 'and' ? yield* And(expression) :
|
|
1771
|
+
expression.type === 'or' ? yield* Or(expression) :
|
|
1772
|
+
expression.type === 'const' ? yield* Const(expression) :
|
|
1773
|
+
(() => { throw new TemplateLiteralGeneratorError('Unknown expression'); })());
|
|
1915
1774
|
}
|
|
1916
1775
|
TemplateLiteralGenerator.Generate = Generate;
|
|
1917
1776
|
})(TemplateLiteralGenerator || (exports.TemplateLiteralGenerator = TemplateLiteralGenerator = {}));
|
|
@@ -1922,16 +1781,17 @@ var TemplateLiteralDslParser;
|
|
|
1922
1781
|
(function (TemplateLiteralDslParser) {
|
|
1923
1782
|
function* ParseUnion(template) {
|
|
1924
1783
|
const trim = template.trim().replace(/"|'/g, '');
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1784
|
+
// prettier-ignore
|
|
1785
|
+
return (trim === 'boolean' ? yield exports.Type.Boolean() :
|
|
1786
|
+
trim === 'number' ? yield exports.Type.Number() :
|
|
1787
|
+
trim === 'bigint' ? yield exports.Type.BigInt() :
|
|
1788
|
+
trim === 'string' ? yield exports.Type.String() :
|
|
1789
|
+
yield (() => {
|
|
1790
|
+
const literals = trim.split('|').map((literal) => exports.Type.Literal(literal.trim()));
|
|
1791
|
+
return (literals.length === 0 ? exports.Type.Never() :
|
|
1792
|
+
literals.length === 1 ? literals[0] :
|
|
1793
|
+
exports.Type.Union(literals));
|
|
1794
|
+
})());
|
|
1935
1795
|
}
|
|
1936
1796
|
function* ParseTerminal(template) {
|
|
1937
1797
|
if (template[1] !== '{') {
|
|
@@ -1963,6 +1823,38 @@ var TemplateLiteralDslParser;
|
|
|
1963
1823
|
}
|
|
1964
1824
|
TemplateLiteralDslParser.Parse = Parse;
|
|
1965
1825
|
})(TemplateLiteralDslParser || (exports.TemplateLiteralDslParser = TemplateLiteralDslParser = {}));
|
|
1826
|
+
// ---------------------------------------------------------------------
|
|
1827
|
+
// TransformBuilder
|
|
1828
|
+
// ---------------------------------------------------------------------
|
|
1829
|
+
class TransformDecodeBuilder {
|
|
1830
|
+
constructor(schema) {
|
|
1831
|
+
this.schema = schema;
|
|
1832
|
+
}
|
|
1833
|
+
Decode(decode) {
|
|
1834
|
+
return new TransformEncodeBuilder(this.schema, decode);
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
exports.TransformDecodeBuilder = TransformDecodeBuilder;
|
|
1838
|
+
class TransformEncodeBuilder {
|
|
1839
|
+
constructor(schema, decode) {
|
|
1840
|
+
this.schema = schema;
|
|
1841
|
+
this.decode = decode;
|
|
1842
|
+
}
|
|
1843
|
+
Encode(encode) {
|
|
1844
|
+
const schema = TypeClone.Type(this.schema);
|
|
1845
|
+
// prettier-ignore
|
|
1846
|
+
return (TypeGuard.TTransform(schema) ? (() => {
|
|
1847
|
+
const Encode = (value) => schema[exports.Transform].Encode(encode(value));
|
|
1848
|
+
const Decode = (value) => this.decode(schema[exports.Transform].Decode(value));
|
|
1849
|
+
const Codec = { Encode: Encode, Decode: Decode };
|
|
1850
|
+
return { ...schema, [exports.Transform]: Codec };
|
|
1851
|
+
})() : (() => {
|
|
1852
|
+
const Codec = { Decode: this.decode, Encode: encode };
|
|
1853
|
+
return { ...schema, [exports.Transform]: Codec };
|
|
1854
|
+
})());
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
exports.TransformEncodeBuilder = TransformEncodeBuilder;
|
|
1966
1858
|
// --------------------------------------------------------------------------
|
|
1967
1859
|
// TypeOrdinal: Used for auto $id generation
|
|
1968
1860
|
// --------------------------------------------------------------------------
|
|
@@ -1970,218 +1862,221 @@ let TypeOrdinal = 0;
|
|
|
1970
1862
|
// --------------------------------------------------------------------------
|
|
1971
1863
|
// TypeBuilder
|
|
1972
1864
|
// --------------------------------------------------------------------------
|
|
1865
|
+
class TypeBuilderError extends TypeBoxError {
|
|
1866
|
+
}
|
|
1867
|
+
exports.TypeBuilderError = TypeBuilderError;
|
|
1973
1868
|
class TypeBuilder {
|
|
1974
|
-
/** `[
|
|
1869
|
+
/** `[Internal]` Creates a schema without `static` and `params` types */
|
|
1975
1870
|
Create(schema) {
|
|
1976
1871
|
return schema;
|
|
1977
1872
|
}
|
|
1978
|
-
/** `[
|
|
1873
|
+
/** `[Internal]` Throws a TypeBuilder error with the given message */
|
|
1874
|
+
Throw(message) {
|
|
1875
|
+
throw new TypeBuilderError(message);
|
|
1876
|
+
}
|
|
1877
|
+
/** `[Internal]` Discards a property key from the given schema */
|
|
1979
1878
|
Discard(schema, key) {
|
|
1980
1879
|
const { [key]: _, ...rest } = schema;
|
|
1981
1880
|
return rest;
|
|
1982
1881
|
}
|
|
1983
|
-
/** `[
|
|
1882
|
+
/** `[Json]` Omits compositing symbols from this schema */
|
|
1984
1883
|
Strict(schema) {
|
|
1985
1884
|
return JSON.parse(JSON.stringify(schema));
|
|
1986
1885
|
}
|
|
1987
1886
|
}
|
|
1988
1887
|
exports.TypeBuilder = TypeBuilder;
|
|
1989
1888
|
// --------------------------------------------------------------------------
|
|
1990
|
-
//
|
|
1889
|
+
// JsonTypeBuilder
|
|
1991
1890
|
// --------------------------------------------------------------------------
|
|
1992
|
-
class
|
|
1891
|
+
class JsonTypeBuilder extends TypeBuilder {
|
|
1993
1892
|
// ------------------------------------------------------------------------
|
|
1994
1893
|
// Modifiers
|
|
1995
1894
|
// ------------------------------------------------------------------------
|
|
1996
|
-
/** `[
|
|
1895
|
+
/** `[Json]` Creates a Readonly and Optional property */
|
|
1997
1896
|
ReadonlyOptional(schema) {
|
|
1998
1897
|
return this.Readonly(this.Optional(schema));
|
|
1999
1898
|
}
|
|
2000
|
-
/** `[
|
|
1899
|
+
/** `[Json]` Creates a Readonly property */
|
|
2001
1900
|
Readonly(schema) {
|
|
2002
|
-
return { ...TypeClone.
|
|
1901
|
+
return { ...TypeClone.Type(schema), [exports.Readonly]: 'Readonly' };
|
|
2003
1902
|
}
|
|
2004
|
-
/** `[
|
|
1903
|
+
/** `[Json]` Creates an Optional property */
|
|
2005
1904
|
Optional(schema) {
|
|
2006
|
-
return { ...TypeClone.
|
|
1905
|
+
return { ...TypeClone.Type(schema), [exports.Optional]: 'Optional' };
|
|
2007
1906
|
}
|
|
2008
1907
|
// ------------------------------------------------------------------------
|
|
2009
1908
|
// Types
|
|
2010
1909
|
// ------------------------------------------------------------------------
|
|
2011
|
-
/** `[
|
|
1910
|
+
/** `[Json]` Creates an Any type */
|
|
2012
1911
|
Any(options = {}) {
|
|
2013
1912
|
return this.Create({ ...options, [exports.Kind]: 'Any' });
|
|
2014
1913
|
}
|
|
2015
|
-
/** `[
|
|
1914
|
+
/** `[Json]` Creates an Array type */
|
|
2016
1915
|
Array(schema, options = {}) {
|
|
2017
|
-
return this.Create({ ...options, [exports.Kind]: 'Array', type: 'array', items: TypeClone.
|
|
1916
|
+
return this.Create({ ...options, [exports.Kind]: 'Array', type: 'array', items: TypeClone.Type(schema) });
|
|
2018
1917
|
}
|
|
2019
|
-
/** `[
|
|
1918
|
+
/** `[Json]` Creates a Boolean type */
|
|
2020
1919
|
Boolean(options = {}) {
|
|
2021
1920
|
return this.Create({ ...options, [exports.Kind]: 'Boolean', type: 'boolean' });
|
|
2022
1921
|
}
|
|
2023
|
-
/** `[
|
|
1922
|
+
/** `[Json]` Intrinsic function to Capitalize LiteralString types */
|
|
2024
1923
|
Capitalize(schema, options = {}) {
|
|
2025
|
-
return { ...Intrinsic.Map(TypeClone.
|
|
1924
|
+
return { ...Intrinsic.Map(TypeClone.Type(schema), 'Capitalize'), ...options };
|
|
2026
1925
|
}
|
|
2027
|
-
/** `[
|
|
1926
|
+
/** `[Json]` Creates a Composite object type */
|
|
2028
1927
|
Composite(objects, options) {
|
|
2029
1928
|
const intersect = exports.Type.Intersect(objects, {});
|
|
2030
1929
|
const keys = KeyResolver.ResolveKeys(intersect, { includePatterns: false });
|
|
2031
1930
|
const properties = keys.reduce((acc, key) => ({ ...acc, [key]: exports.Type.Index(intersect, [key]) }), {});
|
|
2032
1931
|
return exports.Type.Object(properties, options);
|
|
2033
1932
|
}
|
|
2034
|
-
/** `[
|
|
1933
|
+
/** `[Json]` Creates a Enum type */
|
|
2035
1934
|
Enum(item, options = {}) {
|
|
2036
1935
|
// prettier-ignore
|
|
2037
1936
|
const values = Object.getOwnPropertyNames(item).filter((key) => isNaN(key)).map((key) => item[key]);
|
|
2038
|
-
|
|
1937
|
+
// prettier-ignore
|
|
1938
|
+
const anyOf = values.map((value) => ValueGuard.IsString(value)
|
|
1939
|
+
? { [exports.Kind]: 'Literal', type: 'string', const: value }
|
|
1940
|
+
: { [exports.Kind]: 'Literal', type: 'number', const: value });
|
|
2039
1941
|
return this.Create({ ...options, [exports.Kind]: 'Union', anyOf });
|
|
2040
1942
|
}
|
|
2041
|
-
/** `[
|
|
1943
|
+
/** `[Json]` Creates a Conditional type */
|
|
2042
1944
|
Extends(left, right, trueType, falseType, options = {}) {
|
|
2043
1945
|
switch (TypeExtends.Extends(left, right)) {
|
|
2044
1946
|
case TypeExtendsResult.Union:
|
|
2045
|
-
return this.Union([TypeClone.
|
|
1947
|
+
return this.Union([TypeClone.Type(trueType, options), TypeClone.Type(falseType, options)]);
|
|
2046
1948
|
case TypeExtendsResult.True:
|
|
2047
|
-
return TypeClone.
|
|
1949
|
+
return TypeClone.Type(trueType, options);
|
|
2048
1950
|
case TypeExtendsResult.False:
|
|
2049
|
-
return TypeClone.
|
|
1951
|
+
return TypeClone.Type(falseType, options);
|
|
2050
1952
|
}
|
|
2051
1953
|
}
|
|
2052
|
-
/** `[
|
|
1954
|
+
/** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
|
|
2053
1955
|
Exclude(unionType, excludedMembers, options = {}) {
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
}
|
|
2066
|
-
/** `[Standard]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
1956
|
+
// prettier-ignore
|
|
1957
|
+
return (TypeGuard.TTemplateLiteral(unionType) ? this.Exclude(TemplateLiteralResolver.Resolve(unionType), excludedMembers, options) :
|
|
1958
|
+
TypeGuard.TTemplateLiteral(excludedMembers) ? this.Exclude(unionType, TemplateLiteralResolver.Resolve(excludedMembers), options) :
|
|
1959
|
+
TypeGuard.TUnion(unionType) ? (() => {
|
|
1960
|
+
const narrowed = unionType.anyOf.filter((inner) => TypeExtends.Extends(inner, excludedMembers) === TypeExtendsResult.False);
|
|
1961
|
+
return (narrowed.length === 1 ? TypeClone.Type(narrowed[0], options) : this.Union(narrowed, options));
|
|
1962
|
+
})() :
|
|
1963
|
+
TypeExtends.Extends(unionType, excludedMembers) !== TypeExtendsResult.False ? this.Never(options) :
|
|
1964
|
+
TypeClone.Type(unionType, options));
|
|
1965
|
+
}
|
|
1966
|
+
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
2067
1967
|
Extract(type, union, options = {}) {
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
}
|
|
2080
|
-
/** `[Standard]` Returns an Indexed property type for the given keys */
|
|
1968
|
+
// prettier-ignore
|
|
1969
|
+
return (TypeGuard.TTemplateLiteral(type) ? this.Extract(TemplateLiteralResolver.Resolve(type), union, options) :
|
|
1970
|
+
TypeGuard.TTemplateLiteral(union) ? this.Extract(type, TemplateLiteralResolver.Resolve(union), options) :
|
|
1971
|
+
TypeGuard.TUnion(type) ? (() => {
|
|
1972
|
+
const narrowed = type.anyOf.filter((inner) => TypeExtends.Extends(inner, union) !== TypeExtendsResult.False);
|
|
1973
|
+
return (narrowed.length === 1 ? TypeClone.Type(narrowed[0], options) : this.Union(narrowed, options));
|
|
1974
|
+
})() :
|
|
1975
|
+
TypeExtends.Extends(type, union) !== TypeExtendsResult.False ? TypeClone.Type(type, options) :
|
|
1976
|
+
this.Never(options));
|
|
1977
|
+
}
|
|
1978
|
+
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
2081
1979
|
Index(schema, unresolved, options = {}) {
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
}
|
|
2096
|
-
/** `[
|
|
1980
|
+
// prettier-ignore
|
|
1981
|
+
return (TypeGuard.TArray(schema) && TypeGuard.TNumber(unresolved) ? (() => {
|
|
1982
|
+
return TypeClone.Type(schema.items, options);
|
|
1983
|
+
})() :
|
|
1984
|
+
TypeGuard.TTuple(schema) && TypeGuard.TNumber(unresolved) ? (() => {
|
|
1985
|
+
const items = ValueGuard.IsUndefined(schema.items) ? [] : schema.items;
|
|
1986
|
+
const cloned = items.map((schema) => TypeClone.Type(schema));
|
|
1987
|
+
return this.Union(cloned, options);
|
|
1988
|
+
})() : (() => {
|
|
1989
|
+
const keys = KeyArrayResolver.Resolve(unresolved);
|
|
1990
|
+
const clone = TypeClone.Type(schema);
|
|
1991
|
+
return IndexedAccessor.Resolve(clone, keys, options);
|
|
1992
|
+
})());
|
|
1993
|
+
}
|
|
1994
|
+
/** `[Json]` Creates an Integer type */
|
|
2097
1995
|
Integer(options = {}) {
|
|
2098
1996
|
return this.Create({ ...options, [exports.Kind]: 'Integer', type: 'integer' });
|
|
2099
1997
|
}
|
|
2100
|
-
/** `[
|
|
1998
|
+
/** `[Json]` Creates an Intersect type */
|
|
2101
1999
|
Intersect(allOf, options = {}) {
|
|
2102
2000
|
if (allOf.length === 0)
|
|
2103
2001
|
return exports.Type.Never();
|
|
2104
2002
|
if (allOf.length === 1)
|
|
2105
|
-
return TypeClone.
|
|
2003
|
+
return TypeClone.Type(allOf[0], options);
|
|
2004
|
+
if (allOf.some((schema) => TypeGuard.TTransform(schema)))
|
|
2005
|
+
this.Throw('Cannot intersect transform types');
|
|
2106
2006
|
const objects = allOf.every((schema) => TypeGuard.TObject(schema));
|
|
2107
|
-
const cloned =
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
}
|
|
2116
|
-
/** `[
|
|
2007
|
+
const cloned = TypeClone.Rest(allOf);
|
|
2008
|
+
// prettier-ignore
|
|
2009
|
+
const clonedUnevaluatedProperties = TypeGuard.TSchema(options.unevaluatedProperties)
|
|
2010
|
+
? { unevaluatedProperties: TypeClone.Type(options.unevaluatedProperties) }
|
|
2011
|
+
: {};
|
|
2012
|
+
return options.unevaluatedProperties === false || TypeGuard.TSchema(options.unevaluatedProperties) || objects
|
|
2013
|
+
? this.Create({ ...options, ...clonedUnevaluatedProperties, [exports.Kind]: 'Intersect', type: 'object', allOf: cloned })
|
|
2014
|
+
: this.Create({ ...options, ...clonedUnevaluatedProperties, [exports.Kind]: 'Intersect', allOf: cloned });
|
|
2015
|
+
}
|
|
2016
|
+
/** `[Json]` Creates a KeyOf type */
|
|
2117
2017
|
KeyOf(schema, options = {}) {
|
|
2118
|
-
|
|
2018
|
+
// prettier-ignore
|
|
2019
|
+
return (TypeGuard.TRecord(schema) ? (() => {
|
|
2119
2020
|
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
}
|
|
2141
|
-
}
|
|
2142
|
-
/** `[Standard]` Creates a Literal type */
|
|
2021
|
+
return (pattern === exports.PatternNumberExact ? this.Number(options) :
|
|
2022
|
+
pattern === exports.PatternStringExact ? this.String(options) :
|
|
2023
|
+
this.Throw('Unable to resolve key type from Record key pattern'));
|
|
2024
|
+
})() :
|
|
2025
|
+
TypeGuard.TTuple(schema) ? (() => {
|
|
2026
|
+
const items = ValueGuard.IsUndefined(schema.items) ? [] : schema.items;
|
|
2027
|
+
const literals = items.map((_, index) => exports.Type.Literal(index.toString()));
|
|
2028
|
+
return this.Union(literals, options);
|
|
2029
|
+
})() :
|
|
2030
|
+
TypeGuard.TArray(schema) ? (() => {
|
|
2031
|
+
return this.Number(options);
|
|
2032
|
+
})() : (() => {
|
|
2033
|
+
const keys = KeyResolver.ResolveKeys(schema, { includePatterns: false });
|
|
2034
|
+
if (keys.length === 0)
|
|
2035
|
+
return this.Never(options);
|
|
2036
|
+
const literals = keys.map((key) => this.Literal(key));
|
|
2037
|
+
return this.Union(literals, options);
|
|
2038
|
+
})());
|
|
2039
|
+
}
|
|
2040
|
+
/** `[Json]` Creates a Literal type */
|
|
2143
2041
|
Literal(value, options = {}) {
|
|
2144
2042
|
return this.Create({ ...options, [exports.Kind]: 'Literal', const: value, type: typeof value });
|
|
2145
2043
|
}
|
|
2146
|
-
/** `[
|
|
2044
|
+
/** `[Json]` Intrinsic function to Lowercase LiteralString types */
|
|
2147
2045
|
Lowercase(schema, options = {}) {
|
|
2148
|
-
return { ...Intrinsic.Map(TypeClone.
|
|
2046
|
+
return { ...Intrinsic.Map(TypeClone.Type(schema), 'Lowercase'), ...options };
|
|
2149
2047
|
}
|
|
2150
|
-
/** `[
|
|
2048
|
+
/** `[Json]` Creates a Never type */
|
|
2151
2049
|
Never(options = {}) {
|
|
2152
2050
|
return this.Create({ ...options, [exports.Kind]: 'Never', not: {} });
|
|
2153
2051
|
}
|
|
2154
|
-
/** `[
|
|
2052
|
+
/** `[Json]` Creates a Not type */
|
|
2155
2053
|
Not(schema, options) {
|
|
2156
|
-
return this.Create({ ...options, [exports.Kind]: 'Not', not: TypeClone.
|
|
2054
|
+
return this.Create({ ...options, [exports.Kind]: 'Not', not: TypeClone.Type(schema) });
|
|
2157
2055
|
}
|
|
2158
|
-
/** `[
|
|
2056
|
+
/** `[Json]` Creates a Null type */
|
|
2159
2057
|
Null(options = {}) {
|
|
2160
2058
|
return this.Create({ ...options, [exports.Kind]: 'Null', type: 'null' });
|
|
2161
2059
|
}
|
|
2162
|
-
/** `[
|
|
2060
|
+
/** `[Json]` Creates a Number type */
|
|
2163
2061
|
Number(options = {}) {
|
|
2164
2062
|
return this.Create({ ...options, [exports.Kind]: 'Number', type: 'number' });
|
|
2165
2063
|
}
|
|
2166
|
-
/** `[
|
|
2064
|
+
/** `[Json]` Creates an Object type */
|
|
2167
2065
|
Object(properties, options = {}) {
|
|
2168
2066
|
const propertyKeys = Object.getOwnPropertyNames(properties);
|
|
2169
2067
|
const optionalKeys = propertyKeys.filter((key) => TypeGuard.TOptional(properties[key]));
|
|
2170
2068
|
const requiredKeys = propertyKeys.filter((name) => !optionalKeys.includes(name));
|
|
2171
|
-
const clonedAdditionalProperties = TypeGuard.TSchema(options.additionalProperties) ? { additionalProperties: TypeClone.
|
|
2172
|
-
const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: TypeClone.
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
else {
|
|
2177
|
-
return this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: 'Object', type: 'object', properties: clonedProperties });
|
|
2178
|
-
}
|
|
2069
|
+
const clonedAdditionalProperties = TypeGuard.TSchema(options.additionalProperties) ? { additionalProperties: TypeClone.Type(options.additionalProperties) } : {};
|
|
2070
|
+
const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: TypeClone.Type(properties[key]) }), {});
|
|
2071
|
+
return requiredKeys.length > 0
|
|
2072
|
+
? this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: 'Object', type: 'object', properties: clonedProperties, required: requiredKeys })
|
|
2073
|
+
: this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: 'Object', type: 'object', properties: clonedProperties });
|
|
2179
2074
|
}
|
|
2180
|
-
/** `[
|
|
2075
|
+
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
2181
2076
|
Omit(schema, unresolved, options = {}) {
|
|
2182
2077
|
const keys = KeyArrayResolver.Resolve(unresolved);
|
|
2183
2078
|
// prettier-ignore
|
|
2184
|
-
return ObjectMap.Map(TypeClone.
|
|
2079
|
+
return ObjectMap.Map(this.Discard(TypeClone.Type(schema), exports.Transform), (object) => {
|
|
2185
2080
|
if (ValueGuard.IsArray(object.required)) {
|
|
2186
2081
|
object.required = object.required.filter((key) => !keys.includes(key));
|
|
2187
2082
|
if (object.required.length === 0)
|
|
@@ -2194,21 +2089,21 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
2194
2089
|
return this.Create(object);
|
|
2195
2090
|
}, options);
|
|
2196
2091
|
}
|
|
2197
|
-
/** `[
|
|
2092
|
+
/** `[Json]` Constructs a type where all properties are optional */
|
|
2198
2093
|
Partial(schema, options = {}) {
|
|
2199
2094
|
// prettier-ignore
|
|
2200
|
-
return ObjectMap.Map(schema, (object) => {
|
|
2095
|
+
return ObjectMap.Map(this.Discard(TypeClone.Type(schema), exports.Transform), (object) => {
|
|
2201
2096
|
const properties = Object.getOwnPropertyNames(object.properties).reduce((acc, key) => {
|
|
2202
2097
|
return { ...acc, [key]: this.Optional(object.properties[key]) };
|
|
2203
2098
|
}, {});
|
|
2204
2099
|
return this.Object(properties, this.Discard(object, 'required') /* object used as options to retain other constraints */);
|
|
2205
2100
|
}, options);
|
|
2206
2101
|
}
|
|
2207
|
-
/** `[
|
|
2102
|
+
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
2208
2103
|
Pick(schema, unresolved, options = {}) {
|
|
2209
2104
|
const keys = KeyArrayResolver.Resolve(unresolved);
|
|
2210
2105
|
// prettier-ignore
|
|
2211
|
-
return ObjectMap.Map(TypeClone.
|
|
2106
|
+
return ObjectMap.Map(this.Discard(TypeClone.Type(schema), exports.Transform), (object) => {
|
|
2212
2107
|
if (ValueGuard.IsArray(object.required)) {
|
|
2213
2108
|
object.required = object.required.filter((key) => keys.includes(key));
|
|
2214
2109
|
if (object.required.length === 0)
|
|
@@ -2221,43 +2116,41 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
2221
2116
|
return this.Create(object);
|
|
2222
2117
|
}, options);
|
|
2223
2118
|
}
|
|
2224
|
-
/** `[
|
|
2119
|
+
/** `[Json]` Creates a Record type */
|
|
2225
2120
|
Record(key, schema, options = {}) {
|
|
2226
|
-
|
|
2121
|
+
// prettier-ignore
|
|
2122
|
+
return (TypeGuard.TTemplateLiteral(key) ? (() => {
|
|
2227
2123
|
const expression = TemplateLiteralParser.ParseExact(key.pattern);
|
|
2228
2124
|
// prettier-ignore
|
|
2229
2125
|
return TemplateLiteralFinite.Check(expression)
|
|
2230
|
-
? (this.Object([...TemplateLiteralGenerator.Generate(expression)].reduce((acc, key) => ({ ...acc, [key]: TypeClone.
|
|
2231
|
-
: this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [key.pattern]: TypeClone.
|
|
2232
|
-
}
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
}
|
|
2259
|
-
}
|
|
2260
|
-
/** `[Standard]` Creates a Recursive type */
|
|
2126
|
+
? (this.Object([...TemplateLiteralGenerator.Generate(expression)].reduce((acc, key) => ({ ...acc, [key]: TypeClone.Type(schema) }), {}), options))
|
|
2127
|
+
: this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [key.pattern]: TypeClone.Type(schema) } });
|
|
2128
|
+
})() :
|
|
2129
|
+
TypeGuard.TUnion(key) ? (() => {
|
|
2130
|
+
const union = UnionResolver.Resolve(key);
|
|
2131
|
+
if (TypeGuard.TUnionLiteral(union)) {
|
|
2132
|
+
const properties = union.anyOf.reduce((acc, literal) => ({ ...acc, [literal.const]: TypeClone.Type(schema) }), {});
|
|
2133
|
+
return this.Object(properties, { ...options, [exports.Hint]: 'Record' });
|
|
2134
|
+
}
|
|
2135
|
+
else
|
|
2136
|
+
this.Throw('Record key of type union contains non-literal types');
|
|
2137
|
+
})() :
|
|
2138
|
+
TypeGuard.TLiteral(key) ? (() => {
|
|
2139
|
+
// prettier-ignore
|
|
2140
|
+
return (ValueGuard.IsString(key.const) || ValueGuard.IsNumber(key.const))
|
|
2141
|
+
? this.Object({ [key.const]: TypeClone.Type(schema) }, options)
|
|
2142
|
+
: this.Throw('Record key of type literal is not of type string or number');
|
|
2143
|
+
})() :
|
|
2144
|
+
TypeGuard.TInteger(key) || TypeGuard.TNumber(key) ? (() => {
|
|
2145
|
+
return this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [exports.PatternNumberExact]: TypeClone.Type(schema) } });
|
|
2146
|
+
})() :
|
|
2147
|
+
TypeGuard.TString(key) ? (() => {
|
|
2148
|
+
const pattern = ValueGuard.IsUndefined(key.pattern) ? exports.PatternStringExact : key.pattern;
|
|
2149
|
+
return this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [pattern]: TypeClone.Type(schema) } });
|
|
2150
|
+
})() :
|
|
2151
|
+
this.Throw(`Record key is an invalid type`));
|
|
2152
|
+
}
|
|
2153
|
+
/** `[Json]` Creates a Recursive type */
|
|
2261
2154
|
Recursive(callback, options = {}) {
|
|
2262
2155
|
if (ValueGuard.IsUndefined(options.$id))
|
|
2263
2156
|
options.$id = `T${TypeOrdinal++}`;
|
|
@@ -2265,151 +2158,145 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
2265
2158
|
thisType.$id = options.$id;
|
|
2266
2159
|
return this.Create({ ...options, [exports.Hint]: 'Recursive', ...thisType });
|
|
2267
2160
|
}
|
|
2268
|
-
/** `[
|
|
2161
|
+
/** `[Json]` Creates a Ref type. */
|
|
2269
2162
|
Ref(unresolved, options = {}) {
|
|
2270
2163
|
if (ValueGuard.IsString(unresolved))
|
|
2271
2164
|
return this.Create({ ...options, [exports.Kind]: 'Ref', $ref: unresolved });
|
|
2272
2165
|
if (ValueGuard.IsUndefined(unresolved.$id))
|
|
2273
|
-
|
|
2166
|
+
this.Throw('Reference target type must specify an $id');
|
|
2274
2167
|
return this.Create({ ...options, [exports.Kind]: 'Ref', $ref: unresolved.$id });
|
|
2275
2168
|
}
|
|
2276
|
-
/** `[
|
|
2169
|
+
/** `[Json]` Constructs a type where all properties are required */
|
|
2277
2170
|
Required(schema, options = {}) {
|
|
2278
2171
|
// prettier-ignore
|
|
2279
|
-
return ObjectMap.Map(schema, (object) => {
|
|
2172
|
+
return ObjectMap.Map(this.Discard(TypeClone.Type(schema), exports.Transform), (object) => {
|
|
2280
2173
|
const properties = Object.getOwnPropertyNames(object.properties).reduce((acc, key) => {
|
|
2281
2174
|
return { ...acc, [key]: this.Discard(object.properties[key], exports.Optional) };
|
|
2282
2175
|
}, {});
|
|
2283
2176
|
return this.Object(properties, object /* object used as options to retain other constraints */);
|
|
2284
2177
|
}, options);
|
|
2285
2178
|
}
|
|
2286
|
-
/** `[
|
|
2179
|
+
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
2287
2180
|
Rest(schema) {
|
|
2288
|
-
|
|
2289
|
-
if (ValueGuard.IsUndefined(schema.items))
|
|
2290
|
-
return [];
|
|
2291
|
-
return schema.items.map((schema) => TypeClone.Clone(schema));
|
|
2292
|
-
}
|
|
2293
|
-
else {
|
|
2294
|
-
return [TypeClone.Clone(schema)];
|
|
2295
|
-
}
|
|
2181
|
+
return (TypeGuard.TTuple(schema) && !ValueGuard.IsUndefined(schema.items) ? TypeClone.Rest(schema.items) : TypeGuard.TIntersect(schema) ? TypeClone.Rest(schema.allOf) : TypeGuard.TUnion(schema) ? TypeClone.Rest(schema.anyOf) : []);
|
|
2296
2182
|
}
|
|
2297
|
-
/** `[
|
|
2183
|
+
/** `[Json]` Creates a String type */
|
|
2298
2184
|
String(options = {}) {
|
|
2299
2185
|
return this.Create({ ...options, [exports.Kind]: 'String', type: 'string' });
|
|
2300
2186
|
}
|
|
2301
|
-
/** `[
|
|
2187
|
+
/** `[Json]` Creates a TemplateLiteral type */
|
|
2302
2188
|
TemplateLiteral(unresolved, options = {}) {
|
|
2303
2189
|
// prettier-ignore
|
|
2304
|
-
const pattern =
|
|
2190
|
+
const pattern = ValueGuard.IsString(unresolved)
|
|
2305
2191
|
? TemplateLiteralPattern.Create(TemplateLiteralDslParser.Parse(unresolved))
|
|
2306
2192
|
: TemplateLiteralPattern.Create(unresolved);
|
|
2307
2193
|
return this.Create({ ...options, [exports.Kind]: 'TemplateLiteral', type: 'string', pattern });
|
|
2308
2194
|
}
|
|
2309
|
-
/** `[
|
|
2195
|
+
/** `[Json]` Creates a Transform type */
|
|
2196
|
+
Transform(schema) {
|
|
2197
|
+
return new TransformDecodeBuilder(schema);
|
|
2198
|
+
}
|
|
2199
|
+
/** `[Json]` Creates a Tuple type */
|
|
2310
2200
|
Tuple(items, options = {}) {
|
|
2311
2201
|
const [additionalItems, minItems, maxItems] = [false, items.length, items.length];
|
|
2312
|
-
const clonedItems =
|
|
2202
|
+
const clonedItems = TypeClone.Rest(items);
|
|
2313
2203
|
// prettier-ignore
|
|
2314
2204
|
const schema = (items.length > 0 ?
|
|
2315
2205
|
{ ...options, [exports.Kind]: 'Tuple', type: 'array', items: clonedItems, additionalItems, minItems, maxItems } :
|
|
2316
2206
|
{ ...options, [exports.Kind]: 'Tuple', type: 'array', minItems, maxItems });
|
|
2317
2207
|
return this.Create(schema);
|
|
2318
2208
|
}
|
|
2319
|
-
/** `[
|
|
2209
|
+
/** `[Json]` Intrinsic function to Uncapitalize LiteralString types */
|
|
2320
2210
|
Uncapitalize(schema, options = {}) {
|
|
2321
|
-
return { ...Intrinsic.Map(TypeClone.
|
|
2211
|
+
return { ...Intrinsic.Map(TypeClone.Type(schema), 'Uncapitalize'), ...options };
|
|
2322
2212
|
}
|
|
2323
|
-
/** `[
|
|
2213
|
+
/** `[Json]` Creates a Union type */
|
|
2324
2214
|
Union(union, options = {}) {
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
}
|
|
2338
|
-
/** `[
|
|
2215
|
+
// prettier-ignore
|
|
2216
|
+
return TypeGuard.TTemplateLiteral(union)
|
|
2217
|
+
? TemplateLiteralResolver.Resolve(union)
|
|
2218
|
+
: (() => {
|
|
2219
|
+
const anyOf = union;
|
|
2220
|
+
if (anyOf.length === 0)
|
|
2221
|
+
return this.Never(options);
|
|
2222
|
+
if (anyOf.length === 1)
|
|
2223
|
+
return this.Create(TypeClone.Type(anyOf[0], options));
|
|
2224
|
+
const clonedAnyOf = TypeClone.Rest(anyOf);
|
|
2225
|
+
return this.Create({ ...options, [exports.Kind]: 'Union', anyOf: clonedAnyOf });
|
|
2226
|
+
})();
|
|
2227
|
+
}
|
|
2228
|
+
/** `[Json]` Creates an Unknown type */
|
|
2339
2229
|
Unknown(options = {}) {
|
|
2340
2230
|
return this.Create({ ...options, [exports.Kind]: 'Unknown' });
|
|
2341
2231
|
}
|
|
2342
|
-
/** `[
|
|
2232
|
+
/** `[Json]` Creates a Unsafe type that will infers as the generic argument T */
|
|
2343
2233
|
Unsafe(options = {}) {
|
|
2344
2234
|
return this.Create({ ...options, [exports.Kind]: options[exports.Kind] || 'Unsafe' });
|
|
2345
2235
|
}
|
|
2346
|
-
/** `[
|
|
2236
|
+
/** `[Json]` Intrinsic function to Uppercase LiteralString types */
|
|
2347
2237
|
Uppercase(schema, options = {}) {
|
|
2348
|
-
return { ...Intrinsic.Map(TypeClone.
|
|
2238
|
+
return { ...Intrinsic.Map(TypeClone.Type(schema), 'Uppercase'), ...options };
|
|
2349
2239
|
}
|
|
2350
2240
|
}
|
|
2351
|
-
exports.
|
|
2241
|
+
exports.JsonTypeBuilder = JsonTypeBuilder;
|
|
2352
2242
|
// --------------------------------------------------------------------------
|
|
2353
|
-
//
|
|
2243
|
+
// JavaScriptTypeBuilder
|
|
2354
2244
|
// --------------------------------------------------------------------------
|
|
2355
|
-
class
|
|
2356
|
-
/** `[
|
|
2245
|
+
class JavaScriptTypeBuilder extends JsonTypeBuilder {
|
|
2246
|
+
/** `[JavaScript]` Creates a AsyncIterator type */
|
|
2357
2247
|
AsyncIterator(items, options = {}) {
|
|
2358
|
-
return this.Create({ ...options, [exports.Kind]: 'AsyncIterator', type: 'AsyncIterator', items: TypeClone.
|
|
2248
|
+
return this.Create({ ...options, [exports.Kind]: 'AsyncIterator', type: 'AsyncIterator', items: TypeClone.Type(items) });
|
|
2359
2249
|
}
|
|
2360
|
-
/** `[
|
|
2250
|
+
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
2361
2251
|
Awaited(schema, options = {}) {
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
return rest;
|
|
2252
|
+
// prettier-ignore
|
|
2253
|
+
const Unwrap = (rest) => rest.length > 0 ? (() => {
|
|
2365
2254
|
const [L, ...R] = rest;
|
|
2366
|
-
return [this.Awaited(L), ...
|
|
2367
|
-
};
|
|
2255
|
+
return [this.Awaited(L), ...Unwrap(R)];
|
|
2256
|
+
})() : rest;
|
|
2368
2257
|
// prettier-ignore
|
|
2369
|
-
return (TypeGuard.TIntersect(schema) ? exports.Type.Intersect(
|
|
2370
|
-
TypeGuard.TUnion(schema) ? exports.Type.Union(
|
|
2258
|
+
return (TypeGuard.TIntersect(schema) ? exports.Type.Intersect(Unwrap(schema.allOf)) :
|
|
2259
|
+
TypeGuard.TUnion(schema) ? exports.Type.Union(Unwrap(schema.anyOf)) :
|
|
2371
2260
|
TypeGuard.TPromise(schema) ? this.Awaited(schema.item) :
|
|
2372
|
-
TypeClone.
|
|
2261
|
+
TypeClone.Type(schema, options));
|
|
2373
2262
|
}
|
|
2374
|
-
/** `[
|
|
2263
|
+
/** `[JavaScript]` Creates a BigInt type */
|
|
2375
2264
|
BigInt(options = {}) {
|
|
2376
2265
|
return this.Create({ ...options, [exports.Kind]: 'BigInt', type: 'bigint' });
|
|
2377
2266
|
}
|
|
2378
|
-
/** `[
|
|
2267
|
+
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
2379
2268
|
ConstructorParameters(schema, options = {}) {
|
|
2380
2269
|
return this.Tuple([...schema.parameters], { ...options });
|
|
2381
2270
|
}
|
|
2382
|
-
/** `[
|
|
2271
|
+
/** `[JavaScript]` Creates a Constructor type */
|
|
2383
2272
|
Constructor(parameters, returns, options) {
|
|
2384
|
-
const clonedReturns = TypeClone.
|
|
2385
|
-
const clonedParameters = parameters.map((parameter) => TypeClone.Clone(parameter));
|
|
2273
|
+
const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
|
|
2386
2274
|
return this.Create({ ...options, [exports.Kind]: 'Constructor', type: 'constructor', parameters: clonedParameters, returns: clonedReturns });
|
|
2387
2275
|
}
|
|
2388
|
-
/** `[
|
|
2276
|
+
/** `[JavaScript]` Creates a Date type */
|
|
2389
2277
|
Date(options = {}) {
|
|
2390
2278
|
return this.Create({ ...options, [exports.Kind]: 'Date', type: 'Date' });
|
|
2391
2279
|
}
|
|
2392
|
-
/** `[
|
|
2280
|
+
/** `[JavaScript]` Creates a Function type */
|
|
2393
2281
|
Function(parameters, returns, options) {
|
|
2394
|
-
const clonedReturns = TypeClone.
|
|
2395
|
-
const clonedParameters = parameters.map((parameter) => TypeClone.Clone(parameter));
|
|
2282
|
+
const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
|
|
2396
2283
|
return this.Create({ ...options, [exports.Kind]: 'Function', type: 'function', parameters: clonedParameters, returns: clonedReturns });
|
|
2397
2284
|
}
|
|
2398
|
-
/** `[
|
|
2285
|
+
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
2399
2286
|
InstanceType(schema, options = {}) {
|
|
2400
|
-
return TypeClone.
|
|
2287
|
+
return TypeClone.Type(schema.returns, options);
|
|
2401
2288
|
}
|
|
2402
|
-
/** `[
|
|
2289
|
+
/** `[JavaScript]` Creates an Iterator type */
|
|
2403
2290
|
Iterator(items, options = {}) {
|
|
2404
|
-
return this.Create({ ...options, [exports.Kind]: 'Iterator', type: 'Iterator', items: TypeClone.
|
|
2291
|
+
return this.Create({ ...options, [exports.Kind]: 'Iterator', type: 'Iterator', items: TypeClone.Type(items) });
|
|
2405
2292
|
}
|
|
2406
|
-
/** `[
|
|
2293
|
+
/** `[JavaScript]` Extracts the Parameters from the given Function type */
|
|
2407
2294
|
Parameters(schema, options = {}) {
|
|
2408
2295
|
return this.Tuple(schema.parameters, { ...options });
|
|
2409
2296
|
}
|
|
2410
|
-
/** `[
|
|
2297
|
+
/** `[JavaScript]` Creates a Promise type */
|
|
2411
2298
|
Promise(item, options = {}) {
|
|
2412
|
-
return this.Create({ ...options, [exports.Kind]: 'Promise', type: 'Promise', item: TypeClone.
|
|
2299
|
+
return this.Create({ ...options, [exports.Kind]: 'Promise', type: 'Promise', item: TypeClone.Type(item) });
|
|
2413
2300
|
}
|
|
2414
2301
|
/** `[Extended]` Creates a String type */
|
|
2415
2302
|
RegExp(unresolved, options = {}) {
|
|
@@ -2422,29 +2309,29 @@ class ExtendedTypeBuilder extends StandardTypeBuilder {
|
|
|
2422
2309
|
RegEx(regex, options = {}) {
|
|
2423
2310
|
return this.RegExp(regex, options);
|
|
2424
2311
|
}
|
|
2425
|
-
/** `[
|
|
2312
|
+
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
2426
2313
|
ReturnType(schema, options = {}) {
|
|
2427
|
-
return TypeClone.
|
|
2314
|
+
return TypeClone.Type(schema.returns, options);
|
|
2428
2315
|
}
|
|
2429
|
-
/** `[
|
|
2316
|
+
/** `[JavaScript]` Creates a Symbol type */
|
|
2430
2317
|
Symbol(options) {
|
|
2431
2318
|
return this.Create({ ...options, [exports.Kind]: 'Symbol', type: 'symbol' });
|
|
2432
2319
|
}
|
|
2433
|
-
/** `[
|
|
2320
|
+
/** `[JavaScript]` Creates a Undefined type */
|
|
2434
2321
|
Undefined(options = {}) {
|
|
2435
2322
|
return this.Create({ ...options, [exports.Kind]: 'Undefined', type: 'undefined' });
|
|
2436
2323
|
}
|
|
2437
|
-
/** `[
|
|
2324
|
+
/** `[JavaScript]` Creates a Uint8Array type */
|
|
2438
2325
|
Uint8Array(options = {}) {
|
|
2439
2326
|
return this.Create({ ...options, [exports.Kind]: 'Uint8Array', type: 'Uint8Array' });
|
|
2440
2327
|
}
|
|
2441
|
-
/** `[
|
|
2328
|
+
/** `[JavaScript]` Creates a Void type */
|
|
2442
2329
|
Void(options = {}) {
|
|
2443
2330
|
return this.Create({ ...options, [exports.Kind]: 'Void', type: 'void' });
|
|
2444
2331
|
}
|
|
2445
2332
|
}
|
|
2446
|
-
exports.
|
|
2447
|
-
/**
|
|
2448
|
-
exports.
|
|
2449
|
-
/**
|
|
2450
|
-
exports.Type = new
|
|
2333
|
+
exports.JavaScriptTypeBuilder = JavaScriptTypeBuilder;
|
|
2334
|
+
/** Json Type Builder with Static Resolution for TypeScript */
|
|
2335
|
+
exports.JsonType = new JsonTypeBuilder();
|
|
2336
|
+
/** JavaScript Type Builder with Static Resolution for TypeScript */
|
|
2337
|
+
exports.Type = new JavaScriptTypeBuilder();
|