| 1 | // @effect-diagnostics anyUnknownInErrorContext:off layerMergeAllWithDependencies:off - Alchemy provider helpers expose framework-owned any requirements. |
| 2 | import * as Alchemy from "alchemy"; |
| 3 | import * as Output from "alchemy/Output"; |
| 4 | import * as Axiom from "alchemy/Axiom"; |
| 5 | import * as Cloudflare from "alchemy/Cloudflare"; |
| 6 | import * as Drizzle from "alchemy/Drizzle"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import * as Layer from "effect/Layer"; |
| 9 | import * as Planetscale from "alchemy/Planetscale"; |
| 10 | |
| 11 | import { PublishClientConfig, tokenDigest } from "./src/clientConfig.ts"; |
| 12 | import * as RelayDb from "./src/db.ts"; |
| 13 | import { RelayObservability } from "./src/observability.ts"; |
| 14 | import { ManagedEndpointZone, RelayApiZone } from "./src/zone.ts"; |
| 15 | import * as RelayWorker from "./src/worker.ts"; |
| 16 | |
| 17 | export default Alchemy.Stack( |
| 18 | "T3CodeRelay", |
| 19 | { |
| 20 | providers: Layer.mergeAll( |
| 21 | Axiom.providers(), |
| 22 | Cloudflare.providers(), |
| 23 | Drizzle.providers(), |
| 24 | Planetscale.providers(), |
| 25 | ), |
| 26 | state: Cloudflare.state(), |
| 27 | }, |
| 28 | Effect.gen(function* () { |
| 29 | const db = yield* RelayDb.PlanetscaleDatabase; |
| 30 | const hyperdrive = yield* RelayDb.RelayHyperdrive; |
| 31 | const managedEndpointZone = yield* ManagedEndpointZone.pipe(Effect.orDie); |
| 32 | const relayApiZone = yield* RelayApiZone.pipe(Effect.orDie); |
| 33 | const observability = yield* RelayObservability; |
| 34 | const api = yield* RelayWorker.Api; |
| 35 | yield* PublishClientConfig({ |
| 36 | url: api.url, |
| 37 | mobileTracingUrl: observability.traces.otelTracesEndpoint, |
| 38 | mobileTracingDataset: observability.traces.name, |
| 39 | mobileTracingToken: observability.mobileIngestToken.token, |
| 40 | clientTracingUrl: observability.traces.otelTracesEndpoint, |
| 41 | clientTracingDataset: observability.traces.name, |
| 42 | clientTracingToken: observability.clientIngestToken.token, |
| 43 | tokenDigest: Output.map( |
| 44 | Output.all(observability.mobileIngestToken.token, observability.clientIngestToken.token), |
| 45 | tokenDigest, |
| 46 | ), |
| 47 | }); |
| 48 | |
| 49 | return { |
| 50 | databaseName: db.database.name, |
| 51 | databaseBranchName: db.branch?.name ?? "main", |
| 52 | hyperdriveName: hyperdrive.name, |
| 53 | workerName: api.workerName, |
| 54 | url: api.url, |
| 55 | relayApiZoneId: relayApiZone.zoneId, |
| 56 | managedEndpointZoneId: managedEndpointZone.zoneId, |
| 57 | mobileTracingUrl: observability.traces.otelTracesEndpoint, |
| 58 | mobileTracingDataset: observability.traces.name, |
| 59 | mobileTracingToken: observability.mobileIngestToken.token, |
| 60 | clientTracingUrl: observability.traces.otelTracesEndpoint, |
| 61 | clientTracingDataset: observability.traces.name, |
| 62 | clientTracingToken: observability.clientIngestToken.token, |
| 63 | }; |
| 64 | }).pipe(Effect.provide(RelayWorker.layer)), |
| 65 | ); |