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