@kubb/plugin-faker 5.0.0-beta.103 → 5.0.0-beta.104

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
@@ -651,6 +651,45 @@ function dedupeParams(params) {
651
651
  //#endregion
652
652
  //#region ../../internals/shared/src/operation.ts
653
653
  /**
654
+ * Builds the `ResolverFileParams` every operation generator passes to
655
+ * `resolver.file`: a file named `name`, tagged by the operation's first
656
+ * tag (or `'default'`), at the operation's path. Centralizes the entry object
657
+ * that was repeated at dozens of call sites across the client and query plugins.
658
+ *
659
+ * @example
660
+ * ```ts
661
+ * resolver.file(operationFileEntry(node, node.operationId), { root, output, group })
662
+ * ```
663
+ */
664
+ function operationFileEntry(node, name, extname = ".ts") {
665
+ return {
666
+ name,
667
+ extname,
668
+ tag: node.tags[0] ?? "default",
669
+ path: node.path
670
+ };
671
+ }
672
+ /**
673
+ * Resolves a dependency plugin's generated file for `node.operationId`, cached in `cache` (the
674
+ * current node's `ctx.cache`) under the resolver's own plugin name. Several dependents reading the
675
+ * same dependency for the same operation in one pass (a query plugin's several hook generators, the
676
+ * MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.
677
+ *
678
+ * @example Cache `plugin-ts`'s file for the current operation
679
+ * ```ts
680
+ * const fileTs = resolveDependencyOperationFile({ cache: ctx.cache, node, resolver: tsResolver, root, output })
681
+ * ```
682
+ */
683
+ function resolveDependencyOperationFile(options) {
684
+ const { cache, node, resolver, root, output, group } = options;
685
+ return cache.getOrSet(`${resolver.pluginName}:operationFile`, () => resolver.file({
686
+ ...operationFileEntry(node, node.operationId),
687
+ root,
688
+ output,
689
+ group: group ?? void 0
690
+ }));
691
+ }
692
+ /**
654
693
  * Maps a content type to the PascalCase suffix used to name per-content-type variants
655
694
  * (e.g. `application/json` → `Json`, `application/xml` → `Xml`, `multipart/form-data` → `FormData`).
656
695
  */
@@ -698,13 +737,24 @@ function resolveContentTypeVariants(entries, baseName) {
698
737
  };
699
738
  });
700
739
  }
740
+ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
741
+ /**
742
+ * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
743
+ * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
744
+ * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
745
+ * same parameters once per plugin.
746
+ */
701
747
  function getOperationParameters(node) {
702
- return {
748
+ const cached = operationParameterGroupsByNode.get(node);
749
+ if (cached) return cached;
750
+ const groups = {
703
751
  path: dedupeParams(node.parameters.filter((param) => param.in === "path")),
704
752
  query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
705
753
  header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
706
754
  cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
707
755
  };
756
+ operationParameterGroupsByNode.set(node, groups);
757
+ return groups;
708
758
  }
709
759
  //#endregion
710
760
  //#region ../../internals/shared/src/resolver.ts
@@ -1257,14 +1307,13 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
1257
1307
  output,
1258
1308
  group: group ?? void 0
1259
1309
  }),
1260
- typeFile: tsResolver.file({
1261
- name: node.operationId,
1262
- extname: ".ts",
1263
- tag: node.tags[0] ?? "default",
1264
- path: node.path,
1310
+ typeFile: resolveDependencyOperationFile({
1311
+ cache: ctx.cache,
1312
+ node,
1313
+ resolver: tsResolver,
1265
1314
  root,
1266
1315
  output: pluginTs.options?.output ?? output,
1267
- group: pluginTs.options?.group ?? void 0
1316
+ group: pluginTs.options?.group
1268
1317
  })
1269
1318
  };
1270
1319
  function resolveMockImports(schema) {