@kubb/core 5.0.0-beta.93 → 5.0.0-beta.95

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.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
- import { $ as ResolveBannerContext, A as Generator, At as ProblemCode, B as Include, C as KubbWarnContext, Ct as Diagnostic, D as CreateKubbOptions, Dt as DiagnosticSeverity, E as UserConfig, Et as DiagnosticLocation, F as Parser, Ft as Adapter, G as Output, H as KubbPluginSetupContext, I as defineParser, It as AdapterFactoryOptions, J as Override, K as OutputMode, L as Exclude, Lt as AdapterSource, M as defineGenerator, Mt as SerializedDiagnostic, N as KubbDriver, Nt as UpdateDiagnostic, O as Kubb, Ot as Diagnostics, P as FileManagerHooks, Pt as Hookable, Q as BannerMeta, R as Filter, Rt as createAdapter, S as KubbSuccessContext, St as logLevel, T as PostGenerateCommand, Tt as DiagnosticKind, U as KubbPluginStartContext, V as KubbPluginEndContext, W as NormalizedPlugin, X as PluginFactoryOptions, Y as Plugin, Z as definePlugin, _ as KubbHookStartContext, _t as Reporter, a as KubbBuildEndContext, at as ResolverDefault, b as KubbLifecycleStartContext, bt as UserReporter, c as KubbErrorContext, ct as ResolverFilePathParams, d as KubbFilesProcessingStartContext, dt as Renderer, et as ResolveBannerFile, f as KubbFilesProcessingUpdateContext, ft as RendererFactory, g as KubbHookLineContext, gt as GenerationResult, h as KubbHookEndContext, ht as createStorage, i as Input, it as Resolver, j as GeneratorContext, jt as ProblemDiagnostic, k as createKubb, kt as PerformanceDiagnostic, l as KubbFileProcessingUpdate, lt as ResolverPatch, m as KubbGenerationStartContext, mt as Storage, n as CLIOptions, nt as ResolveOptionsContext, o as KubbBuildStartContext, ot as ResolverFile, p as KubbGenerationEndContext, pt as createRenderer, q as OutputOptions, r as Config, rt as ResolvePathOptions, s as KubbDiagnosticContext, st as ResolverFileParams, t as BuildOutput, tt as ResolveFileOptions, u as KubbFilesProcessingEndContext, ut as ResolverPathParams, v as KubbHooks, vt as ReporterContext, w as PossibleConfig, wt as DiagnosticDoc, x as KubbPluginsEndContext, xt as createReporter, y as KubbInfoContext, yt as ReporterName, z as Group } from "./types-BLFyAJLZ.js";
3
-
2
+ import { $ as definePlugin, A as Generator, At as DiagnosticSeverity, B as Include, Bt as AdapterSource, C as KubbWarnContext, Ct as UserReporter, D as CreateKubbOptions, Dt as DiagnosticDoc, E as UserConfig, Et as Diagnostic, F as Parser, Ft as SerializedDiagnostic, G as Output, H as KubbPluginSetupContext, I as defineParser, It as UpdateDiagnostic, J as Override, K as OutputMode, L as Exclude, Lt as Hookable, M as defineGenerator, Mt as PerformanceDiagnostic, N as KubbDriver, Nt as ProblemCode, O as Kubb, Ot as DiagnosticKind, P as FileManagerHooks, Pt as ProblemDiagnostic, Q as ResolvePluginOptions, R as Filter, Rt as Adapter, S as KubbSuccessContext, St as ReporterName, T as PostGenerateCommand, Tt as logLevel, U as KubbPluginStartContext, V as KubbPluginEndContext, Vt as createAdapter, W as NormalizedPlugin, X as PluginFactoryOptions, Y as Plugin, Z as PluginName, _ as KubbHookStartContext, _t as Storage, a as KubbBuildEndContext, at as ResolveOptionsContext, b as KubbLifecycleStartContext, bt as Reporter, c as KubbErrorContext, ct as ResolverDefault, d as KubbFilesProcessingStartContext, dt as ResolverFilePathParams, et as BannerMeta, f as KubbFilesProcessingUpdateContext, ft as ResolverPatch, g as KubbHookLineContext, gt as createRenderer, h as KubbHookEndContext, ht as RendererFactory, i as Input, it as ResolveImportsOptions, j as GeneratorContext, jt as Diagnostics, k as createKubb, kt as DiagnosticLocation, l as KubbFileProcessingUpdate, lt as ResolverFile, m as KubbGenerationStartContext, mt as Renderer, n as CLIOptions, nt as ResolveBannerFile, o as KubbBuildStartContext, ot as ResolvePathOptions, p as KubbGenerationEndContext, pt as ResolverPathParams, q as OutputOptions, r as Config, rt as ResolveFileOptions, s as KubbDiagnosticContext, st as Resolver, t as BuildOutput, tt as ResolveBannerContext, u as KubbFilesProcessingEndContext, ut as ResolverFileParams, v as KubbHooks, vt as createStorage, w as PossibleConfig, wt as createReporter, x as KubbPluginsEndContext, xt as ReporterContext, y as KubbInfoContext, yt as GenerationResult, z as Group, zt as AdapterFactoryOptions } from "./types-Bl0feoGY.js";
4
3
  //#region src/applyConfigDefaults.d.ts
