@eventcatalog/sdk 1.2.3 → 1.3.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.js CHANGED
@@ -75,9 +75,9 @@ var findFileById = async (catalogDir, id, version) => {
75
75
  return match[0].path;
76
76
  }
77
77
  };
78
- var getFiles = async (pattern) => {
78
+ var getFiles = async (pattern, ignore = "") => {
79
79
  try {
80
- const files = await (0, import_glob.glob)(pattern, { ignore: "node_modules/**" });
80
+ const files = await (0, import_glob.glob)(pattern, { ignore: ["node_modules/**", ignore] });
81
81
  return files;
82
82
  } catch (error) {
83
83
  throw new Error(`Error finding files: ${error}`);
@@ -189,6 +189,18 @@ var getResource = async (catalogDir, id, version, options) => {
189
189
  markdown: content.trim()
190
190
  };
191
191
  };
192
+ var getResources = async (catalogDir, { type, latestOnly = false }) => {
193
+ const ignore = latestOnly ? `**/versioned/**` : "";
194
+ const files = await getFiles(`${catalogDir}/**/${type}/**/index.md`, ignore);
195
+ if (files.length === 0) return;
196
+ return files.map((file) => {
197
+ const { data, content } = import_gray_matter2.default.read(file);
198
+ return {
199
+ ...data,
200
+ markdown: content.trim()
201
+ };
202
+ });
203
+ };
192
204
  var rmResourceById = async (catalogDir, id, version, options) => {
193
205
  const files = await getFiles(`${catalogDir}/**/index.md`);
194
206
  const matchedFiles = await searchFilesForId(files, id, version);
@@ -215,6 +227,7 @@ var getVersionedDirectory = (sourceDirectory, version) => {
215
227
 
216
228
  // src/events.ts
217
229
  var getEvent = (directory) => async (id, version) => getResource(directory, id, version, { type: "event" });
230
+ var getEvents = (directory) => async (options) => getResources(directory, { type: "events", ...options });
218
231
  var writeEvent = (directory) => async (event, options = { path: "", override: false }) => writeResource(directory, { ...event }, { ...options, type: "event" });
219
232
  var writeEventToService = (directory) => async (event, service, options = { path: "" }) => {
220
233
  let pathForEvent = service.version && service.version !== "latest" ? `/${service.id}/versioned/${service.version}/events` : `/${service.id}/events`;
@@ -241,6 +254,7 @@ var eventHasVersion = (directory) => async (id, version) => {
241
254
  var import_promises4 = __toESM(require("fs/promises"));
242
255
  var import_node_path3 = require("path");
243
256
  var getCommand = (directory) => async (id, version) => getResource(directory, id, version, { type: "command" });
257
+ var getCommands = (directory) => async (options) => getResources(directory, { type: "commands", ...options });
244
258
  var writeCommand = (directory) => async (command, options = { path: "" }) => writeResource(directory, { ...command }, { ...options, type: "command" });
245
259
  var writeCommandToService = (directory) => async (command, service, options = { path: "" }) => {
246
260
  let pathForEvent = service.version && service.version !== "latest" ? `/${service.id}/versioned/${service.version}/commands` : `/${service.id}/commands`;
@@ -266,6 +280,7 @@ var import_promises5 = __toESM(require("fs/promises"));
266
280
  var import_node_path4 = require("path");
267
281
  var getQuery = (directory) => async (id, version) => getResource(directory, id, version, { type: "query" });
268
282
  var writeQuery = (directory) => async (query, options = { path: "" }) => writeResource(directory, { ...query }, { ...options, type: "query" });
283
+ var getQueries = (directory) => async (options) => getResources(directory, { type: "queries", ...options });
269
284
  var writeQueryToService = (directory) => async (query, service, options = { path: "" }) => {
270
285
  let pathForQuery = service.version && service.version !== "latest" ? `/${service.id}/versioned/${service.version}/queries` : `/${service.id}/queries`;
271
286
  pathForQuery = (0, import_node_path4.join)(pathForQuery, query.id);
@@ -291,6 +306,7 @@ var queryHasVersion = (directory) => async (id, version) => {
291
306
  var import_promises6 = __toESM(require("fs/promises"));
292
307
  var import_node_path5 = require("path");
293
308
  var getService = (directory) => async (id, version) => getResource(directory, id, version, { type: "service" });
309
+ var getServices = (directory) => async (options) => getResources(directory, { type: "services", ...options });
294
310
  var writeService = (directory) => async (service, options = { path: "" }) => {
295
311
  const resource = { ...service };
296
312
  if (Array.isArray(service.sends)) {
@@ -374,6 +390,7 @@ var serviceHasVersion = (directory) => async (id, version) => {
374
390
  var import_promises7 = __toESM(require("fs/promises"));
375
391
  var import_node_path6 = require("path");
376
392
  var getDomain = (directory) => async (id, version) => getResource(directory, id, version, { type: "domain" });
393
+ var getDomains = (directory) => async (options) => getResources(directory, { type: "domains", ...options });
377
394
  var writeDomain = (directory) => async (domain, options = { path: "" }) => {
378
395
  const resource = { ...domain };
379
396
  if (Array.isArray(domain.services)) {
@@ -409,6 +426,7 @@ var addServiceToDomain = (directory) => async (id, service, version) => {
409
426
  var import_promises8 = __toESM(require("fs/promises"));
410
427
  var import_node_path7 = require("path");
411
428
  var getChannel = (directory) => async (id, version) => getResource(directory, id, version, { type: "channel" });
429
+ var getChannels = (directory) => async (options) => getResources(directory, { type: "channels", ...options });
412
430
  var writeChannel = (directory) => async (channel, options = { path: "" }) => writeResource(directory, { ...channel }, { ...options, type: "channel" });
413
431
  var rmChannel = (directory) => async (path) => {
414
432
  await import_promises8.default.rm((0, import_node_path7.join)(directory, path), { recursive: true });
@@ -460,6 +478,12 @@ var src_default = (path) => {
460
478
  * @returns Event|Undefined
461
479
  */
462
480
  getEvent: getEvent((0, import_node_path8.join)(path)),
481
+ /**
482
+ * Returns all events from EventCatalog
483
+ * @param latestOnly - optional boolean, set to true to get only latest versions
484
+ * @returns Event[]|Undefined
485
+ */
486
+ getEvents: getEvents((0, import_node_path8.join)(path)),
463
487
  /**
464
488
  * Adds an event to EventCatalog
465
489
  *
@@ -531,6 +555,12 @@ var src_default = (path) => {
531
555
  * @returns Command|Undefined
532
556
  */
533
557
  getCommand: getCommand((0, import_node_path8.join)(path)),
558
+ /**
559
+ * Returns all commands from EventCatalog
560
+ * @param latestOnly - optional boolean, set to true to get only latest versions
561
+ * @returns Command[]|Undefined
562
+ */
563
+ getCommands: getCommands((0, import_node_path8.join)(path)),
534
564
  /**
535
565
  * Adds an command to EventCatalog
536
566
  *
@@ -602,6 +632,12 @@ var src_default = (path) => {
602
632
  * @returns Query|Undefined
603
633
  */
604
634
  getQuery: getQuery((0, import_node_path8.join)(path)),
635
+ /**
636
+ * Returns all queries from EventCatalog
637
+ * @param latestOnly - optional boolean, set to true to get only latest versions
638
+ * @returns Query[]|Undefined
639
+ */
640
+ getQueries: getQueries((0, import_node_path8.join)(path)),
605
641
  /**
606
642
  * Adds a query to EventCatalog
607
643
  *
@@ -673,6 +709,12 @@ var src_default = (path) => {
673
709
  * @returns Channel|Undefined
674
710
  */
675
711
  getChannel: getChannel((0, import_node_path8.join)(path)),
712
+ /**
713
+ * Returns all channels from EventCatalog
714
+ * @param latestOnly - optional boolean, set to true to get only latest versions
715
+ * @returns Channel[]|Undefined
716
+ */
717
+ getChannels: getChannels((0, import_node_path8.join)(path)),
676
718
  /**
677
719
  * Adds an channel to EventCatalog
678
720
  *
@@ -794,6 +836,12 @@ var src_default = (path) => {
794
836
  * @returns Service|Undefined
795
837
  */
796
838
  getService: getService((0, import_node_path8.join)(path)),
839
+ /**
840
+ * Returns all services from EventCatalog
841
+ * @param latestOnly - optional boolean, set to true to get only latest versions
842
+ * @returns Service[]|Undefined
843
+ */
844
+ getServices: getServices((0, import_node_path8.join)(path)),
797
845
  /**
798
846
  * Moves a given service id to the version directory
799
847
  * @param directory
@@ -915,6 +963,12 @@ var src_default = (path) => {
915
963
  * @returns Domain|Undefined
916
964
  */
917
965
  getDomain: getDomain((0, import_node_path8.join)(path, "domains")),
966
+ /**
967
+ * Returns all domains from EventCatalog
968
+ * @param latestOnly - optional boolean, set to true to get only latest versions
969
+ * @returns Domain[]|Undefined
970
+ */
971
+ getDomains: getDomains((0, import_node_path8.join)(path)),
918
972
  /**
919
973
  * Moves a given domain id to the version directory
920
974
  * @param directory