@jsprismarine/script-host 0.0.0 → 0.23.0-unstable-20261120210452

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 (440) hide show
  1. package/CHANGELOG.md +99 -0
  2. package/LICENSE +21 -0
  3. package/README.md +667 -28
  4. package/dist/ScriptEngine.d.ts +250 -0
  5. package/dist/ScriptEngine.d.ts.map +1 -0
  6. package/dist/ScriptEngine.js +427 -0
  7. package/dist/ScriptEngine.js.map +1 -0
  8. package/dist/absentGlobals.d.ts +29 -0
  9. package/dist/absentGlobals.d.ts.map +1 -0
  10. package/dist/absentGlobals.js +94 -0
  11. package/dist/absentGlobals.js.map +1 -0
  12. package/dist/debugger/DebugSession.d.ts +189 -0
  13. package/dist/debugger/DebugSession.d.ts.map +1 -0
  14. package/dist/debugger/DebugSession.js +588 -0
  15. package/dist/debugger/DebugSession.js.map +1 -0
  16. package/dist/debugger/EngineDebugger.d.ts +158 -0
  17. package/dist/debugger/EngineDebugger.d.ts.map +1 -0
  18. package/dist/debugger/EngineDebugger.js +174 -0
  19. package/dist/debugger/EngineDebugger.js.map +1 -0
  20. package/dist/debugger/channel.d.ts +67 -0
  21. package/dist/debugger/channel.d.ts.map +1 -0
  22. package/dist/debugger/channel.js +120 -0
  23. package/dist/debugger/channel.js.map +1 -0
  24. package/dist/debugger/connectionWorker.d.ts +2 -0
  25. package/dist/debugger/connectionWorker.d.ts.map +1 -0
  26. package/dist/debugger/connectionWorker.js +98 -0
  27. package/dist/debugger/connectionWorker.js.map +1 -0
  28. package/dist/debugger/framing.d.ts +46 -0
  29. package/dist/debugger/framing.d.ts.map +1 -0
  30. package/dist/debugger/framing.js +106 -0
  31. package/dist/debugger/framing.js.map +1 -0
  32. package/dist/debugger/profiler.d.ts +72 -0
  33. package/dist/debugger/profiler.d.ts.map +1 -0
  34. package/dist/debugger/profiler.js +92 -0
  35. package/dist/debugger/profiler.js.map +1 -0
  36. package/dist/debugger/protocol.d.ts +170 -0
  37. package/dist/debugger/protocol.d.ts.map +1 -0
  38. package/dist/debugger/protocol.js +141 -0
  39. package/dist/debugger/protocol.js.map +1 -0
  40. package/dist/debugger/thread.d.ts +85 -0
  41. package/dist/debugger/thread.d.ts.map +1 -0
  42. package/dist/debugger/thread.js +134 -0
  43. package/dist/debugger/thread.js.map +1 -0
  44. package/dist/debugger/transport.d.ts +80 -0
  45. package/dist/debugger/transport.d.ts.map +1 -0
  46. package/dist/debugger/transport.js +150 -0
  47. package/dist/debugger/transport.js.map +1 -0
  48. package/dist/engineSource.d.ts +14 -0
  49. package/dist/engineSource.d.ts.map +1 -0
  50. package/dist/engineSource.js +17 -0
  51. package/dist/engineSource.js.map +1 -0
  52. package/dist/errors.d.ts +62 -0
  53. package/dist/errors.d.ts.map +1 -0
  54. package/dist/errors.js +62 -0
  55. package/dist/errors.js.map +1 -0
  56. package/dist/ffi.d.ts +63 -0
  57. package/dist/ffi.d.ts.map +1 -0
  58. package/dist/ffi.js +156 -0
  59. package/dist/ffi.js.map +1 -0
  60. package/dist/generated/script-modules/common.d.ts +2 -0
  61. package/dist/generated/script-modules/common.js +262 -0
  62. package/dist/generated/script-modules/common.js.map +1 -0
  63. package/dist/generated/script-modules/common.json.d.ts +2 -0
  64. package/dist/generated/script-modules/debug-utilities.d.ts +2 -0
  65. package/dist/generated/script-modules/debug-utilities.js +23 -0
  66. package/dist/generated/script-modules/debug-utilities.js.map +1 -0
  67. package/dist/generated/script-modules/debug-utilities.json.d.ts +2 -0
  68. package/dist/generated/script-modules/diagnostics.d.ts +2 -0
  69. package/dist/generated/script-modules/diagnostics.js +281 -0
  70. package/dist/generated/script-modules/diagnostics.js.map +1 -0
  71. package/dist/generated/script-modules/diagnostics.json.d.ts +2 -0
  72. package/dist/generated/script-modules/server-admin.d.ts +2 -0
  73. package/dist/generated/script-modules/server-admin.js +23 -0
  74. package/dist/generated/script-modules/server-admin.js.map +1 -0
  75. package/dist/generated/script-modules/server-admin.json.d.ts +2 -0
  76. package/dist/generated/script-modules/server-gametest.d.ts +2 -0
  77. package/dist/generated/script-modules/server-gametest.js +23 -0
  78. package/dist/generated/script-modules/server-gametest.js.map +1 -0
  79. package/dist/generated/script-modules/server-gametest.json.d.ts +2 -0
  80. package/dist/generated/script-modules/server-graphics.d.ts +2 -0
  81. package/dist/generated/script-modules/server-graphics.js +30 -0
  82. package/dist/generated/script-modules/server-graphics.js.map +1 -0
  83. package/dist/generated/script-modules/server-graphics.json.d.ts +2 -0
  84. package/dist/generated/script-modules/server-net.d.ts +2 -0
  85. package/dist/generated/script-modules/server-net.js +24 -0
  86. package/dist/generated/script-modules/server-net.js.map +1 -0
  87. package/dist/generated/script-modules/server-net.json.d.ts +2 -0
  88. package/dist/generated/script-modules/server-ui.d.ts +2 -0
  89. package/dist/generated/script-modules/server-ui.js +110 -0
  90. package/dist/generated/script-modules/server-ui.js.map +1 -0
  91. package/dist/generated/script-modules/server-ui.json.d.ts +2 -0
  92. package/dist/generated/script-modules/server.d.ts +2 -0
  93. package/dist/generated/script-modules/server.js +251 -0
  94. package/dist/generated/script-modules/server.js.map +1 -0
  95. package/dist/generated/script-modules/server.json.d.ts +2 -0
  96. package/dist/generated/scriptApi.d.ts +3233 -0
  97. package/dist/generated/scriptApi.d.ts.map +1 -0
  98. package/dist/generated/scriptApi.js +0 -0
  99. package/dist/generated/scriptModules.d.ts +13 -0
  100. package/dist/generated/scriptModules.d.ts.map +1 -0
  101. package/dist/generated/scriptModules.js +34 -0
  102. package/dist/generated/scriptModules.js.map +1 -0
  103. package/dist/host/PackForms.d.ts +71 -0
  104. package/dist/host/PackForms.d.ts.map +1 -0
  105. package/dist/host/PackForms.js +164 -0
  106. package/dist/host/PackForms.js.map +1 -0
  107. package/dist/host/ScriptForms.d.ts +51 -0
  108. package/dist/host/ScriptForms.d.ts.map +1 -0
  109. package/dist/host/ScriptForms.js +103 -0
  110. package/dist/host/ScriptForms.js.map +1 -0
  111. package/dist/host/ScriptHttp.d.ts +54 -0
  112. package/dist/host/ScriptHttp.d.ts.map +1 -0
  113. package/dist/host/ScriptHttp.js +82 -0
  114. package/dist/host/ScriptHttp.js.map +1 -0
  115. package/dist/host/WorldScripts.d.ts +350 -0
  116. package/dist/host/WorldScripts.d.ts.map +1 -0
  117. package/dist/host/WorldScripts.js +1421 -0
  118. package/dist/host/WorldScripts.js.map +1 -0
  119. package/dist/host/blocksItems/blockComponents.d.ts +27 -0
  120. package/dist/host/blocksItems/blockComponents.d.ts.map +1 -0
  121. package/dist/host/blocksItems/blockComponents.js +73 -0
  122. package/dist/host/blocksItems/blockComponents.js.map +1 -0
  123. package/dist/host/blocksItems/blocks.d.ts +12 -0
  124. package/dist/host/blocksItems/blocks.d.ts.map +1 -0
  125. package/dist/host/blocksItems/blocks.js +247 -0
  126. package/dist/host/blocksItems/blocks.js.map +1 -0
  127. package/dist/host/blocksItems/componentFacts.d.ts +14 -0
  128. package/dist/host/blocksItems/componentFacts.d.ts.map +1 -0
  129. package/dist/host/blocksItems/componentFacts.js +34 -0
  130. package/dist/host/blocksItems/componentFacts.js.map +1 -0
  131. package/dist/host/blocksItems/containers.d.ts +18 -0
  132. package/dist/host/blocksItems/containers.d.ts.map +1 -0
  133. package/dist/host/blocksItems/containers.js +128 -0
  134. package/dist/host/blocksItems/containers.js.map +1 -0
  135. package/dist/host/blocksItems/handles.d.ts +10 -0
  136. package/dist/host/blocksItems/handles.d.ts.map +1 -0
  137. package/dist/host/blocksItems/handles.js +30 -0
  138. package/dist/host/blocksItems/handles.js.map +1 -0
  139. package/dist/host/blocksItems/implement.d.ts +22 -0
  140. package/dist/host/blocksItems/implement.d.ts.map +1 -0
  141. package/dist/host/blocksItems/implement.js +23 -0
  142. package/dist/host/blocksItems/implement.js.map +1 -0
  143. package/dist/host/blocksItems/itemExtras.d.ts +8 -0
  144. package/dist/host/blocksItems/itemExtras.d.ts.map +1 -0
  145. package/dist/host/blocksItems/itemExtras.js +106 -0
  146. package/dist/host/blocksItems/itemExtras.js.map +1 -0
  147. package/dist/host/blocksItems/itemLink.d.ts +12 -0
  148. package/dist/host/blocksItems/itemLink.d.ts.map +1 -0
  149. package/dist/host/blocksItems/itemLink.js +38 -0
  150. package/dist/host/blocksItems/itemLink.js.map +1 -0
  151. package/dist/host/blocksItems/items.d.ts +25 -0
  152. package/dist/host/blocksItems/items.d.ts.map +1 -0
  153. package/dist/host/blocksItems/items.js +427 -0
  154. package/dist/host/blocksItems/items.js.map +1 -0
  155. package/dist/host/blocksItems/tags.d.ts +24 -0
  156. package/dist/host/blocksItems/tags.d.ts.map +1 -0
  157. package/dist/host/blocksItems/tags.js +27 -0
  158. package/dist/host/blocksItems/tags.js.map +1 -0
  159. package/dist/host/blocksItems/types.d.ts +13 -0
  160. package/dist/host/blocksItems/types.d.ts.map +1 -0
  161. package/dist/host/blocksItems/types.js +83 -0
  162. package/dist/host/blocksItems/types.js.map +1 -0
  163. package/dist/host/blocksItems/volumes.d.ts +37 -0
  164. package/dist/host/blocksItems/volumes.d.ts.map +1 -0
  165. package/dist/host/blocksItems/volumes.js +361 -0
  166. package/dist/host/blocksItems/volumes.js.map +1 -0
  167. package/dist/host/coverage.d.ts +28 -0
  168. package/dist/host/coverage.d.ts.map +1 -0
  169. package/dist/host/coverage.js +45 -0
  170. package/dist/host/coverage.js.map +1 -0
  171. package/dist/host/customContent.d.ts +81 -0
  172. package/dist/host/customContent.d.ts.map +1 -0
  173. package/dist/host/customContent.js +213 -0
  174. package/dist/host/customContent.js.map +1 -0
  175. package/dist/host/debugUtilities.d.ts +192 -0
  176. package/dist/host/debugUtilities.d.ts.map +1 -0
  177. package/dist/host/debugUtilities.js +503 -0
  178. package/dist/host/debugUtilities.js.map +1 -0
  179. package/dist/host/entities/aimAssist.d.ts +11 -0
  180. package/dist/host/entities/aimAssist.d.ts.map +1 -0
  181. package/dist/host/entities/aimAssist.js +195 -0
  182. package/dist/host/entities/aimAssist.js.map +1 -0
  183. package/dist/host/entities/area.d.ts +14 -0
  184. package/dist/host/entities/area.d.ts.map +1 -0
  185. package/dist/host/entities/area.js +19 -0
  186. package/dist/host/entities/area.js.map +1 -0
  187. package/dist/host/entities/components.d.ts +61 -0
  188. package/dist/host/entities/components.d.ts.map +1 -0
  189. package/dist/host/entities/components.js +642 -0
  190. package/dist/host/entities/components.js.map +1 -0
  191. package/dist/host/entities/entityMembers.d.ts +35 -0
  192. package/dist/host/entities/entityMembers.d.ts.map +1 -0
  193. package/dist/host/entities/entityMembers.js +494 -0
  194. package/dist/host/entities/entityMembers.js.map +1 -0
  195. package/dist/host/entities/playerMembers.d.ts +23 -0
  196. package/dist/host/entities/playerMembers.d.ts.map +1 -0
  197. package/dist/host/entities/playerMembers.js +576 -0
  198. package/dist/host/entities/playerMembers.js.map +1 -0
  199. package/dist/host/entities/world.d.ts +315 -0
  200. package/dist/host/entities/world.d.ts.map +1 -0
  201. package/dist/host/entities/world.js +0 -0
  202. package/dist/host/events/componentEvents.d.ts +11 -0
  203. package/dist/host/events/componentEvents.d.ts.map +1 -0
  204. package/dist/host/events/componentEvents.js +23 -0
  205. package/dist/host/events/componentEvents.js.map +1 -0
  206. package/dist/host/events/eventOptions.d.ts +14 -0
  207. package/dist/host/events/eventOptions.d.ts.map +1 -0
  208. package/dist/host/events/eventOptions.js +224 -0
  209. package/dist/host/events/eventOptions.js.map +1 -0
  210. package/dist/host/events/eventValues.d.ts +41 -0
  211. package/dist/host/events/eventValues.d.ts.map +1 -0
  212. package/dist/host/events/eventValues.js +89 -0
  213. package/dist/host/events/eventValues.js.map +1 -0
  214. package/dist/host/events/worldEvents.d.ts +30 -0
  215. package/dist/host/events/worldEvents.d.ts.map +1 -0
  216. package/dist/host/events/worldEvents.js +207 -0
  217. package/dist/host/events/worldEvents.js.map +1 -0
  218. package/dist/host/formJson.d.ts +35 -0
  219. package/dist/host/formJson.d.ts.map +1 -0
  220. package/dist/host/formJson.js +84 -0
  221. package/dist/host/formJson.js.map +1 -0
  222. package/dist/host/formKit.d.ts +40 -0
  223. package/dist/host/formKit.d.ts.map +1 -0
  224. package/dist/host/formKit.js +124 -0
  225. package/dist/host/formKit.js.map +1 -0
  226. package/dist/host/forms.d.ts +92 -0
  227. package/dist/host/forms.d.ts.map +1 -0
  228. package/dist/host/forms.js +361 -0
  229. package/dist/host/forms.js.map +1 -0
  230. package/dist/host/gametest.d.ts +202 -0
  231. package/dist/host/gametest.d.ts.map +1 -0
  232. package/dist/host/gametest.js +316 -0
  233. package/dist/host/gametest.js.map +1 -0
  234. package/dist/host/inputs.d.ts +29 -0
  235. package/dist/host/inputs.d.ts.map +1 -0
  236. package/dist/host/inputs.js +110 -0
  237. package/dist/host/inputs.js.map +1 -0
  238. package/dist/host/jobs.d.ts +48 -0
  239. package/dist/host/jobs.d.ts.map +1 -0
  240. package/dist/host/jobs.js +62 -0
  241. package/dist/host/jobs.js.map +1 -0
  242. package/dist/host/jsprismarineServer.d.ts +65 -0
  243. package/dist/host/jsprismarineServer.d.ts.map +1 -0
  244. package/dist/host/jsprismarineServer.js +83 -0
  245. package/dist/host/jsprismarineServer.js.map +1 -0
  246. package/dist/host/minecraftServer.d.ts +229 -0
  247. package/dist/host/minecraftServer.d.ts.map +1 -0
  248. package/dist/host/minecraftServer.js +304 -0
  249. package/dist/host/minecraftServer.js.map +1 -0
  250. package/dist/host/minecraftServerUi.d.ts +30 -0
  251. package/dist/host/minecraftServerUi.d.ts.map +1 -0
  252. package/dist/host/minecraftServerUi.js +89 -0
  253. package/dist/host/minecraftServerUi.js.map +1 -0
  254. package/dist/host/netKit.d.ts +44 -0
  255. package/dist/host/netKit.d.ts.map +1 -0
  256. package/dist/host/netKit.js +87 -0
  257. package/dist/host/netKit.js.map +1 -0
  258. package/dist/host/pack.d.ts +71 -0
  259. package/dist/host/pack.d.ts.map +1 -0
  260. package/dist/host/pack.js +157 -0
  261. package/dist/host/pack.js.map +1 -0
  262. package/dist/host/serverAdmin.d.ts +44 -0
  263. package/dist/host/serverAdmin.d.ts.map +1 -0
  264. package/dist/host/serverAdmin.js +96 -0
  265. package/dist/host/serverAdmin.js.map +1 -0
  266. package/dist/host/serverBlocks.d.ts +32 -0
  267. package/dist/host/serverBlocks.d.ts.map +1 -0
  268. package/dist/host/serverBlocks.js +93 -0
  269. package/dist/host/serverBlocks.js.map +1 -0
  270. package/dist/host/serverComponents.d.ts +46 -0
  271. package/dist/host/serverComponents.d.ts.map +1 -0
  272. package/dist/host/serverComponents.js +297 -0
  273. package/dist/host/serverComponents.js.map +1 -0
  274. package/dist/host/serverCustom.d.ts +16 -0
  275. package/dist/host/serverCustom.d.ts.map +1 -0
  276. package/dist/host/serverCustom.js +161 -0
  277. package/dist/host/serverCustom.js.map +1 -0
  278. package/dist/host/serverEntities.d.ts +49 -0
  279. package/dist/host/serverEntities.d.ts.map +1 -0
  280. package/dist/host/serverEntities.js +358 -0
  281. package/dist/host/serverEntities.js.map +1 -0
  282. package/dist/host/serverFeedback.d.ts +15 -0
  283. package/dist/host/serverFeedback.d.ts.map +1 -0
  284. package/dist/host/serverFeedback.js +413 -0
  285. package/dist/host/serverFeedback.js.map +1 -0
  286. package/dist/host/serverGametest.d.ts +43 -0
  287. package/dist/host/serverGametest.d.ts.map +1 -0
  288. package/dist/host/serverGametest.js +246 -0
  289. package/dist/host/serverGametest.js.map +1 -0
  290. package/dist/host/serverItems.d.ts +17 -0
  291. package/dist/host/serverItems.d.ts.map +1 -0
  292. package/dist/host/serverItems.js +71 -0
  293. package/dist/host/serverItems.js.map +1 -0
  294. package/dist/host/serverNet.d.ts +41 -0
  295. package/dist/host/serverNet.d.ts.map +1 -0
  296. package/dist/host/serverNet.js +289 -0
  297. package/dist/host/serverNet.js.map +1 -0
  298. package/dist/host/serverObjects.d.ts +142 -0
  299. package/dist/host/serverObjects.d.ts.map +1 -0
  300. package/dist/host/serverObjects.js +326 -0
  301. package/dist/host/serverObjects.js.map +1 -0
  302. package/dist/host/serverProperties.d.ts +48 -0
  303. package/dist/host/serverProperties.d.ts.map +1 -0
  304. package/dist/host/serverProperties.js +193 -0
  305. package/dist/host/serverProperties.js.map +1 -0
  306. package/dist/host/serverScoreboard.d.ts +9 -0
  307. package/dist/host/serverScoreboard.d.ts.map +1 -0
  308. package/dist/host/serverScoreboard.js +198 -0
  309. package/dist/host/serverScoreboard.js.map +1 -0
  310. package/dist/host/serverStructures.d.ts +9 -0
  311. package/dist/host/serverStructures.d.ts.map +1 -0
  312. package/dist/host/serverStructures.js +243 -0
  313. package/dist/host/serverStructures.js.map +1 -0
  314. package/dist/host/tasks.d.ts +66 -0
  315. package/dist/host/tasks.d.ts.map +1 -0
  316. package/dist/host/tasks.js +107 -0
  317. package/dist/host/tasks.js.map +1 -0
  318. package/dist/host/world.d.ts +1359 -0
  319. package/dist/host/world.d.ts.map +1 -0
  320. package/dist/host/world.js +10 -0
  321. package/dist/host/world.js.map +1 -0
  322. package/dist/host/worldsystem/gameRules.d.ts +189 -0
  323. package/dist/host/worldsystem/gameRules.d.ts.map +1 -0
  324. package/dist/host/worldsystem/gameRules.js +86 -0
  325. package/dist/host/worldsystem/gameRules.js.map +1 -0
  326. package/dist/host/worldsystem/memoryWorldSystem.d.ts +18 -0
  327. package/dist/host/worldsystem/memoryWorldSystem.d.ts.map +1 -0
  328. package/dist/host/worldsystem/memoryWorldSystem.js +223 -0
  329. package/dist/host/worldsystem/memoryWorldSystem.js.map +1 -0
  330. package/dist/host/worldsystem/seam.d.ts +163 -0
  331. package/dist/host/worldsystem/seam.d.ts.map +1 -0
  332. package/dist/host/worldsystem/seam.js +0 -0
  333. package/dist/host/worldsystem/serverClocks.d.ts +18 -0
  334. package/dist/host/worldsystem/serverClocks.d.ts.map +1 -0
  335. package/dist/host/worldsystem/serverClocks.js +166 -0
  336. package/dist/host/worldsystem/serverClocks.js.map +1 -0
  337. package/dist/host/worldsystem/serverDimension.d.ts +10 -0
  338. package/dist/host/worldsystem/serverDimension.d.ts.map +1 -0
  339. package/dist/host/worldsystem/serverDimension.js +388 -0
  340. package/dist/host/worldsystem/serverDimension.js.map +1 -0
  341. package/dist/host/worldsystem/serverFog.d.ts +15 -0
  342. package/dist/host/worldsystem/serverFog.d.ts.map +1 -0
  343. package/dist/host/worldsystem/serverFog.js +66 -0
  344. package/dist/host/worldsystem/serverFog.js.map +1 -0
  345. package/dist/host/worldsystem/serverLoot.d.ts +9 -0
  346. package/dist/host/worldsystem/serverLoot.d.ts.map +1 -0
  347. package/dist/host/worldsystem/serverLoot.js +255 -0
  348. package/dist/host/worldsystem/serverLoot.js.map +1 -0
  349. package/dist/host/worldsystem/serverPrimitiveShapes.d.ts +9 -0
  350. package/dist/host/worldsystem/serverPrimitiveShapes.d.ts.map +1 -0
  351. package/dist/host/worldsystem/serverPrimitiveShapes.js +149 -0
  352. package/dist/host/worldsystem/serverPrimitiveShapes.js.map +1 -0
  353. package/dist/host/worldsystem/serverTickingAreas.d.ts +11 -0
  354. package/dist/host/worldsystem/serverTickingAreas.d.ts.map +1 -0
  355. package/dist/host/worldsystem/serverTickingAreas.js +176 -0
  356. package/dist/host/worldsystem/serverTickingAreas.js.map +1 -0
  357. package/dist/host/worldsystem/serverVolumes.d.ts +9 -0
  358. package/dist/host/worldsystem/serverVolumes.d.ts.map +1 -0
  359. package/dist/host/worldsystem/serverVolumes.js +248 -0
  360. package/dist/host/worldsystem/serverVolumes.js.map +1 -0
  361. package/dist/host/worldsystem/serverWorld.d.ts +18 -0
  362. package/dist/host/worldsystem/serverWorld.d.ts.map +1 -0
  363. package/dist/host/worldsystem/serverWorld.js +199 -0
  364. package/dist/host/worldsystem/serverWorld.js.map +1 -0
  365. package/dist/host/worldsystem/tags.d.ts +40 -0
  366. package/dist/host/worldsystem/tags.d.ts.map +1 -0
  367. package/dist/host/worldsystem/tags.js +43 -0
  368. package/dist/host/worldsystem/tags.js.map +1 -0
  369. package/dist/install.d.ts +39 -0
  370. package/dist/install.d.ts.map +1 -0
  371. package/dist/install.js +83 -0
  372. package/dist/install.js.map +1 -0
  373. package/dist/isRecord.d.ts +3 -0
  374. package/dist/isRecord.d.ts.map +1 -0
  375. package/dist/isRecord.js +6 -0
  376. package/dist/isRecord.js.map +1 -0
  377. package/dist/library.d.ts +40 -0
  378. package/dist/library.d.ts.map +1 -0
  379. package/dist/library.js +101 -0
  380. package/dist/library.js.map +1 -0
  381. package/dist/manifest.d.ts +37 -0
  382. package/dist/manifest.d.ts.map +1 -0
  383. package/dist/manifest.js +40 -0
  384. package/dist/manifest.js.map +1 -0
  385. package/dist/native/manifest.json.js +45 -0
  386. package/dist/native/manifest.json.js.map +1 -0
  387. package/dist/nativeHash.d.ts +16 -0
  388. package/dist/nativeHash.d.ts.map +1 -0
  389. package/dist/nativeHash.js +52 -0
  390. package/dist/nativeHash.js.map +1 -0
  391. package/dist/platform.d.ts +50 -0
  392. package/dist/platform.d.ts.map +1 -0
  393. package/dist/platform.js +77 -0
  394. package/dist/platform.js.map +1 -0
  395. package/dist/shape/binding.d.ts +112 -0
  396. package/dist/shape/binding.d.ts.map +1 -0
  397. package/dist/shape/binding.js +558 -0
  398. package/dist/shape/binding.js.map +1 -0
  399. package/dist/shape/engineRuntime.d.ts +55 -0
  400. package/dist/shape/engineRuntime.d.ts.map +1 -0
  401. package/dist/shape/engineRuntime.js +451 -0
  402. package/dist/shape/engineRuntime.js.map +1 -0
  403. package/dist/shape/format.d.ts +249 -0
  404. package/dist/shape/format.d.ts.map +1 -0
  405. package/dist/shape/format.js +43 -0
  406. package/dist/shape/format.js.map +1 -0
  407. package/dist/shape/history.d.ts +24 -0
  408. package/dist/shape/history.d.ts.map +1 -0
  409. package/dist/shape/history.js +65 -0
  410. package/dist/shape/history.js.map +1 -0
  411. package/dist/shape/implementations.d.ts +105 -0
  412. package/dist/shape/implementations.d.ts.map +1 -0
  413. package/dist/shape/implementations.js +62 -0
  414. package/dist/shape/implementations.js.map +1 -0
  415. package/dist/shape/plan.d.ts +138 -0
  416. package/dist/shape/plan.d.ts.map +1 -0
  417. package/dist/shape/plan.js +0 -0
  418. package/dist/shape/resolve.d.ts +56 -0
  419. package/dist/shape/resolve.d.ts.map +1 -0
  420. package/dist/shape/resolve.js +78 -0
  421. package/dist/shape/resolve.js.map +1 -0
  422. package/dist/shape/version.d.ts +15 -0
  423. package/dist/shape/version.d.ts.map +1 -0
  424. package/dist/shape/version.js +35 -0
  425. package/dist/shape/version.js.map +1 -0
  426. package/dist/testing/debuggerWorker.d.ts +15 -0
  427. package/dist/testing/debuggerWorker.d.ts.map +1 -0
  428. package/dist/testing/debuggerWorker.js +29 -0
  429. package/dist/testing/debuggerWorker.js.map +1 -0
  430. package/dist/testing/engineWorker.d.ts +7 -0
  431. package/dist/testing/engineWorker.d.ts.map +1 -0
  432. package/dist/testing/engineWorker.js +31 -0
  433. package/dist/testing/engineWorker.js.map +1 -0
  434. package/dist/values.d.ts +94 -0
  435. package/dist/values.d.ts.map +1 -0
  436. package/dist/values.js +204 -0
  437. package/dist/values.js.map +1 -0
  438. package/native/manifest.json +49 -0
  439. package/package.json +177 -6
  440. package/scripts/postinstall.mjs +54 -0
