@eventcatalog/core 2.6.1 → 2.6.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @eventcatalog/core
2
2
 
3
+ ## 2.6.3
4
+
5
+ ### Patch Changes
6
+
7
+ - d35846b: chore(core): refactored the way pages are rendered reducing code
8
+
9
+ ## 2.6.2
10
+
11
+ ### Patch Changes
12
+
13
+ - 498f58c: fix(core): generate command now removes any tmp files required for ge…
14
+
3
15
  ## 2.6.1
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -48,6 +48,7 @@
48
48
  - 🗄️ Version domains, services and messages
49
49
  - ⭐ Discoverability feature (search, filter and more) ([demo](https://demo.eventcatalog.dev/discover/events))
50
50
  - ⭐ Document teams and users ([demo](https://demo.eventcatalog.dev/docs/teams/full-stack))
51
+ - 🤖 Automate your catalogs with [generators](https://www.eventcatalog.dev/docs/development/plugins/plugin-overview) (e.g generate your catalogs from your [AsyncAPI](https://www.eventcatalog.dev/docs/ascynapi)/[OpenAPI](https://www.eventcatalog.dev/docs/openapi) documents)
51
52
  - ⭐ And much more...
52
53
 
53
54
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@eventcatalog/core",
3
3
  "type": "module",
4
- "version": "2.6.1",
4
+ "version": "2.6.3",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -99,6 +99,8 @@ const generate = async () => {
99
99
  return;
100
100
  }
101
101
  }
102
+
103
+ await cleanup();
102
104
  } catch (error) {
103
105
  // Failed to generate clean up...
104
106
  console.error(error);
@@ -1,50 +1,40 @@
1
1
  ---
2
- import type { CollectionEntry } from 'astro:content';
3
- import type { CollectionTypes } from '@types';
4
2
  import path from 'path';
5
3
  import { readFileSync } from 'fs';
6
-
7
- import PlainPage from '@layouts/PlainPage.astro';
8
-
9
4
  import { createElement } from 'react';
10
5
  import { renderToString } from 'react-dom/server';
11
-
12
6
  import { Parser } from '@asyncapi/parser';
13
7
 
14
- import { getEvents } from '@utils/events';
15
- import { getServices } from '@utils/services/services';
16
- import { getCommands } from '@utils/commands';
17
- import { getDomains } from '@utils/domains/domains';
8
+ import type { CollectionTypes, PageTypes } from '@types';
9
+
10
+ import PlainPage from '@layouts/PlainPage.astro';
18
11
 
19
12
  import '@asyncapi/react-component/styles/default.min.css';
20
13
  import js from '@asyncapi/react-component/browser/standalone/without-parser.js?url';
21
14
  import { AsyncApiComponentWP, type ConfigInterface } from '@asyncapi/react-component';
15
+ import { pageDataLoader } from '@utils/pages/pages';
16
+ import type { CollectionEntry } from 'astro:content';
22
17
 
23
18
  export async function getStaticPaths() {
24
- const events = await getEvents();
25
- const commands = await getCommands();
26
- const services = await getServices();
27
- const domains = await getDomains();
19
+ const itemTypes: PageTypes[] = ['events', 'commands', 'services', 'domains'];
20
+ const allItems = await Promise.all(itemTypes.map((type) => pageDataLoader[type]()));
28
21
 
29
22
  const hasAsyncAPISpec = (item: CollectionEntry<CollectionTypes>) => item.data.specifications?.asyncapiPath !== undefined;
23
+ const filteredItems = allItems.map((items) => items.filter(hasAsyncAPISpec));
30
24
 
31
- const buildPages = (collection: CollectionEntry<CollectionTypes>[]) => {
32
- const filteredCollection = collection.filter(hasAsyncAPISpec);
33
-
34
- return filteredCollection.map((item) => ({
25
+ return filteredItems.flatMap((items, index) =>
26
+ items.map((item) => ({
35
27
  params: {
36
- type: item.collection,
37
28
  id: item.data.id,
29
+ type: itemTypes[index],
38
30
  version: item.data.version,
39
31
  },
40
32
  props: {
41
- type: item.collection,
33
+ type: itemTypes[index],
42
34
  ...item,
43
35
  },
44
- }));
45
- };
46
-
47
- return [...buildPages(domains), ...buildPages(events), ...buildPages(services), ...buildPages(commands)];
36
+ }))
37
+ );
48
38
  }
49
39
 
50
40
  // @ts-ignore
@@ -1,40 +1,31 @@
1
1
  ---
2
- import type { CollectionEntry } from 'astro:content';
3
-
4
2
  import Layout from '@layouts/DocsLayout.astro';
5
3
  import Footer from '@layouts/Footer.astro';
6
4
 
7
- import { getEvents } from '@utils/events';
8
- import { getServices } from '@utils/services/services';
9
- import { getCommands } from '@utils/commands';
10
- import { getDomains } from '@utils/domains/domains';
11
- import type { CollectionTypes } from '@types';
5
+ import type { PageTypes } from '@types';
12
6
  import { getChangeLogs } from '@utils/changelogs/changelogs';
13
7
  import { EnvelopeIcon, RectangleGroupIcon, ServerIcon } from '@heroicons/react/24/outline';
8
+ import { pageDataLoader } from '@utils/pages/pages';
14
9
 
15
10
  import { buildUrl } from '@utils/url-builder';
16
11
 
17
12
  export async function getStaticPaths() {
18
- const events = await getEvents();
19
- const commands = await getCommands();
20
- const services = await getServices();
21
- const domains = await getDomains();
13
+ const itemTypes: PageTypes[] = ['events', 'commands', 'services', 'domains'];
14
+ const allItems = await Promise.all(itemTypes.map((type) => pageDataLoader[type]()));
22
15
 
23
- const buildPages = (collection: CollectionEntry<CollectionTypes>[]) => {
24
- return collection.map((item) => ({
16
+ return allItems.flatMap((items, index) =>
17
+ items.map((item) => ({
25
18
  params: {
26
- type: item.collection,
19
+ type: itemTypes[index],
27
20
  id: item.data.id,
28
21
  version: item.data.version,
29
22
  },
30
23
  props: {
31
- type: item.collection,
24
+ type: itemTypes[index],
32
25
  ...item,
33
26
  },
34
- }));
35
- };
36
-
37
- return [...buildPages(domains), ...buildPages(events), ...buildPages(services), ...buildPages(commands)];
27
+ }))
28
+ );
38
29
  }
39
30
 
40
31
  const props = Astro.props;
@@ -1,5 +1,4 @@
1
1
  ---
2
- import type { CollectionEntry } from 'astro:content';
3
2
  import DocsLayout from '@layouts/DocsLayout.astro';
4
3
  import Footer from '@layouts/Footer.astro';
5
4
 
@@ -10,40 +9,39 @@ import SchemaViewer from '@components/MDX/SchemaViewer/SchemaViewer.astro';
10
9
  // SideBars
11
10
  import ServiceSideBar from '@components/SideBars/ServiceSideBar.astro';
12
11
  import MessageSideBar from '@components/SideBars/MessageSideBar.astro';
13
-
14
- import { getEvents } from '@utils/events';
15
- import { getServices } from '@utils/services/services';
16
- import { getCommands } from '@utils/commands';
17
- import { EnvelopeIcon, PencilIcon, QueueListIcon, RectangleGroupIcon, ServerIcon } from '@heroicons/react/24/outline';
18
- import { getDomains } from '@utils/domains/domains';
19
12
  import DomainSideBar from '@components/SideBars/DomainSideBar.astro';
20
- import type { CollectionTypes } from '@types';
13
+
14
+ import { EnvelopeIcon, QueueListIcon, RectangleGroupIcon, ServerIcon } from '@heroicons/react/24/outline';
15
+ import type { PageTypes } from '@types';
21
16
 
22
17
  import { buildUrl } from '@utils/url-builder';
23
18
  import { getFlows } from '@utils/flows/flows';
19
+ import { pageDataLoader } from '@utils/pages/pages';
20
+
21
+ type PageTypesWithFlows = PageTypes | 'flows';
24
22
 
25
23
  export async function getStaticPaths() {
26
- const events = await getEvents();
27
- const commands = await getCommands();
28
- const services = await getServices();
29
- const domains = await getDomains();
30
- const flows = await getFlows();
24
+ const loaders = {
25
+ ...pageDataLoader,
26
+ flows: getFlows,
27
+ };
31
28
 
32
- const buildPages = (collection: CollectionEntry<CollectionTypes>[]) => {
33
- return collection.map((item) => ({
29
+ const itemTypes: PageTypesWithFlows[] = ['events', 'commands', 'services', 'domains', 'flows'];
30
+ const allItems = await Promise.all(itemTypes.map((type) => loaders[type]()));
31
+
32
+ return allItems.flatMap((items, index) =>
33
+ items.map((item) => ({
34
34
  params: {
35
- type: item.collection,
35
+ type: itemTypes[index],
36
36
  id: item.data.id,
37
37
  version: item.data.version,
38
38
  },
39
39
  props: {
40
- type: item.collection,
40
+ type: itemTypes[index],
41
41
  ...item,
42
42
  },
43
- }));
44
- };
45
-
46
- return [...buildPages(domains), ...buildPages(events), ...buildPages(services), ...buildPages(commands), ...buildPages(flows)];
43
+ }))
44
+ );
47
45
  }
48
46
 
49
47
  const props = Astro.props;
@@ -3,40 +3,33 @@ import type { CollectionEntry } from 'astro:content';
3
3
  import * as path from 'path';
4
4
  import fs from 'node:fs';
5
5
 
6
- import { getEvents } from '@utils/events';
7
- import { getServices } from '@utils/services/services';
8
- import { getCommands } from '@utils/commands';
9
- import { getDomains } from '@utils/domains/domains';
10
- import type { CollectionTypes } from '@types';
6
+ import type { CollectionTypes, PageTypes } from '@types';
11
7
  import PlainPage from '@layouts/PlainPage.astro';
12
8
  import { DocumentMinusIcon } from '@heroicons/react/24/outline';
13
9
  import { buildUrl } from '@utils/url-builder';
10
+ import { pageDataLoader } from '@utils/pages/pages';
14
11
 
15
12
  export async function getStaticPaths() {
16
- const events = await getEvents();
17
- const commands = await getCommands();
18
- const services = await getServices();
19
- const domains = await getDomains();
13
+ const itemTypes: PageTypes[] = ['events', 'commands', 'services', 'domains'];
20
14
 
21
- const hasOpenAPISpec = (item: CollectionEntry<CollectionTypes>) => item.data.specifications?.openapiPath !== undefined;
15
+ const allItems = await Promise.all(itemTypes.map((type) => pageDataLoader[type]()));
22
16
 
23
- const buildPages = (collection: CollectionEntry<CollectionTypes>[]) => {
24
- const filteredCollection = collection.filter(hasOpenAPISpec);
17
+ const hasOpenAPISpec = (item: CollectionEntry<CollectionTypes>) => item.data.specifications?.openapiPath !== undefined;
18
+ const filteredItems = allItems.map((items) => items.filter(hasOpenAPISpec));
25
19
 
26
- return filteredCollection.map((item) => ({
20
+ return filteredItems.flatMap((items, index) =>
21
+ items.map((item) => ({
27
22
  params: {
28
- type: item.collection,
23
+ type: itemTypes[index],
29
24
  id: item.data.id,
30
25
  version: item.data.version,
31
26
  },
32
27
  props: {
33
- type: item.collection,
28
+ type: itemTypes[index],
34
29
  ...item,
35
30
  },
36
- }));
37
- };
38
-
39
- return [...buildPages(domains), ...buildPages(events), ...buildPages(services), ...buildPages(commands)];
31
+ }))
32
+ );
40
33
  }
41
34
 
42
35
  // @ts-ignore
@@ -1,39 +1,35 @@
1
1
  ---
2
2
  import NodeGraph from '@components/MDX/NodeGraph/NodeGraph.astro';
3
3
  import VisualiserLayout from '@layouts/VisualiserLayout.astro';
4
- import type { CollectionTypes } from '@types';
5
- import { getCommands } from '@utils/commands';
6
- import { getDomains } from '@utils/domains/domains';
7
- import { getEvents } from '@utils/events';
4
+ import type { PageTypes } from '@types';
8
5
  import { getFlows } from '@utils/flows/flows';
9
- import { getServices } from '@utils/services/services';
10
6
  import { buildUrl } from '@utils/url-builder';
11
- import type { CollectionEntry } from 'astro:content';
7
+
8
+ import { pageDataLoader } from '@utils/pages/pages';
9
+ type PageTypesWithFlows = PageTypes | 'flows';
12
10
 
13
11
  export async function getStaticPaths() {
14
- const [services, events, commands, domains, flows] = await Promise.all([
15
- getServices(),
16
- getEvents(),
17
- getCommands(),
18
- getDomains(),
19
- getFlows(),
20
- ]);
12
+ const loaders = {
13
+ ...pageDataLoader,
14
+ flows: getFlows,
15
+ };
16
+
17
+ const itemTypes: PageTypesWithFlows[] = ['events', 'commands', 'services', 'domains', 'flows'];
18
+ const allItems = await Promise.all(itemTypes.map((type) => loaders[type]()));
21
19
 
22
- const buildPages = (collection: CollectionEntry<CollectionTypes>[]) => {
23
- return collection.map((item) => ({
20
+ return allItems.flatMap((items, index) =>
21
+ items.map((item) => ({
24
22
  params: {
25
- type: item.collection,
23
+ type: itemTypes[index],
26
24
  id: item.data.id,
27
25
  version: item.data.version,
28
26
  },
29
27
  props: {
30
- type: item.collection,
28
+ type: itemTypes[index],
31
29
  ...item,
32
30
  },
33
- }));
34
- };
35
-
36
- return [...buildPages(services), ...buildPages(events), ...buildPages(commands), ...buildPages(domains), ...buildPages(flows)];
31
+ }))
32
+ );
37
33
  }
38
34
 
39
35
  const props = Astro.props;
@@ -1,2 +1,4 @@
1
1
  export type CollectionTypes = 'commands' | 'events' | 'domains' | 'services' | 'flows';
2
2
  export type CollectionMessageTypes = 'commands' | 'events';
3
+
4
+ export type PageTypes = 'events' | 'commands' | 'services' | 'domains';
@@ -1,7 +1,13 @@
1
- // // import type { Domain, Message } from '@eventcatalog/types';
2
- // import { getCollection, } from 'astro:content';
1
+ // Exporting getCommands and getEvents directly
2
+ import { getCommands } from '@utils/commands';
3
+ import { getEvents } from '@utils/events';
4
+ export { getCommands } from '@utils/commands';
5
+ export { getEvents } from '@utils/events';
3
6
 
4
- // export const getMessages = async (): Promise<Message[]> => {
5
- // const commands = await getCollection('commands');
6
- // return commands.map((message: any) => message.data);
7
- // };
7
+ // Main function that uses the imported functions
8
+ export const getMessages = async () => {
9
+ const commands = await getCommands();
10
+ const events = await getEvents();
11
+
12
+ return { commands, events };
13
+ };
@@ -0,0 +1,12 @@
1
+ import type { CollectionTypes, PageTypes } from '@types';
2
+ import { getDomains } from '@utils/domains/domains';
3
+ import { getCommands, getEvents } from '@utils/messages';
4
+ import { getServices } from '@utils/services/services';
5
+ import type { CollectionEntry } from 'astro:content';
6
+
7
+ export const pageDataLoader: Record<PageTypes, () => Promise<CollectionEntry<CollectionTypes>[]>> = {
8
+ events: getEvents,
9
+ commands: getCommands,
10
+ services: getServices,
11
+ domains: getDomains,
12
+ };