@kubb/plugin-client 3.0.0-alpha.13 → 3.0.0-alpha.15
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/{chunk-QBFKND4S.js → chunk-BAX6ZFGY.js} +3 -3
- package/dist/chunk-BAX6ZFGY.js.map +1 -0
- package/dist/chunk-H2OOHGK2.js +147 -0
- package/dist/chunk-H2OOHGK2.js.map +1 -0
- package/dist/chunk-TNO4CNBR.cjs +156 -0
- package/dist/chunk-TNO4CNBR.cjs.map +1 -0
- package/dist/{chunk-PO22ZUSH.cjs → chunk-XDWPA5EL.cjs} +3 -3
- package/dist/chunk-XDWPA5EL.cjs.map +1 -0
- package/dist/components.cjs +3 -4
- package/dist/components.d.cts +10 -2
- package/dist/components.d.ts +10 -2
- package/dist/components.js +1 -2
- package/dist/generators.cjs +8 -4
- package/dist/generators.d.cts +5 -3
- package/dist/generators.d.ts +5 -3
- package/dist/generators.js +2 -2
- package/dist/index.cjs +9 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -106
- package/dist/index.js.map +1 -1
- package/dist/{types-DETYKDFZ.d.cts → types-CzL-44IA.d.cts} +18 -34
- package/dist/{types-DETYKDFZ.d.ts → types-CzL-44IA.d.ts} +18 -34
- package/package.json +12 -12
- package/src/components/Client.tsx +2 -2
- package/src/generators/{axiosGenerator.tsx → clientGenerator.tsx} +9 -26
- package/src/generators/index.ts +2 -1
- package/src/generators/operationsGenerator.tsx +21 -0
- package/src/plugin.ts +8 -15
- package/src/types.ts +17 -28
- package/dist/chunk-3NQF7BGA.cjs +0 -58
- package/dist/chunk-3NQF7BGA.cjs.map +0 -1
- package/dist/chunk-AZDWYBLW.cjs +0 -4
- package/dist/chunk-AZDWYBLW.cjs.map +0 -1
- package/dist/chunk-PO22ZUSH.cjs.map +0 -1
- package/dist/chunk-QBFKND4S.js.map +0 -1
- package/dist/chunk-QLVGX3VO.js +0 -56
- package/dist/chunk-QLVGX3VO.js.map +0 -1
- package/dist/chunk-YJOVLRSC.js +0 -3
- package/dist/chunk-YJOVLRSC.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,115 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./chunk-
|
|
4
|
-
|
|
5
|
-
var chunkPO22ZUSH_cjs = require('./chunk-PO22ZUSH.cjs');
|
|
6
|
-
var path = require('path');
|
|
7
|
-
var core = require('@kubb/core');
|
|
8
|
-
var transformers = require('@kubb/core/transformers');
|
|
9
|
-
var utils = require('@kubb/core/utils');
|
|
10
|
-
var pluginOas = require('@kubb/plugin-oas');
|
|
3
|
+
var chunkTNO4CNBR_cjs = require('./chunk-TNO4CNBR.cjs');
|
|
4
|
+
require('./chunk-XDWPA5EL.cjs');
|
|
11
5
|
|
|
12
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
6
|
|
|
14
|
-
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
15
7
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
override = [],
|
|
24
|
-
transformers: transformers$1 = {},
|
|
25
|
-
dataReturnType = "data",
|
|
26
|
-
pathParamsType = "inline",
|
|
27
|
-
templates
|
|
28
|
-
} = options;
|
|
29
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
30
|
-
return {
|
|
31
|
-
name: pluginClientName,
|
|
32
|
-
output: {
|
|
33
|
-
exportType: "barrelNamed",
|
|
34
|
-
...output
|
|
35
|
-
},
|
|
36
|
-
options: {
|
|
37
|
-
extName: output.extName,
|
|
38
|
-
dataReturnType,
|
|
39
|
-
client: {
|
|
40
|
-
importPath: "@kubb/plugin-client/client",
|
|
41
|
-
methods: ["get", "post", "delete", "put"],
|
|
42
|
-
...options.client
|
|
43
|
-
},
|
|
44
|
-
pathParamsType,
|
|
45
|
-
templates: {
|
|
46
|
-
operations: chunkPO22ZUSH_cjs.Operations,
|
|
47
|
-
client: chunkPO22ZUSH_cjs.Client,
|
|
48
|
-
...templates
|
|
49
|
-
},
|
|
50
|
-
baseURL: void 0
|
|
51
|
-
},
|
|
52
|
-
pre: [pluginOas.pluginOasName],
|
|
53
|
-
resolvePath(baseName, pathMode, options2) {
|
|
54
|
-
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
55
|
-
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
56
|
-
if (mode === "single") {
|
|
57
|
-
return path__default.default.resolve(root, output.path);
|
|
58
|
-
}
|
|
59
|
-
if (options2?.tag && group?.type === "tag") {
|
|
60
|
-
const tag = transformers.camelCase(options2.tag);
|
|
61
|
-
return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
|
|
62
|
-
}
|
|
63
|
-
return path__default.default.resolve(root, output.path, baseName);
|
|
64
|
-
},
|
|
65
|
-
resolveName(name, type) {
|
|
66
|
-
const resolvedName = transformers.camelCase(name, { isFile: type === "file" });
|
|
67
|
-
if (type) {
|
|
68
|
-
return transformers$1?.name?.(resolvedName, type) || resolvedName;
|
|
69
|
-
}
|
|
70
|
-
return resolvedName;
|
|
71
|
-
},
|
|
72
|
-
async buildStart() {
|
|
73
|
-
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
74
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
75
|
-
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
76
|
-
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
77
|
-
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
78
|
-
const operationGenerator = new pluginOas.OperationGenerator(
|
|
79
|
-
{
|
|
80
|
-
...this.plugin.options,
|
|
81
|
-
baseURL
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
oas,
|
|
85
|
-
pluginManager: this.pluginManager,
|
|
86
|
-
plugin: this.plugin,
|
|
87
|
-
contentType: swaggerPlugin.context.contentType,
|
|
88
|
-
exclude,
|
|
89
|
-
include,
|
|
90
|
-
override,
|
|
91
|
-
mode
|
|
92
|
-
}
|
|
93
|
-
);
|
|
94
|
-
const files = await operationGenerator.build(chunk3NQF7BGA_cjs.axiosGenerator);
|
|
95
|
-
await this.addFile(...files);
|
|
96
|
-
if (this.config.output.exportType) {
|
|
97
|
-
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
98
|
-
root,
|
|
99
|
-
output,
|
|
100
|
-
files: this.fileManager.files,
|
|
101
|
-
meta: {
|
|
102
|
-
pluginKey: this.plugin.key
|
|
103
|
-
},
|
|
104
|
-
logger: this.logger
|
|
105
|
-
});
|
|
106
|
-
await this.addFile(...barrelFiles);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
};
|
|
8
|
+
Object.defineProperty(exports, "pluginClient", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkTNO4CNBR_cjs.pluginClient; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "pluginClientName", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunkTNO4CNBR_cjs.pluginClientName; }
|
|
110
15
|
});
|
|
111
|
-
|
|
112
|
-
exports.pluginClient = pluginClient;
|
|
113
|
-
exports.pluginClientName = pluginClientName;
|
|
114
16
|
//# sourceMappingURL=index.cjs.map
|
|
115
17
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
|
2
|
-
import { O as Options, P as PluginClient } from './types-
|
|
2
|
+
import { O as Options, P as PluginClient } from './types-CzL-44IA.cjs';
|
|
3
3
|
import '@kubb/fs/types';
|
|
4
|
-
import '@kubb/oas';
|
|
5
4
|
import '@kubb/plugin-oas';
|
|
5
|
+
import '@kubb/oas';
|
|
6
6
|
import '@kubb/react/types';
|
|
7
7
|
|
|
8
8
|
declare const pluginClientName = "plugin-client";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
|
2
|
-
import { O as Options, P as PluginClient } from './types-
|
|
2
|
+
import { O as Options, P as PluginClient } from './types-CzL-44IA.js';
|
|
3
3
|
import '@kubb/fs/types';
|
|
4
|
-
import '@kubb/oas';
|
|
5
4
|
import '@kubb/plugin-oas';
|
|
5
|
+
import '@kubb/oas';
|
|
6
6
|
import '@kubb/react/types';
|
|
7
7
|
|
|
8
8
|
declare const pluginClientName = "plugin-client";
|
package/dist/index.js
CHANGED
|
@@ -1,108 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import { Operations, Client } from './chunk-QBFKND4S.js';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
6
|
-
import { camelCase } from '@kubb/core/transformers';
|
|
7
|
-
import { renderTemplate } from '@kubb/core/utils';
|
|
8
|
-
import { pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
|
|
9
|
-
|
|
10
|
-
var pluginClientName = "plugin-client";
|
|
11
|
-
var pluginClient = createPlugin((options) => {
|
|
12
|
-
const {
|
|
13
|
-
output = { path: "clients" },
|
|
14
|
-
group,
|
|
15
|
-
exclude = [],
|
|
16
|
-
include,
|
|
17
|
-
override = [],
|
|
18
|
-
transformers = {},
|
|
19
|
-
dataReturnType = "data",
|
|
20
|
-
pathParamsType = "inline",
|
|
21
|
-
templates
|
|
22
|
-
} = options;
|
|
23
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
24
|
-
return {
|
|
25
|
-
name: pluginClientName,
|
|
26
|
-
output: {
|
|
27
|
-
exportType: "barrelNamed",
|
|
28
|
-
...output
|
|
29
|
-
},
|
|
30
|
-
options: {
|
|
31
|
-
extName: output.extName,
|
|
32
|
-
dataReturnType,
|
|
33
|
-
client: {
|
|
34
|
-
importPath: "@kubb/plugin-client/client",
|
|
35
|
-
methods: ["get", "post", "delete", "put"],
|
|
36
|
-
...options.client
|
|
37
|
-
},
|
|
38
|
-
pathParamsType,
|
|
39
|
-
templates: {
|
|
40
|
-
operations: Operations,
|
|
41
|
-
client: Client,
|
|
42
|
-
...templates
|
|
43
|
-
},
|
|
44
|
-
baseURL: void 0
|
|
45
|
-
},
|
|
46
|
-
pre: [pluginOasName],
|
|
47
|
-
resolvePath(baseName, pathMode, options2) {
|
|
48
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
49
|
-
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
50
|
-
if (mode === "single") {
|
|
51
|
-
return path.resolve(root, output.path);
|
|
52
|
-
}
|
|
53
|
-
if (options2?.tag && group?.type === "tag") {
|
|
54
|
-
const tag = camelCase(options2.tag);
|
|
55
|
-
return path.resolve(root, renderTemplate(template, { tag }), baseName);
|
|
56
|
-
}
|
|
57
|
-
return path.resolve(root, output.path, baseName);
|
|
58
|
-
},
|
|
59
|
-
resolveName(name, type) {
|
|
60
|
-
const resolvedName = camelCase(name, { isFile: type === "file" });
|
|
61
|
-
if (type) {
|
|
62
|
-
return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
63
|
-
}
|
|
64
|
-
return resolvedName;
|
|
65
|
-
},
|
|
66
|
-
async buildStart() {
|
|
67
|
-
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
68
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
69
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
70
|
-
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
71
|
-
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
72
|
-
const operationGenerator = new OperationGenerator(
|
|
73
|
-
{
|
|
74
|
-
...this.plugin.options,
|
|
75
|
-
baseURL
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
oas,
|
|
79
|
-
pluginManager: this.pluginManager,
|
|
80
|
-
plugin: this.plugin,
|
|
81
|
-
contentType: swaggerPlugin.context.contentType,
|
|
82
|
-
exclude,
|
|
83
|
-
include,
|
|
84
|
-
override,
|
|
85
|
-
mode
|
|
86
|
-
}
|
|
87
|
-
);
|
|
88
|
-
const files = await operationGenerator.build(axiosGenerator);
|
|
89
|
-
await this.addFile(...files);
|
|
90
|
-
if (this.config.output.exportType) {
|
|
91
|
-
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
92
|
-
root,
|
|
93
|
-
output,
|
|
94
|
-
files: this.fileManager.files,
|
|
95
|
-
meta: {
|
|
96
|
-
pluginKey: this.plugin.key
|
|
97
|
-
},
|
|
98
|
-
logger: this.logger
|
|
99
|
-
});
|
|
100
|
-
await this.addFile(...barrelFiles);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
export { pluginClient, pluginClientName };
|
|
1
|
+
export { pluginClient, pluginClientName } from './chunk-H2OOHGK2.js';
|
|
2
|
+
import './chunk-BAX6ZFGY.js';
|
|
107
3
|
//# sourceMappingURL=index.js.map
|
|
108
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
|
|
2
2
|
import * as KubbFile from '@kubb/fs/types';
|
|
3
|
-
import { Operation, HttpMethod } from '@kubb/oas';
|
|
4
3
|
import { OperationSchemas, ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
|
|
4
|
+
import { Operation } from '@kubb/oas';
|
|
5
5
|
import { KubbNode } from '@kubb/react/types';
|
|
6
6
|
|
|
7
7
|
type Props = {
|
|
@@ -15,16 +15,6 @@ type Props = {
|
|
|
15
15
|
};
|
|
16
16
|
declare function Client({ name, options, typedSchemas, operation }: Props): KubbNode;
|
|
17
17
|
|
|
18
|
-
type OperationsProps = {
|
|
19
|
-
name: string;
|
|
20
|
-
operations: Array<Operation>;
|
|
21
|
-
};
|
|
22
|
-
declare function Operations({ name, operations }: OperationsProps): JSX.Element;
|
|
23
|
-
|
|
24
|
-
type Templates = {
|
|
25
|
-
operations?: typeof Operations | false;
|
|
26
|
-
client?: typeof Client | false;
|
|
27
|
-
};
|
|
28
18
|
type Options = {
|
|
29
19
|
output?: {
|
|
30
20
|
/**
|
|
@@ -80,21 +70,20 @@ type Options = {
|
|
|
80
70
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
81
71
|
*/
|
|
82
72
|
override?: Array<Override<ResolvedOptions>>;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
};
|
|
73
|
+
/**
|
|
74
|
+
* Create `operations.ts` file with all operations grouped by methods.
|
|
75
|
+
* @default `false`
|
|
76
|
+
*/
|
|
77
|
+
operations?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Path to the client import path that will be used to do the API calls.
|
|
80
|
+
* It will be used as `import client from '${client.importPath}'`.
|
|
81
|
+
* It allows both relative and absolute path.
|
|
82
|
+
* the path will be applied as is, so relative path should be based on the file being generated.
|
|
83
|
+
* @default '@kubb/plugin-client/client'
|
|
84
|
+
*/
|
|
85
|
+
importPath?: string;
|
|
86
|
+
template?: typeof Client;
|
|
98
87
|
/**
|
|
99
88
|
* ReturnType that needs to be used when calling client().
|
|
100
89
|
*
|
|
@@ -121,19 +110,14 @@ type Options = {
|
|
|
121
110
|
*/
|
|
122
111
|
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
123
112
|
};
|
|
124
|
-
/**
|
|
125
|
-
* Make it possible to override one of the templates
|
|
126
|
-
*/
|
|
127
|
-
templates?: Partial<Templates>;
|
|
128
113
|
};
|
|
129
114
|
type ResolvedOptions = {
|
|
130
|
-
extName: KubbFile.Extname | undefined;
|
|
131
115
|
baseURL: string | undefined;
|
|
132
|
-
|
|
116
|
+
importPath: NonNullable<Options['importPath']>;
|
|
117
|
+
template: NonNullable<Options['template']>;
|
|
133
118
|
dataReturnType: NonNullable<Options['dataReturnType']>;
|
|
134
119
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
135
|
-
templates: NonNullable<Templates>;
|
|
136
120
|
};
|
|
137
121
|
type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
138
122
|
|
|
139
|
-
export { Client as C, type Options as O, type PluginClient as P
|
|
123
|
+
export { Client as C, type Options as O, type PluginClient as P };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
|
|
2
2
|
import * as KubbFile from '@kubb/fs/types';
|
|
3
|
-
import { Operation, HttpMethod } from '@kubb/oas';
|
|
4
3
|
import { OperationSchemas, ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
|
|
4
|
+
import { Operation } from '@kubb/oas';
|
|
5
5
|
import { KubbNode } from '@kubb/react/types';
|
|
6
6
|
|
|
7
7
|
type Props = {
|
|
@@ -15,16 +15,6 @@ type Props = {
|
|
|
15
15
|
};
|
|
16
16
|
declare function Client({ name, options, typedSchemas, operation }: Props): KubbNode;
|
|
17
17
|
|
|
18
|
-
type OperationsProps = {
|
|
19
|
-
name: string;
|
|
20
|
-
operations: Array<Operation>;
|
|
21
|
-
};
|
|
22
|
-
declare function Operations({ name, operations }: OperationsProps): JSX.Element;
|
|
23
|
-
|
|
24
|
-
type Templates = {
|
|
25
|
-
operations?: typeof Operations | false;
|
|
26
|
-
client?: typeof Client | false;
|
|
27
|
-
};
|
|
28
18
|
type Options = {
|
|
29
19
|
output?: {
|
|
30
20
|
/**
|
|
@@ -80,21 +70,20 @@ type Options = {
|
|
|
80
70
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
81
71
|
*/
|
|
82
72
|
override?: Array<Override<ResolvedOptions>>;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
};
|
|
73
|
+
/**
|
|
74
|
+
* Create `operations.ts` file with all operations grouped by methods.
|
|
75
|
+
* @default `false`
|
|
76
|
+
*/
|
|
77
|
+
operations?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Path to the client import path that will be used to do the API calls.
|
|
80
|
+
* It will be used as `import client from '${client.importPath}'`.
|
|
81
|
+
* It allows both relative and absolute path.
|
|
82
|
+
* the path will be applied as is, so relative path should be based on the file being generated.
|
|
83
|
+
* @default '@kubb/plugin-client/client'
|
|
84
|
+
*/
|
|
85
|
+
importPath?: string;
|
|
86
|
+
template?: typeof Client;
|
|
98
87
|
/**
|
|
99
88
|
* ReturnType that needs to be used when calling client().
|
|
100
89
|
*
|
|
@@ -121,19 +110,14 @@ type Options = {
|
|
|
121
110
|
*/
|
|
122
111
|
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
123
112
|
};
|
|
124
|
-
/**
|
|
125
|
-
* Make it possible to override one of the templates
|
|
126
|
-
*/
|
|
127
|
-
templates?: Partial<Templates>;
|
|
128
113
|
};
|
|
129
114
|
type ResolvedOptions = {
|
|
130
|
-
extName: KubbFile.Extname | undefined;
|
|
131
115
|
baseURL: string | undefined;
|
|
132
|
-
|
|
116
|
+
importPath: NonNullable<Options['importPath']>;
|
|
117
|
+
template: NonNullable<Options['template']>;
|
|
133
118
|
dataReturnType: NonNullable<Options['dataReturnType']>;
|
|
134
119
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
135
|
-
templates: NonNullable<Templates>;
|
|
136
120
|
};
|
|
137
121
|
type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
138
122
|
|
|
139
|
-
export { Client as C, type Options as O, type PluginClient as P
|
|
123
|
+
export { Client as C, type Options as O, type PluginClient as P };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-client",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.15",
|
|
4
4
|
"description": "Generator plugin-client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -72,13 +72,13 @@
|
|
|
72
72
|
"!/**/__tests__/**"
|
|
73
73
|
],
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@kubb/core": "3.0.0-alpha.
|
|
76
|
-
"@kubb/fs": "3.0.0-alpha.
|
|
77
|
-
"@kubb/oas": "3.0.0-alpha.
|
|
78
|
-
"@kubb/parser-ts": "3.0.0-alpha.
|
|
79
|
-
"@kubb/plugin-oas": "3.0.0-alpha.
|
|
80
|
-
"@kubb/plugin-ts": "3.0.0-alpha.
|
|
81
|
-
"@kubb/react": "3.0.0-alpha.
|
|
75
|
+
"@kubb/core": "3.0.0-alpha.15",
|
|
76
|
+
"@kubb/fs": "3.0.0-alpha.15",
|
|
77
|
+
"@kubb/oas": "3.0.0-alpha.15",
|
|
78
|
+
"@kubb/parser-ts": "3.0.0-alpha.15",
|
|
79
|
+
"@kubb/plugin-oas": "3.0.0-alpha.15",
|
|
80
|
+
"@kubb/plugin-ts": "3.0.0-alpha.15",
|
|
81
|
+
"@kubb/react": "3.0.0-alpha.15"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@types/react": "^18.3.5",
|
|
@@ -86,13 +86,13 @@
|
|
|
86
86
|
"react": "^18.3.1",
|
|
87
87
|
"tsup": "^8.2.4",
|
|
88
88
|
"typescript": "^5.5.4",
|
|
89
|
-
"@kubb/config-biome": "3.0.0-alpha.
|
|
90
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
91
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
89
|
+
"@kubb/config-biome": "3.0.0-alpha.15",
|
|
90
|
+
"@kubb/config-ts": "3.0.0-alpha.15",
|
|
91
|
+
"@kubb/config-tsup": "3.0.0-alpha.15"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
94
|
"axios": "^1.7.2",
|
|
95
|
-
"@kubb/react": "3.0.0-alpha.
|
|
95
|
+
"@kubb/react": "3.0.0-alpha.15"
|
|
96
96
|
},
|
|
97
97
|
"peerDependenciesMeta": {
|
|
98
98
|
"axios": {
|
|
@@ -4,7 +4,7 @@ import { type Operation, isOptional } from '@kubb/oas'
|
|
|
4
4
|
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
5
5
|
import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
|
|
6
6
|
import { File, Function, createFunctionParams } from '@kubb/react'
|
|
7
|
-
import type { KubbNode
|
|
7
|
+
import type { KubbNode } from '@kubb/react/types'
|
|
8
8
|
import type { PluginClient } from '../types.ts'
|
|
9
9
|
|
|
10
10
|
type Props = {
|
|
@@ -19,7 +19,7 @@ type Props = {
|
|
|
19
19
|
|
|
20
20
|
export function Client({ name, options, typedSchemas, operation }: Props): KubbNode {
|
|
21
21
|
const contentType = operation.getContentType()
|
|
22
|
-
const baseURL = options.
|
|
22
|
+
const baseURL = options.baseURL
|
|
23
23
|
const path = new URLPath(operation.path)
|
|
24
24
|
const isFormData = contentType === 'multipart/form-data'
|
|
25
25
|
const headers = [
|
|
@@ -3,48 +3,31 @@ import { useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
|
3
3
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
4
4
|
import { File, useApp } from '@kubb/react'
|
|
5
5
|
import { Client } from '../components/Client'
|
|
6
|
-
import { Operations } from '../components/Operations'
|
|
7
6
|
import type { PluginClient } from '../types'
|
|
8
7
|
|
|
9
|
-
export const
|
|
8
|
+
export const clientGenerator = createReactGenerator<PluginClient>({
|
|
10
9
|
name: 'plugin-client',
|
|
11
|
-
Operations({ options, operations }) {
|
|
12
|
-
const { pluginManager } = useApp<PluginClient>()
|
|
13
|
-
|
|
14
|
-
if (!options.templates.operations) {
|
|
15
|
-
return null
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const Template = options.templates.operations || Operations
|
|
19
|
-
const name = 'operations'
|
|
20
|
-
const file = pluginManager.getFile({ name, extName: '.ts', pluginKey: ['plugin-client'] })
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<File baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
24
|
-
<Template name={name} operations={operations} />
|
|
25
|
-
</File>
|
|
26
|
-
)
|
|
27
|
-
},
|
|
28
10
|
Operation({ options, operation }) {
|
|
11
|
+
const { plugin } = useApp<PluginClient>()
|
|
29
12
|
const { getSchemas, getName, getFile } = useOperationManager()
|
|
30
13
|
|
|
31
14
|
const name = getName(operation, { type: 'function' })
|
|
32
15
|
const typedSchemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
|
|
33
16
|
const file = getFile(operation)
|
|
34
|
-
const
|
|
17
|
+
const typedFile = getFile(operation, { pluginKey: [pluginTsName] })
|
|
35
18
|
|
|
36
|
-
if (!options.
|
|
19
|
+
if (!options.template) {
|
|
37
20
|
return null
|
|
38
21
|
}
|
|
39
22
|
|
|
40
|
-
const Template = options.
|
|
23
|
+
const Template = options.template || Client
|
|
41
24
|
|
|
42
25
|
return (
|
|
43
26
|
<File baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
44
|
-
<File.Import name={'client'} path={options.client
|
|
45
|
-
<File.Import name={['ResponseConfig']} path={options.client
|
|
27
|
+
<File.Import name={'client'} path={options.importPath || '@kubb/plugin-client/client'} />
|
|
28
|
+
<File.Import name={['ResponseConfig']} path={options.importPath || '@kubb/plugin-client/client'} isTypeOnly />
|
|
46
29
|
<File.Import
|
|
47
|
-
extName={
|
|
30
|
+
extName={plugin.output?.extName}
|
|
48
31
|
name={[
|
|
49
32
|
typedSchemas.request?.name,
|
|
50
33
|
typedSchemas.response.name,
|
|
@@ -53,7 +36,7 @@ export const axiosGenerator = createReactGenerator<PluginClient>({
|
|
|
53
36
|
typedSchemas.headerParams?.name,
|
|
54
37
|
].filter(Boolean)}
|
|
55
38
|
root={file.path}
|
|
56
|
-
path={
|
|
39
|
+
path={typedFile.path}
|
|
57
40
|
isTypeOnly
|
|
58
41
|
/>
|
|
59
42
|
<Template name={name} options={options} typedSchemas={typedSchemas} operation={operation} />
|
package/src/generators/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { clientGenerator } from './clientGenerator.tsx'
|
|
2
|
+
export { operationsGenerator } from './operationsGenerator.tsx'
|
|
@@ -0,0 +1,21 @@
|
|
|
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: 'plugin-client',
|
|
9
|
+
Operations({ operations }) {
|
|
10
|
+
const { pluginManager } = useApp<PluginClient>()
|
|
11
|
+
|
|
12
|
+
const name = 'operations'
|
|
13
|
+
const file = pluginManager.getFile({ name, extName: '.ts', pluginKey: [pluginClientName] })
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<File baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
17
|
+
<Operations name={name} operations={operations} />
|
|
18
|
+
</File>
|
|
19
|
+
)
|
|
20
|
+
},
|
|
21
|
+
})
|