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

1 lines • 3.72 kB
{"version":3,"file":"GenericRecordService.mjs","names":[],"sources":["../../../../src/modules/generic-records/services/GenericRecordService.ts"],"sourcesContent":["import type { AgentContext } from '../../../agent'\nimport { CredoError } from '../../../error'\nimport { injectable } from '../../../plugins'\nimport type { Query, QueryOptions } from '../../../storage/StorageService'\nimport type { SaveGenericRecordOption } from '../repository/GenericRecord'\nimport { GenericRecord } from '../repository/GenericRecord'\nimport { GenericRecordsRepository } from '../repository/GenericRecordsRepository'\n\n@injectable()\nexport class GenericRecordService {\n private genericRecordsRepository: GenericRecordsRepository\n\n public constructor(genericRecordsRepository: GenericRecordsRepository) {\n this.genericRecordsRepository = genericRecordsRepository\n }\n\n public async save(agentContext: AgentContext, { content, tags, id }: SaveGenericRecordOption) {\n const genericRecord = new GenericRecord({\n id,\n content,\n tags,\n })\n\n try {\n await this.genericRecordsRepository.save(agentContext, genericRecord)\n return genericRecord\n } catch (error) {\n throw new CredoError(`Unable to store the genericRecord record with id ${genericRecord.id}. Message: ${error}`)\n }\n }\n\n public async delete(agentContext: AgentContext, record: GenericRecord): Promise<void> {\n try {\n await this.genericRecordsRepository.delete(agentContext, record)\n } catch (error) {\n throw new CredoError(`Unable to delete the genericRecord record with id ${record.id}. Message: ${error}`)\n }\n }\n\n public async deleteById(agentContext: AgentContext, id: string): Promise<void> {\n await this.genericRecordsRepository.deleteById(agentContext, id)\n }\n\n public async update(agentContext: AgentContext, record: GenericRecord): Promise<void> {\n try {\n await this.genericRecordsRepository.update(agentContext, record)\n } catch (error) {\n throw new CredoError(`Unable to update the genericRecord record with id ${record.id}. Message: ${error}`, {\n cause: error,\n })\n }\n }\n\n public async findAllByQuery(agentContext: AgentContext, query: Query<GenericRecord>, queryOptions?: QueryOptions) {\n return this.genericRecordsRepository.findByQuery(agentContext, query, queryOptions)\n }\n\n public async findById(agentContext: AgentContext, id: string): Promise<GenericRecord | null> {\n return this.genericRecordsRepository.findById(agentContext, id)\n }\n\n public async getAll(agentContext: AgentContext) {\n return this.genericRecordsRepository.getAll(agentContext)\n }\n}\n"],"mappings":";;;;;;;;AASO,IAAM,uBAAN,MAAM,qBAAqB;CAGhC,YAAmB,0BAAoD;EACrE,KAAK,2BAA2B;CAClC;CAEA,MAAa,KAAK,cAA4B,EAAE,SAAS,MAAM,MAA+B;EAC5F,MAAM,gBAAgB,IAAI,cAAc;GACtC;GACA;GACA;EACF,CAAC;EAED,IAAI;GACF,MAAM,KAAK,yBAAyB,KAAK,cAAc,aAAa;GACpE,OAAO;EACT,SAAS,OAAO;GACd,MAAM,IAAI,WAAW,oDAAoD,cAAc,GAAG,aAAa,OAAO;EAChH;CACF;CAEA,MAAa,OAAO,cAA4B,QAAsC;EACpF,IAAI;GACF,MAAM,KAAK,yBAAyB,OAAO,cAAc,MAAM;EACjE,SAAS,OAAO;GACd,MAAM,IAAI,WAAW,qDAAqD,OAAO,GAAG,aAAa,OAAO;EAC1G;CACF;CAEA,MAAa,WAAW,cAA4B,IAA2B;EAC7E,MAAM,KAAK,yBAAyB,WAAW,cAAc,EAAE;CACjE;CAEA,MAAa,OAAO,cAA4B,QAAsC;EACpF,IAAI;GACF,MAAM,KAAK,yBAAyB,OAAO,cAAc,MAAM;EACjE,SAAS,OAAO;GACd,MAAM,IAAI,WAAW,qDAAqD,OAAO,GAAG,aAAa,SAAS,EACxG,OAAO,MACT,CAAC;EACH;CACF;CAEA,MAAa,eAAe,cAA4B,OAA6B,cAA6B;EAChH,OAAO,KAAK,yBAAyB,YAAY,cAAc,OAAO,YAAY;CACpF;CAEA,MAAa,SAAS,cAA4B,IAA2C;EAC3F,OAAO,KAAK,yBAAyB,SAAS,cAAc,EAAE;CAChE;CAEA,MAAa,OAAO,cAA4B;EAC9C,OAAO,KAAK,yBAAyB,OAAO,YAAY;CAC1D;AACF;AAxDC,uBAAA,WAAA,CAAA,WAAW,GAAA,mBAAA,qBAAA,CAAA,OAAA,6BAAA,cAAA,SAAA,wBAAA,CAAA,CAAA,GAAA,oBAAA"}