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