@sinclair/typebox 0.32.23 → 0.32.25

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 (120) hide show
  1. package/build/import/type/awaited/awaited.mjs +1 -1
  2. package/build/import/type/clone/value.mjs +8 -3
  3. package/build/import/type/composite/composite.mjs +14 -10
  4. package/build/import/type/const/const.mjs +4 -3
  5. package/build/import/type/deref/deref.d.mts +1 -1
  6. package/build/import/type/deref/deref.mjs +6 -4
  7. package/build/import/type/exclude/exclude-from-mapped-result.mjs +4 -3
  8. package/build/import/type/exclude/exclude.mjs +1 -1
  9. package/build/import/type/extends/extends-from-mapped-result.mjs +4 -3
  10. package/build/import/type/extends/extends.mjs +1 -1
  11. package/build/import/type/extract/extract-from-mapped-result.mjs +4 -3
  12. package/build/import/type/extract/extract.mjs +1 -1
  13. package/build/import/type/guard/index.d.mts +1 -0
  14. package/build/import/type/guard/index.mjs +1 -0
  15. package/build/import/type/guard/kind.d.mts +136 -0
  16. package/build/import/type/guard/kind.mjs +217 -0
  17. package/build/import/type/guard/type.d.mts +2 -2
  18. package/build/import/type/indexed/indexed-from-mapped-result.mjs +5 -3
  19. package/build/import/type/indexed/indexed-property-keys.mjs +5 -4
  20. package/build/import/type/indexed/indexed.mjs +1 -1
  21. package/build/import/type/intersect/intersect-create.mjs +1 -1
  22. package/build/import/type/intersect/intersect-evaluated.mjs +1 -2
  23. package/build/import/type/intersect/intersect.mjs +1 -1
  24. package/build/import/type/intrinsic/intrinsic.mjs +1 -1
  25. package/build/import/type/keyof/keyof-from-mapped-result.mjs +4 -3
  26. package/build/import/type/keyof/keyof-property-keys.mjs +5 -4
  27. package/build/import/type/keyof/keyof.mjs +1 -1
  28. package/build/import/type/mapped/mapped.d.mts +1 -1
  29. package/build/import/type/mapped/mapped.mjs +14 -12
  30. package/build/import/type/object/object.mjs +4 -2
  31. package/build/import/type/omit/omit-from-mapped-result.mjs +4 -3
  32. package/build/import/type/omit/omit.mjs +2 -4
  33. package/build/import/type/optional/optional-from-mapped-result.mjs +4 -3
  34. package/build/import/type/optional/optional.mjs +1 -1
  35. package/build/import/type/partial/partial-from-mapped-result.mjs +4 -3
  36. package/build/import/type/partial/partial.mjs +5 -4
  37. package/build/import/type/pick/pick-from-mapped-result.mjs +4 -3
  38. package/build/import/type/pick/pick.d.mts +1 -1
  39. package/build/import/type/pick/pick.mjs +6 -4
  40. package/build/import/type/readonly/readonly-from-mapped-result.mjs +4 -3
  41. package/build/import/type/readonly/readonly.mjs +1 -1
  42. package/build/import/type/record/record.mjs +5 -3
  43. package/build/import/type/required/required-from-mapped-result.mjs +4 -3
  44. package/build/import/type/required/required.mjs +5 -4
  45. package/build/import/type/rest/rest.mjs +4 -4
  46. package/build/import/type/sets/set.mjs +4 -1
  47. package/build/import/type/template-literal/pattern.mjs +1 -2
  48. package/build/import/type/transform/transform.mjs +1 -1
  49. package/build/import/type/union/union-evaluated.mjs +1 -1
  50. package/build/import/value/clean/clean.mjs +1 -1
  51. package/build/import/value/clone/clone.mjs +8 -2
  52. package/build/import/value/convert/convert.mjs +8 -6
  53. package/build/import/value/create/create.mjs +11 -7
  54. package/build/import/value/hash/hash.mjs +1 -1
  55. package/build/import/value/mutate/mutate.mjs +2 -2
  56. package/build/import/value/transform/decode.mjs +30 -30
  57. package/build/import/value/transform/encode.mjs +33 -30
  58. package/build/import/value/value/value.d.mts +2 -2
  59. package/build/import/value/value/value.mjs +1 -1
  60. package/build/require/type/awaited/awaited.js +4 -4
  61. package/build/require/type/clone/value.js +8 -3
  62. package/build/require/type/composite/composite.js +15 -11
  63. package/build/require/type/const/const.js +4 -3
  64. package/build/require/type/deref/deref.d.ts +1 -1
  65. package/build/require/type/deref/deref.js +17 -15
  66. package/build/require/type/exclude/exclude-from-mapped-result.js +4 -3
  67. package/build/require/type/exclude/exclude.js +4 -4
  68. package/build/require/type/extends/extends-from-mapped-result.js +4 -3
  69. package/build/require/type/extends/extends.js +3 -3
  70. package/build/require/type/extract/extract-from-mapped-result.js +4 -3
  71. package/build/require/type/extract/extract.js +4 -4
  72. package/build/require/type/guard/index.d.ts +1 -0
  73. package/build/require/type/guard/index.js +2 -1
  74. package/build/require/type/guard/kind.d.ts +136 -0
  75. package/build/require/type/guard/kind.js +266 -0
  76. package/build/require/type/guard/type.d.ts +2 -2
  77. package/build/require/type/indexed/indexed-from-mapped-result.js +5 -3
  78. package/build/require/type/indexed/indexed-property-keys.js +10 -9
  79. package/build/require/type/indexed/indexed.js +11 -11
  80. package/build/require/type/intersect/intersect-create.js +4 -4
  81. package/build/require/type/intersect/intersect-evaluated.js +4 -5
  82. package/build/require/type/intersect/intersect.js +2 -2
  83. package/build/require/type/intrinsic/intrinsic.js +5 -5
  84. package/build/require/type/keyof/keyof-from-mapped-result.js +4 -3
  85. package/build/require/type/keyof/keyof-property-keys.js +11 -10
  86. package/build/require/type/keyof/keyof.js +2 -2
  87. package/build/require/type/mapped/mapped.d.ts +1 -1
  88. package/build/require/type/mapped/mapped.js +29 -27
  89. package/build/require/type/object/object.js +6 -4
  90. package/build/require/type/omit/omit-from-mapped-result.js +4 -3
  91. package/build/require/type/omit/omit.js +8 -10
  92. package/build/require/type/optional/optional-from-mapped-result.js +4 -3
  93. package/build/require/type/optional/optional.js +2 -2
  94. package/build/require/type/partial/partial-from-mapped-result.js +4 -3
  95. package/build/require/type/partial/partial.js +9 -8
  96. package/build/require/type/pick/pick-from-mapped-result.js +4 -3
  97. package/build/require/type/pick/pick.d.ts +1 -1
  98. package/build/require/type/pick/pick.js +12 -10
  99. package/build/require/type/readonly/readonly-from-mapped-result.js +4 -3
  100. package/build/require/type/readonly/readonly.js +2 -2
  101. package/build/require/type/record/record.js +12 -10
  102. package/build/require/type/required/required-from-mapped-result.js +4 -3
  103. package/build/require/type/required/required.js +9 -8
  104. package/build/require/type/rest/rest.js +4 -4
  105. package/build/require/type/sets/set.js +4 -1
  106. package/build/require/type/template-literal/pattern.js +9 -10
  107. package/build/require/type/transform/transform.js +2 -2
  108. package/build/require/type/union/union-evaluated.js +3 -3
  109. package/build/require/value/clean/clean.js +1 -1
  110. package/build/require/value/clone/clone.js +8 -2
  111. package/build/require/value/convert/convert.js +7 -5
  112. package/build/require/value/create/create.js +11 -7
  113. package/build/require/value/hash/hash.js +1 -1
  114. package/build/require/value/mutate/mutate.js +2 -2
  115. package/build/require/value/transform/decode.js +30 -30
  116. package/build/require/value/transform/encode.js +33 -30
  117. package/build/require/value/value/value.d.ts +2 -2
  118. package/build/require/value/value/value.js +1 -1
  119. package/package.json +1 -1
  120. package/readme.md +4 -4
