@eventcatalog/sdk 2.17.0 → 2.17.2

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
@@ -475,13 +475,7 @@ declare const _default: (path: string) => {
475
475
  writeEvent: (event: Event, options?: {
476
476
  path?: string;
477
477
  override?: boolean;
478
- versionExistingContent? /**
479
- * Adds an event to EventCatalog
480
- *
481
- * @param event - The event to write
482
- * @param options - Optional options to write the event
483
- *
484
- */: boolean;
478
+ versionExistingContent?: boolean;
485
479
  format?: "md" | "mdx";
486
480
  }) => Promise<void>;
487
481
  /**
@@ -926,14 +920,7 @@ declare const _default: (path: string) => {
926
920
  version?: string;
927
921
  direction?: string;
928
922
  }, options?: {
929
- path? /**
930
- * Adds a command to a service in EventCatalog
931
- *
932
- * @param command - The command to write to the service
933
- * @param service - The service and it's id to write to the command to
934
- * @param options - Optional options to write the command
935
- *
936
- */: string;
923
+ path?: string;
937
924
  format?: "md" | "mdx";
938
925
  override?: boolean;
939
926
  }) => Promise<void>;
@@ -1538,6 +1525,17 @@ declare const _default: (path: string) => {
1538
1525
  * @returns Service[]
1539
1526
  */
1540
1527
  getProducersOfSchema: (path: string) => Promise<Service[]>;
1528
+ /**
1529
+ * Returns the schema for a given message (event, command or query) by its id and version.
1530
+ * If no version is given, the latest version is used.
1531
+ * @param id - The id of the message to get the schema for
1532
+ * @param version - Optional version of the message
1533
+ * @returns { schema: string, fileName: string } | undefined
1534
+ */
1535
+ getSchemaForMessage: (id: string, version?: string) => Promise<{
1536
+ schema: string;
1537
+ fileName: string;
1538
+ } | undefined>;
1541
1539
  /**
1542
1540
  * Returns the owners for a given resource (e.g domain, service, event, command, query, etc.)
1543
1541
  * @param id - The id of the resource to get the owners for
@@ -1803,11 +1801,7 @@ declare const _default: (path: string) => {
1803
1801
  *
1804
1802
  */
1805
1803
  writeDiagram: (diagram: Diagram, options?: {
1806
- path? /**
1807
- * Returns all events from EventCatalog
1808
- * @param latestOnly - optional boolean, set to true to get only latest versions
1809
- * @returns Event[]|Undefined
1810
- */: string;
1804
+ path?: string;
1811
1805
  override?: boolean;
1812
1806
  versionExistingContent?: boolean;
1813
1807
  format?: "md" | "mdx";
package/dist/index.d.ts CHANGED
@@ -475,13 +475,7 @@ declare const _default: (path: string) => {
475
475
  writeEvent: (event: Event, options?: {
476
476
  path?: string;
477
477
  override?: boolean;
478
- versionExistingContent? /**
479
- * Adds an event to EventCatalog
480
- *
481
- * @param event - The event to write
482
- * @param options - Optional options to write the event
483
- *
484
- */: boolean;
478
+ versionExistingContent?: boolean;
485
479
  format?: "md" | "mdx";
486
480
  }) => Promise<void>;
487
481
  /**
@@ -926,14 +920,7 @@ declare const _default: (path: string) => {
926
920
  version?: string;
927
921
  direction?: string;
928
922
  }, options?: {
929
- path? /**
930
- * Adds a command to a service in EventCatalog
931
- *
932
- * @param command - The command to write to the service
933
- * @param service - The service and it's id to write to the command to
934
- * @param options - Optional options to write the command
935
- *
936
- */: string;
923
+ path?: string;
937
924
  format?: "md" | "mdx";
938
925
  override?: boolean;
939
926
  }) => Promise<void>;
@@ -1538,6 +1525,17 @@ declare const _default: (path: string) => {
1538
1525
  * @returns Service[]
1539
1526
  */
1540
1527
  getProducersOfSchema: (path: string) => Promise<Service[]>;
1528
+ /**
1529
+ * Returns the schema for a given message (event, command or query) by its id and version.
1530
+ * If no version is given, the latest version is used.
1531
+ * @param id - The id of the message to get the schema for
1532
+ * @param version - Optional version of the message
1533
+ * @returns { schema: string, fileName: string } | undefined
1534
+ */
1535
+ getSchemaForMessage: (id: string, version?: string) => Promise<{
1536
+ schema: string;
1537
+ fileName: string;
1538
+ } | undefined>;
1541
1539
  /**
1542
1540
  * Returns the owners for a given resource (e.g domain, service, event, command, query, etc.)
1543
1541
  * @param id - The id of the resource to get the owners for
@@ -1803,11 +1801,7 @@ declare const _default: (path: string) => {
1803
1801
  *
1804
1802
  */
1805
1803
  writeDiagram: (diagram: Diagram, options?: {
1806
- path? /**
1807
- * Returns all events from EventCatalog
1808
- * @param latestOnly - optional boolean, set to true to get only latest versions
1809
- * @returns Event[]|Undefined
1810
- */: string;
1804
+ path?: string;
1811
1805
  override?: boolean;
1812
1806
  versionExistingContent?: boolean;
1813
1807
  format?: "md" | "mdx";
package/dist/index.js CHANGED
@@ -1326,7 +1326,7 @@ var addMessageToService = (directory) => async (id, direction, event, version) =
1326
1326
  }
1327
1327
  const path8 = existingResource.split(/[\\/]+services/)[0];
1328
1328
  const pathToResource = (0, import_node_path7.join)(path8, "services");
1329
- await rmServiceById(directory)(id, version);
1329
+ await rmServiceById(directory)(id, version, true);
1330
1330
  await writeService(pathToResource)(service, { format: extension === ".md" ? "md" : "mdx" });
1331
1331
  };
1332
1332
  var serviceHasVersion = (directory) => async (id, version) => {
@@ -1359,7 +1359,7 @@ var addEntityToService = (directory) => async (id, entity, version) => {
1359
1359
  }
1360
1360
  const path8 = existingResource.split(/[\\/]+services/)[0];
1361
1361
  const pathToResource = (0, import_node_path7.join)(path8, "services");
1362
- await rmServiceById(directory)(id, version);
1362
+ await rmServiceById(directory)(id, version, true);
1363
1363
  await writeService(pathToResource)(service, { format: extension === ".md" ? "md" : "mdx" });
1364
1364
  };
1365
1365
  var addDataStoreToService = (directory) => async (id, operation, dataStore, version) => {
@@ -1395,7 +1395,7 @@ var addDataStoreToService = (directory) => async (id, operation, dataStore, vers
1395
1395
  }
1396
1396
  const path8 = existingResource.split(/[\\/]+services/)[0];
1397
1397
  const pathToResource = (0, import_node_path7.join)(path8, "services");
1398
- await rmServiceById(directory)(id, version);
1398
+ await rmServiceById(directory)(id, version, true);
1399
1399
  await writeService(pathToResource)(service, { format: extension === ".md" ? "md" : "mdx" });
1400
1400
  };
1401
1401
 
@@ -1618,6 +1618,7 @@ var addMessageToChannel = (directory, collection) => async (id, _message, versio
1618
1618
 
1619
1619
  // src/messages.ts
1620
1620
  var import_node_path10 = require("path");
1621
+ var import_node_fs4 = __toESM(require("fs"));
1621
1622
  var import_gray_matter4 = __toESM(require("gray-matter"));
1622
1623
  var import_semver5 = require("semver");
1623
1624
  var getMessageBySchemaPath = (directory) => async (path8, options) => {
@@ -1711,17 +1712,31 @@ var getProducersOfSchema = (directory) => async (path8) => {
1711
1712
  return [];
1712
1713
  }
1713
1714
  };
1715
+ var getSchemaForMessage = (directory) => async (id, version) => {
1716
+ const file = await findFileById(directory, id, version);
1717
+ if (!file || !import_node_fs4.default.existsSync(file)) return void 0;
1718
+ const { data } = import_gray_matter4.default.read(file);
1719
+ if (!data.schemaPath) return void 0;
1720
+ const resourceDirectory = (0, import_node_path10.dirname)(file);
1721
+ const pathToSchema = (0, import_node_path10.join)(resourceDirectory, data.schemaPath);
1722
+ if (!import_node_fs4.default.existsSync(pathToSchema)) return void 0;
1723
+ const schema = import_node_fs4.default.readFileSync(pathToSchema, "utf8");
1724
+ return {
1725
+ schema,
1726
+ fileName: data.schemaPath
1727
+ };
1728
+ };
1714
1729
 
1715
1730
  // src/custom-docs.ts
1716
1731
  var import_node_path11 = __toESM(require("path"));
1717
- var import_node_fs4 = __toESM(require("fs"));
1732
+ var import_node_fs5 = __toESM(require("fs"));
1718
1733
  var import_promises8 = __toESM(require("fs/promises"));
1719
1734
  var import_gray_matter5 = __toESM(require("gray-matter"));
1720
1735
  var import_slugify = __toESM(require("slugify"));
1721
1736
  var getCustomDoc = (directory) => async (filePath) => {
1722
1737
  const fullPath = import_node_path11.default.join(directory, filePath);
1723
1738
  const fullPathWithExtension = fullPath.endsWith(".mdx") ? fullPath : `${fullPath}.mdx`;
1724
- const fileExists = import_node_fs4.default.existsSync(fullPathWithExtension);
1739
+ const fileExists = import_node_fs5.default.existsSync(fullPathWithExtension);
1725
1740
  if (!fileExists) {
1726
1741
  return void 0;
1727
1742
  }
@@ -1739,9 +1754,9 @@ var writeCustomDoc = (directory) => async (customDoc, options = { path: "" }) =>
1739
1754
  const name = fileName || (0, import_slugify.default)(customDoc.title, { lower: true });
1740
1755
  const withExtension = name.endsWith(".mdx") ? name : `${name}.mdx`;
1741
1756
  const fullPath = import_node_path11.default.join(directory, options.path || "", withExtension);
1742
- import_node_fs4.default.mkdirSync(import_node_path11.default.dirname(fullPath), { recursive: true });
1757
+ import_node_fs5.default.mkdirSync(import_node_path11.default.dirname(fullPath), { recursive: true });
1743
1758
  const document = import_gray_matter5.default.stringify(customDoc.markdown.trim(), rest);
1744
- import_node_fs4.default.writeFileSync(fullPath, document);
1759
+ import_node_fs5.default.writeFileSync(fullPath, document);
1745
1760
  invalidateFileCache();
1746
1761
  };
1747
1762
  var rmCustomDoc = (directory) => async (filePath) => {
@@ -1752,13 +1767,13 @@ var rmCustomDoc = (directory) => async (filePath) => {
1752
1767
 
1753
1768
  // src/teams.ts
1754
1769
  var import_promises9 = __toESM(require("fs/promises"));
1755
- var import_node_fs6 = __toESM(require("fs"));
1770
+ var import_node_fs7 = __toESM(require("fs"));
1756
1771
  var import_node_path13 = require("path");
1757
1772
  var import_gray_matter7 = __toESM(require("gray-matter"));
1758
1773
  var import_node_path14 = __toESM(require("path"));
1759
1774
 
1760
1775
  // src/users.ts
1761
- var import_node_fs5 = __toESM(require("fs"));
1776
+ var import_node_fs6 = __toESM(require("fs"));
1762
1777
  var import_node_path12 = require("path");
1763
1778
  var import_gray_matter6 = __toESM(require("gray-matter"));
1764
1779
  var getUser = (catalogDir) => async (id) => {
@@ -1797,12 +1812,12 @@ var writeUser = (catalogDir) => async (user, options = {}) => {
1797
1812
  }
1798
1813
  const { markdown, ...frontmatter } = resource;
1799
1814
  const document = import_gray_matter6.default.stringify(markdown, frontmatter);
1800
- import_node_fs5.default.mkdirSync((0, import_node_path12.join)(catalogDir, ""), { recursive: true });
1801
- import_node_fs5.default.writeFileSync((0, import_node_path12.join)(catalogDir, "", `${resource.id}.mdx`), document);
1815
+ import_node_fs6.default.mkdirSync((0, import_node_path12.join)(catalogDir, ""), { recursive: true });
1816
+ import_node_fs6.default.writeFileSync((0, import_node_path12.join)(catalogDir, "", `${resource.id}.mdx`), document);
1802
1817
  invalidateFileCache();
1803
1818
  };
1804
1819
  var rmUserById = (catalogDir) => async (id) => {
1805
- import_node_fs5.default.rmSync((0, import_node_path12.join)(catalogDir, `${id}.mdx`), { recursive: true });
1820
+ import_node_fs6.default.rmSync((0, import_node_path12.join)(catalogDir, `${id}.mdx`), { recursive: true });
1806
1821
  invalidateFileCache();
1807
1822
  };
1808
1823
 
@@ -1841,8 +1856,8 @@ var writeTeam = (catalogDir) => async (team, options = {}) => {
1841
1856
  }
1842
1857
  const { markdown, ...frontmatter } = resource;
1843
1858
  const document = import_gray_matter7.default.stringify(markdown, frontmatter);
1844
- import_node_fs6.default.mkdirSync((0, import_node_path13.join)(catalogDir, ""), { recursive: true });
1845
- import_node_fs6.default.writeFileSync((0, import_node_path13.join)(catalogDir, "", `${resource.id}.mdx`), document);
1859
+ import_node_fs7.default.mkdirSync((0, import_node_path13.join)(catalogDir, ""), { recursive: true });
1860
+ import_node_fs7.default.writeFileSync((0, import_node_path13.join)(catalogDir, "", `${resource.id}.mdx`), document);
1846
1861
  invalidateFileCache();
1847
1862
  };
1848
1863
  var rmTeamById = (catalogDir) => async (id) => {
@@ -1966,7 +1981,7 @@ var dumpCatalog = (directory) => async (options) => {
1966
1981
  };
1967
1982
 
1968
1983
  // src/snapshots.ts
1969
- var import_node_fs7 = __toESM(require("fs"));
1984
+ var import_node_fs8 = __toESM(require("fs"));
1970
1985
  var import_node_path16 = __toESM(require("path"));
1971
1986
  var import_node_child_process = require("child_process");
1972
1987
  var import_semver6 = require("semver");
@@ -2145,7 +2160,7 @@ var computeRelationshipDiff = (snapshotA, snapshotB) => {
2145
2160
  var SNAPSHOT_VERSION = "1.0.0";
2146
2161
  var getEventCatalogVersion2 = (catalogDir) => {
2147
2162
  try {
2148
- const packageJson = import_node_fs7.default.readFileSync(import_node_path16.default.join(catalogDir, "package.json"), "utf8");
2163
+ const packageJson = import_node_fs8.default.readFileSync(import_node_path16.default.join(catalogDir, "package.json"), "utf8");
2149
2164
  const packageJsonObject = JSON.parse(packageJson);
2150
2165
  return packageJsonObject["dependencies"]?.["@eventcatalog/core"] ?? "unknown";
2151
2166
  } catch {
@@ -2223,16 +2238,16 @@ var createSnapshot = (directory) => {
2223
2238
  }
2224
2239
  };
2225
2240
  const snapshotsDir = outputDir || import_node_path16.default.join(directory, ".snapshots");
2226
- import_node_fs7.default.mkdirSync(snapshotsDir, { recursive: true });
2241
+ import_node_fs8.default.mkdirSync(snapshotsDir, { recursive: true });
2227
2242
  const fileName = `${snapshotLabel}.snapshot.json`;
2228
2243
  const filePath = import_node_path16.default.join(snapshotsDir, fileName);
2229
- import_node_fs7.default.writeFileSync(filePath, JSON.stringify(snapshot));
2244
+ import_node_fs8.default.writeFileSync(filePath, JSON.stringify(snapshot));
2230
2245
  return { filePath, snapshot };
2231
2246
  };
2232
2247
  };
2233
2248
  var diffSnapshots = (directory) => async (snapshotAPath, snapshotBPath) => {
2234
- const snapshotA = JSON.parse(import_node_fs7.default.readFileSync(snapshotAPath, "utf-8"));
2235
- const snapshotB = JSON.parse(import_node_fs7.default.readFileSync(snapshotBPath, "utf-8"));
2249
+ const snapshotA = JSON.parse(import_node_fs8.default.readFileSync(snapshotAPath, "utf-8"));
2250
+ const snapshotB = JSON.parse(import_node_fs8.default.readFileSync(snapshotBPath, "utf-8"));
2236
2251
  const resourceChanges = computeResourceDiff(snapshotA, snapshotB);
2237
2252
  const relationshipChanges = computeRelationshipDiff(snapshotA, snapshotB);
2238
2253
  const resourceCounts = { added: 0, removed: 0, modified: 0, versioned: 0 };
@@ -2257,13 +2272,13 @@ var diffSnapshots = (directory) => async (snapshotAPath, snapshotBPath) => {
2257
2272
  };
2258
2273
  var listSnapshots = (directory) => async () => {
2259
2274
  const snapshotsDir = import_node_path16.default.join(directory, ".snapshots");
2260
- if (!import_node_fs7.default.existsSync(snapshotsDir)) return [];
2261
- const files = import_node_fs7.default.readdirSync(snapshotsDir).filter((f) => f.endsWith(".snapshot.json"));
2275
+ if (!import_node_fs8.default.existsSync(snapshotsDir)) return [];
2276
+ const files = import_node_fs8.default.readdirSync(snapshotsDir).filter((f) => f.endsWith(".snapshot.json"));
2262
2277
  const snapshots = [];
2263
2278
  for (const file of files) {
2264
2279
  try {
2265
2280
  const filePath = import_node_path16.default.join(snapshotsDir, file);
2266
- const content = JSON.parse(import_node_fs7.default.readFileSync(filePath, "utf-8"));
2281
+ const content = JSON.parse(import_node_fs8.default.readFileSync(filePath, "utf-8"));
2267
2282
  snapshots.push({
2268
2283
  label: content.label,
2269
2284
  createdAt: content.createdAt,
@@ -2278,7 +2293,7 @@ var listSnapshots = (directory) => async () => {
2278
2293
 
2279
2294
  // src/changelogs.ts
2280
2295
  var import_node_path17 = __toESM(require("path"));
2281
- var import_node_fs8 = __toESM(require("fs"));
2296
+ var import_node_fs9 = __toESM(require("fs"));
2282
2297
  var import_promises10 = __toESM(require("fs/promises"));
2283
2298
  var import_gray_matter8 = __toESM(require("gray-matter"));
2284
2299
  var writeChangelog = (catalogDir) => async (id, changelog, options = {}) => {
@@ -2297,9 +2312,9 @@ var writeChangelog = (catalogDir) => async (id, changelog, options = {}) => {
2297
2312
  if (!fm.badges || fm.badges.length === 0) {
2298
2313
  delete fm.badges;
2299
2314
  }
2300
- import_node_fs8.default.mkdirSync(resourceDir, { recursive: true });
2315
+ import_node_fs9.default.mkdirSync(resourceDir, { recursive: true });
2301
2316
  const document = import_gray_matter8.default.stringify(markdown.trim(), fm);
2302
- import_node_fs8.default.writeFileSync(changelogPath, document);
2317
+ import_node_fs9.default.writeFileSync(changelogPath, document);
2303
2318
  invalidateFileCache();
2304
2319
  };
2305
2320
  var appendChangelog = (catalogDir) => async (id, changelog, options = {}) => {
@@ -2311,7 +2326,7 @@ var appendChangelog = (catalogDir) => async (id, changelog, options = {}) => {
2311
2326
  const resourceDir = (0, import_node_path17.dirname)(resourceFile);
2312
2327
  const mdxPath = import_node_path17.default.join(resourceDir, "changelog.mdx");
2313
2328
  const mdPath = import_node_path17.default.join(resourceDir, "changelog.md");
2314
- const existingPath = import_node_fs8.default.existsSync(mdxPath) ? mdxPath : import_node_fs8.default.existsSync(mdPath) ? mdPath : void 0;
2329
+ const existingPath = import_node_fs9.default.existsSync(mdxPath) ? mdxPath : import_node_fs9.default.existsSync(mdPath) ? mdPath : void 0;
2315
2330
  if (!existingPath) {
2316
2331
  return writeChangelog(catalogDir)(id, changelog, options);
2317
2332
  }
@@ -2331,7 +2346,7 @@ ${existingContent}`;
2331
2346
  delete fm.badges;
2332
2347
  }
2333
2348
  const document = import_gray_matter8.default.stringify(combined, fm);
2334
- import_node_fs8.default.writeFileSync(existingPath, document);
2349
+ import_node_fs9.default.writeFileSync(existingPath, document);
2335
2350
  invalidateFileCache();
2336
2351
  };
2337
2352
  var getChangelog = (catalogDir) => async (id, options = {}) => {
@@ -2341,7 +2356,7 @@ var getChangelog = (catalogDir) => async (id, options = {}) => {
2341
2356
  const resourceDir = (0, import_node_path17.dirname)(resourceFile);
2342
2357
  const mdxPath = import_node_path17.default.join(resourceDir, "changelog.mdx");
2343
2358
  const mdPath = import_node_path17.default.join(resourceDir, "changelog.md");
2344
- const changelogPath = import_node_fs8.default.existsSync(mdxPath) ? mdxPath : import_node_fs8.default.existsSync(mdPath) ? mdPath : void 0;
2359
+ const changelogPath = import_node_fs9.default.existsSync(mdxPath) ? mdxPath : import_node_fs9.default.existsSync(mdPath) ? mdPath : void 0;
2345
2360
  if (!changelogPath) return void 0;
2346
2361
  const { data, content } = import_gray_matter8.default.read(changelogPath);
2347
2362
  return { ...data, markdown: content.trim() };
@@ -2355,10 +2370,10 @@ var rmChangelog = (catalogDir) => async (id, options = {}) => {
2355
2370
  const resourceDir = (0, import_node_path17.dirname)(resourceFile);
2356
2371
  const mdxPath = import_node_path17.default.join(resourceDir, "changelog.mdx");
2357
2372
  const mdPath = import_node_path17.default.join(resourceDir, "changelog.md");
2358
- if (import_node_fs8.default.existsSync(mdxPath)) {
2373
+ if (import_node_fs9.default.existsSync(mdxPath)) {
2359
2374
  await import_promises10.default.rm(mdxPath);
2360
2375
  }
2361
- if (import_node_fs8.default.existsSync(mdPath)) {
2376
+ if (import_node_fs9.default.existsSync(mdPath)) {
2362
2377
  await import_promises10.default.rm(mdPath);
2363
2378
  }
2364
2379
  invalidateFileCache();
@@ -3365,6 +3380,14 @@ var src_default = (path8) => {
3365
3380
  * @returns Service[]
3366
3381
  */
3367
3382
  getProducersOfSchema: getProducersOfSchema((0, import_node_path22.join)(path8)),
3383
+ /**
3384
+ * Returns the schema for a given message (event, command or query) by its id and version.
3385
+ * If no version is given, the latest version is used.
3386
+ * @param id - The id of the message to get the schema for
3387
+ * @param version - Optional version of the message
3388
+ * @returns { schema: string, fileName: string } | undefined
3389
+ */
3390
+ getSchemaForMessage: getSchemaForMessage((0, import_node_path22.join)(path8)),
3368
3391
  /**
3369
3392
  * Returns the owners for a given resource (e.g domain, service, event, command, query, etc.)
3370
3393
  * @param id - The id of the resource to get the owners for