@kubb/plugin-swr 5.2.0-canary.20261007T095624 → 5.2.1
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 +26 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.js +26 -19
- package/dist/index.js.map +1 -1
- package/package.json +9 -12
package/dist/index.cjs
CHANGED
|
@@ -345,8 +345,8 @@ function createGroupConfig(group) {
|
|
|
345
345
|
*
|
|
346
346
|
* - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
|
|
347
347
|
* imports and calls them.
|
|
348
|
-
* - `error` — no client plugin is registered, several are registered without a selector,
|
|
349
|
-
* requested one is missing.
|
|
348
|
+
* - `error` — no client plugin is registered, several are registered without a selector, the
|
|
349
|
+
* requested one is missing, or `client` is not a known selector.
|
|
350
350
|
*
|
|
351
351
|
* The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
|
|
352
352
|
* contract client plugin is picked up automatically.
|
|
@@ -387,6 +387,10 @@ function resolveClient(options) {
|
|
|
387
387
|
pluginName
|
|
388
388
|
};
|
|
389
389
|
}
|
|
390
|
+
if (client !== void 0) return {
|
|
391
|
+
kind: "error",
|
|
392
|
+
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.`
|
|
393
|
+
};
|
|
390
394
|
const registered = contractPlugins.filter(has);
|
|
391
395
|
if (registered.length === 1) return {
|
|
392
396
|
kind: "contract",
|
|
@@ -660,7 +664,8 @@ function MutationKey$1({ name, node, transformer }) {
|
|
|
660
664
|
const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
|
|
661
665
|
const keys = (transformer ?? mutationKeyTransformer)({
|
|
662
666
|
node,
|
|
663
|
-
casing: "camelcase"
|
|
667
|
+
casing: "camelcase",
|
|
668
|
+
variant: "mutation"
|
|
664
669
|
});
|
|
665
670
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
666
671
|
name,
|
|
@@ -732,23 +737,25 @@ function createMutationResolver() {
|
|
|
732
737
|
//#endregion
|
|
733
738
|
//#region ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
734
739
|
const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
735
|
-
const queryKeyTransformer = ({ node }) => {
|
|
740
|
+
const queryKeyTransformer = ({ node, variant }) => {
|
|
736
741
|
if (!node.path) return [];
|
|
737
|
-
const
|
|
738
|
-
const
|
|
739
|
-
const
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
].
|
|
742
|
+
const { path, query } = getOperationParameters(node);
|
|
743
|
+
const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
|
|
744
|
+
const urlFields = [`url: '${kubb_kit.Url.toPath(node.path)}'`];
|
|
745
|
+
if (path.length > 0) urlFields.push("params: path");
|
|
746
|
+
if (isInfinite) urlFields.push("infinite: true");
|
|
747
|
+
const result = [`{ ${urlFields.join(", ")} }`];
|
|
748
|
+
if (query.length > 0) result.push("...(query ? [query] : [])");
|
|
749
|
+
if (node.requestBody?.content?.[0]?.schema) result.push("...(body ? [body] : [])");
|
|
750
|
+
return result;
|
|
745
751
|
};
|
|
746
|
-
function QueryKey({ name, node, tsResolver, typeName, transformer }) {
|
|
752
|
+
function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query" }) {
|
|
747
753
|
const paramsNode = buildQueryKeyParams(node, { resolver: tsResolver });
|
|
748
754
|
const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
|
|
749
755
|
const keys = (transformer ?? queryKeyTransformer)({
|
|
750
756
|
node,
|
|
751
|
-
casing: "camelcase"
|
|
757
|
+
casing: "camelcase",
|
|
758
|
+
variant
|
|
752
759
|
});
|
|
753
760
|
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
761
|
name,
|
|
@@ -982,8 +989,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
982
989
|
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
983
990
|
const { config, driver, resolver, root } = ctx;
|
|
984
991
|
const { output, query, mutation, client, group } = ctx.options;
|
|
985
|
-
const pluginTs =
|
|
986
|
-
if (!pluginTs) return null;
|
|
992
|
+
const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
|
|
987
993
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
988
994
|
const { isMutation } = classifyOperation(node, {
|
|
989
995
|
query,
|
|
@@ -1110,8 +1116,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1110
1116
|
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1111
1117
|
const { config, driver, resolver, root } = ctx;
|
|
1112
1118
|
const { output, query, mutation, client, group } = ctx.options;
|
|
1113
|
-
const pluginTs =
|
|
1114
|
-
if (!pluginTs) return null;
|
|
1119
|
+
const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
|
|
1115
1120
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
1116
1121
|
const { isQuery } = classifyOperation(node, {
|
|
1117
1122
|
query,
|
|
@@ -1200,7 +1205,8 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1200
1205
|
typeName: queryKeyTypeName,
|
|
1201
1206
|
node,
|
|
1202
1207
|
tsResolver,
|
|
1203
|
-
transformer: ctx.options.queryKey
|
|
1208
|
+
transformer: ctx.options.queryKey,
|
|
1209
|
+
variant: "query"
|
|
1204
1210
|
}),
|
|
1205
1211
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryOptions, {
|
|
1206
1212
|
name: queryOptionsName,
|
|
@@ -1303,6 +1309,7 @@ const pluginSwr = (0, kubb_kit.definePlugin)((options) => {
|
|
|
1303
1309
|
options,
|
|
1304
1310
|
dependencies: [_kubb_plugin_ts.pluginTsName],
|
|
1305
1311
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
1312
|
+
ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
|
|
1306
1313
|
const resolver = userResolver ? kubb_kit.Resolver.merge(resolverSwr, userResolver) : resolverSwr;
|
|
1307
1314
|
ctx.setOptions({
|
|
1308
1315
|
output,
|