{"version":3,"file":"scan-CaxGIXbn.cjs","names":[],"sources":["../../src/action/scan.ts"],"sourcesContent":["import { resolve, relative } from \"node:path\";\nimport { scanRoutes } from \"../router/route-scanner.js\";\n\n/**\n * Registry of server actions grouped by page path.\n *\n * The outer key is the page URL path (e.g. \"/contact\"). The inner object maps\n * each exported action name to the absolute file path of the `page.action.ts`\n * module that defines it.\n */\nexport type ActionRegistry = Record<string, Record<string, string>>;\n\n/**\n * Scans `page.action.ts` modules and returns a per-page registry of server actions.\n *\n * Only named function exports are collected; default exports are ignored. The\n * registry is keyed by page URL path so the client can resolve actions scoped\n * to a specific page and avoid name collisions between different routes.\n */\nexport async function scanActions(appDir: string): Promise<ActionRegistry> {\n  const routes = await scanRoutes(appDir);\n  const actions: ActionRegistry = {};\n\n  for (const page of routes.pages) {\n    if (!page.actionPath) continue;\n    const actionPath = resolve(page.actionPath);\n    const mod = (await import(actionPath)) as Record<string, unknown>;\n    const pageActions: Record<string, string> = {};\n    for (const [name, value] of Object.entries(mod)) {\n      if (name === \"default\") continue;\n      if (typeof value === \"function\") {\n        pageActions[name] = actionPath;\n      }\n    }\n    if (Object.keys(pageActions).length > 0) {\n      actions[page.path] = pageActions;\n    }\n  }\n\n  return actions;\n}\n\n/**\n * Return a copy of the action registry where every file path is made relative to\n * the given project root. Useful for serializing actions into the HTML shell\n * without exposing absolute server paths.\n */\nexport function relativeActions(actions: ActionRegistry, root: string): ActionRegistry {\n  const result: ActionRegistry = {};\n  for (const [page, pageActions] of Object.entries(actions)) {\n    const entries: Record<string, string> = {};\n    for (const [name, actionPath] of Object.entries(pageActions)) {\n      entries[name] = relative(root, actionPath);\n    }\n    result[page] = entries;\n  }\n  return result;\n}\n\n/**\n * Return only the names of available actions per page, without file paths.\n * This is the safe format to serialize into the HTML shell: the client only\n * needs to know which actions exist, never where they are implemented.\n */\nexport function actionNames(actions: ActionRegistry): Record<string, string[]> {\n  const result: Record<string, string[]> = {};\n  for (const [page, pageActions] of Object.entries(actions)) {\n    result[page] = Object.keys(pageActions);\n  }\n  return result;\n}\n"],"mappings":"2EAmBA,eAAsB,EAAY,EAAyC,CACzE,IAAM,EAAS,MAAM,EAAA,EAAW,CAAM,EAChC,EAA0B,CAAC,EAEjC,IAAK,IAAM,KAAQ,EAAO,MAAO,CAC/B,GAAI,CAAC,EAAK,WAAY,SACtB,IAAM,GAAA,EAAa,EAAA,QAAA,CAAQ,EAAK,UAAU,EACpC,EAAO,MAAM,OAAO,GACpB,EAAsC,CAAC,EAC7C,IAAK,GAAM,CAAC,EAAM,KAAU,OAAO,QAAQ,CAAG,EACxC,IAAS,WACT,OAAO,GAAU,aACnB,EAAY,GAAQ,GAGpB,OAAO,KAAK,CAAW,CAAC,CAAC,OAAS,IACpC,EAAQ,EAAK,MAAQ,EAEzB,CAEA,OAAO,CACT,CAwBA,SAAgB,EAAY,EAAmD,CAC7E,IAAM,EAAmC,CAAC,EAC1C,IAAK,GAAM,CAAC,EAAM,KAAgB,OAAO,QAAQ,CAAO,EACtD,EAAO,GAAQ,OAAO,KAAK,CAAW,EAExC,OAAO,CACT"}