@openclaw/whatsapp 2026.8.1-beta.3 → 2026.8.2

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 (263) hide show
  1. package/dist/{accounts-BX2fZUyR.js → accounts-CeKQbu_s.js} +9 -26
  2. package/dist/{action-runtime-pM-ExU0l.js → action-runtime-Bw0loEdy.js} +2 -2
  3. package/dist/action-runtime-api.js +1 -1
  4. package/dist/action-runtime.runtime.js +1 -1
  5. package/dist/{call-tool-api.js → agent-tools-api.js} +13 -6
  6. package/dist/{agent-tools-login-BjRpD-JQ.js → agent-tools-login-B-2qZPzc.js} +12 -3
  7. package/dist/api.js +10 -10
  8. package/dist/{approval-handler.runtime-CkMMvUjk.js → approval-handler.runtime-DeyPb57-.js} +3 -3
  9. package/dist/{approval-reactions-Jyr1JaAK.js → approval-reactions-DGDA6hQ7.js} +7 -5
  10. package/dist/{auth-store-CtpBqH5S.js → auth-store-DTj1H9pv.js} +5 -3
  11. package/dist/{channel-DRMYRfZ8.js → channel-DxMmDjqK.js} +26 -24
  12. package/dist/channel-config-api.js +1 -1
  13. package/dist/channel-plugin-api.js +1 -1
  14. package/dist/{channel-react-action-CstrR0CT.js → channel-react-action-BUp7Wbfr.js} +3 -3
  15. package/dist/{channel.runtime-X3JC2gaq.js → channel.runtime-BwSnyXRX.js} +4 -4
  16. package/dist/{channel.setup-DhBBhbQv.js → channel.setup-aOFLSQyw.js} +1 -1
  17. package/dist/{config-schema-BQP5YCeK.js → config-schema-BYA6e_Ii.js} +6 -4
  18. package/dist/{connection-controller-CIYuBJrs.js → connection-controller-BvkxsbWi.js} +2 -2
  19. package/dist/{constants-HU41RHGI.js → constants-C7m81BNe.js} +1 -1
  20. package/dist/{directory-config-P7_3U73Z.js → directory-config-LgxYJLWY.js} +3 -3
  21. package/dist/directory-contract-api.js +1 -1
  22. package/dist/{group-session-key-DmFc_Cqi.js → group-session-key-KUguLmSZ.js} +4 -4
  23. package/dist/index.js +4 -4
  24. package/dist/light-runtime-api.js +2 -2
  25. package/dist/{login-BkpKpndm.js → login-Bk_jiXKD.js} +6 -5
  26. package/dist/{login-qr-1dpv6jjT.js → login-qr-B3m61NqA.js} +43 -20
  27. package/dist/login-qr-runtime.js +1 -1
  28. package/dist/{monitor-IzwQKizW.js → monitor-CTsyo-HE.js} +185 -162
  29. package/dist/{question-reactions-D3eAeB0i.js → question-reactions-B9D6MHXZ.js} +1 -1
  30. package/dist/runtime-api.js +9 -9
  31. package/dist/{send-CwvTU4RI.js → send-DiPjiygK.js} +54 -29
  32. package/dist/{send-api-obOSm2cC.js → send-api-kFcuhSiY.js} +43 -41
  33. package/dist/{setup-finalize-n4K2I2gJ.js → setup-finalize-CqH5wTK5.js} +7 -6
  34. package/dist/setup-plugin-api.js +1 -1
  35. package/dist/{setup-surface-Cwn3zyxK.js → setup-surface-Dm3T6S8t.js} +3 -3
  36. package/dist/{shared-wg42NKFB.js → shared-DDjonGys.js} +7 -6
  37. package/dist/{socket-close-2T0_jZTN.js → socket-close-CpkkJZCU.js} +9 -6
  38. package/dist/{targets-runtime-TMk0lGuy.js → targets-runtime-RBjx3pg_.js} +1 -2
  39. package/dist/{text-runtime-CaKLhowd.js → text-runtime-DyfmcATV.js} +1 -1
  40. package/node_modules/baileys/lib/Defaults/index.js +1 -1
  41. package/node_modules/baileys/lib/Socket/business.d.ts.map +1 -1
  42. package/node_modules/baileys/lib/Socket/chats.d.ts +1 -0
  43. package/node_modules/baileys/lib/Socket/chats.d.ts.map +1 -1
  44. package/node_modules/baileys/lib/Socket/chats.js +10 -5
  45. package/node_modules/baileys/lib/Socket/chats.js.map +1 -1
  46. package/node_modules/baileys/lib/Socket/communities.d.ts.map +1 -1
  47. package/node_modules/baileys/lib/Socket/groups.d.ts.map +1 -1
  48. package/node_modules/baileys/lib/Socket/index.d.ts.map +1 -1
  49. package/node_modules/baileys/lib/Socket/messages-recv.d.ts.map +1 -1
  50. package/node_modules/baileys/lib/Socket/messages-send.d.ts.map +1 -1
  51. package/node_modules/baileys/lib/Socket/newsletter.d.ts.map +1 -1
  52. package/node_modules/baileys/lib/Socket/socket.d.ts.map +1 -1
  53. package/node_modules/baileys/lib/Socket/socket.js +3 -0
  54. package/node_modules/baileys/lib/Socket/socket.js.map +1 -1
  55. package/node_modules/baileys/lib/Types/index.d.ts +1 -0
  56. package/node_modules/baileys/lib/Types/index.d.ts.map +1 -1
  57. package/node_modules/baileys/lib/Types/index.js.map +1 -1
  58. package/node_modules/baileys/lib/Utils/browser-utils.d.ts.map +1 -1
  59. package/node_modules/baileys/lib/Utils/browser-utils.js +1 -0
  60. package/node_modules/baileys/lib/Utils/browser-utils.js.map +1 -1
  61. package/node_modules/baileys/lib/Utils/generics.d.ts +1 -0
  62. package/node_modules/baileys/lib/Utils/generics.d.ts.map +1 -1
  63. package/node_modules/baileys/lib/Utils/generics.js +1 -1
  64. package/node_modules/baileys/lib/Utils/generics.js.map +1 -1
  65. package/node_modules/baileys/lib/Utils/tc-token-utils.d.ts.map +1 -1
  66. package/node_modules/baileys/lib/Utils/tc-token-utils.js +3 -2
  67. package/node_modules/baileys/lib/Utils/tc-token-utils.js.map +1 -1
  68. package/node_modules/baileys/lib/Utils/validate-connection.d.ts.map +1 -1
  69. package/node_modules/baileys/lib/Utils/validate-connection.js +9 -2
  70. package/node_modules/baileys/lib/Utils/validate-connection.js.map +1 -1
  71. package/node_modules/baileys/node_modules/content-type/README.md +2 -0
  72. package/node_modules/baileys/node_modules/content-type/dist/index.d.ts +20 -0
  73. package/node_modules/baileys/node_modules/content-type/dist/index.js +20 -14
  74. package/node_modules/baileys/node_modules/content-type/dist/index.js.map +1 -1
  75. package/node_modules/baileys/node_modules/content-type/package.json +1 -1
  76. package/node_modules/baileys/node_modules/file-type/package.json +1 -1
  77. package/node_modules/baileys/node_modules/file-type/readme.md +3 -0
  78. package/node_modules/baileys/node_modules/file-type/source/detectors/zip.js +6 -1
  79. package/node_modules/baileys/node_modules/file-type/source/index.d.ts +3 -0
  80. package/node_modules/baileys/node_modules/file-type/source/index.js +25 -13
  81. package/node_modules/baileys/node_modules/music-metadata/LICENSE.txt +9 -9
  82. package/node_modules/baileys/node_modules/music-metadata/README.md +878 -878
  83. package/node_modules/baileys/node_modules/music-metadata/lib/ParseError.d.ts +1 -1
  84. package/node_modules/baileys/node_modules/music-metadata/lib/ParseError.js +1 -1
  85. package/node_modules/baileys/node_modules/music-metadata/lib/asf/AsfObject.d.ts +1 -4
  86. package/node_modules/baileys/node_modules/music-metadata/lib/asf/AsfObject.js +66 -30
  87. package/node_modules/baileys/node_modules/music-metadata/lib/asf/AsfParser.d.ts +5 -1
  88. package/node_modules/baileys/node_modules/music-metadata/lib/asf/AsfParser.js +94 -25
  89. package/node_modules/baileys/node_modules/music-metadata/lib/dsf/DsfChunk.js +2 -2
  90. package/node_modules/baileys/node_modules/music-metadata/lib/dsf/DsfParser.js +38 -13
  91. package/node_modules/baileys/node_modules/music-metadata/lib/mp4/AtomToken.js +2 -1
  92. package/node_modules/baileys/node_modules/music-metadata/lib/mp4/MP4Parser.js +34 -7
  93. package/node_modules/baileys/node_modules/music-metadata/lib/ogg/speex/SpeexStream.d.ts +7 -0
  94. package/node_modules/baileys/node_modules/music-metadata/lib/ogg/speex/SpeexStream.js +13 -0
  95. package/node_modules/baileys/node_modules/music-metadata/lib/riff/RiffChunk.js +1 -1
  96. package/node_modules/baileys/node_modules/music-metadata/package.json +156 -156
  97. package/node_modules/baileys/node_modules/process-warning/.github/dependabot.yml +42 -2
  98. package/node_modules/baileys/node_modules/process-warning/.github/workflows/ci.yml +12 -1
  99. package/node_modules/baileys/node_modules/process-warning/.github/workflows/lock-threads.yml +19 -0
  100. package/node_modules/baileys/node_modules/process-warning/LICENSE +1 -1
  101. package/node_modules/baileys/node_modules/process-warning/README.md +41 -2
  102. package/node_modules/baileys/node_modules/process-warning/index.js +85 -17
  103. package/node_modules/baileys/node_modules/process-warning/package.json +6 -7
  104. package/node_modules/baileys/node_modules/process-warning/test/emit-once-only.test.js +3 -3
  105. package/node_modules/baileys/node_modules/process-warning/test/emit-reset.test.js +4 -4
  106. package/node_modules/baileys/node_modules/process-warning/test/emit-unlimited.test.js +2 -2
  107. package/node_modules/baileys/node_modules/process-warning/test/spy-warning.test.js +143 -0
  108. package/node_modules/baileys/node_modules/process-warning/types/index.d.ts +15 -1
  109. package/node_modules/baileys/node_modules/process-warning/types/index.tst.ts +48 -0
  110. package/node_modules/baileys/node_modules/protobufjs/README.md +61 -84
  111. package/node_modules/baileys/node_modules/protobufjs/dist/light/protobuf.js +66 -45
  112. package/node_modules/baileys/node_modules/protobufjs/dist/light/protobuf.js.map +1 -1
  113. package/node_modules/baileys/node_modules/protobufjs/dist/light/protobuf.min.js +3 -3
  114. package/node_modules/baileys/node_modules/protobufjs/dist/light/protobuf.min.js.map +1 -1
  115. package/node_modules/baileys/node_modules/protobufjs/dist/minimal/protobuf.js +47 -40
  116. package/node_modules/baileys/node_modules/protobufjs/dist/minimal/protobuf.js.map +1 -1
  117. package/node_modules/baileys/node_modules/protobufjs/dist/minimal/protobuf.min.js +3 -3
  118. package/node_modules/baileys/node_modules/protobufjs/dist/minimal/protobuf.min.js.map +1 -1
  119. package/node_modules/baileys/node_modules/protobufjs/dist/protobuf.js +92 -68
  120. package/node_modules/baileys/node_modules/protobufjs/dist/protobuf.js.map +1 -1
  121. package/node_modules/baileys/node_modules/protobufjs/dist/protobuf.min.js +3 -3
  122. package/node_modules/baileys/node_modules/protobufjs/dist/protobuf.min.js.map +1 -1
  123. package/node_modules/baileys/node_modules/protobufjs/ext/descriptor.js +26 -10
  124. package/node_modules/baileys/node_modules/protobufjs/index.d.ts +3 -0
  125. package/node_modules/baileys/node_modules/protobufjs/package.json +1 -1
  126. package/node_modules/baileys/node_modules/protobufjs/src/converter.js +5 -1
  127. package/node_modules/baileys/node_modules/protobufjs/src/enum.js +5 -2
  128. package/node_modules/baileys/node_modules/protobufjs/src/field.js +6 -1
  129. package/node_modules/baileys/node_modules/protobufjs/src/parse.js +26 -23
  130. package/node_modules/baileys/node_modules/protobufjs/src/reader.js +36 -9
  131. package/node_modules/baileys/node_modules/protobufjs/src/util/codegen.js +3 -1
  132. package/node_modules/baileys/node_modules/protobufjs/src/util/utf8.js +2 -28
  133. package/node_modules/baileys/node_modules/protobufjs/src/writer.js +7 -1
  134. package/node_modules/baileys/node_modules/ws/lib/permessage-deflate.js +3 -1
  135. package/node_modules/baileys/node_modules/ws/package.json +1 -1
  136. package/node_modules/baileys/package.json +1 -1
  137. package/node_modules/typebox/build/format/date.d.mts +1 -1
  138. package/node_modules/typebox/build/format/date.mjs +1 -1
  139. package/node_modules/typebox/build/format/date_time.d.mts +2 -2
  140. package/node_modules/typebox/build/format/date_time.mjs +3 -3
  141. package/node_modules/typebox/build/format/email.d.mts +1 -1
  142. package/node_modules/typebox/build/format/email.mjs +2 -2
  143. package/node_modules/typebox/build/format/hostname.mjs +2 -10
  144. package/node_modules/typebox/build/format/idn_email.d.mts +1 -1
  145. package/node_modules/typebox/build/format/idn_email.mjs +3 -3
  146. package/node_modules/typebox/build/format/idn_hostname.d.mts +1 -0
  147. package/node_modules/typebox/build/format/idn_hostname.mjs +3 -11
  148. package/node_modules/typebox/build/format/idna/format/bidi.d.mts +3 -0
  149. package/node_modules/typebox/build/format/idna/format/bidi.mjs +98 -0
  150. package/node_modules/typebox/build/format/idna/format/puny.d.mts +3 -0
  151. package/node_modules/typebox/build/format/idna/format/puny.mjs +144 -0
  152. package/node_modules/typebox/build/format/idna/hostname.d.mts +1 -0
  153. package/node_modules/typebox/build/format/idna/hostname.mjs +16 -0
  154. package/node_modules/typebox/build/format/idna/idn-hostname.d.mts +1 -0
  155. package/node_modules/typebox/build/format/idna/idn-hostname.mjs +41 -0
  156. package/node_modules/typebox/build/format/idna/index.d.mts +2 -0
  157. package/node_modules/typebox/build/format/idna/index.mjs +2 -0
  158. package/node_modules/typebox/build/format/idna/label/ascii.d.mts +1 -0
  159. package/node_modules/typebox/build/format/idna/label/ascii.mjs +9 -0
  160. package/node_modules/typebox/build/format/idna/label/puny.d.mts +1 -0
  161. package/node_modules/typebox/build/format/idna/label/puny.mjs +28 -0
  162. package/node_modules/typebox/build/format/idna/label/unicode.d.mts +1 -0
  163. package/node_modules/typebox/build/format/idna/label/unicode.mjs +106 -0
  164. package/node_modules/typebox/build/format/idna/pattern/pattern.d.mts +30 -0
  165. package/node_modules/typebox/build/format/idna/pattern/pattern.mjs +70 -0
  166. package/node_modules/typebox/build/format/ipv4.d.mts +0 -1
  167. package/node_modules/typebox/build/format/ipv4.mjs +2 -32
  168. package/node_modules/typebox/build/format/ipv6.mjs +2 -61
  169. package/node_modules/typebox/build/format/iri.d.mts +2 -2
  170. package/node_modules/typebox/build/format/iri.mjs +26 -8
  171. package/node_modules/typebox/build/format/iri_reference.d.mts +2 -2
  172. package/node_modules/typebox/build/format/iri_reference.mjs +9 -55
  173. package/node_modules/typebox/build/format/regex.d.mts +1 -2
  174. package/node_modules/typebox/build/format/regex.mjs +2 -6
  175. package/node_modules/typebox/build/format/time.d.mts +2 -2
  176. package/node_modules/typebox/build/format/time.mjs +19 -14
  177. package/node_modules/typebox/build/format/uri.d.mts +1 -1
  178. package/node_modules/typebox/build/format/uri.mjs +3 -130
  179. package/node_modules/typebox/build/format/uri_reference.d.mts +1 -1
  180. package/node_modules/typebox/build/format/uri_reference.mjs +2 -3
  181. package/node_modules/typebox/build/format/uri_template.d.mts +2 -3
  182. package/node_modules/typebox/build/format/uri_template.mjs +4 -5
  183. package/node_modules/typebox/build/format/url.d.mts +3 -3
  184. package/node_modules/typebox/build/format/url.mjs +4 -5
  185. package/node_modules/typebox/build/guard/emit.d.mts +3 -1
  186. package/node_modules/typebox/build/guard/emit.mjs +12 -5
  187. package/node_modules/typebox/build/guard/guard.d.mts +8 -2
  188. package/node_modules/typebox/build/guard/guard.mjs +25 -4
  189. package/node_modules/typebox/build/guard/string.d.mts +2 -2
  190. package/node_modules/typebox/build/guard/string.mjs +7 -7
  191. package/node_modules/typebox/build/schema/engine/_context.mjs +3 -3
  192. package/node_modules/typebox/build/schema/engine/_functions.mjs +1 -2
  193. package/node_modules/typebox/build/schema/engine/_regexp.d.mts +2 -0
  194. package/node_modules/typebox/build/schema/engine/_regexp.mjs +4 -0
  195. package/node_modules/typebox/build/schema/engine/_stack.mjs +12 -13
  196. package/node_modules/typebox/build/schema/engine/additionalItems.mjs +17 -7
  197. package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +4 -3
  198. package/node_modules/typebox/build/schema/engine/contains.mjs +18 -6
  199. package/node_modules/typebox/build/schema/engine/enum.mjs +1 -1
  200. package/node_modules/typebox/build/schema/engine/items.mjs +26 -6
  201. package/node_modules/typebox/build/schema/engine/maxContains.mjs +3 -3
  202. package/node_modules/typebox/build/schema/engine/minContains.mjs +14 -4
  203. package/node_modules/typebox/build/schema/engine/not.mjs +4 -2
  204. package/node_modules/typebox/build/schema/engine/oneOf.mjs +7 -6
  205. package/node_modules/typebox/build/schema/engine/pattern.mjs +3 -2
  206. package/node_modules/typebox/build/schema/engine/patternProperties.mjs +4 -3
  207. package/node_modules/typebox/build/schema/engine/ref.mjs +1 -7
  208. package/node_modules/typebox/build/schema/engine/schema.mjs +13 -4
  209. package/node_modules/typebox/build/schema/engine/type.mjs +1 -1
  210. package/node_modules/typebox/build/schema/resolve/resolve.d.mts +4 -1
  211. package/node_modules/typebox/build/schema/resolve/resolve.mjs +202 -1
  212. package/node_modules/typebox/build/schema/static/propertyNames.d.mts +5 -0
  213. package/node_modules/typebox/build/schema/static/propertyNames.mjs +3 -0
  214. package/node_modules/typebox/build/schema/static/schema.d.mts +3 -0
  215. package/node_modules/typebox/build/schema/types/index.d.mts +0 -2
  216. package/node_modules/typebox/build/schema/types/index.mjs +0 -2
  217. package/node_modules/typebox/build/system/memory/clone.mjs +14 -11
  218. package/node_modules/typebox/build/system/memory/discard.mjs +6 -5
  219. package/node_modules/typebox/build/system/settings/settings.d.mts +9 -0
  220. package/node_modules/typebox/build/system/settings/settings.mjs +2 -0
  221. package/node_modules/typebox/build/type/engine/call/distribute_arguments.d.mts +6 -1
  222. package/node_modules/typebox/build/type/engine/call/distribute_arguments.mjs +16 -3
  223. package/node_modules/typebox/build/type/engine/call/instantiate.mjs +34 -4
  224. package/node_modules/typebox/build/type/engine/evaluate/broaden.d.mts +5 -5
  225. package/node_modules/typebox/build/type/engine/evaluate/broaden.mjs +20 -26
  226. package/node_modules/typebox/build/type/engine/evaluate/compare.d.mts +6 -10
  227. package/node_modules/typebox/build/type/engine/evaluate/compare.mjs +9 -13
  228. package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +7 -4
  229. package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +12 -19
  230. package/node_modules/typebox/build/type/engine/evaluate/distribute.d.mts +4 -20
  231. package/node_modules/typebox/build/type/engine/evaluate/distribute.mjs +8 -20
  232. package/node_modules/typebox/build/type/engine/evaluate/evaluate.d.mts +4 -4
  233. package/node_modules/typebox/build/type/engine/evaluate/evaluate.mjs +11 -8
  234. package/node_modules/typebox/build/type/engine/evaluate/flatten.d.mts +1 -1
  235. package/node_modules/typebox/build/type/engine/evaluate/flatten.mjs +3 -4
  236. package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +17 -2
  237. package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +26 -6
  238. package/node_modules/typebox/build/type/engine/exclude/operation.mjs +3 -4
  239. package/node_modules/typebox/build/type/engine/extract/operation.d.mts +1 -1
  240. package/node_modules/typebox/build/type/engine/extract/operation.mjs +3 -4
  241. package/node_modules/typebox/build/type/engine/priority/priority.d.mts +2 -2
  242. package/node_modules/typebox/build/type/engine/priority/priority.mjs +3 -4
  243. package/node_modules/typebox/build/type/script/mapping.d.mts +32 -29
  244. package/node_modules/typebox/build/type/script/mapping.mjs +18 -25
  245. package/node_modules/typebox/build/type/script/parser.d.mts +19 -25
  246. package/node_modules/typebox/build/type/script/parser.mjs +27 -23
  247. package/node_modules/typebox/build/value/errors/errors.d.mts +2 -2
  248. package/node_modules/typebox/build/value/errors/errors.mjs +1 -1
  249. package/node_modules/typebox/package.json +27 -27
  250. package/node_modules/typebox/readme.md +79 -82
  251. package/openclaw.plugin.json +2 -1
  252. package/package.json +6 -6
  253. package/node_modules/baileys/node_modules/process-warning/types/index.test-d.ts +0 -36
  254. package/node_modules/typebox/build/format/_idna.d.mts +0 -2
  255. package/node_modules/typebox/build/format/_idna.mjs +0 -246
  256. package/node_modules/typebox/build/format/_puny.d.mts +0 -1
  257. package/node_modules/typebox/build/format/_puny.mjs +0 -77
  258. package/node_modules/typebox/build/schema/resolve/ref.d.mts +0 -3
  259. package/node_modules/typebox/build/schema/resolve/ref.mjs +0 -146
  260. package/node_modules/typebox/build/schema/types/contentEncoding.d.mts +0 -9
  261. package/node_modules/typebox/build/schema/types/contentEncoding.mjs +0 -13
  262. package/node_modules/typebox/build/schema/types/contentMediaType.d.mts +0 -9
  263. package/node_modules/typebox/build/schema/types/contentMediaType.mjs +0 -13
