@kubb/plugin-client 3.0.0-alpha.9 → 3.0.0-beta.10

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.
Files changed (72) hide show
  1. package/README.md +14 -5
  2. package/client.ts +29 -8
  3. package/dist/chunk-ILOAIN3U.cjs +231 -0
  4. package/dist/chunk-ILOAIN3U.cjs.map +1 -0
  5. package/dist/chunk-PHUXTZZT.js +159 -0
  6. package/dist/chunk-PHUXTZZT.js.map +1 -0
  7. package/dist/chunk-UBMTYBLG.cjs +162 -0
  8. package/dist/chunk-UBMTYBLG.cjs.map +1 -0
  9. package/dist/chunk-UOML26IJ.js +221 -0
  10. package/dist/chunk-UOML26IJ.js.map +1 -0
  11. package/dist/client.cjs +36 -10
  12. package/dist/client.cjs.map +1 -1
  13. package/dist/client.d.cts +10 -4
  14. package/dist/client.d.ts +10 -4
  15. package/dist/client.js +24 -10
  16. package/dist/client.js.map +1 -1
  17. package/dist/components.cjs +11 -5
  18. package/dist/components.cjs.map +1 -1
  19. package/dist/components.d.cts +39 -5
  20. package/dist/components.d.ts +39 -5
  21. package/dist/components.js +2 -9
  22. package/dist/components.js.map +1 -1
  23. package/dist/generators.cjs +17 -4
  24. package/dist/generators.cjs.map +1 -1
  25. package/dist/generators.d.cts +7 -6
  26. package/dist/generators.d.ts +7 -6
  27. package/dist/generators.js +3 -7
  28. package/dist/generators.js.map +1 -1
  29. package/dist/index.cjs +11 -109
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +1 -4
  32. package/dist/index.d.ts +1 -4
  33. package/dist/index.js +3 -114
  34. package/dist/index.js.map +1 -1
  35. package/dist/types-DMMK2qi5.d.cts +88 -0
  36. package/dist/types-DMMK2qi5.d.ts +88 -0
  37. package/package.json +14 -17
  38. package/src/components/Client.tsx +120 -60
  39. package/src/generators/__snapshots__/deletePet.ts +13 -0
  40. package/src/generators/__snapshots__/deletePetObject.ts +13 -0
  41. package/src/generators/__snapshots__/findByTags.ts +13 -0
  42. package/src/generators/__snapshots__/findByTagsFull.ts +13 -0
  43. package/src/generators/__snapshots__/findByTagsObject.ts +15 -0
  44. package/src/generators/__snapshots__/findByTagsWithZod.ts +13 -0
  45. package/src/generators/__snapshots__/findByTagsWithZodFull.ts +13 -0
  46. package/src/generators/__snapshots__/importPath.ts +13 -0
  47. package/src/generators/__snapshots__/operations.ts +82 -0
  48. package/src/generators/__snapshots__/updatePetById.ts +12 -0
  49. package/src/generators/clientGenerator.tsx +67 -0
  50. package/src/generators/groupedClientGenerator.tsx +70 -0
  51. package/src/generators/index.ts +3 -1
  52. package/src/generators/operationsGenerator.tsx +26 -0
  53. package/src/plugin.ts +37 -46
  54. package/src/types.ts +47 -87
  55. package/dist/chunk-AZDWYBLW.cjs +0 -1
  56. package/dist/chunk-AZDWYBLW.cjs.map +0 -1
  57. package/dist/chunk-GHHJWXKQ.cjs +0 -61
  58. package/dist/chunk-GHHJWXKQ.cjs.map +0 -1
  59. package/dist/chunk-OODSLPAP.js +0 -61
  60. package/dist/chunk-OODSLPAP.js.map +0 -1
  61. package/dist/chunk-W256NILH.js +0 -128
  62. package/dist/chunk-W256NILH.js.map +0 -1
  63. package/dist/chunk-YGRM4AA5.cjs +0 -128
  64. package/dist/chunk-YGRM4AA5.cjs.map +0 -1
  65. package/dist/chunk-YJOVLRSC.js +0 -1
  66. package/dist/chunk-YJOVLRSC.js.map +0 -1
  67. package/dist/types-DETYKDFZ.d.cts +0 -139
  68. package/dist/types-DETYKDFZ.d.ts +0 -139
  69. package/src/components/__snapshots__/Client/showPetById.ts +0 -8
  70. package/src/components/__snapshots__/Operations/showPetById.ts +0 -6
  71. package/src/components/__snapshots__/Query/showPetById.ts +0 -15
  72. package/src/generators/axiosGenerator.tsx +0 -63
