@sinclair/typebox 0.26.0-dev.4 → 0.26.0-dev.5
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 +9 -4
- package/compiler/compiler.js +121 -97
- package/errors/errors.d.ts +5 -1
- package/errors/errors.js +173 -157
- package/package.json +1 -1
- package/readme.md +70 -71
- package/typebox.d.ts +16 -27
- package/typebox.js +104 -163
- package/value/cast.d.ts +6 -2
- package/value/cast.js +130 -111
- package/value/check.d.ts +5 -1
- package/value/check.js +168 -154
- package/value/convert.d.ts +6 -6
- package/value/convert.js +83 -74
- package/value/create.d.ts +6 -2
- package/value/create.js +102 -77
- package/value/value.d.ts +13 -3
- package/value/value.js +15 -15
package/typebox.js
CHANGED
|
@@ -27,106 +27,69 @@ THE SOFTWARE.
|
|
|
27
27
|
|
|
28
28
|
---------------------------------------------------------------------------*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.Type = exports.StandardType = exports.ExtendedTypeBuilder = exports.StandardTypeBuilder = exports.TypeBuilder = exports.KeyResolver = exports.ObjectMap = exports.TypeClone = exports.TypeExtends = exports.TypeExtendsResult = exports.ExtendsUndefined = exports.TypeGuard = exports.TypeGuardUnknownTypeError = exports.FormatRegistry = exports.
|
|
30
|
+
exports.Type = exports.StandardType = exports.ExtendedTypeBuilder = exports.StandardTypeBuilder = exports.TypeBuilder = exports.KeyResolver = exports.ObjectMap = exports.TypeClone = exports.TypeExtends = exports.TypeExtendsResult = exports.ExtendsUndefined = exports.TypeGuard = exports.TypeGuardUnknownTypeError = exports.FormatRegistry = exports.TypeRegistry = exports.Kind = exports.Hint = exports.Modifier = void 0;
|
|
31
31
|
// --------------------------------------------------------------------------
|
|
32
32
|
// Compositing Symbols
|
|
33
33
|
// --------------------------------------------------------------------------
|
|
34
|
-
exports.Recursive = Symbol.for('TypeBox.Recursive');
|
|
35
34
|
exports.Modifier = Symbol.for('TypeBox.Modifier');
|
|
36
35
|
exports.Hint = Symbol.for('TypeBox.Hint');
|
|
37
36
|
exports.Kind = Symbol.for('TypeBox.Kind');
|
|
38
37
|
var TypeRegistry;
|
|
39
38
|
(function (TypeRegistry) {
|
|
40
|
-
const
|
|
39
|
+
const map = new Map();
|
|
40
|
+
/** Returns the entries in this registry */
|
|
41
|
+
function Entries() {
|
|
42
|
+
return new Map(map);
|
|
43
|
+
}
|
|
44
|
+
TypeRegistry.Entries = Entries;
|
|
41
45
|
/** Clears all user defined types */
|
|
42
46
|
function Clear() {
|
|
43
|
-
return
|
|
47
|
+
return map.clear();
|
|
44
48
|
}
|
|
45
49
|
TypeRegistry.Clear = Clear;
|
|
46
50
|
/** Returns true if this registry contains this kind */
|
|
47
51
|
function Has(kind) {
|
|
48
|
-
return
|
|
52
|
+
return map.has(kind);
|
|
49
53
|
}
|
|
50
54
|
TypeRegistry.Has = Has;
|
|
51
55
|
/** Sets a validation function for a user defined type */
|
|
52
56
|
function Set(kind, func) {
|
|
53
|
-
|
|
57
|
+
map.set(kind, func);
|
|
54
58
|
}
|
|
55
59
|
TypeRegistry.Set = Set;
|
|
56
60
|
/** Gets a custom validation function for a user defined type */
|
|
57
61
|
function Get(kind) {
|
|
58
|
-
return
|
|
62
|
+
return map.get(kind);
|
|
59
63
|
}
|
|
60
64
|
TypeRegistry.Get = Get;
|
|
61
65
|
})(TypeRegistry = exports.TypeRegistry || (exports.TypeRegistry = {}));
|
|
62
|
-
// --------------------------------------------------------------------------
|
|
63
|
-
// ReferenceRegistry
|
|
64
|
-
// --------------------------------------------------------------------------
|
|
65
|
-
var ReferenceRegistry;
|
|
66
|
-
(function (ReferenceRegistry) {
|
|
67
|
-
const references = new Map();
|
|
68
|
-
/** Clears the reference registry */
|
|
69
|
-
function Clear() {
|
|
70
|
-
return references.clear();
|
|
71
|
-
}
|
|
72
|
-
ReferenceRegistry.Clear = Clear;
|
|
73
|
-
/** Returns true if this registry contains this schema */
|
|
74
|
-
function Has(schema) {
|
|
75
|
-
return references.has(schema.$id);
|
|
76
|
-
}
|
|
77
|
-
ReferenceRegistry.Has = Has;
|
|
78
|
-
/** Sets this schema on this registry if a $id exists */
|
|
79
|
-
function Set(schema) {
|
|
80
|
-
const $id = typeof schema === 'object' && schema !== null && typeof schema['$id'] === 'string' ? schema['$id'] : undefined;
|
|
81
|
-
if ($id !== undefined)
|
|
82
|
-
references.set($id, schema);
|
|
83
|
-
}
|
|
84
|
-
ReferenceRegistry.Set = Set;
|
|
85
|
-
/** Dereferences the schema one level deep */
|
|
86
|
-
function DerefOne(schema) {
|
|
87
|
-
if (TypeGuard.TRef(schema) || TypeGuard.TSelf(schema)) {
|
|
88
|
-
if (!references.has(schema.$ref))
|
|
89
|
-
throw Error(`ReferenceRegistry: Cannot deref schema with $id '${schema.$ref}'`);
|
|
90
|
-
return references.get(schema.$ref);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
return schema;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
ReferenceRegistry.DerefOne = DerefOne;
|
|
97
|
-
/** Dereferences the schema recursively */
|
|
98
|
-
function Deref(schema) {
|
|
99
|
-
if (TypeGuard.TRef(schema)) {
|
|
100
|
-
return Deref(DerefOne(schema));
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
return schema;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
ReferenceRegistry.Deref = Deref;
|
|
107
|
-
})(ReferenceRegistry = exports.ReferenceRegistry || (exports.ReferenceRegistry = {}));
|
|
108
66
|
/** Provides functions to create user defined string formats */
|
|
109
67
|
var FormatRegistry;
|
|
110
68
|
(function (FormatRegistry) {
|
|
111
|
-
const
|
|
69
|
+
const map = new Map();
|
|
70
|
+
/** Returns the entries in this registry */
|
|
71
|
+
function Entries() {
|
|
72
|
+
return new Map(map);
|
|
73
|
+
}
|
|
74
|
+
FormatRegistry.Entries = Entries;
|
|
112
75
|
/** Clears all user defined string formats */
|
|
113
76
|
function Clear() {
|
|
114
|
-
return
|
|
77
|
+
return map.clear();
|
|
115
78
|
}
|
|
116
79
|
FormatRegistry.Clear = Clear;
|
|
117
80
|
/** Returns true if the user defined string format exists */
|
|
118
81
|
function Has(format) {
|
|
119
|
-
return
|
|
82
|
+
return map.has(format);
|
|
120
83
|
}
|
|
121
84
|
FormatRegistry.Has = Has;
|
|
122
85
|
/** Sets a validation function for a user defined string format */
|
|
123
86
|
function Set(format, func) {
|
|
124
|
-
|
|
87
|
+
map.set(format, func);
|
|
125
88
|
}
|
|
126
89
|
FormatRegistry.Set = Set;
|
|
127
90
|
/** Gets a validation function for a user defined string format */
|
|
128
91
|
function Get(format) {
|
|
129
|
-
return
|
|
92
|
+
return map.get(format);
|
|
130
93
|
}
|
|
131
94
|
FormatRegistry.Get = Get;
|
|
132
95
|
})(FormatRegistry = exports.FormatRegistry || (exports.FormatRegistry = {}));
|
|
@@ -346,18 +309,7 @@ var TypeGuard;
|
|
|
346
309
|
TypeGuard.TLiteral = TLiteral;
|
|
347
310
|
/** Returns true if the given schema is TNever */
|
|
348
311
|
function TNever(schema) {
|
|
349
|
-
return
|
|
350
|
-
// IsArray(schema.allOf) &&
|
|
351
|
-
// schema.allOf.length === 2 &&
|
|
352
|
-
// IsObject(schema.allOf[0]) &&
|
|
353
|
-
// IsString(schema.allOf[0].type) &&
|
|
354
|
-
// schema.allOf[0].type === 'boolean' &&
|
|
355
|
-
// schema.allOf[0].const === false &&
|
|
356
|
-
// IsObject(schema.allOf[1]) &&
|
|
357
|
-
// IsString(schema.allOf[1].type) &&
|
|
358
|
-
// schema.allOf[1].type === 'boolean' &&
|
|
359
|
-
// schema.allOf[1].const === true
|
|
360
|
-
);
|
|
312
|
+
return TKind(schema) && schema[exports.Kind] === 'Never' && IsObject(schema.not) && globalThis.Object.getOwnPropertyNames(schema.not).length === 0;
|
|
361
313
|
}
|
|
362
314
|
TypeGuard.TNever = TNever;
|
|
363
315
|
/** Returns true if the given schema is TNot */
|
|
@@ -621,9 +573,9 @@ var TypeGuard;
|
|
|
621
573
|
// --------------------------------------------------------------------------
|
|
622
574
|
// ExtendsUndefined
|
|
623
575
|
// --------------------------------------------------------------------------
|
|
576
|
+
/** Fast undefined check used for properties of type undefined */
|
|
624
577
|
var ExtendsUndefined;
|
|
625
578
|
(function (ExtendsUndefined) {
|
|
626
|
-
/** Fast undefined check for properties of type undefined */
|
|
627
579
|
function Check(schema) {
|
|
628
580
|
if (schema[exports.Kind] === 'Undefined')
|
|
629
581
|
return true;
|
|
@@ -1307,56 +1259,54 @@ var TypeExtends;
|
|
|
1307
1259
|
return TypeGuard.TVoid(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
1308
1260
|
}
|
|
1309
1261
|
function Visit(left, right) {
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
if (TypeGuard.
|
|
1313
|
-
return
|
|
1314
|
-
if (TypeGuard.
|
|
1315
|
-
return
|
|
1316
|
-
if (TypeGuard.
|
|
1317
|
-
return
|
|
1318
|
-
if (TypeGuard.
|
|
1319
|
-
return
|
|
1320
|
-
if (TypeGuard.
|
|
1321
|
-
return
|
|
1322
|
-
if (TypeGuard.
|
|
1323
|
-
return
|
|
1324
|
-
if (TypeGuard.
|
|
1325
|
-
return
|
|
1326
|
-
if (TypeGuard.
|
|
1327
|
-
return
|
|
1328
|
-
if (TypeGuard.
|
|
1329
|
-
return
|
|
1330
|
-
if (TypeGuard.
|
|
1331
|
-
return
|
|
1332
|
-
if (TypeGuard.
|
|
1333
|
-
return
|
|
1334
|
-
if (TypeGuard.
|
|
1335
|
-
return
|
|
1336
|
-
if (TypeGuard.
|
|
1337
|
-
return
|
|
1338
|
-
if (TypeGuard.
|
|
1339
|
-
return
|
|
1340
|
-
if (TypeGuard.
|
|
1341
|
-
return
|
|
1342
|
-
if (TypeGuard.
|
|
1343
|
-
return
|
|
1344
|
-
if (TypeGuard.
|
|
1345
|
-
return
|
|
1346
|
-
if (TypeGuard.
|
|
1347
|
-
return
|
|
1348
|
-
if (TypeGuard.
|
|
1349
|
-
return
|
|
1350
|
-
if (TypeGuard.
|
|
1351
|
-
return
|
|
1352
|
-
if (TypeGuard.
|
|
1353
|
-
return
|
|
1354
|
-
if (TypeGuard.
|
|
1355
|
-
return
|
|
1356
|
-
if (TypeGuard.
|
|
1357
|
-
return
|
|
1358
|
-
if (TypeGuard.TVoid(left_))
|
|
1359
|
-
return Void(left_, right_);
|
|
1262
|
+
if (TypeGuard.TAny(left))
|
|
1263
|
+
return Any(left, right);
|
|
1264
|
+
if (TypeGuard.TArray(left))
|
|
1265
|
+
return Array(left, right);
|
|
1266
|
+
if (TypeGuard.TBigInt(left))
|
|
1267
|
+
return BigInt(left, right);
|
|
1268
|
+
if (TypeGuard.TBoolean(left))
|
|
1269
|
+
return Boolean(left, right);
|
|
1270
|
+
if (TypeGuard.TConstructor(left))
|
|
1271
|
+
return Constructor(left, right);
|
|
1272
|
+
if (TypeGuard.TDate(left))
|
|
1273
|
+
return Date(left, right);
|
|
1274
|
+
if (TypeGuard.TFunction(left))
|
|
1275
|
+
return Function(left, right);
|
|
1276
|
+
if (TypeGuard.TInteger(left))
|
|
1277
|
+
return Integer(left, right);
|
|
1278
|
+
if (TypeGuard.TIntersect(left))
|
|
1279
|
+
return Intersect(left, right);
|
|
1280
|
+
if (TypeGuard.TLiteral(left))
|
|
1281
|
+
return Literal(left, right);
|
|
1282
|
+
if (TypeGuard.TNever(left))
|
|
1283
|
+
return Never(left, right);
|
|
1284
|
+
if (TypeGuard.TNull(left))
|
|
1285
|
+
return Null(left, right);
|
|
1286
|
+
if (TypeGuard.TNumber(left))
|
|
1287
|
+
return Number(left, right);
|
|
1288
|
+
if (TypeGuard.TRecord(left))
|
|
1289
|
+
return Record(left, right);
|
|
1290
|
+
if (TypeGuard.TString(left))
|
|
1291
|
+
return String(left, right);
|
|
1292
|
+
if (TypeGuard.TSymbol(left))
|
|
1293
|
+
return Symbol(left, right);
|
|
1294
|
+
if (TypeGuard.TObject(left))
|
|
1295
|
+
return Object(left, right);
|
|
1296
|
+
if (TypeGuard.TTuple(left))
|
|
1297
|
+
return Tuple(left, right);
|
|
1298
|
+
if (TypeGuard.TPromise(left))
|
|
1299
|
+
return Promise(left, right);
|
|
1300
|
+
if (TypeGuard.TUint8Array(left))
|
|
1301
|
+
return Uint8Array(left, right);
|
|
1302
|
+
if (TypeGuard.TUndefined(left))
|
|
1303
|
+
return Undefined(left, right);
|
|
1304
|
+
if (TypeGuard.TUnion(left))
|
|
1305
|
+
return Union(left, right);
|
|
1306
|
+
if (TypeGuard.TUnknown(left))
|
|
1307
|
+
return Unknown(left, right);
|
|
1308
|
+
if (TypeGuard.TVoid(left))
|
|
1309
|
+
return Void(left, right);
|
|
1360
1310
|
throw Error(`TypeExtends: Unknown left type operand '${left[exports.Kind]}'`);
|
|
1361
1311
|
}
|
|
1362
1312
|
function Extends(left, right) {
|
|
@@ -1367,14 +1317,11 @@ var TypeExtends;
|
|
|
1367
1317
|
// --------------------------------------------------------------------------
|
|
1368
1318
|
// TypeClone
|
|
1369
1319
|
// --------------------------------------------------------------------------
|
|
1370
|
-
/** Specialized Clone for Types
|
|
1320
|
+
/** Specialized Clone for Types */
|
|
1371
1321
|
var TypeClone;
|
|
1372
1322
|
(function (TypeClone) {
|
|
1373
|
-
function IsRecursive(value) {
|
|
1374
|
-
return typeof value[exports.Recursive] === 'string';
|
|
1375
|
-
}
|
|
1376
1323
|
function IsObject(value) {
|
|
1377
|
-
return typeof value === 'object' && value !== null
|
|
1324
|
+
return typeof value === 'object' && value !== null;
|
|
1378
1325
|
}
|
|
1379
1326
|
function IsArray(value) {
|
|
1380
1327
|
return globalThis.Array.isArray(value);
|
|
@@ -1383,22 +1330,24 @@ var TypeClone;
|
|
|
1383
1330
|
return value.map((value) => Visit(value));
|
|
1384
1331
|
}
|
|
1385
1332
|
function Object(value) {
|
|
1386
|
-
const
|
|
1387
|
-
|
|
1333
|
+
const clonedProperties = globalThis.Object.getOwnPropertyNames(value).reduce((acc, key) => {
|
|
1334
|
+
return { ...acc, [key]: Visit(value[key]) };
|
|
1335
|
+
}, {});
|
|
1336
|
+
const clonedSymbols = globalThis.Object.getOwnPropertySymbols(value).reduce((acc, key) => {
|
|
1337
|
+
return { ...acc, [key]: Visit(value[key]) };
|
|
1338
|
+
}, {});
|
|
1339
|
+
return { ...clonedProperties, ...clonedSymbols };
|
|
1388
1340
|
}
|
|
1389
1341
|
function Visit(value) {
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
if (IsArray(clone))
|
|
1396
|
-
return Array(clone);
|
|
1397
|
-
return clone;
|
|
1342
|
+
if (IsArray(value))
|
|
1343
|
+
return Array(value);
|
|
1344
|
+
if (IsObject(value))
|
|
1345
|
+
return Object(value);
|
|
1346
|
+
return value;
|
|
1398
1347
|
}
|
|
1399
1348
|
/** Clones a type. This function will omit non-self referential identifiers on the cloned type. */
|
|
1400
1349
|
function Clone(schema, options) {
|
|
1401
|
-
return { ...Visit(
|
|
1350
|
+
return { ...Visit(schema), ...options };
|
|
1402
1351
|
}
|
|
1403
1352
|
TypeClone.Clone = Clone;
|
|
1404
1353
|
})(TypeClone = exports.TypeClone || (exports.TypeClone = {}));
|
|
@@ -1408,10 +1357,10 @@ var TypeClone;
|
|
|
1408
1357
|
var ObjectMap;
|
|
1409
1358
|
(function (ObjectMap) {
|
|
1410
1359
|
function Intersect(schema, callback) {
|
|
1411
|
-
return exports.Type.Intersect(schema.allOf.map((inner) => Visit(
|
|
1360
|
+
return exports.Type.Intersect(schema.allOf.map((inner) => Visit(inner, callback)), { ...schema });
|
|
1412
1361
|
}
|
|
1413
1362
|
function Union(schema, callback) {
|
|
1414
|
-
return exports.Type.Union(schema.anyOf.map((inner) => Visit(
|
|
1363
|
+
return exports.Type.Union(schema.anyOf.map((inner) => Visit(inner, callback)), { ...schema });
|
|
1415
1364
|
}
|
|
1416
1365
|
function Object(schema, callback) {
|
|
1417
1366
|
return callback(schema);
|
|
@@ -1472,7 +1421,6 @@ let TypeOrdinal = 0;
|
|
|
1472
1421
|
class TypeBuilder {
|
|
1473
1422
|
/** `[Utility]` Creates a schema without `static` and `params` types */
|
|
1474
1423
|
Create(schema) {
|
|
1475
|
-
ReferenceRegistry.Set(schema);
|
|
1476
1424
|
return schema;
|
|
1477
1425
|
}
|
|
1478
1426
|
/** `[Standard]` Omits compositing symbols from this schema */
|
|
@@ -1515,8 +1463,8 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
1515
1463
|
Boolean(options = {}) {
|
|
1516
1464
|
return this.Create({ ...options, [exports.Kind]: 'Boolean', type: 'boolean' });
|
|
1517
1465
|
}
|
|
1518
|
-
|
|
1519
|
-
|
|
1466
|
+
Composite(unresolved, options = {}) {
|
|
1467
|
+
const schemas = TypeGuard.TIntersect(unresolved) ? unresolved.allOf : unresolved;
|
|
1520
1468
|
const optional = new Set();
|
|
1521
1469
|
for (const schema of schemas) {
|
|
1522
1470
|
for (const [key, property] of globalThis.Object.entries(schema.properties)) {
|
|
@@ -1533,10 +1481,6 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
1533
1481
|
}
|
|
1534
1482
|
return this.Object(properties, options);
|
|
1535
1483
|
}
|
|
1536
|
-
/** `[Standard]` Dereferences the given TRef to its target type */
|
|
1537
|
-
Deref(schema) {
|
|
1538
|
-
return ReferenceRegistry.Deref(schema);
|
|
1539
|
-
}
|
|
1540
1484
|
/** `[Standard]` Creates a Enum type */
|
|
1541
1485
|
Enum(item, options = {}) {
|
|
1542
1486
|
// prettier-ignore
|
|
@@ -1546,7 +1490,7 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
1546
1490
|
}
|
|
1547
1491
|
/** `[Standard]` A conditional type expression that will return the true type if the left type extends the right */
|
|
1548
1492
|
Extends(left, right, trueType, falseType, options = {}) {
|
|
1549
|
-
switch (TypeExtends.Extends(
|
|
1493
|
+
switch (TypeExtends.Extends(left, right)) {
|
|
1550
1494
|
case TypeExtendsResult.Union:
|
|
1551
1495
|
return this.Union([TypeClone.Clone(trueType, options), TypeClone.Clone(falseType, options)]);
|
|
1552
1496
|
case TypeExtendsResult.True:
|
|
@@ -1596,7 +1540,7 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
1596
1540
|
}
|
|
1597
1541
|
/** `[Standard]` Creates a KeyOf type */
|
|
1598
1542
|
KeyOf(schema, options = {}) {
|
|
1599
|
-
const keys = KeyResolver.Resolve(
|
|
1543
|
+
const keys = KeyResolver.Resolve(schema);
|
|
1600
1544
|
// prettier-ignore
|
|
1601
1545
|
const keyof = keys.length === 0 ? this.Never(options) : this.Union(keys.map((key) => this.Literal(key)), options);
|
|
1602
1546
|
return keyof;
|
|
@@ -1623,15 +1567,13 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
1623
1567
|
}
|
|
1624
1568
|
/** `[Standard]` Creates an Object type */
|
|
1625
1569
|
Object(properties, options = {}) {
|
|
1626
|
-
const
|
|
1627
|
-
const
|
|
1628
|
-
const
|
|
1570
|
+
const propertyKeys = globalThis.Object.getOwnPropertyNames(properties);
|
|
1571
|
+
const optionalKeys = propertyKeys.filter((key) => TypeGuard.TOptional(properties[key]) || TypeGuard.TReadonlyOptional(properties[key]));
|
|
1572
|
+
const requiredKeys = propertyKeys.filter((name) => !optionalKeys.includes(name));
|
|
1629
1573
|
const clonedAdditionalProperties = TypeGuard.TSchema(options.additionalProperties) ? { additionalProperties: TypeClone.Clone(options.additionalProperties, {}) } : {};
|
|
1630
|
-
const clonedProperties =
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
if (required.length > 0) {
|
|
1634
|
-
return this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: 'Object', type: 'object', properties: clonedProperties, required });
|
|
1574
|
+
const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: TypeClone.Clone(properties[key], {}) }), {});
|
|
1575
|
+
if (requiredKeys.length > 0) {
|
|
1576
|
+
return this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: 'Object', type: 'object', properties: clonedProperties, required: requiredKeys });
|
|
1635
1577
|
}
|
|
1636
1578
|
else {
|
|
1637
1579
|
return this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: 'Object', type: 'object', properties: clonedProperties });
|
|
@@ -1644,7 +1586,7 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
1644
1586
|
TypeGuard.TNever(unresolved) ? [] :
|
|
1645
1587
|
unresolved;
|
|
1646
1588
|
// prettier-ignore
|
|
1647
|
-
return ObjectMap.Map(TypeClone.Clone(
|
|
1589
|
+
return ObjectMap.Map(TypeClone.Clone(schema, {}), (schema) => {
|
|
1648
1590
|
if (schema.required) {
|
|
1649
1591
|
schema.required = schema.required.filter((key) => !keys.includes(key));
|
|
1650
1592
|
if (schema.required.length === 0)
|
|
@@ -1677,7 +1619,7 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
1677
1619
|
}
|
|
1678
1620
|
}
|
|
1679
1621
|
// prettier-ignore
|
|
1680
|
-
return ObjectMap.Map(TypeClone.Clone(
|
|
1622
|
+
return ObjectMap.Map(TypeClone.Clone(schema, {}), (schema) => {
|
|
1681
1623
|
delete schema.required;
|
|
1682
1624
|
globalThis.Object.keys(schema.properties).forEach(key => Apply(schema.properties[key]));
|
|
1683
1625
|
return schema;
|
|
@@ -1690,7 +1632,7 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
1690
1632
|
TypeGuard.TNever(unresolved) ? [] :
|
|
1691
1633
|
unresolved;
|
|
1692
1634
|
// prettier-ignore
|
|
1693
|
-
return ObjectMap.Map(TypeClone.Clone(
|
|
1635
|
+
return ObjectMap.Map(TypeClone.Clone(schema, {}), (schema) => {
|
|
1694
1636
|
if (schema.required) {
|
|
1695
1637
|
schema.required = schema.required.filter((key) => keys.includes(key));
|
|
1696
1638
|
if (schema.required.length === 0)
|
|
@@ -1733,9 +1675,8 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
1733
1675
|
if (options.$id === undefined)
|
|
1734
1676
|
options.$id = `T${TypeOrdinal++}`;
|
|
1735
1677
|
const self = callback({ [exports.Kind]: 'Self', $ref: `${options.$id}` });
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
return this.Create({ ...options, ...self, [exports.Recursive]: reassign.$id });
|
|
1678
|
+
self.$id = options.$id;
|
|
1679
|
+
return this.Create({ ...options, ...self });
|
|
1739
1680
|
}
|
|
1740
1681
|
/** `[Standard]` Creates a Ref type. The referenced type must contain a $id */
|
|
1741
1682
|
Ref(schema, options = {}) {
|
|
@@ -1763,7 +1704,7 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
1763
1704
|
}
|
|
1764
1705
|
}
|
|
1765
1706
|
// prettier-ignore
|
|
1766
|
-
return ObjectMap.Map(TypeClone.Clone(
|
|
1707
|
+
return ObjectMap.Map(TypeClone.Clone(schema, {}), (schema) => {
|
|
1767
1708
|
schema.required = globalThis.Object.keys(schema.properties);
|
|
1768
1709
|
globalThis.Object.keys(schema.properties).forEach(key => Apply(schema.properties[key]));
|
|
1769
1710
|
return schema;
|
package/value/cast.d.ts
CHANGED
|
@@ -20,7 +20,11 @@ export declare class ValueCastUnknownTypeError extends Error {
|
|
|
20
20
|
readonly schema: Types.TSchema;
|
|
21
21
|
constructor(schema: Types.TSchema);
|
|
22
22
|
}
|
|
23
|
+
export declare class ValueCastDereferenceError extends Error {
|
|
24
|
+
readonly schema: Types.TRef | Types.TSelf;
|
|
25
|
+
constructor(schema: Types.TRef | Types.TSelf);
|
|
26
|
+
}
|
|
23
27
|
export declare namespace ValueCast {
|
|
24
|
-
function Visit(schema: Types.TSchema, value: any): any;
|
|
25
|
-
function Cast<T extends Types.TSchema>(schema: T, value: any): Types.Static<T>;
|
|
28
|
+
function Visit(schema: Types.TSchema, references: Types.TSchema[], value: any): any;
|
|
29
|
+
function Cast<T extends Types.TSchema>(schema: T, references: Types.TSchema[], value: any): Types.Static<T>;
|
|
26
30
|
}
|