@kubb/plugin-mcp 5.0.0-beta.95 → 5.0.0-beta.99
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 +33 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -12
- package/dist/index.js +32 -94
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
|
2
2
|
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
3
3
|
import { KubbReactNode } from "kubb/jsx";
|
|
4
4
|
import { ResolverTs } from "@kubb/plugin-ts";
|
|
5
|
+
import "@kubb/plugin-zod";
|
|
5
6
|
//#region src/components/McpHandler.d.ts
|
|
6
7
|
type Props$1 = {
|
|
7
8
|
/**
|
|
@@ -21,12 +22,7 @@ type Props$1 = {
|
|
|
21
22
|
*/
|
|
22
23
|
resolver: ResolverTs;
|
|
23
24
|
};
|
|
24
|
-
declare function McpHandler({
|
|
25
|
-
name,
|
|
26
|
-
clientName,
|
|
27
|
-
node,
|
|
28
|
-
resolver
|
|
29
|
-
}: Props$1): KubbReactNode;
|
|
25
|
+
declare function McpHandler({ name, clientName, node, resolver }: Props$1): KubbReactNode;
|
|
30
26
|
//#endregion
|
|
31
27
|
//#region src/utils.d.ts
|
|
32
28
|
type ZodParam = {
|
|
@@ -78,12 +74,7 @@ type Props = {
|
|
|
78
74
|
node: ast.OperationNode;
|
|
79
75
|
}>;
|
|
80
76
|
};
|
|
81
|
-
declare function Server({
|
|
82
|
-
name,
|
|
83
|
-
serverName,
|
|
84
|
-
serverVersion,
|
|
85
|
-
operations
|
|
86
|
-
}: Props): KubbReactNode;
|
|
77
|
+
declare function Server({ name, serverName, serverVersion, operations }: Props): KubbReactNode;
|
|
87
78
|
//#endregion
|
|
88
79
|
//#region ../../internals/client/src/resolveClient.d.ts
|
|
89
80
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
+
import path from "node:path";
|
|
2
3
|
import { Resolver, ast, createResolver, defineGenerator, definePlugin } from "kubb/kit";
|
|
3
4
|
import { Const, File, Function, jsxRenderer } from "kubb/jsx";
|
|
4
5
|
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
5
6
|
import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
6
|
-
import path from "node:path";
|
|
7
7
|
import { pluginZodName } from "@kubb/plugin-zod";
|
|
8
8
|
//#region ../../internals/utils/src/casing.ts
|
|
9
9
|
/**
|
|
@@ -152,33 +152,17 @@ function isIdentifier(name) {
|
|
|
152
152
|
}
|
|
153
153
|
//#endregion
|
|
154
154
|
//#region ../../internals/utils/src/url.ts
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
function
|
|
160
|
-
|
|
161
|
-
for (const match of path.matchAll(/\{([^}]+)\}/g)) {
|
|
162
|
-
const param = transformParam(match[1], casing);
|
|
163
|
-
const key = replacer ? replacer(param) : param;
|
|
164
|
-
params[key] = key;
|
|
165
|
-
}
|
|
166
|
-
return Object.keys(params).length > 0 ? params : null;
|
|
155
|
+
/**
|
|
156
|
+
* Keeps the OpenAPI parameter name as-is when it is already a valid JS identifier, and
|
|
157
|
+
* camelCases it only enough to become one otherwise (for example a hyphenated path segment).
|
|
158
|
+
*/
|
|
159
|
+
function transformParam(raw) {
|
|
160
|
+
return isValidVarName(raw) ? raw : camelCase(raw);
|
|
167
161
|
}
|
|
168
162
|
/**
|
|
169
|
-
* Helpers for OpenAPI/Swagger paths
|
|
163
|
+
* Helpers for OpenAPI/Swagger paths.
|
|
170
164
|
*/
|
|
171
165
|
var Url = class Url {
|
|
172
|
-
/**
|
|
173
|
-
* Reports whether `url` is a parseable absolute URL. Delegates to the native `URL.canParse`.
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* Url.canParse('https://petstore.swagger.io/v2') // true
|
|
177
|
-
* Url.canParse('/pet/{petId}') // false
|
|
178
|
-
*/
|
|
179
|
-
static canParse(url, base) {
|
|
180
|
-
return URL.canParse(url, base);
|
|
181
|
-
}
|
|
182
166
|
/**
|
|
183
167
|
* Converts an OpenAPI/Swagger path to Express-style colon syntax.
|
|
184
168
|
*
|
|
@@ -194,15 +178,14 @@ var Url = class Url {
|
|
|
194
178
|
* key.
|
|
195
179
|
*
|
|
196
180
|
* @example
|
|
197
|
-
* Url.
|
|
181
|
+
* Url.toSafeTemplate('/user/{monetary-account-id}') // '/user/{monetaryAccountId}'
|
|
198
182
|
*/
|
|
199
|
-
static
|
|
200
|
-
return path.replace(/\{([^}]+)\}/g, (_, name) => `{${transformParam(name
|
|
183
|
+
static toSafeTemplate(path) {
|
|
184
|
+
return path.replace(/\{([^}]+)\}/g, (_, name) => `{${transformParam(name)}}`);
|
|
201
185
|
}
|
|
202
186
|
/**
|
|
203
187
|
* Converts an OpenAPI/Swagger path to a TypeScript template literal string.
|
|
204
|
-
* `prefix` is prepended inside the literal, `replacer` transforms each parameter name
|
|
205
|
-
* and `casing` controls parameter identifier casing.
|
|
188
|
+
* `prefix` is prepended inside the literal, and `replacer` transforms each parameter name.
|
|
206
189
|
*
|
|
207
190
|
* @example
|
|
208
191
|
* Url.toTemplateString('/pet/{petId}') // '`/pet/${petId}`'
|
|
@@ -210,10 +193,10 @@ var Url = class Url {
|
|
|
210
193
|
* @example
|
|
211
194
|
* Url.toTemplateString('/pet/{petId}', { prefix: 'https://api' }) // '`https://api/pet/${petId}`'
|
|
212
195
|
*/
|
|
213
|
-
static toTemplateString(path, { prefix, replacer
|
|
196
|
+
static toTemplateString(path, { prefix, replacer } = {}) {
|
|
214
197
|
const result = path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
215
198
|
if (i % 2 === 0) return part;
|
|
216
|
-
const param = transformParam(part
|
|
199
|
+
const param = transformParam(part);
|
|
217
200
|
return `\${${replacer ? replacer(param) : param}}`;
|
|
218
201
|
}).join("");
|
|
219
202
|
return `\`${prefix ?? ""}${result}\``;
|
|
@@ -221,8 +204,8 @@ var Url = class Url {
|
|
|
221
204
|
/**
|
|
222
205
|
* Converts an OpenAPI/Swagger path to a template literal that reads each parameter off the
|
|
223
206
|
* grouped `path` request option, e.g. `/pet/{petId}` becomes `` `/pet/${path.petId}` ``. Parameter
|
|
224
|
-
* names
|
|
225
|
-
*
|
|
207
|
+
* names match the generated `path` type, and `prefix` is prepended inside the literal. Shared by
|
|
208
|
+
* the client and cypress generators that pass a grouped `path` object.
|
|
226
209
|
*
|
|
227
210
|
* @example
|
|
228
211
|
* Url.toGroupedTemplateString('/pet/{petId}') // '`/pet/${path.petId}`'
|
|
@@ -230,72 +213,25 @@ var Url = class Url {
|
|
|
230
213
|
static toGroupedTemplateString(path, { prefix } = {}) {
|
|
231
214
|
return Url.toTemplateString(path, {
|
|
232
215
|
prefix,
|
|
233
|
-
casing: "camelcase",
|
|
234
216
|
replacer: (name) => `path.${name}`
|
|
235
217
|
});
|
|
236
218
|
}
|
|
237
|
-
/**
|
|
238
|
-
* Returns the path and its extracted params as a structured `URLObject`, or as a stringified
|
|
239
|
-
* expression when `stringify` is set.
|
|
240
|
-
*
|
|
241
|
-
* @example
|
|
242
|
-
* Url.toObject('/pet/{petId}')
|
|
243
|
-
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
244
|
-
*/
|
|
245
|
-
static toObject(path, { type = "path", replacer, stringify, casing } = {}) {
|
|
246
|
-
const object = {
|
|
247
|
-
url: type === "path" ? Url.toPath(path) : Url.toTemplateString(path, {
|
|
248
|
-
replacer,
|
|
249
|
-
casing
|
|
250
|
-
}),
|
|
251
|
-
params: toParamsObject(path, {
|
|
252
|
-
replacer,
|
|
253
|
-
casing
|
|
254
|
-
})
|
|
255
|
-
};
|
|
256
|
-
if (stringify) {
|
|
257
|
-
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
258
|
-
if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
259
|
-
return `{ url: '${object.url}' }`;
|
|
260
|
-
}
|
|
261
|
-
return object;
|
|
262
|
-
}
|
|
263
219
|
};
|
|
264
220
|
//#endregion
|
|
265
221
|
//#region ../../internals/shared/src/params.ts
|
|
266
|
-
const caseParamsCache = /* @__PURE__ */ new WeakMap();
|
|
267
|
-
/**
|
|
268
|
-
* Applies camelCase to parameter names and returns a new array without mutating the input.
|
|
269
|
-
*
|
|
270
|
-
* Run it before handing parameters to schema builders so output property keys get the right casing
|
|
271
|
-
* while `OperationNode.parameters` stays intact for other consumers. When `casing` is unset, the
|
|
272
|
-
* original array is returned unchanged. Results are cached per input array.
|
|
273
|
-
*/
|
|
274
|
-
function caseParams(params, casing) {
|
|
275
|
-
if (!casing) return params;
|
|
276
|
-
const cached = caseParamsCache.get(params);
|
|
277
|
-
if (cached) return cached;
|
|
278
|
-
const result = params.map((param) => ({
|
|
279
|
-
...param,
|
|
280
|
-
name: camelCase(param.name)
|
|
281
|
-
}));
|
|
282
|
-
caseParamsCache.set(params, result);
|
|
283
|
-
return result;
|
|
284
|
-
}
|
|
285
222
|
/**
|
|
286
|
-
* Drops parameters that
|
|
223
|
+
* Drops parameters that share the same name, keeping the first.
|
|
287
224
|
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
225
|
+
* A malformed spec can declare the same parameter name twice within one `in` location. Both would
|
|
226
|
+
* resolve to the same output property, so emitting both would yield an object type with a duplicate
|
|
227
|
+
* member, which TypeScript rejects. This is a defensive guard against that case, not a casing guard:
|
|
228
|
+
* parameter names flow through unchanged, so no two distinct names ever collide here anymore.
|
|
292
229
|
*/
|
|
293
|
-
function
|
|
230
|
+
function dedupeParams(params) {
|
|
294
231
|
const seen = /* @__PURE__ */ new Set();
|
|
295
232
|
return params.filter((param) => {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
seen.add(key);
|
|
233
|
+
if (seen.has(param.name)) return false;
|
|
234
|
+
seen.add(param.name);
|
|
299
235
|
return true;
|
|
300
236
|
});
|
|
301
237
|
}
|
|
@@ -425,13 +361,15 @@ function buildOperationComments(node, options = {}) {
|
|
|
425
361
|
if (!splitLines) return filteredComments;
|
|
426
362
|
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
427
363
|
}
|
|
428
|
-
function getOperationParameters(node
|
|
429
|
-
const params = caseParams(node.parameters, options.paramsCasing === "original" ? void 0 : "camelcase");
|
|
364
|
+
function getOperationParameters(node) {
|
|
430
365
|
return {
|
|
431
|
-
path:
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
366
|
+
path: dedupeParams(node.parameters.filter((param) => param.in === "path").map((param) => isValidVarName(param.name) ? param : {
|
|
367
|
+
...param,
|
|
368
|
+
name: camelCase(param.name)
|
|
369
|
+
})),
|
|
370
|
+
query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
|
|
371
|
+
header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
|
|
372
|
+
cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
|
|
435
373
|
};
|
|
436
374
|
}
|
|
437
375
|
function getStatusCodeNumber(statusCode) {
|