@kubb/plugin-react-query
Version:
React Query hooks generator plugin for Kubb, creating type-safe API client hooks from OpenAPI specifications for React applications.
1,229 lines • 58.4 kB
JavaScript
const require_components = require("./components-BHQT9ZLc.cjs");
let node_path = require("node:path");
node_path = require_components.__toESM(node_path);
let node_fs = require("node:fs");
node_fs = require_components.__toESM(node_fs);
let _kubb_plugin_client = require("@kubb/plugin-client");
let _kubb_plugin_ts = require("@kubb/plugin-ts");
let _kubb_plugin_zod = require("@kubb/plugin-zod");
let _kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
let _kubb_react_fabric = require("@kubb/react-fabric");
let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
let _kubb_plugin_client_components = require("@kubb/plugin-client/components");
let _kubb_core_hooks = require("@kubb/core/hooks");
let _kubb_plugin_oas_generators = require("@kubb/plugin-oas/generators");
let _kubb_plugin_oas_hooks = require("@kubb/plugin-oas/hooks");
let remeda = require("remeda");
//#region src/generators/customHookOptionsFileGenerator.tsx
const customHookOptionsFileGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
name: "react-query-custom-hook-options-file",
Operations({ operations, generator, plugin, config }) {
const { options, options: { output }, key: pluginKey } = plugin;
const pluginManager = (0, _kubb_core_hooks.usePluginManager)();
const { getFile } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
if (!options.customOptions) return null;
const override = output.override ?? config.output.override ?? false;
const { importPath, name } = options.customOptions;
const root = node_path.default.resolve(config.root, config.output.path);
const reactQueryImportPath = options.query ? options.query.importPath : "@tanstack/react-query";
const getHookFilePath = (operations) => {
const firstOperation = operations[0];
if (firstOperation != null) return getFile(firstOperation, { prefix: "use" }).path;
return pluginManager.getFile({
name: "index",
extname: ".ts",
pluginKey
}).path;
};
const ensureExtension = (filePath, extname) => {
if (node_path.default.extname(filePath) === "") return filePath + extname;
return filePath;
};
const getExternalFile = (filePath, rootPath) => {
const actualFilePath = ensureExtension(filePath, ".ts");
return {
baseName: node_path.default.basename(actualFilePath),
name: node_path.default.basename(actualFilePath, node_path.default.extname(actualFilePath)),
path: node_path.default.resolve(rootPath, actualFilePath)
};
};
const file = getExternalFile(importPath, node_path.default.dirname(getHookFilePath(operations)));
if (node_fs.default.existsSync(file.path) && !override) return null;
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
baseName: file.baseName,
path: file.path,
children: [
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["QueryClient"],
path: reactQueryImportPath,
isTypeOnly: true
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["useQueryClient"],
path: reactQueryImportPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["HookOptions"],
root: file.path,
path: node_path.default.resolve(root, "./index.ts")
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File.Source, {
name: file.name,
isExportable: true,
isIndexable: true,
children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
name: "getCustomHookOptions",
params: "{ queryClient }: { queryClient: QueryClient }",
returnType: "Partial<HookOptions>",
children: `return {
// TODO: Define custom hook options here
// Example:
// useUpdatePetHook: {
// onSuccess: () => {
// void queryClient.invalidateQueries({ queryKey: ['pet'] })
// }
// }
}`
}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
name,
generics: "T extends keyof HookOptions",
params: "{ hookName, operationId }: { hookName: T, operationId: string }",
returnType: "HookOptions[T]",
export: true,
children: `const queryClient = useQueryClient()
const customOptions = getCustomHookOptions({ queryClient })
return customOptions[hookName] ?? {}`
})]
})
]
});
}
});
//#endregion
//#region src/generators/hookOptionsGenerator.tsx
const hookOptionsGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
name: "react-query-hook-options",
Operations({ operations, plugin, generator }) {
const { options, options: { output }, key: pluginKey } = plugin;
const pluginManager = (0, _kubb_core_hooks.usePluginManager)();
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
const { getName, getFile } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
if (!options.customOptions) return null;
const name = "HookOptions";
const file = pluginManager.getFile({
name,
extname: ".ts",
pluginKey
});
const getOperationOptions = (operation) => {
const operationOptions = generator.getOptions(operation, operation.method);
return {
...options,
...operationOptions
};
};
const isQuery = (operation) => {
const operationOptions = getOperationOptions(operation);
return typeof operationOptions.query === "boolean" ? true : operationOptions.query?.methods.some((method) => operation.method === method);
};
const isMutation = (operation) => {
const operationOptions = getOperationOptions(operation);
return operationOptions.mutation !== false && !isQuery(operation) && (0, remeda.difference)(operationOptions.mutation ? operationOptions.mutation.methods : [], operationOptions.query ? operationOptions.query.methods : []).some((method) => operation.method === method);
};
const isSuspense = (operation) => {
return !!getOperationOptions(operation).suspense;
};
const isInfinite = (operation) => {
const operationOptions = getOperationOptions(operation);
return !!(operationOptions.infinite && typeof operationOptions.infinite === "object" ? operationOptions.infinite : void 0);
};
const getHookName = (operation) => {
return getName(operation, {
type: "function",
prefix: "use"
});
};
const getHookFile = (operation) => {
return getFile(operation, { prefix: "use" });
};
const getQueryHookOptions = (operation) => {
return getName(operation, {
type: "function",
suffix: "QueryOptions"
});
};
const getQueryHookOptionsImport = (operation) => {
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [getQueryHookOptions(operation)],
root: file.path,
path: getHookFile(operation).path
});
};
const getMutationHookOptions = (operation) => {
return getName(operation, {
type: "function",
suffix: "MutationOptions"
});
};
const getMutationHookOptionsImport = (operation) => {
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [getMutationHookOptions(operation)],
root: file.path,
path: getHookFile(operation).path
});
};
const getSuspenseHookName = (operation) => {
return getName(operation, {
type: "function",
prefix: "use",
suffix: "suspense"
});
};
const getSuspenseHookFile = (operation) => {
return getFile(operation, {
prefix: "use",
suffix: "suspense"
});
};
const getSuspenseHookOptions = (operation) => {
return getName(operation, {
type: "function",
suffix: "SuspenseQueryOptions"
});
};
const getSuspenseHookOptionsImport = (operation) => {
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [getSuspenseHookOptions(operation)],
root: file.path,
path: getSuspenseHookFile(operation).path
});
};
const getInfiniteHookName = (operation) => {
return getName(operation, {
type: "function",
prefix: "use",
suffix: "infinite"
});
};
const getInfiniteHookFile = (operation) => {
return getFile(operation, {
prefix: "use",
suffix: "infinite"
});
};
const getInfiniteHookOptions = (operation) => {
return getName(operation, {
type: "function",
suffix: "InfiniteQueryOptions"
});
};
const getInfiniteHookOptionsImport = (operation) => {
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [getInfiniteHookOptions(operation)],
root: file.path,
path: getInfiniteHookFile(operation).path
});
};
const getSuspenseInfiniteHookName = (operation) => {
return getName(operation, {
type: "function",
prefix: "use",
suffix: "suspenseInfinite"
});
};
const getSuspenseInfiniteHookFile = (operation) => {
return getFile(operation, {
prefix: "use",
suffix: "suspenseInfinite"
});
};
const getSuspenseInfiniteHookOptions = (operation) => {
return getName(operation, {
type: "function",
suffix: "SuspenseInfiniteQueryOptions"
});
};
const getSuspenseInfiniteHookOptionsImport = (operation) => {
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [getSuspenseInfiniteHookOptions(operation)],
root: file.path,
path: getSuspenseInfiniteHookFile(operation).path
});
};
const imports = operations.flatMap((operation) => {
if (isQuery(operation)) return [
getQueryHookOptionsImport(operation),
isSuspense(operation) ? getSuspenseHookOptionsImport(operation) : void 0,
isInfinite(operation) ? getInfiniteHookOptionsImport(operation) : void 0,
isSuspense(operation) && isInfinite(operation) ? getSuspenseInfiniteHookOptionsImport(operation) : void 0
].filter(Boolean);
if (isMutation(operation)) return [getMutationHookOptionsImport(operation)];
return [];
}).filter(Boolean);
const hookOptions = operations.reduce((acc, operation) => {
if (isQuery(operation)) {
acc[getHookName(operation)] = `Partial<ReturnType<typeof ${getQueryHookOptions(operation)}>>`;
if (isSuspense(operation)) acc[getSuspenseHookName(operation)] = `Partial<ReturnType<typeof ${getSuspenseHookOptions(operation)}>>`;
if (isInfinite(operation)) acc[getInfiniteHookName(operation)] = `Partial<ReturnType<typeof ${getInfiniteHookOptions(operation)}>>`;
if (isSuspense(operation) && isInfinite(operation)) acc[getSuspenseInfiniteHookName(operation)] = `Partial<ReturnType<typeof ${getSuspenseInfiniteHookOptions(operation)}>>`;
}
if (isMutation(operation)) acc[getHookName(operation)] = `Partial<ReturnType<typeof ${getMutationHookOptions(operation)}>>`;
return acc;
}, {});
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
baseName: file.baseName,
path: file.path,
meta: file.meta,
banner: (0, _kubb_plugin_oas_utils.getBanner)({
oas,
output,
config: pluginManager.config
}),
footer: (0, _kubb_plugin_oas_utils.getFooter)({
oas,
output
}),
children: [imports, /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
name,
isExportable: true,
isIndexable: true,
isTypeOnly: true,
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Type, {
export: true,
name,
children: `{ ${Object.keys(hookOptions).map((key) => `${JSON.stringify(key)}: ${hookOptions[key]}`)} }`
})
})]
});
}
});
//#endregion
//#region src/generators/infiniteQueryGenerator.tsx
const infiniteQueryGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
name: "react-infinite-query",
Operation({ config, operation, generator, plugin }) {
const { options, options: { output } } = plugin;
const pluginManager = (0, _kubb_core_hooks.usePluginManager)();
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
const { getSchemas, getName, getFile } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
const isMutation = (0, remeda.difference)(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
const infiniteOptions = options.infinite && typeof options.infinite === "object" ? options.infinite : void 0;
const importPath = options.query ? options.query.importPath : "@tanstack/react-query";
const query = {
name: getName(operation, {
type: "function",
prefix: "use",
suffix: "infinite"
}),
typeName: getName(operation, { type: "type" }),
file: getFile(operation, {
prefix: "use",
suffix: "infinite"
})
};
const shouldUseClientPlugin = !!pluginManager.getPluginByKey([_kubb_plugin_client.pluginClientName]) && options.client.clientType !== "class";
const client = {
name: shouldUseClientPlugin ? getName(operation, {
type: "function",
pluginKey: [_kubb_plugin_client.pluginClientName]
}) : getName(operation, {
type: "function",
suffix: "infinite"
}),
file: getFile(operation, { pluginKey: [_kubb_plugin_client.pluginClientName] })
};
const queryOptions = { name: getName(operation, {
type: "function",
suffix: "InfiniteQueryOptions"
}) };
const queryKey = {
name: getName(operation, {
type: "const",
suffix: "InfiniteQueryKey"
}),
typeName: getName(operation, {
type: "type",
suffix: "InfiniteQueryKey"
})
};
const type = {
file: getFile(operation, { pluginKey: [_kubb_plugin_ts.pluginTsName] }),
schemas: getSchemas(operation, {
pluginKey: [_kubb_plugin_ts.pluginTsName],
type: "type"
})
};
const zod = {
file: getFile(operation, { pluginKey: [_kubb_plugin_zod.pluginZodName] }),
schemas: getSchemas(operation, {
pluginKey: [_kubb_plugin_zod.pluginZodName],
type: "function"
})
};
if (!isQuery || isMutation || !infiniteOptions) return null;
const normalizeKey = (key) => (key ?? "").replace(/\?$/, "");
const queryParam = infiniteOptions.queryParam;
const cursorParam = infiniteOptions.cursorParam;
const queryParamKeys = type.schemas.queryParams?.keys ?? [];
const responseKeys = [...type.schemas.responses?.flatMap((item) => item.keys ?? []) ?? [], ...type.schemas.response?.keys ?? []];
const hasQueryParam = queryParam ? queryParamKeys.some((key) => normalizeKey(key) === queryParam) : false;
const hasCursorParam = cursorParam ? responseKeys.some((key) => normalizeKey(key) === cursorParam) : true;
if (!hasQueryParam || !hasCursorParam) return null;
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
baseName: query.file.baseName,
path: query.file.path,
meta: query.file.meta,
banner: (0, _kubb_plugin_oas_utils.getBanner)({
oas,
output,
config: pluginManager.config
}),
footer: (0, _kubb_plugin_oas_utils.getFooter)({
oas,
output
}),
children: [
options.parser === "zod" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
root: query.file.path,
path: zod.file.path
}),
options.client.importPath ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: "fetch",
path: options.client.importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
"Client",
"RequestConfig",
"ResponseErrorConfig"
],
path: options.client.importPath,
isTypeOnly: true
}),
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["ResponseConfig"],
path: options.client.importPath,
isTypeOnly: true
})
] }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["fetch"],
root: query.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts")
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
"Client",
"RequestConfig",
"ResponseErrorConfig"
],
root: query.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
isTypeOnly: true
}),
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["ResponseConfig"],
root: query.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
isTypeOnly: true
})
] }),
shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [client.name],
root: query.file.path,
path: client.file.path
}),
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["buildFormData"],
root: query.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/config.ts")
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
type.schemas.request?.name,
type.schemas.response.name,
type.schemas.pathParams?.name,
type.schemas.queryParams?.name,
type.schemas.headerParams?.name,
...type.schemas.statusCodes?.map((item) => item.name) || []
].filter(Boolean),
root: query.file.path,
path: type.file.path,
isTypeOnly: true
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.QueryKey, {
name: queryKey.name,
typeName: queryKey.typeName,
operation,
paramsCasing: options.paramsCasing,
pathParamsType: options.pathParamsType,
typeSchemas: type.schemas,
transformer: options.queryKey
}),
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_plugin_client_components.Client, {
name: client.name,
baseURL: options.client.baseURL,
operation,
typeSchemas: type.schemas,
zodSchemas: zod.schemas,
dataReturnType: options.client.dataReturnType || "data",
paramsCasing: options.client?.paramsCasing || options.paramsCasing,
paramsType: options.paramsType,
pathParamsType: options.pathParamsType,
parser: options.parser
}),
options.customOptions && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [options.customOptions.name],
path: options.customOptions.importPath
}),
infiniteOptions && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["InfiniteData"],
isTypeOnly: true,
path: importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["infiniteQueryOptions"],
path: importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.InfiniteQueryOptions, {
name: queryOptions.name,
clientName: client.name,
queryKeyName: queryKey.name,
typeSchemas: type.schemas,
paramsCasing: options.paramsCasing,
paramsType: options.paramsType,
pathParamsType: options.pathParamsType,
dataReturnType: options.client.dataReturnType || "data",
cursorParam: infiniteOptions.cursorParam,
nextParam: infiniteOptions.nextParam,
previousParam: infiniteOptions.previousParam,
initialPageParam: infiniteOptions.initialPageParam,
queryParam: infiniteOptions.queryParam
})
] }),
infiniteOptions && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["useInfiniteQuery"],
path: importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
"QueryKey",
"QueryClient",
"InfiniteQueryObserverOptions",
"UseInfiniteQueryResult"
],
path: importPath,
isTypeOnly: true
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.InfiniteQuery, {
name: query.name,
queryOptionsName: queryOptions.name,
typeSchemas: type.schemas,
paramsCasing: options.paramsCasing,
paramsType: options.paramsType,
pathParamsType: options.pathParamsType,
operation,
dataReturnType: options.client.dataReturnType || "data",
queryKeyName: queryKey.name,
queryKeyTypeName: queryKey.typeName,
initialPageParam: infiniteOptions.initialPageParam,
queryParam: infiniteOptions.queryParam,
customOptions: options.customOptions
})
] })
]
});
}
});
//#endregion
//#region src/generators/mutationGenerator.tsx
const mutationGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
name: "react-query",
Operation({ config, plugin, operation, generator }) {
const { options, options: { output } } = plugin;
const pluginManager = (0, _kubb_core_hooks.usePluginManager)();
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
const { getSchemas, getName, getFile } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method);
const isMutation = options.mutation !== false && !isQuery && (0, remeda.difference)(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
const importPath = options.mutation ? options.mutation.importPath : "@tanstack/react-query";
const mutation = {
name: getName(operation, {
type: "function",
prefix: "use"
}),
typeName: getName(operation, { type: "type" }),
file: getFile(operation, { prefix: "use" })
};
const type = {
file: getFile(operation, { pluginKey: [_kubb_plugin_ts.pluginTsName] }),
schemas: getSchemas(operation, {
pluginKey: [_kubb_plugin_ts.pluginTsName],
type: "type"
})
};
const zod = {
file: getFile(operation, { pluginKey: [_kubb_plugin_zod.pluginZodName] }),
schemas: getSchemas(operation, {
pluginKey: [_kubb_plugin_zod.pluginZodName],
type: "function"
})
};
const shouldUseClientPlugin = !!pluginManager.getPluginByKey([_kubb_plugin_client.pluginClientName]) && options.client.clientType !== "class";
const client = {
name: shouldUseClientPlugin ? getName(operation, {
type: "function",
pluginKey: [_kubb_plugin_client.pluginClientName]
}) : getName(operation, { type: "function" }),
file: getFile(operation, { pluginKey: [_kubb_plugin_client.pluginClientName] })
};
const mutationOptions = { name: getName(operation, {
type: "function",
suffix: "MutationOptions"
}) };
const mutationKey = {
name: getName(operation, {
type: "const",
suffix: "MutationKey"
}),
typeName: getName(operation, {
type: "type",
suffix: "MutationKey"
})
};
if (!isMutation) return null;
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
baseName: mutation.file.baseName,
path: mutation.file.path,
meta: mutation.file.meta,
banner: (0, _kubb_plugin_oas_utils.getBanner)({
oas,
output,
config: pluginManager.config
}),
footer: (0, _kubb_plugin_oas_utils.getFooter)({
oas,
output
}),
children: [
options.parser === "zod" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
root: mutation.file.path,
path: zod.file.path
}),
options.client.importPath ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: "fetch",
path: options.client.importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
"Client",
"RequestConfig",
"ResponseErrorConfig"
],
path: options.client.importPath,
isTypeOnly: true
}),
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["ResponseConfig"],
path: options.client.importPath,
isTypeOnly: true
})
] }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["fetch"],
root: mutation.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts")
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
"Client",
"RequestConfig",
"ResponseErrorConfig"
],
root: mutation.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
isTypeOnly: true
}),
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["ResponseConfig"],
root: mutation.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
isTypeOnly: true
})
] }),
shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [client.name],
root: mutation.file.path,
path: client.file.path
}),
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["buildFormData"],
root: mutation.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/config.ts")
}),
options.customOptions && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [options.customOptions.name],
path: options.customOptions.importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
type.schemas.request?.name,
type.schemas.response.name,
type.schemas.pathParams?.name,
type.schemas.queryParams?.name,
type.schemas.headerParams?.name,
...type.schemas.statusCodes?.map((item) => item.name) || []
].filter(Boolean),
root: mutation.file.path,
path: type.file.path,
isTypeOnly: true
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.MutationKey, {
name: mutationKey.name,
typeName: mutationKey.typeName,
operation,
pathParamsType: options.pathParamsType,
typeSchemas: type.schemas,
paramsCasing: options.paramsCasing,
transformer: options.mutationKey
}),
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_plugin_client_components.Client, {
name: client.name,
baseURL: options.client.baseURL,
operation,
typeSchemas: type.schemas,
zodSchemas: zod.schemas,
dataReturnType: options.client.dataReturnType || "data",
paramsCasing: options.client?.paramsCasing || options.paramsCasing,
paramsType: options.paramsType,
pathParamsType: options.pathParamsType,
parser: options.parser
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["mutationOptions"],
path: importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.MutationOptions, {
name: mutationOptions.name,
clientName: client.name,
mutationKeyName: mutationKey.name,
typeSchemas: type.schemas,
paramsCasing: options.paramsCasing,
paramsType: options.paramsType,
pathParamsType: options.pathParamsType,
dataReturnType: options.client.dataReturnType || "data"
}),
options.mutation && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["useMutation"],
path: importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
"UseMutationOptions",
"UseMutationResult",
"QueryClient"
],
path: importPath,
isTypeOnly: true
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.Mutation, {
name: mutation.name,
mutationOptionsName: mutationOptions.name,
typeName: mutation.typeName,
typeSchemas: type.schemas,
operation,
dataReturnType: options.client.dataReturnType || "data",
paramsCasing: options.paramsCasing,
pathParamsType: options.pathParamsType,
mutationKeyName: mutationKey.name,
customOptions: options.customOptions
})
] })
]
});
}
});
//#endregion
//#region src/generators/queryGenerator.tsx
const queryGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
name: "react-query",
Operation({ config, plugin, operation, generator }) {
const { options, options: { output } } = plugin;
const pluginManager = (0, _kubb_core_hooks.usePluginManager)();
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
const { getSchemas, getName, getFile } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
const isMutation = (0, remeda.difference)(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
const importPath = options.query ? options.query.importPath : "@tanstack/react-query";
const query = {
name: getName(operation, {
type: "function",
prefix: "use"
}),
typeName: getName(operation, { type: "type" }),
file: getFile(operation, { prefix: "use" })
};
const shouldUseClientPlugin = !!pluginManager.getPluginByKey([_kubb_plugin_client.pluginClientName]) && options.client.clientType !== "class";
const client = {
name: shouldUseClientPlugin ? getName(operation, {
type: "function",
pluginKey: [_kubb_plugin_client.pluginClientName]
}) : getName(operation, { type: "function" }),
file: getFile(operation, { pluginKey: [_kubb_plugin_client.pluginClientName] })
};
const queryOptions = { name: getName(operation, {
type: "function",
suffix: "QueryOptions"
}) };
const queryKey = {
name: getName(operation, {
type: "const",
suffix: "QueryKey"
}),
typeName: getName(operation, {
type: "type",
suffix: "QueryKey"
})
};
const type = {
file: getFile(operation, { pluginKey: [_kubb_plugin_ts.pluginTsName] }),
schemas: getSchemas(operation, {
pluginKey: [_kubb_plugin_ts.pluginTsName],
type: "type"
})
};
const zod = {
file: getFile(operation, { pluginKey: [_kubb_plugin_zod.pluginZodName] }),
schemas: getSchemas(operation, {
pluginKey: [_kubb_plugin_zod.pluginZodName],
type: "function"
})
};
if (!isQuery || isMutation) return null;
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
baseName: query.file.baseName,
path: query.file.path,
meta: query.file.meta,
banner: (0, _kubb_plugin_oas_utils.getBanner)({
oas,
output,
config: pluginManager.config
}),
footer: (0, _kubb_plugin_oas_utils.getFooter)({
oas,
output
}),
children: [
options.parser === "zod" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
root: query.file.path,
path: zod.file.path
}),
options.client.importPath ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: "fetch",
path: options.client.importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
"Client",
"RequestConfig",
"ResponseErrorConfig"
],
path: options.client.importPath,
isTypeOnly: true
}),
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["ResponseConfig"],
path: options.client.importPath,
isTypeOnly: true
})
] }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["fetch"],
root: query.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts")
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
"Client",
"RequestConfig",
"ResponseErrorConfig"
],
root: query.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
isTypeOnly: true
}),
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["ResponseConfig"],
root: query.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
isTypeOnly: true
})
] }),
shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [client.name],
root: query.file.path,
path: client.file.path
}),
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["buildFormData"],
root: query.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/config.ts")
}),
options.customOptions && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [options.customOptions.name],
path: options.customOptions.importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
type.schemas.request?.name,
type.schemas.response.name,
type.schemas.pathParams?.name,
type.schemas.queryParams?.name,
type.schemas.headerParams?.name,
...type.schemas.statusCodes?.map((item) => item.name) || []
].filter(Boolean),
root: query.file.path,
path: type.file.path,
isTypeOnly: true
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.QueryKey, {
name: queryKey.name,
typeName: queryKey.typeName,
operation,
pathParamsType: options.pathParamsType,
typeSchemas: type.schemas,
paramsCasing: options.paramsCasing,
transformer: options.queryKey
}),
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_plugin_client_components.Client, {
name: client.name,
baseURL: options.client.baseURL,
operation,
typeSchemas: type.schemas,
zodSchemas: zod.schemas,
dataReturnType: options.client.dataReturnType || "data",
paramsType: options.paramsType,
paramsCasing: options.client?.paramsCasing || options.paramsCasing,
pathParamsType: options.pathParamsType,
parser: options.parser
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["queryOptions"],
path: importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.QueryOptions, {
name: queryOptions.name,
clientName: client.name,
queryKeyName: queryKey.name,
typeSchemas: type.schemas,
paramsCasing: options.paramsCasing,
paramsType: options.paramsType,
pathParamsType: options.pathParamsType,
dataReturnType: options.client.dataReturnType || "data"
}),
options.query && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["useQuery"],
path: importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
"QueryKey",
"QueryClient",
"QueryObserverOptions",
"UseQueryResult",
"QueryClient"
],
path: importPath,
isTypeOnly: true
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.Query, {
name: query.name,
queryOptionsName: queryOptions.name,
typeSchemas: type.schemas,
paramsCasing: options.paramsCasing,
paramsType: options.paramsType,
pathParamsType: options.pathParamsType,
operation,
dataReturnType: options.client.dataReturnType || "data",
queryKeyName: queryKey.name,
queryKeyTypeName: queryKey.typeName,
customOptions: options.customOptions
})
] })
]
});
}
});
//#endregion
//#region src/generators/suspenseInfiniteQueryGenerator.tsx
const suspenseInfiniteQueryGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
name: "react-suspense-infinite-query",
Operation({ config, operation, generator, plugin }) {
const { options, options: { output } } = plugin;
const pluginManager = (0, _kubb_core_hooks.usePluginManager)();
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
const { getSchemas, getName, getFile } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
const isMutation = (0, remeda.difference)(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
const isSuspense = !!options.suspense;
const infiniteOptions = options.infinite && typeof options.infinite === "object" ? options.infinite : void 0;
const importPath = options.query ? options.query.importPath : "@tanstack/react-query";
const query = {
name: getName(operation, {
type: "function",
prefix: "use",
suffix: "suspenseInfinite"
}),
typeName: getName(operation, { type: "type" }),
file: getFile(operation, {
prefix: "use",
suffix: "suspenseInfinite"
})
};
const shouldUseClientPlugin = !!pluginManager.getPluginByKey([_kubb_plugin_client.pluginClientName]) && options.client.clientType !== "class";
const client = {
name: shouldUseClientPlugin ? getName(operation, {
type: "function",
pluginKey: [_kubb_plugin_client.pluginClientName]
}) : getName(operation, {
type: "function",
suffix: "suspenseInfinite"
}),
file: getFile(operation, { pluginKey: [_kubb_plugin_client.pluginClientName] })
};
const queryOptions = { name: getName(operation, {
type: "function",
suffix: "SuspenseInfiniteQueryOptions"
}) };
const queryKey = {
name: getName(operation, {
type: "const",
suffix: "SuspenseInfiniteQueryKey"
}),
typeName: getName(operation, {
type: "type",
suffix: "SuspenseInfiniteQueryKey"
})
};
const type = {
file: getFile(operation, { pluginKey: [_kubb_plugin_ts.pluginTsName] }),
schemas: getSchemas(operation, {
pluginKey: [_kubb_plugin_ts.pluginTsName],
type: "type"
})
};
const zod = {
file: getFile(operation, { pluginKey: [_kubb_plugin_zod.pluginZodName] }),
schemas: getSchemas(operation, {
pluginKey: [_kubb_plugin_zod.pluginZodName],
type: "function"
})
};
if (!isQuery || isMutation || !isSuspense || !infiniteOptions) return null;
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
baseName: query.file.baseName,
path: query.file.path,
meta: query.file.meta,
banner: (0, _kubb_plugin_oas_utils.getBanner)({
oas,
output,
config: pluginManager.config
}),
footer: (0, _kubb_plugin_oas_utils.getFooter)({
oas,
output
}),
children: [
options.parser === "zod" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
root: query.file.path,
path: zod.file.path
}),
options.client.importPath ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: "fetch",
path: options.client.importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
"Client",
"RequestConfig",
"ResponseErrorConfig"
],
path: options.client.importPath,
isTypeOnly: true
}),
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["ResponseConfig"],
path: options.client.importPath,
isTypeOnly: true
})
] }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["fetch"],
root: query.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts")
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
"Client",
"RequestConfig",
"ResponseErrorConfig"
],
root: query.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
isTypeOnly: true
}),
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["ResponseConfig"],
root: query.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
isTypeOnly: true
})
] }),
shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [client.name],
root: query.file.path,
path: client.file.path
}),
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["buildFormData"],
root: query.file.path,
path: node_path.default.resolve(config.root, config.output.path, ".kubb/config.ts")
}),
options.customOptions && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [options.customOptions.name],
path: options.customOptions.importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
type.schemas.request?.name,
type.schemas.response.name,
type.schemas.pathParams?.name,
type.schemas.queryParams?.name,
type.schemas.headerParams?.name,
...type.schemas.statusCodes?.map((item) => item.name) || []
].filter(Boolean),
root: query.file.path,
path: type.file.path,
isTypeOnly: true
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.QueryKey, {
name: queryKey.name,
typeName: queryKey.typeName,
operation,
paramsCasing: options.paramsCasing,
pathParamsType: options.pathParamsType,
typeSchemas: type.schemas,
transformer: options.queryKey
}),
!shouldUseClientPlugin && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_plugin_client_components.Client, {
name: client.name,
baseURL: options.client.baseURL,
operation,
typeSchemas: type.schemas,
zodSchemas: zod.schemas,
dataReturnType: options.client.dataReturnType || "data",
paramsCasing: options.client?.paramsCasing || options.paramsCasing,
paramsType: options.paramsType,
pathParamsType: options.pathParamsType,
parser: options.parser
}),
infiniteOptions && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["InfiniteData"],
isTypeOnly: true,
path: importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["infiniteQueryOptions"],
path: importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.SuspenseInfiniteQueryOptions, {
name: queryOptions.name,
clientName: client.name,
queryKeyName: queryKey.name,
typeSchemas: type.schemas,
paramsCasing: options.paramsCasing,
paramsType: options.paramsType,
pathParamsType: options.pathParamsType,
dataReturnType: options.client.dataReturnType || "data",
cursorParam: infiniteOptions.cursorParam,
nextParam: infiniteOptions.nextParam,
previousParam: infiniteOptions.previousParam,
initialPageParam: infiniteOptions.initialPageParam,
queryParam: infiniteOptions.queryParam
})
] }),
infiniteOptions && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: ["useSuspenseInfiniteQuery"],
path: importPath
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
name: [
"QueryKey",
"QueryClient",
"UseSuspenseInfiniteQueryOptions",
"UseSuspenseInfiniteQueryResult"
],
path: importPath,
isTypeOnly: true
}),
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.SuspenseInfiniteQuery, {
name: query.name,
queryOptionsName: queryOptions.name,
typeSchemas: type.schemas,
paramsCasing: options.paramsCasing,
paramsType: options.paramsType,
pathParamsType: options.pathParamsType,
operation,
dataReturnType: options.client.dataReturnType || "data",
queryKeyName: queryKey.name,
queryKeyTypeName: queryKey.typeName,
customOptions: options.customOptions,
initialPageParam: infiniteOptions.initialPageParam,
queryParam: infiniteOptions.queryParam
})
] })
]
});
}
});
//#endregion
//#region src/generators/suspenseQueryGenerator.tsx
const suspenseQueryGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
name: "react-suspense-query",
Operation({ config, operation, generator, plugin }) {
const { options, options: { output } } = plugin;
const pluginManager = (0, _kubb_core_hooks.usePluginManager)();
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
const { getSchemas, getName, getFile } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
const isMutation = (0, remeda.difference)(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
const isSuspense = !!options.suspense;
const importPath = options.query ? options.query.importPath : "@tanstack/react-query";
const query = {
name: getName(operation, {
type: "function",
prefix: "use",
suffix: "suspense"
}),
typeName: getName(operation, { type: "type" }),
file: getFile(operation, {
prefix: "use",
suffix: "suspense"
})
};
const shouldUseClientPlugin = !!pluginManager.getPluginByKey([_kubb_plugin_client.plu