@kubb/plugin-react-query 5.0.0-beta.10 → 5.0.0-beta.22

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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import "./chunk--u3MIqq1.js";
2
- import { _ as mutationKeyTransformer, d as queryKeyTransformer, v as camelCase } from "./components-Dow6tde8.js";
3
- import { a as infiniteQueryGenerator, i as mutationGenerator, n as suspenseInfiniteQueryGenerator, o as hookOptionsGenerator, r as queryGenerator, s as customHookOptionsFileGenerator, t as suspenseQueryGenerator } from "./generators-yfZr_qfT.js";
2
+ import { _ as mutationKeyTransformer, d as queryKeyTransformer, v as camelCase } from "./components-BTwB9V-K.js";
3
+ import { a as infiniteQueryGenerator, i as mutationGenerator, n as suspenseInfiniteQueryGenerator, o as hookOptionsGenerator, r as queryGenerator, s as customHookOptionsFileGenerator, t as suspenseQueryGenerator } from "./generators-BZ_sX2lp.js";
4
4
  import path from "node:path";
5
5
  import { ast, definePlugin, defineResolver } from "@kubb/core";
6
6
  import { pluginClientName } from "@kubb/plugin-client";
package/extension.yaml CHANGED
@@ -56,7 +56,7 @@ options:
56
56
  type: "{ type: 'named' | 'all', nested?: boolean } | false"
57
57
  required: false
58
58
  default: "{ type: 'named' }"
59
- description: "Configure barrel file export strategy. Use `type` to control named vs. wildcard exports; set `nested: true` to generate hierarchical barrels in subdirectories."
59
+ description: 'Configure barrel file export strategy. Use `type` to control named vs. wildcard exports; set `nested: true` to generate hierarchical barrels in subdirectories.'
60
60
  examples:
61
61
  - name: all
62
62
  files:
@@ -70,6 +70,16 @@ options:
70
70
  code: |
71
71
  export { PetService } from './gen/petService.ts'
72
72
  twoslash: false
73
+ - name: nested
74
+ files:
75
+ - name: kubb.config.ts
76
+ lang: typescript
77
+ code: |
78
+ output: {
79
+ path: './gen',
80
+ barrel: { type: 'named', nested: true },
81
+ }
82
+ twoslash: false
73
83
  - name: 'false'
74
84
  files:
75
85
  - lang: typescript
@@ -88,6 +98,13 @@ options:
88
98
  required: false
89
99
  default: 'false'
90
100
  description: Whether Kubb overrides existing external files that can be generated if they already exist.
101
+ - name: contentType
102
+ type: "'application/json' | (string & {})"
103
+ required: false
104
+ description: |
105
+ Define which content type to use.
106
+
107
+ By default, Kubb uses the first JSON-valid media type.
91
108
  - name: group
92
109
  type: Group
93
110
  required: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-react-query",
3
- "version": "5.0.0-beta.10",
3
+ "version": "5.0.0-beta.22",
4
4
  "description": "Generate type-safe TanStack Query (React Query) hooks from your OpenAPI specification. Covers useQuery, useMutation, useInfiniteQuery, and queryOptions with full TypeScript support.",
5
5
  "keywords": [
6
6
  "code-generation",
@@ -68,12 +68,12 @@
68
68
  "registry": "https://registry.npmjs.org/"
69
69
  },
70
70
  "dependencies": {
71
- "@kubb/core": "5.0.0-beta.10",
72
- "@kubb/renderer-jsx": "5.0.0-beta.10",
73
- "remeda": "^2.34.0",
74
- "@kubb/plugin-client": "5.0.0-beta.10",
75
- "@kubb/plugin-ts": "5.0.0-beta.10",
76
- "@kubb/plugin-zod": "5.0.0-beta.10"
71
+ "@kubb/core": "5.0.0-beta.22",
72
+ "@kubb/renderer-jsx": "5.0.0-beta.22",
73
+ "remeda": "^2.34.1",
74
+ "@kubb/plugin-client": "5.0.0-beta.22",
75
+ "@kubb/plugin-ts": "5.0.0-beta.22",
76
+ "@kubb/plugin-zod": "5.0.0-beta.22"
77
77
  },
