@eventcatalog/core 4.7.3 → 4.7.5

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.
Files changed (48) hide show
  1. package/dist/analytics/analytics.cjs +1 -1
  2. package/dist/analytics/analytics.js +2 -2
  3. package/dist/analytics/log-build.cjs +1 -1
  4. package/dist/analytics/log-build.js +3 -3
  5. package/dist/{chunk-SMDTRRED.js → chunk-2BYTIH4L.js} +1 -1
  6. package/dist/chunk-A2RZR3U4.js +29 -0
  7. package/dist/{chunk-XXJX3WWF.js → chunk-EUZT4RKY.js} +1 -1
  8. package/dist/chunk-GYYYAUJD.js +276 -0
  9. package/dist/chunk-JJPB6EOZ.js +159 -0
  10. package/dist/{chunk-GINIJSFI.js → chunk-QJRY6Q7S.js} +1 -1
  11. package/dist/{chunk-IALEXWSE.js → chunk-QQPH6RCB.js} +24 -1
  12. package/dist/chunk-SDZQJTJW.js +90 -0
  13. package/dist/chunk-WRNH5C3U.js +118 -0
  14. package/dist/{chunk-V4FAVGI7.js → chunk-ZBPMCEXS.js} +1 -1
  15. package/dist/constants.cjs +1 -1
  16. package/dist/constants.js +1 -1
  17. package/dist/eventcatalog.cjs +707 -255
  18. package/dist/eventcatalog.config.d.cts +12 -6
  19. package/dist/eventcatalog.config.d.ts +12 -6
  20. package/dist/eventcatalog.js +42 -42
  21. package/dist/federation/diagnostics.cjs +187 -0
  22. package/dist/federation/diagnostics.d.cts +23 -0
  23. package/dist/federation/diagnostics.d.ts +23 -0
  24. package/dist/federation/diagnostics.js +14 -0
  25. package/dist/federation/federate.cjs +605 -174
  26. package/dist/federation/federate.d.cts +8 -1
  27. package/dist/federation/federate.d.ts +8 -1
  28. package/dist/federation/federate.js +8 -2
  29. package/dist/federation/filesystem-source-provider.cjs +124 -0
  30. package/dist/federation/filesystem-source-provider.d.cts +7 -0
  31. package/dist/federation/filesystem-source-provider.d.ts +7 -0
  32. package/dist/federation/filesystem-source-provider.js +6 -0
  33. package/dist/federation/output-transaction.cjs +152 -0
  34. package/dist/federation/output-transaction.d.cts +3 -0
  35. package/dist/federation/output-transaction.d.ts +3 -0
  36. package/dist/federation/output-transaction.js +6 -0
  37. package/dist/federation/source-provider.cjs +265 -0
  38. package/dist/federation/source-provider.d.cts +11 -0
  39. package/dist/federation/source-provider.d.ts +11 -0
  40. package/dist/federation/source-provider.js +8 -0
  41. package/dist/generate.cjs +24 -1
  42. package/dist/generate.js +3 -3
  43. package/dist/utils/cli-logger.cjs +24 -1
  44. package/dist/utils/cli-logger.d.cts +6 -0
  45. package/dist/utils/cli-logger.d.ts +6 -0
  46. package/dist/utils/cli-logger.js +2 -2
  47. package/package.json +3 -3
  48. package/dist/chunk-ZR6AH5Z2.js +0 -204
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/federation/source-provider.ts
31
+ var source_provider_exports = {};
32
+ __export(source_provider_exports, {
33
+ createFederationSourceProvider: () => createFederationSourceProvider
34
+ });
35
+ module.exports = __toCommonJS(source_provider_exports);
36
+
37
+ // src/federation/filesystem-source-provider.ts
38
+ var import_node_crypto = require("crypto");
39
+ var import_promises = __toESM(require("fs/promises"), 1);
40
+ var import_node_path = __toESM(require("path"), 1);
41
+ var import_sdk = __toESM(require("@eventcatalog/sdk"), 1);
42
+ var FILESYSTEM_SOURCE_PREFIX = "file:";
43
+ var isWithinDirectory = (directory, target) => {
44
+ const relativePath = import_node_path.default.relative(directory, target);
45
+ return relativePath === "" || !relativePath.startsWith(`..${import_node_path.default.sep}`) && relativePath !== ".." && !import_node_path.default.isAbsolute(relativePath);
46
+ };
47
+ var assertPortableRelativePath = (filePath, label, allowRoot = true) => {
48
+ const portablePath = filePath.replaceAll("\\", "/");
49
+ const normalizedPath = import_node_path.default.posix.normalize(portablePath);
50
+ const isUnsafe = filePath.includes("\\") || filePath.includes("\0") || import_node_path.default.posix.isAbsolute(normalizedPath) || /^[a-zA-Z]:\//.test(normalizedPath) || normalizedPath === ".." || normalizedPath.startsWith("../") || !allowRoot && (normalizedPath === "." || normalizedPath === "");
51
+ if (isUnsafe) throw new Error(`${label} "${filePath}" escapes its filesystem source`);
52
+ return normalizedPath;
53
+ };
54
+ var getSourceRoot = (projectDirectory, source) => {
55
+ if (!source.source.startsWith(FILESYSTEM_SOURCE_PREFIX)) {
56
+ throw new Error(`Unsupported federation source "${source.source}". Expected file:path/to/catalog.`);
57
+ }
58
+ const locator = source.source.slice(FILESYSTEM_SOURCE_PREFIX.length);
59
+ if (!locator.trim()) throw new Error(`Filesystem federation source "${source.id}" requires a path after "file:".`);
60
+ return import_node_path.default.resolve(projectDirectory, locator);
61
+ };
62
+ var getCatalogDirectory = async (projectDirectory, source) => {
63
+ if (source.ref) throw new Error(`Filesystem federation source "${source.id}" does not support "ref".`);
64
+ const sourceRoot = getSourceRoot(projectDirectory, source);
65
+ const catalogPath = assertPortableRelativePath(source.path ?? ".", "Catalog path");
66
+ const catalogDirectory = import_node_path.default.resolve(sourceRoot, ...catalogPath.split("/"));
67
+ if (!isWithinDirectory(sourceRoot, catalogDirectory)) {
68
+ throw new Error(`Catalog path "${source.path}" escapes source "${source.id}"`);
69
+ }
70
+ try {
71
+ const [realSourceRoot, realCatalogDirectory] = await Promise.all([import_promises.default.realpath(sourceRoot), import_promises.default.realpath(catalogDirectory)]);
72
+ if (!isWithinDirectory(realSourceRoot, realCatalogDirectory)) {
73
+ throw new Error(`Catalog path "${source.path}" escapes source "${source.id}"`);
74
+ }
75
+ if (!(await import_promises.default.stat(realCatalogDirectory)).isDirectory()) {
76
+ throw new Error(`Filesystem federation source "${source.id}" is not a directory: ${catalogDirectory}`);
77
+ }
78
+ return realCatalogDirectory;
79
+ } catch (error) {
80
+ if (error.code === "ENOENT") {
81
+ throw new Error(`Filesystem federation source "${source.id}" does not exist: ${catalogDirectory}`, { cause: error });
82
+ }
83
+ throw error;
84
+ }
85
+ };
86
+ var getArtifactPath = async (catalogDirectory, source, artifactPath) => {
87
+ const normalizedPath = assertPortableRelativePath(artifactPath, "Federated artifact path", false);
88
+ const filePath = import_node_path.default.resolve(catalogDirectory, ...normalizedPath.split("/"));
89
+ if (!isWithinDirectory(catalogDirectory, filePath)) {
90
+ throw new Error(`Federated artifact path "${artifactPath}" escapes source "${source.id}"`);
91
+ }
92
+ try {
93
+ const realFilePath = await import_promises.default.realpath(filePath);
94
+ if (!isWithinDirectory(catalogDirectory, realFilePath)) {
95
+ throw new Error(`Federated artifact path "${artifactPath}" escapes source "${source.id}"`);
96
+ }
97
+ return realFilePath;
98
+ } catch (error) {
99
+ if (error.code === "ENOENT") {
100
+ throw new Error(`Federated artifact not found for "${source.id}": ${artifactPath}`, { cause: error });
101
+ }
102
+ throw error;
103
+ }
104
+ };
105
+ var createFileSystemSourceProvider = (projectDirectory) => ({
106
+ async resolve(source) {
107
+ const catalogDirectory = await getCatalogDirectory(projectDirectory, source);
108
+ const localIndex = await (0, import_sdk.default)(catalogDirectory).buildIndex({
109
+ source: source.id,
110
+ commit: "local",
111
+ includeFederated: false
112
+ });
113
+ const snapshot = (0, import_node_crypto.createHash)("sha256").update(JSON.stringify(localIndex)).digest("hex").slice(0, 12);
114
+ const index = { ...localIndex, commit: `local:${snapshot}` };
115
+ const bytes = Buffer.from(JSON.stringify(index));
116
+ return { bytes, index, commit: index.commit, generated: true };
117
+ },
118
+ async fetchContent({ source, path: artifactPath }) {
119
+ const catalogDirectory = await getCatalogDirectory(projectDirectory, source);
120
+ return import_promises.default.readFile(await getArtifactPath(catalogDirectory, source, artifactPath));
121
+ }
122
+ });
123
+
124
+ // src/federation/github-source-provider.ts
125
+ var import_node_child_process = require("child_process");
126
+ var import_promises2 = __toESM(require("fs/promises"), 1);
127
+ var import_node_os = __toESM(require("os"), 1);
128
+ var import_node_path2 = __toESM(require("path"), 1);
129
+ var import_node_util = require("util");
130
+ var import_sdk2 = __toESM(require("@eventcatalog/sdk"), 1);
131
+ var execFileAsync = (0, import_node_util.promisify)(import_node_child_process.execFile);
132
+ var parseGitHubSource = (source) => {
133
+ const match = /^github:([^/]+)\/(.+)$/.exec(source.source);
134
+ if (!match) throw new Error(`Unsupported federation source "${source.source}". Expected github:owner/repository.`);
135
+ return { owner: match[1], repository: match[2] };
136
+ };
137
+ var assertSafeCatalogPath = (source) => {
138
+ const catalogPath = source.path ?? ".";
139
+ const normalized = import_node_path2.default.posix.normalize(catalogPath.replaceAll("\\", "/"));
140
+ if (catalogPath.includes("\\") || import_node_path2.default.posix.isAbsolute(normalized) || normalized === ".." || normalized.startsWith("../")) {
141
+ throw new Error(`Catalog path "${catalogPath}" escapes source "${source.id}"`);
142
+ }
143
+ };
144
+ var encodePath = (value) => value.split("/").filter(Boolean).map(encodeURIComponent).join("/");
145
+ var rawUrl = (source, ref, filePath) => {
146
+ const { owner, repository } = parseGitHubSource(source);
147
+ return `https://raw.githubusercontent.com/${encodeURIComponent(owner)}/${encodeURIComponent(repository)}/${encodeURIComponent(
148
+ ref
149
+ )}/${encodePath(filePath)}`;
150
+ };
151
+ var contentsApiUrl = (source, ref, filePath) => {
152
+ const { owner, repository } = parseGitHubSource(source);
153
+ return `https://api.github.com/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repository)}/contents/${encodePath(
154
+ filePath
155
+ )}?ref=${encodeURIComponent(ref)}`;
156
+ };
157
+ var fetchBytes = async (source, ref, filePath, fetcher, token) => {
158
+ const url = token ? contentsApiUrl(source, ref, filePath) : rawUrl(source, ref, filePath);
159
+ const response = token ? await fetcher(url, {
160
+ headers: {
161
+ Accept: "application/vnd.github.raw+json",
162
+ Authorization: `Bearer ${token}`,
163
+ "X-GitHub-Api-Version": "2026-03-10"
164
+ }
165
+ }) : await fetcher(url);
166
+ if (response.status === 404) return void 0;
167
+ if (!response.ok) throw new Error(`Failed to fetch ${url}: ${response.status} ${response.statusText}`);
168
+ return Buffer.from(await response.arrayBuffer());
169
+ };
170
+ var getGitEnvironment = (token) => {
171
+ if (!token) return process.env;
172
+ const inheritedCount = Number.parseInt(process.env.GIT_CONFIG_COUNT ?? "0", 10);
173
+ const configIndex = Number.isInteger(inheritedCount) && inheritedCount >= 0 ? inheritedCount : 0;
174
+ return {
175
+ ...process.env,
176
+ GIT_CONFIG_COUNT: String(configIndex + 1),
177
+ [`GIT_CONFIG_KEY_${configIndex}`]: "http.https://github.com/.extraheader",
178
+ [`GIT_CONFIG_VALUE_${configIndex}`]: `AUTHORIZATION: basic ${Buffer.from(`x-access-token:${token}`).toString("base64")}`
179
+ };
180
+ };
181
+ var createCheckout = (executeFile, token) => async (source, ref, callback) => {
182
+ const { owner, repository } = parseGitHubSource(source);
183
+ const catalogPath = import_node_path2.default.posix.normalize(source.path ?? ".");
184
+ const directory = await import_promises2.default.mkdtemp(import_node_path2.default.join(import_node_os.default.tmpdir(), "eventcatalog-federation-"));
185
+ const env = getGitEnvironment(token);
186
+ try {
187
+ const git = (args) => executeFile("git", args, { cwd: directory, env, encoding: "utf8" });
188
+ await git(["init", "--quiet"]);
189
+ await git(["remote", "add", "origin", `https://github.com/${owner}/${repository}.git`]);
190
+ if (catalogPath !== ".") {
191
+ await git(["sparse-checkout", "init", "--cone"]);
192
+ await git(["sparse-checkout", "set", catalogPath]);
193
+ }
194
+ await git(["fetch", "--quiet", "--depth", "1", "origin", ref]);
195
+ await git(["checkout", "--quiet", "--detach", "FETCH_HEAD"]);
196
+ return await callback(directory);
197
+ } finally {
198
+ await import_promises2.default.rm(directory, { recursive: true, force: true });
199
+ }
200
+ };
201
+ var generateIndex = async (source, ref, checkout, executeFile) => checkout(source, ref, async (directory) => {
202
+ const { stdout } = await executeFile("git", ["rev-parse", "HEAD"], { cwd: directory, encoding: "utf8" });
203
+ const commit = stdout.trim();
204
+ const catalogDirectory = import_node_path2.default.resolve(directory, source.path ?? ".");
205
+ const relativeCatalogDirectory = import_node_path2.default.relative(directory, catalogDirectory);
206
+ if (relativeCatalogDirectory.startsWith("..") || import_node_path2.default.isAbsolute(relativeCatalogDirectory)) {
207
+ throw new Error(`Catalog path "${source.path}" escapes source "${source.id}"`);
208
+ }
209
+ const index = await (0, import_sdk2.default)(catalogDirectory).buildIndex({ source: source.id, commit });
210
+ return { bytes: Buffer.from(JSON.stringify(index)), index, commit, generated: true };
211
+ });
212
+ var fetchPublishedIndex = async (source, ref, fetcher, token) => {
213
+ const indexPath = import_node_path2.default.posix.join(source.path ?? ".", "catalog.index.json");
214
+ const bytes = await fetchBytes(source, ref, indexPath, fetcher, token);
215
+ if (!bytes) return void 0;
216
+ const index = (0, import_sdk2.parseIndex)(JSON.parse(bytes.toString("utf8")));
217
+ if (index.source !== source.id) {
218
+ throw new Error(`Published index source "${index.source}" does not match configured id "${source.id}"`);
219
+ }
220
+ return { bytes, index, commit: index.commit, generated: false };
221
+ };
222
+ var createGitHubSourceProvider = (options = {}) => {
223
+ const fetcher = options.fetch ?? ((url, init) => fetch(url, init));
224
+ const executeFile = options.execFile ?? ((file, args, execOptions) => execFileAsync(file, args, execOptions));
225
+ const configuredToken = options.token ?? process.env.EVENTCATALOG_GITHUB_TOKEN ?? process.env.GITHUB_TOKEN;
226
+ const token = configuredToken?.trim() || void 0;
227
+ const checkout = options.checkout ?? createCheckout(executeFile, token);
228
+ return {
229
+ async resolve(source) {
230
+ assertSafeCatalogPath(source);
231
+ const ref = source.ref ?? "main";
232
+ return await fetchPublishedIndex(source, ref, fetcher, token) ?? generateIndex(source, ref, checkout, executeFile);
233
+ },
234
+ async fetchContent({ source, commit, path: artifactPath }) {
235
+ assertSafeCatalogPath(source);
236
+ const catalogPath = import_node_path2.default.posix.join(source.path ?? ".", artifactPath);
237
+ const content = await fetchBytes(source, commit, catalogPath, fetcher, token);
238
+ if (!content) throw new Error(`Federated artifact not found for "${source.id}": ${artifactPath}`);
239
+ return content;
240
+ }
241
+ };
242
+ };
243
+
244
+ // src/federation/source-provider.ts
245
+ var createFederationSourceProvider = (projectDirectory, providers = {}) => {
246
+ const github = providers.github ?? createGitHubSourceProvider();
247
+ const filesystem = providers.filesystem ?? createFileSystemSourceProvider(projectDirectory);
248
+ const getProvider = (source) => {
249
+ if (source.source.startsWith("github:")) return github;
250
+ if (source.source.startsWith("file:")) return filesystem;
251
+ throw new Error(`Unsupported federation source "${source.source}" for "${source.id}". Supported protocols: github:, file:.`);
252
+ };
253
+ return {
254
+ async resolve(source) {
255
+ return getProvider(source).resolve(source);
256
+ },
257
+ async fetchContent(request) {
258
+ return getProvider(request.source).fetchContent(request);
259
+ }
260
+ };
261
+ };
262
+ // Annotate the CommonJS export names for ESM import in node:
263
+ 0 && (module.exports = {
264
+ createFederationSourceProvider
265
+ });
@@ -0,0 +1,11 @@
1
+ import { FederationSourceProvider } from './types.cjs';
2
+ import '@eventcatalog/sdk';
3
+ import '../eventcatalog.config.cjs';
4
+
5
+ type FederationSourceProviders = {
6
+ github?: FederationSourceProvider;
7
+ filesystem?: FederationSourceProvider;
8
+ };
9
+ declare const createFederationSourceProvider: (projectDirectory: string, providers?: FederationSourceProviders) => FederationSourceProvider;
10
+
11
+ export { createFederationSourceProvider };
@@ -0,0 +1,11 @@
1
+ import { FederationSourceProvider } from './types.js';
2
+ import '@eventcatalog/sdk';
3
+ import '../eventcatalog.config.js';
4
+
5
+ type FederationSourceProviders = {
6
+ github?: FederationSourceProvider;
7
+ filesystem?: FederationSourceProvider;
8
+ };
9
+ declare const createFederationSourceProvider: (projectDirectory: string, providers?: FederationSourceProviders) => FederationSourceProvider;
10
+
11
+ export { createFederationSourceProvider };
@@ -0,0 +1,8 @@
1
+ import {
2
+ createFederationSourceProvider
3
+ } from "../chunk-A2RZR3U4.js";
4
+ import "../chunk-SDZQJTJW.js";
5
+ import "../chunk-352FGP6W.js";
6
+ export {
7
+ createFederationSourceProvider
8
+ };
package/dist/generate.cjs CHANGED
@@ -108,7 +108,7 @@ var getEventCatalogConfigFile = async (projectDirectory) => {
108
108
  var import_picocolors = __toESM(require("picocolors"), 1);
109
109
 
110
110
  // package.json
111
- var version = "4.7.3";
111
+ var version = "4.7.5";
112
112
 
113
113
  // src/constants.ts
114
114
  var VERSION = version;
@@ -147,6 +147,29 @@ var logger = {
147
147
  warning: (message, tag = "warn") => {
148
148
  console.log(formatMessage(tag, message, import_picocolors.default.yellow));
149
149
  },
150
+ line: (message = "") => {
151
+ console.log(message);
152
+ },
153
+ diagnostic: (severity, message, rule, attributes = []) => {
154
+ const isError = severity === "error";
155
+ const color = isError ? import_picocolors.default.red : import_picocolors.default.yellow;
156
+ const icon = isError ? "\u2716" : "\u26A0";
157
+ const label = `${icon} ${severity.padEnd(7)} ${message}`;
158
+ const ruleSpacing = " ".repeat(Math.max(2, 72 - label.length));
159
+ console.log(` ${color(icon)} ${color(severity.padEnd(7))} ${message}${ruleSpacing}${import_picocolors.default.gray(rule)}`);
160
+ for (const attribute of attributes) {
161
+ console.log(` - ${import_picocolors.default.dim(`${attribute.label}:`)} ${attribute.value}`);
162
+ }
163
+ },
164
+ diagnosticSummary: (errors, warnings) => {
165
+ const total = errors + warnings;
166
+ const color = errors > 0 ? import_picocolors.default.red : import_picocolors.default.yellow;
167
+ const icon = errors > 0 ? "\u2716" : "\u26A0";
168
+ const problems = `${total} problem${total === 1 ? "" : "s"}`;
169
+ const errorCount = `${errors} error${errors === 1 ? "" : "s"}`;
170
+ const warningCount = `${warnings} warning${warnings === 1 ? "" : "s"}`;
171
+ console.log(color(`${icon} ${problems} (${errorCount}, ${warningCount})`));
172
+ },
150
173
  dim: (message) => {
151
174
  console.log(import_picocolors.default.dim(message));
152
175
  }
package/dist/generate.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  generate
3
- } from "./chunk-XXJX3WWF.js";
4
- import "./chunk-IALEXWSE.js";
5
- import "./chunk-V4FAVGI7.js";
3
+ } from "./chunk-EUZT4RKY.js";
4
+ import "./chunk-QQPH6RCB.js";
5
+ import "./chunk-ZBPMCEXS.js";
6
6
  import "./chunk-6QENHZZP.js";
