/** * The LdContextLoader is initialized with a List of Map> * that it unifies into a single Map to provide to the documentLoader within * the w3c credential module. */ import { isIterable, OrPromise, RecordLike } from '@veramo/utils' import { ContextDoc } from './types.js' export class LdContextLoader { private readonly contexts: Record> constructor(options: { contextsPaths: RecordLike>[] }) { this.contexts = {} Array.from(options.contextsPaths, (mapItem) => { const map = isIterable(mapItem) ? mapItem : Object.entries(mapItem) // generate-plugin-schema is failing unless we use the cast to `any[]` for (const [key, value] of map as any[]) { this.contexts[key] = value } }) } has(url: string): boolean { return this.contexts[url] !== null && typeof this.contexts[url] !== 'undefined' } async get(url: string): Promise { return this.contexts[url] } }