diff --git a/lib/index.js b/lib/index.js index a56565e..f511200 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,16 +1,20 @@ /*! - * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved. + * Copyright (c) 2023-2026 Digital Bazaar, Inc. All rights reserved. */ import {fileURLToPath} from 'node:url'; -import fs from 'node:fs/promises'; +import fs from 'node:fs'; import path from 'node:path'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); export const contextsDir = path.resolve(__dirname, '..', 'contexts'); export const credentialsDir = path.resolve(__dirname, '..', 'credentials'); - -const entries = await fs.readdir(credentialsDir, {withFileTypes: true}); +/** + * TODO: Add an async `loadExamples()` API as additional surface. + * - Should be idempotent (loads once, caches result). + * - Sync loading remains for backward compatibility. + */ +const entries = fs.readdirSync(credentialsDir, {withFileTypes: true}); const credentialDirs = entries.filter(e => e.isDirectory()).map(d => d.name); const credentials = {}; @@ -23,14 +27,14 @@ for(const dirName of credentialDirs) { let queries = null; try { - const credText = await fs.readFile(credentialJsonPath, 'utf8'); + const credText = fs.readFileSync(credentialJsonPath, 'utf8'); credential = JSON.parse(credText); } catch(e) { throw new Error(`Failed to read/parse ${credentialJsonPath}: ${e.message}`); } try { - const queriesText = await fs.readFile(queriesJsonPath, 'utf8'); + const queriesText = fs.readFileSync(queriesJsonPath, 'utf8'); queries = JSON.parse(queriesText); } catch{ // if queries.json is missing or invalid, keep as null