@sinclair/typebox 0.32.0-dev-20 → 0.32.0-dev-21

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.
Files changed (72) hide show
  1. package/build/import/compiler/compiler.mjs +62 -62
  2. package/build/import/errors/errors.mjs +62 -62
  3. package/build/import/index.d.mts +4 -4
  4. package/build/import/index.mjs +1 -1
  5. package/build/import/type/indexed/indexed-property-keys.d.mts +2 -2
  6. package/build/import/type/indexed/indexed-property-keys.mjs +6 -11
  7. package/build/import/type/intrinsic/intrinsic.mjs +3 -3
  8. package/build/import/type/record/record.d.mts +2 -2
  9. package/build/import/type/record/record.mjs +2 -3
  10. package/build/import/type/schema/schema.d.mts +1 -1
  11. package/build/import/type/symbol/symbol.d.mts +1 -1
  12. package/build/import/type/template-literal/finite.d.mts +7 -5
  13. package/build/import/type/template-literal/finite.mjs +14 -5
  14. package/build/import/type/template-literal/generate.d.mts +14 -8
  15. package/build/import/type/template-literal/generate.mjs +19 -9
  16. package/build/import/type/template-literal/index.d.mts +1 -1
  17. package/build/import/type/template-literal/index.mjs +1 -1
  18. package/build/import/type/template-literal/{parser.mjs → parse.mjs} +7 -2
  19. package/build/import/type/template-literal/syntax.d.mts +1 -1
  20. package/build/import/type/template-literal/syntax.mjs +0 -1
  21. package/build/import/type/template-literal/template-literal.d.mts +2 -2
  22. package/build/import/type/template-literal/template-literal.mjs +1 -1
  23. package/build/import/type/template-literal/union.d.mts +2 -2
  24. package/build/import/type/template-literal/union.mjs +5 -10
  25. package/build/import/type/type/json.d.mts +2 -2
  26. package/build/import/value/cast/cast.mjs +20 -20
  27. package/build/import/value/check/check.mjs +62 -62
  28. package/build/import/value/clean/clean.mjs +16 -16
  29. package/build/import/value/convert/convert.mjs +36 -36
  30. package/build/import/value/create/create.mjs +66 -67
  31. package/build/import/value/default/default.mjs +16 -16
  32. package/build/import/value/transform/decode.mjs +18 -18
  33. package/build/import/value/transform/encode.mjs +18 -18
  34. package/build/import/value/transform/has.mjs +28 -28
  35. package/build/require/compiler/compiler.js +62 -62
  36. package/build/require/errors/errors.js +62 -62
  37. package/build/require/index.d.ts +4 -4
  38. package/build/require/index.js +4 -2
  39. package/build/require/type/indexed/indexed-property-keys.d.ts +2 -2
  40. package/build/require/type/indexed/indexed-property-keys.js +4 -9
  41. package/build/require/type/intrinsic/intrinsic.js +2 -2
  42. package/build/require/type/record/record.d.ts +2 -2
  43. package/build/require/type/record/record.js +1 -2
  44. package/build/require/type/schema/schema.d.ts +1 -1
  45. package/build/require/type/symbol/symbol.d.ts +1 -1
  46. package/build/require/type/template-literal/finite.d.ts +7 -5
  47. package/build/require/type/template-literal/finite.js +16 -6
  48. package/build/require/type/template-literal/generate.d.ts +14 -8
  49. package/build/require/type/template-literal/generate.js +22 -11
  50. package/build/require/type/template-literal/index.d.ts +1 -1
  51. package/build/require/type/template-literal/index.js +1 -1
  52. package/build/require/type/template-literal/{parser.js → parse.js} +7 -2
  53. package/build/require/type/template-literal/syntax.d.ts +1 -1
  54. package/build/require/type/template-literal/syntax.js +0 -1
  55. package/build/require/type/template-literal/template-literal.d.ts +2 -2
  56. package/build/require/type/template-literal/template-literal.js +1 -1
  57. package/build/require/type/template-literal/union.d.ts +2 -2
  58. package/build/require/type/template-literal/union.js +5 -10
  59. package/build/require/type/type/json.d.ts +2 -2
  60. package/build/require/value/cast/cast.js +20 -20
  61. package/build/require/value/check/check.js +62 -62
  62. package/build/require/value/clean/clean.js +16 -16
  63. package/build/require/value/convert/convert.js +36 -36
  64. package/build/require/value/create/create.js +65 -66
  65. package/build/require/value/default/default.js +16 -16
  66. package/build/require/value/transform/decode.js +18 -18
  67. package/build/require/value/transform/encode.js +18 -18
  68. package/build/require/value/transform/has.js +28 -28
  69. package/package.json +1 -1
  70. package/readme.md +47 -47
  71. /package/build/import/type/template-literal/{parser.d.mts → parse.d.mts} +0 -0
  72. /package/build/require/type/template-literal/{parser.d.ts → parse.d.ts} +0 -0