7
7
  export {
8
8
  generate
@@ -36,7 +36,7 @@ module.exports = __toCommonJS(cli_logger_exports);
36
36
  var import_picocolors = __toESM(require("picocolors"), 1);
37
37
 
38
38
  // package.json
39
- var version = "4.7.3";
39
+ var version = "4.7.5";
40
40
 
41
41
  // src/constants.ts
42
42
  var VERSION = version;
@@ -75,6 +75,29 @@ var logger = {
75
75
  warning: (message, tag = "warn") => {
76
76
  console.log(formatMessage(tag, message, import_picocolors.default.yellow));
77
77
  },
78
+ line: (message = "") => {
79
+ console.log(message);
80
+ },
81
+ diagnostic: (severity, message, rule, attributes = []) => {
82
+ const isError = severity === "error";
83
+ const color = isError ? import_picocolors.default.red : import_picocolors.default.yellow;
84
+ const icon = isError ? "\u2716" : "\u26A0";
85
+ const label = `${icon} ${severity.padEnd(7)} ${message}`;
86
+ const ruleSpacing = " ".repeat(Math.max(2, 72 - label.length));
87
+ console.log(` ${color(icon)} ${color(severity.padEnd(7))} ${message}${ruleSpacing}${import_picocolors.default.gray(rule)}`);
88
+ for (const attribute of attributes) {
89
+ console.log(` - ${import_picocolors.default.dim(`${attribute.label}:`)} ${attribute.value}`);
90
+ }
91
+ },
92
+ diagnosticSummary: (errors, warnings) => {
93
+ const total = errors + warnings;
94
+ const color = errors > 0 ? import_picocolors.default.red : import_picocolors.default.yellow;
95
+ const icon = errors > 0 ? "\u2716" : "\u26A0";
96
+ const problems = `${total} problem${total === 1 ? "" : "s"}`;
97
+ const errorCount = `${errors} error${errors === 1 ? "" : "s"}`;
98
+ const warningCount = `${warnings} warning${warnings === 1 ? "" : "s"}`;
99
+ console.log(color(`${icon} ${problems} (${errorCount}, ${warningCount})`));
100
+ },
78
101
  dim: (message) => {
79
102
  console.log(import_picocolors.default.dim(message));
80
103
  }
@@ -4,6 +4,12 @@ declare const logger: {
4
4
  success: (message: string, tag?: string) => void;
5
5
  error: (message: string, tag?: string) => void;
6
6
  warning: (message: string, tag?: string) => void;
7
+ line: (message?: string) => void;
8
+ diagnostic: (severity: "error" | "warning", message: string, rule: string, attributes?: {
9
+ label: string;
10
+ value: string;
11
+ }[]) => void;
12
+ diagnosticSummary: (errors: number, warnings: number) => void;
7
13
  dim: (message: string) => void;
8
14
  };
9
15
 
@@ -4,6 +4,12 @@ declare const logger: {
4
4
  success: (message: string, tag?: string) => void;
5
5
  error: (message: string, tag?: string) => void;
6
6
  warning: (message: string, tag?: string) => void;
7
+ line: (message?: string) => void;
8
+ diagnostic: (severity: "error" | "warning", message: string, rule: string, attributes?: {
9
+ label: string;
10
+ value: string;
11
+ }[]) => void;
12
+ diagnosticSummary: (errors: number, warnings: number) => void;
7
13
  dim: (message: string) => void;
8
14
  };
9
15
 
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  logger
3
- } from "../chunk-IALEXWSE.js";
4
- import "../chunk-V4FAVGI7.js";
3
+ } from "../chunk-QQPH6RCB.js";
4
+ import "../chunk-ZBPMCEXS.js";
5
5
  export {
6
6
  logger
7
7
  };
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "license": "SEE LICENSE IN LICENSE",
9
9
  "type": "module",
