import { type Awaitable, type CapabilityRegistrar, type CapabilityResolver, type ModuleRegistrationContext as ContractModuleRegistrationContext, type ModuleRuntimeContext as ContractModuleRuntimeContext, type ModuleRuntimeServices as ContractModuleRuntimeServices, type ModuleConfiguration, type ModuleDatabaseAbiRuntimeDefinition, type ModuleDatabaseExecutor, type ModuleId, parseModuleRuntimeDefinition, } from "@ekklesia/contracts"; /** * What a module's `register` hook receives. `Database` is what `services.database` is for the * module: the Module Database ABI v1 executor when it declares `database: { abi: 1 }`, and `never` * when it declares no database, so code cannot reach a database it never declared. */ export type ModuleRegistrationContext< Database extends ModuleDatabaseExecutor = ModuleDatabaseExecutor, > = ContractModuleRegistrationContext; /** What a module's `start` and `stop` hooks receive. */ export type ModuleRuntimeContext = ContractModuleRuntimeContext; /** The platform services every hook and handler receives. `database` is the ABI v1 executor for a * module that declares one, and `never` otherwise. */ export type ModuleRuntimeServices< Database extends ModuleDatabaseExecutor = ModuleDatabaseExecutor, > = ContractModuleRuntimeServices; /** A module that declares the Module Database ABI v1 (ADR 0050). Its hooks and route handlers see * `services.database` as the ABI v1 executor. */ export interface ModuleRuntimeDefinitionWithDatabase extends ModuleDatabaseAbiRuntimeDefinition {} /** A module that uses no database. Its hooks see `services.database` as `never`. */ export interface ModuleRuntimeDefinitionWithoutDatabase { readonly id: ModuleId; readonly version: string; readonly database?: never; readonly register?: (context: ModuleRegistrationContext) => Awaitable; readonly start?: (context: ModuleRuntimeContext) => Awaitable; readonly stop?: (context: ModuleRuntimeContext) => Awaitable; } /** Every runtime definition the Module SDK supports. The legacy Drizzle database facade is not one * of them: a module that uses a database declares `database: { abi: 1 }` (ADR 0053). */ export type ModuleRuntimeDefinition = | ModuleRuntimeDefinitionWithDatabase | ModuleRuntimeDefinitionWithoutDatabase; /** * Validates and freezes a module's server runtime. The result is typed as one of this package's own * named interfaces, so a module that emits declarations can always name its runtime's type through * `@ekklesia/module-sdk`, without depending on the packages behind it. */ export function defineModuleRuntime( definition: ModuleRuntimeDefinitionWithDatabase, ): ModuleRuntimeDefinitionWithDatabase; export function defineModuleRuntime( definition: ModuleRuntimeDefinitionWithoutDatabase, ): ModuleRuntimeDefinitionWithoutDatabase; export function defineModuleRuntime(definition: ModuleRuntimeDefinition): ModuleRuntimeDefinition { return parseModuleRuntimeDefinition(definition) as ModuleRuntimeDefinition; } export type { Awaitable, CapabilityRegistrar, CapabilityResolver, ModuleConfiguration };