@kubb/plugin-client 3.0.0-alpha.9 → 3.0.0-beta.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/README.md +14 -5
- package/client.ts +2 -2
- package/dist/chunk-6W3SC7JK.cjs +228 -0
- package/dist/chunk-6W3SC7JK.cjs.map +1 -0
- package/dist/chunk-LI44LDXH.js +218 -0
- package/dist/chunk-LI44LDXH.js.map +1 -0
- package/dist/chunk-X73EA6RA.cjs +133 -0
- package/dist/chunk-X73EA6RA.cjs.map +1 -0
- package/dist/chunk-YYBNZBCI.js +130 -0
- package/dist/chunk-YYBNZBCI.js.map +1 -0
- package/dist/client.cjs +16 -7
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +5 -6
- package/dist/client.js.map +1 -1
- package/dist/components.cjs +11 -5
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +37 -5
- package/dist/components.d.ts +37 -5
- package/dist/components.js +2 -9
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -4
- package/dist/generators.cjs.map +1 -1
- package/dist/generators.d.cts +7 -6
- package/dist/generators.d.ts +7 -6
- package/dist/generators.js +3 -7
- package/dist/generators.js.map +1 -1
- package/dist/index.cjs +11 -109
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -4
- package/dist/index.d.ts +1 -4
- package/dist/index.js +3 -114
- package/dist/index.js.map +1 -1
- package/dist/types-Bk_NZurp.d.cts +86 -0
- package/dist/types-Bk_NZurp.d.ts +86 -0
- package/package.json +14 -17
- package/src/components/Client.tsx +78 -58
- package/src/generators/__snapshots__/deletePet.ts +13 -0
- package/src/generators/__snapshots__/deletePetObject.ts +15 -0
- package/src/generators/__snapshots__/findByTags.ts +13 -0
- package/src/generators/__snapshots__/findByTagsFull.ts +13 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +13 -0
- package/src/generators/__snapshots__/findByTagsWithZodFull.ts +13 -0
- package/src/generators/__snapshots__/importPath.ts +13 -0
- package/src/generators/__snapshots__/operations.ts +82 -0
- package/src/generators/__snapshots__/updatePetById.ts +12 -0
- package/src/generators/clientGenerator.tsx +66 -0
- package/src/generators/groupedClientGenerator.tsx +70 -0
- package/src/generators/index.ts +3 -1
- package/src/generators/operationsGenerator.tsx +26 -0
- package/src/plugin.ts +34 -45
- package/src/types.ts +33 -75
- package/dist/chunk-AZDWYBLW.cjs +0 -1
- package/dist/chunk-AZDWYBLW.cjs.map +0 -1
- package/dist/chunk-GHHJWXKQ.cjs +0 -61
- package/dist/chunk-GHHJWXKQ.cjs.map +0 -1
- package/dist/chunk-OODSLPAP.js +0 -61
- package/dist/chunk-OODSLPAP.js.map +0 -1
- package/dist/chunk-W256NILH.js +0 -128
- package/dist/chunk-W256NILH.js.map +0 -1
- package/dist/chunk-YGRM4AA5.cjs +0 -128
- package/dist/chunk-YGRM4AA5.cjs.map +0 -1
- package/dist/chunk-YJOVLRSC.js +0 -1
- package/dist/chunk-YJOVLRSC.js.map +0 -1
- package/dist/types-DETYKDFZ.d.cts +0 -139
- package/dist/types-DETYKDFZ.d.ts +0 -139
- package/src/components/__snapshots__/Client/showPetById.ts +0 -8
- package/src/components/__snapshots__/Operations/showPetById.ts +0 -6
- package/src/components/__snapshots__/Query/showPetById.ts +0 -15
- package/src/generators/axiosGenerator.tsx +0 -63
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 {
|
|
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,34 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
|
|
|
24
24
|
transformers = {},
|
|
25
25
|
dataReturnType = 'data',
|
|
26
26
|
pathParamsType = 'inline',
|
|
27
|
-
|
|
27
|
+
operations = false,
|
|
28
|
+
generators = [clientGenerator, group ? groupedClientGenerator : undefined, operations ? operationsGenerator : undefined].filter(Boolean),
|
|
29
|
+
importPath = '@kubb/plugin-client/client',
|
|
30
|
+
parser = 'client',
|
|
28
31
|
} = options
|
|
29
32
|
|
|
30
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`
|
|
31
|
-
|
|
32
33
|
return {
|
|
33
34
|
name: pluginClientName,
|
|
34
|
-
output: {
|
|
35
|
-
exportType: 'barrelNamed',
|
|
36
|
-
...output,
|
|
37
|
-
},
|
|
38
35
|
options: {
|
|
39
|
-
|
|
36
|
+
output,
|
|
37
|
+
group,
|
|
38
|
+
parser,
|
|
40
39
|
dataReturnType,
|
|
41
|
-
|
|
42
|
-
importPath: '@kubb/plugin-client/client',
|
|
43
|
-
methods: ['get', 'post', 'delete', 'put'],
|
|
44
|
-
...options.client,
|
|
45
|
-
},
|
|
40
|
+
importPath,
|
|
46
41
|
pathParamsType,
|
|
47
|
-
templates: {
|
|
48
|
-
operations: Operations,
|
|
49
|
-
client: Client,
|
|
50
|
-
...templates,
|
|
51
|
-
},
|
|
52
42
|
baseURL: undefined,
|
|
53
43
|
},
|
|
54
|
-
pre: [pluginOasName],
|
|
44
|
+
pre: [pluginOasName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
|
|
55
45
|
resolvePath(baseName, pathMode, options) {
|
|
56
46
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
57
47
|
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
|
|
58
48
|
|
|
49
|
+
if (options?.tag && group?.type === 'tag') {
|
|
50
|
+
const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`
|
|
51
|
+
|
|
52
|
+
return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)
|
|
53
|
+
}
|
|
54
|
+
|
|
59
55
|
if (mode === 'single') {
|
|
60
56
|
/**
|
|
61
57
|
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
@@ -64,12 +60,6 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
|
|
|
64
60
|
return path.resolve(root, output.path)
|
|
65
61
|
}
|
|
66
62
|
|
|
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
63
|
return path.resolve(root, output.path, baseName)
|
|
74
64
|
},
|
|
75
65
|
resolveName(name, type) {
|
|
@@ -106,23 +96,22 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
|
|
|
106
96
|
},
|
|
107
97
|
)
|
|
108
98
|
|
|
109
|
-
const files = await operationGenerator.build(
|
|
99
|
+
const files = await operationGenerator.build(...generators)
|
|
110
100
|
|
|
111
101
|
await this.addFile(...files)
|
|
112
102
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
103
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
104
|
+
type: output.barrelType ?? 'named',
|
|
105
|
+
root,
|
|
106
|
+
output,
|
|
107
|
+
files: this.fileManager.files,
|
|
108
|
+
meta: {
|
|
109
|
+
pluginKey: this.plugin.key,
|
|
110
|
+
},
|
|
111
|
+
logger: this.logger,
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
await this.addFile(...barrelFiles)
|
|
126
115
|
},
|
|
127
116
|
}
|
|
128
117
|
})
|
package/src/types.ts
CHANGED
|
@@ -1,58 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type * as KubbFile from '@kubb/fs/types'
|
|
1
|
+
import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
3
2
|
|
|
4
|
-
import type {
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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,23 +24,20 @@ 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
|
-
*
|
|
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.
|
|
85
41
|
*
|
|
86
42
|
* `Data` will return ResponseConfig[data].
|
|
87
43
|
*
|
|
@@ -100,6 +56,12 @@ export type Options = {
|
|
|
100
56
|
* @private
|
|
101
57
|
*/
|
|
102
58
|
pathParamsType?: 'object' | 'inline'
|
|
59
|
+
/**
|
|
60
|
+
* Which parser can be used before returning the data
|
|
61
|
+
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
62
|
+
* @default 'client'
|
|
63
|
+
*/
|
|
64
|
+
parser?: 'client' | 'zod'
|
|
103
65
|
transformers?: {
|
|
104
66
|
/**
|
|
105
67
|
* Customize the names based on the type that is provided by the plugin.
|
|
@@ -107,23 +69,19 @@ export type Options = {
|
|
|
107
69
|
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
|
|
108
70
|
}
|
|
109
71
|
/**
|
|
110
|
-
*
|
|
72
|
+
* Define some generators next to the client generators
|
|
111
73
|
*/
|
|
112
|
-
|
|
74
|
+
generators?: Array<Generator<PluginClient>>
|
|
113
75
|
}
|
|
114
76
|
|
|
115
77
|
type ResolvedOptions = {
|
|
116
|
-
|
|
78
|
+
output: Output
|
|
79
|
+
group?: Options['group']
|
|
117
80
|
baseURL: string | undefined
|
|
118
|
-
|
|
81
|
+
parser: NonNullable<Options['parser']>
|
|
82
|
+
importPath: NonNullable<Options['importPath']>
|
|
119
83
|
dataReturnType: NonNullable<Options['dataReturnType']>
|
|
120
84
|
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
121
|
-
templates: NonNullable<Templates>
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export type FileMeta = {
|
|
125
|
-
pluginKey?: Plugin['key']
|
|
126
|
-
tag?: string
|
|
127
85
|
}
|
|
128
86
|
|
|
129
87
|
export type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, never, ResolvePathOptions>
|
package/dist/chunk-AZDWYBLW.cjs
DELETED
|
@@ -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"}
|
package/dist/chunk-GHHJWXKQ.cjs
DELETED
|
@@ -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,IAA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A,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"]}
|
package/dist/chunk-OODSLPAP.js
DELETED
|
@@ -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,GAAG;AAChC,UAAM,EAAE,YAAY,SAAS,QAAQ,IAAI,oBAAoB;AAE7D,UAAM,OAAO,QAAQ,WAAW,EAAE,MAAM,WAAW,CAAC;AACpD,UAAM,eAAe,WAAW,WAAW,EAAE,WAAW,CAAC,YAAY,GAAG,MAAM,OAAO,CAAC;AACtF,UAAM,OAAO,QAAQ,SAAS;AAC9B,UAAM,WAAW,QAAQ,WAAW,EAAE,WAAW,CAAC,YAAY,EAAE,CAAC;AAEjE,QAAI,CAAC,QAAQ,UAAU,QAAQ;AAC7B,aAAO;AAAA,IACT;AAEA,UAAM,WAAW,QAAQ,UAAU,UAAU;AAE7C,WACE,qBAAC,QAAK,UAAU,KAAK,UAAU,MAAM,KAAK,MAAM,MAAM,KAAK,MACzD;AAAA,0BAAC,KAAK,QAAL,EAAY,MAAM,UAAU,MAAM,QAAQ,OAAO,YAAY;AAAA,MAC9D,oBAAC,KAAK,QAAL,EAAY,MAAM,CAAC,gBAAgB,GAAG,MAAM,QAAQ,OAAO,YAAY,YAAU,MAAC;AAAA,MACnF;AAAA,QAAC,KAAK;AAAA,QAAL;AAAA,UACC,SAAS,QAAQ;AAAA,UACjB,MAAM;AAAA,YACJ,aAAa,SAAS;AAAA,YACtB,aAAa,SAAS;AAAA,YACtB,aAAa,YAAY;AAAA,YACzB,aAAa,aAAa;AAAA,YAC1B,aAAa,cAAc;AAAA,UAC7B,EAAE,OAAO,OAAO;AAAA,UAChB,MAAM,KAAK;AAAA,UACX,MAAM,SAAS;AAAA,UACf,YAAU;AAAA;AAAA,MACZ;AAAA,MACA,oBAAC,YAAS,MAAY,SAAkB,cAA4B,WAAsB;AAAA,OAC5F;AAAA,EAEJ;AACF,CAAC;","names":[]}
|
package/dist/chunk-W256NILH.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
// src/components/Client.tsx
|
|
2
|
-
import { URLPath } from "@kubb/core/utils";
|
|
3
|
-
import { isOptional } from "@kubb/oas";
|
|
4
|
-
import { getComments, getPathParams } from "@kubb/plugin-oas/utils";
|
|
5
|
-
import { File, Function, createParams } from "@kubb/react";
|
|
6
|
-
import { jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
7
|
-
function Client({ name, options, typedSchemas, operation }) {
|
|
8
|
-
const contentType = operation.getContentType();
|
|
9
|
-
const baseURL = options.client.importPath === "@kubb/plugin-client/client" ? options.baseURL : void 0;
|
|
10
|
-
const path = new URLPath(operation.path);
|
|
11
|
-
const isFormData = contentType === "multipart/form-data";
|
|
12
|
-
const headers = [
|
|
13
|
-
contentType !== "application/json" ? `'Content-Type': '${contentType}'` : void 0,
|
|
14
|
-
typedSchemas.headerParams?.name ? "...headers" : void 0
|
|
15
|
-
].filter(Boolean);
|
|
16
|
-
const params = createParams({
|
|
17
|
-
pathParams: {
|
|
18
|
-
mode: options.pathParamsType === "object" ? "object" : "inlineSpread",
|
|
19
|
-
children: getPathParams(typedSchemas.pathParams, { typed: true })
|
|
20
|
-
},
|
|
21
|
-
data: typedSchemas.request?.name ? {
|
|
22
|
-
type: typedSchemas.request?.name,
|
|
23
|
-
optional: isOptional(typedSchemas.request?.schema)
|
|
24
|
-
} : void 0,
|
|
25
|
-
params: typedSchemas.queryParams?.name ? {
|
|
26
|
-
type: typedSchemas.queryParams?.name,
|
|
27
|
-
optional: isOptional(typedSchemas.queryParams?.schema)
|
|
28
|
-
} : void 0,
|
|
29
|
-
headers: typedSchemas.headerParams?.name ? {
|
|
30
|
-
type: typedSchemas.headerParams?.name,
|
|
31
|
-
optional: isOptional(typedSchemas.headerParams?.schema)
|
|
32
|
-
} : void 0,
|
|
33
|
-
options: {
|
|
34
|
-
type: "Partial<Parameters<typeof client>[0]>",
|
|
35
|
-
default: "{}"
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
const clientParams = createParams({
|
|
39
|
-
data: {
|
|
40
|
-
mode: "object",
|
|
41
|
-
children: {
|
|
42
|
-
method: {
|
|
43
|
-
type: "string",
|
|
44
|
-
value: JSON.stringify(operation.method)
|
|
45
|
-
},
|
|
46
|
-
url: {
|
|
47
|
-
type: "string",
|
|
48
|
-
value: path.template
|
|
49
|
-
},
|
|
50
|
-
baseURL: baseURL ? {
|
|
51
|
-
type: "string",
|
|
52
|
-
value: JSON.stringify(baseURL)
|
|
53
|
-
} : void 0,
|
|
54
|
-
params: typedSchemas.queryParams?.name ? {
|
|
55
|
-
type: "any"
|
|
56
|
-
} : void 0,
|
|
57
|
-
data: typedSchemas.request?.name ? {
|
|
58
|
-
type: "any",
|
|
59
|
-
value: isFormData ? "formData" : void 0
|
|
60
|
-
} : void 0,
|
|
61
|
-
headers: headers.length ? {
|
|
62
|
-
type: "any",
|
|
63
|
-
value: headers.length ? `{ ${headers.join(", ")}, ...options.headers }` : void 0
|
|
64
|
-
} : void 0,
|
|
65
|
-
options: {
|
|
66
|
-
type: "any",
|
|
67
|
-
mode: "inlineSpread"
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
const formData = isFormData ? `
|
|
73
|
-
const formData = new FormData()
|
|
74
|
-
if(data) {
|
|
75
|
-
Object.keys(data).forEach((key) => {
|
|
76
|
-
const value = data[key];
|
|
77
|
-
if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
|
|
78
|
-
formData.append(key, value);
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
` : void 0;
|
|
83
|
-
return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxs(
|
|
84
|
-
Function,
|
|
85
|
-
{
|
|
86
|
-
name,
|
|
87
|
-
async: true,
|
|
88
|
-
export: true,
|
|
89
|
-
returnType: options.dataReturnType === "data" ? `ResponseConfig<${typedSchemas.response.name}>["data"]` : `ResponseConfig<${typedSchemas.response.name}>`,
|
|
90
|
-
params,
|
|
91
|
-
JSDoc: {
|
|
92
|
-
comments: getComments(operation)
|
|
93
|
-
},
|
|
94
|
-
children: [
|
|
95
|
-
formData || "",
|
|
96
|
-
/* @__PURE__ */ jsx(
|
|
97
|
-
Function.Call,
|
|
98
|
-
{
|
|
99
|
-
name: "res",
|
|
100
|
-
to: /* @__PURE__ */ jsx(Function, { name: "client", async: true, generics: [typedSchemas.response.name, typedSchemas.request?.name].filter(Boolean), params: clientParams })
|
|
101
|
-
}
|
|
102
|
-
),
|
|
103
|
-
/* @__PURE__ */ jsx(Function.Return, { children: options.dataReturnType === "data" ? "res.data" : "res" })
|
|
104
|
-
]
|
|
105
|
-
}
|
|
106
|
-
) });
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// src/components/Operations.tsx
|
|
110
|
-
import { URLPath as URLPath2 } from "@kubb/core/utils";
|
|
111
|
-
import { Const, File as File2 } from "@kubb/react";
|
|
112
|
-
import { jsx as jsx2 } from "@kubb/react/jsx-runtime";
|
|
113
|
-
function Operations({ name, operations }) {
|
|
114
|
-
const operationsObject = {};
|
|
115
|
-
operations.forEach((operation) => {
|
|
116
|
-
operationsObject[operation.getOperationId()] = {
|
|
117
|
-
path: new URLPath2(operation.path).URL,
|
|
118
|
-
method: operation.method
|
|
119
|
-
};
|
|
120
|
-
});
|
|
121
|
-
return /* @__PURE__ */ jsx2(File2.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx2(Const, { name, export: true, asConst: true, children: JSON.stringify(operationsObject, void 0, 2) }) });
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export {
|
|
125
|
-
Client,
|
|
126
|
-
Operations
|
|
127
|
-
};
|
|
128
|
-
//# sourceMappingURL=chunk-W256NILH.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Client.tsx","../src/components/Operations.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\n\nimport { type Operation, isOptional } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments, getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, createParams } from '@kubb/react'\nimport type { KubbNode, Params } from '@kubb/react/types'\nimport type { PluginClient } from '../types.ts'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n options: PluginClient['resolvedOptions']\n typedSchemas: OperationSchemas\n operation: Operation\n}\n\nexport function Client({ name, options, typedSchemas, operation }: Props): KubbNode {\n const contentType = operation.getContentType()\n const baseURL = options.client.importPath === '@kubb/plugin-client/client' ? options.baseURL : undefined\n const path = new URLPath(operation.path)\n const isFormData = contentType === 'multipart/form-data'\n const headers = [\n contentType !== 'application/json' ? `'Content-Type': '${contentType}'` : undefined,\n typedSchemas.headerParams?.name ? '...headers' : undefined,\n ].filter(Boolean)\n\n const params = createParams({\n pathParams: {\n mode: options.pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typedSchemas.pathParams, { typed: true }),\n },\n data: typedSchemas.request?.name\n ? {\n type: typedSchemas.request?.name,\n optional: isOptional(typedSchemas.request?.schema),\n }\n : undefined,\n params: typedSchemas.queryParams?.name\n ? {\n type: typedSchemas.queryParams?.name,\n optional: isOptional(typedSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typedSchemas.headerParams?.name\n ? {\n type: typedSchemas.headerParams?.name,\n optional: isOptional(typedSchemas.headerParams?.schema),\n }\n : undefined,\n options: {\n type: 'Partial<Parameters<typeof client>[0]>',\n default: '{}',\n },\n })\n\n const clientParams = createParams({\n data: {\n mode: 'object',\n children: {\n method: {\n type: 'string',\n value: JSON.stringify(operation.method),\n },\n url: {\n type: 'string',\n value: path.template,\n },\n baseURL: baseURL\n ? {\n type: 'string',\n value: JSON.stringify(baseURL),\n }\n : undefined,\n params: typedSchemas.queryParams?.name\n ? {\n type: 'any',\n }\n : undefined,\n data: typedSchemas.request?.name\n ? {\n type: 'any',\n value: isFormData ? 'formData' : undefined,\n }\n : undefined,\n headers: headers.length\n ? {\n type: 'any',\n value: headers.length ? `{ ${headers.join(', ')}, ...options.headers }` : undefined,\n }\n : undefined,\n options: {\n type: 'any',\n mode: 'inlineSpread',\n },\n },\n },\n })\n\n const formData = isFormData\n ? `\n const formData = new FormData()\n if(data) {\n Object.keys(data).forEach((key) => {\n const value = data[key];\n if (typeof key === \"string\" && (typeof value === \"string\" || value instanceof Blob)) {\n formData.append(key, value);\n }\n })\n }\n `\n : undefined\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function\n name={name}\n async\n export\n returnType={\n options.dataReturnType === 'data' ? `ResponseConfig<${typedSchemas.response.name}>[\"data\"]` : `ResponseConfig<${typedSchemas.response.name}>`\n }\n params={params}\n JSDoc={{\n comments: getComments(operation),\n }}\n >\n {formData || ''}\n <Function.Call\n name=\"res\"\n to={<Function name=\"client\" async generics={[typedSchemas.response.name, typedSchemas.request?.name].filter(Boolean)} params={clientParams} />}\n />\n <Function.Return>{options.dataReturnType === 'data' ? 'res.data' : 'res'}</Function.Return>\n </Function>\n </File.Source>\n )\n}\n","import { URLPath } from '@kubb/core/utils'\nimport { Const, File } from '@kubb/react'\n\nimport type { HttpMethod, Operation } from '@kubb/oas'\n\ntype OperationsProps = {\n name: string\n operations: Array<Operation>\n}\n\nexport function Operations({ name, operations }: OperationsProps) {\n const operationsObject: Record<string, { path: string; method: HttpMethod }> = {}\n\n operations.forEach((operation) => {\n operationsObject[operation.getOperationId()] = {\n path: new URLPath(operation.path).URL,\n method: operation.method,\n }\n })\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Const name={name} export asConst>\n {JSON.stringify(operationsObject, undefined, 2)}\n </Const>\n </File.Source>\n )\n}\n"],"mappings":";AAAA,SAAS,eAAe;AAExB,SAAyB,kBAAkB;AAE3C,SAAS,aAAa,qBAAqB;AAC3C,SAAS,MAAM,UAAU,oBAAoB;AAgHvC,SAeQ,KAfR;AAlGC,SAAS,OAAO,EAAE,MAAM,SAAS,cAAc,UAAU,GAAoB;AAClF,QAAM,cAAc,UAAU,eAAe;AAC7C,QAAM,UAAU,QAAQ,OAAO,eAAe,+BAA+B,QAAQ,UAAU;AAC/F,QAAM,OAAO,IA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