{"version":3,"file":"GenericRecordsApi.mjs","names":[],"sources":["../../../src/modules/generic-records/GenericRecordsApi.ts"],"sourcesContent":["import { AgentContext } from '../../agent'\nimport { InjectionSymbols } from '../../constants'\nimport type { Logger } from '../../logger'\nimport { inject, injectable } from '../../plugins'\nimport type { Query, QueryOptions } from '../../storage/StorageService'\nimport type { GenericRecord, SaveGenericRecordOption } from './repository/GenericRecord'\n\nimport { GenericRecordService } from './services/GenericRecordService'\n\nexport type ContentType = {\n  content: string\n}\n\n@injectable()\nexport class GenericRecordsApi {\n  private genericRecordsService: GenericRecordService\n  private logger: Logger\n  private agentContext: AgentContext\n\n  public constructor(\n    genericRecordsService: GenericRecordService,\n    @inject(InjectionSymbols.Logger) logger: Logger,\n    agentContext: AgentContext\n  ) {\n    this.genericRecordsService = genericRecordsService\n    this.logger = logger\n    this.agentContext = agentContext\n  }\n\n  public async save({ content, tags, id }: SaveGenericRecordOption) {\n    try {\n      const record = await this.genericRecordsService.save(this.agentContext, {\n        id,\n        content: content,\n        tags: tags,\n      })\n      return record\n    } catch (error) {\n      this.logger.error('Error while saving generic-record', {\n        error,\n        content,\n        errorMessage: error instanceof Error ? error.message : error,\n      })\n      throw error\n    }\n  }\n\n  public async delete(record: GenericRecord): Promise<void> {\n    try {\n      await this.genericRecordsService.delete(this.agentContext, record)\n    } catch (error) {\n      this.logger.error('Error while saving generic-record', {\n        error,\n        content: record.content,\n        errorMessage: error instanceof Error ? error.message : error,\n      })\n      throw error\n    }\n  }\n\n  public async deleteById(id: string): Promise<void> {\n    await this.genericRecordsService.deleteById(this.agentContext, id)\n  }\n\n  public async update(record: GenericRecord): Promise<void> {\n    try {\n      await this.genericRecordsService.update(this.agentContext, record)\n    } catch (error) {\n      this.logger.error('Error while update generic-record', {\n        error,\n        content: record.content,\n        errorMessage: error instanceof Error ? error.message : error,\n      })\n      throw error\n    }\n  }\n\n  public async findById(id: string) {\n    return this.genericRecordsService.findById(this.agentContext, id)\n  }\n\n  public async findAllByQuery(query: Query<GenericRecord>, queryOptions?: QueryOptions): Promise<GenericRecord[]> {\n    return this.genericRecordsService.findAllByQuery(this.agentContext, query, queryOptions)\n  }\n\n  public async getAll(): Promise<GenericRecord[]> {\n    return this.genericRecordsService.getAll(this.agentContext)\n  }\n}\n"],"mappings":";;;;;;;;;;;;;AAcO,8BAAM,kBAAkB;CAK7B,AAAO,YACL,uBACA,AAAiC,QACjC,cACA;AACA,OAAK,wBAAwB;AAC7B,OAAK,SAAS;AACd,OAAK,eAAe;;CAGtB,MAAa,KAAK,EAAE,SAAS,MAAM,MAA+B;AAChE,MAAI;AAMF,UALe,MAAM,KAAK,sBAAsB,KAAK,KAAK,cAAc;IACtE;IACS;IACH;IACP,CAAC;WAEK,OAAO;AACd,QAAK,OAAO,MAAM,qCAAqC;IACrD;IACA;IACA,cAAc,iBAAiB,QAAQ,MAAM,UAAU;IACxD,CAAC;AACF,SAAM;;;CAIV,MAAa,OAAO,QAAsC;AACxD,MAAI;AACF,SAAM,KAAK,sBAAsB,OAAO,KAAK,cAAc,OAAO;WAC3D,OAAO;AACd,QAAK,OAAO,MAAM,qCAAqC;IACrD;IACA,SAAS,OAAO;IAChB,cAAc,iBAAiB,QAAQ,MAAM,UAAU;IACxD,CAAC;AACF,SAAM;;;CAIV,MAAa,WAAW,IAA2B;AACjD,QAAM,KAAK,sBAAsB,WAAW,KAAK,cAAc,GAAG;;CAGpE,MAAa,OAAO,QAAsC;AACxD,MAAI;AACF,SAAM,KAAK,sBAAsB,OAAO,KAAK,cAAc,OAAO;WAC3D,OAAO;AACd,QAAK,OAAO,MAAM,qCAAqC;IACrD;IACA,SAAS,OAAO;IAChB,cAAc,iBAAiB,QAAQ,MAAM,UAAU;IACxD,CAAC;AACF,SAAM;;;CAIV,MAAa,SAAS,IAAY;AAChC,SAAO,KAAK,sBAAsB,SAAS,KAAK,cAAc,GAAG;;CAGnE,MAAa,eAAe,OAA6B,cAAuD;AAC9G,SAAO,KAAK,sBAAsB,eAAe,KAAK,cAAc,OAAO,aAAa;;CAG1F,MAAa,SAAmC;AAC9C,SAAO,KAAK,sBAAsB,OAAO,KAAK,aAAa;;;;CAzE9D,YAAY;oBAQR,OAAO,iBAAiB,OAAO"}