@graftland/plugin-remote 0.0.0-stage → 0.3.0

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 (380) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +76 -2
  3. package/README.zh-CN.md +71 -0
  4. package/README.zh-TW.md +71 -0
  5. package/dist/Auth-BElTC9_X.js +6 -0
  6. package/dist/Auth.d.ts +49 -0
  7. package/dist/Auth.d.ts.map +1 -0
  8. package/dist/Auth.js +8 -0
  9. package/dist/Auth.js.map +1 -0
  10. package/dist/Bootstrap-MCwivGN1.js +9 -0
  11. package/dist/ConfigDirectory-BCC6q2R4.js +5 -0
  12. package/dist/Contract-CcpSIJm4.js +121 -0
  13. package/dist/Contract.d.ts +71 -0
  14. package/dist/Contract.d.ts.map +1 -0
  15. package/dist/Contract.js +1 -0
  16. package/dist/Contract.js.map +1 -0
  17. package/dist/Errors-oPsTLY7l.js +45 -0
  18. package/dist/Errors.d.ts +67 -0
  19. package/dist/Errors.d.ts.map +1 -0
  20. package/dist/Errors.js +47 -0
  21. package/dist/Errors.js.map +1 -0
  22. package/dist/FailureGroup-BcH0XOBi.js +53 -0
  23. package/dist/Framing-zaYdOJnT.js +61 -0
  24. package/dist/Graft-BsYq3F-J.js +985 -0
  25. package/dist/Instance.d.ts +7 -0
  26. package/dist/Instance.d.ts.map +1 -0
  27. package/dist/Instance.js +14 -0
  28. package/dist/Instance.js.map +1 -0
  29. package/dist/Packages-B1TPk8pa.js +111 -0
  30. package/dist/Peer-IJgFK6mD.js +342 -0
  31. package/dist/ProcessObservation-DEGrEMfP.js +38 -0
  32. package/dist/ServeLifecycle-CJM0gG5B.js +24 -0
  33. package/dist/Testing.d.ts +26 -0
  34. package/dist/Testing.d.ts.map +1 -0
  35. package/dist/Testing.js +69 -0
  36. package/dist/Testing.js.map +1 -0
  37. package/dist/Transport-DULzpsgR.js +6 -0
  38. package/dist/Transport.d.ts +39 -0
  39. package/dist/Transport.d.ts.map +1 -0
  40. package/dist/Transport.js +8 -0
  41. package/dist/Transport.js.map +1 -0
  42. package/dist/WatchdogProtocol-BZmVxrBP.js +17 -0
  43. package/dist/_virtual/_rolldown/runtime.js +12 -0
  44. package/dist/bin.d.ts +1 -0
  45. package/dist/bin.js +28275 -0
  46. package/dist/bin.js.map +1 -0
  47. package/dist/childRuntime-DSqtFN9o.js +188 -0
  48. package/dist/cleanup-BPWr-5U9.js +13 -0
  49. package/dist/command-9zrHdbwT.js +7 -0
  50. package/dist/connectionEnded-DUgcobEd.js +9 -0
  51. package/dist/directTransport-DrexuPSm.js +5 -0
  52. package/dist/entry-SYsx9VNb.js +708 -0
  53. package/dist/host/auth/bearer.d.ts +5 -0
  54. package/dist/host/auth/bearer.d.ts.map +1 -0
  55. package/dist/host/auth/bearer.js +4 -0
  56. package/dist/host/auth/bearer.js.map +1 -0
  57. package/dist/host/auth/jwt.d.ts +5 -0
  58. package/dist/host/auth/jwt.d.ts.map +1 -0
  59. package/dist/host/auth/jwt.js +4 -0
  60. package/dist/host/auth/jwt.js.map +1 -0
  61. package/dist/host/auth/mtls.d.ts +8 -0
  62. package/dist/host/auth/mtls.d.ts.map +1 -0
  63. package/dist/host/auth/mtls.js +34 -0
  64. package/dist/host/auth/mtls.js.map +1 -0
  65. package/dist/host/auth/none.d.ts +3 -0
  66. package/dist/host/auth/none.d.ts.map +1 -0
  67. package/dist/host/auth/none.js +13 -0
  68. package/dist/host/auth/none.js.map +1 -0
  69. package/dist/host/command.d.ts +22 -0
  70. package/dist/host/command.d.ts.map +1 -0
  71. package/dist/host/command.js +61 -0
  72. package/dist/host/command.js.map +1 -0
  73. package/dist/host/local.d.ts +4 -0
  74. package/dist/host/local.d.ts.map +1 -0
  75. package/dist/host/local.js +52 -0
  76. package/dist/host/local.js.map +1 -0
  77. package/dist/host/unix.d.ts +11 -0
  78. package/dist/host/unix.d.ts.map +1 -0
  79. package/dist/host/unix.js +39 -0
  80. package/dist/host/unix.js.map +1 -0
  81. package/dist/host/websocket.d.ts +13 -0
  82. package/dist/host/websocket.d.ts.map +1 -0
  83. package/dist/host/websocket.js +36 -0
  84. package/dist/host/websocket.js.map +1 -0
  85. package/dist/host/worker.d.ts +4 -0
  86. package/dist/host/worker.d.ts.map +1 -0
  87. package/dist/host/worker.js +52 -0
  88. package/dist/host/worker.js.map +1 -0
  89. package/dist/importer-D7zSgqxq.js +347 -0
  90. package/dist/index.d.ts +29 -0
  91. package/dist/index.d.ts.map +1 -0
  92. package/dist/index.js +86 -0
  93. package/dist/index.js.map +1 -0
  94. package/dist/internal/Certificates.js +182 -0
  95. package/dist/internal/Certificates.js.map +1 -0
  96. package/dist/internal/FailureGroup.js +55 -0
  97. package/dist/internal/FailureGroup.js.map +1 -0
  98. package/dist/internal/Limits.d.ts +1 -0
  99. package/dist/internal/Limits.js +17 -0
  100. package/dist/internal/Limits.js.map +1 -0
  101. package/dist/internal/Peer.js +6 -0
  102. package/dist/internal/Peer.js.map +1 -0
  103. package/dist/internal/ServeLifecycle.js +26 -0
  104. package/dist/internal/ServeLifecycle.js.map +1 -0
  105. package/dist/internal/Supervisor.js +7 -0
  106. package/dist/internal/Supervisor.js.map +1 -0
  107. package/dist/internal/assembly.d.ts +5 -0
  108. package/dist/internal/assembly.js +138 -0
  109. package/dist/internal/assembly.js.map +1 -0
  110. package/dist/internal/auth/mtls.js +23 -0
  111. package/dist/internal/auth/mtls.js.map +1 -0
  112. package/dist/internal/auth/token.js +19 -0
  113. package/dist/internal/auth/token.js.map +1 -0
  114. package/dist/internal/auth/tokenCredentials.d.ts +8 -0
  115. package/dist/internal/auth/tokenCredentials.d.ts.map +1 -0
  116. package/dist/internal/auth/tokenCredentials.js +33 -0
  117. package/dist/internal/auth/tokenCredentials.js.map +1 -0
  118. package/dist/internal/child.js +125 -0
  119. package/dist/internal/child.js.map +1 -0
  120. package/dist/internal/childErrors.d.ts +33 -0
  121. package/dist/internal/childErrors.d.ts.map +1 -0
  122. package/dist/internal/childErrors.js +29 -0
  123. package/dist/internal/childErrors.js.map +1 -0
  124. package/dist/internal/childRuntime.js +59 -0
  125. package/dist/internal/childRuntime.js.map +1 -0
  126. package/dist/internal/cleanup.js +15 -0
  127. package/dist/internal/cleanup.js.map +1 -0
  128. package/dist/internal/config.js +6 -0
  129. package/dist/internal/config.js.map +1 -0
  130. package/dist/internal/control.js +42 -0
  131. package/dist/internal/control.js.map +1 -0
  132. package/dist/internal/credentials.d.ts +44 -0
  133. package/dist/internal/credentials.d.ts.map +1 -0
  134. package/dist/internal/credentials.js +54 -0
  135. package/dist/internal/credentials.js.map +1 -0
  136. package/dist/internal/directTransport.d.ts +3 -0
  137. package/dist/internal/directTransport.js +7 -0
  138. package/dist/internal/directTransport.js.map +1 -0
  139. package/dist/internal/entry.d.ts +9 -0
  140. package/dist/internal/entry.d.ts.map +1 -0
  141. package/dist/internal/entry.js +144 -0
  142. package/dist/internal/entry.js.map +1 -0
  143. package/dist/internal/entryConfig.d.ts +202 -0
  144. package/dist/internal/entryConfig.d.ts.map +1 -0
  145. package/dist/internal/entryConfig.js +176 -0
  146. package/dist/internal/entryConfig.js.map +1 -0
  147. package/dist/internal/execution.d.ts +5 -0
  148. package/dist/internal/execution.js +43 -0
  149. package/dist/internal/execution.js.map +1 -0
  150. package/dist/internal/follow.js +11 -0
  151. package/dist/internal/follow.js.map +1 -0
  152. package/dist/internal/forkTree.js +7 -0
  153. package/dist/internal/forkTree.js.map +1 -0
  154. package/dist/internal/host/local.js +28 -0
  155. package/dist/internal/host/local.js.map +1 -0
  156. package/dist/internal/host/runner.js +100 -0
  157. package/dist/internal/host/runner.js.map +1 -0
  158. package/dist/internal/host.js +71 -0
  159. package/dist/internal/host.js.map +1 -0
  160. package/dist/internal/importer.js +18 -0
  161. package/dist/internal/importer.js.map +1 -0
  162. package/dist/internal/listenerStartup.js +17 -0
  163. package/dist/internal/listenerStartup.js.map +1 -0
  164. package/dist/internal/loadModule.js +20 -0
  165. package/dist/internal/loadModule.js.map +1 -0
  166. package/dist/internal/platform.js +9 -0
  167. package/dist/internal/platform.js.map +1 -0
  168. package/dist/internal/port.d.ts +13 -0
  169. package/dist/internal/port.d.ts.map +1 -0
  170. package/dist/internal/port.js +275 -0
  171. package/dist/internal/port.js.map +1 -0
  172. package/dist/internal/release.js +25 -0
  173. package/dist/internal/release.js.map +1 -0
  174. package/dist/internal/runner/Bootstrap.js +11 -0
  175. package/dist/internal/runner/Bootstrap.js.map +1 -0
  176. package/dist/internal/runner/Connection.d.ts +11 -0
  177. package/dist/internal/runner/Connection.js +56 -0
  178. package/dist/internal/runner/Connection.js.map +1 -0
  179. package/dist/internal/runner/Execution.js +115 -0
  180. package/dist/internal/runner/Execution.js.map +1 -0
  181. package/dist/internal/runner/Framing.d.ts +11 -0
  182. package/dist/internal/runner/Framing.d.ts.map +1 -0
  183. package/dist/internal/runner/Framing.js +63 -0
  184. package/dist/internal/runner/Framing.js.map +1 -0
  185. package/dist/internal/runner/Local.js +46 -0
  186. package/dist/internal/runner/Local.js.map +1 -0
  187. package/dist/internal/runner/Lock.js +25 -0
  188. package/dist/internal/runner/Lock.js.map +1 -0
  189. package/dist/internal/runner/Multiplex.d.ts +5 -0
  190. package/dist/internal/runner/Multiplex.js +49 -0
  191. package/dist/internal/runner/Multiplex.js.map +1 -0
  192. package/dist/internal/runner/Packages.d.ts +3 -0
  193. package/dist/internal/runner/Packages.js +108 -0
  194. package/dist/internal/runner/Packages.js.map +1 -0
  195. package/dist/internal/runner/ProcessObservation.js +40 -0
  196. package/dist/internal/runner/ProcessObservation.js.map +1 -0
  197. package/dist/internal/runner/Processes.js +83 -0
  198. package/dist/internal/runner/Processes.js.map +1 -0
  199. package/dist/internal/runner/Retention.js +13 -0
  200. package/dist/internal/runner/Retention.js.map +1 -0
  201. package/dist/internal/runner/Store.js +78 -0
  202. package/dist/internal/runner/Store.js.map +1 -0
  203. package/dist/internal/runner/Supervisor.js +375 -0
  204. package/dist/internal/runner/Supervisor.js.map +1 -0
  205. package/dist/internal/runner/Watchdog.js +47 -0
  206. package/dist/internal/runner/Watchdog.js.map +1 -0
  207. package/dist/internal/runner/WatchdogProtocol.js +19 -0
  208. package/dist/internal/runner/WatchdogProtocol.js.map +1 -0
  209. package/dist/internal/runner/Wire.d.ts +5 -0
  210. package/dist/internal/runner/Wire.js +64 -0
  211. package/dist/internal/runner/Wire.js.map +1 -0
  212. package/dist/internal/runner/accept.js +57 -0
  213. package/dist/internal/runner/accept.js.map +1 -0
  214. package/dist/internal/runner/command.js +9 -0
  215. package/dist/internal/runner/command.js.map +1 -0
  216. package/dist/internal/runner/connectionEnded.js +11 -0
  217. package/dist/internal/runner/connectionEnded.js.map +1 -0
  218. package/dist/internal/runner/model.d.ts +17 -0
  219. package/dist/internal/runner/model.d.ts.map +1 -0
  220. package/dist/internal/runner/model.js +231 -0
  221. package/dist/internal/runner/model.js.map +1 -0
  222. package/dist/internal/serve.js +60 -0
  223. package/dist/internal/serve.js.map +1 -0
  224. package/dist/internal/services.d.ts +18 -0
  225. package/dist/internal/services.d.ts.map +1 -0
  226. package/dist/internal/services.js +22 -0
  227. package/dist/internal/services.js.map +1 -0
  228. package/dist/internal/socketChannel.js +24 -0
  229. package/dist/internal/socketChannel.js.map +1 -0
  230. package/dist/internal/stdioChannel.js +23 -0
  231. package/dist/internal/stdioChannel.js.map +1 -0
  232. package/dist/internal/supervisorPlugin.js +1 -0
  233. package/dist/internal/supervisorPlugin.js.map +1 -0
  234. package/dist/internal/transportOptions.d.ts +18 -0
  235. package/dist/internal/transportOptions.d.ts.map +1 -0
  236. package/dist/internal/watchdogMain.d.ts +1 -0
  237. package/dist/internal/watchdogMain.js +55 -0
  238. package/dist/internal/watchdogMain.js.map +1 -0
  239. package/dist/internal/websocket.js +46 -0
  240. package/dist/internal/websocket.js.map +1 -0
  241. package/dist/internal/websocketServer.js +61 -0
  242. package/dist/internal/websocketServer.js.map +1 -0
  243. package/dist/internal/workerBootstrap.js +9 -0
  244. package/dist/internal/workerBootstrap.js.map +1 -0
  245. package/dist/internal/workerChannel.js +24 -0
  246. package/dist/internal/workerChannel.js.map +1 -0
  247. package/dist/internal/workerMain.d.ts +1 -0
  248. package/dist/internal/workerMain.js +18 -0
  249. package/dist/internal/workerMain.js.map +1 -0
  250. package/dist/port-Blbh8tms.js +285 -0
  251. package/dist/release-BY4Mlluy.js +23 -0
  252. package/dist/rolldown-runtime-DYf_mQCB.js +34 -0
  253. package/dist/runner/auth/bearer.d.ts +7 -0
  254. package/dist/runner/auth/bearer.d.ts.map +1 -0
  255. package/dist/runner/auth/bearer.js +42 -0
  256. package/dist/runner/auth/bearer.js.map +1 -0
  257. package/dist/runner/auth/jwt.d.ts +19 -0
  258. package/dist/runner/auth/jwt.d.ts.map +1 -0
  259. package/dist/runner/auth/jwt.js +65 -0
  260. package/dist/runner/auth/jwt.js.map +1 -0
  261. package/dist/runner/auth/mtls.d.ts +11 -0
  262. package/dist/runner/auth/mtls.d.ts.map +1 -0
  263. package/dist/runner/auth/mtls.js +48 -0
  264. package/dist/runner/auth/mtls.js.map +1 -0
  265. package/dist/runner/auth/none.d.ts +3 -0
  266. package/dist/runner/auth/none.d.ts.map +1 -0
  267. package/dist/runner/auth/none.js +13 -0
  268. package/dist/runner/auth/none.js.map +1 -0
  269. package/dist/runner/index.d.ts +3 -0
  270. package/dist/runner/index.d.ts.map +1 -0
  271. package/dist/runner/index.js +71 -0
  272. package/dist/runner/index.js.map +1 -0
  273. package/dist/runner/stdio.d.ts +7 -0
  274. package/dist/runner/stdio.d.ts.map +1 -0
  275. package/dist/runner/stdio.js +39 -0
  276. package/dist/runner/stdio.js.map +1 -0
  277. package/dist/runner/unix.d.ts +7 -0
  278. package/dist/runner/unix.d.ts.map +1 -0
  279. package/dist/runner/unix.js +42 -0
  280. package/dist/runner/unix.js.map +1 -0
  281. package/dist/runner/websocket.d.ts +28 -0
  282. package/dist/runner/websocket.d.ts.map +1 -0
  283. package/dist/runner/websocket.js +77 -0
  284. package/dist/runner/websocket.js.map +1 -0
  285. package/dist/socketChannel-KmtzF-9G.js +3658 -0
  286. package/dist/supervisorPlugin-Inb1S5IV.js +737 -0
  287. package/dist/token-v5ne2I0-.js +17 -0
  288. package/dist/tokenCredentials-WUJm2AKm.js +31 -0
  289. package/dist/websocketServer-MXcCJx0v.js +58 -0
  290. package/dist/workerChannel-P82YdNjh.js +27 -0
  291. package/package.json +69 -3
  292. package/src/Auth.ts +62 -0
  293. package/src/Contract.ts +100 -0
  294. package/src/Errors.ts +82 -0
  295. package/src/Instance.ts +12 -0
  296. package/src/Testing.ts +135 -0
  297. package/src/Transport.ts +52 -0
  298. package/src/bin.ts +145 -0
  299. package/src/host/auth/bearer.ts +10 -0
  300. package/src/host/auth/jwt.ts +10 -0
  301. package/src/host/auth/mtls.ts +48 -0
  302. package/src/host/auth/none.ts +13 -0
  303. package/src/host/command.ts +131 -0
  304. package/src/host/local.ts +41 -0
  305. package/src/host/unix.ts +65 -0
  306. package/src/host/websocket.ts +66 -0
  307. package/src/host/worker.ts +90 -0
  308. package/src/index.ts +115 -0
  309. package/src/internal/Certificates.ts +330 -0
  310. package/src/internal/FailureGroup.ts +176 -0
  311. package/src/internal/Limits.ts +12 -0
  312. package/src/internal/Peer.ts +4 -0
  313. package/src/internal/ServeLifecycle.ts +53 -0
  314. package/src/internal/Supervisor.ts +14 -0
  315. package/src/internal/assembly.ts +337 -0
  316. package/src/internal/auth/mtls.ts +40 -0
  317. package/src/internal/auth/token.ts +26 -0
  318. package/src/internal/auth/tokenCredentials.ts +65 -0
  319. package/src/internal/child.ts +323 -0
  320. package/src/internal/childErrors.ts +44 -0
  321. package/src/internal/childRuntime.ts +111 -0
  322. package/src/internal/cleanup.ts +34 -0
  323. package/src/internal/config.ts +8 -0
  324. package/src/internal/control.ts +49 -0
  325. package/src/internal/credentials.ts +112 -0
  326. package/src/internal/directTransport.ts +38 -0
  327. package/src/internal/entry.ts +288 -0
  328. package/src/internal/entryConfig.ts +190 -0
  329. package/src/internal/execution.ts +121 -0
  330. package/src/internal/follow.ts +17 -0
  331. package/src/internal/forkTree.ts +13 -0
  332. package/src/internal/host/local.ts +53 -0
  333. package/src/internal/host/runner.ts +187 -0
  334. package/src/internal/host.ts +209 -0
  335. package/src/internal/importer.ts +27 -0
  336. package/src/internal/listenerStartup.ts +55 -0
  337. package/src/internal/loadModule.ts +23 -0
  338. package/src/internal/platform.ts +12 -0
  339. package/src/internal/port.ts +623 -0
  340. package/src/internal/release.ts +71 -0
  341. package/src/internal/runner/Bootstrap.ts +9 -0
  342. package/src/internal/runner/Connection.ts +184 -0
  343. package/src/internal/runner/Execution.ts +244 -0
  344. package/src/internal/runner/Framing.ts +122 -0
  345. package/src/internal/runner/Local.ts +73 -0
  346. package/src/internal/runner/Lock.ts +29 -0
  347. package/src/internal/runner/Multiplex.ts +120 -0
  348. package/src/internal/runner/Packages.ts +178 -0
  349. package/src/internal/runner/ProcessObservation.ts +63 -0
  350. package/src/internal/runner/Processes.ts +109 -0
  351. package/src/internal/runner/Retention.ts +49 -0
  352. package/src/internal/runner/Store.ts +160 -0
  353. package/src/internal/runner/Supervisor.ts +901 -0
  354. package/src/internal/runner/Watchdog.ts +83 -0
  355. package/src/internal/runner/WatchdogProtocol.ts +12 -0
  356. package/src/internal/runner/Wire.ts +99 -0
  357. package/src/internal/runner/accept.ts +103 -0
  358. package/src/internal/runner/command.ts +15 -0
  359. package/src/internal/runner/connectionEnded.ts +28 -0
  360. package/src/internal/runner/model.ts +364 -0
  361. package/src/internal/serve.ts +117 -0
  362. package/src/internal/services.ts +74 -0
  363. package/src/internal/socketChannel.ts +64 -0
  364. package/src/internal/stdioChannel.ts +25 -0
  365. package/src/internal/supervisorPlugin.ts +67 -0
  366. package/src/internal/transportOptions.ts +17 -0
  367. package/src/internal/watchdogMain.ts +72 -0
  368. package/src/internal/websocket.ts +81 -0
  369. package/src/internal/websocketServer.ts +152 -0
  370. package/src/internal/workerBootstrap.ts +6 -0
  371. package/src/internal/workerChannel.ts +54 -0
  372. package/src/internal/workerMain.ts +23 -0
  373. package/src/runner/auth/bearer.ts +66 -0
  374. package/src/runner/auth/jwt.ts +114 -0
  375. package/src/runner/auth/mtls.ts +37 -0
  376. package/src/runner/auth/none.ts +13 -0
  377. package/src/runner/index.ts +97 -0
  378. package/src/runner/stdio.ts +76 -0
  379. package/src/runner/unix.ts +53 -0
  380. package/src/runner/websocket.ts +143 -0
