@keq-request/cli 5.0.0-alpha.29 → 5.0.0-alpha.31
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/CHANGELOG.md +21 -0
- package/dist/chunk-7HHTHYRA.cjs +2895 -0
- package/dist/chunk-7HHTHYRA.cjs.map +1 -0
- package/dist/chunk-DZ2SC5HL.js +2895 -0
- package/dist/chunk-DZ2SC5HL.js.map +1 -0
- package/dist/chunk-HN7ZZFKC.js +19 -0
- package/dist/chunk-HN7ZZFKC.js.map +1 -0
- package/dist/chunk-JX74ZR2O.cjs +670 -0
- package/dist/chunk-JX74ZR2O.cjs.map +1 -0
- package/dist/chunk-OC36G3PF.cjs +19 -0
- package/dist/chunk-OC36G3PF.cjs.map +1 -0
- package/dist/chunk-XRZLO2PB.js +670 -0
- package/dist/chunk-XRZLO2PB.js.map +1 -0
- package/dist/cli.cjs +171 -2757
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +161 -2724
- package/dist/cli.js.map +1 -1
- package/dist/compiler/compiler.d.ts +2 -0
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/index.cjs +8 -2777
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -2738
- package/dist/index.js.map +1 -1
- package/dist/plugins/body-fallback/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/body-fallback/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/body-fallback/index.d.ts.map +1 -1
- package/dist/plugins/chinese-to-pinyin/chinese-to-pinyin.plugin.d.ts.map +1 -1
- package/dist/plugins/chinese-to-pinyin/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/chinese-to-pinyin/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/download-http-file/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/download-http-file/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/download-http-file/download-http-file.plugin.d.ts.map +1 -1
- package/dist/plugins/download-local-file/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/download-local-file/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/download-local-file/download-local-file.plugin.d.ts.map +1 -1
- package/dist/plugins/eslint/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/eslint/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/eslint/eslint.plugin.d.ts.map +1 -1
- package/dist/plugins/generate-declaration/constants/metadata-storage.d.ts +2 -1
- package/dist/plugins/generate-declaration/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/generate-declaration/generate-declaration.plugin.d.ts.map +1 -1
- package/dist/plugins/generate-micro-function/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/generate-micro-function/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/generate-micro-function/generate-micro-function.plugin.d.ts.map +1 -1
- package/dist/plugins/generate-nestjs-module/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/generate-nestjs-module/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/generate-nestjs-module/generate-nestjs-module.d.ts.map +1 -1
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/prettier/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/prettier/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/prettier/prettier.plugin.d.ts.map +1 -1
- package/dist/plugins/shaking/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/shaking/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/shaking/shaking.plugin.d.ts.map +1 -1
- package/dist/plugins/terminal-select/constants/metadata-storage.d.ts +1 -0
- package/dist/plugins/terminal-select/constants/metadata-storage.d.ts.map +1 -1
- package/dist/plugins/terminal-select/terminal-select.plugin.d.ts.map +1 -1
- package/dist/plugins/use-valibot/constants/index.d.ts +2 -0
- package/dist/plugins/use-valibot/constants/index.d.ts.map +1 -0
- package/dist/plugins/use-valibot/constants/metadata-storage.d.ts +6 -0
- package/dist/plugins/use-valibot/constants/metadata-storage.d.ts.map +1 -0
- package/dist/plugins/use-valibot/index.d.ts +3 -0
- package/dist/plugins/use-valibot/index.d.ts.map +1 -0
- package/dist/plugins/use-valibot/use-valibot.plugin.d.ts +12 -0
- package/dist/plugins/use-valibot/use-valibot.plugin.d.ts.map +1 -0
- package/dist/plugins.cjs +3 -2532
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.js +31 -2500
- package/dist/plugins.js.map +1 -1
- package/dist/transformers/json-schema/json-schema.transformer.d.ts +2 -0
- package/dist/transformers/json-schema/json-schema.transformer.d.ts.map +1 -1
- package/dist/transformers/json-schema/valibot.renderer.d.ts +26 -0
- package/dist/transformers/json-schema/valibot.renderer.d.ts.map +1 -0
- package/dist/transformers/schema-definition/schema-definition.transformer.d.ts +5 -0
- package/dist/transformers/schema-definition/schema-definition.transformer.d.ts.map +1 -1
- package/dist/translators.cjs +8 -2047
- package/dist/translators.cjs.map +1 -1
- package/dist/translators.js +7 -2008
- package/dist/translators.js.map +1 -1
- package/dist/utils/scan-generated-files.d.ts +15 -0
- package/dist/utils/scan-generated-files.d.ts.map +1 -0
- package/package.json +3 -3
package/dist/cli.cjs
CHANGED
|
@@ -1,2780 +1,87 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
-
mod
|
|
24
|
-
));
|
|
25
|
-
|
|
26
|
-
// src/cli.ts
|
|
27
|
-
var import_semver = __toESM(require("semver"), 1);
|
|
28
|
-
var import_commander = require("commander");
|
|
29
|
-
|
|
30
|
-
// src/constants/supported-methods.ts
|
|
31
|
-
var SupportedMethods = [
|
|
32
|
-
"get",
|
|
33
|
-
"post",
|
|
34
|
-
"put",
|
|
35
|
-
"delete",
|
|
36
|
-
"patch",
|
|
37
|
-
"head",
|
|
38
|
-
"options"
|
|
39
|
-
];
|
|
40
|
-
|
|
41
|
-
// src/utils/logger.ts
|
|
42
|
-
var import_chalk = __toESM(require("chalk"), 1);
|
|
43
|
-
var logger = {
|
|
44
|
-
log: (str) => console.log(import_chalk.default.green(str)),
|
|
45
|
-
warn: (str) => console.warn(import_chalk.default.yellow(str)),
|
|
46
|
-
error: (str) => console.error(import_chalk.default.red(str))
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// src/compiler/compiler.ts
|
|
50
|
-
var import_listr22 = require("listr2");
|
|
51
|
-
var import_tapable4 = require("tapable");
|
|
52
|
-
|
|
53
|
-
// src/compiler/tasks/setup/index.ts
|
|
54
|
-
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
55
|
-
var import_path = __toESM(require("path"), 1);
|
|
56
|
-
var import_cosmiconfig = require("cosmiconfig");
|
|
57
|
-
|
|
58
|
-
// src/utils/ignore-matcher.ts
|
|
59
|
-
var R = __toESM(require("ramda"), 1);
|
|
60
|
-
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
61
|
-
var IgnoreMatcher = class _IgnoreMatcher {
|
|
62
|
-
rules;
|
|
63
|
-
constructor(rules) {
|
|
64
|
-
this.rules = rules;
|
|
65
|
-
}
|
|
66
|
-
static async read(filepath) {
|
|
67
|
-
let content = await import_fs_extra.default.readFile(filepath, "utf-8");
|
|
68
|
-
content = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/#.*$/gm, "").replace(/\n+/g, "\n").trim();
|
|
69
|
-
let rules = content.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).map((line) => {
|
|
70
|
-
const matched = line.match(/^(!)?\s*([^\s/]+)\s+([^\s/]+)\s+([^\s]+)$/);
|
|
71
|
-
if (!matched) throw new Error(`Invalid ignore rule: "${line}"`);
|
|
72
|
-
const [, flag, moduleName, operationMethod, operationPathname] = matched;
|
|
73
|
-
return {
|
|
74
|
-
persist: true,
|
|
75
|
-
ignore: !flag,
|
|
76
|
-
moduleName,
|
|
77
|
-
operationMethod: operationMethod.toLowerCase(),
|
|
78
|
-
operationPathname
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
rules = R.sortBy(
|
|
82
|
-
R.prop("ignore"),
|
|
83
|
-
rules
|
|
84
|
-
);
|
|
85
|
-
rules = R.uniqWith(
|
|
86
|
-
(a, b) => a.moduleName === b.moduleName && a.operationMethod === b.operationMethod && a.operationPathname === b.operationPathname,
|
|
87
|
-
rules
|
|
88
|
-
);
|
|
89
|
-
return new _IgnoreMatcher(rules);
|
|
90
|
-
}
|
|
91
|
-
async write(filepath) {
|
|
92
|
-
const ruleGroups = R.compose(
|
|
93
|
-
R.groupBy((rule) => rule.moduleName),
|
|
94
|
-
R.reverse,
|
|
95
|
-
R.uniqWith(
|
|
96
|
-
(a, b) => a.moduleName === b.moduleName && a.operationMethod === b.operationMethod && a.operationPathname === b.operationPathname
|
|
97
|
-
),
|
|
98
|
-
R.filter((rule) => rule.persist)
|
|
99
|
-
)(this.rules);
|
|
100
|
-
const content = Object.entries(ruleGroups).sort((a, b) => {
|
|
101
|
-
const aModuleName = a[0];
|
|
102
|
-
const bModuleName = b[0];
|
|
103
|
-
if (aModuleName === "*") return -1;
|
|
104
|
-
if (bModuleName === "*") return 1;
|
|
105
|
-
return aModuleName.localeCompare(bModuleName);
|
|
106
|
-
}).map(([, rules]) => (rules || []).sort((a, b) => {
|
|
107
|
-
if (a.ignore !== b.ignore) return a.ignore ? -1 : 1;
|
|
108
|
-
if (a.operationMethod === "*") return -1;
|
|
109
|
-
if (b.operationMethod === "*") return 1;
|
|
110
|
-
if (a.operationPathname === "*") return -1;
|
|
111
|
-
if (b.operationPathname === "*") return 1;
|
|
112
|
-
if (a.operationMethod !== b.operationMethod) return a.operationMethod.localeCompare(b.operationMethod);
|
|
113
|
-
if (a.operationPathname !== b.operationPathname) return a.operationPathname.localeCompare(b.operationPathname);
|
|
114
|
-
return 0;
|
|
115
|
-
}).map((rule) => `${rule.ignore ? "" : "! "}${rule.moduleName} ${rule.operationMethod.toUpperCase()} ${rule.operationPathname}`).join("\n")).join("\n\n");
|
|
116
|
-
await import_fs_extra.default.writeFile(filepath, content, "utf-8");
|
|
117
|
-
}
|
|
118
|
-
append(rule) {
|
|
119
|
-
this.rules.unshift(rule);
|
|
120
|
-
}
|
|
121
|
-
// if operation is ignored, return true
|
|
122
|
-
isOperationIgnored(operationDefinition) {
|
|
123
|
-
const moduleName = operationDefinition.module.name;
|
|
124
|
-
const operationMethod = operationDefinition.method.toLowerCase();
|
|
125
|
-
const operationPathname = operationDefinition.pathname;
|
|
126
|
-
for (const rule of this.rules) {
|
|
127
|
-
if (rule.moduleName !== "*" && rule.moduleName !== moduleName) continue;
|
|
128
|
-
if (rule.operationMethod !== "*" && rule.operationMethod !== operationMethod) continue;
|
|
129
|
-
if (rule.operationPathname !== "*" && rule.operationPathname !== operationPathname) continue;
|
|
130
|
-
return rule.ignore;
|
|
131
|
-
}
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
isModuleIgnored(moduleDefinition) {
|
|
135
|
-
const moduleName = moduleDefinition.name;
|
|
136
|
-
for (const rule of this.rules) {
|
|
137
|
-
if (!rule.ignore) {
|
|
138
|
-
if (rule.moduleName === "*" || rule.moduleName === moduleName) return false;
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
if (rule.operationMethod !== "*") continue;
|
|
142
|
-
if (rule.operationPathname !== "*") continue;
|
|
143
|
-
if (rule.moduleName === "*" || rule.moduleName === moduleName) return true;
|
|
144
|
-
}
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
// src/compiler/tasks/setup/utils/find-nearest-package-json.ts
|
|
150
|
-
var import_node_fs = __toESM(require("fs"), 1);
|
|
151
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
152
|
-
function findNearestPackageJson(startDir = process.cwd()) {
|
|
153
|
-
let dir = startDir;
|
|
154
|
-
while (true) {
|
|
155
|
-
const pkgPath = import_node_path.default.join(dir, "package.json");
|
|
156
|
-
if (import_node_fs.default.existsSync(pkgPath)) {
|
|
157
|
-
const json = JSON.parse(import_node_fs.default.readFileSync(pkgPath, "utf8"));
|
|
158
|
-
return { json, path: pkgPath };
|
|
159
|
-
}
|
|
160
|
-
const parent = import_node_path.default.dirname(dir);
|
|
161
|
-
if (parent === dir) break;
|
|
162
|
-
dir = parent;
|
|
163
|
-
}
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
2
|
+
"use strict"; function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
166
3
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (!pkgInfo?.json) return "cjs";
|
|
170
|
-
const { json } = pkgInfo;
|
|
171
|
-
if (json.type === "module") return "esm";
|
|
172
|
-
return "cjs";
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// src/compiler/tasks/setup/utils/parse-runtime-config.ts
|
|
176
|
-
var import_value = require("@sinclair/typebox/value");
|
|
177
|
-
|
|
178
|
-
// src/types/address.ts
|
|
179
|
-
var import_typebox = require("@sinclair/typebox");
|
|
180
|
-
var Address = import_typebox.Type.Object({
|
|
181
|
-
url: import_typebox.Type.String(),
|
|
182
|
-
headers: import_typebox.Type.Optional(import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.String(), { default: {} })),
|
|
183
|
-
encoding: import_typebox.Type.Optional(
|
|
184
|
-
import_typebox.Type.Union([
|
|
185
|
-
import_typebox.Type.Literal("utf8"),
|
|
186
|
-
import_typebox.Type.Literal("ascii")
|
|
187
|
-
], { default: "utf8" })
|
|
188
|
-
)
|
|
189
|
-
});
|
|
4
|
+
var _chunkJX74ZR2Ocjs = require('./chunk-JX74ZR2O.cjs');
|
|
5
|
+
require('./chunk-OC36G3PF.cjs');
|
|
190
6
|
|
|
191
|
-
// src/types/runtime-config.ts
|
|
192
|
-
var R2 = __toESM(require("ramda"), 1);
|
|
193
|
-
var import_typebox2 = require("@sinclair/typebox");
|
|
194
7
|
|
|
195
|
-
// src/constants/file-naming-style.ts
|
|
196
|
-
var FileNamingStyle = /* @__PURE__ */ ((FileNamingStyle2) => {
|
|
197
|
-
FileNamingStyle2["camelCase"] = "camelCase";
|
|
198
|
-
FileNamingStyle2["capitalCase"] = "capitalCase";
|
|
199
|
-
FileNamingStyle2["constantCase"] = "constantCase";
|
|
200
|
-
FileNamingStyle2["dotCase"] = "dotCase";
|
|
201
|
-
FileNamingStyle2["headerCase"] = "headerCase";
|
|
202
|
-
FileNamingStyle2["noCase"] = "noCase";
|
|
203
|
-
FileNamingStyle2["paramCase"] = "paramCase";
|
|
204
|
-
FileNamingStyle2["pascalCase"] = "pascalCase";
|
|
205
|
-
FileNamingStyle2["pathCase"] = "pathCase";
|
|
206
|
-
FileNamingStyle2["sentenceCase"] = "sentenceCase";
|
|
207
|
-
FileNamingStyle2["snakeCase"] = "snakeCase";
|
|
208
|
-
return FileNamingStyle2;
|
|
209
|
-
})(FileNamingStyle || {});
|
|
210
8
|
|
|
211
|
-
|
|
212
|
-
var URL_REGEX = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/(?:[^\s@]+@)?[^\s/:?#]*(?::\d+)?(?:\/[^\s?#]*)?(?:\?[^\s#]*)?(?:#[^\s]*)?$/;
|
|
213
|
-
function isValidURL(url) {
|
|
214
|
-
return URL_REGEX.test(url);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// src/types/runtime-config.ts
|
|
218
|
-
var Modules = import_typebox2.Type.Transform(
|
|
219
|
-
import_typebox2.Type.Record(
|
|
220
|
-
import_typebox2.Type.String(),
|
|
221
|
-
import_typebox2.Type.Union([import_typebox2.Type.String(), Address])
|
|
222
|
-
)
|
|
223
|
-
).Decode((value) => {
|
|
224
|
-
const keys2 = Object.keys(value);
|
|
225
|
-
for (const key of keys2) {
|
|
226
|
-
if (!/^[A-Za-z_][A-Za-z0-9_$]*$/.test(key)) {
|
|
227
|
-
throw new Error(`Module name "${key}" is not valid. It must start with a letter or underscore, and can only contain letters, numbers, and underscores.`);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
const keysGroupByLowerCase = R2.groupBy(R2.toLower, keys2);
|
|
231
|
-
for (const groupKey in keysGroupByLowerCase) {
|
|
232
|
-
const keys3 = keysGroupByLowerCase[groupKey] || [];
|
|
233
|
-
if (keys3.length > 1) {
|
|
234
|
-
throw new Error(`Module names ${keys3.map((name) => `"${name}"`).join(", ")} are case-insensitively duplicated.`);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
for (const key in value) {
|
|
238
|
-
const url = typeof value[key] === "string" ? value[key] : value[key].url;
|
|
239
|
-
if (isValidURL(url)) continue;
|
|
240
|
-
throw new Error(`The ${JSON.stringify(url)} of module "${key}" is not a valid URL.`);
|
|
241
|
-
}
|
|
242
|
-
return R2.map(
|
|
243
|
-
(item) => typeof item !== "string" ? item : { url: item, headers: {}, encoding: "utf8" },
|
|
244
|
-
value
|
|
245
|
-
);
|
|
246
|
-
}).Encode((value) => value);
|
|
247
|
-
var RawConfig = import_typebox2.Type.Object({
|
|
248
|
-
/**
|
|
249
|
-
* Whether to generate ES Module code
|
|
250
|
-
*
|
|
251
|
-
* If not specified, the module system will be inferred from the nearest package.json "type" field
|
|
252
|
-
* or defaults to "cjs" if no package.json is found.
|
|
253
|
-
*/
|
|
254
|
-
esm: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
|
|
255
|
-
/**
|
|
256
|
-
* Output directory for generated files
|
|
257
|
-
*/
|
|
258
|
-
outdir: import_typebox2.Type.String({ default: `${process.cwd()}/api` }),
|
|
259
|
-
/**
|
|
260
|
-
* File naming style for generated files
|
|
261
|
-
*/
|
|
262
|
-
fileNamingStyle: import_typebox2.Type.Enum(FileNamingStyle, { default: "snakeCase" /* snakeCase */ }),
|
|
263
|
-
/**
|
|
264
|
-
* OpenAPI/Swagger document sources
|
|
265
|
-
*
|
|
266
|
-
* A map of module names to their document URLs or Address objects.
|
|
267
|
-
* The module name must be a valid JavaScript identifier.
|
|
268
|
-
*/
|
|
269
|
-
modules: Modules,
|
|
270
|
-
/**
|
|
271
|
-
* Enable debug mode to output detailed logs during compilation
|
|
272
|
-
*/
|
|
273
|
-
debug: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
|
|
274
|
-
/**
|
|
275
|
-
* Whether to tolerate wrong openapi/swagger structure
|
|
276
|
-
*/
|
|
277
|
-
tolerant: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
|
|
278
|
-
/**
|
|
279
|
-
* Translators to transform generated code
|
|
280
|
-
*
|
|
281
|
-
* Used to customize the code generation process for different frameworks or patterns.
|
|
282
|
-
* Can be a single translator or an array of translators.
|
|
283
|
-
*/
|
|
284
|
-
translators: import_typebox2.Type.Optional(
|
|
285
|
-
import_typebox2.Type.Transform(
|
|
286
|
-
import_typebox2.Type.Union([
|
|
287
|
-
import_typebox2.Type.Unsafe(import_typebox2.Type.Any()),
|
|
288
|
-
import_typebox2.Type.Array(import_typebox2.Type.Unsafe(import_typebox2.Type.Any()))
|
|
289
|
-
], { default: [] })
|
|
290
|
-
).Decode((value) => {
|
|
291
|
-
if (value === void 0) return [];
|
|
292
|
-
if (Array.isArray(value)) return value;
|
|
293
|
-
return [value];
|
|
294
|
-
}).Encode((value) => value)
|
|
295
|
-
),
|
|
296
|
-
/**
|
|
297
|
-
* Plugins to extend code generation functionality
|
|
298
|
-
*
|
|
299
|
-
* An array of plugin instances that can hook into various stages of the compilation process,
|
|
300
|
-
* such as code transformation, formatting, linting, or custom file generation.
|
|
301
|
-
*/
|
|
302
|
-
plugins: import_typebox2.Type.Optional(import_typebox2.Type.Array(import_typebox2.Type.Unsafe(import_typebox2.Type.Any()), { default: [] }))
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
// src/compiler/tasks/setup/utils/parse-runtime-config.ts
|
|
306
|
-
function parseRuntimeConfig(data) {
|
|
307
|
-
try {
|
|
308
|
-
const originalPlugins = typeof data === "object" && data !== null && "plugins" in data ? data.plugins : void 0;
|
|
309
|
-
const originTranslators = typeof data === "object" && data !== null && "translators" in data ? data.translators : void 0;
|
|
310
|
-
const parsed = import_value.Value.Parse(RawConfig, data);
|
|
311
|
-
if (originalPlugins !== void 0) {
|
|
312
|
-
parsed.plugins = originalPlugins;
|
|
313
|
-
}
|
|
314
|
-
if (originTranslators !== void 0) {
|
|
315
|
-
parsed.translators = originTranslators;
|
|
316
|
-
}
|
|
317
|
-
return parsed;
|
|
318
|
-
} catch (error) {
|
|
319
|
-
if (error instanceof Error) {
|
|
320
|
-
error.message = `Invalid Config: ${error.message}`;
|
|
321
|
-
}
|
|
322
|
-
throw error;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// src/plugins/eslint/eslint.plugin.ts
|
|
327
|
-
var import_eslint = require("eslint");
|
|
328
|
-
|
|
329
|
-
// src/plugins/prettier/prettier.plugin.ts
|
|
330
|
-
var import_child_process = require("child_process");
|
|
331
|
-
var import_util = require("util");
|
|
332
|
-
var execAsync = (0, import_util.promisify)(import_child_process.exec);
|
|
333
|
-
|
|
334
|
-
// src/plugins/body-fallback/index.ts
|
|
335
|
-
var R21 = __toESM(require("ramda"), 1);
|
|
336
|
-
|
|
337
|
-
// src/utils/json-schema-utils/is-array.ts
|
|
338
|
-
function isArray(schema) {
|
|
339
|
-
return schema.type === "array";
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// src/utils/json-schema-utils/is-mixed.ts
|
|
343
|
-
function isMixed(schema) {
|
|
344
|
-
return Array.isArray(schema.type);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// src/utils/json-schema-utils/is-non-array.ts
|
|
348
|
-
function isNonArray(schema) {
|
|
349
|
-
return typeof schema.type === "string" && schema.type !== "array";
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// src/utils/json-schema-utils/is-ref.ts
|
|
353
|
-
function isRef(schema) {
|
|
354
|
-
return "$ref" in schema;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// src/utils/json-schema-utils/index.ts
|
|
358
|
-
var JsonSchemaUtils = class {
|
|
359
|
-
static isRef = isRef;
|
|
360
|
-
static isArray = isArray;
|
|
361
|
-
static isNonArray = isNonArray;
|
|
362
|
-
static isMixed = isMixed;
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
// src/plugins/generate-micro-function/generate-micro-function.plugin.ts
|
|
366
|
-
var import_tapable2 = require("tapable");
|
|
367
|
-
|
|
368
|
-
// src/plugins/generate-micro-function/constants/metadata-storage.ts
|
|
369
|
-
var MetadataStorage3 = /* @__PURE__ */ new WeakMap();
|
|
370
|
-
|
|
371
|
-
// src/plugins/generate-micro-function/generators/micro_function/micro-function.generator.ts
|
|
372
|
-
var R20 = __toESM(require("ramda"), 1);
|
|
373
|
-
var path8 = __toESM(require("path"), 1);
|
|
374
|
-
var changeCase6 = __toESM(require("change-case"), 1);
|
|
375
|
-
|
|
376
|
-
// src/models/artifact.ts
|
|
377
|
-
var path2 = __toESM(require("path"), 1);
|
|
378
|
-
|
|
379
|
-
// src/models/anchor.ts
|
|
380
|
-
var AnchorBlock = class {
|
|
381
|
-
constructor(artifact) {
|
|
382
|
-
this.artifact = artifact;
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Append content to the end of the anchor block.
|
|
386
|
-
*/
|
|
387
|
-
append(anchorName, content) {
|
|
388
|
-
const lines = this.artifact.content.split("\n");
|
|
389
|
-
const anchor = `@anchor:${anchorName}:end`;
|
|
390
|
-
const anchorIndex = lines.findIndex((line) => line.includes(`/* ${anchor} */`));
|
|
391
|
-
if (anchorIndex === -1) {
|
|
392
|
-
throw new Error(`"${anchor}" not found in artifact "${this.artifact.filepath}".`);
|
|
393
|
-
}
|
|
394
|
-
lines.splice(anchorIndex, 0, content);
|
|
395
|
-
this.artifact.content = lines.join("\n");
|
|
396
|
-
}
|
|
397
|
-
prepend(anchorName, content) {
|
|
398
|
-
const lines = this.artifact.content.split("\n");
|
|
399
|
-
const anchor = `@anchor:${anchorName}:start`;
|
|
400
|
-
const anchorIndex = lines.findIndex((line) => line.includes(`/* ${anchor} */`));
|
|
401
|
-
if (anchorIndex === -1) {
|
|
402
|
-
throw new Error(`"${anchor}" not found in artifact "${this.artifact.filepath}".`);
|
|
403
|
-
}
|
|
404
|
-
lines.splice(anchorIndex + 1, 0, content);
|
|
405
|
-
this.artifact.content = lines.join("\n");
|
|
406
|
-
}
|
|
407
|
-
replace(anchorName, content) {
|
|
408
|
-
const lines = this.artifact.content.split("\n");
|
|
409
|
-
const startIndex = lines.findIndex((line) => line.includes(`/* @anchor:${anchorName}:start */`));
|
|
410
|
-
const endIndex = lines.findIndex((line) => line.includes(`/* @anchor:${anchorName}:end */`));
|
|
411
|
-
if (startIndex === -1 || endIndex === -1 || endIndex <= startIndex) {
|
|
412
|
-
throw new Error(`"@anchor:${anchorName}:start" or "@anchor:${anchorName}:end" not found in artifact "${this.artifact.filepath}".`);
|
|
413
|
-
}
|
|
414
|
-
lines.splice(startIndex + 1, endIndex - startIndex - 1, content);
|
|
415
|
-
this.artifact.content = lines.join("\n");
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
var Anchor = class {
|
|
419
|
-
constructor(artifact) {
|
|
420
|
-
this.artifact = artifact;
|
|
421
|
-
this.block = new AnchorBlock(artifact);
|
|
422
|
-
}
|
|
423
|
-
block;
|
|
424
|
-
append(anchorName, content) {
|
|
425
|
-
const lines = this.artifact.content.split("\n");
|
|
426
|
-
const anchor = `@anchor:${anchorName}`;
|
|
427
|
-
const anchorIndex = lines.findIndex((line) => line.includes(`/* ${anchor} */`));
|
|
428
|
-
if (anchorIndex === -1) {
|
|
429
|
-
throw new Error(`"${anchor}" not found in artifact "${this.artifact.filepath}".`);
|
|
430
|
-
}
|
|
431
|
-
lines.splice(anchorIndex + 1, 0, content);
|
|
432
|
-
this.artifact.content = lines.join("\n");
|
|
433
|
-
}
|
|
434
|
-
prepend(anchorName, content) {
|
|
435
|
-
const lines = this.artifact.content.split("\n");
|
|
436
|
-
const anchor = `@anchor:${anchorName}`;
|
|
437
|
-
const anchorIndex = lines.findIndex((line) => line.includes(`/* ${anchor} */`));
|
|
438
|
-
if (anchorIndex === -1) {
|
|
439
|
-
throw new Error(`"${anchor}" not found in artifact "${this.artifact.filepath}".`);
|
|
440
|
-
}
|
|
441
|
-
lines.splice(anchorIndex, 0, content);
|
|
442
|
-
this.artifact.content = lines.join("\n");
|
|
443
|
-
}
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
// src/models/artifact.ts
|
|
447
|
-
var HeaderComment = [
|
|
448
|
-
"// Code generated by keq-cli. DO NOT EDIT.",
|
|
449
|
-
"// Code generated by keq-cli. DO NOT EDIT.",
|
|
450
|
-
"// Code generated by keq-cli. DO NOT EDIT.",
|
|
451
|
-
"",
|
|
452
|
-
""
|
|
453
|
-
].join("\n");
|
|
454
|
-
var Artifact = class {
|
|
455
|
-
id;
|
|
456
|
-
filepath;
|
|
457
|
-
content;
|
|
458
|
-
extensionName;
|
|
459
|
-
anchor = new Anchor(this);
|
|
460
|
-
constructor(options) {
|
|
461
|
-
this.id = options.id;
|
|
462
|
-
this.filepath = options.filepath;
|
|
463
|
-
this.extensionName = options.extensionName || path2.extname(options.filepath);
|
|
464
|
-
this.content = options.content;
|
|
465
|
-
}
|
|
466
|
-
get dirname() {
|
|
467
|
-
return path2.dirname(this.filepath);
|
|
468
|
-
}
|
|
469
|
-
renderer() {
|
|
470
|
-
return `${HeaderComment}${this.content}`;
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
|
|
474
|
-
// src/models/api-document_v3_1.ts
|
|
475
|
-
var R5 = __toESM(require("ramda"), 1);
|
|
476
|
-
|
|
477
|
-
// src/models/module-definition.ts
|
|
478
|
-
var ModuleDefinition = class _ModuleDefinition {
|
|
479
|
-
name;
|
|
480
|
-
address;
|
|
481
|
-
constructor(name, address) {
|
|
482
|
-
this.name = name;
|
|
483
|
-
if (typeof address === "string") {
|
|
484
|
-
this.address = { url: address, headers: {}, encoding: "utf8" };
|
|
485
|
-
} else {
|
|
486
|
-
this.address = address;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
static unknown() {
|
|
490
|
-
return new _ModuleDefinition("", { url: "", headers: {}, encoding: "utf8" });
|
|
491
|
-
}
|
|
492
|
-
};
|
|
493
|
-
|
|
494
|
-
// src/models/operation-definition.ts
|
|
495
|
-
var R4 = __toESM(require("ramda"), 1);
|
|
496
|
-
|
|
497
|
-
// src/utils/is-keywords.ts
|
|
498
|
-
var keywords = [
|
|
499
|
-
"break",
|
|
500
|
-
"case",
|
|
501
|
-
"catch",
|
|
502
|
-
"continue",
|
|
503
|
-
"default",
|
|
504
|
-
"delete",
|
|
505
|
-
"do",
|
|
506
|
-
"else",
|
|
507
|
-
"finally",
|
|
508
|
-
"for",
|
|
509
|
-
"function",
|
|
510
|
-
"if",
|
|
511
|
-
"in",
|
|
512
|
-
"instanceof",
|
|
513
|
-
"new",
|
|
514
|
-
"return",
|
|
515
|
-
"switch",
|
|
516
|
-
"this",
|
|
517
|
-
"throw",
|
|
518
|
-
"try",
|
|
519
|
-
"typeof",
|
|
520
|
-
"var",
|
|
521
|
-
"void",
|
|
522
|
-
"while",
|
|
523
|
-
"with"
|
|
524
|
-
];
|
|
525
|
-
function isKeywords(str) {
|
|
526
|
-
return keywords.includes(str);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
// src/utils/is-reserved-word.ts
|
|
530
|
-
var reservedWords = [
|
|
531
|
-
"abstract",
|
|
532
|
-
"boolean",
|
|
533
|
-
"byte",
|
|
534
|
-
"char",
|
|
535
|
-
"class",
|
|
536
|
-
"const",
|
|
537
|
-
"debugger",
|
|
538
|
-
"double",
|
|
539
|
-
"enum",
|
|
540
|
-
"export",
|
|
541
|
-
"extends",
|
|
542
|
-
"final",
|
|
543
|
-
"float",
|
|
544
|
-
"goto",
|
|
545
|
-
"implements",
|
|
546
|
-
"import",
|
|
547
|
-
"int",
|
|
548
|
-
"interface",
|
|
549
|
-
"long",
|
|
550
|
-
"native",
|
|
551
|
-
"package",
|
|
552
|
-
"private",
|
|
553
|
-
"protected",
|
|
554
|
-
"public",
|
|
555
|
-
"short",
|
|
556
|
-
"static",
|
|
557
|
-
"super",
|
|
558
|
-
"synchronized",
|
|
559
|
-
"throws",
|
|
560
|
-
"transient",
|
|
561
|
-
"volatile"
|
|
562
|
-
];
|
|
563
|
-
function isReservedWord(str) {
|
|
564
|
-
return reservedWords.includes(str);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
// src/models/operation-definition.ts
|
|
568
|
-
var import_jsonpath_plus2 = require("jsonpath-plus");
|
|
569
|
-
|
|
570
|
-
// src/models/schema-definition.ts
|
|
571
|
-
var R3 = __toESM(require("ramda"), 1);
|
|
572
|
-
var import_jsonpath_plus = require("jsonpath-plus");
|
|
573
|
-
var SchemaDefinition = class _SchemaDefinition {
|
|
574
|
-
name;
|
|
575
|
-
schema;
|
|
576
|
-
module;
|
|
577
|
-
document;
|
|
578
|
-
get id() {
|
|
579
|
-
return `${this.module.address}#/components/schemas/${this.name}`;
|
|
580
|
-
}
|
|
581
|
-
constructor(args) {
|
|
582
|
-
this.module = args.module;
|
|
583
|
-
this.name = args.name;
|
|
584
|
-
this.schema = args.schema;
|
|
585
|
-
this.document = args.document;
|
|
586
|
-
}
|
|
587
|
-
getDependencies() {
|
|
588
|
-
const refs = R3.uniq((0, import_jsonpath_plus.JSONPath)({
|
|
589
|
-
path: "$..*['$ref']",
|
|
590
|
-
json: this.schema
|
|
591
|
-
}));
|
|
592
|
-
return refs.filter((ref) => typeof ref === "string" && !!ref.trim()).map((ref) => {
|
|
593
|
-
const definition = this.document.dereference(ref);
|
|
594
|
-
if (definition) return definition;
|
|
595
|
-
return _SchemaDefinition.unknown();
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
static unknown() {
|
|
599
|
-
return new _SchemaDefinition({
|
|
600
|
-
name: "",
|
|
601
|
-
schema: {},
|
|
602
|
-
module: ModuleDefinition.unknown(),
|
|
603
|
-
document: ApiDocumentV3_1.unknown()
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
|
-
static isUnknown(definition) {
|
|
607
|
-
return definition.name === "";
|
|
608
|
-
}
|
|
609
|
-
};
|
|
610
|
-
|
|
611
|
-
// src/models/operation-definition.ts
|
|
612
|
-
var OperationDefinition = class {
|
|
613
|
-
module;
|
|
614
|
-
operationId;
|
|
615
|
-
method;
|
|
616
|
-
pathname;
|
|
617
|
-
operation;
|
|
618
|
-
document;
|
|
619
|
-
get id() {
|
|
620
|
-
return `${this.module.address}#/paths/${this.pathname}/${this.method}`;
|
|
621
|
-
}
|
|
622
|
-
constructor(args) {
|
|
623
|
-
this.module = args.module;
|
|
624
|
-
this.method = args.method.toLowerCase();
|
|
625
|
-
this.pathname = args.pathname;
|
|
626
|
-
this.document = args.document;
|
|
627
|
-
this.operationId = this.formatOperationId(args.method, args.pathname, args.operation);
|
|
628
|
-
this.operation = {
|
|
629
|
-
...args.operation,
|
|
630
|
-
operationId: this.operationId
|
|
631
|
-
};
|
|
632
|
-
}
|
|
633
|
-
formatOperationId(method, pathname, operation) {
|
|
634
|
-
const operationId = operation.operationId;
|
|
635
|
-
if (operationId && operationId !== "index" && !isKeywords(operationId) && !isReservedWord(operationId)) {
|
|
636
|
-
return operationId;
|
|
637
|
-
}
|
|
638
|
-
return `${method}_${pathname}`.replace(/\//g, "_").replace(/-/g, "_").replace(/:/g, "$$").replace(/{(.+)}/, "$$$1");
|
|
639
|
-
}
|
|
640
|
-
getDependencies() {
|
|
641
|
-
const refs = R4.uniq([
|
|
642
|
-
...(0, import_jsonpath_plus2.JSONPath)({
|
|
643
|
-
path: "$.requestBody.content..schema..$ref",
|
|
644
|
-
json: this.operation
|
|
645
|
-
}),
|
|
646
|
-
...(0, import_jsonpath_plus2.JSONPath)({
|
|
647
|
-
path: "$.responses..content..schema..$ref",
|
|
648
|
-
json: this.operation
|
|
649
|
-
}),
|
|
650
|
-
...(0, import_jsonpath_plus2.JSONPath)({
|
|
651
|
-
path: "$.parameters..schema..$ref",
|
|
652
|
-
json: this.operation
|
|
653
|
-
})
|
|
654
|
-
]);
|
|
655
|
-
const dependencies = refs.filter((ref) => typeof ref === "string" && ref).map((ref) => {
|
|
656
|
-
const schemaDefinition = this.document.dereference(ref);
|
|
657
|
-
if (schemaDefinition) return schemaDefinition;
|
|
658
|
-
return SchemaDefinition.unknown();
|
|
659
|
-
});
|
|
660
|
-
return dependencies;
|
|
661
|
-
}
|
|
662
|
-
};
|
|
663
|
-
|
|
664
|
-
// src/models/api-document_v3_1.ts
|
|
665
|
-
var ApiDocumentV3_1 = class _ApiDocumentV3_1 {
|
|
666
|
-
module;
|
|
667
|
-
specification;
|
|
668
|
-
constructor(specification, module2) {
|
|
669
|
-
this.module = module2;
|
|
670
|
-
this.specification = specification;
|
|
671
|
-
}
|
|
672
|
-
get schemas() {
|
|
673
|
-
const module2 = this.module;
|
|
674
|
-
return Object.entries(this.specification.components?.schemas || {}).map(([name, schema]) => new SchemaDefinition({
|
|
675
|
-
name,
|
|
676
|
-
schema,
|
|
677
|
-
module: module2,
|
|
678
|
-
document: this
|
|
679
|
-
}));
|
|
680
|
-
}
|
|
681
|
-
get operations() {
|
|
682
|
-
const module2 = this.module;
|
|
683
|
-
return Object.entries(this.specification.paths || {}).flatMap(([pathname, pathItem]) => Object.entries(pathItem || {}).filter(([method]) => SupportedMethods.includes(method.toLowerCase())).map(([method, operation]) => new OperationDefinition({
|
|
684
|
-
method,
|
|
685
|
-
pathname,
|
|
686
|
-
operation,
|
|
687
|
-
module: module2,
|
|
688
|
-
document: this
|
|
689
|
-
})));
|
|
690
|
-
}
|
|
691
|
-
isEmpty() {
|
|
692
|
-
return R5.isEmpty(this.specification.paths);
|
|
693
|
-
}
|
|
694
|
-
dereference($ref) {
|
|
695
|
-
if ($ref.startsWith("#/")) {
|
|
696
|
-
return this.schemas.find((schema) => schema.id.endsWith($ref));
|
|
697
|
-
}
|
|
698
|
-
logger.warn(`The $ref(${$ref}) is not defined in ${this.module.name} openapi/swagger.`);
|
|
699
|
-
}
|
|
700
|
-
isRefDefined($ref) {
|
|
701
|
-
if ($ref.startsWith("#/")) {
|
|
702
|
-
const path12 = $ref.replace("#/", "").split("/");
|
|
703
|
-
return R5.path(path12, this.specification) !== void 0;
|
|
704
|
-
}
|
|
705
|
-
return false;
|
|
706
|
-
}
|
|
707
|
-
static unknown() {
|
|
708
|
-
return new _ApiDocumentV3_1({}, ModuleDefinition.unknown());
|
|
709
|
-
}
|
|
710
|
-
};
|
|
711
|
-
|
|
712
|
-
// src/models/asset.ts
|
|
713
|
-
var Asset = class {
|
|
714
|
-
path;
|
|
715
|
-
constructor(path12) {
|
|
716
|
-
this.path = path12;
|
|
717
|
-
}
|
|
718
|
-
};
|
|
719
|
-
|
|
720
|
-
// src/plugins/generate-declaration/generate-declaration.plugin.ts
|
|
721
|
-
var import_tapable = require("tapable");
|
|
722
|
-
|
|
723
|
-
// src/plugins/generate-declaration/generators/operation-declaration/operation.generator.ts
|
|
724
|
-
var path7 = __toESM(require("path"), 1);
|
|
725
|
-
var changeCase5 = __toESM(require("change-case"), 1);
|
|
726
|
-
|
|
727
|
-
// src/transformers/json-schema/comment.renderer.ts
|
|
728
|
-
var CommentRenderer = class {
|
|
729
|
-
constructor(schema) {
|
|
730
|
-
this.schema = schema;
|
|
731
|
-
}
|
|
732
|
-
render() {
|
|
733
|
-
const schema = this.schema;
|
|
734
|
-
const lines = ["/**"];
|
|
735
|
-
if (schema.description) {
|
|
736
|
-
const description = schema.description.replace("*/", "*\\/");
|
|
737
|
-
lines.push(...description.split("\n").map((line) => ` * ${line}`));
|
|
738
|
-
}
|
|
739
|
-
if (schema.deprecated) {
|
|
740
|
-
lines.push(" * @deprecated");
|
|
741
|
-
}
|
|
742
|
-
if (schema.readOnly) {
|
|
743
|
-
lines.push(" * @readonly");
|
|
744
|
-
}
|
|
745
|
-
if (schema.format) {
|
|
746
|
-
lines.push(` * @format ${schema.format}`);
|
|
747
|
-
}
|
|
748
|
-
lines.push(" */");
|
|
749
|
-
if (lines.length === 2) return "";
|
|
750
|
-
return lines.join("\n");
|
|
751
|
-
}
|
|
752
|
-
};
|
|
9
|
+
var _chunk7HHTHYRAcjs = require('./chunk-7HHTHYRA.cjs');
|
|
753
10
|
|
|
754
|
-
// src/
|
|
755
|
-
var
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
function indent(space, text) {
|
|
759
|
-
if (text === "") return "";
|
|
760
|
-
const indentation = " ".repeat(space);
|
|
761
|
-
return text.split("\n").map((line) => line ? `${indentation}${line}` : line).join("\n");
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
// src/transformers/json-schema/reference.transformer.ts
|
|
765
|
-
var R6 = __toESM(require("ramda"), 1);
|
|
766
|
-
var ReferenceTransformer = class {
|
|
767
|
-
static toDeclaration(schema, alias2 = R6.identity) {
|
|
768
|
-
if (!schema.$ref || !schema.$ref.startsWith("#")) return `unknown /* ${schema.$ref.replace("*/", "*\\/")} */`;
|
|
769
|
-
const parts = schema.$ref.split("/");
|
|
770
|
-
return alias2(parts[parts.length - 1]) || "unknown";
|
|
771
|
-
}
|
|
772
|
-
};
|
|
773
|
-
|
|
774
|
-
// src/transformers/json-schema/declaration.renderer.ts
|
|
775
|
-
var DeclarationRenderer = class {
|
|
776
|
-
constructor(schema, options = {}) {
|
|
777
|
-
this.schema = schema;
|
|
778
|
-
this.options = options;
|
|
779
|
-
}
|
|
780
|
-
render() {
|
|
781
|
-
return this.renderSchema(this.schema);
|
|
782
|
-
}
|
|
783
|
-
renderSchema(schema) {
|
|
784
|
-
if (typeof schema === "boolean") return "unknown";
|
|
785
|
-
if (JsonSchemaUtils.isRef(schema)) return this.renderReference(schema);
|
|
786
|
-
if (JsonSchemaUtils.isMixed(schema)) return this.renderMixed(schema);
|
|
787
|
-
if (JsonSchemaUtils.isArray(schema)) return this.renderArray(schema);
|
|
788
|
-
if (schema.type === "object") return this.renderObject(schema);
|
|
789
|
-
if (schema.enum) return this.renderEnum(schema);
|
|
790
|
-
if (schema.oneOf) return this.renderOneOf(schema);
|
|
791
|
-
if (schema.anyOf) return this.renderAnyOf(schema);
|
|
792
|
-
if (schema.allOf) return this.renderAllOf(schema);
|
|
793
|
-
if (schema.type === "string") return this.renderString(schema);
|
|
794
|
-
if (schema.type === "number") return this.renderNumber(schema);
|
|
795
|
-
if (schema.type === "boolean") return this.renderBoolean(schema);
|
|
796
|
-
if (schema.type === "null") return this.renderNull(schema);
|
|
797
|
-
if (schema.type === "integer") return this.renderInteger(schema);
|
|
798
|
-
return "unknown";
|
|
799
|
-
}
|
|
800
|
-
renderMixed(schema) {
|
|
801
|
-
if (Array.isArray(schema.type)) {
|
|
802
|
-
schema.type.map((type) => ({ ...schema, type })).map((schema2) => this.renderSchema(schema2)).join(" | ");
|
|
803
|
-
}
|
|
804
|
-
return "unknown";
|
|
805
|
-
}
|
|
806
|
-
renderReference(schema) {
|
|
807
|
-
if (!this.options.referenceTransformer) {
|
|
808
|
-
return ReferenceTransformer.toDeclaration(schema);
|
|
809
|
-
}
|
|
810
|
-
return this.options.referenceTransformer(schema);
|
|
811
|
-
}
|
|
812
|
-
renderArray(schema) {
|
|
813
|
-
if (schema.items && Array.isArray(schema.items)) {
|
|
814
|
-
const items = schema.items.map((s) => this.renderSchema(s)).join(", ");
|
|
815
|
-
return `[${items}]`;
|
|
816
|
-
}
|
|
817
|
-
if (schema.items && typeof schema.items === "object") {
|
|
818
|
-
return `${this.renderSchema(schema.items)}[]`;
|
|
819
|
-
}
|
|
820
|
-
return "any[]";
|
|
821
|
-
}
|
|
822
|
-
renderObject(schema) {
|
|
823
|
-
if ((!schema.properties || R7.isEmpty(schema.properties)) && (!schema.additionalProperties || R7.isEmpty(schema.additionalProperties))) {
|
|
824
|
-
return "object";
|
|
825
|
-
}
|
|
826
|
-
const $properties = Object.entries(schema.properties || {}).map(([propertyName, propertySchema]) => {
|
|
827
|
-
let $comment = new CommentRenderer(propertySchema).render();
|
|
828
|
-
if ($comment) $comment += "\n";
|
|
829
|
-
const $key = `"${propertyName}"${schema.required?.includes(propertyName) ? "" : "?"}`;
|
|
830
|
-
const $value = this.renderSchema(propertySchema);
|
|
831
|
-
return indent(2, `${$comment}${$key}: ${$value}`);
|
|
832
|
-
});
|
|
833
|
-
if (schema.additionalProperties) {
|
|
834
|
-
const $value = schema.additionalProperties === true ? "any" : this.renderSchema(schema.additionalProperties);
|
|
835
|
-
$properties.push(indent(2, `[key: string]: ${$value}`));
|
|
836
|
-
}
|
|
837
|
-
return [
|
|
838
|
-
"{",
|
|
839
|
-
...$properties,
|
|
840
|
-
"}"
|
|
841
|
-
].join("\n");
|
|
842
|
-
}
|
|
843
|
-
renderOneOf(schema) {
|
|
844
|
-
if (!schema.oneOf) return "unknown";
|
|
845
|
-
return schema.oneOf.map((s) => this.renderSchema(s)).join(" | ");
|
|
846
|
-
}
|
|
847
|
-
renderAnyOf(schema) {
|
|
848
|
-
if (!schema.anyOf) return "unknown";
|
|
849
|
-
return schema.anyOf.map((s) => this.renderSchema(s)).join(" | ");
|
|
850
|
-
}
|
|
851
|
-
renderAllOf(schema) {
|
|
852
|
-
if (!schema.allOf) return "unknown";
|
|
853
|
-
return schema.allOf.map((s) => this.renderSchema(s)).join(" & ");
|
|
854
|
-
}
|
|
855
|
-
renderEnum(schema) {
|
|
856
|
-
if (!schema.enum) return "unknown";
|
|
857
|
-
return schema.enum.map((v) => JSON.stringify(v)).join(" | ");
|
|
858
|
-
}
|
|
859
|
-
renderString(schema) {
|
|
860
|
-
if (schema.contentMediaType === "application/octet-stream") return "Blob | Buffer";
|
|
861
|
-
if (schema.format === "binary") return "Blob | Buffer";
|
|
862
|
-
return "string";
|
|
863
|
-
}
|
|
864
|
-
renderNumber(schema) {
|
|
865
|
-
return "number";
|
|
866
|
-
}
|
|
867
|
-
renderBoolean(schema) {
|
|
868
|
-
return "boolean";
|
|
869
|
-
}
|
|
870
|
-
renderNull(schema) {
|
|
871
|
-
return "null";
|
|
872
|
-
}
|
|
873
|
-
renderInteger(schema) {
|
|
874
|
-
return "number";
|
|
875
|
-
}
|
|
876
|
-
};
|
|
877
|
-
|
|
878
|
-
// src/transformers/json-schema/json-schema.transformer.ts
|
|
879
|
-
var JsonSchemaTransformer = class {
|
|
880
|
-
static toComment(schema) {
|
|
881
|
-
return new CommentRenderer(schema).render();
|
|
882
|
-
}
|
|
883
|
-
static toDeclaration(schema, options) {
|
|
884
|
-
return new DeclarationRenderer(schema, options).render();
|
|
885
|
-
}
|
|
886
|
-
};
|
|
887
|
-
|
|
888
|
-
// src/transformers/schema-definition/schema-definition.transformer.ts
|
|
889
|
-
var R8 = __toESM(require("ramda"), 1);
|
|
890
|
-
var SchemaDefinitionTransformer = class {
|
|
891
|
-
static toDeclaration(schemaDefinition, options) {
|
|
892
|
-
const dependencies = schemaDefinition.getDependencies();
|
|
893
|
-
let $dependencies = dependencies.filter((dep) => !SchemaDefinition.isUnknown(dep)).map((dep) => {
|
|
894
|
-
const filepath = options.getDependentSchemaDefinitionFilepath(dep);
|
|
895
|
-
return `import type { ${dep.name} } from "${filepath}"`;
|
|
896
|
-
}).map((str) => str.replace(/ from "(\.\.?\/.+?)(\.ts|\.mts|\.cts|\.js|\.cjs|\.mjs)?"/, options.esm ? ' from "$1.js"' : ' from "$1"')).join("\n");
|
|
897
|
-
if ($dependencies) $dependencies += "\n";
|
|
898
|
-
let $comment = JsonSchemaTransformer.toComment(schemaDefinition.schema);
|
|
899
|
-
if ($comment) $comment += "\n";
|
|
900
|
-
if (typeof schemaDefinition.schema === "boolean") {
|
|
901
|
-
return [
|
|
902
|
-
"/* @anchor:file:start */",
|
|
903
|
-
"",
|
|
904
|
-
$dependencies,
|
|
905
|
-
$comment || void 0,
|
|
906
|
-
`type ${schemaDefinition.name} = unknown`,
|
|
907
|
-
"",
|
|
908
|
-
"/* @anchor:file:end */"
|
|
909
|
-
].filter(R8.isNotNil).join("\n");
|
|
910
|
-
}
|
|
911
|
-
if (JsonSchemaUtils.isNonArray(schemaDefinition.schema) && schemaDefinition.schema.type === "object") {
|
|
912
|
-
const $schema = JsonSchemaTransformer.toDeclaration(schemaDefinition.schema);
|
|
913
|
-
const $declaration = $schema.startsWith("{") ? `export interface ${schemaDefinition.name} ${$schema}` : `export type ${schemaDefinition.name} = ${$schema}`;
|
|
914
|
-
return [
|
|
915
|
-
"/* @anchor:file:start */",
|
|
916
|
-
"",
|
|
917
|
-
$dependencies,
|
|
918
|
-
$comment || void 0,
|
|
919
|
-
$declaration,
|
|
920
|
-
"",
|
|
921
|
-
"/* @anchor:file:end */"
|
|
922
|
-
].filter(R8.isNotNil).join("\n");
|
|
923
|
-
}
|
|
924
|
-
return [
|
|
925
|
-
"/* @anchor:file:start */",
|
|
926
|
-
"",
|
|
927
|
-
$dependencies,
|
|
928
|
-
$comment || void 0,
|
|
929
|
-
`export type ${schemaDefinition.name} = ${JsonSchemaTransformer.toDeclaration(schemaDefinition.schema)}`,
|
|
930
|
-
"",
|
|
931
|
-
"/* @anchor:file:end */"
|
|
932
|
-
].filter(R8.isNotNil).join("\n");
|
|
933
|
-
}
|
|
934
|
-
};
|
|
935
|
-
|
|
936
|
-
// src/transformers/operation-definition/comment.renderer.ts
|
|
937
|
-
var R9 = __toESM(require("ramda"), 1);
|
|
938
|
-
var CommentRenderer2 = class {
|
|
939
|
-
constructor(operationDefinition) {
|
|
940
|
-
this.operationDefinition = operationDefinition;
|
|
941
|
-
}
|
|
942
|
-
render() {
|
|
943
|
-
const operation = this.operationDefinition.operation;
|
|
944
|
-
if (!operation.summary && !operation.description) return "";
|
|
945
|
-
const lines = ["/**"];
|
|
946
|
-
if (operation.summary && typeof operation.summary === "string") {
|
|
947
|
-
lines.push(` * ${R9.trim(operation.summary)}`);
|
|
948
|
-
lines.push(" *");
|
|
949
|
-
}
|
|
950
|
-
if (operation.description && typeof operation.description === "string") {
|
|
951
|
-
lines.push(` * @description ${R9.trim(operation.description)}`);
|
|
952
|
-
}
|
|
953
|
-
lines.push(" */");
|
|
954
|
-
return lines.join("\n");
|
|
955
|
-
}
|
|
956
|
-
};
|
|
957
|
-
|
|
958
|
-
// src/transformers/operation-definition/declaration.renderer.ts
|
|
959
|
-
var R14 = __toESM(require("ramda"), 1);
|
|
960
|
-
|
|
961
|
-
// src/transformers/operation-definition/utils/type-name-factory.ts
|
|
962
|
-
var changeCase = __toESM(require("change-case"), 1);
|
|
963
|
-
function typeNameFactory(operationDefinition) {
|
|
964
|
-
const pascalCaseOperationId = changeCase.pascalCase(operationDefinition.operationId);
|
|
965
|
-
return (name) => `${pascalCaseOperationId}${name}`;
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
// src/utils/openapi-utils/dereference.ts
|
|
969
|
-
function dereference($ref, swagger) {
|
|
970
|
-
let value;
|
|
971
|
-
for (const key of $ref.split("/")) {
|
|
972
|
-
if (key === "#") {
|
|
973
|
-
value = swagger;
|
|
974
|
-
} else {
|
|
975
|
-
value = value[key];
|
|
976
|
-
}
|
|
977
|
-
if (!value) break;
|
|
978
|
-
}
|
|
979
|
-
return value;
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
// src/utils/openapi-utils/dereference-operation.ts
|
|
983
|
-
var R12 = __toESM(require("ramda"), 1);
|
|
984
|
-
var import_jsonpointer2 = __toESM(require("jsonpointer"), 1);
|
|
985
|
-
var import_jsonpath_plus4 = require("jsonpath-plus");
|
|
986
|
-
|
|
987
|
-
// src/utils/openapi-utils/remove-undefined-ref.ts
|
|
988
|
-
var R11 = __toESM(require("ramda"), 1);
|
|
989
|
-
var import_jsonpointer = __toESM(require("jsonpointer"), 1);
|
|
990
|
-
var import_jsonpath_plus3 = require("jsonpath-plus");
|
|
991
|
-
|
|
992
|
-
// src/utils/openapi-utils/is-ref-defined.ts
|
|
993
|
-
var R10 = __toESM(require("ramda"), 1);
|
|
994
|
-
function isRefDefined($ref, swagger) {
|
|
995
|
-
if ($ref.startsWith("#/")) {
|
|
996
|
-
const path12 = $ref.replace("#/", "").split("/");
|
|
997
|
-
return R10.path(path12, swagger) !== void 0;
|
|
998
|
-
}
|
|
999
|
-
return false;
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
// src/utils/openapi-utils/remove-undefined-ref.ts
|
|
1003
|
-
function removeUndefinedRef(swagger) {
|
|
1004
|
-
const shadow = R11.clone(swagger);
|
|
1005
|
-
const matches = (0, import_jsonpath_plus3.JSONPath)({
|
|
1006
|
-
path: "$..*['$ref']^",
|
|
1007
|
-
json: swagger,
|
|
1008
|
-
resultType: "all"
|
|
1009
|
-
});
|
|
1010
|
-
for (const match of matches) {
|
|
1011
|
-
if (match.value.$ref && !isRefDefined(match.value.$ref, swagger)) {
|
|
1012
|
-
import_jsonpointer.default.set(shadow, match.pointer, R11.omit(["$ref"], match.value));
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
return shadow;
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
// src/utils/openapi-utils/dereference-operation.ts
|
|
1019
|
-
function dereferencePathObject(swagger) {
|
|
1020
|
-
const matches = (0, import_jsonpath_plus4.JSONPath)({
|
|
1021
|
-
path: "$.paths.*.$ref^",
|
|
1022
|
-
json: swagger,
|
|
1023
|
-
resultType: "all"
|
|
1024
|
-
});
|
|
1025
|
-
for (const match of matches) {
|
|
1026
|
-
const value = dereference(match.value.$ref, swagger);
|
|
1027
|
-
import_jsonpointer2.default.set(swagger, match.pointer, value);
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
function dereferenceRequestBody(swagger) {
|
|
1031
|
-
const matches = (0, import_jsonpath_plus4.JSONPath)({
|
|
1032
|
-
path: "$.paths.*.*.requestBody.$ref^",
|
|
1033
|
-
json: swagger,
|
|
1034
|
-
resultType: "all"
|
|
1035
|
-
});
|
|
1036
|
-
for (const match of matches) {
|
|
1037
|
-
const value = dereference(match.value.$ref, swagger);
|
|
1038
|
-
import_jsonpointer2.default.set(swagger, match.pointer, value);
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
function dereferenceResponses(swagger) {
|
|
1042
|
-
const matches = [
|
|
1043
|
-
...(0, import_jsonpath_plus4.JSONPath)({
|
|
1044
|
-
path: "$.paths.*.*.responses.*.$ref^",
|
|
1045
|
-
json: swagger,
|
|
1046
|
-
resultType: "all"
|
|
1047
|
-
}),
|
|
1048
|
-
...(0, import_jsonpath_plus4.JSONPath)({
|
|
1049
|
-
path: "$.paths.*.*.responses.*.headers.*.$ref^",
|
|
1050
|
-
json: swagger,
|
|
1051
|
-
resultType: "all"
|
|
1052
|
-
})
|
|
1053
|
-
];
|
|
1054
|
-
for (const match of matches) {
|
|
1055
|
-
const value = dereference(match.value.$ref, swagger);
|
|
1056
|
-
import_jsonpointer2.default.set(swagger, match.pointer, value);
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
function dereferenceParameters(swagger) {
|
|
1060
|
-
const matches = (0, import_jsonpath_plus4.JSONPath)({
|
|
1061
|
-
path: "$.paths.*.*.parameters.*.$ref^",
|
|
1062
|
-
json: swagger,
|
|
1063
|
-
resultType: "all"
|
|
1064
|
-
});
|
|
1065
|
-
for (const match of matches) {
|
|
1066
|
-
const value = dereference(match.value.$ref, swagger);
|
|
1067
|
-
import_jsonpointer2.default.set(swagger, match.pointer, value);
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
function dereferenceOperation(swagger) {
|
|
1071
|
-
const shadow = R12.clone(swagger);
|
|
1072
|
-
dereferencePathObject(shadow);
|
|
1073
|
-
dereferenceRequestBody(shadow);
|
|
1074
|
-
dereferenceResponses(shadow);
|
|
1075
|
-
dereferenceParameters(shadow);
|
|
1076
|
-
return removeUndefinedRef(shadow);
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
// src/utils/openapi-utils/dereference-deep.ts
|
|
1080
|
-
function dereferenceDeep($ref, swagger) {
|
|
1081
|
-
const stack = [$ref];
|
|
1082
|
-
let value;
|
|
1083
|
-
while (true) {
|
|
1084
|
-
const last2 = stack[stack.length - 1];
|
|
1085
|
-
value = dereference(last2, swagger);
|
|
1086
|
-
if (JsonSchemaUtils.isRef(value)) {
|
|
1087
|
-
if (!stack.includes(value.$ref)) {
|
|
1088
|
-
stack.push(value.$ref);
|
|
1089
|
-
continue;
|
|
1090
|
-
} else {
|
|
1091
|
-
throw new Error(`Circular reference detected: ${stack.join(" -> ")} -> ${value.$ref}`);
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
break;
|
|
1095
|
-
}
|
|
1096
|
-
return value;
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
// src/utils/openapi-utils/to-3_1.ts
|
|
1100
|
-
var import_openapi_parser = require("@scalar/openapi-parser");
|
|
1101
|
-
function To3_1(openapi) {
|
|
1102
|
-
const { specification } = (0, import_openapi_parser.upgrade)(openapi);
|
|
1103
|
-
return specification;
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
// src/utils/openapi-utils/map-operation.ts
|
|
1107
|
-
var R13 = __toESM(require("ramda"), 1);
|
|
1108
|
-
function mapOperation(specification, mapper) {
|
|
1109
|
-
const shadow = R13.clone(specification);
|
|
1110
|
-
for (const [pathname, pathItem] of Object.entries(shadow.paths || {})) {
|
|
1111
|
-
for (const m in pathItem) {
|
|
1112
|
-
const method = m.toLowerCase();
|
|
1113
|
-
if (!SupportedMethods.includes(method)) continue;
|
|
1114
|
-
if (typeof pathItem[m] !== "object" || Array.isArray(pathItem[m]) || pathItem[m] === null) continue;
|
|
1115
|
-
const operation = pathItem[m];
|
|
1116
|
-
pathItem[m] = mapper(method, pathname, operation);
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
return shadow;
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
// src/utils/openapi-utils/map-parameter.ts
|
|
1123
|
-
function mapParameter(specification, mapper) {
|
|
1124
|
-
return mapOperation(specification, (method, pathname, operation) => {
|
|
1125
|
-
if (!operation.parameters) return operation;
|
|
1126
|
-
operation.parameters = operation.parameters.map((parameter) => mapper(method, pathname, operation, parameter));
|
|
1127
|
-
return operation;
|
|
1128
|
-
});
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
// src/utils/openapi-utils/index.ts
|
|
1132
|
-
var OpenapiUtils = class {
|
|
1133
|
-
static isRefDefined = isRefDefined;
|
|
1134
|
-
static dereference = dereference;
|
|
1135
|
-
static dereferenceDeep = dereferenceDeep;
|
|
1136
|
-
static removeUndefinedRef = removeUndefinedRef;
|
|
1137
|
-
static dereferenceOperation = dereferenceOperation;
|
|
1138
|
-
static mapOperation = mapOperation;
|
|
1139
|
-
static mapParameter = mapParameter;
|
|
1140
|
-
// static updateOperationId = updateOperationId
|
|
1141
|
-
static to3_1 = To3_1;
|
|
1142
|
-
};
|
|
1143
|
-
|
|
1144
|
-
// src/transformers/operation-definition/declaration.renderer.ts
|
|
1145
|
-
var alias = (name) => `${name}Schema`;
|
|
1146
|
-
var DeclarationRenderer2 = class {
|
|
1147
|
-
constructor(operationDefinition, options) {
|
|
1148
|
-
this.operationDefinition = operationDefinition;
|
|
1149
|
-
this.options = options;
|
|
1150
|
-
this.typeName = typeNameFactory(operationDefinition);
|
|
1151
|
-
}
|
|
1152
|
-
typeName;
|
|
1153
|
-
renderResponseBodies(operation, options) {
|
|
1154
|
-
if (!operation.responses || R14.isEmpty(operation.responses)) {
|
|
1155
|
-
return `export interface ${this.typeName("ResponseBodies")} {}`;
|
|
1156
|
-
}
|
|
1157
|
-
const $responses = Object.entries(operation.responses).map(([statusCode, response]) => {
|
|
1158
|
-
if (!JsonSchemaUtils.isRef(response)) {
|
|
1159
|
-
const $value = Object.entries(response.content || {}).map(([mediaType, mediaTypeObject]) => [mediaType, mediaTypeObject.schema]).map(([mediaType, schema]) => {
|
|
1160
|
-
if (mediaType.includes("text/event-stream")) return "ReadableStream<ServerSentEvent>";
|
|
1161
|
-
if (mediaType.includes("multipart/form-data")) return "FormData";
|
|
1162
|
-
if (!schema) return "unknown";
|
|
1163
|
-
return JsonSchemaTransformer.toDeclaration(schema, options);
|
|
1164
|
-
}).join(" | ");
|
|
1165
|
-
return indent(2, `${statusCode}: ${$value || "void"}`);
|
|
1166
|
-
}
|
|
1167
|
-
}).join("\n");
|
|
1168
|
-
return [
|
|
1169
|
-
`export interface ${this.typeName("ResponseBodies")} {`,
|
|
1170
|
-
$responses,
|
|
1171
|
-
"}"
|
|
1172
|
-
].join("\n");
|
|
1173
|
-
}
|
|
1174
|
-
renderRequestBodies(operation, options) {
|
|
1175
|
-
let $requestBodies = `export interface ${this.typeName("RequestBodies")} {}`;
|
|
1176
|
-
if (operation.requestBody && !JsonSchemaUtils.isRef(operation.requestBody)) {
|
|
1177
|
-
const $mediaTypes = Object.entries(operation.requestBody.content || {}).map(([mediaType, mediaTypeObject]) => [mediaType, mediaTypeObject.schema]).map(([mediaType, schema]) => {
|
|
1178
|
-
if (!schema) return `${JSON.stringify(mediaType)}: unknown`;
|
|
1179
|
-
return `${JSON.stringify(mediaType)}: ${JsonSchemaTransformer.toDeclaration(schema, options)}`;
|
|
1180
|
-
}).map((pair) => indent(2, pair));
|
|
1181
|
-
$requestBodies = [
|
|
1182
|
-
`export interface ${this.typeName("RequestBodies")} {`,
|
|
1183
|
-
...$mediaTypes,
|
|
1184
|
-
"}"
|
|
1185
|
-
].join("\n");
|
|
1186
|
-
}
|
|
1187
|
-
return $requestBodies;
|
|
1188
|
-
}
|
|
1189
|
-
renderParameterBodies(operationDefinition, options) {
|
|
1190
|
-
const { operation } = operationDefinition;
|
|
1191
|
-
let parameterBodies = "";
|
|
1192
|
-
if (operation.requestBody && !JsonSchemaUtils.isRef(operation.requestBody)) {
|
|
1193
|
-
const $mediaTypes = Object.entries(operation.requestBody.content || {}).map(([mediaType, mediaTypeObject]) => [mediaType, mediaTypeObject.schema]).map(([mediaType, schemaOrRef]) => {
|
|
1194
|
-
if (!schemaOrRef) return `${JSON.stringify(mediaType)}: unknown`;
|
|
1195
|
-
const schema = JsonSchemaUtils.isRef(schemaOrRef) ? OpenapiUtils.dereferenceDeep(schemaOrRef.$ref, operationDefinition.document.specification) : schemaOrRef;
|
|
1196
|
-
if (schema.type === "object" || schema.properties) {
|
|
1197
|
-
return `${JSON.stringify(mediaType)}: ${JsonSchemaTransformer.toDeclaration(schemaOrRef, options)} & { [key: string]: any }`;
|
|
1198
|
-
}
|
|
1199
|
-
return `${JSON.stringify(mediaType)}: { [key: string]: any }`;
|
|
1200
|
-
}).map((pair) => indent(2, pair));
|
|
1201
|
-
parameterBodies = [
|
|
1202
|
-
`interface ${this.typeName("ParameterBodies")} {`,
|
|
1203
|
-
...$mediaTypes,
|
|
1204
|
-
"}",
|
|
1205
|
-
""
|
|
1206
|
-
].join("\n");
|
|
1207
|
-
}
|
|
1208
|
-
return parameterBodies;
|
|
1209
|
-
}
|
|
1210
|
-
renderRequestParameters(operation, options) {
|
|
1211
|
-
const mediaTypes = operation.requestBody && !JsonSchemaUtils.isRef(operation.requestBody) ? Object.keys(operation.requestBody.content || {}) : [];
|
|
1212
|
-
const base = `${this.typeName("RequestQuery")} & ${this.typeName("RouteParameters")} & ${this.typeName("RequestHeaders")}`;
|
|
1213
|
-
if (mediaTypes.length === 1) {
|
|
1214
|
-
return `export type ${this.typeName("RequestParameters")} = ${base} & ${this.typeName("RequestBodies")}[${JSON.stringify(mediaTypes[0])}]`;
|
|
1215
|
-
}
|
|
1216
|
-
if (mediaTypes.length > 1) {
|
|
1217
|
-
const unions = mediaTypes.map((mediaType) => `(${base} & ${this.typeName("RequestBodies")}[${JSON.stringify(mediaType)}] & { "content-type": ${JSON.stringify(mediaType)} })`).join("\n| ");
|
|
1218
|
-
return `export type ${this.typeName("RequestParameters")} = ${unions}`;
|
|
1219
|
-
}
|
|
1220
|
-
return `export type ${this.typeName("RequestParameters")} = ${base}`;
|
|
1221
|
-
}
|
|
1222
|
-
rendererParameters(name, parameters, options) {
|
|
1223
|
-
if (parameters.length === 0) {
|
|
1224
|
-
return `export type ${name} = {}`;
|
|
1225
|
-
}
|
|
1226
|
-
const $parameters = parameters.map((parameter) => {
|
|
1227
|
-
const parameterName = `"${parameter.name}"`;
|
|
1228
|
-
const $key = parameter.required ? parameterName : `${parameterName}?`;
|
|
1229
|
-
const $value = JsonSchemaTransformer.toDeclaration(parameter.schema || { type: "any" }, options);
|
|
1230
|
-
return indent(2, `${$key}: ${$value}`);
|
|
1231
|
-
}).join("\n");
|
|
1232
|
-
return [
|
|
1233
|
-
`export type ${name} = {`,
|
|
1234
|
-
$parameters,
|
|
1235
|
-
"}"
|
|
1236
|
-
].filter(Boolean).join("\n");
|
|
1237
|
-
}
|
|
1238
|
-
renderDependencies() {
|
|
1239
|
-
const schemaDefinitions = this.operationDefinition.getDependencies().filter((schemaDefinition) => !SchemaDefinition.isUnknown(schemaDefinition));
|
|
1240
|
-
const $schemaDefinitions = schemaDefinitions.map((schemaDefinition) => {
|
|
1241
|
-
const filepath = this.options.getDependentSchemaDefinitionFilepath(schemaDefinition);
|
|
1242
|
-
const schemaName = schemaDefinition.name;
|
|
1243
|
-
return `import type { ${schemaName} as ${alias(schemaName)} } from "${filepath}"`;
|
|
1244
|
-
}).map((str) => str.replace(/ from "(\.\.?\/.+?)(\.ts|\.mts|\.cts|\.js|\.cjs|\.mjs)?"/, this.options.esm ? ' from "$1.js"' : ' from "$1"'));
|
|
1245
|
-
return [
|
|
1246
|
-
'import type { KeqOperation, KeqPathParameterInit, KeqQueryInit, ServerSentEvent } from "keq"',
|
|
1247
|
-
...$schemaDefinitions
|
|
1248
|
-
].join("\n");
|
|
1249
|
-
}
|
|
1250
|
-
render() {
|
|
1251
|
-
const { operation } = this.operationDefinition;
|
|
1252
|
-
if (!operation.responses) return "";
|
|
1253
|
-
const jsonSchemaDeclarationRendererOptions = {
|
|
1254
|
-
referenceTransformer: (schema) => {
|
|
1255
|
-
return ReferenceTransformer.toDeclaration(schema, alias);
|
|
1256
|
-
}
|
|
1257
|
-
};
|
|
1258
|
-
const $dependencies = this.renderDependencies();
|
|
1259
|
-
const $responseBodies = this.renderResponseBodies(operation, jsonSchemaDeclarationRendererOptions);
|
|
1260
|
-
const $requestBodies = this.renderRequestBodies(operation, jsonSchemaDeclarationRendererOptions);
|
|
1261
|
-
const $parameterBodies = this.renderParameterBodies(this.operationDefinition, jsonSchemaDeclarationRendererOptions);
|
|
1262
|
-
const $requestParameters = this.renderRequestParameters(operation, jsonSchemaDeclarationRendererOptions);
|
|
1263
|
-
const $requestQuery = this.rendererParameters(
|
|
1264
|
-
`${this.typeName("RequestQuery")}`,
|
|
1265
|
-
operation.parameters?.filter((p) => !JsonSchemaUtils.isRef(p) && p.in === "query") || [],
|
|
1266
|
-
jsonSchemaDeclarationRendererOptions
|
|
1267
|
-
);
|
|
1268
|
-
const $routeParameters = this.rendererParameters(
|
|
1269
|
-
`${this.typeName("RouteParameters")}`,
|
|
1270
|
-
operation.parameters?.filter((p) => !JsonSchemaUtils.isRef(p) && p.in === "path") || [],
|
|
1271
|
-
jsonSchemaDeclarationRendererOptions
|
|
1272
|
-
);
|
|
1273
|
-
const $requestHeaders = this.rendererParameters(
|
|
1274
|
-
`${this.typeName("RequestHeaders")}`,
|
|
1275
|
-
operation.parameters?.filter((p) => !JsonSchemaUtils.isRef(p) && p.in === "header") || [],
|
|
1276
|
-
jsonSchemaDeclarationRendererOptions
|
|
1277
|
-
);
|
|
1278
|
-
return [
|
|
1279
|
-
"/* @anchor:file:start */",
|
|
1280
|
-
"",
|
|
1281
|
-
$dependencies,
|
|
1282
|
-
"",
|
|
1283
|
-
$responseBodies,
|
|
1284
|
-
"",
|
|
1285
|
-
$requestBodies,
|
|
1286
|
-
"",
|
|
1287
|
-
$requestQuery,
|
|
1288
|
-
"",
|
|
1289
|
-
$routeParameters,
|
|
1290
|
-
"",
|
|
1291
|
-
$requestHeaders,
|
|
1292
|
-
"",
|
|
1293
|
-
$parameterBodies || void 0,
|
|
1294
|
-
$requestParameters,
|
|
1295
|
-
"",
|
|
1296
|
-
`export interface ${this.typeName("Operation")}<STATUS extends keyof ${this.typeName("ResponseBodies")}, CONTENT_TYPE extends ${$parameterBodies ? `keyof ${this.typeName("ParameterBodies")}` : "string"} > extends KeqOperation {`,
|
|
1297
|
-
` requestParams: ${this.typeName("RouteParameters")} & { [key: string]: KeqPathParameterInit }`,
|
|
1298
|
-
` requestQuery: ${this.typeName("RequestQuery")} & { [key: string]: KeqQueryInit }`,
|
|
1299
|
-
` requestHeaders: ${this.typeName("RequestHeaders")} & { [key: string]: string | number }`,
|
|
1300
|
-
` requestBody: ${$parameterBodies ? `${this.typeName("ParameterBodies")}[CONTENT_TYPE] | ` : "object | "}BodyInit`,
|
|
1301
|
-
` responseBody: ${this.typeName("ResponseBodies")}[STATUS]`,
|
|
1302
|
-
"}",
|
|
1303
|
-
"",
|
|
1304
|
-
"/* @anchor:file:end */"
|
|
1305
|
-
].filter(R14.isNotNil).join("\n");
|
|
1306
|
-
}
|
|
1307
|
-
};
|
|
1308
|
-
|
|
1309
|
-
// src/transformers/operation-definition/micro-function.renderer.ts
|
|
1310
|
-
var R16 = __toESM(require("ramda"), 1);
|
|
1311
|
-
|
|
1312
|
-
// src/exception.ts
|
|
1313
|
-
var import_ts_custom_error = require("ts-custom-error");
|
|
1314
|
-
var import_word_wrap = __toESM(require("word-wrap"), 1);
|
|
1315
|
-
var Exception = class extends import_ts_custom_error.CustomError {
|
|
1316
|
-
constructor(module2, message) {
|
|
1317
|
-
const moduleName = typeof module2 === "string" ? module2 : module2.name;
|
|
1318
|
-
const msg = (0, import_word_wrap.default)(message, { width: 60, indent: " " });
|
|
1319
|
-
super(`${moduleName} module failed to compile:
|
|
1320
|
-
${msg}`);
|
|
1321
|
-
Object.defineProperty(this, "name", { value: "KeqCLI_Exception" });
|
|
1322
|
-
}
|
|
1323
|
-
};
|
|
1324
|
-
|
|
1325
|
-
// src/transformers/operation-definition/typescript-snippet.ts
|
|
1326
|
-
var R15 = __toESM(require("ramda"), 1);
|
|
11
|
+
// src/cli.ts
|
|
12
|
+
var _path = require('path'); var path2 = _interopRequireWildcard(_path); var path = _interopRequireWildcard(_path);
|
|
13
|
+
var _semver = require('semver'); var _semver2 = _interopRequireDefault(_semver);
|
|
14
|
+
var _commander = require('commander');
|
|
1327
15
|
|
|
1328
|
-
// src/
|
|
1329
|
-
var QsArrayFormat = /* @__PURE__ */ ((QsArrayFormat2) => {
|
|
1330
|
-
QsArrayFormat2["brackets"] = "brackets";
|
|
1331
|
-
QsArrayFormat2["indices"] = "indices";
|
|
1332
|
-
QsArrayFormat2["repeat"] = "repeat";
|
|
1333
|
-
QsArrayFormat2["comma"] = "comma";
|
|
1334
|
-
QsArrayFormat2["space"] = "space";
|
|
1335
|
-
QsArrayFormat2["pipe"] = "pipe";
|
|
1336
|
-
return QsArrayFormat2;
|
|
1337
|
-
})(QsArrayFormat || {});
|
|
16
|
+
// src/utils/scan-generated-files.ts
|
|
1338
17
|
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
this.typeName = typeNameFactory(operationDefinition);
|
|
1345
|
-
}
|
|
1346
|
-
typeName;
|
|
1347
|
-
getQsParameters(parameter) {
|
|
1348
|
-
let arrayFormat;
|
|
1349
|
-
let allowDots;
|
|
1350
|
-
let indices;
|
|
1351
|
-
const style = parameter.style || "form";
|
|
1352
|
-
const explode = parameter.explode ?? true;
|
|
1353
|
-
if ("x-qs-array-format" in parameter) {
|
|
1354
|
-
arrayFormat = parameter["x-qs-array-format"];
|
|
1355
|
-
} else {
|
|
1356
|
-
if (style === "deepObject") {
|
|
1357
|
-
arrayFormat = "brackets" /* brackets */;
|
|
1358
|
-
} else if (explode) {
|
|
1359
|
-
arrayFormat = "repeat" /* repeat */;
|
|
1360
|
-
} else {
|
|
1361
|
-
if (style === "form") {
|
|
1362
|
-
arrayFormat = "comma" /* comma */;
|
|
1363
|
-
} else if (style === "spaceDelimited") {
|
|
1364
|
-
arrayFormat = "space" /* space */;
|
|
1365
|
-
} else if (style === "pipeDelimited") {
|
|
1366
|
-
arrayFormat = "pipe" /* pipe */;
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
if ("x-qs-allow-dots" in parameter) {
|
|
1371
|
-
allowDots = Boolean(parameter["x-qs-allow-dots"]);
|
|
1372
|
-
}
|
|
1373
|
-
if ("x-qs-indices" in parameter) {
|
|
1374
|
-
indices = Boolean(parameter["x-qs-indices"]);
|
|
1375
|
-
}
|
|
1376
|
-
if (arrayFormat || allowDots !== void 0 || indices !== void 0) {
|
|
1377
|
-
return {
|
|
1378
|
-
...arrayFormat ? { arrayFormat } : {},
|
|
1379
|
-
...allowDots !== void 0 ? { allowDots } : {},
|
|
1380
|
-
...indices !== void 0 ? { indices } : {}
|
|
1381
|
-
};
|
|
1382
|
-
}
|
|
1383
|
-
return void 0;
|
|
1384
|
-
}
|
|
1385
|
-
// render: "if (args && 'Authorization' in args) req.header('Authorization', args['Authorization'])"
|
|
1386
|
-
renderRequestHeaders() {
|
|
1387
|
-
const { operation } = this.operationDefinition;
|
|
1388
|
-
const $headers = (operation.parameters || []).filter((p) => !JsonSchemaUtils.isRef(p)).filter((p) => p.in === "header").map((p) => `if (args && ${JSON.stringify(p.name)} in args) req.header(${JSON.stringify(p.name)}, args[${JSON.stringify(p.name)}])`).join("\n");
|
|
1389
|
-
return $headers;
|
|
1390
|
-
}
|
|
1391
|
-
// render: "if (args && 'id' in args) req.query('id', args['id'], options)"
|
|
1392
|
-
renderRequestQuery() {
|
|
1393
|
-
const { operation } = this.operationDefinition;
|
|
1394
|
-
const $query = (operation.parameters || []).filter((p) => !JsonSchemaUtils.isRef(p)).filter((p) => p.in === "query").map((p) => {
|
|
1395
|
-
const option = this.getQsParameters(p);
|
|
1396
|
-
const $option = !option || R15.isEmpty(option) ? "" : `, ${JSON.stringify(option)}`;
|
|
1397
|
-
return `if (args && ${JSON.stringify(p.name)} in args) req.query(${JSON.stringify(p.name)}, args[${JSON.stringify(p.name)}]${$option})`;
|
|
1398
|
-
}).join("\n");
|
|
1399
|
-
return $query;
|
|
1400
|
-
}
|
|
1401
|
-
// render: "if (args && 'id' in args) req.params('id', args['id'])"
|
|
1402
|
-
renderRequestPathParameters() {
|
|
1403
|
-
const { operation } = this.operationDefinition;
|
|
1404
|
-
const $pathParameters = (operation.parameters || []).filter((p) => !JsonSchemaUtils.isRef(p)).filter((p) => p.in === "path").map((p) => `if (args && ${JSON.stringify(p.name)} in args) req.params(${JSON.stringify(p.name)}, args[${JSON.stringify(p.name)}])`).join("\n");
|
|
1405
|
-
return $pathParameters;
|
|
1406
|
-
}
|
|
1407
|
-
getRequestMediaTypes() {
|
|
1408
|
-
const { operation } = this.operationDefinition;
|
|
1409
|
-
const requestBodyContent = operation.requestBody?.content || {};
|
|
1410
|
-
return Object.keys(requestBodyContent);
|
|
1411
|
-
}
|
|
1412
|
-
// render "req.type("application/json")"
|
|
1413
|
-
renderMediaType() {
|
|
1414
|
-
const mediaTypes = this.getRequestMediaTypes();
|
|
1415
|
-
if (mediaTypes.length === 1 && !mediaTypes[0].endsWith("/*")) {
|
|
1416
|
-
return `req.type("${mediaTypes[0]}")
|
|
1417
|
-
`;
|
|
1418
|
-
} else if (mediaTypes.some((mediaType) => mediaType === "*/*")) {
|
|
1419
|
-
} else if (mediaTypes.some((mediaType) => mediaType.endsWith("/*"))) {
|
|
1420
|
-
return 'if(args?.["content-type"]) req.type(args["content-type"])\n';
|
|
1421
|
-
} else if (mediaTypes.length > 1) {
|
|
1422
|
-
return 'if(args?.["content-type"]) req.type(args["content-type"])\n';
|
|
1423
|
-
}
|
|
1424
|
-
return "";
|
|
1425
|
-
}
|
|
1426
|
-
// render body
|
|
1427
|
-
requestBodyFormDataPropertyRenderer(propertyName, propertySchema, mediaType) {
|
|
18
|
+
var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
|
|
19
|
+
async function findAllFiles(dir, extensions) {
|
|
20
|
+
const results = [];
|
|
21
|
+
async function scan(currentDir) {
|
|
22
|
+
let entries;
|
|
1428
23
|
try {
|
|
1429
|
-
|
|
1430
|
-
const schema = JsonSchemaUtils.isRef(propertySchema) ? OpenapiUtils.dereferenceDeep(propertySchema.$ref, this.operationDefinition.document.specification) : propertySchema;
|
|
1431
|
-
if (schema.type === "string" && schema.format === "binary" || schema.contentMediaType === "application/octet-stream") {
|
|
1432
|
-
return `if (args && ${$propertyName} in args && args[${$propertyName}]) req.attach(${$propertyName}, args[${$propertyName}])`;
|
|
1433
|
-
} else if (schema.type === "string" || schema.type === "array" && schema.items && schema.items.type === "string") {
|
|
1434
|
-
return `if (args && ${$propertyName} in args && args[${$propertyName}] !== undefined) req.field(${$propertyName}, args[${$propertyName}])`;
|
|
1435
|
-
} else if (schema.type === "number" || schema.type === "integer") {
|
|
1436
|
-
return `if (args && ${$propertyName} in args && args[${$propertyName}] !== undefined) req.field(${$propertyName}, String(args[${$propertyName}]))`;
|
|
1437
|
-
}
|
|
1438
|
-
return `if (args && ${$propertyName} in args && args[${$propertyName}] !== undefined) req.field(${$propertyName}, String(args[${$propertyName}]) /* type is non-string in schema; triggers type coercion here */)`;
|
|
24
|
+
entries = await _fsextra2.default.readdir(currentDir);
|
|
1439
25
|
} catch (err) {
|
|
1440
|
-
return
|
|
26
|
+
return;
|
|
1441
27
|
}
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
return this.requestBodyFormDataPropertyRenderer(propertyName, propertySchema, mediaType);
|
|
1449
|
-
} else {
|
|
1450
|
-
throw new Error(`Unsupported media type: ${mediaType}`);
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
renderRequestBody() {
|
|
1454
|
-
const { operation } = this.operationDefinition;
|
|
1455
|
-
const requestBodyContent = operation.requestBody?.content || {};
|
|
1456
|
-
const $requestBody = Object.entries(requestBodyContent).map(([mediaType, mediaTypeObject]) => {
|
|
1457
|
-
if (!mediaTypeObject.schema) return;
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
if (entry === "node_modules" || entry === ".git") {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const fullPath = path.join(currentDir, entry);
|
|
33
|
+
let stat;
|
|
1458
34
|
try {
|
|
1459
|
-
|
|
1460
|
-
if (schema.type !== "object") return;
|
|
1461
|
-
const properties = schema.properties || {};
|
|
1462
|
-
return Object.entries(properties).map(([propertyName, propertySchema]) => this.requestBodyPropertyRenderer(propertyName, propertySchema, mediaType)).join("\n");
|
|
35
|
+
stat = await _fsextra2.default.stat(fullPath);
|
|
1463
36
|
} catch (err) {
|
|
1464
|
-
|
|
37
|
+
continue;
|
|
1465
38
|
}
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
" */"
|
|
1476
|
-
].join("\n");
|
|
1477
|
-
}
|
|
1478
|
-
};
|
|
1479
|
-
|
|
1480
|
-
// src/transformers/operation-definition/micro-function.renderer.ts
|
|
1481
|
-
var OperationDefinitionMicroFunctionRenderer = class {
|
|
1482
|
-
constructor(operationDefinition, options) {
|
|
1483
|
-
this.operationDefinition = operationDefinition;
|
|
1484
|
-
this.options = options;
|
|
1485
|
-
this.typeName = typeNameFactory(operationDefinition);
|
|
1486
|
-
this.helper = new OperationDefinitionSnippet(operationDefinition, options);
|
|
1487
|
-
}
|
|
1488
|
-
helper;
|
|
1489
|
-
typeName;
|
|
1490
|
-
render() {
|
|
1491
|
-
const { operation, operationId, method, pathname } = this.operationDefinition;
|
|
1492
|
-
if (!operation.responses) return "";
|
|
1493
|
-
const $dependencies = this.renderDependencies();
|
|
1494
|
-
const $comment = new CommentRenderer2(this.operationDefinition).render();
|
|
1495
|
-
const moduleName = this.operationDefinition.module.name;
|
|
1496
|
-
const $method = method.toLowerCase();
|
|
1497
|
-
const $queryParameters = this.helper.renderRequestQuery();
|
|
1498
|
-
const $headerParameters = this.helper.renderRequestHeaders();
|
|
1499
|
-
const $pathParameters = this.helper.renderRequestPathParameters();
|
|
1500
|
-
const $mediaType = this.helper.renderMediaType();
|
|
1501
|
-
const $requestBody = this.helper.renderRequestBody();
|
|
1502
|
-
const $operationDeclaration = this.renderOperationDeclaration();
|
|
1503
|
-
return [
|
|
1504
|
-
"/* @anchor:file:start */",
|
|
1505
|
-
"",
|
|
1506
|
-
$dependencies,
|
|
1507
|
-
"",
|
|
1508
|
-
`const moduleName = "${moduleName}"`,
|
|
1509
|
-
`const method = "${method}"`,
|
|
1510
|
-
`const pathname = "${pathname}"`,
|
|
1511
|
-
"",
|
|
1512
|
-
$comment || void 0,
|
|
1513
|
-
`export ${$operationDeclaration} {`,
|
|
1514
|
-
` const req = request.${$method}<${this.typeName("ResponseBodies")}[STATUS]>("${pathname}")`,
|
|
1515
|
-
" .option('module', { name: moduleName, pathname, method })",
|
|
1516
|
-
"",
|
|
1517
|
-
$mediaType ? indent(2, $mediaType) : void 0,
|
|
1518
|
-
" /* @anchor:query:start */",
|
|
1519
|
-
$queryParameters ? indent(2, $queryParameters) : void 0,
|
|
1520
|
-
" /* @anchor:query:end */",
|
|
1521
|
-
"",
|
|
1522
|
-
" /* @anchor:headers:start */",
|
|
1523
|
-
$headerParameters ? indent(2, $headerParameters) : void 0,
|
|
1524
|
-
" /* @anchor:headers:end */",
|
|
1525
|
-
"",
|
|
1526
|
-
" /* @anchor:path-parameters:start */",
|
|
1527
|
-
$pathParameters ? indent(2, $pathParameters) : void 0,
|
|
1528
|
-
" /* @anchor:path-parameters:end */",
|
|
1529
|
-
"",
|
|
1530
|
-
" /* @anchor:body:start */",
|
|
1531
|
-
$requestBody ? indent(2, $requestBody) : void 0,
|
|
1532
|
-
" /* @anchor:body:end */",
|
|
1533
|
-
"",
|
|
1534
|
-
" /* @anchor:operation-return */",
|
|
1535
|
-
` return req as ReturnType<typeof ${operationId}<STATUS${$operationDeclaration.includes("CONTENT_TYPE") ? ", CONTENT_TYPE" : ""}>>`,
|
|
1536
|
-
"}",
|
|
1537
|
-
"",
|
|
1538
|
-
`${operationId}.pathname = pathname`,
|
|
1539
|
-
`${operationId}.method = method`,
|
|
1540
|
-
"/* @anchor:file:end */"
|
|
1541
|
-
].filter(R16.isNotNil).join("\n");
|
|
1542
|
-
}
|
|
1543
|
-
renderDependencies() {
|
|
1544
|
-
const declarationFilepath = this.options.getOperationDefinitionDeclarationFilepath(this.operationDefinition);
|
|
1545
|
-
const requestFilepath = this.options.getRequestFilepath();
|
|
1546
|
-
return [
|
|
1547
|
-
'import { Keq } from "keq"',
|
|
1548
|
-
`import { request } from "${requestFilepath}"`,
|
|
1549
|
-
`import type { ${this.typeName("Operation")}, ${this.typeName("ResponseBodies")}, ${this.typeName("RequestParameters")} } from "${declarationFilepath}"`,
|
|
1550
|
-
`export type { ${this.typeName("RequestQuery")}, ${this.typeName("RequestHeaders")}, ${this.typeName("RequestBodies")} } from "${declarationFilepath}"`
|
|
1551
|
-
].map((str) => str.replace(/ from "(\.\.?\/.+?)(\.ts|\.mts|\.cts|\.js|\.cjs|\.mjs)?"/, this.options.esm ? ' from "$1.js"' : ' from "$1"')).join("\n");
|
|
1552
|
-
}
|
|
1553
|
-
renderOperationDeclaration() {
|
|
1554
|
-
const { operationId } = this.operationDefinition;
|
|
1555
|
-
const mediaTypes = this.helper.getRequestMediaTypes();
|
|
1556
|
-
if (mediaTypes.length === 0) {
|
|
1557
|
-
return `function ${operationId}<STATUS extends keyof ${this.typeName("ResponseBodies")}, CONTENT_TYPE extends never = never>(args?: ${this.typeName("RequestParameters")}): Keq<${this.typeName("Operation")}<STATUS, CONTENT_TYPE>>`;
|
|
1558
|
-
} else if (mediaTypes.length === 1) {
|
|
1559
|
-
return `function ${operationId}<STATUS extends keyof ${this.typeName("ResponseBodies")}, CONTENT_TYPE extends ${JSON.stringify(mediaTypes[0])} = ${JSON.stringify(mediaTypes[0])}>(args?: ${this.typeName("RequestParameters")}): Keq<${this.typeName("Operation")}<STATUS, CONTENT_TYPE>>`;
|
|
1560
|
-
} else if (mediaTypes.length > 1) {
|
|
1561
|
-
return `function ${operationId}<STATUS extends keyof ${this.typeName("ResponseBodies")}, CONTENT_TYPE extends ${this.typeName("RequestParameters")}["content-type"]>(args?: Extract<${this.typeName("RequestParameters")}, { "content-type": CONTENT_TYPE }>): Keq<${this.typeName("Operation")}<STATUS, CONTENT_TYPE>>`;
|
|
1562
|
-
}
|
|
1563
|
-
throw new Exception(this.operationDefinition.module, "[operationDeclarationRenderer] Unreachable");
|
|
1564
|
-
}
|
|
1565
|
-
};
|
|
1566
|
-
|
|
1567
|
-
// src/transformers/operation-definition/nestjs-method.renderer.ts
|
|
1568
|
-
var R17 = __toESM(require("ramda"), 1);
|
|
1569
|
-
var OperationDefinitionNestjsMethodRenderer = class {
|
|
1570
|
-
constructor(operationDefinition, options) {
|
|
1571
|
-
this.operationDefinition = operationDefinition;
|
|
1572
|
-
this.options = options;
|
|
1573
|
-
this.typeName = typeNameFactory(operationDefinition);
|
|
1574
|
-
this.helper = new OperationDefinitionSnippet(operationDefinition, options);
|
|
1575
|
-
}
|
|
1576
|
-
helper;
|
|
1577
|
-
typeName;
|
|
1578
|
-
render() {
|
|
1579
|
-
const pathname = this.operationDefinition.pathname;
|
|
1580
|
-
const $comment = new CommentRenderer2(this.operationDefinition).render();
|
|
1581
|
-
const $method = this.operationDefinition.method.toLowerCase();
|
|
1582
|
-
const $mediaType = this.helper.renderMediaType();
|
|
1583
|
-
const $operationDeclaration = this.renderOperationDeclaration(this.operationDefinition);
|
|
1584
|
-
const $queryParameters = this.helper.renderRequestQuery();
|
|
1585
|
-
const $headerParameters = this.helper.renderRequestHeaders();
|
|
1586
|
-
const $pathParameters = this.helper.renderRequestPathParameters();
|
|
1587
|
-
const $requestBody = this.helper.renderRequestBody();
|
|
1588
|
-
return [
|
|
1589
|
-
$comment,
|
|
1590
|
-
`${$operationDeclaration} {`,
|
|
1591
|
-
` const req = this.request.${$method}<${this.typeName("ResponseBodies")}[STATUS]>(${JSON.stringify(pathname)})`,
|
|
1592
|
-
" .option(",
|
|
1593
|
-
' "module",',
|
|
1594
|
-
" {",
|
|
1595
|
-
` name: ${JSON.stringify(this.operationDefinition.module.name)},`,
|
|
1596
|
-
` pathname: ${JSON.stringify(pathname)},`,
|
|
1597
|
-
` method: ${JSON.stringify($method)},`,
|
|
1598
|
-
" },",
|
|
1599
|
-
" )",
|
|
1600
|
-
"",
|
|
1601
|
-
$mediaType ? indent(2, $mediaType) : void 0,
|
|
1602
|
-
"",
|
|
1603
|
-
" /* @anchor:query:start */",
|
|
1604
|
-
$queryParameters ? indent(2, $queryParameters) : void 0,
|
|
1605
|
-
" /* @anchor:query:end */",
|
|
1606
|
-
"",
|
|
1607
|
-
" /* @anchor:headers:start */",
|
|
1608
|
-
$headerParameters ? indent(2, $headerParameters) : void 0,
|
|
1609
|
-
" /* @anchor:headers:end */",
|
|
1610
|
-
"",
|
|
1611
|
-
" /* @anchor:path-parameters:start */",
|
|
1612
|
-
$pathParameters ? indent(2, $pathParameters) : void 0,
|
|
1613
|
-
" /* @anchor:path-parameters:end */",
|
|
1614
|
-
"",
|
|
1615
|
-
" /* @anchor:body:start */",
|
|
1616
|
-
$requestBody ? indent(2, $requestBody) : void 0,
|
|
1617
|
-
" /* @anchor:body:end */",
|
|
1618
|
-
"",
|
|
1619
|
-
" return req",
|
|
1620
|
-
"}"
|
|
1621
|
-
].filter(R17.isNotNil).join("\n");
|
|
1622
|
-
}
|
|
1623
|
-
renderOperationDeclaration(operationDefinition) {
|
|
1624
|
-
const { operationId } = operationDefinition;
|
|
1625
|
-
const typeName = typeNameFactory(operationDefinition);
|
|
1626
|
-
const mediaTypes = this.helper.getRequestMediaTypes();
|
|
1627
|
-
if (mediaTypes.length === 0) {
|
|
1628
|
-
return `${operationId}<STATUS extends keyof ${typeName("ResponseBodies")}, CONTENT_TYPE extends never = never>(args?: ${typeName("RequestParameters")}): Keq<${typeName("Operation")}<STATUS, CONTENT_TYPE>>`;
|
|
1629
|
-
} else if (mediaTypes.length === 1) {
|
|
1630
|
-
return `${operationId}<STATUS extends keyof ${typeName("ResponseBodies")}, CONTENT_TYPE extends ${JSON.stringify(mediaTypes[0])} = ${JSON.stringify(mediaTypes[0])}>(args?: ${typeName("RequestParameters")}): Keq<${typeName("Operation")}<STATUS, CONTENT_TYPE>>`;
|
|
1631
|
-
} else if (mediaTypes.length > 1) {
|
|
1632
|
-
return `${operationId}<STATUS extends keyof ${typeName("ResponseBodies")}, CONTENT_TYPE extends ${typeName("RequestParameters")}["content-type"]>(args?: Extract<${typeName("RequestParameters")}, { "content-type": CONTENT_TYPE }>): Keq<${typeName("Operation")}<STATUS, CONTENT_TYPE>>`;
|
|
1633
|
-
}
|
|
1634
|
-
throw new Exception(operationDefinition.module, "[operationDeclarationRenderer] Unreachable");
|
|
1635
|
-
}
|
|
1636
|
-
};
|
|
1637
|
-
|
|
1638
|
-
// src/transformers/operation-definition/operation-definition.transformer.ts
|
|
1639
|
-
var OperationDefinitionTransformer = class {
|
|
1640
|
-
static toDeclaration(operationDefinition, options) {
|
|
1641
|
-
return new DeclarationRenderer2(operationDefinition, options).render();
|
|
1642
|
-
}
|
|
1643
|
-
static toMicroFunction(operationDefinition, options) {
|
|
1644
|
-
return new OperationDefinitionMicroFunctionRenderer(operationDefinition, options).render();
|
|
1645
|
-
}
|
|
1646
|
-
static toNestjsMethod(operationDefinition, options) {
|
|
1647
|
-
return new OperationDefinitionNestjsMethodRenderer(operationDefinition, options).render();
|
|
1648
|
-
}
|
|
1649
|
-
static toComment(operationDefinition) {
|
|
1650
|
-
return new CommentRenderer2(operationDefinition).render();
|
|
1651
|
-
}
|
|
1652
|
-
};
|
|
1653
|
-
|
|
1654
|
-
// src/transformers/entrypoint/entrypoint.transformer.ts
|
|
1655
|
-
var path5 = __toESM(require("path"), 1);
|
|
1656
|
-
var EntrypointTransformer = class {
|
|
1657
|
-
static toTypescript(exports2, options) {
|
|
1658
|
-
const $exports = exports2.map((exportArtifact) => {
|
|
1659
|
-
const relativePath = path5.relative(
|
|
1660
|
-
options.dirpath,
|
|
1661
|
-
exportArtifact.filepath
|
|
1662
|
-
).replace(/(\.ts|\.mts|\.cts|\.js|\.cjs|\.mjs)?$/, options.esm ? ".js" : "");
|
|
1663
|
-
return relativePath.startsWith(".") ? `export * from '${relativePath}'` : `export * from './${relativePath}'`;
|
|
1664
|
-
});
|
|
1665
|
-
return [
|
|
1666
|
-
"/* @anchor:file:start */",
|
|
1667
|
-
"",
|
|
1668
|
-
...$exports,
|
|
1669
|
-
"",
|
|
1670
|
-
"/* @anchor:file:end */"
|
|
1671
|
-
].join("\n");
|
|
1672
|
-
}
|
|
1673
|
-
};
|
|
1674
|
-
|
|
1675
|
-
// src/transformers/api-document/nestjs-client.renderer.ts
|
|
1676
|
-
var R18 = __toESM(require("ramda"), 1);
|
|
1677
|
-
var changeCase2 = __toESM(require("change-case"), 1);
|
|
1678
|
-
|
|
1679
|
-
// src/transformers/api-document/nestjs-module.renderer.ts
|
|
1680
|
-
var changeCase3 = __toESM(require("change-case"), 1);
|
|
1681
|
-
|
|
1682
|
-
// src/plugins/generate-declaration/generators/schema-declaration/schema.generator.ts
|
|
1683
|
-
var R19 = __toESM(require("ramda"), 1);
|
|
1684
|
-
var path6 = __toESM(require("path"), 1);
|
|
1685
|
-
var changeCase4 = __toESM(require("change-case"), 1);
|
|
1686
|
-
|
|
1687
|
-
// src/plugins/generate-declaration/constants/metadata-storage.ts
|
|
1688
|
-
var MetadataStorage4 = /* @__PURE__ */ new WeakMap();
|
|
1689
|
-
|
|
1690
|
-
// src/plugins/generate-declaration/generators/schema-declaration/schema.generator.ts
|
|
1691
|
-
var SCHEMA_GENERATOR = "schemaGenerator";
|
|
1692
|
-
var SchemaDeclarationGenerator = class _SchemaDeclarationGenerator {
|
|
1693
|
-
async compile(compiler, task) {
|
|
1694
|
-
const context = compiler.context;
|
|
1695
|
-
const metadata = MetadataStorage4.get(compiler);
|
|
1696
|
-
const rc = context.rc;
|
|
1697
|
-
const documents = context.documents;
|
|
1698
|
-
const schemaDefinitions = documents.flatMap((document) => document.schemas);
|
|
1699
|
-
const artifactMap = new Map(
|
|
1700
|
-
await Promise.all(
|
|
1701
|
-
schemaDefinitions.map(async (schemaDefinition) => [
|
|
1702
|
-
schemaDefinition,
|
|
1703
|
-
await metadata.hooks.afterSchemaDeclarationArtifactGenerated.promise(
|
|
1704
|
-
this.generateSchemaDefinitionsArtifact(schemaDefinition, rc),
|
|
1705
|
-
schemaDefinition,
|
|
1706
|
-
task
|
|
1707
|
-
)
|
|
1708
|
-
])
|
|
1709
|
-
)
|
|
1710
|
-
);
|
|
1711
|
-
const entrypoints = R19.collectBy(
|
|
1712
|
-
(schemaDefinition) => schemaDefinition.module.name,
|
|
1713
|
-
schemaDefinitions
|
|
1714
|
-
).map((schemaDefinitions2) => [
|
|
1715
|
-
schemaDefinitions2[0].module,
|
|
1716
|
-
schemaDefinitions2.map((schemaDefinition) => artifactMap.get(schemaDefinition)).filter((artifact) => Boolean(artifact))
|
|
1717
|
-
]).map(([moduleDefinition, artifacts]) => this.generateEntrypointArtifact(
|
|
1718
|
-
moduleDefinition,
|
|
1719
|
-
artifacts,
|
|
1720
|
-
rc
|
|
1721
|
-
));
|
|
1722
|
-
return [...artifactMap.values(), ...entrypoints];
|
|
1723
|
-
}
|
|
1724
|
-
generateSchemaDefinitionsArtifact(schemaDefinition, rc) {
|
|
1725
|
-
const filepath = _SchemaDeclarationGenerator.getSchemaDefinitionArtifactFilepath(schemaDefinition, rc.fileNamingStyle);
|
|
1726
|
-
const dirpath = path6.dirname(filepath);
|
|
1727
|
-
const artifact = new Artifact({
|
|
1728
|
-
id: _SchemaDeclarationGenerator.getSchemaDefinitionArtifactId(schemaDefinition),
|
|
1729
|
-
filepath,
|
|
1730
|
-
content: SchemaDefinitionTransformer.toDeclaration(
|
|
1731
|
-
schemaDefinition,
|
|
1732
|
-
{
|
|
1733
|
-
esm: rc.esm,
|
|
1734
|
-
getDependentSchemaDefinitionFilepath(dependentSchemaDefinition) {
|
|
1735
|
-
const relativePath = path6.relative(
|
|
1736
|
-
dirpath,
|
|
1737
|
-
_SchemaDeclarationGenerator.getSchemaDefinitionArtifactFilepath(dependentSchemaDefinition, rc.fileNamingStyle)
|
|
1738
|
-
);
|
|
1739
|
-
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
39
|
+
if (stat.isDirectory()) {
|
|
40
|
+
await scan(fullPath);
|
|
41
|
+
} else if (stat.isFile()) {
|
|
42
|
+
if (!extensions) {
|
|
43
|
+
results.push(fullPath);
|
|
44
|
+
} else {
|
|
45
|
+
const ext = path.extname(fullPath);
|
|
46
|
+
if (extensions.includes(ext)) {
|
|
47
|
+
results.push(fullPath);
|
|
1740
48
|
}
|
|
1741
49
|
}
|
|
1742
|
-
),
|
|
1743
|
-
extensionName: ".schema.ts"
|
|
1744
|
-
});
|
|
1745
|
-
return artifact;
|
|
1746
|
-
}
|
|
1747
|
-
generateEntrypointArtifact(moduleDefinition, exports2, rc) {
|
|
1748
|
-
const filepath = _SchemaDeclarationGenerator.getEntrypointArtifactFilepath(moduleDefinition, rc.fileNamingStyle);
|
|
1749
|
-
const dirpath = path6.dirname(filepath);
|
|
1750
|
-
const artifact = new Artifact({
|
|
1751
|
-
id: _SchemaDeclarationGenerator.getEntrypointArtifactId(moduleDefinition),
|
|
1752
|
-
filepath,
|
|
1753
|
-
content: EntrypointTransformer.toTypescript(exports2, { dirpath })
|
|
1754
|
-
});
|
|
1755
|
-
return artifact;
|
|
1756
|
-
}
|
|
1757
|
-
static getEntrypointArtifactFilepath(moduleDefinition, fileNamingStyle) {
|
|
1758
|
-
return [
|
|
1759
|
-
".",
|
|
1760
|
-
changeCase4[fileNamingStyle](moduleDefinition.name),
|
|
1761
|
-
"types",
|
|
1762
|
-
"components",
|
|
1763
|
-
"schemas",
|
|
1764
|
-
"index.ts"
|
|
1765
|
-
].join("/");
|
|
1766
|
-
}
|
|
1767
|
-
static getEntrypointArtifactId(moduleDefinition) {
|
|
1768
|
-
return `${moduleDefinition.address.url}/components/schemas/entrypoint?generator=${SCHEMA_GENERATOR}`;
|
|
1769
|
-
}
|
|
1770
|
-
static getSchemaDefinitionArtifactFilepath(schemaDefinition, fileNamingStyle) {
|
|
1771
|
-
const filename = `${changeCase4[fileNamingStyle](schemaDefinition.name)}.schema.ts`;
|
|
1772
|
-
return [
|
|
1773
|
-
".",
|
|
1774
|
-
changeCase4[fileNamingStyle](schemaDefinition.module.name),
|
|
1775
|
-
"types",
|
|
1776
|
-
"components",
|
|
1777
|
-
"schemas",
|
|
1778
|
-
filename
|
|
1779
|
-
].join("/");
|
|
1780
|
-
}
|
|
1781
|
-
static getSchemaDefinitionArtifactId(schemaDefinition) {
|
|
1782
|
-
return `${schemaDefinition.id}?generator=${SCHEMA_GENERATOR}`;
|
|
1783
|
-
}
|
|
1784
|
-
};
|
|
1785
|
-
|
|
1786
|
-
// src/plugins/generate-declaration/generators/operation-declaration/operation.generator.ts
|
|
1787
|
-
var OPERATION_GENERATOR = "operationDeclarationGenerator";
|
|
1788
|
-
var OperationDeclarationGenerator = class _OperationDeclarationGenerator {
|
|
1789
|
-
async compile(compiler, task) {
|
|
1790
|
-
const context = compiler.context;
|
|
1791
|
-
const metadata = MetadataStorage4.get(compiler);
|
|
1792
|
-
const rc = context.rc;
|
|
1793
|
-
const documents = context.documents;
|
|
1794
|
-
const operationDefinitions = documents.flatMap((document) => document.operations);
|
|
1795
|
-
const artifactMap = new Map(
|
|
1796
|
-
await Promise.all(
|
|
1797
|
-
operationDefinitions.map(async (operationDefinition) => [
|
|
1798
|
-
operationDefinition,
|
|
1799
|
-
await metadata.hooks.afterOperationDeclarationArtifactGenerated.promise(
|
|
1800
|
-
this.generateOperationDefinitionArtifact(operationDefinition, rc),
|
|
1801
|
-
operationDefinition,
|
|
1802
|
-
task
|
|
1803
|
-
)
|
|
1804
|
-
])
|
|
1805
|
-
)
|
|
1806
|
-
);
|
|
1807
|
-
return Array.from(artifactMap.values());
|
|
1808
|
-
}
|
|
1809
|
-
generateOperationDefinitionArtifact(operationDefinition, rc) {
|
|
1810
|
-
const filepath = _OperationDeclarationGenerator.getOperationDefinitionArtifactFilepath(operationDefinition, rc.fileNamingStyle);
|
|
1811
|
-
const dirpath = path7.dirname(filepath);
|
|
1812
|
-
const artifact = new Artifact({
|
|
1813
|
-
id: _OperationDeclarationGenerator.getOperationDefinitionArtifactId(operationDefinition),
|
|
1814
|
-
filepath,
|
|
1815
|
-
content: OperationDefinitionTransformer.toDeclaration(
|
|
1816
|
-
operationDefinition,
|
|
1817
|
-
{
|
|
1818
|
-
esm: rc.esm,
|
|
1819
|
-
getDependentSchemaDefinitionFilepath(dependentSchemaDefinition) {
|
|
1820
|
-
const relativePath = path7.relative(
|
|
1821
|
-
dirpath,
|
|
1822
|
-
SchemaDeclarationGenerator.getSchemaDefinitionArtifactFilepath(dependentSchemaDefinition, rc.fileNamingStyle)
|
|
1823
|
-
);
|
|
1824
|
-
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1827
|
-
),
|
|
1828
|
-
extensionName: ".type.ts"
|
|
1829
|
-
});
|
|
1830
|
-
return artifact;
|
|
1831
|
-
}
|
|
1832
|
-
generateEntrypointArtifact(moduleDefinition, exports2, rc) {
|
|
1833
|
-
const filepath = _OperationDeclarationGenerator.getEntrypointArtifactFilepath(moduleDefinition, rc.fileNamingStyle);
|
|
1834
|
-
const dirpath = path7.dirname(filepath);
|
|
1835
|
-
const artifact = new Artifact({
|
|
1836
|
-
id: _OperationDeclarationGenerator.getEntrypointArtifactId(moduleDefinition),
|
|
1837
|
-
filepath,
|
|
1838
|
-
content: EntrypointTransformer.toTypescript(exports2, { dirpath })
|
|
1839
|
-
});
|
|
1840
|
-
return artifact;
|
|
1841
|
-
}
|
|
1842
|
-
static getOperationDefinitionArtifactFilepath(operationDefinition, fileNamingStyle) {
|
|
1843
|
-
const filename = `${changeCase5[fileNamingStyle](operationDefinition.operationId)}.type.ts`;
|
|
1844
|
-
const filepath = [
|
|
1845
|
-
".",
|
|
1846
|
-
changeCase5[fileNamingStyle](operationDefinition.module.name),
|
|
1847
|
-
"types",
|
|
1848
|
-
"operations",
|
|
1849
|
-
filename
|
|
1850
|
-
].join("/");
|
|
1851
|
-
return filepath;
|
|
1852
|
-
}
|
|
1853
|
-
static getOperationDefinitionArtifactId(operationDefinition) {
|
|
1854
|
-
return `${operationDefinition.id}?generator=${OPERATION_GENERATOR}`;
|
|
1855
|
-
}
|
|
1856
|
-
static getEntrypointArtifactFilepath(moduleDefinition, fileNamingStyle) {
|
|
1857
|
-
return [
|
|
1858
|
-
".",
|
|
1859
|
-
changeCase5[fileNamingStyle](moduleDefinition.name),
|
|
1860
|
-
"types",
|
|
1861
|
-
"operations",
|
|
1862
|
-
"index.ts"
|
|
1863
|
-
].join("/");
|
|
1864
|
-
}
|
|
1865
|
-
static getEntrypointArtifactId(moduleDefinition) {
|
|
1866
|
-
return `${moduleDefinition.address.url}/paths/entrypoint?generator=${OPERATION_GENERATOR}`;
|
|
1867
|
-
}
|
|
1868
|
-
};
|
|
1869
|
-
|
|
1870
|
-
// src/plugins/generate-declaration/generate-declaration.plugin.ts
|
|
1871
|
-
var DECLARATION_GENERATOR = "declarationGenerator";
|
|
1872
|
-
var GenerateDeclarationPlugin = class _GenerateDeclarationPlugin {
|
|
1873
|
-
name = DECLARATION_GENERATOR;
|
|
1874
|
-
operationGenerator = new OperationDeclarationGenerator();
|
|
1875
|
-
schemaGenerator = new SchemaDeclarationGenerator();
|
|
1876
|
-
constructor() {
|
|
1877
|
-
}
|
|
1878
|
-
apply(compiler) {
|
|
1879
|
-
if (MetadataStorage4.has(compiler)) return;
|
|
1880
|
-
_GenerateDeclarationPlugin.register(compiler);
|
|
1881
|
-
compiler.hooks.compile.tapPromise(_GenerateDeclarationPlugin.name, async (task) => {
|
|
1882
|
-
compiler.context.artifacts?.push(
|
|
1883
|
-
...await this.schemaGenerator.compile(compiler, task),
|
|
1884
|
-
...await this.operationGenerator.compile(compiler, task)
|
|
1885
|
-
);
|
|
1886
|
-
});
|
|
1887
|
-
}
|
|
1888
|
-
static register(compiler) {
|
|
1889
|
-
if (!MetadataStorage4.has(compiler)) {
|
|
1890
|
-
MetadataStorage4.set(compiler, {
|
|
1891
|
-
hooks: {
|
|
1892
|
-
afterEntrypointArtifactGenerated: new import_tapable.AsyncSeriesWaterfallHook(["artifact", "task"]),
|
|
1893
|
-
afterSchemaDeclarationArtifactGenerated: new import_tapable.AsyncSeriesWaterfallHook(["artifact", "schemaDefinition", "task"]),
|
|
1894
|
-
afterOperationDeclarationArtifactGenerated: new import_tapable.AsyncSeriesWaterfallHook(["artifact", "operationDefinition", "task"])
|
|
1895
|
-
}
|
|
1896
|
-
});
|
|
1897
|
-
}
|
|
1898
|
-
return MetadataStorage4.get(compiler);
|
|
1899
|
-
}
|
|
1900
|
-
static of(compiler) {
|
|
1901
|
-
return this.register(compiler);
|
|
1902
|
-
}
|
|
1903
|
-
};
|
|
1904
|
-
|
|
1905
|
-
// src/plugins/generate-micro-function/generators/request/request.generator.ts
|
|
1906
|
-
var MICRO_FUNCTION_REQUEST_GENERATOR = "microFunctionRequestGenerator";
|
|
1907
|
-
var RequestGenerator = class _RequestGenerator {
|
|
1908
|
-
generateRequestArtifact() {
|
|
1909
|
-
const content = [
|
|
1910
|
-
"/* @anchor:file:start */",
|
|
1911
|
-
"",
|
|
1912
|
-
'import { KeqRequest } from "keq"',
|
|
1913
|
-
"",
|
|
1914
|
-
"/* @anchor:request-declaration */",
|
|
1915
|
-
"export const request = new KeqRequest()",
|
|
1916
|
-
"",
|
|
1917
|
-
"/* @anchor:file:end */"
|
|
1918
|
-
].join("\n");
|
|
1919
|
-
return new Artifact({
|
|
1920
|
-
id: _RequestGenerator.getRequestArtifactId(),
|
|
1921
|
-
filepath: _RequestGenerator.getRequestArtifactFilepath(),
|
|
1922
|
-
content
|
|
1923
|
-
});
|
|
1924
|
-
}
|
|
1925
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1926
|
-
async compile(compiler, task) {
|
|
1927
|
-
return [
|
|
1928
|
-
this.generateRequestArtifact()
|
|
1929
|
-
];
|
|
1930
|
-
}
|
|
1931
|
-
static getRequestArtifactFilepath() {
|
|
1932
|
-
return "./request.ts";
|
|
1933
|
-
}
|
|
1934
|
-
static getRequestArtifactId() {
|
|
1935
|
-
return `request?generator=${MICRO_FUNCTION_REQUEST_GENERATOR}`;
|
|
1936
|
-
}
|
|
1937
|
-
};
|
|
1938
|
-
|
|
1939
|
-
// src/plugins/generate-micro-function/generators/micro_function/micro-function.generator.ts
|
|
1940
|
-
var MICRO_FUNCTION_GENERATOR = "microFunctionGenerator";
|
|
1941
|
-
var MicroFunctionGenerator = class _MicroFunctionGenerator {
|
|
1942
|
-
async compile(compiler, task) {
|
|
1943
|
-
const metadata = MetadataStorage3.get(compiler);
|
|
1944
|
-
const context = compiler.context;
|
|
1945
|
-
const rc = context.rc;
|
|
1946
|
-
const documents = context.documents;
|
|
1947
|
-
const operationDefinitions = documents.flatMap((document) => document.operations);
|
|
1948
|
-
const artifactMap = new Map(
|
|
1949
|
-
await Promise.all(
|
|
1950
|
-
operationDefinitions.map(async (operationDefinition) => [
|
|
1951
|
-
operationDefinition,
|
|
1952
|
-
await metadata.hooks.afterMicroFunctionArtifactGenerated.promise(
|
|
1953
|
-
this.generateOperationDefinitionArtifact(operationDefinition, rc),
|
|
1954
|
-
operationDefinition,
|
|
1955
|
-
task
|
|
1956
|
-
)
|
|
1957
|
-
])
|
|
1958
|
-
)
|
|
1959
|
-
);
|
|
1960
|
-
const entrypoints = await Promise.all(
|
|
1961
|
-
R20.collectBy(
|
|
1962
|
-
(operationDefinition) => operationDefinition.module.name,
|
|
1963
|
-
operationDefinitions
|
|
1964
|
-
).map((operationDefinitions2) => [
|
|
1965
|
-
operationDefinitions2[0].module,
|
|
1966
|
-
operationDefinitions2.map((operationDefinition) => artifactMap.get(operationDefinition)).filter((artifact) => Boolean(artifact))
|
|
1967
|
-
]).map(async ([moduleDefinition, artifacts]) => await metadata.hooks.afterEntrypointArtifactGenerated.promise(
|
|
1968
|
-
this.generateEntrypointArtifact(
|
|
1969
|
-
moduleDefinition,
|
|
1970
|
-
artifacts,
|
|
1971
|
-
rc
|
|
1972
|
-
),
|
|
1973
|
-
task
|
|
1974
|
-
))
|
|
1975
|
-
);
|
|
1976
|
-
return [...entrypoints, ...artifactMap.values()];
|
|
1977
|
-
}
|
|
1978
|
-
generateOperationDefinitionArtifact(operationDefinition, rc) {
|
|
1979
|
-
const filepath = _MicroFunctionGenerator.getOperationDefinitionArtifactFilepath(operationDefinition, rc.fileNamingStyle);
|
|
1980
|
-
const dirpath = path8.dirname(filepath);
|
|
1981
|
-
const artifact = new Artifact({
|
|
1982
|
-
id: _MicroFunctionGenerator.getOperationDefinitionArtifactId(operationDefinition),
|
|
1983
|
-
filepath,
|
|
1984
|
-
content: OperationDefinitionTransformer.toMicroFunction(operationDefinition, {
|
|
1985
|
-
esm: rc.esm,
|
|
1986
|
-
getOperationDefinitionDeclarationFilepath(operationDefinition2) {
|
|
1987
|
-
const relativePath = path8.relative(
|
|
1988
|
-
dirpath,
|
|
1989
|
-
OperationDeclarationGenerator.getOperationDefinitionArtifactFilepath(operationDefinition2, rc.fileNamingStyle)
|
|
1990
|
-
);
|
|
1991
|
-
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
1992
|
-
},
|
|
1993
|
-
getRequestFilepath() {
|
|
1994
|
-
const relativePath = path8.relative(
|
|
1995
|
-
dirpath,
|
|
1996
|
-
RequestGenerator.getRequestArtifactFilepath()
|
|
1997
|
-
);
|
|
1998
|
-
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
1999
|
-
}
|
|
2000
|
-
}),
|
|
2001
|
-
extensionName: ".type.ts"
|
|
2002
|
-
});
|
|
2003
|
-
return artifact;
|
|
2004
|
-
}
|
|
2005
|
-
generateEntrypointArtifact(moduleDefinition, exports2, rc) {
|
|
2006
|
-
const filepath = _MicroFunctionGenerator.getEntrypointArtifactFilepath(moduleDefinition, rc.fileNamingStyle);
|
|
2007
|
-
const dirpath = filepath.substring(0, filepath.lastIndexOf("/"));
|
|
2008
|
-
const artifact = new Artifact({
|
|
2009
|
-
id: _MicroFunctionGenerator.getEntrypointArtifactId(moduleDefinition),
|
|
2010
|
-
filepath,
|
|
2011
|
-
content: EntrypointTransformer.toTypescript(exports2, { dirpath })
|
|
2012
|
-
});
|
|
2013
|
-
return artifact;
|
|
2014
|
-
}
|
|
2015
|
-
static getOperationDefinitionArtifactFilepath(operationDefinition, fileNamingStyle) {
|
|
2016
|
-
const filename = `${changeCase6[fileNamingStyle](operationDefinition.operationId)}.fn.ts`;
|
|
2017
|
-
const filepath = [
|
|
2018
|
-
".",
|
|
2019
|
-
changeCase6[fileNamingStyle](operationDefinition.module.name),
|
|
2020
|
-
"operations",
|
|
2021
|
-
filename
|
|
2022
|
-
].join("/");
|
|
2023
|
-
return filepath;
|
|
2024
|
-
}
|
|
2025
|
-
static getOperationDefinitionArtifactId(operationDefinition) {
|
|
2026
|
-
return `${operationDefinition.id}?generator=${MICRO_FUNCTION_GENERATOR}`;
|
|
2027
|
-
}
|
|
2028
|
-
static getEntrypointArtifactFilepath(moduleDefinition, fileNamingStyle) {
|
|
2029
|
-
return [
|
|
2030
|
-
".",
|
|
2031
|
-
changeCase6[fileNamingStyle](moduleDefinition.name),
|
|
2032
|
-
"operations",
|
|
2033
|
-
"index.ts"
|
|
2034
|
-
].join("/");
|
|
2035
|
-
}
|
|
2036
|
-
static getEntrypointArtifactId(moduleDefinition) {
|
|
2037
|
-
return `${moduleDefinition.address}/paths/entrypoint?generator=${MICRO_FUNCTION_GENERATOR}`;
|
|
2038
|
-
}
|
|
2039
|
-
};
|
|
2040
|
-
|
|
2041
|
-
// src/plugins/generate-micro-function/generate-micro-function.plugin.ts
|
|
2042
|
-
var GenerateMicroFunctionPlugin = class _GenerateMicroFunctionPlugin {
|
|
2043
|
-
microFunctionGenerator = new MicroFunctionGenerator();
|
|
2044
|
-
requestGenerator = new RequestGenerator();
|
|
2045
|
-
apply(compiler) {
|
|
2046
|
-
if (MetadataStorage3.has(compiler)) return;
|
|
2047
|
-
_GenerateMicroFunctionPlugin.register(compiler);
|
|
2048
|
-
compiler.hooks.compile.tapPromise(_GenerateMicroFunctionPlugin.name, async (task) => {
|
|
2049
|
-
const artifacts = [
|
|
2050
|
-
...await this.requestGenerator.compile(compiler, task),
|
|
2051
|
-
...await this.microFunctionGenerator.compile(compiler, task)
|
|
2052
|
-
];
|
|
2053
|
-
compiler.context.artifacts.push(...artifacts);
|
|
2054
|
-
});
|
|
2055
|
-
}
|
|
2056
|
-
static register(compiler) {
|
|
2057
|
-
if (!MetadataStorage3.has(compiler)) {
|
|
2058
|
-
MetadataStorage3.set(compiler, {
|
|
2059
|
-
hooks: {
|
|
2060
|
-
afterEntrypointArtifactGenerated: new import_tapable2.AsyncSeriesWaterfallHook(["artifact", "task"]),
|
|
2061
|
-
afterMicroFunctionArtifactGenerated: new import_tapable2.AsyncSeriesWaterfallHook(["artifact", "operationDefinition", "task"])
|
|
2062
|
-
}
|
|
2063
|
-
});
|
|
2064
|
-
}
|
|
2065
|
-
return MetadataStorage3.get(compiler);
|
|
2066
|
-
}
|
|
2067
|
-
static of(compiler) {
|
|
2068
|
-
return this.register(compiler);
|
|
2069
|
-
}
|
|
2070
|
-
};
|
|
2071
|
-
|
|
2072
|
-
// src/plugins/generate-nestjs-module/generate-nestjs-module.ts
|
|
2073
|
-
var import_tapable3 = require("tapable");
|
|
2074
|
-
|
|
2075
|
-
// src/plugins/generate-nestjs-module/generators/nestjs-module.generator.ts
|
|
2076
|
-
var changeCase7 = __toESM(require("change-case"), 1);
|
|
2077
|
-
|
|
2078
|
-
// src/plugins/chinese-to-pinyin/chinese-to-pinyin.plugin.ts
|
|
2079
|
-
var import_swagger_fix = require("swagger-fix");
|
|
2080
|
-
|
|
2081
|
-
// src/plugins/download-http-file/constants/metadata-storage.ts
|
|
2082
|
-
var MetadataStorage8 = /* @__PURE__ */ new WeakMap();
|
|
2083
|
-
|
|
2084
|
-
// src/plugins/download-http-file/download-http-file.plugin.ts
|
|
2085
|
-
var DownloadHttpFilePlugin = class _DownloadHttpFilePlugin {
|
|
2086
|
-
apply(compiler) {
|
|
2087
|
-
if (MetadataStorage8.has(compiler)) return;
|
|
2088
|
-
_DownloadHttpFilePlugin.register(compiler);
|
|
2089
|
-
compiler.hooks.download.tapPromise(_DownloadHttpFilePlugin.name, async (address, task) => {
|
|
2090
|
-
const { url } = address;
|
|
2091
|
-
if (!url.startsWith("http://") && !url.startsWith("https://")) return void 0;
|
|
2092
|
-
const content = await this.download(address);
|
|
2093
|
-
const spec = this.deserialize(content);
|
|
2094
|
-
return JSON.stringify(spec);
|
|
2095
|
-
});
|
|
2096
|
-
}
|
|
2097
|
-
async download(address) {
|
|
2098
|
-
const { url, headers } = address;
|
|
2099
|
-
try {
|
|
2100
|
-
const res = await fetch(url, { headers });
|
|
2101
|
-
if (res.status >= 400) throw new Error(`failed with status code ${res.status}`);
|
|
2102
|
-
return await res.text();
|
|
2103
|
-
} catch (e) {
|
|
2104
|
-
if (e instanceof Error) {
|
|
2105
|
-
e.message = `Unable get the openapi/swagger file from ${url}: ${e.message}`;
|
|
2106
|
-
}
|
|
2107
|
-
throw e;
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
deserialize(content) {
|
|
2111
|
-
const json = JSON.parse(content);
|
|
2112
|
-
const spec = OpenapiUtils.to3_1(json);
|
|
2113
|
-
return spec;
|
|
2114
|
-
}
|
|
2115
|
-
static register(compiler) {
|
|
2116
|
-
if (!MetadataStorage8.has(compiler)) {
|
|
2117
|
-
MetadataStorage8.set(compiler, {
|
|
2118
|
-
hooks: {}
|
|
2119
|
-
});
|
|
2120
|
-
}
|
|
2121
|
-
return MetadataStorage8.get(compiler);
|
|
2122
|
-
}
|
|
2123
|
-
static of(compiler) {
|
|
2124
|
-
return this.register(compiler);
|
|
2125
|
-
}
|
|
2126
|
-
};
|
|
2127
|
-
|
|
2128
|
-
// src/plugins/download-local-file/download-local-file.plugin.ts
|
|
2129
|
-
var path9 = __toESM(require("path"), 1);
|
|
2130
|
-
var fs3 = __toESM(require("fs/promises"), 1);
|
|
2131
|
-
var yaml = __toESM(require("js-yaml"), 1);
|
|
2132
|
-
var import_url = require("url");
|
|
2133
|
-
|
|
2134
|
-
// src/plugins/download-local-file/constants/metadata-storage.ts
|
|
2135
|
-
var MetadataStorage9 = /* @__PURE__ */ new WeakMap();
|
|
2136
|
-
|
|
2137
|
-
// src/plugins/download-local-file/download-local-file.plugin.ts
|
|
2138
|
-
var DownloadLocalFilePlugin = class _DownloadLocalFilePlugin {
|
|
2139
|
-
apply(compiler) {
|
|
2140
|
-
if (MetadataStorage9.has(compiler)) return;
|
|
2141
|
-
_DownloadLocalFilePlugin.register(compiler);
|
|
2142
|
-
compiler.hooks.download.tapPromise(_DownloadLocalFilePlugin.name, async (address, task) => {
|
|
2143
|
-
const { url, encoding } = address;
|
|
2144
|
-
if (!url.startsWith("file://")) return void 0;
|
|
2145
|
-
const filepath = (0, import_url.fileURLToPath)(url);
|
|
2146
|
-
const fileExt = path9.extname(filepath);
|
|
2147
|
-
const content = await fs3.readFile(filepath, encoding);
|
|
2148
|
-
const str = typeof content === "string" ? content : content.toString(encoding);
|
|
2149
|
-
if ([".yml", ".yaml"].includes(fileExt)) {
|
|
2150
|
-
const value = yaml.load(str);
|
|
2151
|
-
return JSON.stringify(OpenapiUtils.to3_1(value));
|
|
2152
|
-
} else if (fileExt === ".json") {
|
|
2153
|
-
return JSON.stringify(OpenapiUtils.to3_1(JSON.parse(str)));
|
|
2154
50
|
}
|
|
2155
|
-
});
|
|
2156
|
-
}
|
|
2157
|
-
static register(compiler) {
|
|
2158
|
-
if (!MetadataStorage9.has(compiler)) {
|
|
2159
|
-
MetadataStorage9.set(compiler, {
|
|
2160
|
-
hooks: {}
|
|
2161
|
-
});
|
|
2162
51
|
}
|
|
2163
|
-
return MetadataStorage9.get(compiler);
|
|
2164
52
|
}
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
}
|
|
2168
|
-
};
|
|
2169
|
-
|
|
2170
|
-
// src/plugins/shaking/shaking.plugin.ts
|
|
2171
|
-
var import_openapi_shaking = require("@opendoc/openapi-shaking");
|
|
2172
|
-
|
|
2173
|
-
// src/plugins/shaking/constants/metadata-storage.ts
|
|
2174
|
-
var MetadataStorage10 = /* @__PURE__ */ new WeakMap();
|
|
2175
|
-
|
|
2176
|
-
// src/plugins/shaking/shaking.plugin.ts
|
|
2177
|
-
var ShakingPlugin = class _ShakingPlugin {
|
|
2178
|
-
apply(compiler) {
|
|
2179
|
-
if (MetadataStorage10.has(compiler)) return;
|
|
2180
|
-
_ShakingPlugin.register(compiler);
|
|
2181
|
-
compiler.hooks.beforeCompile.tap(_ShakingPlugin.name, (task) => {
|
|
2182
|
-
const matcher = compiler.context.matcher;
|
|
2183
|
-
const documents = compiler.context.documents;
|
|
2184
|
-
compiler.context.documents = documents.map((document) => this.shaking(compiler, document)).filter((document) => !document.isEmpty()).filter((document) => !matcher.isModuleIgnored(document.module));
|
|
2185
|
-
});
|
|
2186
|
-
}
|
|
2187
|
-
shaking(compiler, document) {
|
|
2188
|
-
const rc = compiler.context.rc;
|
|
2189
|
-
const matcher = compiler.context.matcher;
|
|
2190
|
-
const isAccepted = (pathname, method, operation) => {
|
|
2191
|
-
if (!SupportedMethods.includes(method)) return false;
|
|
2192
|
-
return !matcher.isOperationIgnored(new OperationDefinition({
|
|
2193
|
-
method,
|
|
2194
|
-
pathname,
|
|
2195
|
-
operation,
|
|
2196
|
-
module: document.module,
|
|
2197
|
-
document
|
|
2198
|
-
}));
|
|
2199
|
-
};
|
|
2200
|
-
const sharkedSwagger = (0, import_openapi_shaking.openapiShakingSync)(
|
|
2201
|
-
document.specification,
|
|
2202
|
-
isAccepted,
|
|
2203
|
-
{ tolerant: rc.tolerant }
|
|
2204
|
-
);
|
|
2205
|
-
return new ApiDocumentV3_1(
|
|
2206
|
-
sharkedSwagger,
|
|
2207
|
-
new ModuleDefinition(
|
|
2208
|
-
document.module.name,
|
|
2209
|
-
{
|
|
2210
|
-
url: `memory://${document.module.name}.v3_1.sharked.json`,
|
|
2211
|
-
headers: {},
|
|
2212
|
-
encoding: "utf8"
|
|
2213
|
-
}
|
|
2214
|
-
)
|
|
2215
|
-
);
|
|
2216
|
-
}
|
|
2217
|
-
static register(compiler) {
|
|
2218
|
-
if (!MetadataStorage10.has(compiler)) {
|
|
2219
|
-
MetadataStorage10.set(compiler, {
|
|
2220
|
-
hooks: {}
|
|
2221
|
-
});
|
|
2222
|
-
}
|
|
2223
|
-
return MetadataStorage10.get(compiler);
|
|
2224
|
-
}
|
|
2225
|
-
static of(compiler) {
|
|
2226
|
-
return this.register(compiler);
|
|
2227
|
-
}
|
|
2228
|
-
};
|
|
2229
|
-
|
|
2230
|
-
// src/plugins/terminal-select/utils/select-operation-definitions.ts
|
|
2231
|
-
var import_inquirer_select_pro = require("inquirer-select-pro");
|
|
2232
|
-
var import_prompt_adapter_inquirer = require("@listr2/prompt-adapter-inquirer");
|
|
2233
|
-
async function selectOperationDefinitions(task, operationDefinitions) {
|
|
2234
|
-
const selectedOperationDefinitions = await task.prompt(import_prompt_adapter_inquirer.ListrInquirerPromptAdapter).run(
|
|
2235
|
-
import_inquirer_select_pro.select,
|
|
2236
|
-
{
|
|
2237
|
-
message: "Select Pathname",
|
|
2238
|
-
defaultValue: [],
|
|
2239
|
-
options: (input) => {
|
|
2240
|
-
const items = operationDefinitions.map((op) => ({ name: `${op.module.name} ${op.method.toUpperCase()} ${op.pathname}`, value: op }));
|
|
2241
|
-
if (!input) return items;
|
|
2242
|
-
const keys2 = input.trim().toLowerCase().split(/\s+/);
|
|
2243
|
-
return items.filter((i) => {
|
|
2244
|
-
const name = i.name.toLowerCase();
|
|
2245
|
-
return keys2.every((q) => name.includes(q));
|
|
2246
|
-
});
|
|
2247
|
-
}
|
|
2248
|
-
}
|
|
2249
|
-
);
|
|
2250
|
-
return selectedOperationDefinitions;
|
|
53
|
+
await scan(dir);
|
|
54
|
+
return results;
|
|
2251
55
|
}
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
// src/plugins/terminal-select/terminal-select.plugin.ts
|
|
2257
|
-
var TerminalSelectPlugin = class _TerminalSelectPlugin {
|
|
2258
|
-
constructor(options) {
|
|
2259
|
-
this.options = options;
|
|
2260
|
-
}
|
|
2261
|
-
apply(compiler) {
|
|
2262
|
-
if (MetadataStorage11.has(compiler)) return;
|
|
2263
|
-
_TerminalSelectPlugin.register(compiler);
|
|
2264
|
-
compiler.hooks.afterDownload.tapPromise(_TerminalSelectPlugin.name, async (task) => {
|
|
2265
|
-
const context = compiler.context;
|
|
2266
|
-
const matcher = context.matcher;
|
|
2267
|
-
const documents = context.documents;
|
|
2268
|
-
const operationDefinitions = documents.flatMap((document) => document.operations);
|
|
2269
|
-
const selectedOperationDefinitions = await selectOperationDefinitions(task, operationDefinitions);
|
|
2270
|
-
if (this.options.clear) {
|
|
2271
|
-
matcher.append({
|
|
2272
|
-
persist: false,
|
|
2273
|
-
ignore: true,
|
|
2274
|
-
moduleName: "*",
|
|
2275
|
-
operationMethod: "*",
|
|
2276
|
-
operationPathname: "*"
|
|
2277
|
-
});
|
|
2278
|
-
}
|
|
2279
|
-
for (const op of selectedOperationDefinitions) {
|
|
2280
|
-
matcher.append({
|
|
2281
|
-
persist: !!this.options.persist,
|
|
2282
|
-
ignore: this.options.mode === "add",
|
|
2283
|
-
moduleName: op.module.name,
|
|
2284
|
-
operationMethod: op.method,
|
|
2285
|
-
operationPathname: op.pathname
|
|
2286
|
-
});
|
|
2287
|
-
}
|
|
2288
|
-
});
|
|
2289
|
-
}
|
|
2290
|
-
static register(compiler) {
|
|
2291
|
-
if (!MetadataStorage11.has(compiler)) {
|
|
2292
|
-
MetadataStorage11.set(compiler, {
|
|
2293
|
-
hooks: {}
|
|
2294
|
-
});
|
|
2295
|
-
}
|
|
2296
|
-
return MetadataStorage11.get(compiler);
|
|
2297
|
-
}
|
|
2298
|
-
static of(compiler) {
|
|
2299
|
-
return this.register(compiler);
|
|
2300
|
-
}
|
|
2301
|
-
};
|
|
2302
|
-
|
|
2303
|
-
// src/plugins/initialize/initialize.plugin.ts
|
|
2304
|
-
var R22 = __toESM(require("ramda"), 1);
|
|
2305
|
-
var InitializePlugin = class _InitializePlugin {
|
|
2306
|
-
constructor(options) {
|
|
2307
|
-
this.options = options;
|
|
56
|
+
async function scanAllFiles(outdir) {
|
|
57
|
+
const absoluteOutdir = path.resolve(outdir);
|
|
58
|
+
if (!await _fsextra2.default.exists(absoluteOutdir)) {
|
|
59
|
+
return [];
|
|
2308
60
|
}
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
];
|
|
2315
|
-
if (this.options.build) {
|
|
2316
|
-
plugins.push(new ShakingPlugin());
|
|
2317
|
-
}
|
|
2318
|
-
if (this.options.interactive) {
|
|
2319
|
-
plugins.push(
|
|
2320
|
-
new TerminalSelectPlugin(
|
|
2321
|
-
typeof this.options.interactive === "object" ? this.options.interactive : { mode: "except" }
|
|
2322
|
-
)
|
|
2323
|
-
);
|
|
2324
|
-
}
|
|
2325
|
-
const rc = compiler.context.rc;
|
|
2326
|
-
plugins.push(
|
|
2327
|
-
...R22.unnest(
|
|
2328
|
-
(rc.translators || []).map((translator) => {
|
|
2329
|
-
const plugins2 = translator.apply();
|
|
2330
|
-
return plugins2;
|
|
2331
|
-
})
|
|
2332
|
-
)
|
|
2333
|
-
);
|
|
2334
|
-
if (rc.plugins && rc.plugins.length) {
|
|
2335
|
-
plugins.push(...rc.plugins);
|
|
2336
|
-
}
|
|
2337
|
-
for (const plugin of plugins) {
|
|
2338
|
-
plugin.apply(compiler);
|
|
2339
|
-
}
|
|
2340
|
-
});
|
|
2341
|
-
if (this.options.includes && this.options.includes.length) {
|
|
2342
|
-
const modulesIncludes = this.options.includes;
|
|
2343
|
-
compiler.hooks.afterSetup.tap(_InitializePlugin.name, (task) => {
|
|
2344
|
-
const rc = compiler.context.rc;
|
|
2345
|
-
const matcher = compiler.context.matcher;
|
|
2346
|
-
const notExistModules = modulesIncludes.filter((moduleName) => !(moduleName in rc.modules));
|
|
2347
|
-
if (notExistModules.length) {
|
|
2348
|
-
throw new Error(`Cannot find module(s) ${notExistModules.join(", ")} in config file.`);
|
|
2349
|
-
}
|
|
2350
|
-
const ignoredModules = R22.difference(R22.keys(rc.modules), modulesIncludes);
|
|
2351
|
-
for (const moduleName of ignoredModules) {
|
|
2352
|
-
matcher.append({
|
|
2353
|
-
persist: false,
|
|
2354
|
-
ignore: true,
|
|
2355
|
-
moduleName,
|
|
2356
|
-
operationMethod: "*",
|
|
2357
|
-
operationPathname: "*"
|
|
2358
|
-
});
|
|
2359
|
-
}
|
|
2360
|
-
});
|
|
2361
|
-
}
|
|
2362
|
-
}
|
|
2363
|
-
};
|
|
2364
|
-
|
|
2365
|
-
// src/plugins/overwrite-query-options/overwrite-query-options.plugin.ts
|
|
2366
|
-
var QsArrayFormatUnion = Object.values(QsArrayFormat);
|
|
2367
|
-
|
|
2368
|
-
// src/translators/micro-function.translator.ts
|
|
2369
|
-
var MicroFunctionTranslator = class {
|
|
2370
|
-
apply() {
|
|
2371
|
-
return [
|
|
2372
|
-
new GenerateDeclarationPlugin(),
|
|
2373
|
-
new GenerateMicroFunctionPlugin()
|
|
2374
|
-
];
|
|
2375
|
-
}
|
|
2376
|
-
};
|
|
2377
|
-
|
|
2378
|
-
// src/compiler/tasks/setup/index.ts
|
|
2379
|
-
var explore = (0, import_cosmiconfig.cosmiconfig)("keq");
|
|
2380
|
-
function main(compiler, options) {
|
|
2381
|
-
return {
|
|
2382
|
-
task: async (context, task) => {
|
|
2383
|
-
const result = options?.config ? await explore.load(options.config) : await explore.search();
|
|
2384
|
-
if (!result || "isEmpty" in result && result.isEmpty) {
|
|
2385
|
-
throw new Error("Cannot find config file.");
|
|
2386
|
-
}
|
|
2387
|
-
const rc = parseRuntimeConfig(result.config);
|
|
2388
|
-
if (options?.debug) {
|
|
2389
|
-
await import_fs_extra2.default.ensureDir(".keq");
|
|
2390
|
-
rc.debug = true;
|
|
2391
|
-
}
|
|
2392
|
-
rc.tolerant = Boolean(rc.tolerant);
|
|
2393
|
-
if (!rc.translators || !rc.translators.length) {
|
|
2394
|
-
rc.translators = [new MicroFunctionTranslator()];
|
|
2395
|
-
}
|
|
2396
|
-
const packageJsonInfo = findNearestPackageJson();
|
|
2397
|
-
if (packageJsonInfo) {
|
|
2398
|
-
const moduleSystem = getProjectModuleSystem(packageJsonInfo);
|
|
2399
|
-
rc.esm = moduleSystem === "esm";
|
|
2400
|
-
}
|
|
2401
|
-
context.rc = rc;
|
|
2402
|
-
let matcher = new IgnoreMatcher([]);
|
|
2403
|
-
if (result.filepath) {
|
|
2404
|
-
const ignoreFilepath = import_path.default.resolve(import_path.default.dirname(result.filepath), ".keqignore");
|
|
2405
|
-
if (await import_fs_extra2.default.exists(ignoreFilepath)) {
|
|
2406
|
-
matcher = await IgnoreMatcher.read(ignoreFilepath);
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
const ignoreRules = options.ignore === false ? [] : options.ignore?.rules || [];
|
|
2410
|
-
for (const rule of ignoreRules) {
|
|
2411
|
-
matcher.append({
|
|
2412
|
-
persist: !!rule.persist,
|
|
2413
|
-
ignore: rule.ignore,
|
|
2414
|
-
moduleName: rule.moduleName,
|
|
2415
|
-
operationMethod: rule.operationMethod,
|
|
2416
|
-
operationPathname: rule.operationPathname
|
|
2417
|
-
});
|
|
2418
|
-
}
|
|
2419
|
-
context.matcher = matcher;
|
|
2420
|
-
await compiler.hooks.setup.promise(task);
|
|
2421
|
-
}
|
|
2422
|
-
};
|
|
2423
|
-
}
|
|
2424
|
-
function createSetupTask(compiler, options) {
|
|
2425
|
-
return {
|
|
2426
|
-
title: "Setup",
|
|
2427
|
-
enabled: options?.enabled,
|
|
2428
|
-
skip: options?.skip,
|
|
2429
|
-
task: (context, task) => task.newListr(
|
|
2430
|
-
[
|
|
2431
|
-
main(compiler, options),
|
|
2432
|
-
{
|
|
2433
|
-
task: (context2, task2) => compiler.hooks.afterSetup.promise(task2)
|
|
2434
|
-
}
|
|
2435
|
-
],
|
|
2436
|
-
{
|
|
2437
|
-
concurrent: false
|
|
2438
|
-
}
|
|
2439
|
-
)
|
|
2440
|
-
};
|
|
2441
|
-
}
|
|
2442
|
-
|
|
2443
|
-
// src/compiler/tasks/download/index.ts
|
|
2444
|
-
var import_listr2 = require("listr2");
|
|
2445
|
-
var import_openapi_parser2 = require("@scalar/openapi-parser");
|
|
2446
|
-
function main2(compiler, options) {
|
|
2447
|
-
return {
|
|
2448
|
-
task: (context, task) => {
|
|
2449
|
-
if (!context.rc || !context.matcher) {
|
|
2450
|
-
throw new Error("Please run setup task first.");
|
|
2451
|
-
}
|
|
2452
|
-
const rc = context.rc;
|
|
2453
|
-
const matcher = context.matcher;
|
|
2454
|
-
context.documents = [];
|
|
2455
|
-
return task.newListr(
|
|
2456
|
-
Object.entries(rc.modules).map(([moduleName, address]) => new ModuleDefinition(moduleName, address)).map((moduleDefinition) => ({
|
|
2457
|
-
title: moduleDefinition.name,
|
|
2458
|
-
task: async (ctx, task2) => {
|
|
2459
|
-
if (options?.skipIgnoredModules && matcher.isModuleIgnored(moduleDefinition)) {
|
|
2460
|
-
task2.skip(`(${moduleDefinition.name}) is ignored`);
|
|
2461
|
-
return;
|
|
2462
|
-
}
|
|
2463
|
-
task2.output = `Downloaded from ${moduleDefinition.address.url}`;
|
|
2464
|
-
const content = await compiler.hooks.download.promise(moduleDefinition.address, moduleDefinition, task2);
|
|
2465
|
-
if (!content) {
|
|
2466
|
-
throw new Exception(moduleDefinition, `Cannot download document from ${moduleDefinition.address.url}`);
|
|
2467
|
-
}
|
|
2468
|
-
const spec = JSON.parse(content);
|
|
2469
|
-
const { valid, errors } = await (0, import_openapi_parser2.validate)(spec);
|
|
2470
|
-
if (!valid) {
|
|
2471
|
-
const message = `${moduleDefinition.name} module openapi/swagger file does not conform to the openapi specifications or have grammatical errors, which may cause unexpected errors:
|
|
2472
|
-
${errors?.map((e) => ` - ${e.message}`).join("\n")}`;
|
|
2473
|
-
task2.output = message;
|
|
2474
|
-
}
|
|
2475
|
-
OpenapiUtils.dereferenceOperation(spec);
|
|
2476
|
-
const document = new ApiDocumentV3_1(
|
|
2477
|
-
spec,
|
|
2478
|
-
moduleDefinition
|
|
2479
|
-
);
|
|
2480
|
-
ctx.documents?.push(document);
|
|
2481
|
-
}
|
|
2482
|
-
})),
|
|
2483
|
-
{
|
|
2484
|
-
concurrent: true,
|
|
2485
|
-
exitOnError: false,
|
|
2486
|
-
collectErrors: "minimal",
|
|
2487
|
-
rendererOptions: {
|
|
2488
|
-
collapseSubtasks: false,
|
|
2489
|
-
// collapseSkips: false,
|
|
2490
|
-
suffixSkips: true,
|
|
2491
|
-
timer: import_listr2.PRESET_TIMER
|
|
2492
|
-
}
|
|
2493
|
-
}
|
|
2494
|
-
);
|
|
2495
|
-
}
|
|
2496
|
-
};
|
|
2497
|
-
}
|
|
2498
|
-
function createDownloadTask(compiler, options) {
|
|
2499
|
-
return {
|
|
2500
|
-
title: "Download",
|
|
2501
|
-
enabled: options?.enabled,
|
|
2502
|
-
skip: options?.skip,
|
|
2503
|
-
task: (_, task) => task.newListr(
|
|
2504
|
-
[
|
|
2505
|
-
main2(compiler, options),
|
|
2506
|
-
{
|
|
2507
|
-
task: (context, task2) => compiler.hooks.afterDownload.promise(task2)
|
|
2508
|
-
}
|
|
2509
|
-
],
|
|
2510
|
-
{
|
|
2511
|
-
concurrent: false
|
|
2512
|
-
}
|
|
2513
|
-
)
|
|
2514
|
-
};
|
|
2515
|
-
}
|
|
2516
|
-
|
|
2517
|
-
// src/compiler/tasks/persist/index.ts
|
|
2518
|
-
var path11 = __toESM(require("path"), 1);
|
|
2519
|
-
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
2520
|
-
function createPersistArtifactTask() {
|
|
2521
|
-
return {
|
|
2522
|
-
title: "Write files",
|
|
2523
|
-
task: async (context, task) => {
|
|
2524
|
-
if (!context.rc) throw new Error("Please run setup task first.");
|
|
2525
|
-
if (!context.artifacts || context.artifacts.length === 0) {
|
|
2526
|
-
task.skip("No compiled artifacts to persist.");
|
|
2527
|
-
return;
|
|
2528
|
-
}
|
|
2529
|
-
const rc = context.rc;
|
|
2530
|
-
const artifacts = context.artifacts;
|
|
2531
|
-
const total = artifacts.length;
|
|
2532
|
-
let completed = 0;
|
|
2533
|
-
const files = await Promise.all(artifacts.map(async (artifact) => {
|
|
2534
|
-
const realpath = `./${path11.join(rc.outdir, artifact.filepath)}`;
|
|
2535
|
-
await import_fs_extra3.default.ensureFile(realpath);
|
|
2536
|
-
await import_fs_extra3.default.writeFile(realpath, artifact.renderer());
|
|
2537
|
-
completed += 1;
|
|
2538
|
-
task.output = `Persisted ${completed}/${total} files`;
|
|
2539
|
-
return new Asset(path11.resolve(realpath));
|
|
2540
|
-
}));
|
|
2541
|
-
context.assets = files;
|
|
2542
|
-
}
|
|
2543
|
-
};
|
|
2544
|
-
}
|
|
2545
|
-
function createPersistIgnoreTask() {
|
|
2546
|
-
return {
|
|
2547
|
-
title: "Update .keqignore",
|
|
2548
|
-
task: async (context, task) => {
|
|
2549
|
-
if (!context.matcher) throw new Error("Please run setup task first.");
|
|
2550
|
-
const matcher = context.matcher;
|
|
2551
|
-
await matcher.write(".keqignore");
|
|
2552
|
-
}
|
|
2553
|
-
};
|
|
2554
|
-
}
|
|
2555
|
-
function main3() {
|
|
2556
|
-
return {
|
|
2557
|
-
task: (context, task) => task.newListr(
|
|
2558
|
-
[
|
|
2559
|
-
createPersistArtifactTask(),
|
|
2560
|
-
createPersistIgnoreTask()
|
|
2561
|
-
],
|
|
2562
|
-
{
|
|
2563
|
-
concurrent: true,
|
|
2564
|
-
rendererOptions: {
|
|
2565
|
-
collapseSubtasks: true
|
|
2566
|
-
}
|
|
2567
|
-
}
|
|
2568
|
-
)
|
|
2569
|
-
};
|
|
2570
|
-
}
|
|
2571
|
-
function createPersistTask(compiler, options) {
|
|
2572
|
-
return {
|
|
2573
|
-
title: "Persist",
|
|
2574
|
-
enabled: options?.enabled,
|
|
2575
|
-
skip: options?.skip,
|
|
2576
|
-
task: (context, task) => task.newListr(
|
|
2577
|
-
[
|
|
2578
|
-
main3(),
|
|
2579
|
-
{
|
|
2580
|
-
task: (context2, task2) => compiler.hooks.afterPersist.promise(task2)
|
|
2581
|
-
}
|
|
2582
|
-
],
|
|
2583
|
-
{
|
|
2584
|
-
concurrent: false
|
|
2585
|
-
}
|
|
2586
|
-
)
|
|
2587
|
-
};
|
|
2588
|
-
}
|
|
2589
|
-
|
|
2590
|
-
// src/compiler/tasks/compile/index.ts
|
|
2591
|
-
function main4(compiler) {
|
|
2592
|
-
return {
|
|
2593
|
-
task: async (context, task) => {
|
|
2594
|
-
if (!context.rc) throw new Error("Please run setup task first.");
|
|
2595
|
-
if (!context.documents) throw new Error("Please run shaking task first.");
|
|
2596
|
-
context.artifacts = [];
|
|
2597
|
-
await compiler.hooks.compile.promise(task);
|
|
2598
|
-
}
|
|
2599
|
-
};
|
|
61
|
+
const files = await findAllFiles(absoluteOutdir);
|
|
62
|
+
return files.map((file) => ({
|
|
63
|
+
absolutePath: file,
|
|
64
|
+
relativePath: path.relative(absoluteOutdir, file)
|
|
65
|
+
}));
|
|
2600
66
|
}
|
|
2601
|
-
function
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
[
|
|
2608
|
-
{
|
|
2609
|
-
task: (context2, task2) => compiler.hooks.beforeCompile.promise(task2)
|
|
2610
|
-
},
|
|
2611
|
-
main4(compiler),
|
|
2612
|
-
{
|
|
2613
|
-
task: (context2, task2) => compiler.hooks.afterCompile.promise(task2)
|
|
2614
|
-
}
|
|
2615
|
-
],
|
|
2616
|
-
{
|
|
2617
|
-
concurrent: false
|
|
2618
|
-
}
|
|
2619
|
-
)
|
|
2620
|
-
};
|
|
2621
|
-
}
|
|
2622
|
-
|
|
2623
|
-
// src/compiler/intercepter/print-information.ts
|
|
2624
|
-
function proxyTaskWrapper(pluginName, task) {
|
|
2625
|
-
return new Proxy(task, {
|
|
2626
|
-
set(target, prop2, value) {
|
|
2627
|
-
if (prop2 !== "output") {
|
|
2628
|
-
return Reflect.set(target, prop2, value);
|
|
2629
|
-
}
|
|
2630
|
-
target.output = `[Plugin: ${pluginName}] ${value}`;
|
|
2631
|
-
return true;
|
|
2632
|
-
}
|
|
67
|
+
async function findInvalidFiles(outdir, validFilePaths) {
|
|
68
|
+
const allFiles = await scanAllFiles(outdir);
|
|
69
|
+
const validPathsSet = new Set(validFilePaths.map((p) => path.normalize(p)));
|
|
70
|
+
return allFiles.filter((file) => {
|
|
71
|
+
const normalizedPath = path.normalize(file.relativePath);
|
|
72
|
+
return !validPathsSet.has(normalizedPath);
|
|
2633
73
|
});
|
|
2634
74
|
}
|
|
2635
|
-
function printInformation(taskIndex) {
|
|
2636
|
-
return {
|
|
2637
|
-
register: (tap) => {
|
|
2638
|
-
const fn = tap.fn;
|
|
2639
|
-
if (tap.type === "promise") {
|
|
2640
|
-
tap.fn = (...args) => {
|
|
2641
|
-
const task = args[taskIndex];
|
|
2642
|
-
const proxyTask = proxyTaskWrapper(tap.name, task);
|
|
2643
|
-
args[taskIndex] = proxyTask;
|
|
2644
|
-
proxyTask.output = "Processing...";
|
|
2645
|
-
return fn(...args);
|
|
2646
|
-
};
|
|
2647
|
-
}
|
|
2648
|
-
if (tap.type === "sync") {
|
|
2649
|
-
tap.fn = (...args) => {
|
|
2650
|
-
const task = args[taskIndex];
|
|
2651
|
-
const proxyTask = proxyTaskWrapper(tap.name, task);
|
|
2652
|
-
args[taskIndex] = proxyTask;
|
|
2653
|
-
proxyTask.output = "Processing...";
|
|
2654
|
-
return fn(...args);
|
|
2655
|
-
};
|
|
2656
|
-
}
|
|
2657
|
-
if (tap.type === "async") {
|
|
2658
|
-
tap.fn = (...args) => {
|
|
2659
|
-
const task = args[taskIndex];
|
|
2660
|
-
const proxyTask = proxyTaskWrapper(tap.name, task);
|
|
2661
|
-
args[taskIndex] = proxyTask;
|
|
2662
|
-
proxyTask.output = "Processing...";
|
|
2663
|
-
return fn(...args);
|
|
2664
|
-
};
|
|
2665
|
-
}
|
|
2666
|
-
return tap;
|
|
2667
|
-
}
|
|
2668
|
-
};
|
|
2669
|
-
}
|
|
2670
|
-
|
|
2671
|
-
// src/compiler/intercepter/perfect-error-message.ts
|
|
2672
|
-
var R23 = __toESM(require("ramda"), 1);
|
|
2673
|
-
function perfectErrorMessage() {
|
|
2674
|
-
return {
|
|
2675
|
-
register: (tap) => {
|
|
2676
|
-
const fn = tap.fn;
|
|
2677
|
-
function prefix(err) {
|
|
2678
|
-
if (err instanceof Error) {
|
|
2679
|
-
err.message = `[Plugin: ${tap.name}] ${err.message}`;
|
|
2680
|
-
}
|
|
2681
|
-
}
|
|
2682
|
-
if (tap.type === "promise") {
|
|
2683
|
-
tap.fn = async (...args) => {
|
|
2684
|
-
try {
|
|
2685
|
-
return await fn(...args);
|
|
2686
|
-
} catch (err) {
|
|
2687
|
-
prefix(err);
|
|
2688
|
-
throw err;
|
|
2689
|
-
}
|
|
2690
|
-
};
|
|
2691
|
-
}
|
|
2692
|
-
if (tap.type === "sync") {
|
|
2693
|
-
tap.fn = (...args) => {
|
|
2694
|
-
try {
|
|
2695
|
-
return fn(...args);
|
|
2696
|
-
} catch (err) {
|
|
2697
|
-
prefix(err);
|
|
2698
|
-
throw err;
|
|
2699
|
-
}
|
|
2700
|
-
};
|
|
2701
|
-
}
|
|
2702
|
-
if (tap.type === "async") {
|
|
2703
|
-
tap.fn = (...args) => {
|
|
2704
|
-
const callback = R23.last(args);
|
|
2705
|
-
return fn(...R23.init(args), (err, result) => {
|
|
2706
|
-
prefix(err);
|
|
2707
|
-
return callback(err, result);
|
|
2708
|
-
});
|
|
2709
|
-
};
|
|
2710
|
-
}
|
|
2711
|
-
return tap;
|
|
2712
|
-
}
|
|
2713
|
-
};
|
|
2714
|
-
}
|
|
2715
|
-
|
|
2716
|
-
// src/compiler/compiler.ts
|
|
2717
|
-
var Compiler = class {
|
|
2718
|
-
constructor(options) {
|
|
2719
|
-
this.options = options;
|
|
2720
|
-
for (const hook of Object.values(this.hooks)) {
|
|
2721
|
-
hook.intercept(perfectErrorMessage());
|
|
2722
|
-
}
|
|
2723
|
-
this.hooks.afterSetup.intercept(printInformation(0));
|
|
2724
|
-
this.hooks.afterPersist.intercept(printInformation(0));
|
|
2725
|
-
new InitializePlugin({
|
|
2726
|
-
build: options.build,
|
|
2727
|
-
interactive: options.interactive,
|
|
2728
|
-
includes: options.includes
|
|
2729
|
-
}).apply(this);
|
|
2730
|
-
}
|
|
2731
|
-
context = {};
|
|
2732
|
-
hooks = {
|
|
2733
|
-
setup: new import_tapable4.AsyncParallelHook(["task"]),
|
|
2734
|
-
afterSetup: new import_tapable4.AsyncSeriesHook(["task"]),
|
|
2735
|
-
beforeDownload: new import_tapable4.AsyncSeriesHook(["task"]),
|
|
2736
|
-
download: new import_tapable4.AsyncSeriesBailHook(["address", "moduleDefinition", "task"]),
|
|
2737
|
-
afterDownload: new import_tapable4.AsyncSeriesHook(["task"]),
|
|
2738
|
-
beforeCompile: new import_tapable4.AsyncSeriesHook(["task"]),
|
|
2739
|
-
compile: new import_tapable4.AsyncParallelHook(["task"]),
|
|
2740
|
-
afterCompile: new import_tapable4.AsyncSeriesHook(["task"]),
|
|
2741
|
-
beforePersist: new import_tapable4.AsyncSeriesHook(["task"]),
|
|
2742
|
-
persist: new import_tapable4.AsyncParallelHook(["task"]),
|
|
2743
|
-
afterPersist: new import_tapable4.AsyncSeriesHook(["task"]),
|
|
2744
|
-
done: new import_tapable4.SyncHook()
|
|
2745
|
-
};
|
|
2746
|
-
async run() {
|
|
2747
|
-
const options = this.options;
|
|
2748
|
-
const tasks = new import_listr22.Listr(
|
|
2749
|
-
[
|
|
2750
|
-
createSetupTask(this, options),
|
|
2751
|
-
createDownloadTask(this, { skipIgnoredModules: !options.interactive }),
|
|
2752
|
-
createCompileTask(this, { enabled: !!options.build }),
|
|
2753
|
-
createPersistTask(this)
|
|
2754
|
-
],
|
|
2755
|
-
{
|
|
2756
|
-
concurrent: false,
|
|
2757
|
-
renderer: "default",
|
|
2758
|
-
rendererOptions: {
|
|
2759
|
-
suffixSkips: true,
|
|
2760
|
-
collapseSubtasks: false,
|
|
2761
|
-
collapseErrors: false
|
|
2762
|
-
}
|
|
2763
|
-
}
|
|
2764
|
-
);
|
|
2765
|
-
await tasks.run(this.context);
|
|
2766
|
-
await this.hooks.done.promise();
|
|
2767
|
-
}
|
|
2768
|
-
};
|
|
2769
75
|
|
|
2770
76
|
// src/cli.ts
|
|
2771
|
-
if (
|
|
77
|
+
if (_semver2.default.lt(process.version, "20.0.0")) {
|
|
2772
78
|
throw new Error("Node.js version must be greater than 20");
|
|
2773
79
|
}
|
|
2774
|
-
var program = new
|
|
80
|
+
var program = new (0, _commander.Command)();
|
|
2775
81
|
program.command("build").option("-c --config <config>", "The keq-cli config file").option("--module <modules...>", "Filter module(s) to generate").option("--debug", "Print debug information").option("--tolerant", "Tolerate wrong swagger/openapi structure").option("-i --interactive", "Interactive select the scope of generation").action(async (options) => {
|
|
2776
|
-
const compiler = new Compiler({
|
|
82
|
+
const compiler = new (0, _chunkJX74ZR2Ocjs.Compiler)({
|
|
2777
83
|
build: true,
|
|
84
|
+
persist: true,
|
|
2778
85
|
config: options.config,
|
|
2779
86
|
includes: options.module,
|
|
2780
87
|
debug: !!options.debug,
|
|
@@ -2787,18 +94,19 @@ program.command("build").option("-c --config <config>", "The keq-cli config file
|
|
|
2787
94
|
await compiler.run();
|
|
2788
95
|
});
|
|
2789
96
|
program.command("ignore").addArgument(
|
|
2790
|
-
new
|
|
97
|
+
new (0, _commander.Argument)("<mode>", "The ignore mode").choices(["all", "add", "except"]).argRequired()
|
|
2791
98
|
).option("-c --config <config>", "The keq-cli config file").option("--debug", "Print debug information").option("--module <modules...>").option("--build", "Build after updating .keqignore file").addOption(
|
|
2792
|
-
new
|
|
2793
|
-
...SupportedMethods,
|
|
2794
|
-
...SupportedMethods.map((method) => method.toUpperCase())
|
|
99
|
+
new (0, _commander.Option)("--method <method>", "Only generate files of the specified operation method").choices([
|
|
100
|
+
..._chunk7HHTHYRAcjs.SupportedMethods,
|
|
101
|
+
..._chunk7HHTHYRAcjs.SupportedMethods.map((method) => method.toUpperCase())
|
|
2795
102
|
])
|
|
2796
103
|
).option("--pathname <pathnames>", "Only generate files of the specified operation pathname").option("-i --interactive", "Interactive select the scope of generation").action(async (mode, options) => {
|
|
2797
104
|
let compiler;
|
|
2798
105
|
if (mode === "all") {
|
|
2799
106
|
if (options.build) throw new Error("'--build' cannot be used with 'all' mode");
|
|
2800
|
-
compiler = new Compiler({
|
|
107
|
+
compiler = new (0, _chunkJX74ZR2Ocjs.Compiler)({
|
|
2801
108
|
build: false,
|
|
109
|
+
persist: true,
|
|
2802
110
|
config: options.config,
|
|
2803
111
|
includes: options.module,
|
|
2804
112
|
debug: !!options.debug,
|
|
@@ -2818,8 +126,9 @@ program.command("ignore").addArgument(
|
|
|
2818
126
|
if (options.method) throw new Error("'--method' cannot be used with '--interactive'");
|
|
2819
127
|
if (options.pathname) throw new Error("'--pathname' cannot be used with '--interactive'");
|
|
2820
128
|
}
|
|
2821
|
-
compiler = new Compiler({
|
|
129
|
+
compiler = new (0, _chunkJX74ZR2Ocjs.Compiler)({
|
|
2822
130
|
build: !!options.build,
|
|
131
|
+
persist: true,
|
|
2823
132
|
config: options.config,
|
|
2824
133
|
includes: options.module,
|
|
2825
134
|
debug: !!options.debug,
|
|
@@ -2833,8 +142,9 @@ program.command("ignore").addArgument(
|
|
|
2833
142
|
throw new Error("at least one of '-i --interactive', '--method' or '--pathname' must be specified");
|
|
2834
143
|
}
|
|
2835
144
|
const moduleNames = options.module || ["*"];
|
|
2836
|
-
compiler = new Compiler({
|
|
145
|
+
compiler = new (0, _chunkJX74ZR2Ocjs.Compiler)({
|
|
2837
146
|
build: !!options.build,
|
|
147
|
+
persist: true,
|
|
2838
148
|
config: options.config,
|
|
2839
149
|
debug: !!options.debug,
|
|
2840
150
|
includes: options.module,
|
|
@@ -2852,7 +162,111 @@ program.command("ignore").addArgument(
|
|
|
2852
162
|
}
|
|
2853
163
|
await compiler.run();
|
|
2854
164
|
});
|
|
2855
|
-
|
|
165
|
+
program.command("list").option("-c --config <config>", "The keq-cli config file").option("--invalid", "List only invalid generated files (files not in current build)").option("--debug", "Print debug information").action(async (options) => {
|
|
166
|
+
const compiler = new (0, _chunkJX74ZR2Ocjs.Compiler)({
|
|
167
|
+
build: true,
|
|
168
|
+
persist: false,
|
|
169
|
+
silent: true,
|
|
170
|
+
config: options.config,
|
|
171
|
+
includes: [],
|
|
172
|
+
debug: !!options.debug
|
|
173
|
+
});
|
|
174
|
+
await compiler.run();
|
|
175
|
+
const context = compiler.context;
|
|
176
|
+
if (!context.rc) {
|
|
177
|
+
throw new Error("Failed to load configuration");
|
|
178
|
+
}
|
|
179
|
+
if (options.invalid) {
|
|
180
|
+
const validFilePaths = (context.artifacts || []).map((artifact) => artifact.filepath);
|
|
181
|
+
const invalidFiles = await findInvalidFiles(context.rc.outdir, validFilePaths);
|
|
182
|
+
for (const file of invalidFiles) {
|
|
183
|
+
const fullPath = `./${path2.join(context.rc.outdir, file.relativePath)}`;
|
|
184
|
+
console.log(fullPath);
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
const artifacts = context.artifacts || [];
|
|
188
|
+
for (const artifact of artifacts) {
|
|
189
|
+
const fullPath = `./${path2.join(context.rc.outdir, artifact.filepath)}`;
|
|
190
|
+
console.log(fullPath);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
program.command("apis").option("-c --config <config>", "The keq-cli config file").option("--module <modules...>", "Filter module(s) to list").addOption(
|
|
195
|
+
new (0, _commander.Option)("--includes <includes...>", "Include specific parts").choices(["operations", "components"])
|
|
196
|
+
).option("--json", "Output in JSON format").option("--debug", "Print debug information").action(async (options) => {
|
|
197
|
+
const compiler = new (0, _chunkJX74ZR2Ocjs.Compiler)({
|
|
198
|
+
build: true,
|
|
199
|
+
persist: false,
|
|
200
|
+
silent: true,
|
|
201
|
+
config: options.config,
|
|
202
|
+
includes: options.module || [],
|
|
203
|
+
debug: !!options.debug
|
|
204
|
+
});
|
|
205
|
+
await compiler.run();
|
|
206
|
+
const context = compiler.context;
|
|
207
|
+
const documents = context.documents || [];
|
|
208
|
+
const includesList = options.includes || ["operations", "components"];
|
|
209
|
+
const includeOperations = includesList.includes("operations");
|
|
210
|
+
const includeComponents = includesList.includes("components");
|
|
211
|
+
const result = documents.map((document) => {
|
|
212
|
+
const item = {
|
|
213
|
+
module: document.module.name
|
|
214
|
+
};
|
|
215
|
+
if (includeOperations) {
|
|
216
|
+
item.operations = document.operations.map((operation) => ({
|
|
217
|
+
method: operation.method.toUpperCase(),
|
|
218
|
+
path: operation.pathname,
|
|
219
|
+
operationId: operation.operationId
|
|
220
|
+
}));
|
|
221
|
+
}
|
|
222
|
+
if (includeComponents) {
|
|
223
|
+
item.components = {
|
|
224
|
+
schemas: document.schemas.map((schema) => ({
|
|
225
|
+
name: schema.name
|
|
226
|
+
}))
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
return item;
|
|
230
|
+
});
|
|
231
|
+
if (options.json) {
|
|
232
|
+
console.log(JSON.stringify(result, null, 2));
|
|
233
|
+
} else {
|
|
234
|
+
for (const item of result) {
|
|
235
|
+
console.log(`
|
|
236
|
+
Module: ${item.module}`);
|
|
237
|
+
console.log("\u2500".repeat(70));
|
|
238
|
+
if (includeOperations) {
|
|
239
|
+
console.log("\n APIs:");
|
|
240
|
+
if (!item.operations || item.operations.length === 0) {
|
|
241
|
+
console.log(" (No APIs)");
|
|
242
|
+
} else {
|
|
243
|
+
for (const operation of item.operations) {
|
|
244
|
+
const method = operation.method.padEnd(7);
|
|
245
|
+
console.log(` ${method} ${operation.path}`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (includeComponents) {
|
|
250
|
+
console.log("\n Schemas:");
|
|
251
|
+
if (!item.components || item.components.schemas.length === 0) {
|
|
252
|
+
console.log(" (No Schemas)");
|
|
253
|
+
} else {
|
|
254
|
+
for (const schema of item.components.schemas) {
|
|
255
|
+
console.log(` ${schema.name}`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const totalApis = result.reduce((sum, item) => sum + (_optionalChain([item, 'access', _ => _.operations, 'optionalAccess', _2 => _2.length]) || 0), 0);
|
|
261
|
+
const totalSchemas = result.reduce((sum, item) => sum + (_optionalChain([item, 'access', _3 => _3.components, 'optionalAccess', _4 => _4.schemas, 'access', _5 => _5.length]) || 0), 0);
|
|
262
|
+
console.log("\n" + "\u2500".repeat(70));
|
|
263
|
+
const parts = [`${result.length} modules`];
|
|
264
|
+
if (includeOperations) parts.push(`${totalApis} APIs`);
|
|
265
|
+
if (includeComponents) parts.push(`${totalSchemas} Schemas`);
|
|
266
|
+
console.log(`Total: ${parts.join(", ")}`);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
async function main() {
|
|
2856
270
|
program.on("command:*", function(operands) {
|
|
2857
271
|
throw new Error(`Unknown command '${String(operands[0])}'`);
|
|
2858
272
|
});
|
|
@@ -2862,9 +276,9 @@ async function main5() {
|
|
|
2862
276
|
if (process.argv.includes("--debug")) {
|
|
2863
277
|
console.error(err);
|
|
2864
278
|
} else {
|
|
2865
|
-
logger.error(err instanceof Error ? err.message : String(err));
|
|
279
|
+
_chunk7HHTHYRAcjs.logger.error(err instanceof Error ? err.message : String(err));
|
|
2866
280
|
}
|
|
2867
281
|
}
|
|
2868
282
|
}
|
|
2869
|
-
void
|
|
283
|
+
void main();
|
|
2870
284
|
//# sourceMappingURL=cli.cjs.map
|