@eventcatalog/generator-asyncapi 4.2.1 → 4.4.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.mjs CHANGED
@@ -1051,9 +1051,9 @@ var require_src = __commonJS({
1051
1051
  }
1052
1052
  });
1053
1053
 
1054
- // ../../node_modules/.pnpm/agent-base@7.1.3/node_modules/agent-base/dist/helpers.js
1054
+ // ../../node_modules/.pnpm/agent-base@7.1.4/node_modules/agent-base/dist/helpers.js
1055
1055
  var require_helpers = __commonJS({
1056
- "../../node_modules/.pnpm/agent-base@7.1.3/node_modules/agent-base/dist/helpers.js"(exports) {
1056
+ "../../node_modules/.pnpm/agent-base@7.1.4/node_modules/agent-base/dist/helpers.js"(exports) {
1057
1057
  "use strict";
1058
1058
  var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
1059
1059
  if (k2 === void 0) k2 = k;
@@ -1121,9 +1121,9 @@ var require_helpers = __commonJS({
1121
1121
  }
1122
1122
  });
1123
1123
 
1124
- // ../../node_modules/.pnpm/agent-base@7.1.3/node_modules/agent-base/dist/index.js
1124
+ // ../../node_modules/.pnpm/agent-base@7.1.4/node_modules/agent-base/dist/index.js
1125
1125
  var require_dist = __commonJS({
1126
- "../../node_modules/.pnpm/agent-base@7.1.3/node_modules/agent-base/dist/index.js"(exports) {
1126
+ "../../node_modules/.pnpm/agent-base@7.1.4/node_modules/agent-base/dist/index.js"(exports) {
1127
1127
  "use strict";
1128
1128
  var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
1129
1129
  if (k2 === void 0) k2 = k;
@@ -1219,7 +1219,7 @@ var require_dist = __commonJS({
1219
1219
  // In order to properly update the socket pool, we need to call `getName()` on
1220
1220
  // the core `https.Agent` if it is a secureEndpoint.
1221
1221
  getName(options) {
1222
- const secureEndpoint = typeof options.secureEndpoint === "boolean" ? options.secureEndpoint : this.isSecureEndpoint(options);
1222
+ const secureEndpoint = this.isSecureEndpoint(options);
1223
1223
  if (secureEndpoint) {
1224
1224
  return https_1.Agent.prototype.getName.call(this, options);
1225
1225
  }
@@ -1536,7 +1536,7 @@ import path2 from "path";
1536
1536
  // package.json
1537
1537
  var package_default = {
1538
1538
  name: "@eventcatalog/generator-asyncapi",
1539
- version: "4.2.1",
1539
+ version: "4.4.0",
1540
1540
  description: "AsyncAPI generator for EventCatalog",
1541
1541
  scripts: {
1542
1542
  build: "tsup",
@@ -1574,7 +1574,7 @@ var package_default = {
1574
1574
  dependencies: {
1575
1575
  "@asyncapi/avro-schema-parser": "^3.0.24",
1576
1576
  "@asyncapi/parser": "^3.3.0",
1577
- "@eventcatalog/sdk": "^2.5.5",
1577
+ "@eventcatalog/sdk": "^2.6.9",
1578
1578
  chalk: "^4",
1579
1579
  "fs-extra": "^11.2.0",
1580
1580
  glob: "^11.0.0",
@@ -2656,16 +2656,50 @@ var optionsSchema = z.object({
2656
2656
  z.object({
2657
2657
  id: z.string({ required_error: "The service id is required. please provide the service id" }),
2658
2658
  path: z.string({ required_error: "The service path is required. please provide the path to specification file" }),
2659
+ draft: z.boolean().optional(),
2659
2660
  name: z.string().optional(),
2660
- owners: z.array(z.string()).optional()
2661
+ owners: z.array(z.string()).optional(),
2662
+ generateMarkdown: z.function().args(
2663
+ z.object({
2664
+ service: z.object({
2665
+ id: z.string(),
2666
+ name: z.string(),
2667
+ version: z.string()
2668
+ }),
2669
+ // AsyncAPI Interface
2670
+ document: z.any(),
2671
+ markdown: z.string().optional()
2672
+ })
2673
+ ).returns(z.string()).optional()
2661
2674
  }),
2662
2675
  { message: "Please provide correct services configuration" }
2663
2676
  ),
2677
+ messages: z.object({
2678
+ generateMarkdown: z.function().args(
2679
+ z.object({
2680
+ message: z.any(),
2681
+ document: z.any(),
2682
+ markdown: z.string().optional()
2683
+ })
2684
+ ).returns(z.string()).optional()
2685
+ }).optional(),
2664
2686
  domain: z.object({
2665
2687
  id: z.string({ required_error: "The domain id is required. please provide a domain id" }),
2666
2688
  name: z.string({ required_error: "The domain name is required. please provide a domain name" }),
2667
2689
  owners: z.array(z.string()).optional(),
2668
- version: z.string({ required_error: "The domain version is required. please provide a domain version" })
2690
+ version: z.string({ required_error: "The domain version is required. please provide a domain version" }),
2691
+ draft: z.boolean().optional(),
2692
+ // function that takes options (including domain) and returns a string
2693
+ generateMarkdown: z.function().args(
2694
+ z.object({
2695
+ domain: z.object({
2696
+ id: z.string(),
2697
+ name: z.string(),
2698
+ version: z.string()
2699
+ }),
2700
+ markdown: z.string().optional()
2701
+ })
2702
+ ).returns(z.string()).optional()
2669
2703
  }).optional(),
2670
2704
  debug: z.boolean().optional(),
2671
2705
  parseSchemas: z.boolean().optional(),
@@ -2760,6 +2794,8 @@ var index_default = async (config, options) => {
2760
2794
  const operations = document2.allOperations();
2761
2795
  const channels = document2.allChannels();
2762
2796
  const documentTags = document2.info().tags().all() || [];
2797
+ const isDomainMarkedAsDraft = options.domain?.draft || false;
2798
+ const isServiceMarkedAsDraft = isDomainMarkedAsDraft || document2.info().extensions().get("x-eventcatalog-draft")?.value() || service.draft || false;
2763
2799
  const serviceId = service.id;
2764
2800
  const serviceName = service.name || document2.info().title();
2765
2801
  const version = document2.info().version();
@@ -2769,7 +2805,12 @@ var index_default = async (config, options) => {
2769
2805
  let repository = null;
2770
2806
  let serviceSpecifications = {};
2771
2807
  let serviceSpecificationsFiles = [];
2772
- let serviceMarkdown = defaultMarkdown2(document2);
2808
+ const generatedMarkdownForService = defaultMarkdown2(document2);
2809
+ let serviceMarkdown = service.generateMarkdown ? service.generateMarkdown({
2810
+ service: { id: service.id, name: serviceName, version },
2811
+ document: document2,
2812
+ markdown: generatedMarkdownForService
2813
+ }) : generatedMarkdownForService;
2773
2814
  let styles2 = null;
2774
2815
  let servicePath = options.domain ? path2.join("../", "domains", options.domain.id, "services", service.id) : path2.join("../", "services", service.id);
2775
2816
  if (options.writeFilesToRoot) {
@@ -2779,6 +2820,7 @@ var index_default = async (config, options) => {
2779
2820
  const { id: domainId, name: domainName, version: domainVersion, owners: domainOwners } = options.domain;
2780
2821
  const domain = await getDomain(options.domain.id, domainVersion || "latest");
2781
2822
  const currentDomain = await getDomain(options.domain.id, "latest");
2823
+ const domainIsDraft = isDomainMarkedAsDraft || currentDomain?.draft || false;
2782
2824
  console.log(chalk3.blue(`
2783
2825
  Processing domain: ${domainName} (v${domainVersion})`));
2784
2826
  if (currentDomain && currentDomain.version !== domainVersion) {
@@ -2786,12 +2828,14 @@ Processing domain: ${domainName} (v${domainVersion})`));
2786
2828
  console.log(chalk3.cyan(` - Versioned previous domain (v${currentDomain.version})`));
2787
2829
  }
2788
2830
  if (!domain || domain && domain.version !== domainVersion) {
2831
+ const generatedMarkdownForDomain = defaultMarkdown3(document2);
2789
2832
  await writeDomain({
2790
2833
  id: domainId,
2791
2834
  name: domainName,
2792
2835
  version: domainVersion,
2793
- markdown: defaultMarkdown3(document2),
2794
- ...domainOwners && { owners: domainOwners }
2836
+ markdown: options.domain?.generateMarkdown ? options.domain.generateMarkdown({ domain: options.domain, markdown: generatedMarkdownForDomain }) : generatedMarkdownForDomain,
2837
+ ...domainOwners && { owners: domainOwners },
2838
+ ...domainIsDraft && { draft: true }
2795
2839
  // services: [{ id: serviceId, version: version }],
2796
2840
  });
2797
2841
  console.log(chalk3.cyan(` - Domain (v${domainVersion}) created`));
@@ -2839,7 +2883,8 @@ Processing domain: ${domainName} (v${domainVersion})`));
2839
2883
  ...Object.keys(paramsForCatalog).length > 0 && { parameters: paramsForCatalog },
2840
2884
  ...channel.address() && { address: channel.address() },
2841
2885
  ...channelAsJSON?.summary && { summary: channelAsJSON.summary },
2842
- ...protocols.length > 0 && { protocols }
2886
+ ...protocols.length > 0 && { protocols },
2887
+ ...(isDomainMarkedAsDraft || isServiceMarkedAsDraft) && { draft: true }
2843
2888
  },
2844
2889
  { override: true }
2845
2890
  );
@@ -2852,6 +2897,7 @@ Processing domain: ${domainName} (v${domainVersion})`));
2852
2897
  const messageVersion = message.extensions().get("x-eventcatalog-message-version")?.value() || version;
2853
2898
  const deprecatedDate = message.extensions().get("x-eventcatalog-deprecated-date")?.value() || null;
2854
2899
  const deprecatedMessage = message.extensions().get("x-eventcatalog-deprecated-message")?.value() || null;
2900
+ const isMessageMarkedAsDraft = isDomainMarkedAsDraft || isServiceMarkedAsDraft || message.extensions().get("x-eventcatalog-draft")?.value() || null;
2855
2901
  const serviceOwnsMessageContract = isServiceMessageOwner(message);
2856
2902
  const isReceived = operation.action() === "receive" || operation.action() === "subscribe";
2857
2903
  const isSent = operation.action() === "send" || operation.action() === "publish";
@@ -2866,7 +2912,8 @@ Processing domain: ${domainName} (v${domainVersion})`));
2866
2912
  addSchema: addSchemaToMessage,
2867
2913
  collection: folder
2868
2914
  } = MESSAGE_OPERATIONS[eventType];
2869
- let messageMarkdown = defaultMarkdown(document2, message);
2915
+ const generatedMarkdownForMessage = defaultMarkdown(document2, message);
2916
+ let messageMarkdown = options.messages?.generateMarkdown ? options.messages.generateMarkdown({ message, document: document2, markdown: generatedMarkdownForMessage }) : generatedMarkdownForMessage;
2870
2917
  const badges = message.tags().all() || [];
2871
2918
  console.log(chalk3.blue(`Processing message: ${getMessageName(message)} (v${messageVersion})`));
2872
2919
  let messagePath = join(servicePath, folder, message.id());
@@ -2896,7 +2943,8 @@ Processing domain: ${domainName} (v${domainVersion})`));
2896
2943
  ...channelsForMessage.length > 0 && { channels: channelsForMessage },
2897
2944
  ...deprecatedDate && {
2898
2945
  deprecated: { date: deprecatedDate, ...deprecatedMessage && { message: deprecatedMessage } }
2899
- }
2946
+ },
2947
+ ...isMessageMarkedAsDraft && { draft: true }
2900
2948
  },
2901
2949
  {
2902
2950
  override: true,
@@ -2963,7 +3011,8 @@ Processing domain: ${domainName} (v${domainVersion})`));
2963
3011
  },
2964
3012
  ...owners && { owners },
2965
3013
  ...repository && { repository },
2966
- ...styles2 && { styles: styles2 }
3014
+ ...styles2 && { styles: styles2 },
3015
+ ...isServiceMarkedAsDraft && { draft: true }
2967
3016
  },
2968
3017
  {
2969
3018
  path: servicePath,