@@ -0,0 +1,67 @@
1
+ import { createReactGenerator } from '@kubb/plugin-oas'
2
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
3
+ import { pluginTsName } from '@kubb/plugin-ts'
4
+ import { pluginZodName } from '@kubb/plugin-zod'
5
+ import { File, useApp } from '@kubb/react'
6
+ import { Client } from '../components/Client'
7
+ import type { PluginClient } from '../types'
8
+
9
+ export const clientGenerator = createReactGenerator<PluginClient>({
10
+ name: 'client',
11
+ Operation({ options, operation }) {
12
+ const {
13
+ plugin: {
14
+ options: { output },
15
+ },
16
+ } = useApp<PluginClient>()
17
+ const { getSchemas, getName, getFile } = useOperationManager()
18
+
19
+ const client = {
20
+ name: getName(operation, { type: 'function' }),
21
+ file: getFile(operation),
22
+ }
23
+
24
+ const type = {
25
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
26
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
27
+ }
28
+
29
+ const zod = {
30
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
31
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
32
+ }
33
+
34
+ return (
35
+ <File baseName={client.file.baseName} path={client.file.path} meta={client.file.meta} banner={output?.banner} footer={output?.footer}>
36
+ <File.Import name={'client'} path={options.importPath} />
37
+ <File.Import name={['RequestConfig']} path={options.importPath} isTypeOnly />
38
+ {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={client.file.path} path={zod.file.path} />}
39
+ <File.Import
40
+ name={[
41
+ type.schemas.request?.name,
42
+ type.schemas.response.name,
43
+ type.schemas.pathParams?.name,
44
+ type.schemas.queryParams?.name,
45
+ type.schemas.headerParams?.name,
46
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
47
+ ].filter(Boolean)}
48
+ root={client.file.path}
49
+ path={type.file.path}
50
+ isTypeOnly
51
+ />
52
+
53
+ <Client
54
+ name={client.name}
55
+ baseURL={options.baseURL}
56
+ dataReturnType={options.dataReturnType}
57
+ pathParamsType={options.pathParamsType}
58
+ paramsType={options.paramsType}
59
+ typeSchemas={type.schemas}
60
+ operation={operation}
61
+ parser={options.parser}
62
+ zodSchemas={zod.schemas}
63
+ />
64
+ </File>
65
+ )
66
+ },
67
+ })
@@ -0,0 +1,70 @@
1
+ import { camelCase } from '@kubb/core/transformers'
2
+ import type * as KubbFile from '@kubb/fs/types'
3
+ import { pluginClientName } from '@kubb/plugin-client'
4
+ import { createReactGenerator } from '@kubb/plugin-oas'
5
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
6
+ import { File, Function, useApp } from '@kubb/react'
7
+ import type { PluginClient } from '../types'
8
+
9
+ export const groupedClientGenerator = createReactGenerator<PluginClient>({
10
+ name: 'groupedClient',
11
+ Operations({ operations }) {
12
+ const {
13
+ pluginManager,
14
+ plugin: { options },
15
+ } = useApp<PluginClient>()
16
+ const { getName, getFile } = useOperationManager()
17
+
18
+ const controllers = operations.reduce(
19
+ (acc, operation) => {
20
+ if (options.group?.type === 'tag') {
21
+ const tag = operation.getTags().at(0)?.name
22
+ const name = tag ? options.group?.name?.({ group: camelCase(tag) }) : undefined
23
+
24
+ if (!tag || !name) {
25
+ return acc
26
+ }
27
+
28
+ const file = pluginManager.getFile({
29
+ name,
30
+ extname: '.ts',
31
+ pluginKey: [pluginClientName],
32
+ options: { tag },
33
+ })
34
+
35
+ const client = {
36
+ name: getName(operation, { type: 'function' }),
37
+ file: getFile(operation),
38
+ }
39
+
40
+ const previousFile = acc.find((item) => item.file.path === file.path)
41
+
42
+ if (previousFile) {
43
+ previousFile.clients.push(client)
44
+ } else {
45
+ acc.push({ name, file, clients: [client] })
46
+ }
47
+ }
48
+
49
+ return acc
50
+ },
51
+ [] as Array<{ name: string; file: KubbFile.File; clients: Array<{ name: string; file: KubbFile.File }> }>,
52
+ )
53
+
54
+ return controllers.map(({ name, file, clients }) => {
55
+ return (
56
+ <File key={file.path} baseName={file.baseName} path={file.path} meta={file.meta} banner={options.output?.banner} footer={options.output?.footer}>
57
+ {clients.map((client) => (
58
+ <File.Import key={client.name} name={[client.name]} root={file.path} path={client.file.path} />
59
+ ))}
60
+
61
+ <File.Source name={name} isExportable isIndexable>
62
+ <Function export name={name}>
63
+ {`return { ${clients.map((client) => client.name).join(', ')} }`}
64
+ </Function>
65
+ </File.Source>
66
+ </File>
67
+ )
68
+ })
69
+ },
70
+ })
@@ -1 +1,3 @@
1
- export { axiosGenerator } from './axiosGenerator.tsx'
1
+ export { clientGenerator } from './clientGenerator.tsx'
2
+ export { operationsGenerator } from './operationsGenerator.tsx'
3
+ export { groupedClientGenerator } from './groupedClientGenerator.tsx'
@@ -0,0 +1,26 @@
1
+ import { pluginClientName } from '@kubb/plugin-client'
2
+ import { createReactGenerator } from '@kubb/plugin-oas'
3
+ import { File, useApp } from '@kubb/react'
4
+ import { Operations } from '../components/Operations'
5
+ import type { PluginClient } from '../types'
6
+
7
+ export const operationsGenerator = createReactGenerator<PluginClient>({
8
+ name: 'client',
9
+ Operations({ operations }) {
10
+ const {
11
+ pluginManager,
12
+ plugin: {
13
+ options: { output },
14
+ },
15
+ } = useApp<PluginClient>()
16
+
17
+ const name = 'operations'
18
+ const file = pluginManager.getFile({ name, extname: '.ts', pluginKey: [pluginClientName] })
19
+
20
+ return (
21
+ <File baseName={file.baseName} path={file.path} meta={file.meta} banner={output?.banner} footer={output?.footer}>
22
+ <Operations name={name} operations={operations} />
23
+ </File>
24
+ )
25
+ },
26
+ })
package/src/plugin.ts CHANGED
@@ -1,22 +1,22 @@
1
1
  import path from 'node:path'
