import{simplifyAstStructure as h}from"@redocly/openapi-docs/lib/utils/simplifyAstStructure.js";import{storeDefinitionBundles as p}from"./store-definition-bundles.js";import{arazzoDocLoader as y,arazzoDocsLoader as P}from"./arazzo-doc-loader.js";import{telemetryTraceStep as k}from"../../../cli/telemetry/helpers/trace-step.js";const u="arazzo-docs-";async function $(w){let l=[];return{id:"arazzo",loaders:{"arazzo-doc":y,"arazzo-docs":P},processContent:async(e,o)=>{await k("build.plugin.arazzo_docs",async()=>{for(const t of await o.fs.scan(/(\.ya?ml|\.json)$/))if(!await o.isPathIgnored(t.relativePath))try{const{data:a,compoundHash:c}=await o.cache.load(t.realRelativePath,"arazzo-doc");if(!a?.length)continue;l=a.map(({markdocChunks:r,relativePath:n,isVirtual:i,customOutputRelativeFile:s,realRelativePath:d})=>({chunks:r,relativePath:n,realRelativePath:d,isVirtual:s!=null||t.isVirtual||i})),p(a,e.outdir,c);for(const r of a){const n=`${u}${r.relativePath}`;await e.createSharedData(n,{document:r.document})}}catch(a){console.error(a)}})},afterRoutesCreated:async(e,o)=>{for(const{chunks:t,relativePath:a,isVirtual:c,realRelativePath:r}of l)await o.cache.load(a,{loader:async function(){await o.cache.load(r,"arazzo-doc");for(const{node:i,markdown:s,pointer:d,key:z,relativePath:m}of t){const{ast:f}=await e.parseMarkdoc({input:{content:s,relativePath:d,isVirtual:c},context:o,deps:{sharedDataIds:[`${u}${m}`]}});i[`x-parsed-md-${z}`]={result:h(f)}}},name:"arazzo-markdoc-inline-parser"})}}}export{$ as arazzoDocsPlugin};
