@kubb/core 5.0.0-beta.60 → 5.0.0-beta.62

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,5 +1,5 @@
1
1
  import { t as __name } from "./chunk-C0LytTxp.js";
2
- import { $ as KubbPluginSetupContext, A as KubbHookStartContext, At as Adapter, B as ParsedFile, C as KubbFilesProcessingEndContext, Ct as GenerationResult, D as KubbGenerationStartContext, Dt as UserReporter, E as KubbGenerationEndContext, Et as ReporterName, F as KubbSuccessContext, G as Generator, H as createKubb, I as KubbWarnContext, J as KubbDriver, K as GeneratorContext, L as PossibleConfig, M as KubbInfoContext, Mt as AdapterSource, N as KubbLifecycleStartContext, Nt as createAdapter, O as KubbHookEndContext, Ot as createReporter, P as KubbPluginsEndContext, Pt as AsyncEventEmitter, Q as KubbPluginEndContext, R as UserConfig, S as KubbFileProcessingUpdate, St as createStorage, T as KubbFilesProcessingUpdateContext, Tt as ReporterContext, U as Parser, V as Kubb, W as defineParser, X as Group, Y as Exclude, Z as Include, _ as InputPath, _t as defineResolver, a as DiagnosticLocation, at as Override, b as KubbDiagnosticContext, bt as createRenderer, c as PerformanceDiagnostic, ct as definePlugin, d as SerializedDiagnostic, dt as ResolveBannerFile, et as KubbPluginStartContext, f as UpdateDiagnostic, ft as ResolveOptionsContext, g as InputData, gt as ResolverPathParams, h as Config, ht as ResolverFileParams, i as DiagnosticKind, it as OutputOptions, j as KubbHooks, jt as AdapterFactoryOptions, k as KubbHookLineContext, kt as logLevel, l as ProblemCode, lt as BannerMeta, m as CLIOptions, mt as ResolverContext, n as DiagnosticByCode, nt as Output, o as DiagnosticSeverity, ot as Plugin, p as BuildOutput, pt as Resolver, q as defineGenerator, r as DiagnosticDoc, rt as OutputMode, s as Diagnostics, st as PluginFactoryOptions, t as Diagnostic, tt as NormalizedPlugin, u as ProblemDiagnostic, ut as ResolveBannerContext, v as KubbBuildEndContext, vt as Renderer, w as KubbFilesProcessingStartContext, wt as Reporter, x as KubbErrorContext, xt as Storage, y as KubbBuildStartContext, yt as RendererFactory, z as FileProcessorHooks } from "./diagnostics-B-UZnFqP.js";
2
+ import { $ as KubbPluginSetupContext, A as KubbHookStartContext, At as Adapter, B as ParsedFile, C as KubbFilesProcessingEndContext, Ct as GenerationResult, D as KubbGenerationStartContext, Dt as UserReporter, E as KubbGenerationEndContext, Et as ReporterName, F as KubbSuccessContext, G as Generator, H as createKubb, I as KubbWarnContext, J as KubbDriver, K as GeneratorContext, L as PossibleConfig, M as KubbInfoContext, Mt as AdapterSource, N as KubbLifecycleStartContext, Nt as createAdapter, O as KubbHookEndContext, Ot as createReporter, P as KubbPluginsEndContext, Pt as AsyncEventEmitter, Q as KubbPluginEndContext, R as UserConfig, S as KubbFileProcessingUpdate, St as createStorage, T as KubbFilesProcessingUpdateContext, Tt as ReporterContext, U as Parser, V as Kubb, W as defineParser, X as Group, Y as Exclude, Z as Include, _ as InputPath, _t as defineResolver, a as DiagnosticLocation, at as Override, b as KubbDiagnosticContext, bt as createRenderer, c as PerformanceDiagnostic, ct as definePlugin, d as SerializedDiagnostic, dt as ResolveBannerFile, et as KubbPluginStartContext, f as UpdateDiagnostic, ft as ResolveOptionsContext, g as InputData, gt as ResolverPathParams, h as Config, ht as ResolverFileParams, i as DiagnosticKind, it as OutputOptions, j as KubbHooks, jt as AdapterFactoryOptions, k as KubbHookLineContext, kt as logLevel, l as ProblemCode, lt as BannerMeta, m as CLIOptions, mt as ResolverContext, n as DiagnosticByCode, nt as Output, o as DiagnosticSeverity, ot as Plugin, p as BuildOutput, pt as Resolver, q as defineGenerator, r as DiagnosticDoc, rt as OutputMode, s as Diagnostics, st as PluginFactoryOptions, t as Diagnostic, tt as NormalizedPlugin, u as ProblemDiagnostic, ut as ResolveBannerContext, v as KubbBuildEndContext, vt as Renderer, w as KubbFilesProcessingStartContext, wt as Reporter, x as KubbErrorContext, xt as Storage, y as KubbBuildStartContext, yt as RendererFactory, z as FileProcessorHooks } from "./diagnostics-D0G07LHG.js";
3
3
  import * as ast from "@kubb/ast";
