@kubb/core 5.0.0-beta.94 → 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.cjs CHANGED
@@ -33,7 +33,6 @@ node_process = require_usingCtx.__toESM(node_process, 1);
33
33
  * // Convert the source (path or inline data) into an InputNode.
34
34
  * return ast.factory.createInput()
35
35
  * },
36
- * getImports: () => [],
37
36
  * async validate() {
38
37
  * // Throw here when the spec is invalid.
39
38
  * },
@@ -192,7 +191,7 @@ function memoize(store, factory) {
192
191
  }
193
192
  //#endregion
194
193
  //#region package.json
195
- var version = "5.0.0-beta.94";
194
+ var version = "5.0.0-beta.95";
196
195
  //#endregion
197
196
  //#region src/constants.ts
198
197
  /**
@@ -813,9 +812,9 @@ function toBaseName({ name, extname }) {
813
812
  /**
814
813
  * Base constraint for all plugin resolver objects.
815
814
  *
816
- * The built-in machinery lives under `default`. Generators call the top-level `name` and
817
- * `file`, and a plugin overrides them to set its conventions. Extend with top-level helpers
818
- * (`typeName`, …) and/or grouped namespaces (`query`, `schema`, …).
815
+ * The built-in machinery lives under `default`. Generators call the top-level `name`, `file`,
816
+ * and `imports`, and a plugin overrides `name` and `file` to set its conventions. Extend with
817
+ * top-level helpers (`typeName`, …) and/or grouped namespaces (`query`, `schema`, …).
819
818
  *
820
819
  * @example Top-level helper
821
820
  * ```ts
@@ -873,6 +872,35 @@ var Resolver = class Resolver {
873
872
  return this.#resolveFile(options);
874
873
  }
875
874
  /**
875
+ * Builds one `ImportNode` per unique schema referenced in the tree, in first-occurrence
876
+ * order. Each ref's target resolves through `resolveRefName`, so collision- or macro-renamed
877
+ * schemas (`targetName`) import the emitted name. Names and paths go through the top-level
878
+ * `name` and `file`, so import entries follow the plugin's conventions, and a per-call
879
+ * `name` override wins over both.
880
+ */
881
+ imports(options) {
882
+ const { node, root, output, group, extname = ".ts", name } = options;
883
+ const resolveName = name ?? ((schemaName) => this.name(schemaName));
884
+ const seen = /* @__PURE__ */ new Set();
885
+ return (0, _kubb_ast.collect)(node, { schema: (schemaNode) => {
886
+ const schemaRef = (0, _kubb_ast.narrowSchema)(schemaNode, "ref");
887
+ if (!schemaRef?.ref) return null;
888
+ const schemaName = (0, _kubb_ast.resolveRefName)(schemaRef);
889
+ if (!schemaName || seen.has(schemaName)) return null;
890
+ seen.add(schemaName);
891
+ return _kubb_ast.ast.factory.createImport({
892
+ name: [resolveName(schemaName)],
893
+ path: this.file({
894
+ name: schemaName,
895
+ extname,
896
+ root,
897
+ output,
898
+ group
899
+ }).path
900
+ });
901
+ } });
902
+ }
903
+ /**
876
904
  * Merges `override` over `base` and returns a new resolver with helpers re-bound. Top-level
877
905
  * keys replace, and a namespace (or `file`) merges per method, so overriding `query.name`
878
906
  * keeps the base `query.keyName`. Used when applying `setResolver` partial overrides. Reads a