@eventcatalog/sdk 2.13.1 → 2.14.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 ADDED
@@ -0,0 +1,2870 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ default: () => src_default
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+ var import_node_path20 = require("path");
37
+
38
+ // src/dsl/utils.ts
39
+ var import_glob = require("glob");
40
+ function serializeBaseFields(resource, indent = " ") {
41
+ const lines = [];
42
+ if (resource.version) {
43
+ lines.push(`${indent}version ${resource.version}`);
44
+ }
45
+ if (resource.name) {
46
+ lines.push(`${indent}name "${resource.name}"`);
47
+ }
48
+ if (resource.summary) {
49
+ lines.push(`${indent}summary "${resource.summary.trim()}"`);
50
+ }
51
+ if (resource.owners && resource.owners.length > 0) {
52
+ for (const owner of resource.owners) {
53
+ lines.push(`${indent}owner ${owner}`);
54
+ }
55
+ }
56
+ if (resource.deprecated === true) {
57
+ lines.push(`${indent}deprecated true`);
58
+ }
59
+ if (resource.draft === true) {
60
+ lines.push(`${indent}draft true`);
61
+ }
62
+ return lines.join("\n");
63
+ }
64
+ function resolveMessageType(catalogDir, id) {
65
+ if ((0, import_glob.globSync)(`**/events/${id}/index.{md,mdx}`, { cwd: catalogDir }).length > 0) return "event";
66
+ if ((0, import_glob.globSync)(`**/commands/${id}/index.{md,mdx}`, { cwd: catalogDir }).length > 0) return "command";
67
+ if ((0, import_glob.globSync)(`**/queries/${id}/index.{md,mdx}`, { cwd: catalogDir }).length > 0) return "query";
68
+ return void 0;
69
+ }
70
+ function serializeChannelRef(channel) {
71
+ let ref = channel.id;
72
+ if (channel.version) ref += `@${channel.version}`;
73
+ return ref;
74
+ }
75
+ function serializeMessagePointers(items, direction, catalogDir, indent = " ") {
76
+ const lines = [];
77
+ for (const item of items) {
78
+ const msgType = resolveMessageType(catalogDir, item.id);
79
+ if (!msgType) continue;
80
+ let ref = `${item.id}`;
81
+ if (item.version) ref += `@${item.version}`;
82
+ const channels = direction === "sends" ? item.to : item.from;
83
+ const channelKeyword = direction === "sends" ? "to" : "from";
84
+ if (channels && channels.length === 1) {
85
+ lines.push(`${indent}${direction} ${msgType} ${ref} ${channelKeyword} ${serializeChannelRef(channels[0])}`);
86
+ } else if (channels && channels.length > 1) {
87
+ const channelRefs = channels.map(serializeChannelRef).join(", ");
88
+ lines.push(`${indent}${direction} ${msgType} ${ref} ${channelKeyword} ${channelRefs}`);
89
+ } else {
90
+ lines.push(`${indent}${direction} ${msgType} ${ref}`);
91
+ }
92
+ }
93
+ return lines.join("\n");
94
+ }
95
+
96
+ // src/dsl/message.ts
97
+ function messageToDSL(resource, type) {
98
+ const body = serializeBaseFields(resource);
99
+ if (!body) {
100
+ return `${type} ${resource.id}`;
101
+ }
102
+ return `${type} ${resource.id} {
103
+ ${body}
104
+ }`;
105
+ }
106
+
107
+ // src/dsl/service.ts
108
+ async function serviceToDSL(resource, options, getMessageFn) {
109
+ const { catalogDir, hydrate = false, _seen = /* @__PURE__ */ new Set() } = options;
110
+ const parts = [];
111
+ if (hydrate && getMessageFn) {
112
+ const allMessages = [...resource.sends || [], ...resource.receives || []];
113
+ for (const msg of allMessages) {
114
+ const key = `${msg.id}@${msg.version || "latest"}`;
115
+ if (_seen.has(key)) continue;
116
+ _seen.add(key);
117
+ const msgType = resolveMessageType(catalogDir, msg.id);
118
+ if (!msgType) continue;
119
+ const msgResource = await getMessageFn(msg.id, msg.version);
120
+ if (msgResource) {
121
+ parts.push(messageToDSL(msgResource, msgType));
122
+ }
123
+ }
124
+ }
125
+ const lines = [];
126
+ const baseFields = serializeBaseFields(resource);
127
+ if (baseFields) lines.push(baseFields);
128
+ if (resource.sends && resource.sends.length > 0) {
129
+ const sendsStr = serializeMessagePointers(resource.sends, "sends", catalogDir);
130
+ if (sendsStr) lines.push(sendsStr);
131
+ }
132
+ if (resource.receives && resource.receives.length > 0) {
133
+ const recvStr = serializeMessagePointers(resource.receives, "receives", catalogDir);
134
+ if (recvStr) lines.push(recvStr);
135
+ }
136
+ if (resource.writesTo && resource.writesTo.length > 0) {
137
+ for (const container of resource.writesTo) {
138
+ let ref = container.id;
139
+ if (container.version) ref += `@${container.version}`;
140
+ lines.push(` writes-to container ${ref}`);
141
+ }
142
+ }
143
+ if (resource.readsFrom && resource.readsFrom.length > 0) {
144
+ for (const container of resource.readsFrom) {
145
+ let ref = container.id;
146
+ if (container.version) ref += `@${container.version}`;
147
+ lines.push(` reads-from container ${ref}`);
148
+ }
149
+ }
150
+ const body = lines.join("\n");
151
+ parts.push(`service ${resource.id} {
152
+ ${body}
153
+ }`);
154
+ return parts.join("\n\n");
155
+ }
156
+
157
+ // src/dsl/channel.ts
158
+ function channelToDSL(resource) {
159
+ const lines = [];
160
+ if (resource.version) {
161
+ lines.push(` version ${resource.version}`);
162
+ }
163
+ if (resource.name) {
164
+ lines.push(` name "${resource.name}"`);
165
+ }
166
+ if (resource.address) {
167
+ lines.push(` address "${resource.address}"`);
168
+ }
169
+ if (resource.protocols && resource.protocols.length > 0) {
170
+ for (const protocol of resource.protocols) {
171
+ lines.push(` protocol "${protocol}"`);
172
+ }
173
+ }
174
+ if (resource.summary) {
175
+ lines.push(` summary "${resource.summary.trim()}"`);
176
+ }
177
+ if (!lines.length) {
178
+ return `channel ${resource.id}`;
179
+ }
180
+ return `channel ${resource.id} {
181
+ ${lines.join("\n")}
182
+ }`;
183
+ }
184
+
185
+ // src/dsl/owner.ts
186
+ function teamToDSL(team) {
187
+ const lines = [];
188
+ if (team.name) lines.push(` name "${team.name}"`);
189
+ if (team.avatarUrl) lines.push(` avatar "${team.avatarUrl}"`);
190
+ if (team.role) lines.push(` role "${team.role}"`);
191
+ if (team.summary) lines.push(` summary "${team.summary}"`);
192
+ if (team.email) lines.push(` email "${team.email}"`);
193
+ if (team.slackDirectMessageUrl) lines.push(` slack "${team.slackDirectMessageUrl}"`);
194
+ return `team ${team.id} {
195
+ ${lines.join("\n")}
196
+ }`;
197
+ }
198
+ function userToDSL(user) {
199
+ const lines = [];
200
+ if (user.name) lines.push(` name "${user.name}"`);
201
+ if (user.avatarUrl) lines.push(` avatar "${user.avatarUrl}"`);
202
+ if (user.role) lines.push(` role "${user.role}"`);
203
+ if (user.email) lines.push(` email "${user.email}"`);
204
+ if (user.slackDirectMessageUrl) lines.push(` slack "${user.slackDirectMessageUrl}"`);
205
+ return `user ${user.id} {
206
+ ${lines.join("\n")}
207
+ }`;
208
+ }
209
+
210
+ // src/dsl/domain.ts
211
+ async function hydrateOwners(owners, resolvers, seen, parts) {
212
+ if (!owners || !resolvers.getTeam || !resolvers.getUser) return;
213
+ for (const ownerId of owners) {
214
+ const key = `owner:${ownerId}`;
215
+ if (seen.has(key)) continue;
216
+ seen.add(key);
217
+ const team = await resolvers.getTeam(ownerId);
218
+ if (team) {
219
+ parts.push(teamToDSL(team));
220
+ continue;
221
+ }
222
+ const user = await resolvers.getUser(ownerId);
223
+ if (user) {
224
+ parts.push(userToDSL(user));
225
+ }
226
+ }
227
+ }
228
+ async function hydrateChannelsFromMessages(messages, resolvers, seen, parts) {
229
+ if (!resolvers.getChannel) return;
230
+ for (const msg of messages) {
231
+ const channels = msg.to || msg.from;
232
+ if (!channels) continue;
233
+ for (const ch of channels) {
234
+ const key = `channel:${ch.id}@${ch.version || "latest"}`;
235
+ if (seen.has(key)) continue;
236
+ seen.add(key);
237
+ const channel = await resolvers.getChannel(ch.id, ch.version);
238
+ if (channel) {
239
+ parts.push(channelToDSL(channel));
240
+ }
241
+ }
242
+ }
243
+ }
244
+ async function buildDomainBody(resource, options, resolvers, keyword) {
245
+ const { catalogDir, hydrate = false, _seen = /* @__PURE__ */ new Set() } = options;
246
+ const topLevelParts = [];
247
+ if (hydrate && resolvers) {
248
+ if (resource.services && resource.services.length > 0 && resolvers.getService) {
249
+ for (const svcRef of resource.services) {
250
+ const svcKey = `service:${svcRef.id}@${svcRef.version || "latest"}`;
251
+ if (_seen.has(svcKey)) continue;
252
+ _seen.add(svcKey);
253
+ const svc = await resolvers.getService(svcRef.id, svcRef.version);
254
+ if (svc) {
255
+ await hydrateOwners(svc.owners, resolvers, _seen, topLevelParts);
256
+ const svcMessages = [...svc.sends || [], ...svc.receives || []];
257
+ await hydrateChannelsFromMessages(svcMessages, resolvers, _seen, topLevelParts);
258
+ const svcDsl = await serviceToDSL(svc, { catalogDir, hydrate: true, _seen }, resolvers.getMessage);
259
+ topLevelParts.push(svcDsl);
260
+ }
261
+ }
262
+ }
263
+ const domainMessages = [...resource.sends || [], ...resource.receives || []];
264
+ await hydrateChannelsFromMessages(domainMessages, resolvers, _seen, topLevelParts);
265
+ if (resolvers.getMessage) {
266
+ for (const msg of domainMessages) {
267
+ const key = `${msg.id}@${msg.version || "latest"}`;
268
+ if (_seen.has(key)) continue;
269
+ _seen.add(key);
270
+ const msgType = resolveMessageType(catalogDir, msg.id);
271
+ if (!msgType) continue;
272
+ const msgResource = await resolvers.getMessage(msg.id, msg.version);
273
+ if (msgResource) {
274
+ topLevelParts.push(messageToDSL(msgResource, msgType));
275
+ }
276
+ }
277
+ }
278
+ }
279
+ const lines = [];
280
+ const baseFields = serializeBaseFields(resource);
281
+ if (baseFields) lines.push(baseFields);
282
+ if (resource.services && resource.services.length > 0) {
283
+ for (const svc of resource.services) {
284
+ let ref = svc.id;
285
+ if (svc.version) ref += `@${svc.version}`;
286
+ lines.push(` service ${ref}`);
287
+ }
288
+ }
289
+ if (resource.sends && resource.sends.length > 0) {
290
+ const sendsStr = serializeMessagePointers(resource.sends, "sends", catalogDir);
291
+ if (sendsStr) lines.push(sendsStr);
292
+ }
293
+ if (resource.receives && resource.receives.length > 0) {
294
+ const recvStr = serializeMessagePointers(resource.receives, "receives", catalogDir);
295
+ if (recvStr) lines.push(recvStr);
296
+ }
297
+ if (resource.domains && resource.domains.length > 0) {
298
+ if (hydrate && resolvers?.getDomain) {
299
+ for (const subRef of resource.domains) {
300
+ const subKey = `domain:${subRef.id}@${subRef.version || "latest"}`;
301
+ if (_seen.has(subKey)) continue;
302
+ _seen.add(subKey);
303
+ const subDomain = await resolvers.getDomain(subRef.id, subRef.version);
304
+ if (subDomain) {
305
+ await hydrateOwners(subDomain.owners, resolvers, _seen, topLevelParts);
306
+ const sub = await buildDomainBody(subDomain, { catalogDir, hydrate, _seen }, resolvers, "subdomain");
307
+ topLevelParts.push(...sub.topLevelParts);
308
+ const indented = sub.block.split("\n").map((line) => ` ${line}`).join("\n");
309
+ lines.push(indented);
310
+ }
311
+ }
312
+ } else {
313
+ for (const sub of resource.domains) {
314
+ let ref = sub.id;
315
+ if (sub.version) ref += `@${sub.version}`;
316
+ lines.push(` subdomain ${ref}`);
317
+ }
318
+ }
319
+ }
320
+ const body = lines.join("\n");
321
+ const block = `${keyword} ${resource.id} {
322
+ ${body}
323
+ }`;
324
+ return { topLevelParts, block };
325
+ }
326
+ async function domainToDSL(resource, options, resolvers) {
327
+ const { catalogDir, hydrate = false, _seen = /* @__PURE__ */ new Set() } = options;
328
+ const result = await buildDomainBody(resource, { catalogDir, hydrate, _seen }, resolvers, "domain");
329
+ const parts = [...result.topLevelParts, result.block];
330
+ return parts.join("\n\n");
331
+ }
332
+
333
+ // src/dsl/index.ts
334
+ function getMessage(resolvers, catalogDir) {
335
+ return async (id, version) => {
336
+ const msgType = resolveMessageType(catalogDir, id);
337
+ if (!msgType) return void 0;
338
+ switch (msgType) {
339
+ case "event":
340
+ return resolvers.getEvent(id, version);
341
+ case "command":
342
+ return resolvers.getCommand(id, version);
343
+ case "query":
344
+ return resolvers.getQuery(id, version);
345
+ }
346
+ };
347
+ }
348
+ async function hydrateChannels(resource, resolvers, seen, parts) {
349
+ const allMessages = [...resource.sends || [], ...resource.receives || []];
350
+ for (const msg of allMessages) {
351
+ const channels = "to" in msg ? msg.to : "from" in msg ? msg.from : void 0;
352
+ if (!channels) continue;
353
+ for (const ch of channels) {
354
+ const key = `channel:${ch.id}@${ch.version || "latest"}`;
355
+ if (seen.has(key)) continue;
356
+ seen.add(key);
357
+ const channel = await resolvers.getChannel(ch.id, ch.version);
358
+ if (channel) {
359
+ parts.push(channelToDSL(channel));
360
+ }
361
+ }
362
+ }
363
+ }
364
+ async function hydrateOwners2(owners, resolvers, seen, parts) {
365
+ if (!owners) return;
366
+ for (const ownerId of owners) {
367
+ const key = `owner:${ownerId}`;
368
+ if (seen.has(key)) continue;
369
+ seen.add(key);
370
+ const team = await resolvers.getTeam(ownerId);
371
+ if (team) {
372
+ parts.push(teamToDSL(team));
373
+ continue;
374
+ }
375
+ const user = await resolvers.getUser(ownerId);
376
+ if (user) {
377
+ parts.push(userToDSL(user));
378
+ }
379
+ }
380
+ }
381
+ var toDSL = (catalogDir, resolvers) => async (resource, options) => {
382
+ const resources = Array.isArray(resource) ? resource : [resource];
383
+ const seen = /* @__PURE__ */ new Set();
384
+ const parts = [];
385
+ for (const res of resources) {
386
+ const key = `${options.type}:${res.id}@${res.version || "latest"}`;
387
+ if (seen.has(key)) continue;
388
+ seen.add(key);
389
+ switch (options.type) {
390
+ case "event":
391
+ case "command":
392
+ case "query":
393
+ if (options.hydrate) {
394
+ await hydrateOwners2(res.owners, resolvers, seen, parts);
395
+ }
396
+ parts.push(messageToDSL(res, options.type));
397
+ break;
398
+ case "service":
399
+ if (options.hydrate) {
400
+ await hydrateOwners2(res.owners, resolvers, seen, parts);
401
+ await hydrateChannels(res, resolvers, seen, parts);
402
+ }
403
+ parts.push(
404
+ await serviceToDSL(
405
+ res,
406
+ { catalogDir, hydrate: options.hydrate, _seen: seen },
407
+ getMessage(resolvers, catalogDir)
408
+ )
409
+ );
410
+ break;
411
+ case "domain":
412
+ if (options.hydrate) {
413
+ await hydrateOwners2(res.owners, resolvers, seen, parts);
414
+ }
415
+ parts.push(
416
+ await domainToDSL(
417
+ res,
418
+ { catalogDir, hydrate: options.hydrate, _seen: seen },
419
+ {
420
+ getService: resolvers.getService,
421
+ getDomain: resolvers.getDomain,
422
+ getMessage: getMessage(resolvers, catalogDir),
423
+ getChannel: resolvers.getChannel,
424
+ getTeam: resolvers.getTeam,
425
+ getUser: resolvers.getUser
426
+ }
427
+ )
428
+ );
429
+ break;
430
+ }
431
+ }
432
+ return parts.join("\n\n");
433
+ };
434
+
435
+ // src/events.ts
436
+ var import_promises2 = __toESM(require("fs/promises"));
437
+ var import_node_path4 = require("path");
438
+
439
+ // src/internal/utils.ts
440
+ var import_glob2 = require("glob");
441
+ var import_node_fs = __toESM(require("fs"));
442
+ var import_fs_extra = require("fs-extra");
443
+ var import_node_path = require("path");
444
+ var import_gray_matter = __toESM(require("gray-matter"));
445
+ var import_semver = require("semver");
446
+ var versionExists = async (catalogDir, id, version) => {
447
+ const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
448
+ const matchedFiles = await searchFilesForId(files, id, version) || [];
449
+ return matchedFiles.length > 0;
450
+ };
451
+ var findFileById = async (catalogDir, id, version) => {
452
+ const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
453
+ const matchedFiles = await searchFilesForId(files, id) || [];
454
+ const latestVersion = matchedFiles.find((path6) => !path6.includes("versioned"));
455
+ if (!version) {
456
+ return latestVersion;
457
+ }
458
+ const parsedFiles = matchedFiles.map((path6) => {
459
+ const { data } = import_gray_matter.default.read(path6);
460
+ return { ...data, path: path6 };
461
+ });
462
+ if (version === "latest") {
463
+ return latestVersion;
464
+ }
465
+ const exactMatch = parsedFiles.find((c) => c.version === version);
466
+ if (exactMatch) {
467
+ return exactMatch.path;
468
+ }
469
+ const semverRange = (0, import_semver.validRange)(version);
470
+ if (semverRange) {
471
+ const match = parsedFiles.filter((c) => {
472
+ try {
473
+ return (0, import_semver.satisfies)(c.version, semverRange);
474
+ } catch (error) {
475
+ return false;
476
+ }
477
+ });
478
+ return match.length > 0 ? match[0].path : void 0;
479
+ }
480
+ return void 0;
481
+ };
482
+ var getFiles = async (pattern, ignore = "") => {
483
+ try {
484
+ const normalizedInputPattern = (0, import_node_path.normalize)(pattern);
485
+ const absoluteBaseDir = (0, import_node_path.resolve)(
486
+ normalizedInputPattern.includes("**") ? normalizedInputPattern.split("**")[0] : (0, import_node_path.dirname)(normalizedInputPattern)
487
+ );
488
+ let relativePattern = (0, import_node_path.relative)(absoluteBaseDir, normalizedInputPattern);
489
+ relativePattern = relativePattern.replace(/\\/g, "/");
490
+ const ignoreList = Array.isArray(ignore) ? ignore : [ignore];
491
+ const files = (0, import_glob2.globSync)(relativePattern, {
492
+ cwd: absoluteBaseDir,
493
+ ignore: ["node_modules/**", ...ignoreList],
494
+ absolute: true,
495
+ nodir: true
496
+ });
497
+ return files.map(import_node_path.normalize);
498
+ } catch (error) {
499
+ const absoluteBaseDirForError = (0, import_node_path.resolve)(
500
+ (0, import_node_path.normalize)(pattern).includes("**") ? (0, import_node_path.normalize)(pattern).split("**")[0] : (0, import_node_path.dirname)((0, import_node_path.normalize)(pattern))
501
+ );
502
+ const relativePatternForError = (0, import_node_path.relative)(absoluteBaseDirForError, (0, import_node_path.normalize)(pattern)).replace(/\\/g, "/");
503
+ throw new Error(
504
+ `Error finding files for pattern "${pattern}" (using cwd: "${absoluteBaseDirForError}", globPattern: "${relativePatternForError}"): ${error.message}`
505
+ );
506
+ }
507
+ };
508
+ var readMdxFile = async (path6) => {
509
+ const { data } = import_gray_matter.default.read(path6);
510
+ const { markdown, ...frontmatter } = data;
511
+ return { ...frontmatter, markdown };
512
+ };
513
+ var searchFilesForId = async (files, id, version) => {
514
+ const escapedId = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
515
+ const idRegex = new RegExp(`^id:\\s*(['"]|>-)?\\s*${escapedId}['"]?\\s*$`, "m");
516
+ const versionRegex = new RegExp(`^version:\\s*['"]?${version}['"]?\\s*$`, "m");
517
+ const matches = files.map((file) => {
518
+ const content = import_node_fs.default.readFileSync(file, "utf-8");
519
+ const hasIdMatch = content.match(idRegex);
520
+ if (version && !content.match(versionRegex)) {
521
+ return void 0;
522
+ }
523
+ if (hasIdMatch) {
524
+ return file;
525
+ }
526
+ });
527
+ return matches.filter(Boolean).filter((file) => file !== void 0);
528
+ };
529
+ var copyDir = async (catalogDir, source, target, filter) => {
530
+ const tmpDirectory = (0, import_node_path.join)(catalogDir, "tmp");
531
+ import_node_fs.default.mkdirSync(tmpDirectory, { recursive: true });
532
+ await (0, import_fs_extra.copy)(source, tmpDirectory, {
533
+ overwrite: true,
534
+ filter
535
+ });
536
+ await (0, import_fs_extra.copy)(tmpDirectory, target, {
537
+ overwrite: true,
538
+ filter
539
+ });
540
+ import_node_fs.default.rmSync(tmpDirectory, { recursive: true });
541
+ };
542
+ var uniqueVersions = (messages) => {
543
+ const uniqueSet = /* @__PURE__ */ new Set();
544
+ return messages.filter((message) => {
545
+ const key = `${message.id}-${message.version}`;
546
+ if (!uniqueSet.has(key)) {
547
+ uniqueSet.add(key);
548
+ return true;
549
+ }
550
+ return false;
551
+ });
552
+ };
553
+
554
+ // src/internal/resources.ts
555
+ var import_path = require("path");
556
+ var import_gray_matter2 = __toESM(require("gray-matter"));
557
+ var import_promises = __toESM(require("fs/promises"));
558
+ var import_node_fs2 = __toESM(require("fs"));
559
+ var import_semver2 = require("semver");
560
+ var import_proper_lockfile = require("proper-lockfile");
561
+ var import_node_path2 = require("path");
562
+ var import_node_path3 = __toESM(require("path"));
563
+ var versionResource = async (catalogDir, id) => {
564
+ const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
565
+ const matchedFiles = await searchFilesForId(files, id);
566
+ if (matchedFiles.length === 0) {
567
+ throw new Error(`No resource found with id: ${id}`);
568
+ }
569
+ const file = matchedFiles[0];
570
+ const sourceDirectory = (0, import_path.dirname)(file).replace(/[/\\]versioned[/\\][^/\\]+[/\\]/, import_node_path3.default.sep);
571
+ const { data: { version = "0.0.1" } = {} } = import_gray_matter2.default.read(file);
572
+ const targetDirectory = getVersionedDirectory(sourceDirectory, version);
573
+ import_node_fs2.default.mkdirSync(targetDirectory, { recursive: true });
574
+ const ignoreListToCopy = ["events", "commands", "queries", "versioned"];
575
+ await copyDir(catalogDir, sourceDirectory, targetDirectory, (src) => {
576
+ const folderName = (0, import_node_path2.basename)(src);
577
+ if (ignoreListToCopy.includes(folderName)) {
578
+ return false;
579
+ }
580
+ return true;
581
+ });
582
+ await import_promises.default.readdir(sourceDirectory).then(async (resourceFiles) => {
583
+ await Promise.all(
584
+ resourceFiles.map(async (file2) => {
585
+ if (ignoreListToCopy.includes(file2)) {
586
+ return;
587
+ }
588
+ if (file2 !== "versioned") {
589
+ import_node_fs2.default.rmSync((0, import_path.join)(sourceDirectory, file2), { recursive: true });
590
+ }
591
+ })
592
+ );
593
+ });
594
+ };
595
+ var writeResource = async (catalogDir, resource, options = {
596
+ path: "",
597
+ type: "",
598
+ override: false,
599
+ versionExistingContent: false,
600
+ format: "mdx"
601
+ }) => {
602
+ const path6 = options.path || `/${resource.id}`;
603
+ const fullPath = (0, import_path.join)(catalogDir, path6);
604
+ const format = options.format || "mdx";
605
+ import_node_fs2.default.mkdirSync(fullPath, { recursive: true });
606
+ const lockPath = (0, import_path.join)(fullPath, `index.${format}`);
607
+ if (!import_node_fs2.default.existsSync(lockPath)) {
608
+ import_node_fs2.default.writeFileSync(lockPath, "");
609
+ }
610
+ try {
611
+ await (0, import_proper_lockfile.lock)(lockPath, {
612
+ retries: 5,
613
+ stale: 1e4
614
+ // 10 seconds
615
+ });
616
+ const exists = await versionExists(catalogDir, resource.id, resource.version);
617
+ if (exists && !options.override) {
618
+ throw new Error(`Failed to write ${resource.id} (${options.type}) as the version ${resource.version} already exists`);
619
+ }
620
+ const { markdown, ...frontmatter } = resource;
621
+ if (options.versionExistingContent && !exists) {
622
+ const currentResource = await getResource(catalogDir, resource.id);
623
+ if (currentResource) {
624
+ if ((0, import_semver2.satisfies)(resource.version, `>${currentResource.version}`)) {
625
+ await versionResource(catalogDir, resource.id);
626
+ } else {
627
+ throw new Error(`New version ${resource.version} is not greater than current version ${currentResource.version}`);
628
+ }
629
+ }
630
+ }
631
+ const document = import_gray_matter2.default.stringify(markdown.trim(), frontmatter);
632
+ import_node_fs2.default.writeFileSync(lockPath, document);
633
+ } finally {
634
+ await (0, import_proper_lockfile.unlock)(lockPath).catch(() => {
635
+ });
636
+ }
637
+ };
638
+ var getResource = async (catalogDir, id, version, options, filePath) => {
639
+ const attachSchema = options?.attachSchema || false;
640
+ const file = filePath || (id ? await findFileById(catalogDir, id, version) : void 0);
641
+ if (!file || !import_node_fs2.default.existsSync(file)) return;
642
+ const { data, content } = import_gray_matter2.default.read(file);
643
+ if (attachSchema && data?.schemaPath) {
644
+ const resourceDirectory = (0, import_path.dirname)(file);
645
+ const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
646
+ if (import_node_fs2.default.existsSync(pathToSchema)) {
647
+ const schema = import_node_fs2.default.readFileSync(pathToSchema, "utf8");
648
+ try {
649
+ data.schema = JSON.parse(schema);
650
+ } catch (error) {
651
+ data.schema = schema;
652
+ }
653
+ }
654
+ }
655
+ return {
656
+ ...data,
657
+ markdown: content.trim()
658
+ };
659
+ };
660
+ var getResourcePath = async (catalogDir, id, version) => {
661
+ const file = await findFileById(catalogDir, id, version);
662
+ if (!file) return;
663
+ return {
664
+ fullPath: file,
665
+ relativePath: file.replace(catalogDir, ""),
666
+ directory: (0, import_path.dirname)(file.replace(catalogDir, ""))
667
+ };
668
+ };
669
+ var getResourceFolderName = async (catalogDir, id, version) => {
670
+ const paths = await getResourcePath(catalogDir, id, version);
671
+ if (!paths) return;
672
+ return paths?.directory.split(import_node_path3.default.sep).filter(Boolean).pop();
673
+ };
674
+ var toResource = async (catalogDir, rawContents) => {
675
+ const { data, content } = (0, import_gray_matter2.default)(rawContents);
676
+ return {
677
+ ...data,
678
+ markdown: content.trim()
679
+ };
680
+ };
681
+ var getResources = async (catalogDir, {
682
+ type,
683
+ latestOnly = false,
684
+ ignore = [],
685
+ pattern = "",
686
+ attachSchema = false
687
+ }) => {
688
+ const ignoreList = latestOnly ? `**/versioned/**` : "";
689
+ const filePattern = pattern || `${catalogDir}/**/${type}/**/index.{md,mdx}`;
690
+ const files = await getFiles(filePattern, [ignoreList, ...ignore]);
691
+ if (files.length === 0) return;
692
+ return files.map((file) => {
693
+ const { data, content } = import_gray_matter2.default.read(file);
694
+ if (attachSchema && data?.schemaPath) {
695
+ const resourceDirectory = (0, import_path.dirname)(file);
696
+ const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
697
+ if (import_node_fs2.default.existsSync(pathToSchema)) {
698
+ const schema = import_node_fs2.default.readFileSync(pathToSchema, "utf8");
699
+ try {
700
+ data.schema = JSON.parse(schema);
701
+ } catch (error) {
702
+ data.schema = schema;
703
+ }
704
+ }
705
+ }
706
+ return {
707
+ ...data,
708
+ markdown: content.trim()
709
+ };
710
+ });
711
+ };
712
+ var rmResourceById = async (catalogDir, id, version, options) => {
713
+ const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
714
+ const matchedFiles = await searchFilesForId(files, id, version);
715
+ if (matchedFiles.length === 0) {
716
+ throw new Error(`No ${options?.type || "resource"} found with id: ${id}`);
717
+ }
718
+ if (options?.persistFiles) {
719
+ await Promise.all(
720
+ matchedFiles.map(async (file) => {
721
+ await import_promises.default.rm(file, { recursive: true });
722
+ await waitForFileRemoval(file);
723
+ })
724
+ );
725
+ } else {
726
+ await Promise.all(
727
+ matchedFiles.map(async (file) => {
728
+ const directory = (0, import_path.dirname)(file);
729
+ await import_promises.default.rm(directory, { recursive: true, force: true });
730
+ await waitForFileRemoval(directory);
731
+ })
732
+ );
733
+ }
734
+ };
735
+ var waitForFileRemoval = async (path6, maxRetries = 50, delay = 10) => {
736
+ for (let i = 0; i < maxRetries; i++) {
737
+ try {
738
+ await import_promises.default.access(path6);
739
+ await new Promise((resolve2) => setTimeout(resolve2, delay));
740
+ } catch (error) {
741
+ return;
742
+ }
743
+ }
744
+ throw new Error(`File/directory ${path6} was not removed after ${maxRetries} attempts`);
745
+ };
746
+ var addFileToResource = async (catalogDir, id, file, version, options) => {
747
+ let pathToResource;
748
+ if (options?.path) {
749
+ pathToResource = (0, import_path.join)(catalogDir, options.path, "index.mdx");
750
+ } else {
751
+ pathToResource = await findFileById(catalogDir, id, version);
752
+ }
753
+ if (!pathToResource) throw new Error("Cannot find directory to write file to");
754
+ import_node_fs2.default.mkdirSync(import_node_path3.default.dirname(pathToResource), { recursive: true });
755
+ let fileContent = file.content.trim();
756
+ try {
757
+ const json = JSON.parse(fileContent);
758
+ fileContent = JSON.stringify(json, null, 2);
759
+ } catch (error) {
760
+ }
761
+ import_node_fs2.default.writeFileSync((0, import_path.join)((0, import_path.dirname)(pathToResource), file.fileName), fileContent);
762
+ };
763
+ var getFileFromResource = async (catalogDir, id, file, version) => {
764
+ const pathToResource = await findFileById(catalogDir, id, version);
765
+ if (!pathToResource) throw new Error("Cannot find directory of resource");
766
+ const exists = await import_promises.default.access((0, import_path.join)((0, import_path.dirname)(pathToResource), file.fileName)).then(() => true).catch(() => false);
767
+ if (!exists) throw new Error(`File ${file.fileName} does not exist in resource ${id} v(${version})`);
768
+ return import_node_fs2.default.readFileSync((0, import_path.join)((0, import_path.dirname)(pathToResource), file.fileName), "utf-8");
769
+ };
770
+ var getVersionedDirectory = (sourceDirectory, version) => {
771
+ return (0, import_path.join)(sourceDirectory, "versioned", version);
772
+ };
773
+ var isLatestVersion = async (catalogDir, id, version) => {
774
+ const resource = await getResource(catalogDir, id, version);
775
+ if (!resource) return false;
776
+ const pathToResource = await getResourcePath(catalogDir, id, version);
777
+ return !pathToResource?.relativePath.replace(/\\/g, "/").includes("/versioned/");
778
+ };
779
+
780
+ // src/events.ts
781
+ var getEvent = (directory) => async (id, version, options) => getResource(directory, id, version, { type: "event", ...options });
782
+ var getEvents = (directory) => async (options) => getResources(directory, { type: "events", ...options });
783
+ var writeEvent = (directory) => async (event, options = {
784
+ path: "",
785
+ override: false,
786
+ format: "mdx"
787
+ }) => writeResource(directory, { ...event }, { ...options, type: "event" });
788
+ var writeEventToService = (directory) => async (event, service, options = { path: "", format: "mdx", override: false }) => {
789
+ const resourcePath = await getResourcePath(directory, service.id, service.version);
790
+ if (!resourcePath) {
791
+ throw new Error("Service not found");
792
+ }
793
+ let pathForEvent = service.version && service.version !== "latest" ? `${resourcePath.directory}/versioned/${service.version}/events` : `${resourcePath.directory}/events`;
794
+ pathForEvent = (0, import_node_path4.join)(pathForEvent, event.id);
795
+ await writeResource(directory, { ...event }, { ...options, path: pathForEvent, type: "event" });
796
+ };
797
+ var rmEvent = (directory) => async (path6) => {
798
+ await import_promises2.default.rm((0, import_node_path4.join)(directory, path6), { recursive: true });
799
+ };
800
+ var rmEventById = (directory) => async (id, version, persistFiles) => {
801
+ await rmResourceById(directory, id, version, { type: "event", persistFiles });
802
+ };
803
+ var versionEvent = (directory) => async (id) => versionResource(directory, id);
804
+ var addFileToEvent = (directory) => async (id, file, version, options) => addFileToResource(directory, id, file, version, options);
805
+ var addSchemaToEvent = (directory) => async (id, schema, version, options) => {
806
+ await addFileToEvent(directory)(id, { content: schema.schema, fileName: schema.fileName }, version, options);
807
+ };
808
+ var eventHasVersion = (directory) => async (id, version) => {
809
+ const file = await findFileById(directory, id, version);
810
+ return !!file;
811
+ };
812
+
813
+ // src/commands.ts
814
+ var import_promises3 = __toESM(require("fs/promises"));
815
+ var import_node_path5 = require("path");
816
+ var getCommand = (directory) => async (id, version, options) => getResource(directory, id, version, { type: "command", ...options });
817
+ var getCommands = (directory) => async (options) => getResources(directory, { type: "commands", ...options });
818
+ var writeCommand = (directory) => async (command, options = {
819
+ path: "",
820
+ override: false,
821
+ versionExistingContent: false,
822
+ format: "mdx"
823
+ }) => writeResource(directory, { ...command }, { ...options, type: "command" });
824
+ var writeCommandToService = (directory) => async (command, service, options = { path: "", format: "mdx", override: false }) => {
825
+ const resourcePath = await getResourcePath(directory, service.id, service.version);
826
+ if (!resourcePath) {
827
+ throw new Error("Service not found");
828
+ }
829
+ let pathForCommand = service.version && service.version !== "latest" ? `${resourcePath.directory}/versioned/${service.version}/commands` : `${resourcePath.directory}/commands`;
830
+ pathForCommand = (0, import_node_path5.join)(pathForCommand, command.id);
831
+ await writeResource(directory, { ...command }, { ...options, path: pathForCommand, type: "command" });
832
+ };
833
+ var rmCommand = (directory) => async (path6) => {
834
+ await import_promises3.default.rm((0, import_node_path5.join)(directory, path6), { recursive: true });
835
+ };
836
+ var rmCommandById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "command", persistFiles });
837
+ var versionCommand = (directory) => async (id) => versionResource(directory, id);
838
+ var addFileToCommand = (directory) => async (id, file, version, options) => addFileToResource(directory, id, file, version, options);
839
+ var addSchemaToCommand = (directory) => async (id, schema, version, options) => {
840
+ await addFileToCommand(directory)(id, { content: schema.schema, fileName: schema.fileName }, version, options);
841
+ };
842
+ var commandHasVersion = (directory) => async (id, version) => {
843
+ const file = await findFileById(directory, id, version);
844
+ return !!file;
845
+ };
846
+
847
+ // src/queries.ts
848
+ var import_promises4 = __toESM(require("fs/promises"));
849
+ var import_node_path6 = require("path");
850
+ var getQuery = (directory) => async (id, version, options) => getResource(directory, id, version, { type: "query", ...options });
851
+ var writeQuery = (directory) => async (query, options = {
852
+ path: "",
853
+ override: false,
854
+ versionExistingContent: false,
855
+ format: "mdx"
856
+ }) => writeResource(directory, { ...query }, { ...options, type: "query" });
857
+ var getQueries = (directory) => async (options) => getResources(directory, { type: "queries", ...options });
858
+ var writeQueryToService = (directory) => async (query, service, options = { path: "", format: "mdx", override: false }) => {
859
+ const resourcePath = await getResourcePath(directory, service.id, service.version);
860
+ if (!resourcePath) {
861
+ throw new Error("Service not found");
862
+ }
863
+ let pathForQuery = service.version && service.version !== "latest" ? `${resourcePath.directory}/versioned/${service.version}/queries` : `${resourcePath.directory}/queries`;
864
+ pathForQuery = (0, import_node_path6.join)(pathForQuery, query.id);
865
+ await writeResource(directory, { ...query }, { ...options, path: pathForQuery, type: "query" });
866
+ };
867
+ var rmQuery = (directory) => async (path6) => {
868
+ await import_promises4.default.rm((0, import_node_path6.join)(directory, path6), { recursive: true });
869
+ };
870
+ var rmQueryById = (directory) => async (id, version, persistFiles) => {
871
+ await rmResourceById(directory, id, version, { type: "query", persistFiles });
872
+ };
873
+ var versionQuery = (directory) => async (id) => versionResource(directory, id);
874
+ var addFileToQuery = (directory) => async (id, file, version, options) => addFileToResource(directory, id, file, version, options);
875
+ var addSchemaToQuery = (directory) => async (id, schema, version, options) => {
876
+ await addFileToQuery(directory)(id, { content: schema.schema, fileName: schema.fileName }, version, options);
877
+ };
878
+ var queryHasVersion = (directory) => async (id, version) => {
879
+ const file = await findFileById(directory, id, version);
880
+ return !!file;
881
+ };
882
+
883
+ // src/services.ts
884
+ var import_promises5 = __toESM(require("fs/promises"));
885
+ var import_node_path7 = require("path");
886
+ var getService = (directory) => async (id, version) => getResource(directory, id, version, { type: "service" });
887
+ var getServiceByPath = (directory) => async (path6) => {
888
+ const service = await getResource(directory, void 0, void 0, { type: "service" }, path6);
889
+ return service;
890
+ };
891
+ var getServices = (directory) => async (options) => getResources(directory, {
892
+ type: "services",
893
+ ignore: [
894
+ "**/events/**",
895
+ "**/commands/**",
896
+ "**/queries/**",
897
+ "**/entities/**",
898
+ "**/channels/**",
899
+ "**/containers/**",
900
+ "**/data-products/**",
901
+ "**/data-stores/**",
902
+ "**/flows/**",
903
+ "**/subdomains/**/entities/**"
904
+ ],
905
+ ...options
906
+ });
907
+ var writeService = (directory) => async (service, options = {
908
+ path: "",
909
+ override: false,
910
+ format: "mdx"
911
+ }) => {
912
+ const resource = { ...service };
913
+ if (Array.isArray(service.sends)) {
914
+ resource.sends = uniqueVersions(service.sends);
915
+ }
916
+ if (Array.isArray(service.receives)) {
917
+ resource.receives = uniqueVersions(service.receives);
918
+ }
919
+ return await writeResource(directory, resource, { ...options, type: "service" });
920
+ };
921
+ var writeVersionedService = (directory) => async (service) => {
922
+ const resource = { ...service };
923
+ const path6 = getVersionedDirectory(service.id, service.version);
924
+ return await writeService(directory)(resource, { path: path6 });
925
+ };
926
+ var writeServiceToDomain = (directory) => async (service, domain, options = { path: "", format: "mdx", override: false }) => {
927
+ let pathForService = domain.version && domain.version !== "latest" ? `/${domain.id}/versioned/${domain.version}/services` : `/${domain.id}/services`;
928
+ pathForService = (0, import_node_path7.join)(pathForService, service.id);
929
+ await writeResource(directory, { ...service }, { ...options, path: pathForService, type: "service" });
930
+ };
931
+ var versionService = (directory) => async (id) => versionResource(directory, id);
932
+ var rmService = (directory) => async (path6) => {
933
+ await import_promises5.default.rm((0, import_node_path7.join)(directory, path6), { recursive: true });
934
+ };
935
+ var rmServiceById = (directory) => async (id, version, persistFiles) => {
936
+ await rmResourceById(directory, id, version, { type: "service", persistFiles });
937
+ };
938
+ var addFileToService = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
939
+ var getSpecificationFilesForService = (directory) => async (id, version) => {
940
+ let service = await getService(directory)(id, version);
941
+ const filePathToService = await findFileById(directory, id, version);
942
+ if (!filePathToService) throw new Error("Cannot find directory of service");
943
+ let specs = [];
944
+ if (service.specifications) {
945
+ const serviceSpecifications = service.specifications;
946
+ let specificationFiles;
947
+ if (Array.isArray(serviceSpecifications)) {
948
+ specificationFiles = serviceSpecifications.map((spec) => ({ key: spec.type, path: spec.path }));
949
+ } else {
950
+ specificationFiles = Object.keys(serviceSpecifications).map((spec) => ({
951
+ key: spec,
952
+ path: serviceSpecifications[spec]
953
+ }));
954
+ }
955
+ const getSpecs = specificationFiles.map(async ({ key, path: fileName }) => {
956
+ if (!fileName) {
957
+ throw new Error(`Specification file name for ${fileName} is undefined`);
958
+ }
959
+ const rawFile = await getFileFromResource(directory, id, { fileName }, version);
960
+ return { key, content: rawFile, fileName, path: (0, import_node_path7.join)((0, import_node_path7.dirname)(filePathToService), fileName) };
961
+ });
962
+ specs = await Promise.all(getSpecs);
963
+ }
964
+ return specs;
965
+ };
966
+ var addMessageToService = (directory) => async (id, direction, event, version) => {
967
+ let service = await getService(directory)(id, version);
968
+ const servicePath = await getResourcePath(directory, id, version);
969
+ const extension = (0, import_node_path7.extname)(servicePath?.fullPath || "");
970
+ if (direction === "sends") {
971
+ if (service.sends === void 0) {
972
+ service.sends = [];
973
+ }
974
+ for (let i = 0; i < service.sends.length; i++) {
975
+ if (service.sends[i].id === event.id && service.sends[i].version === event.version) {
976
+ return;
977
+ }
978
+ }
979
+ service.sends.push({ id: event.id, version: event.version });
980
+ } else if (direction === "receives") {
981
+ if (service.receives === void 0) {
982
+ service.receives = [];
983
+ }
984
+ for (let i = 0; i < service.receives.length; i++) {
985
+ if (service.receives[i].id === event.id && service.receives[i].version === event.version) {
986
+ return;
987
+ }
988
+ }
989
+ service.receives.push({ id: event.id, version: event.version });
990
+ } else {
991
+ throw new Error(`Direction ${direction} is invalid, only 'receives' and 'sends' are supported`);
992
+ }
993
+ const existingResource = await findFileById(directory, id, version);
994
+ if (!existingResource) {
995
+ throw new Error(`Cannot find service ${id} in the catalog`);
996
+ }
997
+ const path6 = existingResource.split(/[\\/]+services/)[0];
998
+ const pathToResource = (0, import_node_path7.join)(path6, "services");
999
+ await rmServiceById(directory)(id, version);
1000
+ await writeService(pathToResource)(service, { format: extension === ".md" ? "md" : "mdx" });
1001
+ };
1002
+ var serviceHasVersion = (directory) => async (id, version) => {
1003
+ const file = await findFileById(directory, id, version);
1004
+ return !!file;
1005
+ };
1006
+ var isService = (directory) => async (path6) => {
1007
+ const service = await getServiceByPath(directory)(path6);
1008
+ const relativePath = (0, import_node_path7.relative)(directory, path6);
1009
+ const segments = relativePath.split(/[/\\]+/);
1010
+ return !!service && segments.includes("services");
1011
+ };
1012
+ var toService = (directory) => async (file) => toResource(directory, file);
1013
+ var addEntityToService = (directory) => async (id, entity, version) => {
1014
+ let service = await getService(directory)(id, version);
1015
+ const servicePath = await getResourcePath(directory, id, version);
1016
+ const extension = (0, import_node_path7.extname)(servicePath?.fullPath || "");
1017
+ if (service.entities === void 0) {
1018
+ service.entities = [];
1019
+ }
1020
+ for (let i = 0; i < service.entities.length; i++) {
1021
+ if (service.entities[i].id === entity.id && service.entities[i].version === entity.version) {
1022
+ return;
1023
+ }
1024
+ }
1025
+ service.entities.push({ id: entity.id, version: entity.version });
1026
+ const existingResource = await findFileById(directory, id, version);
1027
+ if (!existingResource) {
1028
+ throw new Error(`Cannot find service ${id} in the catalog`);
1029
+ }
1030
+ const path6 = existingResource.split(/[\\/]+services/)[0];
1031
+ const pathToResource = (0, import_node_path7.join)(path6, "services");
1032
+ await rmServiceById(directory)(id, version);
1033
+ await writeService(pathToResource)(service, { format: extension === ".md" ? "md" : "mdx" });
1034
+ };
1035
+ var addDataStoreToService = (directory) => async (id, operation, dataStore, version) => {
1036
+ let service = await getService(directory)(id, version);
1037
+ const servicePath = await getResourcePath(directory, id, version);
1038
+ const extension = (0, import_node_path7.extname)(servicePath?.fullPath || "");
1039
+ if (operation === "writesTo") {
1040
+ if (service.writesTo === void 0) {
1041
+ service.writesTo = [];
1042
+ }
1043
+ for (let i = 0; i < service.writesTo.length; i++) {
1044
+ if (service.writesTo[i].id === dataStore.id && service.writesTo[i].version === dataStore.version) {
1045
+ return;
1046
+ }
1047
+ }
1048
+ service.writesTo.push({ id: dataStore.id, version: dataStore.version });
1049
+ } else if (operation === "readsFrom") {
1050
+ if (service.readsFrom === void 0) {
1051
+ service.readsFrom = [];
1052
+ }
1053
+ for (let i = 0; i < service.readsFrom.length; i++) {
1054
+ if (service.readsFrom[i].id === dataStore.id && service.readsFrom[i].version === dataStore.version) {
1055
+ return;
1056
+ }
1057
+ }
1058
+ service.readsFrom.push({ id: dataStore.id, version: dataStore.version });
1059
+ } else {
1060
+ throw new Error(`Operation ${operation} is invalid, only 'writesTo' and 'readsFrom' are supported`);
1061
+ }
1062
+ const existingResource = await findFileById(directory, id, version);
1063
+ if (!existingResource) {
1064
+ throw new Error(`Cannot find service ${id} in the catalog`);
1065
+ }
1066
+ const path6 = existingResource.split(/[\\/]+services/)[0];
1067
+ const pathToResource = (0, import_node_path7.join)(path6, "services");
1068
+ await rmServiceById(directory)(id, version);
1069
+ await writeService(pathToResource)(service, { format: extension === ".md" ? "md" : "mdx" });
1070
+ };
1071
+
1072
+ // src/domains.ts
1073
+ var import_promises6 = __toESM(require("fs/promises"));
1074
+ var import_node_path8 = __toESM(require("path"));
1075
+ var import_node_fs3 = __toESM(require("fs"));
1076
+ var import_gray_matter3 = __toESM(require("gray-matter"));
1077
+ var getDomain = (directory) => async (id, version) => getResource(directory, id, version, { type: "domain" });
1078
+ var getDomains = (directory) => async (options) => getResources(directory, {
1079
+ type: "domains",
1080
+ ignore: ["**/services/**", "**/events/**", "**/commands/**", "**/queries/**", "**/flows/**", "**/entities/**"],
1081
+ ...options
1082
+ });
1083
+ var writeDomain = (directory) => async (domain, options = {
1084
+ path: "",
1085
+ override: false,
1086
+ versionExistingContent: false,
1087
+ format: "mdx"
1088
+ }) => {
1089
+ const resource = { ...domain };
1090
+ if (Array.isArray(domain.services)) {
1091
+ resource.services = uniqueVersions(domain.services);
1092
+ }
1093
+ if (Array.isArray(domain.domains)) {
1094
+ resource.domains = uniqueVersions(domain.domains);
1095
+ }
1096
+ if (Array.isArray(domain.sends)) {
1097
+ resource.sends = uniqueVersions(domain.sends);
1098
+ }
1099
+ if (Array.isArray(domain.receives)) {
1100
+ resource.receives = uniqueVersions(domain.receives);
1101
+ }
1102
+ if (Array.isArray(domain.dataProducts)) {
1103
+ resource.dataProducts = uniqueVersions(domain.dataProducts);
1104
+ }
1105
+ return await writeResource(directory, resource, { ...options, type: "domain" });
1106
+ };
1107
+ var versionDomain = (directory) => async (id) => versionResource(directory, id);
1108
+ var rmDomain = (directory) => async (path6) => {
1109
+ await import_promises6.default.rm((0, import_node_path8.join)(directory, path6), { recursive: true });
1110
+ };
1111
+ var rmDomainById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "domain", persistFiles });
1112
+ var addFileToDomain = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
1113
+ var addUbiquitousLanguageToDomain = (directory) => async (id, ubiquitousLanguageDictionary, version) => {
1114
+ const content = import_gray_matter3.default.stringify("", {
1115
+ ...ubiquitousLanguageDictionary
1116
+ });
1117
+ await addFileToResource(directory, id, { content, fileName: "ubiquitous-language.mdx" }, version);
1118
+ };
1119
+ var getUbiquitousLanguageFromDomain = (directory) => async (id, version) => {
1120
+ const pathToDomain = await findFileById(directory, id, version) || "";
1121
+ const pathToUbiquitousLanguage = import_node_path8.default.join(import_node_path8.default.dirname(pathToDomain), "ubiquitous-language.mdx");
1122
+ const fileExists = import_node_fs3.default.existsSync(pathToUbiquitousLanguage);
1123
+ if (!fileExists) {
1124
+ return void 0;
1125
+ }
1126
+ const content = await readMdxFile(pathToUbiquitousLanguage);
1127
+ return content;
1128
+ };
1129
+ var domainHasVersion = (directory) => async (id, version) => {
1130
+ const file = await findFileById(directory, id, version);
1131
+ return !!file;
1132
+ };
1133
+ var addServiceToDomain = (directory) => async (id, service, version) => {
1134
+ let domain = await getDomain(directory)(id, version);
1135
+ const domainPath = await getResourcePath(directory, id, version);
1136
+ const extension = import_node_path8.default.extname(domainPath?.fullPath || "");
1137
+ if (domain.services === void 0) {
1138
+ domain.services = [];
1139
+ }
1140
+ const serviceExistsInList = domain.services.some((s) => s.id === service.id && s.version === service.version);
1141
+ if (serviceExistsInList) {
1142
+ return;
1143
+ }
1144
+ domain.services.push(service);
1145
+ await rmDomainById(directory)(id, version, true);
1146
+ await writeDomain(directory)(domain, { format: extension === ".md" ? "md" : "mdx" });
1147
+ };
1148
+ var addSubDomainToDomain = (directory) => async (id, subDomain, version) => {
1149
+ let domain = await getDomain(directory)(id, version);
1150
+ const domainPath = await getResourcePath(directory, id, version);
1151
+ const extension = import_node_path8.default.extname(domainPath?.fullPath || "");
1152
+ if (domain.domains === void 0) {
1153
+ domain.domains = [];
1154
+ }
1155
+ const subDomainExistsInList = domain.domains.some((s) => s.id === subDomain.id && s.version === subDomain.version);
1156
+ if (subDomainExistsInList) {
1157
+ return;
1158
+ }
1159
+ domain.domains.push(subDomain);
1160
+ await rmDomainById(directory)(id, version, true);
1161
+ await writeDomain(directory)(domain, { format: extension === ".md" ? "md" : "mdx" });
1162
+ };
1163
+ var addEntityToDomain = (directory) => async (id, entity, version) => {
1164
+ let domain = await getDomain(directory)(id, version);
1165
+ const domainPath = await getResourcePath(directory, id, version);
1166
+ const extension = import_node_path8.default.extname(domainPath?.fullPath || "");
1167
+ if (domain.entities === void 0) {
1168
+ domain.entities = [];
1169
+ }
1170
+ const entityExistsInList = domain.entities.some((e) => e.id === entity.id && e.version === entity.version);
1171
+ if (entityExistsInList) {
1172
+ return;
1173
+ }
1174
+ domain.entities.push(entity);
1175
+ await rmDomainById(directory)(id, version, true);
1176
+ await writeDomain(directory)(domain, { format: extension === ".md" ? "md" : "mdx" });
1177
+ };
1178
+ var addDataProductToDomain = (directory) => async (id, dataProduct, version) => {
1179
+ let domain = await getDomain(directory)(id, version);
1180
+ const domainPath = await getResourcePath(directory, id, version);
1181
+ const extension = import_node_path8.default.extname(domainPath?.fullPath || "");
1182
+ if (domain.dataProducts === void 0) {
1183
+ domain.dataProducts = [];
1184
+ }
1185
+ const dataProductExistsInList = domain.dataProducts.some(
1186
+ (dp) => dp.id === dataProduct.id && dp.version === dataProduct.version
1187
+ );
1188
+ if (dataProductExistsInList) {
1189
+ return;
1190
+ }
1191
+ domain.dataProducts.push(dataProduct);
1192
+ await rmDomainById(directory)(id, version, true);
1193
+ await writeDomain(directory)(domain, { format: extension === ".md" ? "md" : "mdx" });
1194
+ };
1195
+ var addMessageToDomain = (directory) => async (id, direction, message, version) => {
1196
+ let domain = await getDomain(directory)(id, version);
1197
+ const domainPath = await getResourcePath(directory, id, version);
1198
+ const extension = import_node_path8.default.extname(domainPath?.fullPath || "");
1199
+ if (direction === "sends") {
1200
+ if (domain.sends === void 0) {
1201
+ domain.sends = [];
1202
+ }
1203
+ for (let i = 0; i < domain.sends.length; i++) {
1204
+ if (domain.sends[i].id === message.id && domain.sends[i].version === message.version) {
1205
+ return;
1206
+ }
1207
+ }
1208
+ domain.sends.push({ id: message.id, version: message.version });
1209
+ } else if (direction === "receives") {
1210
+ if (domain.receives === void 0) {
1211
+ domain.receives = [];
1212
+ }
1213
+ for (let i = 0; i < domain.receives.length; i++) {
1214
+ if (domain.receives[i].id === message.id && domain.receives[i].version === message.version) {
1215
+ return;
1216
+ }
1217
+ }
1218
+ domain.receives.push({ id: message.id, version: message.version });
1219
+ } else {
1220
+ throw new Error(`Direction ${direction} is invalid, only 'receives' and 'sends' are supported`);
1221
+ }
1222
+ const existingResource = await findFileById(directory, id, version);
1223
+ if (!existingResource) {
1224
+ throw new Error(`Cannot find domain ${id} in the catalog`);
1225
+ }
1226
+ const normalizedPath = existingResource.replace(/\\/g, "/");
1227
+ const lastDomainsIndex = normalizedPath.lastIndexOf("/domains/");
1228
+ const pathToResource = existingResource.substring(0, lastDomainsIndex + "/domains".length);
1229
+ await rmDomainById(directory)(id, version, true);
1230
+ await writeDomain(pathToResource)(domain, { format: extension === ".md" ? "md" : "mdx" });
1231
+ };
1232
+
1233
+ // src/channels.ts
1234
+ var import_promises7 = __toESM(require("fs/promises"));
1235
+ var import_node_path9 = require("path");
1236
+ var getChannel = (directory) => async (id, version) => getResource(directory, id, version, { type: "channel" });
1237
+ var getChannels = (directory) => async (options) => getResources(directory, { type: "channels", ...options });
1238
+ var writeChannel = (directory) => async (channel, options = { path: "" }) => writeResource(directory, { ...channel }, { ...options, type: "channel" });
1239
+ var rmChannel = (directory) => async (path6) => {
1240
+ await import_promises7.default.rm((0, import_node_path9.join)(directory, path6), { recursive: true });
1241
+ };
1242
+ var rmChannelById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "channel", persistFiles });
1243
+ var versionChannel = (directory) => async (id) => versionResource(directory, id);
1244
+ var channelHasVersion = (directory) => async (id, version) => {
1245
+ const file = await findFileById(directory, id, version);
1246
+ return !!file;
1247
+ };
1248
+ var addMessageToChannel = (directory, collection) => async (id, _message, version) => {
1249
+ let channel = await getChannel(directory)(id, version);
1250
+ const functions = {
1251
+ events: {
1252
+ getMessage: getEvent,
1253
+ rmMessageById: rmEventById,
1254
+ writeMessage: writeEvent
1255
+ },
1256
+ commands: {
1257
+ getMessage: getCommand,
1258
+ rmMessageById: rmCommandById,
1259
+ writeMessage: writeCommand
1260
+ },
1261
+ queries: {
1262
+ getMessage: getQuery,
1263
+ rmMessageById: rmQueryById,
1264
+ writeMessage: writeQuery
1265
+ }
1266
+ };
1267
+ const { getMessage: getMessage2, rmMessageById, writeMessage } = functions[collection];
1268
+ const message = await getMessage2(directory)(_message.id, _message.version);
1269
+ const messagePath = await getResourcePath(directory, _message.id, _message.version);
1270
+ const extension = (0, import_node_path9.extname)(messagePath?.fullPath || "");
1271
+ if (!message) throw new Error(`Message ${_message.id} with version ${_message.version} not found`);
1272
+ if (message.channels === void 0) {
1273
+ message.channels = [];
1274
+ }
1275
+ const channelInfo = { id, version: channel.version, ..._message.parameters && { parameters: _message.parameters } };
1276
+ message.channels.push(channelInfo);
1277
+ const existingResource = await findFileById(directory, _message.id, _message.version);
1278
+ if (!existingResource) {
1279
+ throw new Error(`Cannot find message ${id} in the catalog`);
1280
+ }
1281
+ const path6 = existingResource.split(`/[\\/]+${collection}`)[0];
1282
+ const pathToResource = (0, import_node_path9.join)(path6, collection);
1283
+ await rmMessageById(directory)(_message.id, _message.version, true);
1284
+ await writeMessage(pathToResource)(message, { format: extension === ".md" ? "md" : "mdx" });
1285
+ };
1286
+
1287
+ // src/messages.ts
1288
+ var import_node_path10 = require("path");
1289
+ var import_gray_matter4 = __toESM(require("gray-matter"));
1290
+ var import_semver3 = require("semver");
1291
+ var getMessageBySchemaPath = (directory) => async (path6, options) => {
1292
+ const pathToMessage = (0, import_node_path10.dirname)(path6);
1293
+ try {
1294
+ const files = await getFiles(`${directory}/${pathToMessage}/index.{md,mdx}`);
1295
+ if (!files || files.length === 0) {
1296
+ throw new Error(`No message definition file (index.md or index.mdx) found in directory: ${pathToMessage}`);
1297
+ }
1298
+ const messageFile = files[0];
1299
+ const { data } = import_gray_matter4.default.read(messageFile);
1300
+ const { id, version } = data;
1301
+ if (!id || !version) {
1302
+ throw new Error(`Message definition file at ${messageFile} is missing 'id' or 'version' in its frontmatter.`);
1303
+ }
1304
+ const message = await getResource(directory, id, version, { type: "message", ...options });
1305
+ if (!message) {
1306
+ throw new Error(`Message resource with id '${id}' and version '${version}' not found, as referenced in ${messageFile}.`);
1307
+ }
1308
+ return message;
1309
+ } catch (error) {
1310
+ if (error instanceof Error) {
1311
+ error.message = `Failed to retrieve message from ${pathToMessage}: ${error.message}`;
1312
+ throw error;
1313
+ }
1314
+ throw new Error(`Failed to retrieve message from ${pathToMessage} due to an unknown error.`);
1315
+ }
1316
+ };
1317
+ var getProducersAndConsumersForMessage = (directory) => async (id, version, options) => {
1318
+ const services = await getServices(directory)({ latestOnly: options?.latestOnly ?? true });
1319
+ const message = await getResource(directory, id, version, { type: "message" });
1320
+ const isMessageLatestVersion = await isLatestVersion(directory, id, version);
1321
+ if (!message) {
1322
+ throw new Error(`Message resource with id '${id}' and version '${version}' not found.`);
1323
+ }
1324
+ const producers = [];
1325
+ const consumers = [];
1326
+ for (const service of services) {
1327
+ const servicePublishesMessage = service.sends?.some((_message) => {
1328
+ if (_message.version) {
1329
+ const isServiceUsingSemverRange = (0, import_semver3.validRange)(_message.version);
1330
+ if (isServiceUsingSemverRange) {
1331
+ return _message.id === message.id && (0, import_semver3.satisfies)(message.version, _message.version);
1332
+ } else {
1333
+ return _message.id === message.id && message.version === _message.version;
1334
+ }
1335
+ }
1336
+ if (isMessageLatestVersion && _message.id === message.id) {
1337
+ return true;
1338
+ }
1339
+ return false;
1340
+ });
1341
+ const serviceSubscribesToMessage = service.receives?.some((_message) => {
1342
+ if (_message.version) {
1343
+ const isServiceUsingSemverRange = (0, import_semver3.validRange)(_message.version);
1344
+ if (isServiceUsingSemverRange) {
1345
+ return _message.id === message.id && (0, import_semver3.satisfies)(message.version, _message.version);
1346
+ } else {
1347
+ return _message.id === message.id && message.version === _message.version;
1348
+ }
1349
+ }
1350
+ if (isMessageLatestVersion && _message.id === message.id) {
1351
+ return true;
1352
+ }
1353
+ return false;
1354
+ });
1355
+ if (servicePublishesMessage) {
1356
+ producers.push(service);
1357
+ }
1358
+ if (serviceSubscribesToMessage) {
1359
+ consumers.push(service);
1360
+ }
1361
+ }
1362
+ return { producers, consumers };
1363
+ };
1364
+ var getConsumersOfSchema = (directory) => async (path6) => {
1365
+ try {
1366
+ const message = await getMessageBySchemaPath(directory)(path6);
1367
+ const { consumers } = await getProducersAndConsumersForMessage(directory)(message.id, message.version);
1368
+ return consumers;
1369
+ } catch (error) {
1370
+ return [];
1371
+ }
1372
+ };
1373
+ var getProducersOfSchema = (directory) => async (path6) => {
1374
+ try {
1375
+ const message = await getMessageBySchemaPath(directory)(path6);
1376
+ const { producers } = await getProducersAndConsumersForMessage(directory)(message.id, message.version);
1377
+ return producers;
1378
+ } catch (error) {
1379
+ return [];
1380
+ }
1381
+ };
1382
+
1383
+ // src/custom-docs.ts
1384
+ var import_node_path11 = __toESM(require("path"));
1385
+ var import_node_fs4 = __toESM(require("fs"));
1386
+ var import_promises8 = __toESM(require("fs/promises"));
1387
+ var import_gray_matter5 = __toESM(require("gray-matter"));
1388
+ var import_slugify = __toESM(require("slugify"));
1389
+ var getCustomDoc = (directory) => async (filePath) => {
1390
+ const fullPath = import_node_path11.default.join(directory, filePath);
1391
+ const fullPathWithExtension = fullPath.endsWith(".mdx") ? fullPath : `${fullPath}.mdx`;
1392
+ const fileExists = import_node_fs4.default.existsSync(fullPathWithExtension);
1393
+ if (!fileExists) {
1394
+ return void 0;
1395
+ }
1396
+ return readMdxFile(fullPathWithExtension);
1397
+ };
1398
+ var getCustomDocs = (directory) => async (options) => {
1399
+ if (options?.path) {
1400
+ const pattern = `${directory}/${options.path}/**/*.{md,mdx}`;
1401
+ return getResources(directory, { type: "docs", pattern });
1402
+ }
1403
+ return getResources(directory, { type: "docs", pattern: `${directory}/**/*.{md,mdx}` });
1404
+ };
1405
+ var writeCustomDoc = (directory) => async (customDoc, options = { path: "" }) => {
1406
+ const { fileName, ...rest } = customDoc;
1407
+ const name = fileName || (0, import_slugify.default)(customDoc.title, { lower: true });
1408
+ const withExtension = name.endsWith(".mdx") ? name : `${name}.mdx`;
1409
+ const fullPath = import_node_path11.default.join(directory, options.path || "", withExtension);
1410
+ import_node_fs4.default.mkdirSync(import_node_path11.default.dirname(fullPath), { recursive: true });
1411
+ const document = import_gray_matter5.default.stringify(customDoc.markdown.trim(), rest);
1412
+ import_node_fs4.default.writeFileSync(fullPath, document);
1413
+ };
1414
+ var rmCustomDoc = (directory) => async (filePath) => {
1415
+ const withExtension = filePath.endsWith(".mdx") ? filePath : `${filePath}.mdx`;
1416
+ await import_promises8.default.rm((0, import_node_path11.join)(directory, withExtension), { recursive: true });
1417
+ };
1418
+
1419
+ // src/teams.ts
1420
+ var import_promises9 = __toESM(require("fs/promises"));
1421
+ var import_node_fs6 = __toESM(require("fs"));
1422
+ var import_node_path13 = require("path");
1423
+ var import_gray_matter7 = __toESM(require("gray-matter"));
1424
+ var import_node_path14 = __toESM(require("path"));
1425
+
1426
+ // src/users.ts
1427
+ var import_node_fs5 = __toESM(require("fs"));
1428
+ var import_node_path12 = require("path");
1429
+ var import_gray_matter6 = __toESM(require("gray-matter"));
1430
+ var getUser = (catalogDir) => async (id) => {
1431
+ const files = await getFiles(`${catalogDir}/${id}.{md,mdx}`);
1432
+ if (files.length == 0) return void 0;
1433
+ const file = files[0];
1434
+ const { data, content } = import_gray_matter6.default.read(file);
1435
+ return {
1436
+ ...data,
1437
+ id: data.id,
1438
+ name: data.name,
1439
+ avatarUrl: data.avatarUrl,
1440
+ markdown: content.trim()
1441
+ };
1442
+ };
1443
+ var getUsers = (catalogDir) => async (options) => {
1444
+ const files = await getFiles(`${catalogDir}/users/*.{md,mdx}`);
1445
+ if (files.length === 0) return [];
1446
+ return files.map((file) => {
1447
+ const { data, content } = import_gray_matter6.default.read(file);
1448
+ return {
1449
+ ...data,
1450
+ id: data.id,
1451
+ name: data.name,
1452
+ avatarUrl: data.avatarUrl,
1453
+ markdown: content.trim()
1454
+ };
1455
+ });
1456
+ };
1457
+ var writeUser = (catalogDir) => async (user, options = {}) => {
1458
+ const resource = { ...user };
1459
+ const currentUser = await getUser(catalogDir)(resource.id);
1460
+ const exists = currentUser !== void 0;
1461
+ if (exists && !options.override) {
1462
+ throw new Error(`Failed to write ${resource.id} (user) as it already exists`);
1463
+ }
1464
+ const { markdown, ...frontmatter } = resource;
1465
+ const document = import_gray_matter6.default.stringify(markdown, frontmatter);
1466
+ import_node_fs5.default.mkdirSync((0, import_node_path12.join)(catalogDir, ""), { recursive: true });
1467
+ import_node_fs5.default.writeFileSync((0, import_node_path12.join)(catalogDir, "", `${resource.id}.mdx`), document);
1468
+ };
1469
+ var rmUserById = (catalogDir) => async (id) => {
1470
+ import_node_fs5.default.rmSync((0, import_node_path12.join)(catalogDir, `${id}.mdx`), { recursive: true });
1471
+ };
1472
+
1473
+ // src/teams.ts
1474
+ var getTeam = (catalogDir) => async (id) => {
1475
+ const files = await getFiles(`${catalogDir}/${id}.{md,mdx}`);
1476
+ if (files.length == 0) return void 0;
1477
+ const file = files[0];
1478
+ const { data, content } = import_gray_matter7.default.read(file);
1479
+ return {
1480
+ ...data,
1481
+ id: data.id,
1482
+ name: data.name,
1483
+ markdown: content.trim()
1484
+ };
1485
+ };
1486
+ var getTeams = (catalogDir) => async (options) => {
1487
+ const files = await getFiles(`${catalogDir}/*.{md,mdx}`);
1488
+ if (files.length === 0) return [];
1489
+ return files.map((file) => {
1490
+ const { data, content } = import_gray_matter7.default.read(file);
1491
+ return {
1492
+ ...data,
1493
+ id: data.id,
1494
+ name: data.name,
1495
+ markdown: content.trim()
1496
+ };
1497
+ });
1498
+ };
1499
+ var writeTeam = (catalogDir) => async (team, options = {}) => {
1500
+ const resource = { ...team };
1501
+ const currentTeam = await getTeam(catalogDir)(resource.id);
1502
+ const exists = currentTeam !== void 0;
1503
+ if (exists && !options.override) {
1504
+ throw new Error(`Failed to write ${resource.id} (team) as it already exists`);
1505
+ }
1506
+ const { markdown, ...frontmatter } = resource;
1507
+ const document = import_gray_matter7.default.stringify(markdown, frontmatter);
1508
+ import_node_fs6.default.mkdirSync((0, import_node_path13.join)(catalogDir, ""), { recursive: true });
1509
+ import_node_fs6.default.writeFileSync((0, import_node_path13.join)(catalogDir, "", `${resource.id}.mdx`), document);
1510
+ };
1511
+ var rmTeamById = (catalogDir) => async (id) => {
1512
+ await import_promises9.default.rm((0, import_node_path13.join)(catalogDir, `${id}.mdx`), { recursive: true });
1513
+ };
1514
+ var getOwnersForResource = (catalogDir) => async (id, version) => {
1515
+ const resource = await getResource(catalogDir, id, version);
1516
+ let owners = [];
1517
+ if (!resource) return [];
1518
+ if (!resource.owners) return [];
1519
+ for (const owner of resource.owners) {
1520
+ const team = await getTeam(import_node_path14.default.join(catalogDir, "teams"))(owner);
1521
+ if (team) {
1522
+ owners.push(team);
1523
+ } else {
1524
+ const user = await getUser(import_node_path14.default.join(catalogDir, "users"))(owner);
1525
+ if (user) {
1526
+ owners.push(user);
1527
+ }
1528
+ }
1529
+ }
1530
+ return owners;
1531
+ };
1532
+
1533
+ // src/eventcatalog.ts
1534
+ var import_fs = __toESM(require("fs"));
1535
+ var import_node_path15 = __toESM(require("path"));
1536
+ var DUMP_VERSION = "0.0.1";
1537
+ var getEventCatalogVersion = async (catalogDir) => {
1538
+ try {
1539
+ const packageJson = import_fs.default.readFileSync((0, import_node_path15.join)(catalogDir, "package.json"), "utf8");
1540
+ const packageJsonObject = JSON.parse(packageJson);
1541
+ return packageJsonObject["dependencies"]["@eventcatalog/core"];
1542
+ } catch (error) {
1543
+ return "unknown";
1544
+ }
1545
+ };
1546
+ var hydrateResource = async (catalogDir, resources = [], { attachSchema = false } = {}) => {
1547
+ return await Promise.all(
1548
+ resources.map(async (resource) => {
1549
+ const resourcePath = await getResourcePath(catalogDir, resource.id, resource.version);
1550
+ let schema = "";
1551
+ if (resource.schemaPath && resourcePath?.fullPath) {
1552
+ const pathToSchema = import_node_path15.default.join(import_node_path15.default.dirname(resourcePath?.fullPath), resource.schemaPath);
1553
+ if (import_fs.default.existsSync(pathToSchema)) {
1554
+ schema = import_fs.default.readFileSync(pathToSchema, "utf8");
1555
+ }
1556
+ }
1557
+ const eventcatalog = schema ? { directory: resourcePath?.directory, schema } : { directory: resourcePath?.directory };
1558
+ return {
1559
+ ...resource,
1560
+ _eventcatalog: eventcatalog
1561
+ };
1562
+ })
1563
+ );
1564
+ };
1565
+ var filterCollection = (collection, options) => {
1566
+ return collection.map((item) => ({
1567
+ ...item,
1568
+ markdown: options?.includeMarkdown ? item.markdown : void 0
1569
+ }));
1570
+ };
1571
+ var getEventCatalogConfigurationFile = (directory) => async () => {
1572
+ try {
1573
+ const path6 = (0, import_node_path15.join)(directory, "eventcatalog.config.js");
1574
+ const configModule = await import(path6);
1575
+ return configModule.default;
1576
+ } catch (error) {
1577
+ console.error("Error getting event catalog configuration file", error);
1578
+ return null;
1579
+ }
1580
+ };
1581
+ var dumpCatalog = (directory) => async (options) => {
1582
+ const { getDomains: getDomains2, getServices: getServices2, getEvents: getEvents2, getQueries: getQueries2, getCommands: getCommands2, getChannels: getChannels2, getTeams: getTeams2, getUsers: getUsers3 } = src_default(directory);
1583
+ const { includeMarkdown = true } = options || {};
1584
+ const domains = await getDomains2();
1585
+ const services = await getServices2();
1586
+ const events = await getEvents2();
1587
+ const commands = await getCommands2();
1588
+ const queries = await getQueries2();
1589
+ const teams = await getTeams2();
1590
+ const users = await getUsers3();
1591
+ const channels = await getChannels2();
1592
+ const [
1593
+ hydratedDomains,
1594
+ hydratedServices,
1595
+ hydratedEvents,
1596
+ hydratedQueries,
1597
+ hydratedCommands,
1598
+ hydratedTeams,
1599
+ hydratedUsers,
1600
+ hydratedChannels
1601
+ ] = await Promise.all([
1602
+ hydrateResource(directory, domains),
1603
+ hydrateResource(directory, services),
1604
+ hydrateResource(directory, events),
1605
+ hydrateResource(directory, queries),
1606
+ hydrateResource(directory, commands),
1607
+ hydrateResource(directory, teams),
1608
+ hydrateResource(directory, users),
1609
+ hydrateResource(directory, channels)
1610
+ ]);
1611
+ return {
1612
+ version: DUMP_VERSION,
1613
+ catalogVersion: await getEventCatalogVersion(directory),
1614
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1615
+ resources: {
1616
+ domains: filterCollection(hydratedDomains, { includeMarkdown }),
1617
+ services: filterCollection(hydratedServices, { includeMarkdown }),
1618
+ messages: {
1619
+ events: filterCollection(hydratedEvents, { includeMarkdown }),
1620
+ queries: filterCollection(hydratedQueries, { includeMarkdown }),
1621
+ commands: filterCollection(hydratedCommands, { includeMarkdown })
1622
+ },
1623
+ teams: filterCollection(hydratedTeams, { includeMarkdown }),
1624
+ users: filterCollection(hydratedUsers, { includeMarkdown }),
1625
+ channels: filterCollection(hydratedChannels, { includeMarkdown })
1626
+ }
1627
+ };
1628
+ };
1629
+
1630
+ // src/entities.ts
1631
+ var import_promises10 = __toESM(require("fs/promises"));
1632
+ var import_node_path16 = require("path");
1633
+ var getEntity = (directory) => async (id, version) => getResource(directory, id, version, { type: "entity" });
1634
+ var getEntities = (directory) => async (options) => getResources(directory, { type: "entities", latestOnly: options?.latestOnly });
1635
+ var writeEntity = (directory) => async (entity, options = {
1636
+ path: "",
1637
+ override: false,
1638
+ format: "mdx"
1639
+ }) => writeResource(directory, { ...entity }, { ...options, type: "entity" });
1640
+ var rmEntity = (directory) => async (path6) => {
1641
+ await import_promises10.default.rm((0, import_node_path16.join)(directory, path6), { recursive: true });
1642
+ };
1643
+ var rmEntityById = (directory) => async (id, version, persistFiles) => {
1644
+ await rmResourceById(directory, id, version, { type: "entity", persistFiles });
1645
+ };
1646
+ var versionEntity = (directory) => async (id) => versionResource(directory, id);
1647
+ var entityHasVersion = (directory) => async (id, version) => {
1648
+ const file = await findFileById(directory, id, version);
1649
+ return !!file;
1650
+ };
1651
+
1652
+ // src/containers.ts
1653
+ var import_promises11 = __toESM(require("fs/promises"));
1654
+ var import_node_path17 = require("path");
1655
+ var getContainer = (directory) => async (id, version) => getResource(directory, id, version, { type: "container" });
1656
+ var getContainers = (directory) => async (options) => getResources(directory, { type: "containers", latestOnly: options?.latestOnly });
1657
+ var writeContainer = (directory) => async (data, options = {
1658
+ path: "",
1659
+ override: false,
1660
+ format: "mdx"
1661
+ }) => writeResource(directory, { ...data }, { ...options, type: "container" });
1662
+ var versionContainer = (directory) => async (id) => versionResource(directory, id);
1663
+ var rmContainer = (directory) => async (path6) => {
1664
+ await import_promises11.default.rm((0, import_node_path17.join)(directory, path6), { recursive: true });
1665
+ };
1666
+ var rmContainerById = (directory) => async (id, version, persistFiles) => {
1667
+ await rmResourceById(directory, id, version, { type: "container", persistFiles });
1668
+ };
1669
+ var containerHasVersion = (directory) => async (id, version) => {
1670
+ const file = await findFileById(directory, id, version);
1671
+ return !!file;
1672
+ };
1673
+ var addFileToContainer = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
1674
+ var writeContainerToService = (directory) => async (container, service, options = { path: "", format: "mdx", override: false }) => {
1675
+ const resourcePath = await getResourcePath(directory, service.id, service.version);
1676
+ if (!resourcePath) {
1677
+ throw new Error("Service not found");
1678
+ }
1679
+ let pathForContainer = service.version && service.version !== "latest" ? `${resourcePath.directory}/versioned/${service.version}/containers` : `${resourcePath.directory}/containers`;
1680
+ pathForContainer = (0, import_node_path17.join)(pathForContainer, container.id);
1681
+ await writeResource(directory, { ...container }, { ...options, path: pathForContainer, type: "container" });
1682
+ };
1683
+
1684
+ // src/data-stores.ts
1685
+ var getDataStore = getContainer;
1686
+ var getDataStores = getContainers;
1687
+ var writeDataStore = writeContainer;
1688
+ var versionDataStore = versionContainer;
1689
+ var rmDataStore = rmContainer;
1690
+ var rmDataStoreById = rmContainerById;
1691
+ var dataStoreHasVersion = containerHasVersion;
1692
+ var addFileToDataStore = addFileToContainer;
1693
+ var writeDataStoreToService = writeContainerToService;
1694
+
1695
+ // src/data-products.ts
1696
+ var import_promises12 = __toESM(require("fs/promises"));
1697
+ var import_node_path18 = require("path");
1698
+ var getDataProduct = (directory) => async (id, version) => getResource(directory, id, version, { type: "data-product" });
1699
+ var getDataProducts = (directory) => async (options) => getResources(directory, { type: "data-products", latestOnly: options?.latestOnly });
1700
+ var writeDataProduct = (directory) => async (dataProduct, options = {
1701
+ path: "",
1702
+ override: false,
1703
+ format: "mdx"
1704
+ }) => writeResource(directory, { ...dataProduct }, { ...options, type: "data-product" });
1705
+ var writeDataProductToDomain = (directory) => async (dataProduct, domain, options = { path: "", format: "mdx", override: false }) => {
1706
+ let pathForDataProduct = domain.version && domain.version !== "latest" ? `/${domain.id}/versioned/${domain.version}/data-products` : `/${domain.id}/data-products`;
1707
+ pathForDataProduct = (0, import_node_path18.join)(pathForDataProduct, dataProduct.id);
1708
+ await writeResource(directory, { ...dataProduct }, { ...options, path: pathForDataProduct, type: "data-product" });
1709
+ };
1710
+ var rmDataProduct = (directory) => async (path6) => {
1711
+ await import_promises12.default.rm((0, import_node_path18.join)(directory, path6), { recursive: true });
1712
+ };
1713
+ var rmDataProductById = (directory) => async (id, version, persistFiles) => {
1714
+ await rmResourceById(directory, id, version, { type: "data-product", persistFiles });
1715
+ };
1716
+ var versionDataProduct = (directory) => async (id) => versionResource(directory, id);
1717
+ var dataProductHasVersion = (directory) => async (id, version) => {
1718
+ const file = await findFileById(directory, id, version);
1719
+ return !!file;
1720
+ };
1721
+ var addFileToDataProduct = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
1722
+
1723
+ // src/diagrams.ts
1724
+ var import_promises13 = __toESM(require("fs/promises"));
1725
+ var import_node_path19 = require("path");
1726
+ var getDiagram = (directory) => async (id, version) => getResource(directory, id, version, { type: "diagram" });
1727
+ var getDiagrams = (directory) => async (options) => getResources(directory, { type: "diagrams", latestOnly: options?.latestOnly });
1728
+ var writeDiagram = (directory) => async (diagram, options = {
1729
+ path: "",
1730
+ override: false,
1731
+ format: "mdx"
1732
+ }) => writeResource(directory, { ...diagram }, { ...options, type: "diagram" });
1733
+ var rmDiagram = (directory) => async (path6) => {
1734
+ await import_promises13.default.rm((0, import_node_path19.join)(directory, path6), { recursive: true });
1735
+ };
1736
+ var rmDiagramById = (directory) => async (id, version, persistFiles) => {
1737
+ await rmResourceById(directory, id, version, { type: "diagram", persistFiles });
1738
+ };
1739
+ var versionDiagram = (directory) => async (id) => versionResource(directory, id);
1740
+ var diagramHasVersion = (directory) => async (id, version) => {
1741
+ const file = await findFileById(directory, id, version);
1742
+ return !!file;
1743
+ };
1744
+ var addFileToDiagram = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version, { type: "diagram" });
1745
+
1746
+ // src/index.ts
1747
+ var src_default = (path6) => {
1748
+ return {
1749
+ /**
1750
+ * Returns an events from EventCatalog
1751
+ * @param id - The id of the event to retrieve
1752
+ * @param version - Optional id of the version to get (supports semver)
1753
+ * @returns Event|Undefined
1754
+ */
1755
+ getEvent: getEvent((0, import_node_path20.join)(path6)),
1756
+ /**
1757
+ * Returns all events from EventCatalog
1758
+ * @param latestOnly - optional boolean, set to true to get only latest versions
1759
+ * @returns Event[]|Undefined
1760
+ */
1761
+ getEvents: getEvents((0, import_node_path20.join)(path6)),
1762
+ /**
1763
+ * Adds an event to EventCatalog
1764
+ *
1765
+ * @param event - The event to write
1766
+ * @param options - Optional options to write the event
1767
+ *
1768
+ */
1769
+ writeEvent: writeEvent((0, import_node_path20.join)(path6, "events")),
1770
+ /**
1771
+ * Adds an event to a service in EventCatalog
1772
+ *
1773
+ * @param event - The event to write to the service
1774
+ * @param service - The service and it's id to write to the event to
1775
+ * @param options - Optional options to write the event
1776
+ *
1777
+ */
1778
+ writeEventToService: writeEventToService((0, import_node_path20.join)(path6)),
1779
+ /**
1780
+ * Remove an event to EventCatalog (modeled on the standard POSIX rm utility)
1781
+ *
1782
+ * @param path - The path to your event, e.g. `/Inventory/InventoryAdjusted`
1783
+ *
1784
+ */
1785
+ rmEvent: rmEvent((0, import_node_path20.join)(path6, "events")),
1786
+ /**
1787
+ * Remove an event by an Event id
1788
+ *
1789
+ * @param id - The id of the event you want to remove
1790
+ *
1791
+ */
1792
+ rmEventById: rmEventById((0, import_node_path20.join)(path6)),
1793
+ /**
1794
+ * Moves a given event id to the version directory
1795
+ * @param directory
1796
+ */
1797
+ versionEvent: versionEvent((0, import_node_path20.join)(path6)),
1798
+ /**
1799
+ * Adds a file to the given event
1800
+ * @param id - The id of the event to add the file to
1801
+ * @param file - File contents to add including the content and the file name
1802
+ * @param version - Optional version of the event to add the file to
1803
+ * @returns
1804
+ */
1805
+ addFileToEvent: addFileToEvent((0, import_node_path20.join)(path6)),
1806
+ /**
1807
+ * Adds a schema to the given event
1808
+ * @param id - The id of the event to add the schema to
1809
+ * @param schema - Schema contents to add including the content and the file name
1810
+ * @param version - Optional version of the event to add the schema to
1811
+ * @returns
1812
+ */
1813
+ addSchemaToEvent: addSchemaToEvent((0, import_node_path20.join)(path6)),
1814
+ /**
1815
+ * Check to see if an event version exists
1816
+ * @param id - The id of the event
1817
+ * @param version - The version of the event (supports semver)
1818
+ * @returns
1819
+ */
1820
+ eventHasVersion: eventHasVersion((0, import_node_path20.join)(path6)),
1821
+ /**
1822
+ * ================================
1823
+ * Commands
1824
+ * ================================
1825
+ */
1826
+ /**
1827
+ * Returns a command from EventCatalog
1828
+ * @param id - The id of the command to retrieve
1829
+ * @param version - Optional id of the version to get (supports semver)
1830
+ * @returns Command|Undefined
1831
+ */
1832
+ getCommand: getCommand((0, import_node_path20.join)(path6)),
1833
+ /**
1834
+ * Returns all commands from EventCatalog
1835
+ * @param latestOnly - optional boolean, set to true to get only latest versions
1836
+ * @returns Command[]|Undefined
1837
+ */
1838
+ getCommands: getCommands((0, import_node_path20.join)(path6)),
1839
+ /**
1840
+ * Adds an command to EventCatalog
1841
+ *
1842
+ * @param command - The command to write
1843
+ * @param options - Optional options to write the command
1844
+ *
1845
+ */
1846
+ writeCommand: writeCommand((0, import_node_path20.join)(path6, "commands")),
1847
+ /**
1848
+ * Adds a command to a service in EventCatalog
1849
+ *
1850
+ * @param command - The command to write to the service
1851
+ * @param service - The service and it's id to write to the command to
1852
+ * @param options - Optional options to write the command
1853
+ *
1854
+ */
1855
+ writeCommandToService: writeCommandToService((0, import_node_path20.join)(path6)),
1856
+ /**
1857
+ * Remove an command to EventCatalog (modeled on the standard POSIX rm utility)
1858
+ *
1859
+ * @param path - The path to your command, e.g. `/Inventory/InventoryAdjusted`
1860
+ *
1861
+ */
1862
+ rmCommand: rmCommand((0, import_node_path20.join)(path6, "commands")),
1863
+ /**
1864
+ * Remove an command by an Event id
1865
+ *
1866
+ * @param id - The id of the command you want to remove
1867
+ *
1868
+ */
1869
+ rmCommandById: rmCommandById((0, import_node_path20.join)(path6)),
1870
+ /**
1871
+ * Moves a given command id to the version directory
1872
+ * @param directory
1873
+ */
1874
+ versionCommand: versionCommand((0, import_node_path20.join)(path6)),
1875
+ /**
1876
+ * Adds a file to the given command
1877
+ * @param id - The id of the command to add the file to
1878
+ * @param file - File contents to add including the content and the file name
1879
+ * @param version - Optional version of the command to add the file to
1880
+ * @returns
1881
+ */
1882
+ addFileToCommand: addFileToCommand((0, import_node_path20.join)(path6)),
1883
+ /**
1884
+ * Adds a schema to the given command
1885
+ * @param id - The id of the command to add the schema to
1886
+ * @param schema - Schema contents to add including the content and the file name
1887
+ * @param version - Optional version of the command to add the schema to
1888
+ * @returns
1889
+ */
1890
+ addSchemaToCommand: addSchemaToCommand((0, import_node_path20.join)(path6)),
1891
+ /**
1892
+ * Check to see if a command version exists
1893
+ * @param id - The id of the command
1894
+ * @param version - The version of the command (supports semver)
1895
+ * @returns
1896
+ */
1897
+ commandHasVersion: commandHasVersion((0, import_node_path20.join)(path6)),
1898
+ /**
1899
+ * ================================
1900
+ * Queries
1901
+ * ================================
1902
+ */
1903
+ /**
1904
+ * Returns a query from EventCatalog
1905
+ * @param id - The id of the query to retrieve
1906
+ * @param version - Optional id of the version to get (supports semver)
1907
+ * @returns Query|Undefined
1908
+ */
1909
+ getQuery: getQuery((0, import_node_path20.join)(path6)),
1910
+ /**
1911
+ * Returns all queries from EventCatalog
1912
+ * @param latestOnly - optional boolean, set to true to get only latest versions
1913
+ * @returns Query[]|Undefined
1914
+ */
1915
+ getQueries: getQueries((0, import_node_path20.join)(path6)),
1916
+ /**
1917
+ * Adds a query to EventCatalog
1918
+ *
1919
+ * @param query - The query to write
1920
+ * @param options - Optional options to write the event
1921
+ *
1922
+ */
1923
+ writeQuery: writeQuery((0, import_node_path20.join)(path6, "queries")),
1924
+ /**
1925
+ * Adds a query to a service in EventCatalog
1926
+ *
1927
+ * @param query - The query to write to the service
1928
+ * @param service - The service and it's id to write to the query to
1929
+ * @param options - Optional options to write the query
1930
+ *
1931
+ */
1932
+ writeQueryToService: writeQueryToService((0, import_node_path20.join)(path6)),
1933
+ /**
1934
+ * Remove an query to EventCatalog (modeled on the standard POSIX rm utility)
1935
+ *
1936
+ * @param path - The path to your query, e.g. `/Orders/GetOrder`
1937
+ *
1938
+ */
1939
+ rmQuery: rmQuery((0, import_node_path20.join)(path6, "queries")),
1940
+ /**
1941
+ * Remove a query by a Query id
1942
+ *
1943
+ * @param id - The id of the query you want to remove
1944
+ *
1945
+ */
1946
+ rmQueryById: rmQueryById((0, import_node_path20.join)(path6)),
1947
+ /**
1948
+ * Moves a given query id to the version directory
1949
+ * @param directory
1950
+ */
1951
+ versionQuery: versionQuery((0, import_node_path20.join)(path6)),
1952
+ /**
1953
+ * Adds a file to the given query
1954
+ * @param id - The id of the query to add the file to
1955
+ * @param file - File contents to add including the content and the file name
1956
+ * @param version - Optional version of the query to add the file to
1957
+ * @returns
1958
+ */
1959
+ addFileToQuery: addFileToQuery((0, import_node_path20.join)(path6)),
1960
+ /**
1961
+ * Adds a schema to the given query
1962
+ * @param id - The id of the query to add the schema to
1963
+ * @param schema - Schema contents to add including the content and the file name
1964
+ * @param version - Optional version of the query to add the schema to
1965
+ * @returns
1966
+ */
1967
+ addSchemaToQuery: addSchemaToQuery((0, import_node_path20.join)(path6)),
1968
+ /**
1969
+ * Check to see if an query version exists
1970
+ * @param id - The id of the query
1971
+ * @param version - The version of the query (supports semver)
1972
+ * @returns
1973
+ */
1974
+ queryHasVersion: queryHasVersion((0, import_node_path20.join)(path6)),
1975
+ /**
1976
+ * ================================
1977
+ * Channels
1978
+ * ================================
1979
+ */
1980
+ /**
1981
+ * Returns a channel from EventCatalog
1982
+ * @param id - The id of the channel to retrieve
1983
+ * @param version - Optional id of the version to get (supports semver)
1984
+ * @returns Channel|Undefined
1985
+ */
1986
+ getChannel: getChannel((0, import_node_path20.join)(path6)),
1987
+ /**
1988
+ * Returns all channels from EventCatalog
1989
+ * @param latestOnly - optional boolean, set to true to get only latest versions
1990
+ * @returns Channel[]|Undefined
1991
+ */
1992
+ getChannels: getChannels((0, import_node_path20.join)(path6)),
1993
+ /**
1994
+ * Adds an channel to EventCatalog
1995
+ *
1996
+ * @param command - The channel to write
1997
+ * @param options - Optional options to write the channel
1998
+ *
1999
+ */
2000
+ writeChannel: writeChannel((0, import_node_path20.join)(path6, "channels")),
2001
+ /**
2002
+ * Remove an channel to EventCatalog (modeled on the standard POSIX rm utility)
2003
+ *
2004
+ * @param path - The path to your channel, e.g. `/Inventory/InventoryAdjusted`
2005
+ *
2006
+ */
2007
+ rmChannel: rmChannel((0, import_node_path20.join)(path6, "channels")),
2008
+ /**
2009
+ * Remove an channel by an Event id
2010
+ *
2011
+ * @param id - The id of the channel you want to remove
2012
+ *
2013
+ */
2014
+ rmChannelById: rmChannelById((0, import_node_path20.join)(path6)),
2015
+ /**
2016
+ * Moves a given channel id to the version directory
2017
+ * @param directory
2018
+ */
2019
+ versionChannel: versionChannel((0, import_node_path20.join)(path6)),
2020
+ /**
2021
+ * Check to see if a channel version exists
2022
+ * @param id - The id of the channel
2023
+ * @param version - The version of the channel (supports semver)
2024
+ * @returns
2025
+ */
2026
+ channelHasVersion: channelHasVersion((0, import_node_path20.join)(path6)),
2027
+ /**
2028
+ * Add a channel to an event
2029
+ *
2030
+ * Optionally specify a version to add the channel to a specific version of the event.
2031
+ *
2032
+ * @example
2033
+ * ```ts
2034
+ * import utils from '@eventcatalog/utils';
2035
+ *
2036
+ * const { addEventToChannel } = utils('/path/to/eventcatalog');
2037
+ *
2038
+ * // adds a new event (InventoryUpdatedEvent) to the inventory.{env}.events channel
2039
+ * await addEventToChannel('inventory.{env}.events channel', { id: 'InventoryUpdatedEvent', version: '2.0.0', parameters: { env: 'dev' } });
2040
+ *
2041
+ * ```
2042
+ */
2043
+ addEventToChannel: addMessageToChannel((0, import_node_path20.join)(path6), "events"),
2044
+ /**
2045
+ * Add a channel to an command
2046
+ *
2047
+ * Optionally specify a version to add the channel to a specific version of the command.
2048
+ *
2049
+ * @example
2050
+ * ```ts
2051
+ * import utils from '@eventcatalog/utils';
2052
+ *
2053
+ * const { addCommandToChannel } = utils('/path/to/eventcatalog');
2054
+ *
2055
+ * // adds a new command (UpdateInventory) to the inventory.{env}.events channel
2056
+ * await addCommandToChannel('inventory.{env}.events channel', { id: 'UpdateInventory', version: '2.0.0', parameters: { env: 'dev' } });
2057
+ *
2058
+ * ```
2059
+ */
2060
+ addCommandToChannel: addMessageToChannel((0, import_node_path20.join)(path6), "commands"),
2061
+ /**
2062
+ * Add a channel to an query
2063
+ *
2064
+ * Optionally specify a version to add the channel to a specific version of the query.
2065
+ *
2066
+ * @example
2067
+ * ```ts
2068
+ * import utils from '@eventcatalog/utils';
2069
+ *
2070
+ * const { addQueryToChannel } = utils('/path/to/eventcatalog');
2071
+ *
2072
+ * // adds a new query (GetInventory) to the inventory.{env}.events channel
2073
+ * await addQueryToChannel('inventory.{env}.events channel', { id: 'GetInventory', version: '2.0.0', parameters: { env: 'dev' } });
2074
+ *
2075
+ * ```
2076
+ */
2077
+ addQueryToChannel: addMessageToChannel((0, import_node_path20.join)(path6), "queries"),
2078
+ /**
2079
+ * ================================
2080
+ * SERVICES
2081
+ * ================================
2082
+ */
2083
+ /**
2084
+ * Adds a service to EventCatalog
2085
+ *
2086
+ * @param service - The service to write
2087
+ * @param options - Optional options to write the event
2088
+ *
2089
+ */
2090
+ writeService: writeService((0, import_node_path20.join)(path6, "services")),
2091
+ /**
2092
+ * Adds a versioned service to EventCatalog
2093
+ *
2094
+ * @param service - The service to write
2095
+ *
2096
+ */
2097
+ writeVersionedService: writeVersionedService((0, import_node_path20.join)(path6, "services")),
2098
+ /**
2099
+ * Adds a service to a domain in EventCatalog
2100
+ *
2101
+ * @param service - The service to write
2102
+ * @param domain - The domain to add the service to
2103
+ * @param options - Optional options to write the event
2104
+ *
2105
+ */
2106
+ writeServiceToDomain: writeServiceToDomain((0, import_node_path20.join)(path6, "domains")),
2107
+ /**
2108
+ * Returns a service from EventCatalog
2109
+ * @param id - The id of the service to retrieve
2110
+ * @param version - Optional id of the version to get (supports semver)
2111
+ * @returns Service|Undefined
2112
+ */
2113
+ getService: getService((0, import_node_path20.join)(path6)),
2114
+ /**
2115
+ * Returns a service from EventCatalog by it's path.
2116
+ * @param path - The path to the service to retrieve
2117
+ * @returns Service|Undefined
2118
+ */
2119
+ getServiceByPath: getServiceByPath((0, import_node_path20.join)(path6)),
2120
+ /**
2121
+ * Returns all services from EventCatalog
2122
+ * @param latestOnly - optional boolean, set to true to get only latest versions
2123
+ * @returns Service[]|Undefined
2124
+ */
2125
+ getServices: getServices((0, import_node_path20.join)(path6)),
2126
+ /**
2127
+ * Moves a given service id to the version directory
2128
+ * @param directory
2129
+ */
2130
+ versionService: versionService((0, import_node_path20.join)(path6)),
2131
+ /**
2132
+ * Remove a service from EventCatalog (modeled on the standard POSIX rm utility)
2133
+ *
2134
+ * @param path - The path to your service, e.g. `/InventoryService`
2135
+ *
2136
+ */
2137
+ rmService: rmService((0, import_node_path20.join)(path6, "services")),
2138
+ /**
2139
+ * Remove an service by an service id
2140
+ *
2141
+ * @param id - The id of the service you want to remove
2142
+ *
2143
+ */
2144
+ rmServiceById: rmServiceById((0, import_node_path20.join)(path6)),
2145
+ /**
2146
+ * Adds a file to the given service
2147
+ * @param id - The id of the service to add the file to
2148
+ * @param file - File contents to add including the content and the file name
2149
+ * @param version - Optional version of the service to add the file to
2150
+ * @returns
2151
+ */
2152
+ addFileToService: addFileToService((0, import_node_path20.join)(path6)),
2153
+ /**
2154
+ * Returns the specifications for a given service
2155
+ * @param id - The id of the service to retrieve the specifications for
2156
+ * @param version - Optional version of the service
2157
+ * @returns
2158
+ */
2159
+ getSpecificationFilesForService: getSpecificationFilesForService((0, import_node_path20.join)(path6)),
2160
+ /**
2161
+ * Check to see if a service version exists
2162
+ * @param id - The id of the service
2163
+ * @param version - The version of the service (supports semver)
2164
+ * @returns
2165
+ */
2166
+ serviceHasVersion: serviceHasVersion((0, import_node_path20.join)(path6)),
2167
+ /**
2168
+ * Add an event to a service by it's id.
2169
+ *
2170
+ * Optionally specify a version to add the event to a specific version of the service.
2171
+ *
2172
+ * @example
2173
+ * ```ts
2174
+ * import utils from '@eventcatalog/utils';
2175
+ *
2176
+ * const { addEventToService } = utils('/path/to/eventcatalog');
2177
+ *
2178
+ * // adds a new event (InventoryUpdatedEvent) that the InventoryService will send
2179
+ * await addEventToService('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });
2180
+ *
2181
+ * // adds a new event (OrderComplete) that the InventoryService will receive
2182
+ * await addEventToService('InventoryService', 'receives', { event: 'OrderComplete', version: '2.0.0' });
2183
+ *
2184
+ * ```
2185
+ */
2186
+ addEventToService: addMessageToService((0, import_node_path20.join)(path6)),
2187
+ /**
2188
+ * Add a data store to a service by it's id.
2189
+ *
2190
+ * Optionally specify a version to add the data store to a specific version of the service.
2191
+ *
2192
+ * @example
2193
+ * ```ts
2194
+ * import utils from '@eventcatalog/utils';
2195
+ *
2196
+ * const { addDataStoreToService } = utils('/path/to/eventcatalog');
2197
+ *
2198
+ * // adds a new data store (orders-db) that the InventoryService will write to
2199
+ * await addDataStoreToService('InventoryService', 'writesTo', { id: 'orders-db', version: '2.0.0' });
2200
+ *
2201
+ * ```
2202
+ */
2203
+ addDataStoreToService: addDataStoreToService((0, import_node_path20.join)(path6)),
2204
+ /**
2205
+ * Add a command to a service by it's id.
2206
+ *
2207
+ * Optionally specify a version to add the event to a specific version of the service.
2208
+ *
2209
+ * @example
2210
+ * ```ts
2211
+ * import utils from '@eventcatalog/utils';
2212
+ *
2213
+ * const { addCommandToService } = utils('/path/to/eventcatalog');
2214
+ *
2215
+ * // adds a new command (UpdateInventoryCommand) that the InventoryService will send
2216
+ * await addCommandToService('InventoryService', 'sends', { command: 'UpdateInventoryCommand', version: '2.0.0' });
2217
+ *
2218
+ * // adds a new command (VerifyInventory) that the InventoryService will receive
2219
+ * await addCommandToService('InventoryService', 'receives', { command: 'VerifyInventory', version: '2.0.0' });
2220
+ *
2221
+ * ```
2222
+ */
2223
+ addCommandToService: addMessageToService((0, import_node_path20.join)(path6)),
2224
+ /**
2225
+ * Add a query to a service by it's id.
2226
+ *
2227
+ * Optionally specify a version to add the event to a specific version of the service.
2228
+ *
2229
+ * @example
2230
+ * ```ts
2231
+ * import utils from '@eventcatalog/utils';
2232
+ *
2233
+ * const { addQueryToService } = utils('/path/to/eventcatalog');
2234
+ *
2235
+ * // adds a new query (UpdateInventory) that the InventoryService will send
2236
+ * await addQueryToService('InventoryService', 'sends', { command: 'UpdateInventory', version: '2.0.0' });
2237
+ *
2238
+ * // adds a new command (VerifyInventory) that the InventoryService will receive
2239
+ * await addQueryToService('InventoryService', 'receives', { command: 'VerifyInventory', version: '2.0.0' });
2240
+ *
2241
+ * ```
2242
+ */
2243
+ addQueryToService: addMessageToService((0, import_node_path20.join)(path6)),
2244
+ /**
2245
+ * Add an entity to a service by its id.
2246
+ *
2247
+ * @example
2248
+ * ```ts
2249
+ * import utils from '@eventcatalog/utils';
2250
+ *
2251
+ * const { addEntityToService } = utils('/path/to/eventcatalog');
2252
+ *
2253
+ * // adds a new entity (User) to the InventoryService
2254
+ * await addEntityToService('InventoryService', { id: 'User', version: '1.0.0' });
2255
+ *
2256
+ * // adds a new entity (Product) to a specific version of the InventoryService
2257
+ * await addEntityToService('InventoryService', { id: 'Product', version: '1.0.0' }, '2.0.0');
2258
+ *
2259
+ * ```
2260
+ */
2261
+ addEntityToService: addEntityToService((0, import_node_path20.join)(path6)),
2262
+ /**
2263
+ * Check to see if a service exists by it's path.
2264
+ *
2265
+ * @example
2266
+ * ```ts
2267
+ * import utils from '@eventcatalog/utils';
2268
+ *
2269
+ * const { isService } = utils('/path/to/eventcatalog');
2270
+ *
2271
+ * // returns true if the path is a service
2272
+ * await isService('/services/InventoryService/index.mdx');
2273
+ * ```
2274
+ *
2275
+ * @param path - The path to the service to check
2276
+ * @returns boolean
2277
+ */
2278
+ isService: isService((0, import_node_path20.join)(path6)),
2279
+ /**
2280
+ * Converts a file to a service.
2281
+ * @param file - The file to convert to a service.
2282
+ * @returns The service.
2283
+ */
2284
+ toService: toService((0, import_node_path20.join)(path6)),
2285
+ /**
2286
+ * ================================
2287
+ * Domains
2288
+ * ================================
2289
+ */
2290
+ /**
2291
+ * Adds a domain to EventCatalog
2292
+ *
2293
+ * @param domain - The domain to write
2294
+ * @param options - Optional options to write the event
2295
+ *
2296
+ */
2297
+ writeDomain: writeDomain((0, import_node_path20.join)(path6, "domains")),
2298
+ /**
2299
+ * Returns a domain from EventCatalog
2300
+ * @param id - The id of the domain to retrieve
2301
+ * @param version - Optional id of the version to get (supports semver)
2302
+ * @returns Domain|Undefined
2303
+ */
2304
+ getDomain: getDomain((0, import_node_path20.join)(path6, "domains")),
2305
+ /**
2306
+ * Returns all domains from EventCatalog
2307
+ * @param latestOnly - optional boolean, set to true to get only latest versions
2308
+ * @returns Domain[]|Undefined
2309
+ */
2310
+ getDomains: getDomains((0, import_node_path20.join)(path6)),
2311
+ /**
2312
+ * Moves a given domain id to the version directory
2313
+ * @param directory
2314
+ */
2315
+ versionDomain: versionDomain((0, import_node_path20.join)(path6, "domains")),
2316
+ /**
2317
+ * Remove a domain from EventCatalog (modeled on the standard POSIX rm utility)
2318
+ *
2319
+ * @param path - The path to your domain, e.g. `/Payment`
2320
+ *
2321
+ */
2322
+ rmDomain: rmDomain((0, import_node_path20.join)(path6, "domains")),
2323
+ /**
2324
+ * Remove an service by an domain id
2325
+ *
2326
+ * @param id - The id of the domain you want to remove
2327
+ *
2328
+ */
2329
+ rmDomainById: rmDomainById((0, import_node_path20.join)(path6, "domains")),
2330
+ /**
2331
+ * Adds a file to the given domain
2332
+ * @param id - The id of the domain to add the file to
2333
+ * @param file - File contents to add including the content and the file name
2334
+ * @param version - Optional version of the domain to add the file to
2335
+ * @returns
2336
+ */
2337
+ addFileToDomain: addFileToDomain((0, import_node_path20.join)(path6, "domains")),
2338
+ /**
2339
+ * Adds an ubiquitous language dictionary to a domain
2340
+ * @param id - The id of the domain to add the ubiquitous language to
2341
+ * @param ubiquitousLanguageDictionary - The ubiquitous language dictionary to add
2342
+ * @param version - Optional version of the domain to add the ubiquitous language to
2343
+ */
2344
+ addUbiquitousLanguageToDomain: addUbiquitousLanguageToDomain((0, import_node_path20.join)(path6, "domains")),
2345
+ /**
2346
+ * Get the ubiquitous language dictionary from a domain
2347
+ * @param id - The id of the domain to get the ubiquitous language from
2348
+ * @param version - Optional version of the domain to get the ubiquitous language from
2349
+ * @returns
2350
+ */
2351
+ getUbiquitousLanguageFromDomain: getUbiquitousLanguageFromDomain((0, import_node_path20.join)(path6, "domains")),
2352
+ /**
2353
+ * Check to see if a domain version exists
2354
+ * @param id - The id of the domain
2355
+ * @param version - The version of the domain (supports semver)
2356
+ * @returns
2357
+ */
2358
+ domainHasVersion: domainHasVersion((0, import_node_path20.join)(path6)),
2359
+ /**
2360
+ * Adds a given service to a domain
2361
+ * @param id - The id of the domain
2362
+ * @param service - The id and version of the service to add
2363
+ * @param version - (Optional) The version of the domain to add the service to
2364
+ * @returns
2365
+ */
2366
+ addServiceToDomain: addServiceToDomain((0, import_node_path20.join)(path6, "domains")),
2367
+ /**
2368
+ * Adds a given subdomain to a domain
2369
+ * @param id - The id of the domain
2370
+ * @param subDomain - The id and version of the subdomain to add
2371
+ * @param version - (Optional) The version of the domain to add the subdomain to
2372
+ * @returns
2373
+ */
2374
+ addSubDomainToDomain: addSubDomainToDomain((0, import_node_path20.join)(path6, "domains")),
2375
+ /**
2376
+ * Adds an entity to a domain
2377
+ * @param id - The id of the domain
2378
+ * @param entity - The id and version of the entity to add
2379
+ * @param version - (Optional) The version of the domain to add the entity to
2380
+ * @returns
2381
+ */
2382
+ addEntityToDomain: addEntityToDomain((0, import_node_path20.join)(path6, "domains")),
2383
+ /**
2384
+ * Add an event to a domain by its id.
2385
+ *
2386
+ * @example
2387
+ * ```ts
2388
+ * import utils from '@eventcatalog/utils';
2389
+ *
2390
+ * const { addEventToDomain } = utils('/path/to/eventcatalog');
2391
+ *
2392
+ * // adds a new event (OrderCreated) that the Orders domain will send
2393
+ * await addEventToDomain('Orders', 'sends', { id: 'OrderCreated', version: '2.0.0' });
2394
+ *
2395
+ * // adds a new event (PaymentProcessed) that the Orders domain will receive
2396
+ * await addEventToDomain('Orders', 'receives', { id: 'PaymentProcessed', version: '2.0.0' });
2397
+ *
2398
+ * ```
2399
+ */
2400
+ addEventToDomain: addMessageToDomain((0, import_node_path20.join)(path6, "domains")),
2401
+ /**
2402
+ * Add a command to a domain by its id.
2403
+ *
2404
+ * @example
2405
+ * ```ts
2406
+ * import utils from '@eventcatalog/utils';
2407
+ *
2408
+ * const { addCommandToDomain } = utils('/path/to/eventcatalog');
2409
+ *
2410
+ * // adds a new command (ProcessOrder) that the Orders domain will send
2411
+ * await addCommandToDomain('Orders', 'sends', { id: 'ProcessOrder', version: '2.0.0' });
2412
+ *
2413
+ * // adds a new command (CancelOrder) that the Orders domain will receive
2414
+ * await addCommandToDomain('Orders', 'receives', { id: 'CancelOrder', version: '2.0.0' });
2415
+ *
2416
+ * ```
2417
+ */
2418
+ addCommandToDomain: addMessageToDomain((0, import_node_path20.join)(path6, "domains")),
2419
+ /**
2420
+ * Add a query to a domain by its id.
2421
+ *
2422
+ * @example
2423
+ * ```ts
2424
+ * import utils from '@eventcatalog/utils';
2425
+ *
2426
+ * const { addQueryToDomain } = utils('/path/to/eventcatalog');
2427
+ *
2428
+ * // adds a new query (GetOrderStatus) that the Orders domain will send
2429
+ * await addQueryToDomain('Orders', 'sends', { id: 'GetOrderStatus', version: '2.0.0' });
2430
+ *
2431
+ * // adds a new query (GetInventory) that the Orders domain will receive
2432
+ * await addQueryToDomain('Orders', 'receives', { id: 'GetInventory', version: '2.0.0' });
2433
+ *
2434
+ * ```
2435
+ */
2436
+ addQueryToDomain: addMessageToDomain((0, import_node_path20.join)(path6, "domains")),
2437
+ /**
2438
+ * ================================
2439
+ * Teams
2440
+ * ================================
2441
+ */
2442
+ /**
2443
+ * Adds a team to EventCatalog
2444
+ *
2445
+ * @param team - The team to write
2446
+ * @param options - Optional options to write the team
2447
+ *
2448
+ */
2449
+ writeTeam: writeTeam((0, import_node_path20.join)(path6, "teams")),
2450
+ /**
2451
+ * Returns a team from EventCatalog
2452
+ * @param id - The id of the team to retrieve
2453
+ * @returns Team|Undefined
2454
+ */
2455
+ getTeam: getTeam((0, import_node_path20.join)(path6, "teams")),
2456
+ /**
2457
+ * Returns all teams from EventCatalog
2458
+ * @returns Team[]|Undefined
2459
+ */
2460
+ getTeams: getTeams((0, import_node_path20.join)(path6, "teams")),
2461
+ /**
2462
+ * Remove a team by the team id
2463
+ *
2464
+ * @param id - The id of the team you want to remove
2465
+ *
2466
+ */
2467
+ rmTeamById: rmTeamById((0, import_node_path20.join)(path6, "teams")),
2468
+ /**
2469
+ * ================================
2470
+ * Users
2471
+ * ================================
2472
+ */
2473
+ /**
2474
+ * Adds a user to EventCatalog
2475
+ *
2476
+ * @param user - The user to write
2477
+ * @param options - Optional options to write the user
2478
+ *
2479
+ */
2480
+ writeUser: writeUser((0, import_node_path20.join)(path6, "users")),
2481
+ /**
2482
+ * Returns a user from EventCatalog
2483
+ * @param id - The id of the user to retrieve
2484
+ * @returns User|Undefined
2485
+ */
2486
+ getUser: getUser((0, import_node_path20.join)(path6, "users")),
2487
+ /**
2488
+ * Returns all user from EventCatalog
2489
+ * @returns User[]|Undefined
2490
+ */
2491
+ getUsers: getUsers((0, import_node_path20.join)(path6)),
2492
+ /**
2493
+ * Remove a user by the user id
2494
+ *
2495
+ * @param id - The id of the user you want to remove
2496
+ *
2497
+ */
2498
+ rmUserById: rmUserById((0, import_node_path20.join)(path6, "users")),
2499
+ /**
2500
+ * ================================
2501
+ * Custom Docs
2502
+ * ================================
2503
+ */
2504
+ /**
2505
+ * Returns a custom doc from EventCatalog
2506
+ * @param path - The path to the custom doc to retrieve
2507
+ * @returns CustomDoc|Undefined
2508
+ */
2509
+ getCustomDoc: getCustomDoc((0, import_node_path20.join)(path6, "docs")),
2510
+ /**
2511
+ * Returns all custom docs from EventCatalog
2512
+ * @param options - Optional options to get custom docs from a specific path
2513
+ * @returns CustomDoc[]|Undefined
2514
+ */
2515
+ getCustomDocs: getCustomDocs((0, import_node_path20.join)(path6, "docs")),
2516
+ /**
2517
+ * Writes a custom doc to EventCatalog
2518
+ * @param customDoc - The custom doc to write
2519
+ * @param options - Optional options to write the custom doc
2520
+ *
2521
+ */
2522
+ writeCustomDoc: writeCustomDoc((0, import_node_path20.join)(path6, "docs")),
2523
+ /**
2524
+ * Removes a custom doc from EventCatalog
2525
+ * @param path - The path to the custom doc to remove
2526
+ *
2527
+ */
2528
+ rmCustomDoc: rmCustomDoc((0, import_node_path20.join)(path6, "docs")),
2529
+ /**
2530
+ * Dumps the catalog to a JSON file.
2531
+ * @param directory - The directory to dump the catalog to
2532
+ * @returns A JSON file with the catalog
2533
+ */
2534
+ dumpCatalog: dumpCatalog((0, import_node_path20.join)(path6)),
2535
+ /**
2536
+ * Returns the event catalog configuration file.
2537
+ * The event catalog configuration file is the file that contains the configuration for the event catalog.
2538
+ *
2539
+ * @param directory - The directory of the catalog.
2540
+ * @returns A JSON object with the configuration for the event catalog.
2541
+ */
2542
+ getEventCatalogConfigurationFile: getEventCatalogConfigurationFile((0, import_node_path20.join)(path6)),
2543
+ /**
2544
+ * ================================
2545
+ * Resources Utils
2546
+ * ================================
2547
+ */
2548
+ /**
2549
+ * Returns the path to a given resource by id and version
2550
+ */
2551
+ getResourcePath,
2552
+ /**
2553
+ * Returns the folder name of a given resource
2554
+ */
2555
+ getResourceFolderName,
2556
+ /**
2557
+ * ================================
2558
+ * General Message Utils
2559
+ * ================================
2560
+ */
2561
+ /**
2562
+ * Returns a message from EventCatalog by a given schema path.
2563
+ *
2564
+ * @param path - The path to the message to retrieve
2565
+ * @returns Message|Undefined
2566
+ */
2567
+ getMessageBySchemaPath: getMessageBySchemaPath((0, import_node_path20.join)(path6)),
2568
+ /**
2569
+ * Returns the producers and consumers (services) for a given message
2570
+ * @param id - The id of the message to get the producers and consumers for
2571
+ * @param version - Optional version of the message
2572
+ * @returns { producers: Service[], consumers: Service[] }
2573
+ */
2574
+ getProducersAndConsumersForMessage: getProducersAndConsumersForMessage((0, import_node_path20.join)(path6)),
2575
+ /**
2576
+ * Returns the consumers of a given schema path
2577
+ * @param path - The path to the schema to get the consumers for
2578
+ * @returns Service[]
2579
+ */
2580
+ getConsumersOfSchema: getConsumersOfSchema((0, import_node_path20.join)(path6)),
2581
+ /**
2582
+ * Returns the producers of a given schema path
2583
+ * @param path - The path to the schema to get the producers for
2584
+ * @returns Service[]
2585
+ */
2586
+ getProducersOfSchema: getProducersOfSchema((0, import_node_path20.join)(path6)),
2587
+ /**
2588
+ * Returns the owners for a given resource (e.g domain, service, event, command, query, etc.)
2589
+ * @param id - The id of the resource to get the owners for
2590
+ * @param version - Optional version of the resource
2591
+ * @returns { owners: User[] }
2592
+ */
2593
+ getOwnersForResource: getOwnersForResource((0, import_node_path20.join)(path6)),
2594
+ /**
2595
+ * ================================
2596
+ * Entities
2597
+ * ================================
2598
+ */
2599
+ /**
2600
+ * Returns an entity from EventCatalog
2601
+ * @param id - The id of the entity to retrieve
2602
+ * @param version - Optional id of the version to get (supports semver)
2603
+ * @returns Entity|Undefined
2604
+ */
2605
+ getEntity: getEntity((0, import_node_path20.join)(path6)),
2606
+ /**
2607
+ * Returns all entities from EventCatalog
2608
+ * @param latestOnly - optional boolean, set to true to get only latest versions
2609
+ * @returns Entity[]|Undefined
2610
+ */
2611
+ getEntities: getEntities((0, import_node_path20.join)(path6)),
2612
+ /**
2613
+ * Adds an entity to EventCatalog
2614
+ *
2615
+ * @param entity - The entity to write
2616
+ * @param options - Optional options to write the entity
2617
+ *
2618
+ */
2619
+ writeEntity: writeEntity((0, import_node_path20.join)(path6, "entities")),
2620
+ /**
2621
+ * Remove an entity from EventCatalog (modeled on the standard POSIX rm utility)
2622
+ *
2623
+ * @param path - The path to your entity, e.g. `/User`
2624
+ *
2625
+ */
2626
+ rmEntity: rmEntity((0, import_node_path20.join)(path6, "entities")),
2627
+ /**
2628
+ * Remove an entity by an entity id
2629
+ *
2630
+ * @param id - The id of the entity you want to remove
2631
+ *
2632
+ */
2633
+ rmEntityById: rmEntityById((0, import_node_path20.join)(path6)),
2634
+ /**
2635
+ * Moves a given entity id to the version directory
2636
+ * @param id - The id of the entity to version
2637
+ */
2638
+ versionEntity: versionEntity((0, import_node_path20.join)(path6)),
2639
+ /**
2640
+ * Check to see if an entity version exists
2641
+ * @param id - The id of the entity
2642
+ * @param version - The version of the entity (supports semver)
2643
+ * @returns
2644
+ */
2645
+ entityHasVersion: entityHasVersion((0, import_node_path20.join)(path6)),
2646
+ /**
2647
+ * ================================
2648
+ * Data Stores
2649
+ * ================================
2650
+ */
2651
+ /**
2652
+ * Adds a data store to EventCatalog
2653
+ * @param dataStore - The data store to write
2654
+ * @param options - Optional options to write the data store
2655
+ *
2656
+ */
2657
+ writeDataStore: writeDataStore((0, import_node_path20.join)(path6, "containers")),
2658
+ /**
2659
+ * Returns a data store from EventCatalog
2660
+ * @param id - The id of the data store to retrieve
2661
+ * @param version - Optional id of the version to get (supports semver)
2662
+ * @returns Container|Undefined
2663
+ */
2664
+ getDataStore: getDataStore((0, import_node_path20.join)(path6)),
2665
+ /**
2666
+ * Returns all data stores from EventCatalog
2667
+ * @param latestOnly - optional boolean, set to true to get only latest versions
2668
+ * @returns Container[]|Undefined
2669
+ */
2670
+ getDataStores: getDataStores((0, import_node_path20.join)(path6)),
2671
+ /**
2672
+ * Version a data store by its id
2673
+ * @param id - The id of the data store to version
2674
+ */
2675
+ versionDataStore: versionDataStore((0, import_node_path20.join)(path6, "containers")),
2676
+ /**
2677
+ * Remove a data store by its path
2678
+ * @param path - The path to the data store to remove
2679
+ */
2680
+ rmDataStore: rmDataStore((0, import_node_path20.join)(path6, "containers")),
2681
+ /**
2682
+ * Remove a data store by its id
2683
+ * @param id - The id of the data store to remove
2684
+ */
2685
+ rmDataStoreById: rmDataStoreById((0, import_node_path20.join)(path6)),
2686
+ /**
2687
+ * Check to see if a data store version exists
2688
+ * @param id - The id of the data store
2689
+ * @param version - The version of the data store (supports semver)
2690
+ * @returns
2691
+ */
2692
+ dataStoreHasVersion: dataStoreHasVersion((0, import_node_path20.join)(path6)),
2693
+ /**
2694
+ * Adds a file to a data store by its id
2695
+ * @param id - The id of the data store to add the file to
2696
+ * @param file - File contents to add including the content and the file name
2697
+ * @param version - Optional version of the data store to add the file to
2698
+ * @returns
2699
+ */
2700
+ addFileToDataStore: addFileToDataStore((0, import_node_path20.join)(path6)),
2701
+ /**
2702
+ * Writes a data store to a service by its id
2703
+ * @param dataStore - The data store to write
2704
+ * @param service - The service to write the data store to
2705
+ * @returns
2706
+ */
2707
+ writeDataStoreToService: writeDataStoreToService((0, import_node_path20.join)(path6)),
2708
+ /**
2709
+ * ================================
2710
+ * Data Products
2711
+ * ================================
2712
+ */
2713
+ /**
2714
+ * Adds a data product to EventCatalog
2715
+ * @param dataProduct - The data product to write
2716
+ * @param options - Optional options to write the data product
2717
+ *
2718
+ */
2719
+ writeDataProduct: writeDataProduct((0, import_node_path20.join)(path6, "data-products")),
2720
+ /**
2721
+ * Writes a data product to a domain in EventCatalog
2722
+ * @param dataProduct - The data product to write
2723
+ * @param domain - The domain to write the data product to
2724
+ * @param options - Optional options to write the data product
2725
+ *
2726
+ */
2727
+ writeDataProductToDomain: writeDataProductToDomain((0, import_node_path20.join)(path6, "domains")),
2728
+ /**
2729
+ * Returns a data product from EventCatalog
2730
+ * @param id - The id of the data product to retrieve
2731
+ * @param version - Optional id of the version to get (supports semver)
2732
+ * @returns DataProduct|Undefined
2733
+ */
2734
+ getDataProduct: getDataProduct((0, import_node_path20.join)(path6)),
2735
+ /**
2736
+ * Returns all data products from EventCatalog
2737
+ * @param latestOnly - optional boolean, set to true to get only latest versions
2738
+ * @returns DataProduct[]|Undefined
2739
+ */
2740
+ getDataProducts: getDataProducts((0, import_node_path20.join)(path6)),
2741
+ /**
2742
+ * Version a data product by its id
2743
+ * @param id - The id of the data product to version
2744
+ */
2745
+ versionDataProduct: versionDataProduct((0, import_node_path20.join)(path6)),
2746
+ /**
2747
+ * Remove a data product by its path
2748
+ * @param path - The path to the data product to remove
2749
+ */
2750
+ rmDataProduct: rmDataProduct((0, import_node_path20.join)(path6, "data-products")),
2751
+ /**
2752
+ * Remove a data product by its id
2753
+ * @param id - The id of the data product to remove
2754
+ * @param version - Optional version of the data product to remove
2755
+ */
2756
+ rmDataProductById: rmDataProductById((0, import_node_path20.join)(path6)),
2757
+ /**
2758
+ * Check to see if a data product version exists
2759
+ * @param id - The id of the data product
2760
+ * @param version - The version of the data product (supports semver)
2761
+ * @returns
2762
+ */
2763
+ dataProductHasVersion: dataProductHasVersion((0, import_node_path20.join)(path6)),
2764
+ /**
2765
+ * Adds a file to a data product by its id
2766
+ * @param id - The id of the data product to add the file to
2767
+ * @param file - File contents to add including the content and the file name
2768
+ * @param version - Optional version of the data product to add the file to
2769
+ * @returns
2770
+ */
2771
+ addFileToDataProduct: addFileToDataProduct((0, import_node_path20.join)(path6)),
2772
+ /**
2773
+ * Adds a data product to a domain
2774
+ * @param id - The id of the domain
2775
+ * @param dataProduct - The id and version of the data product to add
2776
+ * @param version - (Optional) The version of the domain to add the data product to
2777
+ * @returns
2778
+ */
2779
+ addDataProductToDomain: addDataProductToDomain((0, import_node_path20.join)(path6, "domains")),
2780
+ /**
2781
+ * ================================
2782
+ * Diagrams
2783
+ * ================================
2784
+ */
2785
+ /**
2786
+ * Returns a diagram from EventCatalog
2787
+ * @param id - The id of the diagram to retrieve
2788
+ * @param version - Optional id of the version to get (supports semver)
2789
+ * @returns Diagram|Undefined
2790
+ */
2791
+ getDiagram: getDiagram((0, import_node_path20.join)(path6)),
2792
+ /**
2793
+ * Returns all diagrams from EventCatalog
2794
+ * @param latestOnly - optional boolean, set to true to get only latest versions
2795
+ * @returns Diagram[]|Undefined
2796
+ */
2797
+ getDiagrams: getDiagrams((0, import_node_path20.join)(path6)),
2798
+ /**
2799
+ * Adds a diagram to EventCatalog
2800
+ *
2801
+ * @param diagram - The diagram to write
2802
+ * @param options - Optional options to write the diagram
2803
+ *
2804
+ */
2805
+ writeDiagram: writeDiagram((0, import_node_path20.join)(path6, "diagrams")),
2806
+ /**
2807
+ * Remove a diagram from EventCatalog (modeled on the standard POSIX rm utility)
2808
+ *
2809
+ * @param path - The path to your diagram, e.g. `/ArchitectureDiagram`
2810
+ *
2811
+ */
2812
+ rmDiagram: rmDiagram((0, import_node_path20.join)(path6, "diagrams")),
2813
+ /**
2814
+ * Remove a diagram by a diagram id
2815
+ *
2816
+ * @param id - The id of the diagram you want to remove
2817
+ *
2818
+ */
2819
+ rmDiagramById: rmDiagramById((0, import_node_path20.join)(path6)),
2820
+ /**
2821
+ * Moves a given diagram id to the version directory
2822
+ * @param id - The id of the diagram to version
2823
+ */
2824
+ versionDiagram: versionDiagram((0, import_node_path20.join)(path6)),
2825
+ /**
2826
+ * Check to see if a diagram version exists
2827
+ * @param id - The id of the diagram
2828
+ * @param version - The version of the diagram (supports semver)
2829
+ * @returns
2830
+ */
2831
+ diagramHasVersion: diagramHasVersion((0, import_node_path20.join)(path6)),
2832
+ /**
2833
+ * Adds a file to the given diagram
2834
+ * @param id - The id of the diagram to add the file to
2835
+ * @param file - File contents to add including the content and the file name
2836
+ * @param version - Optional version of the diagram to add the file to
2837
+ * @returns
2838
+ */
2839
+ addFileToDiagram: addFileToDiagram((0, import_node_path20.join)(path6)),
2840
+ /**
2841
+ * ================================
2842
+ * DSL
2843
+ * ================================
2844
+ */
2845
+ /**
2846
+ * Converts catalog resources to EventCatalog DSL (.ec) format strings.
2847
+ *
2848
+ * @param resource - A resource or array of resources to convert
2849
+ * @param options - Options including type ('event'|'command'|'query'|'service'|'domain') and optional hydrate flag
2850
+ * @returns A DSL string representation
2851
+ *
2852
+ * @example
2853
+ * ```ts
2854
+ * const dsl = await sdk.toDSL(event, { type: 'event' });
2855
+ * const dsl = await sdk.toDSL(services, { type: 'service', hydrate: true });
2856
+ * ```
2857
+ */
2858
+ toDSL: toDSL((0, import_node_path20.join)(path6), {
2859
+ getEvent: getEvent((0, import_node_path20.join)(path6)),
2860
+ getCommand: getCommand((0, import_node_path20.join)(path6)),
2861
+ getQuery: getQuery((0, import_node_path20.join)(path6)),
2862
+ getService: getService((0, import_node_path20.join)(path6)),
2863
+ getDomain: getDomain((0, import_node_path20.join)(path6, "domains")),
2864
+ getChannel: getChannel((0, import_node_path20.join)(path6)),
2865
+ getTeam: getTeam((0, import_node_path20.join)(path6, "teams")),
2866
+ getUser: getUser((0, import_node_path20.join)(path6, "users"))
2867
+ })
2868
+ };
2869
+ };
2870
+ //# sourceMappingURL=index.js.map