@eventcatalog/generator-asyncapi 0.0.3 → 0.1.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.
package/README.md CHANGED
@@ -130,3 +130,5 @@ You can find the [contributing guidelines here](https://eventcatalog.dev/docs/co
130
130
  # Commercial Use
131
131
 
132
132
  This project is governed by a [dual-license](./LICENSE.md). To ensure the sustainability of the project, you can freely make use of this software if your projects are Open Source. Otherwise for proprietary systems you must obtain a [commercial license](./LICENSE-COMMERCIAL.md).
133
+
134
+ To obtain a commercial license or have any questions you can email us at `hello@eventcatalog.dev`.
package/dist/index.d.mts CHANGED
@@ -1,25 +1,13 @@
1
- import { OpenAPIV3_1 } from 'openapi-types';
2
-
3
- type Props = {
4
- path: string | string[];
5
- domain?: Domain;
6
- debug?: boolean;
7
- };
8
1
  type Domain = {
9
2
  id: string;
10
3
  name: string;
11
4
  version: string;
12
5
  };
13
- type Operation = {
14
- path: string;
15
- method: string;
16
- operationId: string;
17
- summary?: string;
18
- description?: string;
19
- type: string;
20
- externalDocs?: OpenAPIV3_1.ExternalDocumentationObject;
21
- tags: string[];
6
+ type Props = {
7
+ path: string | string[];
8
+ domain?: Domain;
9
+ debug?: boolean;
22
10
  };
23
11
  declare const _default: (config: any, options: Props) => Promise<void>;
24
12
 
25
- export { type Operation, _default as default };
13
+ export { _default as default };
package/dist/index.d.ts CHANGED
@@ -1,25 +1,13 @@
1
- import { OpenAPIV3_1 } from 'openapi-types';
2
-
3
- type Props = {
4
- path: string | string[];
5
- domain?: Domain;
6
- debug?: boolean;
7
- };
8
1
  type Domain = {
9
2
  id: string;
10
3
  name: string;
11
4
  version: string;
12
5
  };
13
- type Operation = {
14
- path: string;
15
- method: string;
16
- operationId: string;
17
- summary?: string;
18
- description?: string;
19
- type: string;
20
- externalDocs?: OpenAPIV3_1.ExternalDocumentationObject;
21
- tags: string[];
6
+ type Props = {
7
+ path: string | string[];
8
+ domain?: Domain;
9
+ debug?: boolean;
22
10
  };
23
11
  declare const _default: (config: any, options: Props) => Promise<void>;
24
12
 
25
- export { type Operation, _default as default };
13
+ export { _default as default };
package/dist/index.js CHANGED
@@ -33,67 +33,92 @@ __export(src_exports, {
33
33
  default: () => src_default
34
34
  });
35
35
  module.exports = __toCommonJS(src_exports);
36
- var import_sdk = __toESM(require("@eventcatalog/sdk"));
36
+ var import_parser = require("@asyncapi/parser");
37
37
  var import_promises = require("fs/promises");
38
- var import_chalk2 = __toESM(require("chalk"));
39
- var import_swagger_parser = __toESM(require("@apidevtools/swagger-parser"));
38
+ var import_sdk = __toESM(require("@eventcatalog/sdk"));
40
39
  var import_slugify = __toESM(require("slugify"));
41
40
 
42
- // src/utils/domains.ts
43
- var defaultMarkdown = () => {
44
- return `
41
+ // src/utils/schemas.ts
42
+ var getFileExtentionFromSchemaFormat = (format = "") => {
43
+ if (format.includes("avro")) return "avsc";
44
+ if (format.includes("yml")) return "yml";
45
+ if (format.includes("json")) return "json";
46
+ if (format.includes("openapi")) return "openapi";
47
+ if (format.includes("protobuf")) return "protobuf";
48
+ if (format.includes("yaml")) return "yaml";
49
+ return "json";
50
+ };
45
51
 
46
- ## Architecture diagram
52
+ // src/utils/messages.ts
53
+ var defaultMarkdown = (document, message) => {
54
+ return `
55
+ ## Architecture
47
56
  <NodeGraph />
48
57
 
58
+ ${messageHasSchema(message) ? `
59
+ ## Schema
60
+ <SchemaViewer file="${getSchemaFileName(message)}" title="Message Schema" maxHeight="500" />
61
+ ` : ""}
62
+
63
+ ${message.externalDocs() ? `
64
+ ## External documentation
65
+ - [${message.externalDocs()?.description()}](${message.externalDocs()?.url()})
66
+ ` : ""}
67
+
49
68
  `;
50
69
  };
70
+ var getSummary = (message) => {
71
+ const messageSummary = message.hasSummary() ? message.summary() : "";
72
+ const messageDescription = message.hasDescription() ? message.description() : "";
73
+ let eventCatalogMessageSummary = messageSummary;
74
+ if (!eventCatalogMessageSummary) {
75
+ eventCatalogMessageSummary = messageDescription && messageDescription.length < 150 ? messageDescription : "";
76
+ }
77
+ return eventCatalogMessageSummary;
78
+ };
79
+ var messageHasSchema = (message) => {
80
+ return message.hasPayload() && message.schemaFormat();
81
+ };
82
+ var getSchemaFileName = (message) => {
83
+ const extension = getFileExtentionFromSchemaFormat(message.schemaFormat());
84
+ return `schema.${extension}`;
85
+ };
86
+ var getMessageName = (message) => {
87
+ return message.hasTitle() && message.title() ? message.title() : message.id();
88
+ };
51
89
 
52
90
  // src/utils/services.ts
53
91
  var defaultMarkdown2 = (document) => {
54
92
  return `
55
93
 
56
- ${document.info.description ? `${document.info.description}` : ""}
94
+ ${document.info().hasDescription() ? `${document.info().description()}` : ""}
57
95
 
58
96
  ## Architecture diagram
59
97
  <NodeGraph />
60
98
 
61
- ${document.externalDocs ? `
99
+ ${document.info().externalDocs() ? `
62
100
  ## External documentation
63
- - [${document.externalDocs.description}](${document.externalDocs.url})
101
+ - [${document.info().externalDocs()?.description()}](${document.info().externalDocs()?.url()})
64
102
  ` : ""}
65
103
  `;
66
104
  };
67
- var getSummary = (document) => {
68
- const summary = document.info.description ? document.info.description : "";
105
+ var getSummary2 = (document) => {
106
+ const summary = document.info().hasDescription() ? document.info().description() : "";
69
107
  return summary && summary.length < 150 ? summary : "";
70
108
  };
71
109
 
72
- // src/utils/messages.ts
73
- var defaultMarkdown3 = (message) => {
110
+ // src/utils/domains.ts
111
+ var defaultMarkdown3 = (document) => {
74
112
  return `
75
- ## Architecture
76
- <NodeGraph />
77
113
 
78
- ${message.externalDocs ? `
79
- ## External documentation
80
- - [${message.externalDocs.description}](${message.externalDocs.url})
81
- ` : ""}
114
+ ## Architecture diagram
115
+ <NodeGraph />
82
116
 
83
117
  `;
84
118
  };
85
- var getSummary2 = (message) => {
86
- const messageSummary = message.summary ? message.summary : "";
87
- const messageDescription = message.description ? message.description : "";
88
- let eventCatalogMessageSummary = messageSummary;
89
- if (!eventCatalogMessageSummary) {
90
- eventCatalogMessageSummary = messageDescription && messageDescription.length < 150 ? messageDescription : "";
91
- }
92
- return eventCatalogMessageSummary;
93
- };
94
- var getMessageName = (message) => {
95
- return message.operationId;
96
- };
119
+
120
+ // src/index.ts
121
+ var import_chalk2 = __toESM(require("chalk"));
97
122
 
98
123
  // src/checkLicense.ts
99
124
  var import_chalk = __toESM(require("chalk"));
@@ -109,72 +134,57 @@ If using for internal, commercial or proprietary software, please contact hello@
109
134
  };
110
135
 
111
136
  // src/index.ts
112
- var DEFAULT_MESSAGE_TYPE = "query";
113
- async function getOperationsByType(openApiPath) {
114
- try {
115
- const api = await import_swagger_parser.default.validate(openApiPath);
116
- const operations = [];
117
- for (const path in api.paths) {
118
- const pathItem = api.paths[path];
119
- for (const method in pathItem) {
120
- const openAPIOperation = pathItem[method];
121
- const messageType = openAPIOperation["x-eventcatalog-message-type"] || DEFAULT_MESSAGE_TYPE;
122
- const operation = {
123
- path,
124
- method: method.toUpperCase(),
125
- operationId: openAPIOperation.operationId,
126
- externalDocs: openAPIOperation.externalDocs,
127
- type: messageType,
128
- description: openAPIOperation.description,
129
- summary: openAPIOperation.summary,
130
- tags: openAPIOperation.tags || []
131
- };
132
- operations.push(operation);
133
- }
134
- }
135
- return operations;
136
- } catch (err) {
137
- console.error("Error parsing OpenAPI document:", err);
138
- return [];
139
- }
140
- }
137
+ var import_minimist = __toESM(require("minimist"));
138
+ var parser = new import_parser.Parser();
139
+ var cliArgs = (0, import_minimist.default)(process.argv.slice(2));
141
140
  var src_default = async (config, options) => {
142
141
  if (!process.env.PROJECT_DIR) {
143
142
  throw new Error("Please provide catalog url (env variable PROJECT_DIR)");
144
143
  }
145
144
  const {
145
+ writeService,
146
146
  writeEvent,
147
- getDomain,
148
- versionDomain,
149
- writeDomain,
150
- addServiceToDomain,
147
+ writeCommand,
151
148
  getService,
152
149
  versionService,
153
150
  rmService,
154
- writeService,
155
- addFileToService,
156
- versionCommand,
157
- getEvent,
151
+ getDomain,
152
+ writeDomain,
153
+ addServiceToDomain,
158
154
  getCommand,
159
- rmCommandById,
155
+ getEvent,
160
156
  rmEventById,
161
- writeCommand
157
+ rmCommandById,
158
+ versionCommand,
159
+ versionEvent,
160
+ addSchemaToCommand,
161
+ addSchemaToEvent,
162
+ addFileToService,
163
+ versionDomain
162
164
  } = (0, import_sdk.default)(process.env.PROJECT_DIR);
163
- const openAPIFiles = Array.isArray(options.path) ? options.path : [options.path];
164
- for (const path of openAPIFiles) {
165
- console.log(import_chalk2.default.green(`Processing ${path}`));
166
- try {
167
- await import_swagger_parser.default.validate(path);
168
- } catch (error) {
169
- console.error(import_chalk2.default.red(`Failed to parse OpenAPI file: ${path}`));
170
- console.error(import_chalk2.default.red(error));
165
+ const asyncAPIFiles = Array.isArray(options.path) ? options.path : [options.path];
166
+ console.log(import_chalk2.default.green(`Processing ${asyncAPIFiles.length} AsyncAPI files...`));
167
+ for (const path of asyncAPIFiles) {
168
+ console.log(import_chalk2.default.gray(`Processing ${path}`));
169
+ const asyncAPIFile = await (0, import_promises.readFile)(path, "utf-8");
170
+ const { document } = await parser.parse(asyncAPIFile);
171
+ if (!document) {
172
+ console.log(import_chalk2.default.red("Failed to parse AsyncAPI file"));
173
+ if (options.debug || cliArgs.debug) {
174
+ const diagnostics = await parser.validate(asyncAPIFile);
175
+ console.log(diagnostics);
176
+ } else {
177
+ console.log(import_chalk2.default.red("Run with debug option in the generator to see diagnostics"));
178
+ }
171
179
  continue;
172
180
  }
173
- const openAPIFile = await (0, import_promises.readFile)(path, "utf-8");
174
- const document = await import_swagger_parser.default.parse(path);
175
- const operations = await getOperationsByType(path);
176
- const serviceId = (0, import_slugify.default)(document.info.title, { lower: true, strict: true });
177
- const version = document.info.version;
181
+ const operations = document.allOperations();
182
+ const documentTags = document.info().tags().all() || [];
183
+ const serviceId = (0, import_slugify.default)(document.info().title(), { lower: true, strict: true });
184
+ const version = document.info().version();
185
+ const sends = [];
186
+ const receives = [];
187
+ let specifications = {};
178
188
  let serviceMarkdown = defaultMarkdown2(document);
179
189
  if (options.domain) {
180
190
  const { id: domainId, name: domainName, version: domainVersion } = options.domain;
@@ -191,7 +201,8 @@ Processing domain: ${domainName} (v${domainVersion})`));
191
201
  id: domainId,
192
202
  name: domainName,
193
203
  version: domainVersion,
194
- markdown: defaultMarkdown()
204
+ markdown: defaultMarkdown3(document)
205
+ // services: [{ id: serviceId, version: version }],
195
206
  });
196
207
  console.log(import_chalk2.default.cyan(` - Domain (v${domainVersion}) created`));
197
208
  }
@@ -200,85 +211,105 @@ Processing domain: ${domainName} (v${domainVersion})`));
200
211
  }
201
212
  await addServiceToDomain(domainId, { id: serviceId, version }, domainVersion);
202
213
  }
203
- const documentTags = document.tags || [];
204
- let sends = [];
205
- const receives = [];
206
214
  for (const operation of operations) {
207
- const messageType = operation.type;
208
- const messageId = getMessageName(operation);
209
- let messageMarkdown = defaultMarkdown3(operation);
210
- const versionMessage = versionCommand;
211
- const getMessage = messageType === "event" ? getEvent : getCommand;
212
- const rmMessageById = messageType === "event" ? rmEventById : rmCommandById;
213
- const writeMessage = messageType === "event" ? writeEvent : writeCommand;
214
- const catalogedMessage = await getMessage(messageId, "latest");
215
- console.log(import_chalk2.default.blue(`Processing message: ${getMessageName(operation)} (v${version})`));
216
- if (catalogedMessage) {
217
- messageMarkdown = catalogedMessage.markdown;
218
- if (catalogedMessage.version === version) {
219
- await rmMessageById(messageId, version);
220
- } else {
221
- await versionMessage(messageId);
222
- console.log(import_chalk2.default.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));
215
+ for (const message of operation.messages()) {
216
+ const eventType = message.extensions().get("x-eventcatalog-message-type")?.value() || "event";
217
+ const messageId = message.id().toLowerCase();
218
+ let messageMarkdown = defaultMarkdown(document, message);
219
+ const writeMessage = eventType === "event" ? writeEvent : writeCommand;
220
+ const versionMessage = eventType === "event" ? versionEvent : versionCommand;
221
+ const getMessage = eventType === "event" ? getEvent : getCommand;
222
+ const rmMessageById = eventType === "event" ? rmEventById : rmCommandById;
223
+ const addSchemaToMessage = eventType === "event" ? addSchemaToEvent : addSchemaToCommand;
224
+ const badges = message.tags().all() || [];
225
+ const catalogedMessage = await getMessage(message.id().toLowerCase(), "latest");
226
+ console.log(import_chalk2.default.blue(`Processing message: ${getMessageName(message)} (v${version})`));
227
+ if (catalogedMessage) {
228
+ messageMarkdown = catalogedMessage.markdown;
229
+ if (catalogedMessage.version === version) {
230
+ await rmMessageById(messageId, version);
231
+ } else {
232
+ await versionMessage(messageId);
233
+ console.log(import_chalk2.default.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));
234
+ }
223
235
  }
224
- }
225
- await writeMessage(
226
- {
227
- id: messageId,
228
- version,
229
- name: getMessageName(operation),
230
- summary: getSummary2(operation),
231
- markdown: messageMarkdown,
232
- badges: operation.tags.map((badge) => ({ content: badge, textColor: "blue", backgroundColor: "blue" }))
233
- },
234
- {
235
- path: messageId
236
+ await writeMessage(
237
+ {
238
+ id: messageId,
239
+ version,
240
+ name: getMessageName(message),
241
+ summary: getSummary(message),
242
+ markdown: messageMarkdown,
243
+ badges: badges.map((badge) => ({ content: badge.name(), textColor: "blue", backgroundColor: "blue" })),
244
+ schemaPath: messageHasSchema(message) ? getSchemaFileName(message) : void 0
245
+ },
246
+ {
247
+ path: message.id()
248
+ }
249
+ );
250
+ console.log(import_chalk2.default.cyan(` - Message (v${version}) created`));
251
+ if (messageHasSchema(message)) {
252
+ addSchemaToMessage(
253
+ messageId,
254
+ {
255
+ fileName: getSchemaFileName(message),
256
+ schema: JSON.stringify(message.payload()?.json(), null, 4)
257
+ },
258
+ version
259
+ );
260
+ console.log(import_chalk2.default.cyan(` - Schema added to message (v${version})`));
236
261
  }
237
- );
238
- receives.push({
239
- id: operation.operationId,
240
- version
241
- });
242
- console.log(import_chalk2.default.cyan(` - Message (v${version}) created`));
262
+ if (operation.action() === "send" || operation.action() === "publish") {
263
+ sends.push({ id: messageId, version });
264
+ }
265
+ if (operation.action() === "receive" || operation.action() === "subscribe") {
266
+ receives.push({ id: messageId, version });
267
+ }
268
+ }
243
269
  }
244
270
  const latestServiceInCatalog = await getService(serviceId, "latest");
245
- console.log(import_chalk2.default.blue(`Processing service: ${document.info.title} (v${version})`));
271
+ console.log(import_chalk2.default.blue(`Processing service: ${document.info().title()} (v${version})`));
246
272
  if (latestServiceInCatalog) {
247
273
  serviceMarkdown = latestServiceInCatalog.markdown;
248
- sends = latestServiceInCatalog.sends || [];
249
274
  if (latestServiceInCatalog.version !== version) {
250
275
  await versionService(serviceId);
251
276
  console.log(import_chalk2.default.cyan(` - Versioned previous service (v${latestServiceInCatalog.version})`));
252
277
  }
253
278
  if (latestServiceInCatalog.version === version) {
254
- await rmService(document.info.title);
279
+ serviceMarkdown = latestServiceInCatalog.markdown;
280
+ specifications = latestServiceInCatalog.specifications ?? {};
281
+ await rmService(document.info().title());
255
282
  }
256
283
  }
257
284
  await writeService(
258
285
  {
259
286
  id: serviceId,
260
- name: document.info.title,
287
+ name: document.info().title(),
261
288
  version,
262
- summary: getSummary(document),
263
- badges: documentTags.map((tag) => ({ content: tag.name, textColor: "blue", backgroundColor: "blue" })),
289
+ summary: getSummary2(document),
290
+ badges: documentTags.map((tag) => ({ content: tag.name(), textColor: "blue", backgroundColor: "blue" })),
264
291
  markdown: serviceMarkdown,
265
292
  sends,
266
- schemaPath: path.split("/").pop() || "openapi.yml",
267
- receives
293
+ receives,
294
+ schemaPath: path.split("/").pop() || "asyncapi.yml",
295
+ specifications: {
296
+ ...specifications,
297
+ asyncapiPath: path.split("/").pop() || "asyncapi.yml"
298
+ }
268
299
  },
269
- { path: document.info.title }
300
+ { path: document.info().title() }
270
301
  );
271
302
  await addFileToService(
272
303
  serviceId,
273
304
  {
274
- fileName: path.split("/").pop() || "openapi.yml",
275
- content: openAPIFile
305
+ fileName: path.split("/").pop() || "asyncapi.yml",
306
+ content: asyncAPIFile
276
307
  },
277
308
  version
278
309
  );
279
310
  console.log(import_chalk2.default.cyan(` - Service (v${version}) created`));
280
311
  console.log(import_chalk2.default.green(`
281
- Finished generating event catalog for AsyncAPI ${document.info.title} (v${version})`));
312
+ Finished generating event catalog for AsyncAPI ${document.info().title()} (v${version})`));
282
313
  }
283
314
  await checkLicense_default();
284
315
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/utils/domains.ts","../src/utils/services.ts","../src/utils/messages.ts","../src/checkLicense.ts"],"sourcesContent":["// import utils from '@eventcatalog/sdk';\n// import { Parser } from '@asyncapi/parser';\n// const parser = new Parser();\nimport utils from '@eventcatalog/sdk';\n// import slugify from 'slugify';\nimport { readFile } from 'node:fs/promises';\nimport chalk from 'chalk';\nimport SwaggerParser from '@apidevtools/swagger-parser';\nimport slugify from 'slugify';\nimport { defaultMarkdown as generateMarkdownForDomain } from './utils/domains';\nimport { defaultMarkdown as generateMarkdownForService, getSummary as getServiceSummary } from './utils/services';\nimport { defaultMarkdown as generateMarkdownForMessage, getSummary as getMessageSummary } from './utils/messages';\n\nimport { OpenAPIV3_1 } from 'openapi-types';\nimport { getMessageName } from './utils/messages';\nimport checkLicense from './checkLicense';\n\ntype Props = {\n path: string | string[];\n domain?: Domain;\n debug?: boolean;\n};\n\ntype Domain = {\n id: string;\n name: string;\n version: string;\n};\n\nconst DEFAULT_MESSAGE_TYPE = 'query';\n\nexport type Operation = {\n path: string;\n method: string;\n operationId: string;\n summary?: string;\n description?: string;\n type: string;\n externalDocs?: OpenAPIV3_1.ExternalDocumentationObject;\n tags: string[];\n};\n\nasync function getOperationsByType(openApiPath: string) {\n try {\n // Parse the OpenAPI document\n const api = await SwaggerParser.validate(openApiPath);\n\n const operations = [];\n\n // Iterate through paths\n for (const path in api.paths) {\n const pathItem = api.paths[path];\n\n // Iterate through each HTTP method in the path\n for (const method in pathItem) {\n // @ts-ignore\n const openAPIOperation = pathItem[method];\n\n // Check if the x-eventcatalog-message-type field is set\n const messageType = openAPIOperation['x-eventcatalog-message-type'] || DEFAULT_MESSAGE_TYPE;\n\n const operation = {\n path: path,\n method: method.toUpperCase(),\n operationId: openAPIOperation.operationId,\n externalDocs: openAPIOperation.externalDocs,\n type: messageType,\n description: openAPIOperation.description,\n summary: openAPIOperation.summary,\n tags: openAPIOperation.tags || [],\n } as Operation;\n\n operations.push(operation);\n }\n }\n\n return operations;\n } catch (err) {\n console.error('Error parsing OpenAPI document:', err);\n return [];\n }\n}\n\nexport default async (config: any, options: Props) => {\n if (!process.env.PROJECT_DIR) {\n throw new Error('Please provide catalog url (env variable PROJECT_DIR)');\n }\n\n const {\n writeEvent,\n getDomain,\n versionDomain,\n writeDomain,\n addServiceToDomain,\n getService,\n versionService,\n rmService,\n writeService,\n addFileToService,\n versionCommand,\n getEvent,\n getCommand,\n rmCommandById,\n rmEventById,\n writeCommand,\n } = utils(process.env.PROJECT_DIR);\n\n const openAPIFiles = Array.isArray(options.path) ? options.path : [options.path];\n\n for (const path of openAPIFiles) {\n console.log(chalk.green(`Processing ${path}`));\n\n try {\n await SwaggerParser.validate(path);\n } catch (error) {\n console.error(chalk.red(`Failed to parse OpenAPI file: ${path}`));\n console.error(chalk.red(error));\n continue;\n }\n\n const openAPIFile = await readFile(path, 'utf-8');\n const document = await SwaggerParser.parse(path);\n const operations = await getOperationsByType(path);\n\n const serviceId = slugify(document.info.title, { lower: true, strict: true });\n const version = document.info.version;\n let serviceMarkdown = generateMarkdownForService(document);\n\n // Manage domain\n if (options.domain) {\n // Try and get the domain\n const { id: domainId, name: domainName, version: domainVersion } = options.domain;\n const domain = await getDomain(options.domain.id, domainVersion || 'latest');\n const currentDomain = await getDomain(options.domain.id, 'latest');\n\n console.log(chalk.blue(`\\nProcessing domain: ${domainName} (v${domainVersion})`));\n\n // Found a domain, but the versions do not match\n if (currentDomain && currentDomain.version !== domainVersion) {\n await versionDomain(domainId);\n console.log(chalk.cyan(` - Versioned previous domain (v${currentDomain.version})`));\n }\n\n // Do we need to create a new domain?\n if (!domain || (domain && domain.version !== domainVersion)) {\n await writeDomain({\n id: domainId,\n name: domainName,\n version: domainVersion,\n markdown: generateMarkdownForDomain(),\n });\n console.log(chalk.cyan(` - Domain (v${domainVersion}) created`));\n }\n\n if (currentDomain && currentDomain.version === domainVersion) {\n console.log(chalk.yellow(` - Domain (v${domainVersion}) already exists, skipped creation...`));\n }\n\n // Add the service to the domain\n await addServiceToDomain(domainId, { id: serviceId, version: version }, domainVersion);\n }\n\n // parse\n // const { document } = await parser.parse(asyncAPIFile);\n\n // const operations = document.allOperations();\n const documentTags = document.tags || [];\n\n // // What messages does this service send and receive\n let sends = [];\n const receives = [];\n\n for (const operation of operations) {\n const messageType = operation.type;\n const messageId = getMessageName(operation);\n let messageMarkdown = generateMarkdownForMessage(operation);\n const versionMessage = versionCommand;\n const getMessage = messageType === 'event' ? getEvent : getCommand;\n const rmMessageById = messageType === 'event' ? rmEventById : rmCommandById;\n const writeMessage = messageType === 'event' ? writeEvent : writeCommand;\n // const addSchemaToMessage = messageType === 'event' ? addSchemaToEvent : addSchemaToCommand;\n\n // Check if the message already exists in the catalog\n const catalogedMessage = await getMessage(messageId, 'latest');\n\n console.log(chalk.blue(`Processing message: ${getMessageName(operation)} (v${version})`));\n\n if (catalogedMessage) {\n messageMarkdown = catalogedMessage.markdown;\n // if the version matches, we can override the message but keep markdown as it was\n if (catalogedMessage.version === version) {\n await rmMessageById(messageId, version);\n } else {\n // if the version does not match, we need to version the message\n await versionMessage(messageId);\n console.log(chalk.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));\n }\n }\n\n await writeMessage(\n {\n id: messageId,\n version: version,\n name: getMessageName(operation),\n summary: getMessageSummary(operation),\n markdown: messageMarkdown,\n badges: operation.tags.map((badge) => ({ content: badge, textColor: 'blue', backgroundColor: 'blue' })),\n },\n {\n path: messageId,\n }\n );\n\n // messages will always be messages the service receives\n receives.push({\n id: operation.operationId,\n version: version,\n });\n\n console.log(chalk.cyan(` - Message (v${version}) created`));\n }\n\n // Check if service is already defined... if the versions do not match then create service.\n const latestServiceInCatalog = await getService(serviceId, 'latest');\n console.log(chalk.blue(`Processing service: ${document.info.title} (v${version})`));\n\n if (latestServiceInCatalog) {\n serviceMarkdown = latestServiceInCatalog.markdown;\n sends = latestServiceInCatalog.sends || ([] as any);\n // Found a service, and versions do not match, we need to version the one already there\n if (latestServiceInCatalog.version !== version) {\n await versionService(serviceId);\n console.log(chalk.cyan(` - Versioned previous service (v${latestServiceInCatalog.version})`));\n }\n\n // Match found, override it\n if (latestServiceInCatalog.version === version) {\n await rmService(document.info.title);\n }\n }\n\n await writeService(\n {\n id: serviceId,\n name: document.info.title,\n version: version,\n summary: getServiceSummary(document),\n badges: documentTags.map((tag) => ({ content: tag.name, textColor: 'blue', backgroundColor: 'blue' })),\n markdown: serviceMarkdown,\n sends,\n schemaPath: path.split('/').pop() || 'openapi.yml',\n receives,\n },\n { path: document.info.title }\n );\n\n await addFileToService(\n serviceId,\n {\n fileName: path.split('/').pop() || 'openapi.yml',\n content: openAPIFile,\n },\n version\n );\n\n console.log(chalk.cyan(` - Service (v${version}) created`));\n\n console.log(chalk.green(`\\nFinished generating event catalog for AsyncAPI ${document.info.title} (v${version})`));\n }\n\n await checkLicense();\n};\n","export const defaultMarkdown = () => {\n return `\n\n## Architecture diagram\n<NodeGraph />\n\n`;\n};\n","import { OpenAPI } from 'openapi-types';\n\nexport const defaultMarkdown = (document: OpenAPI.Document) => {\n return `\n\n${document.info.description ? `${document.info.description}` : ''} \n\n## Architecture diagram\n<NodeGraph />\n\n${\n document.externalDocs\n ? `\n## External documentation\n- [${document.externalDocs.description}](${document.externalDocs.url})\n`\n : ''\n}\n`;\n};\n\nexport const getSummary = (document: OpenAPI.Document) => {\n const summary = document.info.description ? document.info.description : '';\n return summary && summary.length < 150 ? summary : '';\n};\n","import { MessageInterface, AsyncAPIDocumentInterface } from '@asyncapi/parser';\nimport { OpenAPI } from 'openapi-types';\nimport { Operation } from '..';\n// import { getFileExtentionFromSchemaFormat } from './schemas';\n\nexport const defaultMarkdown = (message: Operation) => {\n return `\n## Architecture\n<NodeGraph />\n\n${\n message.externalDocs\n ? `\n## External documentation\n- [${message.externalDocs.description}](${message.externalDocs.url})\n`\n : ''\n}\n\n`;\n};\n\nexport const getSummary = (message: Operation) => {\n const messageSummary = message.summary ? message.summary : '';\n const messageDescription = message.description ? message.description : '';\n\n let eventCatalogMessageSummary = messageSummary;\n\n if (!eventCatalogMessageSummary) {\n eventCatalogMessageSummary = messageDescription && messageDescription.length < 150 ? messageDescription : '';\n }\n\n return eventCatalogMessageSummary;\n};\n\n// export const messageHasSchema = (message: Operation) => {\n// return message.hasPayload() && message.schemaFormat();\n// };\n\n// export const getSchemaFileName = (message: Operation) => {\n// const extension = getFileExtentionFromSchemaFormat(message.schemaFormat());\n// return `schema.${extension}`;\n// };\n\nexport const getMessageName = (message: Operation) => {\n return message.operationId;\n};\n","import chalk from 'chalk';\n\nexport default () => {\n console.log(chalk.bgBlue(`\\nYou are using the open source license for this plugin`));\n console.log(\n chalk.blueBright(\n `This plugin is governed and published under a dual-license. \\nIf using for internal, commercial or proprietary software, please contact hello@eventcatalog.dev for a license to support the project.`\n )\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAkB;AAElB,sBAAyB;AACzB,IAAAA,gBAAkB;AAClB,4BAA0B;AAC1B,qBAAoB;;;ACRb,IAAM,kBAAkB,MAAM;AACnC,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAMT;;;ACLO,IAAMC,mBAAkB,CAAC,aAA+B;AAC7D,SAAO;AAAA;AAAA,EAEP,SAAS,KAAK,cAAc,GAAG,SAAS,KAAK,WAAW,KAAK,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA,EAM/D,SAAS,eACL;AAAA;AAAA,KAED,SAAS,aAAa,WAAW,KAAK,SAAS,aAAa,GAAG;AAAA,IAE9D,EACN;AAAA;AAEA;AAEO,IAAM,aAAa,CAAC,aAA+B;AACxD,QAAM,UAAU,SAAS,KAAK,cAAc,SAAS,KAAK,cAAc;AACxE,SAAO,WAAW,QAAQ,SAAS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,SAAS,KAAK,KAAK;AAAA,MACrC;AAAA,IACF;AAEA,UAAM;AAAA,MACJ;AAAA,QACE,IAAI;AAAA,QACJ,MAAM,SAAS,KAAK;AAAA,QACpB;AAAA,QACA,SAAS,WAAkB,QAAQ;AAAA,QACnC,QAAQ,aAAa,IAAI,CAAC,SAAS,EAAE,SAAS,IAAI,MAAM,WAAW,QAAQ,iBAAiB,OAAO,EAAE;AAAA,QACrG,UAAU;AAAA,QACV;AAAA,QACA,YAAY,KAAK,MAAM,GAAG,EAAE,IAAI,KAAK;AAAA,QACrC;AAAA,MACF;AAAA,MACA,EAAE,MAAM,SAAS,KAAK,MAAM;AAAA,IAC9B;AAEA,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,QACE,UAAU,KAAK,MAAM,GAAG,EAAE,IAAI,KAAK;AAAA,QACnC,SAAS;AAAA,MACX;AAAA,MACA;AAAA,IACF;AAEA,YAAQ,IAAI,cAAAA,QAAM,KAAK,gBAAgB,OAAO,WAAW,CAAC;AAE1D,YAAQ,IAAI,cAAAA,QAAM,MAAM;AAAA,iDAAoD,SAAS,KAAK,KAAK,MAAM,OAAO,GAAG,CAAC;AAAA,EAClH;AAEA,QAAM,qBAAa;AACrB;","names":["import_chalk","defaultMarkdown","defaultMarkdown","getSummary","chalk","SwaggerParser","utils","chalk","slugify","defaultMarkdown","getSummary"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/utils/schemas.ts","../src/utils/messages.ts","../src/utils/services.ts","../src/utils/domains.ts","../src/checkLicense.ts"],"sourcesContent":["// import utils from '@eventcatalog/sdk';\nimport { Parser } from '@asyncapi/parser';\nconst parser = new Parser();\nimport { readFile } from 'node:fs/promises';\nimport utils from '@eventcatalog/sdk';\nimport slugify from 'slugify';\nimport {\n defaultMarkdown as generateMarkdownForMessage,\n getMessageName,\n getSummary as getMessageSummary,\n getSchemaFileName,\n messageHasSchema,\n} from './utils/messages';\nimport { defaultMarkdown as generateMarkdownForService, getSummary as getServiceSummary } from './utils/services';\nimport { defaultMarkdown as generateMarkdownForDomain } from './utils/domains';\nimport chalk from 'chalk';\nimport checkLicense from './checkLicense';\nimport argv from 'minimist';\nconst cliArgs = argv(process.argv.slice(2));\n\ntype Domain = {\n id: string;\n name: string;\n version: string;\n};\n\ntype Props = {\n path: string | string[];\n domain?: Domain;\n debug?: boolean;\n};\n\nexport default async (config: any, options: Props) => {\n if (!process.env.PROJECT_DIR) {\n throw new Error('Please provide catalog url (env variable PROJECT_DIR)');\n }\n\n const {\n writeService,\n writeEvent,\n writeCommand,\n getService,\n versionService,\n rmService,\n getDomain,\n writeDomain,\n addServiceToDomain,\n getCommand,\n getEvent,\n rmEventById,\n rmCommandById,\n versionCommand,\n versionEvent,\n addSchemaToCommand,\n addSchemaToEvent,\n addFileToService,\n versionDomain,\n } = utils(process.env.PROJECT_DIR);\n\n const asyncAPIFiles = Array.isArray(options.path) ? options.path : [options.path];\n\n console.log(chalk.green(`Processing ${asyncAPIFiles.length} AsyncAPI files...`));\n\n for (const path of asyncAPIFiles) {\n console.log(chalk.gray(`Processing ${path}`));\n\n const asyncAPIFile = await readFile(path, 'utf-8');\n const { document } = await parser.parse(asyncAPIFile);\n\n if (!document) {\n console.log(chalk.red('Failed to parse AsyncAPI file'));\n if (options.debug || cliArgs.debug) {\n const diagnostics = await parser.validate(asyncAPIFile);\n console.log(diagnostics);\n } else {\n console.log(chalk.red('Run with debug option in the generator to see diagnostics'));\n }\n continue;\n }\n\n const operations = document.allOperations();\n const documentTags = document.info().tags().all() || [];\n\n const serviceId = slugify(document.info().title(), { lower: true, strict: true });\n const version = document.info().version();\n\n // What messages does this service send and receive\n const sends = [];\n const receives = [];\n let specifications = {};\n\n let serviceMarkdown = generateMarkdownForService(document);\n\n // Manage domain\n if (options.domain) {\n // Try and get the domain\n const { id: domainId, name: domainName, version: domainVersion } = options.domain;\n const domain = await getDomain(options.domain.id, domainVersion || 'latest');\n const currentDomain = await getDomain(options.domain.id, 'latest');\n\n console.log(chalk.blue(`\\nProcessing domain: ${domainName} (v${domainVersion})`));\n\n // Found a domain, but the versions do not match\n if (currentDomain && currentDomain.version !== domainVersion) {\n await versionDomain(domainId);\n console.log(chalk.cyan(` - Versioned previous domain (v${currentDomain.version})`));\n }\n\n // Do we need to create a new domain?\n if (!domain || (domain && domain.version !== domainVersion)) {\n await writeDomain({\n id: domainId,\n name: domainName,\n version: domainVersion,\n markdown: generateMarkdownForDomain(document),\n // services: [{ id: serviceId, version: version }],\n });\n console.log(chalk.cyan(` - Domain (v${domainVersion}) created`));\n }\n\n if (currentDomain && currentDomain.version === domainVersion) {\n console.log(chalk.yellow(` - Domain (v${domainVersion}) already exists, skipped creation...`));\n }\n\n // Add the service to the domain\n await addServiceToDomain(domainId, { id: serviceId, version: version }, domainVersion);\n }\n\n // Find events/commands\n for (const operation of operations) {\n for (const message of operation.messages()) {\n const eventType = message.extensions().get('x-eventcatalog-message-type')?.value() || 'event';\n\n const messageId = message.id().toLowerCase();\n\n let messageMarkdown = generateMarkdownForMessage(document, message);\n const writeMessage = eventType === 'event' ? writeEvent : writeCommand;\n const versionMessage = eventType === 'event' ? versionEvent : versionCommand;\n const getMessage = eventType === 'event' ? getEvent : getCommand;\n const rmMessageById = eventType === 'event' ? rmEventById : rmCommandById;\n const addSchemaToMessage = eventType === 'event' ? addSchemaToEvent : addSchemaToCommand;\n const badges = message.tags().all() || [];\n\n // Check if the message already exists in the catalog\n const catalogedMessage = await getMessage(message.id().toLowerCase(), 'latest');\n\n console.log(chalk.blue(`Processing message: ${getMessageName(message)} (v${version})`));\n\n if (catalogedMessage) {\n messageMarkdown = catalogedMessage.markdown;\n // if the version matches, we can override the message but keep markdown as it was\n if (catalogedMessage.version === version) {\n await rmMessageById(messageId, version);\n } else {\n // if the version does not match, we need to version the message\n await versionMessage(messageId);\n console.log(chalk.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));\n }\n }\n\n // Write the message to the catalog\n await writeMessage(\n {\n id: messageId,\n version: version,\n name: getMessageName(message),\n summary: getMessageSummary(message),\n markdown: messageMarkdown,\n badges: badges.map((badge) => ({ content: badge.name(), textColor: 'blue', backgroundColor: 'blue' })),\n schemaPath: messageHasSchema(message) ? getSchemaFileName(message) : undefined,\n },\n {\n path: message.id(),\n }\n );\n\n console.log(chalk.cyan(` - Message (v${version}) created`));\n\n // Check if the message has a payload, if it does then document in EventCatalog\n if (messageHasSchema(message)) {\n addSchemaToMessage(\n messageId,\n {\n fileName: getSchemaFileName(message),\n schema: JSON.stringify(message.payload()?.json(), null, 4),\n },\n version\n );\n console.log(chalk.cyan(` - Schema added to message (v${version})`));\n }\n\n // Add the message to the correct array\n if (operation.action() === 'send' || operation.action() === 'publish') {\n sends.push({ id: messageId, version: version });\n }\n if (operation.action() === 'receive' || operation.action() === 'subscribe') {\n receives.push({ id: messageId, version: version });\n }\n }\n }\n\n // Check if service is already defined... if the versions do not match then create service.\n const latestServiceInCatalog = await getService(serviceId, 'latest');\n\n console.log(chalk.blue(`Processing service: ${document.info().title()} (v${version})`));\n\n if (latestServiceInCatalog) {\n serviceMarkdown = latestServiceInCatalog.markdown;\n // Found a service, and versions do not match, we need to version the one already there\n if (latestServiceInCatalog.version !== version) {\n await versionService(serviceId);\n console.log(chalk.cyan(` - Versioned previous service (v${latestServiceInCatalog.version})`));\n }\n\n // Match found, override it\n if (latestServiceInCatalog.version === version) {\n serviceMarkdown = latestServiceInCatalog.markdown;\n specifications = latestServiceInCatalog.specifications ?? {};\n await rmService(document.info().title());\n }\n }\n\n await writeService(\n {\n id: serviceId,\n name: document.info().title(),\n version: version,\n summary: getServiceSummary(document),\n badges: documentTags.map((tag) => ({ content: tag.name(), textColor: 'blue', backgroundColor: 'blue' })),\n markdown: serviceMarkdown,\n sends,\n receives,\n schemaPath: path.split('/').pop() || 'asyncapi.yml',\n specifications: {\n ...specifications,\n asyncapiPath: path.split('/').pop() || 'asyncapi.yml',\n },\n },\n { path: document.info().title() }\n );\n\n await addFileToService(\n serviceId,\n {\n fileName: path.split('/').pop() || 'asyncapi.yml',\n content: asyncAPIFile,\n },\n version\n );\n\n console.log(chalk.cyan(` - Service (v${version}) created`));\n\n console.log(chalk.green(`\\nFinished generating event catalog for AsyncAPI ${document.info().title()} (v${version})`));\n }\n\n await checkLicense();\n};\n","export const getFileExtentionFromSchemaFormat = (format: string | undefined = '') => {\n if (format.includes('avro')) return 'avsc';\n if (format.includes('yml')) return 'yml';\n if (format.includes('json')) return 'json';\n if (format.includes('openapi')) return 'openapi';\n if (format.includes('protobuf')) return 'protobuf';\n if (format.includes('yaml')) return 'yaml';\n\n return 'json';\n};\n","import { MessageInterface, AsyncAPIDocumentInterface } from '@asyncapi/parser';\nimport { getFileExtentionFromSchemaFormat } from './schemas';\n\nexport const defaultMarkdown = (document: AsyncAPIDocumentInterface, message: MessageInterface) => {\n return `\n## Architecture\n<NodeGraph />\n\n${\n messageHasSchema(message)\n ? `\n## Schema\n<SchemaViewer file=\"${getSchemaFileName(message)}\" title=\"Message Schema\" maxHeight=\"500\" />\n`\n : ''\n}\n\n${\n message.externalDocs()\n ? `\n## External documentation\n- [${message.externalDocs()?.description()}](${message.externalDocs()?.url()})\n`\n : ''\n}\n\n`;\n};\n\nexport const getSummary = (message: MessageInterface) => {\n const messageSummary = message.hasSummary() ? message.summary() : '';\n const messageDescription = message.hasDescription() ? message.description() : '';\n\n let eventCatalogMessageSummary = messageSummary;\n\n if (!eventCatalogMessageSummary) {\n eventCatalogMessageSummary = messageDescription && messageDescription.length < 150 ? messageDescription : '';\n }\n\n return eventCatalogMessageSummary;\n};\n\nexport const messageHasSchema = (message: MessageInterface) => {\n return message.hasPayload() && message.schemaFormat();\n};\n\nexport const getSchemaFileName = (message: MessageInterface) => {\n const extension = getFileExtentionFromSchemaFormat(message.schemaFormat());\n return `schema.${extension}`;\n};\n\nexport const getMessageName = (message: MessageInterface) => {\n return message.hasTitle() && message.title() ? (message.title() as string) : message.id();\n};\n","import { AsyncAPIDocumentInterface } from '@asyncapi/parser';\n\nexport const defaultMarkdown = (document: AsyncAPIDocumentInterface) => {\n return `\n\n${document.info().hasDescription() ? `${document.info().description()}` : ''} \n\n## Architecture diagram\n<NodeGraph />\n\n${\n document.info().externalDocs()\n ? `\n## External documentation\n- [${document.info().externalDocs()?.description()}](${document.info().externalDocs()?.url()})\n`\n : ''\n}\n`;\n};\n\nexport const getSummary = (document: AsyncAPIDocumentInterface) => {\n const summary = document.info().hasDescription() ? document.info().description() : '';\n return summary && summary.length < 150 ? summary : '';\n};\n","import { AsyncAPIDocumentInterface } from '@asyncapi/parser';\n\nexport const defaultMarkdown = (document: AsyncAPIDocumentInterface) => {\n return `\n\n## Architecture diagram\n<NodeGraph />\n\n`;\n};\n","import chalk from 'chalk';\n\nexport default () => {\n console.log(chalk.bgBlue(`\\nYou are using the open source license for this plugin`));\n console.log(\n chalk.blueBright(\n `This plugin is governed and published under a dual-license. \\nIf using for internal, commercial or proprietary software, please contact hello@eventcatalog.dev for a license to support the project.`\n )\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAuB;AAEvB,sBAAyB;AACzB,iBAAkB;AAClB,qBAAoB;;;ACLb,IAAM,mCAAmC,CAAC,SAA6B,OAAO;AACnF,MAAI,OAAO,SAAS,MAAM,EAAG,QAAO;AACpC,MAAI,OAAO,SAAS,KAAK,EAAG,QAAO;AACnC,MAAI,OAAO,SAAS,MAAM,EAAG,QAAO;AACpC,MAAI,OAAO,SAAS,SAAS,EAAG,QAAO;AACvC,MAAI,OAAO,SAAS,UAAU,EAAG,QAAO;AACxC,MAAI,OAAO,SAAS,MAAM,EAAG,QAAO;AAEpC,SAAO;AACT;;;ACNO,IAAM,kBAAkB,CAAC,UAAqC,YAA8B;AACjG,SAAO;AAAA;AAAA;AAAA;AAAA,EAKP,iBAAiB,OAAO,IACpB;AAAA;AAAA,sBAEgB,kBAAkB,OAAO,CAAC;AAAA,IAE1C,EACN;AAAA;AAAA,EAGE,QAAQ,a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A,UAAI,uBAAuB,YAAY,SAAS;AAC9C,0BAAkB,uBAAuB;AACzC,yBAAiB,uBAAuB,kBAAkB,CAAC;AAC3D,cAAM,UAAU,SAAS,KAAK,EAAE,MAAM,CAAC;AAAA,MACzC;AAAA,IACF;AAEA,UAAM;AAAA,MACJ;AAAA,QACE,IAAI;AAAA,QACJ,MAAM,SAAS,KAAK,EAAE,MAAM;AAAA,QAC5B;AAAA,QACA,SAASG,YAAkB,QAAQ;AAAA,QACnC,QAAQ,aAAa,IAAI,CAAC,SAAS,EAAE,SAAS,IAAI,KAAK,GAAG,WAAW,QAAQ,iBAAiB,OAAO,EAAE;AAAA,QACvG,UAAU;AAAA,QACV;AAAA,QACA;AAAA,QACA,YAAY,KAAK,MAAM,GAAG,EAAE,IAAI,KAAK;AAAA,QACrC,gBAAgB;AAAA,UACd,GAAG;AAAA,UACH,cAAc,KAAK,MAAM,GAAG,EAAE,IAAI,KAAK;AAAA,QACzC;AAAA,MACF;AAAA,MACA,EAAE,MAAM,SAAS,KAAK,EAAE,MAAM,EAAE;AAAA,IAClC;AAEA,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,QACE,UAAU,KAAK,MAAM,GAAG,EAAE,IAAI,KAAK;AAAA,QACnC,SAAS;AAAA,MACX;AAAA,MACA;AAAA,IACF;AAEA,YAAQ,IAAI,cAAAH,QAAM,KAAK,gBAAgB,OAAO,WAAW,CAAC;AAE1D,YAAQ,IAAI,cAAAA,QAAM,MAAM;AAAA,iDAAoD,SAAS,KAAK,EAAE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC;AAAA,EACtH;AAEA,QAAM,qBAAa;AACrB;","names":["defaultMarkdown","getSummary","defaultMarkdown","import_chalk","chalk","argv","utils","chalk","slugify","defaultMarkdown","getSummary"]}
package/dist/index.mjs CHANGED
@@ -1,65 +1,90 @@
1
1
  // src/index.ts
2
- import utils from "@eventcatalog/sdk";
2
+ import { Parser } from "@asyncapi/parser";
3
3
  import { readFile } from "node:fs/promises";
4
- import chalk2 from "chalk";
5
- import SwaggerParser from "@apidevtools/swagger-parser";
4
+ import utils from "@eventcatalog/sdk";
6
5
  import slugify from "slugify";
7
6
 
8
- // src/utils/domains.ts
9
- var defaultMarkdown = () => {
10
- return `
7
+ // src/utils/schemas.ts
8
+ var getFileExtentionFromSchemaFormat = (format = "") => {
9
+ if (format.includes("avro")) return "avsc";
10
+ if (format.includes("yml")) return "yml";
11
+ if (format.includes("json")) return "json";
12
+ if (format.includes("openapi")) return "openapi";
13
+ if (format.includes("protobuf")) return "protobuf";
14
+ if (format.includes("yaml")) return "yaml";
15
+ return "json";
16
+ };
11
17
 
12
- ## Architecture diagram
18
+ // src/utils/messages.ts
19
+ var defaultMarkdown = (document, message) => {
20
+ return `
21
+ ## Architecture
13
22
  <NodeGraph />
14
23
 
24
+ ${messageHasSchema(message) ? `
25
+ ## Schema
26
+ <SchemaViewer file="${getSchemaFileName(message)}" title="Message Schema" maxHeight="500" />
27
+ ` : ""}
28
+
29
+ ${message.externalDocs() ? `
30
+ ## External documentation
31
+ - [${message.externalDocs()?.description()}](${message.externalDocs()?.url()})
32
+ ` : ""}
33
+
15
34
  `;
16
35
  };
36
+ var getSummary = (message) => {
37
+ const messageSummary = message.hasSummary() ? message.summary() : "";
38
+ const messageDescription = message.hasDescription() ? message.description() : "";
39
+ let eventCatalogMessageSummary = messageSummary;
40
+ if (!eventCatalogMessageSummary) {
41
+ eventCatalogMessageSummary = messageDescription && messageDescription.length < 150 ? messageDescription : "";
42
+ }
43
+ return eventCatalogMessageSummary;
44
+ };
45
+ var messageHasSchema = (message) => {
46
+ return message.hasPayload() && message.schemaFormat();
47
+ };
48
+ var getSchemaFileName = (message) => {
49
+ const extension = getFileExtentionFromSchemaFormat(message.schemaFormat());
50
+ return `schema.${extension}`;
51
+ };
52
+ var getMessageName = (message) => {
53
+ return message.hasTitle() && message.title() ? message.title() : message.id();
54
+ };
17
55
 
18
56
  // src/utils/services.ts
19
57
  var defaultMarkdown2 = (document) => {
20
58
  return `
21
59
 
22
- ${document.info.description ? `${document.info.description}` : ""}
60
+ ${document.info().hasDescription() ? `${document.info().description()}` : ""}
23
61
 
24
62
  ## Architecture diagram
25
63
  <NodeGraph />
26
64
 
27
- ${document.externalDocs ? `
65
+ ${document.info().externalDocs() ? `
28
66
  ## External documentation
29
- - [${document.externalDocs.description}](${document.externalDocs.url})
67
+ - [${document.info().externalDocs()?.description()}](${document.info().externalDocs()?.url()})
30
68
  ` : ""}
31
69
  `;
32
70
  };
33
- var getSummary = (document) => {
34
- const summary = document.info.description ? document.info.description : "";
71
+ var getSummary2 = (document) => {
72
+ const summary = document.info().hasDescription() ? document.info().description() : "";
35
73
  return summary && summary.length < 150 ? summary : "";
36
74
  };
37
75
 
38
- // src/utils/messages.ts
39
- var defaultMarkdown3 = (message) => {
76
+ // src/utils/domains.ts
77
+ var defaultMarkdown3 = (document) => {
40
78
  return `
41
- ## Architecture
42
- <NodeGraph />
43
79
 
44
- ${message.externalDocs ? `
45
- ## External documentation
46
- - [${message.externalDocs.description}](${message.externalDocs.url})
47
- ` : ""}
80
+ ## Architecture diagram
81
+ <NodeGraph />
48
82
 
49
83
  `;
50
84
  };
51
- var getSummary2 = (message) => {
52
- const messageSummary = message.summary ? message.summary : "";
53
- const messageDescription = message.description ? message.description : "";
54
- let eventCatalogMessageSummary = messageSummary;
55
- if (!eventCatalogMessageSummary) {
56
- eventCatalogMessageSummary = messageDescription && messageDescription.length < 150 ? messageDescription : "";
57
- }
58
- return eventCatalogMessageSummary;
59
- };
60
- var getMessageName = (message) => {
61
- return message.operationId;
62
- };
85
+
86
+ // src/index.ts
87
+ import chalk2 from "chalk";
63
88
 
64
89
  // src/checkLicense.ts
65
90
  import chalk from "chalk";
@@ -75,72 +100,57 @@ If using for internal, commercial or proprietary software, please contact hello@
75
100
  };
76
101
 
77
102
  // src/index.ts
78
- var DEFAULT_MESSAGE_TYPE = "query";
79
- async function getOperationsByType(openApiPath) {
80
- try {
81
- const api = await SwaggerParser.validate(openApiPath);
82
- const operations = [];
83
- for (const path in api.paths) {
84
- const pathItem = api.paths[path];
85
- for (const method in pathItem) {
86
- const openAPIOperation = pathItem[method];
87
- const messageType = openAPIOperation["x-eventcatalog-message-type"] || DEFAULT_MESSAGE_TYPE;
88
- const operation = {
89
- path,
90
- method: method.toUpperCase(),
91
- operationId: openAPIOperation.operationId,
92
- externalDocs: openAPIOperation.externalDocs,
93
- type: messageType,
94
- description: openAPIOperation.description,
95
- summary: openAPIOperation.summary,
96
- tags: openAPIOperation.tags || []
97
- };
98
- operations.push(operation);
99
- }
100
- }
101
- return operations;
102
- } catch (err) {
103
- console.error("Error parsing OpenAPI document:", err);
104
- return [];
105
- }
106
- }
103
+ import argv from "minimist";
104
+ var parser = new Parser();
105
+ var cliArgs = argv(process.argv.slice(2));
107
106
  var src_default = async (config, options) => {
108
107
  if (!process.env.PROJECT_DIR) {
109
108
  throw new Error("Please provide catalog url (env variable PROJECT_DIR)");
110
109
  }
111
110
  const {
111
+ writeService,
112
112
  writeEvent,
113
- getDomain,
114
- versionDomain,
115
- writeDomain,
116
- addServiceToDomain,
113
+ writeCommand,
117
114
  getService,
118
115
  versionService,
119
116
  rmService,
120
- writeService,
121
- addFileToService,
122
- versionCommand,
123
- getEvent,
117
+ getDomain,
118
+ writeDomain,
119
+ addServiceToDomain,
124
120
  getCommand,
125
- rmCommandById,
121
+ getEvent,
126
122
  rmEventById,
127
- writeCommand
123
+ rmCommandById,
124
+ versionCommand,
125
+ versionEvent,
126
+ addSchemaToCommand,
127
+ addSchemaToEvent,
128
+ addFileToService,
129
+ versionDomain
128
130
  } = utils(process.env.PROJECT_DIR);
129
- const openAPIFiles = Array.isArray(options.path) ? options.path : [options.path];
130
- for (const path of openAPIFiles) {
131
- console.log(chalk2.green(`Processing ${path}`));
132
- try {
133
- await SwaggerParser.validate(path);
134
- } catch (error) {
135
- console.error(chalk2.red(`Failed to parse OpenAPI file: ${path}`));
136
- console.error(chalk2.red(error));
131
+ const asyncAPIFiles = Array.isArray(options.path) ? options.path : [options.path];
132
+ console.log(chalk2.green(`Processing ${asyncAPIFiles.length} AsyncAPI files...`));
133
+ for (const path of asyncAPIFiles) {
134
+ console.log(chalk2.gray(`Processing ${path}`));
135
+ const asyncAPIFile = await readFile(path, "utf-8");
136
+ const { document } = await parser.parse(asyncAPIFile);
137
+ if (!document) {
138
+ console.log(chalk2.red("Failed to parse AsyncAPI file"));
139
+ if (options.debug || cliArgs.debug) {
140
+ const diagnostics = await parser.validate(asyncAPIFile);
141
+ console.log(diagnostics);
142
+ } else {
143
+ console.log(chalk2.red("Run with debug option in the generator to see diagnostics"));
144
+ }
137
145
  continue;
138
146
  }
139
- const openAPIFile = await readFile(path, "utf-8");
140
- const document = await SwaggerParser.parse(path);
141
- const operations = await getOperationsByType(path);
142
- const serviceId = slugify(document.info.title, { lower: true, strict: true });
143
- const version = document.info.version;
147
+ const operations = document.allOperations();
148
+ const documentTags = document.info().tags().all() || [];
149
+ const serviceId = slugify(document.info().title(), { lower: true, strict: true });
150
+ const version = document.info().version();
151
+ const sends = [];
152
+ const receives = [];
153
+ let specifications = {};
144
154
  let serviceMarkdown = defaultMarkdown2(document);
145
155
  if (options.domain) {
146
156
  const { id: domainId, name: domainName, version: domainVersion } = options.domain;
@@ -157,7 +167,8 @@ Processing domain: ${domainName} (v${domainVersion})`));
157
167
  id: domainId,
158
168
  name: domainName,
159
169
  version: domainVersion,
160
- markdown: defaultMarkdown()
170
+ markdown: defaultMarkdown3(document)
171
+ // services: [{ id: serviceId, version: version }],
161
172
  });
162
173
  console.log(chalk2.cyan(` - Domain (v${domainVersion}) created`));
163
174
  }
@@ -166,85 +177,105 @@ Processing domain: ${domainName} (v${domainVersion})`));
166
177
  }
167
178
  await addServiceToDomain(domainId, { id: serviceId, version }, domainVersion);
168
179
  }
169
- const documentTags = document.tags || [];
170
- let sends = [];
171
- const receives = [];
172
180
  for (const operation of operations) {
173
- const messageType = operation.type;
174
- const messageId = getMessageName(operation);
175
- let messageMarkdown = defaultMarkdown3(operation);
176
- const versionMessage = versionCommand;
177
- const getMessage = messageType === "event" ? getEvent : getCommand;
178
- const rmMessageById = messageType === "event" ? rmEventById : rmCommandById;
179
- const writeMessage = messageType === "event" ? writeEvent : writeCommand;
180
- const catalogedMessage = await getMessage(messageId, "latest");
181
- console.log(chalk2.blue(`Processing message: ${getMessageName(operation)} (v${version})`));
182
- if (catalogedMessage) {
183
- messageMarkdown = catalogedMessage.markdown;
184
- if (catalogedMessage.version === version) {
185
- await rmMessageById(messageId, version);
186
- } else {
187
- await versionMessage(messageId);
188
- console.log(chalk2.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));
181
+ for (const message of operation.messages()) {
182
+ const eventType = message.extensions().get("x-eventcatalog-message-type")?.value() || "event";
183
+ const messageId = message.id().toLowerCase();
184
+ let messageMarkdown = defaultMarkdown(document, message);
185
+ const writeMessage = eventType === "event" ? writeEvent : writeCommand;
186
+ const versionMessage = eventType === "event" ? versionEvent : versionCommand;
187
+ const getMessage = eventType === "event" ? getEvent : getCommand;
188
+ const rmMessageById = eventType === "event" ? rmEventById : rmCommandById;
189
+ const addSchemaToMessage = eventType === "event" ? addSchemaToEvent : addSchemaToCommand;
190
+ const badges = message.tags().all() || [];
191
+ const catalogedMessage = await getMessage(message.id().toLowerCase(), "latest");
192
+ console.log(chalk2.blue(`Processing message: ${getMessageName(message)} (v${version})`));
193
+ if (catalogedMessage) {
194
+ messageMarkdown = catalogedMessage.markdown;
195
+ if (catalogedMessage.version === version) {
196
+ await rmMessageById(messageId, version);
197
+ } else {
198
+ await versionMessage(messageId);
199
+ console.log(chalk2.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));
200
+ }
189
201
  }
190
- }
191
- await writeMessage(
192
- {
193
- id: messageId,
194
- version,
195
- name: getMessageName(operation),
196
- summary: getSummary2(operation),
197
- markdown: messageMarkdown,
198
- badges: operation.tags.map((badge) => ({ content: badge, textColor: "blue", backgroundColor: "blue" }))
199
- },
200
- {
201
- path: messageId
202
+ await writeMessage(
203
+ {
204
+ id: messageId,
205
+ version,
206
+ name: getMessageName(message),
207
+ summary: getSummary(message),
208
+ markdown: messageMarkdown,
209
+ badges: badges.map((badge) => ({ content: badge.name(), textColor: "blue", backgroundColor: "blue" })),
210
+ schemaPath: messageHasSchema(message) ? getSchemaFileName(message) : void 0
211
+ },
212
+ {
213
+ path: message.id()
214
+ }
215
+ );
216
+ console.log(chalk2.cyan(` - Message (v${version}) created`));
217
+ if (messageHasSchema(message)) {
218
+ addSchemaToMessage(
219
+ messageId,
220
+ {
221
+ fileName: getSchemaFileName(message),
222
+ schema: JSON.stringify(message.payload()?.json(), null, 4)
223
+ },
224
+ version
225
+ );
226
+ console.log(chalk2.cyan(` - Schema added to message (v${version})`));
202
227
  }
203
- );
204
- receives.push({
205
- id: operation.operationId,
206
- version
207
- });
208
- console.log(chalk2.cyan(` - Message (v${version}) created`));
228
+ if (operation.action() === "send" || operation.action() === "publish") {
229
+ sends.push({ id: messageId, version });
230
+ }
231
+ if (operation.action() === "receive" || operation.action() === "subscribe") {
232
+ receives.push({ id: messageId, version });
233
+ }
234
+ }
209
235
  }
210
236
  const latestServiceInCatalog = await getService(serviceId, "latest");
211
- console.log(chalk2.blue(`Processing service: ${document.info.title} (v${version})`));
237
+ console.log(chalk2.blue(`Processing service: ${document.info().title()} (v${version})`));
212
238
  if (latestServiceInCatalog) {
213
239
  serviceMarkdown = latestServiceInCatalog.markdown;
214
- sends = latestServiceInCatalog.sends || [];
215
240
  if (latestServiceInCatalog.version !== version) {
216
241
  await versionService(serviceId);
217
242
  console.log(chalk2.cyan(` - Versioned previous service (v${latestServiceInCatalog.version})`));
218
243
  }
219
244
  if (latestServiceInCatalog.version === version) {
220
- await rmService(document.info.title);
245
+ serviceMarkdown = latestServiceInCatalog.markdown;
246
+ specifications = latestServiceInCatalog.specifications ?? {};
247
+ await rmService(document.info().title());
221
248
  }
222
249
  }
223
250
  await writeService(
224
251
  {
225
252
  id: serviceId,
226
- name: document.info.title,
253
+ name: document.info().title(),
227
254
  version,
228
- summary: getSummary(document),
229
- badges: documentTags.map((tag) => ({ content: tag.name, textColor: "blue", backgroundColor: "blue" })),
255
+ summary: getSummary2(document),
256
+ badges: documentTags.map((tag) => ({ content: tag.name(), textColor: "blue", backgroundColor: "blue" })),
230
257
  markdown: serviceMarkdown,
231
258
  sends,
232
- schemaPath: path.split("/").pop() || "openapi.yml",
233
- receives
259
+ receives,
260
+ schemaPath: path.split("/").pop() || "asyncapi.yml",
261
+ specifications: {
262
+ ...specifications,
263
+ asyncapiPath: path.split("/").pop() || "asyncapi.yml"
264
+ }
234
265
  },
235
- { path: document.info.title }
266
+ { path: document.info().title() }
236
267
  );
237
268
  await addFileToService(
238
269
  serviceId,
239
270
  {
240
- fileName: path.split("/").pop() || "openapi.yml",
241
- content: openAPIFile
271
+ fileName: path.split("/").pop() || "asyncapi.yml",
272
+ content: asyncAPIFile
242
273
  },
243
274
  version
244
275
  );
245
276
  console.log(chalk2.cyan(` - Service (v${version}) created`));
246
277
  console.log(chalk2.green(`
247
- Finished generating event catalog for AsyncAPI ${document.info.title} (v${version})`));
278
+ Finished generating event catalog for AsyncAPI ${document.info().title()} (v${version})`));
248
279
  }
249
280
  await checkLicense_default();
250
281
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/utils/domains.ts","../src/utils/services.ts","../src/utils/messages.ts","../src/checkLicense.ts"],"sourcesContent":["// import utils from '@eventcatalog/sdk';\n// import { Parser } from '@asyncapi/parser';\n// const parser = new Parser();\nimport utils from '@eventcatalog/sdk';\n// import slugify from 'slugify';\nimport { readFile } from 'node:fs/promises';\nimport chalk from 'chalk';\nimport SwaggerParser from '@apidevtools/swagger-parser';\nimport slugify from 'slugify';\nimport { defaultMarkdown as generateMarkdownForDomain } from './utils/domains';\nimport { defaultMarkdown as generateMarkdownForService, getSummary as getServiceSummary } from './utils/services';\nimport { defaultMarkdown as generateMarkdownForMessage, getSummary as getMessageSummary } from './utils/messages';\n\nimport { OpenAPIV3_1 } from 'openapi-types';\nimport { getMessageName } from './utils/messages';\nimport checkLicense from './checkLicense';\n\ntype Props = {\n path: string | string[];\n domain?: Domain;\n debug?: boolean;\n};\n\ntype Domain = {\n id: string;\n name: string;\n version: string;\n};\n\nconst DEFAULT_MESSAGE_TYPE = 'query';\n\nexport type Operation = {\n path: string;\n method: string;\n operationId: string;\n summary?: string;\n description?: string;\n type: string;\n externalDocs?: OpenAPIV3_1.ExternalDocumentationObject;\n tags: string[];\n};\n\nasync function getOperationsByType(openApiPath: string) {\n try {\n // Parse the OpenAPI document\n const api = await SwaggerParser.validate(openApiPath);\n\n const operations = [];\n\n // Iterate through paths\n for (const path in api.paths) {\n const pathItem = api.paths[path];\n\n // Iterate through each HTTP method in the path\n for (const method in pathItem) {\n // @ts-ignore\n const openAPIOperation = pathItem[method];\n\n // Check if the x-eventcatalog-message-type field is set\n const messageType = openAPIOperation['x-eventcatalog-message-type'] || DEFAULT_MESSAGE_TYPE;\n\n const operation = {\n path: path,\n method: method.toUpperCase(),\n operationId: openAPIOperation.operationId,\n externalDocs: openAPIOperation.externalDocs,\n type: messageType,\n description: openAPIOperation.description,\n summary: openAPIOperation.summary,\n tags: openAPIOperation.tags || [],\n } as Operation;\n\n operations.push(operation);\n }\n }\n\n return operations;\n } catch (err) {\n console.error('Error parsing OpenAPI document:', err);\n return [];\n }\n}\n\nexport default async (config: any, options: Props) => {\n if (!process.env.PROJECT_DIR) {\n throw new Error('Please provide catalog url (env variable PROJECT_DIR)');\n }\n\n const {\n writeEvent,\n getDomain,\n versionDomain,\n writeDomain,\n addServiceToDomain,\n getService,\n versionService,\n rmService,\n writeService,\n addFileToService,\n versionCommand,\n getEvent,\n getCommand,\n rmCommandById,\n rmEventById,\n writeCommand,\n } = utils(process.env.PROJECT_DIR);\n\n const openAPIFiles = Array.isArray(options.path) ? options.path : [options.path];\n\n for (const path of openAPIFiles) {\n console.log(chalk.green(`Processing ${path}`));\n\n try {\n await SwaggerParser.validate(path);\n } catch (error) {\n console.error(chalk.red(`Failed to parse OpenAPI file: ${path}`));\n console.error(chalk.red(error));\n continue;\n }\n\n const openAPIFile = await readFile(path, 'utf-8');\n const document = await SwaggerParser.parse(path);\n const operations = await getOperationsByType(path);\n\n const serviceId = slugify(document.info.title, { lower: true, strict: true });\n const version = document.info.version;\n let serviceMarkdown = generateMarkdownForService(document);\n\n // Manage domain\n if (options.domain) {\n // Try and get the domain\n const { id: domainId, name: domainName, version: domainVersion } = options.domain;\n const domain = await getDomain(options.domain.id, domainVersion || 'latest');\n const currentDomain = await getDomain(options.domain.id, 'latest');\n\n console.log(chalk.blue(`\\nProcessing domain: ${domainName} (v${domainVersion})`));\n\n // Found a domain, but the versions do not match\n if (currentDomain && currentDomain.version !== domainVersion) {\n await versionDomain(domainId);\n console.log(chalk.cyan(` - Versioned previous domain (v${currentDomain.version})`));\n }\n\n // Do we need to create a new domain?\n if (!domain || (domain && domain.version !== domainVersion)) {\n await writeDomain({\n id: domainId,\n name: domainName,\n version: domainVersion,\n markdown: generateMarkdownForDomain(),\n });\n console.log(chalk.cyan(` - Domain (v${domainVersion}) created`));\n }\n\n if (currentDomain && currentDomain.version === domainVersion) {\n console.log(chalk.yellow(` - Domain (v${domainVersion}) already exists, skipped creation...`));\n }\n\n // Add the service to the domain\n await addServiceToDomain(domainId, { id: serviceId, version: version }, domainVersion);\n }\n\n // parse\n // const { document } = await parser.parse(asyncAPIFile);\n\n // const operations = document.allOperations();\n const documentTags = document.tags || [];\n\n // // What messages does this service send and receive\n let sends = [];\n const receives = [];\n\n for (const operation of operations) {\n const messageType = operation.type;\n const messageId = getMessageName(operation);\n let messageMarkdown = generateMarkdownForMessage(operation);\n const versionMessage = versionCommand;\n const getMessage = messageType === 'event' ? getEvent : getCommand;\n const rmMessageById = messageType === 'event' ? rmEventById : rmCommandById;\n const writeMessage = messageType === 'event' ? writeEvent : writeCommand;\n // const addSchemaToMessage = messageType === 'event' ? addSchemaToEvent : addSchemaToCommand;\n\n // Check if the message already exists in the catalog\n const catalogedMessage = await getMessage(messageId, 'latest');\n\n console.log(chalk.blue(`Processing message: ${getMessageName(operation)} (v${version})`));\n\n if (catalogedMessage) {\n messageMarkdown = catalogedMessage.markdown;\n // if the version matches, we can override the message but keep markdown as it was\n if (catalogedMessage.version === version) {\n await rmMessageById(messageId, version);\n } else {\n // if the version does not match, we need to version the message\n await versionMessage(messageId);\n console.log(chalk.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));\n }\n }\n\n await writeMessage(\n {\n id: messageId,\n version: version,\n name: getMessageName(operation),\n summary: getMessageSummary(operation),\n markdown: messageMarkdown,\n badges: operation.tags.map((badge) => ({ content: badge, textColor: 'blue', backgroundColor: 'blue' })),\n },\n {\n path: messageId,\n }\n );\n\n // messages will always be messages the service receives\n receives.push({\n id: operation.operationId,\n version: version,\n });\n\n console.log(chalk.cyan(` - Message (v${version}) created`));\n }\n\n // Check if service is already defined... if the versions do not match then create service.\n const latestServiceInCatalog = await getService(serviceId, 'latest');\n console.log(chalk.blue(`Processing service: ${document.info.title} (v${version})`));\n\n if (latestServiceInCatalog) {\n serviceMarkdown = latestServiceInCatalog.markdown;\n sends = latestServiceInCatalog.sends || ([] as any);\n // Found a service, and versions do not match, we need to version the one already there\n if (latestServiceInCatalog.version !== version) {\n await versionService(serviceId);\n console.log(chalk.cyan(` - Versioned previous service (v${latestServiceInCatalog.version})`));\n }\n\n // Match found, override it\n if (latestServiceInCatalog.version === version) {\n await rmService(document.info.title);\n }\n }\n\n await writeService(\n {\n id: serviceId,\n name: document.info.title,\n version: version,\n summary: getServiceSummary(document),\n badges: documentTags.map((tag) => ({ content: tag.name, textColor: 'blue', backgroundColor: 'blue' })),\n markdown: serviceMarkdown,\n sends,\n schemaPath: path.split('/').pop() || 'openapi.yml',\n receives,\n },\n { path: document.info.title }\n );\n\n await addFileToService(\n serviceId,\n {\n fileName: path.split('/').pop() || 'openapi.yml',\n content: openAPIFile,\n },\n version\n );\n\n console.log(chalk.cyan(` - Service (v${version}) created`));\n\n console.log(chalk.green(`\\nFinished generating event catalog for AsyncAPI ${document.info.title} (v${version})`));\n }\n\n await checkLicense();\n};\n","export const defaultMarkdown = () => {\n return `\n\n## Architecture diagram\n<NodeGraph />\n\n`;\n};\n","import { OpenAPI } from 'openapi-types';\n\nexport const defaultMarkdown = (document: OpenAPI.Document) => {\n return `\n\n${document.info.description ? `${document.info.description}` : ''} \n\n## Architecture diagram\n<NodeGraph />\n\n${\n document.externalDocs\n ? `\n## External documentation\n- [${document.externalDocs.description}](${document.externalDocs.url})\n`\n : ''\n}\n`;\n};\n\nexport const getSummary = (document: OpenAPI.Document) => {\n const summary = document.info.description ? document.info.description : '';\n return summary && summary.length < 150 ? summary : '';\n};\n","import { MessageInterface, AsyncAPIDocumentInterface } from '@asyncapi/parser';\nimport { OpenAPI } from 'openapi-types';\nimport { Operation } from '..';\n// import { getFileExtentionFromSchemaFormat } from './schemas';\n\nexport const defaultMarkdown = (message: Operation) => {\n return `\n## Architecture\n<NodeGraph />\n\n${\n message.externalDocs\n ? `\n## External documentation\n- [${message.externalDocs.description}](${message.externalDocs.url})\n`\n : ''\n}\n\n`;\n};\n\nexport const getSummary = (message: Operation) => {\n const messageSummary = message.summary ? message.summary : '';\n const messageDescription = message.description ? message.description : '';\n\n let eventCatalogMessageSummary = messageSummary;\n\n if (!eventCatalogMessageSummary) {\n eventCatalogMessageSummary = messageDescription && messageDescription.length < 150 ? messageDescription : '';\n }\n\n return eventCatalogMessageSummary;\n};\n\n// export const messageHasSchema = (message: Operation) => {\n// return message.hasPayload() && message.schemaFormat();\n// };\n\n// export const getSchemaFileName = (message: Operation) => {\n// const extension = getFileExtentionFromSchemaFormat(message.schemaFormat());\n// return `schema.${extension}`;\n// };\n\nexport const getMessageName = (message: Operation) => {\n return message.operationId;\n};\n","import chalk from 'chalk';\n\nexport default () => {\n console.log(chalk.bgBlue(`\\nYou are using the open source license for this plugin`));\n console.log(\n chalk.blueBright(\n `This plugin is governed and published under a dual-license. \\nIf using for internal, commercial or proprietary software, please contact hello@eventcatalog.dev for a license to support the project.`\n )\n );\n};\n"],"mappings":";AAGA,OAAO,WAAW;AAElB,SAAS,gBAAgB;AACzB,OAAOA,YAAW;AAClB,OAAO,mBAAmB;AAC1B,OAAO,aAAa;;;ACRb,IAAM,kBAAkB,MAAM;AACnC,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAMT;;;ACLO,IAAMC,mBAAkB,CAAC,aAA+B;AAC7D,SAAO;AAAA;AAAA,EAEP,SAAS,KAAK,cAAc,GAAG,SAAS,KAAK,WAAW,KAAK,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA,EAM/D,SAAS,eACL;AAAA;AAAA,KAED,SAAS,aAAa,WAAW,KAAK,SAAS,aAAa,GAAG;AAAA,IAE9D,EACN;AAAA;AAEA;AAEO,IAAM,aAAa,CAAC,aAA+B;AACxD,QAAM,UAAU,SAAS,KAAK,cAAc,SAAS,KAAK,cAAc;AACxE,SAAO,WAAW,QAAQ,SAAS,MAAM,UAAU;AACrD;;;ACnBO,IAAMC,mBAAkB,CAAC,YAAuB;AACrD,SAAO;AAAA;AAAA;AAAA;AAAA,EAKP,QAAQ,eACJ;AAAA;AAAA,KAED,QAAQ,aAAa,WAAW,KAAK,QAAQ,aAAa,GAAG;AAAA,IAE5D,EACN;AAAA;AAAA;AAGA;AAEO,IAAMC,cAAa,CAAC,YAAuB;AAChD,QAAM,iBAAiB,QAAQ,UAAU,QAAQ,UAAU;AAC3D,QAAM,qBAAqB,QAAQ,cAAc,QAAQ,cAAc;AAEvE,MAAI,6BAA6B;AAEjC,MAAI,CAAC,4BAA4B;AAC/B,iCAA6B,sBAAsB,mBAAmB,SAAS,MAAM,qBAAqB;AAAA,EAC5G;AAEA,SAAO;AACT;AAWO,IAAM,iBAAiB,CAAC,YAAuB;AACpD,SAAO,QAAQ;AACjB;;;AC9CA,OAAO,WAAW;AAElB,IAAO,uBAAQ,MAAM;AACnB,UAAQ,IAAI,MA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,qBAAa;AACrB;","names":["chalk","defaultMarkdown","defaultMarkdown","getSummary","chalk","defaultMarkdown","getSummary"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/utils/schemas.ts","../src/utils/messages.ts","../src/utils/services.ts","../src/utils/domains.ts","../src/checkLicense.ts"],"sourcesContent":["// import utils from '@eventcatalog/sdk';\nimport { Parser } from '@asyncapi/parser';\nconst parser = new Parser();\nimport { readFile } from 'node:fs/promises';\nimport utils from '@eventcatalog/sdk';\nimport slugify from 'slugify';\nimport {\n defaultMarkdown as generateMarkdownForMessage,\n getMessageName,\n getSummary as getMessageSummary,\n getSchemaFileName,\n messageHasSchema,\n} from './utils/messages';\nimport { defaultMarkdown as generateMarkdownForService, getSummary as getServiceSummary } from './utils/services';\nimport { defaultMarkdown as generateMarkdownForDomain } from './utils/domains';\nimport chalk from 'chalk';\nimport checkLicense from './checkLicense';\nimport argv from 'minimist';\nconst cliArgs = argv(process.argv.slice(2));\n\ntype Domain = {\n id: string;\n name: string;\n version: string;\n};\n\ntype Props = {\n path: string | string[];\n domain?: Domain;\n debug?: boolean;\n};\n\nexport default async (config: any, options: Props) => {\n if (!process.env.PROJECT_DIR) {\n throw new Error('Please provide catalog url (env variable PROJECT_DIR)');\n }\n\n const {\n writeService,\n writeEvent,\n writeCommand,\n getService,\n versionService,\n rmService,\n getDomain,\n writeDomain,\n addServiceToDomain,\n getCommand,\n getEvent,\n rmEventById,\n rmCommandById,\n versionCommand,\n versionEvent,\n addSchemaToCommand,\n addSchemaToEvent,\n addFileToService,\n versionDomain,\n } = utils(process.env.PROJECT_DIR);\n\n const asyncAPIFiles = Array.isArray(options.path) ? options.path : [options.path];\n\n console.log(chalk.green(`Processing ${asyncAPIFiles.length} AsyncAPI files...`));\n\n for (const path of asyncAPIFiles) {\n console.log(chalk.gray(`Processing ${path}`));\n\n const asyncAPIFile = await readFile(path, 'utf-8');\n const { document } = await parser.parse(asyncAPIFile);\n\n if (!document) {\n console.log(chalk.red('Failed to parse AsyncAPI file'));\n if (options.debug || cliArgs.debug) {\n const diagnostics = await parser.validate(asyncAPIFile);\n console.log(diagnostics);\n } else {\n console.log(chalk.red('Run with debug option in the generator to see diagnostics'));\n }\n continue;\n }\n\n const operations = document.allOperations();\n const documentTags = document.info().tags().all() || [];\n\n const serviceId = slugify(document.info().title(), { lower: true, strict: true });\n const version = document.info().version();\n\n // What messages does this service send and receive\n const sends = [];\n const receives = [];\n let specifications = {};\n\n let serviceMarkdown = generateMarkdownForService(document);\n\n // Manage domain\n if (options.domain) {\n // Try and get the domain\n const { id: domainId, name: domainName, version: domainVersion } = options.domain;\n const domain = await getDomain(options.domain.id, domainVersion || 'latest');\n const currentDomain = await getDomain(options.domain.id, 'latest');\n\n console.log(chalk.blue(`\\nProcessing domain: ${domainName} (v${domainVersion})`));\n\n // Found a domain, but the versions do not match\n if (currentDomain && currentDomain.version !== domainVersion) {\n await versionDomain(domainId);\n console.log(chalk.cyan(` - Versioned previous domain (v${currentDomain.version})`));\n }\n\n // Do we need to create a new domain?\n if (!domain || (domain && domain.version !== domainVersion)) {\n await writeDomain({\n id: domainId,\n name: domainName,\n version: domainVersion,\n markdown: generateMarkdownForDomain(document),\n // services: [{ id: serviceId, version: version }],\n });\n console.log(chalk.cyan(` - Domain (v${domainVersion}) created`));\n }\n\n if (currentDomain && currentDomain.version === domainVersion) {\n console.log(chalk.yellow(` - Domain (v${domainVersion}) already exists, skipped creation...`));\n }\n\n // Add the service to the domain\n await addServiceToDomain(domainId, { id: serviceId, version: version }, domainVersion);\n }\n\n // Find events/commands\n for (const operation of operations) {\n for (const message of operation.messages()) {\n const eventType = message.extensions().get('x-eventcatalog-message-type')?.value() || 'event';\n\n const messageId = message.id().toLowerCase();\n\n let messageMarkdown = generateMarkdownForMessage(document, message);\n const writeMessage = eventType === 'event' ? writeEvent : writeCommand;\n const versionMessage = eventType === 'event' ? versionEvent : versionCommand;\n const getMessage = eventType === 'event' ? getEvent : getCommand;\n const rmMessageById = eventType === 'event' ? rmEventById : rmCommandById;\n const addSchemaToMessage = eventType === 'event' ? addSchemaToEvent : addSchemaToCommand;\n const badges = message.tags().all() || [];\n\n // Check if the message already exists in the catalog\n const catalogedMessage = await getMessage(message.id().toLowerCase(), 'latest');\n\n console.log(chalk.blue(`Processing message: ${getMessageName(message)} (v${version})`));\n\n if (catalogedMessage) {\n messageMarkdown = catalogedMessage.markdown;\n // if the version matches, we can override the message but keep markdown as it was\n if (catalogedMessage.version === version) {\n await rmMessageById(messageId, version);\n } else {\n // if the version does not match, we need to version the message\n await versionMessage(messageId);\n console.log(chalk.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));\n }\n }\n\n // Write the message to the catalog\n await writeMessage(\n {\n id: messageId,\n version: version,\n name: getMessageName(message),\n summary: getMessageSummary(message),\n markdown: messageMarkdown,\n badges: badges.map((badge) => ({ content: badge.name(), textColor: 'blue', backgroundColor: 'blue' })),\n schemaPath: messageHasSchema(message) ? getSchemaFileName(message) : undefined,\n },\n {\n path: message.id(),\n }\n );\n\n console.log(chalk.cyan(` - Message (v${version}) created`));\n\n // Check if the message has a payload, if it does then document in EventCatalog\n if (messageHasSchema(message)) {\n addSchemaToMessage(\n messageId,\n {\n fileName: getSchemaFileName(message),\n schema: JSON.stringify(message.payload()?.json(), null, 4),\n },\n version\n );\n console.log(chalk.cyan(` - Schema added to message (v${version})`));\n }\n\n // Add the message to the correct array\n if (operation.action() === 'send' || operation.action() === 'publish') {\n sends.push({ id: messageId, version: version });\n }\n if (operation.action() === 'receive' || operation.action() === 'subscribe') {\n receives.push({ id: messageId, version: version });\n }\n }\n }\n\n // Check if service is already defined... if the versions do not match then create service.\n const latestServiceInCatalog = await getService(serviceId, 'latest');\n\n console.log(chalk.blue(`Processing service: ${document.info().title()} (v${version})`));\n\n if (latestServiceInCatalog) {\n serviceMarkdown = latestServiceInCatalog.markdown;\n // Found a service, and versions do not match, we need to version the one already there\n if (latestServiceInCatalog.version !== version) {\n await versionService(serviceId);\n console.log(chalk.cyan(` - Versioned previous service (v${latestServiceInCatalog.version})`));\n }\n\n // Match found, override it\n if (latestServiceInCatalog.version === version) {\n serviceMarkdown = latestServiceInCatalog.markdown;\n specifications = latestServiceInCatalog.specifications ?? {};\n await rmService(document.info().title());\n }\n }\n\n await writeService(\n {\n id: serviceId,\n name: document.info().title(),\n version: version,\n summary: getServiceSummary(document),\n badges: documentTags.map((tag) => ({ content: tag.name(), textColor: 'blue', backgroundColor: 'blue' })),\n markdown: serviceMarkdown,\n sends,\n receives,\n schemaPath: path.split('/').pop() || 'asyncapi.yml',\n specifications: {\n ...specifications,\n asyncapiPath: path.split('/').pop() || 'asyncapi.yml',\n },\n },\n { path: document.info().title() }\n );\n\n await addFileToService(\n serviceId,\n {\n fileName: path.split('/').pop() || 'asyncapi.yml',\n content: asyncAPIFile,\n },\n version\n );\n\n console.log(chalk.cyan(` - Service (v${version}) created`));\n\n console.log(chalk.green(`\\nFinished generating event catalog for AsyncAPI ${document.info().title()} (v${version})`));\n }\n\n await checkLicense();\n};\n","export const getFileExtentionFromSchemaFormat = (format: string | undefined = '') => {\n if (format.includes('avro')) return 'avsc';\n if (format.includes('yml')) return 'yml';\n if (format.includes('json')) return 'json';\n if (format.includes('openapi')) return 'openapi';\n if (format.includes('protobuf')) return 'protobuf';\n if (format.includes('yaml')) return 'yaml';\n\n return 'json';\n};\n","import { MessageInterface, AsyncAPIDocumentInterface } from '@asyncapi/parser';\nimport { getFileExtentionFromSchemaFormat } from './schemas';\n\nexport const defaultMarkdown = (document: AsyncAPIDocumentInterface, message: MessageInterface) => {\n return `\n## Architecture\n<NodeGraph />\n\n${\n messageHasSchema(message)\n ? `\n## Schema\n<SchemaViewer file=\"${getSchemaFileName(message)}\" title=\"Message Schema\" maxHeight=\"500\" />\n`\n : ''\n}\n\n${\n message.externalDocs()\n ? `\n## External documentation\n- [${message.externalDocs()?.description()}](${message.externalDocs()?.url()})\n`\n : ''\n}\n\n`;\n};\n\nexport const getSummary = (message: MessageInterface) => {\n const messageSummary = message.hasSummary() ? message.summary() : '';\n const messageDescription = message.hasDescription() ? message.description() : '';\n\n let eventCatalogMessageSummary = messageSummary;\n\n if (!eventCatalogMessageSummary) {\n eventCatalogMessageSummary = messageDescription && messageDescription.length < 150 ? messageDescription : '';\n }\n\n return eventCatalogMessageSummary;\n};\n\nexport const messageHasSchema = (message: MessageInterface) => {\n return message.hasPayload() && message.schemaFormat();\n};\n\nexport const getSchemaFileName = (message: MessageInterface) => {\n const extension = getFileExtentionFromSchemaFormat(message.schemaFormat());\n return `schema.${extension}`;\n};\n\nexport const getMessageName = (message: MessageInterface) => {\n return message.hasTitle() && message.title() ? (message.title() as string) : message.id();\n};\n","import { AsyncAPIDocumentInterface } from '@asyncapi/parser';\n\nexport const defaultMarkdown = (document: AsyncAPIDocumentInterface) => {\n return `\n\n${document.info().hasDescription() ? `${document.info().description()}` : ''} \n\n## Architecture diagram\n<NodeGraph />\n\n${\n document.info().externalDocs()\n ? `\n## External documentation\n- [${document.info().externalDocs()?.description()}](${document.info().externalDocs()?.url()})\n`\n : ''\n}\n`;\n};\n\nexport const getSummary = (document: AsyncAPIDocumentInterface) => {\n const summary = document.info().hasDescription() ? document.info().description() : '';\n return summary && summary.length < 150 ? summary : '';\n};\n","import { AsyncAPIDocumentInterface } from '@asyncapi/parser';\n\nexport const defaultMarkdown = (document: AsyncAPIDocumentInterface) => {\n return `\n\n## Architecture diagram\n<NodeGraph />\n\n`;\n};\n","import chalk from 'chalk';\n\nexport default () => {\n console.log(chalk.bgBlue(`\\nYou are using the open source license for this plugin`));\n console.log(\n chalk.blueBright(\n `This plugin is governed and published under a dual-license. \\nIf using for internal, commercial or proprietary software, please contact hello@eventcatalog.dev for a license to support the project.`\n )\n );\n};\n"],"mappings":";AACA,SAAS,cAAc;AAEvB,SAAS,gBAAgB;AACzB,OAAO,WAAW;AAClB,OAAO,aAAa;;;ACLb,IAAM,mCAAmC,CAAC,SAA6B,OAAO;AACnF,MAAI,OAAO,SAAS,MAAM,EAAG,QAAO;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M,CAAC,MAAM,OAAO,GAAG,CAAC;AAAA,EACtH;AAEA,QAAM,qBAAa;AACrB;","names":["defaultMarkdown","getSummary","defaultMarkdown","chalk","chalk","defaultMarkdown","getSummary"]}
package/package.json CHANGED
@@ -1,15 +1,7 @@
1
1
  {
2
2
  "name": "@eventcatalog/generator-asyncapi",
3
- "version": "0.0.3",
3
+ "version": "0.1.0",
4
4
  "description": "AsyncAPI generator for EventCatalog",
5
- "scripts": {
6
- "build": "tsup",
7
- "test": "vitest",
8
- "format": "prettier --write .",
9
- "format:diff": "prettier --list-different .",
10
- "changeset": "changeset",
11
- "release": "changeset publish"
12
- },
13
5
  "publishConfig": {
14
6
  "access": "public"
15
7
  },
@@ -19,6 +11,7 @@
19
11
  "devDependencies": {
20
12
  "@types/fs-extra": "^11.0.4",
21
13
  "@types/lodash": "^4.17.7",
14
+ "@types/minimist": "^1.2.5",
22
15
  "@types/node": "^20.16.1",
23
16
  "prettier": "^3.3.3",
24
17
  "tsup": "^8.1.0",
@@ -33,16 +26,23 @@
33
26
  "module": "./dist/index.mjs",
34
27
  "types": "./dist/index.d.ts",
35
28
  "dependencies": {
36
- "@apidevtools/swagger-parser": "^10.1.0",
37
29
  "@asyncapi/parser": "^3.2.2",
38
30
  "@changesets/cli": "^2.27.7",
39
- "@eventcatalog/sdk": "^0.0.12",
31
+ "@eventcatalog/sdk": "^0.1.1",
40
32
  "chalk": "^4",
41
33
  "fs-extra": "^11.2.0",
42
34
  "glob": "^11.0.0",
43
35
  "gray-matter": "^4.0.3",
44
36
  "lodash": "^4.17.21",
45
- "openapi-types": "^12.1.3",
37
+ "minimist": "^1.2.8",
46
38
  "slugify": "^1.6.6"
39
+ },
40
+ "scripts": {
41
+ "build": "tsup",
42
+ "test": "vitest",
43
+ "format": "prettier --write .",
44
+ "format:diff": "prettier --list-different .",
45
+ "changeset": "changeset",
46
+ "release": "changeset publish"
47
47
  }
48
- }
48
+ }