opinionated-machine
Version:
Very opinionated DI framework for fastify, built on top of awilix
39 lines (38 loc) • 1.75 kB
TypeScript
import type { FastifyPluginCallback } from 'fastify';
import type { DIContext } from '../DIContext.ts';
import type { BuildGatewayManifestOptions } from './manifest/buildManifest.ts';
import type { GatewayManifest } from './manifest/manifestSchema.ts';
/**
* Function decoration installed on the Fastify instance by
* `fastifyGatewayPlugin`. Returns the gateway manifest, recomputed on every
* call so it always reflects the current set of registered controllers.
*
* Mirrors the spirit of `@fastify/swagger`'s `app.swagger()`.
*/
export type BuildGatewayManifestFn = (overrides?: Partial<BuildGatewayManifestOptions>) => GatewayManifest;
declare module 'fastify' {
interface FastifyInstance {
buildGatewayManifest: BuildGatewayManifestFn;
}
}
export type FastifyGatewayPluginOptions = {
/**
* The DI context that owns the controllers whose manifest we expose.
* The plugin calls `context.buildGatewayManifest()` lazily, so route
* registration order (plugin first vs. routes first) doesn't matter.
*/
context: DIContext<any, any, any>;
/** Default options applied to every `app.buildGatewayManifest()` call. */
defaults: BuildGatewayManifestOptions;
/**
* If set to a path string, exposes `GET <route>` returning the manifest as
* JSON. Useful when a CLI / sibling process wants to fetch the manifest
* over HTTP instead of loading the service code.
*
* **Opt-in.** No HTTP route is registered when this is omitted, so adding
* the plugin can never accidentally expose internal routing topology to
* unauthenticated callers.
*/
exposeRoute?: string;
};
export declare const fastifyGatewayPlugin: FastifyPluginCallback<FastifyGatewayPluginOptions>;