@graftland/plugin-remote 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +76 -2
- package/README.zh-CN.md +71 -0
- package/README.zh-TW.md +71 -0
- package/dist/Auth-BElTC9_X.js +6 -0
- package/dist/Auth.d.ts +49 -0
- package/dist/Auth.d.ts.map +1 -0
- package/dist/Auth.js +8 -0
- package/dist/Auth.js.map +1 -0
- package/dist/Bootstrap-MCwivGN1.js +9 -0
- package/dist/ConfigDirectory-BCC6q2R4.js +5 -0
- package/dist/Contract-CcpSIJm4.js +121 -0
- package/dist/Contract.d.ts +71 -0
- package/dist/Contract.d.ts.map +1 -0
- package/dist/Contract.js +1 -0
- package/dist/Contract.js.map +1 -0
- package/dist/Errors-oPsTLY7l.js +45 -0
- package/dist/Errors.d.ts +67 -0
- package/dist/Errors.d.ts.map +1 -0
- package/dist/Errors.js +47 -0
- package/dist/Errors.js.map +1 -0
- package/dist/FailureGroup-BcH0XOBi.js +53 -0
- package/dist/Framing-zaYdOJnT.js +61 -0
- package/dist/Graft-BsYq3F-J.js +985 -0
- package/dist/Instance.d.ts +7 -0
- package/dist/Instance.d.ts.map +1 -0
- package/dist/Instance.js +14 -0
- package/dist/Instance.js.map +1 -0
- package/dist/Packages-B1TPk8pa.js +111 -0
- package/dist/Peer-IJgFK6mD.js +342 -0
- package/dist/ProcessObservation-DEGrEMfP.js +38 -0
- package/dist/ServeLifecycle-CJM0gG5B.js +24 -0
- package/dist/Testing.d.ts +26 -0
- package/dist/Testing.d.ts.map +1 -0
- package/dist/Testing.js +69 -0
- package/dist/Testing.js.map +1 -0
- package/dist/Transport-DULzpsgR.js +6 -0
- package/dist/Transport.d.ts +39 -0
- package/dist/Transport.d.ts.map +1 -0
- package/dist/Transport.js +8 -0
- package/dist/Transport.js.map +1 -0
- package/dist/WatchdogProtocol-BZmVxrBP.js +17 -0
- package/dist/_virtual/_rolldown/runtime.js +12 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +28275 -0
- package/dist/bin.js.map +1 -0
- package/dist/childRuntime-DSqtFN9o.js +188 -0
- package/dist/cleanup-BPWr-5U9.js +13 -0
- package/dist/command-9zrHdbwT.js +7 -0
- package/dist/connectionEnded-DUgcobEd.js +9 -0
- package/dist/directTransport-DrexuPSm.js +5 -0
- package/dist/entry-SYsx9VNb.js +708 -0
- package/dist/host/auth/bearer.d.ts +5 -0
- package/dist/host/auth/bearer.d.ts.map +1 -0
- package/dist/host/auth/bearer.js +4 -0
- package/dist/host/auth/bearer.js.map +1 -0
- package/dist/host/auth/jwt.d.ts +5 -0
- package/dist/host/auth/jwt.d.ts.map +1 -0
- package/dist/host/auth/jwt.js +4 -0
- package/dist/host/auth/jwt.js.map +1 -0
- package/dist/host/auth/mtls.d.ts +8 -0
- package/dist/host/auth/mtls.d.ts.map +1 -0
- package/dist/host/auth/mtls.js +34 -0
- package/dist/host/auth/mtls.js.map +1 -0
- package/dist/host/auth/none.d.ts +3 -0
- package/dist/host/auth/none.d.ts.map +1 -0
- package/dist/host/auth/none.js +13 -0
- package/dist/host/auth/none.js.map +1 -0
- package/dist/host/command.d.ts +22 -0
- package/dist/host/command.d.ts.map +1 -0
- package/dist/host/command.js +61 -0
- package/dist/host/command.js.map +1 -0
- package/dist/host/local.d.ts +4 -0
- package/dist/host/local.d.ts.map +1 -0
- package/dist/host/local.js +52 -0
- package/dist/host/local.js.map +1 -0
- package/dist/host/unix.d.ts +11 -0
- package/dist/host/unix.d.ts.map +1 -0
- package/dist/host/unix.js +39 -0
- package/dist/host/unix.js.map +1 -0
- package/dist/host/websocket.d.ts +13 -0
- package/dist/host/websocket.d.ts.map +1 -0
- package/dist/host/websocket.js +36 -0
- package/dist/host/websocket.js.map +1 -0
- package/dist/host/worker.d.ts +4 -0
- package/dist/host/worker.d.ts.map +1 -0
- package/dist/host/worker.js +52 -0
- package/dist/host/worker.js.map +1 -0
- package/dist/importer-D7zSgqxq.js +347 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +86 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/Certificates.js +182 -0
- package/dist/internal/Certificates.js.map +1 -0
- package/dist/internal/FailureGroup.js +55 -0
- package/dist/internal/FailureGroup.js.map +1 -0
- package/dist/internal/Limits.d.ts +1 -0
- package/dist/internal/Limits.js +17 -0
- package/dist/internal/Limits.js.map +1 -0
- package/dist/internal/Peer.js +6 -0
- package/dist/internal/Peer.js.map +1 -0
- package/dist/internal/ServeLifecycle.js +26 -0
- package/dist/internal/ServeLifecycle.js.map +1 -0
- package/dist/internal/Supervisor.js +7 -0
- package/dist/internal/Supervisor.js.map +1 -0
- package/dist/internal/assembly.d.ts +5 -0
- package/dist/internal/assembly.js +138 -0
- package/dist/internal/assembly.js.map +1 -0
- package/dist/internal/auth/mtls.js +23 -0
- package/dist/internal/auth/mtls.js.map +1 -0
- package/dist/internal/auth/token.js +19 -0
- package/dist/internal/auth/token.js.map +1 -0
- package/dist/internal/auth/tokenCredentials.d.ts +8 -0
- package/dist/internal/auth/tokenCredentials.d.ts.map +1 -0
- package/dist/internal/auth/tokenCredentials.js +33 -0
- package/dist/internal/auth/tokenCredentials.js.map +1 -0
- package/dist/internal/child.js +125 -0
- package/dist/internal/child.js.map +1 -0
- package/dist/internal/childErrors.d.ts +33 -0
- package/dist/internal/childErrors.d.ts.map +1 -0
- package/dist/internal/childErrors.js +29 -0
- package/dist/internal/childErrors.js.map +1 -0
- package/dist/internal/childRuntime.js +59 -0
- package/dist/internal/childRuntime.js.map +1 -0
- package/dist/internal/cleanup.js +15 -0
- package/dist/internal/cleanup.js.map +1 -0
- package/dist/internal/config.js +6 -0
- package/dist/internal/config.js.map +1 -0
- package/dist/internal/control.js +42 -0
- package/dist/internal/control.js.map +1 -0
- package/dist/internal/credentials.d.ts +44 -0
- package/dist/internal/credentials.d.ts.map +1 -0
- package/dist/internal/credentials.js +54 -0
- package/dist/internal/credentials.js.map +1 -0
- package/dist/internal/directTransport.d.ts +3 -0
- package/dist/internal/directTransport.js +7 -0
- package/dist/internal/directTransport.js.map +1 -0
- package/dist/internal/entry.d.ts +9 -0
- package/dist/internal/entry.d.ts.map +1 -0
- package/dist/internal/entry.js +144 -0
- package/dist/internal/entry.js.map +1 -0
- package/dist/internal/entryConfig.d.ts +202 -0
- package/dist/internal/entryConfig.d.ts.map +1 -0
- package/dist/internal/entryConfig.js +176 -0
- package/dist/internal/entryConfig.js.map +1 -0
- package/dist/internal/execution.d.ts +5 -0
- package/dist/internal/execution.js +43 -0
- package/dist/internal/execution.js.map +1 -0
- package/dist/internal/follow.js +11 -0
- package/dist/internal/follow.js.map +1 -0
- package/dist/internal/forkTree.js +7 -0
- package/dist/internal/forkTree.js.map +1 -0
- package/dist/internal/host/local.js +28 -0
- package/dist/internal/host/local.js.map +1 -0
- package/dist/internal/host/runner.js +100 -0
- package/dist/internal/host/runner.js.map +1 -0
- package/dist/internal/host.js +71 -0
- package/dist/internal/host.js.map +1 -0
- package/dist/internal/importer.js +18 -0
- package/dist/internal/importer.js.map +1 -0
- package/dist/internal/listenerStartup.js +17 -0
- package/dist/internal/listenerStartup.js.map +1 -0
- package/dist/internal/loadModule.js +20 -0
- package/dist/internal/loadModule.js.map +1 -0
- package/dist/internal/platform.js +9 -0
- package/dist/internal/platform.js.map +1 -0
- package/dist/internal/port.d.ts +13 -0
- package/dist/internal/port.d.ts.map +1 -0
- package/dist/internal/port.js +275 -0
- package/dist/internal/port.js.map +1 -0
- package/dist/internal/release.js +25 -0
- package/dist/internal/release.js.map +1 -0
- package/dist/internal/runner/Bootstrap.js +11 -0
- package/dist/internal/runner/Bootstrap.js.map +1 -0
- package/dist/internal/runner/Connection.d.ts +11 -0
- package/dist/internal/runner/Connection.js +56 -0
- package/dist/internal/runner/Connection.js.map +1 -0
- package/dist/internal/runner/Execution.js +115 -0
- package/dist/internal/runner/Execution.js.map +1 -0
- package/dist/internal/runner/Framing.d.ts +11 -0
- package/dist/internal/runner/Framing.d.ts.map +1 -0
- package/dist/internal/runner/Framing.js +63 -0
- package/dist/internal/runner/Framing.js.map +1 -0
- package/dist/internal/runner/Local.js +46 -0
- package/dist/internal/runner/Local.js.map +1 -0
- package/dist/internal/runner/Lock.js +25 -0
- package/dist/internal/runner/Lock.js.map +1 -0
- package/dist/internal/runner/Multiplex.d.ts +5 -0
- package/dist/internal/runner/Multiplex.js +49 -0
- package/dist/internal/runner/Multiplex.js.map +1 -0
- package/dist/internal/runner/Packages.d.ts +3 -0
- package/dist/internal/runner/Packages.js +108 -0
- package/dist/internal/runner/Packages.js.map +1 -0
- package/dist/internal/runner/ProcessObservation.js +40 -0
- package/dist/internal/runner/ProcessObservation.js.map +1 -0
- package/dist/internal/runner/Processes.js +83 -0
- package/dist/internal/runner/Processes.js.map +1 -0
- package/dist/internal/runner/Retention.js +13 -0
- package/dist/internal/runner/Retention.js.map +1 -0
- package/dist/internal/runner/Store.js +78 -0
- package/dist/internal/runner/Store.js.map +1 -0
- package/dist/internal/runner/Supervisor.js +375 -0
- package/dist/internal/runner/Supervisor.js.map +1 -0
- package/dist/internal/runner/Watchdog.js +47 -0
- package/dist/internal/runner/Watchdog.js.map +1 -0
- package/dist/internal/runner/WatchdogProtocol.js +19 -0
- package/dist/internal/runner/WatchdogProtocol.js.map +1 -0
- package/dist/internal/runner/Wire.d.ts +5 -0
- package/dist/internal/runner/Wire.js +64 -0
- package/dist/internal/runner/Wire.js.map +1 -0
- package/dist/internal/runner/accept.js +57 -0
- package/dist/internal/runner/accept.js.map +1 -0
- package/dist/internal/runner/command.js +9 -0
- package/dist/internal/runner/command.js.map +1 -0
- package/dist/internal/runner/connectionEnded.js +11 -0
- package/dist/internal/runner/connectionEnded.js.map +1 -0
- package/dist/internal/runner/model.d.ts +17 -0
- package/dist/internal/runner/model.d.ts.map +1 -0
- package/dist/internal/runner/model.js +231 -0
- package/dist/internal/runner/model.js.map +1 -0
- package/dist/internal/serve.js +60 -0
- package/dist/internal/serve.js.map +1 -0
- package/dist/internal/services.d.ts +18 -0
- package/dist/internal/services.d.ts.map +1 -0
- package/dist/internal/services.js +22 -0
- package/dist/internal/services.js.map +1 -0
- package/dist/internal/socketChannel.js +24 -0
- package/dist/internal/socketChannel.js.map +1 -0
- package/dist/internal/stdioChannel.js +23 -0
- package/dist/internal/stdioChannel.js.map +1 -0
- package/dist/internal/supervisorPlugin.js +1 -0
- package/dist/internal/supervisorPlugin.js.map +1 -0
- package/dist/internal/transportOptions.d.ts +18 -0
- package/dist/internal/transportOptions.d.ts.map +1 -0
- package/dist/internal/watchdogMain.d.ts +1 -0
- package/dist/internal/watchdogMain.js +55 -0
- package/dist/internal/watchdogMain.js.map +1 -0
- package/dist/internal/websocket.js +46 -0
- package/dist/internal/websocket.js.map +1 -0
- package/dist/internal/websocketServer.js +61 -0
- package/dist/internal/websocketServer.js.map +1 -0
- package/dist/internal/workerBootstrap.js +9 -0
- package/dist/internal/workerBootstrap.js.map +1 -0
- package/dist/internal/workerChannel.js +24 -0
- package/dist/internal/workerChannel.js.map +1 -0
- package/dist/internal/workerMain.d.ts +1 -0
- package/dist/internal/workerMain.js +18 -0
- package/dist/internal/workerMain.js.map +1 -0
- package/dist/port-Blbh8tms.js +285 -0
- package/dist/release-BY4Mlluy.js +23 -0
- package/dist/rolldown-runtime-DYf_mQCB.js +34 -0
- package/dist/runner/auth/bearer.d.ts +7 -0
- package/dist/runner/auth/bearer.d.ts.map +1 -0
- package/dist/runner/auth/bearer.js +42 -0
- package/dist/runner/auth/bearer.js.map +1 -0
- package/dist/runner/auth/jwt.d.ts +19 -0
- package/dist/runner/auth/jwt.d.ts.map +1 -0
- package/dist/runner/auth/jwt.js +65 -0
- package/dist/runner/auth/jwt.js.map +1 -0
- package/dist/runner/auth/mtls.d.ts +11 -0
- package/dist/runner/auth/mtls.d.ts.map +1 -0
- package/dist/runner/auth/mtls.js +48 -0
- package/dist/runner/auth/mtls.js.map +1 -0
- package/dist/runner/auth/none.d.ts +3 -0
- package/dist/runner/auth/none.d.ts.map +1 -0
- package/dist/runner/auth/none.js +13 -0
- package/dist/runner/auth/none.js.map +1 -0
- package/dist/runner/index.d.ts +3 -0
- package/dist/runner/index.d.ts.map +1 -0
- package/dist/runner/index.js +71 -0
- package/dist/runner/index.js.map +1 -0
- package/dist/runner/stdio.d.ts +7 -0
- package/dist/runner/stdio.d.ts.map +1 -0
- package/dist/runner/stdio.js +39 -0
- package/dist/runner/stdio.js.map +1 -0
- package/dist/runner/unix.d.ts +7 -0
- package/dist/runner/unix.d.ts.map +1 -0
- package/dist/runner/unix.js +42 -0
- package/dist/runner/unix.js.map +1 -0
- package/dist/runner/websocket.d.ts +28 -0
- package/dist/runner/websocket.d.ts.map +1 -0
- package/dist/runner/websocket.js +77 -0
- package/dist/runner/websocket.js.map +1 -0
- package/dist/socketChannel-KmtzF-9G.js +3658 -0
- package/dist/supervisorPlugin-Inb1S5IV.js +737 -0
- package/dist/token-v5ne2I0-.js +17 -0
- package/dist/tokenCredentials-WUJm2AKm.js +31 -0
- package/dist/websocketServer-MXcCJx0v.js +58 -0
- package/dist/workerChannel-P82YdNjh.js +27 -0
- package/package.json +69 -3
- package/src/Auth.ts +62 -0
- package/src/Contract.ts +100 -0
- package/src/Errors.ts +82 -0
- package/src/Instance.ts +12 -0
- package/src/Testing.ts +135 -0
- package/src/Transport.ts +52 -0
- package/src/bin.ts +145 -0
- package/src/host/auth/bearer.ts +10 -0
- package/src/host/auth/jwt.ts +10 -0
- package/src/host/auth/mtls.ts +48 -0
- package/src/host/auth/none.ts +13 -0
- package/src/host/command.ts +131 -0
- package/src/host/local.ts +41 -0
- package/src/host/unix.ts +65 -0
- package/src/host/websocket.ts +66 -0
- package/src/host/worker.ts +90 -0
- package/src/index.ts +115 -0
- package/src/internal/Certificates.ts +330 -0
- package/src/internal/FailureGroup.ts +176 -0
- package/src/internal/Limits.ts +12 -0
- package/src/internal/Peer.ts +4 -0
- package/src/internal/ServeLifecycle.ts +53 -0
- package/src/internal/Supervisor.ts +14 -0
- package/src/internal/assembly.ts +337 -0
- package/src/internal/auth/mtls.ts +40 -0
- package/src/internal/auth/token.ts +26 -0
- package/src/internal/auth/tokenCredentials.ts +65 -0
- package/src/internal/child.ts +323 -0
- package/src/internal/childErrors.ts +44 -0
- package/src/internal/childRuntime.ts +111 -0
- package/src/internal/cleanup.ts +34 -0
- package/src/internal/config.ts +8 -0
- package/src/internal/control.ts +49 -0
- package/src/internal/credentials.ts +112 -0
- package/src/internal/directTransport.ts +38 -0
- package/src/internal/entry.ts +288 -0
- package/src/internal/entryConfig.ts +190 -0
- package/src/internal/execution.ts +121 -0
- package/src/internal/follow.ts +17 -0
- package/src/internal/forkTree.ts +13 -0
- package/src/internal/host/local.ts +53 -0
- package/src/internal/host/runner.ts +187 -0
- package/src/internal/host.ts +209 -0
- package/src/internal/importer.ts +27 -0
- package/src/internal/listenerStartup.ts +55 -0
- package/src/internal/loadModule.ts +23 -0
- package/src/internal/platform.ts +12 -0
- package/src/internal/port.ts +623 -0
- package/src/internal/release.ts +71 -0
- package/src/internal/runner/Bootstrap.ts +9 -0
- package/src/internal/runner/Connection.ts +184 -0
- package/src/internal/runner/Execution.ts +244 -0
- package/src/internal/runner/Framing.ts +122 -0
- package/src/internal/runner/Local.ts +73 -0
- package/src/internal/runner/Lock.ts +29 -0
- package/src/internal/runner/Multiplex.ts +120 -0
- package/src/internal/runner/Packages.ts +178 -0
- package/src/internal/runner/ProcessObservation.ts +63 -0
- package/src/internal/runner/Processes.ts +109 -0
- package/src/internal/runner/Retention.ts +49 -0
- package/src/internal/runner/Store.ts +160 -0
- package/src/internal/runner/Supervisor.ts +901 -0
- package/src/internal/runner/Watchdog.ts +83 -0
- package/src/internal/runner/WatchdogProtocol.ts +12 -0
- package/src/internal/runner/Wire.ts +99 -0
- package/src/internal/runner/accept.ts +103 -0
- package/src/internal/runner/command.ts +15 -0
- package/src/internal/runner/connectionEnded.ts +28 -0
- package/src/internal/runner/model.ts +364 -0
- package/src/internal/serve.ts +117 -0
- package/src/internal/services.ts +74 -0
- package/src/internal/socketChannel.ts +64 -0
- package/src/internal/stdioChannel.ts +25 -0
- package/src/internal/supervisorPlugin.ts +67 -0
- package/src/internal/transportOptions.ts +17 -0
- package/src/internal/watchdogMain.ts +72 -0
- package/src/internal/websocket.ts +81 -0
- package/src/internal/websocketServer.ts +152 -0
- package/src/internal/workerBootstrap.ts +6 -0
- package/src/internal/workerChannel.ts +54 -0
- package/src/internal/workerMain.ts +23 -0
- package/src/runner/auth/bearer.ts +66 -0
- package/src/runner/auth/jwt.ts +114 -0
- package/src/runner/auth/mtls.ts +37 -0
- package/src/runner/auth/none.ts +13 -0
- package/src/runner/index.ts +97 -0
- package/src/runner/stdio.ts +76 -0
- package/src/runner/unix.ts +53 -0
- package/src/runner/websocket.ts +143 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Cause, Effect, Fiber, Option, Sink, Stream } from "effect"
|
|
2
|
+
import type { ChildProcessSpawner } from "effect/process"
|
|
3
|
+
import { ProcessExited, TransportError } from "../../Errors"
|
|
4
|
+
import * as ProcessObservation from "../runner/ProcessObservation"
|
|
5
|
+
|
|
6
|
+
export const observe = Effect.fnUntraced(function* (
|
|
7
|
+
child: ChildProcessSpawner.ChildProcessHandle,
|
|
8
|
+
) {
|
|
9
|
+
const observation = yield* ProcessObservation.observe(child)
|
|
10
|
+
const exited = yield* observation.exited.pipe(
|
|
11
|
+
Effect.mapBoth({
|
|
12
|
+
onFailure: (error) => TransportError.make({ cause: Cause.fail(error) }),
|
|
13
|
+
onSuccess: (status) =>
|
|
14
|
+
ProcessExited.make({
|
|
15
|
+
pid: Option.some(child.pid),
|
|
16
|
+
exitCode: status.code,
|
|
17
|
+
stderr: status.stderr,
|
|
18
|
+
statusCause: status.cause,
|
|
19
|
+
}),
|
|
20
|
+
}),
|
|
21
|
+
Effect.forkScoped,
|
|
22
|
+
)
|
|
23
|
+
return {
|
|
24
|
+
pid: Option.some(child.pid),
|
|
25
|
+
exited: Fiber.join(exited),
|
|
26
|
+
failure: observation.failure.pipe(
|
|
27
|
+
Effect.mapError((error) =>
|
|
28
|
+
TransportError.make({ cause: Cause.fail(error) }),
|
|
29
|
+
),
|
|
30
|
+
),
|
|
31
|
+
channel: {
|
|
32
|
+
input: child.getOutputFd(3).pipe(
|
|
33
|
+
// EOF can precede Node's exit event; prefer complete process diagnostics.
|
|
34
|
+
Stream.concat(
|
|
35
|
+
Stream.fromEffect(
|
|
36
|
+
Fiber.join(exited).pipe(
|
|
37
|
+
Effect.timeoutOption("1 second"),
|
|
38
|
+
Effect.asVoid,
|
|
39
|
+
),
|
|
40
|
+
).pipe(Stream.drain),
|
|
41
|
+
),
|
|
42
|
+
Stream.mapError((error) =>
|
|
43
|
+
TransportError.make({ cause: Cause.fail(error) }),
|
|
44
|
+
),
|
|
45
|
+
),
|
|
46
|
+
output: child.stdin.pipe(
|
|
47
|
+
Sink.mapError((error) =>
|
|
48
|
+
TransportError.make({ cause: Cause.fail(error) }),
|
|
49
|
+
),
|
|
50
|
+
),
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
})
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import * as FailureGroup from "../FailureGroup"
|
|
2
|
+
import {
|
|
3
|
+
Cause,
|
|
4
|
+
Effect,
|
|
5
|
+
Duration,
|
|
6
|
+
Exit,
|
|
7
|
+
Fiber,
|
|
8
|
+
Option,
|
|
9
|
+
Ref,
|
|
10
|
+
Scope,
|
|
11
|
+
} from "effect"
|
|
12
|
+
import { RpcClient } from "effect/rpc"
|
|
13
|
+
import { connectWith as connectCapability } from "../assembly"
|
|
14
|
+
import type { ConfiguredRunner, Connected } from "../runner/Connection"
|
|
15
|
+
import { ProcessExited, TransportError } from "../../Errors"
|
|
16
|
+
import { cleanupCause } from "../cleanup"
|
|
17
|
+
import * as Port from "../port"
|
|
18
|
+
import * as Multiplex from "../runner/Multiplex"
|
|
19
|
+
import * as Packages from "../runner/Packages"
|
|
20
|
+
import * as Wire from "../runner/Wire"
|
|
21
|
+
import { awaitTermination, defaults, childOf } from "../runner/model"
|
|
22
|
+
export const connect = (
|
|
23
|
+
target: ConfiguredRunner,
|
|
24
|
+
contractModule: string,
|
|
25
|
+
options: Port.Options,
|
|
26
|
+
resources: Scope.Scope,
|
|
27
|
+
processScope: Scope.Scope,
|
|
28
|
+
) =>
|
|
29
|
+
Effect.gen(function* () {
|
|
30
|
+
const instance = target.instance
|
|
31
|
+
|
|
32
|
+
const margin = Duration.toMillis(target.margin ?? "5 seconds")
|
|
33
|
+
const channel = yield* connectCapability(target.explicitAuth).pipe(
|
|
34
|
+
Scope.provide(processScope),
|
|
35
|
+
)
|
|
36
|
+
const mux = yield* Multiplex.make(channel).pipe(Scope.provide(resources))
|
|
37
|
+
const control = yield* Port.make(Wire.channel(mux, 0), {
|
|
38
|
+
session: "session-v1",
|
|
39
|
+
serve: {},
|
|
40
|
+
call: { session: Wire.Session },
|
|
41
|
+
}).pipe(Scope.provide(resources))
|
|
42
|
+
const session = yield* RpcClient.make(Wire.Session).pipe(
|
|
43
|
+
Effect.provideService(
|
|
44
|
+
RpcClient.Protocol,
|
|
45
|
+
control.clientProtocol("session"),
|
|
46
|
+
),
|
|
47
|
+
Scope.provide(resources),
|
|
48
|
+
)
|
|
49
|
+
const expectedGeneration = yield* session.HighWater({ instance })
|
|
50
|
+
const record = yield* session.Open({
|
|
51
|
+
instance,
|
|
52
|
+
expectedGeneration,
|
|
53
|
+
requestId: options.session,
|
|
54
|
+
limits: defaults,
|
|
55
|
+
...(target.lease === undefined
|
|
56
|
+
? {}
|
|
57
|
+
: {
|
|
58
|
+
leaseMillis: Duration.toMillis(target.lease),
|
|
59
|
+
}),
|
|
60
|
+
})
|
|
61
|
+
const failures = yield* FailureGroup.make<TransportError>().pipe(
|
|
62
|
+
Scope.provide(resources),
|
|
63
|
+
)
|
|
64
|
+
const finishStarted = yield* Ref.make(false)
|
|
65
|
+
const terminate = yield* Effect.cached(
|
|
66
|
+
Effect.gen(function* () {
|
|
67
|
+
yield* Ref.set(finishStarted, true)
|
|
68
|
+
yield* failures.close
|
|
69
|
+
const result = yield* awaitTermination(
|
|
70
|
+
record.handle,
|
|
71
|
+
session.Dispose(record.handle),
|
|
72
|
+
record.leaseMillis,
|
|
73
|
+
margin,
|
|
74
|
+
)
|
|
75
|
+
const { code, signal, stderr, cause } = result.exit
|
|
76
|
+
yield* Effect.logInfo("Remote execution terminated", {
|
|
77
|
+
code,
|
|
78
|
+
...(signal === null ? {} : { signal }),
|
|
79
|
+
...(stderr === undefined || stderr === "" ? {} : { stderr }),
|
|
80
|
+
...(cause === undefined || cause.reasons.length === 0
|
|
81
|
+
? {}
|
|
82
|
+
: { cause }),
|
|
83
|
+
}).pipe(
|
|
84
|
+
Effect.annotateLogs({
|
|
85
|
+
"remote.instance": record.handle.key.instance,
|
|
86
|
+
"remote.generation": record.handle.generation,
|
|
87
|
+
"remote.termination": result.kind,
|
|
88
|
+
}),
|
|
89
|
+
)
|
|
90
|
+
if (result.cause.reasons.length > 0)
|
|
91
|
+
return yield* Effect.failCause(cleanupCause(result.cause))
|
|
92
|
+
}),
|
|
93
|
+
)
|
|
94
|
+
yield* Scope.addFinalizer(
|
|
95
|
+
processScope,
|
|
96
|
+
Effect.gen(function* () {
|
|
97
|
+
if (!(yield* Ref.get(finishStarted)))
|
|
98
|
+
yield* terminate.pipe(
|
|
99
|
+
Effect.catchCause((cause) => Effect.failCause(cleanupCause(cause))),
|
|
100
|
+
)
|
|
101
|
+
}),
|
|
102
|
+
)
|
|
103
|
+
const renewed = yield* Effect.forever(
|
|
104
|
+
Effect.sleep(record.leaseMillis / 3).pipe(
|
|
105
|
+
Effect.andThen(session.Renew(record.handle)),
|
|
106
|
+
),
|
|
107
|
+
).pipe(Effect.forkIn(resources))
|
|
108
|
+
const code = yield* session.Load({
|
|
109
|
+
handle: record.handle,
|
|
110
|
+
specifier: contractModule,
|
|
111
|
+
digest: target.expect?.digest !== undefined,
|
|
112
|
+
})
|
|
113
|
+
yield* Packages.verify(code, target.expect)
|
|
114
|
+
const loaded = yield* session.Status(record.handle)
|
|
115
|
+
const peer = yield* Port.make(Wire.channel(mux, 1), {
|
|
116
|
+
...options,
|
|
117
|
+
session: record.handle.token,
|
|
118
|
+
limits: record.limits,
|
|
119
|
+
}).pipe(Scope.provide(resources))
|
|
120
|
+
// RPC forwarding cancellation is expected; resource cleanup is collected by Connection's scopes.
|
|
121
|
+
const report = (cause: Cause.Cause<unknown>) =>
|
|
122
|
+
Cause.hasInterruptsOnly(cause)
|
|
123
|
+
? Effect.void
|
|
124
|
+
: failures.failCause(
|
|
125
|
+
Cause.map(cause, (error) =>
|
|
126
|
+
TransportError.make({ cause: Cause.fail(error) }),
|
|
127
|
+
),
|
|
128
|
+
)
|
|
129
|
+
yield* failures.await.pipe(
|
|
130
|
+
Effect.catchCause((cause) =>
|
|
131
|
+
Cause.hasInterruptsOnly(cause)
|
|
132
|
+
? Effect.void
|
|
133
|
+
: peer.fail(TransportError.make({ cause })),
|
|
134
|
+
),
|
|
135
|
+
Effect.forkIn(resources),
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
yield* failures.run(
|
|
139
|
+
Fiber.join(renewed).pipe(
|
|
140
|
+
Effect.catchCause((cause) =>
|
|
141
|
+
Effect.gen(function* () {
|
|
142
|
+
if (Cause.hasInterruptsOnly(cause)) return
|
|
143
|
+
const status = yield* Effect.exit(
|
|
144
|
+
session.Status(record.handle).pipe(Effect.timeout("5 seconds")),
|
|
145
|
+
)
|
|
146
|
+
if (Exit.isSuccess(status) && status.value.phase === "Stopped") {
|
|
147
|
+
const exit = status.value.termination.exit
|
|
148
|
+
yield* report(
|
|
149
|
+
Cause.combine(
|
|
150
|
+
cause,
|
|
151
|
+
Cause.fail(
|
|
152
|
+
ProcessExited.make({
|
|
153
|
+
pid: Option.map(childOf(loaded), (child) => child.pid),
|
|
154
|
+
exitCode: exit.code,
|
|
155
|
+
stderr: exit.stderr ?? "",
|
|
156
|
+
statusCause: exit.cause ?? Cause.empty,
|
|
157
|
+
}),
|
|
158
|
+
),
|
|
159
|
+
),
|
|
160
|
+
)
|
|
161
|
+
} else
|
|
162
|
+
yield* report(
|
|
163
|
+
Exit.isFailure(status)
|
|
164
|
+
? Cause.combine(cause, status.cause)
|
|
165
|
+
: cause,
|
|
166
|
+
)
|
|
167
|
+
}),
|
|
168
|
+
),
|
|
169
|
+
),
|
|
170
|
+
)
|
|
171
|
+
return {
|
|
172
|
+
resources,
|
|
173
|
+
pid: Option.map(childOf(loaded), (child) => child.pid),
|
|
174
|
+
diagnostics: failures.cause,
|
|
175
|
+
terminate: () =>
|
|
176
|
+
Effect.gen(function* () {
|
|
177
|
+
// No renewal may extend a disconnected session while termination waits out its lease.
|
|
178
|
+
yield* Fiber.interrupt(renewed)
|
|
179
|
+
yield* terminate
|
|
180
|
+
}),
|
|
181
|
+
transport: {
|
|
182
|
+
...peer,
|
|
183
|
+
failure: peer.await,
|
|
184
|
+
report,
|
|
185
|
+
},
|
|
186
|
+
} satisfies Connected
|
|
187
|
+
})
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import * as FailureGroup from "./FailureGroup"
|
|
2
|
+
import * as ContractModule from "../Contract"
|
|
3
|
+
import {
|
|
4
|
+
Cause,
|
|
5
|
+
Array,
|
|
6
|
+
Deferred,
|
|
7
|
+
Effect,
|
|
8
|
+
Ref,
|
|
9
|
+
Option,
|
|
10
|
+
Schema,
|
|
11
|
+
Scope,
|
|
12
|
+
Stream,
|
|
13
|
+
} from "effect"
|
|
14
|
+
import { RpcClient, type RpcClientError } from "effect/rpc"
|
|
15
|
+
import { RemoteWithdrawn } from "../Errors"
|
|
16
|
+
import * as Control from "./control"
|
|
17
|
+
import { cleanupCause } from "./cleanup"
|
|
18
|
+
import { Connection } from "./runner/Connection"
|
|
19
|
+
import type { Service } from "./services"
|
|
20
|
+
|
|
21
|
+
type ErrorSchema = Schema.Top & {
|
|
22
|
+
readonly DecodingServices: never
|
|
23
|
+
readonly EncodingServices: never
|
|
24
|
+
}
|
|
25
|
+
type ControlGroup<E extends ErrorSchema> = ContractModule.Contract<
|
|
26
|
+
Schema.Codec<unknown, Schema.Json>,
|
|
27
|
+
E
|
|
28
|
+
>["control"]
|
|
29
|
+
interface Contract<E extends ErrorSchema> {
|
|
30
|
+
readonly control: ControlGroup<E>
|
|
31
|
+
readonly inject: ReadonlyArray<Service>
|
|
32
|
+
readonly decodeCause: (
|
|
33
|
+
input: unknown,
|
|
34
|
+
) => Effect.Effect<
|
|
35
|
+
Cause.Cause<
|
|
36
|
+
E["Type"] | ContractModule.UndeclaredFailure | ContractModule.ChildFailure
|
|
37
|
+
>,
|
|
38
|
+
Schema.SchemaError
|
|
39
|
+
>
|
|
40
|
+
}
|
|
41
|
+
type Client<E extends ErrorSchema> = RpcClient.FromGroup<
|
|
42
|
+
ControlGroup<E>,
|
|
43
|
+
RpcClientError.RpcClientError
|
|
44
|
+
>
|
|
45
|
+
const race = <A, E, R>(
|
|
46
|
+
connection: Connection["Service"],
|
|
47
|
+
effect: Effect.Effect<A, E, R>,
|
|
48
|
+
) => Effect.raceFirst(effect, connection.transport.failure)
|
|
49
|
+
|
|
50
|
+
const forwardEvents = <E extends ErrorSchema>(
|
|
51
|
+
contract: Contract<E>,
|
|
52
|
+
client: Client<E>,
|
|
53
|
+
connection: Connection["Service"],
|
|
54
|
+
) =>
|
|
55
|
+
Effect.gen(function* () {
|
|
56
|
+
const stopped = yield* Deferred.make<void>()
|
|
57
|
+
const remoteFailure = yield* FailureGroup.make<
|
|
58
|
+
| E["Type"]
|
|
59
|
+
| ContractModule.UndeclaredFailure
|
|
60
|
+
| ContractModule.ChildFailure
|
|
61
|
+
| RemoteWithdrawn
|
|
62
|
+
>()
|
|
63
|
+
const events = yield* race(
|
|
64
|
+
connection,
|
|
65
|
+
client.Events().pipe(
|
|
66
|
+
Stream.runForEach((event) => {
|
|
67
|
+
switch (event._tag) {
|
|
68
|
+
case "Stopped":
|
|
69
|
+
return Deferred.succeed(stopped, undefined)
|
|
70
|
+
case "Withdrawing":
|
|
71
|
+
return remoteFailure.fail(RemoteWithdrawn.make({}))
|
|
72
|
+
case "Failed":
|
|
73
|
+
return contract
|
|
74
|
+
.decodeCause(event.cause)
|
|
75
|
+
.pipe(Effect.flatMap((cause) => remoteFailure.failCause(cause)))
|
|
76
|
+
}
|
|
77
|
+
}),
|
|
78
|
+
),
|
|
79
|
+
).pipe(
|
|
80
|
+
Effect.tapCause(connection.transport.report),
|
|
81
|
+
Effect.forkIn(connection.resources),
|
|
82
|
+
)
|
|
83
|
+
return { stopped, remoteFailure, events }
|
|
84
|
+
})
|
|
85
|
+
const forwardLogs = <E extends ErrorSchema>(
|
|
86
|
+
contract: Contract<E>,
|
|
87
|
+
client: Client<E>,
|
|
88
|
+
connection: Connection["Service"],
|
|
89
|
+
) =>
|
|
90
|
+
Effect.gen(function* () {
|
|
91
|
+
const logsEnded = yield* Deferred.make<void>()
|
|
92
|
+
const reportedDrops = yield* Ref.make(0)
|
|
93
|
+
yield* race(
|
|
94
|
+
connection,
|
|
95
|
+
client.Logs().pipe(
|
|
96
|
+
Stream.runForEach((event) =>
|
|
97
|
+
Effect.gen(function* () {
|
|
98
|
+
const previous = yield* Ref.getAndSet(reportedDrops, event.dropped)
|
|
99
|
+
if (event.dropped > previous)
|
|
100
|
+
yield* Effect.logWarning("Remote logs were dropped").pipe(
|
|
101
|
+
Effect.annotateLogs({
|
|
102
|
+
...(Option.isSome(connection.pid)
|
|
103
|
+
? { "remote.pid": connection.pid.value }
|
|
104
|
+
: {}),
|
|
105
|
+
"remote.logs.dropped": event.dropped - previous,
|
|
106
|
+
"remote.logs.droppedTotal": event.dropped,
|
|
107
|
+
}),
|
|
108
|
+
)
|
|
109
|
+
if (event._tag === "LogsEnded") {
|
|
110
|
+
yield* Deferred.succeed(logsEnded, undefined)
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
const entry = event.entry
|
|
114
|
+
const cause = yield* contract.decodeCause(entry.cause)
|
|
115
|
+
yield* Effect.logWithLevel(
|
|
116
|
+
entry.level === "All" || entry.level === "None"
|
|
117
|
+
? "Info"
|
|
118
|
+
: entry.level,
|
|
119
|
+
)(
|
|
120
|
+
...(Array.isArray(entry.message)
|
|
121
|
+
? entry.message
|
|
122
|
+
: [entry.message]),
|
|
123
|
+
cause,
|
|
124
|
+
).pipe(
|
|
125
|
+
Effect.annotateLogs({
|
|
126
|
+
...(Option.isSome(connection.pid)
|
|
127
|
+
? { "remote.pid": connection.pid.value }
|
|
128
|
+
: {}),
|
|
129
|
+
...(connection.threadId === undefined
|
|
130
|
+
? {}
|
|
131
|
+
: { "remote.threadId": connection.threadId }),
|
|
132
|
+
"remote.annotations": entry.annotations,
|
|
133
|
+
}),
|
|
134
|
+
)
|
|
135
|
+
}),
|
|
136
|
+
),
|
|
137
|
+
),
|
|
138
|
+
).pipe(
|
|
139
|
+
Effect.tapCause(connection.transport.report),
|
|
140
|
+
Effect.forkIn(connection.resources),
|
|
141
|
+
)
|
|
142
|
+
return logsEnded
|
|
143
|
+
})
|
|
144
|
+
export const initialize = <E extends ErrorSchema>(contract: Contract<E>) =>
|
|
145
|
+
Effect.gen(function* () {
|
|
146
|
+
const connection = yield* Connection
|
|
147
|
+
const client = yield* RpcClient.make(contract.control).pipe(
|
|
148
|
+
Effect.provideService(
|
|
149
|
+
RpcClient.Protocol,
|
|
150
|
+
connection.transport.clientProtocol(Control.endpoint),
|
|
151
|
+
),
|
|
152
|
+
Scope.provide(connection.resources),
|
|
153
|
+
)
|
|
154
|
+
for (const service of contract.inject)
|
|
155
|
+
yield* service
|
|
156
|
+
.serve(connection.transport)
|
|
157
|
+
.pipe(
|
|
158
|
+
Effect.tapCause(connection.transport.report),
|
|
159
|
+
Effect.forkIn(connection.resources),
|
|
160
|
+
)
|
|
161
|
+
const events = yield* forwardEvents(contract, client, connection)
|
|
162
|
+
const logsEnded = yield* forwardLogs(contract, client, connection)
|
|
163
|
+
return { connection, client, ...events, logsEnded }
|
|
164
|
+
})
|
|
165
|
+
type Active<E extends ErrorSchema> = Effect.Success<
|
|
166
|
+
ReturnType<typeof initialize<E>>
|
|
167
|
+
>
|
|
168
|
+
export const load = <E extends ErrorSchema>(
|
|
169
|
+
active: Active<E>,
|
|
170
|
+
input: Schema.Json,
|
|
171
|
+
) =>
|
|
172
|
+
race(
|
|
173
|
+
active.connection,
|
|
174
|
+
Effect.raceFirst(
|
|
175
|
+
active.client
|
|
176
|
+
.Load({ input })
|
|
177
|
+
.pipe(
|
|
178
|
+
Effect.catchIf(
|
|
179
|
+
(
|
|
180
|
+
cause,
|
|
181
|
+
): cause is Cause.Cause<
|
|
182
|
+
| E["Type"]
|
|
183
|
+
| ContractModule.UndeclaredFailure
|
|
184
|
+
| ContractModule.ChildFailure
|
|
185
|
+
> => Cause.isCause(cause),
|
|
186
|
+
Effect.failCause,
|
|
187
|
+
),
|
|
188
|
+
),
|
|
189
|
+
active.remoteFailure.await,
|
|
190
|
+
),
|
|
191
|
+
)
|
|
192
|
+
export const dispose = <E extends ErrorSchema>(active: Active<E>) =>
|
|
193
|
+
Effect.gen(function* () {
|
|
194
|
+
const result = yield* race(
|
|
195
|
+
active.connection,
|
|
196
|
+
active.client
|
|
197
|
+
.Dispose()
|
|
198
|
+
.pipe(Effect.catchIf(Cause.isCause, Effect.succeed)),
|
|
199
|
+
)
|
|
200
|
+
const cause = Cause.isCause(result) ? result : Cause.empty
|
|
201
|
+
// A remote cleanup failure still permits the bounded event and log tail to drain.
|
|
202
|
+
yield* race(
|
|
203
|
+
active.connection,
|
|
204
|
+
Deferred.await(active.stopped).pipe(
|
|
205
|
+
Effect.andThen(Deferred.await(active.logsEnded)),
|
|
206
|
+
),
|
|
207
|
+
).pipe(Effect.onError(() => Effect.failCause(cleanupCause(cause))))
|
|
208
|
+
return cause
|
|
209
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Effect, Path, String } from "effect"
|
|
2
|
+
import { SecureRandom } from "effect/crypto"
|
|
3
|
+
import { registerHooks } from "node:module"
|
|
4
|
+
|
|
5
|
+
/** Bare names resolve from the application; imported dependencies keep their own parent URLs. */
|
|
6
|
+
export const make = Effect.fnUntraced(function* (directory: string) {
|
|
7
|
+
const path = yield* Path.Path
|
|
8
|
+
const base = yield* path.toFileUrl(path.join(directory, "graft.yml"))
|
|
9
|
+
const random = yield* SecureRandom.SecureRandom
|
|
10
|
+
const id = yield* random.uuidV4()
|
|
11
|
+
const prefix = `graft-remote-${id}:`
|
|
12
|
+
yield* Effect.acquireRelease(
|
|
13
|
+
Effect.sync(() =>
|
|
14
|
+
registerHooks({
|
|
15
|
+
resolve: (specifier, context, next) =>
|
|
16
|
+
String.startsWith(prefix)(specifier)
|
|
17
|
+
? next(String.slice(prefix.length)(specifier), {
|
|
18
|
+
...context,
|
|
19
|
+
parentURL: base.href,
|
|
20
|
+
})
|
|
21
|
+
: next(specifier, context),
|
|
22
|
+
}),
|
|
23
|
+
),
|
|
24
|
+
(hooks) => Effect.sync(() => hooks.deregister()),
|
|
25
|
+
)
|
|
26
|
+
return (specifier: string): Promise<unknown> => import(prefix + specifier)
|
|
27
|
+
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Fork } from "@graftland/graft"
|
|
2
|
+
import { Array, Deferred, Effect, HashSet, Option, Stream } from "effect"
|
|
3
|
+
import type { AuthenticatorApi } from "../Auth"
|
|
4
|
+
import type { Properties } from "../Transport"
|
|
5
|
+
import { CapabilityCombinationError, CapabilityFailed } from "./assembly"
|
|
6
|
+
|
|
7
|
+
export interface Description {
|
|
8
|
+
readonly properties: Properties
|
|
9
|
+
readonly auth: AuthenticatorApi
|
|
10
|
+
}
|
|
11
|
+
export const signals = Effect.all({
|
|
12
|
+
description: Deferred.make<Description>(),
|
|
13
|
+
ready: Deferred.make<void>(),
|
|
14
|
+
})
|
|
15
|
+
/** A startup signal races its assembly's failure; no runtime failure is promoted to the owner. */
|
|
16
|
+
export const wait = <A>(fork: Fork.Fork, signal: Deferred.Deferred<A>) =>
|
|
17
|
+
Deferred.await(signal).pipe(
|
|
18
|
+
Effect.raceFirst(
|
|
19
|
+
fork.state.pipe(
|
|
20
|
+
Stream.runForEach((state) =>
|
|
21
|
+
state._tag === "Failed"
|
|
22
|
+
? Effect.fail(CapabilityFailed.make({ cause: state.cause }))
|
|
23
|
+
: Effect.void,
|
|
24
|
+
),
|
|
25
|
+
Effect.andThen(Effect.never),
|
|
26
|
+
),
|
|
27
|
+
),
|
|
28
|
+
)
|
|
29
|
+
export const validate = (listeners: ReadonlyArray<Description>) => {
|
|
30
|
+
if (
|
|
31
|
+
listeners.length !== 1 &&
|
|
32
|
+
Array.some(listeners, ({ properties }) => properties.protocol === "stdio")
|
|
33
|
+
)
|
|
34
|
+
return Effect.fail(
|
|
35
|
+
CapabilityCombinationError.make({
|
|
36
|
+
detail: "A stdio listener must be the only listener in serve",
|
|
37
|
+
}),
|
|
38
|
+
)
|
|
39
|
+
const issuers = HashSet.fromIterable(
|
|
40
|
+
Array.getSomes(
|
|
41
|
+
Array.map(listeners, ({ auth }) =>
|
|
42
|
+
auth._tag === "Header"
|
|
43
|
+
? Option.fromUndefinedOr(auth.issuer)
|
|
44
|
+
: Option.none(),
|
|
45
|
+
),
|
|
46
|
+
),
|
|
47
|
+
)
|
|
48
|
+
return HashSet.size(issuers) > 1
|
|
49
|
+
? Effect.fail(
|
|
50
|
+
CapabilityCombinationError.make({
|
|
51
|
+
detail: "A runner must use a single authentication issuer",
|
|
52
|
+
}),
|
|
53
|
+
)
|
|
54
|
+
: Effect.void
|
|
55
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Cause, Effect } from "effect"
|
|
2
|
+
import { ModuleImportFailed } from "./childErrors"
|
|
3
|
+
|
|
4
|
+
/** Native imports cannot be cancelled; late rejection still belongs to the importing context. */
|
|
5
|
+
export const loadModule = Effect.fn("Remote.loadModule")(function* (
|
|
6
|
+
module: string,
|
|
7
|
+
) {
|
|
8
|
+
const context = yield* Effect.context<never>()
|
|
9
|
+
return yield* Effect.tryPromise({
|
|
10
|
+
try: (signal) =>
|
|
11
|
+
import(module).catch((cause) => {
|
|
12
|
+
if (signal.aborted)
|
|
13
|
+
Effect.runSyncWith(context)(
|
|
14
|
+
Effect.logError(
|
|
15
|
+
"Module import failed after cancellation",
|
|
16
|
+
Cause.die(cause),
|
|
17
|
+
).pipe(Effect.annotateLogs({ module })),
|
|
18
|
+
)
|
|
19
|
+
throw cause
|
|
20
|
+
}),
|
|
21
|
+
catch: (cause) => ModuleImportFailed.make({ module, cause }),
|
|
22
|
+
})
|
|
23
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NodeServices } from "@effect/platform-node"
|
|
2
|
+
import { Layer } from "effect"
|
|
3
|
+
import { Digest, SecureRandom, Signature } from "effect/crypto"
|
|
4
|
+
import { FetchHttpClient } from "effect/http"
|
|
5
|
+
|
|
6
|
+
export const platform = Layer.mergeAll(
|
|
7
|
+
NodeServices.layer,
|
|
8
|
+
FetchHttpClient.layer,
|
|
9
|
+
Digest.layerWebCrypto,
|
|
10
|
+
SecureRandom.layerWebCrypto,
|
|
11
|
+
Signature.layerWebCrypto.pipe(Layer.provide(SecureRandom.layerWebCrypto)),
|
|
12
|
+
)
|