The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Context from "effect/Context"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import type { IssueTrackerKind } from "@t3tools/contracts"; |
| 5 | import * as LinearDriver from "@t3tools/issue-tracker-linear/server/driver"; |
| 6 | import { |
| 7 | isStandaloneIssueTracker, |
| 8 | type IssueTrackerApi, |
| 9 | type StandaloneIssueTrackerApi, |
| 10 | } from "@t3tools/source-control-core/server/IssueTracker"; |
| 11 | |
| 12 | import * as BuiltInDrivers from "../sourceControl/builtInDrivers.ts"; |
| 13 | import * as IssueTrackerHostLive from "./IssueTrackerHostLive.ts"; |
| 14 | |
| 15 | export class IssueTrackerRegistry extends Context.Service< |
| 16 | IssueTrackerRegistry, |
| 17 | { |
| 18 | /** Null for a kind with no implementation, which the service reports as unsupported. */ |
| 19 | readonly get: (kind: IssueTrackerKind) => IssueTrackerApi | null; |
| 20 | readonly kinds: ReadonlyArray<IssueTrackerKind>; |
| 21 | /** The trackers a user connects with a credential of their own, in registration order. */ |
| 22 | readonly standalone: ReadonlyArray<StandaloneIssueTrackerApi>; |
| 23 | } |
| 24 | >()("t3/issue/IssueTrackerRegistry") {} |
| 25 | |
| 26 | /** Exported for tests, which stand a registry up from trackers they supply themselves. */ |
| 27 | export function fromTrackers( |
| 28 | trackers: ReadonlyArray<IssueTrackerApi>, |
| 29 | ): IssueTrackerRegistry["Service"] { |
| 30 | const byKind = new Map(trackers.map((tracker) => [tracker.kind, tracker])); |
| 31 | return { |
| 32 | get: (kind) => byKind.get(kind) ?? null, |
| 33 | kinds: trackers.map((tracker) => tracker.kind), |
| 34 | standalone: trackers.filter(isStandaloneIssueTracker), |
| 35 | }; |
| 36 | } |
| 37 | |
| 38 | /** Trackers that are not a git host's own. Each signs requests with a credential from Settings. */ |
| 39 | const STANDALONE_TRACKERS = [LinearDriver.make]; |
| 40 | |
| 41 | const make = Effect.gen(function* () { |
| 42 | const drivers = yield* BuiltInDrivers.SourceControlDrivers; |
| 43 | const standalone = yield* Effect.all(STANDALONE_TRACKERS); |
| 44 | return fromTrackers([...drivers.flatMap(({ instance }) => instance.issues ?? []), ...standalone]); |
| 45 | }); |
| 46 | |
| 47 | export const layer = Layer.effect(IssueTrackerRegistry, make).pipe( |
| 48 | Layer.provide(Layer.merge(BuiltInDrivers.layer, IssueTrackerHostLive.layer)), |
| 49 | ); |