@eventcatalog/core 4.7.4 → 4.7.6
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/LICENSE +95 -0
- package/README.md +3 -2
- 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-7QTCSRAC.js → chunk-6BBLQLGL.js} +1 -1
- package/dist/chunk-DDALKGTF.js +7 -0
- package/dist/chunk-JJPB6EOZ.js +159 -0
- package/dist/chunk-MLIR3NL4.js +279 -0
- package/dist/{chunk-ZXVQXBTT.js → chunk-MNAPKH63.js} +24 -1
- package/dist/{chunk-TLWM7WRZ.js → chunk-Q534DWPZ.js} +1 -1
- package/dist/{chunk-ZIABX6SP.js → chunk-RZAJNR7O.js} +1 -1
- package/dist/chunk-WRNH5C3U.js +118 -0
- package/dist/{chunk-FDXJIZ74.js → chunk-YXANZO6Y.js} +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/eventcatalog.cjs +560 -211
- package/dist/eventcatalog.config.d.cts +9 -3
- package/dist/eventcatalog.config.d.ts +9 -3
- package/dist/eventcatalog.js +40 -42
- package/dist/federation/content-cache.d.cts +5 -0
- package/dist/federation/content-cache.d.ts +5 -0
- package/dist/federation/diagnostics.cjs +187 -0
- package/dist/federation/diagnostics.d.cts +28 -0
- package/dist/federation/diagnostics.d.ts +28 -0
- package/dist/federation/diagnostics.js +14 -0
- package/dist/federation/entitlement.cjs +31 -0
- package/dist/federation/entitlement.d.cts +12 -0
- package/dist/federation/entitlement.d.ts +12 -0
- package/dist/federation/entitlement.js +6 -0
- package/dist/federation/federate.cjs +447 -118
- package/dist/federation/federate.d.cts +13 -2
- package/dist/federation/federate.d.ts +13 -2
- package/dist/federation/federate.js +9 -4
- package/dist/federation/filesystem-source-provider.d.cts +5 -0
- package/dist/federation/filesystem-source-provider.d.ts +5 -0
- package/dist/federation/github-source-provider.d.cts +5 -0
- package/dist/federation/github-source-provider.d.ts +5 -0
- package/dist/federation/output-transaction.cjs +152 -0
- package/dist/federation/output-transaction.d.cts +7 -0
- package/dist/federation/output-transaction.d.ts +7 -0
- package/dist/federation/output-transaction.js +6 -0
- package/dist/federation/public-assets.d.cts +5 -0
- package/dist/federation/public-assets.d.ts +5 -0
- package/dist/federation/source-provider.d.cts +5 -0
- package/dist/federation/source-provider.d.ts +5 -0
- package/dist/federation/source-provider.js +2 -2
- package/dist/federation/types.d.cts +5 -0
- package/dist/federation/types.d.ts +5 -0
- package/dist/generate.cjs +24 -1
- package/dist/generate.js +3 -3
- package/dist/utils/cli-logger.cjs +24 -1
- package/dist/utils/cli-logger.d.cts +6 -0
- package/dist/utils/cli-logger.d.ts +6 -0
- package/dist/utils/cli-logger.js +2 -2
- package/package.json +4 -4
- package/dist/chunk-RIUHZZRA.js +0 -204
- package/dist/{chunk-A2RZR3U4.js → chunk-6K7XZAYI.js} +3 -3
package/dist/chunk-RIUHZZRA.js
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createFederationSourceProvider
|
|
3
|
-
} from "./chunk-A2RZR3U4.js";
|
|
4
|
-
import {
|
|
5
|
-
createFederationContentCache
|
|
6
|
-
} from "./chunk-R7Z5ALYI.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 ?? createFederationSourceProvider(projectDirectory);
|
|
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
|
-
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createFileSystemSourceProvider
|
|
3
|
-
} from "./chunk-SDZQJTJW.js";
|
|
4
1
|
import {
|
|
5
2
|
createGitHubSourceProvider
|
|
6
3
|
} from "./chunk-352FGP6W.js";
|
|
4
|
+
import {
|
|
5
|
+
createFileSystemSourceProvider
|
|
6
|
+
} from "./chunk-SDZQJTJW.js";
|
|
7
7
|
|
|
8
8
|
// src/federation/source-provider.ts
|
|
9
9
|
var createFederationSourceProvider = (projectDirectory, providers = {}) => {
|