@kubb/plugin-fetch 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.js CHANGED
@@ -44,6 +44,26 @@ function operationFileEntry(node, name, extname = ".ts") {
44
44
  path: node.path
45
45
  };
46
46
  }
47
+ /**
48
+ * Resolves a dependency plugin's generated file for `node.operationId`, cached in `cache` (the
49
+ * current node's `ctx.cache`) under the resolver's own plugin name. Several dependents reading the
50
+ * same dependency for the same operation in one pass (a query plugin's several hook generators, the
51
+ * MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.
52
+ *
53
+ * @example Cache `plugin-ts`'s file for the current operation
54
+ * ```ts
55
+ * const fileTs = resolveDependencyOperationFile({ cache: ctx.cache, node, resolver: tsResolver, root, output })
56
+ * ```
57
+ */
58
+ function resolveDependencyOperationFile(options) {
59
+ const { cache, node, resolver, root, output, group } = options;
60
+ return cache.getOrSet(`${resolver.pluginName}:operationFile`, () => resolver.file({
61
+ ...operationFileEntry(node, node.operationId),
62
+ root,
63
+ output,
64
+ group: group ?? void 0
65
+ }));
66
+ }
47
67
  function getOperationLink(node, link) {
48
68
  if (!link) return null;
49
69
  if (typeof link === "function") return link(node) ?? null;
@@ -155,13 +175,24 @@ function buildOperationComments(node, options = {}) {
155
175
  if (!splitLines) return filteredComments;
156
176
  return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
157
177
  }
178
+ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
179
+ /**
180
+ * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
181
+ * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
182
+ * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
183
+ * same parameters once per plugin.
184
+ */
158
185
  function getOperationParameters(node) {
159
- return {
186
+ const cached = operationParameterGroupsByNode.get(node);
187
+ if (cached) return cached;
188
+ const groups = {
160
189
  path: dedupeParams(node.parameters.filter((param) => param.in === "path")),
161
190
  query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
162
191
  header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
163
192
  cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
164
193
  };
194
+ operationParameterGroupsByNode.set(node, groups);
195
+ return groups;
165
196
  }
166
197
  function getStatusCodeNumber(statusCode) {
167
198
  const code = Number(statusCode);
@@ -873,11 +904,13 @@ function createClientGenerator(name) {
873
904
  output,
874
905
  group: group ?? void 0
875
906
  }),
876
- fileTs: tsResolver.file({
877
- ...operationFileEntry(node, node.operationId),
907
+ fileTs: resolveDependencyOperationFile({
908
+ cache: ctx.cache,
909
+ node,
910
+ resolver: tsResolver,
878
911
  root,
879
912
  output: pluginTs.options?.output ?? output,
880
- group: pluginTs.options?.group ?? void 0
913
+ group: pluginTs.options?.group
881
914
  }),
882
915
  fileZod: zodResolver && pluginZod?.options ? zodResolver.file({
883
916
  ...operationFileEntry(node, node.operationId),