@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.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Diagnostics, Resolver, Url, addGenerator, ast, createResolver, defineExtension, defineGenerator, setMacros, setResolver, useConfig } from "kubb/kit";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
4
|
+
import { pluginZodName } from "@kubb/plugin-zod";
|
|
4
5
|
import { File, Function, Type, jsxRenderer } from "kubb/jsx";
|
|
5
6
|
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
6
7
|
//#endregion
|
|
@@ -313,7 +314,74 @@ var compatibility = {
|
|
|
313
314
|
};
|
|
314
315
|
//#endregion
|
|
315
316
|
//#region package.json
|
|
316
|
-
var version = "5.5.
|
|
317
|
+
var version = "5.5.2";
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region ../../internals/client/src/resolveOperationTypes.ts
|
|
320
|
+
/**
|
|
321
|
+
* A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
|
|
322
|
+
* exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
|
|
323
|
+
*/
|
|
324
|
+
function toZodTypeResolver(resolver) {
|
|
325
|
+
const type = (name) => resolver.schema.type(name);
|
|
326
|
+
return {
|
|
327
|
+
...resolver,
|
|
328
|
+
file: resolver.file.bind(resolver),
|
|
329
|
+
param: {
|
|
330
|
+
name: (node, p) => type(resolver.param.name(node, p)),
|
|
331
|
+
path: (node, p) => type(resolver.param.path(node, p)),
|
|
332
|
+
query: (node, p) => type(resolver.param.query(node, p)),
|
|
333
|
+
headers: (node, p) => type(resolver.param.headers(node, p))
|
|
334
|
+
},
|
|
335
|
+
response: {
|
|
336
|
+
body: (node) => type(resolver.response.body(node)),
|
|
337
|
+
status: (node, statusCode) => type(resolver.response.status(node, statusCode)),
|
|
338
|
+
response: (node) => type(resolver.response.response(node)),
|
|
339
|
+
responses: (node) => type(resolver.response.responses(node)),
|
|
340
|
+
options: (node) => resolver.response.options(node)
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Picks the plugin generated clients, query hooks, and MCP handlers take their operation types from.
|
|
346
|
+
*
|
|
347
|
+
* `pluginZod({ inferred: 'codec' })` wins, so a codec param takes its domain value. Otherwise `plugin-ts`
|
|
348
|
+
* wins when it is in the pipeline, and without it any `pluginZod({ inferred })`. Throws
|
|
349
|
+
* `KUBB_MISSING_DEPENDENCY` for `pluginName` when neither is available.
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```ts
|
|
353
|
+
* const types = resolveOperationTypes(ctx.driver, ctx.plugin.name)
|
|
354
|
+
* types.response.options(node) // 'GetPetByIdOptions', or 'GetPetByIdOptionsSchemaType' from zod
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
function resolveOperationTypes(driver, pluginName) {
|
|
358
|
+
const pluginTs = driver.getPlugin(pluginTsName);
|
|
359
|
+
const pluginZod = driver.getPlugin(pluginZodName);
|
|
360
|
+
if (pluginTs && pluginZod?.options?.inferred !== "codec") {
|
|
361
|
+
const resolver = driver.getResolver(pluginTsName);
|
|
362
|
+
return {
|
|
363
|
+
response: resolver.response,
|
|
364
|
+
resolver,
|
|
365
|
+
output: pluginTs.options?.output,
|
|
366
|
+
group: pluginTs.options?.group ?? void 0
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
if (!pluginZod?.options?.inferred) throw new Diagnostics.Error({
|
|
370
|
+
code: Diagnostics.code.missingDependency,
|
|
371
|
+
severity: "error",
|
|
372
|
+
message: `Plugin "${pluginName}" has no source for operation types.`,
|
|
373
|
+
help: `Add \`pluginTs()\` before "${pluginName}", or add \`pluginZod({ inferred: true })\`.`,
|
|
374
|
+
location: { kind: "config" },
|
|
375
|
+
plugin: pluginName
|
|
376
|
+
});
|
|
377
|
+
const resolver = toZodTypeResolver(driver.getResolver(pluginZodName));
|
|
378
|
+
return {
|
|
379
|
+
response: resolver.response,
|
|
380
|
+
resolver,
|
|
381
|
+
output: pluginZod.options.output,
|
|
382
|
+
group: pluginZod.options.group ?? void 0
|
|
383
|
+
};
|
|
384
|
+
}
|
|
317
385
|
//#endregion
|
|
318
386
|
//#region ../../internals/client/src/resolveClient.ts
|
|
319
387
|
/**
|
|
@@ -488,13 +556,14 @@ function resolveClientOperation(options) {
|
|
|
488
556
|
//#endregion
|
|
489
557
|
//#region ../../internals/tanstack-query/src/components/HookFile.tsx
|
|
490
558
|
/**
|
|
491
|
-
* Resolves what every TanStack hook file shares: its file, the
|
|
559
|
+
* Resolves what every TanStack hook file shares: its file, the operation types file and names (`@kubb/plugin-ts`, or
|
|
560
|
+
* `pluginZod({ inferred: 'codec' })`), banner and footer.
|
|
492
561
|
*/
|
|
493
562
|
function resolveHookFile(node, ctx, options) {
|
|
494
563
|
const { name, output, group, contractOp, keyTypeName, extraTypeNames = [] } = options;
|
|
495
564
|
const { config, root, resolver } = ctx;
|
|
496
|
-
const
|
|
497
|
-
const tsResolver =
|
|
565
|
+
const types = resolveOperationTypes(ctx.driver, resolver.pluginName);
|
|
566
|
+
const tsResolver = types.resolver;
|
|
498
567
|
const file = resolver.file({
|
|
499
568
|
...operationFileEntry(node, name),
|
|
500
569
|
root,
|
|
@@ -506,8 +575,8 @@ function resolveHookFile(node, ctx, options) {
|
|
|
506
575
|
node,
|
|
507
576
|
resolver: tsResolver,
|
|
508
577
|
root,
|
|
509
|
-
output:
|
|
510
|
-
group:
|
|
578
|
+
output: types.output ?? output,
|
|
579
|
+
group: types.group
|
|
511
580
|
});
|
|
512
581
|
const importedTypeNames = [
|
|
513
582
|
tsResolver.response.options(node),
|
|
@@ -1327,7 +1396,7 @@ const pluginSwr = defineExtension({
|
|
|
1327
1396
|
version,
|
|
1328
1397
|
compatibility
|
|
1329
1398
|
},
|
|
1330
|
-
dependencies: { [pluginTsName]: {} },
|
|
1399
|
+
dependencies: { [pluginTsName]: { optional: true } },
|
|
1331
1400
|
setup(options) {
|
|
1332
1401
|
const { output = {
|
|
1333
1402
|
path: "hooks",
|