@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.78 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;CACpF,MAAM,OAAO,OAAO,KAAK,gDAAgD;CACzE,MAAM,gBAAgB,MAAM,kBAAkB,QAAQ,aAAa;CAEnE,MAAM,OAAO,OAAO,MAAM,uCAAuC;CACjE,MAAM,UAAU,MAAM,cAAc,OAAO,MAAM,OAAO;CAExD,MAAM,OAAO,OAAO,MAAM,oBAAoB,QAAQ,OAAO,wBAAwB;CACrF,KAAK,MAAM,aAAa,SAAS;EAC/B,MAAM,OAAO,OAAO,MAAM,gCAAgC,UAAU,GAAG,0BAA0B;EAGjG,MAAM,QAAQ,UAAU;EAGxB,MAAM,QAAQ,KAAK;EAEnB,MAAM,OAAO,OAAO,MAAM,eAAe,MAAM,MAAM,MAAM,gBAAgB;EAG3E,IAAI,CAAC,UAAU,KACb,UAAU,MAAM;EAGlB,UAAU,KAAK;EAGf,MAAM,cAAc,KAAK,MAAM,SAAS,SAAS;EAGjD,MAAM,cAAc,WAAW,MAAM,SAAS,KAAK;EAEnD,IAAI,CAAC,UAAU,IAAI,WAAW,MAAM,GAClC,MAAM,IAAI,MAAM,gCAAgC,UAAU,KAAK;EAGjE,MAAM,OAAO,OAAO,MAAM,gDAAgD,MAAM,aAAa,OAAO;CACtG;AACF"}