@@ -0,0 +1,141 @@
1
+ import { isRecord } from "../isRecord.js";
2
+ import { ScriptHostErrors } from "@jsprismarine/errors/script-host";
3
+ // src/debugger/protocol.ts
4
+ /**
5
+ * The messages of the protocol Mojang's Minecraft Bedrock Debugger for VS Code speaks
6
+ * (`Mojang/minecraft-debugger`, MIT), which the extension took from koush's QuickJS debugger. The
7
+ * shapes follow the extension's `src/protocol-events.ts` and `src/session.ts` at v1.61.0.
8
+ */
9
+ /**
10
+ * The protocol version the host offers. The extension echoes any version from 2 up to its own
11
+ * `DEBUGGER_PROTOCOL_VERSION` (`src/protocol-events.ts`), and 11 is that constant in v1.61.0.
12
+ */
13
+ var DEBUGGER_PROTOCOL_VERSION = 11;
14
+ /** The port the extension and Bedrock Dedicated Server use when none is given. */
15
+ var DEFAULT_DEBUGGER_PORT = 19144;
16
+ /** The level of a printed or notified message, as the extension's `LogLevel` numbers them. */
17
+ var LogLevel = {
18
+ verbose: 0,
19
+ log: 1,
20
+ warn: 2,
21
+ error: 3
22
+ };
23
+ /**
24
+ * The tabs the pinned BDS 1.26.51.1 sends in its `SchemaEvent`, captured from its wire: two for a
25
+ * client's frame timings and memory, which a dedicated server never fills, and the engine's
26
+ * memory table, which the `scripting_engine` statistic fills.
27
+ */
28
+ var DIAGNOSTICS_TABS = [
29
+ {
30
+ name: "Client - Timings",
31
+ stat_group_id: "client_frame_timings",
32
+ data_source: "client",
33
+ display_type: "stacked_line_chart",
34
+ is_empty_tab: false,
35
+ y_label: "Time (ms)",
36
+ tick_range: 200,
37
+ value_scalar: 1
38
+ },
39
+ {
40
+ name: "Client - Memory",
41
+ stat_group_id: "client_memory",
42
+ data_source: "client",
43
+ display_type: "stacked_line_chart",
44
+ is_empty_tab: false,
45
+ y_label: "Memory (MB)",
46
+ tick_range: 200,
47
+ value_scalar: 1e-6
48
+ },
49
+ {
50
+ name: "Server - Scripting Engine",
51
+ stat_group_id: "scripting_engine",
52
+ data_source: "server",
53
+ display_type: "table",
54
+ is_empty_tab: false,
55
+ key_label: "Stat"
56
+ }
57
+ ];
58
+ var text = (value) => typeof value === "string" ? value : void 0;
59
+ /** The lines of a breakpoint list: numbers since protocol 6, `SourceBreakpoint` objects before. */
60
+ var breakpointLines = (value) => Array.isArray(value) ? value.flatMap((entry) => {
61
+ const line = isRecord(entry) ? entry.line : entry;
62
+ return typeof line === "number" && Number.isInteger(line) && line > 0 ? [line] : [];
63
+ }) : [];
64
+ /**
65
+ * Reads one message from the extension. The shapes of protocol 8 and later are flat, and the
66
+ * older ones nest their fields one level down (`src/protocol-events.ts`), so both are read.
67
+ * @param message - A parsed JSON message.
68
+ * @returns The message, or `other` for a type the host does not act on.
69
+ * @throws {TypeError} When the message is not an object with a `type`.
70
+ */
71
+ var parseExtensionMessage = (message) => {
72
+ if (!isRecord(message) || typeof message.type !== "string") throw new ScriptHostErrors.InvalidDebuggerMessage();
73
+ switch (message.type) {
74
+ case "protocol": return {
75
+ type: "protocol",
76
+ version: typeof message.version === "number" ? message.version : 0,
77
+ targetModuleUuid: text(message.target_module_uuid),
78
+ passcode: text(message.passcode)
79
+ };
80
+ case "request": {
81
+ const request = message.request;
82
+ if (!isRecord(request) || typeof request.request_seq !== "number" || typeof request.command !== "string") break;
83
+ return {
84
+ type: "request",
85
+ request: {
86
+ request_seq: request.request_seq,
87
+ command: request.command,
88
+ args: isRecord(request.args) ? request.args : {}
89
+ }
90
+ };
91
+ }
92
+ case "breakpoints": {
93
+ const body = isRecord(message.breakpoints) ? message.breakpoints : message;
94
+ const path = text(body.path);
95
+ if (path === void 0) break;
96
+ return {
97
+ type: "breakpoints",
98
+ path,
99
+ lines: breakpointLines(body.breakpoints)
100
+ };
101
+ }
102
+ case "stopOnException": return {
103
+ type: "stopOnException",
104
+ stop: message.stopOnException === true
105
+ };
106
+ case "resume": return { type: "resume" };
107
+ case "minecraftCommand": {
108
+ const body = isRecord(message.command) ? message.command : message;
109
+ const command = text(body.command);
110
+ if (command === void 0) break;
111
+ return {
112
+ type: "minecraftCommand",
113
+ command,
114
+ dimension: text(body.dimension_type) ?? "overworld"
115
+ };
116
+ }
117
+ case "debugger-request": {
118
+ const body = isRecord(message.request) ? message.request : message;
119
+ if (typeof body.request_seq !== "number") break;
120
+ return {
121
+ type: "debugger-request",
122
+ request_seq: body.request_seq,
123
+ request: text(body.request) ?? ""
124
+ };
125
+ }
126
+ case "startProfiler": return { type: "startProfiler" };
127
+ case "stopProfiler": return {
128
+ type: "stopProfiler",
129
+ capturesPath: text((isRecord(message.profiler) ? message.profiler : message).captures_path) ?? ""
130
+ };
131
+ }
132
+ return {
133
+ type: "other",
134
+ name: message.type
135
+ };
136
+ };
137
+ /** Reads the lines of a `setBreakpoints` request, which protocol 6 and later send as a request. */
138
+ var requestedBreakpointLines = (args) => breakpointLines(args.breakpoints);
139
+ export { DEBUGGER_PROTOCOL_VERSION, DEFAULT_DEBUGGER_PORT, DIAGNOSTICS_TABS, LogLevel, parseExtensionMessage, requestedBreakpointLines };
140
+
141
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","names":[],"sources":["../../src/debugger/protocol.ts"],"sourcesContent":["/**\n * The messages of the protocol Mojang's Minecraft Bedrock Debugger for VS Code speaks\n * (`Mojang/minecraft-debugger`, MIT), which the extension took from koush's QuickJS debugger. The\n * shapes follow the extension's `src/protocol-events.ts` and `src/session.ts` at v1.61.0.\n */\n\nimport { ScriptHostErrors } from '@jsprismarine/errors/script-host';\n\nimport { isRecord } from '../isRecord';\n\n/**\n * The protocol version the host offers. The extension echoes any version from 2 up to its own\n * `DEBUGGER_PROTOCOL_VERSION` (`src/protocol-events.ts`), and 11 is that constant in v1.61.0.\n */\nexport const DEBUGGER_PROTOCOL_VERSION = 11;\n\n/** The port the extension and Bedrock Dedicated Server use when none is given. */\nexport const DEFAULT_DEBUGGER_PORT = 19144;\n\n/** The level of a printed or notified message, as the extension's `LogLevel` numbers them. */\nexport const LogLevel = { verbose: 0, log: 1, warn: 2, error: 3 } as const;\n\n/** One script pack the extension may debug: its name and the UUID of its script module. */\nexport interface DebuggerPlugin {\n readonly name: string;\n readonly module_uuid: string;\n}\n\n/**\n * One statistic of a `StatEvent2`, the extension's `StatDataModel` (`src/stats/stats-provider.ts`):\n * a value for this tick, or a group of named children.\n */\nexport interface DebuggerStat {\n readonly name: string;\n readonly should_aggregate: boolean;\n /** The values; the last one is this tick's. */\n readonly values?: readonly (number | string)[];\n readonly children?: readonly DebuggerStat[];\n}\n\n/**\n * A tab of the extension's diagnostics panel, the extension's `DiagnosticsTabDescriptor`\n * (`src/diagnostics-schema.ts`), with the fields Bedrock Dedicated Server (BDS) fills.\n */\nexport interface DiagnosticsTab {\n readonly name: string;\n readonly stat_group_id: string;\n readonly data_source: 'server' | 'client' | 'server_script';\n readonly display_type: string;\n readonly is_empty_tab: boolean;\n readonly y_label?: string;\n readonly tick_range?: number;\n readonly value_scalar?: number;\n readonly key_label?: string;\n}\n\n/**\n * The tabs the pinned BDS 1.26.51.1 sends in its `SchemaEvent`, captured from its wire: two for a\n * client's frame timings and memory, which a dedicated server never fills, and the engine's\n * memory table, which the `scripting_engine` statistic fills.\n */\nexport const DIAGNOSTICS_TABS: readonly DiagnosticsTab[] = [\n {\n name: 'Client - Timings',\n stat_group_id: 'client_frame_timings',\n data_source: 'client',\n display_type: 'stacked_line_chart',\n is_empty_tab: false,\n y_label: 'Time (ms)',\n tick_range: 200,\n value_scalar: 1\n },\n {\n name: 'Client - Memory',\n stat_group_id: 'client_memory',\n data_source: 'client',\n display_type: 'stacked_line_chart',\n is_empty_tab: false,\n y_label: 'Memory (MB)',\n tick_range: 200,\n value_scalar: 0.000001\n },\n {\n name: 'Server - Scripting Engine',\n stat_group_id: 'scripting_engine',\n data_source: 'server',\n display_type: 'table',\n is_empty_tab: false,\n key_label: 'Stat'\n }\n];\n\n/** The events the host sends, each inside an `{ type: 'event', event }` envelope. */\nexport type DebuggerEvent =\n | {\n readonly type: 'ProtocolEvent';\n readonly version: number;\n readonly plugins: readonly DebuggerPlugin[];\n readonly require_passcode?: boolean;\n }\n | { readonly type: 'StoppedEvent'; readonly reason: string; readonly thread: number }\n | { readonly type: 'ThreadEvent'; readonly reason: 'new' | 'exited'; readonly thread: number }\n | { readonly type: 'PrintEvent'; readonly message: string; readonly logLevel: number }\n | { readonly type: 'NotificationEvent'; readonly message: string; readonly logLevel: number }\n | { readonly type: 'StatEvent2'; readonly tick: number; readonly stats: readonly DebuggerStat[] }\n | { readonly type: 'SchemaEvent'; readonly descriptors: readonly DiagnosticsTab[] }\n /** A CPU profile, `.cpuprofile` JSON in base64, for the extension to write under `capture_base_path`. */\n | { readonly type: 'ProfilerCapture'; readonly capture_base_path: string; readonly capture_data: string }\n /** The host ends the session; BDS sends it just before it closes the connection. */\n | { readonly type: 'terminated' };\n\n/**\n * A message the host sends. A response answers a `request` by its `request_seq`, with a body or\n * an error. `debuggee-response` answers a `debugger-request`; the extension reads it from the\n * envelope's `event` field (`receiveDebugeeMessage` in `src/session.ts`).\n */\nexport type HostMessage =\n | { readonly type: 'event'; readonly event: DebuggerEvent }\n | { readonly type: 'response'; readonly request_seq: number; readonly body?: unknown; readonly error?: string }\n | {\n readonly type: 'debuggee-response';\n readonly event: {\n readonly type: 'debuggee-response';\n readonly request_seq: number;\n readonly success: boolean;\n readonly response_message?: string;\n };\n };\n\n/** A Debug Adapter Protocol request the extension forwards: `stackTrace`, `next` and the rest. */\nexport interface ForwardedRequest {\n readonly request_seq: number;\n readonly command: string;\n readonly args: Record<string, unknown>;\n}\n\n/** A message the extension sends, parsed into what the host acts on. */\nexport type ExtensionMessage =\n | {\n readonly type: 'protocol';\n readonly version: number;\n readonly targetModuleUuid: string | undefined;\n readonly passcode: string | undefined;\n }\n | { readonly type: 'request'; readonly request: ForwardedRequest }\n | { readonly type: 'breakpoints'; readonly path: string; readonly lines: readonly number[] }\n | { readonly type: 'stopOnException'; readonly stop: boolean }\n | { readonly type: 'resume' }\n | { readonly type: 'minecraftCommand'; readonly command: string; readonly dimension: string }\n | { readonly type: 'debugger-request'; readonly request_seq: number; readonly request: string }\n | { readonly type: 'startProfiler' }\n | { readonly type: 'stopProfiler'; readonly capturesPath: string }\n | { readonly type: 'other'; readonly name: string };\n\nconst text = (value: unknown): string | undefined => (typeof value === 'string' ? value : undefined);\n\n/** The lines of a breakpoint list: numbers since protocol 6, `SourceBreakpoint` objects before. */\nconst breakpointLines = (value: unknown): number[] =>\n Array.isArray(value)\n ? value.flatMap((entry) => {\n const line = isRecord(entry) ? entry.line : entry;\n return typeof line === 'number' && Number.isInteger(line) && line > 0 ? [line] : [];\n })\n : [];\n\n/**\n * Reads one message from the extension. The shapes of protocol 8 and later are flat, and the\n * older ones nest their fields one level down (`src/protocol-events.ts`), so both are read.\n * @param message - A parsed JSON message.\n * @returns The message, or `other` for a type the host does not act on.\n * @throws {TypeError} When the message is not an object with a `type`.\n */\nexport const parseExtensionMessage = (message: unknown): ExtensionMessage => {\n if (!isRecord(message) || typeof message.type !== 'string') {\n throw new ScriptHostErrors.InvalidDebuggerMessage();\n }\n switch (message.type) {\n case 'protocol':\n return {\n type: 'protocol',\n version: typeof message.version === 'number' ? message.version : 0,\n targetModuleUuid: text(message.target_module_uuid),\n passcode: text(message.passcode)\n };\n case 'request': {\n const request = message.request;\n if (!isRecord(request) || typeof request.request_seq !== 'number' || typeof request.command !== 'string') {\n break;\n }\n return {\n type: 'request',\n request: {\n request_seq: request.request_seq,\n command: request.command,\n args: isRecord(request.args) ? request.args : {}\n }\n };\n }\n case 'breakpoints': {\n // Before protocol 8 the path and the list sit in a `breakpoints` object.\n const body = isRecord(message.breakpoints) ? message.breakpoints : message;\n const path = text(body.path);\n if (path === undefined) break;\n return { type: 'breakpoints', path, lines: breakpointLines(body.breakpoints) };\n }\n case 'stopOnException':\n return { type: 'stopOnException', stop: message.stopOnException === true };\n case 'resume':\n return { type: 'resume' };\n case 'minecraftCommand': {\n const body = isRecord(message.command) ? message.command : message;\n const command = text(body.command);\n if (command === undefined) break;\n return { type: 'minecraftCommand', command, dimension: text(body.dimension_type) ?? 'overworld' };\n }\n case 'debugger-request': {\n const body = isRecord(message.request) ? message.request : message;\n if (typeof body.request_seq !== 'number') break;\n return { type: 'debugger-request', request_seq: body.request_seq, request: text(body.request) ?? '' };\n }\n case 'startProfiler':\n return { type: 'startProfiler' };\n case 'stopProfiler': {\n // Before protocol 8 the path sits in a `profiler` object.\n const body = isRecord(message.profiler) ? message.profiler : message;\n return { type: 'stopProfiler', capturesPath: text(body.captures_path) ?? '' };\n }\n default:\n break;\n }\n return { type: 'other', name: message.type };\n};\n\n/** Reads the lines of a `setBreakpoints` request, which protocol 6 and later send as a request. */\nexport const requestedBreakpointLines = (args: Record<string, unknown>): number[] => breakpointLines(args.breakpoints);\n"],"mappings":";;;;;;;;;;;;AAcA,IAAa,4BAA4B;;AAGzC,IAAa,wBAAwB;;AAGrC,IAAa,WAAW;CAAE,SAAS;CAAG,KAAK;CAAG,MAAM;CAAG,OAAO;AAAE;;;;;;AAyChE,IAAa,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,QAAQ,cAAc;GACnE,MAAM,OAAO,KAAK,KAAK,IAAI;GAC3B,IAAI,SAAS,KAAA,GAAW;GACxB,OAAO;IAAE,MAAM;IAAe;IAAM,OAAO,gBAAgB,KAAK,WAAW;GAAE;EACjF;EACA,KAAK,mBACD,OAAO;GAAE,MAAM;GAAmB,MAAM,QAAQ,oBAAoB;EAAK;EAC7E,KAAK,UACD,OAAO,EAAE,MAAM,SAAS;EAC5B,KAAK,oBAAoB;GACrB,MAAM,OAAO,SAAS,QAAQ,OAAO,IAAI,QAAQ,UAAU;GAC3D,MAAM,UAAU,KAAK,KAAK,OAAO;GACjC,IAAI,YAAY,KAAA,GAAW;GAC3B,OAAO;IAAE,MAAM;IAAoB;IAAS,WAAW,KAAK,KAAK,cAAc,KAAK;GAAY;EACpG;EACA,KAAK,oBAAoB;GACrB,MAAM,OAAO,SAAS,QAAQ,OAAO,IAAI,QAAQ,UAAU;GAC3D,IAAI,OAAO,KAAK,gBAAgB,UAAU;GAC1C,OAAO;IAAE,MAAM;IAAoB,aAAa,KAAK;IAAa,SAAS,KAAK,KAAK,OAAO,KAAK;GAAG;EACxG;EACA,KAAK,iBACD,OAAO,EAAE,MAAM,gBAAgB;EACnC,KAAK,gBAGD,OAAO;GAAE,MAAM;GAAgB,cAAc,MADhC,SAAS,QAAQ,QAAQ,IAAI,QAAQ,WAAW,QACX,CAAK,aAAa,KAAK;EAAG;CAIpF;CACA,OAAO;EAAE,MAAM;EAAS,MAAM,QAAQ;CAAK;AAC/C;;AAGA,IAAa,4BAA4B,SAA4C,gBAAgB,KAAK,WAAW"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The debugger's sockets on a thread of their own. A stopped script blocks the thread its engine
3
+ * runs on, which is the world's thread, so that thread cannot read a socket while the extension
4
+ * inspects the stopped script. The socket thread listens or connects, and hands each connection to
5
+ * the engine's thread as a {@link DebuggerChannelEndpoint}, which a {@link PortDebuggerChannel}
6
+ * reads there.
7
+ */
8
+ import type { DebuggerChannelEndpoint } from './channel.js';
9
+ import type { ConnectOptions, ListenOptions } from './transport.js';
10
+ /** A connection the socket thread made or accepted. */
11
+ export interface DebuggerThreadConnection {
12
+ /** The end of the channel to the extension that a {@link PortDebuggerChannel} wraps. */
13
+ readonly endpoint: DebuggerChannelEndpoint;
14
+ /** The extension's IP address. */
15
+ readonly address: string;
16
+ /** The extension's port. */
17
+ readonly port: number;
18
+ }
19
+ /** What the socket thread tells the thread that started it. Both run on that thread's event loop. */
20
+ export interface DebuggerThreadEvents {
21
+ /** A connection to the extension arrived; earlier connections have closed. */
22
+ connected(connection: DebuggerThreadConnection): void;
23
+ /** The extension sent a message, or the connection closed, so a session has something to read. */
24
+ activity(): void;
25
+ }
26
+ /** A request to the socket thread. */
27
+ export type DebuggerThreadRequest = {
28
+ readonly id: number;
29
+ readonly op: 'listen';
30
+ readonly options: ListenOptions;
31
+ } | {
32
+ readonly id: number;
33
+ readonly op: 'connect';
34
+ readonly options: ConnectOptions;
35
+ } | {
36
+ readonly id: number;
37
+ readonly op: 'close';
38
+ };
39
+ /** A message from the socket thread. */
40
+ export type DebuggerThreadMessage = {
41
+ readonly kind: 'reply';
42
+ readonly id: number;
43
+ readonly port?: number;
44
+ readonly error?: string;
45
+ } | {
46
+ readonly kind: 'connected';
47
+ readonly connection: DebuggerThreadConnection;
48
+ } | {
49
+ readonly kind: 'activity';
50
+ };
51
+ /**
52
+ * The debugger's socket thread. It holds at most one listener and one connection: a new `listen`
53
+ * or `connect` closes both first, as Bedrock Dedicated Server's commands replace the debugger
54
+ * they find. The thread starts with the first request and does not keep the process alive.
55
+ */
56
+ export declare class DebuggerThread {
57
+ private readonly events;
58
+ private worker;
59
+ private nextId;
60
+ private readonly pending;
61
+ constructor(events: DebuggerThreadEvents);
62
+ /**
63
+ * Listens for the extension, as `/script debugger listen` does.
64
+ * @returns The port it listens on, which tells the port when 0 asked for any.
65
+ * @throws {DebuggerTransportError} With Bedrock Dedicated Server's message for an address other
66
+ * than loopback without a passcode, or why the port could not be opened.
67
+ */
68
+ listen(options: ListenOptions): Promise<number>;
69
+ /**
70
+ * Connects to an extension that listens, as `/script debugger connect` does. The
71
+ * {@link DebuggerThreadEvents.connected} event comes before this resolves.
72
+ * @throws {DebuggerTransportError} When the connection fails.
73
+ */
74
+ connect(options: ConnectOptions): Promise<void>;
75
+ /** Closes the listener and the connection; the channel's end on this thread then reads as closed. */
76
+ close(): Promise<void>;
77
+ /** Stops the thread, closing whatever it held. */
78
+ terminate(): Promise<void>;
79
+ private request;
80
+ private start;
81
+ private receive;
82
+ /** Rejects what waited on a worker that failed or exited, so the next request starts another. */
83
+ private fail;
84
+ }
85
+ //# sourceMappingURL=thread.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thread.d.ts","sources":["../../src/debugger/thread.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAE,uBAAuB,EAAuB,MAAM,WAAW,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjE,uDAAuD;AACvD,MAAM,WAAW,wBAAwB;IACrC,wFAAwF;IACxF,QAAQ,CAAC,QAAQ,EAAE,uBAAuB,CAAC;IAC3C,kCAAkC;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,4BAA4B;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACzB;AAED,qGAAqG;AACrG,MAAM,WAAW,oBAAoB;IACjC,8EAA8E;IAC9E,SAAS,CAAC,UAAU,EAAE,wBAAwB,GAAG,IAAI,CAAC;IACtD,kGAAkG;IAClG,QAAQ,IAAI,IAAI,CAAC;CACpB;AAED,sCAAsC;AACtC,MAAM,MAAM,qBAAqB,GAC3B;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAA;CAAE,GAC/E;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,CAAC,OAAO;IAmBf,iGAAiG;IACjG,OAAO,CAAC,IAAI;CAMf"}
@@ -0,0 +1,134 @@
1
+ import { ScriptHostErrors } from "@jsprismarine/errors/script-host";
2
+ import { Worker } from "node:worker_threads";
3
+ // src/debugger/thread.ts
4
+ /**
5
+ * The debugger's sockets on a thread of their own. A stopped script blocks the thread its engine
6
+ * runs on, which is the world's thread, so that thread cannot read a socket while the extension
7
+ * inspects the stopped script. The socket thread listens or connects, and hands each connection to
8
+ * the engine's thread as a {@link DebuggerChannelEndpoint}, which a {@link PortDebuggerChannel}
9
+ * reads there.
10
+ */
11
+ /** The worker's module beside this one: the source in a checkout, the build otherwise. */
12
+ var workerUrl = () => new URL(import.meta.url.endsWith(".ts") ? "./connectionWorker.ts" : "./connectionWorker.js", import.meta.url);
13
+ /**
14
+ * The flags a worker starts with. Node strips a source worker's types itself, and the repository's
15
+ * resolver adds the extensionless imports the source uses, unless a loader is already there.
16
+ */
17
+ var workerExecArgv = () => {
18
+ if (!import.meta.url.endsWith(".ts")) return process.execArgv;
19
+ const loaderFlags = [
20
+ "--import",
21
+ "--loader",
22
+ "--experimental-loader"
23
+ ];
24
+ if (process.execArgv.some((argument) => loaderFlags.some((flag) => argument.startsWith(flag)))) return process.execArgv;
25
+ const resolver = new URL("data:text/javascript;base64,LyoqCiAqIFJ1bnMgd29ya3NwYWNlIFR5cGVTY3JpcHQgc291cmNlIG9uIE5vZGUncyBidWlsdC1pbiB0eXBlIHN0cmlwcGluZywgYWRkaW5nIHRoZSBleHRlbnNpb25sZXNzCiAqIHJlbGF0aXZlIGltcG9ydHMgdGhlIHNvdXJjZSB1c2VzOiBgbm9kZSAtLWltcG9ydCA8dGhpcyBmaWxlPiBlbnRyeS50c2AuIEl0IHJlcGxhY2VzIHRzeCB3aGVyZSBhCiAqIHByb2Nlc3Mgb3Igd29ya2VyIHJ1bnMgc291cmNlIGRpcmVjdGx5LCBzdWNoIGFzIExldmVsREIncyB0YWJsZSBidWlsZGVyIHdv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TCA9PT0gdW5kZWZpbmVkIHx8ICFjb250ZXh0LnBhcmVudFVSTC5zdGFydHNXaXRoKCdmaWxlOicpKSB7CiAgICAgICAgICAgIHJldHVybiBuZXh0UmVzb2x2ZShzcGVjaWZpZXIsIGNvbnRleHQpOwogICAgICAgIH0KCiAgICAgICAgY29uc3QgY2FuZGlkYXRlID0gcmVzb2x2ZVJlbGF0aXZlRmlsZShzcGVjaWZpZXIsIGNvbnRleHQucGFyZW50VVJMKTsKICAgICAgICByZXR1cm4gY2FuZGlkYXRlID09PSB1bmRlZmluZWQKICAgICAgICAgICAgPyBuZXh0UmVzb2x2ZShzcGVjaWZpZXIsIGNvbnRleHQpCiAgICAgICAgICAgIDogbmV4dFJlc29sdmUocGF0aFRvRmlsZVVSTChjYW5kaWRhdGUpLmhyZWYsIGNvbnRleHQpOwogICAgfQp9KTsK", "" + import.meta.url).href;
26
+ return [
27
+ ...process.execArgv,
28
+ "--import",
29
+ resolver
30
+ ];
31
+ };
32
+ var isThreadMessage = (message) => typeof message === "object" && message !== null && "kind" in message;
33
+ /**
34
+ * The debugger's socket thread. It holds at most one listener and one connection: a new `listen`
35
+ * or `connect` closes both first, as Bedrock Dedicated Server's commands replace the debugger
36
+ * they find. The thread starts with the first request and does not keep the process alive.
37
+ */
38
+ var DebuggerThread = class {
39
+ events;
40
+ worker;
41
+ nextId = 1;
42
+ pending = /* @__PURE__ */ new Map();
43
+ constructor(events) {
44
+ this.events = events;
45
+ }
46
+ /**
47
+ * Listens for the extension, as `/script debugger listen` does.
48
+ * @returns The port it listens on, which tells the port when 0 asked for any.
49
+ * @throws {DebuggerTransportError} With Bedrock Dedicated Server's message for an address other
50
+ * than loopback without a passcode, or why the port could not be opened.
51
+ */
52
+ listen(options) {
53
+ return this.request((id) => ({
54
+ id,
55
+ op: "listen",
56
+ options
57
+ }));
58
+ }
59
+ /**
60
+ * Connects to an extension that listens, as `/script debugger connect` does. The
61
+ * {@link DebuggerThreadEvents.connected} event comes before this resolves.
62
+ * @throws {DebuggerTransportError} When the connection fails.
63
+ */
64
+ async connect(options) {
65
+ await this.request((id) => ({
66
+ id,
67
+ op: "connect",
68
+ options
69
+ }));
70
+ }
71
+ /** Closes the listener and the connection; the channel's end on this thread then reads as closed. */
72
+ async close() {
73
+ if (this.worker === void 0) return;
74
+ await this.request((id) => ({
75
+ id,
76
+ op: "close"
77
+ }));
78
+ }
79
+ /** Stops the thread, closing whatever it held. */
80
+ async terminate() {
81
+ const worker = this.worker;
82
+ this.worker = void 0;
83
+ for (const { reject } of this.pending.values()) reject(new ScriptHostErrors.DebuggerThreadStopped());
84
+ this.pending.clear();
85
+ if (worker !== void 0) await worker.terminate();
86
+ }
87
+ request(build) {
88
+ const id = this.nextId++;
89
+ const reply = new Promise((resolve, reject) => this.pending.set(id, {
90
+ resolve,
91
+ reject
92
+ }));
93
+ this.start().postMessage(build(id));
94
+ return reply;
95
+ }
96
+ start() {
97
+ if (this.worker !== void 0) return this.worker;
98
+ const worker = new Worker(workerUrl(), { execArgv: workerExecArgv() });
99
+ worker.unref();
100
+ worker.on("message", (message) => this.receive(message));
101
+ worker.on("error", (error) => this.fail(worker, error instanceof Error ? error : new ScriptHostErrors.DebuggerThreadThrew({ value: error })));
102
+ worker.on("exit", (code) => this.fail(worker, new ScriptHostErrors.DebuggerThreadExited({ code })));
103
+ this.worker = worker;
104
+ return worker;
105
+ }
106
+ receive(message) {
107
+ if (!isThreadMessage(message)) return;
108
+ switch (message.kind) {
109
+ case "connected":
110
+ this.events.connected(message.connection);
111
+ return;
112
+ case "activity":
113
+ this.events.activity();
114
+ return;
115
+ case "reply": {
116
+ const waiter = this.pending.get(message.id);
117
+ this.pending.delete(message.id);
118
+ if (message.error === void 0) waiter?.resolve(message.port ?? 0);
119
+ else waiter?.reject(new ScriptHostErrors.DebuggerThreadRequestFailed({ reason: message.error }));
120
+ return;
121
+ }
122
+ }
123
+ }
124
+ /** Rejects what waited on a worker that failed or exited, so the next request starts another. */
125
+ fail(worker, error) {
126
+ if (this.worker !== worker) return;
127
+ this.worker = void 0;
128
+ for (const { reject } of this.pending.values()) reject(error);
129
+ this.pending.clear();
130
+ }
131
+ };
132
+ export { DebuggerThread };
133
+
134
+ //# sourceMappingURL=thread.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thread.js","names":[],"sources":["../../src/debugger/thread.ts"],"sourcesContent":["/**\n * The debugger's sockets on a thread of their own. A stopped script blocks the thread its engine\n * runs on, which is the world's thread, so that thread cannot read a socket while the extension\n * inspects the stopped script. The socket thread listens or connects, and hands each connection to\n * the engine's thread as a {@link DebuggerChannelEndpoint}, which a {@link PortDebuggerChannel}\n * reads there.\n */\n\nimport { Worker } from 'node:worker_threads';\n\nimport { ScriptHostErrors } from '@jsprismarine/errors/script-host';\n\nimport type { DebuggerChannelEndpoint, PortDebuggerChannel } from './channel';\nimport type { ConnectOptions, ListenOptions } from './transport';\n\n/** A connection the socket thread made or accepted. */\nexport interface DebuggerThreadConnection {\n /** The end of the channel to the extension that a {@link PortDebuggerChannel} wraps. */\n readonly endpoint: DebuggerChannelEndpoint;\n /** The extension's IP address. */\n readonly address: string;\n /** The extension's port. */\n readonly port: number;\n}\n\n/** What the socket thread tells the thread that started it. Both run on that thread's event loop. */\nexport interface DebuggerThreadEvents {\n /** A connection to the extension arrived; earlier connections have closed. */\n connected(connection: DebuggerThreadConnection): void;\n /** The extension sent a message, or the connection closed, so a session has something to read. */\n activity(): void;\n}\n\n/** A request to the socket thread. */\nexport type DebuggerThreadRequest =\n | { readonly id: number; readonly op: 'listen'; readonly options: ListenOptions }\n | { readonly id: number; readonly op: 'connect'; readonly options: ConnectOptions }\n | { readonly id: number; readonly op: 'close' };\n\n/** A message from the socket thread. */\nexport type DebuggerThreadMessage =\n | { readonly kind: 'reply'; readonly id: number; readonly port?: number; readonly error?: string }\n | { readonly kind: 'connected'; readonly connection: DebuggerThreadConnection }\n | { readonly kind: 'activity' };\n\n/** The worker's module beside this one: the source in a checkout, the build otherwise. */\nconst workerUrl = (): URL =>\n new URL(import.meta.url.endsWith('.ts') ? './connectionWorker.ts' : './connectionWorker.js', import.meta.url);\n\n/**\n * The flags a worker starts with. Node strips a source worker's types itself, and the repository's\n * resolver adds the extensionless imports the source uses, unless a loader is already there.\n */\nconst workerExecArgv = (): string[] => {\n if (!import.meta.url.endsWith('.ts')) return process.execArgv;\n const loaderFlags = ['--import', '--loader', '--experimental-loader'];\n if (process.execArgv.some((argument) => loaderFlags.some((flag) => argument.startsWith(flag)))) {\n return process.execArgv;\n }\n const resolver = new URL('../../../../scripts/native-typescript-loader.mjs', import.meta.url).href;\n return [...process.execArgv, '--import', resolver];\n};\n\nconst isThreadMessage = (message: unknown): message is DebuggerThreadMessage =>\n typeof message === 'object' && message !== null && 'kind' in message;\n\n/**\n * The debugger's socket thread. It holds at most one listener and one connection: a new `listen`\n * or `connect` closes both first, as Bedrock Dedicated Server's commands replace the debugger\n * they find. The thread starts with the first request and does not keep the process alive.\n */\nexport class DebuggerThread {\n private readonly events: DebuggerThreadEvents;\n private worker: Worker | undefined;\n private nextId = 1;\n private readonly pending = new Map<number, { resolve(port: number): void; reject(error: Error): void }>();\n\n public constructor(events: DebuggerThreadEvents) {\n this.events = events;\n }\n\n /**\n * Listens for the extension, as `/script debugger listen` does.\n * @returns The port it listens on, which tells the port when 0 asked for any.\n * @throws {DebuggerTransportError} With Bedrock Dedicated Server's message for an address other\n * than loopback without a passcode, or why the port could not be opened.\n */\n public listen(options: ListenOptions): Promise<number> {\n return this.request((id) => ({ id, op: 'listen', options }));\n }\n\n /**\n * Connects to an extension that listens, as `/script debugger connect` does. The\n * {@link DebuggerThreadEvents.connected} event comes before this resolves.\n * @throws {DebuggerTransportError} When the connection fails.\n */\n public async connect(options: ConnectOptions): Promise<void> {\n await this.request((id) => ({ id, op: 'connect', options }));\n }\n\n /** Closes the listener and the connection; the channel's end on this thread then reads as closed. */\n public async close(): Promise<void> {\n if (this.worker === undefined) return;\n await this.request((id) => ({ id, op: 'close' }));\n }\n\n /** Stops the thread, closing whatever it held. */\n public async terminate(): Promise<void> {\n const worker = this.worker;\n this.worker = undefined;\n for (const { reject } of this.pending.values()) reject(new ScriptHostErrors.DebuggerThreadStopped());\n this.pending.clear();\n if (worker !== undefined) await worker.terminate();\n }\n\n private request(build: (id: number) => DebuggerThreadRequest): Promise<number> {\n const id = this.nextId++;\n const reply = new Promise<number>((resolve, reject) => this.pending.set(id, { resolve, reject }));\n this.start().postMessage(build(id));\n return reply;\n }\n\n private start(): Worker {\n if (this.worker !== undefined) return this.worker;\n const worker = new Worker(workerUrl(), { execArgv: workerExecArgv() });\n worker.unref();\n worker.on('message', (message: unknown) => this.receive(message));\n worker.on('error', (error) =>\n this.fail(\n worker,\n error instanceof Error ? error : new ScriptHostErrors.DebuggerThreadThrew({ value: error })\n )\n );\n worker.on('exit', (code) => this.fail(worker, new ScriptHostErrors.DebuggerThreadExited({ code })));\n this.worker = worker;\n return worker;\n }\n\n private receive(message: unknown): void {\n if (!isThreadMessage(message)) return;\n switch (message.kind) {\n case 'connected':\n this.events.connected(message.connection);\n return;\n case 'activity':\n this.events.activity();\n return;\n case 'reply': {\n const waiter = this.pending.get(message.id);\n this.pending.delete(message.id);\n if (message.error === undefined) waiter?.resolve(message.port ?? 0);\n else waiter?.reject(new ScriptHostErrors.DebuggerThreadRequestFailed({ reason: message.error }));\n return;\n }\n }\n }\n\n /** Rejects what waited on a worker that failed or exited, so the next request starts another. */\n private fail(worker: Worker, error: Error): void {\n if (this.worker !== worker) return;\n this.worker = undefined;\n for (const { reject } of this.pending.values()) reject(error);\n this.pending.clear();\n }\n}\n"],"mappings":";;;;;;;;;;;AA8CA,IAAM,kBACF,IAAI,IAAI,YAAY,IAAI,SAAS,KAAK,IAAI,0BAA0B,yBAAyB,YAAY,GAAG;;;;;AAMhH,IAAM,uBAAiC;CACnC,IAAI,CAAC,YAAY,IAAI,SAAS,KAAK,GAAG,OAAO,QAAQ;CACrD,MAAM,cAAc;EAAC;EAAY;EAAY;CAAu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;EACpB,IAAI,KAAK,WAAW,KAAA,GAAW,OAAO,KAAK;EAC3C,MAAM,SAAS,IAAI,OAAO,UAAU,GAAG,EAAE,UAAU,eAAe,EAAE,CAAC;EACrE,OAAO,MAAM;EACb,OAAO,GAAG,YAAY,YAAqB,KAAK,QAAQ,OAAO,CAAC;EAChE,OAAO,GAAG,UAAU,UAChB,KAAK,KACD,QACA,iBAAiB,QAAQ,QAAQ,IAAI,iBAAiB,oBAAoB,EAAE,OAAO,MAAM,CAAC,CAC9F,CACJ;EACA,OAAO,GAAG,SAAS,SAAS,KAAK,KAAK,QAAQ,IAAI,iBAAiB,qBAAqB,EAAE,KAAK,CAAC,CAAC,CAAC;EAClG,KAAK,SAAS;EACd,OAAO;CACX;CAEA,QAAgB,SAAwB;EACpC,IAAI,CAAC,gBAAgB,OAAO,GAAG;EAC/B,QAAQ,QAAQ,MAAhB;GACI,KAAK;IACD,KAAK,OAAO,UAAU,QAAQ,UAAU;IACxC;GACJ,KAAK;IACD,KAAK,OAAO,SAAS;IACrB;GACJ,KAAK,SAAS;IACV,MAAM,SAAS,KAAK,QAAQ,IAAI,QAAQ,EAAE;IAC1C,KAAK,QAAQ,OAAO,QAAQ,EAAE;IAC9B,IAAI,QAAQ,UAAU,KAAA,GAAW,QAAQ,QAAQ,QAAQ,QAAQ,CAAC;SAC7D,QAAQ,OAAO,IAAI,iBAAiB,4BAA4B,EAAE,QAAQ,QAAQ,MAAM,CAAC,CAAC;IAC/F;GACJ;EACJ;CACJ;;CAGA,KAAa,QAAgB,OAAoB;EAC7C,IAAI,KAAK,WAAW,QAAQ;EAC5B,KAAK,SAAS,KAAA;EACd,KAAK,MAAM,EAAE,YAAY,KAAK,QAAQ,OAAO,GAAG,OAAO,KAAK;EAC5D,KAAK,QAAQ,MAAM;CACvB;AACJ"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The TCP side of the debugger. Like Bedrock Dedicated Server, the host either listens and the
3
+ * extension connects (`/script debugger listen`, the extension's `connect` mode), or connects to
4
+ * an extension that listens (`/script debugger connect`, its `listen` mode). See the extension's
5
+ * `Session.listen` and `Session.connect` in `src/session.ts`.
6
+ */
7
+ import type { AddressInfo, Socket } from 'node:net';
8
+ /** The address a listener binds when none is given, as `script-debugger-listen-address` defaults. */
9
+ export declare const DEFAULT_LISTEN_ADDRESS = "127.0.0.1";
10
+ /**
11
+ * Whether an address only reaches this machine: `localhost`, `127.0.0.0/8`, `::1`, or an IPv4
12
+ * loopback address mapped into IPv6.
13
+ */
14
+ export declare const isLoopbackAddress: (address: string) => boolean;
15
+ /**
16
+ * Applies Bedrock Dedicated Server's rule for listeners: one on an address other machines can reach
17
+ * needs a passcode.
18
+ * @throws {DebuggerTransportError} With the server's message when the address is not loopback and the passcode is empty.
19
+ */
20
+ export declare const checkListenAddress: (address: string, passcode: string | undefined) => void;
21
+ /** One TCP connection to the extension, framed in both directions. */
22
+ export declare class DebuggerSocket {
23
+ private readonly socket;
24
+ private readonly decoder;
25
+ private readonly messageListeners;
26
+ private readonly closeListeners;
27
+ private closedValue;
28
+ /** Wraps a connected socket. */
29
+ constructor(socket: Socket);
30
+ /** Whether the connection has closed. */
31
+ get closed(): boolean;
32
+ /** The extension's end of the connection: its IP address and port. */
33
+ get peer(): {
34
+ readonly address: string;
35
+ readonly port: number;
36
+ };
37
+ /** Calls `listener` with each message the extension sends, in order. */
38
+ onMessage(listener: (message: unknown) => void): void;
39
+ /** Calls `listener` once when the connection closes, with the error that closed it if any. */
40
+ onClose(listener: (error: Error | undefined) => void): void;
41
+ /** Sends one message. */
42
+ send(message: unknown): void;
43
+ /**
44
+ * Closes the connection once what was sent has gone. It destroys the socket then, rather than
45
+ * only ending its side, so the close completes even when the peer keeps its own side open.
46
+ */
47
+ close(): void;
48
+ private finish;
49
+ }
50
+ /** Where to listen for the extension, and the passcode a non-loopback address requires. */
51
+ export interface ListenOptions {
52
+ readonly port?: number;
53
+ readonly address?: string;
54
+ readonly passcode?: string;
55
+ }
56
+ /** A listener waiting for the extension to connect. It takes one connection, then stops listening. */
57
+ export interface DebuggerListener {
58
+ /** The address and port it listens on, which tells the port when 0 asked for any. */
59
+ readonly address: AddressInfo;
60
+ /** The connection, once the extension makes it; rejected when the listener closes first. */
61
+ readonly connection: Promise<DebuggerSocket>;
62
+ /** Stops waiting. */
63
+ close(): void;
64
+ }
65
+ /**
66
+ * Listens for the extension, as `/script debugger listen` does.
67
+ * @throws {DebuggerTransportError} When the address is not loopback and no passcode is set, or it cannot listen.
68
+ */
69
+ export declare const listenForDebugger: (options?: ListenOptions) => Promise<DebuggerListener>;
70
+ /** Where an extension in `listen` mode waits. */
71
+ export interface ConnectOptions {
72
+ readonly host?: string;
73
+ readonly port?: number;
74
+ }
75
+ /**
76
+ * Connects to an extension that listens, as `/script debugger connect` does.
77
+ * @throws {DebuggerTransportError} When the connection fails.
78
+ */
79
+ export declare const connectToDebugger: (options?: ConnectOptions) => Promise<DebuggerSocket>;
80
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sources":["../../src/debugger/transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAU,MAAM,EAAE,MAAM,UAAU,CAAC;AAO5D,qGAAqG;AACrG,eAAO,MAAM,sBAAsB,cAAc,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,YAAa,MAAM,KAAG,OASnD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,YAAa,MAAM,YAAY,MAAM,GAAG,SAAS,KAAG,IAIlF,CAAC;AAEF,sEAAsE;AACtE,qBAAa,cAAc;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAC9C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAsC;IACvE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA8C;IAC7E,OAAO,CAAC,WAAW,C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,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,aAAa,cAAc,KAAQ,OAAO,CAAC,cAAc,CAUjF,CAAC"}
@@ -0,0 +1,150 @@
1
+ import { FrameDecoder, encodeFrame } from "./framing.js";
2
+ import "./protocol.js";
3
+ import { DebuggerFramingError, ScriptHostErrors } from "@jsprismarine/errors/script-host";
4
+ import { connect, createServer, isIP } from "node:net";
5
+ // src/debugger/transport.ts
6
+ /**
7
+ * The TCP side of the debugger. Like Bedrock Dedicated Server, the host either listens and the
8
+ * extension connects (`/script debugger listen`, the extension's `connect` mode), or connects to
9
+ * an extension that listens (`/script debugger connect`, its `listen` mode). See the extension's
10
+ * `Session.listen` and `Session.connect` in `src/session.ts`.
11
+ */
12
+ /** The address a listener binds when none is given, as `script-debugger-listen-address` defaults. */
13
+ var DEFAULT_LISTEN_ADDRESS = "127.0.0.1";
14
+ /**
15
+ * Whether an address only reaches this machine: `localhost`, `127.0.0.0/8`, `::1`, or an IPv4
16
+ * loopback address mapped into IPv6.
17
+ */
18
+ var isLoopbackAddress = (address) => {
19
+ const host = address.startsWith("[") && address.endsWith("]") ? address.slice(1, -1) : address;
20
+ if (host.toLowerCase() === "localhost") return true;
21
+ if (isIP(host) === 4) return host.startsWith("127.");
22
+ if (isIP(host) === 6) {
23
+ const lower = host.toLowerCase();
24
+ return lower === "::1" || lower === "0:0:0:0:0:0:0:1" || lower.startsWith("::ffff:127.");
25
+ }
26
+ return false;
27
+ };
28
+ /**
29
+ * Applies Bedrock Dedicated Server's rule for listeners: one on an address other machines can reach
30
+ * needs a passcode.
31
+ * @throws {DebuggerTransportError} With the server's message when the address is not loopback and the passcode is empty.
32
+ */
33
+ var checkListenAddress = (address, passcode) => {
34
+ if (!isLoopbackAddress(address) && (passcode ?? "") === "") throw new ScriptHostErrors.ListenerNeedsPasscode({ address });
35
+ };
36
+ /** One TCP connection to the extension, framed in both directions. */
37
+ var DebuggerSocket = class {
38
+ socket;
39
+ decoder = new FrameDecoder();
40
+ messageListeners = [];
41
+ closeListeners = [];
42
+ closedValue = false;
43
+ /** Wraps a connected socket. */
44
+ constructor(socket) {
45
+ this.socket = socket;
46
+ socket.setNoDelay(true);
47
+ socket.on("data", (chunk) => {
48
+ let messages;
49
+ try {
50
+ messages = this.decoder.push(chunk);
51
+ } catch (error) {
52
+ this.finish(error instanceof DebuggerFramingError ? error : new ScriptHostErrors.FrameNotRead({ reason: String(error) }, { cause: error }));
53
+ return;
54
+ }
55
+ for (const message of messages) for (const listener of this.messageListeners) listener(message);
56
+ });
57
+ socket.on("error", (error) => this.finish(error));
58
+ socket.on("close", () => this.finish(void 0));
59
+ }
60
+ /** Whether the connection has closed. */
61
+ get closed() {
62
+ return this.closedValue;
63
+ }
64
+ /** The extension's end of the connection: its IP address and port. */
65
+ get peer() {
66
+ return {
67
+ address: this.socket.remoteAddress ?? "",
68
+ port: this.socket.remotePort ?? 0
69
+ };
70
+ }
71
+ /** Calls `listener` with each message the extension sends, in order. */
72
+ onMessage(listener) {
73
+ this.messageListeners.push(listener);
74
+ }
75
+ /** Calls `listener` once when the connection closes, with the error that closed it if any. */
76
+ onClose(listener) {
77
+ if (this.closedValue) listener(void 0);
78
+ else this.closeListeners.push(listener);
79
+ }
80
+ /** Sends one message. */
81
+ send(message) {
82
+ if (!this.closedValue) this.socket.write(encodeFrame(message));
83
+ }
84
+ /**
85
+ * Closes the connection once what was sent has gone. It destroys the socket then, rather than
86
+ * only ending its side, so the close completes even when the peer keeps its own side open.
87
+ */
88
+ close() {
89
+ this.socket.destroySoon();
90
+ }
91
+ finish(error) {
92
+ if (this.closedValue) return;
93
+ this.closedValue = true;
94
+ this.socket.destroy();
95
+ for (const listener of this.closeListeners.splice(0)) listener(error);
96
+ }
97
+ };
98
+ /**
99
+ * Listens for the extension, as `/script debugger listen` does.
100
+ * @throws {DebuggerTransportError} When the address is not loopback and no passcode is set, or it cannot listen.
101
+ */
102
+ var listenForDebugger = async (options = {}) => {
103
+ const host = options.address ?? "127.0.0.1";
104
+ checkListenAddress(host, options.passcode);
105
+ const server = createServer();
106
+ let settle;
107
+ const connection = new Promise((resolve, reject) => {
108
+ settle = {
109
+ resolve,
110
+ reject
111
+ };
112
+ });
113
+ connection.catch(() => void 0);
114
+ server.on("connection", (socket) => {
115
+ server.close();
116
+ settle?.resolve(new DebuggerSocket(socket));
117
+ });
118
+ await new Promise((resolve, reject) => {
119
+ server.once("error", (error) => reject(new ScriptHostErrors.ListenFailed({ reason: error.message }, { cause: error })));
120
+ server.listen(options.port ?? 19144, host, resolve);
121
+ });
122
+ const address = server.address();
123
+ if (address === null || typeof address === "string") throw new ScriptHostErrors.ListenerHasNoAddress();
124
+ return {
125
+ address,
126
+ connection,
127
+ close: () => {
128
+ server.close();
129
+ settle?.reject(new ScriptHostErrors.ListenerClosed());
130
+ }
131
+ };
132
+ };
133
+ /**
134
+ * Connects to an extension that listens, as `/script debugger connect` does.
135
+ * @throws {DebuggerTransportError} When the connection fails.
136
+ */
137
+ var connectToDebugger = (options = {}) => new Promise((resolve, reject) => {
138
+ const socket = connect({
139
+ host: options.host ?? "localhost",
140
+ port: options.port ?? 19144
141
+ });
142
+ socket.once("connect", () => {
143
+ socket.removeAllListeners("error");
144
+ resolve(new DebuggerSocket(socket));
145
+ });
146
+ socket.once("error", (error) => reject(new ScriptHostErrors.ConnectFailed({ reason: error.message }, { cause: error })));
147
+ });
148
+ export { DEFAULT_LISTEN_ADDRESS, DebuggerSocket, checkListenAddress, connectToDebugger, isLoopbackAddress, listenForDebugger };
149
+
150
+ //# sourceMappingURL=transport.js.map