@eventcatalog/sdk 2.3.7 → 2.5.0
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/channels.js +30 -4
- package/dist/channels.js.map +1 -1
- package/dist/channels.mjs +44 -12
- package/dist/channels.mjs.map +1 -1
- package/dist/commands.d.mts +10 -1
- package/dist/commands.d.ts +10 -1
- package/dist/commands.js +28 -2
- package/dist/commands.js.map +1 -1
- package/dist/commands.mjs +34 -8
- package/dist/commands.mjs.map +1 -1
- package/dist/custom-docs.js +15 -1
- package/dist/custom-docs.js.map +1 -1
- package/dist/custom-docs.mjs +26 -9
- package/dist/custom-docs.mjs.map +1 -1
- package/dist/domains.js +27 -1
- package/dist/domains.js.map +1 -1
- package/dist/domains.mjs +34 -8
- package/dist/domains.mjs.map +1 -1
- package/dist/eventcatalog.js +30 -4
- package/dist/eventcatalog.js.map +1 -1
- package/dist/eventcatalog.mjs +57 -31
- package/dist/eventcatalog.mjs.map +1 -1
- package/dist/events.d.mts +10 -1
- package/dist/events.d.ts +10 -1
- package/dist/events.js +28 -2
- package/dist/events.js.map +1 -1
- package/dist/events.mjs +34 -8
- package/dist/events.mjs.map +1 -1
- package/dist/index.d.mts +20 -5
- package/dist/index.d.ts +20 -5
- package/dist/index.js +130 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +153 -127
- package/dist/index.mjs.map +1 -1
- package/dist/queries.d.mts +10 -1
- package/dist/queries.d.ts +10 -1
- package/dist/queries.js +28 -2
- package/dist/queries.js.map +1 -1
- package/dist/queries.mjs +34 -8
- package/dist/queries.mjs.map +1 -1
- package/dist/services.js +27 -1
- package/dist/services.js.map +1 -1
- package/dist/services.mjs +33 -7
- package/dist/services.mjs.map +1 -1
- package/dist/teams.mjs +7 -6
- package/dist/teams.mjs.map +1 -1
- package/dist/types.d.d.mts +13 -1
- package/dist/types.d.d.ts +13 -1
- package/dist/types.d.js.map +1 -1
- package/dist/users.mjs +7 -6
- package/dist/users.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EventCatalogObject } from './eventcatalog.js';
|
|
2
2
|
import { Event, Command, Query, Channel, Service, Domain, UbiquitousLanguageDictionary, Team, User, CustomDoc } from './types.d.js';
|
|
3
|
+
export { Badge, BaseSchema, ChannelPointer, Message, ResourceGroup, ResourcePointer, Specifications, UbiquitousLanguage } from './types.d.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Init the SDK for EventCatalog
|
|
@@ -14,7 +15,9 @@ declare const _default: (path: string) => {
|
|
|
14
15
|
* @param version - Optional id of the version to get (supports semver)
|
|
15
16
|
* @returns Event|Undefined
|
|
16
17
|
*/
|
|
17
|
-
getEvent: (id: string, version?: string
|
|
18
|
+
getEvent: (id: string, version?: string, options?: {
|
|
19
|
+
attachSchema?: boolean;
|
|
20
|
+
}) => Promise<Event>;
|
|
18
21
|
/**
|
|
19
22
|
* Returns all events from EventCatalog
|
|
20
23
|
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
@@ -22,6 +25,7 @@ declare const _default: (path: string) => {
|
|
|
22
25
|
*/
|
|
23
26
|
getEvents: (options?: {
|
|
24
27
|
latestOnly?: boolean;
|
|
28
|
+
attachSchema?: boolean;
|
|
25
29
|
}) => Promise<Event[]>;
|
|
26
30
|
/**
|
|
27
31
|
* Adds an event to EventCatalog
|
|
@@ -111,7 +115,9 @@ declare const _default: (path: string) => {
|
|
|
111
115
|
* @param version - Optional id of the version to get (supports semver)
|
|
112
116
|
* @returns Command|Undefined
|
|
113
117
|
*/
|
|
114
|
-
getCommand: (id: string, version?: string
|
|
118
|
+
getCommand: (id: string, version?: string, options?: {
|
|
119
|
+
attachSchema?: boolean;
|
|
120
|
+
}) => Promise<Command>;
|
|
115
121
|
/**
|
|
116
122
|
* Returns all commands from EventCatalog
|
|
117
123
|
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
@@ -119,6 +125,7 @@ declare const _default: (path: string) => {
|
|
|
119
125
|
*/
|
|
120
126
|
getCommands: (options?: {
|
|
121
127
|
latestOnly?: boolean;
|
|
128
|
+
attachSchema?: boolean;
|
|
122
129
|
}) => Promise<Command[]>;
|
|
123
130
|
/**
|
|
124
131
|
* Adds an command to EventCatalog
|
|
@@ -208,7 +215,9 @@ declare const _default: (path: string) => {
|
|
|
208
215
|
* @param version - Optional id of the version to get (supports semver)
|
|
209
216
|
* @returns Query|Undefined
|
|
210
217
|
*/
|
|
211
|
-
getQuery: (id: string, version?: string
|
|
218
|
+
getQuery: (id: string, version?: string, options?: {
|
|
219
|
+
attachSchema?: boolean;
|
|
220
|
+
}) => Promise<Query>;
|
|
212
221
|
/**
|
|
213
222
|
* Returns all queries from EventCatalog
|
|
214
223
|
* @param latestOnly - optional boolean, set to true to get only latest versions
|
|
@@ -216,6 +225,7 @@ declare const _default: (path: string) => {
|
|
|
216
225
|
*/
|
|
217
226
|
getQueries: (options?: {
|
|
218
227
|
latestOnly?: boolean;
|
|
228
|
+
attachSchema?: boolean;
|
|
219
229
|
}) => Promise<Query[]>;
|
|
220
230
|
/**
|
|
221
231
|
* Adds a query to EventCatalog
|
|
@@ -240,7 +250,12 @@ declare const _default: (path: string) => {
|
|
|
240
250
|
*/
|
|
241
251
|
writeQueryToService: (query: Query, service: {
|
|
242
252
|
id: string;
|
|
243
|
-
version
|
|
253
|
+
version? /**
|
|
254
|
+
* Returns a command from EventCatalog
|
|
255
|
+
* @param id - The id of the command to retrieve
|
|
256
|
+
* @param version - Optional id of the version to get (supports semver)
|
|
257
|
+
* @returns Command|Undefined
|
|
258
|
+
*/: string;
|
|
244
259
|
}, options?: {
|
|
245
260
|
path?: string;
|
|
246
261
|
format?: "md" | "mdx";
|
|
@@ -823,4 +838,4 @@ declare const _default: (path: string) => {
|
|
|
823
838
|
} | undefined>;
|
|
824
839
|
};
|
|
825
840
|
|
|
826
|
-
export { _default as default };
|
|
841
|
+
export { Channel, Command, CustomDoc, Domain, Event, Query, Service, Team, UbiquitousLanguageDictionary, User, _default as default };
|
package/dist/index.js
CHANGED
|
@@ -221,9 +221,22 @@ var writeResource = async (catalogDir, resource, options = {
|
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
223
|
var getResource = async (catalogDir, id, version, options) => {
|
|
224
|
+
const attachSchema = options?.attachSchema || false;
|
|
224
225
|
const file = await findFileById(catalogDir, id, version);
|
|
225
226
|
if (!file) return;
|
|
226
227
|
const { data, content } = import_gray_matter2.default.read(file);
|
|
228
|
+
if (attachSchema && data?.schemaPath) {
|
|
229
|
+
const resourceDirectory = (0, import_path.dirname)(file);
|
|
230
|
+
const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
|
|
231
|
+
if (import_node_fs2.default.existsSync(pathToSchema)) {
|
|
232
|
+
const schema = import_node_fs2.default.readFileSync(pathToSchema, "utf8");
|
|
233
|
+
try {
|
|
234
|
+
data.schema = JSON.parse(schema);
|
|
235
|
+
} catch (error) {
|
|
236
|
+
data.schema = schema;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
227
240
|
return {
|
|
228
241
|
...data,
|
|
229
242
|
markdown: content.trim()
|
|
@@ -242,7 +255,8 @@ var getResources = async (catalogDir, {
|
|
|
242
255
|
type,
|
|
243
256
|
latestOnly = false,
|
|
244
257
|
ignore = [],
|
|
245
|
-
pattern = ""
|
|
258
|
+
pattern = "",
|
|
259
|
+
attachSchema = false
|
|
246
260
|
}) => {
|
|
247
261
|
const ignoreList = latestOnly ? `**/versioned/**` : "";
|
|
248
262
|
const filePattern = pattern || `${catalogDir}/**/${type}/**/index.{md,mdx}`;
|
|
@@ -250,6 +264,18 @@ var getResources = async (catalogDir, {
|
|
|
250
264
|
if (files.length === 0) return;
|
|
251
265
|
return files.map((file) => {
|
|
252
266
|
const { data, content } = import_gray_matter2.default.read(file);
|
|
267
|
+
if (attachSchema && data?.schemaPath) {
|
|
268
|
+
const resourceDirectory = (0, import_path.dirname)(file);
|
|
269
|
+
const pathToSchema = (0, import_path.join)(resourceDirectory, data.schemaPath);
|
|
270
|
+
if (import_node_fs2.default.existsSync(pathToSchema)) {
|
|
271
|
+
const schema = import_node_fs2.default.readFileSync(pathToSchema, "utf8");
|
|
272
|
+
try {
|
|
273
|
+
data.schema = JSON.parse(schema);
|
|
274
|
+
} catch (error) {
|
|
275
|
+
data.schema = schema;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
253
279
|
return {
|
|
254
280
|
...data,
|
|
255
281
|
markdown: content.trim()
|
|
@@ -300,7 +326,7 @@ var getVersionedDirectory = (sourceDirectory, version) => {
|
|
|
300
326
|
};
|
|
301
327
|
|
|
302
328
|
// src/events.ts
|
|
303
|
-
var getEvent = (directory) => async (id, version) => getResource(directory, id, version, { type: "event" });
|
|
329
|
+
var getEvent = (directory) => async (id, version, options) => getResource(directory, id, version, { type: "event", ...options });
|
|
304
330
|
var getEvents = (directory) => async (options) => getResources(directory, { type: "events", ...options });
|
|
305
331
|
var writeEvent = (directory) => async (event, options = {
|
|
306
332
|
path: "",
|
|
@@ -335,7 +361,7 @@ var eventHasVersion = (directory) => async (id, version) => {
|
|
|
335
361
|
// src/commands.ts
|
|
336
362
|
var import_promises3 = __toESM(require("fs/promises"));
|
|
337
363
|
var import_node_path3 = require("path");
|
|
338
|
-
var getCommand = (directory) => async (id, version) => getResource(directory, id, version, { type: "command" });
|
|
364
|
+
var getCommand = (directory) => async (id, version, options) => getResource(directory, id, version, { type: "command", ...options });
|
|
339
365
|
var getCommands = (directory) => async (options) => getResources(directory, { type: "commands", ...options });
|
|
340
366
|
var writeCommand = (directory) => async (command, options = {
|
|
341
367
|
path: "",
|
|
@@ -369,7 +395,7 @@ var commandHasVersion = (directory) => async (id, version) => {
|
|
|
369
395
|
// src/queries.ts
|
|
370
396
|
var import_promises4 = __toESM(require("fs/promises"));
|
|
371
397
|
var import_node_path4 = require("path");
|
|
372
|
-
var getQuery = (directory) => async (id, version) => getResource(directory, id, version, { type: "query" });
|
|
398
|
+
var getQuery = (directory) => async (id, version, options) => getResource(directory, id, version, { type: "query", ...options });
|
|
373
399
|
var writeQuery = (directory) => async (query, options = {
|
|
374
400
|
path: "",
|
|
375
401
|
override: false,
|
|
@@ -639,101 +665,14 @@ var addMessageToChannel = (directory, collection) => async (id, _message, versio
|
|
|
639
665
|
await writeMessage(pathToResource)(message, { format: extension === ".md" ? "md" : "mdx" });
|
|
640
666
|
};
|
|
641
667
|
|
|
642
|
-
// src/eventcatalog.ts
|
|
643
|
-
var import_fs = __toESM(require("fs"));
|
|
644
|
-
var import_node_path8 = __toESM(require("path"));
|
|
645
|
-
var DUMP_VERSION = "0.0.1";
|
|
646
|
-
var getEventCatalogVersion = async (catalogDir) => {
|
|
647
|
-
try {
|
|
648
|
-
const packageJson = import_fs.default.readFileSync((0, import_node_path8.join)(catalogDir, "package.json"), "utf8");
|
|
649
|
-
const packageJsonObject = JSON.parse(packageJson);
|
|
650
|
-
return packageJsonObject["dependencies"]["@eventcatalog/core"];
|
|
651
|
-
} catch (error) {
|
|
652
|
-
return "unknown";
|
|
653
|
-
}
|
|
654
|
-
};
|
|
655
|
-
var hydrateResource = async (catalogDir, resources, { attachSchema = false } = {}) => {
|
|
656
|
-
return await Promise.all(
|
|
657
|
-
resources.map(async (resource) => {
|
|
658
|
-
const resourcePath = await getResourcePath(catalogDir, resource.id, resource.version);
|
|
659
|
-
let schema = "";
|
|
660
|
-
if (resource.schemaPath && resourcePath?.fullPath) {
|
|
661
|
-
const pathToSchema = import_node_path8.default.join(import_node_path8.default.dirname(resourcePath?.fullPath), resource.schemaPath);
|
|
662
|
-
if (import_fs.default.existsSync(pathToSchema)) {
|
|
663
|
-
schema = import_fs.default.readFileSync(pathToSchema, "utf8");
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
const eventcatalog = schema ? { directory: resourcePath?.directory, schema } : { directory: resourcePath?.directory };
|
|
667
|
-
return {
|
|
668
|
-
...resource,
|
|
669
|
-
_eventcatalog: eventcatalog
|
|
670
|
-
};
|
|
671
|
-
})
|
|
672
|
-
);
|
|
673
|
-
};
|
|
674
|
-
var filterCollection = (collection, options) => {
|
|
675
|
-
return collection.map((item) => ({
|
|
676
|
-
...item,
|
|
677
|
-
markdown: options?.includeMarkdown ? item.markdown : void 0
|
|
678
|
-
}));
|
|
679
|
-
};
|
|
680
|
-
var dumpCatalog = (directory) => async (options) => {
|
|
681
|
-
const { getDomains: getDomains2, getServices: getServices2, getEvents: getEvents2, getQueries: getQueries2, getCommands: getCommands2, getChannels: getChannels2, getTeams: getTeams2, getUsers: getUsers2 } = index_default(directory);
|
|
682
|
-
const { includeMarkdown = true } = options || {};
|
|
683
|
-
const domains = await getDomains2();
|
|
684
|
-
const services = await getServices2();
|
|
685
|
-
const events = await getEvents2();
|
|
686
|
-
const commands = await getCommands2();
|
|
687
|
-
const queries = await getQueries2();
|
|
688
|
-
const teams = await getTeams2();
|
|
689
|
-
const users = await getUsers2();
|
|
690
|
-
const channels = await getChannels2();
|
|
691
|
-
const [
|
|
692
|
-
hydratedDomains,
|
|
693
|
-
hydratedServices,
|
|
694
|
-
hydratedEvents,
|
|
695
|
-
hydratedQueries,
|
|
696
|
-
hydratedCommands,
|
|
697
|
-
hydratedTeams,
|
|
698
|
-
hydratedUsers,
|
|
699
|
-
hydratedChannels
|
|
700
|
-
] = await Promise.all([
|
|
701
|
-
hydrateResource(directory, domains),
|
|
702
|
-
hydrateResource(directory, services),
|
|
703
|
-
hydrateResource(directory, events),
|
|
704
|
-
hydrateResource(directory, queries),
|
|
705
|
-
hydrateResource(directory, commands),
|
|
706
|
-
hydrateResource(directory, teams),
|
|
707
|
-
hydrateResource(directory, users),
|
|
708
|
-
hydrateResource(directory, channels)
|
|
709
|
-
]);
|
|
710
|
-
return {
|
|
711
|
-
version: DUMP_VERSION,
|
|
712
|
-
catalogVersion: await getEventCatalogVersion(directory),
|
|
713
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
714
|
-
resources: {
|
|
715
|
-
domains: filterCollection(hydratedDomains, { includeMarkdown }),
|
|
716
|
-
services: filterCollection(hydratedServices, { includeMarkdown }),
|
|
717
|
-
messages: {
|
|
718
|
-
events: filterCollection(hydratedEvents, { includeMarkdown }),
|
|
719
|
-
queries: filterCollection(hydratedQueries, { includeMarkdown }),
|
|
720
|
-
commands: filterCollection(hydratedCommands, { includeMarkdown })
|
|
721
|
-
},
|
|
722
|
-
teams: filterCollection(hydratedTeams, { includeMarkdown }),
|
|
723
|
-
users: filterCollection(hydratedUsers, { includeMarkdown }),
|
|
724
|
-
channels: filterCollection(hydratedChannels, { includeMarkdown })
|
|
725
|
-
}
|
|
726
|
-
};
|
|
727
|
-
};
|
|
728
|
-
|
|
729
668
|
// src/custom-docs.ts
|
|
730
|
-
var
|
|
669
|
+
var import_node_path8 = __toESM(require("path"));
|
|
731
670
|
var import_node_fs4 = __toESM(require("fs"));
|
|
732
671
|
var import_promises8 = __toESM(require("fs/promises"));
|
|
733
672
|
var import_gray_matter4 = __toESM(require("gray-matter"));
|
|
734
673
|
var import_slugify = __toESM(require("slugify"));
|
|
735
674
|
var getCustomDoc = (directory) => async (filePath) => {
|
|
736
|
-
const fullPath =
|
|
675
|
+
const fullPath = import_node_path8.default.join(directory, filePath);
|
|
737
676
|
const fullPathWithExtension = fullPath.endsWith(".mdx") ? fullPath : `${fullPath}.mdx`;
|
|
738
677
|
const fileExists = import_node_fs4.default.existsSync(fullPathWithExtension);
|
|
739
678
|
if (!fileExists) {
|
|
@@ -752,20 +691,20 @@ var writeCustomDoc = (directory) => async (customDoc, options = { path: "" }) =>
|
|
|
752
691
|
const { fileName, ...rest } = customDoc;
|
|
753
692
|
const name = fileName || (0, import_slugify.default)(customDoc.title, { lower: true });
|
|
754
693
|
const withExtension = name.endsWith(".mdx") ? name : `${name}.mdx`;
|
|
755
|
-
const fullPath =
|
|
756
|
-
import_node_fs4.default.mkdirSync(
|
|
694
|
+
const fullPath = import_node_path8.default.join(directory, options.path || "", withExtension);
|
|
695
|
+
import_node_fs4.default.mkdirSync(import_node_path8.default.dirname(fullPath), { recursive: true });
|
|
757
696
|
const document = import_gray_matter4.default.stringify(customDoc.markdown.trim(), rest);
|
|
758
697
|
import_node_fs4.default.writeFileSync(fullPath, document);
|
|
759
698
|
};
|
|
760
699
|
var rmCustomDoc = (directory) => async (filePath) => {
|
|
761
700
|
const withExtension = filePath.endsWith(".mdx") ? filePath : `${filePath}.mdx`;
|
|
762
|
-
await import_promises8.default.rm((0,
|
|
701
|
+
await import_promises8.default.rm((0, import_node_path8.join)(directory, withExtension), { recursive: true });
|
|
763
702
|
};
|
|
764
703
|
|
|
765
704
|
// src/teams.ts
|
|
766
705
|
var import_promises9 = __toESM(require("fs/promises"));
|
|
767
706
|
var import_node_fs5 = __toESM(require("fs"));
|
|
768
|
-
var
|
|
707
|
+
var import_node_path9 = require("path");
|
|
769
708
|
var import_gray_matter5 = __toESM(require("gray-matter"));
|
|
770
709
|
var getTeam = (catalogDir) => async (id) => {
|
|
771
710
|
const files = await getFiles(`${catalogDir}/${id}.{md,mdx}`);
|
|
@@ -801,16 +740,16 @@ var writeTeam = (catalogDir) => async (team, options = {}) => {
|
|
|
801
740
|
}
|
|
802
741
|
const { markdown, ...frontmatter } = resource;
|
|
803
742
|
const document = import_gray_matter5.default.stringify(markdown, frontmatter);
|
|
804
|
-
import_node_fs5.default.mkdirSync((0,
|
|
805
|
-
import_node_fs5.default.writeFileSync((0,
|
|
743
|
+
import_node_fs5.default.mkdirSync((0, import_node_path9.join)(catalogDir, ""), { recursive: true });
|
|
744
|
+
import_node_fs5.default.writeFileSync((0, import_node_path9.join)(catalogDir, "", `${resource.id}.mdx`), document);
|
|
806
745
|
};
|
|
807
746
|
var rmTeamById = (catalogDir) => async (id) => {
|
|
808
|
-
await import_promises9.default.rm((0,
|
|
747
|
+
await import_promises9.default.rm((0, import_node_path9.join)(catalogDir, `${id}.mdx`), { recursive: true });
|
|
809
748
|
};
|
|
810
749
|
|
|
811
750
|
// src/users.ts
|
|
812
751
|
var import_node_fs6 = __toESM(require("fs"));
|
|
813
|
-
var
|
|
752
|
+
var import_node_path10 = require("path");
|
|
814
753
|
var import_gray_matter6 = __toESM(require("gray-matter"));
|
|
815
754
|
var getUser = (catalogDir) => async (id) => {
|
|
816
755
|
const files = await getFiles(`${catalogDir}/${id}.{md,mdx}`);
|
|
@@ -848,11 +787,98 @@ var writeUser = (catalogDir) => async (user, options = {}) => {
|
|
|
848
787
|
}
|
|
849
788
|
const { markdown, ...frontmatter } = resource;
|
|
850
789
|
const document = import_gray_matter6.default.stringify(markdown, frontmatter);
|
|
851
|
-
import_node_fs6.default.mkdirSync((0,
|
|
852
|
-
import_node_fs6.default.writeFileSync((0,
|
|
790
|
+
import_node_fs6.default.mkdirSync((0, import_node_path10.join)(catalogDir, ""), { recursive: true });
|
|
791
|
+
import_node_fs6.default.writeFileSync((0, import_node_path10.join)(catalogDir, "", `${resource.id}.mdx`), document);
|
|
853
792
|
};
|
|
854
793
|
var rmUserById = (catalogDir) => async (id) => {
|
|
855
|
-
import_node_fs6.default.rmSync((0,
|
|
794
|
+
import_node_fs6.default.rmSync((0, import_node_path10.join)(catalogDir, `${id}.mdx`), { recursive: true });
|
|
795
|
+
};
|
|
796
|
+
|
|
797
|
+
// src/eventcatalog.ts
|
|
798
|
+
var import_fs = __toESM(require("fs"));
|
|
799
|
+
var import_node_path11 = __toESM(require("path"));
|
|
800
|
+
var DUMP_VERSION = "0.0.1";
|
|
801
|
+
var getEventCatalogVersion = async (catalogDir) => {
|
|
802
|
+
try {
|
|
803
|
+
const packageJson = import_fs.default.readFileSync((0, import_node_path11.join)(catalogDir, "package.json"), "utf8");
|
|
804
|
+
const packageJsonObject = JSON.parse(packageJson);
|
|
805
|
+
return packageJsonObject["dependencies"]["@eventcatalog/core"];
|
|
806
|
+
} catch (error) {
|
|
807
|
+
return "unknown";
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
var hydrateResource = async (catalogDir, resources, { attachSchema = false } = {}) => {
|
|
811
|
+
return await Promise.all(
|
|
812
|
+
resources.map(async (resource) => {
|
|
813
|
+
const resourcePath = await getResourcePath(catalogDir, resource.id, resource.version);
|
|
814
|
+
let schema = "";
|
|
815
|
+
if (resource.schemaPath && resourcePath?.fullPath) {
|
|
816
|
+
const pathToSchema = import_node_path11.default.join(import_node_path11.default.dirname(resourcePath?.fullPath), resource.schemaPath);
|
|
817
|
+
if (import_fs.default.existsSync(pathToSchema)) {
|
|
818
|
+
schema = import_fs.default.readFileSync(pathToSchema, "utf8");
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
const eventcatalog = schema ? { directory: resourcePath?.directory, schema } : { directory: resourcePath?.directory };
|
|
822
|
+
return {
|
|
823
|
+
...resource,
|
|
824
|
+
_eventcatalog: eventcatalog
|
|
825
|
+
};
|
|
826
|
+
})
|
|
827
|
+
);
|
|
828
|
+
};
|
|
829
|
+
var filterCollection = (collection, options) => {
|
|
830
|
+
return collection.map((item) => ({
|
|
831
|
+
...item,
|
|
832
|
+
markdown: options?.includeMarkdown ? item.markdown : void 0
|
|
833
|
+
}));
|
|
834
|
+
};
|
|
835
|
+
var dumpCatalog = (directory) => async (options) => {
|
|
836
|
+
const { getDomains: getDomains2, getServices: getServices2, getEvents: getEvents2, getQueries: getQueries2, getCommands: getCommands2, getChannels: getChannels2, getTeams: getTeams2, getUsers: getUsers2 } = index_default(directory);
|
|
837
|
+
const { includeMarkdown = true } = options || {};
|
|
838
|
+
const domains = await getDomains2();
|
|
839
|
+
const services = await getServices2();
|
|
840
|
+
const events = await getEvents2();
|
|
841
|
+
const commands = await getCommands2();
|
|
842
|
+
const queries = await getQueries2();
|
|
843
|
+
const teams = await getTeams2();
|
|
844
|
+
const users = await getUsers2();
|
|
845
|
+
const channels = await getChannels2();
|
|
846
|
+
const [
|
|
847
|
+
hydratedDomains,
|
|
848
|
+
hydratedServices,
|
|
849
|
+
hydratedEvents,
|
|
850
|
+
hydratedQueries,
|
|
851
|
+
hydratedCommands,
|
|
852
|
+
hydratedTeams,
|
|
853
|
+
hydratedUsers,
|
|
854
|
+
hydratedChannels
|
|
855
|
+
] = await Promise.all([
|
|
856
|
+
hydrateResource(directory, domains),
|
|
857
|
+
hydrateResource(directory, services),
|
|
858
|
+
hydrateResource(directory, events),
|
|
859
|
+
hydrateResource(directory, queries),
|
|
860
|
+
hydrateResource(directory, commands),
|
|
861
|
+
hydrateResource(directory, teams),
|
|
862
|
+
hydrateResource(directory, users),
|
|
863
|
+
hydrateResource(directory, channels)
|
|
864
|
+
]);
|
|
865
|
+
return {
|
|
866
|
+
version: DUMP_VERSION,
|
|
867
|
+
catalogVersion: await getEventCatalogVersion(directory),
|
|
868
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
869
|
+
resources: {
|
|
870
|
+
domains: filterCollection(hydratedDomains, { includeMarkdown }),
|
|
871
|
+
services: filterCollection(hydratedServices, { includeMarkdown }),
|
|
872
|
+
messages: {
|
|
873
|
+
events: filterCollection(hydratedEvents, { includeMarkdown }),
|
|
874
|
+
queries: filterCollection(hydratedQueries, { includeMarkdown }),
|
|
875
|
+
commands: filterCollection(hydratedCommands, { includeMarkdown })
|
|
876
|
+
},
|
|
877
|
+
teams: filterCollection(hydratedTeams, { includeMarkdown }),
|
|
878
|
+
users: filterCollection(hydratedUsers, { includeMarkdown }),
|
|
879
|
+
channels: filterCollection(hydratedChannels, { includeMarkdown })
|
|
880
|
+
}
|
|
881
|
+
};
|
|
856
882
|
};
|
|
857
883
|
|
|
858
884
|
// src/index.ts
|