@eventcatalog/sdk 2.4.0 → 2.5.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.mjs CHANGED
@@ -631,101 +631,14 @@ var addMessageToChannel = (directory, collection) => async (id, _message, versio
631
631
  await writeMessage(pathToResource)(message, { format: extension === ".md" ? "md" : "mdx" });
632
632
  };
633
633
 
634
- // src/eventcatalog.ts
635
- import fs8 from "fs";
636
- import path2, { join as join9 } from "path";
637
- var DUMP_VERSION = "0.0.1";
638
- var getEventCatalogVersion = async (catalogDir) => {
639
- try {
640
- const packageJson = fs8.readFileSync(join9(catalogDir, "package.json"), "utf8");
641
- const packageJsonObject = JSON.parse(packageJson);
642
- return packageJsonObject["dependencies"]["@eventcatalog/core"];
643
- } catch (error) {
644
- return "unknown";
645
- }
646
- };
647
- var hydrateResource = async (catalogDir, resources, { attachSchema = false } = {}) => {
648
- return await Promise.all(
649
- resources.map(async (resource) => {
650
- const resourcePath = await getResourcePath(catalogDir, resource.id, resource.version);
651
- let schema = "";
652
- if (resource.schemaPath && resourcePath?.fullPath) {
653
- const pathToSchema = path2.join(path2.dirname(resourcePath?.fullPath), resource.schemaPath);
654
- if (fs8.existsSync(pathToSchema)) {
655
- schema = fs8.readFileSync(pathToSchema, "utf8");
656
- }
657
- }
658
- const eventcatalog = schema ? { directory: resourcePath?.directory, schema } : { directory: resourcePath?.directory };
659
- return {
660
- ...resource,
661
- _eventcatalog: eventcatalog
662
- };
663
- })
664
- );
665
- };
666
- var filterCollection = (collection, options) => {
667
- return collection.map((item) => ({
668
- ...item,
669
- markdown: options?.includeMarkdown ? item.markdown : void 0
670
- }));
671
- };
672
- var dumpCatalog = (directory) => async (options) => {
673
- const { getDomains: getDomains2, getServices: getServices2, getEvents: getEvents2, getQueries: getQueries2, getCommands: getCommands2, getChannels: getChannels2, getTeams: getTeams2, getUsers: getUsers2 } = index_default(directory);
674
- const { includeMarkdown = true } = options || {};
675
- const domains = await getDomains2();
676
- const services = await getServices2();
677
- const events = await getEvents2();
678
- const commands = await getCommands2();
679
- const queries = await getQueries2();
680
- const teams = await getTeams2();
681
- const users = await getUsers2();
682
- const channels = await getChannels2();
683
- const [
684
- hydratedDomains,
685
- hydratedServices,
686
- hydratedEvents,
687
- hydratedQueries,
688
- hydratedCommands,
689
- hydratedTeams,
690
- hydratedUsers,
691
- hydratedChannels
692
- ] = await Promise.all([
693
- hydrateResource(directory, domains),
694
- hydrateResource(directory, services),
695
- hydrateResource(directory, events),
696
- hydrateResource(directory, queries),
697
- hydrateResource(directory, commands),
698
- hydrateResource(directory, teams),
699
- hydrateResource(directory, users),
700
- hydrateResource(directory, channels)
701
- ]);
702
- return {
703
- version: DUMP_VERSION,
704
- catalogVersion: await getEventCatalogVersion(directory),
705
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
706
- resources: {
707
- domains: filterCollection(hydratedDomains, { includeMarkdown }),
708
- services: filterCollection(hydratedServices, { includeMarkdown }),
709
- messages: {
710
- events: filterCollection(hydratedEvents, { includeMarkdown }),
711
- queries: filterCollection(hydratedQueries, { includeMarkdown }),
712
- commands: filterCollection(hydratedCommands, { includeMarkdown })
713
- },
714
- teams: filterCollection(hydratedTeams, { includeMarkdown }),
715
- users: filterCollection(hydratedUsers, { includeMarkdown }),
716
- channels: filterCollection(hydratedChannels, { includeMarkdown })
717
- }
718
- };
719
- };
720
-
721
634
  // src/custom-docs.ts
722
- import path3, { join as join10 } from "path";
635
+ import path2, { join as join9 } from "path";
723
636
  import fsSync4 from "fs";
724
- import fs9 from "fs/promises";
637
+ import fs8 from "fs/promises";
725
638
  import matter4 from "gray-matter";
726
639
  import slugify from "slugify";
