/** * Base types for plugin registry that can be extended by users using declaration merging. * This solves issue where published libraries can't know about user's plugins. */ import type { IPlugin } from "../types"; /** * Base API interface that all plugins extend. * Users can extend this interface with their own plugin APIs. */ export interface BasePluginApi { name: string; version: string; actions?: string[]; type?: string; loaded?: string; } /** * Plugin factory map - users can extend this with their own plugins. * * This interface can be extended by users using declaration merging. * * Example of how users extend this: * ```typescript * declare module "bun_plugins" { * export interface PluginFactory { * "my-custom-plugin": { * name: "my-custom-plugin"; * version: "1.0.0"; * class: MyCustomPlugin; * api: MyCustomPluginApi; * }; * } * } * * // Now you can use context.getPlugin("my-custom-plugin") with full autocomplete * const api = await context.getPlugin("my-custom-plugin"); * api.myCustomMethod(); * ``` */ export interface PluginFactory { } /** * Union type of all plugin names. * This is dynamically computed from PluginFactory keys. * For development, we allow any string to be used as plugin name. */ export type PluginNames = keyof PluginFactory | string; /** * Get the API type for a specific plugin. * Falls back to BasePluginApi if the plugin is not found. */ export type PluginApiType = T extends keyof PluginFactory ? PluginFactory[T]["api"] : BasePluginApi; /** * Get the class type for a specific plugin. * Falls back to IPlugin if the plugin is not found. */ export type PluginClassType = T extends keyof PluginFactory ? PluginFactory[T]["class"] : IPlugin; /** * Get the API type for a specific plugin. */ export type GetPluginApi = PluginApiType; /** * Get the class type for a specific plugin. */ export type GetPluginClass = PluginClassType; /** * Helper to check if a plugin name is valid. * Returns true if the plugin is in PluginFactory. */ export type IsValidPlugin = T extends PluginNames ? true : false; /** * Type-safe plugin retrieval from the factory. * Returns the plugin info if found, undefined otherwise. */ export type PluginFromFactory = T extends keyof PluginFactory ? PluginFactory[T] : undefined; /** * Plugin instance type - combines class and API types. */ export type PluginInstanceType = T extends keyof PluginFactory ? PluginFactory[T]["class"] : IPlugin; //# sourceMappingURL=plugin-registry-base.d.ts.map