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