@kubb/core 5.12.8 → 5.13.0

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.d.cts CHANGED
@@ -848,9 +848,13 @@ declare class FileManager {
848
848
  add(...files: Array<FileNode>): Array<FileNode>;
849
849
  upsert(...files: Array<FileNode>): Array<FileNode>;
850
850
  /** Stores a generator result: a file array is upserted as is, an element renders through `renderer` first, falsy is a no-op. */
851
- dispatch<TElement = unknown>({ result, renderer }: {
851
+ dispatch<TElement = unknown>({ result, renderer, pointer }: {
852
852
  result: TElement | Array<FileNode> | undefined | null;
853
853
  renderer?: RendererFactory<TElement> | null;
854
+ /**
855
+ * Pointer of the node the result was generated from, set on each source that carries none.
856
+ */
857
+ pointer?: string;
854
858
  }): Promise<void>;
855
859
  /**
856
860
  * Releases all stored files. Called by the core after `kubb:build:end`.
@@ -3185,6 +3189,11 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
3185
3189
  validate: (input: string, options?: {
3186
3190
  throwOnError?: boolean;
3187
3191
  }) => Promise<void>;
3192
+ /**
3193
+ * Waits for work `parse` left running alongside generation, such as spec validation in a worker thread.
3194
+ * Kubb awaits it before `kubb:build:end`, inside the build's diagnostics scope. Must not reject.
3195
+ */
3196
+ settle?: () => Promise<void>;
3188
3197
  /**
3189
3198
  * Zero-based UTF-16 offsets of a diagnostic in `source` for a code frame, `end` exclusive; `undefined` when it cannot be found.
3190
3199
  */
@@ -3663,8 +3672,9 @@ type KubbStorageOptions = {
3663
3672
  */
3664
3673
  export declare function resolveKubbDir(base?: string): string;
3665
3674
  /**
3666
- * unstorage on the fs driver, rooted at {@link resolveKubbDir}. The fs driver cannot set a file
3667
- * mode, so the 0700 folder keeps files such as a stored token private.
3675
+ * Key-value files rooted at {@link resolveKubbDir}. Each key is a file path inside that folder.
3676
+ * Strings are stored as is and other values as JSON. `getItem` parses JSON and falls back to the
3677
+ * raw string. The 0700 folder keeps files such as a stored token private.
3668
3678
  *
3669
3679
  * @example
3670
3680
  * ```ts
@@ -3672,7 +3682,11 @@ export declare function resolveKubbDir(base?: string): string;
3672
3682
  * await storage.setItem('machine-secret', secret)
3673
3683
  * ```
3674
3684
  */
3675
- export declare function kubbStorage({ base }?: KubbStorageOptions): import("unstorage").Storage<import("unstorage").StorageValue>;
3685
+ export declare function kubbStorage({ base }?: KubbStorageOptions): {
3686
+ getItem<T = unknown>(key: string): Promise<T | null>;
3687
+ setItem(key: string, value: unknown): Promise<void>;
3688
+ removeItem(key: string): Promise<void>;
3689
+ };
3676
3690
  //#endregion
3677
3691
  //#region src/storages/memoryStorage.d.ts
3678
3692
  /**
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as NodeCache, $t as ReporterContext, A as PluginFactory, At as KubbInfoContext, B as ResolveImportsOptions, Bt as RunHookOptions, C as NormalizedPlugin, Ct as KubbGenerationEndContext, D as Override, Dt as KubbHookLineContext, E as OutputOptions, Et as KubbHookEndContext, F as definePlugin, Ft as KubbWarnContext, G as ResolverFile, Gt as createOutputManifest, H as ResolvePathOptions, Ht as KubbDriver, I as BannerMeta, It as PossibleConfig, J as ResolverPatch, Jt as createRenderer, K as ResolverFileParams, Kt as Renderer, L as ResolveBannerContext, Lt as PostGenerateCommand, M as PluginType, Mt as KubbMessageContext, N as ResolvePluginOptions, Nt as KubbPluginsEndContext, O as Plugin, Ot as KubbHookStartContext, P as assertPluginOption, Pt as KubbSuccessContext, Q as defineGenerator, Qt as Reporter, R as ResolveBannerFile, Rt as UserConfig, S as KubbPluginStartContext, St as KubbFilesProcessingUpdateContext, T as OutputMode, Tt as KubbGenerationSummaryContext, U as Resolver, Ut as Hookable, V as ResolveOptionsContext, Vt as runHook, W as ResolverDefault, Wt as OutputManifest, X as Generator, Xt as createStorage, Y as ResolverPathParams, Yt as Storage, Z as GeneratorContext, Zt as GenerationResult, _ as Filter, _t as KubbDiagnosticContext, a as AdapterSource, an as DiagnosticFormatOptions, at as Diagnostics, b as KubbPluginEndContext, bt as KubbFilesProcessingEndContext, c as ExtensionDependency, cn as ParserDefinition, ct as ProblemDiagnostic, d as ExtensionKind, dt as CLIOptions, en as ReporterName, et as Diagnostic, f as ExtensionMeta, ft as Config, g as Exclude, gt as KubbBuildStartContext, h as resolveMeta, ht as KubbBuildEndContext, i as AdapterFactoryOptions, in as logLevel, it as DiagnosticSeverity, j as PluginName, jt as KubbLifecycleStartContext, k as PluginDefinition, kt as KubbHooks, l as ExtensionDependencyRecord, ln as ParserFactory, lt as UpdateDiagnostic, m as defineExtension, mt as Input, n as AdapterDefinition, nn as UserReporter, nt as DiagnosticKind, o as createAdapter, on as SerializedDiagnostic, ot as PerformanceDiagnostic, p as checkCompatibility, pt as FilesContext, q as ResolverFilePathParams, qt as RendererFactory, r as AdapterFactory, rn as createReporter, rt as DiagnosticLocation, s as ExtensionDependencies, sn as Parser, st as ProblemCode, t as Adapter, tn as ReporterPluginFiles, tt as DiagnosticDoc, u as ExtensionFactory, un as defineParser, ut as BuildOutput, v as Group, vt as KubbErrorContext, w as Output, wt as KubbGenerationStartContext, x as KubbPluginSetupContext, xt as KubbFilesProcessingStartContext, y as Include, yt as KubbFileProcessingUpdate, z as ResolveFileOptions, zt as HookResult } from "./createAdapter-DFXvZLZC.js";
1
+ import { $ as NodeCache, $t as ReporterContext, A as PluginFactory, At as KubbInfoContext, B as ResolveImportsOptions, Bt as RunHookOptions, C as NormalizedPlugin, Ct as KubbGenerationEndContext, D as Override, Dt as KubbHookLineContext, E as OutputOptions, Et as KubbHookEndContext, F as definePlugin, Ft as KubbWarnContext, G as ResolverFile, Gt as createOutputManifest, H as ResolvePathOptions, Ht as KubbDriver, I as BannerMeta, It as PossibleConfig, J as ResolverPatch, Jt as createRenderer, K as ResolverFileParams, Kt as Renderer, L as ResolveBannerContext, Lt as PostGenerateCommand, M as PluginType, Mt as KubbMessageContext, N as ResolvePluginOptions, Nt as KubbPluginsEndContext, O as Plugin, Ot as KubbHookStartContext, P as assertPluginOption, Pt as KubbSuccessContext, Q as defineGenerator, Qt as Reporter, R as ResolveBannerFile, Rt as UserConfig, S as KubbPluginStartContext, St as KubbFilesProcessingUpdateContext, T as OutputMode, Tt as KubbGenerationSummaryContext, U as Resolver, Ut as Hookable, V as ResolveOptionsContext, Vt as runHook, W as ResolverDefault, Wt as OutputManifest, X as Generator, Xt as createStorage, Y as ResolverPathParams, Yt as Storage, Z as GeneratorContext, Zt as GenerationResult, _ as Filter, _t as KubbDiagnosticContext, a as AdapterSource, an as DiagnosticFormatOptions, at as Diagnostics, b as KubbPluginEndContext, bt as KubbFilesProcessingEndContext, c as ExtensionDependency, cn as ParserDefinition, ct as ProblemDiagnostic, d as ExtensionKind, dt as CLIOptions, en as ReporterName, et as Diagnostic, f as ExtensionMeta, ft as Config, g as Exclude, gt as KubbBuildStartContext, h as resolveMeta, ht as KubbBuildEndContext, i as AdapterFactoryOptions, in as logLevel, it as DiagnosticSeverity, j as PluginName, jt as KubbLifecycleStartContext, k as PluginDefinition, kt as KubbHooks, l as ExtensionDependencyRecord, ln as ParserFactory, lt as UpdateDiagnostic, m as defineExtension, mt as Input, n as AdapterDefinition, nn as UserReporter, nt as DiagnosticKind, o as createAdapter, on as SerializedDiagnostic, ot as PerformanceDiagnostic, p as checkCompatibility, pt as FilesContext, q as ResolverFilePathParams, qt as RendererFactory, r as AdapterFactory, rn as createReporter, rt as DiagnosticLocation, s as ExtensionDependencies, sn as Parser, st as ProblemCode, t as Adapter, tn as ReporterPluginFiles, tt as DiagnosticDoc, u as ExtensionFactory, un as defineParser, ut as BuildOutput, v as Group, vt as KubbErrorContext, w as Output, wt as KubbGenerationStartContext, x as KubbPluginSetupContext, xt as KubbFilesProcessingStartContext, y as Include, yt as KubbFileProcessingUpdate, z as ResolveFileOptions, zt as HookResult } from "./createAdapter-BNUEQcw9.js";
2
2
  import { FileNode, Macro, UserFileNode } from "@kubb/ast";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  import net from "node:net";
@@ -441,8 +441,9 @@ type KubbStorageOptions = {
441
441
  */
442
442
  export declare function resolveKubbDir(base?: string): string;
443
443
  /**
444
- * unstorage on the fs driver, rooted at {@link resolveKubbDir}. The fs driver cannot set a file
445
- * mode, so the 0700 folder keeps files such as a stored token private.
444
+ * Key-value files rooted at {@link resolveKubbDir}. Each key is a file path inside that folder.
445
+ * Strings are stored as is and other values as JSON. `getItem` parses JSON and falls back to the
446
+ * raw string. The 0700 folder keeps files such as a stored token private.
446
447
  *
447
448
  * @example
448
449
  * ```ts
@@ -450,7 +451,11 @@ export declare function resolveKubbDir(base?: string): string;
450
451
  * await storage.setItem('machine-secret', secret)
451
452
  * ```
452
453
  */
453
- export declare function kubbStorage({ base }?: KubbStorageOptions): import("unstorage").Storage<import("unstorage").StorageValue>;
454
+ export declare function kubbStorage({ base }?: KubbStorageOptions): {
455
+ getItem<T = unknown>(key: string): Promise<T | null>;
456
+ setItem(key: string, value: unknown): Promise<void>;
457
+ removeItem(key: string): Promise<void>;
458
+ };
454
459
  //#endregion
455
460
  //#region src/storages/memoryStorage.d.ts
456
461
  /**
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as formatMs, B as toError, C as useConfig, D as defineExtension, E as checkCompatibility, F as listFiles, I as read, L as rm$1, M as inParallel, N as existsSync$1, O as resolveMeta, P as isPathInside, R as write, S as tryUseKubb, T as useOptions, _ as kubbContext, b as setOptions, c as Resolver, d as isPublicAddress, f as assertPluginOption, g as injectFile, h as addMacro, j as getElapsedMs, k as Diagnostics, l as getInputKind, m as addGenerator, n as KubbDriver, o as _usingCtx, p as definePlugin, s as createResolver, t as Hookable, u as checkoutGitInput, v as requirePlugin, w as useKubb, x as setResolver, y as setMacros, z as writeRaw } from "./Hookable-CsDHibJ8.js";
1
+ import { A as formatMs, B as writeRaw, C as useConfig, D as defineExtension, E as checkCompatibility, F as isPathInside, I as listFiles, L as read, M as inParallel, N as exists, O as resolveMeta, P as existsSync$1, R as rm$1, S as tryUseKubb, T as useOptions, V as toError, _ as kubbContext, b as setOptions, c as Resolver, d as isPublicAddress, f as assertPluginOption, g as injectFile, h as addMacro, j as getElapsedMs, k as Diagnostics, l as getInputKind, m as addGenerator, n as KubbDriver, o as _usingCtx, p as definePlugin, s as createResolver, t as Hookable, u as checkoutGitInput, v as requirePlugin, w as useKubb, x as setResolver, y as setMacros, z as write } from "./Hookable-BR69O7aj.js";
2
2
  import { createRequire } from "node:module";
3
3
  import { isValid } from "verkit";
4
4
  import process$1 from "node:process";
@@ -10,8 +10,6 @@ import { stripVTControlCharacters, styleText } from "node:util";
10
10
  import { homedir, tmpdir } from "node:os";
11
11
  import { hash, randomUUID } from "node:crypto";
12
12
  import { createInterface } from "node:readline";
13
- import { createStorage as createStorage$1 } from "unstorage";
14
- import fsDriver from "unstorage/drivers/fs";
15
13
  import { fileURLToPath } from "node:url";
16
14
  //#region ../../internals/utils/src/isCIEnvironment.ts
17
15
  /**
@@ -1016,8 +1014,9 @@ function resolveKubbDir(base = "") {
1016
1014
  }
1017
1015
  }
1018
1016
  /**
1019
- * unstorage on the fs driver, rooted at {@link resolveKubbDir}. The fs driver cannot set a file
1020
- * mode, so the 0700 folder keeps files such as a stored token private.
1017
+ * Key-value files rooted at {@link resolveKubbDir}. Each key is a file path inside that folder.
1018
+ * Strings are stored as is and other values as JSON. `getItem` parses JSON and falls back to the
1019
+ * raw string. The 0700 folder keeps files such as a stored token private.
1021
1020
  *
1022
1021
  * @example
1023
1022
  * ```ts
@@ -1026,7 +1025,30 @@ function resolveKubbDir(base = "") {
1026
1025
  * ```
1027
1026
  */
1028
1027
  function kubbStorage({ base } = {}) {
1029
- return createStorage$1({ driver: fsDriver({ base: resolveKubbDir(base) }) });
1028
+ const dir = resolveKubbDir(base);
1029
+ const pathOf = (key) => {
1030
+ const path = resolve(dir, key.replaceAll(":", "/"));
1031
+ if (path === dir || !isPathInside(path, dir)) throw new Error(`Invalid key: ${JSON.stringify(key)}. It should not leave the storage folder`);
1032
+ return path;
1033
+ };
1034
+ return {
1035
+ async getItem(key) {
1036
+ const path = pathOf(key);
1037
+ if (!await exists(path)) return null;
1038
+ const raw = await read(path);
1039
+ try {
1040
+ return JSON.parse(raw);
1041
+ } catch {
1042
+ return raw;
1043
+ }
1044
+ },
1045
+ async setItem(key, value) {
1046
+ await writeRaw(pathOf(key), typeof value === "string" ? value : JSON.stringify(value));
1047
+ },
1048
+ async removeItem(key) {
1049
+ await rm$1(pathOf(key), { force: true });
1050
+ }
1051
+ };
1030
1052
  }
1031
1053
  //#endregion
1032
1054
  //#region src/reporters/fileReporter.ts