@eventcatalog/sdk 2.12.1 → 2.13.0

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