@eventcatalog/sdk 1.4.7 → 1.4.9

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
@@ -2,12 +2,11 @@
2
2
  import { join as join11 } from "node:path";
3
3
 
4
4
  // src/events.ts
5
- import fs3 from "node:fs/promises";
5
+ import fs2 from "node:fs/promises";
6
6
  import { join as join3 } from "node:path";
7
7
 
8
8
  // src/internal/utils.ts
9
- import { glob } from "glob";
10
- import fs from "node:fs/promises";
9
+ import { globSync } from "glob";
11
10
  import fsSync from "node:fs";
12
11
  import { copy } from "fs-extra";
13
12
  import { join } from "node:path";
@@ -45,7 +44,7 @@ var findFileById = async (catalogDir, id, version) => {
45
44
  var getFiles = async (pattern, ignore = "") => {
46
45
  try {
47
46
  const ignoreList = Array.isArray(ignore) ? ignore : [ignore];
48
- const files = await glob(pattern, { ignore: ["node_modules/**", ...ignoreList] });
47
+ const files = globSync(pattern, { ignore: ["node_modules/**", ...ignoreList] });
49
48
  return files;
50
49
  } catch (error) {
51
50
  throw new Error(`Error finding files: ${error}`);
@@ -54,18 +53,16 @@ var getFiles = async (pattern, ignore = "") => {
54
53
  var searchFilesForId = async (files, id, version) => {
55
54
  const idRegex = new RegExp(`^id:\\s*(['"]|>-)?\\s*${id}['"]?\\s*$`, "m");
56
55
  const versionRegex = new RegExp(`^version:\\s*['"]?${version}['"]?\\s*$`, "m");
57
- const matches = await Promise.all(
58
- files.map(async (file) => {
59
- const content = await fs.readFile(file, "utf-8");
60
- const hasIdMatch = content.match(idRegex);
61
- if (version && !content.match(versionRegex)) {
62
- return void 0;
63
- }
64
- if (hasIdMatch) {
65
- return file;
66
- }
67
- })
68
- );
56
+ const matches = files.map((file) => {
57
+ const content = fsSync.readFileSync(file, "utf-8");
58
+ const hasIdMatch = content.match(idRegex);
59
+ if (version && !content.match(versionRegex)) {
60
+ return void 0;
61
+ }
62
+ if (hasIdMatch) {
63
+ return file;
64
+ }
65
+ });
69
66
  return matches.filter(Boolean).filter((file) => file !== void 0);
70
67
  };
71
68
  var copyDir = async (catalogDir, source, target, filter) => {
@@ -96,7 +93,7 @@ var uniqueVersions = (messages) => {
96
93
  // src/internal/resources.ts
97
94
  import { dirname, join as join2 } from "path";
98
95
  import matter2 from "gray-matter";
99
- import fs2 from "node:fs/promises";
96
+ import fs from "node:fs/promises";
100
97
  import fsSync2 from "node:fs";
101
98
  import { satisfies as satisfies2 } from "semver";
102
99
  import { lock, unlock } from "proper-lockfile";
@@ -114,7 +111,7 @@ var versionResource = async (catalogDir, id) => {
114
111
  await copyDir(catalogDir, sourceDirectory, targetDirectory, (src) => {
115
112
  return !src.includes("versioned");
116
113
  });
117
- await fs2.readdir(sourceDirectory).then(async (resourceFiles) => {
114
+ await fs.readdir(sourceDirectory).then(async (resourceFiles) => {
118
115
  await Promise.all(
119
116
  resourceFiles.map(async (file2) => {
120
117
  if (file2 !== "versioned") {
@@ -195,14 +192,14 @@ var rmResourceById = async (catalogDir, id, version, options) => {
195
192
  if (options?.persistFiles) {
196
193
  await Promise.all(
197
194
  matchedFiles.map(async (file) => {
198
- await fs2.rm(file, { recursive: true });
195
+ await fs.rm(file, { recursive: true });
199
196
  })
200
197
  );
201
198
  } else {
202
199
  await Promise.all(
203
200
  matchedFiles.map(async (file) => {
204
201
  const directory = dirname(file);
205
- await fs2.rm(directory, { recursive: true, force: true });
202
+ await fs.rm(directory, { recursive: true, force: true });
206
203
  })
207
204
  );
208
205
  }
@@ -215,7 +212,7 @@ var addFileToResource = async (catalogDir, id, file, version) => {
215
212
  var getFileFromResource = async (catalogDir, id, file, version) => {
216
213
  const pathToResource = await findFileById(catalogDir, id, version);
217
214
  if (!pathToResource) throw new Error("Cannot find directory of resource");
218
- const exists = await fs2.access(join2(dirname(pathToResource), file.fileName)).then(() => true).catch(() => false);
215
+ const exists = await fs.access(join2(dirname(pathToResource), file.fileName)).then(() => true).catch(() => false);
219
216
  if (!exists) throw new Error(`File ${file.fileName} does not exist in resource ${id} v(${version})`);
220
217
  return fsSync2.readFileSync(join2(dirname(pathToResource), file.fileName), "utf-8");
221
218
  };
@@ -233,7 +230,7 @@ var writeEventToService = (directory) => async (event, service, options = { path
233
230
  await writeResource(directory, { ...event }, { ...options, path: pathForEvent, type: "event" });
234
231
  };
235
232
  var rmEvent = (directory) => async (path) => {
236
- await fs3.rm(join3(directory, path), { recursive: true });
233
+ await fs2.rm(join3(directory, path), { recursive: true });
237
234
  };
238
235
  var rmEventById = (directory) => async (id, version, persistFiles) => {
239
236
  await rmResourceById(directory, id, version, { type: "event", persistFiles });
@@ -249,7 +246,7 @@ var eventHasVersion = (directory) => async (id, version) => {
249
246
  };
250
247
 
251
248
  // src/commands.ts
252
- import fs4 from "node:fs/promises";
249
+ import fs3 from "node:fs/promises";
253
250
  import { join as join4 } from "node:path";
254
251
  var getCommand = (directory) => async (id, version) => getResource(directory, id, version, { type: "command" });
255
252
  var getCommands = (directory) => async (options) => getResources(directory, { type: "commands", ...options });
@@ -260,7 +257,7 @@ var writeCommandToService = (directory) => async (command, service, options = {
260
257
  await writeResource(directory, { ...command }, { ...options, path: pathForEvent, type: "command" });
261
258
  };
262
259
  var rmCommand = (directory) => async (path) => {
263
- await fs4.rm(join4(directory, path), { recursive: true });
260
+ await fs3.rm(join4(directory, path), { recursive: true });
264
261
  };
265
262
  var rmCommandById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "command", persistFiles });
266
263
  var versionCommand = (directory) => async (id) => versionResource(directory, id);
@@ -274,7 +271,7 @@ var commandHasVersion = (directory) => async (id, version) => {
274
271
  };
275
272
 
276
273
  // src/queries.ts
277
- import fs5 from "node:fs/promises";
274
+ import fs4 from "node:fs/promises";
278
275
  import { join as join5 } from "node:path";
279
276
  var getQuery = (directory) => async (id, version) => getResource(directory, id, version, { type: "query" });
280
277
  var writeQuery = (directory) => async (query, options = { path: "" }) => writeResource(directory, { ...query }, { ...options, type: "query" });
@@ -285,7 +282,7 @@ var writeQueryToService = (directory) => async (query, service, options = { path
285
282
  await writeResource(directory, { ...query }, { ...options, path: pathForQuery, type: "query" });
286
283
  };
287
284
  var rmQuery = (directory) => async (path) => {
288
- await fs5.rm(join5(directory, path), { recursive: true });
285
+ await fs4.rm(join5(directory, path), { recursive: true });
289
286
  };
290
287
  var rmQueryById = (directory) => async (id, version, persistFiles) => {
291
288
  await rmResourceById(directory, id, version, { type: "query", persistFiles });
@@ -301,7 +298,7 @@ var queryHasVersion = (directory) => async (id, version) => {
301
298
  };
302
299
 
303
300
  // src/services.ts
304
- import fs6 from "node:fs/promises";
301
+ import fs5 from "node:fs/promises";
305
302
  import { join as join6, dirname as dirname2 } from "node:path";
306
303
  var getService = (directory) => async (id, version) => getResource(directory, id, version, { type: "service" });
307
304
  var getServices = (directory) => async (options) => getResources(directory, {
@@ -331,7 +328,7 @@ var writeServiceToDomain = (directory) => async (service, domain, options = { pa
331
328
  };
332
329
  var versionService = (directory) => async (id) => versionResource(directory, id);
333
330
  var rmService = (directory) => async (path) => {
334
- await fs6.rm(join6(directory, path), { recursive: true });
331
+ await fs5.rm(join6(directory, path), { recursive: true });
335
332
  };
336
333
  var rmServiceById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "service", persistFiles });
337
334
  var addFileToService = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
@@ -395,12 +392,12 @@ var serviceHasVersion = (directory) => async (id, version) => {
395
392
  };
396
393
 
397
394
  // src/domains.ts
398
- import fs7 from "node:fs/promises";
395
+ import fs6 from "node:fs/promises";
399
396
  import { join as join7 } from "node:path";
400
397
  var getDomain = (directory) => async (id, version) => getResource(directory, id, version, { type: "domain" });
401
398
  var getDomains = (directory) => async (options) => getResources(directory, {
402
399
  type: "domains",
403
- ignore: ["**/services/**", "**/events/**", "**/commands/**", "**/queries/**"],
400
+ ignore: ["**/services/**", "**/events/**", "**/commands/**", "**/queries/**", "**/flows/**"],
404
401
  ...options
405
402
  });
406
403
  var writeDomain = (directory) => async (domain, options = { path: "" }) => {
@@ -412,7 +409,7 @@ var writeDomain = (directory) => async (domain, options = { path: "" }) => {
412
409
  };
413
410
  var versionDomain = (directory) => async (id) => versionResource(directory, id);
414
411
  var rmDomain = (directory) => async (path) => {
415
- await fs7.rm(join7(directory, path), { recursive: true });
412
+ await fs6.rm(join7(directory, path), { recursive: true });
416
413
  };
417
414
  var rmDomainById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "domain", persistFiles });
418
415
  var addFileToDomain = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
@@ -435,13 +432,13 @@ var addServiceToDomain = (directory) => async (id, service, version) => {
435
432
  };
436
433
 
437
434
  // src/channels.ts
438
- import fs8 from "node:fs/promises";
435
+ import fs7 from "node:fs/promises";
439
436
  import { join as join8 } from "node:path";
440
437
  var getChannel = (directory) => async (id, version) => getResource(directory, id, version, { type: "channel" });
441
438
  var getChannels = (directory) => async (options) => getResources(directory, { type: "channels", ...options });
442
439
  var writeChannel = (directory) => async (channel, options = { path: "" }) => writeResource(directory, { ...channel }, { ...options, type: "channel" });
443
440
  var rmChannel = (directory) => async (path) => {
444
- await fs8.rm(join8(directory, path), { recursive: true });
441
+ await fs7.rm(join8(directory, path), { recursive: true });
445
442
  };
446
443
  var rmChannelById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "channel", persistFiles });
447
444
  var versionChannel = (directory) => async (id) => versionResource(directory, id);
@@ -487,7 +484,7 @@ var addMessageToChannel = (directory, collection) => async (id, _message, versio
487
484
  };
488
485
 
489
486
  // src/teams.ts
490
- import fs9 from "node:fs/promises";
487
+ import fs8 from "node:fs/promises";
491
488
  import fsSync3 from "node:fs";
492
489
  import { join as join9 } from "node:path";
493
490
  import matter3 from "gray-matter";
@@ -529,7 +526,7 @@ var writeTeam = (catalogDir) => async (team, options = {}) => {
529
526
  fsSync3.writeFileSync(join9(catalogDir, "", `${resource.id}.md`), document);
530
527
  };
531
528
  var rmTeamById = (catalogDir) => async (id) => {
532
- await fs9.rm(join9(catalogDir, `${id}.md`), { recursive: true });
529
+ await fs8.rm(join9(catalogDir, `${id}.md`), { recursive: true });
533
530
  };
534
531
 
535
532
  // src/users.ts