@eventcatalog/sdk 2.18.0 → 2.18.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
@@ -1320,7 +1320,25 @@ declare const _default: (path: string) => {
1320
1320
  addEventToDomain: (id: string, direction: string, message: {
1321
1321
  id: string;
1322
1322
  version: string;
1323
- fields?: string[];
1323
+ fields? /**
1324
+ * Add an event to a service by it's id.
1325
+ *
1326
+ * Optionally specify a version to add the event to a specific version of the service.
1327
+ *
1328
+ * @example
1329
+ * ```ts
1330
+ * import utils from '@eventcatalog/utils';
1331
+ *
1332
+ * const { addEventToService } = utils('/path/to/eventcatalog');
1333
+ *
1334
+ * // adds a new event (InventoryUpdatedEvent) that the InventoryService will send
1335
+ * await addEventToService('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });
1336
+ *
1337
+ * // adds a new event (OrderComplete) that the InventoryService will receive
1338
+ * await addEventToService('InventoryService', 'receives', { event: 'OrderComplete', version: '2.0.0' });
1339
+ *
1340
+ * ```
1341
+ */: string[];
1324
1342
  }, version?: string) => Promise<void>;
1325
1343
  /**
1326
1344
  * Add a command to a domain by its id.
@@ -1342,7 +1360,25 @@ declare const _default: (path: string) => {
1342
1360
  addCommandToDomain: (id: string, direction: string, message: {
1343
1361
  id: string;
1344
1362
  version: string;
1345
- fields?: string[];
1363
+ fields? /**
1364
+ * Add an event to a service by it's id.
1365
+ *
1366
+ * Optionally specify a version to add the event to a specific version of the service.
1367
+ *
1368
+ * @example
1369
+ * ```ts
1370
+ * import utils from '@eventcatalog/utils';
1371
+ *
1372
+ * const { addEventToService } = utils('/path/to/eventcatalog');
1373
+ *
1374
+ * // adds a new event (InventoryUpdatedEvent) that the InventoryService will send
1375
+ * await addEventToService('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });
1376
+ *
1377
+ * // adds a new event (OrderComplete) that the InventoryService will receive
1378
+ * await addEventToService('InventoryService', 'receives', { event: 'OrderComplete', version: '2.0.0' });
1379
+ *
1380
+ * ```
1381
+ */: string[];
1346
1382
  }, version?: string) => Promise<void>;
1347
1383
  /**
1348
1384
  * Add a query to a domain by its id.
@@ -1364,7 +1400,25 @@ declare const _default: (path: string) => {
1364
1400
  addQueryToDomain: (id: string, direction: string, message: {
1365
1401
  id: string;
1366
1402
  version: string;
1367
- fields?: string[];
1403
+ fields? /**
1404
+ * Add an event to a service by it's id.
1405
+ *
1406
+ * Optionally specify a version to add the event to a specific version of the service.
1407
+ *
1408
+ * @example
1409
+ * ```ts
1410
+ * import utils from '@eventcatalog/utils';
1411
+ *
1412
+ * const { addEventToService } = utils('/path/to/eventcatalog');
1413
+ *
1414
+ * // adds a new event (InventoryUpdatedEvent) that the InventoryService will send
1415
+ * await addEventToService('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });
1416
+ *
1417
+ * // adds a new event (OrderComplete) that the InventoryService will receive
1418
+ * await addEventToService('InventoryService', 'receives', { event: 'OrderComplete', version: '2.0.0' });
1419
+ *
1420
+ * ```
1421
+ */: string[];
1368
1422
  }, version?: string) => Promise<void>;
1369
1423
  /**
1370
1424
  * ================================
package/dist/index.d.ts CHANGED
@@ -1320,7 +1320,25 @@ declare const _default: (path: string) => {
1320
1320
  addEventToDomain: (id: string, direction: string, message: {
1321
1321
  id: string;
1322
1322
  version: string;
1323
- fields?: string[];
1323
+ fields? /**
1324
+ * Add an event to a service by it's id.
1325
+ *
1326
+ * Optionally specify a version to add the event to a specific version of the service.
1327
+ *
1328
+ * @example
1329
+ * ```ts
1330
+ * import utils from '@eventcatalog/utils';
1331
+ *
1332
+ * const { addEventToService } = utils('/path/to/eventcatalog');
1333
+ *
1334
+ * // adds a new event (InventoryUpdatedEvent) that the InventoryService will send
1335
+ * await addEventToService('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });
1336
+ *
1337
+ * // adds a new event (OrderComplete) that the InventoryService will receive
1338
+ * await addEventToService('InventoryService', 'receives', { event: 'OrderComplete', version: '2.0.0' });
1339
+ *
1340
+ * ```
1341
+ */: string[];
1324
1342
  }, version?: string) => Promise<void>;
