@eventcatalog/sdk 2.3.6 → 2.4.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.
Files changed (52) hide show
  1. package/dist/channels.js +30 -4
  2. package/dist/channels.js.map +1 -1
  3. package/dist/channels.mjs +44 -12
  4. package/dist/channels.mjs.map +1 -1
  5. package/dist/commands.d.mts +10 -1
  6. package/dist/commands.d.ts +10 -1
  7. package/dist/commands.js +28 -2
  8. package/dist/commands.js.map +1 -1
  9. package/dist/commands.mjs +34 -8
  10. package/dist/commands.mjs.map +1 -1
  11. package/dist/custom-docs.js +15 -1
  12. package/dist/custom-docs.js.map +1 -1
  13. package/dist/custom-docs.mjs +26 -9
  14. package/dist/custom-docs.mjs.map +1 -1
  15. package/dist/domains.js +27 -1
  16. package/dist/domains.js.map +1 -1
  17. package/dist/domains.mjs +34 -8
  18. package/dist/domains.mjs.map +1 -1
  19. package/dist/eventcatalog.js +40 -5
  20. package/dist/eventcatalog.js.map +1 -1
  21. package/dist/eventcatalog.mjs +67 -32
  22. package/dist/eventcatalog.mjs.map +1 -1
  23. package/dist/events.d.mts +10 -1
  24. package/dist/events.d.ts +10 -1
  25. package/dist/events.js +28 -2
  26. package/dist/events.js.map +1 -1
  27. package/dist/events.mjs +34 -8
  28. package/dist/events.mjs.map +1 -1
  29. package/dist/index.d.mts +26 -9
  30. package/dist/index.d.ts +26 -9
  31. package/dist/index.js +40 -5
  32. package/dist/index.js.map +1 -1
  33. package/dist/index.mjs +67 -32
  34. package/dist/index.mjs.map +1 -1
  35. package/dist/queries.d.mts +10 -1
  36. package/dist/queries.d.ts +10 -1
  37. package/dist/queries.js +28 -2
  38. package/dist/queries.js.map +1 -1
  39. package/dist/queries.mjs +34 -8
  40. package/dist/queries.mjs.map +1 -1
  41. package/dist/services.js +27 -1
  42. package/dist/services.js.map +1 -1
  43. package/dist/services.mjs +33 -7
  44. package/dist/services.mjs.map +1 -1
  45. package/dist/teams.mjs +7 -6
  46. package/dist/teams.mjs.map +1 -1
  47. package/dist/types.d.d.mts +3 -0
  48. package/dist/types.d.d.ts +3 -0
  49. package/dist/types.d.js.map +1 -1
  50. package/dist/users.mjs +7 -6
  51. package/dist/users.mjs.map +1 -1
  52. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,15 +1,15 @@
1
1
  // src/index.ts
2
- import { join as join13 } from "node:path";
2
+ import { join as join13 } from "path";
3
3
 
4
4
  // src/events.ts
5
- import fs2 from "node:fs/promises";
6
- import { join as join3 } from "node:path";
5
+ import fs2 from "fs/promises";
6
+ import { join as join3 } from "path";
7
7
 
8
8
  // src/internal/utils.ts
9
9
  import { globSync } from "glob";
10
- import fsSync from "node:fs";
10
+ import fsSync from "fs";
11
11
  import { copy } from "fs-extra";
12
- import { join, dirname, normalize, resolve, relative } from "node:path";
12
+ import { join, dirname, normalize, resolve, relative } from "path";
13
13
  import matter from "gray-matter";
14
14
  import { satisfies, validRange, valid } from "semver";
