@kubb/plugin-swr 3.0.0-beta.9 → 3.0.1
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-4EGGCGSE.js → chunk-2CUWQAT4.js} +49 -28
- package/dist/chunk-2CUWQAT4.js.map +1 -0
- package/dist/{chunk-H23WKEYP.js → chunk-2KDZWGWG.js} +122 -23
- package/dist/chunk-2KDZWGWG.js.map +1 -0
- package/dist/{chunk-JWGWABV5.cjs → chunk-AFAHUG3Q.cjs} +129 -30
- package/dist/chunk-AFAHUG3Q.cjs.map +1 -0
- package/dist/{chunk-PTOQHHST.cjs → chunk-W7U2E4KO.cjs} +51 -30
- package/dist/chunk-W7U2E4KO.cjs.map +1 -0
- package/dist/components.cjs +6 -6
- package/dist/components.d.cts +15 -9
- package/dist/components.d.ts +15 -9
- package/dist/components.js +1 -1
- package/dist/generators.cjs +4 -4
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +2 -2
- package/dist/index.cjs +24 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +23 -24
- package/dist/index.js.map +1 -1
- package/dist/types-AhGZx7jH.d.cts +272 -0
- package/dist/types-AhGZx7jH.d.ts +272 -0
- package/package.json +14 -13
- package/src/components/Mutation.tsx +15 -4
- package/src/components/MutationKey.tsx +11 -5
- package/src/components/Query.tsx +63 -6
- package/src/components/QueryKey.tsx +17 -7
- package/src/components/QueryOptions.tsx +47 -7
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +11 -5
- package/src/generators/__snapshots__/clientGetImportPath.ts +11 -5
- package/src/generators/__snapshots__/findByTags.ts +11 -5
- package/src/generators/__snapshots__/findByTagsObject.ts +49 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +11 -5
- package/src/generators/__snapshots__/findByTagsWithZod.ts +11 -5
- package/src/generators/__snapshots__/postAsQuery.ts +14 -5
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +1 -3
- package/src/generators/mutationGenerator.tsx +29 -18
- package/src/generators/queryGenerator.tsx +32 -15
- package/src/plugin.ts +29 -26
- package/src/types.ts +71 -46
- package/dist/chunk-4EGGCGSE.js.map +0 -1
- package/dist/chunk-H23WKEYP.js.map +0 -1
- package/dist/chunk-JWGWABV5.cjs.map +0 -1
- package/dist/chunk-PTOQHHST.cjs.map +0 -1
- package/dist/types-Bt7A3YoC.d.cts +0 -101
- package/dist/types-Bt7A3YoC.d.ts +0 -101
package/dist/components.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Operation } from '@kubb/oas';
|
|
2
2
|
import { OperationSchemas } from '@kubb/plugin-oas';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
|
-
import { P as PluginSwr } from './types-
|
|
4
|
+
import { P as PluginSwr, T as Transformer } from './types-AhGZx7jH.cjs';
|
|
5
5
|
import { FunctionParams } from '@kubb/react';
|
|
6
6
|
import '@kubb/core';
|
|
7
7
|
import '@kubb/plugin-client';
|
|
@@ -17,10 +17,11 @@ type Props$4 = {
|
|
|
17
17
|
mutationKeyTypeName: string;
|
|
18
18
|
typeSchemas: OperationSchemas;
|
|
19
19
|
operation: Operation;
|
|
20
|
+
paramsType: PluginSwr['resolvedOptions']['paramsType'];
|
|
20
21
|
dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType'];
|
|
21
22
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
22
23
|
};
|
|
23
|
-
declare function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, pathParamsType, dataReturnType, typeSchemas, operation }: Props$4): ReactNode;
|
|
24
|
+
declare function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, paramsType, pathParamsType, dataReturnType, typeSchemas, operation, }: Props$4): ReactNode;
|
|
24
25
|
|
|
25
26
|
type Props$3 = {
|
|
26
27
|
/**
|
|
@@ -31,25 +32,28 @@ type Props$3 = {
|
|
|
31
32
|
queryKeyName: string;
|
|
32
33
|
queryKeyTypeName: string;
|
|
33
34
|
typeSchemas: OperationSchemas;
|
|
35
|
+
paramsType: PluginSwr['resolvedOptions']['paramsType'];
|
|
34
36
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
35
37
|
dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType'];
|
|
36
38
|
operation: Operation;
|
|
37
39
|
};
|
|
38
|
-
declare function Query({ name, typeSchemas, queryKeyName, queryKeyTypeName, queryOptionsName, operation, dataReturnType, pathParamsType }: Props$3): ReactNode;
|
|
40
|
+
declare function Query({ name, typeSchemas, queryKeyName, queryKeyTypeName, queryOptionsName, operation, dataReturnType, paramsType, pathParamsType, }: Props$3): ReactNode;
|
|
39
41
|
|
|
40
42
|
type Props$2 = {
|
|
41
43
|
name: string;
|
|
42
44
|
clientName: string;
|
|
43
45
|
typeSchemas: OperationSchemas;
|
|
46
|
+
paramsType: PluginSwr['resolvedOptions']['paramsType'];
|
|
44
47
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
45
48
|
};
|
|
46
49
|
type GetParamsProps$2 = {
|
|
50
|
+
paramsType: PluginSwr['resolvedOptions']['paramsType'];
|
|
47
51
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
48
52
|
typeSchemas: OperationSchemas;
|
|
49
53
|
};
|
|
50
|
-
declare function QueryOptions({ name, clientName, typeSchemas, pathParamsType }: Props$2): ReactNode;
|
|
54
|
+
declare function QueryOptions({ name, clientName, typeSchemas, paramsType, pathParamsType }: Props$2): ReactNode;
|
|
51
55
|
declare namespace QueryOptions {
|
|
52
|
-
var getParams: ({ pathParamsType, typeSchemas }: GetParamsProps$2) => FunctionParams;
|
|
56
|
+
var getParams: ({ paramsType, pathParamsType, typeSchemas }: GetParamsProps$2) => FunctionParams;
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
type Props$1 = {
|
|
@@ -58,15 +62,16 @@ type Props$1 = {
|
|
|
58
62
|
typeSchemas: OperationSchemas;
|
|
59
63
|
operation: Operation;
|
|
60
64
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
61
|
-
|
|
65
|
+
transformer: Transformer | undefined;
|
|
62
66
|
};
|
|
63
67
|
type GetParamsProps$1 = {
|
|
64
68
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
65
69
|
typeSchemas: OperationSchemas;
|
|
66
70
|
};
|
|
67
|
-
declare function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName,
|
|
71
|
+
declare function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer }: Props$1): ReactNode;
|
|
68
72
|
declare namespace QueryKey {
|
|
69
73
|
var getParams: ({ pathParamsType, typeSchemas }: GetParamsProps$1) => FunctionParams;
|
|
74
|
+
var getTransformer: Transformer;
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
type Props = {
|
|
@@ -75,15 +80,16 @@ type Props = {
|
|
|
75
80
|
typeSchemas: OperationSchemas;
|
|
76
81
|
operation: Operation;
|
|
77
82
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
78
|
-
|
|
83
|
+
transformer: Transformer | undefined;
|
|
79
84
|
};
|
|
80
85
|
type GetParamsProps = {
|
|
81
86
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
82
87
|
typeSchemas: OperationSchemas;
|
|
83
88
|
};
|
|
84
|
-
declare function MutationKey({ name, typeSchemas, pathParamsType, operation, typeName,
|
|
89
|
+
declare function MutationKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer }: Props): ReactNode;
|
|
85
90
|
declare namespace MutationKey {
|
|
86
91
|
var getParams: ({}: GetParamsProps) => FunctionParams;
|
|
92
|
+
var getTransformer: Transformer;
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
export { Mutation, MutationKey, Query, QueryKey, QueryOptions };
|
package/dist/components.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Operation } from '@kubb/oas';
|
|
2
2
|
import { OperationSchemas } from '@kubb/plugin-oas';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
|
-
import { P as PluginSwr } from './types-
|
|
4
|
+
import { P as PluginSwr, T as Transformer } from './types-AhGZx7jH.js';
|
|
5
5
|
import { FunctionParams } from '@kubb/react';
|
|
6
6
|
import '@kubb/core';
|
|
7
7
|
import '@kubb/plugin-client';
|
|
@@ -17,10 +17,11 @@ type Props$4 = {
|
|
|
17
17
|
mutationKeyTypeName: string;
|
|
18
18
|
typeSchemas: OperationSchemas;
|
|
19
19
|
operation: Operation;
|
|
20
|
+
paramsType: PluginSwr['resolvedOptions']['paramsType'];
|
|
20
21
|
dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType'];
|
|
21
22
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
22
23
|
};
|
|
23
|
-
declare function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, pathParamsType, dataReturnType, typeSchemas, operation }: Props$4): ReactNode;
|
|
24
|
+
declare function Mutation({ name, clientName, mutationKeyName, mutationKeyTypeName, paramsType, pathParamsType, dataReturnType, typeSchemas, operation, }: Props$4): ReactNode;
|
|
24
25
|
|
|
25
26
|
type Props$3 = {
|
|
26
27
|
/**
|
|
@@ -31,25 +32,28 @@ type Props$3 = {
|
|
|
31
32
|
queryKeyName: string;
|
|
32
33
|
queryKeyTypeName: string;
|
|
33
34
|
typeSchemas: OperationSchemas;
|
|
35
|
+
paramsType: PluginSwr['resolvedOptions']['paramsType'];
|
|
34
36
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
35
37
|
dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType'];
|
|
36
38
|
operation: Operation;
|
|
37
39
|
};
|
|
38
|
-
declare function Query({ name, typeSchemas, queryKeyName, queryKeyTypeName, queryOptionsName, operation, dataReturnType, pathParamsType }: Props$3): ReactNode;
|
|
40
|
+
declare function Query({ name, typeSchemas, queryKeyName, queryKeyTypeName, queryOptionsName, operation, dataReturnType, paramsType, pathParamsType, }: Props$3): ReactNode;
|
|
39
41
|
|
|
40
42
|
type Props$2 = {
|
|
41
43
|
name: string;
|
|
42
44
|
clientName: string;
|
|
43
45
|
typeSchemas: OperationSchemas;
|
|
46
|
+
paramsType: PluginSwr['resolvedOptions']['paramsType'];
|
|
44
47
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
45
48
|
};
|
|
46
49
|
type GetParamsProps$2 = {
|
|
50
|
+
paramsType: PluginSwr['resolvedOptions']['paramsType'];
|
|
47
51
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
48
52
|
typeSchemas: OperationSchemas;
|
|
49
53
|
};
|
|
50
|
-
declare function QueryOptions({ name, clientName, typeSchemas, pathParamsType }: Props$2): ReactNode;
|
|
54
|
+
declare function QueryOptions({ name, clientName, typeSchemas, paramsType, pathParamsType }: Props$2): ReactNode;
|
|
51
55
|
declare namespace QueryOptions {
|
|
52
|
-
var getParams: ({ pathParamsType, typeSchemas }: GetParamsProps$2) => FunctionParams;
|
|
56
|
+
var getParams: ({ paramsType, pathParamsType, typeSchemas }: GetParamsProps$2) => FunctionParams;
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
type Props$1 = {
|
|
@@ -58,15 +62,16 @@ type Props$1 = {
|
|
|
58
62
|
typeSchemas: OperationSchemas;
|
|
59
63
|
operation: Operation;
|
|
60
64
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
61
|
-
|
|
65
|
+
transformer: Transformer | undefined;
|
|
62
66
|
};
|
|
63
67
|
type GetParamsProps$1 = {
|
|
64
68
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
65
69
|
typeSchemas: OperationSchemas;
|
|
66
70
|
};
|
|
67
|
-
declare function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName,
|
|
71
|
+
declare function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer }: Props$1): ReactNode;
|
|
68
72
|
declare namespace QueryKey {
|
|
69
73
|
var getParams: ({ pathParamsType, typeSchemas }: GetParamsProps$1) => FunctionParams;
|
|
74
|
+
var getTransformer: Transformer;
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
type Props = {
|
|
@@ -75,15 +80,16 @@ type Props = {
|
|
|
75
80
|
typeSchemas: OperationSchemas;
|
|
76
81
|
operation: Operation;
|
|
77
82
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
78
|
-
|
|
83
|
+
transformer: Transformer | undefined;
|
|
79
84
|
};
|
|
80
85
|
type GetParamsProps = {
|
|
81
86
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType'];
|
|
82
87
|
typeSchemas: OperationSchemas;
|
|
83
88
|
};
|
|
84
|
-
declare function MutationKey({ name, typeSchemas, pathParamsType, operation, typeName,
|
|
89
|
+
declare function MutationKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer }: Props): ReactNode;
|
|
85
90
|
declare namespace MutationKey {
|
|
86
91
|
var getParams: ({}: GetParamsProps) => FunctionParams;
|
|
92
|
+
var getTransformer: Transformer;
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
export { Mutation, MutationKey, Query, QueryKey, QueryOptions };
|
package/dist/components.js
CHANGED
package/dist/generators.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunkW7U2E4KO_cjs = require('./chunk-W7U2E4KO.cjs');
|
|
4
|
+
require('./chunk-AFAHUG3Q.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "mutationGenerator", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkW7U2E4KO_cjs.mutationGenerator; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "queryGenerator", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkW7U2E4KO_cjs.queryGenerator; }
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=generators.cjs.map
|
|
17
17
|
//# sourceMappingURL=generators.cjs.map
|
package/dist/generators.d.cts
CHANGED
package/dist/generators.d.ts
CHANGED
package/dist/generators.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { mutationGenerator, queryGenerator } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { mutationGenerator, queryGenerator } from './chunk-2CUWQAT4.js';
|
|
2
|
+
import './chunk-2KDZWGWG.js';
|
|
3
3
|
//# sourceMappingURL=generators.js.map
|
|
4
4
|
//# sourceMappingURL=generators.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunkW7U2E4KO_cjs = require('./chunk-W7U2E4KO.cjs');
|
|
4
|
+
var chunkAFAHUG3Q_cjs = require('./chunk-AFAHUG3Q.cjs');
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var core = require('@kubb/core');
|
|
7
7
|
var transformers = require('@kubb/core/transformers');
|
|
8
|
-
require('@kubb/core/utils');
|
|
9
8
|
var pluginOas = require('@kubb/plugin-oas');
|
|
10
9
|
var pluginTs = require('@kubb/plugin-ts');
|
|
11
10
|
var pluginZod = require('@kubb/plugin-zod');
|
|
@@ -27,33 +26,36 @@ var pluginSwr = core.createPlugin((options) => {
|
|
|
27
26
|
query,
|
|
28
27
|
mutation,
|
|
29
28
|
client,
|
|
29
|
+
paramsType = "inline",
|
|
30
30
|
pathParamsType = "inline",
|
|
31
|
-
|
|
31
|
+
mutationKey = chunkAFAHUG3Q_cjs.MutationKey.getTransformer,
|
|
32
|
+
queryKey = chunkAFAHUG3Q_cjs.QueryKey.getTransformer,
|
|
33
|
+
generators = [chunkW7U2E4KO_cjs.queryGenerator, chunkW7U2E4KO_cjs.mutationGenerator].filter(Boolean)
|
|
32
34
|
} = options;
|
|
33
35
|
return {
|
|
34
36
|
name: pluginSwrName,
|
|
35
37
|
options: {
|
|
36
38
|
output,
|
|
37
|
-
pathParamsType,
|
|
38
39
|
client: {
|
|
39
40
|
importPath: "@kubb/plugin-client/client",
|
|
40
41
|
dataReturnType: "data",
|
|
41
42
|
...client
|
|
42
43
|
},
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
queryKey,
|
|
45
|
+
query: query === false ? false : {
|
|
45
46
|
importPath: "swr",
|
|
46
47
|
methods: ["get"],
|
|
47
48
|
...query
|
|
48
49
|
},
|
|
50
|
+
mutationKey,
|
|
49
51
|
mutation: {
|
|
50
|
-
key: (key) => key,
|
|
51
52
|
importPath: "swr/mutation",
|
|
52
53
|
methods: ["post", "put", "delete", "patch"],
|
|
53
54
|
...mutation
|
|
54
55
|
},
|
|
55
56
|
parser,
|
|
56
|
-
|
|
57
|
+
paramsType,
|
|
58
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType
|
|
57
59
|
},
|
|
58
60
|
pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, parser === "zod" ? pluginZod.pluginZodName : void 0].filter(Boolean),
|
|
59
61
|
resolvePath(baseName, pathMode, options2) {
|
|
@@ -89,22 +91,19 @@ var pluginSwr = core.createPlugin((options) => {
|
|
|
89
91
|
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
90
92
|
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
91
93
|
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
mode
|
|
106
|
-
}
|
|
107
|
-
);
|
|
94
|
+
if (baseURL) {
|
|
95
|
+
this.plugin.options.client.baseURL = baseURL;
|
|
96
|
+
}
|
|
97
|
+
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
98
|
+
oas,
|
|
99
|
+
pluginManager: this.pluginManager,
|
|
100
|
+
plugin: this.plugin,
|
|
101
|
+
contentType: swaggerPlugin.context.contentType,
|
|
102
|
+
exclude,
|
|
103
|
+
include,
|
|
104
|
+
override,
|
|
105
|
+
mode
|
|
106
|
+
});
|
|
108
107
|
const files = await operationGenerator.build(...generators);
|
|
109
108
|
await this.addFile(...files);
|
|
110
109
|
const barrelFiles = await this.fileManager.getBarrelFiles({
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","queryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","pascalCase","PluginManager","OperationGenerator"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","MutationKey","QueryKey","queryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","pascalCase","PluginManager","OperationGenerator"],"mappings":";;;;;;;;;;;;;;;AAeO,IAAM,aAAgB,GAAA;AAEhB,IAAA,SAAA,GAAYA,iBAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,OAAA,EAAS,YAAY,OAAQ,EAAA;AAAA,IAC9C,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,MAAS,GAAA,QAAA;AAAA,kBACTC,iBAAe,EAAC;AAAA,IAChB,KAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAa,GAAA,QAAA;A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AAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.cjs","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { MutationKey, QueryKey } from './components'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = createPlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n paramsType = 'inline',\n pathParamsType = 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n } = options\n\n return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n ...client,\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation: {\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'delete', 'patch'],\n ...mutation,\n },\n parser,\n paramsType,\n pathParamsType: paramsType === 'object' ? 'object' : pathParamsType,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n const baseURL = await swaggerPlugin.context.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { queryGenerator, mutationGenerator } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
import { queryGenerator, mutationGenerator } from './chunk-2CUWQAT4.js';
|
|
2
|
+
import { MutationKey, QueryKey } from './chunk-2KDZWGWG.js';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
5
5
|
import { camelCase, pascalCase } from '@kubb/core/transformers';
|
|
6
|
-
import '@kubb/core/utils';
|
|
7
6
|
import { pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
|
|
8
7
|
import { pluginTsName } from '@kubb/plugin-ts';
|
|
9
8
|
import { pluginZodName } from '@kubb/plugin-zod';
|
|
@@ -21,33 +20,36 @@ var pluginSwr = createPlugin((options) => {
|
|
|
21
20
|
query,
|
|
22
21
|
mutation,
|
|
23
22
|
client,
|
|
23
|
+
paramsType = "inline",
|
|
24
24
|
pathParamsType = "inline",
|
|
25
|
+
mutationKey = MutationKey.getTransformer,
|
|
26
|
+
queryKey = QueryKey.getTransformer,
|
|
25
27
|
generators = [queryGenerator, mutationGenerator].filter(Boolean)
|
|
26
28
|
} = options;
|
|
27
29
|
return {
|
|
28
30
|
name: pluginSwrName,
|
|
29
31
|
options: {
|
|
30
32
|
output,
|
|
31
|
-
pathParamsType,
|
|
32
33
|
client: {
|
|
33
34
|
importPath: "@kubb/plugin-client/client",
|
|
34
35
|
dataReturnType: "data",
|
|
35
36
|
...client
|
|
36
37
|
},
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
queryKey,
|
|
39
|
+
query: query === false ? false : {
|
|
39
40
|
importPath: "swr",
|
|
40
41
|
methods: ["get"],
|
|
41
42
|
...query
|
|
42
43
|
},
|
|
44
|
+
mutationKey,
|
|
43
45
|
mutation: {
|
|
44
|
-
key: (key) => key,
|
|
45
46
|
importPath: "swr/mutation",
|
|
46
47
|
methods: ["post", "put", "delete", "patch"],
|
|
47
48
|
...mutation
|
|
48
49
|
},
|
|
49
50
|
parser,
|
|
50
|
-
|
|
51
|
+
paramsType,
|
|
52
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType
|
|
51
53
|
},
|
|
52
54
|
pre: [pluginOasName, pluginTsName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
|
|
53
55
|
resolvePath(baseName, pathMode, options2) {
|
|
@@ -83,22 +85,19 @@ var pluginSwr = createPlugin((options) => {
|
|
|
83
85
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
84
86
|
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
85
87
|
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
mode
|
|
100
|
-
}
|
|
101
|
-
);
|
|
88
|
+
if (baseURL) {
|
|
89
|
+
this.plugin.options.client.baseURL = baseURL;
|
|
90
|
+
}
|
|
91
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
92
|
+
oas,
|
|
93
|
+
pluginManager: this.pluginManager,
|
|
94
|
+
plugin: this.plugin,
|
|
95
|
+
contentType: swaggerPlugin.context.contentType,
|
|
96
|
+
exclude,
|
|
97
|
+
include,
|
|
98
|
+
override,
|
|
99
|
+
mode
|
|
100
|
+
});
|
|
102
101
|
const files = await operationGenerator.build(...generators);
|
|
103
102
|
await this.addFile(...files);
|
|
104
103
|
const barrelFiles = await this.fileManager.getBarrelFiles({
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;;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A,QACA,QAAA;AAAA,QACA;AAAA,OACD,CAAA;AAED,MAAA,MAAM,KAAQ,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AAC1D,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA;AAE3B,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { MutationKey, QueryKey } from './components'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = createPlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n paramsType = 'inline',\n pathParamsType = 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n } = options\n\n return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n ...client,\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation: {\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'delete', 'patch'],\n ...mutation,\n },\n parser,\n paramsType,\n pathParamsType: paramsType === 'object' ? 'object' : pathParamsType,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n const baseURL = await swaggerPlugin.context.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
|