2
2
 
3
- import { FileManager, PluginManager, createPlugin } from '@kubb/core'
3
+ import { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'
4
4
  import { camelCase } from '@kubb/core/transformers'
5
- import { renderTemplate } from '@kubb/core/utils'
6
5
  import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
7
6
 
8
- import { Client, Operations } from './components/index.ts'
9
-
10
7
  import type { Plugin } from '@kubb/core'
11
8
  import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
12
- import { axiosGenerator } from './generators/axiosGenerator.tsx'
9
+ import { pluginZodName } from '@kubb/plugin-zod'
10
+ import { operationsGenerator } from './generators'
11
+ import { clientGenerator } from './generators/clientGenerator.tsx'
12
+ import { groupedClientGenerator } from './generators/groupedClientGenerator.tsx'
13
13
  import type { PluginClient } from './types.ts'
14
14
 
15
15
  export const pluginClientName = 'plugin-client' satisfies PluginClient['name']
16
16
 
17
17
  export const pluginClient = createPlugin<PluginClient>((options) => {
18
18
  const {
19
- output = { path: 'clients' },
19
+ output = { path: 'clients', barrelType: 'named' },
20
20
  group,
21
21
  exclude = [],
22
22
  include,
@@ -24,38 +24,36 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
24
24
  transformers = {},
25
25
  dataReturnType = 'data',
26
26
  pathParamsType = 'inline',
27
- templates,
27
+ paramsType = 'inline',
28
+ operations = false,
29
+ generators = [clientGenerator, group ? groupedClientGenerator : undefined, operations ? operationsGenerator : undefined].filter(Boolean),
30
+ importPath = '@kubb/plugin-client/client',
31
+ parser = 'client',
28
32
  } = options
29
33
 
30
- const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`
31
-
32
34
  return {
33
35
  name: pluginClientName,
34
- output: {
35
- exportType: 'barrelNamed',
36
- ...output,
37
- },
38
36
  options: {
39
- extName: output.extName,
37
+ output,
38
+ group,
39
+ parser,
40
40
  dataReturnType,
41
- client: {
42
- importPath: '@kubb/plugin-client/client',
43
- methods: ['get', 'post', 'delete', 'put'],
44
- ...options.client,
45
- },
46
- pathParamsType,
47
- templates: {
48
- operations: Operations,
49
- client: Client,
50
- ...templates,
51
- },
41
+ importPath,
42
+ paramsType,
43
+ pathParamsType: paramsType === 'object' ? 'object' : pathParamsType,
52
44
  baseURL: undefined,
53
45
  },
54
- pre: [pluginOasName],
46
+ pre: [pluginOasName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
55
47
  resolvePath(baseName, pathMode, options) {
56
48
  const root = path.resolve(this.config.root, this.config.output.path)
57
49
  const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
58
50
 
51
+ if (options?.tag && group?.type === 'tag') {
52
+ const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`
53
+
54
+ return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)
55
+ }
56
+
59
57
  if (mode === 'single') {
60
58
  /**
61
59
  * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
@@ -64,12 +62,6 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
64
62
  return path.resolve(root, output.path)
65
63
  }
66
64
 
67
- if (options?.tag && group?.type === 'tag') {
68
- const tag = camelCase(options.tag)
69
-
70
- return path.resolve(root, renderTemplate(template, { tag }), baseName)
71
- }
72
-
73
65
  return path.resolve(root, output.path, baseName)
74
66
  },
75
67
  resolveName(name, type) {
@@ -106,23 +98,22 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
106
98
  },
107
99
  )
108
100
 
109
- const files = await operationGenerator.build(axiosGenerator)
101
+ const files = await operationGenerator.build(...generators)
110
102
 
111
103
  await this.addFile(...files)
112
104
 
113
- if (this.config.output.exportType) {
114
- const barrelFiles = await this.fileManager.getBarrelFiles({
115
- root,
116
- output,
117
- files: this.fileManager.files,
118
- meta: {
119
- pluginKey: this.plugin.key,
120
- },
121
- logger: this.logger,
122
- })
123
-
124
- await this.addFile(...barrelFiles)
125
- }
105
+ const barrelFiles = await this.fileManager.getBarrelFiles({
106
+ type: output.barrelType ?? 'named',
107
+ root,
108
+ output,
109
+ files: this.fileManager.files,
110
+ meta: {
111
+ pluginKey: this.plugin.key,
112
+ },
113
+ logger: this.logger,
114
+ })
115
+
116
+ await this.addFile(...barrelFiles)
126
117
  },
127
118
  }
128
119
  })
package/src/types.ts CHANGED
@@ -1,58 +1,17 @@
1
- import type { Plugin, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
- import type * as KubbFile from '@kubb/fs/types'
1
+ import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
3
2
 
4
- import type { HttpMethod } from '@kubb/oas'
5
- import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
6
- import type { Client, Operations } from './components/index.ts'
7
-
8
- type Templates = {
9
- operations?: typeof Operations | false
10
- client?: typeof Client | false
11
- }
3
+ import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
12
4
 
13
5
  export type Options = {
14
- output?: {
15
- /**
16
- * Output to save the clients.
17
- * @default `"clients"``
18
- */
19
- path: string
20
- /**
21
- * Name to be used for the `export * as {{exportAs}} from './'`
22
- */
23
- exportAs?: string
24
- /**
25
- * Add an extension to the generated imports and exports, default it will not use an extension
26
- */
27
- extName?: KubbFile.Extname
28
- /**
29
- * Define what needs to exported, here you can also disable the export of barrel files
30
- * @default `'barrelNamed'`
31
- */
32
- exportType?: 'barrel' | 'barrelNamed' | false
33
- }
6
+ /**
7
+ * Specify the export location for the files and define the behavior of the output
8
+ * @default { path: 'clients', barrelType: 'named' }
9
+ */
10
+ output?: Output
34
11
  /**
35
12
  * Group the clients based on the provided name.
36
13
  */
37
- group?: {
38
- /**
39
- * Tag will group based on the operation tag inside the Swagger file
40
- */
41
- type: 'tag'
42
- /**
43
- * Relative path to save the grouped clients.
44
- *
45
- * `{{tag}}` will be replaced by the current tagName.
46
- * @example `${output}/{{tag}}Controller` => `clients/PetController`
47
- * @default `${output}/{{tag}}Controller`
48
- */
49
- output?: string
50
- /**
51
- * Name to be used for the `export * as {{exportAs}} from './`
52
- * @default `"{{tag}}Service"`
53
- */
54
- exportAs?: string
55
- }
14
+ group?: Group
56
15
  /**
57
16
  * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
58
17
  */
@@ -65,41 +24,45 @@ export type Options = {
65
24
  * Array containing override parameters to override `options` based on tags/operations/methods/paths.
66
25
  */
67
26
  override?: Array<Override<ResolvedOptions>>
68
- client?: {
69
- /**
70
- * Path to the client import path that will be used to do the API calls.
71
- * It will be used as `import client from '${client.importPath}'`.
72
- * It allows both relative and absolute path.
73
- * the path will be applied as is, so relative path should be based on the file being generated.
74
- * @default '@kubb/plugin-client/client'
75
- */
76
- importPath?: string
77
- /**
78
- * Define which HttpMethods can be used for queries
79
- * @default ['get', 'post', 'put', 'delete']
80
- */
81
- methods?: Array<HttpMethod>
82
- }
83
27
  /**
84
- * ReturnType that needs to be used when calling client().
85
- *
86
- * `Data` will return ResponseConfig[data].
87
- *
88
- * `Full` will return ResponseConfig.
89
- * @default `'data'`
90
- * @private
28
+ * Create `operations.ts` file with all operations grouped by methods.
29
+ * @default false
30
+ */
31
+ operations?: boolean
32
+ /**
33
+ * Path to the client import path that will be used to do the API calls.
34
+ * It will be used as `import client from '${client.importPath}'`.
35
+ * It allows both relative and absolute path but be aware that we will not change the path.
36
+ * @default '@kubb/plugin-client/client'
37
+ */
38
+ importPath?: string
39
+ /**
40
+ * ReturnType that will be used when calling the client.
41
+ * - 'data' will return ResponseConfig[data].
42
+ * - 'full' will return ResponseConfig.
43
+ * @default 'data'
91
44
  */
92
45
  dataReturnType?: 'data' | 'full'
46
+ /**
47
+ * How to pass your params
48
+ * - 'object' will return the params and pathParams as an object.
49
+ * - 'inline' will return the params as comma separated params.
50
+ * @default 'inline'
51
+ */
52
+ paramsType?: 'object' | 'inline'
93
53
  /**
94
54
  * How to pass your pathParams.
95
- *
96
- * `object` will return the pathParams as an object.
97
- *
98
- * `inline` will return the pathParams as comma separated params.
99
- * @default `'inline'`
100
- * @private
55
+ * - 'object' will return the pathParams as an object.
56
+ * - 'inline' will return the pathParams as comma separated params.
57
+ * @default 'inline'
101
58
  */
102
59
  pathParamsType?: 'object' | 'inline'
60
+ /**
61
+ * Which parser can be used before returning the data
62
+ * - 'zod' will use `@kubb/plugin-zod` to parse the data.
63
+ * @default 'client'
64
+ */
65
+ parser?: 'client' | 'zod'
103
66
  transformers?: {
104
67
  /**
105
68
  * Customize the names based on the type that is provided by the plugin.
@@ -107,23 +70,20 @@ export type Options = {
107
70
  name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
108
71
  }
109
72
  /**
110
- * Make it possible to override one of the templates
73
+ * Define some generators next to the client generators
111
74
  */
112
- templates?: Partial<Templates>
75
+ generators?: Array<Generator<PluginClient>>
113
76
  }
114
77
 
115
78
  type ResolvedOptions = {
116
- extName: KubbFile.Extname | undefined
79
+ output: Output
80
+ group?: Options['group']
117
81
  baseURL: string | undefined
118
- client: Required<NonNullable<Options['client']>>
82
+ parser: NonNullable<Options['parser']>
83
+ importPath: NonNullable<Options['importPath']>
119
84
  dataReturnType: NonNullable<Options['dataReturnType']>
120
85
  pathParamsType: NonNullable<Options['pathParamsType']>
121
- templates: NonNullable<Templates>
122
- }
123
-
124
- export type FileMeta = {
125
- pluginKey?: Plugin['key']
126
- tag?: string
86
+ paramsType: NonNullable<Options['paramsType']>
127
87
  }
128
88
 
129
89
  export type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, never, ResolvePathOptions>
@@ -1 +0,0 @@
1
- "use strict";//# sourceMappingURL=chunk-AZDWYBLW.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-client/dist/chunk-AZDWYBLW.cjs"],"names":[],"mappings":"AAAA","file":"/home/runner/work/kubb/kubb/packages/plugin-client/dist/chunk-AZDWYBLW.cjs"}
@@ -1,61 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
-
4
- var _chunkYGRM4AA5cjs = require('./chunk-YGRM4AA5.cjs');
5
-
6
- // src/generators/axiosGenerator.tsx
7
- var _pluginoas = require('@kubb/plugin-oas');
8
- var _hooks = require('@kubb/plugin-oas/hooks');
9
- var _plugints = require('@kubb/plugin-ts');
10
- var _react = require('@kubb/react');
11
- var _jsxruntime = require('@kubb/react/jsx-runtime');
12
- var axiosGenerator = _pluginoas.createReactGenerator.call(void 0, {
13
- name: "plugin-client",
14
- Operations({ options, operations }) {
15
- const { pluginManager } = _react.useApp.call(void 0, );
16
- if (!options.templates.operations) {
17
- return null;
18
- }
19
- const Template = options.templates.operations || _chunkYGRM4AA5cjs.Operations;
20
- const name = "operations";
21
- const file = pluginManager.getFile({ name, extName: ".ts", pluginKey: ["plugin-client"] });
22
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Template, { name, operations }) });
23
- },
24
- Operation({ options, operation }) {
25
- const { getSchemas, getName, getFile } = _hooks.useOperationManager.call(void 0, );
26
- const name = getName(operation, { type: "function" });
27
- const typedSchemas = getSchemas(operation, { pluginKey: [_plugints.pluginTsName], type: "type" });
28
- const file = getFile(operation);
29
- const fileType = getFile(operation, { pluginKey: [_plugints.pluginTsName] });
30
- if (!options.templates.client) {
31
- return null;
32
- }
33
- const Template = options.templates.client || _chunkYGRM4AA5cjs.Client;
34
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
35
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: "client", path: options.client.importPath }),
36
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
37
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
38
- _react.File.Import,
39
- {
40
- extName: options.extName,
41
- name: [
42
- _optionalChain([typedSchemas, 'access', _ => _.request, 'optionalAccess', _2 => _2.name]),
43
- typedSchemas.response.name,
44
- _optionalChain([typedSchemas, 'access', _3 => _3.pathParams, 'optionalAccess', _4 => _4.name]),
45
- _optionalChain([typedSchemas, 'access', _5 => _5.queryParams, 'optionalAccess', _6 => _6.name]),
46
- _optionalChain([typedSchemas, 'access', _7 => _7.headerParams, 'optionalAccess', _8 => _8.name])
47
- ].filter(Boolean),
48
- root: file.path,
49
- path: fileType.path,
50
- isTypeOnly: true
51
- }
52
- ),
53
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Template, { name, options, typedSchemas, operation })
54
- ] });
55
- }
56
- });
57
-
58
-
59
-
60
- exports.axiosGenerator = axiosGenerator;
61
- //# sourceMappingURL=chunk-GHHJWXKQ.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-client/dist/chunk-GHHJWXKQ.cjs","../src/generators/axiosGenerator.tsx"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACLA,6CAAqC;AACrC,+CAAoC;AACpC,2CAA6B;AAC7B,oCAA6B;AAoBrB,qDAAA;AAfD,IAAM,eAAA,EAAiB,6CAAA;AAAmC,EAC/D,IAAA,EAAM,eAAA;AAAA,EACN,UAAA,CAAW,EAAE,OAAA,EAAS,WAAW,CAAA,EAAG;AAClC,IAAA,MAAM,EAAE,cAAc,EAAA,EAAI,2BAAA,CAAqB;AAE/C,IAAA,GAAA,CAAI,CAAC,OAAA,CAAQ,SAAA,CAAU,UAAA,EAAY;AACjC,MAAA,OAAO,IAAA;AAAA,IACT;AAEA,IAAA,MAAM,SAAA,EAAW,OAAA,CAAQ,SAAA,CAAU,WAAA,GAAc,4BAAA;AACjD,IAAA,MAAM,KAAA,EAAO,YAAA;AACb,IAAA,MAAM,KAAA,EAAO,aAAA,CAAc,OAAA,CAAQ,EAAE,IAAA,EAAM,OAAA,EAAS,KAAA,EAAO,SAAA,EAAW,CAAC,eAAe,EAAE,CAAC,CAAA;AAEzF,IAAA,uBACE,6BAAA,WAAC,EAAA,EAAK,QAAA,EAAU,IAAA,CAAK,QAAA,EAAU,IAAA,EAAM,IAAA,CAAK,IAAA,EAAM,IAAA,EAAM,IAAA,CAAK,I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AAO,UAAA,EAAY,UAAA,EAAU,KAAA,CAAC,CAAA;AAAA,sBACnF,6BAAA;AAAA,QAAC,WAAA,CAAK,MAAA;AAAA,QAAL;AAAA,UACC,OAAA,EAAS,OAAA,CAAQ,OAAA;AAAA,UACjB,IAAA,EAAM;AAAA,4BACJ,YAAA,mBAAa,OAAA,6BAAS,MAAA;AAAA,YACtB,YAAA,CAAa,QAAA,CAAS,IAAA;AAAA,4BACtB,YAAA,qBAAa,UAAA,6BAAY,MAAA;AAAA,4BACzB,YAAA,qBAAa,WAAA,6BAAa,MAAA;AAAA,4BAC1B,YAAA,qBAAa,YAAA,6BAAc;AAAA,UAC7B,CAAA,CAAE,MAAA,CAAO,OAAO,CAAA;AAAA,UAChB,IAAA,EAAM,IAAA,CAAK,IAAA;AAAA,UACX,IAAA,EAAM,QAAA,CAAS,IAAA;AAAA,UACf,UAAA,EAAU;AAAA,QAAA;AAAA,MACZ,CAAA;AAAA,sBACA,6BAAA,QAAC,EAAA,EAAS,IAAA,EAAY,OAAA,EAAkB,YAAA,EAA4B,UAAA,CAAsB;AAAA,IAAA,EAAA,CAC5F,CAAA;AAAA,EAEJ;AACF,CAAC,CAAA;ADND;AACA;AACE;AACF,wCAAC","file":"/home/runner/work/kubb/kubb/packages/plugin-client/dist/chunk-GHHJWXKQ.cjs","sourcesContent":[null,"import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Client } from '../components/Client'\nimport { Operations } from '../components/Operations'\nimport type { PluginClient } from '../types'\n\nexport const axiosGenerator = createReactGenerator<PluginClient>({\n name: 'plugin-client',\n Operations({ options, operations }) {\n const { pluginManager } = useApp<PluginClient>()\n\n if (!options.templates.operations) {\n return null\n }\n\n const Template = options.templates.operations || Operations\n const name = 'operations'\n const file = pluginManager.getFile({ name, extName: '.ts', pluginKey: ['plugin-client'] })\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta}>\n <Template name={name} operations={operations} />\n </File>\n )\n },\n Operation({ options, operation }) {\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const name = getName(operation, { type: 'function' })\n const typedSchemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })\n const file = getFile(operation)\n const fileType = getFile(operation, { pluginKey: [pluginTsName] })\n\n if (!options.templates.client) {\n return null\n }\n\n const Template = options.templates.client || Client\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name={'client'} path={options.client.importPath} />\n <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />\n <File.Import\n extName={options.extName}\n name={[\n typedSchemas.request?.name,\n typedSchemas.response.name,\n typedSchemas.pathParams?.name,\n typedSchemas.queryParams?.name,\n typedSchemas.headerParams?.name,\n ].filter(Boolean)}\n root={file.path}\n path={fileType.path}\n isTypeOnly\n />\n <Template name={name} options={options} typedSchemas={typedSchemas} operation={operation} />\n </File>\n )\n },\n})\n"]}
@@ -1,61 +0,0 @@
1
- import {
2
- Client,
3
- Operations
4
- } from "./chunk-W256NILH.js";
5
-
6
- // src/generators/axiosGenerator.tsx
7
- import { createReactGenerator } from "@kubb/plugin-oas";
8
- import { useOperationManager } from "@kubb/plugin-oas/hooks";
9
- import { pluginTsName } from "@kubb/plugin-ts";
10
- import { File, useApp } from "@kubb/react";
11
- import { jsx, jsxs } from "@kubb/react/jsx-runtime";
12
- var axiosGenerator = createReactGenerator({
13
- name: "plugin-client",
14
- Operations({ options, operations }) {
15
- const { pluginManager } = useApp();
16
- if (!options.templates.operations) {
17
- return null;
18
- }
19
- const Template = options.templates.operations || Operations;
20
- const name = "operations";
21
- const file = pluginManager.getFile({ name, extName: ".ts", pluginKey: ["plugin-client"] });
22
- return /* @__PURE__ */ jsx(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: /* @__PURE__ */ jsx(Template, { name, operations }) });
23
- },
24
- Operation({ options, operation }) {
25
- const { getSchemas, getName, getFile } = useOperationManager();
26
- const name = getName(operation, { type: "function" });
27
- const typedSchemas = getSchemas(operation, { pluginKey: [pluginTsName], type: "type" });
28
- const file = getFile(operation);
29
- const fileType = getFile(operation, { pluginKey: [pluginTsName] });
30
- if (!options.templates.client) {
31
- return null;
32
- }
33
- const Template = options.templates.client || Client;
34
- return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
35
- /* @__PURE__ */ jsx(File.Import, { name: "client", path: options.client.importPath }),
36
- /* @__PURE__ */ jsx(File.Import, { name: ["ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
37
- /* @__PURE__ */ jsx(
38
- File.Import,
39
- {
40
- extName: options.extName,
41
- name: [
42
- typedSchemas.request?.name,
43
- typedSchemas.response.name,
44
- typedSchemas.pathParams?.name,
45
- typedSchemas.queryParams?.name,
46
- typedSchemas.headerParams?.name
47
- ].filter(Boolean),
48
- root: file.path,
49
- path: fileType.path,
50
- isTypeOnly: true
51
- }
52
- ),
53
- /* @__PURE__ */ jsx(Template, { name, options, typedSchemas, operation })
54
- ] });
55
- }
56
- });
57
-
58
- export {
59
- axiosGenerator
60
- };
61
- //# sourceMappingURL=chunk-OODSLPAP.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/generators/axiosGenerator.tsx"],"sourcesContent":["import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Client } from '../components/Client'\nimport { Operations } from '../components/Operations'\nimport type { PluginClient } from '../types'\n\nexport const axiosGenerator = createReactGenerator<PluginClient>({\n name: 'plugin-client',\n Operations({ options, operations }) {\n const { pluginManager } = useApp<PluginClient>()\n\n if (!options.templates.operations) {\n return null\n }\n\n const Template = options.templates.operations || Operations\n const name = 'operations'\n const file = pluginManager.getFile({ name, extName: '.ts', pluginKey: ['plugin-client'] })\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta}>\n <Template name={name} operations={operations} />\n </File>\n )\n },\n Operation({ options, operation }) {\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const name = getName(operation, { type: 'function' })\n const typedSchemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })\n const file = getFile(operation)\n const fileType = getFile(operation, { pluginKey: [pluginTsName] })\n\n if (!options.templates.client) {\n return null\n }\n\n const Template = options.templates.client || Client\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name={'client'} path={options.client.importPath} />\n <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />\n <File.Import\n extName={options.extName}\n name={[\n typedSchemas.request?.name,\n typedSchemas.response.name,\n typedSchemas.pathParams?.name,\n typedSchemas.queryParams?.name,\n typedSchemas.headerParams?.name,\n ].filter(Boolean)}\n root={file.path}\n path={fileType.path}\n isTypeOnly\n />\n <Template name={name} options={options} typedSchemas={typedSchemas} operation={operation} />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;AAAA,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,oBAAoB;AAC7B,SAAS,MAAM,cAAc;AAoBrB,cAmBF,YAnBE;AAfD,IAAM,iBAAiB,qBAAmC;AAAA,EAC/D,MAAM;AAAA,EACN,WAAW,EAAE,SAAS,WAAW,GAAG;AAClC,UAAM,EAAE,cAAc,IAAI,OAAqB;AAE/C,QAAI,CAAC,QAAQ,UAAU,YAAY;AACjC,aAAO;AAAA,IACT;AAEA,UAAM,WAAW,QAAQ,UAAU,cAAc;AACjD,UAAM,OAAO;AACb,UAAM,OAAO,cAAc,QAAQ,EAAE,MAAM,SAAS,OAAO,WAAW,CAAC,eAAe,EAAE,CAAC;AAEzF,WACE,oBAAC,QAAK,UAAU,KAAK,UAAU,MAAM,KAAK,MAAM,MAAM,KAAK,MACzD,8BAAC,YAAS,MAAY,YAAwB,GAChD;AAAA,EAEJ;AAAA,EACA,UAAU,EAAE,SAAS,UAAU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