@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.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ import "@kubb/plugin-zod";
|
|
|
13
13
|
*
|
|
14
14
|
* - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
|
|
15
15
|
* imports and calls them.
|
|
16
|
-
* - `error` — no client plugin is registered, several are registered without a selector,
|
|
17
|
-
* requested one is missing.
|
|
16
|
+
* - `error` — no client plugin is registered, several are registered without a selector, the
|
|
17
|
+
* requested one is missing, or `client` is not a known selector.
|
|
18
18
|
*
|
|
19
19
|
* The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
|
|
20
20
|
* contract client plugin is picked up automatically.
|
|
@@ -27,9 +27,19 @@ type ClientSelector = 'fetch' | 'axios';
|
|
|
27
27
|
//#endregion
|
|
28
28
|
//#region ../../internals/tanstack-query/src/types.d.ts
|
|
29
29
|
type ParamsCasing = 'camelcase' | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* The hook a key is built for. Plain and suspense queries can share a key, but an infinite query
|
|
32
|
+
* caches `InfiniteData` and must never share one with a plain query.
|
|
33
|
+
*/
|
|
34
|
+
type KeyVariant = 'query' | 'suspenseQuery' | 'infiniteQuery' | 'suspenseInfiniteQuery' | 'mutation';
|
|
35
|
+
/**
|
|
36
|
+
* Builds query or mutation key segments for an operation node.
|
|
37
|
+
* Receives `variant` indicating which hook or composable the key is built for.
|
|
38
|
+
*/
|
|
30
39
|
type Transformer = (props: {
|
|
31
40
|
node: ast.OperationNode;
|
|
32
41
|
casing: ParamsCasing;
|
|
42
|
+
variant: KeyVariant;
|
|
33
43
|
}) => Array<unknown>;
|
|
34
44
|
//#endregion
|
|
35
45
|
//#region src/types.d.ts
|
|
@@ -271,7 +281,7 @@ export declare const pluginSwrName = "plugin-swr";
|
|
|
271
281
|
* })
|
|
272
282
|
* ```
|
|
273
283
|
*/
|
|
274
|
-
export declare const pluginSwr:
|
|
284
|
+
export declare const pluginSwr: import("kubb/kit").PluginFactory<PluginSwr>;
|
|
275
285
|
//#endregion
|
|
276
286
|
//#region src/resolvers/resolverSwr.d.ts
|
|
277
287
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
-
import { Resolver, Url, ast, createResolver, defineGenerator, definePlugin } from "kubb/kit";
|
|
2
|
+
import { Resolver, Url, addGenerator, ast, createResolver, defineGenerator, definePlugin, setMacros, setResolver, useConfig } from "kubb/kit";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
5
5
|
import { File, Function, Type, jsxRenderer } from "kubb/jsx";
|
|
@@ -305,6 +305,9 @@ function createGroupConfig(group) {
|
|
|
305
305
|
};
|
|
306
306
|
}
|
|
307
307
|
//#endregion
|
|
308
|
+
//#region package.json
|
|
309
|
+
var version = "5.2.2";
|
|
310
|
+
//#endregion
|
|
308
311
|
//#region ../../internals/client/src/resolveClient.ts
|
|
309
312
|
/**
|
|
310
313
|
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
@@ -315,8 +318,8 @@ function createGroupConfig(group) {
|
|
|
315
318
|
*
|
|
316
319
|
* - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
|
|
317
320
|
* imports and calls them.
|
|
318
|
-
* - `error` — no client plugin is registered, several are registered without a selector,
|
|
319
|
-
* requested one is missing.
|
|
321
|
+
* - `error` — no client plugin is registered, several are registered without a selector, the
|
|
322
|
+
* requested one is missing, or `client` is not a known selector.
|
|
320
323
|
*
|
|
321
324
|
* The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
|
|
322
325
|
* contract client plugin is picked up automatically.
|
|
@@ -357,6 +360,10 @@ function resolveClient(options) {
|
|
|
357
360
|
pluginName
|
|
358
361
|
};
|
|
359
362
|
}
|
|
363
|
+
if (client !== void 0) return {
|
|
364
|
+
kind: "error",
|
|
365
|
+
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.`
|
|
366
|
+
};
|
|
360
367
|
const registered = contractPlugins.filter(has);
|
|
361
368
|
if (registered.length === 1) return {
|
|
362
369
|
kind: "contract",
|
|
@@ -630,7 +637,8 @@ function MutationKey$1({ name, node, transformer }) {
|
|
|
630
637
|
const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
|
|
631
638
|
const keys = (transformer ?? mutationKeyTransformer)({
|
|
632
639
|
node,
|
|
633
|
-
casing: "camelcase"
|
|
640
|
+
casing: "camelcase",
|
|
641
|
+
variant: "mutation"
|
|
634
642
|
});
|
|
635
643
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
636
644
|
name,
|
|
@@ -702,23 +710,25 @@ function createMutationResolver() {
|
|
|
702
710
|
//#endregion
|
|
703
711
|
//#region ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
704
712
|
const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
|
|
705
|
-
const queryKeyTransformer = ({ node }) => {
|
|
713
|
+
const queryKeyTransformer = ({ node, variant }) => {
|
|
706
714
|
if (!node.path) return [];
|
|
707
|
-
const
|
|
708
|
-
const
|
|
709
|
-
const
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
].
|
|
715
|
+
const { path, query } = getOperationParameters(node);
|
|
716
|
+
const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
|
|
717
|
+
const urlFields = [`url: '${Url.toPath(node.path)}'`];
|
|
718
|
+
if (path.length > 0) urlFields.push("params: path");
|
|
719
|
+
if (isInfinite) urlFields.push("infinite: true");
|
|
720
|
+
const result = [`{ ${urlFields.join(", ")} }`];
|
|
721
|
+
if (query.length > 0) result.push("...(query ? [query] : [])");
|
|
722
|
+
if (node.requestBody?.content?.[0]?.schema) result.push("...(body ? [body] : [])");
|
|
723
|
+
return result;
|
|
715
724
|
};
|
|
716
|
-
function QueryKey({ name, node, tsResolver, typeName, transformer }) {
|
|
725
|
+
function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query" }) {
|
|
717
726
|
const paramsNode = buildQueryKeyParams(node, { resolver: tsResolver });
|
|
718
727
|
const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
|
|
719
728
|
const keys = (transformer ?? queryKeyTransformer)({
|
|
720
729
|
node,
|
|
721
|
-
casing: "camelcase"
|
|
730
|
+
casing: "camelcase",
|
|
731
|
+
variant
|
|
722
732
|
});
|
|
723
733
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
|
|
724
734
|
name,
|
|
@@ -952,8 +962,7 @@ const mutationGenerator = defineGenerator({
|
|
|
952
962
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
953
963
|
const { config, driver, resolver, root } = ctx;
|
|
954
964
|
const { output, query, mutation, client, group } = ctx.options;
|
|
955
|
-
const pluginTs =
|
|
956
|
-
if (!pluginTs) return null;
|
|
965
|
+
const pluginTs = ctx.requirePlugin(pluginTsName);
|
|
957
966
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
958
967
|
const { isMutation } = classifyOperation(node, {
|
|
959
968
|
query,
|
|
@@ -1080,8 +1089,7 @@ const queryGenerator = defineGenerator({
|
|
|
1080
1089
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1081
1090
|
const { config, driver, resolver, root } = ctx;
|
|
1082
1091
|
const { output, query, mutation, client, group } = ctx.options;
|
|
1083
|
-
const pluginTs =
|
|
1084
|
-
if (!pluginTs) return null;
|
|
1092
|
+
const pluginTs = ctx.requirePlugin(pluginTsName);
|
|
1085
1093
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
1086
1094
|
const { isQuery } = classifyOperation(node, {
|
|
1087
1095
|
query,
|
|
@@ -1170,7 +1178,8 @@ const queryGenerator = defineGenerator({
|
|
|
1170
1178
|
typeName: queryKeyTypeName,
|
|
1171
1179
|
node,
|
|
1172
1180
|
tsResolver,
|
|
1173
|
-
transformer: ctx.options.queryKey
|
|
1181
|
+
transformer: ctx.options.queryKey,
|
|
1182
|
+
variant: "query"
|
|
1174
1183
|
}),
|
|
1175
1184
|
/* @__PURE__ */ jsx(QueryOptions, {
|
|
1176
1185
|
name: queryOptionsName,
|
|
@@ -1261,40 +1270,39 @@ const pluginSwrName = "plugin-swr";
|
|
|
1261
1270
|
* })
|
|
1262
1271
|
* ```
|
|
1263
1272
|
*/
|
|
1264
|
-
const pluginSwr = definePlugin(
|
|
1265
|
-
|
|
1266
|
-
path: "hooks",
|
|
1267
|
-
barrel: { type: "named" }
|
|
1268
|
-
}, group, exclude = [], include, override = [], mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, client, resolver: userResolver, macros: userMacros } = options;
|
|
1269
|
-
const selectedGenerators = [queryGenerator, mutationGenerator];
|
|
1270
|
-
const groupConfig = createGroupConfig(group) ?? void 0;
|
|
1271
|
-
return {
|
|
1273
|
+
const pluginSwr = definePlugin({
|
|
1274
|
+
meta: {
|
|
1272
1275
|
name: pluginSwrName,
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1276
|
+
version,
|
|
1277
|
+
compatibility: { kubb: ">=5.8.0" }
|
|
1278
|
+
},
|
|
1279
|
+
dependencies: { [pluginTsName]: {} },
|
|
1280
|
+
setup(options) {
|
|
1281
|
+
const { output = {
|
|
1282
|
+
path: "hooks",
|
|
1283
|
+
barrel: { type: "named" }
|
|
1284
|
+
}, group, exclude = [], include, override = [], mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, client, resolver: userResolver, macros: userMacros } = options;
|
|
1285
|
+
const resolver = userResolver ? Resolver.merge(resolverSwr, userResolver) : resolverSwr;
|
|
1286
|
+
setResolver(resolver);
|
|
1287
|
+
if (userMacros?.length) setMacros(userMacros);
|
|
1288
|
+
addGenerator(queryGenerator, mutationGenerator);
|
|
1289
|
+
return {
|
|
1290
|
+
output,
|
|
1291
|
+
client: resolveContractClient({
|
|
1292
|
+
client,
|
|
1293
|
+
plugins: useConfig().plugins
|
|
1294
|
+
}),
|
|
1295
|
+
queryKey,
|
|
1296
|
+
query: resolveQueryConfig(query, { importPath: "swr" }),
|
|
1297
|
+
mutationKey,
|
|
1298
|
+
mutation: resolveMutationConfig(mutation, { importPath: "swr/mutation" }),
|
|
1299
|
+
group: createGroupConfig(group) ?? void 0,
|
|
1300
|
+
exclude,
|
|
1301
|
+
include,
|
|
1302
|
+
override,
|
|
1303
|
+
resolver
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1298
1306
|
});
|
|
1299
1307
|
//#endregion
|
|
1300
1308
|
export { pluginSwr as default, pluginSwr, pluginSwrName, resolverSwr };
|