@eventcatalog/generator-asyncapi 6.4.4 → 7.0.1

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.d.mts CHANGED
@@ -3,6 +3,7 @@ import { z } from 'zod';
3
3
  declare const optionsSchema: z.ZodObject<{
4
4
  licenseKey: z.ZodOptional<z.ZodString>;
5
5
  writeFilesToRoot: z.ZodOptional<z.ZodBoolean>;
6
+ preserveExistingMessages: z.ZodOptional<z.ZodBoolean>;
6
7
  services: z.ZodArray<z.ZodObject<{
7
8
  id: z.ZodString;
8
9
  version: z.ZodOptional<z.ZodString>;
@@ -279,6 +280,7 @@ declare const optionsSchema: z.ZodObject<{
279
280
  }[];
280
281
  licenseKey?: string | undefined;
281
282
  writeFilesToRoot?: boolean | undefined;
283
+ preserveExistingMessages?: boolean | undefined;
282
284
  messages?: {
283
285
  id?: {
284
286
  lowerCase?: boolean | undefined;
@@ -344,6 +346,7 @@ declare const optionsSchema: z.ZodObject<{
344
346
  }[];
345
347
  licenseKey?: string | undefined;
346
348
  writeFilesToRoot?: boolean | undefined;
349
+ preserveExistingMessages?: boolean | undefined;
347
350
  messages?: {
348
351
  id?: {
349
352
  lowerCase?: boolean | undefined;
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { z } from 'zod';
3
3
  declare const optionsSchema: z.ZodObject<{
4
4
  licenseKey: z.ZodOptional<z.ZodString>;
5
5
  writeFilesToRoot: z.ZodOptional<z.ZodBoolean>;
6
+ preserveExistingMessages: z.ZodOptional<z.ZodBoolean>;
6
7
  services: z.ZodArray<z.ZodObject<{
7
8
  id: z.ZodString;
8
9
  version: z.ZodOptional<z.ZodString>;
@@ -279,6 +280,7 @@ declare const optionsSchema: z.ZodObject<{
279
280
  }[];
280
281
  licenseKey?: string | undefined;
281
282
  writeFilesToRoot?: boolean | undefined;
283
+ preserveExistingMessages?: boolean | undefined;
282
284
  messages?: {
283
285
  id?: {
284
286
  lowerCase?: boolean | undefined;
@@ -344,6 +346,7 @@ declare const optionsSchema: z.ZodObject<{
344
346
  }[];
345
347
  licenseKey?: string | undefined;
346
348
  writeFilesToRoot?: boolean | undefined;
349
+ preserveExistingMessages?: boolean | undefined;
347
350
  messages?: {
348
351
  id?: {
349
352
  lowerCase?: boolean | undefined;
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.4",
1546
+ version: "7.0.1",
1547
1547
  description: "AsyncAPI generator for EventCatalog",
1548
1548
  scripts: {
1549
1549
  build: "tsup",
@@ -4161,6 +4161,7 @@ var cliArgs = (0, import_minimist.default)(process.argv.slice(2));
4161
4161
  var optionsSchema = import_zod.z.object({
4162
4162
  licenseKey: import_zod.z.string().optional(),
4163
4163
  writeFilesToRoot: import_zod.z.boolean().optional(),
4164
+ preserveExistingMessages: import_zod.z.boolean().optional(),
4164
4165
  services: import_zod.z.array(
4165
4166
  import_zod.z.object({
4166
4167
  id: import_zod.z.string({ required_error: "The service id is required. please provide the service id" }),
@@ -4295,6 +4296,9 @@ var index_default = async (config, options) => {
4295
4296
  versionCommand,
4296
4297
  versionEvent,
4297
4298
  versionQuery,
4299
+ rmCommandById,
4300
+ rmEventById,
4301
+ rmQueryById,
4298
4302
  addSchemaToCommand,
4299
4303
  addSchemaToEvent,
4300
4304
  addSchemaToQuery,
@@ -4314,6 +4318,7 @@ var index_default = async (config, options) => {
4314
4318
  write: writeEvent,
4315
4319
  version: versionEvent,
4316
4320
  get: getEvent,
4321
+ remove: rmEventById,
4317
4322
  addSchema: addSchemaToEvent,
4318
4323
  addExample: addExampleToEvent,
4319
4324
  collection: "events"
@@ -4322,6 +4327,7 @@ var index_default = async (config, options) => {
4322
4327
  write: writeCommand,
4323
4328
  version: versionCommand,
4324
4329
  get: getCommand,
4330
+ remove: rmCommandById,
4325
4331
  addSchema: addSchemaToCommand,
4326
4332
  addExample: addExampleToCommand,
4327
4333
  collection: "commands"
@@ -4330,6 +4336,7 @@ var index_default = async (config, options) => {
4330
4336
  write: writeQuery,
4331
4337
  version: versionQuery,
4332
4338
  get: getQuery,
4339
+ remove: rmQueryById,
4333
4340
  addSchema: addSchemaToQuery,
4334
4341
  addExample: addExampleToQuery,
4335
4342
  collection: "queries"
@@ -4342,7 +4349,8 @@ var index_default = async (config, options) => {
4342
4349
  parseSchemas = true,
4343
4350
  parseChannels = false,
4344
4351
  parseExamples = true,
4345
- attachHeadersToSchema = false
4352
+ attachHeadersToSchema = false,
4353
+ preserveExistingMessages = true
4346
4354
  } = options;
4347
4355
  console.log(import_chalk4.default.green(`Processing ${services.length} AsyncAPI files...`));
4348
4356
  for (const service of services) {
@@ -4501,7 +4509,8 @@ Processing domain: ${domainName} (v${domainVersion})`));
4501
4509
  const deprecatedDate = message2.extensions().get("x-eventcatalog-deprecated-date")?.value() || null;
4502
4510
  const deprecatedMessage = message2.extensions().get("x-eventcatalog-deprecated-message")?.value() || null;
4503
4511
  const isMessageMarkedAsDraft = isDomainMarkedAsDraft || isServiceMarkedAsDraft || message2.extensions().get("x-eventcatalog-draft")?.value() || null;
4504
- const serviceOwnsMessageContract = isServiceMessageOwner(message2, operation);
4512
+ const messageOwnership = getMessageOwnership(message2, operation);
4513
+ const serviceOwnsMessageContract = messageOwnership === "owner";
4505
4514
  const isReceived = operation.action() === "receive" || operation.action() === "subscribe";
4506
4515
  const isSent = operation.action() === "send" || operation.action() === "publish";
4507
4516
  let messageId = options.messages?.id?.lowerCase ? message2.id().toLowerCase() : message2.id();
@@ -4519,6 +4528,7 @@ Processing domain: ${domainName} (v${domainVersion})`));
4519
4528
  write: writeMessage,
4520
4529
  version: versionMessage,
4521
4530
  get: getMessage,
4531
+ remove: removeMessage,
4522
4532
  addSchema: addSchemaToMessage,
4523
4533
  addExample: addExampleToMessage,
4524
4534
  collection: folder
@@ -4533,15 +4543,26 @@ Processing domain: ${domainName} (v${domainVersion})`));
4533
4543
  if (options.writeFilesToRoot) {
4534
4544
  messagePath = messageId;
4535
4545
  }
4536
- if (serviceOwnsMessageContract) {
4546
+ if (messageOwnership === "external") {
4547
+ console.log(import_chalk4.default.yellow(` - Skipping external message: ${getMessageName(message2)}(v${messageVersion})`));
4548
+ } else {
4537
4549
  const catalogedMessage = await getMessage(messageId, "latest");
4538
4550
  let shouldWriteMessage = true;
4539
- if (catalogedMessage) {
4540
- messageMarkdown = catalogedMessage.markdown;
4551
+ let existingMessageDirectoryToRelocate = null;
4552
+ if (serviceOwnsMessageContract && catalogedMessage) {
4541
4553
  messageBadges = catalogedMessage.badges || null;
4542
4554
  messageAttachments = catalogedMessage.attachments || null;
4555
+ if (preserveExistingMessages) {
4556
+ messageMarkdown = catalogedMessage.markdown;
4557
+ }
4543
4558
  const catalogedVersion = catalogedMessage.version ?? "";
4544
4559
  if (isSameVersion(catalogedVersion, messageVersion)) {
4560
+ const catalogedMessagePath = await getResourcePath(process.env.PROJECT_DIR, messageId, catalogedVersion);
4561
+ const targetMessageDirectory = import_path3.default.resolve(process.env.PROJECT_DIR, folder, messagePath);
4562
+ const catalogedMessageDirectory = catalogedMessagePath ? import_path3.default.dirname(catalogedMessagePath.fullPath) : null;
4563
+ if (catalogedMessageDirectory && import_path3.default.normalize(catalogedMessageDirectory) !== import_path3.default.normalize(targetMessageDirectory)) {
4564
+ existingMessageDirectoryToRelocate = catalogedMessageDirectory;
4565
+ }
4545
4566
  } else if (isNewerVersion(messageVersion, catalogedVersion)) {
4546
4567
  await versionMessage(messageId);
4547
4568
  console.log(import_chalk4.default.cyan(` - Versioned previous message: (v${catalogedMessage.version})`));
@@ -4554,8 +4575,24 @@ Processing domain: ${domainName} (v${domainVersion})`));
4554
4575
  messageVersion = catalogedVersion;
4555
4576
  shouldWriteMessage = false;
4556
4577
  }
4578
+ } else if (!serviceOwnsMessageContract && catalogedMessage) {
4579
+ console.log(
4580
+ import_chalk4.default.yellow(` - Referencing existing message ${messageId} (v${catalogedMessage.version}) without overwriting`)
4581
+ );
4582
+ messageVersion = catalogedMessage.version ?? messageVersion;
4583
+ shouldWriteMessage = false;
4557
4584
  }
4558
4585
  if (shouldWriteMessage) {
4586
+ if (existingMessageDirectoryToRelocate) {
4587
+ const targetMessageDirectory = import_path3.default.resolve(process.env.PROJECT_DIR, folder, messagePath);
4588
+ await removeMessage(messageId, messageVersion, true);
4589
+ await (0, import_promises.mkdir)(import_path3.default.dirname(targetMessageDirectory), { recursive: true });
4590
+ await (0, import_promises.cp)(existingMessageDirectoryToRelocate, targetMessageDirectory, {
4591
+ recursive: true,
4592
+ force: true
4593
+ });
4594
+ await (0, import_promises.rm)(existingMessageDirectoryToRelocate, { recursive: true, force: true });
4595
+ }
4559
4596
  await writeMessage(
4560
4597
  {
4561
4598
  id: messageId,
@@ -4573,7 +4610,9 @@ Processing domain: ${domainName} (v${domainVersion})`));
4573
4610
  ...isMessageMarkedAsDraft && { draft: true }
4574
4611
  },
4575
4612
  {
4576
- override: true,
4613
+ // References only reach this branch when the message is missing. They may
4614
+ // create a fallback, but only owners may replace an existing contract.
4615
+ override: serviceOwnsMessageContract,
4577
4616
  path: messagePath
4578
4617
  }
4579
4618
  );
@@ -4607,8 +4646,6 @@ Processing domain: ${domainName} (v${domainVersion})`));
4607
4646
  }
4608
4647
  }
4609
4648
  }
4610
- } else {
4611
- console.log(import_chalk4.default.yellow(` - Skipping external message: ${getMessageName(message2)}(v${messageVersion})`));
4612
4649
  }
4613
4650
  const group = options.groupMessagesBy === "x-extension" ? message2.extensions().get("x-eventcatalog-group")?.value() || void 0 : void 0;
4614
4651
  if (parseChannels) {
@@ -4774,10 +4811,17 @@ var getSchemaFromMessagePart = (schema) => {
4774
4811
  var isJSONSchemaMessage = (message2) => {
4775
4812
  return getSchemaFileName(message2).endsWith(".json");
4776
4813
  };
4777
- var isServiceMessageOwner = (message2, operation) => {
4814
+ var getMessageOwnership = (message2, operation) => {
4778
4815
  const operationRole = operation?.extensions?.().get?.("x-eventcatalog-role")?.value?.();
4779
4816
  const messageRole = message2.extensions().get("x-eventcatalog-role")?.value();
4780
- const value = operationRole || messageRole || "provider";
4781
- return value === "provider";
4817
+ const explicitRole = operationRole || messageRole;
4818
+ if (explicitRole) {
4819
+ return explicitRole === "provider" ? "owner" : "external";
4820
+ }
4821
+ const action = operation?.action?.();
4822
+ if (action === "receive" || action === "subscribe") {
4823
+ return "reference";
4824
+ }
4825
+ return "owner";
4782
4826
  };
4783
4827
  //# sourceMappingURL=index.js.map