4
4
 
5
5
  //#region ../../internals/utils/src/url.d.ts
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { stripVTControlCharacters, styleText } from "node:util";
5
5
  import { access, glob, mkdir, readFile, rm, writeFile } from "node:fs/promises";
6
6
  import path, { dirname, join, relative, resolve } from "node:path";
7
7
  import * as ast from "@kubb/ast";
8
- import { operationDef, schemaDef, transform } from "@kubb/ast";
8
+ import { composeMacros, operationDef, schemaDef, transform } from "@kubb/ast";
9
9
  import { AsyncLocalStorage } from "node:async_hooks";
10
10
  import * as factory from "@kubb/ast/factory";
11
11
  import { collectUsedSchemaNames } from "@kubb/ast/utils";
@@ -608,7 +608,7 @@ function createAdapter(build) {
608
608
  /**
609
609
  * Docs major version, derived from the package version so the link tracks the published major.
610
610
  */
611
- const docsMajor = "5.0.0-beta.60".split(".")[0] ?? "5";
611
+ const docsMajor = "5.0.0-beta.62".split(".")[0] ?? "5";
612
612
  /**
613
613
  * Narrows a {@link Diagnostic} to the variant for `code`, or `null` when it does not match.
614
614
  *
@@ -1489,45 +1489,55 @@ function defineResolver(build) {
1489
1489
  //#endregion
1490
1490
  //#region src/Transform.ts
1491
1491
  /**
1492
- * Holds one `Visitor` per plugin, keyed by plugin name. Each plugin's transformer runs in
1493
- * isolation on the original adapter node. `applyTo` is a lookup, not a chain, so plugin A's
1494
- * visitor never sees plugin B's output. When no transformer is registered, `applyTo` returns
1495
- * the original node reference, and the `@kubb/ast` `transform` primitive does the same when
1496
- * its visitor leaves the tree untouched. Callers can compare by identity to detect a no-op.
1497
- *
1498
- * Registration order matches the order setup hooks fire, which the driver has already sorted
1499
- * by `enforce` and dependency edges. The registry does not re-order anything.
1492
+ * Holds an ordered list of macros per plugin, keyed by plugin name. Each plugin's macros run in
1493
+ * isolation on the original adapter node and are composed into a single `Visitor` that the
1494
+ * `@kubb/ast` `transform` primitive applies. `applyTo` is a per-plugin lookup, not a cross-plugin
1495
+ * chain, so plugin A's macros never see plugin B's output. When a plugin has no macros, `applyTo`
1496
+ * returns the original node reference, and `transform` does the same when the composed visitor
1497
+ * leaves the tree untouched, so callers can detect a no-op by identity.
1498
+ *
1499
+ * Registration order matches the order setup hooks fire, which the driver has already sorted by
1500
+ * `enforce` and dependency edges. The registry preserves that order; macro `enforce` only reorders
1501
+ * within a single plugin's list.
1500
1502
  */
1501
1503
  var Transform = class {
1502
- #visitors = /* @__PURE__ */ new Map();
1504
+ #macros = /* @__PURE__ */ new Map();
1505
+ #composed = /* @__PURE__ */ new Map();
1503
1506
  #memo = /* @__PURE__ */ new Map();
1504
1507
  /**
1505
- * Number of plugins with a registered transformer.
1508
+ * Number of plugins with at least one registered macro.
1506
1509
  */
1507
1510
  get size() {
1508
- return this.#visitors.size;
1511
+ return this.#macros.size;
1509
1512
  }
1510
1513
  /**
1511
- * Records `visitor` as the transformer for `pluginName`. A second call for the same plugin
1512
- * replaces the first.
1514
+ * Appends `macro` to the plugin's list, after any macros already registered.
1513
1515
  */
1514
- register(pluginName, visitor) {
1515
- this.#visitors.set(pluginName, visitor);
1516
- this.#memo.delete(pluginName);
1516
+ add(pluginName, macro) {
1517
+ const list = this.#macros.get(pluginName);
1518
+ if (list) list.push(macro);
1519
+ else this.#macros.set(pluginName, [macro]);
1520
+ this.#invalidate(pluginName);
1521
+ }
1522
+ /**
1523
+ * Replaces the plugin's macro list with `macros`.
1524
+ */
1525
+ set(pluginName, macros) {
1526
+ this.#macros.set(pluginName, [...macros]);
1527
+ this.#invalidate(pluginName);
1517
1528
  }
1518
1529
  /**
1519
- * Looks up the transformer for `pluginName`. The generator context uses this so plugins can
1520
- * read their own visitor through `ctx.transformer`.
1530
+ * Looks up the composed visitor for `pluginName`, or `undefined` when the plugin has no macros.
1521
1531
  */
1522
1532
  get(pluginName) {
1523
- return this.#visitors.get(pluginName);
1533
+ return this.#visitorFor(pluginName);
1524
1534
  }
1525
1535
  /**
1526
- * Runs the plugin's transformer on `node`. Returns the original node reference when the
1527
- * plugin has no transformer, so callers can compare by identity to detect a no-op.
1536
+ * Runs the plugin's macros on `node`. Returns the original node reference when the plugin has no
1537
+ * macros, so callers can compare by identity to detect a no-op.
1528
1538
  */
1529
1539
  applyTo(pluginName, node) {
1530
- const visitor = this.#visitors.get(pluginName);
1540
+ const visitor = this.#visitorFor(pluginName);
1531
1541
  if (!visitor) return node;
1532
1542
  let memo = this.#memo.get(pluginName);
1533
1543
  if (!memo) {
@@ -1541,13 +1551,28 @@ var Transform = class {
1541
1551
  return result;
1542
1552
  }
1543
1553
  /**
1544
- * Clears every registration. Called from the driver's `dispose()` so visitors do not leak
1545
- * across builds.
1554
+ * Clears every registration. Called from the driver's `dispose()` so macros do not leak across
1555
+ * builds.
1546
1556
  */
1547
1557
  dispose() {
1548
- this.#visitors.clear();
1558
+ this.#macros.clear();
1559
+ this.#composed.clear();
1549
1560
  this.#memo.clear();
1550
1561
  }
1562
+ #invalidate(pluginName) {
1563
+ this.#composed.delete(pluginName);
1564
+ this.#memo.delete(pluginName);
1565
+ }
1566
+ #visitorFor(pluginName) {
1567
+ const macros = this.#macros.get(pluginName);
1568
+ if (!macros || macros.length === 0) return void 0;
1569
+ let composed = this.#composed.get(pluginName);
1570
+ if (!composed) {
1571
+ composed = composeMacros(macros);
1572
+ this.#composed.set(pluginName, composed);
1573
+ }
1574
+ return composed;
1575
+ }
1551
1576
  };
1552
1577
  //#endregion
1553
1578
  //#region src/KubbDriver.ts
@@ -1588,7 +1613,7 @@ var KubbDriver = class {
1588
1613
  */
1589
1614
  #listeners = [];
1590
1615
  /**
1591
- * Transform registry. Plugins populate it during `kubb:plugin:setup` via `setTransformer`,
1616
+ * Transform registry. Plugins populate it during `kubb:plugin:setup` via `addMacro`/`setMacros`,
1592
1617
  * and `#runGenerators` reads it once per `(plugin, node)` pair through `applyTo`.
1593
1618
  */
1594
1619
  #transforms = new Transform();
@@ -1671,7 +1696,7 @@ var KubbDriver = class {
1671
1696
  * Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.
1672
1697
  *
1673
1698
  * The `kubb:plugin:setup` listener wraps the global context in a plugin-specific one so
1674
- * `addGenerator`, `setResolver`, and `setTransformer` target the right `normalizedPlugin`.
1699
+ * `addGenerator`, `setResolver`, and `setMacros` target the right `normalizedPlugin`.
1675
1700
  * Every other `KubbHooks` event registers as a pass-through listener that external tooling
1676
1701
  * can observe via `hooks.on(...)`.
1677
1702
  *
@@ -1691,8 +1716,11 @@ var KubbDriver = class {
1691
1716
  setResolver: (resolver) => {
1692
1717
  this.setPluginResolver(plugin.name, resolver);
1693
1718
  },
1694
- setTransformer: (visitor) => {
1695
- this.#transforms.register(plugin.name, visitor);
1719
+ addMacro: (macro) => {
1720
+ this.#transforms.add(plugin.name, macro);
1721
+ },
1722
+ setMacros: (macros) => {
1723
+ this.#transforms.set(plugin.name, macros);
1696
1724
  },
1697
1725
  setOptions: (opts) => {
1698
1726
  plugin.options = {
@@ -1725,7 +1753,7 @@ var KubbDriver = class {
1725
1753
  }
1726
1754
  /**
1727
1755
  * Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners
1728
- * can configure generators, resolvers, transformers and renderers before `buildStart` runs.
1756
+ * can configure generators, resolvers, macros and renderers before `buildStart` runs.
1729
1757
  *
1730
1758
  * Call this once from `safeBuild` before the plugin execution loop begins.
1731
1759
  */
@@ -1736,7 +1764,8 @@ var KubbDriver = class {
1736
1764
  options: {},
1737
1765
  addGenerator: noop,
1738
1766
  setResolver: noop,
1739
- setTransformer: noop,
1767
+ addMacro: noop,
1768
+ setMacros: noop,
1740
1769
  setOptions: noop,
1741
1770
  injectFile: noop,
1742
1771
  updateConfig: noop
@@ -1756,39 +1785,21 @@ var KubbDriver = class {
1756
1785
  * Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.
1757
1786
  */
1758
1787
  registerGenerator(pluginName, generator) {
1759
- if (generator.schema) {
1760
- const schemaHandler = async (node, ctx) => {
1788
+ const register = (event, method) => {
1789
+ if (!method) return;
1790
+ const handler = async (node, ctx) => {
1761
1791
  if (ctx.plugin.name !== pluginName) return;
1762
- const result = await generator.schema(node, ctx);
1792
+ const result = await method(node, ctx);
1763
1793
  await this.dispatch({
1764
1794
  result,
1765
1795
  renderer: generator.renderer
1766
1796
  });
1767
1797
  };
1768
- this.#trackListener("kubb:generate:schema", schemaHandler);
1769
- }
1770
- if (generator.operation) {
1771
- const operationHandler = async (node, ctx) => {
1772
- if (ctx.plugin.name !== pluginName) return;
1773
- const result = await generator.operation(node, ctx);
1774
- await this.dispatch({
1775
- result,
1776
- renderer: generator.renderer
1777
- });
1778
- };
1779
- this.#trackListener("kubb:generate:operation", operationHandler);
1780
- }
1781
- if (generator.operations) {
1782
- const operationsHandler = async (nodes, ctx) => {
1783
- if (ctx.plugin.name !== pluginName) return;
1784
- const result = await generator.operations(nodes, ctx);
1785
- await this.dispatch({
1786
- result,
1787
- renderer: generator.renderer
1788
- });
1789
- };
1790
- this.#trackListener("kubb:generate:operations", operationsHandler);
1791
- }
1798
+ this.#trackListener(event, handler);
1799
+ };
1800
+ register("kubb:generate:schema", generator.schema);
1801
+ register("kubb:generate:operation", generator.operation);
1802
+ register("kubb:generate:operations", generator.operations);
1792
1803
  this.#eventGeneratorPlugins.add(pluginName);
1793
1804
  }
1794
1805
  /**
@@ -1928,7 +1939,7 @@ var KubbDriver = class {
1928
1939
  }
1929
1940
  /**
1930
1941
  * Streams schemas and operations through every plugin's generators. Each node is run
1931
- * through the plugin's transformer (from `this.#transforms`) before the generator sees it,
1942
+ * through the plugin's macros (from `this.#transforms`) before the generator sees it,
1932
1943
  * so plugins stay isolated and the hot path stays per-node. Schemas run before operations
1933
1944
  * because the two passes share `flushPending` and the FileProcessor's event emitter.
1934
1945
  * A failing plugin contributes an error diagnostic so the rest of the build continues.
@@ -2232,9 +2243,6 @@ var KubbDriver = class {
2232
2243
  get resolver() {
2233
2244
  return driver.getResolver(plugin.name);
2234
2245
  },
2235
- get transformer() {
2236
- return driver.#transforms.get(plugin.name);
2237
- },
2238
2246
  warn(message) {
2239
2247
  report({
2240
2248
  code: Diagnostics.code.pluginWarning,