@graftland/plugin-remote 0.0.0-stage → 0.2.0-beta.2
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,24 @@
|
|
|
1
|
+
import { TransportError } from "../Errors.js";
|
|
2
|
+
import { FrameError, decoder, encode, isCompleteFrame } from "./runner/Framing.js";
|
|
3
|
+
import { Cause, Effect, Exit, Sink, Stream } from "effect";
|
|
4
|
+
import { Socket } from "effect/socket";
|
|
5
|
+
// src/internal/socketChannel.ts
|
|
6
|
+
/** WebSocket boundaries are a wire compatibility detail, not Channel chunk boundaries. */
|
|
7
|
+
const fromSocket = Effect.fnUntraced(function* (socket) {
|
|
8
|
+
const reader = yield* socket.reader;
|
|
9
|
+
const writer = yield* socket.writer;
|
|
10
|
+
return {
|
|
11
|
+
input: Stream.fromEffectRepeat(reader.pull).pipe(Stream.catchTag("SocketError", (error) => error.reason._tag === "SocketCloseError" && error.reason.code === 1e3 ? Stream.empty : Stream.fail(error)), Stream.flattenIterable, Stream.mapEffect((bytes) => {
|
|
12
|
+
if (typeof bytes === "string") return Effect.fail(FrameError.make({ detail: "Runner WebSocket messages must be binary" }));
|
|
13
|
+
if (!isCompleteFrame(bytes)) return Effect.fail(FrameError.make({ detail: "Invalid runner frame header or payload length" }));
|
|
14
|
+
return Effect.succeed(bytes);
|
|
15
|
+
}), Stream.mapError((error) => TransportError.make({ cause: Cause.fail(error) }))),
|
|
16
|
+
output: Sink.suspend(() => {
|
|
17
|
+
const frames = decoder();
|
|
18
|
+
return Sink.forEach((bytes) => Effect.fromResult(frames.decode(bytes)).pipe(Effect.flatMap((values) => Effect.forEach(values, (frame) => encode(frame).pipe(Effect.flatMap(writer.write)), { discard: true })))).pipe(Sink.onExit((exit) => Exit.isSuccess(exit) ? frames.finish.pipe(Effect.andThen(writer.write(new Socket.CloseEvent(1e3)))) : Effect.void), Sink.mapError((error) => TransportError.make({ cause: Cause.fail(error) })));
|
|
19
|
+
})
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
export { fromSocket };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=socketChannel.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TransportError } from "../Errors.js";
|
|
2
|
+
import { Cause, Effect, Stdio, Stream } from "effect";
|
|
3
|
+
import { NodeSink } from "@effect/platform-node";
|
|
4
|
+
import { createWriteStream } from "node:fs";
|
|
5
|
+
// src/internal/stdioChannel.ts
|
|
6
|
+
const bytes = Effect.gen(function* () {
|
|
7
|
+
const stdio = yield* Stdio.Stdio;
|
|
8
|
+
const output = yield* Effect.sync(() => createWriteStream("", {
|
|
9
|
+
fd: 3,
|
|
10
|
+
autoClose: false
|
|
11
|
+
}));
|
|
12
|
+
return {
|
|
13
|
+
input: stdio.stdin.pipe(Stream.mapError((error) => TransportError.make({ cause: Cause.fail(error) }))),
|
|
14
|
+
output: NodeSink.fromWritable({
|
|
15
|
+
evaluate: () => output,
|
|
16
|
+
onError: (cause) => TransportError.make({ cause: Cause.die(cause) }),
|
|
17
|
+
endOnDone: false
|
|
18
|
+
})
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
export { bytes };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=stdioChannel.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as Config, n as default } from "../supervisorPlugin-Inb1S5IV.js";
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Duration } from "effect";
|
|
2
|
+
export interface WebsocketOptions {
|
|
3
|
+
readonly url: string;
|
|
4
|
+
readonly tls?: {
|
|
5
|
+
readonly ca?: string;
|
|
6
|
+
readonly servername?: string;
|
|
7
|
+
};
|
|
8
|
+
readonly openTimeout?: Duration.Input;
|
|
9
|
+
}
|
|
10
|
+
export interface UnixOptions {
|
|
11
|
+
readonly path: string;
|
|
12
|
+
}
|
|
13
|
+
export interface CommandOptions {
|
|
14
|
+
readonly argv: readonly [string, ...string[]];
|
|
15
|
+
readonly cwd?: string;
|
|
16
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=transportOptions.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { n as Notice, t as CommandJson } from "../WatchdogProtocol-BZmVxrBP.js";
|
|
2
|
+
import { Effect, FiberHandle, Ref, Schema, Stream } from "effect";
|
|
3
|
+
import { NodeRuntime, NodeStream } from "@effect/platform-node";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { parentPort } from "node:worker_threads";
|
|
6
|
+
import { Socket } from "node:net";
|
|
7
|
+
// packages/remote/src/internal/watchdogMain.ts
|
|
8
|
+
/** Executable worker: fd 4 and the lease timer remain independent of the plugin thread. */
|
|
9
|
+
const die = Effect.sync(() => process.kill(process.pid, "SIGKILL")).pipe(Effect.andThen(Effect.never));
|
|
10
|
+
const notify = (notice) => Schema.encodeEffect(Notice)(notice).pipe(Effect.flatMap((message) => Effect.sync(() => parentPort?.postMessage(message))));
|
|
11
|
+
const now = Effect.sync(() => performance.now());
|
|
12
|
+
const expire = (deadline) => Effect.gen(function* () {
|
|
13
|
+
const remaining = deadline - (yield* now);
|
|
14
|
+
if (remaining <= 0) return yield* die;
|
|
15
|
+
yield* Effect.sleep(Math.min(remaining, 2147483647));
|
|
16
|
+
return yield* expire(deadline);
|
|
17
|
+
});
|
|
18
|
+
const main = Effect.scoped(Effect.gen(function* () {
|
|
19
|
+
const lease = yield* Ref.make({
|
|
20
|
+
deadline: (yield* now) + 3e4,
|
|
21
|
+
stopped: false
|
|
22
|
+
});
|
|
23
|
+
const timer = yield* FiberHandle.make();
|
|
24
|
+
yield* FiberHandle.run(timer, expire((yield* Ref.get(lease)).deadline));
|
|
25
|
+
const input = yield* Effect.acquireRelease(Effect.sync(() => new Socket({
|
|
26
|
+
fd: 4,
|
|
27
|
+
readable: true,
|
|
28
|
+
writable: false
|
|
29
|
+
})), (socket) => Effect.sync(() => {
|
|
30
|
+
socket.destroy();
|
|
31
|
+
}));
|
|
32
|
+
yield* notify("ready");
|
|
33
|
+
yield* NodeStream.fromReadable({ evaluate: () => input }).pipe(Stream.decodeText(), Stream.splitLines, Stream.mapEffect((line) => Schema.decodeEffect(CommandJson)(line)), Stream.runForEach((command) => Effect.gen(function* () {
|
|
34
|
+
if (command.kind === "start") return yield* notify("start");
|
|
35
|
+
if (command.kind === "stop") {
|
|
36
|
+
yield* Ref.update(lease, (state) => ({
|
|
37
|
+
...state,
|
|
38
|
+
stopped: true
|
|
39
|
+
}));
|
|
40
|
+
return yield* notify("stop");
|
|
41
|
+
}
|
|
42
|
+
const current = yield* Ref.get(lease);
|
|
43
|
+
const time = yield* now;
|
|
44
|
+
if (current.stopped || time >= current.deadline) return yield* die;
|
|
45
|
+
const deadline = time + command.millis;
|
|
46
|
+
yield* Ref.set(lease, {
|
|
47
|
+
deadline,
|
|
48
|
+
stopped: false
|
|
49
|
+
});
|
|
50
|
+
yield* FiberHandle.run(timer, expire(deadline));
|
|
51
|
+
})));
|
|
52
|
+
return yield* die;
|
|
53
|
+
})).pipe(Effect.catchCause((cause) => Effect.logError("Watchdog failed", cause).pipe(Effect.andThen(die))));
|
|
54
|
+
NodeRuntime.runMain(main);
|
|
55
|
+
export {};
|
|
@@ -0,0 +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 { 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)\nconst now = Effect.sync(() => performance.now())\nconst expire = (deadline: number): Effect.Effect<never> =>\n\tEffect.gen(function* () {\n\t\tconst remaining = deadline - (yield* now)\n\t\tif (remaining <= 0) return yield* die\n\t\tyield* Effect.sleep(Math.min(remaining, 2147483647))\n\t\treturn yield* expire(deadline)\n\t})\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((command) =>\n\t\t\t\tEffect.gen(function* () {\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":";;;;;;;;AAUA,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;AACD,MAAM,MAAM,OAAO,WAAW,YAAY,IAAI,CAAC;AAC/C,MAAM,UAAU,aACf,OAAO,IAAI,aAAa;CACvB,MAAM,YAAY,YAAY,OAAO;CACrC,IAAI,aAAa,GAAG,OAAO,OAAO;CAClC,OAAO,OAAO,MAAM,KAAK,IAAI,WAAW,UAAU,CAAC;CACnD,OAAO,OAAO,OAAO,QAAQ;AAC9B,CAAC;AACF,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,YAAY,YAClB,OAAO,IAAI,aAAa;EACvB,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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { maxPayload } from "./runner/Framing.js";
|
|
2
|
+
import { Array, Effect, Layer, Redacted, Schema } from "effect";
|
|
3
|
+
import { Socket } from "effect/socket";
|
|
4
|
+
import WS from "ws";
|
|
5
|
+
// src/internal/websocket.ts
|
|
6
|
+
const protocol = "graft-remote.v1";
|
|
7
|
+
const path = "/graft";
|
|
8
|
+
const payloadLimit = maxPayload + 8;
|
|
9
|
+
const Url = Schema.URLFromString.check(Schema.makeFilter((url) => url.protocol === "wss:" || url.protocol === "ws:", { expected: "a ws:// or wss:// URL" }));
|
|
10
|
+
const constructor = (tls, credentials = {}) => Layer.succeed(Socket.WebSocketConstructor, (url, options) => {
|
|
11
|
+
const settings = typeof options === "object" && !Array.isArray(options) ? options : { protocols: options };
|
|
12
|
+
return new WS(url, settings.protocols, {
|
|
13
|
+
...tls,
|
|
14
|
+
...credentials.certificate === void 0 ? {} : {
|
|
15
|
+
cert: credentials.certificate.cert,
|
|
16
|
+
key: Redacted.value(credentials.certificate.key)
|
|
17
|
+
},
|
|
18
|
+
headers: {
|
|
19
|
+
...settings.headers,
|
|
20
|
+
...credentials.authorization === void 0 ? {} : { authorization: Redacted.value(credentials.authorization) }
|
|
21
|
+
},
|
|
22
|
+
perMessageDeflate: false,
|
|
23
|
+
maxPayload: payloadLimit,
|
|
24
|
+
rejectUnauthorized: true,
|
|
25
|
+
minVersion: "TLSv1.3"
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
const open = Effect.fnUntraced(function* (options, credentials = {}) {
|
|
29
|
+
const url = yield* Schema.decodeEffect(Url)(options.url);
|
|
30
|
+
if (credentials.certificate !== void 0 && url.protocol !== "wss:") yield* Schema.decodeEffect(Url.check(Schema.makeFilter((url) => url.protocol === "wss:", { expected: "wss:// for mutual TLS" })))(options.url);
|
|
31
|
+
const address = url.pathname === "/" ? new URL(path, url).href : url.href;
|
|
32
|
+
const services = yield* Layer.build(constructor(options.tls, credentials));
|
|
33
|
+
return yield* Socket.makeWebSocket(address, {
|
|
34
|
+
protocols: protocol,
|
|
35
|
+
openTimeout: options.openTimeout ?? "10 seconds"
|
|
36
|
+
}).pipe(Effect.provideContext(services));
|
|
37
|
+
});
|
|
38
|
+
const properties = (url) => ({
|
|
39
|
+
protocol: url.protocol === "wss:" ? "wss" : "ws",
|
|
40
|
+
encrypted: url.protocol === "wss:",
|
|
41
|
+
network: true,
|
|
42
|
+
carries: url.protocol === "wss:" ? ["header", "certificate"] : ["header"]
|
|
43
|
+
});
|
|
44
|
+
export { Url, constructor, open, path, payloadLimit, properties, protocol };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=websocket.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { TransportError } from "../Errors.js";
|
|
2
|
+
import { fromSocket } from "./socketChannel.js";
|
|
3
|
+
import { payloadLimit, protocol } from "./websocket.js";
|
|
4
|
+
import { Array, Cause, Deferred, Effect, Option, Redacted, Scope, String } from "effect";
|
|
5
|
+
import { NodeHttpServer, NodeHttpServerRequest } from "@effect/platform-node";
|
|
6
|
+
import { HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
7
|
+
import { TLSSocket } from "node:tls";
|
|
8
|
+
// src/internal/websocketServer.ts
|
|
9
|
+
const rejection = (error) => Effect.logWarning("Remote host authentication failed", { reason: error.reason }, ...error.cause === void 0 ? [] : [error.cause]).pipe(Effect.as(HttpServerResponse.empty({
|
|
10
|
+
status: 401,
|
|
11
|
+
headers: error.challenge === void 0 ? {} : { "www-authenticate": error.challenge }
|
|
12
|
+
})));
|
|
13
|
+
const handshake = Effect.gen(function* () {
|
|
14
|
+
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
15
|
+
const { socket } = NodeHttpServerRequest.toIncomingMessage(request);
|
|
16
|
+
const peer = socket instanceof TLSSocket && socket.authorized ? Option.some(socket.getPeerCertificate()) : Option.none();
|
|
17
|
+
return {
|
|
18
|
+
authorization: Option.map(Option.fromUndefinedOr(request.headers["authorization"]), Redacted.make),
|
|
19
|
+
certificate: Option.map(peer, (certificate) => ({
|
|
20
|
+
der: certificate.raw,
|
|
21
|
+
subjectAltName: Option.fromUndefinedOr(certificate.subjectaltname)
|
|
22
|
+
}))
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
const open = Effect.fnUntraced(function* (createServer, options) {
|
|
26
|
+
const resources = yield* Effect.acquireRelease(Scope.make(), Scope.close);
|
|
27
|
+
const ready = yield* Deferred.make();
|
|
28
|
+
const server = yield* NodeHttpServer.make(createServer, {
|
|
29
|
+
...options,
|
|
30
|
+
disablePreemptiveShutdown: true,
|
|
31
|
+
websocket: {
|
|
32
|
+
perMessageDeflate: false,
|
|
33
|
+
maxPayload: payloadLimit,
|
|
34
|
+
handleProtocols: (protocols) => protocols.has("graft-remote.v1") ? protocol : false
|
|
35
|
+
}
|
|
36
|
+
}).pipe(Scope.provide(resources));
|
|
37
|
+
return {
|
|
38
|
+
address: server.address,
|
|
39
|
+
ready: Deferred.await(ready),
|
|
40
|
+
run: (accept) => server.serve(Effect.gen(function* () {
|
|
41
|
+
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
42
|
+
if (request.url !== "/graft") return HttpServerResponse.empty({ status: 404 });
|
|
43
|
+
if (String.toLowerCase(request.headers["upgrade"] ?? "") !== "websocket" || !Array.some(String.split(request.headers["sec-websocket-protocol"] ?? "", ","), (value) => String.trim(value) === "graft-remote.v1")) return HttpServerResponse.empty({ status: 400 });
|
|
44
|
+
const session = yield* Effect.result(accept);
|
|
45
|
+
if (session._tag === "Failure") return yield* rejection(session.failure);
|
|
46
|
+
yield* request.upgrade.pipe(Effect.flatMap(session.success), Effect.interruptible, Effect.scoped);
|
|
47
|
+
return HttpServerResponse.empty();
|
|
48
|
+
})).pipe(Effect.andThen(Deferred.succeed(ready, void 0)), Effect.andThen(Effect.never))
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
const bind = Effect.fnUntraced(function* (createServer, options) {
|
|
52
|
+
const server = yield* open(createServer, options);
|
|
53
|
+
return {
|
|
54
|
+
address: server.address,
|
|
55
|
+
ready: server.ready,
|
|
56
|
+
serve: (accept) => server.run(handshake.pipe(Effect.flatMap(accept), Effect.map((session) => (socket) => fromSocket(socket).pipe(Effect.flatMap(session))))).pipe(Effect.mapError((error) => TransportError.make({ cause: Cause.fail(error) })))
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
export { bind };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=websocketServer.js.map
|
|
@@ -0,0 +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 { AuthenticationFailed, TransportError } 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) =>\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,\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":";;;;;;;;AAmBA,MAAM,aAAa,UAClB,OAAO,WACN,qCACA,EACC,QAAQ,MAAM,OACf,GACA,GAAI,MAAM,UAAU,KAAA,IAAY,CAAC,IAAI,CAAC,MAAM,KAAK,CAClD,CAAC,CAAC,KACD,OAAO,GACN,mBAAmB,MAAM;CACxB,QAAQ;CACR,SACC,MAAM,cAAc,KAAA,IACjB,CAAC,IACD,EAAE,oBAAoB,MAAM,UAAU;AAC3C,CAAC,CACF,CACD;AAED,MAAM,YAIF,OAAO,IAAI,aAAa;CAC3B,MAAM,UAAU,OAAO,kBAAkB;CACzC,MAAM,EAAE,WAAW,sBAAsB,kBAAkB,OAAO;CAElE,MAAM,OACL,kBAAkB,aAAa,OAAO,aACnC,OAAO,KAAK,OAAO,mBAAmB,CAAC,IACvC,OAAO,KAAK;CAChB,OAAO;EACN,eAAe,OAAO,IACrB,OAAO,gBAAgB,QAAQ,QAAQ,gBAAgB,GACvD,SAAS,IACV;EACA,aAAa,OAAO,IAAI,OAAO,iBAAiB;GAC/C,KAAK,YAAY;GACjB,gBAAgB,OAAO,gBAAgB,YAAY,cAAc;EAClE,EAAE;CACH;AACD,CAAC;AAED,MAAM,OAAO,OAAO,WAAW,WAC9B,cACA,SACC;CAED,MAAM,YAAY,OAAO,OAAO,eAAe,MAAM,KAAK,GAAG,MAAM,KAAK;CACxE,MAAM,QAAQ,OAAO,SAAS,KAAW;CACzC,MAAM,SAAS,OAAO,eAAe,KAAK,cAAc;EACvD,GAAG;EACH,2BAA2B;EAC3B,WAAW;GACV,mBAAmB;GACnB,YAAY;GACZ,kBAAkB,cACjB,UAAU,IAAA,iBAAY,IAAI,WAAW;EACvC;CACD,CAAC,CAAC,CAAC,KAAK,MAAM,QAAQ,SAAS,CAAC;CAChC,OAAO;EACN,SAAS,OAAO;EAChB,OAAO,SAAS,MAAM,KAAK;EAC3B,MACC,WAMA,OACE,MACA,OAAO,IAAI,aAAa;GACvB,MAAM,UAAU,OAAO,kBAAkB;GACzC,IAAI,QAAQ,QAAA,UACX,OAAO,mBAAmB,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerBootstrap.js","names":[],"sources":["../../src/internal/workerBootstrap.ts"],"sourcesContent":["import { Schema } from \"effect\"\n\nexport const Bootstrap = Schema.Struct({\n\tcontractModule: Schema.String,\n\tsession: Schema.String,\n})\n"],"mappings":";;AAEA,MAAa,YAAY,OAAO,OAAO;CACtC,gBAAgB,OAAO;CACvB,SAAS,OAAO;AACjB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TransportError } from "../Errors.js";
|
|
2
|
+
import { Cause, Effect, FiberSet, Queue, Sink, Stream } from "effect";
|
|
3
|
+
// src/internal/workerChannel.ts
|
|
4
|
+
const make = Effect.fnUntraced(function* (endpoint) {
|
|
5
|
+
const input = yield* Queue.unbounded();
|
|
6
|
+
const callbacks = yield* FiberSet.make();
|
|
7
|
+
const run = yield* FiberSet.runtime(callbacks)();
|
|
8
|
+
const receive = (value) => run(value === null ? Queue.end(input) : Queue.offer(input, new Uint8Array(value)));
|
|
9
|
+
yield* Effect.acquireRelease(Effect.sync(() => endpoint.on("message", receive)), () => Effect.sync(() => endpoint.off("message", receive)).pipe(Effect.andThen(Queue.shutdown(input))));
|
|
10
|
+
const send = (bytes) => Effect.try({
|
|
11
|
+
try: () => {
|
|
12
|
+
const buffer = bytes === null ? null : new Uint8Array(bytes).buffer;
|
|
13
|
+
endpoint.postMessage(buffer, buffer === null ? [] : [buffer]);
|
|
14
|
+
},
|
|
15
|
+
catch: (cause) => TransportError.make({ cause: Cause.die(cause) })
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
input: Stream.fromQueue(input),
|
|
19
|
+
output: Sink.forEach((bytes) => send(bytes)).pipe(Sink.ensuring(send(null)))
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
export { make };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=workerChannel.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { r as layer } from "../Graft-BsYq3F-J.js";
|
|
2
|
+
import { n as run, r as platform, t as load } from "../childRuntime-DSqtFN9o.js";
|
|
3
|
+
import { n as Bootstrap, t as make } from "../workerChannel-P82YdNjh.js";
|
|
4
|
+
import { Effect, Layer, Schema } from "effect";
|
|
5
|
+
import { NodeRuntime } from "@effect/platform-node";
|
|
6
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
7
|
+
// packages/remote/src/internal/workerMain.ts
|
|
8
|
+
/** Executable entry for a direct worker; platform services belong to this thread. */
|
|
9
|
+
const main = Effect.scoped(Effect.gen(function* () {
|
|
10
|
+
const port = yield* Effect.fromNullishOr(parentPort);
|
|
11
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => port.close()));
|
|
12
|
+
const bootstrap = yield* Schema.decodeUnknownEffect(Bootstrap)(workerData);
|
|
13
|
+
const channel = yield* make(port);
|
|
14
|
+
const contract = yield* load(bootstrap.contractModule);
|
|
15
|
+
yield* run(contract, channel, bootstrap.session);
|
|
16
|
+
}));
|
|
17
|
+
NodeRuntime.runMain(main.pipe(Effect.provide(layer.pipe(Layer.provide(platform)))));
|
|
18
|
+
export {};
|
|
@@ -0,0 +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"}
|