@@ -1 +1,202 @@
1
- export * from './ref.mjs';
1
+ // deno-fmt-ignore-file
2
+ import { Guard } from '../../guard/index.mjs';
3
+ import { Pointer } from '../pointer/index.mjs';
4
+ import * as Schema from '../types/index.mjs';
5
+ // ------------------------------------------------------------------
6
+ // DefaultBase
7
+ // ------------------------------------------------------------------
8
+ export const DefaultBase = new URL('https://json-schema.org');
9
+ // ------------------------------------------------------------------
10
+ // Match: Id
11
+ // ------------------------------------------------------------------
12
+ function MatchId(schema, base, ref) {
13
+ if (schema.$id === ref.hash)
14
+ return schema;
15
+ const absoluteId = new URL(schema.$id, base.href);
16
+ const absoluteRef = new URL(ref.href, base.href);
17
+ if (Guard.IsEqual(absoluteId.pathname, absoluteRef.pathname)) {
18
+ return ref.hash.startsWith('#') ? MatchHash(schema, base, ref) : schema;
19
+ }
20
+ return undefined;
21
+ }
22
+ // ------------------------------------------------------------------
23
+ // Match: Anchor
24
+ // ------------------------------------------------------------------
25
+ function MatchAnchor(schema, base, ref) {
26
+ const absoluteAnchor = new URL(`#${schema.$anchor}`, base.href);
27
+ const absoluteRef = new URL(ref.href, base.href);
28
+ return Guard.IsEqual(absoluteAnchor.href, absoluteRef.href) ? schema : undefined;
29
+ }
30
+ // ------------------------------------------------------------------
31
+ // Match: DynamicAnchor
32
+ // ------------------------------------------------------------------
33
+ function MatchDynamicAnchor(schema, base, ref) {
34
+ const absoluteAnchor = new URL(`#${schema.$dynamicAnchor}`, base.href);
35
+ const absoluteRef = new URL(ref.href, base.href);
36
+ return Guard.IsEqual(absoluteAnchor.href, absoluteRef.href) ? schema : undefined;
37
+ }
38
+ // ------------------------------------------------------------------
39
+ // Match: Hash
40
+ //
41
+ // Resolves JSON Pointer fragments only. Plain anchor-style fragments
42
+ // (no leading '/') are handled exclusively by MatchAnchor and
43
+ // MatchDynamicAnchor to prevent accidentally resolving an anchor name
44
+ // as a pointer into the schema tree.
45
+ //
46
+ // ------------------------------------------------------------------
47
+ function MatchHash(schema, _base, ref) {
48
+ if (ref.href.endsWith('#'))
49
+ return schema;
50
+ if (!ref.hash.startsWith('#'))
51
+ return undefined;
52
+ const fragment = decodeURIComponent(ref.hash.slice(1));
53
+ if (!fragment.startsWith('/'))
54
+ return undefined;
55
+ return Pointer.Get(schema, fragment);
56
+ }
57
+ // ------------------------------------------------------------------
58
+ // Match
59
+ // ------------------------------------------------------------------
60
+ function Match(schema, base, ref) {
61
+ if (Schema.IsId(schema)) {
62
+ const result = MatchId(schema, base, ref);
63
+ if (!Guard.IsUndefined(result))
64
+ return result;
65
+ }
66
+ if (Schema.IsAnchor(schema)) {
67
+ const result = MatchAnchor(schema, base, ref);
68
+ if (!Guard.IsUndefined(result))
69
+ return result;
70
+ }
71
+ if (Schema.IsDynamicAnchor(schema)) {
72
+ const result = MatchDynamicAnchor(schema, base, ref);
73
+ if (!Guard.IsUndefined(result))
74
+ return result;
75
+ }
76
+ return MatchHash(schema, base, ref);
77
+ }
78
+ // ------------------------------------------------------------------
79
+ // FromArray
80
+ // ------------------------------------------------------------------
81
+ function FromArray(schema, base, ref) {
82
+ return schema.reduce((result, item) => {
83
+ const match = FromValue(item, base, ref);
84
+ return !Guard.IsUndefined(match) ? match : result;
85
+ }, undefined);
86
+ }
87
+ // ------------------------------------------------------------------
88
+ // FromObject
89
+ // ------------------------------------------------------------------
90
+ function SkipProperty(key) {
91
+ // these are explicit data encoded in a schema, they should not
92
+ // be considered valid targets used for de-referencing.
93
+ return Guard.IsEqual(key, 'const') || Guard.IsEqual(key, 'enum');
94
+ }
95
+ function FromObject(schema, base, ref) {
96
+ return Guard.Keys(schema).reduce((result, key) => {
97
+ if (SkipProperty(key))
98
+ return result;
99
+ const match = FromValue(schema[key], base, ref);
100
+ return !Guard.IsUndefined(match) ? match : result;
101
+ }, undefined);
102
+ }
103
+ // ------------------------------------------------------------------
104
+ // FromValue
105
+ // ------------------------------------------------------------------
106
+ function FromValue(schema, base, ref) {
107
+ const nextBase = Schema.IsSchemaObject(schema) && Schema.IsId(schema)
108
+ ? new URL(schema.$id, base.href)
109
+ : base;
110
+ if (Schema.IsSchemaObject(schema)) {
111
+ const result = Match(schema, nextBase, ref);
112
+ if (!Guard.IsUndefined(result))
113
+ return result;
114
+ }
115
+ if (Guard.IsArray(schema))
116
+ return FromArray(schema, nextBase, ref);
117
+ if (Guard.IsObject(schema))
118
+ return FromObject(schema, nextBase, ref);
119
+ return undefined;
120
+ }
121
+ // ------------------------------------------------------------------
122
+ // CanonicalHref
123
+ //
124
+ // Returns the URL's href with its fragment removed, as a string.
125
+ // This is the canonical URI a document is identified and keyed by
126
+ // in context.
127
+ // ------------------------------------------------------------------
128
+ function CanonicalHref(url) {
129
+ return url.href.split('#')[0];
130
+ }
131
+ // ------------------------------------------------------------------
132
+ // RefContext: Phase 1
133
+ //
134
+ // A ContextRef targets a simple key name in the context and is
135
+ // used for fast resolution of inline referential TypeBox types.
136
+ // ------------------------------------------------------------------
137
+ function RefContext(context, ref) {
138
+ return Guard.HasPropertyKey(context, ref) ? context[ref] : undefined;
139
+ }
140
+ // ------------------------------------------------------------------
141
+ // RefLocal: Phase 2
142
+ //
143
+ // Resolves the ref's fragment within the current schema resource,
144
+ // either as a JSON Pointer or a plain-name fragment ($anchor,
145
+ // $dynamicAnchor), per the JSON Schema spec.
146
+ // ------------------------------------------------------------------
147
+ function RefLocal(schema, base, ref) {
148
+ return FromValue(schema, base, ref);
149
+ }
150
+ // ------------------------------------------------------------------
151
+ // RefRemote: Phase 3
152
+ //
153
+ // Locates the schema resource identified by the ref's base URI, then
154
+ // resolves the ref's fragment within that resource, either as a JSON
155
+ // Pointer or a plain-name fragment, per the JSON Schema spec.
156
+ // ------------------------------------------------------------------
157
+ function RefRemote(context, base, ref) {
158
+ const targetDocumentHref = CanonicalHref(ref);
159
+ if (Guard.IsEqual(targetDocumentHref, CanonicalHref(base)))
160
+ return undefined;
161
+ if (!Guard.HasPropertyKey(context, targetDocumentHref))
162
+ return undefined;
163
+ const remoteSchema = context[targetDocumentHref];
164
+ const remoteBase = (Schema.IsSchemaObject(remoteSchema) && Schema.IsId(remoteSchema)) ? new URL(remoteSchema.$id, DefaultBase.href) : new URL(targetDocumentHref);
165
+ return FromValue(remoteSchema, remoteBase, ref);
166
+ }
167
+ // ------------------------------------------------------------------
168
+ // Ref
169
+ // ------------------------------------------------------------------
170
+ export function Ref(context, schema, ref) {
171
+ const initialBase = Schema.IsId(schema) ? new URL(schema.$id, DefaultBase.href) : DefaultBase;
172
+ const initialRef = new URL(ref, initialBase.href);
173
+ return RefContext(context, ref) ?? RefLocal(schema, initialBase, initialRef) ?? RefRemote(context, initialBase, initialRef);
174
+ }
175
+ // ------------------------------------------------------------------
176
+ // DynamicRef
177
+ // ------------------------------------------------------------------
178
+ export function DynamicRef(context, root, base, dynamicRef, dynamicAnchors) {
179
+ // Resolve the static target using either the local base (for fragment‑only references)
180
+ // or the document root (for absolute URI references).
181
+ const fragmentTarget = dynamicRef.$dynamicRef.startsWith('#')
182
+ ? Ref(context, base, dynamicRef.$dynamicRef)
183
+ : Ref(context, root, dynamicRef.$dynamicRef);
184
+ if (Guard.IsUndefined(fragmentTarget))
185
+ return undefined;
186
+ // Dynamic override only applies if the resolved target itself declares a $dynamicAnchor.
187
+ // If it does not, return the static target unchanged.
188
+ if (!Schema.IsSchemaObject(fragmentTarget) || !Schema.IsDynamicAnchor(fragmentTarget))
189
+ return fragmentTarget;
190
+ // Extract the fragment portion of the reference. According to the test suite,
191
+ // only plain fragment names (e.g., "#foo") trigger the dynamic scope; JSON
192
+ // Pointer fragments (e.g., "#/definitions/foo") bypass dynamic resolution.
193
+ const fragment = new URL(dynamicRef.$dynamicRef, DefaultBase).hash;
194
+ if (fragment.startsWith('#/'))
195
+ return fragmentTarget;
196
+ // Search the live dynamic anchor stack for a schema whose $dynamicAnchor matches the
197
+ // target's $dynamicAnchor. The stack reflects the current evaluation path, and
198
+ // find() returns the outermost (first encountered) match, which is the correct
199
+ // lexical scope per the specification.
200
+ const anchorTarget = dynamicAnchors.find(anchor => anchor.$dynamicAnchor === fragmentTarget.$dynamicAnchor);
201
+ return anchorTarget ?? fragmentTarget;
202
+ }
@@ -0,0 +1,5 @@
1
+ import type { XSchema } from '../types/schema.mjs';
2
+ import type { XStaticSchema } from './schema.mjs';
3
+ export type XStaticPropertyNames<Stack extends string[], Root extends XSchema, Schema extends XSchema, StaticKey extends unknown = XStaticSchema<Stack, Root, Schema>, Result extends Record<string, unknown> = [StaticKey] extends [PropertyKey] ? {
4
+ [Key in StaticKey]?: unknown;
5
+ } : {}> = Result;
@@ -0,0 +1,3 @@
1
+ // deno-lint-ignore-file ban-types
2
+ // deno-fmt-ignore-file
3
+ export {};
@@ -9,6 +9,7 @@ import type { XOneOf } from '../types/oneOf.mjs';
9
9
  import type { XPatternProperties } from '../types/patternProperties.mjs';
