@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/messages.js DELETED
@@ -1,312 +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/messages.ts
31
- var messages_exports = {};
32
- __export(messages_exports, {
33
- getConsumersOfSchema: () => getConsumersOfSchema,
34
- getMessageBySchemaPath: () => getMessageBySchemaPath,
35
- getProducersAndConsumersForMessage: () => getProducersAndConsumersForMessage,
36
- getProducersOfSchema: () => getProducersOfSchema
37
- });
38
- module.exports = __toCommonJS(messages_exports);
39
- var import_node_path5 = require("path");
40
- var import_gray_matter3 = __toESM(require("gray-matter"));
41
-
42
- // src/internal/resources.ts
43
- var import_path = require("path");
44
-
45
- // src/internal/utils.ts
46
- var import_glob = require("glob");
47
- var import_node_fs = __toESM(require("fs"));
48
- var import_fs_extra = require("fs-extra");
49
- var import_node_path = require("path");
50
- var import_gray_matter = __toESM(require("gray-matter"));
51
- var import_semver = require("semver");
52
- var findFileById = async (catalogDir, id, version) => {
53
- const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
54
- const matchedFiles = await searchFilesForId(files, id) || [];
55
- const latestVersion = matchedFiles.find((path2) => !path2.includes("versioned"));
56
- if (!version) {
57
- return latestVersion;
58
- }
59
- const parsedFiles = matchedFiles.map((path2) => {
60
- const { data } = import_gray_matter.default.read(path2);
61
- return { ...data, path: path2 };
62
- });
63
- if (version === "latest") {
64
- return latestVersion;
65
- }
66
- const exactMatch = parsedFiles.find((c) => c.version === version);
67
- if (exactMatch) {
68
- return exactMatch.path;
69
- }
70
- const semverRange = (0, import_semver.validRange)(version);
71
- if (semverRange) {
72
- const match = parsedFiles.filter((c) => {
73
- try {
74
- return (0, import_semver.satisfies)(c.version, semverRange);
75
- } catch (error) {
76
- return false;
77
- }
78
- });
79
- return match.length > 0 ? match[0].path : void 0;
80
- }
81
- return void 0;
82
- };
83
- var getFiles = async (pattern, ignore = "") => {
84
- try {
85
- const normalizedInputPattern = (0, import_node_path.normalize)(pattern);
86
- const absoluteBaseDir = (0, import_node_path.resolve)(
87
- normalizedInputPattern.includes("**") ? normalizedInputPattern.split("**")[0] : (0, import_node_path.dirname)(normalizedInputPattern)
88
- );
89
- let relativePattern = (0, import_node_path.relative)(absoluteBaseDir, normalizedInputPattern);
90
- relativePattern = relativePattern.replace(/\\/g, "/");
91
- const ignoreList = Array.isArray(ignore) ? ignore : [ignore];
92
- const files = (0, import_glob.globSync)(relativePattern, {
93
- cwd: absoluteBaseDir,
94
- ignore: ["node_modules/**", ...ignoreList],
95
- absolute: true,
96
- nodir: true
97
- });
98
- return files.map(import_node_path.normalize);
99
- } catch (error) {
100
- const absoluteBaseDirForError = (0, import_node_path.resolve)(
101
- (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))
102
- );
103
- const relativePatternForError = (0, import_node_path.relative)(absoluteBaseDirForError, (0, import_node_path.normalize)(pattern)).replace(/\\/g, "/");
104
- throw new Error(
105
- `Error finding files for pattern "${pattern}" (using cwd: "${absoluteBaseDirForError}", globPattern: "${relativePatternForError}"): ${error.message}`
106
- );
107
- }
108
- };
109
- var searchFilesForId = async (files, id, version) => {
110
- const escapedId = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
111
- const idRegex = new RegExp(`^id:\\s*(['"]|>-)?\\s*${escapedId}['"]?\\s*$`, "m");
112
- const versionRegex = new RegExp(`^version:\\s*['"]?${version}['"]?\\s*$`, "m");
113
- const matches = files.map((file) => {
114
- const content = import_node_fs.default.readFileSync(file, "utf-8");
115
- const hasIdMatch = content.match(idRegex);
116
- if (version && !content.match(versionRegex)) {
117
- return void 0;
118
- }
119
- if (hasIdMatch) {
120
- return file;
121
- }
122
- });
123
- return matches.filter(Boolean).filter((file) => file !== void 0);
124
- };
125
-
126
- // src/internal/resources.ts
127
- var import_gray_matter2 = __toESM(require("gray-matter"));
128
- var import_promises = __toESM(require("fs/promises"));
129
- var import_node_fs2 = __toESM(require("fs"));
130
- var import_semver2 = require("semver");
131
- var import_proper_lockfile = require("proper-lockfile");
132
- var import_node_path2 = require("path");
133
- var import_node_path3 = __toESM(require("path"));
134
- var getResource = async (catalogDir, id, version, options, filePath) => {
135
- const attachSchema = options?.attachSchema || false;
136
- const file = filePath || (id ? await findFileById(catalogDir, id, version) : void 0);
137
- if (!file || !import_node_fs2.default.existsSync(file)) return;
138
- const { data, content } = import_gray_matter2.default.read(file);
139
- if (attachSchema && data?.schemaPath) {
140
- const resourceDirectory = (0, import_path.dirname)(file);
141
- const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
142
- if (import_node_fs2.default.existsSync(pathToSchema)) {
143
- const schema = import_node_fs2.default.readFileSync(pathToSchema, "utf8");
144
- try {
145
- data.schema = JSON.parse(schema);
146
- } catch (error) {
147
- data.schema = schema;
148
- }
149
- }
150
- }
151
- return {
152
- ...data,
153
- markdown: content.trim()
154
- };
155
- };
156
- var getResourcePath = async (catalogDir, id, version) => {
157
- const file = await findFileById(catalogDir, id, version);
158
- if (!file) return;
159
- return {
160
- fullPath: file,
161
- relativePath: file.replace(catalogDir, ""),
162
- directory: (0, import_path.dirname)(file.replace(catalogDir, ""))
163
- };
164
- };
165
- var getResources = async (catalogDir, {
166
- type,
167
- latestOnly = false,
168
- ignore = [],
169
- pattern = "",
170
- attachSchema = false
171
- }) => {
172
- const ignoreList = latestOnly ? `**/versioned/**` : "";
173
- const filePattern = pattern || `${catalogDir}/**/${type}/**/index.{md,mdx}`;
174
- const files = await getFiles(filePattern, [ignoreList, ...ignore]);
175
- if (files.length === 0) return;
176
- return files.map((file) => {
177
- const { data, content } = import_gray_matter2.default.read(file);
178
- if (attachSchema && data?.schemaPath) {
179
- const resourceDirectory = (0, import_path.dirname)(file);
180
- const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
181
- if (import_node_fs2.default.existsSync(pathToSchema)) {
182
- const schema = import_node_fs2.default.readFileSync(pathToSchema, "utf8");
183
- try {
184
- data.schema = JSON.parse(schema);
185
- } catch (error) {
186
- data.schema = schema;
187
- }
188
- }
189
- }
190
- return {
191
- ...data,
192
- markdown: content.trim()
193
- };
194
- });
195
- };
196
- var isLatestVersion = async (catalogDir, id, version) => {
197
- const resource = await getResource(catalogDir, id, version);
198
- if (!resource) return false;
199
- const pathToResource = await getResourcePath(catalogDir, id, version);
200
- return !pathToResource?.relativePath.replace(/\\/g, "/").includes("/versioned/");
201
- };
202
-
203
- // src/services.ts
204
- var import_promises2 = __toESM(require("fs/promises"));
205
- var import_node_path4 = require("path");
206
- var getServices = (directory) => async (options) => getResources(directory, {
207
- type: "services",
208
- ignore: ["**/events/**", "**/commands/**", "**/queries/**", "**/entities/**", "**/subdomains/**/entities/**"],
209
- ...options
210
- });
211
-
212
- // src/messages.ts
213
- var import_semver3 = require("semver");
214
- var getMessageBySchemaPath = (directory) => async (path2, options) => {
215
- const pathToMessage = (0, import_node_path5.dirname)(path2);
216
- try {
217
- const files = await getFiles(`${directory}/${pathToMessage}/index.{md,mdx}`);
218
- if (!files || files.length === 0) {
219
- throw new Error(`No message definition file (index.md or index.mdx) found in directory: ${pathToMessage}`);
220
- }
221
- const messageFile = files[0];
222
- const { data } = import_gray_matter3.default.read(messageFile);
223
- const { id, version } = data;
224
- if (!id || !version) {
225
- throw new Error(`Message definition file at ${messageFile} is missing 'id' or 'version' in its frontmatter.`);
226
- }
227
- const message = await getResource(directory, id, version, { type: "message", ...options });
228
- if (!message) {
229
- throw new Error(`Message resource with id '${id}' and version '${version}' not found, as referenced in ${messageFile}.`);
230
- }
231
- return message;
232
- } catch (error) {
233
- if (error instanceof Error) {
234
- error.message = `Failed to retrieve message from ${pathToMessage}: ${error.message}`;
235
- throw error;
236
- }
237
- throw new Error(`Failed to retrieve message from ${pathToMessage} due to an unknown error.`);
238
- }
239
- };
240
- var getProducersAndConsumersForMessage = (directory) => async (id, version, options) => {
241
- const services = await getServices(directory)({ latestOnly: options?.latestOnly ?? true });
242
- const message = await getResource(directory, id, version, { type: "message" });
243
- const isMessageLatestVersion = await isLatestVersion(directory, id, version);
244
- if (!message) {
245
- throw new Error(`Message resource with id '${id}' and version '${version}' not found.`);
246
- }
247
- const producers = [];
248
- const consumers = [];
249
- for (const service of services) {
250
- const servicePublishesMessage = service.sends?.some((_message) => {
251
- if (_message.version) {
252
- const isServiceUsingSemverRange = (0, import_semver3.validRange)(_message.version);
253
- if (isServiceUsingSemverRange) {
254
- return _message.id === message.id && (0, import_semver3.satisfies)(message.version, _message.version);
255
- } else {
256
- return _message.id === message.id && message.version === _message.version;
257
- }
258
- }
259
- if (isMessageLatestVersion && _message.id === message.id) {
260
- return true;
261
- }
262
- return false;
263
- });
264
- const serviceSubscribesToMessage = service.receives?.some((_message) => {
265
- if (_message.version) {
266
- const isServiceUsingSemverRange = (0, import_semver3.validRange)(_message.version);
267
- if (isServiceUsingSemverRange) {
268
- return _message.id === message.id && (0, import_semver3.satisfies)(message.version, _message.version);
269
- } else {
270
- return _message.id === message.id && message.version === _message.version;
271
- }
272
- }
273
- if (isMessageLatestVersion && _message.id === message.id) {
274
- return true;
275
- }
276
- return false;
277
- });
278
- if (servicePublishesMessage) {
279
- producers.push(service);
280
- }
281
- if (serviceSubscribesToMessage) {
282
- consumers.push(service);
283
- }
284
- }
285
- return { producers, consumers };
286
- };
287
- var getConsumersOfSchema = (directory) => async (path2) => {
288
- try {
289
- const message = await getMessageBySchemaPath(directory)(path2);
290
- const { consumers } = await getProducersAndConsumersForMessage(directory)(message.id, message.version);
291
- return consumers;
292
- } catch (error) {
293
- return [];
294
- }
295
- };
296
- var getProducersOfSchema = (directory) => async (path2) => {
297
- try {
298
- const message = await getMessageBySchemaPath(directory)(path2);
299
- const { producers } = await getProducersAndConsumersForMessage(directory)(message.id, message.version);
300
- return producers;
301
- } catch (error) {
302
- return [];
303
- }
304
- };
305
- // Annotate the CommonJS export names for ESM import in node:
306
- 0 && (module.exports = {
307
- getConsumersOfSchema,
308
- getMessageBySchemaPath,
309
- getProducersAndConsumersForMessage,
310
- getProducersOfSchema
311
- });
312
- //# sourceMappingURL=messages.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/messages.ts","../src/internal/resources.ts","../src/internal/utils.ts","../src/services.ts"],"sourcesContent":["import { dirname, join } from 'node:path';\nimport type { Message, Service } from './types';\nimport matter from 'gray-matter';\nimport { getResource, getResourcePath, isLatestVersion } from './internal/resources';\nimport { getFiles } from './internal/utils';\nimport { getServices } from './services';\nimport { satisfies, validRange } from 'semver';\n\n/**\n * Returns a message from EventCatalog by a given schema path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getMessageBySchemaPath } = utils('/path/to/eventcatalog');\n *\n * // Get the message by the schema path\n * const message = await getMessageBySchemaPath('/path/to/eventcatalog/messages/InventoryAdjusted/schema.json');\n * const message = await getMessageBySchemaPath('/path/to/eventcatalog/messages/InventoryAdjusted/schema.avro');\n * ```\n */\nexport const getMessageBySchemaPath =\n (directory: string) =>\n async (path: string, options?: { attachSchema?: boolean }): Promise<Message> => {\n const pathToMessage = dirname(path);\n try {\n const files = await getFiles(`${directory}/${pathToMessage}/index.{md,mdx}`);\n\n if (!files || files.length === 0) {\n throw new Error(`No message definition file (index.md or index.mdx) found in directory: ${pathToMessage}`);\n }\n const messageFile = files[0];\n\n const { data } = matter.read(messageFile);\n const { id, version } = data;\n\n if (!id || !version) {\n throw new Error(`Message definition file at ${messageFile} is missing 'id' or 'version' in its frontmatter.`);\n }\n\n const message = await getResource(directory, id, version, { type: 'message', ...options });\n\n if (!message) {\n throw new Error(`Message resource with id '${id}' and version '${version}' not found, as referenced in ${messageFile}.`);\n }\n return message as Message;\n } catch (error) {\n // console.error(`Failed to get message for schema path ${path}. Error processing directory ${pathToMessage}:`, error);\n if (error instanceof Error) {\n // Prepend more context to the existing error message\n error.message = `Failed to retrieve message from ${pathToMessage}: ${error.message}`;\n throw error;\n }\n throw new Error(`Failed to retrieve message from ${pathToMessage} due to an unknown error.`);\n }\n };\n\n/**\n * Returns the producers and consumers (services) for a given message.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getProducersAndConsumersForMessage } = utils('/path/to/eventcatalog');\n *\n * // Returns the producers and consumers (services) for a given message\n * const { producers, consumers } = await getProducersAndConsumersForMessage('InventoryAdjusted', '0.0.1');\n */\nexport const getProducersAndConsumersForMessage =\n (directory: string) =>\n async (\n id: string,\n version?: string,\n options?: { latestOnly?: boolean }\n ): Promise<{ producers: Service[]; consumers: Service[] }> => {\n const services = await getServices(directory)({ latestOnly: options?.latestOnly ?? true });\n const message = (await getResource(directory, id, version, { type: 'message' })) as Message;\n const isMessageLatestVersion = await isLatestVersion(directory, id, version);\n\n if (!message) {\n throw new Error(`Message resource with id '${id}' and version '${version}' not found.`);\n }\n\n const producers: Service[] = [];\n const consumers: Service[] = [];\n\n for (const service of services) {\n const servicePublishesMessage = service.sends?.some((_message) => {\n if (_message.version) {\n const isServiceUsingSemverRange = validRange(_message.version);\n if (isServiceUsingSemverRange) {\n return _message.id === message.id && satisfies(message.version, _message.version);\n } else {\n return _message.id === message.id && message.version === _message.version;\n }\n }\n if (isMessageLatestVersion && _message.id === message.id) {\n return true;\n }\n return false;\n });\n const serviceSubscribesToMessage = service.receives?.some((_message) => {\n if (_message.version) {\n const isServiceUsingSemverRange = validRange(_message.version);\n if (isServiceUsingSemverRange) {\n return _message.id === message.id && satisfies(message.version, _message.version);\n } else {\n return _message.id === message.id && message.version === _message.version;\n }\n }\n if (isMessageLatestVersion && _message.id === message.id) {\n return true;\n }\n return false;\n });\n\n if (servicePublishesMessage) {\n producers.push(service);\n }\n if (serviceSubscribesToMessage) {\n consumers.push(service);\n }\n }\n\n return { producers, consumers };\n };\n\n/**\n * Returns the consumers of a given schema path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getConsumersOfSchema } = utils('/path/to/eventcatalog');\n *\n * // Returns the consumers of a given schema path\n * const consumers = await getConsumersOfSchema('events/InventoryAdjusted/schema.json');\n */\nexport const getConsumersOfSchema = (directory: string) => async (path: string) => {\n try {\n const message = await getMessageBySchemaPath(directory)(path);\n const { consumers } = await getProducersAndConsumersForMessage(directory)(message.id, message.version);\n return consumers;\n } catch (error) {\n return [];\n }\n};\n\n/**\n * Returns the producers of a given schema path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getProducersOfSchema } = utils('/path/to/eventcatalog');\n *\n * // Returns the producers of a given schema path\n * const producers = await getProducersOfSchema('events/InventoryAdjusted/schema.json');\n */\nexport const getProducersOfSchema = (directory: string) => async (path: string) => {\n try {\n const message = await getMessageBySchemaPath(directory)(path);\n const { producers } = await getProducersAndConsumersForMessage(directory)(message.id, message.version);\n return producers;\n } catch (error) {\n return [];\n }\n};\n","import { dirname, join } from 'path';\nimport { copyDir, findFileById, getFiles, searchFilesForId, versionExists } from './utils';\nimport matter from 'gray-matter';\nimport fs from 'node:fs/promises';\nimport fsSync from 'node:fs';\nimport { Message, Service, CustomDoc } from '../types';\nimport { satisfies } from 'semver';\nimport { lock, unlock } from 'proper-lockfile';\nimport { basename } from 'node:path';\nimport path from 'node:path';\n\ntype Resource = Service | Message | CustomDoc;\n\nexport const versionResource = async (catalogDir: string, id: string) => {\n // Find all the events in the directory\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n const matchedFiles = await searchFilesForId(files, id);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No resource found with id: ${id}`);\n }\n\n // Event that is in the route of the project\n const file = matchedFiles[0];\n // Handle both forward and back slashes for cross-platform compatibility (Windows uses \\, Unix uses /)\n const sourceDirectory = dirname(file).replace(/[/\\\\]versioned[/\\\\][^/\\\\]+[/\\\\]/, path.sep);\n const { data: { version = '0.0.1' } = {} } = matter.read(file);\n const targetDirectory = getVersionedDirectory(sourceDirectory, version);\n\n fsSync.mkdirSync(targetDirectory, { recursive: true });\n\n const ignoreListToCopy = ['events', 'commands', 'queries', 'versioned'];\n\n // Copy the event to the versioned directory\n await copyDir(catalogDir, sourceDirectory, targetDirectory, (src) => {\n // get the folder name\n const folderName = basename(src);\n\n if (ignoreListToCopy.includes(folderName)) {\n return false;\n }\n return true;\n });\n\n // Remove all the files in the root of the resource as they have now been versioned\n await fs.readdir(sourceDirectory).then(async (resourceFiles) => {\n await Promise.all(\n resourceFiles.map(async (file) => {\n // Dont remove anything in the ignore list\n if (ignoreListToCopy.includes(file)) {\n return;\n }\n if (file !== 'versioned') {\n fsSync.rmSync(join(sourceDirectory, file), { recursive: true });\n }\n })\n );\n });\n};\n\nexport const writeResource = async (\n catalogDir: string,\n resource: Resource,\n options: { path?: string; type: string; override?: boolean; versionExistingContent?: boolean; format?: 'md' | 'mdx' } = {\n path: '',\n type: '',\n override: false,\n versionExistingContent: false,\n format: 'mdx',\n }\n) => {\n const path = options.path || `/${resource.id}`;\n const fullPath = join(catalogDir, path);\n const format = options.format || 'mdx';\n\n // Create directory if it doesn't exist\n fsSync.mkdirSync(fullPath, { recursive: true });\n\n // Create or get lock file path\n const lockPath = join(fullPath, `index.${format}`);\n\n // Ensure the file exists before attempting to lock it\n if (!fsSync.existsSync(lockPath)) {\n fsSync.writeFileSync(lockPath, '');\n }\n\n try {\n // Acquire lock with retry\n await lock(lockPath, {\n retries: 5,\n stale: 10000, // 10 seconds\n });\n\n const exists = await versionExists(catalogDir, resource.id, resource.version);\n\n if (exists && !options.override) {\n throw new Error(`Failed to write ${resource.id} (${options.type}) as the version ${resource.version} already exists`);\n }\n\n const { markdown, ...frontmatter } = resource;\n\n if (options.versionExistingContent && !exists) {\n const currentResource = await getResource(catalogDir, resource.id);\n\n if (currentResource) {\n if (satisfies(resource.version, `>${currentResource.version}`)) {\n await versionResource(catalogDir, resource.id);\n } else {\n throw new Error(`New version ${resource.version} is not greater than current version ${currentResource.version}`);\n }\n }\n }\n\n const document = matter.stringify(markdown.trim(), frontmatter);\n fsSync.writeFileSync(lockPath, document);\n } finally {\n // Always release the lock\n await unlock(lockPath).catch(() => {});\n }\n};\n\nexport const getResource = async (\n catalogDir: string,\n id?: string,\n version?: string,\n options?: { type: string; attachSchema?: boolean },\n filePath?: string\n): Promise<Resource | undefined> => {\n const attachSchema = options?.attachSchema || false;\n const file = filePath || (id ? await findFileById(catalogDir, id, version) : undefined);\n if (!file || !fsSync.existsSync(file)) return;\n\n const { data, content } = matter.read(file);\n\n if (attachSchema && data?.schemaPath) {\n const resourceDirectory = dirname(file);\n const pathToSchema = join(resourceDirectory, data.schemaPath);\n if (fsSync.existsSync(pathToSchema)) {\n const schema = fsSync.readFileSync(pathToSchema, 'utf8');\n // Try to parse the schema\n try {\n data.schema = JSON.parse(schema);\n } catch (error) {\n data.schema = schema;\n }\n }\n }\n\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n};\n\nexport const getResourcePath = async (catalogDir: string, id: string, version?: string) => {\n const file = await findFileById(catalogDir, id, version);\n if (!file) return;\n\n return {\n fullPath: file,\n relativePath: file.replace(catalogDir, ''),\n directory: dirname(file.replace(catalogDir, '')),\n };\n};\n\nexport const getResourceFolderName = async (catalogDir: string, id: string, version?: string) => {\n const paths = await getResourcePath(catalogDir, id, version);\n if (!paths) return;\n return paths?.directory.split(path.sep).filter(Boolean).pop();\n};\n\nexport const toResource = async (catalogDir: string, rawContents: string) => {\n const { data, content } = matter(rawContents);\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n};\n\nexport const getResources = async (\n catalogDir: string,\n {\n type,\n latestOnly = false,\n ignore = [],\n pattern = '',\n attachSchema = false,\n }: { type: string; pattern?: string; latestOnly?: boolean; ignore?: string[]; attachSchema?: boolean }\n): Promise<Resource[] | undefined> => {\n const ignoreList = latestOnly ? `**/versioned/**` : '';\n const filePattern = pattern || `${catalogDir}/**/${type}/**/index.{md,mdx}`;\n const files = await getFiles(filePattern, [ignoreList, ...ignore]);\n\n if (files.length === 0) return;\n\n return files.map((file) => {\n const { data, content } = matter.read(file);\n\n // Attach the schema if the attachSchema option is set to true\n if (attachSchema && data?.schemaPath) {\n const resourceDirectory = dirname(file);\n const pathToSchema = join(resourceDirectory, data.schemaPath);\n if (fsSync.existsSync(pathToSchema)) {\n const schema = fsSync.readFileSync(pathToSchema, 'utf8');\n // Try to parse the schema\n try {\n data.schema = JSON.parse(schema);\n } catch (error) {\n data.schema = schema;\n }\n }\n }\n return {\n ...data,\n markdown: content.trim(),\n } as Resource;\n });\n};\n\nexport const rmResourceById = async (\n catalogDir: string,\n id: string,\n version?: string,\n options?: { type: string; persistFiles?: boolean }\n) => {\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n\n const matchedFiles = await searchFilesForId(files, id, version);\n\n if (matchedFiles.length === 0) {\n throw new Error(`No ${options?.type || 'resource'} found with id: ${id}`);\n }\n\n if (options?.persistFiles) {\n await Promise.all(\n matchedFiles.map(async (file) => {\n await fs.rm(file, { recursive: true });\n // Verify file is actually removed\n await waitForFileRemoval(file);\n })\n );\n } else {\n await Promise.all(\n matchedFiles.map(async (file) => {\n const directory = dirname(file);\n await fs.rm(directory, { recursive: true, force: true });\n // Verify directory is actually removed\n await waitForFileRemoval(directory);\n })\n );\n }\n};\n\n// Helper function to ensure file/directory is completely removed\nconst waitForFileRemoval = async (path: string, maxRetries: number = 50, delay: number = 10): Promise<void> => {\n for (let i = 0; i < maxRetries; i++) {\n try {\n await fs.access(path);\n // If access succeeds, file still exists, wait and retry\n await new Promise((resolve) => setTimeout(resolve, delay));\n } catch (error) {\n // If access fails, file is removed\n return;\n }\n }\n // If we reach here, file still exists after all retries\n throw new Error(`File/directory ${path} was not removed after ${maxRetries} attempts`);\n};\n\nexport const addFileToResource = async (\n catalogDir: string,\n id: string,\n file: { content: string; fileName: string },\n version?: string,\n options?: { path?: string }\n) => {\n let pathToResource: string | undefined;\n\n if (options?.path) {\n pathToResource = join(catalogDir, options.path, 'index.mdx');\n } else {\n // Fall back to global lookup (existing behavior)\n pathToResource = await findFileById(catalogDir, id, version);\n }\n\n if (!pathToResource) throw new Error('Cannot find directory to write file to');\n\n // Create the directory if it doesn't exist\n fsSync.mkdirSync(path.dirname(pathToResource), { recursive: true });\n\n let fileContent = file.content.trim();\n\n try {\n const json = JSON.parse(fileContent);\n fileContent = JSON.stringify(json, null, 2);\n } catch (error) {\n // Just silently fail if the file is not valid JSON\n // Write it as it is\n }\n\n fsSync.writeFileSync(join(dirname(pathToResource), file.fileName), fileContent);\n};\n\nexport const getFileFromResource = async (catalogDir: string, id: string, file: { fileName: string }, version?: string) => {\n const pathToResource = await findFileById(catalogDir, id, version);\n\n if (!pathToResource) throw new Error('Cannot find directory of resource');\n\n const exists = await fs\n .access(join(dirname(pathToResource), file.fileName))\n .then(() => true)\n .catch(() => false);\n if (!exists) throw new Error(`File ${file.fileName} does not exist in resource ${id} v(${version})`);\n\n return fsSync.readFileSync(join(dirname(pathToResource), file.fileName), 'utf-8');\n};\nexport const getVersionedDirectory = (sourceDirectory: string, version: any): string => {\n return join(sourceDirectory, 'versioned', version);\n};\n\nexport const isLatestVersion = async (catalogDir: string, id: string, version?: string) => {\n const resource = await getResource(catalogDir, id, version);\n if (!resource) return false;\n\n const pathToResource = await getResourcePath(catalogDir, id, version);\n\n return !pathToResource?.relativePath.replace(/\\\\/g, '/').includes('/versioned/');\n};\n","import { globSync } from 'glob';\nimport fsSync from 'node:fs';\nimport { copy, CopyFilterAsync, CopyFilterSync } from 'fs-extra';\nimport { join, dirname, normalize, sep as pathSeparator, resolve, basename, relative } from 'node:path';\nimport matter from 'gray-matter';\nimport { satisfies, validRange, valid } from 'semver';\n\n/**\n * Returns true if a given version of a resource id exists in the catalog\n */\nexport const versionExists = async (catalogDir: string, id: string, version: string) => {\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n const matchedFiles = (await searchFilesForId(files, id, version)) || [];\n return matchedFiles.length > 0;\n};\n\nexport const findFileById = async (catalogDir: string, id: string, version?: string): Promise<string | undefined> => {\n const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);\n\n const matchedFiles = (await searchFilesForId(files, id)) || [];\n const latestVersion = matchedFiles.find((path) => !path.includes('versioned'));\n\n // If no version is provided, return the latest version\n if (!version) {\n return latestVersion;\n }\n\n // map files into gray matter to get versions\n const parsedFiles = matchedFiles.map((path) => {\n const { data } = matter.read(path);\n return { ...data, path };\n }) as any[];\n\n // Handle 'latest' version - return the latest (non-versioned) file\n if (version === 'latest') {\n return latestVersion;\n }\n\n // First, check for exact version match (handles non-semver versions like '1', '2', etc.)\n const exactMatch = parsedFiles.find((c) => c.version === version);\n if (exactMatch) {\n return exactMatch.path;\n }\n\n // Try semver range matching\n const semverRange = validRange(version);\n\n if (semverRange) {\n const match = parsedFiles.filter((c) => {\n try {\n return satisfies(c.version, semverRange);\n } catch (error) {\n // If satisfies fails (e.g., comparing semver range with non-semver version), skip this file\n return false;\n }\n });\n return match.length > 0 ? match[0].path : undefined;\n }\n\n // If no exact match and no valid semver range, return undefined\n return undefined;\n};\n\nexport const getFiles = async (pattern: string, ignore: string | string[] = '') => {\n try {\n // 1. Normalize the input pattern to handle mixed separators potentially\n const normalizedInputPattern = normalize(pattern);\n\n // 2. Determine the absolute base directory (cwd for glob)\n // Resolve ensures it's absolute. Handles cases with/without globstar.\n const absoluteBaseDir = resolve(\n normalizedInputPattern.includes('**') ? normalizedInputPattern.split('**')[0] : dirname(normalizedInputPattern)\n );\n\n // 3. Determine the pattern part relative to the absolute base directory\n // We extract the part of the normalized pattern that comes *after* the absoluteBaseDir\n let relativePattern = relative(absoluteBaseDir, normalizedInputPattern);\n\n // On Windows, relative() might return empty string if paths are identical,\n // or might need normalization if the original pattern didn't have `**`\n // Example: pattern = 'dir/file.md', absoluteBaseDir='.../dir', normalized='...\\dir\\file.md'\n // relative() -> 'file.md'\n // Example: pattern = 'dir/**/file.md', absoluteBaseDir='.../dir', normalized='...\\dir\\**\\file.md'\n // relative() -> '**\\file.md'\n // Convert separators in the relative pattern to forward slashes for glob\n relativePattern = relativePattern.replace(/\\\\/g, '/');\n\n const ignoreList = Array.isArray(ignore) ? ignore : [ignore];\n\n const files = globSync(relativePattern, {\n cwd: absoluteBaseDir,\n ignore: ['node_modules/**', ...ignoreList],\n absolute: true,\n nodir: true,\n });\n\n // 5. Normalize results for consistency before returning\n return files.map(normalize);\n } catch (error: any) {\n // Add more diagnostic info to the error\n const absoluteBaseDirForError = resolve(\n normalize(pattern).includes('**') ? normalize(pattern).split('**')[0] : dirname(normalize(pattern))\n );\n const relativePatternForError = relative(absoluteBaseDirForError, normalize(pattern)).replace(/\\\\/g, '/');\n throw new Error(\n `Error finding files for pattern \"${pattern}\" (using cwd: \"${absoluteBaseDirForError}\", globPattern: \"${relativePatternForError}\"): ${error.message}`\n );\n }\n};\n\nexport const readMdxFile = async (path: string) => {\n const { data } = matter.read(path);\n const { markdown, ...frontmatter } = data;\n return { ...frontmatter, markdown };\n};\n\nexport const searchFilesForId = async (files: string[], id: string, version?: string) => {\n // Escape the id to avoid regex issues\n const escapedId = id.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n const idRegex = new RegExp(`^id:\\\\s*(['\"]|>-)?\\\\s*${escapedId}['\"]?\\\\s*$`, 'm');\n\n const versionRegex = new RegExp(`^version:\\\\s*['\"]?${version}['\"]?\\\\s*$`, 'm');\n\n const matches = files.map((file) => {\n const content = fsSync.readFileSync(file, 'utf-8');\n const hasIdMatch = content.match(idRegex);\n\n // Check version if provided\n if (version && !content.match(versionRegex)) {\n return undefined;\n }\n\n if (hasIdMatch) {\n return file;\n }\n });\n\n return matches.filter(Boolean).filter((file) => file !== undefined);\n};\n\n/**\n * Function to copy a directory from source to target, uses a tmp directory\n * @param catalogDir\n * @param source\n * @param target\n * @param filter\n */\nexport const copyDir = async (catalogDir: string, source: string, target: string, filter?: CopyFilterAsync | CopyFilterSync) => {\n const tmpDirectory = join(catalogDir, 'tmp');\n fsSync.mkdirSync(tmpDirectory, { recursive: true });\n\n // Copy everything over\n await copy(source, tmpDirectory, {\n overwrite: true,\n filter,\n });\n\n await copy(tmpDirectory, target, {\n overwrite: true,\n filter,\n });\n\n // Remove the tmp directory\n fsSync.rmSync(tmpDirectory, { recursive: true });\n};\n\n// Makes sure values in sends/recieves are unique\nexport const uniqueVersions = (messages: { id: string; version: string }[]): { id: string; version: string }[] => {\n const uniqueSet = new Set();\n\n return messages.filter((message) => {\n const key = `${message.id}-${message.version}`;\n if (!uniqueSet.has(key)) {\n uniqueSet.add(key);\n return true;\n }\n return false;\n });\n};\n","import type { Service, Specifications } from './types';\nimport fs from 'node:fs/promises';\nimport { join, dirname, extname, relative } from 'node:path';\nimport {\n addFileToResource,\n getFileFromResource,\n getResource,\n rmResourceById,\n versionResource,\n writeResource,\n getVersionedDirectory,\n getResources,\n getResourcePath,\n toResource,\n} from './internal/resources';\nimport { findFileById, uniqueVersions } from './internal/utils';\n\n/**\n * Returns a service from EventCatalog.\n *\n * You can optionally specify a version to get a specific version of the service\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getService } = utils('/path/to/eventcatalog');\n *\n * // Gets the latest version of the event\n * const service = await getService('InventoryService');\n *\n * // Gets a version of the event\n * const service = await getService('InventoryService', '0.0.1');\n * ```\n */\nexport const getService =\n (directory: string) =>\n async (id: string, version?: string): Promise<Service> =>\n getResource(directory, id, version, { type: 'service' }) as Promise<Service>;\n\n/**\n * Returns a service from EventCatalog by it's path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getServiceByPath } = utils('/path/to/eventcatalog');\n *\n * // Returns a service from the catalog by it's path\n * const service = await getServiceByPath('/services/InventoryService/index.mdx');\n * ```\n */\nexport const getServiceByPath = (directory: string) => async (path: string) => {\n const service = await getResource(directory, undefined, undefined, { type: 'service' }, path);\n return service as Service;\n};\n\n/**\n * Returns all services from EventCatalog.\n *\n * You can optionally specify if you want to get the latest version of the services.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getServices } = utils('/path/to/eventcatalog');\n *\n * // Gets all services (and versions) from the catalog\n * const services = await getServices();\n *\n * // Gets all services (only latest version) from the catalog\n * const services = await getServices({ latestOnly: true });\n * ```\n */\nexport const getServices =\n (directory: string) =>\n async (options?: { latestOnly?: boolean }): Promise<Service[]> =>\n getResources(directory, {\n type: 'services',\n ignore: ['**/events/**', '**/commands/**', '**/queries/**', '**/entities/**', '**/subdomains/**/entities/**'],\n ...options,\n }) as Promise<Service[]>;\n\n/**\n * Write a Service to EventCatalog.\n *\n * You can optionally overide the path of the Service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeService } = utils('/path/to/eventcatalog');\n *\n * // Write a Service\n * // Service would be written to services/InventoryService\n * await writeService({\n * id: 'InventoryService',\n * name: 'Inventory Service',\n * version: '0.0.1',\n * summary: 'Service that handles the inventory',\n * markdown: '# Hello world',\n * });\n *\n * // Write a service to the catalog but override the path\n * // Service would be written to services/Inventory/InventoryService\n * await writeService({\n * id: 'InventoryService',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { path: \"/Inventory/InventoryService\"});\n *\n * // Write a service to the catalog and override the existing content (if there is any)\n * await writeService({\n * id: 'InventoryService',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { override: true });\n *\n * // Write a service to the catalog and version the previous version\n * // only works if the new version is greater than the previous version\n * await writeService({\n * id: 'InventoryService',\n * name: 'Inventory Adjusted',\n * version: '0.0.1',\n * summary: 'This is a summary',\n * markdown: '# Hello world',\n * }, { versionExistingContent: true });\n *\n * ```\n */\nexport const writeService =\n (directory: string) =>\n async (\n service: Service,\n options: { path?: string; override?: boolean; versionExistingContent?: boolean; format?: 'md' | 'mdx' } = {\n path: '',\n override: false,\n format: 'mdx',\n }\n ) => {\n const resource: Service = { ...service };\n\n if (Array.isArray(service.sends)) {\n resource.sends = uniqueVersions(service.sends as { id: string; version: string }[]);\n }\n\n if (Array.isArray(service.receives)) {\n resource.receives = uniqueVersions(service.receives as { id: string; version: string }[]);\n }\n\n return await writeResource(directory, resource, { ...options, type: 'service' });\n };\n\n/**\n * Write a versioned service to EventCatalog.\n *\n * You can optionally overide the path of the Service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeVersionedService } = utils('/path/to/eventcatalog');\n *\n * // Write a service\n * // Service would be written to services/InventoryService/versioned/0.0.1\n * await writeVersionedService({\n * id: 'InventoryService',\n * name: 'Inventory Service',\n * version: '0.0.1',\n * summary: 'Service that handles the inventory',\n * markdown: '# Hello world',\n * });\n *\n * ```\n */\nexport const writeVersionedService = (directory: string) => async (service: Service) => {\n const resource: Service = { ...service };\n const path = getVersionedDirectory(service.id, service.version);\n\n return await writeService(directory)(resource, { path: path });\n};\n\n/**\n * Write a service to a domain in EventCatalog.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { writeServiceToDomain } = utils('/path/to/eventcatalog');\n *\n * // Write a service to a domain\n * // Service would be written to domains/Shopping/services/InventoryService\n * await writeServiceToDomain({\n * id: 'InventoryService',\n * name: 'Inventory Service',\n * version: '0.0.1',\n * summary: 'Service that handles the inventory',\n * markdown: '# Hello world',\n * }, { id: 'Shopping' });\n * ```\n */\nexport const writeServiceToDomain =\n (directory: string) =>\n async (\n service: Service,\n domain: { id: string; version?: string; direction?: string },\n options: { path?: string; format?: 'md' | 'mdx'; override?: boolean } = { path: '', format: 'mdx', override: false }\n ) => {\n let pathForService =\n domain.version && domain.version !== 'latest'\n ? `/${domain.id}/versioned/${domain.version}/services`\n : `/${domain.id}/services`;\n pathForService = join(pathForService, service.id);\n\n //\n await writeResource(directory, { ...service }, { ...options, path: pathForService, type: 'service' });\n };\n\n/**\n * Version a service by it's id.\n *\n * Takes the latest service and moves it to a versioned directory.\n * All files with this service are also versioned. (e.g /services/InventoryService/openapi.yml)\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { versionService } = utils('/path/to/eventcatalog');\n *\n * // moves the latest InventoryService service to a versioned directory\n * // the version within that service is used as the version number.\n * await versionService('InventoryService');\n *\n * ```\n */\nexport const versionService = (directory: string) => async (id: string) => versionResource(directory, id);\n\n/**\n * Delete a service at it's given path.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmService } = utils('/path/to/eventcatalog');\n *\n * // Removes the service at services/InventoryService\n * await rmService('/InventoryService');\n * ```\n */\nexport const rmService = (directory: string) => async (path: string) => {\n await fs.rm(join(directory, path), { recursive: true });\n};\n\n/**\n * Delete a service by it's id.\n *\n * Optionally specify a version to delete a specific version of the service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { rmServiceById } = utils('/path/to/eventcatalog');\n *\n * // deletes the latest InventoryService event\n * await rmServiceById('InventoryService');\n *\n * // deletes a specific version of the InventoryService event\n * await rmServiceById('InventoryService', '0.0.1');\n * ```\n */\nexport const rmServiceById = (directory: string) => async (id: string, version?: string, persistFiles?: boolean) => {\n await rmResourceById(directory, id, version, { type: 'service', persistFiles });\n};\n\n/**\n * Add a file to a service by it's id.\n *\n * Optionally specify a version to add a file to a specific version of the service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addFileToService } = utils('/path/to/eventcatalog');\n *\n * // adds a file to the latest InventoryService event\n * await addFileToService('InventoryService', { content: 'Hello world', fileName: 'hello.txt' });\n *\n * // adds a file to a specific version of the InventoryService event\n * await addFileToService('InventoryService', { content: 'Hello world', fileName: 'hello.txt' }, '0.0.1');\n *\n * ```\n */\n\nexport const addFileToService =\n (directory: string) => async (id: string, file: { content: string; fileName: string }, version?: string) =>\n addFileToResource(directory, id, file, version);\n\n/**\n * Returns specification files for a service\n *\n * Optionally specify a version to of the service\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { getSpecificationFilesForService } = utils('/path/to/eventcatalog');\n *\n * // returns a list of specification files for a service\n * await getSpecificationFilesForService('InventoryService', '0.0.1');\n *\n * ```\n */\n\nexport const getSpecificationFilesForService = (directory: string) => async (id: string, version?: string) => {\n let service: Service = await getService(directory)(id, version);\n const filePathToService = await findFileById(directory, id, version);\n\n if (!filePathToService) throw new Error('Cannot find directory of service');\n\n let specs = [] as any;\n if (service.specifications) {\n const serviceSpecifications = service.specifications;\n let specificationFiles;\n\n if (Array.isArray(serviceSpecifications)) {\n specificationFiles = serviceSpecifications.map((spec) => ({ key: spec.type, path: spec.path }));\n } else {\n specificationFiles = Object.keys(serviceSpecifications).map((spec) => ({\n key: spec,\n path: serviceSpecifications[spec as keyof Specifications] as string,\n }));\n }\n\n const getSpecs = specificationFiles.map(async ({ key, path: fileName }) => {\n if (!fileName) {\n throw new Error(`Specification file name for ${fileName} is undefined`);\n }\n const rawFile = await getFileFromResource(directory, id, { fileName }, version);\n\n return { key, content: rawFile, fileName: fileName, path: join(dirname(filePathToService), fileName) };\n });\n\n specs = await Promise.all(getSpecs);\n }\n return specs;\n};\n\n/**\n * Add an event/command to a service by it's id.\n *\n * Optionally specify a version to add the event to a specific version of the service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * // Adds an event to the service or command to the service\n * const { addEventToService, addCommandToService } = utils('/path/to/eventcatalog');\n *\n * // Adds a new event (InventoryUpdatedEvent) that the InventoryService will send\n * await addEventToService('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });\n * * // Adds a new event (OrderComplete) that the InventoryService will receive\n * await addEventToService('InventoryService', 'receives', { event: 'OrderComplete', version: '1.0.0' });\n *\n * // Adds a new command (UpdateInventoryCommand) that the InventoryService will send\n * await addCommandToService('InventoryService', 'sends', { command: 'UpdateInventoryCommand', version: '2.0.0' });\n * // Adds a new command (VerifyInventory) that the InventoryService will receive\n * await addCommandToService('InventoryService', 'receives', { command: 'VerifyInventory', version: '1.0.0' });\n *\n * ```\n */\n\nexport const addMessageToService =\n (directory: string) => async (id: string, direction: string, event: { id: string; version: string }, version?: string) => {\n let service: Service = await getService(directory)(id, version);\n const servicePath = await getResourcePath(directory, id, version);\n const extension = extname(servicePath?.fullPath || '');\n\n if (direction === 'sends') {\n if (service.sends === undefined) {\n service.sends = [];\n }\n // We first check if the event is already in the list\n for (let i = 0; i < service.sends.length; i++) {\n if (service.sends[i].id === event.id && service.sends[i].version === event.version) {\n return;\n }\n }\n service.sends.push({ id: event.id, version: event.version });\n } else if (direction === 'receives') {\n if (service.receives === undefined) {\n service.receives = [];\n }\n // We first check if the event is already in the list\n for (let i = 0; i < service.receives.length; i++) {\n if (service.receives[i].id === event.id && service.receives[i].version === event.version) {\n return;\n }\n }\n service.receives.push({ id: event.id, version: event.version });\n } else {\n throw new Error(`Direction ${direction} is invalid, only 'receives' and 'sends' are supported`);\n }\n\n const existingResource = await findFileById(directory, id, version);\n\n if (!existingResource) {\n throw new Error(`Cannot find service ${id} in the catalog`);\n }\n\n // Get where the service was located, make sure it goes back there.\n const path = existingResource.split(/[\\\\/]+services/)[0];\n const pathToResource = join(path, 'services');\n\n await rmServiceById(directory)(id, version);\n await writeService(pathToResource)(service, { format: extension === '.md' ? 'md' : 'mdx' });\n };\n\n/**\n * Check to see if the catalog has a version for the given service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { serviceHasVersion } = utils('/path/to/eventcatalog');\n *\n * // returns true if version is found for the given event and version (supports semver)\n * await serviceHasVersion('InventoryService', '0.0.1');\n * await serviceHasVersion('InventoryService', 'latest');\n * await serviceHasVersion('InventoryService', '0.0.x');*\n *\n * ```\n */\nexport const serviceHasVersion = (directory: string) => async (id: string, version?: string) => {\n const file = await findFileById(directory, id, version);\n return !!file;\n};\n\n/**\n * Check to see if the path is a service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { isService } = utils('/path/to/eventcatalog');\n *\n * // returns true if the path is a service\n * await isService('/services/InventoryService/index.mdx');\n * ```\n */\nexport const isService = (directory: string) => async (path: string) => {\n const service = await getServiceByPath(directory)(path);\n // Get relative path from root directory\n const relativePath = relative(directory, path);\n\n // Split into path segments using regex to handle both / and \\\n const segments = relativePath.split(/[/\\\\]+/);\n\n // needs to workf or windows too\n return !!service && segments.includes('services');\n};\n\n/**\n * Takes a given raw file and converts it to a service.\n *\n * @param directory - The directory to convert the file to a service.\n * @returns The service.\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { toService } = utils('/path/to/eventcatalog');\n *\n * // Read the file from somewhere\n * const file = fs.readFileSync('/path/to/services/InventoryService/index.mdx', 'utf8');\n *\n * // Converts the raw file to a service\n * await toService(file);\n * ```\n */\nexport const toService = (directory: string) => async (file: string) => toResource(directory, file) as Promise<Service>;\n\n/**\n * Add an entity to a service by its id.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * const { addEntityToService } = utils('/path/to/eventcatalog');\n *\n * // adds a new entity (User) to the InventoryService\n * await addEntityToService('InventoryService', { id: 'User', version: '1.0.0' });\n *\n * // adds a new entity (Product) to a specific version of the InventoryService\n * await addEntityToService('InventoryService', { id: 'Product', version: '1.0.0' }, '2.0.0');\n *\n * ```\n */\nexport const addEntityToService =\n (directory: string) => async (id: string, entity: { id: string; version: string }, version?: string) => {\n let service: Service = await getService(directory)(id, version);\n const servicePath = await getResourcePath(directory, id, version);\n const extension = extname(servicePath?.fullPath || '');\n\n if (service.entities === undefined) {\n service.entities = [];\n }\n\n // Check if the entity is already in the list\n for (let i = 0; i < service.entities.length; i++) {\n if (service.entities[i].id === entity.id && service.entities[i].version === entity.version) {\n return;\n }\n }\n\n service.entities.push({ id: entity.id, version: entity.version });\n\n const existingResource = await findFileById(directory, id, version);\n\n if (!existingResource) {\n throw new Error(`Cannot find service ${id} in the catalog`);\n }\n\n // Get where the service was located, make sure it goes back there.\n const path = existingResource.split(/[\\\\/]+services/)[0];\n const pathToResource = join(path, 'services');\n\n await rmServiceById(directory)(id, version);\n await writeService(pathToResource)(service, { format: extension === '.md' ? 'md' : 'mdx' });\n };\n\n/**\n * Add a data store to a service by it's id.\n *\n * Optionally specify a version to add the data store to a specific version of the service.\n *\n * @example\n * ```ts\n * import utils from '@eventcatalog/utils';\n *\n * // Adds an data store to the service\n * const { addDataStoreToService } = utils('/path/to/eventcatalog');\n *\n * // Adds a new data store (orders-db) that the InventoryService will write to\n * await addDataStoreToService('InventoryService', 'writesTo', { id: 'orders-db', version: '2.0.0' });\n *\n * * // Adds a new data store (OrderComplete) that the InventoryService will read from\n * await addDataStoreToService('InventoryService', 'readsFrom', { id: 'orders-db', version: '1.0.0' });\n *\n * ```\n */\n\nexport const addDataStoreToService =\n (directory: string) =>\n async (id: string, operation: 'writesTo' | 'readsFrom', dataStore: { id: string; version: string }, version?: string) => {\n let service: Service = await getService(directory)(id, version);\n const servicePath = await getResourcePath(directory, id, version);\n const extension = extname(servicePath?.fullPath || '');\n\n if (operation === 'writesTo') {\n if (service.writesTo === undefined) {\n service.writesTo = [];\n }\n\n // We first check if the data store is already in the list\n for (let i = 0; i < service.writesTo.length; i++) {\n if (service.writesTo[i].id === dataStore.id && service.writesTo[i].version === dataStore.version) {\n return;\n }\n }\n\n service.writesTo.push({ id: dataStore.id, version: dataStore.version });\n } else if (operation === 'readsFrom') {\n if (service.readsFrom === undefined) {\n service.readsFrom = [];\n }\n\n // We first check if the data store is already in the list\n for (let i = 0; i < service.readsFrom.length; i++) {\n if (service.readsFrom[i].id === dataStore.id && service.readsFrom[i].version === dataStore.version) {\n return;\n }\n }\n service.readsFrom.push({ id: dataStore.id, version: dataStore.version });\n } else {\n throw new Error(`Operation ${operation} is invalid, only 'writesTo' and 'readsFrom' are supported`);\n }\n\n const existingResource = await findFileById(directory, id, version);\n\n if (!existingResource) {\n throw new Error(`Cannot find service ${id} in the catalog`);\n }\n\n // Get where the service was located, make sure it goes back there.\n const path = existingResource.split(/[\\\\/]+services/)[0];\n const pathToResource = join(path, 'services');\n\n await rmServiceById(directory)(id, version);\n await writeService(p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OAAOD,UAAiB;AACjF,MAAI;AACF,UAAM,UAAU,MAAM,uBAAuB,SAAS,EAAEA,KAAI;AAC5D,UAAM,EAAE,UAAU,IAAI,MAAM,mCAAmC,SAAS,EAAE,QAAQ,IAAI,QAAQ,OAAO;AACrG,WAAO;AAAA,EACT,SAAS,OAAO;AACd,WAAO,CAAC;AAAA,EACV;AACF;AAcO,IAAM,uBAAuB,CAAC,cAAsB,OAAOA,UAAiB;AACjF,MAAI;AACF,UAAM,UAAU,MAAM,uBAAuB,SAAS,EAAEA,KAAI;AAC5D,UAAM,EAAE,UAAU,IAAI,MAAM,mCAAmC,SAAS,EAAE,QAAQ,IAAI,QAAQ,OAAO;AACrG,WAAO;AAAA,EACT,SAAS,OAAO;AACd,WAAO,CAAC;AAAA,EACV;AACF;","names":["import_node_path","import_gray_matter","path","matter","fsSync","import_gray_matter","import_node_fs","import_semver","import_node_path","fsSync","matter","matter","fsSync","import_promises","import_node_path","import_semver","path","matter"]}