@smthrs/platform-node 0.0.0-stage → 1.0.0-rc.4

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 (442) hide show
  1. package/CHANGELOG.md +211 -0
  2. package/LICENSE +21 -0
  3. package/README.md +165 -2
  4. package/bin/darwin-arm64/smithers-jj-export +0 -0
  5. package/bin/darwin-x64/smithers-jj-export +0 -0
  6. package/bin/linux-arm64/smithers-jj-export +0 -0
  7. package/bin/linux-x64/smithers-jj-export +4 -0
  8. package/bin/win32-x64/smithers-jj-export.exe +0 -0
  9. package/dist/cjs/AtomicFileSystem.d.ts +147 -0
  10. package/dist/cjs/AtomicFileSystem.d.ts.map +1 -0
  11. package/dist/cjs/AtomicFileSystem.js +234 -0
  12. package/dist/cjs/AtomicFileSystem.js.map +7 -0
  13. package/dist/cjs/EgressHttpClient.d.ts +106 -0
  14. package/dist/cjs/EgressHttpClient.d.ts.map +1 -0
  15. package/dist/cjs/EgressHttpClient.js +202 -0
  16. package/dist/cjs/EgressHttpClient.js.map +7 -0
  17. package/dist/cjs/HostLiveness.d.ts +81 -0
  18. package/dist/cjs/HostLiveness.d.ts.map +1 -0
  19. package/dist/cjs/HostLiveness.js +49 -0
  20. package/dist/cjs/HostLiveness.js.map +7 -0
  21. package/dist/cjs/NodeHost.d.ts +145 -0
  22. package/dist/cjs/NodeHost.d.ts.map +1 -0
  23. package/dist/cjs/NodeHost.js +128 -0
  24. package/dist/cjs/NodeHost.js.map +7 -0
  25. package/dist/cjs/ProcessConfinement.d.ts +61 -0
  26. package/dist/cjs/ProcessConfinement.d.ts.map +1 -0
  27. package/dist/cjs/ProcessConfinement.js +292 -0
  28. package/dist/cjs/ProcessConfinement.js.map +7 -0
  29. package/dist/cjs/ProcessReaper.d.ts +457 -0
  30. package/dist/cjs/ProcessReaper.d.ts.map +1 -0
  31. package/dist/cjs/ProcessReaper.js +349 -0
  32. package/dist/cjs/ProcessReaper.js.map +7 -0
  33. package/dist/cjs/ProcessSandbox.d.ts +391 -0
  34. package/dist/cjs/ProcessSandbox.d.ts.map +1 -0
  35. package/dist/cjs/ProcessSandbox.js +774 -0
  36. package/dist/cjs/ProcessSandbox.js.map +7 -0
  37. package/dist/cjs/ScopedProcess.d.ts +66 -0
  38. package/dist/cjs/ScopedProcess.d.ts.map +1 -0
  39. package/dist/cjs/ScopedProcess.js +87 -0
  40. package/dist/cjs/ScopedProcess.js.map +7 -0
  41. package/dist/cjs/index.d.ts +38 -0
  42. package/dist/cjs/index.d.ts.map +1 -0
  43. package/dist/cjs/index.js +47 -0
  44. package/dist/cjs/index.js.map +7 -0
  45. package/dist/cjs/internal/AtomicFileSystemExecutable.d.ts +61 -0
  46. package/dist/cjs/internal/AtomicFileSystemExecutable.d.ts.map +1 -0
  47. package/dist/cjs/internal/AtomicFileSystemExecutable.js +250 -0
  48. package/dist/cjs/internal/AtomicFileSystemExecutable.js.map +7 -0
  49. package/dist/cjs/internal/AtomicFileSystemProtocol.d.ts +78 -0
  50. package/dist/cjs/internal/AtomicFileSystemProtocol.d.ts.map +1 -0
  51. package/dist/cjs/internal/AtomicFileSystemProtocol.js +382 -0
  52. package/dist/cjs/internal/AtomicFileSystemProtocol.js.map +7 -0
  53. package/dist/cjs/internal/AtomicFileSystemTransport.d.ts +44 -0
  54. package/dist/cjs/internal/AtomicFileSystemTransport.d.ts.map +1 -0
  55. package/dist/cjs/internal/AtomicFileSystemTransport.js +197 -0
  56. package/dist/cjs/internal/AtomicFileSystemTransport.js.map +7 -0
  57. package/dist/cjs/internal/AtomicHelperError.d.ts +35 -0
  58. package/dist/cjs/internal/AtomicHelperError.d.ts.map +1 -0
  59. package/dist/cjs/internal/AtomicHelperError.js +45 -0
  60. package/dist/cjs/internal/AtomicHelperError.js.map +7 -0
  61. package/dist/cjs/internal/AtomicHelperFault.d.ts +59 -0
  62. package/dist/cjs/internal/AtomicHelperFault.d.ts.map +1 -0
  63. package/dist/cjs/internal/AtomicHelperFault.js +66 -0
  64. package/dist/cjs/internal/AtomicHelperFault.js.map +7 -0
  65. package/dist/cjs/internal/PipedProcess.d.ts +35 -0
  66. package/dist/cjs/internal/PipedProcess.d.ts.map +1 -0
  67. package/dist/cjs/internal/PipedProcess.js +309 -0
  68. package/dist/cjs/internal/PipedProcess.js.map +7 -0
  69. package/dist/cjs/internal/ProcSnapshot.d.ts +85 -0
  70. package/dist/cjs/internal/ProcSnapshot.d.ts.map +1 -0
  71. package/dist/cjs/internal/ProcSnapshot.js +123 -0
  72. package/dist/cjs/internal/ProcSnapshot.js.map +7 -0
  73. package/dist/cjs/internal/ProcessCleanup.d.ts +64 -0
  74. package/dist/cjs/internal/ProcessCleanup.d.ts.map +1 -0
  75. package/dist/cjs/internal/ProcessCleanup.js +62 -0
  76. package/dist/cjs/internal/ProcessCleanup.js.map +7 -0
  77. package/dist/cjs/internal/ProcessCleanupPolicyError.d.ts +30 -0
  78. package/dist/cjs/internal/ProcessCleanupPolicyError.d.ts.map +1 -0
  79. package/dist/cjs/internal/ProcessCleanupPolicyError.js +33 -0
  80. package/dist/cjs/internal/ProcessCleanupPolicyError.js.map +7 -0
  81. package/dist/cjs/internal/ProcessFault.d.ts +63 -0
  82. package/dist/cjs/internal/ProcessFault.d.ts.map +1 -0
  83. package/dist/cjs/internal/ProcessFault.js +63 -0
  84. package/dist/cjs/internal/ProcessFault.js.map +7 -0
  85. package/dist/cjs/internal/ProcessSupervisor.d.ts +143 -0
  86. package/dist/cjs/internal/ProcessSupervisor.d.ts.map +1 -0
  87. package/dist/cjs/internal/ProcessSupervisor.js +685 -0
  88. package/dist/cjs/internal/ProcessSupervisor.js.map +7 -0
  89. package/dist/cjs/internal/SupervisorProgram.d.ts +9 -0
  90. package/dist/cjs/internal/SupervisorProgram.d.ts.map +1 -0
  91. package/dist/cjs/internal/SupervisorProgram.js +326 -0
  92. package/dist/cjs/internal/SupervisorProgram.js.map +7 -0
  93. package/dist/cjs/internal/WindowsProcessJob.d.ts +39 -0
  94. package/dist/cjs/internal/WindowsProcessJob.d.ts.map +1 -0
  95. package/dist/cjs/internal/WindowsProcessJob.js +113 -0
  96. package/dist/cjs/internal/WindowsProcessJob.js.map +7 -0
  97. package/dist/cjs/package.json +1 -0
  98. package/dist/esm/AtomicFileSystem.d.ts +147 -0
  99. package/dist/esm/AtomicFileSystem.d.ts.map +1 -0
  100. package/dist/esm/AtomicFileSystem.js +290 -0
  101. package/dist/esm/AtomicFileSystem.js.map +1 -0
  102. package/dist/esm/EgressHttpClient.d.ts +106 -0
  103. package/dist/esm/EgressHttpClient.d.ts.map +1 -0
  104. package/dist/esm/EgressHttpClient.js +259 -0
  105. package/dist/esm/EgressHttpClient.js.map +1 -0
  106. package/dist/esm/HostLiveness.d.ts +81 -0
  107. package/dist/esm/HostLiveness.d.ts.map +1 -0
  108. package/dist/esm/HostLiveness.js +68 -0
  109. package/dist/esm/HostLiveness.js.map +1 -0
  110. package/dist/esm/NodeHost.d.ts +145 -0
  111. package/dist/esm/NodeHost.d.ts.map +1 -0
  112. package/dist/esm/NodeHost.js +162 -0
  113. package/dist/esm/NodeHost.js.map +1 -0
  114. package/dist/esm/ProcessConfinement.d.ts +61 -0
  115. package/dist/esm/ProcessConfinement.d.ts.map +1 -0
  116. package/dist/esm/ProcessConfinement.js +311 -0
  117. package/dist/esm/ProcessConfinement.js.map +1 -0
  118. package/dist/esm/ProcessReaper.d.ts +457 -0
  119. package/dist/esm/ProcessReaper.d.ts.map +1 -0
  120. package/dist/esm/ProcessReaper.js +711 -0
  121. package/dist/esm/ProcessReaper.js.map +1 -0
  122. package/dist/esm/ProcessSandbox.d.ts +391 -0
  123. package/dist/esm/ProcessSandbox.d.ts.map +1 -0
  124. package/dist/esm/ProcessSandbox.js +1043 -0
  125. package/dist/esm/ProcessSandbox.js.map +1 -0
  126. package/dist/esm/ScopedProcess.d.ts +66 -0
  127. package/dist/esm/ScopedProcess.d.ts.map +1 -0
  128. package/dist/esm/ScopedProcess.js +67 -0
  129. package/dist/esm/ScopedProcess.js.map +1 -0
  130. package/dist/esm/index.d.ts +38 -0
  131. package/dist/esm/index.d.ts.map +1 -0
  132. package/dist/esm/index.js +38 -0
  133. package/dist/esm/index.js.map +1 -0
  134. package/dist/esm/internal/AtomicFileSystemExecutable.d.ts +61 -0
  135. package/dist/esm/internal/AtomicFileSystemExecutable.d.ts.map +1 -0
  136. package/dist/esm/internal/AtomicFileSystemExecutable.js +350 -0
  137. package/dist/esm/internal/AtomicFileSystemExecutable.js.map +1 -0
  138. package/dist/esm/internal/AtomicFileSystemProtocol.d.ts +78 -0
  139. package/dist/esm/internal/AtomicFileSystemProtocol.d.ts.map +1 -0
  140. package/dist/esm/internal/AtomicFileSystemProtocol.js +412 -0
  141. package/dist/esm/internal/AtomicFileSystemProtocol.js.map +1 -0
  142. package/dist/esm/internal/AtomicFileSystemTransport.d.ts +44 -0
  143. package/dist/esm/internal/AtomicFileSystemTransport.d.ts.map +1 -0
  144. package/dist/esm/internal/AtomicFileSystemTransport.js +242 -0
  145. package/dist/esm/internal/AtomicFileSystemTransport.js.map +1 -0
  146. package/dist/esm/internal/AtomicHelperError.d.ts +35 -0
  147. package/dist/esm/internal/AtomicHelperError.d.ts.map +1 -0
  148. package/dist/esm/internal/AtomicHelperError.js +39 -0
  149. package/dist/esm/internal/AtomicHelperError.js.map +1 -0
  150. package/dist/esm/internal/AtomicHelperFault.d.ts +59 -0
  151. package/dist/esm/internal/AtomicHelperFault.d.ts.map +1 -0
  152. package/dist/esm/internal/AtomicHelperFault.js +66 -0
  153. package/dist/esm/internal/AtomicHelperFault.js.map +1 -0
  154. package/dist/esm/internal/PipedProcess.d.ts +35 -0
  155. package/dist/esm/internal/PipedProcess.d.ts.map +1 -0
  156. package/dist/esm/internal/PipedProcess.js +321 -0
  157. package/dist/esm/internal/PipedProcess.js.map +1 -0
  158. package/dist/esm/internal/ProcSnapshot.d.ts +85 -0
  159. package/dist/esm/internal/ProcSnapshot.d.ts.map +1 -0
  160. package/dist/esm/internal/ProcSnapshot.js +188 -0
  161. package/dist/esm/internal/ProcSnapshot.js.map +1 -0
  162. package/dist/esm/internal/ProcessCleanup.d.ts +64 -0
  163. package/dist/esm/internal/ProcessCleanup.d.ts.map +1 -0
  164. package/dist/esm/internal/ProcessCleanup.js +45 -0
  165. package/dist/esm/internal/ProcessCleanup.js.map +1 -0
  166. package/dist/esm/internal/ProcessCleanupPolicyError.d.ts +30 -0
  167. package/dist/esm/internal/ProcessCleanupPolicyError.d.ts.map +1 -0
  168. package/dist/esm/internal/ProcessCleanupPolicyError.js +25 -0
  169. package/dist/esm/internal/ProcessCleanupPolicyError.js.map +1 -0
  170. package/dist/esm/internal/ProcessFault.d.ts +63 -0
  171. package/dist/esm/internal/ProcessFault.d.ts.map +1 -0
  172. package/dist/esm/internal/ProcessFault.js +64 -0
  173. package/dist/esm/internal/ProcessFault.js.map +1 -0
  174. package/dist/esm/internal/ProcessSupervisor.d.ts +143 -0
  175. package/dist/esm/internal/ProcessSupervisor.d.ts.map +1 -0
  176. package/dist/esm/internal/ProcessSupervisor.js +689 -0
  177. package/dist/esm/internal/ProcessSupervisor.js.map +1 -0
  178. package/dist/esm/internal/SupervisorProgram.d.ts +9 -0
  179. package/dist/esm/internal/SupervisorProgram.d.ts.map +1 -0
  180. package/dist/esm/internal/SupervisorProgram.js +310 -0
  181. package/dist/esm/internal/SupervisorProgram.js.map +1 -0
  182. package/dist/esm/internal/WindowsProcessJob.d.ts +39 -0
  183. package/dist/esm/internal/WindowsProcessJob.d.ts.map +1 -0
  184. package/dist/esm/internal/WindowsProcessJob.js +115 -0
  185. package/dist/esm/internal/WindowsProcessJob.js.map +1 -0
  186. package/dist/vendor/adapters.json +1757 -0
  187. package/dist/vendor/chunk-2Y7WC4KU.js +109 -0
  188. package/dist/vendor/chunk-3GR5VZ2M.js +118 -0
  189. package/dist/vendor/chunk-42QKY6T6.js +40 -0
  190. package/dist/vendor/chunk-54RLBMTZ.js +61 -0
  191. package/dist/vendor/chunk-5ZMHBXIK.js +55 -0
  192. package/dist/vendor/chunk-6ME2W7TF.js +28 -0
  193. package/dist/vendor/chunk-AMQKOQNT.js +34 -0
  194. package/dist/vendor/chunk-B3FZ67QU.js +59 -0
  195. package/dist/vendor/chunk-BKTBUBQY.js +437 -0
  196. package/dist/vendor/chunk-DS7GF46S.js +34 -0
  197. package/dist/vendor/chunk-DVOAHXPG.js +104 -0
  198. package/dist/vendor/chunk-DWSHTSVX.js +229 -0
  199. package/dist/vendor/chunk-EGBNVEEW.js +14 -0
  200. package/dist/vendor/chunk-EZWY45HP.js +18 -0
  201. package/dist/vendor/chunk-FNZOJHSV.js +71 -0
  202. package/dist/vendor/chunk-GXCHI7BM.js +131 -0
  203. package/dist/vendor/chunk-IIJ52ZU6.js +20 -0
  204. package/dist/vendor/chunk-J7A4CZDO.js +92 -0
  205. package/dist/vendor/chunk-JG5TTWPT.js +85 -0
  206. package/dist/vendor/chunk-JJ24ARBQ.js +394 -0
  207. package/dist/vendor/chunk-KOZMM5PZ.js +426 -0
  208. package/dist/vendor/chunk-KUUXSID7.js +18 -0
  209. package/dist/vendor/chunk-LEUPYT3Q.js +36 -0
  210. package/dist/vendor/chunk-M32LDTW7.js +18 -0
  211. package/dist/vendor/chunk-M7CLUILA.js +0 -0
  212. package/dist/vendor/chunk-MBSKBQ5D.js +21 -0
  213. package/dist/vendor/chunk-MLKGABMK.js +9 -0
  214. package/dist/vendor/chunk-NBVRTDTV.js +129 -0
  215. package/dist/vendor/chunk-OXNGN5H7.js +81 -0
  216. package/dist/vendor/chunk-QPLDT6A6.js +564 -0
  217. package/dist/vendor/chunk-QYBKAIA6.js +18 -0
  218. package/dist/vendor/chunk-RO2R4MJH.js +62 -0
  219. package/dist/vendor/chunk-SIR62W3Y.js +398 -0
  220. package/dist/vendor/chunk-TFIKFFSC.js +26 -0
  221. package/dist/vendor/chunk-TXKLEBBL.js +143 -0
  222. package/dist/vendor/chunk-UFH5UUZK.js +48 -0
  223. package/dist/vendor/chunk-VANKHF46.js +96 -0
  224. package/dist/vendor/chunk-VZBDV3TV.js +18 -0
  225. package/dist/vendor/chunk-XDKNKFBW.js +22 -0
  226. package/dist/vendor/chunk-XH4U3JSV.js +249 -0
  227. package/dist/vendor/chunk-Y35ZAO5U.js +53 -0
  228. package/dist/vendor/chunk-ZJMRMY57.js +0 -0
  229. package/dist/vendor/cjs/node/NodeChildProcessSpawner.d.ts +7 -0
  230. package/dist/vendor/cjs/node/NodeChildProcessSpawner.js +1 -0
  231. package/dist/vendor/cjs/node/NodeClusterHttp.d.ts +63 -0
  232. package/dist/vendor/cjs/node/NodeClusterHttp.js +1 -0
  233. package/dist/vendor/cjs/node/NodeClusterSocket.d.ts +79 -0
  234. package/dist/vendor/cjs/node/NodeClusterSocket.js +1 -0
  235. package/dist/vendor/cjs/node/NodeCrypto.d.ts +10 -0
  236. package/dist/vendor/cjs/node/NodeCrypto.js +1 -0
  237. package/dist/vendor/cjs/node/NodeFileSystem.d.ts +10 -0
  238. package/dist/vendor/cjs/node/NodeFileSystem.js +1 -0
  239. package/dist/vendor/cjs/node/NodeHttpClient.d.ts +179 -0
  240. package/dist/vendor/cjs/node/NodeHttpClient.js +1 -0
  241. package/dist/vendor/cjs/node/NodeHttpIncomingMessage.d.ts +62 -0
  242. package/dist/vendor/cjs/node/NodeHttpIncomingMessage.js +1 -0
  243. package/dist/vendor/cjs/node/NodeHttpPlatform.d.ts +36 -0
  244. package/dist/vendor/cjs/node/NodeHttpPlatform.js +1 -0
  245. package/dist/vendor/cjs/node/NodeHttpServer.d.ts +120 -0
  246. package/dist/vendor/cjs/node/NodeHttpServer.js +1 -0
  247. package/dist/vendor/cjs/node/NodeHttpServerRequest.d.ts +29 -0
  248. package/dist/vendor/cjs/node/NodeHttpServerRequest.js +1 -0
  249. package/dist/vendor/cjs/node/NodeMultipart.d.ts +46 -0
  250. package/dist/vendor/cjs/node/NodeMultipart.js +1 -0
  251. package/dist/vendor/cjs/node/NodeMultipartParser.d.ts +97 -0
  252. package/dist/vendor/cjs/node/NodeMultipartParser.js +1 -0
  253. package/dist/vendor/cjs/node/NodePath.d.ts +27 -0
  254. package/dist/vendor/cjs/node/NodePath.js +1 -0
  255. package/dist/vendor/cjs/node/NodeRedis.d.ts +74 -0
  256. package/dist/vendor/cjs/node/NodeRedis.js +1 -0
  257. package/dist/vendor/cjs/node/NodeRuntime.d.ts +85 -0
  258. package/dist/vendor/cjs/node/NodeRuntime.js +1 -0
  259. package/dist/vendor/cjs/node/NodeServices.d.ts +34 -0
  260. package/dist/vendor/cjs/node/NodeServices.js +1 -0
  261. package/dist/vendor/cjs/node/NodeSink.d.ts +8 -0
  262. package/dist/vendor/cjs/node/NodeSink.js +1 -0
  263. package/dist/vendor/cjs/node/NodeSocket.d.ts +38 -0
  264. package/dist/vendor/cjs/node/NodeSocket.js +1 -0
  265. package/dist/vendor/cjs/node/NodeSocketServer.d.ts +8 -0
  266. package/dist/vendor/cjs/node/NodeSocketServer.js +1 -0
  267. package/dist/vendor/cjs/node/NodeStdio.d.ts +11 -0
  268. package/dist/vendor/cjs/node/NodeStdio.js +1 -0
  269. package/dist/vendor/cjs/node/NodeStream.d.ts +8 -0
  270. package/dist/vendor/cjs/node/NodeStream.js +1 -0
  271. package/dist/vendor/cjs/node/NodeTerminal.d.ts +21 -0
  272. package/dist/vendor/cjs/node/NodeTerminal.js +1 -0
  273. package/dist/vendor/cjs/node/NodeWorker.d.ts +22 -0
  274. package/dist/vendor/cjs/node/NodeWorker.js +1 -0
  275. package/dist/vendor/cjs/node/NodeWorkerRunner.d.ts +12 -0
  276. package/dist/vendor/cjs/node/NodeWorkerRunner.js +1 -0
  277. package/dist/vendor/cjs/node/Undici.d.ts +28 -0
  278. package/dist/vendor/cjs/node/Undici.js +1 -0
  279. package/dist/vendor/cjs/node/index.d.ts +100 -0
  280. package/dist/vendor/cjs/node/index.js +1 -0
  281. package/dist/vendor/cjs/node-shared/NodeChildProcessSpawner.d.ts +57 -0
  282. package/dist/vendor/cjs/node-shared/NodeChildProcessSpawner.js +1 -0
  283. package/dist/vendor/cjs/node-shared/NodeClusterSocket.d.ts +22 -0
  284. package/dist/vendor/cjs/node-shared/NodeClusterSocket.js +1 -0
  285. package/dist/vendor/cjs/node-shared/NodeCrypto.d.ts +27 -0
  286. package/dist/vendor/cjs/node-shared/NodeCrypto.js +1 -0
  287. package/dist/vendor/cjs/node-shared/NodeFileSystem.d.ts +11 -0
  288. package/dist/vendor/cjs/node-shared/NodeFileSystem.js +1 -0
  289. package/dist/vendor/cjs/node-shared/NodeHttpCompression.d.ts +36 -0
  290. package/dist/vendor/cjs/node-shared/NodeHttpCompression.js +1 -0
  291. package/dist/vendor/cjs/node-shared/NodePath.d.ts +27 -0
  292. package/dist/vendor/cjs/node-shared/NodePath.js +1 -0
  293. package/dist/vendor/cjs/node-shared/NodeRuntime.d.ts +47 -0
  294. package/dist/vendor/cjs/node-shared/NodeRuntime.js +1 -0
  295. package/dist/vendor/cjs/node-shared/NodeSink.d.ts +69 -0
  296. package/dist/vendor/cjs/node-shared/NodeSink.js +1 -0
  297. package/dist/vendor/cjs/node-shared/NodeSocket.d.ts +134 -0
  298. package/dist/vendor/cjs/node-shared/NodeSocket.js +1 -0
  299. package/dist/vendor/cjs/node-shared/NodeSocketServer.d.ts +80 -0
  300. package/dist/vendor/cjs/node-shared/NodeSocketServer.js +1 -0
  301. package/dist/vendor/cjs/node-shared/NodeStdio.d.ts +12 -0
  302. package/dist/vendor/cjs/node-shared/NodeStdio.js +1 -0
  303. package/dist/vendor/cjs/node-shared/NodeStream.d.ts +179 -0
  304. package/dist/vendor/cjs/node-shared/NodeStream.js +1 -0
  305. package/dist/vendor/cjs/node-shared/NodeTerminal.d.ts +22 -0
  306. package/dist/vendor/cjs/node-shared/NodeTerminal.js +1 -0
  307. package/dist/vendor/cjs/node-shared/index.d.ts +56 -0
  308. package/dist/vendor/cjs/node-shared/index.js +1 -0
  309. package/dist/vendor/cjs/node-shared/internal/nodeChildProcessSpawner.d.ts +4 -0
  310. package/dist/vendor/cjs/node-shared/internal/nodeChildProcessSpawner.js +1 -0
  311. package/dist/vendor/cjs/node-shared/internal/utils.d.ts +2 -0
  312. package/dist/vendor/cjs/node-shared/internal/utils.js +1 -0
  313. package/dist/vendor/cjs/package.json +1 -0
  314. package/dist/vendor/cjs/platform-node-shared.d.ts +56 -0
  315. package/dist/vendor/cjs/platform-node-shared.js +1 -0
  316. package/dist/vendor/cjs/platform-node.d.ts +100 -0
  317. package/dist/vendor/cjs/platform-node.js +1 -0
  318. package/dist/vendor/node/LICENSE +21 -0
  319. package/dist/vendor/node/NodeChildProcessSpawner.d.ts +7 -0
  320. package/dist/vendor/node/NodeChildProcessSpawner.js +14 -0
  321. package/dist/vendor/node/NodeClusterHttp.d.ts +63 -0
  322. package/dist/vendor/node/NodeClusterHttp.js +43 -0
  323. package/dist/vendor/node/NodeClusterSocket.d.ts +79 -0
  324. package/dist/vendor/node/NodeClusterSocket.js +30 -0
  325. package/dist/vendor/node/NodeCrypto.d.ts +10 -0
  326. package/dist/vendor/node/NodeCrypto.js +8 -0
  327. package/dist/vendor/node/NodeFileSystem.d.ts +10 -0
  328. package/dist/vendor/node/NodeFileSystem.js +9 -0
  329. package/dist/vendor/node/NodeHttpClient.d.ts +179 -0
  330. package/dist/vendor/node/NodeHttpClient.js +46 -0
  331. package/dist/vendor/node/NodeHttpIncomingMessage.d.ts +62 -0
  332. package/dist/vendor/node/NodeHttpIncomingMessage.js +10 -0
  333. package/dist/vendor/node/NodeHttpPlatform.d.ts +36 -0
  334. package/dist/vendor/node/NodeHttpPlatform.js +16 -0
  335. package/dist/vendor/node/NodeHttpServer.d.ts +120 -0
  336. package/dist/vendor/node/NodeHttpServer.js +46 -0
  337. package/dist/vendor/node/NodeHttpServerRequest.d.ts +29 -0
  338. package/dist/vendor/node/NodeHttpServerRequest.js +9 -0
  339. package/dist/vendor/node/NodeMultipart.d.ts +46 -0
  340. package/dist/vendor/node/NodeMultipart.js +15 -0
  341. package/dist/vendor/node/NodeMultipartParser.d.ts +97 -0
  342. package/dist/vendor/node/NodeMultipartParser.js +11 -0
  343. package/dist/vendor/node/NodePath.d.ts +27 -0
  344. package/dist/vendor/node/NodePath.js +12 -0
  345. package/dist/vendor/node/NodeRedis.d.ts +74 -0
  346. package/dist/vendor/node/NodeRedis.js +11 -0
  347. package/dist/vendor/node/NodeRuntime.d.ts +85 -0
  348. package/dist/vendor/node/NodeRuntime.js +8 -0
  349. package/dist/vendor/node/NodeServices.d.ts +34 -0
  350. package/dist/vendor/node/NodeServices.js +23 -0
  351. package/dist/vendor/node/NodeSink.d.ts +8 -0
  352. package/dist/vendor/node/NodeSink.js +12 -0
  353. package/dist/vendor/node/NodeSocket.d.ts +38 -0
  354. package/dist/vendor/node/NodeSocket.js +31 -0
  355. package/dist/vendor/node/NodeSocketServer.d.ts +8 -0
  356. package/dist/vendor/node/NodeSocketServer.js +21 -0
  357. package/dist/vendor/node/NodeStdio.d.ts +11 -0
  358. package/dist/vendor/node/NodeStdio.js +10 -0
  359. package/dist/vendor/node/NodeStream.d.ts +8 -0
  360. package/dist/vendor/node/NodeStream.js +27 -0
  361. package/dist/vendor/node/NodeTerminal.d.ts +21 -0
  362. package/dist/vendor/node/NodeTerminal.js +10 -0
  363. package/dist/vendor/node/NodeWorker.d.ts +22 -0
  364. package/dist/vendor/node/NodeWorker.js +9 -0
  365. package/dist/vendor/node/NodeWorkerRunner.d.ts +12 -0
  366. package/dist/vendor/node/NodeWorkerRunner.js +7 -0
  367. package/dist/vendor/node/Undici.d.ts +28 -0
  368. package/dist/vendor/node/Undici.js +9 -0
  369. package/dist/vendor/node/index.d.ts +100 -0
  370. package/dist/vendor/node/index.js +115 -0
  371. package/dist/vendor/node-shared/LICENSE +21 -0
  372. package/dist/vendor/node-shared/NodeChildProcessSpawner.d.ts +57 -0
  373. package/dist/vendor/node-shared/NodeChildProcessSpawner.js +13 -0
  374. package/dist/vendor/node-shared/NodeClusterSocket.d.ts +22 -0
  375. package/dist/vendor/node-shared/NodeClusterSocket.js +11 -0
  376. package/dist/vendor/node-shared/NodeCrypto.d.ts +27 -0
  377. package/dist/vendor/node-shared/NodeCrypto.js +9 -0
  378. package/dist/vendor/node-shared/NodeFileSystem.d.ts +11 -0
  379. package/dist/vendor/node-shared/NodeFileSystem.js +8 -0
  380. package/dist/vendor/node-shared/NodeHttpCompression.d.ts +36 -0
  381. package/dist/vendor/node-shared/NodeHttpCompression.js +13 -0
  382. package/dist/vendor/node-shared/NodePath.d.ts +27 -0
  383. package/dist/vendor/node-shared/NodePath.js +11 -0
  384. package/dist/vendor/node-shared/NodeRuntime.d.ts +47 -0
  385. package/dist/vendor/node-shared/NodeRuntime.js +7 -0
  386. package/dist/vendor/node-shared/NodeSink.d.ts +69 -0
  387. package/dist/vendor/node-shared/NodeSink.js +11 -0
  388. package/dist/vendor/node-shared/NodeSocket.d.ts +134 -0
  389. package/dist/vendor/node-shared/NodeSocket.js +23 -0
  390. package/dist/vendor/node-shared/NodeSocketServer.d.ts +80 -0
  391. package/dist/vendor/node-shared/NodeSocketServer.js +20 -0
  392. package/dist/vendor/node-shared/NodeStdio.d.ts +12 -0
  393. package/dist/vendor/node-shared/NodeStdio.js +9 -0
  394. package/dist/vendor/node-shared/NodeStream.d.ts +179 -0
  395. package/dist/vendor/node-shared/NodeStream.js +26 -0
  396. package/dist/vendor/node-shared/NodeTerminal.d.ts +22 -0
  397. package/dist/vendor/node-shared/NodeTerminal.js +9 -0
  398. package/dist/vendor/node-shared/index.d.ts +56 -0
  399. package/dist/vendor/node-shared/index.js +58 -0
  400. package/dist/vendor/node-shared/internal/nodeChildProcessSpawner.d.ts +4 -0
  401. package/dist/vendor/node-shared/internal/nodeChildProcessSpawner.js +7 -0
  402. package/dist/vendor/node-shared/internal/utils.d.ts +2 -0
  403. package/dist/vendor/node-shared/internal/utils.js +7 -0
  404. package/dist/vendor/platform-node-shared.d.ts +56 -0
  405. package/dist/vendor/platform-node-shared.js +58 -0
  406. package/dist/vendor/platform-node.d.ts +100 -0
  407. package/dist/vendor/platform-node.js +115 -0
  408. package/docs/README.md +129 -0
  409. package/docs/api.md +553 -0
  410. package/docs/concepts/descriptor-relative-filesystem.md +181 -0
  411. package/docs/concepts/host-bundle.md +125 -0
  412. package/docs/concepts/process-containment.md +190 -0
  413. package/docs/guides/answer-run-ownership.md +87 -0
  414. package/docs/guides/configure-the-filesystem-helper.md +152 -0
  415. package/docs/guides/contain-child-processes.md +139 -0
  416. package/docs/guides/match-files-with-glob.md +151 -0
  417. package/docs/installation.md +204 -0
  418. package/docs/quickstart.md +147 -0
  419. package/docs/troubleshooting.md +130 -0
  420. package/package.json +202 -3
  421. package/src/AtomicFileSystem.ts +415 -0
  422. package/src/EgressHttpClient.ts +327 -0
  423. package/src/HostLiveness.ts +103 -0
  424. package/src/NodeHost.ts +253 -0
  425. package/src/ProcessConfinement.ts +363 -0
  426. package/src/ProcessReaper.ts +951 -0
  427. package/src/ProcessSandbox.ts +1307 -0
  428. package/src/ScopedProcess.ts +124 -0
  429. package/src/index.ts +44 -0
  430. package/src/internal/AtomicFileSystemExecutable.ts +379 -0
  431. package/src/internal/AtomicFileSystemProtocol.ts +502 -0
  432. package/src/internal/AtomicFileSystemTransport.ts +272 -0
  433. package/src/internal/AtomicHelperError.ts +50 -0
  434. package/src/internal/AtomicHelperFault.ts +84 -0
  435. package/src/internal/PipedProcess.ts +357 -0
  436. package/src/internal/ProcSnapshot.ts +193 -0
  437. package/src/internal/ProcessCleanup.ts +99 -0
  438. package/src/internal/ProcessCleanupPolicyError.ts +30 -0
  439. package/src/internal/ProcessFault.ts +82 -0
  440. package/src/internal/ProcessSupervisor.ts +807 -0
  441. package/src/internal/SupervisorProgram.ts +309 -0
  442. package/src/internal/WindowsProcessJob.ts +114 -0
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var AtomicFileSystem_exports = {};
30
+ __export(AtomicFileSystem_exports, {
31
+ AtomicHelperError: () => import_AtomicHelperError2.AtomicHelperError,
32
+ AtomicHelperErrorCode: () => import_AtomicHelperError2.AtomicHelperErrorCode,
33
+ defaultConcurrency: () => defaultConcurrency,
34
+ defaultExecutable: () => defaultExecutable,
35
+ defaultLimits: () => defaultLimits,
36
+ defaultTimeoutMs: () => defaultTimeoutMs,
37
+ helperSpawns: () => helperSpawns,
38
+ layer: () => layer,
39
+ layerWith: () => layerWith,
40
+ resolveHelper: () => resolveHelper
41
+ });
42
+ module.exports = __toCommonJS(AtomicFileSystem_exports);
43
+ var NodeFileSystem = __toESM(require("../vendor/cjs/node/NodeFileSystem.js"), 1);
44
+ var KernelFileSystem = __toESM(require("@smthrs/kernel/FileSystem"), 1);
45
+ var import_effect = require("effect");
46
+ var import_promises = require("node:fs/promises");
47
+ var import_node_os = require("node:os");
48
+ var import_AtomicFileSystemExecutable = require("./internal/AtomicFileSystemExecutable.js");
49
+ var Protocol = __toESM(require("./internal/AtomicFileSystemProtocol.js"), 1);
50
+ var Transport = __toESM(require("./internal/AtomicFileSystemTransport.js"), 1);
51
+ var import_AtomicHelperError = require("./internal/AtomicHelperError.js");
52
+ var import_AtomicHelperError2 = require("./internal/AtomicHelperError.js");
53
+ const defaultExecutable = "/usr/local/bin/smithers-jj-export";
54
+ const defaultLimits = {
55
+ content: 16 * 1024 * 1024,
56
+ request: 24 * 1024 * 1024,
57
+ response: 24 * 1024 * 1024,
58
+ stderr: 64 * 1024,
59
+ batchSize: KernelFileSystem.maxBatchSize,
60
+ batchEntry: 24 * 1024 * 1024
61
+ };
62
+ const defaultConcurrency = (0, import_node_os.availableParallelism)();
63
+ const defaultTimeoutMs = 3e5;
64
+ const helperSpawns = () => Transport.started();
65
+ const hardLimitBytes = 256 * 1024 * 1024;
66
+ const maxTimeoutMs = 2147483647;
67
+ const resolveLimits = (overrides) => {
68
+ const limits = {
69
+ content: overrides?.content ?? defaultLimits.content,
70
+ request: overrides?.request ?? defaultLimits.request,
71
+ response: overrides?.response ?? defaultLimits.response,
72
+ stderr: overrides?.stderr ?? defaultLimits.stderr,
73
+ batchSize: overrides?.batchSize ?? defaultLimits.batchSize,
74
+ batchEntry: overrides?.batchEntry ?? defaultLimits.batchEntry
75
+ };
76
+ for (const [name, value] of Object.entries(limits)) {
77
+ if (!Number.isSafeInteger(value) || value <= 0 || value > hardLimitBytes) {
78
+ throw new import_AtomicHelperError.AtomicHelperError({
79
+ code: "limit_invalid",
80
+ message: `atomic helper ${name} limit must be a positive integer no greater than ${hardLimitBytes}`
81
+ });
82
+ }
83
+ }
84
+ if (limits.batchSize > KernelFileSystem.maxBatchSize) {
85
+ throw new import_AtomicHelperError.AtomicHelperError({
86
+ code: "limit_invalid",
87
+ message: `atomic helper batchSize limit must be no greater than ${KernelFileSystem.maxBatchSize}`
88
+ });
89
+ }
90
+ return limits;
91
+ };
92
+ const resolveSettings = (options) => {
93
+ try {
94
+ const limits = resolveLimits(options.limits);
95
+ const concurrency = options.concurrency ?? defaultConcurrency;
96
+ if (!Number.isSafeInteger(concurrency) || concurrency <= 0) {
97
+ throw new import_AtomicHelperError.AtomicHelperError({
98
+ code: "concurrency_invalid",
99
+ message: "atomic helper concurrency must be a positive integer"
100
+ });
101
+ }
102
+ const timeoutMs = options.timeoutMs ?? defaultTimeoutMs;
103
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > maxTimeoutMs) {
104
+ throw new import_AtomicHelperError.AtomicHelperError({
105
+ code: "timeout_invalid",
106
+ message: "atomic helper timeoutMs must be a positive integer no greater than 2147483647"
107
+ });
108
+ }
109
+ return { limits, timeoutMs, semaphore: import_effect.Semaphore.makeUnsafe(concurrency) };
110
+ } catch (invalid) {
111
+ return { invalid };
112
+ }
113
+ };
114
+ const executeFramed = (options, resolved) => (request) => import_effect.Effect.suspend(() => {
115
+ if ("invalid" in resolved) {
116
+ const cause = resolved.invalid;
117
+ return import_effect.Effect.fail(import_effect.PlatformError.badArgument({
118
+ module: Protocol.moduleName,
119
+ method: request.operation,
120
+ description: cause instanceof Error ? cause.message : "atomic helper limits are invalid",
121
+ cause
122
+ }));
123
+ }
124
+ const limits = resolved.limits;
125
+ if (request.operation === "batch" && (!Array.isArray(request.requests) || request.requests.length === 0 || request.requests.length > limits.batchSize)) {
126
+ return import_effect.Effect.fail(import_effect.PlatformError.badArgument({
127
+ module: Protocol.moduleName,
128
+ method: "batch",
129
+ description: `atomic batch must contain 1 to ${limits.batchSize} operations`
130
+ }));
131
+ }
132
+ return resolved.semaphore.withPermits(1)(import_effect.Effect.suspend(() => {
133
+ let body;
134
+ try {
135
+ const serialized = JSON.stringify(
136
+ request.operation === "batch" ? { ...request, batchSize: limits.batchSize, batchEntry: limits.batchEntry } : request
137
+ );
138
+ if (serialized === void 0) {
139
+ throw new import_AtomicHelperError.AtomicHelperError({
140
+ code: "request_not_serializable",
141
+ message: "atomic request is not serializable"
142
+ });
143
+ }
144
+ body = Buffer.from(serialized, "utf8");
145
+ } catch (cause) {
146
+ return import_effect.Effect.fail(import_effect.PlatformError.badArgument({
147
+ module: Protocol.moduleName,
148
+ method: request.operation,
149
+ description: "atomic request is not serializable",
150
+ cause
151
+ }));
152
+ }
153
+ if (body.byteLength > limits.request) {
154
+ return import_effect.Effect.fail(import_effect.PlatformError.badArgument({
155
+ module: Protocol.moduleName,
156
+ method: request.operation,
157
+ description: `atomic request of ${body.byteLength} bytes exceeds the ${limits.request} byte limit`
158
+ }));
159
+ }
160
+ let executable;
161
+ try {
162
+ executable = resolveExecutable(options, request.boundaryRoot);
163
+ } catch (cause) {
164
+ return import_effect.Effect.fail(Protocol.failure(request, cause));
165
+ }
166
+ return Transport.spawnHelper(request, executable, Protocol.encode(body, limits), resolved);
167
+ }));
168
+ });
169
+ const resolveExecutable = (options, boundaryRoot) => {
170
+ const configured = process.env.SMITHERS_WORKSPACE_JJ_EXPORT_BINARY;
171
+ return options.executable !== void 0 ? Transport.usableExecutable(options.executable, boundaryRoot) : configured === void 0 ? (0, import_AtomicFileSystemExecutable.resolveDefaultExecutable)(import_AtomicFileSystemExecutable.packageRoot, boundaryRoot, defaultExecutable) : (0, import_AtomicFileSystemExecutable.resolveConfiguredExecutable)(configured, boundaryRoot);
172
+ };
173
+ const resolveHelper = () => resolveExecutable({}, void 0);
174
+ const execute = (options, resolved) => {
175
+ const framed = executeFramed(options, resolved);
176
+ return (request) => framed(request);
177
+ };
178
+ const nativeRealPath = (path) => import_effect.Effect.tryPromise({
179
+ try: () => (0, import_promises.realpath)(path),
180
+ catch: (cause) => Protocol.failure({ operation: "realPath", path }, cause, {
181
+ ok: false,
182
+ code: cause.code ?? null,
183
+ message: cause.message,
184
+ syscall: "realpath"
185
+ })
186
+ });
187
+ const layerWith = (options) => {
188
+ const settings = resolveSettings(options);
189
+ return import_effect.Layer.effect(
190
+ import_effect.FileSystem.FileSystem,
191
+ import_effect.Effect.map(
192
+ // The packaged helper is pinned while the host is built, before any flow
193
+ // can rewrite a workspace-local install of this package.
194
+ import_effect.Effect.andThen(
195
+ import_effect.Effect.sync(() => {
196
+ if (options.executable === void 0 && process.env.SMITHERS_WORKSPACE_JJ_EXPORT_BINARY === void 0) {
197
+ (0, import_AtomicFileSystemExecutable.stagePackaged)(import_AtomicFileSystemExecutable.packageRoot);
198
+ }
199
+ }),
200
+ import_effect.FileSystem.FileSystem
201
+ ),
202
+ (fileSystem) => KernelFileSystem.withAtomicFileSystem({
203
+ ...fileSystem,
204
+ // Expand DOS names before pinning roots or opening native watchers.
205
+ realPath: nativeRealPath,
206
+ watch: (path, options2) => process.platform !== "win32" ? fileSystem.watch(path, options2) : import_effect.Stream.unwrap(
207
+ nativeRealPath(path).pipe(import_effect.Effect.map((canonical) => fileSystem.watch(canonical, options2)))
208
+ )
209
+ }, {
210
+ noFollowAuthorization: true,
211
+ execute: execute(options, settings),
212
+ identifyRoot: (path) => import_effect.Effect.tryPromise({
213
+ try: async () => {
214
+ const info = await (0, import_promises.stat)(path, { bigint: true });
215
+ return `${info.dev}:${info.ino}`;
216
+ },
217
+ catch: (cause) => Protocol.failure({ operation: "stat", path }, cause, {
218
+ ok: false,
219
+ code: cause.code ?? null,
220
+ message: cause.message,
221
+ syscall: "stat"
222
+ })
223
+ }),
224
+ batchLimits: {
225
+ size: "invalid" in settings ? defaultLimits.batchSize : settings.limits.batchSize,
226
+ response: "invalid" in settings ? defaultLimits.response : settings.limits.response
227
+ },
228
+ contentLimit: "invalid" in settings ? defaultLimits.content : settings.limits.content
229
+ })
230
+ )
231
+ ).pipe(import_effect.Layer.provide(NodeFileSystem.layer));
232
+ };
233
+ const layer = layerWith({});
234
+ //# sourceMappingURL=AtomicFileSystem.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/AtomicFileSystem.ts"],
4
+ "sourcesContent": ["/**\n * Descriptor-relative filesystem operations through the packaged Rust helper.\n * The helper pins the workspace root and walks each component with O_NOFOLLOW.\n * Requests and responses are length-framed, size-limited, and cancellable.\n * @since 0.1.0\n */\n\nimport * as NodeFileSystem from \"@effect/platform-node/NodeFileSystem\"\nimport * as KernelFileSystem from \"@smthrs/kernel/FileSystem\"\nimport { Effect, FileSystem, Layer, PlatformError, Semaphore, Stream } from \"effect\"\nimport { realpath, stat } from \"node:fs/promises\"\nimport { availableParallelism } from \"node:os\"\nimport {\n packageRoot,\n resolveConfiguredExecutable,\n resolveDefaultExecutable,\n stagePackaged\n} from \"./internal/AtomicFileSystemExecutable.ts\"\nimport * as Protocol from \"./internal/AtomicFileSystemProtocol.ts\"\nimport * as Transport from \"./internal/AtomicFileSystemTransport.ts\"\nimport { AtomicHelperError } from \"./internal/AtomicHelperError.ts\"\n\nexport { AtomicHelperError, AtomicHelperErrorCode } from \"./internal/AtomicHelperError.ts\"\n\n/**\n * The legacy system installation path, used after package and checkout paths.\n * Helper selection never consults `PATH` or the process working directory.\n *\n * @since 0.1.0\n * @category constants\n */\nexport const defaultExecutable = \"/usr/local/bin/smithers-jj-export\"\n\n/**\n * Byte ceilings for the helper protocol. Every one of them is a contract, not\n * a tuning knob: without them a large file, a large directory tree, or a\n * malfunctioning helper makes the host allocate until it dies.\n *\n * - `content` bounds the bytes a single `readFile`/`writeFile` may carry.\n * - `request` bounds the framed request; an over-limit request is refused\n * before an helper is even started.\n * - `response` bounds the framed response, and is what a directory listing is\n * charged against as it is built. It bounds the REJECTION envelope too, so a\n * ceiling small enough to cut one off degrades that operation's typed reason\n * to the fail-closed one.\n * - `stderr` bounds the diagnostic text retained from a failing helper.\n * - `batchEntry` bounds one batch member's encoded success or failure envelope.\n * - `batchSize` bounds the number of operations in one batch, at most 128.\n *\n * All except `batchSize` count bytes. The two ceilings that decide whether the host\n * survives a wide fan-out are {@link Options.concurrency}, which bounds how\n * many helpers run at once, and {@link Options.timeoutMs}, which bounds\n * how long any one of them may take.\n *\n * @since 0.1.0\n * @category models\n */\nexport interface Limits {\n readonly content: number\n readonly request: number\n readonly response: number\n readonly stderr: number\n /** Maximum operations in one helper invocation, at most 128. */\n readonly batchSize: number\n /** Maximum encoded result bytes for one batch member. */\n readonly batchEntry: number\n}\n\n/**\n * 16 MiB of file content, 24 MiB of framed request and response (base64\n * expands 16 MiB to 22369624 bytes, which has to fit), and 64 KiB of retained\n * helper diagnostics.\n *\n * @since 0.1.0\n * @category constants\n */\nexport const defaultLimits: Limits = {\n content: 16 * 1024 * 1024,\n request: 24 * 1024 * 1024,\n response: 24 * 1024 * 1024,\n stderr: 64 * 1024,\n batchSize: KernelFileSystem.maxBatchSize,\n batchEntry: 24 * 1024 * 1024\n}\n\n/**\n * The default number of helper processes that may run at once:\n * `os.availableParallelism()`.\n *\n * @since 1.0.0-rc.0\n * @category constants\n */\nexport const defaultConcurrency: number = availableParallelism()\n\n/**\n * How long one helper may run before it is killed and the operation fails\n * closed: five minutes.\n *\n * It is a backstop, not a latency budget. A read at the content ceiling over a\n * slow disk has to fit under it, so it is generous; what it bounds is a helper\n * that will never answer at all.\n *\n * @since 1.0.0-rc.0\n * @category constants\n */\nexport const defaultTimeoutMs = 300_000\n\n/**\n * The deliberate seam for a POSIX host that installs the native helper somewhere other\n * than {@link defaultExecutable}, or that needs different ceilings. It is\n * configuration, never discovery: the executable is validated as an absolute,\n * executable regular file outside the confined workspace on every request, and\n * every other field is read ONCE, when the layer is built.\n *\n * @since 0.1.0\n * @category models\n */\nexport interface Options {\n readonly executable?: string | undefined\n readonly limits?: Partial<Limits> | undefined\n /**\n * How many helper processes may run at once. Default\n * {@link defaultConcurrency}.\n *\n * Each ordinary operation or batch starts one helper, so an unbounded\n * `Effect.forEach` over a directory would start\n * one helper per entry. This ceiling is what keeps a wide fan-out from\n * pinning every core; it is a contract, not a tuning knob.\n */\n readonly concurrency?: number | undefined\n /**\n * How long one helper may run before it is killed and the operation fails\n * closed, in milliseconds. Default {@link defaultTimeoutMs}.\n */\n readonly timeoutMs?: number | undefined\n}\n\n/**\n * Everything read out of {@link Options} once, when the layer is built.\n *\n * Snapshotted rather than re-read per request: `Options` is a plain object the\n * caller still holds, and a byte ceiling that changes under a running host is\n * not a ceiling. The executable is deliberately NOT here \u2014 it is re-validated\n * per request, because the file it names can be replaced while the host runs.\n */\ninterface Settings {\n readonly limits: Limits\n readonly timeoutMs: number\n readonly semaphore: Semaphore.Semaphore\n}\n\n/**\n * Process-local helper starts, for cost counters and local measurements.\n * Includes helpers later cancelled or refused; rejected preflight starts none.\n *\n * @since 1.0.0\n * @category metrics\n */\nexport const helperSpawns = (): number => Transport.started()\n\n/** The helper enforces the same ceiling before it trusts a declared limit. */\nconst hardLimitBytes = 256 * 1024 * 1024\n/** `setTimeout` clamps a longer delay to 1 ms, so a bigger backstop is none. */\nconst maxTimeoutMs = 2_147_483_647\n\n/** Resolves every optional byte ceiling and refuses values that could disable a bound. */\nconst resolveLimits = (overrides: Partial<Limits> | undefined): Limits => {\n const limits: Limits = {\n content: overrides?.content ?? defaultLimits.content,\n request: overrides?.request ?? defaultLimits.request,\n response: overrides?.response ?? defaultLimits.response,\n stderr: overrides?.stderr ?? defaultLimits.stderr,\n batchSize: overrides?.batchSize ?? defaultLimits.batchSize,\n batchEntry: overrides?.batchEntry ?? defaultLimits.batchEntry\n }\n for (const [name, value] of Object.entries(limits)) {\n if (!Number.isSafeInteger(value) || value <= 0 || value > hardLimitBytes) {\n throw new AtomicHelperError({\n code: \"limit_invalid\",\n message: `atomic helper ${name} limit must be a positive integer no greater than ${hardLimitBytes}`\n })\n }\n }\n if (limits.batchSize > KernelFileSystem.maxBatchSize) {\n throw new AtomicHelperError({\n code: \"limit_invalid\",\n message: `atomic helper batchSize limit must be no greater than ${KernelFileSystem.maxBatchSize}`\n })\n }\n return limits\n}\n\n/**\n * Reads the whole of {@link Options} once, at layer construction.\n *\n * A rejected value is carried rather than thrown, because the failure a caller\n * sees for it is a typed `BadArgument` on the first operation and not an\n * exception escaping a layer.\n */\nconst resolveSettings = (options: Options): Settings | { readonly invalid: unknown } => {\n try {\n const limits = resolveLimits(options.limits)\n const concurrency = options.concurrency ?? defaultConcurrency\n if (!Number.isSafeInteger(concurrency) || concurrency <= 0) {\n throw new AtomicHelperError({\n code: \"concurrency_invalid\",\n message: \"atomic helper concurrency must be a positive integer\"\n })\n }\n const timeoutMs = options.timeoutMs ?? defaultTimeoutMs\n if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > maxTimeoutMs) {\n throw new AtomicHelperError({\n code: \"timeout_invalid\",\n message: \"atomic helper timeoutMs must be a positive integer no greater than 2147483647\"\n })\n }\n return { limits, timeoutMs, semaphore: Semaphore.makeUnsafe(concurrency) }\n } catch (invalid) {\n return { invalid }\n }\n}\n\n/**\n * The framed half, one concrete result type. Nothing on this side of the pipe\n * can prove what the helper answered: the protocol pairs an operation with its\n * result, and {@link execute} restates that pairing for the kernel's typed\n * request. Keeping the decode `unknown` here confines that promise to one\n * assertion instead of one per caller.\n */\nconst executeFramed = (options: Options, resolved: Settings | { readonly invalid: unknown }) =>\n(\n request: KernelFileSystem.AtomicRequest\n): Effect.Effect<unknown, PlatformError.PlatformError> =>\n Effect.suspend(() => {\n if (\"invalid\" in resolved) {\n const cause = resolved.invalid\n return Effect.fail(PlatformError.badArgument({\n module: Protocol.moduleName,\n method: request.operation,\n description: cause instanceof Error ? cause.message : \"atomic helper limits are invalid\",\n cause\n }))\n }\n const limits = resolved.limits\n if (\n request.operation === \"batch\" &&\n (!Array.isArray(request.requests) || request.requests.length === 0 || request.requests.length > limits.batchSize)\n ) {\n return Effect.fail(PlatformError.badArgument({\n module: Protocol.moduleName,\n method: \"batch\",\n description: `atomic batch must contain 1 to ${limits.batchSize} operations`\n }))\n }\n // Admission bounds request serialization and framing as well as children.\n // Queued callers retain their input, without another full payload copy.\n return resolved.semaphore.withPermits(1)(Effect.suspend(() => {\n let body: Buffer\n try {\n const serialized = JSON.stringify(\n request.operation === \"batch\"\n ? { ...request, batchSize: limits.batchSize, batchEntry: limits.batchEntry }\n : request\n )\n if (serialized === undefined) {\n throw new AtomicHelperError({\n code: \"request_not_serializable\",\n message: \"atomic request is not serializable\"\n })\n }\n body = Buffer.from(serialized, \"utf8\")\n } catch (cause) {\n return Effect.fail(PlatformError.badArgument({\n module: Protocol.moduleName,\n method: request.operation,\n description: \"atomic request is not serializable\",\n cause\n }))\n }\n if (body.byteLength > limits.request) {\n // Refused before an helper exists: an over-limit request is caller\n // input, and nothing about it improves by being sent.\n return Effect.fail(PlatformError.badArgument({\n module: Protocol.moduleName,\n method: request.operation,\n description: `atomic request of ${body.byteLength} bytes exceeds the ${limits.request} byte limit`\n }))\n }\n let executable: string\n try {\n executable = resolveExecutable(options, request.boundaryRoot)\n } catch (cause) {\n return Effect.fail(Protocol.failure(request, cause))\n }\n return Transport.spawnHelper<unknown>(request, executable, Protocol.encode(body, limits), resolved)\n }))\n })\n\nconst resolveExecutable = (options: Pick<Options, \"executable\">, boundaryRoot: string | undefined): string => {\n const configured = process.env.SMITHERS_WORKSPACE_JJ_EXPORT_BINARY\n return options.executable !== undefined\n ? Transport.usableExecutable(options.executable, boundaryRoot)\n : configured === undefined\n ? resolveDefaultExecutable(packageRoot, boundaryRoot, defaultExecutable)\n : resolveConfiguredExecutable(configured, boundaryRoot)\n}\n\n/**\n * The helper this process would start for an atomic operation, resolved exactly\n * as an operation resolves it: `SMITHERS_WORKSPACE_JJ_EXPORT_BINARY`, then the\n * packaged and checkout locations. Nothing is spawned. Throws an {@link AtomicHelperError} whose\n * message names what was searched and how to install the helper when none is\n * usable, so a diagnostic can report it before any operation needs it.\n *\n * @since 1.0.0\n * @category constructors\n */\nexport const resolveHelper = (): string => resolveExecutable({}, undefined)\n\nconst execute = (\n options: Options,\n resolved: Settings | { readonly invalid: unknown }\n): KernelFileSystem.AtomicFileSystem[\"execute\"] => {\n const framed = executeFramed(options, resolved)\n return <R extends KernelFileSystem.AtomicRequest>(request: R) =>\n framed(request) as Effect.Effect<KernelFileSystem.AtomicResult<R>, PlatformError.PlatformError>\n}\n\nconst nativeRealPath = (path: string) =>\n Effect.tryPromise({\n try: () => realpath(path),\n catch: (cause) =>\n Protocol.failure({ operation: \"realPath\", path }, cause, {\n ok: false,\n code: (cause as NodeJS.ErrnoException).code ?? null,\n message: (cause as NodeJS.ErrnoException).message,\n syscall: \"realpath\"\n })\n })\n\n/**\n * A Node filesystem layer carrying the kernel's atomic host extension, built\n * against an explicitly configured helper, byte limits, process ceiling,\n * and helper timeout.\n *\n * Every field of {@link Options} except `executable` is read once, here. The\n * concurrency ceiling is one semaphore for the whole layer rather than one per\n * request, which is the only arrangement that bounds anything.\n *\n * @since 0.1.0\n * @category layers\n */\nexport const layerWith = (options: Options): Layer.Layer<FileSystem.FileSystem> => {\n // Outside the layer body on purpose. Inside it the settings would be read\n // again on every BUILD, so two compositions of the same layer value could\n // enforce two different ceilings out of one mutated object, and each would\n // get a process ceiling of its own instead of sharing one.\n const settings = resolveSettings(options)\n return Layer.effect(\n FileSystem.FileSystem,\n Effect.map(\n // The packaged helper is pinned while the host is built, before any flow\n // can rewrite a workspace-local install of this package.\n Effect.andThen(\n Effect.sync(() => {\n if (options.executable === undefined && process.env.SMITHERS_WORKSPACE_JJ_EXPORT_BINARY === undefined) {\n stagePackaged(packageRoot)\n }\n }),\n FileSystem.FileSystem\n ),\n (fileSystem) =>\n KernelFileSystem.withAtomicFileSystem({\n ...fileSystem,\n // Expand DOS names before pinning roots or opening native watchers.\n realPath: nativeRealPath,\n watch: (path, options) =>\n process.platform !== \"win32\"\n ? fileSystem.watch(path, options)\n : Stream.unwrap(\n nativeRealPath(path).pipe(Effect.map((canonical) => fileSystem.watch(canonical, options)))\n )\n }, {\n noFollowAuthorization: true,\n execute: execute(options, settings),\n identifyRoot: (path) =>\n Effect.tryPromise({\n try: async () => {\n const info = await stat(path, { bigint: true })\n return `${info.dev}:${info.ino}`\n },\n catch: (cause) =>\n Protocol.failure({ operation: \"stat\", path }, cause, {\n ok: false,\n code: (cause as NodeJS.ErrnoException).code ?? null,\n message: (cause as NodeJS.ErrnoException).message,\n syscall: \"stat\"\n })\n }),\n batchLimits: {\n size: \"invalid\" in settings ? defaultLimits.batchSize : settings.limits.batchSize,\n response: \"invalid\" in settings ? defaultLimits.response : settings.limits.response\n },\n contentLimit: \"invalid\" in settings ? defaultLimits.content : settings.limits.content\n })\n )\n ).pipe(Layer.provide(NodeFileSystem.layer))\n}\n\n/** A Node filesystem layer carrying the kernel's atomic host extension.\n *\n * @since 0.1.0\n * @category layers\n */\nexport const layer: Layer.Layer<FileSystem.FileSystem> = layerWith({})\n"],
5
+ "mappings": "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",
6
+ "names": ["import_AtomicHelperError", "options"]
7
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * The outbound HTTP client a Node process should use, read off its environment.
3
+ *
4
+ * `@effect/platform-node` ships `NodeHttpClient.layerUndici`, and its
5
+ * dispatcher is a bare Undici `Agent`. A bare `Agent` dials every origin
6
+ * directly: it does not read `HTTP_PROXY`, `HTTPS_PROXY` or `NO_PROXY`, and
7
+ * nothing at the call site says so. That is invisible on a developer machine
8
+ * with open egress and fatal inside a sandbox whose egress is default-deny
9
+ * behind a named proxy — the request leaves for the origin, the firewall drops
10
+ * it, and the only symptom is a transport failure far from the composition
11
+ * that chose the client.
12
+ *
13
+ * This module is the one place that decision is made. {@link layer} is the
14
+ * client every Node host composition installs; it honours the proxy the
15
+ * environment names. Requests without a web destination use a shared pool;
16
+ * web requests receive a fresh pinned dispatcher.
17
+ *
18
+ * The rule for loopback is fixed here, not by the environment: `localhost`,
19
+ * `127.0.0.1` and `[::1]` are always reached directly, even when the
20
+ * environment names a proxy and no exclusion, and every other origin follows
21
+ * `NO_PROXY`. A proxy is how a process leaves its machine, and
22
+ * `--remote http://127.0.0.1:3000` is not leaving it. The exemption is those
23
+ * three names and nothing wider: Undici matches `NO_PROXY` entries by name,
24
+ * never by resolved address, so `127.0.0.2` or a hostname that resolves to
25
+ * loopback is an origin like any other and goes through the proxy.
26
+ *
27
+ * @since 1.0.0-rc.0
28
+ */
29
+ import type * as Undici from "../vendor/cjs/node/Undici.js";
30
+ import { GrantStore } from "@smthrs/kernel/GrantStore";
31
+ import * as Effect from "effect/Effect";
32
+ import * as Layer from "effect/Layer";
33
+ import * as Schema from "effect/Schema";
34
+ import * as Scope from "effect/Scope";
35
+ import { HttpClient } from "effect/unstable/http/HttpClient";
36
+ declare const EgressAddressError_base: Schema.Class<EgressAddressError, Schema.TaggedStruct<"@smthrs/platform-node/EgressAddressError", {
37
+ readonly code: Schema.Literal<"no_approved_address">;
38
+ readonly message: Schema.String;
39
+ }>, import("effect/Cause").YieldableError>;
40
+ /**
41
+ * A pinned connection asked for an address family none of the authorized
42
+ * addresses has. It is the `cause` of the `TransportError` the request fails
43
+ * with; `code` is always `no_approved_address`.
44
+ *
45
+ * @category errors
46
+ * @since 1.0.0
47
+ */
48
+ export declare class EgressAddressError extends EgressAddressError_base {
49
+ readonly name = "EgressAddressError";
50
+ }
51
+ /**
52
+ * An Undici dispatcher that routes through the egress proxy the supplied
53
+ * environment names, or a direct one when it names none.
54
+ *
55
+ * The proxy variables are read in the order Undici itself reads them,
56
+ * lowercase first, and passed explicitly rather than left to
57
+ * `EnvHttpProxyAgent`'s own ambient lookup: a host serving a guest's
58
+ * environment is not the guest, and the pool has to follow the record it was
59
+ * handed. Loopback is always direct; see {@link exclusions}. Each dispatcher is
60
+ * acquired in the caller's scope and destroyed with it, so a composition that
61
+ * builds several still owns every pool it opened.
62
+ *
63
+ * @param environment the environment record whose proxy variables decide the route
64
+ * @category constructors
65
+ * @since 1.0.0-rc.0
66
+ */
67
+ export declare const dispatcher: (environment: Readonly<Record<string, string | undefined>>) => Effect.Effect<Undici.Dispatcher, never, Scope.Scope>;
68
+ /**
69
+ * The Undici `HttpClient` to install, given the environment the process runs in.
70
+ *
71
+ * Use this wherever `NodeHttpClient.layerUndici` would otherwise be provided
72
+ * under a layer that takes `HttpClient` from context — a model transport, a
73
+ * judge, a fetch rule, a host bundle. The two differ only in whether the pool
74
+ * honours `HTTP_PROXY`/`HTTPS_PROXY`/`NO_PROXY`, which is the difference
75
+ * between a request that reaches the gateway from inside a default-deny
76
+ * sandbox and one the firewall drops.
77
+ *
78
+ * @param environment the environment record whose proxy variables decide the route
79
+ * @category layers
80
+ * @since 1.0.0-rc.0
81
+ */
82
+ export declare const layer: (environment: Readonly<Record<string, string | undefined>>) => Layer.Layer<HttpClient>;
83
+ /**
84
+ * Owns one replaceable Undici pool in the caller's scope. Each replacement
85
+ * receives the same middleware and closes the previous pool.
86
+ *
87
+ * @category constructors
88
+ * @since 1.0.0
89
+ */
90
+ export declare const rebuildableTransport: (acquire: Effect.Effect<Undici.Dispatcher, never, Scope.Scope>, decorate?: (client: HttpClient) => Effect.Effect<HttpClient>) => Effect.Effect<{
91
+ readonly client: HttpClient;
92
+ readonly rebuild: Effect.Effect<HttpClient>;
93
+ }, never, Scope.Scope>;
94
+ /**
95
+ * A model transport whose replacements retain the caller's grant store and
96
+ * environment proxy policy. Pass it to RequestExecutor.makeWith in the host scope.
97
+ *
98
+ * @category constructors
99
+ * @since 1.0.0
100
+ */
101
+ export declare const guardedTransport: (environment: Readonly<Record<string, string | undefined>>) => Effect.Effect<{
102
+ readonly client: HttpClient;
103
+ readonly rebuild: Effect.Effect<HttpClient>;
104
+ }, never, GrantStore | Scope.Scope>;
105
+ export {};
106
+ //# sourceMappingURL=EgressHttpClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EgressHttpClient.d.ts","sourceRoot":"","sources":["../../src/EgressHttpClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,OAAO,KAAK,KAAK,MAAM,MAAM,8BAA8B,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAGtD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;;;;;AAM5D;;;;;;;GAOG;AACH,qBAAa,kBAAmB,SAAQ,uBAGvC;IACC,SAAkB,IAAI,wBAAuB;CAC9C;AAoCD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,UAAU,GACrB,aAAa,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,KACxD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAsBlD,CAAA;AAEJ;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK,GAChB,aAAa,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,KACxD,KAAK,CAAC,KAAK,CAAC,UAAU,CAqHtB,CAAA;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC/B,SAAS,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,EAC7D,WAAU,CAAC,MAAM,EAAE,UAAU,KAAK,MAAM,CAAC,MAAM,CAAC,UAAU,CAAkB,KAC3E,MAAM,CAAC,MAAM,CACd;IACE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;CAC5C,EACD,KAAK,EACL,KAAK,CAAC,KAAK,CAqBT,CAAA;AAEJ;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAI,aAAa,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;qBAlCrE,UAAU;sBACT,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;mCAyC3C,CAAA"}
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var EgressHttpClient_exports = {};
30
+ __export(EgressHttpClient_exports, {
31
+ EgressAddressError: () => EgressAddressError,
32
+ dispatcher: () => dispatcher,
33
+ guardedTransport: () => guardedTransport,
34
+ layer: () => layer,
35
+ rebuildableTransport: () => rebuildableTransport
36
+ });
37
+ module.exports = __toCommonJS(EgressHttpClient_exports);
38
+ var NodeHttpClient = __toESM(require("../vendor/cjs/node/NodeHttpClient.js"), 1);
39
+ var import_GrantStore = require("@smthrs/kernel/GrantStore");
40
+ var KernelHttpClient = __toESM(require("@smthrs/kernel/HttpClient"), 1);
41
+ var import_HttpClient = require("@smthrs/kernel/HttpClient");
42
+ var Effect = __toESM(require("effect/Effect"), 1);
43
+ var Exit = __toESM(require("effect/Exit"), 1);
44
+ var Layer = __toESM(require("effect/Layer"), 1);
45
+ var Schema = __toESM(require("effect/Schema"), 1);
46
+ var Scope = __toESM(require("effect/Scope"), 1);
47
+ var Semaphore = __toESM(require("effect/Semaphore"), 1);
48
+ var import_HttpClient2 = require("effect/unstable/http/HttpClient");
49
+ var EffectHttpClient = __toESM(require("effect/unstable/http/HttpClient"), 1);
50
+ var HttpClientError = __toESM(require("effect/unstable/http/HttpClientError"), 1);
51
+ var HttpClientRequest = __toESM(require("effect/unstable/http/HttpClientRequest"), 1);
52
+ var import_node_net = require("node:net");
53
+ class EgressAddressError extends Schema.TaggedError()(
54
+ "@smthrs/platform-node/EgressAddressError",
55
+ { code: Schema.Literal("no_approved_address"), message: Schema.String }
56
+ ) {
57
+ name = "EgressAddressError";
58
+ }
59
+ const loopback = ["localhost", "127.0.0.1", "::1"];
60
+ const exclusions = (declared) => declared === "*" ? declared : [declared, ...loopback].filter((entry) => entry !== "").join(",");
61
+ const loadUndici = Effect.promise(
62
+ async () => (await import("undici/index.js")).default
63
+ );
64
+ const dispatcher = (environment) => Effect.suspend(() => {
65
+ const httpProxy = environment.http_proxy ?? environment.HTTP_PROXY ?? "";
66
+ const httpsProxy = environment.https_proxy ?? environment.HTTPS_PROXY ?? "";
67
+ const noProxy = exclusions(environment.no_proxy ?? environment.NO_PROXY ?? "");
68
+ return Effect.acquireRelease(
69
+ Effect.map(
70
+ loadUndici,
71
+ (undici) => new undici.EnvHttpProxyAgent({ httpProxy, httpsProxy, noProxy })
72
+ ),
73
+ (dispatcher2) => Effect.promise(() => dispatcher2.destroy())
74
+ );
75
+ });
76
+ const layer = (environment) => Layer.effect(
77
+ import_HttpClient2.HttpClient,
78
+ Effect.gen(function* () {
79
+ const shared = yield* dispatcher(environment);
80
+ const ordinary = yield* NodeHttpClient.makeUndici.pipe(Effect.provideService(NodeHttpClient.Dispatcher, shared));
81
+ return (0, import_HttpClient.withDestinationPinning)(EffectHttpClient.transform(ordinary, (execute, request) => Effect.gen(function* () {
82
+ const destination = yield* import_HttpClient.Destination;
83
+ if (destination === void 0) return yield* execute;
84
+ const url = new URL(request.url);
85
+ if (url.origin !== destination.origin || destination.addresses.length === 0 || destination.addresses.some((address) => (0, import_node_net.isIP)(address) === 0)) {
86
+ return yield* Effect.fail(
87
+ new HttpClientError.HttpClientError({
88
+ reason: new HttpClientError.TransportError({
89
+ request,
90
+ description: "Invalid pinned HTTP destination"
91
+ })
92
+ })
93
+ );
94
+ }
95
+ const proxies = [
96
+ environment.http_proxy ?? environment.HTTP_PROXY,
97
+ environment.https_proxy ?? environment.HTTPS_PROXY
98
+ ];
99
+ const validProxies = proxies.every((proxy) => {
100
+ if (!proxy) return true;
101
+ try {
102
+ return ["http:", "https:"].includes(new URL(proxy).protocol);
103
+ } catch {
104
+ return false;
105
+ }
106
+ });
107
+ if (!validProxies) {
108
+ return yield* Effect.fail(
109
+ new HttpClientError.HttpClientError({
110
+ reason: new HttpClientError.TransportError({
111
+ request,
112
+ description: "Pinned HTTP requests require HTTP or HTTPS proxies"
113
+ })
114
+ })
115
+ );
116
+ }
117
+ const undici = yield* loadUndici;
118
+ const addresses = destination.addresses.map((address) => ({ address, family: (0, import_node_net.isIP)(address) }));
119
+ return yield* Effect.uninterruptibleMask((restore) => {
120
+ const pinned = new undici.EnvHttpProxyAgent({
121
+ httpProxy: environment.http_proxy ?? environment.HTTP_PROXY ?? "",
122
+ httpsProxy: environment.https_proxy ?? environment.HTTPS_PROXY ?? "",
123
+ noProxy: exclusions(environment.no_proxy ?? environment.NO_PROXY ?? ""),
124
+ // Tunnelling HTTP too prevents the proxy resolving the target hostname.
125
+ proxyTunnel: true,
126
+ connect: {
127
+ lookup: (_hostname, options, callback) => {
128
+ const candidates = options.family ? addresses.filter((item) => item.family === options.family) : addresses;
129
+ const first = candidates[0];
130
+ if (first === void 0) {
131
+ return callback(
132
+ new EgressAddressError({
133
+ code: "no_approved_address",
134
+ message: "No approved address for family"
135
+ }),
136
+ "",
137
+ 4
138
+ );
139
+ }
140
+ if (options.all) callback(null, candidates);
141
+ else callback(null, first.address, first.family);
142
+ }
143
+ },
144
+ clientFactory: (origin, options) => {
145
+ const proxy = new undici.Pool(origin, options);
146
+ const connect = proxy.connect.bind(proxy);
147
+ proxy.connect = (options2) => {
148
+ const address = addresses[0].address;
149
+ const host = (0, import_node_net.isIP)(address) === 6 ? `[${address}]` : address;
150
+ const authority = `${host}:${url.port || (url.protocol === "https:" ? "443" : "80")}`;
151
+ return connect({ ...options2, path: authority, headers: { ...options2.headers, host: authority } });
152
+ };
153
+ return proxy;
154
+ }
155
+ });
156
+ const pinnedRequest = request.pipe(
157
+ HttpClientRequest.setHeader("host", url.host),
158
+ HttpClientRequest.removeHeader("proxy-authorization"),
159
+ HttpClientRequest.removeHeader("connection"),
160
+ HttpClientRequest.removeHeader("transfer-encoding"),
161
+ HttpClientRequest.removeHeader("content-length")
162
+ );
163
+ return restore(NodeHttpClient.makeUndici.pipe(
164
+ Effect.provideService(NodeHttpClient.Dispatcher, pinned),
165
+ Effect.flatMap((client) => client.execute(pinnedRequest))
166
+ )).pipe(Effect.onExit(
167
+ (exit) => Exit.isFailure(exit) ? Effect.promise(() => pinned.destroy()) : Effect.sync(() => {
168
+ void pinned.close().catch(() => pinned.destroy());
169
+ })
170
+ ));
171
+ });
172
+ })));
173
+ })
174
+ );
175
+ const rebuildableTransport = (acquire, decorate = Effect.succeed) => Effect.gen(function* () {
176
+ const scope = yield* Scope.Scope;
177
+ const gate = yield* Semaphore.make(1);
178
+ let held = void 0;
179
+ const rebuild = gate.withPermit(Effect.uninterruptibleMask(
180
+ (restore) => Effect.gen(function* () {
181
+ const owned = yield* Scope.fork(scope);
182
+ const client = yield* restore(NodeHttpClient.makeUndici.pipe(
183
+ Effect.provideServiceEffect(NodeHttpClient.Dispatcher, acquire),
184
+ Effect.flatMap(decorate),
185
+ Effect.provideService(Scope.Scope, owned)
186
+ )).pipe(Effect.onExit((exit) => Exit.isSuccess(exit) ? Effect.void : Scope.close(owned, exit)));
187
+ const previous = held;
188
+ held = owned;
189
+ if (previous !== void 0) yield* Scope.close(previous, Exit.void);
190
+ return client;
191
+ })
192
+ ));
193
+ return { client: yield* rebuild, rebuild };
194
+ });
195
+ const guardedTransport = (environment) => Effect.gen(function* () {
196
+ const grants = yield* import_GrantStore.GrantStore;
197
+ return yield* rebuildableTransport(dispatcher(environment), (client) => import_HttpClient2.HttpClient.pipe(Effect.provide(KernelHttpClient.layer.pipe(
198
+ Layer.provide(Layer.succeed(import_HttpClient2.HttpClient)(client)),
199
+ Layer.provide(Layer.succeed(import_GrantStore.GrantStore)(grants))
200
+ ))));
201
+ });
202
+ //# sourceMappingURL=EgressHttpClient.js.map