@@ -0,0 +1,54 @@
1
+ import { Cause, Effect, FiberSet, Queue, Sink, Stream } from "effect"
2
+ import { TransportError } from "../Errors"
3
+ import type { Channel } from "./port"
4
+
5
+ /** Both ends send owned ArrayBuffers; null is the byte stream's EOF. */
6
+ export interface Endpoint {
7
+ readonly postMessage: (
8
+ value: ArrayBuffer | null,
9
+ transferList: ArrayBuffer[],
10
+ ) => void
11
+ readonly on: (
12
+ event: "message",
13
+ listener: (value: ArrayBuffer | null) => void,
14
+ ) => unknown
15
+ readonly off: (
16
+ event: "message",
17
+ listener: (value: ArrayBuffer | null) => void,
18
+ ) => unknown
19
+ }
20
+ export const make = Effect.fnUntraced(function* (endpoint: Endpoint) {
21
+ // Port owns admission and RPC chunk backpressure; this queue only bridges message events.
22
+ const input = yield* Queue.unbounded<Uint8Array, Cause.Done>()
23
+ const callbacks = yield* FiberSet.make()
24
+ const run = yield* FiberSet.runtime(callbacks)()
25
+ const receive = (value: ArrayBuffer | null) =>
26
+ run(
27
+ value === null
28
+ ? Queue.end(input)
29
+ : Queue.offer(input, new Uint8Array(value)),
30
+ )
31
+ yield* Effect.acquireRelease(
32
+ Effect.sync(() => endpoint.on("message", receive)),
33
+ () =>
34
+ Effect.sync(() => endpoint.off("message", receive)).pipe(
35
+ Effect.andThen(Queue.shutdown(input)),
36
+ ),
37
+ )
38
+ const send = (bytes: Uint8Array | null) =>
39
+ Effect.try({
40
+ try: () => {
41
+ // Copy even Buffer slices: only this fresh, exact-sized backing store is transferable.
42
+ const buffer = bytes === null ? null : new Uint8Array(bytes).buffer
43
+ endpoint.postMessage(buffer, buffer === null ? [] : [buffer])
44
+ },
45
+ catch: (cause) => TransportError.make({ cause: Cause.die(cause) }),
46
+ })
47
+ return {
48
+ input: Stream.fromQueue(input),
49
+ output: Sink.forEach((bytes: Uint8Array) => send(bytes)).pipe(
50
+ // Closing the output half always sends EOF, including when its writer is interrupted.
51
+ Sink.ensuring(send(null)),
52
+ ),
53
+ } satisfies Channel
54
+ })
@@ -0,0 +1,23 @@
1
+ /** Executable entry for a direct worker; platform services belong to this thread. */
2
+ import { Graft } from "@graftland/graft"
3
+ import { NodeRuntime } from "@effect/platform-node"
4
+ import { Effect, Layer, Schema } from "effect"
5
+ import { parentPort, workerData } from "node:worker_threads"
6
+ import { load, run } from "./childRuntime"
7
+ import { Bootstrap } from "./workerBootstrap"
8
+ import * as Channel from "./workerChannel"
9
+ import { platform } from "./platform"
10
+
11
+ const main = Effect.scoped(
12
+ Effect.gen(function* () {
13
+ const port = yield* Effect.fromNullishOr(parentPort)
14
+ yield* Effect.addFinalizer(() => Effect.sync(() => port.close()))
15
+ const bootstrap = yield* Schema.decodeUnknownEffect(Bootstrap)(workerData)
16
+ const channel = yield* Channel.make(port)
17
+ const contract = yield* load(bootstrap.contractModule)
18
+ yield* run(contract, channel, bootstrap.session)
19
+ }),
20
+ )
21
+ NodeRuntime.runMain(
22
+ main.pipe(Effect.provide(Graft.layer.pipe(Layer.provide(platform)))),
23
+ )
@@ -0,0 +1,66 @@
1
+ import { Option } from "effect"
2
+ import { Graft, Plugin } from "@graftland/graft"
3
+ import {
4
+ Array,
5
+ Effect,
6
+ FileSystem,
7
+ Path,
8
+ Record,
9
+ Redacted,
10
+ Schema,
11
+ } from "effect"
12
+ import { Digest } from "effect/crypto"
13
+ import { Hex } from "effect/encoding"
14
+ // @effect-diagnostics-next-line nodeBuiltinImport:off -- Token digests use Node's constant-time comparison
15
+ import { timingSafeEqual } from "node:crypto"
16
+ import { Authenticator } from "../../Auth"
17
+ import { ConfigDirectory } from "@graftland/loader"
18
+ import * as Token from "../../internal/auth/token"
19
+
20
+ export const Config = Schema.Struct({ tokens: Schema.String })
21
+ const Tokens = Schema.fromJsonString(
22
+ Schema.Record(
23
+ Schema.String.check(Schema.isPattern(/^[0-9a-fA-F]{64}$/)),
24
+ Schema.NonEmptyString,
25
+ ),
26
+ )
27
+ export default Plugin.make({
28
+ name: "remote-bearer-authenticator",
29
+ config: Config,
30
+ inject: [FileSystem.FileSystem, Path.Path, Digest.Digest],
31
+ apply: Effect.fnUntraced(function* (config) {
32
+ const fs = yield* FileSystem.FileSystem
33
+ const path = yield* Path.Path
34
+ const directory = yield* ConfigDirectory.pipe(
35
+ Effect.map(Option.getOrElse(() => ".")),
36
+ )
37
+ const digest = yield* Digest.Digest
38
+ const file = yield* fs.readFileString(
39
+ path.resolve(directory, config.tokens),
40
+ )
41
+ const mapping = yield* Schema.decodeEffect(Tokens)(file)
42
+ const tokens = yield* Effect.forEach(
43
+ Record.toEntries(mapping),
44
+ ([hex, identity]) =>
45
+ Effect.fromResult(Hex.decode(hex)).pipe(
46
+ Effect.map((hash) => ({ hash, identity })),
47
+ ),
48
+ )
49
+ yield* Graft.provide(Authenticator, {
50
+ _tag: "Header",
51
+ authenticate: Effect.fnUntraced(function* (authorization) {
52
+ const token = yield* Token.read(authorization)
53
+ const hash = yield* digest.digest(
54
+ Digest.sha256,
55
+ new TextEncoder().encode(Redacted.value(token)),
56
+ )
57
+ const found = Array.findFirst(tokens, (entry) =>
58
+ timingSafeEqual(hash, entry.hash),
59
+ )
60
+ return yield* Effect.fromOption(found, Token.invalid).pipe(
61
+ Effect.map((entry) => entry.identity),
62
+ )
63
+ }),
64
+ })
65
+ }),
66
+ })
@@ -0,0 +1,114 @@
1
+ import { Option } from "effect"
2
+ import { Graft, Plugin } from "@graftland/graft"
3
+ import {
4
+ Cause,
5
+ Duration,
6
+ Effect,
7
+ FileSystem,
8
+ Layer,
9
+ Path,
10
+ Schema,
11
+ } from "effect"
12
+ import { Jwk, Jwks, Jwt } from "effect/jose"
13
+ import { Signature } from "effect/crypto"
14
+ import { HttpClient } from "effect/http"
15
+ import { Authenticator } from "../../Auth"
16
+ import { ConfigDirectory } from "@graftland/loader"
17
+ import { AuthenticationFailed } from "../../Errors"
18
+ import * as Token from "../../internal/auth/token"
19
+
20
+ export const ClockTolerance = Schema.DurationFromString.check(
21
+ Schema.makeFilter(
22
+ (duration) =>
23
+ Duration.isFinite(duration) && Duration.toMillis(duration) >= 0,
24
+ { expected: "a finite, non-negative duration" },
25
+ ),
26
+ )
27
+ export const Config = Schema.Struct({
28
+ issuer: Schema.NonEmptyString,
29
+ audience: Schema.NonEmptyArray(Schema.NonEmptyString),
30
+ algorithms: Schema.NonEmptyArray(Jwk.AsymmetricAlgorithm),
31
+ identityClaim: Schema.NonEmptyString.pipe(
32
+ Schema.withDecodingDefaultKey(Effect.succeed("sub")),
33
+ ),
34
+ clockTolerance: ClockTolerance.pipe(
35
+ Schema.withDecodingDefaultKey(Effect.succeed("5 seconds")),
36
+ ),
37
+ keys: Schema.Union([
38
+ Schema.Struct({
39
+ jwksUrl: Schema.String,
40
+ publicKey: Schema.optionalKey(Schema.Never),
41
+ }),
42
+ Schema.Struct({
43
+ publicKey: Schema.String,
44
+ jwksUrl: Schema.optionalKey(Schema.Never),
45
+ }),
46
+ ]),
47
+ })
48
+ const keys = Effect.fnUntraced(function* (config: typeof Config.Type) {
49
+ if (config.keys.jwksUrl !== undefined)
50
+ return Jwks.layerRemote({ url: config.keys.jwksUrl })
51
+ const fs = yield* FileSystem.FileSystem
52
+ const path = yield* Path.Path
53
+ const directory = yield* ConfigDirectory.pipe(
54
+ Effect.map(Option.getOrElse(() => ".")),
55
+ )
56
+ const pem = yield* fs.readFileString(
57
+ path.resolve(directory, config.keys.publicKey),
58
+ )
59
+ // A single PEM must support the allowed algorithms; use JWKS for multiple key types.
60
+ const keys = yield* Effect.forEach(config.algorithms, (algorithm) =>
61
+ Jwk.importSpki(pem, algorithm).pipe(Effect.flatMap(Jwk.exportPublic)),
62
+ )
63
+ return Jwks.layerLocal({ keys })
64
+ })
65
+ export default Plugin.make({
66
+ name: "remote-jwt-authenticator",
67
+ config: Config,
68
+ inject: [
69
+ FileSystem.FileSystem,
70
+ Path.Path,
71
+ Signature.Signature,
72
+ HttpClient.HttpClient,
73
+ ],
74
+ apply: Effect.fnUntraced(function* (config) {
75
+ const keySet = yield* keys(config)
76
+ const services = yield* Layer.build(keySet)
77
+ const signature = yield* Signature.Signature
78
+ yield* Graft.provide(Authenticator, {
79
+ _tag: "Header",
80
+ issuer: config.issuer,
81
+ authenticate: (authorization) =>
82
+ Token.read(authorization).pipe(
83
+ Effect.flatMap((token) =>
84
+ Jwt.verifyWithKeySet(
85
+ Schema.Record(Schema.String, Schema.Unknown),
86
+ token,
87
+ {
88
+ issuer: config.issuer,
89
+ audience: config.audience,
90
+ algorithms: config.algorithms,
91
+ clockTolerance: config.clockTolerance,
92
+ requiredClaims: ["exp"],
93
+ },
94
+ ).pipe(
95
+ Effect.flatMap((verified) =>
96
+ Schema.decodeUnknownEffect(Schema.NonEmptyString)(
97
+ verified.claims[config.identityClaim],
98
+ ),
99
+ ),
100
+ Effect.mapError((error) =>
101
+ AuthenticationFailed.make({
102
+ reason: "invalid",
103
+ challenge: 'Bearer error="invalid_token"',
104
+ cause: Cause.fail(error),
105
+ }),
106
+ ),
107
+ Effect.provideService(Signature.Signature, signature),
108
+ Effect.provideContext(services),
109
+ ),
110
+ ),
111
+ ),
112
+ })
113
+ }),
114
+ })
@@ -0,0 +1,37 @@
1
+ import { Graft, Plugin } from "@graftland/graft"
2
+ import { Effect, FileSystem, Option, Path, Schema } from "effect"
3
+ import { Authenticator, type AuthenticatorApi } from "../../Auth"
4
+ import { ConfigDirectory } from "@graftland/loader"
5
+ import { identityFromSubjectAltName } from "../../internal/auth/mtls"
6
+
7
+ export const Config = Schema.Struct({ ca: Schema.String })
8
+ const read = Effect.fnUntraced(function* (ca: string) {
9
+ const fs = yield* FileSystem.FileSystem
10
+ const path = yield* Path.Path
11
+ const directory = yield* ConfigDirectory.pipe(
12
+ Effect.map(Option.getOrElse(() => ".")),
13
+ )
14
+ return yield* fs.readFileString(path.resolve(directory, ca))
15
+ })
16
+ export const make = (
17
+ ca: string,
18
+ ): Extract<AuthenticatorApi, { readonly _tag: "Mtls" }> => ({
19
+ _tag: "Mtls",
20
+ tls: {
21
+ ca: [ca],
22
+ minVersion: "TLSv1.3",
23
+ requestCert: true,
24
+ rejectUnauthorized: true,
25
+ },
26
+ authenticate: (peer) =>
27
+ identityFromSubjectAltName(Option.getOrUndefined(peer.subjectAltName)),
28
+ })
29
+ export default Plugin.make({
30
+ name: "remote-certificate-authenticator",
31
+ config: Config,
32
+ inject: [FileSystem.FileSystem, Path.Path],
33
+ apply: ({ ca }) =>
34
+ read(ca).pipe(
35
+ Effect.flatMap((ca) => Graft.provide(Authenticator, make(ca))),
36
+ ),
37
+ })
@@ -0,0 +1,13 @@
1
+ import { Graft, Plugin } from "@graftland/graft"
2
+ import { Effect, Schema } from "effect"
3
+ import { Authenticator } from "../../Auth"
4
+
5
+ export default Plugin.make({
6
+ name: "remote-none-authenticator",
7
+ config: Schema.Struct({
8
+ identity: Schema.String.pipe(
9
+ Schema.withDecodingDefaultKey(Effect.succeed("anonymous")),
10
+ ),
11
+ }),
12
+ apply: (config) => Graft.provide(Authenticator, { _tag: "None", ...config }),
13
+ })
@@ -0,0 +1,97 @@
1
+ import { Graft, Plugin } from "@graftland/graft"
2
+ import { SecureRandom } from "effect/crypto"
3
+ import { Path } from "effect"
4
+ import { ModuleResolver } from "@graftland/loader"
5
+ import { Deferred, Effect, Schema, Stream } from "effect"
6
+ import * as Configuration from "../internal/entryConfig"
7
+ import { boundary, resolve } from "../internal/entry"
8
+ import * as Assembly from "../internal/assembly"
9
+ import * as Startup from "../internal/listenerStartup"
10
+ import { follow } from "../internal/follow"
11
+ import { Supervisor } from "../internal/Supervisor"
12
+ import supervisor, {
13
+ Config as SupervisorConfig,
14
+ } from "../internal/supervisorPlugin"
15
+
16
+ const startListener = Effect.fnUntraced(function* (
17
+ input: Configuration.Listen,
18
+ index: number,
19
+ begin: Deferred.Deferred<void>,
20
+ ) {
21
+ const field = `listen[${index}]`
22
+ const transport = yield* resolve(
23
+ Configuration.runnerTransport(input),
24
+ field + ".transport",
25
+ )
26
+ const auth = yield* resolve(
27
+ Configuration.runnerAuthentication(input),
28
+ field + ".auth",
29
+ )
30
+ const signals = yield* Startup.signals
31
+ const consumer = Assembly.makeListenerConsumer(
32
+ (properties, auth) =>
33
+ Assembly.directAuth(properties, input.auth !== undefined).pipe(
34
+ Effect.andThen(
35
+ Deferred.succeed(signals.description, { properties, auth }),
36
+ ),
37
+ Effect.andThen(Deferred.await(begin)),
38
+ ),
39
+ Deferred.succeed(signals.ready, undefined).pipe(Effect.asVoid),
40
+ )
41
+ const fork = yield* Assembly.runner({ transport, auth }, consumer)
42
+ return { fork, signals, field }
43
+ })
44
+
45
+ const owner = Plugin.make({
46
+ name: "remote-supervised-runtime",
47
+ config: Configuration.Runner,
48
+ inject: [ModuleResolver.ModuleResolver, Path.Path, SecureRandom.SecureRandom],
49
+ apply: Effect.fnUntraced(function* (config) {
50
+ const options = yield* Schema.encodeEffect(SupervisorConfig)(config)
51
+ const engine = yield* Graft.plugin(supervisor, options)
52
+ const fail = yield* boundary("supervisor")
53
+ yield* follow(engine, fail)
54
+ const begin = yield* Deferred.make<void>()
55
+ const listeners = yield* Effect.forEach(config.listen, (input, index) =>
56
+ startListener(input, index, begin),
57
+ )
58
+ const descriptions = yield* Effect.forEach(
59
+ listeners,
60
+ ({ fork, signals }) => Startup.wait(fork, signals.description),
61
+ { concurrency: "unbounded" },
62
+ )
63
+ yield* Startup.validate(descriptions)
64
+ yield* Deferred.succeed(begin, undefined)
65
+ yield* Effect.forEach(
66
+ listeners,
67
+ ({ fork, signals }) => Startup.wait(fork, signals.ready),
68
+ { concurrency: "unbounded" },
69
+ )
70
+ yield* Effect.forEach(
71
+ listeners,
72
+ ({ fork, field }) =>
73
+ Plugin.fork(
74
+ fork.state.pipe(
75
+ Stream.runForEach((state) =>
76
+ state._tag === "Failed"
77
+ ? Effect.logWarning("Remote listener failed", state.cause).pipe(
78
+ Effect.annotateLogs({ "remote.listener": field }),
79
+ )
80
+ : Effect.void,
81
+ ),
82
+ ),
83
+ ),
84
+ { discard: true },
85
+ )
86
+ }),
87
+ })
88
+ export default Plugin.make({
89
+ name: "remote-server",
90
+ config: Configuration.Runner,
91
+ apply: Effect.fnUntraced(function* (config) {
92
+ const encoded = yield* Schema.encodeEffect(Configuration.Runner)(config)
93
+ const fork = yield* Graft.plugin(owner, encoded, { isolate: [Supervisor] })
94
+ const fail = yield* boundary("runner")
95
+ yield* follow(fork, fail)
96
+ }),
97
+ })
@@ -0,0 +1,76 @@
1
+ import { Graft, Plugin } from "@graftland/graft"
2
+ import {
3
+ Cause,
4
+ Deferred,
5
+ Effect,
6
+ Exit,
7
+ Option,
8
+ Schema,
9
+ Sink,
10
+ Stdio,
11
+ Stream,
12
+ } from "effect"
13
+ import { Listener, type Accept } from "../Transport"
14
+ import { TransportError } from "../Errors"
15
+ import * as Release from "../internal/release"
16
+
17
+ export const Config = Schema.Struct({ auth: Schema.optionalKey(Schema.Never) })
18
+ export default Plugin.make({
19
+ name: "remote-stdio-listener",
20
+ config: Config,
21
+ inject: [Stdio.Stdio],
22
+ apply: Effect.fnUntraced(function* () {
23
+ const stdio = yield* Stdio.Stdio
24
+ yield* Graft.provide(Listener, {
25
+ properties: {
26
+ protocol: "stdio",
27
+ encrypted: false,
28
+ network: false,
29
+ carries: [],
30
+ },
31
+ bind: Effect.fnUntraced(function* () {
32
+ const ready = yield* Deferred.make<void>()
33
+ const eof = yield* Deferred.make<void>()
34
+ const channel = {
35
+ input: stdio.stdin.pipe(
36
+ Stream.onExit((exit) =>
37
+ Exit.isSuccess(exit)
38
+ ? Deferred.succeed(eof, undefined)
39
+ : Effect.void,
40
+ ),
41
+ Stream.mapError((error) =>
42
+ TransportError.make({ cause: Cause.fail(error) }),
43
+ ),
44
+ ),
45
+ output: stdio
46
+ .stdout({ endOnDone: false })
47
+ .pipe(
48
+ Sink.mapError((error) =>
49
+ TransportError.make({ cause: Cause.fail(error) }),
50
+ ),
51
+ ),
52
+ }
53
+ return {
54
+ ready: Deferred.await(ready),
55
+ serve: (accept: Accept) =>
56
+ accept({
57
+ authorization: Option.none(),
58
+ certificate: Option.none(),
59
+ }).pipe(
60
+ Effect.mapError((error) =>
61
+ TransportError.make({ cause: Cause.fail(error) }),
62
+ ),
63
+ Effect.flatMap((session) =>
64
+ Deferred.succeed(ready, undefined).pipe(
65
+ Effect.andThen(session(channel)),
66
+ ),
67
+ ),
68
+ Release.scoped,
69
+ // Successful session completion alone is not EOF.
70
+ Effect.andThen(Deferred.await(eof)),
71
+ ),
72
+ }
73
+ }),
74
+ })
75
+ }),
76
+ })
@@ -0,0 +1,53 @@
1
+ import { Graft, Plugin } from "@graftland/graft"
2
+ import { ConfigDirectory } from "@graftland/loader"
3
+ import { Cause, Console, Effect, Option, Path, Schema } from "effect"
4
+ // @effect-diagnostics-next-line nodeBuiltinImport:off -- NodeHttpServer takes a factory for an HTTP/1.1 server on the Unix socket
5
+ import { createServer } from "node:http"
6
+ import { Listener } from "../Transport"
7
+ import { TransportError } from "../Errors"
8
+ import * as Server from "../internal/websocketServer"
9
+
10
+ export const Config = Schema.Struct({ path: Schema.String })
11
+ const Listening = Schema.fromJsonString(
12
+ Schema.Struct({ event: Schema.Literal("Listening"), path: Schema.String }),
13
+ )
14
+ export default Plugin.make({
15
+ name: "remote-unix-listener",
16
+ config: Config,
17
+ inject: [Path.Path],
18
+ apply: Effect.fnUntraced(function* (config) {
19
+ const path = yield* Path.Path
20
+ const directory = yield* ConfigDirectory
21
+ const socket = path.resolve(
22
+ Option.getOrElse(directory, () => "."),
23
+ config.path,
24
+ )
25
+ yield* Graft.provide(Listener, {
26
+ properties: {
27
+ protocol: "unix",
28
+ encrypted: false,
29
+ network: false,
30
+ carries: ["header"],
31
+ },
32
+ // Node rejects an occupied path and removes its own socket file when the server closes.
33
+ bind: () =>
34
+ Server.bind(createServer, { path: socket }).pipe(
35
+ Effect.mapBoth({
36
+ onSuccess: (server) => ({
37
+ serve: server.serve,
38
+ ready: server.ready.pipe(
39
+ Effect.andThen(
40
+ Schema.encodeEffect(Listening)({
41
+ event: "Listening",
42
+ path: socket,
43
+ }).pipe(Effect.orDie, Effect.flatMap(Console.log)),
44
+ ),
45
+ ),
46
+ }),
47
+ onFailure: (error) =>
48
+ TransportError.make({ cause: Cause.fail(error) }),
49
+ }),
50
+ ),
51
+ })
52
+ }),
53
+ })
@@ -0,0 +1,143 @@
1
+ import { Graft, Plugin } from "@graftland/graft"
2
+ import {
3
+ Cause,
4
+ Console,
5
+ Effect,
6
+ FileSystem,
7
+ Option,
8
+ Path,
9
+ Schema,
10
+ String,
11
+ } from "effect"
12
+ import { ConfigDirectory } from "@graftland/loader"
13
+ import { createSecureServer } from "node:http2"
14
+ import { Url, path as upgradePath } from "../internal/websocket"
15
+ import { Listener } from "../Transport"
16
+ import type { TlsPolicy } from "../Auth"
17
+ import { TransportError } from "../Errors"
18
+ import * as Server from "../internal/websocketServer"
19
+ import { properties } from "../internal/websocket"
20
+ // @effect-diagnostics-next-line nodeBuiltinImport:off -- NodeHttpServer takes a factory for an HTTP/1.1 upgrade server
21
+ import { createServer } from "node:http"
22
+
23
+ const url = (protocol: "ws:" | "wss:") =>
24
+ Url.check(
25
+ Schema.makeFilter((url) => url.protocol === protocol, {
26
+ expected: protocol + "//",
27
+ }),
28
+ Schema.makeFilter(
29
+ (url) => url.pathname === "/" || url.pathname === upgradePath,
30
+ {
31
+ expected: "a listener URL with no path or /graft",
32
+ },
33
+ ),
34
+ )
35
+ const ws = {
36
+ auth: Schema.optionalKey(Schema.Never),
37
+ url: url("ws:"),
38
+ cert: Schema.optionalKey(Schema.Never),
39
+ key: Schema.optionalKey(Schema.Never),
40
+ }
41
+ const wss = {
42
+ auth: Schema.optionalKey(Schema.Never),
43
+ url: url("wss:"),
44
+ cert: Schema.String,
45
+ key: Schema.String,
46
+ }
47
+ export const Config = Schema.Union([
48
+ Schema.Struct({
49
+ ...ws,
50
+ }).pipe(
51
+ Schema.extendTo(
52
+ { _tag: Schema.Literal("ws") },
53
+ { _tag: () => Option.some<"ws">("ws") },
54
+ ),
55
+ ),
56
+ Schema.Struct({
57
+ ...wss,
58
+ }).pipe(
59
+ Schema.extendTo(
60
+ { _tag: Schema.Literal("wss") },
61
+ { _tag: () => Option.some<"wss">("wss") },
62
+ ),
63
+ ),
64
+ ])
65
+
66
+ const factory = Effect.fnUntraced(function* (
67
+ config: typeof Config.Type,
68
+ tls: Option.Option<TlsPolicy>,
69
+ ) {
70
+ if (config._tag === "ws") return createServer
71
+ const fs = yield* FileSystem.FileSystem
72
+ const path = yield* Path.Path
73
+ const directory = yield* ConfigDirectory.pipe(
74
+ Effect.map(Option.getOrElse(() => ".")),
75
+ )
76
+ const cert = yield* fs.readFileString(path.resolve(directory, config.cert))
77
+ const key = yield* fs.readFileString(path.resolve(directory, config.key))
78
+ return () =>
79
+ createSecureServer({
80
+ allowHTTP1: true,
81
+ cert,
82
+ key,
83
+ minVersion: "TLSv1.3",
84
+ ...Option.match(tls, {
85
+ onNone: () => ({}),
86
+ onSome: (tls) => ({ ...tls, ca: [...tls.ca] }),
87
+ }),
88
+ })
89
+ })
90
+ /** Configured Listener; authentication is supplied to bind, never injected here. */
91
+ export default Plugin.make({
92
+ name: "remote-websocket-capability",
93
+ config: Config,
94
+ inject: [FileSystem.FileSystem, Path.Path],
95
+ apply: Effect.fnUntraced(function* (config) {
96
+ const fs = yield* FileSystem.FileSystem
97
+ const path = yield* Path.Path
98
+ const directory = yield* ConfigDirectory.pipe(
99
+ Effect.map(Option.getOrElse(() => ".")),
100
+ )
101
+ yield* Graft.provide(Listener, {
102
+ properties: properties(config.url),
103
+ bind: (tls) =>
104
+ factory(config, tls).pipe(
105
+ Effect.provideService(FileSystem.FileSystem, fs),
106
+ Effect.provideService(Path.Path, path),
107
+ Effect.provideService(ConfigDirectory, Option.some(directory)),
108
+ Effect.flatMap((server) =>
109
+ Server.bind(server, {
110
+ host: String.replace(/^\[|\]$/g, "")(config.url.hostname),
111
+ port: Number(
112
+ config.url.port || (config._tag === "wss" ? 443 : 80),
113
+ ),
114
+ }),
115
+ ),
116
+ Effect.mapBoth({
117
+ onSuccess: (server) => ({
118
+ ready: server.ready.pipe(
119
+ Effect.andThen(
120
+ Schema.encodeEffect(Listening)({
121
+ event: "Listening",
122
+ port:
123
+ server.address._tag === "UnixPathAddress"
124
+ ? null
125
+ : server.address.port,
126
+ }).pipe(Effect.orDie, Effect.flatMap(Console.log)),
127
+ ),
128
+ ),
129
+ serve: server.serve,
130
+ }),
131
+ onFailure: (error) =>
132
+ TransportError.make({ cause: Cause.fail(error) }),
133
+ }),
134
+ ),
135
+ })
136
+ }),
137
+ })
138
+ const Listening = Schema.fromJsonString(
139
+ Schema.Struct({
140
+ event: Schema.Literal("Listening"),
141
+ port: Schema.NullOr(Schema.Int),
142
+ }),
143
+ )