@sinclair/typebox 0.32.0-dev-19 → 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 (98) 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 +6 -6
  4. package/build/import/index.mjs +3 -3
  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/optional/index.d.mts +1 -0
  9. package/build/import/type/optional/index.mjs +1 -0
  10. package/build/import/type/optional/optional-from-mapped-result.d.mts +12 -0
  11. package/build/import/type/optional/optional-from-mapped-result.mjs +17 -0
  12. package/build/import/type/optional/optional.d.mts +19 -2
  13. package/build/import/type/optional/optional.mjs +18 -2
  14. package/build/import/type/readonly/index.d.mts +1 -0
  15. package/build/import/type/readonly/index.mjs +1 -0
  16. package/build/import/type/readonly/readonly-from-mapped-result.d.mts +12 -0
  17. package/build/import/type/readonly/readonly-from-mapped-result.mjs +17 -0
  18. package/build/import/type/readonly/readonly.d.mts +18 -1
  19. package/build/import/type/readonly/readonly.mjs +18 -2
  20. package/build/import/type/record/record.d.mts +2 -2
  21. package/build/import/type/record/record.mjs +2 -3
  22. package/build/import/type/schema/schema.d.mts +1 -1
  23. package/build/import/type/symbol/symbol.d.mts +1 -1
  24. package/build/import/type/template-literal/finite.d.mts +7 -5
  25. package/build/import/type/template-literal/finite.mjs +14 -5
  26. package/build/import/type/template-literal/generate.d.mts +14 -8
  27. package/build/import/type/template-literal/generate.mjs +19 -9
  28. package/build/import/type/template-literal/index.d.mts +1 -1
  29. package/build/import/type/template-literal/index.mjs +1 -1
  30. package/build/import/type/template-literal/{parser.mjs → parse.mjs} +7 -2
  31. package/build/import/type/template-literal/syntax.d.mts +1 -1
  32. package/build/import/type/template-literal/syntax.mjs +0 -1
  33. package/build/import/type/template-literal/template-literal.d.mts +2 -2
  34. package/build/import/type/template-literal/template-literal.mjs +1 -1
  35. package/build/import/type/template-literal/union.d.mts +2 -2
  36. package/build/import/type/template-literal/union.mjs +5 -10
  37. package/build/import/type/type/json.d.mts +19 -7
  38. package/build/import/type/type/json.mjs +5 -5
  39. package/build/import/value/cast/cast.mjs +20 -20
  40. package/build/import/value/check/check.mjs +62 -62
  41. package/build/import/value/clean/clean.mjs +16 -16
  42. package/build/import/value/convert/convert.mjs +36 -36
  43. package/build/import/value/create/create.mjs +66 -67
  44. package/build/import/value/default/default.mjs +16 -16
  45. package/build/import/value/transform/decode.mjs +18 -18
  46. package/build/import/value/transform/encode.mjs +18 -18
  47. package/build/import/value/transform/has.mjs +28 -28
  48. package/build/require/compiler/compiler.js +62 -62
  49. package/build/require/errors/errors.js +62 -62
  50. package/build/require/index.d.ts +6 -6
  51. package/build/require/index.js +6 -2
  52. package/build/require/type/indexed/indexed-property-keys.d.ts +2 -2
  53. package/build/require/type/indexed/indexed-property-keys.js +4 -9
  54. package/build/require/type/intrinsic/intrinsic.js +2 -2
  55. package/build/require/type/optional/index.d.ts +1 -0
  56. package/build/require/type/optional/index.js +1 -0
  57. package/build/require/type/optional/optional-from-mapped-result.d.ts +12 -0
  58. package/build/require/type/optional/optional-from-mapped-result.js +22 -0
  59. package/build/require/type/optional/optional.d.ts +19 -2
  60. package/build/require/type/optional/optional.js +18 -2
  61. package/build/require/type/readonly/index.d.ts +1 -0
  62. package/build/require/type/readonly/index.js +1 -0
  63. package/build/require/type/readonly/readonly-from-mapped-result.d.ts +12 -0
  64. package/build/require/type/readonly/readonly-from-mapped-result.js +22 -0
  65. package/build/require/type/readonly/readonly.d.ts +18 -1
  66. package/build/require/type/readonly/readonly.js +18 -2
  67. package/build/require/type/record/record.d.ts +2 -2
  68. package/build/require/type/record/record.js +1 -2
  69. package/build/require/type/schema/schema.d.ts +1 -1
  70. package/build/require/type/symbol/symbol.d.ts +1 -1
  71. package/build/require/type/template-literal/finite.d.ts +7 -5
  72. package/build/require/type/template-literal/finite.js +16 -6
  73. package/build/require/type/template-literal/generate.d.ts +14 -8
  74. package/build/require/type/template-literal/generate.js +22 -11
  75. package/build/require/type/template-literal/index.d.ts +1 -1
  76. package/build/require/type/template-literal/index.js +1 -1
  77. package/build/require/type/template-literal/{parser.js → parse.js} +7 -2
  78. package/build/require/type/template-literal/syntax.d.ts +1 -1
  79. package/build/require/type/template-literal/syntax.js +0 -1
  80. package/build/require/type/template-literal/template-literal.d.ts +2 -2
  81. package/build/require/type/template-literal/template-literal.js +1 -1
  82. package/build/require/type/template-literal/union.d.ts +2 -2
  83. package/build/require/type/template-literal/union.js +5 -10
  84. package/build/require/type/type/json.d.ts +19 -7
  85. package/build/require/type/type/json.js +5 -5
  86. package/build/require/value/cast/cast.js +20 -20
  87. package/build/require/value/check/check.js +62 -62
  88. package/build/require/value/clean/clean.js +16 -16
  89. package/build/require/value/convert/convert.js +36 -36
  90. package/build/require/value/create/create.js +65 -66
  91. package/build/require/value/default/default.js +16 -16
  92. package/build/require/value/transform/decode.js +18 -18
  93. package/build/require/value/transform/encode.js +18 -18
  94. package/build/require/value/transform/has.js +28 -28
  95. package/package.json +1 -1
  96. package/readme.md +52 -52
  97. /package/build/import/type/template-literal/{parser.d.mts → parse.d.mts} +0 -0
  98. /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';
