| 1 | /** |
| 2 | * SourceControlDriver — what a source control provider package hands the server. |
| 3 | * |
| 4 | * One driver per host kind. The server lists its drivers once and both registries (repository |
| 5 | * operations and pull requests) iterate that list, so adding a host means writing its package |
| 6 | * and adding its driver to the list. |
| 7 | * |
| 8 | * `make` yields what it needs from the environment: the `SourceControlHost` port, Effect |
| 9 | * platform services, and the package's own services, which the server provides from the |
| 10 | * package's layers. Its `R` channel is the full list. |
| 11 | * |
| 12 | * @module source-control-core/server/driver |
| 13 | */ |
| 14 | import type { SourceControlProviderKind } from "@t3tools/contracts"; |
| 15 | import type * as Effect from "effect/Effect"; |
| 16 | |
| 17 | import type { SourceControlProviderDiscoverySpec } from "./discovery.ts"; |
| 18 | import type { PullRequestProviderApi } from "./PullRequestProvider.ts"; |
| 19 | import type * as SourceControlProvider from "./SourceControlProvider.ts"; |
| 20 | |
| 21 | export interface SourceControlDriverInstance { |
| 22 | readonly sourceControl: SourceControlProvider.SourceControlProvider["Service"]; |
| 23 | readonly discovery: SourceControlProviderDiscoverySpec; |
| 24 | /** Null for a host whose pull requests this build cannot read. */ |
| 25 | readonly pullRequests: PullRequestProviderApi | null; |
| 26 | } |
| 27 | |
| 28 | export interface SourceControlDriver<R = never> { |
| 29 | readonly kind: SourceControlProviderKind; |
| 30 | readonly make: Effect.Effect<SourceControlDriverInstance, never, R>; |
| 31 | } |
| 32 | |
| 33 | /** Declares a driver with its `R` inferred from `make`. */ |
| 34 | export const defineSourceControlDriver = <R>( |
| 35 | driver: SourceControlDriver<R>, |
| 36 | ): SourceControlDriver<R> => driver; |