@eventcatalog/sdk 2.12.0 → 2.13.0-beta.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,2486 +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_path20 = 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_path19 = 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/index.ts
1337
- var src_default = (path6) => {
1338
- return {
1339
- /**
1340
- * Returns an events from EventCatalog
1341
- * @param id - The id of the event to retrieve
1342
- * @param version - Optional id of the version to get (supports semver)
1343
- * @returns Event|Undefined
1344
- */
1345
- getEvent: getEvent((0, import_node_path19.join)(path6)),
1346
- /**
1347
- * Returns all events from EventCatalog
1348
- * @param latestOnly - optional boolean, set to true to get only latest versions
1349
- * @returns Event[]|Undefined
1350
- */
1351
- getEvents: getEvents((0, import_node_path19.join)(path6)),
1352
- /**
1353
- * Adds an event to EventCatalog
1354
- *
1355
- * @param event - The event to write
1356
- * @param options - Optional options to write the event
1357
- *
1358
- */
1359
- writeEvent: writeEvent((0, import_node_path19.join)(path6, "events")),
1360
- /**
1361
- * Adds an event to a service in EventCatalog
1362
- *
1363
- * @param event - The event to write to the service
1364
- * @param service - The service and it's id to write to the event to
1365
- * @param options - Optional options to write the event
1366
- *
1367
- */
1368
- writeEventToService: writeEventToService((0, import_node_path19.join)(path6)),
1369
- /**
1370
- * Remove an event to EventCatalog (modeled on the standard POSIX rm utility)
1371
- *
1372
- * @param path - The path to your event, e.g. `/Inventory/InventoryAdjusted`
1373
- *
1374
- */
1375
- rmEvent: rmEvent((0, import_node_path19.join)(path6, "events")),
1376
- /**
1377
- * Remove an event by an Event id
1378
- *
1379
- * @param id - The id of the event you want to remove
1380
- *
1381
- */
1382
- rmEventById: rmEventById((0, import_node_path19.join)(path6)),
1383
- /**
1384
- * Moves a given event id to the version directory
1385
- * @param directory
1386
- */
1387
- versionEvent: versionEvent((0, import_node_path19.join)(path6)),
1388
- /**
1389
- * Adds a file to the given event
1390
- * @param id - The id of the event to add the file to
1391
- * @param file - File contents to add including the content and the file name
1392
- * @param version - Optional version of the event to add the file to
1393
- * @returns
1394
- */
1395
- addFileToEvent: addFileToEvent((0, import_node_path19.join)(path6)),
1396
- /**
1397
- * Adds a schema to the given event
1398
- * @param id - The id of the event to add the schema to
1399
- * @param schema - Schema contents to add including the content and the file name
1400
- * @param version - Optional version of the event to add the schema to
1401
- * @returns
1402
- */
1403
- addSchemaToEvent: addSchemaToEvent((0, import_node_path19.join)(path6)),
1404
- /**
1405
- * Check to see if an event version exists
1406
- * @param id - The id of the event
1407
- * @param version - The version of the event (supports semver)
1408
- * @returns
1409
- */
1410
- eventHasVersion: eventHasVersion((0, import_node_path19.join)(path6)),
1411
- /**
1412
- * ================================
1413
- * Commands
1414
- * ================================
1415
- */
1416
- /**
1417
- * Returns a command from EventCatalog
1418
- * @param id - The id of the command to retrieve
1419
- * @param version - Optional id of the version to get (supports semver)
1420
- * @returns Command|Undefined
1421
- */
1422
- getCommand: getCommand((0, import_node_path19.join)(path6)),
1423
- /**
1424
- * Returns all commands from EventCatalog
1425
- * @param latestOnly - optional boolean, set to true to get only latest versions
1426
- * @returns Command[]|Undefined
1427
- */
1428
- getCommands: getCommands((0, import_node_path19.join)(path6)),
1429
- /**
1430
- * Adds an command to EventCatalog
1431
- *
1432
- * @param command - The command to write
1433
- * @param options - Optional options to write the command
1434
- *
1435
- */
1436
- writeCommand: writeCommand((0, import_node_path19.join)(path6, "commands")),
1437
- /**
1438
- * Adds a command to a service in EventCatalog
1439
- *
1440
- * @param command - The command to write to the service
1441
- * @param service - The service and it's id to write to the command to
1442
- * @param options - Optional options to write the command
1443
- *
1444
- */
1445
- writeCommandToService: writeCommandToService((0, import_node_path19.join)(path6)),
1446
- /**
1447
- * Remove an command to EventCatalog (modeled on the standard POSIX rm utility)
1448
- *
1449
- * @param path - The path to your command, e.g. `/Inventory/InventoryAdjusted`
1450
- *
1451
- */
1452
- rmCommand: rmCommand((0, import_node_path19.join)(path6, "commands")),
1453
- /**
1454
- * Remove an command by an Event id
1455
- *
1456
- * @param id - The id of the command you want to remove
1457
- *
1458
- */
1459
- rmCommandById: rmCommandById((0, import_node_path19.join)(path6)),
1460
- /**
1461
- * Moves a given command id to the version directory
1462
- * @param directory
1463
- */
1464
- versionCommand: versionCommand((0, import_node_path19.join)(path6)),
1465
- /**
1466
- * Adds a file to the given command
1467
- * @param id - The id of the command to add the file to
1468
- * @param file - File contents to add including the content and the file name
1469
- * @param version - Optional version of the command to add the file to
1470
- * @returns
1471
- */
1472
- addFileToCommand: addFileToCommand((0, import_node_path19.join)(path6)),
1473
- /**
1474
- * Adds a schema to the given command
1475
- * @param id - The id of the command to add the schema to
1476
- * @param schema - Schema contents to add including the content and the file name
1477
- * @param version - Optional version of the command to add the schema to
1478
- * @returns
1479
- */
1480
- addSchemaToCommand: addSchemaToCommand((0, import_node_path19.join)(path6)),
1481
- /**
1482
- * Check to see if a command version exists
1483
- * @param id - The id of the command
1484
- * @param version - The version of the command (supports semver)
1485
- * @returns
1486
- */
1487
- commandHasVersion: commandHasVersion((0, import_node_path19.join)(path6)),
1488
- /**
1489
- * ================================
1490
- * Queries
1491
- * ================================
1492
- */
1493
- /**
1494
- * Returns a query from EventCatalog
1495
- * @param id - The id of the query to retrieve
1496
- * @param version - Optional id of the version to get (supports semver)
1497
- * @returns Query|Undefined
1498
- */
1499
- getQuery: getQuery((0, import_node_path19.join)(path6)),
1500
- /**
1501
- * Returns all queries from EventCatalog
1502
- * @param latestOnly - optional boolean, set to true to get only latest versions
1503
- * @returns Query[]|Undefined
1504
- */
1505
- getQueries: getQueries((0, import_node_path19.join)(path6)),
1506
- /**
1507
- * Adds a query to EventCatalog
1508
- *
1509
- * @param query - The query to write
1510
- * @param options - Optional options to write the event
1511
- *
1512
- */
1513
- writeQuery: writeQuery((0, import_node_path19.join)(path6, "queries")),
1514
- /**
1515
- * Adds a query to a service in EventCatalog
1516
- *
1517
- * @param query - The query to write to the service
1518
- * @param service - The service and it's id to write to the query to
1519
- * @param options - Optional options to write the query
1520
- *
1521
- */
1522
- writeQueryToService: writeQueryToService((0, import_node_path19.join)(path6)),
1523
- /**
1524
- * Remove an query to EventCatalog (modeled on the standard POSIX rm utility)
1525
- *
1526
- * @param path - The path to your query, e.g. `/Orders/GetOrder`
1527
- *
1528
- */
1529
- rmQuery: rmQuery((0, import_node_path19.join)(path6, "queries")),
1530
- /**
1531
- * Remove a query by a Query id
1532
- *
1533
- * @param id - The id of the query you want to remove
1534
- *
1535
- */
1536
- rmQueryById: rmQueryById((0, import_node_path19.join)(path6)),
1537
- /**
1538
- * Moves a given query id to the version directory
1539
- * @param directory
1540
- */
1541
- versionQuery: versionQuery((0, import_node_path19.join)(path6)),
1542
- /**
1543
- * Adds a file to the given query
1544
- * @param id - The id of the query to add the file to
1545
- * @param file - File contents to add including the content and the file name
1546
- * @param version - Optional version of the query to add the file to
1547
- * @returns
1548
- */
1549
- addFileToQuery: addFileToQuery((0, import_node_path19.join)(path6)),
1550
- /**
1551
- * Adds a schema to the given query
1552
- * @param id - The id of the query to add the schema to
1553
- * @param schema - Schema contents to add including the content and the file name
1554
- * @param version - Optional version of the query to add the schema to
1555
- * @returns
1556
- */
1557
- addSchemaToQuery: addSchemaToQuery((0, import_node_path19.join)(path6)),
1558
- /**
1559
- * Check to see if an query version exists
1560
- * @param id - The id of the query
1561
- * @param version - The version of the query (supports semver)
1562
- * @returns
1563
- */
1564
- queryHasVersion: queryHasVersion((0, import_node_path19.join)(path6)),
1565
- /**
1566
- * ================================
1567
- * Channels
1568
- * ================================
1569
- */
1570
- /**
1571
- * Returns a channel from EventCatalog
1572
- * @param id - The id of the channel to retrieve
1573
- * @param version - Optional id of the version to get (supports semver)
1574
- * @returns Channel|Undefined
1575
- */
1576
- getChannel: getChannel((0, import_node_path19.join)(path6)),
1577
- /**
1578
- * Returns all channels from EventCatalog
1579
- * @param latestOnly - optional boolean, set to true to get only latest versions
1580
- * @returns Channel[]|Undefined
1581
- */
1582
- getChannels: getChannels((0, import_node_path19.join)(path6)),
1583
- /**
1584
- * Adds an channel to EventCatalog
1585
- *
1586
- * @param command - The channel to write
1587
- * @param options - Optional options to write the channel
1588
- *
1589
- */
1590
- writeChannel: writeChannel((0, import_node_path19.join)(path6, "channels")),
1591
- /**
1592
- * Remove an channel to EventCatalog (modeled on the standard POSIX rm utility)
1593
- *
1594
- * @param path - The path to your channel, e.g. `/Inventory/InventoryAdjusted`
1595
- *
1596
- */
1597
- rmChannel: rmChannel((0, import_node_path19.join)(path6, "channels")),
1598
- /**
1599
- * Remove an channel by an Event id
1600
- *
1601
- * @param id - The id of the channel you want to remove
1602
- *
1603
- */
1604
- rmChannelById: rmChannelById((0, import_node_path19.join)(path6)),
1605
- /**
1606
- * Moves a given channel id to the version directory
1607
- * @param directory
1608
- */
1609
- versionChannel: versionChannel((0, import_node_path19.join)(path6)),
1610
- /**
1611
- * Check to see if a channel version exists
1612
- * @param id - The id of the channel
1613
- * @param version - The version of the channel (supports semver)
1614
- * @returns
1615
- */
1616
- channelHasVersion: channelHasVersion((0, import_node_path19.join)(path6)),
1617
- /**
1618
- * Add a channel to an event
1619
- *
1620
- * Optionally specify a version to add the channel to a specific version of the event.
1621
- *
1622
- * @example
1623
- * ```ts
1624
- * import utils from '@eventcatalog/utils';
1625
- *
1626
- * const { addEventToChannel } = utils('/path/to/eventcatalog');
1627
- *
1628
- * // adds a new event (InventoryUpdatedEvent) to the inventory.{env}.events channel
1629
- * await addEventToChannel('inventory.{env}.events channel', { id: 'InventoryUpdatedEvent', version: '2.0.0', parameters: { env: 'dev' } });
1630
- *
1631
- * ```
1632
- */
1633
- addEventToChannel: addMessageToChannel((0, import_node_path19.join)(path6), "events"),
1634
- /**
1635
- * Add a channel to an command
1636
- *
1637
- * Optionally specify a version to add the channel to a specific version of the command.
1638
- *
1639
- * @example
1640
- * ```ts
1641
- * import utils from '@eventcatalog/utils';
1642
- *
1643
- * const { addCommandToChannel } = utils('/path/to/eventcatalog');
1644
- *
1645
- * // adds a new command (UpdateInventory) to the inventory.{env}.events channel
1646
- * await addCommandToChannel('inventory.{env}.events channel', { id: 'UpdateInventory', version: '2.0.0', parameters: { env: 'dev' } });
1647
- *
1648
- * ```
1649
- */
1650
- addCommandToChannel: addMessageToChannel((0, import_node_path19.join)(path6), "commands"),
1651
- /**
1652
- * Add a channel to an query
1653
- *
1654
- * Optionally specify a version to add the channel to a specific version of the query.
1655
- *
1656
- * @example
1657
- * ```ts
1658
- * import utils from '@eventcatalog/utils';
1659
- *
1660
- * const { addQueryToChannel } = utils('/path/to/eventcatalog');
1661
- *
1662
- * // adds a new query (GetInventory) to the inventory.{env}.events channel
1663
- * await addQueryToChannel('inventory.{env}.events channel', { id: 'GetInventory', version: '2.0.0', parameters: { env: 'dev' } });
1664
- *
1665
- * ```
1666
- */
1667
- addQueryToChannel: addMessageToChannel((0, import_node_path19.join)(path6), "queries"),
1668
- /**
1669
- * ================================
1670
- * SERVICES
1671
- * ================================
1672
- */
1673
- /**
1674
- * Adds a service to EventCatalog
1675
- *
1676
- * @param service - The service to write
1677
- * @param options - Optional options to write the event
1678
- *
1679
- */
1680
- writeService: writeService((0, import_node_path19.join)(path6, "services")),
1681
- /**
1682
- * Adds a versioned service to EventCatalog
1683
- *
1684
- * @param service - The service to write
1685
- *
1686
- */
1687
- writeVersionedService: writeVersionedService((0, import_node_path19.join)(path6, "services")),
1688
- /**
1689
- * Adds a service to a domain in EventCatalog
1690
- *
1691
- * @param service - The service to write
1692
- * @param domain - The domain to add the service to
1693
- * @param options - Optional options to write the event
1694
- *
1695
- */
1696
- writeServiceToDomain: writeServiceToDomain((0, import_node_path19.join)(path6, "domains")),
1697
- /**
1698
- * Returns a service from EventCatalog
1699
- * @param id - The id of the service to retrieve
1700
- * @param version - Optional id of the version to get (supports semver)
1701
- * @returns Service|Undefined
1702
- */
1703
- getService: getService((0, import_node_path19.join)(path6)),
1704
- /**
1705
- * Returns a service from EventCatalog by it's path.
1706
- * @param path - The path to the service to retrieve
1707
- * @returns Service|Undefined
1708
- */
1709
- getServiceByPath: getServiceByPath((0, import_node_path19.join)(path6)),
1710
- /**
1711
- * Returns all services from EventCatalog
1712
- * @param latestOnly - optional boolean, set to true to get only latest versions
1713
- * @returns Service[]|Undefined
1714
- */
1715
- getServices: getServices((0, import_node_path19.join)(path6)),
1716
- /**
1717
- * Moves a given service id to the version directory
1718
- * @param directory
1719
- */
1720
- versionService: versionService((0, import_node_path19.join)(path6)),
1721
- /**
1722
- * Remove a service from EventCatalog (modeled on the standard POSIX rm utility)
1723
- *
1724
- * @param path - The path to your service, e.g. `/InventoryService`
1725
- *
1726
- */
1727
- rmService: rmService((0, import_node_path19.join)(path6, "services")),
1728
- /**
1729
- * Remove an service by an service id
1730
- *
1731
- * @param id - The id of the service you want to remove
1732
- *
1733
- */
1734
- rmServiceById: rmServiceById((0, import_node_path19.join)(path6)),
1735
- /**
1736
- * Adds a file to the given service
1737
- * @param id - The id of the service to add the file to
1738
- * @param file - File contents to add including the content and the file name
1739
- * @param version - Optional version of the service to add the file to
1740
- * @returns
1741
- */
1742
- addFileToService: addFileToService((0, import_node_path19.join)(path6)),
1743
- /**
1744
- * Returns the specifications for a given service
1745
- * @param id - The id of the service to retrieve the specifications for
1746
- * @param version - Optional version of the service
1747
- * @returns
1748
- */
1749
- getSpecificationFilesForService: getSpecificationFilesForService((0, import_node_path19.join)(path6)),
1750
- /**
1751
- * Check to see if a service version exists
1752
- * @param id - The id of the service
1753
- * @param version - The version of the service (supports semver)
1754
- * @returns
1755
- */
1756
- serviceHasVersion: serviceHasVersion((0, import_node_path19.join)(path6)),
1757
- /**
1758
- * Add an event to a service by it's id.
1759
- *
1760
- * Optionally specify a version to add the event to a specific version of the service.
1761
- *
1762
- * @example
1763
- * ```ts
1764
- * import utils from '@eventcatalog/utils';
1765
- *
1766
- * const { addEventToService } = utils('/path/to/eventcatalog');
1767
- *
1768
- * // adds a new event (InventoryUpdatedEvent) that the InventoryService will send
1769
- * await addEventToService('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });
1770
- *
1771
- * // adds a new event (OrderComplete) that the InventoryService will receive
1772
- * await addEventToService('InventoryService', 'receives', { event: 'OrderComplete', version: '2.0.0' });
1773
- *
1774
- * ```
1775
- */
1776
- addEventToService: addMessageToService((0, import_node_path19.join)(path6)),
1777
- /**
1778
- * Add a data store to a service by it's id.
1779
- *
1780
- * Optionally specify a version to add the data store to a specific version of the service.
1781
- *
1782
- * @example
1783
- * ```ts
1784
- * import utils from '@eventcatalog/utils';
1785
- *
1786
- * const { addDataStoreToService } = utils('/path/to/eventcatalog');
1787
- *
1788
- * // adds a new data store (orders-db) that the InventoryService will write to
1789
- * await addDataStoreToService('InventoryService', 'writesTo', { id: 'orders-db', version: '2.0.0' });
1790
- *
1791
- * ```
1792
- */
1793
- addDataStoreToService: addDataStoreToService((0, import_node_path19.join)(path6)),
1794
- /**
1795
- * Add a command to a service by it's id.
1796
- *
1797
- * Optionally specify a version to add the event to a specific version of the service.
1798
- *
1799
- * @example
1800
- * ```ts
1801
- * import utils from '@eventcatalog/utils';
1802
- *
1803
- * const { addCommandToService } = utils('/path/to/eventcatalog');
1804
- *
1805
- * // adds a new command (UpdateInventoryCommand) that the InventoryService will send
1806
- * await addCommandToService('InventoryService', 'sends', { command: 'UpdateInventoryCommand', version: '2.0.0' });
1807
- *
1808
- * // adds a new command (VerifyInventory) that the InventoryService will receive
1809
- * await addCommandToService('InventoryService', 'receives', { command: 'VerifyInventory', version: '2.0.0' });
1810
- *
1811
- * ```
1812
- */
1813
- addCommandToService: addMessageToService((0, import_node_path19.join)(path6)),
1814
- /**
1815
- * Add a query to a service by it's id.
1816
- *
1817
- * Optionally specify a version to add the event to a specific version of the service.
1818
- *
1819
- * @example
1820
- * ```ts
1821
- * import utils from '@eventcatalog/utils';
1822
- *
1823
- * const { addQueryToService } = utils('/path/to/eventcatalog');
1824
- *
1825
- * // adds a new query (UpdateInventory) that the InventoryService will send
1826
- * await addQueryToService('InventoryService', 'sends', { command: 'UpdateInventory', version: '2.0.0' });
1827
- *
1828
- * // adds a new command (VerifyInventory) that the InventoryService will receive
1829
- * await addQueryToService('InventoryService', 'receives', { command: 'VerifyInventory', version: '2.0.0' });
1830
- *
1831
- * ```
1832
- */
1833
- addQueryToService: addMessageToService((0, import_node_path19.join)(path6)),
1834
- /**
1835
- * Add an entity to a service by its id.
1836
- *
1837
- * @example
1838
- * ```ts
1839
- * import utils from '@eventcatalog/utils';
1840
- *
1841
- * const { addEntityToService } = utils('/path/to/eventcatalog');
1842
- *
1843
- * // adds a new entity (User) to the InventoryService
1844
- * await addEntityToService('InventoryService', { id: 'User', version: '1.0.0' });
1845
- *
1846
- * // adds a new entity (Product) to a specific version of the InventoryService
1847
- * await addEntityToService('InventoryService', { id: 'Product', version: '1.0.0' }, '2.0.0');
1848
- *
1849
- * ```
1850
- */
1851
- addEntityToService: addEntityToService((0, import_node_path19.join)(path6)),
1852
- /**
1853
- * Check to see if a service exists by it's path.
1854
- *
1855
- * @example
1856
- * ```ts
1857
- * import utils from '@eventcatalog/utils';
1858
- *
1859
- * const { isService } = utils('/path/to/eventcatalog');
1860
- *
1861
- * // returns true if the path is a service
1862
- * await isService('/services/InventoryService/index.mdx');
1863
- * ```
1864
- *
1865
- * @param path - The path to the service to check
1866
- * @returns boolean
1867
- */
1868
- isService: isService((0, import_node_path19.join)(path6)),
1869
- /**
1870
- * Converts a file to a service.
1871
- * @param file - The file to convert to a service.
1872
- * @returns The service.
1873
- */
1874
- toService: toService((0, import_node_path19.join)(path6)),
1875
- /**
1876
- * ================================
1877
- * Domains
1878
- * ================================
1879
- */
1880
- /**
1881
- * Adds a domain to EventCatalog
1882
- *
1883
- * @param domain - The domain to write
1884
- * @param options - Optional options to write the event
1885
- *
1886
- */
1887
- writeDomain: writeDomain((0, import_node_path19.join)(path6, "domains")),
1888
- /**
1889
- * Returns a domain from EventCatalog
1890
- * @param id - The id of the domain to retrieve
1891
- * @param version - Optional id of the version to get (supports semver)
1892
- * @returns Domain|Undefined
1893
- */
1894
- getDomain: getDomain((0, import_node_path19.join)(path6, "domains")),
1895
- /**
1896
- * Returns all domains from EventCatalog
1897
- * @param latestOnly - optional boolean, set to true to get only latest versions
1898
- * @returns Domain[]|Undefined
1899
- */
1900
- getDomains: getDomains((0, import_node_path19.join)(path6)),
1901
- /**
1902
- * Moves a given domain id to the version directory
1903
- * @param directory
1904
- */
1905
- versionDomain: versionDomain((0, import_node_path19.join)(path6, "domains")),
1906
- /**
1907
- * Remove a domain from EventCatalog (modeled on the standard POSIX rm utility)
1908
- *
1909
- * @param path - The path to your domain, e.g. `/Payment`
1910
- *
1911
- */
1912
- rmDomain: rmDomain((0, import_node_path19.join)(path6, "domains")),
1913
- /**
1914
- * Remove an service by an domain id
1915
- *
1916
- * @param id - The id of the domain you want to remove
1917
- *
1918
- */
1919
- rmDomainById: rmDomainById((0, import_node_path19.join)(path6, "domains")),
1920
- /**
1921
- * Adds a file to the given domain
1922
- * @param id - The id of the domain to add the file to
1923
- * @param file - File contents to add including the content and the file name
1924
- * @param version - Optional version of the domain to add the file to
1925
- * @returns
1926
- */
1927
- addFileToDomain: addFileToDomain((0, import_node_path19.join)(path6, "domains")),
1928
- /**
1929
- * Adds an ubiquitous language dictionary to a domain
1930
- * @param id - The id of the domain to add the ubiquitous language to
1931
- * @param ubiquitousLanguageDictionary - The ubiquitous language dictionary to add
1932
- * @param version - Optional version of the domain to add the ubiquitous language to
1933
- */
1934
- addUbiquitousLanguageToDomain: addUbiquitousLanguageToDomain((0, import_node_path19.join)(path6, "domains")),
1935
- /**
1936
- * Get the ubiquitous language dictionary from a domain
1937
- * @param id - The id of the domain to get the ubiquitous language from
1938
- * @param version - Optional version of the domain to get the ubiquitous language from
1939
- * @returns
1940
- */
1941
- getUbiquitousLanguageFromDomain: getUbiquitousLanguageFromDomain((0, import_node_path19.join)(path6, "domains")),
1942
- /**
1943
- * Check to see if a domain version exists
1944
- * @param id - The id of the domain
1945
- * @param version - The version of the domain (supports semver)
1946
- * @returns
1947
- */
1948
- domainHasVersion: domainHasVersion((0, import_node_path19.join)(path6)),
1949
- /**
1950
- * Adds a given service to a domain
1951
- * @param id - The id of the domain
1952
- * @param service - The id and version of the service to add
1953
- * @param version - (Optional) The version of the domain to add the service to
1954
- * @returns
1955
- */
1956
- addServiceToDomain: addServiceToDomain((0, import_node_path19.join)(path6, "domains")),
1957
- /**
1958
- * Adds a given subdomain to a domain
1959
- * @param id - The id of the domain
1960
- * @param subDomain - The id and version of the subdomain to add
1961
- * @param version - (Optional) The version of the domain to add the subdomain to
1962
- * @returns
1963
- */
1964
- addSubDomainToDomain: addSubDomainToDomain((0, import_node_path19.join)(path6, "domains")),
1965
- /**
1966
- * Adds an entity to a domain
1967
- * @param id - The id of the domain
1968
- * @param entity - The id and version of the entity to add
1969
- * @param version - (Optional) The version of the domain to add the entity to
1970
- * @returns
1971
- */
1972
- addEntityToDomain: addEntityToDomain((0, import_node_path19.join)(path6, "domains")),
1973
- /**
1974
- * Add an event to a domain by its id.
1975
- *
1976
- * @example
1977
- * ```ts
1978
- * import utils from '@eventcatalog/utils';
1979
- *
1980
- * const { addEventToDomain } = utils('/path/to/eventcatalog');
1981
- *
1982
- * // adds a new event (OrderCreated) that the Orders domain will send
1983
- * await addEventToDomain('Orders', 'sends', { id: 'OrderCreated', version: '2.0.0' });
1984
- *
1985
- * // adds a new event (PaymentProcessed) that the Orders domain will receive
1986
- * await addEventToDomain('Orders', 'receives', { id: 'PaymentProcessed', version: '2.0.0' });
1987
- *
1988
- * ```
1989
- */
1990
- addEventToDomain: addMessageToDomain((0, import_node_path19.join)(path6, "domains")),
1991
- /**
1992
- * Add a command to a domain by its id.
1993
- *
1994
- * @example
1995
- * ```ts
1996
- * import utils from '@eventcatalog/utils';
1997
- *
1998
- * const { addCommandToDomain } = utils('/path/to/eventcatalog');
1999
- *
2000
- * // adds a new command (ProcessOrder) that the Orders domain will send
2001
- * await addCommandToDomain('Orders', 'sends', { id: 'ProcessOrder', version: '2.0.0' });
2002
- *
2003
- * // adds a new command (CancelOrder) that the Orders domain will receive
2004
- * await addCommandToDomain('Orders', 'receives', { id: 'CancelOrder', version: '2.0.0' });
2005
- *
2006
- * ```
2007
- */
2008
- addCommandToDomain: addMessageToDomain((0, import_node_path19.join)(path6, "domains")),
2009
- /**
2010
- * Add a query to a domain by its id.
2011
- *
2012
- * @example
2013
- * ```ts
2014
- * import utils from '@eventcatalog/utils';
2015
- *
2016
- * const { addQueryToDomain } = utils('/path/to/eventcatalog');
2017
- *
2018
- * // adds a new query (GetOrderStatus) that the Orders domain will send
2019
- * await addQueryToDomain('Orders', 'sends', { id: 'GetOrderStatus', version: '2.0.0' });
2020
- *
2021
- * // adds a new query (GetInventory) that the Orders domain will receive
2022
- * await addQueryToDomain('Orders', 'receives', { id: 'GetInventory', version: '2.0.0' });
2023
- *
2024
- * ```
2025
- */
2026
- addQueryToDomain: addMessageToDomain((0, import_node_path19.join)(path6, "domains")),
2027
- /**
2028
- * ================================
2029
- * Teams
2030
- * ================================
2031
- */
2032
- /**
2033
- * Adds a team to EventCatalog
2034
- *
2035
- * @param team - The team to write
2036
- * @param options - Optional options to write the team
2037
- *
2038
- */
2039
- writeTeam: writeTeam((0, import_node_path19.join)(path6, "teams")),
2040
- /**
2041
- * Returns a team from EventCatalog
2042
- * @param id - The id of the team to retrieve
2043
- * @returns Team|Undefined
2044
- */
2045
- getTeam: getTeam((0, import_node_path19.join)(path6, "teams")),
2046
- /**
2047
- * Returns all teams from EventCatalog
2048
- * @returns Team[]|Undefined
2049
- */
2050
- getTeams: getTeams((0, import_node_path19.join)(path6, "teams")),
2051
- /**
2052
- * Remove a team by the team id
2053
- *
2054
- * @param id - The id of the team you want to remove
2055
- *
2056
- */
2057
- rmTeamById: rmTeamById((0, import_node_path19.join)(path6, "teams")),
2058
- /**
2059
- * ================================
2060
- * Users
2061
- * ================================
2062
- */
2063
- /**
2064
- * Adds a user to EventCatalog
2065
- *
2066
- * @param user - The user to write
2067
- * @param options - Optional options to write the user
2068
- *
2069
- */
2070
- writeUser: writeUser((0, import_node_path19.join)(path6, "users")),
2071
- /**
2072
- * Returns a user from EventCatalog
2073
- * @param id - The id of the user to retrieve
2074
- * @returns User|Undefined
2075
- */
2076
- getUser: getUser((0, import_node_path19.join)(path6, "users")),
2077
- /**
2078
- * Returns all user from EventCatalog
2079
- * @returns User[]|Undefined
2080
- */
2081
- getUsers: getUsers((0, import_node_path19.join)(path6)),
2082
- /**
2083
- * Remove a user by the user id
2084
- *
2085
- * @param id - The id of the user you want to remove
2086
- *
2087
- */
2088
- rmUserById: rmUserById((0, import_node_path19.join)(path6, "users")),
2089
- /**
2090
- * ================================
2091
- * Custom Docs
2092
- * ================================
2093
- */
2094
- /**
2095
- * Returns a custom doc from EventCatalog
2096
- * @param path - The path to the custom doc to retrieve
2097
- * @returns CustomDoc|Undefined
2098
- */
2099
- getCustomDoc: getCustomDoc((0, import_node_path19.join)(path6, "docs")),
2100
- /**
2101
- * Returns all custom docs from EventCatalog
2102
- * @param options - Optional options to get custom docs from a specific path
2103
- * @returns CustomDoc[]|Undefined
2104
- */
2105
- getCustomDocs: getCustomDocs((0, import_node_path19.join)(path6, "docs")),
2106
- /**
2107
- * Writes a custom doc to EventCatalog
2108
- * @param customDoc - The custom doc to write
2109
- * @param options - Optional options to write the custom doc
2110
- *
2111
- */
2112
- writeCustomDoc: writeCustomDoc((0, import_node_path19.join)(path6, "docs")),
2113
- /**
2114
- * Removes a custom doc from EventCatalog
2115
- * @param path - The path to the custom doc to remove
2116
- *
2117
- */
2118
- rmCustomDoc: rmCustomDoc((0, import_node_path19.join)(path6, "docs")),
2119
- /**
2120
- * Dumps the catalog to a JSON file.
2121
- * @param directory - The directory to dump the catalog to
2122
- * @returns A JSON file with the catalog
2123
- */
2124
- dumpCatalog: dumpCatalog((0, import_node_path19.join)(path6)),
2125
- /**
2126
- * Returns the event catalog configuration file.
2127
- * The event catalog configuration file is the file that contains the configuration for the event catalog.
2128
- *
2129
- * @param directory - The directory of the catalog.
2130
- * @returns A JSON object with the configuration for the event catalog.
2131
- */
2132
- getEventCatalogConfigurationFile: getEventCatalogConfigurationFile((0, import_node_path19.join)(path6)),
2133
- /**
2134
- * ================================
2135
- * Resources Utils
2136
- * ================================
2137
- */
2138
- /**
2139
- * Returns the path to a given resource by id and version
2140
- */
2141
- getResourcePath,
2142
- /**
2143
- * Returns the folder name of a given resource
2144
- */
2145
- getResourceFolderName,
2146
- /**
2147
- * ================================
2148
- * General Message Utils
2149
- * ================================
2150
- */
2151
- /**
2152
- * Returns a message from EventCatalog by a given schema path.
2153
- *
2154
- * @param path - The path to the message to retrieve
2155
- * @returns Message|Undefined
2156
- */
2157
- getMessageBySchemaPath: getMessageBySchemaPath((0, import_node_path19.join)(path6)),
2158
- /**
2159
- * Returns the producers and consumers (services) for a given message
2160
- * @param id - The id of the message to get the producers and consumers for
2161
- * @param version - Optional version of the message
2162
- * @returns { producers: Service[], consumers: Service[] }
2163
- */
2164
- getProducersAndConsumersForMessage: getProducersAndConsumersForMessage((0, import_node_path19.join)(path6)),
2165
- /**
2166
- * Returns the consumers of a given schema path
2167
- * @param path - The path to the schema to get the consumers for
2168
- * @returns Service[]
2169
- */
2170
- getConsumersOfSchema: getConsumersOfSchema((0, import_node_path19.join)(path6)),
2171
- /**
2172
- * Returns the producers of a given schema path
2173
- * @param path - The path to the schema to get the producers for
2174
- * @returns Service[]
2175
- */
2176
- getProducersOfSchema: getProducersOfSchema((0, import_node_path19.join)(path6)),
2177
- /**
2178
- * Returns the owners for a given resource (e.g domain, service, event, command, query, etc.)
2179
- * @param id - The id of the resource to get the owners for
2180
- * @param version - Optional version of the resource
2181
- * @returns { owners: User[] }
2182
- */
2183
- getOwnersForResource: getOwnersForResource((0, import_node_path19.join)(path6)),
2184
- /**
2185
- * ================================
2186
- * Entities
2187
- * ================================
2188
- */
2189
- /**
2190
- * Returns an entity from EventCatalog
2191
- * @param id - The id of the entity to retrieve
2192
- * @param version - Optional id of the version to get (supports semver)
2193
- * @returns Entity|Undefined
2194
- */
2195
- getEntity: getEntity((0, import_node_path19.join)(path6)),
2196
- /**
2197
- * Returns all entities from EventCatalog
2198
- * @param latestOnly - optional boolean, set to true to get only latest versions
2199
- * @returns Entity[]|Undefined
2200
- */
2201
- getEntities: getEntities((0, import_node_path19.join)(path6)),
2202
- /**
2203
- * Adds an entity to EventCatalog
2204
- *
2205
- * @param entity - The entity to write
2206
- * @param options - Optional options to write the entity
2207
- *
2208
- */
2209
- writeEntity: writeEntity((0, import_node_path19.join)(path6, "entities")),
2210
- /**
2211
- * Remove an entity from EventCatalog (modeled on the standard POSIX rm utility)
2212
- *
2213
- * @param path - The path to your entity, e.g. `/User`
2214
- *
2215
- */
2216
- rmEntity: rmEntity((0, import_node_path19.join)(path6, "entities")),
2217
- /**
2218
- * Remove an entity by an entity id
2219
- *
2220
- * @param id - The id of the entity you want to remove
2221
- *
2222
- */
2223
- rmEntityById: rmEntityById((0, import_node_path19.join)(path6)),
2224
- /**
2225
- * Moves a given entity id to the version directory
2226
- * @param id - The id of the entity to version
2227
- */
2228
- versionEntity: versionEntity((0, import_node_path19.join)(path6)),
2229
- /**
2230
- * Check to see if an entity version exists
2231
- * @param id - The id of the entity
2232
- * @param version - The version of the entity (supports semver)
2233
- * @returns
2234
- */
2235
- entityHasVersion: entityHasVersion((0, import_node_path19.join)(path6)),
2236
- /**
2237
- * ================================
2238
- * Data Stores
2239
- * ================================
2240
- */
2241
- /**
2242
- * Adds a data store to EventCatalog
2243
- * @param dataStore - The data store to write
2244
- * @param options - Optional options to write the data store
2245
- *
2246
- */
2247
- writeDataStore: writeDataStore((0, import_node_path19.join)(path6, "containers")),
2248
- /**
2249
- * Returns a data store from EventCatalog
2250
- * @param id - The id of the data store to retrieve
2251
- * @param version - Optional id of the version to get (supports semver)
2252
- * @returns Container|Undefined
2253
- */
2254
- getDataStore: getDataStore((0, import_node_path19.join)(path6)),
2255
- /**
2256
- * Returns all data stores from EventCatalog
2257
- * @param latestOnly - optional boolean, set to true to get only latest versions
2258
- * @returns Container[]|Undefined
2259
- */
2260
- getDataStores: getDataStores((0, import_node_path19.join)(path6)),
2261
- /**
2262
- * Version a data store by its id
2263
- * @param id - The id of the data store to version
2264
- */
2265
- versionDataStore: versionDataStore((0, import_node_path19.join)(path6, "containers")),
2266
- /**
2267
- * Remove a data store by its path
2268
- * @param path - The path to the data store to remove
2269
- */
2270
- rmDataStore: rmDataStore((0, import_node_path19.join)(path6, "containers")),
2271
- /**
2272
- * Remove a data store by its id
2273
- * @param id - The id of the data store to remove
2274
- */
2275
- rmDataStoreById: rmDataStoreById((0, import_node_path19.join)(path6)),
2276
- /**
2277
- * Check to see if a data store version exists
2278
- * @param id - The id of the data store
2279
- * @param version - The version of the data store (supports semver)
2280
- * @returns
2281
- */
2282
- dataStoreHasVersion: dataStoreHasVersion((0, import_node_path19.join)(path6)),
2283
- /**
2284
- * Adds a file to a data store by its id
2285
- * @param id - The id of the data store to add the file to
2286
- * @param file - File contents to add including the content and the file name
2287
- * @param version - Optional version of the data store to add the file to
2288
- * @returns
2289
- */
2290
- addFileToDataStore: addFileToDataStore((0, import_node_path19.join)(path6)),
2291
- /**
2292
- * Writes a data store to a service by its id
2293
- * @param dataStore - The data store to write
2294
- * @param service - The service to write the data store to
2295
- * @returns
2296
- */
2297
- writeDataStoreToService: writeDataStoreToService((0, import_node_path19.join)(path6)),
2298
- /**
2299
- * ================================
2300
- * Data Products
2301
- * ================================
2302
- */
2303
- /**
2304
- * Adds a data product to EventCatalog
2305
- * @param dataProduct - The data product to write
2306
- * @param options - Optional options to write the data product
2307
- *
2308
- */
2309
- writeDataProduct: writeDataProduct((0, import_node_path19.join)(path6, "data-products")),
2310
- /**
2311
- * Writes a data product to a domain in EventCatalog
2312
- * @param dataProduct - The data product to write
2313
- * @param domain - The domain to write the data product to
2314
- * @param options - Optional options to write the data product
2315
- *
2316
- */
2317
- writeDataProductToDomain: writeDataProductToDomain((0, import_node_path19.join)(path6, "domains")),
2318
- /**
2319
- * Returns a data product from EventCatalog
2320
- * @param id - The id of the data product to retrieve
2321
- * @param version - Optional id of the version to get (supports semver)
2322
- * @returns DataProduct|Undefined
2323
- */
2324
- getDataProduct: getDataProduct((0, import_node_path19.join)(path6)),
2325
- /**
2326
- * Returns all data products from EventCatalog
2327
- * @param latestOnly - optional boolean, set to true to get only latest versions
2328
- * @returns DataProduct[]|Undefined
2329
- */
2330
- getDataProducts: getDataProducts((0, import_node_path19.join)(path6)),
2331
- /**
2332
- * Version a data product by its id
2333
- * @param id - The id of the data product to version
2334
- */
2335
- versionDataProduct: versionDataProduct((0, import_node_path19.join)(path6)),
2336
- /**
2337
- * Remove a data product by its path
2338
- * @param path - The path to the data product to remove
2339
- */
2340
- rmDataProduct: rmDataProduct((0, import_node_path19.join)(path6, "data-products")),
2341
- /**
2342
- * Remove a data product by its id
2343
- * @param id - The id of the data product to remove
2344
- * @param version - Optional version of the data product to remove
2345
- */
2346
- rmDataProductById: rmDataProductById((0, import_node_path19.join)(path6)),
2347
- /**
2348
- * Check to see if a data product version exists
2349
- * @param id - The id of the data product
2350
- * @param version - The version of the data product (supports semver)
2351
- * @returns
2352
- */
2353
- dataProductHasVersion: dataProductHasVersion((0, import_node_path19.join)(path6)),
2354
- /**
2355
- * Adds a file to a data product by its id
2356
- * @param id - The id of the data product to add the file to
2357
- * @param file - File contents to add including the content and the file name
2358
- * @param version - Optional version of the data product to add the file to
2359
- * @returns
2360
- */
2361
- addFileToDataProduct: addFileToDataProduct((0, import_node_path19.join)(path6)),
2362
- /**
2363
- * Adds a data product to a domain
2364
- * @param id - The id of the domain
2365
- * @param dataProduct - The id and version of the data product to add
2366
- * @param version - (Optional) The version of the domain to add the data product to
2367
- * @returns
2368
- */
2369
- addDataProductToDomain: addDataProductToDomain((0, import_node_path19.join)(path6, "domains"))
2370
- };
2371
- };
2372
-
2373
- // src/cli/executor.ts
2374
- async function executeFunction(catalogDir, functionName, rawArgs) {
2375
- if (!(0, import_node_fs7.existsSync)(catalogDir)) {
2376
- throw new Error(`Catalog directory not found: ${catalogDir}`);
2377
- }
2378
- const sdk = src_default(catalogDir);
2379
- if (!(functionName in sdk)) {
2380
- throw new Error(`Function '${functionName}' not found. Use 'eventcatalog list' to see available functions.`);
2381
- }
2382
- const fn = sdk[functionName];
2383
- if (typeof fn !== "function") {
2384
- throw new Error(`'${functionName}' is not a callable function.`);
2385
- }
2386
- const parsedArgs = parseArguments(rawArgs);
2387
- try {
2388
- return await fn(...parsedArgs);
2389
- } catch (error) {
2390
- throw new Error(`Error executing '${functionName}': ${error instanceof Error ? error.message : String(error)}`);
2391
- }
2392
- }
2393
-
2394
- // src/cli/list.ts
2395
- function listFunctions(catalogDir = ".") {
2396
- const sdk = src_default(catalogDir);
2397
- const functionNames = Object.keys(sdk).filter((key) => typeof sdk[key] === "function");
2398
- const categories = {
2399
- Events: [],
2400
- Commands: [],
2401
- Queries: [],
2402
- Channels: [],
2403
- Services: [],
2404
- Domains: [],
2405
- Entities: [],
2406
- DataStores: [],
2407
- DataProducts: [],
2408
- Teams: [],
2409
- Users: [],
2410
- "Custom Docs": [],
2411
- Messages: [],
2412
- Utilities: []
2413
- };
2414
- functionNames.forEach((name) => {
2415
- if (name.includes("Event")) categories["Events"].push(name);
2416
- else if (name.includes("Command")) categories["Commands"].push(name);
2417
- else if (name.includes("Query")) categories["Queries"].push(name);
2418
- else if (name.includes("Channel")) categories["Channels"].push(name);
2419
- else if (name.includes("Service")) categories["Services"].push(name);
2420
- else if (name.includes("Domain")) categories["Domains"].push(name);
2421
- else if (name.includes("Entity")) categories["Entities"].push(name);
2422
- else if (name.includes("DataStore")) categories["DataStores"].push(name);
2423
- else if (name.includes("DataProduct")) categories["DataProducts"].push(name);
2424
- else if (name.includes("Team")) categories["Teams"].push(name);
2425
- else if (name.includes("User")) categories["Users"].push(name);
2426
- else if (name.includes("CustomDoc")) categories["Custom Docs"].push(name);
2427
- else if (name.includes("Message") || name.includes("Producers") || name.includes("Consumers"))
2428
- categories["Messages"].push(name);
2429
- else categories["Utilities"].push(name);
2430
- });
2431
- Object.keys(categories).forEach((key) => {
2432
- if (categories[key].length === 0) {
2433
- delete categories[key];
2434
- }
2435
- });
2436
- return categories;
2437
- }
2438
- function formatListOutput(functions) {
2439
- let output = "Available EventCatalog SDK Functions:\n\n";
2440
- Object.entries(functions).forEach(([category, names]) => {
2441
- output += `${category}:
2442
- `;
2443
- names.sort().forEach((name) => {
2444
- output += ` - ${name}
2445
- `;
2446
- });
2447
- output += "\n";
2448
- });
2449
- return output;
2450
- }
2451
-
2452
- // src/cli/index.ts
2453
- var version = "1.0.0";
2454
- try {
2455
- const packageJsonPath = (0, import_node_path20.resolve)(__dirname, "../../package.json");
2456
- const packageJson = JSON.parse((0, import_node_fs8.readFileSync)(packageJsonPath, "utf-8"));
2457
- version = packageJson.version;
2458
- } catch {
2459
- }
2460
- 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)", ".");
2461
- import_commander.program.command("list").description("List all available SDK functions").action(() => {
2462
- try {
2463
- const functions = listFunctions(".");
2464
- const output = formatListOutput(functions);
2465
- console.log(output);
2466
- } catch (error) {
2467
- console.error("Error listing functions:", error instanceof Error ? error.message : String(error));
2468
- process.exit(1);
2469
- }
2470
- });
2471
- import_commander.program.arguments("<function> [args...]").action(async (functionName, args) => {
2472
- try {
2473
- const options = import_commander.program.opts();
2474
- const dir = options.dir || ".";
2475
- const result = await executeFunction(dir, functionName, args);
2476
- console.log(JSON.stringify(result, null, 0));
2477
- } catch (error) {
2478
- console.error(error instanceof Error ? error.message : String(error));
2479
- process.exit(1);
2480
- }
2481
- });
2482
- import_commander.program.parse(process.argv);
2483
- if (process.argv.length < 3) {
2484
- import_commander.program.outputHelp();
2485
- }
2486
- //# sourceMappingURL=index.js.map