@openclaw/slack 2026.8.1-beta.3 → 2026.8.1

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 (237) hide show
  1. package/dist/account-configured-sUohAxZr.js +33 -0
  2. package/dist/account-inspect-CN2hBsim.js +87 -0
  3. package/dist/account-inspect-api.js +1 -1
  4. package/dist/{accounts-BlzxuYle.js → accounts-Dm_H77gH.js} +7 -10
  5. package/dist/{accounts.runtime-CbabBL8x.js → accounts.runtime-DRuEK6mL.js} +1 -1
  6. package/dist/{action-runtime-D6jg2CQd.js → action-runtime-044ldvNL.js} +53 -48
  7. package/dist/action-runtime.runtime-BL3KzX13.js +2 -0
  8. package/dist/{actions-DFk0ANVB.js → actions-BI7JkfVm.js} +266 -96
  9. package/dist/api.js +12 -12
  10. package/dist/{approval-handler.runtime-BNvAoKdK.js → approval-handler.runtime-DYv0UIZS.js} +53 -176
  11. package/dist/{channel-CA5w7qDF.js → channel-1vIJOzPx.js} +77 -142
  12. package/dist/channel-config-api.js +1 -1
  13. package/dist/channel-plugin-api.js +1 -1
  14. package/dist/{channel-type-CZWv55Wu.js → channel-type-DlFSKeIZ.js} +3 -3
  15. package/dist/{channel.setup-CpyYsEXH.js → channel.setup-ofDi3_Pu.js} +34 -49
  16. package/dist/{config-schema-CN3XZRX5.js → config-schema-BVIMyiDN.js} +19 -12
  17. package/dist/configured-state.js +34 -0
  18. package/dist/{directory-config-BGYyuzWh.js → directory-config-DqfQ42OV.js} +1 -1
  19. package/dist/directory-contract-api.js +1 -1
  20. package/dist/{directory-live-DjUJQLbq.js → directory-live-BPaNHjmP.js} +2 -2
  21. package/dist/{group-policy-DyfB_ZIE.js → group-policy-BdwszjYn.js} +581 -743
  22. package/dist/{message-tool-api-CqMr5Rmc.js → message-tool-api-CJ0kjcg5.js} +23 -5
  23. package/dist/message-tool-api.js +1 -1
  24. package/dist/{monitor-Chrecrb9.js → monitor-Dq5Cmrvp.js} +3 -3
  25. package/dist/{outbound-adapter-DuRqAQXK.js → outbound-adapter-DYaI8ThX.js} +93 -68
  26. package/dist/{pipeline.runtime-Bbfd5VFW.js → pipeline.runtime-Bd22U0ga.js} +128 -160
  27. package/dist/{policy-BKXSxrIS.js → policy-CtQVbde1.js} +2 -1
  28. package/dist/{probe-BVA65leh.js → probe-0usmAb0i.js} +209 -22
  29. package/dist/{provider-CUUiwsg2.js → provider-CN_8hFv2.js} +243 -146
  30. package/dist/{relay-source-mhpMMRG-.js → relay-source-BNGpsdwV.js} +1 -1
  31. package/dist/{replies-SnWyXcsL.js → replies-BSiRQOJ1.js} +15 -5
  32. package/dist/{resolve-channels-BSpqC8jU.js → resolve-channels-Czheznc8.js} +1 -1
  33. package/dist/{resolve-users-Dvz9pDe0.js → resolve-users-BAOlNimr.js} +1 -1
  34. package/dist/runtime-api.js +11 -11
  35. package/dist/{scopes-BSk4GZvZ.js → scopes-COSlmhnH.js} +1 -1
  36. package/dist/{send-CtnOxKCc.js → send-DS9ICrBI.js} +39 -31
  37. package/dist/send-results-eeOu_HYm.js +23 -0
  38. package/dist/{send.runtime-kYctMHSd.js → send.runtime-D_Bb6IuH.js} +1 -1
  39. package/dist/setup-plugin-api.js +1 -1
  40. package/dist/{setup-surface-BPFfp6So.js → setup-surface-BGnd2pSe.js} +6 -6
  41. package/dist/{shared-DJBaslN7.js → shared-D5B-5hBg.js} +26 -6
  42. package/dist/{slash-dispatch.runtime-Cf2FTrnf.js → slash-dispatch.runtime-CilDmI0c.js} +3 -3
  43. package/node_modules/@slack/bolt/node_modules/@types/node/README.md +1 -1
  44. package/node_modules/@slack/bolt/node_modules/@types/node/child_process.d.ts +0 -1
  45. package/node_modules/@slack/bolt/node_modules/@types/node/crypto.d.ts +6 -6
  46. package/node_modules/@slack/bolt/node_modules/@types/node/dns/promises.d.ts +5 -5
  47. package/node_modules/@slack/bolt/node_modules/@types/node/dns.d.ts +5 -5
  48. package/node_modules/@slack/bolt/node_modules/@types/node/fs.d.ts +7 -0
  49. package/node_modules/@slack/bolt/node_modules/@types/node/http.d.ts +30 -0
  50. package/node_modules/@slack/bolt/node_modules/@types/node/http2.d.ts +4 -4
  51. package/node_modules/@slack/bolt/node_modules/@types/node/os.d.ts +30 -30
  52. package/node_modules/@slack/bolt/node_modules/@types/node/package.json +2 -2
  53. package/node_modules/@slack/bolt/node_modules/@types/node/perf_hooks.d.ts +2 -1
  54. package/node_modules/@slack/bolt/node_modules/@types/node/process.d.ts +42 -43
  55. package/node_modules/@slack/bolt/node_modules/@types/node/quic.d.ts +1049 -84
  56. package/node_modules/@slack/bolt/node_modules/@types/node/sqlite.d.ts +14 -1
  57. package/node_modules/@slack/bolt/node_modules/@types/node/stream/iter.d.ts +3 -2
  58. package/node_modules/@slack/bolt/node_modules/@types/node/test.d.ts +61 -0
  59. package/node_modules/@slack/bolt/node_modules/@types/node/v8.d.ts +20 -23
  60. package/node_modules/@slack/bolt/node_modules/body-parser/node_modules/content-type/README.md +2 -0
  61. package/node_modules/@slack/bolt/node_modules/body-parser/node_modules/content-type/dist/index.d.ts +20 -0
  62. package/node_modules/@slack/bolt/node_modules/body-parser/node_modules/content-type/dist/index.js +20 -14
  63. package/node_modules/@slack/bolt/node_modules/body-parser/node_modules/content-type/dist/index.js.map +1 -1
  64. package/node_modules/@slack/bolt/node_modules/body-parser/node_modules/content-type/package.json +1 -1
  65. package/node_modules/@slack/bolt/node_modules/type-is/node_modules/content-type/README.md +2 -0
  66. package/node_modules/@slack/bolt/node_modules/type-is/node_modules/content-type/dist/index.d.ts +20 -0
  67. package/node_modules/@slack/bolt/node_modules/type-is/node_modules/content-type/dist/index.js +20 -14
  68. package/node_modules/@slack/bolt/node_modules/type-is/node_modules/content-type/dist/index.js.map +1 -1
  69. package/node_modules/@slack/bolt/node_modules/type-is/node_modules/content-type/package.json +1 -1
  70. package/node_modules/@slack/socket-mode/node_modules/@types/node/README.md +1 -1
  71. package/node_modules/@slack/socket-mode/node_modules/@types/node/child_process.d.ts +0 -1
  72. package/node_modules/@slack/socket-mode/node_modules/@types/node/crypto.d.ts +6 -6
  73. package/node_modules/@slack/socket-mode/node_modules/@types/node/dns/promises.d.ts +5 -5
  74. package/node_modules/@slack/socket-mode/node_modules/@types/node/dns.d.ts +5 -5
  75. package/node_modules/@slack/socket-mode/node_modules/@types/node/fs.d.ts +7 -0
  76. package/node_modules/@slack/socket-mode/node_modules/@types/node/http.d.ts +30 -0
  77. package/node_modules/@slack/socket-mode/node_modules/@types/node/http2.d.ts +4 -4
  78. package/node_modules/@slack/socket-mode/node_modules/@types/node/os.d.ts +30 -30
  79. package/node_modules/@slack/socket-mode/node_modules/@types/node/package.json +2 -2
  80. package/node_modules/@slack/socket-mode/node_modules/@types/node/perf_hooks.d.ts +2 -1
  81. package/node_modules/@slack/socket-mode/node_modules/@types/node/process.d.ts +42 -43
  82. package/node_modules/@slack/socket-mode/node_modules/@types/node/quic.d.ts +1049 -84
  83. package/node_modules/@slack/socket-mode/node_modules/@types/node/sqlite.d.ts +14 -1
  84. package/node_modules/@slack/socket-mode/node_modules/@types/node/stream/iter.d.ts +3 -2
  85. package/node_modules/@slack/socket-mode/node_modules/@types/node/test.d.ts +61 -0
  86. package/node_modules/@slack/socket-mode/node_modules/@types/node/v8.d.ts +20 -23
  87. package/node_modules/@slack/web-api/node_modules/@types/node/README.md +1 -1
  88. package/node_modules/@slack/web-api/node_modules/@types/node/child_process.d.ts +0 -1
  89. package/node_modules/@slack/web-api/node_modules/@types/node/crypto.d.ts +6 -6
  90. package/node_modules/@slack/web-api/node_modules/@types/node/dns/promises.d.ts +5 -5
  91. package/node_modules/@slack/web-api/node_modules/@types/node/dns.d.ts +5 -5
  92. package/node_modules/@slack/web-api/node_modules/@types/node/fs.d.ts +7 -0
  93. package/node_modules/@slack/web-api/node_modules/@types/node/http.d.ts +30 -0
  94. package/node_modules/@slack/web-api/node_modules/@types/node/http2.d.ts +4 -4
  95. package/node_modules/@slack/web-api/node_modules/@types/node/os.d.ts +30 -30
  96. package/node_modules/@slack/web-api/node_modules/@types/node/package.json +2 -2
  97. package/node_modules/@slack/web-api/node_modules/@types/node/perf_hooks.d.ts +2 -1
  98. package/node_modules/@slack/web-api/node_modules/@types/node/process.d.ts +42 -43
  99. package/node_modules/@slack/web-api/node_modules/@types/node/quic.d.ts +1049 -84
  100. package/node_modules/@slack/web-api/node_modules/@types/node/sqlite.d.ts +14 -1
  101. package/node_modules/@slack/web-api/node_modules/@types/node/stream/iter.d.ts +3 -2
  102. package/node_modules/@slack/web-api/node_modules/@types/node/test.d.ts +61 -0
  103. package/node_modules/@slack/web-api/node_modules/@types/node/v8.d.ts +20 -23
  104. package/node_modules/typebox/build/format/date.d.mts +1 -1
  105. package/node_modules/typebox/build/format/date.mjs +1 -1
  106. package/node_modules/typebox/build/format/date_time.d.mts +2 -2
  107. package/node_modules/typebox/build/format/date_time.mjs +3 -3
  108. package/node_modules/typebox/build/format/email.d.mts +1 -1
  109. package/node_modules/typebox/build/format/email.mjs +2 -2
  110. package/node_modules/typebox/build/format/hostname.mjs +2 -10
  111. package/node_modules/typebox/build/format/idn_email.d.mts +1 -1
  112. package/node_modules/typebox/build/format/idn_email.mjs +3 -3
  113. package/node_modules/typebox/build/format/idn_hostname.d.mts +1 -0
  114. package/node_modules/typebox/build/format/idn_hostname.mjs +3 -11
  115. package/node_modules/typebox/build/format/idna/format/bidi.d.mts +3 -0
  116. package/node_modules/typebox/build/format/idna/format/bidi.mjs +98 -0
  117. package/node_modules/typebox/build/format/idna/format/puny.d.mts +3 -0
  118. package/node_modules/typebox/build/format/idna/format/puny.mjs +144 -0
  119. package/node_modules/typebox/build/format/idna/hostname.d.mts +1 -0
  120. package/node_modules/typebox/build/format/idna/hostname.mjs +16 -0
  121. package/node_modules/typebox/build/format/idna/idn-hostname.d.mts +1 -0
  122. package/node_modules/typebox/build/format/idna/idn-hostname.mjs +23 -0
  123. package/node_modules/typebox/build/format/idna/index.d.mts +2 -0
  124. package/node_modules/typebox/build/format/idna/index.mjs +2 -0
  125. package/node_modules/typebox/build/format/idna/label/ascii.d.mts +1 -0
  126. package/node_modules/typebox/build/format/idna/label/ascii.mjs +9 -0
  127. package/node_modules/typebox/build/format/idna/label/puny.d.mts +1 -0
  128. package/node_modules/typebox/build/format/idna/label/puny.mjs +28 -0
  129. package/node_modules/typebox/build/format/idna/label/unicode.d.mts +1 -0
  130. package/node_modules/typebox/build/format/idna/label/unicode.mjs +106 -0
  131. package/node_modules/typebox/build/format/idna/pattern/pattern.d.mts +30 -0
  132. package/node_modules/typebox/build/format/idna/pattern/pattern.mjs +70 -0
  133. package/node_modules/typebox/build/format/ipv4.d.mts +0 -1
  134. package/node_modules/typebox/build/format/ipv4.mjs +2 -32
  135. package/node_modules/typebox/build/format/ipv6.mjs +2 -61
  136. package/node_modules/typebox/build/format/iri.d.mts +2 -2
  137. package/node_modules/typebox/build/format/iri.mjs +26 -8
  138. package/node_modules/typebox/build/format/iri_reference.d.mts +2 -2
  139. package/node_modules/typebox/build/format/iri_reference.mjs +9 -55
  140. package/node_modules/typebox/build/format/regex.d.mts +1 -2
  141. package/node_modules/typebox/build/format/regex.mjs +2 -6
  142. package/node_modules/typebox/build/format/time.d.mts +2 -2
  143. package/node_modules/typebox/build/format/time.mjs +19 -14
  144. package/node_modules/typebox/build/format/uri.d.mts +1 -1
  145. package/node_modules/typebox/build/format/uri.mjs +3 -130
  146. package/node_modules/typebox/build/format/uri_reference.d.mts +1 -1
  147. package/node_modules/typebox/build/format/uri_reference.mjs +2 -3
  148. package/node_modules/typebox/build/format/uri_template.d.mts +2 -3
  149. package/node_modules/typebox/build/format/uri_template.mjs +4 -5
  150. package/node_modules/typebox/build/format/url.d.mts +3 -3
  151. package/node_modules/typebox/build/format/url.mjs +4 -5
  152. package/node_modules/typebox/build/guard/emit.d.mts +3 -1
  153. package/node_modules/typebox/build/guard/emit.mjs +12 -5
  154. package/node_modules/typebox/build/guard/guard.d.mts +8 -2
  155. package/node_modules/typebox/build/guard/guard.mjs +25 -4
  156. package/node_modules/typebox/build/guard/string.d.mts +2 -2
  157. package/node_modules/typebox/build/guard/string.mjs +7 -7
  158. package/node_modules/typebox/build/schema/engine/_context.mjs +3 -3
  159. package/node_modules/typebox/build/schema/engine/_functions.mjs +1 -2
  160. package/node_modules/typebox/build/schema/engine/_regexp.d.mts +2 -0
  161. package/node_modules/typebox/build/schema/engine/_regexp.mjs +4 -0
  162. package/node_modules/typebox/build/schema/engine/_stack.mjs +12 -13
  163. package/node_modules/typebox/build/schema/engine/additionalItems.mjs +17 -7
  164. package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +4 -3
  165. package/node_modules/typebox/build/schema/engine/contains.mjs +18 -6
  166. package/node_modules/typebox/build/schema/engine/enum.mjs +1 -1
  167. package/node_modules/typebox/build/schema/engine/items.mjs +26 -6
  168. package/node_modules/typebox/build/schema/engine/maxContains.mjs +3 -3
  169. package/node_modules/typebox/build/schema/engine/minContains.mjs +14 -4
  170. package/node_modules/typebox/build/schema/engine/not.mjs +4 -2
  171. package/node_modules/typebox/build/schema/engine/oneOf.mjs +7 -6
  172. package/node_modules/typebox/build/schema/engine/pattern.mjs +3 -2
  173. package/node_modules/typebox/build/schema/engine/patternProperties.mjs +4 -3
  174. package/node_modules/typebox/build/schema/engine/ref.mjs +1 -7
  175. package/node_modules/typebox/build/schema/engine/schema.mjs +13 -4
  176. package/node_modules/typebox/build/schema/engine/type.mjs +1 -1
  177. package/node_modules/typebox/build/schema/resolve/resolve.d.mts +4 -1
  178. package/node_modules/typebox/build/schema/resolve/resolve.mjs +202 -1
  179. package/node_modules/typebox/build/schema/static/propertyNames.d.mts +5 -0
  180. package/node_modules/typebox/build/schema/static/propertyNames.mjs +3 -0
  181. package/node_modules/typebox/build/schema/static/schema.d.mts +3 -0
  182. package/node_modules/typebox/build/schema/types/index.d.mts +0 -2
  183. package/node_modules/typebox/build/schema/types/index.mjs +0 -2
  184. package/node_modules/typebox/build/system/memory/clone.mjs +14 -11
  185. package/node_modules/typebox/build/system/memory/discard.mjs +6 -5
  186. package/node_modules/typebox/build/system/settings/settings.d.mts +9 -0
  187. package/node_modules/typebox/build/system/settings/settings.mjs +2 -0
  188. package/node_modules/typebox/build/type/engine/call/distribute_arguments.d.mts +6 -1
  189. package/node_modules/typebox/build/type/engine/call/distribute_arguments.mjs +16 -3
  190. package/node_modules/typebox/build/type/engine/call/instantiate.mjs +34 -4
  191. package/node_modules/typebox/build/type/engine/evaluate/broaden.d.mts +5 -5
  192. package/node_modules/typebox/build/type/engine/evaluate/broaden.mjs +20 -26
  193. package/node_modules/typebox/build/type/engine/evaluate/compare.d.mts +6 -10
  194. package/node_modules/typebox/build/type/engine/evaluate/compare.mjs +9 -13
  195. package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +7 -4
  196. package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +12 -19
  197. package/node_modules/typebox/build/type/engine/evaluate/distribute.d.mts +4 -20
  198. package/node_modules/typebox/build/type/engine/evaluate/distribute.mjs +8 -20
  199. package/node_modules/typebox/build/type/engine/evaluate/evaluate.d.mts +4 -4
  200. package/node_modules/typebox/build/type/engine/evaluate/evaluate.mjs +11 -8
  201. package/node_modules/typebox/build/type/engine/evaluate/flatten.d.mts +1 -1
  202. package/node_modules/typebox/build/type/engine/evaluate/flatten.mjs +3 -4
  203. package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +17 -2
  204. package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +26 -6
  205. package/node_modules/typebox/build/type/engine/exclude/operation.mjs +3 -4
  206. package/node_modules/typebox/build/type/engine/extract/operation.d.mts +1 -1
  207. package/node_modules/typebox/build/type/engine/extract/operation.mjs +3 -4
  208. package/node_modules/typebox/build/type/engine/priority/priority.d.mts +2 -2
  209. package/node_modules/typebox/build/type/engine/priority/priority.mjs +3 -4
  210. package/node_modules/typebox/build/type/script/mapping.d.mts +32 -29
  211. package/node_modules/typebox/build/type/script/mapping.mjs +18 -25
  212. package/node_modules/typebox/build/type/script/parser.d.mts +19 -25
  213. package/node_modules/typebox/build/type/script/parser.mjs +27 -23
  214. package/node_modules/typebox/build/value/errors/errors.d.mts +2 -2
  215. package/node_modules/typebox/build/value/errors/errors.mjs +1 -1
  216. package/node_modules/typebox/package.json +27 -27
  217. package/node_modules/typebox/readme.md +79 -82
  218. package/node_modules/ws/lib/permessage-deflate.js +3 -1
  219. package/node_modules/ws/package.json +1 -1
  220. package/openclaw.plugin.json +14 -6
  221. package/package.json +9 -7
  222. package/dist/account-configured-BwfXBo_F.js +0 -14
  223. package/dist/account-inspect-YJvFBbCR.js +0 -89
  224. package/dist/action-runtime.runtime-JtoOK9l5.js +0 -2
  225. package/dist/actions.runtime-CYLsYRai.js +0 -2
  226. package/dist/runtime-api-DBi7xc_g.js +0 -10
  227. package/dist/slack-client-kind-BXyOOICI.js +0 -94
  228. package/node_modules/typebox/build/format/_idna.d.mts +0 -2
  229. package/node_modules/typebox/build/format/_idna.mjs +0 -246
  230. package/node_modules/typebox/build/format/_puny.d.mts +0 -1
  231. package/node_modules/typebox/build/format/_puny.mjs +0 -77
  232. package/node_modules/typebox/build/schema/resolve/ref.d.mts +0 -3
  233. package/node_modules/typebox/build/schema/resolve/ref.mjs +0 -146
  234. package/node_modules/typebox/build/schema/types/contentEncoding.d.mts +0 -9
  235. package/node_modules/typebox/build/schema/types/contentEncoding.mjs +0 -13
  236. package/node_modules/typebox/build/schema/types/contentMediaType.d.mts +0 -9
  237. package/node_modules/typebox/build/schema/types/contentMediaType.mjs +0 -13
