40 lines
1.7 KiB
TypeScript
40 lines
1.7 KiB
TypeScript
/**
|
|
* ServiceRegistry module augmentation — declares the `authService`
|
|
* slot on `@suaveplan/api-plugin/service-registry`'s `ServiceRegistry`
|
|
* interface so downstream plugins typed against the augmented registry
|
|
* see `ctx.getService("authService")` resolve to `AuthService |
|
|
* undefined` without any cast.
|
|
*
|
|
* Importing this module for its side effects (which the package root
|
|
* barrel does automatically) is sufficient — every consumer of
|
|
* `@suaveplan/api-plugin-auth` gets typed `authService` access.
|
|
*
|
|
* The host-side slots (`app`, `openAPIRegistry`, `migrationRunner`,
|
|
* `db`, `logger`, `eventBus`, `clock`) are owned by `@suaveplan/api`'s
|
|
* own registry-augmentation module. We re-declare them here as a
|
|
* cumulative augmentation so the auth plugin's `onInit(ctx)` can
|
|
* resolve them with full typing even when the consumer has not
|
|
* explicitly imported `@suaveplan/api` (e.g. during isolated
|
|
* unit-tests of the plugin). TypeScript merges duplicate declarations,
|
|
* so this is safe alongside `@suaveplan/api`'s declarations.
|
|
*/
|
|
import type { OpenAPIHono } from "@hono/zod-openapi";
|
|
import type { MigrationRunner } from "@suaveplan/api-migrations";
|
|
import type { OpenAPIRegistry } from "@suaveplan/api-openapi";
|
|
import type { SurrealAdapter } from "@suaveplan/surrealdb";
|
|
import type { Clock, EventBusLike, LoggerLike } from "@suaveplan/types";
|
|
import type { AuthService } from "./auth-service.js";
|
|
|
|
declare module "@suaveplan/api-plugin/service-registry" {
|
|
interface ServiceRegistry {
|
|
authService: AuthService;
|
|
app: OpenAPIHono;
|
|
openAPIRegistry: OpenAPIRegistry;
|
|
migrationRunner?: MigrationRunner;
|
|
db?: SurrealAdapter;
|
|
logger: LoggerLike;
|
|
eventBus: EventBusLike;
|
|
clock: Clock;
|
|
}
|
|
}
|