10
10
  import type { XPrefixItems } from '../types/prefixItems.mjs';
11
11
  import type { XProperties } from '../types/properties.mjs';
12
+ import type { XPropertyNames } from '../types/propertyNames.mjs';
12
13
  import type { XRef } from '../types/ref.mjs';
13
14
  import type { XRequired } from '../types/required.mjs';
14
15
  import type { XSchema } from '../types/schema.mjs';
@@ -25,6 +26,7 @@ import type { XStaticOneOf } from './oneOf.mjs';
25
26
  import type { XStaticPatternProperties } from './patternProperties.mjs';
26
27
  import type { XStaticPrefixItems } from './prefixItems.mjs';
27
28
  import type { XStaticProperties } from './properties.mjs';
29
+ import type { XStaticPropertyNames } from './propertyNames.mjs';
28
30
  import type { XStaticRef } from './ref.mjs';
29
31
  import type { XStaticRequired } from './required.mjs';
30
32
  import type { XStaticType } from './type.mjs';
@@ -41,6 +43,7 @@ type XFromKeywords<Stack extends string[], Root extends XSchema, Schema extends
41
43
  Schema extends XPatternProperties<infer Properties extends Record<PropertyKey, XSchema>> ? XStaticPatternProperties<Stack, Root, Properties> : unknown,
