@graftland/plugin-remote 0.3.3 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (323) hide show
  1. package/README.md +18 -54
  2. package/README.zh-CN.md +17 -51
  3. package/README.zh-TW.md +17 -51
  4. package/dist/Auth.d.ts.map +1 -1
  5. package/dist/Auth.js.map +1 -1
  6. package/dist/Config.d.ts +1151 -0
  7. package/dist/Config.d.ts.map +1 -0
  8. package/dist/Config.js +183 -0
  9. package/dist/Config.js.map +1 -0
  10. package/dist/Contract.d.ts +1 -1
  11. package/dist/Contract.d.ts.map +1 -1
  12. package/dist/Contract.js +32 -1
  13. package/dist/Contract.js.map +1 -1
  14. package/dist/Instance.d.ts.map +1 -1
  15. package/dist/Instance.js.map +1 -1
  16. package/dist/Testing.d.ts +1 -1
  17. package/dist/Testing.d.ts.map +1 -1
  18. package/dist/Testing.js.map +1 -1
  19. package/dist/Transport.d.ts +1 -1
  20. package/dist/Transport.d.ts.map +1 -1
  21. package/dist/Transport.js.map +1 -1
  22. package/dist/cli.d.ts +4 -0
  23. package/dist/cli.d.ts.map +1 -0
  24. package/dist/cli.js +25 -0
  25. package/dist/cli.js.map +1 -0
  26. package/dist/host/auth/bearer.d.ts.map +1 -1
  27. package/dist/host/auth/bearer.js +4 -2
  28. package/dist/host/auth/bearer.js.map +1 -1
  29. package/dist/host/auth/jwt.d.ts.map +1 -1
  30. package/dist/host/auth/jwt.js +4 -2
  31. package/dist/host/auth/jwt.js.map +1 -1
  32. package/dist/host/auth/mtls.d.ts +3 -7
  33. package/dist/host/auth/mtls.d.ts.map +1 -1
  34. package/dist/host/auth/mtls.js +13 -14
  35. package/dist/host/auth/mtls.js.map +1 -1
  36. package/dist/host/auth/none.d.ts +1 -1
  37. package/dist/host/auth/none.js +7 -5
  38. package/dist/host/auth/none.js.map +1 -1
  39. package/dist/host/command.d.ts +1 -1
  40. package/dist/host/command.d.ts.map +1 -1
  41. package/dist/host/command.js +11 -9
  42. package/dist/host/command.js.map +1 -1
  43. package/dist/host/local.d.ts.map +1 -1
  44. package/dist/host/local.js +9 -30
  45. package/dist/host/local.js.map +1 -1
  46. package/dist/host/unix.d.ts +1 -1
  47. package/dist/host/unix.d.ts.map +1 -1
  48. package/dist/host/unix.js +13 -9
  49. package/dist/host/unix.js.map +1 -1
  50. package/dist/host/websocket.d.ts +1 -1
  51. package/dist/host/websocket.d.ts.map +1 -1
  52. package/dist/host/websocket.js +11 -8
  53. package/dist/host/websocket.js.map +1 -1
  54. package/dist/host/worker.d.ts +1 -1
  55. package/dist/host/worker.d.ts.map +1 -1
  56. package/dist/host/worker.js +13 -9
  57. package/dist/host/worker.js.map +1 -1
  58. package/dist/index.d.ts +6 -8
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +30 -64
  61. package/dist/index.js.map +1 -1
  62. package/dist/internal/Certificates.js.map +1 -1
  63. package/dist/internal/FailureGroup.js +6 -6
  64. package/dist/internal/FailureGroup.js.map +1 -1
  65. package/dist/internal/Peer.js.map +1 -1
  66. package/dist/internal/{ServeLifecycle.js → RunnerLifecycle.js} +6 -6
  67. package/dist/internal/RunnerLifecycle.js.map +1 -0
  68. package/dist/internal/Supervisor.js.map +1 -1
  69. package/dist/internal/assembly.d.ts +3 -3
  70. package/dist/internal/assembly.js +8 -8
  71. package/dist/internal/assembly.js.map +1 -1
  72. package/dist/internal/auth/config.d.ts +27 -0
  73. package/dist/internal/auth/config.d.ts.map +1 -0
  74. package/dist/internal/auth/config.js +29 -0
  75. package/dist/internal/auth/config.js.map +1 -0
  76. package/dist/internal/auth/mtls.js.map +1 -1
  77. package/dist/internal/auth/token.js.map +1 -1
  78. package/dist/internal/auth/tokenCredentials.d.ts +1 -1
  79. package/dist/internal/auth/tokenCredentials.d.ts.map +1 -1
  80. package/dist/internal/auth/tokenCredentials.js +1 -1
  81. package/dist/internal/auth/tokenCredentials.js.map +1 -1
  82. package/dist/internal/child.js +3 -3
  83. package/dist/internal/child.js.map +1 -1
  84. package/dist/internal/childMain.js +47 -0
  85. package/dist/internal/childMain.js.map +1 -0
  86. package/dist/internal/childRuntime.js +8 -8
  87. package/dist/internal/childRuntime.js.map +1 -1
  88. package/dist/internal/cleanup.js +3 -3
  89. package/dist/internal/cleanup.js.map +1 -1
  90. package/dist/internal/contract.js.map +1 -1
  91. package/dist/internal/credentials.d.ts +3 -2
  92. package/dist/internal/credentials.d.ts.map +1 -1
  93. package/dist/internal/credentials.js +1 -1
  94. package/dist/internal/credentials.js.map +1 -1
  95. package/dist/internal/directTransport.js.map +1 -1
  96. package/dist/internal/entry.d.ts +104 -26
  97. package/dist/internal/entry.d.ts.map +1 -1
  98. package/dist/internal/entry.js +22 -9
  99. package/dist/internal/entry.js.map +1 -1
  100. package/dist/internal/entryConfig.d.ts +2 -202
  101. package/dist/internal/entryConfig.js +2 -136
  102. package/dist/internal/entryConfig.js.map +1 -1
  103. package/dist/internal/execution.d.ts +4 -4
  104. package/dist/internal/execution.js +11 -11
  105. package/dist/internal/execution.js.map +1 -1
  106. package/dist/internal/follow.js +1 -1
  107. package/dist/internal/follow.js.map +1 -1
  108. package/dist/internal/forkTree.js.map +1 -1
  109. package/dist/internal/host/local.js.map +1 -1
  110. package/dist/internal/host/runner.js +4 -4
  111. package/dist/internal/host/runner.js.map +1 -1
  112. package/dist/internal/host.js +2 -2
  113. package/dist/internal/host.js.map +1 -1
  114. package/dist/internal/importer.js +1 -1
  115. package/dist/internal/importer.js.map +1 -1
  116. package/dist/internal/listenerStartup.js +1 -1
  117. package/dist/internal/listenerStartup.js.map +1 -1
  118. package/dist/internal/loadModule.js.map +1 -1
  119. package/dist/internal/platform.js +1 -9
  120. package/dist/internal/port.d.ts +1 -1
  121. package/dist/internal/port.js +2 -2
  122. package/dist/internal/port.js.map +1 -1
  123. package/dist/internal/runner/Bootstrap.js.map +1 -1
  124. package/dist/internal/runner/Connection.d.ts +3 -2
  125. package/dist/internal/runner/Connection.js +6 -6
  126. package/dist/internal/runner/Connection.js.map +1 -1
  127. package/dist/internal/runner/Execution.js +6 -6
  128. package/dist/internal/runner/Execution.js.map +1 -1
  129. package/dist/internal/runner/Local.js +1 -1
  130. package/dist/internal/runner/Local.js.map +1 -1
  131. package/dist/internal/runner/Lock.js.map +1 -1
  132. package/dist/internal/runner/Multiplex.js.map +1 -1
  133. package/dist/internal/runner/Packages.js.map +1 -1
  134. package/dist/internal/runner/ProcessObservation.js.map +1 -1
  135. package/dist/internal/runner/Processes.js.map +1 -1
  136. package/dist/internal/runner/Retention.js.map +1 -1
  137. package/dist/internal/runner/Store.js.map +1 -1
  138. package/dist/internal/runner/Supervisor.js +5 -5
  139. package/dist/internal/runner/Supervisor.js.map +1 -1
  140. package/dist/internal/runner/Watchdog.js.map +1 -1
  141. package/dist/internal/runner/Wire.d.ts +1 -1
  142. package/dist/internal/runner/Wire.js.map +1 -1
  143. package/dist/internal/runner/accept.js +2 -2
  144. package/dist/internal/runner/accept.js.map +1 -1
  145. package/dist/internal/runner/command.js +1 -1
  146. package/dist/internal/runner/command.js.map +1 -1
  147. package/dist/internal/runner/connectionEnded.js +1 -1
  148. package/dist/internal/runner/connectionEnded.js.map +1 -1
  149. package/dist/internal/runner/model.d.ts.map +1 -1
  150. package/dist/internal/runner/model.js.map +1 -1
  151. package/dist/internal/services.d.ts.map +1 -1
  152. package/dist/internal/services.js +1 -1
  153. package/dist/internal/services.js.map +1 -1
  154. package/dist/internal/socketChannel.js.map +1 -1
  155. package/dist/internal/stdioChannel.js.map +1 -1
  156. package/dist/internal/supervisorPlugin.js +48 -1
  157. package/dist/internal/supervisorPlugin.js.map +1 -1
  158. package/dist/internal/transportOptions.d.ts.map +1 -1
  159. package/dist/internal/watchdogMain.js +5 -3
  160. package/dist/internal/watchdogMain.js.map +1 -1
  161. package/dist/internal/websocket.js.map +1 -1
  162. package/dist/internal/websocketServer.js +1 -1
  163. package/dist/internal/websocketServer.js.map +1 -1
  164. package/dist/internal/workerChannel.js.map +1 -1
  165. package/dist/internal/workerMain.js +13 -6
  166. package/dist/internal/workerMain.js.map +1 -1
  167. package/dist/runner/auth/bearer.d.ts +3 -5
  168. package/dist/runner/auth/bearer.d.ts.map +1 -1
  169. package/dist/runner/auth/bearer.js +13 -11
  170. package/dist/runner/auth/bearer.js.map +1 -1
  171. package/dist/runner/auth/jwt.d.ts +4 -18
  172. package/dist/runner/auth/jwt.d.ts.map +1 -1
  173. package/dist/runner/auth/jwt.js +16 -28
  174. package/dist/runner/auth/jwt.js.map +1 -1
  175. package/dist/runner/auth/mtls.d.ts +3 -6
  176. package/dist/runner/auth/mtls.d.ts.map +1 -1
  177. package/dist/runner/auth/mtls.js +13 -29
  178. package/dist/runner/auth/mtls.js.map +1 -1
  179. package/dist/runner/auth/none.d.ts +1 -1
  180. package/dist/runner/auth/none.js +7 -5
  181. package/dist/runner/auth/none.js.map +1 -1
  182. package/dist/runner/index.d.ts +3 -308
  183. package/dist/runner/index.d.ts.map +1 -1
  184. package/dist/runner/index.js +62 -30
  185. package/dist/runner/index.js.map +1 -1
  186. package/dist/runner/stdio.d.ts +1 -1
  187. package/dist/runner/stdio.d.ts.map +1 -1
  188. package/dist/runner/stdio.js +11 -9
  189. package/dist/runner/stdio.js.map +1 -1
  190. package/dist/runner/unix.d.ts +1 -1
  191. package/dist/runner/unix.d.ts.map +1 -1
  192. package/dist/runner/unix.js +10 -8
  193. package/dist/runner/unix.js.map +1 -1
  194. package/dist/runner/websocket.d.ts +1 -1
  195. package/dist/runner/websocket.d.ts.map +1 -1
  196. package/dist/runner/websocket.js +12 -10
  197. package/dist/runner/websocket.js.map +1 -1
  198. package/package.json +14 -12
  199. package/schema.json +2269 -0
  200. package/src/Auth.ts +8 -2
  201. package/src/Config.ts +196 -0
  202. package/src/Contract.ts +12 -3
  203. package/src/Instance.ts +1 -0
  204. package/src/Testing.ts +6 -4
  205. package/src/Transport.ts +12 -3
  206. package/src/cli.ts +60 -0
  207. package/src/host/auth/bearer.ts +1 -0
  208. package/src/host/auth/jwt.ts +1 -0
  209. package/src/host/auth/mtls.ts +7 -12
  210. package/src/host/auth/none.ts +3 -1
  211. package/src/host/command.ts +8 -5
  212. package/src/host/local.ts +4 -2
  213. package/src/host/unix.ts +11 -7
  214. package/src/host/websocket.ts +10 -7
  215. package/src/host/worker.ts +8 -5
  216. package/src/index.ts +36 -23
  217. package/src/internal/Certificates.ts +1 -0
  218. package/src/internal/FailureGroup.ts +5 -3
  219. package/src/internal/Peer.ts +1 -0
  220. package/src/internal/{ServeLifecycle.ts → RunnerLifecycle.ts} +7 -5
  221. package/src/internal/Supervisor.ts +5 -4
  222. package/src/internal/assembly.ts +11 -9
  223. package/src/internal/auth/config.ts +44 -0
  224. package/src/internal/auth/mtls.ts +1 -0
  225. package/src/internal/auth/token.ts +1 -0
  226. package/src/internal/auth/tokenCredentials.ts +4 -2
  227. package/src/internal/child.ts +8 -6
  228. package/src/{bin.ts → internal/childMain.ts} +16 -61
  229. package/src/internal/childRuntime.ts +12 -10
  230. package/src/internal/cleanup.ts +3 -2
  231. package/src/internal/contract.ts +1 -0
  232. package/src/internal/credentials.ts +3 -1
  233. package/src/internal/directTransport.ts +9 -2
  234. package/src/internal/entry.ts +53 -16
  235. package/src/internal/entryConfig.ts +10 -132
  236. package/src/internal/execution.ts +17 -15
  237. package/src/internal/follow.ts +2 -1
  238. package/src/internal/forkTree.ts +2 -1
  239. package/src/internal/host/local.ts +1 -0
  240. package/src/internal/host/runner.ts +7 -5
  241. package/src/internal/host.ts +9 -8
  242. package/src/internal/importer.ts +3 -2
  243. package/src/internal/listenerStartup.ts +4 -2
  244. package/src/internal/loadModule.ts +1 -0
  245. package/src/internal/platform.ts +1 -12
  246. package/src/internal/port.ts +11 -6
  247. package/src/internal/runner/Bootstrap.ts +1 -0
  248. package/src/internal/runner/Connection.ts +13 -11
  249. package/src/internal/runner/Execution.ts +14 -13
  250. package/src/internal/runner/Local.ts +3 -2
  251. package/src/internal/runner/Lock.ts +1 -0
  252. package/src/internal/runner/Multiplex.ts +2 -1
  253. package/src/internal/runner/Packages.ts +7 -5
  254. package/src/internal/runner/ProcessObservation.ts +2 -1
  255. package/src/internal/runner/Processes.ts +3 -1
  256. package/src/internal/runner/Retention.ts +1 -0
  257. package/src/internal/runner/Store.ts +3 -2
  258. package/src/internal/runner/Supervisor.ts +22 -20
  259. package/src/internal/runner/Watchdog.ts +3 -1
  260. package/src/internal/runner/Wire.ts +13 -12
  261. package/src/internal/runner/accept.ts +6 -5
  262. package/src/internal/runner/command.ts +3 -2
  263. package/src/internal/runner/connectionEnded.ts +2 -1
  264. package/src/internal/runner/model.ts +5 -3
  265. package/src/internal/services.ts +9 -2
  266. package/src/internal/socketChannel.ts +2 -1
  267. package/src/internal/stdioChannel.ts +4 -2
  268. package/src/internal/supervisorPlugin.ts +10 -8
  269. package/src/internal/transportOptions.ts +1 -0
  270. package/src/internal/watchdogMain.ts +5 -3
  271. package/src/internal/websocket.ts +5 -2
  272. package/src/internal/websocketServer.ts +6 -4
  273. package/src/internal/workerChannel.ts +1 -0
  274. package/src/internal/workerMain.ts +21 -5
  275. package/src/runner/auth/bearer.ts +10 -6
  276. package/src/runner/auth/jwt.ts +10 -41
  277. package/src/runner/auth/mtls.ts +6 -3
  278. package/src/runner/auth/none.ts +3 -1
  279. package/src/runner/index.ts +102 -11
  280. package/src/runner/stdio.ts +15 -10
  281. package/src/runner/unix.ts +7 -4
  282. package/src/runner/websocket.ts +9 -7
  283. package/dist/Auth-BElTC9_X.js +0 -6
  284. package/dist/Bootstrap-H9gDsgsC.js +0 -9
  285. package/dist/ConfigDirectory-BCC6q2R4.js +0 -5
  286. package/dist/Contract-DsJtisvL.js +0 -83
  287. package/dist/Errors-DYhsGZcZ.js +0 -58
  288. package/dist/FailureGroup-BgT73AaR.js +0 -63
  289. package/dist/Framing-G9eSaeLb.js +0 -61
  290. package/dist/Graft-B71CPA2Y.js +0 -996
  291. package/dist/Packages-AgoCGotL.js +0 -108
  292. package/dist/Peer-DXeVrGBh.js +0 -342
  293. package/dist/ProcessObservation-gLgGirYv.js +0 -38
  294. package/dist/ServeLifecycle-Bd1FPJ6e.js +0 -24
  295. package/dist/Transport-DULzpsgR.js +0 -6
  296. package/dist/WatchdogProtocol-BZmVxrBP.js +0 -17
  297. package/dist/bin.js +0 -28276
  298. package/dist/bin.js.map +0 -1
  299. package/dist/childRuntime-Bm3iSg_N.js +0 -192
  300. package/dist/command-9zrHdbwT.js +0 -7
  301. package/dist/connectionEnded-BwcxQ7W8.js +0 -54
  302. package/dist/directTransport-DrexuPSm.js +0 -5
  303. package/dist/entry-psOpX3Bj.js +0 -736
  304. package/dist/importer-Cvf88eAY.js +0 -344
  305. package/dist/internal/ServeLifecycle.js.map +0 -1
  306. package/dist/internal/entryConfig.d.ts.map +0 -1
  307. package/dist/internal/platform.js.map +0 -1
  308. package/dist/internal/release.js +0 -25
  309. package/dist/internal/release.js.map +0 -1
  310. package/dist/internal/serve.js +0 -60
  311. package/dist/internal/serve.js.map +0 -1
  312. package/dist/port--3x2zJ4D.js +0 -285
  313. package/dist/release-DfZPuIcK.js +0 -23
  314. package/dist/rolldown-runtime-DYf_mQCB.js +0 -34
  315. package/dist/socketChannel-CJvL2DiB.js +0 -3658
  316. package/dist/supervisorPlugin-t6Z6PrhD.js +0 -733
  317. package/dist/token-CYBNNlhS.js +0 -17
  318. package/dist/tokenCredentials-CbCuk-Rt.js +0 -31
  319. package/dist/websocketServer-NQhODlEt.js +0 -60
  320. package/dist/workerChannel-C8hhBJzA.js +0 -27
  321. package/src/internal/release.ts +0 -72
  322. package/src/internal/serve.ts +0 -119
  323. /package/dist/{bin.d.ts → internal/childMain.d.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { TransportError } from "../../Errors.js";
2
- import { EndOfStream } from "./Framing.js";
3
2
  import { Peer } from "../Peer.js";
3
+ import { EndOfStream } from "./Framing.js";
4
4
  import { Array, Cause, Effect, Schema } from "effect";
5
5
  import { Socket } from "effect/socket";
6
6
  // src/internal/runner/connectionEnded.ts
@@ -1 +1 @@
1
- {"version":3,"file":"connectionEnded.js","names":[],"sources":["../../../src/internal/runner/connectionEnded.ts"],"sourcesContent":["import { Array, Cause, Effect, Schema } from \"effect\"\nimport { Socket } from \"effect/socket\"\nimport { TransportError } from \"../../Errors\"\nimport { EndOfStream } from \"./Framing\"\nimport { Peer } from \"../Peer\"\n\n// Multiplex preserves the socket reason inside TransportError; only an entirely normal close is silent.\nexport const closedNormally = (cause: Cause.Cause<unknown>): boolean =>\n\tcause.reasons.length > 0 &&\n\tArray.every(\n\t\tcause.reasons,\n\t\t(reason) =>\n\t\t\treason._tag === \"Fail\" &&\n\t\t\t(Schema.is(TransportError)(reason.error)\n\t\t\t\t? closedNormally(reason.error.cause)\n\t\t\t\t: Schema.is(EndOfStream)(reason.error) ||\n\t\t\t\t\t(Socket.isSocketError(reason.error) &&\n\t\t\t\t\t\treason.error.reason._tag === \"SocketCloseError\" &&\n\t\t\t\t\t\treason.error.reason.code === 1000)),\n\t)\nexport const connectionEnded = (cause: Cause.Cause<unknown>) =>\n\tCause.hasInterruptsOnly(cause) || closedNormally(cause)\n\t\t? Effect.void\n\t\t: Effect.flatMap(Peer, (identity) =>\n\t\t\t\tEffect.logWarning(\"Remote host connection failed\", cause).pipe(\n\t\t\t\t\tEffect.annotateLogs({ \"remote.peer\": identity }),\n\t\t\t\t),\n\t\t\t)\n"],"mappings":";;;;;;AAOA,MAAa,kBAAkB,UAC9B,MAAM,QAAQ,SAAS,KACvB,MAAM,MACL,MAAM,UACL,WACA,OAAO,SAAS,WACf,OAAO,GAAG,cAAc,CAAC,CAAC,OAAO,KAAK,IACpC,eAAe,OAAO,MAAM,KAAK,IACjC,OAAO,GAAG,WAAW,CAAC,CAAC,OAAO,KAAK,KACnC,OAAO,cAAc,OAAO,KAAK,KACjC,OAAO,MAAM,OAAO,SAAS,sBAC7B,OAAO,MAAM,OAAO,SAAS,IAClC;AACD,MAAa,mBAAmB,UAC/B,MAAM,kBAAkB,KAAK,KAAK,eAAe,KAAK,IACnD,OAAO,OACP,OAAO,QAAQ,OAAO,aACtB,OAAO,WAAW,iCAAiC,KAAK,CAAC,CAAC,KACzD,OAAO,aAAa,EAAE,eAAe,SAAS,CAAC,CAChD,CACD"}
1
+ {"version":3,"file":"connectionEnded.js","names":[],"sources":["../../../src/internal/runner/connectionEnded.ts"],"sourcesContent":["import { Array, Cause, Effect, Schema } from \"effect\"\nimport { Socket } from \"effect/socket\"\n\nimport { TransportError } from \"../../Errors\"\nimport { Peer } from \"../Peer\"\nimport { EndOfStream } from \"./Framing\"\n\n// Multiplex preserves the socket reason inside TransportError; only an entirely normal close is silent.\nexport const closedNormally = (cause: Cause.Cause<unknown>): boolean =>\n\tcause.reasons.length > 0 &&\n\tArray.every(\n\t\tcause.reasons,\n\t\t(reason) =>\n\t\t\treason._tag === \"Fail\" &&\n\t\t\t(Schema.is(TransportError)(reason.error)\n\t\t\t\t? closedNormally(reason.error.cause)\n\t\t\t\t: Schema.is(EndOfStream)(reason.error) ||\n\t\t\t\t\t(Socket.isSocketError(reason.error) &&\n\t\t\t\t\t\treason.error.reason._tag === \"SocketCloseError\" &&\n\t\t\t\t\t\treason.error.reason.code === 1000)),\n\t)\nexport const connectionEnded = (cause: Cause.Cause<unknown>) =>\n\tCause.hasInterruptsOnly(cause) || closedNormally(cause)\n\t\t? Effect.void\n\t\t: Effect.flatMap(Peer, (identity) =>\n\t\t\t\tEffect.logWarning(\"Remote host connection failed\", cause).pipe(\n\t\t\t\t\tEffect.annotateLogs({ \"remote.peer\": identity }),\n\t\t\t\t),\n\t\t\t)\n"],"mappings":";;;;;;AAQA,MAAa,kBAAkB,UAC9B,MAAM,QAAQ,SAAS,KACvB,MAAM,MACL,MAAM,UACL,WACA,OAAO,SAAS,WACf,OAAO,GAAG,cAAc,CAAC,CAAC,OAAO,KAAK,IACpC,eAAe,OAAO,MAAM,KAAK,IACjC,OAAO,GAAG,WAAW,CAAC,CAAC,OAAO,KAAK,KACnC,OAAO,cAAc,OAAO,KAAK,KACjC,OAAO,MAAM,OAAO,SAAS,sBAC7B,OAAO,MAAM,OAAO,SAAS,IAClC;AACD,MAAa,mBAAmB,UAC/B,MAAM,kBAAkB,KAAK,KAAK,eAAe,KAAK,IACnD,OAAO,OACP,OAAO,QAAQ,OAAO,aACtB,OAAO,WAAW,iCAAiC,KAAK,CAAC,CAAC,KACzD,OAAO,aAAa,EAAE,eAAe,SAAS,CAAC,CAChD,CACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","names":[],"sources":["../../../src/internal/runner/model.ts"],"mappings":";;;;;;;;;;;;WAgVmB;;qBAFN,qCAAqC"}
1
+ {"version":3,"file":"model.d.ts","names":[],"sources":["../../../src/internal/runner/model.ts"],"mappings":";;;;;;;;;;;;WAkVmB;;qBAFN,qCAAqC"}
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","names":[],"sources":["../../../src/internal/runner/model.ts"],"sourcesContent":["import { Limits, PositiveInt } from \"../Limits\"\nexport { Limits, PositiveInt, PositiveFinite, defaults } from \"../Limits\"\nimport {\n\tArray,\n\tCause,\n\tContext,\n\tData,\n\tDuration,\n\tEffect,\n\tOption,\n\tSchema,\n} from \"effect\"\nimport type { Scope } from \"effect\"\n\nconst diagnosticCause = Schema.Cause(\n\tSchema.Defect({ includeStack: true }),\n\tSchema.Defect({ includeStack: true }),\n)\nexport class PackageError extends Schema.TaggedError<\n\tPackageError,\n\t{ readonly brand: unique symbol }\n>()(\"PackageError\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class SessionAccessDenied extends Schema.TaggedError<\n\tSessionAccessDenied,\n\t{ readonly brand: unique symbol }\n>()(\"SessionAccessDenied\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class StaleSession extends Schema.TaggedError<\n\tStaleSession,\n\t{ readonly brand: unique symbol }\n>()(\"StaleSession\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class LeaseExpired extends Schema.TaggedError<\n\tLeaseExpired,\n\t{ readonly brand: unique symbol }\n>()(\"LeaseExpired\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class SessionStopped extends Schema.TaggedError<\n\tSessionStopped,\n\t{ readonly brand: unique symbol }\n>()(\"SessionStopped\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class SessionConflict extends Schema.TaggedError<\n\tSessionConflict,\n\t{ readonly brand: unique symbol }\n>()(\"SessionConflict\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class StateStorageError extends Schema.TaggedError<\n\tStateStorageError,\n\t{ readonly brand: unique symbol }\n>()(\"StateStorageError\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class ExecutionError extends Schema.TaggedError<\n\tExecutionError,\n\t{ readonly brand: unique symbol }\n>()(\"ExecutionError\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class TerminationUnconfirmed extends Schema.TaggedError<\n\tTerminationUnconfirmed,\n\t{ readonly brand: unique symbol }\n>()(\"TerminationUnconfirmed\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class RunnerClosing extends Schema.TaggedError<\n\tRunnerClosing,\n\t{ readonly brand: unique symbol }\n>()(\"RunnerClosing\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class StateDirectoryLocked extends Schema.TaggedError<\n\tStateDirectoryLocked,\n\t{ readonly brand: unique symbol }\n>()(\"StateDirectoryLocked\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport const Key = Schema.Struct({\n\tidentity: Schema.NonEmptyString,\n\tinstance: Schema.NonEmptyString,\n})\nexport type Key = typeof Key.Type\n/** Structural keys keep identity namespaces separate without delimiter conventions. */\nexport class SessionKey extends Data.Class<Key> {}\nexport const keyOf = (key: Key) => new SessionKey(key)\nexport const negotiate = (local: Limits, peer: Limits): Limits => ({\n\tcontrol: Math.min(local.control, peer.control),\n\tdata: Math.min(local.data, peer.data),\n\tlog: Math.min(local.log, peer.log),\n})\nexport const Handle = Schema.Struct({\n\tkey: Key,\n\ttoken: Schema.NonEmptyString,\n\tgeneration: PositiveInt,\n})\nexport type Handle = typeof Handle.Type\nexport const ProcessIdentity = Schema.Struct({\n\tpid: Schema.Int,\n\tstart: Schema.Struct({ born: Schema.String }),\n})\nexport type ProcessIdentity = typeof ProcessIdentity.Type\nexport const ExitStatus = Schema.Struct({\n\tstderr: Schema.optionalKey(Schema.String),\n\tcause: Schema.optionalKey(diagnosticCause),\n\tcode: Schema.NullOr(Schema.Int),\n\tsignal: Schema.NullOr(Schema.String),\n})\nexport type ExitStatus = typeof ExitStatus.Type\nexport const CodeIdentity = Schema.Struct({\n\tname: Schema.String,\n\tversion: Schema.String,\n\tdigest: Schema.optionalKey(Schema.String),\n})\nexport type CodeIdentity = typeof CodeIdentity.Type\nexport const Load = Schema.Struct({\n\tspecifier: Schema.String,\n\tdigest: Schema.optionalKey(Schema.Boolean),\n})\nexport type Load = typeof Load.Type\nexport const Termination = Schema.Struct({\n\tkind: Schema.Literals([\"Exited\", \"Killed\"]),\n\texit: ExitStatus,\n\tcause: diagnosticCause,\n})\nexport type Termination = typeof Termination.Type\nconst Fields = {\n\tversion: Schema.Literal(1),\n\thandle: Handle,\n\trequestId: Schema.String,\n\tleaseMillis: Schema.Finite,\n\tlimits: Limits,\n}\nexport const OpenRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Open\"),\n})\nexport const Launch = Schema.Union([\n\tSchema.TaggedStruct(\"Starting\", {}),\n\tSchema.TaggedStruct(\"Registered\", { child: ProcessIdentity }),\n])\nexport const LoadingRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Loading\"),\n\tload: Load,\n\tlaunch: Launch,\n})\nexport const LoadedRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Loaded\"),\n\tload: Load,\n\tchild: ProcessIdentity,\n\tcode: CodeIdentity,\n})\nexport const ActiveRecord = Schema.Union([\n\tOpenRecord,\n\tLoadingRecord,\n\tLoadedRecord,\n])\nexport type ActiveRecord = typeof ActiveRecord.Type\nexport const StopReason = Schema.Union([\n\t...Array.map(\n\t\t[\n\t\t\t\"Disposed\",\n\t\t\t\"Expired\",\n\t\t\t\"Superseded\",\n\t\t\t\"Recovery\",\n\t\t\t\"Shutdown\",\n\t\t\t\"Exited\",\n\t\t] as const,\n\t\t(tag) => Schema.TaggedStruct(tag, {}),\n\t),\n\tSchema.TaggedStruct(\"LoadFailed\", { cause: diagnosticCause }),\n])\nexport type StopReason = typeof StopReason.Type\nexport const StoppingRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Stopping\"),\n\tprevious: ActiveRecord,\n\treason: StopReason,\n})\nexport const StoppedRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Stopped\"),\n\tprevious: ActiveRecord,\n\treason: StopReason,\n\ttermination: Termination,\n})\nexport const SessionRecord = Schema.Union([\n\tOpenRecord,\n\tLoadingRecord,\n\tLoadedRecord,\n\tStoppingRecord,\n\tStoppedRecord,\n])\nexport type SessionRecord = typeof SessionRecord.Type\nexport const childOf = (\n\trecord: SessionRecord,\n): Option.Option<ProcessIdentity> => {\n\tswitch (record.phase) {\n\t\tcase \"Open\":\n\t\t\treturn Option.none()\n\t\tcase \"Loading\":\n\t\t\treturn record.launch._tag === \"Registered\"\n\t\t\t\t? Option.some(record.launch.child)\n\t\t\t\t: Option.none()\n\t\tcase \"Loaded\":\n\t\t\treturn Option.some(record.child)\n\t\tcase \"Stopping\":\n\t\tcase \"Stopped\":\n\t\t\treturn childOf(record.previous)\n\t}\n}\nexport const stoppingRecord = (\n\tprevious: ActiveRecord,\n\treason: StopReason,\n): typeof StoppingRecord.Type => ({\n\tversion: previous.version,\n\thandle: previous.handle,\n\trequestId: previous.requestId,\n\tleaseMillis: previous.leaseMillis,\n\tlimits: previous.limits,\n\tphase: \"Stopping\",\n\tprevious,\n\treason,\n})\nexport const stoppedRecord = (\n\tprevious: ActiveRecord,\n\treason: StopReason,\n\ttermination: Termination,\n): typeof StoppedRecord.Type => ({\n\t...stoppingRecord(previous, reason),\n\tphase: \"Stopped\",\n\ttermination,\n})\n\nexport class Store extends Context.Service<\n\tStore,\n\t{\n\t\treadonly list: Effect.Effect<\n\t\t\tReadonlyArray<SessionRecord>,\n\t\t\tStateStorageError\n\t\t>\n\t\treadonly save: (\n\t\t\trecord: SessionRecord,\n\t\t) => Effect.Effect<void, StateStorageError>\n\t}\n>()(\"@graftland/plugin-remote/internal/runner/model/Store\") {}\nexport type ExecutionFailure =\n\tExecutionError | PackageError | TerminationUnconfirmed\nexport interface Unit {\n\treadonly code: CodeIdentity\n\t/** The supervisor persists identity and renews the lease before releasing the child startup gate. */\n\treadonly start: Effect.Effect<void, ExecutionFailure>\n\treadonly identity: ProcessIdentity\n\treadonly exited: Effect.Effect<ExitStatus, ExecutionFailure>\n\treadonly interrupt: Effect.Effect<void, ExecutionFailure>\n\treadonly kill: Effect.Effect<void, ExecutionFailure>\n\treadonly renew: (millis: number) => Effect.Effect<void, ExecutionFailure>\n}\nexport class Execution extends Context.Service<\n\tExecution,\n\t{\n\t\treadonly spawn: (\n\t\t\thandle: Handle,\n\t\t\trequest: Load,\n\t\t\tlimits: Limits,\n\t\t) => Effect.Effect<Unit, ExecutionFailure, Scope.Scope>\n\t\treadonly recover: (\n\t\t\tchild: ProcessIdentity,\n\t\t) => Effect.Effect<Termination, ExecutionFailure>\n\t}\n>()(\"@graftland/plugin-remote/internal/runner/model/Execution\") {}\nexport class RemoteTerminationUnconfirmed extends Schema.TaggedError<\n\tRemoteTerminationUnconfirmed,\n\t{ readonly brand: unique symbol }\n>()(\"RemoteTerminationUnconfirmed\", { handle: Handle }) {}\n/** Losing contact never becomes a successful stop merely because a lease duration passed. */\nexport const awaitTermination = Effect.fnUntraced(function* <E, R>(\n\thandle: Handle,\n\tconfirmation: Effect.Effect<Termination, E, R>,\n\tleaseMillis: number,\n\tmarginMillis: number,\n) {\n\tconst [elapsed, result] = yield* Effect.exit(\n\t\tEffect.timeoutOption(confirmation, leaseMillis + marginMillis),\n\t).pipe(Effect.timed)\n\tif (result._tag === \"Success\") {\n\t\tif (Option.isSome(result.value)) return result.value.value\n\t\treturn yield* RemoteTerminationUnconfirmed.make({ handle })\n\t}\n\t// Confirmation and the disconnected wait share one deadline.\n\tyield* Effect.sleep(\n\t\tMath.max(0, leaseMillis + marginMillis - Duration.toMillis(elapsed)),\n\t)\n\treturn yield* Effect.failCause(\n\t\tCause.combine(\n\t\t\tresult.cause,\n\t\t\tCause.fail(RemoteTerminationUnconfirmed.make({ handle })),\n\t\t),\n\t)\n})\n"],"mappings":";;;AAcA,MAAM,kBAAkB,OAAO,MAC9B,OAAO,OAAO,EAAE,cAAc,KAAK,CAAC,GACpC,OAAO,OAAO,EAAE,cAAc,KAAK,CAAC,CACrC;AACA,IAAa,eAAb,cAAkC,OAAO,YAGvC,CAAC,CAAC,gBAAgB;CACnB,QAAQ,OAAO;CACf,OAAO,OAAO,YAAY,eAAe;AAC1C,CA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AAC,KAAK,OAAO,KAAK;CACnB,IAAI,OAAO,SAAS,WAAW;EAC9B,IAAI,OAAO,OAAO,OAAO,KAAK,GAAG,OAAO,OAAO,MAAM;EACrD,OAAO,OAAO,6BAA6B,KAAK,EAAE,OAAO,CAAC;CAC3D;CAEA,OAAO,OAAO,MACb,KAAK,IAAI,GAAG,cAAc,eAAe,SAAS,SAAS,OAAO,CAAC,CACpE;CACA,OAAO,OAAO,OAAO,UACpB,MAAM,QACL,OAAO,OACP,MAAM,KAAK,6BAA6B,KAAK,EAAE,OAAO,CAAC,CAAC,CACzD,CACD;AACD,CAAC"}
1
+ {"version":3,"file":"model.js","names":[],"sources":["../../../src/internal/runner/model.ts"],"sourcesContent":["import {\n\tArray,\n\tCause,\n\tContext,\n\tData,\n\tDuration,\n\tEffect,\n\tOption,\n\tSchema,\n\ttype Scope,\n} from \"effect\"\n\nimport { Limits, PositiveInt } from \"../Limits\"\n\nexport { Limits, PositiveInt, PositiveFinite, defaults } from \"../Limits\"\n\nconst diagnosticCause = Schema.Cause(\n\tSchema.Defect({ includeStack: true }),\n\tSchema.Defect({ includeStack: true }),\n)\nexport class PackageError extends Schema.TaggedError<\n\tPackageError,\n\t{ readonly brand: unique symbol }\n>()(\"PackageError\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class SessionAccessDenied extends Schema.TaggedError<\n\tSessionAccessDenied,\n\t{ readonly brand: unique symbol }\n>()(\"SessionAccessDenied\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class StaleSession extends Schema.TaggedError<\n\tStaleSession,\n\t{ readonly brand: unique symbol }\n>()(\"StaleSession\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class LeaseExpired extends Schema.TaggedError<\n\tLeaseExpired,\n\t{ readonly brand: unique symbol }\n>()(\"LeaseExpired\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class SessionStopped extends Schema.TaggedError<\n\tSessionStopped,\n\t{ readonly brand: unique symbol }\n>()(\"SessionStopped\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class SessionConflict extends Schema.TaggedError<\n\tSessionConflict,\n\t{ readonly brand: unique symbol }\n>()(\"SessionConflict\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class StateStorageError extends Schema.TaggedError<\n\tStateStorageError,\n\t{ readonly brand: unique symbol }\n>()(\"StateStorageError\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class ExecutionError extends Schema.TaggedError<\n\tExecutionError,\n\t{ readonly brand: unique symbol }\n>()(\"ExecutionError\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class TerminationUnconfirmed extends Schema.TaggedError<\n\tTerminationUnconfirmed,\n\t{ readonly brand: unique symbol }\n>()(\"TerminationUnconfirmed\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class RunnerClosing extends Schema.TaggedError<\n\tRunnerClosing,\n\t{ readonly brand: unique symbol }\n>()(\"RunnerClosing\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport class StateDirectoryLocked extends Schema.TaggedError<\n\tStateDirectoryLocked,\n\t{ readonly brand: unique symbol }\n>()(\"StateDirectoryLocked\", {\n\tdetail: Schema.String,\n\tcause: Schema.optionalKey(diagnosticCause),\n}) {\n\toverride get message() {\n\t\treturn this.detail\n\t}\n}\nexport const Key = Schema.Struct({\n\tidentity: Schema.NonEmptyString,\n\tinstance: Schema.NonEmptyString,\n})\nexport type Key = typeof Key.Type\n/** Structural keys keep identity namespaces separate without delimiter conventions. */\nexport class SessionKey extends Data.Class<Key> {}\nexport const keyOf = (key: Key) => new SessionKey(key)\nexport const negotiate = (local: Limits, peer: Limits): Limits => ({\n\tcontrol: Math.min(local.control, peer.control),\n\tdata: Math.min(local.data, peer.data),\n\tlog: Math.min(local.log, peer.log),\n})\nexport const Handle = Schema.Struct({\n\tkey: Key,\n\ttoken: Schema.NonEmptyString,\n\tgeneration: PositiveInt,\n})\nexport type Handle = typeof Handle.Type\nexport const ProcessIdentity = Schema.Struct({\n\tpid: Schema.Int,\n\tstart: Schema.Struct({ born: Schema.String }),\n})\nexport type ProcessIdentity = typeof ProcessIdentity.Type\nexport const ExitStatus = Schema.Struct({\n\tstderr: Schema.optionalKey(Schema.String),\n\tcause: Schema.optionalKey(diagnosticCause),\n\tcode: Schema.NullOr(Schema.Int),\n\tsignal: Schema.NullOr(Schema.String),\n})\nexport type ExitStatus = typeof ExitStatus.Type\nexport const CodeIdentity = Schema.Struct({\n\tname: Schema.String,\n\tversion: Schema.String,\n\tdigest: Schema.optionalKey(Schema.String),\n})\nexport type CodeIdentity = typeof CodeIdentity.Type\nexport const Load = Schema.Struct({\n\tspecifier: Schema.String,\n\tdigest: Schema.optionalKey(Schema.Boolean),\n})\nexport type Load = typeof Load.Type\nexport const Termination = Schema.Struct({\n\tkind: Schema.Literals([\"Exited\", \"Killed\"]),\n\texit: ExitStatus,\n\tcause: diagnosticCause,\n})\nexport type Termination = typeof Termination.Type\nconst Fields = {\n\tversion: Schema.Literal(1),\n\thandle: Handle,\n\trequestId: Schema.String,\n\tleaseMillis: Schema.Finite,\n\tlimits: Limits,\n}\nexport const OpenRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Open\"),\n})\nexport const Launch = Schema.Union([\n\tSchema.TaggedStruct(\"Starting\", {}),\n\tSchema.TaggedStruct(\"Registered\", { child: ProcessIdentity }),\n])\nexport const LoadingRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Loading\"),\n\tload: Load,\n\tlaunch: Launch,\n})\nexport const LoadedRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Loaded\"),\n\tload: Load,\n\tchild: ProcessIdentity,\n\tcode: CodeIdentity,\n})\nexport const ActiveRecord = Schema.Union([\n\tOpenRecord,\n\tLoadingRecord,\n\tLoadedRecord,\n])\nexport type ActiveRecord = typeof ActiveRecord.Type\nexport const StopReason = Schema.Union([\n\t...Array.map(\n\t\t[\n\t\t\t\"Disposed\",\n\t\t\t\"Expired\",\n\t\t\t\"Superseded\",\n\t\t\t\"Recovery\",\n\t\t\t\"Shutdown\",\n\t\t\t\"Exited\",\n\t\t] as const,\n\t\t(tag) => Schema.TaggedStruct(tag, {}),\n\t),\n\tSchema.TaggedStruct(\"LoadFailed\", { cause: diagnosticCause }),\n])\nexport type StopReason = typeof StopReason.Type\nexport const StoppingRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Stopping\"),\n\tprevious: ActiveRecord,\n\treason: StopReason,\n})\nexport const StoppedRecord = Schema.Struct({\n\t...Fields,\n\tphase: Schema.Literal(\"Stopped\"),\n\tprevious: ActiveRecord,\n\treason: StopReason,\n\ttermination: Termination,\n})\nexport const SessionRecord = Schema.Union([\n\tOpenRecord,\n\tLoadingRecord,\n\tLoadedRecord,\n\tStoppingRecord,\n\tStoppedRecord,\n])\nexport type SessionRecord = typeof SessionRecord.Type\nexport const childOf = (\n\trecord: SessionRecord,\n): Option.Option<ProcessIdentity> => {\n\tswitch (record.phase) {\n\t\tcase \"Open\":\n\t\t\treturn Option.none()\n\t\tcase \"Loading\":\n\t\t\treturn record.launch._tag === \"Registered\"\n\t\t\t\t? Option.some(record.launch.child)\n\t\t\t\t: Option.none()\n\t\tcase \"Loaded\":\n\t\t\treturn Option.some(record.child)\n\t\tcase \"Stopping\":\n\t\tcase \"Stopped\":\n\t\t\treturn childOf(record.previous)\n\t}\n}\nexport const stoppingRecord = (\n\tprevious: ActiveRecord,\n\treason: StopReason,\n): typeof StoppingRecord.Type => ({\n\tversion: previous.version,\n\thandle: previous.handle,\n\trequestId: previous.requestId,\n\tleaseMillis: previous.leaseMillis,\n\tlimits: previous.limits,\n\tphase: \"Stopping\",\n\tprevious,\n\treason,\n})\nexport const stoppedRecord = (\n\tprevious: ActiveRecord,\n\treason: StopReason,\n\ttermination: Termination,\n): typeof StoppedRecord.Type => ({\n\t...stoppingRecord(previous, reason),\n\tphase: \"Stopped\",\n\ttermination,\n})\n\nexport class Store extends Context.Service<\n\tStore,\n\t{\n\t\treadonly list: Effect.Effect<\n\t\t\tReadonlyArray<SessionRecord>,\n\t\t\tStateStorageError\n\t\t>\n\t\treadonly save: (\n\t\t\trecord: SessionRecord,\n\t\t) => Effect.Effect<void, StateStorageError>\n\t}\n>()(\"@graftland/plugin-remote/internal/runner/model/Store\") {}\nexport type ExecutionFailure =\n\tExecutionError | PackageError | TerminationUnconfirmed\nexport interface Unit {\n\treadonly code: CodeIdentity\n\t/** The supervisor persists identity and renews the lease before releasing the child startup gate. */\n\treadonly start: Effect.Effect<void, ExecutionFailure>\n\treadonly identity: ProcessIdentity\n\treadonly exited: Effect.Effect<ExitStatus, ExecutionFailure>\n\treadonly interrupt: Effect.Effect<void, ExecutionFailure>\n\treadonly kill: Effect.Effect<void, ExecutionFailure>\n\treadonly renew: (millis: number) => Effect.Effect<void, ExecutionFailure>\n}\nexport class Execution extends Context.Service<\n\tExecution,\n\t{\n\t\treadonly spawn: (\n\t\t\thandle: Handle,\n\t\t\trequest: Load,\n\t\t\tlimits: Limits,\n\t\t) => Effect.Effect<Unit, ExecutionFailure, Scope.Scope>\n\t\treadonly recover: (\n\t\t\tchild: ProcessIdentity,\n\t\t) => Effect.Effect<Termination, ExecutionFailure>\n\t}\n>()(\"@graftland/plugin-remote/internal/runner/model/Execution\") {}\nexport class RemoteTerminationUnconfirmed extends Schema.TaggedError<\n\tRemoteTerminationUnconfirmed,\n\t{ readonly brand: unique symbol }\n>()(\"RemoteTerminationUnconfirmed\", { handle: Handle }) {}\n/** Losing contact never becomes a successful stop merely because a lease duration passed. */\nexport const awaitTermination = Effect.fnUntraced(function* <E, R>(\n\thandle: Handle,\n\tconfirmation: Effect.Effect<Termination, E, R>,\n\tleaseMillis: number,\n\tmarginMillis: number,\n) {\n\tconst [elapsed, result] = yield* Effect.exit(\n\t\tEffect.timeoutOption(confirmation, leaseMillis + marginMillis),\n\t).pipe(Effect.timed)\n\tif (result._tag === \"Success\") {\n\t\tif (Option.isSome(result.value)) return result.value.value\n\t\treturn yield* RemoteTerminationUnconfirmed.make({ handle })\n\t}\n\t// Confirmation and the disconnected wait share one deadline.\n\tyield* Effect.sleep(\n\t\tMath.max(0, leaseMillis + marginMillis - Duration.toMillis(elapsed)),\n\t)\n\treturn yield* Effect.failCause(\n\t\tCause.combine(\n\t\t\tresult.cause,\n\t\t\tCause.fail(RemoteTerminationUnconfirmed.make({ handle })),\n\t\t),\n\t)\n})\n"],"mappings":";;;AAgBA,MAAM,kBAAkB,OAAO,MAC9B,OAAO,OAAO,EAAE,cAAc,KAAK,CAAC,GACpC,OAAO,OAAO,EAAE,cAAc,KAAK,CAAC,CACrC;AACA,IAAa,eAAb,cAAkC,OAAO,YAGvC,CAAC,CAAC,gBAAgB;CACnB,QAAQ,OAAO;CACf,OAAO,OAAO,YAAY,eAAe;AAC1C,CAAC,CAAC,CAAC;CACF,IAAa,UAAU;EACtB,OAAO,KAAK;CACb;AACD;AACA,IAAa,sBAAb,cAAyC,OAAO,YAG9C,CAAC,CAAC,uBAAuB;CAC1B,QAAQ,OAA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6B,KAAK,EAAE,OAAO,CAAC;CAC3D;CAEA,OAAO,OAAO,MACb,KAAK,IAAI,GAAG,cAAc,eAAe,SAAS,SAAS,OAAO,CAAC,CACpE;CACA,OAAO,OAAO,OAAO,UACpB,MAAM,QACL,OAAO,OACP,MAAM,KAAK,6BAA6B,KAAK,EAAE,OAAO,CAAC,CAAC,CACzD,CACD;AACD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.ts","names":[],"sources":["../../src/internal/services.ts"],"mappings":";;;qBAMa,UACZ,GACA,GACA,UAAU,IAAI,KACd,UAAU,SAAS,aAAa,IAAE,KAE7B,QAAQ,IAAI,GAAG,IAAE,OACf,SAAS,SAAS,IAAE;WAEjB,aAAa,OAAO,MAAM;WAC1B,aACR,QAAQ,UAAU,UAAU,GAAG,eAAe,oBAC1C;MAEJ,QACF,SAAS,iBAAiB,GAAG,KAAK,IAAI,WAAW,KAAK,IAAI,eAAe,IACzE,IAAI,iBAAiB"}
1
+ {"version":3,"file":"services.d.ts","names":[],"sources":["../../src/internal/services.ts"],"mappings":";;;qBAaa,UACZ,GACA,GACA,UAAU,IAAI,KACd,UAAU,SAAS,aAAa,IAAE,KAE7B,QAAQ,IAAI,GAAG,IAAE,OACf,SAAS,SAAS,IAAE;WAEjB,aAAa,OAAO,MAAM;WAC1B,aACR,QAAQ,UAAU,UAAU,GAAG,eAAe,oBAC1C;MAEJ,QACF,SAAS,iBAAiB,GAAG,KAAK,IAAI,WAAW,KAAK,IAAI,eAAe,IACzE,IAAI,iBAAiB"}
@@ -1,5 +1,5 @@
1
- import { Graft } from "@graftland/graft";
2
1
  import { Array, Context, Effect, Record } from "effect";