@@ -13,24 +13,27 @@ function FromClassInstance(value) {
13
13
  return value; // atomic
14
14
  }
15
15
  // ------------------------------------------------------------------
16
- // TypeObject
16
+ // SchemaObject
17
17
  //
18
- // Types have non-enumerable properties that MUST be preserved on Clone.
19
- // The following is the optimal path for TypeBox types.
18
+ // Schema objects have non-enumerable properties that MUST be preserved
19
+ // on Clone. The following is the optimal path these objects.
20
20
  // ------------------------------------------------------------------
21
- function IsTypeObject(value) {
21
+ function IsSchemaObject(value) {
22
22
  return (Guard.HasPropertyKey(value, '~kind') ||
23
23
  Guard.HasPropertyKey(value, '~unsafe'));
24
24
  }
25
- function FromTypeObject(value) {
25
+ function FromSchemaObject(value) {
26
26
  const result = {};
27
- const descriptors = Object.getOwnPropertyDescriptors(value);
28
- for (const key of Object.keys(descriptors)) {
27
+ for (const key of Guard.Keys(value)) {
29
28
  if (Guard.IsUnsafePropertyKey(key))
30
29
  continue; // (ignore: prototype-pollution)
31
- const descriptor = descriptors[key];
32
- if (Guard.HasPropertyKey(descriptor, 'value')) {
33
- Object.defineProperty(result, key, { ...descriptor, value: FromValue(descriptor.value) });
30
+ const descriptor = Object.getOwnPropertyDescriptor(value, key); // safe-name!
31
+ descriptor.value = FromValue(descriptor.value);
32
+ if (Guard.IsEqual(descriptor.enumerable, true)) {
33
+ result[key] = descriptor.value;
34
+ }
35
+ else {
36
+ Object.defineProperty(result, key, descriptor);
34
37
  }
35
38
  }
36
39
  return result;
@@ -55,7 +58,7 @@ function FromPlainObject(value) {
55
58
  // ------------------------------------------------------------------
56
59
  function FromObject(value) {
57
60
  return (Guard.IsClassInstance(value) ? FromClassInstance(value) :
58
- IsTypeObject(value) ? FromTypeObject(value) :
61
+ IsSchemaObject(value) ? FromSchemaObject(value) :
59
62
  FromPlainObject(value));
60
63
  }
61
64
  // ------------------------------------------------------------------
@@ -1,17 +1,18 @@
1
1
  // deno-lint-ignore-file no-explicit-any
2
2
  // deno-fmt-ignore-file
3
+ import { Guard } from '../../guard/index.mjs';
3
4
  import { Metrics } from './metrics.mjs';
4
5
  import { Clone } from './clone.mjs';
5
6
  /** Discards multiple property keys from the given object value */
6
7
  export function Discard(value, propertyKeys) {
7
8
  Metrics.discard += 1;
8
9
  const result = {};
9
- const descriptors = Object.getOwnPropertyDescriptors(Clone(value));
10
- const keysToDiscard = new Set(propertyKeys);
11
- for (const key of Object.keys(descriptors)) {
12
- if (keysToDiscard.has(key))
10
+ for (const key of Guard.Keys(value)) {
11
+ if (propertyKeys.includes(key))
13
12
  continue;
14
- Object.defineProperty(result, key, descriptors[key]);
13
+ const descriptor = Object.getOwnPropertyDescriptor(value, key); // safe-name!
14
+ descriptor.value = Clone(descriptor.value);
15
+ Object.defineProperty(result, key, descriptor);
15
16
  }
16
17
  return result;
17
18
  }
@@ -16,6 +16,15 @@ export interface TSettings {
16
16
  * @default 8
17
17
  */
18
18
  maxErrors: number;
19
+ /**
20
+ * Specifies the maximum number of instantiations allowed within a top-level generic instantiation
21
+ * context. This setting can be used to bound generic calls to a fixed count, which can be useful if
22
+ * evaluating string-encoded types originating from untrusted sources. Setting this value to 0 will
23
+ * disallow generics entirely, ensuring type instantiation runs linear.
24
+ *
25
+ * @default 128
26
+ */
27
+ maxInstantiationCount: number;
19
28
  /**
20
29
  * Enables or disables the use of runtime code evaluation to accelerate validation. By default,
21
30
  * TypeBox checks for `unsafe-eval` support in the environment before attempting to evaluate
@@ -3,6 +3,7 @@ import { Guard } from '../../guard/index.mjs';
3
3
  const settings = {
4
4
  immutableTypes: false,
5
5
  maxErrors: 8,
6
+ maxInstantiationCount: 128,
6
7
  useAcceleration: true,
7
8
  exactOptionalPropertyTypes: false,
8
9
  enumerableKind: false,
@@ -13,6 +14,7 @@ const settings = {
13
14
  export function Reset() {
14
15
  settings.immutableTypes = false;
15
16
  settings.maxErrors = 8;
17
+ settings.maxInstantiationCount = 128;
16
18
  settings.useAcceleration = true;
17
19
  settings.exactOptionalPropertyTypes = false;
18
20
  settings.enumerableKind = false;
@@ -1,12 +1,17 @@
1
1
  import { type TSchema } from '../../types/schema.mjs';
2
2
  import { type TUnion } from '../../types/union.mjs';
3
3
  import { type TDeferred } from '../../types/deferred.mjs';
4
+ import { type TEnum, type TEnumValue } from '../../types/enum.mjs';
5
+ import { type TTemplateLiteral } from '../../types/template_literal.mjs';
4
6
  import { type TRef } from '../../types/ref.mjs';
5
7
  import { type TParameter } from '../../types/parameter.mjs';
8
+ import { type TEvaluateTemplateLiteral } from '../evaluate/evaluate.mjs';
9
+ import { type TEvaluateEnum } from '../evaluate/evaluate.mjs';
6
10
  type TCollectDistributionNames<Expression extends TSchema, Result extends string[] = []> = (Expression extends TDeferred<'Conditional', [infer Left extends TSchema, infer _Right extends TSchema, infer True extends TSchema, infer False extends TSchema]> ? Left extends TRef ? TCollectDistributionNames<True, TCollectDistributionNames<False, [...Result, Left['$ref']]>> : TCollectDistributionNames<True, TCollectDistributionNames<False, Result>> : Expression extends TDeferred<'Mapped', [infer _Identifier extends TSchema, infer Type extends TSchema, infer _As extends TSchema, infer _Property extends TSchema]> ? (Type extends TDeferred<'KeyOf', [infer Ref extends TRef]> ? [...Result, Ref['$ref']] : Result) : Result);
7
11
  type TBuildDistributionArray<Parameters extends TParameter[], Names extends string[], Result extends boolean[] = []> = (Parameters extends [infer Left extends TParameter, ...infer Right extends TParameter[]] ? Left['name'] extends Names[number] ? TBuildDistributionArray<Right, Names, [...Result, true]> : TBuildDistributionArray<Right, Names, [...Result, false]> : Result);
8
12
  type TZipDistributionArray<Arguments extends TSchema[], DistributionArray extends boolean[], Result extends [boolean, TSchema][] = []> = (Arguments extends [infer ArgumentLeft extends TSchema, ...infer ArgumentRight extends TSchema[]] ? DistributionArray extends [infer BooleanLeft extends boolean, ...infer BooleanRight extends boolean[]] ? TZipDistributionArray<ArgumentRight, BooleanRight, [...Result, [BooleanLeft, ArgumentLeft]]> : Result : Result);
9
- type TExpand<Type extends TSchema> = (Type extends TUnion<infer Types extends TSchema[]> ? [...Types] : [Type]);
13
+ type TCanonicalArgument<Type extends TSchema> = (Type extends TTemplateLiteral<infer Pattern extends string> ? TEvaluateTemplateLiteral<Pattern> : Type extends TEnum<infer Values extends TEnumValue[]> ? TEvaluateEnum<Values> : Type);
14
+ type TExpand<Argument extends TSchema, CanonicalArgument extends TSchema = TCanonicalArgument<Argument>> = (CanonicalArgument extends TUnion<infer Types extends TSchema[]> ? [...Types] : [CanonicalArgument]);
10
15
  type TAppend<Current extends TSchema[][], Type extends TSchema, Result extends TSchema[][] = []> = (Current extends [infer Left extends TSchema[], ...infer Right extends TSchema[][]] ? TAppend<Right, Type, [...Result, [...Left, Type]]> : Result);
11
16
  type TCross<Current extends TSchema[][], Variants extends TSchema[], Result extends TSchema[][] = []> = (Variants extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TCross<Current, Right, [...Result, ...TAppend<Current, Left>]> : Result);
12
17
  type TDistribute<ZippedArguments extends [boolean, TSchema][], Result extends TSchema[][] = [[]]> = (ZippedArguments extends [infer Left extends [boolean, TSchema], ...infer Right extends [boolean, TSchema][]] ? Left[0] extends true ? TDistribute<Right, TCross<Result, TExpand<Left[1]>>> : TDistribute<Right, TCross<Result, [Left[1]]>> : Result);
@@ -2,7 +2,14 @@
2
2
  import { Guard } from '../../../guard/index.mjs';
3
3
  import { IsUnion } from '../../types/union.mjs';
4
4
  import { IsDeferred } from '../../types/deferred.mjs';
5
+ import { IsEnum } from '../../types/enum.mjs';
6
+ import { IsTemplateLiteral } from '../../types/template_literal.mjs';
5
7
  import { IsRef } from '../../types/ref.mjs';
8
+ // ------------------------------------------------------------------
9
+ // Infrastructure
10
+ // ------------------------------------------------------------------
11
+ import { EvaluateTemplateLiteral } from '../evaluate/evaluate.mjs';
12
+ import { EvaluateEnum } from '../evaluate/evaluate.mjs';
6
13
  function CollectDistributionNames(expression, result = []) {
7
14
  return (
8
15
  // Conditional
@@ -21,10 +28,16 @@ function BuildDistributionArray(parameters, names) {
21
28
  function ZipDistributionArray(arguments_, distributionArray, result = []) {
22
29
  return Guard.ShiftLeft(arguments_, (argumentLeft, argumentRight) => Guard.ShiftLeft(distributionArray, (booleanLeft, booleanRight) => ZipDistributionArray(argumentRight, booleanRight, [...result, [booleanLeft, argumentLeft]]), () => result), () => result);
23
30
  }
31
+ function CanonicalArgument(type) {
32
+ return (IsTemplateLiteral(type) ? EvaluateTemplateLiteral(type.pattern) :
33
+ IsEnum(type) ? EvaluateEnum(type.enum) :
34
+ type);
35
+ }
24
36
  function Expand(type) {
25
- return (IsUnion(type)
26
- ? [...type.anyOf]
27
- : [type]);
37
+ const canonicalArgument = CanonicalArgument(type);
38
+ return (IsUnion(canonicalArgument)
39
+ ? [...canonicalArgument.anyOf]
40
+ : [canonicalArgument]);
28
41
  }
29
42
  function Append(current, type) {
30
43
  return current.reduce((result, left) => [...result, [...left, type]], []);
@@ -1,4 +1,5 @@
1
1
  // deno-fmt-ignore-file
2
+ import { Settings } from '../../../system/settings/index.mjs';
2
3
  import { Guard } from '../../../guard/index.mjs';
3
4
  import { CallConstruct } from '../../types/call.mjs';
4
5
  import { Ref } from '../../types/ref.mjs';
@@ -13,6 +14,26 @@ import { State } from '../instantiate.mjs';
13
14
  import { DistributeArguments } from './distribute_arguments.mjs';
14
15
  import { ResolveTarget } from './resolve_target.mjs';
15
16
  import { ResolveArgumentsContext } from './resolve_arguments.mjs';
17
+ // ------------------------------------------------------------------
18
+ // InstantiationGuard
19
+ // ------------------------------------------------------------------
20
+ let instantiationDepth = 0;
21
+ let instantiationCount = 0;
22
+ function InstantiationAssert() {
23
+ if (Guard.IsLessThan(instantiationCount, Settings.Get().maxInstantiationCount))
24
+ return;
25
+ throw Error('Type instantiation is excessively deep and possibly infinite');
26
+ }
27
+ function InstantiationIncrement() {
28
+ InstantiationAssert();
29
+ instantiationCount++;
30
+ instantiationDepth++;
31
+ }
32
+ function InstantiationDecrement() {
33
+ instantiationDepth--;
34
+ if (Guard.IsEqual(instantiationDepth, 0))
35
+ instantiationCount = 0;
36
+ }
16
37
  function Peek(state) {
17
38
  const result = Guard.IsGreaterThan(state.callstack.length, 0) ? state.callstack[state.callstack.length - 1] : '';
18
39
  return result;
@@ -22,12 +43,21 @@ function IsTailCall(state, name) {
22
43
  return result;
23
44
  }
24
45
  function CallDispatch(context, state, target, parameters, expression, arguments_) {
25
- const argumentsContext = ResolveArgumentsContext(context, state, parameters, arguments_);
26
- const returnType = InstantiateType(argumentsContext, State([...state['callstack'], target['$ref']], state['visited']), expression);
27
- return InstantiateType(argumentsContext, State([], []), returnType);
46
+ InstantiationIncrement();
47
+ try {
48
+ const argumentsContext = ResolveArgumentsContext(context, state, parameters, arguments_);
49
+ const returnType = InstantiateType(argumentsContext, State([...state['callstack'], target['$ref']], state['visited']), expression);
50
+ return InstantiateType(argumentsContext, State([], []), returnType);
51
+ }
52
+ finally {
53
+ InstantiationDecrement();
54
+ }
28
55
  }
29
56
  function CallDistributed(context, state, target, parameters, expression, distributedArguments) {
30
- return distributedArguments.reduce((result, arguments_) => [...result, CallDispatch(context, state, target, parameters, expression, arguments_)], []);
57
+ return distributedArguments.reduce((result, arguments_) => {
58
+ const returnType = CallDispatch(context, state, target, parameters, expression, arguments_);
59
+ return [...result, returnType];
60
+ }, []);
31
61
  }
32
62
  function CallImmediate(context, state, target, parameters, expression, arguments_) {
33
63
  const distributedArguments = DistributeArguments(parameters, arguments_, expression);
@@ -2,13 +2,13 @@ import { type TSchema } from '../../types/schema.mjs';
2
2
  import { type TAny } from '../../types/any.mjs';
3
3
  import { type TNever } from '../../types/never.mjs';
4
4
  import { type TObject } from '../../types/object.mjs';
5
- import { type TCompare, ResultRightInside, ResultLeftInside, ResultEqual } from './compare.mjs';
5
+ import { type TUnknown } from '../../types/unknown.mjs';
6
+ import { type TCompare, CompareResultLeftInside, CompareResultEqual, CompareResultDisjoint } from './compare.mjs';
6
7
  import { type TFlatten } from './flatten.mjs';
7
8
  import { type TEvaluateType } from './evaluate.mjs';
8
- type TBroadFilter<Type extends TSchema, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TCompare<Type, Left> extends typeof ResultRightInside ? TBroadFilter<Type, Right, [...Result]> : TBroadFilter<Type, Right, [...Result, Left]> : Result);
9
- type TIsBroadestType<Type extends TSchema, Types extends TSchema[]> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TCompare<Type, Left> extends typeof ResultLeftInside | typeof ResultEqual ? false : TIsBroadestType<Type, Right> : true);
10
- type TBroadenType<Type extends TSchema, Types extends TSchema[], Evaluated extends TSchema = TEvaluateType<Type>, Result extends TSchema[] = (Evaluated extends TAny ? [Evaluated] : TIsBroadestType<Evaluated, Types> extends true ? [...TBroadFilter<Evaluated, Types>, Evaluated] : Types)> = Result;
11
- type TBroadenTypes<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? (Left extends TObject ? TBroadenTypes<Right, [...Result, Left]> : Left extends TNever ? TBroadenTypes<Right, Result> : TBroadenTypes<Right, TBroadenType<Left, Result>>) : Result);
9
+ type TBroadenFilter<Type extends TSchema, Types extends TSchema[], Result extends TSchema[] = [], All extends TSchema[] = Types> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TCompare<Type, Left> extends typeof CompareResultLeftInside | typeof CompareResultEqual ? All : TCompare<Type, Left> extends typeof CompareResultDisjoint ? TBroadenFilter<Type, Right, [...Result, Left], All> : TBroadenFilter<Type, Right, Result, All> : [...Result, Type]);
10
+ type TBroadenType<Type extends TSchema, Types extends TSchema[], Result extends TSchema[], Evaluated extends TSchema = TEvaluateType<Type>> = (Evaluated extends TAny ? [Evaluated] : Evaluated extends TUnknown ? [Evaluated] : Evaluated extends TNever ? TBroadenTypes<Types, Result> : Evaluated extends TObject ? TBroadenTypes<Types, [...Result, Evaluated]> : TBroadenTypes<Types, TBroadenFilter<Evaluated, Result>>);
11
+ type TBroadenTypes<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TBroadenType<Left, Right, Result> : Result);
12
12
  export type TBroaden<Types extends TSchema[], Broadened extends TSchema[] = TBroadenTypes<Types>, Flattened extends TSchema[] = TFlatten<Broadened>> = Flattened;
13
13
  /** Broadens a set of types and returns either the most broad type, or union or disjoint types. */
14
14
  export declare function Broaden<Types extends TSchema[]>(types: [...Types]): TBroaden<Types>;
@@ -3,37 +3,31 @@ import { Guard } from '../../../guard/index.mjs';
3
3
  import { IsAny } from '../../types/any.mjs';
4
4
  import { IsNever } from '../../types/never.mjs';
5
5
  import { IsObject } from '../../types/object.mjs';
6
- import { Compare, ResultRightInside, ResultLeftInside, ResultEqual } from './compare.mjs';
6
+ import { IsUnknown } from '../../types/unknown.mjs';
7
+ import { Compare, CompareResultLeftInside, CompareResultEqual, CompareResultDisjoint } from './compare.mjs';
7
8
  import { Flatten } from './flatten.mjs';
8
9
  import { EvaluateType } from './evaluate.mjs';
9
- function BroadFilter(type, types) {
10
- return types.filter(left => {
11
- return Compare(type, left) === ResultRightInside
12
- ? false
13
- : true;
14
- });
15
- }
16
- function IsBroadestType(type, types) {
17
- const result = types.some(left => {
18
- const result = Compare(type, left);
19
- return Guard.IsEqual(result, ResultLeftInside) || Guard.IsEqual(result, ResultEqual);
20
- });
21
- return Guard.IsEqual(result, false);
10
+ function BroadenFilter(type, types, result = [], all = types) {
11
+ return Guard.ShiftLeft(types, (left, right) => {
12
+ const compare = Compare(type, left);
13
+ return ((Guard.IsEqual(compare, CompareResultLeftInside) || Guard.IsEqual(compare, CompareResultEqual))
14
+ ? all // Left in set. Return original All set.
15
+ : Guard.IsEqual(compare, CompareResultDisjoint)
16
+ ? BroadenFilter(type, right, [...result, left], all) // Left is disjoint, keep it
17
+ : BroadenFilter(type, right, result, all) // Left in Type, drop it
18
+ );
19
+ }, () => [...result, type]); // Type broadest in set
22
20
  }
23
- function BroadenType(type, types) {
21
+ function BroadenType(type, types, result) {
24
22
  const evaluated = EvaluateType(type);
25
- return (IsAny(evaluated) ? [evaluated] :
26
- IsBroadestType(evaluated, types)
27
- ? [...BroadFilter(evaluated, types), evaluated]
28
- : types);
23
+ return (IsAny(evaluated) ? [evaluated] : // terminate (always the most broad)
24
+ IsUnknown(evaluated) ? [evaluated] : // terminate (always the most broad)
25
+ IsNever(evaluated) ? BroadenTypes(types, result) : // ignored: never is dropped
26
+ IsObject(evaluated) ? BroadenTypes(types, [...result, evaluated]) : // objects are always considered (too expensive to compare)
27
+ BroadenTypes(types, BroadenFilter(evaluated, result)));
29
28
  }
30
- function BroadenTypes(types) {
31
- return types.reduce((result, left) => {
32
- return (IsObject(left) ? [...result, left] : // push
33
- IsNever(left) ? result : // ignore
34
- BroadenType(left, result) // broaden
35
- );
36
- }, []);
29
+ function BroadenTypes(types, result = []) {
30
+ return Guard.ShiftLeft(types, (left, right) => (BroadenType(left, right, result)), () => result);
37
31
  }
38
32
  /** Broadens a set of types and returns either the most broad type, or union or disjoint types. */
39
33
  export function Broaden(types) {
@@ -1,15 +1,11 @@
1
1
  import { type TSchema } from '../../types/index.mjs';
2
- import { type TUnknown } from '../../types/unknown.mjs';
3
2
  import { type TExtends, ExtendsResult } from "../../extends/index.mjs";
4
- export declare const ResultEqual = "equal";
5
- export declare const ResultDisjoint = "disjoint";
6
- export declare const ResultLeftInside = "left-inside";
7
- export declare const ResultRightInside = "right-inside";
8
- export type TCompareResult = typeof ResultEqual | typeof ResultDisjoint | typeof ResultLeftInside | typeof ResultRightInside;
3
+ export declare const CompareResultEqual = 0;
4
+ export declare const CompareResultDisjoint = 1;
5
+ export declare const CompareResultLeftInside = 2;
6
+ export declare const CompareResultRightInside = 3;
7
+ export type TCompareResult = (typeof CompareResultEqual | typeof CompareResultDisjoint | typeof CompareResultLeftInside | typeof CompareResultRightInside);
9
8
  /** Compares left and right types and determines their set relationship */
10
- export type TCompare<Left extends TSchema, Right extends TSchema, Extends extends [ExtendsResult.TResult, ExtendsResult.TResult] = [
11
- Left extends TUnknown ? ExtendsResult.TExtendsFalse : TExtends<{}, Left, Right>,
12
- Left extends TUnknown ? ExtendsResult.TExtendsTrue : TExtends<{}, Right, Left>
13
- ]> = (Extends extends [ExtendsResult.TExtendsTrueLike, ExtendsResult.TExtendsTrueLike] ? typeof ResultEqual : Extends extends [ExtendsResult.TExtendsTrueLike, ExtendsResult.TExtendsFalse] ? typeof ResultLeftInside : Extends extends [ExtendsResult.TExtendsFalse, ExtendsResult.TExtendsTrueLike] ? typeof ResultRightInside : typeof ResultDisjoint);
9
+ export type TCompare<Left extends TSchema, Right extends TSchema, Extends extends [ExtendsResult.TResult, ExtendsResult.TResult] = [TExtends<{}, Left, Right>, TExtends<{}, Right, Left>]> = (Extends extends [ExtendsResult.TExtendsTrueLike, ExtendsResult.TExtendsTrueLike] ? typeof CompareResultEqual : Extends extends [ExtendsResult.TExtendsTrueLike, ExtendsResult.TExtendsFalse] ? typeof CompareResultLeftInside : Extends extends [ExtendsResult.TExtendsFalse, ExtendsResult.TExtendsTrueLike] ? typeof CompareResultRightInside : typeof CompareResultDisjoint);
14
10
  /** Compares left and right types and determines their set relationship. */
15
11
  export declare function Compare<Left extends TSchema, Right extends TSchema>(left: Left, right: Right): TCompare<Left, Right>;
@@ -1,22 +1,18 @@
1
1
  // deno-lint-ignore-file ban-types
2
2
  // deno-fmt-ignore-file
3
- import { IsUnknown } from '../../types/unknown.mjs';
4
3
  import { Extends, ExtendsResult } from "../../extends/index.mjs";
5
4
  // ------------------------------------------------------------------
6
5
  // TCompare
7
6
  // ------------------------------------------------------------------
8
- export const ResultEqual = 'equal';
9
- export const ResultDisjoint = 'disjoint';
10
- export const ResultLeftInside = 'left-inside';
11
- export const ResultRightInside = 'right-inside';
7
+ export const CompareResultEqual = 0; // 'equal'
8
+ export const CompareResultDisjoint = 1; // 'disjoint'
9
+ export const CompareResultLeftInside = 2; // 'left-inside'
10
+ export const CompareResultRightInside = 3; // 'right-inside'
12
11
  /** Compares left and right types and determines their set relationship. */
13
12
  export function Compare(left, right) {
14
- const extendsCheck = [
15
- IsUnknown(left) ? ExtendsResult.ExtendsFalse() : Extends({}, left, right),
16
- IsUnknown(left) ? ExtendsResult.ExtendsTrue({}) : Extends({}, right, left),
17
- ];
18
- return (ExtendsResult.IsExtendsTrueLike(extendsCheck[0]) && ExtendsResult.IsExtendsTrueLike(extendsCheck[1]) ? ResultEqual :
19
- ExtendsResult.IsExtendsTrueLike(extendsCheck[0]) && ExtendsResult.IsExtendsFalse(extendsCheck[1]) ? ResultLeftInside :
20
- ExtendsResult.IsExtendsFalse(extendsCheck[0]) && ExtendsResult.IsExtendsTrueLike(extendsCheck[1]) ? ResultRightInside :
21
- ResultDisjoint);
13
+ const extendsCheck = [Extends({}, left, right), Extends({}, right, left)];
14
+ return (ExtendsResult.IsExtendsTrueLike(extendsCheck[0]) && ExtendsResult.IsExtendsTrueLike(extendsCheck[1]) ? CompareResultEqual :
15
+ ExtendsResult.IsExtendsTrueLike(extendsCheck[0]) && ExtendsResult.IsExtendsFalse(extendsCheck[1]) ? CompareResultLeftInside :
16
+ ExtendsResult.IsExtendsFalse(extendsCheck[0]) && ExtendsResult.IsExtendsTrueLike(extendsCheck[1]) ? CompareResultRightInside :
17
+ CompareResultDisjoint);
22
18
  }
@@ -1,4 +1,3 @@
1
- import { type TUnreachable } from '../../../system/unreachable/index.mjs';
2
1
  import { type TReadonly } from '../../types/_readonly.mjs';
3
2
  import { type TOptional } from '../../types/_optional.mjs';
4
3
  import { type TSchema } from '../../types/schema.mjs';
@@ -12,6 +11,10 @@ import { type TRemoveReadonly } from '../../action/_remove_readonly.mjs';
12
11
  import { type TRemoveOptional } from '../../action/_remove_optional.mjs';
13
12
  import { type TTupleElementsToProperties } from '../tuple/to_object.mjs';
14
13
  import { type TEvaluateIntersect } from './evaluate.mjs';
14
+ /** Returns true if the type is a valid operand to Composite. */
15
+ export type TCanComposite<Type extends TSchema> = (Type extends TObject<infer _ extends TProperties> ? true : Type extends TTuple<infer _ extends TSchema[]> ? true : false);
16
+ /** Returns true if the type is a valid operand to Composite. */
17
+ export declare function CanComposite<Type extends TSchema>(type: Type): TCanComposite<Type>;
15
18
  type TIsReadonlyProperty<Left extends TSchema, Right extends TSchema> = (Left extends TReadonly<Left> ? Right extends TReadonly<Right> ? true : false : false);
16
19
  type TIsOptionalProperty<Left extends TSchema, Right extends TSchema> = (Left extends TOptional<Left> ? Right extends TOptional<Right> ? true : false : false);
17
20
  type TCompositeProperty<Left extends TSchema, Right extends TSchema, IsReadonly extends boolean = TIsReadonlyProperty<Left, Right>, IsOptional extends boolean = TIsOptionalProperty<Left, Right>, Evaluated extends TSchema = TEvaluateIntersect<[Left, Right]>, Property extends TSchema = TRemoveReadonly<TRemoveOptional<Evaluated>>> = ([
@@ -25,10 +28,10 @@ type TCompositeProperty<Left extends TSchema, Right extends TSchema, IsReadonly
25
28
  IsOptional
26
29
  ] extends [false, true] ? TAddOptional<Property> : Property);
27
30
  type TCompositePropertyKey<Left extends TProperties, Right extends TProperties, Key extends PropertyKey, Result extends TSchema = (Key extends keyof Left ? Key extends keyof Right ? TCompositeProperty<Left[Key], Right[Key]> : Left[Key] : Key extends keyof Right ? Right[Key] : TNever)> = Result;
28
- type TCompositeProperties<Left extends TProperties, Right extends TProperties, Result extends TProperties = {
29
- [Key in keyof (Right & Left)]: TCompositePropertyKey<Left, Right, Key>;
31
+ type TCompositeProperties<Left extends TProperties, Right extends TProperties, Keys extends PropertyKey = keyof (Left & Right), Result extends TProperties = {
32
+ [Key in Keys]: TCompositePropertyKey<Left, Right, Key>;
30
33
  }> = Result;
31
- type TGetProperties<Type extends TSchema, Result extends TProperties = (Type extends TObject<infer Properties extends TProperties> ? Properties : Type extends TTuple<infer Types extends TSchema[]> ? TTupleElementsToProperties<Types> : TUnreachable)> = Result;
34
+ type TGetProperties<Type extends TSchema, Result extends TProperties = (Type extends TObject<infer Properties extends TProperties> ? Properties : Type extends TTuple<infer Types extends TSchema[]> ? TTupleElementsToProperties<Types> : {})> = Result;
32
35
  export type TComposite<Left extends TSchema, Right extends TSchema, LeftProperties extends TProperties = TGetProperties<Left>, RightProperties extends TProperties = TGetProperties<Right>, Properties extends TProperties = TCompositeProperties<LeftProperties, RightProperties>, Result extends TSchema = TObject<Properties>> = Result;
33
36
  export declare function Composite<Left extends TSchema, Right extends TSchema>(left: Left, right: Right): TComposite<Left, Right>;
34
37
  export {};
@@ -1,6 +1,5 @@
1
1
  // deno-fmt-ignore-file
2
2
  // deno-lint-ignore-file
3
- import { Unreachable } from '../../../system/unreachable/index.mjs';
4
3
  import { Guard } from '../../../guard/index.mjs';
5
4
  import { IsReadonly } from '../../types/_readonly.mjs';
6
5
  import { IsOptional } from '../../types/_optional.mjs';
@@ -13,6 +12,10 @@ import { RemoveReadonly } from '../../action/_remove_readonly.mjs';
13
12
  import { RemoveOptional } from '../../action/_remove_optional.mjs';
14
13
  import { TupleElementsToProperties } from '../tuple/to_object.mjs';
15
14
  import { EvaluateIntersect } from './evaluate.mjs';
15
+ /** Returns true if the type is a valid operand to Composite. */
16
+ export function CanComposite(type) {
17
+ return (IsObject(type) || IsTuple(type));
18
+ }
16
19
  function IsReadonlyProperty(left, right) {
17
20
  return (IsReadonly(left) ? IsReadonly(right) ? true : false : false);
18
21
  }
@@ -32,36 +35,26 @@ function CompositeProperty(left, right) {
32
35
  }
33
36
  function CompositePropertyKey(left, right, key) {
34
37
  return (key in left
35
- ? key in right
36
- ? CompositeProperty(left[key], right[key])
37
- : left[key]
38
- : key in right
39
- ? right[key]
40
- : Never());
38
+ ? key in right ? CompositeProperty(left[key], right[key]) : left[key]
39
+ : key in right ? right[key] : Never());
41
40
  }
42
41
  function CompositeProperties(left, right) {
43
- const keys = new Set([...Guard.Keys(right), ...Guard.Keys(left)]);
44
- return [...keys].reduce((result, key) => {
42
+ const keys = new Set([...Guard.Keys(left), ...Guard.Keys(right)]);
43
+ const result = [...keys].reduce((result, key) => {
45
44
  return { ...result, [key]: CompositePropertyKey(left, right, key) };
46
45
  }, {});
46
+ return result;
47
47
  }
48
- // ------------------------------------------------------------------
49
- // deno-coverage-ignore-start - symmetric unreachable | internal
50
- //
51
- // Composite is called by Distribute which provisions the type as
52
- // either TObject ot TTuple. Fall-through unreachable.
53
- //
54
- // ------------------------------------------------------------------
55
48
  function GetProperties(type) {
56
49
  const result = (IsObject(type) ? type.properties :
57
50
  IsTuple(type) ? TupleElementsToProperties(type.items) :
58
- Unreachable() // {}
59
- );
51
+ {});
60
52
  return result;
61
53
  }
62
54
  export function Composite(left, right) {
63
55
  const leftProperties = GetProperties(left);
64
56
  const rightProperties = GetProperties(right);
65
57
  const properties = CompositeProperties(leftProperties, rightProperties);
66
- return Object(properties);
58
+ const result = Object(properties);
59
+ return result;
67
60
  }
@@ -1,27 +1,11 @@
1
1
  import { type TSchema } from '../../types/schema.mjs';
2
- import { type TProperties } from '../../types/properties.mjs';
3
2
  import { type TUnion } from '../../types/union.mjs';
4
- import { type TObject } from '../../types/object.mjs';
5
- import { type TTuple } from '../../types/tuple.mjs';
6
- import { type TComposite } from './composite.mjs';
7
3
  import { type TNarrow } from './narrow.mjs';
8
- import { type TEvaluateType } from './evaluate.mjs';
9
4
  import { type TEvaluateIntersect } from './evaluate.mjs';
10
- type TIsObjectLike<Type extends TSchema> = (Type extends TObject<infer _ extends TProperties> ? true : Type extends TTuple<infer _ extends TSchema[]> ? true : false);
11
- type TIsUnionOperand<Left extends TSchema, Right extends TSchema, IsUnionLeft extends boolean = Left extends TUnion ? true : false, IsUnionRight extends boolean = Right extends TUnion ? true : false, Result extends boolean = IsUnionLeft extends true ? true : IsUnionRight extends true ? true : false> = Result;
12
- type TDistributeOperation<Left extends TSchema, Right extends TSchema, EvaluatedLeft extends TSchema = TEvaluateType<Left>, EvaluatedRight extends TSchema = TEvaluateType<Right>, IsUnionOperand extends boolean = TIsUnionOperand<EvaluatedLeft, EvaluatedRight>, IsObjectLeft extends boolean = TIsObjectLike<EvaluatedLeft>, IsObjectRight extends boolean = TIsObjectLike<EvaluatedRight>, Result extends TSchema = ([
13
- IsUnionOperand
14
- ] extends [true] ? TEvaluateIntersect<[EvaluatedLeft, EvaluatedRight]> : [
15
- IsObjectLeft,
16
- IsObjectRight
17
- ] extends [true, true] ? TComposite<EvaluatedLeft, EvaluatedRight> : [
18
- IsObjectLeft,
19
- IsObjectRight
20
- ] extends [true, false] ? EvaluatedLeft : [
21
- IsObjectLeft,
22
- IsObjectRight
23
- ] extends [false, true] ? EvaluatedRight : TNarrow<EvaluatedLeft, EvaluatedRight>)> = Result;
24
- type TDistributeType<Type extends TSchema, Distribution extends TSchema[], Result extends TSchema[] = []> = (Distribution extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TDistributeType<Type, Right, [...Result, TDistributeOperation<Type, Left>]> : Result extends [] ? [Type] : Result);
5
+ import { type TEvaluateType } from './evaluate.mjs';
6
+ type TShouldEvaluate<Left extends TSchema, Right extends TSchema, IsUnionLeft extends boolean = Left extends TUnion ? true : false, IsUnionRight extends boolean = Right extends TUnion ? true : false, Result extends boolean = IsUnionLeft extends true ? true : IsUnionRight extends true ? true : false> = Result;
7
+ type TDistributeOperation<Left extends TSchema, Right extends TSchema, EvaluatedLeft extends TSchema = TEvaluateType<Left>, EvaluatedRight extends TSchema = TEvaluateType<Right>, ShouldEvaluate extends boolean = TShouldEvaluate<EvaluatedLeft, EvaluatedRight>, Result extends TSchema = [ShouldEvaluate] extends [true] ? TEvaluateIntersect<[EvaluatedLeft, EvaluatedRight]> : TNarrow<EvaluatedLeft, EvaluatedRight>> = Result;
8
+ type TDistributeType<Type extends TSchema, Distribution extends TSchema[], Result extends TSchema[] = []> = (Distribution extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TDistributeType<Type, Right, [...Result, TDistributeOperation<Left, Type>]> : Result extends [] ? [Type] : Result);
25
9
  type TDistributeUnion<Types extends TSchema[], Distribution extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TDistributeUnion<Right, Distribution, [...Result, ...TDistribute<[Left], Distribution>]> : Result);
26
10
  export type TDistribute<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TUnion<infer UnionTypes extends TSchema[]> ? TDistribute<Right, TDistributeUnion<UnionTypes, Result>> : TDistribute<Right, TDistributeType<Left, Result>> : Result);
27
11
  export declare function Distribute<Types extends TSchema[]>(types: [...Types], result?: TSchema[]): TDistribute<Types>;
@@ -2,36 +2,24 @@
2
2
  // deno-fmt-ignore-file
3
3
  import { Guard } from '../../../guard/index.mjs';
4
4
  import { IsUnion } from '../../types/union.mjs';
5
- import { IsObject } from '../../types/object.mjs';
6
- import { IsTuple } from '../../types/tuple.mjs';
7
- import { Composite } from './composite.mjs';
8
5
  import { Narrow } from './narrow.mjs';
9
- import { EvaluateType } from './evaluate.mjs';
10
6
  import { EvaluateIntersect } from './evaluate.mjs';
11
- function IsObjectLike(type) {
12
- return IsObject(type) || IsTuple(type);
13
- }
14
- function IsUnionOperand(left, right) {
15
- const isUnionLeft = IsUnion(left);
16
- const isUnionRight = IsUnion(right);
17
- const result = isUnionLeft || isUnionRight;
7
+ import { EvaluateType } from './evaluate.mjs';
8
+ function ShouldEvaluate(left, right) {
9
+ const result = IsUnion(left) || IsUnion(right);
18
10
  return result;
19
11
  }
20
12
  function DistributeOperation(left, right) {
21
13
  const evaluatedLeft = EvaluateType(left);
22
14
  const evaluatedRight = EvaluateType(right);
23
- const isUnionOperand = IsUnionOperand(evaluatedLeft, evaluatedRight);
24
- const isObjectLeft = IsObjectLike(evaluatedLeft);
25
- const IsObjectRight = IsObjectLike(evaluatedRight);
26
- const result = (isUnionOperand ? EvaluateIntersect([evaluatedLeft, evaluatedRight]) :
27
- isObjectLeft && IsObjectRight ? Composite(evaluatedLeft, evaluatedRight) :
28
- isObjectLeft && !IsObjectRight ? evaluatedLeft :
29
- !isObjectLeft && IsObjectRight ? evaluatedRight :
30
- Narrow(evaluatedLeft, evaluatedRight));
15
+ const shouldEvaluate = ShouldEvaluate(evaluatedLeft, evaluatedRight);
16
+ const result = shouldEvaluate
17
+ ? EvaluateIntersect([evaluatedLeft, evaluatedRight])
18
+ : Narrow(evaluatedLeft, evaluatedRight);
31
19
  return result;
32
20
  }
33
21
  function DistributeType(type, types, result = []) {
34
- return Guard.ShiftLeft(types, (left, right) => DistributeType(type, right, [...result, DistributeOperation(type, left)]), () => Guard.IsEqual(result.length, 0)
22
+ return Guard.ShiftLeft(types, (left, right) => DistributeType(type, right, [...result, DistributeOperation(left, type)]), () => Guard.IsEqual(result.length, 0)
35
23
  ? [type]
36
24
  : result);
37
25
  }
@@ -1,8 +1,8 @@
1
1
  import { type TSchema } from '../../types/schema.mjs';
2
2
  import { type TDependent } from '../../types/dependent.mjs';
3
3
  import { type TEnum, type TEnumValue } from '../../types/enum.mjs';
4
- import { type TLiteral } from '../../types/literal.mjs';
5
4
  import { type TIntersect } from '../../types/intersect.mjs';
5
+ import { type TLiteral } from '../../types/literal.mjs';
6
6
  import { type TNever } from '../../types/never.mjs';
7
7
  import { type TTemplateLiteral } from '../../types/template_literal.mjs';
8
8
  import { type TUnion } from '../../types/union.mjs';
@@ -10,11 +10,11 @@ import { type TDistribute } from './distribute.mjs';
10
10
  import { type TBroaden } from './broaden.mjs';
11
11
  import { type TExcludeOperation } from '../exclude/operation.mjs';
12
12
  import { type TTemplateLiteralDecode } from '../template_literal/decode.mjs';
13
- export type TEvaluateDependent<If extends TSchema, Then extends TSchema, Else extends TSchema, Intersect extends TSchema = TIntersect<[If, Then]>, Excluded extends TSchema = TExcludeOperation<Else, If>, Result extends TSchema = TEvaluateUnion<[Intersect, Excluded]>> = Result;
13
+ export type TEvaluateDependent<If extends TSchema, Then extends TSchema, Else extends TSchema, Intersected extends TSchema = TEvaluateIntersect<[If, Then]>, Excluded extends TSchema = TExcludeOperation<Else, If>, Result extends TSchema = TEvaluateUnion<[Intersected, Excluded]>> = Result;
14
14
  export declare function EvaluateDependent<If extends TSchema, Then extends TSchema, Else extends TSchema>(if_: If, then_: Then, else_: Else): TEvaluateDependent<If, Then, Else>;
15
15
  export type TEvaluateEnum<Values extends TEnumValue[], Result extends TSchema[] = []> = (Values extends [infer Left extends TEnumValue, ...infer Right extends TEnumValue[]] ? TEvaluateEnum<Right, [...Result, TLiteral<Left>]> : TEvaluateUnion<Result>);
16
- export declare function EvaluateEnum<Values extends TEnumValue[]>(values: [...Values]): TEvaluateEnum<Values>;
17
- export type TEvaluateIntersect<Types extends TSchema[], Distribution extends TSchema[] = TDistribute<Types>, Broadend extends TSchema[] = TBroaden<Distribution>, Result extends TSchema = TEvaluateUnionFast<Broadend>> = Result;
16
+ export declare function EvaluateEnum<Values extends TEnumValue[]>(values: [...Values], result?: TSchema[]): TEvaluateEnum<Values>;
17
+ export type TEvaluateIntersect<Types extends TSchema[], Distribution extends TSchema[] = TDistribute<Types>, Broadend extends TSchema[] = TBroaden<Distribution>, Result extends TSchema = TEvaluateUnion<Broadend>> = Result;
18
18
  export declare function EvaluateIntersect<Types extends TSchema[]>(types: [...Types]): TEvaluateIntersect<Types>;
19
19
  export type TEvaluateTemplateLiteral<Pattern extends string, Evaluated extends TSchema = TTemplateLiteralDecode<Pattern>, Result extends TSchema = TEvaluateType<Evaluated>> = Result;
20
20
  export declare function EvaluateTemplateLiteral<Pattern extends string>(pattern: Pattern): TEvaluateTemplateLiteral<Pattern>;