@kubb/core
Advanced tools
| import { t as __name } from "./chunk--u3MIqq1.js"; | ||
| import { EventEmitter } from "node:events"; | ||
| import { KubbFile } from "@kubb/fabric-core/types"; | ||
| import { Printer, PrinterFactoryOptions, RootNode } from "@kubb/ast/types"; | ||
| import { Fabric } from "@kubb/react-fabric/types"; | ||
| //#region ../../internals/utils/dist/index.d.ts | ||
| /** | ||
| * A typed EventEmitter that awaits all async listeners before resolving. | ||
| * Wraps Node's `EventEmitter` with full TypeScript event-map inference. | ||
| */ | ||
| declare var AsyncEventEmitter: { | ||
| new (maxListener?: number): { | ||
| "__#private@#emitter": EventEmitter<[never]>; | ||
| /** | ||
| * Emits an event and awaits all registered listeners in parallel. | ||
| * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments. | ||
| */ | ||
| emit(eventName: any, ...eventArgs: any[]): Promise<void>; /** Registers a persistent listener for the given event. */ | ||
| on(eventName: any, handler: any): void; /** Registers a one-shot listener that removes itself after the first invocation. */ | ||
| onOnce(eventName: any, handler: any): void; /** Removes a previously registered listener. */ | ||
| off(eventName: any, handler: any): void; /** Removes all listeners from every event channel. */ | ||
| removeAll(): void; | ||
| }; | ||
| }; | ||
| /** | ||
| * Parses and transforms an OpenAPI/Swagger path string into various URL formats. | ||
| * | ||
| * @example | ||
| * const p = new URLPath('/pet/{petId}') | ||
| * p.URL // '/pet/:petId' | ||
| * p.template // '`/pet/${petId}`' | ||
| */ | ||
| declare var URLPath: { | ||
| new (path: any, options?: {}): { | ||
| /** The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`. */path: any; | ||
| "__#private@#options": {}; /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */ | ||
| get URL(): any; /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`). */ | ||
| get isURL(): boolean; | ||
| /** | ||
| * Converts the OpenAPI path to a TypeScript template literal string. | ||
| * | ||
| * @example | ||
| * new URLPath('/pet/{petId}').template // '`/pet/${petId}`' | ||
| * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`' | ||
| */ | ||
| get template(): string; /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set. */ | ||
| get object(): string | { | ||
| url: any; | ||
| params: {} | undefined; | ||
| }; /** Returns a map of path parameter names, or `undefined` when the path has no parameters. */ | ||
| get params(): {} | undefined; | ||
| "__#private@#transformParam"(raw: any): any; /** Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name. */ | ||
| "__#private@#eachParam"(fn: any): void; | ||
| toObject({ | ||
| type, | ||
| replacer, | ||
| stringify | ||
| }?: { | ||
| type?: string | undefined; | ||
| }): string | { | ||
| url: any; | ||
| params: {} | undefined; | ||
| }; | ||
| /** | ||
| * Converts the OpenAPI path to a TypeScript template literal string. | ||
| * An optional `replacer` can transform each extracted parameter name before interpolation. | ||
| * | ||
| * @example | ||
| * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`' | ||
| */ | ||
| toTemplateString({ | ||
| prefix, | ||
| replacer | ||
| }?: { | ||
| prefix?: string | undefined; | ||
| }): string; | ||
| /** | ||
| * Extracts all `{param}` segments from the path and returns them as a key-value map. | ||
| * An optional `replacer` transforms each parameter name in both key and value positions. | ||
| * Returns `undefined` when no path parameters are found. | ||
| */ | ||
| getParams(replacer: any): {} | undefined; /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */ | ||
| toURLPath(): any; | ||
| }; | ||
| }; | ||
| /** | ||
| * Serializes a primitive value to a JSON string literal, stripping any surrounding quote characters first. | ||
| * | ||
| * @example | ||
| * stringify('hello') // '"hello"' | ||
| * stringify('"hello"') // '"hello"' | ||
| */ | ||
| declare function stringify(value: any): string; | ||
| //#endregion | ||
| //#region src/constants.d.ts | ||
| declare const DEFAULT_STUDIO_URL: "https://studio.kubb.dev"; | ||
| declare const logLevel: { | ||
| readonly silent: number; | ||
| readonly error: 0; | ||
| readonly warn: 1; | ||
| readonly info: 3; | ||
| readonly verbose: 4; | ||
| readonly debug: 5; | ||
| }; | ||
| declare const linters: { | ||
| readonly eslint: { | ||
| readonly command: "eslint"; | ||
| readonly args: (outputPath: string) => string[]; | ||
| readonly errorMessage: "Eslint not found"; | ||
| }; | ||
| readonly biome: { | ||
| readonly command: "biome"; | ||
| readonly args: (outputPath: string) => string[]; | ||
| readonly errorMessage: "Biome not found"; | ||
| }; | ||
| readonly oxlint: { | ||
| readonly command: "oxlint"; | ||
| readonly args: (outputPath: string) => string[]; | ||
| readonly errorMessage: "Oxlint not found"; | ||
| }; | ||
| }; | ||
| declare const formatters: { | ||
| readonly prettier: { | ||
| readonly command: "prettier"; | ||
| readonly args: (outputPath: string) => string[]; | ||
| readonly errorMessage: "Prettier not found"; | ||
| }; | ||
| readonly biome: { | ||
| readonly command: "biome"; | ||
| readonly args: (outputPath: string) => string[]; | ||
| readonly errorMessage: "Biome not found"; | ||
| }; | ||
| readonly oxfmt: { | ||
| readonly command: "oxfmt"; | ||
| readonly args: (outputPath: string) => string[]; | ||
| readonly errorMessage: "Oxfmt not found"; | ||
| }; | ||
| }; | ||
| //#endregion | ||
| //#region src/defineStorage.d.ts | ||
| /** | ||
| * Storage interface for persisting Kubb output. | ||
| * | ||
| * Keys are root-relative forward-slash paths (e.g. `src/gen/api/getPets.ts`). | ||
| * Implement this interface to route generated files to any backend — filesystem, | ||
| * S3, Redis, in-memory, etc. | ||
| * | ||
| * Use `defineStorage` to create a typed storage driver. | ||
| */ | ||
| interface DefineStorage { | ||
| /** Identifier used for logging and debugging (e.g. `'fs'`, `'s3'`). */ | ||
| readonly name: string; | ||
| /** Returns `true` when an entry for `key` exists in storage. */ | ||
| hasItem(key: string): Promise<boolean>; | ||
| /** Returns the stored string value, or `null` when `key` does not exist. */ | ||
| getItem(key: string): Promise<string | null>; | ||
| /** Persists `value` under `key`, creating any required structure. */ | ||
| setItem(key: string, value: string): Promise<void>; | ||
| /** Removes the entry for `key`. No-ops when the key does not exist. */ | ||
| removeItem(key: string): Promise<void>; | ||
| /** Returns all keys, optionally filtered to those starting with `base`. */ | ||
| getKeys(base?: string): Promise<Array<string>>; | ||
| /** Removes all entries, optionally scoped to those starting with `base`. */ | ||
| clear(base?: string): Promise<void>; | ||
| /** Optional teardown hook called after the build completes. */ | ||
| dispose?(): Promise<void>; | ||
| } | ||
| /** | ||
| * Wraps a storage builder so the `options` argument is optional, following the | ||
| * same factory pattern as `definePlugin`, `defineLogger`, and `defineAdapter`. | ||
| * | ||
| * The builder receives the resolved options object and must return a | ||
| * `DefineStorage`-compatible object that includes a `name` string. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { defineStorage } from '@kubb/core' | ||
| * | ||
| * export const memoryStorage = defineStorage((_options) => { | ||
| * const store = new Map<string, string>() | ||
| * return { | ||
| * name: 'memory', | ||
| * async hasItem(key) { return store.has(key) }, | ||
| * async getItem(key) { return store.get(key) ?? null }, | ||
| * async setItem(key, value) { store.set(key, value) }, | ||
| * async removeItem(key) { store.delete(key) }, | ||
| * async getKeys() { return [...store.keys()] }, | ||
| * async clear() { store.clear() }, | ||
| * } | ||
| * }) | ||
| * ``` | ||
| */ | ||
| declare function defineStorage<TOptions = Record<string, never>>(build: (options: TOptions) => DefineStorage): (options?: TOptions) => DefineStorage; | ||
| //#endregion | ||
| //#region src/PluginManager.d.ts | ||
| type RequiredPluginLifecycle = Required<PluginLifecycle>; | ||
| type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq'; | ||
| type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H]; | ||
| type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = { | ||
| result: Result; | ||
| plugin: Plugin; | ||
| }; | ||
| type Options = { | ||
| fabric: Fabric; | ||
| events: AsyncEventEmitter<KubbEvents>; | ||
| /** | ||
| * @default Number.POSITIVE_INFINITY | ||
| */ | ||
| concurrency?: number; | ||
| }; | ||
| type GetFileProps<TOptions = object> = { | ||
| name: string; | ||
| mode?: KubbFile.Mode; | ||
| extname: KubbFile.Extname; | ||
| pluginKey: Plugin['key']; | ||
| options?: TOptions; | ||
| }; | ||
| declare function getMode(fileOrFolder: string | undefined | null): KubbFile.Mode; | ||
| declare class PluginManager { | ||
| #private; | ||
| readonly config: Config; | ||
| readonly options: Options; | ||
| /** | ||
| * The universal `@kubb/ast` `RootNode` produced by the adapter, set by | ||
| * the build pipeline after the adapter's `parse()` resolves. | ||
| */ | ||
| rootNode: RootNode | undefined; | ||
| constructor(config: Config, options: Options); | ||
| get events(): AsyncEventEmitter<KubbEvents>; | ||
| getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, unknown>; | ||
| get plugins(): Array<Plugin>; | ||
| getFile<TOptions = object>({ | ||
| name, | ||
| mode, | ||
| extname, | ||
| pluginKey, | ||
| options | ||
| }: GetFileProps<TOptions>): KubbFile.File<{ | ||
| pluginKey: Plugin['key']; | ||
| }>; | ||
| resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path; | ||
| resolveName: (params: ResolveNameParams) => string; | ||
| /** | ||
| * Run a specific hookName for plugin x. | ||
| */ | ||
| hookForPlugin<H extends PluginLifecycleHooks>({ | ||
| pluginKey, | ||
| hookName, | ||
| parameters | ||
| }: { | ||
| pluginKey: Plugin['key']; | ||
| hookName: H; | ||
| parameters: PluginParameter<H>; | ||
| }): Promise<Array<ReturnType<ParseResult<H>> | null>>; | ||
| /** | ||
| * Run a specific hookName for plugin x. | ||
| */ | ||
| hookForPluginSync<H extends PluginLifecycleHooks>({ | ||
| pluginKey, | ||
| hookName, | ||
| parameters | ||
| }: { | ||
| pluginKey: Plugin['key']; | ||
| hookName: H; | ||
| parameters: PluginParameter<H>; | ||
| }): Array<ReturnType<ParseResult<H>>> | null; | ||
| /** | ||
| * Returns the first non-null result. | ||
| */ | ||
| hookFirst<H extends PluginLifecycleHooks>({ | ||
| hookName, | ||
| parameters, | ||
| skipped | ||
| }: { | ||
| hookName: H; | ||
| parameters: PluginParameter<H>; | ||
| skipped?: ReadonlySet<Plugin> | null; | ||
| }): Promise<SafeParseResult<H>>; | ||
| /** | ||
| * Returns the first non-null result. | ||
| */ | ||
| hookFirstSync<H extends PluginLifecycleHooks>({ | ||
| hookName, | ||
| parameters, | ||
| skipped | ||
| }: { | ||
| hookName: H; | ||
| parameters: PluginParameter<H>; | ||
| skipped?: ReadonlySet<Plugin> | null; | ||
| }): SafeParseResult<H> | null; | ||
| /** | ||
| * Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings. | ||
| */ | ||
| hookParallel<H extends PluginLifecycleHooks, TOutput = void>({ | ||
| hookName, | ||
| parameters | ||
| }: { | ||
| hookName: H; | ||
| parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined; | ||
| }): Promise<Awaited<TOutput>[]>; | ||
| /** | ||
| * Chains plugins | ||
| */ | ||
| hookSeq<H extends PluginLifecycleHooks>({ | ||
| hookName, | ||
| parameters | ||
| }: { | ||
| hookName: H; | ||
| parameters?: PluginParameter<H>; | ||
| }): Promise<void>; | ||
| getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined; | ||
| getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[]; | ||
| } | ||
| //#endregion | ||
| //#region src/Kubb.d.ts | ||
| type DebugEvent = { | ||
| date: Date; | ||
| logs: string[]; | ||
| fileName?: string; | ||
| }; | ||
| type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = { | ||
| hookName: H; | ||
| plugins: Array<Plugin>; | ||
| }; | ||
| type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = { | ||
| hookName: H; | ||
| }; | ||
| type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = { | ||
| strategy: Strategy; | ||
| hookName: H; | ||
| plugin: Plugin; | ||
| parameters?: unknown[] | undefined; | ||
| output?: unknown; | ||
| }; | ||
| type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = { | ||
| duration: number; | ||
| strategy: Strategy; | ||
| hookName: H; | ||
| plugin: Plugin; | ||
| parameters?: unknown[] | undefined; | ||
| output?: unknown; | ||
| }; | ||
| /** | ||
| * Events emitted during the Kubb code generation lifecycle. | ||
| * These events can be listened to for logging, progress tracking, and custom integrations. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import type { AsyncEventEmitter } from '@kubb/core' | ||
| * import type { KubbEvents } from '@kubb/core' | ||
| * | ||
| * const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter() | ||
| * | ||
| * events.on('lifecycle:start', () => { | ||
| * console.log('Starting Kubb generation') | ||
| * }) | ||
| * | ||
| * events.on('plugin:end', (plugin, { duration }) => { | ||
| * console.log(`Plugin ${plugin.name} completed in ${duration}ms`) | ||
| * }) | ||
| * ``` | ||
| */ | ||
| interface KubbEvents { | ||
| /** | ||
| * Emitted at the beginning of the Kubb lifecycle, before any code generation starts. | ||
| */ | ||
| 'lifecycle:start': [version: string]; | ||
| /** | ||
| * Emitted at the end of the Kubb lifecycle, after all code generation is complete. | ||
| */ | ||
| 'lifecycle:end': []; | ||
| /** | ||
| * Emitted when configuration loading starts. | ||
| */ | ||
| 'config:start': []; | ||
| /** | ||
| * Emitted when configuration loading is complete. | ||
| */ | ||
| 'config:end': [configs: Array<Config>]; | ||
| /** | ||
| * Emitted when code generation phase starts. | ||
| */ | ||
| 'generation:start': [config: Config]; | ||
| /** | ||
| * Emitted when code generation phase completes. | ||
| */ | ||
| 'generation:end': [Config: Config, files: Array<KubbFile.ResolvedFile>, sources: Map<KubbFile.Path, string>]; | ||
| /** | ||
| * Emitted with a summary of the generation results. | ||
| * Contains summary lines, title, and success status. | ||
| */ | ||
| 'generation:summary': [Config: Config, { | ||
| failedPlugins: Set<{ | ||
| plugin: Plugin; | ||
| error: Error; | ||
| }>; | ||
| status: 'success' | 'failed'; | ||
| hrStart: [number, number]; | ||
| filesCreated: number; | ||
| pluginTimings?: Map<string, number>; | ||
| }]; | ||
| /** | ||
| * Emitted when code formatting starts (e.g., running Biome or Prettier). | ||
| */ | ||
| 'format:start': []; | ||
| /** | ||
| * Emitted when code formatting completes. | ||
| */ | ||
| 'format:end': []; | ||
| /** | ||
| * Emitted when linting starts. | ||
| */ | ||
| 'lint:start': []; | ||
| /** | ||
| * Emitted when linting completes. | ||
| */ | ||
| 'lint:end': []; | ||
| /** | ||
| * Emitted when plugin hooks execution starts. | ||
| */ | ||
| 'hooks:start': []; | ||
| /** | ||
| * Emitted when plugin hooks execution completes. | ||
| */ | ||
| 'hooks:end': []; | ||
| /** | ||
| * Emitted when a single hook execution starts. (e.g., format or lint). | ||
| * The callback should be invoked when the command completes. | ||
| */ | ||
| 'hook:start': [{ | ||
| id?: string; | ||
| command: string; | ||
| args?: readonly string[]; | ||
| }]; | ||
| /** | ||
| * Emitted when a single hook execution completes. | ||
| */ | ||
| 'hook:end': [{ | ||
| id?: string; | ||
| command: string; | ||
| args?: readonly string[]; | ||
| success: boolean; | ||
| error: Error | null; | ||
| }]; | ||
| /** | ||
| * Emitted when a new version of Kubb is available. | ||
| */ | ||
| 'version:new': [currentVersion: string, latestVersion: string]; | ||
| /** | ||
| * Informational message event. | ||
| */ | ||
| info: [message: string, info?: string]; | ||
| /** | ||
| * Error event. Emitted when an error occurs during code generation. | ||
| */ | ||
| error: [error: Error, meta?: Record<string, unknown>]; | ||
| /** | ||
| * Success message event. | ||
| */ | ||
| success: [message: string, info?: string]; | ||
| /** | ||
| * Warning message event. | ||
| */ | ||
| warn: [message: string, info?: string]; | ||
| /** | ||
| * Debug event for detailed logging. | ||
| * Contains timestamp, log messages, and optional filename. | ||
| */ | ||
| debug: [meta: DebugEvent]; | ||
| /** | ||
| * Emitted when file processing starts. | ||
| * Contains the list of files to be processed. | ||
| */ | ||
| 'files:processing:start': [files: Array<KubbFile.ResolvedFile>]; | ||
| /** | ||
| * Emitted for each file being processed, providing progress updates. | ||
| * Contains processed count, total count, percentage, and file details. | ||
| */ | ||
| 'file:processing:update': [{ | ||
| /** Number of files processed so far */processed: number; /** Total number of files to process */ | ||
| total: number; /** Processing percentage (0-100) */ | ||
| percentage: number; /** Optional source identifier */ | ||
| source?: string; /** The file being processed */ | ||
| file: KubbFile.ResolvedFile; | ||
| /** | ||
| * Kubb configuration (not present in Fabric). | ||
| * Provides access to the current config during file processing. | ||
| */ | ||
| config: Config; | ||
| }]; | ||
| /** | ||
| * Emitted when file processing completes. | ||
| * Contains the list of processed files. | ||
| */ | ||
| 'files:processing:end': [files: KubbFile.ResolvedFile[]]; | ||
| /** | ||
| * Emitted when a plugin starts executing. | ||
| */ | ||
| 'plugin:start': [plugin: Plugin]; | ||
| /** | ||
| * Emitted when a plugin completes execution. | ||
| * Duration in ms | ||
| */ | ||
| 'plugin:end': [plugin: Plugin, meta: { | ||
| duration: number; | ||
| success: boolean; | ||
| error?: Error; | ||
| }]; | ||
| /** | ||
| * Emitted when plugin hook progress tracking starts. | ||
| * Contains the hook name and list of plugins to execute. | ||
| */ | ||
| 'plugins:hook:progress:start': [meta: ProgressStartMeta]; | ||
| /** | ||
| * Emitted when plugin hook progress tracking ends. | ||
| * Contains the hook name that completed. | ||
| */ | ||
| 'plugins:hook:progress:end': [meta: ProgressStopMeta]; | ||
| /** | ||
| * Emitted when a plugin hook starts processing. | ||
| * Contains strategy, hook name, plugin, parameters, and output. | ||
| */ | ||
| 'plugins:hook:processing:start': [meta: ExecutingMeta]; | ||
| /** | ||
| * Emitted when a plugin hook completes processing. | ||
| * Contains duration, strategy, hook name, plugin, parameters, and output. | ||
| */ | ||
| 'plugins:hook:processing:end': [meta: ExecutedMeta]; | ||
| } | ||
| //#endregion | ||
| //#region src/types.d.ts | ||
| declare global { | ||
| namespace Kubb { | ||
| interface PluginContext {} | ||
| } | ||
| } | ||
| /** | ||
| * Config used in `kubb.config.ts` | ||
| * | ||
| * @example | ||
| * import { defineConfig } from '@kubb/core' | ||
| * export default defineConfig({ | ||
| * ... | ||
| * }) | ||
| */ | ||
| type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins'> & { | ||
| /** | ||
| * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file. | ||
| * @default process.cwd() | ||
| */ | ||
| root?: string; | ||
| /** | ||
| * An array of Kubb plugins used for generation. Each plugin may have additional configurable options (defined within the plugin itself). If a plugin relies on another plugin, an error will occur if the required dependency is missing. Refer to “pre” for more details. | ||
| */ | ||
| plugins?: Array<Omit<UnknownUserPlugin, 'inject'>>; | ||
| }; | ||
| type InputPath = { | ||
| /** | ||
| * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root. | ||
| */ | ||
| path: string; | ||
| }; | ||
| type InputData = { | ||
| /** | ||
| * A `string` or `object` that contains your Swagger/OpenAPI data. | ||
| */ | ||
| data: string | unknown; | ||
| }; | ||
| type Input = InputPath | InputData | Array<InputPath>; | ||
| /** | ||
| * The raw source passed to an adapter's `parse` function. | ||
| * Mirrors the shape of `Config['input']` with paths already resolved to absolute. | ||
| */ | ||
| type AdapterSource = { | ||
| type: 'path'; | ||
| path: string; | ||
| } | { | ||
| type: 'data'; | ||
| data: string | unknown; | ||
| } | { | ||
| type: 'paths'; | ||
| paths: Array<string>; | ||
| }; | ||
| /** | ||
| * Type parameters for an adapter definition. | ||
| * | ||
| * Mirrors `PluginFactoryOptions` but scoped to the adapter lifecycle: | ||
| * - `TName` — unique string identifier (e.g. `'oas'`, `'asyncapi'`) | ||
| * - `TOptions` — raw user-facing options passed to the adapter factory | ||
| * - `TResolvedOptions` — defaults applied; what the adapter stores as `options` | ||
| */ | ||
| type AdapterFactoryOptions<TName extends string = string, TOptions extends object = object, TResolvedOptions extends object = TOptions> = { | ||
| name: TName; | ||
| options: TOptions; | ||
| resolvedOptions: TResolvedOptions; | ||
| }; | ||
| /** | ||
| * An adapter converts a source file or data into a `@kubb/ast` `RootNode`. | ||
| * | ||
| * Adapters are the single entry-point for different schema formats | ||
| * (OpenAPI, AsyncAPI, Drizzle, …) and produce the universal `RootNode` | ||
| * that all Kubb plugins consume. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { oasAdapter } from '@kubb/adapter-oas' | ||
| * | ||
| * export default defineConfig({ | ||
| * adapter: adapterOas(), // default — OpenAPI / Swagger | ||
| * input: { path: './openapi.yaml' }, | ||
| * plugins: [pluginTs(), pluginZod()], | ||
| * }) | ||
| * ``` | ||
| */ | ||
| type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = { | ||
| /** Human-readable identifier, e.g. `'oas'`, `'drizzle'`, `'asyncapi'`. */name: TOptions['name']; /** Resolved options (after defaults have been applied). */ | ||
| options: TOptions['resolvedOptions']; /** Convert the raw source into a universal `RootNode`. */ | ||
| parse: (source: AdapterSource) => PossiblePromise<RootNode>; | ||
| }; | ||
| type BarrelType = 'all' | 'named' | 'propagate'; | ||
| /** | ||
| * Object form of the barrel option, the forward-compatible replacement for `barrelType`. | ||
| * | ||
| * Available in v4 so a config can be migrated ahead of v5, where it becomes the only barrel option. | ||
| * See https://kubb.dev/docs/5.x/migration-guide | ||
| */ | ||
| type Barrel = { | ||
| /** | ||
| * How `index.ts` files re-export their files. | ||
| * - 'named' lists every export by name. | ||
| * - 'all' re-exports with a wildcard (`export *`). | ||
| * @default 'named' | ||
| */ | ||
| type?: Exclude<BarrelType, 'propagate'>; | ||
| /** | ||
| * Re-export the nested barrel files instead of the individual files. Replaces the legacy `'propagate'` value of `barrelType`. | ||
| * @default false | ||
| */ | ||
| nested?: boolean; | ||
| }; | ||
| type DevtoolsOptions = { | ||
| /** | ||
| * Open the AST inspector view (`/ast`) in Kubb Studio. | ||
| * When `false`, opens the main Studio page instead. | ||
| * @default false | ||
| */ | ||
| ast?: boolean; | ||
| }; | ||
| /** | ||
| * @private | ||
| */ | ||
| type Config<TInput = Input> = { | ||
| /** | ||
| * The name to display in the CLI output. | ||
| */ | ||
| name?: string; | ||
| /** | ||
| * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file. | ||
| * @default process.cwd() | ||
| */ | ||
| root: string; | ||
| /** | ||
| * Adapter that converts the input file into a `@kubb/ast` `RootNode` — the universal | ||
| * intermediate representation consumed by all Kubb plugins. | ||
| * | ||
| * - Omit (or pass `undefined`) to use the built-in OpenAPI/Swagger adapter. | ||
| * - Use `@kubb/adapter-oas` for explicit OpenAPI configuration (validate, contentType, …). | ||
| * - Use `@kubb/adapter-drizzle` or `@kubb/adapter-asyncapi` for other formats. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { drizzleAdapter } from '@kubb/adapter-drizzle' | ||
| * export default defineConfig({ | ||
| * adapter: drizzleAdapter(), | ||
| * input: { path: './src/schema.ts' }, | ||
| * }) | ||
| * ``` | ||
| */ | ||
| adapter?: Adapter; | ||
| /** | ||
| * You can use either `input.path` or `input.data`, depending on your specific needs. | ||
| */ | ||
| input: TInput; | ||
| output: { | ||
| /** | ||
| * The path where all generated files receives exported. | ||
| * This can be an absolute path or a path relative to the specified root option. | ||
| */ | ||
| path: string; | ||
| /** | ||
| * Clean the output directory before each build. | ||
| */ | ||
| clean?: boolean; | ||
| /** | ||
| * Save files to the file system. | ||
| * @default true | ||
| * @deprecated Use `storage` to control where files are written. | ||
| */ | ||
| write?: boolean; | ||
| /** | ||
| * Storage backend for generated files. | ||
| * Defaults to `fsStorage()` — the built-in filesystem driver. | ||
| * Accepts any object implementing the {@link DefineStorage} interface. | ||
| * Keys are root-relative paths (e.g. `src/gen/api/getPets.ts`). | ||
| * @default fsStorage() | ||
| * @example | ||
| * ```ts | ||
| * import { defineStorage, fsStorage } from '@kubb/core' | ||
| * storage: defineStorage(fsStorage()) | ||
| * ``` | ||
| */ | ||
| storage?: DefineStorage; | ||
| /** | ||
| * Specifies the formatting tool to be used. | ||
| * - 'auto' automatically detects and uses biome or prettier (in that order of preference). | ||
| * - 'prettier' uses Prettier for code formatting. | ||
| * - 'biome' uses Biome for code formatting. | ||
| * - 'oxfmt' uses Oxfmt for code formatting. | ||
| * - false disables code formatting. | ||
| * @default 'prettier' | ||
| */ | ||
| format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false; | ||
| /** | ||
| * Specifies the linter that should be used to analyze the code. | ||
| * - 'auto' automatically detects and uses biome, oxlint, or eslint (in that order of preference). | ||
| * - 'eslint' uses ESLint for linting. | ||
| * - 'biome' uses Biome for linting. | ||
| * - 'oxlint' uses Oxlint for linting. | ||
| * - false disables linting. | ||
| * @default 'auto' | ||
| */ | ||
| lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false; | ||
| /** | ||
| * Overrides the extension for generated imports and exports. By default, each plugin adds an extension. | ||
| * @default { '.ts': '.ts'} | ||
| */ | ||
| extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>; | ||
| /** | ||
| * Configures how `index.ts` files are created, including disabling barrel file generation. Each plugin has its own `barrelType` option; this setting controls the root barrel file (e.g., `src/gen/index.ts`). | ||
| * @default 'named' | ||
| * @deprecated Use the `output.barrel` object instead. See https://kubb.dev/docs/5.x/migration-guide | ||
| */ | ||
| barrelType?: Exclude<BarrelType, 'propagate'> | false; | ||
| /** | ||
| * Object form of {@link Config.output.barrelType} for the root barrel file (e.g., `src/gen/index.ts`). Prefer this over `barrelType`; it becomes the only barrel option in v5. | ||
| * - `{ type: 'named' }` lists every export by name. | ||
| * - `{ type: 'all' }` re-exports with a wildcard. | ||
| * - `false` disables the root barrel file. | ||
| * @default { type: 'named' } | ||
| */ | ||
| barrel?: Omit<Barrel, 'nested'> | false; | ||
| /** | ||
| * Adds a default banner to the start of every generated file indicating it was generated by Kubb. | ||
| * - 'simple' adds banner with link to Kubb. | ||
| * - 'full' adds source, title, description, and OpenAPI version. | ||
| * - false disables banner generation. | ||
| * @default 'simple' | ||
| */ | ||
| defaultBanner?: 'simple' | 'full' | false; | ||
| /** | ||
| * Whether to override existing external files if they already exist. | ||
| * When setting the option in the global configuration, all plugins inherit the same behavior by default. | ||
| * However, all plugins also have an `output.override` option, which can be used to override the behavior for a specific plugin. | ||
| * @default false | ||
| * @deprecated Removed in v5, where it no longer has any effect. See https://kubb.dev/docs/5.x/migration-guide | ||
| */ | ||
| override?: boolean; | ||
| }; | ||
| /** | ||
| * An array of Kubb plugins that used in the generation. | ||
| * Each plugin may include additional configurable options(defined in the plugin itself). | ||
| * If a plugin depends on another plugin, an error is returned if the required dependency is missing. See pre for more details. | ||
| */ | ||
| plugins?: Array<Plugin>; | ||
| /** | ||
| * Devtools configuration for Kubb Studio integration. | ||
| */ | ||
| devtools?: true | { | ||
| /** | ||
| * Override the Kubb Studio base URL. | ||
| * @default 'https://studio.kubb.dev' | ||
| */ | ||
| studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {}); | ||
| }; | ||
| /** | ||
| * Hooks triggered when a specific action occurs in Kubb. | ||
| */ | ||
| hooks?: { | ||
| /** | ||
| * Hook that triggers at the end of all executions. | ||
| * Useful for running Prettier or ESLint to format/lint your code. | ||
| */ | ||
| done?: string | Array<string>; | ||
| }; | ||
| }; | ||
| type PluginFactoryOptions< | ||
| /** | ||
| * Name to be used for the plugin, this will also be used for they key. | ||
| */ | ||
| TName extends string = string, | ||
| /** | ||
| * Options of the plugin. | ||
| */ | ||
| TOptions extends object = object, | ||
| /** | ||
| * Options of the plugin that can be used later on, see `options` inside your plugin config. | ||
| */ | ||
| TResolvedOptions extends object = TOptions, | ||
| /** | ||
| * Context that you want to expose to other plugins. | ||
| */ | ||
| TContext = unknown, | ||
| /** | ||
| * When calling `resolvePath` you can specify better types. | ||
| */ | ||
| TResolvePathOptions extends object = object> = { | ||
| name: TName; | ||
| /** | ||
| * Same behavior like what has been done with `QueryKey` in `@tanstack/react-query` | ||
| */ | ||
| key: PluginKey<TName | string>; | ||
| options: TOptions; | ||
| resolvedOptions: TResolvedOptions; | ||
| context: TContext; | ||
| resolvePathOptions: TResolvePathOptions; | ||
| }; | ||
| type PluginKey<TName> = [name: TName, identifier?: string | number]; | ||
| type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never; | ||
| type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = { | ||
| /** | ||
| * Unique name used for the plugin | ||
| * The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins. | ||
| * @example @kubb/typescript | ||
| */ | ||
| name: TOptions['name']; | ||
| /** | ||
| * Options set for a specific plugin(see kubb.config.js), passthrough of options. | ||
| */ | ||
| options: TOptions['resolvedOptions']; | ||
| /** | ||
| * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins. | ||
| * Can be used to validate dependent plugins. | ||
| */ | ||
| pre?: Array<string>; | ||
| /** | ||
| * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins. | ||
| */ | ||
| post?: Array<string>; | ||
| inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context']; | ||
| }; | ||
| type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>; | ||
| type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<any, any, any, any, any>>; | ||
| type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = { | ||
| /** | ||
| * Unique name used for the plugin | ||
| * @example @kubb/typescript | ||
| */ | ||
| name: TOptions['name']; | ||
| /** | ||
| * Internal key used when a developer uses more than one of the same plugin | ||
| * @private | ||
| */ | ||
| key: TOptions['key']; | ||
| /** | ||
| * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins. | ||
| * Can be used to validate dependent plugins. | ||
| */ | ||
| pre?: Array<string>; | ||
| /** | ||
| * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins. | ||
| */ | ||
| post?: Array<string>; | ||
| /** | ||
| * Options set for a specific plugin(see kubb.config.js), passthrough of options. | ||
| */ | ||
| options: TOptions['resolvedOptions']; | ||
| install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>; | ||
| /** | ||
| * Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`). | ||
| */ | ||
| inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context']; | ||
| }; | ||
| type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>; | ||
| type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = { | ||
| /** | ||
| * Start of the lifecycle of a plugin. | ||
| * @type hookParallel | ||
| */ | ||
| install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>; | ||
| /** | ||
| * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`). | ||
| * Options can als be included. | ||
| * @type hookFirst | ||
| * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts' | ||
| */ | ||
| resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path; | ||
| /** | ||
| * Resolve to a name based on a string. | ||
| * Useful when converting to PascalCase or camelCase. | ||
| * @type hookFirst | ||
| * @example ('pet') => 'Pet' | ||
| */ | ||
| resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string; | ||
| }; | ||
| type PluginLifecycleHooks = keyof PluginLifecycle; | ||
| type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>; | ||
| type ResolvePathParams<TOptions = object> = { | ||
| pluginKey?: Plugin['key']; | ||
| baseName: KubbFile.BaseName; | ||
| mode?: KubbFile.Mode; | ||
| /** | ||
| * Options to be passed to 'resolvePath' 3th parameter | ||
| */ | ||
| options?: TOptions; | ||
| }; | ||
| type ResolveNameParams = { | ||
| name: string; | ||
| pluginKey?: Plugin['key']; | ||
| /** | ||
| * Specifies the type of entity being named. | ||
| * - 'file' customizes the name of the created file (uses camelCase). | ||
| * - 'function' customizes the exported function names (uses camelCase). | ||
| * - 'type' customizes TypeScript types (uses PascalCase). | ||
| * - 'const' customizes variable names (uses camelCase). | ||
| * @default undefined | ||
| */ | ||
| type?: 'file' | 'function' | 'type' | 'const'; | ||
| }; | ||
| type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = { | ||
| fabric: Fabric; | ||
| config: Config; | ||
| pluginManager: PluginManager; | ||
| /** | ||
| * Only add when the file does not exist yet | ||
| */ | ||
| addFile: (...file: Array<KubbFile.File>) => Promise<void>; | ||
| /** | ||
| * merging multiple sources into the same output file | ||
| */ | ||
| upsertFile: (...file: Array<KubbFile.File>) => Promise<void>; | ||
| events: AsyncEventEmitter<KubbEvents>; | ||
| mode: KubbFile.Mode; | ||
| /** | ||
| * Current plugin | ||
| */ | ||
| plugin: Plugin<TOptions>; | ||
| /** | ||
| * Returns the universal `@kubb/ast` `RootNode` produced by the configured adapter. | ||
| * Returns `undefined` when no adapter was set (legacy OAS-only usage). | ||
| */ | ||
| rootNode: RootNode | undefined; | ||
| /** | ||
| * Opens the Kubb Studio URL for the current `rootNode` in the default browser. | ||
| * Falls back to printing the URL if the browser cannot be launched. | ||
| * No-ops silently when no adapter has set a `rootNode`. | ||
| */ | ||
| openInStudio: (options?: DevtoolsOptions) => Promise<void>; | ||
| } & Kubb.PluginContext; | ||
| /** | ||
| * Specify the export location for the files and define the behavior of the output | ||
| */ | ||
| type Output<TOptions> = { | ||
| /** | ||
| * Path to the output folder or file that will contain the generated code | ||
| */ | ||
| path: string; | ||
| /** | ||
| * Define what needs to be exported, here you can also disable the export of barrel files | ||
| * @default 'named' | ||
| * @deprecated Use the `output.barrel` object instead. See https://kubb.dev/docs/5.x/migration-guide | ||
| */ | ||
| barrelType?: BarrelType | false; | ||
| /** | ||
| * Object form of {@link Output.barrelType}. Prefer this over `barrelType`; it becomes the only barrel option in v5. | ||
| * - `{ type: 'named' }` lists every export by name. | ||
| * - `{ type: 'all' }` re-exports with a wildcard. | ||
| * - `{ type: 'named', nested: true }` replaces the legacy `'propagate'` value. | ||
| * - `false` disables the barrel file for this plugin. | ||
| * @default { type: 'named' } | ||
| */ | ||
| barrel?: Barrel | false; | ||
| /** | ||
| * Add a banner text in the beginning of every file | ||
| */ | ||
| banner?: string | ((options: TOptions) => string); | ||
| /** | ||
| * Add a footer text in the beginning of every file | ||
| */ | ||
| footer?: string | ((options: TOptions) => string); | ||
| /** | ||
| * Whether to override existing external files if they already exist. | ||
| * @default false | ||
| * @deprecated Removed in v5, where it no longer has any effect. See https://kubb.dev/docs/5.x/migration-guide | ||
| */ | ||
| override?: boolean; | ||
| }; | ||
| type GroupContext = { | ||
| group: string; | ||
| }; | ||
| type Group = { | ||
| /** | ||
| * Defines the type where to group the files. | ||
| * - 'tag' groups files by OpenAPI tags. | ||
| * - 'path' groups files by OpenAPI paths. | ||
| * @default undefined | ||
| */ | ||
| type: 'tag' | 'path'; | ||
| /** | ||
| * Return the name of a group based on the group name, this used for the file and name generation | ||
| */ | ||
| name?: (context: GroupContext) => string; | ||
| }; | ||
| type LoggerOptions = { | ||
| /** | ||
| * @default 3 | ||
| */ | ||
| logLevel: (typeof logLevel)[keyof typeof logLevel]; | ||
| }; | ||
| /** | ||
| * Shared context passed to all plugins, parsers, and Fabric internals. | ||
| */ | ||
| interface LoggerContext extends AsyncEventEmitter<KubbEvents> {} | ||
| type Install<TOptions = unknown> = (context: LoggerContext, options?: TOptions) => void | Promise<void>; | ||
| type Logger<TOptions extends LoggerOptions = LoggerOptions> = { | ||
| name: string; | ||
| install: Install<TOptions>; | ||
| }; | ||
| type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Omit<Logger<TOptions>, 'logLevel'>; | ||
| //#endregion | ||
| export { UserLogger as A, logLevel as B, PluginWithLifeCycle as C, ResolvePathParams as D, ResolveNameParams as E, getMode as F, URLPath as H, DefineStorage as I, defineStorage as L, UserPluginWithLifeCycle as M, KubbEvents as N, UnknownUserPlugin as O, PluginManager as P, formatters as R, PluginParameter as S, PrinterFactoryOptions as T, AsyncEventEmitter as V, PluginContext as _, BarrelType as a, PluginLifecycle as b, GetPluginFactoryOptions as c, InputPath as d, Logger as f, Plugin as g, Output as h, Barrel as i, UserPlugin as j, UserConfig as k, Group as l, LoggerOptions as m, AdapterFactoryOptions as n, Config as o, LoggerContext as p, AdapterSource as r, DevtoolsOptions as s, Adapter as t, InputData as u, PluginFactoryOptions as v, Printer as w, PluginLifecycleHooks as x, PluginKey as y, linters as z }; | ||
| //# sourceMappingURL=types-DsJhzsHG.d.ts.map |
| import type { Barrel, BarrelType } from '../types.ts' | ||
| type BarrelOutput = { | ||
| barrel?: Barrel | false | ||
| barrelType?: BarrelType | false | ||
| } | ||
| /** | ||
| * Resolve the effective barrel strategy from an output config. | ||
| * | ||
| * Prefers the object `barrel` option and falls back to the legacy `barrelType`. | ||
| * `barrel: { nested: true }` maps to the legacy `'propagate'` value, and | ||
| * `barrel: false` disables the barrel file. | ||
| */ | ||
| export function resolveBarrelType(output: BarrelOutput | undefined): BarrelType | false | undefined { | ||
| if (!output) { | ||
| return undefined | ||
| } | ||
| const { barrel } = output | ||
| if (barrel !== undefined) { | ||
| if (barrel === false) { | ||
| return false | ||
| } | ||
| if (barrel.nested) { | ||
| return 'propagate' | ||
| } | ||
| return barrel.type ?? 'named' | ||
| } | ||
| return output.barrelType | ||
| } |
+1
-1
| import { t as __name } from "./chunk--u3MIqq1.js"; | ||
| import { N as PluginManager, _ as PluginFactoryOptions, h as Plugin } from "./types-BwL2CHjl.js"; | ||
| import { P as PluginManager, g as Plugin, v as PluginFactoryOptions } from "./types-DsJhzsHG.js"; | ||
| import { KubbFile } from "@kubb/fabric-core/types"; | ||
@@ -4,0 +4,0 @@ |
+30
-3
| import { t as __name } from "./chunk--u3MIqq1.js"; | ||
| import { A as UserPlugin, B as AsyncEventEmitter, C as Printer, D as UnknownUserPlugin, E as ResolvePathParams, F as DefineStorage, I as defineStorage, L as formatters, M as KubbEvents, N as PluginManager, O as UserConfig, P as getMode, R as linters, S as PluginWithLifeCycle, T as ResolveNameParams, V as URLPath, _ as PluginFactoryOptions, a as Config, b as PluginLifecycleHooks, c as Group, d as Logger, f as LoggerContext, g as PluginContext, h as Plugin, i as BarrelType, j as UserPluginWithLifeCycle, k as UserLogger, l as InputData, m as Output, n as AdapterFactoryOptions, o as DevtoolsOptions, p as LoggerOptions, r as AdapterSource, s as GetPluginFactoryOptions, t as Adapter, u as InputPath, v as PluginKey, w as PrinterFactoryOptions, x as PluginParameter, y as PluginLifecycle, z as logLevel } from "./types-BwL2CHjl.js"; | ||
| import { A as UserLogger, B as logLevel, C as PluginWithLifeCycle, D as ResolvePathParams, E as ResolveNameParams, F as getMode, H as URLPath, I as DefineStorage, L as defineStorage, M as UserPluginWithLifeCycle, N as KubbEvents, O as UnknownUserPlugin, P as PluginManager, R as formatters, S as PluginParameter, T as PrinterFactoryOptions, V as AsyncEventEmitter, _ as PluginContext, a as BarrelType, b as PluginLifecycle, c as GetPluginFactoryOptions, d as InputPath, f as Logger, g as Plugin, h as Output, i as Barrel, j as UserPlugin, k as UserConfig, l as Group, m as LoggerOptions, n as AdapterFactoryOptions, o as Config, p as LoggerContext, r as AdapterSource, s as DevtoolsOptions, t as Adapter, u as InputData, v as PluginFactoryOptions, w as Printer, x as PluginLifecycleHooks, y as PluginKey, z as linters } from "./types-DsJhzsHG.js"; | ||
| import { definePrinter } from "@kubb/ast"; | ||
@@ -62,2 +62,10 @@ import { KubbFile } from "@kubb/fabric-core/types"; | ||
| * | ||
| * @deprecated Import `defineConfig` from `kubb` instead of `@kubb/core`. The `kubb` | ||
| * package wires up the OpenAPI adapter, the TypeScript parsers, and the barrel plugin | ||
| * for you. See the v5 migration guide: https://kubb.dev/docs/5.x/migration-guide | ||
| * | ||
| * ```ts | ||
| * import { defineConfig } from '@kubb/core' // [!code --] | ||
| * import { defineConfig } from 'kubb' // [!code ++] | ||
| * ``` | ||
| * @example | ||
@@ -281,4 +289,7 @@ * export default defineConfig(({ logLevel }) => ({ | ||
| type AddIndexesProps = { | ||
| type: BarrelType | false | undefined; | ||
| /** | ||
| * Explicit barrel strategy. When omitted it is resolved from `output.barrel` (preferred) or the legacy `output.barrelType`. | ||
| */ | ||
| type?: BarrelType | false; | ||
| /** | ||
| * Root based on root and output.path specified in the config | ||
@@ -292,2 +303,4 @@ */ | ||
| path: string; | ||
| barrel?: Barrel | false; | ||
| barrelType?: BarrelType | false; | ||
| }; | ||
@@ -317,3 +330,17 @@ group?: { | ||
| //#endregion | ||
| export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BarrelType, type CLIOptions, Config, type ConfigInput, DefineStorage, DevtoolsOptions, type FileMetaBase, FunctionParams, type FunctionParamsAST, GetPluginFactoryOptions, Group, InputData, InputPath, KubbEvents, Logger, LoggerContext, LoggerOptions, Output, PackageManager, Plugin, PluginContext, PluginFactoryOptions, PluginKey, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PluginWithLifeCycle, Printer, PrinterFactoryOptions, PromiseManager, ResolveNameParams, ResolvePathParams, URLPath, UnknownUserPlugin, UserConfig, UserLogger, UserPlugin, UserPluginWithLifeCycle, build, build as default, defineAdapter, defineConfig, defineLogger, definePlugin, definePrinter, defineStorage, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, isInputPath, linters, logLevel, memoryStorage, safeBuild, setup }; | ||
| //#region src/utils/resolveBarrelType.d.ts | ||
| type BarrelOutput = { | ||
| barrel?: Barrel | false; | ||
| barrelType?: BarrelType | false; | ||
| }; | ||
| /** | ||
| * Resolve the effective barrel strategy from an output config. | ||
| * | ||
| * Prefers the object `barrel` option and falls back to the legacy `barrelType`. | ||
| * `barrel: { nested: true }` maps to the legacy `'propagate'` value, and | ||
| * `barrel: false` disables the barrel file. | ||
| */ | ||
| declare function resolveBarrelType(output: BarrelOutput | undefined): BarrelType | false | undefined; | ||
| //#endregion | ||
| export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, Barrel, BarrelType, type CLIOptions, Config, type ConfigInput, DefineStorage, DevtoolsOptions, type FileMetaBase, FunctionParams, type FunctionParamsAST, GetPluginFactoryOptions, Group, InputData, InputPath, KubbEvents, Logger, LoggerContext, LoggerOptions, Output, PackageManager, Plugin, PluginContext, PluginFactoryOptions, PluginKey, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PluginWithLifeCycle, Printer, PrinterFactoryOptions, PromiseManager, ResolveNameParams, ResolvePathParams, URLPath, UnknownUserPlugin, UserConfig, UserLogger, UserPlugin, UserPluginWithLifeCycle, build, build as default, defineAdapter, defineConfig, defineLogger, definePlugin, definePrinter, defineStorage, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, isInputPath, linters, logLevel, memoryStorage, resolveBarrelType, safeBuild, setup }; | ||
| //# sourceMappingURL=index.d.ts.map |
+2
-2
| { | ||
| "name": "@kubb/core", | ||
| "version": "4.38.1", | ||
| "version": "4.39.0", | ||
| "description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.", | ||
@@ -74,3 +74,3 @@ "keywords": [ | ||
| "tinyexec": "^1.2.4", | ||
| "@kubb/ast": "4.38.1" | ||
| "@kubb/ast": "4.39.0" | ||
| }, | ||
@@ -77,0 +77,0 @@ "devDependencies": { |
+9
-6
@@ -16,2 +16,3 @@ import { dirname, relative, resolve } from 'node:path' | ||
| import type { FileMetaBase } from './utils/getBarrelFiles.ts' | ||
| import { resolveBarrelType } from './utils/resolveBarrelType.ts' | ||
@@ -165,3 +166,3 @@ type BuildOptions = { | ||
| ` • Storage: ${storage ? storage.name : 'disabled (dry-run)'}`, | ||
| ` • Barrel type: ${definedConfig.output.barrelType || 'none'}`, | ||
| ` • Barrel type: ${resolveBarrelType(definedConfig.output) || 'none'}`, | ||
| ], | ||
@@ -291,3 +292,4 @@ }) | ||
| if (config.output.barrelType) { | ||
| const rootBarrelType = resolveBarrelType(config.output) | ||
| if (rootBarrelType) { | ||
| const root = resolve(config.root) | ||
@@ -299,3 +301,3 @@ const rootPath = resolve(root, config.output.path, BARREL_FILENAME) | ||
| date: new Date(), | ||
| logs: ['Generating barrel file', ` • Type: ${config.output.barrelType}`, ` • Path: ${rootPath}`], | ||
| logs: ['Generating barrel file', ` • Type: ${rootBarrelType}`, ` • Path: ${rootPath}`], | ||
| }) | ||
@@ -368,2 +370,3 @@ | ||
| function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, pluginManager }: BuildBarrelExportsParams): KubbFile.Export[] { | ||
| const rootBarrelType = resolveBarrelType(config.output) | ||
| const pluginKeyMap = new Map<string, Plugin>() | ||
@@ -386,7 +389,7 @@ for (const plugin of pluginManager.plugins) { | ||
| if (!pluginOptions || pluginOptions.output?.barrelType === false) { | ||
| if (!pluginOptions || resolveBarrelType(pluginOptions.output) === false) { | ||
| return [] | ||
| } | ||
| const exportName = config.output.barrelType === 'all' ? undefined : source.name ? [source.name] : undefined | ||
| const exportName = rootBarrelType === 'all' ? undefined : source.name ? [source.name] : undefined | ||
| if (exportName?.some((n) => existingExports.has(n))) { | ||
@@ -400,3 +403,3 @@ return [] | ||
| path: getRelativePath(rootDir, file.path), | ||
| isTypeOnly: config.output.barrelType === 'all' ? containsOnlyTypes : source.isTypeOnly, | ||
| isTypeOnly: rootBarrelType === 'all' ? containsOnlyTypes : source.isTypeOnly, | ||
| } satisfies KubbFile.Export, | ||
@@ -403,0 +406,0 @@ ] |
+8
-0
@@ -39,2 +39,10 @@ import type { PossiblePromise } from '@internals/utils' | ||
| * | ||
| * @deprecated Import `defineConfig` from `kubb` instead of `@kubb/core`. The `kubb` | ||
| * package wires up the OpenAPI adapter, the TypeScript parsers, and the barrel plugin | ||
| * for you. See the v5 migration guide: https://kubb.dev/docs/5.x/migration-guide | ||
| * | ||
| * ```ts | ||
| * import { defineConfig } from '@kubb/core' // [!code --] | ||
| * import { defineConfig } from 'kubb' // [!code ++] | ||
| * ``` | ||
| * @example | ||
@@ -41,0 +49,0 @@ * export default defineConfig(({ logLevel }) => ({ |
+1
-0
@@ -23,1 +23,2 @@ export { AsyncEventEmitter, URLPath } from '@internals/utils' | ||
| export { detectLinter } from './utils/linters.ts' | ||
| export { resolveBarrelType } from './utils/resolveBarrelType.ts' |
+42
-0
@@ -105,2 +105,23 @@ import type { AsyncEventEmitter, PossiblePromise } from '@internals/utils' | ||
| /** | ||
| * Object form of the barrel option, the forward-compatible replacement for `barrelType`. | ||
| * | ||
| * Available in v4 so a config can be migrated ahead of v5, where it becomes the only barrel option. | ||
| * See https://kubb.dev/docs/5.x/migration-guide | ||
| */ | ||
| export type Barrel = { | ||
| /** | ||
| * How `index.ts` files re-export their files. | ||
| * - 'named' lists every export by name. | ||
| * - 'all' re-exports with a wildcard (`export *`). | ||
| * @default 'named' | ||
| */ | ||
| type?: Exclude<BarrelType, 'propagate'> | ||
| /** | ||
| * Re-export the nested barrel files instead of the individual files. Replaces the legacy `'propagate'` value of `barrelType`. | ||
| * @default false | ||
| */ | ||
| nested?: boolean | ||
| } | ||
| export type DevtoolsOptions = { | ||
@@ -207,5 +228,14 @@ /** | ||
| * @default 'named' | ||
| * @deprecated Use the `output.barrel` object instead. See https://kubb.dev/docs/5.x/migration-guide | ||
| */ | ||
| barrelType?: Exclude<BarrelType, 'propagate'> | false | ||
| /** | ||
| * Object form of {@link Config.output.barrelType} for the root barrel file (e.g., `src/gen/index.ts`). Prefer this over `barrelType`; it becomes the only barrel option in v5. | ||
| * - `{ type: 'named' }` lists every export by name. | ||
| * - `{ type: 'all' }` re-exports with a wildcard. | ||
| * - `false` disables the root barrel file. | ||
| * @default { type: 'named' } | ||
| */ | ||
| barrel?: Omit<Barrel, 'nested'> | false | ||
| /** | ||
| * Adds a default banner to the start of every generated file indicating it was generated by Kubb. | ||
@@ -223,2 +253,3 @@ * - 'simple' adds banner with link to Kubb. | ||
| * @default false | ||
| * @deprecated Removed in v5, where it no longer has any effect. See https://kubb.dev/docs/5.x/migration-guide | ||
| */ | ||
@@ -448,5 +479,15 @@ override?: boolean | ||
| * @default 'named' | ||
| * @deprecated Use the `output.barrel` object instead. See https://kubb.dev/docs/5.x/migration-guide | ||
| */ | ||
| barrelType?: BarrelType | false | ||
| /** | ||
| * Object form of {@link Output.barrelType}. Prefer this over `barrelType`; it becomes the only barrel option in v5. | ||
| * - `{ type: 'named' }` lists every export by name. | ||
| * - `{ type: 'all' }` re-exports with a wildcard. | ||
| * - `{ type: 'named', nested: true }` replaces the legacy `'propagate'` value. | ||
| * - `false` disables the barrel file for this plugin. | ||
| * @default { type: 'named' } | ||
| */ | ||
| barrel?: Barrel | false | ||
| /** | ||
| * Add a banner text in the beginning of every file | ||
@@ -462,2 +503,3 @@ */ | ||
| * @default false | ||
| * @deprecated Removed in v5, where it no longer has any effect. See https://kubb.dev/docs/5.x/migration-guide | ||
| */ | ||
@@ -464,0 +506,0 @@ override?: boolean |
| import { join } from 'node:path' | ||
| import type { KubbFile } from '@kubb/fabric-core/types' | ||
| import { BarrelManager } from '../BarrelManager.ts' | ||
| import type { BarrelType, Plugin } from '../types.ts' | ||
| import type { Barrel, BarrelType, Plugin } from '../types.ts' | ||
| import { resolveBarrelType } from './resolveBarrelType.ts' | ||
@@ -11,4 +12,7 @@ export type FileMetaBase = { | ||
| type AddIndexesProps = { | ||
| type: BarrelType | false | undefined | ||
| /** | ||
| * Explicit barrel strategy. When omitted it is resolved from `output.barrel` (preferred) or the legacy `output.barrelType`. | ||
| */ | ||
| type?: BarrelType | false | ||
| /** | ||
| * Root based on root and output.path specified in the config | ||
@@ -22,2 +26,4 @@ */ | ||
| path: string | ||
| barrel?: Barrel | false | ||
| barrelType?: BarrelType | false | ||
| } | ||
@@ -43,3 +49,5 @@ group?: { | ||
| export async function getBarrelFiles(files: Array<KubbFile.ResolvedFile>, { type, meta = {}, root, output }: AddIndexesProps): Promise<KubbFile.File[]> { | ||
| if (!type || type === 'propagate') { | ||
| const resolvedType = type ?? resolveBarrelType(output) ?? 'named' | ||
| if (!resolvedType || resolvedType === 'propagate') { | ||
| return [] | ||
@@ -62,3 +70,3 @@ } | ||
| if (type === 'all') { | ||
| if (resolvedType === 'all') { | ||
| return barrelFiles.map((file) => { | ||
@@ -65,0 +73,0 @@ return { |
| import { t as __name } from "./chunk--u3MIqq1.js"; | ||
| import { EventEmitter } from "node:events"; | ||
| import { KubbFile } from "@kubb/fabric-core/types"; | ||
| import { Printer, PrinterFactoryOptions, RootNode } from "@kubb/ast/types"; | ||
| import { Fabric } from "@kubb/react-fabric/types"; | ||
| //#region ../../internals/utils/dist/index.d.ts | ||
| /** | ||
| * A typed EventEmitter that awaits all async listeners before resolving. | ||
| * Wraps Node's `EventEmitter` with full TypeScript event-map inference. | ||
| */ | ||
| declare var AsyncEventEmitter: { | ||
| new (maxListener?: number): { | ||
| "__#private@#emitter": EventEmitter<[never]>; | ||
| /** | ||
| * Emits an event and awaits all registered listeners in parallel. | ||
| * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments. | ||
| */ | ||
| emit(eventName: any, ...eventArgs: any[]): Promise<void>; /** Registers a persistent listener for the given event. */ | ||
| on(eventName: any, handler: any): void; /** Registers a one-shot listener that removes itself after the first invocation. */ | ||
| onOnce(eventName: any, handler: any): void; /** Removes a previously registered listener. */ | ||
| off(eventName: any, handler: any): void; /** Removes all listeners from every event channel. */ | ||
| removeAll(): void; | ||
| }; | ||
| }; | ||
| /** | ||
| * Parses and transforms an OpenAPI/Swagger path string into various URL formats. | ||
| * | ||
| * @example | ||
| * const p = new URLPath('/pet/{petId}') | ||
| * p.URL // '/pet/:petId' | ||
| * p.template // '`/pet/${petId}`' | ||
| */ | ||
| declare var URLPath: { | ||
| new (path: any, options?: {}): { | ||
| /** The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`. */path: any; | ||
| "__#private@#options": {}; /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */ | ||
| get URL(): any; /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`). */ | ||
| get isURL(): boolean; | ||
| /** | ||
| * Converts the OpenAPI path to a TypeScript template literal string. | ||
| * | ||
| * @example | ||
| * new URLPath('/pet/{petId}').template // '`/pet/${petId}`' | ||
| * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`' | ||
| */ | ||
| get template(): string; /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set. */ | ||
| get object(): string | { | ||
| url: any; | ||
| params: {} | undefined; | ||
| }; /** Returns a map of path parameter names, or `undefined` when the path has no parameters. */ | ||
| get params(): {} | undefined; | ||
| "__#private@#transformParam"(raw: any): any; /** Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name. */ | ||
| "__#private@#eachParam"(fn: any): void; | ||
| toObject({ | ||
| type, | ||
| replacer, | ||
| stringify | ||
| }?: { | ||
| type?: string | undefined; | ||
| }): string | { | ||
| url: any; | ||
| params: {} | undefined; | ||
| }; | ||
| /** | ||
| * Converts the OpenAPI path to a TypeScript template literal string. | ||
| * An optional `replacer` can transform each extracted parameter name before interpolation. | ||
| * | ||
| * @example | ||
| * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`' | ||
| */ | ||
| toTemplateString({ | ||
| prefix, | ||
| replacer | ||
| }?: { | ||
| prefix?: string | undefined; | ||
| }): string; | ||
| /** | ||
| * Extracts all `{param}` segments from the path and returns them as a key-value map. | ||
| * An optional `replacer` transforms each parameter name in both key and value positions. | ||
| * Returns `undefined` when no path parameters are found. | ||
| */ | ||
| getParams(replacer: any): {} | undefined; /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */ | ||
| toURLPath(): any; | ||
| }; | ||
| }; | ||
| /** | ||
| * Serializes a primitive value to a JSON string literal, stripping any surrounding quote characters first. | ||
| * | ||
| * @example | ||
| * stringify('hello') // '"hello"' | ||
| * stringify('"hello"') // '"hello"' | ||
| */ | ||
| declare function stringify(value: any): string; | ||
| //#endregion | ||
| //#region src/constants.d.ts | ||
| declare const DEFAULT_STUDIO_URL: "https://studio.kubb.dev"; | ||
| declare const logLevel: { | ||
| readonly silent: number; | ||
| readonly error: 0; | ||
| readonly warn: 1; | ||
| readonly info: 3; | ||
| readonly verbose: 4; | ||
| readonly debug: 5; | ||
| }; | ||
| declare const linters: { | ||
| readonly eslint: { | ||
| readonly command: "eslint"; | ||
| readonly args: (outputPath: string) => string[]; | ||
| readonly errorMessage: "Eslint not found"; | ||
| }; | ||
| readonly biome: { | ||
| readonly command: "biome"; | ||
| readonly args: (outputPath: string) => string[]; | ||
| readonly errorMessage: "Biome not found"; | ||
| }; | ||
| readonly oxlint: { | ||
| readonly command: "oxlint"; | ||
| readonly args: (outputPath: string) => string[]; | ||
| readonly errorMessage: "Oxlint not found"; | ||
| }; | ||
| }; | ||
| declare const formatters: { | ||
| readonly prettier: { | ||
| readonly command: "prettier"; | ||
| readonly args: (outputPath: string) => string[]; | ||
| readonly errorMessage: "Prettier not found"; | ||
| }; | ||
| readonly biome: { | ||
| readonly command: "biome"; | ||
| readonly args: (outputPath: string) => string[]; | ||
| readonly errorMessage: "Biome not found"; | ||
| }; | ||
| readonly oxfmt: { | ||
| readonly command: "oxfmt"; | ||
| readonly args: (outputPath: string) => string[]; | ||
| readonly errorMessage: "Oxfmt not found"; | ||
| }; | ||
| }; | ||
| //#endregion | ||
| //#region src/defineStorage.d.ts | ||
| /** | ||
| * Storage interface for persisting Kubb output. | ||
| * | ||
| * Keys are root-relative forward-slash paths (e.g. `src/gen/api/getPets.ts`). | ||
| * Implement this interface to route generated files to any backend — filesystem, | ||
| * S3, Redis, in-memory, etc. | ||
| * | ||
| * Use `defineStorage` to create a typed storage driver. | ||
| */ | ||
| interface DefineStorage { | ||
| /** Identifier used for logging and debugging (e.g. `'fs'`, `'s3'`). */ | ||
| readonly name: string; | ||
| /** Returns `true` when an entry for `key` exists in storage. */ | ||
| hasItem(key: string): Promise<boolean>; | ||
| /** Returns the stored string value, or `null` when `key` does not exist. */ | ||
| getItem(key: string): Promise<string | null>; | ||
| /** Persists `value` under `key`, creating any required structure. */ | ||
| setItem(key: string, value: string): Promise<void>; | ||
| /** Removes the entry for `key`. No-ops when the key does not exist. */ | ||
| removeItem(key: string): Promise<void>; | ||
| /** Returns all keys, optionally filtered to those starting with `base`. */ | ||
| getKeys(base?: string): Promise<Array<string>>; | ||
| /** Removes all entries, optionally scoped to those starting with `base`. */ | ||
| clear(base?: string): Promise<void>; | ||
| /** Optional teardown hook called after the build completes. */ | ||
| dispose?(): Promise<void>; | ||
| } | ||
| /** | ||
| * Wraps a storage builder so the `options` argument is optional, following the | ||
| * same factory pattern as `definePlugin`, `defineLogger`, and `defineAdapter`. | ||
| * | ||
| * The builder receives the resolved options object and must return a | ||
| * `DefineStorage`-compatible object that includes a `name` string. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { defineStorage } from '@kubb/core' | ||
| * | ||
| * export const memoryStorage = defineStorage((_options) => { | ||
| * const store = new Map<string, string>() | ||
| * return { | ||
| * name: 'memory', | ||
| * async hasItem(key) { return store.has(key) }, | ||
| * async getItem(key) { return store.get(key) ?? null }, | ||
| * async setItem(key, value) { store.set(key, value) }, | ||
| * async removeItem(key) { store.delete(key) }, | ||
| * async getKeys() { return [...store.keys()] }, | ||
| * async clear() { store.clear() }, | ||
| * } | ||
| * }) | ||
| * ``` | ||
| */ | ||
| declare function defineStorage<TOptions = Record<string, never>>(build: (options: TOptions) => DefineStorage): (options?: TOptions) => DefineStorage; | ||
| //#endregion | ||
| //#region src/PluginManager.d.ts | ||
| type RequiredPluginLifecycle = Required<PluginLifecycle>; | ||
| type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq'; | ||
| type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H]; | ||
| type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = { | ||
| result: Result; | ||
| plugin: Plugin; | ||
| }; | ||
| type Options = { | ||
| fabric: Fabric; | ||
| events: AsyncEventEmitter<KubbEvents>; | ||
| /** | ||
| * @default Number.POSITIVE_INFINITY | ||
| */ | ||
| concurrency?: number; | ||
| }; | ||
| type GetFileProps<TOptions = object> = { | ||
| name: string; | ||
| mode?: KubbFile.Mode; | ||
| extname: KubbFile.Extname; | ||
| pluginKey: Plugin['key']; | ||
| options?: TOptions; | ||
| }; | ||
| declare function getMode(fileOrFolder: string | undefined | null): KubbFile.Mode; | ||
| declare class PluginManager { | ||
| #private; | ||
| readonly config: Config; | ||
| readonly options: Options; | ||
| /** | ||
| * The universal `@kubb/ast` `RootNode` produced by the adapter, set by | ||
| * the build pipeline after the adapter's `parse()` resolves. | ||
| */ | ||
| rootNode: RootNode | undefined; | ||
| constructor(config: Config, options: Options); | ||
| get events(): AsyncEventEmitter<KubbEvents>; | ||
| getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, unknown>; | ||
| get plugins(): Array<Plugin>; | ||
| getFile<TOptions = object>({ | ||
| name, | ||
| mode, | ||
| extname, | ||
| pluginKey, | ||
| options | ||
| }: GetFileProps<TOptions>): KubbFile.File<{ | ||
| pluginKey: Plugin['key']; | ||
| }>; | ||
| resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path; | ||
| resolveName: (params: ResolveNameParams) => string; | ||
| /** | ||
| * Run a specific hookName for plugin x. | ||
| */ | ||
| hookForPlugin<H extends PluginLifecycleHooks>({ | ||
| pluginKey, | ||
| hookName, | ||
| parameters | ||
| }: { | ||
| pluginKey: Plugin['key']; | ||
| hookName: H; | ||
| parameters: PluginParameter<H>; | ||
| }): Promise<Array<ReturnType<ParseResult<H>> | null>>; | ||
| /** | ||
| * Run a specific hookName for plugin x. | ||
| */ | ||
| hookForPluginSync<H extends PluginLifecycleHooks>({ | ||
| pluginKey, | ||
| hookName, | ||
| parameters | ||
| }: { | ||
| pluginKey: Plugin['key']; | ||
| hookName: H; | ||
| parameters: PluginParameter<H>; | ||
| }): Array<ReturnType<ParseResult<H>>> | null; | ||
| /** | ||
| * Returns the first non-null result. | ||
| */ | ||
| hookFirst<H extends PluginLifecycleHooks>({ | ||
| hookName, | ||
| parameters, | ||
| skipped | ||
| }: { | ||
| hookName: H; | ||
| parameters: PluginParameter<H>; | ||
| skipped?: ReadonlySet<Plugin> | null; | ||
| }): Promise<SafeParseResult<H>>; | ||
| /** | ||
| * Returns the first non-null result. | ||
| */ | ||
| hookFirstSync<H extends PluginLifecycleHooks>({ | ||
| hookName, | ||
| parameters, | ||
| skipped | ||
| }: { | ||
| hookName: H; | ||
| parameters: PluginParameter<H>; | ||
| skipped?: ReadonlySet<Plugin> | null; | ||
| }): SafeParseResult<H> | null; | ||
| /** | ||
| * Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings. | ||
| */ | ||
| hookParallel<H extends PluginLifecycleHooks, TOutput = void>({ | ||
| hookName, | ||
| parameters | ||
| }: { | ||
| hookName: H; | ||
| parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined; | ||
| }): Promise<Awaited<TOutput>[]>; | ||
| /** | ||
| * Chains plugins | ||
| */ | ||
| hookSeq<H extends PluginLifecycleHooks>({ | ||
| hookName, | ||
| parameters | ||
| }: { | ||
| hookName: H; | ||
| parameters?: PluginParameter<H>; | ||
| }): Promise<void>; | ||
| getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined; | ||
| getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[]; | ||
| } | ||
| //#endregion | ||
| //#region src/Kubb.d.ts | ||
| type DebugEvent = { | ||
| date: Date; | ||
| logs: string[]; | ||
| fileName?: string; | ||
| }; | ||
| type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = { | ||
| hookName: H; | ||
| plugins: Array<Plugin>; | ||
| }; | ||
| type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = { | ||
| hookName: H; | ||
| }; | ||
| type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = { | ||
| strategy: Strategy; | ||
| hookName: H; | ||
| plugin: Plugin; | ||
| parameters?: unknown[] | undefined; | ||
| output?: unknown; | ||
| }; | ||
| type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = { | ||
| duration: number; | ||
| strategy: Strategy; | ||
| hookName: H; | ||
| plugin: Plugin; | ||
| parameters?: unknown[] | undefined; | ||
| output?: unknown; | ||
| }; | ||
| /** | ||
| * Events emitted during the Kubb code generation lifecycle. | ||
| * These events can be listened to for logging, progress tracking, and custom integrations. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import type { AsyncEventEmitter } from '@kubb/core' | ||
| * import type { KubbEvents } from '@kubb/core' | ||
| * | ||
| * const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter() | ||
| * | ||
| * events.on('lifecycle:start', () => { | ||
| * console.log('Starting Kubb generation') | ||
| * }) | ||
| * | ||
| * events.on('plugin:end', (plugin, { duration }) => { | ||
| * console.log(`Plugin ${plugin.name} completed in ${duration}ms`) | ||
| * }) | ||
| * ``` | ||
| */ | ||
| interface KubbEvents { | ||
| /** | ||
| * Emitted at the beginning of the Kubb lifecycle, before any code generation starts. | ||
| */ | ||
| 'lifecycle:start': [version: string]; | ||
| /** | ||
| * Emitted at the end of the Kubb lifecycle, after all code generation is complete. | ||
| */ | ||
| 'lifecycle:end': []; | ||
| /** | ||
| * Emitted when configuration loading starts. | ||
| */ | ||
| 'config:start': []; | ||
| /** | ||
| * Emitted when configuration loading is complete. | ||
| */ | ||
| 'config:end': [configs: Array<Config>]; | ||
| /** | ||
| * Emitted when code generation phase starts. | ||
| */ | ||
| 'generation:start': [config: Config]; | ||
| /** | ||
| * Emitted when code generation phase completes. | ||
| */ | ||
| 'generation:end': [Config: Config, files: Array<KubbFile.ResolvedFile>, sources: Map<KubbFile.Path, string>]; | ||
| /** | ||
| * Emitted with a summary of the generation results. | ||
| * Contains summary lines, title, and success status. | ||
| */ | ||
| 'generation:summary': [Config: Config, { | ||
| failedPlugins: Set<{ | ||
| plugin: Plugin; | ||
| error: Error; | ||
| }>; | ||
| status: 'success' | 'failed'; | ||
| hrStart: [number, number]; | ||
| filesCreated: number; | ||
| pluginTimings?: Map<string, number>; | ||
| }]; | ||
| /** | ||
| * Emitted when code formatting starts (e.g., running Biome or Prettier). | ||
| */ | ||
| 'format:start': []; | ||
| /** | ||
| * Emitted when code formatting completes. | ||
| */ | ||
| 'format:end': []; | ||
| /** | ||
| * Emitted when linting starts. | ||
| */ | ||
| 'lint:start': []; | ||
| /** | ||
| * Emitted when linting completes. | ||
| */ | ||
| 'lint:end': []; | ||
| /** | ||
| * Emitted when plugin hooks execution starts. | ||
| */ | ||
| 'hooks:start': []; | ||
| /** | ||
| * Emitted when plugin hooks execution completes. | ||
| */ | ||
| 'hooks:end': []; | ||
| /** | ||
| * Emitted when a single hook execution starts. (e.g., format or lint). | ||
| * The callback should be invoked when the command completes. | ||
| */ | ||
| 'hook:start': [{ | ||
| id?: string; | ||
| command: string; | ||
| args?: readonly string[]; | ||
| }]; | ||
| /** | ||
| * Emitted when a single hook execution completes. | ||
| */ | ||
| 'hook:end': [{ | ||
| id?: string; | ||
| command: string; | ||
| args?: readonly string[]; | ||
| success: boolean; | ||
| error: Error | null; | ||
| }]; | ||
| /** | ||
| * Emitted when a new version of Kubb is available. | ||
| */ | ||
| 'version:new': [currentVersion: string, latestVersion: string]; | ||
| /** | ||
| * Informational message event. | ||
| */ | ||
| info: [message: string, info?: string]; | ||
| /** | ||
| * Error event. Emitted when an error occurs during code generation. | ||
| */ | ||
| error: [error: Error, meta?: Record<string, unknown>]; | ||
| /** | ||
| * Success message event. | ||
| */ | ||
| success: [message: string, info?: string]; | ||
| /** | ||
| * Warning message event. | ||
| */ | ||
| warn: [message: string, info?: string]; | ||
| /** | ||
| * Debug event for detailed logging. | ||
| * Contains timestamp, log messages, and optional filename. | ||
| */ | ||
| debug: [meta: DebugEvent]; | ||
| /** | ||
| * Emitted when file processing starts. | ||
| * Contains the list of files to be processed. | ||
| */ | ||
| 'files:processing:start': [files: Array<KubbFile.ResolvedFile>]; | ||
| /** | ||
| * Emitted for each file being processed, providing progress updates. | ||
| * Contains processed count, total count, percentage, and file details. | ||
| */ | ||
| 'file:processing:update': [{ | ||
| /** Number of files processed so far */processed: number; /** Total number of files to process */ | ||
| total: number; /** Processing percentage (0-100) */ | ||
| percentage: number; /** Optional source identifier */ | ||
| source?: string; /** The file being processed */ | ||
| file: KubbFile.ResolvedFile; | ||
| /** | ||
| * Kubb configuration (not present in Fabric). | ||
| * Provides access to the current config during file processing. | ||
| */ | ||
| config: Config; | ||
| }]; | ||
| /** | ||
| * Emitted when file processing completes. | ||
| * Contains the list of processed files. | ||
| */ | ||
| 'files:processing:end': [files: KubbFile.ResolvedFile[]]; | ||
| /** | ||
| * Emitted when a plugin starts executing. | ||
| */ | ||
| 'plugin:start': [plugin: Plugin]; | ||
| /** | ||
| * Emitted when a plugin completes execution. | ||
| * Duration in ms | ||
| */ | ||
| 'plugin:end': [plugin: Plugin, meta: { | ||
| duration: number; | ||
| success: boolean; | ||
| error?: Error; | ||
| }]; | ||
| /** | ||
| * Emitted when plugin hook progress tracking starts. | ||
| * Contains the hook name and list of plugins to execute. | ||
| */ | ||
| 'plugins:hook:progress:start': [meta: ProgressStartMeta]; | ||
| /** | ||
| * Emitted when plugin hook progress tracking ends. | ||
| * Contains the hook name that completed. | ||
| */ | ||
| 'plugins:hook:progress:end': [meta: ProgressStopMeta]; | ||
| /** | ||
| * Emitted when a plugin hook starts processing. | ||
| * Contains strategy, hook name, plugin, parameters, and output. | ||
| */ | ||
| 'plugins:hook:processing:start': [meta: ExecutingMeta]; | ||
| /** | ||
| * Emitted when a plugin hook completes processing. | ||
| * Contains duration, strategy, hook name, plugin, parameters, and output. | ||
| */ | ||
| 'plugins:hook:processing:end': [meta: ExecutedMeta]; | ||
| } | ||
| //#endregion | ||
| //#region src/types.d.ts | ||
| declare global { | ||
| namespace Kubb { | ||
| interface PluginContext {} | ||
| } | ||
| } | ||
| /** | ||
| * Config used in `kubb.config.ts` | ||
| * | ||
| * @example | ||
| * import { defineConfig } from '@kubb/core' | ||
| * export default defineConfig({ | ||
| * ... | ||
| * }) | ||
| */ | ||
| type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins'> & { | ||
| /** | ||
| * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file. | ||
| * @default process.cwd() | ||
| */ | ||
| root?: string; | ||
| /** | ||
| * An array of Kubb plugins used for generation. Each plugin may have additional configurable options (defined within the plugin itself). If a plugin relies on another plugin, an error will occur if the required dependency is missing. Refer to “pre” for more details. | ||
| */ | ||
| plugins?: Array<Omit<UnknownUserPlugin, 'inject'>>; | ||
| }; | ||
| type InputPath = { | ||
| /** | ||
| * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root. | ||
| */ | ||
| path: string; | ||
| }; | ||
| type InputData = { | ||
| /** | ||
| * A `string` or `object` that contains your Swagger/OpenAPI data. | ||
| */ | ||
| data: string | unknown; | ||
| }; | ||
| type Input = InputPath | InputData | Array<InputPath>; | ||
| /** | ||
| * The raw source passed to an adapter's `parse` function. | ||
| * Mirrors the shape of `Config['input']` with paths already resolved to absolute. | ||
| */ | ||
| type AdapterSource = { | ||
| type: 'path'; | ||
| path: string; | ||
| } | { | ||
| type: 'data'; | ||
| data: string | unknown; | ||
| } | { | ||
| type: 'paths'; | ||
| paths: Array<string>; | ||
| }; | ||
| /** | ||
| * Type parameters for an adapter definition. | ||
| * | ||
| * Mirrors `PluginFactoryOptions` but scoped to the adapter lifecycle: | ||
| * - `TName` — unique string identifier (e.g. `'oas'`, `'asyncapi'`) | ||
| * - `TOptions` — raw user-facing options passed to the adapter factory | ||
| * - `TResolvedOptions` — defaults applied; what the adapter stores as `options` | ||
| */ | ||
| type AdapterFactoryOptions<TName extends string = string, TOptions extends object = object, TResolvedOptions extends object = TOptions> = { | ||
| name: TName; | ||
| options: TOptions; | ||
| resolvedOptions: TResolvedOptions; | ||
| }; | ||
| /** | ||
| * An adapter converts a source file or data into a `@kubb/ast` `RootNode`. | ||
| * | ||
| * Adapters are the single entry-point for different schema formats | ||
| * (OpenAPI, AsyncAPI, Drizzle, …) and produce the universal `RootNode` | ||
| * that all Kubb plugins consume. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { oasAdapter } from '@kubb/adapter-oas' | ||
| * | ||
| * export default defineConfig({ | ||
| * adapter: adapterOas(), // default — OpenAPI / Swagger | ||
| * input: { path: './openapi.yaml' }, | ||
| * plugins: [pluginTs(), pluginZod()], | ||
| * }) | ||
| * ``` | ||
| */ | ||
| type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = { | ||
| /** Human-readable identifier, e.g. `'oas'`, `'drizzle'`, `'asyncapi'`. */name: TOptions['name']; /** Resolved options (after defaults have been applied). */ | ||
| options: TOptions['resolvedOptions']; /** Convert the raw source into a universal `RootNode`. */ | ||
| parse: (source: AdapterSource) => PossiblePromise<RootNode>; | ||
| }; | ||
| type BarrelType = 'all' | 'named' | 'propagate'; | ||
| type DevtoolsOptions = { | ||
| /** | ||
| * Open the AST inspector view (`/ast`) in Kubb Studio. | ||
| * When `false`, opens the main Studio page instead. | ||
| * @default false | ||
| */ | ||
| ast?: boolean; | ||
| }; | ||
| /** | ||
| * @private | ||
| */ | ||
| type Config<TInput = Input> = { | ||
| /** | ||
| * The name to display in the CLI output. | ||
| */ | ||
| name?: string; | ||
| /** | ||
| * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file. | ||
| * @default process.cwd() | ||
| */ | ||
| root: string; | ||
| /** | ||
| * Adapter that converts the input file into a `@kubb/ast` `RootNode` — the universal | ||
| * intermediate representation consumed by all Kubb plugins. | ||
| * | ||
| * - Omit (or pass `undefined`) to use the built-in OpenAPI/Swagger adapter. | ||
| * - Use `@kubb/adapter-oas` for explicit OpenAPI configuration (validate, contentType, …). | ||
| * - Use `@kubb/adapter-drizzle` or `@kubb/adapter-asyncapi` for other formats. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { drizzleAdapter } from '@kubb/adapter-drizzle' | ||
| * export default defineConfig({ | ||
| * adapter: drizzleAdapter(), | ||
| * input: { path: './src/schema.ts' }, | ||
| * }) | ||
| * ``` | ||
| */ | ||
| adapter?: Adapter; | ||
| /** | ||
| * You can use either `input.path` or `input.data`, depending on your specific needs. | ||
| */ | ||
| input: TInput; | ||
| output: { | ||
| /** | ||
| * The path where all generated files receives exported. | ||
| * This can be an absolute path or a path relative to the specified root option. | ||
| */ | ||
| path: string; | ||
| /** | ||
| * Clean the output directory before each build. | ||
| */ | ||
| clean?: boolean; | ||
| /** | ||
| * Save files to the file system. | ||
| * @default true | ||
| * @deprecated Use `storage` to control where files are written. | ||
| */ | ||
| write?: boolean; | ||
| /** | ||
| * Storage backend for generated files. | ||
| * Defaults to `fsStorage()` — the built-in filesystem driver. | ||
| * Accepts any object implementing the {@link DefineStorage} interface. | ||
| * Keys are root-relative paths (e.g. `src/gen/api/getPets.ts`). | ||
| * @default fsStorage() | ||
| * @example | ||
| * ```ts | ||
| * import { defineStorage, fsStorage } from '@kubb/core' | ||
| * storage: defineStorage(fsStorage()) | ||
| * ``` | ||
| */ | ||
| storage?: DefineStorage; | ||
| /** | ||
| * Specifies the formatting tool to be used. | ||
| * - 'auto' automatically detects and uses biome or prettier (in that order of preference). | ||
| * - 'prettier' uses Prettier for code formatting. | ||
| * - 'biome' uses Biome for code formatting. | ||
| * - 'oxfmt' uses Oxfmt for code formatting. | ||
| * - false disables code formatting. | ||
| * @default 'prettier' | ||
| */ | ||
| format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false; | ||
| /** | ||
| * Specifies the linter that should be used to analyze the code. | ||
| * - 'auto' automatically detects and uses biome, oxlint, or eslint (in that order of preference). | ||
| * - 'eslint' uses ESLint for linting. | ||
| * - 'biome' uses Biome for linting. | ||
| * - 'oxlint' uses Oxlint for linting. | ||
| * - false disables linting. | ||
| * @default 'auto' | ||
| */ | ||
| lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false; | ||
| /** | ||
| * Overrides the extension for generated imports and exports. By default, each plugin adds an extension. | ||
| * @default { '.ts': '.ts'} | ||
| */ | ||
| extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>; | ||
| /** | ||
| * Configures how `index.ts` files are created, including disabling barrel file generation. Each plugin has its own `barrelType` option; this setting controls the root barrel file (e.g., `src/gen/index.ts`). | ||
| * @default 'named' | ||
| */ | ||
| barrelType?: Exclude<BarrelType, 'propagate'> | false; | ||
| /** | ||
| * Adds a default banner to the start of every generated file indicating it was generated by Kubb. | ||
| * - 'simple' adds banner with link to Kubb. | ||
| * - 'full' adds source, title, description, and OpenAPI version. | ||
| * - false disables banner generation. | ||
| * @default 'simple' | ||
| */ | ||
| defaultBanner?: 'simple' | 'full' | false; | ||
| /** | ||
| * Whether to override existing external files if they already exist. | ||
| * When setting the option in the global configuration, all plugins inherit the same behavior by default. | ||
| * However, all plugins also have an `output.override` option, which can be used to override the behavior for a specific plugin. | ||
| * @default false | ||
| */ | ||
| override?: boolean; | ||
| }; | ||
| /** | ||
| * An array of Kubb plugins that used in the generation. | ||
| * Each plugin may include additional configurable options(defined in the plugin itself). | ||
| * If a plugin depends on another plugin, an error is returned if the required dependency is missing. See pre for more details. | ||
| */ | ||
| plugins?: Array<Plugin>; | ||
| /** | ||
| * Devtools configuration for Kubb Studio integration. | ||
| */ | ||
| devtools?: true | { | ||
| /** | ||
| * Override the Kubb Studio base URL. | ||
| * @default 'https://studio.kubb.dev' | ||
| */ | ||
| studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {}); | ||
| }; | ||
| /** | ||
| * Hooks triggered when a specific action occurs in Kubb. | ||
| */ | ||
| hooks?: { | ||
| /** | ||
| * Hook that triggers at the end of all executions. | ||
| * Useful for running Prettier or ESLint to format/lint your code. | ||
| */ | ||
| done?: string | Array<string>; | ||
| }; | ||
| }; | ||
| type PluginFactoryOptions< | ||
| /** | ||
| * Name to be used for the plugin, this will also be used for they key. | ||
| */ | ||
| TName extends string = string, | ||
| /** | ||
| * Options of the plugin. | ||
| */ | ||
| TOptions extends object = object, | ||
| /** | ||
| * Options of the plugin that can be used later on, see `options` inside your plugin config. | ||
| */ | ||
| TResolvedOptions extends object = TOptions, | ||
| /** | ||
| * Context that you want to expose to other plugins. | ||
| */ | ||
| TContext = unknown, | ||
| /** | ||
| * When calling `resolvePath` you can specify better types. | ||
| */ | ||
| TResolvePathOptions extends object = object> = { | ||
| name: TName; | ||
| /** | ||
| * Same behavior like what has been done with `QueryKey` in `@tanstack/react-query` | ||
| */ | ||
| key: PluginKey<TName | string>; | ||
| options: TOptions; | ||
| resolvedOptions: TResolvedOptions; | ||
| context: TContext; | ||
| resolvePathOptions: TResolvePathOptions; | ||
| }; | ||
| type PluginKey<TName> = [name: TName, identifier?: string | number]; | ||
| type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never; | ||
| type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = { | ||
| /** | ||
| * Unique name used for the plugin | ||
| * The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins. | ||
| * @example @kubb/typescript | ||
| */ | ||
| name: TOptions['name']; | ||
| /** | ||
| * Options set for a specific plugin(see kubb.config.js), passthrough of options. | ||
| */ | ||
| options: TOptions['resolvedOptions']; | ||
| /** | ||
| * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins. | ||
| * Can be used to validate dependent plugins. | ||
| */ | ||
| pre?: Array<string>; | ||
| /** | ||
| * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins. | ||
| */ | ||
| post?: Array<string>; | ||
| inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context']; | ||
| }; | ||
| type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>; | ||
| type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<any, any, any, any, any>>; | ||
| type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = { | ||
| /** | ||
| * Unique name used for the plugin | ||
| * @example @kubb/typescript | ||
| */ | ||
| name: TOptions['name']; | ||
| /** | ||
| * Internal key used when a developer uses more than one of the same plugin | ||
| * @private | ||
| */ | ||
| key: TOptions['key']; | ||
| /** | ||
| * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins. | ||
| * Can be used to validate dependent plugins. | ||
| */ | ||
| pre?: Array<string>; | ||
| /** | ||
| * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins. | ||
| */ | ||
| post?: Array<string>; | ||
| /** | ||
| * Options set for a specific plugin(see kubb.config.js), passthrough of options. | ||
| */ | ||
| options: TOptions['resolvedOptions']; | ||
| install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>; | ||
| /** | ||
| * Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`). | ||
| */ | ||
| inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context']; | ||
| }; | ||
| type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>; | ||
| type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = { | ||
| /** | ||
| * Start of the lifecycle of a plugin. | ||
| * @type hookParallel | ||
| */ | ||
| install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>; | ||
| /** | ||
| * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`). | ||
| * Options can als be included. | ||
| * @type hookFirst | ||
| * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts' | ||
| */ | ||
| resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path; | ||
| /** | ||
| * Resolve to a name based on a string. | ||
| * Useful when converting to PascalCase or camelCase. | ||
| * @type hookFirst | ||
| * @example ('pet') => 'Pet' | ||
| */ | ||
| resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string; | ||
| }; | ||
| type PluginLifecycleHooks = keyof PluginLifecycle; | ||
| type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>; | ||
| type ResolvePathParams<TOptions = object> = { | ||
| pluginKey?: Plugin['key']; | ||
| baseName: KubbFile.BaseName; | ||
| mode?: KubbFile.Mode; | ||
| /** | ||
| * Options to be passed to 'resolvePath' 3th parameter | ||
| */ | ||
| options?: TOptions; | ||
| }; | ||
| type ResolveNameParams = { | ||
| name: string; | ||
| pluginKey?: Plugin['key']; | ||
| /** | ||
| * Specifies the type of entity being named. | ||
| * - 'file' customizes the name of the created file (uses camelCase). | ||
| * - 'function' customizes the exported function names (uses camelCase). | ||
| * - 'type' customizes TypeScript types (uses PascalCase). | ||
| * - 'const' customizes variable names (uses camelCase). | ||
| * @default undefined | ||
| */ | ||
| type?: 'file' | 'function' | 'type' | 'const'; | ||
| }; | ||
| type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = { | ||
| fabric: Fabric; | ||
| config: Config; | ||
| pluginManager: PluginManager; | ||
| /** | ||
| * Only add when the file does not exist yet | ||
| */ | ||
| addFile: (...file: Array<KubbFile.File>) => Promise<void>; | ||
| /** | ||
| * merging multiple sources into the same output file | ||
| */ | ||
| upsertFile: (...file: Array<KubbFile.File>) => Promise<void>; | ||
| events: AsyncEventEmitter<KubbEvents>; | ||
| mode: KubbFile.Mode; | ||
| /** | ||
| * Current plugin | ||
| */ | ||
| plugin: Plugin<TOptions>; | ||
| /** | ||
| * Returns the universal `@kubb/ast` `RootNode` produced by the configured adapter. | ||
| * Returns `undefined` when no adapter was set (legacy OAS-only usage). | ||
| */ | ||
| rootNode: RootNode | undefined; | ||
| /** | ||
| * Opens the Kubb Studio URL for the current `rootNode` in the default browser. | ||
| * Falls back to printing the URL if the browser cannot be launched. | ||
| * No-ops silently when no adapter has set a `rootNode`. | ||
| */ | ||
| openInStudio: (options?: DevtoolsOptions) => Promise<void>; | ||
| } & Kubb.PluginContext; | ||
| /** | ||
| * Specify the export location for the files and define the behavior of the output | ||
| */ | ||
| type Output<TOptions> = { | ||
| /** | ||
| * Path to the output folder or file that will contain the generated code | ||
| */ | ||
| path: string; | ||
| /** | ||
| * Define what needs to be exported, here you can also disable the export of barrel files | ||
| * @default 'named' | ||
| */ | ||
| barrelType?: BarrelType | false; | ||
| /** | ||
| * Add a banner text in the beginning of every file | ||
| */ | ||
| banner?: string | ((options: TOptions) => string); | ||
| /** | ||
| * Add a footer text in the beginning of every file | ||
| */ | ||
| footer?: string | ((options: TOptions) => string); | ||
| /** | ||
| * Whether to override existing external files if they already exist. | ||
| * @default false | ||
| */ | ||
| override?: boolean; | ||
| }; | ||
| type GroupContext = { | ||
| group: string; | ||
| }; | ||
| type Group = { | ||
| /** | ||
| * Defines the type where to group the files. | ||
| * - 'tag' groups files by OpenAPI tags. | ||
| * - 'path' groups files by OpenAPI paths. | ||
| * @default undefined | ||
| */ | ||
| type: 'tag' | 'path'; | ||
| /** | ||
| * Return the name of a group based on the group name, this used for the file and name generation | ||
| */ | ||
| name?: (context: GroupContext) => string; | ||
| }; | ||
| type LoggerOptions = { | ||
| /** | ||
| * @default 3 | ||
| */ | ||
| logLevel: (typeof logLevel)[keyof typeof logLevel]; | ||
| }; | ||
| /** | ||
| * Shared context passed to all plugins, parsers, and Fabric internals. | ||
| */ | ||
| interface LoggerContext extends AsyncEventEmitter<KubbEvents> {} | ||
| type Install<TOptions = unknown> = (context: LoggerContext, options?: TOptions) => void | Promise<void>; | ||
| type Logger<TOptions extends LoggerOptions = LoggerOptions> = { | ||
| name: string; | ||
| install: Install<TOptions>; | ||
| }; | ||
| type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Omit<Logger<TOptions>, 'logLevel'>; | ||
| //#endregion | ||
| export { UserPlugin as A, AsyncEventEmitter as B, Printer as C, UnknownUserPlugin as D, ResolvePathParams as E, DefineStorage as F, defineStorage as I, formatters as L, KubbEvents as M, PluginManager as N, UserConfig as O, getMode as P, linters as R, PluginWithLifeCycle as S, ResolveNameParams as T, URLPath as V, PluginFactoryOptions as _, Config as a, PluginLifecycleHooks as b, Group as c, Logger as d, LoggerContext as f, PluginContext as g, Plugin as h, BarrelType as i, UserPluginWithLifeCycle as j, UserLogger as k, InputData as l, Output as m, AdapterFactoryOptions as n, DevtoolsOptions as o, LoggerOptions as p, AdapterSource as r, GetPluginFactoryOptions as s, Adapter as t, InputPath as u, PluginKey as v, PrinterFactoryOptions as w, PluginParameter as x, PluginLifecycle as y, logLevel as z }; | ||
| //# sourceMappingURL=types-BwL2CHjl.d.ts.map |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
656212
1.96%48
2.13%9109
2.26%+ Added
- Removed
Updated