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