UNPKG

@kubb/core

Version:

Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.

123 lines (114 loc) • 6.13 kB
import { R as ResolvedFile } from './types-CA8nQKwM.cjs'; import { U as UserConfig, P as PluginManager, a as PossiblePromise, I as InputPath, b as PluginFactoryOptions, c as UserPluginWithLifeCycle } from './PluginManager-E3SghPP9.cjs'; export { B as BarrelType, C as Config, F as FileManager, d as FileMetaBase, G as GetPluginFactoryOptions, p as Group, e as InputData, O as Output, i as Plugin, o as PluginContext, f as PluginKey, k as PluginLifecycle, l as PluginLifecycleHooks, m as PluginParameter, j as PluginWithLifeCycle, n as ResolveNameParams, R as ResolvePathParams, h as UserPlugin, g as getSource } from './PluginManager-E3SghPP9.cjs'; import { L as Logger } from './logger-BWq-oJU_.cjs'; export { g as getDefaultBanner } from './parser-D6vU1kA9.cjs'; import 'consola/utils'; import 'consola'; type BuildOptions = { config: UserConfig; /** * @default Logger without the spinner */ logger?: Logger; pluginManager?: PluginManager; }; type BuildOutput = { files: Array<ResolvedFile>; pluginManager: PluginManager; /** * Only for safeBuild */ error?: Error; }; declare function setup(options: BuildOptions): Promise<PluginManager>; declare function build(options: BuildOptions): Promise<BuildOutput>; declare function safeBuild(options: BuildOptions): Promise<BuildOutput>; type Args = { /** * Path to `kubb.config.js` */ config?: string; /** * Watch changes on input */ watch?: boolean; /** * Log level to report when using the CLI * * `silent` will hide all information that is not relevant * * `info` will show all information possible(not related to the PluginManager) * * `debug` will show all information possible(related to the PluginManager), handy for seeing logs * @default `silent` */ logLevel?: string; /** * Run Kubb with Bun */ bun?: boolean; }; /** * Type helper to make it easier to use vite.config.ts accepts a direct UserConfig object, or a function that returns it. The function receives a ConfigEnv object. */ declare function defineConfig(options: PossiblePromise<UserConfig | Array<UserConfig>> | (( /** The options derived from the CLI flags */ args: Args) => PossiblePromise<UserConfig | Array<UserConfig>>)): typeof options; declare function isInputPath(result: UserConfig | undefined): result is UserConfig<InputPath>; /** * Abstract class that contains the building blocks for plugins to create their own Generator * @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137 */ declare abstract class BaseGenerator<TOptions = unknown, TContext = unknown> { #private; constructor(options?: TOptions, context?: TContext); get options(): TOptions; get context(): TContext; set options(options: TOptions); abstract build(...params: unknown[]): unknown; } type PackageJSON = { dependencies?: Record<string, string>; devDependencies?: Record<string, string>; }; type DependencyName = string; type DependencyVersion = string; declare class PackageManager { #private; constructor(workspace?: string); set workspace(workspace: string); get workspace(): string | undefined; normalizeDirectory(directory: string): string; getLocation(path: string): string; import(path: string): Promise<any | undefined>; getPackageJSON(): Promise<PackageJSON | undefined>; getPackageJSONSync(): PackageJSON | undefined; static setVersion(dependency: DependencyName, version: DependencyVersion): void; getVersion(dependency: DependencyName | RegExp): Promise<DependencyVersion | undefined>; getVersionSync(dependency: DependencyName | RegExp): DependencyVersion | undefined; isValid(dependency: DependencyName | RegExp, version: DependencyVersion): Promise<boolean>; isValidSync(dependency: DependencyName | RegExp, version: DependencyVersion): boolean; } type PluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => UserPluginWithLifeCycle<T>; type OptionalPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options?: T['options']) => UserPluginWithLifeCycle<T>; declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: PluginFactory<T>): OptionalPluginFactory<T>; type PromiseFunc$1<T = unknown, T2 = never> = (state?: T) => T2 extends never ? Promise<T> : Promise<T> | T2; type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Array<PromiseFunc$1<infer X, infer Y>> ? X | Y : never; type SeqOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Promise<Array<Awaited<ValueOfPromiseFuncArray<TInput>>>>; type HookFirstOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue = unknown> = ValueOfPromiseFuncArray<TInput>; type HookParallelOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Promise<PromiseSettledResult<Awaited<ValueOfPromiseFuncArray<TInput>>>[]>; type Strategy = 'seq' | 'first' | 'parallel'; type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = TStrategy extends 'first' ? HookFirstOutput<TInput, TValue> : TStrategy extends 'seq' ? SeqOutput<TInput, TValue> : TStrategy extends 'parallel' ? HookParallelOutput<TInput, TValue> : never; type PromiseFunc<T = unknown, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2; type Options<TState = any> = { nullCheck?: (state: TState) => boolean; }; declare class PromiseManager<TState = any> { #private; constructor(options?: Options<TState>); run<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TStrategy extends Strategy, TOutput = StrategySwitch<TStrategy, TInput, TValue>>(strategy: TStrategy, promises: TInput, { concurrency }?: { concurrency?: number; }): TOutput; } export { BaseGenerator, InputPath, PackageManager, PluginFactoryOptions, PluginManager, PromiseManager, UserConfig, UserPluginWithLifeCycle, build, createPlugin, build as default, defineConfig, isInputPath, safeBuild, setup };