@eventcatalog/sdk 2.11.0 → 2.12.1

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.
Files changed (114) hide show
  1. package/README.md +86 -1
  2. package/dist/cli/index.d.mts +1 -0
  3. package/dist/cli/index.d.ts +1 -0
  4. package/dist/{eventcatalog.js → cli/index.js} +588 -378
  5. package/dist/cli/index.js.map +1 -0
  6. package/dist/{eventcatalog.mjs → cli/index.mjs} +666 -436
  7. package/dist/cli/index.mjs.map +1 -0
  8. package/dist/cli-docs.d.mts +43 -0
  9. package/dist/cli-docs.d.ts +43 -0
  10. package/dist/cli-docs.js +1614 -0
  11. package/dist/cli-docs.js.map +1 -0
  12. package/dist/cli-docs.mjs +1586 -0
  13. package/dist/cli-docs.mjs.map +1 -0
  14. package/dist/index.d.mts +443 -25
  15. package/dist/index.d.ts +443 -25
  16. package/dist/index.js +204 -121
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +204 -121
  19. package/dist/index.mjs.map +1 -1
  20. package/package.json +13 -4
  21. package/dist/channels.d.mts +0 -214
  22. package/dist/channels.d.ts +0 -214
  23. package/dist/channels.js +0 -432
  24. package/dist/channels.js.map +0 -1
  25. package/dist/channels.mjs +0 -384
  26. package/dist/channels.mjs.map +0 -1
  27. package/dist/commands.d.mts +0 -274
  28. package/dist/commands.d.ts +0 -274
  29. package/dist/commands.js +0 -394
  30. package/dist/commands.js.map +0 -1
  31. package/dist/commands.mjs +0 -350
  32. package/dist/commands.mjs.map +0 -1
  33. package/dist/containers.d.mts +0 -179
  34. package/dist/containers.d.ts +0 -179
  35. package/dist/containers.js +0 -388
  36. package/dist/containers.js.map +0 -1
  37. package/dist/containers.mjs +0 -345
  38. package/dist/containers.mjs.map +0 -1
  39. package/dist/custom-docs.d.mts +0 -89
  40. package/dist/custom-docs.d.ts +0 -89
  41. package/dist/custom-docs.js +0 -164
  42. package/dist/custom-docs.js.map +0 -1
  43. package/dist/custom-docs.mjs +0 -122
  44. package/dist/custom-docs.mjs.map +0 -1
  45. package/dist/data-products.d.mts +0 -225
  46. package/dist/data-products.d.ts +0 -225
  47. package/dist/data-products.js +0 -375
  48. package/dist/data-products.js.map +0 -1
  49. package/dist/data-products.mjs +0 -332
  50. package/dist/data-products.mjs.map +0 -1
  51. package/dist/data-stores.d.mts +0 -179
  52. package/dist/data-stores.d.ts +0 -179
  53. package/dist/data-stores.js +0 -401
  54. package/dist/data-stores.js.map +0 -1
  55. package/dist/data-stores.mjs +0 -356
  56. package/dist/data-stores.mjs.map +0 -1
  57. package/dist/domains.d.mts +0 -347
  58. package/dist/domains.d.ts +0 -347
  59. package/dist/domains.js +0 -547
  60. package/dist/domains.js.map +0 -1
  61. package/dist/domains.mjs +0 -498
  62. package/dist/domains.mjs.map +0 -1
  63. package/dist/entities.d.mts +0 -174
  64. package/dist/entities.d.ts +0 -174
  65. package/dist/entities.js +0 -348
  66. package/dist/entities.js.map +0 -1
  67. package/dist/entities.mjs +0 -307
  68. package/dist/entities.mjs.map +0 -1
  69. package/dist/eventcatalog.d.mts +0 -21
  70. package/dist/eventcatalog.d.ts +0 -21
  71. package/dist/eventcatalog.js.map +0 -1
  72. package/dist/eventcatalog.mjs.map +0 -1
  73. package/dist/events.d.mts +0 -276
  74. package/dist/events.d.ts +0 -276
  75. package/dist/events.js +0 -393
  76. package/dist/events.js.map +0 -1
  77. package/dist/events.mjs +0 -349
  78. package/dist/events.mjs.map +0 -1
  79. package/dist/messages.d.mts +0 -65
  80. package/dist/messages.d.ts +0 -65
  81. package/dist/messages.js +0 -312
  82. package/dist/messages.js.map +0 -1
  83. package/dist/messages.mjs +0 -269
  84. package/dist/messages.mjs.map +0 -1
  85. package/dist/queries.d.mts +0 -276
  86. package/dist/queries.d.ts +0 -276
  87. package/dist/queries.js +0 -394
  88. package/dist/queries.js.map +0 -1
  89. package/dist/queries.mjs +0 -350
  90. package/dist/queries.mjs.map +0 -1
  91. package/dist/services.d.mts +0 -384
  92. package/dist/services.d.ts +0 -384
  93. package/dist/services.js +0 -577
  94. package/dist/services.js.map +0 -1
  95. package/dist/services.mjs +0 -526
  96. package/dist/services.mjs.map +0 -1
  97. package/dist/teams.d.mts +0 -90
  98. package/dist/teams.d.ts +0 -90
  99. package/dist/teams.js +0 -246
  100. package/dist/teams.js.map +0 -1
  101. package/dist/teams.mjs +0 -202
  102. package/dist/teams.mjs.map +0 -1
  103. package/dist/types.d.d.mts +0 -331
  104. package/dist/types.d.d.ts +0 -331
  105. package/dist/types.d.js +0 -19
  106. package/dist/types.d.js.map +0 -1
  107. package/dist/types.d.mjs +0 -1
  108. package/dist/types.d.mjs.map +0 -1
  109. package/dist/users.d.mts +0 -83
  110. package/dist/users.d.ts +0 -83
  111. package/dist/users.js +0 -127
  112. package/dist/users.js.map +0 -1
  113. package/dist/users.mjs +0 -88
  114. package/dist/users.mjs.map +0 -1
