From a002c3c5526bd42a930a87c42f16016e5725e881 Mon Sep 17 00:00:00 2001 From: David McFadzean Date: Fri, 20 Dec 2024 10:38:53 -0500 Subject: [PATCH] Refactored checkDIDs --- packages/gatekeeper/src/gatekeeper-lib.js | 13 ++++++++++++- .../gatekeeper/server/src/gatekeeper-api.js | 12 ++++++++---- tests/gatekeeper.test.js | 17 ++++++++++------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/packages/gatekeeper/src/gatekeeper-lib.js b/packages/gatekeeper/src/gatekeeper-lib.js index f2471f34..1b305a98 100644 --- a/packages/gatekeeper/src/gatekeeper-lib.js +++ b/packages/gatekeeper/src/gatekeeper-lib.js @@ -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; @@ -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; } @@ -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) { diff --git a/services/gatekeeper/server/src/gatekeeper-api.js b/services/gatekeeper/server/src/gatekeeper-api.js index 247b62f4..82998a6f 100644 --- a/services/gatekeeper/server/src/gatekeeper-api.js +++ b/services/gatekeeper/server/src/gatekeeper-api.js @@ -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) { @@ -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)`); diff --git a/tests/gatekeeper.test.js b/tests/gatekeeper.test.js index 75abf531..34ab4cf8 100644 --- a/tests/gatekeeper.test.js +++ b/tests/gatekeeper.test.js @@ -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); }); @@ -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);