@eventcatalog/generator-asyncapi 6.4.3 → 7.0.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/dist/index.js CHANGED
@@ -1543,7 +1543,7 @@ var import_path3 = __toESM(require("path"));
1543
1543
  // package.json
1544
1544
  var package_default = {
1545
1545
  name: "@eventcatalog/generator-asyncapi",
1546
- version: "6.4.3",
1546
+ version: "7.0.0",
1547
1547
  description: "AsyncAPI generator for EventCatalog",
1548
1548
  scripts: {
1549
1549
  build: "tsup",
@@ -1587,7 +1587,7 @@ var package_default = {
1587
1587
  "fs-extra": "^11.2.0",
1588
1588
  glob: "^12.0.0",
1589
1589
  "gray-matter": "^4.0.3",
1590
- "js-yaml": "^4.1.0",
1590
+ "js-yaml": "^4.3.0",
1591
1591
  lodash: "^4.17.23",
1592
1592
  minimist: "^1.2.8",
1593
1593
  semver: "^7.7.2",
@@ -4295,6 +4295,9 @@ var index_default = async (config, options) => {
4295
4295
  versionCommand,
4296
4296
  versionEvent,
4297
4297
  versionQuery,
4298
+ rmCommandById,
4299
+ rmEventById,
4300
+ rmQueryById,
4298
4301
  addSchemaToCommand,
4299
4302
  addSchemaToEvent,
4300
4303
  addSchemaToQuery,
@@ -4314,6 +4317,7 @@ var index_default = async (config, options) => {
4314
4317
  write: writeEvent,
4315
4318
  version: versionEvent,
4316
4319
  get: getEvent,
4320
+ remove: rmEventById,
4317
4321
  addSchema: addSchemaToEvent,
4318
4322
  addExample: addExampleToEvent,
4319
4323
  collection: "events"
@@ -4322,6 +4326,7 @@ var index_default = async (config, options) => {
4322
4326
  write: writeCommand,
4323
4327
  version: versionCommand,
4324
4328
  get: getCommand,
4329
+ remove: rmCommandById,
4325
4330
  addSchema: addSchemaToCommand,
4326
4331
  addExample: addExampleToCommand,
4327
4332
  collection: "commands"
@@ -4330,6 +4335,7 @@ var index_default = async (config, options) => {
4330
4335
  write: writeQuery,
4331
4336
  version: versionQuery,
4332
4337
  get: getQuery,
4338
+ remove: rmQueryById,
4333
4339
  addSchema: addSchemaToQuery,
4334
4340
  addExample: addExampleToQuery,
4335
4341
  collection: "queries"
@@ -4501,7 +4507,8 @@ Processing domain: ${domainName} (v${domainVersion})`));
4501
4507
  const deprecatedDate = message2.extensions().get("x-eventcatalog-deprecated-date")?.value() || null;
4502
4508
  const deprecatedMessage = message2.extensions().get("x-eventcatalog-deprecated-message")?.value() || null;
4503
4509
  const isMessageMarkedAsDraft = isDomainMarkedAsDraft || isServiceMarkedAsDraft || message2.extensions().get("x-eventcatalog-draft")?.value() || null;
4504
- const serviceOwnsMessageContract = isServiceMessageOwner(message2, operation);
4510
+ const messageOwnership = getMessageOwnership(message2, operation);
4511
+ const serviceOwnsMessageContract = messageOwnership === "owner";
4505
4512
  const isReceived = operation.action() === "receive" || operation.action() === "subscribe";
4506
4513
  const isSent = operation.action() === "send" || operation.action() === "publish";
4507
4514
  let messageId = options.messages?.id?.lowerCase ? message2.id().toLowerCase() : message2.id();
@@ -4519,6 +4526,7 @@ Processing domain: ${domainName} (v${domainVersion})`));
4519
4526
  write: writeMessage,
4520
4527
  version: versionMessage,
4521
4528
  get: getMessage,
4529
+ remove: removeMessage,
4522
4530
  addSchema: addSchemaToMessage,
4523
4531
  addExample: addExampleToMessage,
4524
4532
  collection: folder
@@ -4533,15 +4541,24 @@ Processing domain: ${domainName} (v${domainVersion})`));
4533
4541
  if (options.writeFilesToRoot) {
4534
4542
  messagePath = messageId;
4535
4543
  }
4536
- if (serviceOwnsMessageContract) {
4544
+ if (messageOwnership === "external") {
4545
+ console.log(import_chalk4.default.yellow(` - Skipping external message: ${getMessageName(message2)}(v${messageVersion})`));
4546
+ } else {
4537
4547
  const catalogedMessage = await getMessage(messageId, "latest");
4538
4548
  let shouldWriteMessage = true;
4539
- if (catalogedMessage) {
4549
+ let existingMessageDirectoryToRelocate = null;
4550
+ if (serviceOwnsMessageContract && catalogedMessage) {
4540
4551
  messageMarkdown = catalogedMessage.markdown;
4541
4552
  messageBadges = catalogedMessage.badges || null;
4542
4553
  messageAttachments = catalogedMessage.attachments || null;
4543
4554
  const catalogedVersion = catalogedMessage.version ?? "";
4544
4555
  if (isSameVersion(catalogedVersion, messageVersion)) {
4556
+ const catalogedMessagePath = await getResourcePath(process.env.PROJECT_DIR, messageId, catalogedVersion);
4557
+ const targetMessageDirectory = import_path3.default.resolve(process.env.PROJECT_DIR, folder, messagePath);
4558
+ const catalogedMessageDirectory = catalogedMessagePath ? import_path3.default.dirname(catalogedMessagePath.fullPath) : null;
4559
+ if (catalogedMessageDirectory && import_path3.default.normalize(catalogedMessageDirectory) !== import_path3.default.normalize(targetMessageDirectory)) {
4560
+ existingMessageDirectoryToRelocate = catalogedMessageDirectory;
4561
+ }
4545
4562
  } else if (isNewerVersion(messageVersion, catalogedVersion)) {
4546
4563
  await versionMessage(messageId);
4547
4564
  console.log(import_chalk4.default.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));
@@ -4554,8 +4571,24 @@ Processing domain: ${domainName} (v${domainVersion})`));
4554
4571
  messageVersion = catalogedVersion;
4555
4572
  shouldWriteMessage = false;
4556
4573
  }
4574
+ } else if (!serviceOwnsMessageContract && catalogedMessage) {
4575
+ console.log(
4576
+ import_chalk4.default.yellow(` - Referencing existing message ${messageId} (v${catalogedMessage.version}) without overwriting`)
4577
+ );
4578
+ messageVersion = catalogedMessage.version ?? messageVersion;
4579
+ shouldWriteMessage = false;
4557
4580
  }
4558
4581
  if (shouldWriteMessage) {
4582
+ if (existingMessageDirectoryToRelocate) {
4583
+ const targetMessageDirectory = import_path3.default.resolve(process.env.PROJECT_DIR, folder, messagePath);
4584
+ await removeMessage(messageId, messageVersion, true);
4585
+ await (0, import_promises.mkdir)(import_path3.default.dirname(targetMessageDirectory), { recursive: true });
4586
+ await (0, import_promises.cp)(existingMessageDirectoryToRelocate, targetMessageDirectory, {
4587
+ recursive: true,
4588
+ force: true
4589
+ });
4590
+ await (0, import_promises.rm)(existingMessageDirectoryToRelocate, { recursive: true, force: true });
4591
+ }
4559
4592
  await writeMessage(
4560
4593
  {
4561
4594
  id: messageId,
@@ -4573,7 +4606,9 @@ Processing domain: ${domainName} (v${domainVersion})`));
4573
4606
  ...isMessageMarkedAsDraft && { draft: true }
4574
4607
  },
4575
4608
  {
4576
- override: true,
4609
+ // References only reach this branch when the message is missing. They may
4610
+ // create a fallback, but only owners may replace an existing contract.
4611
+ override: serviceOwnsMessageContract,
4577
4612
  path: messagePath
4578
4613
  }
4579
4614
  );
@@ -4607,8 +4642,6 @@ Processing domain: ${domainName} (v${domainVersion})`));
4607
4642
  }
4608
4643
  }
