@kubb/core 5.5.6 → 5.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +698 -306
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +202 -4
- package/dist/index.js +645 -258
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +30 -47
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.js +24 -41
- package/dist/mocks.js.map +1 -1
- package/dist/{usingCtx-C_vhSf7M.cjs → nodeCache-CllHsCcy.cjs} +101 -222
- package/dist/nodeCache-CllHsCcy.cjs.map +1 -0
- package/dist/{usingCtx-DdG2edpx.js → nodeCache-CumrOPh-.js} +101 -216
- package/dist/nodeCache-CumrOPh-.js.map +1 -0
- package/dist/{types-DNE8KVDT.d.ts → types-B-w6zShf.d.ts} +66 -296
- package/package.json +6 -8
- package/dist/usingCtx-C_vhSf7M.cjs.map +0 -1
- package/dist/usingCtx-DdG2edpx.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as Plugin, A as HookResult, At as logLevel, B as defineParser, Bt as SerializedDiagnostic, C as KubbMessageContext, Ct as GenerationResult, D as PossibleConfig, Dt as ReporterPluginFiles, E as KubbWarnContext, Et as ReporterName, F as defineGenerator, Ft as DiagnosticSeverity, G as KubbPluginEndContext, Gt as AdapterSource, H as Filter, Ht as Hookable, I as NodeCache, It as Diagnostics, J as NormalizedPlugin, K as KubbPluginSetupContext, Kt as createAdapter, L as KubbDriver, Lt as PerformanceDiagnostic, M as runHook, Mt as DiagnosticDoc, N as Generator, Nt as DiagnosticKind, O as PostGenerateCommand, Ot as UserReporter, P as GeneratorContext, Pt as DiagnosticLocation, Q as Override, R as FileManagerHooks, Rt as ProblemCode, S as KubbLifecycleStartContext, St as createStorage, T as KubbSuccessContext, Tt as ReporterContext, U as Group, Ut as Adapter, V as Exclude, Vt as UpdateDiagnostic, W as Include, Wt as AdapterFactoryOptions, X as OutputMode, Y as Output, Z as OutputOptions, _ as KubbHookEndContext, _t as ResolverPathParams, a as Input, at as ResolveBannerContext, b as KubbHooks, bt as createRenderer, c as KubbDiagnosticContext, ct as ResolveImportsOptions, d as KubbFilesProcessingEndContext, dt as Resolver, et as PluginFactoryOptions, f as KubbFilesProcessingStartContext, ft as ResolverDefault, g as KubbGenerationSummaryContext, gt as ResolverPatch, h as KubbGenerationStartContext, ht as ResolverFilePathParams, i as FilesContext, it as BannerMeta, j as RunHookOptions, jt as Diagnostic, k as UserConfig, kt as createReporter, l as KubbErrorContext, lt as ResolveOptionsContext, m as KubbGenerationEndContext, mt as ResolverFileParams, n as CLIOptions, nt as ResolvePluginOptions, o as KubbBuildEndContext, ot as ResolveBannerFile, p as KubbFilesProcessingUpdateContext, pt as ResolverFile, q as KubbPluginStartContext, r as Config, rt as definePlugin, s as KubbBuildStartContext, st as ResolveFileOptions, t as BuildOutput, tt as PluginName, u as KubbFileProcessingUpdate, ut as ResolvePathOptions, v as KubbHookLineContext, vt as Renderer, w as KubbPluginsEndContext, wt as Reporter, x as KubbInfoContext, xt as Storage, y as KubbHookStartContext, yt as RendererFactory, z as Parser, zt as ProblemDiagnostic } from "./types-B-w6zShf.js";
|
|
3
|
+
import { FileNode } from "@kubb/ast";
|
|
3
4
|
//#region src/applyConfigDefaults.d.ts
|
|
4
5
|
type ApplyConfigDefaultsOptions<TOutput> = {
|
|
5
6
|
defaultAdapter: Adapter;
|
|
@@ -25,6 +26,158 @@ export declare function applyConfigDefaults<TOutput extends Config['output'] = C
|
|
|
25
26
|
plugins: Array<Plugin>;
|
|
26
27
|
};
|
|
27
28
|
//#endregion
|
|
29
|
+
//#region src/output/runOutputPasses.d.ts
|
|
30
|
+
type RunOutputPassesOptions = {
|
|
31
|
+
config: Config;
|
|
32
|
+
/**
|
|
33
|
+
* Absolute directory the formatter and linter run over.
|
|
34
|
+
*/
|
|
35
|
+
outputPath: string;
|
|
36
|
+
hooks: Hookable<KubbHooks>;
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Runs `output.format`, `output.lint` and `output.postGenerate` over the generated output and
|
|
41
|
+
* returns the diagnostics they produced. Each failure is emitted through `Diagnostics.emit` and
|
|
42
|
+
* returned, so it reaches the summary, the reporters and the exit code; the passes keep going so
|
|
43
|
+
* one failing tool does not hide the next. `Kubb.generate()` runs this after an error-free build
|
|
44
|
+
* unless the host passes its own `processOutput`.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const diagnostics = await runOutputPasses({ config, outputPath: '/repo/src/gen', hooks })
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function runOutputPasses({ config, outputPath, hooks, signal }: RunOutputPassesOptions): Promise<Array<Diagnostic>>;
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/createKubb.d.ts
|
|
54
|
+
type CreateKubbOptions = {
|
|
55
|
+
/**
|
|
56
|
+
* Receives Kubb lifecycle hooks for the run.
|
|
57
|
+
*/
|
|
58
|
+
hooks?: Hookable<KubbHooks>;
|
|
59
|
+
/**
|
|
60
|
+
* Stops the build at the next safe checkpoint.
|
|
61
|
+
*/
|
|
62
|
+
signal?: AbortSignal;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Host hooks for a single {@link Kubb.generate} call. All optional. Progress narration rides the
|
|
66
|
+
* `kubb:*` lifecycle hooks on `.hooks`, so hosts subscribe there rather than pass a callback.
|
|
67
|
+
*/
|
|
68
|
+
type GenerateOptions = {
|
|
69
|
+
/**
|
|
70
|
+
* Replaces the output passes that run after an error-free build. The default,
|
|
71
|
+
* {@link runOutputPasses}, formats, lints and runs `output.postGenerate` over the generated
|
|
72
|
+
* output and returns the diagnostics they emitted.
|
|
73
|
+
*/
|
|
74
|
+
processOutput?: (context: RunOutputPassesOptions) => Promise<Array<Diagnostic>>;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* What a {@link Kubb.generate} call produced, for the host to map onto its own result shape.
|
|
78
|
+
*/
|
|
79
|
+
type GenerateResult = {
|
|
80
|
+
/**
|
|
81
|
+
* `true` when the build and every output pass completed without an error-level diagnostic.
|
|
82
|
+
*/
|
|
83
|
+
success: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* All files generated during the build.
|
|
86
|
+
*/
|
|
87
|
+
files: Array<FileNode>;
|
|
88
|
+
/**
|
|
89
|
+
* Build diagnostics plus any collected from the output passes.
|
|
90
|
+
*/
|
|
91
|
+
diagnostics: Array<Diagnostic>;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Kubb code-generation instance bound to a single config entry. Resolves the user
|
|
95
|
+
* config in the constructor, so `config` is available right away, and shares `hooks`,
|
|
96
|
+
* `storage`, and `driver` across the `setup → build` lifecycle.
|
|
97
|
+
*
|
|
98
|
+
* `createKubb` takes a plain config object (the shape `defineConfig` produces),
|
|
99
|
+
* not a fluent builder.
|
|
100
|
+
*
|
|
101
|
+
* Attach hook listeners to `.hooks` before calling `setup()` or `build()`.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* const kubb = createKubb(userConfig)
|
|
106
|
+
* kubb.hooks.hook('kubb:plugin:end', ({ plugin, duration }) => console.log(plugin.name, duration))
|
|
107
|
+
* const { files, diagnostics } = await kubb.safeBuild()
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
declare class Kubb {
|
|
111
|
+
#private;
|
|
112
|
+
readonly hooks: Hookable<KubbHooks>;
|
|
113
|
+
readonly config: Config;
|
|
114
|
+
constructor(userConfig: UserConfig, options?: CreateKubbOptions);
|
|
115
|
+
get storage(): Storage;
|
|
116
|
+
get driver(): KubbDriver;
|
|
117
|
+
/**
|
|
118
|
+
* Initializes the driver and storage. `build()` calls this automatically.
|
|
119
|
+
*/
|
|
120
|
+
setup(): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Runs the full pipeline and throws on any plugin error.
|
|
123
|
+
* Automatically calls `setup()` if needed.
|
|
124
|
+
*/
|
|
125
|
+
build(): Promise<BuildOutput>;
|
|
126
|
+
/**
|
|
127
|
+
* Runs the full pipeline and captures errors in `BuildOutput` instead of throwing.
|
|
128
|
+
* Automatically calls `setup()` if needed. This is the canonical call: it never throws on
|
|
129
|
+
* plugin errors, so callers stay in control of how failures surface.
|
|
130
|
+
*/
|
|
131
|
+
safeBuild(): Promise<BuildOutput>;
|
|
132
|
+
/**
|
|
133
|
+
* Run one build and its output passes end to end, emitting the surrounding `kubb:generation:*`
|
|
134
|
+
* hooks. Never throws on a build error: the outcome comes back in {@link GenerateResult} so the
|
|
135
|
+
* host decides how failures surface. Telemetry and progress narration stay with the host, which
|
|
136
|
+
* reads the result and subscribes to the `kubb:*` hooks.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* const result = await createKubb(config, { hooks }).generate()
|
|
141
|
+
* if (!result.success) process.exitCode = 1
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
generate(options?: GenerateOptions): Promise<GenerateResult>;
|
|
145
|
+
dispose(): void;
|
|
146
|
+
[Symbol.dispose](): void;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Constructs a {@link Kubb} build orchestrator from a user config. Equivalent
|
|
150
|
+
* to `new Kubb(userConfig, options)` and the canonical public entry point.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* import { createKubb } from '@kubb/core'
|
|
155
|
+
* import { adapterOas } from '@kubb/adapter-oas'
|
|
156
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
157
|
+
*
|
|
158
|
+
* const kubb = createKubb({
|
|
159
|
+
* input: './petStore.yaml',
|
|
160
|
+
* output: { path: './src/gen' },
|
|
161
|
+
* adapter: adapterOas(),
|
|
162
|
+
* plugins: [pluginTs()],
|
|
163
|
+
* })
|
|
164
|
+
*
|
|
165
|
+
* await kubb.build()
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export declare function createKubb(userConfig: UserConfig, options?: CreateKubbOptions): Kubb;
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/reporters/summary.d.ts
|
|
171
|
+
/**
|
|
172
|
+
* Writes a finished summary. The `cli` reporter formats the lines and hands them to one of these,
|
|
173
|
+
* so the caller decides where they land: plain `console.log` by default, or the active logger's own
|
|
174
|
+
* output when a host installs one.
|
|
175
|
+
*/
|
|
176
|
+
type SummaryRenderer = (lines: ReadonlyArray<string>, meta: {
|
|
177
|
+
title: string;
|
|
178
|
+
status: 'success' | 'failed';
|
|
179
|
+
}) => void;
|
|
180
|
+
//#endregion
|
|
28
181
|
//#region src/reporters/cliReporter.d.ts
|
|
29
182
|
/**
|
|
30
183
|
* Builds a `cli` reporter that renders the {@link Report} for each config as it finishes.
|
|
@@ -133,6 +286,25 @@ type ResolverOptions<T extends PluginFactoryOptions> = Omit<T['resolver'], keyof
|
|
|
133
286
|
*/
|
|
134
287
|
export declare function createResolver<T extends PluginFactoryOptions>(options: ResolverOptions<T>): T['resolver'];
|
|
135
288
|
//#endregion
|
|
289
|
+
//#region src/input.d.ts
|
|
290
|
+
/**
|
|
291
|
+
* What an `input` value points at, once Kubb has looked at it.
|
|
292
|
+
*
|
|
293
|
+
* - `file` is a local file path, absolute or relative to the config file.
|
|
294
|
+
* - `url` is a remote document to fetch.
|
|
295
|
+
* - `inline` is OpenAPI content held in the string itself (JSON or YAML).
|
|
296
|
+
* - `object` is an already-parsed spec.
|
|
297
|
+
*/
|
|
298
|
+
type InputKind = 'file' | 'url' | 'inline' | 'object';
|
|
299
|
+
/**
|
|
300
|
+
* Classifies an `input` value so callers branch on it once instead of repeating the checks.
|
|
301
|
+
*
|
|
302
|
+
* A non-string is a parsed spec (`object`). A string is `inline` when it holds OpenAPI content,
|
|
303
|
+
* meaning it starts with `{` or `[`, spans multiple lines, or opens with a YAML `openapi:` or
|
|
304
|
+
* `swagger:` key. Otherwise a string is a `url` when it parses as one, or a `file` path.
|
|
305
|
+
*/
|
|
306
|
+
export declare function getInputKind(input: NonNullable<Input>): InputKind;
|
|
307
|
+
//#endregion
|
|
136
308
|
//#region src/storages/cacheStorage.d.ts
|
|
137
309
|
type CacheStorageOptions = {
|
|
138
310
|
/**
|
|
@@ -179,8 +351,7 @@ export declare const cacheStorage: (options?: CacheStorageOptions | undefined) =
|
|
|
179
351
|
* a formatter left behind
|
|
180
352
|
* - missing parent directories are created automatically
|
|
181
353
|
* - Bun's native file API is used when running under Bun
|
|
182
|
-
* -
|
|
183
|
-
* can fire every file's write without pacing itself
|
|
354
|
+
* - `FileManager.write` bounds in-flight writes, so this driver does not pace itself
|
|
184
355
|
*
|
|
185
356
|
* @example
|
|
186
357
|
* ```ts
|
|
@@ -196,6 +367,33 @@ export declare const cacheStorage: (options?: CacheStorageOptions | undefined) =
|
|
|
196
367
|
*/
|
|
197
368
|
export declare const fsStorage: (options?: Record<string, never> | undefined) => Storage;
|
|
198
369
|
//#endregion
|
|
370
|
+
//#region src/storages/kubbStorage.d.ts
|
|
371
|
+
type KubbStorageOptions = {
|
|
372
|
+
/**
|
|
373
|
+
* Folder inside the Kubb home, or an absolute path such as `<cwd>/.kubb`.
|
|
374
|
+
*/
|
|
375
|
+
base?: string;
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* Folder Kubb keeps its own files in, created with mode 0700. `base` resolves inside `KUBB_HOME`
|
|
379
|
+
* (default `~/.kubb`). When that folder is not writable, it falls back to a folder in the OS temp directory.
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* `resolveKubbDir('cache') // '/home/me/.kubb/cache'`
|
|
383
|
+
*/
|
|
384
|
+
export declare function resolveKubbDir(base?: string): string;
|
|
385
|
+
/**
|
|
386
|
+
* unstorage on the fs driver, rooted at {@link resolveKubbDir}. The fs driver cannot set a file
|
|
387
|
+
* mode, so the 0700 folder keeps files such as a stored token private.
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* const storage = kubbStorage({ base: 'cache' })
|
|
392
|
+
* await storage.setItem('machine-secret', secret)
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
export declare function kubbStorage({ base }?: KubbStorageOptions): import("unstorage").Storage<import("unstorage").StorageValue>;
|
|
396
|
+
//#endregion
|
|
199
397
|
//#region src/storages/memoryStorage.d.ts
|
|
200
398
|
/**
|
|
201
399
|
* In-memory storage driver. Useful for testing and dry-run scenarios where
|
|
@@ -218,5 +416,5 @@ export declare const fsStorage: (options?: Record<string, never> | undefined) =>
|
|
|
218
416
|
*/
|
|
219
417
|
export declare const memoryStorage: (options?: Record<string, never> | undefined) => Storage;
|
|
220
418
|
//#endregion
|
|
221
|
-
export { type Adapter, type AdapterFactoryOptions, type AdapterSource, type BannerMeta, BuildOutput, CLIOptions, Config, type CreateKubbOptions, type Diagnostic, type DiagnosticDoc, type DiagnosticKind, type DiagnosticLocation, type DiagnosticSeverity, Diagnostics, type Exclude, type FileManagerHooks, type Filter, type GenerateOptions, type GenerateResult, type GenerationResult, type Generator, type GeneratorContext, type Group, Hookable, type Include, Input, type InputKind, type Kubb, KubbBuildEndContext, KubbBuildStartContext, KubbDiagnosticContext, KubbDriver, KubbErrorContext, KubbFileProcessingUpdate, KubbFilesProcessingEndContext, KubbFilesProcessingStartContext, KubbFilesProcessingUpdateContext, KubbGenerationEndContext, KubbGenerationStartContext, KubbGenerationSummaryContext, KubbHookEndContext, KubbHookLineContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, type KubbPluginEndContext, type KubbPluginSetupContext, type KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbWarnContext, type NodeCache, type NormalizedPlugin, type Output, type OutputMode, type OutputOptions, type Override, type Parser, type PerformanceDiagnostic, type Plugin, type PluginFactoryOptions, type PluginName, PossibleConfig, PostGenerateCommand, type ProblemCode, type ProblemDiagnostic, type Renderer, type RendererFactory, type Reporter, type ReporterContext, type ReporterName, type ReporterPluginFiles, type ResolveBannerContext, type ResolveBannerFile, type ResolveFileOptions, type ResolveImportsOptions, type ResolveOptionsContext, type ResolvePathOptions, type ResolvePluginOptions, Resolver, type ResolverDefault, type ResolverFile, type ResolverFileParams, type ResolverFilePathParams, type ResolverPatch, type ResolverPathParams, type SerializedDiagnostic, type Storage, type SummaryRenderer, type UpdateDiagnostic, UserConfig, type UserReporter, createAdapter,
|
|
419
|
+
export { type Adapter, type AdapterFactoryOptions, type AdapterSource, type BannerMeta, BuildOutput, CLIOptions, Config, type CreateKubbOptions, type Diagnostic, type DiagnosticDoc, type DiagnosticKind, type DiagnosticLocation, type DiagnosticSeverity, Diagnostics, type Exclude, type FileManagerHooks, FilesContext, type Filter, type GenerateOptions, type GenerateResult, type GenerationResult, type Generator, type GeneratorContext, type Group, type HookResult, Hookable, type Include, Input, type InputKind, type Kubb, KubbBuildEndContext, KubbBuildStartContext, KubbDiagnosticContext, KubbDriver, KubbErrorContext, KubbFileProcessingUpdate, KubbFilesProcessingEndContext, KubbFilesProcessingStartContext, KubbFilesProcessingUpdateContext, KubbGenerationEndContext, KubbGenerationStartContext, KubbGenerationSummaryContext, KubbHookEndContext, KubbHookLineContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, KubbMessageContext, type KubbPluginEndContext, type KubbPluginSetupContext, type KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbWarnContext, type NodeCache, type NormalizedPlugin, type Output, type OutputMode, type OutputOptions, type Override, type Parser, type PerformanceDiagnostic, type Plugin, type PluginFactoryOptions, type PluginName, PossibleConfig, PostGenerateCommand, type ProblemCode, type ProblemDiagnostic, type Renderer, type RendererFactory, type Reporter, type ReporterContext, type ReporterName, type ReporterPluginFiles, type ResolveBannerContext, type ResolveBannerFile, type ResolveFileOptions, type ResolveImportsOptions, type ResolveOptionsContext, type ResolvePathOptions, type ResolvePluginOptions, Resolver, type ResolverDefault, type ResolverFile, type ResolverFileParams, type ResolverFilePathParams, type ResolverPatch, type ResolverPathParams, type RunHookOptions, type RunOutputPassesOptions, type SerializedDiagnostic, type Storage, type SummaryRenderer, type UpdateDiagnostic, UserConfig, type UserReporter, createAdapter, createRenderer, createReporter, createStorage, defineGenerator, defineParser, definePlugin, logLevel, runHook };
|
|
222
420
|
//# sourceMappingURL=index.d.ts.map
|