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

ProviderAdapterRegistry.ts

68 lines2.7 KB

1/**
2 * ProviderAdapterRegistry - Lookup boundary for provider adapter implementations.
3 *
4 * Maps a `ProviderInstanceId` to its provider adapter. `ProviderService` uses
5 * this registry with `ProviderSessionDirectory`. The registry does not own
6 * session lifecycle or routing rules.
7 *
8 * @module ProviderAdapterRegistry
9 */
10import type { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
11import * as Context from "effect/Context";
12import type * as Effect from "effect/Effect";
13import type * as PubSub from "effect/PubSub";
14import type * as Scope from "effect/Scope";
15​
16import type { ProviderAdapterError, ProviderUnsupportedError } from "../Errors.ts";
17import type { ProviderAdapterShape } from "./ProviderAdapter.ts";
18import type { ProviderContinuationIdentity } from "../ProviderDriver.ts";
19​
20export interface ProviderInstanceRoutingInfo {
21 readonly instanceId: ProviderInstanceId;
22 readonly driverKind: ProviderDriverKind;
23 readonly displayName: string | undefined;
24 readonly accentColor?: string | undefined;
25 readonly enabled: boolean;
26 readonly continuationIdentity: ProviderContinuationIdentity;
28​
29/**
30 * ProviderAdapterRegistryShape - Service API for adapter lookup.
31 */
32export interface ProviderAdapterRegistryShape {
33 /**
34 * Resolve the adapter for a specific instance id. Returns
35 * `ProviderUnsupportedError` if no such instance is currently registered
36 * (which covers "never configured" *and* "configured but the driver is
37 * unavailable in this build" — both surface the same failure to callers
38 * that expect a working adapter).
39 */
40 readonly getByInstance: (
41 instanceId: ProviderInstanceId,
42 ) => Effect.Effect<ProviderAdapterShape<ProviderAdapterError>, ProviderUnsupportedError>;
43​
44 readonly getInstanceInfo: (
45 instanceId: ProviderInstanceId,
46 ) => Effect.Effect<ProviderInstanceRoutingInfo, ProviderUnsupportedError>;
47​
48 /**
49 * List all live instance ids. Excludes unavailable/shadow instances —
50 * callers of this method want something they can pass to `getByInstance`.
51 */
52 readonly listInstances: () => Effect.Effect<ReadonlyArray<ProviderInstanceId>>;
53​
54 /**
55 * Acquire a change subscription synchronously in the caller's current fiber.
56 * Consumers that must avoid missing a publish between initial reconciliation
57 * and watcher startup should use this, then fork `Stream.fromSubscription`.
58 */
59 readonly subscribeChanges: Effect.Effect<PubSub.Subscription<void>, never, Scope.Scope>;
61​
62/**
63 * ProviderAdapterRegistry - Service tag for provider adapter lookup.
64 */
65export class ProviderAdapterRegistry extends Context.Service<
66 ProviderAdapterRegistry,
67 ProviderAdapterRegistryShape
68>()("t3/provider/Services/ProviderAdapterRegistry") {}