@eventcatalog/sdk 2.8.1 → 2.8.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/dist/index.mjs CHANGED
@@ -571,6 +571,42 @@ var addEntityToService = (directory) => async (id, entity, version) => {
571
571
  await rmServiceById(directory)(id, version);
572
572
  await writeService(pathToResource)(service, { format: extension === ".md" ? "md" : "mdx" });
573
573
  };
574
+ var addDataStoreToService = (directory) => async (id, operation, dataStore, version) => {
575
+ let service = await getService(directory)(id, version);
576
+ const servicePath = await getResourcePath(directory, id, version);
577
+ const extension = extname(servicePath?.fullPath || "");
578
+ if (operation === "writesTo") {
579
+ if (service.writesTo === void 0) {
580
+ service.writesTo = [];
581
+ }
582
+ for (let i = 0; i < service.writesTo.length; i++) {
583
+ if (service.writesTo[i].id === dataStore.id && service.writesTo[i].version === dataStore.version) {
584
+ return;
585
+ }
586
+ }
587
+ service.writesTo.push({ id: dataStore.id, version: dataStore.version });
588
+ } else if (operation === "readsFrom") {
589
+ if (service.readsFrom === void 0) {
590
+ service.readsFrom = [];
591
+ }
592
+ for (let i = 0; i < service.readsFrom.length; i++) {
593
+ if (service.readsFrom[i].id === dataStore.id && service.readsFrom[i].version === dataStore.version) {
594
+ return;
595
+ }
596
+ }
597
+ service.readsFrom.push({ id: dataStore.id, version: dataStore.version });
598
+ } else {
599
+ throw new Error(`Operation ${operation} is invalid, only 'writesTo' and 'readsFrom' are supported`);
600
+ }
601
+ const existingResource = await findFileById(directory, id, version);
602
+ if (!existingResource) {
603
+ throw new Error(`Cannot find service ${id} in the catalog`);
604
+ }
605
+ const path5 = existingResource.split(/[\\/]+services/)[0];
606
+ const pathToResource = join6(path5, "services");
607
+ await rmServiceById(directory)(id, version);
608
+ await writeService(pathToResource)(service, { format: extension === ".md" ? "md" : "mdx" });
609
+ };
574
610
 
575
611
  // src/domains.ts
576
612
  import fs6 from "fs/promises";
@@ -1121,6 +1157,17 @@ var writeContainerToService = (directory) => async (container, service, options
1121
1157
  await writeResource(directory, { ...container }, { ...options, path: pathForContainer, type: "container" });
1122
1158
  };
1123
1159
 
1160
+ // src/data-stores.ts
1161
+ var getDataStore = getContainer;
1162
+ var getDataStores = getContainers;
1163
+ var writeDataStore = writeContainer;
1164
+ var versionDataStore = versionContainer;
1165
+ var rmDataStore = rmContainer;
1166
+ var rmDataStoreById = rmContainerById;
1167
+ var dataStoreHasVersion = containerHasVersion;
1168
+ var addFileToDataStore = addFileToContainer;
1169
+ var writeDataStoreToService = writeContainerToService;
1170
+
1124
1171
  // src/index.ts
1125
1172
  var index_default = (path5) => {
1126
1173
  return {
@@ -1562,6 +1609,23 @@ var index_default = (path5) => {
1562
1609
  * ```
1563
1610
  */
1564
1611
  addEventToService: addMessageToService(join16(path5)),
1612
+ /**
1613
+ * Add a data store to a service by it's id.
1614
+ *
1615
+ * Optionally specify a version to add the data store to a specific version of the service.
1616
+ *
1617
+ * @example
1618
+ * ```ts
1619
+ * import utils from '@eventcatalog/utils';
1620
+ *
1621
+ * const { addDataStoreToService } = utils('/path/to/eventcatalog');
1622
+ *
1623
+ * // adds a new data store (orders-db) that the InventoryService will write to
1624
+ * await addDataStoreToService('InventoryService', 'writesTo', { id: 'orders-db', version: '2.0.0' });
1625
+ *
1626
+ * ```
1627
+ */
1628
+ addDataStoreToService: addDataStoreToService(join16(path5)),
1565
1629
  /**
1566
1630
  * Add a command to a service by it's id.
1567
1631
  *
@@ -1957,42 +2021,42 @@ var index_default = (path5) => {
1957
2021
  * @param options - Optional options to write the data store
1958
2022
  *
1959
2023
  */
1960
- writeDataStore: writeContainer(join16(path5, "containers")),
2024
+ writeDataStore: writeDataStore(join16(path5, "containers")),
1961
2025
  /**
1962
- * Returns a container from EventCatalog
1963
- * @param id - The id of the container to retrieve
2026
+ * Returns a data store from EventCatalog
2027
+ * @param id - The id of the data store to retrieve
1964
2028
  * @param version - Optional id of the version to get (supports semver)
1965
2029
  * @returns Container|Undefined
1966
2030
  */
1967
- getDataStore: getContainer(join16(path5)),
2031
+ getDataStore: getDataStore(join16(path5)),
1968
2032
  /**
1969
2033
  * Returns all data stores from EventCatalog
1970
2034
  * @param latestOnly - optional boolean, set to true to get only latest versions
1971
2035
  * @returns Container[]|Undefined
1972
2036
  */
1973
- getDataStores: getContainers(join16(path5)),
2037
+ getDataStores: getDataStores(join16(path5)),
1974
2038
  /**
1975
2039
  * Version a data store by its id
1976
2040
  * @param id - The id of the data store to version
1977
2041
  */
1978
- versionDataStore: versionContainer(join16(path5, "containers")),
2042
+ versionDataStore: versionDataStore(join16(path5, "containers")),
1979
2043
  /**
1980
2044
  * Remove a data store by its path
1981
2045
  * @param path - The path to the data store to remove
1982
2046
  */
1983
- rmDataStore: rmContainer(join16(path5, "containers")),
2047
+ rmDataStore: rmDataStore(join16(path5, "containers")),
1984
2048
  /**
1985
2049
  * Remove a data store by its id
1986
2050
  * @param id - The id of the data store to remove
1987
2051
  */
1988
- rmDataStoreById: rmContainerById(join16(path5)),
2052
+ rmDataStoreById: rmDataStoreById(join16(path5)),
1989
2053
  /**
1990
2054
  * Check to see if a data store version exists
1991
2055
  * @param id - The id of the data store
1992
2056
  * @param version - The version of the data store (supports semver)
1993
2057
  * @returns
1994
2058
  */
1995
- dataStoreHasVersion: containerHasVersion(join16(path5)),
2059
+ dataStoreHasVersion: dataStoreHasVersion(join16(path5)),
1996
2060
  /**
1997
2061
  * Adds a file to a data store by its id
1998
2062
  * @param id - The id of the data store to add the file to
@@ -2000,14 +2064,14 @@ var index_default = (path5) => {
2000
2064
  * @param version - Optional version of the data store to add the file to
2001
2065
  * @returns
2002
2066
  */
2003
- addFileToDataStore: addFileToContainer(join16(path5)),
2067
+ addFileToDataStore: addFileToDataStore(join16(path5)),
2004
2068
  /**
2005
2069
  * Writes a data store to a service by its id
2006
2070
  * @param dataStore - The data store to write
2007
2071
  * @param service - The service to write the data store to
2008
2072
  * @returns
2009
2073
  */
2010
- writeDataStoreToService: writeContainerToService(join16(path5))
2074
+ writeDataStoreToService: writeDataStoreToService(join16(path5))
2011
2075
  };
2012
2076
  };
2013
2077
  export {