@@ -36,12 +36,12 @@ export { Null, type TNull } from './type/null/index';
36
36
  export { Number, type TNumber, type NumberOptions } from './type/number/index';
37
37
  export { Object, type TObject, type TProperties, type ObjectOptions } from './type/object/index';
38
38
  export { Omit, type TOmit, type TOmitFromMappedKey } from './type/omit/index';
39
- export { Optional, type TOptional } from './type/optional/index';
39
+ export { Optional, OptionalFromMappedResult, type TOptional, type TOptionalWithFlag, type TOptionalFromMappedResult } from './type/optional/index';
40
40
  export { Parameters, type TParameters } from './type/parameters/index';
41
41
  export { Partial, PartialFromMappedResult, type TPartial, type TPartialFromMappedResult } from './type/partial/index';
42
42
  export { Pick, type TPick, type TPickFromMappedKey } from './type/pick/index';
43
43
  export { Promise, type TPromise } from './type/promise/index';
44
- export { Readonly, type TReadonly } from './type/readonly/index';
44
+ export { Readonly, ReadonlyFromMappedResult, type TReadonly, type TReadonlyWithFlag, type TReadonlyFromMappedResult } from './type/readonly/index';
45
45
  export { ReadonlyOptional, type TReadonlyOptional } from './type/readonly-optional/index';
46
46
  export { Record, type TRecord } from './type/record/index';
47
47
  export { Recursive, type TRecursive, type TThis } from './type/recursive/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.Type = exports.Void = 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.Readonly = exports.Promise = exports.Pick = exports.PartialFromMappedResult = exports.Partial = exports.Parameters = 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 = 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
  // ------------------------------------------------------------------
@@ -115,6 +115,7 @@ var index_37 = require("./type/omit/index");
115
115
  Object.defineProperty(exports, "Omit", { enumerable: true, get: function () { return index_37.Omit; } });