1325
1343
  /**
1326
1344
  * Add a command to a domain by its id.
@@ -1342,7 +1360,25 @@ declare const _default: (path: string) => {
1342
1360
  addCommandToDomain: (id: string, direction: string, message: {
1343
1361
  id: string;
1344
1362
  version: string;
1345
- fields?: string[];
1363
+ fields? /**
1364
+ * Add an event to a service by it's id.
1365
+ *
1366
+ * Optionally specify a version to add the event to a specific version of the service.
1367
+ *
1368
+ * @example
1369
+ * ```ts
1370
+ * import utils from '@eventcatalog/utils';
1371
+ *
1372
+ * const { addEventToService } = utils('/path/to/eventcatalog');
1373
+ *
1374
+ * // adds a new event (InventoryUpdatedEvent) that the InventoryService will send
1375
+ * await addEventToService('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });
1376
+ *
1377
+ * // adds a new event (OrderComplete) that the InventoryService will receive
1378
+ * await addEventToService('InventoryService', 'receives', { event: 'OrderComplete', version: '2.0.0' });
1379
+ *
1380
+ * ```
1381
+ */: string[];
1346
1382
  }, version?: string) => Promise<void>;
1347
1383
  /**
1348
1384
  * Add a query to a domain by its id.
@@ -1364,7 +1400,25 @@ declare const _default: (path: string) => {
1364
1400
  addQueryToDomain: (id: string, direction: string, message: {
1365
1401
  id: string;
1366
1402
  version: string;
1367
- fields?: string[];
1403
+ fields? /**
1404
+ * Add an event to a service by it's id.
1405
+ *
1406
+ * Optionally specify a version to add the event to a specific version of the service.
1407
+ *
1408
+ * @example
1409
+ * ```ts
1410
+ * import utils from '@eventcatalog/utils';
1411
+ *
1412
+ * const { addEventToService } = utils('/path/to/eventcatalog');
1413
+ *
1414
+ * // adds a new event (InventoryUpdatedEvent) that the InventoryService will send
1415
+ * await addEventToService('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });
1416
+ *
1417
+ * // adds a new event (OrderComplete) that the InventoryService will receive
1418
+ * await addEventToService('InventoryService', 'receives', { event: 'OrderComplete', version: '2.0.0' });
1419
+ *
1420
+ * ```
1421
+ */: string[];
1368
1422
  }, version?: string) => Promise<void>;
