@eventcatalog/generator-asyncapi 0.0.2 → 0.0.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.
- package/LICENSE.md +25 -644
- package/README.md +2 -2
- package/dist/checkLicense.d.mts +3 -0
- package/dist/checkLicense.d.ts +3 -0
- package/dist/checkLicense.js +47 -0
- package/dist/checkLicense.js.map +1 -0
- package/dist/checkLicense.mjs +16 -0
- package/dist/checkLicense.mjs.map +1 -0
- package/dist/index.d.mts +17 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.js +154 -161
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +154 -161
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/utils/schemas.ts","../src/utils/messages.ts","../src/utils/services.ts","../src/utils/domains.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';\n\nlet metrics = { eventsCreated: 0, commandsCreated: 0, servicesCreated: 0, domainsCreated: 0 };\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) {\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\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 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() || 'asyncapi.yml',\n receives,\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","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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;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,SAAS,KAAK,EAAE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC;AAEtF,QAAI,wBAAwB;AAC1B,wBAAkB,uBAAuB;AAEzC,UAAI,uBAAuB,YAAY,SAAS;AAC9C,cAAM,eAAe,SAAS;AAC9B,gBAAQ,IAAI,aAAAA,QAAM,KAAK,mCAAmC,uBAAuB,OAAO,GAAG,CAAC;AAAA,MAC9F;AAGA,UAAI,uBAAuB,YAAY,SAAS;AAC9C,0BAAkB,uBAAuB;AACzC,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,YAAY,KAAK,MAAM,GAAG,EAAE,IAAI,KAAK;AAAA,QACrC;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,aAAAH,QAAM,KAAK,gBAAgB,OAAO,WAAW,CAAC;AAE1D,YAAQ,IAAI,aAAAA,QAAM,MAAM;AAAA,iDAAoD,SAAS,KAAK,EAAE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC;AAAA,EACtH;AACF;","names":["defaultMarkdown","getSummary","defaultMarkdown","utils","chalk","slugify","defaultMarkdown","getSummary"]}
|
|
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,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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A,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"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,259 +1,252 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { Parser } from "@asyncapi/parser";
|
|
3
|
-
import { readFile } from "node:fs/promises";
|
|
4
2
|
import utils from "@eventcatalog/sdk";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import chalk2 from "chalk";
|
|
5
|
+
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
5
6
|
import slugify from "slugify";
|
|
6
7
|
|
|
7
|
-
// src/utils/
|
|
8
|
-
var
|
|
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
|
-
};
|
|
17
|
-
|
|
18
|
-
// src/utils/messages.ts
|
|
19
|
-
var defaultMarkdown = (document, message) => {
|
|
8
|
+
// src/utils/domains.ts
|
|
9
|
+
var defaultMarkdown = () => {
|
|
20
10
|
return `
|
|
21
|
-
## Architecture
|
|
22
|
-
<NodeGraph />
|
|
23
|
-
|
|
24
|
-
${messageHasSchema(message) ? `
|
|
25
|
-
## Schema
|
|
26
|
-
<SchemaViewer file="${getSchemaFileName(message)}" title="Message Schema" maxHeight="500" />
|
|
27
|
-
` : ""}
|
|
28
11
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- [${message.externalDocs()?.description()}](${message.externalDocs()?.url()})
|
|
32
|
-
` : ""}
|
|
12
|
+
## Architecture diagram
|
|
13
|
+
<NodeGraph />
|
|
33
14
|
|
|
34
15
|
`;
|
|
35
16
|
};
|
|
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
|
-
};
|
|
55
17
|
|
|
56
18
|
// src/utils/services.ts
|
|
57
19
|
var defaultMarkdown2 = (document) => {
|
|
58
20
|
return `
|
|
59
21
|
|
|
60
|
-
${document.info
|
|
22
|
+
${document.info.description ? `${document.info.description}` : ""}
|
|
61
23
|
|
|
62
24
|
## Architecture diagram
|
|
63
25
|
<NodeGraph />
|
|
64
26
|
|
|
65
|
-
${document.
|
|
27
|
+
${document.externalDocs ? `
|
|
66
28
|
## External documentation
|
|
67
|
-
- [${document.
|
|
29
|
+
- [${document.externalDocs.description}](${document.externalDocs.url})
|
|
68
30
|
` : ""}
|
|
69
31
|
`;
|
|
70
32
|
};
|
|
71
|
-
var
|
|
72
|
-
const summary = document.info
|
|
33
|
+
var getSummary = (document) => {
|
|
34
|
+
const summary = document.info.description ? document.info.description : "";
|
|
73
35
|
return summary && summary.length < 150 ? summary : "";
|
|
74
36
|
};
|
|
75
37
|
|
|
76
|
-
// src/utils/
|
|
77
|
-
var defaultMarkdown3 = (
|
|
38
|
+
// src/utils/messages.ts
|
|
39
|
+
var defaultMarkdown3 = (message) => {
|
|
78
40
|
return `
|
|
79
|
-
|
|
80
|
-
## Architecture diagram
|
|
41
|
+
## Architecture
|
|
81
42
|
<NodeGraph />
|
|
82
43
|
|
|
44
|
+
${message.externalDocs ? `
|
|
45
|
+
## External documentation
|
|
46
|
+
- [${message.externalDocs.description}](${message.externalDocs.url})
|
|
47
|
+
` : ""}
|
|
48
|
+
|
|
83
49
|
`;
|
|
84
50
|
};
|
|
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
63
|
|
|
86
|
-
// src/
|
|
64
|
+
// src/checkLicense.ts
|
|
87
65
|
import chalk from "chalk";
|
|
88
|
-
var
|
|
66
|
+
var checkLicense_default = () => {
|
|
67
|
+
console.log(chalk.bgBlue(`
|
|
68
|
+
You are using the open source license for this plugin`));
|
|
69
|
+
console.log(
|
|
70
|
+
chalk.blueBright(
|
|
71
|
+
`This plugin is governed and published under a dual-license.
|
|
72
|
+
If using for internal, commercial or proprietary software, please contact hello@eventcatalog.dev for a license to support the project.`
|
|
73
|
+
)
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// 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
|
+
}
|
|
89
107
|
var src_default = async (config, options) => {
|
|
90
108
|
if (!process.env.PROJECT_DIR) {
|
|
91
109
|
throw new Error("Please provide catalog url (env variable PROJECT_DIR)");
|
|
92
110
|
}
|
|
93
111
|
const {
|
|
94
|
-
writeService,
|
|
95
112
|
writeEvent,
|
|
96
|
-
writeCommand,
|
|
97
|
-
getService,
|
|
98
|
-
versionService,
|
|
99
|
-
rmService,
|
|
100
113
|
getDomain,
|
|
114
|
+
versionDomain,
|
|
101
115
|
writeDomain,
|
|
102
116
|
addServiceToDomain,
|
|
103
|
-
|
|
117
|
+
getService,
|
|
118
|
+
versionService,
|
|
119
|
+
rmService,
|
|
120
|
+
writeService,
|
|
121
|
+
addFileToService,
|
|
122
|
+
versionCommand,
|
|
104
123
|
getEvent,
|
|
105
|
-
|
|
124
|
+
getCommand,
|
|
106
125
|
rmCommandById,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
addSchemaToCommand,
|
|
110
|
-
addSchemaToEvent,
|
|
111
|
-
addFileToService,
|
|
112
|
-
versionDomain
|
|
126
|
+
rmEventById,
|
|
127
|
+
writeCommand
|
|
113
128
|
} = utils(process.env.PROJECT_DIR);
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
console.
|
|
122
|
-
if (options.debug) {
|
|
123
|
-
const diagnostics = await parser.validate(asyncAPIFile);
|
|
124
|
-
console.log(diagnostics);
|
|
125
|
-
} else {
|
|
126
|
-
console.log(chalk.red("Run with debug option in the generator to see diagnostics"));
|
|
127
|
-
}
|
|
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));
|
|
128
137
|
continue;
|
|
129
138
|
}
|
|
130
|
-
const
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
const receives = [];
|
|
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;
|
|
136
144
|
let serviceMarkdown = defaultMarkdown2(document);
|
|
137
145
|
if (options.domain) {
|
|
138
146
|
const { id: domainId, name: domainName, version: domainVersion } = options.domain;
|
|
139
147
|
const domain = await getDomain(options.domain.id, domainVersion || "latest");
|
|
140
148
|
const currentDomain = await getDomain(options.domain.id, "latest");
|
|
141
|
-
console.log(
|
|
149
|
+
console.log(chalk2.blue(`
|
|
142
150
|
Processing domain: ${domainName} (v${domainVersion})`));
|
|
143
151
|
if (currentDomain && currentDomain.version !== domainVersion) {
|
|
144
152
|
await versionDomain(domainId);
|
|
145
|
-
console.log(
|
|
153
|
+
console.log(chalk2.cyan(` - Versioned previous domain (v${currentDomain.version})`));
|
|
146
154
|
}
|
|
147
155
|
if (!domain || domain && domain.version !== domainVersion) {
|
|
148
156
|
await writeDomain({
|
|
149
157
|
id: domainId,
|
|
150
158
|
name: domainName,
|
|
151
159
|
version: domainVersion,
|
|
152
|
-
markdown:
|
|
153
|
-
// services: [{ id: serviceId, version: version }],
|
|
160
|
+
markdown: defaultMarkdown()
|
|
154
161
|
});
|
|
155
|
-
console.log(
|
|
162
|
+
console.log(chalk2.cyan(` - Domain (v${domainVersion}) created`));
|
|
156
163
|
}
|
|
157
164
|
if (currentDomain && currentDomain.version === domainVersion) {
|
|
158
|
-
console.log(
|
|
165
|
+
console.log(chalk2.yellow(` - Domain (v${domainVersion}) already exists, skipped creation...`));
|
|
159
166
|
}
|
|
160
167
|
await addServiceToDomain(domainId, { id: serviceId, version }, domainVersion);
|
|
161
168
|
}
|
|
169
|
+
const documentTags = document.tags || [];
|
|
170
|
+
let sends = [];
|
|
171
|
+
const receives = [];
|
|
162
172
|
for (const operation of operations) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
} else {
|
|
180
|
-
await versionMessage(messageId);
|
|
181
|
-
console.log(chalk.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
await writeMessage(
|
|
185
|
-
{
|
|
186
|
-
id: messageId,
|
|
187
|
-
version,
|
|
188
|
-
name: getMessageName(message),
|
|
189
|
-
summary: getSummary(message),
|
|
190
|
-
markdown: messageMarkdown,
|
|
191
|
-
badges: badges.map((badge) => ({ content: badge.name(), textColor: "blue", backgroundColor: "blue" })),
|
|
192
|
-
schemaPath: messageHasSchema(message) ? getSchemaFileName(message) : void 0
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
path: message.id()
|
|
196
|
-
}
|
|
197
|
-
);
|
|
198
|
-
console.log(chalk.cyan(` - Message (v${version}) created`));
|
|
199
|
-
if (messageHasSchema(message)) {
|
|
200
|
-
addSchemaToMessage(
|
|
201
|
-
messageId,
|
|
202
|
-
{
|
|
203
|
-
fileName: getSchemaFileName(message),
|
|
204
|
-
schema: JSON.stringify(message.payload()?.json(), null, 4)
|
|
205
|
-
},
|
|
206
|
-
version
|
|
207
|
-
);
|
|
208
|
-
console.log(chalk.cyan(` - Schema added to message (v${version})`));
|
|
209
|
-
}
|
|
210
|
-
if (operation.action() === "send" || operation.action() === "publish") {
|
|
211
|
-
sends.push({ id: messageId, version });
|
|
212
|
-
}
|
|
213
|
-
if (operation.action() === "receive" || operation.action() === "subscribe") {
|
|
214
|
-
receives.push({ id: messageId, version });
|
|
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})`));
|
|
215
189
|
}
|
|
216
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
|
+
}
|
|
203
|
+
);
|
|
204
|
+
receives.push({
|
|
205
|
+
id: operation.operationId,
|
|
206
|
+
version
|
|
207
|
+
});
|
|
208
|
+
console.log(chalk2.cyan(` - Message (v${version}) created`));
|
|
217
209
|
}
|
|
218
210
|
const latestServiceInCatalog = await getService(serviceId, "latest");
|
|
219
|
-
console.log(
|
|
211
|
+
console.log(chalk2.blue(`Processing service: ${document.info.title} (v${version})`));
|
|
220
212
|
if (latestServiceInCatalog) {
|
|
221
213
|
serviceMarkdown = latestServiceInCatalog.markdown;
|
|
214
|
+
sends = latestServiceInCatalog.sends || [];
|
|
222
215
|
if (latestServiceInCatalog.version !== version) {
|
|
223
216
|
await versionService(serviceId);
|
|
224
|
-
console.log(
|
|
217
|
+
console.log(chalk2.cyan(` - Versioned previous service (v${latestServiceInCatalog.version})`));
|
|
225
218
|
}
|
|
226
219
|
if (latestServiceInCatalog.version === version) {
|
|
227
|
-
|
|
228
|
-
await rmService(document.info().title());
|
|
220
|
+
await rmService(document.info.title);
|
|
229
221
|
}
|
|
230
222
|
}
|
|
231
223
|
await writeService(
|
|
232
224
|
{
|
|
233
225
|
id: serviceId,
|
|
234
|
-
name: document.info
|
|
226
|
+
name: document.info.title,
|
|
235
227
|
version,
|
|
236
|
-
summary:
|
|
237
|
-
badges: documentTags.map((tag) => ({ content: tag.name
|
|
228
|
+
summary: getSummary(document),
|
|
229
|
+
badges: documentTags.map((tag) => ({ content: tag.name, textColor: "blue", backgroundColor: "blue" })),
|
|
238
230
|
markdown: serviceMarkdown,
|
|
239
231
|
sends,
|
|
240
|
-
schemaPath: path.split("/").pop() || "
|
|
232
|
+
schemaPath: path.split("/").pop() || "openapi.yml",
|
|
241
233
|
receives
|
|
242
234
|
},
|
|
243
|
-
{ path: document.info
|
|
235
|
+
{ path: document.info.title }
|
|
244
236
|
);
|
|
245
237
|
await addFileToService(
|
|
246
238
|
serviceId,
|
|
247
239
|
{
|
|
248
|
-
fileName: path.split("/").pop() || "
|
|
249
|
-
content:
|
|
240
|
+
fileName: path.split("/").pop() || "openapi.yml",
|
|
241
|
+
content: openAPIFile
|
|
250
242
|
},
|
|
251
243
|
version
|
|
252
244
|
);
|
|
253
|
-
console.log(
|
|
254
|
-
console.log(
|
|
255
|
-
Finished generating event catalog for AsyncAPI ${document.info
|
|
245
|
+
console.log(chalk2.cyan(` - Service (v${version}) created`));
|
|
246
|
+
console.log(chalk2.green(`
|
|
247
|
+
Finished generating event catalog for AsyncAPI ${document.info.title} (v${version})`));
|
|
256
248
|
}
|
|
249
|
+
await checkLicense_default();
|
|
257
250
|
};
|
|
258
251
|
export {
|
|
259
252
|
src_default as default
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/utils/schemas.ts","../src/utils/messages.ts","../src/utils/services.ts","../src/utils/domains.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';\n\nlet metrics = { eventsCreated: 0, commandsCreated: 0, servicesCreated: 0, domainsCreated: 0 };\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) {\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\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 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() || 'asyncapi.yml',\n receives,\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","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"],"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;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,s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AAAA,QACvG,UAAU;AAAA,QACV;AAAA,QACA,YAAY,KAAK,MAAM,GAAG,EAAE,IAAI,KAAK;AAAA,QACrC;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,MAAM,KAAK,gBAAgB,OAAO,WAAW,CAAC;AAE1D,YAAQ,IAAI,MAAM,MAAM;AAAA,iDAAoD,SAAS,KAAK,EAAE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC;AAAA,EACtH;AACF;","names":["defaultMarkdown","getSummary","defaultMarkdown","defaultMarkdown","getSummary"]}
|
|
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;AA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BAAwB;AAC1B,wBAAkB,uBAAuB;AACzC,cAAQ,uBAAuB,SAAU,CAAC;AAE1C,UAAI,uBAAuB,YAAY,SAAS;AAC9C,cAAM,eAAe,SAAS;AAC9B,gBAAQ,IAAIA,OAAM,KAAK,mCAAmC,uBAAuB,OAAO,GAAG,CAAC;AAAA,MAC9F;AAGA,UAAI,uBAAuB,YAAY,SAAS;AAC9C,cAAM,UAAU,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,IAAIA,OAAM,KAAK,gBAAgB,OAAO,WAAW,CAAC;AAE1D,YAAQ,IAAIA,OAAM,MAAM;AAAA,iDAAoD,SAAS,KAAK,KAAK,MAAM,OAAO,GAAG,CAAC;AAAA,EAClH;AAEA,QAAM,qBAAa;AACrB;","names":["chalk","defaultMarkdown","defaultMarkdown","getSummary","chalk","defaultMarkdown","getSummary"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eventcatalog/generator-asyncapi",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "AsyncAPI generator for EventCatalog",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"module": "./dist/index.mjs",
|
|
34
34
|
"types": "./dist/index.d.ts",
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@apidevtools/swagger-parser": "^10.1.0",
|
|
36
37
|
"@asyncapi/parser": "^3.2.2",
|
|
37
38
|
"@changesets/cli": "^2.27.7",
|
|
38
39
|
"@eventcatalog/sdk": "^0.0.12",
|
|
@@ -41,6 +42,7 @@
|
|
|
41
42
|
"glob": "^11.0.0",
|
|
42
43
|
"gray-matter": "^4.0.3",
|
|
43
44
|
"lodash": "^4.17.21",
|
|
45
|
+
"openapi-types": "^12.1.3",
|
|
44
46
|
"slugify": "^1.6.6"
|
|
45
47
|
}
|
|
46
48
|
}
|