@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.mjs CHANGED
@@ -41,9 +41,9 @@ var findFileById = async (catalogDir, id, version) => {
41
41
  return match[0].path;
42
42
  }
43
43
  };
44
- var getFiles = async (pattern) => {
44
+ var getFiles = async (pattern, ignore = "") => {
45
45
  try {
46
- const files = await glob(pattern, { ignore: "node_modules/**" });
46
+ const files = await glob(pattern, { ignore: ["node_modules/**", ignore] });
47
47
  return files;
48
48
  } catch (error) {
49
49
  throw new Error(`Error finding files: ${error}`);
@@ -155,6 +155,18 @@ var getResource = async (catalogDir, id, version, options) => {
155
155
  markdown: content.trim()
156
156
  };
157
157
  };
158
+ var getResources = async (catalogDir, { type, latestOnly = false }) => {
159
+ const ignore = latestOnly ? `**/versioned/**` : "";
160
+ const files = await getFiles(`${catalogDir}/**/${type}/**/index.md`, ignore);
161
+ if (files.length === 0) return;
162
+ return files.map((file) => {
163
+ const { data, content } = matter2.read(file);
164
+ return {
165
+ ...data,
166
+ markdown: content.trim()
167
+ };
168
+ });
169
+ };
158
170
  var rmResourceById = async (catalogDir, id, version, options) => {
159
171
  const files = await getFiles(`${catalogDir}/**/index.md`);
160
172
  const matchedFiles = await searchFilesForId(files, id, version);
@@ -181,6 +193,7 @@ var getVersionedDirectory = (sourceDirectory, version) => {
181
193
 
182
194
  // src/events.ts
183
195
  var getEvent = (directory) => async (id, version) => getResource(directory, id, version, { type: "event" });
196
+ var getEvents = (directory) => async (options) => getResources(directory, { type: "events", ...options });
184
197
  var writeEvent = (directory) => async (event, options = { path: "", override: false }) => writeResource(directory, { ...event }, { ...options, type: "event" });
185
198
  var writeEventToService = (directory) => async (event, service, options = { path: "" }) => {
186
199
  let pathForEvent = service.version && service.version !== "latest" ? `/${service.id}/versioned/${service.version}/events` : `/${service.id}/events`;
@@ -207,6 +220,7 @@ var eventHasVersion = (directory) => async (id, version) => {
207
220
  import fs4 from "node:fs/promises";
208
221
  import { join as join4 } from "node:path";
209
222
  var getCommand = (directory) => async (id, version) => getResource(directory, id, version, { type: "command" });
223
+ var getCommands = (directory) => async (options) => getResources(directory, { type: "commands", ...options });
210
224
  var writeCommand = (directory) => async (command, options = { path: "" }) => writeResource(directory, { ...command }, { ...options, type: "command" });
211
225
  var writeCommandToService = (directory) => async (command, service, options = { path: "" }) => {
212
226
  let pathForEvent = service.version && service.version !== "latest" ? `/${service.id}/versioned/${service.version}/commands` : `/${service.id}/commands`;
@@ -232,6 +246,7 @@ import fs5 from "node:fs/promises";
232
246
  import { join as join5 } from "node:path";
233
247
  var getQuery = (directory) => async (id, version) => getResource(directory, id, version, { type: "query" });
234
248
  var writeQuery = (directory) => async (query, options = { path: "" }) => writeResource(directory, { ...query }, { ...options, type: "query" });
249
+ var getQueries = (directory) => async (options) => getResources(directory, { type: "queries", ...options });
235
250
  var writeQueryToService = (directory) => async (query, service, options = { path: "" }) => {
236
251
  let pathForQuery = service.version && service.version !== "latest" ? `/${service.id}/versioned/${service.version}/queries` : `/${service.id}/queries`;
237
252
  pathForQuery = join5(pathForQuery, query.id);
@@ -257,6 +272,7 @@ var queryHasVersion = (directory) => async (id, version) => {
257
272
  import fs6 from "node:fs/promises";
258
273
  import { join as join6, dirname as dirname2 } from "node:path";
259
274
  var getService = (directory) => async (id, version) => getResource(directory, id, version, { type: "service" });
275
+ var getServices = (directory) => async (options) => getResources(directory, { type: "services", ...options });
260
276
  var writeService = (directory) => async (service, options = { path: "" }) => {
261
277
  const resource = { ...service };
262
278
  if (Array.isArray(service.sends)) {
@@ -340,6 +356,7 @@ var serviceHasVersion = (directory) => async (id, version) => {
340
356
  import fs7 from "node:fs/promises";
341
357
  import { join as join7 } from "node:path";
342
358
  var getDomain = (directory) => async (id, version) => getResource(directory, id, version, { type: "domain" });
359
+ var getDomains = (directory) => async (options) => getResources(directory, { type: "domains", ...options });
343
360
  var writeDomain = (directory) => async (domain, options = { path: "" }) => {
344
361
  const resource = { ...domain };
345
362
  if (Array.isArray(domain.services)) {
@@ -375,6 +392,7 @@ var addServiceToDomain = (directory) => async (id, service, version) => {
375
392
  import fs8 from "node:fs/promises";
376
393
  import { join as join8 } from "node:path";
377
394
  var getChannel = (directory) => async (id, version) => getResource(directory, id, version, { type: "channel" });
395
+ var getChannels = (directory) => async (options) => getResources(directory, { type: "channels", ...options });
378
396
  var writeChannel = (directory) => async (channel, options = { path: "" }) => writeResource(directory, { ...channel }, { ...options, type: "channel" });
379
397
  var rmChannel = (directory) => async (path) => {
380
398
  await fs8.rm(join8(directory, path), { recursive: true });
@@ -426,6 +444,12 @@ var src_default = (path) => {
426
444
  * @returns Event|Undefined
427
445
  */
428
446
  getEvent: getEvent(join9(path)),
447
+ /**
448
+ * Returns all events from EventCatalog
449
+ * @param latestOnly - optional boolean, set to true to get only latest versions
450
+ * @returns Event[]|Undefined
451
+ */
452
+ getEvents: getEvents(join9(path)),
429
453
  /**
430
454
  * Adds an event to EventCatalog
431
455
  *
@@ -497,6 +521,12 @@ var src_default = (path) => {
497
521
  * @returns Command|Undefined
498
522
  */
499
523
  getCommand: getCommand(join9(path)),
524
+ /**
525
+ * Returns all commands from EventCatalog
526
+ * @param latestOnly - optional boolean, set to true to get only latest versions
527
+ * @returns Command[]|Undefined
528
+ */
529
+ getCommands: getCommands(join9(path)),
500
530
  /**
501
531
  * Adds an command to EventCatalog
502
532
  *
@@ -568,6 +598,12 @@ var src_default = (path) => {
568
598
  * @returns Query|Undefined
569
599
  */
570
600
  getQuery: getQuery(join9(path)),
601
+ /**
602
+ * Returns all queries from EventCatalog
603
+ * @param latestOnly - optional boolean, set to true to get only latest versions
604
+ * @returns Query[]|Undefined
605
+ */
606
+ getQueries: getQueries(join9(path)),
571
607
  /**
572
608
  * Adds a query to EventCatalog
573
609
  *
@@ -639,6 +675,12 @@ var src_default = (path) => {
639
675
  * @returns Channel|Undefined
640
676
  */
641
677
  getChannel: getChannel(join9(path)),
678
+ /**
679
+ * Returns all channels from EventCatalog
680
+ * @param latestOnly - optional boolean, set to true to get only latest versions
681
+ * @returns Channel[]|Undefined
682
+ */
683
+ getChannels: getChannels(join9(path)),
642
684
  /**
643
685
  * Adds an channel to EventCatalog
644
686
  *
@@ -760,6 +802,12 @@ var src_default = (path) => {
760
802
  * @returns Service|Undefined
761
803
  */
762
804
  getService: getService(join9(path)),
805
+ /**
806
+ * Returns all services from EventCatalog
807
+ * @param latestOnly - optional boolean, set to true to get only latest versions
808
+ * @returns Service[]|Undefined
809
+ */
810
+ getServices: getServices(join9(path)),
763
811
  /**
764
812
  * Moves a given service id to the version directory
765
813
  * @param directory
@@ -881,6 +929,12 @@ var src_default = (path) => {
881
929
  * @returns Domain|Undefined
882
930
  */
883
931
  getDomain: getDomain(join9(path, "domains")),
932
+ /**
933
+ * Returns all domains from EventCatalog
934
+ * @param latestOnly - optional boolean, set to true to get only latest versions
935
+ * @returns Domain[]|Undefined
936
+ */
937
+ getDomains: getDomains(join9(path)),
884
938
  /**
885
939
  * Moves a given domain id to the version directory
886
940
  * @param directory