116
116
  var index_38 = require("./type/optional/index");
117
117
  Object.defineProperty(exports, "Optional", { enumerable: true, get: function () { return index_38.Optional; } });
118
+ Object.defineProperty(exports, "OptionalFromMappedResult", { enumerable: true, get: function () { return index_38.OptionalFromMappedResult; } });
118
119
  var index_39 = require("./type/parameters/index");
119
120
  Object.defineProperty(exports, "Parameters", { enumerable: true, get: function () { return index_39.Parameters; } });
120
121
  var index_40 = require("./type/partial/index");
@@ -126,6 +127,7 @@ var index_42 = require("./type/promise/index");
126
127
  Object.defineProperty(exports, "Promise", { enumerable: true, get: function () { return index_42.Promise; } });
127
128
  var index_43 = require("./type/readonly/index");
128
129
  Object.defineProperty(exports, "Readonly", { enumerable: true, get: function () { return index_43.Readonly; } });
130
+ Object.defineProperty(exports, "ReadonlyFromMappedResult", { enumerable: true, get: function () { return index_43.ReadonlyFromMappedResult; } });
129
131
  var index_44 = require("./type/readonly-optional/index");
130
132
  Object.defineProperty(exports, "ReadonlyOptional", { enumerable: true, get: function () { return index_44.ReadonlyOptional; } });
131
133
  var index_45 = require("./type/record/index");
@@ -151,9 +153,11 @@ Object.defineProperty(exports, "Symbol", { enumerable: true, get: function () {
151
153
  var index_55 = require("./type/template-literal/index");
152
154
  Object.defineProperty(exports, "TemplateLiteral", { enumerable: true, get: function () { return index_55.TemplateLiteral; } });
153
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; } });
154
157
  Object.defineProperty(exports, "TemplateLiteralParse", { enumerable: true, get: function () { return index_55.TemplateLiteralParse; } });
155
158
  Object.defineProperty(exports, "TemplateLiteralParseExact", { enumerable: true, get: function () { return index_55.TemplateLiteralParseExact; } });
156
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; } });
157
161
  var index_56 = require("./type/transform/index");
158
162
  Object.defineProperty(exports, "Transform", { enumerable: true, get: function () { return index_56.Transform; } });
159
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);
@@ -1 +1,2 @@
1
+ export * from './optional-from-mapped-result';
1
2
  export * from './optional';
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./optional-from-mapped-result"), exports);
18
19
  __exportStar(require("./optional"), exports);
@@ -0,0 +1,12 @@
1
+ import type { TProperties } from '../object/index';
2
+ import { type TMappedResult } from '../mapped/index';
3
+ import { type TOptionalWithFlag } from './optional';
4
+ type FromProperties<K extends TProperties, F extends boolean> = ({
5
+ [K2 in keyof K]: TOptionalWithFlag<K[K2], F>;
6
+ });
7
+ declare function FromProperties<K extends TProperties, F extends boolean>(K: K, F: F): FromProperties<K, F>;
8
+ type FromMappedResult<K extends TMappedResult, F extends boolean> = (FromProperties<K['properties'], F>);
9
+ declare function FromMappedResult<K extends TMappedResult, F extends boolean>(K: K, F: F): FromMappedResult<K, F>;
10
+ export type TOptionalFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = FromMappedResult<T, F>> = (TMappedResult<P>);
11
+ export declare function OptionalFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = FromMappedResult<T, F>>(T: T, F: F): TMappedResult<P>;
12
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.OptionalFromMappedResult = void 0;
5
+ const index_1 = require("../mapped/index");
6
+ const optional_1 = require("./optional");
7
+ // prettier-ignore
8
+ function FromProperties(K, F) {
9
+ return globalThis.Object.getOwnPropertyNames(K).reduce((Acc, K2) => {
10
+ return { ...Acc, [K2]: (0, optional_1.Optional)(K[K2], F) };
11
+ }, {});
12
+ }
13
+ // prettier-ignore
14
+ function FromMappedResult(K, F) {
15
+ return FromProperties(K.properties, F);
16
+ }
17
+ // prettier-ignore
18
+ function OptionalFromMappedResult(T, F) {
19
+ const P = FromMappedResult(T, F);
20
+ return (0, index_1.MappedResult)(P);
21
+ }
22
+ exports.OptionalFromMappedResult = OptionalFromMappedResult;
@@ -1,7 +1,24 @@
1
1
  import type { TSchema } from '../schema/index';
