| 1 | import * as Layer from "effect/Layer"; |
| 2 | import * as FetchHttpClient from "effect/http/FetchHttpClient"; |
| 3 | import { CredentialsStoreLive } from "../Auth/Credentials.ts"; |
| 4 | import { ProfileStoreLive } from "../Auth/Profile.ts"; |
| 5 | import * as Provider from "../Provider.ts"; |
| 6 | import { PlanetscaleAuth } from "./AuthProvider.ts"; |
| 7 | import * as Credentials from "./Credentials.ts"; |
| 8 | import { MySQLBranch, MySQLBranchProvider } from "./MySQL/MySQLBranch.ts"; |
| 9 | import { MySQLDatabase, MySQLDatabaseProvider } from "./MySQL/MySQLDatabase.ts"; |
| 10 | import { MySQLPassword, MySQLPasswordProvider } from "./MySQL/MySQLPassword.ts"; |
| 11 | import { |
| 12 | PostgresBranch, |
| 13 | PostgresBranchProvider, |
| 14 | } from "./Postgres/PostgresBranch.ts"; |
| 15 | import { |
| 16 | PostgresDatabase, |
| 17 | PostgresDatabaseProvider, |
| 18 | } from "./Postgres/PostgresDatabase.ts"; |
| 19 | import { |
| 20 | PostgresDefaultRole, |
| 21 | PostgresDefaultRoleProvider, |
| 22 | } from "./Postgres/PostgresDefaultRole.ts"; |
| 23 | import { PostgresRole, PostgresRoleProvider } from "./Postgres/PostgresRole.ts"; |
| 24 | |
| 25 | /** |
| 26 | * Service tag bundling all PlanetScale providers + auth + credentials. Use |
| 27 | * `Planetscale.providers()` to materialize the full layer. |
| 28 | */ |
| 29 | export class Providers extends Provider.ProviderCollection<Providers>()( |
| 30 | "Planetscale", |
| 31 | ) {} |
| 32 | |
| 33 | export type ProviderRequirements = Layer.Services<ReturnType<typeof providers>>; |
| 34 | |
| 35 | /** |
| 36 | * Build the complete PlanetScale providers Layer. Provide this on a Stack |
| 37 | * (or via `Effect.provide` at test time) to enable all PlanetScale |
| 38 | * resources, the AuthProvider registration, and credential resolution. |
| 39 | * |
| 40 | * @example |
| 41 | * ```ts |
| 42 | * Effect.provide(Planetscale.providers()) |
| 43 | * ``` |
| 44 | */ |
| 45 | export const providers = () => |
| 46 | Layer.effect( |
| 47 | Providers, |
| 48 | Provider.collection([ |
| 49 | MySQLDatabase, |
| 50 | PostgresDatabase, |
| 51 | MySQLBranch, |
| 52 | PostgresBranch, |
| 53 | MySQLPassword, |
| 54 | PostgresRole, |
| 55 | PostgresDefaultRole, |
| 56 | ]), |
| 57 | ).pipe( |
| 58 | Layer.provide( |
| 59 | Layer.mergeAll( |
| 60 | MySQLDatabaseProvider(), |
| 61 | PostgresDatabaseProvider(), |
| 62 | MySQLBranchProvider(), |
| 63 | PostgresBranchProvider(), |
| 64 | MySQLPasswordProvider(), |
| 65 | PostgresRoleProvider(), |
| 66 | PostgresDefaultRoleProvider(), |
| 67 | ), |
| 68 | ), |
| 69 | Layer.provideMerge(Credentials.fromAuthProvider()), |
| 70 | Layer.provideMerge(FetchHttpClient.layer), |
| 71 | Layer.provideMerge(PlanetscaleAuth), |
| 72 | Layer.provideMerge(ProfileStoreLive), |
| 73 | Layer.provideMerge(CredentialsStoreLive), |
| 74 | Layer.orDie, |
| 75 | ); |