@kubb/core 5.18.4 → 5.18.6

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
@@ -2,13 +2,9 @@ import { Enforce, FileNode, HttpMethod, ImportNode, InlineLanguage, InputMeta, I
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
3
  import net from "node:net";
4
4
  type Options$1 = {
5
- /**
6
- * Text prepended before casing is applied.
7
- */
5
+ /** Text prepended before casing is applied. */
8
6
  prefix?: string;
9
- /**
10
- * Text appended before casing is applied.
11
- */
7
+ /** Text appended before casing is applied. */
12
8
  suffix?: string;
13
9
  };
14
10
  /**
@@ -2227,7 +2223,7 @@ type Generator<TOptions extends PluginType = PluginType, TElement = unknown> = {
2227
2223
  * @example Only match GET operations
2228
2224
  * ```ts
2229
2225
  * match(node, ctx) {
2230
- * return ast.isHttpOperationNode(node) && node.method.toLowerCase() === 'get'
2226
+ * return ast.http.isOperation(node) && node.method.toLowerCase() === 'get'
2231
2227
  * }
2232
2228
  * ```
2233
2229
  */
@@ -2621,12 +2617,12 @@ export declare class Resolver {
2621
2617
  file(options: ResolveFileOptions): FileNode;
2622
2618
  /**
2623
2619
  * Builds one `ImportNode` per unique schema referenced in the tree, in first-occurrence
2624
- * order. Each ref's target resolves through `resolveRefName`, so collision- or macro-renamed
2620
+ * order. Each ref's target resolves through `ast.ref.getName`, so collision- or macro-renamed
2625
2621
  * schemas (`targetName`) import the emitted name. Names and paths go through the top-level
2626
2622
  * `name` and `file`, so import entries follow the plugin's conventions, and a per-call
2627
2623
  * `name` override wins over both.
2628
2624
  *
2629
- * The subtree scan runs through `collectImportedRefNames`, which memoizes by node identity, so a
2625
+ * The subtree scan runs through `ast.graph.getImportedNames`, which memoizes by node identity, so a
2630
2626
  * schema shared across the ts, zod, and faker plugins is walked once and every plugin's resolver
2631
2627
  * reads the same ref set instead of re-scanning it per plugin.
2632
2628
  */
@@ -2646,6 +2642,18 @@ export declare class Resolver {
2646
2642
  * ```
2647
2643
  */
2648
2644
  static merge<T extends Resolver>(base: T, ...overrides: Array<ResolverPatch<T> | Resolver>): T;
2645
+ /**
2646
+ * The folder a group puts a file in, relative to the output directory. A custom `group.name` wins; otherwise `tag`
2647
+ * groups use the camelCased tag, nested in the folders of its `parent` tags, and `path` groups use the first
2648
+ * non-traversal segment (`''` when none remain, placing the file in the output root, kept safe by the caller's
2649
+ * boundary check).
2650
+ *
2651
+ * @example
2652
+ * ```ts
2653
+ * resolver.groupDir({ type: 'tag' }, 'pet store') // 'petStore'
2654
+ * ```
2655
+ */
2656
+ groupDir(group: Group, groupValue: string): string;
2649
2657
  }
2650
2658
  /** Reads key `K` from a registry interface, or `{}` when no package has augmented it. @internal */
2651
2659
  type ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {};
@@ -3232,7 +3240,7 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
3232
3240
  * Parse the source into a universal `InputNode`.
3233
3241
  *
3234
3242
  * An adapter that renames schemas (e.g. collision handling) must stamp `targetName` on
3235
- * every ref node pointing at a renamed schema, so `resolveRefName` and `resolver.imports`
3243
+ * every ref node pointing at a renamed schema, so `ast.ref.getName` and `resolver.imports`
3236
3244
  * resolve a `$ref` to the file that is actually generated. Refs that keep their pointer's
3237
3245
  * last segment need no stamp.
3238
3246
  */
package/dist/index.d.ts CHANGED
@@ -2,13 +2,9 @@ import { Enforce, FileNode, HttpMethod, ImportNode, InlineLanguage, InputMeta, I
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
3
  import net from "node:net";
4
4
  type Options$1 = {
5
- /**
6
- * Text prepended before casing is applied.
7
- */
5
+ /** Text prepended before casing is applied. */
8
6
  prefix?: string;
9
- /**
10
- * Text appended before casing is applied.
11
- */
7
+ /** Text appended before casing is applied. */
12
8
  suffix?: string;
13
9
  };
14
10
  /**
@@ -2227,7 +2223,7 @@ type Generator<TOptions extends PluginType = PluginType, TElement = unknown> = {
2227
2223
  * @example Only match GET operations
2228
2224
  * ```ts
2229
2225
  * match(node, ctx) {
2230
- * return ast.isHttpOperationNode(node) && node.method.toLowerCase() === 'get'
2226
+ * return ast.http.isOperation(node) && node.method.toLowerCase() === 'get'
2231
2227
  * }
2232
2228
  * ```
2233
2229
  */
@@ -2621,12 +2617,12 @@ export declare class Resolver {
2621
2617
  file(options: ResolveFileOptions): FileNode;
2622
2618
  /**
2623
2619
  * Builds one `ImportNode` per unique schema referenced in the tree, in first-occurrence
2624
- * order. Each ref's target resolves through `resolveRefName`, so collision- or macro-renamed
2620
+ * order. Each ref's target resolves through `ast.ref.getName`, so collision- or macro-renamed
2625
2621
  * schemas (`targetName`) import the emitted name. Names and paths go through the top-level
2626
2622
  * `name` and `file`, so import entries follow the plugin's conventions, and a per-call
2627
2623
  * `name` override wins over both.
2628
2624
  *
2629
- * The subtree scan runs through `collectImportedRefNames`, which memoizes by node identity, so a
2625
+ * The subtree scan runs through `ast.graph.getImportedNames`, which memoizes by node identity, so a
2630
2626
  * schema shared across the ts, zod, and faker plugins is walked once and every plugin's resolver
2631
2627
  * reads the same ref set instead of re-scanning it per plugin.
2632
2628
  */
@@ -2646,6 +2642,18 @@ export declare class Resolver {
2646
2642
  * ```
2647
2643
  */
2648
2644
  static merge<T extends Resolver>(base: T, ...overrides: Array<ResolverPatch<T> | Resolver>): T;
2645
+ /**
2646
+ * The folder a group puts a file in, relative to the output directory. A custom `group.name` wins; otherwise `tag`
2647
+ * groups use the camelCased tag, nested in the folders of its `parent` tags, and `path` groups use the first
2648
+ * non-traversal segment (`''` when none remain, placing the file in the output root, kept safe by the caller's
2649
+ * boundary check).
2650
+ *
2651
+ * @example
2652
+ * ```ts
2653
+ * resolver.groupDir({ type: 'tag' }, 'pet store') // 'petStore'
2654
+ * ```
2655
+ */
2656
+ groupDir(group: Group, groupValue: string): string;
2649
2657
  }
2650
2658
  /** Reads key `K` from a registry interface, or `{}` when no package has augmented it. @internal */
2651
2659
  type ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {};
@@ -3232,7 +3240,7 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
3232
3240
  * Parse the source into a universal `InputNode`.
3233
3241
  *
3234
3242
  * An adapter that renames schemas (e.g. collision handling) must stamp `targetName` on
3235
- * every ref node pointing at a renamed schema, so `resolveRefName` and `resolver.imports`
3243
+ * every ref node pointing at a renamed schema, so `ast.ref.getName` and `resolver.imports`
3236
3244
  * resolve a `$ref` to the file that is actually generated. Refs that keep their pointer's
3237
3245
  * last segment need no stamp.
3238
3246
  */
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import { access, glob, mkdir, mkdtemp, readFile, readdir, rename, rm, rm as rm$1
7
7
  import path, { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
8
8
  import { chmodSync, existsSync, existsSync as existsSync$1, mkdirSync } from "node:fs";
9
9
  import { stripVTControlCharacters, styleText } from "node:util";
10
- import { ast, collectImportedRefNames, collectUsedSchemaNames, compareEnforce, extractStringsFromNodes } from "@kubb/ast";
10
+ import { ast } from "@kubb/ast";
11
11
  import dns from "node:dns";
12
12
  import net from "node:net";
13
13
  import { homedir, tmpdir } from "node:os";
@@ -21,7 +21,7 @@ var __name = (target, value) => __defProp(target, "name", {
21
21
  configurable: true
22
22
  });
23
23
  // package.json
24
- var version = "5.18.4";
24
+ var version = "5.18.6";
25
25
  // ../../internals/utils/src/casing.ts
26
26
  /**
27
27
  * Shared implementation for camelCase and PascalCase conversion.
@@ -1741,7 +1741,7 @@ function matchesSchema(node, filter) {
1741
1741
  return null;
1742
1742
  }
1743
1743
  function computeOptions(node, { options, exclude = [], include, override = [] }) {
1744
- if (node.kind === ast.nodeKinds.operation) {
1744
+ if (node.kind === ast.node.kinds.operation) {
1745
1745
  if (exclude.some((filter) => matchesOperation(node, filter))) return null;
1746
1746
  if (include && !include.some((filter) => matchesOperation(node, filter))) return null;
1747
1747
  return {
@@ -1749,7 +1749,7 @@ function computeOptions(node, { options, exclude = [], include, override = [] })
1749
1749
  ...override.find((filter) => matchesOperation(node, filter))?.options
1750
1750
  };
1751
1751
  }
1752
- if (node.kind === ast.nodeKinds.schema) {
1752
+ if (node.kind === ast.node.kinds.schema) {
1753
1753
  if (exclude.some((filter) => matchesSchema(node, filter) === true)) return null;
1754
1754
  if (include) {
1755
1755
  const applicable = include.map((filter) => matchesSchema(node, filter)).filter((result) => result !== null);
@@ -1928,19 +1928,19 @@ var Resolver = class Resolver {
1928
1928
  }
1929
1929
  /**
1930
1930
  * Builds one `ImportNode` per unique schema referenced in the tree, in first-occurrence
1931
- * order. Each ref's target resolves through `resolveRefName`, so collision- or macro-renamed
1931
+ * order. Each ref's target resolves through `ast.ref.getName`, so collision- or macro-renamed
1932
1932
  * schemas (`targetName`) import the emitted name. Names and paths go through the top-level
1933
1933
  * `name` and `file`, so import entries follow the plugin's conventions, and a per-call
1934
1934
  * `name` override wins over both.
1935
1935
  *
1936
- * The subtree scan runs through `collectImportedRefNames`, which memoizes by node identity, so a
1936
+ * The subtree scan runs through `ast.graph.getImportedNames`, which memoizes by node identity, so a
1937
1937
  * schema shared across the ts, zod, and faker plugins is walked once and every plugin's resolver
1938
1938
  * reads the same ref set instead of re-scanning it per plugin.
1939
1939
  */
1940
1940
  imports(options) {
1941
1941
  const { node, root, output, group, extname = ".ts", name, checks } = options;
1942
1942
  const resolveName = name ?? ((schemaName) => this.name(schemaName));
1943
- return collectImportedRefNames(node, { checks }).map((schemaName) => ast.factory.createImport({
1943
+ return ast.graph.getImportedNames(node, { checks }).map((schemaName) => ast.factory.createImport({
1944
1944
  name: [resolveName(schemaName)],
1945
1945
  path: this.#resolveFilePath({
1946
1946
  name: schemaName,
@@ -1994,11 +1994,17 @@ var Resolver = class Resolver {
1994
1994
  }
1995
1995
  }
1996
1996
  /**
1997
- * A custom `group.name` wins; otherwise `tag` groups use the camelCased tag, nested in the
1998
- * folders of its `parent` tags, and `path` groups use the first non-traversal segment (`''`
1999
- * when none remain, placing the file in the output root, kept safe by the caller's boundary check).
1997
+ * The folder a group puts a file in, relative to the output directory. A custom `group.name` wins; otherwise `tag`
1998
+ * groups use the camelCased tag, nested in the folders of its `parent` tags, and `path` groups use the first
1999
+ * non-traversal segment (`''` when none remain, placing the file in the output root, kept safe by the caller's
2000
+ * boundary check).
2001
+ *
2002
+ * @example
2003
+ * ```ts
2004
+ * resolver.groupDir({ type: 'tag' }, 'pet store') // 'petStore'
2005
+ * ```
2000
2006
  */
2001
- #resolveGroupDir(group, groupValue) {
2007
+ groupDir(group, groupValue) {
2002
2008
  if (group.name) return group.name({ group: groupValue });
2003
2009
  if (group.type === "tag") {
2004
2010
  const chain = [groupValue];
@@ -2017,7 +2023,7 @@ var Resolver = class Resolver {
2017
2023
  if (output.mode !== "directory") return path.resolve(root, output.path);
2018
2024
  const outputDir = path.resolve(root, output.path);
2019
2025
  const groupValue = group?.type === "path" ? groupPath : tag;
2020
- const result = group && groupValue ? path.resolve(outputDir, this.#resolveGroupDir(group, groupValue), baseName) : path.resolve(outputDir, baseName);
2026
+ const result = group && groupValue ? path.resolve(outputDir, this.groupDir(group, groupValue), baseName) : path.resolve(outputDir, baseName);
2021
2027
  assertInside({
2022
2028
  target: result,
2023
2029
  parent: outputDir,
@@ -2240,7 +2246,7 @@ function _usingCtx() {
2240
2246
  };
2241
2247
  }
2242
2248
  function joinSources(file) {
2243
- return file.sources.map((source) => extractStringsFromNodes(source.nodes)).filter(Boolean).join("\n\n");
2249
+ return file.sources.map((source) => ast.node.getText(source.nodes)).filter(Boolean).join("\n\n");
2244
2250
  }
2245
2251
  /** Runs a parser call and turns a crash into a `KUBB_PARSER_FAILED` diagnostic that names the parser. */
2246
2252
  function runParser(parser, print) {
@@ -2572,7 +2578,7 @@ function assertPluginEntry(entry, index) {
2572
2578
  * pointer into the input.
2573
2579
  */
2574
2580
  function getCrashSite(node) {
2575
- if (node.kind === ast.nodeKinds.schema) return {
2581
+ if (node.kind === ast.node.kinds.schema) return {
2576
2582
  label: node.name ? `schema "${node.name}"` : "an inline schema",
2577
2583
  location: node.pointer ? {
2578
2584
  kind: "schema",
@@ -2672,7 +2678,7 @@ var KubbDriver = class {
2672
2678
  * config are ignored here and surface later through `requirePlugin`.
2673
2679
  */
2674
2680
  #sortPlugins(plugins) {
2675
- const queue = [...plugins].sort((a, b) => compareEnforce(a.enforce, b.enforce));
2681
+ const queue = [...plugins].sort((a, b) => ast.macro.compareOrder(a.enforce, b.enforce));
2676
2682
  const names = new Set(queue.map((plugin) => plugin.name));
2677
2683
  const blockedBy = new Map(queue.map((plugin) => {
2678
2684
  const dependencies = Array.isArray(plugin.dependencies) ? plugin.dependencies : Object.keys(plugin.dependencies ?? {});
@@ -2880,7 +2886,7 @@ var KubbDriver = class {
2880
2886
  * (`kubb:plugins:end`) and the write see them.
2881
2887
  */
2882
2888
  #inlineFiles(parsers) {
2883
- const { files, virtualPaths, problems } = ast.inlineFiles(this.fileManager.files, { language: (file) => parsers.get(file.extname)?.inline });
2889
+ const { files, virtualPaths, problems } = ast.file.inline(this.fileManager.files, { language: (file) => parsers.get(file.extname)?.inline });
2884
2890
  if (virtualPaths.length === 0) return;
2885
2891
  this.fileManager.add(...files);
2886
2892
  this.fileManager.delete(...virtualPaths);
@@ -2967,7 +2973,7 @@ var KubbDriver = class {
2967
2973
  include,
2968
2974
  override
2969
2975
  }) !== null);
2970
- allowedSchemaNamesByPlugin.set(plugin.name, collectUsedSchemaNames(includedOps, schemas));
2976
+ allowedSchemaNamesByPlugin.set(plugin.name, ast.graph.getUsedNames(includedOps, schemas));
2971
2977
  }
2972
2978
  const states = entries.map(({ plugin, context, hrStart }) => {
2973
2979
  const generatorContext = {
@@ -2995,7 +3001,7 @@ var KubbDriver = class {
2995
3001
  };
2996
3002
  });
2997
3003
  const resolveForPlugin = (state, node) => {
2998
- const transformedNode = ast.applyMacros(node, state.plugin.macros ?? []);
3004
+ const transformedNode = ast.macro.apply(node, state.plugin.macros ?? []);
2999
3005
  if (state.optionsAreStatic) return {
3000
3006
  transformedNode,
3001
3007
  options: state.plugin.options