@sinclair/typebox 0.26.0-dev.4 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/typebox.js CHANGED
@@ -27,106 +27,70 @@ 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.ReferenceRegistry = exports.TypeRegistry = exports.Kind = exports.Hint = exports.Modifier = exports.Recursive = void 0;
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');
37
+ /** A registry for user defined types */
38
38
  var TypeRegistry;
39
39
  (function (TypeRegistry) {
40
- const types = new Map();
40
+ const map = new Map();
41
+ /** Returns the entries in this registry */
42
+ function Entries() {
43
+ return new Map(map);
44
+ }
45
+ TypeRegistry.Entries = Entries;
41
46
  /** Clears all user defined types */
42
47
  function Clear() {
43
- return types.clear();
48
+ return map.clear();
44
49
  }
45
50
  TypeRegistry.Clear = Clear;
46
51
  /** Returns true if this registry contains this kind */
47
52
  function Has(kind) {
48
- return types.has(kind);
53
+ return map.has(kind);
49
54
  }
50
55
  TypeRegistry.Has = Has;
51
56
  /** Sets a validation function for a user defined type */
52
57
  function Set(kind, func) {
53
- types.set(kind, func);
58
+ map.set(kind, func);
54
59
  }
55
60
  TypeRegistry.Set = Set;
56
61
  /** Gets a custom validation function for a user defined type */
57
62
  function Get(kind) {
58
- return types.get(kind);
63
+ return map.get(kind);
59
64
  }
60
65
  TypeRegistry.Get = Get;
61
66
  })(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
- /** Provides functions to create user defined string formats */
67
+ /** A registry for user defined string formats */
109
68
  var FormatRegistry;
110
69
  (function (FormatRegistry) {
111
- const formats = new Map();
70
+ const map = new Map();
71
+ /** Returns the entries in this registry */
72
+ function Entries() {
73
+ return new Map(map);
74
+ }
75
+ FormatRegistry.Entries = Entries;
112
76
  /** Clears all user defined string formats */
113
77
  function Clear() {
114
- return formats.clear();
78
+ return map.clear();
115
79
  }
116
80
  FormatRegistry.Clear = Clear;
117
81
  /** Returns true if the user defined string format exists */
118
82
  function Has(format) {
119
- return formats.has(format);
83
+ return map.has(format);
120
84
  }
121
85
  FormatRegistry.Has = Has;
122
86
  /** Sets a validation function for a user defined string format */
123
87
  function Set(format, func) {
124
- formats.set(format, func);
88
+ map.set(format, func);
125
89
  }
126
90
  FormatRegistry.Set = Set;
127
91
  /** Gets a validation function for a user defined string format */
128
92
  function Get(format) {
129
- return formats.get(format);
93
+ return map.get(format);
130
94
  }
131
95
  FormatRegistry.Get = Get;
132
96
  })(FormatRegistry = exports.FormatRegistry || (exports.FormatRegistry = {}));
@@ -140,6 +104,7 @@ class TypeGuardUnknownTypeError extends Error {
140
104
  }
141
105
  }
142
106
  exports.TypeGuardUnknownTypeError = TypeGuardUnknownTypeError;
107
+ /** Provides functions to test if JavaScript values are TypeBox types */
143
108
  var TypeGuard;