@@ -6,12 +6,13 @@ const index_1 = require("../sets/index");
6
6
  // ------------------------------------------------------------------
7
7
  // TypeGuard
8
8
  // ------------------------------------------------------------------
9
- const type_1 = require("../guard/type");
9
+ const kind_1 = require("../guard/kind");
10
10
  // prettier-ignore
11
11
  function FromRest(T) {
12
- return T.reduce((Acc, L) => {
13
- return [...Acc, KeyOfPropertyKeys(L)];
14
- }, []);
12
+ const Acc = [];
13
+ for (const L of T)
14
+ Acc.push(KeyOfPropertyKeys(L));
15
+ return Acc;
15
16
  }
16
17
  // prettier-ignore
17
18
  function FromIntersect(T) {
@@ -54,12 +55,12 @@ function FromPatternProperties(patternProperties) {
54
55
  /** Returns a tuple of PropertyKeys derived from the given TSchema. */
55
56
  // prettier-ignore
56
57
  function KeyOfPropertyKeys(T) {
57
- return ((0, type_1.IsIntersect)(T) ? FromIntersect(T.allOf) :
58
- (0, type_1.IsUnion)(T) ? FromUnion(T.anyOf) :
59
- (0, type_1.IsTuple)(T) ? FromTuple(T.items ?? []) :
60
- (0, type_1.IsArray)(T) ? FromArray(T.items) :
61
- (0, type_1.IsObject)(T) ? FromProperties(T.properties) :
62
- (0, type_1.IsRecord)(T) ? FromPatternProperties(T.patternProperties) :
58
+ return ((0, kind_1.IsIntersect)(T) ? FromIntersect(T.allOf) :
59
+ (0, kind_1.IsUnion)(T) ? FromUnion(T.anyOf) :
60
+ (0, kind_1.IsTuple)(T) ? FromTuple(T.items ?? []) :
61
+ (0, kind_1.IsArray)(T) ? FromArray(T.items) :
62
+ (0, kind_1.IsObject)(T) ? FromProperties(T.properties) :
63
+ (0, kind_1.IsRecord)(T) ? FromPatternProperties(T.patternProperties) :
63
64
  []);
64
65
  }
65
66
  exports.KeyOfPropertyKeys = KeyOfPropertyKeys;
@@ -11,7 +11,7 @@ const keyof_from_mapped_result_1 = require("./keyof-from-mapped-result");
11
11
  // ------------------------------------------------------------------
12
12
  // TypeGuard
13
13
  // ------------------------------------------------------------------
14
- const type_2 = require("../guard/type");
14
+ const kind_1 = require("../guard/kind");
15
15
  // prettier-ignore
16
16
  function KeyOfPropertyKeysToRest(T) {
17
17
  return T.map(L => L === '[number]' ? (0, index_2.Number)() : (0, index_1.Literal)(L));
@@ -19,7 +19,7 @@ function KeyOfPropertyKeysToRest(T) {
19
19
  exports.KeyOfPropertyKeysToRest = KeyOfPropertyKeysToRest;
20
20
  /** `[Json]` Creates a KeyOf type */
21
21
  function KeyOf(T, options = {}) {
22
- if ((0, type_2.IsMappedResult)(T)) {
22
+ if ((0, kind_1.IsMappedResult)(T)) {
23
23
  return (0, keyof_from_mapped_result_1.KeyOfFromMappedResult)(T, options);
24
24
  }
25
25
  else {
@@ -36,7 +36,7 @@ declare function FromSchemaType<K extends PropertyKey, T extends TSchema>(K: K,
36
36
  export type TMappedFunctionReturnType<K extends PropertyKey[], T extends TSchema, Acc extends TProperties = {}> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TMappedFunctionReturnType<R, T, Acc & {
37
37
  [_ in L]: FromSchemaType<L, T>;
38
38
  }> : Acc);
39
- export declare function MappedFunctionReturnType<K extends PropertyKey[], T extends TSchema>(K: [...K], T: T, Acc?: TProperties): TMappedFunctionReturnType<K, T>;
39
+ export declare function MappedFunctionReturnType<K extends PropertyKey[], T extends TSchema>(K: [...K], T: T): TMappedFunctionReturnType<K, T>;
40
40
  export type TMappedFunction<K extends PropertyKey[], I = TMappedKey<K>> = (T: I) => TSchema;
41
41
  export type TMapped<K extends PropertyKey[], F extends TMappedFunction<K>, R extends TProperties = Evaluate<TMappedFunctionReturnType<K, ReturnType<F>>>> = Ensure<TObject<R>>;
42
42
  /** `[Json]` Creates a Mapped object type */
@@ -27,8 +27,7 @@ const mapped_result_1 = require("./mapped-result");
27
27
  // ------------------------------------------------------------------
28
28
  // TypeGuard
29
29
  // ------------------------------------------------------------------
30
- // prettier-ignore
31
- const type_2 = require("../guard/type");
30
+ const kind_1 = require("../guard/kind");
32
31
  // prettier-ignore
33
32
  function FromMappedResult(K, P) {
34
33
  return (K in P
@@ -41,9 +40,10 @@ function MappedKeyToKnownMappedResultProperties(K) {
41
40
  }
42
41
  // prettier-ignore
43
42
  function MappedKeyToUnknownMappedResultProperties(P) {
44
- return P.reduce((Acc, L) => {
45
- return { ...Acc, [L]: (0, index_10.Literal)(L) };
46
- }, {});
43
+ const Acc = {};
44
+ for (const L of P)
45
+ Acc[L] = (0, index_10.Literal)(L);
46
+ return Acc;
47
47
  }
48
48
  // prettier-ignore
49
49
  function MappedKeyToMappedResultProperties(K, P) {
@@ -62,42 +62,44 @@ function FromRest(K, T) {
62
62
  }
63
63
  // prettier-ignore
64
64
  function FromProperties(K, T) {
65
- return globalThis.Object.getOwnPropertyNames(T).reduce((Acc, K2) => {
66
- return { ...Acc, [K2]: FromSchemaType(K, T[K2]) };
67
- }, {});
65
+ const Acc = {};
66
+ for (const K2 of globalThis.Object.getOwnPropertyNames(T))
67
+ Acc[K2] = FromSchemaType(K, T[K2]);
68
+ return Acc;
68
69
  }
69
70
  // prettier-ignore
70
71
  function FromSchemaType(K, T) {
71
72
  return (
72
73
  // unevaluated modifier types
73
- (0, type_2.IsOptional)(T) ? (0, index_12.Optional)(FromSchemaType(K, (0, index_2.Discard)(T, [index_1.OptionalKind]))) :
74
- (0, type_2.IsReadonly)(T) ? (0, index_14.Readonly)(FromSchemaType(K, (0, index_2.Discard)(T, [index_1.ReadonlyKind]))) :
74
+ (0, kind_1.IsOptional)(T) ? (0, index_12.Optional)(FromSchemaType(K, (0, index_2.Discard)(T, [index_1.OptionalKind]))) :
75
+ (0, kind_1.IsReadonly)(T) ? (0, index_14.Readonly)(FromSchemaType(K, (0, index_2.Discard)(T, [index_1.ReadonlyKind]))) :
75
76
  // unevaluated mapped types
76
- (0, type_2.IsMappedResult)(T) ? FromMappedResult(K, T.properties) :
77
- (0, type_2.IsMappedKey)(T) ? FromMappedKey(K, T.keys) :
77
+ (0, kind_1.IsMappedResult)(T) ? FromMappedResult(K, T.properties) :
78
+ (0, kind_1.IsMappedKey)(T) ? FromMappedKey(K, T.keys) :
78
79
  // unevaluated types
79
- (0, type_2.IsConstructor)(T) ? (0, index_5.Constructor)(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
80
- (0, type_2.IsFunction)(T) ? (0, index_6.Function)(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
81
- (0, type_2.IsAsyncIterator)(T) ? (0, index_4.AsyncIterator)(FromSchemaType(K, T.items)) :
82
- (0, type_2.IsIterator)(T) ? (0, index_9.Iterator)(FromSchemaType(K, T.items)) :
83
- (0, type_2.IsIntersect)(T) ? (0, index_8.Intersect)(FromRest(K, T.allOf)) :
84
- (0, type_2.IsUnion)(T) ? (0, index_16.Union)(FromRest(K, T.anyOf)) :
85
- (0, type_2.IsTuple)(T) ? (0, index_15.Tuple)(FromRest(K, T.items ?? [])) :
86
- (0, type_2.IsObject)(T) ? (0, index_11.Object)(FromProperties(K, T.properties)) :
87
- (0, type_2.IsArray)(T) ? (0, index_3.Array)(FromSchemaType(K, T.items)) :
88
- (0, type_2.IsPromise)(T) ? (0, index_13.Promise)(FromSchemaType(K, T.item)) :
80
+ (0, kind_1.IsConstructor)(T) ? (0, index_5.Constructor)(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
81
+ (0, kind_1.IsFunction)(T) ? (0, index_6.Function)(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
82
+ (0, kind_1.IsAsyncIterator)(T) ? (0, index_4.AsyncIterator)(FromSchemaType(K, T.items)) :
83
+ (0, kind_1.IsIterator)(T) ? (0, index_9.Iterator)(FromSchemaType(K, T.items)) :
84
+ (0, kind_1.IsIntersect)(T) ? (0, index_8.Intersect)(FromRest(K, T.allOf)) :
85
+ (0, kind_1.IsUnion)(T) ? (0, index_16.Union)(FromRest(K, T.anyOf)) :
86
+ (0, kind_1.IsTuple)(T) ? (0, index_15.Tuple)(FromRest(K, T.items ?? [])) :
87
+ (0, kind_1.IsObject)(T) ? (0, index_11.Object)(FromProperties(K, T.properties)) :
88
+ (0, kind_1.IsArray)(T) ? (0, index_3.Array)(FromSchemaType(K, T.items)) :
89
+ (0, kind_1.IsPromise)(T) ? (0, index_13.Promise)(FromSchemaType(K, T.item)) :
89
90
  T);
90
91
  }
91
92
  // prettier-ignore
92
- function MappedFunctionReturnType(K, T, Acc = {}) {
93
- return K.reduce((Acc, L) => {
94
- return { ...Acc, [L]: FromSchemaType(L, T) };
95
- }, {});
93
+ function MappedFunctionReturnType(K, T) {
94
+ const Acc = {};
95
+ for (const L of K)
96
+ Acc[L] = FromSchemaType(L, T);
97
+ return Acc;
96
98
  }
97
99
  exports.MappedFunctionReturnType = MappedFunctionReturnType;
98
100
  /** `[Json]` Creates a Mapped object type */
99
101
  function Mapped(key, map, options = {}) {
100
- const K = (0, type_2.IsSchema)(key) ? (0, index_7.IndexPropertyKeys)(key) : key;
102
+ const K = (0, kind_1.IsSchema)(key) ? (0, index_7.IndexPropertyKeys)(key) : key;
101
103
  const RT = map({ [index_1.Kind]: 'MappedKey', keys: K });
102
104
  const R = MappedFunctionReturnType(K, RT);
103
105
  return (0, type_1.CloneType)((0, index_11.Object)(R), options);
@@ -7,14 +7,16 @@ const index_1 = require("../symbols/index");
7
7
  // ------------------------------------------------------------------
8
8
  // TypeGuard
9
9
  // ------------------------------------------------------------------
10
- const type_2 = require("../guard/type");
10
+ const kind_1 = require("../guard/kind");
11
11
  /** `[Json]` Creates an Object type */
12
12
  function _Object(properties, options = {}) {
13
13
  const propertyKeys = globalThis.Object.getOwnPropertyNames(properties);
14
- const optionalKeys = propertyKeys.filter((key) => (0, type_2.IsOptional)(properties[key]));
14
+ const optionalKeys = propertyKeys.filter((key) => (0, kind_1.IsOptional)(properties[key]));
15
15
  const requiredKeys = propertyKeys.filter((name) => !optionalKeys.includes(name));
16
- const clonedAdditionalProperties = (0, type_2.IsSchema)(options.additionalProperties) ? { additionalProperties: (0, type_1.CloneType)(options.additionalProperties) } : {};
17
- const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: (0, type_1.CloneType)(properties[key]) }), {});
16
+ const clonedAdditionalProperties = (0, kind_1.IsSchema)(options.additionalProperties) ? { additionalProperties: (0, type_1.CloneType)(options.additionalProperties) } : {};
17
+ const clonedProperties = {};
18
+ for (const key of propertyKeys)
19
+ clonedProperties[key] = (0, type_1.CloneType)(properties[key]);
18
20
  return (requiredKeys.length > 0
19
21
  ? { ...options, ...clonedAdditionalProperties, [index_1.Kind]: 'Object', type: 'object', properties: clonedProperties, required: requiredKeys }
20
22
  : { ...options, ...clonedAdditionalProperties, [index_1.Kind]: 'Object', type: 'object', properties: clonedProperties });
@@ -6,9 +6,10 @@ const index_1 = require("../mapped/index");
6
6
  const omit_1 = require("./omit");
7
7
  // prettier-ignore
8
8
  function FromProperties(P, K, options) {
9
- return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
10
- return { ...Acc, [K2]: (0, omit_1.Omit)(P[K2], K, options) };
11
- }, {});
9
+ const Acc = {};
10
+ for (const K2 of globalThis.Object.getOwnPropertyNames(P))
11
+ Acc[K2] = (0, omit_1.Omit)(P[K2], K, options);
12
+ return Acc;
12
13
  }
13
14
  // prettier-ignore
14
15
  function FromMappedResult(R, K, options) {
@@ -14,7 +14,7 @@ const omit_from_mapped_result_1 = require("./omit-from-mapped-result");
14
14
  // ------------------------------------------------------------------
15
15
  // TypeGuard
16
16
  // ------------------------------------------------------------------
17
- const type_2 = require("../guard/type");
17
+ const kind_1 = require("../guard/kind");
18
18
  // prettier-ignore
19
19
  function FromIntersect(T, K) {
20
20
  return T.map((T) => OmitResolve(T, K));
@@ -33,28 +33,26 @@ function FromProperty(T, K) {
33
33
  }
34
34
  // prettier-ignore
35
35
  function FromProperties(T, K) {
36
- return K.reduce((T, K2) => {
37
- return FromProperty(T, K2);
38
- }, T);
36
+ return K.reduce((T, K2) => FromProperty(T, K2), T);
39
37
  }
40
38
  // ------------------------------------------------------------------
41
39
  // OmitResolve
42
40
  // ------------------------------------------------------------------
43
41
  // prettier-ignore
44
42
  function OmitResolve(T, K) {
45
- return ((0, type_2.IsIntersect)(T) ? (0, index_1.Intersect)(FromIntersect(T.allOf, K)) :
46
- (0, type_2.IsUnion)(T) ? (0, index_2.Union)(FromUnion(T.anyOf, K)) :
47
- (0, type_2.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties, K)) :
43
+ return ((0, kind_1.IsIntersect)(T) ? (0, index_1.Intersect)(FromIntersect(T.allOf, K)) :
44
+ (0, kind_1.IsUnion)(T) ? (0, index_2.Union)(FromUnion(T.anyOf, K)) :
45
+ (0, kind_1.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties, K)) :
48
46
  (0, index_3.Object)({}));
49
47
  }
50
48
  function Omit(T, K, options = {}) {
51
49
  // mapped
52
- if ((0, type_2.IsMappedKey)(K))
50
+ if ((0, kind_1.IsMappedKey)(K))
53
51
  return (0, omit_from_mapped_key_1.OmitFromMappedKey)(T, K, options);
54
- if ((0, type_2.IsMappedResult)(T))
52
+ if ((0, kind_1.IsMappedResult)(T))
55
53
  return (0, omit_from_mapped_result_1.OmitFromMappedResult)(T, K, options);
56
54
  // non-mapped
57
- const I = (0, type_2.IsSchema)(K) ? (0, index_4.IndexPropertyKeys)(K) : K;
55
+ const I = (0, kind_1.IsSchema)(K) ? (0, index_4.IndexPropertyKeys)(K) : K;
58
56
  const D = (0, index_5.Discard)(T, [index_6.TransformKind, '$id', 'required']);
59
57
  const R = (0, type_1.CloneType)(OmitResolve(T, I), options);
60
58
  return { ...D, ...R };
@@ -6,9 +6,10 @@ const index_1 = require("../mapped/index");
6
6
  const optional_1 = require("./optional");
7
7
  // prettier-ignore
8
8
  function FromProperties(P, F) {
9
- return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
10
- return { ...Acc, [K2]: (0, optional_1.Optional)(P[K2], F) };
11
- }, {});
9
+ const Acc = {};
10
+ for (const K2 of globalThis.Object.getOwnPropertyNames(P))
11
+ Acc[K2] = (0, optional_1.Optional)(P[K2], F);
12
+ return Acc;
12
13
  }
13
14
  // prettier-ignore
14
15
  function FromMappedResult(R, F) {
@@ -6,7 +6,7 @@ const index_1 = require("../symbols/index");
6
6
  const type_1 = require("../clone/type");
7
7
  const index_2 = require("../discard/index");
8
8
  const optional_from_mapped_result_1 = require("./optional-from-mapped-result");
9
- const type_2 = require("../guard/type");
9
+ const kind_1 = require("../guard/kind");
10
10
  function RemoveOptional(schema) {
11
11
  return (0, index_2.Discard)((0, type_1.CloneType)(schema), [index_1.OptionalKind]);
12
12
  }
@@ -22,6 +22,6 @@ function OptionalWithFlag(schema, F) {
22
22
  /** `[Json]` Creates a Optional property */
23
23
  function Optional(schema, enable) {
24
24
  const F = enable ?? true;
25
- return (0, type_2.IsMappedResult)(schema) ? (0, optional_from_mapped_result_1.OptionalFromMappedResult)(schema, F) : OptionalWithFlag(schema, F);
25
+ return (0, kind_1.IsMappedResult)(schema) ? (0, optional_from_mapped_result_1.OptionalFromMappedResult)(schema, F) : OptionalWithFlag(schema, F);
26
26
  }
27
27
  exports.Optional = Optional;
@@ -6,9 +6,10 @@ const index_1 = require("../mapped/index");
6
6
  const partial_1 = require("./partial");
7
7
  // prettier-ignore
8
8
  function FromProperties(K, options) {
9
- return globalThis.Object.getOwnPropertyNames(K).reduce((Acc, K2) => {
10
- return { ...Acc, [K2]: (0, partial_1.Partial)(K[K2], options) };
11
- }, {});
9
+ const Acc = {};
10
+ for (const K2 of globalThis.Object.getOwnPropertyNames(K))
11
+ Acc[K2] = (0, partial_1.Partial)(K[K2], options);
12
+ return Acc;
12
13
  }
13
14
  // prettier-ignore
14
15
  function FromMappedResult(R, options) {
@@ -13,30 +13,31 @@ const partial_from_mapped_result_1 = require("./partial-from-mapped-result");
13
13
  // ------------------------------------------------------------------
14
14
  // TypeGuard
15
15
  // ------------------------------------------------------------------
16
- const type_2 = require("../guard/type");
16
+ const kind_1 = require("../guard/kind");
17
17
  // prettier-ignore
18
18
  function FromRest(T) {
19
19
  return T.map(L => PartialResolve(L));
20
20
  }
21
21
  // prettier-ignore
22
22
  function FromProperties(T) {
23
- return globalThis.Object.getOwnPropertyNames(T).reduce((Acc, K) => {
24
- return { ...Acc, [K]: (0, index_1.Optional)(T[K]) };
25
- }, {});
23
+ const Acc = {};
24
+ for (const K of globalThis.Object.getOwnPropertyNames(T))
25
+ Acc[K] = (0, index_1.Optional)(T[K]);
26
+ return Acc;
26
27
  }
27
28
  // ------------------------------------------------------------------
28
29
  // PartialResolve
29
30
  // ------------------------------------------------------------------
30
31
  // prettier-ignore
31
32
  function PartialResolve(T) {
32
- return ((0, type_2.IsIntersect)(T) ? (0, index_3.Intersect)(FromRest(T.allOf)) :
33
- (0, type_2.IsUnion)(T) ? (0, index_4.Union)(FromRest(T.anyOf)) :
34
- (0, type_2.IsObject)(T) ? (0, index_2.Object)(FromProperties(T.properties)) :
33
+ return ((0, kind_1.IsIntersect)(T) ? (0, index_3.Intersect)(FromRest(T.allOf)) :
34
+ (0, kind_1.IsUnion)(T) ? (0, index_4.Union)(FromRest(T.anyOf)) :
35
+ (0, kind_1.IsObject)(T) ? (0, index_2.Object)(FromProperties(T.properties)) :
35
36
  (0, index_2.Object)({}));
36
37
  }
37
38
  /** `[Json]` Constructs a type where all properties are optional */
38
39
  function Partial(T, options = {}) {
39
- if ((0, type_2.IsMappedResult)(T))
40
+ if ((0, kind_1.IsMappedResult)(T))
40
41
  return (0, partial_from_mapped_result_1.PartialFromMappedResult)(T, options);
41
42
  const D = (0, index_5.Discard)(T, [index_6.TransformKind, '$id', 'required']);
42
43
  const R = (0, type_1.CloneType)(PartialResolve(T), options);
@@ -6,9 +6,10 @@ const index_1 = require("../mapped/index");
6
6
  const pick_1 = require("./pick");
7
7
  // prettier-ignore
8
8
  function FromProperties(P, K, options) {
9
- return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
10
- return { ...Acc, [K2]: (0, pick_1.Pick)(P[K2], K, options) };
11
- }, {});
9
+ const Acc = {};
10
+ for (const K2 of globalThis.Object.getOwnPropertyNames(P))
11
+ Acc[K2] = (0, pick_1.Pick)(P[K2], K, options);
12
+ return Acc;
12
13
  }
13
14
  // prettier-ignore
14
15
  function FromMappedResult(R, K, options) {
@@ -13,7 +13,7 @@ declare function FromIntersect<T extends TSchema[], K extends PropertyKey[]>(T:
13
13
  type FromUnion<T extends TSchema[], K extends PropertyKey[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? FromUnion<R, K, [...Acc, TPick<L, K>]> : Acc;
14
14
  declare function FromUnion<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromUnion<T, K, []>;
15
15
  type FromProperties<T extends TProperties, K extends PropertyKey[], I extends PropertyKey = TupleToUnion<K>> = Evaluate<Pick<T, I & keyof T>>;
16
- declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(T: T, K: K): {};
16
+ declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(T: T, K: K): never;
17
17
  export type TPick<T extends TProperties, K extends PropertyKey[]> = T extends TRecursive<infer S> ? TRecursive<TPick<S, K>> : T extends TIntersect<infer S> ? TIntersect<FromIntersect<S, K>> : T extends TUnion<infer S> ? TUnion<FromUnion<S, K>> : T extends TObject<infer S> ? TObject<FromProperties<S, K>> : TObject<{}>;
18
18
  /** `[Json]` Constructs a type whose keys are picked from the given type */
19
19
  export declare function Pick<T extends TMappedResult, K extends PropertyKey[]>(T: T, K: [...K], options?: SchemaOptions): TPickFromMappedResult<T, K>;
@@ -14,7 +14,7 @@ const pick_from_mapped_result_1 = require("./pick-from-mapped-result");
14
14
  // ------------------------------------------------------------------
15
15
  // TypeGuard
16
16
  // ------------------------------------------------------------------
17
- const type_2 = require("../guard/type");
17
+ const kind_1 = require("../guard/kind");
18
18
  function FromIntersect(T, K) {
19
19
  return T.map((T) => PickResolve(T, K));
20
20
  }
@@ -24,28 +24,30 @@ function FromUnion(T, K) {
24
24
  }
25
25
  // prettier-ignore
26
26
  function FromProperties(T, K) {
27
- return K.reduce((Acc, K) => {
28
- return K in T ? { ...Acc, [K]: T[K] } : Acc;
29
- }, {});
27
+ const Acc = {};
28
+ for (const K2 of K)
29
+ if (K2 in T)
30
+ Acc[K2] = T[K2];
31
+ return Acc;
30
32
  }
31
33
  // ------------------------------------------------------------------
32
34
  // PickResolve
33
35
  // ------------------------------------------------------------------
34
36
  // prettier-ignore
35
37
  function PickResolve(T, K) {
36
- return ((0, type_2.IsIntersect)(T) ? (0, index_1.Intersect)(FromIntersect(T.allOf, K)) :
37
- (0, type_2.IsUnion)(T) ? (0, index_2.Union)(FromUnion(T.anyOf, K)) :
38
- (0, type_2.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties, K)) :
38
+ return ((0, kind_1.IsIntersect)(T) ? (0, index_1.Intersect)(FromIntersect(T.allOf, K)) :
39
+ (0, kind_1.IsUnion)(T) ? (0, index_2.Union)(FromUnion(T.anyOf, K)) :
40
+ (0, kind_1.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties, K)) :
39
41
  (0, index_3.Object)({}));
40
42
  }
41
43
  function Pick(T, K, options = {}) {
42
44
  // mapped
43
- if ((0, type_2.IsMappedKey)(K))
45
+ if ((0, kind_1.IsMappedKey)(K))
44
46
  return (0, pick_from_mapped_key_1.PickFromMappedKey)(T, K, options);
45
- if ((0, type_2.IsMappedResult)(T))
47
+ if ((0, kind_1.IsMappedResult)(T))
46
48
  return (0, pick_from_mapped_result_1.PickFromMappedResult)(T, K, options);
47
49
  // non-mapped
48
- const I = (0, type_2.IsSchema)(K) ? (0, index_4.IndexPropertyKeys)(K) : K;
50
+ const I = (0, kind_1.IsSchema)(K) ? (0, index_4.IndexPropertyKeys)(K) : K;
49
51
  const D = (0, index_5.Discard)(T, [index_6.TransformKind, '$id', 'required']);
50
52
  const R = (0, type_1.CloneType)(PickResolve(T, I), options);
51
53
  return { ...D, ...R };
@@ -6,9 +6,10 @@ const index_1 = require("../mapped/index");
6
6
  const readonly_1 = require("./readonly");
7
7
  // prettier-ignore
8
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
- }, {});
9
+ const Acc = {};
10
+ for (const K2 of globalThis.Object.getOwnPropertyNames(K))
11
+ Acc[K2] = (0, readonly_1.Readonly)(K[K2], F);
12
+ return Acc;
12
13
  }
13
14
  // prettier-ignore
14
15
  function FromMappedResult(R, F) {
@@ -6,7 +6,7 @@ const index_1 = require("../symbols/index");
6
6
  const type_1 = require("../clone/type");
7
7
  const index_2 = require("../discard/index");
8
8
  const readonly_from_mapped_result_1 = require("./readonly-from-mapped-result");
9
- const type_2 = require("../guard/type");
9
+ const kind_1 = require("../guard/kind");
10
10
  function RemoveReadonly(schema) {
11
11
  return (0, index_2.Discard)((0, type_1.CloneType)(schema), [index_1.ReadonlyKind]);
12
12
  }
@@ -22,6 +22,6 @@ function ReadonlyWithFlag(schema, F) {
22
22
  /** `[Json]` Creates a Readonly property */
23
23
  function Readonly(schema, enable) {
24
24
  const F = enable ?? true;
25
- return (0, type_2.IsMappedResult)(schema) ? (0, readonly_from_mapped_result_1.ReadonlyFromMappedResult)(schema, F) : ReadonlyWithFlag(schema, F);
25
+ return (0, kind_1.IsMappedResult)(schema) ? (0, readonly_from_mapped_result_1.ReadonlyFromMappedResult)(schema, F) : ReadonlyWithFlag(schema, F);
26
26
  }
27
27
  exports.Readonly = Readonly;
@@ -17,7 +17,7 @@ const value_1 = require("../guard/value");
17
17
  // ------------------------------------------------------------------
18
18
  // TypeGuard
19
19
  // ------------------------------------------------------------------
20
- const type_2 = require("../guard/type");
20
+ const kind_1 = require("../guard/kind");
21
21
  // ------------------------------------------------------------------
22
22
  // RecordCreateFromPattern
23
23
  // ------------------------------------------------------------------
@@ -35,8 +35,10 @@ function RecordCreateFromPattern(pattern, T, options) {
35
35
  // ------------------------------------------------------------------
36
36
  // prettier-ignore
37
37
  function RecordCreateFromKeys(K, T, options) {
38
- const P = K.reduce((Acc, K) => ({ ...Acc, [K]: (0, type_1.CloneType)(T) }), {});
39
- return (0, index_1.Object)(P, { ...options, [index_7.Hint]: 'Record' });
38
+ const Acc = {};
39
+ for (const K2 of K)
40
+ Acc[K2] = (0, type_1.CloneType)(T);
41
+ return (0, index_1.Object)(Acc, { ...options, [index_7.Hint]: 'Record' });
40
42
  }
41
43
  // prettier-ignore
42
44
  function FromTemplateLiteralKey(K, T, options) {
@@ -75,13 +77,13 @@ function FromNumberKey(_, T, options) {
75
77
  /** `[Json]` Creates a Record type */
76
78
  function Record(K, T, options = {}) {
77
79
  // prettier-ignore
78
- return ((0, type_2.IsUnion)(K) ? FromUnionKey(K.anyOf, T, options) :
79
- (0, type_2.IsTemplateLiteral)(K) ? FromTemplateLiteralKey(K, T, options) :
80
- (0, type_2.IsLiteral)(K) ? FromLiteralKey(K.const, T, options) :
81
- (0, type_2.IsInteger)(K) ? FromIntegerKey(K, T, options) :
82
- (0, type_2.IsNumber)(K) ? FromNumberKey(K, T, options) :
83
- (0, type_2.IsRegExp)(K) ? FromRegExpKey(K, T, options) :
84
- (0, type_2.IsString)(K) ? FromStringKey(K, T, options) :
80
+ return ((0, kind_1.IsUnion)(K) ? FromUnionKey(K.anyOf, T, options) :
81
+ (0, kind_1.IsTemplateLiteral)(K) ? FromTemplateLiteralKey(K, T, options) :
82
+ (0, kind_1.IsLiteral)(K) ? FromLiteralKey(K.const, T, options) :
83
+ (0, kind_1.IsInteger)(K) ? FromIntegerKey(K, T, options) :
84
+ (0, kind_1.IsNumber)(K) ? FromNumberKey(K, T, options) :
85
+ (0, kind_1.IsRegExp)(K) ? FromRegExpKey(K, T, options) :
86
+ (0, kind_1.IsString)(K) ? FromStringKey(K, T, options) :
85
87
  (0, index_2.Never)(options));
86
88
  }
87
89
  exports.Record = Record;
@@ -6,9 +6,10 @@ const index_1 = require("../mapped/index");
6
6
  const required_1 = require("./required");
7
7
  // prettier-ignore
8
8
  function FromProperties(P, options) {
9
- return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
10
- return { ...Acc, [K2]: (0, required_1.Required)(P[K2], options) };
11
- }, {});
9
+ const Acc = {};
10
+ for (const K2 of globalThis.Object.getOwnPropertyNames(P))
11
+ Acc[K2] = (0, required_1.Required)(P[K2], options);
12
+ return Acc;
12
13
  }
13
14
  // prettier-ignore
14
15
  function FromMappedResult(R, options) {
@@ -12,30 +12,31 @@ const required_from_mapped_result_1 = require("./required-from-mapped-result");
12
12
  // ------------------------------------------------------------------
13
13
  // TypeGuard
14
14
  // ------------------------------------------------------------------
15
- const type_2 = require("../guard/type");
15
+ const kind_1 = require("../guard/kind");
16
16
  // prettier-ignore
17
17
  function FromRest(T) {
18
18
  return T.map(L => RequiredResolve(L));
19
19
  }
20
20
  // prettier-ignore
21
21
  function FromProperties(T) {
22
- return globalThis.Object.getOwnPropertyNames(T).reduce((Acc, K) => {
23
- return { ...Acc, [K]: (0, index_5.Discard)(T[K], [index_4.OptionalKind]) };
24
- }, {});
22
+ const Acc = {};
23
+ for (const K of globalThis.Object.getOwnPropertyNames(T))
24
+ Acc[K] = (0, index_5.Discard)(T[K], [index_4.OptionalKind]);
25
+ return Acc;
25
26
  }
26
27
  // ------------------------------------------------------------------
27
28
  // RequiredResolve
28
29
  // ------------------------------------------------------------------
29
30
  // prettier-ignore
30
31
  function RequiredResolve(T) {
31
- return ((0, type_2.IsIntersect)(T) ? (0, index_1.Intersect)(FromRest(T.allOf)) :
32
- (0, type_2.IsUnion)(T) ? (0, index_2.Union)(FromRest(T.anyOf)) :
33
- (0, type_2.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties)) :
32
+ return ((0, kind_1.IsIntersect)(T) ? (0, index_1.Intersect)(FromRest(T.allOf)) :
33
+ (0, kind_1.IsUnion)(T) ? (0, index_2.Union)(FromRest(T.anyOf)) :
34
+ (0, kind_1.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties)) :
34
35
  (0, index_3.Object)({}));
35
36
  }
36
37
  /** `[Json]` Constructs a type where all properties are required */
37
38
  function Required(T, options = {}) {
38
- if ((0, type_2.IsMappedResult)(T)) {
39
+ if ((0, kind_1.IsMappedResult)(T)) {
39
40
  return (0, required_from_mapped_result_1.RequiredFromMappedResult)(T, options);
40
41
  }
41
42
  else {
@@ -6,12 +6,12 @@ const type_1 = require("../clone/type");
6
6
  // ------------------------------------------------------------------
7
7
  // TypeGuard
8
8
  // ------------------------------------------------------------------
9
- const type_2 = require("../guard/type");
9
+ const kind_1 = require("../guard/kind");
10
10
  // prettier-ignore
11
11
  function RestResolve(T) {
12
- return ((0, type_2.IsIntersect)(T) ? [...T.allOf] :
13
- (0, type_2.IsUnion)(T) ? [...T.anyOf] :
14
- (0, type_2.IsTuple)(T) ? [...(T.items ?? [])] :
12
+ return ((0, kind_1.IsIntersect)(T) ? (0, type_1.CloneRest)(T.allOf) :
13
+ (0, kind_1.IsUnion)(T) ? (0, type_1.CloneRest)(T.anyOf) :
14
+ (0, kind_1.IsTuple)(T) ? (0, type_1.CloneRest)(T.items ?? []) :
15
15
  []);
16
16
  }
17
17
  /** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
@@ -52,6 +52,9 @@ function SetIntersectMany(T) {
52
52
  exports.SetIntersectMany = SetIntersectMany;
53
53
  /** Returns the Union of multiple sets */
54
54
  function SetUnionMany(T) {
55
- return T.reduce((Acc, L) => [...Acc, ...L], []);
55
+ const Acc = [];
56
+ for (const L of T)
57
+ Acc.push(...L);
58
+ return Acc;
56
59
  }
57
60
  exports.SetUnionMany = SetUnionMany;
@@ -8,8 +8,7 @@ const index_3 = require("../error/index");
8
8
  // ------------------------------------------------------------------
9
9
  // TypeGuard
10
10
  // ------------------------------------------------------------------
11
- // prettier-ignore
12
- const type_1 = require("../guard/type");
11
+ const kind_1 = require("../guard/kind");
13
12
  // ------------------------------------------------------------------
14
13
  // TemplateLiteralPatternError
15
14
  // ------------------------------------------------------------------
@@ -24,14 +23,14 @@ function Escape(value) {
24
23
  }
25
24
  // prettier-ignore
26
25
  function Visit(schema, acc) {
27
- return ((0, type_1.IsTemplateLiteral)(schema) ? schema.pattern.slice(1, schema.pattern.length - 1) :
28
- (0, type_1.IsUnion)(schema) ? `(${schema.anyOf.map((schema) => Visit(schema, acc)).join('|')})` :
29
- (0, type_1.IsNumber)(schema) ? `${acc}${index_1.PatternNumber}` :
30
- (0, type_1.IsInteger)(schema) ? `${acc}${index_1.PatternNumber}` :
31
- (0, type_1.IsBigInt)(schema) ? `${acc}${index_1.PatternNumber}` :
32
- (0, type_1.IsString)(schema) ? `${acc}${index_1.PatternString}` :
33
- (0, type_1.IsLiteral)(schema) ? `${acc}${Escape(schema.const.toString())}` :
34
- (0, type_1.IsBoolean)(schema) ? `${acc}${index_1.PatternBoolean}` :
26
+ return ((0, kind_1.IsTemplateLiteral)(schema) ? schema.pattern.slice(1, schema.pattern.length - 1) :
27
+ (0, kind_1.IsUnion)(schema) ? `(${schema.anyOf.map((schema) => Visit(schema, acc)).join('|')})` :
28
+ (0, kind_1.IsNumber)(schema) ? `${acc}${index_1.PatternNumber}` :
29
+ (0, kind_1.IsInteger)(schema) ? `${acc}${index_1.PatternNumber}` :
30
+ (0, kind_1.IsBigInt)(schema) ? `${acc}${index_1.PatternNumber}` :
31
+ (0, kind_1.IsString)(schema) ? `${acc}${index_1.PatternString}` :
32
+ (0, kind_1.IsLiteral)(schema) ? `${acc}${Escape(schema.const.toString())}` :
33
+ (0, kind_1.IsBoolean)(schema) ? `${acc}${index_1.PatternBoolean}` :
35
34
  (() => { throw new TemplateLiteralPatternError(`Unexpected Kind '${schema[index_2.Kind]}'`); })());
36
35
  }
37
36
  function TemplateLiteralPattern(kinds) {
@@ -7,7 +7,7 @@ const type_1 = require("../clone/type");
7
7
  // ------------------------------------------------------------------
8
8
  // TypeGuard
9
9
  // ------------------------------------------------------------------
10
- const type_2 = require("../guard/type");
10
+ const kind_1 = require("../guard/kind");
11
11
  // ------------------------------------------------------------------
12
12
  // TransformBuilders
13
13
  // ------------------------------------------------------------------
@@ -38,7 +38,7 @@ class TransformEncodeBuilder {
38
38
  }
39
39
  Encode(encode) {
40
40
  const schema = (0, type_1.CloneType)(this.schema);
41
- return ((0, type_2.IsTransform)(schema) ? this.EncodeTransform(encode, schema) : this.EncodeSchema(encode, schema));
41
+ return ((0, kind_1.IsTransform)(schema) ? this.EncodeTransform(encode, schema) : this.EncodeSchema(encode, schema));
42
42
  }
43
43
  }
44
44
  exports.TransformEncodeBuilder = TransformEncodeBuilder;