@eventcatalog/sdk 2.27.1 → 2.27.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/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +58 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -636,7 +636,7 @@ function buildFileCache(catalogDir) {
|
|
|
636
636
|
const canonicalCatalogDir = toCanonicalPath(catalogDir);
|
|
637
637
|
const files = globSync2("**/index.{md,mdx}", {
|
|
638
638
|
cwd: canonicalCatalogDir,
|
|
639
|
-
ignore: ["node_modules/**"],
|
|
639
|
+
ignore: ["node_modules/**", "dist/**", ".eventcatalog-core/**"],
|
|
640
640
|
absolute: true,
|
|
641
641
|
nodir: true
|
|
642
642
|
}).map(normalize);
|
|
@@ -779,7 +779,7 @@ var getFiles = async (pattern, ignore2 = "") => {
|
|
|
779
779
|
const ignoreList = Array.isArray(ignore2) ? ignore2 : [ignore2];
|
|
780
780
|
const files = globSync2(relativePattern, {
|
|
781
781
|
cwd: absoluteBaseDir,
|
|
782
|
-
ignore: ["node_modules/**", ...ignoreList],
|
|
782
|
+
ignore: ["node_modules/**", "dist/**", ".eventcatalog-core/**", ...ignoreList],
|
|
783
783
|
absolute: true,
|
|
784
784
|
nodir: true
|
|
785
785
|
});
|
|
@@ -861,6 +861,8 @@ import { satisfies as satisfies3 } from "semver";
|
|
|
861
861
|
import { lock, unlock } from "proper-lockfile";
|
|
862
862
|
import { basename as basename2 } from "path";
|
|
863
863
|
import path from "path";
|
|
864
|
+
var resourceSourcePaths = /* @__PURE__ */ new WeakMap();
|
|
865
|
+
var getResourceSourcePath = (resource) => resourceSourcePaths.get(resource);
|
|
864
866
|
var versionResource = async (catalogDir, id) => {
|
|
865
867
|
const files = await getFiles(`${catalogDir}/**/index.{md,mdx}`);
|
|
866
868
|
const matchedFiles = await searchFilesForId(files, id);
|
|
@@ -1006,10 +1008,12 @@ var getResources = async (catalogDir, {
|
|
|
1006
1008
|
}
|
|
1007
1009
|
}
|
|
1008
1010
|
}
|
|
1009
|
-
|
|
1011
|
+
const resource = {
|
|
1010
1012
|
...data,
|
|
1011
1013
|
markdown: content.trim()
|
|
1012
1014
|
};
|
|
1015
|
+
resourceSourcePaths.set(resource, file);
|
|
1016
|
+
return resource;
|
|
1013
1017
|
});
|
|
1014
1018
|
};
|
|
1015
1019
|
var rmResourceById = async (catalogDir, id, version, options) => {
|
|
@@ -3765,6 +3769,7 @@ var listSnapshots = (directory) => async () => {
|
|
|
3765
3769
|
import { createHash as createHash2 } from "crypto";
|
|
3766
3770
|
import fs21 from "fs/promises";
|
|
3767
3771
|
import path8 from "path";
|
|
3772
|
+
import matter8 from "gray-matter";
|
|
3768
3773
|
import ignore from "ignore";
|
|
3769
3774
|
import { rcompare, valid as valid2 } from "semver";
|
|
3770
3775
|
|
|
@@ -3827,6 +3832,7 @@ var compareVersions = (left, right) => {
|
|
|
3827
3832
|
};
|
|
3828
3833
|
var compareIndexResources = (left, right) => compareText(left.type, right.type) || compareText(left.id, right.id) || compareVersions(left.version, right.version);
|
|
3829
3834
|
var toCatalogPath = (directory, filePath) => path8.relative(directory, filePath).split(path8.sep).join("/");
|
|
3835
|
+
var isFederatedPath = (directory, filePath) => toCatalogPath(directory, filePath).startsWith("federated/");
|
|
3830
3836
|
var loadIgnoreRules = async (directory) => {
|
|
3831
3837
|
try {
|
|
3832
3838
|
return ignore().add(await fs21.readFile(path8.join(directory, ".eventcatalogignore"), "utf8"));
|
|
@@ -3835,6 +3841,17 @@ var loadIgnoreRules = async (directory) => {
|
|
|
3835
3841
|
throw error;
|
|
3836
3842
|
}
|
|
3837
3843
|
};
|
|
3844
|
+
var getFederatedDirectoryResources = async (directory, type, resourceDirectory, ignoreRules) => {
|
|
3845
|
+
const files = await getFiles(path8.join(directory, "federated", "**", resourceDirectory, "*.{md,mdx}"));
|
|
3846
|
+
const resourcePathPattern = new RegExp(`^(?:federated/[^/]+/)+${resourceDirectory}/[^/]+\\.mdx?$`, "i");
|
|
3847
|
+
return files.filter((file) => {
|
|
3848
|
+
const catalogPath = toCatalogPath(directory, file);
|
|
3849
|
+
return resourcePathPattern.test(catalogPath) && !ignoreRules?.ignores(catalogPath);
|
|
3850
|
+
}).map((sourcePath) => {
|
|
3851
|
+
const { data } = matter8.read(sourcePath);
|
|
3852
|
+
return { type, resource: data, sourcePath };
|
|
3853
|
+
});
|
|
3854
|
+
};
|
|
3838
3855
|
var normalizeAssets = async (directory, hashContent, ignoreRules) => {
|
|
3839
3856
|
const collectFiles = async (currentDirectory) => {
|
|
3840
3857
|
let entries;
|
|
@@ -3992,7 +4009,8 @@ var toIndexResource = async (directory, type, resource, hashContent, sourcePath,
|
|
|
3992
4009
|
...resource.members === void 0 ? {} : { members: resource.members }
|
|
3993
4010
|
};
|
|
3994
4011
|
};
|
|
3995
|
-
var buildIndex = (directory) => async ({ source, commit, hashContent = true }) => {
|
|
4012
|
+
var buildIndex = (directory) => async ({ source, commit, hashContent = true, includeFederated = true }) => {
|
|
4013
|
+
const ignoreRules = await loadIgnoreRules(directory);
|
|
3996
4014
|
const [
|
|
3997
4015
|
domains,
|
|
3998
4016
|
channels,
|
|
@@ -4028,6 +4046,10 @@ var buildIndex = (directory) => async ({ source, commit, hashContent = true }) =
|
|
|
4028
4046
|
getUsers(directory)(),
|
|
4029
4047
|
getDiagrams(directory)()
|
|
4030
4048
|
]);
|
|
4049
|
+
const federatedDirectoryResources = includeFederated ? await Promise.all([
|
|
4050
|
+
getFederatedDirectoryResources(directory, "team", "teams", ignoreRules),
|
|
4051
|
+
getFederatedDirectoryResources(directory, "user", "users", ignoreRules)
|
|
4052
|
+
]) : [];
|
|
4031
4053
|
const indexableResources = [
|
|
4032
4054
|
...(domains ?? []).map((resource) => ({ type: "domain", resource })),
|
|
4033
4055
|
...(channels ?? []).map((resource) => ({ type: "channel", resource })),
|
|
@@ -4052,19 +4074,20 @@ var buildIndex = (directory) => async ({ source, commit, hashContent = true }) =
|
|
|
4052
4074
|
resource,
|
|
4053
4075
|
sourcePath: path8.join(directory, "users", `${resource.id}.mdx`)
|
|
4054
4076
|
})),
|
|
4077
|
+
...federatedDirectoryResources.flat(),
|
|
4055
4078
|
...(diagrams ?? []).map((resource) => ({ type: "diagram", resource }))
|
|
4056
4079
|
];
|
|
4057
|
-
const locatedResources = await Promise.all(
|
|
4080
|
+
const locatedResources = (await Promise.all(
|
|
4058
4081
|
indexableResources.map(async (entry) => {
|
|
4059
|
-
const sourcePath = entry.sourcePath ?? (await getResourcePath(directory, entry.resource.id, entry.resource.version))?.fullPath;
|
|
4082
|
+
const sourcePath = entry.sourcePath ?? (includeFederated ? void 0 : getResourceSourcePath(entry.resource)) ?? (await getResourcePath(directory, entry.resource.id, entry.resource.version))?.fullPath;
|
|
4060
4083
|
if (!sourcePath) throw new Error(`Cannot find ${entry.type} ${entry.resource.id} (${entry.resource.version})`);
|
|
4084
|
+
if (!includeFederated && isFederatedPath(directory, sourcePath)) return void 0;
|
|
4061
4085
|
return { ...entry, sourcePath };
|
|
4062
4086
|
})
|
|
4063
|
-
);
|
|
4087
|
+
)).filter((entry) => entry !== void 0);
|
|
4064
4088
|
const resourceDirectories = new Set(
|
|
4065
4089
|
locatedResources.filter(({ sourcePath }) => /^index\.mdx?$/i.test(path8.basename(sourcePath))).map(({ sourcePath }) => path8.resolve(path8.dirname(sourcePath)))
|
|
4066
4090
|
);
|
|
4067
|
-
const ignoreRules = await loadIgnoreRules(directory);
|
|
4068
4091
|
const resources = await Promise.all(
|
|
4069
4092
|
locatedResources.map(
|
|
4070
4093
|
({ type, resource, sourcePath }) => toIndexResource(directory, type, resource, hashContent, sourcePath, resourceDirectories, ignoreRules)
|
|
@@ -4084,7 +4107,7 @@ var buildIndex = (directory) => async ({ source, commit, hashContent = true }) =
|
|
|
4084
4107
|
import path9, { dirname as dirname7 } from "path";
|
|
4085
4108
|
import fsSync8 from "fs";
|
|
4086
4109
|
import fs22 from "fs/promises";
|
|
4087
|
-
import
|
|
4110
|
+
import matter9 from "gray-matter";
|
|
4088
4111
|
var writeChangelog = (catalogDir) => async (id, changelog, options = {}) => {
|
|
4089
4112
|
const { version, format = "mdx" } = options;
|
|
4090
4113
|
const resourceFile = await findFileById(catalogDir, id, version);
|
|
@@ -4102,7 +4125,7 @@ var writeChangelog = (catalogDir) => async (id, changelog, options = {}) => {
|
|
|
4102
4125
|
delete fm.badges;
|
|
4103
4126
|
}
|
|
4104
4127
|
fsSync8.mkdirSync(resourceDir, { recursive: true });
|
|
4105
|
-
const document =
|
|
4128
|
+
const document = matter9.stringify(markdown.trim(), fm);
|
|
4106
4129
|
fsSync8.writeFileSync(changelogPath, document);
|
|
4107
4130
|
invalidateFileCache();
|
|
4108
4131
|
};
|
|
@@ -4119,7 +4142,7 @@ var appendChangelog = (catalogDir) => async (id, changelog, options = {}) => {
|
|
|
4119
4142
|
if (!existingPath) {
|
|
4120
4143
|
return writeChangelog(catalogDir)(id, changelog, options);
|
|
4121
4144
|
}
|
|
4122
|
-
const existing =
|
|
4145
|
+
const existing = matter9.read(existingPath);
|
|
4123
4146
|
const existingContent = existing.content.trim();
|
|
4124
4147
|
const newEntry = changelog.markdown.trim();
|
|
4125
4148
|
const combined = `${newEntry}
|
|
@@ -4134,7 +4157,7 @@ ${existingContent}`;
|
|
|
4134
4157
|
} else {
|
|
4135
4158
|
delete fm.badges;
|
|
4136
4159
|
}
|
|
4137
|
-
const document =
|
|
4160
|
+
const document = matter9.stringify(combined, fm);
|
|
4138
4161
|
fsSync8.writeFileSync(existingPath, document);
|
|
4139
4162
|
invalidateFileCache();
|
|
4140
4163
|
};
|
|
@@ -4147,7 +4170,7 @@ var getChangelog = (catalogDir) => async (id, options = {}) => {
|
|
|
4147
4170
|
const mdPath = path9.join(resourceDir, "changelog.md");
|
|
4148
4171
|
const changelogPath = fsSync8.existsSync(mdxPath) ? mdxPath : fsSync8.existsSync(mdPath) ? mdPath : void 0;
|
|
4149
4172
|
if (!changelogPath) return void 0;
|
|
4150
|
-
const { data, content } =
|
|
4173
|
+
const { data, content } = matter9.read(changelogPath);
|
|
4151
4174
|
return { ...data, markdown: content.trim() };
|
|
4152
4175
|
};
|
|
4153
4176
|
var rmChangelog = (catalogDir) => async (id, options = {}) => {
|
|
@@ -4234,10 +4257,7 @@ var resolve2 = (indexes) => {
|
|
|
4234
4257
|
const assets = [];
|
|
4235
4258
|
const warnings = [];
|
|
4236
4259
|
for (const [assetPath, candidates] of assetCandidatesByPath) {
|
|
4237
|
-
candidates.
|
|
4238
|
-
(left, right) => compareText2(left.resolvedFrom.source, right.resolvedFrom.source) || compareText2(left.resolvedFrom.commit, right.resolvedFrom.commit)
|
|
4239
|
-
);
|
|
4240
|
-
const [winner] = candidates;
|
|
4260
|
+
const winner = candidates[candidates.length - 1];
|
|
4241
4261
|
const sources = [...new Set(candidates.map((candidate) => candidate.resolvedFrom.source))].sort(compareText2);
|
|
4242
4262
|
const hashes = new Set(candidates.map((candidate) => candidate.hash));
|
|
4243
4263
|
const hashesCanBeCompared = candidates.every((candidate) => candidate.hash !== void 0);
|
|
@@ -4387,6 +4407,7 @@ var getSourceDirectory = (source) => {
|
|
|
4387
4407
|
return `${slug}--${digest}`;
|
|
4388
4408
|
};
|
|
4389
4409
|
var getContentHash = (content) => `sha256:${createHash3("sha256").update(content).digest("hex")}`;
|
|
4410
|
+
var getHydrationTarget = (artifactPath) => artifactPath.replace(/^(?:federated\/[^/]+\/)+/, "");
|
|
4390
4411
|
var getArtifactOutputPath = (artifact, outDir) => {
|
|
4391
4412
|
const allowedDirectory = path10.resolve(artifact.shared ? outDir : path10.join(outDir, getSourceDirectory(artifact.source)));
|
|
4392
4413
|
const portableTarget = artifact.target.replaceAll("\\", "/");
|
|
@@ -4426,7 +4447,7 @@ async function hydrate(graph, options) {
|
|
|
4426
4447
|
const artifacts = [];
|
|
4427
4448
|
for (const entity of graph.entities) {
|
|
4428
4449
|
const { source, commit } = entity.resolvedFrom;
|
|
4429
|
-
if (source === options.localSource) continue;
|
|
4450
|
+
if (options.localSource !== void 0 && source === options.localSource) continue;
|
|
4430
4451
|
if (options.modes?.[source] === "reference") {
|
|
4431
4452
|
result.referenced++;
|
|
4432
4453
|
continue;
|
|
@@ -4437,31 +4458,44 @@ async function hydrate(graph, options) {
|
|
|
4437
4458
|
commit,
|
|
4438
4459
|
path: entity.contentPath,
|
|
4439
4460
|
hash: entity.contentHash,
|
|
4440
|
-
target: entity.contentPath
|
|
4461
|
+
target: getHydrationTarget(entity.contentPath)
|
|
4441
4462
|
});
|
|
4442
4463
|
const entityDirectory = path10.posix.dirname(entity.contentPath);
|
|
4443
4464
|
for (const schema of entity.schemas ?? []) {
|
|
4444
4465
|
if (!schema.path) continue;
|
|
4445
4466
|
const artifactPath = path10.posix.join(entityDirectory, schema.path);
|
|
4446
|
-
artifacts.push({ source, commit, path: artifactPath, hash: schema.hash, target: artifactPath });
|
|
4467
|
+
artifacts.push({ source, commit, path: artifactPath, hash: schema.hash, target: getHydrationTarget(artifactPath) });
|
|
4447
4468
|
}
|
|
4448
4469
|
for (const specification of entity.specifications ?? []) {
|
|
4449
4470
|
const artifactPath = path10.posix.join(entityDirectory, specification.path);
|
|
4450
|
-
artifacts.push({
|
|
4471
|
+
artifacts.push({
|
|
4472
|
+
source,
|
|
4473
|
+
commit,
|
|
4474
|
+
path: artifactPath,
|
|
4475
|
+
hash: specification.hash,
|
|
4476
|
+
target: getHydrationTarget(artifactPath)
|
|
4477
|
+
});
|
|
4451
4478
|
}
|
|
4452
4479
|
for (const sidecar of entity.sidecars ?? []) {
|
|
4453
|
-
artifacts.push({
|
|
4480
|
+
artifacts.push({
|
|
4481
|
+
source,
|
|
4482
|
+
commit,
|
|
4483
|
+
path: sidecar.path,
|
|
4484
|
+
hash: sidecar.hash,
|
|
4485
|
+
target: getHydrationTarget(sidecar.path)
|
|
4486
|
+
});
|
|
4454
4487
|
}
|
|
4455
4488
|
}
|
|
4456
4489
|
for (const asset of graph.assets) {
|
|
4457
4490
|
const { source, commit } = asset.resolvedFrom;
|
|
4458
|
-
if (source === options.localSource || options.modes?.[source] === "reference")
|
|
4491
|
+
if (options.localSource !== void 0 && source === options.localSource || options.modes?.[source] === "reference")
|
|
4492
|
+
continue;
|
|
4459
4493
|
artifacts.push({
|
|
4460
4494
|
source,
|
|
4461
4495
|
commit,
|
|
4462
4496
|
path: asset.path,
|
|
4463
4497
|
hash: asset.hash,
|
|
4464
|
-
target: asset.path,
|
|
4498
|
+
target: getHydrationTarget(asset.path),
|
|
4465
4499
|
shared: true
|
|
4466
4500
|
});
|
|
4467
4501
|
}
|