42
44
  Schema extends XPrefixItems<infer Types extends XSchema[]> ? XStaticPrefixItems<Stack, Root, Schema, Types> : unknown,
43
45
  Schema extends XProperties<infer Properties extends Record<PropertyKey, XSchema>> ? XStaticProperties<Stack, Root, Schema, Properties> : unknown,
46
+ Schema extends XPropertyNames<infer Type extends XSchema> ? XStaticPropertyNames<Stack, Root, Type> : unknown,
44
47
  Schema extends XRef<infer Ref extends string> ? XStaticRef<Stack, Root, Ref> : unknown,
45
48
  Schema extends XRequired<infer Keys extends string[]> ? XStaticRequired<Stack, Root, Schema, Keys> : unknown,
46
49
  Schema extends XType<infer TypeName extends string[] | string> ? XStaticType<TypeName> : unknown,
@@ -6,8 +6,6 @@ export * from './anchor.mjs';
6
6
  export * from './anyOf.mjs';
7
7
  export * from './const.mjs';
8
8
  export * from './contains.mjs';
9
- export * from './contentEncoding.mjs';
10
- export * from './contentMediaType.mjs';
11
9
  export * from './default.mjs';
12
10
  export * from './defs.mjs';
13
11
  export * from './dependencies.mjs';
@@ -12,8 +12,6 @@ export * from './anchor.mjs';
12
12
  export * from './anyOf.mjs';
13
13
  export * from './const.mjs';
14
14
  export * from './contains.mjs';
15
- export * from './contentEncoding.mjs';
16
- export * from './contentMediaType.mjs';
17
15
  export * from './default.mjs';
18
16
  export * from './defs.mjs';
19
17
  export * from './dependencies.mjs';
@@ -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
  }