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