UNPKG

@api-buddy/types

Version:

Shared types for API Buddy

156 lines 5.34 kB
import type { Command } from 'commander'; /** * Plugin System Types * * This file contains type definitions for the plugin system. */ export interface PluginHookContext { /** Plugin configuration */ config: Record<string, unknown>; /** Logger instance */ logger: { info: (message: string, meta?: Record<string, unknown>) => void; error: (message: string, meta?: Record<string, unknown>) => void; debug: (message: string, meta?: Record<string, unknown>) => void; }; /** Utility functions */ utils: { registerCommand: (command: Command) => void; registerHook: <T = unknown>(hookName: string, handler: (context: PluginHookContext, ...args: unknown[]) => T | Promise<T>) => void; }; /** Shared data store */ data: Map<string, unknown>; } export interface PluginCommandOption { /** CLI flags (e.g., '--output <path>') */ flags: string; /** Description of the option */ description?: string; /** Default value if not provided */ defaultValue?: unknown; /** Whether the option is required */ required?: boolean; } export interface PluginCommand { /** Name of the command */ name: string; /** Description of the command */ description: string; /** Command options/flags */ options?: PluginCommandOption[]; /** * Command action handler * @param args - Positional arguments * @param options - Parsed options * @param context - Plugin context */ handler: (args: string[], options: Record<string, unknown>, context: PluginHookContext) => Promise<void> | void; } export interface PluginHooks { /** Called before the plugin is loaded */ 'before:load'?: (context: PluginHookContext) => Promise<void> | void; /** Called after the plugin is loaded */ 'after:load'?: (context: PluginHookContext) => Promise<void> | void; /** Called before the plugin is unloaded */ 'before:unload'?: (context: PluginHookContext) => Promise<void> | void; /** Custom hooks */ [hookName: string]: ((context: PluginHookContext, ...args: unknown[]) => unknown) | undefined; } export interface Plugin { /** Unique identifier for the plugin (e.g., @api-buddy/plugin-name) */ name: string; /** Semantic version of the plugin */ version: string; /** Human-readable description of the plugin */ description?: string; /** Lifecycle hooks and custom hooks */ hooks?: PluginHooks; /** CLI commands provided by the plugin */ commands?: Record<string, Omit<PluginCommand, 'name'>>; /** List of plugin dependencies */ dependencies?: string[]; /** Optional metadata */ metadata?: Record<string, unknown>; } export interface PluginManagerOptions { /** Time in milliseconds before a hook times out (default: 30000) */ hookTimeout?: number; /** Whether to continue loading other plugins if one fails (default: false) */ continueOnError?: boolean; /** Plugin installation directory */ pluginDir?: string; } export interface PluginManager { /** * Register a new plugin * @param plugin - The plugin to register */ register(plugin: Plugin): Promise<void>; /** * Unregister a plugin * @param pluginName - The name of the plugin to unregister */ unregister(pluginName: string): Promise<boolean>; /** * Get a plugin by name * @param pluginName - The name of the plugin to get */ getPlugin<T extends Plugin = Plugin>(pluginName: string): T | undefined; /** * Execute a hook * @param hookName - The name of the hook to execute * @param args - Arguments to pass to the hook */ executeHook<T = unknown>(hookName: string, ...args: unknown[]): Promise<T[]>; /** * Get all registered plugins */ getPlugins(): Map<string, Plugin>; /** * Load plugins from a directory * @param dir - Directory to load plugins from */ loadPlugins(dir: string): Promise<void>; } export interface PluginManifest { /** Package name */ name: string; /** Semantic version */ version: string; /** Package description */ description?: string; /** Main entry point */ main: string; /** TypeScript types entry point */ types?: string; /** Package keywords */ keywords?: string[]; /** Package author */ author?: string; /** Package license */ license?: string; /** Dependencies */ dependencies?: Record<string, string>; /** Peer dependencies */ peerDependencies?: Record<string, string>; /** API Buddy specific configuration */ apiBuddy?: { /** List of adapters this plugin provides */ adapters?: string[]; /** List of CLI commands this plugin provides */ commands?: string[]; /** List of templates this plugin provides */ templates?: string[]; /** Minimum required API Buddy version */ requires?: string; }; } export interface PluginModule { /** Plugin definition */ default: Plugin | (() => Plugin); /** Optional setup function */ setup?: (context: PluginHookContext) => Promise<void> | void; /** Optional teardown function */ teardown?: (context: PluginHookContext) => Promise<void> | void; } //# sourceMappingURL=plugin.types.d.ts.map