@eventcatalog/sdk 1.4.0 → 1.4.2

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/index.mjs CHANGED
@@ -43,7 +43,8 @@ var findFileById = async (catalogDir, id, version) => {
43
43
  };
44
44
  var getFiles = async (pattern, ignore = "") => {
45
45
  try {
46
- const files = await glob(pattern, { ignore: ["node_modules/**", ignore] });
46
+ const ignoreList = Array.isArray(ignore) ? ignore : [ignore];
47
+ const files = await glob(pattern, { ignore: ["node_modules/**", ...ignoreList] });
47
48
  return files;
48
49
  } catch (error) {
49
50
  throw new Error(`Error finding files: ${error}`);
@@ -155,9 +156,9 @@ var getResource = async (catalogDir, id, version, options) => {
155
156
  markdown: content.trim()
156
157
  };
157
158
  };
158
- var getResources = async (catalogDir, { type, latestOnly = false }) => {
159
- const ignore = latestOnly ? `**/versioned/**` : "";
160
- const files = await getFiles(`${catalogDir}/**/${type}/**/index.md`, ignore);
159
+ var getResources = async (catalogDir, { type, latestOnly = false, ignore = [] }) => {
160
+ const ignoreList = latestOnly ? `**/versioned/**` : "";
161
+ const files = await getFiles(`${catalogDir}/**/${type}/**/index.md`, [ignoreList, ...ignore]);
161
162
  if (files.length === 0) return;
162
163
  return files.map((file) => {
163
164
  const { data, content } = matter2.read(file);
@@ -173,7 +174,20 @@ var rmResourceById = async (catalogDir, id, version, options) => {
173
174
  if (matchedFiles.length === 0) {
174
175
  throw new Error(`No ${options?.type || "resource"} found with id: ${id}`);
175
176
  }
176
- await Promise.all(matchedFiles.map((file) => fs2.rm(file)));
177
+ if (options?.persistFiles) {
178
+ await Promise.all(
179
+ matchedFiles.map(async (file) => {
180
+ await fs2.rm(file, { recursive: true });
181
+ })
182
+ );
183
+ } else {
184
+ await Promise.all(
185
+ matchedFiles.map(async (file) => {
186
+ const directory = dirname(file);
187
+ await fs2.rm(directory, { recursive: true, force: true });
188
+ })
189
+ );
190
+ }
177
191
  };
178
192
  var addFileToResource = async (catalogDir, id, file, version) => {
179
193
  const pathToResource = await findFileById(catalogDir, id, version);
@@ -203,8 +217,8 @@ var writeEventToService = (directory) => async (event, service, options = { path
203
217
  var rmEvent = (directory) => async (path) => {
204
218
  await fs3.rm(join3(directory, path), { recursive: true });
205
219
  };
206
- var rmEventById = (directory) => async (id, version) => {
207
- await rmResourceById(directory, id, version, { type: "event" });
220
+ var rmEventById = (directory) => async (id, version, persistFiles) => {
221
+ await rmResourceById(directory, id, version, { type: "event", persistFiles });
208
222
  };
209
223
  var versionEvent = (directory) => async (id) => versionResource(directory, id);
210
224
  var addFileToEvent = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
@@ -230,7 +244,7 @@ var writeCommandToService = (directory) => async (command, service, options = {
230
244
  var rmCommand = (directory) => async (path) => {
231
245
  await fs4.rm(join4(directory, path), { recursive: true });
232
246
  };
233
- var rmCommandById = (directory) => async (id, version) => rmResourceById(directory, id, version, { type: "command" });
247
+ var rmCommandById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "command", persistFiles });
234
248
  var versionCommand = (directory) => async (id) => versionResource(directory, id);
235
249
  var addFileToCommand = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
236
250
  var addSchemaToCommand = (directory) => async (id, schema, version) => {
@@ -255,8 +269,8 @@ var writeQueryToService = (directory) => async (query, service, options = { path
255
269
  var rmQuery = (directory) => async (path) => {
256
270
  await fs5.rm(join5(directory, path), { recursive: true });
257
271
  };
258
- var rmQueryById = (directory) => async (id, version) => {
259
- await rmResourceById(directory, id, version, { type: "query" });
272
+ var rmQueryById = (directory) => async (id, version, persistFiles) => {
273
+ await rmResourceById(directory, id, version, { type: "query", persistFiles });
260
274
  };
261
275
  var versionQuery = (directory) => async (id) => versionResource(directory, id);
262
276
  var addFileToQuery = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
@@ -272,7 +286,11 @@ var queryHasVersion = (directory) => async (id, version) => {
272
286
  import fs6 from "node:fs/promises";
273
287
  import { join as join6, dirname as dirname2 } from "node:path";
274
288
  var getService = (directory) => async (id, version) => getResource(directory, id, version, { type: "service" });
275
- var getServices = (directory) => async (options) => getResources(directory, { type: "services", ...options });
289
+ var getServices = (directory) => async (options) => getResources(directory, {
290
+ type: "services",
291
+ ignore: ["**/events/**", "**/commands/**", "**/queries/**"],
292
+ ...options
293
+ });
276
294
  var writeService = (directory) => async (service, options = { path: "" }) => {
277
295
  const resource = { ...service };
278
296
  if (Array.isArray(service.sends)) {
@@ -362,7 +380,11 @@ var serviceHasVersion = (directory) => async (id, version) => {
362
380
  import fs7 from "node:fs/promises";
363
381
  import { join as join7 } from "node:path";
364
382
  var getDomain = (directory) => async (id, version) => getResource(directory, id, version, { type: "domain" });
365
- var getDomains = (directory) => async (options) => getResources(directory, { type: "domains", ...options });
383
+ var getDomains = (directory) => async (options) => getResources(directory, {
384
+ type: "domains",
385
+ ignore: ["**/services/**", "**/events/**", "**/commands/**", "**/queries/**"],
386
+ ...options
387
+ });
366
388
  var writeDomain = (directory) => async (domain, options = { path: "" }) => {
367
389
  const resource = { ...domain };
368
390
  if (Array.isArray(domain.services)) {
@@ -442,7 +464,7 @@ var addMessageToChannel = (directory, collection) => async (id, _message, versio
442
464
  }
443
465
  const path = existingResource.split(`/${collection}`)[0];
444
466
  const pathToResource = join8(path, collection);
445
- await rmMessageById(directory)(_message.id, _message.version);
467
+ await rmMessageById(directory)(_message.id, _message.version, true);
446
468
  await writeMessage(pathToResource)(message);
447
469
  };
448
470