@sinclair/typebox 0.27.7 → 0.28.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,7 +27,7 @@ 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.TemplateLiteralGenerator = exports.TemplateLiteralFinite = exports.TemplateLiteralParser = exports.TemplateLiteralParserError = exports.TemplateLiteralResolver = exports.TemplateLiteralPattern = exports.KeyResolver = exports.ObjectMap = exports.TypeClone = exports.TypeExtends = exports.TypeExtendsResult = exports.ExtendsUndefined = exports.TypeGuard = exports.TypeGuardUnknownTypeError = exports.FormatRegistry = exports.TypeRegistry = exports.PatternStringExact = exports.PatternNumberExact = exports.PatternBooleanExact = exports.PatternString = exports.PatternNumber = exports.PatternBoolean = exports.Kind = exports.Hint = exports.Modifier = void 0;
30
+ exports.Type = exports.StandardType = exports.ExtendedTypeBuilder = exports.StandardTypeBuilder = exports.TypeBuilder = exports.TemplateLiteralGenerator = exports.TemplateLiteralFinite = exports.TemplateLiteralParser = exports.TemplateLiteralParserError = exports.TemplateLiteralResolver = exports.TemplateLiteralPattern = exports.KeyArrayResolver = exports.KeyResolver = exports.ObjectMap = exports.IndexedAccessor = exports.TypeClone = exports.TypeExtends = exports.TypeExtendsResult = exports.ExtendsUndefined = exports.TypeGuard = exports.TypeGuardUnknownTypeError = exports.FormatRegistry = exports.TypeRegistry = exports.PatternStringExact = exports.PatternNumberExact = exports.PatternBooleanExact = exports.PatternString = exports.PatternNumber = exports.PatternBoolean = exports.Kind = exports.Hint = exports.Modifier = void 0;
31
31
  // --------------------------------------------------------------------------
32
32
  // Symbols
33
33
  // --------------------------------------------------------------------------
@@ -142,6 +142,9 @@ var TypeGuard;
142
142
  }
143
143
  return true;
144
144
  }
145
+ function IsAdditionalProperties(value) {
146
+ return IsOptionalBoolean(value) || TSchema(value);
147
+ }
145
148
  function IsBigInt(value) {
146
149
  return typeof value === 'bigint';
147
150
  }
@@ -306,16 +309,29 @@ var TypeGuard;
306
309
  return IsObject(schema) && exports.Kind in schema && typeof schema[exports.Kind] === 'string'; // TS 4.1.5: any required for symbol indexer
307
310
  }
308
311
  TypeGuard.TKind = TKind;
312
+ /** Returns true if the given schema is TLiteral<string> */
313
+ function TLiteralString(schema) {
314
+ return TKind(schema) && schema[exports.Kind] === 'Literal' && IsOptionalString(schema.$id) && typeof schema.const === 'string';
315
+ }
316
+ TypeGuard.TLiteralString = TLiteralString;
317
+ /** Returns true if the given schema is TLiteral<number> */
318
+ function TLiteralNumber(schema) {
319
+ return TKind(schema) && schema[exports.Kind] === 'Literal' && IsOptionalString(schema.$id) && typeof schema.const === 'number';
320
+ }
321
+ TypeGuard.TLiteralNumber = TLiteralNumber;
322
+ /** Returns true if the given schema is TLiteral<boolean> */
323
+ function TLiteralBoolean(schema) {
324
+ return TKind(schema) && schema[exports.Kind] === 'Literal' && IsOptionalString(schema.$id) && typeof schema.const === 'boolean';
325
+ }
326
+ TypeGuard.TLiteralBoolean = TLiteralBoolean;
327
+ /** Returns true if the given schema is TUnion<Literal<string>[]> */
328
+ function TLiteralUnion(schema) {
329
+ return TUnion(schema) && schema.anyOf.every((schema) => TLiteral(schema));
330
+ }
331
+ TypeGuard.TLiteralUnion = TLiteralUnion;
309
332
  /** Returns true if the given schema is TLiteral */
310
333
  function TLiteral(schema) {
311
- // prettier-ignore
312
- return (TKind(schema) &&
313
- schema[exports.Kind] === 'Literal' &&
314
- IsOptionalString(schema.$id) &&
315
- (IsString(schema.const) ||
316
- IsNumber(schema.const) ||
317
- IsBoolean(schema.const) ||
318
- IsBigInt(schema.const)));
334
+ return TLiteralString(schema) || TLiteralNumber(schema) || TLiteralBoolean(schema);
319
335
  }
