@kubb/plugin-fetch 5.0.0-beta.100 → 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
@@ -70,6 +70,26 @@ function operationFileEntry(node, name, extname = ".ts") {
70
70
  path: node.path
71
71
  };
72
72
  }
73
+ /**
74
+ * Resolves a dependency plugin's generated file for `node.operationId`, cached in `cache` (the
75
+ * current node's `ctx.cache`) under the resolver's own plugin name. Several dependents reading the
76
+ * same dependency for the same operation in one pass (a query plugin's several hook generators, the
77
+ * MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.
78
+ *
79
+ * @example Cache `plugin-ts`'s file for the current operation
80
+ * ```ts
81
+ * const fileTs = resolveDependencyOperationFile({ cache: ctx.cache, node, resolver: tsResolver, root, output })
82
+ * ```
83
+ */
84
+ function resolveDependencyOperationFile(options) {
85
+ const { cache, node, resolver, root, output, group } = options;
86
+ return cache.getOrSet(`${resolver.pluginName}:operationFile`, () => resolver.file({
87
+ ...operationFileEntry(node, node.operationId),
88
+ root,
89
+ output,
90
+ group: group ?? void 0
91
+ }));
92
+ }
73
93
  function getOperationLink(node, link) {
74
94
  if (!link) return null;
75
95
  if (typeof link === "function") return link(node) ?? null;
@@ -181,13 +201,24 @@ function buildOperationComments(node, options = {}) {
181
201
  if (!splitLines) return filteredComments;
182
202
  return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
183
203
  }
204
+ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
205
+ /**
206
+ * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
207
+ * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
208
+ * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
209
+ * same parameters once per plugin.
210
+ */
184
211
  function getOperationParameters(node) {
185
- return {
212
+ const cached = operationParameterGroupsByNode.get(node);
213
+ if (cached) return cached;
214
+ const groups = {
186
215
  path: dedupeParams(node.parameters.filter((param) => param.in === "path")),
187
216
  query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
188
217
  header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
189
218
  cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
190
219
  };
220
+ operationParameterGroupsByNode.set(node, groups);
221
+ return groups;
191
222
  }
192
223
  function getStatusCodeNumber(statusCode) {
193
224
  const code = Number(statusCode);
@@ -899,11 +930,13 @@ function createClientGenerator(name) {
899
930
  output,
900
931
  group: group ?? void 0
901
932
  }),
902
- fileTs: tsResolver.file({
903
- ...operationFileEntry(node, node.operationId),
933
+ fileTs: resolveDependencyOperationFile({
934
+ cache: ctx.cache,
935
+ node,
936
+ resolver: tsResolver,
904
937
  root,
905
938
  output: pluginTs.options?.output ?? output,
906
- group: pluginTs.options?.group ?? void 0
939
+ group: pluginTs.options?.group
907
940
  }),
908
941
  fileZod: zodResolver && pluginZod?.options ? zodResolver.file({
909
942
  ...operationFileEntry(node, node.operationId),