@kubb/plugin-swr 5.2.0-canary.20261008T111956 → 5.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +60 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.js +61 -53
- package/dist/index.js.map +1 -1
- package/package.json +9 -12
package/dist/index.cjs
CHANGED
|
@@ -335,6 +335,9 @@ function createGroupConfig(group) {
|
|
|
335
335
|
};
|
|
336
336
|
}
|
|
337
337
|
//#endregion
|
|
338
|
+
//#region package.json
|
|
339
|
+
var version = "5.2.2";
|
|
340
|
+
//#endregion
|
|
338
341
|
//#region ../../internals/client/src/resolveClient.ts
|
|
339
342
|
/**
|
|
340
343
|
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
@@ -345,8 +348,8 @@ function createGroupConfig(group) {
|
|
|
345
348
|
*
|
|
346
349
|
* - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
|
|
347
350
|
* imports and calls them.
|
|
348
|
-
* - `error` — no client plugin is registered, several are registered without a selector,
|
|
349
|
-
* requested one is missing.
|
|
351
|
+
* - `error` — no client plugin is registered, several are registered without a selector, the
|
|
352
|
+
* requested one is missing, or `client` is not a known selector.
|
|
350
353
|
*
|
|
351
354
|
* The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
|
|
352
355
|
* contract client plugin is picked up automatically.
|
|
@@ -387,6 +390,10 @@ function resolveClient(options) {
|
|
|
387
390
|
pluginName
|
|
388
391
|
};
|
|
389
392
|
}
|
|
393
|
+
if (client !== void 0) return {
|
|
394
|
+
kind: "error",
|
|
395
|
+
message: `Option \`client\` is ${typeof client === "string" ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios'. Drop \`client\` to use the registered client plugin.`
|
|
396
|
+
};
|
|
390
397
|
const registered = contractPlugins.filter(has);
|
|
391
398
|
if (registered.length === 1) return {
|
|
392
399
|
kind: "contract",
|
|
@@ -660,7 +667,8 @@ function MutationKey$1({ name, node, transformer }) {
|
|
|
660
667
|
const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
|
|
661
668
|
const keys = (transformer ?? mutationKeyTransformer)({
|
|
662
669
|
node,
|
|
663
|
-
casing: "camelcase"
|
|
670
|
+
casing: "camelcase",
|
|
671
|
+
variant: "mutation"
|
|
664
672
|
});
|
|
665
673
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
666
674
|
name,
|
|
@@ -732,23 +740,25 @@ function createMutationResolver() {
|
|
|
732
740
|
//#endregion
|
|
733
741
|
//#region ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
734
742
|
const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
735
|
-
const queryKeyTransformer = ({ node }) => {
|
|
743
|
+
const queryKeyTransformer = ({ node, variant }) => {
|
|
736
744
|
if (!node.path) return [];
|
|
737
|
-
const
|
|
738
|
-
const
|
|
739
|
-
const
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
].
|
|
745
|
+
const { path, query } = getOperationParameters(node);
|
|
746
|
+
const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
|
|
747
|
+
const urlFields = [`url: '${kubb_kit.Url.toPath(node.path)}'`];
|
|
748
|
+
if (path.length > 0) urlFields.push("params: path");
|
|
749
|
+
if (isInfinite) urlFields.push("infinite: true");
|
|
750
|
+
const result = [`{ ${urlFields.join(", ")} }`];
|
|
751
|
+
if (query.length > 0) result.push("...(query ? [query] : [])");
|
|
752
|
+
if (node.requestBody?.content?.[0]?.schema) result.push("...(body ? [body] : [])");
|
|
753
|
+
return result;
|
|
745
754
|
};
|
|
746
|
-
function QueryKey({ name, node, tsResolver, typeName, transformer }) {
|
|
755
|
+
function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query" }) {
|
|
747
756
|
const paramsNode = buildQueryKeyParams(node, { resolver: tsResolver });
|
|
748
757
|
const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
|
|
749
758
|
const keys = (transformer ?? queryKeyTransformer)({
|
|
750
759
|
node,
|
|
751
|
-
casing: "camelcase"
|
|
760
|
+
casing: "camelcase",
|
|
761
|
+
variant
|
|
752
762
|
});
|
|
753
763
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
754
764
|
name,
|
|
@@ -982,8 +992,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
982
992
|
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
983
993
|
const { config, driver, resolver, root } = ctx;
|
|
984
994
|
const { output, query, mutation, client, group } = ctx.options;
|
|
985
|
-
const pluginTs =
|
|
986
|
-
if (!pluginTs) return null;
|
|
995
|
+
const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
|
|
987
996
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
988
997
|
const { isMutation } = classifyOperation(node, {
|
|
989
998
|
query,
|
|
@@ -1110,8 +1119,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1110
1119
|
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1111
1120
|
const { config, driver, resolver, root } = ctx;
|
|
1112
1121
|
const { output, query, mutation, client, group } = ctx.options;
|
|
1113
|
-
const pluginTs =
|
|
1114
|
-
if (!pluginTs) return null;
|
|
1122
|
+
const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
|
|
1115
1123
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
1116
1124
|
const { isQuery } = classifyOperation(node, {
|
|
1117
1125
|
query,
|
|
@@ -1200,7 +1208,8 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1200
1208
|
typeName: queryKeyTypeName,
|
|
1201
1209
|
node,
|
|
1202
1210
|
tsResolver,
|
|
1203
|
-
transformer: ctx.options.queryKey
|
|
1211
|
+
transformer: ctx.options.queryKey,
|
|
1212
|
+
variant: "query"
|
|
1204
1213
|
}),
|
|
1205
1214
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryOptions, {
|
|
1206
1215
|
name: queryOptionsName,
|
|
@@ -1291,40 +1300,39 @@ const pluginSwrName = "plugin-swr";
|
|
|
1291
1300
|
* })
|
|
1292
1301
|
* ```
|
|
1293
1302
|
*/
|
|
1294
|
-
const pluginSwr = (0, kubb_kit.definePlugin)(
|
|
1295
|
-
|
|
1296
|
-
path: "hooks",
|
|
1297
|
-
barrel: { type: "named" }
|
|
1298
|
-
}, group, exclude = [], include, override = [], mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, client, resolver: userResolver, macros: userMacros } = options;
|
|
1299
|
-
const selectedGenerators = [queryGenerator, mutationGenerator];
|
|
1300
|
-
const groupConfig = createGroupConfig(group) ?? void 0;
|
|
1301
|
-
return {
|
|
1303
|
+
const pluginSwr = (0, kubb_kit.definePlugin)({
|
|
1304
|
+
meta: {
|
|
1302
1305
|
name: pluginSwrName,
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1306
|
+
version,
|
|
1307
|
+
compatibility: { kubb: ">=5.8.0" }
|
|
1308
|
+
},
|
|
1309
|
+
dependencies: { [_kubb_plugin_ts.pluginTsName]: {} },
|
|
1310
|
+
setup(options) {
|
|
1311
|
+
const { output = {
|
|
1312
|
+
path: "hooks",
|
|
1313
|
+
barrel: { type: "named" }
|
|
1314
|
+
}, group, exclude = [], include, override = [], mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, client, resolver: userResolver, macros: userMacros } = options;
|
|
1315
|
+
const resolver = userResolver ? kubb_kit.Resolver.merge(resolverSwr, userResolver) : resolverSwr;
|
|
1316
|
+
(0, kubb_kit.setResolver)(resolver);
|
|
1317
|
+
if (userMacros?.length) (0, kubb_kit.setMacros)(userMacros);
|
|
1318
|
+
(0, kubb_kit.addGenerator)(queryGenerator, mutationGenerator);
|
|
1319
|
+
return {
|
|
1320
|
+
output,
|
|
1321
|
+
client: resolveContractClient({
|
|
1322
|
+
client,
|
|
1323
|
+
plugins: (0, kubb_kit.useConfig)().plugins
|
|
1324
|
+
}),
|
|
1325
|
+
queryKey,
|
|
1326
|
+
query: resolveQueryConfig(query, { importPath: "swr" }),
|
|
1327
|
+
mutationKey,
|
|
1328
|
+
mutation: resolveMutationConfig(mutation, { importPath: "swr/mutation" }),
|
|
1329
|
+
group: createGroupConfig(group) ?? void 0,
|
|
1330
|
+
exclude,
|
|
1331
|
+
include,
|
|
1332
|
+
override,
|
|
1333
|
+
resolver
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1328
1336
|
});
|
|
1329
1337
|
//#endregion
|
|
1330
1338
|
exports.default = pluginSwr;
|