alchemy 2.0.0-beta.22 → 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 +12590 -2452
- 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/commands/logs.ts +1 -1
- package/bin/commands/tail.ts +1 -1
- package/bin/exec.ts +22 -0
- package/lib/AWS/Lambda/Function.d.ts.map +1 -1
- package/lib/AWS/Lambda/Function.js +25 -21
- package/lib/AWS/Lambda/Function.js.map +1 -1
- package/lib/AWS/Lambda/HttpServer.d.ts.map +1 -1
- package/lib/AWS/Lambda/HttpServer.js +3 -1
- package/lib/AWS/Lambda/HttpServer.js.map +1 -1
- 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/Container/Container.d.ts +55 -2
- package/lib/Cloudflare/Container/Container.d.ts.map +1 -1
- package/lib/Cloudflare/Container/Container.js +55 -2
- package/lib/Cloudflare/Container/Container.js.map +1 -1
- package/lib/Cloudflare/D1/D1Export.d.ts.map +1 -1
- package/lib/Cloudflare/D1/D1Export.js.map +1 -1
- package/lib/Cloudflare/D1/D1SqlFile.d.ts.map +1 -1
- package/lib/Cloudflare/D1/D1SqlFile.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/Queue/Queue.d.ts +34 -4
- package/lib/Cloudflare/Queue/Queue.d.ts.map +1 -1
- package/lib/Cloudflare/Queue/Queue.js +34 -4
- package/lib/Cloudflare/Queue/Queue.js.map +1 -1
- package/lib/Cloudflare/Queue/QueueBinding.d.ts +33 -0
- package/lib/Cloudflare/Queue/QueueBinding.d.ts.map +1 -1
- package/lib/Cloudflare/Queue/QueueBinding.js +33 -0
- package/lib/Cloudflare/Queue/QueueBinding.js.map +1 -1
- 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/DurableObjectNamespace.d.ts +103 -6
- package/lib/Cloudflare/Workers/DurableObjectNamespace.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/DurableObjectNamespace.js +103 -6
- package/lib/Cloudflare/Workers/DurableObjectNamespace.js.map +1 -1
- 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/Workflow.d.ts +94 -0
- package/lib/Cloudflare/Workers/Workflow.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/Workflow.js +94 -0
- package/lib/Cloudflare/Workers/Workflow.js.map +1 -1
- 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/Platform.js +1 -1
- package/lib/Platform.js.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/AWS/Lambda/Function.ts +30 -24
- package/src/AWS/Lambda/HttpServer.ts +3 -1
- 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/Container/Container.ts +55 -2
- package/src/Cloudflare/D1/D1Export.ts +1 -5
- package/src/Cloudflare/D1/D1SqlFile.ts +1 -3
- 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/Queue/Queue.ts +34 -4
- package/src/Cloudflare/Queue/QueueBinding.ts +33 -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/DurableObjectNamespace.ts +103 -6
- 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/Workflow.ts +94 -0
- package/src/Cloudflare/Workers/index.ts +1 -0
- package/src/Platform.ts +2 -2
- 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,14 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as FileSystem from "effect/FileSystem";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Path from "effect/Path";
|
|
5
|
+
import * as AlchemyContext from "../AlchemyContext.ts";
|
|
6
|
+
declare const RpcPaths_base: Context.ServiceClass<RpcPaths, "RpcPaths", {
|
|
7
|
+
readonly lock: string;
|
|
8
|
+
readonly url: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare class RpcPaths extends RpcPaths_base {
|
|
11
|
+
}
|
|
12
|
+
export declare const layer: (main: string) => Layer.Layer<RpcPaths, import("effect/PlatformError").PlatformError, AlchemyContext.AlchemyContext | Path.Path | FileSystem.FileSystem>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=RpcPaths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcPaths.d.ts","sourceRoot":"","sources":["../../src/Sidecar/RpcPaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAE1C,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAC;;mBAIpC,MAAM;kBAAgB,MAAM;;AAF/C,qBAAa,QAAS,SAAQ,aAGf;CAAG;AAElB,eAAO,MAAM,KAAK,GAAI,MAAM,MAAM,2IAe/B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as FileSystem from "effect/FileSystem";
|
|
4
|
+
import * as Hash from "effect/Hash";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import * as Path from "effect/Path";
|
|
7
|
+
import * as AlchemyContext from "../AlchemyContext.js";
|
|
8
|
+
export class RpcPaths extends Context.Service()("RpcPaths") {
|
|
9
|
+
}
|
|
10
|
+
export const layer = (main) => Layer.effect(RpcPaths, Effect.gen(function* () {
|
|
11
|
+
const { dotAlchemy } = yield* AlchemyContext.AlchemyContext;
|
|
12
|
+
const path = yield* Path.Path;
|
|
13
|
+
const fs = yield* FileSystem.FileSystem;
|
|
14
|
+
const id = Math.abs(Hash.string(main));
|
|
15
|
+
const dir = path.resolve(dotAlchemy, "local");
|
|
16
|
+
yield* fs.makeDirectory(dir, { recursive: true });
|
|
17
|
+
return RpcPaths.of({
|
|
18
|
+
lock: path.join(dir, `${id}.lock`),
|
|
19
|
+
url: path.join(dir, `${id}.url`),
|
|
20
|
+
});
|
|
21
|
+
}));
|
|
22
|
+
//# sourceMappingURL=RpcPaths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcPaths.js","sourceRoot":"","sources":["../../src/Sidecar/RpcPaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAC;AAEvD,MAAM,OAAO,QAAS,SAAQ,OAAO,CAAC,OAAO,EAG1C,CAAC,UAAU,CAAC;CAAG;AAElB,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CACpC,KAAK,CAAC,MAAM,CACV,QAAQ,EACR,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC,CAAC,cAAc,CAAC,cAAc,CAAC;IAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;IAC9B,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;IACxC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IACvC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC9C,KAAK,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,OAAO,QAAQ,CAAC,EAAE,CAAC;QACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC;QAClC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC;KACjC,CAAC,CAAC;AACL,CAAC,CAAC,CACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as FileSystem from "effect/FileSystem";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as AlchemyContext from "../AlchemyContext.ts";
|
|
5
|
+
import * as Lock from "./Lock.ts";
|
|
6
|
+
import { type RpcHandlerEncoders, type RpcHandlers } from "./RpcHandler.ts";
|
|
7
|
+
import * as RpcPaths from "./RpcPaths.ts";
|
|
8
|
+
export declare const layerServices: (main: string) => Layer.Layer<AlchemyContext.AlchemyContext | RpcPaths.RpcPaths | Lock.Lock, import("effect/PlatformError").PlatformError, import("effect/Path").Path | FileSystem.FileSystem>;
|
|
9
|
+
export declare const makeRpcServer: <T extends RpcHandlers, E, R>(handlersEffect: Effect.Effect<T, E, R>, schema: RpcHandlerEncoders<T>) => Effect.Effect<void, Lock.LockError, FileSystem.FileSystem | import("effect/Scope").Scope | RpcPaths.RpcPaths | Lock.Lock | R>;
|
|
10
|
+
//# sourceMappingURL=RpcServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcServer.d.ts","sourceRoot":"","sources":["../../src/Sidecar/RpcServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAG1C,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,iLAIvC,CAAC;AAEJ,eAAO,MAAM,aAAa,GAAwB,CAAC,SAAS,WAAW,EAAE,CAAC,EAAE,CAAC,yMAyC3E,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Fiber from "effect/Fiber";
|
|
3
|
+
import * as FileSystem from "effect/FileSystem";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import * as Schedule from "effect/Schedule";
|
|
6
|
+
import * as AlchemyContext from "../AlchemyContext.js";
|
|
7
|
+
import * as Lock from "./Lock.js";
|
|
8
|
+
import { serializeRpcHandlers, } from "./RpcHandler.js";
|
|
9
|
+
import * as RpcPaths from "./RpcPaths.js";
|
|
10
|
+
import { makeBunWebSocketRpcServer } from "./RpcTransport.js";
|
|
11
|
+
export const layerServices = (main) => Layer.provideMerge(Lock.LockLive, Layer.provideMerge(RpcPaths.layer(main), AlchemyContext.AlchemyContextLive));
|
|
12
|
+
export const makeRpcServer = Effect.fn(function* (handlersEffect, schema) {
|
|
13
|
+
const lock = yield* Lock.Lock.use((lock) => lock.acquire);
|
|
14
|
+
const fs = yield* FileSystem.FileSystem;
|
|
15
|
+
const paths = yield* RpcPaths.RpcPaths;
|
|
16
|
+
const server = yield* Effect.gen(function* () {
|
|
17
|
+
const heartbeat = yield* Heartbeat;
|
|
18
|
+
const handlers = yield* handlersEffect;
|
|
19
|
+
const server = yield* Effect.acquireRelease(Effect.sync(() => makeBunWebSocketRpcServer(() => {
|
|
20
|
+
const methods = Object.assign(serializeRpcHandlers(handlers, schema), {
|
|
21
|
+
heartbeat: () => Effect.runPromise(heartbeat.touch),
|
|
22
|
+
shutdown: () => Effect.runPromise(heartbeat.shutdown),
|
|
23
|
+
});
|
|
24
|
+
void methods.heartbeat();
|
|
25
|
+
return methods;
|
|
26
|
+
})), (server) => Effect.promise(() => server.stop(true)));
|
|
27
|
+
const address = `ws://${server.hostname}:${server.port}`;
|
|
28
|
+
yield* fs.writeFileString(paths.url, address);
|
|
29
|
+
yield* Effect.addFinalizer(() => fs.readFileString(paths.url).pipe(Effect.flatMap((text) => text === address ? fs.remove(paths.url) : Effect.void), Effect.ignore));
|
|
30
|
+
yield* heartbeat.await;
|
|
31
|
+
}).pipe(Effect.forkScoped);
|
|
32
|
+
yield* Fiber.joinAll([lock, server]);
|
|
33
|
+
});
|
|
34
|
+
const Heartbeat = Effect.gen(function* () {
|
|
35
|
+
let last = Date.now();
|
|
36
|
+
const fiber = yield* Effect.suspend(() => {
|
|
37
|
+
if (Date.now() - last > 10_000) {
|
|
38
|
+
return Effect.fail({ _tag: "Timeout" });
|
|
39
|
+
}
|
|
40
|
+
return Effect.void;
|
|
41
|
+
}).pipe(Effect.repeat(Schedule.spaced("4 seconds")), Effect.forkScoped);
|
|
42
|
+
return {
|
|
43
|
+
touch: Effect.sync(() => {
|
|
44
|
+
last = Date.now();
|
|
45
|
+
}),
|
|
46
|
+
shutdown: Fiber.interrupt(fiber),
|
|
47
|
+
await: Fiber.join(fiber),
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=RpcServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcServer.js","sourceRoot":"","sources":["../../src/Sidecar/RpcServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,oBAAoB,GAGrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAE9D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,EAAE,CAC5C,KAAK,CAAC,YAAY,CAChB,IAAI,CAAC,QAAQ,EACb,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC,kBAAkB,CAAC,CAC5E,CAAC;AAEJ,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC,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MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;YACtB,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACpB,CAAC,CAAC;QACF,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC;QAChC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;KACzB,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ServerWebSocket } from "bun";
|
|
2
|
+
import type { RpcCompatible, RpcTransport } from "capnweb";
|
|
3
|
+
import { RpcSession } from "capnweb";
|
|
4
|
+
export declare function makeBunWebSocketRpcServer<T extends RpcCompatible<T>>(main: () => T): Bun.Server<{
|
|
5
|
+
transport: BunWebSocketRpcTransport;
|
|
6
|
+
session: RpcSession<T>;
|
|
7
|
+
}>;
|
|
8
|
+
declare class BunWebSocketRpcTransport implements RpcTransport {
|
|
9
|
+
private readonly ws;
|
|
10
|
+
private receiveQueue;
|
|
11
|
+
private receiveResolver?;
|
|
12
|
+
private receiveRejecter?;
|
|
13
|
+
private error?;
|
|
14
|
+
constructor(ws: ServerWebSocket<any>);
|
|
15
|
+
send(message: string): Promise<void>;
|
|
16
|
+
receive(): Promise<string>;
|
|
17
|
+
abort?(reason: any): void;
|
|
18
|
+
dispatchMessage(data: string | Buffer<ArrayBuffer>): void;
|
|
19
|
+
dispatchClose(code: number, reason: string): void;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=RpcTransport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcTransport.d.ts","sourceRoot":"","sources":["../../src/Sidecar/RpcTransport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,aAAa,CAAC,CAAC,CAAC,EAClE,IAAI,EAAE,MAAM,CAAC;eAGA,wBAAwB;aAC1B,UAAU,CAAC,CAAC,CAAC;GAuBzB;AAED,cAAM,wBAAyB,YAAW,YAAY;IAKxC,OAAO,CAAC,QAAQ,CAAC,EAAE;IAJ/B,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,eAAe,CAAC,CAA0B;IAClD,OAAO,CAAC,eAAe,CAAC,CAA4B;IACpD,OAAO,CAAC,KAAK,CAAC,CAAU;gBACK,EAAE,EAAE,eAAe,CAAC,GAAG,CAAC;IAC/C,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAGpC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAYhC,KAAK,CAAC,CAAC,MAAM,EAAE,GAAG,GAAG,IAAI;IAKzB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,IAAI;IAczD,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;CAUlD"}
|
|
@@ -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,CAAC;QACD,SAAS,EAAE;YACT,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE;gBACX,MAAM,SAAS,GAAG,IAAI,wBAAwB,CAAC,EAAE,CAAC,CAAC;gBACnD,MAAM,OAAO,GAAG,IAAI,UAAU,CAAI,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;gBACrD,EAAE,CAAC,IAAI,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;YACnC,CAAC;YACD,OAAO,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE;gBACvB,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;YAC7C,CAAC;YACD,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;gBA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,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAEhE,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAC3B,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;YACjC,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QACnC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IACD,aAAa,CAAC,IAAY,EAAE,MAAc;QACxC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,8BAA8B,IAAI,KAAK,MAAM,EAAE,CAAC,CAAC;YACxE,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;gBACzB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACjC,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;gBACjC,IAAI,CAAC,eAAe,GAAG,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":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC;;;;GAIG;AACH,eAAO,MAAM,eAAe,wBAI1B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,gBAAgB,qCAG3B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,UAAU,wBAGrB,CAAC;AAEH;;;;;;;;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,M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AAE,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,MAAM,eAAe,CAAC;AAExC;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,6BAA6B,EAAE;IAC3E,WAAW,EACT,sEAAsE;IACxE,WAAW,EAAE,IAAI;CAClB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,2BAA2B,EAAE;IACxE,WAAW,EACT,mFAAmF;CACtF,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,yBAAyB,EAAE;IAClE,WAAW,EAAE,4CAA4C;IACzD,WAAW,EAAE,IAAI;CAClB,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACH,MAA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S,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO;CACnD,CAAC,EACF,CAAC,CACF,CACF,CACF,CAAC;AAIN,MAAM,OAAO,GAAG,CAAC,OAAe,EAAqB,EAAE,CACrD,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC;AAEpD,MAAM,aAAa,GAAG,CACpB,SAAoD,EACpD,MAA2B,EAC3B,QAA2B,EACN,EAAE;IACvB,MAAM,KAAK,GAAG,EAAE,GAAG,SAAS,EAAE,MAAM,EAAE,CAAC;IACvC,OAAO,MAAM,CAAC,GAAG,CACf;QACE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;QAC/D,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,gBAAgB,EAAE,KAAK,CAAC,EAAE,QAAQ,CAAC;KACxE,EACD,EAAE,OAAO,EAAE,IAAI,EAAE,CAClB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -5,6 +5,8 @@ import type { Path } from "effect/Path";
|
|
|
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,CAAC;AAI1E,MAAM,MAAM,gBAAgB,GACxB,mBAAmB,GACnB,UAAU,GACV,IAAI,GACJ,KAAK,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"}
|
|
1
|
+
{"version":3,"file":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AAU,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,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"PlatformServices.js","sourceRoot":"","sources":["../../src/Util/PlatformServices.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAUtC,MAAM,KAAK,GAAG,OAAO,GAAG,KAAK,WAAW,CAAC;AAWzC,MAAM,CAAC,MAAM,gBAAgB,GAAkC,MAAM,CAAC,OAAO,CAC3E,KAAK,IAAI,EAAE;IACT,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACjD,MAAM,CAAC,kCAAk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AI,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",
|
|
@@ -23,6 +23,7 @@ import { Platform, type Main, type PlatformProps } from "../../Platform.ts";
|
|
|
23
23
|
import type { LogLine, LogsInput } from "../../Provider.ts";
|
|
24
24
|
import * as Provider from "../../Provider.ts";
|
|
25
25
|
import { Resource, type ResourceBinding } from "../../Resource.ts";
|
|
26
|
+
import { Self } from "../../Self.ts";
|
|
26
27
|
import * as Serverless from "../../Serverless/index.ts";
|
|
27
28
|
import { Stack } from "../../Stack.ts";
|
|
28
29
|
import { createInternalTags, createTagsList, hasTags } from "../../Tags.ts";
|
|
@@ -617,7 +618,6 @@ export const FunctionProvider = () =>
|
|
|
617
618
|
cwd,
|
|
618
619
|
external: [
|
|
619
620
|
/^@aws-sdk\//,
|
|
620
|
-
/^@smithy\//,
|
|
621
621
|
...((props.build?.input?.external as string[]) ?? []),
|
|
622
622
|
],
|
|
623
623
|
platform: "node",
|
|
@@ -627,8 +627,9 @@ export const FunctionProvider = () =>
|
|
|
627
627
|
...props.build?.output,
|
|
628
628
|
format: "esm",
|
|
629
629
|
sourcemap: rolldownSourcemap,
|
|
630
|
-
minify: props.build?.output?.minify ??
|
|
630
|
+
minify: props.build?.output?.minify ?? false,
|
|
631
631
|
entryFileNames: "index.js",
|
|
632
|
+
codeSplitting: props.build?.output?.codeSplitting ?? false,
|
|
632
633
|
},
|
|
633
634
|
);
|
|
634
635
|
});
|
|
@@ -639,30 +640,34 @@ export const FunctionProvider = () =>
|
|
|
639
640
|
realMain,
|
|
640
641
|
virtualEntryPlugin(
|
|
641
642
|
(importPath) => `
|
|
642
|
-
import {
|
|
643
|
+
import { layer as nodeServicesLayer } from "@effect/platform-node/NodeServices";
|
|
643
644
|
import { Stack } from "alchemy/Stack";
|
|
644
645
|
import * as Config from "effect/Config";
|
|
645
646
|
import * as ConfigProvider from "effect/ConfigProvider";
|
|
646
647
|
import * as Credentials from "@distilled.cloud/aws/Credentials";
|
|
647
648
|
import * as Effect from "effect/Effect";
|
|
648
|
-
import
|
|
649
|
+
import { layer as fetchHttpClientLayer } from "effect/unstable/http/FetchHttpClient";
|
|
649
650
|
import * as Layer from "effect/Layer";
|
|
650
651
|
import * as Logger from "effect/Logger";
|
|
651
652
|
import * as Region from "@distilled.cloud/aws/Region";
|
|
652
653
|
import * as Context from "effect/Context";
|
|
653
654
|
import { MinimumLogLevel } from "effect/References";
|
|
654
655
|
|
|
655
|
-
import
|
|
656
|
+
import entry from "${importPath}";
|
|
657
|
+
|
|
658
|
+
const tag = Context.Service("${Self.key}")
|
|
659
|
+
const layer =
|
|
660
|
+
typeof entry?.build === "function"
|
|
661
|
+
? entry
|
|
662
|
+
: Layer.effect(tag, typeof entry?.asEffect === "function" ? entry.asEffect() : entry);
|
|
656
663
|
|
|
657
664
|
const platform = Layer.mergeAll(
|
|
658
|
-
|
|
659
|
-
|
|
665
|
+
nodeServicesLayer,
|
|
666
|
+
fetchHttpClientLayer,
|
|
660
667
|
// TODO(sam): wire this up to telemetry more directly
|
|
661
668
|
Logger.layer([Logger.consolePretty()]),
|
|
662
669
|
);
|
|
663
670
|
|
|
664
|
-
const tag = Context.Service("${FunctionTypeId}<${id}>")
|
|
665
|
-
|
|
666
671
|
const stack = Layer.effect(
|
|
667
672
|
Stack,
|
|
668
673
|
Effect.all([
|
|
@@ -679,7 +684,8 @@ const stack = Layer.effect(
|
|
|
679
684
|
);
|
|
680
685
|
|
|
681
686
|
const handlerEffect = tag.asEffect().pipe(
|
|
682
|
-
Effect.flatMap(func => func.ExecutionContext.exports
|
|
687
|
+
Effect.flatMap(func => func.ExecutionContext.exports),
|
|
688
|
+
Effect.flatMap(exports => exports.handler),
|
|
683
689
|
Effect.provide(
|
|
684
690
|
layer.pipe(
|
|
685
691
|
Layer.provideMerge(stack),
|
|
@@ -714,23 +720,23 @@ export default await Effect.runPromise(handlerEffect)
|
|
|
714
720
|
? new TextEncoder().encode(mainFile.content)
|
|
715
721
|
: mainFile.content;
|
|
716
722
|
|
|
717
|
-
const
|
|
718
|
-
uploadSourceMap && (sourcemap === true || sourcemap === "hidden")
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
+
const includeSourceMaps =
|
|
724
|
+
uploadSourceMap && (sourcemap === true || sourcemap === "hidden");
|
|
725
|
+
|
|
726
|
+
const extraFiles = bundleOutput.files
|
|
727
|
+
.slice(1)
|
|
728
|
+
.filter(
|
|
729
|
+
(f: Bundle.BundleFile) =>
|
|
730
|
+
includeSourceMaps || !f.path.endsWith(".map"),
|
|
731
|
+
)
|
|
732
|
+
.map((f: Bundle.BundleFile) => ({
|
|
733
|
+
path: f.path,
|
|
734
|
+
content: f.content,
|
|
735
|
+
}));
|
|
723
736
|
|
|
724
737
|
const archive = yield* zipCode(
|
|
725
738
|
code,
|
|
726
|
-
|
|
727
|
-
? [
|
|
728
|
-
{
|
|
729
|
-
path: sourceMapFile.path,
|
|
730
|
-
content: sourceMapFile.content,
|
|
731
|
-
},
|
|
732
|
-
]
|
|
733
|
-
: undefined,
|
|
739
|
+
extraFiles.length > 0 ? extraFiles : undefined,
|
|
734
740
|
);
|
|
735
741
|
return {
|
|
736
742
|
archive,
|
|
@@ -19,7 +19,9 @@ export const makeFunctionHttpHandler = <Req>(handler: Http.HttpEffect<Req>) => {
|
|
|
19
19
|
const safeHandler = Http.safeHttpEffect(handler);
|
|
20
20
|
return (event: any) => {
|
|
21
21
|
if (isFunctionURLEvent(event)) {
|
|
22
|
-
const
|
|
22
|
+
const webRequest = toWebRequest(event);
|
|
23
|
+
const request = HttpServerRequest.fromWeb(webRequest).modify({
|
|
24
|
+
url: webRequest.url,
|
|
23
25
|
remoteAddress: Option.some(event.requestContext.http.sourceIp),
|
|
24
26
|
});
|
|
25
27
|
return safeHandler.pipe(
|
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
|
);
|