Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ProviderHostLive.ts

39 lines1.4 KB

1/**
2 * The server's implementation of `ProviderHost`, the only server surface
3 * provider drivers and adapters may use.
4 *
5 * @module provider/ProviderHostLive
6 */
7import { ProviderHost } from "@t3tools/provider-core/server/ProviderHost";
8import * as Effect from "effect/Effect";
9import * as Layer from "effect/Layer";
10​
11import { resolveAttachmentPath } from "../attachmentStore.ts";
12import * as BackgroundPolicy from "../background/BackgroundPolicy.ts";
13import * as ServerConfig from "../config.ts";
14import * as ServerSettings from "../serverSettings.ts";
15​
16export const layer = Layer.effect(
17 ProviderHost,
18 Effect.gen(function* () {
19 const config = yield* ServerConfig.ServerConfig;
20 const serverSettings = yield* ServerSettings.ServerSettingsService;
21 const backgroundPolicy = yield* BackgroundPolicy.BackgroundPolicy;
22 return ProviderHost.of({
23 paths: {
24 cwd: config.cwd,
25 baseDir: config.baseDir,
26 stateDir: config.stateDir,
27 providerStatusCacheDir: config.providerStatusCacheDir,
28 },
29 settings: {
30 get: serverSettings.getSettings,
31 changes: serverSettings.streamChanges,
32 subscribe: serverSettings.subscribeChanges,
33 },
34 shouldRunBackgroundWork: backgroundPolicy.shouldRunScopeWork,
35 resolveAttachmentPath: (attachment) =>
36 resolveAttachmentPath({ attachmentsDir: config.attachmentsDir, attachment }),
37 });
38 }),
39);