The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | /** |
| 2 | * Utilities for applying Effect SQL migrations to SQLite WASM databases. |
| 3 | * |
| 4 | * This module re-exports the shared `Migrator` loaders and error types, then |
| 5 | * provides `run` and `layer` helpers that execute ordered migrations through the |
| 6 | * current SQLite WASM `SqlClient`. Use it when a browser, worker, or test |
| 7 | * runtime needs to create or upgrade a local SQLite schema before repositories, |
| 8 | * caches, sync services, or other database-backed services start. |
| 9 | * |
| 10 | * The migrator operates on whichever WASM client is in the environment. With |
| 11 | * `SqliteClient.makeMemory`, migrations update an in-memory database, so the |
| 12 | * resulting schema is transient unless you persist it with the client's |
| 13 | * `export` and `import` operations. With worker-backed OPFS databases, run the |
| 14 | * migrator against the same worker configuration and OPFS database name used by |
| 15 | * the rest of the application, and coordinate startup across tabs or workers so |
| 16 | * only one migrator upgrades a given database at a time. OPFS availability is |
| 17 | * browser- and origin-dependent, and this adapter does not currently write |
| 18 | * SQLite schema dumps for `schemaDirectory`. |
| 19 | * |
| 20 | * @stability unstable |
| 21 | * @since 4.0.0 |
| 22 | */ |
| 23 | import type * as Effect from "effect/Effect" |
| 24 | import * as Layer from "effect/Layer" |
| 25 | import * as Migrator from "effect/sql/Migrator" |
| 26 | import type * as Client from "effect/sql/SqlClient" |
| 27 | import type { SqlError } from "effect/sql/SqlError" |
| 28 | |
| 29 | /** |
| 30 | * @since 4.0.0 |
| 31 | */ |
| 32 | export * from "effect/sql/Migrator" |
| 33 | export { |
| 34 | /** |
| 35 | * @stability unstable |
| 36 | * @category loaders |
| 37 | * @since 4.0.0 |
| 38 | */ |
| 39 | fromFileSystem |
| 40 | } from "effect/sql/MigratorFileSystem" |
| 41 | |
| 42 | /** |
| 43 | * Runs SQL migrations for a SQLite WASM database using the shared `Migrator` implementation and the current `SqlClient`. |
| 44 | * |
| 45 | * @stability unstable |
| 46 | * @category running |
| 47 | * @since 4.0.0 |
| 48 | */ |
| 49 | export const run: <R>( |
| 50 | options: Migrator.MigratorOptions<R> |
| 51 | ) => Effect.Effect< |
| 52 | ReadonlyArray<readonly [id: number, name: string]>, |
| 53 | SqlError | Migrator.MigrationError, |
| 54 | Client.SqlClient | R |
| 55 | > = Migrator.make({}) |
| 56 | |
| 57 | /** |
| 58 | * Creates a layer that runs the configured SQLite WASM migrations during layer construction and provides no services. |
| 59 | * |
| 60 | * @stability unstable |
| 61 | * @category layers |
| 62 | * @since 4.0.0 |
| 63 | */ |
| 64 | export const layer = <R>( |
| 65 | options: Migrator.MigratorOptions<R> |
| 66 | ): Layer.Layer<never, SqlError | Migrator.MigrationError, R | Client.SqlClient> => Layer.effectDiscard(run(options)) |