320
336
  TypeGuard.TLiteral = TLiteral;
321
337
  /** Returns true if the given schema is TNever */
@@ -364,7 +380,7 @@ var TypeGuard;
364
380
  schema.type === 'object' &&
365
381
  IsOptionalString(schema.$id) &&
366
382
  IsObject(schema.properties) &&
367
- (IsOptionalBoolean(schema.additionalProperties) || IsOptionalSchema(schema.additionalProperties)) &&
383
+ IsAdditionalProperties(schema.additionalProperties) &&
368
384
  IsOptionalNumber(schema.minProperties) &&
369
385
  IsOptionalNumber(schema.maxProperties))) {
370
386
  return false;
@@ -396,7 +412,7 @@ var TypeGuard;
396
412
  schema[exports.Kind] === 'Record' &&
397
413
  schema.type === 'object' &&
398
414
  IsOptionalString(schema.$id) &&
399
- schema.additionalProperties === false &&
415
+ IsAdditionalProperties(schema.additionalProperties) &&
400
416
  IsObject(schema.patternProperties))) {
401
417
  return false;
402
418
  }
@@ -515,11 +531,6 @@ var TypeGuard;
515
531
  return true;
516
532
  }
517
533
  TypeGuard.TUnion = TUnion;
518
- /** Returns true if the given schema is TUnion<Literal<string>[]> */
519
- function TUnionLiteral(schema) {
520
- return TUnion(schema) && schema.anyOf.every((schema) => TLiteral(schema) && typeof schema.const === 'string');
521
- }
522
- TypeGuard.TUnionLiteral = TUnionLiteral;
523
534
  /** Returns true if the given schema is TUint8Array */
524
535
  function TUint8Array(schema) {
525
536
  return TKind(schema) && schema[exports.Kind] === 'Uint8Array' && schema.type === 'object' && IsOptionalString(schema.$id) && schema.instanceOf === 'Uint8Array' && IsOptionalNumber(schema.minByteLength) && IsOptionalNumber(schema.maxByteLength);
@@ -1290,12 +1301,12 @@ var TypeExtends;
1290
1301
  return TypeGuard.TVoid(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
1291
1302
  }
1292
1303
  function Visit(left, right) {
1293
- // template union remap
1304
+ // Template Literal Union Unwrap
1294
1305
  if (TypeGuard.TTemplateLiteral(left))
1295
1306
  return Visit(TemplateLiteralResolver.Resolve(left), right);
1296
1307
  if (TypeGuard.TTemplateLiteral(right))
1297
1308
  return Visit(left, TemplateLiteralResolver.Resolve(right));
1298
- // standard extends
1309
+ // Standard Extends
1299
1310
  if (TypeGuard.TAny(left))
1300
1311
  return Any(left, right);
1301
1312
  if (TypeGuard.TArray(left))
@@ -1389,25 +1400,66 @@ var TypeClone;
1389
1400
  TypeClone.Clone = Clone;
1390
1401
  })(TypeClone = exports.TypeClone || (exports.TypeClone = {}));
1391
1402
  // --------------------------------------------------------------------------
1403
+ // IndexedAccessor
1404
+ // --------------------------------------------------------------------------
1405
+ var IndexedAccessor;
1406
+ (function (IndexedAccessor) {
1407
+ function Intersect(schema, key) {
1408
+ return schema.allOf.reduce((acc, schema) => [...acc, ...Visit(schema, key)], []);
1409
+ }
1410
+ function Union(schema, key) {
1411
+ return schema.anyOf.reduce((acc, schema) => [...acc, ...Visit(schema, key)], []);
1412
+ }
1413
+ function Object(schema, key) {
1414
+ const keys = globalThis.Object.getOwnPropertyNames(schema.properties).filter((k) => k === key);
1415
+ return keys.map((key) => schema.properties[key]);
1416
+ }
1417
+ function Tuple(schema, key) {
1418
+ const items = schema.items === undefined ? [] : schema.items;
1419
+ return items.filter((_, index) => index.toString() === key.toString());
1420
+ }
1421
+ function Visit(schema, key) {
1422
+ if (schema[exports.Kind] === 'Intersect')
1423
+ return Intersect(schema, key);
1424
+ if (schema[exports.Kind] === 'Union')
1425
+ return Union(schema, key);
1426
+ if (schema[exports.Kind] === 'Object')
1427
+ return Object(schema, key);
1428
+ if (schema[exports.Kind] === 'Tuple')
1429
+ return Tuple(schema, key);
1430
+ return [];
1431
+ }
1432
+ function Resolve(schema, keys) {
1433
+ return keys.reduce((acc, key) => [...acc, ...Visit(schema, key)], []);
1434
+ }
1435
+ IndexedAccessor.Resolve = Resolve;
1436
+ })(IndexedAccessor = exports.IndexedAccessor || (exports.IndexedAccessor = {}));
1437
+ // --------------------------------------------------------------------------
1392
1438
  // ObjectMap