5
4
  type ApplyConfigDefaultsOptions<TOutput> = {
6
5
  defaultAdapter: Adapter;
7
6
  barrelPlugin: Plugin;
8
- barrelPluginName: string; /** Output fields to fill in when the user's config leaves them unset. */
7
+ barrelPluginName: string;
8
+ /** Output fields to fill in when the user's config leaves them unset. */
9
9
  defaultOutput: Partial<TOutput>;
10
10
  };
11
11
  /**
@@ -19,12 +19,7 @@ declare function applyConfigDefaults<TOutput extends Config['output'] = Config['
19
19
  adapter?: Adapter;
20
20
  output: TOutput;
21
21
  plugins?: Array<Plugin>;
22
- }, {
23
- defaultAdapter,
24
- barrelPlugin,
25
- barrelPluginName,
26
- defaultOutput
27
- }: ApplyConfigDefaultsOptions<TOutput>): {
22
+ }, { defaultAdapter, barrelPlugin, barrelPluginName, defaultOutput }: ApplyConfigDefaultsOptions<TOutput>): {
28
23
  adapter: Adapter;
29
24
  output: TOutput;
30
25
  plugins: Array<Plugin>;
@@ -188,5 +183,5 @@ declare const fsStorage: (options?: Record<string, never> | undefined) => Storag
188
183
  */
189
184
  declare const memoryStorage: (options?: Record<string, never> | undefined) => Storage;
190
185
  //#endregion
191
- 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 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, KubbHookEndContext, KubbHookLineContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, type KubbPluginEndContext, type KubbPluginSetupContext, type KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbWarnContext, type NormalizedPlugin, type Output, type OutputMode, type OutputOptions, type Override, type Parser, type PerformanceDiagnostic, type Plugin, type PluginFactoryOptions, PossibleConfig, PostGenerateCommand, type ProblemCode, type ProblemDiagnostic, type Renderer, type RendererFactory, type Reporter, type ReporterContext, type ReporterName, type ResolveBannerContext, type ResolveBannerFile, type ResolveFileOptions, type ResolveOptionsContext, type ResolvePathOptions, Resolver, type ResolverDefault, type ResolverFile, type ResolverFileParams, type ResolverFilePathParams, type ResolverPatch, type ResolverPathParams, type SerializedDiagnostic, type Storage, type UpdateDiagnostic, UserConfig, type UserReporter, applyConfigDefaults, cliReporter, createAdapter, createKubb, createRenderer, createReporter, createResolver, createStorage, defineGenerator, defineParser, definePlugin, fileReporter, fsStorage, getInputKind, jsonReporter, logLevel, memoryStorage };
186
+ 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 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, KubbHookEndContext, KubbHookLineContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, type KubbPluginEndContext, type KubbPluginSetupContext, type KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbWarnContext, 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 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 UpdateDiagnostic, UserConfig, type UserReporter, applyConfigDefaults, cliReporter, createAdapter, createKubb, createRenderer, createReporter, createResolver, createStorage, defineGenerator, defineParser, definePlugin, fileReporter, fsStorage, getInputKind, jsonReporter, logLevel, memoryStorage };
192
187
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { stripVTControlCharacters, styleText } from "node:util";
5
5
  import { hash } from "node:crypto";
6
6
  import { access, glob, readFile, rm } from "node:fs/promises";
7
7
  import path, { join, relative, resolve } from "node:path";
8
- import { ast, collectUsedSchemaNames, composeMacros, operationDef, schemaDef, transform } from "@kubb/ast";
8
+ import { ast, collect, collectUsedSchemaNames, composeMacros, narrowSchema, operationDef, resolveRefName, schemaDef, transform } from "@kubb/ast";
9
9
  import process$1 from "node:process";
10
10
  //#region src/createAdapter.ts