2
+ import type { Ensure } from '../helpers/index';
2
3
  import { OptionalKind } from '../symbols/index';
4
+ import type { TMappedResult } from '../mapped/index';
5
+ import { type TOptionalFromMappedResult } from './optional-from-mapped-result';
6
+ type RemoveOptional<T extends TSchema> = T extends TOptional<infer S> ? S : T;
7
+ declare function RemoveOptional<T extends TSchema>(schema: T): Record<PropertyKey, any>;
8
+ type AddOptional<T extends TSchema> = T extends TOptional<infer S> ? TOptional<S> : Ensure<TOptional<T>>;
9
+ declare function AddOptional<T extends TSchema>(schema: T): T & {
10
+ [OptionalKind]: string;
11
+ };
12
+ export type TOptionalWithFlag<T extends TSchema, F extends boolean> = F extends false ? RemoveOptional<T> : AddOptional<T>;
3
13
  export type TOptional<T extends TSchema> = T & {
4
14
  [OptionalKind]: 'Optional';
5
15
  };
6
- /** `[Json]` Creates an Optional property */
7
- export declare function Optional<T extends TSchema>(schema: T): TOptional<T>;
16
+ /** `[Json]` Creates a Optional property */
17
+ export declare function Optional<T extends TMappedResult, F extends boolean>(schema: T, enable: F): TOptionalFromMappedResult<T, F>;
18
+ /** `[Json]` Creates a Optional property */
19
+ export declare function Optional<T extends TSchema, F extends boolean>(schema: T, enable: F): TOptionalWithFlag<T, F>;
20
+ /** `[Json]` Creates a Optional property */
21
+ export declare function Optional<T extends TMappedResult>(schema: T): TOptionalFromMappedResult<T, true>;
22
+ /** `[Json]` Creates a Optional property */
23
+ export declare function Optional<T extends TSchema>(schema: T): TOptionalWithFlag<T, true>;
24
+ export {};
@@ -4,8 +4,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Optional = void 0;
5
5
  const index_1 = require("../symbols/index");
6
6
  const type_1 = require("../clone/type");
