@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.d.ts CHANGED
@@ -307,7 +307,7 @@ declare const pluginVueQueryName = "plugin-vue-query";
307
307
  * import { pluginVueQuery } from '@kubb/plugin-vue-query'
308
308
  *
309
309
  * export default defineConfig({
310
- * input: { path: './petStore.yaml' },
310
+ * input: './petStore.yaml',
311
311
  * output: { path: './src/gen' },
312
312
  * plugins: [
313
313
  * pluginTs(),
package/dist/index.js CHANGED
@@ -131,6 +131,22 @@ const reservedWords = /* @__PURE__ */ new Set([
131
131
  */
132
132
  function isValidVarName(name) {
133
133
  if (!name || reservedWords.has(name)) return false;
134
+ return isIdentifier(name);
135
+ }
136
+ /**
137
+ * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
138
+ *
139
+ * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
140
+ * even though they are not valid variable names, so use this (not {@link isValidVarName}) when
141
+ * deciding whether an object key needs quoting.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * isIdentifier('name') // true
146
+ * isIdentifier('x-total')// false
147
+ * ```
148
+ */
149
+ function isIdentifier(name) {
134
150
  return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
135
151
  }
136
152
  //#endregion
@@ -326,8 +342,11 @@ function getOperationLink(node, link) {
326
342
  if (link === "urlPath") return node.path ? `{@link ${Url.toPath(node.path)}}` : null;
327
343
  return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
328
344
  }
329
- function getContentTypeInfo(node) {
330
- const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
345
+ /**
346
+ * Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
347
+ * are present and the union, default, and form-data flags the client uses to pick one.
348
+ */
349
+ function buildContentTypeInfo(contentTypes) {
331
350
  const isMultipleContentTypes = contentTypes.length > 1;
332
351
  return {
333
352
  contentTypes,
@@ -337,20 +356,15 @@ function getContentTypeInfo(node) {
337
356
  hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
338
357
  };
339
358
  }
359
+ function getContentTypeInfo(node) {
360
+ return buildContentTypeInfo(node.requestBody?.content?.map((e) => e.contentType) ?? []);
361
+ }
340
362
  /**
341
363
  * The request-body counterpart for the primary success response: the content types it documents and
342
364
  * whether several are present, so the client can let a caller pick which one to accept.
343
365
  */
344
366
  function getResponseContentTypeInfo(node) {
345
- const contentTypes = getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? [];
346
- const isMultipleContentTypes = contentTypes.length > 1;
347
- return {
348
- contentTypes,
349
- isMultipleContentTypes,
350
- contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
351
- defaultContentType: contentTypes[0] ?? "application/json",
352
- hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
353
- };
367
+ return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
354
368
  }
355
369
  function buildRequestConfigType(node) {
356
370
  const request = getContentTypeInfo(node);
@@ -1065,8 +1079,6 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName }) {
1065
1079
  resolveMutationRequestType(node, tsResolver),
1066
1080
  "TContext"
1067
1081
  ].join(", ");
1068
- const mutationKeyParamsNode = createFunctionParameters({ params: [] });
1069
- const mutationKeyParamsCall = callPrinter$1.print(mutationKeyParamsNode) ?? "";
1070
1082
  const paramsNode = buildMutationParamsNode(node, { resolver: tsResolver });
1071
1083
  const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
1072
1084
  return /* @__PURE__ */ jsx(File.Source, {
@@ -1082,10 +1094,10 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName }) {
1082
1094
  children: `
1083
1095
  const { mutation = {}, client: config = {} } = options ?? {}
1084
1096
  const { client: queryClient, ...mutationOptions } = mutation;
1085
- const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}(${mutationKeyParamsCall})
1097
+ const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}()
1086
1098
 
1087
1099
  return useMutation<${generics}>({
1088
- mutationFn: async(${hasMutationParams ? argBindingStr : ""}) => {
1100
+ mutationFn: async(${argBindingStr}) => {
1089
1101
  ${mutationFnBody}
1090
1102
  },
1091
1103
  mutationKey,
@@ -1194,9 +1206,7 @@ const infiniteQueryGenerator = defineGenerator({
1194
1206
  if (!isQuery || isMutation || !infiniteOptions) return null;
1195
1207
  const normalizeKey = (key) => key.replace(/\?$/, "");
1196
1208
  const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
1197
- const hasQueryParam = infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false;
1198
- const hasCursorParam = !infiniteOptions.cursorParam || true;
1199
- if (!hasQueryParam || !hasCursorParam) return null;
1209
+ if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
1200
1210
  const importPath = query ? query.importPath : "@tanstack/vue-query";
1201
1211
  const contractOp = resolveClientOperation({
1202
1212
  clientPlugin: { pluginName: client.pluginName },
@@ -1707,7 +1717,7 @@ const pluginVueQueryName = "plugin-vue-query";
1707
1717
  * import { pluginVueQuery } from '@kubb/plugin-vue-query'
1708
1718
  *
1709
1719
  * export default defineConfig({
1710
- * input: { path: './petStore.yaml' },
1720
+ * input: './petStore.yaml',
1711
1721
  * output: { path: './src/gen' },
1712
1722
  * plugins: [
1713
1723
  * pluginTs(),
@@ -1727,7 +1737,7 @@ const pluginVueQuery = definePlugin((options) => {
1727
1737
  queryGenerator,
1728
1738
  infiniteQueryGenerator,
1729
1739
  mutationGenerator
1730
- ].filter((generator) => Boolean(generator));
1740
+ ];
1731
1741
  const groupConfig = createGroupConfig(group);
1732
1742
  return {
1733
1743
  name: pluginVueQueryName,