@kubb/plugin-swr 5.2.1 → 5.2.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/OVERVIEW.md ADDED
@@ -0,0 +1,16 @@
1
+ # SWR
2
+
3
+ Generates typed SWR hooks from your OpenAPI spec: `useSWR` for reads and `useSWRMutation` for writes.
4
+
5
+ The plugin ships no HTTP client. Each hook calls a function generated by a client plugin.
6
+
7
+ ## Setup
8
+
9
+ - Add `@kubb/plugin-ts` and a client plugin: `@kubb/plugin-fetch` or `@kubb/plugin-axios`.
10
+ - Install SWR v2 or higher in the app that uses the generated code.
11
+ - Configure validation on the client plugin, not here.
12
+
13
+ ## Options worth knowing
14
+
15
+ - `client` picks `fetch` or `axios` when both client plugins are registered. A single client is detected automatically.
16
+ - `query` and `mutation` set which HTTP methods become queries (`GET`) and mutations (`POST`, `PUT`, `PATCH`, `DELETE`), and where SWR is imported from (`swr` and `swr/mutation`). Set either to `false` to skip it.
package/dist/index.cjs CHANGED
@@ -335,6 +335,15 @@ function createGroupConfig(group) {
335
335
  };
336
336
  }
337
337
  //#endregion
338
+ //#region kubb-extension.json
339
+ var compatibility = {
340
+ "kubb": ">=5.8.0",
341
+ "node": ">=22"
342
+ };
343
+ //#endregion
344
+ //#region package.json
345
+ var version = "5.2.3";
346
+ //#endregion
338
347
  //#region ../../internals/client/src/resolveClient.ts
339
348
  /**
340
349
  * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
@@ -1297,41 +1306,39 @@ const pluginSwrName = "plugin-swr";
1297
1306
  * })
1298
1307
  * ```
1299
1308
  */
1300
- const pluginSwr = (0, kubb_kit.definePlugin)((options) => {
1301
- const { output = {
1302
- path: "hooks",
1303
- barrel: { type: "named" }
1304
- }, group, exclude = [], include, override = [], mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, client, resolver: userResolver, macros: userMacros } = options;
1305
- const selectedGenerators = [queryGenerator, mutationGenerator];
1306
- const groupConfig = createGroupConfig(group) ?? void 0;
1307
- return {
1309
+ const pluginSwr = (0, kubb_kit.definePlugin)({
1310
+ meta: {
1308
1311
  name: pluginSwrName,
1309
- options,
1310
- dependencies: [_kubb_plugin_ts.pluginTsName],
1311
- hooks: { "kubb:plugin:setup"(ctx) {
1312
- ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
1313
- const resolver = userResolver ? kubb_kit.Resolver.merge(resolverSwr, userResolver) : resolverSwr;
1314
- ctx.setOptions({
1315
- output,
1316
- client: resolveContractClient({
1317
- client,
1318
- plugins: ctx.config.plugins
1319
- }),
1320
- queryKey,
1321
- query: resolveQueryConfig(query, { importPath: "swr" }),
1322
- mutationKey,
1323
- mutation: resolveMutationConfig(mutation, { importPath: "swr/mutation" }),
1324
- group: groupConfig,
1325
- exclude,
1326
- include,
1327
- override,
1328
- resolver
1329
- });
1330
- ctx.setResolver(resolver);
1331
- if (userMacros?.length) ctx.setMacros(userMacros);
1332
- ctx.addGenerator(...selectedGenerators);
1333
- } }
1334
- };
1312
+ version,
1313
+ compatibility
1314
+ },
1315
+ dependencies: { [_kubb_plugin_ts.pluginTsName]: {} },
1316
+ setup(options) {
1317
+ const { output = {
1318
+ path: "hooks",
1319
+ barrel: { type: "named" }
1320
+ }, group, exclude = [], include, override = [], mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, client, resolver: userResolver, macros: userMacros } = options;
1321
+ const resolver = userResolver ? kubb_kit.Resolver.merge(resolverSwr, userResolver) : resolverSwr;
1322
+ (0, kubb_kit.setResolver)(resolver);
1323
+ if (userMacros?.length) (0, kubb_kit.setMacros)(userMacros);
1324
+ (0, kubb_kit.addGenerator)(queryGenerator, mutationGenerator);
1325
+ return {
1326
+ output,
1327
+ client: resolveContractClient({
1328
+ client,
1329
+ plugins: (0, kubb_kit.useConfig)().plugins
1330
+ }),
1331
+ queryKey,
1332
+ query: resolveQueryConfig(query, { importPath: "swr" }),
1333
+ mutationKey,
1334
+ mutation: resolveMutationConfig(mutation, { importPath: "swr/mutation" }),
1335
+ group: createGroupConfig(group) ?? void 0,
1336
+ exclude,
1337
+ include,
1338
+ override,
1339
+ resolver
1340
+ };
1341
+ }
1335
1342
  });
1336
1343
  //#endregion
1337
1344
  exports.default = pluginSwr;