7
- /** `[Json]` Creates an Optional property */
8
- function Optional(schema) {
7
+ const index_2 = require("../discard/index");
8
+ const optional_from_mapped_result_1 = require("./optional-from-mapped-result");
9
+ const type_2 = require("../guard/type");
10
+ function RemoveOptional(schema) {
11
+ return (0, index_2.Discard)((0, type_1.CloneType)(schema), [index_1.OptionalKind]);
12
+ }
13
+ function AddOptional(schema) {
9
14
  return { ...(0, type_1.CloneType)(schema), [index_1.OptionalKind]: 'Optional' };
10
15
  }
16
+ // prettier-ignore
17
+ function OptionalWithFlag(schema, F) {
18
+ return (F === false
19
+ ? RemoveOptional(schema)
20
+ : AddOptional(schema));
21
+ }
22
+ /** `[Json]` Creates a Optional property */
23
+ function Optional(schema, enable) {
24
+ const F = enable ?? true;
25
+ return (0, type_2.IsMappedResult)(schema) ? (0, optional_from_mapped_result_1.OptionalFromMappedResult)(schema, F) : OptionalWithFlag(schema, F);
26
+ }
11
27
  exports.Optional = Optional;
@@ -1 +1,2 @@
1
+ export * from './readonly-from-mapped-result';
1
2
  export * from './readonly';
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./readonly-from-mapped-result"), exports);
18
19
  __exportStar(require("./readonly"), exports);
@@ -0,0 +1,12 @@
1
+ import type { TProperties } from '../object/index';
2
+ import { type TMappedResult } from '../mapped/index';
3
+ import { type TReadonlyWithFlag } from './readonly';
4
+ type FromProperties<K extends TProperties, F extends boolean> = ({
5
+ [K2 in keyof K]: TReadonlyWithFlag<K[K2], F>;
6
+ });
7
+ declare function FromProperties<K extends TProperties, F extends boolean>(K: K, F: F): FromProperties<K, F>;
8
+ type FromMappedResult<K extends TMappedResult, F extends boolean> = (FromProperties<K['properties'], F>);
9
+ declare function FromMappedResult<K extends TMappedResult, F extends boolean>(K: K, F: F): FromMappedResult<K, F>;
10
+ export type TReadonlyFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = FromMappedResult<T, F>> = (TMappedResult<P>);
11
+ export declare function ReadonlyFromMappedResult<T extends TMappedResult, F extends boolean, P extends TProperties = FromMappedResult<T, F>>(T: T, F: F): TMappedResult<P>;
12
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ReadonlyFromMappedResult = void 0;
5
+ const index_1 = require("../mapped/index");
6
+ const readonly_1 = require("./readonly");
7
+ // prettier-ignore
8
+ function FromProperties(K, F) {
9
+ return globalThis.Object.getOwnPropertyNames(K).reduce((Acc, K2) => {
10
+ return { ...Acc, [K2]: (0, readonly_1.Readonly)(K[K2], F) };
11
+ }, {});
12
+ }
13
+ // prettier-ignore
14
+ function FromMappedResult(K, F) {
15
+ return FromProperties(K.properties, F);
16
+ }
17
+ // prettier-ignore
18
+ function ReadonlyFromMappedResult(T, F) {
19
+ const P = FromMappedResult(T, F);
20
+ return (0, index_1.MappedResult)(P);
21
+ }
22
+ exports.ReadonlyFromMappedResult = ReadonlyFromMappedResult;
@@ -1,7 +1,24 @@
1
1
  import type { TSchema } from '../schema/index';
2
+ import type { Ensure } from '../helpers/index';
2
3
  import { ReadonlyKind } from '../symbols/index';
4
+ import type { TMappedResult } from '../mapped/index';
5
+ import { type TReadonlyFromMappedResult } from './readonly-from-mapped-result';
6
+ type RemoveReadonly<T extends TSchema> = T extends TReadonly<infer S> ? S : T;
7
+ declare function RemoveReadonly<T extends TSchema>(schema: T): Record<PropertyKey, any>;
8
+ type AddReadonly<T extends TSchema> = T extends TReadonly<infer S> ? TReadonly<S> : Ensure<TReadonly<T>>;
9
+ declare function AddReadonly<T extends TSchema>(schema: T): T & {
10
+ [ReadonlyKind]: string;
11
+ };
12
+ export type TReadonlyWithFlag<T extends TSchema, F extends boolean> = F extends false ? RemoveReadonly<T> : AddReadonly<T>;
3
13
  export type TReadonly<T extends TSchema> = T & {
4
14
  [ReadonlyKind]: 'Readonly';
5
15
  };
6
16
  /** `[Json]` Creates a Readonly property */
7
- export declare function Readonly<T extends TSchema>(schema: T): TReadonly<T>;
17
+ export declare function Readonly<T extends TMappedResult, F extends boolean>(schema: T, enable: F): TReadonlyFromMappedResult<T, F>;
18
+ /** `[Json]` Creates a Readonly property */
19
+ export declare function Readonly<T extends TSchema, F extends boolean>(schema: T, enable: F): TReadonlyWithFlag<T, F>;
20
+ /** `[Json]` Creates a Readonly property */
21
+ export declare function Readonly<T extends TMappedResult>(schema: T): TReadonlyFromMappedResult<T, true>;
22
+ /** `[Json]` Creates a Readonly property */
23
+ export declare function Readonly<T extends TSchema>(schema: T): TReadonlyWithFlag<T, true>;
24
+ export {};