@eventcatalog/sdk 2.27.3 → 2.28.0
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 +7 -4
- package/dist/index.d.mts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +59 -78
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -79
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3,21 +3,37 @@ import { join as join22 } from "path";
|
|
|
3
3
|
|
|
4
4
|
// src/dsl/utils.ts
|
|
5
5
|
import { globSync } from "glob";
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
// src/internal/versions.ts
|
|
8
|
+
import { coerce, compare, satisfies, valid, validRange } from "semver";
|
|
9
|
+
var NUMERIC_VERSION_PATTERN = /^[vV]?\d+(?:\.\d+){0,2}$/;
|
|
10
|
+
var toComparableVersion = (version) => {
|
|
11
|
+
const strictVersion = valid(version);
|
|
12
|
+
if (strictVersion) return strictVersion;
|
|
13
|
+
if (!NUMERIC_VERSION_PATTERN.test(version)) return void 0;
|
|
14
|
+
return coerce(version) ?? void 0;
|
|
15
|
+
};
|
|
16
|
+
var compareVersions = (left, right) => {
|
|
17
|
+
const leftVersion = toComparableVersion(left);
|
|
18
|
+
const rightVersion = toComparableVersion(right);
|
|
19
|
+
if (!leftVersion || !rightVersion) return void 0;
|
|
20
|
+
return compare(leftVersion, rightVersion);
|
|
21
|
+
};
|
|
22
|
+
var isVersionGreaterThan = (candidate, current) => compareVersions(candidate, current) === 1;
|
|
23
|
+
var versionSatisfiesRange = (version, range) => {
|
|
24
|
+
const comparableVersion = toComparableVersion(version);
|
|
25
|
+
const comparableRange = validRange(range) ?? validRange(range.replace(/V(?=\d)/g, "v"));
|
|
26
|
+
if (!comparableVersion || !comparableRange) return false;
|
|
27
|
+
return satisfies(comparableVersion, comparableRange);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// src/dsl/utils.ts
|
|
7
31
|
function msgVersionMatches(pointerVersion, messageVersion) {
|
|
8
32
|
if (!pointerVersion) return true;
|
|
9
33
|
if (!messageVersion) return false;
|
|
10
34
|
if (pointerVersion === messageVersion) return true;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (satisfies(messageVersion, pointerVersion)) return true;
|
|
14
|
-
}
|
|
15
|
-
if (validRange(messageVersion)) {
|
|
16
|
-
if (satisfies(pointerVersion, messageVersion)) return true;
|
|
17
|
-
}
|
|
18
|
-
} catch {
|
|
19
|
-
}
|
|
20
|
-
return false;
|
|
35
|
+
if (versionSatisfiesRange(messageVersion, pointerVersion)) return true;
|
|
36
|
+
return versionSatisfiesRange(pointerVersion, messageVersion);
|
|
21
37
|
}
|
|
22
38
|
function serializeBaseFields(resource, indent = " ") {
|
|
23
39
|
const lines = [];
|
|
@@ -623,7 +639,6 @@ import fsSync from "fs";
|
|
|
623
639
|
import { copy } from "fs-extra";
|
|
624
640
|
import { join, dirname, normalize, sep as pathSeparator, resolve, relative } from "path";
|
|
625
641
|
import matter from "gray-matter";
|
|
626
|
-
import { satisfies as satisfies2, validRange as validRange2 } from "semver";
|
|
627
642
|
var _fileIndexCache = null;
|
|
628
643
|
var _fileIndexCatalogDir = null;
|
|
629
644
|
var _matterCache = null;
|
|
@@ -755,18 +770,12 @@ var findFileById = async (catalogDir, id, version) => {
|
|
|
755
770
|
}
|
|
756
771
|
const exactMatch = entries.find((e) => e.version === version);
|
|
757
772
|
if (exactMatch) return exactMatch.path;
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
return satisfies2(e.version, semverRange);
|
|
763
|
-
} catch {
|
|
764
|
-
return false;
|
|
765
|
-
}
|
|
766
|
-
});
|
|
767
|
-
return match?.path;
|
|
773
|
+
let match;
|
|
774
|
+
for (const entry of entries) {
|
|
775
|
+
if (!versionSatisfiesRange(entry.version, version)) continue;
|
|
776
|
+
if (!match || isVersionGreaterThan(entry.version, match.version)) match = entry;
|
|
768
777
|
}
|
|
769
|
-
return
|
|
778
|
+
return match?.path;
|
|
770
779
|
};
|
|
771
780
|
var getFiles = async (pattern, ignore2 = "") => {
|
|
772
781
|
try {
|
|
@@ -857,7 +866,6 @@ import { dirname as dirname2, join as join2 } from "path";
|
|
|
857
866
|
import matter2 from "gray-matter";
|
|
858
867
|
import fs from "fs/promises";
|
|
859
868
|
import fsSync2 from "fs";
|
|
860
|
-
import { satisfies as satisfies3 } from "semver";
|
|
861
869
|
import { lock, unlock } from "proper-lockfile";
|
|
862
870
|
import { basename as basename2 } from "path";
|
|
863
871
|
import path from "path";
|
|
@@ -925,7 +933,7 @@ var writeResource = async (catalogDir, resource, options = {
|
|
|
925
933
|
if (options.versionExistingContent && !exists) {
|
|
926
934
|
const currentResource = await getResource(catalogDir, resource.id);
|
|
927
935
|
if (currentResource) {
|
|
928
|
-
if (
|
|
936
|
+
if (isVersionGreaterThan(resource.version, currentResource.version)) {
|
|
929
937
|
await versionResource(catalogDir, resource.id);
|
|
930
938
|
} else {
|
|
931
939
|
throw new Error(`New version ${resource.version} is not greater than current version ${currentResource.version}`);
|
|
@@ -2007,7 +2015,6 @@ var addMessageToChannel = (directory, collection) => async (id, _message, versio
|
|
|
2007
2015
|
import { dirname as dirname5, join as join11 } from "path";
|
|
2008
2016
|
import fsSync4 from "fs";
|
|
2009
2017
|
import matter4 from "gray-matter";
|
|
2010
|
-
import { satisfies as satisfies4, validRange as validRange3 } from "semver";
|
|
2011
2018
|
var getMessageBySchemaPath = (directory) => async (path11, options) => {
|
|
2012
2019
|
const pathToMessage = dirname5(path11);
|
|
2013
2020
|
try {
|
|
@@ -2048,34 +2055,17 @@ var getProducersAndConsumersForMessage = (directory) => async (id, version, opti
|
|
|
2048
2055
|
const producers = [];
|
|
2049
2056
|
const consumers = [];
|
|
2050
2057
|
for (const participant of [...services, ...agents, ...domains]) {
|
|
2051
|
-
const
|
|
2058
|
+
const matchesMessage = (_message) => {
|
|
2052
2059
|
if (_message.version) {
|
|
2053
|
-
|
|
2054
|
-
if (isParticipantUsingSemverRange) {
|
|
2055
|
-
return _message.id === message.id && satisfies4(message.version, _message.version);
|
|
2056
|
-
} else {
|
|
2057
|
-
return _message.id === message.id && message.version === _message.version;
|
|
2058
|
-
}
|
|
2060
|
+
return _message.id === message.id && (message.version === _message.version || versionSatisfiesRange(message.version, _message.version));
|
|
2059
2061
|
}
|
|
2060
2062
|
if (isMessageLatestVersion && _message.id === message.id) {
|
|
2061
2063
|
return true;
|
|
2062
2064
|
}
|
|
2063
2065
|
return false;
|
|
2064
|
-
}
|
|
2065
|
-
const
|
|
2066
|
-
|
|
2067
|
-
const isParticipantUsingSemverRange = validRange3(_message.version);
|
|
2068
|
-
if (isParticipantUsingSemverRange) {
|
|
2069
|
-
return _message.id === message.id && satisfies4(message.version, _message.version);
|
|
2070
|
-
} else {
|
|
2071
|
-
return _message.id === message.id && message.version === _message.version;
|
|
2072
|
-
}
|
|
2073
|
-
}
|
|
2074
|
-
if (isMessageLatestVersion && _message.id === message.id) {
|
|
2075
|
-
return true;
|
|
2076
|
-
}
|
|
2077
|
-
return false;
|
|
2078
|
-
});
|
|
2066
|
+
};
|
|
2067
|
+
const participantPublishesMessage = participant.sends?.some(matchesMessage);
|
|
2068
|
+
const participantSubscribesToMessage = participant.receives?.some(matchesMessage);
|
|
2079
2069
|
if (participantPublishesMessage) {
|
|
2080
2070
|
producers.push(participant);
|
|
2081
2071
|
}
|
|
@@ -2441,9 +2431,6 @@ var dumpCatalog = (directory) => async (options) => {
|
|
|
2441
2431
|
};
|
|
2442
2432
|
};
|
|
2443
2433
|
|
|
2444
|
-
// src/graph.ts
|
|
2445
|
-
import { maxSatisfying, validRange as validRange4 } from "semver";
|
|
2446
|
-
|
|
2447
2434
|
// src/adrs.ts
|
|
2448
2435
|
import fs14 from "fs/promises";
|
|
2449
2436
|
import { join as join16 } from "path";
|
|
@@ -3249,14 +3236,13 @@ var getGraph = (directory) => {
|
|
|
3249
3236
|
const allVersionsIndex = await loadAllVersionsIndex(type);
|
|
3250
3237
|
const exactMatch = allVersionsIndex.byVersion.get(`${pointer.id}:${pointer.version}`);
|
|
3251
3238
|
if (exactMatch) return exactMatch;
|
|
3252
|
-
const range = validRange4(pointer.version);
|
|
3253
|
-
if (!range) return void 0;
|
|
3254
3239
|
const candidates = allVersionsIndex.byId.get(pointer.id) || [];
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3240
|
+
let match;
|
|
3241
|
+
for (const candidate of candidates) {
|
|
3242
|
+
if (!versionSatisfiesRange(candidate.version, pointer.version)) continue;
|
|
3243
|
+
if (!match || isVersionGreaterThan(candidate.version, match.version)) match = candidate;
|
|
3244
|
+
}
|
|
3245
|
+
return match;
|
|
3260
3246
|
};
|
|
3261
3247
|
const resolvePointer = async (pointer, candidateTypes) => {
|
|
3262
3248
|
const explicitType = normalizeResourceType(pointer.type);
|
|
@@ -3298,8 +3284,7 @@ var getGraph = (directory) => {
|
|
|
3298
3284
|
const pointerMatchesVersion = (pointer, version) => {
|
|
3299
3285
|
if (!pointer.version || pointer.version === "latest") return true;
|
|
3300
3286
|
if (pointer.version === version) return true;
|
|
3301
|
-
|
|
3302
|
-
return range ? maxSatisfying([version], range) === version : false;
|
|
3287
|
+
return versionSatisfiesRange(version, pointer.version);
|
|
3303
3288
|
};
|
|
3304
3289
|
const getAdrsForResource = async (type, resource) => {
|
|
3305
3290
|
if (type === "adr") return [];
|
|
@@ -3437,7 +3422,6 @@ import fs19 from "fs";
|
|
|
3437
3422
|
import path7 from "path";
|
|
3438
3423
|
import { createHash } from "crypto";
|
|
3439
3424
|
import { execSync } from "child_process";
|
|
3440
|
-
import { compare } from "semver";
|
|
3441
3425
|
|
|
3442
3426
|
// src/snapshot-diff.ts
|
|
3443
3427
|
var stableStringify = (value) => {
|
|
@@ -3631,11 +3615,16 @@ var pickCoreFields = (resource) => {
|
|
|
3631
3615
|
if (resource.schemaHash) picked.schemaHash = resource.schemaHash;
|
|
3632
3616
|
return picked;
|
|
3633
3617
|
};
|
|
3618
|
+
var isNewerVersion = (candidate, current) => {
|
|
3619
|
+
const comparison = compareVersions(candidate, current);
|
|
3620
|
+
if (comparison !== void 0) return comparison > 0;
|
|
3621
|
+
return candidate.localeCompare(current) > 0;
|
|
3622
|
+
};
|
|
3634
3623
|
var deduplicateByLatestVersion = (resources) => {
|
|
3635
3624
|
const seen = /* @__PURE__ */ new Map();
|
|
3636
3625
|
for (const r of resources) {
|
|
3637
3626
|
const existing = seen.get(r.id);
|
|
3638
|
-
if (!existing ||
|
|
3627
|
+
if (!existing || isNewerVersion(r.version, existing.version)) {
|
|
3639
3628
|
seen.set(r.id, r);
|
|
3640
3629
|
}
|
|
3641
3630
|
}
|
|
@@ -3771,7 +3760,6 @@ import fs21 from "fs/promises";
|
|
|
3771
3760
|
import path8 from "path";
|
|
3772
3761
|
import matter8 from "gray-matter";
|
|
3773
3762
|
import ignore from "ignore";
|
|
3774
|
-
import { rcompare, valid as valid2 } from "semver";
|
|
3775
3763
|
|
|
3776
3764
|
// src/diagrams.ts
|
|
3777
3765
|
import fs20 from "fs/promises";
|
|
@@ -3823,14 +3811,15 @@ var getFlowReferences = (steps) => steps.flatMap((step) => [
|
|
|
3823
3811
|
...step.flow ? [{ kind: "flow", ...step.flow }] : []
|
|
3824
3812
|
]);
|
|
3825
3813
|
var compareText = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
3826
|
-
var
|
|
3814
|
+
var compareVersions2 = (left, right) => {
|
|
3827
3815
|
if (left === right) return 0;
|
|
3828
3816
|
if (left === void 0) return 1;
|
|
3829
3817
|
if (right === void 0) return -1;
|
|
3830
|
-
|
|
3818
|
+
const comparison = compareVersions(left, right);
|
|
3819
|
+
if (comparison !== void 0) return -comparison;
|
|
3831
3820
|
return compareText(right, left);
|
|
3832
3821
|
};
|
|
3833
|
-
var compareIndexResources = (left, right) => compareText(left.type, right.type) || compareText(left.id, right.id) ||
|
|
3822
|
+
var compareIndexResources = (left, right) => compareText(left.type, right.type) || compareText(left.id, right.id) || compareVersions2(left.version, right.version);
|
|
3834
3823
|
var toCatalogPath = (directory, filePath) => path8.relative(directory, filePath).split(path8.sep).join("/");
|
|
3835
3824
|
var isFederatedPath = (directory, filePath) => toCatalogPath(directory, filePath).startsWith("federated/");
|
|
3836
3825
|
var loadIgnoreRules = async (directory) => {
|
|
@@ -4192,12 +4181,12 @@ var rmChangelog = (catalogDir) => async (id, options = {}) => {
|
|
|
4192
4181
|
};
|
|
4193
4182
|
|
|
4194
4183
|
// src/resolve.ts
|
|
4195
|
-
import { gt, satisfies as satisfies5, valid as valid3, validRange as validRange5 } from "semver";
|
|
4196
4184
|
var compareText2 = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
4197
4185
|
var isHigherVersion = (candidate, current) => {
|
|
4198
4186
|
if (candidate === current || candidate === void 0) return false;
|
|
4199
4187
|
if (current === void 0) return true;
|
|
4200
|
-
|
|
4188
|
+
const comparison = compareVersions(candidate, current);
|
|
4189
|
+
if (comparison !== void 0) return comparison > 0;
|
|
4201
4190
|
return compareText2(candidate, current) > 0;
|
|
4202
4191
|
};
|
|
4203
4192
|
var selectTarget = (candidates, pointerVersion) => {
|
|
@@ -4207,10 +4196,8 @@ var selectTarget = (candidates, pointerVersion) => {
|
|
|
4207
4196
|
}
|
|
4208
4197
|
const exactMatch = candidates.find((candidate) => candidate.version === pointerVersion);
|
|
4209
4198
|
if (exactMatch) return exactMatch;
|
|
4210
|
-
const range = validRange5(pointerVersion);
|
|
4211
|
-
if (!range) return void 0;
|
|
4212
4199
|
return candidates.reduce((latest, candidate) => {
|
|
4213
|
-
if (candidate.version === void 0 || !
|
|
4200
|
+
if (candidate.version === void 0 || !versionSatisfiesRange(candidate.version, pointerVersion)) return latest;
|
|
4214
4201
|
if (latest === void 0 || isHigherVersion(candidate.version, latest.version)) return candidate;
|
|
4215
4202
|
return latest;
|
|
4216
4203
|
}, void 0);
|
|
@@ -4441,17 +4428,12 @@ var replaceDirectory = async (stagingDirectory, outDir) => {
|
|
|
4441
4428
|
async function hydrate(graph, options) {
|
|
4442
4429
|
const result = {
|
|
4443
4430
|
fetched: 0,
|
|
4444
|
-
written: 0
|
|
4445
|
-
referenced: 0
|
|
4431
|
+
written: 0
|
|
4446
4432
|
};
|
|
4447
4433
|
const artifacts = [];
|
|
4448
4434
|
for (const entity of graph.entities) {
|
|
4449
4435
|
const { source, commit } = entity.resolvedFrom;
|
|
4450
4436
|
if (options.localSource !== void 0 && source === options.localSource) continue;
|
|
4451
|
-
if (options.modes?.[source] === "reference") {
|
|
4452
|
-
result.referenced++;
|
|
4453
|
-
continue;
|
|
4454
|
-
}
|
|
4455
4437
|
if (!entity.contentPath) continue;
|
|
4456
4438
|
artifacts.push({
|
|
4457
4439
|
source,
|
|
@@ -4488,8 +4470,7 @@ async function hydrate(graph, options) {
|
|
|
4488
4470
|
}
|
|
4489
4471
|
for (const asset of graph.assets) {
|
|
4490
4472
|
const { source, commit } = asset.resolvedFrom;
|
|
4491
|
-
if (options.localSource !== void 0 && source === options.localSource
|
|
4492
|
-
continue;
|
|
4473
|
+
if (options.localSource !== void 0 && source === options.localSource) continue;
|
|
4493
4474
|
artifacts.push({
|
|
4494
4475
|
source,
|
|
4495
4476
|
commit,
|