@@ -133,8 +133,8 @@ function Create(type, schema, path, value) {
133
133
  // --------------------------------------------------------------------------
134
134
  // Types
135
135
  // --------------------------------------------------------------------------
136
- function* TAny(schema, references, path, value) { }
137
- function* TArray(schema, references, path, value) {
136
+ function* FromAny(schema, references, path, value) { }
137
+ function* FromArray(schema, references, path, value) {
138
138
  if (!(0, index_8.IsArray)(value)) {
139
139
  return yield Create(ValueErrorType.Array, schema, path, value);
140
140
  }
@@ -175,11 +175,11 @@ function* TArray(schema, references, path, value) {
175
175
  yield Create(ValueErrorType.ArrayMaxContains, schema, path, value);
176
176
  }
177
177
  }
178
- function* TAsyncIterator(schema, references, path, value) {
178
+ function* FromAsyncIterator(schema, references, path, value) {
179
179
  if (!(0, index_8.IsAsyncIterator)(value))
180
180
  yield Create(ValueErrorType.AsyncIterator, schema, path, value);
181
181
  }
182
- function* TBigInt(schema, references, path, value) {
182
+ function* FromBigInt(schema, references, path, value) {
183
183
  if (!(0, index_8.IsBigInt)(value))
184
184
  return yield Create(ValueErrorType.BigInt, schema, path, value);
185
185
  if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
@@ -198,14 +198,14 @@ function* TBigInt(schema, references, path, value) {
198
198
  yield Create(ValueErrorType.BigIntMultipleOf, schema, path, value);
199
199
  }
200
200
  }
201
- function* TBoolean(schema, references, path, value) {
201
+ function* FromBoolean(schema, references, path, value) {
202
202
  if (!(0, index_8.IsBoolean)(value))
203
203
  yield Create(ValueErrorType.Boolean, schema, path, value);
204
204
  }
205
- function* TConstructor(schema, references, path, value) {
205
+ function* FromConstructor(schema, references, path, value) {
206
206
  yield* Visit(schema.returns, references, path, value.prototype);
207
207
  }
208
- function* TDate(schema, references, path, value) {
208
+ function* FromDate(schema, references, path, value) {
209
209
  if (!(0, index_8.IsDate)(value))
210
210
  return yield Create(ValueErrorType.Date, schema, path, value);
211
211
  if (IsDefined(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
@@ -224,11 +224,11 @@ function* TDate(schema, references, path, value) {
224
224
  yield Create(ValueErrorType.DateMultipleOfTimestamp, schema, path, value);
225
225
  }
226
226
  }
227
- function* TFunction(schema, references, path, value) {
227
+ function* FromFunction(schema, references, path, value) {
228
228
  if (!(0, index_8.IsFunction)(value))
229
229
  yield Create(ValueErrorType.Function, schema, path, value);
230
230
  }
231
- function* TInteger(schema, references, path, value) {
231
+ function* FromInteger(schema, references, path, value) {
232
232
  if (!(0, index_8.IsInteger)(value))
233
233
  return yield Create(ValueErrorType.Integer, schema, path, value);
234
234
  if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
@@ -247,7 +247,7 @@ function* TInteger(schema, references, path, value) {
247
247
  yield Create(ValueErrorType.IntegerMultipleOf, schema, path, value);
248
248
  }
249
249
  }
250
- function* TIntersect(schema, references, path, value) {
250
+ function* FromIntersect(schema, references, path, value) {
251
251
  for (const inner of schema.allOf) {
252
252
  const next = Visit(inner, references, path, value).next();
253
253
  if (!next.done) {
@@ -274,26 +274,26 @@ function* TIntersect(schema, references, path, value) {
274
274
  }
275
275
  }
276
276
  }
277
- function* TIterator(schema, references, path, value) {
277
+ function* FromIterator(schema, references, path, value) {
278
278
  if (!(0, index_8.IsIterator)(value))
279
279
  yield Create(ValueErrorType.Iterator, schema, path, value);
280
280
  }
281
- function* TLiteral(schema, references, path, value) {
281
+ function* FromLiteral(schema, references, path, value) {
282
282
  if (!(value === schema.const))
283
283
  yield Create(ValueErrorType.Literal, schema, path, value);
284
284
  }
285
- function* TNever(schema, references, path, value) {
285
+ function* FromNever(schema, references, path, value) {
286
286
  yield Create(ValueErrorType.Never, schema, path, value);
287
287
  }
288
- function* TNot(schema, references, path, value) {
288
+ function* FromNot(schema, references, path, value) {
289
289
  if (Visit(schema.not, references, path, value).next().done === true)
290
290
  yield Create(ValueErrorType.Not, schema, path, value);
291
291
  }
292
- function* TNull(schema, references, path, value) {
292
+ function* FromNull(schema, references, path, value) {
293
293
  if (!(0, index_8.IsNull)(value))
294
294
  yield Create(ValueErrorType.Null, schema, path, value);
295
295
  }
296
- function* TNumber(schema, references, path, value) {
296
+ function* FromNumber(schema, references, path, value) {
297
297
  if (!index_1.TypeSystemPolicy.IsNumberLike(value))
298
298
  return yield Create(ValueErrorType.Number, schema, path, value);
299
299
  if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
@@ -312,7 +312,7 @@ function* TNumber(schema, references, path, value) {
312
312
  yield Create(ValueErrorType.NumberMultipleOf, schema, path, value);
313
313
  }
314
314
  }
315
- function* TObject(schema, references, path, value) {
315
+ function* FromObject(schema, references, path, value) {
316
316
  if (!index_1.TypeSystemPolicy.IsObjectLike(value))
317
317
  return yield Create(ValueErrorType.Object, schema, path, value);
318
318
  if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
@@ -358,11 +358,11 @@ function* TObject(schema, references, path, value) {
358
358
  }
359
359
  }
360
360
  }
361
- function* TPromise(schema, references, path, value) {
361
+ function* FromPromise(schema, references, path, value) {
362
362
  if (!(0, index_8.IsPromise)(value))
363
363
  yield Create(ValueErrorType.Promise, schema, path, value);
364
364
  }
365
- function* TRecord(schema, references, path, value) {
365
+ function* FromRecord(schema, references, path, value) {
366
366
  if (!index_1.TypeSystemPolicy.IsRecordLike(value))
367
367
  return yield Create(ValueErrorType.Object, schema, path, value);
368
368
  if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
@@ -391,10 +391,10 @@ function* TRecord(schema, references, path, value) {
391
391
  }
392
392
  }
393
393
  }
394
- function* TRef(schema, references, path, value) {
394
+ function* FromRef(schema, references, path, value) {
395
395
  yield* Visit((0, index_4.Deref)(schema, references), references, path, value);
396
396
  }
397
- function* TString(schema, references, path, value) {
397
+ function* FromString(schema, references, path, value) {
398
398
  if (!(0, index_8.IsString)(value))
399
399
  return yield Create(ValueErrorType.String, schema, path, value);
400
400
  if (IsDefined(schema.minLength) && !(value.length >= schema.minLength)) {
@@ -421,11 +421,11 @@ function* TString(schema, references, path, value) {
421
421
  }
422
422
  }
423
423
  }
424
- function* TSymbol(schema, references, path, value) {
424
+ function* FromSymbol(schema, references, path, value) {
425
425
  if (!(0, index_8.IsSymbol)(value))
426
426
  yield Create(ValueErrorType.Symbol, schema, path, value);
427
427
  }
428
- function* TTemplateLiteral(schema, references, path, value) {
428
+ function* FromTemplateLiteral(schema, references, path, value) {
429
429
  if (!(0, index_8.IsString)(value))
430
430
  return yield Create(ValueErrorType.String, schema, path, value);
431
431
  const regex = new RegExp(schema.pattern);
@@ -433,10 +433,10 @@ function* TTemplateLiteral(schema, references, path, value) {
433
433
  yield Create(ValueErrorType.StringPattern, schema, path, value);
434
434
  }
435
435
  }
436
- function* TThis(schema, references, path, value) {
436
+ function* FromThis(schema, references, path, value) {
437
437
  yield* Visit((0, index_4.Deref)(schema, references), references, path, value);
438
438
  }
439
- function* TTuple(schema, references, path, value) {
439
+ function* FromTuple(schema, references, path, value) {
440
440
  if (!(0, index_8.IsArray)(value))
441
441
  return yield Create(ValueErrorType.Tuple, schema, path, value);
442
442
  if (schema.items === undefined && !(value.length === 0)) {
@@ -452,11 +452,11 @@ function* TTuple(schema, references, path, value) {
452
452
  yield* Visit(schema.items[i], references, `${path}/${i}`, value[i]);
453
453
  }
454
454
  }
455
- function* TUndefined(schema, references, path, value) {
455
+ function* FromUndefined(schema, references, path, value) {
456
456
  if (!(0, index_8.IsUndefined)(value))
457
457
  yield Create(ValueErrorType.Undefined, schema, path, value);
458
458
  }
459
- function* TUnion(schema, references, path, value) {
459
+ function* FromUnion(schema, references, path, value) {
460
460
  let count = 0;
461
461
  for (const subschema of schema.anyOf) {
462
462
  const errors = [...Visit(subschema, references, path, value)];
@@ -468,7 +468,7 @@ function* TUnion(schema, references, path, value) {
468
468
  yield Create(ValueErrorType.Union, schema, path, value);
469
469
  }
470
470
  }
471
- function* TUint8Array(schema, references, path, value) {
471
+ function* FromUint8Array(schema, references, path, value) {
472
472
  if (!(0, index_8.IsUint8Array)(value))
473
473
  return yield Create(ValueErrorType.Uint8Array, schema, path, value);
474
474
  if (IsDefined(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
@@ -478,12 +478,12 @@ function* TUint8Array(schema, references, path, value) {
478
478
  yield Create(ValueErrorType.Uint8ArrayMinByteLength, schema, path, value);
479
479
  }
480
480
  }
481
- function* TUnknown(schema, references, path, value) { }
482
- function* TVoid(schema, references, path, value) {
481
+ function* FromUnknown(schema, references, path, value) { }
482
+ function* FromVoid(schema, references, path, value) {
483
483
  if (!index_1.TypeSystemPolicy.IsVoidLike(value))
484
484
  yield Create(ValueErrorType.Void, schema, path, value);
485
485
  }
486
- function* TKind(schema, references, path, value) {
486
+ function* FromKind(schema, references, path, value) {
487
487
  const check = index_3.TypeRegistry.Get(schema[index_6.Kind]);
488
488
  if (!check(schema, value))
489
489
  yield Create(ValueErrorType.Kind, schema, path, value);
@@ -493,69 +493,69 @@ function* Visit(schema, references, path, value) {
493
493
  const schema_ = schema;
494
494
  switch (schema_[index_6.Kind]) {
495
495
  case 'Any':
496
- return yield* TAny(schema_, references_, path, value);
496
+ return yield* FromAny(schema_, references_, path, value);
497
497
  case 'Array':
498
- return yield* TArray(schema_, references_, path, value);
498
+ return yield* FromArray(schema_, references_, path, value);
499
499
  case 'AsyncIterator':
500
- return yield* TAsyncIterator(schema_, references_, path, value);
500
+ return yield* FromAsyncIterator(schema_, references_, path, value);
501
501
  case 'BigInt':
502
- return yield* TBigInt(schema_, references_, path, value);
502
+ return yield* FromBigInt(schema_, references_, path, value);
503
503
  case 'Boolean':
504
- return yield* TBoolean(schema_, references_, path, value);
504
+ return yield* FromBoolean(schema_, references_, path, value);
505
505
  case 'Constructor':
506
- return yield* TConstructor(schema_, references_, path, value);
506
+ return yield* FromConstructor(schema_, references_, path, value);
507
507
  case 'Date':
508
- return yield* TDate(schema_, references_, path, value);
508
+ return yield* FromDate(schema_, references_, path, value);
509
509
  case 'Function':
510
- return yield* TFunction(schema_, references_, path, value);
510
+ return yield* FromFunction(schema_, references_, path, value);
511
511
  case 'Integer':
512
- return yield* TInteger(schema_, references_, path, value);
512
+ return yield* FromInteger(schema_, references_, path, value);
513
513
  case 'Intersect':
514
- return yield* TIntersect(schema_, references_, path, value);
514
+ return yield* FromIntersect(schema_, references_, path, value);
515
515
  case 'Iterator':
516
- return yield* TIterator(schema_, references_, path, value);
516
+ return yield* FromIterator(schema_, references_, path, value);
517
517
  case 'Literal':
518
- return yield* TLiteral(schema_, references_, path, value);
518
+ return yield* FromLiteral(schema_, references_, path, value);
519
519
  case 'Never':
520
- return yield* TNever(schema_, references_, path, value);
520
+ return yield* FromNever(schema_, references_, path, value);
521
521
  case 'Not':
522
- return yield* TNot(schema_, references_, path, value);
522
+ return yield* FromNot(schema_, references_, path, value);
523
523
  case 'Null':
524
- return yield* TNull(schema_, references_, path, value);
524
+ return yield* FromNull(schema_, references_, path, value);
525
525
  case 'Number':
526
- return yield* TNumber(schema_, references_, path, value);
526
+ return yield* FromNumber(schema_, references_, path, value);
527
527
  case 'Object':
528
- return yield* TObject(schema_, references_, path, value);
528
+ return yield* FromObject(schema_, references_, path, value);
529
529
  case 'Promise':
530
- return yield* TPromise(schema_, references_, path, value);
530
+ return yield* FromPromise(schema_, references_, path, value);
531
531
  case 'Record':
532
- return yield* TRecord(schema_, references_, path, value);
532
+ return yield* FromRecord(schema_, references_, path, value);
533
533
  case 'Ref':
534
- return yield* TRef(schema_, references_, path, value);
534
+ return yield* FromRef(schema_, references_, path, value);
535
535
  case 'String':
536
- return yield* TString(schema_, references_, path, value);
536
+ return yield* FromString(schema_, references_, path, value);
537
537
  case 'Symbol':
538
- return yield* TSymbol(schema_, references_, path, value);
538
+ return yield* FromSymbol(schema_, references_, path, value);
539
539
  case 'TemplateLiteral':
540
- return yield* TTemplateLiteral(schema_, references_, path, value);
540
+ return yield* FromTemplateLiteral(schema_, references_, path, value);
541
541
  case 'This':
542
- return yield* TThis(schema_, references_, path, value);
542
+ return yield* FromThis(schema_, references_, path, value);
543
543
  case 'Tuple':
544
- return yield* TTuple(schema_, references_, path, value);
544
+ return yield* FromTuple(schema_, references_, path, value);
545
545
  case 'Undefined':
546
- return yield* TUndefined(schema_, references_, path, value);
546
+ return yield* FromUndefined(schema_, references_, path, value);
547
547
  case 'Union':
548
- return yield* TUnion(schema_, references_, path, value);
548
+ return yield* FromUnion(schema_, references_, path, value);
549
549
  case 'Uint8Array':
550
- return yield* TUint8Array(schema_, references_, path, value);
550
+ return yield* FromUint8Array(schema_, references_, path, value);
551
551
  case 'Unknown':
552
- return yield* TUnknown(schema_, references_, path, value);
552
+ return yield* FromUnknown(schema_, references_, path, value);
553
553
  case 'Void':
554
- return yield* TVoid(schema_, references_, path, value);
554
+ return yield* FromVoid(schema_, references_, path, value);
555
555
  default:
556
556
  if (!index_3.TypeRegistry.Has(schema_[index_6.Kind]))
557
557
  throw new ValueErrorsUnknownTypeError(schema);
558
- return yield* TKind(schema_, references_, path, value);
558
+ return yield* FromKind(schema_, references_, path, value);
559
559
  }
560
560
  }
561
561
  /** Returns an iterator for each error in this value. */
@@ -7,7 +7,7 @@ export { Any, type TAny } from './type/any/index';
7
7
  export { Array, type TArray, type ArrayOptions } from './type/array/index';
8
8
  export { AsyncIterator, type TAsyncIterator } from './type/async-iterator/index';
9
9
  export { Awaited, type TAwaited } from './type/awaited/index';
10
- export { BigInt, type TBigInt, BigIntOptions } from './type/bigint/index';
10
+ export { BigInt, type TBigInt, type BigIntOptions } from './type/bigint/index';
11
11
  export { Boolean, type TBoolean } from './type/boolean/index';
12
12
  export { Composite, type TComposite } from './type/composite/index';
13
13
  export { Const, type TConst } from './type/const/index';
@@ -54,9 +54,9 @@ export { type TSchema, type TKind, type SchemaOptions, type TAnySchema } from '.
54
54
  export { type Static, type StaticDecode, type StaticEncode } from './type/static/index';
55
55
  export { Strict } from './type/strict/index';
56
56
  export { String, type TString, type StringOptions, type StringFormatOption, type StringContentEncodingOption } from './type/string/index';
57
- export { Symbol, type TSymbol, type SymbolValue } from './type/symbol/index';
58
- export { TemplateLiteral, IsTemplateLiteralFinite, TemplateLiteralParse, TemplateLiteralParseExact, TemplateLiteralGenerate, type TTemplateLiteral, type TTemplateLiteralKind } from './type/template-literal/index';
59
- export { Transform, type TTransform, type TransformOptions, type TransformFunction, TransformDecodeBuilder, TransformEncodeBuilder } from './type/transform/index';
57
+ export { Symbol, type TSymbol, type TSymbolValue as SymbolValue } from './type/symbol/index';
58
+ export { TemplateLiteral, IsTemplateLiteralFinite, IsTemplateLiteralExpressionFinite, TemplateLiteralParse, TemplateLiteralParseExact, TemplateLiteralGenerate, TemplateLiteralExpressionGenerate, type TTemplateLiteral, type TIsTemplateLiteralFinite, type TTemplateLiteralGenerate, type TTemplateLiteralKind, } from './type/template-literal/index';
59
+ export { Transform, TransformDecodeBuilder, TransformEncodeBuilder, type TTransform, type TransformOptions, type TransformFunction } from './type/transform/index';
60
60
  export { Tuple, type TTuple } from './type/tuple/index';
61
61
  export { Uint8Array, type TUint8Array, type Uint8ArrayOptions } from './type/uint8array/index';
62
62
  export { Undefined, type TUndefined } from './type/undefined/index';
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Lowercase = exports.Capitalize = exports.IntrinsicFromMappedKey = exports.Intrinsic = exports.Iterator = exports.IntersectEvaluated = exports.Intersect = exports.Integer = exports.InstanceType = exports.IndexFromMappedKey = exports.IndexPropertyKeys = exports.Index = exports.Increment = exports.Function = exports.Extract = exports.ExtendsUndefinedCheck = exports.ExtendsResult = exports.ExtendsCheck = exports.Extends = exports.Exclude = exports.Enum = exports.Deref = exports.Date = exports.ConstructorParameters = exports.Constructor = exports.Const = exports.Composite = exports.Boolean = exports.BigInt = exports.Awaited = exports.AsyncIterator = exports.Array = exports.Any = exports.CloneRest = exports.CloneType = exports.ValueGuard = exports.TypeGuard = exports.FormatRegistry = exports.TypeRegistry = exports.PatternStringExact = exports.PatternString = exports.PatternNumberExact = exports.PatternNumber = exports.PatternBooleanExact = exports.PatternBoolean = exports.TransformKind = exports.OptionalKind = exports.ReadonlyKind = exports.Hint = exports.Kind = void 0;
5
- exports.Unsafe = exports.Unknown = exports.UnionEvaluated = exports.Union = exports.Undefined = exports.Uint8Array = exports.Tuple = exports.TransformEncodeBuilder = exports.TransformDecodeBuilder = exports.Transform = exports.TemplateLiteralGenerate = exports.TemplateLiteralParseExact = exports.TemplateLiteralParse = exports.IsTemplateLiteralFinite = exports.TemplateLiteral = exports.Symbol = exports.String = exports.Strict = exports.ReturnType = exports.Rest = exports.Required = exports.RegExp = exports.Ref = exports.Recursive = exports.Record = exports.ReadonlyOptional = exports.ReadonlyFromMappedResult = exports.Readonly = exports.Promise = exports.Pick = exports.PartialFromMappedResult = exports.Partial = exports.Parameters = exports.OptionalFromMappedResult = exports.Optional = exports.Omit = exports.Object = exports.Number = exports.Null = exports.Not = exports.Never = exports.MappedResult = exports.MappedKey = exports.Mapped = exports.Literal = exports.KeyOfPattern = exports.KeyOfPropertyKeys = exports.KeyOf = exports.Uppercase = exports.Uncapitalize = void 0;
6
- exports.JavaScriptTypeBuilder = exports.JsonTypeBuilder = exports.Type = exports.Void = void 0;
5
+ exports.UnionEvaluated = exports.Union = exports.Undefined = exports.Uint8Array = exports.Tuple = exports.TransformEncodeBuilder = exports.TransformDecodeBuilder = exports.Transform = exports.TemplateLiteralExpressionGenerate = exports.TemplateLiteralGenerate = exports.TemplateLiteralParseExact = exports.TemplateLiteralParse = exports.IsTemplateLiteralExpressionFinite = exports.IsTemplateLiteralFinite = exports.TemplateLiteral = exports.Symbol = exports.String = exports.Strict = exports.ReturnType = exports.Rest = exports.Required = exports.RegExp = exports.Ref = exports.Recursive = exports.Record = exports.ReadonlyOptional = exports.ReadonlyFromMappedResult = exports.Readonly = exports.Promise = exports.Pick = exports.PartialFromMappedResult = exports.Partial = exports.Parameters = exports.OptionalFromMappedResult = exports.Optional = exports.Omit = exports.Object = exports.Number = exports.Null = exports.Not = exports.Never = exports.MappedResult = exports.MappedKey = exports.Mapped = exports.Literal = exports.KeyOfPattern = exports.KeyOfPropertyKeys = exports.KeyOf = exports.Uppercase = exports.Uncapitalize = void 0;
6
+ exports.JavaScriptTypeBuilder = exports.JsonTypeBuilder = exports.Type = exports.Void = exports.Unsafe = exports.Unknown = void 0;
7
7
  // ------------------------------------------------------------------
8
8
  // Infrastructure
9
9
  // ------------------------------------------------------------------
@@ -153,9 +153,11 @@ Object.defineProperty(exports, "Symbol", { enumerable: true, get: function () {
153
153
  var index_55 = require("./type/template-literal/index");
154
154
  Object.defineProperty(exports, "TemplateLiteral", { enumerable: true, get: function () { return index_55.TemplateLiteral; } });
155
155
  Object.defineProperty(exports, "IsTemplateLiteralFinite", { enumerable: true, get: function () { return index_55.IsTemplateLiteralFinite; } });
156
+ Object.defineProperty(exports, "IsTemplateLiteralExpressionFinite", { enumerable: true, get: function () { return index_55.IsTemplateLiteralExpressionFinite; } });
156
157
  Object.defineProperty(exports, "TemplateLiteralParse", { enumerable: true, get: function () { return index_55.TemplateLiteralParse; } });
157
158
  Object.defineProperty(exports, "TemplateLiteralParseExact", { enumerable: true, get: function () { return index_55.TemplateLiteralParseExact; } });
158
159
  Object.defineProperty(exports, "TemplateLiteralGenerate", { enumerable: true, get: function () { return index_55.TemplateLiteralGenerate; } });
160
+ Object.defineProperty(exports, "TemplateLiteralExpressionGenerate", { enumerable: true, get: function () { return index_55.TemplateLiteralExpressionGenerate; } });
159
161
  var index_56 = require("./type/transform/index");
160
162
  Object.defineProperty(exports, "Transform", { enumerable: true, get: function () { return index_56.Transform; } });
161
163
  Object.defineProperty(exports, "TransformDecodeBuilder", { enumerable: true, get: function () { return index_56.TransformDecodeBuilder; } });
@@ -1,10 +1,10 @@
1
- import { type TTemplateLiteral, TemplateLiteralGenerate, IsTemplateLiteralFinite } from '../template-literal/index';
1
+ import { type TTemplateLiteral, TTemplateLiteralGenerate } from '../template-literal/index';
2
2
  import { type TLiteral, type TLiteralValue } from '../literal/index';
3
3
  import { type TInteger } from '../integer/index';
4
4
  import { type TNumber } from '../number/index';
5
5
  import { type TSchema } from '../schema/index';
6
6
  import { type TUnion } from '../union/index';
7
- type FromTemplateLiteral<T extends TTemplateLiteral, F = IsTemplateLiteralFinite<T>> = (F extends true ? TemplateLiteralGenerate<T> extends infer R extends string[] ? R : [] : []);
7
+ type FromTemplateLiteral<T extends TTemplateLiteral, R extends string[] = TTemplateLiteralGenerate<T>> = (R);
8
8
  declare function FromTemplateLiteral<T extends TTemplateLiteral>(T: T): FromTemplateLiteral<T>;
9
9
  type FromUnion<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [...TIndexPropertyKeys<L>, ...FromUnion<R>] : []);
10
10
  declare function FromUnion<T extends TSchema[]>(T: T): FromUnion<T>;
@@ -10,14 +10,8 @@ const index_1 = require("../template-literal/index");
10
10
  const type_1 = require("../guard/type");
11
11
  // prettier-ignore
12
12
  function FromTemplateLiteral(T) {
13
- const E = (0, index_1.TemplateLiteralParseExact)(T.pattern);
14
- const F = (0, index_1.IsTemplateLiteralFinite)(E);
15
- const S = (0, index_1.TemplateLiteralToUnion)(T);
16
- return (F === true
17
- ? (0, type_1.IsUnionLiteral)(S)
18
- ? S.anyOf.map(S => S.const.toString())
19
- : []
20
- : []);
13
+ const R = (0, index_1.TemplateLiteralGenerate)(T);
14
+ return R.map(S => S.toString());
21
15
  }
22
16
  // prettier-ignore
23
17
  function FromUnion(T) {
@@ -28,7 +22,8 @@ function FromUnion(T) {
28
22
  }
29
23
  // prettier-ignore
30
24
  function FromLiteral(T) {
31
- return ([T.toString()]);
25
+ return ([T.toString()] // TS 5.4 observes TLiteralValue as not having a toString()
26
+ );
32
27
  }
33
28
  /** Returns a tuple of PropertyKeys derived from the given TSchema */
34
29
  // prettier-ignore
@@ -32,10 +32,10 @@ function FromTemplateLiteral(schema, mode, options) {
32
32
  // note: template literals require special runtime handling as they are encoded in string patterns.
33
33
  // This diverges from the mapped type which would otherwise map on the template literal kind.
34
34
  const expression = (0, index_1.TemplateLiteralParseExact)(schema.pattern);
35
- const finite = (0, index_1.IsTemplateLiteralFinite)(expression);
35
+ const finite = (0, index_1.IsTemplateLiteralExpressionFinite)(expression);
36
36
  if (!finite)
37
37
  return { ...schema, pattern: FromLiteralValue(schema.pattern, mode) };
38
- const strings = [...(0, index_1.TemplateLiteralGenerate)(expression)];
38
+ const strings = [...(0, index_1.TemplateLiteralExpressionGenerate)(expression)];
39
39
  const literals = strings.map((value) => (0, index_2.Literal)(value));
40
40
  const mapped = FromRest(literals, mode);
41
41
  const union = (0, index_3.Union)(mapped);
@@ -9,13 +9,13 @@ import { type TString } from '../string/index';
9
9
  import { type TInteger } from '../integer/index';
10
10
  import { type TNumber } from '../number/index';
11
11
  import { type TEnum } from '../enum/index';
12
- import { TTemplateLiteral, IsTemplateLiteralFinite } from '../template-literal/index';
12
+ import { TTemplateLiteral, TIsTemplateLiteralFinite } from '../template-literal/index';
13
13
  import { Kind } from '../symbols/index';
14
14
  type FromTemplateLiteralKeyInfinite<K extends TTemplateLiteral, T extends TSchema> = Ensure<TRecord<K, T>>;
15
15
  type FromTemplateLiteralKeyFinite<K extends TTemplateLiteral, T extends TSchema, I extends string = Static<K>> = (Ensure<TObject<Evaluate<{
16
16
  [_ in I]: T;
17
17
  }>>>);
18
- type FromTemplateLiteralKey<K extends TTemplateLiteral, T extends TSchema> = IsTemplateLiteralFinite<K> extends false ? FromTemplateLiteralKeyInfinite<K, T> : FromTemplateLiteralKeyFinite<K, T>;
18
+ type FromTemplateLiteralKey<K extends TTemplateLiteral, T extends TSchema> = TIsTemplateLiteralFinite<K> extends false ? FromTemplateLiteralKeyInfinite<K, T> : FromTemplateLiteralKeyFinite<K, T>;
19
19
  declare function FromTemplateLiteralKey<K extends TTemplateLiteral, T extends TSchema>(K: K, T: T, options: ObjectOptions): FromTemplateLiteralKey<K, T>;
20
20
  type FromEnumKey<K extends Record<string, string | number>, T extends TSchema> = Ensure<TObject<{
21
21
  [_ in K[keyof K]]: T;
@@ -38,8 +38,7 @@ function RecordCreateFromKeys(K, T, options) {
38
38
  }
39
39
  // prettier-ignore
40
40
  function FromTemplateLiteralKey(K, T, options) {
41
- const expression = (0, index_4.TemplateLiteralParseExact)(K.pattern);
42
- return ((0, index_4.IsTemplateLiteralFinite)(expression)
41
+ return ((0, index_4.IsTemplateLiteralFinite)(K)
43
42
  ? RecordCreateFromKeys((0, index_6.IndexPropertyKeys)(K), T, options)
44
43
  : RecordCreateFromPattern(K.pattern, T, options));
45
44
  }
@@ -20,7 +20,7 @@ export interface SchemaOptions {
20
20
  export interface TKind {
21
21
  [Kind]: string;
22
22
  }
23
- export interface TSchema extends SchemaOptions, TKind {
23
+ export interface TSchema extends TKind, SchemaOptions {
24
24
  [ReadonlyKind]?: string;
25
25
  [OptionalKind]?: string;
26
26
  [Hint]?: string;
@@ -1,6 +1,6 @@
1
1
  import { TSchema, SchemaOptions } from '../schema/index';
2
2
  import { Kind } from '../symbols/index';
3
- export type SymbolValue = string | number | undefined;
3
+ export type TSymbolValue = string | number | undefined;
4
4
  export interface TSymbol extends TSchema, SchemaOptions {
5
5
  [Kind]: 'Symbol';
6
6
  static: symbol;
@@ -6,11 +6,13 @@ import type { TNumber } from '../number/index';
6
6
  import type { TInteger } from '../integer/index';
7
7
  import type { TBigInt } from '../bigint/index';
8
8
  import type { TLiteral } from '../literal/index';
9
- import type { Expression } from './parser';
9
+ import type { Expression } from './parse';
10
10
  export declare class TemplateLiteralFiniteError extends Error {
11
11
  }
12
- type IsTemplateLiteralFiniteCheck<T> = T extends TTemplateLiteral<infer U extends TTemplateLiteralKind[]> ? IsTemplateLiteralFiniteArray<U> : T extends TUnion<infer U extends TTemplateLiteralKind[]> ? IsTemplateLiteralFiniteArray<U> : T extends TString ? false : T extends TBoolean ? false : T extends TNumber ? false : T extends TInteger ? false : T extends TBigInt ? false : T extends TLiteral ? true : false;
13
- type IsTemplateLiteralFiniteArray<T extends TTemplateLiteralKind[]> = T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? IsTemplateLiteralFiniteCheck<L> extends false ? false : IsTemplateLiteralFiniteArray<R> : true;
14
- export type IsTemplateLiteralFinite<T> = T extends TTemplateLiteral<infer U> ? IsTemplateLiteralFiniteArray<U> : false;
15
- export declare function IsTemplateLiteralFinite(expression: Expression): boolean;
12
+ type FromTemplateLiteralKind<T> = T extends TTemplateLiteral<infer U extends TTemplateLiteralKind[]> ? FromTemplateLiteralKinds<U> : T extends TUnion<infer U extends TTemplateLiteralKind[]> ? FromTemplateLiteralKinds<U> : T extends TString ? false : T extends TNumber ? false : T extends TInteger ? false : T extends TBigInt ? false : T extends TBoolean ? true : T extends TLiteral ? true : false;
13
+ type FromTemplateLiteralKinds<T extends TTemplateLiteralKind[]> = T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? FromTemplateLiteralKind<L> extends false ? false : FromTemplateLiteralKinds<R> : true;
14
+ export declare function IsTemplateLiteralExpressionFinite(expression: Expression): boolean;
15
+ export type TIsTemplateLiteralFinite<T> = T extends TTemplateLiteral<infer U> ? FromTemplateLiteralKinds<U> : false;
16
+ /** Returns true if this TemplateLiteral resolves to a finite set of values */
17
+ export declare function IsTemplateLiteralFinite<T extends TTemplateLiteral>(schema: T): boolean;
16
18
  export {};
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.IsTemplateLiteralFinite = exports.TemplateLiteralFiniteError = void 0;
4
+ exports.IsTemplateLiteralFinite = exports.IsTemplateLiteralExpressionFinite = exports.TemplateLiteralFiniteError = void 0;
5
+ const parse_1 = require("./parse");
5
6
  // ------------------------------------------------------------------
6
7
  // TemplateLiteralFiniteError
7
8
  // ------------------------------------------------------------------
@@ -33,13 +34,22 @@ function IsBooleanExpression(expression) {
33
34
  function IsStringExpression(expression) {
34
35
  return expression.type === 'const' && expression.const === '.*';
35
36
  }
37
+ // ------------------------------------------------------------------
38
+ // IsTemplateLiteralExpressionFinite
39
+ // ------------------------------------------------------------------
36
40
  // prettier-ignore
37
- function IsTemplateLiteralFinite(expression) {
38
- return (IsBooleanExpression(expression) ? true :
39
- IsNumberExpression(expression) || IsStringExpression(expression) ? false :
40
- (expression.type === 'and') ? expression.expr.every((expr) => IsTemplateLiteralFinite(expr)) :
41
- (expression.type === 'or') ? expression.expr.every((expr) => IsTemplateLiteralFinite(expr)) :
41
+ function IsTemplateLiteralExpressionFinite(expression) {
42
+ return (IsNumberExpression(expression) || IsStringExpression(expression) ? false :
43
+ IsBooleanExpression(expression) ? true :
44
+ (expression.type === 'and') ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) :
45
+ (expression.type === 'or') ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) :
42
46
  (expression.type === 'const') ? true :
43
47
  (() => { throw new TemplateLiteralFiniteError(`Unknown expression type`); })());
44
48
  }
49
+ exports.IsTemplateLiteralExpressionFinite = IsTemplateLiteralExpressionFinite;
50
+ /** Returns true if this TemplateLiteral resolves to a finite set of values */
51
+ function IsTemplateLiteralFinite(schema) {
52
+ const expression = (0, parse_1.TemplateLiteralParseExact)(schema.pattern);
53
+ return IsTemplateLiteralExpressionFinite(expression);
54
+ }
45
55
  exports.IsTemplateLiteralFinite = IsTemplateLiteralFinite;
@@ -1,15 +1,21 @@
1
+ import { TIsTemplateLiteralFinite } from './finite';
2
+ import type { Assert } from '../helpers/index';
3
+ import type { TBoolean } from '../boolean/index';
1
4
  import type { TTemplateLiteral, TTemplateLiteralKind } from './index';
2
5
  import type { TLiteral, TLiteralValue } from '../literal/index';
3
- import type { Expression } from './parser';
6
+ import type { Expression } from './parse';
4
7
  import type { TUnion } from '../union/index';
8
+ export declare class TemplateLiteralGenerateError extends Error {
9
+ }
5
10
  type StringReduceUnary<L extends string, R extends string[]> = R extends [infer A extends string, ...infer B extends string[]] ? [`${L}${A}`, ...StringReduceUnary<L, B>] : [];
6
11
  type StringReduceBinary<L extends string[], R extends string[]> = L extends [infer A extends string, ...infer B extends string[]] ? [...StringReduceUnary<A, R>, ...StringReduceBinary<B, R>] : [];
7
12
  type StringReduceMany<T extends string[][]> = T extends [infer L extends string[], infer R extends string[], ...infer Rest extends string[][]] ? StringReduceMany<[StringReduceBinary<L, R>, ...Rest]> : T;
8
- type StringReduce<T extends string[][], O = StringReduceMany<T>> = 0 extends keyof O ? O[0] : [];
9
- type TemplateLiteralReduceUnion<T extends TTemplateLiteralKind[]> = T extends [infer L extends TLiteral, ...infer R extends TLiteral[]] ? [L['const'], ...TemplateLiteralReduceUnion<R>] : [];
10
- type TemplateLiteralReduce<T extends TTemplateLiteralKind[]> = T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? L extends TLiteral<infer S extends TLiteralValue> ? [[S], ...TemplateLiteralReduce<R>] : L extends TUnion<infer S extends TTemplateLiteralKind[]> ? [TemplateLiteralReduceUnion<S>, ...TemplateLiteralReduce<R>] : [] : [];
11
- export declare class TemplateLiteralGenerateError extends Error {
12
- }
13
- export type TemplateLiteralGenerate<T> = T extends TTemplateLiteral<infer S extends TTemplateLiteralKind[]> ? TemplateLiteralReduce<S> extends infer R extends string[][] ? StringReduce<R> : [] : [];
14
- export declare function TemplateLiteralGenerate(expression: Expression): IterableIterator<string>;
13
+ type StringReduce<T extends string[][], O = StringReduceMany<T>> = 0 extends keyof O ? Assert<O[0], string[]> : [];
14
+ type FromTemplateLiteralUnionKinds<T extends TTemplateLiteralKind[]> = T extends [infer L extends TLiteral, ...infer R extends TLiteral[]] ? [L['const'], ...FromTemplateLiteralUnionKinds<R>] : [];
15
+ type FromTemplateLiteralKinds<T extends TTemplateLiteralKind[]> = T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? (L extends TLiteral<infer S extends TLiteralValue> ? [[S], ...FromTemplateLiteralKinds<R>] : L extends TUnion<infer S extends TTemplateLiteralKind[]> ? [FromTemplateLiteralUnionKinds<S>, ...FromTemplateLiteralKinds<R>] : L extends TBoolean ? [['true', 'false'], ...FromTemplateLiteralKinds<R>] : [
16
+ ]) : [];
17
+ export declare function TemplateLiteralExpressionGenerate(expression: Expression): IterableIterator<string>;
18
+ export type TTemplateLiteralGenerate<T extends TTemplateLiteral, F = TIsTemplateLiteralFinite<T>> = F extends true ? (T extends TTemplateLiteral<infer S extends TTemplateLiteralKind[]> ? FromTemplateLiteralKinds<S> extends infer R extends string[][] ? StringReduce<R> : [] : []) : [];
19
+ /** Generates a tuple of strings from the given TemplateLiteral. Returns an empty tuple if infinite. */
20
+ export declare function TemplateLiteralGenerate<T extends TTemplateLiteral>(schema: T): TTemplateLiteralGenerate<T>;
15
21
  export {};
@@ -1,9 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.TemplateLiteralGenerate = exports.TemplateLiteralGenerateError = void 0;
4
+ exports.TemplateLiteralGenerate = exports.TemplateLiteralExpressionGenerate = exports.TemplateLiteralGenerateError = void 0;
5
+ const finite_1 = require("./finite");
6
+ const parse_1 = require("./parse");
5
7
  // ------------------------------------------------------------------
6
- // GenerateFromExpression
8
+ // TemplateLiteralGenerateError
9
+ // ------------------------------------------------------------------
10
+ class TemplateLiteralGenerateError extends Error {
11
+ }
12
+ exports.TemplateLiteralGenerateError = TemplateLiteralGenerateError;
13
+ // ------------------------------------------------------------------
14
+ // TemplateLiteralExpressionGenerate
7
15
  // ------------------------------------------------------------------
8
16
  // prettier-ignore
9
17
  function* GenerateReduce(buffer) {
@@ -17,24 +25,18 @@ function* GenerateReduce(buffer) {
17
25
  }
18
26
  // prettier-ignore
19
27
  function* GenerateAnd(expression) {
20
- return yield* GenerateReduce(expression.expr.map((expr) => [...TemplateLiteralGenerate(expr)]));
28
+ return yield* GenerateReduce(expression.expr.map((expr) => [...TemplateLiteralExpressionGenerate(expr)]));
21
29
  }
22
30
  // prettier-ignore
23
31
  function* GenerateOr(expression) {
24
32
  for (const expr of expression.expr)
25
- yield* TemplateLiteralGenerate(expr);
33
+ yield* TemplateLiteralExpressionGenerate(expr);
26
34
  }
27
35
  // prettier-ignore
28
36
  function* GenerateConst(expression) {
29
37
  return yield expression.const;
30
38
  }
31
- // ------------------------------------------------------------------
32
- // TemplateLiteralGenerateError
33
- // ------------------------------------------------------------------
34
- class TemplateLiteralGenerateError extends Error {
35
- }
36
- exports.TemplateLiteralGenerateError = TemplateLiteralGenerateError;
37
- function* TemplateLiteralGenerate(expression) {
39
+ function* TemplateLiteralExpressionGenerate(expression) {
38
40
  return expression.type === 'and'
39
41
  ? yield* GenerateAnd(expression)
40
42
  : expression.type === 'or'
@@ -45,4 +47,13 @@ function* TemplateLiteralGenerate(expression) {
45
47
  throw new TemplateLiteralGenerateError('Unknown expression');
46
48
  })();
47
49
  }
50
+ exports.TemplateLiteralExpressionGenerate = TemplateLiteralExpressionGenerate;
51
+ /** Generates a tuple of strings from the given TemplateLiteral. Returns an empty tuple if infinite. */
52
+ function TemplateLiteralGenerate(schema) {
53
+ const expression = (0, parse_1.TemplateLiteralParseExact)(schema.pattern);
54
+ // prettier-ignore
55
+ return ((0, finite_1.IsTemplateLiteralExpressionFinite)(expression)
56
+ ? [...TemplateLiteralExpressionGenerate(expression)]
57
+ : []);
58
+ }
48
59
  exports.TemplateLiteralGenerate = TemplateLiteralGenerate;
@@ -1,7 +1,7 @@
1
1
  export * from './finite';
2
2
  export * from './generate';
3
3
  export * from './syntax';
4
- export * from './parser';
4
+ export * from './parse';
5
5
  export * from './pattern';
6
6
  export * from './union';
7
7
  export * from './template-literal';