import { Plugin } from "./plugin.cjs"; import { Scope } from "effect"; import { AnyContractRouter, AnySchema, InferSchemaInput, InferSchemaOutput } from "@orpc/contract"; import { Router, RouterClient } from "@orpc/server"; //#region src/types.d.ts /** * Registry bindings interface - populated via module augmentation * Only needed for remote-only plugin entries. * @example * ```typescript * declare module "every-plugin" { * interface RegisteredPlugins { * "my-plugin": typeof MyPlugin; * } * } * ``` */ interface RegisteredPlugins {} /** * Base type for any plugin instance. */ type AnyPlugin = Plugin; /** * Loaded plugin constructor with binding information */ type AnyPluginConstructor = { new (): AnyPlugin; binding: { contract: AnyContractRouter; variables: AnySchema; secrets: AnySchema; context: AnySchema | undefined; }; }; /** * Registry entry that supports both direct module imports and remote URLs */ type PluginRegistryEntry = { module: AnyPluginConstructor; remote?: string; version?: string; description?: string; } | { remote: string; version?: string; description?: string; }; /** * Extract plugin constructor type from registry entry */ type ExtractPluginType = E extends { module: infer M; } ? M : never; /** * Infer registry types from plugin entries with module constructors */ type InferRegistryFromEntries> = { [K in keyof R]: R[K] extends { module: infer M; } ? M : K extends keyof RegisteredPlugins ? RegisteredPlugins[K] : never; }; /** * Extract contract type from plugin binding */ type PluginContract = T extends { binding: { contract: infer C extends AnyContractRouter; }; } ? C : never; /** * Extract variables type from plugin binding */ type PluginVariables = T extends { binding: { variables: infer V extends AnySchema; }; } ? V : never; /** * Extract secrets type from plugin binding */ type PluginSecrets = T extends { binding: { secrets: infer S extends AnySchema; }; } ? S : never; /** * Extract context schema type from plugin binding */ type PluginContext = T extends { binding: { context: infer C extends AnySchema | undefined; }; } ? C : never; /** * Extract router type from plugin binding * Uses 'any' for context to support nested router compositions */ type PluginRouterType = Router, any>; /** * Extract client type from plugin binding */ type PluginClientType = RouterClient>; /** * Extract plugin type from registered plugins by key * @param K - The plugin key * @param R - The registry type (defaults to RegisteredPlugins for module augmentation pattern) */ type RegisteredPlugin = R[K] extends { binding: infer B; } ? B extends { contract: infer C extends AnyContractRouter; variables: infer V extends AnySchema; secrets: infer S extends AnySchema; context: infer TRequestContext extends AnySchema | undefined; } ? Plugin : never : never; /** * Extract plugin constructor type from registry entry */ type PluginConstructor = RegisteredPlugin; /** * Extract context input type from plugin binding (for client creation) */ type PluginContextInput = PluginContext extends AnySchema ? InferSchemaInput> : never; /** * Extract config input type from plugin binding */ type PluginConfigInput = { variables: InferSchemaInput>; secrets: InferSchemaInput>; }; /** * Extract deps context type from plugin instance (used for initialization) */ type ContextOf = T extends Plugin ? TDeps : never; /** * Plugin metadata for remote loading */ type PluginMetadata = { readonly remoteUrl: string; readonly version?: string; readonly description?: string; }; /** * Runtime registry configuration supporting both module and remote entries */ type PluginRegistry = Record; /** * Legacy metadata-only registry (for backwards compatibility) */ type PluginMetadataRegistry = Record; /** * Configuration for secrets injection. * Secrets are hydrated into plugin configs using template replacement. */ interface SecretsConfig { [key: string]: string; } /** * Loaded plugin */ interface LoadedPlugin { readonly ctor: new () => T; readonly metadata: PluginMetadata; } /** * Instantiated plugin */ interface PluginInstance { readonly plugin: T; readonly metadata: PluginMetadata; } /** * Fully initialized plugin ready for use */ interface InitializedPlugin { readonly plugin: T; readonly metadata: PluginMetadata; readonly config: { variables: InferSchemaOutput; secrets: InferSchemaOutput; }; readonly context: ContextOf; readonly scope: Scope.CloseableScope; } /** * Helper type to detect type errors when looking up RegisteredPlugins */ type VerifyPluginBinding = R[K] extends { binding: infer B; } ? B extends { contract: AnyContractRouter; variables: AnySchema; secrets: AnySchema; context: AnySchema | undefined; } ? true : `❌ Plugin "${K & string}" is not properly registered. Ensure it extends plugin binding layout { contract, variables, secrets, context }.` : `❌ Plugin "${K & string}" is not properly registered. Missing binding property.`; /** * Result of runtime.usePlugin() call * @param K - The plugin key * @param R - The registry type (defaults to RegisteredPlugins for module augmentation pattern) */ type UsePluginResult = VerifyPluginBinding extends true ? { readonly createClient: (context?: PluginContextInput) => PluginClientType; readonly router: PluginRouterType; readonly metadata: PluginMetadata; readonly initialized: InitializedPlugin>; } : VerifyPluginBinding; /** * Runtime options */ interface RuntimeOptions { isolation?: "strict" | "shared" | "none"; memoryLimit?: string; concurrency?: number; resourceTimeout?: string; debug?: boolean; metrics?: boolean; } /** * Extract registry type from runtime instance or use type directly * This allows EveryPlugin.Infer to work with both: * - typeof runtime (extracts registry from PluginRuntime via __registryType) * - Registry types directly */ type RegistryOf = T extends { __registryType?: infer R; } ? R : T; /** * Namespace containing type utilities for working with plugin results. */ declare namespace EveryPlugin { /** * Extract plugin runtime instance type from registered plugins or runtime. * Provides full type safety for plugin clients, routers, and metadata. * * @example * ```ts * // From RegisteredPlugins (module augmentation) * type Plugin = EveryPlugin.Infer<"my-plugin">; * * // From runtime instance (when using module entries) * const runtime = createPluginRuntime({ registry: { "my-plugin": { module: MyPlugin } } }); * type Plugin = EveryPlugin.Infer<"my-plugin", typeof runtime>; * * // From explicit registry type * type Plugin = EveryPlugin.Infer<"my-plugin", MyRegistryType>; * ``` */ type Infer = K extends keyof RegistryOf ? UsePluginResult> : never; } /** * Plugin runtime configuration with support for both module and remote entries */ interface PluginRuntimeConfig = Record> { registry: R; secrets?: SecretsConfig; options?: RuntimeOptions; } /** * Legacy plugin runtime configuration (metadata-only registry) * @deprecated Use PluginRuntimeConfig with module/remote entries instead */ interface LegacyPluginRuntimeConfig { registry: PluginMetadataRegistry; secrets?: SecretsConfig; options?: RuntimeOptions; } //#endregion export { AnyPlugin, AnyPluginConstructor, ContextOf, EveryPlugin, ExtractPluginType, InferRegistryFromEntries, InitializedPlugin, LegacyPluginRuntimeConfig, LoadedPlugin, PluginClientType, PluginConfigInput, PluginConstructor, PluginContext, PluginContextInput, PluginContract, PluginInstance, PluginMetadata, PluginMetadataRegistry, PluginRegistry, PluginRegistryEntry, PluginRouterType, PluginRuntimeConfig, PluginSecrets, PluginVariables, RegisteredPlugin, RegisteredPlugins, RuntimeOptions, SecretsConfig, UsePluginResult }; //# sourceMappingURL=types.d.cts.map