@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
1 lines • 2.77 kB
Source Map (JSON)
{"version":3,"file":"did.mjs","names":[],"sources":["../../../../../src/storage/migration/updates/0.3-0.3.1/did.ts"],"sourcesContent":["import type { BaseAgent } from '../../../../agent/BaseAgent'\n\nimport { DidRepository } from '../../../../modules/dids'\nimport { uuid } from '../../../../utils/uuid'\n\n/**\n * Migrates the {@link DidRecord} to 0.3 compatible format. It fetches all records from storage\n * and applies the needed updates to the records. After a record has been transformed, it is updated\n * in storage and the next record will be transformed.\n *\n * The following transformations are applied:\n * - {@link extractDidAsSeparateProperty}\n */\nexport async function migrateDidRecordToV0_3_1<Agent extends BaseAgent>(agent: Agent) {\n agent.config.logger.info('Migrating did records to storage version 0.3.1')\n const didRepository = agent.dependencyManager.resolve(DidRepository)\n\n agent.config.logger.debug('Fetching all did records from storage')\n const allDids = await didRepository.getAll(agent.context)\n\n agent.config.logger.debug(`Found a total of ${allDids.length} did records to update.`)\n for (const didRecord of allDids) {\n agent.config.logger.debug(`Migrating did record with id ${didRecord.id} to storage version 0.3.1`)\n\n // Save old DID or ID for reference/deletion\n const oldId = didRecord.id\n\n // Generate new storage ID\n const newId = uuid()\n\n agent.config.logger.debug(`Updating id ${oldId} to ${newId} for did record`)\n\n // Preserve the actual DID in didRecord.did\n if (!didRecord.did) {\n didRecord.did = oldId // fallback if didRecord.did was empty\n }\n\n didRecord.id = newId\n\n // Save new did record\n await didRepository.save(agent.context, didRecord)\n\n // Delete old did record\n await didRepository.deleteById(agent.context, oldId)\n\n if (!didRecord.did.startsWith('did:')) {\n throw new Error(`Invalid DID after migration: ${didRecord.did}`)\n }\n\n agent.config.logger.debug(`Successfully migrated did record with old id ${oldId} to new id ${newId}`)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAaA,eAAsB,yBAAkD,OAAc;AACpF,OAAM,OAAO,OAAO,KAAK,iDAAiD;CAC1E,MAAM,gBAAgB,MAAM,kBAAkB,QAAQ,cAAc;AAEpE,OAAM,OAAO,OAAO,MAAM,wCAAwC;CAClE,MAAM,UAAU,MAAM,cAAc,OAAO,MAAM,QAAQ;AAEzD,OAAM,OAAO,OAAO,MAAM,oBAAoB,QAAQ,OAAO,yBAAyB;AACtF,MAAK,MAAM,aAAa,SAAS;AAC/B,QAAM,OAAO,OAAO,MAAM,gCAAgC,UAAU,GAAG,2BAA2B;EAGlG,MAAM,QAAQ,UAAU;EAGxB,MAAM,QAAQ,MAAM;AAEpB,QAAM,OAAO,OAAO,MAAM,eAAe,MAAM,MAAM,MAAM,iBAAiB;AAG5E,MAAI,CAAC,UAAU,IACb,WAAU,MAAM;AAGlB,YAAU,KAAK;AAGf,QAAM,cAAc,KAAK,MAAM,SAAS,UAAU;AAGlD,QAAM,cAAc,WAAW,MAAM,SAAS,MAAM;AAEpD,MAAI,CAAC,UAAU,IAAI,WAAW,OAAO,CACnC,OAAM,IAAI,MAAM,gCAAgC,UAAU,MAAM;AAGlE,QAAM,OAAO,OAAO,MAAM,gDAAgD,MAAM,aAAa,QAAQ"}