| 1 | import { Connection } from "@t3tools/client-runtime/connection"; |
| 2 | import { ShellSnapshotLoader } from "@t3tools/client-runtime/state/shell"; |
| 3 | import { PullRequestDiffLoader } from "@t3tools/client-runtime/state/pull-requests"; |
| 4 | import { |
| 5 | BoundedThreadSnapshotLoader, |
| 6 | ThreadHistoryController, |
| 7 | } from "@t3tools/client-runtime/state/threads"; |
| 8 | import * as Layer from "effect/Layer"; |
| 9 | import { Atom } from "effect/reactivity"; |
| 10 | |
| 11 | import type { FoundationHotModule } from "../lib/foundation-fast-refresh"; |
| 12 | import { hotSwappableAtomRuntime } from "../lib/hot-swappable-atom-runtime"; |
| 13 | import * as Runtime from "../lib/runtime"; |
| 14 | import { appAtomRegistry } from "../state/atom-registry"; |
| 15 | import * as BackgroundActivity from "./background-activity"; |
| 16 | import * as ConnectionPlatform from "./platform"; |
| 17 | |
| 18 | declare const module: { readonly hot?: FoundationHotModule } | undefined; |
| 19 | |
| 20 | const layerProvidedConnectionPlatform = ConnectionPlatform.layer.pipe(Layer.provide(Runtime.layer)); |
| 21 | |
| 22 | const layerSnapshotLoader = Layer.mergeAll( |
| 23 | PullRequestDiffLoader.layer, |
| 24 | BoundedThreadSnapshotLoader.layer, |
| 25 | ShellSnapshotLoader.layer, |
| 26 | ThreadHistoryController.layer, |
| 27 | ); |
| 28 | |
| 29 | type ConnectionLayerSource = |
| 30 | | typeof Connection.layer |
| 31 | | typeof layerSnapshotLoader |
| 32 | | typeof Runtime.layer |
| 33 | | typeof ConnectionPlatform.layer |
| 34 | | typeof BackgroundActivity.layerObserver |
| 35 | | typeof BackgroundActivity.layerReporter; |
| 36 | |
| 37 | const layerProvidedClientConnection = layerSnapshotLoader.pipe( |
| 38 | Layer.provideMerge( |
| 39 | Connection.layerWithOptions({ usageLimitSources: true, usageLimitsCommand: true }), |
| 40 | ), |
| 41 | Layer.provideMerge( |
| 42 | Layer.mergeAll( |
| 43 | Runtime.layer, |
| 44 | layerProvidedConnectionPlatform, |
| 45 | BackgroundActivity.layerObserver, |
| 46 | ), |
| 47 | ), |
| 48 | ); |
| 49 | |
| 50 | const layerConnection = BackgroundActivity.layerReporter.pipe( |
| 51 | Layer.provideMerge(layerProvidedClientConnection), |
| 52 | ); |
| 53 | |
| 54 | export const connectionAtomRuntime: Atom.AtomRuntime< |
| 55 | Layer.Success<ConnectionLayerSource>, |
| 56 | Layer.Error<ConnectionLayerSource> |
| 57 | > = hotSwappableAtomRuntime({ |
| 58 | id: "t3.mobile.connection-runtime", |
| 59 | hotModule: typeof module === "undefined" ? undefined : module.hot, |
| 60 | registry: appAtomRegistry, |
| 61 | layer: layerConnection, |
| 62 | }); |