@eventcatalog/sdk 2.14.1 → 2.14.2
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.js +60 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
package/dist/index.js
CHANGED
|
@@ -475,48 +475,58 @@ var import_semver = require("semver");
|
|
|
475
475
|
var _fileIndexCache = null;
|
|
476
476
|
var _fileIndexCatalogDir = null;
|
|
477
477
|
var _matterCache = null;
|
|
478
|
+
var _filePathToIdCache = null;
|
|
478
479
|
var _fileIndexMtimeMs = 0;
|
|
480
|
+
function toCanonicalPath(inputPath) {
|
|
481
|
+
return (0, import_node_path.normalize)((0, import_node_path.resolve)(inputPath));
|
|
482
|
+
}
|
|
479
483
|
function buildFileCache(catalogDir) {
|
|
484
|
+
const canonicalCatalogDir = toCanonicalPath(catalogDir);
|
|
480
485
|
const files = (0, import_glob2.globSync)("**/index.{md,mdx}", {
|
|
481
|
-
cwd:
|
|
486
|
+
cwd: canonicalCatalogDir,
|
|
482
487
|
ignore: ["node_modules/**"],
|
|
483
488
|
absolute: true,
|
|
484
489
|
nodir: true
|
|
485
490
|
}).map(import_node_path.normalize);
|
|
486
491
|
const index = /* @__PURE__ */ new Map();
|
|
487
492
|
const matterResults = /* @__PURE__ */ new Map();
|
|
493
|
+
const pathToId = /* @__PURE__ */ new Map();
|
|
488
494
|
for (const file of files) {
|
|
489
495
|
const content = import_node_fs.default.readFileSync(file, "utf-8");
|
|
490
496
|
const parsed = (0, import_gray_matter.default)(content);
|
|
491
497
|
matterResults.set(file, parsed);
|
|
492
498
|
const id = parsed.data.id;
|
|
493
499
|
if (!id) continue;
|
|
500
|
+
const resourceId = String(id);
|
|
494
501
|
const version = parsed.data.version || "";
|
|
495
502
|
const isVersioned = file.includes("versioned");
|
|
496
|
-
const entry = { path: file, id, version: String(version), isVersioned };
|
|
497
|
-
|
|
503
|
+
const entry = { path: file, id: resourceId, version: String(version), isVersioned };
|
|
504
|
+
pathToId.set(file, resourceId);
|
|
505
|
+
const existing = index.get(resourceId);
|
|
498
506
|
if (existing) {
|
|
499
507
|
existing.push(entry);
|
|
500
508
|
} else {
|
|
501
|
-
index.set(
|
|
509
|
+
index.set(resourceId, [entry]);
|
|
502
510
|
}
|
|
503
511
|
}
|
|
504
512
|
_fileIndexCache = index;
|
|
505
|
-
_fileIndexCatalogDir =
|
|
513
|
+
_fileIndexCatalogDir = canonicalCatalogDir;
|
|
506
514
|
_matterCache = matterResults;
|
|
515
|
+
_filePathToIdCache = pathToId;
|
|
507
516
|
try {
|
|
508
|
-
_fileIndexMtimeMs = import_node_fs.default.statSync(
|
|
517
|
+
_fileIndexMtimeMs = import_node_fs.default.statSync(canonicalCatalogDir).mtimeMs;
|
|
509
518
|
} catch {
|
|
510
519
|
_fileIndexMtimeMs = 0;
|
|
511
520
|
}
|
|
512
521
|
}
|
|
513
522
|
function ensureFileCache(catalogDir) {
|
|
514
|
-
|
|
523
|
+
const canonicalCatalogDir = toCanonicalPath(catalogDir);
|
|
524
|
+
if (!_fileIndexCache || _fileIndexCatalogDir !== canonicalCatalogDir) {
|
|
515
525
|
buildFileCache(catalogDir);
|
|
516
526
|
return;
|
|
517
527
|
}
|
|
518
528
|
try {
|
|
519
|
-
const currentMtime = import_node_fs.default.statSync(
|
|
529
|
+
const currentMtime = import_node_fs.default.statSync(canonicalCatalogDir).mtimeMs;
|
|
520
530
|
if (currentMtime !== _fileIndexMtimeMs) {
|
|
521
531
|
buildFileCache(catalogDir);
|
|
522
532
|
}
|
|
@@ -528,6 +538,47 @@ function invalidateFileCache() {
|
|
|
528
538
|
_fileIndexCache = null;
|
|
529
539
|
_fileIndexCatalogDir = null;
|
|
530
540
|
_matterCache = null;
|
|
541
|
+
_filePathToIdCache = null;
|
|
542
|
+
}
|
|
543
|
+
function upsertFileCacheEntry(catalogDir, filePath, rawContent) {
|
|
544
|
+
const canonicalCatalogDir = toCanonicalPath(catalogDir);
|
|
545
|
+
if (!_fileIndexCache || !_matterCache || !_filePathToIdCache || _fileIndexCatalogDir !== canonicalCatalogDir) {
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
const normalizedPath = toCanonicalPath(filePath);
|
|
549
|
+
const parsed = (0, import_gray_matter.default)(rawContent);
|
|
550
|
+
const previousId = _filePathToIdCache.get(normalizedPath);
|
|
551
|
+
if (previousId) {
|
|
552
|
+
const previousEntries = _fileIndexCache.get(previousId) || [];
|
|
553
|
+
const nextEntries = previousEntries.filter((entry2) => entry2.path !== normalizedPath);
|
|
554
|
+
if (nextEntries.length === 0) {
|
|
555
|
+
_fileIndexCache.delete(previousId);
|
|
556
|
+
} else {
|
|
557
|
+
_fileIndexCache.set(previousId, nextEntries);
|
|
558
|
+
}
|
|
559
|
+
_filePathToIdCache.delete(normalizedPath);
|
|
560
|
+
}
|
|
561
|
+
_matterCache.set(normalizedPath, parsed);
|
|
562
|
+
const id = parsed.data.id;
|
|
563
|
+
if (!id) {
|
|
564
|
+
_filePathToIdCache.delete(normalizedPath);
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
const resourceId = String(id);
|
|
568
|
+
const entry = {
|
|
569
|
+
path: normalizedPath,
|
|
570
|
+
id: resourceId,
|
|
571
|
+
version: String(parsed.data.version || ""),
|
|
572
|
+
isVersioned: normalizedPath.includes(`${import_node_path.sep}versioned${import_node_path.sep}`)
|
|
573
|
+
};
|
|
574
|
+
const entries = _fileIndexCache.get(resourceId) || [];
|
|
575
|
+
entries.push(entry);
|
|
576
|
+
_fileIndexCache.set(resourceId, entries);
|
|
577
|
+
_filePathToIdCache.set(normalizedPath, resourceId);
|
|
578
|
+
try {
|
|
579
|
+
_fileIndexMtimeMs = import_node_fs.default.statSync(canonicalCatalogDir).mtimeMs;
|
|
580
|
+
} catch {
|
|
581
|
+
}
|
|
531
582
|
}
|
|
532
583
|
function cachedMatterRead(filePath) {
|
|
533
584
|
if (_matterCache) {
|
|
@@ -717,7 +768,7 @@ var writeResource = async (catalogDir, resource, options = {
|
|
|
717
768
|
}
|
|
718
769
|
const document = import_gray_matter2.default.stringify(markdown.trim(), frontmatter);
|
|
719
770
|
import_node_fs2.default.writeFileSync(lockPath, document);
|
|
720
|
-
|
|
771
|
+
upsertFileCacheEntry(catalogDir, lockPath, document);
|
|
721
772
|
} finally {
|
|
722
773
|
await (0, import_proper_lockfile.unlock)(lockPath).catch(() => {
|
|
723
774
|
});
|