1369
1423
  /**
1370
1424
  * ================================
package/dist/index.js CHANGED
@@ -1467,6 +1467,14 @@ var import_promises6 = __toESM(require("fs/promises"));
1467
1467
  var import_node_path8 = __toESM(require("path"));
1468
1468
  var import_node_fs3 = __toESM(require("fs"));
1469
1469
  var import_gray_matter3 = __toESM(require("gray-matter"));
1470
+ var resolveDomainWriteDirectory = async (directory, id, version) => {
1471
+ const existingResource = await findFileById(directory, id, version);
1472
+ if (!existingResource) return directory;
1473
+ const normalizedPath = existingResource.replace(/\\/g, "/");
1474
+ const lastDomainsIndex = normalizedPath.lastIndexOf("/domains/");
1475
+ if (lastDomainsIndex === -1) return directory;
1476
+ return existingResource.substring(0, lastDomainsIndex + "/domains".length);
1477
+ };
1470
1478
  var getDomain = (directory) => async (id, version) => getResource(directory, id, version, { type: "domain" });
1471
1479
  var getDomains = (directory) => async (options) => getResources(directory, {
1472
1480
  type: "domains",
@@ -1536,8 +1544,9 @@ var addServiceToDomain = (directory) => async (id, service, version) => {
1536
1544
  return;
1537
1545
  }
1538
1546
  domain.services.push(service);
1547
+ const writeDir = await resolveDomainWriteDirectory(directory, id, version);
1539
1548
  await rmDomainById(directory)(id, version, true);
1540
- await writeDomain(directory)(domain, { format: extension === ".md" ? "md" : "mdx" });
1549
+ await writeDomain(writeDir)(domain, { format: extension === ".md" ? "md" : "mdx" });
1541
1550
  };
1542
1551
  var addSubDomainToDomain = (directory) => async (id, subDomain, version) => {
1543
1552
  let domain = await getDomain(directory)(id, version);
@@ -1551,8 +1560,9 @@ var addSubDomainToDomain = (directory) => async (id, subDomain, version) => {
1551
1560
  return;
1552
1561
  }
1553
1562
  domain.domains.push(subDomain);
1563
+ const writeDir = await resolveDomainWriteDirectory(directory, id, version);
1554
1564
  await rmDomainById(directory)(id, version, true);
1555
- await writeDomain(directory)(domain, { format: extension === ".md" ? "md" : "mdx" });
1565
+ await writeDomain(writeDir)(domain, { format: extension === ".md" ? "md" : "mdx" });
1556
1566
  };
1557
1567
  var addEntityToDomain = (directory) => async (id, entity, version) => {
1558
1568
  let domain = await getDomain(directory)(id, version);
@@ -1566,8 +1576,9 @@ var addEntityToDomain = (directory) => async (id, entity, version) => {
1566
1576
  return;
1567
1577
  }
1568
1578
  domain.entities.push(entity);
1579
+ const writeDir = await resolveDomainWriteDirectory(directory, id, version);
1569
1580
  await rmDomainById(directory)(id, version, true);
1570
- await writeDomain(directory)(domain, { format: extension === ".md" ? "md" : "mdx" });
1581
+ await writeDomain(writeDir)(domain, { format: extension === ".md" ? "md" : "mdx" });
1571
1582
  };
1572
1583
  var addDataProductToDomain = (directory) => async (id, dataProduct, version) => {
1573
1584
  let domain = await getDomain(directory)(id, version);
@@ -1583,8 +1594,9 @@ var addDataProductToDomain = (directory) => async (id, dataProduct, version) =>
1583
1594
  return;
1584
1595
  }
1585
1596
  domain.dataProducts.push(dataProduct);
1597
+ const writeDir = await resolveDomainWriteDirectory(directory, id, version);
1586
1598
  await rmDomainById(directory)(id, version, true);
1587
- await writeDomain(directory)(domain, { format: extension === ".md" ? "md" : "mdx" });
1599
+ await writeDomain(writeDir)(domain, { format: extension === ".md" ? "md" : "mdx" });
1588
1600
  };
1589
1601
  var addMessageToDomain = (directory) => async (id, direction, message, version) => {
1590
1602
  let domain = await getDomain(directory)(id, version);
@@ -1613,15 +1625,9 @@ var addMessageToDomain = (directory) => async (id, direction, message, version)
1613
1625
  } else {
1614
1626
  throw new Error(`Direction ${direction} is invalid, only 'receives' and 'sends' are supported`);
1615
1627
  }
1616
- const existingResource = await findFileById(directory, id, version);
1617
- if (!existingResource) {
1618
- throw new Error(`Cannot find domain ${id} in the catalog`);
1619
- }
1620
- const normalizedPath = existingResource.replace(/\\/g, "/");
1621
- const lastDomainsIndex = normalizedPath.lastIndexOf("/domains/");
1622
- const pathToResource = existingResource.substring(0, lastDomainsIndex + "/domains".length);
1628
+ const writeDir = await resolveDomainWriteDirectory(directory, id, version);
1623
1629
  await rmDomainById(directory)(id, version, true);
1624
- await writeDomain(pathToResource)(domain, { format: extension === ".md" ? "md" : "mdx" });
1630
+ await writeDomain(writeDir)(domain, { format: extension === ".md" ? "md" : "mdx" });
1625
1631
  };
1626
1632
 
1627
1633
  // src/channels.ts