@kubb/plugin-fetch 5.0.0-beta.86 → 5.0.0-beta.94

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
@@ -171,7 +171,7 @@ const reservedWords = /* @__PURE__ */ new Set([
171
171
  */
172
172
  function isValidVarName(name) {
173
173
  if (!name || reservedWords.has(name)) return false;
174
- return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
174
+ return isIdentifier(name);
175
175
  }
176
176
  /**
177
177
  * Returns `name` when it's a syntactically valid JavaScript variable name,
@@ -193,6 +193,22 @@ function ensureValidVarName(name) {
193
193
  if (!name || isValidVarName(name)) return name;
194
194
  return `_${name}`;
195
195
  }
196
+ /**
197
+ * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
198
+ *
199
+ * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
200
+ * even though they are not valid variable names, so use this (not {@link isValidVarName}) when
201
+ * deciding whether an object key needs quoting.
202
+ *
203
+ * @example
204
+ * ```ts
205
+ * isIdentifier('name') // true
206
+ * isIdentifier('x-total')// false
207
+ * ```
208
+ */
209
+ function isIdentifier(name) {
210
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
211
+ }
196
212
  //#endregion
197
213
  //#region ../../internals/utils/src/codegen.ts
198
214
  /**
@@ -414,8 +430,11 @@ function getOperationLink(node, link) {
414
430
  if (link === "urlPath") return node.path ? `{@link ${Url.toPath(node.path)}}` : null;
415
431
  return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
416
432
  }
417
- function getContentTypeInfo(node) {
418
- const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
433
+ /**
434
+ * Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
435
+ * are present and the union, default, and form-data flags the client uses to pick one.
436
+ */
437
+ function buildContentTypeInfo(contentTypes) {
419
438
  const isMultipleContentTypes = contentTypes.length > 1;
420
439
  return {
421
440
  contentTypes,
@@ -425,20 +444,15 @@ function getContentTypeInfo(node) {
425
444
  hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
426
445
  };
427
446
  }
447
+ function getContentTypeInfo(node) {
448
+ return buildContentTypeInfo(node.requestBody?.content?.map((e) => e.contentType) ?? []);
449
+ }
428
450
  /**
429
451
  * The request-body counterpart for the primary success response: the content types it documents and
430
452
  * whether several are present, so the client can let a caller pick which one to accept.
431
453
  */
432
454
  function getResponseContentTypeInfo(node) {
433
- const contentTypes = getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? [];
434
- const isMultipleContentTypes = contentTypes.length > 1;
435
- return {
436
- contentTypes,
437
- isMultipleContentTypes,
438
- contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
439
- defaultContentType: contentTypes[0] ?? "application/json",
440
- hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
441
- };
455
+ return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
442
456
  }
443
457
  /**
444
458
  * Reads the single base content type of an operation's primary success response, lowercased and
@@ -1482,7 +1496,7 @@ const pluginFetchName = "plugin-fetch";
1482
1496
  * import { pluginFetch } from '@kubb/plugin-fetch'
1483
1497
  *
1484
1498
  * export default defineConfig({
1485
- * input: { path: './petStore.yaml' },
1499
+ * input: './petStore.yaml',
1486
1500
  * output: { path: './src/gen' },
1487
1501
  * plugins: [
1488
1502
  * pluginTs(),