2
+ import { Graft } from "@graftland/graft";
3
3
  import { RpcClient, RpcServer } from "effect/rpc";
4
4
  // src/internal/services.ts
5
5
  const service = (key, group, mapping) => ({
@@ -1 +1 @@
1
- {"version":3,"file":"services.js","names":[],"sources":["../../src/internal/services.ts"],"sourcesContent":["import { Array, Context, Effect, Record } from \"effect\"\nimport { Graft } from \"@graftland/graft\"\nimport { RpcClient, RpcServer } from \"effect/rpc\"\nimport type { Rpc, RpcClientError, RpcGroup } from \"effect/rpc\"\nimport type { Service } from \"../Contract\"\n\nexport const service = <\n\tI,\n\tS,\n\tR extends Rpc.Any,\n\tH extends RpcGroup.HandlersFrom<R>,\n>(\n\tkey: Context.Key<I, S>,\n\tgroup: RpcGroup.RpcGroup<R>,\n\tmapping: {\n\t\treadonly toHandlers: (value: S) => H\n\t\treadonly fromClient: (\n\t\t\tclient: RpcClient.RpcClient<R, RpcClientError.RpcClientError>,\n\t\t) => S\n\t},\n): Service<\n\tRpcGroup.HandlersServices<R, H> | Rpc.Middleware<R> | Rpc.ServicesServer<R>,\n\tRpc.MiddlewareClient<R>\n> => ({\n\tkey,\n\tgroup,\n\tserve: Effect.fnUntraced(function* (port) {\n\t\t// Graft admits the activation from this descriptor's key before serving it.\n\t\tconst context = yield* Effect.context<never>()\n\t\tconst value = yield* Effect.fromOption(\n\t\t\tContext.getOption(context, key),\n\t\t).pipe(Effect.orDie)\n\t\tconst handlers = yield* group.toHandlers(mapping.toHandlers(value))\n\t\treturn yield* RpcServer.make(group, { disableFatalDefects: true }).pipe(\n\t\t\tEffect.provideContext(handlers),\n\t\t\tEffect.provideService(RpcServer.Protocol, port.serverProtocol(key.key)),\n\t\t)\n\t}),\n\tpublish: Effect.fnUntraced(function* (port) {\n\t\tconst client = yield* RpcClient.make(group).pipe(\n\t\t\tEffect.provideService(RpcClient.Protocol, port.clientProtocol(key.key)),\n\t\t)\n\t\tyield* Graft.provide(key, mapping.fromClient(client))\n\t}),\n})\nexport const endpoints = (services: ReadonlyArray<Service>) =>\n\tRecord.fromEntries(\n\t\tArray.map(\n\t\t\tservices,\n\t\t\t(service) =>\n\t\t\t\t[service.key.key, service.group] satisfies readonly [\n\t\t\t\t\tstring,\n\t\t\t\t\tService[\"group\"],\n\t\t\t\t],\n\t\t),\n\t)\n"],"mappings":";;;;AAMA,MAAa,WAMZ,KACA,OACA,aASK;CACL;CACA;CACA,OAAO,OAAO,WAAW,WAAW,MAAM;EAEzC,MAAM,UAAU,OAAO,OAAO,QAAe;EAC7C,MAAM,QAAQ,OAAO,OAAO,WAC3B,QAAQ,UAAU,SAAS,GAAG,CAC/B,CAAC,CAAC,KAAK,OAAO,KAAK;EACnB,MAAM,WAAW,OAAO,MAAM,WAAW,QAAQ,WAAW,KAAK,CAAC;EAClE,OAAO,OAAO,UAAU,KAAK,OAAO,EAAE,qBAAqB,KAAK,CAAC,CAAC,CAAC,KAClE,OAAO,eAAe,QAAQ,GAC9B,OAAO,eAAe,UAAU,UAAU,KAAK,eAAe,IAAI,GAAG,CAAC,CACvE;CACD,CAAC;CACD,SAAS,OAAO,WAAW,WAAW,MAAM;EAC3C,MAAM,SAAS,OAAO,UAAU,KAAK,KAAK,CAAC,CAAC,KAC3C,OAAO,eAAe,UAAU,UAAU,KAAK,eAAe,IAAI,GAAG,CAAC,CACvE;EACA,OAAO,MAAM,QAAQ,KAAK,QAAQ,WAAW,MAAM,CAAC;CACrD,CAAC;AACF;AACA,MAAa,aAAa,aACzB,OAAO,YACN,MAAM,IACL,WACC,YACA,CAAC,QAAQ,IAAI,KAAK,QAAQ,KAAK,CAIjC,CACD"}
1
+ {"version":3,"file":"services.js","names":[],"sources":["../../src/internal/services.ts"],"sourcesContent":["import { Array, Context, Effect, Record } from \"effect\"\nimport {\n\tRpcClient,\n\tRpcServer,\n\ttype Rpc,\n\ttype RpcClientError,\n\ttype RpcGroup,\n} from \"effect/rpc\"\n\nimport { Graft } from \"@graftland/graft\"\n\nimport type { Service } from \"../Contract\"\n\nexport const service = <\n\tI,\n\tS,\n\tR extends Rpc.Any,\n\tH extends RpcGroup.HandlersFrom<R>,\n>(\n\tkey: Context.Key<I, S>,\n\tgroup: RpcGroup.RpcGroup<R>,\n\tmapping: {\n\t\treadonly toHandlers: (value: S) => H\n\t\treadonly fromClient: (\n\t\t\tclient: RpcClient.RpcClient<R, RpcClientError.RpcClientError>,\n\t\t) => S\n\t},\n): Service<\n\tRpcGroup.HandlersServices<R, H> | Rpc.Middleware<R> | Rpc.ServicesServer<R>,\n\tRpc.MiddlewareClient<R>\n> => ({\n\tkey,\n\tgroup,\n\tserve: Effect.fnUntraced(function* (port) {\n\t\t// Graft admits the activation from this descriptor's key before serving it.\n\t\tconst context = yield* Effect.context<never>()\n\t\tconst value = yield* Effect.fromOption(\n\t\t\tContext.getOption(context, key),\n\t\t).pipe(Effect.orDie)\n\t\tconst handlers = yield* group.toHandlers(mapping.toHandlers(value))\n\t\treturn yield* RpcServer.make(group, { disableFatalDefects: true }).pipe(\n\t\t\tEffect.provideContext(handlers),\n\t\t\tEffect.provideService(RpcServer.Protocol, port.serverProtocol(key.key)),\n\t\t)\n\t}),\n\tpublish: Effect.fnUntraced(function* (port) {\n\t\tconst client = yield* RpcClient.make(group).pipe(\n\t\t\tEffect.provideService(RpcClient.Protocol, port.clientProtocol(key.key)),\n\t\t)\n\t\tyield* Graft.provide(key, mapping.fromClient(client))\n\t}),\n})\nexport const endpoints = (services: ReadonlyArray<Service>) =>\n\tRecord.fromEntries(\n\t\tArray.map(\n\t\t\tservices,\n\t\t\t(service) =>\n\t\t\t\t[service.key.key, service.group] satisfies readonly [\n\t\t\t\t\tstring,\n\t\t\t\t\tService[\"group\"],\n\t\t\t\t],\n\t\t),\n\t)\n"],"mappings":";;;;AAaA,MAAa,WAMZ,KACA,OACA,aASK;CACL;CACA;CACA,OAAO,OAAO,WAAW,WAAW,MAAM;EAEzC,MAAM,UAAU,OAAO,OAAO,QAAe;EAC7C,MAAM,QAAQ,OAAO,OAAO,WAC3B,QAAQ,UAAU,SAAS,GAAG,CAC/B,CAAC,CAAC,KAAK,OAAO,KAAK;EACnB,MAAM,WAAW,OAAO,MAAM,WAAW,QAAQ,WAAW,KAAK,CAAC;EAClE,OAAO,OAAO,UAAU,KAAK,OAAO,EAAE,qBAAqB,KAAK,CAAC,CAAC,CAAC,KAClE,OAAO,eAAe,QAAQ,GAC9B,OAAO,eAAe,UAAU,UAAU,KAAK,eAAe,IAAI,GAAG,CAAC,CACvE;CACD,CAAC;CACD,SAAS,OAAO,WAAW,WAAW,MAAM;EAC3C,MAAM,SAAS,OAAO,UAAU,KAAK,KAAK,CAAC,CAAC,KAC3C,OAAO,eAAe,UAAU,UAAU,KAAK,eAAe,IAAI,GAAG,CAAC,CACvE;EACA,OAAO,MAAM,QAAQ,KAAK,QAAQ,WAAW,MAAM,CAAC;CACrD,CAAC;AACF;AACA,MAAa,aAAa,aACzB,OAAO,YACN,MAAM,IACL,WACC,YACA,CAAC,QAAQ,IAAI,KAAK,QAAQ,KAAK,CAIjC,CACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"socketChannel.js","names":[],"sources":["../../src/internal/socketChannel.ts"],"sourcesContent":["import { Cause, Effect, Exit, Sink, Stream } from \"effect\"\nimport { Socket } from \"effect/socket\"\nimport { TransportError } from \"../Errors\"\nimport { FrameError, isCompleteFrame, decoder, encode } from \"./runner/Framing\"\n\n/** WebSocket boundaries are a wire compatibility detail, not Channel chunk boundaries. */\nexport const fromSocket = Effect.fnUntraced(function* (socket: Socket.Socket) {\n\tconst reader = yield* socket.reader\n\tconst writer = yield* socket.writer\n\treturn {\n\t\tinput: Stream.fromEffectRepeat(reader.pull).pipe(\n\t\t\tStream.catchTag(\"SocketError\", (error) =>\n\t\t\t\terror.reason._tag === \"SocketCloseError\" && error.reason.code === 1000\n\t\t\t\t\t? Stream.empty\n\t\t\t\t\t: Stream.fail(error),\n\t\t\t),\n\t\t\tStream.flattenIterable,\n\t\t\tStream.mapEffect((bytes) => {\n\t\t\t\tif (typeof bytes === \"string\")\n\t\t\t\t\treturn Effect.fail(\n\t\t\t\t\t\tFrameError.make({\n\t\t\t\t\t\t\tdetail: \"Runner WebSocket messages must be binary\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t// WebSocket messages preserve one complete framing frame, including its header.\n\t\t\t\tif (!isCompleteFrame(bytes))\n\t\t\t\t\treturn Effect.fail(\n\t\t\t\t\t\tFrameError.make({\n\t\t\t\t\t\t\tdetail: \"Invalid runner frame header or payload length\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\treturn Effect.succeed(bytes)\n\t\t\t}),\n\t\t\tStream.mapError((error) =>\n\t\t\t\tTransportError.make({ cause: Cause.fail(error) }),\n\t\t\t),\n\t\t),\n\t\toutput: Sink.suspend(() => {\n\t\t\tconst frames = decoder()\n\t\t\treturn Sink.forEach((bytes: Uint8Array) =>\n\t\t\t\tEffect.fromResult(frames.decode(bytes)).pipe(\n\t\t\t\t\tEffect.flatMap((values) =>\n\t\t\t\t\t\tEffect.forEach(\n\t\t\t\t\t\t\tvalues,\n\t\t\t\t\t\t\t(frame) => encode(frame).pipe(Effect.flatMap(writer.write)),\n\t\t\t\t\t\t\t{ discard: true },\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t).pipe(\n\t\t\t\tSink.onExit((exit) =>\n\t\t\t\t\tExit.isSuccess(exit)\n\t\t\t\t\t\t? frames.finish.pipe(\n\t\t\t\t\t\t\t\tEffect.andThen(writer.write(new Socket.CloseEvent(1000))),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: Effect.void,\n\t\t\t\t),\n\t\t\t\tSink.mapError((error) =>\n\t\t\t\t\tTransportError.make({ cause: Cause.fail(error) }),\n\t\t\t\t),\n\t\t\t)\n\t\t}),\n\t}\n})\n"],"mappings":";;;;;;AAMA,MAAa,aAAa,OAAO,WAAW,WAAW,QAAuB;CAC7E,MAAM,SAAS,OAAO,OAAO;CAC7B,MAAM,SAAS,OAAO,OAAO;CAC7B,OAAO;EACN,OAAO,OAAO,iBAAiB,OAAO,IAAI,CAAC,CAAC,KAC3C,OAAO,SAAS,gBAAgB,UAC/B,MAAM,OAAO,SAAS,sBAAsB,MAAM,OAAO,SAAS,MAC/D,OAAO,QACP,OAAO,KAAK,KAAK,CACrB,GACA,OAAO,iBACP,OAAO,WAAW,UAAU;GAC3B,IAAI,OAAO,UAAU,UACpB,OAAO,OAAO,KACb,WAAW,KAAK,EACf,QAAQ,2CACT,CAAC,CACF;GAED,IAAI,CAAC,gBAAgB,KAAK,GACzB,OAAO,OAAO,KACb,WAAW,KAAK,EACf,QAAQ,gDACT,CAAC,CACF;GACD,OAAO,OAAO,QAAQ,KAAK;EAC5B,CAAC,GACD,OAAO,UAAU,UAChB,eAAe,KAAK,EAAE,OAAO,MAAM,KAAK,KAAK,EAAE,CAAC,CACjD,CACD;EACA,QAAQ,KAAK,cAAc;GAC1B,MAAM,SAAS,QAAQ;GACvB,OAAO,KAAK,SAAS,UACpB,OAAO,WAAW,OAAO,OAAO,KAAK,CAAC,CAAC,CAAC,KACvC,OAAO,SAAS,WACf,OAAO,QACN,SACC,UAAU,OAAO,KAAK,CAAC,CAAC,KAAK,OAAO,QAAQ,OAAO,KAAK,CAAC,GAC1D,EAAE,SAAS,KAAK,CACjB,CACD,CACD,CACD,CAAC,CAAC,KACD,KAAK,QAAQ,SACZ,KAAK,UAAU,IAAI,IAChB,OAAO,OAAO,KACd,OAAO,QAAQ,OAAO,MAAM,IAAI,OAAO,WAAW,GAAI,CAAC,CAAC,CACzD,IACC,OAAO,IACX,GACA,KAAK,UAAU,UACd,eAAe,KAAK,EAAE,OAAO,MAAM,KAAK,KAAK,EAAE,CAAC,CACjD,CACD;EACD,CAAC;CACF;AACD,CAAC"}
1
+ {"version":3,"file":"socketChannel.js","names":[],"sources":["../../src/internal/socketChannel.ts"],"sourcesContent":["import { Cause, Effect, Exit, Sink, Stream } from \"effect\"\nimport { Socket } from \"effect/socket\"\n\nimport { TransportError } from \"../Errors\"\nimport { decoder, encode, FrameError, isCompleteFrame } from \"./runner/Framing\"\n\n/** WebSocket boundaries are a wire compatibility detail, not Channel chunk boundaries. */\nexport const fromSocket = Effect.fnUntraced(function* (socket: Socket.Socket) {\n\tconst reader = yield* socket.reader\n\tconst writer = yield* socket.writer\n\treturn {\n\t\tinput: Stream.fromEffectRepeat(reader.pull).pipe(\n\t\t\tStream.catchTag(\"SocketError\", (error) =>\n\t\t\t\terror.reason._tag === \"SocketCloseError\" && error.reason.code === 1000\n\t\t\t\t\t? Stream.empty\n\t\t\t\t\t: Stream.fail(error),\n\t\t\t),\n\t\t\tStream.flattenIterable,\n\t\t\tStream.mapEffect((bytes) => {\n\t\t\t\tif (typeof bytes === \"string\")\n\t\t\t\t\treturn Effect.fail(\n\t\t\t\t\t\tFrameError.make({\n\t\t\t\t\t\t\tdetail: \"Runner WebSocket messages must be binary\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t// WebSocket messages preserve one complete framing frame, including its header.\n\t\t\t\tif (!isCompleteFrame(bytes))\n\t\t\t\t\treturn Effect.fail(\n\t\t\t\t\t\tFrameError.make({\n\t\t\t\t\t\t\tdetail: \"Invalid runner frame header or payload length\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\treturn Effect.succeed(bytes)\n\t\t\t}),\n\t\t\tStream.mapError((error) =>\n\t\t\t\tTransportError.make({ cause: Cause.fail(error) }),\n\t\t\t),\n\t\t),\n\t\toutput: Sink.suspend(() => {\n\t\t\tconst frames = decoder()\n\t\t\treturn Sink.forEach((bytes: Uint8Array) =>\n\t\t\t\tEffect.fromResult(frames.decode(bytes)).pipe(\n\t\t\t\t\tEffect.flatMap((values) =>\n\t\t\t\t\t\tEffect.forEach(\n\t\t\t\t\t\t\tvalues,\n\t\t\t\t\t\t\t(frame) => encode(frame).pipe(Effect.flatMap(writer.write)),\n\t\t\t\t\t\t\t{ discard: true },\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t).pipe(\n\t\t\t\tSink.onExit((exit) =>\n\t\t\t\t\tExit.isSuccess(exit)\n\t\t\t\t\t\t? frames.finish.pipe(\n\t\t\t\t\t\t\t\tEffect.andThen(writer.write(new Socket.CloseEvent(1000))),\n\t\t\t\t\t\t\t)\n\t\t\t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IACX,GACA,KAAK,UAAU,UACd,eAAe,KAAK,EAAE,OAAO,MAAM,KAAK,KAAK,EAAE,CAAC,CACjD,CACD;EACD,CAAC;CACF;AACD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"stdioChannel.js","names":[],"sources":["../../src/internal/stdioChannel.ts"],"sourcesContent":["import { NodeSink } from \"@effect/platform-node\"\nimport { Cause, Effect, Stdio, Stream } from \"effect\"\n// @effect-diagnostics-next-line nodeBuiltinImport:off -- Node's extra inherited descriptor carries protocol output separately from console output.\nimport { createWriteStream } from \"node:fs\"\nimport { TransportError } from \"../Errors\"\nimport type * as Port from \"./port\"\n\nexport const bytes = Effect.gen(function* () {\n\tconst stdio = yield* Stdio.Stdio\n\tconst output = yield* Effect.sync(() =>\n\t\tcreateWriteStream(\"\", { fd: 3, autoClose: false }),\n\t)\n\treturn {\n\t\tinput: stdio.stdin.pipe(\n\t\t\tStream.mapError((error) =>\n\t\t\t\tTransportError.make({ cause: Cause.fail(error) }),\n\t\t\t),\n\t\t),\n\t\toutput: NodeSink.fromWritable({\n\t\t\tevaluate: () => output,\n\t\t\tonError: (cause) => TransportError.make({ cause: Cause.die(cause) }),\n\t\t\tendOnDone: false,\n\t\t}),\n\t} satisfies Port.Channel\n})\n"],"mappings":";;;;;AAOA,MAAa,QAAQ,OAAO,IAAI,aAAa;CAC5C,MAAM,QAAQ,OAAO,MAAM;CAC3B,MAAM,SAAS,OAAO,OAAO,WAC5B,kBAAkB,IAAI;EAAE,IAAI;EAAG,WAAW;CAAM,CAAC,CAClD;CACA,OAAO;EACN,OAAO,MAAM,MAAM,KAClB,OAAO,UAAU,UAChB,eAAe,KAAK,EAAE,OAAO,MAAM,KAAK,KAAK,EAAE,CAAC,CACjD,CACD;EACA,QAAQ,SAAS,aAAa;GAC7B,gBAAgB;GAChB,UAAU,UAAU,eAAe,KAAK,EAAE,OAAO,MAAM,IAAI,KAAK,EAAE,CAAC;GACnE,WAAW;EACZ,CAAC;CACF;AACD,CAAC"}
1
+ {"version":3,"file":"stdioChannel.js","names":[],"sources":["../../src/internal/stdioChannel.ts"],"sourcesContent":["// @effect-diagnostics-next-line nodeBuiltinImport:off -- Node's extra inherited descriptor carries protocol output separately from console output.\nimport { createWriteStream } from \"node:fs\"\n\nimport { Cause, Effect, Stdio, Stream } from \"effect\"\nimport { NodeSink } from \"@effect/platform-node\"\n\nimport { TransportError } from \"../Errors\"\nimport type * as Port from \"./port\"\n\nexport const bytes = Effect.gen(function* () {\n\tconst stdio = yield* Stdio.Stdio\n\tconst output = yield* Effect.sync(() =>\n\t\tcreateWriteStream(\"\", { fd: 3, autoClose: false }),\n\t)\n\treturn {\n\t\tinput: stdio.stdin.pipe(\n\t\t\tStream.mapError((error) =>\n\t\t\t\tTransportError.make({ cause: Cause.fail(error) }),\n\t\t\t),\n\t\t),\n\t\toutput: NodeSink.fromWritable({\n\t\t\tevaluate: () => output,\n\t\t\tonError: (cause) => TransportError.make({ cause: Cause.die(cause) }),\n\t\t\tendOnDone: false,\n\t\t}),\n\t} satisfies Port.Channel\n})\n"],"mappings":";;;;;AASA,MAAa,QAAQ,OAAO,IAAI,aAAa;CAC5C,MAAM,QAAQ,OAAO,MAAM;CAC3B,MAAM,SAAS,OAAO,OAAO,WAC5B,kBAAkB,IAAI;EAAE,IAAI;EAAG,WAAW;CAAM,CAAC,CAClD;CACA,OAAO;EACN,OAAO,MAAM,MAAM,KAClB,OAAO,UAAU,UAChB,eAAe,KAAK,EAAE,OAAO,MAAM,KAAK,KAAK,EAAE,CAAC,CACjD,CACD;EACA,QAAQ,SAAS,aAAa;GAC7B,gBAAgB;GAChB,UAAU,UAAU,eAAe,KAAK,EAAE,OAAO,MAAM,IAAI,KAAK,EAAE,CAAC;GACnE,WAAW;EACZ,CAAC;CACF;AACD,CAAC"}
@@ -1 +1,48 @@
1
- export { t as Config, n as default } from "../supervisorPlugin-t6Z6PrhD.js";
1
+ import { PositiveDuration } from "./config.js";
2
+ import { accept } from "./runner/accept.js";
3
+ import { Channels, layer } from "./runner/Execution.js";
4
+ import { acquire } from "./runner/Lock.js";
5
+ import { layerDirectory } from "./runner/Store.js";
6
+ import { Supervisor, layer as layer$1 } from "./runner/Supervisor.js";
7
+ import { RunnerLifecycle, resources } from "./RunnerLifecycle.js";
8
+ import { Supervisor as Supervisor$1 } from "./Supervisor.js";
9
+ import { Context, Effect, FileSystem, Layer, Option, Path, Schema, Scope } from "effect";
10
+ import { Digest, SecureRandom } from "effect/crypto";
11
+ import { ChildProcessSpawner } from "effect/process";
12
+ import { Graft, Plugin } from "@graftland/graft";
13
+ import { ConfigDirectory } from "@graftland/loader";
14
+ // src/internal/supervisorPlugin.ts
15
+ const Config = Schema.Struct({
16
+ root: Schema.String,
17
+ state: Schema.String,
18
+ lease: Schema.optionalKey(PositiveDuration),
19
+ grace: Schema.optionalKey(PositiveDuration)
20
+ });
21
+ var supervisorPlugin_default = Plugin.make({
22
+ name: "remote-supervisor",
23
+ config: Config,
24
+ inject: [
25
+ Plugin.optional(RunnerLifecycle),
26
+ FileSystem.FileSystem,
27
+ Path.Path,
28
+ ChildProcessSpawner.ChildProcessSpawner,
29
+ SecureRandom.SecureRandom,
30
+ Digest.Digest
31
+ ],
32
+ apply: Effect.fnUntraced(function* (options) {
33
+ const lifecycle = yield* Effect.serviceOption(RunnerLifecycle);
34
+ const resources$1 = yield* resources(lifecycle);
35
+ const path = yield* Path.Path;
36
+ const directory = yield* ConfigDirectory.pipe(Effect.map(Option.getOrElse(() => ".")));
37
+ const state = path.resolve(directory, options.state);
38
+ yield* acquire(state).pipe(Scope.provide(resources$1));
39
+ const services = yield* Layer.build(layer$1(options).pipe(Layer.provideMerge(Layer.merge(layerDirectory(state), layer(path.resolve(directory, options.root)))))).pipe(Scope.provide(resources$1));
40
+ const engine = Context.get(services, Supervisor);
41
+ const execution = Context.get(services, Channels);
42
+ yield* Plugin.fork(engine.await);
43
+ yield* Graft.provide(Supervisor$1, { accept: (channel) => accept(engine, execution, channel) });
44
+ })
45
+ });
46
+ export { Config, supervisorPlugin_default as default };
47
+
48
+ //# sourceMappingURL=supervisorPlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"supervisorPlugin.js","names":["Lifecycle.ServeLifecycle","resources","Lifecycle.resources","Lock.acquire","Engine.layer","Stores.layerDirectory","Execution.layer","Engine.Supervisor","Execution.Channels"],"sources":["../../src/internal/supervisorPlugin.ts"],"sourcesContent":["import { Graft, Plugin } from \"@graftland/graft\"\nimport {\n\tContext,\n\tEffect,\n\tFileSystem,\n\tLayer,\n\tOption,\n\tPath,\n\tSchema,\n\tScope,\n} from \"effect\"\nimport { Digest, SecureRandom } from \"effect/crypto\"\nimport { ChildProcessSpawner } from \"effect/process\"\nimport { Supervisor } from \"./Supervisor\"\nimport { PositiveDuration } from \"./config\"\nimport { ConfigDirectory } from \"@graftland/loader\"\nimport * as Lock from \"./runner/Lock\"\nimport * as Stores from \"./runner/Store\"\nimport * as Execution from \"./runner/Execution\"\nimport * as Engine from \"./runner/Supervisor\"\nimport { accept } from \"./runner/accept\"\nimport * as Lifecycle from \"./ServeLifecycle\"\n\nexport const Config = Schema.Struct({\n\troot: Schema.String,\n\tstate: Schema.String,\n\tlease: Schema.optionalKey(PositiveDuration),\n\tgrace: Schema.optionalKey(PositiveDuration),\n})\nexport default Plugin.make({\n\tname: \"remote-supervisor\",\n\tconfig: Config,\n\tinject: [\n\t\tPlugin.optional(Lifecycle.ServeLifecycle),\n\t\tFileSystem.FileSystem,\n\t\tPath.Path,\n\t\tChildProcessSpawner.ChildProcessSpawner,\n\t\tSecureRandom.SecureRandom,\n\t\tDigest.Digest,\n\t],\n\tapply: Effect.fnUntraced(function* (options) {\n\t\tconst lifecycle = yield* Effect.serviceOption(Lifecycle.ServeLifecycle)\n\t\tconst resources = yield* Lifecycle.resources(lifecycle)\n\t\tconst path = yield* Path.Path\n\t\tconst directory = yield* ConfigDirectory.pipe(\n\t\t\tEffect.map(Option.getOrElse(() => \".\")),\n\t\t)\n\t\tconst state = path.resolve(directory, options.state)\n\t\tyield* Lock.acquire(state).pipe(Scope.provide(resources))\n\t\tconst services = yield* Layer.build(\n\t\t\tEngine.layer(options).pipe(\n\t\t\t\tLayer.provideMerge(\n\t\t\t\t\tLayer.merge(\n\t\t\t\t\t\tStores.layerDirectory(state),\n\t\t\t\t\t\tExecution.layer(path.resolve(directory, options.root)),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n\t\t).pipe(Scope.provide(resources))\n\t\tconst engine = Context.get(services, Engine.Supervisor)\n\t\tconst execution = Context.get(services, Execution.Channels)\n\t\tyield* Plugin.fork(engine.await)\n\t\tyield* Graft.provide(Supervisor, {\n\t\t\taccept: (channel) => accept(engine, execution, channel),\n\t\t})\n\t}),\n})\n"],"mappings":";;;;;;;;;;;;;;AAuBA,MAAa,SAAS,OAAO,OAAO;CACnC,MAAM,OAAO;CACb,OAAO,OAAO;CACd,OAAO,OAAO,YAAY,gBAAgB;CAC1C,OAAO,OAAO,YAAY,gBAAgB;AAC3C,CAAC;AACD,IAAA,2BAAe,OAAO,KAAK;CAC1B,MAAM;CACN,QAAQ;CACR,QAAQ;EACP,OAAO,SAASA,cAAwB;EACxC,WAAW;EACX,KAAK;EACL,oBAAoB;EACpB,aAAa;EACb,OAAO;CACR;CACA,OAAO,OAAO,WAAW,WAAW,SAAS;EAC5C,MAAM,YAAY,OAAO,OAAO,cAAcA,cAAwB;EACtE,MAAMC,cAAY,OAAOC,UAAoB,SAAS;EACtD,MAAM,OAAO,OAAO,KAAK;EACzB,MAAM,YAAY,OAAO,gBAAgB,KACxC,OAAO,IAAI,OAAO,gBAAgB,GAAG,CAAC,CACvC;EACA,MAAM,QAAQ,KAAK,QAAQ,WAAW,QAAQ,KAAK;EACnD,OAAOC,QAAa,KAAK,CAAC,CAAC,KAAK,MAAM,QAAQF,WAAS,CAAC;EACxD,MAAM,WAAW,OAAO,MAAM,MAC7BG,QAAa,OAAO,CAAC,CAAC,KACrB,MAAM,aACL,MAAM,MACLC,eAAsB,KAAK,GAC3BC,MAAgB,KAAK,QAAQ,WAAW,QAAQ,IAAI,CAAC,CACtD,CACD,CACD,CACD,CAAC,CAAC,KAAK,MAAM,QAAQL,WAAS,CAAC;EAC/B,MAAM,SAAS,QAAQ,IAAI,UAAUM,YAAiB;EACtD,MAAM,YAAY,QAAQ,IAAI,UAAUC,QAAkB;EAC1D,OAAO,OAAO,KAAK,OAAO,KAAK;EAC/B,OAAO,MAAM,QAAQ,YAAY,EAChC,SAAS,YAAY,OAAO,QAAQ,WAAW,OAAO,EACvD,CAAC;CACF,CAAC;AACF,CAAC"}
1
+ {"version":3,"file":"supervisorPlugin.js","names":["Lifecycle.RunnerLifecycle","resources","Lifecycle.resources","Lock.acquire","Engine.layer","Stores.layerDirectory","Execution.layer","Engine.Supervisor","Execution.Channels","Supervisor"],"sources":["../../src/internal/supervisorPlugin.ts"],"sourcesContent":["import {\n\tContext,\n\tEffect,\n\tFileSystem,\n\tLayer,\n\tOption,\n\tPath,\n\tSchema,\n\tScope,\n} from \"effect\"\nimport { Digest, SecureRandom } from \"effect/crypto\"\nimport { ChildProcessSpawner } from \"effect/process\"\n\nimport { Graft, Plugin } from \"@graftland/graft\"\nimport { ConfigDirectory } from \"@graftland/loader\"\n\nimport { PositiveDuration } from \"./config\"\nimport { accept } from \"./runner/accept\"\nimport * as Execution from \"./runner/Execution\"\nimport * as Lock from \"./runner/Lock\"\nimport * as Stores from \"./runner/Store\"\nimport * as Engine from \"./runner/Supervisor\"\nimport * as Lifecycle from \"./RunnerLifecycle\"\nimport { Supervisor } from \"./Supervisor\"\n\nexport const Config = Schema.Struct({\n\troot: Schema.String,\n\tstate: Schema.String,\n\tlease: Schema.optionalKey(PositiveDuration),\n\tgrace: Schema.optionalKey(PositiveDuration),\n})\nexport default Plugin.make({\n\tname: \"remote-supervisor\",\n\tconfig: Config,\n\tinject: [\n\t\tPlugin.optional(Lifecycle.RunnerLifecycle),\n\t\tFileSystem.FileSystem,\n\t\tPath.Path,\n\t\tChildProcessSpawner.ChildProcessSpawner,\n\t\tSecureRandom.SecureRandom,\n\t\tDigest.Digest,\n\t],\n\tapply: Effect.fnUntraced(function* (options) {\n\t\tconst lifecycle = yield* Effect.serviceOption(Lifecycle.RunnerLifecycle)\n\t\tconst resources = yield* Lifecycle.resources(lifecycle)\n\t\tconst path = yield* Path.Path\n\t\tconst directory = yield* ConfigDirectory.pipe(\n\t\t\tEffect.map(Option.getOrElse(() => \".\")),\n\t\t)\n\t\tconst state = path.resolve(directory, options.state)\n\t\tyield* Lock.acquire(state).pipe(Scope.provide(resources))\n\t\tconst services = yield* Layer.build(\n\t\t\tEngine.layer(options).pipe(\n\t\t\t\tLayer.provideMerge(\n\t\t\t\t\tLayer.merge(\n\t\t\t\t\t\tStores.layerDirectory(state),\n\t\t\t\t\t\tExecution.layer(path.resolve(directory, options.root)),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n\t\t).pipe(Scope.provide(resources))\n\t\tconst engine = Context.get(services, Engine.Supervisor)\n\t\tconst execution = Context.get(services, Execution.Channels)\n\t\tyield* Plugin.fork(engine.await)\n\t\tyield* Graft.provide(Supervisor, {\n\t\t\taccept: (channel) => accept(engine, execution, channel),\n\t\t})\n\t}),\n})\n"],"mappings":";;;;;;;;;;;;;;AAyBA,MAAa,SAAS,OAAO,OAAO;CACnC,MAAM,OAAO;CACb,OAAO,OAAO;CACd,OAAO,OAAO,YAAY,gBAAgB;CAC1C,OAAO,OAAO,YAAY,gBAAgB;AAC3C,CAAC;AACD,IAAA,2BAAe,OAAO,KAAK;CAC1B,MAAM;CACN,QAAQ;CACR,QAAQ;EACP,OAAO,SAASA,eAAyB;EACzC,WAAW;EACX,KAAK;EACL,oBAAoB;EACpB,aAAa;EACb,OAAO;CACR;CACA,OAAO,OAAO,WAAW,WAAW,SAAS;EAC5C,MAAM,YAAY,OAAO,OAAO,cAAcA,eAAyB;EACvE,MAAMC,cAAY,OAAOC,UAAoB,SAAS;EACtD,MAAM,OAAO,OAAO,KAAK;EACzB,MAAM,YAAY,OAAO,gBAAgB,KACxC,OAAO,IAAI,OAAO,gBAAgB,GAAG,CAAC,CACvC;EACA,MAAM,QAAQ,KAAK,QAAQ,WAAW,QAAQ,KAAK;EACnD,OAAOC,QAAa,KAAK,CAAC,CAAC,KAAK,MAAM,QAAQF,WAAS,CAAC;EACxD,MAAM,WAAW,OAAO,MAAM,MAC7BG,QAAa,OAAO,CAAC,CAAC,KACrB,MAAM,aACL,MAAM,MACLC,eAAsB,KAAK,GAC3BC,MAAgB,KAAK,QAAQ,WAAW,QAAQ,IAAI,CAAC,CACtD,CACD,CACD,CACD,CAAC,CAAC,KAAK,MAAM,QAAQL,WAAS,CAAC;EAC/B,MAAM,SAAS,QAAQ,IAAI,UAAUM,UAAiB;EACtD,MAAM,YAAY,QAAQ,IAAI,UAAUC,QAAkB;EAC1D,OAAO,OAAO,KAAK,OAAO,KAAK;EAC/B,OAAO,MAAM,QAAQC,cAAY,EAChC,SAAS,YAAY,OAAO,QAAQ,WAAW,OAAO,EACvD,CAAC;CACF,CAAC;AACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"transportOptions.d.ts","names":[],"sources":["../../src/internal/transportOptions.ts"],"mappings":";iBACiB;WACP;WACA;aACC;aACA;;WAED,cAAc,SAAS;;iBAEhB;WACP;;iBAEO;WACP;WACA;WACA,MAAM,SAAS"}
1
+ {"version":3,"file":"transportOptions.d.ts","names":[],"sources":["../../src/internal/transportOptions.ts"],"mappings":";iBAEiB;WACP;WACA;aACC;aACA;;WAED,cAAc,SAAS;;iBAEhB;WACP;;iBAEO;WACP;WACA;WACA,MAAM,SAAS"}
@@ -1,10 +1,10 @@
1
- import { n as Notice, t as CommandJson } from "../WatchdogProtocol-BZmVxrBP.js";
1
+ import { CommandJson, Notice } from "./runner/WatchdogProtocol.js";
2
2
  import { Clock, Effect, FiberHandle, Ref, Schema, Stream } from "effect";
3
- import { NodeRuntime, NodeStream } from "@effect/platform-node";
4
3
  import process from "node:process";
4
+ import { NodeRuntime, NodeStream } from "@effect/platform-node";
5
5
  import { parentPort } from "node:worker_threads";
6
6
  import { Socket } from "node:net";
7
- // packages/remote/src/internal/watchdogMain.ts
7
+ // src/internal/watchdogMain.ts
8
8
  /** Executable worker: fd 4 and the lease timer remain independent of the plugin thread. */
9
9
  const die = Effect.sync(() => process.kill(process.pid, "SIGKILL")).pipe(Effect.andThen(Effect.never));
10
10
  const notify = (notice) => Schema.encodeEffect(Notice)(notice).pipe(Effect.flatMap((message) => Effect.sync(() => parentPort?.postMessage(message))));
@@ -53,3 +53,5 @@ const main = Effect.scoped(Effect.gen(function* () {
53
53
  })).pipe(Effect.catchCause((cause) => Effect.logError("Watchdog failed", cause).pipe(Effect.andThen(die))));
54
54
  NodeRuntime.runMain(main);
55
55
  export {};
56
+
57
+ //# sourceMappingURL=watchdogMain.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"watchdogMain.js","names":[],"sources":["../../src/internal/watchdogMain.ts"],"sourcesContent":["/** Executable worker: fd 4 and the lease timer remain independent of the plugin thread. */\nimport { NodeRuntime, NodeStream } from \"@effect/platform-node\"\nimport { Clock, Effect, FiberHandle, Ref, Schema, Stream } from \"effect\"\nimport { Socket } from \"node:net\"\nimport { parentPort } from \"node:worker_threads\"\nimport process from \"node:process\"\nimport { CommandJson, Notice } from \"./runner/WatchdogProtocol\"\n\n// The runner machine is trusted. A suspended machine cannot enforce a deadline until it resumes.\n// Killing this live process has no PID lookup; external supervisor kills retain a small PID reuse window.\nconst die = Effect.sync(() => process.kill(process.pid, \"SIGKILL\")).pipe(\n\tEffect.andThen(Effect.never),\n)\nconst notify = (notice: typeof Notice.Type) =>\n\tSchema.encodeEffect(Notice)(notice).pipe(\n\t\tEffect.flatMap((message) =>\n\t\t\tEffect.sync(() => parentPort?.postMessage(message)),\n\t\t),\n\t)\n// Milliseconds on the monotonic clock, which the lease sleep also uses.\nconst now = Clock.monotonicTimeNanos.pipe(\n\tEffect.map((nanos) => Number(nanos) / 1_000_000),\n)\nconst expire = Effect.fnUntraced(function* (\n\tdeadline: number,\n): Effect.fn.Return<never> {\n\tconst remaining = deadline - (yield* now)\n\tif (remaining <= 0) return yield* die\n\t// The clock splits sleeps longer than the platform timer limit.\n\tyield* Effect.sleep(remaining)\n\treturn yield* expire(deadline)\n})\nconst main = Effect.scoped(\n\tEffect.gen(function* () {\n\t\tconst lease = yield* Ref.make({\n\t\t\tdeadline: (yield* now) + 30000,\n\t\t\tstopped: false,\n\t\t})\n\t\tconst timer = yield* FiberHandle.make<never, never>()\n\t\tyield* FiberHandle.run(timer, expire((yield* Ref.get(lease)).deadline))\n\t\tconst input = yield* Effect.acquireRelease(\n\t\t\tEffect.sync(() => new Socket({ fd: 4, readable: true, writable: false })),\n\t\t\t(socket) =>\n\t\t\t\tEffect.sync(() => {\n\t\t\t\t\tsocket.destroy()\n\t\t\t\t}),\n\t\t)\n\t\tyield* notify(\"ready\")\n\t\tyield* NodeStream.fromReadable({ evaluate: () => input }).pipe(\n\t\t\tStream.decodeText(),\n\t\t\tStream.splitLines,\n\t\t\tStream.mapEffect((line) => Schema.decodeEffect(CommandJson)(line)),\n\t\t\tStream.runForEach(\n\t\t\t\tEffect.fnUntraced(function* (command: typeof CommandJson.Type) {\n\t\t\t\t\tif (command.kind === \"start\") return yield* notify(\"start\")\n\t\t\t\t\tif (command.kind === \"stop\") {\n\t\t\t\t\t\tyield* Ref.update(lease, (state) => ({ ...state, stopped: true }))\n\t\t\t\t\t\treturn yield* notify(\"stop\")\n\t\t\t\t\t}\n\t\t\t\t\tconst current = yield* Ref.get(lease)\n\t\t\t\t\tconst time = yield* now\n\t\t\t\t\tif (current.stopped || time >= current.deadline) return yield* die\n\t\t\t\t\tconst deadline = time + command.millis\n\t\t\t\t\tyield* Ref.set(lease, { deadline, stopped: false })\n\t\t\t\t\tyield* FiberHandle.run(timer, expire(deadline))\n\t\t\t\t}),\n\t\t\t),\n\t\t)\n\t\treturn yield* die\n\t}),\n).pipe(\n\tEffect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,CAAC,CAAC,IAAI,CAAC,GACjE,OAAO,WACN,OAAO,WAAW,WAAW,SAAkC;EAC9D,IAAI,QAAQ,SAAS,SAAS,OAAO,OAAO,OAAO,OAAO;EAC1D,IAAI,QAAQ,SAAS,QAAQ;GAC5B,OAAO,IAAI,OAAO,QAAQ,WAAW;IAAE,GAAG;IAAO,SAAS;GAAK,EAAE;GACjE,OAAO,OAAO,OAAO,MAAM;EAC5B;EACA,MAAM,UAAU,OAAO,IAAI,IAAI,KAAK;EACpC,MAAM,OAAO,OAAO;EACpB,IAAI,QAAQ,WAAW,QAAQ,QAAQ,UAAU,OAAO,OAAO;EAC/D,MAAM,WAAW,OAAO,QAAQ;EAChC,OAAO,IAAI,IAAI,OAAO;GAAE;GAAU,SAAS;EAAM,CAAC;EAClD,OAAO,YAAY,IAAI,OAAO,OAAO,QAAQ,CAAC;CAC/C,CAAC,CACF,CACD;CACA,OAAO,OAAO;AACf,CAAC,CACF,CAAC,CAAC,KACD,OAAO,YAAY,UAClB,OAAO,SAAS,mBAAmB,KAAK,CAAC,CAAC,KAAK,OAAO,QAAQ,GAAG,CAAC,CACnE,CACD;AAEA,YAAY,QAAQ,IAAI"}
1
+ {"version":3,"file":"watchdogMain.js","names":[],"sources":["../../src/internal/watchdogMain.ts"],"sourcesContent":["/** Executable worker: fd 4 and the lease timer remain independent of the plugin thread. */\nimport { Socket } from \"node:net\"\nimport process from \"node:process\"\nimport { parentPort } from \"node:worker_threads\"\n\nimport { Clock, Effect, FiberHandle, Ref, Schema, Stream } from \"effect\"\nimport { NodeRuntime, NodeStream } from \"@effect/platform-node\"\n\nimport { CommandJson, Notice } from \"./runner/WatchdogProtocol\"\n\n// The runner machine is trusted. A suspended machine cannot enforce a deadline until it resumes.\n// Killing this live process has no PID lookup; external supervisor kills retain a small PID reuse window.\nconst die = Effect.sync(() => process.kill(process.pid, \"SIGKILL\")).pipe(\n\tEffect.andThen(Effect.never),\n)\nconst notify = (notice: typeof Notice.Type) =>\n\tSchema.encodeEffect(Notice)(notice).pipe(\n\t\tEffect.flatMap((message) =>\n\t\t\tEffect.sync(() => parentPort?.postMessage(message)),\n\t\t),\n\t)\n// Milliseconds on the monotonic clock, which the lease sleep also uses.\nconst now = Clock.monotonicTimeNanos.pipe(\n\tEffect.map((nanos) => Number(nanos) / 1_000_000),\n)\nconst expire = Effect.fnUntraced(function* (\n\tdeadline: number,\n): Effect.fn.Return<never> {\n\tconst remaining = deadline - (yield* now)\n\tif (remaining <= 0) return yield* die\n\t// The clock splits sleeps longer than the platform timer limit.\n\tyield* Effect.sleep(remaining)\n\treturn yield* expire(deadline)\n})\nconst main = Effect.scoped(\n\tEffect.gen(function* () {\n\t\tconst lease = yield* Ref.make({\n\t\t\tdeadline: (yield* now) + 30000,\n\t\t\tstopped: false,\n\t\t})\n\t\tconst timer = yield* FiberHandle.make<never, never>()\n\t\tyield* FiberHandle.run(timer, expire((yield* Ref.get(lease)).deadline))\n\t\tconst input = yield* Effect.acquireRelease(\n\t\t\tEffect.sync(() => new Socket({ fd: 4, readable: true, writable: false })),\n\t\t\t(socket) =>\n\t\t\t\tEffect.sync(() => {\n\t\t\t\t\tsocket.destroy()\n\t\t\t\t}),\n\t\t)\n\t\tyield* notify(\"ready\")\n\t\tyield* NodeStream.fromReadable({ evaluate: () => input }).pipe(\n\t\t\tStream.decodeText(),\n\t\t\tStream.splitLines,\n\t\t\tStream.mapEffect((line) => Schema.decodeEffect(CommandJson)(line)),\n\t\t\tStream.runForEach(\n\t\t\t\tEffect.fnUntraced(function* (command: typeof CommandJson.Type) {\n\t\t\t\t\tif (command.kind === \"start\") return yield* notify(\"start\")\n\t\t\t\t\tif (command.kind === \"stop\") {\n\t\t\t\t\t\tyield* Ref.update(lease, (state) => ({ ...state, stopped: true }))\n\t\t\t\t\t\treturn yield* notify(\"stop\")\n\t\t\t\t\t}\n\t\t\t\t\tconst current = yield* Ref.get(lease)\n\t\t\t\t\tconst time = yield* now\n\t\t\t\t\tif (current.stopped || time >= current.deadline) return yield* die\n\t\t\t\t\tconst deadline = time + command.millis\n\t\t\t\t\tyield* Ref.set(lease, { deadline, stopped: false })\n\t\t\t\t\tyield* FiberHandle.run(timer, expire(deadline))\n\t\t\t\t}),\n\t\t\t),\n\t\t)\n\t\treturn yield* die\n\t}),\n).pipe(\n\tEffect.catchCause((cause) =>\n\t\tEffect.logError(\"Watchdog failed\", cause).pipe(Effect.andThen(die)),\n\t),\n)\n\nNodeRuntime.runMain(main)\n"],"mappings":";;;;;;;;AAYA,MAAM,MAAM,OAAO,WAAW,QAAQ,KAAK,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,KACnE,OAAO,QAAQ,OAAO,KAAK,CAC5B;AACA,MAAM,UAAU,WACf,OAAO,aAAa,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,KACnC,OAAO,SAAS,YACf,OAAO,WAAW,YAAY,YAAY,OAAO,CAAC,CACnD,CACD;AAED,MAAM,MAAM,MAAM,mBAAmB,KACpC,OAAO,KAAK,UAAU,OAAO,KAAK,IAAI,GAAS,CAChD;AACA,MAAM,SAAS,OAAO,WAAW,WAChC,UAC0B;CAC1B,MAAM,YAAY,YAAY,OAAO;CACrC,IAAI,aAAa,GAAG,OAAO,OAAO;CAElC,OAAO,OAAO,MAAM,SAAS;CAC7B,OAAO,OAAO,OAAO,QAAQ;AAC9B,CAAC;AACD,MAAM,OAAO,OAAO,OACnB,OAAO,IAAI,aAAa;CACvB,MAAM,QAAQ,OAAO,IAAI,KAAK;EAC7B,WAAW,OAAO,OAAO;EACzB,SAAS;CACV,CAAC;CACD,MAAM,QAAQ,OAAO,YAAY,KAAmB;CACpD,OAAO,YAAY,IAAI,OAAO,QAAQ,OAAO,IAAI,IAAI,KAAK,EAAA,CAAG,QAAQ,CAAC;CACtE,MAAM,QAAQ,OAAO,OAAO,eAC3B,OAAO,WAAW,IAAI,OAAO;EAAE,IAAI;EAAG,UAAU;EAAM,UAAU;CAAM,CAAC,CAAC,IACvE,WACA,OAAO,WAAW;EACjB,OAAO,QAAQ;CAChB,CAAC,CACH;CACA,OAAO,OAAO,OAAO;CACrB,OAAO,WAAW,aAAa,EAAE,gBAAgB,MAAM,CAAC,CAAC,CAAC,KACzD,OAAO,WAAW,GAClB,OAAO,YACP,OAAO,WAAW,SAAS,OAAO,aAAa,WAAW,CAAC,CAAC,IAAI,CAAC,GACjE,OAAO,WACN,OAAO,WAAW,WAAW,SAAkC;EAC9D,IAAI,QAAQ,SAAS,SAAS,OAAO,OAAO,OAAO,OAAO;EAC1D,IAAI,QAAQ,SAAS,QAAQ;GAC5B,OAAO,IAAI,OAAO,QAAQ,WAAW;IAAE,GAAG;IAAO,SAAS;GAAK,EAAE;GACjE,OAAO,OAAO,OAAO,MAAM;EAC5B;EACA,MAAM,UAAU,OAAO,IAAI,IAAI,KAAK;EACpC,MAAM,OAAO,OAAO;EACpB,IAAI,QAAQ,WAAW,QAAQ,QAAQ,UAAU,OAAO,OAAO;EAC/D,MAAM,WAAW,OAAO,QAAQ;EAChC,OAAO,IAAI,IAAI,OAAO;GAAE;GAAU,SAAS;EAAM,CAAC;EAClD,OAAO,YAAY,IAAI,OAAO,OAAO,QAAQ,CAAC;CAC/C,CAAC,CACF,CACD;CACA,OAAO,OAAO;AACf,CAAC,CACF,CAAC,CAAC,KACD,OAAO,YAAY,UAClB,OAAO,SAAS,mBAAmB,KAAK,CAAC,CAAC,KAAK,OAAO,QAAQ,GAAG,CAAC,CACnE,CACD;AAEA,YAAY,QAAQ,IAAI"}
@@ -1 +1 @@
1
- {"version":3,"file":"websocket.js","names":[],"sources":["../../src/internal/websocket.ts"],"sourcesContent":["import { Array, Effect, Layer, Redacted, Schema } from \"effect\"\nimport { Socket } from \"effect/socket\"\nimport WS from \"ws\"\nimport type { ClientCertificate } from \"../Auth\"\nimport type { Properties } from \"../Transport\"\ninterface PreparedCredentials {\n\treadonly certificate?: ClientCertificate\n\treadonly authorization?: Redacted.Redacted<string>\n}\nimport type { WebsocketOptions } from \"./transportOptions\"\nimport { headerSize, maxPayload } from \"./runner/Framing\"\n\nexport const protocol = \"graft-remote.v1\"\nexport const path = \"/graft\"\nexport const payloadLimit = maxPayload + headerSize\nexport const Url = Schema.URLFromString.check(\n\tSchema.makeFilter(\n\t\t(url) => url.protocol === \"wss:\" || url.protocol === \"ws:\",\n\t\t{\n\t\t\texpected: \"a ws:// or wss:// URL\",\n\t\t},\n\t),\n)\n\nexport const constructor = (\n\ttls: WebsocketOptions[\"tls\"],\n\tcredentials: PreparedCredentials = {},\n) =>\n\tLayer.succeed(Socket.WebSocketConstructor, (url, options) => {\n\t\tconst settings =\n\t\t\ttypeof options === \"object\" && !Array.isArray(options)\n\t\t\t\t? options\n\t\t\t\t: { protocols: options }\n\t\treturn new WS(url, settings.protocols, {\n\t\t\t...tls,\n\t\t\t...(credentials.certificate === undefined\n\t\t\t\t? {}\n\t\t\t\t: {\n\t\t\t\t\t\tcert: credentials.certificate.cert,\n\t\t\t\t\t\tkey: Redacted.value(credentials.certificate.key),\n\t\t\t\t\t}),\n\t\t\theaders: {\n\t\t\t\t...settings.headers,\n\t\t\t\t...(credentials.authorization === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { authorization: Redacted.value(credentials.authorization) }),\n\t\t\t},\n\t\t\tperMessageDeflate: false,\n\t\t\tmaxPayload: payloadLimit,\n\t\t\trejectUnauthorized: true,\n\t\t\tminVersion: \"TLSv1.3\",\n\t\t})\n\t})\n\nexport const open = Effect.fnUntraced(function* (\n\toptions: WebsocketOptions,\n\tcredentials: PreparedCredentials = {},\n) {\n\tconst url = yield* Schema.decodeEffect(Url)(options.url)\n\tif (credentials.certificate !== undefined && url.protocol !== \"wss:\")\n\t\tyield* Schema.decodeEffect(\n\t\t\tUrl.check(\n\t\t\t\tSchema.makeFilter((url) => url.protocol === \"wss:\", {\n\t\t\t\t\texpected: \"wss:// for mutual TLS\",\n\t\t\t\t}),\n\t\t\t),\n\t\t)(options.url)\n\tconst address = url.pathname === \"/\" ? new URL(path, url).href : url.href\n\tconst services = yield* Layer.build(constructor(options.tls, credentials))\n\treturn yield* Socket.makeWebSocket(address, {\n\t\tprotocols: protocol,\n\t\topenTimeout: options.openTimeout ?? \"10 seconds\",\n\t}).pipe(Effect.provideContext(services))\n})\n\nexport const properties = (url: URL): Properties => ({\n\tprotocol: url.protocol === \"wss:\" ? \"wss\" : \"ws\",\n\tencrypted: url.protocol === \"wss:\",\n\tnetwork: true,\n\tcarries: url.protocol === \"wss:\" ? [\"header\", \"certificate\"] : [\"header\"],\n})\n"],"mappings":";;;;;AAYA,MAAa,WAAW;AACxB,MAAa,OAAO;AACpB,MAAa,eAAe,aAAA;AAC5B,MAAa,MAAM,OAAO,cAAc,MACvC,OAAO,YACL,QAAQ,IAAI,aAAa,UAAU,IAAI,aAAa,OACrD,EACC,UAAU,wBACX,CACD,CACD;AAEA,MAAa,eACZ,KACA,cAAmC,CAAC,MAEpC,MAAM,QAAQ,OAAO,uBAAuB,KAAK,YAAY;CAC5D,MAAM,WACL,OAAO,YAAY,YAAY,CAAC,MAAM,QAAQ,OAAO,IAClD,UACA,EAAE,WAAW,QAAQ;CACzB,OAAO,IAAI,GAAG,KAAK,SAAS,WAAW;EACtC,GAAG;EACH,GAAI,YAAY,gBAAgB,KAAA,IAC7B,CAAC,IACD;GACA,MAAM,YAAY,YAAY;GAC9B,KAAK,SAAS,MAAM,YAAY,YAAY,GAAG;EAChD;EACF,SAAS;GACR,GAAG,SAAS;GACZ,GAAI,YAAY,kBAAkB,KAAA,IAC/B,CAAC,IACD,EAAE,eAAe,SAAS,MAAM,YAAY,aAAa,EAAE;EAC/D;EACA,mBAAmB;EACnB,YAAY;EACZ,oBAAoB;EACpB,YAAY;CACb,CAAC;AACF,CAAC;AAEF,MAAa,OAAO,OAAO,WAAW,WACrC,SACA,cAAmC,CAAC,GACnC;CACD,MAAM,MAAM,OAAO,OAAO,aAAa,GAAG,CAAC,CAAC,QAAQ,GAAG;CACvD,IAAI,YAAY,gBAAgB,KAAA,KAAa,IAAI,aAAa,QAC7D,OAAO,OAAO,aACb,IAAI,MACH,OAAO,YAAY,QAAQ,IAAI,aAAa,QAAQ,EACnD,UAAU,wBACX,CAAC,CACF,CACD,CAAC,CAAC,QAAQ,GAAG;CACd,MAAM,UAAU,IAAI,aAAa,MAAM,IAAI,IAAI,MAAM,GAAG,CAAC,CAAC,OAAO,IAAI;CACrE,MAAM,WAAW,OAAO,MAAM,MAAM,YAAY,QAAQ,KAAK,WAAW,CAAC;CACzE,OAAO,OAAO,OAAO,cAAc,SAAS;EAC3C,WAAW;EACX,aAAa,QAAQ,eAAe;CACrC,CAAC,CAAC,CAAC,KAAK,OAAO,eAAe,QAAQ,CAAC;AACxC,CAAC;AAED,MAAa,cAAc,SAA0B;CACpD,UAAU,IAAI,aAAa,SAAS,QAAQ;CAC5C,WAAW,IAAI,aAAa;CAC5B,SAAS;CACT,SAAS,IAAI,aAAa,SAAS,CAAC,UAAU,aAAa,IAAI,CAAC,QAAQ;AACzE"}
1
+ {"version":3,"file":"websocket.js","names":[],"sources":["../../src/internal/websocket.ts"],"sourcesContent":["import { Array, Effect, Layer, Redacted, Schema } from \"effect\"\nimport { Socket } from \"effect/socket\"\n\nimport WS from \"ws\"\n\nimport type { ClientCertificate } from \"../Auth\"\nimport type { Properties } from \"../Transport\"\nimport { headerSize, maxPayload } from \"./runner/Framing\"\nimport type { WebsocketOptions } from \"./transportOptions\"\n\ninterface PreparedCredentials {\n\treadonly certificate?: ClientCertificate\n\treadonly authorization?: Redacted.Redacted<string>\n}\n\nexport const protocol = \"graft-remote.v1\"\nexport const path = \"/graft\"\nexport const payloadLimit = maxPayload + headerSize\nexport const Url = Schema.URLFromString.check(\n\tSchema.makeFilter(\n\t\t(url) => url.protocol === \"wss:\" || url.protocol === \"ws:\",\n\t\t{\n\t\t\texpected: \"a ws:// or wss:// URL\",\n\t\t},\n\t),\n)\n\nexport const constructor = (\n\ttls: WebsocketOptions[\"tls\"],\n\tcredentials: PreparedCredentials = {},\n) =>\n\tLayer.succeed(Socket.WebSocketConstructor, (url, options) => {\n\t\tconst settings =\n\t\t\ttypeof options === \"object\" && !Array.isArray(options)\n\t\t\t\t? options\n\t\t\t\t: { protocols: options }\n\t\treturn new WS(url, settings.protocols, {\n\t\t\t...tls,\n\t\t\t...(credentials.certificate === undefined\n\t\t\t\t? {}\n\t\t\t\t: {\n\t\t\t\t\t\tcert: credentials.certificate.cert,\n\t\t\t\t\t\tkey: Redacted.value(credentials.certificate.key),\n\t\t\t\t\t}),\n\t\t\theaders: {\n\t\t\t\t...settings.headers,\n\t\t\t\t...(credentials.authorization === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { authorization: Redacted.value(credentials.authorization) }),\n\t\t\t},\n\t\t\tperMessageDeflate: false,\n\t\t\tmaxPayload: payloadLimit,\n\t\t\trejectUnauthorized: true,\n\t\t\tminVersion: \"TLSv1.3\",\n\t\t})\n\t})\n\nexport const open = Effect.fnUntraced(function* (\n\toptions: WebsocketOptions,\n\tcredentials: PreparedCredentials = {},\n) {\n\tconst url = yield* Schema.decodeEffect(Url)(options.url)\n\tif (credentials.certificate !== undefined && url.protocol !== \"wss:\")\n\t\tyield* Schema.decodeEffect(\n\t\t\tUrl.check(\n\t\t\t\tSchema.makeFilter((url) => url.protocol === \"wss:\", {\n\t\t\t\t\texpected: \"wss:// for mutual TLS\",\n\t\t\t\t}),\n\t\t\t),\n\t\t)(options.url)\n\tconst address = url.pathname === \"/\" ? new URL(path, url).href : url.href\n\tconst services = yield* Layer.build(constructor(options.tls, credentials))\n\treturn yield* Socket.makeWebSocket(address, {\n\t\tprotocols: protocol,\n\t\topenTimeout: options.openTimeout ?? \"10 seconds\",\n\t}).pipe(Effect.provideContext(services))\n})\n\nexport const properties = (url: URL): Properties => ({\n\tprotocol: url.protocol === \"wss:\" ? \"wss\" : \"ws\",\n\tencrypted: url.protocol === \"wss:\",\n\tnetwork: true,\n\tcarries: url.protocol === \"wss:\" ? [\"header\", \"certificate\"] : [\"header\"],\n})\n"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SAAS;EAC3C,WAAW;EACX,aAAa,QAAQ,eAAe;CACrC,CAAC,CAAC,CAAC,KAAK,OAAO,eAAe,QAAQ,CAAC;AACxC,CAAC;AAED,MAAa,cAAc,SAA0B;CACpD,UAAU,IAAI,aAAa,SAAS,QAAQ;CAC5C,WAAW,IAAI,aAAa;CAC5B,SAAS;CACT,SAAS,IAAI,aAAa,SAAS,CAAC,UAAU,aAAa,IAAI,CAAC,QAAQ;AACzE"}
@@ -3,8 +3,8 @@ import { fromSocket } from "./socketChannel.js";
3
3
  import { payloadLimit, protocol } from "./websocket.js";
4
4
  import { Array, Cause, Deferred, Effect, Option, Redacted, Scope, String } from "effect";
5
5
  import { NodeHttpServer, NodeHttpServerRequest } from "@effect/platform-node";
6
- import { HttpServerRequest, HttpServerResponse } from "effect/http";
7
6
  import { TLSSocket } from "node:tls";
7
+ import { HttpServerRequest, HttpServerResponse } from "effect/http";
8
8
  // src/internal/websocketServer.ts
9
9
  const rejection = (error) => error._tag === "AuthenticatorUnavailable" ? unavailable(error) : unauthorized(error);
10
10
  const unavailable = (error) => Effect.logError("Remote host authenticator is unavailable", error.cause).pipe(Effect.as(HttpServerResponse.empty({ status: 503 })));
@@ -1 +1 @@
1
- {"version":3,"file":"websocketServer.js","names":["Channel.fromSocket"],"sources":["../../src/internal/websocketServer.ts"],"sourcesContent":["import { NodeHttpServer, NodeHttpServerRequest } from \"@effect/platform-node\"\nimport {\n\tArray,\n\tCause,\n\tDeferred,\n\tEffect,\n\tOption,\n\tRedacted,\n\tScope,\n\tString,\n} from \"effect\"\nimport { HttpServerRequest, HttpServerResponse } from \"effect/http\"\nimport type { Socket } from \"effect/socket\"\nimport { TLSSocket } from \"node:tls\"\nimport {\n\ttype AuthenticationFailed,\n\ttype AuthenticatorUnavailable,\n\tTransportError,\n} from \"../Errors\"\nimport type { Accept, Handshake, Serving } from \"../Transport\"\nimport * as Channel from \"./socketChannel\"\nimport { path, protocol, payloadLimit } from \"./websocket\"\n\nconst rejection = (error: AuthenticationFailed | AuthenticatorUnavailable) =>\n\terror._tag === \"AuthenticatorUnavailable\"\n\t\t? unavailable(error)\n\t\t: unauthorized(error)\n\n// The credential was not judged, so the client is told to retry rather than to replace it.\nconst unavailable = (error: AuthenticatorUnavailable) =>\n\tEffect.logError(\"Remote host authenticator is unavailable\", error.cause).pipe(\n\t\tEffect.as(HttpServerResponse.empty({ status: 503 })),\n\t)\n\nconst unauthorized = (error: AuthenticationFailed) =>\n\tEffect.logWarning(\n\t\t\"Remote host authentication failed\",\n\t\t{\n\t\t\treason: error.reason,\n\t\t},\n\t\t...(error.cause === undefined ? [] : [error.cause]),\n\t).pipe(\n\t\tEffect.as(\n\t\t\tHttpServerResponse.empty({\n\t\t\t\tstatus: 401,\n\t\t\t\theaders:\n\t\t\t\t\terror.challenge === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { \"www-authenticate\": error.challenge },\n\t\t\t}),\n\t\t),\n\t)\n\nconst handshake: Effect.Effect<\n\tHandshake,\n\tnever,\n\tHttpServerRequest.HttpServerRequest\n> = Effect.gen(function* () {\n\tconst request = yield* HttpServerRequest.HttpServerRequest\n\tconst { socket } = NodeHttpServerRequest.toIncomingMessage(request)\n\t// Only a TLS-verified peer is certificate evidence; forwarded headers are not.\n\tconst peer =\n\t\tsocket instanceof TLSSocket && socket.authorized\n\t\t\t? Option.some(socket.getPeerCertificate())\n\t\t\t: Option.none()\n\treturn {\n\t\tauthorization: Option.map(\n\t\t\tOption.fromUndefinedOr(request.headers[\"authorization\"]),\n\t\t\tRedacted.make,\n\t\t),\n\t\tcertificate: Option.map(peer, (certificate) => ({\n\t\t\tder: certificate.raw,\n\t\t\tsubjectAltName: Option.fromUndefinedOr(certificate.subjectaltname),\n\t\t})),\n\t}\n})\n\nconst open = Effect.fnUntraced(function* (\n\tcreateServer: Parameters<typeof NodeHttpServer.make>[0],\n\toptions: Pick<NodeHttpServer.Options, \"host\" | \"port\" | \"path\">,\n) {\n\t// The lazily created ws server belongs here, so serving scopes close before ws.close waits.\n\tconst resources = yield* Effect.acquireRelease(Scope.make(), Scope.close)\n\tconst ready = yield* Deferred.make<void>()\n\tconst server = yield* NodeHttpServer.make(createServer, {\n\t\t...options,\n\t\tdisablePreemptiveShutdown: true,\n\t\twebsocket: {\n\t\t\tperMessageDeflate: false,\n\t\t\tmaxPayload: payloadLimit,\n\t\t\thandleProtocols: (protocols) =>\n\t\t\t\tprotocols.has(protocol) ? protocol : false,\n\t\t},\n\t}).pipe(Scope.provide(resources))\n\treturn {\n\t\taddress: server.address,\n\t\tready: Deferred.await(ready),\n\t\trun: <A, E, R>(\n\t\t\taccept: Effect.Effect<\n\t\t\t\t(socket: Socket.Socket) => Effect.Effect<A, E, R>,\n\t\t\t\tAuthenticationFailed | AuthenticatorUnavailable,\n\t\t\t\tHttpServerRequest.HttpServerRequest\n\t\t\t>,\n\t\t) =>\n\t\t\tserver\n\t\t\t\t.serve(\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tconst request = yield* HttpServerRequest.HttpServerRequest\n\t\t\t\t\t\tif (request.url !== path)\n\t\t\t\t\t\t\treturn HttpServerResponse.empty({ status: 404 })\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tString.toLowerCase(request.headers[\"upgrade\"] ?? \"\") !==\n\t\t\t\t\t\t\t\t\"websocket\" ||\n\t\t\t\t\t\t\t!Array.some(\n\t\t\t\t\t\t\t\tString.split(\n\t\t\t\t\t\t\t\t\trequest.headers[\"sec-websocket-protocol\"] ?? \"\",\n\t\t\t\t\t\t\t\t\t\",\",\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t(value) => String.trim(value) === protocol,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn HttpServerResponse.empty({ status: 400 })\n\t\t\t\t\t\tconst session = yield* Effect.result(accept)\n\t\t\t\t\t\tif (session._tag === \"Failure\")\n\t\t\t\t\t\t\treturn yield* rejection(session.failure)\n\t\t\t\t\t\t// Authentication finishes before upgrade; session work is owned by the request scope.\n\t\t\t\t\t\tyield* request.upgrade.pipe(\n\t\t\t\t\t\t\tEffect.flatMap(session.success),\n\t\t\t\t\t\t\tEffect.interruptible,\n\t\t\t\t\t\t\tEffect.scoped,\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn HttpServerResponse.empty()\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.pipe(\n\t\t\t\t\tEffect.andThen(Deferred.succeed(ready, undefined)),\n\t\t\t\t\tEffect.andThen(Effect.never),\n\t\t\t\t),\n\t}\n})\n\nexport const bind = Effect.fnUntraced(function* (\n\tcreateServer: Parameters<typeof NodeHttpServer.make>[0],\n\toptions: Pick<NodeHttpServer.Options, \"host\" | \"port\" | \"path\">,\n) {\n\tconst server = yield* open(createServer, options)\n\treturn {\n\t\taddress: server.address,\n\t\tready: server.ready,\n\t\tserve: (accept: Accept) =>\n\t\t\tserver\n\t\t\t\t.run(\n\t\t\t\t\thandshake.pipe(\n\t\t\t\t\t\tEffect.flatMap(accept),\n\t\t\t\t\t\tEffect.map(\n\t\t\t\t\t\t\t(session) => (socket: Socket.Socket) =>\n\t\t\t\t\t\t\t\tChannel.fromSocket(socket).pipe(Effect.flatMap(session)),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.pipe(\n\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\tTransportError.make({ cause: Cause.fail(error) }),\n\t\t\t\t\t),\n\t\t\t\t),\n\t} satisfies Serving & { readonly address: typeof server.address }\n})\n"],"mappings":";;;;;;;;AAuBA,MAAM,aAAa,UAClB,MAAM,SAAS,6BACZ,YAAY,KAAK,IACjB,aAAa,KAAK;AAGtB,MAAM,eAAe,UACpB,OAAO,SAAS,4CAA4C,MAAM,KAAK,CAAC,CAAC,KACxE,OAAO,GAAG,mBAAmB,MAAM,EAAE,QAAQ,IAAI,CAAC,CAAC,CACpD;AAED,MAAM,gBAAgB,UACr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,MAAM,EAAE,QAAQ,IAAI,CAAC;GAChD,IACC,OAAO,YAAY,QAAQ,QAAQ,cAAc,EAAE,MAClD,eACD,CAAC,MAAM,KACN,OAAO,MACN,QAAQ,QAAQ,6BAA6B,IAC7C,GACD,IACC,UAAU,OAAO,KAAK,KAAK,MAAA,iBAC7B,GAEA,OAAO,mBAAmB,MAAM,EAAE,QAAQ,IAAI,CAAC;GAChD,MAAM,UAAU,OAAO,OAAO,OAAO,MAAM;GAC3C,IAAI,QAAQ,SAAS,WACpB,OAAO,OAAO,UAAU,QAAQ,OAAO;GAExC,OAAO,QAAQ,QAAQ,KACtB,OAAO,QAAQ,QAAQ,OAAO,GAC9B,OAAO,eACP,OAAO,MACR;GACA,OAAO,mBAAmB,MAAM;EACjC,CAAC,CACF,CAAC,CACA,KACA,OAAO,QAAQ,SAAS,QAAQ,OAAO,KAAA,CAAS,CAAC,GACjD,OAAO,QAAQ,OAAO,KAAK,CAC5B;CACH;AACD,CAAC;AAED,MAAa,OAAO,OAAO,WAAW,WACrC,cACA,SACC;CACD,MAAM,SAAS,OAAO,KAAK,cAAc,OAAO;CAChD,OAAO;EACN,SAAS,OAAO;EAChB,OAAO,OAAO;EACd,QAAQ,WACP,OACE,IACA,UAAU,KACT,OAAO,QAAQ,MAAM,GACrB,OAAO,KACL,aAAa,WACbA,WAAmB,MAAM,CAAC,CAAC,KAAK,OAAO,QAAQ,OAAO,CAAC,CACzD,CACD,CACD,CAAC,CACA,KACA,OAAO,UAAU,UAChB,eAAe,KAAK,EAAE,OAAO,MAAM,KAAK,KAAK,EAAE,CAAC,CACjD,CACD;CACH;AACD,CAAC"}
1
+ {"version":3,"file":"websocketServer.js","names":["Channel.fromSocket"],"sources":["../../src/internal/websocketServer.ts"],"sourcesContent":["import { TLSSocket } from \"node:tls\"\n\nimport {\n\tArray,\n\tCause,\n\tDeferred,\n\tEffect,\n\tOption,\n\tRedacted,\n\tScope,\n\tString,\n} from \"effect\"\nimport { HttpServerRequest, HttpServerResponse } from \"effect/http\"\nimport type { Socket } from \"effect/socket\"\nimport { NodeHttpServer, NodeHttpServerRequest } from \"@effect/platform-node\"\n\nimport {\n\tTransportError,\n\ttype AuthenticationFailed,\n\ttype AuthenticatorUnavailable,\n} from \"../Errors\"\nimport type { Accept, Handshake, Serving } from \"../Transport\"\nimport * as Channel from \"./socketChannel\"\nimport { path, payloadLimit, protocol } from \"./websocket\"\n\nconst rejection = (error: AuthenticationFailed | AuthenticatorUnavailable) =>\n\terror._tag === \"AuthenticatorUnavailable\"\n\t\t? unavailable(error)\n\t\t: unauthorized(error)\n\n// The credential was not judged, so the client is told to retry rather than to replace it.\nconst unavailable = (error: AuthenticatorUnavailable) =>\n\tEffect.logError(\"Remote host authenticator is unavailable\", error.cause).pipe(\n\t\tEffect.as(HttpServerResponse.empty({ status: 503 })),\n\t)\n\nconst unauthorized = (error: AuthenticationFailed) =>\n\tEffect.logWarning(\n\t\t\"Remote host authentication failed\",\n\t\t{\n\t\t\treason: error.reason,\n\t\t},\n\t\t...(error.cause === undefined ? [] : [error.cause]),\n\t).pipe(\n\t\tEffect.as(\n\t\t\tHttpServerResponse.empty({\n\t\t\t\tstatus: 401,\n\t\t\t\theaders:\n\t\t\t\t\terror.challenge === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { \"www-authenticate\": error.challenge },\n\t\t\t}),\n\t\t),\n\t)\n\nconst handshake: Effect.Effect<\n\tHandshake,\n\tnever,\n\tHttpServerRequest.HttpServerRequest\n> = Effect.gen(function* () {\n\tconst request = yield* HttpServerRequest.HttpServerRequest\n\tconst { socket } = NodeHttpServerRequest.toIncomingMessage(request)\n\t// Only a TLS-verified peer is certificate evidence; forwarded headers are not.\n\tconst peer =\n\t\tsocket instanceof TLSSocket && socket.authorized\n\t\t\t? Option.some(socket.getPeerCertificate())\n\t\t\t: Option.none()\n\treturn {\n\t\tauthorization: Option.map(\n\t\t\tOption.fromUndefinedOr(request.headers[\"authorization\"]),\n\t\t\tRedacted.make,\n\t\t),\n\t\tcertificate: Option.map(peer, (certificate) => ({\n\t\t\tder: certificate.raw,\n\t\t\tsubjectAltName: Option.fromUndefinedOr(certificate.subjectaltname),\n\t\t})),\n\t}\n})\n\nconst open = Effect.fnUntraced(function* (\n\tcreateServer: Parameters<typeof NodeHttpServer.make>[0],\n\toptions: Pick<NodeHttpServer.Options, \"host\" | \"port\" | \"path\">,\n) {\n\t// The lazily created ws server belongs here, so serving scopes close before ws.close waits.\n\tconst resources = yield* Effect.acquireRelease(Scope.make(), Scope.close)\n\tconst ready = yield* Deferred.make<void>()\n\tconst server = yield* NodeHttpServer.make(createServer, {\n\t\t...options,\n\t\tdisablePreemptiveShutdown: true,\n\t\twebsocket: {\n\t\t\tperMessageDeflate: false,\n\t\t\tmaxPayload: payloadLimit,\n\t\t\thandleProtocols: (protocols) =>\n\t\t\t\tprotocols.has(protocol) ? protocol : false,\n\t\t},\n\t}).pipe(Scope.provide(resources))\n\treturn {\n\t\taddress: server.address,\n\t\tready: Deferred.await(ready),\n\t\trun: <A, E, R>(\n\t\t\taccept: Effect.Effect<\n\t\t\t\t(socket: Socket.Socket) => Effect.Effect<A, E, R>,\n\t\t\t\tAuthenticationFailed | AuthenticatorUnavailable,\n\t\t\t\tHttpServerRequest.HttpServerRequest\n\t\t\t>,\n\t\t) =>\n\t\t\tserver\n\t\t\t\t.serve(\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tconst request = yield* HttpServerRequest.HttpServerRequest\n\t\t\t\t\t\tif (request.url !== path)\n\t\t\t\t\t\t\treturn HttpServerResponse.empty({ status: 404 })\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tString.toLowerCase(request.headers[\"upgrade\"] ?? \"\") !==\n\t\t\t\t\t\t\t\t\"websocket\" ||\n\t\t\t\t\t\t\t!Array.some(\n\t\t\t\t\t\t\t\tString.split(\n\t\t\t\t\t\t\t\t\trequest.headers[\"sec-websocket-protocol\"] ?? \"\",\n\t\t\t\t\t\t\t\t\t\",\",\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t(value) => String.trim(value) === protocol,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn HttpServerResponse.empty({ status: 400 })\n\t\t\t\t\t\tconst session = yield* Effect.result(accept)\n\t\t\t\t\t\tif (session._tag === \"Failure\")\n\t\t\t\t\t\t\treturn yield* rejection(session.failure)\n\t\t\t\t\t\t// Authentication finishes before upgrade; session work is owned by the request scope.\n\t\t\t\t\t\tyield* request.upgrade.pipe(\n\t\t\t\t\t\t\tEffect.flatMap(session.success),\n\t\t\t\t\t\t\tEffect.interruptible,\n\t\t\t\t\t\t\tEffect.scoped,\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn HttpServerResponse.empty()\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.pipe(\n\t\t\t\t\tEffect.andThen(Deferred.succeed(ready, undefined)),\n\t\t\t\t\tEffect.andThen(Effect.never),\n\t\t\t\t),\n\t}\n})\n\nexport const bind = Effect.fnUntraced(function* (\n\tcreateServer: Parameters<typeof NodeHttpServer.make>[0],\n\toptions: Pick<NodeHttpServer.Options, \"host\" | \"port\" | \"path\">,\n) {\n\tconst server = yield* open(createServer, options)\n\treturn {\n\t\taddress: server.address,\n\t\tready: server.ready,\n\t\tserve: (accept: Accept) =>\n\t\t\tserver\n\t\t\t\t.run(\n\t\t\t\t\thandshake.pipe(\n\t\t\t\t\t\tEffect.flatMap(accept),\n\t\t\t\t\t\tEffect.map(\n\t\t\t\t\t\t\t(session) => (socket: Socket.Socket) =>\n\t\t\t\t\t\t\t\tChannel.fromSocket(socket).pipe(Effect.flatMap(session)),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.pipe(\n\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\tTransportError.make({ cause: Cause.fail(error) }),\n\t\t\t\t\t),\n\t\t\t\t),\n\t} satisfies Serving & { readonly address: type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,KAAK,EAAE,CAAC,CACjD,CACD;CACH;AACD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"workerChannel.js","names":[],"sources":["../../src/internal/workerChannel.ts"],"sourcesContent":["import { Cause, Effect, FiberSet, Queue, Sink, Stream } from \"effect\"\nimport { TransportError } from \"../Errors\"\nimport type { Channel } from \"./port\"\n\n/** Both ends send owned ArrayBuffers; null is the byte stream's EOF. */\nexport interface Endpoint {\n\treadonly postMessage: (\n\t\tvalue: ArrayBuffer | null,\n\t\ttransferList: ArrayBuffer[],\n\t) => void\n\treadonly on: (\n\t\tevent: \"message\",\n\t\tlistener: (value: ArrayBuffer | null) => void,\n\t) => unknown\n\treadonly off: (\n\t\tevent: \"message\",\n\t\tlistener: (value: ArrayBuffer | null) => void,\n\t) => unknown\n}\nexport const make = Effect.fnUntraced(function* (endpoint: Endpoint) {\n\t// Port owns admission and RPC chunk backpressure; this queue only bridges message events.\n\tconst input = yield* Queue.unbounded<Uint8Array, Cause.Done>()\n\tconst callbacks = yield* FiberSet.make()\n\tconst run = yield* FiberSet.runtime(callbacks)()\n\tconst receive = (value: ArrayBuffer | null) =>\n\t\trun(\n\t\t\tvalue === null\n\t\t\t\t? Queue.end(input)\n\t\t\t\t: Queue.offer(input, new Uint8Array(value)),\n\t\t)\n\tyield* Effect.acquireRelease(\n\t\tEffect.sync(() => endpoint.on(\"message\", receive)),\n\t\t() =>\n\t\t\tEffect.sync(() => endpoint.off(\"message\", receive)).pipe(\n\t\t\t\tEffect.andThen(Queue.shutdown(input)),\n\t\t\t),\n\t)\n\tconst send = (bytes: Uint8Array | null) =>\n\t\tEffect.try({\n\t\t\ttry: () => {\n\t\t\t\t// Copy even Buffer slices: only this fresh, exact-sized backing store is transferable.\n\t\t\t\tconst buffer = bytes === null ? null : new Uint8Array(bytes).buffer\n\t\t\t\tendpoint.postMessage(buffer, buffer === null ? [] : [buffer])\n\t\t\t},\n\t\t\tcatch: (cause) => TransportError.make({ cause: Cause.die(cause) }),\n\t\t})\n\treturn {\n\t\tinput: Stream.fromQueue(input),\n\t\toutput: Sink.forEach((bytes: Uint8Array) => send(bytes)).pipe(\n\t\t\t// Closing the output half always sends EOF, including when its writer is interrupted.\n\t\t\tSink.ensuring(send(null)),\n\t\t),\n\t} satisfies Channel\n})\n"],"mappings":";;;AAmBA,MAAa,OAAO,OAAO,WAAW,WAAW,UAAoB;CAEpE,MAAM,QAAQ,OAAO,MAAM,UAAkC;CAC7D,MAAM,YAAY,OAAO,SAAS,KAAK;CACvC,MAAM,MAAM,OAAO,SAAS,QAAQ,SAAS,CAAC,CAAC;CAC/C,MAAM,WAAW,UAChB,IACC,UAAU,OACP,MAAM,IAAI,KAAK,IACf,MAAM,MAAM,OAAO,IAAI,WAAW,KAAK,CAAC,CAC5C;CACD,OAAO,OAAO,eACb,OAAO,WAAW,SAAS,GAAG,WAAW,OAAO,CAAC,SAEhD,OAAO,WAAW,SAAS,IAAI,WAAW,OAAO,CAAC,CAAC,CAAC,KACnD,OAAO,QAAQ,MAAM,SAAS,KAAK,CAAC,CACrC,CACF;CACA,MAAM,QAAQ,UACb,OAAO,IAAI;EACV,WAAW;GAEV,MAAM,SAAS,UAAU,OAAO,OAAO,IAAI,WAAW,KAAK,CAAC,CAAC;GAC7D,SAAS,YAAY,QAAQ,WAAW,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;EAC7D;EACA,QAAQ,UAAU,eAAe,KAAK,EAAE,OAAO,MAAM,IAAI,KAAK,EAAE,CAAC;CAClE,CAAC;CACF,OAAO;EACN,OAAO,OAAO,UAAU,KAAK;EAC7B,QAAQ,KAAK,SAAS,UAAsB,KAAK,KAAK,CAAC,CAAC,CAAC,KAExD,KAAK,SAAS,KAAK,IAAI,CAAC,CACzB;CACD;AACD,CAAC"}
1
+ {"version":3,"file":"workerChannel.js","names":[],"sources":["../../src/internal/workerChannel.ts"],"sourcesContent":["import { Cause, Effect, FiberSet, Queue, Sink, Stream } from \"effect\"\n\nimport { TransportError } from \"../Errors\"\nimport type { Channel } from \"./port\"\n\n/** Both ends send owned ArrayBuffers; null is the byte stream's EOF. */\nexport interface Endpoint {\n\treadonly postMessage: (\n\t\tvalue: ArrayBuffer | null,\n\t\ttransferList: ArrayBuffer[],\n\t) => void\n\treadonly on: (\n\t\tevent: \"message\",\n\t\tlistener: (value: ArrayBuffer | null) => void,\n\t) => unknown\n\treadonly off: (\n\t\tevent: \"message\",\n\t\tlistener: (value: ArrayBuffer | null) => void,\n\t) => unknown\n}\nexport const make = Effect.fnUntraced(function* (endpoint: Endpoint) {\n\t// Port owns admission and RPC chunk backpressure; this queue only bridges message events.\n\tconst input = yield* Queue.unbounded<Uint8Array, Cause.Done>()\n\tconst callbacks = yield* FiberSet.make()\n\tconst run = yield* FiberSet.runtime(callbacks)()\n\tconst receive = (value: ArrayBuffer | null) =>\n\t\trun(\n\t\t\tvalue === null\n\t\t\t\t? Queue.end(input)\n\t\t\t\t: Queue.offer(input, new Uint8Array(value)),\n\t\t)\n\tyield* Effect.acquireRelease(\n\t\tEffect.sync(() => endpoint.on(\"message\", receive)),\n\t\t() =>\n\t\t\tEffect.sync(() => endpoint.off(\"message\", receive)).pipe(\n\t\t\t\tEffect.andThen(Queue.shutdown(input)),\n\t\t\t),\n\t)\n\tconst send = (bytes: Uint8Array | null) =>\n\t\tEffect.try({\n\t\t\ttry: () => {\n\t\t\t\t// Copy even Buffer slices: only this fresh, exact-sized backing store is transferable.\n\t\t\t\tconst buffer = bytes === null ? null : new Uint8Array(bytes).buffer\n\t\t\t\tendpoint.postMessage(buffer, buffer === null ? [] : [buffer])\n\t\t\t},\n\t\t\tcatch: (cause) => TransportError.make({ cause: Cause.die(cause) }),\n\t\t})\n\treturn {\n\t\tinput: Stream.fromQueue(input),\n\t\toutput: Sink.forEach((bytes: Uint8Array) => send(bytes)).pipe(\n\t\t\t// Closing the output half always sends EOF, including when its writer is interrupted.\n\t\t\tSink.ensuring(send(null)),\n\t\t),\n\t} satisfies Channel\n})\n"],"mappings":";;;AAoBA,MAAa,OAAO,OAAO,WAAW,WAAW,UAAoB;CAEpE,MAAM,QAAQ,OAAO,MAAM,UAAkC;CAC7D,MAAM,YAAY,OAAO,SAAS,KAAK;CACvC,MAAM,MAAM,OAAO,SAAS,QAAQ,SAAS,CAAC,CAAC;CAC/C,MAAM,WAAW,UAChB,IACC,UAAU,OACP,MAAM,IAAI,KAAK,IACf,MAAM,MAAM,OAAO,IAAI,WAAW,KAAK,CAAC,CAC5C;CACD,OAAO,OAAO,eACb,OAAO,WAAW,SAAS,GAAG,WAAW,OAAO,CAAC,SAEhD,OAAO,WAAW,SAAS,IAAI,WAAW,OAAO,CAAC,CAAC,CAAC,KACnD,OAAO,QAAQ,MAAM,SAAS,KAAK,CAAC,CACrC,CACF;CACA,MAAM,QAAQ,UACb,OAAO,IAAI;EACV,WAAW;GAEV,MAAM,SAAS,UAAU,OAAO,OAAO,IAAI,WAAW,KAAK,CAAC,CAAC;GAC7D,SAAS,YAAY,QAAQ,WAAW,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;EAC7D;EACA,QAAQ,UAAU,eAAe,KAAK,EAAE,OAAO,MAAM,IAAI,KAAK,EAAE,CAAC;CAClE,CAAC;CACF,OAAO;EACN,OAAO,OAAO,UAAU,KAAK;EAC7B,QAAQ,KAAK,SAAS,UAAsB,KAAK,KAAK,CAAC,CAAC,CAAC,KAExD,KAAK,SAAS,KAAK,IAAI,CAAC,CACzB;CACD;AACD,CAAC"}
@@ -1,10 +1,12 @@
1
- import { r as layer } from "../Graft-B71CPA2Y.js";
2
- import { n as run, r as platform, t as load } from "../childRuntime-Bm3iSg_N.js";
3
- import { n as Bootstrap, t as make } from "../workerChannel-C8hhBJzA.js";
4
- import { Effect, Layer, Schema } from "effect";
1
+ import { load, run } from "./childRuntime.js";
2
+ import { platform } from "./platform.js";
3
+ import { Bootstrap } from "./workerBootstrap.js";
4
+ import { make } from "./workerChannel.js";
5
+ import { Cause, Effect, Layer, Logger, Schema } from "effect";
6
+ import { Graft } from "@graftland/graft";
5
7
  import { NodeRuntime } from "@effect/platform-node";
6
8
  import { parentPort, workerData } from "node:worker_threads";
7
- // packages/remote/src/internal/workerMain.ts
9
+ // src/internal/workerMain.ts
8
10
  /** Executable entry for a direct worker; platform services belong to this thread. */
9
11
  const main = Effect.scoped(Effect.gen(function* () {
10
12
  const port = yield* Effect.fromNullishOr(parentPort);
@@ -14,5 +16,10 @@ const main = Effect.scoped(Effect.gen(function* () {
14
16
  const contract = yield* load(bootstrap.contractModule);
15
17
  yield* run(contract, channel, bootstrap.session);
16
18
  }));
17
- NodeRuntime.runMain(main.pipe(Effect.provide(layer.pipe(Layer.provide(platform)))));
19
+ NodeRuntime.runMain(Effect.scoped(Effect.gen(function* () {
20
+ const context = yield* Layer.build(Graft.layer.pipe(Layer.provide(platform)));
21
+ return yield* main.pipe(Effect.provideContext(context));
22
+ })).pipe(Effect.tapCause((cause) => Cause.hasInterruptsOnly(cause) ? Effect.void : Effect.logError(cause)), Effect.provideService(Logger.LogToStderr, true)), { disableErrorReporting: true });
18
23
  export {};
24
+
25
+ //# sourceMappingURL=workerMain.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"workerMain.js","names":["Channel.make"],"sources":["../../src/internal/workerMain.ts"],"sourcesContent":["/** Executable entry for a direct worker; platform services belong to this thread. */\nimport { Graft } from \"@graftland/graft\"\nimport { NodeRuntime } from \"@effect/platform-node\"\nimport { Effect, Layer, Schema } from \"effect\"\nimport { parentPort, workerData } from \"node:worker_threads\"\nimport { load, run } from \"./childRuntime\"\nimport { Bootstrap } from \"./workerBootstrap\"\nimport * as Channel from \"./workerChannel\"\nimport { platform } from \"./platform\"\n\nconst main = Effect.scoped(\n\tEffect.gen(function* () {\n\t\tconst port = yield* Effect.fromNullishOr(parentPort)\n\t\tyield* Effect.addFinalizer(() => Effect.sync(() => port.close()))\n\t\tconst bootstrap = yield* Schema.decodeUnknownEffect(Bootstrap)(workerData)\n\t\tconst channel = yield* Channel.make(port)\n\t\tconst contract = yield* load(bootstrap.contractModule)\n\t\tyield* run(contract, channel, bootstrap.session)\n\t}),\n)\nNodeRuntime.runMain(\n\tmain.pipe(Effect.provide(Graft.layer.pipe(Layer.provide(platform)))),\n)\n"],"mappings":";;;;;;;;;;AAUA,MAAM,OAAO,OAAO,OACnB,OAAO,IAAI,aAAa;CACvB,MAAM,OAAO,OAAO,OAAO,cAAc,UAAU;CACnD,OAAO,OAAO,mBAAmB,OAAO,WAAW,KAAK,MAAM,CAAC,CAAC;CAChE,MAAM,YAAY,OAAO,OAAO,oBAAoB,SAAS,CAAC,CAAC,UAAU;CACzE,MAAM,UAAU,OAAOA,KAAa,IAAI;CACxC,MAAM,WAAW,OAAO,KAAK,UAAU,cAAc;CACrD,OAAO,IAAI,UAAU,SAAS,UAAU,OAAO;AAChD,CAAC,CACF;AACA,YAAY,QACX,KAAK,KAAK,OAAO,QAAQ,MAAM,MAAM,KAAK,MAAM,QAAQ,QAAQ,CAAC,CAAC,CAAC,CACpE"}
1
+ {"version":3,"file":"workerMain.js","names":["Channel.make"],"sources":["../../src/internal/workerMain.ts"],"sourcesContent":["/** Executable entry for a direct worker; platform services belong to this thread. */\nimport { parentPort, workerData } from \"node:worker_threads\"\n\nimport { Cause, Effect, Layer, Logger, Schema } from \"effect\"\nimport { NodeRuntime } from \"@effect/platform-node\"\n\nimport { Graft } from \"@graftland/graft\"\n\nimport { load, run } from \"./childRuntime\"\nimport { platform } from \"./platform\"\nimport { Bootstrap } from \"./workerBootstrap\"\nimport * as Channel from \"./workerChannel\"\n\nconst main = Effect.scoped(\n\tEffect.gen(function* () {\n\t\tconst port = yield* Effect.fromNullishOr(parentPort)\n\t\tyield* Effect.addFinalizer(() => Effect.sync(() => port.close()))\n\t\tconst bootstrap = yield* Schema.decodeUnknownEffect(Bootstrap)(workerData)\n\t\tconst channel = yield* Channel.make(port)\n\t\tconst contract = yield* load(bootstrap.contractModule)\n\t\tyield* run(contract, channel, bootstrap.session)\n\t}),\n)\nNodeRuntime.runMain(\n\tEffect.scoped(\n\t\tEffect.gen(function* () {\n\t\t\tconst context = yield* Layer.build(\n\t\t\t\tGraft.layer.pipe(Layer.provide(platform)),\n\t\t\t)\n\t\t\treturn yield* main.pipe(Effect.provideContext(context))\n\t\t}),\n\t).pipe(\n\t\tEffect.tapCause((cause) =>\n\t\t\tCause.hasInterruptsOnly(cause) ? Effect.void : Effect.logError(cause),\n\t\t),\n\t\tEffect.provideService(Logger.LogToStderr, true),\n\t),\n\t{ disableErrorReporting: true },\n)\n"],"mappings":";;;;;;;;;;AAaA,MAAM,OAAO,OAAO,OACnB,OAAO,IAAI,aAAa;CACvB,MAAM,OAAO,OAAO,OAAO,cAAc,UAAU;CACnD,OAAO,OAAO,mBAAmB,OAAO,WAAW,KAAK,MAAM,CAAC,CAAC;CAChE,MAAM,YAAY,OAAO,OAAO,oBAAoB,SAAS,CAAC,CAAC,UAAU;CACzE,MAAM,UAAU,OAAOA,KAAa,IAAI;CACxC,MAAM,WAAW,OAAO,KAAK,UAAU,cAAc;CACrD,OAAO,IAAI,UAAU,SAAS,UAAU,OAAO;AAChD,CAAC,CACF;AACA,YAAY,QACX,OAAO,OACN,OAAO,IAAI,aAAa;CACvB,MAAM,UAAU,OAAO,MAAM,MAC5B,MAAM,MAAM,KAAK,MAAM,QAAQ,QAAQ,CAAC,CACzC;CACA,OAAO,OAAO,KAAK,KAAK,OAAO,eAAe,OAAO,CAAC;AACvD,CAAC,CACF,CAAC,CAAC,KACD,OAAO,UAAU,UAChB,MAAM,kBAAkB,KAAK,IAAI,OAAO,OAAO,OAAO,SAAS,KAAK,CACrE,GACA,OAAO,eAAe,OAAO,aAAa,IAAI,CAC/C,GACA,EAAE,uBAAuB,KAAK,CAC/B"}
@@ -1,12 +1,10 @@
1
- import { Graft, Plugin } from "@graftland/graft";
1
+ import { Bearer } from "../../internal/auth/config.js";
2
2
  import { Schema } from "effect";
3
- export declare const Config: Schema.Struct<{
4
- readonly tokens: Schema.String;
5
- }>;
3
+ import { Graft, Plugin } from "@graftland/graft";
6
4
  declare const _default: Plugin.Definition<{
7
5
  readonly tokens: string;
8
6
  }, {
9
7
  readonly tokens: string;
10
8
  }, import("effect/encoding/EncodingError").EncodingError | import("effect/PlatformError").PlatformError | Schema.SchemaError | Graft.ServiceConflict>;
11
- export { _default as default };
9
+ export { Bearer as Config, _default as default };
12
10
  //# sourceMappingURL=bearer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bearer.d.ts","names":[],"sources":["../../../src/runner/auth/bearer.ts"],"mappings":";;qBAmBa,QAAM,OAAA"}
1
+ {"version":3,"file":"bearer.d.ts","names":[],"sources":["../../../src/runner/auth/bearer.ts"],"mappings":""}
@@ -1,17 +1,17 @@
1
- import { a as provide, l as make } from "../../Graft-B71CPA2Y.js";
2
- import { t as Authenticator } from "../../Auth-BElTC9_X.js";
3
- import { t as ConfigDirectory } from "../../ConfigDirectory-BCC6q2R4.js";
4
- import { r as read, t as invalid } from "../../token-CYBNNlhS.js";
1
+ import { Authenticator } from "../../Auth.js";
2
+ import { Bearer } from "../../internal/auth/config.js";
3
+ import { invalid, read } from "../../internal/auth/token.js";
5
4
  import { Array, Effect, FileSystem, Option, Path, Record, Redacted, Schema } from "effect";
6
5
  import { Digest } from "effect/crypto";
7
- import { Hex } from "effect/encoding";
6
+ import { Graft, Plugin } from "@graftland/graft";
7
+ import { ConfigDirectory } from "@graftland/loader";
8
8
  import { timingSafeEqual } from "node:crypto";
9
- // packages/remote/src/runner/auth/bearer.ts
10
- const Config = Schema.Struct({ tokens: Schema.String });
9
+ import { Hex } from "effect/encoding";
10
+ // src/runner/auth/bearer.ts
11
11
  const Tokens = Schema.fromJsonString(Schema.Record(Schema.String.check(Schema.isPattern(/^[0-9a-fA-F]{64}$/)), Schema.NonEmptyString));
12
- var bearer_default = make({
12
+ var bearer_default = Plugin.make({
13
13
  name: "remote-bearer-authenticator",
14
- config: Config,
14
+ config: Bearer,
15
15
  inject: [
16
16
  FileSystem.FileSystem,
17
17
  Path.Path,
@@ -28,7 +28,7 @@ var bearer_default = make({
28
28
  hash,
29
29
  identity
30
30
  }))));
31
- yield* provide(Authenticator, {
31
+ yield* Graft.provide(Authenticator, {
32
32
  _tag: "Header",
33
33
  authenticate: Effect.fnUntraced(function* (authorization) {
34
34
  const token = yield* read(authorization);
@@ -39,4 +39,6 @@ var bearer_default = make({
39
39
  });
40
40
  })
41
41
  });
42
- export { Config, bearer_default as default };
42
+ export { Bearer as Config, bearer_default as default };
43
+
44
+ //# sourceMappingURL=bearer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bearer.js","names":["Token.read","Token.invalid"],"sources":["../../../src/runner/auth/bearer.ts"],"sourcesContent":["import { Option } from \"effect\"\nimport { Graft, Plugin } from \"@graftland/graft\"\nimport {\n\tArray,\n\tEffect,\n\tFileSystem,\n\tPath,\n\tRecord,\n\tRedacted,\n\tSchema,\n} from \"effect\"\nimport { Digest } from \"effect/crypto\"\nimport { Hex } from \"effect/encoding\"\n// @effect-diagnostics-next-line nodeBuiltinImport:off -- Token digests use Node's constant-time comparison\nimport { timingSafeEqual } from \"node:crypto\"\nimport { Authenticator } from \"../../Auth\"\nimport { ConfigDirectory } from \"@graftland/loader\"\nimport * as Token from \"../../internal/auth/token\"\n\nexport const Config = Schema.Struct({ tokens: Schema.String })\nconst Tokens = Schema.fromJsonString(\n\tSchema.Record(\n\t\tSchema.String.check(Schema.isPattern(/^[0-9a-fA-F]{64}$/)),\n\t\tSchema.NonEmptyString,\n\t),\n)\nexport default Plugin.make({\n\tname: \"remote-bearer-authenticator\",\n\tconfig: Config,\n\tinject: [FileSystem.FileSystem, Path.Path, Digest.Digest],\n\tapply: Effect.fnUntraced(function* (config) {\n\t\tconst fs = yield* FileSystem.FileSystem\n\t\tconst path = yield* Path.Path\n\t\tconst directory = yield* ConfigDirectory.pipe(\n\t\t\tEffect.map(Option.getOrElse(() => \".\")),\n\t\t)\n\t\tconst digest = yield* Digest.Digest\n\t\tconst file = yield* fs.readFileString(\n\t\t\tpath.resolve(directory, config.tokens),\n\t\t)\n\t\tconst mapping = yield* Schema.decodeEffect(Tokens)(file)\n\t\tconst tokens = yield* Effect.forEach(\n\t\t\tRecord.toEntries(mapping),\n\t\t\t([hex, identity]) =>\n\t\t\t\tEffect.fromResult(Hex.decode(hex)).pipe(\n\t\t\t\t\tEffect.map((hash) => ({ hash, identity })),\n\t\t\t\t),\n\t\t)\n\t\tyield* Graft.provide(Authenticator, {\n\t\t\t_tag: \"Header\",\n\t\t\tauthenticate: Effect.fnUntraced(function* (authorization) {\n\t\t\t\tconst token = yield* Token.read(authorization)\n\t\t\t\tconst hash = yield* digest.digest(\n\t\t\t\t\tDigest.sha256,\n\t\t\t\t\tnew TextEncoder().encode(Redacted.value(token)),\n\t\t\t\t)\n\t\t\t\tconst found = Array.findFirst(tokens, (entry) =>\n\t\t\t\t\ttimingSafeEqual(hash, entry.hash),\n\t\t\t\t)\n\t\t\t\treturn yield* Effect.fromOption(found, Token.invalid).pipe(\n\t\t\t\t\tEffect.map((entry) => entry.identity),\n\t\t\t\t)\n\t\t\t}),\n\t\t})\n\t}),\n})\n"],"mappings":";;;;;;;;;AAmBA,MAAa,SAAS,OAAO,OAAO,EAAE,QAAQ,OAAO,OAAO,CAAC;AAC7D,MAAM,SAAS,OAAO,eACrB,OAAO,OACN,OAAO,OAAO,MAAM,OAAO,UAAU,mBAAmB,CAAC,GACzD,OAAO,cACR,CACD;AACA,IAAA,iBAAe,OAAO,KAAK;CAC1B,MAAM;CACN,QAAQ;CACR,QAAQ;EAAC,WAAW;EAAY,KAAK;EAAM,OAAO;CAAM;CACxD,OAAO,OAAO,WAAW,WAAW,QAAQ;EAC3C,MAAM,KAAK,OAAO,WAAW;EAC7B,MAAM,OAAO,OAAO,KAAK;EACzB,MAAM,YAAY,OAAO,gBAAgB,KACxC,OAAO,IAAI,OAAO,gBAAgB,GAAG,CAAC,CACvC;EACA,MAAM,SAAS,OAAO,OAAO;EAC7B,MAAM,OAAO,OAAO,GAAG,eACtB,KAAK,QAAQ,WAAW,OAAO,MAAM,CACtC;EACA,MAAM,UAAU,OAAO,OAAO,aAAa,MAAM,CAAC,CAAC,IAAI;EACvD,MAAM,SAAS,OAAO,OAAO,QAC5B,OAAO,UAAU,OAAO,IACvB,CAAC,KAAK,cACN,OAAO,WAAW,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,KAClC,OAAO,KAAK,UAAU;GAAE;GAAM;EAAS,EAAE,CAC1C,CACF;EACA,OAAO,MAAM,QAAQ,eAAe;GACnC,MAAM;GACN,cAAc,OAAO,WAAW,WAAW,eAAe;IACzD,MAAM,QAAQ,OAAOA,KAAW,aAAa;IAC7C,MAAM,OAAO,OAAO,OAAO,OAC1B,OAAO,QACP,IAAI,YAAY,CAAC,CAAC,OAAO,SAAS,MAAM,KAAK,CAAC,CAC/C;IACA,MAAM,QAAQ,MAAM,UAAU,SAAS,UACtC,gBAAgB,MAAM,MAAM,IAAI,CACjC;IACA,OAAO,OAAO,OAAO,WAAW,OAAOC,OAAa,CAAC,CAAC,KACrD,OAAO,KAAK,UAAU,MAAM,QAAQ,CACrC;GACD,CAAC;EACF,CAAC;CACF,CAAC;AACF,CAAC"}
1
+ {"version":3,"file":"bearer.js","names":["Config","Token.read","Token.invalid"],"sources":["../../../src/runner/auth/bearer.ts"],"sourcesContent":["// @effect-diagnostics-next-line nodeBuiltinImport:off -- Token digests use Node's constant-time comparison\nimport { timingSafeEqual } from \"node:crypto\"\n\nimport {\n\tArray,\n\tEffect,\n\tFileSystem,\n\tOption,\n\tPath,\n\tRecord,\n\tRedacted,\n\tSchema,\n} from \"effect\"\nimport { Digest } from \"effect/crypto\"\nimport { Hex } from \"effect/encoding\"\n\nimport { Graft, Plugin } from \"@graftland/graft\"\nimport { ConfigDirectory } from \"@graftland/loader\"\n\nimport { Authenticator } from \"../../Auth\"\nimport { Bearer as Config } from \"../../internal/auth/config\"\nimport * as Token from \"../../internal/auth/token\"\n\nexport { Config }\nconst Tokens = Schema.fromJsonString(\n\tSchema.Record(\n\t\tSchema.String.check(Schema.isPattern(/^[0-9a-fA-F]{64}$/)),\n\t\tSchema.NonEmptyString,\n\t),\n)\nexport default Plugin.make({\n\tname: \"remote-bearer-authenticator\",\n\tconfig: Config,\n\tinject: [FileSystem.FileSystem, Path.Path, Digest.Digest],\n\tapply: Effect.fnUntraced(function* (config) {\n\t\tconst fs = yield* FileSystem.FileSystem\n\t\tconst path = yield* Path.Path\n\t\tconst directory = yield* ConfigDirectory.pipe(\n\t\t\tEffect.map(Option.getOrElse(() => \".\")),\n\t\t)\n\t\tconst digest = yield* Digest.Digest\n\t\tconst file = yield* fs.readFileString(\n\t\t\tpath.resolve(directory, config.tokens),\n\t\t)\n\t\tconst mapping = yield* Schema.decodeEffect(Tokens)(file)\n\t\tconst tokens = yield* Effect.forEach(\n\t\t\tRecord.toEntries(mapping),\n\t\t\t([hex, identity]) =>\n\t\t\t\tEffect.fromResult(Hex.decode(hex)).pipe(\n\t\t\t\t\tEffect.map((hash) => ({ hash, identity })),\n\t\t\t\t),\n\t\t)\n\t\tyield* Graft.provide(Authenticator, {\n\t\t\t_tag: \"Header\",\n\t\t\tauthenticate: Effect.fnUntraced(function* (authorization) {\n\t\t\t\tconst token = yield* Token.read(authorization)\n\t\t\t\tconst hash = yield* digest.digest(\n\t\t\t\t\tDigest.sha256,\n\t\t\t\t\tnew TextEncoder().encode(Redacted.value(token)),\n\t\t\t\t)\n\t\t\t\tconst found = Array.findFirst(tokens, (entry) =>\n\t\t\t\t\ttimingSafeEqual(hash, entry.hash),\n\t\t\t\t)\n\t\t\t\treturn yield* Effect.fromOption(found, Token.invalid).pipe(\n\t\t\t\t\tEffect.map((entry) => entry.identity),\n\t\t\t\t)\n\t\t\t}),\n\t\t})\n\t}),\n})\n"],"mappings":";;;;;;;;;;AAwBA,MAAM,SAAS,OAAO,eACrB,OAAO,OACN,OAAO,OAAO,MAAM,OAAO,UAAU,mBAAmB,CAAC,GACzD,OAAO,cACR,CACD;AACA,IAAA,iBAAe,OAAO,KAAK;CAC1B,MAAM;CACN,QAAQA;CACR,QAAQ;EAAC,WAAW;EAAY,KAAK;EAAM,OAAO;CAAM;CACxD,OAAO,OAAO,WAAW,WAAW,QAAQ;EAC3C,MAAM,KAAK,OAAO,WAAW;EAC7B,MAAM,OAAO,OAAO,KAAK;EACzB,MAAM,YAAY,OAAO,gBAAgB,KACxC,OAAO,IAAI,OAAO,gBAAgB,GAAG,CAAC,CACvC;EACA,MAAM,SAAS,OAAO,OAAO;EAC7B,MAAM,OAAO,OAAO,GAAG,eACtB,KAAK,QAAQ,WAAW,OAAO,MAAM,CACtC;EACA,MAAM,UAAU,OAAO,OAAO,aAAa,MAAM,CAAC,CAAC,IAAI;EACvD,MAAM,SAAS,OAAO,OAAO,QAC5B,OAAO,UAAU,OAAO,IACvB,CAAC,KAAK,cACN,OAAO,WAAW,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,KAClC,OAAO,KAAK,UAAU;GAAE;GAAM;EAAS,EAAE,CAC1C,CACF;EACA,OAAO,MAAM,QAAQ,eAAe;GACnC,MAAM;GACN,cAAc,OAAO,WAAW,WAAW,eAAe;IACzD,MAAM,QAAQ,OAAOC,KAAW,aAAa;IAC7C,MAAM,OAAO,OAAO,OAAO,OAC1B,OAAO,QACP,IAAI,YAAY,CAAC,CAAC,OAAO,SAAS,MAAM,KAAK,CAAC,CAC/C;IACA,MAAM,QAAQ,MAAM,UAAU,SAAS,UACtC,gBAAgB,MAAM,MAAM,IAAI,CACjC;IACA,OAAO,OAAO,OAAO,WAAW,OAAOC,OAAa,CAAC,CAAC,KACrD,OAAO,KAAK,UAAU,MAAM,QAAQ,CACrC;GACD,CAAC;EACF,CAAC;CACF,CAAC;AACF,CAAC"}
@@ -1,26 +1,12 @@
1
+ import { ClockTolerance, Jwt } from "../../internal/auth/config.js";
2
+ import { Schema } from "effect";
1
3
  import { Graft, Plugin } from "@graftland/graft";
2
- import { Duration, Schema } from "effect";
3
- export declare const ClockTolerance: Schema.DurationFromString;
4
- export declare const Config: Schema.Struct<{
5
- readonly issuer: Schema.NonEmptyString;
6
- readonly audience: Schema.NonEmptyArray<Schema.NonEmptyString>;
7
- readonly algorithms: Schema.NonEmptyArray<Schema.Literals<readonly ["RS256", "RS384", "RS512", "PS256", "PS384", "PS512", "ES256", "ES384", "ES512", "EdDSA"]>>;
8
- readonly identityClaim: Schema.withDecodingDefaultKey<Schema.NonEmptyString, never>;
9
- readonly clockTolerance: Schema.withDecodingDefaultKey<Schema.DurationFromString, never>;
10
- readonly keys: Schema.Union<readonly [Schema.Struct<{
11
- readonly jwksUrl: Schema.String;
12
- readonly publicKey: Schema.optionalKey<Schema.Never>;
13
- }>, Schema.Struct<{
14
- readonly publicKey: Schema.String;
15
- readonly jwksUrl: Schema.optionalKey<Schema.Never>;
16
- }>]>;
17
- }>;
18
4
  declare const _default: Plugin.Definition<{
19
5
  readonly issuer: string;
20
6
  readonly audience: readonly [string, ...string[]];
21
7
  readonly algorithms: readonly ["ES256" | "ES384" | "ES512" | "EdDSA" | "PS256" | "PS384" | "PS512" | "RS256" | "RS384" | "RS512", ...("ES256" | "ES384" | "ES512" | "EdDSA" | "PS256" | "PS384" | "PS512" | "RS256" | "RS384" | "RS512")[]];
22
8
  readonly identityClaim: string;
23
- readonly clockTolerance: Duration.Duration;
9
+ readonly clockTolerance: import("effect/Duration").Duration;
24
10
  readonly keys: {
25
11
  readonly jwksUrl: string;
26
12
  readonly publicKey?: never;
@@ -42,5 +28,5 @@ declare const _default: Plugin.Definition<{
42
28
  readonly jwksUrl?: never;
43
29
  };
44
30
  }, import("effect/jose/JoseError").JoseError | import("effect/PlatformError").PlatformError | Schema.SchemaError | Graft.ServiceConflict>;
45
- export { _default as default };
31
+ export { ClockTolerance, Jwt as Config, _default as default };
46
32
  //# sourceMappingURL=jwt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jwt.d.ts","names":[],"sources":["../../../src/runner/auth/jwt.ts"],"mappings":";;qBAmBa,gBAAc,OAAA;qBAOd,QAAM,OAAA"}
1
+ {"version":3,"file":"jwt.d.ts","names":[],"sources":["../../../src/runner/auth/jwt.ts"],"mappings":""}