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