The best way to control Claude Code, Codex and more from any computer or phone

main
ts 34 lines 1.23 KB
Raw
1 import type { MigrationRecord } from "@alchemy.run/sql/Migrations/Format";
2 import { makeEntrypointLayer } from "alchemy/Runtime";
3 import { Self } from "alchemy/Self";
4 import * as Context from "effect/Context";
5 import * as Layer from "effect/Layer";
6
7 /** SQL files captured during construction and embedded in the Worker bundle. */
8 export interface SqlMigrationSnapshot {
9 readonly _tag: "Cloudflare.SqlMigrations";
10 /** The per-instance applied-migrations table. */
11 readonly table: string;
12 /** Ordered SQL records, including their content hashes. */
13 readonly records: ReadonlyArray<MigrationRecord>;
14 }
15
16 /** @internal */
17 export interface SqlMigrationsExport {
18 readonly kind: "sqlMigrations";
19 readonly snapshot: SqlMigrationSnapshot;
20 }
21
22 export class SqlMigrationsRuntime extends Context.Service<
23 SqlMigrationsRuntime,
24 Readonly<Record<string, SqlMigrationSnapshot>>
25 >()("Cloudflare.SqlMigrationsRuntime") {}
26
27 /** Supply the generated migration records to every entrypoint and object activation. */
28 export const withSqlMigrations = (
29 entrypoint: unknown,
30 migrations: Readonly<Record<string, SqlMigrationSnapshot>>,
31 ) =>
32 makeEntrypointLayer(Self, entrypoint).pipe(
33 Layer.provideMerge(Layer.succeed(SqlMigrationsRuntime, migrations)),
34 );