@asyncapi-actions-test/trusted-publishing-test_asyncapi-cli 4.1.3

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 (257) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +117 -0
  3. package/assets/create-template/templates/default/asyncapi.yaml +34 -0
  4. package/assets/create-template/templates/default/package-lock.json +4062 -0
  5. package/assets/create-template/templates/default/package.json +10 -0
  6. package/assets/create-template/templates/default/readme.md +4 -0
  7. package/assets/create-template/templates/default/template/index.js +11 -0
  8. package/assets/examples/adeo-kafka-request-reply-asyncapi.yml +298 -0
  9. package/assets/examples/anyof-asyncapi.yml +36 -0
  10. package/assets/examples/application-headers-asyncapi.yml +86 -0
  11. package/assets/examples/correlation-id-asyncapi.yml +180 -0
  12. package/assets/examples/default-example.json +51 -0
  13. package/assets/examples/default-example.yaml +31 -0
  14. package/assets/examples/examples.json +82 -0
  15. package/assets/examples/gitter-streaming-asyncapi.yml +178 -0
  16. package/assets/examples/kraken-websocket-request-reply-message-filter-in-reply-asyncapi.yml +388 -0
  17. package/assets/examples/kraken-websocket-request-reply-multiple-channels-asyncapi.yml +394 -0
  18. package/assets/examples/mercure-asyncapi.yml +58 -0
  19. package/assets/examples/not-asyncapi.yml +29 -0
  20. package/assets/examples/oneof-asyncapi.yml +57 -0
  21. package/assets/examples/operation-security-asyncapi.yml +117 -0
  22. package/assets/examples/rpc-client-asyncapi.yml +72 -0
  23. package/assets/examples/rpc-server-asyncapi.yml +69 -0
  24. package/assets/examples/simple-asyncapi.yml +31 -0
  25. package/assets/examples/slack-rtm-asyncapi.yml +982 -0
  26. package/assets/examples/streetlights-kafka-asyncapi.yml +199 -0
  27. package/assets/examples/streetlights-mqtt-asyncapi.yml +253 -0
  28. package/assets/examples/streetlights-operation-security-asyncapi.yml +240 -0
  29. package/assets/examples/tutorial.yml +41 -0
  30. package/assets/examples/websocket-gemini-asyncapi.yml +301 -0
  31. package/assets/logo.png +0 -0
  32. package/assets/server-api.png +0 -0
  33. package/bin/dev +17 -0
  34. package/bin/dev.cmd +3 -0
  35. package/bin/run +12 -0
  36. package/bin/run.cmd +3 -0
  37. package/bin/run_bin +13 -0
  38. package/bin/run_bin.cmd +3 -0
  39. package/lib/apps/api/app.d.ts +15 -0
  40. package/lib/apps/api/app.js +91 -0
  41. package/lib/apps/api/configs/development.json +16 -0
  42. package/lib/apps/api/configs/production.json +16 -0
  43. package/lib/apps/api/configs/test.json +16 -0
  44. package/lib/apps/api/constants.d.ts +1 -0
  45. package/lib/apps/api/constants.js +4 -0
  46. package/lib/apps/api/controllers/bundle.controller.d.ts +7 -0
  47. package/lib/apps/api/controllers/bundle.controller.js +44 -0
  48. package/lib/apps/api/controllers/convert.controller.d.ts +11 -0
  49. package/lib/apps/api/controllers/convert.controller.js +69 -0
  50. package/lib/apps/api/controllers/diff.controller.d.ts +7 -0
  51. package/lib/apps/api/controllers/diff.controller.js +42 -0
  52. package/lib/apps/api/controllers/docs.controller.d.ts +6 -0
  53. package/lib/apps/api/controllers/docs.controller.js +24 -0
  54. package/lib/apps/api/controllers/generate.controller.d.ts +22 -0
  55. package/lib/apps/api/controllers/generate.controller.js +174 -0
  56. package/lib/apps/api/controllers/help.controller.d.ts +6 -0
  57. package/lib/apps/api/controllers/help.controller.js +101 -0
  58. package/lib/apps/api/controllers/parse.controller.d.ts +10 -0
  59. package/lib/apps/api/controllers/parse.controller.js +35 -0
  60. package/lib/apps/api/controllers/validate.controller.d.ts +10 -0
  61. package/lib/apps/api/controllers/validate.controller.js +50 -0
  62. package/lib/apps/api/controllers/version.controller.d.ts +8 -0
  63. package/lib/apps/api/controllers/version.controller.js +69 -0
  64. package/lib/apps/api/exceptions/problem.exception.d.ts +14 -0
  65. package/lib/apps/api/exceptions/problem.exception.js +10 -0
  66. package/lib/apps/api/index.d.ts +10 -0
  67. package/lib/apps/api/index.js +23 -0
  68. package/lib/apps/api/middlewares/logger.middleware.d.ts +2 -0
  69. package/lib/apps/api/middlewares/logger.middleware.js +12 -0
  70. package/lib/apps/api/middlewares/problem.middleware.d.ts +6 -0
  71. package/lib/apps/api/middlewares/problem.middleware.js +27 -0
  72. package/lib/apps/api/middlewares/validation.middleware.d.ts +12 -0
  73. package/lib/apps/api/middlewares/validation.middleware.js +245 -0
  74. package/lib/apps/api/server.d.ts +3 -0
  75. package/lib/apps/api/server.js +19 -0
  76. package/lib/apps/cli/commands/bundle.d.ts +15 -0
  77. package/lib/apps/cli/commands/bundle.js +75 -0
  78. package/lib/apps/cli/commands/config/analytics.d.ts +11 -0
  79. package/lib/apps/cli/commands/config/analytics.js +61 -0
  80. package/lib/apps/cli/commands/config/auth/add.d.ts +13 -0
  81. package/lib/apps/cli/commands/config/auth/add.js +68 -0
  82. package/lib/apps/cli/commands/config/context/add.d.ts +13 -0
  83. package/lib/apps/cli/commands/config/context/add.js +46 -0
  84. package/lib/apps/cli/commands/config/context/current.d.ts +8 -0
  85. package/lib/apps/cli/commands/config/context/current.js +37 -0
  86. package/lib/apps/cli/commands/config/context/edit.d.ts +12 -0
  87. package/lib/apps/cli/commands/config/context/edit.js +44 -0
  88. package/lib/apps/cli/commands/config/context/index.d.ts +5 -0
  89. package/lib/apps/cli/commands/config/context/index.js +16 -0
  90. package/lib/apps/cli/commands/config/context/init.d.ts +12 -0
  91. package/lib/apps/cli/commands/config/context/init.js +31 -0
  92. package/lib/apps/cli/commands/config/context/list.d.ts +8 -0
  93. package/lib/apps/cli/commands/config/context/list.js +36 -0
  94. package/lib/apps/cli/commands/config/context/remove.d.ts +11 -0
  95. package/lib/apps/cli/commands/config/context/remove.js +39 -0
  96. package/lib/apps/cli/commands/config/context/use.d.ts +11 -0
  97. package/lib/apps/cli/commands/config/context/use.js +40 -0
  98. package/lib/apps/cli/commands/config/index.d.ts +5 -0
  99. package/lib/apps/cli/commands/config/index.js +16 -0
  100. package/lib/apps/cli/commands/config/versions.d.ts +8 -0
  101. package/lib/apps/cli/commands/config/versions.js +56 -0
  102. package/lib/apps/cli/commands/convert.d.ts +21 -0
  103. package/lib/apps/cli/commands/convert.js +85 -0
  104. package/lib/apps/cli/commands/diff.d.ts +36 -0
  105. package/lib/apps/cli/commands/diff.js +335 -0
  106. package/lib/apps/cli/commands/format.d.ts +18 -0
  107. package/lib/apps/cli/commands/format.js +97 -0
  108. package/lib/apps/cli/commands/generate/client.d.ts +30 -0
  109. package/lib/apps/cli/commands/generate/client.js +94 -0
  110. package/lib/apps/cli/commands/generate/fromTemplate.d.ts +29 -0
  111. package/lib/apps/cli/commands/generate/fromTemplate.js +91 -0
  112. package/lib/apps/cli/commands/generate/index.d.ts +5 -0
  113. package/lib/apps/cli/commands/generate/index.js +15 -0
  114. package/lib/apps/cli/commands/generate/models.d.ts +16 -0
  115. package/lib/apps/cli/commands/generate/models.js +166 -0
  116. package/lib/apps/cli/commands/new/file.d.ts +16 -0
  117. package/lib/apps/cli/commands/new/file.js +180 -0
  118. package/lib/apps/cli/commands/new/index.d.ts +5 -0
  119. package/lib/apps/cli/commands/new/index.js +15 -0
  120. package/lib/apps/cli/commands/new/template.d.ts +18 -0
  121. package/lib/apps/cli/commands/new/template.js +102 -0
  122. package/lib/apps/cli/commands/optimize.d.ts +41 -0
  123. package/lib/apps/cli/commands/optimize.js +289 -0
  124. package/lib/apps/cli/commands/pretty.d.ts +12 -0
  125. package/lib/apps/cli/commands/pretty.js +70 -0
  126. package/lib/apps/cli/commands/start/api.d.ts +11 -0
  127. package/lib/apps/cli/commands/start/api.js +23 -0
  128. package/lib/apps/cli/commands/start/index.d.ts +5 -0
  129. package/lib/apps/cli/commands/start/index.js +15 -0
  130. package/lib/apps/cli/commands/start/preview.d.ts +17 -0
  131. package/lib/apps/cli/commands/start/preview.js +41 -0
  132. package/lib/apps/cli/commands/start/studio.d.ts +16 -0
  133. package/lib/apps/cli/commands/start/studio.js +94 -0
  134. package/lib/apps/cli/commands/validate.d.ts +23 -0
  135. package/lib/apps/cli/commands/validate.js +95 -0
  136. package/lib/apps/cli/internal/args/generate.args.d.ts +3 -0
  137. package/lib/apps/cli/internal/args/generate.args.js +10 -0
  138. package/lib/apps/cli/internal/base/BaseGeneratorCommand.d.ts +42 -0
  139. package/lib/apps/cli/internal/base/BaseGeneratorCommand.js +119 -0
  140. package/lib/apps/cli/internal/base.d.ts +20 -0
  141. package/lib/apps/cli/internal/base.js +173 -0
  142. package/lib/apps/cli/internal/flags/bundle.flags.d.ts +7 -0
  143. package/lib/apps/cli/internal/flags/bundle.flags.js +26 -0
  144. package/lib/apps/cli/internal/flags/config/analytics.flags.d.ts +6 -0
  145. package/lib/apps/cli/internal/flags/config/analytics.flags.js +24 -0
  146. package/lib/apps/cli/internal/flags/config/context.flags.d.ts +4 -0
  147. package/lib/apps/cli/internal/flags/config/context.flags.js +16 -0
  148. package/lib/apps/cli/internal/flags/convert.flags.d.ts +7 -0
  149. package/lib/apps/cli/internal/flags/convert.flags.js +32 -0
  150. package/lib/apps/cli/internal/flags/diff.flags.d.ts +13 -0
  151. package/lib/apps/cli/internal/flags/diff.flags.js +29 -0
  152. package/lib/apps/cli/internal/flags/format.flags.d.ts +6 -0
  153. package/lib/apps/cli/internal/flags/format.flags.js +22 -0
  154. package/lib/apps/cli/internal/flags/generate/clients.flags.d.ts +16 -0
  155. package/lib/apps/cli/internal/flags/generate/clients.flags.js +8 -0
  156. package/lib/apps/cli/internal/flags/generate/fromTemplate.flags.d.ts +16 -0
  157. package/lib/apps/cli/internal/flags/generate/fromTemplate.flags.js +8 -0
  158. package/lib/apps/cli/internal/flags/generate/models.flags.d.ts +1 -0
  159. package/lib/apps/cli/internal/flags/generate/models.flags.js +14 -0
  160. package/lib/apps/cli/internal/flags/generate/sharedFlags.d.ts +16 -0
  161. package/lib/apps/cli/internal/flags/generate/sharedFlags.js +57 -0
  162. package/lib/apps/cli/internal/flags/global.flags.d.ts +4 -0
  163. package/lib/apps/cli/internal/flags/global.flags.js +18 -0
  164. package/lib/apps/cli/internal/flags/new/file.flags.d.ts +8 -0
  165. package/lib/apps/cli/internal/flags/new/file.flags.js +20 -0
  166. package/lib/apps/cli/internal/flags/new/template.flags.d.ts +7 -0
  167. package/lib/apps/cli/internal/flags/new/template.flags.js +28 -0
  168. package/lib/apps/cli/internal/flags/optimize.flags.d.ts +21 -0
  169. package/lib/apps/cli/internal/flags/optimize.flags.js +51 -0
  170. package/lib/apps/cli/internal/flags/parser.flags.d.ts +10 -0
  171. package/lib/apps/cli/internal/flags/parser.flags.js +28 -0
  172. package/lib/apps/cli/internal/flags/pretty.flags.d.ts +3 -0
  173. package/lib/apps/cli/internal/flags/pretty.flags.js +13 -0
  174. package/lib/apps/cli/internal/flags/proxy.flags.d.ts +4 -0
  175. package/lib/apps/cli/internal/flags/proxy.flags.js +17 -0
  176. package/lib/apps/cli/internal/flags/start/api.flags.d.ts +5 -0
  177. package/lib/apps/cli/internal/flags/start/api.flags.js +20 -0
  178. package/lib/apps/cli/internal/flags/start/preview.flags.d.ts +9 -0
  179. package/lib/apps/cli/internal/flags/start/preview.flags.js +32 -0
  180. package/lib/apps/cli/internal/flags/start/studio.flags.d.ts +7 -0
  181. package/lib/apps/cli/internal/flags/start/studio.flags.js +25 -0
  182. package/lib/apps/cli/internal/flags/validate.flags.d.ts +11 -0
  183. package/lib/apps/cli/internal/flags/validate.flags.js +22 -0
  184. package/lib/apps/cli/internal/globals.d.ts +10 -0
  185. package/lib/apps/cli/internal/globals.js +46 -0
  186. package/lib/apps/cli/internal/hooks/command_not_found/myhook.d.ts +4 -0
  187. package/lib/apps/cli/internal/hooks/command_not_found/myhook.js +85 -0
  188. package/lib/domains/models/Context.d.ts +21 -0
  189. package/lib/domains/models/Context.js +321 -0
  190. package/lib/domains/models/Preview.d.ts +2 -0
  191. package/lib/domains/models/Preview.js +227 -0
  192. package/lib/domains/models/SpecificationFile.d.ts +40 -0
  193. package/lib/domains/models/SpecificationFile.js +295 -0
  194. package/lib/domains/models/Studio.d.ts +2 -0
  195. package/lib/domains/models/Studio.js +182 -0
  196. package/lib/domains/models/generate/ClientLanguages.d.ts +12 -0
  197. package/lib/domains/models/generate/ClientLanguages.js +17 -0
  198. package/lib/domains/models/generate/Flags.d.ts +9 -0
  199. package/lib/domains/models/generate/Flags.js +2 -0
  200. package/lib/domains/services/archiver.service.d.ts +17 -0
  201. package/lib/domains/services/archiver.service.js +53 -0
  202. package/lib/domains/services/base.service.d.ts +6 -0
  203. package/lib/domains/services/base.service.js +26 -0
  204. package/lib/domains/services/config.service.d.ts +42 -0
  205. package/lib/domains/services/config.service.js +95 -0
  206. package/lib/domains/services/convert.service.d.ts +12 -0
  207. package/lib/domains/services/convert.service.js +65 -0
  208. package/lib/domains/services/generator.service.d.ts +15 -0
  209. package/lib/domains/services/generator.service.js +75 -0
  210. package/lib/domains/services/validation.service.d.ts +54 -0
  211. package/lib/domains/services/validation.service.js +375 -0
  212. package/lib/errors/context-error.d.ts +26 -0
  213. package/lib/errors/context-error.js +71 -0
  214. package/lib/errors/diff-error.d.ts +9 -0
  215. package/lib/errors/diff-error.js +27 -0
  216. package/lib/errors/generator-error.d.ts +3 -0
  217. package/lib/errors/generator-error.js +11 -0
  218. package/lib/errors/specification-file.d.ts +18 -0
  219. package/lib/errors/specification-file.js +65 -0
  220. package/lib/errors/validation-error.d.ts +11 -0
  221. package/lib/errors/validation-error.js +55 -0
  222. package/lib/index.d.ts +1 -0
  223. package/lib/index.js +11 -0
  224. package/lib/interfaces/index.d.ts +87 -0
  225. package/lib/interfaces/index.js +7 -0
  226. package/lib/utils/ajv.d.ts +2 -0
  227. package/lib/utils/ajv.js +18 -0
  228. package/lib/utils/app-openapi.d.ts +4 -0
  229. package/lib/utils/app-openapi.js +28 -0
  230. package/lib/utils/generate/flags.d.ts +2 -0
  231. package/lib/utils/generate/flags.js +14 -0
  232. package/lib/utils/generate/mapBaseUrl.d.ts +6 -0
  233. package/lib/utils/generate/mapBaseUrl.js +34 -0
  234. package/lib/utils/generate/parseParams.d.ts +3 -0
  235. package/lib/utils/generate/parseParams.js +58 -0
  236. package/lib/utils/generate/prompts.d.ts +4 -0
  237. package/lib/utils/generate/prompts.js +77 -0
  238. package/lib/utils/generate/registry.d.ts +2 -0
  239. package/lib/utils/generate/registry.js +30 -0
  240. package/lib/utils/generate/watcher.d.ts +51 -0
  241. package/lib/utils/generate/watcher.js +230 -0
  242. package/lib/utils/logger.d.ts +6 -0
  243. package/lib/utils/logger.js +33 -0
  244. package/lib/utils/retrieve-language.d.ts +1 -0
  245. package/lib/utils/retrieve-language.js +9 -0
  246. package/lib/utils/scoreCalculator.d.ts +2 -0
  247. package/lib/utils/scoreCalculator.js +22 -0
  248. package/lib/utils/temp-dir.d.ts +2 -0
  249. package/lib/utils/temp-dir.js +26 -0
  250. package/oclif.manifest.json +2137 -0
  251. package/openapi.yaml +713 -0
  252. package/package.json +203 -0
  253. package/scripts/enableAutoComplete.js +160 -0
  254. package/scripts/fetch-asyncapi-example.js +126 -0
  255. package/scripts/generateTypesForGenerateCommand.js +40 -0
  256. package/scripts/releasePackagesRename.js +88 -0
  257. package/scripts/updateUsageDocs.js +73 -0
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_PORT = void 0;
4
+ exports.start = start;
5
+ const tslib_1 = require("tslib");
6
+ const fs_1 = require("fs");
7
+ const specification_file_1 = require("../../errors/specification-file");
8
+ const http_1 = require("http");
9
+ const ws_1 = require("ws");
10
+ const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
11
+ const open_1 = tslib_1.__importDefault(require("open"));
12
+ const path_1 = tslib_1.__importDefault(require("path"));
13
+ const package_json_1 = require("@asyncapi/studio/package.json");
14
+ const picocolors_1 = require("picocolors");
15
+ const { readFile, writeFile } = fs_1.promises;
16
+ const sockets = [];
17
+ const messageQueue = [];
18
+ exports.DEFAULT_PORT = 0;
19
+ function isValidFilePath(filePath) {
20
+ return (0, fs_1.existsSync)(filePath);
21
+ }
22
+ function resolveStudioNextInstance(studioPath) {
23
+ var _a;
24
+ const resolvedNextPath = require.resolve('next', { paths: [studioPath] });
25
+ // eslint-disable-next-line @typescript-eslint/no-var-requires,security/detect-non-literal-require
26
+ const nextModule = require(resolvedNextPath);
27
+ return (_a = nextModule.default) !== null && _a !== void 0 ? _a : nextModule;
28
+ }
29
+ // eslint-disable-next-line sonarjs/cognitive-complexity
30
+ function start(filePath, port = exports.DEFAULT_PORT, noBrowser) {
31
+ if (filePath && !isValidFilePath(filePath)) {
32
+ throw new specification_file_1.SpecificationFileNotFound(filePath);
33
+ }
34
+ // Locate @asyncapi/studio package
35
+ const studioPath = path_1.default.dirname(require.resolve('@asyncapi/studio/package.json'));
36
+ const nextInstance = resolveStudioNextInstance(studioPath);
37
+ const app = nextInstance({
38
+ dev: false,
39
+ dir: studioPath,
40
+ conf: {
41
+ distDir: 'build',
42
+ },
43
+ });
44
+ const handle = app.getRequestHandler();
45
+ const wsServer = new ws_1.WebSocketServer({ noServer: true });
46
+ wsServer.on('connection', (socket) => {
47
+ sockets.push(socket);
48
+ if (filePath) {
49
+ getFileContent(filePath).then((code) => {
50
+ messageQueue.push(JSON.stringify({
51
+ type: 'file:loaded',
52
+ code,
53
+ }));
54
+ sendQueuedMessages();
55
+ });
56
+ }
57
+ else {
58
+ messageQueue.push(JSON.stringify({
59
+ type: 'file:loaded',
60
+ code: '',
61
+ }));
62
+ sendQueuedMessages();
63
+ }
64
+ socket.on('message', (event) => {
65
+ try {
66
+ const json = JSON.parse(event);
67
+ if (filePath && json.type === 'file:update') {
68
+ saveFileContent(filePath, json.code);
69
+ }
70
+ else {
71
+ console.warn('Live Server: An unknown event has been received. See details:');
72
+ console.log(json);
73
+ }
74
+ }
75
+ catch (e) {
76
+ console.error(`Live Server: An invalid event has been received. See details:\n${event}`);
77
+ }
78
+ });
79
+ });
80
+ wsServer.on('close', (socket) => {
81
+ sockets.splice(sockets.findIndex((s) => s === socket));
82
+ });
83
+ app.prepare().then(() => {
84
+ if (filePath) {
85
+ chokidar_1.default.watch(filePath).on('all', (event, path) => {
86
+ switch (event) {
87
+ case 'add':
88
+ case 'change':
89
+ getFileContent(path).then((code) => {
90
+ messageQueue.push(JSON.stringify({
91
+ type: 'file:changed',
92
+ code,
93
+ }));
94
+ sendQueuedMessages();
95
+ });
96
+ break;
97
+ case 'unlink':
98
+ messageQueue.push(JSON.stringify({
99
+ type: 'file:deleted',
100
+ filePath,
101
+ }));
102
+ sendQueuedMessages();
103
+ break;
104
+ }
105
+ });
106
+ }
107
+ const server = (0, http_1.createServer)((req, res) => {
108
+ if (req.url === '/close') {
109
+ for (const socket of wsServer.clients) {
110
+ socket.close();
111
+ }
112
+ res.writeHead(200, { 'Content-Type': 'application/json' });
113
+ res.end(JSON.stringify({ message: 'Server is shutting down' }));
114
+ // Close the server
115
+ server.close(() => {
116
+ // eslint-disable-next-line no-process-exit
117
+ process.exit(0);
118
+ });
119
+ return;
120
+ }
121
+ handle(req, res);
122
+ });
123
+ server.on('upgrade', (request, socket, head) => {
124
+ if (request.url === '/live-server') {
125
+ console.log('🔗 WebSocket connection established.');
126
+ wsServer.handleUpgrade(request, socket, head, (sock) => {
127
+ wsServer.emit('connection', sock, request);
128
+ });
129
+ }
130
+ else {
131
+ socket.destroy();
132
+ }
133
+ });
134
+ server.listen(port, () => {
135
+ const addr = server.address();
136
+ const listenPort = (addr && typeof addr === 'object' && 'port' in addr) ? addr.port : port;
137
+ const url = `http://localhost:${listenPort}?liveServer=${listenPort}&studio-version=${package_json_1.version}`;
138
+ console.log(`🎉 Connected to Live Server running at ${(0, picocolors_1.blueBright)(url)}.`);
139
+ console.log(`🌐 Open this URL in your web browser: ${(0, picocolors_1.blueBright)(url)}`);
140
+ console.log(`🛑 If needed, press ${(0, picocolors_1.redBright)('Ctrl + C')} to stop the process.`);
141
+ if (filePath) {
142
+ console.log(`👁️ Watching changes on file ${(0, picocolors_1.blueBright)(filePath)}`);
143
+ }
144
+ else {
145
+ console.warn('Warning: No file was provided, and we couldn\'t find a default file (like "asyncapi.yaml" or "asyncapi.json") in the current folder. Starting Studio with a blank workspace.');
146
+ }
147
+ if (!noBrowser) {
148
+ (0, open_1.default)(url);
149
+ }
150
+ }).on('error', (error) => {
151
+ if (error.message.includes('EADDRINUSE')) {
152
+ console.log(error);
153
+ console.error((0, picocolors_1.redBright)(`Error: Port ${port} is already in use.`));
154
+ // eslint-disable-next-line no-process-exit
155
+ process.exit(2);
156
+ }
157
+ else {
158
+ console.error(`Failed to start server on port ${port}`);
159
+ }
160
+ });
161
+ });
162
+ }
163
+ function sendQueuedMessages() {
164
+ while (messageQueue.length && sockets.length) {
165
+ const nextMessage = messageQueue.shift();
166
+ for (const socket of sockets) {
167
+ socket.send(nextMessage);
168
+ }
169
+ }
170
+ }
171
+ function getFileContent(filePath) {
172
+ return new Promise((resolve) => {
173
+ readFile(filePath, { encoding: 'utf8' })
174
+ .then((code) => {
175
+ resolve(code);
176
+ })
177
+ .catch(console.error);
178
+ });
179
+ }
180
+ function saveFileContent(filePath, fileContent) {
181
+ writeFile(filePath, fileContent, { encoding: 'utf8' }).catch(console.error);
182
+ }
@@ -0,0 +1,12 @@
1
+ export declare enum AvailableLanguage {
2
+ Dart = "dart",
3
+ Java = "java",
4
+ Javascript = "javascript",
5
+ Python = "python"
6
+ }
7
+ export declare const availableLanguages: readonly ["dart", "java", "javascript", "python"];
8
+ export type AvailableLanguageType = typeof availableLanguages[number];
9
+ /**
10
+ * Returns the first available language as the default option.
11
+ */
12
+ export declare const getDefaultLanguage: () => AvailableLanguageType;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultLanguage = exports.availableLanguages = exports.AvailableLanguage = void 0;
4
+ // Auto-generated. Do not edit manually.
5
+ var AvailableLanguage;
6
+ (function (AvailableLanguage) {
7
+ AvailableLanguage["Dart"] = "dart";
8
+ AvailableLanguage["Java"] = "java";
9
+ AvailableLanguage["Javascript"] = "javascript";
10
+ AvailableLanguage["Python"] = "python";
11
+ })(AvailableLanguage || (exports.AvailableLanguage = AvailableLanguage = {}));
12
+ exports.availableLanguages = ['dart', 'java', 'javascript', 'python'];
13
+ /**
14
+ * Returns the first available language as the default option.
15
+ */
16
+ const getDefaultLanguage = () => exports.availableLanguages[0];
17
+ exports.getDefaultLanguage = getDefaultLanguage;
@@ -0,0 +1,9 @@
1
+ export interface IMapBaseUrlToFlag {
2
+ url: string;
3
+ folder: string;
4
+ }
5
+ export interface ParsedFlags {
6
+ params: Record<string, string>;
7
+ disableHooks: Record<string, string>;
8
+ mapBaseUrlToFolder: IMapBaseUrlToFlag;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
1
+ import archiver, { Archiver } from 'archiver';
2
+ import { Response } from 'express';
3
+ /**
4
+ * Service wrapping the `archiver` module:
5
+ - easier zip creation
6
+ - adding proper `Content-Type` header
7
+ - easier adding an AsyncAPI document to the archive
8
+ - easier stream finalization
9
+ */
10
+ export declare class ArchiverService {
11
+ createZip(res?: Response): archiver.Archiver;
12
+ appendDirectory(archive: Archiver, from: string, to: string): void;
13
+ appendAsyncAPIDocument(archive: Archiver, asyncapi: string, fileName?: string): void;
14
+ finalize(archive: Archiver): Promise<void>;
15
+ createTempDirectory(): Promise<string>;
16
+ removeTempDirectory(tmpDir: string): Promise<void>;
17
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArchiverService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const archiver_1 = tslib_1.__importDefault(require("archiver"));
6
+ const retrieve_language_1 = require("../../utils/retrieve-language");
7
+ const temp_dir_1 = require("../../utils/temp-dir");
8
+ /**
9
+ * Service wrapping the `archiver` module:
10
+ - easier zip creation
11
+ - adding proper `Content-Type` header
12
+ - easier adding an AsyncAPI document to the archive
13
+ - easier stream finalization
14
+ */
15
+ class ArchiverService {
16
+ createZip(res) {
17
+ const zip = (0, archiver_1.default)('zip', { zlib: { level: 9 } });
18
+ if (res) {
19
+ zip.pipe(res);
20
+ res.attachment('asyncapi.zip');
21
+ }
22
+ return zip;
23
+ }
24
+ appendDirectory(archive, from, to) {
25
+ archive.directory(from, to);
26
+ }
27
+ appendAsyncAPIDocument(archive, asyncapi, fileName = 'asyncapi') {
28
+ asyncapi = JSON.stringify(asyncapi);
29
+ const language = (0, retrieve_language_1.retrieveLangauge)(asyncapi);
30
+ if (language === 'yaml') {
31
+ archive.append(asyncapi, { name: `${fileName}.yml` });
32
+ }
33
+ else {
34
+ archive.append(asyncapi, { name: `${fileName}.json` });
35
+ }
36
+ }
37
+ finalize(archive) {
38
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
39
+ yield new Promise((resolve) => {
40
+ // wait for end stream
41
+ archive.on('end', resolve);
42
+ archive.finalize();
43
+ });
44
+ });
45
+ }
46
+ createTempDirectory() {
47
+ return (0, temp_dir_1.createTempDirectory)();
48
+ }
49
+ removeTempDirectory(tmpDir) {
50
+ return (0, temp_dir_1.removeTempDirectory)(tmpDir);
51
+ }
52
+ }
53
+ exports.ArchiverService = ArchiverService;
@@ -0,0 +1,6 @@
1
+ import { ServiceResult } from '../../interfaces';
2
+ export declare abstract class BaseService {
3
+ protected createSuccessResult<T>(data: T): ServiceResult<T>;
4
+ protected createErrorResult(error: string, diagnostics?: any[]): ServiceResult;
5
+ protected handleServiceError(error: any): Promise<ServiceResult>;
6
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ class BaseService {
6
+ createSuccessResult(data) {
7
+ return {
8
+ success: true,
9
+ data,
10
+ };
11
+ }
12
+ createErrorResult(error, diagnostics) {
13
+ return {
14
+ success: false,
15
+ error,
16
+ diagnostics,
17
+ };
18
+ }
19
+ handleServiceError(error) {
20
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
21
+ const errorMessage = error instanceof Error ? error.message : String(error);
22
+ return this.createErrorResult(errorMessage);
23
+ });
24
+ }
25
+ }
26
+ exports.BaseService = BaseService;
@@ -0,0 +1,42 @@
1
+ export interface AuthEntry {
2
+ pattern: string;
3
+ token: string;
4
+ authType?: string;
5
+ headers?: Record<string, string>;
6
+ }
7
+ export interface AuthResult {
8
+ token: string;
9
+ authType: string;
10
+ headers: Record<string, string>;
11
+ }
12
+ interface Config {
13
+ auth?: AuthEntry[];
14
+ }
15
+ export declare class ConfigService {
16
+ /**
17
+ * Load config file (~/.asyncapi/config.json)
18
+ */
19
+ static loadConfig(): Promise<Config>;
20
+ /**
21
+ * Save config back to file
22
+ */
23
+ static saveConfig(config: Config): Promise<void>;
24
+ /**
25
+ * Add a new auth entry
26
+ */
27
+ static addAuthEntry(entry: AuthEntry): Promise<void>;
28
+ /**
29
+ * Reads auth config from ~/.asyncapi/config.json and
30
+ * returns auth info matching the given URL, or null if no match.
31
+ *
32
+ * @param url - URL to match against auth patterns
33
+ * @returns Auth info or null if no match found
34
+ */
35
+ static getAuthForUrl(url: string): Promise<AuthResult | null>;
36
+ /**
37
+ * Convert wildcard pattern (*, **) to RegExp matching start of string
38
+ * @param pattern - wildcard pattern
39
+ */
40
+ private static wildcardToRegex;
41
+ }
42
+ export {};
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const os_1 = tslib_1.__importDefault(require("os"));
7
+ const fs_1 = require("fs");
8
+ const CONFIG_DIR = path_1.default.join(os_1.default.homedir(), '.asyncapi');
9
+ const CONFIG_FILE = path_1.default.join(CONFIG_DIR, 'config.json');
10
+ class ConfigService {
11
+ /**
12
+ * Load config file (~/.asyncapi/config.json)
13
+ */
14
+ static loadConfig() {
15
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
+ try {
17
+ const content = yield fs_1.promises.readFile(CONFIG_FILE, 'utf8');
18
+ return JSON.parse(content);
19
+ }
20
+ catch (err) {
21
+ if (err.code === 'ENOENT') {
22
+ return {}; // no config yet
23
+ }
24
+ throw new Error(`Error reading config file: ${err.message}`);
25
+ }
26
+ });
27
+ }
28
+ /**
29
+ * Save config back to file
30
+ */
31
+ static saveConfig(config) {
32
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
33
+ yield fs_1.promises.mkdir(CONFIG_DIR, { recursive: true });
34
+ yield fs_1.promises.writeFile(CONFIG_FILE, JSON.stringify(config, null, 2), 'utf8');
35
+ });
36
+ }
37
+ /**
38
+ * Add a new auth entry
39
+ */
40
+ static addAuthEntry(entry) {
41
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
42
+ const config = yield this.loadConfig();
43
+ if (!config.auth) {
44
+ config.auth = [];
45
+ }
46
+ config.auth.push(entry);
47
+ yield this.saveConfig(config);
48
+ });
49
+ }
50
+ /**
51
+ * Reads auth config from ~/.asyncapi/config.json and
52
+ * returns auth info matching the given URL, or null if no match.
53
+ *
54
+ * @param url - URL to match against auth patterns
55
+ * @returns Auth info or null if no match found
56
+ */
57
+ static getAuthForUrl(url) {
58
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
59
+ const config = yield this.loadConfig();
60
+ if (!config.auth || !Array.isArray(config.auth)) {
61
+ console.warn('⚠️ No valid "auth" array found in config');
62
+ return null;
63
+ }
64
+ for (const entry of config.auth) {
65
+ try {
66
+ const regex = this.wildcardToRegex(entry.pattern);
67
+ if (regex.test(url)) {
68
+ return {
69
+ token: entry.token,
70
+ authType: entry.authType || 'Bearer',
71
+ headers: entry.headers || {}
72
+ };
73
+ }
74
+ }
75
+ catch (err) {
76
+ console.warn(`⚠️ Invalid pattern "${entry.pattern}": ${err.message}`);
77
+ }
78
+ }
79
+ return null;
80
+ });
81
+ }
82
+ /**
83
+ * Convert wildcard pattern (*, **) to RegExp matching start of string
84
+ * @param pattern - wildcard pattern
85
+ */
86
+ static wildcardToRegex(pattern) {
87
+ const escaped = pattern.replace(/[-/\\^$+?.()|[\]{}]/g, '\\$&');
88
+ const regexStr = escaped
89
+ .replace(/\*\*/g, '.*')
90
+ .replace(/\*/g, '[^/]*');
91
+ // eslint-disable-next-line security/detect-non-literal-regexp
92
+ return new RegExp(`^${regexStr}`);
93
+ }
94
+ }
95
+ exports.ConfigService = ConfigService;
@@ -0,0 +1,12 @@
1
+ import { ConversionOptions, ConversionResult, ServiceResult } from '../../interfaces';
2
+ import { Specification } from '../models/SpecificationFile';
3
+ import { BaseService } from './base.service';
4
+ export declare class ConversionService extends BaseService {
5
+ /**
6
+ * Handles the conversion of AsyncAPI, Postman or OpenAPI documents based on the provided flags.
7
+ */
8
+ convertDocument(specFile: Specification, options: ConversionOptions): Promise<ServiceResult<ConversionResult>>;
9
+ handleLogging(specFile: Specification, flags: ConversionOptions): string;
10
+ private formatConvertedFile;
11
+ handleOutput(outputPath: string, convertedFileFormatted: string): Promise<void>;
12
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConversionService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const base_service_1 = require("./base.service");
6
+ const converter_1 = require("@asyncapi/converter");
7
+ const picocolors_1 = require("picocolors");
8
+ const fs_1 = require("fs");
9
+ class ConversionService extends base_service_1.BaseService {
10
+ /**
11
+ * Handles the conversion of AsyncAPI, Postman or OpenAPI documents based on the provided flags.
12
+ */
13
+ convertDocument(specFile, options) {
14
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
+ var _a, _b, _c;
16
+ let convertedDocument;
17
+ switch (options.format) {
18
+ case 'asyncapi':
19
+ convertedDocument = (0, converter_1.convert)((_a = specFile.text()) !== null && _a !== void 0 ? _a : '', options['target-version'] || '3.0.0');
20
+ break;
21
+ case 'openapi':
22
+ convertedDocument = (0, converter_1.convertOpenAPI)((_b = specFile.text()) !== null && _b !== void 0 ? _b : '', specFile.toJson().openapi, {
23
+ perspective: options.perspective,
24
+ });
25
+ break;
26
+ case 'postman-collection':
27
+ convertedDocument = (0, converter_1.convertPostman)((_c = specFile.text()) !== null && _c !== void 0 ? _c : '', '3.0.0', {
28
+ perspective: options.perspective,
29
+ });
30
+ break;
31
+ default:
32
+ return this.createErrorResult(`Unsupported conversion format: ${options.format}`);
33
+ }
34
+ return this.createSuccessResult({
35
+ convertedDocument: this.formatConvertedFile(convertedDocument),
36
+ originalFormat: options.format,
37
+ });
38
+ });
39
+ }
40
+ handleLogging(specFile, flags) {
41
+ const sourcePath = specFile.getFilePath() || specFile.getFileURL();
42
+ const targetVersion = flags['target-version'] || 'latest';
43
+ const outputMap = {
44
+ asyncapi: 'AsyncAPI document',
45
+ openapi: 'OpenAPI document',
46
+ 'postman-collection': 'Postman Collection',
47
+ };
48
+ return `🎉 The ${outputMap[flags.format]} from ${(0, picocolors_1.cyan)(sourcePath)} has been successfully converted to AsyncAPI version ${(0, picocolors_1.green)(targetVersion)}!!`;
49
+ }
50
+ // Helper function to format the converted file
51
+ formatConvertedFile(convertedFile) {
52
+ return typeof convertedFile === 'object'
53
+ ? JSON.stringify(convertedFile, null, 4)
54
+ : convertedFile;
55
+ }
56
+ // Helper function to handle output
57
+ handleOutput(outputPath, convertedFileFormatted) {
58
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
59
+ yield fs_1.promises.writeFile(`${outputPath}`, convertedFileFormatted, {
60
+ encoding: 'utf8',
61
+ });
62
+ });
63
+ }
64
+ }
65
+ exports.ConversionService = ConversionService;
@@ -0,0 +1,15 @@
1
+ import { GenerationOptions, GenerationResult, ServiceResult } from '../../interfaces';
2
+ import { Specification } from '../models/SpecificationFile';
3
+ import { BaseService } from './base.service';
4
+ export declare class GeneratorService extends BaseService {
5
+ private defaultInteractive;
6
+ constructor(interactive?: boolean);
7
+ private templatesNotSupportingV3;
8
+ /**
9
+ * Verify that a given template support v3, if not, return the link to the issue that needs to be solved.
10
+ */
11
+ private verifyTemplateSupportForV3;
12
+ private getGenerationSuccessMessage;
13
+ private checkV3NotSupported;
14
+ generate(asyncapi: Specification, template: string, output: string, options: GenerationOptions, genOption: any, interactive?: boolean): Promise<ServiceResult<GenerationResult>>;
15
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeneratorService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const base_service_1 = require("./base.service");
6
+ const generator_1 = tslib_1.__importDefault(require("@asyncapi/generator"));
7
+ const prompts_1 = require("@clack/prompts");
8
+ const path_1 = tslib_1.__importDefault(require("path"));
9
+ const os_1 = tslib_1.__importDefault(require("os"));
10
+ const picocolors_1 = require("picocolors");
11
+ class GeneratorService extends base_service_1.BaseService {
12
+ constructor(interactive = false) {
13
+ super();
14
+ this.templatesNotSupportingV3 = {
15
+ '@asyncapi/minimaltemplate': 'some link', // For testing purpose
16
+ '@asyncapi/dotnet-nats-template': 'https://github.com/asyncapi/dotnet-nats-template/issues/384',
17
+ '@asyncapi/ts-nats-template': 'https://github.com/asyncapi/ts-nats-template/issues/545',
18
+ '@asyncapi/python-paho-template': 'https://github.com/asyncapi/python-paho-template/issues/189',
19
+ '@asyncapi/nodejs-ws-template': 'https://github.com/asyncapi/nodejs-ws-template/issues/294',
20
+ '@asyncapi/java-spring-cloud-stream-template': 'https://github.com/asyncapi/java-spring-cloud-stream-template/issues/336',
21
+ '@asyncapi/go-watermill-template': 'https://github.com/asyncapi/go-watermill-template/issues/243',
22
+ '@asyncapi/java-spring-template': 'https://github.com/asyncapi/java-spring-template/issues/308',
23
+ '@asyncapi/php-template': 'https://github.com/asyncapi/php-template/issues/191',
24
+ };
25
+ this.defaultInteractive = interactive;
26
+ }
27
+ /**
28
+ * Verify that a given template support v3, if not, return the link to the issue that needs to be solved.
29
+ */
30
+ verifyTemplateSupportForV3(template) {
31
+ if (this.templatesNotSupportingV3[`${template}`] !== undefined) {
32
+ return this.templatesNotSupportingV3[`${template}`];
33
+ }
34
+ return undefined;
35
+ }
36
+ getGenerationSuccessMessage(output) {
37
+ return `${(0, picocolors_1.yellow)('Check out your shiny new generated files at ') + (0, picocolors_1.magenta)(output) + (0, picocolors_1.yellow)('.')}\n\n`;
38
+ }
39
+ checkV3NotSupported(asyncapi, template) {
40
+ if (asyncapi.isAsyncAPI3()) {
41
+ const v3IssueLink = this.verifyTemplateSupportForV3(template);
42
+ if (v3IssueLink !== undefined) {
43
+ return `${template} template does not support AsyncAPI v3 documents, please checkout ${v3IssueLink}`;
44
+ }
45
+ }
46
+ }
47
+ generate(asyncapi_1, template_1, output_1, options_1, genOption_1) {
48
+ return tslib_1.__awaiter(this, arguments, void 0, function* (asyncapi, template, output, options, genOption, interactive = this.defaultInteractive) {
49
+ const v3NotSupported = this.checkV3NotSupported(asyncapi, template);
50
+ if (v3NotSupported) {
51
+ return this.createErrorResult(v3NotSupported);
52
+ }
53
+ const logs = [];
54
+ const generator = new generator_1.default(template, output || path_1.default.resolve(os_1.default.tmpdir(), 'asyncapi-generator'), options);
55
+ const s = interactive
56
+ ? (0, prompts_1.spinner)()
57
+ : { start: () => null, stop: (string) => logs.push(string) };
58
+ s.start('Generation in progress. Keep calm and wait a bit');
59
+ try {
60
+ yield generator.generateFromString(asyncapi.text(), Object.assign(Object.assign({}, genOption), { path: asyncapi }));
61
+ }
62
+ catch (err) {
63
+ s.stop('Generation failed');
64
+ return this.createErrorResult(err.message, err.diagnostics);
65
+ }
66
+ s.stop(this.getGenerationSuccessMessage(output));
67
+ return this.createSuccessResult({
68
+ success: true,
69
+ outputPath: output,
70
+ logs,
71
+ });
72
+ });
73
+ }
74
+ }
75
+ exports.GeneratorService = GeneratorService;