4609
4644
  }
4610
- } else {
4611
- console.log(import_chalk4.default.yellow(` - Skipping external message: ${getMessageName(message2)}(v${messageVersion})`));
4612
4645
  }
4613
4646
  const group = options.groupMessagesBy === "x-extension" ? message2.extensions().get("x-eventcatalog-group")?.value() || void 0 : void 0;
4614
4647
  if (parseChannels) {
@@ -4774,10 +4807,17 @@ var getSchemaFromMessagePart = (schema) => {
4774
4807
  var isJSONSchemaMessage = (message2) => {
4775
4808
  return getSchemaFileName(message2).endsWith(".json");
4776
4809
  };
4777
- var isServiceMessageOwner = (message2, operation) => {
4810
+ var getMessageOwnership = (message2, operation) => {
4778
4811
  const operationRole = operation?.extensions?.().get?.("x-eventcatalog-role")?.value?.();
4779
4812
  const messageRole = message2.extensions().get("x-eventcatalog-role")?.value();
4780
- const value = operationRole || messageRole || "provider";
4781
- return value === "provider";
4813
+ const explicitRole = operationRole || messageRole;
4814
+ if (explicitRole) {
4815
+ return explicitRole === "provider" ? "owner" : "external";
4816
+ }
4817
+ const action = operation?.action?.();
4818
+ if (action === "receive" || action === "subscribe") {
4819
+ return "reference";
4820
+ }
4821
+ return "owner";
4782
4822
  };
4783
4823
  //# sourceMappingURL=index.js.map