144
109
  (function (TypeGuard) {
145
110
  function IsObject(value) {
@@ -346,18 +311,7 @@ var TypeGuard;
346
311
  TypeGuard.TLiteral = TLiteral;
347
312
  /** Returns true if the given schema is TNever */
348
313
  function TNever(schema) {
349
- return (TKind(schema) && schema[exports.Kind] === 'Never' && IsObject(schema.not) && globalThis.Object.getOwnPropertyNames(schema.not).length === 0
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
- );
314
+ return TKind(schema) && schema[exports.Kind] === 'Never' && IsObject(schema.not) && globalThis.Object.getOwnPropertyNames(schema.not).length === 0;
361
315
  }
362
316
  TypeGuard.TNever = TNever;
363
317
  /** Returns true if the given schema is TNot */
@@ -621,9 +575,9 @@ var TypeGuard;
621
575
  // --------------------------------------------------------------------------
622
576
  // ExtendsUndefined
623
577
  // --------------------------------------------------------------------------
578
+ /** Fast undefined check used for properties of type undefined */
624
579
  var ExtendsUndefined;
625
580
  (function (ExtendsUndefined) {
626
- /** Fast undefined check for properties of type undefined */
627
581
  function Check(schema) {
628
582
  if (schema[exports.Kind] === 'Undefined')
629
583
  return true;
@@ -1307,56 +1261,54 @@ var TypeExtends;
1307
1261
  return TypeGuard.TVoid(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
1308
1262
  }
1309
1263
  function Visit(left, right) {
1310
- const right_ = ReferenceRegistry.Deref(right);
1311
- const left_ = ReferenceRegistry.Deref(left);
1312
- if (TypeGuard.TAny(left_))
1313
- return Any(left_, right_);
1314
- if (TypeGuard.TArray(left_))
1315
- return Array(left_, right_);
1316
- if (TypeGuard.TBigInt(left_))
1317
- return BigInt(left_, right_);
1318
- if (TypeGuard.TBoolean(left_))
1319
- return Boolean(left_, right_);
1320
- if (TypeGuard.TConstructor(left_))
1321
- return Constructor(left_, right_);
1322
- if (TypeGuard.TDate(left_))
1323
- return Date(left_, right_);
1324
- if (TypeGuard.TFunction(left_))
1325
- return Function(left_, right_);
1326
- if (TypeGuard.TInteger(left_))
1327
- return Integer(left_, right_);
1328
- if (TypeGuard.TIntersect(left_))
1329
- return Intersect(left_, right_);
1330
- if (TypeGuard.TLiteral(left_))
1331
- return Literal(left_, right_);
1332
- if (TypeGuard.TNever(left_))
1333
- return Never(left_, right_);
1334
- if (TypeGuard.TNull(left_))
1335
- return Null(left_, right_);
1336
- if (TypeGuard.TNumber(left_))
1337
- return Number(left_, right_);
1338
- if (TypeGuard.TRecord(left_))
1339
- return Record(left_, right_);
1340
- if (TypeGuard.TString(left_))
1341
- return String(left_, right_);
1342
- if (TypeGuard.TSymbol(left_))
1343
- return Symbol(left_, right_);
1344
- if (TypeGuard.TObject(left_))
1345
- return Object(left_, right_);
1346
- if (TypeGuard.TTuple(left_))
1347
- return Tuple(left_, right_);
1348
- if (TypeGuard.TPromise(left_))
1349
- return Promise(left_, right_);
1350
- if (TypeGuard.TUint8Array(left_))
1351
- return Uint8Array(left_, right_);
1352
- if (TypeGuard.TUndefined(left_))
1353
- return Undefined(left_, right_);
1354
- if (TypeGuard.TUnion(left_))
1355
- return Union(left_, right_);
1356
- if (TypeGuard.TUnknown(left_))
1357
- return Unknown(left_, right_);
1358
- if (TypeGuard.TVoid(left_))
1359
- return Void(left_, right_);
1264
+ if (TypeGuard.TAny(left))
1265
+ return Any(left, right);
1266
+ if (TypeGuard.TArray(left))
1267
+ return Array(left, right);
1268
+ if (TypeGuard.TBigInt(left))
1269
+ return BigInt(left, right);
1270
+ if (TypeGuard.TBoolean(left))
1271
+ return Boolean(left, right);
1272
+ if (TypeGuard.TConstructor(left))
1273
+ return Constructor(left, right);
1274
+ if (TypeGuard.TDate(left))
1275
+ return Date(left, right);
1276
+ if (TypeGuard.TFunction(left))
1277
+ return Function(left, right);
1278
+ if (TypeGuard.TInteger(left))
1279
+ return Integer(left, right);
1280
+ if (TypeGuard.TIntersect(left))
1281
+ return Intersect(left, right);
1282
+ if (TypeGuard.TLiteral(left))
1283
+ return Literal(left, right);
1284
+ if (TypeGuard.TNever(left))
1285
+ return Never(left, right);
1286
+ if (TypeGuard.TNull(left))
1287
+ return Null(left, right);
1288
+ if (TypeGuard.TNumber(left))
1289
+ return Number(left, right);
1290
+ if (TypeGuard.TRecord(left))
1291
+ return Record(left, right);
1292
+ if (TypeGuard.TString(left))
1293
+ return String(left, right);
1294
+ if (TypeGuard.TSymbol(left))
1295
+ return Symbol(left, right);
1296
+ if (TypeGuard.TObject(left))
1297
+ return Object(left, right);
1298
+ if (TypeGuard.TTuple(left))
1299
+ return Tuple(left, right);
1300
+ if (TypeGuard.TPromise(left))
1301
+ return Promise(left, right);
1302
+ if (TypeGuard.TUint8Array(left))
1303
+ return Uint8Array(left, right);
1304
+ if (TypeGuard.TUndefined(left))
1305
+ return Undefined(left, right);
1306
+ if (TypeGuard.TUnion(left))
1307
+ return Union(left, right);
1308
+ if (TypeGuard.TUnknown(left))
1309
+ return Unknown(left, right);
1310
+ if (TypeGuard.TVoid(left))
1311
+ return Void(left, right);
1360
1312
  throw Error(`TypeExtends: Unknown left type operand '${left[exports.Kind]}'`);
1361
1313
  }
1362
1314
  function Extends(left, right) {
@@ -1367,14 +1319,11 @@ var TypeExtends;
1367
1319
  // --------------------------------------------------------------------------
1368
1320
  // TypeClone
1369
1321
  // --------------------------------------------------------------------------
1370
- /** Specialized Clone for Types. Clones and removes non self-referential identifiers */
1322
+ /** Specialized Clone for Types */
1371
1323
  var TypeClone;
1372
1324
  (function (TypeClone) {
1373
- function IsRecursive(value) {
1374
- return typeof value[exports.Recursive] === 'string';
1375
- }
1376
1325
  function IsObject(value) {
1377
- return typeof value === 'object' && value !== null && !globalThis.Array.isArray(value);
1326
+ return typeof value === 'object' && value !== null;
1378
1327
  }
1379
1328
  function IsArray(value) {
1380
1329
  return globalThis.Array.isArray(value);
@@ -1383,22 +1332,24 @@ var TypeClone;
1383
1332
  return value.map((value) => Visit(value));
1384
1333
  }
1385
1334
  function Object(value) {
1386
- const clone = globalThis.Object.getOwnPropertyNames(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), globalThis.Object.getOwnPropertySymbols(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), {}));
1387
- return clone;
1335
+ const clonedProperties = globalThis.Object.getOwnPropertyNames(value).reduce((acc, key) => {
1336
+ return { ...acc, [key]: Visit(value[key]) };
1337
+ }, {});
1338
+ const clonedSymbols = globalThis.Object.getOwnPropertySymbols(value).reduce((acc, key) => {
1339
+ return { ...acc, [key]: Visit(value[key]) };
1340
+ }, {});
1341
+ return { ...clonedProperties, ...clonedSymbols };
1388
1342
  }
1389
1343
  function Visit(value) {
1390
- const clone = IsObject(value) ? { ...value } : IsArray(value) ? [...value] : value;
1391
- if (IsObject(clone) && !IsRecursive(clone))
1392
- delete clone['$id'];
1393
- if (IsObject(clone))
1394
- return Object(clone);
1395
- if (IsArray(clone))
1396
- return Array(clone);
1397
- return clone;
1344
+ if (IsArray(value))
1345
+ return Array(value);
1346
+ if (IsObject(value))
1347
+ return Object(value);
1348
+ return value;
1398
1349
  }
1399
1350
  /** Clones a type. This function will omit non-self referential identifiers on the cloned type. */
1400
1351
  function Clone(schema, options) {
1401
- return { ...Visit({ ...schema }), ...options };
1352
+ return { ...Visit(schema), ...options };
1402
1353
  }
1403
1354
  TypeClone.Clone = Clone;
1404
1355
  })(TypeClone = exports.TypeClone || (exports.TypeClone = {}));
@@ -1408,10 +1359,10 @@ var TypeClone;
1408
1359
  var ObjectMap;
1409
1360
  (function (ObjectMap) {
1410
1361
  function Intersect(schema, callback) {
1411
- return exports.Type.Intersect(schema.allOf.map((inner) => Visit(ReferenceRegistry.Deref(inner), callback)), { ...schema });
1362
+ return exports.Type.Intersect(schema.allOf.map((inner) => Visit(inner, callback)), { ...schema });
1412
1363
  }
1413
1364
  function Union(schema, callback) {
1414
- return exports.Type.Union(schema.anyOf.map((inner) => Visit(ReferenceRegistry.Deref(inner), callback)), { ...schema });
1365
+ return exports.Type.Union(schema.anyOf.map((inner) => Visit(inner, callback)), { ...schema });
1415
1366
  }
1416
1367
  function Object(schema, callback) {
1417
1368
  return callback(schema);
@@ -1472,7 +1423,6 @@ let TypeOrdinal = 0;
1472
1423
  class TypeBuilder {
1473
1424
  /** `[Utility]` Creates a schema without `static` and `params` types */
1474
1425
  Create(schema) {
1475
- ReferenceRegistry.Set(schema);
1476
1426
  return schema;
1477
1427
  }
1478
1428
  /** `[Standard]` Omits compositing symbols from this schema */
@@ -1515,28 +1465,16 @@ class StandardTypeBuilder extends TypeBuilder {
1515
1465
  Boolean(options = {}) {
1516
1466
  return this.Create({ ...options, [exports.Kind]: 'Boolean', type: 'boolean' });
1517
1467
  }
1518
- /** `[Standard]` Creates a Composite object type that will Union any overlapping properties of the given Object array */
1519
- Composite(schemas, options = {}) {
1520
- const optional = new Set();
1521
- for (const schema of schemas) {
1522
- for (const [key, property] of globalThis.Object.entries(schema.properties)) {
1523
- if (TypeGuard.TOptional(property) || TypeGuard.TReadonlyOptional(property))
1524
- optional.add(key);
1525
- }
1526
- }
1468
+ /** `[Standard]` Creates a Composite object type that will union any overlapping properties of the given object array */
1469
+ Composite(schemas, options) {
1527
1470
  const properties = {};
1528
1471
  for (const object of schemas) {
1529
1472
  for (const [key, property] of globalThis.Object.entries(object.properties)) {
1530
- const mapped = key in properties ? this.Union([properties[key], property]) : TypeClone.Clone(property, {});
1531
- properties[key] = optional.has(key) ? this.Optional(mapped) : mapped;
1473
+ properties[key] = key in properties ? this.Union([properties[key], property]) : TypeClone.Clone(property, {});
1532
1474
  }
1533
1475
  }
1534
1476
  return this.Object(properties, options);
1535
1477
  }
1536
- /** `[Standard]` Dereferences the given TRef to its target type */
1537
- Deref(schema) {
1538
- return ReferenceRegistry.Deref(schema);
1539
- }
1540
1478
  /** `[Standard]` Creates a Enum type */
1541
1479
  Enum(item, options = {}) {
1542
1480
  // prettier-ignore
@@ -1546,7 +1484,7 @@ class StandardTypeBuilder extends TypeBuilder {
1546
1484
  }
1547
1485
  /** `[Standard]` A conditional type expression that will return the true type if the left type extends the right */
1548
1486
  Extends(left, right, trueType, falseType, options = {}) {
1549
- switch (TypeExtends.Extends(ReferenceRegistry.Deref(left), ReferenceRegistry.Deref(right))) {
1487
+ switch (TypeExtends.Extends(left, right)) {
1550
1488
  case TypeExtendsResult.Union:
1551
1489
  return this.Union([TypeClone.Clone(trueType, options), TypeClone.Clone(falseType, options)]);
1552
1490
  case TypeExtendsResult.True:
@@ -1596,7 +1534,7 @@ class StandardTypeBuilder extends TypeBuilder {
1596
1534
  }
1597
1535
  /** `[Standard]` Creates a KeyOf type */
1598
1536
  KeyOf(schema, options = {}) {
1599
- const keys = KeyResolver.Resolve(ReferenceRegistry.Deref(schema));
1537
+ const keys = KeyResolver.Resolve(schema);
1600
1538
  // prettier-ignore
1601
1539
  const keyof = keys.length === 0 ? this.Never(options) : this.Union(keys.map((key) => this.Literal(key)), options);
1602
1540
  return keyof;
@@ -1623,15 +1561,13 @@ class StandardTypeBuilder extends TypeBuilder {
1623
1561
  }
1624
1562
  /** `[Standard]` Creates an Object type */
1625
1563
  Object(properties, options = {}) {
1626
- const keys = globalThis.Object.keys(properties);
1627
- const optional = keys.filter((key) => TypeGuard.TOptional(properties[key]) || TypeGuard.TReadonlyOptional(properties[key]));
1628
- const required = keys.filter((name) => !optional.includes(name));
1564
+ const propertyKeys = globalThis.Object.getOwnPropertyNames(properties);
1565
+ const optionalKeys = propertyKeys.filter((key) => TypeGuard.TOptional(properties[key]) || TypeGuard.TReadonlyOptional(properties[key]));
1566
+ const requiredKeys = propertyKeys.filter((name) => !optionalKeys.includes(name));
1629
1567
  const clonedAdditionalProperties = TypeGuard.TSchema(options.additionalProperties) ? { additionalProperties: TypeClone.Clone(options.additionalProperties, {}) } : {};
1630
- const clonedProperties = globalThis.Object.getOwnPropertyNames(properties).reduce((acc, key) => {
1631
- return { ...acc, [key]: TypeClone.Clone(properties[key], {}) };
1632
- }, {});
1633
- if (required.length > 0) {
1634
- return this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: 'Object', type: 'object', properties: clonedProperties, required });
1568
+ const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: TypeClone.Clone(properties[key], {}) }), {});
1569
+ if (requiredKeys.length > 0) {
1570
+ return this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: 'Object', type: 'object', properties: clonedProperties, required: requiredKeys });
1635
1571
  }
1636
1572
  else {
1637
1573
  return this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: 'Object', type: 'object', properties: clonedProperties });
@@ -1644,7 +1580,7 @@ class StandardTypeBuilder extends TypeBuilder {
1644
1580
  TypeGuard.TNever(unresolved) ? [] :
1645
1581
  unresolved;
1646
1582
  // prettier-ignore
1647
- return ObjectMap.Map(TypeClone.Clone(ReferenceRegistry.Deref(schema), {}), (schema) => {
1583
+ return ObjectMap.Map(TypeClone.Clone(schema, {}), (schema) => {
1648
1584
  if (schema.required) {
1649
1585
  schema.required = schema.required.filter((key) => !keys.includes(key));
1650
1586
  if (schema.required.length === 0)
@@ -1677,7 +1613,7 @@ class StandardTypeBuilder extends TypeBuilder {
1677
1613
  }
1678
1614
  }
1679
1615
  // prettier-ignore
1680
- return ObjectMap.Map(TypeClone.Clone(ReferenceRegistry.Deref(schema), {}), (schema) => {
1616
+ return ObjectMap.Map(TypeClone.Clone(schema, {}), (schema) => {
1681
1617
  delete schema.required;
1682
1618
  globalThis.Object.keys(schema.properties).forEach(key => Apply(schema.properties[key]));
1683
1619
  return schema;
@@ -1690,7 +1626,7 @@ class StandardTypeBuilder extends TypeBuilder {
1690
1626
  TypeGuard.TNever(unresolved) ? [] :
1691
1627
  unresolved;
1692
1628
  // prettier-ignore
1693
- return ObjectMap.Map(TypeClone.Clone(ReferenceRegistry.Deref(schema), {}), (schema) => {
1629
+ return ObjectMap.Map(TypeClone.Clone(schema, {}), (schema) => {
1694
1630
  if (schema.required) {
1695
1631
  schema.required = schema.required.filter((key) => keys.includes(key));
1696
1632
  if (schema.required.length === 0)
@@ -1733,9 +1669,8 @@ class StandardTypeBuilder extends TypeBuilder {
1733
1669
  if (options.$id === undefined)
1734
1670
  options.$id = `T${TypeOrdinal++}`;
1735
1671
  const self = callback({ [exports.Kind]: 'Self', $ref: `${options.$id}` });
1736
- const reassign = self;
1737
- reassign.$id = options.$id; // required as $id is readonly
1738
- return this.Create({ ...options, ...self, [exports.Recursive]: reassign.$id });
1672
+ self.$id = options.$id;
1673
+ return this.Create({ ...options, ...self });
1739
1674
  }
1740
1675
  /** `[Standard]` Creates a Ref type. The referenced type must contain a $id */
1741
1676
  Ref(schema, options = {}) {
@@ -1763,7 +1698,7 @@ class StandardTypeBuilder extends TypeBuilder {
1763
1698
  }
1764
1699
  }
1765
1700
  // prettier-ignore
1766
- return ObjectMap.Map(TypeClone.Clone(ReferenceRegistry.Deref(schema), {}), (schema) => {
1701
+ return ObjectMap.Map(TypeClone.Clone(schema, {}), (schema) => {
1767
1702
  schema.required = globalThis.Object.keys(schema.properties);
1768
1703
  globalThis.Object.keys(schema.properties).forEach(key => Apply(schema.properties[key]));
1769
1704
  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
  }