@kubb/plugin-react-query 5.7.0-canary.20261025T193222 → 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 +313 -83
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -17
- package/dist/index.d.ts +1 -17
- package/dist/index.js +312 -82
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
|
|
5
|
+
// \0rolldown/runtime.js
|
|
6
6
|
var __create = Object.create;
|
|
7
7
|
var __defProp = Object.defineProperty;
|
|
8
8
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -23,7 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
value: mod,
|
|
24
24
|
enumerable: true
|
|
25
25
|
}) : target, mod));
|
|
26
|
-
//#endregion
|
|
27
26
|
let kubb_kit = require("kubb/kit");
|
|
28
27
|
let node_path = require("node:path");
|
|
29
28
|
node_path = __toESM(node_path, 1);
|
|
@@ -33,7 +32,7 @@ let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
|
33
32
|
let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
34
33
|
let node_fs = require("node:fs");
|
|
35
34
|
node_fs = __toESM(node_fs, 1);
|
|
36
|
-
|
|
35
|
+
// ../../internals/shared/src/operation.ts
|
|
37
36
|
/**
|
|
38
37
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
39
38
|
* `resolver.file`: a file named `name`, tagged by the operation's first
|
|
@@ -102,6 +101,24 @@ function getContentTypeInfo(node) {
|
|
|
102
101
|
function getResponseContentTypeInfo(node) {
|
|
103
102
|
return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
|
|
104
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Reads the single base content type of an operation's primary success response, lowercased and
|
|
106
|
+
* stripped of any `; charset=...` suffix. Returns `undefined` when the response declares zero or
|
|
107
|
+
* more than one content type, since neither case has a single type to act on.
|
|
108
|
+
*/
|
|
109
|
+
function getPrimarySuccessContentType(node) {
|
|
110
|
+
const contentTypes = getPrimarySuccessResponse(node)?.content?.map((entry) => entry.contentType) ?? [];
|
|
111
|
+
if (contentTypes.length !== 1) return void 0;
|
|
112
|
+
return contentTypes[0].split(";")[0].trim().toLowerCase();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Whether an operation streams its primary success response as Server-Sent Events
|
|
116
|
+
* (`text/event-stream`). The client generator uses this to return a typed event stream instead of a
|
|
117
|
+
* one-shot `RequestResult`.
|
|
118
|
+
*/
|
|
119
|
+
function isEventStream(node) {
|
|
120
|
+
return getPrimarySuccessContentType(node) === "text/event-stream";
|
|
121
|
+
}
|
|
105
122
|
const requestConfigBaseType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
|
|
106
123
|
function buildRequestConfigType(node) {
|
|
107
124
|
const request = getContentTypeInfo(node);
|
|
@@ -193,6 +210,22 @@ function getOperationParameters(node) {
|
|
|
193
210
|
operationParameterGroupsByNode.set(node, groups);
|
|
194
211
|
return groups;
|
|
195
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Builds the combined `{ body, path, query, headers }` options object schema for an operation,
|
|
215
|
+
* referencing the already-resolved body and grouped param names. Shared by `@kubb/plugin-ts`'s
|
|
216
|
+
* `Options` type and `@kubb/plugin-zod`'s inferred options schema, so both printers emit the same
|
|
217
|
+
* shape from the same inputs. `primitive: 'object'` is a no-op for the TS printer and tells the Zod
|
|
218
|
+
* printer to emit `z.object(…)` rather than a record.
|
|
219
|
+
*/
|
|
220
|
+
function hasRequestContentTypeChoice(node) {
|
|
221
|
+
return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Casts a call argument to the client's parameter type; a `'plain'` client is non-generic.
|
|
225
|
+
*/
|
|
226
|
+
function castToClientOptions(callArg, clientName, returnType = "full") {
|
|
227
|
+
return `${callArg} as Parameters<typeof ${clientName}${returnType === "plain" ? "" : "<true>"}>[0]`;
|
|
228
|
+
}
|
|
196
229
|
function getStatusCodeNumber(statusCode) {
|
|
197
230
|
const code = Number(statusCode);
|
|
198
231
|
return Number.isNaN(code) ? null : code;
|
|
@@ -255,8 +288,7 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
255
288
|
byResolver.set(cacheKey, result);
|
|
256
289
|
return result;
|
|
257
290
|
}
|
|
258
|
-
|
|
259
|
-
//#region ../../internals/utils/src/casing.ts
|
|
291
|
+
// ../../internals/utils/src/casing.ts
|
|
260
292
|
/**
|
|
261
293
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
262
294
|
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
@@ -303,8 +335,146 @@ function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
|
303
335
|
function capitalize(text) {
|
|
304
336
|
return `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
|
|
305
337
|
}
|
|
306
|
-
|
|
307
|
-
|
|
338
|
+
// ../../internals/utils/src/reserved.ts
|
|
339
|
+
/**
|
|
340
|
+
* JavaScript and Java reserved words.
|
|
341
|
+
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
342
|
+
*/
|
|
343
|
+
const reservedWords = /* @__PURE__ */ new Set([
|
|
344
|
+
"abstract",
|
|
345
|
+
"arguments",
|
|
346
|
+
"await",
|
|
347
|
+
"boolean",
|
|
348
|
+
"break",
|
|
349
|
+
"byte",
|
|
350
|
+
"case",
|
|
351
|
+
"catch",
|
|
352
|
+
"char",
|
|
353
|
+
"class",
|
|
354
|
+
"const",
|
|
355
|
+
"continue",
|
|
356
|
+
"debugger",
|
|
357
|
+
"default",
|
|
358
|
+
"delete",
|
|
359
|
+
"do",
|
|
360
|
+
"double",
|
|
361
|
+
"else",
|
|
362
|
+
"enum",
|
|
363
|
+
"eval",
|
|
364
|
+
"export",
|
|
365
|
+
"extends",
|
|
366
|
+
"false",
|
|
367
|
+
"final",
|
|
368
|
+
"finally",
|
|
369
|
+
"float",
|
|
370
|
+
"for",
|
|
371
|
+
"function",
|
|
372
|
+
"goto",
|
|
373
|
+
"if",
|
|
374
|
+
"implements",
|
|
375
|
+
"import",
|
|
376
|
+
"in",
|
|
377
|
+
"instanceof",
|
|
378
|
+
"int",
|
|
379
|
+
"interface",
|
|
380
|
+
"let",
|
|
381
|
+
"long",
|
|
382
|
+
"native",
|
|
383
|
+
"new",
|
|
384
|
+
"null",
|
|
385
|
+
"package",
|
|
386
|
+
"private",
|
|
387
|
+
"protected",
|
|
388
|
+
"public",
|
|
389
|
+
"return",
|
|
390
|
+
"short",
|
|
391
|
+
"static",
|
|
392
|
+
"super",
|
|
393
|
+
"switch",
|
|
394
|
+
"synchronized",
|
|
395
|
+
"this",
|
|
396
|
+
"throw",
|
|
397
|
+
"throws",
|
|
398
|
+
"transient",
|
|
399
|
+
"true",
|
|
400
|
+
"try",
|
|
401
|
+
"typeof",
|
|
402
|
+
"var",
|
|
403
|
+
"void",
|
|
404
|
+
"volatile",
|
|
405
|
+
"while",
|
|
406
|
+
"with",
|
|
407
|
+
"yield",
|
|
408
|
+
"Array",
|
|
409
|
+
"Date",
|
|
410
|
+
"hasOwnProperty",
|
|
411
|
+
"Infinity",
|
|
412
|
+
"isFinite",
|
|
413
|
+
"isNaN",
|
|
414
|
+
"isPrototypeOf",
|
|
415
|
+
"length",
|
|
416
|
+
"Math",
|
|
417
|
+
"name",
|
|
418
|
+
"NaN",
|
|
419
|
+
"Number",
|
|
420
|
+
"Object",
|
|
421
|
+
"prototype",
|
|
422
|
+
"String",
|
|
423
|
+
"toString",
|
|
424
|
+
"undefined",
|
|
425
|
+
"valueOf"
|
|
426
|
+
]);
|
|
427
|
+
/**
|
|
428
|
+
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* ```ts
|
|
432
|
+
* isValidVarName('status') // true
|
|
433
|
+
* isValidVarName('class') // false (reserved word)
|
|
434
|
+
* isValidVarName('42foo') // false (starts with digit)
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
function isValidVarName(name) {
|
|
438
|
+
if (!name || reservedWords.has(name)) return false;
|
|
439
|
+
return isIdentifier(name);
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Returns `name` when it's a syntactically valid JavaScript variable name,
|
|
443
|
+
* otherwise prefixes it with `_` so the result is a valid identifier.
|
|
444
|
+
*
|
|
445
|
+
* Useful for sanitizing OpenAPI schema names or operation IDs that start with
|
|
446
|
+
* a digit (e.g. `409`, `504AccountCancel`) before using them as exported
|
|
447
|
+
* variable, type, or function names.
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* ```ts
|
|
451
|
+
* ensureValidVarName('409') // '_409'
|
|
452
|
+
* ensureValidVarName('504AccountCancel') // '_504AccountCancel'
|
|
453
|
+
* ensureValidVarName('Pet') // 'Pet'
|
|
454
|
+
* ensureValidVarName('class') // '_class'
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
457
|
+
function ensureValidVarName(name) {
|
|
458
|
+
if (!name || isValidVarName(name)) return name;
|
|
459
|
+
return `_${name}`;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
|
|
463
|
+
*
|
|
464
|
+
* Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
|
|
465
|
+
* even though they are not valid variable names, so use this (not {@link isValidVarName}) when
|
|
466
|
+
* deciding whether an object key needs quoting.
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```ts
|
|
470
|
+
* isIdentifier('name') // true
|
|
471
|
+
* isIdentifier('x-total')// false
|
|
472
|
+
* ```
|
|
473
|
+
*/
|
|
474
|
+
function isIdentifier(name) {
|
|
475
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
476
|
+
}
|
|
477
|
+
// ../../internals/utils/src/strings.ts
|
|
308
478
|
/**
|
|
309
479
|
* Renders a dotted path or string array as an optional-chaining accessor expression rooted at
|
|
310
480
|
* `accessor`. Returns `null` for an empty path.
|
|
@@ -320,8 +490,29 @@ function getNestedAccessor(param, accessor) {
|
|
|
320
490
|
if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
|
|
321
491
|
return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
|
|
322
492
|
}
|
|
323
|
-
|
|
324
|
-
|
|
493
|
+
// ../../internals/shared/src/resolver.ts
|
|
494
|
+
function resolveOperationName(name) {
|
|
495
|
+
return ensureValidVarName(camelCase(name));
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Builds the allocation key for a declaration an operation owns. `scope` names which declaration
|
|
499
|
+
* it is, so two of them never share an allocation even when a custom resolver gives both the same
|
|
500
|
+
* name. Leave `scope` empty for the operation's own declaration.
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```ts
|
|
504
|
+
* resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })
|
|
505
|
+
* ```
|
|
506
|
+
*/
|
|
507
|
+
function operationKey(node, ...scope) {
|
|
508
|
+
return [
|
|
509
|
+
"operation",
|
|
510
|
+
node.method,
|
|
511
|
+
node.path,
|
|
512
|
+
...scope.map(String)
|
|
513
|
+
];
|
|
514
|
+
}
|
|
515
|
+
// ../../internals/shared/src/group.ts
|
|
325
516
|
/**
|
|
326
517
|
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
327
518
|
* shared default naming so every plugin groups output consistently:
|
|
@@ -351,17 +542,14 @@ function createGroupConfig(group) {
|
|
|
351
542
|
name: group.name ? group.name : defaultName
|
|
352
543
|
};
|
|
353
544
|
}
|
|
354
|
-
|
|
355
|
-
//#region kubb-extension.json
|
|
545
|
+
// kubb-extension.json
|
|
356
546
|
var compatibility = {
|
|
357
|
-
"kubb": ">=5.
|
|
547
|
+
"kubb": ">=5.14.6",
|
|
358
548
|
"node": ">=22.22"
|
|
359
549
|
};
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
//#endregion
|
|
364
|
-
//#region ../../internals/client/src/resolveOperationTypes.ts
|
|
550
|
+
// package.json
|
|
551
|
+
var version = "5.7.0";
|
|
552
|
+
// ../../internals/client/src/resolveOperationTypes.ts
|
|
365
553
|
/**
|
|
366
554
|
* A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
|
|
367
555
|
* exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
|
|
@@ -427,8 +615,7 @@ function resolveOperationTypes(driver, pluginName) {
|
|
|
427
615
|
group: pluginZod.options.group ?? void 0
|
|
428
616
|
};
|
|
429
617
|
}
|
|
430
|
-
|
|
431
|
-
//#region ../../internals/client/src/resolveClient.ts
|
|
618
|
+
// ../../internals/client/src/resolveClient.ts
|
|
432
619
|
/**
|
|
433
620
|
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
434
621
|
* operation, shared so the selection rules and diagnostics stay in one place.
|
|
@@ -538,8 +725,7 @@ function resolveContractClient(options) {
|
|
|
538
725
|
}
|
|
539
726
|
return resolved;
|
|
540
727
|
}
|
|
541
|
-
|
|
542
|
-
//#region ../../internals/client/src/resolveClientOperation.ts
|
|
728
|
+
// ../../internals/client/src/resolveClientOperation.ts
|
|
543
729
|
function isRelativeImport(importPath) {
|
|
544
730
|
return importPath.startsWith(".");
|
|
545
731
|
}
|
|
@@ -586,8 +772,12 @@ function resolveClientOperation(options) {
|
|
|
586
772
|
group: operationOptions.group ?? void 0
|
|
587
773
|
});
|
|
588
774
|
const { importPath } = operationOptions;
|
|
775
|
+
const name = resolver.name(node.operationId);
|
|
589
776
|
return {
|
|
590
|
-
name: resolver.
|
|
777
|
+
name: resolver.resolveName({
|
|
778
|
+
key: operationKey(node),
|
|
779
|
+
name
|
|
780
|
+
}),
|
|
591
781
|
path: file.path,
|
|
592
782
|
clientPath: importPath === void 0 ? node_path.default.resolve(root, ".kubb/client.ts") : resolveImportPath({
|
|
593
783
|
importPath,
|
|
@@ -598,8 +788,7 @@ function resolveClientOperation(options) {
|
|
|
598
788
|
};
|
|
599
789
|
});
|
|
600
790
|
}
|
|
601
|
-
|
|
602
|
-
//#region ../../internals/tanstack-query/src/components/HookFile.tsx
|
|
791
|
+
// ../../internals/tanstack-query/src/components/HookFile.tsx
|
|
603
792
|
/**
|
|
604
793
|
* Resolves what every TanStack hook file shares: its file, the operation types file and names (`@kubb/plugin-ts`, or
|
|
605
794
|
* `pluginZod({ inferred: 'codec' })`), banner and footer.
|
|
@@ -688,8 +877,7 @@ function HookFile({ hook, imports, children }) {
|
|
|
688
877
|
]
|
|
689
878
|
});
|
|
690
879
|
}
|
|
691
|
-
|
|
692
|
-
//#region ../../internals/tanstack-query/src/utils.ts
|
|
880
|
+
// ../../internals/tanstack-query/src/utils.ts
|
|
693
881
|
/**
|
|
694
882
|
* The grouped request options, ordered for both the destructured signature and the
|
|
695
883
|
* call passed to the underlying client.
|
|
@@ -715,7 +903,7 @@ function maybeValueOrGetter(type) {
|
|
|
715
903
|
* `MaybeRefOrGetter` per group.
|
|
716
904
|
*/
|
|
717
905
|
function buildGroupedRequestParam(node, options) {
|
|
718
|
-
const { resolver, keys = requestGroupOrder, memberTypeWrapper } = options;
|
|
906
|
+
const { resolver, keys = requestGroupOrder, memberTypeWrapper, withContentType = false } = options;
|
|
719
907
|
const { groups, hasRequiredPath, hasRequiredQuery, hasRequiredHeader } = getRequestGroupOptionality(node);
|
|
720
908
|
const names = keys.filter((key) => groups[key]);
|
|
721
909
|
if (names.length === 0) return null;
|
|
@@ -727,6 +915,11 @@ function buildGroupedRequestParam(node, options) {
|
|
|
727
915
|
};
|
|
728
916
|
const isOptional = names.every((name) => !requiredByGroup[name]);
|
|
729
917
|
const optionsName = resolver.response.options(node);
|
|
918
|
+
if (withContentType && hasRequestContentTypeChoice(node)) return (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
919
|
+
name: "variables",
|
|
920
|
+
type: optionsName,
|
|
921
|
+
optional: false
|
|
922
|
+
});
|
|
730
923
|
const omittedKeys = requestGroupOrder.filter((key) => !keys.includes(key));
|
|
731
924
|
const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
|
|
732
925
|
if (memberTypeWrapper) {
|
|
@@ -784,14 +977,17 @@ function buildQueryOptionsParams(node, options) {
|
|
|
784
977
|
* ```
|
|
785
978
|
*/
|
|
786
979
|
function buildClientCall(node, options) {
|
|
787
|
-
const { clientName, signal = false, unwrapName } = options;
|
|
980
|
+
const { clientName, signal = false, unwrapName, withContentType = false, returnType = "full" } = options;
|
|
788
981
|
const { groups } = getRequestGroupOptionality(node);
|
|
789
|
-
|
|
982
|
+
const names = requestGroupOrder.filter((key) => groups[key]);
|
|
983
|
+
const args = [
|
|
790
984
|
"...config",
|
|
791
|
-
...
|
|
985
|
+
...withContentType && hasRequestContentTypeChoice(node) ? ["...variables"] : names.map((name) => unwrapName ? `${name}: ${unwrapName(name)}` : name),
|
|
792
986
|
signal ? "signal: config.signal ?? signal" : null,
|
|
793
987
|
"throwOnError: true"
|
|
794
|
-
].filter((part) => part !== null)
|
|
988
|
+
].filter((part) => part !== null);
|
|
989
|
+
if (withContentType && hasRequestContentTypeChoice(node)) return `${clientName}(${castToClientOptions(`{ ${args.join(", ")} }`, clientName, returnType)})`;
|
|
990
|
+
return `${clientName}({ ${args.join(", ")} })`;
|
|
795
991
|
}
|
|
796
992
|
/**
|
|
797
993
|
* Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
|
|
@@ -887,9 +1083,14 @@ function resolveMutationConfig(mutation, options) {
|
|
|
887
1083
|
/**
|
|
888
1084
|
* Classifies an operation as a query or a mutation from the resolved `query` / `mutation` method lists.
|
|
889
1085
|
* Disabled query and mutation configs do not claim operations, and a method already claimed by an
|
|
890
|
-
* enabled query config never counts as a mutation.
|
|
1086
|
+
* enabled query config never counts as a mutation. Event streams are consumed through the client
|
|
1087
|
+
* directly, so they do not generate query or mutation hooks.
|
|
891
1088
|
*/
|
|
892
1089
|
function classifyOperation(node, { query, mutation }) {
|
|
1090
|
+
if (isEventStream(node)) return {
|
|
1091
|
+
isQuery: false,
|
|
1092
|
+
isMutation: false
|
|
1093
|
+
};
|
|
893
1094
|
const isQuery = !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
894
1095
|
const queryMethods = new Set(query ? query.methods : []);
|
|
895
1096
|
return {
|
|
@@ -1042,8 +1243,7 @@ function buildResolvedRequestParams(node) {
|
|
|
1042
1243
|
if (names.length === 0) return null;
|
|
1043
1244
|
return `{ ${names.map((name) => `${name}: typeof ${name} === 'function' ? ${name}() : ${name}`).join(", ")} }`;
|
|
1044
1245
|
}
|
|
1045
|
-
|
|
1046
|
-
//#region ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
|
|
1246
|
+
// ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
|
|
1047
1247
|
const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1048
1248
|
const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1049
1249
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, returnType = "full" }) {
|
|
@@ -1119,8 +1319,7 @@ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${que
|
|
|
1119
1319
|
})
|
|
1120
1320
|
});
|
|
1121
1321
|
}
|
|
1122
|
-
|
|
1123
|
-
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
1322
|
+
// ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
1124
1323
|
const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1125
1324
|
/**
|
|
1126
1325
|
* Default `mutationKey` builder. Call it from a custom builder to extend the default key.
|
|
@@ -1167,8 +1366,7 @@ function MutationKey({ name, node, transformer, typeName }) {
|
|
|
1167
1366
|
})
|
|
1168
1367
|
})] });
|
|
1169
1368
|
}
|
|
1170
|
-
|
|
1171
|
-
//#region ../../internals/tanstack-query/src/resolver.ts
|
|
1369
|
+
// ../../internals/tanstack-query/src/resolver.ts
|
|
1172
1370
|
/**
|
|
1173
1371
|
* Builds the shared query namespace for a variant. Spread the result into
|
|
1174
1372
|
* `createResolver` once per variant the plugin supports.
|
|
@@ -1184,19 +1382,39 @@ function MutationKey({ name, node, transformer, typeName }) {
|
|
|
1184
1382
|
function createQueryResolver(variant = "") {
|
|
1185
1383
|
return {
|
|
1186
1384
|
name(node) {
|
|
1187
|
-
|
|
1385
|
+
const name = `use${capitalize(this.name(node.operationId))}${variant}`;
|
|
1386
|
+
return this.resolveName({
|
|
1387
|
+
key: operationKey(node, "query", variant, "name"),
|
|
1388
|
+
name
|
|
1389
|
+
});
|
|
1188
1390
|
},
|
|
1189
1391
|
optionsName(node) {
|
|
1190
|
-
|
|
1392
|
+
const name = `${this.name(node.operationId)}${variant}QueryOptions`;
|
|
1393
|
+
return this.resolveName({
|
|
1394
|
+
key: operationKey(node, "query", variant, "optionsName"),
|
|
1395
|
+
name
|
|
1396
|
+
});
|
|
1191
1397
|
},
|
|
1192
1398
|
keyName(node) {
|
|
1193
|
-
|
|
1399
|
+
const name = `${this.name(node.operationId)}${variant}QueryKey`;
|
|
1400
|
+
return this.resolveName({
|
|
1401
|
+
key: operationKey(node, "query", variant, "keyName"),
|
|
1402
|
+
name
|
|
1403
|
+
});
|
|
1194
1404
|
},
|
|
1195
1405
|
keyTypeName(node) {
|
|
1196
|
-
|
|
1406
|
+
const name = `${capitalize(this.name(node.operationId))}${variant}QueryKey`;
|
|
1407
|
+
return this.resolveName({
|
|
1408
|
+
key: operationKey(node, "query", variant, "keyTypeName"),
|
|
1409
|
+
name
|
|
1410
|
+
});
|
|
1197
1411
|
},
|
|
1198
1412
|
clientName(node) {
|
|
1199
|
-
|
|
1413
|
+
const name = `${this.name(node.operationId)}${variant}`;
|
|
1414
|
+
return this.resolveName({
|
|
1415
|
+
key: operationKey(node, "query", variant, "clientName"),
|
|
1416
|
+
name
|
|
1417
|
+
});
|
|
1200
1418
|
}
|
|
1201
1419
|
};
|
|
1202
1420
|
}
|
|
@@ -1213,15 +1431,22 @@ function createQueryResolver(variant = "") {
|
|
|
1213
1431
|
function createMutationResolver() {
|
|
1214
1432
|
return {
|
|
1215
1433
|
name(node) {
|
|
1216
|
-
|
|
1434
|
+
const name = `use${capitalize(this.name(node.operationId))}`;
|
|
1435
|
+
return this.resolveName({
|
|
1436
|
+
key: operationKey(node, "mutation", "name"),
|
|
1437
|
+
name
|
|
1438
|
+
});
|
|
1217
1439
|
},
|
|
1218
1440
|
keyName(node) {
|
|
1219
|
-
|
|
1441
|
+
const name = `${this.name(node.operationId)}MutationKey`;
|
|
1442
|
+
return this.resolveName({
|
|
1443
|
+
key: operationKey(node, "mutation", "keyName"),
|
|
1444
|
+
name
|
|
1445
|
+
});
|
|
1220
1446
|
}
|
|
1221
1447
|
};
|
|
1222
1448
|
}
|
|
1223
|
-
|
|
1224
|
-
//#region ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
1449
|
+
// ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
1225
1450
|
const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1226
1451
|
/**
|
|
1227
1452
|
* Default `queryKey` builder. Call it from a custom builder to extend the default key.
|
|
@@ -1279,8 +1504,7 @@ function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "qu
|
|
|
1279
1504
|
})
|
|
1280
1505
|
})] });
|
|
1281
1506
|
}
|
|
1282
|
-
|
|
1283
|
-
//#region src/generators/customHookOptionsFileGenerator.tsx
|
|
1507
|
+
// src/generators/customHookOptionsFileGenerator.tsx
|
|
1284
1508
|
/**
|
|
1285
1509
|
* Scaffolds the user-editable `useCustomHookOptions` file when
|
|
1286
1510
|
* `pluginReactQuery({ customOptions: { ... }, hooks: true })` is configured. The file is
|
|
@@ -1377,8 +1601,7 @@ const customHookOptionsFileGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1377
1601
|
});
|
|
1378
1602
|
}
|
|
1379
1603
|
});
|
|
1380
|
-
|
|
1381
|
-
//#region src/generators/hookOptionsGenerator.tsx
|
|
1604
|
+
// src/generators/hookOptionsGenerator.tsx
|
|
1382
1605
|
/**
|
|
1383
1606
|
* Emits the `HookOptions` type used by `customOptions`. Enabled when
|
|
1384
1607
|
* `pluginReactQuery({ customOptions: { ... } })`. The generated type lists
|
|
@@ -1537,8 +1760,7 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1537
1760
|
});
|
|
1538
1761
|
}
|
|
1539
1762
|
});
|
|
1540
|
-
|
|
1541
|
-
//#region src/components/Query.tsx
|
|
1763
|
+
// src/components/Query.tsx
|
|
1542
1764
|
const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1543
1765
|
const OBSERVER_OPTIONS_NAMES = {
|
|
1544
1766
|
infinite: {
|
|
@@ -1648,8 +1870,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1648
1870
|
})
|
|
1649
1871
|
});
|
|
1650
1872
|
}
|
|
1651
|
-
|
|
1652
|
-
//#region src/components/QueryOptions.tsx
|
|
1873
|
+
// src/components/QueryOptions.tsx
|
|
1653
1874
|
const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1654
1875
|
const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1655
1876
|
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, returnType = "full" }) {
|
|
@@ -1682,8 +1903,7 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, return
|
|
|
1682
1903
|
})
|
|
1683
1904
|
});
|
|
1684
1905
|
}
|
|
1685
|
-
|
|
1686
|
-
//#region src/generators/createQueryGenerator.tsx
|
|
1906
|
+
// src/generators/createQueryGenerator.tsx
|
|
1687
1907
|
const OBSERVER_IMPORTS = {
|
|
1688
1908
|
query: ["QueryObserverOptions", "UseQueryResult"],
|
|
1689
1909
|
suspenseQuery: ["UseSuspenseQueryOptions", "UseSuspenseQueryResult"],
|
|
@@ -1842,8 +2062,7 @@ function createQueryGenerator({ name, variant }) {
|
|
|
1842
2062
|
}
|
|
1843
2063
|
});
|
|
1844
2064
|
}
|
|
1845
|
-
|
|
1846
|
-
//#region src/generators/infiniteQueryGenerator.tsx
|
|
2065
|
+
// src/generators/infiniteQueryGenerator.tsx
|
|
1847
2066
|
/**
|
|
1848
2067
|
* Built-in generator for `useInfiniteQuery` hooks. Enabled when
|
|
1849
2068
|
* `pluginReactQuery({ infinite: { ... }, hooks: true })`. Emits one
|
|
@@ -1855,8 +2074,7 @@ const infiniteQueryGenerator = createQueryGenerator({
|
|
|
1855
2074
|
name: "react-infinite-query",
|
|
1856
2075
|
variant: "infiniteQuery"
|
|
1857
2076
|
});
|
|
1858
|
-
|
|
1859
|
-
//#region src/components/MutationOptions.tsx
|
|
2077
|
+
// src/components/MutationOptions.tsx
|
|
1860
2078
|
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1861
2079
|
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1862
2080
|
function buildMutationConfigParamsNode(node) {
|
|
@@ -1870,14 +2088,19 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName,
|
|
|
1870
2088
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1871
2089
|
const configParamsNode = buildMutationConfigParamsNode(node);
|
|
1872
2090
|
const paramsSignature = declarationPrinter$1.print(configParamsNode) ?? "";
|
|
1873
|
-
const groupedParam = buildGroupedRequestParam(node, {
|
|
2091
|
+
const groupedParam = buildGroupedRequestParam(node, {
|
|
2092
|
+
resolver: tsResolver,
|
|
2093
|
+
withContentType: true
|
|
2094
|
+
});
|
|
1874
2095
|
const hasMutationParams = groupedParam !== null;
|
|
1875
2096
|
const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
|
|
1876
2097
|
const TRequest = hasMutationParams ? tsResolver.response.options(node) : "undefined";
|
|
1877
2098
|
const argBindingStr = hasMutationParams ? callPrinter$1.print(groupedParamsNode) ?? "" : "_";
|
|
1878
2099
|
const mutationFnBody = buildCallResultBody(buildClientCall(node, {
|
|
1879
2100
|
clientName,
|
|
1880
|
-
signal: false
|
|
2101
|
+
signal: false,
|
|
2102
|
+
withContentType: true,
|
|
2103
|
+
returnType
|
|
1881
2104
|
}), { returnType });
|
|
1882
2105
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1883
2106
|
name,
|
|
@@ -1900,8 +2123,7 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName,
|
|
|
1900
2123
|
})
|
|
1901
2124
|
});
|
|
1902
2125
|
}
|
|
1903
|
-
|
|
1904
|
-
//#region src/components/Mutation.tsx
|
|
2126
|
+
// src/components/Mutation.tsx
|
|
1905
2127
|
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1906
2128
|
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1907
2129
|
function buildMutationParamsNode(node, options) {
|
|
@@ -1960,8 +2182,7 @@ function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName
|
|
|
1960
2182
|
})
|
|
1961
2183
|
});
|
|
1962
2184
|
}
|
|
1963
|
-
|
|
1964
|
-
//#region src/generators/mutationGenerator.tsx
|
|
2185
|
+
// src/generators/mutationGenerator.tsx
|
|
1965
2186
|
/**
|
|
1966
2187
|
* Built-in generator for `useMutation` hooks. Emits one `useFooMutation` hook
|
|
1967
2188
|
* per POST/PUT/DELETE operation (configurable via `mutation.methods`) plus
|
|
@@ -2054,8 +2275,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2054
2275
|
});
|
|
2055
2276
|
}
|
|
2056
2277
|
});
|
|
2057
|
-
|
|
2058
|
-
//#region src/generators/queryGenerator.tsx
|
|
2278
|
+
// src/generators/queryGenerator.tsx
|
|
2059
2279
|
/**
|
|
2060
2280
|
* Built-in generator for `useQuery` hooks. Emits one `useFooQuery` hook per
|
|
2061
2281
|
* GET and QUERY operation (configurable via `query.methods`) plus the matching
|
|
@@ -2065,8 +2285,7 @@ const queryGenerator = createQueryGenerator({
|
|
|
2065
2285
|
name: "react-query",
|
|
2066
2286
|
variant: "query"
|
|
2067
2287
|
});
|
|
2068
|
-
|
|
2069
|
-
//#region src/generators/suspenseInfiniteQueryGenerator.tsx
|
|
2288
|
+
// src/generators/suspenseInfiniteQueryGenerator.tsx
|
|
2070
2289
|
/**
|
|
2071
2290
|
* Built-in generator for `useSuspenseInfiniteQuery` hooks. Enabled when
|
|
2072
2291
|
* `suspense`, `infinite`, and `hooks` are all configured. Combines suspense
|
|
@@ -2077,8 +2296,7 @@ const suspenseInfiniteQueryGenerator = createQueryGenerator({
|
|
|
2077
2296
|
name: "react-suspense-infinite-query",
|
|
2078
2297
|
variant: "suspenseInfiniteQuery"
|
|
2079
2298
|
});
|
|
2080
|
-
|
|
2081
|
-
//#region src/generators/suspenseQueryGenerator.tsx
|
|
2299
|
+
// src/generators/suspenseQueryGenerator.tsx
|
|
2082
2300
|
/**
|
|
2083
2301
|
* Built-in generator for `useSuspenseQuery` hooks. Enabled when
|
|
2084
2302
|
* `pluginReactQuery({ suspense: {}, hooks: true })`. Emits one
|
|
@@ -2090,15 +2308,14 @@ const suspenseQueryGenerator = createQueryGenerator({
|
|
|
2090
2308
|
name: "react-suspense-query",
|
|
2091
2309
|
variant: "suspenseQuery"
|
|
2092
2310
|
});
|
|
2093
|
-
|
|
2094
|
-
//#region src/resolvers/resolverReactQuery.ts
|
|
2311
|
+
// src/resolvers/resolverReactQuery.ts
|
|
2095
2312
|
/**
|
|
2096
2313
|
* Default resolver used by `@kubb/plugin-react-query`. Decides the names and
|
|
2097
2314
|
* file paths for every generated TanStack Query hook (`useFoo`,
|
|
2098
2315
|
* `useFooSuspense`, `useFooInfinite`, ...) and its companion helpers
|
|
2099
2316
|
* (`fooQueryKey`, `fooQueryOptions`).
|
|
2100
2317
|
*
|
|
2101
|
-
* Functions
|
|
2318
|
+
* Functions use safe camelCase identifiers; hooks get the `use`
|
|
2102
2319
|
* prefix; suspense and infinite variants are suffixed with `Suspense`/`Infinite`.
|
|
2103
2320
|
*
|
|
2104
2321
|
* @example Resolve hook and helper names
|
|
@@ -2113,6 +2330,7 @@ const suspenseQueryGenerator = createQueryGenerator({
|
|
|
2113
2330
|
*/
|
|
2114
2331
|
const resolverReactQuery = (0, kubb_kit.createResolver)({
|
|
2115
2332
|
pluginName: "plugin-react-query",
|
|
2333
|
+
name: resolveOperationName,
|
|
2116
2334
|
query: createQueryResolver(),
|
|
2117
2335
|
suspenseQuery: createQueryResolver("Suspense"),
|
|
2118
2336
|
infiniteQuery: createQueryResolver("Infinite"),
|
|
@@ -2120,23 +2338,36 @@ const resolverReactQuery = (0, kubb_kit.createResolver)({
|
|
|
2120
2338
|
mutation: {
|
|
2121
2339
|
...createMutationResolver(),
|
|
2122
2340
|
optionsName(node) {
|
|
2123
|
-
|
|
2341
|
+
const name = `${this.name(node.operationId)}MutationOptions`;
|
|
2342
|
+
return this.resolveName({
|
|
2343
|
+
key: operationKey(node, "mutation", "optionsName"),
|
|
2344
|
+
name
|
|
2345
|
+
});
|
|
2124
2346
|
},
|
|
2125
2347
|
typeName(node) {
|
|
2126
|
-
|
|
2348
|
+
const name = capitalize(this.name(node.operationId));
|
|
2349
|
+
return this.resolveName({
|
|
2350
|
+
key: operationKey(node, "mutation", "typeName"),
|
|
2351
|
+
name
|
|
2352
|
+
});
|
|
2127
2353
|
}
|
|
2128
2354
|
},
|
|
2129
2355
|
hook: {
|
|
2130
2356
|
optionsName() {
|
|
2131
|
-
return
|
|
2357
|
+
return this.resolveName({
|
|
2358
|
+
key: ["hook", "options"],
|
|
2359
|
+
name: "HookOptions"
|
|
2360
|
+
});
|
|
2132
2361
|
},
|
|
2133
2362
|
customOptionsName() {
|
|
2134
|
-
return
|
|
2363
|
+
return this.resolveName({
|
|
2364
|
+
key: ["hook", "custom-options"],
|
|
2365
|
+
name: "getCustomHookOptions"
|
|
2366
|
+
});
|
|
2135
2367
|
}
|
|
2136
2368
|
}
|
|
2137
2369
|
});
|
|
2138
|
-
|
|
2139
|
-
//#region src/plugin.ts
|
|
2370
|
+
// src/plugin.ts
|
|
2140
2371
|
/**
|
|
2141
2372
|
* Canonical plugin name for `@kubb/plugin-react-query`. Used for driver lookups
|
|
2142
2373
|
* and cross-plugin dependency references.
|
|
@@ -2210,7 +2441,6 @@ const pluginReactQuery = (0, kubb_kit.defineExtension)({
|
|
|
2210
2441
|
};
|
|
2211
2442
|
}
|
|
2212
2443
|
});
|
|
2213
|
-
//#endregion
|
|
2214
2444
|
exports.default = pluginReactQuery;
|
|
2215
2445
|
exports.definePageParam = definePageParam;
|
|
2216
2446
|
exports.mutationKeyTransformer = mutationKeyTransformer;
|