@kubb/plugin-swr 4.9.1 → 4.9.3
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/{components-BkOGXzS-.cjs → components-Djw0ll1l.cjs} +116 -16
- package/dist/components-Djw0ll1l.cjs.map +1 -0
- package/dist/{components-BWaOPuUc.js → components-bS6nIkbY.js} +115 -15
- package/dist/components-bS6nIkbY.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.cts +8 -2
- package/dist/components.d.ts +8 -2
- package/dist/components.js +1 -1
- package/dist/{generators-B-l1M57U.cjs → generators-DM1zpqft.cjs} +6 -4
- package/dist/generators-DM1zpqft.cjs.map +1 -0
- package/dist/{generators-Cqn7fJTZ.js → generators-DWKtejUq.js} +6 -4
- package/dist/generators-DWKtejUq.js.map +1 -0
- package/dist/generators.cjs +2 -2
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +2 -2
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/{types-CZ5nqQF8.d.cts → types-BhMJy6gt.d.ts} +10 -3
- package/dist/{types-CzR1-kCr.d.ts → types-DV16H9Nj.d.cts} +10 -3
- package/package.json +7 -7
- package/src/components/Mutation.tsx +155 -17
- package/src/generators/__snapshots__/updatePetByIdParamsToTrigger.ts +67 -0
- package/src/generators/mutationGenerator.tsx +2 -0
- package/src/plugin.ts +8 -5
- package/src/types.ts +8 -1
- package/dist/components-BWaOPuUc.js.map +0 -1
- package/dist/components-BkOGXzS-.cjs.map +0 -1
- package/dist/generators-B-l1M57U.cjs.map +0 -1
- package/dist/generators-Cqn7fJTZ.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as MutationKey, i as Mutation, n as QueryOptions, r as QueryKey, t as Query } from "./components-
|
|
1
|
+
import { a as MutationKey, i as Mutation, n as QueryOptions, r as QueryKey, t as Query } from "./components-bS6nIkbY.js";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { pluginClientName } from "@kubb/plugin-client";
|
|
4
4
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
@@ -20,7 +20,8 @@ const mutationGenerator = createReactGenerator({
|
|
|
20
20
|
const pluginManager = usePluginManager();
|
|
21
21
|
const oas = useOas();
|
|
22
22
|
const { getSchemas, getName, getFile } = useOperationManager(generator);
|
|
23
|
-
const
|
|
23
|
+
const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method);
|
|
24
|
+
const isMutation = options.mutation !== false && !isQuery && difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
|
|
24
25
|
const importPath = options.mutation ? options.mutation.importPath : "swr";
|
|
25
26
|
const mutation = {
|
|
26
27
|
name: getName(operation, {
|
|
@@ -180,7 +181,8 @@ const mutationGenerator = createReactGenerator({
|
|
|
180
181
|
paramsCasing: options.paramsCasing,
|
|
181
182
|
pathParamsType: options.pathParamsType,
|
|
182
183
|
mutationKeyName: mutationKey.name,
|
|
183
|
-
mutationKeyTypeName: mutationKey.typeName
|
|
184
|
+
mutationKeyTypeName: mutationKey.typeName,
|
|
185
|
+
paramsToTrigger: options.mutation.paramsToTrigger
|
|
184
186
|
})
|
|
185
187
|
]
|
|
186
188
|
});
|
|
@@ -379,4 +381,4 @@ const queryGenerator = createReactGenerator({
|
|
|
379
381
|
|
|
380
382
|
//#endregion
|
|
381
383
|
export { mutationGenerator as n, queryGenerator as t };
|
|
382
|
-
//# sourceMappingURL=generators-
|
|
384
|
+
//# sourceMappingURL=generators-DWKtejUq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-DWKtejUq.js","names":[],"sources":["../src/generators/mutationGenerator.tsx","../src/generators/queryGenerator.tsx"],"sourcesContent":["import path from 'node:path'\nimport { usePluginManager } from '@kubb/core/hooks'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File } from '@kubb/react-fabric'\nimport { difference } from 'remeda'\nimport { Mutation, MutationKey } from '../components'\nimport type { PluginSwr } from '../types'\n\nexport const mutationGenerator = createReactGenerator<PluginSwr>({\n name: 'swr-mutation',\n Operation({ config, operation, generator, plugin }) {\n const {\n options,\n options: { output },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager(generator)\n\n const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method)\n const isMutation =\n options.mutation !== false &&\n !isQuery &&\n difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method)\n\n const importPath = options.mutation ? options.mutation.importPath : 'swr'\n\n const mutation = {\n name: getName(operation, { type: 'function', prefix: 'use' }),\n typeName: getName(operation, { type: 'type' }),\n file: getFile(operation, { prefix: 'use' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n //todo remove type?\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n }\n\n const hasClientPlugin = !!pluginManager.getPluginByKey([pluginClientName])\n // Class-based clients are not compatible with query hooks, so we generate inline clients\n const shouldUseClientPlugin = hasClientPlugin && options.client.clientType !== 'class'\n const client = {\n name: shouldUseClientPlugin\n ? getName(operation, {\n type: 'function',\n pluginKey: [pluginClientName],\n })\n : getName(operation, {\n type: 'function',\n }),\n file: getFile(operation, { pluginKey: [pluginClientName] }),\n }\n\n const mutationKey = {\n name: getName(operation, { type: 'const', suffix: 'MutationKey' }),\n typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),\n }\n\n if (!isMutation) {\n return null\n }\n\n return (\n <File\n baseName={mutation.file.baseName}\n path={mutation.file.path}\n meta={mutation.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {options.parser === 'zod' && (\n <File.Import name={[zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean)} root={mutation.file.path} path={zod.file.path} />\n )}\n {options.client.importPath ? (\n <>\n <File.Import name={'fetch'} path={options.client.importPath} />\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />\n {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}\n </>\n ) : (\n <>\n <File.Import name={['fetch']} root={mutation.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} />\n <File.Import\n name={['RequestConfig', 'ResponseErrorConfig']}\n root={mutation.file.path}\n path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')}\n isTypeOnly\n />\n {options.client.dataReturnType === 'full' && (\n <File.Import\n name={['ResponseConfig']}\n root={mutation.file.path}\n path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')}\n isTypeOnly\n />\n )}\n </>\n )}\n <File.Import name=\"useSWRMutation\" path={importPath} />\n <File.Import name={['SWRMutationConfiguration', 'SWRMutationResponse']} path={importPath} isTypeOnly />\n {shouldUseClientPlugin && <File.Import name={[client.name]} root={mutation.file.path} path={client.file.path} />}\n {!shouldUseClientPlugin && (\n <File.Import name={['buildFormData']} root={mutation.file.path} path={path.resolve(config.root, config.output.path, '.kubb/config.ts')} />\n )}\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={mutation.file.path}\n path={type.file.path}\n isTypeOnly\n />\n\n <MutationKey\n name={mutationKey.name}\n typeName={mutationKey.typeName}\n operation={operation}\n pathParamsType={options.pathParamsType}\n typeSchemas={type.schemas}\n paramsCasing={options.paramsCasing}\n transformer={options.mutationKey}\n />\n\n {!shouldUseClientPlugin && (\n <Client\n name={client.name}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={zod.schemas}\n dataReturnType={options.client.dataReturnType || 'data'}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n parser={options.parser}\n />\n )}\n {options.mutation && (\n <Mutation\n name={mutation.name}\n clientName={client.name}\n typeName={mutation.typeName}\n typeSchemas={type.schemas}\n operation={operation}\n dataReturnType={options.client.dataReturnType || 'data'}\n paramsType={options.paramsType}\n paramsCasing={options.paramsCasing}\n pathParamsType={options.pathParamsType}\n mutationKeyName={mutationKey.name}\n mutationKeyTypeName={mutationKey.typeName}\n paramsToTrigger={options.mutation.paramsToTrigger}\n />\n )}\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { usePluginManager } from '@kubb/core/hooks'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File } from '@kubb/react-fabric'\nimport { difference } from 'remeda'\nimport { Query, QueryKey, QueryOptions } from '../components'\nimport type { PluginSwr } from '../types'\n\nexport const queryGenerator = createReactGenerator<PluginSwr>({\n name: 'swr-query',\n Operation({ config, operation, generator, plugin }) {\n const {\n options,\n options: { output },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager(generator)\n\n const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)\n const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some(\n (method) => operation.method === method,\n )\n const importPath = options.query ? options.query.importPath : 'swr/mutation'\n\n const query = {\n name: getName(operation, { type: 'function', prefix: 'use' }),\n typeName: getName(operation, { type: 'type' }),\n file: getFile(operation, { prefix: 'use' }),\n }\n\n const hasClientPlugin = !!pluginManager.getPluginByKey([pluginClientName])\n // Class-based clients are not compatible with query hooks, so we generate inline clients\n const shouldUseClientPlugin = hasClientPlugin && options.client.clientType !== 'class'\n const client = {\n name: shouldUseClientPlugin\n ? getName(operation, {\n type: 'function',\n pluginKey: [pluginClientName],\n })\n : getName(operation, {\n type: 'function',\n }),\n file: getFile(operation, { pluginKey: [pluginClientName] }),\n }\n\n const queryOptions = {\n name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),\n }\n const queryKey = {\n name: getName(operation, { type: 'const', suffix: 'QueryKey' }),\n typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n //todo remove type?\n schemas: getSchemas(operation, {\n pluginKey: [pluginTsName],\n type: 'type',\n }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, {\n pluginKey: [pluginZodName],\n type: 'function',\n }),\n }\n\n if (!isQuery || isMutation) {\n return null\n }\n\n return (\n <File\n baseName={query.file.baseName}\n path={query.file.path}\n meta={query.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {options.parser === 'zod' && (\n <File.Import name={[zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean)} root={query.file.path} path={zod.file.path} />\n )}\n {options.client.importPath ? (\n <>\n <File.Import name={'fetch'} path={options.client.importPath} />\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />\n {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}\n </>\n ) : (\n <>\n <File.Import name={['fetch']} root={query.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} />\n <File.Import\n name={['RequestConfig', 'ResponseErrorConfig']}\n root={query.file.path}\n path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')}\n isTypeOnly\n />\n {options.client.dataReturnType === 'full' && (\n <File.Import name={['ResponseConfig']} root={query.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} isTypeOnly />\n )}\n </>\n )}\n {shouldUseClientPlugin && <File.Import name={[client.name]} root={query.file.path} path={client.file.path} />}\n {!shouldUseClientPlugin && (\n <File.Import name={['buildFormData']} root={query.file.path} path={path.resolve(config.root, config.output.path, '.kubb/config.ts')} />\n )}\n\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={query.file.path}\n path={type.file.path}\n isTypeOnly\n />\n <QueryKey\n name={queryKey.name}\n typeName={queryKey.typeName}\n operation={operation}\n pathParamsType={options.pathParamsType}\n typeSchemas={type.schemas}\n paramsCasing={options.paramsCasing}\n transformer={options.queryKey}\n />\n {!shouldUseClientPlugin && (\n <Client\n name={client.name}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={zod.schemas}\n dataReturnType={options.client.dataReturnType || 'data'}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n parser={options.parser}\n />\n )}\n <QueryOptions\n name={queryOptions.name}\n clientName={client.name}\n typeSchemas={type.schemas}\n paramsType={options.paramsType}\n paramsCasing={options.paramsCasing}\n pathParamsType={options.pathParamsType}\n />\n {options.query && (\n <>\n <File.Import name=\"useSWR\" path={importPath} />\n <File.Import name={['SWRResponse']} path={importPath} isTypeOnly />\n <Query\n name={query.name}\n queryOptionsName={queryOptions.name}\n typeSchemas={type.schemas}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n operation={operation}\n dataReturnType={options.client.dataReturnType || 'data'}\n queryKeyName={queryKey.name}\n paramsCasing={options.paramsCasing}\n queryKeyTypeName={queryKey.typeName}\n />\n </>\n )}\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAa,oBAAoB,qBAAgC;CAC/D,MAAM;CACN,UAAU,EAAE,QAAQ,WAAW,WAAW,UAAU;EAClD,MAAM,EACJ,SACA,SAAS,EAAE,aACT;EACJ,MAAM,gBAAgB,kBAAkB;EAExC,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,YAAY,SAAS,YAAY,oBAAoB,UAAU;EAEvE,MAAM,UAAU,CAAC,CAAC,QAAQ,SAAS,QAAQ,OAAO,QAAQ,MAAM,WAAW,UAAU,WAAW,OAAO;EACvG,MAAM,aACJ,QAAQ,aAAa,SACrB,CAAC,WACD,WAAW,QAAQ,WAAW,QAAQ,SAAS,UAAU,EAAE,EAAE,QAAQ,QAAQ,QAAQ,MAAM,UAAU,EAAE,CAAC,CAAC,MAAM,WAAW,UAAU,WAAW,OAAO;EAExJ,MAAM,aAAa,QAAQ,WAAW,QAAQ,SAAS,aAAa;EAEpE,MAAM,WAAW;GACf,MAAM,QAAQ,WAAW;IAAE,MAAM;IAAY,QAAQ;IAAO,CAAC;GAC7D,UAAU,QAAQ,WAAW,EAAE,MAAM,QAAQ,CAAC;GAC9C,MAAM,QAAQ,WAAW,EAAE,QAAQ,OAAO,CAAC;GAC5C;EAED,MAAM,OAAO;GACX,MAAM,QAAQ,WAAW,EAAE,WAAW,CAAC,aAAa,EAAE,CAAC;GAEvD,SAAS,WAAW,WAAW;IAAE,WAAW,CAAC,aAAa;IAAE,MAAM;IAAQ,CAAC;GAC5E;EAED,MAAM,MAAM;GACV,MAAM,QAAQ,WAAW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const require_generators = require('./generators-
|
|
2
|
-
require('./components-
|
|
1
|
+
const require_generators = require('./generators-DM1zpqft.cjs');
|
|
2
|
+
require('./components-Djw0ll1l.cjs');
|
|
3
3
|
|
|
4
4
|
exports.mutationGenerator = require_generators.mutationGenerator;
|
|
5
5
|
exports.queryGenerator = require_generators.queryGenerator;
|
package/dist/generators.d.cts
CHANGED
package/dist/generators.d.ts
CHANGED
package/dist/generators.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./components-
|
|
2
|
-
import { n as mutationGenerator, t as queryGenerator } from "./generators-
|
|
1
|
+
import "./components-bS6nIkbY.js";
|
|
2
|
+
import { n as mutationGenerator, t as queryGenerator } from "./generators-DWKtejUq.js";
|
|
3
3
|
|
|
4
4
|
export { mutationGenerator, queryGenerator };
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_generators = require('./generators-
|
|
2
|
-
const require_components = require('./components-
|
|
1
|
+
const require_generators = require('./generators-DM1zpqft.cjs');
|
|
2
|
+
const require_components = require('./components-Djw0ll1l.cjs');
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
node_path = require_generators.__toESM(node_path);
|
|
5
5
|
let __kubb_core = require("@kubb/core");
|
|
@@ -37,7 +37,7 @@ const pluginSwr = (0, __kubb_core.definePlugin)((options) => {
|
|
|
37
37
|
...query
|
|
38
38
|
},
|
|
39
39
|
mutationKey,
|
|
40
|
-
mutation: {
|
|
40
|
+
mutation: mutation === false ? false : {
|
|
41
41
|
importPath: "swr/mutation",
|
|
42
42
|
methods: [
|
|
43
43
|
"post",
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["MutationKey","QueryKey","queryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","path","options","groupName: Group['name']","pluginClientName","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey, QueryKey } from './components'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = definePlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n paramsCasing,\n contentType,\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n ...options.client,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation: {\n
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["MutationKey","QueryKey","queryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","path","options","groupName: Group['name']","pluginClientName","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey, QueryKey } from './components'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = definePlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n paramsCasing,\n contentType,\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n ...options.client,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'delete', 'patch'],\n ...mutation,\n },\n parser,\n paramsType,\n pathParamsType,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {\n // pre add bundled fetch\n await this.upsertFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n {\n name: 'fetch',\n value: resolveModuleSource(\n this.plugin.options.client.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\n isExportable: true,\n isIndexable: true,\n },\n ],\n })\n }\n\n if (!hasClientPlugin) {\n await this.addFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n {\n name: 'config',\n value: resolveModuleSource('@kubb/plugin-client/templates/config').source,\n isExportable: false,\n isIndexable: false,\n },\n ],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAa,gBAAgB;AAE7B,MAAa,2CAAqC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,UACT,eAAe,EAAE,EACjB,OACA,UACA,QACA,aAAa,UACb,iBAAiB,eAAe,WAAW,WAAW,QAAQ,kBAAkB,UAChF,cAAcA,+BAAY,gBAC1B,WAAWC,4BAAS,gBACpB,aAAa,CAACC,mCAAgBC,qCAAkB,CAAC,OAAO,QAAQ,EAChE,cACA,gBACE;CAEJ,MAAM,aAAa,QAAQ,UAAU;CACrC,MAAM,mBAAmB,QAAQ,eAAe,CAAC,QAAQ,SAAS,+BAA+B,eAAe;AAEhH,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA,QAAQ;IACN,GAAG,QAAQ;IACX,QAAQ;IACR,YAAY,QAAQ,cAAc;IAClC,YAAY;IACZ,gBAAgB,QAAQ,kBAAkB;IAC3C;GACD;GACA,OACE,UAAU,QACN,QACA;IACE,YAAY;IACZ,SAAS,CAAC,MAAM;IAChB,GAAG;IACJ;GACP;GACA,UACE,aAAa,QACT,QACA;IACE,YAAY;IACZ,SAAS;KAAC;KAAQ;KAAO;KAAU;KAAQ;IAC3C,GAAG;IACJ;GACP;GACA;GACA;GACA;GACA;GACD;EACD,KAAK;GAACC;GAAeC;GAAc,WAAW,QAAQC,kCAAgB;GAAU,CAAC,OAAO,QAAQ;EAChG,YAAY,UAAU,UAAU,WAAS;GACvC,MAAM,OAA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,CAAC,KAAK,OAAO,QAAQ,OAAO,WAEvF,OAAM,KAAK,WAAW;IACpB,UAAU;IACV,MAAMH,kBAAK,QAAQ,MAAM,iBAAiB;IAC1C,SAAS,CACP;KACE,MAAM;KACN,kDACE,KAAK,OAAO,QAAQ,OAAO,WAAW,UAAU,gDAAgD,8CACjG,CAAC;KACF,cAAc;KACd,aAAa;KACd,CACF;IACF,CAAC;AAGJ,OAAI,CAAC,gBACH,OAAM,KAAK,QAAQ;IACjB,UAAU;IACV,MAAMA,kBAAK,QAAQ,MAAM,kBAAkB;IAC3C,SAAS,CACP;KACE,MAAM;KACN,kDAA2B,uCAAuC,CAAC;KACnE,cAAc;KACd,aAAa;KACd,CACF;IACF,CAAC;GAeJ,MAAM,QAAQ,MAZa,IAAII,qCAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,sCAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as PluginSwr, o as UserPluginWithLifeCycle, t as Options } from "./types-
|
|
1
|
+
import { n as PluginSwr, o as UserPluginWithLifeCycle, t as Options } from "./types-DV16H9Nj.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin.d.ts
|
|
4
4
|
declare const pluginSwrName = "plugin-swr";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as PluginSwr, o as UserPluginWithLifeCycle, t as Options } from "./types-
|
|
1
|
+
import { n as PluginSwr, o as UserPluginWithLifeCycle, t as Options } from "./types-BhMJy6gt.js";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin.d.ts
|
|
4
4
|
declare const pluginSwrName = "plugin-swr";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as MutationKey, r as QueryKey } from "./components-
|
|
2
|
-
import { n as mutationGenerator, t as queryGenerator } from "./generators-
|
|
1
|
+
import { a as MutationKey, r as QueryKey } from "./components-bS6nIkbY.js";
|
|
2
|
+
import { n as mutationGenerator, t as queryGenerator } from "./generators-DWKtejUq.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { definePlugin, getBarrelFiles, getMode } from "@kubb/core";
|
|
5
5
|
import { camelCase, pascalCase } from "@kubb/core/transformers";
|
|
@@ -36,7 +36,7 @@ const pluginSwr = definePlugin((options) => {
|
|
|
36
36
|
...query
|
|
37
37
|
},
|
|
38
38
|
mutationKey,
|
|
39
|
-
mutation: {
|
|
39
|
+
mutation: mutation === false ? false : {
|
|
40
40
|
importPath: "swr/mutation",
|
|
41
41
|
methods: [
|
|
42
42
|
"post",
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["options","groupName: Group['name']"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey, QueryKey } from './components'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = definePlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n paramsCasing,\n contentType,\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n ...options.client,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation: {\n
|
|
1
|
+
{"version":3,"file":"index.js","names":["options","groupName: Group['name']"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey, QueryKey } from './components'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = definePlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n paramsCasing,\n contentType,\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n ...options.client,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation:\n mutation === false\n ? false\n : {\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'delete', 'patch'],\n ...mutation,\n },\n parser,\n paramsType,\n pathParamsType,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {\n // pre add bundled fetch\n await this.upsertFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n {\n name: 'fetch',\n value: resolveModuleSource(\n this.plugin.options.client.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\n isExportable: true,\n isIndexable: true,\n },\n ],\n })\n }\n\n if (!hasClientPlugin) {\n await this.addFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n {\n name: 'config',\n value: resolveModuleSource('@kubb/plugin-client/templates/config').source,\n isExportable: false,\n isIndexable: false,\n },\n ],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,gBAAgB;AAE7B,MAAa,YAAY,cAAyB,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,UACT,eAAe,E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d,CACF;IACF,CAAC;GAeJ,MAAM,QAAQ,MAZa,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fabric } from "@kubb/react-fabric";
|
|
1
2
|
import * as OasTypes from "oas/types";
|
|
2
3
|
import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
|
|
3
4
|
import { Operation, Operation as Operation$1 } from "oas/operation";
|
|
@@ -5,7 +6,6 @@ import { OpenAPIV3 } from "openapi-types";
|
|
|
5
6
|
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
6
7
|
import BaseOas from "oas";
|
|
7
8
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
8
|
-
import { Fabric } from "@kubb/react-fabric";
|
|
9
9
|
import { ConsolaInstance, LogLevel } from "consola";
|
|
10
10
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
11
11
|
|
|
@@ -1180,6 +1180,13 @@ type Mutation = {
|
|
|
1180
1180
|
* @default 'swr/mutation'
|
|
1181
1181
|
*/
|
|
1182
1182
|
importPath?: string;
|
|
1183
|
+
/**
|
|
1184
|
+
* When true, mutation parameters (path params, query params, headers, body) will be passed via `trigger()` instead of as hook arguments.
|
|
1185
|
+
* This aligns with React Query's mutation pattern where variables are passed when triggering the mutation.
|
|
1186
|
+
* @default false
|
|
1187
|
+
* @deprecated This will become the default behavior in v5. Set to `true` to opt-in early.
|
|
1188
|
+
*/
|
|
1189
|
+
paramsToTrigger?: boolean;
|
|
1183
1190
|
};
|
|
1184
1191
|
type Options$1 = {
|
|
1185
1192
|
/**
|
|
@@ -1255,7 +1262,7 @@ type ResolvedOptions = {
|
|
|
1255
1262
|
queryKey: QueryKey | undefined;
|
|
1256
1263
|
query: NonNullable<Required<Query>> | false;
|
|
1257
1264
|
mutationKey: MutationKey | undefined;
|
|
1258
|
-
mutation:
|
|
1265
|
+
mutation: (Required<Pick<Mutation, 'methods' | 'importPath'>> & Pick<Mutation, 'paramsToTrigger'>) | false;
|
|
1259
1266
|
paramsCasing: Options$1['paramsCasing'];
|
|
1260
1267
|
paramsType: NonNullable<Options$1['paramsType']>;
|
|
1261
1268
|
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
@@ -1264,4 +1271,4 @@ type ResolvedOptions = {
|
|
|
1264
1271
|
type PluginSwr = PluginFactoryOptions<'plugin-swr', Options$1, ResolvedOptions, never, ResolvePathOptions>;
|
|
1265
1272
|
//#endregion
|
|
1266
1273
|
export { OperationSchemas as a, ReactGenerator as i, PluginSwr as n, UserPluginWithLifeCycle as o, Transformer as r, Operation$1 as s, Options$1 as t };
|
|
1267
|
-
//# sourceMappingURL=types-
|
|
1274
|
+
//# sourceMappingURL=types-BhMJy6gt.d.ts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Fabric } from "@kubb/react-fabric";
|
|
2
1
|
import * as OasTypes from "oas/types";
|
|
3
2
|
import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
|
|
4
3
|
import { Operation, Operation as Operation$1 } from "oas/operation";
|
|
@@ -6,6 +5,7 @@ import { OpenAPIV3 } from "openapi-types";
|
|
|
6
5
|
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
7
6
|
import BaseOas from "oas";
|
|
8
7
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
8
|
+
import { Fabric } from "@kubb/react-fabric";
|
|
9
9
|
import { ConsolaInstance, LogLevel } from "consola";
|
|
10
10
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
11
11
|
|
|
@@ -1180,6 +1180,13 @@ type Mutation = {
|
|
|
1180
1180
|
* @default 'swr/mutation'
|
|
1181
1181
|
*/
|
|
1182
1182
|
importPath?: string;
|
|
1183
|
+
/**
|
|
1184
|
+
* When true, mutation parameters (path params, query params, headers, body) will be passed via `trigger()` instead of as hook arguments.
|
|
1185
|
+
* This aligns with React Query's mutation pattern where variables are passed when triggering the mutation.
|
|
1186
|
+
* @default false
|
|
1187
|
+
* @deprecated This will become the default behavior in v5. Set to `true` to opt-in early.
|
|
1188
|
+
*/
|
|
1189
|
+
paramsToTrigger?: boolean;
|
|
1183
1190
|
};
|
|
1184
1191
|
type Options$1 = {
|
|
1185
1192
|
/**
|
|
@@ -1255,7 +1262,7 @@ type ResolvedOptions = {
|
|
|
1255
1262
|
queryKey: QueryKey | undefined;
|
|
1256
1263
|
query: NonNullable<Required<Query>> | false;
|
|
1257
1264
|
mutationKey: MutationKey | undefined;
|
|
1258
|
-
mutation:
|
|
1265
|
+
mutation: (Required<Pick<Mutation, 'methods' | 'importPath'>> & Pick<Mutation, 'paramsToTrigger'>) | false;
|
|
1259
1266
|
paramsCasing: Options$1['paramsCasing'];
|
|
1260
1267
|
paramsType: NonNullable<Options$1['paramsType']>;
|
|
1261
1268
|
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
@@ -1264,4 +1271,4 @@ type ResolvedOptions = {
|
|
|
1264
1271
|
type PluginSwr = PluginFactoryOptions<'plugin-swr', Options$1, ResolvedOptions, never, ResolvePathOptions>;
|
|
1265
1272
|
//#endregion
|
|
1266
1273
|
export { OperationSchemas as a, ReactGenerator as i, PluginSwr as n, UserPluginWithLifeCycle as o, Transformer as r, Operation$1 as s, Options$1 as t };
|
|
1267
|
-
//# sourceMappingURL=types-
|
|
1274
|
+
//# sourceMappingURL=types-DV16H9Nj.d.cts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-swr",
|
|
3
|
-
"version": "4.9.
|
|
3
|
+
"version": "4.9.3",
|
|
4
4
|
"description": "SWR hooks generator plugin for Kubb, creating type-safe data fetching hooks from OpenAPI specifications for React and Next.js applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"swr",
|
|
@@ -72,12 +72,12 @@
|
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"@kubb/react-fabric": "0.5.4",
|
|
74
74
|
"remeda": "^2.32.0",
|
|
75
|
-
"@kubb/core": "4.9.
|
|
76
|
-
"@kubb/oas": "4.9.
|
|
77
|
-
"@kubb/plugin-client": "4.9.
|
|
78
|
-
"@kubb/plugin-oas": "4.9.
|
|
79
|
-
"@kubb/plugin-ts": "4.9.
|
|
80
|
-
"@kubb/plugin-zod": "4.9.
|
|
75
|
+
"@kubb/core": "4.9.3",
|
|
76
|
+
"@kubb/oas": "4.9.3",
|
|
77
|
+
"@kubb/plugin-client": "4.9.3",
|
|
78
|
+
"@kubb/plugin-oas": "4.9.3",
|
|
79
|
+
"@kubb/plugin-ts": "4.9.3",
|
|
80
|
+
"@kubb/plugin-zod": "4.9.3"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
83
|
"@kubb/react-fabric": "0.5.4"
|
|
@@ -2,8 +2,8 @@ import { isOptional, type Operation } from '@kubb/oas'
|
|
|
2
2
|
import { Client } from '@kubb/plugin-client/components'
|
|
3
3
|
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
4
4
|
import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
|
|
5
|
-
import { File, Function, FunctionParams } from '@kubb/react-fabric'
|
|
6
|
-
import type { KubbNode } from '@kubb/react-fabric/types'
|
|
5
|
+
import { File, Function, FunctionParams, Type } from '@kubb/react-fabric'
|
|
6
|
+
import type { KubbNode, Params } from '@kubb/react-fabric/types'
|
|
7
7
|
import type { PluginSwr } from '../types.ts'
|
|
8
8
|
import { MutationKey } from './MutationKey.tsx'
|
|
9
9
|
|
|
@@ -22,6 +22,11 @@ type Props = {
|
|
|
22
22
|
paramsType: PluginSwr['resolvedOptions']['paramsType']
|
|
23
23
|
dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']
|
|
24
24
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
25
|
+
/**
|
|
26
|
+
* When true, mutation parameters are passed via trigger() instead of as hook arguments
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
paramsToTrigger?: boolean
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
type GetParamsProps = {
|
|
@@ -31,7 +36,8 @@ type GetParamsProps = {
|
|
|
31
36
|
typeSchemas: OperationSchemas
|
|
32
37
|
mutationKeyTypeName: string
|
|
33
38
|
}
|
|
34
|
-
|
|
39
|
+
|
|
40
|
+
// Original getParams - used when paramsToTrigger is false (default)
|
|
35
41
|
function getParams({ pathParamsType, paramsCasing, dataReturnType, typeSchemas, mutationKeyTypeName }: GetParamsProps) {
|
|
36
42
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
37
43
|
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
|
|
@@ -67,6 +73,61 @@ function getParams({ pathParamsType, paramsCasing, dataReturnType, typeSchemas,
|
|
|
67
73
|
})
|
|
68
74
|
}
|
|
69
75
|
|
|
76
|
+
type GetTriggerParamsProps = {
|
|
77
|
+
dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']
|
|
78
|
+
typeSchemas: OperationSchemas
|
|
79
|
+
mutationKeyTypeName: string
|
|
80
|
+
mutationArgTypeName: string
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// New getParams - used when paramsToTrigger is true
|
|
84
|
+
function getTriggerParams({ dataReturnType, typeSchemas, mutationKeyTypeName, mutationArgTypeName }: GetTriggerParamsProps) {
|
|
85
|
+
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
86
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
|
|
87
|
+
|
|
88
|
+
return FunctionParams.factory({
|
|
89
|
+
options: {
|
|
90
|
+
type: `
|
|
91
|
+
{
|
|
92
|
+
mutation?: SWRMutationConfiguration<${TData}, ${TError}, ${mutationKeyTypeName} | null, ${mutationArgTypeName}> & { throwOnError?: boolean },
|
|
93
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : 'Partial<RequestConfig> & { client?: typeof fetch }'},
|
|
94
|
+
shouldFetch?: boolean,
|
|
95
|
+
}
|
|
96
|
+
`,
|
|
97
|
+
default: '{}',
|
|
98
|
+
},
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
type GetMutationParamsProps = {
|
|
103
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
104
|
+
typeSchemas: OperationSchemas
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function getMutationParams({ paramsCasing, typeSchemas }: GetMutationParamsProps) {
|
|
108
|
+
return FunctionParams.factory({
|
|
109
|
+
...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
110
|
+
data: typeSchemas.request?.name
|
|
111
|
+
? {
|
|
112
|
+
type: typeSchemas.request?.name,
|
|
113
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
114
|
+
}
|
|
115
|
+
: undefined,
|
|
116
|
+
params: typeSchemas.queryParams?.name
|
|
117
|
+
? {
|
|
118
|
+
type: typeSchemas.queryParams?.name,
|
|
119
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
120
|
+
}
|
|
121
|
+
: undefined,
|
|
122
|
+
headers: typeSchemas.headerParams?.name
|
|
123
|
+
? {
|
|
124
|
+
type: typeSchemas.headerParams?.name,
|
|
125
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
126
|
+
}
|
|
127
|
+
: undefined,
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
70
131
|
export function Mutation({
|
|
71
132
|
name,
|
|
72
133
|
clientName,
|
|
@@ -78,22 +139,107 @@ export function Mutation({
|
|
|
78
139
|
dataReturnType,
|
|
79
140
|
typeSchemas,
|
|
80
141
|
operation,
|
|
142
|
+
paramsToTrigger = false,
|
|
81
143
|
}: Props): KubbNode {
|
|
82
144
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
83
145
|
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
|
|
84
146
|
|
|
147
|
+
const mutationKeyParams = MutationKey.getParams({
|
|
148
|
+
pathParamsType,
|
|
149
|
+
typeSchemas,
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
const clientParams = Client.getParams({
|
|
153
|
+
paramsCasing,
|
|
154
|
+
paramsType,
|
|
155
|
+
typeSchemas,
|
|
156
|
+
pathParamsType,
|
|
157
|
+
isConfigurable: true,
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
// Use the new trigger-based approach when paramsToTrigger is true
|
|
161
|
+
if (paramsToTrigger) {
|
|
162
|
+
// Build the mutation params type (for arg destructuring)
|
|
163
|
+
const mutationParams = getMutationParams({
|
|
164
|
+
paramsCasing,
|
|
165
|
+
typeSchemas,
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
// Get the arg type name
|
|
169
|
+
const mutationArgTypeName = `${mutationKeyTypeName.replace('MutationKey', '')}MutationArg`
|
|
170
|
+
|
|
171
|
+
// Check if there are any mutation params (path, data, params, headers)
|
|
172
|
+
const hasMutationParams = Object.keys(mutationParams.params).length > 0
|
|
173
|
+
|
|
174
|
+
// Build the arg type for useSWRMutation
|
|
175
|
+
const argParams = FunctionParams.factory({
|
|
176
|
+
data: {
|
|
177
|
+
mode: 'object',
|
|
178
|
+
children: Object.entries(mutationParams.params).reduce((acc, [key, value]) => {
|
|
179
|
+
if (value) {
|
|
180
|
+
acc[key] = {
|
|
181
|
+
...value,
|
|
182
|
+
type: undefined,
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return acc
|
|
186
|
+
}, {} as Params),
|
|
187
|
+
},
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
const params = getTriggerParams({
|
|
191
|
+
dataReturnType,
|
|
192
|
+
typeSchemas,
|
|
193
|
+
mutationKeyTypeName,
|
|
194
|
+
mutationArgTypeName,
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
const generics = [TData, TError, `${mutationKeyTypeName} | null`, mutationArgTypeName].filter(Boolean)
|
|
198
|
+
|
|
199
|
+
const mutationArg = mutationParams.toConstructor()
|
|
200
|
+
|
|
201
|
+
return (
|
|
202
|
+
<>
|
|
203
|
+
<File.Source name={mutationArgTypeName} isExportable isIndexable isTypeOnly>
|
|
204
|
+
<Type name={mutationArgTypeName} export>
|
|
205
|
+
{hasMutationParams ? `{${mutationArg}}` : 'never'}
|
|
206
|
+
</Type>
|
|
207
|
+
</File.Source>
|
|
208
|
+
<File.Source name={name} isExportable isIndexable>
|
|
209
|
+
<Function
|
|
210
|
+
name={name}
|
|
211
|
+
export
|
|
212
|
+
params={params.toConstructor()}
|
|
213
|
+
JSDoc={{
|
|
214
|
+
comments: getComments(operation),
|
|
215
|
+
}}
|
|
216
|
+
>
|
|
217
|
+
{`
|
|
218
|
+
const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
|
|
219
|
+
const mutationKey = ${mutationKeyName}(${mutationKeyParams.toCall()})
|
|
220
|
+
|
|
221
|
+
return useSWRMutation<${generics.join(', ')}>(
|
|
222
|
+
shouldFetch ? mutationKey : null,
|
|
223
|
+
async (_url${hasMutationParams ? `, { arg: ${argParams.toCall()} }` : ''}) => {
|
|
224
|
+
return ${clientName}(${clientParams.toCall()})
|
|
225
|
+
},
|
|
226
|
+
mutationOptions
|
|
227
|
+
)
|
|
228
|
+
`}
|
|
229
|
+
</Function>
|
|
230
|
+
</File.Source>
|
|
231
|
+
</>
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Original behavior (default)
|
|
85
236
|
const generics = [
|
|
86
237
|
TData,
|
|
87
238
|
TError,
|
|
88
239
|
`${mutationKeyTypeName} | null`,
|
|
89
|
-
typeSchemas.request?.name, //arg
|
|
240
|
+
typeSchemas.request?.name, // TExtraArg - the arg type for useSWRMutation
|
|
90
241
|
].filter(Boolean)
|
|
91
242
|
|
|
92
|
-
const mutationKeyParams = MutationKey.getParams({
|
|
93
|
-
pathParamsType,
|
|
94
|
-
typeSchemas,
|
|
95
|
-
})
|
|
96
|
-
|
|
97
243
|
const params = getParams({
|
|
98
244
|
paramsCasing,
|
|
99
245
|
pathParamsType,
|
|
@@ -102,14 +248,6 @@ export function Mutation({
|
|
|
102
248
|
mutationKeyTypeName,
|
|
103
249
|
})
|
|
104
250
|
|
|
105
|
-
const clientParams = Client.getParams({
|
|
106
|
-
paramsCasing,
|
|
107
|
-
paramsType,
|
|
108
|
-
typeSchemas,
|
|
109
|
-
pathParamsType,
|
|
110
|
-
isConfigurable: true,
|
|
111
|
-
})
|
|
112
|
-
|
|
113
251
|
return (
|
|
114
252
|
<File.Source name={name} isExportable isIndexable>
|
|
115
253
|
<Function
|