1393
1439
  // --------------------------------------------------------------------------
1394
1440
  var ObjectMap;
1395
1441
  (function (ObjectMap) {
1396
1442
  function Intersect(schema, callback) {
1443
+ // prettier-ignore
1397
1444
  return exports.Type.Intersect(schema.allOf.map((inner) => Visit(inner, callback)), { ...schema });
1398
1445
  }
1399
1446
  function Union(schema, callback) {
1447
+ // prettier-ignore
1400
1448
  return exports.Type.Union(schema.anyOf.map((inner) => Visit(inner, callback)), { ...schema });
1401
1449
  }
1402
1450
  function Object(schema, callback) {
1403
1451
  return callback(schema);
1404
1452
  }
1405
1453
  function Visit(schema, callback) {
1406
- if (TypeGuard.TIntersect(schema))
1454
+ // There are cases where users need to map objects with unregistered kinds. Using a TypeGuard here would
1455
+ // prevent sub schema mapping as unregistered kinds will not pass TSchema checks. This is notable in the
1456
+ // case of TObject where unregistered property kinds cause the TObject check to fail. As mapping is only
1457
+ // used for composition, we use explicit checks instead.
1458
+ if (schema[exports.Kind] === 'Intersect')
1407
1459
  return Intersect(schema, callback);
1408
- if (TypeGuard.TUnion(schema))
1460
+ if (schema[exports.Kind] === 'Union')
1409
1461
  return Union(schema, callback);
1410
- if (TypeGuard.TObject(schema))
1462
+ if (schema[exports.Kind] === 'Object')
1411
1463
  return Object(schema, callback);
1412
1464
  return schema;
1413
1465
  }
@@ -1416,39 +1468,72 @@ var ObjectMap;
1416
1468
  }
1417
1469
  ObjectMap.Map = Map;
1418
1470
  })(ObjectMap = exports.ObjectMap || (exports.ObjectMap = {}));
1419
- // --------------------------------------------------------------------------
1420
- // KeyResolver
1421
- // --------------------------------------------------------------------------
1422
1471
  var KeyResolver;