11
11
  /**
@@ -31,7 +31,6 @@ import process$1 from "node:process";
31
31
  * // Convert the source (path or inline data) into an InputNode.
32
32
  * return ast.factory.createInput()
33
33
  * },
34
- * getImports: () => [],
35
34
  * async validate() {
36
35
  * // Throw here when the spec is invalid.
37
36
  * },
@@ -190,7 +189,7 @@ function memoize(store, factory) {
190
189
  }
191
190
  //#endregion
192
191
  //#region package.json
193
- var version = "5.0.0-beta.93";
192
+ var version = "5.0.0-beta.95";
194
193
  //#endregion
195
194
  //#region src/constants.ts
196
195
  /**
@@ -811,9 +810,9 @@ function toBaseName({ name, extname }) {
811
810
  /**
812
811
  * Base constraint for all plugin resolver objects.
813
812
  *
814
- * The built-in machinery lives under `default`. Generators call the top-level `name` and
815
- * `file`, and a plugin overrides them to set its conventions. Extend with top-level helpers
816
- * (`typeName`, …) and/or grouped namespaces (`query`, `schema`, …).
813
+ * The built-in machinery lives under `default`. Generators call the top-level `name`, `file`,
814
+ * and `imports`, and a plugin overrides `name` and `file` to set its conventions. Extend with
815
+ * top-level helpers (`typeName`, …) and/or grouped namespaces (`query`, `schema`, …).
817
816
  *
818
817
  * @example Top-level helper
819
818
  * ```ts
@@ -871,6 +870,35 @@ var Resolver = class Resolver {
871
870
  return this.#resolveFile(options);
872
871
  }
873
872
  /**
873
+ * Builds one `ImportNode` per unique schema referenced in the tree, in first-occurrence
874
+ * order. Each ref's target resolves through `resolveRefName`, so collision- or macro-renamed
875
+ * schemas (`targetName`) import the emitted name. Names and paths go through the top-level
876
+ * `name` and `file`, so import entries follow the plugin's conventions, and a per-call
877
+ * `name` override wins over both.
878
+ */
879
+ imports(options) {
880
+ const { node, root, output, group, extname = ".ts", name } = options;
881
+ const resolveName = name ?? ((schemaName) => this.name(schemaName));
882
+ const seen = /* @__PURE__ */ new Set();
883
+ return collect(node, { schema: (schemaNode) => {
884
+ const schemaRef = narrowSchema(schemaNode, "ref");
885
+ if (!schemaRef?.ref) return null;
886
+ const schemaName = resolveRefName(schemaRef);
887
+ if (!schemaName || seen.has(schemaName)) return null;
888
+ seen.add(schemaName);
889
+ return ast.factory.createImport({
890
+ name: [resolveName(schemaName)],
891
+ path: this.file({
892
+ name: schemaName,
893
+ extname,
894
+ root,
895
+ output,
896
+ group
897
+ }).path
898
+ });
899
+ } });
900
+ }
901
+ /**
874
902
  * Merges `override` over `base` and returns a new resolver with helpers re-bound. Top-level
875
903
  * keys replace, and a namespace (or `file`) merges per method, so overriding `query.name`
876
904
  * keeps the base `query.keyName`. Used when applying `setResolver` partial overrides. Reads a
@@ -1301,7 +1329,8 @@ var KubbDriver = class {
1301
1329
  },
1302
1330
  exclude: [],
1303
1331
  override: []
1304
- }
1332
+ },
1333
+ resolver: this.#getDefaultResolver(rawPlugin.name)
1305
1334
  };
1306
1335
  }));
1307
1336
  for (const plugin of normalized) {
@@ -2141,10 +2170,10 @@ const logLevel = {
2141
2170
  verbose: 4
2142
2171
  };
2143
2172
  /**
2144
- * Defines a reporter. When the definition has a `drain`, the returned reporter buffers each value
2145
- * `report` returns and hands the array to `drain` once, then clears it. Without a `drain`, nothing
2146
- * is buffered. Wiring the reporter onto the run's hooks is the host's job, so the reporter only
2147
- * ever deals with a {@link GenerationResult}.
2173
+ * Defines a reporter. The returned reporter buffers each value `report` returns in order and, when
2174
+ * the definition has a `drain`, hands the array to `drain` once and then clears it. Wiring the
2175
+ * reporter onto the run's hooks is the host's job, so the reporter only ever deals with a
2176
+ * {@link GenerationResult}.
2148
2177
  *
2149
2178
  * @example
2150
2179
  * ```ts
@@ -2162,19 +2191,19 @@ const logLevel = {
2162
2191
  * ```
2163
2192
  */
2164
2193
  function createReporter(reporter) {
2165
- const reports = /* @__PURE__ */ new Set();
2194
+ const reports = [];
2166
2195
  return {
2167
2196
  name: reporter.name,
2168
2197
  async report(result, context) {
2169
2198
  const report = await reporter.report(result, context);
2170
- reports.add(report);
2199
+ if (reporter.drain) reports.push(report);
2171
2200
  },
2172
2201
  async drain(context) {
2173
- await reporter.drain?.(context, Array.from(reports));
2174
- reports.clear();
2202
+ await reporter.drain?.(context, [...reports]);
2203
+ reports.length = 0;
2175
2204
  },
2176
2205
  [Symbol.dispose]() {
2177
- reports.clear();
2206
+ reports.length = 0;
2178
2207
  }
2179
2208
  };
2180
2209
  }