import{FileHashStatus as h,FileType as s}from"../../../../../persistence/file-hashes/types.js";import{promiseMapLimit as r}from"../../../../../utils/async.js";import{UniqueKeyResolver as c}from"../../../../../utils/conflict-resolvers.js";import{HashManager as o}from"../../../utils/hash-manager.js";const n=3,l={openapi:s.OPENAPI_DESCRIPTION,asyncapi:s.ASYNCAPI_DESCRIPTION,arazzo:s.ARAZZO_DESCRIPTION,graphql:s.GRAPHQL_DESCRIPTION};class A{type="api-description";specType;actions;context;catalogEntitiesService;hashManager;entitySources={};#e=new c;constructor(i,t){this.specType=i,this.actions=t.actions,this.context=t.context,this.catalogEntitiesService=t.catalogEntitiesService,this.hashManager=new o({hashManagerUpdateService:t.catalogEntitiesService,fileType:l[this.specType],fileHashesService:t.fileHashesService,localHashesCache:t.hashesCache})}async extract(){const i=await this.loadApiDescriptions();let t=0;await this.hashManager.markAllHashesAsOutdated(),await r(i,n,async e=>{try{if(e.isVirtual||!e.hash)return;if(t++,process.env.FORCE_CATALOG_CACHE_REVALIDATE!=="true"&&await this.hashManager.getHash(e.hash)){await this.hashManager.setHash(e.hash,h.UP_TO_DATE);return}const a=this.mapApiDescriptionToEntity(e);a.key=this.#e.resolve(a.key),await this.processApiDescription(e,a.key),await this.catalogEntitiesService.createEntityInLocalDatabase({entity:a,sourceFile:e.realRelativePath,fileHash:e.hash,isRootEntity:a.type==="api-description"}),await this.hashManager.setHash(e.hash,h.UP_TO_DATE)}catch(a){this.context.logger.warn(`Error extracting entities from ${this.specType} description: ${e.realRelativePath}`),this.context.logger.warn(a)}}),await this.hashManager.clearOutdatedHashesAndRelatedRecords()}}export{A as BaseApiEntitiesExtractor};