1423
1472
  (function (KeyResolver) {
1424
- function IsKeyable(schema) {
1425
- return TypeGuard.TIntersect(schema) || TypeGuard.TUnion(schema) || (TypeGuard.TObject(schema) && globalThis.Object.getOwnPropertyNames(schema.properties).length > 0);
1473
+ function UnwrapPattern(key) {
1474
+ return key[0] === '^' && key[key.length - 1] === '$' ? key.slice(1, key.length - 1) : key;
1426
1475
  }
1427
- function Intersect(schema) {
1428
- return [...schema.allOf.filter((schema) => IsKeyable(schema)).reduce((set, schema) => Visit(schema).map((key) => set.add(key))[0], new Set())];
1476
+ function Intersect(schema, options) {
1477
+ return schema.allOf.reduce((acc, schema) => [...acc, ...Visit(schema, options)], []);
1429
1478
  }
1430
- function Union(schema) {
1431
- const sets = schema.anyOf.filter((schema) => IsKeyable(schema)).map((inner) => Visit(inner));
1479
+ function Union(schema, options) {
1480
+ const sets = schema.anyOf.map((inner) => Visit(inner, options));
1432
1481
  return [...sets.reduce((set, outer) => outer.map((key) => (sets.every((inner) => inner.includes(key)) ? set.add(key) : set))[0], new Set())];
1433
1482
  }
1434
- function Object(schema) {
1483
+ function Object(schema, options) {
1435
1484
  return globalThis.Object.keys(schema.properties);
1436
1485
  }
1437
- function Visit(schema) {
1486
+ function Record(schema, options) {
1487
+ return options.includePatterns ? globalThis.Object.keys(schema.patternProperties) : [];
1488
+ }
1489
+ function Visit(schema, options) {
1438
1490
  if (TypeGuard.TIntersect(schema))
1439
- return Intersect(schema);
1491
+ return Intersect(schema, options);
1440
1492
  if (TypeGuard.TUnion(schema))
1441
- return Union(schema);
1493
+ return Union(schema, options);
1442
1494
  if (TypeGuard.TObject(schema))
1443
- return Object(schema);
1495
+ return Object(schema, options);
1496
+ if (TypeGuard.TRecord(schema))
1497
+ return Record(schema, options);
1444
1498
  return [];
1445
1499
  }
1446
- function Resolve(schema) {
1447
- return Visit(schema);
1500
+ /** Resolves an array of keys in this schema */
1501
+ function ResolveKeys(schema, options) {
1502
+ return [...new Set(Visit(schema, options))];
1503
+ }
1504
+ KeyResolver.ResolveKeys = ResolveKeys;
1505
+ /** Resolves a regular expression pattern matching all keys in this schema */
1506
+ function ResolvePattern(schema) {
1507
+ const keys = ResolveKeys(schema, { includePatterns: true });
1508
+ const pattern = keys.map((key) => `(${UnwrapPattern(key)})`);
1509
+ return `^(${pattern.join('|')})$`;
1448
1510
  }
1449
- KeyResolver.Resolve = Resolve;
1511
+ KeyResolver.ResolvePattern = ResolvePattern;
1450
1512
  })(KeyResolver = exports.KeyResolver || (exports.KeyResolver = {}));
1451
1513
  // --------------------------------------------------------------------------
1514
+ // KeyArrayResolver
1515
+ // --------------------------------------------------------------------------
1516
+ var KeyArrayResolver;
1517
+ (function (KeyArrayResolver) {
1518
+ /** Resolves an array of string[] keys from the given schema or array type. */
1519
+ function Resolve(schema) {
1520
+ if (globalThis.Array.isArray(schema))
1521
+ return schema;
1522
+ if (TypeGuard.TLiteralUnion(schema))
1523
+ return schema.anyOf.map((schema) => schema.const);
1524
+ if (TypeGuard.TLiteral(schema))
1525
+ return [schema.const];
1526
+ if (TypeGuard.TTemplateLiteral(schema)) {
1527
+ const expression = TemplateLiteralParser.ParseExact(schema.pattern);
1528
+ if (!TemplateLiteralFinite.Check(expression))
1529
+ throw Error('KeyArrayResolver: Cannot resolve keys from infinite template expression');
1530
+ return [...TemplateLiteralGenerator.Generate(expression)];
1531
+ }
1532
+ return [];
1533
+ }
1534
+ KeyArrayResolver.Resolve = Resolve;
1535
+ })(KeyArrayResolver = exports.KeyArrayResolver || (exports.KeyArrayResolver = {}));
1536
+ // --------------------------------------------------------------------------
1452
1537
  // TemplateLiteralPattern
1453
1538
  // --------------------------------------------------------------------------
1454
1539
  var TemplateLiteralPattern;
@@ -1500,6 +1585,7 @@ var TemplateLiteralPattern;
1500
1585
  // --------------------------------------------------------------------------------------
1501
1586
  var TemplateLiteralResolver;
1502
1587
  (function (TemplateLiteralResolver) {
1588
+ /** Resolves a template literal as a TUnion */
1503
1589
  function Resolve(template) {
1504
1590
  const expression = TemplateLiteralParser.ParseExact(template.pattern);
1505
1591
  if (!TemplateLiteralFinite.Check(expression))
@@ -1805,23 +1891,21 @@ class StandardTypeBuilder extends TypeBuilder {
1805
1891
  if (!optional.has(key))
1806
1892
  delete property[exports.Modifier];
1807
1893
  if (key in properties) {
1808
- const left = TypeExtends.Extends(properties[key], property) !== TypeExtendsResult.False;
1809
- const right = TypeExtends.Extends(property, properties[key]) !== TypeExtendsResult.False;
1810
- if (!left && !right)
1811
- properties[key] = exports.Type.Never();
1812
- if (!left && right)
1813
- properties[key] = property;
1894
+ properties[key] = TypeGuard.TIntersect(properties[key]) ? this.Intersect([...properties[key].allOf, property]) : this.Intersect([properties[key], property]);
1814
1895
  }
1815
1896
  else {
1816
1897
  properties[key] = property;
1817
1898
  }
1818
1899
  }
1819
1900
  }
1901
+ for (const key of globalThis.Object.getOwnPropertyNames(properties)) {
1902
+ properties[key] = optional.has(key) ? this.Optional(properties[key]) : properties[key];
1903
+ }
1820
1904
  if (required.size > 0) {
1821
- return this.Create({ ...options, [exports.Kind]: 'Object', [exports.Hint]: 'Composite', type: 'object', properties, required: [...required] });
1905
+ return this.Create({ ...options, [exports.Kind]: 'Object', type: 'object', properties, required: [...required] });
1822
1906
  }
1823
1907
  else {
1824
- return this.Create({ ...options, [exports.Kind]: 'Object', [exports.Hint]: 'Composite', type: 'object', properties });
1908
+ return this.Create({ ...options, [exports.Kind]: 'Object', type: 'object', properties });
1825
1909
  }
1826
1910
  }
1827
1911
  /** `[Standard]` Creates a Enum type */
@@ -1870,6 +1954,16 @@ class StandardTypeBuilder extends TypeBuilder {
1870
1954
  return (TypeExtends.Extends(left, right) !== TypeExtendsResult.False ? TypeClone.Clone(left, options) : this.Never(options));
1871
1955
  }
1872
1956
  }
1957
+ /** `[Standard]` Returns indexed property types for the given keys */
1958
+ Index(schema, unresolved, options = {}) {
1959
+ const keys = KeyArrayResolver.Resolve(unresolved);
1960
+ if (TypeGuard.TArray(schema) && TypeGuard.TNumber(unresolved)) {
1961
+ return TypeClone.Clone(schema.items, options);
1962
+ }
1963
+ const resolved = IndexedAccessor.Resolve(schema, keys);
1964
+ const cloned = resolved.map((schema) => TypeClone.Clone(schema, {}));
1965
+ return this.Union(cloned, options);
1966
+ }
1873
1967
  /** `[Standard]` Creates an Integer type */
1874
1968
  Integer(options = {}) {
1875
1969
  return this.Create({ ...options, [exports.Kind]: 'Integer', type: 'integer' });
@@ -1899,11 +1993,19 @@ class StandardTypeBuilder extends TypeBuilder {
1899
1993
  return this.String(options);
1900
1994
  throw Error('StandardTypeBuilder: Unable to resolve key type from Record key pattern');
1901
1995
  }
1996
+ else if (TypeGuard.TTuple(schema)) {
1997
+ const items = schema.items === undefined ? [] : schema.items;
1998
+ const literals = items.map((_, index) => exports.Type.Literal(index));
1999
+ return this.Union(literals, options);
2000
+ }
2001
+ else if (TypeGuard.TArray(schema)) {
2002
+ return this.Number(options);
2003
+ }
1902
2004
  else {
1903
- const resolved = KeyResolver.Resolve(schema);
1904
- if (resolved.length === 0)
2005
+ const keys = KeyResolver.ResolveKeys(schema, { includePatterns: false });
2006
+ if (keys.length === 0)
1905
2007
  return this.Never(options);
1906
- const literals = resolved.map((key) => this.Literal(key));
2008
+ const literals = keys.map((key) => this.Literal(key));
1907
2009
  return this.Union(literals, options);
1908
2010
  }
1909
2011
  }
@@ -1942,11 +2044,7 @@ class StandardTypeBuilder extends TypeBuilder {
1942
2044
  }
1943
2045
  }
1944
2046
  Omit(schema, unresolved, options = {}) {
1945
- // prettier-ignore
1946
- const keys = TypeGuard.TUnionLiteral(unresolved) ? unresolved.anyOf.map((schema) => schema.const) :
1947
- TypeGuard.TLiteral(unresolved) ? [unresolved.const] :
1948
- TypeGuard.TNever(unresolved) ? [] :
1949
- unresolved;
2047
+ const keys = KeyArrayResolver.Resolve(unresolved);
1950
2048
  // prettier-ignore
1951
2049
  return ObjectMap.Map(TypeClone.Clone(schema, {}), (schema) => {
1952
2050
  if (schema.required) {
@@ -1988,11 +2086,7 @@ class StandardTypeBuilder extends TypeBuilder {
1988
2086
  }, options);
1989
2087
  }
1990
2088
  Pick(schema, unresolved, options = {}) {
1991
- // prettier-ignore
1992
- const keys = TypeGuard.TUnionLiteral(unresolved) ? unresolved.anyOf.map((schema) => schema.const) :
1993
- TypeGuard.TLiteral(unresolved) ? [unresolved.const] :
1994
- TypeGuard.TNever(unresolved) ? [] :
1995
- unresolved;
2089
+ const keys = KeyArrayResolver.Resolve(unresolved);
1996
2090
  // prettier-ignore
1997
2091
  return ObjectMap.Map(TypeClone.Clone(schema, {}), (schema) => {
1998
2092
  if (schema.required) {
@@ -2014,9 +2108,9 @@ class StandardTypeBuilder extends TypeBuilder {
2014
2108
  // prettier-ignore
2015
2109
  return TemplateLiteralFinite.Check(expression)
2016
2110
  ? (this.Object([...TemplateLiteralGenerator.Generate(expression)].reduce((acc, key) => ({ ...acc, [key]: TypeClone.Clone(schema, {}) }), {}), options))
2017
- : this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [key.pattern]: TypeClone.Clone(schema, {}) }, additionalProperties: false });
2111
+ : this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [key.pattern]: TypeClone.Clone(schema, {}) } });
2018
2112
  }
2019
- else if (TypeGuard.TUnionLiteral(key)) {
2113
+ else if (TypeGuard.TLiteralUnion(key)) {
2020
2114
  if (key.anyOf.every((schema) => TypeGuard.TLiteral(schema) && (typeof schema.const === 'string' || typeof schema.const === 'number'))) {
2021
2115
  const properties = key.anyOf.reduce((acc, literal) => ({ ...acc, [literal.const]: TypeClone.Clone(schema, {}) }), {});
2022
2116
  return this.Object(properties, { ...options, [exports.Hint]: 'Record' });
@@ -2033,11 +2127,11 @@ class StandardTypeBuilder extends TypeBuilder {
2033
2127
  }
2034
2128
  else if (TypeGuard.TInteger(key) || TypeGuard.TNumber(key)) {
2035
2129
  const pattern = exports.PatternNumberExact;
2036
- return this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [pattern]: TypeClone.Clone(schema, {}) }, additionalProperties: false });
2130
+ return this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [pattern]: TypeClone.Clone(schema, {}) } });
2037
2131
  }
2038
2132
  else if (TypeGuard.TString(key)) {
2039
2133
  const pattern = key.pattern === undefined ? exports.PatternStringExact : key.pattern;
2040
- return this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [pattern]: TypeClone.Clone(schema, {}) }, additionalProperties: false });
2134
+ return this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [pattern]: TypeClone.Clone(schema, {}) } });
2041
2135
  }
