/** * Manifest Plugin API — stable contract for third-party extensions. * * Exposes five extension points that map 1:1 to existing internal interfaces: * 1. Projection targets (code generators) * 2. Store adapters (persistence backends) * 3. Audit sinks (audit trail consumers) * 4. Builtin functions (expression evaluation extensions) * 5. CLI commands (CLI extensions) * * Plugins are loaded via `@angriff36/manifest/plugin-loader` and declared in * `manifest.config.yaml` under the `plugins` key. * * IR-FIRST: This API has no IR mutation hooks. Plugins extend tooling and * runtime, never language semantics. */ import type { ProjectionTarget } from './projections/interface'; import type { AuditSink } from './audit/audit-sink'; import type { IR } from './ir'; /** Current Plugin API version. Plugins must declare this exact value. */ export declare const PLUGIN_API_VERSION = "1"; /** * Minimal CLI program interface — decoupled from commander.js so plugins * don't need to import commander as a dependency. */ export interface CliProgramLike { command(name: string): { description(d: string): { action(fn: (...args: unknown[]) => void | Promise): unknown; }; }; } /** * Entity instance shape — matches runtime-engine.ts EntityInstance. */ export interface EntityInstance { id: string; [key: string]: unknown; } /** * Store interface — matches runtime-engine.ts Store. */ export interface Store { getAll(): Promise; getById(id: string): Promise; create(data: Partial): Promise; update(id: string, data: Partial): Promise; delete(id: string): Promise; clear(): Promise; } /** * Static metadata every plugin must embed. */ export interface PluginManifest { /** Unique plugin identifier (npm-style: '@scope/name' or 'name'). */ name: string; /** Plugin's own SemVer version. */ version: string; /** Must match PLUGIN_API_VERSION exactly. */ pluginApiVersion: typeof PLUGIN_API_VERSION; /** SemVer range for compatible Manifest package versions. */ manifestVersion: string; /** Optional human-readable description. */ description?: string; } /** * Built-in store target names reserved by the Manifest runtime. * Plugin-registered store adapters MUST NOT use these as scheme names. */ export declare const BUILTIN_STORE_TARGETS: ReadonlySet; /** * Store adapter plugin. Registered by URI scheme and used by the runtime * engine's storeProvider to create Store instances for entities. * * The scheme MUST NOT collide with built-in targets (see BUILTIN_STORE_TARGETS). * Custom adapters are resolved by the CompositeStoreProvider built by the * plugin loader during runtime initialization. * * @example * ```ts * const redisAdapter: StoreAdapterPlugin = { * scheme: 'redis', * createStore(entityName, options) { * return new RedisStore(entityName, options?.connectionUrl); * }, * }; * ``` */ export interface StoreAdapterPlugin { /** URI scheme this adapter handles (e.g. 'redis', 'dynamodb'). */ scheme: string; /** * Factory to create a Store for the given entity. * @param entityName - IR entity name * @param options - Plugin-specific options from manifest.config.yaml */ createStore(entityName: string, options?: Record): Store | Promise; } /** * Audit sink plugin. Provides a named AuditSink factory. */ export interface AuditSinkPlugin { /** Unique sink identifier (e.g. 'opentelemetry', 'datadog'). */ id: string; /** * Factory to create an AuditSink. * @param options - Plugin-specific options from manifest.config.yaml */ createSink(options?: Record): AuditSink | Promise; } /** Purity classification for builtin functions. */ export type BuiltinPurity = 'pure' | 'time-dependent' | 'random'; /** * Builtin function plugin. Extends the runtime engine's expression evaluator * with custom functions. * * RESERVED NAMES (cannot be overridden): * now, uuid, trim, split, count, startsWith, endsWith, replace, * toUpperCase, toLowerCase, length, substring, indexOf, matches, * abs, round, floor, ceil, min, max, between, * sum, avg, min_of, max_of, count_of, filter, map, flat_map, unique_of, * year, month, day, hours, minutes, seconds */ export interface BuiltinFunctionPlugin { /** Function name (must not collide with reserved builtins). */ name: string; /** Purity declaration — enables future static analysis. */ purity: BuiltinPurity; /** Number of required arguments (-1 for variadic). */ arity: number; /** The function implementation. */ fn: (...args: unknown[]) => unknown; } /** * CLI command plugin. Receives a minimal program interface to register * commands without coupling to commander.js. */ export interface CliCommandPlugin { /** Command name (e.g. 'my-command'). */ name: string; /** Register the command with the CLI program. */ register(program: CliProgramLike): void; } /** * Runtime context passed to plugin onLoad hooks. */ export interface PluginContext { /** Compiled IR (available after compile phase). */ ir?: IR; /** Plugin-specific options from manifest.config.yaml. */ options: Record; /** Manifest package version. */ manifestVersion: string; } /** * A Manifest plugin. Plugins export this interface (as default or named * `plugin` export) and the loader discovers and validates it. */ export interface ManifestPlugin { /** Required static metadata. */ manifest: PluginManifest; /** Projection targets to register. */ projections?: ProjectionTarget[]; /** Store adapter factories. */ storeAdapters?: StoreAdapterPlugin[]; /** Audit sink factories. */ auditSinks?: AuditSinkPlugin[]; /** Expression builtin functions. */ builtins?: BuiltinFunctionPlugin[]; /** CLI command extensions. */ cliCommands?: CliCommandPlugin[]; /** Lifecycle hook — called after the plugin is loaded and validated. */ onLoad?(ctx: PluginContext): void | Promise; } /** * Type-safe helper for defining a Manifest plugin. Provides compile-time * validation of the plugin shape. * * @example * ```ts * import { definePlugin } from '@angriff36/manifest/plugin-api'; * * export default definePlugin({ * manifest: { * name: '@acme/manifest-plugin-hono', * version: '1.0.0', * pluginApiVersion: '1', * manifestVersion: '>=1.0.0', * description: 'Hono projection for Manifest', * }, * projections: [honoProjection], * storeAdapters: [redisStoreAdapter], * }); * ``` */ export declare function definePlugin(plugin: ManifestPlugin): ManifestPlugin; /** * Names reserved by Manifest's built-in expression functions. * Plugins cannot register builtins with these names. */ export declare const RESERVED_BUILTIN_NAMES: ReadonlySet; //# sourceMappingURL=plugin-api.d.ts.map