@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
@@ -4,8 +4,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Readonly = void 0;
5
5
  const index_1 = require("../symbols/index");
6
6
  const type_1 = require("../clone/type");
7
- /** `[Json]` Creates a Readonly property */
8
- function Readonly(schema) {
7
+ const index_2 = require("../discard/index");
8
+ const readonly_from_mapped_result_1 = require("./readonly-from-mapped-result");
9
+ const type_2 = require("../guard/type");
10
+ function RemoveReadonly(schema) {
11
+ return (0, index_2.Discard)((0, type_1.CloneType)(schema), [index_1.ReadonlyKind]);
12
+ }
13
+ function AddReadonly(schema) {
9
14
  return { ...(0, type_1.CloneType)(schema), [index_1.ReadonlyKind]: 'Readonly' };
10
15
  }
16
+ // prettier-ignore
17
+ function ReadonlyWithFlag(schema, F) {
18
+ return (F === false
19
+ ? RemoveReadonly(schema)
20
+ : AddReadonly(schema));
21
+ }
22
+ /** `[Json]` Creates a Readonly property */
23
+ function Readonly(schema, enable) {
24
+ const F = enable ?? true;
25
+ return (0, type_2.IsMappedResult)(schema) ? (0, readonly_from_mapped_result_1.ReadonlyFromMappedResult)(schema, F) : ReadonlyWithFlag(schema, F);
26
+ }
11
27
  exports.Readonly = Readonly;
@@ -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';
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  __exportStar(require("./finite"), exports);
19
19
  __exportStar(require("./generate"), exports);
20
20
  __exportStar(require("./syntax"), exports);
21
- __exportStar(require("./parser"), exports);
21
+ __exportStar(require("./parse"), exports);
22
22
  __exportStar(require("./pattern"), exports);
23
23
  __exportStar(require("./union"), exports);
24
24
  __exportStar(require("./template-literal"), exports);
@@ -132,17 +132,22 @@ function And(pattern) {
132
132
  (expressions.length === 1) ? expressions[0] :
133
133
  { type: 'and', expr: expressions });
134
134
  }
135
+ // ------------------------------------------------------------------
136
+ // TemplateLiteralParse
137
+ // ------------------------------------------------------------------
135
138
  /** Parses a pattern and returns an expression tree */
136
- // prettier-ignore
137
139
  function TemplateLiteralParse(pattern) {
140
+ // prettier-ignore
138
141
  return (IsGroup(pattern) ? TemplateLiteralParse(InGroup(pattern)) :
139
142
  IsPrecedenceOr(pattern) ? Or(pattern) :
140
143
  IsPrecedenceAnd(pattern) ? And(pattern) :
141
144
  { type: 'const', const: pattern });
142
145
  }
143
146
  exports.TemplateLiteralParse = TemplateLiteralParse;
147
+ // ------------------------------------------------------------------
148
+ // TemplateLiteralParseExact
149
+ // ------------------------------------------------------------------
144
150
  /** Parses a pattern and strips forward and trailing ^ and $ */
145
- // prettier-ignore
146
151
  function TemplateLiteralParseExact(pattern) {
147
152
  return TemplateLiteralParse(pattern.slice(1, pattern.length - 1));
148
153
  }
@@ -14,7 +14,7 @@ type FromUnion<T extends string> = UnionEvaluated<FromUnionLiteral<T>>;
14
14
  type FromTerminal<T extends string> = T extends 'boolean' ? TBoolean : T extends 'bigint' ? TBigInt : T extends 'number' ? TNumber : T extends 'string' ? TString : FromUnion<T>;
15
15
  type FromString<T extends string> = T extends `{${infer L}}${infer R}` ? [FromTerminal<L>, ...FromString<R>] : T extends `${infer L}$${infer R}` ? [TLiteral<L>, ...FromString<R>] : T extends `${infer L}` ? [TLiteral<L>] : [
16
16
  ];
