@kubb/plugin-swr 5.5.0 → 5.5.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 +76 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +76 -7
- package/dist/index.js.map +1 -1
- package/docs/overview.md +1 -1
- package/kubb-extension.json +1 -0
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,7 @@ let kubb_kit = require("kubb/kit");
|
|
|
28
28
|
let node_path = require("node:path");
|
|
29
29
|
node_path = __toESM(node_path, 1);
|
|
30
30
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
31
|
+
let _kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
31
32
|
let kubb_jsx = require("kubb/jsx");
|
|
32
33
|
let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
33
34
|
//#region ../../internals/shared/src/operation.ts
|
|
@@ -339,7 +340,74 @@ var compatibility = {
|
|
|
339
340
|
};
|
|
340
341
|
//#endregion
|
|
341
342
|
//#region package.json
|
|
342
|
-
var version = "5.5.
|
|
343
|
+
var version = "5.5.2";
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region ../../internals/client/src/resolveOperationTypes.ts
|
|
346
|
+
/**
|
|
347
|
+
* A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
|
|
348
|
+
* exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
|
|
349
|
+
*/
|
|
350
|
+
function toZodTypeResolver(resolver) {
|
|
351
|
+
const type = (name) => resolver.schema.type(name);
|
|
352
|
+
return {
|
|
353
|
+
...resolver,
|
|
354
|
+
file: resolver.file.bind(resolver),
|
|
355
|
+
param: {
|
|
356
|
+
name: (node, p) => type(resolver.param.name(node, p)),
|
|
357
|
+
path: (node, p) => type(resolver.param.path(node, p)),
|
|
358
|
+
query: (node, p) => type(resolver.param.query(node, p)),
|
|
359
|
+
headers: (node, p) => type(resolver.param.headers(node, p))
|
|
360
|
+
},
|
|
361
|
+
response: {
|
|
362
|
+
body: (node) => type(resolver.response.body(node)),
|
|
363
|
+
status: (node, statusCode) => type(resolver.response.status(node, statusCode)),
|
|
364
|
+
response: (node) => type(resolver.response.response(node)),
|
|
365
|
+
responses: (node) => type(resolver.response.responses(node)),
|
|
366
|
+
options: (node) => resolver.response.options(node)
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Picks the plugin generated clients, query hooks, and MCP handlers take their operation types from.
|
|
372
|
+
*
|
|
373
|
+
* `pluginZod({ inferred: 'codec' })` wins, so a codec param takes its domain value. Otherwise `plugin-ts`
|
|
374
|
+
* wins when it is in the pipeline, and without it any `pluginZod({ inferred })`. Throws
|
|
375
|
+
* `KUBB_MISSING_DEPENDENCY` for `pluginName` when neither is available.
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* ```ts
|
|
379
|
+
* const types = resolveOperationTypes(ctx.driver, ctx.plugin.name)
|
|
380
|
+
* types.response.options(node) // 'GetPetByIdOptions', or 'GetPetByIdOptionsSchemaType' from zod
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
383
|
+
function resolveOperationTypes(driver, pluginName) {
|
|
384
|
+
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
385
|
+
const pluginZod = driver.getPlugin(_kubb_plugin_zod.pluginZodName);
|
|
386
|
+
if (pluginTs && pluginZod?.options?.inferred !== "codec") {
|
|
387
|
+
const resolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
388
|
+
return {
|
|
389
|
+
response: resolver.response,
|
|
390
|
+
resolver,
|
|
391
|
+
output: pluginTs.options?.output,
|
|
392
|
+
group: pluginTs.options?.group ?? void 0
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
if (!pluginZod?.options?.inferred) throw new kubb_kit.Diagnostics.Error({
|
|
396
|
+
code: kubb_kit.Diagnostics.code.missingDependency,
|
|
397
|
+
severity: "error",
|
|
398
|
+
message: `Plugin "${pluginName}" has no source for operation types.`,
|
|
399
|
+
help: `Add \`pluginTs()\` before "${pluginName}", or add \`pluginZod({ inferred: true })\`.`,
|
|
400
|
+
location: { kind: "config" },
|
|
401
|
+
plugin: pluginName
|
|
402
|
+
});
|
|
403
|
+
const resolver = toZodTypeResolver(driver.getResolver(_kubb_plugin_zod.pluginZodName));
|
|
404
|
+
return {
|
|
405
|
+
response: resolver.response,
|
|
406
|
+
resolver,
|
|
407
|
+
output: pluginZod.options.output,
|
|
408
|
+
group: pluginZod.options.group ?? void 0
|
|
409
|
+
};
|
|
410
|
+
}
|
|
343
411
|
//#endregion
|
|
344
412
|
//#region ../../internals/client/src/resolveClient.ts
|
|
345
413
|
/**
|
|
@@ -514,13 +582,14 @@ function resolveClientOperation(options) {
|
|
|
514
582
|
//#endregion
|
|
515
583
|
//#region ../../internals/tanstack-query/src/components/HookFile.tsx
|
|
516
584
|
/**
|
|
517
|
-
* Resolves what every TanStack hook file shares: its file, the
|
|
585
|
+
* Resolves what every TanStack hook file shares: its file, the operation types file and names (`@kubb/plugin-ts`, or
|
|
586
|
+
* `pluginZod({ inferred: 'codec' })`), banner and footer.
|
|
518
587
|
*/
|
|
519
588
|
function resolveHookFile(node, ctx, options) {
|
|
520
589
|
const { name, output, group, contractOp, keyTypeName, extraTypeNames = [] } = options;
|
|
521
590
|
const { config, root, resolver } = ctx;
|
|
522
|
-
const
|
|
523
|
-
const tsResolver =
|
|
591
|
+
const types = resolveOperationTypes(ctx.driver, resolver.pluginName);
|
|
592
|
+
const tsResolver = types.resolver;
|
|
524
593
|
const file = resolver.file({
|
|
525
594
|
...operationFileEntry(node, name),
|
|
526
595
|
root,
|
|
@@ -532,8 +601,8 @@ function resolveHookFile(node, ctx, options) {
|
|
|
532
601
|
node,
|
|
533
602
|
resolver: tsResolver,
|
|
534
603
|
root,
|
|
535
|
-
output:
|
|
536
|
-
group:
|
|
604
|
+
output: types.output ?? output,
|
|
605
|
+
group: types.group
|
|
537
606
|
});
|
|
538
607
|
const importedTypeNames = [
|
|
539
608
|
tsResolver.response.options(node),
|
|
@@ -1353,7 +1422,7 @@ const pluginSwr = (0, kubb_kit.defineExtension)({
|
|
|
1353
1422
|
version,
|
|
1354
1423
|
compatibility
|
|
1355
1424
|
},
|
|
1356
|
-
dependencies: { [_kubb_plugin_ts.pluginTsName]: {} },
|
|
1425
|
+
dependencies: { [_kubb_plugin_ts.pluginTsName]: { optional: true } },
|
|
1357
1426
|
setup(options) {
|
|
1358
1427
|
const { output = {
|
|
1359
1428
|
path: "hooks",
|