@eventcatalog/core 3.45.0 → 3.46.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/analytics/analytics.cjs +1 -1
- package/dist/analytics/analytics.js +2 -2
- package/dist/analytics/log-build.cjs +1 -1
- package/dist/analytics/log-build.js +3 -3
- package/dist/{chunk-G6KYCMUM.js → chunk-62QAJWPT.js} +1 -1
- package/dist/{chunk-6XNMBNIU.js → chunk-A7XUEEUA.js} +1 -1
- package/dist/{chunk-E4K4KTSR.js → chunk-E4QGTJXO.js} +1 -1
- package/dist/{chunk-2QK37BNF.js → chunk-TZ72NP2W.js} +1 -1
- package/dist/{chunk-KHL25572.js → chunk-VZ6L3G2S.js} +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/eventcatalog.cjs +1 -1
- package/dist/eventcatalog.config.d.cts +29 -0
- package/dist/eventcatalog.config.d.ts +29 -0
- package/dist/eventcatalog.js +5 -5
- package/dist/generate.cjs +1 -1
- package/dist/generate.js +3 -3
- package/dist/utils/cli-logger.cjs +1 -1
- package/dist/utils/cli-logger.js +2 -2
- package/eventcatalog/astro.config.mjs +7 -10
- package/eventcatalog/ec.config.mjs +20 -0
- package/eventcatalog/src/components/MDX/SchemaViewer/SchemaViewerPortal.tsx +1 -1
- package/eventcatalog/src/components/MDX/SchemaViewer/SchemaViewerRoot.astro +19 -47
- package/eventcatalog/src/components/MDX/SchemaViewer/schema-viewer-utils.spec.ts +53 -0
- package/eventcatalog/src/components/MDX/SchemaViewer/schema-viewer-utils.ts +133 -0
- package/eventcatalog/src/content.config.ts +7 -0
- package/eventcatalog/src/enterprise/tools/catalog-tools.ts +23 -0
- package/eventcatalog/src/pages/docs/[type]/[id]/[version]/index.astro +1 -1
- package/eventcatalog/src/stores/sidebar-store/builders/message.ts +25 -2
- package/eventcatalog/src/stores/sidebar-store/builders/shared.ts +1 -0
- package/eventcatalog/src/stores/sidebar-store/state.ts +3 -0
- package/eventcatalog/src/styles/tailwind.css +18 -0
- package/eventcatalog/src/utils/collections/schema-loader.ts +302 -16
- package/eventcatalog/src/utils/files.ts +1 -1
- package/package.json +3 -4
|
@@ -71,6 +71,7 @@ const channelPointer = z
|
|
|
71
71
|
|
|
72
72
|
const schemaPointer = z.object({
|
|
73
73
|
id: z.string().optional(),
|
|
74
|
+
ref: z.string().optional(),
|
|
74
75
|
file: z.string().optional(),
|
|
75
76
|
path: z.string().optional(),
|
|
76
77
|
name: z.string().optional(),
|
|
@@ -1018,10 +1019,13 @@ const schemas = defineCollection({
|
|
|
1018
1019
|
]) as string[],
|
|
1019
1020
|
base: projectDirBase,
|
|
1020
1021
|
},
|
|
1022
|
+
sources: config.schemas?.sources ?? [],
|
|
1021
1023
|
}),
|
|
1022
1024
|
schema: z
|
|
1023
1025
|
.object({
|
|
1024
1026
|
format: z.string(),
|
|
1027
|
+
schemaId: z.string().optional(),
|
|
1028
|
+
ref: z.string().optional(),
|
|
1025
1029
|
content: z.string().optional(),
|
|
1026
1030
|
file: z.string().optional(),
|
|
1027
1031
|
filePath: z.string().optional(),
|
|
@@ -1038,8 +1042,11 @@ const schemas = defineCollection({
|
|
|
1038
1042
|
}),
|
|
1039
1043
|
source: z.object({
|
|
1040
1044
|
provider: z.string(),
|
|
1045
|
+
id: z.string().optional(),
|
|
1041
1046
|
path: z.string().optional(),
|
|
1042
1047
|
url: z.string().optional(),
|
|
1048
|
+
ref: z.string().optional(),
|
|
1049
|
+
branch: z.string().optional(),
|
|
1043
1050
|
}),
|
|
1044
1051
|
readOnly: z.boolean().optional(),
|
|
1045
1052
|
})
|
|
@@ -28,6 +28,8 @@ import { getNodesAndEdges as getNodesAndEdgesForContainer } from '@utils/node-gr
|
|
|
28
28
|
import { convertToMermaid } from '@utils/node-graphs/export-mermaid';
|
|
29
29
|
import config from '@config';
|
|
30
30
|
|
|
31
|
+
const MESSAGE_COLLECTIONS = new Set(['events', 'commands', 'queries']);
|
|
32
|
+
|
|
31
33
|
// ============================================
|
|
32
34
|
// Pagination utilities
|
|
33
35
|
// ============================================
|
|
@@ -226,6 +228,27 @@ export async function getSchemaForResource(params: { resourceId: string; resourc
|
|
|
226
228
|
};
|
|
227
229
|
}
|
|
228
230
|
|
|
231
|
+
if (MESSAGE_COLLECTIONS.has(params.resourceCollection)) {
|
|
232
|
+
const schemaEntries = await getCollection('schemas');
|
|
233
|
+
const schemas = schemaEntries.filter(
|
|
234
|
+
(schema) =>
|
|
235
|
+
schema.data.message.collection === params.resourceCollection &&
|
|
236
|
+
schema.data.message.id === params.resourceId &&
|
|
237
|
+
schema.data.message.version === params.resourceVersion
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
if (schemas.length > 0) {
|
|
241
|
+
return schemas.map((schema) => ({
|
|
242
|
+
id: schema.id,
|
|
243
|
+
name: schema.data.name,
|
|
244
|
+
ref: schema.data.ref,
|
|
245
|
+
format: schema.data.format,
|
|
246
|
+
source: schema.data.source,
|
|
247
|
+
code: schema.data.content || '',
|
|
248
|
+
}));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
229
252
|
const schema = await getSchemasFromResource(resource);
|
|
230
253
|
|
|
231
254
|
if (schema.length > 0) {
|
|
@@ -565,7 +565,7 @@ if (!isAdrPage && !hasCurrentFlowEmbed && !hasCurrentPageNodeGraph) {
|
|
|
565
565
|
<div data-pagefind-ignore>
|
|
566
566
|
<!-- @ts-ignore -->
|
|
567
567
|
<!-- <SchemaViewer id={props.data.id} catalog={props.catalog} filePath={props.filePath} /> -->
|
|
568
|
-
<SchemaViewer id={props.data.id} filePath={props.filePath} />
|
|
568
|
+
<SchemaViewer id={props.data.id} version={props.data.version} collection={props.collection} filePath={props.filePath} />
|
|
569
569
|
|
|
570
570
|
{
|
|
571
571
|
nodeGraphs.length > 0 &&
|
|
@@ -15,11 +15,33 @@ import { isVisualiserEnabled, isChangelogEnabled } from '@utils/feature';
|
|
|
15
15
|
import { iconFieldsForResource } from '@utils/icon';
|
|
16
16
|
import { collectionToResourceMap } from '@utils/collections/util';
|
|
17
17
|
|
|
18
|
+
type MessageSchemaEntry = CollectionEntry<'schemas'>;
|
|
19
|
+
|
|
18
20
|
const getProducerConsumerPageRef = (resource: any) => {
|
|
19
21
|
const resourceType = collectionToResourceMap[resource.collection as keyof typeof collectionToResourceMap];
|
|
20
22
|
return `${resourceType}:${resource.data.id}:${resource.data.version}`;
|
|
21
23
|
};
|
|
22
24
|
|
|
25
|
+
const getSchemasForMessage = (
|
|
26
|
+
message: CollectionEntry<'events' | 'commands' | 'queries'>,
|
|
27
|
+
schemas: MessageSchemaEntry[] = []
|
|
28
|
+
) => {
|
|
29
|
+
return schemas.filter(
|
|
30
|
+
(schema) =>
|
|
31
|
+
schema.data.message.collection === message.collection &&
|
|
32
|
+
schema.data.message.id === message.data.id &&
|
|
33
|
+
schema.data.message.version === message.data.version
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const getSchemaNavTitle = (schemas: MessageSchemaEntry[]) => {
|
|
38
|
+
if (schemas.length > 1) return 'Schemas';
|
|
39
|
+
|
|
40
|
+
const schemaPath = schemas[0]?.data.file || schemas[0]?.data.source.path || schemas[0]?.data.ref || schemas[0]?.id;
|
|
41
|
+
const format = schemaPath ? getSchemaFormatFromURL(schemaPath) : schemas[0]?.data.format;
|
|
42
|
+
return format ? `Schema (${format.toUpperCase()})` : 'Schema';
|
|
43
|
+
};
|
|
44
|
+
|
|
23
45
|
export const buildMessageNode = (
|
|
24
46
|
message: CollectionEntry<'events' | 'commands' | 'queries'>,
|
|
25
47
|
owners: any[],
|
|
@@ -51,7 +73,8 @@ export const buildMessageNode = (
|
|
|
51
73
|
};
|
|
52
74
|
const defaultIcon = iconMap[collection] || 'Mail';
|
|
53
75
|
|
|
54
|
-
const
|
|
76
|
+
const resolvedSchemas = getSchemasForMessage(message, context.schemas);
|
|
77
|
+
const hasSchema = resolvedSchemas.length > 0;
|
|
55
78
|
const renderVisualiser = isVisualiserEnabled();
|
|
56
79
|
const docsSection = buildResourceDocsSection(
|
|
57
80
|
collection as 'events' | 'commands' | 'queries',
|
|
@@ -116,7 +139,7 @@ export const buildMessageNode = (
|
|
|
116
139
|
pages: [
|
|
117
140
|
{
|
|
118
141
|
type: 'item',
|
|
119
|
-
title:
|
|
142
|
+
title: getSchemaNavTitle(resolvedSchemas),
|
|
120
143
|
href: buildUrl(`/schemas/${collection}/${message.data.id}/${message.data.version}`),
|
|
121
144
|
},
|
|
122
145
|
hasFieldUsage && {
|
|
@@ -67,6 +67,7 @@ export type ResourceGroupContext = {
|
|
|
67
67
|
entities?: CollectionEntry<'entities'>[];
|
|
68
68
|
dataProducts: CollectionEntry<'data-products'>[];
|
|
69
69
|
diagrams: CollectionEntry<'diagrams'>[];
|
|
70
|
+
schemas?: CollectionEntry<'schemas'>[];
|
|
70
71
|
adrs: Adr[];
|
|
71
72
|
users?: CollectionEntry<'users'>[];
|
|
72
73
|
teams?: CollectionEntry<'teams'>[];
|
|
@@ -292,6 +292,7 @@ export const getNestedSideBarData = async (): Promise<NavigationData> => {
|
|
|
292
292
|
dataProducts,
|
|
293
293
|
entities,
|
|
294
294
|
adrs,
|
|
295
|
+
schemas,
|
|
295
296
|
resourceDocs,
|
|
296
297
|
resourceDocCategories,
|
|
297
298
|
] = await Promise.all([
|
|
@@ -309,6 +310,7 @@ export const getNestedSideBarData = async (): Promise<NavigationData> => {
|
|
|
309
310
|
getDataProducts({ getAllVersions: false }),
|
|
310
311
|
getEntities({ getAllVersions: false }),
|
|
311
312
|
getAdrs({ getAllVersions: false }),
|
|
313
|
+
getCollection('schemas'),
|
|
312
314
|
getResourceDocs(),
|
|
313
315
|
getResourceDocCategories(),
|
|
314
316
|
]);
|
|
@@ -330,6 +332,7 @@ export const getNestedSideBarData = async (): Promise<NavigationData> => {
|
|
|
330
332
|
containers,
|
|
331
333
|
channels,
|
|
332
334
|
diagrams,
|
|
335
|
+
schemas,
|
|
333
336
|
dataProducts,
|
|
334
337
|
entities,
|
|
335
338
|
adrs,
|
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
@plugin "@tailwindcss/typography";
|
|
4
4
|
|
|
5
|
+
/*
|
|
6
|
+
* EventCatalog renders MDX inside Tailwind Typography's `.prose` wrapper.
|
|
7
|
+
* Typography adds decorative backticks around inline code via pseudo-elements;
|
|
8
|
+
* docs should show only the code content itself.
|
|
9
|
+
*/
|
|
10
|
+
.prose code::before,
|
|
11
|
+
.prose code::after {
|
|
12
|
+
content: '';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.prose :not(pre) > code {
|
|
16
|
+
background-color: oklab(0.97 0 0.0013 / 0.5);
|
|
17
|
+
border-radius: 0.25rem;
|
|
18
|
+
font-family: var(--font-mono);
|
|
19
|
+
padding: 0.125rem 0.375rem;
|
|
20
|
+
font-weight: 400;
|
|
21
|
+
}
|
|
22
|
+
|
|
5
23
|
/* Dark mode uses data-theme attribute, not prefers-color-scheme */
|
|
6
24
|
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
|
|
7
25
|
|
|
@@ -4,12 +4,18 @@ import matter from 'gray-matter';
|
|
|
4
4
|
import fs from 'node:fs/promises';
|
|
5
5
|
import fsSync from 'node:fs';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import pc from 'picocolors';
|
|
9
|
+
import { isEventCatalogScaleEnabled } from '../feature';
|
|
7
10
|
import { sortVersioned } from './util';
|
|
8
11
|
|
|
12
|
+
const colors = pc.createColors(true);
|
|
13
|
+
|
|
9
14
|
type MessageCollection = 'events' | 'commands' | 'queries';
|
|
10
15
|
|
|
11
16
|
type SchemaReference = {
|
|
12
17
|
id?: string;
|
|
18
|
+
ref?: string;
|
|
13
19
|
file?: string;
|
|
14
20
|
path?: string;
|
|
15
21
|
name?: string;
|
|
@@ -18,6 +24,34 @@ type SchemaReference = {
|
|
|
18
24
|
default?: boolean;
|
|
19
25
|
};
|
|
20
26
|
|
|
27
|
+
type SchemaSourceEntry = {
|
|
28
|
+
provider: string;
|
|
29
|
+
id?: string;
|
|
30
|
+
path?: string;
|
|
31
|
+
url?: string;
|
|
32
|
+
ref?: string;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type SchemaSource = {
|
|
37
|
+
type: 'schemas';
|
|
38
|
+
name: string;
|
|
39
|
+
canResolve: (ref: string) => boolean;
|
|
40
|
+
resolve: (
|
|
41
|
+
ref: string,
|
|
42
|
+
context?: { messageFilePath?: string }
|
|
43
|
+
) => Promise<
|
|
44
|
+
| {
|
|
45
|
+
id: string;
|
|
46
|
+
name?: string;
|
|
47
|
+
format?: string;
|
|
48
|
+
content: string;
|
|
49
|
+
source: SchemaSourceEntry;
|
|
50
|
+
}
|
|
51
|
+
| undefined
|
|
52
|
+
>;
|
|
53
|
+
};
|
|
54
|
+
|
|
21
55
|
type MessageFrontmatter = {
|
|
22
56
|
id?: string;
|
|
23
57
|
name?: string;
|
|
@@ -30,6 +64,8 @@ type MessageFrontmatter = {
|
|
|
30
64
|
|
|
31
65
|
export type MessageSchemaResource = {
|
|
32
66
|
id: string;
|
|
67
|
+
schemaId?: string;
|
|
68
|
+
ref?: string;
|
|
33
69
|
name?: string;
|
|
34
70
|
version?: string;
|
|
35
71
|
format: string;
|
|
@@ -48,8 +84,19 @@ export type MessageSchemaResource = {
|
|
|
48
84
|
owners?: string[];
|
|
49
85
|
};
|
|
50
86
|
source: {
|
|
51
|
-
provider:
|
|
52
|
-
|
|
87
|
+
provider: string;
|
|
88
|
+
id?: string;
|
|
89
|
+
path?: string;
|
|
90
|
+
url?: string;
|
|
91
|
+
ref?: string;
|
|
92
|
+
[key: string]: unknown;
|
|
93
|
+
};
|
|
94
|
+
readOnly?: boolean;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
type InternalMessageSchemaResource = MessageSchemaResource & {
|
|
98
|
+
_context?: {
|
|
99
|
+
messageFilePath?: string;
|
|
53
100
|
};
|
|
54
101
|
};
|
|
55
102
|
|
|
@@ -58,11 +105,13 @@ type SchemaLoaderOptions = {
|
|
|
58
105
|
pattern: string[];
|
|
59
106
|
base?: string;
|
|
60
107
|
};
|
|
108
|
+
sources?: SchemaSource[];
|
|
61
109
|
};
|
|
62
110
|
|
|
63
111
|
type LoaderContext = Parameters<Loader['load']>[0];
|
|
64
112
|
|
|
65
113
|
const MESSAGE_COLLECTIONS: MessageCollection[] = ['events', 'commands', 'queries'];
|
|
114
|
+
const FILE_SCHEMA_REF_PREFIX = 'file://';
|
|
66
115
|
|
|
67
116
|
const normalizePath = (value: string) => value.replace(/\\/g, '/');
|
|
68
117
|
|
|
@@ -85,11 +134,137 @@ const getSchemaFormat = (schemaPath: string) => {
|
|
|
85
134
|
const buildGeneratedSchemaId = (message: { collection: MessageCollection; id: string; version: string }, schemaPath: string) =>
|
|
86
135
|
`schema:${message.collection}:${message.id}:${message.version}:${schemaPath}`;
|
|
87
136
|
|
|
137
|
+
const getSchemaCollectionId = ({
|
|
138
|
+
message,
|
|
139
|
+
reference,
|
|
140
|
+
schemaRef,
|
|
141
|
+
schemaFile,
|
|
142
|
+
}: {
|
|
143
|
+
message: { collection: MessageCollection; id: string; version: string };
|
|
144
|
+
reference: SchemaReference;
|
|
145
|
+
schemaRef?: string;
|
|
146
|
+
schemaFile?: string;
|
|
147
|
+
}) => {
|
|
148
|
+
if (schemaRef) return buildGeneratedSchemaId(message, schemaRef);
|
|
149
|
+
if (reference.id) return buildGeneratedSchemaId(message, reference.id);
|
|
150
|
+
return buildGeneratedSchemaId(message, schemaFile as string);
|
|
151
|
+
};
|
|
152
|
+
|
|
88
153
|
const getSchemaFile = (reference: SchemaReference) => reference.file ?? reference.path;
|
|
89
154
|
|
|
155
|
+
const getSchemaRef = (reference: SchemaReference) => {
|
|
156
|
+
if (reference.ref) return reference.ref;
|
|
157
|
+
if (!getSchemaFile(reference)) return reference.id;
|
|
158
|
+
return undefined;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const getSchemaDisplayName = ({
|
|
162
|
+
referenceName,
|
|
163
|
+
resolvedName,
|
|
164
|
+
schemaFile,
|
|
165
|
+
filePath,
|
|
166
|
+
schemaRef,
|
|
167
|
+
sourcePath,
|
|
168
|
+
schemaId,
|
|
169
|
+
messageName,
|
|
170
|
+
}: {
|
|
171
|
+
referenceName?: string;
|
|
172
|
+
resolvedName?: string;
|
|
173
|
+
schemaFile?: string;
|
|
174
|
+
filePath?: string;
|
|
175
|
+
schemaRef?: string;
|
|
176
|
+
sourcePath?: string;
|
|
177
|
+
schemaId: string;
|
|
178
|
+
messageName?: string;
|
|
179
|
+
}) => {
|
|
180
|
+
const pathLikeName = schemaFile ?? filePath ?? sourcePath ?? schemaRef ?? schemaId;
|
|
181
|
+
return referenceName ?? resolvedName ?? path.basename(pathLikeName) ?? messageName ?? 'Schema';
|
|
182
|
+
};
|
|
183
|
+
|
|
90
184
|
const schemaFileExists = (schema: MessageSchemaResource): schema is MessageSchemaResource & { filePath: string } =>
|
|
91
185
|
Boolean(schema.filePath && fsSync.existsSync(schema.filePath));
|
|
92
186
|
|
|
187
|
+
const getSchemaProvider = (id: string) => {
|
|
188
|
+
try {
|
|
189
|
+
const url = new URL(id);
|
|
190
|
+
return url.protocol.replace(':', '') || 'external';
|
|
191
|
+
} catch {
|
|
192
|
+
return 'external';
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const isFileSchemaRef = (ref?: string) => ref?.startsWith(FILE_SCHEMA_REF_PREFIX);
|
|
197
|
+
|
|
198
|
+
const getFileSchemaRefPath = (ref: string, messageFilePath: string) => {
|
|
199
|
+
if (ref.startsWith('file:///') || ref.startsWith('file://localhost/')) {
|
|
200
|
+
try {
|
|
201
|
+
const filePath = fileURLToPath(ref);
|
|
202
|
+
return {
|
|
203
|
+
filePath,
|
|
204
|
+
sourcePath: filePath,
|
|
205
|
+
};
|
|
206
|
+
} catch {
|
|
207
|
+
throw new Error(`Invalid file schema ref "${ref}". Expected file://<relative-path> or file:///absolute/path.`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const sourcePath = decodeURIComponent(ref.slice(FILE_SCHEMA_REF_PREFIX.length));
|
|
212
|
+
if (!sourcePath) {
|
|
213
|
+
throw new Error(`Invalid file schema ref "${ref}". Expected file://<relative-path> or file:///absolute/path.`);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return {
|
|
217
|
+
filePath: path.resolve(path.dirname(messageFilePath), sourcePath),
|
|
218
|
+
sourcePath,
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const getTimestamp = () => {
|
|
223
|
+
const now = new Date();
|
|
224
|
+
return now.toLocaleTimeString('en-US', { hour12: false });
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const logSchemaInfo = (message: string) => {
|
|
228
|
+
console.log(`${colors.dim(getTimestamp())} ${colors.blue('[schemas]')} ${message}`);
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const getMessageTypeLabel = (collection: MessageCollection) => {
|
|
232
|
+
if (collection === 'events') return 'event';
|
|
233
|
+
if (collection === 'commands') return 'command';
|
|
234
|
+
return 'query';
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const getErrorMessage = (error: unknown) => {
|
|
238
|
+
return error instanceof Error ? error.message : String(error);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const getSchemaResolveRef = (schema: MessageSchemaResource) => schema.ref ?? schema.id;
|
|
242
|
+
|
|
243
|
+
const buildSchemaSourceErrorMessage = ({
|
|
244
|
+
schema,
|
|
245
|
+
source,
|
|
246
|
+
error,
|
|
247
|
+
}: {
|
|
248
|
+
schema: MessageSchemaResource;
|
|
249
|
+
source: SchemaSource;
|
|
250
|
+
error: unknown;
|
|
251
|
+
}) => {
|
|
252
|
+
const messageType = getMessageTypeLabel(schema.message.collection);
|
|
253
|
+
|
|
254
|
+
return [
|
|
255
|
+
'',
|
|
256
|
+
colors.red(colors.bold('[schemas] Failed to resolve schema')),
|
|
257
|
+
'',
|
|
258
|
+
` Message: ${messageType} "${schema.message.id}" version "${schema.message.version}"`,
|
|
259
|
+
` Schema: ${getSchemaResolveRef(schema)}`,
|
|
260
|
+
` Source: ${source.name}`,
|
|
261
|
+
'',
|
|
262
|
+
colors.bold('Reason:'),
|
|
263
|
+
` ${getErrorMessage(error)}`,
|
|
264
|
+
'',
|
|
265
|
+
].join('\n');
|
|
266
|
+
};
|
|
267
|
+
|
|
93
268
|
const addLatestMetadata = (schemas: MessageSchemaResource[]) => {
|
|
94
269
|
const schemasByMessage = schemas.reduce(
|
|
95
270
|
(acc, schema) => {
|
|
@@ -138,11 +313,10 @@ export const getMessageSchemasFromFrontmatter = ({
|
|
|
138
313
|
};
|
|
139
314
|
|
|
140
315
|
const schemaReferences =
|
|
141
|
-
data.schemas?.filter((schema) => getSchemaFile(schema)) ??
|
|
316
|
+
data.schemas?.filter((schema) => getSchemaRef(schema) || getSchemaFile(schema)) ??
|
|
142
317
|
(data.schemaPath
|
|
143
318
|
? [
|
|
144
319
|
{
|
|
145
|
-
id: buildGeneratedSchemaId(message, data.schemaPath),
|
|
146
320
|
file: data.schemaPath,
|
|
147
321
|
name: 'Schema',
|
|
148
322
|
default: true,
|
|
@@ -151,29 +325,123 @@ export const getMessageSchemasFromFrontmatter = ({
|
|
|
151
325
|
: []);
|
|
152
326
|
|
|
153
327
|
return schemaReferences.map((reference) => {
|
|
154
|
-
const schemaFile = getSchemaFile(reference)
|
|
155
|
-
const
|
|
156
|
-
const
|
|
328
|
+
const schemaFile = getSchemaFile(reference);
|
|
329
|
+
const schemaRef = getSchemaRef(reference);
|
|
330
|
+
const fileSchemaRef = isFileSchemaRef(schemaRef) ? getFileSchemaRefPath(schemaRef as string, messageFilePath) : undefined;
|
|
331
|
+
const schemaFilePath = schemaFile ? path.resolve(path.dirname(messageFilePath), schemaFile) : fileSchemaRef?.filePath;
|
|
332
|
+
const schemaId = getSchemaCollectionId({ message, reference, schemaRef, schemaFile });
|
|
333
|
+
const schemaPathForFormat = schemaFile ?? fileSchemaRef?.filePath;
|
|
157
334
|
|
|
158
335
|
return {
|
|
159
336
|
id: schemaId,
|
|
160
|
-
|
|
337
|
+
...(reference.id && !schemaRef ? { schemaId: reference.id } : {}),
|
|
338
|
+
...(schemaRef ? { ref: schemaRef } : {}),
|
|
339
|
+
name: getSchemaDisplayName({
|
|
340
|
+
referenceName: reference.name,
|
|
341
|
+
schemaFile,
|
|
342
|
+
filePath: fileSchemaRef?.filePath,
|
|
343
|
+
schemaRef,
|
|
344
|
+
schemaId,
|
|
345
|
+
messageName: data.name,
|
|
346
|
+
}),
|
|
161
347
|
version: data.version,
|
|
162
|
-
format: reference.format ?? getSchemaFormat(
|
|
348
|
+
format: reference.format ?? (schemaPathForFormat ? getSchemaFormat(schemaPathForFormat) : 'unknown'),
|
|
163
349
|
file: schemaFile,
|
|
164
350
|
filePath: schemaFilePath,
|
|
165
351
|
environments: reference.environments,
|
|
166
352
|
default: reference.default,
|
|
167
353
|
message,
|
|
168
354
|
source: {
|
|
169
|
-
provider: 'file',
|
|
170
|
-
path: schemaFile,
|
|
355
|
+
provider: schemaFile || fileSchemaRef ? 'file' : getSchemaProvider(schemaRef ?? schemaId),
|
|
356
|
+
path: schemaFile ?? fileSchemaRef?.sourcePath,
|
|
171
357
|
},
|
|
172
358
|
};
|
|
173
359
|
});
|
|
174
360
|
};
|
|
175
361
|
|
|
176
|
-
|
|
362
|
+
const resolveSchemaSource = async (
|
|
363
|
+
schema: InternalMessageSchemaResource,
|
|
364
|
+
source: SchemaSource
|
|
365
|
+
): Promise<InternalMessageSchemaResource | undefined> => {
|
|
366
|
+
if (schemaFileExists(schema)) return schema;
|
|
367
|
+
if (schema.filePath) return undefined;
|
|
368
|
+
|
|
369
|
+
let resolvedSchema: Awaited<ReturnType<SchemaSource['resolve']>>;
|
|
370
|
+
const schemaResolveRef = getSchemaResolveRef(schema);
|
|
371
|
+
|
|
372
|
+
try {
|
|
373
|
+
resolvedSchema = await source.resolve(schemaResolveRef, schema._context);
|
|
374
|
+
} catch (error) {
|
|
375
|
+
throw new Error(buildSchemaSourceErrorMessage({ schema, source, error }));
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (!resolvedSchema) return undefined;
|
|
379
|
+
|
|
380
|
+
const resolvedMessageSchema: InternalMessageSchemaResource = {
|
|
381
|
+
...schema,
|
|
382
|
+
format: schema.format !== 'unknown' ? schema.format : (resolvedSchema.format ?? 'unknown'),
|
|
383
|
+
content: resolvedSchema.content,
|
|
384
|
+
source: resolvedSchema.source,
|
|
385
|
+
readOnly: true,
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
resolvedMessageSchema.name = getSchemaDisplayName({
|
|
389
|
+
referenceName: schema.name,
|
|
390
|
+
resolvedName: resolvedSchema.name,
|
|
391
|
+
schemaRef: schema.ref,
|
|
392
|
+
sourcePath: resolvedSchema.source.path,
|
|
393
|
+
schemaId: schema.id,
|
|
394
|
+
messageName: schema.message.name,
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
return resolvedMessageSchema;
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
const resolveSchemaSources = async (schemas: InternalMessageSchemaResource[], sources: SchemaSource[] = []) => {
|
|
401
|
+
if (sources.length > 0 && !isEventCatalogScaleEnabled()) {
|
|
402
|
+
throw new Error('Schema sources require EventCatalog Scale.');
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const localSchemas = schemas.filter(schemaFileExists);
|
|
406
|
+
const externalSchemas = schemas.filter((schema) => !schema.filePath);
|
|
407
|
+
const resolvedExternalSchemas: InternalMessageSchemaResource[] = [];
|
|
408
|
+
const resolvedExternalSchemaIds = new Set<string>();
|
|
409
|
+
|
|
410
|
+
for (const source of sources) {
|
|
411
|
+
const sourceSchemas = externalSchemas.filter((schema) => source.canResolve(getSchemaResolveRef(schema)));
|
|
412
|
+
if (sourceSchemas.length === 0) continue;
|
|
413
|
+
|
|
414
|
+
logSchemaInfo(
|
|
415
|
+
`Loading ${sourceSchemas.length} schema${sourceSchemas.length === 1 ? '' : 's'} from schema source "${source.name}"`
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
const resolvedSchemas = await Promise.all(sourceSchemas.map((schema) => resolveSchemaSource(schema, source)));
|
|
419
|
+
const syncedSchemas = resolvedSchemas.filter((schema): schema is InternalMessageSchemaResource => schema !== undefined);
|
|
420
|
+
|
|
421
|
+
for (const schema of syncedSchemas) {
|
|
422
|
+
resolvedExternalSchemaIds.add(schema.id);
|
|
423
|
+
resolvedExternalSchemas.push(schema);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const skippedSchemas = sourceSchemas.length - syncedSchemas.length;
|
|
427
|
+
logSchemaInfo(
|
|
428
|
+
`Synced ${syncedSchemas.length} schema${syncedSchemas.length === 1 ? '' : 's'} from schema source "${source.name}"${
|
|
429
|
+
skippedSchemas > 0 ? ` (${skippedSchemas} skipped)` : ''
|
|
430
|
+
}`
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return [
|
|
435
|
+
...localSchemas,
|
|
436
|
+
...resolvedExternalSchemas,
|
|
437
|
+
...schemas.filter((schema) => schema.filePath && !schemaFileExists(schema)),
|
|
438
|
+
].filter((schema) => {
|
|
439
|
+
if (schema.filePath) return schemaFileExists(schema);
|
|
440
|
+
return resolvedExternalSchemaIds.has(schema.id);
|
|
441
|
+
});
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
const loadMessageSchemaResources = async ({ pattern, base }: SchemaLoaderOptions['messages']) => {
|
|
177
445
|
if (!base) return [];
|
|
178
446
|
|
|
179
447
|
const files = await glob(pattern, {
|
|
@@ -189,14 +457,32 @@ export const loadMessageSchemas = async ({ pattern, base }: SchemaLoaderOptions[
|
|
|
189
457
|
if (!collection) return [];
|
|
190
458
|
|
|
191
459
|
const { data } = matter.read(file) as { data: MessageFrontmatter };
|
|
192
|
-
return getMessageSchemasFromFrontmatter({ data, collection, messageFilePath: file })
|
|
460
|
+
return getMessageSchemasFromFrontmatter({ data, collection, messageFilePath: file }).map((schema) => ({
|
|
461
|
+
...schema,
|
|
462
|
+
_context: {
|
|
463
|
+
messageFilePath: file,
|
|
464
|
+
},
|
|
465
|
+
}));
|
|
193
466
|
})
|
|
194
467
|
);
|
|
195
468
|
|
|
196
|
-
return
|
|
469
|
+
return schemas.flat();
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
const stripSchemaLoaderContext = (schema: InternalMessageSchemaResource): MessageSchemaResource => {
|
|
473
|
+
const { _context, ...publicSchema } = schema;
|
|
474
|
+
return publicSchema;
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
export const loadMessageSchemas = async (messages: SchemaLoaderOptions['messages'], sources: SchemaSource[] = []) => {
|
|
478
|
+
const schemas = await loadMessageSchemaResources(messages);
|
|
479
|
+
const resolvedSchemas = await resolveSchemaSources(schemas, sources);
|
|
480
|
+
|
|
481
|
+
return addLatestMetadata(resolvedSchemas.map(stripSchemaLoaderContext));
|
|
197
482
|
};
|
|
198
483
|
|
|
199
484
|
const getSchemaBody = async (schema: MessageSchemaResource) => {
|
|
485
|
+
if (schema.content !== undefined) return schema.content;
|
|
200
486
|
if (!schemaFileExists(schema)) return undefined;
|
|
201
487
|
return fs.readFile(schema.filePath, 'utf8');
|
|
202
488
|
};
|
|
@@ -222,12 +508,12 @@ const setSchema = async (context: LoaderContext, schema: MessageSchemaResource)
|
|
|
222
508
|
});
|
|
223
509
|
};
|
|
224
510
|
|
|
225
|
-
export const schemaLoader = ({ messages }: SchemaLoaderOptions): Loader => {
|
|
511
|
+
export const schemaLoader = ({ messages, sources = [] }: SchemaLoaderOptions): Loader => {
|
|
226
512
|
return {
|
|
227
513
|
name: 'eventcatalog-schema-loader',
|
|
228
514
|
load: async (context) => {
|
|
229
515
|
context.store.clear();
|
|
230
|
-
const schemas = await loadMessageSchemas(messages);
|
|
516
|
+
const schemas = await loadMessageSchemas(messages, sources);
|
|
231
517
|
|
|
232
518
|
for (const schema of schemas) {
|
|
233
519
|
await setSchema(context, schema);
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"license": "SEE LICENSE IN LICENSE",
|
|
9
9
|
"type": "module",
|
|
10
|
-
"version": "3.
|
|
10
|
+
"version": "3.46.1",
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
@@ -65,7 +65,6 @@
|
|
|
65
65
|
"auth-astro": "^4.2.0",
|
|
66
66
|
"boxen": "^8.0.1",
|
|
67
67
|
"commander": "^12.1.0",
|
|
68
|
-
"concurrently": "^8.2.2",
|
|
69
68
|
"cross-env": "^7.0.3",
|
|
70
69
|
"dagre": "^0.8.5",
|
|
71
70
|
"diff": "^8.0.3",
|
|
@@ -74,7 +73,7 @@
|
|
|
74
73
|
"elkjs": "^0.10.0",
|
|
75
74
|
"glob": "^13.0.6",
|
|
76
75
|
"gray-matter": "^4.0.3",
|
|
77
|
-
"hono": "4.12.
|
|
76
|
+
"hono": "4.12.21",
|
|
78
77
|
"html-to-image": "^1.11.11",
|
|
79
78
|
"js-yaml": "^4.1.1",
|
|
80
79
|
"jsonpath-plus": "^10.4.0",
|
|
@@ -112,8 +111,8 @@
|
|
|
112
111
|
"update-notifier": "^7.3.1",
|
|
113
112
|
"uuid": "^10.0.0",
|
|
114
113
|
"zod": "^4.3.6",
|
|
115
|
-
"@eventcatalog/sdk": "2.24.1",
|
|
116
114
|
"@eventcatalog/linter": "1.0.29",
|
|
115
|
+
"@eventcatalog/sdk": "2.24.1",
|
|
117
116
|
"@eventcatalog/visualiser": "^3.22.1"
|
|
118
117
|
},
|
|
119
118
|
"devDependencies": {
|