@keq-request/cli 5.0.0-alpha.27 → 5.0.0-alpha.29
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 +19 -0
- package/dist/cli.cjs +1060 -1112
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1180 -1232
- package/dist/cli.js.map +1 -1
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/compiler/tasks/setup/index.d.ts.map +1 -1
- package/dist/compiler/tasks/setup/utils/index.d.ts +0 -1
- package/dist/compiler/tasks/setup/utils/index.d.ts.map +1 -1
- package/dist/compiler/tasks/setup/utils/parse-runtime-config.d.ts +3 -0
- package/dist/compiler/tasks/setup/utils/parse-runtime-config.d.ts.map +1 -0
- package/dist/compiler/types/compiler-context.d.ts +1 -1
- package/dist/compiler/types/compiler-context.d.ts.map +1 -1
- package/dist/compiler/types/compiler-hooks.d.ts +2 -1
- package/dist/compiler/types/compiler-hooks.d.ts.map +1 -1
- package/dist/define-config.d.ts +3 -0
- package/dist/define-config.d.ts.map +1 -0
- package/dist/index.cjs +1130 -1184
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1041 -1094
- package/dist/index.js.map +1 -1
- package/dist/models/module-definition.d.ts +3 -2
- package/dist/models/module-definition.d.ts.map +1 -1
- package/dist/plugins/body-fallback/constants/index.d.ts +2 -0
- package/dist/plugins/body-fallback/constants/index.d.ts.map +1 -0
- package/dist/plugins/body-fallback/constants/metadata-storage.d.ts +6 -0
- package/dist/plugins/body-fallback/constants/metadata-storage.d.ts.map +1 -0
- package/dist/plugins/body-fallback/index.d.ts +3 -0
- package/dist/plugins/body-fallback/index.d.ts.map +1 -1
- package/dist/plugins/chinese-to-pinyin/chinese-to-pinyin.plugin.d.ts +3 -0
- package/dist/plugins/chinese-to-pinyin/chinese-to-pinyin.plugin.d.ts.map +1 -1
- package/dist/plugins/chinese-to-pinyin/constants/index.d.ts +2 -0
- package/dist/plugins/chinese-to-pinyin/constants/index.d.ts.map +1 -0
- package/dist/plugins/chinese-to-pinyin/constants/metadata-storage.d.ts +6 -0
- package/dist/plugins/chinese-to-pinyin/constants/metadata-storage.d.ts.map +1 -0
- package/dist/plugins/download-http-file/constants/index.d.ts +2 -0
- package/dist/plugins/download-http-file/constants/index.d.ts.map +1 -0
- package/dist/plugins/download-http-file/constants/metadata-storage.d.ts +6 -0
- package/dist/plugins/download-http-file/constants/metadata-storage.d.ts.map +1 -0
- package/dist/plugins/download-http-file/download-http-file.plugin.d.ts +5 -2
- package/dist/plugins/download-http-file/download-http-file.plugin.d.ts.map +1 -1
- package/dist/plugins/download-local-file/constants/index.d.ts +2 -0
- package/dist/plugins/download-local-file/constants/index.d.ts.map +1 -0
- package/dist/plugins/download-local-file/constants/metadata-storage.d.ts +6 -0
- package/dist/plugins/download-local-file/constants/metadata-storage.d.ts.map +1 -0
- package/dist/plugins/download-local-file/download-local-file.plugin.d.ts +3 -0
- package/dist/plugins/download-local-file/download-local-file.plugin.d.ts.map +1 -1
- package/dist/plugins/eslint/constants/index.d.ts +2 -0
- package/dist/plugins/eslint/constants/index.d.ts.map +1 -0
- package/dist/plugins/eslint/constants/metadata-storage.d.ts +6 -0
- package/dist/plugins/eslint/constants/metadata-storage.d.ts.map +1 -0
- package/dist/plugins/eslint/eslint.plugin.d.ts +18 -0
- package/dist/plugins/eslint/eslint.plugin.d.ts.map +1 -0
- package/dist/plugins/eslint/index.d.ts +1 -14
- package/dist/plugins/eslint/index.d.ts.map +1 -1
- package/dist/plugins/generate-declaration/generate-declaration.plugin.d.ts.map +1 -1
- package/dist/plugins/generate-declaration/generators/schema-declaration/schema.generator.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/generate-nestjs-module.d.ts.map +1 -1
- package/dist/plugins/initialize/initialize.plugin.d.ts.map +1 -1
- package/dist/plugins/prettier/constants/index.d.ts +2 -0
- package/dist/plugins/prettier/constants/index.d.ts.map +1 -0
- package/dist/plugins/prettier/constants/metadata-storage.d.ts +6 -0
- package/dist/plugins/prettier/constants/metadata-storage.d.ts.map +1 -0
- package/dist/plugins/prettier/prettier.plugin.d.ts +3 -0
- package/dist/plugins/prettier/prettier.plugin.d.ts.map +1 -1
- package/dist/plugins/shaking/constants/index.d.ts +2 -0
- package/dist/plugins/shaking/constants/index.d.ts.map +1 -0
- package/dist/plugins/shaking/constants/metadata-storage.d.ts +6 -0
- package/dist/plugins/shaking/constants/metadata-storage.d.ts.map +1 -0
- package/dist/plugins/shaking/shaking.plugin.d.ts +3 -0
- package/dist/plugins/shaking/shaking.plugin.d.ts.map +1 -1
- package/dist/plugins/terminal-select/constants/index.d.ts +2 -0
- package/dist/plugins/terminal-select/constants/index.d.ts.map +1 -0
- package/dist/plugins/terminal-select/constants/metadata-storage.d.ts +6 -0
- package/dist/plugins/terminal-select/constants/metadata-storage.d.ts.map +1 -0
- package/dist/plugins/terminal-select/terminal-select.plugin.d.ts +3 -0
- package/dist/plugins/terminal-select/terminal-select.plugin.d.ts.map +1 -1
- package/dist/plugins.cjs +208 -47
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.js +208 -47
- package/dist/plugins.js.map +1 -1
- package/dist/translators/index.d.ts +3 -0
- package/dist/translators/index.d.ts.map +1 -0
- package/dist/translators/micro-function.translator.d.ts +5 -0
- package/dist/translators/micro-function.translator.d.ts.map +1 -0
- package/dist/translators/nestjs.translator.d.ts +5 -0
- package/dist/translators/nestjs.translator.d.ts.map +1 -0
- package/dist/translators.cjs +2061 -0
- package/dist/translators.cjs.map +1 -0
- package/dist/translators.js +2023 -0
- package/dist/translators.js.map +1 -0
- package/dist/types/address.d.ts +8 -0
- package/dist/types/address.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/runtime-config.d.ts +39 -8
- package/dist/types/runtime-config.d.ts.map +1 -1
- package/dist/types/translator.d.ts +5 -0
- package/dist/types/translator.d.ts.map +1 -0
- package/dist/utils/is-valid-url.d.ts +16 -0
- package/dist/utils/is-valid-url.d.ts.map +1 -0
- package/package.json +8 -3
- package/dist/compiler/tasks/setup/utils/validate-modules.d.ts +0 -2
- package/dist/compiler/tasks/setup/utils/validate-modules.d.ts.map +0 -1
- package/dist/define-keq-config.d.ts +0 -3
- package/dist/define-keq-config.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -38,20 +38,16 @@ __export(src_exports, {
|
|
|
38
38
|
ModuleDefinition: () => ModuleDefinition,
|
|
39
39
|
OperationDefinition: () => OperationDefinition,
|
|
40
40
|
QsArrayFormat: () => QsArrayFormat,
|
|
41
|
-
RuntimeConfig: () => RuntimeConfig,
|
|
42
41
|
SchemaDefinition: () => SchemaDefinition,
|
|
43
|
-
|
|
42
|
+
defineConfig: () => defineConfig
|
|
44
43
|
});
|
|
45
44
|
module.exports = __toCommonJS(src_exports);
|
|
46
45
|
|
|
47
|
-
// src/define-
|
|
48
|
-
function
|
|
46
|
+
// src/define-config.ts
|
|
47
|
+
function defineConfig(config) {
|
|
49
48
|
return config;
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
// src/types/runtime-config.ts
|
|
53
|
-
var import_typebox = require("@sinclair/typebox");
|
|
54
|
-
|
|
55
51
|
// src/constants/file-naming-style.ts
|
|
56
52
|
var FileNamingStyle = /* @__PURE__ */ ((FileNamingStyle2) => {
|
|
57
53
|
FileNamingStyle2["camelCase"] = "camelCase";
|
|
@@ -68,39 +64,6 @@ var FileNamingStyle = /* @__PURE__ */ ((FileNamingStyle2) => {
|
|
|
68
64
|
return FileNamingStyle2;
|
|
69
65
|
})(FileNamingStyle || {});
|
|
70
66
|
|
|
71
|
-
// src/types/runtime-config.ts
|
|
72
|
-
var RuntimeConfig = import_typebox.Type.Object({
|
|
73
|
-
mode: import_typebox.Type.Optional(
|
|
74
|
-
import_typebox.Type.Union([
|
|
75
|
-
import_typebox.Type.Literal("micro-function"),
|
|
76
|
-
import_typebox.Type.Literal("nestjs-module"),
|
|
77
|
-
import_typebox.Type.Literal("none")
|
|
78
|
-
], { default: "micro-function" })
|
|
79
|
-
),
|
|
80
|
-
/**
|
|
81
|
-
* Whether to generate ES Module code
|
|
82
|
-
*
|
|
83
|
-
* If not specified, the module system will be inferred from the nearest package.json "type" field
|
|
84
|
-
* or defaults to "cjs" if no package.json is found.
|
|
85
|
-
*/
|
|
86
|
-
esm: import_typebox.Type.Optional(import_typebox.Type.Boolean({ default: false })),
|
|
87
|
-
/**
|
|
88
|
-
* Output directory for generated files
|
|
89
|
-
*/
|
|
90
|
-
outdir: import_typebox.Type.String({ default: `${process.cwd()}/api` }),
|
|
91
|
-
/**
|
|
92
|
-
* File naming style for generated files
|
|
93
|
-
*/
|
|
94
|
-
fileNamingStyle: import_typebox.Type.Enum(FileNamingStyle, { default: "snakeCase" /* snakeCase */ }),
|
|
95
|
-
modules: import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.String()),
|
|
96
|
-
debug: import_typebox.Type.Optional(import_typebox.Type.Boolean({ default: false })),
|
|
97
|
-
/**
|
|
98
|
-
* Whether to tolerate wrong openapi/swagger structure
|
|
99
|
-
*/
|
|
100
|
-
tolerant: import_typebox.Type.Optional(import_typebox.Type.Boolean({ default: false })),
|
|
101
|
-
plugins: import_typebox.Type.Optional(import_typebox.Type.Array(import_typebox.Type.Any(), { default: [] }))
|
|
102
|
-
});
|
|
103
|
-
|
|
104
67
|
// src/constants/qs-array-format.ts
|
|
105
68
|
var QsArrayFormat = /* @__PURE__ */ ((QsArrayFormat2) => {
|
|
106
69
|
QsArrayFormat2["brackets"] = "brackets";
|
|
@@ -130,7 +93,6 @@ var import_tapable4 = require("tapable");
|
|
|
130
93
|
// src/compiler/tasks/setup/index.ts
|
|
131
94
|
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
132
95
|
var import_path = __toESM(require("path"), 1);
|
|
133
|
-
var import_value = require("@sinclair/typebox/value");
|
|
134
96
|
var import_cosmiconfig = require("cosmiconfig");
|
|
135
97
|
|
|
136
98
|
// src/utils/ignore-matcher.ts
|
|
@@ -224,35 +186,6 @@ var IgnoreMatcher = class _IgnoreMatcher {
|
|
|
224
186
|
}
|
|
225
187
|
};
|
|
226
188
|
|
|
227
|
-
// src/compiler/tasks/setup/utils/validate-modules.ts
|
|
228
|
-
var R2 = __toESM(require("ramda"), 1);
|
|
229
|
-
var import_validator = __toESM(require("validator"), 1);
|
|
230
|
-
function validateModules(modules) {
|
|
231
|
-
const keys2 = Object.keys(modules);
|
|
232
|
-
for (const key of keys2) {
|
|
233
|
-
if (!/^[A-Za-z_][A-Za-z0-9_$]*$/.test(key)) {
|
|
234
|
-
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.`);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
const keysGroupByLowerCase = R2.groupBy(R2.toLower, keys2);
|
|
238
|
-
for (const groupKey in keysGroupByLowerCase) {
|
|
239
|
-
const keys3 = keysGroupByLowerCase[groupKey] || [];
|
|
240
|
-
if (keys3.length > 1) {
|
|
241
|
-
throw new Error(`Module names ${keys3.map((name) => `"${name}"`).join(", ")} are case-insensitively duplicated.`);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
for (const key in modules) {
|
|
245
|
-
const address = modules[key];
|
|
246
|
-
if (import_validator.default.isURL(address, { require_host: true, require_protocol: true, protocols: ["http", "https"] })) {
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
if (/^(\/|\.\/|\.\.\/)/.test(address)) {
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
throw new Error(`Module address "${address}" of module "${key}" is not valid. It must be a URL or a local path.`);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
189
|
// src/compiler/tasks/setup/utils/find-nearest-package-json.ts
|
|
257
190
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
258
191
|
var import_node_path = __toESM(require("path"), 1);
|
|
@@ -279,80 +212,193 @@ function getProjectModuleSystem(pkgInfo) {
|
|
|
279
212
|
return "cjs";
|
|
280
213
|
}
|
|
281
214
|
|
|
282
|
-
// src/compiler/tasks/setup/
|
|
283
|
-
var
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
persist: !!rule.persist,
|
|
320
|
-
ignore: rule.ignore,
|
|
321
|
-
moduleName: rule.moduleName,
|
|
322
|
-
operationMethod: rule.operationMethod,
|
|
323
|
-
operationPathname: rule.operationPathname
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
context.matcher = matcher;
|
|
327
|
-
await compiler.hooks.setup.promise(task);
|
|
215
|
+
// src/compiler/tasks/setup/utils/parse-runtime-config.ts
|
|
216
|
+
var import_value = require("@sinclair/typebox/value");
|
|
217
|
+
|
|
218
|
+
// src/types/address.ts
|
|
219
|
+
var import_typebox = require("@sinclair/typebox");
|
|
220
|
+
var Address = import_typebox.Type.Object({
|
|
221
|
+
url: import_typebox.Type.String(),
|
|
222
|
+
headers: import_typebox.Type.Optional(import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.String(), { default: {} })),
|
|
223
|
+
encoding: import_typebox.Type.Optional(
|
|
224
|
+
import_typebox.Type.Union([
|
|
225
|
+
import_typebox.Type.Literal("utf8"),
|
|
226
|
+
import_typebox.Type.Literal("ascii")
|
|
227
|
+
], { default: "utf8" })
|
|
228
|
+
)
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// src/types/runtime-config.ts
|
|
232
|
+
var R2 = __toESM(require("ramda"), 1);
|
|
233
|
+
var import_typebox2 = require("@sinclair/typebox");
|
|
234
|
+
|
|
235
|
+
// src/utils/is-valid-url.ts
|
|
236
|
+
var URL_REGEX = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/(?:[^\s@]+@)?[^\s/:?#]*(?::\d+)?(?:\/[^\s?#]*)?(?:\?[^\s#]*)?(?:#[^\s]*)?$/;
|
|
237
|
+
function isValidURL(url) {
|
|
238
|
+
return URL_REGEX.test(url);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/types/runtime-config.ts
|
|
242
|
+
var Modules = import_typebox2.Type.Transform(
|
|
243
|
+
import_typebox2.Type.Record(
|
|
244
|
+
import_typebox2.Type.String(),
|
|
245
|
+
import_typebox2.Type.Union([import_typebox2.Type.String(), Address])
|
|
246
|
+
)
|
|
247
|
+
).Decode((value) => {
|
|
248
|
+
const keys2 = Object.keys(value);
|
|
249
|
+
for (const key of keys2) {
|
|
250
|
+
if (!/^[A-Za-z_][A-Za-z0-9_$]*$/.test(key)) {
|
|
251
|
+
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.`);
|
|
328
252
|
}
|
|
329
|
-
}
|
|
253
|
+
}
|
|
254
|
+
const keysGroupByLowerCase = R2.groupBy(R2.toLower, keys2);
|
|
255
|
+
for (const groupKey in keysGroupByLowerCase) {
|
|
256
|
+
const keys3 = keysGroupByLowerCase[groupKey] || [];
|
|
257
|
+
if (keys3.length > 1) {
|
|
258
|
+
throw new Error(`Module names ${keys3.map((name) => `"${name}"`).join(", ")} are case-insensitively duplicated.`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
for (const key in value) {
|
|
262
|
+
const url = typeof value[key] === "string" ? value[key] : value[key].url;
|
|
263
|
+
if (isValidURL(url)) continue;
|
|
264
|
+
throw new Error(`The ${JSON.stringify(url)} of module "${key}" is not a valid URL.`);
|
|
265
|
+
}
|
|
266
|
+
return R2.map(
|
|
267
|
+
(item) => typeof item !== "string" ? item : { url: item, headers: {}, encoding: "utf8" },
|
|
268
|
+
value
|
|
269
|
+
);
|
|
270
|
+
}).Encode((value) => value);
|
|
271
|
+
var RawConfig = import_typebox2.Type.Object({
|
|
272
|
+
/**
|
|
273
|
+
* Whether to generate ES Module code
|
|
274
|
+
*
|
|
275
|
+
* If not specified, the module system will be inferred from the nearest package.json "type" field
|
|
276
|
+
* or defaults to "cjs" if no package.json is found.
|
|
277
|
+
*/
|
|
278
|
+
esm: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
|
|
279
|
+
/**
|
|
280
|
+
* Output directory for generated files
|
|
281
|
+
*/
|
|
282
|
+
outdir: import_typebox2.Type.String({ default: `${process.cwd()}/api` }),
|
|
283
|
+
/**
|
|
284
|
+
* File naming style for generated files
|
|
285
|
+
*/
|
|
286
|
+
fileNamingStyle: import_typebox2.Type.Enum(FileNamingStyle, { default: "snakeCase" /* snakeCase */ }),
|
|
287
|
+
/**
|
|
288
|
+
* OpenAPI/Swagger document sources
|
|
289
|
+
*
|
|
290
|
+
* A map of module names to their document URLs or Address objects.
|
|
291
|
+
* The module name must be a valid JavaScript identifier.
|
|
292
|
+
*/
|
|
293
|
+
modules: Modules,
|
|
294
|
+
/**
|
|
295
|
+
* Enable debug mode to output detailed logs during compilation
|
|
296
|
+
*/
|
|
297
|
+
debug: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
|
|
298
|
+
/**
|
|
299
|
+
* Whether to tolerate wrong openapi/swagger structure
|
|
300
|
+
*/
|
|
301
|
+
tolerant: import_typebox2.Type.Optional(import_typebox2.Type.Boolean({ default: false })),
|
|
302
|
+
/**
|
|
303
|
+
* Translators to transform generated code
|
|
304
|
+
*
|
|
305
|
+
* Used to customize the code generation process for different frameworks or patterns.
|
|
306
|
+
* Can be a single translator or an array of translators.
|
|
307
|
+
*/
|
|
308
|
+
translators: import_typebox2.Type.Optional(
|
|
309
|
+
import_typebox2.Type.Transform(
|
|
310
|
+
import_typebox2.Type.Union([
|
|
311
|
+
import_typebox2.Type.Unsafe(import_typebox2.Type.Any()),
|
|
312
|
+
import_typebox2.Type.Array(import_typebox2.Type.Unsafe(import_typebox2.Type.Any()))
|
|
313
|
+
], { default: [] })
|
|
314
|
+
).Decode((value) => {
|
|
315
|
+
if (value === void 0) return [];
|
|
316
|
+
if (Array.isArray(value)) return value;
|
|
317
|
+
return [value];
|
|
318
|
+
}).Encode((value) => value)
|
|
319
|
+
),
|
|
320
|
+
/**
|
|
321
|
+
* Plugins to extend code generation functionality
|
|
322
|
+
*
|
|
323
|
+
* An array of plugin instances that can hook into various stages of the compilation process,
|
|
324
|
+
* such as code transformation, formatting, linting, or custom file generation.
|
|
325
|
+
*/
|
|
326
|
+
plugins: import_typebox2.Type.Optional(import_typebox2.Type.Array(import_typebox2.Type.Unsafe(import_typebox2.Type.Any()), { default: [] }))
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// src/compiler/tasks/setup/utils/parse-runtime-config.ts
|
|
330
|
+
function parseRuntimeConfig(data) {
|
|
331
|
+
try {
|
|
332
|
+
const originalPlugins = typeof data === "object" && data !== null && "plugins" in data ? data.plugins : void 0;
|
|
333
|
+
const originTranslators = typeof data === "object" && data !== null && "translators" in data ? data.translators : void 0;
|
|
334
|
+
const parsed = import_value.Value.Parse(RawConfig, data);
|
|
335
|
+
if (originalPlugins !== void 0) {
|
|
336
|
+
parsed.plugins = originalPlugins;
|
|
337
|
+
}
|
|
338
|
+
if (originTranslators !== void 0) {
|
|
339
|
+
parsed.translators = originTranslators;
|
|
340
|
+
}
|
|
341
|
+
return parsed;
|
|
342
|
+
} catch (error) {
|
|
343
|
+
if (error instanceof Error) {
|
|
344
|
+
error.message = `Invalid Config: ${error.message}`;
|
|
345
|
+
}
|
|
346
|
+
throw error;
|
|
347
|
+
}
|
|
330
348
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
)
|
|
347
|
-
};
|
|
349
|
+
|
|
350
|
+
// src/plugins/eslint/eslint.plugin.ts
|
|
351
|
+
var import_eslint = require("eslint");
|
|
352
|
+
|
|
353
|
+
// src/plugins/prettier/prettier.plugin.ts
|
|
354
|
+
var import_child_process = require("child_process");
|
|
355
|
+
var import_util = require("util");
|
|
356
|
+
var execAsync = (0, import_util.promisify)(import_child_process.exec);
|
|
357
|
+
|
|
358
|
+
// src/plugins/body-fallback/index.ts
|
|
359
|
+
var R21 = __toESM(require("ramda"), 1);
|
|
360
|
+
|
|
361
|
+
// src/utils/json-schema-utils/is-array.ts
|
|
362
|
+
function isArray(schema) {
|
|
363
|
+
return schema.type === "array";
|
|
348
364
|
}
|
|
349
365
|
|
|
350
|
-
// src/
|
|
351
|
-
|
|
352
|
-
|
|
366
|
+
// src/utils/json-schema-utils/is-mixed.ts
|
|
367
|
+
function isMixed(schema) {
|
|
368
|
+
return Array.isArray(schema.type);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// src/utils/json-schema-utils/is-non-array.ts
|
|
372
|
+
function isNonArray(schema) {
|
|
373
|
+
return typeof schema.type === "string" && schema.type !== "array";
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// src/utils/json-schema-utils/is-ref.ts
|
|
377
|
+
function isRef(schema) {
|
|
378
|
+
return "$ref" in schema;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// src/utils/json-schema-utils/index.ts
|
|
382
|
+
var JsonSchemaUtils = class {
|
|
383
|
+
static isRef = isRef;
|
|
384
|
+
static isArray = isArray;
|
|
385
|
+
static isNonArray = isNonArray;
|
|
386
|
+
static isMixed = isMixed;
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// src/plugins/generate-micro-function/generate-micro-function.plugin.ts
|
|
390
|
+
var import_tapable2 = require("tapable");
|
|
391
|
+
|
|
392
|
+
// src/plugins/generate-micro-function/constants/metadata-storage.ts
|
|
393
|
+
var MetadataStorage3 = /* @__PURE__ */ new WeakMap();
|
|
394
|
+
|
|
395
|
+
// src/plugins/generate-micro-function/generators/micro_function/micro-function.generator.ts
|
|
396
|
+
var R20 = __toESM(require("ramda"), 1);
|
|
397
|
+
var path8 = __toESM(require("path"), 1);
|
|
398
|
+
var changeCase6 = __toESM(require("change-case"), 1);
|
|
353
399
|
|
|
354
400
|
// src/models/artifact.ts
|
|
355
|
-
var
|
|
401
|
+
var path2 = __toESM(require("path"), 1);
|
|
356
402
|
|
|
357
403
|
// src/models/anchor.ts
|
|
358
404
|
var AnchorBlock = class {
|
|
@@ -438,11 +484,11 @@ var Artifact = class {
|
|
|
438
484
|
constructor(options) {
|
|
439
485
|
this.id = options.id;
|
|
440
486
|
this.filepath = options.filepath;
|
|
441
|
-
this.extensionName = options.extensionName ||
|
|
487
|
+
this.extensionName = options.extensionName || path2.extname(options.filepath);
|
|
442
488
|
this.content = options.content;
|
|
443
489
|
}
|
|
444
490
|
get dirname() {
|
|
445
|
-
return
|
|
491
|
+
return path2.dirname(this.filepath);
|
|
446
492
|
}
|
|
447
493
|
renderer() {
|
|
448
494
|
return `${HeaderComment}${this.content}`;
|
|
@@ -458,10 +504,14 @@ var ModuleDefinition = class _ModuleDefinition {
|
|
|
458
504
|
address;
|
|
459
505
|
constructor(name, address) {
|
|
460
506
|
this.name = name;
|
|
461
|
-
|
|
507
|
+
if (typeof address === "string") {
|
|
508
|
+
this.address = { url: address, headers: {}, encoding: "utf8" };
|
|
509
|
+
} else {
|
|
510
|
+
this.address = address;
|
|
511
|
+
}
|
|
462
512
|
}
|
|
463
513
|
static unknown() {
|
|
464
|
-
return new _ModuleDefinition("", "");
|
|
514
|
+
return new _ModuleDefinition("", { url: "", headers: {}, encoding: "utf8" });
|
|
465
515
|
}
|
|
466
516
|
};
|
|
467
517
|
|
|
@@ -681,8 +731,8 @@ var ApiDocumentV3_1 = class _ApiDocumentV3_1 {
|
|
|
681
731
|
}
|
|
682
732
|
isRefDefined($ref) {
|
|
683
733
|
if ($ref.startsWith("#/")) {
|
|
684
|
-
const
|
|
685
|
-
return R5.path(
|
|
734
|
+
const path12 = $ref.replace("#/", "").split("/");
|
|
735
|
+
return R5.path(path12, this.specification) !== void 0;
|
|
686
736
|
}
|
|
687
737
|
return false;
|
|
688
738
|
}
|
|
@@ -694,29 +744,264 @@ var ApiDocumentV3_1 = class _ApiDocumentV3_1 {
|
|
|
694
744
|
// src/models/asset.ts
|
|
695
745
|
var Asset = class {
|
|
696
746
|
path;
|
|
697
|
-
constructor(
|
|
698
|
-
this.path =
|
|
747
|
+
constructor(path12) {
|
|
748
|
+
this.path = path12;
|
|
699
749
|
}
|
|
700
750
|
};
|
|
701
751
|
|
|
702
|
-
// src/
|
|
703
|
-
var
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
752
|
+
// src/plugins/generate-declaration/generate-declaration.plugin.ts
|
|
753
|
+
var import_tapable = require("tapable");
|
|
754
|
+
|
|
755
|
+
// src/plugins/generate-declaration/generators/operation-declaration/operation.generator.ts
|
|
756
|
+
var path7 = __toESM(require("path"), 1);
|
|
757
|
+
var changeCase5 = __toESM(require("change-case"), 1);
|
|
758
|
+
|
|
759
|
+
// src/transformers/json-schema/comment.renderer.ts
|
|
760
|
+
var CommentRenderer = class {
|
|
761
|
+
constructor(schema) {
|
|
762
|
+
this.schema = schema;
|
|
763
|
+
}
|
|
764
|
+
render() {
|
|
765
|
+
const schema = this.schema;
|
|
766
|
+
const lines = ["/**"];
|
|
767
|
+
if (schema.description) {
|
|
768
|
+
const description = schema.description.replace("*/", "*\\/");
|
|
769
|
+
lines.push(...description.split("\n").map((line) => ` * ${line}`));
|
|
770
|
+
}
|
|
771
|
+
if (schema.deprecated) {
|
|
772
|
+
lines.push(" * @deprecated");
|
|
773
|
+
}
|
|
774
|
+
if (schema.readOnly) {
|
|
775
|
+
lines.push(" * @readonly");
|
|
776
|
+
}
|
|
777
|
+
if (schema.format) {
|
|
778
|
+
lines.push(` * @format ${schema.format}`);
|
|
779
|
+
}
|
|
780
|
+
lines.push(" */");
|
|
781
|
+
if (lines.length === 2) return "";
|
|
782
|
+
return lines.join("\n");
|
|
712
783
|
}
|
|
713
784
|
};
|
|
714
785
|
|
|
715
|
-
// src/
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
786
|
+
// src/transformers/json-schema/declaration.renderer.ts
|
|
787
|
+
var R7 = __toESM(require("ramda"), 1);
|
|
788
|
+
|
|
789
|
+
// src/utils/indent.ts
|
|
790
|
+
function indent(space, text) {
|
|
791
|
+
if (text === "") return "";
|
|
792
|
+
const indentation = " ".repeat(space);
|
|
793
|
+
return text.split("\n").map((line) => line ? `${indentation}${line}` : line).join("\n");
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// src/transformers/json-schema/reference.transformer.ts
|
|
797
|
+
var R6 = __toESM(require("ramda"), 1);
|
|
798
|
+
var ReferenceTransformer = class {
|
|
799
|
+
static toDeclaration(schema, alias2 = R6.identity) {
|
|
800
|
+
if (!schema.$ref || !schema.$ref.startsWith("#")) return `unknown /* ${schema.$ref.replace("*/", "*\\/")} */`;
|
|
801
|
+
const parts = schema.$ref.split("/");
|
|
802
|
+
return alias2(parts[parts.length - 1]) || "unknown";
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
|
|
806
|
+
// src/transformers/json-schema/declaration.renderer.ts
|
|
807
|
+
var DeclarationRenderer = class {
|
|
808
|
+
constructor(schema, options = {}) {
|
|
809
|
+
this.schema = schema;
|
|
810
|
+
this.options = options;
|
|
811
|
+
}
|
|
812
|
+
render() {
|
|
813
|
+
return this.renderSchema(this.schema);
|
|
814
|
+
}
|
|
815
|
+
renderSchema(schema) {
|
|
816
|
+
if (typeof schema === "boolean") return "unknown";
|
|
817
|
+
if (JsonSchemaUtils.isRef(schema)) return this.renderReference(schema);
|
|
818
|
+
if (JsonSchemaUtils.isMixed(schema)) return this.renderMixed(schema);
|
|
819
|
+
if (JsonSchemaUtils.isArray(schema)) return this.renderArray(schema);
|
|
820
|
+
if (schema.type === "object") return this.renderObject(schema);
|
|
821
|
+
if (schema.enum) return this.renderEnum(schema);
|
|
822
|
+
if (schema.oneOf) return this.renderOneOf(schema);
|
|
823
|
+
if (schema.anyOf) return this.renderAnyOf(schema);
|
|
824
|
+
if (schema.allOf) return this.renderAllOf(schema);
|
|
825
|
+
if (schema.type === "string") return this.renderString(schema);
|
|
826
|
+
if (schema.type === "number") return this.renderNumber(schema);
|
|
827
|
+
if (schema.type === "boolean") return this.renderBoolean(schema);
|
|
828
|
+
if (schema.type === "null") return this.renderNull(schema);
|
|
829
|
+
if (schema.type === "integer") return this.renderInteger(schema);
|
|
830
|
+
return "unknown";
|
|
831
|
+
}
|
|
832
|
+
renderMixed(schema) {
|
|
833
|
+
if (Array.isArray(schema.type)) {
|
|
834
|
+
schema.type.map((type) => ({ ...schema, type })).map((schema2) => this.renderSchema(schema2)).join(" | ");
|
|
835
|
+
}
|
|
836
|
+
return "unknown";
|
|
837
|
+
}
|
|
838
|
+
renderReference(schema) {
|
|
839
|
+
if (!this.options.referenceTransformer) {
|
|
840
|
+
return ReferenceTransformer.toDeclaration(schema);
|
|
841
|
+
}
|
|
842
|
+
return this.options.referenceTransformer(schema);
|
|
843
|
+
}
|
|
844
|
+
renderArray(schema) {
|
|
845
|
+
if (schema.items && Array.isArray(schema.items)) {
|
|
846
|
+
const items = schema.items.map((s) => this.renderSchema(s)).join(", ");
|
|
847
|
+
return `[${items}]`;
|
|
848
|
+
}
|
|
849
|
+
if (schema.items && typeof schema.items === "object") {
|
|
850
|
+
return `${this.renderSchema(schema.items)}[]`;
|
|
851
|
+
}
|
|
852
|
+
return "any[]";
|
|
853
|
+
}
|
|
854
|
+
renderObject(schema) {
|
|
855
|
+
if ((!schema.properties || R7.isEmpty(schema.properties)) && (!schema.additionalProperties || R7.isEmpty(schema.additionalProperties))) {
|
|
856
|
+
return "object";
|
|
857
|
+
}
|
|
858
|
+
const $properties = Object.entries(schema.properties || {}).map(([propertyName, propertySchema]) => {
|
|
859
|
+
let $comment = new CommentRenderer(propertySchema).render();
|
|
860
|
+
if ($comment) $comment += "\n";
|
|
861
|
+
const $key = `"${propertyName}"${schema.required?.includes(propertyName) ? "" : "?"}`;
|
|
862
|
+
const $value = this.renderSchema(propertySchema);
|
|
863
|
+
return indent(2, `${$comment}${$key}: ${$value}`);
|
|
864
|
+
});
|
|
865
|
+
if (schema.additionalProperties) {
|
|
866
|
+
const $value = schema.additionalProperties === true ? "any" : this.renderSchema(schema.additionalProperties);
|
|
867
|
+
$properties.push(indent(2, `[key: string]: ${$value}`));
|
|
868
|
+
}
|
|
869
|
+
return [
|
|
870
|
+
"{",
|
|
871
|
+
...$properties,
|
|
872
|
+
"}"
|
|
873
|
+
].join("\n");
|
|
874
|
+
}
|
|
875
|
+
renderOneOf(schema) {
|
|
876
|
+
if (!schema.oneOf) return "unknown";
|
|
877
|
+
return schema.oneOf.map((s) => this.renderSchema(s)).join(" | ");
|
|
878
|
+
}
|
|
879
|
+
renderAnyOf(schema) {
|
|
880
|
+
if (!schema.anyOf) return "unknown";
|
|
881
|
+
return schema.anyOf.map((s) => this.renderSchema(s)).join(" | ");
|
|
882
|
+
}
|
|
883
|
+
renderAllOf(schema) {
|
|
884
|
+
if (!schema.allOf) return "unknown";
|
|
885
|
+
return schema.allOf.map((s) => this.renderSchema(s)).join(" & ");
|
|
886
|
+
}
|
|
887
|
+
renderEnum(schema) {
|
|
888
|
+
if (!schema.enum) return "unknown";
|
|
889
|
+
return schema.enum.map((v) => JSON.stringify(v)).join(" | ");
|
|
890
|
+
}
|
|
891
|
+
renderString(schema) {
|
|
892
|
+
if (schema.contentMediaType === "application/octet-stream") return "Blob | Buffer";
|
|
893
|
+
if (schema.format === "binary") return "Blob | Buffer";
|
|
894
|
+
return "string";
|
|
895
|
+
}
|
|
896
|
+
renderNumber(schema) {
|
|
897
|
+
return "number";
|
|
898
|
+
}
|
|
899
|
+
renderBoolean(schema) {
|
|
900
|
+
return "boolean";
|
|
901
|
+
}
|
|
902
|
+
renderNull(schema) {
|
|
903
|
+
return "null";
|
|
904
|
+
}
|
|
905
|
+
renderInteger(schema) {
|
|
906
|
+
return "number";
|
|
907
|
+
}
|
|
908
|
+
};
|
|
909
|
+
|
|
910
|
+
// src/transformers/json-schema/json-schema.transformer.ts
|
|
911
|
+
var JsonSchemaTransformer = class {
|
|
912
|
+
static toComment(schema) {
|
|
913
|
+
return new CommentRenderer(schema).render();
|
|
914
|
+
}
|
|
915
|
+
static toDeclaration(schema, options) {
|
|
916
|
+
return new DeclarationRenderer(schema, options).render();
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
|
|
920
|
+
// src/transformers/schema-definition/schema-definition.transformer.ts
|
|
921
|
+
var R8 = __toESM(require("ramda"), 1);
|
|
922
|
+
var SchemaDefinitionTransformer = class {
|
|
923
|
+
static toDeclaration(schemaDefinition, options) {
|
|
924
|
+
const dependencies = schemaDefinition.getDependencies();
|
|
925
|
+
let $dependencies = dependencies.filter((dep) => !SchemaDefinition.isUnknown(dep)).map((dep) => {
|
|
926
|
+
const filepath = options.getDependentSchemaDefinitionFilepath(dep);
|
|
927
|
+
return `import type { ${dep.name} } from "${filepath}"`;
|
|
928
|
+
}).map((str) => str.replace(/ from "(\.\.?\/.+?)(\.ts|\.mts|\.cts|\.js|\.cjs|\.mjs)?"/, options.esm ? ' from "$1.js"' : ' from "$1"')).join("\n");
|
|
929
|
+
if ($dependencies) $dependencies += "\n";
|
|
930
|
+
let $comment = JsonSchemaTransformer.toComment(schemaDefinition.schema);
|
|
931
|
+
if ($comment) $comment += "\n";
|
|
932
|
+
if (typeof schemaDefinition.schema === "boolean") {
|
|
933
|
+
return [
|
|
934
|
+
"/* @anchor:file:start */",
|
|
935
|
+
"",
|
|
936
|
+
$dependencies,
|
|
937
|
+
$comment || void 0,
|
|
938
|
+
`type ${schemaDefinition.name} = unknown`,
|
|
939
|
+
"",
|
|
940
|
+
"/* @anchor:file:end */"
|
|
941
|
+
].filter(R8.isNotNil).join("\n");
|
|
942
|
+
}
|
|
943
|
+
if (JsonSchemaUtils.isNonArray(schemaDefinition.schema) && schemaDefinition.schema.type === "object") {
|
|
944
|
+
const $schema = JsonSchemaTransformer.toDeclaration(schemaDefinition.schema);
|
|
945
|
+
const $declaration = $schema.startsWith("{") ? `export interface ${schemaDefinition.name} ${$schema}` : `export type ${schemaDefinition.name} = ${$schema}`;
|
|
946
|
+
return [
|
|
947
|
+
"/* @anchor:file:start */",
|
|
948
|
+
"",
|
|
949
|
+
$dependencies,
|
|
950
|
+
$comment || void 0,
|
|
951
|
+
$declaration,
|
|
952
|
+
"",
|
|
953
|
+
"/* @anchor:file:end */"
|
|
954
|
+
].filter(R8.isNotNil).join("\n");
|
|
955
|
+
}
|
|
956
|
+
return [
|
|
957
|
+
"/* @anchor:file:start */",
|
|
958
|
+
"",
|
|
959
|
+
$dependencies,
|
|
960
|
+
$comment || void 0,
|
|
961
|
+
`export type ${schemaDefinition.name} = ${JsonSchemaTransformer.toDeclaration(schemaDefinition.schema)}`,
|
|
962
|
+
"",
|
|
963
|
+
"/* @anchor:file:end */"
|
|
964
|
+
].filter(R8.isNotNil).join("\n");
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
|
|
968
|
+
// src/transformers/operation-definition/comment.renderer.ts
|
|
969
|
+
var R9 = __toESM(require("ramda"), 1);
|
|
970
|
+
var CommentRenderer2 = class {
|
|
971
|
+
constructor(operationDefinition) {
|
|
972
|
+
this.operationDefinition = operationDefinition;
|
|
973
|
+
}
|
|
974
|
+
render() {
|
|
975
|
+
const operation = this.operationDefinition.operation;
|
|
976
|
+
if (!operation.summary && !operation.description) return "";
|
|
977
|
+
const lines = ["/**"];
|
|
978
|
+
if (operation.summary && typeof operation.summary === "string") {
|
|
979
|
+
lines.push(` * ${R9.trim(operation.summary)}`);
|
|
980
|
+
lines.push(" *");
|
|
981
|
+
}
|
|
982
|
+
if (operation.description && typeof operation.description === "string") {
|
|
983
|
+
lines.push(` * @description ${R9.trim(operation.description)}`);
|
|
984
|
+
}
|
|
985
|
+
lines.push(" */");
|
|
986
|
+
return lines.join("\n");
|
|
987
|
+
}
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
// src/transformers/operation-definition/declaration.renderer.ts
|
|
991
|
+
var R14 = __toESM(require("ramda"), 1);
|
|
992
|
+
|
|
993
|
+
// src/transformers/operation-definition/utils/type-name-factory.ts
|
|
994
|
+
var changeCase = __toESM(require("change-case"), 1);
|
|
995
|
+
function typeNameFactory(operationDefinition) {
|
|
996
|
+
const pascalCaseOperationId = changeCase.pascalCase(operationDefinition.operationId);
|
|
997
|
+
return (name) => `${pascalCaseOperationId}${name}`;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
// src/utils/openapi-utils/dereference.ts
|
|
1001
|
+
function dereference($ref, swagger) {
|
|
1002
|
+
let value;
|
|
1003
|
+
for (const key of $ref.split("/")) {
|
|
1004
|
+
if (key === "#") {
|
|
720
1005
|
value = swagger;
|
|
721
1006
|
} else {
|
|
722
1007
|
value = value[key];
|
|
@@ -727,28 +1012,28 @@ function dereference($ref, swagger) {
|
|
|
727
1012
|
}
|
|
728
1013
|
|
|
729
1014
|
// src/utils/openapi-utils/dereference-operation.ts
|
|
730
|
-
var
|
|
1015
|
+
var R12 = __toESM(require("ramda"), 1);
|
|
731
1016
|
var import_jsonpointer2 = __toESM(require("jsonpointer"), 1);
|
|
732
1017
|
var import_jsonpath_plus4 = require("jsonpath-plus");
|
|
733
1018
|
|
|
734
1019
|
// src/utils/openapi-utils/remove-undefined-ref.ts
|
|
735
|
-
var
|
|
1020
|
+
var R11 = __toESM(require("ramda"), 1);
|
|
736
1021
|
var import_jsonpointer = __toESM(require("jsonpointer"), 1);
|
|
737
1022
|
var import_jsonpath_plus3 = require("jsonpath-plus");
|
|
738
1023
|
|
|
739
1024
|
// src/utils/openapi-utils/is-ref-defined.ts
|
|
740
|
-
var
|
|
1025
|
+
var R10 = __toESM(require("ramda"), 1);
|
|
741
1026
|
function isRefDefined($ref, swagger) {
|
|
742
1027
|
if ($ref.startsWith("#/")) {
|
|
743
|
-
const
|
|
744
|
-
return
|
|
1028
|
+
const path12 = $ref.replace("#/", "").split("/");
|
|
1029
|
+
return R10.path(path12, swagger) !== void 0;
|
|
745
1030
|
}
|
|
746
1031
|
return false;
|
|
747
1032
|
}
|
|
748
1033
|
|
|
749
1034
|
// src/utils/openapi-utils/remove-undefined-ref.ts
|
|
750
1035
|
function removeUndefinedRef(swagger) {
|
|
751
|
-
const shadow =
|
|
1036
|
+
const shadow = R11.clone(swagger);
|
|
752
1037
|
const matches = (0, import_jsonpath_plus3.JSONPath)({
|
|
753
1038
|
path: "$..*['$ref']^",
|
|
754
1039
|
json: swagger,
|
|
@@ -756,7 +1041,7 @@ function removeUndefinedRef(swagger) {
|
|
|
756
1041
|
});
|
|
757
1042
|
for (const match of matches) {
|
|
758
1043
|
if (match.value.$ref && !isRefDefined(match.value.$ref, swagger)) {
|
|
759
|
-
import_jsonpointer.default.set(shadow, match.pointer,
|
|
1044
|
+
import_jsonpointer.default.set(shadow, match.pointer, R11.omit(["$ref"], match.value));
|
|
760
1045
|
}
|
|
761
1046
|
}
|
|
762
1047
|
return shadow;
|
|
@@ -815,7 +1100,7 @@ function dereferenceParameters(swagger) {
|
|
|
815
1100
|
}
|
|
816
1101
|
}
|
|
817
1102
|
function dereferenceOperation(swagger) {
|
|
818
|
-
const shadow =
|
|
1103
|
+
const shadow = R12.clone(swagger);
|
|
819
1104
|
dereferencePathObject(shadow);
|
|
820
1105
|
dereferenceRequestBody(shadow);
|
|
821
1106
|
dereferenceResponses(shadow);
|
|
@@ -823,34 +1108,6 @@ function dereferenceOperation(swagger) {
|
|
|
823
1108
|
return removeUndefinedRef(shadow);
|
|
824
1109
|
}
|
|
825
1110
|
|
|
826
|
-
// src/utils/json-schema-utils/is-array.ts
|
|
827
|
-
function isArray(schema) {
|
|
828
|
-
return schema.type === "array";
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
// src/utils/json-schema-utils/is-mixed.ts
|
|
832
|
-
function isMixed(schema) {
|
|
833
|
-
return Array.isArray(schema.type);
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
// src/utils/json-schema-utils/is-non-array.ts
|
|
837
|
-
function isNonArray(schema) {
|
|
838
|
-
return typeof schema.type === "string" && schema.type !== "array";
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
// src/utils/json-schema-utils/is-ref.ts
|
|
842
|
-
function isRef(schema) {
|
|
843
|
-
return "$ref" in schema;
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
// src/utils/json-schema-utils/index.ts
|
|
847
|
-
var JsonSchemaUtils = class {
|
|
848
|
-
static isRef = isRef;
|
|
849
|
-
static isArray = isArray;
|
|
850
|
-
static isNonArray = isNonArray;
|
|
851
|
-
static isMixed = isMixed;
|
|
852
|
-
};
|
|
853
|
-
|
|
854
1111
|
// src/utils/openapi-utils/dereference-deep.ts
|
|
855
1112
|
function dereferenceDeep($ref, swagger) {
|
|
856
1113
|
const stack = [$ref];
|
|
@@ -879,9 +1136,9 @@ function To3_1(openapi) {
|
|
|
879
1136
|
}
|
|
880
1137
|
|
|
881
1138
|
// src/utils/openapi-utils/map-operation.ts
|
|
882
|
-
var
|
|
1139
|
+
var R13 = __toESM(require("ramda"), 1);
|
|
883
1140
|
function mapOperation(specification, mapper) {
|
|
884
|
-
const shadow =
|
|
1141
|
+
const shadow = R13.clone(specification);
|
|
885
1142
|
for (const [pathname, pathItem] of Object.entries(shadow.paths || {})) {
|
|
886
1143
|
for (const m in pathItem) {
|
|
887
1144
|
const method = m.toLowerCase();
|
|
@@ -916,547 +1173,6 @@ var OpenapiUtils = class {
|
|
|
916
1173
|
static to3_1 = To3_1;
|
|
917
1174
|
};
|
|
918
1175
|
|
|
919
|
-
// src/compiler/tasks/download/index.ts
|
|
920
|
-
function main2(compiler, options) {
|
|
921
|
-
return {
|
|
922
|
-
task: (context, task) => {
|
|
923
|
-
if (!context.rc || !context.matcher) {
|
|
924
|
-
throw new Error("Please run setup task first.");
|
|
925
|
-
}
|
|
926
|
-
const rc = context.rc;
|
|
927
|
-
const matcher = context.matcher;
|
|
928
|
-
context.documents = [];
|
|
929
|
-
return task.newListr(
|
|
930
|
-
Object.entries(rc.modules).map(([moduleName, address]) => new ModuleDefinition(moduleName, address)).map((moduleDefinition) => ({
|
|
931
|
-
title: moduleDefinition.name,
|
|
932
|
-
task: async (ctx, task2) => {
|
|
933
|
-
if (options?.skipIgnoredModules && matcher.isModuleIgnored(moduleDefinition)) {
|
|
934
|
-
task2.skip(`(${moduleDefinition.name}) is ignored`);
|
|
935
|
-
return;
|
|
936
|
-
}
|
|
937
|
-
task2.output = `Downloaded from ${moduleDefinition.address}`;
|
|
938
|
-
const content = await compiler.hooks.download.promise(moduleDefinition.address, moduleDefinition, task2);
|
|
939
|
-
if (!content) {
|
|
940
|
-
throw new Exception(moduleDefinition, `Cannot download document from ${moduleDefinition.address}`);
|
|
941
|
-
}
|
|
942
|
-
const spec = JSON.parse(content);
|
|
943
|
-
const { valid, errors } = await (0, import_openapi_parser2.validate)(spec);
|
|
944
|
-
if (!valid) {
|
|
945
|
-
const message = `${moduleDefinition.name} module openapi/swagger file does not conform to the openapi specifications or have grammatical errors, which may cause unexpected errors:
|
|
946
|
-
${errors?.map((e) => ` - ${e.message}`).join("\n")}`;
|
|
947
|
-
task2.output = message;
|
|
948
|
-
}
|
|
949
|
-
OpenapiUtils.dereferenceOperation(spec);
|
|
950
|
-
const document = new ApiDocumentV3_1(
|
|
951
|
-
spec,
|
|
952
|
-
moduleDefinition
|
|
953
|
-
);
|
|
954
|
-
ctx.documents?.push(document);
|
|
955
|
-
}
|
|
956
|
-
})),
|
|
957
|
-
{
|
|
958
|
-
concurrent: true,
|
|
959
|
-
exitOnError: false,
|
|
960
|
-
collectErrors: "minimal",
|
|
961
|
-
rendererOptions: {
|
|
962
|
-
collapseSubtasks: false,
|
|
963
|
-
// collapseSkips: false,
|
|
964
|
-
suffixSkips: true,
|
|
965
|
-
timer: import_listr2.PRESET_TIMER
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
);
|
|
969
|
-
}
|
|
970
|
-
};
|
|
971
|
-
}
|
|
972
|
-
function createDownloadTask(compiler, options) {
|
|
973
|
-
return {
|
|
974
|
-
title: "Download",
|
|
975
|
-
enabled: options?.enabled,
|
|
976
|
-
skip: options?.skip,
|
|
977
|
-
task: (_, task) => task.newListr(
|
|
978
|
-
[
|
|
979
|
-
main2(compiler, options),
|
|
980
|
-
{
|
|
981
|
-
task: (context, task2) => compiler.hooks.afterDownload.promise(task2)
|
|
982
|
-
}
|
|
983
|
-
],
|
|
984
|
-
{
|
|
985
|
-
concurrent: false
|
|
986
|
-
}
|
|
987
|
-
)
|
|
988
|
-
};
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
// src/compiler/tasks/persist/index.ts
|
|
992
|
-
var path6 = __toESM(require("path"), 1);
|
|
993
|
-
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
994
|
-
function createPersistArtifactTask() {
|
|
995
|
-
return {
|
|
996
|
-
title: "Write files",
|
|
997
|
-
task: async (context, task) => {
|
|
998
|
-
if (!context.rc) throw new Error("Please run setup task first.");
|
|
999
|
-
if (!context.artifacts || context.artifacts.length === 0) {
|
|
1000
|
-
task.skip("No compiled artifacts to persist.");
|
|
1001
|
-
return;
|
|
1002
|
-
}
|
|
1003
|
-
const rc = context.rc;
|
|
1004
|
-
const artifacts = context.artifacts;
|
|
1005
|
-
const total = artifacts.length;
|
|
1006
|
-
let completed = 0;
|
|
1007
|
-
const files = await Promise.all(artifacts.map(async (artifact) => {
|
|
1008
|
-
const realpath = `./${path6.join(rc.outdir, artifact.filepath)}`;
|
|
1009
|
-
await import_fs_extra3.default.ensureFile(realpath);
|
|
1010
|
-
await import_fs_extra3.default.writeFile(realpath, artifact.renderer());
|
|
1011
|
-
completed += 1;
|
|
1012
|
-
task.output = `Persisted ${completed}/${total} files`;
|
|
1013
|
-
return new Asset(path6.resolve(realpath));
|
|
1014
|
-
}));
|
|
1015
|
-
context.assets = files;
|
|
1016
|
-
}
|
|
1017
|
-
};
|
|
1018
|
-
}
|
|
1019
|
-
function createPersistIgnoreTask() {
|
|
1020
|
-
return {
|
|
1021
|
-
title: "Update .keqignore",
|
|
1022
|
-
task: async (context, task) => {
|
|
1023
|
-
if (!context.matcher) throw new Error("Please run setup task first.");
|
|
1024
|
-
const matcher = context.matcher;
|
|
1025
|
-
await matcher.write(".keqignore");
|
|
1026
|
-
}
|
|
1027
|
-
};
|
|
1028
|
-
}
|
|
1029
|
-
function main3() {
|
|
1030
|
-
return {
|
|
1031
|
-
task: (context, task) => task.newListr(
|
|
1032
|
-
[
|
|
1033
|
-
createPersistArtifactTask(),
|
|
1034
|
-
createPersistIgnoreTask()
|
|
1035
|
-
],
|
|
1036
|
-
{
|
|
1037
|
-
concurrent: true,
|
|
1038
|
-
rendererOptions: {
|
|
1039
|
-
collapseSubtasks: true
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
)
|
|
1043
|
-
};
|
|
1044
|
-
}
|
|
1045
|
-
function createPersistTask(compiler, options) {
|
|
1046
|
-
return {
|
|
1047
|
-
title: "Persist",
|
|
1048
|
-
enabled: options?.enabled,
|
|
1049
|
-
skip: options?.skip,
|
|
1050
|
-
task: (context, task) => task.newListr(
|
|
1051
|
-
[
|
|
1052
|
-
main3(),
|
|
1053
|
-
{
|
|
1054
|
-
task: (context2, task2) => compiler.hooks.afterPersist.promise(task2)
|
|
1055
|
-
}
|
|
1056
|
-
],
|
|
1057
|
-
{
|
|
1058
|
-
concurrent: false
|
|
1059
|
-
}
|
|
1060
|
-
)
|
|
1061
|
-
};
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
// src/compiler/tasks/compile/index.ts
|
|
1065
|
-
function main4(compiler) {
|
|
1066
|
-
return {
|
|
1067
|
-
task: async (context, task) => {
|
|
1068
|
-
if (!context.rc) throw new Error("Please run setup task first.");
|
|
1069
|
-
if (!context.documents) throw new Error("Please run shaking task first.");
|
|
1070
|
-
context.artifacts = [];
|
|
1071
|
-
await compiler.hooks.compile.promise(task);
|
|
1072
|
-
}
|
|
1073
|
-
};
|
|
1074
|
-
}
|
|
1075
|
-
function createCompileTask(compiler, options) {
|
|
1076
|
-
return {
|
|
1077
|
-
title: "Compile",
|
|
1078
|
-
enabled: options?.enabled,
|
|
1079
|
-
skip: options?.skip,
|
|
1080
|
-
task: (context, task) => task.newListr(
|
|
1081
|
-
[
|
|
1082
|
-
{
|
|
1083
|
-
task: (context2, task2) => compiler.hooks.beforeCompile.promise(task2)
|
|
1084
|
-
},
|
|
1085
|
-
main4(compiler),
|
|
1086
|
-
{
|
|
1087
|
-
task: (context2, task2) => compiler.hooks.afterCompile.promise(task2)
|
|
1088
|
-
}
|
|
1089
|
-
],
|
|
1090
|
-
{
|
|
1091
|
-
concurrent: false
|
|
1092
|
-
}
|
|
1093
|
-
)
|
|
1094
|
-
};
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
// src/compiler/intercepter/print-information.ts
|
|
1098
|
-
function proxyTaskWrapper(pluginName, task) {
|
|
1099
|
-
return new Proxy(task, {
|
|
1100
|
-
set(target, prop2, value) {
|
|
1101
|
-
if (prop2 !== "output") {
|
|
1102
|
-
return Reflect.set(target, prop2, value);
|
|
1103
|
-
}
|
|
1104
|
-
target.output = `[Plugin: ${pluginName}] ${value}`;
|
|
1105
|
-
return true;
|
|
1106
|
-
}
|
|
1107
|
-
});
|
|
1108
|
-
}
|
|
1109
|
-
function printInformation(taskIndex) {
|
|
1110
|
-
return {
|
|
1111
|
-
register: (tap) => {
|
|
1112
|
-
const fn = tap.fn;
|
|
1113
|
-
if (tap.type === "promise") {
|
|
1114
|
-
tap.fn = (...args) => {
|
|
1115
|
-
const task = args[taskIndex];
|
|
1116
|
-
const proxyTask = proxyTaskWrapper(tap.name, task);
|
|
1117
|
-
args[taskIndex] = proxyTask;
|
|
1118
|
-
proxyTask.output = "Processing...";
|
|
1119
|
-
return fn(...args);
|
|
1120
|
-
};
|
|
1121
|
-
}
|
|
1122
|
-
if (tap.type === "sync") {
|
|
1123
|
-
tap.fn = (...args) => {
|
|
1124
|
-
const task = args[taskIndex];
|
|
1125
|
-
const proxyTask = proxyTaskWrapper(tap.name, task);
|
|
1126
|
-
args[taskIndex] = proxyTask;
|
|
1127
|
-
proxyTask.output = "Processing...";
|
|
1128
|
-
return fn(...args);
|
|
1129
|
-
};
|
|
1130
|
-
}
|
|
1131
|
-
if (tap.type === "async") {
|
|
1132
|
-
tap.fn = (...args) => {
|
|
1133
|
-
const task = args[taskIndex];
|
|
1134
|
-
const proxyTask = proxyTaskWrapper(tap.name, task);
|
|
1135
|
-
args[taskIndex] = proxyTask;
|
|
1136
|
-
proxyTask.output = "Processing...";
|
|
1137
|
-
return fn(...args);
|
|
1138
|
-
};
|
|
1139
|
-
}
|
|
1140
|
-
return tap;
|
|
1141
|
-
}
|
|
1142
|
-
};
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
// src/compiler/intercepter/perfect-error-message.ts
|
|
1146
|
-
var R10 = __toESM(require("ramda"), 1);
|
|
1147
|
-
function perfectErrorMessage() {
|
|
1148
|
-
return {
|
|
1149
|
-
register: (tap) => {
|
|
1150
|
-
const fn = tap.fn;
|
|
1151
|
-
function prefix(err) {
|
|
1152
|
-
if (err instanceof Error) {
|
|
1153
|
-
err.message = `[Plugin: ${tap.name}] ${err.message}`;
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
if (tap.type === "promise") {
|
|
1157
|
-
tap.fn = async (...args) => {
|
|
1158
|
-
try {
|
|
1159
|
-
return await fn(...args);
|
|
1160
|
-
} catch (err) {
|
|
1161
|
-
prefix(err);
|
|
1162
|
-
throw err;
|
|
1163
|
-
}
|
|
1164
|
-
};
|
|
1165
|
-
}
|
|
1166
|
-
if (tap.type === "sync") {
|
|
1167
|
-
tap.fn = (...args) => {
|
|
1168
|
-
try {
|
|
1169
|
-
return fn(...args);
|
|
1170
|
-
} catch (err) {
|
|
1171
|
-
prefix(err);
|
|
1172
|
-
throw err;
|
|
1173
|
-
}
|
|
1174
|
-
};
|
|
1175
|
-
}
|
|
1176
|
-
if (tap.type === "async") {
|
|
1177
|
-
tap.fn = (...args) => {
|
|
1178
|
-
const callback = R10.last(args);
|
|
1179
|
-
return fn(...R10.init(args), (err, result) => {
|
|
1180
|
-
prefix(err);
|
|
1181
|
-
return callback(err, result);
|
|
1182
|
-
});
|
|
1183
|
-
};
|
|
1184
|
-
}
|
|
1185
|
-
return tap;
|
|
1186
|
-
}
|
|
1187
|
-
};
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
// src/plugins/eslint/index.ts
|
|
1191
|
-
var import_eslint = require("eslint");
|
|
1192
|
-
|
|
1193
|
-
// src/plugins/prettier/prettier.plugin.ts
|
|
1194
|
-
var import_child_process = require("child_process");
|
|
1195
|
-
var import_util = require("util");
|
|
1196
|
-
var execAsync = (0, import_util.promisify)(import_child_process.exec);
|
|
1197
|
-
|
|
1198
|
-
// src/plugins/body-fallback/index.ts
|
|
1199
|
-
var R22 = __toESM(require("ramda"), 1);
|
|
1200
|
-
|
|
1201
|
-
// src/plugins/generate-micro-function/generate-micro-function.plugin.ts
|
|
1202
|
-
var import_tapable2 = require("tapable");
|
|
1203
|
-
|
|
1204
|
-
// src/plugins/generate-micro-function/constants/metadata-storage.ts
|
|
1205
|
-
var MetadataStorage = /* @__PURE__ */ new WeakMap();
|
|
1206
|
-
|
|
1207
|
-
// src/plugins/generate-micro-function/generators/micro_function/micro-function.generator.ts
|
|
1208
|
-
var R21 = __toESM(require("ramda"), 1);
|
|
1209
|
-
var path10 = __toESM(require("path"), 1);
|
|
1210
|
-
var changeCase6 = __toESM(require("change-case"), 1);
|
|
1211
|
-
|
|
1212
|
-
// src/plugins/generate-declaration/generate-declaration.plugin.ts
|
|
1213
|
-
var import_tapable = require("tapable");
|
|
1214
|
-
|
|
1215
|
-
// src/plugins/generate-declaration/generators/operation-declaration/operation.generator.ts
|
|
1216
|
-
var path9 = __toESM(require("path"), 1);
|
|
1217
|
-
var changeCase5 = __toESM(require("change-case"), 1);
|
|
1218
|
-
|
|
1219
|
-
// src/transformers/json-schema/comment.renderer.ts
|
|
1220
|
-
var CommentRenderer = class {
|
|
1221
|
-
constructor(schema) {
|
|
1222
|
-
this.schema = schema;
|
|
1223
|
-
}
|
|
1224
|
-
render() {
|
|
1225
|
-
const schema = this.schema;
|
|
1226
|
-
const lines = ["/**"];
|
|
1227
|
-
if (schema.description) {
|
|
1228
|
-
const description = schema.description.replace("*/", "*\\/");
|
|
1229
|
-
lines.push(...description.split("\n").map((line) => ` * ${line}`));
|
|
1230
|
-
}
|
|
1231
|
-
if (schema.deprecated) {
|
|
1232
|
-
lines.push(" * @deprecated");
|
|
1233
|
-
}
|
|
1234
|
-
if (schema.readOnly) {
|
|
1235
|
-
lines.push(" * @readonly");
|
|
1236
|
-
}
|
|
1237
|
-
if (schema.format) {
|
|
1238
|
-
lines.push(` * @format ${schema.format}`);
|
|
1239
|
-
}
|
|
1240
|
-
lines.push(" */");
|
|
1241
|
-
if (lines.length === 2) return "";
|
|
1242
|
-
return lines.join("\n");
|
|
1243
|
-
}
|
|
1244
|
-
};
|
|
1245
|
-
|
|
1246
|
-
// src/transformers/json-schema/declaration.renderer.ts
|
|
1247
|
-
var R12 = __toESM(require("ramda"), 1);
|
|
1248
|
-
|
|
1249
|
-
// src/utils/indent.ts
|
|
1250
|
-
function indent(space, text) {
|
|
1251
|
-
if (text === "") return "";
|
|
1252
|
-
const indentation = " ".repeat(space);
|
|
1253
|
-
return text.split("\n").map((line) => line ? `${indentation}${line}` : line).join("\n");
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
// src/transformers/json-schema/reference.transformer.ts
|
|
1257
|
-
var R11 = __toESM(require("ramda"), 1);
|
|
1258
|
-
var ReferenceTransformer = class {
|
|
1259
|
-
static toDeclaration(schema, alias2 = R11.identity) {
|
|
1260
|
-
if (!schema.$ref || !schema.$ref.startsWith("#")) return `unknown /* ${schema.$ref.replace("*/", "*\\/")} */`;
|
|
1261
|
-
const parts = schema.$ref.split("/");
|
|
1262
|
-
return alias2(parts[parts.length - 1]) || "unknown";
|
|
1263
|
-
}
|
|
1264
|
-
};
|
|
1265
|
-
|
|
1266
|
-
// src/transformers/json-schema/declaration.renderer.ts
|
|
1267
|
-
var DeclarationRenderer = class {
|
|
1268
|
-
constructor(schema, options = {}) {
|
|
1269
|
-
this.schema = schema;
|
|
1270
|
-
this.options = options;
|
|
1271
|
-
}
|
|
1272
|
-
render() {
|
|
1273
|
-
return this.renderSchema(this.schema);
|
|
1274
|
-
}
|
|
1275
|
-
renderSchema(schema) {
|
|
1276
|
-
if (typeof schema === "boolean") return "unknown";
|
|
1277
|
-
if (JsonSchemaUtils.isRef(schema)) return this.renderReference(schema);
|
|
1278
|
-
if (JsonSchemaUtils.isMixed(schema)) return this.renderMixed(schema);
|
|
1279
|
-
if (JsonSchemaUtils.isArray(schema)) return this.renderArray(schema);
|
|
1280
|
-
if (schema.type === "object") return this.renderObject(schema);
|
|
1281
|
-
if (schema.enum) return this.renderEnum(schema);
|
|
1282
|
-
if (schema.oneOf) return this.renderOneOf(schema);
|
|
1283
|
-
if (schema.anyOf) return this.renderAnyOf(schema);
|
|
1284
|
-
if (schema.allOf) return this.renderAllOf(schema);
|
|
1285
|
-
if (schema.type === "string") return this.renderString(schema);
|
|
1286
|
-
if (schema.type === "number") return this.renderNumber(schema);
|
|
1287
|
-
if (schema.type === "boolean") return this.renderBoolean(schema);
|
|
1288
|
-
if (schema.type === "null") return this.renderNull(schema);
|
|
1289
|
-
if (schema.type === "integer") return this.renderInteger(schema);
|
|
1290
|
-
return "unknown";
|
|
1291
|
-
}
|
|
1292
|
-
renderMixed(schema) {
|
|
1293
|
-
if (Array.isArray(schema.type)) {
|
|
1294
|
-
schema.type.map((type) => ({ ...schema, type })).map((schema2) => this.renderSchema(schema2)).join(" | ");
|
|
1295
|
-
}
|
|
1296
|
-
return "unknown";
|
|
1297
|
-
}
|
|
1298
|
-
renderReference(schema) {
|
|
1299
|
-
if (!this.options.referenceTransformer) {
|
|
1300
|
-
return ReferenceTransformer.toDeclaration(schema);
|
|
1301
|
-
}
|
|
1302
|
-
return this.options.referenceTransformer(schema);
|
|
1303
|
-
}
|
|
1304
|
-
renderArray(schema) {
|
|
1305
|
-
if (schema.items && Array.isArray(schema.items)) {
|
|
1306
|
-
const items = schema.items.map((s) => this.renderSchema(s)).join(", ");
|
|
1307
|
-
return `[${items}]`;
|
|
1308
|
-
}
|
|
1309
|
-
if (schema.items && typeof schema.items === "object") {
|
|
1310
|
-
return `${this.renderSchema(schema.items)}[]`;
|
|
1311
|
-
}
|
|
1312
|
-
return "any[]";
|
|
1313
|
-
}
|
|
1314
|
-
renderObject(schema) {
|
|
1315
|
-
if ((!schema.properties || R12.isEmpty(schema.properties)) && (!schema.additionalProperties || R12.isEmpty(schema.additionalProperties))) {
|
|
1316
|
-
return "object";
|
|
1317
|
-
}
|
|
1318
|
-
const $properties = Object.entries(schema.properties || {}).map(([propertyName, propertySchema]) => {
|
|
1319
|
-
let $comment = new CommentRenderer(propertySchema).render();
|
|
1320
|
-
if ($comment) $comment += "\n";
|
|
1321
|
-
const $key = `"${propertyName}"${schema.required?.includes(propertyName) ? "" : "?"}`;
|
|
1322
|
-
const $value = this.renderSchema(propertySchema);
|
|
1323
|
-
return indent(2, `${$comment}${$key}: ${$value}`);
|
|
1324
|
-
});
|
|
1325
|
-
if (schema.additionalProperties) {
|
|
1326
|
-
const $value = schema.additionalProperties === true ? "any" : this.renderSchema(schema.additionalProperties);
|
|
1327
|
-
$properties.push(indent(2, `[key: string]: ${$value}`));
|
|
1328
|
-
}
|
|
1329
|
-
return [
|
|
1330
|
-
"{",
|
|
1331
|
-
...$properties,
|
|
1332
|
-
"}"
|
|
1333
|
-
].join("\n");
|
|
1334
|
-
}
|
|
1335
|
-
renderOneOf(schema) {
|
|
1336
|
-
if (!schema.oneOf) return "unknown";
|
|
1337
|
-
return schema.oneOf.map((s) => this.renderSchema(s)).join(" | ");
|
|
1338
|
-
}
|
|
1339
|
-
renderAnyOf(schema) {
|
|
1340
|
-
if (!schema.anyOf) return "unknown";
|
|
1341
|
-
return schema.anyOf.map((s) => this.renderSchema(s)).join(" | ");
|
|
1342
|
-
}
|
|
1343
|
-
renderAllOf(schema) {
|
|
1344
|
-
if (!schema.allOf) return "unknown";
|
|
1345
|
-
return schema.allOf.map((s) => this.renderSchema(s)).join(" & ");
|
|
1346
|
-
}
|
|
1347
|
-
renderEnum(schema) {
|
|
1348
|
-
if (!schema.enum) return "unknown";
|
|
1349
|
-
return schema.enum.map((v) => JSON.stringify(v)).join(" | ");
|
|
1350
|
-
}
|
|
1351
|
-
renderString(schema) {
|
|
1352
|
-
if (schema.contentMediaType === "application/octet-stream") return "Blob | Buffer";
|
|
1353
|
-
if (schema.format === "binary") return "Blob | Buffer";
|
|
1354
|
-
return "string";
|
|
1355
|
-
}
|
|
1356
|
-
renderNumber(schema) {
|
|
1357
|
-
return "number";
|
|
1358
|
-
}
|
|
1359
|
-
renderBoolean(schema) {
|
|
1360
|
-
return "boolean";
|
|
1361
|
-
}
|
|
1362
|
-
renderNull(schema) {
|
|
1363
|
-
return "null";
|
|
1364
|
-
}
|
|
1365
|
-
renderInteger(schema) {
|
|
1366
|
-
return "number";
|
|
1367
|
-
}
|
|
1368
|
-
};
|
|
1369
|
-
|
|
1370
|
-
// src/transformers/json-schema/json-schema.transformer.ts
|
|
1371
|
-
var JsonSchemaTransformer = class {
|
|
1372
|
-
static toComment(schema) {
|
|
1373
|
-
return new CommentRenderer(schema).render();
|
|
1374
|
-
}
|
|
1375
|
-
static toDeclaration(schema, options) {
|
|
1376
|
-
return new DeclarationRenderer(schema, options).render();
|
|
1377
|
-
}
|
|
1378
|
-
};
|
|
1379
|
-
|
|
1380
|
-
// src/transformers/schema-definition/schema-definition.transformer.ts
|
|
1381
|
-
var R13 = __toESM(require("ramda"), 1);
|
|
1382
|
-
var SchemaDefinitionTransformer = class {
|
|
1383
|
-
static toDeclaration(schemaDefinition, options) {
|
|
1384
|
-
const dependencies = schemaDefinition.getDependencies();
|
|
1385
|
-
let $dependencies = dependencies.filter((dep) => !SchemaDefinition.isUnknown(dep)).map((dep) => {
|
|
1386
|
-
const filepath = options.getDependentSchemaDefinitionFilepath(dep);
|
|
1387
|
-
return `import type { ${dep.name} } from "${filepath}"`;
|
|
1388
|
-
}).map((str) => str.replace(/ from "(\.\.?\/.+?)(\.ts|\.mts|\.cts|\.js|\.cjs|\.mjs)?"/, options.esm ? ' from "$1.js"' : ' from "$1"')).join("\n");
|
|
1389
|
-
if ($dependencies) $dependencies += "\n";
|
|
1390
|
-
let $comment = JsonSchemaTransformer.toComment(schemaDefinition.schema);
|
|
1391
|
-
if ($comment) $comment += "\n";
|
|
1392
|
-
if (typeof schemaDefinition.schema === "boolean") {
|
|
1393
|
-
return [
|
|
1394
|
-
"/* @anchor:file:start */",
|
|
1395
|
-
"",
|
|
1396
|
-
$dependencies,
|
|
1397
|
-
$comment || void 0,
|
|
1398
|
-
`type ${schemaDefinition.name} = unknown`,
|
|
1399
|
-
"",
|
|
1400
|
-
"/* @anchor:file:end */"
|
|
1401
|
-
].filter(R13.isNotNil).join("\n");
|
|
1402
|
-
}
|
|
1403
|
-
if (JsonSchemaUtils.isNonArray(schemaDefinition.schema) && schemaDefinition.schema.type === "object") {
|
|
1404
|
-
const $schema = JsonSchemaTransformer.toDeclaration(schemaDefinition.schema);
|
|
1405
|
-
const $declaration = $schema.startsWith("{") ? `export interface ${schemaDefinition.name} ${$schema}` : `export type ${schemaDefinition.name} = ${$schema}`;
|
|
1406
|
-
return [
|
|
1407
|
-
"/* @anchor:file:start */",
|
|
1408
|
-
"",
|
|
1409
|
-
$dependencies,
|
|
1410
|
-
$comment || void 0,
|
|
1411
|
-
$declaration,
|
|
1412
|
-
"",
|
|
1413
|
-
"/* @anchor:file:end */"
|
|
1414
|
-
].filter(R13.isNotNil).join("\n");
|
|
1415
|
-
}
|
|
1416
|
-
return [
|
|
1417
|
-
"/* @anchor:file:start */",
|
|
1418
|
-
"",
|
|
1419
|
-
$dependencies,
|
|
1420
|
-
$comment || void 0,
|
|
1421
|
-
`export type ${schemaDefinition.name} = ${JsonSchemaTransformer.toDeclaration(schemaDefinition.schema)}`,
|
|
1422
|
-
"",
|
|
1423
|
-
"/* @anchor:file:end */"
|
|
1424
|
-
].filter(R13.isNotNil).join("\n");
|
|
1425
|
-
}
|
|
1426
|
-
};
|
|
1427
|
-
|
|
1428
|
-
// src/transformers/operation-definition/comment.renderer.ts
|
|
1429
|
-
var R14 = __toESM(require("ramda"), 1);
|
|
1430
|
-
var CommentRenderer2 = class {
|
|
1431
|
-
constructor(operationDefinition) {
|
|
1432
|
-
this.operationDefinition = operationDefinition;
|
|
1433
|
-
}
|
|
1434
|
-
render() {
|
|
1435
|
-
const operation = this.operationDefinition.operation;
|
|
1436
|
-
if (!operation.summary && !operation.description) return "";
|
|
1437
|
-
const lines = ["/**"];
|
|
1438
|
-
if (operation.summary && typeof operation.summary === "string") {
|
|
1439
|
-
lines.push(` * ${R14.trim(operation.summary)}`);
|
|
1440
|
-
lines.push(" *");
|
|
1441
|
-
}
|
|
1442
|
-
if (operation.description && typeof operation.description === "string") {
|
|
1443
|
-
lines.push(` * @description ${R14.trim(operation.description)}`);
|
|
1444
|
-
}
|
|
1445
|
-
lines.push(" */");
|
|
1446
|
-
return lines.join("\n");
|
|
1447
|
-
}
|
|
1448
|
-
};
|
|
1449
|
-
|
|
1450
|
-
// src/transformers/operation-definition/declaration.renderer.ts
|
|
1451
|
-
var R15 = __toESM(require("ramda"), 1);
|
|
1452
|
-
|
|
1453
|
-
// src/transformers/operation-definition/utils/type-name-factory.ts
|
|
1454
|
-
var changeCase = __toESM(require("change-case"), 1);
|
|
1455
|
-
function typeNameFactory(operationDefinition) {
|
|
1456
|
-
const pascalCaseOperationId = changeCase.pascalCase(operationDefinition.operationId);
|
|
1457
|
-
return (name) => `${pascalCaseOperationId}${name}`;
|
|
1458
|
-
}
|
|
1459
|
-
|
|
1460
1176
|
// src/transformers/operation-definition/declaration.renderer.ts
|
|
1461
1177
|
var alias = (name) => `${name}Schema`;
|
|
1462
1178
|
var DeclarationRenderer2 = class {
|
|
@@ -1467,7 +1183,7 @@ var DeclarationRenderer2 = class {
|
|
|
1467
1183
|
}
|
|
1468
1184
|
typeName;
|
|
1469
1185
|
renderResponseBodies(operation, options) {
|
|
1470
|
-
if (!operation.responses ||
|
|
1186
|
+
if (!operation.responses || R14.isEmpty(operation.responses)) {
|
|
1471
1187
|
return `export interface ${this.typeName("ResponseBodies")} {}`;
|
|
1472
1188
|
}
|
|
1473
1189
|
const $responses = Object.entries(operation.responses).map(([statusCode, response]) => {
|
|
@@ -1618,15 +1334,28 @@ var DeclarationRenderer2 = class {
|
|
|
1618
1334
|
"}",
|
|
1619
1335
|
"",
|
|
1620
1336
|
"/* @anchor:file:end */"
|
|
1621
|
-
].filter(
|
|
1337
|
+
].filter(R14.isNotNil).join("\n");
|
|
1622
1338
|
}
|
|
1623
1339
|
};
|
|
1624
1340
|
|
|
1625
1341
|
// src/transformers/operation-definition/micro-function.renderer.ts
|
|
1626
|
-
var
|
|
1342
|
+
var R16 = __toESM(require("ramda"), 1);
|
|
1343
|
+
|
|
1344
|
+
// src/exception.ts
|
|
1345
|
+
var import_ts_custom_error = require("ts-custom-error");
|
|
1346
|
+
var import_word_wrap = __toESM(require("word-wrap"), 1);
|
|
1347
|
+
var Exception = class extends import_ts_custom_error.CustomError {
|
|
1348
|
+
constructor(module2, message) {
|
|
1349
|
+
const moduleName = typeof module2 === "string" ? module2 : module2.name;
|
|
1350
|
+
const msg = (0, import_word_wrap.default)(message, { width: 60, indent: " " });
|
|
1351
|
+
super(`${moduleName} module failed to compile:
|
|
1352
|
+
${msg}`);
|
|
1353
|
+
Object.defineProperty(this, "name", { value: "KeqCLI_Exception" });
|
|
1354
|
+
}
|
|
1355
|
+
};
|
|
1627
1356
|
|
|
1628
1357
|
// src/transformers/operation-definition/typescript-snippet.ts
|
|
1629
|
-
var
|
|
1358
|
+
var R15 = __toESM(require("ramda"), 1);
|
|
1630
1359
|
var OperationDefinitionSnippet = class {
|
|
1631
1360
|
constructor(operationDefinition, options) {
|
|
1632
1361
|
this.operationDefinition = operationDefinition;
|
|
@@ -1683,7 +1412,7 @@ var OperationDefinitionSnippet = class {
|
|
|
1683
1412
|
const { operation } = this.operationDefinition;
|
|
1684
1413
|
const $query = (operation.parameters || []).filter((p) => !JsonSchemaUtils.isRef(p)).filter((p) => p.in === "query").map((p) => {
|
|
1685
1414
|
const option = this.getQsParameters(p);
|
|
1686
|
-
const $option = !option ||
|
|
1415
|
+
const $option = !option || R15.isEmpty(option) ? "" : `, ${JSON.stringify(option)}`;
|
|
1687
1416
|
return `if (args && ${JSON.stringify(p.name)} in args) req.query(${JSON.stringify(p.name)}, args[${JSON.stringify(p.name)}]${$option})`;
|
|
1688
1417
|
}).join("\n");
|
|
1689
1418
|
return $query;
|
|
@@ -1753,7 +1482,7 @@ var OperationDefinitionSnippet = class {
|
|
|
1753
1482
|
} catch (err) {
|
|
1754
1483
|
return this.renderErrorComment(err, mediaType);
|
|
1755
1484
|
}
|
|
1756
|
-
}).filter(
|
|
1485
|
+
}).filter(R15.isNotNil).join("\n");
|
|
1757
1486
|
return $requestBody;
|
|
1758
1487
|
}
|
|
1759
1488
|
renderErrorComment(err, mediaType) {
|
|
@@ -1828,7 +1557,7 @@ var OperationDefinitionMicroFunctionRenderer = class {
|
|
|
1828
1557
|
`${operationId}.pathname = pathname`,
|
|
1829
1558
|
`${operationId}.method = method`,
|
|
1830
1559
|
"/* @anchor:file:end */"
|
|
1831
|
-
].filter(
|
|
1560
|
+
].filter(R16.isNotNil).join("\n");
|
|
1832
1561
|
}
|
|
1833
1562
|
renderDependencies() {
|
|
1834
1563
|
const declarationFilepath = this.options.getOperationDefinitionDeclarationFilepath(this.operationDefinition);
|
|
@@ -1855,7 +1584,7 @@ var OperationDefinitionMicroFunctionRenderer = class {
|
|
|
1855
1584
|
};
|
|
1856
1585
|
|
|
1857
1586
|
// src/transformers/operation-definition/nestjs-method.renderer.ts
|
|
1858
|
-
var
|
|
1587
|
+
var R17 = __toESM(require("ramda"), 1);
|
|
1859
1588
|
var OperationDefinitionNestjsMethodRenderer = class {
|
|
1860
1589
|
constructor(operationDefinition, options) {
|
|
1861
1590
|
this.operationDefinition = operationDefinition;
|
|
@@ -1908,7 +1637,7 @@ var OperationDefinitionNestjsMethodRenderer = class {
|
|
|
1908
1637
|
"",
|
|
1909
1638
|
" return req",
|
|
1910
1639
|
"}"
|
|
1911
|
-
].filter(
|
|
1640
|
+
].filter(R17.isNotNil).join("\n");
|
|
1912
1641
|
}
|
|
1913
1642
|
renderOperationDeclaration(operationDefinition) {
|
|
1914
1643
|
const { operationId } = operationDefinition;
|
|
@@ -1928,163 +1657,61 @@ var OperationDefinitionNestjsMethodRenderer = class {
|
|
|
1928
1657
|
// src/transformers/operation-definition/operation-definition.transformer.ts
|
|
1929
1658
|
var OperationDefinitionTransformer = class {
|
|
1930
1659
|
static toDeclaration(operationDefinition, options) {
|
|
1931
|
-
return new DeclarationRenderer2(operationDefinition, options).render();
|
|
1932
|
-
}
|
|
1933
|
-
static toMicroFunction(operationDefinition, options) {
|
|
1934
|
-
return new OperationDefinitionMicroFunctionRenderer(operationDefinition, options).render();
|
|
1935
|
-
}
|
|
1936
|
-
static toNestjsMethod(operationDefinition, options) {
|
|
1937
|
-
return new OperationDefinitionNestjsMethodRenderer(operationDefinition, options).render();
|
|
1938
|
-
}
|
|
1939
|
-
static toComment(operationDefinition) {
|
|
1940
|
-
return new CommentRenderer2(operationDefinition).render();
|
|
1941
|
-
}
|
|
1942
|
-
};
|
|
1943
|
-
|
|
1944
|
-
// src/transformers/entrypoint/entrypoint.transformer.ts
|
|
1945
|
-
var path7 = __toESM(require("path"), 1);
|
|
1946
|
-
var EntrypointTransformer = class {
|
|
1947
|
-
static toTypescript(exports2, options) {
|
|
1948
|
-
const $exports = exports2.map((exportArtifact) => {
|
|
1949
|
-
const relativePath = path7.relative(
|
|
1950
|
-
options.dirpath,
|
|
1951
|
-
exportArtifact.filepath
|
|
1952
|
-
).replace(/(\.ts|\.mts|\.cts|\.js|\.cjs|\.mjs)?$/, options.esm ? ".js" : "");
|
|
1953
|
-
return relativePath.startsWith(".") ? `export * from '${relativePath}'` : `export * from './${relativePath}'`;
|
|
1954
|
-
});
|
|
1955
|
-
return [
|
|
1956
|
-
"/* @anchor:file:start */",
|
|
1957
|
-
"",
|
|
1958
|
-
...$exports,
|
|
1959
|
-
"",
|
|
1960
|
-
"/* @anchor:file:end */"
|
|
1961
|
-
].join("\n");
|
|
1962
|
-
}
|
|
1963
|
-
};
|
|
1964
|
-
|
|
1965
|
-
// src/transformers/api-document/nestjs-client.renderer.ts
|
|
1966
|
-
var R19 = __toESM(require("ramda"), 1);
|
|
1967
|
-
var changeCase2 = __toESM(require("change-case"), 1);
|
|
1968
|
-
var NestjsClientRenderer = class {
|
|
1969
|
-
constructor(document, options) {
|
|
1970
|
-
this.document = document;
|
|
1971
|
-
this.options = options;
|
|
1972
|
-
}
|
|
1973
|
-
renderDependencies() {
|
|
1974
|
-
const $operations = this.document.operations.map((operationDefinition) => {
|
|
1975
|
-
const filepath = this.options.getOperationDefinitionDeclarationFilepath(operationDefinition);
|
|
1976
|
-
const typeName = typeNameFactory(operationDefinition);
|
|
1977
|
-
return `import type { ${typeName("Operation")}, ${typeName("ResponseBodies")}, ${typeName("RequestParameters")} } from "${filepath}"`;
|
|
1978
|
-
}).map((str) => str.replace(/ from "(\.\.?\/.+?)(\.ts|\.mts|\.cts|\.js|\.cjs|\.mjs)?"/, this.options.esm ? ' from "$1.js"' : ' from "$1"'));
|
|
1979
|
-
return [
|
|
1980
|
-
'import { Injectable, Logger } from "@nestjs/common"',
|
|
1981
|
-
'import { Keq, KeqRequest } from "keq"',
|
|
1982
|
-
...$operations
|
|
1983
|
-
].join("\n");
|
|
1984
|
-
}
|
|
1985
|
-
render() {
|
|
1986
|
-
const moduleName = changeCase2.pascalCase(this.document.module.name);
|
|
1987
|
-
const $dependencies = this.renderDependencies();
|
|
1988
|
-
const $operations = this.document.operations.map((operation) => OperationDefinitionTransformer.toNestjsMethod(operation, {
|
|
1989
|
-
esm: this.options.esm
|
|
1990
|
-
})).join("\n\n");
|
|
1991
|
-
return [
|
|
1992
|
-
"/* @anchor:file:start */",
|
|
1993
|
-
"",
|
|
1994
|
-
$dependencies,
|
|
1995
|
-
"",
|
|
1996
|
-
"@Injectable()",
|
|
1997
|
-
`export class ${moduleName}Client {`,
|
|
1998
|
-
` private readonly logger = new Logger(${moduleName}Client.name)`,
|
|
1999
|
-
"",
|
|
2000
|
-
" constructor(",
|
|
2001
|
-
" // @anchor:client-constructor-parameters:start",
|
|
2002
|
-
" private readonly request: KeqRequest,",
|
|
2003
|
-
" // @anchor:client-constructor-parameters:end",
|
|
2004
|
-
" ) {}",
|
|
2005
|
-
"",
|
|
2006
|
-
indent(2, $operations),
|
|
2007
|
-
"}",
|
|
2008
|
-
"",
|
|
2009
|
-
"/* @anchor:file:end */"
|
|
2010
|
-
].filter(R19.isNotNil).join("\n");
|
|
1660
|
+
return new DeclarationRenderer2(operationDefinition, options).render();
|
|
1661
|
+
}
|
|
1662
|
+
static toMicroFunction(operationDefinition, options) {
|
|
1663
|
+
return new OperationDefinitionMicroFunctionRenderer(operationDefinition, options).render();
|
|
1664
|
+
}
|
|
1665
|
+
static toNestjsMethod(operationDefinition, options) {
|
|
1666
|
+
return new OperationDefinitionNestjsMethodRenderer(operationDefinition, options).render();
|
|
1667
|
+
}
|
|
1668
|
+
static toComment(operationDefinition) {
|
|
1669
|
+
return new CommentRenderer2(operationDefinition).render();
|
|
2011
1670
|
}
|
|
2012
1671
|
};
|
|
2013
1672
|
|
|
2014
|
-
// src/transformers/
|
|
2015
|
-
var
|
|
2016
|
-
var
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
1673
|
+
// src/transformers/entrypoint/entrypoint.transformer.ts
|
|
1674
|
+
var path5 = __toESM(require("path"), 1);
|
|
1675
|
+
var EntrypointTransformer = class {
|
|
1676
|
+
static toTypescript(exports2, options) {
|
|
1677
|
+
const $exports = exports2.map((exportArtifact) => {
|
|
1678
|
+
const relativePath = path5.relative(
|
|
1679
|
+
options.dirpath,
|
|
1680
|
+
exportArtifact.filepath
|
|
1681
|
+
).replace(/(\.ts|\.mts|\.cts|\.js|\.cjs|\.mjs)?$/, options.esm ? ".js" : "");
|
|
1682
|
+
return relativePath.startsWith(".") ? `export * from '${relativePath}'` : `export * from './${relativePath}'`;
|
|
1683
|
+
});
|
|
2024
1684
|
return [
|
|
2025
1685
|
"/* @anchor:file:start */",
|
|
2026
|
-
'import { Module, Inject, ConfigurableModuleBuilder, Global } from "@nestjs/common"',
|
|
2027
|
-
'import { KeqRequest } from "keq"',
|
|
2028
|
-
'import { KeqModuleOptions } from "@keq-request/nestjs"',
|
|
2029
|
-
`import { ${moduleName}Client } from "${clientFilepath}"`,
|
|
2030
|
-
"",
|
|
2031
|
-
"",
|
|
2032
|
-
"const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, OPTIONS_TYPE, ASYNC_OPTIONS_TYPE } = new ConfigurableModuleBuilder<KeqModuleOptions>().build()",
|
|
2033
|
-
"",
|
|
2034
|
-
"@Global()",
|
|
2035
|
-
"@Module({",
|
|
2036
|
-
" imports: [],",
|
|
2037
|
-
" controllers: [],",
|
|
2038
|
-
` providers: [${moduleName}Client],`,
|
|
2039
|
-
` exports: [${moduleName}Client],`,
|
|
2040
|
-
"})",
|
|
2041
|
-
`export class ${moduleName}Module extends ConfigurableModuleClass {`,
|
|
2042
1686
|
"",
|
|
2043
|
-
|
|
2044
|
-
" @Inject(MODULE_OPTIONS_TOKEN) private readonly options: KeqModuleOptions,",
|
|
2045
|
-
" private readonly request: KeqRequest,",
|
|
2046
|
-
" ) {",
|
|
2047
|
-
" super()",
|
|
2048
|
-
" }",
|
|
2049
|
-
"",
|
|
2050
|
-
" onModuleInit() {",
|
|
2051
|
-
" if (this.options.middlewares) {",
|
|
2052
|
-
" for (const middleware of this.options.middlewares) {",
|
|
2053
|
-
" this.request.use(middleware)",
|
|
2054
|
-
" }",
|
|
2055
|
-
" }",
|
|
2056
|
-
" }",
|
|
2057
|
-
"}",
|
|
1687
|
+
...$exports,
|
|
2058
1688
|
"",
|
|
2059
1689
|
"/* @anchor:file:end */"
|
|
2060
1690
|
].join("\n");
|
|
2061
1691
|
}
|
|
2062
1692
|
};
|
|
2063
1693
|
|
|
2064
|
-
// src/transformers/api-document/
|
|
2065
|
-
var
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
return new NestjsClientRenderer(document, options).render();
|
|
2071
|
-
}
|
|
2072
|
-
};
|
|
1694
|
+
// src/transformers/api-document/nestjs-client.renderer.ts
|
|
1695
|
+
var R18 = __toESM(require("ramda"), 1);
|
|
1696
|
+
var changeCase2 = __toESM(require("change-case"), 1);
|
|
1697
|
+
|
|
1698
|
+
// src/transformers/api-document/nestjs-module.renderer.ts
|
|
1699
|
+
var changeCase3 = __toESM(require("change-case"), 1);
|
|
2073
1700
|
|
|
2074
1701
|
// src/plugins/generate-declaration/generators/schema-declaration/schema.generator.ts
|
|
2075
|
-
var
|
|
2076
|
-
var
|
|
1702
|
+
var R19 = __toESM(require("ramda"), 1);
|
|
1703
|
+
var path6 = __toESM(require("path"), 1);
|
|
2077
1704
|
var changeCase4 = __toESM(require("change-case"), 1);
|
|
2078
1705
|
|
|
2079
1706
|
// src/plugins/generate-declaration/constants/metadata-storage.ts
|
|
2080
|
-
var
|
|
1707
|
+
var MetadataStorage4 = /* @__PURE__ */ new WeakMap();
|
|
2081
1708
|
|
|
2082
1709
|
// src/plugins/generate-declaration/generators/schema-declaration/schema.generator.ts
|
|
2083
1710
|
var SCHEMA_GENERATOR = "schemaGenerator";
|
|
2084
1711
|
var SchemaDeclarationGenerator = class _SchemaDeclarationGenerator {
|
|
2085
1712
|
async compile(compiler, task) {
|
|
2086
1713
|
const context = compiler.context;
|
|
2087
|
-
const metadata =
|
|
1714
|
+
const metadata = MetadataStorage4.get(compiler);
|
|
2088
1715
|
const rc = context.rc;
|
|
2089
1716
|
const documents = context.documents;
|
|
2090
1717
|
const schemaDefinitions = documents.flatMap((document) => document.schemas);
|
|
@@ -2100,7 +1727,7 @@ var SchemaDeclarationGenerator = class _SchemaDeclarationGenerator {
|
|
|
2100
1727
|
])
|
|
2101
1728
|
)
|
|
2102
1729
|
);
|
|
2103
|
-
const entrypoints =
|
|
1730
|
+
const entrypoints = R19.collectBy(
|
|
2104
1731
|
(schemaDefinition) => schemaDefinition.module.name,
|
|
2105
1732
|
schemaDefinitions
|
|
2106
1733
|
).map((schemaDefinitions2) => [
|
|
@@ -2115,7 +1742,7 @@ var SchemaDeclarationGenerator = class _SchemaDeclarationGenerator {
|
|
|
2115
1742
|
}
|
|
2116
1743
|
generateSchemaDefinitionsArtifact(schemaDefinition, rc) {
|
|
2117
1744
|
const filepath = _SchemaDeclarationGenerator.getSchemaDefinitionArtifactFilepath(schemaDefinition, rc.fileNamingStyle);
|
|
2118
|
-
const dirpath =
|
|
1745
|
+
const dirpath = path6.dirname(filepath);
|
|
2119
1746
|
const artifact = new Artifact({
|
|
2120
1747
|
id: _SchemaDeclarationGenerator.getSchemaDefinitionArtifactId(schemaDefinition),
|
|
2121
1748
|
filepath,
|
|
@@ -2124,7 +1751,7 @@ var SchemaDeclarationGenerator = class _SchemaDeclarationGenerator {
|
|
|
2124
1751
|
{
|
|
2125
1752
|
esm: rc.esm,
|
|
2126
1753
|
getDependentSchemaDefinitionFilepath(dependentSchemaDefinition) {
|
|
2127
|
-
const relativePath =
|
|
1754
|
+
const relativePath = path6.relative(
|
|
2128
1755
|
dirpath,
|
|
2129
1756
|
_SchemaDeclarationGenerator.getSchemaDefinitionArtifactFilepath(dependentSchemaDefinition, rc.fileNamingStyle)
|
|
2130
1757
|
);
|
|
@@ -2138,7 +1765,7 @@ var SchemaDeclarationGenerator = class _SchemaDeclarationGenerator {
|
|
|
2138
1765
|
}
|
|
2139
1766
|
generateEntrypointArtifact(moduleDefinition, exports2, rc) {
|
|
2140
1767
|
const filepath = _SchemaDeclarationGenerator.getEntrypointArtifactFilepath(moduleDefinition, rc.fileNamingStyle);
|
|
2141
|
-
const dirpath =
|
|
1768
|
+
const dirpath = path6.dirname(filepath);
|
|
2142
1769
|
const artifact = new Artifact({
|
|
2143
1770
|
id: _SchemaDeclarationGenerator.getEntrypointArtifactId(moduleDefinition),
|
|
2144
1771
|
filepath,
|
|
@@ -2157,7 +1784,7 @@ var SchemaDeclarationGenerator = class _SchemaDeclarationGenerator {
|
|
|
2157
1784
|
].join("/");
|
|
2158
1785
|
}
|
|
2159
1786
|
static getEntrypointArtifactId(moduleDefinition) {
|
|
2160
|
-
return `${moduleDefinition.address}/components/schemas/entrypoint?generator=${SCHEMA_GENERATOR}`;
|
|
1787
|
+
return `${moduleDefinition.address.url}/components/schemas/entrypoint?generator=${SCHEMA_GENERATOR}`;
|
|
2161
1788
|
}
|
|
2162
1789
|
static getSchemaDefinitionArtifactFilepath(schemaDefinition, fileNamingStyle) {
|
|
2163
1790
|
const filename = `${changeCase4[fileNamingStyle](schemaDefinition.name)}.schema.ts`;
|
|
@@ -2180,7 +1807,7 @@ var OPERATION_GENERATOR = "operationDeclarationGenerator";
|
|
|
2180
1807
|
var OperationDeclarationGenerator = class _OperationDeclarationGenerator {
|
|
2181
1808
|
async compile(compiler, task) {
|
|
2182
1809
|
const context = compiler.context;
|
|
2183
|
-
const metadata =
|
|
1810
|
+
const metadata = MetadataStorage4.get(compiler);
|
|
2184
1811
|
const rc = context.rc;
|
|
2185
1812
|
const documents = context.documents;
|
|
2186
1813
|
const operationDefinitions = documents.flatMap((document) => document.operations);
|
|
@@ -2200,7 +1827,7 @@ var OperationDeclarationGenerator = class _OperationDeclarationGenerator {
|
|
|
2200
1827
|
}
|
|
2201
1828
|
generateOperationDefinitionArtifact(operationDefinition, rc) {
|
|
2202
1829
|
const filepath = _OperationDeclarationGenerator.getOperationDefinitionArtifactFilepath(operationDefinition, rc.fileNamingStyle);
|
|
2203
|
-
const dirpath =
|
|
1830
|
+
const dirpath = path7.dirname(filepath);
|
|
2204
1831
|
const artifact = new Artifact({
|
|
2205
1832
|
id: _OperationDeclarationGenerator.getOperationDefinitionArtifactId(operationDefinition),
|
|
2206
1833
|
filepath,
|
|
@@ -2209,7 +1836,7 @@ var OperationDeclarationGenerator = class _OperationDeclarationGenerator {
|
|
|
2209
1836
|
{
|
|
2210
1837
|
esm: rc.esm,
|
|
2211
1838
|
getDependentSchemaDefinitionFilepath(dependentSchemaDefinition) {
|
|
2212
|
-
const relativePath =
|
|
1839
|
+
const relativePath = path7.relative(
|
|
2213
1840
|
dirpath,
|
|
2214
1841
|
SchemaDeclarationGenerator.getSchemaDefinitionArtifactFilepath(dependentSchemaDefinition, rc.fileNamingStyle)
|
|
2215
1842
|
);
|
|
@@ -2223,7 +1850,7 @@ var OperationDeclarationGenerator = class _OperationDeclarationGenerator {
|
|
|
2223
1850
|
}
|
|
2224
1851
|
generateEntrypointArtifact(moduleDefinition, exports2, rc) {
|
|
2225
1852
|
const filepath = _OperationDeclarationGenerator.getEntrypointArtifactFilepath(moduleDefinition, rc.fileNamingStyle);
|
|
2226
|
-
const dirpath =
|
|
1853
|
+
const dirpath = path7.dirname(filepath);
|
|
2227
1854
|
const artifact = new Artifact({
|
|
2228
1855
|
id: _OperationDeclarationGenerator.getEntrypointArtifactId(moduleDefinition),
|
|
2229
1856
|
filepath,
|
|
@@ -2255,7 +1882,7 @@ var OperationDeclarationGenerator = class _OperationDeclarationGenerator {
|
|
|
2255
1882
|
].join("/");
|
|
2256
1883
|
}
|
|
2257
1884
|
static getEntrypointArtifactId(moduleDefinition) {
|
|
2258
|
-
return `${moduleDefinition.address}/paths/entrypoint?generator=${OPERATION_GENERATOR}`;
|
|
1885
|
+
return `${moduleDefinition.address.url}/paths/entrypoint?generator=${OPERATION_GENERATOR}`;
|
|
2259
1886
|
}
|
|
2260
1887
|
};
|
|
2261
1888
|
|
|
@@ -2268,6 +1895,7 @@ var GenerateDeclarationPlugin = class _GenerateDeclarationPlugin {
|
|
|
2268
1895
|
constructor() {
|
|
2269
1896
|
}
|
|
2270
1897
|
apply(compiler) {
|
|
1898
|
+
if (MetadataStorage4.has(compiler)) return;
|
|
2271
1899
|
_GenerateDeclarationPlugin.register(compiler);
|
|
2272
1900
|
compiler.hooks.compile.tapPromise(_GenerateDeclarationPlugin.name, async (task) => {
|
|
2273
1901
|
compiler.context.artifacts?.push(
|
|
@@ -2277,8 +1905,8 @@ var GenerateDeclarationPlugin = class _GenerateDeclarationPlugin {
|
|
|
2277
1905
|
});
|
|
2278
1906
|
}
|
|
2279
1907
|
static register(compiler) {
|
|
2280
|
-
if (!
|
|
2281
|
-
|
|
1908
|
+
if (!MetadataStorage4.has(compiler)) {
|
|
1909
|
+
MetadataStorage4.set(compiler, {
|
|
2282
1910
|
hooks: {
|
|
2283
1911
|
afterEntrypointArtifactGenerated: new import_tapable.AsyncSeriesWaterfallHook(["artifact", "task"]),
|
|
2284
1912
|
afterSchemaDeclarationArtifactGenerated: new import_tapable.AsyncSeriesWaterfallHook(["artifact", "schemaDefinition", "task"]),
|
|
@@ -2286,7 +1914,7 @@ var GenerateDeclarationPlugin = class _GenerateDeclarationPlugin {
|
|
|
2286
1914
|
}
|
|
2287
1915
|
});
|
|
2288
1916
|
}
|
|
2289
|
-
return
|
|
1917
|
+
return MetadataStorage4.get(compiler);
|
|
2290
1918
|
}
|
|
2291
1919
|
static of(compiler) {
|
|
2292
1920
|
return this.register(compiler);
|
|
@@ -2331,7 +1959,7 @@ var RequestGenerator = class _RequestGenerator {
|
|
|
2331
1959
|
var MICRO_FUNCTION_GENERATOR = "microFunctionGenerator";
|
|
2332
1960
|
var MicroFunctionGenerator = class _MicroFunctionGenerator {
|
|
2333
1961
|
async compile(compiler, task) {
|
|
2334
|
-
const metadata =
|
|
1962
|
+
const metadata = MetadataStorage3.get(compiler);
|
|
2335
1963
|
const context = compiler.context;
|
|
2336
1964
|
const rc = context.rc;
|
|
2337
1965
|
const documents = context.documents;
|
|
@@ -2349,7 +1977,7 @@ var MicroFunctionGenerator = class _MicroFunctionGenerator {
|
|
|
2349
1977
|
)
|
|
2350
1978
|
);
|
|
2351
1979
|
const entrypoints = await Promise.all(
|
|
2352
|
-
|
|
1980
|
+
R20.collectBy(
|
|
2353
1981
|
(operationDefinition) => operationDefinition.module.name,
|
|
2354
1982
|
operationDefinitions
|
|
2355
1983
|
).map((operationDefinitions2) => [
|
|
@@ -2368,21 +1996,21 @@ var MicroFunctionGenerator = class _MicroFunctionGenerator {
|
|
|
2368
1996
|
}
|
|
2369
1997
|
generateOperationDefinitionArtifact(operationDefinition, rc) {
|
|
2370
1998
|
const filepath = _MicroFunctionGenerator.getOperationDefinitionArtifactFilepath(operationDefinition, rc.fileNamingStyle);
|
|
2371
|
-
const dirpath =
|
|
1999
|
+
const dirpath = path8.dirname(filepath);
|
|
2372
2000
|
const artifact = new Artifact({
|
|
2373
2001
|
id: _MicroFunctionGenerator.getOperationDefinitionArtifactId(operationDefinition),
|
|
2374
2002
|
filepath,
|
|
2375
2003
|
content: OperationDefinitionTransformer.toMicroFunction(operationDefinition, {
|
|
2376
2004
|
esm: rc.esm,
|
|
2377
2005
|
getOperationDefinitionDeclarationFilepath(operationDefinition2) {
|
|
2378
|
-
const relativePath =
|
|
2006
|
+
const relativePath = path8.relative(
|
|
2379
2007
|
dirpath,
|
|
2380
2008
|
OperationDeclarationGenerator.getOperationDefinitionArtifactFilepath(operationDefinition2, rc.fileNamingStyle)
|
|
2381
2009
|
);
|
|
2382
2010
|
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
2383
2011
|
},
|
|
2384
2012
|
getRequestFilepath() {
|
|
2385
|
-
const relativePath =
|
|
2013
|
+
const relativePath = path8.relative(
|
|
2386
2014
|
dirpath,
|
|
2387
2015
|
RequestGenerator.getRequestArtifactFilepath()
|
|
2388
2016
|
);
|
|
@@ -2434,6 +2062,7 @@ var GenerateMicroFunctionPlugin = class _GenerateMicroFunctionPlugin {
|
|
|
2434
2062
|
microFunctionGenerator = new MicroFunctionGenerator();
|
|
2435
2063
|
requestGenerator = new RequestGenerator();
|
|
2436
2064
|
apply(compiler) {
|
|
2065
|
+
if (MetadataStorage3.has(compiler)) return;
|
|
2437
2066
|
_GenerateMicroFunctionPlugin.register(compiler);
|
|
2438
2067
|
compiler.hooks.compile.tapPromise(_GenerateMicroFunctionPlugin.name, async (task) => {
|
|
2439
2068
|
const artifacts = [
|
|
@@ -2444,15 +2073,15 @@ var GenerateMicroFunctionPlugin = class _GenerateMicroFunctionPlugin {
|
|
|
2444
2073
|
});
|
|
2445
2074
|
}
|
|
2446
2075
|
static register(compiler) {
|
|
2447
|
-
if (!
|
|
2448
|
-
|
|
2076
|
+
if (!MetadataStorage3.has(compiler)) {
|
|
2077
|
+
MetadataStorage3.set(compiler, {
|
|
2449
2078
|
hooks: {
|
|
2450
2079
|
afterEntrypointArtifactGenerated: new import_tapable2.AsyncSeriesWaterfallHook(["artifact", "task"]),
|
|
2451
2080
|
afterMicroFunctionArtifactGenerated: new import_tapable2.AsyncSeriesWaterfallHook(["artifact", "operationDefinition", "task"])
|
|
2452
2081
|
}
|
|
2453
2082
|
});
|
|
2454
2083
|
}
|
|
2455
|
-
return
|
|
2084
|
+
return MetadataStorage3.get(compiler);
|
|
2456
2085
|
}
|
|
2457
2086
|
static of(compiler) {
|
|
2458
2087
|
return this.register(compiler);
|
|
@@ -2462,328 +2091,646 @@ var GenerateMicroFunctionPlugin = class _GenerateMicroFunctionPlugin {
|
|
|
2462
2091
|
// src/plugins/generate-nestjs-module/generate-nestjs-module.ts
|
|
2463
2092
|
var import_tapable3 = require("tapable");
|
|
2464
2093
|
|
|
2465
|
-
// src/plugins/generate-nestjs-module/constants/metadata-storage.ts
|
|
2466
|
-
var MetadataStorage3 = /* @__PURE__ */ new WeakMap();
|
|
2467
|
-
|
|
2468
2094
|
// src/plugins/generate-nestjs-module/generators/nestjs-module.generator.ts
|
|
2469
|
-
var path11 = __toESM(require("path"), 1);
|
|
2470
2095
|
var changeCase7 = __toESM(require("change-case"), 1);
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2096
|
+
|
|
2097
|
+
// src/plugins/chinese-to-pinyin/chinese-to-pinyin.plugin.ts
|
|
2098
|
+
var import_swagger_fix = require("swagger-fix");
|
|
2099
|
+
|
|
2100
|
+
// src/plugins/download-http-file/constants/metadata-storage.ts
|
|
2101
|
+
var MetadataStorage8 = /* @__PURE__ */ new WeakMap();
|
|
2102
|
+
|
|
2103
|
+
// src/plugins/download-http-file/download-http-file.plugin.ts
|
|
2104
|
+
var DownloadHttpFilePlugin = class _DownloadHttpFilePlugin {
|
|
2105
|
+
apply(compiler) {
|
|
2106
|
+
if (MetadataStorage8.has(compiler)) return;
|
|
2107
|
+
_DownloadHttpFilePlugin.register(compiler);
|
|
2108
|
+
compiler.hooks.download.tapPromise(_DownloadHttpFilePlugin.name, async (address, task) => {
|
|
2109
|
+
const { url } = address;
|
|
2110
|
+
if (!url.startsWith("http://") && !url.startsWith("https://")) return void 0;
|
|
2111
|
+
const content = await this.download(address);
|
|
2112
|
+
const spec = this.deserialize(content);
|
|
2113
|
+
return JSON.stringify(spec);
|
|
2489
2114
|
});
|
|
2490
|
-
return artifact;
|
|
2491
2115
|
}
|
|
2492
|
-
|
|
2493
|
-
const
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2116
|
+
async download(address) {
|
|
2117
|
+
const { url, headers } = address;
|
|
2118
|
+
try {
|
|
2119
|
+
const res = await fetch(url, { headers });
|
|
2120
|
+
if (res.status >= 400) throw new Error(`failed with status code ${res.status}`);
|
|
2121
|
+
return await res.text();
|
|
2122
|
+
} catch (e) {
|
|
2123
|
+
if (e instanceof Error) {
|
|
2124
|
+
e.message = `Unable get the openapi/swagger file from ${url}: ${e.message}`;
|
|
2125
|
+
}
|
|
2126
|
+
throw e;
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
deserialize(content) {
|
|
2130
|
+
const json = JSON.parse(content);
|
|
2131
|
+
const spec = OpenapiUtils.to3_1(json);
|
|
2132
|
+
return spec;
|
|
2133
|
+
}
|
|
2134
|
+
static register(compiler) {
|
|
2135
|
+
if (!MetadataStorage8.has(compiler)) {
|
|
2136
|
+
MetadataStorage8.set(compiler, {
|
|
2137
|
+
hooks: {}
|
|
2138
|
+
});
|
|
2139
|
+
}
|
|
2140
|
+
return MetadataStorage8.get(compiler);
|
|
2141
|
+
}
|
|
2142
|
+
static of(compiler) {
|
|
2143
|
+
return this.register(compiler);
|
|
2144
|
+
}
|
|
2145
|
+
};
|
|
2146
|
+
|
|
2147
|
+
// src/plugins/download-local-file/download-local-file.plugin.ts
|
|
2148
|
+
var path9 = __toESM(require("path"), 1);
|
|
2149
|
+
var fs3 = __toESM(require("fs/promises"), 1);
|
|
2150
|
+
var yaml = __toESM(require("js-yaml"), 1);
|
|
2151
|
+
var import_url = require("url");
|
|
2152
|
+
|
|
2153
|
+
// src/plugins/download-local-file/constants/metadata-storage.ts
|
|
2154
|
+
var MetadataStorage9 = /* @__PURE__ */ new WeakMap();
|
|
2155
|
+
|
|
2156
|
+
// src/plugins/download-local-file/download-local-file.plugin.ts
|
|
2157
|
+
var DownloadLocalFilePlugin = class _DownloadLocalFilePlugin {
|
|
2158
|
+
apply(compiler) {
|
|
2159
|
+
if (MetadataStorage9.has(compiler)) return;
|
|
2160
|
+
_DownloadLocalFilePlugin.register(compiler);
|
|
2161
|
+
compiler.hooks.download.tapPromise(_DownloadLocalFilePlugin.name, async (address, task) => {
|
|
2162
|
+
const { url, encoding } = address;
|
|
2163
|
+
if (!url.startsWith("file://")) return void 0;
|
|
2164
|
+
const filepath = (0, import_url.fileURLToPath)(url);
|
|
2165
|
+
const fileExt = path9.extname(filepath);
|
|
2166
|
+
const content = await fs3.readFile(filepath, encoding);
|
|
2167
|
+
const str = typeof content === "string" ? content : content.toString(encoding);
|
|
2168
|
+
if ([".yml", ".yaml"].includes(fileExt)) {
|
|
2169
|
+
const value = yaml.load(str);
|
|
2170
|
+
return JSON.stringify(OpenapiUtils.to3_1(value));
|
|
2171
|
+
} else if (fileExt === ".json") {
|
|
2172
|
+
return JSON.stringify(OpenapiUtils.to3_1(JSON.parse(str)));
|
|
2173
|
+
}
|
|
2508
2174
|
});
|
|
2509
|
-
return artifact;
|
|
2510
2175
|
}
|
|
2511
|
-
|
|
2512
|
-
|
|
2176
|
+
static register(compiler) {
|
|
2177
|
+
if (!MetadataStorage9.has(compiler)) {
|
|
2178
|
+
MetadataStorage9.set(compiler, {
|
|
2179
|
+
hooks: {}
|
|
2180
|
+
});
|
|
2181
|
+
}
|
|
2182
|
+
return MetadataStorage9.get(compiler);
|
|
2183
|
+
}
|
|
2184
|
+
static of(compiler) {
|
|
2185
|
+
return this.register(compiler);
|
|
2186
|
+
}
|
|
2187
|
+
};
|
|
2188
|
+
|
|
2189
|
+
// src/plugins/shaking/shaking.plugin.ts
|
|
2190
|
+
var import_openapi_shaking = require("@opendoc/openapi-shaking");
|
|
2191
|
+
|
|
2192
|
+
// src/plugins/shaking/constants/metadata-storage.ts
|
|
2193
|
+
var MetadataStorage10 = /* @__PURE__ */ new WeakMap();
|
|
2194
|
+
|
|
2195
|
+
// src/plugins/shaking/shaking.plugin.ts
|
|
2196
|
+
var ShakingPlugin = class _ShakingPlugin {
|
|
2197
|
+
apply(compiler) {
|
|
2198
|
+
if (MetadataStorage10.has(compiler)) return;
|
|
2199
|
+
_ShakingPlugin.register(compiler);
|
|
2200
|
+
compiler.hooks.beforeCompile.tap(_ShakingPlugin.name, (task) => {
|
|
2201
|
+
const matcher = compiler.context.matcher;
|
|
2202
|
+
const documents = compiler.context.documents;
|
|
2203
|
+
compiler.context.documents = documents.map((document) => this.shaking(compiler, document)).filter((document) => !document.isEmpty()).filter((document) => !matcher.isModuleIgnored(document.module));
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
shaking(compiler, document) {
|
|
2513
2207
|
const rc = compiler.context.rc;
|
|
2514
|
-
const
|
|
2515
|
-
const
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2208
|
+
const matcher = compiler.context.matcher;
|
|
2209
|
+
const isAccepted = (pathname, method, operation) => {
|
|
2210
|
+
if (!SupportedMethods.includes(method)) return false;
|
|
2211
|
+
return !matcher.isOperationIgnored(new OperationDefinition({
|
|
2212
|
+
method,
|
|
2213
|
+
pathname,
|
|
2214
|
+
operation,
|
|
2215
|
+
module: document.module,
|
|
2216
|
+
document
|
|
2217
|
+
}));
|
|
2218
|
+
};
|
|
2219
|
+
const sharkedSwagger = (0, import_openapi_shaking.openapiShakingSync)(
|
|
2220
|
+
document.specification,
|
|
2221
|
+
isAccepted,
|
|
2222
|
+
{ tolerant: rc.tolerant }
|
|
2521
2223
|
);
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
document,
|
|
2526
|
-
|
|
2527
|
-
|
|
2224
|
+
return new ApiDocumentV3_1(
|
|
2225
|
+
sharkedSwagger,
|
|
2226
|
+
new ModuleDefinition(
|
|
2227
|
+
document.module.name,
|
|
2228
|
+
{
|
|
2229
|
+
url: `memory://${document.module.name}.v3_1.sharked.json`,
|
|
2230
|
+
headers: {},
|
|
2231
|
+
encoding: "utf8"
|
|
2232
|
+
}
|
|
2233
|
+
)
|
|
2528
2234
|
);
|
|
2529
|
-
return [...nestjsModuleArtifacts, ...nestjsClientArtifacts];
|
|
2530
2235
|
}
|
|
2531
|
-
static
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
return filepath.join("/");
|
|
2236
|
+
static register(compiler) {
|
|
2237
|
+
if (!MetadataStorage10.has(compiler)) {
|
|
2238
|
+
MetadataStorage10.set(compiler, {
|
|
2239
|
+
hooks: {}
|
|
2240
|
+
});
|
|
2241
|
+
}
|
|
2242
|
+
return MetadataStorage10.get(compiler);
|
|
2539
2243
|
}
|
|
2540
|
-
static
|
|
2541
|
-
return
|
|
2244
|
+
static of(compiler) {
|
|
2245
|
+
return this.register(compiler);
|
|
2542
2246
|
}
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2247
|
+
};
|
|
2248
|
+
|
|
2249
|
+
// src/plugins/terminal-select/utils/select-operation-definitions.ts
|
|
2250
|
+
var import_inquirer_select_pro = require("inquirer-select-pro");
|
|
2251
|
+
var import_prompt_adapter_inquirer = require("@listr2/prompt-adapter-inquirer");
|
|
2252
|
+
async function selectOperationDefinitions(task, operationDefinitions) {
|
|
2253
|
+
const selectedOperationDefinitions = await task.prompt(import_prompt_adapter_inquirer.ListrInquirerPromptAdapter).run(
|
|
2254
|
+
import_inquirer_select_pro.select,
|
|
2255
|
+
{
|
|
2256
|
+
message: "Select Pathname",
|
|
2257
|
+
defaultValue: [],
|
|
2258
|
+
options: (input) => {
|
|
2259
|
+
const items = operationDefinitions.map((op) => ({ name: `${op.module.name} ${op.method.toUpperCase()} ${op.pathname}`, value: op }));
|
|
2260
|
+
if (!input) return items;
|
|
2261
|
+
const keys2 = input.trim().toLowerCase().split(/\s+/);
|
|
2262
|
+
return items.filter((i) => {
|
|
2263
|
+
const name = i.name.toLowerCase();
|
|
2264
|
+
return keys2.every((q) => name.includes(q));
|
|
2265
|
+
});
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
);
|
|
2269
|
+
return selectedOperationDefinitions;
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
// src/plugins/terminal-select/constants/metadata-storage.ts
|
|
2273
|
+
var MetadataStorage11 = /* @__PURE__ */ new WeakMap();
|
|
2274
|
+
|
|
2275
|
+
// src/plugins/terminal-select/terminal-select.plugin.ts
|
|
2276
|
+
var TerminalSelectPlugin = class _TerminalSelectPlugin {
|
|
2277
|
+
constructor(options) {
|
|
2278
|
+
this.options = options;
|
|
2279
|
+
}
|
|
2280
|
+
apply(compiler) {
|
|
2281
|
+
if (MetadataStorage11.has(compiler)) return;
|
|
2282
|
+
_TerminalSelectPlugin.register(compiler);
|
|
2283
|
+
compiler.hooks.afterDownload.tapPromise(_TerminalSelectPlugin.name, async (task) => {
|
|
2284
|
+
const context = compiler.context;
|
|
2285
|
+
const matcher = context.matcher;
|
|
2286
|
+
const documents = context.documents;
|
|
2287
|
+
const operationDefinitions = documents.flatMap((document) => document.operations);
|
|
2288
|
+
const selectedOperationDefinitions = await selectOperationDefinitions(task, operationDefinitions);
|
|
2289
|
+
if (this.options.clear) {
|
|
2290
|
+
matcher.append({
|
|
2291
|
+
persist: false,
|
|
2292
|
+
ignore: true,
|
|
2293
|
+
moduleName: "*",
|
|
2294
|
+
operationMethod: "*",
|
|
2295
|
+
operationPathname: "*"
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
for (const op of selectedOperationDefinitions) {
|
|
2299
|
+
matcher.append({
|
|
2300
|
+
persist: !!this.options.persist,
|
|
2301
|
+
ignore: this.options.mode === "add",
|
|
2302
|
+
moduleName: op.module.name,
|
|
2303
|
+
operationMethod: op.method,
|
|
2304
|
+
operationPathname: op.pathname
|
|
2305
|
+
});
|
|
2306
|
+
}
|
|
2307
|
+
});
|
|
2308
|
+
}
|
|
2309
|
+
static register(compiler) {
|
|
2310
|
+
if (!MetadataStorage11.has(compiler)) {
|
|
2311
|
+
MetadataStorage11.set(compiler, {
|
|
2312
|
+
hooks: {}
|
|
2313
|
+
});
|
|
2314
|
+
}
|
|
2315
|
+
return MetadataStorage11.get(compiler);
|
|
2551
2316
|
}
|
|
2552
|
-
static
|
|
2553
|
-
return
|
|
2317
|
+
static of(compiler) {
|
|
2318
|
+
return this.register(compiler);
|
|
2554
2319
|
}
|
|
2555
2320
|
};
|
|
2556
2321
|
|
|
2557
|
-
// src/plugins/
|
|
2558
|
-
var
|
|
2559
|
-
|
|
2322
|
+
// src/plugins/initialize/initialize.plugin.ts
|
|
2323
|
+
var R22 = __toESM(require("ramda"), 1);
|
|
2324
|
+
var InitializePlugin = class _InitializePlugin {
|
|
2325
|
+
constructor(options) {
|
|
2326
|
+
this.options = options;
|
|
2327
|
+
}
|
|
2560
2328
|
apply(compiler) {
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2329
|
+
compiler.hooks.setup.tap(_InitializePlugin.name, (task) => {
|
|
2330
|
+
const plugins = [
|
|
2331
|
+
new DownloadHttpFilePlugin(),
|
|
2332
|
+
new DownloadLocalFilePlugin()
|
|
2333
|
+
];
|
|
2334
|
+
if (this.options.build) {
|
|
2335
|
+
plugins.push(new ShakingPlugin());
|
|
2336
|
+
}
|
|
2337
|
+
if (this.options.interactive) {
|
|
2338
|
+
plugins.push(
|
|
2339
|
+
new TerminalSelectPlugin(
|
|
2340
|
+
typeof this.options.interactive === "object" ? this.options.interactive : { mode: "except" }
|
|
2341
|
+
)
|
|
2342
|
+
);
|
|
2343
|
+
}
|
|
2344
|
+
const rc = compiler.context.rc;
|
|
2345
|
+
plugins.push(
|
|
2346
|
+
...R22.unnest(
|
|
2347
|
+
(rc.translators || []).map((translator) => {
|
|
2348
|
+
const plugins2 = translator.apply();
|
|
2349
|
+
return plugins2;
|
|
2350
|
+
})
|
|
2351
|
+
)
|
|
2352
|
+
);
|
|
2353
|
+
if (rc.plugins && rc.plugins.length) {
|
|
2354
|
+
plugins.push(...rc.plugins);
|
|
2355
|
+
}
|
|
2356
|
+
for (const plugin of plugins) {
|
|
2357
|
+
plugin.apply(compiler);
|
|
2358
|
+
}
|
|
2565
2359
|
});
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2360
|
+
if (this.options.includes && this.options.includes.length) {
|
|
2361
|
+
const modulesIncludes = this.options.includes;
|
|
2362
|
+
compiler.hooks.afterSetup.tap(_InitializePlugin.name, (task) => {
|
|
2363
|
+
const rc = compiler.context.rc;
|
|
2364
|
+
const matcher = compiler.context.matcher;
|
|
2365
|
+
const notExistModules = modulesIncludes.filter((moduleName) => !(moduleName in rc.modules));
|
|
2366
|
+
if (notExistModules.length) {
|
|
2367
|
+
throw new Error(`Cannot find module(s) ${notExistModules.join(", ")} in config file.`);
|
|
2368
|
+
}
|
|
2369
|
+
const ignoredModules = R22.difference(R22.keys(rc.modules), modulesIncludes);
|
|
2370
|
+
for (const moduleName of ignoredModules) {
|
|
2371
|
+
matcher.append({
|
|
2372
|
+
persist: false,
|
|
2373
|
+
ignore: true,
|
|
2374
|
+
moduleName,
|
|
2375
|
+
operationMethod: "*",
|
|
2376
|
+
operationPathname: "*"
|
|
2377
|
+
});
|
|
2572
2378
|
}
|
|
2573
2379
|
});
|
|
2574
2380
|
}
|
|
2575
|
-
return MetadataStorage3.get(compiler);
|
|
2576
|
-
}
|
|
2577
|
-
static of(compiler) {
|
|
2578
|
-
return MetadataStorage3.get(compiler);
|
|
2579
2381
|
}
|
|
2580
2382
|
};
|
|
2581
2383
|
|
|
2582
|
-
// src/plugins/
|
|
2583
|
-
var
|
|
2384
|
+
// src/plugins/overwrite-query-options/overwrite-query-options.plugin.ts
|
|
2385
|
+
var QsArrayFormatUnion = Object.values(QsArrayFormat);
|
|
2584
2386
|
|
|
2585
|
-
// src/
|
|
2586
|
-
var
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
const spec = this.deserialize(content);
|
|
2593
|
-
return JSON.stringify(spec);
|
|
2594
|
-
});
|
|
2387
|
+
// src/translators/micro-function.translator.ts
|
|
2388
|
+
var MicroFunctionTranslator = class {
|
|
2389
|
+
apply() {
|
|
2390
|
+
return [
|
|
2391
|
+
new GenerateDeclarationPlugin(),
|
|
2392
|
+
new GenerateMicroFunctionPlugin()
|
|
2393
|
+
];
|
|
2595
2394
|
}
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2395
|
+
};
|
|
2396
|
+
|
|
2397
|
+
// src/compiler/tasks/setup/index.ts
|
|
2398
|
+
var explore = (0, import_cosmiconfig.cosmiconfig)("keq");
|
|
2399
|
+
function main(compiler, options) {
|
|
2400
|
+
return {
|
|
2401
|
+
task: async (context, task) => {
|
|
2402
|
+
const result = options?.config ? await explore.load(options.config) : await explore.search();
|
|
2403
|
+
if (!result || "isEmpty" in result && result.isEmpty) {
|
|
2404
|
+
throw new Error("Cannot find config file.");
|
|
2604
2405
|
}
|
|
2605
|
-
|
|
2406
|
+
const rc = parseRuntimeConfig(result.config);
|
|
2407
|
+
if (options?.debug) {
|
|
2408
|
+
await import_fs_extra2.default.ensureDir(".keq");
|
|
2409
|
+
rc.debug = true;
|
|
2410
|
+
}
|
|
2411
|
+
rc.tolerant = Boolean(rc.tolerant);
|
|
2412
|
+
if (!rc.translators || !rc.translators.length) {
|
|
2413
|
+
rc.translators = [new MicroFunctionTranslator()];
|
|
2414
|
+
}
|
|
2415
|
+
const packageJsonInfo = findNearestPackageJson();
|
|
2416
|
+
if (packageJsonInfo) {
|
|
2417
|
+
const moduleSystem = getProjectModuleSystem(packageJsonInfo);
|
|
2418
|
+
rc.esm = moduleSystem === "esm";
|
|
2419
|
+
}
|
|
2420
|
+
context.rc = rc;
|
|
2421
|
+
let matcher = new IgnoreMatcher([]);
|
|
2422
|
+
if (result.filepath) {
|
|
2423
|
+
const ignoreFilepath = import_path.default.resolve(import_path.default.dirname(result.filepath), ".keqignore");
|
|
2424
|
+
if (await import_fs_extra2.default.exists(ignoreFilepath)) {
|
|
2425
|
+
matcher = await IgnoreMatcher.read(ignoreFilepath);
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
const ignoreRules = options.ignore === false ? [] : options.ignore?.rules || [];
|
|
2429
|
+
for (const rule of ignoreRules) {
|
|
2430
|
+
matcher.append({
|
|
2431
|
+
persist: !!rule.persist,
|
|
2432
|
+
ignore: rule.ignore,
|
|
2433
|
+
moduleName: rule.moduleName,
|
|
2434
|
+
operationMethod: rule.operationMethod,
|
|
2435
|
+
operationPathname: rule.operationPathname
|
|
2436
|
+
});
|
|
2437
|
+
}
|
|
2438
|
+
context.matcher = matcher;
|
|
2439
|
+
await compiler.hooks.setup.promise(task);
|
|
2606
2440
|
}
|
|
2607
|
-
}
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2441
|
+
};
|
|
2442
|
+
}
|
|
2443
|
+
function createSetupTask(compiler, options) {
|
|
2444
|
+
return {
|
|
2445
|
+
title: "Setup",
|
|
2446
|
+
enabled: options?.enabled,
|
|
2447
|
+
skip: options?.skip,
|
|
2448
|
+
task: (context, task) => task.newListr(
|
|
2449
|
+
[
|
|
2450
|
+
main(compiler, options),
|
|
2451
|
+
{
|
|
2452
|
+
task: (context2, task2) => compiler.hooks.afterSetup.promise(task2)
|
|
2453
|
+
}
|
|
2454
|
+
],
|
|
2455
|
+
{
|
|
2456
|
+
concurrent: false
|
|
2457
|
+
}
|
|
2458
|
+
)
|
|
2459
|
+
};
|
|
2460
|
+
}
|
|
2614
2461
|
|
|
2615
|
-
// src/
|
|
2616
|
-
var
|
|
2617
|
-
var
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
const
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2462
|
+
// src/compiler/tasks/download/index.ts
|
|
2463
|
+
var import_listr2 = require("listr2");
|
|
2464
|
+
var import_openapi_parser2 = require("@scalar/openapi-parser");
|
|
2465
|
+
function main2(compiler, options) {
|
|
2466
|
+
return {
|
|
2467
|
+
task: (context, task) => {
|
|
2468
|
+
if (!context.rc || !context.matcher) {
|
|
2469
|
+
throw new Error("Please run setup task first.");
|
|
2470
|
+
}
|
|
2471
|
+
const rc = context.rc;
|
|
2472
|
+
const matcher = context.matcher;
|
|
2473
|
+
context.documents = [];
|
|
2474
|
+
return task.newListr(
|
|
2475
|
+
Object.entries(rc.modules).map(([moduleName, address]) => new ModuleDefinition(moduleName, address)).map((moduleDefinition) => ({
|
|
2476
|
+
title: moduleDefinition.name,
|
|
2477
|
+
task: async (ctx, task2) => {
|
|
2478
|
+
if (options?.skipIgnoredModules && matcher.isModuleIgnored(moduleDefinition)) {
|
|
2479
|
+
task2.skip(`(${moduleDefinition.name}) is ignored`);
|
|
2480
|
+
return;
|
|
2481
|
+
}
|
|
2482
|
+
task2.output = `Downloaded from ${moduleDefinition.address.url}`;
|
|
2483
|
+
const content = await compiler.hooks.download.promise(moduleDefinition.address, moduleDefinition, task2);
|
|
2484
|
+
if (!content) {
|
|
2485
|
+
throw new Exception(moduleDefinition, `Cannot download document from ${moduleDefinition.address.url}`);
|
|
2486
|
+
}
|
|
2487
|
+
const spec = JSON.parse(content);
|
|
2488
|
+
const { valid, errors } = await (0, import_openapi_parser2.validate)(spec);
|
|
2489
|
+
if (!valid) {
|
|
2490
|
+
const message = `${moduleDefinition.name} module openapi/swagger file does not conform to the openapi specifications or have grammatical errors, which may cause unexpected errors:
|
|
2491
|
+
${errors?.map((e) => ` - ${e.message}`).join("\n")}`;
|
|
2492
|
+
task2.output = message;
|
|
2493
|
+
}
|
|
2494
|
+
OpenapiUtils.dereferenceOperation(spec);
|
|
2495
|
+
const document = new ApiDocumentV3_1(
|
|
2496
|
+
spec,
|
|
2497
|
+
moduleDefinition
|
|
2498
|
+
);
|
|
2499
|
+
ctx.documents?.push(document);
|
|
2500
|
+
}
|
|
2501
|
+
})),
|
|
2502
|
+
{
|
|
2503
|
+
concurrent: true,
|
|
2504
|
+
exitOnError: false,
|
|
2505
|
+
collectErrors: "minimal",
|
|
2506
|
+
rendererOptions: {
|
|
2507
|
+
collapseSubtasks: false,
|
|
2508
|
+
// collapseSkips: false,
|
|
2509
|
+
suffixSkips: true,
|
|
2510
|
+
timer: import_listr2.PRESET_TIMER
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
);
|
|
2514
|
+
}
|
|
2515
|
+
};
|
|
2516
|
+
}
|
|
2517
|
+
function createDownloadTask(compiler, options) {
|
|
2518
|
+
return {
|
|
2519
|
+
title: "Download",
|
|
2520
|
+
enabled: options?.enabled,
|
|
2521
|
+
skip: options?.skip,
|
|
2522
|
+
task: (_, task) => task.newListr(
|
|
2523
|
+
[
|
|
2524
|
+
main2(compiler, options),
|
|
2525
|
+
{
|
|
2526
|
+
task: (context, task2) => compiler.hooks.afterDownload.promise(task2)
|
|
2527
|
+
}
|
|
2528
|
+
],
|
|
2529
|
+
{
|
|
2530
|
+
concurrent: false
|
|
2531
|
+
}
|
|
2532
|
+
)
|
|
2533
|
+
};
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
// src/compiler/tasks/persist/index.ts
|
|
2537
|
+
var path11 = __toESM(require("path"), 1);
|
|
2538
|
+
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
2539
|
+
function createPersistArtifactTask() {
|
|
2540
|
+
return {
|
|
2541
|
+
title: "Write files",
|
|
2542
|
+
task: async (context, task) => {
|
|
2543
|
+
if (!context.rc) throw new Error("Please run setup task first.");
|
|
2544
|
+
if (!context.artifacts || context.artifacts.length === 0) {
|
|
2545
|
+
task.skip("No compiled artifacts to persist.");
|
|
2546
|
+
return;
|
|
2547
|
+
}
|
|
2548
|
+
const rc = context.rc;
|
|
2549
|
+
const artifacts = context.artifacts;
|
|
2550
|
+
const total = artifacts.length;
|
|
2551
|
+
let completed = 0;
|
|
2552
|
+
const files = await Promise.all(artifacts.map(async (artifact) => {
|
|
2553
|
+
const realpath = `./${path11.join(rc.outdir, artifact.filepath)}`;
|
|
2554
|
+
await import_fs_extra3.default.ensureFile(realpath);
|
|
2555
|
+
await import_fs_extra3.default.writeFile(realpath, artifact.renderer());
|
|
2556
|
+
completed += 1;
|
|
2557
|
+
task.output = `Persisted ${completed}/${total} files`;
|
|
2558
|
+
return new Asset(path11.resolve(realpath));
|
|
2559
|
+
}));
|
|
2560
|
+
context.assets = files;
|
|
2561
|
+
}
|
|
2562
|
+
};
|
|
2563
|
+
}
|
|
2564
|
+
function createPersistIgnoreTask() {
|
|
2565
|
+
return {
|
|
2566
|
+
title: "Update .keqignore",
|
|
2567
|
+
task: async (context, task) => {
|
|
2568
|
+
if (!context.matcher) throw new Error("Please run setup task first.");
|
|
2569
|
+
const matcher = context.matcher;
|
|
2570
|
+
await matcher.write(".keqignore");
|
|
2571
|
+
}
|
|
2572
|
+
};
|
|
2573
|
+
}
|
|
2574
|
+
function main3() {
|
|
2575
|
+
return {
|
|
2576
|
+
task: (context, task) => task.newListr(
|
|
2577
|
+
[
|
|
2578
|
+
createPersistArtifactTask(),
|
|
2579
|
+
createPersistIgnoreTask()
|
|
2580
|
+
],
|
|
2581
|
+
{
|
|
2582
|
+
concurrent: true,
|
|
2583
|
+
rendererOptions: {
|
|
2584
|
+
collapseSubtasks: true
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
)
|
|
2588
|
+
};
|
|
2589
|
+
}
|
|
2590
|
+
function createPersistTask(compiler, options) {
|
|
2591
|
+
return {
|
|
2592
|
+
title: "Persist",
|
|
2593
|
+
enabled: options?.enabled,
|
|
2594
|
+
skip: options?.skip,
|
|
2595
|
+
task: (context, task) => task.newListr(
|
|
2596
|
+
[
|
|
2597
|
+
main3(),
|
|
2598
|
+
{
|
|
2599
|
+
task: (context2, task2) => compiler.hooks.afterPersist.promise(task2)
|
|
2600
|
+
}
|
|
2601
|
+
],
|
|
2602
|
+
{
|
|
2603
|
+
concurrent: false
|
|
2630
2604
|
}
|
|
2631
|
-
|
|
2632
|
-
}
|
|
2633
|
-
}
|
|
2605
|
+
)
|
|
2606
|
+
};
|
|
2607
|
+
}
|
|
2634
2608
|
|
|
2635
|
-
// src/
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
}
|
|
2644
|
-
}
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
{
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
`file://${document.module.name}.v3_1.sharked.json`
|
|
2668
|
-
)
|
|
2669
|
-
);
|
|
2670
|
-
}
|
|
2671
|
-
};
|
|
2609
|
+
// src/compiler/tasks/compile/index.ts
|
|
2610
|
+
function main4(compiler) {
|
|
2611
|
+
return {
|
|
2612
|
+
task: async (context, task) => {
|
|
2613
|
+
if (!context.rc) throw new Error("Please run setup task first.");
|
|
2614
|
+
if (!context.documents) throw new Error("Please run shaking task first.");
|
|
2615
|
+
context.artifacts = [];
|
|
2616
|
+
await compiler.hooks.compile.promise(task);
|
|
2617
|
+
}
|
|
2618
|
+
};
|
|
2619
|
+
}
|
|
2620
|
+
function createCompileTask(compiler, options) {
|
|
2621
|
+
return {
|
|
2622
|
+
title: "Compile",
|
|
2623
|
+
enabled: options?.enabled,
|
|
2624
|
+
skip: options?.skip,
|
|
2625
|
+
task: (context, task) => task.newListr(
|
|
2626
|
+
[
|
|
2627
|
+
{
|
|
2628
|
+
task: (context2, task2) => compiler.hooks.beforeCompile.promise(task2)
|
|
2629
|
+
},
|
|
2630
|
+
main4(compiler),
|
|
2631
|
+
{
|
|
2632
|
+
task: (context2, task2) => compiler.hooks.afterCompile.promise(task2)
|
|
2633
|
+
}
|
|
2634
|
+
],
|
|
2635
|
+
{
|
|
2636
|
+
concurrent: false
|
|
2637
|
+
}
|
|
2638
|
+
)
|
|
2639
|
+
};
|
|
2640
|
+
}
|
|
2672
2641
|
|
|
2673
|
-
// src/
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
{
|
|
2680
|
-
message: "Select Pathname",
|
|
2681
|
-
defaultValue: [],
|
|
2682
|
-
options: (input) => {
|
|
2683
|
-
const items = operationDefinitions.map((op) => ({ name: `${op.module.name} ${op.method.toUpperCase()} ${op.pathname}`, value: op }));
|
|
2684
|
-
if (!input) return items;
|
|
2685
|
-
const keys2 = input.trim().toLowerCase().split(/\s+/);
|
|
2686
|
-
return items.filter((i) => {
|
|
2687
|
-
const name = i.name.toLowerCase();
|
|
2688
|
-
return keys2.every((q) => name.includes(q));
|
|
2689
|
-
});
|
|
2642
|
+
// src/compiler/intercepter/print-information.ts
|
|
2643
|
+
function proxyTaskWrapper(pluginName, task) {
|
|
2644
|
+
return new Proxy(task, {
|
|
2645
|
+
set(target, prop2, value) {
|
|
2646
|
+
if (prop2 !== "output") {
|
|
2647
|
+
return Reflect.set(target, prop2, value);
|
|
2690
2648
|
}
|
|
2649
|
+
target.output = `[Plugin: ${pluginName}] ${value}`;
|
|
2650
|
+
return true;
|
|
2691
2651
|
}
|
|
2692
|
-
);
|
|
2693
|
-
return selectedOperationDefinitions;
|
|
2652
|
+
});
|
|
2694
2653
|
}
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
const selectedOperationDefinitions = await selectOperationDefinitions(task, operationDefinitions);
|
|
2708
|
-
if (this.options.clear) {
|
|
2709
|
-
matcher.append({
|
|
2710
|
-
persist: false,
|
|
2711
|
-
ignore: true,
|
|
2712
|
-
moduleName: "*",
|
|
2713
|
-
operationMethod: "*",
|
|
2714
|
-
operationPathname: "*"
|
|
2715
|
-
});
|
|
2654
|
+
function printInformation(taskIndex) {
|
|
2655
|
+
return {
|
|
2656
|
+
register: (tap) => {
|
|
2657
|
+
const fn = tap.fn;
|
|
2658
|
+
if (tap.type === "promise") {
|
|
2659
|
+
tap.fn = (...args) => {
|
|
2660
|
+
const task = args[taskIndex];
|
|
2661
|
+
const proxyTask = proxyTaskWrapper(tap.name, task);
|
|
2662
|
+
args[taskIndex] = proxyTask;
|
|
2663
|
+
proxyTask.output = "Processing...";
|
|
2664
|
+
return fn(...args);
|
|
2665
|
+
};
|
|
2716
2666
|
}
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
}
|
|
2667
|
+
if (tap.type === "sync") {
|
|
2668
|
+
tap.fn = (...args) => {
|
|
2669
|
+
const task = args[taskIndex];
|
|
2670
|
+
const proxyTask = proxyTaskWrapper(tap.name, task);
|
|
2671
|
+
args[taskIndex] = proxyTask;
|
|
2672
|
+
proxyTask.output = "Processing...";
|
|
2673
|
+
return fn(...args);
|
|
2674
|
+
};
|
|
2725
2675
|
}
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2676
|
+
if (tap.type === "async") {
|
|
2677
|
+
tap.fn = (...args) => {
|
|
2678
|
+
const task = args[taskIndex];
|
|
2679
|
+
const proxyTask = proxyTaskWrapper(tap.name, task);
|
|
2680
|
+
args[taskIndex] = proxyTask;
|
|
2681
|
+
proxyTask.output = "Processing...";
|
|
2682
|
+
return fn(...args);
|
|
2683
|
+
};
|
|
2684
|
+
}
|
|
2685
|
+
return tap;
|
|
2686
|
+
}
|
|
2687
|
+
};
|
|
2688
|
+
}
|
|
2729
2689
|
|
|
2730
|
-
// src/
|
|
2690
|
+
// src/compiler/intercepter/perfect-error-message.ts
|
|
2731
2691
|
var R23 = __toESM(require("ramda"), 1);
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
new GenerateDeclarationPlugin().apply(compiler);
|
|
2741
|
-
if (this.options.build) {
|
|
2742
|
-
new ShakingPlugin().apply(compiler);
|
|
2743
|
-
}
|
|
2744
|
-
if (this.options.interactive) {
|
|
2745
|
-
new TerminalSelectPlugin(
|
|
2746
|
-
typeof this.options.interactive === "object" ? this.options.interactive : { mode: "except" }
|
|
2747
|
-
).apply(compiler);
|
|
2692
|
+
function perfectErrorMessage() {
|
|
2693
|
+
return {
|
|
2694
|
+
register: (tap) => {
|
|
2695
|
+
const fn = tap.fn;
|
|
2696
|
+
function prefix(err) {
|
|
2697
|
+
if (err instanceof Error) {
|
|
2698
|
+
err.message = `[Plugin: ${tap.name}] ${err.message}`;
|
|
2699
|
+
}
|
|
2748
2700
|
}
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2701
|
+
if (tap.type === "promise") {
|
|
2702
|
+
tap.fn = async (...args) => {
|
|
2703
|
+
try {
|
|
2704
|
+
return await fn(...args);
|
|
2705
|
+
} catch (err) {
|
|
2706
|
+
prefix(err);
|
|
2707
|
+
throw err;
|
|
2708
|
+
}
|
|
2709
|
+
};
|
|
2754
2710
|
}
|
|
2755
|
-
if (
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2711
|
+
if (tap.type === "sync") {
|
|
2712
|
+
tap.fn = (...args) => {
|
|
2713
|
+
try {
|
|
2714
|
+
return fn(...args);
|
|
2715
|
+
} catch (err) {
|
|
2716
|
+
prefix(err);
|
|
2717
|
+
throw err;
|
|
2718
|
+
}
|
|
2719
|
+
};
|
|
2759
2720
|
}
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
const notExistModules = modulesIncludes.filter((moduleName) => !(moduleName in rc.modules));
|
|
2767
|
-
if (notExistModules.length) {
|
|
2768
|
-
throw new Error(`Cannot find module(s) ${notExistModules.join(", ")} in config file.`);
|
|
2769
|
-
}
|
|
2770
|
-
const ignoredModules = R23.difference(R23.keys(rc.modules), modulesIncludes);
|
|
2771
|
-
for (const moduleName of ignoredModules) {
|
|
2772
|
-
matcher.append({
|
|
2773
|
-
persist: false,
|
|
2774
|
-
ignore: true,
|
|
2775
|
-
moduleName,
|
|
2776
|
-
operationMethod: "*",
|
|
2777
|
-
operationPathname: "*"
|
|
2721
|
+
if (tap.type === "async") {
|
|
2722
|
+
tap.fn = (...args) => {
|
|
2723
|
+
const callback = R23.last(args);
|
|
2724
|
+
return fn(...R23.init(args), (err, result) => {
|
|
2725
|
+
prefix(err);
|
|
2726
|
+
return callback(err, result);
|
|
2778
2727
|
});
|
|
2779
|
-
}
|
|
2780
|
-
}
|
|
2728
|
+
};
|
|
2729
|
+
}
|
|
2730
|
+
return tap;
|
|
2781
2731
|
}
|
|
2782
|
-
}
|
|
2783
|
-
}
|
|
2784
|
-
|
|
2785
|
-
// src/plugins/overwrite-query-options/overwrite-query-options.plugin.ts
|
|
2786
|
-
var QsArrayFormatUnion = Object.values(QsArrayFormat);
|
|
2732
|
+
};
|
|
2733
|
+
}
|
|
2787
2734
|
|
|
2788
2735
|
// src/compiler/compiler.ts
|
|
2789
2736
|
var Compiler = class {
|
|
@@ -2848,8 +2795,7 @@ var Compiler = class {
|
|
|
2848
2795
|
ModuleDefinition,
|
|
2849
2796
|
OperationDefinition,
|
|
2850
2797
|
QsArrayFormat,
|
|
2851
|
-
RuntimeConfig,
|
|
2852
2798
|
SchemaDefinition,
|
|
2853
|
-
|
|
2799
|
+
defineConfig
|
|
2854
2800
|
});
|
|
2855
2801
|
//# sourceMappingURL=index.cjs.map
|