@genapi/presets 3.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.
Files changed (126) hide show
  1. package/LICENSE.md +21 -0
  2. package/dist/axios/index.d.ts +9 -0
  3. package/dist/axios/index.mjs +7 -0
  4. package/dist/axios/js/config/index.d.ts +5 -0
  5. package/dist/axios/js/config/index.mjs +18 -0
  6. package/dist/axios/js/index.d.ts +6 -0
  7. package/dist/axios/js/index.mjs +25 -0
  8. package/dist/axios/js/parser/index.d.ts +12 -0
  9. package/dist/axios/js/parser/index.mjs +77 -0
  10. package/dist/axios/ts/config/index.d.ts +5 -0
  11. package/dist/axios/ts/config/index.mjs +22 -0
  12. package/dist/axios/ts/index.d.ts +6 -0
  13. package/dist/axios/ts/index.mjs +25 -0
  14. package/dist/axios/ts/parser/index.d.ts +12 -0
  15. package/dist/axios/ts/parser/index.mjs +76 -0
  16. package/dist/fetch/index.d.ts +9 -0
  17. package/dist/fetch/index.mjs +7 -0
  18. package/dist/fetch/js/config/index.d.ts +5 -0
  19. package/dist/fetch/js/config/index.mjs +13 -0
  20. package/dist/fetch/js/index.d.ts +6 -0
  21. package/dist/fetch/js/index.mjs +25 -0
  22. package/dist/fetch/js/parser/index.d.ts +12 -0
  23. package/dist/fetch/js/parser/index.mjs +83 -0
  24. package/dist/fetch/ts/config/index.d.ts +5 -0
  25. package/dist/fetch/ts/config/index.mjs +11 -0
  26. package/dist/fetch/ts/index.d.ts +6 -0
  27. package/dist/fetch/ts/index.mjs +25 -0
  28. package/dist/fetch/ts/parser/index.d.ts +12 -0
  29. package/dist/fetch/ts/parser/index.mjs +79 -0
  30. package/dist/got/index.d.ts +9 -0
  31. package/dist/got/index.mjs +7 -0
  32. package/dist/got/js/config/index.d.ts +5 -0
  33. package/dist/got/js/config/index.mjs +18 -0
  34. package/dist/got/js/index.d.ts +6 -0
  35. package/dist/got/js/index.mjs +25 -0
  36. package/dist/got/js/parser/index.d.ts +12 -0
  37. package/dist/got/js/parser/index.mjs +82 -0
  38. package/dist/got/ts/config/index.d.ts +5 -0
  39. package/dist/got/ts/config/index.mjs +22 -0
  40. package/dist/got/ts/index.d.ts +6 -0
  41. package/dist/got/ts/index.mjs +25 -0
  42. package/dist/got/ts/parser/index.d.ts +12 -0
  43. package/dist/got/ts/parser/index.mjs +82 -0
  44. package/dist/index--xiziIvG.d.ts +8 -0
  45. package/dist/index-BByL5W2V.d.ts +18 -0
  46. package/dist/index-BIRCFgYi.d.ts +18 -0
  47. package/dist/index-BJrp0lx3.d.ts +18 -0
  48. package/dist/index-BWvY4w5U.d.ts +8 -0
  49. package/dist/index-BnNpBsOT.d.ts +18 -0
  50. package/dist/index-CApSnKVf.d.ts +8 -0
  51. package/dist/index-CQJFGBWr.d.ts +8 -0
  52. package/dist/index-DBbTnSBj.d.ts +18 -0
  53. package/dist/index-DEC0eIj4.d.ts +18 -0
  54. package/dist/index-DZ7D8MkM.d.ts +18 -0
  55. package/dist/index-IqUGJ_D5.d.ts +8 -0
  56. package/dist/index-VKTbyIEw.d.ts +18 -0
  57. package/dist/index-pIxMzJ5o.d.ts +18 -0
  58. package/dist/index-vrb8mA6n.d.ts +18 -0
  59. package/dist/index.d.ts +48 -0
  60. package/dist/index.mjs +21 -0
  61. package/dist/ky/index.d.ts +9 -0
  62. package/dist/ky/index.mjs +7 -0
  63. package/dist/ky/js/config/index.d.ts +5 -0
  64. package/dist/ky/js/config/index.mjs +18 -0
  65. package/dist/ky/js/index.d.ts +6 -0
  66. package/dist/ky/js/index.mjs +25 -0
  67. package/dist/ky/js/parser/index.d.ts +12 -0
  68. package/dist/ky/js/parser/index.mjs +79 -0
  69. package/dist/ky/ts/config/index.d.ts +5 -0
  70. package/dist/ky/ts/config/index.mjs +22 -0
  71. package/dist/ky/ts/index.d.ts +6 -0
  72. package/dist/ky/ts/index.mjs +25 -0
  73. package/dist/ky/ts/parser/index.d.ts +12 -0
  74. package/dist/ky/ts/parser/index.mjs +78 -0
  75. package/dist/ofetch/index.d.ts +9 -0
  76. package/dist/ofetch/index.mjs +7 -0
  77. package/dist/ofetch/js/config/index.d.ts +5 -0
  78. package/dist/ofetch/js/config/index.mjs +18 -0
  79. package/dist/ofetch/js/index.d.ts +6 -0
  80. package/dist/ofetch/js/index.mjs +25 -0
  81. package/dist/ofetch/js/parser/index.d.ts +12 -0
  82. package/dist/ofetch/js/parser/index.mjs +78 -0
  83. package/dist/ofetch/ts/config/index.d.ts +5 -0
  84. package/dist/ofetch/ts/config/index.mjs +22 -0
  85. package/dist/ofetch/ts/index.d.ts +6 -0
  86. package/dist/ofetch/ts/index.mjs +25 -0
  87. package/dist/ofetch/ts/parser/index.d.ts +12 -0
  88. package/dist/ofetch/ts/parser/index.mjs +76 -0
  89. package/package.json +71 -0
  90. package/src/axios/index.ts +2 -0
  91. package/src/axios/js/config/index.ts +19 -0
  92. package/src/axios/js/index.ts +19 -0
  93. package/src/axios/js/parser/index.ts +96 -0
  94. package/src/axios/ts/config/index.ts +24 -0
  95. package/src/axios/ts/index.ts +20 -0
  96. package/src/axios/ts/parser/index.ts +95 -0
  97. package/src/fetch/index.ts +2 -0
  98. package/src/fetch/js/config/index.ts +12 -0
  99. package/src/fetch/js/index.ts +19 -0
  100. package/src/fetch/js/parser/index.ts +107 -0
  101. package/src/fetch/ts/config/index.ts +11 -0
  102. package/src/fetch/ts/index.ts +20 -0
  103. package/src/fetch/ts/parser/index.ts +98 -0
  104. package/src/got/index.ts +2 -0
  105. package/src/got/js/config/index.ts +19 -0
  106. package/src/got/js/index.ts +20 -0
  107. package/src/got/js/parser/index.ts +101 -0
  108. package/src/got/ts/config/index.ts +24 -0
  109. package/src/got/ts/index.ts +20 -0
  110. package/src/got/ts/parser/index.ts +102 -0
  111. package/src/index.ts +21 -0
  112. package/src/ky/index.ts +2 -0
  113. package/src/ky/js/config/index.ts +19 -0
  114. package/src/ky/js/index.ts +20 -0
  115. package/src/ky/js/parser/index.ts +97 -0
  116. package/src/ky/ts/config/index.ts +24 -0
  117. package/src/ky/ts/index.ts +20 -0
  118. package/src/ky/ts/parser/index.ts +97 -0
  119. package/src/ofetch/index.ts +2 -0
  120. package/src/ofetch/js/config/index.ts +19 -0
  121. package/src/ofetch/js/index.ts +20 -0
  122. package/src/ofetch/js/parser/index.ts +97 -0
  123. package/src/ofetch/ts/config/index.ts +24 -0
  124. package/src/ofetch/ts/index.ts +20 -0
  125. package/src/ofetch/ts/parser/index.ts +96 -0
  126. package/tsup.config.ts +18 -0
