@kubb/plugin-swr 5.0.0-beta.98 → 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.js +33 -95
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -161,33 +161,17 @@ function isIdentifier(name) {
|
|
|
161
161
|
}
|
|
162
162
|
//#endregion
|
|
163
163
|
//#region ../../internals/utils/src/url.ts
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
function
|
|
169
|
-
|
|
170
|
-
for (const match of path.matchAll(/\{([^}]+)\}/g)) {
|
|
171
|
-
const param = transformParam(match[1], casing);
|
|
172
|
-
const key = replacer ? replacer(param) : param;
|
|
173
|
-
params[key] = key;
|
|
174
|
-
}
|
|
175
|
-
return Object.keys(params).length > 0 ? params : null;
|
|
164
|
+
/**
|
|
165
|
+
* Keeps the OpenAPI parameter name as-is when it is already a valid JS identifier, and
|
|
166
|
+
* camelCases it only enough to become one otherwise (for example a hyphenated path segment).
|
|
167
|
+
*/
|
|
168
|
+
function transformParam(raw) {
|
|
169
|
+
return isValidVarName(raw) ? raw : camelCase(raw);
|
|
176
170
|
}
|
|
177
171
|
/**
|
|
178
|
-
* Helpers for OpenAPI/Swagger paths
|
|
172
|
+
* Helpers for OpenAPI/Swagger paths.
|
|
179
173
|
*/
|
|
180
174
|
var Url = class Url {
|
|
181
|
-
/**
|
|
182
|
-
* Reports whether `url` is a parseable absolute URL. Delegates to the native `URL.canParse`.
|
|
183
|
-
*
|
|
184
|
-
* @example
|
|
185
|
-
* Url.canParse('https://petstore.swagger.io/v2') // true
|
|
186
|
-
* Url.canParse('/pet/{petId}') // false
|
|
187
|
-
*/
|
|
188
|
-
static canParse(url, base) {
|
|
189
|
-
return URL.canParse(url, base);
|
|
190
|
-
}
|
|
191
175
|
/**
|
|
192
176
|
* Converts an OpenAPI/Swagger path to Express-style colon syntax.
|
|
193
177
|
*
|
|
@@ -203,15 +187,14 @@ var Url = class Url {
|
|
|
203
187
|
* key.
|
|
204
188
|
*
|
|
205
189
|
* @example
|
|
206
|
-
* Url.
|
|
190
|
+
* Url.toSafeTemplate('/user/{monetary-account-id}') // '/user/{monetaryAccountId}'
|
|
207
191
|
*/
|
|
208
|
-
static
|
|
209
|
-
return path.replace(/\{([^}]+)\}/g, (_, name) => `{${transformParam(name
|
|
192
|
+
static toSafeTemplate(path) {
|
|
193
|
+
return path.replace(/\{([^}]+)\}/g, (_, name) => `{${transformParam(name)}}`);
|
|
210
194
|
}
|
|
211
195
|
/**
|
|
212
196
|
* Converts an OpenAPI/Swagger path to a TypeScript template literal string.
|
|
213
|
-
* `prefix` is prepended inside the literal, `replacer` transforms each parameter name
|
|
214
|
-
* and `casing` controls parameter identifier casing.
|
|
197
|
+
* `prefix` is prepended inside the literal, and `replacer` transforms each parameter name.
|
|
215
198
|
*
|
|
216
199
|
* @example
|
|
217
200
|
* Url.toTemplateString('/pet/{petId}') // '`/pet/${petId}`'
|
|
@@ -219,10 +202,10 @@ var Url = class Url {
|
|
|
219
202
|
* @example
|
|
220
203
|
* Url.toTemplateString('/pet/{petId}', { prefix: 'https://api' }) // '`https://api/pet/${petId}`'
|
|
221
204
|
*/
|
|
222
|
-
static toTemplateString(path, { prefix, replacer
|
|
205
|
+
static toTemplateString(path, { prefix, replacer } = {}) {
|
|
223
206
|
const result = path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
224
207
|
if (i % 2 === 0) return part;
|
|
225
|
-
const param = transformParam(part
|
|
208
|
+
const param = transformParam(part);
|
|
226
209
|
return `\${${replacer ? replacer(param) : param}}`;
|
|
227
210
|
}).join("");
|
|
228
211
|
return `\`${prefix ?? ""}${result}\``;
|
|
@@ -230,8 +213,8 @@ var Url = class Url {
|
|
|
230
213
|
/**
|
|
231
214
|
* Converts an OpenAPI/Swagger path to a template literal that reads each parameter off the
|
|
232
215
|
* grouped `path` request option, e.g. `/pet/{petId}` becomes `` `/pet/${path.petId}` ``. Parameter
|
|
233
|
-
* names
|
|
234
|
-
*
|
|
216
|
+
* names match the generated `path` type, and `prefix` is prepended inside the literal. Shared by
|
|
217
|
+
* the client and cypress generators that pass a grouped `path` object.
|
|
235
218
|
*
|
|
236
219
|
* @example
|
|
237
220
|
* Url.toGroupedTemplateString('/pet/{petId}') // '`/pet/${path.petId}`'
|
|
@@ -239,72 +222,25 @@ var Url = class Url {
|
|
|
239
222
|
static toGroupedTemplateString(path, { prefix } = {}) {
|
|
240
223
|
return Url.toTemplateString(path, {
|
|
241
224
|
prefix,
|
|
242
|
-
casing: "camelcase",
|
|
243
225
|
replacer: (name) => `path.${name}`
|
|
244
226
|
});
|
|
245
227
|
}
|
|
246
|
-
/**
|
|
247
|
-
* Returns the path and its extracted params as a structured `URLObject`, or as a stringified
|
|
248
|
-
* expression when `stringify` is set.
|
|
249
|
-
*
|
|
250
|
-
* @example
|
|
251
|
-
* Url.toObject('/pet/{petId}')
|
|
252
|
-
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
253
|
-
*/
|
|
254
|
-
static toObject(path, { type = "path", replacer, stringify, casing } = {}) {
|
|
255
|
-
const object = {
|
|
256
|
-
url: type === "path" ? Url.toPath(path) : Url.toTemplateString(path, {
|
|
257
|
-
replacer,
|
|
258
|
-
casing
|
|
259
|
-
}),
|
|
260
|
-
params: toParamsObject(path, {
|
|
261
|
-
replacer,
|
|
262
|
-
casing
|
|
263
|
-
})
|
|
264
|
-
};
|
|
265
|
-
if (stringify) {
|
|
266
|
-
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
267
|
-
if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
268
|
-
return `{ url: '${object.url}' }`;
|
|
269
|
-
}
|
|
270
|
-
return object;
|
|
271
|
-
}
|
|
272
228
|
};
|
|
273
229
|
//#endregion
|
|
274
230
|
//#region ../../internals/shared/src/params.ts
|
|
275
|
-
const caseParamsCache = /* @__PURE__ */ new WeakMap();
|
|
276
231
|
/**
|
|
277
|
-
*
|
|
232
|
+
* Drops parameters that share the same name, keeping the first.
|
|
278
233
|
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
234
|
+
* A malformed spec can declare the same parameter name twice within one `in` location. Both would
|
|
235
|
+
* resolve to the same output property, so emitting both would yield an object type with a duplicate
|
|
236
|
+
* member, which TypeScript rejects. This is a defensive guard against that case, not a casing guard:
|
|
237
|
+
* parameter names flow through unchanged, so no two distinct names ever collide here anymore.
|
|
282
238
|
*/
|
|
283
|
-
function
|
|
284
|
-
if (!casing) return params;
|
|
285
|
-
const cached = caseParamsCache.get(params);
|
|
286
|
-
if (cached) return cached;
|
|
287
|
-
const result = params.map((param) => ({
|
|
288
|
-
...param,
|
|
289
|
-
name: camelCase(param.name)
|
|
290
|
-
}));
|
|
291
|
-
caseParamsCache.set(params, result);
|
|
292
|
-
return result;
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Drops parameters that collapse to the same property identity once camelCased, keeping the first.
|
|
296
|
-
*
|
|
297
|
-
* Some specs declare the same parameter twice under different casings (for example AWS S3 lists both
|
|
298
|
-
* `max-uploads` and `MaxUploads`). Both resolve to one output property, so emitting both would yield
|
|
299
|
-
* an object type with a duplicate member, which TypeScript rejects. De-duplicate by the camelCased
|
|
300
|
-
* identity so the resulting group is collision-free regardless of the names each caller carries.
|
|
301
|
-
*/
|
|
302
|
-
function dedupeByCasedName(params) {
|
|
239
|
+
function dedupeParams(params) {
|
|
303
240
|
const seen = /* @__PURE__ */ new Set();
|
|
304
241
|
return params.filter((param) => {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
seen.add(key);
|
|
242
|
+
if (seen.has(param.name)) return false;
|
|
243
|
+
seen.add(param.name);
|
|
308
244
|
return true;
|
|
309
245
|
});
|
|
310
246
|
}
|
|
@@ -423,13 +359,15 @@ function buildOperationComments(node, options = {}) {
|
|
|
423
359
|
if (!splitLines) return filteredComments;
|
|
424
360
|
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
425
361
|
}
|
|
426
|
-
function getOperationParameters(node
|
|
427
|
-
const params = caseParams(node.parameters, options.paramsCasing === "original" ? void 0 : "camelcase");
|
|
362
|
+
function getOperationParameters(node) {
|
|
428
363
|
return {
|
|
429
|
-
path:
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
364
|
+
path: dedupeParams(node.parameters.filter((param) => param.in === "path").map((param) => isValidVarName(param.name) ? param : {
|
|
365
|
+
...param,
|
|
366
|
+
name: camelCase(param.name)
|
|
367
|
+
})),
|
|
368
|
+
query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
|
|
369
|
+
header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
|
|
370
|
+
cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
|
|
433
371
|
};
|
|
434
372
|
}
|
|
435
373
|
function getStatusCodeNumber(statusCode) {
|
|
@@ -461,7 +399,7 @@ function resolveStatusCodeNames(node, resolver) {
|
|
|
461
399
|
}
|
|
462
400
|
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
463
401
|
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
464
|
-
const cacheKey = `${node.operationId}\0${options.
|
|
402
|
+
const cacheKey = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
|
|
465
403
|
let byResolver = typeNamesByResolver.get(resolver);
|
|
466
404
|
if (byResolver) {
|
|
467
405
|
const cached = byResolver.get(cacheKey);
|
|
@@ -470,7 +408,7 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
470
408
|
byResolver = /* @__PURE__ */ new Map();
|
|
471
409
|
typeNamesByResolver.set(resolver, byResolver);
|
|
472
410
|
}
|
|
473
|
-
const { path, query, header } = getOperationParameters(node
|
|
411
|
+
const { path, query, header } = getOperationParameters(node);
|
|
474
412
|
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
475
413
|
const exclude = new Set(options.exclude ?? []);
|
|
476
414
|
const paramNames = options.includeParams === false ? [] : [
|