| 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 * as Command from "../Command/index.ts"; |
| 7 | import { Server, ServerProvider } from "../Website/Server.ts"; |
| 8 | import { NeonAuth } from "./AuthProvider.ts"; |
| 9 | import { Auth, AuthProvider } from "./Auth.ts"; |
| 10 | import { |
| 11 | AuthOAuthProvider, |
| 12 | AuthOAuthProviderProvider, |
| 13 | } from "./AuthOAuthProvider.ts"; |
| 14 | import { |
| 15 | AuthTrustedDomain, |
| 16 | AuthTrustedDomainProvider, |
| 17 | } from "./AuthTrustedDomain.ts"; |
| 18 | import { DataApi, DataApiProvider } from "./DataApi.ts"; |
| 19 | import { Branch, BranchProvider } from "./Branch.ts"; |
| 20 | import * as Credentials from "./Credentials.ts"; |
| 21 | import { Credential, CredentialProvider } from "./Credential.ts"; |
| 22 | import { Bucket, BucketProvider } from "./Bucket.ts"; |
| 23 | import { Object, ObjectProvider } from "./Object.ts"; |
| 24 | import { Project, ProjectProvider } from "./Project.ts"; |
| 25 | import { |
| 26 | OrganizationApiKey, |
| 27 | OrganizationApiKeyProvider, |
| 28 | } from "./OrganizationApiKey.ts"; |
| 29 | import { |
| 30 | OrganizationMemberRole, |
| 31 | OrganizationMemberRoleProvider, |
| 32 | } from "./OrganizationMemberRole.ts"; |
| 33 | import { |
| 34 | ProjectMemberRole, |
| 35 | ProjectMemberRoleProvider, |
| 36 | } from "./ProjectMemberRole.ts"; |
| 37 | import { |
| 38 | OrganizationSpendingLimit, |
| 39 | OrganizationSpendingLimitProvider, |
| 40 | } from "./OrganizationSpendingLimit.ts"; |
| 41 | import { |
| 42 | OrganizationVPCEndpoint, |
| 43 | OrganizationVPCEndpointProvider, |
| 44 | } from "./OrganizationVPCEndpoint.ts"; |
| 45 | import { |
| 46 | ProjectVPCEndpoint, |
| 47 | ProjectVPCEndpointProvider, |
| 48 | } from "./ProjectVPCEndpoint.ts"; |
| 49 | import { Function } from "./Function.ts"; |
| 50 | import { FunctionProvider } from "./FunctionProvider.ts"; |
| 51 | import { FunctionTrigger, FunctionTriggerProvider } from "./FunctionTrigger.ts"; |
| 52 | import { CustomDomain, CustomDomainProvider } from "./CustomDomain.ts"; |
| 53 | import { |
| 54 | WebsiteArtifact, |
| 55 | WebsiteArtifactProvider, |
| 56 | } from "./Website/Artifact.ts"; |
| 57 | |
| 58 | export class Providers extends Provider.ProviderCollection<Providers>()( |
| 59 | "Neon", |
| 60 | ) {} |
| 61 | |
| 62 | /** |
| 63 | * Build a layer that registers all Neon resource providers, the Neon |
| 64 | * `AuthProvider`, the resolved `Credentials`, and an `HttpClient`. Include |
| 65 | * this from your stack alongside other cloud `providers()` layers. |
| 66 | * |
| 67 | * @example |
| 68 | * ```typescript |
| 69 | * import * as Alchemy from "alchemy"; |
| 70 | * import * as Cloudflare from "alchemy/Cloudflare"; |
| 71 | * import * as Neon from "alchemy/Neon"; |
| 72 | * import * as Effect from "effect/Effect"; |
| 73 | * import * as Layer from "effect/Layer"; |
| 74 | * |
| 75 | * export default Alchemy.Stack( |
| 76 | * "MyStack", |
| 77 | * { |
| 78 | * providers: Layer.mergeAll(Cloudflare.providers(), Neon.providers()), |
| 79 | * state: Alchemy.localState(), |
| 80 | * }, |
| 81 | * Effect.gen(function* () { |
| 82 | * const project = yield* Neon.Project("app-db"); |
| 83 | * const branch = yield* Neon.Branch("app-branch", { project }); |
| 84 | * return { branchId: branch.branchId }; |
| 85 | * }), |
| 86 | * ); |
| 87 | * ``` |
| 88 | */ |
| 89 | export const providers = () => |
| 90 | Layer.effect( |
| 91 | Providers, |
| 92 | Provider.collection([ |
| 93 | Project, |
| 94 | OrganizationApiKey, |
| 95 | OrganizationMemberRole, |
| 96 | ProjectMemberRole, |
| 97 | OrganizationSpendingLimit, |
| 98 | OrganizationVPCEndpoint, |
| 99 | ProjectVPCEndpoint, |
| 100 | Branch, |
| 101 | Credential, |
| 102 | Bucket, |
| 103 | Object, |
| 104 | Auth, |
| 105 | AuthOAuthProvider, |
| 106 | AuthTrustedDomain, |
| 107 | DataApi, |
| 108 | Function, |
| 109 | FunctionTrigger, |
| 110 | CustomDomain, |
| 111 | WebsiteArtifact, |
| 112 | Server, |
| 113 | ]), |
| 114 | ).pipe( |
| 115 | Layer.provideMerge( |
| 116 | Layer.mergeAll( |
| 117 | ProjectProvider(), |
| 118 | OrganizationApiKeyProvider(), |
| 119 | OrganizationMemberRoleProvider(), |
| 120 | ProjectMemberRoleProvider(), |
| 121 | OrganizationSpendingLimitProvider(), |
| 122 | OrganizationVPCEndpointProvider(), |
| 123 | ProjectVPCEndpointProvider(), |
| 124 | BranchProvider(), |
| 125 | CredentialProvider(), |
| 126 | BucketProvider(), |
| 127 | ObjectProvider(), |
| 128 | AuthProvider(), |
| 129 | AuthOAuthProviderProvider(), |
| 130 | AuthTrustedDomainProvider(), |
| 131 | DataApiProvider(), |
| 132 | FunctionProvider(), |
| 133 | FunctionTriggerProvider(), |
| 134 | CustomDomainProvider(), |
| 135 | WebsiteArtifactProvider(), |
| 136 | ServerProvider(), |
| 137 | ), |
| 138 | ), |
| 139 | Layer.provideMerge(Command.providers()), |
| 140 | Layer.provideMerge(Credentials.fromAuthProvider()), |
| 141 | Layer.provideMerge(NeonAuth), |
| 142 | Layer.provideMerge(ProfileStoreLive), |
| 143 | Layer.provideMerge(CredentialsStoreLive), |
| 144 | Layer.provideMerge(FetchHttpClient.layer), |
| 145 | Layer.orDie, |
| 146 | ); |