2042
2136
  else {
2043
2137
  throw Error(`StandardTypeBuilder: Invalid Record Key`);
package/value/check.js CHANGED
@@ -189,21 +189,19 @@ var ValueCheck;
189
189
  return true;
190
190
  }
191
191
  function Intersect(schema, references, value) {
192
- if (!schema.allOf.every((schema) => Visit(schema, references, value))) {
193
- return false;
194
- }
195
- else if (schema.unevaluatedProperties === false) {
196
- const schemaKeys = Types.KeyResolver.Resolve(schema);
197
- const valueKeys = globalThis.Object.getOwnPropertyNames(value);
198
- return valueKeys.every((key) => schemaKeys.includes(key));
192
+ const check1 = schema.allOf.every((schema) => Visit(schema, references, value));
193
+ if (schema.unevaluatedProperties === false) {
194
+ const keyCheck = new RegExp(Types.KeyResolver.ResolvePattern(schema));
195
+ const check2 = globalThis.Object.getOwnPropertyNames(value).every((key) => keyCheck.test(key));
196
+ return check1 && check2;
199
197
  }
200
198
  else if (Types.TypeGuard.TSchema(schema.unevaluatedProperties)) {
201
- const schemaKeys = Types.KeyResolver.Resolve(schema);
202
- const valueKeys = globalThis.Object.getOwnPropertyNames(value);
203
- return valueKeys.every((key) => schemaKeys.includes(key) || Visit(schema.unevaluatedProperties, references, value[key]));
199
+ const keyCheck = new RegExp(Types.KeyResolver.ResolvePattern(schema));
200
+ const check2 = globalThis.Object.getOwnPropertyNames(value).every((key) => keyCheck.test(key) || Visit(schema.unevaluatedProperties, references, value[key]));
201
+ return check1 && check2;
204
202
  }
205
203
  else {
206
- return true;
204
+ return check1;
207
205
  }
208
206
  }
209
207
  function Literal(schema, references, value) {
@@ -297,16 +295,20 @@ var ValueCheck;
297
295
  if (IsDefined(schema.maxProperties) && !(globalThis.Object.getOwnPropertyNames(value).length <= schema.maxProperties)) {
298
296
  return false;
299
297
  }
300
- const [keyPattern, valueSchema] = globalThis.Object.entries(schema.patternProperties)[0];
301
- const regex = new RegExp(keyPattern);
302
- if (!globalThis.Object.getOwnPropertyNames(value).every((key) => regex.test(key))) {
303
- return false;
304
- }
305
- for (const propValue of globalThis.Object.values(value)) {
306
- if (!Visit(valueSchema, references, propValue))
298
+ const [patternKey, patternSchema] = globalThis.Object.entries(schema.patternProperties)[0];
299
+ const regex = new RegExp(patternKey);
300
+ return globalThis.Object.entries(value).every(([key, value]) => {
301
+ if (regex.test(key)) {
302
+ return Visit(patternSchema, references, value);
303
+ }
304
+ if (typeof schema.additionalProperties === 'object') {
305
+ return Visit(schema.additionalProperties, references, value);
306
+ }
307
+ if (schema.additionalProperties === false) {
307
308
  return false;
308
- }
309
- return true;
309
+ }
310
+ return true;
311
+ });
310
312
  }
311
313
  function Ref(schema, references, value) {
312
314
  const index = references.findIndex((foreign) => foreign.$id === schema.$ref);
package/value/delta.d.ts CHANGED
@@ -2,32 +2,32 @@ import { Static } from '../typebox';
2
2
  export type Insert = Static<typeof Insert>;
3
3
  export declare const Insert: import("../typebox").TObject<{
4
4
  type: import("../typebox").TLiteral<"insert">;
5
- path: import("../typebox").TString<string>;
5
+ path: import("../typebox").TString;
6
6
  value: import("../typebox").TUnknown;
7
7
  }>;
8
8
  export type Update = Static<typeof Update>;
9
9
  export declare const Update: import("../typebox").TObject<{
10
10
  type: import("../typebox").TLiteral<"update">;
11
- path: import("../typebox").TString<string>;
11
+ path: import("../typebox").TString;
12
12
  value: import("../typebox").TUnknown;
13
13
  }>;
14
14
  export type Delete = Static<typeof Delete>;
15
15
  export declare const Delete: import("../typebox").TObject<{
16
16
  type: import("../typebox").TLiteral<"delete">;
17
- path: import("../typebox").TString<string>;
17
+ path: import("../typebox").TString;
18
18
  }>;
19
19
  export type Edit = Static<typeof Edit>;
20
20
  export declare const Edit: import("../typebox").TUnion<[import("../typebox").TObject<{
21
21
  type: import("../typebox").TLiteral<"insert">;
22
- path: import("../typebox").TString<string>;
22
+ path: import("../typebox").TString;
23
23
  value: import("../typebox").TUnknown;
24
24
  }>, import("../typebox").TObject<{
25
25
  type: import("../typebox").TLiteral<"update">;
26
- path: import("../typebox").TString<string>;
26
+ path: import("../typebox").TString;
27
27
  value: import("../typebox").TUnknown;
28
28
  }>, import("../typebox").TObject<{
29
29
  type: import("../typebox").TLiteral<"delete">;
30
- path: import("../typebox").TString<string>;
30
+ path: import("../typebox").TString;
31
31
  }>]>;
32
32
  export declare class ValueDeltaObjectWithSymbolKeyError extends Error {
33
33
  readonly key: unknown;