@kubb/plugin-swr 5.7.0-canary.20261029T093900 → 5.7.0
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 +73 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +15 -15
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -23,13 +23,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
value: mod,
|
|
24
24
|
enumerable: true
|
|
25
25
|
}) : target, mod));
|
|
26
|
-
let
|
|
26
|
+
let _kubb_kit = require("@kubb/kit");
|
|
27
27
|
let node_path = require("node:path");
|
|
28
28
|
node_path = __toESM(node_path, 1);
|
|
29
29
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
30
30
|
let _kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
31
|
-
let
|
|
32
|
-
let
|
|
31
|
+
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
32
|
+
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
33
33
|
// ../../internals/shared/src/operation.ts
|
|
34
34
|
/**
|
|
35
35
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
@@ -51,19 +51,19 @@ function operationFileEntry(node, name, extname = ".ts") {
|
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
|
-
* Resolves a dependency plugin's generated file for `node.operationId`, cached in `
|
|
55
|
-
*
|
|
54
|
+
* Resolves a dependency plugin's generated file for `node.operationId`, cached in `memo` (the
|
|
55
|
+
* build's `ctx.memo`) under the resolver's own plugin name and the operation. Several dependents reading the
|
|
56
56
|
* same dependency for the same operation in one pass (a query plugin's several hook generators, the
|
|
57
57
|
* MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.
|
|
58
58
|
*
|
|
59
59
|
* @example Cache `plugin-ts`'s file for the current operation
|
|
60
60
|
* ```ts
|
|
61
|
-
* const fileTs = resolveDependencyOperationFile({
|
|
61
|
+
* const fileTs = resolveDependencyOperationFile({ memo: ctx.memo, node, resolver: tsResolver, root, output })
|
|
62
62
|
* ```
|
|
63
63
|
*/
|
|
64
64
|
function resolveDependencyOperationFile(options) {
|
|
65
|
-
const {
|
|
66
|
-
return
|
|
65
|
+
const { memo, node, resolver, root, output, group } = options;
|
|
66
|
+
return memo(`${resolver.pluginName}:operationFile:${node.operationId}`, () => resolver.file({
|
|
67
67
|
...operationFileEntry(node, node.operationId),
|
|
68
68
|
root,
|
|
69
69
|
output,
|
|
@@ -73,7 +73,7 @@ function resolveDependencyOperationFile(options) {
|
|
|
73
73
|
function getOperationLink(node, link) {
|
|
74
74
|
if (!link) return null;
|
|
75
75
|
if (typeof link === "function") return link(node) ?? null;
|
|
76
|
-
return node.path ? `{@link ${
|
|
76
|
+
return node.path ? `{@link ${_kubb_kit.Url.toPath(node.path)}}` : null;
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
|
|
@@ -436,7 +436,7 @@ function isIdentifier(name) {
|
|
|
436
436
|
* The shared top-level `name` of the operation plugins, computed once per operation name and build.
|
|
437
437
|
*/
|
|
438
438
|
function resolveOperationName(name) {
|
|
439
|
-
return this.memo(`operation:${name}`, () => ensureValidVarName((0,
|
|
439
|
+
return this.memo(`operation:${name}`, () => ensureValidVarName((0, _kubb_kit.camelCase)(name)));
|
|
440
440
|
}
|
|
441
441
|
/**
|
|
442
442
|
* Builds the allocation key for a declaration an operation owns. `scope` names which declaration
|
|
@@ -479,7 +479,7 @@ function createGroupConfig(group) {
|
|
|
479
479
|
if (!group) return null;
|
|
480
480
|
const defaultName = (ctx) => {
|
|
481
481
|
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
482
|
-
return (0,
|
|
482
|
+
return (0, _kubb_kit.camelCase)(ctx.group);
|
|
483
483
|
};
|
|
484
484
|
return {
|
|
485
485
|
...group,
|
|
@@ -492,7 +492,7 @@ var compatibility = {
|
|
|
492
492
|
"node": ">=22.22"
|
|
493
493
|
};
|
|
494
494
|
// package.json
|
|
495
|
-
var version = "5.7.0
|
|
495
|
+
var version = "5.7.0";
|
|
496
496
|
// ../../internals/client/src/resolveOperationTypes.ts
|
|
497
497
|
/**
|
|
498
498
|
* A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
|
|
@@ -545,8 +545,8 @@ function resolveOperationTypes(driver, pluginName) {
|
|
|
545
545
|
group: pluginTs.options?.group ?? void 0
|
|
546
546
|
};
|
|
547
547
|
}
|
|
548
|
-
if (!pluginZod?.options?.inferred) throw new
|
|
549
|
-
code:
|
|
548
|
+
if (!pluginZod?.options?.inferred) throw new _kubb_kit.Diagnostics.Error({
|
|
549
|
+
code: _kubb_kit.Diagnostics.code.missingDependency,
|
|
550
550
|
severity: "error",
|
|
551
551
|
message: `Plugin "${pluginName}" has no source for operation types.`,
|
|
552
552
|
help: `Add \`pluginTs()\` before "${pluginName}", or add \`pluginZod({ inferred: true })\`.`,
|
|
@@ -614,7 +614,7 @@ function resolveClient(options) {
|
|
|
614
614
|
const pluginName = selectorToPlugin[client];
|
|
615
615
|
if (!has(pluginName)) return {
|
|
616
616
|
kind: "error",
|
|
617
|
-
code:
|
|
617
|
+
code: _kubb_kit.Diagnostics.code.missingDependency,
|
|
618
618
|
message: `\`client: '${client}'\` is set but \`@kubb/plugin-${client}\` is not registered in \`plugins\`.`,
|
|
619
619
|
help: `Add \`@kubb/plugin-${client}\` to \`plugins\`, or drop \`client\` to use a different client plugin.`
|
|
620
620
|
};
|
|
@@ -625,7 +625,7 @@ function resolveClient(options) {
|
|
|
625
625
|
}
|
|
626
626
|
if (client !== void 0) return {
|
|
627
627
|
kind: "error",
|
|
628
|
-
code:
|
|
628
|
+
code: _kubb_kit.Diagnostics.code.invalidPluginOptions,
|
|
629
629
|
message: `Option \`client\` is ${typeof client === "string" ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios', 'client'.`,
|
|
630
630
|
help: "Set `client` to one of those values, or drop it to use the registered client plugin."
|
|
631
631
|
};
|
|
@@ -636,13 +636,13 @@ function resolveClient(options) {
|
|
|
636
636
|
};
|
|
637
637
|
if (registered.length > 1) return {
|
|
638
638
|
kind: "error",
|
|
639
|
-
code:
|
|
639
|
+
code: _kubb_kit.Diagnostics.code.invalidPluginOptions,
|
|
640
640
|
message: `Multiple client plugins are registered (${registered.map((name) => `\`@kubb/${name}\``).join(", ")}) and \`client\` is not set.`,
|
|
641
641
|
help: "Set `client: 'fetch' | 'axios' | 'client'` to choose which client the hooks call, or register a single client plugin."
|
|
642
642
|
};
|
|
643
643
|
return {
|
|
644
644
|
kind: "error",
|
|
645
|
-
code:
|
|
645
|
+
code: _kubb_kit.Diagnostics.code.missingDependency,
|
|
646
646
|
message: "No client plugin is registered.",
|
|
647
647
|
help: "Add `@kubb/plugin-fetch`, `@kubb/plugin-axios`, or `@kubb/plugin-client` to `plugins` so the generated code has an HTTP client to call."
|
|
648
648
|
};
|
|
@@ -661,7 +661,7 @@ function resolveContractClient(options) {
|
|
|
661
661
|
});
|
|
662
662
|
if (resolved.kind === "error") {
|
|
663
663
|
const { code, message, help } = resolved;
|
|
664
|
-
throw new
|
|
664
|
+
throw new _kubb_kit.Diagnostics.Error({
|
|
665
665
|
code,
|
|
666
666
|
severity: "error",
|
|
667
667
|
message,
|
|
@@ -689,7 +689,7 @@ function resolveImportPath(options) {
|
|
|
689
689
|
* output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from.
|
|
690
690
|
* With plugin-client they come from the user's `importPath` module instead.
|
|
691
691
|
*
|
|
692
|
-
* The result is cached in the
|
|
692
|
+
* The result is cached in `memo` (the build's `ctx.memo`) under the client plugin's name and the operation,
|
|
693
693
|
* so several dependents reading the same client plugin for one operation in a single pass
|
|
694
694
|
* (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
|
|
695
695
|
* one computed result instead of each re-deriving the name and path.
|
|
@@ -699,9 +699,9 @@ function resolveImportPath(options) {
|
|
|
699
699
|
* and import path therefore match the `<op>` actually emitted, even when an `override` changes it.
|
|
700
700
|
*/
|
|
701
701
|
function resolveClientOperation(options) {
|
|
702
|
-
const { clientPlugin, driver, node, root, output,
|
|
702
|
+
const { clientPlugin, driver, node, root, output, memo } = options;
|
|
703
703
|
if (!clientPlugin) return null;
|
|
704
|
-
return
|
|
704
|
+
return memo(`${clientPlugin.pluginName}:clientOperation:${node.operationId}`, () => {
|
|
705
705
|
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
706
706
|
const pluginOptions = driver.getPlugin(clientPlugin.pluginName)?.options ?? {};
|
|
707
707
|
const { exclude, include, override } = pluginOptions;
|
|
@@ -752,7 +752,7 @@ function resolveHookFile(node, ctx, options) {
|
|
|
752
752
|
group: group ?? void 0
|
|
753
753
|
});
|
|
754
754
|
const fileTs = resolveDependencyOperationFile({
|
|
755
|
-
|
|
755
|
+
memo: ctx.memo,
|
|
756
756
|
node,
|
|
757
757
|
resolver: tsResolver,
|
|
758
758
|
root,
|
|
@@ -795,26 +795,26 @@ function resolveHookFile(node, ctx, options) {
|
|
|
795
795
|
*/
|
|
796
796
|
function HookFile({ hook, imports, children }) {
|
|
797
797
|
const { file, fileTs, contractOp, importedTypeNames, banner, footer } = hook;
|
|
798
|
-
return /* @__PURE__ */ (0,
|
|
798
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
799
799
|
baseName: file.baseName,
|
|
800
800
|
path: file.path,
|
|
801
801
|
meta: file.meta,
|
|
802
802
|
banner,
|
|
803
803
|
footer,
|
|
804
804
|
children: [
|
|
805
|
-
/* @__PURE__ */ (0,
|
|
805
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
806
806
|
name: [contractOp.name],
|
|
807
807
|
root: file.path,
|
|
808
808
|
path: contractOp.path
|
|
809
809
|
}),
|
|
810
|
-
/* @__PURE__ */ (0,
|
|
810
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
811
811
|
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
812
812
|
root: contractOp.clientPathIsFile ? file.path : void 0,
|
|
813
813
|
path: contractOp.clientPath,
|
|
814
814
|
isTypeOnly: true
|
|
815
815
|
}),
|
|
816
816
|
imports,
|
|
817
|
-
fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0,
|
|
817
|
+
fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
818
818
|
name: Array.from(new Set(importedTypeNames)),
|
|
819
819
|
root: file.path,
|
|
820
820
|
path: fileTs.path,
|
|
@@ -1071,7 +1071,7 @@ const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "decla
|
|
|
1071
1071
|
*/
|
|
1072
1072
|
const mutationKeyTransformer = ({ node }) => {
|
|
1073
1073
|
if (!node.path) return [];
|
|
1074
|
-
return [`{ url: '${
|
|
1074
|
+
return [`{ url: '${_kubb_kit.Url.toPath(node.path)}' }`];
|
|
1075
1075
|
};
|
|
1076
1076
|
function MutationKey({ name, node, transformer, typeName }) {
|
|
1077
1077
|
const paramsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: [] });
|
|
@@ -1081,23 +1081,23 @@ function MutationKey({ name, node, transformer, typeName }) {
|
|
|
1081
1081
|
casing: "camelcase",
|
|
1082
1082
|
variant: "mutation"
|
|
1083
1083
|
});
|
|
1084
|
-
return /* @__PURE__ */ (0,
|
|
1084
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1085
1085
|
name,
|
|
1086
1086
|
isExportable: true,
|
|
1087
1087
|
isIndexable: true,
|
|
1088
|
-
children: /* @__PURE__ */ (0,
|
|
1088
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
|
|
1089
1089
|
name,
|
|
1090
1090
|
export: true,
|
|
1091
1091
|
params: paramsSignature,
|
|
1092
1092
|
singleLine: true,
|
|
1093
1093
|
children: `[${keys.join(", ")}] as const`
|
|
1094
1094
|
})
|
|
1095
|
-
}), typeName && /* @__PURE__ */ (0,
|
|
1095
|
+
}), typeName && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1096
1096
|
name: typeName,
|
|
1097
1097
|
isExportable: true,
|
|
1098
1098
|
isIndexable: true,
|
|
1099
1099
|
isTypeOnly: true,
|
|
1100
|
-
children: /* @__PURE__ */ (0,
|
|
1100
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
|
|
1101
1101
|
export: true,
|
|
1102
1102
|
name: typeName,
|
|
1103
1103
|
children: `ReturnType<typeof ${name}>`
|
|
@@ -1193,7 +1193,7 @@ const queryKeyTransformer = ({ node, variant }) => {
|
|
|
1193
1193
|
if (!node.path) return [];
|
|
1194
1194
|
const { path, query } = getOperationParameters(node);
|
|
1195
1195
|
const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
|
|
1196
|
-
const urlFields = [`url: '${
|
|
1196
|
+
const urlFields = [`url: '${_kubb_kit.Url.toPath(node.path)}'`];
|
|
1197
1197
|
if (path.length > 0) urlFields.push("params: path");
|
|
1198
1198
|
if (isInfinite) urlFields.push("infinite: true");
|
|
1199
1199
|
const result = [`{ ${urlFields.join(", ")} }`];
|
|
@@ -1212,23 +1212,23 @@ function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "qu
|
|
|
1212
1212
|
casing: "camelcase",
|
|
1213
1213
|
variant
|
|
1214
1214
|
});
|
|
1215
|
-
return /* @__PURE__ */ (0,
|
|
1215
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1216
1216
|
name,
|
|
1217
1217
|
isExportable: true,
|
|
1218
1218
|
isIndexable: true,
|
|
1219
|
-
children: /* @__PURE__ */ (0,
|
|
1219
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
|
|
1220
1220
|
name,
|
|
1221
1221
|
export: true,
|
|
1222
1222
|
params: paramsSignature,
|
|
1223
1223
|
singleLine: true,
|
|
1224
1224
|
children: `[${keys.join(", ")}] as const`
|
|
1225
1225
|
})
|
|
1226
|
-
}), /* @__PURE__ */ (0,
|
|
1226
|
+
}), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1227
1227
|
name: typeName,
|
|
1228
1228
|
isExportable: exportType,
|
|
1229
1229
|
isIndexable: exportType,
|
|
1230
1230
|
isTypeOnly: true,
|
|
1231
|
-
children: /* @__PURE__ */ (0,
|
|
1231
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
|
|
1232
1232
|
name: typeName,
|
|
1233
1233
|
export: exportType,
|
|
1234
1234
|
children: `ReturnType<typeof ${name}>`
|
|
@@ -1279,21 +1279,21 @@ function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, muta
|
|
|
1279
1279
|
resolver: tsResolver
|
|
1280
1280
|
});
|
|
1281
1281
|
const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
|
|
1282
|
-
return /* @__PURE__ */ (0,
|
|
1282
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1283
1283
|
name: mutationArgTypeName,
|
|
1284
1284
|
isExportable: true,
|
|
1285
1285
|
isIndexable: true,
|
|
1286
1286
|
isTypeOnly: true,
|
|
1287
|
-
children: /* @__PURE__ */ (0,
|
|
1287
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
|
|
1288
1288
|
name: mutationArgTypeName,
|
|
1289
1289
|
export: true,
|
|
1290
1290
|
children: hasMutationParams ? argTypeBody : "never"
|
|
1291
1291
|
})
|
|
1292
|
-
}), /* @__PURE__ */ (0,
|
|
1292
|
+
}), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1293
1293
|
name,
|
|
1294
1294
|
isExportable: true,
|
|
1295
1295
|
isIndexable: true,
|
|
1296
|
-
children: /* @__PURE__ */ (0,
|
|
1296
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
|
|
1297
1297
|
name,
|
|
1298
1298
|
export: true,
|
|
1299
1299
|
params: paramsSignature,
|
|
@@ -1319,11 +1319,11 @@ function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, muta
|
|
|
1319
1319
|
* per POST/PUT/DELETE operation (configurable via `mutation.methods`) plus
|
|
1320
1320
|
* the matching `fooMutationKey` helper.
|
|
1321
1321
|
*/
|
|
1322
|
-
const mutationGenerator = (0,
|
|
1322
|
+
const mutationGenerator = (0, _kubb_kit.defineGenerator)({
|
|
1323
1323
|
name: "swr-mutation",
|
|
1324
|
-
renderer:
|
|
1324
|
+
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
1325
1325
|
operation(node, ctx) {
|
|
1326
|
-
if (!
|
|
1326
|
+
if (!_kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1327
1327
|
const { driver, resolver, root } = ctx;
|
|
1328
1328
|
const { output, query, mutation, client, group } = ctx.options;
|
|
1329
1329
|
const { isMutation } = classifyOperation(node, {
|
|
@@ -1338,7 +1338,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1338
1338
|
node,
|
|
1339
1339
|
root,
|
|
1340
1340
|
output,
|
|
1341
|
-
|
|
1341
|
+
memo: ctx.memo
|
|
1342
1342
|
});
|
|
1343
1343
|
if (!contractOp) return null;
|
|
1344
1344
|
const mutationHookName = resolver.mutation.name(node);
|
|
@@ -1351,24 +1351,24 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1351
1351
|
group,
|
|
1352
1352
|
contractOp
|
|
1353
1353
|
});
|
|
1354
|
-
return /* @__PURE__ */ (0,
|
|
1354
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(HookFile, {
|
|
1355
1355
|
hook,
|
|
1356
|
-
children: [/* @__PURE__ */ (0,
|
|
1356
|
+
children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(MutationKey, {
|
|
1357
1357
|
name: mutationKeyName,
|
|
1358
1358
|
typeName: mutationKeyTypeName,
|
|
1359
1359
|
node,
|
|
1360
1360
|
transformer: ctx.options.mutationKey
|
|
1361
|
-
}), mutation && /* @__PURE__ */ (0,
|
|
1362
|
-
/* @__PURE__ */ (0,
|
|
1361
|
+
}), mutation && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
|
|
1362
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1363
1363
|
name: "useSWRMutation",
|
|
1364
1364
|
path: importPath
|
|
1365
1365
|
}),
|
|
1366
|
-
/* @__PURE__ */ (0,
|
|
1366
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1367
1367
|
name: ["SWRMutationConfiguration"],
|
|
1368
1368
|
path: importPath,
|
|
1369
1369
|
isTypeOnly: true
|
|
1370
1370
|
}),
|
|
1371
|
-
/* @__PURE__ */ (0,
|
|
1371
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Mutation, {
|
|
1372
1372
|
name: mutationHookName,
|
|
1373
1373
|
clientName: contractOp.name,
|
|
1374
1374
|
mutationKeyName,
|
|
@@ -1406,11 +1406,11 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1406
1406
|
}`
|
|
1407
1407
|
});
|
|
1408
1408
|
const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
|
|
1409
|
-
return /* @__PURE__ */ (0,
|
|
1409
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1410
1410
|
name,
|
|
1411
1411
|
isExportable: true,
|
|
1412
1412
|
isIndexable: true,
|
|
1413
|
-
children: /* @__PURE__ */ (0,
|
|
1413
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
|
|
1414
1414
|
name,
|
|
1415
1415
|
export: true,
|
|
1416
1416
|
params: paramsSignature,
|
|
@@ -1445,11 +1445,11 @@ function QueryOptions({ name, clientName, node, tsResolver, returnType = "full"
|
|
|
1445
1445
|
clientName,
|
|
1446
1446
|
signal: false
|
|
1447
1447
|
}), { returnType });
|
|
1448
|
-
return /* @__PURE__ */ (0,
|
|
1448
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1449
1449
|
name,
|
|
1450
1450
|
isExportable: true,
|
|
1451
1451
|
isIndexable: true,
|
|
1452
|
-
children: /* @__PURE__ */ (0,
|
|
1452
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
|
|
1453
1453
|
name,
|
|
1454
1454
|
export: true,
|
|
1455
1455
|
params: paramsSignature,
|
|
@@ -1468,11 +1468,11 @@ function QueryOptions({ name, clientName, node, tsResolver, returnType = "full"
|
|
|
1468
1468
|
* Built-in generator for `useSWR` hooks. Emits one `useFoo` hook per read operation plus the
|
|
1469
1469
|
* matching `fooQueryKey` helper and `fooQueryOptions` factory.
|
|
1470
1470
|
*/
|
|
1471
|
-
const queryGenerator = (0,
|
|
1471
|
+
const queryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
1472
1472
|
name: "swr-query",
|
|
1473
|
-
renderer:
|
|
1473
|
+
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
1474
1474
|
operation(node, ctx) {
|
|
1475
|
-
if (!
|
|
1475
|
+
if (!_kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1476
1476
|
const { driver, resolver, root } = ctx;
|
|
1477
1477
|
const { output, query, mutation, client, group } = ctx.options;
|
|
1478
1478
|
const { isQuery } = classifyOperation(node, {
|
|
@@ -1487,7 +1487,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1487
1487
|
node,
|
|
1488
1488
|
root,
|
|
1489
1489
|
output,
|
|
1490
|
-
|
|
1490
|
+
memo: ctx.memo
|
|
1491
1491
|
});
|
|
1492
1492
|
if (!contractOp) return null;
|
|
1493
1493
|
const queryName = resolver.query.name(node);
|
|
@@ -1502,10 +1502,10 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1502
1502
|
keyTypeName: queryKeyTypeName
|
|
1503
1503
|
});
|
|
1504
1504
|
const { tsResolver } = hook;
|
|
1505
|
-
return /* @__PURE__ */ (0,
|
|
1505
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(HookFile, {
|
|
1506
1506
|
hook,
|
|
1507
1507
|
children: [
|
|
1508
|
-
/* @__PURE__ */ (0,
|
|
1508
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(QueryKey, {
|
|
1509
1509
|
name: queryKeyName,
|
|
1510
1510
|
typeName: queryKeyTypeName,
|
|
1511
1511
|
node,
|
|
@@ -1513,24 +1513,24 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1513
1513
|
transformer: ctx.options.queryKey,
|
|
1514
1514
|
variant: "query"
|
|
1515
1515
|
}),
|
|
1516
|
-
/* @__PURE__ */ (0,
|
|
1516
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(QueryOptions, {
|
|
1517
1517
|
name: queryOptionsName,
|
|
1518
1518
|
clientName: contractOp.name,
|
|
1519
1519
|
node,
|
|
1520
1520
|
tsResolver,
|
|
1521
1521
|
returnType: contractOp.returnType
|
|
1522
1522
|
}),
|
|
1523
|
-
query && /* @__PURE__ */ (0,
|
|
1524
|
-
/* @__PURE__ */ (0,
|
|
1523
|
+
query && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
|
|
1524
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1525
1525
|
name: "useSWR",
|
|
1526
1526
|
path: importPath
|
|
1527
1527
|
}),
|
|
1528
|
-
/* @__PURE__ */ (0,
|
|
1528
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1529
1529
|
name: ["SWRConfiguration"],
|
|
1530
1530
|
path: importPath,
|
|
1531
1531
|
isTypeOnly: true
|
|
1532
1532
|
}),
|
|
1533
|
-
/* @__PURE__ */ (0,
|
|
1533
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Query, {
|
|
1534
1534
|
name: queryName,
|
|
1535
1535
|
queryOptionsName,
|
|
1536
1536
|
queryKeyName,
|
|
@@ -1560,7 +1560,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1560
1560
|
* resolverSwr.mutation.name(operationNode) // 'useUpdatePet'
|
|
1561
1561
|
* ```
|
|
1562
1562
|
*/
|
|
1563
|
-
const resolverSwr = (0,
|
|
1563
|
+
const resolverSwr = (0, _kubb_kit.createResolver)({
|
|
1564
1564
|
pluginName: "plugin-swr",
|
|
1565
1565
|
name: resolveOperationName,
|
|
1566
1566
|
query: createQueryResolver(),
|
|
@@ -1609,7 +1609,7 @@ const pluginSwrName = "plugin-swr";
|
|
|
1609
1609
|
* })
|
|
1610
1610
|
* ```
|
|
1611
1611
|
*/
|
|
1612
|
-
const pluginSwr = (0,
|
|
1612
|
+
const pluginSwr = (0, _kubb_kit.defineExtension)({
|
|
1613
1613
|
kind: "plugin",
|
|
1614
1614
|
meta: {
|
|
1615
1615
|
name: pluginSwrName,
|
|
@@ -1622,16 +1622,16 @@ const pluginSwr = (0, kubb_kit.defineExtension)({
|
|
|
1622
1622
|
path: "hooks",
|
|
1623
1623
|
barrel: { type: "named" }
|
|
1624
1624
|
}, group, exclude = [], include, override = [], mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, client, resolver: userResolver, macros: userMacros } = options;
|
|
1625
|
-
const resolver = userResolver ?
|
|
1626
|
-
(0,
|
|
1627
|
-
if (userMacros?.length) (0,
|
|
1628
|
-
(0,
|
|
1625
|
+
const resolver = userResolver ? _kubb_kit.Resolver.merge(resolverSwr, userResolver) : resolverSwr;
|
|
1626
|
+
(0, _kubb_kit.setResolver)(resolver);
|
|
1627
|
+
if (userMacros?.length) (0, _kubb_kit.setMacros)(userMacros);
|
|
1628
|
+
(0, _kubb_kit.addGenerator)(queryGenerator, mutationGenerator);
|
|
1629
1629
|
return {
|
|
1630
1630
|
output,
|
|
1631
1631
|
client: resolveContractClient({
|
|
1632
1632
|
plugin: pluginSwrName,
|
|
1633
1633
|
client,
|
|
1634
|
-
plugins: (0,
|
|
1634
|
+
plugins: (0, _kubb_kit.useConfig)().plugins
|
|
1635
1635
|
}),
|
|
1636
1636
|
queryKey,
|
|
1637
1637
|
query: resolveQueryConfig(query, { importPath: "swr" }),
|