@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.js
CHANGED
|
@@ -315,8 +315,8 @@ function createGroupConfig(group) {
|
|
|
315
315
|
*
|
|
316
316
|
* - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
|
|
317
317
|
* imports and calls them.
|
|
318
|
-
* - `error` — no client plugin is registered, several are registered without a selector,
|
|
319
|
-
* requested one is missing.
|
|
318
|
+
* - `error` — no client plugin is registered, several are registered without a selector, the
|
|
319
|
+
* requested one is missing, or `client` is not a known selector.
|
|
320
320
|
*
|
|
321
321
|
* The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
|
|
322
322
|
* contract client plugin is picked up automatically.
|
|
@@ -357,6 +357,10 @@ function resolveClient(options) {
|
|
|
357
357
|
pluginName
|
|
358
358
|
};
|
|
359
359
|
}
|
|
360
|
+
if (client !== void 0) return {
|
|
361
|
+
kind: "error",
|
|
362
|
+
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.`
|
|
363
|
+
};
|
|
360
364
|
const registered = contractPlugins.filter(has);
|
|
361
365
|
if (registered.length === 1) return {
|
|
362
366
|
kind: "contract",
|
|
@@ -630,7 +634,8 @@ function MutationKey$1({ name, node, transformer }) {
|
|
|
630
634
|
const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
|
|
631
635
|
const keys = (transformer ?? mutationKeyTransformer)({
|
|
632
636
|
node,
|
|
633
|
-
casing: "camelcase"
|
|
637
|
+
casing: "camelcase",
|
|
638
|
+
variant: "mutation"
|
|
634
639
|
});
|
|
635
640
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
636
641
|
name,
|
|
@@ -702,23 +707,25 @@ function createMutationResolver() {
|
|
|
702
707
|
//#endregion
|
|
703
708
|
//#region ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
704
709
|
const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
|
|
705
|
-
const queryKeyTransformer = ({ node }) => {
|
|
710
|
+
const queryKeyTransformer = ({ node, variant }) => {
|
|
706
711
|
if (!node.path) return [];
|
|
707
|
-
const
|
|
708
|
-
const
|
|
709
|
-
const
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
].
|
|
712
|
+
const { path, query } = getOperationParameters(node);
|
|
713
|
+
const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
|
|
714
|
+
const urlFields = [`url: '${Url.toPath(node.path)}'`];
|
|
715
|
+
if (path.length > 0) urlFields.push("params: path");
|
|
716
|
+
if (isInfinite) urlFields.push("infinite: true");
|
|
717
|
+
const result = [`{ ${urlFields.join(", ")} }`];
|
|
718
|
+
if (query.length > 0) result.push("...(query ? [query] : [])");
|
|
719
|
+
if (node.requestBody?.content?.[0]?.schema) result.push("...(body ? [body] : [])");
|
|
720
|
+
return result;
|
|
715
721
|
};
|
|
716
|
-
function QueryKey({ name, node, tsResolver, typeName, transformer }) {
|
|
722
|
+
function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query" }) {
|
|
717
723
|
const paramsNode = buildQueryKeyParams(node, { resolver: tsResolver });
|
|
718
724
|
const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
|
|
719
725
|
const keys = (transformer ?? queryKeyTransformer)({
|
|
720
726
|
node,
|
|
721
|
-
casing: "camelcase"
|
|
727
|
+
casing: "camelcase",
|
|
728
|
+
variant
|
|
722
729
|
});
|
|
723
730
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
|
|
724
731
|
name,
|
|
@@ -952,8 +959,7 @@ const mutationGenerator = defineGenerator({
|
|
|
952
959
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
953
960
|
const { config, driver, resolver, root } = ctx;
|
|
954
961
|
const { output, query, mutation, client, group } = ctx.options;
|
|
955
|
-
const pluginTs =
|
|
956
|
-
if (!pluginTs) return null;
|
|
962
|
+
const pluginTs = ctx.requirePlugin(pluginTsName);
|
|
957
963
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
958
964
|
const { isMutation } = classifyOperation(node, {
|
|
959
965
|
query,
|
|
@@ -1080,8 +1086,7 @@ const queryGenerator = defineGenerator({
|
|
|
1080
1086
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1081
1087
|
const { config, driver, resolver, root } = ctx;
|
|
1082
1088
|
const { output, query, mutation, client, group } = ctx.options;
|
|
1083
|
-
const pluginTs =
|
|
1084
|
-
if (!pluginTs) return null;
|
|
1089
|
+
const pluginTs = ctx.requirePlugin(pluginTsName);
|
|
1085
1090
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
1086
1091
|
const { isQuery } = classifyOperation(node, {
|
|
1087
1092
|
query,
|
|
@@ -1170,7 +1175,8 @@ const queryGenerator = defineGenerator({
|
|
|
1170
1175
|
typeName: queryKeyTypeName,
|
|
1171
1176
|
node,
|
|
1172
1177
|
tsResolver,
|
|
1173
|
-
transformer: ctx.options.queryKey
|
|
1178
|
+
transformer: ctx.options.queryKey,
|
|
1179
|
+
variant: "query"
|
|
1174
1180
|
}),
|
|
1175
1181
|
/* @__PURE__ */ jsx(QueryOptions, {
|
|
1176
1182
|
name: queryOptionsName,
|
|
@@ -1273,6 +1279,7 @@ const pluginSwr = definePlugin((options) => {
|
|
|
1273
1279
|
options,
|
|
1274
1280
|
dependencies: [pluginTsName],
|
|
1275
1281
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
1282
|
+
ctx.requirePlugin(pluginTsName);
|
|
1276
1283
|
const resolver = userResolver ? Resolver.merge(resolverSwr, userResolver) : resolverSwr;
|
|
1277
1284
|
ctx.setOptions({
|
|
1278
1285
|
output,
|