import{join as c}from"path";import{REDOCLY_ROUTE_RBAC as f}from"@redocly/config";import{USER_DEFINED_API_FUNCTIONS_COUNTER_KEY as p}from"../../../server/store.js";import{parseRouteFsPathForHono as l}from"./utils/parse-route-fs-path-for-hono.js";const h="api-functions";async function _(){return{id:"ApiFunctions",requiredEntitlements:["apiFunctions"],async processContent(n,e){const i=((await e.getConfig()).apiFunctions?.folders||[]).map(t=>`^${t}`);i.push(".*@api");const a=new RegExp(`(${i.join("|")})/.*.(ts|js)$`);let r=0;for(const t of await e.fs.scan(a)){if(t.isVirtual)continue;const o=l(t.relativePath);if(!o)continue;const s=`${h}:${o.handler}`,u=c(n.contentDir,o.handler);n.createRequestHandler(s,u),n.addApiRoute({requestHandlerId:s,slug:o.path,fsPath:t.relativePath,httpMethod:o.method,[f]:{fsPath:t.relativePath,slug:o.path}}),r++}n.setGlobalConfig({[p]:r})}}}export{h as API_FUNCTIONS_REQUEST_HANDLER_ID,_ as apiFunctionsPlugin};
