@asyncapi/cli 3.1.1 → 3.3.0

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.
Files changed (194) hide show
  1. package/README.md +4 -0
  2. package/assets/create-glee-app/templates/default/package-lock.json +1185 -676
  3. package/assets/create-glee-app/templates/tutorial/package-lock.json +1148 -554
  4. package/assets/create-template/templates/default/package-lock.json +55 -132
  5. package/lib/apps/api/app.d.ts +15 -0
  6. package/lib/apps/api/app.js +89 -0
  7. package/lib/apps/api/configs/development.json +16 -0
  8. package/lib/apps/api/configs/production.json +16 -0
  9. package/lib/apps/api/configs/test.json +16 -0
  10. package/lib/apps/api/constants.d.ts +1 -0
  11. package/lib/apps/api/constants.js +4 -0
  12. package/lib/apps/api/controllers/bundle.controller.d.ts +7 -0
  13. package/lib/apps/api/controllers/bundle.controller.js +44 -0
  14. package/lib/apps/api/controllers/convert.controller.d.ts +11 -0
  15. package/lib/apps/api/controllers/convert.controller.js +69 -0
  16. package/lib/apps/api/controllers/diff.controller.d.ts +7 -0
  17. package/lib/apps/api/controllers/diff.controller.js +42 -0
  18. package/lib/apps/api/controllers/docs.controller.d.ts +6 -0
  19. package/lib/apps/api/controllers/docs.controller.js +24 -0
  20. package/lib/apps/api/controllers/generate.controller.d.ts +22 -0
  21. package/lib/apps/api/controllers/generate.controller.js +176 -0
  22. package/lib/apps/api/controllers/help.controller.d.ts +6 -0
  23. package/lib/apps/api/controllers/help.controller.js +101 -0
  24. package/lib/apps/api/controllers/parse.controller.d.ts +10 -0
  25. package/lib/apps/api/controllers/parse.controller.js +35 -0
  26. package/lib/apps/api/controllers/validate.controller.d.ts +10 -0
  27. package/lib/apps/api/controllers/validate.controller.js +50 -0
  28. package/lib/apps/api/exceptions/problem.exception.d.ts +14 -0
  29. package/lib/apps/api/exceptions/problem.exception.js +10 -0
  30. package/lib/apps/api/index.d.ts +9 -0
  31. package/lib/apps/api/index.js +21 -0
  32. package/lib/apps/api/middlewares/problem.middleware.d.ts +6 -0
  33. package/lib/apps/api/middlewares/problem.middleware.js +27 -0
  34. package/lib/apps/api/middlewares/validation.middleware.d.ts +12 -0
  35. package/lib/apps/api/middlewares/validation.middleware.js +236 -0
  36. package/lib/apps/api/server.d.ts +3 -0
  37. package/lib/apps/api/server.js +19 -0
  38. package/lib/{commands → apps/cli/commands}/bundle.d.ts +1 -1
  39. package/lib/{commands → apps/cli/commands}/bundle.js +3 -3
  40. package/lib/{commands → apps/cli/commands}/config/analytics.d.ts +1 -1
  41. package/lib/{commands → apps/cli/commands}/config/analytics.js +4 -3
  42. package/lib/{commands → apps/cli/commands}/config/context/add.d.ts +1 -1
  43. package/lib/{commands → apps/cli/commands}/config/context/add.js +12 -6
  44. package/lib/{commands → apps/cli/commands}/config/context/current.d.ts +1 -1
  45. package/lib/{commands → apps/cli/commands}/config/context/current.js +4 -4
  46. package/lib/{commands → apps/cli/commands}/config/context/edit.d.ts +1 -1
  47. package/lib/{commands → apps/cli/commands}/config/context/edit.js +12 -6
  48. package/lib/{commands → apps/cli/commands}/config/context/index.d.ts +1 -1
  49. package/lib/{commands → apps/cli/commands}/config/context/index.js +1 -1
  50. package/lib/{commands → apps/cli/commands}/config/context/init.d.ts +1 -1
  51. package/lib/{commands → apps/cli/commands}/config/context/init.js +7 -4
  52. package/lib/{commands → apps/cli/commands}/config/context/list.d.ts +1 -1
  53. package/lib/{commands → apps/cli/commands}/config/context/list.js +4 -4
  54. package/lib/{commands → apps/cli/commands}/config/context/remove.d.ts +1 -1
  55. package/lib/{commands → apps/cli/commands}/config/context/remove.js +8 -5
  56. package/lib/{commands → apps/cli/commands}/config/context/use.d.ts +1 -1
  57. package/lib/{commands → apps/cli/commands}/config/context/use.js +8 -5
  58. package/lib/{commands → apps/cli/commands}/config/index.d.ts +1 -1
  59. package/lib/{commands → apps/cli/commands}/config/index.js +1 -1
  60. package/lib/{commands → apps/cli/commands}/config/versions.d.ts +1 -1
  61. package/lib/{commands → apps/cli/commands}/config/versions.js +2 -2
  62. package/lib/{commands → apps/cli/commands}/convert.d.ts +2 -7
  63. package/lib/apps/cli/commands/convert.js +85 -0
  64. package/lib/{commands → apps/cli/commands}/diff.d.ts +11 -2
  65. package/lib/{commands → apps/cli/commands}/diff.js +85 -31
  66. package/lib/{commands → apps/cli/commands}/format.d.ts +1 -1
  67. package/lib/{commands → apps/cli/commands}/format.js +4 -4
  68. package/lib/{commands → apps/cli/commands}/generate/fromTemplate.d.ts +4 -5
  69. package/lib/{commands → apps/cli/commands}/generate/fromTemplate.js +89 -122
  70. package/lib/{commands → apps/cli/commands}/generate/index.d.ts +1 -1
  71. package/lib/{commands → apps/cli/commands}/generate/index.js +1 -1
  72. package/lib/{commands → apps/cli/commands}/generate/models.d.ts +6 -1
  73. package/lib/{commands → apps/cli/commands}/generate/models.js +48 -9
  74. package/lib/{commands → apps/cli/commands}/new/file.d.ts +1 -1
  75. package/lib/{commands → apps/cli/commands}/new/file.js +11 -8
  76. package/lib/{commands → apps/cli/commands}/new/glee.d.ts +2 -2
  77. package/lib/{commands → apps/cli/commands}/new/glee.js +4 -4
  78. package/lib/{commands → apps/cli/commands}/new/index.d.ts +1 -1
  79. package/lib/{commands → apps/cli/commands}/new/index.js +1 -1
  80. package/lib/{commands → apps/cli/commands}/new/template.d.ts +1 -1
  81. package/lib/{commands → apps/cli/commands}/new/template.js +10 -8
  82. package/lib/{commands → apps/cli/commands}/optimize.d.ts +1 -1
  83. package/lib/{commands → apps/cli/commands}/optimize.js +71 -30
  84. package/lib/{commands → apps/cli/commands}/pretty.d.ts +1 -1
  85. package/lib/{commands → apps/cli/commands}/pretty.js +8 -5
  86. package/lib/apps/cli/commands/start/api.d.ts +11 -0
  87. package/lib/apps/cli/commands/start/api.js +23 -0
  88. package/lib/{commands → apps/cli/commands}/start/index.d.ts +1 -1
  89. package/lib/{commands → apps/cli/commands}/start/index.js +1 -1
  90. package/lib/{commands → apps/cli/commands}/start/preview.d.ts +1 -1
  91. package/lib/{commands → apps/cli/commands}/start/preview.js +9 -6
  92. package/lib/{commands → apps/cli/commands}/start/studio.d.ts +1 -1
  93. package/lib/{commands → apps/cli/commands}/start/studio.js +10 -7
  94. package/lib/{commands → apps/cli/commands}/validate.d.ts +6 -2
  95. package/lib/apps/cli/commands/validate.js +94 -0
  96. package/lib/{core → apps/cli/internal}/base.d.ts +1 -1
  97. package/lib/{core → apps/cli/internal}/base.js +12 -4
  98. package/lib/apps/cli/internal/flags/bundle.flags.js +26 -0
  99. package/lib/apps/cli/internal/flags/config/analytics.flags.js +24 -0
  100. package/lib/{core → apps/cli/internal}/flags/config/context.flags.js +1 -1
  101. package/lib/{core → apps/cli/internal}/flags/convert.flags.js +9 -2
  102. package/lib/{core → apps/cli/internal}/flags/diff.flags.d.ts +1 -1
  103. package/lib/{core → apps/cli/internal}/flags/diff.flags.js +3 -3
  104. package/lib/{core → apps/cli/internal}/flags/generate/fromTemplate.flags.js +12 -12
  105. package/lib/{core → apps/cli/internal}/flags/generate/models.flags.js +2 -2
  106. package/lib/{core → apps/cli/internal}/flags/global.flags.js +1 -1
  107. package/lib/{core → apps/cli/internal}/flags/new/file.flags.js +7 -2
  108. package/lib/{core → apps/cli/internal}/flags/optimize.flags.js +24 -4
  109. package/lib/apps/cli/internal/flags/parser.flags.d.ts +10 -0
  110. package/lib/apps/cli/internal/flags/parser.flags.js +28 -0
  111. package/lib/{core → apps/cli/internal}/flags/proxy.flags.js +3 -3
  112. package/lib/apps/cli/internal/flags/start/api.flags.d.ts +5 -0
  113. package/lib/apps/cli/internal/flags/start/api.flags.js +20 -0
  114. package/lib/apps/cli/internal/flags/start/preview.flags.js +31 -0
  115. package/lib/{core → apps/cli/internal}/flags/start/studio.flags.js +9 -2
  116. package/lib/{core → apps/cli/internal}/flags/validate.flags.d.ts +3 -1
  117. package/lib/{core → apps/cli/internal}/flags/validate.flags.js +11 -3
  118. package/lib/{core → apps/cli/internal}/globals.d.ts +1 -1
  119. package/lib/{core → apps/cli/internal}/globals.js +2 -4
  120. package/lib/{core → apps/cli/internal}/hooks/command_not_found/myhook.js +14 -4
  121. package/lib/{core → domains}/models/Context.js +1 -1
  122. package/lib/{core → domains}/models/Preview.js +35 -19
  123. package/lib/{core → domains}/models/SpecificationFile.d.ts +2 -2
  124. package/lib/{core → domains}/models/SpecificationFile.js +8 -5
  125. package/lib/{core → domains}/models/Studio.js +4 -4
  126. package/lib/domains/services/archiver.service.d.ts +17 -0
  127. package/lib/domains/services/archiver.service.js +53 -0
  128. package/lib/domains/services/base.service.d.ts +6 -0
  129. package/lib/domains/services/base.service.js +26 -0
  130. package/lib/domains/services/convert.service.d.ts +12 -0
  131. package/lib/domains/services/convert.service.js +65 -0
  132. package/lib/domains/services/generator.service.d.ts +15 -0
  133. package/lib/domains/services/generator.service.js +95 -0
  134. package/lib/domains/services/validation.service.d.ts +54 -0
  135. package/lib/domains/services/validation.service.js +288 -0
  136. package/lib/{core/errors → errors}/specification-file.js +1 -1
  137. package/lib/{core/errors → errors}/validation-error.js +6 -5
  138. package/lib/interfaces/index.d.ts +87 -0
  139. package/lib/interfaces/index.js +7 -0
  140. package/lib/utils/ajv.d.ts +2 -0
  141. package/lib/utils/ajv.js +18 -0
  142. package/lib/utils/app-openapi.d.ts +4 -0
  143. package/lib/utils/app-openapi.js +28 -0
  144. package/lib/{core/utils/generator.js → utils/fileWatcher.js} +8 -2
  145. package/lib/utils/logger.d.ts +6 -0
  146. package/lib/utils/logger.js +33 -0
  147. package/lib/utils/retrieve-language.d.ts +1 -0
  148. package/lib/utils/retrieve-language.js +9 -0
  149. package/lib/utils/temp-dir.d.ts +2 -0
  150. package/lib/utils/temp-dir.js +25 -0
  151. package/oclif.manifest.json +124 -1
  152. package/package.json +37 -22
  153. package/lib/commands/convert.js +0 -132
  154. package/lib/commands/validate.js +0 -45
  155. package/lib/core/flags/bundle.flags.js +0 -14
  156. package/lib/core/flags/config/analytics.flags.js +0 -13
  157. package/lib/core/flags/start/preview.flags.js +0 -15
  158. package/lib/core/parser.d.ts +0 -33
  159. package/lib/core/parser.js +0 -176
  160. /package/lib/{core → apps/cli/internal}/flags/bundle.flags.d.ts +0 -0
  161. /package/lib/{core → apps/cli/internal}/flags/config/analytics.flags.d.ts +0 -0
  162. /package/lib/{core → apps/cli/internal}/flags/config/context.flags.d.ts +0 -0
  163. /package/lib/{core → apps/cli/internal}/flags/convert.flags.d.ts +0 -0
  164. /package/lib/{core → apps/cli/internal}/flags/format.flags.d.ts +0 -0
  165. /package/lib/{core → apps/cli/internal}/flags/format.flags.js +0 -0
  166. /package/lib/{core → apps/cli/internal}/flags/generate/fromTemplate.flags.d.ts +0 -0
  167. /package/lib/{core → apps/cli/internal}/flags/generate/models.flags.d.ts +0 -0
  168. /package/lib/{core → apps/cli/internal}/flags/global.flags.d.ts +0 -0
  169. /package/lib/{core → apps/cli/internal}/flags/new/file.flags.d.ts +0 -0
  170. /package/lib/{core → apps/cli/internal}/flags/new/glee.flags.d.ts +0 -0
  171. /package/lib/{core → apps/cli/internal}/flags/new/glee.flags.js +0 -0
  172. /package/lib/{core → apps/cli/internal}/flags/new/template.flags.d.ts +0 -0
  173. /package/lib/{core → apps/cli/internal}/flags/new/template.flags.js +0 -0
  174. /package/lib/{core → apps/cli/internal}/flags/optimize.flags.d.ts +0 -0
  175. /package/lib/{core → apps/cli/internal}/flags/pretty.flags.d.ts +0 -0
  176. /package/lib/{core → apps/cli/internal}/flags/pretty.flags.js +0 -0
  177. /package/lib/{core → apps/cli/internal}/flags/proxy.flags.d.ts +0 -0
  178. /package/lib/{core → apps/cli/internal}/flags/start/preview.flags.d.ts +0 -0
  179. /package/lib/{core → apps/cli/internal}/flags/start/studio.flags.d.ts +0 -0
  180. /package/lib/{core → apps/cli/internal}/hooks/command_not_found/myhook.d.ts +0 -0
  181. /package/lib/{core → domains}/models/Context.d.ts +0 -0
  182. /package/lib/{core → domains}/models/Preview.d.ts +0 -0
  183. /package/lib/{core → domains}/models/Studio.d.ts +0 -0
  184. /package/lib/{core/errors → errors}/context-error.d.ts +0 -0
  185. /package/lib/{core/errors → errors}/context-error.js +0 -0
  186. /package/lib/{core/errors → errors}/diff-error.d.ts +0 -0
  187. /package/lib/{core/errors → errors}/diff-error.js +0 -0
  188. /package/lib/{core/errors → errors}/generator-error.d.ts +0 -0
  189. /package/lib/{core/errors → errors}/generator-error.js +0 -0
  190. /package/lib/{core/errors → errors}/specification-file.d.ts +0 -0
  191. /package/lib/{core/errors → errors}/validation-error.d.ts +0 -0
  192. /package/lib/{core/utils/generator.d.ts → utils/fileWatcher.d.ts} +0 -0
  193. /package/lib/{core/utils → utils}/scoreCalculator.d.ts +0 -0
  194. /package/lib/{core/utils → utils}/scoreCalculator.js +0 -0
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const base_1 = tslib_1.__importDefault(require("../internal/base"));
6
+ const validation_error_1 = require("../../../errors/validation-error");
7
+ const SpecificationFile_1 = require("../../../domains/models/SpecificationFile");
8
+ const specification_file_1 = require("../../../errors/specification-file");
9
+ const picocolors_1 = require("picocolors");
10
+ const proxy_flags_1 = require("../internal/flags/proxy.flags");
11
+ const specs_1 = tslib_1.__importDefault(require("@asyncapi/specs"));
12
+ const convert_flags_1 = require("../internal/flags/convert.flags");
13
+ const convert_service_1 = require("../../../domains/services/convert.service");
14
+ const latestVersion = Object.keys(specs_1.default.schemas).pop();
15
+ class Convert extends base_1.default {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.conversionService = new convert_service_1.ConversionService();
19
+ }
20
+ run() {
21
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
22
+ const { args, flags } = yield this.parse(Convert);
23
+ let filePath = args['spec-file'];
24
+ const proxyHost = flags['proxyHost'];
25
+ const proxyPort = flags['proxyPort'];
26
+ if (proxyHost && proxyPort) {
27
+ const proxyUrl = `http://${proxyHost}:${proxyPort}`;
28
+ filePath = `${filePath}+${proxyUrl}`; // Update filePath with proxyUrl
29
+ }
30
+ try {
31
+ // LOAD FILE
32
+ this.specFile = yield (0, SpecificationFile_1.load)(filePath);
33
+ // eslint-disable-next-line sonarjs/no-duplicate-string
34
+ this.metricsMetadata.to_version = flags['target-version'];
35
+ const conversionOptions = {
36
+ format: flags.format,
37
+ 'target-version': (flags['target-version'] ||
38
+ latestVersion),
39
+ perspective: flags['perspective'],
40
+ };
41
+ const result = yield this.conversionService.convertDocument(this.specFile, conversionOptions);
42
+ if (!result.success || !result.data) {
43
+ this.error(result.error || 'Conversion failed', { exit: 1 });
44
+ }
45
+ this.metricsMetadata.conversion_result = result;
46
+ this.log(this.conversionService.handleLogging(this.specFile, conversionOptions));
47
+ if (flags['output']) {
48
+ yield this.conversionService.handleOutput(flags['output'], result.data.convertedDocument);
49
+ }
50
+ else {
51
+ this.log(result.data.convertedDocument);
52
+ }
53
+ }
54
+ catch (err) {
55
+ this.handleError(err, filePath !== null && filePath !== void 0 ? filePath : 'unknown', flags);
56
+ }
57
+ });
58
+ }
59
+ // Helper function to handle errors
60
+ handleError(err, filePath, flags) {
61
+ var _a;
62
+ if (err instanceof specification_file_1.SpecificationFileNotFound) {
63
+ this.error(new validation_error_1.ValidationError({
64
+ type: 'invalid-file',
65
+ filepath: filePath,
66
+ }));
67
+ }
68
+ else if (((_a = this.specFile) === null || _a === void 0 ? void 0 : _a.toJson().asyncapi) > flags['target-version']) {
69
+ this.error(`The ${(0, picocolors_1.cyan)(filePath)} file cannot be converted to an older version. Downgrading is not supported.`);
70
+ }
71
+ else {
72
+ this.error(err);
73
+ }
74
+ }
75
+ }
76
+ Convert.metricsMetadata = {};
77
+ Convert.description = 'Convert asyncapi documents older to newer versions or OpenAPI/postman-collection documents to AsyncAPI';
78
+ Convert.flags = Object.assign(Object.assign({}, (0, convert_flags_1.convertFlags)(latestVersion)), (0, proxy_flags_1.proxyFlags)());
79
+ Convert.args = {
80
+ 'spec-file': core_1.Args.string({
81
+ description: 'spec path, url, or context-name',
82
+ required: false,
83
+ }),
84
+ };
85
+ exports.default = Convert;
@@ -1,11 +1,15 @@
1
1
  import AsyncAPIDiff from '@asyncapi/diff/lib/asyncapidiff';
