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

ProviderRegistry.ts

80 lines2.9 KB

1/**
2 * ProviderRegistry - Provider snapshot service.
3 *
4 * Owns provider install/auth/version/model snapshots and exposes the latest
5 * provider state to transport layers.
6 *
7 * @module ProviderRegistry
8 */
9import type {
10 ProviderInstanceId,
11 ProviderDriverKind,
12 ServerProvider,
13 ServerProviderUpdateState,
14} from "@t3tools/contracts";
15import { Context } from "effect";
16import type { Effect, Stream } from "effect";
17import type { ProviderMaintenanceCapabilities } from "../providerMaintenance.ts";
18​
19export type ProviderMaintenanceActionKind = "update";
20​
21export interface ProviderRegistryShape {
22 /**
23 * Read the latest provider snapshots for every configured instance.
24 * Multiple snapshots may share the same `provider` kind (multiple
25 * instances of the same driver) and disambiguate via `instanceId`.
26 */
27 readonly getProviders: Effect.Effect<ReadonlyArray<ServerProvider>>;
28​
29 /**
30 * Refresh all providers, or the default instance of the specified
31 * kind when supplied.
32 *
33 * Retained for back-compat with legacy call sites (WS refresh RPC,
34 * orchestration metrics). New code should prefer `refreshInstance`.
35 *
36 * @deprecated prefer `refreshInstance` for new call sites.
37 */
38 readonly refresh: (provider?: ProviderDriverKind) => Effect.Effect<ReadonlyArray<ServerProvider>>;
39​
40 /**
41 * Refresh the specific configured instance. Returns the updated snapshot
42 * list. When the instance id is unknown the call resolves with the
43 * currently cached list (no error) — matching the legacy `refresh` shim
44 * behaviour so transport layers don't have to special-case unknowns.
45 */
46 readonly refreshInstance: (
47 instanceId: ProviderInstanceId,
48 ) => Effect.Effect<ReadonlyArray<ServerProvider>>;
49​
50 /**
51 * Resolve the maintenance capabilities owned by one live provider instance.
52 * Falls back to manual-only capabilities when the instance is not live.
53 */
54 readonly getProviderMaintenanceCapabilitiesForInstance: (
55 instanceId: ProviderInstanceId,
56 provider: ProviderDriverKind,
57 ) => Effect.Effect<ProviderMaintenanceCapabilities>;
58​
59 /**
60 * Apply volatile maintenance-action state to one configured instance.
61 * This state is never persisted to disk. Today only update actions are
62 * projected onto `ServerProvider.updateState`; install/auth actions can
63 * extend this action map without adding driver-scoped APIs.
64 */
65 readonly setProviderMaintenanceActionState: (input: {
66 readonly instanceId: ProviderInstanceId;
67 readonly action: ProviderMaintenanceActionKind;
68 readonly state: ServerProviderUpdateState | null;
69 }) => Effect.Effect<ReadonlyArray<ServerProvider>>;
70​
71 /**
72 * Stream of provider snapshot updates — one emission per aggregated
73 * change. The array contains the full current state.
74 */
75 readonly streamChanges: Stream.Stream<ReadonlyArray<ServerProvider>>;
77​
78export class ProviderRegistry extends Context.Service<ProviderRegistry, ProviderRegistryShape>()(
79 "t3/provider/Services/ProviderRegistry",
80) {}