package/LICENSE.md ADDED
@@ -0,0 +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.
@@ -0,0 +1,9 @@
1
+ export { i as js } from '../index-BByL5W2V.js';
2
+ export { i as ts } from '../index-DBbTnSBj.js';
3
+ import '@genapi/shared';
4
+ import '@genapi/pipeline';
5
+ import './js/config/index.js';
6
+ import './js/parser/index.js';
7
+ import 'openapi-specification-types';
8
+ import './ts/config/index.js';
9
+ import './ts/parser/index.js';
@@ -0,0 +1,7 @@
1
+ // src/axios/index.ts
2
+ import * as js from "./js/index.mjs";
3
+ import * as ts from "./ts/index.mjs";
4
+ export {
5
+ js,
6
+ ts
7
+ };
@@ -0,0 +1,5 @@
1
+ import { ApiPipeline } from '@genapi/shared';
2
+
3
+ declare function config(userConfig: ApiPipeline.Config): ApiPipeline.ConfigRead;
4
+
5
+ export { config };
@@ -0,0 +1,18 @@
1
+ // src/axios/js/config/index.ts
2
+ import { replaceMainext } from "@genapi/parser";
3
+ import { config as _config } from "@genapi/pipeline";
4
+ function config(userConfig) {
5
+ userConfig.import = userConfig.import || {};
6
+ userConfig.output = userConfig.output || {};
7
+ userConfig.import.http = userConfig.import.http || "axios";
8
+ userConfig.output = replaceMainext(userConfig.output) || "src/api/index.js";
9
+ const configRead = _config(userConfig);
10
+ configRead.graphs.imports.push({
11
+ name: "http",
12
+ value: userConfig.import.http
13
+ });
14
+ return configRead;
15
+ }
16
+ export {
17
+ config
18
+ };
@@ -0,0 +1,6 @@
1
+ import '@genapi/shared';
2
+ export { compiler, dest, generate, original } from '@genapi/pipeline';
3
+ export { config } from './config/index.js';
4
+ export { parser } from './parser/index.js';
5
+ export { o as default } from '../../index-BByL5W2V.js';
6
+ import 'openapi-specification-types';
@@ -0,0 +1,25 @@
1
+ // src/axios/js/index.ts
2
+ import pipeline, { compiler, dest, generate, original } from "@genapi/pipeline";
3
+ import { config } from "./config/index.mjs";
4
+ import { parser } from "./parser/index.mjs";
5
+ function openapiPipeline(userConfig) {
6
+ const process = pipeline(
7
+ (userConfig2) => config(userConfig2),
8
+ (configRead) => original(configRead),
9
+ (configRead) => parser(configRead),
10
+ (configRead) => compiler(configRead),
11
+ (configRead) => generate(configRead),
12
+ (configRead) => dest(configRead)
13
+ );
14
+ return process(userConfig);
15
+ }
16
+ var js_default = openapiPipeline;
17
+ export {
18
+ compiler,
19
+ config,
20
+ js_default as default,
21
+ dest,
22
+ generate,
23
+ original,
24
+ parser
25
+ };
@@ -0,0 +1,12 @@
1
+ import { ApiPipeline, StatementInterface, StatementFunction } from '@genapi/shared';
2
+ import { Paths } from 'openapi-specification-types';
3
+
4
+ interface PathsTransformOptions {
5
+ configRead: ApiPipeline.ConfigRead;
6
+ interfaces: StatementInterface[];
7
+ functions: StatementFunction[];
8
+ }
9
+ declare function parser(configRead: ApiPipeline.ConfigRead): ApiPipeline.ConfigRead<ApiPipeline.Config>;
10
+ declare function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions): void;
11
+
12
+ export { type PathsTransformOptions, parser, transformPaths };
@@ -0,0 +1,77 @@
1
+ // src/axios/js/parser/index.ts
2
+ import {
3
+ literalFieldsToString,
4
+ parseHeaderCommits,
5
+ parseMethodMetadata,
6
+ parseMethodParameters,
7
+ parseOpenapiSpecification,
8
+ transformBaseURL,
9
+ transformDefinitions,
10
+ transformParameters,
11
+ transformUrlSyntax,
12
+ traversePaths
13
+ } from "@genapi/parser";
14
+ function parser(configRead) {
15
+ const source = parseOpenapiSpecification(configRead.source);
16
+ const comments = parseHeaderCommits(source);
17
+ const interfaces = [];
18
+ const functions = [];
19
+ transformBaseURL(source, {
20
+ configRead
21
+ });
22
+ transformDefinitions(source.definitions, {
23
+ interfaces
24
+ });
25
+ transformPaths(source.paths, {
26
+ configRead,
27
+ functions,
28
+ interfaces
29
+ });
30
+ configRead.graphs.comments = comments;
31
+ configRead.graphs.functions = functions;
32
+ configRead.graphs.interfaces = interfaces;
33
+ return configRead;
34
+ }
35
+ function transformPaths(paths, { configRead, functions, interfaces }) {
36
+ traversePaths(paths, (config) => {
37
+ const { parameters, interfaces: attachInters, options } = parseMethodParameters(config, {
38
+ body: "data",
39
+ query: "params"
40
+ });
41
+ let { name, description, url, responseType } = parseMethodMetadata(config);
42
+ options.push(["...", "config"]);
43
+ interfaces.push(...attachInters);
44
+ parameters.push({
45
+ type: "import('axios').AxiosRequestConfig",
46
+ name: "config",
47
+ required: false
48
+ });
49
+ options.unshift("url");
50
+ options.unshift(["method", `"${config.method}"`]);
51
+ if (configRead.config.baseURL)
52
+ options.unshift("baseURL");
53
+ transformParameters(parameters, {
54
+ syntax: "ecmascript",
55
+ configRead,
56
+ description,
57
+ interfaces,
58
+ responseType,
59
+ generic: "import('axios').AxiosResponse<{__type__}>"
60
+ });
61
+ url = transformUrlSyntax(url);
62
+ functions.push({
63
+ export: true,
64
+ name,
65
+ description,
66
+ parameters,
67
+ body: [
68
+ `const url = ${url}`,
69
+ `return http.request({ ${literalFieldsToString(options)} })`
70
+ ]
71
+ });
72
+ });
73
+ }
74
+ export {
75
+ parser,
76
+ transformPaths
77
+ };
@@ -0,0 +1,5 @@
1
+ import { ApiPipeline } from '@genapi/shared';
2
+
3
+ declare function config(userConfig: ApiPipeline.Config): ApiPipeline.ConfigRead;
4
+
5
+ export { config };
@@ -0,0 +1,22 @@
1
+ // src/axios/ts/config/index.ts
2
+ import { config as _config } from "@genapi/pipeline";
3
+ function config(userConfig) {
4
+ userConfig.import = userConfig.import || {};
5
+ userConfig.import.http = userConfig.import.http || "axios";
6
+ const configRead = _config(userConfig);
7
+ configRead.graphs.imports.push({
8
+ name: "http",
9
+ names: userConfig.import.http === "axios" ? ["AxiosRequestConfig"] : void 0,
10
+ value: userConfig.import.http
11
+ });
12
+ if (userConfig.import.http !== "axios") {
13
+ configRead.graphs.imports.push({
14
+ names: ["AxiosRequestConfig"],
15
+ value: "axios"
16
+ });
17
+ }
18
+ return configRead;
19
+ }
20
+ export {
21
+ config
22
+ };
@@ -0,0 +1,6 @@
1
+ import '@genapi/shared';
2
+ export { compiler, dest, generate, original } from '@genapi/pipeline';
3
+ export { config } from './config/index.js';
4
+ export { parser } from './parser/index.js';
5
+ export { o as default } from '../../index-DBbTnSBj.js';
6
+ import 'openapi-specification-types';
@@ -0,0 +1,25 @@
1
+ // src/axios/ts/index.ts
2
+ import pipeline, { compiler, dest, generate, original } from "@genapi/pipeline";
3
+ import { config } from "./config/index.mjs";
4
+ import { parser } from "./parser/index.mjs";
5
+ function openapiPipeline(userConfig) {
6
+ const process = pipeline(
7
+ (userConfig2) => config(userConfig2),
8
+ (configRead) => original(configRead),
9
+ (configRead) => parser(configRead),
10
+ (configRead) => compiler(configRead),
11
+ (configRead) => generate(configRead),
12
+ (configRead) => dest(configRead)
13
+ );
14
+ return process(userConfig);
15
+ }
16
+ var ts_default = openapiPipeline;
17
+ export {
18
+ compiler,
19
+ config,
20
+ ts_default as default,
21
+ dest,
22
+ generate,
23
+ original,
24
+ parser
25
+ };
@@ -0,0 +1,12 @@
1
+ import { ApiPipeline, StatementInterface, StatementFunction } from '@genapi/shared';
2
+ import { Paths } from 'openapi-specification-types';
3
+
4
+ interface PathsTransformOptions {
5
+ configRead: ApiPipeline.ConfigRead;
6
+ interfaces: StatementInterface[];
7
+ functions: StatementFunction[];
8
+ }
9
+ declare function parser(configRead: ApiPipeline.ConfigRead): ApiPipeline.ConfigRead<ApiPipeline.Config>;
10
+ declare function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions): void;
11
+
12
+ export { type PathsTransformOptions, parser, transformPaths };
@@ -0,0 +1,76 @@
1
+ // src/axios/ts/parser/index.ts
2
+ import {
3
+ literalFieldsToString,
4
+ parseHeaderCommits,
5
+ parseMethodMetadata,
6
+ parseMethodParameters,
7
+ parseOpenapiSpecification,
8
+ transformBaseURL,
9
+ transformDefinitions,
10
+ transformParameters,
11
+ transformUrlSyntax,
12
+ traversePaths
13
+ } from "@genapi/parser";
14
+ function parser(configRead) {
15
+ const source = parseOpenapiSpecification(configRead.source);
16
+ const comments = parseHeaderCommits(source);
17
+ const interfaces = [];
18
+ const functions = [];
19
+ transformBaseURL(source, {
20
+ configRead
21
+ });
22
+ transformDefinitions(source.definitions, {
23
+ interfaces
24
+ });
25
+ transformPaths(source.paths, {
26
+ configRead,
27
+ functions,
28
+ interfaces
29
+ });
30
+ configRead.graphs.comments = comments;
31
+ configRead.graphs.functions = functions;
32
+ configRead.graphs.interfaces = interfaces;
33
+ return configRead;
34
+ }
35
+ function transformPaths(paths, { configRead, functions, interfaces }) {
36
+ traversePaths(paths, (config) => {
37
+ const { parameters, interfaces: attachInters, options } = parseMethodParameters(config, {
38
+ body: "data",
39
+ query: "params"
40
+ });
41
+ let { name, description, url, responseType } = parseMethodMetadata(config);
42
+ options.push(["...", "config"]);
43
+ interfaces.push(...attachInters);
44
+ parameters.push({
45
+ name: "config",
46
+ type: "AxiosRequestConfig",
47
+ required: false
48
+ });
49
+ options.unshift("url");
50
+ options.unshift(["method", `"${config.method}"`]);
51
+ if (configRead.config.baseURL)
52
+ options.unshift("baseURL");
53
+ const { spaceResponseType } = transformParameters(parameters, {
54
+ syntax: "typescript",
55
+ configRead,
56
+ description,
57
+ interfaces,
58
+ responseType
59
+ });
60
+ url = transformUrlSyntax(url);
61
+ functions.push({
62
+ export: true,
63
+ name,
64
+ description,
65
+ parameters,
66
+ body: [
67
+ `const url = ${url}`,
68
+ `return http.request<${spaceResponseType}>({ ${literalFieldsToString(options)} })`
69
+ ]
70
+ });
71
+ });
72
+ }
73
+ export {
74
+ parser,
75
+ transformPaths
76
+ };
@@ -0,0 +1,9 @@
1
+ export { i as js } from '../index-pIxMzJ5o.js';
2
+ export { i as ts } from '../index-vrb8mA6n.js';
3
+ import '@genapi/shared';
4
+ import '@genapi/pipeline';
5
+ import './js/config/index.js';
6
+ import './js/parser/index.js';
7
+ import 'openapi-specification-types';
8
+ import './ts/config/index.js';
9
+ import './ts/parser/index.js';
@@ -0,0 +1,7 @@
1
+ // src/fetch/index.ts
2
+ import * as js from "./js/index.mjs";
3
+ import * as ts from "./ts/index.mjs";
4
+ export {
5
+ js,
6
+ ts
7
+ };
@@ -0,0 +1,5 @@
1
+ import { ApiPipeline } from '@genapi/shared';
2
+
3
+ declare function config(userConfig: ApiPipeline.Config): ApiPipeline.ConfigRead;
4
+
5
+ export { config };
@@ -0,0 +1,13 @@
1
+ // src/fetch/js/config/index.ts
2
+ import { replaceMainext } from "@genapi/parser";
3
+ import { config as _config } from "@genapi/pipeline";
4
+ function config(userConfig) {
5
+ userConfig.import = userConfig.import || {};
6
+ userConfig.output = userConfig.output || {};
7
+ userConfig.output = replaceMainext(userConfig.output) || "src/api/index.js";
8
+ const configRead = _config(userConfig);
9
+ return configRead;
10
+ }
11
+ export {
12
+ config
13
+ };
@@ -0,0 +1,6 @@
1
+ import '@genapi/shared';
2
+ export { compiler, dest, generate, original } from '@genapi/pipeline';
3
+ export { config } from './config/index.js';
4
+ export { parser } from './parser/index.js';
5
+ export { o as default } from '../../index-pIxMzJ5o.js';
6
+ import 'openapi-specification-types';
@@ -0,0 +1,25 @@
1
+ // src/fetch/js/index.ts
2
+ import pipeline, { compiler, dest, generate, original } from "@genapi/pipeline";
3
+ import { config } from "./config/index.mjs";
4
+ import { parser } from "./parser/index.mjs";
5
+ function openapiPipeline(userConfig) {
6
+ const process = pipeline(
7
+ (userConfig2) => config(userConfig2),
8
+ (configRead) => original(configRead),
9
+ (configRead) => parser(configRead),
10
+ (configRead) => compiler(configRead),
11
+ (configRead) => generate(configRead),
12
+ (configRead) => dest(configRead)
13
+ );
14
+ return process(userConfig);
15
+ }
16
+ var js_default = openapiPipeline;
17
+ export {
18
+ compiler,
19
+ config,
20
+ js_default as default,
21
+ dest,
22
+ generate,
23
+ original,
24
+ parser
25
+ };
@@ -0,0 +1,12 @@
1
+ import { ApiPipeline, StatementInterface, StatementFunction } from '@genapi/shared';
2
+ import { Paths } from 'openapi-specification-types';
3
+
4
+ interface PathsTransformOptions {
5
+ configRead: ApiPipeline.ConfigRead;
6
+ interfaces: StatementInterface[];
7
+ functions: StatementFunction[];
8
+ }
9
+ declare function parser(configRead: ApiPipeline.ConfigRead): ApiPipeline.ConfigRead<ApiPipeline.Config>;
10
+ declare function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions): void;
11
+
12
+ export { type PathsTransformOptions, parser, transformPaths };
@@ -0,0 +1,83 @@
1
+ // src/fetch/js/parser/index.ts
2
+ import {
3
+ literalFieldsToString,
4
+ parseHeaderCommits,
5
+ parseMethodMetadata,
6
+ parseMethodParameters,
7
+ parseOpenapiSpecification,
8
+ transformBaseURL,
9
+ transformBodyStringify,
10
+ transformDefinitions,
11
+ transformHeaderOptions,
12
+ transformParameters,
13
+ transformQueryParams,
14
+ transformUrlSyntax,
15
+ traversePaths
16
+ } from "@genapi/parser";
17
+ function parser(configRead) {
18
+ const source = parseOpenapiSpecification(configRead.source);
19
+ const comments = parseHeaderCommits(source);
20
+ const interfaces = [];
21
+ const functions = [];
22
+ transformBaseURL(source, {
23
+ configRead
24
+ });
25
+ transformDefinitions(source.definitions, {
26
+ interfaces
27
+ });
28
+ transformPaths(source.paths, {
29
+ configRead,
30
+ functions,
31
+ interfaces
32
+ });
33
+ configRead.graphs.comments = comments;
34
+ configRead.graphs.functions = functions;
35
+ configRead.graphs.interfaces = interfaces;
36
+ return configRead;
37
+ }
38
+ function transformPaths(paths, { configRead, functions, interfaces }) {
39
+ traversePaths(paths, (config) => {
40
+ const { parameters, interfaces: attachInters, options } = parseMethodParameters(config, {
41
+ formData: "body"
42
+ });
43
+ let { name, description, url, responseType, body } = parseMethodMetadata(config);
44
+ interfaces.push(...attachInters);
45
+ parameters.push({
46
+ name: "config",
47
+ type: "RequestInit",
48
+ required: false
49
+ });
50
+ if (config.method.toLowerCase() !== "get")
51
+ options.unshift(["method", `"${config.method}"`]);
52
+ transformHeaderOptions("body", { options, parameters });
53
+ options.push(["...", "config"]);
54
+ transformParameters(parameters, {
55
+ syntax: "ecmascript",
56
+ configRead,
57
+ description,
58
+ interfaces,
59
+ responseType
60
+ });
61
+ transformBodyStringify("body", { options, parameters });
62
+ url = transformQueryParams("query", { body, options, url });
63
+ url = transformUrlSyntax(url, { baseURL: configRead.config.baseURL });
64
+ functions.push({
65
+ export: true,
66
+ async: true,
67
+ name,
68
+ description,
69
+ parameters,
70
+ body: [
71
+ ...body,
72
+ `const response = await fetch(${url}, {
73
+ ${literalFieldsToString(options)}
74
+ })`,
75
+ "return response.json()"
76
+ ]
77
+ });
78
+ });
79
+ }
80
+ export {
81
+ parser,
82
+ transformPaths
83
+ };
@@ -0,0 +1,5 @@
1
+ import { ApiPipeline } from '@genapi/shared';
2
+
3
+ declare function config(userConfig: ApiPipeline.Config): ApiPipeline.ConfigRead;
4
+
5
+ export { config };
@@ -0,0 +1,11 @@
1
+ // src/fetch/ts/config/index.ts
2
+ import { config as _config } from "@genapi/pipeline";
3
+ function config(userConfig) {
4
+ userConfig.import = userConfig.import || {};
5
+ userConfig.import.http = userConfig.import.http || "axios";
6
+ const configRead = _config(userConfig);
7
+ return configRead;
8
+ }
9
+ export {
10
+ config
11
+ };
@@ -0,0 +1,6 @@
1
+ import '@genapi/shared';
2
+ export { compiler, dest, generate, original } from '@genapi/pipeline';
3
+ export { config } from './config/index.js';
4
+ export { parser } from './parser/index.js';
5
+ export { o as default } from '../../index-vrb8mA6n.js';
6
+ import 'openapi-specification-types';
@@ -0,0 +1,25 @@
1
+ // src/fetch/ts/index.ts
2
+ import pipeline, { compiler, dest, generate, original } from "@genapi/pipeline";
3
+ import { config } from "./config/index.mjs";
4
+ import { parser } from "./parser/index.mjs";
5
+ function openapiPipeline(userConfig) {
6
+ const process = pipeline(
7
+ (userConfig2) => config(userConfig2),
8
+ (configRead) => original(configRead),
9
+ (configRead) => parser(configRead),
10
+ (configRead) => compiler(configRead),
11
+ (configRead) => generate(configRead),
12
+ (configRead) => dest(configRead)
13
+ );
14
+ return process(userConfig);
15
+ }
16
+ var ts_default = openapiPipeline;
17
+ export {
18
+ compiler,
19
+ config,
20
+ ts_default as default,
21
+ dest,
22
+ generate,
23
+ original,
24
+ parser
25
+ };
@@ -0,0 +1,12 @@
1
+ import { ApiPipeline, StatementInterface, StatementFunction } from '@genapi/shared';
2
+ import { Paths } from 'openapi-specification-types';
3
+
4
+ interface PathsTransformOptions {
5
+ configRead: ApiPipeline.ConfigRead;
6
+ interfaces: StatementInterface[];
7
+ functions: StatementFunction[];
8
+ }
9
+ declare function parser(configRead: ApiPipeline.ConfigRead): ApiPipeline.ConfigRead<ApiPipeline.Config>;
10
+ declare function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions): void;
11
+
12
+ export { type PathsTransformOptions, parser, transformPaths };
@@ -0,0 +1,79 @@
1
+ // src/fetch/ts/parser/index.ts
2
+ import {
3
+ parseHeaderCommits,
4
+ parseMethodMetadata,
5
+ parseMethodParameters,
6
+ parseOpenapiSpecification,
7
+ transformBaseURL,
8
+ transformBodyStringify,
9
+ transformDefinitions,
10
+ transformFetchBody,
11
+ transformHeaderOptions,
12
+ transformParameters,
13
+ transformQueryParams,
14
+ transformUrlSyntax,
15
+ traversePaths
16
+ } from "@genapi/parser";
17
+ function parser(configRead) {
18
+ const source = parseOpenapiSpecification(configRead.source);
19
+ const comments = parseHeaderCommits(source);
20
+ const interfaces = [];
21
+ const functions = [];
22
+ transformBaseURL(source, {
23
+ configRead
24
+ });
25
+ transformDefinitions(source.definitions, {
26
+ interfaces
27
+ });
28
+ transformPaths(source.paths, {
29
+ configRead,
30
+ functions,
31
+ interfaces
32
+ });
33
+ configRead.graphs.comments = comments;
34
+ configRead.graphs.functions = functions;
35
+ configRead.graphs.interfaces = interfaces;
36
+ return configRead;
37
+ }
38
+ function transformPaths(paths, { configRead, functions, interfaces }) {
39
+ traversePaths(paths, (config) => {
40
+ const { parameters, interfaces: attachInters, options } = parseMethodParameters(config);
41
+ let { name, description, url, responseType, body } = parseMethodMetadata(config);
42
+ interfaces.push(...attachInters);
43
+ parameters.push({
44
+ name: "config",
45
+ type: "RequestInit",
46
+ required: false
47
+ });
48
+ if (config.method.toLowerCase() !== "get")
49
+ options.unshift(["method", `"${config.method}"`]);
50
+ transformHeaderOptions("body", { options, parameters });
51
+ options.push(["...", "config"]);
52
+ const { spaceResponseType } = transformParameters(parameters, {
53
+ syntax: "typescript",
54
+ configRead,
55
+ description,
56
+ interfaces,
57
+ responseType
58
+ });
59
+ transformBodyStringify("body", { options, parameters });
60
+ url = transformQueryParams("query", { body, options, url });
61
+ url = transformUrlSyntax(url, { baseURL: configRead.config.baseURL });
62
+ const fetch = transformFetchBody(url, options, spaceResponseType);
63
+ functions.push({
64
+ export: true,
65
+ async: true,
66
+ name,
67
+ description,
68
+ parameters,
69
+ body: [
70
+ ...body,
71
+ ...fetch
72
+ ]
73
+ });
74
+ });
75
+ }
76
+ export {
77
+ parser,
78
+ transformPaths
79
+ };