@genapi/presets 4.0.0 → 4.1.0
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/LICENSE.md +21 -21
- package/README.md +36 -108
- package/dist/_shared/query/config.d.mts +14 -0
- package/dist/_shared/query/config.mjs +58 -0
- package/dist/_shared/query/index.d.mts +3 -0
- package/dist/_shared/query/index.mjs +4 -0
- package/dist/_shared/query/parser.d.mts +7 -0
- package/dist/_shared/query/parser.mjs +75 -0
- package/dist/_shared/schema/compiler.mjs +8 -6
- package/dist/_shared/schema/config.mjs +8 -5
- package/dist/axios/js/config/index.mjs +3 -1
- package/dist/axios/js/parser/index.mjs +3 -3
- package/dist/axios/ts/config/index.mjs +4 -2
- package/dist/axios/ts/parser/index.mjs +3 -3
- package/dist/fetch/js/parser/index.mjs +3 -3
- package/dist/fetch/schema/index.d.mts +1 -0
- package/dist/fetch/schema/parser/index.d.mts +1 -0
- package/dist/fetch/ts/parser/index.mjs +3 -3
- package/dist/got/js/config/index.mjs +3 -1
- package/dist/got/js/parser/index.mjs +3 -3
- package/dist/got/ts/config/index.mjs +4 -2
- package/dist/got/ts/parser/index.mjs +3 -3
- package/dist/index.d.mts +10 -7
- package/dist/index.mjs +11 -8
- package/dist/ky/js/config/index.mjs +3 -1
- package/dist/ky/js/parser/index.mjs +3 -3
- package/dist/ky/ts/config/index.mjs +4 -2
- package/dist/ky/ts/parser/index.mjs +3 -3
- package/dist/ofetch/js/config/index.mjs +3 -1
- package/dist/ofetch/js/parser/index.mjs +3 -3
- package/dist/ofetch/schema/index.d.mts +1 -0
- package/dist/ofetch/schema/parser/index.d.mts +1 -0
- package/dist/ofetch/ts/config/index.mjs +4 -2
- package/dist/ofetch/ts/parser/index.mjs +3 -3
- package/dist/tanstack/colada/config/index.d.mts +2 -2
- package/dist/tanstack/colada/config/index.mjs +2 -11
- package/dist/tanstack/colada/index.d.mts +1 -1
- package/dist/tanstack/colada/parser/index.mjs +2 -66
- package/dist/tanstack/react/config/index.d.mts +2 -2
- package/dist/tanstack/react/config/index.mjs +2 -11
- package/dist/tanstack/react/index.d.mts +1 -1
- package/dist/tanstack/react/parser/index.mjs +2 -70
- package/dist/tanstack/vue/config/index.d.mts +2 -2
- package/dist/tanstack/vue/config/index.mjs +2 -11
- package/dist/tanstack/vue/index.d.mts +1 -1
- package/dist/tanstack/vue/parser/index.mjs +2 -66
- package/dist/uni/js/config/index.mjs +3 -1
- package/dist/uni/js/parser/index.mjs +3 -3
- package/dist/uni/ts/config/index.mjs +4 -2
- package/dist/uni/ts/parser/index.mjs +3 -3
- package/package.json +5 -5
package/LICENSE.md
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025-PRESENT Hairyf <https://github.com/hairyf>
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-PRESENT Hairyf <https://github.com/hairyf>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,108 +1,36 @@
|
|
|
1
|
-
# @genapi/presets
|
|
2
|
-
|
|
3
|
-
<!-- automd:badges -->
|
|
4
|
-
|
|
5
|
-
[](https://npmjs.com/package/@genapi/presets)
|
|
6
|
-
[](https://npm.chart.dev/@genapi/presets)
|
|
7
|
-
|
|
8
|
-
<!-- /automd -->
|
|
9
|
-
|
|
10
|
-
Prebuilt HTTP client pipelines (axios, fetch, ky, got, ofetch, uni) with TypeScript/JavaScript generation support.
|
|
11
|
-
|
|
12
|
-
## Installation
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
pnpm add @genapi/presets
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## API
|
|
19
|
-
|
|
20
|
-
<!-- automd:jsdocs src=src/index.ts -->
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
##### `js()`
|
|
39
|
-
|
|
40
|
-
##### `ts()`
|
|
41
|
-
|
|
42
|
-
#### `got`
|
|
43
|
-
|
|
44
|
-
##### `js()`
|
|
45
|
-
|
|
46
|
-
##### `ts()`
|
|
47
|
-
|
|
48
|
-
#### `ky`
|
|
49
|
-
|
|
50
|
-
##### `js()`
|
|
51
|
-
|
|
52
|
-
##### `ts()`
|
|
53
|
-
|
|
54
|
-
#### `ofetch`
|
|
55
|
-
|
|
56
|
-
##### `js()`
|
|
57
|
-
|
|
58
|
-
##### `ts()`
|
|
59
|
-
|
|
60
|
-
#### `uni`
|
|
61
|
-
|
|
62
|
-
##### `js()`
|
|
63
|
-
|
|
64
|
-
##### `ts()`
|
|
65
|
-
|
|
66
|
-
### `fetch`
|
|
67
|
-
|
|
68
|
-
#### `js()`
|
|
69
|
-
|
|
70
|
-
#### `ts()`
|
|
71
|
-
|
|
72
|
-
### `got`
|
|
73
|
-
|
|
74
|
-
#### `js()`
|
|
75
|
-
|
|
76
|
-
#### `ts()`
|
|
77
|
-
|
|
78
|
-
### `ky`
|
|
79
|
-
|
|
80
|
-
#### `js()`
|
|
81
|
-
|
|
82
|
-
#### `ts()`
|
|
83
|
-
|
|
84
|
-
### `ofetch`
|
|
85
|
-
|
|
86
|
-
#### `js()`
|
|
87
|
-
|
|
88
|
-
#### `ts()`
|
|
89
|
-
|
|
90
|
-
### `uni`
|
|
91
|
-
|
|
92
|
-
#### `js()`
|
|
93
|
-
|
|
94
|
-
#### `ts()`
|
|
95
|
-
|
|
96
|
-
<!-- /automd -->
|
|
97
|
-
|
|
98
|
-
## License
|
|
99
|
-
|
|
100
|
-
[MIT](https://github.com/hairyf/genapi/blob/main/LICENSE)
|
|
101
|
-
|
|
102
|
-
<!-- automd:with-automd -->
|
|
103
|
-
|
|
104
|
-
---
|
|
105
|
-
|
|
106
|
-
_🤖 auto updated with [automd](https://automd.unjs.io)_
|
|
107
|
-
|
|
108
|
-
<!-- /automd -->
|
|
1
|
+
# @genapi/presets
|
|
2
|
+
|
|
3
|
+
<!-- automd:badges -->
|
|
4
|
+
|
|
5
|
+
[](https://npmjs.com/package/@genapi/presets)
|
|
6
|
+
[](https://npm.chart.dev/@genapi/presets)
|
|
7
|
+
|
|
8
|
+
<!-- /automd -->
|
|
9
|
+
|
|
10
|
+
Prebuilt HTTP client pipelines (axios, fetch, ky, got, ofetch, uni) with TypeScript/JavaScript generation support.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @genapi/presets
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## API
|
|
19
|
+
|
|
20
|
+
<!-- automd:jsdocs src=src/index.ts -->
|
|
21
|
+
|
|
22
|
+
<!-- ⚠️ (jsdocs) (0 , _parser.createParser) is not a function -->
|
|
23
|
+
|
|
24
|
+
<!-- /automd -->
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
[MIT](https://github.com/hairyf/genapi/blob/main/LICENSE)
|
|
29
|
+
|
|
30
|
+
<!-- automd:with-automd -->
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
_🤖 auto updated with [automd](https://automd.unjs.io)_
|
|
35
|
+
|
|
36
|
+
<!-- /automd -->
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ApiPipeline } from "@genapi/shared";
|
|
2
|
+
|
|
3
|
+
//#region src/_shared/query/config.d.ts
|
|
4
|
+
/** Query preset Default Output: main(hooks)、api(apis)、type(types);Query preset only effective output.main / output.api / output.type;type is false, not default api, keep single file main */
|
|
5
|
+
declare function ensureQueryOutput(userConfig: ApiPipeline.Config): void;
|
|
6
|
+
/** main import api file (apis.xxx reference); api import type file (Types reference) */
|
|
7
|
+
declare function addApiImportToMain(configRead: ApiPipeline.ConfigRead): void;
|
|
8
|
+
interface QueryConfigOptions {
|
|
9
|
+
/** Query library name (e.g., @pinia/colada, @tanstack/react-query, @tanstack/vue-query) */
|
|
10
|
+
queryLibrary: string;
|
|
11
|
+
}
|
|
12
|
+
declare function createQueryConfig(options: QueryConfigOptions | string): (userConfig: ApiPipeline.Config) => ApiPipeline.ConfigRead;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { QueryConfigOptions, addApiImportToMain, createQueryConfig, ensureQueryOutput };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { config } from "@genapi/pipeline";
|
|
2
|
+
import { inject } from "@genapi/shared";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
//#region src/_shared/query/config.ts
|
|
6
|
+
/** Query preset Default Output: main(hooks)、api(apis)、type(types);Query preset only effective output.main / output.api / output.type;type is false, not default api, keep single file main */
|
|
7
|
+
function ensureQueryOutput(userConfig) {
|
|
8
|
+
userConfig.output = userConfig.output && typeof userConfig.output === "object" ? userConfig.output : {};
|
|
9
|
+
const out = userConfig.output;
|
|
10
|
+
out.main = out.main ?? "src/api/index.ts";
|
|
11
|
+
out.type = out.type !== false ? out.type ?? (typeof out.main === "string" ? out.main.replace(/\.(ts|js)$/, ".type.ts") : "src/api/index.type.ts") : false;
|
|
12
|
+
if (out.type !== false) out.api = out.api ?? (typeof out.main === "string" ? out.main.replace(/index\.(ts|js)$/, "index.api.$1") : "src/api/index.api.ts");
|
|
13
|
+
}
|
|
14
|
+
/** main import api file (apis.xxx reference); api import type file (Types reference) */
|
|
15
|
+
function addApiImportToMain(configRead) {
|
|
16
|
+
const mainOut = configRead.outputs.find((o) => o.type === "main");
|
|
17
|
+
const apiOut = configRead.outputs.find((o) => o.type === "api");
|
|
18
|
+
const typeOut = configRead.outputs.find((o) => o.type === "type");
|
|
19
|
+
const { imports } = inject();
|
|
20
|
+
if (mainOut && apiOut) {
|
|
21
|
+
const rel = path.relative(path.dirname(mainOut.path), apiOut.path).replace(/\.(ts|js)$/, "");
|
|
22
|
+
const value = (rel.startsWith(".") ? rel : `./${rel}`).replace(/\\/g, "/");
|
|
23
|
+
imports.add("main", {
|
|
24
|
+
value,
|
|
25
|
+
namespace: true,
|
|
26
|
+
name: "apis"
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (apiOut && typeOut) {
|
|
30
|
+
const rel = path.relative(path.dirname(apiOut.path), typeOut.path).replace(/\.(ts|js)$/, "");
|
|
31
|
+
const value = (rel.startsWith(".") ? rel : `./${rel}`).replace(/\\/g, "/");
|
|
32
|
+
imports.add("api", {
|
|
33
|
+
value,
|
|
34
|
+
namespace: true,
|
|
35
|
+
name: "Types",
|
|
36
|
+
type: true
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function createQueryConfig(options) {
|
|
41
|
+
const queryLibrary = typeof options === "string" ? options : options.queryLibrary;
|
|
42
|
+
return function config$1(userConfig) {
|
|
43
|
+
userConfig.meta = userConfig.meta || {};
|
|
44
|
+
userConfig.meta.import = userConfig.meta.import || {};
|
|
45
|
+
ensureQueryOutput(userConfig);
|
|
46
|
+
const configRead = config(userConfig);
|
|
47
|
+
const { imports } = inject();
|
|
48
|
+
addApiImportToMain(configRead);
|
|
49
|
+
imports.add("main", {
|
|
50
|
+
names: ["useQuery", "useMutation"],
|
|
51
|
+
value: queryLibrary
|
|
52
|
+
});
|
|
53
|
+
return configRead;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { addApiImportToMain, createQueryConfig, ensureQueryOutput };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as _genapi_shared0 from "@genapi/shared";
|
|
2
|
+
|
|
3
|
+
//#region src/_shared/query/parser.d.ts
|
|
4
|
+
/** Query preset 统一 parser:固定三文件,useQuery(queryKey, queryFn)、useMutation(mutationFn),description 统一 @wraps */
|
|
5
|
+
declare function createQueryParser(): (configRead: _genapi_shared0.ApiPipeline.ConfigRead) => _genapi_shared0.ApiPipeline.ConfigRead;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { createQueryParser };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createParser, parseMethodMetadata, parseMethodParameters, transformBodyStringify, transformFetchBody, transformHeaderOptions, transformParameters, transformQueryParams, transformUrlSyntax } from "@genapi/parser";
|
|
2
|
+
|
|
3
|
+
//#region src/_shared/query/parser.ts
|
|
4
|
+
function hookName(fetcherName) {
|
|
5
|
+
return `use${fetcherName.charAt(0).toUpperCase()}${fetcherName.slice(1)}`;
|
|
6
|
+
}
|
|
7
|
+
/** Query preset 统一 parser:固定三文件,useQuery(queryKey, queryFn)、useMutation(mutationFn),description 统一 @wraps */
|
|
8
|
+
function createQueryParser() {
|
|
9
|
+
return createParser((config, { configRead, functions, interfaces }) => {
|
|
10
|
+
const { parameters, interfaces: attachInters, options: optList } = parseMethodParameters(config);
|
|
11
|
+
let { name, description, url, responseType, body } = parseMethodMetadata(config);
|
|
12
|
+
attachInters.forEach((i) => interfaces.add("type", i));
|
|
13
|
+
const fetcherParams = [...parameters];
|
|
14
|
+
fetcherParams.push({
|
|
15
|
+
name: "config",
|
|
16
|
+
type: "RequestInit",
|
|
17
|
+
required: false
|
|
18
|
+
});
|
|
19
|
+
if (config.method.toLowerCase() !== "get") optList.unshift(["method", `"${config.method}"`]);
|
|
20
|
+
transformHeaderOptions("body", {
|
|
21
|
+
options: optList,
|
|
22
|
+
parameters
|
|
23
|
+
});
|
|
24
|
+
optList.push(["...", "config"]);
|
|
25
|
+
const { spaceResponseType } = transformParameters(parameters, {
|
|
26
|
+
syntax: "typescript",
|
|
27
|
+
interfaces: interfaces.all(),
|
|
28
|
+
configRead,
|
|
29
|
+
description,
|
|
30
|
+
responseType
|
|
31
|
+
});
|
|
32
|
+
transformBodyStringify("body", {
|
|
33
|
+
options: optList,
|
|
34
|
+
parameters
|
|
35
|
+
});
|
|
36
|
+
url = transformQueryParams("query", {
|
|
37
|
+
body,
|
|
38
|
+
options: optList,
|
|
39
|
+
url
|
|
40
|
+
});
|
|
41
|
+
url = transformUrlSyntax(url, { baseURL: configRead.config.meta?.baseURL });
|
|
42
|
+
const fetchBody = transformFetchBody(url, optList, spaceResponseType);
|
|
43
|
+
const fetcherRef = `apis.${name}`;
|
|
44
|
+
functions.add("api", {
|
|
45
|
+
export: true,
|
|
46
|
+
async: true,
|
|
47
|
+
name,
|
|
48
|
+
description,
|
|
49
|
+
parameters: fetcherParams,
|
|
50
|
+
body: [...body, ...fetchBody]
|
|
51
|
+
});
|
|
52
|
+
const isRead = ["get", "head"].includes(config.method.toLowerCase());
|
|
53
|
+
const hook = hookName(name);
|
|
54
|
+
const paramNames = fetcherParams.map((p) => p.name).join(", ");
|
|
55
|
+
if (isRead) {
|
|
56
|
+
const keyItems = `${fetcherRef}.name, ${paramNames}`;
|
|
57
|
+
functions.add("main", {
|
|
58
|
+
export: true,
|
|
59
|
+
name: hook,
|
|
60
|
+
description: [`@wraps ${name}`],
|
|
61
|
+
parameters: fetcherParams,
|
|
62
|
+
body: [`return useQuery({ queryKey: [${keyItems}], queryFn: () => ${fetcherRef}(${paramNames}) })`]
|
|
63
|
+
});
|
|
64
|
+
} else functions.add("main", {
|
|
65
|
+
export: true,
|
|
66
|
+
name: hook,
|
|
67
|
+
description: [`@wraps ${name}`],
|
|
68
|
+
parameters: [],
|
|
69
|
+
body: [`return useMutation({ mutationFn: ${fetcherRef} })`]
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
export { createQueryParser };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { compile } from "@genapi/pipeline";
|
|
2
2
|
import { genInterface, genTypeObject } from "knitwork-x";
|
|
3
3
|
|
|
4
4
|
//#region src/_shared/schema/compiler.ts
|
|
@@ -10,7 +10,9 @@ function convert(str, names) {
|
|
|
10
10
|
function createSchemaCompiler(options) {
|
|
11
11
|
return function compiler(config) {
|
|
12
12
|
const routes = config.__schemaRoutes || [];
|
|
13
|
-
const
|
|
13
|
+
const allInterfaces = [...config.graphs.scopes.main?.interfaces || [], ...config.graphs.scopes.type?.interfaces || []];
|
|
14
|
+
const allTypings = config.graphs.scopes.type?.typings || [];
|
|
15
|
+
const interfaceNames = new Set([...allInterfaces.map((i) => i.name), ...allTypings.filter((t) => t.name && !t.value?.includes("{")).map((t) => t.name)]);
|
|
14
16
|
const tree = routes.reduce((root, r) => {
|
|
15
17
|
const node = r.path.split("/").filter(Boolean).reduce((curr, p) => {
|
|
16
18
|
const key = p.startsWith("{") ? Dynamic : p;
|
|
@@ -32,7 +34,7 @@ function createSchemaCompiler(options) {
|
|
|
32
34
|
Object.keys(node).forEach((k) => res[isRoot ? `/${k}` : k] = genTypeObject(toObj(node[k])));
|
|
33
35
|
return res;
|
|
34
36
|
};
|
|
35
|
-
config.graphs.functions = [{
|
|
37
|
+
config.graphs.scopes.main.functions = [{
|
|
36
38
|
export: true,
|
|
37
39
|
name: "$fetch",
|
|
38
40
|
async: true,
|
|
@@ -52,13 +54,13 @@ function createSchemaCompiler(options) {
|
|
|
52
54
|
body: [`return ${options.httpClient}(input, init as any) as Promise<TypedResponse<TypedFetchResponseBody<APISchema, T>>>`]
|
|
53
55
|
}];
|
|
54
56
|
config.outputs.forEach((out) => {
|
|
55
|
-
if (out.type === "
|
|
56
|
-
const code =
|
|
57
|
+
if (out.type === "main" && !config.config.meta?.onlyDeclaration) {
|
|
58
|
+
const code = compile(config, "main");
|
|
57
59
|
const schema = `\n// API Schema\n${genInterface("APISchema", toObj(tree, true))}\n`;
|
|
58
60
|
const idx = code.lastIndexOf("import");
|
|
59
61
|
const pos = idx !== -1 ? code.indexOf("\n", idx) + 1 : 0;
|
|
60
62
|
out.code = code.slice(0, pos) + schema + code.slice(pos);
|
|
61
|
-
} else if (out.type === "
|
|
63
|
+
} else if (out.type === "type") out.code = compile(config, "type");
|
|
62
64
|
});
|
|
63
65
|
return config;
|
|
64
66
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { config } from "@genapi/pipeline";
|
|
2
|
+
import { inject } from "@genapi/shared";
|
|
2
3
|
|
|
3
4
|
//#region src/_shared/schema/config.ts
|
|
4
5
|
function createSchemaConfig(options = {}) {
|
|
@@ -8,11 +9,12 @@ function createSchemaConfig(options = {}) {
|
|
|
8
9
|
if (options.httpPackage && options.httpClientName) {
|
|
9
10
|
userConfig.meta.import.http = userConfig.meta.import.http || options.httpPackage;
|
|
10
11
|
const configRead = config(userConfig);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
names: [options.httpClientName]
|
|
12
|
+
const { imports } = inject();
|
|
13
|
+
imports.add("main", {
|
|
14
|
+
names: [options.httpClientName],
|
|
15
|
+
value: userConfig.meta.import.http
|
|
14
16
|
});
|
|
15
|
-
|
|
17
|
+
imports.add("main", {
|
|
16
18
|
names: [
|
|
17
19
|
"TypedFetchInput",
|
|
18
20
|
"TypedFetchRequestInit",
|
|
@@ -26,7 +28,8 @@ function createSchemaConfig(options = {}) {
|
|
|
26
28
|
return configRead;
|
|
27
29
|
}
|
|
28
30
|
const configRead = config(userConfig);
|
|
29
|
-
|
|
31
|
+
const { imports } = inject();
|
|
32
|
+
imports.add("main", {
|
|
30
33
|
names: [
|
|
31
34
|
"TypedFetchInput",
|
|
32
35
|
"TypedFetchRequestInit",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { config as config$1 } from "@genapi/pipeline";
|
|
2
2
|
import { replaceMainext } from "@genapi/parser";
|
|
3
|
+
import { inject } from "@genapi/shared";
|
|
3
4
|
|
|
4
5
|
//#region src/axios/js/config/index.ts
|
|
5
6
|
function config(userConfig) {
|
|
@@ -9,7 +10,8 @@ function config(userConfig) {
|
|
|
9
10
|
userConfig.meta.import.http = userConfig.meta.import.http || "axios";
|
|
10
11
|
userConfig.output = replaceMainext(userConfig.output) || "src/api/index.js";
|
|
11
12
|
const configRead = config$1(userConfig);
|
|
12
|
-
|
|
13
|
+
const { imports } = inject();
|
|
14
|
+
imports.add("main", {
|
|
13
15
|
name: "http",
|
|
14
16
|
value: userConfig.meta.import.http
|
|
15
17
|
});
|
|
@@ -8,7 +8,7 @@ const parser = createParser((config, { configRead, functions, interfaces }) => {
|
|
|
8
8
|
});
|
|
9
9
|
let { name, description, url, responseType } = parseMethodMetadata(config);
|
|
10
10
|
options.push(["...", "config"]);
|
|
11
|
-
interfaces.
|
|
11
|
+
attachInters.forEach((i) => interfaces.add("type", i));
|
|
12
12
|
parameters.push({
|
|
13
13
|
type: "import('axios').AxiosRequestConfig",
|
|
14
14
|
name: "config",
|
|
@@ -21,12 +21,12 @@ const parser = createParser((config, { configRead, functions, interfaces }) => {
|
|
|
21
21
|
syntax: "ecmascript",
|
|
22
22
|
configRead,
|
|
23
23
|
description,
|
|
24
|
-
interfaces,
|
|
24
|
+
interfaces: interfaces.all(),
|
|
25
25
|
responseType,
|
|
26
26
|
generic: "import('axios').AxiosResponse<{__type__}>"
|
|
27
27
|
});
|
|
28
28
|
url = transformUrlSyntax(url);
|
|
29
|
-
functions.
|
|
29
|
+
functions.add("main", {
|
|
30
30
|
export: true,
|
|
31
31
|
name,
|
|
32
32
|
description,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { config as config$1 } from "@genapi/pipeline";
|
|
2
|
+
import { inject } from "@genapi/shared";
|
|
2
3
|
|
|
3
4
|
//#region src/axios/ts/config/index.ts
|
|
4
5
|
function config(userConfig) {
|
|
@@ -6,12 +7,13 @@ function config(userConfig) {
|
|
|
6
7
|
userConfig.meta.import = userConfig.meta.import || {};
|
|
7
8
|
userConfig.meta.import.http = userConfig.meta.import.http || "axios";
|
|
8
9
|
const configRead = config$1(userConfig);
|
|
9
|
-
|
|
10
|
+
const { imports } = inject();
|
|
11
|
+
imports.add("main", {
|
|
10
12
|
name: "http",
|
|
11
13
|
names: userConfig.meta.import.http === "axios" ? ["AxiosRequestConfig"] : void 0,
|
|
12
14
|
value: userConfig.meta.import.http
|
|
13
15
|
});
|
|
14
|
-
if (userConfig.meta.import.http !== "axios")
|
|
16
|
+
if (userConfig.meta.import.http !== "axios") imports.add("main", {
|
|
15
17
|
names: ["AxiosRequestConfig"],
|
|
16
18
|
value: "axios"
|
|
17
19
|
});
|
|
@@ -8,7 +8,7 @@ const parser = createParser((config, { configRead, functions, interfaces }) => {
|
|
|
8
8
|
});
|
|
9
9
|
let { name, description, url, responseType } = parseMethodMetadata(config);
|
|
10
10
|
options.push(["...", "config"]);
|
|
11
|
-
interfaces.
|
|
11
|
+
attachInters.forEach((i) => interfaces.add("type", i));
|
|
12
12
|
parameters.push({
|
|
13
13
|
name: "config",
|
|
14
14
|
type: "AxiosRequestConfig",
|
|
@@ -21,11 +21,11 @@ const parser = createParser((config, { configRead, functions, interfaces }) => {
|
|
|
21
21
|
syntax: "typescript",
|
|
22
22
|
configRead,
|
|
23
23
|
description,
|
|
24
|
-
interfaces,
|
|
24
|
+
interfaces: interfaces.all(),
|
|
25
25
|
responseType
|
|
26
26
|
});
|
|
27
27
|
url = transformUrlSyntax(url);
|
|
28
|
-
functions.
|
|
28
|
+
functions.add("main", {
|
|
29
29
|
export: true,
|
|
30
30
|
name,
|
|
31
31
|
description,
|
|
@@ -4,7 +4,7 @@ import { createParser, literalFieldsToString, parseMethodMetadata, parseMethodPa
|
|
|
4
4
|
const parser = createParser((config, { configRead, functions, interfaces }) => {
|
|
5
5
|
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config, { formData: "body" });
|
|
6
6
|
let { name, description, url, responseType, body } = parseMethodMetadata(config);
|
|
7
|
-
interfaces.
|
|
7
|
+
attachInters.forEach((i) => interfaces.add("type", i));
|
|
8
8
|
parameters.push({
|
|
9
9
|
name: "config",
|
|
10
10
|
type: "RequestInit",
|
|
@@ -20,7 +20,7 @@ const parser = createParser((config, { configRead, functions, interfaces }) => {
|
|
|
20
20
|
syntax: "ecmascript",
|
|
21
21
|
configRead,
|
|
22
22
|
description,
|
|
23
|
-
interfaces,
|
|
23
|
+
interfaces: interfaces.all(),
|
|
24
24
|
responseType
|
|
25
25
|
});
|
|
26
26
|
transformBodyStringify("body", {
|
|
@@ -33,7 +33,7 @@ const parser = createParser((config, { configRead, functions, interfaces }) => {
|
|
|
33
33
|
url
|
|
34
34
|
});
|
|
35
35
|
url = transformUrlSyntax(url, { baseURL: configRead.config.meta?.baseURL });
|
|
36
|
-
functions.
|
|
36
|
+
functions.add("main", {
|
|
37
37
|
export: true,
|
|
38
38
|
async: true,
|
|
39
39
|
name,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { schemaParser } from "../../_shared/schema/parser.mjs";
|
|
2
2
|
import { compiler } from "./compiler/index.mjs";
|
|
3
3
|
import { config } from "./config/index.mjs";
|
|
4
|
+
import "./parser/index.mjs";
|
|
4
5
|
import * as _genapi_pipeline0 from "@genapi/pipeline";
|
|
5
6
|
import { dest, generate, original } from "@genapi/pipeline";
|
|
6
7
|
import { ApiPipeline } from "@genapi/shared";
|
|
@@ -4,7 +4,7 @@ import { createParser, parseMethodMetadata, parseMethodParameters, transformBody
|
|
|
4
4
|
const parser = createParser((config, { configRead, functions, interfaces }) => {
|
|
5
5
|
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config);
|
|
6
6
|
let { name, description, url, responseType, body } = parseMethodMetadata(config);
|
|
7
|
-
interfaces.
|
|
7
|
+
attachInters.forEach((i) => interfaces.add("type", i));
|
|
8
8
|
parameters.push({
|
|
9
9
|
name: "config",
|
|
10
10
|
type: "RequestInit",
|
|
@@ -20,7 +20,7 @@ const parser = createParser((config, { configRead, functions, interfaces }) => {
|
|
|
20
20
|
syntax: "typescript",
|
|
21
21
|
configRead,
|
|
22
22
|
description,
|
|
23
|
-
interfaces,
|
|
23
|
+
interfaces: interfaces.all(),
|
|
24
24
|
responseType
|
|
25
25
|
});
|
|
26
26
|
transformBodyStringify("body", {
|
|
@@ -34,7 +34,7 @@ const parser = createParser((config, { configRead, functions, interfaces }) => {
|
|
|
34
34
|
});
|
|
35
35
|
url = transformUrlSyntax(url, { baseURL: configRead.config.meta?.baseURL });
|
|
36
36
|
const fetch = transformFetchBody(url, options, spaceResponseType);
|
|
37
|
-
functions.
|
|
37
|
+
functions.add("main", {
|
|
38
38
|
export: true,
|
|
39
39
|
async: true,
|
|
40
40
|
name,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { config as config$1 } from "@genapi/pipeline";
|
|
2
2
|
import { replaceMainext } from "@genapi/parser";
|
|
3
|
+
import { inject } from "@genapi/shared";
|
|
3
4
|
|
|
4
5
|
//#region src/got/js/config/index.ts
|
|
5
6
|
function config(userConfig) {
|
|
@@ -9,7 +10,8 @@ function config(userConfig) {
|
|
|
9
10
|
userConfig.meta.import.http = userConfig.meta.import.http || "got";
|
|
10
11
|
userConfig.output = replaceMainext(userConfig.output) || "src/api/index.js";
|
|
11
12
|
const configRead = config$1(userConfig);
|
|
12
|
-
|
|
13
|
+
const { imports } = inject();
|
|
14
|
+
imports.add("main", {
|
|
13
15
|
name: "http",
|
|
14
16
|
value: userConfig.meta.import.http
|
|
15
17
|
});
|
|
@@ -4,7 +4,7 @@ import { createParser, literalFieldsToString, parseMethodMetadata, parseMethodPa
|
|
|
4
4
|
const parser = createParser((config, { configRead, functions, interfaces }) => {
|
|
5
5
|
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config);
|
|
6
6
|
let { name, description, url, responseType } = parseMethodMetadata(config);
|
|
7
|
-
interfaces.
|
|
7
|
+
attachInters.forEach((i) => interfaces.add("type", i));
|
|
8
8
|
parameters.push({
|
|
9
9
|
name: "config",
|
|
10
10
|
type: "import('got').OptionsOfTextResponseBody",
|
|
@@ -17,7 +17,7 @@ const parser = createParser((config, { configRead, functions, interfaces }) => {
|
|
|
17
17
|
syntax: "ecmascript",
|
|
18
18
|
configRead,
|
|
19
19
|
description,
|
|
20
|
-
interfaces,
|
|
20
|
+
interfaces: interfaces.all(),
|
|
21
21
|
responseType
|
|
22
22
|
});
|
|
23
23
|
transformBodyStringify("body", {
|
|
@@ -29,7 +29,7 @@ const parser = createParser((config, { configRead, functions, interfaces }) => {
|
|
|
29
29
|
options
|
|
30
30
|
});
|
|
31
31
|
url = transformUrlSyntax(url);
|
|
32
|
-
functions.
|
|
32
|
+
functions.add("main", {
|
|
33
33
|
export: true,
|
|
34
34
|
async: true,
|
|
35
35
|
name,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { config as config$1 } from "@genapi/pipeline";
|
|
2
|
+
import { inject } from "@genapi/shared";
|
|
2
3
|
|
|
3
4
|
//#region src/got/ts/config/index.ts
|
|
4
5
|
function config(userConfig) {
|
|
@@ -6,12 +7,13 @@ function config(userConfig) {
|
|
|
6
7
|
userConfig.meta.import = userConfig.meta.import || {};
|
|
7
8
|
userConfig.meta.import.http = userConfig.meta.import.http || "got";
|
|
8
9
|
const configRead = config$1(userConfig);
|
|
9
|
-
|
|
10
|
+
const { imports } = inject();
|
|
11
|
+
imports.add("main", {
|
|
10
12
|
name: "http",
|
|
11
13
|
names: userConfig.meta.import.http === "got" ? ["OptionsOfTextResponseBody"] : void 0,
|
|
12
14
|
value: userConfig.meta.import.http
|
|
13
15
|
});
|
|
14
|
-
if (userConfig.meta.import.http !== "got")
|
|
16
|
+
if (userConfig.meta.import.http !== "got") imports.add("main", {
|
|
15
17
|
names: ["OptionsOfTextResponseBody"],
|
|
16
18
|
value: "got"
|
|
17
19
|
});
|