@eventcatalog/sdk 2.12.1 → 2.13.0

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