alchemy 2.0.0-beta.34 → 2.0.0-beta.35
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 +8 -7
- package/bin/exec.js +226 -52
- package/bin/exec.js.map +1 -1
- package/lib/AWS/AuthProvider.d.ts +7 -6
- package/lib/AWS/AuthProvider.d.ts.map +1 -1
- package/lib/AWS/AuthProvider.js +143 -134
- package/lib/AWS/AuthProvider.js.map +1 -1
- package/lib/AWS/Bootstrap.d.ts +2 -2
- package/lib/AWS/Bootstrap.d.ts.map +1 -1
- package/lib/AWS/EC2/hosted.d.ts +1 -1
- package/lib/AWS/Environment.d.ts +25 -3
- package/lib/AWS/Environment.d.ts.map +1 -1
- package/lib/AWS/Environment.js +47 -3
- package/lib/AWS/Environment.js.map +1 -1
- package/lib/AWS/IAM/OpenIDConnectProvider.d.ts +14 -6
- package/lib/AWS/IAM/OpenIDConnectProvider.d.ts.map +1 -1
- package/lib/AWS/IAM/OpenIDConnectProvider.js +6 -3
- package/lib/AWS/IAM/OpenIDConnectProvider.js.map +1 -1
- package/lib/AWS/IAM/Policy.d.ts +1 -1
- package/lib/AWS/IAM/Policy.d.ts.map +1 -1
- package/lib/AWS/IAM/Policy.js.map +1 -1
- package/lib/AWS/Lambda/BucketEventSource.d.ts +1 -1
- package/lib/AWS/Lambda/BucketEventSource.d.ts.map +1 -1
- package/lib/AWS/Lambda/EventBridgeEventSource.d.ts +1 -1
- package/lib/AWS/Lambda/EventBridgeEventSource.d.ts.map +1 -1
- package/lib/AWS/Lambda/QueueEventSource.d.ts +1 -1
- package/lib/AWS/Lambda/QueueEventSource.d.ts.map +1 -1
- package/lib/AWS/Lambda/StreamEventSource.d.ts +1 -1
- package/lib/AWS/Lambda/StreamEventSource.d.ts.map +1 -1
- package/lib/AWS/Lambda/TableEventSource.d.ts +1 -1
- package/lib/AWS/Lambda/TableEventSource.d.ts.map +1 -1
- package/lib/AWS/Lambda/TopicEventSource.d.ts +1 -1
- package/lib/AWS/Lambda/TopicEventSource.d.ts.map +1 -1
- package/lib/AWS/Providers.d.ts +1 -1
- package/lib/AWS/Providers.d.ts.map +1 -1
- package/lib/AWS/Providers.js +2 -1
- package/lib/AWS/Providers.js.map +1 -1
- package/lib/Auth/Credentials.d.ts +21 -6
- package/lib/Auth/Credentials.d.ts.map +1 -1
- package/lib/Auth/Credentials.js +30 -31
- package/lib/Auth/Credentials.js.map +1 -1
- package/lib/Auth/Profile.d.ts +31 -34
- package/lib/Auth/Profile.d.ts.map +1 -1
- package/lib/Auth/Profile.js +46 -31
- package/lib/Auth/Profile.js.map +1 -1
- package/lib/Axiom/AuthProvider.d.ts +2 -1
- package/lib/Axiom/AuthProvider.d.ts.map +1 -1
- package/lib/Axiom/AuthProvider.js +149 -143
- package/lib/Axiom/AuthProvider.js.map +1 -1
- package/lib/Axiom/Credentials.d.ts +2 -1
- package/lib/Axiom/Credentials.d.ts.map +1 -1
- package/lib/Axiom/Credentials.js +4 -4
- package/lib/Axiom/Credentials.js.map +1 -1
- package/lib/Axiom/Providers.d.ts +1 -1
- package/lib/Axiom/Providers.d.ts.map +1 -1
- package/lib/Axiom/Providers.js +3 -1
- package/lib/Axiom/Providers.js.map +1 -1
- package/lib/Cli/LoggingCli.d.ts.map +1 -1
- package/lib/Cli/LoggingCli.js +105 -7
- package/lib/Cli/LoggingCli.js.map +1 -1
- package/lib/Cli/checkVersion.d.ts +13 -0
- package/lib/Cli/checkVersion.d.ts.map +1 -0
- package/lib/Cli/checkVersion.js +47 -0
- package/lib/Cli/checkVersion.js.map +1 -0
- package/lib/Cli/commands/_shared.d.ts +2 -2
- package/lib/Cli/commands/_shared.d.ts.map +1 -1
- package/lib/Cli/commands/_shared.js +3 -3
- package/lib/Cli/commands/_shared.js.map +1 -1
- package/lib/Cli/commands/aws.d.ts +6 -0
- package/lib/Cli/commands/aws.d.ts.map +1 -0
- package/lib/Cli/commands/aws.js +63 -0
- package/lib/Cli/commands/aws.js.map +1 -0
- package/lib/Cli/commands/cloudflare.d.ts +17 -0
- package/lib/Cli/commands/cloudflare.d.ts.map +1 -0
- package/lib/Cli/commands/cloudflare.js +111 -0
- package/lib/Cli/commands/cloudflare.js.map +1 -0
- package/lib/Cli/commands/deploy.d.ts +6 -5
- package/lib/Cli/commands/deploy.d.ts.map +1 -1
- package/lib/Cli/commands/deploy.js +10 -10
- package/lib/Cli/commands/deploy.js.map +1 -1
- package/lib/Cli/commands/dev.d.ts.map +1 -1
- package/lib/Cli/commands/dev.js +16 -16
- package/lib/Cli/commands/dev.js.map +1 -1
- package/lib/Cli/commands/login.d.ts +2 -1
- package/lib/Cli/commands/login.d.ts.map +1 -1
- package/lib/Cli/commands/login.js +9 -8
- package/lib/Cli/commands/login.js.map +1 -1
- package/lib/Cli/commands/logs.d.ts +1 -1
- package/lib/Cli/commands/logs.d.ts.map +1 -1
- package/lib/Cli/commands/logs.js +7 -7
- package/lib/Cli/commands/logs.js.map +1 -1
- package/lib/Cli/commands/profile.d.ts +3 -1
- package/lib/Cli/commands/profile.d.ts.map +1 -1
- package/lib/Cli/commands/profile.js +14 -11
- package/lib/Cli/commands/profile.js.map +1 -1
- package/lib/Cli/commands/state.d.ts +1 -1
- package/lib/Cli/commands/state.d.ts.map +1 -1
- package/lib/Cli/commands/state.js +8 -8
- package/lib/Cli/commands/state.js.map +1 -1
- package/lib/Cli/commands/tail.d.ts +1 -1
- package/lib/Cli/commands/tail.d.ts.map +1 -1
- package/lib/Cli/commands/tail.js +7 -7
- package/lib/Cli/commands/tail.js.map +1 -1
- package/lib/Cli/exec.d.ts.map +1 -1
- package/lib/Cli/exec.js +5 -3
- package/lib/Cli/exec.js.map +1 -1
- package/lib/Cli/main.d.ts.map +1 -1
- package/lib/Cli/main.js +17 -5
- package/lib/Cli/main.js.map +1 -1
- package/lib/Cli/selectCli.d.ts +12 -0
- package/lib/Cli/selectCli.d.ts.map +1 -0
- package/lib/Cli/selectCli.js +32 -0
- package/lib/Cli/selectCli.js.map +1 -0
- package/lib/Cloudflare/Auth/AuthProvider.d.ts +2 -1
- package/lib/Cloudflare/Auth/AuthProvider.d.ts.map +1 -1
- package/lib/Cloudflare/Auth/AuthProvider.js +235 -214
- package/lib/Cloudflare/Auth/AuthProvider.js.map +1 -1
- package/lib/Cloudflare/CloudflareEnvironment.d.ts +2 -1
- package/lib/Cloudflare/CloudflareEnvironment.d.ts.map +1 -1
- package/lib/Cloudflare/CloudflareEnvironment.js +3 -2
- package/lib/Cloudflare/CloudflareEnvironment.js.map +1 -1
- package/lib/Cloudflare/Credentials.d.ts +2 -1
- package/lib/Cloudflare/Credentials.d.ts.map +1 -1
- package/lib/Cloudflare/Credentials.js +4 -4
- package/lib/Cloudflare/Credentials.js.map +1 -1
- package/lib/Cloudflare/D1/D1Clone.d.ts +2 -1
- package/lib/Cloudflare/D1/D1Clone.d.ts.map +1 -1
- package/lib/Cloudflare/D1/D1Database.d.ts +2 -1
- package/lib/Cloudflare/D1/D1Database.d.ts.map +1 -1
- package/lib/Cloudflare/D1/D1Import.d.ts +3 -1
- package/lib/Cloudflare/D1/D1Import.d.ts.map +1 -1
- package/lib/Cloudflare/Local/Sidecar.d.ts +11 -4
- package/lib/Cloudflare/Local/Sidecar.d.ts.map +1 -1
- package/lib/Cloudflare/Local/Sidecar.js +8 -6
- package/lib/Cloudflare/Local/Sidecar.js.map +1 -1
- package/lib/Cloudflare/Local/SidecarHandlers.d.ts.map +1 -1
- package/lib/Cloudflare/Local/SidecarHandlers.js +1 -5
- package/lib/Cloudflare/Local/SidecarHandlers.js.map +1 -1
- package/lib/Cloudflare/Local/SidecarServer.js +5 -2
- package/lib/Cloudflare/Local/SidecarServer.js.map +1 -1
- package/lib/Cloudflare/Logs.d.ts +5 -0
- package/lib/Cloudflare/Logs.d.ts.map +1 -1
- package/lib/Cloudflare/Logs.js +70 -1
- package/lib/Cloudflare/Logs.js.map +1 -1
- package/lib/Cloudflare/Providers.d.ts +1 -1
- package/lib/Cloudflare/Providers.d.ts.map +1 -1
- package/lib/Cloudflare/Providers.js +4 -1
- package/lib/Cloudflare/Providers.js.map +1 -1
- package/lib/Cloudflare/Queue/Queue.d.ts +1 -1
- package/lib/Cloudflare/Queue/Queue.js +1 -1
- package/lib/Cloudflare/Queue/QueueConsumer.d.ts +6 -2
- package/lib/Cloudflare/Queue/QueueConsumer.d.ts.map +1 -1
- package/lib/Cloudflare/Queue/QueueConsumer.js +194 -53
- package/lib/Cloudflare/Queue/QueueConsumer.js.map +1 -1
- package/lib/Cloudflare/Queue/QueueEventSource.d.ts +106 -0
- package/lib/Cloudflare/Queue/QueueEventSource.d.ts.map +1 -0
- package/lib/Cloudflare/Queue/QueueEventSource.js +145 -0
- package/lib/Cloudflare/Queue/QueueEventSource.js.map +1 -0
- package/lib/Cloudflare/Queue/index.d.ts +1 -0
- package/lib/Cloudflare/Queue/index.d.ts.map +1 -1
- package/lib/Cloudflare/Queue/index.js +1 -0
- package/lib/Cloudflare/Queue/index.js.map +1 -1
- package/lib/Cloudflare/R2/R2Bucket.d.ts +94 -0
- package/lib/Cloudflare/R2/R2Bucket.d.ts.map +1 -1
- package/lib/Cloudflare/R2/R2Bucket.js +186 -2
- package/lib/Cloudflare/R2/R2Bucket.js.map +1 -1
- package/lib/Cloudflare/StateStore/State.d.ts +4 -3
- package/lib/Cloudflare/StateStore/State.d.ts.map +1 -1
- package/lib/Cloudflare/StateStore/State.js +16 -8
- package/lib/Cloudflare/StateStore/State.js.map +1 -1
- package/lib/Cloudflare/VpcService/VpcServiceRef.d.ts +1 -1
- package/lib/Cloudflare/VpcService/VpcServiceRef.d.ts.map +1 -1
- package/lib/Cloudflare/Website/StaticSite.d.ts.map +1 -1
- package/lib/Cloudflare/Website/StaticSite.js +10 -1
- package/lib/Cloudflare/Website/StaticSite.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/LocalWorkerProvider.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/LocalWorkerProvider.js +11 -1
- package/lib/Cloudflare/Workers/LocalWorkerProvider.js.map +1 -1
- package/lib/Cloudflare/Workers/Worker.d.ts +9 -7
- package/lib/Cloudflare/Workers/Worker.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/Worker.js +62 -142
- package/lib/Cloudflare/Workers/Worker.js.map +1 -1
- package/lib/Cloudflare/Workers/WorkerBundle.d.ts +2 -0
- package/lib/Cloudflare/Workers/WorkerBundle.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/WorkerBundle.js +21 -7
- package/lib/Cloudflare/Workers/WorkerBundle.js.map +1 -1
- package/lib/Cloudflare/Zone.d.ts +14 -0
- package/lib/Cloudflare/Zone.d.ts.map +1 -0
- package/lib/Cloudflare/Zone.js +44 -0
- package/lib/Cloudflare/Zone.js.map +1 -0
- package/lib/Drizzle/Schema.d.ts.map +1 -1
- package/lib/Drizzle/Schema.js +20 -5
- package/lib/Drizzle/Schema.js.map +1 -1
- package/lib/GitHub/AuthProvider.d.ts +3 -1
- package/lib/GitHub/AuthProvider.d.ts.map +1 -1
- package/lib/GitHub/AuthProvider.js +114 -108
- package/lib/GitHub/AuthProvider.js.map +1 -1
- package/lib/GitHub/Credentials.d.ts +2 -1
- package/lib/GitHub/Credentials.d.ts.map +1 -1
- package/lib/GitHub/Credentials.js +4 -4
- package/lib/GitHub/Credentials.js.map +1 -1
- package/lib/GitHub/Providers.d.ts +1 -1
- package/lib/GitHub/Providers.d.ts.map +1 -1
- package/lib/GitHub/Providers.js +3 -1
- package/lib/GitHub/Providers.js.map +1 -1
- package/lib/GitHub/Secrets.d.ts.map +1 -1
- package/lib/GitHub/Secrets.js +14 -1
- package/lib/GitHub/Secrets.js.map +1 -1
- package/lib/GitHub/Variables.d.ts +40 -0
- package/lib/GitHub/Variables.d.ts.map +1 -0
- package/lib/GitHub/Variables.js +28 -0
- package/lib/GitHub/Variables.js.map +1 -0
- package/lib/GitHub/index.d.ts +1 -0
- package/lib/GitHub/index.d.ts.map +1 -1
- package/lib/GitHub/index.js +1 -0
- package/lib/GitHub/index.js.map +1 -1
- package/lib/Neon/AuthProvider.d.ts +3 -1
- package/lib/Neon/AuthProvider.d.ts.map +1 -1
- package/lib/Neon/AuthProvider.js +87 -80
- package/lib/Neon/AuthProvider.js.map +1 -1
- package/lib/Neon/Credentials.d.ts +2 -1
- package/lib/Neon/Credentials.d.ts.map +1 -1
- package/lib/Neon/Credentials.js +4 -4
- package/lib/Neon/Credentials.js.map +1 -1
- package/lib/Neon/NeonEnvironment.d.ts +2 -1
- package/lib/Neon/NeonEnvironment.d.ts.map +1 -1
- package/lib/Neon/NeonEnvironment.js +3 -2
- package/lib/Neon/NeonEnvironment.js.map +1 -1
- package/lib/Neon/Project.d.ts +16 -0
- package/lib/Neon/Project.d.ts.map +1 -1
- package/lib/Neon/Project.js +25 -0
- package/lib/Neon/Project.js.map +1 -1
- package/lib/Neon/Providers.d.ts +1 -1
- package/lib/Neon/Providers.d.ts.map +1 -1
- package/lib/Neon/Providers.js +3 -1
- package/lib/Neon/Providers.js.map +1 -1
- package/lib/Neon/api.d.ts +1 -0
- package/lib/Neon/api.d.ts.map +1 -1
- package/lib/Neon/api.js +1 -0
- package/lib/Neon/api.js.map +1 -1
- package/lib/Sidecar/RpcClient.d.ts.map +1 -1
- package/lib/Sidecar/RpcClient.js +8 -5
- package/lib/Sidecar/RpcClient.js.map +1 -1
- package/lib/Sidecar/RpcPaths.d.ts +5 -0
- package/lib/Sidecar/RpcPaths.d.ts.map +1 -1
- package/lib/Sidecar/RpcPaths.js +10 -1
- package/lib/Sidecar/RpcPaths.js.map +1 -1
- package/lib/Sidecar/RpcServer.d.ts +24 -4
- package/lib/Sidecar/RpcServer.d.ts.map +1 -1
- package/lib/Sidecar/RpcServer.js +70 -15
- package/lib/Sidecar/RpcServer.js.map +1 -1
- package/lib/Sidecar/RpcServerBun.d.ts +4 -0
- package/lib/Sidecar/RpcServerBun.d.ts.map +1 -0
- package/lib/Sidecar/RpcServerBun.js +28 -0
- package/lib/Sidecar/RpcServerBun.js.map +1 -0
- package/lib/Sidecar/RpcServerNode.d.ts +4 -0
- package/lib/Sidecar/RpcServerNode.d.ts.map +1 -0
- package/lib/Sidecar/RpcServerNode.js +39 -0
- package/lib/Sidecar/RpcServerNode.js.map +1 -0
- package/lib/Sidecar/RpcServices.d.ts +6 -0
- package/lib/Sidecar/RpcServices.d.ts.map +1 -0
- package/lib/Sidecar/RpcServices.js +29 -0
- package/lib/Sidecar/RpcServices.js.map +1 -0
- package/lib/Stack.d.ts +5 -3
- package/lib/Stack.d.ts.map +1 -1
- package/lib/Stack.js +3 -1
- package/lib/Stack.js.map +1 -1
- package/lib/Test/Core.d.ts.map +1 -1
- package/lib/Test/Core.js +5 -4
- package/lib/Test/Core.js.map +1 -1
- package/lib/Util/PlatformServices.js +1 -1
- package/lib/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +15 -12
- package/src/AWS/AuthProvider.ts +269 -259
- package/src/AWS/Environment.ts +57 -3
- package/src/AWS/IAM/OpenIDConnectProvider.ts +19 -8
- package/src/AWS/IAM/Policy.ts +1 -1
- package/src/AWS/Providers.ts +2 -0
- package/src/Auth/Credentials.ts +82 -46
- package/src/Auth/Profile.ts +123 -69
- package/src/Axiom/AuthProvider.ts +263 -255
- package/src/Axiom/Credentials.ts +3 -4
- package/src/Axiom/Providers.ts +4 -0
- package/src/Cli/LoggingCli.ts +127 -11
- package/src/Cli/checkVersion.ts +57 -0
- package/src/Cli/commands/_shared.ts +4 -4
- package/src/Cli/commands/aws.ts +127 -0
- package/src/Cli/commands/cloudflare.ts +222 -0
- package/src/Cli/commands/deploy.ts +11 -10
- package/src/Cli/commands/dev.ts +28 -33
- package/src/Cli/commands/login.ts +9 -12
- package/src/Cli/commands/logs.ts +8 -8
- package/src/Cli/commands/profile.ts +14 -16
- package/src/Cli/commands/state.ts +8 -8
- package/src/Cli/commands/tail.ts +8 -8
- package/src/Cli/exec.ts +7 -3
- package/src/Cli/main.ts +20 -5
- package/src/Cli/selectCli.ts +33 -0
- package/src/Cloudflare/Auth/AuthProvider.ts +445 -430
- package/src/Cloudflare/CloudflareEnvironment.ts +3 -2
- package/src/Cloudflare/Credentials.ts +3 -4
- package/src/Cloudflare/Local/Sidecar.ts +13 -10
- package/src/Cloudflare/Local/SidecarHandlers.ts +8 -13
- package/src/Cloudflare/Local/SidecarServer.ts +6 -1
- package/src/Cloudflare/Logs.ts +115 -1
- package/src/Cloudflare/Providers.ts +6 -0
- package/src/Cloudflare/Queue/Queue.ts +1 -1
- package/src/Cloudflare/Queue/QueueConsumer.ts +262 -60
- package/src/Cloudflare/Queue/QueueEventSource.ts +234 -0
- package/src/Cloudflare/Queue/index.ts +1 -0
- package/src/Cloudflare/R2/R2Bucket.ts +337 -2
- package/src/Cloudflare/StateStore/State.ts +25 -16
- package/src/Cloudflare/Website/StaticSite.ts +11 -1
- package/src/Cloudflare/Workers/LocalWorkerProvider.ts +9 -1
- package/src/Cloudflare/Workers/Worker.ts +83 -203
- package/src/Cloudflare/Workers/WorkerBundle.ts +38 -12
- package/src/Cloudflare/Zone.ts +88 -0
- package/src/Drizzle/Schema.ts +21 -5
- package/src/GitHub/AuthProvider.ts +221 -217
- package/src/GitHub/Credentials.ts +3 -4
- package/src/GitHub/Providers.ts +4 -0
- package/src/GitHub/Secrets.ts +25 -1
- package/src/GitHub/Variables.ts +54 -0
- package/src/GitHub/index.ts +1 -0
- package/src/Neon/AuthProvider.ts +160 -154
- package/src/Neon/Credentials.ts +3 -4
- package/src/Neon/NeonEnvironment.ts +3 -2
- package/src/Neon/Project.ts +42 -0
- package/src/Neon/Providers.ts +4 -0
- package/src/Neon/api.ts +2 -0
- package/src/Sidecar/RpcClient.ts +8 -7
- package/src/Sidecar/RpcPaths.ts +11 -1
- package/src/Sidecar/RpcServer.ts +97 -24
- package/src/Sidecar/RpcServerBun.ts +41 -0
- package/src/Sidecar/RpcServerNode.ts +51 -0
- package/src/Sidecar/RpcServices.ts +48 -0
- package/src/Stack.ts +8 -0
- package/src/Test/Core.ts +10 -4
- package/src/Util/PlatformServices.ts +1 -1
- package/lib/Cli/commands/bootstrap.d.ts +0 -20
- package/lib/Cli/commands/bootstrap.d.ts.map +0 -1
- package/lib/Cli/commands/bootstrap.js +0 -107
- package/lib/Cli/commands/bootstrap.js.map +0 -1
- package/lib/Sidecar/RpcTransport.d.ts +0 -22
- package/lib/Sidecar/RpcTransport.d.ts.map +0 -1
- package/lib/Sidecar/RpcTransport.js +0 -81
- package/lib/Sidecar/RpcTransport.js.map +0 -1
- package/lib/Test/TestCli.d.ts +0 -19
- package/lib/Test/TestCli.d.ts.map +0 -1
- package/lib/Test/TestCli.js +0 -175
- package/lib/Test/TestCli.js.map +0 -1
- package/src/Cli/commands/bootstrap.ts +0 -216
- package/src/Sidecar/RpcTransport.ts +0 -85
- package/src/Test/TestCli.ts +0 -221
package/src/Sidecar/RpcPaths.ts
CHANGED
|
@@ -4,6 +4,7 @@ import * as FileSystem from "effect/FileSystem";
|
|
|
4
4
|
import * as Hash from "effect/Hash";
|
|
5
5
|
import * as Layer from "effect/Layer";
|
|
6
6
|
import * as Path from "effect/Path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
7
8
|
import * as AlchemyContext from "../AlchemyContext.ts";
|
|
8
9
|
|
|
9
10
|
export class RpcPaths extends Context.Service<
|
|
@@ -18,7 +19,7 @@ export const layer = (main: string) =>
|
|
|
18
19
|
const { dotAlchemy } = yield* AlchemyContext.AlchemyContext;
|
|
19
20
|
const path = yield* Path.Path;
|
|
20
21
|
const fs = yield* FileSystem.FileSystem;
|
|
21
|
-
const id = Math.abs(Hash.string(main));
|
|
22
|
+
const id = Math.abs(Hash.string(sanitizeSidecarMain(main)));
|
|
22
23
|
const dir = path.resolve(dotAlchemy, "local");
|
|
23
24
|
yield* fs.makeDirectory(dir, { recursive: true });
|
|
24
25
|
return RpcPaths.of({
|
|
@@ -27,3 +28,12 @@ export const layer = (main: string) =>
|
|
|
27
28
|
});
|
|
28
29
|
}),
|
|
29
30
|
);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The sidecar main file is provided using `import.meta.resolve("./SidecarServer.ts", import.meta.url)`.
|
|
34
|
+
* This changes the extension to .js if you're currently running in js.
|
|
35
|
+
*/
|
|
36
|
+
export const sanitizeSidecarMain = (url: string) => {
|
|
37
|
+
const main = fileURLToPath(url);
|
|
38
|
+
return import.meta.url.endsWith(".js") ? main.replace(".ts", ".js") : main;
|
|
39
|
+
};
|
package/src/Sidecar/RpcServer.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { RpcSession, type RpcCompatible, type RpcTransport } from "capnweb";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
1
3
|
import * as Effect from "effect/Effect";
|
|
2
4
|
import * as Fiber from "effect/Fiber";
|
|
3
5
|
import * as FileSystem from "effect/FileSystem";
|
|
4
|
-
import * as Layer from "effect/Layer";
|
|
5
6
|
import * as Schedule from "effect/Schedule";
|
|
6
|
-
import * as
|
|
7
|
+
import type * as Scope from "effect/Scope";
|
|
7
8
|
import * as Lock from "./Lock.ts";
|
|
8
9
|
import {
|
|
9
10
|
serializeRpcHandlers,
|
|
@@ -11,13 +12,21 @@ import {
|
|
|
11
12
|
type RpcHandlers,
|
|
12
13
|
} from "./RpcHandler.ts";
|
|
13
14
|
import * as RpcPaths from "./RpcPaths.ts";
|
|
14
|
-
import { makeBunWebSocketRpcServer } from "./RpcTransport.ts";
|
|
15
15
|
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
export class RpcServer extends Context.Service<
|
|
17
|
+
RpcServer,
|
|
18
|
+
{
|
|
19
|
+
make: <T extends RpcCompatible<T>>(
|
|
20
|
+
main: () => T,
|
|
21
|
+
) => Effect.Effect<
|
|
22
|
+
{
|
|
23
|
+
readonly url: string;
|
|
24
|
+
},
|
|
25
|
+
never,
|
|
26
|
+
Scope.Scope
|
|
27
|
+
>;
|
|
28
|
+
}
|
|
29
|
+
>()("RpcServer") {}
|
|
21
30
|
|
|
22
31
|
export const makeRpcServer = Effect.fn(function* <T extends RpcHandlers, E, R>(
|
|
23
32
|
handlersEffect: Effect.Effect<T, E, R>,
|
|
@@ -30,28 +39,19 @@ export const makeRpcServer = Effect.fn(function* <T extends RpcHandlers, E, R>(
|
|
|
30
39
|
const server = yield* Effect.gen(function* () {
|
|
31
40
|
const heartbeat = yield* Heartbeat;
|
|
32
41
|
const handlers = yield* handlersEffect;
|
|
33
|
-
const server = yield*
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
{
|
|
39
|
-
heartbeat: () => Effect.runPromise(heartbeat.touch),
|
|
40
|
-
shutdown: () => Effect.runPromise(heartbeat.shutdown),
|
|
41
|
-
},
|
|
42
|
-
);
|
|
43
|
-
void methods.heartbeat();
|
|
44
|
-
return methods;
|
|
42
|
+
const server = yield* RpcServer.use((server) =>
|
|
43
|
+
server.make(() =>
|
|
44
|
+
Object.assign(serializeRpcHandlers(handlers, schema), {
|
|
45
|
+
heartbeat: () => Effect.runPromise(heartbeat.touch),
|
|
46
|
+
shutdown: () => Effect.runPromise(heartbeat.shutdown),
|
|
45
47
|
}),
|
|
46
48
|
),
|
|
47
|
-
(server) => Effect.promise(() => server.stop(true)),
|
|
48
49
|
);
|
|
49
|
-
|
|
50
|
-
yield* fs.writeFileString(paths.url, address);
|
|
50
|
+
yield* fs.writeFileString(paths.url, server.url);
|
|
51
51
|
yield* Effect.addFinalizer(() =>
|
|
52
52
|
fs.readFileString(paths.url).pipe(
|
|
53
53
|
Effect.flatMap((text) =>
|
|
54
|
-
text ===
|
|
54
|
+
text === server.url ? fs.remove(paths.url) : Effect.void,
|
|
55
55
|
),
|
|
56
56
|
Effect.ignore,
|
|
57
57
|
),
|
|
@@ -78,3 +78,76 @@ const Heartbeat = Effect.gen(function* () {
|
|
|
78
78
|
await: Fiber.join(fiber),
|
|
79
79
|
};
|
|
80
80
|
});
|
|
81
|
+
|
|
82
|
+
interface ServerWebSocketLike {
|
|
83
|
+
send: (message: string) => any | Promise<any>;
|
|
84
|
+
close: (code?: number, reason?: string) => void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type WebSocketRpcSession<T extends RpcCompatible<T>> = ReturnType<
|
|
88
|
+
typeof makeWebSocketRpcSession<T>
|
|
89
|
+
>;
|
|
90
|
+
|
|
91
|
+
export function makeWebSocketRpcSession<T extends RpcCompatible<T>>(
|
|
92
|
+
ws: ServerWebSocketLike,
|
|
93
|
+
main: () => T,
|
|
94
|
+
) {
|
|
95
|
+
const { transport, dispatch } = makeWebSocketRpcTransport(ws);
|
|
96
|
+
const session = new RpcSession(transport, main());
|
|
97
|
+
return { session, dispatch };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function makeWebSocketRpcTransport(ws: ServerWebSocketLike) {
|
|
101
|
+
let receiveQueue: Array<string> = [];
|
|
102
|
+
let receiveResolver: ((value: string) => void) | undefined;
|
|
103
|
+
let receiveRejecter: ((reason: unknown) => void) | undefined;
|
|
104
|
+
let error: unknown | undefined;
|
|
105
|
+
return {
|
|
106
|
+
transport: {
|
|
107
|
+
send: async (message: string) => await ws.send(message),
|
|
108
|
+
receive: async () => {
|
|
109
|
+
const next = receiveQueue.shift();
|
|
110
|
+
if (next) {
|
|
111
|
+
return next;
|
|
112
|
+
} else if (error) {
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
return new Promise<string>((resolve, reject) => {
|
|
116
|
+
receiveResolver = resolve;
|
|
117
|
+
receiveRejecter = reject;
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
abort: (reason: unknown) => {
|
|
121
|
+
const message =
|
|
122
|
+
reason instanceof Error ? reason.message : String(reason);
|
|
123
|
+
ws.close(3000, message);
|
|
124
|
+
error ??= reason;
|
|
125
|
+
},
|
|
126
|
+
} satisfies RpcTransport,
|
|
127
|
+
dispatch: {
|
|
128
|
+
message: (data: string | Buffer<ArrayBuffer>) => {
|
|
129
|
+
if (error) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
data = typeof data === "string" ? data : data.toString("utf-8");
|
|
133
|
+
if (receiveResolver) {
|
|
134
|
+
receiveResolver(data);
|
|
135
|
+
receiveResolver = undefined;
|
|
136
|
+
receiveRejecter = undefined;
|
|
137
|
+
} else {
|
|
138
|
+
receiveQueue.push(data);
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
close: (code: number, reason: string) => {
|
|
142
|
+
if (!error) {
|
|
143
|
+
error = new Error(`WebSocket closed with code ${code}: ${reason}`);
|
|
144
|
+
if (receiveRejecter) {
|
|
145
|
+
receiveRejecter(error);
|
|
146
|
+
receiveRejecter = undefined;
|
|
147
|
+
receiveResolver = undefined;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { RpcCompatible } from "capnweb";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import type { WebSocketRpcSession } from "./RpcServer.ts";
|
|
5
|
+
import { makeWebSocketRpcSession, RpcServer } from "./RpcServer.ts";
|
|
6
|
+
|
|
7
|
+
export const RpcServerBun = Layer.succeed(
|
|
8
|
+
RpcServer,
|
|
9
|
+
RpcServer.of({
|
|
10
|
+
make: <T extends RpcCompatible<T>>(main: () => T) =>
|
|
11
|
+
Effect.acquireRelease(
|
|
12
|
+
Effect.sync(() =>
|
|
13
|
+
Bun.serve<WebSocketRpcSession<T>>({
|
|
14
|
+
port: 0,
|
|
15
|
+
fetch: (request, server) => {
|
|
16
|
+
if (server.upgrade(request, { data: undefined! })) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
return new Response("Upgrade failed", { status: 400 });
|
|
20
|
+
},
|
|
21
|
+
websocket: {
|
|
22
|
+
open: (ws) => {
|
|
23
|
+
ws.data = makeWebSocketRpcSession(ws, main);
|
|
24
|
+
},
|
|
25
|
+
message: (ws, message) => {
|
|
26
|
+
ws.data.dispatch.message(message);
|
|
27
|
+
},
|
|
28
|
+
close: (ws, code, reason) => {
|
|
29
|
+
ws.data.dispatch.close(code, reason);
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
),
|
|
34
|
+
(server) => Effect.sync(() => server.stop(true)),
|
|
35
|
+
).pipe(
|
|
36
|
+
Effect.map((server) => ({
|
|
37
|
+
url: `ws://${server.hostname}:${server.port}`,
|
|
38
|
+
})),
|
|
39
|
+
),
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Layer from "effect/Layer";
|
|
3
|
+
import { WebSocketServer, type Server } from "ws";
|
|
4
|
+
import { makeWebSocketRpcSession, RpcServer } from "./RpcServer.ts";
|
|
5
|
+
|
|
6
|
+
export const RpcServerNode = Layer.succeed(
|
|
7
|
+
RpcServer,
|
|
8
|
+
RpcServer.of({
|
|
9
|
+
make: Effect.fnUntraced(function* (main) {
|
|
10
|
+
const server = new WebSocketServer({ host: "127.0.0.1", port: 0 });
|
|
11
|
+
const url = yield* Effect.callback<string>((resume) => {
|
|
12
|
+
server.on("connection", (ws) => {
|
|
13
|
+
const session = makeWebSocketRpcSession(ws, main);
|
|
14
|
+
ws.on("message", (data) => {
|
|
15
|
+
session.dispatch.message(data.toString());
|
|
16
|
+
});
|
|
17
|
+
ws.on("close", (code, reason) => {
|
|
18
|
+
session.dispatch.close(code, reason.toString());
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
server.on("error", (error) => {
|
|
22
|
+
resume(Effect.die(error));
|
|
23
|
+
});
|
|
24
|
+
server.on("listening", () => {
|
|
25
|
+
resume(getServerAddress(server));
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => server.close()));
|
|
29
|
+
return { url };
|
|
30
|
+
}),
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
function getServerAddress(server: Server): Effect.Effect<string> {
|
|
35
|
+
const address = server.address();
|
|
36
|
+
if (
|
|
37
|
+
typeof address === "object" &&
|
|
38
|
+
address !== null &&
|
|
39
|
+
"address" in address &&
|
|
40
|
+
"port" in address
|
|
41
|
+
) {
|
|
42
|
+
return Effect.succeed(
|
|
43
|
+
`ws://${address.address === "::" ? "localhost" : address.address}:${address.port}`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
return Effect.die(
|
|
47
|
+
new Error(
|
|
48
|
+
`Server address is not an object with address and port properties: ${JSON.stringify(address)}`,
|
|
49
|
+
),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as ConfigProvider from "effect/ConfigProvider";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
5
|
+
import * as AlchemyContext from "../AlchemyContext.ts";
|
|
6
|
+
import { withProfileOverride } from "../Auth/Profile.ts";
|
|
7
|
+
import type { ExecStackOptionsEncoded } from "../Cli/commands/deploy.ts";
|
|
8
|
+
import { loadConfigProvider } from "../Util/ConfigProvider.ts";
|
|
9
|
+
import * as Lock from "./Lock.ts";
|
|
10
|
+
import * as RpcPaths from "./RpcPaths.ts";
|
|
11
|
+
|
|
12
|
+
export const layer = (main: string) =>
|
|
13
|
+
Layer.provideMerge(
|
|
14
|
+
Lock.LockLive,
|
|
15
|
+
Layer.provideMerge(
|
|
16
|
+
RpcPaths.layer(main),
|
|
17
|
+
Layer.mergeAll(
|
|
18
|
+
AlchemyContext.AlchemyContextLive,
|
|
19
|
+
makeConfigProvider(),
|
|
20
|
+
Layer.unwrap(
|
|
21
|
+
Effect.promise(() => {
|
|
22
|
+
if ("Bun" in globalThis) {
|
|
23
|
+
return import("./RpcServerBun.ts").then((m) => m.RpcServerBun);
|
|
24
|
+
} else {
|
|
25
|
+
return import("./RpcServerNode.js").then((m) => m.RpcServerNode);
|
|
26
|
+
}
|
|
27
|
+
}),
|
|
28
|
+
),
|
|
29
|
+
),
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const makeConfigProvider = () => {
|
|
34
|
+
let options: Partial<ExecStackOptionsEncoded>;
|
|
35
|
+
try {
|
|
36
|
+
options = JSON.parse(
|
|
37
|
+
process.env.ALCHEMY_EXEC_OPTIONS!,
|
|
38
|
+
) as ExecStackOptionsEncoded;
|
|
39
|
+
} catch {
|
|
40
|
+
options = {};
|
|
41
|
+
}
|
|
42
|
+
const envFile = Option.fromUndefinedOr(options.envFile);
|
|
43
|
+
return ConfigProvider.layer(
|
|
44
|
+
loadConfigProvider(envFile).pipe(
|
|
45
|
+
Effect.map((base) => withProfileOverride(base, options.profile)),
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
};
|
package/src/Stack.ts
CHANGED
|
@@ -13,6 +13,8 @@ import type { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSp
|
|
|
13
13
|
import { AlchemyContext, AlchemyContextLive } from "./AlchemyContext.ts";
|
|
14
14
|
import { provideFreshArtifactStore } from "./Artifacts.ts";
|
|
15
15
|
import { AuthProviders } from "./Auth/AuthProvider.ts";
|
|
16
|
+
import { CredentialsStore, CredentialsStoreLive } from "./Auth/Credentials.ts";
|
|
17
|
+
import { Profile, ProfileLive } from "./Auth/Profile.ts";
|
|
16
18
|
import { Cli } from "./Cli/Cli.ts";
|
|
17
19
|
import type { Input, InputProps } from "./Input.ts";
|
|
18
20
|
import * as Output from "./Output.ts";
|
|
@@ -35,6 +37,8 @@ export type StackServices =
|
|
|
35
37
|
| HttpClient
|
|
36
38
|
| ChildProcessSpawner
|
|
37
39
|
| AuthProviders
|
|
40
|
+
| Profile
|
|
41
|
+
| CredentialsStore
|
|
38
42
|
| Cli;
|
|
39
43
|
|
|
40
44
|
export type StackEffect<A, Err = never, Req = never> = Effect.Effect<
|
|
@@ -46,6 +50,8 @@ export type StackEffect<A, Err = never, Req = never> = Effect.Effect<
|
|
|
46
50
|
| AuthProviders
|
|
47
51
|
| AlchemyContext
|
|
48
52
|
| Cli
|
|
53
|
+
| Profile
|
|
54
|
+
| CredentialsStore
|
|
49
55
|
| State
|
|
50
56
|
| Req
|
|
51
57
|
>;
|
|
@@ -250,6 +256,8 @@ const platform = Layer.mergeAll(
|
|
|
250
256
|
PlatformServices,
|
|
251
257
|
FetchHttpClient.layer,
|
|
252
258
|
Logger.layer([fileLogger("out")], { mergeWithExisting: true }),
|
|
259
|
+
Layer.provide(ProfileLive, PlatformServices),
|
|
260
|
+
Layer.provide(CredentialsStoreLive, PlatformServices),
|
|
253
261
|
);
|
|
254
262
|
// override alchemy state store, CLI/reporting, state, and Config
|
|
255
263
|
const alchemy = (overrides?: { dev?: boolean }) =>
|
package/src/Test/Core.ts
CHANGED
|
@@ -9,8 +9,9 @@ import { AlchemyContext, AlchemyContextLive } from "../AlchemyContext.ts";
|
|
|
9
9
|
import { apply } from "../Apply.ts";
|
|
10
10
|
import { provideFreshArtifactStore } from "../Artifacts.ts";
|
|
11
11
|
import { AuthProviders } from "../Auth/AuthProvider.ts";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { CredentialsStoreLive } from "../Auth/Credentials.ts";
|
|
13
|
+
import { ProfileLive, withProfileOverride } from "../Auth/Profile.ts";
|
|
14
|
+
import { LoggingCli } from "../Cli/LoggingCli.ts";
|
|
14
15
|
import { deploy as _deploy } from "../Deploy.ts";
|
|
15
16
|
import { destroy as _destroy } from "../Destroy.ts";
|
|
16
17
|
import type { Input } from "../Input.ts";
|
|
@@ -72,9 +73,14 @@ const overrideAlchemyContext = (overrides: { dev: boolean }) =>
|
|
|
72
73
|
|
|
73
74
|
export type TestEffect<A, Req = never> = StackEffect<A, any, Req>;
|
|
74
75
|
|
|
75
|
-
const platformLayer = Layer.mergeAll(
|
|
76
|
+
const platformLayer = Layer.mergeAll(
|
|
77
|
+
PlatformServices,
|
|
78
|
+
FetchHttpClient.layer,
|
|
79
|
+
Layer.provide(ProfileLive, PlatformServices),
|
|
80
|
+
Layer.provide(CredentialsStoreLive, PlatformServices),
|
|
81
|
+
);
|
|
76
82
|
|
|
77
|
-
const alchemyLayer = Layer.mergeAll(
|
|
83
|
+
const alchemyLayer = Layer.mergeAll(LoggingCli, AlchemyContextLive);
|
|
78
84
|
|
|
79
85
|
/**
|
|
80
86
|
* Build the per-test runtime and return a self-contained Effect.
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { FileSystem } from "effect/FileSystem";
|
|
2
|
-
import { Path } from "effect/Path";
|
|
3
|
-
import * as Command from "effect/unstable/cli/Command";
|
|
4
|
-
import type { HttpClient } from "effect/unstable/http/HttpClient";
|
|
5
|
-
import * as CloudflareAccess from "../../Cloudflare/Access.ts";
|
|
6
|
-
export declare const bootstrapCommand: Command.Command<"bootstrap", {} | {}, {}, import("../../AlchemyContext.ts").AlchemyContext | import("effect/Config").ConfigError | import("../../Auth/AuthProvider").AuthError | import("../../Stage.ts").Stage | import("../../State/State.ts").StateStoreError | import("../../Output.ts").MissingSourceError | import("../../Output.ts").InvalidReferenceError | import("@distilled.cloud/aws/Errors").UnknownAwsError | import("@distilled.cloud/aws/Errors").AccessDeniedException | import("@distilled.cloud/aws/Errors").ExpiredTokenException | import("@distilled.cloud/aws/Errors").IncompleteSignature | import("@distilled.cloud/aws/Errors").InternalFailure | import("@distilled.cloud/aws/Errors").MalformedHttpRequestException | import("@distilled.cloud/aws/Errors").NotAuthorized | import("@distilled.cloud/aws/Errors").OptInRequired | import("@distilled.cloud/aws/Errors").RequestAbortedException | import("@distilled.cloud/aws/Errors").RequestEntityTooLargeException | import("@distilled.cloud/aws/Errors").RequestExpired | import("@distilled.cloud/aws/Errors").RequestTimeoutException | import("@distilled.cloud/aws/Errors").ServiceUnavailable | import("@distilled.cloud/aws/Errors").ThrottlingException | import("@distilled.cloud/aws/Errors").UnrecognizedClientException | import("@distilled.cloud/aws/Errors").UnknownOperationException | import("@distilled.cloud/aws/Errors").ValidationError | import("@distilled.cloud/aws/Errors").ValidationException | import("@distilled.cloud/aws/Errors").OperationAborted | import("@distilled.cloud/aws/Errors").EndpointError | import("@distilled.cloud/aws/Errors").NoMatchingRuleError | import("@distilled.cloud/aws/Credentials").CredentialsError | import("@distilled.cloud/aws/s3").RequestLimitExceeded | import("@distilled.cloud/aws/s3").RequestError | import("@distilled.cloud/aws/s3").NoSuchBucket | import("@distilled.cloud/aws/s3").PermanentRedirect | import("@distilled.cloud/aws/s3").BucketAlreadyExists | import("@distilled.cloud/aws/s3").IllegalLocationConstraintException | import("@distilled.cloud/aws/s3").InvalidArgument | import("@distilled.cloud/aws/s3").InvalidBucketName | import("@distilled.cloud/aws/s3").InvalidLocationConstraint | import("@distilled.cloud/aws/s3").NotFound | import("@distilled.cloud/aws/s3").ParseError | import("@distilled.cloud/aws/s3").BucketNotEmpty | CloudflareAccess.AccessError | import("@distilled.cloud/cloudflare").DefaultErrors | import("@distilled.cloud/cloudflare/workers").InvalidRoute | import("@distilled.cloud/cloudflare/secrets-store").InvalidAccountId | {
|
|
7
|
-
readonly _tag: "StateStoreVersionNotReady";
|
|
8
|
-
readonly expected: number;
|
|
9
|
-
readonly observed: number | undefined;
|
|
10
|
-
name: string;
|
|
11
|
-
message: string;
|
|
12
|
-
stack?: string;
|
|
13
|
-
cause?: unknown;
|
|
14
|
-
readonly "~effect/Runtime/errorExitCode"?: number;
|
|
15
|
-
readonly "~effect/Runtime/errorReported"?: boolean;
|
|
16
|
-
readonly "~effect/ErrorReporter/ignore"?: boolean;
|
|
17
|
-
readonly "~effect/ErrorReporter/severity"?: import("effect/LogLevel").Severity;
|
|
18
|
-
readonly "~effect/ErrorReporter/attributes"?: import("effect/Record").ReadonlyRecord<string, unknown>;
|
|
19
|
-
}, import("../../AlchemyContext.ts").AlchemyContext | Path | FileSystem | import("effect/unstable/process/ChildProcessSpawner").ChildProcessSpawner | HttpClient | import("../Cli.ts").Cli>;
|
|
20
|
-
//# sourceMappingURL=bootstrap.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../../src/Cli/commands/bootstrap.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAIpD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,KAAK,OAAO,MAAM,6BAA6B,CAAC;AAEvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAWlE,OAAO,KAAK,gBAAgB,MAAM,4BAA4B,CAAC;AA+L/D,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;2LAE5B,CAAC"}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import * as Auth from "@distilled.cloud/aws/Auth";
|
|
2
|
-
import * as ConfigProvider from "effect/ConfigProvider";
|
|
3
|
-
import * as Console from "effect/Console";
|
|
4
|
-
import * as Effect from "effect/Effect";
|
|
5
|
-
import * as Layer from "effect/Layer";
|
|
6
|
-
import * as Logger from "effect/Logger";
|
|
7
|
-
import * as Option from "effect/Option";
|
|
8
|
-
import { Path } from "effect/Path";
|
|
9
|
-
import * as Command from "effect/unstable/cli/Command";
|
|
10
|
-
import * as Flag from "effect/unstable/cli/Flag";
|
|
11
|
-
import { bootstrap as bootstrapAws, destroyBootstrap as destroyBootstrapAws, } from "../../AWS/Bootstrap";
|
|
12
|
-
import * as AWSCredentials from "../../AWS/Credentials";
|
|
13
|
-
import * as AWSEnvironment from "../../AWS/Environment";
|
|
14
|
-
import * as AWSRegion from "../../AWS/Region";
|
|
15
|
-
import { AuthProviders } from "../../Auth/AuthProvider";
|
|
16
|
-
import { withProfileOverride } from "../../Auth/Profile";
|
|
17
|
-
import * as CloudflareAccess from "../../Cloudflare/Access.js";
|
|
18
|
-
import { CloudflareAuth } from "../../Cloudflare/Auth/AuthProvider";
|
|
19
|
-
import * as CloudflareEnvironment from "../../Cloudflare/CloudflareEnvironment";
|
|
20
|
-
import * as CloudflareCredentials from "../../Cloudflare/Credentials";
|
|
21
|
-
import { bootstrap as bootstrapCloudflare } from "../../Cloudflare/StateStore/State";
|
|
22
|
-
import { loadConfigProvider } from "../../Util/ConfigProvider";
|
|
23
|
-
import { fileLogger } from "../../Util/FileLogger";
|
|
24
|
-
import { envFile, instrumentCommand, profile } from "./_shared.js";
|
|
25
|
-
const awsProfile = Flag.string("profile").pipe(Flag.withDescription("AWS profile to use for credentials"), Flag.optional, Flag.map(Option.getOrElse(() => "default")));
|
|
26
|
-
const awsRegion = Flag.string("region").pipe(Flag.withDescription("AWS region to bootstrap (defaults to AWS_REGION env var)"), Flag.optional, Flag.map(Option.getOrUndefined));
|
|
27
|
-
const bootstrapDestroy = Flag.boolean("destroy").pipe(Flag.withDescription("Destroy all bootstrap buckets in the selected region"), Flag.withDefault(false));
|
|
28
|
-
const bootstrapAwsCommand = Command.make("aws", {
|
|
29
|
-
envFile,
|
|
30
|
-
profile: awsProfile,
|
|
31
|
-
region: awsRegion,
|
|
32
|
-
destroy: bootstrapDestroy,
|
|
33
|
-
}, instrumentCommand("bootstrap.aws", (a) => ({
|
|
34
|
-
"alchemy.profile": a.profile,
|
|
35
|
-
"alchemy.region": a.region ?? "",
|
|
36
|
-
"alchemy.destroy": a.destroy,
|
|
37
|
-
}))(Effect.fnUntraced(function* ({ envFile, profile, region, destroy }) {
|
|
38
|
-
const logger = Logger.layer([fileLogger("bootstrap.txt")], {
|
|
39
|
-
mergeWithExisting: true,
|
|
40
|
-
});
|
|
41
|
-
return yield* Effect.gen(function* () {
|
|
42
|
-
const ssoProfile = yield* Auth.loadProfile(profile);
|
|
43
|
-
if (!ssoProfile.sso_account_id) {
|
|
44
|
-
return yield* Effect.die(`AWS SSO profile '${profile}' is missing sso_account_id`);
|
|
45
|
-
}
|
|
46
|
-
// Build a single AWSEnvironment, then derive Region/Credentials from
|
|
47
|
-
// it so resource providers downstream see a consistent view. The
|
|
48
|
-
// credentials Effect captures FileSystem/Path/HttpClient via the
|
|
49
|
-
// ambient context; AWSEnvironment expects R=never, so we provide it
|
|
50
|
-
// here.
|
|
51
|
-
const ambient = yield* Effect.context();
|
|
52
|
-
const environment = AWSEnvironment.makeEnvironment({
|
|
53
|
-
accountId: ssoProfile.sso_account_id,
|
|
54
|
-
region: region ?? ssoProfile.region ?? "us-east-1",
|
|
55
|
-
credentials: Auth.loadProfileCredentials(profile).pipe(Effect.provide(ambient)),
|
|
56
|
-
profile,
|
|
57
|
-
});
|
|
58
|
-
const awsLayers = Layer.provideMerge(Layer.mergeAll(AWSRegion.fromEnvironment, AWSCredentials.fromEnvironment), environment);
|
|
59
|
-
return yield* Effect.gen(function* () {
|
|
60
|
-
const provider = yield* loadConfigProvider(envFile);
|
|
61
|
-
const bootstrapLayer = Layer.provide(awsLayers, Layer.succeed(ConfigProvider.ConfigProvider, provider));
|
|
62
|
-
if (destroy) {
|
|
63
|
-
yield* destroyBootstrapAws().pipe(Effect.tap((result) => result.destroyed === 0
|
|
64
|
-
? Console.log("✓ No bootstrap buckets found to destroy")
|
|
65
|
-
: Console.log(`✓ Destroyed ${result.destroyed} bootstrap bucket(s): ${result.bucketNames.join(", ")}`)), Effect.provide(bootstrapLayer));
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
yield* bootstrapAws().pipe(Effect.tap(({ bucketName, created }) => created
|
|
69
|
-
? Console.log(`✓ Created assets bucket: ${bucketName}`)
|
|
70
|
-
: Console.log(`✓ Assets bucket already exists: ${bucketName}`)), Effect.provide(bootstrapLayer));
|
|
71
|
-
});
|
|
72
|
-
}).pipe(Effect.provide(logger));
|
|
73
|
-
})));
|
|
74
|
-
const cloudflareForce = Flag.boolean("force").pipe(Flag.withDescription("Force a full redeploy even if the state-store worker already exists. " +
|
|
75
|
-
"Without this flag, an existing worker is adopted and only its credentials are refreshed."), Flag.withDefault(false));
|
|
76
|
-
const cloudflareWorkerName = Flag.string("worker-name").pipe(Flag.withDescription("Override the default state-store worker name (advanced; only needed for multiple state stores per account)."), Flag.optional, Flag.map(Option.getOrUndefined));
|
|
77
|
-
const bootstrapCloudflareCommand = Command.make("cloudflare", {
|
|
78
|
-
envFile,
|
|
79
|
-
profile,
|
|
80
|
-
force: cloudflareForce,
|
|
81
|
-
workerName: cloudflareWorkerName,
|
|
82
|
-
}, instrumentCommand("bootstrap.cloudflare", (a) => ({
|
|
83
|
-
"alchemy.profile": a.profile,
|
|
84
|
-
"alchemy.force": a.force,
|
|
85
|
-
"alchemy.worker_name": a.workerName ?? "",
|
|
86
|
-
}))(Effect.fnUntraced(function* ({ envFile, profile, force, workerName }) {
|
|
87
|
-
const logger = Logger.layer([fileLogger("bootstrap.txt")], {
|
|
88
|
-
mergeWithExisting: true,
|
|
89
|
-
});
|
|
90
|
-
// Wire up the same Cloudflare auth chain that
|
|
91
|
-
// `Cloudflare.state(...)` uses internally. CloudflareAuth is an
|
|
92
|
-
// `effectDiscard` layer that registers itself into the
|
|
93
|
-
// `AuthProviders` registry at build time, and downstream layers
|
|
94
|
-
// (`fromProfile`, `fromAuthProvider`) plus the deploy stack all
|
|
95
|
-
// look the registry back up through `getAuthProvider`. We need
|
|
96
|
-
// the registry to remain visible all the way through, so the
|
|
97
|
-
// composition uses `provideMerge` (provides + re-exports) rather
|
|
98
|
-
// than `provide` (provides + hides).
|
|
99
|
-
const authProviders = {};
|
|
100
|
-
const authRegistry = Layer.succeed(AuthProviders, authProviders);
|
|
101
|
-
const authLayer = Layer.provideMerge(CloudflareAuth, authRegistry);
|
|
102
|
-
const cloudflareLayers = Layer.provideMerge(Layer.mergeAll(CloudflareCredentials.fromAuthProvider(), CloudflareEnvironment.fromProfile(), CloudflareAccess.AccessLive), authLayer);
|
|
103
|
-
const services = Layer.mergeAll(cloudflareLayers, ConfigProvider.layer(withProfileOverride(yield* loadConfigProvider(envFile), profile)), logger);
|
|
104
|
-
yield* bootstrapCloudflare({ workerName, force }).pipe(Effect.provide(services));
|
|
105
|
-
})));
|
|
106
|
-
export const bootstrapCommand = Command.make("bootstrap", {}).pipe(Command.withSubcommands([bootstrapAwsCommand, bootstrapCloudflareCommand]));
|
|
107
|
-
//# sourceMappingURL=bootstrap.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../src/Cli/commands/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,2BAA2B,CAAC;AAClD,OAAO,KAAK,cAAc,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,KAAK,OAAO,MAAM,6BAA6B,CAAC;AACvD,OAAO,KAAK,IAAI,MAAM,0BAA0B,CAAC;AAGjD,OAAO,EACL,SAAS,IAAI,YAAY,EACzB,gBAAgB,IAAI,mBAAmB,GACxC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,cAAc,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,cAAc,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,gBAAgB,MAAM,4BAA4B,CAAC;AAC/D,OAA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jE,MAAM,SAAS,GAAG,KAAK,CAAC,YAAY,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IACnE,MAAM,gBAAgB,GAAG,KAAK,CAAC,YAAY,CACzC,KAAK,CAAC,QAAQ,CACZ,qBAAqB,CAAC,gBAAgB,EAAE,EACxC,qBAAqB,CAAC,WAAW,EAAE,EACnC,gBAAgB,CAAC,UAAU,CAC5B,EACD,SAAS,CACV,CAAC;IAEF,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAC7B,gBAAgB,EAChB,cAAc,CAAC,KAAK,CAClB,mBAAmB,CAAC,KAAK,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CACjE,EACD,MAAM,CACP,CAAC;IAEF,KAAK,CAAC,CAAC,mBAAmB,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,IAAI,CACpD,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CACzB,CAAC;AACJ,CAAC,CAAC,CACH,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,IAAI,CAChE,OAAO,CAAC,eAAe,CAAC,CAAC,mBAAmB,EAAE,0BAA0B,CAAC,CAAC,CAC3E,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,81 +0,0 @@
|
|
|
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
|