15
15
  var versionExists = async (catalogDir, id, version) => {
@@ -115,8 +115,8 @@ var uniqueVersions = (messages) => {
115
115
  // src/internal/resources.ts
116
116
  import { dirname as dirname2, join as join2 } from "path";
117
117
  import matter2 from "gray-matter";
118
- import fs from "node:fs/promises";
119
- import fsSync2 from "node:fs";
118
+ import fs from "fs/promises";
119
+ import fsSync2 from "fs";
120
120
  import { satisfies as satisfies2 } from "semver";
121
121
  import { lock, unlock } from "proper-lockfile";
122
122
  var versionResource = async (catalogDir, id) => {
@@ -187,9 +187,22 @@ var writeResource = async (catalogDir, resource, options = {
187
187
  }
188
188
  };
189
189
  var getResource = async (catalogDir, id, version, options) => {
190
+ const attachSchema = options?.attachSchema || false;
190
191
  const file = await findFileById(catalogDir, id, version);
191
192
  if (!file) return;
192
193
  const { data, content } = matter2.read(file);
194
+ if (attachSchema && data?.schemaPath) {
195
+ const resourceDirectory = dirname2(file);
196
+ const pathToSchema = join2(resourceDirectory, data.schemaPath);
197
+ if (fsSync2.existsSync(pathToSchema)) {
198
+ const schema = fsSync2.readFileSync(pathToSchema, "utf8");
199
+ try {
200
+ data.schema = JSON.parse(schema);
201
+ } catch (error) {
202
+ data.schema = schema;
203
+ }
204
+ }
205
+ }
193
206
  return {
194
207
  ...data,
195
208
  markdown: content.trim()
@@ -208,7 +221,8 @@ var getResources = async (catalogDir, {
208
221
  type,
209
222
  latestOnly = false,
210
223
  ignore = [],
211
- pattern = ""
224
+ pattern = "",
225
+ attachSchema = false
212
226
  }) => {
213
227
  const ignoreList = latestOnly ? `**/versioned/**` : "";
214
228
  const filePattern = pattern || `${catalogDir}/**/${type}/**/index.{md,mdx}`;
@@ -216,6 +230,18 @@ var getResources = async (catalogDir, {
216
230
  if (files.length === 0) return;
217
231
  return files.map((file) => {
218
232
  const { data, content } = matter2.read(file);
233
+ if (attachSchema && data?.schemaPath) {
234
+ const resourceDirectory = dirname2(file);
235
+ const pathToSchema = join2(resourceDirectory, data.schemaPath);
236
+ if (fsSync2.existsSync(pathToSchema)) {
237
+ const schema = fsSync2.readFileSync(pathToSchema, "utf8");
238
+ try {
239
+ data.schema = JSON.parse(schema);
240
+ } catch (error) {
241
+ data.schema = schema;
242
+ }
243
+ }
244
+ }
219
245
  return {
220
246
  ...data,
221
247
  markdown: content.trim()
@@ -266,7 +292,7 @@ var getVersionedDirectory = (sourceDirectory, version) => {
266
292
  };
267
293
 
268
294
  // src/events.ts
269
- var getEvent = (directory) => async (id, version) => getResource(directory, id, version, { type: "event" });
295
+ var getEvent = (directory) => async (id, version, options) => getResource(directory, id, version, { type: "event", ...options });
270
296
  var getEvents = (directory) => async (options) => getResources(directory, { type: "events", ...options });
271
297
  var writeEvent = (directory) => async (event, options = {
272
298
  path: "",
@@ -299,9 +325,9 @@ var eventHasVersion = (directory) => async (id, version) => {
299
325
  };
300
326
 
301
327
  // src/commands.ts
302
- import fs3 from "node:fs/promises";
303
- import { join as join4 } from "node:path";
304
- var getCommand = (directory) => async (id, version) => getResource(directory, id, version, { type: "command" });
328
+ import fs3 from "fs/promises";
329
+ import { join as join4 } from "path";
330
+ var getCommand = (directory) => async (id, version, options) => getResource(directory, id, version, { type: "command", ...options });
305
331
  var getCommands = (directory) => async (options) => getResources(directory, { type: "commands", ...options });
306
332
  var writeCommand = (directory) => async (command, options = {
307
333
  path: "",
@@ -333,9 +359,9 @@ var commandHasVersion = (directory) => async (id, version) => {
333
359
  };
334
360
 
335
361
  // src/queries.ts
336
- import fs4 from "node:fs/promises";
337
- import { join as join5 } from "node:path";
338
- var getQuery = (directory) => async (id, version) => getResource(directory, id, version, { type: "query" });
362
+ import fs4 from "fs/promises";
363
+ import { join as join5 } from "path";
364
+ var getQuery = (directory) => async (id, version, options) => getResource(directory, id, version, { type: "query", ...options });
339
365
  var writeQuery = (directory) => async (query, options = {
340
366
  path: "",
341
367
  override: false,
@@ -369,8 +395,8 @@ var queryHasVersion = (directory) => async (id, version) => {
369
395
  };
370
396
 
371
397
  // src/services.ts
372
- import fs5 from "node:fs/promises";
373
- import { join as join6, dirname as dirname4, extname } from "node:path";
398
+ import fs5 from "fs/promises";
399
+ import { join as join6, dirname as dirname4, extname } from "path";
374
400
  var getService = (directory) => async (id, version) => getResource(directory, id, version, { type: "service" });
375
401
  var getServices = (directory) => async (options) => getResources(directory, {
376
402
  type: "services",
@@ -469,9 +495,9 @@ var serviceHasVersion = (directory) => async (id, version) => {
469
495
  };
470
496
 
471
497
  // src/domains.ts
472
- import fs6 from "node:fs/promises";
473
- import path, { join as join7 } from "node:path";
474
- import fsSync3 from "node:fs";
498
+ import fs6 from "fs/promises";
499
+ import path, { join as join7 } from "path";
500
+ import fsSync3 from "fs";
475
501
  import matter3 from "gray-matter";
476
502
  var getDomain = (directory) => async (id, version) => getResource(directory, id, version, { type: "domain" });
477
503
  var getDomains = (directory) => async (options) => getResources(directory, {
@@ -552,8 +578,8 @@ var addSubDomainToDomain = (directory) => async (id, subDomain, version) => {
552
578
  };
553
579
 
554
580
  // src/channels.ts
555
- import fs7 from "node:fs/promises";
556
- import { join as join8, extname as extname2 } from "node:path";
581
+ import fs7 from "fs/promises";
582
+ import { join as join8, extname as extname2 } from "path";
557
583
  var getChannel = (directory) => async (id, version) => getResource(directory, id, version, { type: "channel" });
558
584
  var getChannels = (directory) => async (options) => getResources(directory, { type: "channels", ...options });
559
585
  var writeChannel = (directory) => async (channel, options = { path: "" }) => writeResource(directory, { ...channel }, { ...options, type: "channel" });
@@ -607,7 +633,7 @@ var addMessageToChannel = (directory, collection) => async (id, _message, versio
607
633
 
608
634
  // src/eventcatalog.ts
609
635
  import fs8 from "fs";
610
- import path2, { join as join9 } from "node:path";
636
+ import path2, { join as join9 } from "path";
611
637
  var DUMP_VERSION = "0.0.1";
612
638
  var getEventCatalogVersion = async (catalogDir) => {
613
639
  try {
@@ -693,9 +719,9 @@ var dumpCatalog = (directory) => async (options) => {
693
719
  };
694
720
 
695
721
  // src/custom-docs.ts
696
- import path3, { join as join10 } from "node:path";
697
- import fsSync4 from "node:fs";
698
- import fs9 from "node:fs/promises";
722
+ import path3, { join as join10 } from "path";
723
+ import fsSync4 from "fs";
724
+ import fs9 from "fs/promises";
699
725
  import matter4 from "gray-matter";
700
726
  import slugify from "slugify";
701
727
  var getCustomDoc = (directory) => async (filePath) => {
@@ -729,9 +755,9 @@ var rmCustomDoc = (directory) => async (filePath) => {
729
755
  };
730
756
 
731
757
  // src/teams.ts
732
- import fs10 from "node:fs/promises";
733
- import fsSync5 from "node:fs";
734
- import { join as join11 } from "node:path";
758
+ import fs10 from "fs/promises";
759
+ import fsSync5 from "fs";
760
+ import { join as join11 } from "path";
735
761
  import matter5 from "gray-matter";
736
762
  var getTeam = (catalogDir) => async (id) => {
737
763
  const files = await getFiles(`${catalogDir}/${id}.{md,mdx}`);
@@ -775,8 +801,8 @@ var rmTeamById = (catalogDir) => async (id) => {
775
801
  };
776
802
 
777
803
  // src/users.ts
778
- import fsSync6 from "node:fs";
779
- import { join as join12 } from "node:path";
804
+ import fsSync6 from "fs";
805
+ import { join as join12 } from "path";
780
806
  import matter6 from "gray-matter";
781
807
  var getUser = (catalogDir) => async (id) => {
782
808
  const files = await getFiles(`${catalogDir}/${id}.{md,mdx}`);
@@ -1483,7 +1509,16 @@ var index_default = (path4) => {
1483
1509
  * @param directory - The directory to dump the catalog to
1484
1510
  * @returns A JSON file with the catalog
1485
1511
  */
1486
- dumpCatalog: dumpCatalog(join13(path4))
1512
+ dumpCatalog: dumpCatalog(join13(path4)),
1513
+ /**
1514
+ * ================================
1515
+ * Resources Utils
1516
+ * ================================
1517
+ */
1518
+ /**
1519
+ * Returns the path to a given resource by id and version
1520
+ */
1521
+ getResourcePath
1487
1522
  };
1488
1523
  };
1489
1524
  export {