727
640
  var getCustomDoc = (directory) => async (filePath) => {
728
- const fullPath = path3.join(directory, filePath);
641
+ const fullPath = path2.join(directory, filePath);
729
642
  const fullPathWithExtension = fullPath.endsWith(".mdx") ? fullPath : `${fullPath}.mdx`;
730
643
  const fileExists = fsSync4.existsSync(fullPathWithExtension);
731
644
  if (!fileExists) {
@@ -744,20 +657,20 @@ var writeCustomDoc = (directory) => async (customDoc, options = { path: "" }) =>
744
657
  const { fileName, ...rest } = customDoc;
745
658
  const name = fileName || slugify(customDoc.title, { lower: true });
746
659
  const withExtension = name.endsWith(".mdx") ? name : `${name}.mdx`;
747
- const fullPath = path3.join(directory, options.path || "", withExtension);
748
- fsSync4.mkdirSync(path3.dirname(fullPath), { recursive: true });
660
+ const fullPath = path2.join(directory, options.path || "", withExtension);
661
+ fsSync4.mkdirSync(path2.dirname(fullPath), { recursive: true });
749
662
  const document = matter4.stringify(customDoc.markdown.trim(), rest);
750
663
  fsSync4.writeFileSync(fullPath, document);
751
664
  };
752
665
  var rmCustomDoc = (directory) => async (filePath) => {
753
666
  const withExtension = filePath.endsWith(".mdx") ? filePath : `${filePath}.mdx`;
754
- await fs9.rm(join10(directory, withExtension), { recursive: true });
667
+ await fs8.rm(join9(directory, withExtension), { recursive: true });
755
668
  };
756
669
 
757
670
  // src/teams.ts
758
- import fs10 from "fs/promises";
671
+ import fs9 from "fs/promises";
759
672
  import fsSync5 from "fs";
760
- import { join as join11 } from "path";
673
+ import { join as join10 } from "path";
761
674
  import matter5 from "gray-matter";
762
675
  var getTeam = (catalogDir) => async (id) => {
763
676
  const files = await getFiles(`${catalogDir}/${id}.{md,mdx}`);
@@ -793,16 +706,16 @@ var writeTeam = (catalogDir) => async (team, options = {}) => {
793
706
  }
794
707
  const { markdown, ...frontmatter } = resource;
795
708
  const document = matter5.stringify(markdown, frontmatter);
796
- fsSync5.mkdirSync(join11(catalogDir, ""), { recursive: true });
797
- fsSync5.writeFileSync(join11(catalogDir, "", `${resource.id}.mdx`), document);
709
+ fsSync5.mkdirSync(join10(catalogDir, ""), { recursive: true });
710
+ fsSync5.writeFileSync(join10(catalogDir, "", `${resource.id}.mdx`), document);
798
711
  };
799
712
  var rmTeamById = (catalogDir) => async (id) => {
800
- await fs10.rm(join11(catalogDir, `${id}.mdx`), { recursive: true });
713
+ await fs9.rm(join10(catalogDir, `${id}.mdx`), { recursive: true });
801
714
  };
802
715
 
803
716
  // src/users.ts
804
717
  import fsSync6 from "fs";
805
- import { join as join12 } from "path";
718
+ import { join as join11 } from "path";
806
719
  import matter6 from "gray-matter";
807
720
  var getUser = (catalogDir) => async (id) => {
808
721
  const files = await getFiles(`${catalogDir}/${id}.{md,mdx}`);
@@ -840,11 +753,108 @@ var writeUser = (catalogDir) => async (user, options = {}) => {
840
753
  }
841
754
  const { markdown, ...frontmatter } = resource;
842
755
  const document = matter6.stringify(markdown, frontmatter);
843
- fsSync6.mkdirSync(join12(catalogDir, ""), { recursive: true });
844
- fsSync6.writeFileSync(join12(catalogDir, "", `${resource.id}.mdx`), document);
756
+ fsSync6.mkdirSync(join11(catalogDir, ""), { recursive: true });
757
+ fsSync6.writeFileSync(join11(catalogDir, "", `${resource.id}.mdx`), document);
845
758
  };
846
759
  var rmUserById = (catalogDir) => async (id) => {
847
- fsSync6.rmSync(join12(catalogDir, `${id}.mdx`), { recursive: true });
760
+ fsSync6.rmSync(join11(catalogDir, `${id}.mdx`), { recursive: true });
761
+ };
762
+
763
+ // src/eventcatalog.ts
764
+ import fs10 from "fs";
765
+ import path3, { join as join12 } from "path";
766
+ var DUMP_VERSION = "0.0.1";
767
+ var getEventCatalogVersion = async (catalogDir) => {
768
+ try {
769
+ const packageJson = fs10.readFileSync(join12(catalogDir, "package.json"), "utf8");
770
+ const packageJsonObject = JSON.parse(packageJson);
771
+ return packageJsonObject["dependencies"]["@eventcatalog/core"];
772
+ } catch (error) {
773
+ return "unknown";
774
+ }
775
+ };
776
+ var hydrateResource = async (catalogDir, resources, { attachSchema = false } = {}) => {
777
+ return await Promise.all(
778
+ resources.map(async (resource) => {
779
+ const resourcePath = await getResourcePath(catalogDir, resource.id, resource.version);
780
+ let schema = "";
781
+ if (resource.schemaPath && resourcePath?.fullPath) {
782
+ const pathToSchema = path3.join(path3.dirname(resourcePath?.fullPath), resource.schemaPath);
783
+ if (fs10.existsSync(pathToSchema)) {
784
+ schema = fs10.readFileSync(pathToSchema, "utf8");
785
+ }
786
+ }
787
+ const eventcatalog = schema ? { directory: resourcePath?.directory, schema } : { directory: resourcePath?.directory };
788
+ return {
789
+ ...resource,
790
+ _eventcatalog: eventcatalog
791
+ };
792
+ })
793
+ );
794
+ };
795
+ var filterCollection = (collection, options) => {
796
+ return collection.map((item) => ({
797
+ ...item,
798
+ markdown: options?.includeMarkdown ? item.markdown : void 0
799
+ }));
800
+ };
801
+ var getEventCatalogConfigurationFile = (directory) => async () => {
802
+ try {
803
+ const path4 = join12(directory, "eventcatalog.config.js");
804
+ const configModule = await import(path4);
805
+ return configModule.default;
806
+ } catch (error) {
807
+ console.error("Error getting event catalog configuration file", error);
808
+ return null;
809
+ }
810
+ };
811
+ var dumpCatalog = (directory) => async (options) => {
812
+ const { getDomains: getDomains2, getServices: getServices2, getEvents: getEvents2, getQueries: getQueries2, getCommands: getCommands2, getChannels: getChannels2, getTeams: getTeams2, getUsers: getUsers2 } = index_default(directory);
813
+ const { includeMarkdown = true } = options || {};
814
+ const domains = await getDomains2();
815
+ const services = await getServices2();
816
+ const events = await getEvents2();
817
+ const commands = await getCommands2();
818
+ const queries = await getQueries2();
819
+ const teams = await getTeams2();
820
+ const users = await getUsers2();
821
+ const channels = await getChannels2();
822
+ const [
823
+ hydratedDomains,
824
+ hydratedServices,
825
+ hydratedEvents,
826
+ hydratedQueries,
827
+ hydratedCommands,
828
+ hydratedTeams,
829
+ hydratedUsers,
830
+ hydratedChannels
831
+ ] = await Promise.all([
832
+ hydrateResource(directory, domains),
833
+ hydrateResource(directory, services),
834
+ hydrateResource(directory, events),
835
+ hydrateResource(directory, queries),
836
+ hydrateResource(directory, commands),
837
+ hydrateResource(directory, teams),
838
+ hydrateResource(directory, users),
839
+ hydrateResource(directory, channels)
840
+ ]);
841
+ return {
842
+ version: DUMP_VERSION,
843
+ catalogVersion: await getEventCatalogVersion(directory),
844
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
845
+ resources: {
846
+ domains: filterCollection(hydratedDomains, { includeMarkdown }),
847
+ services: filterCollection(hydratedServices, { includeMarkdown }),
848
+ messages: {
849
+ events: filterCollection(hydratedEvents, { includeMarkdown }),
850
+ queries: filterCollection(hydratedQueries, { includeMarkdown }),
851
+ commands: filterCollection(hydratedCommands, { includeMarkdown })
852
+ },
853
+ teams: filterCollection(hydratedTeams, { includeMarkdown }),
854
+ users: filterCollection(hydratedUsers, { includeMarkdown }),
855
+ channels: filterCollection(hydratedChannels, { includeMarkdown })
856
+ }
857
+ };
848
858
  };
849
859
 
850
860
  // src/index.ts
@@ -1510,6 +1520,14 @@ var index_default = (path4) => {
1510
1520
  * @returns A JSON file with the catalog
1511
1521
  */
1512
1522
  dumpCatalog: dumpCatalog(join13(path4)),
1523
+ /**
1524
+ * Returns the event catalog configuration file.
1525
+ * The event catalog configuration file is the file that contains the configuration for the event catalog.
1526
+ *
1527
+ * @param directory - The directory of the catalog.
1528
+ * @returns A JSON object with the configuration for the event catalog.
1529
+ */
1530
+ getEventCatalogConfigurationFile: getEventCatalogConfigurationFile(join13(path4)),
1513
1531
  /**
1514
1532
  * ================================
1515
1533
  * Resources Utils