UNPKG

@credo-ts/core

Version:

<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1

35 lines (34 loc) • 1.75 kB
import { uuid } from "../../../../utils/uuid.mjs"; import { DidRepository } from "../../../../modules/dids/repository/DidRepository.mjs"; import "../../../../modules/dids/index.mjs"; //#region src/storage/migration/updates/0.3-0.3.1/did.ts /** * Migrates the {@link DidRecord} to 0.3 compatible format. It fetches all records from storage * and applies the needed updates to the records. After a record has been transformed, it is updated * in storage and the next record will be transformed. * * The following transformations are applied: * - {@link extractDidAsSeparateProperty} */ async function migrateDidRecordToV0_3_1(agent) { agent.config.logger.info("Migrating did records to storage version 0.3.1"); const didRepository = agent.dependencyManager.resolve(DidRepository); agent.config.logger.debug("Fetching all did records from storage"); const allDids = await didRepository.getAll(agent.context); agent.config.logger.debug(`Found a total of ${allDids.length} did records to update.`); for (const didRecord of allDids) { agent.config.logger.debug(`Migrating did record with id ${didRecord.id} to storage version 0.3.1`); const oldId = didRecord.id; const newId = uuid(); agent.config.logger.debug(`Updating id ${oldId} to ${newId} for did record`); if (!didRecord.did) didRecord.did = oldId; didRecord.id = newId; await didRepository.save(agent.context, didRecord); await didRepository.deleteById(agent.context, oldId); if (!didRecord.did.startsWith("did:")) throw new Error(`Invalid DID after migration: ${didRecord.did}`); agent.config.logger.debug(`Successfully migrated did record with old id ${oldId} to new id ${newId}`); } } //#endregion export { migrateDidRecordToV0_3_1 }; //# sourceMappingURL=did.mjs.map