{"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,IAAM,oBAAN,MAAM,kBAAkB;CAK7B,YACE,uBACA,QACA,cACA;EACA,KAAK,wBAAwB;EAC7B,KAAK,SAAS;EACd,KAAK,eAAe;CACtB;CAEA,MAAa,KAAK,EAAE,SAAS,MAAM,MAA+B;EAChE,IAAI;GAMF,OAAO,MALc,KAAK,sBAAsB,KAAK,KAAK,cAAc;IACtE;IACS;IACH;GACR,CAAC;EAEH,SAAS,OAAO;GACd,KAAK,OAAO,MAAM,qCAAqC;IACrD;IACA;IACA,cAAc,iBAAiB,QAAQ,MAAM,UAAU;GACzD,CAAC;GACD,MAAM;EACR;CACF;CAEA,MAAa,OAAO,QAAsC;EACxD,IAAI;GACF,MAAM,KAAK,sBAAsB,OAAO,KAAK,cAAc,MAAM;EACnE,SAAS,OAAO;GACd,KAAK,OAAO,MAAM,qCAAqC;IACrD;IACA,SAAS,OAAO;IAChB,cAAc,iBAAiB,QAAQ,MAAM,UAAU;GACzD,CAAC;GACD,MAAM;EACR;CACF;CAEA,MAAa,WAAW,IAA2B;EACjD,MAAM,KAAK,sBAAsB,WAAW,KAAK,cAAc,EAAE;CACnE;CAEA,MAAa,OAAO,QAAsC;EACxD,IAAI;GACF,MAAM,KAAK,sBAAsB,OAAO,KAAK,cAAc,MAAM;EACnE,SAAS,OAAO;GACd,KAAK,OAAO,MAAM,qCAAqC;IACrD;IACA,SAAS,OAAO;IAChB,cAAc,iBAAiB,QAAQ,MAAM,UAAU;GACzD,CAAC;GACD,MAAM;EACR;CACF;CAEA,MAAa,SAAS,IAAY;EAChC,OAAO,KAAK,sBAAsB,SAAS,KAAK,cAAc,EAAE;CAClE;CAEA,MAAa,eAAe,OAA6B,cAAuD;EAC9G,OAAO,KAAK,sBAAsB,eAAe,KAAK,cAAc,OAAO,YAAY;CACzF;CAEA,MAAa,SAAmC;EAC9C,OAAO,KAAK,sBAAsB,OAAO,KAAK,YAAY;CAC5D;AACF;;CA3EC,WAAW;CAQP,gBAAA,GAAA,OAAO,iBAAiB,MAAM,CAAA"}