10
- "version": "4.7.3",
10
+ "version": "4.7.5",
11
11
  "publishConfig": {
12
12
  "access": "public"
13
13
  },
@@ -119,8 +119,8 @@
119
119
  "update-notifier": "^7.3.1",
120
120
  "uuid": "^11.1.1",
121
121
  "zod": "^4.3.6",
122
- "@eventcatalog/linter": "1.1.12",
123
- "@eventcatalog/sdk": "2.27.2",
122
+ "@eventcatalog/linter": "1.1.14",
123
+ "@eventcatalog/sdk": "2.27.4",
124
124
  "@eventcatalog/visualiser": "^4.1.3"
125
125
  },
126
126
  "devDependencies": {
@@ -1,204 +0,0 @@
1
- import {
2
- createFederationContentCache
3
- } from "./chunk-R7Z5ALYI.js";
4
- import {
5
- createGitHubSourceProvider
6
- } from "./chunk-352FGP6W.js";
7
- import {
8
- composePublicAssets
9
- } from "./chunk-5EPNFDT5.js";
10
- import {
11
- getEventCatalogConfigFile
12
- } from "./chunk-6QENHZZP.js";
13
-
14
- // src/federation/federate.ts
15
- import { createHash } from "crypto";
16
- import fs from "fs/promises";
17
- import path from "path";
18
- import createSDK, { hydrate, resolve } from "@eventcatalog/sdk";
19
- var FederationConflictError = class extends Error {
20
- conflicts;
21
- constructor(conflicts) {
22
- const details = conflicts.map((conflict) => `${conflict.id}: ${conflict.sources.join(", ")}`).join("\n");
23
- super(`Federation conflicts prevent hydration:
24
- ${details}`);
25
- this.name = "FederationConflictError";
26
- this.conflicts = conflicts;
27
- }
28
- };
29
- var validateSources = (sources) => {
30
- const ids = /* @__PURE__ */ new Set();
31
- for (const source of sources) {
32
- if (!source.id?.trim()) throw new Error("Every federation source requires a stable id.");
33
- if (ids.has(source.id)) throw new Error(`Federation source id "${source.id}" is configured more than once.`);
34
- ids.add(source.id);
35
- }
36
- };
37
- var writeLock = async (lockPath, lock) => {
38
- const temporaryPath = `${lockPath}.tmp-${process.pid}`;
39
- try {
40
- await fs.writeFile(temporaryPath, `${JSON.stringify(lock, null, 2)}
41
- `, "utf8");
42
- await fs.rename(temporaryPath, lockPath);
43
- } finally {
44
- await fs.rm(temporaryPath, { force: true });
45
- }
46
- };
47
- var readLock = async (lockPath) => {
48
- try {
49
- return JSON.parse(await fs.readFile(lockPath, "utf8"));
50
- } catch (error) {
51
- if (error.code === "ENOENT") return void 0;
52
- throw new Error(`Cannot read federation lock at "${lockPath}"`, { cause: error });
53
- }
54
- };
55
- var pathExists = async (filePath) => {
56
- try {
57
- await fs.access(filePath);
58
- return true;
59
- } catch (error) {
60
- if (error.code === "ENOENT") return false;
61
- throw error;
62
- }
63
- };
64
- var cleanupPreviousFederation = async (projectDirectory, onProgress) => {
65
- const outDir = path.join(projectDirectory, "federated");
66
- const lockPath = path.join(projectDirectory, "eventcatalog.lock");
67
- const previousLock = await readLock(lockPath);
68
- const hadFederatedOutput = await pathExists(outDir);
69
- const hadLock = previousLock !== void 0;
70
- if (!hadFederatedOutput && !hadLock) return;
71
- await fs.rm(outDir, { recursive: true, force: true });
72
- const publicResult = await composePublicAssets({
73
- projectDirectory,
74
- federatedDirectory: outDir,
75
- assets: [],
76
- previousFiles: previousLock?.publicFiles
77
- });
78
- await fs.rm(lockPath, { force: true });
79
- onProgress?.({
80
- type: "cleanup:complete",
81
- federated: hadFederatedOutput,
82
- publicFiles: publicResult.removed,
83
- lock: hadLock
84
- });
85
- };
86
- var federateCatalog = async (projectDirectory, options = {}) => {
87
- const config = await getEventCatalogConfigFile(projectDirectory);
88
- const sources = config.federation?.sources ?? [];
89
- options.onProgress?.({ type: "configured", sources: sources.length });
90
- if (sources.length === 0) {
91
- await cleanupPreviousFederation(projectDirectory, options.onProgress);
92
- return null;
93
- }
94
- if (options.isFederationEnabled && !await options.isFederationEnabled()) {
95
- throw new Error(
96
- "Cannot federate catalogs: EventCatalog federation is an Enterprise feature. Visit https://www.eventcatalog.dev/pricing to enable federation."
97
- );
98
- }
99
- validateSources(sources);
100
- if (options.useCache === false) options.onProgress?.({ type: "cache:disabled" });
101
- const provider = options.provider ?? createGitHubSourceProvider();
102
- const resolvedSources = [];
103
- for (const [index, source] of sources.entries()) {
104
- const current = index + 1;
105
- options.onProgress?.({ type: "source:start", source, current, total: sources.length });
106
- try {
107
- const resolved = await provider.resolve(source);
108
- resolvedSources.push({ config: source, resolved });
109
- options.onProgress?.({
110
- type: "source:complete",
111
- source,
112
- current,
113
- total: sources.length,
114
- commit: resolved.commit,
115
- resources: resolved.index.resources.length,
116
- generated: resolved.generated
117
- });
118
- } catch (error) {
119
- const message = error instanceof Error ? error.message : String(error);
120
- throw new Error(`Failed to federate source "${source.id}": ${message}`, { cause: error });
121
- }
122
- }
123
- const outDir = path.join(projectDirectory, "federated");
124
- const lockPath = path.join(projectDirectory, "eventcatalog.lock");
125
- const previousLock = await readLock(lockPath);
126
- const resources = resolvedSources.reduce((total, source) => total + source.resolved.index.resources.length, 0);
127
- const remoteIndexes = resolvedSources.map(({ resolved }) => resolved.index);
128
- options.onProgress?.({ type: "local:start" });
129
- const localIndex = await createSDK(projectDirectory).buildIndex({
130
- source: config.cId,
131
- commit: "local",
132
- hashContent: false,
133
- includeFederated: false
134
- });
135
- options.onProgress?.({ type: "local:complete", resources: localIndex.resources.length });
136
- options.onProgress?.({ type: "resolving", resources, localResources: localIndex.resources.length });
137
- const ownershipGraph = resolve([localIndex, ...remoteIndexes]);
138
- if (ownershipGraph.conflicts.length > 0) {
139
- options.onProgress?.({ type: "resolved", graph: ownershipGraph });
140
- throw new FederationConflictError(ownershipGraph.conflicts);
141
- }
142
- const graph = resolve(remoteIndexes);
143
- options.onProgress?.({ type: "resolved", graph });
144
- const sourcesById = new Map(sources.map((source) => [source.id, source]));
145
- options.onProgress?.({ type: "hydrating", outDir });
146
- let hydratedFiles = 0;
147
- let cachedFiles = 0;
148
- const hydrateResult = await hydrate(graph, {
149
- outDir,
150
- cache: createFederationContentCache(projectDirectory, {
151
- read: options.useCache !== false,
152
- onHit: () => {
153
- cachedFiles += 1;
154
- options.onProgress?.({ type: "hydrate:cache", files: cachedFiles });
155
- }
156
- }),
157
- modes: Object.fromEntries(sources.map((source) => [source.id, source.mode ?? "hydrate"])),
158
- fetch: async ({ source: sourceId, commit, path: artifactPath }) => {
159
- const source = sourcesById.get(sourceId);
160
- if (!source) throw new Error(`Cannot fetch content for unconfigured source "${sourceId}"`);
161
- const content = await provider.fetchContent({ source, commit, path: artifactPath });
162
- hydratedFiles += 1;
163
- options.onProgress?.({ type: "hydrate:file", files: hydratedFiles, source: sourceId, path: artifactPath });
164
- return content;
165
- }
166
- });
167
- const publicResult = await composePublicAssets({
168
- projectDirectory,
169
- federatedDirectory: outDir,
170
- assets: graph.assets,
171
- previousFiles: previousLock?.publicFiles,
172
- collisionPaths: new Set(
173
- graph.warnings.filter((warning) => warning.kind === "asset-collision").map((warning) => warning.path)
174
- )
175
- });
176
- options.onProgress?.({ type: "public:complete", result: publicResult });
177
- const resolvedAt = (options.now ?? (() => /* @__PURE__ */ new Date()))().toISOString();
178
- await writeLock(lockPath, {
179
- lockVersion: 1,
180
- sources: resolvedSources.map(({ config: source, resolved }) => ({
181
- id: source.id,
182
- digest: `sha256:${createHash("sha256").update(resolved.bytes).digest("hex")}`,
183
- commit: resolved.commit,
184
- resolvedAt
185
- })).sort((left, right) => left.id.localeCompare(right.id)),
186
- publicFiles: publicResult.files
187
- });
188
- const result = {
189
- sources: sources.length,
190
- resources,
191
- graph,
192
- hydrate: hydrateResult,
193
- public: publicResult,
194
- outDir,
195
- lockPath
196
- };
197
- options.onProgress?.({ type: "complete", result });
198
- return result;
199
- };
200
-
201
- export {
202
- FederationConflictError,
203
- federateCatalog
204
- };