@eventcatalog/sdk 2.14.0 → 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.d.mts +46 -11
- package/dist/index.d.ts +46 -11
- package/dist/index.js +152 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +152 -47
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -637,13 +637,7 @@ declare const _default: (path: string) => {
|
|
|
637
637
|
content: string;
|
|
638
638
|
fileName: string;
|
|
639
639
|
}, version?: string, options?: {
|
|
640
|
-
path
|
|
641
|
-
* Adds a schema to the given command
|
|
642
|
-
* @param id - The id of the command to add the schema to
|
|
643
|
-
* @param schema - Schema contents to add including the content and the file name
|
|
644
|
-
* @param version - Optional version of the command to add the schema to
|
|
645
|
-
* @returns
|
|
646
|
-
*/: string;
|
|
640
|
+
path?: string;
|
|
647
641
|
}) => Promise<void>;
|
|
648
642
|
/**
|
|
649
643
|
* Adds a schema to the given query
|
|
@@ -743,7 +737,18 @@ declare const _default: (path: string) => {
|
|
|
743
737
|
addEventToChannel: (id: string, _message: {
|
|
744
738
|
id: string;
|
|
745
739
|
version: string;
|
|
746
|
-
parameters
|
|
740
|
+
parameters
|
|
741
|
+
/**
|
|
742
|
+
* Returns a query from EventCatalog
|
|
743
|
+
* @param id - The id of the query to retrieve
|
|
744
|
+
* @param version - Optional id of the version to get (supports semver)
|
|
745
|
+
* @returns Query|Undefined
|
|
746
|
+
*/
|
|
747
|
+
? /**
|
|
748
|
+
* ================================
|
|
749
|
+
* Queries
|
|
750
|
+
* ================================
|
|
751
|
+
*/: {
|
|
747
752
|
[key: string]: string;
|
|
748
753
|
};
|
|
749
754
|
}, version?: string) => Promise<void>;
|
|
@@ -766,7 +771,18 @@ declare const _default: (path: string) => {
|
|
|
766
771
|
addCommandToChannel: (id: string, _message: {
|
|
767
772
|
id: string;
|
|
768
773
|
version: string;
|
|
769
|
-
parameters
|
|
774
|
+
parameters
|
|
775
|
+
/**
|
|
776
|
+
* Returns a query from EventCatalog
|
|
777
|
+
* @param id - The id of the query to retrieve
|
|
778
|
+
* @param version - Optional id of the version to get (supports semver)
|
|
779
|
+
* @returns Query|Undefined
|
|
780
|
+
*/
|
|
781
|
+
? /**
|
|
782
|
+
* ================================
|
|
783
|
+
* Queries
|
|
784
|
+
* ================================
|
|
785
|
+
*/: {
|
|
770
786
|
[key: string]: string;
|
|
771
787
|
};
|
|
772
788
|
}, version?: string) => Promise<void>;
|
|
@@ -789,7 +805,18 @@ declare const _default: (path: string) => {
|
|
|
789
805
|
addQueryToChannel: (id: string, _message: {
|
|
790
806
|
id: string;
|
|
791
807
|
version: string;
|
|
792
|
-
parameters
|
|
808
|
+
parameters
|
|
809
|
+
/**
|
|
810
|
+
* Returns a query from EventCatalog
|
|
811
|
+
* @param id - The id of the query to retrieve
|
|
812
|
+
* @param version - Optional id of the version to get (supports semver)
|
|
813
|
+
* @returns Query|Undefined
|
|
814
|
+
*/
|
|
815
|
+
? /**
|
|
816
|
+
* ================================
|
|
817
|
+
* Queries
|
|
818
|
+
* ================================
|
|
819
|
+
*/: {
|
|
793
820
|
[key: string]: string;
|
|
794
821
|
};
|
|
795
822
|
}, version?: string) => Promise<void>;
|
|
@@ -808,7 +835,15 @@ declare const _default: (path: string) => {
|
|
|
808
835
|
writeService: (service: Service, options?: {
|
|
809
836
|
path?: string;
|
|
810
837
|
override?: boolean;
|
|
811
|
-
versionExistingContent
|
|
838
|
+
versionExistingContent
|
|
839
|
+
/**
|
|
840
|
+
* Moves a given event id to the version directory
|
|
841
|
+
* @param directory
|
|
842
|
+
*/
|
|
843
|
+
? /**
|
|
844
|
+
* Moves a given event id to the version directory
|
|
845
|
+
* @param directory
|
|
846
|
+
*/: boolean;
|
|
812
847
|
format?: "md" | "mdx";
|
|
813
848
|
}) => Promise<void>;
|
|
814
849
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -637,13 +637,7 @@ declare const _default: (path: string) => {
|
|
|
637
637
|
content: string;
|
|
638
638
|
fileName: string;
|
|
639
639
|
}, version?: string, options?: {
|
|
640
|
-
path
|
|
641
|
-
* Adds a schema to the given command
|
|
642
|
-
* @param id - The id of the command to add the schema to
|
|
643
|
-
* @param schema - Schema contents to add including the content and the file name
|
|
644
|
-
* @param version - Optional version of the command to add the schema to
|
|
645
|
-
* @returns
|
|
646
|
-
*/: string;
|
|
640
|
+
path?: string;
|
|
647
641
|
}) => Promise<void>;
|
|
648
642
|
/**
|
|
649
643
|
* Adds a schema to the given query
|
|
@@ -743,7 +737,18 @@ declare const _default: (path: string) => {
|
|
|
743
737
|
addEventToChannel: (id: string, _message: {
|
|
744
738
|
id: string;
|
|
745
739
|
version: string;
|
|
746
|
-
parameters
|
|
740
|
+
parameters
|
|
741
|
+
/**
|
|
742
|
+
* Returns a query from EventCatalog
|
|
743
|
+
* @param id - The id of the query to retrieve
|
|
744
|
+
* @param version - Optional id of the version to get (supports semver)
|
|
745
|
+
* @returns Query|Undefined
|
|
746
|
+
*/
|
|
747
|
+
? /**
|
|
748
|
+
* ================================
|
|
749
|
+
* Queries
|
|
750
|
+
* ================================
|
|
751
|
+
*/: {
|
|
747
752
|
[key: string]: string;
|
|
748
753
|
};
|
|
749
754
|
}, version?: string) => Promise<void>;
|
|
@@ -766,7 +771,18 @@ declare const _default: (path: string) => {
|
|
|
766
771
|
addCommandToChannel: (id: string, _message: {
|
|
767
772
|
id: string;
|
|
768
773
|
version: string;
|
|
769
|
-
parameters
|
|
774
|
+
parameters
|
|
775
|
+
/**
|
|
776
|
+
* Returns a query from EventCatalog
|
|
777
|
+
* @param id - The id of the query to retrieve
|
|
778
|
+
* @param version - Optional id of the version to get (supports semver)
|
|
779
|
+
* @returns Query|Undefined
|
|
780
|
+
*/
|
|
781
|
+
? /**
|
|
782
|
+
* ================================
|
|
783
|
+
* Queries
|
|
784
|
+
* ================================
|
|
785
|
+
*/: {
|
|
770
786
|
[key: string]: string;
|
|
771
787
|
};
|
|
772
788
|
}, version?: string) => Promise<void>;
|
|
@@ -789,7 +805,18 @@ declare const _default: (path: string) => {
|
|
|
789
805
|
addQueryToChannel: (id: string, _message: {
|
|
790
806
|
id: string;
|
|
791
807
|
version: string;
|
|
792
|
-
parameters
|
|
808
|
+
parameters
|
|
809
|
+
/**
|
|
810
|
+
* Returns a query from EventCatalog
|
|
811
|
+
* @param id - The id of the query to retrieve
|
|
812
|
+
* @param version - Optional id of the version to get (supports semver)
|
|
813
|
+
* @returns Query|Undefined
|
|
814
|
+
*/
|
|
815
|
+
? /**
|
|
816
|
+
* ================================
|
|
817
|
+
* Queries
|
|
818
|
+
* ================================
|
|
819
|
+
*/: {
|
|
793
820
|
[key: string]: string;
|
|
794
821
|
};
|
|
795
822
|
}, version?: string) => Promise<void>;
|
|
@@ -808,7 +835,15 @@ declare const _default: (path: string) => {
|
|
|
808
835
|
writeService: (service: Service, options?: {
|
|
809
836
|
path?: string;
|
|
810
837
|
override?: boolean;
|
|
811
|
-
versionExistingContent
|
|
838
|
+
versionExistingContent
|
|
839
|
+
/**
|
|
840
|
+
* Moves a given event id to the version directory
|
|
841
|
+
* @param directory
|
|
842
|
+
*/
|
|
843
|
+
? /**
|
|
844
|
+
* Moves a given event id to the version directory
|
|
845
|
+
* @param directory
|
|
846
|
+
*/: boolean;
|
|
812
847
|
format?: "md" | "mdx";
|
|
813
848
|
}) => Promise<void>;
|
|
814
849
|
/**
|
package/dist/index.js
CHANGED
|
@@ -61,10 +61,30 @@ function serializeBaseFields(resource, indent = " ") {
|
|
|
61
61
|
}
|
|
62
62
|
return lines.join("\n");
|
|
63
63
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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";
|
|
68
88
|
return void 0;
|
|
69
89
|
}
|
|
70
90
|
function serializeChannelRef(channel) {
|
|
@@ -72,10 +92,10 @@ function serializeChannelRef(channel) {
|
|
|
72
92
|
if (channel.version) ref += `@${channel.version}`;
|
|
73
93
|
return ref;
|
|
74
94
|
}
|
|
75
|
-
function serializeMessagePointers(items, direction,
|
|
95
|
+
function serializeMessagePointers(items, direction, catalogDirOrIndex, indent = " ") {
|
|
76
96
|
const lines = [];
|
|
77
97
|
for (const item of items) {
|
|
78
|
-
const msgType = resolveMessageType(
|
|
98
|
+
const msgType = resolveMessageType(catalogDirOrIndex, item.id);
|
|
79
99
|
if (!msgType) continue;
|
|
80
100
|
let ref = `${item.id}`;
|
|
81
101
|
if (item.version) ref += `@${item.version}`;
|
|
@@ -107,6 +127,7 @@ ${body}
|
|
|
107
127
|
// src/dsl/service.ts
|
|
108
128
|
async function serviceToDSL(resource, options, getMessageFn) {
|
|
109
129
|
const { catalogDir, hydrate = false, _seen = /* @__PURE__ */ new Set() } = options;
|
|
130
|
+
const msgIndex = options._msgIndex || buildMessageTypeIndex(catalogDir);
|
|
110
131
|
const parts = [];
|
|
111
132
|
if (hydrate && getMessageFn) {
|
|
112
133
|
const allMessages = [...resource.sends || [], ...resource.receives || []];
|
|
@@ -114,7 +135,7 @@ async function serviceToDSL(resource, options, getMessageFn) {
|
|
|
114
135
|
const key = `${msg.id}@${msg.version || "latest"}`;
|
|
115
136
|
if (_seen.has(key)) continue;
|
|
116
137
|
_seen.add(key);
|
|
117
|
-
const msgType = resolveMessageType(
|
|
138
|
+
const msgType = resolveMessageType(msgIndex, msg.id);
|
|
118
139
|
if (!msgType) continue;
|
|
119
140
|
const msgResource = await getMessageFn(msg.id, msg.version);
|
|
120
141
|
if (msgResource) {
|
|
@@ -126,11 +147,11 @@ async function serviceToDSL(resource, options, getMessageFn) {
|
|
|
126
147
|
const baseFields = serializeBaseFields(resource);
|
|
127
148
|
if (baseFields) lines.push(baseFields);
|
|
128
149
|
if (resource.sends && resource.sends.length > 0) {
|
|
129
|
-
const sendsStr = serializeMessagePointers(resource.sends, "sends",
|
|
150
|
+
const sendsStr = serializeMessagePointers(resource.sends, "sends", msgIndex);
|
|
130
151
|
if (sendsStr) lines.push(sendsStr);
|
|
131
152
|
}
|
|
132
153
|
if (resource.receives && resource.receives.length > 0) {
|
|
133
|
-
const recvStr = serializeMessagePointers(resource.receives, "receives",
|
|
154
|
+
const recvStr = serializeMessagePointers(resource.receives, "receives", msgIndex);
|
|
134
155
|
if (recvStr) lines.push(recvStr);
|
|
135
156
|
}
|
|
136
157
|
if (resource.writesTo && resource.writesTo.length > 0) {
|
|
@@ -243,6 +264,7 @@ async function hydrateChannelsFromMessages(messages, resolvers, seen, parts) {
|
|
|
243
264
|
}
|
|
244
265
|
async function buildDomainBody(resource, options, resolvers, keyword) {
|
|
245
266
|
const { catalogDir, hydrate = false, _seen = /* @__PURE__ */ new Set() } = options;
|
|
267
|
+
const msgIndex = options._msgIndex || buildMessageTypeIndex(catalogDir);
|
|
246
268
|
const topLevelParts = [];
|
|
247
269
|
if (hydrate && resolvers) {
|
|
248
270
|
if (resource.services && resource.services.length > 0 && resolvers.getService) {
|
|
@@ -255,7 +277,7 @@ async function buildDomainBody(resource, options, resolvers, keyword) {
|
|
|
255
277
|
await hydrateOwners(svc.owners, resolvers, _seen, topLevelParts);
|
|
256
278
|
const svcMessages = [...svc.sends || [], ...svc.receives || []];
|
|
257
279
|
await hydrateChannelsFromMessages(svcMessages, resolvers, _seen, topLevelParts);
|
|
258
|
-
const svcDsl = await serviceToDSL(svc, { catalogDir, hydrate: true, _seen }, resolvers.getMessage);
|
|
280
|
+
const svcDsl = await serviceToDSL(svc, { catalogDir, hydrate: true, _seen, _msgIndex: msgIndex }, resolvers.getMessage);
|
|
259
281
|
topLevelParts.push(svcDsl);
|
|
260
282
|
}
|
|
261
283
|
}
|
|
@@ -267,7 +289,7 @@ async function buildDomainBody(resource, options, resolvers, keyword) {
|
|
|
267
289
|
const key = `${msg.id}@${msg.version || "latest"}`;
|
|
268
290
|
if (_seen.has(key)) continue;
|
|
269
291
|
_seen.add(key);
|
|
270
|
-
const msgType = resolveMessageType(
|
|
292
|
+
const msgType = resolveMessageType(msgIndex, msg.id);
|
|
271
293
|
if (!msgType) continue;
|
|
272
294
|
const msgResource = await resolvers.getMessage(msg.id, msg.version);
|
|
273
295
|
if (msgResource) {
|
|
@@ -287,11 +309,11 @@ async function buildDomainBody(resource, options, resolvers, keyword) {
|
|
|
287
309
|
}
|
|
288
310
|
}
|
|
289
311
|
if (resource.sends && resource.sends.length > 0) {
|
|
290
|
-
const sendsStr = serializeMessagePointers(resource.sends, "sends",
|
|
312
|
+
const sendsStr = serializeMessagePointers(resource.sends, "sends", msgIndex);
|
|
291
313
|
if (sendsStr) lines.push(sendsStr);
|
|
292
314
|
}
|
|
293
315
|
if (resource.receives && resource.receives.length > 0) {
|
|
294
|
-
const recvStr = serializeMessagePointers(resource.receives, "receives",
|
|
316
|
+
const recvStr = serializeMessagePointers(resource.receives, "receives", msgIndex);
|
|
295
317
|
if (recvStr) lines.push(recvStr);
|
|
296
318
|
}
|
|
297
319
|
if (resource.domains && resource.domains.length > 0) {
|
|
@@ -303,7 +325,12 @@ async function buildDomainBody(resource, options, resolvers, keyword) {
|
|
|
303
325
|
const subDomain = await resolvers.getDomain(subRef.id, subRef.version);
|
|
304
326
|
if (subDomain) {
|
|
305
327
|
await hydrateOwners(subDomain.owners, resolvers, _seen, topLevelParts);
|
|
306
|
-
const sub = await buildDomainBody(
|
|
328
|
+
const sub = await buildDomainBody(
|
|
329
|
+
subDomain,
|
|
330
|
+
{ catalogDir, hydrate, _seen, _msgIndex: msgIndex },
|
|
331
|
+
resolvers,
|
|
332
|
+
"subdomain"
|
|
333
|
+
);
|
|
307
334
|
topLevelParts.push(...sub.topLevelParts);
|
|
308
335
|
const indented = sub.block.split("\n").map((line) => ` ${line}`).join("\n");
|
|
309
336
|
lines.push(indented);
|
|
@@ -325,15 +352,16 @@ ${body}
|
|
|
325
352
|
}
|
|
326
353
|
async function domainToDSL(resource, options, resolvers) {
|
|
327
354
|
const { catalogDir, hydrate = false, _seen = /* @__PURE__ */ new Set() } = options;
|
|
328
|
-
const
|
|
355
|
+
const msgIndex = options._msgIndex || buildMessageTypeIndex(catalogDir);
|
|
356
|
+
const result = await buildDomainBody(resource, { catalogDir, hydrate, _seen, _msgIndex: msgIndex }, resolvers, "domain");
|
|
329
357
|
const parts = [...result.topLevelParts, result.block];
|
|
330
358
|
return parts.join("\n\n");
|
|
331
359
|
}
|
|
332
360
|
|
|
333
361
|
// src/dsl/index.ts
|
|
334
|
-
function getMessage(resolvers,
|
|
362
|
+
function getMessage(resolvers, msgIndex) {
|
|
335
363
|
return async (id, version) => {
|
|
336
|
-
const msgType = resolveMessageType(
|
|
364
|
+
const msgType = resolveMessageType(msgIndex, id);
|
|
337
365
|
if (!msgType) return void 0;
|
|
338
366
|
switch (msgType) {
|
|
339
367
|
case "event":
|
|
@@ -382,6 +410,7 @@ var toDSL = (catalogDir, resolvers) => async (resource, options) => {
|
|
|
382
410
|
const resources = Array.isArray(resource) ? resource : [resource];
|
|
383
411
|
const seen = /* @__PURE__ */ new Set();
|
|
384
412
|
const parts = [];
|
|
413
|
+
const msgIndex = buildMessageTypeIndex(catalogDir);
|
|
385
414
|
for (const res of resources) {
|
|
386
415
|
const key = `${options.type}:${res.id}@${res.version || "latest"}`;
|
|
387
416
|
if (seen.has(key)) continue;
|
|
@@ -403,8 +432,8 @@ var toDSL = (catalogDir, resolvers) => async (resource, options) => {
|
|
|
403
432
|
parts.push(
|
|
404
433
|
await serviceToDSL(
|
|
405
434
|
res,
|
|
406
|
-
{ catalogDir, hydrate: options.hydrate, _seen: seen },
|
|
407
|
-
getMessage(resolvers,
|
|
435
|
+
{ catalogDir, hydrate: options.hydrate, _seen: seen, _msgIndex: msgIndex },
|
|
436
|
+
getMessage(resolvers, msgIndex)
|
|
408
437
|
)
|
|
409
438
|
);
|
|
410
439
|
break;
|
|
@@ -415,11 +444,11 @@ var toDSL = (catalogDir, resolvers) => async (resource, options) => {
|
|
|
415
444
|
parts.push(
|
|
416
445
|
await domainToDSL(
|
|
417
446
|
res,
|
|
418
|
-
{ catalogDir, hydrate: options.hydrate, _seen: seen },
|
|
447
|
+
{ catalogDir, hydrate: options.hydrate, _seen: seen, _msgIndex: msgIndex },
|
|
419
448
|
{
|
|
420
449
|
getService: resolvers.getService,
|
|
421
450
|
getDomain: resolvers.getDomain,
|
|
422
|
-
getMessage: getMessage(resolvers,
|
|
451
|
+
getMessage: getMessage(resolvers, msgIndex),
|
|
423
452
|
getChannel: resolvers.getChannel,
|
|
424
453
|
getTeam: resolvers.getTeam,
|
|
425
454
|
getUser: resolvers.getUser
|
|
@@ -443,39 +472,96 @@ var import_fs_extra = require("fs-extra");
|
|
|
443
472
|
var import_node_path = require("path");
|
|
444
473
|
var import_gray_matter = __toESM(require("gray-matter"));
|
|
445
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
|
+
}
|
|
446
539
|
var versionExists = async (catalogDir, id, version) => {
|
|
447
|
-
|
|
448
|
-
const
|
|
449
|
-
|
|
540
|
+
ensureFileCache(catalogDir);
|
|
541
|
+
const entries = _fileIndexCache.get(id);
|
|
542
|
+
if (!entries) return false;
|
|
543
|
+
return entries.some((e) => e.version === version);
|
|
450
544
|
};
|
|
451
545
|
var findFileById = async (catalogDir, id, version) => {
|
|
452
|
-
|
|
453
|
-
const
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
});
|
|
462
|
-
if (version === "latest") {
|
|
463
|
-
return latestVersion;
|
|
464
|
-
}
|
|
465
|
-
const exactMatch = parsedFiles.find((c) => c.version === version);
|
|
466
|
-
if (exactMatch) {
|
|
467
|
-
return exactMatch.path;
|
|
468
|
-
}
|
|
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;
|
|
552
|
+
}
|
|
553
|
+
const exactMatch = entries.find((e) => e.version === version);
|
|
554
|
+
if (exactMatch) return exactMatch.path;
|
|
469
555
|
const semverRange = (0, import_semver.validRange)(version);
|
|
470
556
|
if (semverRange) {
|
|
471
|
-
const match =
|
|
557
|
+
const match = entries.find((e) => {
|
|
472
558
|
try {
|
|
473
|
-
return (0, import_semver.satisfies)(
|
|
474
|
-
} catch
|
|
559
|
+
return (0, import_semver.satisfies)(e.version, semverRange);
|
|
560
|
+
} catch {
|
|
475
561
|
return false;
|
|
476
562
|
}
|
|
477
563
|
});
|
|
478
|
-
return match
|
|
564
|
+
return match?.path;
|
|
479
565
|
}
|
|
480
566
|
return void 0;
|
|
481
567
|
};
|
|
@@ -591,6 +677,7 @@ var versionResource = async (catalogDir, id) => {
|
|
|
591
677
|
})
|
|
592
678
|
);
|
|
593
679
|
});
|
|
680
|
+
invalidateFileCache();
|
|
594
681
|
};
|
|
595
682
|
var writeResource = async (catalogDir, resource, options = {
|
|
596
683
|
path: "",
|
|
@@ -630,6 +717,7 @@ var writeResource = async (catalogDir, resource, options = {
|
|
|
630
717
|
}
|
|
631
718
|
const document = import_gray_matter2.default.stringify(markdown.trim(), frontmatter);
|
|
632
719
|
import_node_fs2.default.writeFileSync(lockPath, document);
|
|
720
|
+
invalidateFileCache();
|
|
633
721
|
} finally {
|
|
634
722
|
await (0, import_proper_lockfile.unlock)(lockPath).catch(() => {
|
|
635
723
|
});
|
|
@@ -639,7 +727,7 @@ var getResource = async (catalogDir, id, version, options, filePath) => {
|
|
|
639
727
|
const attachSchema = options?.attachSchema || false;
|
|
640
728
|
const file = filePath || (id ? await findFileById(catalogDir, id, version) : void 0);
|
|
641
729
|
if (!file || !import_node_fs2.default.existsSync(file)) return;
|
|
642
|
-
const { data, content } =
|
|
730
|
+
const { data, content } = cachedMatterRead(file);
|
|
643
731
|
if (attachSchema && data?.schemaPath) {
|
|
644
732
|
const resourceDirectory = (0, import_path.dirname)(file);
|
|
645
733
|
const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
|
|
@@ -690,7 +778,7 @@ var getResources = async (catalogDir, {
|
|
|
690
778
|
const files = await getFiles(filePattern, [ignoreList, ...ignore]);
|
|
691
779
|
if (files.length === 0) return;
|
|
692
780
|
return files.map((file) => {
|
|
693
|
-
const { data, content } =
|
|
781
|
+
const { data, content } = cachedMatterRead(file);
|
|
694
782
|
if (attachSchema && data?.schemaPath) {
|
|
695
783
|
const resourceDirectory = (0, import_path.dirname)(file);
|
|
696
784
|
const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
|
|
@@ -731,6 +819,7 @@ var rmResourceById = async (catalogDir, id, version, options) => {
|
|
|
731
819
|
})
|
|
732
820
|
);
|
|
733
821
|
}
|
|
822
|
+
invalidateFileCache();
|
|
734
823
|
};
|
|
735
824
|
var waitForFileRemoval = async (path6, maxRetries = 50, delay = 10) => {
|
|
736
825
|
for (let i = 0; i < maxRetries; i++) {
|
|
@@ -796,6 +885,7 @@ var writeEventToService = (directory) => async (event, service, options = { path
|
|
|
796
885
|
};
|
|
797
886
|
var rmEvent = (directory) => async (path6) => {
|
|
798
887
|
await import_promises2.default.rm((0, import_node_path4.join)(directory, path6), { recursive: true });
|
|
888
|
+
invalidateFileCache();
|
|
799
889
|
};
|
|
800
890
|
var rmEventById = (directory) => async (id, version, persistFiles) => {
|
|
801
891
|
await rmResourceById(directory, id, version, { type: "event", persistFiles });
|
|
@@ -832,6 +922,7 @@ var writeCommandToService = (directory) => async (command, service, options = {
|
|
|
832
922
|
};
|
|
833
923
|
var rmCommand = (directory) => async (path6) => {
|
|
834
924
|
await import_promises3.default.rm((0, import_node_path5.join)(directory, path6), { recursive: true });
|
|
925
|
+
invalidateFileCache();
|
|
835
926
|
};
|
|
836
927
|
var rmCommandById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "command", persistFiles });
|
|
837
928
|
var versionCommand = (directory) => async (id) => versionResource(directory, id);
|
|
@@ -866,6 +957,7 @@ var writeQueryToService = (directory) => async (query, service, options = { path
|
|
|
866
957
|
};
|
|
867
958
|
var rmQuery = (directory) => async (path6) => {
|
|
868
959
|
await import_promises4.default.rm((0, import_node_path6.join)(directory, path6), { recursive: true });
|
|
960
|
+
invalidateFileCache();
|
|
869
961
|
};
|
|
870
962
|
var rmQueryById = (directory) => async (id, version, persistFiles) => {
|
|
871
963
|
await rmResourceById(directory, id, version, { type: "query", persistFiles });
|
|
@@ -931,6 +1023,7 @@ var writeServiceToDomain = (directory) => async (service, domain, options = { pa
|
|
|
931
1023
|
var versionService = (directory) => async (id) => versionResource(directory, id);
|
|
932
1024
|
var rmService = (directory) => async (path6) => {
|
|
933
1025
|
await import_promises5.default.rm((0, import_node_path7.join)(directory, path6), { recursive: true });
|
|
1026
|
+
invalidateFileCache();
|
|
934
1027
|
};
|
|
935
1028
|
var rmServiceById = (directory) => async (id, version, persistFiles) => {
|
|
936
1029
|
await rmResourceById(directory, id, version, { type: "service", persistFiles });
|
|
@@ -1107,6 +1200,7 @@ var writeDomain = (directory) => async (domain, options = {
|
|
|
1107
1200
|
var versionDomain = (directory) => async (id) => versionResource(directory, id);
|
|
1108
1201
|
var rmDomain = (directory) => async (path6) => {
|
|
1109
1202
|
await import_promises6.default.rm((0, import_node_path8.join)(directory, path6), { recursive: true });
|
|
1203
|
+
invalidateFileCache();
|
|
1110
1204
|
};
|
|
1111
1205
|
var rmDomainById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "domain", persistFiles });
|
|
1112
1206
|
var addFileToDomain = (directory) => async (id, file, version) => addFileToResource(directory, id, file, version);
|
|
@@ -1238,6 +1332,7 @@ var getChannels = (directory) => async (options) => getResources(directory, { ty
|
|
|
1238
1332
|
var writeChannel = (directory) => async (channel, options = { path: "" }) => writeResource(directory, { ...channel }, { ...options, type: "channel" });
|
|
1239
1333
|
var rmChannel = (directory) => async (path6) => {
|
|
1240
1334
|
await import_promises7.default.rm((0, import_node_path9.join)(directory, path6), { recursive: true });
|
|
1335
|
+
invalidateFileCache();
|
|
1241
1336
|
};
|
|
1242
1337
|
var rmChannelById = (directory) => async (id, version, persistFiles) => rmResourceById(directory, id, version, { type: "channel", persistFiles });
|
|
1243
1338
|
var versionChannel = (directory) => async (id) => versionResource(directory, id);
|
|
@@ -1410,10 +1505,12 @@ var writeCustomDoc = (directory) => async (customDoc, options = { path: "" }) =>
|
|
|
1410
1505
|
import_node_fs4.default.mkdirSync(import_node_path11.default.dirname(fullPath), { recursive: true });
|
|
1411
1506
|
const document = import_gray_matter5.default.stringify(customDoc.markdown.trim(), rest);
|
|
1412
1507
|
import_node_fs4.default.writeFileSync(fullPath, document);
|
|
1508
|
+
invalidateFileCache();
|
|
1413
1509
|
};
|
|
1414
1510
|
var rmCustomDoc = (directory) => async (filePath) => {
|
|
1415
1511
|
const withExtension = filePath.endsWith(".mdx") ? filePath : `${filePath}.mdx`;
|
|
1416
1512
|
await import_promises8.default.rm((0, import_node_path11.join)(directory, withExtension), { recursive: true });
|
|
1513
|
+
invalidateFileCache();
|
|
1417
1514
|
};
|
|
1418
1515
|
|
|
1419
1516
|
// src/teams.ts
|
|
@@ -1465,9 +1562,11 @@ var writeUser = (catalogDir) => async (user, options = {}) => {
|
|
|
1465
1562
|
const document = import_gray_matter6.default.stringify(markdown, frontmatter);
|
|
1466
1563
|
import_node_fs5.default.mkdirSync((0, import_node_path12.join)(catalogDir, ""), { recursive: true });
|
|
1467
1564
|
import_node_fs5.default.writeFileSync((0, import_node_path12.join)(catalogDir, "", `${resource.id}.mdx`), document);
|
|
1565
|
+
invalidateFileCache();
|
|
1468
1566
|
};
|
|
1469
1567
|
var rmUserById = (catalogDir) => async (id) => {
|
|
1470
1568
|
import_node_fs5.default.rmSync((0, import_node_path12.join)(catalogDir, `${id}.mdx`), { recursive: true });
|
|
1569
|
+
invalidateFileCache();
|
|
1471
1570
|
};
|
|
1472
1571
|
|
|
1473
1572
|
// src/teams.ts
|
|
@@ -1507,9 +1606,11 @@ var writeTeam = (catalogDir) => async (team, options = {}) => {
|
|
|
1507
1606
|
const document = import_gray_matter7.default.stringify(markdown, frontmatter);
|
|
1508
1607
|
import_node_fs6.default.mkdirSync((0, import_node_path13.join)(catalogDir, ""), { recursive: true });
|
|
1509
1608
|
import_node_fs6.default.writeFileSync((0, import_node_path13.join)(catalogDir, "", `${resource.id}.mdx`), document);
|
|
1609
|
+
invalidateFileCache();
|
|
1510
1610
|
};
|
|
1511
1611
|
var rmTeamById = (catalogDir) => async (id) => {
|
|
1512
1612
|
await import_promises9.default.rm((0, import_node_path13.join)(catalogDir, `${id}.mdx`), { recursive: true });
|
|
1613
|
+
invalidateFileCache();
|
|
1513
1614
|
};
|
|
1514
1615
|
var getOwnersForResource = (catalogDir) => async (id, version) => {
|
|
1515
1616
|
const resource = await getResource(catalogDir, id, version);
|
|
@@ -1639,6 +1740,7 @@ var writeEntity = (directory) => async (entity, options = {
|
|
|
1639
1740
|
}) => writeResource(directory, { ...entity }, { ...options, type: "entity" });
|
|
1640
1741
|
var rmEntity = (directory) => async (path6) => {
|
|
1641
1742
|
await import_promises10.default.rm((0, import_node_path16.join)(directory, path6), { recursive: true });
|
|
1743
|
+
invalidateFileCache();
|
|
1642
1744
|
};
|
|
1643
1745
|
var rmEntityById = (directory) => async (id, version, persistFiles) => {
|
|
1644
1746
|
await rmResourceById(directory, id, version, { type: "entity", persistFiles });
|
|
@@ -1662,6 +1764,7 @@ var writeContainer = (directory) => async (data, options = {
|
|
|
1662
1764
|
var versionContainer = (directory) => async (id) => versionResource(directory, id);
|
|
1663
1765
|
var rmContainer = (directory) => async (path6) => {
|
|
1664
1766
|
await import_promises11.default.rm((0, import_node_path17.join)(directory, path6), { recursive: true });
|
|
1767
|
+
invalidateFileCache();
|
|
1665
1768
|
};
|
|
1666
1769
|
var rmContainerById = (directory) => async (id, version, persistFiles) => {
|
|
1667
1770
|
await rmResourceById(directory, id, version, { type: "container", persistFiles });
|
|
@@ -1709,6 +1812,7 @@ var writeDataProductToDomain = (directory) => async (dataProduct, domain, option
|
|
|
1709
1812
|
};
|
|
1710
1813
|
var rmDataProduct = (directory) => async (path6) => {
|
|
1711
1814
|
await import_promises12.default.rm((0, import_node_path18.join)(directory, path6), { recursive: true });
|
|
1815
|
+
invalidateFileCache();
|
|
1712
1816
|
};
|
|
1713
1817
|
var rmDataProductById = (directory) => async (id, version, persistFiles) => {
|
|
1714
1818
|
await rmResourceById(directory, id, version, { type: "data-product", persistFiles });
|
|
@@ -1732,6 +1836,7 @@ var writeDiagram = (directory) => async (diagram, options = {
|
|
|
1732
1836
|
}) => writeResource(directory, { ...diagram }, { ...options, type: "diagram" });
|
|
1733
1837
|
var rmDiagram = (directory) => async (path6) => {
|
|
1734
1838
|
await import_promises13.default.rm((0, import_node_path19.join)(directory, path6), { recursive: true });
|
|
1839
|
+
invalidateFileCache();
|
|
1735
1840
|
};
|
|
1736
1841
|
var rmDiagramById = (directory) => async (id, version, persistFiles) => {
|
|
1737
1842
|
await rmResourceById(directory, id, version, { type: "diagram", persistFiles });
|