package/dist/domains.js DELETED
@@ -1,547 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/domains.ts
31
- var domains_exports = {};
32
- __export(domains_exports, {
33
- addDataProductToDomain: () => addDataProductToDomain,
34
- addEntityToDomain: () => addEntityToDomain,
35
- addFileToDomain: () => addFileToDomain,
36
- addMessageToDomain: () => addMessageToDomain,
37
- addServiceToDomain: () => addServiceToDomain,
38
- addSubDomainToDomain: () => addSubDomainToDomain,
39
- addUbiquitousLanguageToDomain: () => addUbiquitousLanguageToDomain,
40
- domainHasVersion: () => domainHasVersion,
41
- getDomain: () => getDomain,
42
- getDomains: () => getDomains,
43
- getUbiquitousLanguageFromDomain: () => getUbiquitousLanguageFromDomain,
44
- rmDomain: () => rmDomain,
45
- rmDomainById: () => rmDomainById,
46
- versionDomain: () => versionDomain,
47
- writeDomain: () => writeDomain
48
- });
49
- module.exports = __toCommonJS(domains_exports);
50
- var import_promises2 = __toESM(require("fs/promises"));
51
- var import_node_path4 = __toESM(require("path"));
52
- var import_node_fs3 = __toESM(require("fs"));
53
-
54
- // src/internal/resources.ts
55
- var import_path = require("path");
56
-
57
- // src/internal/utils.ts
58
- var import_glob = require("glob");
59
- var import_node_fs = __toESM(require("fs"));
60
- var import_fs_extra = require("fs-extra");
61
- var import_node_path = require("path");
62
- var import_gray_matter = __toESM(require("gray-matter"));
63
- var import_semver = require("semver");
64
- var versionExists = async (catalogDir, id, version) => {
65
- const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
66
- const matchedFiles = await searchFilesForId(files, id, version) || [];
67
- return matchedFiles.length > 0;
68
- };
69
- var findFileById = async (catalogDir, id, version) => {
70
- const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
71
- const matchedFiles = await searchFilesForId(files, id) || [];
72
- const latestVersion = matchedFiles.find((path3) => !path3.includes("versioned"));
73
- if (!version) {
74
- return latestVersion;
75
- }
76
- const parsedFiles = matchedFiles.map((path3) => {
77
- const { data } = import_gray_matter.default.read(path3);
78
- return { ...data, path: path3 };
79
- });
80
- if (version === "latest") {
81
- return latestVersion;
82
- }
83
- const exactMatch = parsedFiles.find((c) => c.version === version);
84
- if (exactMatch) {
85
- return exactMatch.path;
86
- }
87
- const semverRange = (0, import_semver.validRange)(version);
88
- if (semverRange) {
89
- const match = parsedFiles.filter((c) => {
90
- try {
91
- return (0, import_semver.satisfies)(c.version, semverRange);
92
- } catch (error) {
93
- return false;
94
- }
95
- });
96
- return match.length > 0 ? match[0].path : void 0;
97
- }
98
- return void 0;
99
- };
100
- var getFiles = async (pattern, ignore = "") => {
101
- try {
102
- const normalizedInputPattern = (0, import_node_path.normalize)(pattern);
103
- const absoluteBaseDir = (0, import_node_path.resolve)(
104
- normalizedInputPattern.includes("**") ? normalizedInputPattern.split("**")[0] : (0, import_node_path.dirname)(normalizedInputPattern)
105
- );
106
- let relativePattern = (0, import_node_path.relative)(absoluteBaseDir, normalizedInputPattern);
107
- relativePattern = relativePattern.replace(/\\/g, "/");
108
- const ignoreList = Array.isArray(ignore) ? ignore : [ignore];
109
- const files = (0, import_glob.globSync)(relativePattern, {
110
- cwd: absoluteBaseDir,
111
- ignore: ["node_modules/**", ...ignoreList],
112
- absolute: true,
113
- nodir: true
114
- });
115
- return files.map(import_node_path.normalize);
116
- } catch (error) {
117
- const absoluteBaseDirForError = (0, import_node_path.resolve)(
118
- (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))
119
- );
120
- const relativePatternForError = (0, import_node_path.relative)(absoluteBaseDirForError, (0, import_node_path.normalize)(pattern)).replace(/\\/g, "/");
121
- throw new Error(
122
- `Error finding files for pattern "${pattern}" (using cwd: "${absoluteBaseDirForError}", globPattern: "${relativePatternForError}"): ${error.message}`
123
- );
124
- }
125
- };
126
- var readMdxFile = async (path3) => {
127
- const { data } = import_gray_matter.default.read(path3);
128
- const { markdown, ...frontmatter } = data;
129
- return { ...frontmatter, markdown };
130
- };
131
- var searchFilesForId = async (files, id, version) => {
132
- const escapedId = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
133
- const idRegex = new RegExp(`^id:\\s*(['"]|>-)?\\s*${escapedId}['"]?\\s*$`, "m");
134
- const versionRegex = new RegExp(`^version:\\s*['"]?${version}['"]?\\s*$`, "m");
135
- const matches = files.map((file) => {
136
- const content = import_node_fs.default.readFileSync(file, "utf-8");
137
- const hasIdMatch = content.match(idRegex);
138
- if (version && !content.match(versionRegex)) {
139
- return void 0;
140
- }
141
- if (hasIdMatch) {
142
- return file;
143
- }
144
- });
145
- return matches.filter(Boolean).filter((file) => file !== void 0);
146
- };
147
- var copyDir = async (catalogDir, source, target, filter) => {
148
- const tmpDirectory = (0, import_node_path.join)(catalogDir, "tmp");
149
- import_node_fs.default.mkdirSync(tmpDirectory, { recursive: true });
150
- await (0, import_fs_extra.copy)(source, tmpDirectory, {
151
- overwrite: true,
152
- filter
153
- });
154
- await (0, import_fs_extra.copy)(tmpDirectory, target, {
155
- overwrite: true,
156
- filter
157
- });
158
- import_node_fs.default.rmSync(tmpDirectory, { recursive: true });
159
- };
160
- var uniqueVersions = (messages) => {
161
- const uniqueSet = /* @__PURE__ */ new Set();
162
- return messages.filter((message) => {
163
- const key = `${message.id}-${message.version}`;
164
- if (!uniqueSet.has(key)) {
165
- uniqueSet.add(key);
166
- return true;
167
- }
168
- return false;
169
- });
170
- };
171
-
172
- // src/internal/resources.ts
173
- var import_gray_matter2 = __toESM(require("gray-matter"));
174
- var import_promises = __toESM(require("fs/promises"));
175
- var import_node_fs2 = __toESM(require("fs"));
176
- var import_semver2 = require("semver");
177
- var import_proper_lockfile = require("proper-lockfile");
178
- var import_node_path2 = require("path");
179
- var import_node_path3 = __toESM(require("path"));
180
- var versionResource = async (catalogDir, id) => {
181
- const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
182
- const matchedFiles = await searchFilesForId(files, id);
183
- if (matchedFiles.length === 0) {
184
- throw new Error(`No resource found with id: ${id}`);
185
- }
186
- const file = matchedFiles[0];
187
- const sourceDirectory = (0, import_path.dirname)(file).replace(/[/\\]versioned[/\\][^/\\]+[/\\]/, import_node_path3.default.sep);
188
- const { data: { version = "0.0.1" } = {} } = import_gray_matter2.default.read(file);
189
- const targetDirectory = getVersionedDirectory(sourceDirectory, version);
190
- import_node_fs2.default.mkdirSync(targetDirectory, { recursive: true });
191
- const ignoreListToCopy = ["events", "commands", "queries", "versioned"];
192
- await copyDir(catalogDir, sourceDirectory, targetDirectory, (src) => {
193
- const folderName = (0, import_node_path2.basename)(src);
194
- if (ignoreListToCopy.includes(folderName)) {
195
- return false;
196
- }
197
- return true;
198
- });
199
- await import_promises.default.readdir(sourceDirectory).then(async (resourceFiles) => {
200
- await Promise.all(
201
- resourceFiles.map(async (file2) => {
202
- if (ignoreListToCopy.includes(file2)) {
203
- return;
204
- }
205
- if (file2 !== "versioned") {
206
- import_node_fs2.default.rmSync((0, import_path.join)(sourceDirectory, file2), { recursive: true });
207
- }
208
- })
209
- );
210
- });
211
- };
212
- var writeResource = async (catalogDir, resource, options = {
213
- path: "",
214
- type: "",
215
- override: false,
216
- versionExistingContent: false,
217
- format: "mdx"
218
- }) => {
219
- const path3 = options.path || `/${resource.id}`;
220
- const fullPath = (0, import_path.join)(catalogDir, path3);
221
- const format = options.format || "mdx";
222
- import_node_fs2.default.mkdirSync(fullPath, { recursive: true });
223
- const lockPath = (0, import_path.join)(fullPath, `index.${format}`);
224
- if (!import_node_fs2.default.existsSync(lockPath)) {
225
- import_node_fs2.default.writeFileSync(lockPath, "");
226
- }
227
- try {
228
- await (0, import_proper_lockfile.lock)(lockPath, {
229
- retries: 5,
230
- stale: 1e4
231
- // 10 seconds
232
- });
233
- const exists = await versionExists(catalogDir, resource.id, resource.version);
234
- if (exists && !options.override) {
235
- throw new Error(`Failed to write ${resource.id} (${options.type}) as the version ${resource.version} already exists`);
236
- }
237
- const { markdown, ...frontmatter } = resource;
238
- if (options.versionExistingContent && !exists) {
239
- const currentResource = await getResource(catalogDir, resource.id);
240
- if (currentResource) {
241
- if ((0, import_semver2.satisfies)(resource.version, `>${currentResource.version}`)) {
242
- await versionResource(catalogDir, resource.id);
243
- } else {
244
- throw new Error(`New version ${resource.version} is not greater than current version ${currentResource.version}`);
245
- }
246
- }
247
- }
248
- const document = import_gray_matter2.default.stringify(markdown.trim(), frontmatter);
249
- import_node_fs2.default.writeFileSync(lockPath, document);
250
- } finally {
251
- await (0, import_proper_lockfile.unlock)(lockPath).catch(() => {
252
- });
253
- }
254
- };
255
- var getResource = async (catalogDir, id, version, options, filePath) => {
256
- const attachSchema = options?.attachSchema || false;
257
- const file = filePath || (id ? await findFileById(catalogDir, id, version) : void 0);
258
- if (!file || !import_node_fs2.default.existsSync(file)) return;
259
- const { data, content } = import_gray_matter2.default.read(file);
260
- if (attachSchema && data?.schemaPath) {
261
- const resourceDirectory = (0, import_path.dirname)(file);
262
- const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
263
- if (import_node_fs2.default.existsSync(pathToSchema)) {
264
- const schema = import_node_fs2.default.readFileSync(pathToSchema, "utf8");
265
- try {
266
- data.schema = JSON.parse(schema);
267
- } catch (error) {
268
- data.schema = schema;
269
- }
270
- }
271
- }
272
- return {
273
- ...data,
274
- markdown: content.trim()
275
- };
276
- };
277
- var getResourcePath = async (catalogDir, id, version) => {
278
- const file = await findFileById(catalogDir, id, version);
279
- if (!file) return;
280
- return {
281
- fullPath: file,
282
- relativePath: file.replace(catalogDir, ""),
283
- directory: (0, import_path.dirname)(file.replace(catalogDir, ""))
284
- };
285
- };
286
- var getResources = async (catalogDir, {
287
- type,
288
- latestOnly = false,
289
- ignore = [],
290
- pattern = "",
291
- attachSchema = false
292
- }) => {
293
- const ignoreList = latestOnly ? `**/versioned/**` : "";
294
- const filePattern = pattern || `${catalogDir}/**/${type}/**/index.{md,mdx}`;
295
- const files = await getFiles(filePattern, [ignoreList, ...ignore]);
296
- if (files.length === 0) return;
297
- return files.map((file) => {
298
- const { data, content } = import_gray_matter2.default.read(file);
299
- if (attachSchema && data?.schemaPath) {
300
- const resourceDirectory = (0, import_path.dirname)(file);
301
- const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
302
- if (import_node_fs2.default.existsSync(pathToSchema)) {
303
- const schema = import_node_fs2.default.readFileSync(pathToSchema, "utf8");
304
- try {
305
- data.schema = JSON.parse(schema);
306
- } catch (error) {
307
- data.schema = schema;
308
- }
309
- }
310
- }
311
- return {
312
- ...data,
313
- markdown: content.trim()
314
- };
315
- });
316
- };
317
- var rmResourceById = async (catalogDir, id, version, options) => {
318
- const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
319
- const matchedFiles = await searchFilesForId(files, id, version);
320
- if (matchedFiles.length === 0) {
321
- throw new Error(`No ${options?.type || "resource"} found with id: ${id}`);
322
- }
323
- if (options?.persistFiles) {
324
- await Promise.all(
325
- matchedFiles.map(async (file) => {
326
- await import_promises.default.rm(file, { recursive: true });
327
- await waitForFileRemoval(file);
328
- })
329
- );
330
- } else {
331
- await Promise.all(
332
- matchedFiles.map(async (file) => {
333
- const directory = (0, import_path.dirname)(file);
334
- await import_promises.default.rm(directory, { recursive: true, force: true });
335
- await waitForFileRemoval(directory);
336
- })
337
- );
338
- }
339
- };
340
- var waitForFileRemoval = async (path3, maxRetries = 50, delay = 10) => {
341
- for (let i = 0; i < maxRetries; i++) {
342
- try {
343
- await import_promises.default.access(path3);
344
- await new Promise((resolve2) => setTimeout(resolve2, delay));
345
- } catch (error) {
346
- return;
347
- }
348
- }
349
- throw new Error(`File/directory ${path3} was not removed after ${maxRetries} attempts`);
350
- };
351
- var addFileToResource = async (catalogDir, id, file, version, options) => {
352
- let pathToResource;
353
- if (options?.path) {
354
- pathToResource = (0, import_path.join)(catalogDir, options.path, "index.mdx");
355
- } else {
356
- pathToResource = await findFileById(catalogDir, id, version);
357
- }
358
- if (!pathToResource) throw new Error("Cannot find directory to write file to");
359
- import_node_fs2.default.mkdirSync(import_node_path3.default.dirname(pathToResource), { recursive: true });
360
- let fileContent = file.content.trim();
361
- try {
362
- const json = JSON.parse(fileContent);
363
- fileContent = JSON.stringify(json, null, 2);
364
- } catch (error) {
365
- }
366
- import_node_fs2.default.writeFileSync((0, import_path.join)((0, import_path.dirname)(pathToResource), file.fileName), fileContent);
367
- };
368
- var getVersionedDirectory = (sourceDirectory, version) => {
369
- return (0, import_path.join)(sourceDirectory, "versioned", version);
370
- };
371
-
372
- // src/domains.ts
373
- var import_gray_matter3 = __toESM(require("gray-matter"));
374
- var getDomain = (directory) => async (id, version) => getResource(directory, id, version, { type: "domain" });
375
- var getDomains = (directory) => async (options) => getResources(directory, {
376
- type: "domains",
377
- ignore: ["**/services/**", "**/events/**", "**/commands/**", "**/queries/**", "**/flows/**", "**/entities/**"],
378
- ...options
379
- });
380
- var writeDomain = (directory) => async (domain, options = {
381
- path: "",
382
- override: false,
383
- versionExistingContent: false,
384
- format: "mdx"
385
- }) => {
386
- const resource = { ...domain };
387
- if (Array.isArray(domain.services)) {
388
- resource.services = uniqueVersions(domain.services);
389
- }
390
- if (Array.isArray(domain.domains)) {
391
- resource.domains = uniqueVersions(domain.domains);
392
- }
393
- if (Array.isArray(domain.sends)) {
394
- resource.sends = uniqueVersions(domain.sends);
395
- }
396
- if (Array.isArray(domain.receives)) {
397
- resource.receives = uniqueVersions(domain.receives);
398
- }
399
- if (Array.isArray(domain.dataProducts)) {
400
- resource.dataProducts = uniqueVersions(domain.dataProducts);
401
- }
402
- return await writeResource(directory, resource, { ...options, type: "domain" });
403
- };
404
- var versionDomain = (directory) => async (id) => versionResource(directory, id);
405
- var rmDomain = (directory) => async (path3) => {
406
- await import_promises2.default.rm((0, import_node_path4.join)(directory, path3), { recursive: true });
407
- };
408
- var rmDomainById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "domain", persistFiles });
409
- var addFileToDomain = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
410
- var addUbiquitousLanguageToDomain = (directory) => async (id, ubiquitousLanguageDictionary, version) => {
411
- const content = import_gray_matter3.default.stringify("", {
412
- ...ubiquitousLanguageDictionary
413
- });
414
- await addFileToResource(directory, id, { content, fileName: "ubiquitous-language.mdx" }, version);
415
- };
416
- var getUbiquitousLanguageFromDomain = (directory) => async (id, version) => {
417
- const pathToDomain = await findFileById(directory, id, version) || "";
418
- const pathToUbiquitousLanguage = import_node_path4.default.join(import_node_path4.default.dirname(pathToDomain), "ubiquitous-language.mdx");
419
- const fileExists = import_node_fs3.default.existsSync(pathToUbiquitousLanguage);
420
- if (!fileExists) {
421
- return void 0;
422
- }
423
- const content = await readMdxFile(pathToUbiquitousLanguage);
424
- return content;
425
- };
426
- var domainHasVersion = (directory) => async (id, version) => {
427
- const file = await findFileById(directory, id, version);
428
- return !!file;
429
- };
430
- var addServiceToDomain = (directory) => async (id, service, version) => {
431
- let domain = await getDomain(directory)(id, version);
432
- const domainPath = await getResourcePath(directory, id, version);
433
- const extension = import_node_path4.default.extname(domainPath?.fullPath || "");
434
- if (domain.services === void 0) {
435
- domain.services = [];
436
- }
437
- const serviceExistsInList = domain.services.some((s) => s.id === service.id && s.version === service.version);
438
- if (serviceExistsInList) {
439
- return;
440
- }
441
- domain.services.push(service);
442
- await rmDomainById(directory)(id, version, true);
443
- await writeDomain(directory)(domain, { format: extension === ".md" ? "md" : "mdx" });
444
- };
445
- var addSubDomainToDomain = (directory) => async (id, subDomain, version) => {
446
- let domain = await getDomain(directory)(id, version);
447
- const domainPath = await getResourcePath(directory, id, version);
448
- const extension = import_node_path4.default.extname(domainPath?.fullPath || "");
449
- if (domain.domains === void 0) {
450
- domain.domains = [];
451
- }
452
- const subDomainExistsInList = domain.domains.some((s) => s.id === subDomain.id && s.version === subDomain.version);
453
- if (subDomainExistsInList) {
454
- return;
455
- }
456
- domain.domains.push(subDomain);
457
- await rmDomainById(directory)(id, version, true);
458
- await writeDomain(directory)(domain, { format: extension === ".md" ? "md" : "mdx" });
459
- };
460
- var addEntityToDomain = (directory) => async (id, entity, version) => {
461
- let domain = await getDomain(directory)(id, version);
462
- const domainPath = await getResourcePath(directory, id, version);
463
- const extension = import_node_path4.default.extname(domainPath?.fullPath || "");
464
- if (domain.entities === void 0) {
465
- domain.entities = [];
466
- }
467
- const entityExistsInList = domain.entities.some((e) => e.id === entity.id && e.version === entity.version);
468
- if (entityExistsInList) {
469
- return;
470
- }
471
- domain.entities.push(entity);
472
- await rmDomainById(directory)(id, version, true);
473
- await writeDomain(directory)(domain, { format: extension === ".md" ? "md" : "mdx" });
474
- };
475
- var addDataProductToDomain = (directory) => async (id, dataProduct, version) => {
476
- let domain = await getDomain(directory)(id, version);
477
- const domainPath = await getResourcePath(directory, id, version);
478
- const extension = import_node_path4.default.extname(domainPath?.fullPath || "");
479
- if (domain.dataProducts === void 0) {
480
- domain.dataProducts = [];
481
- }
482
- const dataProductExistsInList = domain.dataProducts.some(
483
- (dp) => dp.id === dataProduct.id && dp.version === dataProduct.version
484
- );
485
- if (dataProductExistsInList) {
486
- return;
487
- }
488
- domain.dataProducts.push(dataProduct);
489
- await rmDomainById(directory)(id, version, true);
490
- await writeDomain(directory)(domain, { format: extension === ".md" ? "md" : "mdx" });
491
- };
492
- var addMessageToDomain = (directory) => async (id, direction, message, version) => {
493
- let domain = await getDomain(directory)(id, version);
494
- const domainPath = await getResourcePath(directory, id, version);
495
- const extension = import_node_path4.default.extname(domainPath?.fullPath || "");
496
- if (direction === "sends") {
497
- if (domain.sends === void 0) {
498
- domain.sends = [];
499
- }
500
- for (let i = 0; i < domain.sends.length; i++) {
501
- if (domain.sends[i].id === message.id && domain.sends[i].version === message.version) {
502
- return;
503
- }
504
- }
505
- domain.sends.push({ id: message.id, version: message.version });
506
- } else if (direction === "receives") {
507
- if (domain.receives === void 0) {
508
- domain.receives = [];
509
- }
510
- for (let i = 0; i < domain.receives.length; i++) {
511
- if (domain.receives[i].id === message.id && domain.receives[i].version === message.version) {
512
- return;
513
- }
514
- }
515
- domain.receives.push({ id: message.id, version: message.version });
516
- } else {
517
- throw new Error(`Direction ${direction} is invalid, only 'receives' and 'sends' are supported`);
518
- }
519
- const existingResource = await findFileById(directory, id, version);
520
- if (!existingResource) {
521
- throw new Error(`Cannot find domain ${id} in the catalog`);
522
- }
523
- const normalizedPath = existingResource.replace(/\\/g, "/");
524
- const lastDomainsIndex = normalizedPath.lastIndexOf("/domains/");
525
- const pathToResource = existingResource.substring(0, lastDomainsIndex + "/domains".length);
526
- await rmDomainById(directory)(id, version, true);
527
- await writeDomain(pathToResource)(domain, { format: extension === ".md" ? "md" : "mdx" });
528
- };
529
- // Annotate the CommonJS export names for ESM import in node:
530
- 0 && (module.exports = {
531
- addDataProductToDomain,
532
- addEntityToDomain,
533
- addFileToDomain,
534
- addMessageToDomain,
535
- addServiceToDomain,
536
- addSubDomainToDomain,
537
- addUbiquitousLanguageToDomain,
538
- domainHasVersion,
539
- getDomain,
540
- getDomains,
541
- getUbiquitousLanguageFromDomain,
542
- rmDomain,
543
- rmDomainById,
544
- versionDomain,
545
- writeDomain
546
- });
547
- //# sourceMappingURL=domains.js.map