@eventcatalog/sdk 2.13.2 → 2.14.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.
package/dist/index.js CHANGED
@@ -35,50 +35,533 @@ __export(src_exports, {
35
35
  module.exports = __toCommonJS(src_exports);
36
36
  var import_node_path20 = require("path");
37
37
 
38
+ // src/dsl/utils.ts
39
+ var import_glob = require("glob");
40
+ function serializeBaseFields(resource, indent = " ") {
41
+ const lines = [];
42
+ if (resource.version) {
43
+ lines.push(`${indent}version ${resource.version}`);
44
+ }
45
+ if (resource.name) {
46
+ lines.push(`${indent}name "${resource.name}"`);
47
+ }
48
+ if (resource.summary) {
49
+ lines.push(`${indent}summary "${resource.summary.trim()}"`);
50
+ }
51
+ if (resource.owners && resource.owners.length > 0) {
52
+ for (const owner of resource.owners) {
53
+ lines.push(`${indent}owner ${owner}`);
54
+ }
55
+ }
56
+ if (resource.deprecated === true) {
57
+ lines.push(`${indent}deprecated true`);
58
+ }
59
+ if (resource.draft === true) {
60
+ lines.push(`${indent}draft true`);
61
+ }
62
+ return lines.join("\n");
63
+ }
64
+ function buildMessageTypeIndex(catalogDir) {
65
+ const index = /* @__PURE__ */ new Map();
66
+ const types = ["events", "commands", "queries"];
67
+ const typeMap = { events: "event", commands: "command", queries: "query" };
68
+ for (const type of types) {
69
+ const matches = (0, import_glob.globSync)(`**/${type}/*/index.{md,mdx}`, { cwd: catalogDir });
70
+ for (const match of matches) {
71
+ const parts = match.replace(/\\/g, "/").split("/");
72
+ const typeIdx = parts.lastIndexOf(type);
73
+ if (typeIdx !== -1 && typeIdx + 1 < parts.length) {
74
+ const id = parts[typeIdx + 1];
75
+ if (!index.has(id)) index.set(id, typeMap[type]);
76
+ }
77
+ }
78
+ }
79
+ return index;
80
+ }
81
+ function resolveMessageType(catalogDirOrIndex, id) {
82
+ if (typeof catalogDirOrIndex !== "string") {
83
+ return catalogDirOrIndex.get(id);
84
+ }
85
+ if ((0, import_glob.globSync)(`**/events/${id}/index.{md,mdx}`, { cwd: catalogDirOrIndex }).length > 0) return "event";
86
+ if ((0, import_glob.globSync)(`**/commands/${id}/index.{md,mdx}`, { cwd: catalogDirOrIndex }).length > 0) return "command";
87
+ if ((0, import_glob.globSync)(`**/queries/${id}/index.{md,mdx}`, { cwd: catalogDirOrIndex }).length > 0) return "query";
88
+ return void 0;
89
+ }
90
+ function serializeChannelRef(channel) {
91
+ let ref = channel.id;
92
+ if (channel.version) ref += `@${channel.version}`;
93
+ return ref;
94
+ }
95
+ function serializeMessagePointers(items, direction, catalogDirOrIndex, indent = " ") {
96
+ const lines = [];
97
+ for (const item of items) {
98
+ const msgType = resolveMessageType(catalogDirOrIndex, item.id);
99
+ if (!msgType) continue;
100
+ let ref = `${item.id}`;
101
+ if (item.version) ref += `@${item.version}`;
102
+ const channels = direction === "sends" ? item.to : item.from;
103
+ const channelKeyword = direction === "sends" ? "to" : "from";
104
+ if (channels && channels.length === 1) {
105
+ lines.push(`${indent}${direction} ${msgType} ${ref} ${channelKeyword} ${serializeChannelRef(channels[0])}`);
106
+ } else if (channels && channels.length > 1) {
107
+ const channelRefs = channels.map(serializeChannelRef).join(", ");
108
+ lines.push(`${indent}${direction} ${msgType} ${ref} ${channelKeyword} ${channelRefs}`);
109
+ } else {
110
+ lines.push(`${indent}${direction} ${msgType} ${ref}`);
111
+ }
112
+ }
113
+ return lines.join("\n");
114
+ }
115
+
116
+ // src/dsl/message.ts
117
+ function messageToDSL(resource, type) {
118
+ const body = serializeBaseFields(resource);
119
+ if (!body) {
120
+ return `${type} ${resource.id}`;
121
+ }
122
+ return `${type} ${resource.id} {
123
+ ${body}
124
+ }`;
125
+ }
126
+
127
+ // src/dsl/service.ts
128
+ async function serviceToDSL(resource, options, getMessageFn) {
129
+ const { catalogDir, hydrate = false, _seen = /* @__PURE__ */ new Set() } = options;
130
+ const msgIndex = options._msgIndex || buildMessageTypeIndex(catalogDir);
131
+ const parts = [];
132
+ if (hydrate && getMessageFn) {
133
+ const allMessages = [...resource.sends || [], ...resource.receives || []];
134
+ for (const msg of allMessages) {
135
+ const key = `${msg.id}@${msg.version || "latest"}`;
136
+ if (_seen.has(key)) continue;
137
+ _seen.add(key);
138
+ const msgType = resolveMessageType(msgIndex, msg.id);
139
+ if (!msgType) continue;
140
+ const msgResource = await getMessageFn(msg.id, msg.version);
141
+ if (msgResource) {
142
+ parts.push(messageToDSL(msgResource, msgType));
143
+ }
144
+ }
145
+ }
146
+ const lines = [];
147
+ const baseFields = serializeBaseFields(resource);
148
+ if (baseFields) lines.push(baseFields);
149
+ if (resource.sends && resource.sends.length > 0) {
150
+ const sendsStr = serializeMessagePointers(resource.sends, "sends", msgIndex);
151
+ if (sendsStr) lines.push(sendsStr);
152
+ }
153
+ if (resource.receives && resource.receives.length > 0) {
154
+ const recvStr = serializeMessagePointers(resource.receives, "receives", msgIndex);
155
+ if (recvStr) lines.push(recvStr);
156
+ }
157
+ if (resource.writesTo && resource.writesTo.length > 0) {
158
+ for (const container of resource.writesTo) {
159
+ let ref = container.id;
160
+ if (container.version) ref += `@${container.version}`;
161
+ lines.push(` writes-to container ${ref}`);
162
+ }
163
+ }
164
+ if (resource.readsFrom && resource.readsFrom.length > 0) {
165
+ for (const container of resource.readsFrom) {
166
+ let ref = container.id;
167
+ if (container.version) ref += `@${container.version}`;
168
+ lines.push(` reads-from container ${ref}`);
169
+ }
170
+ }
171
+ const body = lines.join("\n");
172
+ parts.push(`service ${resource.id} {
173
+ ${body}
174
+ }`);
175
+ return parts.join("\n\n");
176
+ }
177
+
178
+ // src/dsl/channel.ts
179
+ function channelToDSL(resource) {
180
+ const lines = [];
181
+ if (resource.version) {
182
+ lines.push(` version ${resource.version}`);
183
+ }
184
+ if (resource.name) {
185
+ lines.push(` name "${resource.name}"`);
186
+ }
187
+ if (resource.address) {
188
+ lines.push(` address "${resource.address}"`);
189
+ }
190
+ if (resource.protocols && resource.protocols.length > 0) {
191
+ for (const protocol of resource.protocols) {
192
+ lines.push(` protocol "${protocol}"`);
193
+ }
194
+ }
195
+ if (resource.summary) {
196
+ lines.push(` summary "${resource.summary.trim()}"`);
197
+ }
198
+ if (!lines.length) {
199
+ return `channel ${resource.id}`;
200
+ }
201
+ return `channel ${resource.id} {
202
+ ${lines.join("\n")}
203
+ }`;
204
+ }
205
+
206
+ // src/dsl/owner.ts
207
+ function teamToDSL(team) {
208
+ const lines = [];
209
+ if (team.name) lines.push(` name "${team.name}"`);
210
+ if (team.avatarUrl) lines.push(` avatar "${team.avatarUrl}"`);
211
+ if (team.role) lines.push(` role "${team.role}"`);
212
+ if (team.summary) lines.push(` summary "${team.summary}"`);
213
+ if (team.email) lines.push(` email "${team.email}"`);
214
+ if (team.slackDirectMessageUrl) lines.push(` slack "${team.slackDirectMessageUrl}"`);
215
+ return `team ${team.id} {
216
+ ${lines.join("\n")}
217
+ }`;
218
+ }
219
+ function userToDSL(user) {
220
+ const lines = [];
221
+ if (user.name) lines.push(` name "${user.name}"`);
222
+ if (user.avatarUrl) lines.push(` avatar "${user.avatarUrl}"`);
223
+ if (user.role) lines.push(` role "${user.role}"`);
224
+ if (user.email) lines.push(` email "${user.email}"`);
225
+ if (user.slackDirectMessageUrl) lines.push(` slack "${user.slackDirectMessageUrl}"`);
226
+ return `user ${user.id} {
227
+ ${lines.join("\n")}
228
+ }`;
229
+ }
230
+
231
+ // src/dsl/domain.ts
232
+ async function hydrateOwners(owners, resolvers, seen, parts) {
233
+ if (!owners || !resolvers.getTeam || !resolvers.getUser) return;
234
+ for (const ownerId of owners) {
235
+ const key = `owner:${ownerId}`;
236
+ if (seen.has(key)) continue;
237
+ seen.add(key);
238
+ const team = await resolvers.getTeam(ownerId);
239
+ if (team) {
240
+ parts.push(teamToDSL(team));
241
+ continue;
242
+ }
243
+ const user = await resolvers.getUser(ownerId);
244
+ if (user) {
245
+ parts.push(userToDSL(user));
246
+ }
247
+ }
248
+ }
249
+ async function hydrateChannelsFromMessages(messages, resolvers, seen, parts) {
250
+ if (!resolvers.getChannel) return;
251
+ for (const msg of messages) {
252
+ const channels = msg.to || msg.from;
253
+ if (!channels) continue;
254
+ for (const ch of channels) {
255
+ const key = `channel:${ch.id}@${ch.version || "latest"}`;
256
+ if (seen.has(key)) continue;
257
+ seen.add(key);
258
+ const channel = await resolvers.getChannel(ch.id, ch.version);
259
+ if (channel) {
260
+ parts.push(channelToDSL(channel));
261
+ }
262
+ }
263
+ }
264
+ }
265
+ async function buildDomainBody(resource, options, resolvers, keyword) {
266
+ const { catalogDir, hydrate = false, _seen = /* @__PURE__ */ new Set() } = options;
267
+ const msgIndex = options._msgIndex || buildMessageTypeIndex(catalogDir);
268
+ const topLevelParts = [];
269
+ if (hydrate && resolvers) {
270
+ if (resource.services && resource.services.length > 0 && resolvers.getService) {
271
+ for (const svcRef of resource.services) {
272
+ const svcKey = `service:${svcRef.id}@${svcRef.version || "latest"}`;
273
+ if (_seen.has(svcKey)) continue;
274
+ _seen.add(svcKey);
275
+ const svc = await resolvers.getService(svcRef.id, svcRef.version);
276
+ if (svc) {
277
+ await hydrateOwners(svc.owners, resolvers, _seen, topLevelParts);
278
+ const svcMessages = [...svc.sends || [], ...svc.receives || []];
279
+ await hydrateChannelsFromMessages(svcMessages, resolvers, _seen, topLevelParts);
280
+ const svcDsl = await serviceToDSL(svc, { catalogDir, hydrate: true, _seen, _msgIndex: msgIndex }, resolvers.getMessage);
281
+ topLevelParts.push(svcDsl);
282
+ }
283
+ }
284
+ }
285
+ const domainMessages = [...resource.sends || [], ...resource.receives || []];
286
+ await hydrateChannelsFromMessages(domainMessages, resolvers, _seen, topLevelParts);
287
+ if (resolvers.getMessage) {
288
+ for (const msg of domainMessages) {
289
+ const key = `${msg.id}@${msg.version || "latest"}`;
290
+ if (_seen.has(key)) continue;
291
+ _seen.add(key);
292
+ const msgType = resolveMessageType(msgIndex, msg.id);
293
+ if (!msgType) continue;
294
+ const msgResource = await resolvers.getMessage(msg.id, msg.version);
295
+ if (msgResource) {
296
+ topLevelParts.push(messageToDSL(msgResource, msgType));
297
+ }
298
+ }
299
+ }
300
+ }
301
+ const lines = [];
302
+ const baseFields = serializeBaseFields(resource);
303
+ if (baseFields) lines.push(baseFields);
304
+ if (resource.services && resource.services.length > 0) {
305
+ for (const svc of resource.services) {
306
+ let ref = svc.id;
307
+ if (svc.version) ref += `@${svc.version}`;
308
+ lines.push(` service ${ref}`);
309
+ }
310
+ }
311
+ if (resource.sends && resource.sends.length > 0) {
312
+ const sendsStr = serializeMessagePointers(resource.sends, "sends", msgIndex);
313
+ if (sendsStr) lines.push(sendsStr);
314
+ }
315
+ if (resource.receives && resource.receives.length > 0) {
316
+ const recvStr = serializeMessagePointers(resource.receives, "receives", msgIndex);
317
+ if (recvStr) lines.push(recvStr);
318
+ }
319
+ if (resource.domains && resource.domains.length > 0) {
320
+ if (hydrate && resolvers?.getDomain) {
321
+ for (const subRef of resource.domains) {
322
+ const subKey = `domain:${subRef.id}@${subRef.version || "latest"}`;
323
+ if (_seen.has(subKey)) continue;
324
+ _seen.add(subKey);
325
+ const subDomain = await resolvers.getDomain(subRef.id, subRef.version);
326
+ if (subDomain) {
327
+ await hydrateOwners(subDomain.owners, resolvers, _seen, topLevelParts);
328
+ const sub = await buildDomainBody(
329
+ subDomain,
330
+ { catalogDir, hydrate, _seen, _msgIndex: msgIndex },
331
+ resolvers,
332
+ "subdomain"
333
+ );
334
+ topLevelParts.push(...sub.topLevelParts);
335
+ const indented = sub.block.split("\n").map((line) => ` ${line}`).join("\n");
336
+ lines.push(indented);
337
+ }
338
+ }
339
+ } else {
340
+ for (const sub of resource.domains) {
341
+ let ref = sub.id;
342
+ if (sub.version) ref += `@${sub.version}`;
343
+ lines.push(` subdomain ${ref}`);
344
+ }
345
+ }
346
+ }
347
+ const body = lines.join("\n");
348
+ const block = `${keyword} ${resource.id} {
349
+ ${body}
350
+ }`;
351
+ return { topLevelParts, block };
352
+ }
353
+ async function domainToDSL(resource, options, resolvers) {
354
+ const { catalogDir, hydrate = false, _seen = /* @__PURE__ */ new Set() } = options;
355
+ const msgIndex = options._msgIndex || buildMessageTypeIndex(catalogDir);
356
+ const result = await buildDomainBody(resource, { catalogDir, hydrate, _seen, _msgIndex: msgIndex }, resolvers, "domain");
357
+ const parts = [...result.topLevelParts, result.block];
358
+ return parts.join("\n\n");
359
+ }
360
+
361
+ // src/dsl/index.ts
362
+ function getMessage(resolvers, msgIndex) {
363
+ return async (id, version) => {
364
+ const msgType = resolveMessageType(msgIndex, id);
365
+ if (!msgType) return void 0;
366
+ switch (msgType) {
367
+ case "event":
368
+ return resolvers.getEvent(id, version);
369
+ case "command":
370
+ return resolvers.getCommand(id, version);
371
+ case "query":
372
+ return resolvers.getQuery(id, version);
373
+ }
374
+ };
375
+ }
376
+ async function hydrateChannels(resource, resolvers, seen, parts) {
377
+ const allMessages = [...resource.sends || [], ...resource.receives || []];
378
+ for (const msg of allMessages) {
379
+ const channels = "to" in msg ? msg.to : "from" in msg ? msg.from : void 0;
380
+ if (!channels) continue;
381
+ for (const ch of channels) {
382
+ const key = `channel:${ch.id}@${ch.version || "latest"}`;
383
+ if (seen.has(key)) continue;
384
+ seen.add(key);
385
+ const channel = await resolvers.getChannel(ch.id, ch.version);
386
+ if (channel) {
387
+ parts.push(channelToDSL(channel));
388
+ }
389
+ }
390
+ }
391
+ }
392
+ async function hydrateOwners2(owners, resolvers, seen, parts) {
393
+ if (!owners) return;
394
+ for (const ownerId of owners) {
395
+ const key = `owner:${ownerId}`;
396
+ if (seen.has(key)) continue;
397
+ seen.add(key);
398
+ const team = await resolvers.getTeam(ownerId);
399
+ if (team) {
400
+ parts.push(teamToDSL(team));
401
+ continue;
402
+ }
403
+ const user = await resolvers.getUser(ownerId);
404
+ if (user) {
405
+ parts.push(userToDSL(user));
406
+ }
407
+ }
408
+ }
409
+ var toDSL = (catalogDir, resolvers) => async (resource, options) => {
410
+ const resources = Array.isArray(resource) ? resource : [resource];
411
+ const seen = /* @__PURE__ */ new Set();
412
+ const parts = [];
413
+ const msgIndex = buildMessageTypeIndex(catalogDir);
414
+ for (const res of resources) {
415
+ const key = `${options.type}:${res.id}@${res.version || "latest"}`;
416
+ if (seen.has(key)) continue;
417
+ seen.add(key);
418
+ switch (options.type) {
419
+ case "event":
420
+ case "command":
421
+ case "query":
422
+ if (options.hydrate) {
423
+ await hydrateOwners2(res.owners, resolvers, seen, parts);
424
+ }
425
+ parts.push(messageToDSL(res, options.type));
426
+ break;
427
+ case "service":
428
+ if (options.hydrate) {
429
+ await hydrateOwners2(res.owners, resolvers, seen, parts);
430
+ await hydrateChannels(res, resolvers, seen, parts);
431
+ }
432
+ parts.push(
433
+ await serviceToDSL(
434
+ res,
435
+ { catalogDir, hydrate: options.hydrate, _seen: seen, _msgIndex: msgIndex },
436
+ getMessage(resolvers, msgIndex)
437
+ )
438
+ );
439
+ break;
440
+ case "domain":
441
+ if (options.hydrate) {
442
+ await hydrateOwners2(res.owners, resolvers, seen, parts);
443
+ }
444
+ parts.push(
445
+ await domainToDSL(
446
+ res,
447
+ { catalogDir, hydrate: options.hydrate, _seen: seen, _msgIndex: msgIndex },
448
+ {
449
+ getService: resolvers.getService,
450
+ getDomain: resolvers.getDomain,
451
+ getMessage: getMessage(resolvers, msgIndex),
452
+ getChannel: resolvers.getChannel,
453
+ getTeam: resolvers.getTeam,
454
+ getUser: resolvers.getUser
455
+ }
456
+ )
457
+ );
458
+ break;
459
+ }
460
+ }
461
+ return parts.join("\n\n");
462
+ };
463
+
38
464
  // src/events.ts
39
465
  var import_promises2 = __toESM(require("fs/promises"));
40
466
  var import_node_path4 = require("path");
41
467
 
42
468
  // src/internal/utils.ts
43
- var import_glob = require("glob");
469
+ var import_glob2 = require("glob");
44
470
  var import_node_fs = __toESM(require("fs"));
45
471
  var import_fs_extra = require("fs-extra");
46
472
  var import_node_path = require("path");
47
473
  var import_gray_matter = __toESM(require("gray-matter"));
48
474
  var import_semver = require("semver");
475
+ var _fileIndexCache = null;
476
+ var _fileIndexCatalogDir = null;
477
+ var _matterCache = null;
478
+ var _fileIndexMtimeMs = 0;
479
+ function buildFileCache(catalogDir) {
480
+ const files = (0, import_glob2.globSync)("**/index.{md,mdx}", {
481
+ cwd: catalogDir,
482
+ ignore: ["node_modules/**"],
483
+ absolute: true,
484
+ nodir: true
485
+ }).map(import_node_path.normalize);
486
+ const index = /* @__PURE__ */ new Map();
487
+ const matterResults = /* @__PURE__ */ new Map();
488
+ for (const file of files) {
489
+ const content = import_node_fs.default.readFileSync(file, "utf-8");
490
+ const parsed = (0, import_gray_matter.default)(content);
491
+ matterResults.set(file, parsed);
492
+ const id = parsed.data.id;
493
+ if (!id) continue;
494
+ const version = parsed.data.version || "";
495
+ const isVersioned = file.includes("versioned");
496
+ const entry = { path: file, id, version: String(version), isVersioned };
497
+ const existing = index.get(id);
498
+ if (existing) {
499
+ existing.push(entry);
500
+ } else {
501
+ index.set(id, [entry]);
502
+ }
503
+ }
504
+ _fileIndexCache = index;
505
+ _fileIndexCatalogDir = catalogDir;
506
+ _matterCache = matterResults;
507
+ try {
508
+ _fileIndexMtimeMs = import_node_fs.default.statSync(catalogDir).mtimeMs;
509
+ } catch {
510
+ _fileIndexMtimeMs = 0;
511
+ }
512
+ }
513
+ function ensureFileCache(catalogDir) {
514
+ if (!_fileIndexCache || _fileIndexCatalogDir !== catalogDir) {
515
+ buildFileCache(catalogDir);
516
+ return;
517
+ }
518
+ try {
519
+ const currentMtime = import_node_fs.default.statSync(catalogDir).mtimeMs;
520
+ if (currentMtime !== _fileIndexMtimeMs) {
521
+ buildFileCache(catalogDir);
522
+ }
523
+ } catch {
524
+ buildFileCache(catalogDir);
525
+ }
526
+ }
527
+ function invalidateFileCache() {
528
+ _fileIndexCache = null;
529
+ _fileIndexCatalogDir = null;
530
+ _matterCache = null;
531
+ }
532
+ function cachedMatterRead(filePath) {
533
+ if (_matterCache) {
534
+ const cached = _matterCache.get(filePath);
535
+ if (cached) return cached;
536
+ }
537
+ return import_gray_matter.default.read(filePath);
538
+ }
49
539
  var versionExists = async (catalogDir, id, version) => {
50
- const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
51
- const matchedFiles = await searchFilesForId(files, id, version) || [];
52
- return matchedFiles.length > 0;
540
+ ensureFileCache(catalogDir);
541
+ const entries = _fileIndexCache.get(id);
542
+ if (!entries) return false;
543
+ return entries.some((e) => e.version === version);
53
544
  };
54
545
  var findFileById = async (catalogDir, id, version) => {
55
- const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
56
- const matchedFiles = await searchFilesForId(files, id) || [];
57
- const latestVersion = matchedFiles.find((path6) => !path6.includes("versioned"));
58
- if (!version) {
59
- return latestVersion;
60
- }
61
- const parsedFiles = matchedFiles.map((path6) => {
62
- const { data } = import_gray_matter.default.read(path6);
63
- return { ...data, path: path6 };
64
- });
65
- if (version === "latest") {
66
- return latestVersion;
67
- }
68
- const exactMatch = parsedFiles.find((c) => c.version === version);
69
- if (exactMatch) {
70
- return exactMatch.path;
546
+ ensureFileCache(catalogDir);
547
+ const entries = _fileIndexCache.get(id);
548
+ if (!entries || entries.length === 0) return void 0;
549
+ const latestEntry = entries.find((e) => !e.isVersioned);
550
+ if (!version || version === "latest") {
551
+ return latestEntry?.path;
71
552
  }
553
+ const exactMatch = entries.find((e) => e.version === version);
554
+ if (exactMatch) return exactMatch.path;
72
555
  const semverRange = (0, import_semver.validRange)(version);
73
556
  if (semverRange) {
74
- const match = parsedFiles.filter((c) => {
557
+ const match = entries.find((e) => {
75
558
  try {
76
- return (0, import_semver.satisfies)(c.version, semverRange);
77
- } catch (error) {
559
+ return (0, import_semver.satisfies)(e.version, semverRange);
560
+ } catch {
78
561
  return false;
79
562
  }
80
563
  });
81
- return match.length > 0 ? match[0].path : void 0;
564
+ return match?.path;
82
565
  }
83
566
  return void 0;
84
567
  };
@@ -91,7 +574,7 @@ var getFiles = async (pattern, ignore = "") => {
91
574
  let relativePattern = (0, import_node_path.relative)(absoluteBaseDir, normalizedInputPattern);
92
575
  relativePattern = relativePattern.replace(/\\/g, "/");
93
576
  const ignoreList = Array.isArray(ignore) ? ignore : [ignore];
94
- const files = (0, import_glob.globSync)(relativePattern, {
577
+ const files = (0, import_glob2.globSync)(relativePattern, {
95
578
  cwd: absoluteBaseDir,
96
579
  ignore: ["node_modules/**", ...ignoreList],
97
580
  absolute: true,
@@ -194,6 +677,7 @@ var versionResource = async (catalogDir, id) => {
194
677
  })
195
678
  );
196
679
  });
680
+ invalidateFileCache();
197
681
  };
198
682
  var writeResource = async (catalogDir, resource, options = {
199
683
  path: "",
@@ -233,6 +717,7 @@ var writeResource = async (catalogDir, resource, options = {
233
717
  }
234
718
  const document = import_gray_matter2.default.stringify(markdown.trim(), frontmatter);
235
719
  import_node_fs2.default.writeFileSync(lockPath, document);
720
+ invalidateFileCache();
236
721
  } finally {
237
722
  await (0, import_proper_lockfile.unlock)(lockPath).catch(() => {
238
723
  });
@@ -242,7 +727,7 @@ var getResource = async (catalogDir, id, version, options, filePath) => {
242
727
  const attachSchema = options?.attachSchema || false;
243
728
  const file = filePath || (id ? await findFileById(catalogDir, id, version) : void 0);
244
729
  if (!file || !import_node_fs2.default.existsSync(file)) return;
245
- const { data, content } = import_gray_matter2.default.read(file);
730
+ const { data, content } = cachedMatterRead(file);
246
731
  if (attachSchema && data?.schemaPath) {
247
732
  const resourceDirectory = (0, import_path.dirname)(file);
248
733
  const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
@@ -293,7 +778,7 @@ var getResources = async (catalogDir, {
293
778
  const files = await getFiles(filePattern, [ignoreList, ...ignore]);
294
779
  if (files.length === 0) return;
295
780
  return files.map((file) => {
296
- const { data, content } = import_gray_matter2.default.read(file);
781
+ const { data, content } = cachedMatterRead(file);
297
782
  if (attachSchema && data?.schemaPath) {
298
783
  const resourceDirectory = (0, import_path.dirname)(file);
299
784
  const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
@@ -334,6 +819,7 @@ var rmResourceById = async (catalogDir, id, version, options) => {
334
819
  })
335
820
  );
336
821
  }
822
+ invalidateFileCache();
337
823
  };
338
824
  var waitForFileRemoval = async (path6, maxRetries = 50, delay = 10) => {
339
825
  for (let i = 0; i < maxRetries; i++) {
@@ -399,6 +885,7 @@ var writeEventToService = (directory) => async (event, service, options = { path
399
885
  };
400
886
  var rmEvent = (directory) => async (path6) => {
401
887
  await import_promises2.default.rm((0, import_node_path4.join)(directory, path6), { recursive: true });
888
+ invalidateFileCache();
402
889
  };
403
890
  var rmEventById = (directory) => async (id, version, persistFiles) => {
404
891
  await rmResourceById(directory, id, version, { type: "event", persistFiles });
@@ -435,6 +922,7 @@ var writeCommandToService = (directory) => async (command, service, options = {
435
922
  };
436
923
  var rmCommand = (directory) => async (path6) => {
437
924
  await import_promises3.default.rm((0, import_node_path5.join)(directory, path6), { recursive: true });
925
+ invalidateFileCache();
438
926
  };
439
927
  var rmCommandById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "command", persistFiles });
440
928
  var versionCommand = (directory) => async (id) => versionResource(directory, id);
@@ -469,6 +957,7 @@ var writeQueryToService = (directory) => async (query, service, options = { path
469
957
  };
470
958
  var rmQuery = (directory) => async (path6) => {
471
959
  await import_promises4.default.rm((0, import_node_path6.join)(directory, path6), { recursive: true });
960
+ invalidateFileCache();
472
961
  };
473
962
  var rmQueryById = (directory) => async (id, version, persistFiles) => {
474
963
  await rmResourceById(directory, id, version, { type: "query", persistFiles });
@@ -493,7 +982,18 @@ var getServiceByPath = (directory) => async (path6) => {
493
982
  };
494
983
  var getServices = (directory) => async (options) => getResources(directory, {
495
984
  type: "services",
496
- ignore: ["**/events/**", "**/commands/**", "**/queries/**", "**/entities/**", "**/subdomains/**/entities/**"],
985
+ ignore: [
986
+ "**/events/**",
987
+ "**/commands/**",
988
+ "**/queries/**",
989
+ "**/entities/**",
990
+ "**/channels/**",
991
+ "**/containers/**",
992
+ "**/data-products/**",
993
+ "**/data-stores/**",
994
+ "**/flows/**",
995
+ "**/subdomains/**/entities/**"
996
+ ],
497
997
  ...options
498
998
  });
499
999
  var writeService = (directory) => async (service, options = {
@@ -523,6 +1023,7 @@ var writeServiceToDomain = (directory) => async (service, domain, options = { pa
523
1023
  var versionService = (directory) => async (id) => versionResource(directory, id);
524
1024
  var rmService = (directory) => async (path6) => {
525
1025
  await import_promises5.default.rm((0, import_node_path7.join)(directory, path6), { recursive: true });
1026
+ invalidateFileCache();
526
1027
  };
527
1028
  var rmServiceById = (directory) => async (id, version, persistFiles) => {
528
1029
  await rmResourceById(directory, id, version, { type: "service", persistFiles });
@@ -699,6 +1200,7 @@ var writeDomain = (directory) => async (domain, options = {
699
1200
  var versionDomain = (directory) => async (id) => versionResource(directory, id);
700
1201
  var rmDomain = (directory) => async (path6) => {
701
1202
  await import_promises6.default.rm((0, import_node_path8.join)(directory, path6), { recursive: true });
1203
+ invalidateFileCache();
702
1204
  };
703
1205
  var rmDomainById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "domain", persistFiles });
704
1206
  var addFileToDomain = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
@@ -830,6 +1332,7 @@ var getChannels = (directory) => async (options) => getResources(directory, { ty
830
1332
  var writeChannel = (directory) => async (channel, options = { path: "" }) => writeResource(directory, { ...channel }, { ...options, type: "channel" });
831
1333
  var rmChannel = (directory) => async (path6) => {
832
1334
  await import_promises7.default.rm((0, import_node_path9.join)(directory, path6), { recursive: true });
1335
+ invalidateFileCache();
833
1336
  };
834
1337
  var rmChannelById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "channel", persistFiles });
835
1338
  var versionChannel = (directory) => async (id) => versionResource(directory, id);
@@ -856,8 +1359,8 @@ var addMessageToChannel = (directory, collection) => async (id, _message, versio
856
1359
  writeMessage: writeQuery
857
1360
  }
858
1361
  };
859
- const { getMessage, rmMessageById, writeMessage } = functions[collection];
860
- const message = await getMessage(directory)(_message.id, _message.version);
1362
+ const { getMessage: getMessage2, rmMessageById, writeMessage } = functions[collection];
1363
+ const message = await getMessage2(directory)(_message.id, _message.version);
861
1364
  const messagePath = await getResourcePath(directory, _message.id, _message.version);
862
1365
  const extension = (0, import_node_path9.extname)(messagePath?.fullPath || "");
863
1366
  if (!message) throw new Error(`Message ${_message.id} with version ${_message.version} not found`);
@@ -1002,10 +1505,12 @@ var writeCustomDoc = (directory) => async (customDoc, options = { path: "" }) =>
1002
1505
  import_node_fs4.default.mkdirSync(import_node_path11.default.dirname(fullPath), { recursive: true });
1003
1506
  const document = import_gray_matter5.default.stringify(customDoc.markdown.trim(), rest);
1004
1507
  import_node_fs4.default.writeFileSync(fullPath, document);
1508
+ invalidateFileCache();
1005
1509
  };
1006
1510
  var rmCustomDoc = (directory) => async (filePath) => {
1007
1511
  const withExtension = filePath.endsWith(".mdx") ? filePath : `${filePath}.mdx`;
1008
1512
  await import_promises8.default.rm((0, import_node_path11.join)(directory, withExtension), { recursive: true });
1513
+ invalidateFileCache();
1009
1514
  };
1010
1515
 
1011
1516
  // src/teams.ts
@@ -1057,9 +1562,11 @@ var writeUser = (catalogDir) => async (user, options = {}) => {
1057
1562
  const document = import_gray_matter6.default.stringify(markdown, frontmatter);
1058
1563
  import_node_fs5.default.mkdirSync((0, import_node_path12.join)(catalogDir, ""), { recursive: true });
1059
1564
  import_node_fs5.default.writeFileSync((0, import_node_path12.join)(catalogDir, "", `${resource.id}.mdx`), document);
1565
+ invalidateFileCache();
1060
1566
  };
1061
1567
  var rmUserById = (catalogDir) => async (id) => {
1062
1568
  import_node_fs5.default.rmSync((0, import_node_path12.join)(catalogDir, `${id}.mdx`), { recursive: true });
1569
+ invalidateFileCache();
1063
1570
  };
1064
1571
 
1065
1572
  // src/teams.ts
@@ -1099,9 +1606,11 @@ var writeTeam = (catalogDir) => async (team, options = {}) => {
1099
1606
  const document = import_gray_matter7.default.stringify(markdown, frontmatter);
1100
1607
  import_node_fs6.default.mkdirSync((0, import_node_path13.join)(catalogDir, ""), { recursive: true });
1101
1608
  import_node_fs6.default.writeFileSync((0, import_node_path13.join)(catalogDir, "", `${resource.id}.mdx`), document);
1609
+ invalidateFileCache();
1102
1610
  };
1103
1611
  var rmTeamById = (catalogDir) => async (id) => {
1104
1612
  await import_promises9.default.rm((0, import_node_path13.join)(catalogDir, `${id}.mdx`), { recursive: true });
1613
+ invalidateFileCache();
1105
1614
  };
1106
1615
  var getOwnersForResource = (catalogDir) => async (id, version) => {
1107
1616
  const resource = await getResource(catalogDir, id, version);
@@ -1231,6 +1740,7 @@ var writeEntity = (directory) => async (entity, options = {
1231
1740
  }) => writeResource(directory, { ...entity }, { ...options, type: "entity" });
1232
1741
  var rmEntity = (directory) => async (path6) => {
1233
1742
  await import_promises10.default.rm((0, import_node_path16.join)(directory, path6), { recursive: true });
1743
+ invalidateFileCache();
1234
1744
  };
1235
1745
  var rmEntityById = (directory) => async (id, version, persistFiles) => {
1236
1746
  await rmResourceById(directory, id, version, { type: "entity", persistFiles });
@@ -1254,6 +1764,7 @@ var writeContainer = (directory) => async (data, options = {
1254
1764
  var versionContainer = (directory) => async (id) => versionResource(directory, id);
1255
1765
  var rmContainer = (directory) => async (path6) => {
1256
1766
  await import_promises11.default.rm((0, import_node_path17.join)(directory, path6), { recursive: true });
1767
+ invalidateFileCache();
1257
1768
  };
1258
1769
  var rmContainerById = (directory) => async (id, version, persistFiles) => {
1259
1770
  await rmResourceById(directory, id, version, { type: "container", persistFiles });
@@ -1301,6 +1812,7 @@ var writeDataProductToDomain = (directory) => async (dataProduct, domain, option
1301
1812
  };
1302
1813
  var rmDataProduct = (directory) => async (path6) => {
1303
1814
  await import_promises12.default.rm((0, import_node_path18.join)(directory, path6), { recursive: true });
1815
+ invalidateFileCache();
1304
1816
  };
1305
1817
  var rmDataProductById = (directory) => async (id, version, persistFiles) => {
1306
1818
  await rmResourceById(directory, id, version, { type: "data-product", persistFiles });
@@ -1324,6 +1836,7 @@ var writeDiagram = (directory) => async (diagram, options = {
1324
1836
  }) => writeResource(directory, { ...diagram }, { ...options, type: "diagram" });
1325
1837
  var rmDiagram = (directory) => async (path6) => {
1326
1838
  await import_promises13.default.rm((0, import_node_path19.join)(directory, path6), { recursive: true });
1839
+ invalidateFileCache();
1327
1840
  };
1328
1841
  var rmDiagramById = (directory) => async (id, version, persistFiles) => {
1329
1842
  await rmResourceById(directory, id, version, { type: "diagram", persistFiles });
@@ -2428,7 +2941,35 @@ var src_default = (path6) => {
2428
2941
  * @param version - Optional version of the diagram to add the file to
2429
2942
  * @returns
2430
2943
  */
2431
- addFileToDiagram: addFileToDiagram((0, import_node_path20.join)(path6))
2944
+ addFileToDiagram: addFileToDiagram((0, import_node_path20.join)(path6)),
2945
+ /**
2946
+ * ================================
2947
+ * DSL
2948
+ * ================================
2949
+ */
2950
+ /**
2951
+ * Converts catalog resources to EventCatalog DSL (.ec) format strings.
2952
+ *
2953
+ * @param resource - A resource or array of resources to convert
2954
+ * @param options - Options including type ('event'|'command'|'query'|'service'|'domain') and optional hydrate flag
2955
+ * @returns A DSL string representation
2956
+ *
2957
+ * @example
2958
+ * ```ts
2959
+ * const dsl = await sdk.toDSL(event, { type: 'event' });
2960
+ * const dsl = await sdk.toDSL(services, { type: 'service', hydrate: true });
2961
+ * ```
2962
+ */
2963
+ toDSL: toDSL((0, import_node_path20.join)(path6), {
2964
+ getEvent: getEvent((0, import_node_path20.join)(path6)),
2965
+ getCommand: getCommand((0, import_node_path20.join)(path6)),
2966
+ getQuery: getQuery((0, import_node_path20.join)(path6)),
2967
+ getService: getService((0, import_node_path20.join)(path6)),
2968
+ getDomain: getDomain((0, import_node_path20.join)(path6, "domains")),
2969
+ getChannel: getChannel((0, import_node_path20.join)(path6)),
2970
+ getTeam: getTeam((0, import_node_path20.join)(path6, "teams")),
2971
+ getUser: getUser((0, import_node_path20.join)(path6, "users"))
2972
+ })
2432
2973
  };
2433
2974
  };
2434
2975
  //# sourceMappingURL=index.js.map