Split NATS modules: splitter, WORM bloom archive, aggregator, docs-master
Some checks are pending
offline / test (push) Waiting to run

Each module has SUMMARY.md and NATS.md (who sends/receives, subject
addresses, payload). Tests: splitter 3, worm 3, aggregator 2.
Forgejo repos pushed separately; this commit keeps them in the monorepo.
This commit is contained in:
George Lambert 2026-09-11 12:33:40 -04:00
parent ca693366dc
commit 8f9707a3b7
39 changed files with 893 additions and 0 deletions

View file

@ -0,0 +1,53 @@
/**
* Fan-out archive query and merge replies until timeout.
* @module aggregate
*/
/**
* @param {object} opts
* @param {string} opts.sha256
* @param {string} opts.tenantId
* @param {string[]} [opts.kinds]
* @param {Array<{ archiveId: string, query: (sha: string) => object[]|null }>} opts.archives
* @param {number} [opts.timeoutMs=50] unused in in-process mock (archives are sync)
* @returns {{ archivesQueried: boolean, archiveReplies: number, records: object[], silent: string[] }}
*/
export function aggregateAttached({ sha256, tenantId, kinds = ['publicMeta', 'privateMeta', 'file'], archives }) {
const records = [];
const silent = [];
for (const arch of archives) {
const hit = arch.query(sha256);
if (hit == null) {
silent.push(arch.archiveId);
continue;
}
for (const rec of hit) {
if (!kinds.length || kinds.includes(rec.kind)) records.push(rec);
}
}
return {
sha256,
tenantId,
archivesQueried: true,
archiveReplies: archives.length - silent.length,
silent,
records,
};
}
/**
* Merge chain receipts with archive records.
* @param {object[]} chainReceipts
* @param {object[]} archiveRecords
*/
export function mergeReceipts(chainReceipts, archiveRecords) {
const extra = archiveRecords
.filter((r) => r.kind === 'publicMeta' || r.kind === 'privateMeta' || r.kind === 'file')
.map((r) => ({
kind: r.kind === 'file' ? 'file-attach' : 'metadata-attach',
archiveId: r.archiveId,
attachedAt: r.storedAt,
...r.record,
}));
return [...chainReceipts, ...extra];
}