alchemy 2.0.0-beta.43 → 2.0.0-beta.44
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/bin/cli.js +18 -5
- package/bin/exec.js +315 -233
- package/bin/exec.js.map +1 -1
- package/lib/Auth/Lock.js +2 -2
- package/lib/Auth/Lock.js.map +1 -1
- package/lib/Bundle/Bundle.d.ts +11 -0
- package/lib/Bundle/Bundle.d.ts.map +1 -1
- package/lib/Bundle/Bundle.js +19 -12
- package/lib/Bundle/Bundle.js.map +1 -1
- package/lib/Bundle/BundleAnalyzerPlugin.d.ts +25 -0
- package/lib/Bundle/BundleAnalyzerPlugin.d.ts.map +1 -0
- package/lib/Bundle/BundleAnalyzerPlugin.js +16 -0
- package/lib/Bundle/BundleAnalyzerPlugin.js.map +1 -0
- package/lib/Bundle/RawPlugin.d.ts +36 -0
- package/lib/Bundle/RawPlugin.d.ts.map +1 -0
- package/lib/Bundle/RawPlugin.js +80 -0
- package/lib/Bundle/RawPlugin.js.map +1 -0
- package/lib/Bundle/index.d.ts +2 -0
- package/lib/Bundle/index.d.ts.map +1 -1
- package/lib/Bundle/index.js +2 -0
- package/lib/Bundle/index.js.map +1 -1
- package/lib/Cli/commands/dev.d.ts +3 -2
- package/lib/Cli/commands/dev.d.ts.map +1 -1
- package/lib/Cli/commands/dev.js +9 -1
- package/lib/Cli/commands/dev.js.map +1 -1
- package/lib/Cli/exec.d.ts.map +1 -1
- package/lib/Cli/exec.js +2 -1
- package/lib/Cli/exec.js.map +1 -1
- package/lib/Cloudflare/Local.d.ts +2 -0
- package/lib/Cloudflare/Local.d.ts.map +1 -0
- package/lib/Cloudflare/Local.js +9 -0
- package/lib/Cloudflare/Local.js.map +1 -0
- package/lib/Cloudflare/Providers.d.ts.map +1 -1
- package/lib/Cloudflare/Providers.js +3 -1
- package/lib/Cloudflare/Providers.js.map +1 -1
- package/lib/Cloudflare/Workers/DurableObjectBridge.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/DurableObjectBridge.js +0 -1
- package/lib/Cloudflare/Workers/DurableObjectBridge.js.map +1 -1
- package/lib/Cloudflare/Workers/LocalWorkerProvider.d.ts +22 -3
- package/lib/Cloudflare/Workers/LocalWorkerProvider.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/LocalWorkerProvider.js +413 -21
- package/lib/Cloudflare/Workers/LocalWorkerProvider.js.map +1 -1
- package/lib/Cloudflare/Workers/Worker.d.ts +6 -19
- package/lib/Cloudflare/Workers/Worker.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/Worker.js +3 -4
- package/lib/Cloudflare/Workers/Worker.js.map +1 -1
- package/lib/Cloudflare/Workers/WorkerBridge.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/WorkerBridge.js +3 -5
- package/lib/Cloudflare/Workers/WorkerBridge.js.map +1 -1
- package/lib/Cloudflare/Workers/WorkerBundle.d.ts +1 -2
- package/lib/Cloudflare/Workers/WorkerBundle.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/WorkerBundle.js +3 -6
- package/lib/Cloudflare/Workers/WorkerBundle.js.map +1 -1
- package/lib/Cloudflare/Zaraz/ZarazConfig.d.ts +184 -0
- package/lib/Cloudflare/Zaraz/ZarazConfig.d.ts.map +1 -0
- package/lib/Cloudflare/Zaraz/ZarazConfig.js +216 -0
- package/lib/Cloudflare/Zaraz/ZarazConfig.js.map +1 -0
- package/lib/Cloudflare/Zaraz/ZarazEventTypes.d.ts +188 -0
- package/lib/Cloudflare/Zaraz/ZarazEventTypes.d.ts.map +1 -0
- package/lib/Cloudflare/Zaraz/ZarazEventTypes.js +4 -0
- package/lib/Cloudflare/Zaraz/ZarazEventTypes.js.map +1 -0
- package/lib/Cloudflare/Zaraz/index.d.ts +3 -0
- package/lib/Cloudflare/Zaraz/index.d.ts.map +1 -0
- package/lib/Cloudflare/Zaraz/index.js +2 -0
- package/lib/Cloudflare/Zaraz/index.js.map +1 -0
- package/lib/Cloudflare/index.d.ts +1 -0
- package/lib/Cloudflare/index.d.ts.map +1 -1
- package/lib/Cloudflare/index.js +1 -0
- package/lib/Cloudflare/index.js.map +1 -1
- package/lib/Local/RpcProvider.d.ts +54 -0
- package/lib/Local/RpcProvider.d.ts.map +1 -0
- package/lib/Local/RpcProvider.js +57 -0
- package/lib/Local/RpcProvider.js.map +1 -0
- package/lib/Local/RpcProviderProxy.d.ts +19 -0
- package/lib/Local/RpcProviderProxy.d.ts.map +1 -0
- package/lib/Local/RpcProviderProxy.js +48 -0
- package/lib/Local/RpcProviderProxy.js.map +1 -0
- package/lib/Local/RpcSerialization.d.ts +34 -0
- package/lib/Local/RpcSerialization.d.ts.map +1 -0
- package/lib/Local/RpcSerialization.js +120 -0
- package/lib/Local/RpcSerialization.js.map +1 -0
- package/lib/Local/RpcServer.d.ts +63 -0
- package/lib/Local/RpcServer.d.ts.map +1 -0
- package/lib/Local/RpcServer.js +72 -0
- package/lib/Local/RpcServer.js.map +1 -0
- package/lib/Local/RpcServerBun.d.ts +3 -0
- package/lib/Local/RpcServerBun.d.ts.map +1 -0
- package/lib/Local/RpcServerBun.js +47 -0
- package/lib/Local/RpcServerBun.js.map +1 -0
- package/lib/Local/RpcServerEnvironment.d.ts +20 -0
- package/lib/Local/RpcServerEnvironment.d.ts.map +1 -0
- package/lib/Local/RpcServerEnvironment.js +22 -0
- package/lib/Local/RpcServerEnvironment.js.map +1 -0
- package/lib/Local/RpcServerNode.d.ts +3 -0
- package/lib/Local/RpcServerNode.d.ts.map +1 -0
- package/lib/Local/RpcServerNode.js +43 -0
- package/lib/Local/RpcServerNode.js.map +1 -0
- package/lib/Local/RpcServerSession.d.ts +27 -0
- package/lib/Local/RpcServerSession.d.ts.map +1 -0
- package/lib/Local/RpcServerSession.js +68 -0
- package/lib/Local/RpcServerSession.js.map +1 -0
- package/lib/Local/RpcSpawner.d.ts +21 -0
- package/lib/Local/RpcSpawner.d.ts.map +1 -0
- package/lib/Local/RpcSpawner.js +132 -0
- package/lib/Local/RpcSpawner.js.map +1 -0
- package/lib/Util/PlatformServices.d.ts +7 -0
- package/lib/Util/PlatformServices.d.ts.map +1 -1
- package/lib/Util/PlatformServices.js +22 -11
- package/lib/Util/PlatformServices.js.map +1 -1
- package/lib/Util/camel.d.ts.map +1 -1
- package/lib/Util/camel.js +2 -3
- package/lib/Util/camel.js.map +1 -1
- package/lib/Util/data.d.ts +5 -0
- package/lib/Util/data.d.ts.map +1 -1
- package/lib/Util/data.js +29 -0
- package/lib/Util/data.js.map +1 -1
- package/lib/Util/stable.d.ts.map +1 -1
- package/lib/Util/stable.js +3 -6
- package/lib/Util/stable.js.map +1 -1
- package/lib/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +12 -14
- package/src/Auth/Lock.ts +2 -2
- package/src/Bundle/Bundle.ts +35 -13
- package/src/Bundle/BundleAnalyzerPlugin.ts +33 -0
- package/src/Bundle/RawPlugin.ts +82 -0
- package/src/Bundle/index.ts +2 -0
- package/src/Cli/commands/dev.ts +51 -37
- package/src/Cli/exec.ts +12 -7
- package/src/Cloudflare/Local.ts +23 -0
- package/src/Cloudflare/Providers.ts +3 -0
- package/src/Cloudflare/Workers/DurableObjectBridge.ts +0 -1
- package/src/Cloudflare/Workers/LocalWorkerProvider.ts +547 -21
- package/src/Cloudflare/Workers/Worker.ts +11 -22
- package/src/Cloudflare/Workers/WorkerBridge.ts +3 -5
- package/src/Cloudflare/Workers/WorkerBundle.ts +4 -8
- package/src/Cloudflare/Zaraz/ZarazConfig.ts +403 -0
- package/src/Cloudflare/Zaraz/ZarazEventTypes.ts +257 -0
- package/src/Cloudflare/Zaraz/index.ts +25 -0
- package/src/Cloudflare/index.ts +1 -0
- package/src/Local/RpcProvider.ts +102 -0
- package/src/Local/RpcProviderProxy.ts +86 -0
- package/src/Local/RpcSerialization.ts +225 -0
- package/src/Local/RpcServer.ts +138 -0
- package/src/Local/RpcServerBun.ts +59 -0
- package/src/Local/RpcServerEnvironment.ts +55 -0
- package/src/Local/RpcServerNode.ts +58 -0
- package/src/Local/RpcServerSession.ts +87 -0
- package/src/Local/RpcSpawner.ts +196 -0
- package/src/Util/PlatformServices.ts +41 -27
- package/src/Util/camel.ts +3 -5
- package/src/Util/data.ts +38 -0
- package/src/Util/stable.ts +4 -10
- package/lib/Cloudflare/Local/Sidecar.d.ts +0 -63
- package/lib/Cloudflare/Local/Sidecar.d.ts.map +0 -1
- package/lib/Cloudflare/Local/Sidecar.js +0 -50
- package/lib/Cloudflare/Local/Sidecar.js.map +0 -1
- package/lib/Cloudflare/Local/SidecarHandlers.d.ts +0 -8
- package/lib/Cloudflare/Local/SidecarHandlers.d.ts.map +0 -1
- package/lib/Cloudflare/Local/SidecarHandlers.js +0 -381
- package/lib/Cloudflare/Local/SidecarHandlers.js.map +0 -1
- package/lib/Cloudflare/Local/SidecarServer.d.ts +0 -2
- package/lib/Cloudflare/Local/SidecarServer.d.ts.map +0 -1
- package/lib/Cloudflare/Local/SidecarServer.js +0 -34
- package/lib/Cloudflare/Local/SidecarServer.js.map +0 -1
- package/lib/Sidecar/Lock.d.ts +0 -23
- package/lib/Sidecar/Lock.d.ts.map +0 -1
- package/lib/Sidecar/Lock.js +0 -39
- package/lib/Sidecar/Lock.js.map +0 -1
- package/lib/Sidecar/RpcClient.d.ts +0 -15
- package/lib/Sidecar/RpcClient.d.ts.map +0 -1
- package/lib/Sidecar/RpcClient.js +0 -78
- package/lib/Sidecar/RpcClient.js.map +0 -1
- package/lib/Sidecar/RpcHandler.d.ts +0 -51
- package/lib/Sidecar/RpcHandler.d.ts.map +0 -1
- package/lib/Sidecar/RpcHandler.js +0 -87
- package/lib/Sidecar/RpcHandler.js.map +0 -1
- package/lib/Sidecar/RpcPaths.d.ts +0 -19
- package/lib/Sidecar/RpcPaths.d.ts.map +0 -1
- package/lib/Sidecar/RpcPaths.js +0 -31
- package/lib/Sidecar/RpcPaths.js.map +0 -1
- package/lib/Sidecar/RpcServer.d.ts +0 -30
- package/lib/Sidecar/RpcServer.d.ts.map +0 -1
- package/lib/Sidecar/RpcServer.js +0 -105
- package/lib/Sidecar/RpcServer.js.map +0 -1
- package/lib/Sidecar/RpcServerBun.d.ts +0 -4
- package/lib/Sidecar/RpcServerBun.d.ts.map +0 -1
- package/lib/Sidecar/RpcServerBun.js +0 -28
- package/lib/Sidecar/RpcServerBun.js.map +0 -1
- package/lib/Sidecar/RpcServerNode.d.ts +0 -4
- package/lib/Sidecar/RpcServerNode.d.ts.map +0 -1
- package/lib/Sidecar/RpcServerNode.js +0 -39
- package/lib/Sidecar/RpcServerNode.js.map +0 -1
- package/lib/Sidecar/RpcServices.d.ts +0 -6
- package/lib/Sidecar/RpcServices.d.ts.map +0 -1
- package/lib/Sidecar/RpcServices.js +0 -29
- package/lib/Sidecar/RpcServices.js.map +0 -1
- package/src/Cloudflare/Local/Sidecar.ts +0 -81
- package/src/Cloudflare/Local/SidecarHandlers.ts +0 -491
- package/src/Cloudflare/Local/SidecarServer.ts +0 -70
- package/src/Sidecar/Lock.ts +0 -66
- package/src/Sidecar/RpcClient.ts +0 -142
- package/src/Sidecar/RpcHandler.ts +0 -205
- package/src/Sidecar/RpcPaths.ts +0 -39
- package/src/Sidecar/RpcServer.ts +0 -153
- package/src/Sidecar/RpcServerBun.ts +0 -41
- package/src/Sidecar/RpcServerNode.ts +0 -51
- package/src/Sidecar/RpcServices.ts +0 -48
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import { WebSocketServer, type Server } from "ws";
|
|
3
|
+
import * as RpcServer from "./RpcServer.ts";
|
|
4
|
+
|
|
5
|
+
export const RpcServerNode = RpcServer.layerServer(
|
|
6
|
+
Effect.fnUntraced(function* ({
|
|
7
|
+
parentConnected,
|
|
8
|
+
parentDisconnected,
|
|
9
|
+
createRpcSession,
|
|
10
|
+
}) {
|
|
11
|
+
const server = new WebSocketServer({ host: "127.0.0.1", port: 0 });
|
|
12
|
+
const url = yield* Effect.callback<string>((resume) => {
|
|
13
|
+
server.on("connection", (ws, req) => {
|
|
14
|
+
if (req.url?.startsWith("/parent")) {
|
|
15
|
+
parentConnected();
|
|
16
|
+
ws.on("close", () => {
|
|
17
|
+
parentDisconnected();
|
|
18
|
+
});
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const session = createRpcSession(ws);
|
|
22
|
+
ws.on("message", (data) => {
|
|
23
|
+
session.dispatch.message(data.toString());
|
|
24
|
+
});
|
|
25
|
+
ws.on("close", (code, reason) => {
|
|
26
|
+
session.dispatch.close(code, reason.toString());
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
server.on("error", (error) => {
|
|
30
|
+
resume(Effect.die(error));
|
|
31
|
+
});
|
|
32
|
+
server.on("listening", () => {
|
|
33
|
+
resume(getServerAddress(server));
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => server.close()));
|
|
37
|
+
return { url };
|
|
38
|
+
}),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
function getServerAddress(server: Server): Effect.Effect<string> {
|
|
42
|
+
const address = server.address();
|
|
43
|
+
if (
|
|
44
|
+
typeof address === "object" &&
|
|
45
|
+
address !== null &&
|
|
46
|
+
"address" in address &&
|
|
47
|
+
"port" in address
|
|
48
|
+
) {
|
|
49
|
+
return Effect.succeed(
|
|
50
|
+
`ws://${address.address === "::" ? "localhost" : address.address}:${address.port}`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return Effect.die(
|
|
54
|
+
new Error(
|
|
55
|
+
`Server address is not an object with address and port properties: ${JSON.stringify(address)}`,
|
|
56
|
+
),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { RpcSession, type RpcCompatible, type RpcTransport } from "capnweb";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A platform-agnostic interface for a server-side WebSocket.
|
|
5
|
+
*/
|
|
6
|
+
export interface ServerWebSocketLike {
|
|
7
|
+
send: (message: string) => any | Promise<any>;
|
|
8
|
+
close: (code?: number, reason?: string) => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Represents a websocket RPC session with capnweb.
|
|
13
|
+
* Use the `dispatch` object to handle messages that are received from the client.
|
|
14
|
+
*/
|
|
15
|
+
export type ServerRpcSession<T extends RpcCompatible<T>> = ReturnType<
|
|
16
|
+
typeof makeServerRpcSession<T>
|
|
17
|
+
>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Constructs a ServerRpcSession using capnweb.
|
|
21
|
+
* @param ws - The WebSocket to use for the session.
|
|
22
|
+
* @param main - The main object to use for the session.
|
|
23
|
+
* @returns A ServerRpcSession.
|
|
24
|
+
*/
|
|
25
|
+
export function makeServerRpcSession<T extends RpcCompatible<T>>(
|
|
26
|
+
ws: ServerWebSocketLike,
|
|
27
|
+
main: T,
|
|
28
|
+
) {
|
|
29
|
+
const { transport, dispatch } = makeWebSocketRpcTransport(ws);
|
|
30
|
+
const session = new RpcSession(transport, main);
|
|
31
|
+
return { session, dispatch };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function makeWebSocketRpcTransport(ws: ServerWebSocketLike) {
|
|
35
|
+
let receiveQueue: Array<string> = [];
|
|
36
|
+
let receiveResolver: ((value: string) => void) | undefined;
|
|
37
|
+
let receiveRejecter: ((reason: unknown) => void) | undefined;
|
|
38
|
+
let error: unknown | undefined;
|
|
39
|
+
return {
|
|
40
|
+
transport: {
|
|
41
|
+
send: async (message: string) => await ws.send(message),
|
|
42
|
+
receive: async () => {
|
|
43
|
+
const next = receiveQueue.shift();
|
|
44
|
+
if (next) {
|
|
45
|
+
return next;
|
|
46
|
+
} else if (error) {
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
return new Promise<string>((resolve, reject) => {
|
|
50
|
+
receiveResolver = resolve;
|
|
51
|
+
receiveRejecter = reject;
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
abort: (reason: unknown) => {
|
|
55
|
+
const message =
|
|
56
|
+
reason instanceof Error ? reason.message : String(reason);
|
|
57
|
+
ws.close(3000, message);
|
|
58
|
+
error ??= reason;
|
|
59
|
+
},
|
|
60
|
+
} satisfies RpcTransport,
|
|
61
|
+
dispatch: {
|
|
62
|
+
message: (data: string | Buffer<ArrayBuffer>) => {
|
|
63
|
+
if (error) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
data = typeof data === "string" ? data : data.toString("utf-8");
|
|
67
|
+
if (receiveResolver) {
|
|
68
|
+
receiveResolver(data);
|
|
69
|
+
receiveResolver = undefined;
|
|
70
|
+
receiveRejecter = undefined;
|
|
71
|
+
} else {
|
|
72
|
+
receiveQueue.push(data);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
close: (code: number, reason: string) => {
|
|
76
|
+
if (!error) {
|
|
77
|
+
error = new Error(`WebSocket closed with code ${code}: ${reason}`);
|
|
78
|
+
if (receiveRejecter) {
|
|
79
|
+
receiveRejecter(error);
|
|
80
|
+
receiveRejecter = undefined;
|
|
81
|
+
receiveResolver = undefined;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { exitHook } from "@alchemy.run/node-utils/exit-hook";
|
|
2
|
+
import * as Cache from "effect/Cache";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as Deferred from "effect/Deferred";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import type { PlatformError } from "effect/PlatformError";
|
|
8
|
+
import * as Scope from "effect/Scope";
|
|
9
|
+
import * as Stream from "effect/Stream";
|
|
10
|
+
import * as HttpServer from "effect/unstable/http/HttpServer";
|
|
11
|
+
import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
|
|
12
|
+
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
|
13
|
+
import * as ChildProcess from "effect/unstable/process/ChildProcess";
|
|
14
|
+
import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
|
|
15
|
+
import * as NodeChildProcess from "node:child_process";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
import { httpServer } from "../Util/PlatformServices.ts";
|
|
18
|
+
import {
|
|
19
|
+
RPC_SERVER_ENVIRONMENT_KEY,
|
|
20
|
+
type RpcServerEnvironment,
|
|
21
|
+
} from "./RpcServerEnvironment.ts";
|
|
22
|
+
|
|
23
|
+
export class RpcSpawner extends Context.Service<
|
|
24
|
+
RpcSpawner,
|
|
25
|
+
{
|
|
26
|
+
readonly url: string;
|
|
27
|
+
}
|
|
28
|
+
>()("alchemy/Local/RpcSpawner") {}
|
|
29
|
+
|
|
30
|
+
export interface RpcSpawnPayload extends Pick<
|
|
31
|
+
RpcServerEnvironment,
|
|
32
|
+
"alchemyContext" | "stack"
|
|
33
|
+
> {
|
|
34
|
+
serverEntryUrl: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const make = Effect.fnUntraced(function* ({
|
|
38
|
+
profile,
|
|
39
|
+
envFile,
|
|
40
|
+
}: Pick<RpcServerEnvironment, "profile" | "envFile">) {
|
|
41
|
+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
42
|
+
const scope = yield* Effect.scope;
|
|
43
|
+
const cache = yield* Cache.make({
|
|
44
|
+
lookup: (payload: RpcSpawnPayload) =>
|
|
45
|
+
spawn(payload).pipe(Scope.provide(scope)),
|
|
46
|
+
capacity: Infinity,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const spawn = Effect.fnUntraced(function* ({
|
|
50
|
+
serverEntryUrl,
|
|
51
|
+
alchemyContext,
|
|
52
|
+
stack,
|
|
53
|
+
}: RpcSpawnPayload) {
|
|
54
|
+
const bin = typeof globalThis.Bun !== "undefined" ? "bun" : "node";
|
|
55
|
+
const main = fileURLToPath(serverEntryUrl);
|
|
56
|
+
const environment: RpcServerEnvironment = {
|
|
57
|
+
profile,
|
|
58
|
+
envFile,
|
|
59
|
+
alchemyContext,
|
|
60
|
+
stack,
|
|
61
|
+
};
|
|
62
|
+
const command = ChildProcess.make(
|
|
63
|
+
bin,
|
|
64
|
+
{
|
|
65
|
+
bun: ["run", main],
|
|
66
|
+
// Under Node, transparently strip TypeScript types so that `.ts`
|
|
67
|
+
// entry points work the same way they do under Bun. Mirrors what
|
|
68
|
+
// `dev.ts` already does for the outer process, so the dev experience
|
|
69
|
+
// is symmetric on both runtimes whether the entry came from `src/`
|
|
70
|
+
// (dev/tests) or `lib/` (published packages).
|
|
71
|
+
node: main.endsWith(".ts")
|
|
72
|
+
? [
|
|
73
|
+
"--experimental-transform-types",
|
|
74
|
+
"--no-warnings=ExperimentalWarning",
|
|
75
|
+
main,
|
|
76
|
+
]
|
|
77
|
+
: [main],
|
|
78
|
+
}[bin],
|
|
79
|
+
{
|
|
80
|
+
stdout: "pipe",
|
|
81
|
+
stderr: "inherit",
|
|
82
|
+
detached: false,
|
|
83
|
+
env: {
|
|
84
|
+
[RPC_SERVER_ENVIRONMENT_KEY]: JSON.stringify(environment),
|
|
85
|
+
},
|
|
86
|
+
extendEnv: true,
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
const handle = yield* spawner.spawn(command);
|
|
90
|
+
const unregister = exitHook(() => {
|
|
91
|
+
killProcessGroup(handle.pid, "SIGKILL");
|
|
92
|
+
});
|
|
93
|
+
const kill = handle
|
|
94
|
+
.kill({ forceKillAfter: "500 millis" })
|
|
95
|
+
.pipe(Effect.tap(() => Effect.sync(unregister)));
|
|
96
|
+
yield* Effect.addFinalizer(() => kill.pipe(Effect.ignore));
|
|
97
|
+
const url = yield* getRpcAddress(handle.stdout);
|
|
98
|
+
const ws = yield* Effect.acquireRelease(
|
|
99
|
+
Effect.sync(() => new WebSocket(new URL("/parent", url))),
|
|
100
|
+
(ws) => Effect.sync(() => ws.close()),
|
|
101
|
+
);
|
|
102
|
+
return {
|
|
103
|
+
url,
|
|
104
|
+
isRunning: Effect.zipWith(
|
|
105
|
+
handle.isRunning,
|
|
106
|
+
Effect.sync(
|
|
107
|
+
() =>
|
|
108
|
+
ws.readyState === WebSocket.CONNECTING ||
|
|
109
|
+
ws.readyState === WebSocket.OPEN,
|
|
110
|
+
),
|
|
111
|
+
(a, b) => a && b,
|
|
112
|
+
{ concurrent: true },
|
|
113
|
+
),
|
|
114
|
+
kill,
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const register = Effect.fnUntraced(function* (
|
|
119
|
+
payload: RpcSpawnPayload,
|
|
120
|
+
attempt = 0,
|
|
121
|
+
): Effect.fn.Return<string, PlatformError> {
|
|
122
|
+
const child = yield* Cache.get(cache, payload);
|
|
123
|
+
if (yield* child.isRunning) {
|
|
124
|
+
return child.url;
|
|
125
|
+
}
|
|
126
|
+
if (attempt > 3) {
|
|
127
|
+
return yield* Effect.die(
|
|
128
|
+
new Error(
|
|
129
|
+
`Failed to spawn RPC server for "${payload.serverEntryUrl}" after ${attempt} attempts.`,
|
|
130
|
+
),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
yield* child.kill;
|
|
134
|
+
yield* Cache.invalidate(cache, payload);
|
|
135
|
+
return yield* register(payload, attempt + 1);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const server = yield* HttpServer.HttpServer;
|
|
139
|
+
|
|
140
|
+
yield* server.serve(
|
|
141
|
+
Effect.gen(function* () {
|
|
142
|
+
const request = yield* HttpServerRequest;
|
|
143
|
+
const payload = (yield* request.json) as unknown as RpcSpawnPayload;
|
|
144
|
+
const url = yield* register(payload);
|
|
145
|
+
return HttpServerResponse.text(url);
|
|
146
|
+
}),
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
return RpcSpawner.of({
|
|
150
|
+
url: HttpServer.formatAddress(server.address),
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
export const layerServer = (
|
|
155
|
+
environment: Pick<RpcServerEnvironment, "profile" | "envFile">,
|
|
156
|
+
) =>
|
|
157
|
+
Layer.effect(RpcSpawner, make(environment)).pipe(Layer.provide(httpServer()));
|
|
158
|
+
|
|
159
|
+
const RPC_ADDRESS_REGEX =
|
|
160
|
+
/(<ALCHEMY_RPC_ADDRESS>)(.+)(<\/ALCHEMY_RPC_ADDRESS>)/;
|
|
161
|
+
|
|
162
|
+
const getRpcAddress = (stdout: Stream.Stream<Uint8Array, PlatformError>) =>
|
|
163
|
+
Effect.gen(function* () {
|
|
164
|
+
const address = yield* Deferred.make<string>();
|
|
165
|
+
let done = false;
|
|
166
|
+
yield* stdout.pipe(
|
|
167
|
+
Stream.decodeText,
|
|
168
|
+
Stream.splitLines,
|
|
169
|
+
Stream.runForEach((line) => {
|
|
170
|
+
if (done) {
|
|
171
|
+
console.log(line);
|
|
172
|
+
} else {
|
|
173
|
+
const match = line.match(RPC_ADDRESS_REGEX);
|
|
174
|
+
if (match) {
|
|
175
|
+
done = true;
|
|
176
|
+
return Deferred.succeed(address, match[2]);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return Effect.void;
|
|
180
|
+
}),
|
|
181
|
+
Effect.forkScoped,
|
|
182
|
+
);
|
|
183
|
+
return yield* Deferred.await(address);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const killProcessGroup = (pid: number, signal: NodeJS.Signals) => {
|
|
187
|
+
try {
|
|
188
|
+
if (process.platform === "win32") {
|
|
189
|
+
NodeChildProcess.execSync(`taskkill /pid ${pid} /T /F`);
|
|
190
|
+
} else {
|
|
191
|
+
process.kill(-pid, signal);
|
|
192
|
+
}
|
|
193
|
+
} catch {
|
|
194
|
+
// ignore errors during best-effort cleanup
|
|
195
|
+
}
|
|
196
|
+
};
|
|
@@ -12,6 +12,23 @@ import type { WebSocketConstructor } from "effect/unstable/socket/Socket";
|
|
|
12
12
|
|
|
13
13
|
const isBun = typeof Bun !== "undefined";
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Constructs a layer with different implementations for Bun and Node.
|
|
17
|
+
*/
|
|
18
|
+
export const platformLayer = <A, E, R>(constructors: {
|
|
19
|
+
bun: () => Promise<Layer.Layer<A, E, R>>;
|
|
20
|
+
node: () => Promise<Layer.Layer<A, E, R>>;
|
|
21
|
+
}) =>
|
|
22
|
+
Layer.unwrap(
|
|
23
|
+
Effect.promise(async () => {
|
|
24
|
+
if (isBun) {
|
|
25
|
+
return await constructors.bun();
|
|
26
|
+
} else {
|
|
27
|
+
return await constructors.node();
|
|
28
|
+
}
|
|
29
|
+
}),
|
|
30
|
+
);
|
|
31
|
+
|
|
15
32
|
export type PlatformServices =
|
|
16
33
|
| ChildProcessSpawner
|
|
17
34
|
| FileSystem
|
|
@@ -21,29 +38,25 @@ export type PlatformServices =
|
|
|
21
38
|
// WebSocketConstructor is not included in NodeServices/BunServices, but required for Workers tail
|
|
22
39
|
| WebSocketConstructor;
|
|
23
40
|
|
|
24
|
-
export const PlatformServices: Layer.Layer<PlatformServices> =
|
|
25
|
-
async () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
NodeServices.layer,
|
|
42
|
-
NodeSocket.layerWebSocketConstructor,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
41
|
+
export const PlatformServices: Layer.Layer<PlatformServices> = platformLayer({
|
|
42
|
+
bun: async () => {
|
|
43
|
+
const [BunServices, BunSocket] = await Promise.all([
|
|
44
|
+
import("@effect/platform-bun/BunServices"),
|
|
45
|
+
import("@effect/platform-bun/BunSocket"),
|
|
46
|
+
]);
|
|
47
|
+
return Layer.merge(BunServices.layer, BunSocket.layerWebSocketConstructor);
|
|
48
|
+
},
|
|
49
|
+
node: async () => {
|
|
50
|
+
const [NodeServices, NodeSocket] = await Promise.all([
|
|
51
|
+
import("@effect/platform-node/NodeServices"),
|
|
52
|
+
import("@effect/platform-node/NodeSocket"),
|
|
53
|
+
]);
|
|
54
|
+
return Layer.merge(
|
|
55
|
+
NodeServices.layer,
|
|
56
|
+
NodeSocket.layerWebSocketConstructor,
|
|
57
|
+
);
|
|
45
58
|
},
|
|
46
|
-
)
|
|
59
|
+
});
|
|
47
60
|
|
|
48
61
|
export const runMain = <E, A>(
|
|
49
62
|
effect: Effect.Effect<A, E>,
|
|
@@ -67,15 +80,16 @@ export const httpServer = (
|
|
|
67
80
|
port: number = 0,
|
|
68
81
|
host: string = "127.0.0.1",
|
|
69
82
|
): Layer.Layer<HttpServer, ServeError> =>
|
|
70
|
-
|
|
71
|
-
|
|
83
|
+
platformLayer({
|
|
84
|
+
bun: async () => {
|
|
72
85
|
const BunHttpServer = await import("@effect/platform-bun/BunHttpServer");
|
|
73
86
|
return BunHttpServer.layer({ hostname: host, port });
|
|
74
|
-
}
|
|
87
|
+
},
|
|
88
|
+
node: async () => {
|
|
75
89
|
const [NodeHttpServer, Http] = await Promise.all([
|
|
76
90
|
import("@effect/platform-node/NodeHttpServer"),
|
|
77
91
|
import("node:http"),
|
|
78
92
|
]);
|
|
79
93
|
return NodeHttpServer.layerServer(Http.createServer, { host, port });
|
|
80
|
-
}
|
|
81
|
-
})
|
|
94
|
+
},
|
|
95
|
+
});
|
package/src/Util/camel.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isPlainObject } from "./data.ts";
|
|
2
|
+
|
|
1
3
|
export const camelCaseKey = (key: string) =>
|
|
2
4
|
key
|
|
3
5
|
.replace(/^_+/, "")
|
|
@@ -7,11 +9,7 @@ export const toCamelCase = <T>(value: unknown): T => {
|
|
|
7
9
|
if (Array.isArray(value)) {
|
|
8
10
|
return value.map((item) => toCamelCase(item)) as T;
|
|
9
11
|
}
|
|
10
|
-
if (
|
|
11
|
-
value &&
|
|
12
|
-
typeof value === "object" &&
|
|
13
|
-
Object.getPrototypeOf(value) === Object.prototype
|
|
14
|
-
) {
|
|
12
|
+
if (isPlainObject(value)) {
|
|
15
13
|
return Object.fromEntries(
|
|
16
14
|
Object.entries(value).map(([key, nested]) => [
|
|
17
15
|
camelCaseKey(key),
|
package/src/Util/data.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import * as Predicate from "effect/Predicate";
|
|
2
|
+
import * as EffectRecord from "effect/Record";
|
|
3
|
+
import * as Redacted from "effect/Redacted";
|
|
4
|
+
|
|
1
5
|
export type Primitive =
|
|
2
6
|
| never
|
|
3
7
|
| undefined
|
|
@@ -16,3 +20,37 @@ export const isPrimitive = (value: any): value is Primitive =>
|
|
|
16
20
|
typeof value === "string" ||
|
|
17
21
|
typeof value === "symbol" ||
|
|
18
22
|
typeof value === "bigint";
|
|
23
|
+
|
|
24
|
+
export const isPlainObject = (
|
|
25
|
+
value: unknown,
|
|
26
|
+
): value is Record<string, unknown> => {
|
|
27
|
+
if (!Predicate.isObject(value)) return false;
|
|
28
|
+
return Object.getPrototypeOf(value) === Object.prototype;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const stripFields = <T>(value: T, empty: null | undefined): T => {
|
|
32
|
+
if (Array.isArray(value)) {
|
|
33
|
+
return value.map((item) => stripFields(item, empty)) as T;
|
|
34
|
+
}
|
|
35
|
+
if (!isPlainObject(value)) return value;
|
|
36
|
+
return EffectRecord.map(
|
|
37
|
+
EffectRecord.filter(value, (entry) => entry !== empty),
|
|
38
|
+
(entry) => stripFields(entry, empty),
|
|
39
|
+
) as T;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const stripNullFields = <T>(value: T): T => stripFields(value, null);
|
|
43
|
+
|
|
44
|
+
export const stripUndefinedFields = <T>(value: T): T =>
|
|
45
|
+
stripFields(value, undefined);
|
|
46
|
+
|
|
47
|
+
export const unwrapRedacted = <T>(value: T): T => {
|
|
48
|
+
if (Redacted.isRedacted(value)) {
|
|
49
|
+
return Redacted.value(value) as T;
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(value)) {
|
|
52
|
+
return value.map(unwrapRedacted) as T;
|
|
53
|
+
}
|
|
54
|
+
if (!isPlainObject(value)) return value;
|
|
55
|
+
return EffectRecord.map(value, unwrapRedacted) as T;
|
|
56
|
+
};
|
package/src/Util/stable.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isPlainObject } from "./data.ts";
|
|
2
|
+
|
|
1
3
|
export const normalizeNulls = <T>(value: T): T => {
|
|
2
4
|
if (value === null) {
|
|
3
5
|
return undefined as T;
|
|
@@ -5,11 +7,7 @@ export const normalizeNulls = <T>(value: T): T => {
|
|
|
5
7
|
if (Array.isArray(value)) {
|
|
6
8
|
return value.map((item) => normalizeNulls(item)) as T;
|
|
7
9
|
}
|
|
8
|
-
if (
|
|
9
|
-
value &&
|
|
10
|
-
typeof value === "object" &&
|
|
11
|
-
Object.getPrototypeOf(value) === Object.prototype
|
|
12
|
-
) {
|
|
10
|
+
if (isPlainObject(value)) {
|
|
13
11
|
return Object.fromEntries(
|
|
14
12
|
Object.entries(value)
|
|
15
13
|
.map(([key, nested]) => [key, normalizeNulls(nested)])
|
|
@@ -23,11 +21,7 @@ export const stableValue = (value: unknown): unknown => {
|
|
|
23
21
|
if (Array.isArray(value)) {
|
|
24
22
|
return value.map(stableValue);
|
|
25
23
|
}
|
|
26
|
-
if (
|
|
27
|
-
value &&
|
|
28
|
-
typeof value === "object" &&
|
|
29
|
-
Object.getPrototypeOf(value) === Object.prototype
|
|
30
|
-
) {
|
|
24
|
+
if (isPlainObject(value)) {
|
|
31
25
|
return Object.fromEntries(
|
|
32
26
|
Object.entries(value)
|
|
33
27
|
.sort(([a], [b]) => a.localeCompare(b))
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import * as Effect from "effect/Effect";
|
|
2
|
-
import * as Schema from "effect/Schema";
|
|
3
|
-
import { BundleError } from "../../Bundle/Bundle.ts";
|
|
4
|
-
import type { ResourceBinding } from "../../Resource.ts";
|
|
5
|
-
import type { Worker, WorkerProps } from "../Workers/Worker.ts";
|
|
6
|
-
export interface ReconcileOptions {
|
|
7
|
-
id: string;
|
|
8
|
-
props: WorkerProps;
|
|
9
|
-
bindings: ResourceBinding<Worker["Binding"]>[];
|
|
10
|
-
stack: {
|
|
11
|
-
name: string;
|
|
12
|
-
stage: string;
|
|
13
|
-
};
|
|
14
|
-
instanceId: string;
|
|
15
|
-
}
|
|
16
|
-
declare const ValidationError_base: Schema.Class<ValidationError, Schema.TaggedStruct<"ValidationError", {
|
|
17
|
-
readonly message: Schema.String;
|
|
18
|
-
readonly hint: Schema.optional<Schema.String>;
|
|
19
|
-
readonly value: Schema.Unknown;
|
|
20
|
-
}>, import("effect/Cause").YieldableError>;
|
|
21
|
-
export declare class ValidationError extends ValidationError_base {
|
|
22
|
-
}
|
|
23
|
-
export declare const ServeResult: Schema.Struct<{
|
|
24
|
-
readonly workerId: Schema.String;
|
|
25
|
-
readonly workerName: Schema.String;
|
|
26
|
-
readonly logpush: Schema.UndefinedOr<Schema.Boolean>;
|
|
27
|
-
readonly url: Schema.String;
|
|
28
|
-
readonly tags: Schema.mutable<Schema.$Array<Schema.String>>;
|
|
29
|
-
readonly durableObjectNamespaces: Schema.$Record<Schema.String, Schema.String>;
|
|
30
|
-
readonly domains: Schema.mutable<Schema.$Array<Schema.Struct<{
|
|
31
|
-
readonly hostname: Schema.String;
|
|
32
|
-
readonly id: Schema.String;
|
|
33
|
-
readonly zoneId: Schema.String;
|
|
34
|
-
}>>>;
|
|
35
|
-
readonly crons: Schema.mutable<Schema.$Array<Schema.String>>;
|
|
36
|
-
readonly accountId: Schema.String;
|
|
37
|
-
}>;
|
|
38
|
-
export type ServeResult = typeof ServeResult.Type;
|
|
39
|
-
export declare const ServeError: Schema.Union<readonly [Schema.Union<readonly [typeof import("@distilled.cloud/cloudflare-runtime").ConfigError, typeof import("@distilled.cloud/cloudflare-runtime").SystemError, typeof import("@distilled.cloud/cloudflare-runtime").ApiError]>, typeof BundleError, typeof ValidationError]>;
|
|
40
|
-
export type ServeError = typeof ServeError.Type;
|
|
41
|
-
export declare const DiffResult: Schema.Struct<{
|
|
42
|
-
readonly action: Schema.Literals<readonly ["update", "noop"]>;
|
|
43
|
-
}>;
|
|
44
|
-
export type DiffResult = typeof DiffResult.Type;
|
|
45
|
-
export declare const SidecarSchema: import("../../Sidecar/RpcHandler.ts").RpcHandlerEncoders<{
|
|
46
|
-
readonly diff: (options: ReconcileOptions) => Effect.Effect<DiffResult>;
|
|
47
|
-
readonly reconcile: (options: ReconcileOptions) => Effect.Effect<ServeResult, ServeError>;
|
|
48
|
-
readonly delete: (id: string) => Effect.Effect<void>;
|
|
49
|
-
}> & import("../../Sidecar/RpcHandler.ts").RpcHandlerDecoders<{
|
|
50
|
-
readonly diff: (options: ReconcileOptions) => Effect.Effect<DiffResult>;
|
|
51
|
-
readonly reconcile: (options: ReconcileOptions) => Effect.Effect<ServeResult, ServeError>;
|
|
52
|
-
readonly delete: (id: string) => Effect.Effect<void>;
|
|
53
|
-
}>;
|
|
54
|
-
declare const Sidecar_base: import("effect/Context").ServiceClass<Sidecar, "Sidecar", {
|
|
55
|
-
readonly diff: (options: ReconcileOptions) => Effect.Effect<DiffResult>;
|
|
56
|
-
readonly reconcile: (options: ReconcileOptions) => Effect.Effect<ServeResult, ServeError>;
|
|
57
|
-
readonly delete: (id: string) => Effect.Effect<void>;
|
|
58
|
-
}>;
|
|
59
|
-
export declare class Sidecar extends Sidecar_base {
|
|
60
|
-
}
|
|
61
|
-
export declare const SidecarLive: import("effect/Layer").Layer<Sidecar, never, import("effect/unstable/process/ChildProcessSpawner").ChildProcessSpawner | import("effect/FileSystem").FileSystem | import("effect/Path").Path | import("../../AlchemyContext.ts").AlchemyContext>;
|
|
62
|
-
export {};
|
|
63
|
-
//# sourceMappingURL=Sidecar.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Sidecar.d.ts","sourceRoot":"","sources":["../../../src/Cloudflare/Local/Sidecar.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzD,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEhE,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;IAC/C,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,UAAU,EAAE,MAAM,CAAC;CACpB;;;;;;AAED,qBAAa,eAAgB,SAAQ,oBAOpC;CAAG;AAEJ,eAAO,MAAM,WAAW;;;;;;;;;;;;;;EAgBtB,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAC;AAElD,eAAO,MAAM,UAAU,iSAIrB,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,IAAI,CAAC;AAEhD,eAAO,MAAM,UAAU;;EAErB,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,IAAI,CAAC;AAEhD,eAAO,MAAM,aAAa;mBAYP,CAAC,OAAO,EAAE,gBAAgB,KAAK,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;wBACnD,CAClB,OAAO,EAAE,gBAAgB,KACtB,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC;qBAC1B,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;;mBAJrC,CAAC,OAAO,EAAE,gBAAgB,KAAK,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;wBACnD,CAClB,OAAO,EAAE,gBAAgB,KACtB,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC;qBAC1B,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;EATtD,CAAC;;mBAKgB,CAAC,OAAO,EAAE,gBAAgB,KAAK,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;wBACnD,CAClB,OAAO,EAAE,gBAAgB,KACtB,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC;qBAC1B,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;;AAPxD,qBAAa,OAAQ,SAAQ,YASf;CAAG;AAEjB,eAAO,MAAM,WAAW,kPAGtB,CAAC"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { RuntimeError } from "@distilled.cloud/cloudflare-runtime/RuntimeError";
|
|
2
|
-
import * as Effect from "effect/Effect";
|
|
3
|
-
import * as Schema from "effect/Schema";
|
|
4
|
-
import { BundleError } from "../../Bundle/Bundle.js";
|
|
5
|
-
import * as RpcClient from "../../Sidecar/RpcClient.js";
|
|
6
|
-
import { defineSchema } from "../../Sidecar/RpcHandler.js";
|
|
7
|
-
export class ValidationError extends Schema.TaggedErrorClass()("ValidationError", {
|
|
8
|
-
message: Schema.String,
|
|
9
|
-
hint: Schema.optional(Schema.String),
|
|
10
|
-
value: Schema.Unknown,
|
|
11
|
-
}) {
|
|
12
|
-
}
|
|
13
|
-
export const ServeResult = Schema.Struct({
|
|
14
|
-
workerId: Schema.String,
|
|
15
|
-
workerName: Schema.String,
|
|
16
|
-
logpush: Schema.UndefinedOr(Schema.Boolean),
|
|
17
|
-
url: Schema.String,
|
|
18
|
-
tags: Schema.Array(Schema.String).pipe(Schema.mutable),
|
|
19
|
-
durableObjectNamespaces: Schema.Record(Schema.String, Schema.String),
|
|
20
|
-
domains: Schema.Array(Schema.Struct({
|
|
21
|
-
hostname: Schema.String,
|
|
22
|
-
id: Schema.String,
|
|
23
|
-
zoneId: Schema.String,
|
|
24
|
-
})).pipe(Schema.mutable),
|
|
25
|
-
crons: Schema.Array(Schema.String).pipe(Schema.mutable),
|
|
26
|
-
accountId: Schema.String,
|
|
27
|
-
});
|
|
28
|
-
export const ServeError = Schema.Union([
|
|
29
|
-
RuntimeError,
|
|
30
|
-
BundleError,
|
|
31
|
-
ValidationError,
|
|
32
|
-
]);
|
|
33
|
-
export const DiffResult = Schema.Struct({
|
|
34
|
-
action: Schema.Literals(["update", "noop"]),
|
|
35
|
-
});
|
|
36
|
-
export const SidecarSchema = defineSchema({
|
|
37
|
-
diff: { success: DiffResult, error: Schema.Never },
|
|
38
|
-
reconcile: {
|
|
39
|
-
success: ServeResult,
|
|
40
|
-
error: ServeError,
|
|
41
|
-
},
|
|
42
|
-
delete: { success: Schema.Void, error: Schema.Never },
|
|
43
|
-
});
|
|
44
|
-
export class Sidecar extends RpcClient.RpcClientService()("Sidecar") {
|
|
45
|
-
}
|
|
46
|
-
export const SidecarLive = RpcClient.layer(Sidecar, {
|
|
47
|
-
main: import.meta.resolve("./SidecarServer.ts", import.meta.url),
|
|
48
|
-
schema: SidecarSchema,
|
|
49
|
-
});
|
|
50
|
-
//# sourceMappingURL=Sidecar.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Sidecar.js","sourceRoot":"","sources":["../../../src/Cloudflare/Local/Sidecar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kDAAkD,CAAC;AAChF,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,KAAK,SAAS,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAW3D,MAAM,OAAO,eAAgB,SAAQ,MAAM,CAAC,gBAAgB,EAAmB,CAC7E,iBAAiB,EACjB;IACE,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACpC,KAAK,EAAE,MAAM,CAAC,OAAO;CACtB,CACF;CAAG;AAEJ,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;IACvC,QAAQ,EAAE,MAAM,CAAC,MAAM;IACvB,UAAU,EAAE,MAAM,CAAC,MAAM;IACzB,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC;IAC3C,GAAG,EAAE,MAAM,CAAC,MAAM;IAClB,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IACtD,uBAAuB,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;IACpE,OAAO,EAAE,MAAM,CAAC,KAAK,CACnB,MAAM,CAAC,MAAM,CAAC;QACZ,QAAQ,EAAE,MAAM,CAAC,MAAM;QACvB,EAAE,EAAE,MAAM,CAAC,MAAM;QACjB,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAC,CACH,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IACvD,SAAS,EAAE,MAAM,CAAC,MAAM;CACzB,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC;IACrC,YAAY;IACZ,WAAW;IACX,eAAe;CAChB,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;CAC5C,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAqB;IAC5D,IAAI,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE;IAClD,SAAS,EAAE;QACT,OAAO,EAAE,WAAW;QACpB,KAAK,EAAE,UAAU;KAClB;IACD,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE;CACtD,CAAC,CAAC;AAEH,MAAM,OAAO,OAAQ,SAAQ,SAAS,CAAC,gBAAgB,EASpD,CAAC,SAAS,CAAC;CAAG;AAEjB,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE;IAClD,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;IAChE,MAAM,EAAE,aAAa;CACtB,CAAC,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type RuntimeServices } from "@distilled.cloud/cloudflare-runtime";
|
|
2
|
-
import * as LocalProxy from "@distilled.cloud/cloudflare-runtime/proxy/LocalProxy";
|
|
3
|
-
import * as Layer from "effect/Layer";
|
|
4
|
-
import * as Path from "effect/Path";
|
|
5
|
-
import { CloudflareEnvironment } from "../CloudflareEnvironment.ts";
|
|
6
|
-
import { Sidecar } from "./Sidecar.ts";
|
|
7
|
-
export declare const SidecarHandlers: Layer.Layer<Sidecar, never, import("effect/FileSystem").FileSystem | Path.Path | CloudflareEnvironment | LocalProxy.LocalProxy | RuntimeServices>;
|
|
8
|
-
//# sourceMappingURL=SidecarHandlers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SidecarHandlers.d.ts","sourceRoot":"","sources":["../../../src/Cloudflare/Local/SidecarHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,eAAe,EACrB,MAAM,qCAAqC,CAAC;AAmB7C,OAAO,KAAK,UAAU,MAAM,sDAAsD,CAAC;AAMnF,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AASpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAWpE,OAAO,EAGL,OAAO,EAGR,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,eAAe,mJAwS3B,CAAC"}
|