@kubb/plugin-vue-query 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
@@ -157,6 +157,22 @@ const reservedWords = /* @__PURE__ */ new Set([
157
157
  */
158
158
  function isValidVarName(name) {
159
159
  if (!name || reservedWords.has(name)) return false;
160
+ return isIdentifier(name);
161
+ }
162
+ /**
163
+ * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
164
+ *
165
+ * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
166
+ * even though they are not valid variable names, so use this (not {@link isValidVarName}) when
167
+ * deciding whether an object key needs quoting.
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * isIdentifier('name') // true
172
+ * isIdentifier('x-total')// false
173
+ * ```
174
+ */
175
+ function isIdentifier(name) {
160
176
  return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
161
177
  }
162
178
  //#endregion
@@ -352,8 +368,11 @@ function getOperationLink(node, link) {
352
368
  if (link === "urlPath") return node.path ? `{@link ${Url.toPath(node.path)}}` : null;
353
369
  return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
354
370
  }
355
- function getContentTypeInfo(node) {
356
- const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
371
+ /**
372
+ * Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
373
+ * are present and the union, default, and form-data flags the client uses to pick one.
374
+ */
375
+ function buildContentTypeInfo(contentTypes) {
357
376
  const isMultipleContentTypes = contentTypes.length > 1;
358
377
  return {
359
378
  contentTypes,
@@ -363,20 +382,15 @@ function getContentTypeInfo(node) {
363
382
  hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
364
383
  };
365
384
  }
385
+ function getContentTypeInfo(node) {
386
+ return buildContentTypeInfo(node.requestBody?.content?.map((e) => e.contentType) ?? []);
387
+ }
366
388
  /**
367
389
  * The request-body counterpart for the primary success response: the content types it documents and
368
390
  * whether several are present, so the client can let a caller pick which one to accept.
369
391
  */
370
392
  function getResponseContentTypeInfo(node) {
371
- const contentTypes = getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? [];
372
- const isMultipleContentTypes = contentTypes.length > 1;
373
- return {
374
- contentTypes,
375
- isMultipleContentTypes,
376
- contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
377
- defaultContentType: contentTypes[0] ?? "application/json",
378
- hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
379
- };
393
+ return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
380
394
  }
381
395
  function buildRequestConfigType(node) {
382
396
  const request = getContentTypeInfo(node);
@@ -1091,8 +1105,6 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName }) {
1091
1105
  resolveMutationRequestType(node, tsResolver),
1092
1106
  "TContext"
1093
1107
  ].join(", ");
1094
- const mutationKeyParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: [] });
1095
- const mutationKeyParamsCall = callPrinter$1.print(mutationKeyParamsNode) ?? "";
1096
1108
  const paramsNode = buildMutationParamsNode(node, { resolver: tsResolver });
1097
1109
  const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
1098
1110
  return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
@@ -1108,10 +1120,10 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName }) {
1108
1120
  children: `
1109
1121
  const { mutation = {}, client: config = {} } = options ?? {}
1110
1122
  const { client: queryClient, ...mutationOptions } = mutation;
1111
- const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}(${mutationKeyParamsCall})
1123
+ const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}()
1112
1124
 
1113
1125
  return useMutation<${generics}>({
1114
- mutationFn: async(${hasMutationParams ? argBindingStr : ""}) => {
1126
+ mutationFn: async(${argBindingStr}) => {
1115
1127
  ${mutationFnBody}
1116
1128
  },
1117
1129
  mutationKey,
@@ -1220,9 +1232,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
1220
1232
  if (!isQuery || isMutation || !infiniteOptions) return null;
1221
1233
  const normalizeKey = (key) => key.replace(/\?$/, "");
1222
1234
  const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
1223
- const hasQueryParam = infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false;
1224
- const hasCursorParam = !infiniteOptions.cursorParam || true;
1225
- if (!hasQueryParam || !hasCursorParam) return null;
1235
+ if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
1226
1236
  const importPath = query ? query.importPath : "@tanstack/vue-query";
1227
1237
  const contractOp = resolveClientOperation({
1228
1238
  clientPlugin: { pluginName: client.pluginName },
@@ -1733,7 +1743,7 @@ const pluginVueQueryName = "plugin-vue-query";
1733
1743
  * import { pluginVueQuery } from '@kubb/plugin-vue-query'
1734
1744
  *
1735
1745
  * export default defineConfig({
1736
- * input: { path: './petStore.yaml' },
1746
+ * input: './petStore.yaml',
1737
1747
  * output: { path: './src/gen' },
1738
1748
  * plugins: [
1739
1749
  * pluginTs(),
@@ -1753,7 +1763,7 @@ const pluginVueQuery = (0, kubb_kit.definePlugin)((options) => {
1753
1763
  queryGenerator,
1754
1764
  infiniteQueryGenerator,
1755
1765
  mutationGenerator
1756
- ].filter((generator) => Boolean(generator));
1766
+ ];
1757
1767
  const groupConfig = createGroupConfig(group);
1758
1768
  return {
1759
1769
  name: pluginVueQueryName,