import k from"path";import{simplifyAstStructure as v}from"@redocly/openapi-docs/lib/utils/simplifyAstStructure.js";import{slash as w}from"../../../utils/path/slash.js";import{storeDefinitionBundles as A}from"./store-definition-bundles.js";import{arazzoDocLoader as R,arazzoDocsLoader as $}from"./arazzo-doc-loader.js";import{telemetryTraceStep as I}from"../../../cli/telemetry/helpers/trace-step.js";const h="arazzo-docs-";async function b(z){let l=[];return{id:"arazzo",loaders:{"arazzo-doc":R,"arazzo-docs":$},processContent:async(e,o)=>{await I("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:n}=await o.cache.load(t.realRelativePath,"arazzo-doc");if(!a?.length)continue;l=a.map(({markdocChunks:r,relativePath:s,isVirtual:i,customOutputRelativeFile:c,realRelativePath:d})=>({chunks:r,relativePath:s,realRelativePath:d,isVirtual:c!=null||t.isVirtual||i})),A(a,e.outdir,n);for(const r of a){const s=`${h}${r.relativePath}`;await e.createSharedData(s,{document:r.document})}}catch(a){console.error(a)}})},afterRoutesCreated:async(e,o)=>{for(const{chunks:t,relativePath:a,isVirtual:n,realRelativePath:r}of l)await o.cache.load(a,{loader:async function(){await o.cache.load(r,"arazzo-doc");for(const{node:i,markdown:c,pointer:d,key:f,relativePath:p}of t){const[P,...y]=d.split("#"),m=y.join("#"),u=w(k.relative(z.contentDir,P)),{ast:D}=await e.parseMarkdoc({content:c,relativePath:u,isVirtual:n,cacheId:u+(m?"#"+m:"")},o,{sharedDataIds:[`${h}${p}`]});i[`x-parsed-md-${f}`]={result:v(D)}}},name:"arazzo-markdoc-inline-parser"})}}}export{b as arazzoDocsPlugin};
