@graftland/plugin-remote 0.3.3 → 0.4.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/README.md +18 -54
- package/README.zh-CN.md +17 -51
- package/README.zh-TW.md +17 -51
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js.map +1 -1
- package/dist/Config.d.ts +1151 -0
- package/dist/Config.d.ts.map +1 -0
- package/dist/Config.js +183 -0
- package/dist/Config.js.map +1 -0
- package/dist/Contract.d.ts +1 -1
- package/dist/Contract.d.ts.map +1 -1
- package/dist/Contract.js +32 -1
- package/dist/Contract.js.map +1 -1
- package/dist/Instance.d.ts.map +1 -1
- package/dist/Instance.js.map +1 -1
- package/dist/Testing.d.ts +1 -1
- package/dist/Testing.d.ts.map +1 -1
- package/dist/Testing.js.map +1 -1
- package/dist/Transport.d.ts +1 -1
- package/dist/Transport.d.ts.map +1 -1
- package/dist/Transport.js.map +1 -1
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +25 -0
- package/dist/cli.js.map +1 -0
- package/dist/host/auth/bearer.d.ts.map +1 -1
- package/dist/host/auth/bearer.js +4 -2
- package/dist/host/auth/bearer.js.map +1 -1
- package/dist/host/auth/jwt.d.ts.map +1 -1
- package/dist/host/auth/jwt.js +4 -2
- package/dist/host/auth/jwt.js.map +1 -1
- package/dist/host/auth/mtls.d.ts +3 -7
- package/dist/host/auth/mtls.d.ts.map +1 -1
- package/dist/host/auth/mtls.js +13 -14
- package/dist/host/auth/mtls.js.map +1 -1
- package/dist/host/auth/none.d.ts +1 -1
- package/dist/host/auth/none.js +7 -5
- package/dist/host/auth/none.js.map +1 -1
- package/dist/host/command.d.ts +1 -1
- package/dist/host/command.d.ts.map +1 -1
- package/dist/host/command.js +11 -9
- package/dist/host/command.js.map +1 -1
- package/dist/host/local.d.ts.map +1 -1
- package/dist/host/local.js +9 -30
- package/dist/host/local.js.map +1 -1
- package/dist/host/unix.d.ts +1 -1
- package/dist/host/unix.d.ts.map +1 -1
- package/dist/host/unix.js +13 -9
- package/dist/host/unix.js.map +1 -1
- package/dist/host/websocket.d.ts +1 -1
- package/dist/host/websocket.d.ts.map +1 -1
- package/dist/host/websocket.js +11 -8
- package/dist/host/websocket.js.map +1 -1
- package/dist/host/worker.d.ts +1 -1
- package/dist/host/worker.d.ts.map +1 -1
- package/dist/host/worker.js +13 -9
- package/dist/host/worker.js.map +1 -1
- package/dist/index.d.ts +6 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -64
- package/dist/index.js.map +1 -1
- package/dist/internal/Certificates.js.map +1 -1
- package/dist/internal/FailureGroup.js +6 -6
- package/dist/internal/FailureGroup.js.map +1 -1
- package/dist/internal/Peer.js.map +1 -1
- package/dist/internal/{ServeLifecycle.js → RunnerLifecycle.js} +6 -6
- package/dist/internal/RunnerLifecycle.js.map +1 -0
- package/dist/internal/Supervisor.js.map +1 -1
- package/dist/internal/assembly.d.ts +3 -3
- package/dist/internal/assembly.js +8 -8
- package/dist/internal/assembly.js.map +1 -1
- package/dist/internal/auth/config.d.ts +27 -0
- package/dist/internal/auth/config.d.ts.map +1 -0
- package/dist/internal/auth/config.js +29 -0
- package/dist/internal/auth/config.js.map +1 -0
- package/dist/internal/auth/mtls.js.map +1 -1
- package/dist/internal/auth/token.js.map +1 -1
- package/dist/internal/auth/tokenCredentials.d.ts +1 -1
- package/dist/internal/auth/tokenCredentials.d.ts.map +1 -1
- package/dist/internal/auth/tokenCredentials.js +1 -1
- package/dist/internal/auth/tokenCredentials.js.map +1 -1
- package/dist/internal/child.js +3 -3
- package/dist/internal/child.js.map +1 -1
- package/dist/internal/childMain.js +47 -0
- package/dist/internal/childMain.js.map +1 -0
- package/dist/internal/childRuntime.js +8 -8
- package/dist/internal/childRuntime.js.map +1 -1
- package/dist/internal/cleanup.js +3 -3
- package/dist/internal/cleanup.js.map +1 -1
- package/dist/internal/contract.js.map +1 -1
- package/dist/internal/credentials.d.ts +3 -2
- package/dist/internal/credentials.d.ts.map +1 -1
- package/dist/internal/credentials.js +1 -1
- package/dist/internal/credentials.js.map +1 -1
- package/dist/internal/directTransport.js.map +1 -1
- package/dist/internal/entry.d.ts +104 -26
- package/dist/internal/entry.d.ts.map +1 -1
- package/dist/internal/entry.js +22 -9
- package/dist/internal/entry.js.map +1 -1
- package/dist/internal/entryConfig.d.ts +2 -202
- package/dist/internal/entryConfig.js +2 -136
- package/dist/internal/entryConfig.js.map +1 -1
- package/dist/internal/execution.d.ts +4 -4
- package/dist/internal/execution.js +11 -11
- package/dist/internal/execution.js.map +1 -1
- package/dist/internal/follow.js +1 -1
- package/dist/internal/follow.js.map +1 -1
- package/dist/internal/forkTree.js.map +1 -1
- package/dist/internal/host/local.js.map +1 -1
- package/dist/internal/host/runner.js +4 -4
- package/dist/internal/host/runner.js.map +1 -1
- package/dist/internal/host.js +2 -2
- package/dist/internal/host.js.map +1 -1
- package/dist/internal/importer.js +1 -1
- package/dist/internal/importer.js.map +1 -1
- package/dist/internal/listenerStartup.js +1 -1
- package/dist/internal/listenerStartup.js.map +1 -1
- package/dist/internal/loadModule.js.map +1 -1
- package/dist/internal/platform.js +1 -9
- package/dist/internal/port.d.ts +1 -1
- package/dist/internal/port.js +2 -2
- package/dist/internal/port.js.map +1 -1
- package/dist/internal/runner/Bootstrap.js.map +1 -1
- package/dist/internal/runner/Connection.d.ts +3 -2
- package/dist/internal/runner/Connection.js +6 -6
- package/dist/internal/runner/Connection.js.map +1 -1
- package/dist/internal/runner/Execution.js +6 -6
- package/dist/internal/runner/Execution.js.map +1 -1
- package/dist/internal/runner/Local.js +1 -1
- package/dist/internal/runner/Local.js.map +1 -1
- package/dist/internal/runner/Lock.js.map +1 -1
- package/dist/internal/runner/Multiplex.js.map +1 -1
- package/dist/internal/runner/Packages.js.map +1 -1
- package/dist/internal/runner/ProcessObservation.js.map +1 -1
- package/dist/internal/runner/Processes.js.map +1 -1
- package/dist/internal/runner/Retention.js.map +1 -1
- package/dist/internal/runner/Store.js.map +1 -1
- package/dist/internal/runner/Supervisor.js +5 -5
- package/dist/internal/runner/Supervisor.js.map +1 -1
- package/dist/internal/runner/Watchdog.js.map +1 -1
- package/dist/internal/runner/Wire.d.ts +1 -1
- package/dist/internal/runner/Wire.js.map +1 -1
- package/dist/internal/runner/accept.js +2 -2
- package/dist/internal/runner/accept.js.map +1 -1
- package/dist/internal/runner/command.js +1 -1
- package/dist/internal/runner/command.js.map +1 -1
- package/dist/internal/runner/connectionEnded.js +1 -1
- package/dist/internal/runner/connectionEnded.js.map +1 -1
- package/dist/internal/runner/model.d.ts.map +1 -1
- package/dist/internal/runner/model.js.map +1 -1
- package/dist/internal/services.d.ts.map +1 -1
- package/dist/internal/services.js +1 -1
- package/dist/internal/services.js.map +1 -1
- package/dist/internal/socketChannel.js.map +1 -1
- package/dist/internal/stdioChannel.js.map +1 -1
- package/dist/internal/supervisorPlugin.js +48 -1
- package/dist/internal/supervisorPlugin.js.map +1 -1
- package/dist/internal/transportOptions.d.ts.map +1 -1
- package/dist/internal/watchdogMain.js +5 -3
- package/dist/internal/watchdogMain.js.map +1 -1
- package/dist/internal/websocket.js.map +1 -1
- package/dist/internal/websocketServer.js +1 -1
- package/dist/internal/websocketServer.js.map +1 -1
- package/dist/internal/workerChannel.js.map +1 -1
- package/dist/internal/workerMain.js +13 -6
- package/dist/internal/workerMain.js.map +1 -1
- package/dist/runner/auth/bearer.d.ts +3 -5
- package/dist/runner/auth/bearer.d.ts.map +1 -1
- package/dist/runner/auth/bearer.js +13 -11
- package/dist/runner/auth/bearer.js.map +1 -1
- package/dist/runner/auth/jwt.d.ts +4 -18
- package/dist/runner/auth/jwt.d.ts.map +1 -1
- package/dist/runner/auth/jwt.js +16 -28
- package/dist/runner/auth/jwt.js.map +1 -1
- package/dist/runner/auth/mtls.d.ts +3 -6
- package/dist/runner/auth/mtls.d.ts.map +1 -1
- package/dist/runner/auth/mtls.js +13 -29
- package/dist/runner/auth/mtls.js.map +1 -1
- package/dist/runner/auth/none.d.ts +1 -1
- package/dist/runner/auth/none.js +7 -5
- package/dist/runner/auth/none.js.map +1 -1
- package/dist/runner/index.d.ts +3 -308
- package/dist/runner/index.d.ts.map +1 -1
- package/dist/runner/index.js +62 -30
- package/dist/runner/index.js.map +1 -1
- package/dist/runner/stdio.d.ts +1 -1
- package/dist/runner/stdio.d.ts.map +1 -1
- package/dist/runner/stdio.js +11 -9
- package/dist/runner/stdio.js.map +1 -1
- package/dist/runner/unix.d.ts +1 -1
- package/dist/runner/unix.d.ts.map +1 -1
- package/dist/runner/unix.js +10 -8
- package/dist/runner/unix.js.map +1 -1
- package/dist/runner/websocket.d.ts +1 -1
- package/dist/runner/websocket.d.ts.map +1 -1
- package/dist/runner/websocket.js +12 -10
- package/dist/runner/websocket.js.map +1 -1
- package/package.json +14 -12
- package/schema.json +2269 -0
- package/src/Auth.ts +8 -2
- package/src/Config.ts +196 -0
- package/src/Contract.ts +12 -3
- package/src/Instance.ts +1 -0
- package/src/Testing.ts +6 -4
- package/src/Transport.ts +12 -3
- package/src/cli.ts +60 -0
- package/src/host/auth/bearer.ts +1 -0
- package/src/host/auth/jwt.ts +1 -0
- package/src/host/auth/mtls.ts +7 -12
- package/src/host/auth/none.ts +3 -1
- package/src/host/command.ts +8 -5
- package/src/host/local.ts +4 -2
- package/src/host/unix.ts +11 -7
- package/src/host/websocket.ts +10 -7
- package/src/host/worker.ts +8 -5
- package/src/index.ts +36 -23
- package/src/internal/Certificates.ts +1 -0
- package/src/internal/FailureGroup.ts +5 -3
- package/src/internal/Peer.ts +1 -0
- package/src/internal/{ServeLifecycle.ts → RunnerLifecycle.ts} +7 -5
- package/src/internal/Supervisor.ts +5 -4
- package/src/internal/assembly.ts +11 -9
- package/src/internal/auth/config.ts +44 -0
- package/src/internal/auth/mtls.ts +1 -0
- package/src/internal/auth/token.ts +1 -0
- package/src/internal/auth/tokenCredentials.ts +4 -2
- package/src/internal/child.ts +8 -6
- package/src/{bin.ts → internal/childMain.ts} +16 -61
- package/src/internal/childRuntime.ts +12 -10
- package/src/internal/cleanup.ts +3 -2
- package/src/internal/contract.ts +1 -0
- package/src/internal/credentials.ts +3 -1
- package/src/internal/directTransport.ts +9 -2
- package/src/internal/entry.ts +53 -16
- package/src/internal/entryConfig.ts +10 -132
- package/src/internal/execution.ts +17 -15
- package/src/internal/follow.ts +2 -1
- package/src/internal/forkTree.ts +2 -1
- package/src/internal/host/local.ts +1 -0
- package/src/internal/host/runner.ts +7 -5
- package/src/internal/host.ts +9 -8
- package/src/internal/importer.ts +3 -2
- package/src/internal/listenerStartup.ts +4 -2
- package/src/internal/loadModule.ts +1 -0
- package/src/internal/platform.ts +1 -12
- package/src/internal/port.ts +11 -6
- package/src/internal/runner/Bootstrap.ts +1 -0
- package/src/internal/runner/Connection.ts +13 -11
- package/src/internal/runner/Execution.ts +14 -13
- package/src/internal/runner/Local.ts +3 -2
- package/src/internal/runner/Lock.ts +1 -0
- package/src/internal/runner/Multiplex.ts +2 -1
- package/src/internal/runner/Packages.ts +7 -5
- package/src/internal/runner/ProcessObservation.ts +2 -1
- package/src/internal/runner/Processes.ts +3 -1
- package/src/internal/runner/Retention.ts +1 -0
- package/src/internal/runner/Store.ts +3 -2
- package/src/internal/runner/Supervisor.ts +22 -20
- package/src/internal/runner/Watchdog.ts +3 -1
- package/src/internal/runner/Wire.ts +13 -12
- package/src/internal/runner/accept.ts +6 -5
- package/src/internal/runner/command.ts +3 -2
- package/src/internal/runner/connectionEnded.ts +2 -1
- package/src/internal/runner/model.ts +5 -3
- package/src/internal/services.ts +9 -2
- package/src/internal/socketChannel.ts +2 -1
- package/src/internal/stdioChannel.ts +4 -2
- package/src/internal/supervisorPlugin.ts +10 -8
- package/src/internal/transportOptions.ts +1 -0
- package/src/internal/watchdogMain.ts +5 -3
- package/src/internal/websocket.ts +5 -2
- package/src/internal/websocketServer.ts +6 -4
- package/src/internal/workerChannel.ts +1 -0
- package/src/internal/workerMain.ts +21 -5
- package/src/runner/auth/bearer.ts +10 -6
- package/src/runner/auth/jwt.ts +10 -41
- package/src/runner/auth/mtls.ts +6 -3
- package/src/runner/auth/none.ts +3 -1
- package/src/runner/index.ts +102 -11
- package/src/runner/stdio.ts +15 -10
- package/src/runner/unix.ts +7 -4
- package/src/runner/websocket.ts +9 -7
- package/dist/Auth-BElTC9_X.js +0 -6
- package/dist/Bootstrap-H9gDsgsC.js +0 -9
- package/dist/ConfigDirectory-BCC6q2R4.js +0 -5
- package/dist/Contract-DsJtisvL.js +0 -83
- package/dist/Errors-DYhsGZcZ.js +0 -58
- package/dist/FailureGroup-BgT73AaR.js +0 -63
- package/dist/Framing-G9eSaeLb.js +0 -61
- package/dist/Graft-B71CPA2Y.js +0 -996
- package/dist/Packages-AgoCGotL.js +0 -108
- package/dist/Peer-DXeVrGBh.js +0 -342
- package/dist/ProcessObservation-gLgGirYv.js +0 -38
- package/dist/ServeLifecycle-Bd1FPJ6e.js +0 -24
- package/dist/Transport-DULzpsgR.js +0 -6
- package/dist/WatchdogProtocol-BZmVxrBP.js +0 -17
- package/dist/bin.js +0 -28276
- package/dist/bin.js.map +0 -1
- package/dist/childRuntime-Bm3iSg_N.js +0 -192
- package/dist/command-9zrHdbwT.js +0 -7
- package/dist/connectionEnded-BwcxQ7W8.js +0 -54
- package/dist/directTransport-DrexuPSm.js +0 -5
- package/dist/entry-psOpX3Bj.js +0 -736
- package/dist/importer-Cvf88eAY.js +0 -344
- package/dist/internal/ServeLifecycle.js.map +0 -1
- package/dist/internal/entryConfig.d.ts.map +0 -1
- package/dist/internal/platform.js.map +0 -1
- package/dist/internal/release.js +0 -25
- package/dist/internal/release.js.map +0 -1
- package/dist/internal/serve.js +0 -60
- package/dist/internal/serve.js.map +0 -1
- package/dist/port--3x2zJ4D.js +0 -285
- package/dist/release-DfZPuIcK.js +0 -23
- package/dist/rolldown-runtime-DYf_mQCB.js +0 -34
- package/dist/socketChannel-CJvL2DiB.js +0 -3658
- package/dist/supervisorPlugin-t6Z6PrhD.js +0 -733
- package/dist/token-CYBNNlhS.js +0 -17
- package/dist/tokenCredentials-CbCuk-Rt.js +0 -31
- package/dist/websocketServer-NQhODlEt.js +0 -60
- package/dist/workerChannel-C8hhBJzA.js +0 -27
- package/src/internal/release.ts +0 -72
- package/src/internal/serve.ts +0 -119
- /package/dist/{bin.d.ts → internal/childMain.d.ts} +0 -0
package/dist/token-CYBNNlhS.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { t as AuthenticationFailed } from "./Errors-DYhsGZcZ.js";
|
|
2
|
-
import { Effect, Option, Redacted } from "effect";
|
|
3
|
-
// packages/remote/src/internal/auth/token.ts
|
|
4
|
-
const invalid = () => AuthenticationFailed.make({
|
|
5
|
-
reason: "invalid",
|
|
6
|
-
challenge: "Bearer error=\"invalid_token\""
|
|
7
|
-
});
|
|
8
|
-
const read = (authorization) => {
|
|
9
|
-
if (Option.isNone(authorization)) return Effect.fail(AuthenticationFailed.make({
|
|
10
|
-
reason: "missing",
|
|
11
|
-
challenge: "Bearer"
|
|
12
|
-
}));
|
|
13
|
-
const token = /^Bearer +([^ ]+)$/i.exec(Redacted.value(authorization.value))?.[1];
|
|
14
|
-
return token === void 0 ? Effect.fail(invalid()) : Effect.succeed(Redacted.make(token));
|
|
15
|
-
};
|
|
16
|
-
const prepare = (token) => Effect.succeed(Redacted.make("Bearer " + Redacted.value(token)));
|
|
17
|
-
export { prepare as n, read as r, invalid as t };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { a as provide, l as make } from "./Graft-B71CPA2Y.js";
|
|
2
|
-
import { t as ConfigDirectory } from "./ConfigDirectory-BCC6q2R4.js";
|
|
3
|
-
import { n as Credentials } from "./Auth-BElTC9_X.js";
|
|
4
|
-
import { r as CredentialsError } from "./Errors-DYhsGZcZ.js";
|
|
5
|
-
import { n as prepare } from "./token-CYBNNlhS.js";
|
|
6
|
-
import { Cause, Effect, FileSystem, Option, Path, Redacted, Schema } from "effect";
|
|
7
|
-
// packages/remote/src/internal/auth/tokenCredentials.ts
|
|
8
|
-
const Config$1 = Schema.Struct({ token: Schema.Union([Schema.RedactedFromValue(Schema.String), Schema.Struct({ file: Schema.String })]) });
|
|
9
|
-
const plugin = (name) => make({
|
|
10
|
-
name,
|
|
11
|
-
config: Config$1,
|
|
12
|
-
inject: [FileSystem.FileSystem, Path.Path],
|
|
13
|
-
apply: Effect.fnUntraced(function* (config) {
|
|
14
|
-
const fs = yield* FileSystem.FileSystem;
|
|
15
|
-
const path = yield* Path.Path;
|
|
16
|
-
const directory = yield* ConfigDirectory;
|
|
17
|
-
const token = config.token;
|
|
18
|
-
const read = Redacted.isRedacted(token) ? Effect.succeed(token) : fs.readFileString(path.resolve(Option.getOrElse(directory, () => "."), token.file)).pipe(Effect.map(Redacted.make));
|
|
19
|
-
yield* provide(Credentials, {
|
|
20
|
-
kind: "Authorization",
|
|
21
|
-
read: read.pipe(Effect.flatMap(prepare), Effect.mapBoth({
|
|
22
|
-
onSuccess: (value) => ({
|
|
23
|
-
_tag: "Authorization",
|
|
24
|
-
value
|
|
25
|
-
}),
|
|
26
|
-
onFailure: (error) => CredentialsError.make({ cause: Cause.fail(error) })
|
|
27
|
-
}))
|
|
28
|
-
});
|
|
29
|
-
})
|
|
30
|
-
});
|
|
31
|
-
export { plugin as n, Config$1 as t };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { u as TransportError } from "./Errors-DYhsGZcZ.js";
|
|
2
|
-
import { a as payloadLimit, s as protocol, t as fromSocket } from "./socketChannel-CJvL2DiB.js";
|
|
3
|
-
import { Array, Cause, Deferred, Effect, Option, Redacted, Scope, String } from "effect";
|
|
4
|
-
import { NodeHttpServer, NodeHttpServerRequest } from "@effect/platform-node";
|
|
5
|
-
import { HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
6
|
-
import { TLSSocket } from "node:tls";
|
|
7
|
-
// packages/remote/src/internal/websocketServer.ts
|
|
8
|
-
const rejection = (error) => error._tag === "AuthenticatorUnavailable" ? unavailable(error) : unauthorized(error);
|
|
9
|
-
const unavailable = (error) => Effect.logError("Remote host authenticator is unavailable", error.cause).pipe(Effect.as(HttpServerResponse.empty({ status: 503 })));
|
|
10
|
-
const unauthorized = (error) => Effect.logWarning("Remote host authentication failed", { reason: error.reason }, ...error.cause === void 0 ? [] : [error.cause]).pipe(Effect.as(HttpServerResponse.empty({
|
|
11
|
-
status: 401,
|
|
12
|
-
headers: error.challenge === void 0 ? {} : { "www-authenticate": error.challenge }
|
|
13
|
-
})));
|
|
14
|
-
const handshake = Effect.gen(function* () {
|
|
15
|
-
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
16
|
-
const { socket } = NodeHttpServerRequest.toIncomingMessage(request);
|
|
17
|
-
const peer = socket instanceof TLSSocket && socket.authorized ? Option.some(socket.getPeerCertificate()) : Option.none();
|
|
18
|
-
return {
|
|
19
|
-
authorization: Option.map(Option.fromUndefinedOr(request.headers["authorization"]), Redacted.make),
|
|
20
|
-
certificate: Option.map(peer, (certificate) => ({
|
|
21
|
-
der: certificate.raw,
|
|
22
|
-
subjectAltName: Option.fromUndefinedOr(certificate.subjectaltname)
|
|
23
|
-
}))
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
const open = Effect.fnUntraced(function* (createServer, options) {
|
|
27
|
-
const resources = yield* Effect.acquireRelease(Scope.make(), Scope.close);
|
|
28
|
-
const ready = yield* Deferred.make();
|
|
29
|
-
const server = yield* NodeHttpServer.make(createServer, {
|
|
30
|
-
...options,
|
|
31
|
-
disablePreemptiveShutdown: true,
|
|
32
|
-
websocket: {
|
|
33
|
-
perMessageDeflate: false,
|
|
34
|
-
maxPayload: payloadLimit,
|
|
35
|
-
handleProtocols: (protocols) => protocols.has("graft-remote.v1") ? protocol : false
|
|
36
|
-
}
|
|
37
|
-
}).pipe(Scope.provide(resources));
|
|
38
|
-
return {
|
|
39
|
-
address: server.address,
|
|
40
|
-
ready: Deferred.await(ready),
|
|
41
|
-
run: (accept) => server.serve(Effect.gen(function* () {
|
|
42
|
-
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
43
|
-
if (request.url !== "/graft") return HttpServerResponse.empty({ status: 404 });
|
|
44
|
-
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 });
|
|
45
|
-
const session = yield* Effect.result(accept);
|
|
46
|
-
if (session._tag === "Failure") return yield* rejection(session.failure);
|
|
47
|
-
yield* request.upgrade.pipe(Effect.flatMap(session.success), Effect.interruptible, Effect.scoped);
|
|
48
|
-
return HttpServerResponse.empty();
|
|
49
|
-
})).pipe(Effect.andThen(Deferred.succeed(ready, void 0)), Effect.andThen(Effect.never))
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
const bind = Effect.fnUntraced(function* (createServer, options) {
|
|
53
|
-
const server = yield* open(createServer, options);
|
|
54
|
-
return {
|
|
55
|
-
address: server.address,
|
|
56
|
-
ready: server.ready,
|
|
57
|
-
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) })))
|
|
58
|
-
};
|
|
59
|
-
});
|
|
60
|
-
export { bind as t };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { u as TransportError } from "./Errors-DYhsGZcZ.js";
|
|
2
|
-
import { Cause, Effect, FiberSet, Queue, Schema, Sink, Stream } from "effect";
|
|
3
|
-
// packages/remote/src/internal/workerBootstrap.ts
|
|
4
|
-
const Bootstrap = Schema.Struct({
|
|
5
|
-
contractModule: Schema.String,
|
|
6
|
-
session: Schema.String
|
|
7
|
-
});
|
|
8
|
-
// packages/remote/src/internal/workerChannel.ts
|
|
9
|
-
const make = Effect.fnUntraced(function* (endpoint) {
|
|
10
|
-
const input = yield* Queue.unbounded();
|
|
11
|
-
const callbacks = yield* FiberSet.make();
|
|
12
|
-
const run = yield* FiberSet.runtime(callbacks)();
|
|
13
|
-
const receive = (value) => run(value === null ? Queue.end(input) : Queue.offer(input, new Uint8Array(value)));
|
|
14
|
-
yield* Effect.acquireRelease(Effect.sync(() => endpoint.on("message", receive)), () => Effect.sync(() => endpoint.off("message", receive)).pipe(Effect.andThen(Queue.shutdown(input))));
|
|
15
|
-
const send = (bytes) => Effect.try({
|
|
16
|
-
try: () => {
|
|
17
|
-
const buffer = bytes === null ? null : new Uint8Array(bytes).buffer;
|
|
18
|
-
endpoint.postMessage(buffer, buffer === null ? [] : [buffer]);
|
|
19
|
-
},
|
|
20
|
-
catch: (cause) => TransportError.make({ cause: Cause.die(cause) })
|
|
21
|
-
});
|
|
22
|
-
return {
|
|
23
|
-
input: Stream.fromQueue(input),
|
|
24
|
-
output: Sink.forEach((bytes) => send(bytes)).pipe(Sink.ensuring(send(null)))
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
export { Bootstrap as n, make as t };
|
package/src/internal/release.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { Array, Cause, Effect, Exit, Result, Schema, Scope } from "effect"
|
|
2
|
-
|
|
3
|
-
/** Resource release was interrupted, rather than successfully cancelled. */
|
|
4
|
-
export class ReleaseInterrupted extends Schema.TaggedError<
|
|
5
|
-
ReleaseInterrupted,
|
|
6
|
-
{ readonly brand: unique symbol }
|
|
7
|
-
>()("ReleaseInterrupted", {
|
|
8
|
-
cause: Schema.Cause(Schema.Never, Schema.Unknown),
|
|
9
|
-
}) {
|
|
10
|
-
override get message() {
|
|
11
|
-
return "Resource release was interrupted"
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** Keep a known release failure distinguishable from cancellation through enclosing scopes. */
|
|
16
|
-
export const close = (
|
|
17
|
-
scope: Scope.Closeable,
|
|
18
|
-
exit: Exit.Exit<unknown, unknown>,
|
|
19
|
-
) =>
|
|
20
|
-
Effect.uninterruptible(
|
|
21
|
-
Scope.close(scope, exit).pipe(
|
|
22
|
-
Effect.catchCauseIf(
|
|
23
|
-
Cause.hasInterruptsOnly,
|
|
24
|
-
Effect.fnUntraced(function* (cause) {
|
|
25
|
-
// Re-entering interruptibility observes pending external cancellation without producing a self-interrupt.
|
|
26
|
-
// Read it after release so cancellation arriving during a finalizer is included too.
|
|
27
|
-
const pending = yield* Effect.exit(Effect.interruptible(Effect.void))
|
|
28
|
-
const [cancelled, interrupted] = Array.partition(
|
|
29
|
-
cause.reasons,
|
|
30
|
-
(reason) =>
|
|
31
|
-
Exit.isFailure(pending) &&
|
|
32
|
-
Array.some(
|
|
33
|
-
pending.cause.reasons,
|
|
34
|
-
(external) =>
|
|
35
|
-
reason._tag === "Interrupt" &&
|
|
36
|
-
external._tag === "Interrupt" &&
|
|
37
|
-
reason.fiberId === external.fiberId,
|
|
38
|
-
)
|
|
39
|
-
? Result.succeed(reason)
|
|
40
|
-
: Result.fail(reason),
|
|
41
|
-
)
|
|
42
|
-
if (interrupted.length === 0) return yield* Effect.failCause(cause)
|
|
43
|
-
return yield* Effect.failCause(
|
|
44
|
-
Cause.combine(
|
|
45
|
-
Cause.fromReasons(cancelled),
|
|
46
|
-
Cause.die(
|
|
47
|
-
ReleaseInterrupted.make({
|
|
48
|
-
cause: Cause.fromReasons(interrupted),
|
|
49
|
-
}),
|
|
50
|
-
),
|
|
51
|
-
),
|
|
52
|
-
)
|
|
53
|
-
}),
|
|
54
|
-
),
|
|
55
|
-
),
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
export const scoped = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
|
|
59
|
-
Effect.uninterruptibleMask((restore) =>
|
|
60
|
-
Effect.gen(function* () {
|
|
61
|
-
const scope = yield* Scope.make()
|
|
62
|
-
const body = yield* Effect.exit(restore(Scope.provide(scope)(effect)))
|
|
63
|
-
const closed = yield* Effect.exit(close(scope, body))
|
|
64
|
-
if (Exit.isFailure(closed))
|
|
65
|
-
return yield* Effect.failCause(
|
|
66
|
-
Exit.isFailure(body)
|
|
67
|
-
? Cause.combine(body.cause, closed.cause)
|
|
68
|
-
: closed.cause,
|
|
69
|
-
)
|
|
70
|
-
return yield* body
|
|
71
|
-
}),
|
|
72
|
-
)
|
package/src/internal/serve.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { findSubtree, isSubtreeActive } from "./forkTree"
|
|
2
|
-
import { Graft, Plugin, type Fork } from "@graftland/graft"
|
|
3
|
-
import {
|
|
4
|
-
ConfigDirectory,
|
|
5
|
-
Include,
|
|
6
|
-
Loader,
|
|
7
|
-
ModuleResolver,
|
|
8
|
-
} from "@graftland/loader"
|
|
9
|
-
import {
|
|
10
|
-
Array,
|
|
11
|
-
Cause,
|
|
12
|
-
Deferred,
|
|
13
|
-
Effect,
|
|
14
|
-
Exit,
|
|
15
|
-
Logger,
|
|
16
|
-
Option,
|
|
17
|
-
Path,
|
|
18
|
-
Stream,
|
|
19
|
-
} from "effect"
|
|
20
|
-
import * as Importer from "./importer"
|
|
21
|
-
|
|
22
|
-
import { ServeLifecycle, StartupError, make } from "./ServeLifecycle"
|
|
23
|
-
import { cleanupCause } from "./cleanup"
|
|
24
|
-
export { StartupError } from "./ServeLifecycle"
|
|
25
|
-
|
|
26
|
-
const check = (
|
|
27
|
-
trees: ReadonlyArray<Fork.ForkTree>,
|
|
28
|
-
): Effect.Effect<void, StartupError> =>
|
|
29
|
-
Effect.forEach(
|
|
30
|
-
trees,
|
|
31
|
-
(tree) => {
|
|
32
|
-
if (tree.state._tag === "Failed")
|
|
33
|
-
return Effect.fail(
|
|
34
|
-
StartupError.make({
|
|
35
|
-
detail: `Runner entry ${tree.name} failed`,
|
|
36
|
-
cause: tree.state.cause,
|
|
37
|
-
}),
|
|
38
|
-
)
|
|
39
|
-
return check(tree.children)
|
|
40
|
-
},
|
|
41
|
-
{ discard: true },
|
|
42
|
-
)
|
|
43
|
-
const ready = Plugin.make({
|
|
44
|
-
name: "remote-ready",
|
|
45
|
-
inject: [Loader.Loader],
|
|
46
|
-
apply: Effect.fnUntraced(function* () {
|
|
47
|
-
const loader = yield* Loader.Loader
|
|
48
|
-
// A failed authenticator can leave its listener child Pending while the outer plugin is Applying.
|
|
49
|
-
yield* loader.ready.pipe(
|
|
50
|
-
Effect.raceFirst(
|
|
51
|
-
Graft.forks.pipe(
|
|
52
|
-
Stream.map((trees) => findSubtree(trees, loader.root.id)),
|
|
53
|
-
Stream.filter(Option.isSome),
|
|
54
|
-
Stream.runForEach((tree) => check([tree.value])),
|
|
55
|
-
),
|
|
56
|
-
),
|
|
57
|
-
)
|
|
58
|
-
// Pending can still be reacting to a provider published during startup.
|
|
59
|
-
// Observe the loader's subtree, excluding this startup observer itself.
|
|
60
|
-
yield* Graft.forks.pipe(
|
|
61
|
-
Stream.map((trees) => findSubtree(trees, loader.root.id)),
|
|
62
|
-
Stream.filter(Option.isSome),
|
|
63
|
-
Stream.map((tree) => tree.value),
|
|
64
|
-
Stream.tap((tree) => check([tree])),
|
|
65
|
-
Stream.filter(isSubtreeActive),
|
|
66
|
-
Stream.runHead,
|
|
67
|
-
)
|
|
68
|
-
}),
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
/** Loader logs child cleanup errors; the supervisor's release signal also reaches the command exit. */
|
|
72
|
-
const close = Effect.fnUntraced(function* (
|
|
73
|
-
entries: Fork.Fork,
|
|
74
|
-
lifecycle: typeof ServeLifecycle.Service,
|
|
75
|
-
) {
|
|
76
|
-
const disposed = yield* Effect.exit(entries.dispose)
|
|
77
|
-
const released = yield* Effect.exit(Deferred.await(lifecycle.released))
|
|
78
|
-
const cause = Array.reduce(
|
|
79
|
-
[disposed, released],
|
|
80
|
-
Cause.empty,
|
|
81
|
-
(cause: Cause.Cause<unknown>, exit: Exit.Exit<void, unknown>) =>
|
|
82
|
-
Exit.isFailure(exit) ? Cause.combine(cause, exit.cause) : cause,
|
|
83
|
-
)
|
|
84
|
-
if (cause.reasons.length > 0)
|
|
85
|
-
return yield* Effect.failCause(cleanupCause(cause))
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
const load = Effect.fnUntraced(function* (config: string, directory: string) {
|
|
89
|
-
const lifecycle = yield* make
|
|
90
|
-
yield* Graft.provide(ServeLifecycle, lifecycle)
|
|
91
|
-
const importer = yield* Importer.make(directory)
|
|
92
|
-
const resolver = yield* ModuleResolver.make({ base: directory, importer })
|
|
93
|
-
yield* Graft.provide(ModuleResolver.ModuleResolver, resolver)
|
|
94
|
-
const entries = yield* Graft.plugin(Include.Include, {
|
|
95
|
-
path: config,
|
|
96
|
-
watch: false,
|
|
97
|
-
})
|
|
98
|
-
yield* entries.await
|
|
99
|
-
const startup = yield* Graft.plugin(ready)
|
|
100
|
-
yield* startup.await
|
|
101
|
-
return yield* Deferred.await(lifecycle.ended).pipe(
|
|
102
|
-
Effect.ensuring(close(entries, lifecycle)),
|
|
103
|
-
)
|
|
104
|
-
})
|
|
105
|
-
export const run = Effect.fnUntraced(function* (config: string) {
|
|
106
|
-
const path = yield* Path.Path
|
|
107
|
-
const file = path.resolve(config)
|
|
108
|
-
const directory = path.dirname(file)
|
|
109
|
-
return yield* load(file, directory).pipe(
|
|
110
|
-
Effect.mapError((error) =>
|
|
111
|
-
StartupError.make({
|
|
112
|
-
detail: "Starting the runner failed",
|
|
113
|
-
cause: Cause.fail(error),
|
|
114
|
-
}),
|
|
115
|
-
),
|
|
116
|
-
Effect.provideService(ConfigDirectory, Option.some(directory)),
|
|
117
|
-
Effect.provideService(Logger.LogToStderr, true),
|
|
118
|
-
)
|
|
119
|
-
})
|
|
File without changes
|