@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,118 @@
1
+ // src/federation/output-transaction.ts
2
+ import fs from "fs/promises";
3
+ import path from "path";
4
+ var getSafePublicPath = (publicDirectory, relativePath) => {
5
+ const normalizedPath = path.posix.normalize(relativePath);
6
+ const unsafe = relativePath.length === 0 || relativePath.includes("\0") || relativePath.includes("\\") || path.posix.isAbsolute(relativePath) || /^[a-zA-Z]:\//.test(relativePath) || normalizedPath !== relativePath || normalizedPath === ".." || normalizedPath.startsWith("../");
7
+ if (unsafe) return void 0;
8
+ const destinationPath = path.resolve(publicDirectory, relativePath);
9
+ const relativeDestinationPath = path.relative(publicDirectory, destinationPath);
10
+ return relativeDestinationPath !== "" && relativeDestinationPath !== ".." && !relativeDestinationPath.startsWith(`..${path.sep}`) && !path.isAbsolute(relativeDestinationPath) ? destinationPath : void 0;
11
+ };
12
+ var beginFederationOutputTransaction = async (projectDirectory, outDir, relativePublicPaths) => {
13
+ const transactionDirectory = await fs.mkdtemp(path.join(projectDirectory, ".eventcatalog-federation-transaction-"));
14
+ const previousOutDir = path.join(transactionDirectory, "federated");
15
+ const publicBackupDirectory = path.join(transactionDirectory, "public");
16
+ const publicDirectory = path.resolve(projectDirectory, "public");
17
+ const publicSnapshots = [];
18
+ const missingPublicDirectories = /* @__PURE__ */ new Set();
19
+ let hadPreviousOutDir = false;
20
+ try {
21
+ for (const relativePath of new Set(relativePublicPaths)) {
22
+ const destinationPath = getSafePublicPath(publicDirectory, relativePath);
23
+ if (!destinationPath) continue;
24
+ try {
25
+ const stat = await fs.lstat(destinationPath);
26
+ if (!stat.isFile()) continue;
27
+ const backupPath = path.join(publicBackupDirectory, `${publicSnapshots.length}`);
28
+ await fs.mkdir(path.dirname(backupPath), { recursive: true });
29
+ await fs.copyFile(destinationPath, backupPath);
30
+ publicSnapshots.push({ backupPath, destinationPath, state: "file" });
31
+ } catch (error) {
32
+ const code = error.code;
33
+ if (code === "ENOTDIR") continue;
34
+ if (code !== "ENOENT") throw error;
35
+ publicSnapshots.push({ destinationPath, state: "missing" });
36
+ let directory = path.dirname(destinationPath);
37
+ while (directory !== publicDirectory) {
38
+ try {
39
+ await fs.lstat(directory);
40
+ break;
41
+ } catch (directoryError) {
42
+ const directoryCode = directoryError.code;
43
+ if (directoryCode === "ENOTDIR") break;
44
+ if (directoryCode !== "ENOENT") throw directoryError;
45
+ missingPublicDirectories.add(directory);
46
+ directory = path.dirname(directory);
47
+ }
48
+ }
49
+ }
50
+ }
51
+ try {
52
+ await fs.rename(outDir, previousOutDir);
53
+ hadPreviousOutDir = true;
54
+ } catch (error) {
55
+ if (error.code !== "ENOENT") throw error;
56
+ }
57
+ } catch (error) {
58
+ await fs.rm(transactionDirectory, { recursive: true, force: true });
59
+ throw error;
60
+ }
61
+ return {
62
+ commit: async () => {
63
+ await fs.rm(transactionDirectory, { recursive: true, force: true }).catch(() => void 0);
64
+ },
65
+ rollback: async () => {
66
+ const rollbackErrors = [];
67
+ const attempt = async (operation) => {
68
+ try {
69
+ await operation();
70
+ } catch (error) {
71
+ rollbackErrors.push(error);
72
+ }
73
+ };
74
+ await attempt(() => fs.rm(outDir, { recursive: true, force: true }));
75
+ if (hadPreviousOutDir) await attempt(() => fs.rename(previousOutDir, outDir));
76
+ for (const snapshot of publicSnapshots) {
77
+ if (snapshot.state === "missing") {
78
+ await attempt(() => fs.rm(snapshot.destinationPath, { force: true }));
79
+ continue;
80
+ }
81
+ await attempt(async () => {
82
+ await fs.mkdir(path.dirname(snapshot.destinationPath), { recursive: true });
83
+ await fs.copyFile(snapshot.backupPath, snapshot.destinationPath);
84
+ });
85
+ }
86
+ for (const directory of [...missingPublicDirectories].sort((left, right) => right.length - left.length)) {
87
+ await attempt(async () => {
88
+ try {
89
+ await fs.rmdir(directory);
90
+ } catch (error) {
91
+ if (!["ENOENT", "ENOTEMPTY"].includes(error.code ?? "")) throw error;
92
+ }
93
+ });
94
+ }
95
+ await attempt(() => fs.rm(transactionDirectory, { recursive: true, force: true }));
96
+ if (rollbackErrors.length > 0) throw new AggregateError(rollbackErrors, "Failed to restore the previous federation output");
97
+ }
98
+ };
99
+ };
100
+ var withFederationOutputTransaction = async (projectDirectory, outDir, relativePublicPaths, update) => {
101
+ const transaction = await beginFederationOutputTransaction(projectDirectory, outDir, relativePublicPaths);
102
+ try {
103
+ const result = await update();
104
+ await transaction.commit();
105
+ return result;
106
+ } catch (error) {
107
+ try {
108
+ await transaction.rollback();
109
+ } catch (rollbackError) {
110
+ throw new AggregateError([error, rollbackError], "Federation failed and the previous output could not be restored");
111
+ }
112
+ throw error;
113
+ }
114
+ };
115
+
116
+ export {
117
+ withFederationOutputTransaction
118
+ };
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "4.7.3";
2
+ var version = "4.7.5";
3
3
 
4
4
  // src/constants.ts
5
5
  var VERSION = version;
@@ -25,7 +25,7 @@ __export(constants_exports, {
25
25
  module.exports = __toCommonJS(constants_exports);
26
26
 
27
27
  // package.json
28
- var version = "4.7.3";
28
+ var version = "4.7.5";
29
29
 
30
30
  // src/constants.ts
31
31
  var VERSION = version;
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  VERSION
3
- } from "./chunk-V4FAVGI7.js";
3
+ } from "./chunk-ZBPMCEXS.js";
4
4
  export {
5
5
  VERSION
6
6
  };