alchemy 2.0.0-beta.23 → 2.0.0-beta.24
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/alchemy.js +12589 -2451
- package/bin/alchemy.js.map +1 -1
- package/bin/alchemy.ts +2 -0
- package/bin/cli.js +18 -0
- package/bin/commands/bootstrap.ts +88 -4
- package/bin/commands/deploy.ts +54 -20
- package/bin/commands/dev.ts +45 -0
- package/bin/exec.ts +22 -0
- package/lib/AdoptPolicy.d.ts +2 -2
- package/lib/AdoptPolicy.d.ts.map +1 -1
- package/lib/AdoptPolicy.js.map +1 -1
- package/lib/AlchemyContext.d.ts +1 -0
- package/lib/AlchemyContext.d.ts.map +1 -1
- package/lib/AlchemyContext.js +1 -0
- package/lib/AlchemyContext.js.map +1 -1
- package/lib/Build/Command.d.ts.map +1 -1
- package/lib/Build/Command.js +8 -1
- package/lib/Build/Command.js.map +1 -1
- package/lib/Bundle/Bundle.d.ts +21 -9
- package/lib/Bundle/Bundle.d.ts.map +1 -1
- package/lib/Bundle/Bundle.js +29 -15
- package/lib/Bundle/Bundle.js.map +1 -1
- package/lib/Cloudflare/Local/Sidecar.d.ts +27 -0
- package/lib/Cloudflare/Local/Sidecar.d.ts.map +1 -0
- package/lib/Cloudflare/Local/Sidecar.js +24 -0
- package/lib/Cloudflare/Local/Sidecar.js.map +1 -0
- package/lib/Cloudflare/Local/SidecarHandlers.d.ts +5 -0
- package/lib/Cloudflare/Local/SidecarHandlers.d.ts.map +1 -0
- package/lib/Cloudflare/Local/SidecarHandlers.js +119 -0
- package/lib/Cloudflare/Local/SidecarHandlers.js.map +1 -0
- package/lib/Cloudflare/Local/SidecarServer.d.ts +2 -0
- package/lib/Cloudflare/Local/SidecarServer.d.ts.map +1 -0
- package/lib/Cloudflare/Local/SidecarServer.js +27 -0
- package/lib/Cloudflare/Local/SidecarServer.js.map +1 -0
- package/lib/Cloudflare/SecretsStore/Secret.d.ts.map +1 -1
- package/lib/Cloudflare/SecretsStore/Secret.js +55 -7
- package/lib/Cloudflare/SecretsStore/Secret.js.map +1 -1
- package/lib/Cloudflare/SecretsStore/SecretsStore.d.ts.map +1 -1
- package/lib/Cloudflare/SecretsStore/SecretsStore.js +35 -11
- package/lib/Cloudflare/SecretsStore/SecretsStore.js.map +1 -1
- package/lib/Cloudflare/StateStore/State.d.ts +35 -0
- package/lib/Cloudflare/StateStore/State.d.ts.map +1 -1
- package/lib/Cloudflare/StateStore/State.js +187 -45
- package/lib/Cloudflare/StateStore/State.js.map +1 -1
- package/lib/Cloudflare/StateStore/index.d.ts +1 -1
- package/lib/Cloudflare/StateStore/index.d.ts.map +1 -1
- package/lib/Cloudflare/StateStore/index.js +1 -1
- package/lib/Cloudflare/StateStore/index.js.map +1 -1
- package/lib/Cloudflare/Workers/Assets.d.ts +1 -1
- package/lib/Cloudflare/Workers/Assets.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/Assets.js +6 -1
- package/lib/Cloudflare/Workers/Assets.js.map +1 -1
- package/lib/Cloudflare/Workers/Compatibility.d.ts +6 -0
- package/lib/Cloudflare/Workers/Compatibility.d.ts.map +1 -0
- package/lib/Cloudflare/Workers/Compatibility.js +10 -0
- package/lib/Cloudflare/Workers/Compatibility.js.map +1 -0
- package/lib/Cloudflare/Workers/LocalWorkerProvider.d.ts +7 -0
- package/lib/Cloudflare/Workers/LocalWorkerProvider.d.ts.map +1 -0
- package/lib/Cloudflare/Workers/LocalWorkerProvider.js +81 -0
- package/lib/Cloudflare/Workers/LocalWorkerProvider.js.map +1 -0
- package/lib/Cloudflare/Workers/Worker.d.ts +3 -1
- package/lib/Cloudflare/Workers/Worker.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/Worker.js +54 -7
- package/lib/Cloudflare/Workers/Worker.js.map +1 -1
- package/lib/Cloudflare/Workers/WorkerBundle.d.ts +31 -0
- package/lib/Cloudflare/Workers/WorkerBundle.d.ts.map +1 -0
- package/lib/Cloudflare/Workers/WorkerBundle.js +174 -0
- package/lib/Cloudflare/Workers/WorkerBundle.js.map +1 -0
- package/lib/Cloudflare/Workers/WorkerName.d.ts +3 -0
- package/lib/Cloudflare/Workers/WorkerName.d.ts.map +1 -0
- package/lib/Cloudflare/Workers/WorkerName.js +9 -0
- package/lib/Cloudflare/Workers/WorkerName.js.map +1 -0
- package/lib/Cloudflare/Workers/index.d.ts +1 -0
- package/lib/Cloudflare/Workers/index.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/index.js +1 -0
- package/lib/Cloudflare/Workers/index.js.map +1 -1
- package/lib/Platform.d.ts +1 -1
- package/lib/Platform.d.ts.map +1 -1
- package/lib/Sidecar/Lock.d.ts +24 -0
- package/lib/Sidecar/Lock.d.ts.map +1 -0
- package/lib/Sidecar/Lock.js +102 -0
- package/lib/Sidecar/Lock.js.map +1 -0
- package/lib/Sidecar/RpcClient.d.ts +15 -0
- package/lib/Sidecar/RpcClient.d.ts.map +1 -0
- package/lib/Sidecar/RpcClient.js +75 -0
- package/lib/Sidecar/RpcClient.js.map +1 -0
- package/lib/Sidecar/RpcHandler.d.ts +48 -0
- package/lib/Sidecar/RpcHandler.d.ts.map +1 -0
- package/lib/Sidecar/RpcHandler.js +64 -0
- package/lib/Sidecar/RpcHandler.js.map +1 -0
- package/lib/Sidecar/RpcPaths.d.ts +14 -0
- package/lib/Sidecar/RpcPaths.d.ts.map +1 -0
- package/lib/Sidecar/RpcPaths.js +22 -0
- package/lib/Sidecar/RpcPaths.js.map +1 -0
- package/lib/Sidecar/RpcServer.d.ts +10 -0
- package/lib/Sidecar/RpcServer.d.ts.map +1 -0
- package/lib/Sidecar/RpcServer.js +50 -0
- package/lib/Sidecar/RpcServer.js.map +1 -0
- package/lib/Sidecar/RpcTransport.d.ts +22 -0
- package/lib/Sidecar/RpcTransport.d.ts.map +1 -0
- package/lib/Sidecar/RpcTransport.js +81 -0
- package/lib/Sidecar/RpcTransport.js.map +1 -0
- package/lib/Telemetry/Metrics.d.ts +15 -0
- package/lib/Telemetry/Metrics.d.ts.map +1 -1
- package/lib/Telemetry/Metrics.js +20 -0
- package/lib/Telemetry/Metrics.js.map +1 -1
- package/lib/Util/PlatformServices.d.ts +3 -0
- package/lib/Util/PlatformServices.d.ts.map +1 -1
- package/lib/Util/PlatformServices.js +13 -0
- package/lib/Util/PlatformServices.js.map +1 -1
- package/lib/Util/layer-scoped.d.ts +16 -0
- package/lib/Util/layer-scoped.d.ts.map +1 -0
- package/lib/Util/layer-scoped.js +14 -0
- package/lib/Util/layer-scoped.js.map +1 -0
- package/package.json +4 -2
- package/src/AdoptPolicy.ts +9 -9
- package/src/AlchemyContext.ts +2 -0
- package/src/Build/Command.ts +8 -1
- package/src/Bundle/Bundle.ts +65 -25
- package/src/Cloudflare/Local/Sidecar.ts +44 -0
- package/src/Cloudflare/Local/SidecarHandlers.ts +182 -0
- package/src/Cloudflare/Local/SidecarServer.ts +57 -0
- package/src/Cloudflare/SecretsStore/Secret.ts +78 -7
- package/src/Cloudflare/SecretsStore/SecretsStore.ts +47 -12
- package/src/Cloudflare/StateStore/State.ts +281 -64
- package/src/Cloudflare/StateStore/index.ts +1 -1
- package/src/Cloudflare/Workers/Assets.ts +10 -1
- package/src/Cloudflare/Workers/Compatibility.ts +12 -0
- package/src/Cloudflare/Workers/LocalWorkerProvider.ts +93 -0
- package/src/Cloudflare/Workers/Worker.ts +102 -19
- package/src/Cloudflare/Workers/WorkerBundle.ts +234 -0
- package/src/Cloudflare/Workers/WorkerName.ts +10 -0
- package/src/Cloudflare/Workers/index.ts +1 -0
- package/src/Platform.ts +1 -1
- package/src/Sidecar/Lock.ts +190 -0
- package/src/Sidecar/RpcClient.ts +141 -0
- package/src/Sidecar/RpcHandler.ts +169 -0
- package/src/Sidecar/RpcPaths.ts +29 -0
- package/src/Sidecar/RpcServer.ts +80 -0
- package/src/Sidecar/RpcTransport.ts +85 -0
- package/src/Telemetry/Metrics.ts +38 -0
- package/src/Util/PlatformServices.ts +19 -0
- package/src/Util/layer-scoped.ts +25 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { RpcSession } from "capnweb";
|
|
2
|
+
export function makeBunWebSocketRpcServer(main) {
|
|
3
|
+
return Bun.serve({
|
|
4
|
+
port: 0,
|
|
5
|
+
fetch: (request, server) => {
|
|
6
|
+
if (server.upgrade(request, { data: undefined })) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
return new Response("Upgrade failed", { status: 400 });
|
|
10
|
+
},
|
|
11
|
+
websocket: {
|
|
12
|
+
open: (ws) => {
|
|
13
|
+
const transport = new BunWebSocketRpcTransport(ws);
|
|
14
|
+
const session = new RpcSession(transport, main());
|
|
15
|
+
ws.data = { transport, session };
|
|
16
|
+
},
|
|
17
|
+
message: (ws, message) => {
|
|
18
|
+
ws.data.transport.dispatchMessage(message);
|
|
19
|
+
},
|
|
20
|
+
close: (ws, code, reason) => {
|
|
21
|
+
ws.data.transport.dispatchClose(code, reason);
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
class BunWebSocketRpcTransport {
|
|
27
|
+
ws;
|
|
28
|
+
receiveQueue = [];
|
|
29
|
+
receiveResolver;
|
|
30
|
+
receiveRejecter;
|
|
31
|
+
error;
|
|
32
|
+
constructor(ws) {
|
|
33
|
+
this.ws = ws;
|
|
34
|
+
}
|
|
35
|
+
async send(message) {
|
|
36
|
+
this.ws.send(message);
|
|
37
|
+
}
|
|
38
|
+
async receive() {
|
|
39
|
+
const next = this.receiveQueue.shift();
|
|
40
|
+
if (next) {
|
|
41
|
+
return next;
|
|
42
|
+
}
|
|
43
|
+
else if (this.error) {
|
|
44
|
+
throw this.error;
|
|
45
|
+
}
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
this.receiveResolver = resolve;
|
|
48
|
+
this.receiveRejecter = reject;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
abort(reason) {
|
|
52
|
+
const message = reason instanceof Error ? reason.message : String(reason);
|
|
53
|
+
this.ws.close(3000, message);
|
|
54
|
+
this.error ??= reason;
|
|
55
|
+
}
|
|
56
|
+
dispatchMessage(data) {
|
|
57
|
+
if (this.error) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
data = typeof data === "string" ? data : data.toString("utf-8");
|
|
61
|
+
if (this.receiveResolver) {
|
|
62
|
+
this.receiveResolver(data);
|
|
63
|
+
this.receiveResolver = undefined;
|
|
64
|
+
this.receiveRejecter = undefined;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.receiveQueue.push(data);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
dispatchClose(code, reason) {
|
|
71
|
+
if (!this.error) {
|
|
72
|
+
this.error = new Error(`WebSocket closed with code ${code}: ${reason}`);
|
|
73
|
+
if (this.receiveRejecter) {
|
|
74
|
+
this.receiveRejecter(this.error);
|
|
75
|
+
this.receiveRejecter = undefined;
|
|
76
|
+
this.receiveResolver = undefined;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=RpcTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcTransport.js","sourceRoot":"","sources":["../../src/Sidecar/RpcTransport.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,MAAM,UAAU,yBAAyB,CACvC,IAAa;IAEb,OAAO,GAAG,CAAC,KAAK,CAGb;QACD,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACzB,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,SAAU,EAAE,CAAC,EAAE,CAAC;gBAClD,OAAO;YACT,CAAC;YACD,OAAO,IAAI,QAAQ,CAAC,gBAAgB,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;QACzD,CA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G,SAAS,CAAC;YACnC,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -15,6 +15,15 @@ export declare const resourceDuration: Metric.Histogram<Duration.Duration>;
|
|
|
15
15
|
* Counter for CLI command invocations.
|
|
16
16
|
*/
|
|
17
17
|
export declare const cliCounter: Metric.Counter<number>;
|
|
18
|
+
/**
|
|
19
|
+
* Counter for Cloudflare State Store bootstrap/deploy operations.
|
|
20
|
+
* Tagged per call with `op` (e.g. `deploy`) and `status`
|
|
21
|
+
* (`success`/`error`) so that the deploy success rate of the
|
|
22
|
+
* state store itself can be tracked separately from regular
|
|
23
|
+
* resource lifecycle ops.
|
|
24
|
+
*/
|
|
25
|
+
export declare const stateStoreCounter: Metric.Counter<number>;
|
|
26
|
+
export type StateStoreOp = "deploy";
|
|
18
27
|
/**
|
|
19
28
|
* Wraps a resource lifecycle Effect to record a counter + timer entry,
|
|
20
29
|
* tagged with `resource_type`, `op`, and `status` (`success`/`error`).
|
|
@@ -30,5 +39,11 @@ export declare const recordResourceOp: (resourceType: string, op: ResourceOp) =>
|
|
|
30
39
|
* outcome (`success`/`error`).
|
|
31
40
|
*/
|
|
32
41
|
export declare const recordCli: (command: string) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
42
|
+
/**
|
|
43
|
+
* Wraps a Cloudflare State Store deploy/bootstrap Effect to bump
|
|
44
|
+
* {@link stateStoreCounter} with the outcome (`success`/`error`),
|
|
45
|
+
* tagged with the given `op`.
|
|
46
|
+
*/
|
|
47
|
+
export declare const recordStateStoreOp: (op: StateStoreOp) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
33
48
|
export type ResourceOp = "precreate" | "create" | "update" | "delete" | "read";
|
|
34
49
|
//# sourceMappingURL=Metrics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Metrics.d.ts","sourceRoot":"","sources":["../../src/Telemetry/Metrics.ts"],"names":[],"m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eAAO,MAAM,UAAU,wBAGrB,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,wBAO7B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC;AAEpC;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAC1B,cAAc,MAAM,EAAE,IAAI,UAAU,MACpC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAa1D,CAAC;AAEP;;;GAGG;AACH,eAAO,MAAM,SAAS,GACnB,SAAS,MAAM,MACf,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAW3D,CAAC;AAEN;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAC5B,IAAI,YAAY,MAChB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAW3D,CAAC;AAEN,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC"}
|
package/lib/Telemetry/Metrics.js
CHANGED
|
@@ -24,6 +24,17 @@ export const cliCounter = Metric.counter("alchemy.cli.invocations", {
|
|
|
24
24
|
description: "Number of alchemy CLI command invocations.",
|
|
25
25
|
incremental: true,
|
|
26
26
|
});
|
|
27
|
+
/**
|
|
28
|
+
* Counter for Cloudflare State Store bootstrap/deploy operations.
|
|
29
|
+
* Tagged per call with `op` (e.g. `deploy`) and `status`
|
|
30
|
+
* (`success`/`error`) so that the deploy success rate of the
|
|
31
|
+
* state store itself can be tracked separately from regular
|
|
32
|
+
* resource lifecycle ops.
|
|
33
|
+
*/
|
|
34
|
+
export const stateStoreCounter = Metric.counter("alchemy.state_store.operations", {
|
|
35
|
+
description: "Number of Cloudflare State Store deploy/bootstrap operations dispatched by alchemy.",
|
|
36
|
+
incremental: true,
|
|
37
|
+
});
|
|
27
38
|
/**
|
|
28
39
|
* Wraps a resource lifecycle Effect to record a counter + timer entry,
|
|
29
40
|
* tagged with `resource_type`, `op`, and `status` (`success`/`error`).
|
|
@@ -46,6 +57,15 @@ export const recordCli = (command) => (self) => self.pipe(Effect.onExit((exit) =
|
|
|
46
57
|
command,
|
|
47
58
|
status: Exit.isSuccess(exit) ? "success" : "error",
|
|
48
59
|
}), 1)));
|
|
60
|
+
/**
|
|
61
|
+
* Wraps a Cloudflare State Store deploy/bootstrap Effect to bump
|
|
62
|
+
* {@link stateStoreCounter} with the outcome (`success`/`error`),
|
|
63
|
+
* tagged with the given `op`.
|
|
64
|
+
*/
|
|
65
|
+
export const recordStateStoreOp = (op) => (self) => self.pipe(Effect.onExit((exit) => Metric.update(Metric.withAttributes(stateStoreCounter, {
|
|
66
|
+
op,
|
|
67
|
+
status: Exit.isSuccess(exit) ? "success" : "error",
|
|
68
|
+
}), 1)));
|
|
49
69
|
const elapsed = (startNs) => Duration.nanos(process.hrtime.bigint() - startNs);
|
|
50
70
|
const recordOutcome = (baseAttrs, status, duration) => {
|
|
51
71
|
const attrs = { ...baseAttrs, status };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Metrics.js","sourceRoot":"","sources":["../../src/Telemetry/Metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,MAAM,M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
|
|
|
5
5
|
import type { Teardown } from "effect/Runtime";
|
|
6
6
|
import type { Stdio } from "effect/Stdio";
|
|
7
7
|
import type { Terminal } from "effect/Terminal";
|
|
8
|
+
import type { HttpServer } from "effect/unstable/http/HttpServer";
|
|
9
|
+
import type { ServeError } from "effect/unstable/http/HttpServerError";
|
|
8
10
|
import type { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner";
|
|
9
11
|
import type { WebSocketConstructor } from "effect/unstable/socket/Socket";
|
|
10
12
|
export type PlatformServices = ChildProcessSpawner | FileSystem | Path | Stdio | Terminal | WebSocketConstructor;
|
|
@@ -13,4 +15,5 @@ export declare const runMain: <E, A>(effect: Effect.Effect<A, E>, options?: {
|
|
|
13
15
|
readonly disableErrorReporting?: boolean | undefined;
|
|
14
16
|
readonly teardown?: Teardown | undefined;
|
|
15
17
|
}) => void;
|
|
18
|
+
export declare const httpServer: (port?: number, host?: string) => Layer.Layer<HttpServer, ServeError>;
|
|
16
19
|
//# sourceMappingURL=PlatformServices.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformServices.d.ts","sourceRoot":"","sources":["../../src/Util/PlatformServices.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AACvF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAA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GACL,QAAQ,GAER,oBAAoB,CAAC;AAEzB,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAsBvC,CAAC;AAErB,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,CAAC,EAC1B,QAAQ,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAC3B,UAAU;IACR,QAAQ,CAAC,qBAAqB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACrD,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;CAC1C,KACA,IAUF,CAAC;AAEF,eAAO,MAAM,UAAU,GACrB,OAAM,MAAU,EAChB,OAAM,MAAoB,KACzB,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,UAAU,CAYd,CAAC"}
|
|
@@ -25,4 +25,17 @@ export const runMain = (effect, options) => {
|
|
|
25
25
|
void import("@effect/platform-node/NodeRuntime").then((NodeRuntime) => NodeRuntime.runMain(effect, options));
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
+
export const httpServer = (port = 0, host = "localhost") => Effect.promise(async () => {
|
|
29
|
+
if (isBun) {
|
|
30
|
+
const BunHttpServer = await import("@effect/platform-bun/BunHttpServer");
|
|
31
|
+
return BunHttpServer.layer({ hostname: host, port });
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
const [NodeHttpServer, Http] = await Promise.all([
|
|
35
|
+
import("@effect/platform-node/NodeHttpServer"),
|
|
36
|
+
import("node:http"),
|
|
37
|
+
]);
|
|
38
|
+
return NodeHttpServer.layerServer(Http.createServer, { host, port });
|
|
39
|
+
}
|
|
40
|
+
}).pipe(Layer.unwrap);
|
|
28
41
|
//# sourceMappingURL=PlatformServices.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformServices.js","sourceRoot":"","sources":["../../src/Util/PlatformServices.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAA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CACpC,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,KAAK,MAAM,CAAC,mCAAmC,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CACpE,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CACrC,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,OAAe,CAAC,EAChB,OAAe,WAAW,EACW,EAAE,CACvC,MAAM,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE;IACxB,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,oCAAoC,CAAC,CAAC;QACzE,OAAO,aAAa,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,cAAc,EAAE,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC/C,MAAM,CAAC,sCAAsC,CAAC;YAC9C,MAAM,CAAC,WAAW,CAAC;SACpB,CAAC,CAAC;QACH,OAAO,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACvE,CAAC;AACH,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import type * as Scope from "effect/Scope";
|
|
5
|
+
/**
|
|
6
|
+
* Builds a layer with the current scope.
|
|
7
|
+
* @param layer - The layer to build.
|
|
8
|
+
* @returns A scoped effect returning a Context with the provided layer.
|
|
9
|
+
*/
|
|
10
|
+
export declare const buildLayerScoped: <ROut, E, RIn>(layer: Layer.Layer<ROut, E, RIn>) => Effect.Effect<Context.Context<ROut>, E, RIn | Scope.Scope>;
|
|
11
|
+
/**
|
|
12
|
+
* Builds a layer with the current scope and provides it to the given effect.
|
|
13
|
+
* @param layer - The layer to build.
|
|
14
|
+
*/
|
|
15
|
+
export declare const provideLayerScoped: <ROut, E1, RIn>(layer: Layer.Layer<ROut, E1, RIn>) => <A, E2, R>(effect: Effect.Effect<A, E2, R>) => Effect.Effect<A, E1 | E2, Scope.Scope | RIn | Exclude<R, ROut>>;
|
|
16
|
+
//# sourceMappingURL=layer-scoped.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layer-scoped.d.ts","sourceRoot":"","sources":["../../src/Util/layer-scoped.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,IAAI,EAAE,CAAC,EAAE,GAAG,EAC3C,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,KAC/B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,KAAK,CACiB,CAAC;AAE9E;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAC5B,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,MAChD,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,QAAQ,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,oEAGvC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Layer from "effect/Layer";
|
|
3
|
+
/**
|
|
4
|
+
* Builds a layer with the current scope.
|
|
5
|
+
* @param layer - The layer to build.
|
|
6
|
+
* @returns A scoped effect returning a Context with the provided layer.
|
|
7
|
+
*/
|
|
8
|
+
export const buildLayerScoped = (layer) => Effect.flatMap(Effect.scope, (scope) => Layer.buildWithScope(layer, scope));
|
|
9
|
+
/**
|
|
10
|
+
* Builds a layer with the current scope and provides it to the given effect.
|
|
11
|
+
* @param layer - The layer to build.
|
|
12
|
+
*/
|
|
13
|
+
export const provideLayerScoped = (layer) => (effect) => Effect.flatMap(buildLayerScoped(layer), (context) => Effect.provideContext(effect, context));
|
|
14
|
+
//# sourceMappingURL=layer-scoped.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layer-scoped.js","sourceRoot":"","sources":["../../src/Util/layer-scoped.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAGtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,KAAgC,EAC4B,EAAE,CAC9D,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAE9E;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAC7B,CAAgB,KAAiC,EAAE,EAAE,CACrD,CAAW,MAA+B,EAAE,EAAE,CAC5C,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,CAClD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CACvC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alchemy",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.24",
|
|
4
4
|
"homepage": "https://alchemy.run",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Sam Goodwin <sam@alchemy.run>",
|
|
@@ -241,6 +241,7 @@
|
|
|
241
241
|
"@distilled.cloud/axiom": "^0.13.1",
|
|
242
242
|
"@distilled.cloud/cloudflare": "^0.13.1",
|
|
243
243
|
"@distilled.cloud/cloudflare-rolldown-plugin": "0.3.0",
|
|
244
|
+
"@distilled.cloud/cloudflare-runtime": "0.1.1",
|
|
244
245
|
"@distilled.cloud/cloudflare-vite-plugin": "0.2.0",
|
|
245
246
|
"@distilled.cloud/core": "^0.13.1",
|
|
246
247
|
"@effect/vitest": "4.0.0-beta.58",
|
|
@@ -254,6 +255,7 @@
|
|
|
254
255
|
"ai": "^6.0.62",
|
|
255
256
|
"aws4fetch": "^1.0.20",
|
|
256
257
|
"capnp-es": "^0.0.14",
|
|
258
|
+
"capnweb": "^0.6.1",
|
|
257
259
|
"cloudflare": "^5.2.0",
|
|
258
260
|
"fast-glob": "^3.3.2",
|
|
259
261
|
"fast-xml-parser": "^5.3.4",
|
|
@@ -263,7 +265,7 @@
|
|
|
263
265
|
"libsodium-wrappers": "^0.8.3",
|
|
264
266
|
"magic-string": "^0.30.21",
|
|
265
267
|
"picomatch": "^4.0.4",
|
|
266
|
-
"rolldown": "1.0.0-rc.
|
|
268
|
+
"rolldown": "1.0.0-rc.17",
|
|
267
269
|
"sonda": "^0.11.1",
|
|
268
270
|
"web-tree-sitter": "0.25.10",
|
|
269
271
|
"workerd": "1.20260417.1",
|
package/src/AdoptPolicy.ts
CHANGED
|
@@ -8,16 +8,16 @@ export class AdoptPolicy extends Context.Service<AdoptPolicy, boolean>()(
|
|
|
8
8
|
export const adopt: {
|
|
9
9
|
(
|
|
10
10
|
enabled?: boolean,
|
|
11
|
-
): <
|
|
12
|
-
effect: Effect.Effect<
|
|
13
|
-
) => Effect.Effect<
|
|
14
|
-
<
|
|
15
|
-
enabled: Effect.Effect<boolean, never,
|
|
16
|
-
): <
|
|
17
|
-
effect: Effect.Effect<
|
|
18
|
-
) => Effect.Effect<
|
|
11
|
+
): <A, E, R = never>(
|
|
12
|
+
effect: Effect.Effect<A, E, R>,
|
|
13
|
+
) => Effect.Effect<A, E, R>;
|
|
14
|
+
<R1 = never>(
|
|
15
|
+
enabled: Effect.Effect<boolean, never, R1>,
|
|
16
|
+
): <A, E, R2 = never>(
|
|
17
|
+
effect: Effect.Effect<A, E, R2>,
|
|
18
|
+
) => Effect.Effect<A, E, R1 | R2>;
|
|
19
19
|
} = ((enabled: boolean | Effect.Effect<boolean, never, any>) =>
|
|
20
|
-
(eff: Effect.Effect<any,
|
|
20
|
+
(eff: Effect.Effect<any, any, any>) =>
|
|
21
21
|
eff.pipe(
|
|
22
22
|
typeof enabled === "boolean"
|
|
23
23
|
? Effect.provideService(AdoptPolicy, enabled ?? true)
|
package/src/AlchemyContext.ts
CHANGED
|
@@ -9,6 +9,7 @@ export class AlchemyContext extends EffectContext.Service<
|
|
|
9
9
|
{
|
|
10
10
|
dotAlchemy: string;
|
|
11
11
|
updateStateStore: boolean;
|
|
12
|
+
dev: boolean;
|
|
12
13
|
}
|
|
13
14
|
>()("alchemy/Context") {}
|
|
14
15
|
|
|
@@ -22,6 +23,7 @@ export const AlchemyContextLive = Layer.effect(
|
|
|
22
23
|
return {
|
|
23
24
|
dotAlchemy: dir,
|
|
24
25
|
updateStateStore: false,
|
|
26
|
+
dev: false,
|
|
25
27
|
};
|
|
26
28
|
}),
|
|
27
29
|
);
|
package/src/Build/Command.ts
CHANGED
|
@@ -143,12 +143,19 @@ export const CommandProvider = () =>
|
|
|
143
143
|
if (!output) {
|
|
144
144
|
return undefined;
|
|
145
145
|
}
|
|
146
|
+
// Recompute the output path against the *current* cwd. State
|
|
147
|
+
// may have been written by a different machine (e.g. CI) and
|
|
148
|
+
// the absolute path baked into `output.outdir` won't exist
|
|
149
|
+
// locally. As long as the path resolved against this
|
|
150
|
+
// machine's cwd is present, return the refreshed output so
|
|
151
|
+
// downstream consumers (e.g. `Cloudflare.Worker` assets)
|
|
152
|
+
// don't try to read a stale, foreign-machine path.
|
|
146
153
|
const outputPath = getOutputPath(olds);
|
|
147
154
|
const exists = yield* fs.exists(outputPath);
|
|
148
155
|
if (!exists) {
|
|
149
156
|
return undefined;
|
|
150
157
|
}
|
|
151
|
-
return output;
|
|
158
|
+
return { ...output, outdir: outputPath };
|
|
152
159
|
}),
|
|
153
160
|
create: Effect.fnUntraced(function* ({ news, session }) {
|
|
154
161
|
const hash = yield* hashDirectory(news);
|
package/src/Bundle/Bundle.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import * as Data from "effect/Data";
|
|
2
1
|
import * as Effect from "effect/Effect";
|
|
3
2
|
import * as Path from "effect/Path";
|
|
4
3
|
import * as Queue from "effect/Queue";
|
|
5
|
-
import * as
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
6
5
|
import * as Stream from "effect/Stream";
|
|
7
6
|
import assert from "node:assert";
|
|
8
7
|
import * as rolldown from "rolldown";
|
|
@@ -45,10 +44,32 @@ export interface BundleFile {
|
|
|
45
44
|
readonly hash: string;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
export class BundleError extends
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
export class BundleError extends Schema.TaggedErrorClass<BundleError>()(
|
|
48
|
+
"BundleError",
|
|
49
|
+
{
|
|
50
|
+
message: Schema.String,
|
|
51
|
+
cause: Schema.optional(Schema.DefectWithStack),
|
|
52
|
+
},
|
|
53
|
+
) {}
|
|
54
|
+
|
|
55
|
+
export type BundleWatchEvent =
|
|
56
|
+
| BundleWatchEvent.Start
|
|
57
|
+
| BundleWatchEvent.Success
|
|
58
|
+
| BundleWatchEvent.Error;
|
|
59
|
+
|
|
60
|
+
export declare namespace BundleWatchEvent {
|
|
61
|
+
interface Start {
|
|
62
|
+
readonly _tag: "Start";
|
|
63
|
+
}
|
|
64
|
+
interface Success {
|
|
65
|
+
readonly _tag: "Success";
|
|
66
|
+
readonly output: BundleOutput;
|
|
67
|
+
}
|
|
68
|
+
interface Error {
|
|
69
|
+
readonly _tag: "Error";
|
|
70
|
+
readonly error: BundleError;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
52
73
|
|
|
53
74
|
/**
|
|
54
75
|
* Build a bundle using rolldown from the given input options and output options.
|
|
@@ -93,8 +114,15 @@ export const watch = (
|
|
|
93
114
|
inputOptions: rolldown.InputOptions,
|
|
94
115
|
outputOptions?: rolldown.OutputOptions,
|
|
95
116
|
extra?: BundleExtraOptions,
|
|
96
|
-
): Stream.Stream<
|
|
97
|
-
Stream.callback<
|
|
117
|
+
): Stream.Stream<BundleWatchEvent> =>
|
|
118
|
+
Stream.callback<
|
|
119
|
+
| BundleWatchEvent.Start
|
|
120
|
+
| BundleWatchEvent.Error
|
|
121
|
+
| {
|
|
122
|
+
readonly _tag: "Success";
|
|
123
|
+
readonly output: rolldown.OutputBundle;
|
|
124
|
+
}
|
|
125
|
+
>((queue) =>
|
|
98
126
|
Effect.acquireRelease(
|
|
99
127
|
Effect.sync(() => {
|
|
100
128
|
const watcher = rolldown.watch({
|
|
@@ -104,8 +132,16 @@ export const watch = (
|
|
|
104
132
|
// The watcher event listener does not receive the bundle output, so we grab it using a plugin.
|
|
105
133
|
{
|
|
106
134
|
name: "alchemy:watch-bundle",
|
|
135
|
+
watchChange() {
|
|
136
|
+
Queue.offerUnsafe(queue, {
|
|
137
|
+
_tag: "Start",
|
|
138
|
+
});
|
|
139
|
+
},
|
|
107
140
|
generateBundle(_outputOptions, bundle) {
|
|
108
|
-
Queue.offerUnsafe(queue,
|
|
141
|
+
Queue.offerUnsafe(queue, {
|
|
142
|
+
_tag: "Success",
|
|
143
|
+
output: bundle,
|
|
144
|
+
});
|
|
109
145
|
},
|
|
110
146
|
},
|
|
111
147
|
],
|
|
@@ -113,10 +149,10 @@ export const watch = (
|
|
|
113
149
|
});
|
|
114
150
|
watcher.on("event", (event) => {
|
|
115
151
|
if (event.code === "ERROR") {
|
|
116
|
-
Queue.offerUnsafe(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
);
|
|
152
|
+
Queue.offerUnsafe(queue, {
|
|
153
|
+
_tag: "Error",
|
|
154
|
+
error: bundleErrorFromUnknown(event.error),
|
|
155
|
+
});
|
|
120
156
|
} else if (event.code === "BUNDLE_END") {
|
|
121
157
|
// This must be called to avoid resource leaks.
|
|
122
158
|
event.result.close().catch(() => {});
|
|
@@ -127,23 +163,27 @@ export const watch = (
|
|
|
127
163
|
(watcher) => Effect.promise(() => watcher.close()),
|
|
128
164
|
),
|
|
129
165
|
).pipe(
|
|
130
|
-
Stream.mapEffect((
|
|
166
|
+
Stream.mapEffect((event) =>
|
|
131
167
|
Effect.gen(function* () {
|
|
132
|
-
if (
|
|
133
|
-
return
|
|
168
|
+
if (event._tag !== "Success") {
|
|
169
|
+
return event;
|
|
134
170
|
}
|
|
135
|
-
return yield* bundleOutputFromRolldownOutputBundle(
|
|
136
|
-
Effect.map(
|
|
137
|
-
|
|
171
|
+
return yield* bundleOutputFromRolldownOutputBundle(event.output).pipe(
|
|
172
|
+
Effect.map(
|
|
173
|
+
(output): BundleWatchEvent.Success => ({
|
|
174
|
+
_tag: "Success",
|
|
175
|
+
output,
|
|
176
|
+
}),
|
|
177
|
+
),
|
|
178
|
+
Effect.catch((error) =>
|
|
179
|
+
Effect.succeed<BundleWatchEvent.Error>({
|
|
180
|
+
_tag: "Error",
|
|
181
|
+
error: bundleErrorFromUnknown(error),
|
|
182
|
+
}),
|
|
183
|
+
),
|
|
138
184
|
);
|
|
139
185
|
}),
|
|
140
186
|
),
|
|
141
|
-
Stream.changesWith((left, right) => {
|
|
142
|
-
if (left._tag === "Success" && right._tag === "Success") {
|
|
143
|
-
return left.success.hash === right.success.hash;
|
|
144
|
-
}
|
|
145
|
-
return false;
|
|
146
|
-
}),
|
|
147
187
|
);
|
|
148
188
|
|
|
149
189
|
const ENTRY_MODULE_ID = "virtual:alchemy-entry";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ServeError,
|
|
3
|
+
type ServeResult,
|
|
4
|
+
} from "@distilled.cloud/cloudflare-runtime/Server";
|
|
5
|
+
import * as Worker from "@distilled.cloud/cloudflare-runtime/Worker";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
import { BundleError } from "../../Bundle/Bundle.ts";
|
|
9
|
+
import * as RpcClient from "../../Sidecar/RpcClient.ts";
|
|
10
|
+
import { defineSchema } from "../../Sidecar/RpcHandler.ts";
|
|
11
|
+
import type { WorkerBinding } from "../Workers/Worker.ts";
|
|
12
|
+
import type { WorkerBundleOptions } from "../Workers/WorkerBundle.ts";
|
|
13
|
+
|
|
14
|
+
export interface ServeOptions extends WorkerBundleOptions {
|
|
15
|
+
name: string;
|
|
16
|
+
bindings: WorkerBinding[];
|
|
17
|
+
durableObjectNamespaces: Worker.DurableObjectNamespace[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const SidecarSchema = defineSchema<Sidecar["Service"]>({
|
|
21
|
+
serve: {
|
|
22
|
+
success: Schema.Struct({
|
|
23
|
+
name: Schema.String,
|
|
24
|
+
address: Schema.String,
|
|
25
|
+
}),
|
|
26
|
+
error: Schema.Union([ServeError, BundleError]),
|
|
27
|
+
},
|
|
28
|
+
stop: { success: Schema.Void, error: Schema.Never },
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export class Sidecar extends RpcClient.RpcClientService<
|
|
32
|
+
Sidecar,
|
|
33
|
+
{
|
|
34
|
+
readonly serve: (
|
|
35
|
+
options: ServeOptions,
|
|
36
|
+
) => Effect.Effect<ServeResult, ServeError | BundleError>;
|
|
37
|
+
readonly stop: (name: string) => Effect.Effect<void>;
|
|
38
|
+
}
|
|
39
|
+
>()("Sidecar") {}
|
|
40
|
+
|
|
41
|
+
export const SidecarLive = RpcClient.layer(Sidecar, {
|
|
42
|
+
main: import.meta.resolve("./SidecarServer.ts", import.meta.url),
|
|
43
|
+
schema: SidecarSchema,
|
|
44
|
+
});
|