import{CatalogEntitiesLocalReadRepository as r}from"./catalog-entities-local-read-repository.js";import{CatalogEntitiesLocalWriteRepository as o}from"./catalog-entities-local-write-repository.js";import{createEntityRelationDbRecordFromDto as y}from"../../mappers/create-entity-relation-db-record-from-dto.js";import{promiseMapLimit as n}from"../../../../../utils/async.js";import{BaseRepository as l}from"../../../../../providers/database/base-repository.js";import{LocalDatabaseInitializationStrategy as h}from"../../../../../providers/database/database-initialization-strategy.js";import{CATALOG_DATABASE_MIGRATIONS_FOLDER as E,CATALOG_LOCAL_DATABASE_FOLDER as c,CATALOG_LOCAL_DATABASE_NAME as d}from"../../consts.js";import{hasOptionsChanged as R}from"../../../utils/has-options-changed.js";const a=50;class i extends l{static#i;static#n;#t;#e;#a={};constructor(t){super(t),this.#t=new r(this.databaseClient),this.#e=new o(this.databaseClient,this.organizationId,this.projectId)}get transactionsManager(){return this.databaseClient.transactionsManager}getEntitySources(){return this.#a}static async getInstance(t){const e=R(i.#n,t);if(!i.#i||e){const s=await new h().initialize({databaseName:d,additionalFolder:c,migrationsFolder:E,...t});i.#i=new i(s),i.#n=t}return i.#i}async attachDatabase(t){await this.#t.attachDatabase(t)}getEntities(t={}){return this.#t.getEntities(t)}getEntityByKey(t){return this.#t.getEntityByKey(t)}getEntitiesRelations(t={}){return this.#t.getEntitiesRelations(t)}getEntityRelationById(t){return this.#t.getEntityRelationById(t)}getEntitiesWithRelations(t={}){return this.#t.getEntitiesWithRelations(t)}getEntityWithRelationsByKey(t){return this.#t.getEntityWithRelationsByKey(t)}getRelatedEntities(t,e={}){return this.#t.getRelatedEntities(t,e)}createEntity(t){return t.isRootEntity&&(this.#a[t.sourceFile]=t.entity.key),this.#e.createEntity(t)}async createEntities(t){await n(t,a,async e=>this.createEntity(e))}createEntityRelation(t){const e=y(t,this.organizationId,this.projectId);return this.#e.createEntityRelation(e)}async createEntityRelations(t){await n(t,a,async e=>this.createEntityRelation(e))}deleteEntity(t){return this.#e.deleteEntity(t)}deleteEntities(t){return this.#e.deleteEntities(t)}deleteEntityRelation(t){return this.#e.deleteEntityRelation(t)}deleteEntityRelations(t){return this.#e.deleteEntityRelations(t)}getCatalogFilters(t){return this.#t.getCatalogFilters(t)}}export{i as CatalogEntitiesLocalRepository};
