Skip to content

Commit

Permalink
Refactored checkDIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
macterra committed Dec 20, 2024
1 parent 56863c6 commit a002c3c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
13 changes: 12 additions & 1 deletion packages/gatekeeper/src/gatekeeper-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export async function checkDIDs(options = {}) {

const total = dids.length;
let n = 0;
let agents = 0;
let assets = 0;
let confirmed = 0;
let unconfirmed = 0;
let ephemeral = 0;
Expand All @@ -140,6 +142,14 @@ export async function checkDIDs(options = {}) {
console.log(`resolved ${n}/${total} ${did} OK`);
}

if (doc.mdip.type === 'agent') {
agents += 1;
}

if (doc.mdip.type === 'asset') {
assets += 1;
}

if (doc.didDocumentMetadata.confirmed) {
confirmed += 1;
}
Expand All @@ -165,7 +175,8 @@ export async function checkDIDs(options = {}) {
}
}

return { total, confirmed, unconfirmed, ephemeral, invalid, byRegistry, byVersion };
const byType = { agents, assets, confirmed, unconfirmed, ephemeral, invalid };
return { total, byType, byRegistry, byVersion };
}

export async function initRegistries(csvRegistries) {
Expand Down
12 changes: 8 additions & 4 deletions services/gatekeeper/server/src/gatekeeper-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ async function reportStatus() {
console.log(`DID Database (${config.db}):`);
console.log(` Total: ${status.dids.total}`);

console.log(` By type:`);
console.log(` Agents: ${status.dids.byType.agents}`);
console.log(` Assets: ${status.dids.byType.assets}`);
console.log(` Confirmed: ${status.dids.byType.confirmed}`);
console.log(` Unconfirmed: ${status.dids.byType.unconfirmed}`);
console.log(` Ephemeral: ${status.dids.byType.ephemeral}`);
console.log(` Invalid: ${status.dids.byType.invalid}`);

console.log(` By registry:`);
const registries = Object.keys(status.dids.byRegistry).sort();
for (let registry of registries) {
Expand All @@ -310,10 +318,6 @@ async function reportStatus() {
}
console.log(` 6+: ${status.dids.total - count}`);

console.log(` Confirmed: ${status.dids.confirmed}`);
console.log(` Unconfirmed: ${status.dids.unconfirmed}`);
console.log(` Ephemeral: ${status.dids.ephemeral}`);
console.log(` Invalid: ${status.dids.invalid}`);

console.log(`Memory Usage Report:`);
console.log(` RSS: ${formatBytes(status.memoryUsage.rss)} (Resident Set Size - total memory allocated for the process)`);
Expand Down
17 changes: 10 additions & 7 deletions tests/gatekeeper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2625,9 +2625,10 @@ describe('checkDIDs', () => {
const check = await gatekeeper.checkDIDs({ chatty: true });

expect(check.total).toBe(2);
expect(check.confirmed).toBe(2);
expect(check.ephemeral).toBe(1);
expect(check.invalid).toBe(0);
expect(check.byType.agents).toBe(1);
expect(check.byType.assets).toBe(1);
expect(check.byType.ephemeral).toBe(1);
expect(check.byType.invalid).toBe(0);
expect(check.byRegistry['local']).toBe(2);
expect(check.byVersion[1]).toBe(2);
});
Expand All @@ -2649,10 +2650,12 @@ describe('checkDIDs', () => {

expect(ok).toBe(true);
expect(check.total).toBe(2);
expect(check.confirmed).toBe(1);
expect(check.unconfirmed).toBe(1);
expect(check.ephemeral).toBe(0);
expect(check.invalid).toBe(0);
expect(check.byType.agents).toBe(1);
expect(check.byType.assets).toBe(1);
expect(check.byType.confirmed).toBe(1);
expect(check.byType.unconfirmed).toBe(1);
expect(check.byType.ephemeral).toBe(0);
expect(check.byType.invalid).toBe(0);
expect(check.byRegistry['hyperswarm']).toBe(2);
expect(check.byVersion[1]).toBe(1);
expect(check.byVersion[2]).toBe(1);
Expand Down

0 comments on commit a002c3c

Please sign in to comment.