@genapi/presets 3.7.1 → 4.0.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/README.md +108 -0
- package/dist/_shared/schema/compiler.d.mts +10 -0
- package/dist/_shared/schema/compiler.mjs +68 -0
- package/dist/_shared/schema/config.d.mts +12 -0
- package/dist/_shared/schema/config.mjs +45 -0
- package/dist/_shared/schema/index.d.mts +4 -0
- package/dist/_shared/schema/index.mjs +5 -0
- package/dist/_shared/schema/parser.d.mts +14 -0
- package/dist/_shared/schema/parser.mjs +49 -0
- package/dist/axios/index.d.mts +8 -8
- package/dist/axios/index.mjs +11 -8
- package/dist/axios/js/config/index.d.mts +4 -1
- package/dist/axios/js/config/index.mjs +18 -1
- package/dist/axios/js/index.d.mts +16 -3
- package/dist/axios/js/index.mjs +16 -4
- package/dist/axios/js/parser/index.d.mts +5 -2
- package/dist/axios/js/parser/index.mjs +38 -2
- package/dist/axios/ts/config/index.d.mts +4 -1
- package/dist/axios/ts/config/index.mjs +20 -1
- package/dist/axios/ts/index.d.mts +16 -3
- package/dist/axios/ts/index.mjs +16 -4
- package/dist/axios/ts/parser/index.d.mts +5 -2
- package/dist/axios/ts/parser/index.mjs +37 -2
- package/dist/chunk-DQk6qfdC.mjs +18 -0
- package/dist/fetch/index.d.mts +9 -8
- package/dist/fetch/index.mjs +13 -8
- package/dist/fetch/js/config/index.d.mts +4 -1
- package/dist/fetch/js/config/index.mjs +12 -1
- package/dist/fetch/js/index.d.mts +16 -3
- package/dist/fetch/js/index.mjs +16 -4
- package/dist/fetch/js/parser/index.d.mts +5 -2
- package/dist/fetch/js/parser/index.mjs +52 -2
- package/dist/fetch/schema/compiler/index.d.mts +6 -0
- package/dist/fetch/schema/compiler/index.mjs +7 -0
- package/dist/fetch/schema/config/index.d.mts +6 -0
- package/dist/fetch/schema/config/index.mjs +7 -0
- package/dist/fetch/schema/index.d.mts +19 -0
- package/dist/fetch/schema/index.mjs +18 -0
- package/dist/fetch/schema/parser/index.d.mts +2 -0
- package/dist/fetch/schema/parser/index.mjs +3 -0
- package/dist/fetch/ts/config/index.d.mts +4 -1
- package/dist/fetch/ts/config/index.mjs +10 -1
- package/dist/fetch/ts/index.d.mts +16 -3
- package/dist/fetch/ts/index.mjs +16 -4
- package/dist/fetch/ts/parser/index.d.mts +5 -2
- package/dist/fetch/ts/parser/index.mjs +47 -2
- package/dist/got/index.d.mts +8 -8
- package/dist/got/index.mjs +11 -8
- package/dist/got/js/config/index.d.mts +4 -1
- package/dist/got/js/config/index.mjs +18 -1
- package/dist/got/js/index.d.mts +16 -3
- package/dist/got/js/index.mjs +16 -4
- package/dist/got/js/parser/index.d.mts +5 -2
- package/dist/got/js/parser/index.mjs +44 -2
- package/dist/got/ts/config/index.d.mts +4 -1
- package/dist/got/ts/config/index.mjs +20 -1
- package/dist/got/ts/index.d.mts +16 -3
- package/dist/got/ts/index.mjs +16 -4
- package/dist/got/ts/parser/index.d.mts +5 -2
- package/dist/got/ts/parser/index.mjs +44 -2
- package/dist/index.d.mts +21 -50
- package/dist/index.mjs +15 -43
- package/dist/ky/index.d.mts +8 -8
- package/dist/ky/index.mjs +11 -8
- package/dist/ky/js/config/index.d.mts +4 -1
- package/dist/ky/js/config/index.mjs +18 -1
- package/dist/ky/js/index.d.mts +16 -3
- package/dist/ky/js/index.mjs +16 -4
- package/dist/ky/js/parser/index.d.mts +5 -2
- package/dist/ky/js/parser/index.mjs +44 -2
- package/dist/ky/ts/config/index.d.mts +4 -1
- package/dist/ky/ts/config/index.mjs +20 -1
- package/dist/ky/ts/index.d.mts +16 -3
- package/dist/ky/ts/index.mjs +16 -4
- package/dist/ky/ts/parser/index.d.mts +5 -2
- package/dist/ky/ts/parser/index.mjs +43 -2
- package/dist/ofetch/index.d.mts +9 -8
- package/dist/ofetch/index.mjs +13 -8
- package/dist/ofetch/js/config/index.d.mts +4 -1
- package/dist/ofetch/js/config/index.mjs +18 -1
- package/dist/ofetch/js/index.d.mts +16 -3
- package/dist/ofetch/js/index.mjs +16 -4
- package/dist/ofetch/js/parser/index.d.mts +5 -2
- package/dist/ofetch/js/parser/index.mjs +42 -2
- package/dist/ofetch/schema/compiler/index.d.mts +6 -0
- package/dist/ofetch/schema/compiler/index.mjs +7 -0
- package/dist/ofetch/schema/config/index.d.mts +6 -0
- package/dist/ofetch/schema/config/index.mjs +10 -0
- package/dist/ofetch/schema/index.d.mts +19 -0
- package/dist/ofetch/schema/index.mjs +18 -0
- package/dist/ofetch/schema/parser/index.d.mts +2 -0
- package/dist/ofetch/schema/parser/index.mjs +3 -0
- package/dist/ofetch/ts/config/index.d.mts +4 -1
- package/dist/ofetch/ts/config/index.mjs +19 -1
- package/dist/ofetch/ts/index.d.mts +16 -3
- package/dist/ofetch/ts/index.mjs +16 -4
- package/dist/ofetch/ts/parser/index.d.mts +5 -2
- package/dist/ofetch/ts/parser/index.mjs +41 -2
- package/dist/{index.d-Df6nDub9.d.mts → tanstack/colada/config/index.d.mts} +2 -3
- package/dist/tanstack/colada/config/index.mjs +16 -0
- package/dist/tanstack/colada/index.d.mts +18 -0
- package/dist/tanstack/colada/index.mjs +17 -0
- package/dist/tanstack/colada/parser/index.d.mts +6 -0
- package/dist/tanstack/colada/parser/index.mjs +71 -0
- package/dist/tanstack/index.d.mts +10 -0
- package/dist/tanstack/index.mjs +14 -0
- package/dist/{index.d-BsBf_9LO.d.mts → tanstack/react/config/index.d.mts} +2 -3
- package/dist/tanstack/react/config/index.mjs +16 -0
- package/dist/tanstack/react/index.d.mts +18 -0
- package/dist/tanstack/react/index.mjs +17 -0
- package/dist/tanstack/react/parser/index.d.mts +6 -0
- package/dist/tanstack/react/parser/index.mjs +75 -0
- package/dist/{index.d-BkDRl56J.d.mts → tanstack/vue/config/index.d.mts} +2 -3
- package/dist/tanstack/vue/config/index.mjs +16 -0
- package/dist/tanstack/vue/index.d.mts +18 -0
- package/dist/tanstack/vue/index.mjs +17 -0
- package/dist/tanstack/vue/parser/index.d.mts +6 -0
- package/dist/tanstack/vue/parser/index.mjs +71 -0
- package/dist/uni/index.d.mts +8 -8
- package/dist/uni/index.mjs +11 -8
- package/dist/uni/js/config/index.d.mts +4 -1
- package/dist/uni/js/config/index.mjs +18 -1
- package/dist/uni/js/index.d.mts +16 -3
- package/dist/uni/js/index.mjs +16 -4
- package/dist/uni/js/parser/index.d.mts +5 -2
- package/dist/uni/js/parser/index.mjs +38 -2
- package/dist/uni/ts/config/index.d.mts +4 -1
- package/dist/uni/ts/config/index.mjs +20 -1
- package/dist/uni/ts/index.d.mts +16 -3
- package/dist/uni/ts/index.mjs +16 -4
- package/dist/uni/ts/parser/index.d.mts +5 -2
- package/dist/uni/ts/parser/index.mjs +37 -2
- package/package.json +26 -6
- package/dist/axios-C-GYxVyS.mjs +0 -13
- package/dist/chunk-BL35Yyzp.mjs +0 -12
- package/dist/config-Bt-OVtrF.mjs +0 -21
- package/dist/config-CCf0xLx5.mjs +0 -12
- package/dist/config-CDvaM7ZL.mjs +0 -19
- package/dist/config-CEngTpXa.mjs +0 -21
- package/dist/config-CRdZhud4.mjs +0 -19
- package/dist/config-CTDgiXdv.mjs +0 -19
- package/dist/config-Dn-mxTew.mjs +0 -19
- package/dist/config-Dp9C4aUE.mjs +0 -21
- package/dist/config-Duv2zgs0.mjs +0 -14
- package/dist/config-IeVj3de_.mjs +0 -21
- package/dist/config-SP_VEcsX.mjs +0 -19
- package/dist/config-aVU8JEKy.mjs +0 -21
- package/dist/fetch-DNLodiAP.mjs +0 -13
- package/dist/got-BIOwnc0x.mjs +0 -13
- package/dist/index.d-99mf5fZX.d.mts +0 -7
- package/dist/index.d-B0Dj119v.d.mts +0 -7
- package/dist/index.d-B1n6Tnt1.d.mts +0 -12
- package/dist/index.d-BAZgb_b9.d.mts +0 -18
- package/dist/index.d-BG_KI3-b.d.mts +0 -7
- package/dist/index.d-BfFQykLh.d.mts +0 -12
- package/dist/index.d-BumPVmi6.d.mts +0 -14
- package/dist/index.d-Bxb1Ew8J.d.mts +0 -14
- package/dist/index.d-BxhX9ZHb.d.mts +0 -14
- package/dist/index.d-C7snKiSp.d.mts +0 -18
- package/dist/index.d-CBozMBWF.d.mts +0 -14
- package/dist/index.d-CDWq1HYV.d.mts +0 -18
- package/dist/index.d-CEAmhQXE.d.mts +0 -14
- package/dist/index.d-CJvL62Un.d.mts +0 -12
- package/dist/index.d-CTkBXgsL.d.mts +0 -7
- package/dist/index.d-CV6YWGPd.d.mts +0 -18
- package/dist/index.d-C_cfONoz.d.mts +0 -14
- package/dist/index.d-CkaW5o1S.d.mts +0 -7
- package/dist/index.d-CoyMx1eg.d.mts +0 -14
- package/dist/index.d-D2DYrmcB.d.mts +0 -14
- package/dist/index.d-D31630wD.d.mts +0 -18
- package/dist/index.d-D4dt4SN4.d.mts +0 -12
- package/dist/index.d-D8QZqVyr.d.mts +0 -18
- package/dist/index.d-DJrTX9xf.d.mts +0 -18
- package/dist/index.d-DMF-u4U9.d.mts +0 -18
- package/dist/index.d-DRC1cM3h.d.mts +0 -18
- package/dist/index.d-DZt4GzNR.d.mts +0 -18
- package/dist/index.d-DbmCOzZ_.d.mts +0 -12
- package/dist/index.d-DhevLWeK.d.mts +0 -18
- package/dist/index.d-Gm6xdqdc.d.mts +0 -14
- package/dist/index.d-KiVamk2z.d.mts +0 -12
- package/dist/index.d-Oclhn_rY.d.mts +0 -7
- package/dist/index.d-SEFhGKxl.d.mts +0 -7
- package/dist/index.d-dxrAw57N.d.mts +0 -7
- package/dist/index.d-fRobkY_s.d.mts +0 -18
- package/dist/index.d-ltrmOwIz.d.mts +0 -14
- package/dist/index.d-lzQFIw8d.d.mts +0 -7
- package/dist/index.d-mJ3Pcxey.d.mts +0 -14
- package/dist/index.d-xPgxVw9l.d.mts +0 -14
- package/dist/js-BIi60-ws.mjs +0 -19
- package/dist/js-CbvjSthC.mjs +0 -19
- package/dist/js-DrRwXaos.mjs +0 -19
- package/dist/js-_HvDqbMK.mjs +0 -19
- package/dist/js-rCsJDgHU.mjs +0 -19
- package/dist/js-tqiiLynG.mjs +0 -19
- package/dist/ky-P-rg3kH4.mjs +0 -13
- package/dist/ofetch-B_VRlsTN.mjs +0 -13
- package/dist/parser-BMWMb1tW.mjs +0 -65
- package/dist/parser-BOXlubkg.mjs +0 -64
- package/dist/parser-BYrX-ru-.mjs +0 -71
- package/dist/parser-BcgivITa.mjs +0 -79
- package/dist/parser-BtnVu9-k.mjs +0 -68
- package/dist/parser-ChqBZo9I.mjs +0 -70
- package/dist/parser-DqCzNFba.mjs +0 -65
- package/dist/parser-ZusEtk4G.mjs +0 -74
- package/dist/parser-ie6DpPJX.mjs +0 -64
- package/dist/parser-kk99DwsW.mjs +0 -71
- package/dist/parser-p29Uia9I.mjs +0 -69
- package/dist/parser-v9oBdoth.mjs +0 -71
- package/dist/ts-B-VDMOmJ.mjs +0 -19
- package/dist/ts-BAOPMwAr.mjs +0 -19
- package/dist/ts-BEo8NDau.mjs +0 -19
- package/dist/ts-C0RacOIG.mjs +0 -19
- package/dist/ts-CBWxAza5.mjs +0 -19
- package/dist/ts-UnhKokN_.mjs +0 -19
- package/dist/uni-CQMaFViG.mjs +0 -13
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
### `axios`
|
|
23
|
+
|
|
24
|
+
#### `js()`
|
|
25
|
+
|
|
26
|
+
#### `ts()`
|
|
27
|
+
|
|
28
|
+
### `default`
|
|
29
|
+
|
|
30
|
+
#### `axios`
|
|
31
|
+
|
|
32
|
+
##### `js()`
|
|
33
|
+
|
|
34
|
+
##### `ts()`
|
|
35
|
+
|
|
36
|
+
#### `fetch`
|
|
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 -->
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ApiPipeline } from "@genapi/shared";
|
|
2
|
+
|
|
3
|
+
//#region src/_shared/schema/compiler.d.ts
|
|
4
|
+
interface SchemaCompilerOptions {
|
|
5
|
+
/** HTTP client function name (e.g., 'fetch' or 'ofetch') */
|
|
6
|
+
httpClient: string;
|
|
7
|
+
}
|
|
8
|
+
declare function createSchemaCompiler(options: SchemaCompilerOptions): (config: ApiPipeline.ConfigRead) => ApiPipeline.ConfigRead<ApiPipeline.Config>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { SchemaCompilerOptions, createSchemaCompiler };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { compilerTsRequestDeclaration, compilerTsTypingsDeclaration } from "@genapi/pipeline";
|
|
2
|
+
import { genInterface, genTypeObject } from "knitwork-x";
|
|
3
|
+
|
|
4
|
+
//#region src/_shared/schema/compiler.ts
|
|
5
|
+
const [Endpoint, Dynamic] = [Symbol.for("Endpoint"), Symbol.for("DynamicParam")];
|
|
6
|
+
/** Ultimate type conversion: regex word boundary replacement, covering all complex nested scenarios */
|
|
7
|
+
function convert(str, names) {
|
|
8
|
+
return str?.replace(/\b\w+\b/g, (m) => names.has(m) ? `Types.${m}` : m) || "";
|
|
9
|
+
}
|
|
10
|
+
function createSchemaCompiler(options) {
|
|
11
|
+
return function compiler(config) {
|
|
12
|
+
const routes = config.__schemaRoutes || [];
|
|
13
|
+
const interfaceNames = new Set([...config.graphs.interfaces.map((i) => i.name), ...config.graphs.typings.filter((t) => t.name && !t.value?.includes("{")).map((t) => t.name)]);
|
|
14
|
+
const tree = routes.reduce((root, r) => {
|
|
15
|
+
const node = r.path.split("/").filter(Boolean).reduce((curr, p) => {
|
|
16
|
+
const key = p.startsWith("{") ? Dynamic : p;
|
|
17
|
+
return curr[key] = curr[key] || {};
|
|
18
|
+
}, root);
|
|
19
|
+
const ep = node[Endpoint] = node[Endpoint] || {};
|
|
20
|
+
ep[r.method] = genTypeObject({
|
|
21
|
+
response: convert(r.responseType, interfaceNames),
|
|
22
|
+
...r.queryType && { query: convert(r.queryType, interfaceNames) },
|
|
23
|
+
...r.bodyType && { body: convert(r.bodyType, interfaceNames) },
|
|
24
|
+
...r.headersType && { headers: convert(r.headersType, interfaceNames) }
|
|
25
|
+
});
|
|
26
|
+
return root;
|
|
27
|
+
}, {});
|
|
28
|
+
const toObj = (node, isRoot = false) => {
|
|
29
|
+
const res = {};
|
|
30
|
+
if (node[Endpoint]) res["[Endpoint]"] = genTypeObject(node[Endpoint]);
|
|
31
|
+
if (node[Dynamic]) res["[DynamicParam]"] = genTypeObject(toObj(node[Dynamic]));
|
|
32
|
+
Object.keys(node).forEach((k) => res[isRoot ? `/${k}` : k] = genTypeObject(toObj(node[k])));
|
|
33
|
+
return res;
|
|
34
|
+
};
|
|
35
|
+
config.graphs.functions = [{
|
|
36
|
+
export: true,
|
|
37
|
+
name: "$fetch",
|
|
38
|
+
async: true,
|
|
39
|
+
generics: [{
|
|
40
|
+
name: "T",
|
|
41
|
+
extends: "TypedFetchInput<APISchema>"
|
|
42
|
+
}],
|
|
43
|
+
parameters: [{
|
|
44
|
+
name: "input",
|
|
45
|
+
type: "T",
|
|
46
|
+
required: true
|
|
47
|
+
}, {
|
|
48
|
+
name: "init",
|
|
49
|
+
type: "TypedFetchRequestInit<APISchema, T>",
|
|
50
|
+
required: false
|
|
51
|
+
}],
|
|
52
|
+
body: [`return ${options.httpClient}(input, init as any) as Promise<TypedResponse<TypedFetchResponseBody<APISchema, T>>>`]
|
|
53
|
+
}];
|
|
54
|
+
config.outputs.forEach((out) => {
|
|
55
|
+
if (out.type === "request" && !config.config.meta?.onlyDeclaration) {
|
|
56
|
+
const code = compilerTsRequestDeclaration(config);
|
|
57
|
+
const schema = `\n// API Schema\n${genInterface("APISchema", toObj(tree, true))}\n`;
|
|
58
|
+
const idx = code.lastIndexOf("import");
|
|
59
|
+
const pos = idx !== -1 ? code.indexOf("\n", idx) + 1 : 0;
|
|
60
|
+
out.code = code.slice(0, pos) + schema + code.slice(pos);
|
|
61
|
+
} else if (out.type === "typings") out.code = compilerTsTypingsDeclaration(config);
|
|
62
|
+
});
|
|
63
|
+
return config;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { createSchemaCompiler };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ApiPipeline } from "@genapi/shared";
|
|
2
|
+
|
|
3
|
+
//#region src/_shared/schema/config.d.ts
|
|
4
|
+
interface SchemaConfigOptions {
|
|
5
|
+
/** HTTP client package name (e.g., 'ofetch') */
|
|
6
|
+
httpPackage?: string;
|
|
7
|
+
/** HTTP client function name to import (e.g., 'ofetch') */
|
|
8
|
+
httpClientName?: string;
|
|
9
|
+
}
|
|
10
|
+
declare function createSchemaConfig(options?: SchemaConfigOptions): (userConfig: ApiPipeline.Config) => ApiPipeline.ConfigRead;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { SchemaConfigOptions, createSchemaConfig };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { config } from "@genapi/pipeline";
|
|
2
|
+
|
|
3
|
+
//#region src/_shared/schema/config.ts
|
|
4
|
+
function createSchemaConfig(options = {}) {
|
|
5
|
+
return function config$1(userConfig) {
|
|
6
|
+
userConfig.meta = userConfig.meta || {};
|
|
7
|
+
userConfig.meta.import = userConfig.meta.import || {};
|
|
8
|
+
if (options.httpPackage && options.httpClientName) {
|
|
9
|
+
userConfig.meta.import.http = userConfig.meta.import.http || options.httpPackage;
|
|
10
|
+
const configRead = config(userConfig);
|
|
11
|
+
configRead.graphs.imports.push({
|
|
12
|
+
value: userConfig.meta.import.http,
|
|
13
|
+
names: [options.httpClientName]
|
|
14
|
+
});
|
|
15
|
+
configRead.graphs.imports.push({
|
|
16
|
+
names: [
|
|
17
|
+
"TypedFetchInput",
|
|
18
|
+
"TypedFetchRequestInit",
|
|
19
|
+
"TypedFetchResponseBody",
|
|
20
|
+
"TypedResponse",
|
|
21
|
+
"Endpoint",
|
|
22
|
+
"DynamicParam"
|
|
23
|
+
],
|
|
24
|
+
value: "fetchdts"
|
|
25
|
+
});
|
|
26
|
+
return configRead;
|
|
27
|
+
}
|
|
28
|
+
const configRead = config(userConfig);
|
|
29
|
+
configRead.graphs.imports.push({
|
|
30
|
+
names: [
|
|
31
|
+
"TypedFetchInput",
|
|
32
|
+
"TypedFetchRequestInit",
|
|
33
|
+
"TypedFetchResponseBody",
|
|
34
|
+
"TypedResponse",
|
|
35
|
+
"Endpoint",
|
|
36
|
+
"DynamicParam"
|
|
37
|
+
],
|
|
38
|
+
value: "fetchdts"
|
|
39
|
+
});
|
|
40
|
+
return configRead;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { createSchemaConfig };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SchemaCompilerOptions, createSchemaCompiler } from "./compiler.mjs";
|
|
2
|
+
import { SchemaConfigOptions, createSchemaConfig } from "./config.mjs";
|
|
3
|
+
import { SchemaRoute, schemaParser } from "./parser.mjs";
|
|
4
|
+
export { type SchemaCompilerOptions, type SchemaConfigOptions, type SchemaRoute, createSchemaCompiler, createSchemaConfig, schemaParser };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as _genapi_shared0 from "@genapi/shared";
|
|
2
|
+
|
|
3
|
+
//#region src/_shared/schema/parser.d.ts
|
|
4
|
+
interface SchemaRoute {
|
|
5
|
+
path: string;
|
|
6
|
+
method: string;
|
|
7
|
+
queryType?: string;
|
|
8
|
+
bodyType?: string;
|
|
9
|
+
headersType?: string;
|
|
10
|
+
responseType: string;
|
|
11
|
+
}
|
|
12
|
+
declare const schemaParser: (configRead: _genapi_shared0.ApiPipeline.ConfigRead) => _genapi_shared0.ApiPipeline.ConfigRead;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { SchemaRoute, schemaParser };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createParser, parseSchemaType } from "@genapi/parser";
|
|
2
|
+
|
|
3
|
+
//#region src/_shared/schema/parser.ts
|
|
4
|
+
function hasContent(r) {
|
|
5
|
+
return r != null && typeof r === "object" && "content" in r;
|
|
6
|
+
}
|
|
7
|
+
function getResponseType(responses) {
|
|
8
|
+
const resDefault = responses.default && hasContent(responses.default) ? responses.default : null;
|
|
9
|
+
const res200 = responses["200"] && typeof responses["200"] === "object" ? responses["200"] : null;
|
|
10
|
+
const contentDefault = resDefault?.content?.["application/json"];
|
|
11
|
+
const content200 = res200 && hasContent(res200) ? res200.content?.["application/json"] : null;
|
|
12
|
+
const schemaFromContent = (contentDefault && typeof contentDefault === "object" && "schema" in contentDefault ? contentDefault.schema : null) ?? (content200 && typeof content200 === "object" && "schema" in content200 ? content200.schema : null);
|
|
13
|
+
const schemaFromRes200 = res200 && typeof res200 === "object" && "schema" in res200 && !("content" in res200) ? res200.schema : null;
|
|
14
|
+
const responseSchema = schemaFromContent ?? schemaFromRes200;
|
|
15
|
+
return responseSchema && typeof responseSchema === "object" ? parseSchemaType(responseSchema) : "void";
|
|
16
|
+
}
|
|
17
|
+
const schemaParser = createParser((config, { configRead }) => {
|
|
18
|
+
const { path, method, responses, parameters } = config;
|
|
19
|
+
const queryParams = parameters.filter((p) => p.in === "query");
|
|
20
|
+
const headerParams = parameters.filter((p) => p.in === "header");
|
|
21
|
+
const bodyParams = parameters.filter((p) => p.in === "body");
|
|
22
|
+
const responseType = getResponseType(responses);
|
|
23
|
+
let queryType;
|
|
24
|
+
if (queryParams.length > 0) queryType = `{ ${queryParams.map((p) => {
|
|
25
|
+
const type = parseSchemaType(p);
|
|
26
|
+
const optional = p.required ? "" : "?";
|
|
27
|
+
return `${p.name}${optional}: ${type}`;
|
|
28
|
+
}).join("; ")} }`;
|
|
29
|
+
let bodyType;
|
|
30
|
+
if (bodyParams.length > 0) bodyType = parseSchemaType(bodyParams[0]);
|
|
31
|
+
let headersType;
|
|
32
|
+
if (headerParams.length > 0) headersType = `{ ${headerParams.map((p) => {
|
|
33
|
+
const type = parseSchemaType(p);
|
|
34
|
+
const optional = p.required ? "" : "?";
|
|
35
|
+
return `'${p.name}'${optional}: ${type}`;
|
|
36
|
+
}).join("; ")} }`;
|
|
37
|
+
configRead.__schemaRoutes = configRead.__schemaRoutes || [];
|
|
38
|
+
configRead.__schemaRoutes.push({
|
|
39
|
+
path,
|
|
40
|
+
method: method.toUpperCase(),
|
|
41
|
+
queryType,
|
|
42
|
+
bodyType,
|
|
43
|
+
headersType,
|
|
44
|
+
responseType
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { schemaParser };
|
package/dist/axios/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "
|
|
3
|
-
import { openapiPipeline$6 as openapiPipeline } from "../index.d-DJrTX9xf.mjs";
|
|
4
|
-
import "../index.d-BumPVmi6.mjs";
|
|
5
|
-
import "../index.d-SEFhGKxl.mjs";
|
|
6
|
-
import { openapiPipeline$2 as openapiPipeline$1 } from "../index.d-fRobkY_s.mjs";
|
|
7
|
-
import "../index.d-CJvL62Un.mjs";
|
|
1
|
+
import openapiPipeline from "./js/index.mjs";
|
|
2
|
+
import openapiPipeline$1 from "./ts/index.mjs";
|
|
8
3
|
|
|
9
|
-
|
|
4
|
+
//#region src/axios/index.d.ts
|
|
5
|
+
declare namespace index_d_exports {
|
|
6
|
+
export { openapiPipeline as js, openapiPipeline$1 as ts };
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { openapiPipeline as js, index_d_exports as t, openapiPipeline$1 as ts };
|
package/dist/axios/index.mjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import "
|
|
3
|
-
import
|
|
4
|
-
import "../config-Bt-OVtrF.mjs";
|
|
5
|
-
import "../parser-ie6DpPJX.mjs";
|
|
6
|
-
import { ts_default$1 as ts_default } from "../ts-UnhKokN_.mjs";
|
|
7
|
-
import "../axios-C-GYxVyS.mjs";
|
|
1
|
+
import { t as __exportAll } from "../chunk-DQk6qfdC.mjs";
|
|
2
|
+
import openapiPipeline from "./js/index.mjs";
|
|
3
|
+
import openapiPipeline$1 from "./ts/index.mjs";
|
|
8
4
|
|
|
9
|
-
|
|
5
|
+
//#region src/axios/index.ts
|
|
6
|
+
var axios_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
js: () => openapiPipeline,
|
|
8
|
+
ts: () => openapiPipeline$1
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { openapiPipeline as js, axios_exports as t, openapiPipeline$1 as ts };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApiPipeline } from "@genapi/shared";
|
|
2
2
|
|
|
3
|
+
//#region src/axios/js/config/index.d.ts
|
|
4
|
+
declare function config(userConfig: ApiPipeline.Config): ApiPipeline.ConfigRead;
|
|
5
|
+
//#endregion
|
|
3
6
|
export { config };
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
import { config
|
|
1
|
+
import { config as config$1 } from "@genapi/pipeline";
|
|
2
|
+
import { replaceMainext } from "@genapi/parser";
|
|
2
3
|
|
|
4
|
+
//#region src/axios/js/config/index.ts
|
|
5
|
+
function config(userConfig) {
|
|
6
|
+
userConfig.meta = userConfig.meta || {};
|
|
7
|
+
userConfig.meta.import = userConfig.meta.import || {};
|
|
8
|
+
userConfig.output = userConfig.output || {};
|
|
9
|
+
userConfig.meta.import.http = userConfig.meta.import.http || "axios";
|
|
10
|
+
userConfig.output = replaceMainext(userConfig.output) || "src/api/index.js";
|
|
11
|
+
const configRead = config$1(userConfig);
|
|
12
|
+
configRead.graphs.imports.push({
|
|
13
|
+
name: "http",
|
|
14
|
+
value: userConfig.meta.import.http
|
|
15
|
+
});
|
|
16
|
+
return configRead;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
3
20
|
export { config };
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { config } from "./config/index.mjs";
|
|
2
|
+
import { parser } from "./parser/index.mjs";
|
|
3
|
+
import * as _genapi_pipeline0 from "@genapi/pipeline";
|
|
4
|
+
import { compiler, dest, generate, original } from "@genapi/pipeline";
|
|
5
|
+
import { ApiPipeline } from "@genapi/shared";
|
|
4
6
|
|
|
7
|
+
//#region src/axios/js/index.d.ts
|
|
8
|
+
declare function openapiPipeline(userConfig: ApiPipeline.Config): Promise<void>;
|
|
9
|
+
declare namespace openapiPipeline {
|
|
10
|
+
var config: typeof config;
|
|
11
|
+
var original: typeof _genapi_pipeline0.original;
|
|
12
|
+
var parser: (configRead: ApiPipeline.ConfigRead) => ApiPipeline.ConfigRead;
|
|
13
|
+
var compiler: typeof _genapi_pipeline0.compiler;
|
|
14
|
+
var generate: typeof _genapi_pipeline0.generate;
|
|
15
|
+
var dest: typeof _genapi_pipeline0.dest;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
5
18
|
export { compiler, config, openapiPipeline as default, dest, generate, original, parser };
|
package/dist/axios/js/index.mjs
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
import { config
|
|
2
|
-
import { parser
|
|
3
|
-
import { compiler
|
|
1
|
+
import { config } from "./config/index.mjs";
|
|
2
|
+
import { parser } from "./parser/index.mjs";
|
|
3
|
+
import pipeline, { compiler, dest, generate, original } from "@genapi/pipeline";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
//#region src/axios/js/index.ts
|
|
6
|
+
function openapiPipeline(userConfig) {
|
|
7
|
+
return pipeline((userConfig) => config(userConfig), (configRead) => original(configRead), (configRead) => parser(configRead), (configRead) => compiler(configRead), (configRead) => generate(configRead), (configRead) => dest(configRead))(userConfig);
|
|
8
|
+
}
|
|
9
|
+
openapiPipeline.config = config;
|
|
10
|
+
openapiPipeline.original = original;
|
|
11
|
+
openapiPipeline.parser = parser;
|
|
12
|
+
openapiPipeline.compiler = compiler;
|
|
13
|
+
openapiPipeline.generate = generate;
|
|
14
|
+
openapiPipeline.dest = dest;
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { compiler, config, openapiPipeline as default, dest, generate, original, parser };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _genapi_shared0 from "@genapi/shared";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
//#region src/axios/js/parser/index.d.ts
|
|
4
|
+
declare const parser: (configRead: _genapi_shared0.ApiPipeline.ConfigRead) => _genapi_shared0.ApiPipeline.ConfigRead;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { parser };
|
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createParser, literalFieldsToString, parseMethodMetadata, parseMethodParameters, transformParameters, transformUrlSyntax } from "@genapi/parser";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
//#region src/axios/js/parser/index.ts
|
|
4
|
+
const parser = createParser((config, { configRead, functions, interfaces }) => {
|
|
5
|
+
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config, {
|
|
6
|
+
body: "data",
|
|
7
|
+
query: "params"
|
|
8
|
+
});
|
|
9
|
+
let { name, description, url, responseType } = parseMethodMetadata(config);
|
|
10
|
+
options.push(["...", "config"]);
|
|
11
|
+
interfaces.push(...attachInters);
|
|
12
|
+
parameters.push({
|
|
13
|
+
type: "import('axios').AxiosRequestConfig",
|
|
14
|
+
name: "config",
|
|
15
|
+
required: false
|
|
16
|
+
});
|
|
17
|
+
options.unshift("url");
|
|
18
|
+
options.unshift(["method", `"${config.method}"`]);
|
|
19
|
+
if (configRead.config.meta?.baseURL) options.unshift("baseURL");
|
|
20
|
+
transformParameters(parameters, {
|
|
21
|
+
syntax: "ecmascript",
|
|
22
|
+
configRead,
|
|
23
|
+
description,
|
|
24
|
+
interfaces,
|
|
25
|
+
responseType,
|
|
26
|
+
generic: "import('axios').AxiosResponse<{__type__}>"
|
|
27
|
+
});
|
|
28
|
+
url = transformUrlSyntax(url);
|
|
29
|
+
functions.push({
|
|
30
|
+
export: true,
|
|
31
|
+
name,
|
|
32
|
+
description,
|
|
33
|
+
parameters,
|
|
34
|
+
body: [`const url = ${url}`, `return http.request({ ${literalFieldsToString(options)} })`]
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { parser };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApiPipeline } from "@genapi/shared";
|
|
2
2
|
|
|
3
|
+
//#region src/axios/ts/config/index.d.ts
|
|
4
|
+
declare function config(userConfig: ApiPipeline.Config): ApiPipeline.ConfigRead;
|
|
5
|
+
//#endregion
|
|
3
6
|
export { config };
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
import { config
|
|
1
|
+
import { config as config$1 } from "@genapi/pipeline";
|
|
2
2
|
|
|
3
|
+
//#region src/axios/ts/config/index.ts
|
|
4
|
+
function config(userConfig) {
|
|
5
|
+
userConfig.meta = userConfig.meta || {};
|
|
6
|
+
userConfig.meta.import = userConfig.meta.import || {};
|
|
7
|
+
userConfig.meta.import.http = userConfig.meta.import.http || "axios";
|
|
8
|
+
const configRead = config$1(userConfig);
|
|
9
|
+
configRead.graphs.imports.push({
|
|
10
|
+
name: "http",
|
|
11
|
+
names: userConfig.meta.import.http === "axios" ? ["AxiosRequestConfig"] : void 0,
|
|
12
|
+
value: userConfig.meta.import.http
|
|
13
|
+
});
|
|
14
|
+
if (userConfig.meta.import.http !== "axios") configRead.graphs.imports.push({
|
|
15
|
+
names: ["AxiosRequestConfig"],
|
|
16
|
+
value: "axios"
|
|
17
|
+
});
|
|
18
|
+
return configRead;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
3
22
|
export { config };
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { config } from "./config/index.mjs";
|
|
2
|
+
import { parser } from "./parser/index.mjs";
|
|
3
|
+
import * as _genapi_pipeline0 from "@genapi/pipeline";
|
|
4
|
+
import { compiler, dest, generate, original } from "@genapi/pipeline";
|
|
5
|
+
import { ApiPipeline } from "@genapi/shared";
|
|
4
6
|
|
|
7
|
+
//#region src/axios/ts/index.d.ts
|
|
8
|
+
declare function openapiPipeline(userConfig: ApiPipeline.Config): Promise<void>;
|
|
9
|
+
declare namespace openapiPipeline {
|
|
10
|
+
var config: typeof config;
|
|
11
|
+
var original: typeof _genapi_pipeline0.original;
|
|
12
|
+
var parser: (configRead: ApiPipeline.ConfigRead) => ApiPipeline.ConfigRead;
|
|
13
|
+
var compiler: typeof _genapi_pipeline0.compiler;
|
|
14
|
+
var generate: typeof _genapi_pipeline0.generate;
|
|
15
|
+
var dest: typeof _genapi_pipeline0.dest;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
5
18
|
export { compiler, config, openapiPipeline as default, dest, generate, original, parser };
|
package/dist/axios/ts/index.mjs
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
import { config
|
|
2
|
-
import { parser
|
|
3
|
-
import { compiler
|
|
1
|
+
import { config } from "./config/index.mjs";
|
|
2
|
+
import { parser } from "./parser/index.mjs";
|
|
3
|
+
import pipeline, { compiler, dest, generate, original } from "@genapi/pipeline";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
//#region src/axios/ts/index.ts
|
|
6
|
+
function openapiPipeline(userConfig) {
|
|
7
|
+
return pipeline((userConfig) => config(userConfig), (configRead) => original(configRead), (configRead) => parser(configRead), (configRead) => compiler(configRead), (configRead) => generate(configRead), (configRead) => dest(configRead))(userConfig);
|
|
8
|
+
}
|
|
9
|
+
openapiPipeline.config = config;
|
|
10
|
+
openapiPipeline.original = original;
|
|
11
|
+
openapiPipeline.parser = parser;
|
|
12
|
+
openapiPipeline.compiler = compiler;
|
|
13
|
+
openapiPipeline.generate = generate;
|
|
14
|
+
openapiPipeline.dest = dest;
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { compiler, config, openapiPipeline as default, dest, generate, original, parser };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _genapi_shared0 from "@genapi/shared";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
//#region src/axios/ts/parser/index.d.ts
|
|
4
|
+
declare const parser: (configRead: _genapi_shared0.ApiPipeline.ConfigRead) => _genapi_shared0.ApiPipeline.ConfigRead;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { parser };
|
|
@@ -1,3 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createParser, literalFieldsToString, parseMethodMetadata, parseMethodParameters, transformParameters, transformUrlSyntax } from "@genapi/parser";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
//#region src/axios/ts/parser/index.ts
|
|
4
|
+
const parser = createParser((config, { configRead, functions, interfaces }) => {
|
|
5
|
+
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config, {
|
|
6
|
+
body: "data",
|
|
7
|
+
query: "params"
|
|
8
|
+
});
|
|
9
|
+
let { name, description, url, responseType } = parseMethodMetadata(config);
|
|
10
|
+
options.push(["...", "config"]);
|
|
11
|
+
interfaces.push(...attachInters);
|
|
12
|
+
parameters.push({
|
|
13
|
+
name: "config",
|
|
14
|
+
type: "AxiosRequestConfig",
|
|
15
|
+
required: false
|
|
16
|
+
});
|
|
17
|
+
options.unshift("url");
|
|
18
|
+
options.unshift(["method", `"${config.method}"`]);
|
|
19
|
+
if (configRead.config.meta?.baseURL) options.unshift("baseURL");
|
|
20
|
+
const { spaceResponseType } = transformParameters(parameters, {
|
|
21
|
+
syntax: "typescript",
|
|
22
|
+
configRead,
|
|
23
|
+
description,
|
|
24
|
+
interfaces,
|
|
25
|
+
responseType
|
|
26
|
+
});
|
|
27
|
+
url = transformUrlSyntax(url);
|
|
28
|
+
functions.push({
|
|
29
|
+
export: true,
|
|
30
|
+
name,
|
|
31
|
+
description,
|
|
32
|
+
parameters,
|
|
33
|
+
body: [`const url = ${url}`, `return http.request<${spaceResponseType}>({ ${literalFieldsToString(options)} })`]
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { parser };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) {
|
|
6
|
+
__defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
if (!no_symbols) {
|
|
12
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { __exportAll as t };
|