78
78
  "devDependencies": {
79
79
  "@internals/shared": "0.0.0",
@@ -81,7 +81,7 @@
81
81
  "@internals/utils": "0.0.0"
82
82
  },
83
83
  "peerDependencies": {
84
- "@kubb/renderer-jsx": "5.0.0-beta.10"
84
+ "@kubb/renderer-jsx": "5.0.0-beta.22"
85
85
  },
86
86
  "size-limit": [
87
87
  {
@@ -92,35 +92,25 @@ export function InfiniteQueryOptions({
92
92
 
93
93
  const hasNewParams = nextParam !== undefined || previousParam !== undefined
94
94
 
95
- let getNextPageParamExpr: string | undefined
96
- let getPreviousPageParamExpr: string | undefined
97
-
98
- if (hasNewParams) {
99
- if (nextParam) {
100
- const accessor = getNestedAccessor(nextParam, 'lastPage')
101
- if (accessor) {
102
- getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`
103
- }
104
- }
105
- if (previousParam) {
106
- const accessor = getNestedAccessor(previousParam, 'firstPage')
107
- if (accessor) {
108
- getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`
109
- }
95
+ const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
96
+ if (hasNewParams) {
97
+ const nextAccessor = nextParam ? getNestedAccessor(nextParam, 'lastPage') : undefined
98
+ const prevAccessor = previousParam ? getNestedAccessor(previousParam, 'firstPage') : undefined
99
+ return [
100
+ nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : undefined,
101
+ prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : undefined,
102
+ ] as const
110
103
  }
111
- } else if (cursorParam) {
112
- getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`
113
- getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`
114
- } else {
115
- if (dataReturnType === 'full') {
116
- getNextPageParamExpr =
117
- 'getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1'
118
- } else {
119
- getNextPageParamExpr =
120
- 'getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1'
104
+ if (cursorParam) {
105
+ return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`] as const
121
106
  }
122
- getPreviousPageParamExpr = 'getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1'
123
- }
107
+ return [
108
+ dataReturnType === 'full'
109
+ ? 'getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1'
110
+ : 'getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1',
111
+ 'getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1',
112
+ ] as const
113
+ })()
124
114
 
125
115
  const queryOptionsArr = [
126
116
  `initialPageParam: ${typeof initialPageParam === 'string' ? JSON.stringify(initialPageParam) : initialPageParam}`,
@@ -92,35 +92,25 @@ export function SuspenseInfiniteQueryOptions({
92
92
 
93
93
  const hasNewParams = nextParam !== undefined || previousParam !== undefined
94
94
 
95
- let getNextPageParamExpr: string | undefined
96
- let getPreviousPageParamExpr: string | undefined
97
-
98
- if (hasNewParams) {
99
- if (nextParam) {
100
- const accessor = getNestedAccessor(nextParam, 'lastPage')
101
- if (accessor) {
102
- getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`
103
- }
104
- }
105
- if (previousParam) {
106
- const accessor = getNestedAccessor(previousParam, 'firstPage')
107
- if (accessor) {
108
- getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`
109
- }
95
+ const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
96
+ if (hasNewParams) {
97
+ const nextAccessor = nextParam ? getNestedAccessor(nextParam, 'lastPage') : undefined
98
+ const prevAccessor = previousParam ? getNestedAccessor(previousParam, 'firstPage') : undefined
99
+ return [
100
+ nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : undefined,
101
+ prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : undefined,
102
+ ] as const
110
103
  }
111
- } else if (cursorParam) {
112
- getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`
113
- getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`
114
- } else {
115
- if (dataReturnType === 'full') {
116
- getNextPageParamExpr =
117
- 'getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1'
118
- } else {
119
- getNextPageParamExpr =
120
- 'getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1'
104
+ if (cursorParam) {
105
+ return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`] as const
121
106
  }
122
- getPreviousPageParamExpr = 'getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1'
123
- }
107
+ return [
108
+ dataReturnType === 'full'
109
+ ? 'getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1'
110
+ : 'getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1',
111
+ 'getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1',
112
+ ] as const
113
+ })()
124
114
 
125
115
  const queryOptionsArr = [
126
116
  `initialPageParam: ${typeof initialPageParam === 'string' ? JSON.stringify(initialPageParam) : initialPageParam}`,
@@ -2,12 +2,12 @@ import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
 
4
4
  import { defineGenerator } from '@kubb/core'
5
- import { File, Function, jsxRenderer } from '@kubb/renderer-jsx'
5
+ import { File, Function, jsxRendererSync } from '@kubb/renderer-jsx'
6
6
  import type { PluginReactQuery } from '../types'
7
7
 
8
8
  export const customHookOptionsFileGenerator = defineGenerator<PluginReactQuery>({
9
9
  name: 'react-query-custom-hook-options-file',
10
- renderer: jsxRenderer,
10
+ renderer: jsxRendererSync,
11
11
  operations(nodes, ctx) {
12
12
  const { resolver, config, root } = ctx
13
13
  const { output, customOptions, query, group } = ctx.options
@@ -1,6 +1,6 @@
1
1
  import { getOperationParameters } from '@internals/shared'
2
2
  import { defineGenerator } from '@kubb/core'
3
- import { File, jsxRenderer, Type } from '@kubb/renderer-jsx'
3
+ import { File, jsxRendererSync, Type } from '@kubb/renderer-jsx'
4
4
  import type { KubbReactNode } from '@kubb/renderer-jsx/types'
5
5
  import { difference } from 'remeda'
6
6
  import type { PluginReactQuery } from '../types'
@@ -11,9 +11,9 @@ type MutationOption = PluginReactQuery['resolvedOptions']['mutation']
11
11
 
12
12
  export const hookOptionsGenerator = defineGenerator<PluginReactQuery>({
13
13
  name: 'react-query-hook-options',
14
- renderer: jsxRenderer,
14
+ renderer: jsxRendererSync,
15
15
  operations(nodes, ctx) {
16
- const { resolver, config, root, adapter } = ctx
16
+ const { resolver, config, root } = ctx
17
17
  const { output, customOptions, query, mutation, suspense, infinite, group, override } = ctx.options
18
18
 
19
19
  if (!customOptions) return null
@@ -116,8 +116,8 @@ export const hookOptionsGenerator = defineGenerator<PluginReactQuery>({
116
116
  baseName={hookOptionsFile.baseName}
117
117
  path={hookOptionsFile.path}
118
118
  meta={hookOptionsFile.meta}
119
- banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
120
- footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
119
+ banner={resolver.resolveBanner(ctx.meta, { output, config })}
120
+ footer={resolver.resolveFooter(ctx.meta, { output, config })}
121
121
  >
122
122
  {imports}
123
123
  <File.Source name={name} isExportable isIndexable isTypeOnly>
@@ -5,16 +5,16 @@ import { defineGenerator } from '@kubb/core'
5
5
  import { Client, pluginClientName } from '@kubb/plugin-client'
6
6
  import { pluginTsName } from '@kubb/plugin-ts'
7
7
  import { pluginZodName } from '@kubb/plugin-zod'
8
- import { File, jsxRenderer } from '@kubb/renderer-jsx'
8
+ import { File, jsxRendererSync } from '@kubb/renderer-jsx'
9
9
  import { difference } from 'remeda'
10
10
  import { InfiniteQuery, InfiniteQueryOptions, QueryKey } from '../components'
11
11
  import type { PluginReactQuery } from '../types'
12
12
 
13
13
  export const infiniteQueryGenerator = defineGenerator<PluginReactQuery>({
14
14
  name: 'react-infinite-query',
15
- renderer: jsxRenderer,
15
+ renderer: jsxRendererSync,
16
16
  operation(node, ctx) {
17
- const { adapter, config, driver, resolver, root } = ctx
17
+ const { config, driver, resolver, root } = ctx
18
18
  const { output, query, mutation, infinite, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, customOptions } = ctx.options
19
19
 
20
20
  const pluginTs = driver.getPlugin(pluginTsName)
@@ -94,8 +94,8 @@ export const infiniteQueryGenerator = defineGenerator<PluginReactQuery>({
94
94
  baseName={meta.file.baseName}
95
95
  path={meta.file.path}
96
96
  meta={meta.file.meta}
97
- banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
98
- footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
97
+ banner={resolver.resolveBanner(ctx.meta, { output, config })}
98
+ footer={resolver.resolveFooter(ctx.meta, { output, config })}
99
99
  >
100
100
  {fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
101
101
  {clientOptions.importPath ? (
@@ -5,16 +5,16 @@ import { defineGenerator } from '@kubb/core'
5
5
  import { Client, pluginClientName } from '@kubb/plugin-client'
6
6
  import { pluginTsName } from '@kubb/plugin-ts'
7
7
  import { pluginZodName } from '@kubb/plugin-zod'
8
- import { File, jsxRenderer } from '@kubb/renderer-jsx'
8
+ import { File, jsxRendererSync } from '@kubb/renderer-jsx'
9
9
  import { difference } from 'remeda'
10
10
  import { Mutation, MutationKey, MutationOptions } from '../components'
11
11
  import type { PluginReactQuery } from '../types'
12
12
 
13
13
  export const mutationGenerator = defineGenerator<PluginReactQuery>({
14
14
  name: 'react-query-mutation',
15
- renderer: jsxRenderer,
15
+ renderer: jsxRendererSync,
16
16
  operation(node, ctx) {
17
- const { adapter, config, driver, resolver, root } = ctx
17
+ const { config, driver, resolver, root } = ctx
18
18
  const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, customOptions } = ctx.options
19
19
 
20
20
  const pluginTs = driver.getPlugin(pluginTsName)
@@ -80,8 +80,8 @@ export const mutationGenerator = defineGenerator<PluginReactQuery>({
80
80
  baseName={meta.file.baseName}
81
81
  path={meta.file.path}
82
82
  meta={meta.file.meta}
83
- banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
84
- footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
83
+ banner={resolver.resolveBanner(ctx.meta, { output, config })}
84
+ footer={resolver.resolveFooter(ctx.meta, { output, config })}
85
85
  >
86
86
  {fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
87
87
  {clientOptions.importPath ? (
@@ -5,16 +5,16 @@ import { defineGenerator } from '@kubb/core'
5
5
  import { Client, pluginClientName } from '@kubb/plugin-client'
6
6
  import { pluginTsName } from '@kubb/plugin-ts'
7
7
  import { pluginZodName } from '@kubb/plugin-zod'
8
- import { File, jsxRenderer } from '@kubb/renderer-jsx'
8
+ import { File, jsxRendererSync } from '@kubb/renderer-jsx'
9
9
  import { difference } from 'remeda'
10
10
  import { Query, QueryKey, QueryOptions } from '../components'
11
11
  import type { PluginReactQuery } from '../types'
12
12
 
13
13
  export const queryGenerator = defineGenerator<PluginReactQuery>({
14
14
  name: 'react-query',
15
- renderer: jsxRenderer,
15
+ renderer: jsxRendererSync,
16
16
  operation(node, ctx) {
17
- const { adapter, config, driver, resolver, root } = ctx
17
+ const { config, driver, resolver, root } = ctx
18
18
  const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, customOptions } = ctx.options
19
19
 
20
20
  const pluginTs = driver.getPlugin(pluginTsName)
@@ -85,8 +85,8 @@ export const queryGenerator = defineGenerator<PluginReactQuery>({
85
85
  baseName={meta.file.baseName}
86
86
  path={meta.file.path}
87
87
  meta={meta.file.meta}
88
- banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
89
- footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
88
+ banner={resolver.resolveBanner(ctx.meta, { output, config })}
89
+ footer={resolver.resolveFooter(ctx.meta, { output, config })}
90
90
  >
91
91
  {fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
92
92
  {clientOptions.importPath ? (
@@ -5,16 +5,16 @@ import { defineGenerator } from '@kubb/core'
5
5
  import { Client, pluginClientName } from '@kubb/plugin-client'
6
6
  import { pluginTsName } from '@kubb/plugin-ts'
7
7
  import { pluginZodName } from '@kubb/plugin-zod'
8
- import { File, jsxRenderer } from '@kubb/renderer-jsx'
8
+ import { File, jsxRendererSync } from '@kubb/renderer-jsx'
9
9
  import { difference } from 'remeda'
10
10
  import { QueryKey, SuspenseInfiniteQuery, SuspenseInfiniteQueryOptions } from '../components'
11
11
  import type { PluginReactQuery } from '../types'
12
12
 
13
13
  export const suspenseInfiniteQueryGenerator = defineGenerator<PluginReactQuery>({
14
14
  name: 'react-suspense-infinite-query',
15
- renderer: jsxRenderer,
15
+ renderer: jsxRendererSync,
16
16
  operation(node, ctx) {
17
- const { adapter, config, driver, resolver, root } = ctx
17
+ const { config, driver, resolver, root } = ctx
18
18
  const {
19
19
  output,
20
20
  query,
@@ -103,8 +103,8 @@ export const suspenseInfiniteQueryGenerator = defineGenerator<PluginReactQuery>(
103
103
  baseName={meta.file.baseName}
104
104
  path={meta.file.path}
105
105
  meta={meta.file.meta}
106
- banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
107
- footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
106
+ banner={resolver.resolveBanner(ctx.meta, { output, config })}
107
+ footer={resolver.resolveFooter(ctx.meta, { output, config })}
108
108
  >
109
109
  {fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
110
110
  {clientOptions.importPath ? (
@@ -5,16 +5,16 @@ import { defineGenerator } from '@kubb/core'
5
5
  import { Client, pluginClientName } from '@kubb/plugin-client'
6
6
  import { pluginTsName } from '@kubb/plugin-ts'
7
7
  import { pluginZodName } from '@kubb/plugin-zod'
8
- import { File, jsxRenderer } from '@kubb/renderer-jsx'
8
+ import { File, jsxRendererSync } from '@kubb/renderer-jsx'
9
9
  import { difference } from 'remeda'
10
10
  import { QueryKey, QueryOptions, SuspenseQuery } from '../components'
11
11
  import type { PluginReactQuery } from '../types'
12
12
 
13
13
  export const suspenseQueryGenerator = defineGenerator<PluginReactQuery>({
14
14
  name: 'react-suspense-query',
15
- renderer: jsxRenderer,
15
+ renderer: jsxRendererSync,
16
16
  operation(node, ctx) {
17
- const { adapter, config, driver, resolver, root } = ctx
17
+ const { config, driver, resolver, root } = ctx
18
18
  const { output, query, mutation, suspense, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, customOptions } = ctx.options
19
19
 
20
20
  const pluginTs = driver.getPlugin(pluginTsName)
@@ -86,8 +86,8 @@ export const suspenseQueryGenerator = defineGenerator<PluginReactQuery>({
86
86
  baseName={meta.file.baseName}
87
87
  path={meta.file.path}
88
88
  meta={meta.file.meta}
89
- banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
90
- footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
89
+ banner={resolver.resolveBanner(ctx.meta, { output, config })}
90
+ footer={resolver.resolveFooter(ctx.meta, { output, config })}
91
91
  >
92
92
  {fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
93
93
  {clientOptions.importPath ? (