17
- export type TemplateLiteralSyntax<T extends string> = (TTemplateLiteral<Assert<FromString<T>, TTemplateLiteralKind[]>>);
17
+ export type TTemplateLiteralSyntax<T extends string> = (TTemplateLiteral<Assert<FromString<T>, TTemplateLiteralKind[]>>);
18
18
  /** Parses TemplateLiteralSyntax and returns a tuple of TemplateLiteralKinds */
19
19
  export declare function TemplateLiteralSyntax(syntax: string): TTemplateLiteralKind[];
20
20
  export {};
@@ -53,7 +53,6 @@ function* FromSyntax(syntax) {
53
53
  }
54
54
  yield (0, index_1.Literal)(syntax);
55
55
  }
56
- // prettier-ignore
57
56
  /** Parses TemplateLiteralSyntax and returns a tuple of TemplateLiteralKinds */
58
57
  function TemplateLiteralSyntax(syntax) {
59
58
  return [...FromSyntax(syntax)];
@@ -9,7 +9,7 @@ import type { TString } from '../string/index';
9
9
  import type { TBoolean } from '../boolean/index';
10
10
  import type { TNever } from '../never/index';
11
11
  import type { Static } from '../static/index';
12
- import { TemplateLiteralSyntax } from './syntax';
12
+ import { TTemplateLiteralSyntax } from './syntax';
13
13
  import { EmptyString } from '../helpers/index';
14
14
  import { Kind } from '../symbols/index';
15
15
  type TemplateLiteralStaticKind<T, Acc extends string> = T extends TUnion<infer U> ? {
@@ -24,7 +24,7 @@ export interface TTemplateLiteral<T extends TTemplateLiteralKind[] = TTemplateLi
24
24
  pattern: string;
25
25
  }
26
26
  /** `[Json]` Creates a TemplateLiteral type from template dsl string */
27
- export declare function TemplateLiteral<T extends string>(syntax: T, options?: SchemaOptions): TemplateLiteralSyntax<T>;
27
+ export declare function TemplateLiteral<T extends string>(syntax: T, options?: SchemaOptions): TTemplateLiteralSyntax<T>;
28
28
  /** `[Json]` Creates a TemplateLiteral type */
29
29
  export declare function TemplateLiteral<T extends TTemplateLiteralKind[]>(kinds: [...T], options?: SchemaOptions): TTemplateLiteral<T>;
30
30
  export {};
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.TemplateLiteral = void 0;
5
- const pattern_1 = require("./pattern");
6
5
  const syntax_1 = require("./syntax");
6
+ const pattern_1 = require("./pattern");
7
7
  const value_1 = require("../guard/value");
8
8
  const index_1 = require("../symbols/index");
9
9
  /** `[Json]` Creates a TemplateLiteral type */
@@ -3,5 +3,5 @@ import { type TUnion } from '../union/index';
3
3
  import { type TLiteral } from '../literal/index';
4
4
  import { type TString } from '../string/index';
5
5
  import { type TNever } from '../never/index';
6
- /** Resolves a template literal as a TUnion */
7
- export declare function TemplateLiteralToUnion(template: TTemplateLiteral): TNever | TString | TUnion<TLiteral[]>;
6
+ /** Returns a Union from the given TemplateLiteral */
7
+ export declare function TemplateLiteralToUnion(schema: TTemplateLiteral): TNever | TString | TUnion<TLiteral[]>;
@@ -4,19 +4,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.TemplateLiteralToUnion = void 0;
5
5
  const index_1 = require("../union/index");
6
6
  const index_2 = require("../literal/index");
7
- const index_3 = require("../string/index");
8
7
  const generate_1 = require("./generate");
9
- const parser_1 = require("./parser");
10
- const finite_1 = require("./finite");
11
8
  // ------------------------------------------------------------------
12
9
  // TemplateLiteralToUnion
13
10
  // ------------------------------------------------------------------
14
- /** Resolves a template literal as a TUnion */
15
- function TemplateLiteralToUnion(template) {
16
- const expression = (0, parser_1.TemplateLiteralParseExact)(template.pattern);
17
- if (!(0, finite_1.IsTemplateLiteralFinite)(expression))
18
- return (0, index_3.String)();
19
- const literals = [...(0, generate_1.TemplateLiteralGenerate)(expression)].map((value) => (0, index_2.Literal)(value));
20
- return (0, index_1.Union)(literals);
11
+ /** Returns a Union from the given TemplateLiteral */
12
+ function TemplateLiteralToUnion(schema) {
13
+ const R = (0, generate_1.TemplateLiteralGenerate)(schema);
14
+ const L = R.map((S) => (0, index_2.Literal)(S));
15
+ return (0, index_1.Union)(L);
21
16
  }
22
17
  exports.TemplateLiteralToUnion = TemplateLiteralToUnion;
@@ -22,10 +22,10 @@ import { type TMappedKey } from '../mapped/index';
22
22
  import { type TNumber, type NumberOptions } from '../number/index';
23
23
  import { type TObject, type TProperties, type ObjectOptions } from '../object/index';
24
24
  import { type TOmit, type TOmitFromMappedKey } from '../omit/index';
25
- import { type TOptional } from '../optional/index';
25
+ import { type TOptionalWithFlag, type TOptionalFromMappedResult } from '../optional/index';
26
26
  import { type TPartial, type TPartialFromMappedResult } from '../partial/index';
27
27
  import { type TPick, type TPickFromMappedKey } from '../pick/index';
28
- import { type TReadonly } from '../readonly/index';
28
+ import { type TReadonlyWithFlag, type TReadonlyFromMappedResult } from '../readonly/index';
29
29
  import { type TReadonlyOptional } from '../readonly-optional/index';
30
30
  import { type TRecordOrObject } from '../record/index';
31
31
  import { type TRecursive, type TThis } from '../recursive/index';
@@ -34,7 +34,7 @@ import { type TRequired, type TRequiredFromMappedResult } from '../required/inde
34
34
  import { type TRest } from '../rest/index';
35
35
  import { type TSchema, type SchemaOptions } from '../schema/index';
36
36
  import { type TString, type StringOptions } from '../string/index';
37
- import { type TTemplateLiteral, type TTemplateLiteralKind, type TemplateLiteralSyntax } from '../template-literal/index';
37
+ import { type TTemplateLiteral, type TTemplateLiteralKind, type TTemplateLiteralSyntax } from '../template-literal/index';
38
38
  import { TransformDecodeBuilder } from '../transform/index';
39
39
  import { type TTuple } from '../tuple/index';
40
40
  import { Union } from '../union/index';
@@ -47,9 +47,21 @@ export declare class JsonTypeBuilder {
47
47
  /** `[Json]` Creates a Readonly and Optional property */
48
48
  ReadonlyOptional<T extends TSchema>(schema: T): TReadonlyOptional<T>;
49
49
  /** `[Json]` Creates a Readonly property */
50
- Readonly<T extends TSchema>(schema: T): TReadonly<T>;
51
- /** `[Json]` Creates an Optional property */
52
- Optional<T extends TSchema>(schema: T): TOptional<T>;
50
+ Readonly<T extends TMappedResult, F extends boolean>(schema: T, enable: F): TReadonlyFromMappedResult<T, F>;
51
+ /** `[Json]` Creates a Readonly property */
52
+ Readonly<T extends TSchema, F extends boolean>(schema: T, enable: F): TReadonlyWithFlag<T, F>;
53
+ /** `[Json]` Creates a Optional property */
54
+ Readonly<T extends TMappedResult>(schema: T): TReadonlyFromMappedResult<T, true>;
55
+ /** `[Json]` Creates a Readonly property */
56
+ Readonly<T extends TSchema>(schema: T): TReadonlyWithFlag<T, true>;
57
+ /** `[Json]` Creates a Optional property */
58
+ Optional<T extends TMappedResult, F extends boolean>(schema: T, enable: F): TOptionalFromMappedResult<T, F>;
59
+ /** `[Json]` Creates a Optional property */
60
+ Optional<T extends TSchema, F extends boolean>(schema: T, enable: F): TOptionalWithFlag<T, F>;
61
+ /** `[Json]` Creates a Optional property */
62
+ Optional<T extends TMappedResult>(schema: T): TOptionalFromMappedResult<T, true>;
63
+ /** `[Json]` Creates a Optional property */
64
+ Optional<T extends TSchema>(schema: T): TOptionalWithFlag<T, true>;
53
65
  /** `[Json]` Creates an Any type */
54
66
  Any(options?: SchemaOptions): TAny;
55
67
  /** `[Json]` Creates an Array type */
@@ -145,7 +157,7 @@ export declare class JsonTypeBuilder {
145
157
  /** `[Json]` Creates a String type */
146
158
  String(options?: StringOptions): TString;
147
159
  /** `[Json]` Creates a TemplateLiteral type from template dsl string */
148
- TemplateLiteral<T extends string>(syntax: T, options?: SchemaOptions): TemplateLiteralSyntax<T>;
160
+ TemplateLiteral<T extends string>(syntax: T, options?: SchemaOptions): TTemplateLiteralSyntax<T>;
149
161
  /** `[Json]` Creates a TemplateLiteral type */
150
162
  TemplateLiteral<T extends TTemplateLiteralKind[]>(kinds: [...T], options?: SchemaOptions): TTemplateLiteral<T>;
151
163
  /** `[Json]` Creates a Transform type */
@@ -60,12 +60,12 @@ class JsonTypeBuilder {
60
60
  return (0, index_28.ReadonlyOptional)(schema);
61
61
  }
62
62
  /** `[Json]` Creates a Readonly property */
63
- Readonly(schema) {
64
- return (0, index_27.Readonly)(schema);
63
+ Readonly(schema, enable) {
64
+ return (0, index_27.Readonly)(schema, enable ?? true);
65
65
  }
66
- /** `[Json]` Creates an Optional property */
67
- Optional(schema) {
68
- return (0, index_24.Optional)(schema);
66
+ /** `[Json]` Creates a Optional property */
67
+ Optional(schema, enable) {
68
+ return (0, index_24.Optional)(schema, enable ?? true);
69
69
  }
70
70
  // ------------------------------------------------------------------------
71
71
  // Types
@@ -97,7 +97,7 @@ function Default(schema, references, value) {
97
97
  // ------------------------------------------------------------------
98
98
  // Cast
99
99
  // ------------------------------------------------------------------
100
- function TArray(schema, references, value) {
100
+ function FromArray(schema, references, value) {
101
101
  if ((0, index_4.Check)(schema, references, value))
102
102
  return (0, index_5.Clone)(value);
103
103
  const created = (0, index_1.IsArray)(value) ? (0, index_5.Clone)(value) : (0, index_3.Create)(schema, references);
@@ -111,7 +111,7 @@ function TArray(schema, references, value) {
111
111
  throw new ValueCastArrayUniqueItemsTypeError(schema, unique);
112
112
  return unique;
113
113
  }
114
- function TConstructor(schema, references, value) {
114
+ function FromConstructor(schema, references, value) {
115
115
  if ((0, index_4.Check)(schema, references, value))
116
116
  return (0, index_3.Create)(schema, references);
117
117
  const required = new Set(schema.returns.required || []);
@@ -123,15 +123,15 @@ function TConstructor(schema, references, value) {
123
123
  }
124
124
  return result;
125
125
  }
126
- function TIntersect(schema, references, value) {
126
+ function FromIntersect(schema, references, value) {
127
127
  const created = (0, index_3.Create)(schema, references);
128
128
  const mapped = (0, index_1.IsPlainObject)(created) && (0, index_1.IsPlainObject)(value) ? { ...created, ...value } : value;
129
129
  return (0, index_4.Check)(schema, references, mapped) ? mapped : (0, index_3.Create)(schema, references);
130
130
  }
131
- function TNever(schema, references, value) {
131
+ function FromNever(schema, references, value) {
132
132
  throw new ValueCastNeverTypeError(schema);
133
133
  }
134
- function TObject(schema, references, value) {
134
+ function FromObject(schema, references, value) {
135
135
  if ((0, index_4.Check)(schema, references, value))
136
136
  return value;
137
137
  if (value === null || typeof value !== 'object')
@@ -154,7 +154,7 @@ function TObject(schema, references, value) {
154
154
  }
155
155
  return result;
156
156
  }
157
- function TRecord(schema, references, value) {
157
+ function FromRecord(schema, references, value) {
158
158
  if ((0, index_4.Check)(schema, references, value))
159
159
  return (0, index_5.Clone)(value);
160
160
  if (value === null || typeof value !== 'object' || Array.isArray(value) || value instanceof Date)
@@ -167,13 +167,13 @@ function TRecord(schema, references, value) {
167
167
  }
168
168
  return result;
169
169
  }
170
- function TRef(schema, references, value) {
170
+ function FromRef(schema, references, value) {
171
171
  return Visit((0, index_6.Deref)(schema, references), references, value);
172
172
  }
173
- function TThis(schema, references, value) {
173
+ function FromThis(schema, references, value) {
174
174
  return Visit((0, index_6.Deref)(schema, references), references, value);
175
175
  }
176
- function TTuple(schema, references, value) {
176
+ function FromTuple(schema, references, value) {
177
177
  if ((0, index_4.Check)(schema, references, value))
178
178
  return (0, index_5.Clone)(value);
179
179
  if (!(0, index_1.IsArray)(value))
@@ -182,7 +182,7 @@ function TTuple(schema, references, value) {
182
182
  return [];
183
183
  return schema.items.map((schema, index) => Visit(schema, references, value[index]));
184
184
  }
185
- function TUnion(schema, references, value) {
185
+ function FromUnion(schema, references, value) {
186
186
  return (0, index_4.Check)(schema, references, value) ? (0, index_5.Clone)(value) : CastUnion(schema, references, value);
187
187
  }
188
188
  function Visit(schema, references, value) {
@@ -193,25 +193,25 @@ function Visit(schema, references, value) {
193
193
  // Structural
194
194
  // --------------------------------------------------------------
195
195
  case 'Array':
196
- return TArray(schema_, references_, value);
196
+ return FromArray(schema_, references_, value);
197
197
  case 'Constructor':
198
- return TConstructor(schema_, references_, value);
198
+ return FromConstructor(schema_, references_, value);
199
199
  case 'Intersect':
200
- return TIntersect(schema_, references_, value);
200
+ return FromIntersect(schema_, references_, value);
201
201
  case 'Never':
202
- return TNever(schema_, references_, value);
202
+ return FromNever(schema_, references_, value);
203
203
  case 'Object':
204
- return TObject(schema_, references_, value);
204
+ return FromObject(schema_, references_, value);
205
205
  case 'Record':
206
- return TRecord(schema_, references_, value);
206
+ return FromRecord(schema_, references_, value);
207
207
  case 'Ref':
208
- return TRef(schema_, references_, value);
208
+ return FromRef(schema_, references_, value);
209
209
  case 'This':
210
- return TThis(schema_, references_, value);
210
+ return FromThis(schema_, references_, value);
211
211
  case 'Tuple':
212
- return TTuple(schema_, references_, value);
212
+ return FromTuple(schema_, references_, value);
213
213
  case 'Union':
214
- return TUnion(schema_, references_, value);
214
+ return FromUnion(schema_, references_, value);
215
215
  // --------------------------------------------------------------
216
216
  // DefaultClone
217
217
  // --------------------------------------------------------------