2
- import Command from '../core/base';
2
+ import { Specification } from '../../../domains/models/SpecificationFile';
3
+ import Command from '../internal/base';
4
+ import { ValidationStatus } from '../../../domains/services/validation.service';
5
+ import { Diagnostic } from '@asyncapi/parser/cjs';
3
6
  export default class Diff extends Command {
4
7
  static description: string;
8
+ private validationService;
5
9
  static flags: {
6
10
  'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
11
  'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
8
- 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
12
+ 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
9
13
  output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
10
14
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
11
15
  format: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
@@ -23,4 +27,9 @@ export default class Diff extends Command {
23
27
  outputJSON(diffOutput: AsyncAPIDiff, outputType: string): void;
24
28
  outputYAML(diffOutput: AsyncAPIDiff, outputType: string): void;
25
29
  outputMarkdown(diffOutput: AsyncAPIDiff, outputType: string): void;
30
+ parseDocuments(command: Command, firstDocument: Specification, secondDocument: Specification, flags: Record<string, any>): Promise<{
31
+ firstDocumentParsed: import("@asyncapi/parser/cjs").AsyncAPIDocumentInterface;
32
+ secondDocumentParsed: import("@asyncapi/parser/cjs").AsyncAPIDocumentInterface;
33
+ } | undefined>;
34
+ handleGovernanceMessage(document: Specification, diagnostics: Diagnostic[], status: ValidationStatus): Promise<void>;
26
35
  }
@@ -6,16 +6,20 @@ const core_1 = require("@oclif/core");
6
6
  const diff = tslib_1.__importStar(require("@asyncapi/diff"));
7
7
  const fs_1 = require("fs");
8
8
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
9
- const SpecificationFile_1 = require("../core/models/SpecificationFile");
10
- const base_1 = tslib_1.__importDefault(require("../core/base"));
11
- const validation_error_1 = require("../core/errors/validation-error");
12
- const specification_file_1 = require("../core/errors/specification-file");
13
- const diff_error_1 = require("../core/errors/diff-error");
14
- const globals_1 = require("../core/globals");
15
- const parser_1 = require("../core/parser");
16
- const diff_flags_1 = require("../core/flags/diff.flags");
9
+ const SpecificationFile_1 = require("../../../domains/models/SpecificationFile");
10
+ const base_1 = tslib_1.__importDefault(require("../internal/base"));
11
+ const validation_error_1 = require("../../../errors/validation-error");
12
+ const specification_file_1 = require("../../../errors/specification-file");
13
+ const diff_error_1 = require("../../../errors/diff-error");
14
+ const globals_1 = require("../internal/globals");
15
+ const diff_flags_1 = require("../internal/flags/diff.flags");
16
+ const validation_service_1 = require("../../../domains/services/validation.service");
17
17
  const { readFile } = fs_1.promises;
18
18
  class Diff extends base_1.default {
19
+ constructor() {
20
+ super(...arguments);
21
+ this.validationService = new validation_service_1.ValidationService();
22
+ }
19
23
  /* eslint-disable sonarjs/cognitive-complexity */
20
24
  run() {
21
25
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
@@ -84,14 +88,14 @@ class Diff extends base_1.default {
84
88
  }
85
89
  }
86
90
  try {
87
- const parsed = yield parseDocuments(this, firstDocument, secondDocument, flags);
91
+ const parsed = yield this.parseDocuments(this, firstDocument, secondDocument, flags);
88
92
  if (!parsed) {
89
93
  return;
90
94
  }
91
95
  const diffOutput = diff.diff(parsed.firstDocumentParsed.json(), parsed.secondDocumentParsed.json(), {
92
96
  override: overrides,
93
97
  outputType: outputFormat, // NOSONAR
94
- markdownSubtype: markdownSubtype
98
+ markdownSubtype: markdownSubtype,
95
99
  });
96
100
  if (outputFormat === 'json') {
97
101
  this.outputJSON(diffOutput, outputType);
@@ -110,7 +114,8 @@ class Diff extends base_1.default {
110
114
  }
111
115
  }
112
116
  catch (error) {
113
- if (error instanceof diff_error_1.DiffBreakingChangeError || error instanceof TypeError) {
117
+ if (error instanceof diff_error_1.DiffBreakingChangeError ||
118
+ error instanceof TypeError) {
114
119
  this.error(error);
115
120
  }
116
121
  throw new validation_error_1.ValidationError({
@@ -143,12 +148,65 @@ class Diff extends base_1.default {
143
148
  outputMarkdown(diffOutput, outputType) {
144
149
  this.log(genericOutput(diffOutput, outputType));
145
150
  }
151
+ parseDocuments(command, firstDocument, secondDocument, flags) {
152
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
153
+ const firstResult = yield this.validationService.parseDocument(firstDocument, {}, flags);
154
+ const secondResult = yield this.validationService.parseDocument(secondDocument, {}, flags);
155
+ if (!firstResult.success || !secondResult.success) {
156
+ this.error(new validation_error_1.ValidationError({
157
+ type: 'invalid-file',
158
+ filepath: firstDocument.getFilePath() || secondDocument.getFilePath(),
159
+ err: firstResult.error || secondResult.error,
160
+ }));
161
+ }
162
+ if (!firstResult.data || !secondResult.data) {
163
+ return;
164
+ }
165
+ const { document: firstDocumentParsed, status: firstDocumentStatus, diagnostics: firstDiagnostics, } = firstResult.data;
166
+ const { document: secondDocumentParsed, status: secondDocumentStatus, diagnostics: secondDiagnostics, } = secondResult.data;
167
+ if (flags['log-diagnostics']) {
168
+ this.log(`Diagnostics for ${firstDocument.getFilePath() || firstDocument.getFileURL()}:`);
169
+ this.handleGovernanceMessage(firstDocument, firstDiagnostics, firstDocumentStatus);
170
+ this.log(this.validationService.formatDiagnosticsOutput(firstDiagnostics, flags['diagnostics-format'], flags['fail-severity']));
171
+ this.log(`Diagnostics for ${secondDocument.getFilePath() || secondDocument.getFileURL()}:`);
172
+ this.handleGovernanceMessage(secondDocument, secondDiagnostics, secondDocumentStatus);
173
+ this.log(this.validationService.formatDiagnosticsOutput(secondDiagnostics, flags['diagnostics-format'], flags['fail-severity']));
174
+ }
175
+ if (!firstDocumentParsed ||
176
+ !secondDocumentParsed ||
177
+ firstDocumentStatus === 'invalid' ||
178
+ secondDocumentStatus === 'invalid') {
179
+ return;
180
+ }
181
+ return { firstDocumentParsed, secondDocumentParsed };
182
+ });
183
+ }
184
+ handleGovernanceMessage(document, diagnostics, status) {
185
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
186
+ const sourceString = document.toSourceString();
187
+ const hasIssues = diagnostics && diagnostics.length > 0;
188
+ const isFailSeverity = status === validation_service_1.ValidationStatus.INVALID;
189
+ const governanceMessage = this.validationService.generateGovernanceMessage(sourceString, hasIssues, isFailSeverity);
190
+ if (isFailSeverity) {
191
+ this.logToStderr(governanceMessage);
192
+ }
193
+ else {
194
+ this.log(governanceMessage);
195
+ }
196
+ });
197
+ }
146
198
  }
147
199
  Diff.description = 'Find diff between two asyncapi files';
148
200
  Diff.flags = (0, diff_flags_1.diffFlags)();
149
201
  Diff.args = {
150
- old: core_1.Args.string({ description: 'old spec path, URL or context-name', required: true }),
151
- new: core_1.Args.string({ description: 'new spec path, URL or context-name', required: true }),
202
+ old: core_1.Args.string({
203
+ description: 'old spec path, URL or context-name',
204
+ required: true,
205
+ }),
206
+ new: core_1.Args.string({
207
+ description: 'new spec path, URL or context-name',
208
+ required: true,
209
+ }),
152
210
  };
153
211
  exports.default = Diff;
154
212
  /**
@@ -159,23 +217,18 @@ exports.default = Diff;
159
217
  */
160
218
  function genericOutput(diffOutput, outputType) {
161
219
  switch (outputType) {
162
- case 'breaking': return diffOutput.breaking();
163
- case 'non-breaking': return diffOutput.nonBreaking();
164
- case 'unclassified': return diffOutput.unclassified();
165
- case 'all': return diffOutput.getOutput();
166
- default: return `The output type ${outputType} is not supported at the moment.`;
220
+ case 'breaking':
221
+ return diffOutput.breaking();
222
+ case 'non-breaking':
223
+ return diffOutput.nonBreaking();
224
+ case 'unclassified':
225
+ return diffOutput.unclassified();
226
+ case 'all':
227
+ return diffOutput.getOutput();
228
+ default:
229
+ return `The output type ${outputType} is not supported at the moment.`;
167
230
  }
168
231
  }
169
- function parseDocuments(command, firstDocument, secondDocument, flags) {
170
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
171
- const { document: firstDocumentParsed, status: firstDocumentStatus } = yield (0, parser_1.parse)(command, firstDocument, flags);
172
- const { document: secondDocumentParsed, status: secondDocumentStatus } = yield (0, parser_1.parse)(command, secondDocument, flags);
173
- if (!firstDocumentParsed || !secondDocumentParsed || firstDocumentStatus === 'invalid' || secondDocumentStatus === 'invalid') {
174
- return;
175
- }
176
- return { firstDocumentParsed, secondDocumentParsed };
177
- });
178
- }
179
232
  /**
180
233
  * Reads the file from give path and parses it as JSON
181
234
  * @param path The path to override file
@@ -213,7 +266,8 @@ const enableWatch = (status, watcher) => {
213
266
  function throwOnBreakingChange(diffOutput, outputFormat) {
214
267
  const breakingChanges = diffOutput.breaking();
215
268
  if ((outputFormat === 'json' && breakingChanges.length !== 0) ||
216
- ((outputFormat === 'yaml' || outputFormat === 'yml') && breakingChanges !== '[]\n')) {
269
+ ((outputFormat === 'yaml' || outputFormat === 'yml') &&
270
+ breakingChanges !== '[]\n')) {
217
271
  throw new diff_error_1.DiffBreakingChangeError();
218
272
  }
219
273
  }
@@ -221,7 +275,7 @@ function throwOnBreakingChange(diffOutput, outputFormat) {
221
275
  * Checks and warns user about providing unnecessary markdownSubtype option.
222
276
  */
223
277
  function checkAndWarnFalseFlag(format, markdownSubtype) {
224
- if (format !== 'md' && typeof (markdownSubtype) !== 'undefined') {
278
+ if (format !== 'md' && typeof markdownSubtype !== 'undefined') {
225
279
  const warningMessage = chalk_1.default.yellowBright(`Warning: The given markdownSubtype flag will not work with the given format.\nProvided flag markdownSubtype: ${markdownSubtype}`);
226
280
  console.log(warningMessage);
227
281
  }
@@ -230,7 +284,7 @@ function checkAndWarnFalseFlag(format, markdownSubtype) {
230
284
  * Sets the default markdownSubtype option in case user doesn't provide one.
231
285
  */
232
286
  function setDefaultMarkdownSubtype(format, markdownSubtype) {
233
- if (format === 'md' && typeof (markdownSubtype) === 'undefined') {
287
+ if (format === 'md' && typeof markdownSubtype === 'undefined') {
234
288
  return 'yaml';
235
289
  }
236
290
  return markdownSubtype;
@@ -1,4 +1,4 @@
1
- import Command from '../core/base';
1
+ import Command from '../internal/base';
2
2
  export default class Convert extends Command {
3
3
  static specFile: any;
4
4
  static metricsMetadata: any;
@@ -4,11 +4,11 @@ const tslib_1 = require("tslib");
4
4
  /* eslint-disable @typescript-eslint/ban-ts-comment */
5
5
  const fs_1 = require("fs");
6
6
  const core_1 = require("@oclif/core");
7
- const base_1 = tslib_1.__importDefault(require("../core/base"));
8
- const SpecificationFile_1 = require("../core/models/SpecificationFile");
9
- const specification_file_1 = require("../core/errors/specification-file");
7
+ const base_1 = tslib_1.__importDefault(require("../internal/base"));
8
+ const SpecificationFile_1 = require("../../../domains/models/SpecificationFile");
9
+ const specification_file_1 = require("../../../errors/specification-file");
10
10
  const picocolors_1 = require("picocolors");
11
- const format_flags_1 = require("../core/flags/format.flags");
11
+ const format_flags_1 = require("../internal/flags/format.flags");
12
12
  class Convert extends base_1.default {
13
13
  run() {
14
14
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
@@ -1,7 +1,8 @@
1
- import Command from '../../core/base';
1
+ import Command from '../../internal/base';
2
2
  import { Parser } from '@asyncapi/parser';
3
3
  export default class Template extends Command {
4
4
  static description: string;
5
+ private generatorService;
5
6
  static examples: string[];
6
7
  static readonly flags: {
7
8
  proxyHost: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
@@ -27,16 +28,14 @@ export default class Template extends Command {
27
28
  template: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
28
29
  };
29
30
  parser: Parser;
30
- run(): Promise<void>;
31
+ run(): Promise<undefined>;
31
32
  private parseArgs;
33
+ private disableHooksParser;
32
34
  private parseFlags;
33
35
  private registryURLParser;
34
36
  private registryValidation;
35
37
  private paramParser;
36
- private disableHooksParser;
37
38
  private mapBaseURLParser;
38
- private generate;
39
- private generateUsingNewGenerator;
40
39
  private runWatchMode;
41
40
  private watcherHandler;
42
41
  private getMapBaseUrlToFolderResolver;