@lunora/codegen 1.0.0-alpha.56 → 1.0.0-alpha.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{GENERATED_HEADER-C94PuLpQ.mjs → GENERATED_HEADER-hlHbtIBb.mjs} +1 -1
- package/dist/packem_shared/{OPENRPC_VERSION-DpV3v2W8.mjs → OPENRPC_VERSION-DWoqALFJ.mjs} +1 -1
- package/dist/packem_shared/{SCHEMA_SNAPSHOT_FILENAME-DJsxljOQ.mjs → SCHEMA_SNAPSHOT_FILENAME-Cuf8KyVF.mjs} +1 -1
- package/dist/packem_shared/{buildOpenApiDocument-DXX1G3GZ.mjs → buildOpenApiDocument-BRCc5AIx.mjs} +1 -1
- package/dist/packem_shared/{emit-Dr6XSLfW.mjs → emit-BYVxPDqO.mjs} +27 -4
- package/dist/packem_shared/{emitApp-B671iU7r.mjs → emitApp-CHCOfQer.mjs} +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{formatAdvisories as t,lintSchema as s}from"./packem_shared/formatAdvisories-DZvv-0MG.mjs";import{CodegenDiagnosticError as i,diagnosticAt as m}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as f,discoverAgents as p}from"./packem_shared/AGENTS_FILENAME-BesaDYkL.mjs";import{default as n}from"./packem_shared/discoverAuthApiCalls-DOfSQqVK.mjs";import{CONTAINERS_FILENAME as l,discoverContainers as E}from"./packem_shared/CONTAINERS_FILENAME-CFwdyaCI.mjs";import{default as x}from"./packem_shared/discoverCrons-B09_uEuL.mjs";import{FLAGS_FILENAME as v,discoverFlags as N}from"./packem_shared/FLAGS_FILENAME-DW5oGq1q.mjs";import{discoverFunctions as R}from"./packem_shared/discoverFunctions-BdibLQmc.mjs";import{default as h}from"./packem_shared/discoverHttpRoutes-BOWz6y_n.mjs";import{default as I}from"./packem_shared/discoverInserts-BtteTyNy.mjs";import{default as g}from"./packem_shared/discoverMaskProcedures-COPmwMBm.mjs";import{default as F}from"./packem_shared/discoverMigrations-iGMlp9YJ.mjs";import{MUTATORS_FILENAME as D,discoverMutators as P}from"./packem_shared/MUTATORS_FILENAME-BKKPROzu.mjs";import{default as H}from"./packem_shared/discoverNondeterministicCalls-Dmgc4QBx.mjs";import{NOTIFY_FILENAME as W,discoverNotifyCalls as b,discoverNotifyConfig as z}from"./packem_shared/NOTIFY_FILENAME-C-c7Lg-U.mjs";import{default as k}from"./packem_shared/discoverQueries-CcfuGKHh.mjs";import{QUEUES_FILENAME as y,discoverQueues as K}from"./packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs";import{default as j}from"./packem_shared/discoverR2sqlCalls-CjZKvg-N.mjs";import{discoverRlsMetadata as q,default as B}from"./packem_shared/discoverRlsMetadata-BXmNOgry.mjs";import{discoverSandboxUsage as X}from"./packem_shared/discoverSandboxUsage-CDdBqWcM.mjs";import{default as $}from"./packem_shared/discoverSchema-m2voTncu.mjs";import{SHAPES_FILENAME as oe,discoverShapes as re}from"./packem_shared/SHAPES_FILENAME-DTkSJSsg.mjs";import{default as se}from"./packem_shared/discoverStorageRulesMetadata-b71cJJHz.mjs";import{WORKFLOWS_FILENAME as ie,discoverWorkflows as me}from"./packem_shared/WORKFLOWS_FILENAME-Bk5upkGM.mjs";import{w as fe,E as pe,n as ce,o as ne,L as Se,X as le,G as Ee,z as ue,g as xe,u as Ae,K as ve,Y as Ne,D as Oe,Z as Re}from"./packem_shared/emit-
|
|
1
|
+
import{formatAdvisories as t,lintSchema as s}from"./packem_shared/formatAdvisories-DZvv-0MG.mjs";import{CodegenDiagnosticError as i,diagnosticAt as m}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as f,discoverAgents as p}from"./packem_shared/AGENTS_FILENAME-BesaDYkL.mjs";import{default as n}from"./packem_shared/discoverAuthApiCalls-DOfSQqVK.mjs";import{CONTAINERS_FILENAME as l,discoverContainers as E}from"./packem_shared/CONTAINERS_FILENAME-CFwdyaCI.mjs";import{default as x}from"./packem_shared/discoverCrons-B09_uEuL.mjs";import{FLAGS_FILENAME as v,discoverFlags as N}from"./packem_shared/FLAGS_FILENAME-DW5oGq1q.mjs";import{discoverFunctions as R}from"./packem_shared/discoverFunctions-BdibLQmc.mjs";import{default as h}from"./packem_shared/discoverHttpRoutes-BOWz6y_n.mjs";import{default as I}from"./packem_shared/discoverInserts-BtteTyNy.mjs";import{default as g}from"./packem_shared/discoverMaskProcedures-COPmwMBm.mjs";import{default as F}from"./packem_shared/discoverMigrations-iGMlp9YJ.mjs";import{MUTATORS_FILENAME as D,discoverMutators as P}from"./packem_shared/MUTATORS_FILENAME-BKKPROzu.mjs";import{default as H}from"./packem_shared/discoverNondeterministicCalls-Dmgc4QBx.mjs";import{NOTIFY_FILENAME as W,discoverNotifyCalls as b,discoverNotifyConfig as z}from"./packem_shared/NOTIFY_FILENAME-C-c7Lg-U.mjs";import{default as k}from"./packem_shared/discoverQueries-CcfuGKHh.mjs";import{QUEUES_FILENAME as y,discoverQueues as K}from"./packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs";import{default as j}from"./packem_shared/discoverR2sqlCalls-CjZKvg-N.mjs";import{discoverRlsMetadata as q,default as B}from"./packem_shared/discoverRlsMetadata-BXmNOgry.mjs";import{discoverSandboxUsage as X}from"./packem_shared/discoverSandboxUsage-CDdBqWcM.mjs";import{default as $}from"./packem_shared/discoverSchema-m2voTncu.mjs";import{SHAPES_FILENAME as oe,discoverShapes as re}from"./packem_shared/SHAPES_FILENAME-DTkSJSsg.mjs";import{default as se}from"./packem_shared/discoverStorageRulesMetadata-b71cJJHz.mjs";import{WORKFLOWS_FILENAME as ie,discoverWorkflows as me}from"./packem_shared/WORKFLOWS_FILENAME-Bk5upkGM.mjs";import{w as fe,E as pe,n as ce,o as ne,L as Se,X as le,G as Ee,z as ue,g as xe,u as Ae,K as ve,Y as Ne,D as Oe,Z as Re}from"./packem_shared/emit-BYVxPDqO.mjs";import{emitApp as he}from"./packem_shared/emitApp-CHCOfQer.mjs";import{buildOpenApiDocument as Ie,emitOpenApi as _e,emitOpenApiModule as ge}from"./packem_shared/buildOpenApiDocument-BRCc5AIx.mjs";import{OPENRPC_VERSION as Fe,buildOpenRpcDocument as Te,emitOpenRpc as De,emitOpenRpcModule as Pe}from"./packem_shared/OPENRPC_VERSION-DWoqALFJ.mjs";import{SCHEMA_SNAPSHOT_FILENAME as He,createCodegenProject as Ge,refreshCodegenProject as We,runCodegen as be}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-Cuf8KyVF.mjs";import{SCHEMA_SNAPSHOT_VERSION as Ve,SchemaSnapshotParseError as ke,buildSchemaSnapshot as we,diffSchemaSnapshots as ye,evaluateSchemaDrift as Ke,parseSchemaSnapshot as Qe,serializeSchemaSnapshot as je}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-Bpf1FGMG.mjs";import{schemaFromIr as qe}from"./packem_shared/schemaFromIr-R1ZFzVyy.mjs";import{LUNORA_ERROR_CODES as Je,validatorIrToJsonSchema as Xe}from"./packem_shared/LUNORA_ERROR_CODES-Um9hC1gr.mjs";import{redact as $e,secretKindOf as eo}from"./packem_shared/redact-CQ8-to6l.mjs";import{MESSAGE_SOLUTIONS as ro,findSolutionByMessage as to}from"@lunora/errors";const e="0.0.0";export{f as AGENTS_FILENAME,l as CONTAINERS_FILENAME,i as CodegenDiagnosticError,v as FLAGS_FILENAME,fe as GENERATED_HEADER,Je as LUNORA_ERROR_CODES,ro as LUNORA_SOLUTION_RULES,D as MUTATORS_FILENAME,W as NOTIFY_FILENAME,Fe as OPENRPC_VERSION,y as QUEUES_FILENAME,He as SCHEMA_SNAPSHOT_FILENAME,Ve as SCHEMA_SNAPSHOT_VERSION,oe as SHAPES_FILENAME,ke as SchemaSnapshotParseError,e as VERSION,ie as WORKFLOWS_FILENAME,Ie as buildOpenApiDocument,Te as buildOpenRpcDocument,we as buildSchemaSnapshot,Ge as createCodegenProject,m as diagnosticAt,ye as diffSchemaSnapshots,p as discoverAgents,n as discoverAuthApiCalls,E as discoverContainers,x as discoverCrons,N as discoverFlags,R as discoverFunctions,h as discoverHttpRoutes,I as discoverInserts,g as discoverMaskProcedures,F as discoverMigrations,P as discoverMutators,H as discoverNondeterministicCalls,b as discoverNotifyCalls,z as discoverNotifyConfig,k as discoverQueries,K as discoverQueues,j as discoverR2sqlCalls,q as discoverRlsMetadata,B as discoverRlsProcedures,X as discoverSandboxUsage,$ as discoverSchema,re as discoverShapes,se as discoverStorageRulesMetadata,me as discoverWorkflows,pe as emitAgents,ce as emitApi,he as emitApp,ne as emitCollections,Se as emitContainers,le as emitCrons,Ee as emitDataModel,ue as emitDrizzleSchema,xe as emitFunctions,_e as emitOpenApi,ge as emitOpenApiModule,De as emitOpenRpc,Pe as emitOpenRpcModule,Ae as emitServer,ve as emitShard,Ne as emitVectors,Oe as emitWorkflows,Re as emitWranglerCronTriggers,Ke as evaluateSchemaDrift,to as findLunoraSolution,t as formatAdvisories,s as lintSchema,Qe as parseSchemaSnapshot,$e as redact,We as refreshCodegenProject,be as runCodegen,qe as schemaFromIr,eo as secretKindOf,je as serializeSchemaSnapshot,Xe as validatorIrToJsonSchema};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"@lunora/agent/component";import"@lunora/errors";import{w as m,a as r,E as o,n,o as l,L as g,X as u,G as E,z as p,g as C,_ as D,b as S,u as c,K as d,Y as A,D as z,Z as b}from"./emit-
|
|
1
|
+
import"@lunora/agent/component";import"@lunora/errors";import{w as m,a as r,E as o,n,o as l,L as g,X as u,G as E,z as p,g as C,_ as D,b as S,u as c,K as d,Y as A,D as z,Z as b}from"./emit-BYVxPDqO.mjs";import"./paths-BmX5O1sG.mjs";export{m as GENERATED_HEADER,r as buildStorageColumns,o as emitAgents,n as emitApi,l as emitCollections,g as emitContainers,u as emitCrons,E as emitDataModel,p as emitDrizzleSchema,C as emitFunctions,D as emitQueues,S as emitSeed,c as emitServer,d as emitShard,A as emitVectors,z as emitWorkflows,b as emitWranglerCronTriggers};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{w as a}from"./emit-
|
|
1
|
+
import{w as a}from"./emit-BYVxPDqO.mjs";import{n as s}from"./paths-BmX5O1sG.mjs";import{argsObjectSchema as i,LUNORA_ERROR_CODES as c}from"./LUNORA_ERROR_CODES-Um9hC1gr.mjs";const m="1.3.2",p=()=>({description:"Result is TS-inferred from the function's return type (no `.output()` declared); best-effort — any JSON."}),u=e=>{const n=s(e.filePath),t=`${n}:${e.exportName}`;return{description:`Invoke the \`${e.kind}\` \`${t}\` over the Lunora RPC envelope (POST /_lunora/rpc, body \`{ "functionPath": "${t}", "args": { … } }\`).`,errors:c.map((r,o)=>({code:-32e3-o,data:{code:r},message:r})),name:t,params:[{description:"The function's argument object (the RPC envelope's `args`).",name:"args",required:Object.keys(e.args).length>0,schema:i(e.args)}],result:{name:"result",schema:p()},summary:`${e.kind}: ${t}`,"x-lunora-function-kind":e.kind,"x-tags":[{name:n}]}},d=e=>{const n=e.version??"0.0.0",t=e.functions.filter(r=>r.visibility!=="internal"&&r.kind!=="stream").map(r=>u(r)).toSorted((r,o)=>r.name.localeCompare(o.name));return{info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora RPC",version:n},methods:t,openrpc:m}},R=e=>`${JSON.stringify(d(e),void 0,2)}
|
|
2
2
|
`,O=e=>`${a}export const openRpcSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
|
|
3
3
|
`;export{m as OPENRPC_VERSION,d as buildOpenRpcDocument,R as emitOpenRpc,O as emitOpenRpcModule};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{existsSync as E,readFileSync as ye,mkdirSync as jt,writeFileSync as qt,rmSync as Bt}from"node:fs";import{join as g,dirname as de}from"node:path";import{performance as ge}from"node:perf_hooks";import{LunoraError as q}from"@lunora/errors";import{Node as i,SyntaxKind as u,Project as Xe}from"ts-morph";import{lintSchema as Vt}from"./formatAdvisories-DZvv-0MG.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as f,classifyProcedureCall as K,inlineHandler as Ut,procedureHandler as ft,chainUsesWrappedCall as pt,isDatabaseAccessor as k,chainHasStep as Wt,discoverFunctions as Gt}from"./discoverFunctions-BdibLQmc.mjs";import{discoverAgents as _t}from"./AGENTS_FILENAME-BesaDYkL.mjs";import Ht from"./discoverAuthApiCalls-DOfSQqVK.mjs";import{discoverContainers as Qt}from"./CONTAINERS_FILENAME-CFwdyaCI.mjs";import Xt from"./discoverCrons-B09_uEuL.mjs";import{diagnosticAt as _}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{r as fe,a as Jt,G as Zt,n as Yt,u as es,g as ts,K as ss,o as rs,L as ns,D as is,E as os,_ as as,X as cs,Y as us,z as ls,b as ds,Z as gs}from"./emit-Dr6XSLfW.mjs";import{discoverFlagKeys as fs}from"./FLAGS_FILENAME-DW5oGq1q.mjs";import ps from"./discoverHttpRoutes-BOWz6y_n.mjs";import ms from"./discoverInserts-BtteTyNy.mjs";import xs,{discoverMaskStrategies as hs,discoverMaskMetadata as Es}from"./discoverMaskProcedures-COPmwMBm.mjs";import ys from"./discoverMigrations-iGMlp9YJ.mjs";import{MUTATORS_FILENAME as As,isDefineMutatorCallee as $s,discoverMutators as Ss}from"./MUTATORS_FILENAME-BKKPROzu.mjs";import Ns from"./discoverNondeterministicCalls-Dmgc4QBx.mjs";import{discoverNotifyConfig as vs,discoverNotifyCalls as bs}from"./NOTIFY_FILENAME-C-c7Lg-U.mjs";import Ps from"./discoverQueries-CcfuGKHh.mjs";import{discoverQueues as ws}from"./QUEUES_FILENAME-CSE6i-ld.mjs";import Is from"./discoverR2sqlCalls-CjZKvg-N.mjs";import Ls,{discoverRlsMetadata as Os}from"./discoverRlsMetadata-BXmNOgry.mjs";import{discoverSandboxUsage as Fs}from"./discoverSandboxUsage-CDdBqWcM.mjs";import Ds from"./discoverSchema-m2voTncu.mjs";import{secretKindOf as Ts,redact as Cs}from"./redact-CQ8-to6l.mjs";import{discoverShapes as ks}from"./SHAPES_FILENAME-DTkSJSsg.mjs";import Ks from"./discoverStorageRulesMetadata-b71cJJHz.mjs";import{e as Rs}from"./discover-ast-CezKqEhE.mjs";import{discoverWorkflows as Ms}from"./WORKFLOWS_FILENAME-Bk5upkGM.mjs";import{emitApp as zs}from"./emitApp-B671iU7r.mjs";import{buildOpenApiDocument as js,emitOpenApiModule as qs}from"./buildOpenApiDocument-DXX1G3GZ.mjs";import{buildOpenRpcDocument as Bs,emitOpenRpcModule as Vs}from"./OPENRPC_VERSION-DpV3v2W8.mjs";import{buildSchemaSnapshot as Us,serializeSchemaSnapshot as Ws}from"./SCHEMA_SNAPSHOT_VERSION-Bpf1FGMG.mjs";const mt=new Set(["delete","get","head","options","patch","post","put"]),Gs=new Set(["handler","stream"]),_s=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,Je=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Hs=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!mt.has(t.getName()))return;const s=t.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpRoute")return;const r=e.getArguments()[0];if(!(!r||!i.isStringLiteral(r)))return{method:t.getName().toUpperCase(),path:r.getLiteralValue()}},Qs=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||mt.has(r.getName()))break;s=r.getExpression()}return Hs(s)},Xs=e=>{for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression))if(Je.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&Je.has(s.getText()))return!0}return!1},Js=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||!Gs.has(r.getName()))return;const n=Qs(s);if(!n||!_s.test(n.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&Xs(o);return{exportName:e.getName(),file:t,method:n.method,path:n.path,usesGuard:a}},Zs=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Js(n,t);o&&s.push(o)}return s},Ys=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Zs(n,f(t,r)))}return s},Ze=e=>{if(e.getText()!=="args")return!1;const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(i.isPropertyAssignment(t)&&t.getNameNode()===e)},Ye=e=>{if(e.getText()!=="ctx")return!1;const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(i.isPropertyAssignment(t)&&t.getNameNode()===e)},pe=e=>i.isIdentifier(e)?Ye(e):e.getDescendantsOfKind(u.Identifier).some(t=>Ye(t)),et=(e,t)=>{if(e.getText()!==t)return!1;const s=e.getParent();return i.isPropertyAccessExpression(s)&&s.getNameNode()===e?!1:!(i.isPropertyAssignment(s)&&s.getNameNode()===e)},er=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t:void 0},b=e=>{if(i.isIdentifier(e))return e.getText();if(i.isPropertyAccessExpression(e))return e.getName()},he=e=>i.isIdentifier(e)?Ze(e):e.getDescendantsOfKind(u.Identifier).some(t=>Ze(t)),L=e=>{if(!i.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a));if(s===void 0)return;const r=e.getStart();let n,o=-1;for(const a of s.getDescendantsOfKind(u.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<r&&l>o&&(n=c,o=l)}return n},P=e=>{if(he(e))return!0;const t=L(e);return t!==void 0&&he(t)},D=e=>{if(pe(e))return!0;const t=L(e);if(t!==void 0&&pe(t))return!0;const s=t??e;return(i.isIdentifier(s)?[s]:s.getDescendantsOfKind(u.Identifier)).some(r=>{const n=L(r);return n!==void 0&&pe(n)})},B=(e,t)=>i.isIdentifier(e)?et(e,t):e.getDescendantsOfKind(u.Identifier).some(s=>et(s,t)),tr=(e,t)=>{if(B(e,t))return!0;const s=L(e);if(s!==void 0&&B(s,t))return!0;const r=er(e);if(r!==void 0){const n=L(r);return n!==void 0&&B(n,t)}return!1},h=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)&&t.getVariableStatement()?.hasExportKeyword()===!0)return t.getName();return"<module>"},sr=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",rr=(e,t)=>{if(!sr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!P(s)||D(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},nr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=rr(r,t);n&&s.push(n)}return s},ir=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...nr(n,f(t,r)))}return s},or=new Set(["generateText","streamText"]),ar=new Set(["messages","prompt","system"]),cr=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],ur=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),r=t.getExpression().getText();for(const n of cr)if(n.methods.has(s)&&n.prefixes.some(o=>r===o||r.startsWith(`${o}.`)))return`${r}.${s}`},lr=e=>{for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=ur(t);if(s!==void 0)return s}},dr=e=>{const t=new Set,s=e.getFirstAncestor(o=>i.isArrowFunction(o)||i.isFunctionExpression(o)||i.isFunctionDeclaration(o)),[r]=s?.getParameters()??[],n=r?.getNameNode();if(n===void 0||!i.isObjectBindingPattern(n))return t;for(const o of n.getElements()){const a=o.getPropertyNameNode()?.getText()??o.getName(),c=o.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},gr=e=>{if(he(e))return!0;const t=dr(e);return t.size===0?!1:e.getDescendantsOfKind(u.Identifier).some(s=>t.has(s.getText()))},fr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!ar.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&gr(s))return!0}return!1},pr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=b(r.getExpression());if(n===void 0||!or.has(n))continue;const[o]=r.getArguments();if(o===void 0||!i.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(u.CallExpression))if(b(c.getExpression())==="tool"&&(a=lr(c),a!==void 0))break;a!==void 0&&s.push({exportName:h(r),file:t,line:r.getStartLineNumber(),method:n,sideEffect:a,userInputDerived:fr(o)})}return s},mr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...pr(n,f(t,r)))}return s},xr=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},hr=(e,t)=>{if(!xr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!P(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},Er=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=hr(r,t);n&&s.push(n)}return s},yr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Er(n,f(t,r)))}return s},Ar=/\.check\(|\.meta\(|length|max/iu,$r=/\bv\.any\s*\(/u,Sr=/\bv\.string\s*\(/u,Nr=e=>$r.test(e),vr=e=>Sr.test(e)&&!Ar.test(e),br=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("args");if(!s||!i.isPropertyAssignment(s))return;const r=s.getInitializer();return r&&i.isObjectLiteralExpression(r)?r:void 0},Pr=e=>{const t=[];let s=e;for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const n=s.getArguments()[0];n&&i.isObjectLiteralExpression(n)&&t.push(n)}s=r.getExpression()}return t},wr=e=>{const t=[],s=[];for(const r of e)for(const n of r.getProperties()){if(!i.isPropertyAssignment(n))continue;const o=n.getInitializer();if(!o)continue;const a=o.getText(),c=n.getName();Nr(a)?t.push(c):vr(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Ir=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=K(s);if(r?.visibility!=="public")return;const n=r.receiver?Pr(r.receiver):[br(s)].filter(c=>c!==void 0),{anyArgs:o,unboundedStringArgs:a}=wr(n);if(!(o.length===0&&a.length===0))return{anyArgs:o,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Lr=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Ir(n,t);o&&s.push(o)}return s},Or=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Lr(n,f(t,r)))}return s},I=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},me=e=>e?.getKind()===u.TrueKeyword,Fr=e=>e?.getKind()===u.FalseKeyword,Dr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Tr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),Cr=e=>{const t=I(e,"advanced"),s=I(e,"emailAndPassword"),r=I(e,"session");return{analyzable:!0,disableCsrfCheck:me(I(t,"disableCSRFCheck")),emailPasswordEnabled:me(I(s,"enabled")),requireEmailVerification:me(I(s,"requireEmailVerification")),secureCookiesDisabled:Fr(I(t,"useSecureCookies")),sessionFreshAgeZero:Dr(I(r,"freshAge")),trustedOriginsWildcard:Tr(I(e,"trustedOrigins"))}},kr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Kr=(e,t)=>{if(b(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],r=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(o=>i.isSpreadAssignment(o)),n=s!==void 0&&i.isObjectLiteralExpression(s)&&!r?Cr(s):kr();return{exportName:h(e),file:t,line:e.getStartLineNumber(),...n}},Rr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Kr(r,t);n&&s.push(n)}return s},Mr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Rr(n,f(t,r)))}return s},zr=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},jr=(e,t,s)=>{const r=zr(e.getExpression(),s);if(r===void 0)return;const n=e.getArguments()[s.argIndex];if(!(!n||!P(n)||D(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:r}},qr=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const o=jr(n,t,s);o&&r.push(o)}return r},H=(e,t,s)=>{const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(...qr(o,f(t,n),s))}return r},Br=new Set(["content","pdf","scrape","screenshot"]),Vr=(e,t)=>H(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Br}),Ur=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Wr=new Set(["RateLimiter"]),Gr=new Set(["extend"]),xt=e=>{const t=[],s=[];let r=!1;for(const n of e.getProperties()){if(i.isSpreadAssignment(n)){r=!0;continue}if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o),n.getInitializer()?.getKind()===u.TrueKeyword&&s.push(o);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,presentKeys:t,trueKeys:s}},tt=e=>e&&i.isObjectLiteralExpression(e)?xt(e):{analyzable:!1,presentKeys:[],trueKeys:[]},_r=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!i.isReturnStatement(s))return;const r=s.getExpression();return r!==void 0&&i.isObjectLiteralExpression(r)?r:void 0},Hr=e=>{if(i.isObjectLiteralExpression(e))return e;if(i.isParenthesizedExpression(e)){const t=e.getExpression();return i.isObjectLiteralExpression(t)?t:void 0}return i.isBlock(e)?_r(e):void 0},Qr=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&Hr(t.getBody());return s?xt(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Xr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=b(r.getExpression());n!==void 0&&(Ur.has(n)?s.push({callee:n,file:t,line:r.getStartLineNumber(),...tt(r.getArguments()[0])}):Gr.has(n)&&s.push({callee:n,file:t,line:r.getStartLineNumber(),...Qr(r.getArguments()[0])}))}for(const r of e.getDescendantsOfKind(u.NewExpression)){const n=b(r.getExpression());n===void 0||!Wr.has(n)||s.push({callee:n,file:t,line:r.getStartLineNumber(),...tt(r.getArguments()[0])})}return s},Jr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Xr(n,f(t,r)))}return s},st="ctx.containers.",Zr=e=>{if(!e.startsWith(st))return!1;const t=e.slice(st.length);return t.length>0&&!t.includes(".")},Yr=(e,t)=>H(e,t,{argIndex:0,matchReceiver:Zr,methods:new Set(["get"])}),en=new Set(["allow","deny","setAllowed"]),tn=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},sn=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!tn(e)))return{detail:"enableInternet: true",exportName:h(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},rn=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!en.has(s.getName()))return;const r=s.getExpression();if(!(!i.isPropertyAccessExpression(r)||r.getName()!=="egress"))return{detail:s.getName(),exportName:h(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},nn=(e,t)=>sn(e,t)??rn(e,t),on=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=nn(r,t);n&&s.push(n)}return s},an=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...on(n,f(t,r)))}return s},cn="env.ts",ht=new Set(["@lunora/server","lunorash/server"]),un=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return ht.has(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},ln=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const r=s.getFirstAncestorByKind(u.ImportDeclaration);return r!==void 0&&ht.has(r.getModuleSpecifierValue())}return!1},dn=e=>{if(i.isIdentifier(e))return un(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&ln(t)}return!1},gn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!dn(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw _(n,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},fn=(e,t)=>{const s=g(t,cn);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=gn(r);if(n.length!==0){if(n.length>1)throw _(r,`lunora/env.ts declares ${n.length.toString()} defineEnv() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},pn=new Set(["defineExportSink","r2Sink","webhookExportSink"]),mn=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return pn.has(s)?s:void 0},xn=e=>{const t=[],s=[];for(const r of e.getProperties()){if(i.isSpreadAssignment(r))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(r)){const n=r.getName();t.push(n);const o=r.getInitializer();o&&i.isStringLiteral(o)&&o.getLiteralText()===""&&s.push(n);continue}(i.isShorthandPropertyAssignment(r)||i.isMethodDeclaration(r)||i.isGetAccessorDeclaration(r))&&t.push(r.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},hn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){const c=mn(a);if(c===void 0)continue;const l=a.getArguments()[0],m=l&&i.isObjectLiteralExpression(l)?xn(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:m.analyzable,emptyKeys:m.emptyKeys,factory:c,file:o,line:a.getStartLineNumber(),presentKeys:m.presentKeys})}}return s},En=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),yn=new Set(["dbRateLimit","rateLimit"]),An=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&i.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===u.TrueKeyword},$n=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},Sn=(e,t)=>{const s=b(e.getExpression());if(s===void 0)return;const r=En.get(s);if(r!==void 0)return{callee:s,exportName:h(e),failOpen:An(e.getArguments()[r]),file:t,limitName:yn.has(s)?$n(e):"",line:e.getStartLineNumber()}},Nn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Sn(r,t);n&&s.push(n)}return s},vn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Nn(n,f(t,r)))}return s},bn=e=>{const t=r=>i.isIdentifier(r)&&r.getText()==="ctx",s=new Set;for(const r of e.getDescendantsOfKind(u.PropertyAccessExpression))t(r.getExpression())&&s.add(r.getName());for(const r of e.getDescendantsOfKind(u.VariableDeclaration)){const n=r.getInitializer(),o=r.getNameNode();if(!(n===void 0||!t(n)||!i.isObjectBindingPattern(o)))for(const a of o.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},Pn=(e,t)=>{const s=Object.fromEntries(fe.map(r=>[r.key,!1]));for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=new Set(n.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=bn(n);for(const c of fe)if(!s[c.key]){if(o.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(fe.every(c=>s[c.key]))break}return s},wn=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings/kv"),mail:e.mail||t.dependencies.has("@lunora/mail"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),In=e=>i.isIdentifier(e)&&e.getText()==="ctx",Ln=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&In(t.getExpression())},On=e=>{if(e?.getKind()===u.TrueKeyword)return!0;if(e?.getKind()===u.FalseKeyword)return!1},Fn=(e,t)=>{if(!Ln(e.getExpression()))return;const[s,r]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const n=s.getLiteralValue(),o=On(r);if(!(n.length===0||o===void 0))return{defaultValue:o,exportName:h(e),file:t,key:n,line:e.getStartLineNumber()}},Dn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Fn(r,t);n&&s.push(n)}return s},Tn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Dn(n,f(t,r)))}return s},Cn=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},kn=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Kn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression))Cn(a)&&s.push({file:o,indexName:kn(a),line:a.getStartLineNumber()})}return s},Rn=new Set(["delete","get","head","options","patch","post","put"]),Mn=new Set(["handler","stream"]),zn=new Set(["runAction","runMutation"]),jn=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),U=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,rt=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,nt=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const r=s.getNameNode();if(t)return i.isIdentifier(r)?r.getText():void 0;if(i.isObjectBindingPattern(r)){for(const n of r.getElements())if((n.getPropertyNameNode()?.getText()??n.getNameNode().getText())==="ctx"){const o=n.getNameNode();return i.isIdentifier(o)?o.getText():void 0}}},it=(e,t)=>{const s=e.getBody(),r=s.getDescendantsOfKind(u.CallExpression);i.isCallExpression(s)&&r.unshift(s);for(const n of r){const o=n.getExpression();if(!i.isPropertyAccessExpression(o))continue;const a=o.getName(),c=o.getExpression();if(zn.has(a)&&U(c,t))return a;if(jn.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&U(c.getExpression(),t))return`db.${a}`}},ot=(e,t)=>{const s=e.getBody();for(const r of s.getDescendantsOfKind(u.PropertyAccessExpression))if(r.getName()==="auth"&&U(r.getExpression(),t))return!0;for(const r of s.getDescendantsOfKind(u.VariableDeclaration)){const n=r.getNameNode();if(!(!i.isObjectBindingPattern(n)||!U(r.getInitializer(),t))){for(const o of n.getElements())if((o.getPropertyNameNode()?.getText()??o.getNameNode().getText())==="auth")return!0}}return!1},qn=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Mn.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))return;const n=r.getName();if(Rn.has(n)){const o=r.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?n.toUpperCase():void 0}s=r.getExpression()}},Bn=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=rt(e.getArguments()[0]),l=c&&nt(c,!0);if(!c||l===void 0)return;const m=it(c,l);return m===void 0?void 0:{exportName:h(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ot(c,l),sideEffect:m}}const r=qn(e);if(r===void 0)return;const n=rt(e.getArguments()[0]),o=n&&nt(n,!1);if(!n||o===void 0)return;const a=it(n,o);return a===void 0?void 0:{exportName:h(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:r,readsAuth:ot(n,o),sideEffect:a}},Vn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Bn(r,t);n&&s.push(n)}return s},Un=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Vn(n,f(t,r)))}return s},Wn=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),Gn=new Set(["append","set"]),Ae=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",Et=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",at=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(u.CallExpression)]:e.getDescendantsOfKind(u.CallExpression)).some(s=>Wn.has(Ae(s.getExpression()))&&B(s,t)),_n=(e,t)=>{if(at(e,t))return!0;const s=L(e);return s!==void 0&&at(s,t)},Ee=(e,t)=>tr(e,t)&&!_n(e,t),Hn=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=L(e);return t!==void 0&&i.isNewExpression(t)&&Ae(t.getExpression())==="Headers"},W=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=L(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},$e=(e,t,s)=>{for(const r of e.getProperties())if(i.isPropertyAssignment(r)){const n=r.getInitializer();n!==void 0&&Ee(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:Et(r.getNameNode()),line:n.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(r)){const n=r.getNameNode();Ee(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:r.getName(),line:n.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(r)){const n=W(r.getExpression());n!==void 0&&$e(n,t,s)}},yt=(e,t)=>{const s=W(e);if(s===void 0)return;const r=s.getProperty("headers");if(r===void 0||!i.isPropertyAssignment(r))return;const n=W(r.getInitializer());n!==void 0&&$e(n,"response-init",t)},Qn=(e,t)=>{const s=Ae(e.getExpression());if(s==="Response")yt(e.getArguments()[1],t);else if(s==="Headers"){const r=W(e.getArguments()[0]);r!==void 0&&$e(r,"headers-ctor",t)}},Xn=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const r=s.getName(),n=s.getExpression();if(r==="json"&&i.isIdentifier(n)&&n.getText()==="Response"){yt(e.getArguments()[1],t);return}if(Gn.has(r)&&Hn(n)){const o=e.getArguments()[1];o!==void 0&&Ee(o,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:Et(e.getArguments()[0]),line:o.getStartLineNumber(),via:r==="set"?"headers-set":"headers-append"})}},Jn=(e,t)=>{for(const s of e.getDescendantsOfKind(u.NewExpression))Qn(s,t);for(const s of e.getDescendantsOfKind(u.CallExpression))Xn(s,t)},Zn=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const r=Ut(e.getArguments()[0]);if(r===void 0)return[];const n=r.getParameters()[1];if(n===void 0)return[];const o=n.getNameNode();if(!i.isIdentifier(o))return[];const a=[];return Jn(r,{exportName:h(e),relativePath:t,requestName:o.getText(),rows:a}),a},Yn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...Zn(r,t));return s},ei=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Yn(n,f(t,r)))}return s},At="identity.ts",$t=new Set(["@lunora/server","lunorash/server"]),ti=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return $t.has(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},si=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const r=s.getFirstAncestorByKind(u.ImportDeclaration);return r!==void 0&&$t.has(r.getModuleSpecifierValue())}return!1},ri=e=>{if(i.isIdentifier(e))return ti(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&si(t)}return!1},ni=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!ri(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw _(n,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},ii=(e,t)=>{const s=g(t,At);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=ni(r);if(n.length!==0){if(n.length>1)throw _(r,`lunora/identity.ts declares ${n.length.toString()} defineIdentity() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},oi=new Set(["auth","context.auth","ctx.auth"]),ai="userId",ci=e=>{const t=new Set;for(const s of e.getProperties()){if(i.isSpreadAssignment(s))return;(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s))&&t.add(s.getName())}return t},ui=(e,t)=>{const s=g(t,At);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const n of r.getDescendantsOfKind(u.CallExpression)){if(b(n.getExpression())!=="defineIdentity")continue;const[o]=n.getArguments();return o&&i.isObjectLiteralExpression(o)?ci(o):void 0}},ct=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return oi.has(e.getExpression().getText())?e:void 0},li=e=>{if(i.isPropertyAccessExpression(e)&&ct(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&ct(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},di=(e,t,s)=>{const r=[];for(const n of e.getDescendants()){const o=li(n);o!==void 0&&r.push({declared:o===ai||s.has(o),exportName:h(n),file:t,key:o,line:n.getStartLineNumber()})}return r},gi=(e,t)=>{const s=ui(e,t);if(s===void 0)return[];const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(...di(o,f(t,n),s))}return r},fi=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},pi=(e,t)=>{if(b(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const r=fi(s);if(!(!r||!P(r)||D(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},mi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=pi(r,t);n&&s.push(n)}return s},xi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...mi(n,f(t,r)))}return s},hi=new Set(["delete","get","getRaw","getWithMetadata","put"]),Ei=(e,t)=>H(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:hi}),yi=new Set(["queue","send"]),ut=new Set(["bcc","cc","to"]),Ai=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!yi.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},$i=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const r=t.getNameNode();return ut.has(t.getName())&&P(r)&&!D(r)}if(!i.isPropertyAssignment(t)||!ut.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&P(s)&&!D(s)}):!1,Si=(e,t)=>{const s=Ai(e.getExpression());if(s===void 0)return;const r=e.getArguments()[0];if(!(!r||!$i(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Ni=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Si(r,t);n&&s.push(n)}return s},vi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ni(n,f(t,r)))}return s},bi=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},Pi=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},wi=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==u.CallExpression)return;const s=t;return $s(s.getExpression())?s:void 0},Ii=e=>{const t=wi(e),s=t===void 0?void 0:Pi(t);if(s===void 0)return[];const r=e.getNameNode(),n=i.isIdentifier(r)?r.getText():"";return s.getDescendantsOfKind(u.CallExpression).filter(o=>bi(o)).map(o=>({exportName:n,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},Li=e=>e.getVariableDeclarations().flatMap(t=>Ii(t)),Oi=(e,t)=>{const s=g(t,As);if(!E(s))return[];const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Li(r)},Fi=new Set(["delete","get","patch"]),Di=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Ti=new Set(["auth","identity","session","user"]),Ci=new Set([u.EqualsEqualsEqualsToken,u.EqualsEqualsToken,u.ExclamationEqualsEqualsToken,u.ExclamationEqualsToken]),ki=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!k(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},Ki=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(i.isAsExpression(s)||i.isParenthesizedExpression(s)||i.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!i.isVariableDeclaration(s))return;const r=s.getNameNode();return i.isIdentifier(r)?r.getText():void 0},Ri=(e,t)=>e.getDescendantsOfKind(u.Identifier).some(s=>s.getText()===t),Mi=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(u.ThrowStatement).length>0||e.getDescendantsOfKind(u.ReturnStatement).length>0,zi=(e,t)=>e.getDescendantsOfKind(u.IfStatement).some(s=>Ri(s.getExpression(),t)&&Mi(s.getThenStatement())),ji=(e,t)=>{for(const s of e.getDescendantsOfKind(u.CallExpression)){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))continue;const n=r.getName();if(!Fi.has(n))continue;const o=r.getExpression();if(!(k(o)||i.isPropertyAccessExpression(o)&&k(o.getExpression())))continue;const a=s.getArguments()[0];if(a!==void 0&&i.isIdentifier(a)&&a.getText()===t)return n}},qi=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t)||i.isParenthesizedExpression(t)||i.isAsExpression(t)||i.isAwaitExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t.getText():void 0},Bi=e=>e.getDescendantsOfKind(u.CallExpression).some(t=>t.getArguments().some(s=>qi(s)==="ctx")),Vi=e=>e.getDescendantsOfKind(u.BinaryExpression).some(t=>Ci.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),Ui=e=>{for(const t of e.getDescendantsOfKind(u.Identifier))if(Di.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&Ti.has(t.getName()))return!0}return Bi(e)||Vi(e)},Wi=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const r=K(s);if(r?.kind!=="query"&&r?.kind!=="mutation")return[];const n=ft(s);if(n===void 0)return[];const o=r.receiver!==void 0&&pt(r.receiver,"use","rls"),a=Ui(n),c=new Set,l=[];for(const m of n.getDescendantsOfKind(u.CallExpression)){const y=ki(m);if(y===void 0)continue;const O=Ki(m);if(O===void 0||c.has(O)||!zi(n,O))continue;const R=ji(n,O);R!==void 0&&(c.add(O),l.push({exportName:e.getName(),file:t,line:m.getStartLineNumber(),mentionsOwnership:a,sinkMethod:R,table:y,usesRls:o,visibility:r.visibility}))}return l},Gi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Wi(c,o))}return s},_i=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Hi=new Set(["insert","insertManyUnsafe","patch","replace"]),Qi=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Hi.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="db")return;const r=s.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"?t:void 0},Xi=(e,t)=>{if(t!=="insertManyUnsafe")return i.isObjectLiteralExpression(e)?[e]:[];if(!i.isArrayLiteralExpression(e))return[];const s=[];for(const r of e.getElements())i.isObjectLiteralExpression(r)&&s.push(r);return s},Ji=(e,t,s,r)=>{const n=[];for(const o of e.getProperties()){let a,c;i.isPropertyAssignment(o)?(a=o.getName(),c=o.getInitializer()):i.isShorthandPropertyAssignment(o)&&(a=o.getName(),c=o.getNameNode()),!(a===void 0||c===void 0||!_i.has(a))&&P(c)&&!D(c)&&n.push({exportName:h(s),field:a,file:r,line:s.getStartLineNumber(),method:t})}return n},Zi=(e,t)=>{const s=Qi(e.getExpression());if(s===void 0)return[];const r=e.getArguments()[1];return r?Xi(r,s).flatMap(n=>Ji(n,s,e,t)):[]},Yi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...Zi(r,t));return s},eo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Yi(n,f(t,r)))}return s},to=e=>{const t=g(e,"package.json");if(!E(t))return new Set;try{const s=JSON.parse(ye(t,"utf8")),r=new Set;for(const n of["dependencies","devDependencies","peerDependencies","optionalDependencies"]){const o=s[n];if(o!==null&&typeof o=="object")for(const a of Object.keys(o))r.add(a)}return r}catch{return new Set}},so=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),ro=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,no=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?ro(t.getInitializer()):void 0},io=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=b(r.getExpression());if(n===void 0||!so.has(n))continue;const[o]=r.getArguments(),a=o&&i.isObjectLiteralExpression(o)?no(o):void 0;s.push({callee:n,exportName:h(r),file:t,line:r.getStartLineNumber(),...a===void 0?{}:{toleranceSeconds:a}})}return s},oo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...io(n,f(t,r)))}return s},ao=new Set(["defineQueue","defineWorkflow"]),co=new Set(["run","runAction","runMutation","runQuery"]),uo=new Set(["api","internal"]),lo=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},go=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!i.isPropertyAssignment(s))return;const r=s.getInitializer();if(r&&(i.isArrowFunction(r)||i.isFunctionExpression(r)))return r},St=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},Nt=(e,t)=>e===t||e.startsWith(`${t}.`),vt=e=>{const t=e.getDescendantsOfKind(u.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},lt=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e||i.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(i.isBindingElement(t)&&t.getNameNode()===e)},bt=e=>{const t=e.getDescendantsOfKind(u.Identifier).filter(s=>lt(s));return i.isIdentifier(e)&<(e)&&t.push(e),t},fo=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(u.BindingElement).map(s=>s.getName())},po=e=>{const t=St(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const r of e.getDescendantsOfKind(u.ForOfStatement)){if(r.getExpression().getText()!==`${t}.messages`)continue;const n=r.getInitializer(),o=i.isVariableDeclarationList(n)?n.getDeclarations()[0]?.getNameNode():void 0;o&&i.isIdentifier(o)&&s.push(`${o.getText()}.body`)}return s},mo=(e,t,s)=>{const r=t==="workflow"?[`${s}.params`]:po(e),n=new Set,o=a=>vt(a).some(c=>r.some(l=>Nt(c.getText(),l)))?!0:bt(a).some(c=>n.has(c.getText()));for(const a of e.getDescendantsOfKind(u.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of fo(a))n.add(l)}return{names:n,prefixes:r}},xo=(e,t)=>vt(e).some(s=>t.prefixes.some(r=>Nt(s.getText(),r)))?!0:bt(e).some(s=>t.names.has(s.getText())),ho=e=>{if(e===void 0||!i.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;i.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const r=t.at(-1);if(!(r===void 0||!i.isIdentifier(s)||!uo.has(s.getText())||t.length<2))return{exportName:r,file:t.slice(0,-1).join("/")}},Eo=(e,t,s)=>{const r=St(e,0);if(r===void 0)return[];const n=mo(e,t,r),o=[];for(const a of e.getDescendantsOfKind(u.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!co.has(c.getName())||c.getExpression().getText()!==r)continue;const l=a.getArguments()[1];if(!l||!xo(l,n))continue;const m=ho(a.getArguments()[0]);m!==void 0&&o.push({dispatchKind:t,file:s,handlerExport:h(a),line:a.getStartLineNumber(),targetExport:m.exportName,targetFile:m.file})}return o},yo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=lo(r);if(n===void 0||!ao.has(n))continue;const o=go(r);o!==void 0&&s.push(...Eo(o,n==="defineQueue"?"queue":"workflow",t))}return s},Ao=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...yo(n,f(t,r)))}return s},dt={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},$o=/account|credential|member|passkey|session|user/iu,Pt=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},So=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},No=e=>{if(i.isCallExpression(e))return e;if(!i.isIdentifier(e))return;const t=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return t&&i.isCallExpression(t)?t:void 0},V={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},vo=e=>{const t=No(e),s=t?Pt(t):void 0;if(t&&s==="protectPublic"){const r=So(t);return{...V,usesCaptcha:r.usesCaptcha,usesRateLimit:r.usesRateLimit}}return s!==void 0&&s in dt?{...V,[dt[s]]:!0}:V},bo=e=>{const t={...V};let s=e;for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))break;const n=r.getName()==="use"?s.getArguments()[0]:void 0;if(n){const o=vo(n);t.usesCaptcha||=o.usesCaptcha,t.usesEmailGate||=o.usesEmailGate,t.usesMask||=o.usesMask,t.usesRateLimit||=o.usesRateLimit,t.usesRls||=o.usesRls}s=r.getExpression()}return t},Po=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insert")return!1;const s=t.getExpression();if(!(i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"))return!1;const r=e.getArguments()[0];return!!(r&&i.isStringLiteral(r)&&$o.test(r.getLiteralText()))},wo=new Set(["create","runAfter","runAt","send","sendBatch"]),Io=new Set(["queues","scheduler","workflows"]),Lo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!wo.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&Io.has(s.getName())){const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="ctx")return!0}s=s.getExpression()}return!1},Oo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},Fo=new Set(["generateObject","generateText","streamObject","streamText"]),Do=e=>{const t=Pt(e);if(t===void 0||!Fo.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(r=>i.isSpreadAssignment(r))?!1:!s.getProperty("maxOutputTokens")},To=e=>e.getDescendantsOfKind(u.PropertyAccessExpression).some(t=>{const s=t.getName();if(s!=="mail"&&s!=="email")return!1;const r=t.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"}),Co=e=>{let t=!1,s=!1,r=!1,n=!1;for(const o of e.getDescendantsOfKind(u.CallExpression))if(Po(o)&&(n=!0),Lo(o)&&(t=!0),Oo(o)&&(r=!0),Do(o)&&(s=!0),n&&t&&r&&s)break;return{callsMail:To(e),fanOut:t,unboundedAiGeneration:s,usesInsertManyUnsafe:r,writesUserTable:n}},ko=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=K(s);if(!r||r.kind!=="query"&&r.kind!=="mutation"&&r.kind!=="action")return;const n=r.receiver?bo(r.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},{callsMail:o,fanOut:a,unboundedAiGeneration:c,usesInsertManyUnsafe:l,writesUserTable:m}=Co(e);return{callsMail:o,exportName:e.getName(),fanOut:a,file:t,kind:r.kind,unboundedAiGeneration:c,usesCaptcha:n.usesCaptcha,usesEmailGate:n.usesEmailGate,usesInsertManyUnsafe:l,usesMask:n.usesMask,usesRateLimit:n.usesRateLimit,usesRls:n.usesRls,visibility:r.visibility,writesUserTable:m}},Ko=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=ko(n,t);o&&s.push(o)}return s},Ro=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ko(n,f(t,r)))}return s},Mo=new Set(["dbRateLimit","rateLimit"]),zo=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},jo=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},qo=e=>i.isArrowFunction(e)?e.getBody():e,Bo=(e,t)=>{const s=b(e.getExpression());if(s===void 0||!Mo.has(s))return;const r=e.getArguments()[2];if(!r)return;const n=zo(r);if(!n)return;const o=qo(n);if(!(!P(o)||D(o)))return{callee:s,exportName:h(e),file:t,limitName:jo(e),line:e.getStartLineNumber()}},Vo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Bo(r,t);n&&s.push(n)}return s},Uo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Vo(n,f(t,r)))}return s},Wo=new Set(["findFirst","findFirstOrThrow","findMany","get"]),Go=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Wo.has(t.getName()))return;const s=t.getExpression();if(k(s)){const r=e.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&k(s.getExpression()))return s.getName()},_o=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&k(s.getExpression())){const r=t.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}t=s.getExpression()}},Ho=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},wt=(e,t=!1)=>{const s=Ho(e);if(i.isIdentifier(s)){if(t)return;const r=L(s);return r===void 0?void 0:wt(r,!0)}if(i.isCallExpression(s))return Go(s)??_o(s)},Qo=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const r of e.getDescendantsOfKind(u.ReturnStatement)){const n=r.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),o=r.getExpression();n===e&&o!==void 0&&s.push(o)}return s},Xo=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const r=K(s);if(r?.kind!=="query")return[];const n=ft(s);if(n===void 0)return[];const o=r.receiver!==void 0&&Wt(r.receiver,"output"),a=r.receiver!==void 0&&pt(r.receiver,"use","mask"),c=new Set,l=[];for(const m of Qo(n)){const y=wt(m);y===void 0||c.has(y)||(c.add(y),l.push({exportName:e.getName(),file:t,line:m.getStartLineNumber(),table:y,usesMask:a,usesOutput:o,visibility:r.visibility}))}return l},Jo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Xo(c,o))}return s},Zo=new Set(["findFirst","findFirstOrThrow","findMany"]),Yo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Zo.has(t.getName()))return;const s=t.getExpression();if(i.isPropertyAccessExpression(s)&&s.getName()==="db"||i.isIdentifier(s)&&s.getText()==="db"){const r=e.getArguments()[0];return{options:e.getArguments()[1],table:r&&i.isStringLiteral(r)?r.getLiteralText():""}}if(i.isPropertyAccessExpression(s)){const r=s.getExpression();if(i.isPropertyAccessExpression(r)&&r.getName()==="db"||i.isIdentifier(r)&&r.getText()==="db")return{options:e.getArguments()[0],table:s.getName()}}},ea=e=>{if(!e||!i.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s)||i.isGetAccessorDeclaration(s))&&t.push(s.getName());return t},ta=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},sa=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&i.isCallExpression(s)?K(s):void 0;if(!r)return[];const n=[];for(const o of e.getDescendantsOfKind(u.CallExpression)){const a=Yo(o);if(a===void 0)continue;const c=ea(ta(a.options,"with"));c.length!==0&&n.push({exportName:e.getName(),file:t,line:o.getStartLineNumber(),parentTable:a.table,relations:c,visibility:r.visibility})}return n},ra=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...sa(c,o))}return s},G=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===u.PlusToken){const t=G(e.getLeft()),s=G(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},na=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===u.PlusToken;)t=s,s=t.getParent();return t!==e&&G(t)!==void 0},ia=(e,t)=>{const s=[],r=[...e.getDescendantsOfKind(u.BinaryExpression),...e.getDescendantsOfKind(u.StringLiteral),...e.getDescendantsOfKind(u.NoSubstitutionTemplateLiteral)],n=new Set;for(const o of r){if(na(o))continue;const a=G(o);if(a===void 0)continue;const c=Ts(a);if(c===void 0)continue;const l=o.getStartLineNumber(),m=`${String(l)}:${c}`;n.has(m)||(n.add(m),s.push({file:t,kind:c,line:l,preview:Cs(a)}))}return s},oa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ia(n,f(t,r)))}return s},aa=new Set(["findFirst","findFirstOrThrow","findMany"]),ca=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!aa.has(t.getName()))return;const s=t.getExpression();if(i.isPropertyAccessExpression(s)&&s.getName()==="db"||i.isIdentifier(s)&&s.getText()==="db"){const r=e.getArguments()[0];return{options:e.getArguments()[1],table:r&&i.isStringLiteral(r)?r.getLiteralText():""}}if(i.isPropertyAccessExpression(s)){const r=s.getExpression();if(i.isPropertyAccessExpression(r)&&r.getName()==="db"||i.isIdentifier(r)&&r.getText()==="db")return{options:e.getArguments()[0],table:s.getName()}}},ua=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},la=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&i.isCallExpression(s)?K(s):void 0;if(!r)return[];const n=[];for(const o of e.getDescendantsOfKind(u.CallExpression)){const a=ca(o);if(a===void 0)continue;const c=ua(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),m=!l&&P(c);!l&&!m||n.push({exportName:e.getName(),file:t,fromArgs:m,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:r.visibility})}return n},da=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...la(c,o))}return s},ga=new Set(["query","unsafe"]),fa=e=>{if(!i.isPropertyAccessExpression(e)||!ga.has(e.getName()))return!1;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return i.isIdentifier(s)&&s.getText()==="ctx"},pa=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),ma=e=>e.getFirstAncestorByKind(u.VariableDeclaration)?.getName()??"<module>",xa=(e,t)=>{if(!fa(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!pa(s)))return{exportName:ma(e),file:t,line:s.getStartLineNumber()}},ha=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=xa(r,t);n&&s.push(n)}return s},Ea=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ha(n,f(t,r)))}return s},ya=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Aa=(e,t)=>H(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.storage"||s.startsWith("ctx.storage."),methods:ya}),$a=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Sa=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Na=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!i.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,r=!1;for(const n of e.getProperties()){if(i.isSpreadAssignment(n)){r=!0;continue}if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o),o==="expiresInSeconds"&&(s=Sa(n.getInitializer()));continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,expiresInSeconds:s,presentKeys:t}},va=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=$a.get(t);if(s===void 0)return;const r=e.getExpression().getText();return r==="ctx.storage"||r.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},ba=(e,t)=>{const s=va(e.getExpression());if(s!==void 0)return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s.method,...Na(e.getArguments()[s.optionsIndex])}},Pa=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ba(r,t);n&&s.push(n)}return s},wa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Pa(n,f(t,r)))}return s},Ia=new Set(["when","where"]),xe=new Set(["definePolicy","defineShape"]),La=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const r=t.getName();return xe.has(r)?r:void 0}if(!i.isIdentifier(t))return;for(const r of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(r)){const n=r.getNameNode().getText();return xe.has(n)?n:void 0}const s=t.getText();return xe.has(s)?s:void 0},Oa=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,It=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===u.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Oa(e))return"empty-object";if(i.isParenthesizedExpression(e))return It(e.getExpression())}},Lt=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Ot=e=>e.getDescendantsOfKind(u.ReturnStatement).filter(t=>Lt(t)===e),Ft=e=>e.getDescendantsOfKind(u.ConditionalExpression).filter(t=>Lt(t)===e),Fa=e=>{const t=Ot(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(u.IfStatement)!==void 0)||Ft(e).length>0},Da=e=>{const t=[],s=e.getBody();i.isBlock(s)||t.push(s);for(const r of Ot(e)){const n=i.isReturnStatement(r)?r.getExpression():void 0;t.push(n??r)}for(const r of Ft(e))t.push(r.getWhenTrue(),r.getWhenFalse());return t},Ta=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},Ca=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[r]=e.getArguments();if(!r||!i.isObjectLiteralExpression(r))return[];const n=[];for(const o of r.getProperties()){if(!i.isPropertyAssignment(o)||!Ia.has(o.getName()))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Fa(a))for(const c of Da(a)){const l=It(c);l!==void 0&&n.push({exportName:Ta(e),file:s,form:l,key:o.getName(),line:c.getStartLineNumber(),owner:t})}}return n},ka=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=La(r);n!==void 0&&s.push(...Ca(r,n,t))}return s},Ka=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ka(n,f(t,r)))}return s},Ra=new Set(["query","upsert","upsertMany"]),Ma=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(Ra.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},za=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("namespace");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},ja=(e,t)=>{const s=Ma(e.getExpression());if(s===void 0)return;const r=e.getArguments()[1];if(!r)return;const n=za(r);if(!(!n||!P(n)||D(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},qa=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ja(r,t);n&&s.push(n)}return s},Ba=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...qa(n,f(t,r)))}return s},Va=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="workflows":i.isIdentifier(s)&&s.getText()==="workflows"},Ua=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Wa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){if(!Va(a))continue;const c=Rs(a);c!==""&&s.push({exportName:c,file:o,line:a.getStartLineNumber(),workflow:Ua(a)})}}return s},Ga=".lunora-schema.json",$=(e,t)=>{E(e)&&ye(e,"utf8")===t||qt(e,t,"utf8")},v=(e,t)=>{if(t===""){Bt(e,{force:!0});return}$(e,t)},_a=e=>{const t=g(e,"package.json");if(E(t))try{const s=JSON.parse(ye(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},Ha=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Qa=e=>{let t=E(e)?e:de(e);for(;t&&t!==de(t);){const s=g(t,"tsconfig.json");if(E(s))return s;t=de(t)}},gt=e=>e.replaceAll("\\","/"),Xa=(e,t)=>{const s=new Map,r=new Map,n=new Map;for(const o of e)s.set(o.name,`workflow "${o.exportName}"`),r.set(o.bindingName,`workflow "${o.exportName}"`),n.set(o.className,`workflow "${o.exportName}"`);for(const o of t){const a=s.get(o.name);if(a!==void 0)throw new q("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${o.name}": produced by both ${a} and agent "${o.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=r.get(o.bindingName);if(c!==void 0)throw new q("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${o.bindingName}": produced by both ${c} and agent "${o.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const l=n.get(o.className);if(l!==void 0)throw new q("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${o.className}": produced by both ${l} and agent "${o.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},Ja=e=>{const t=Qa(e);return t?new Xe({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Xe({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Cc=(e,t)=>{const s=d(t),r=g(t,"schema.ts");E(r)&&s.push(r);for(const c of s){const l=e.getSourceFile(c);l===void 0?e.addSourceFileAtPath(c):l.refreshFromFileSystemSync()}const n=new Set(s.map(c=>gt(c))),o=gt(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!n.has(l)&&e.removeSourceFile(c)}},kc=e=>{const t=Ha(),s=t?ge.now():0,r=g(e.projectRoot,e.lunoraDirectory??"lunora"),n=g(r,"schema.ts");if(!E(n))throw new q("INTERNAL",`schema.ts not found at ${n}`);const o=e.project??Ja(r),a=Ds(o,n,e.projectRoot),c=Gt(o,r),l=ps(o,r),m=ys(o,r),y=ks(o,r),O=Ss(o,r),R=ii(o,r),Se=fn(o,r),S=Ms(o,r),T=ws(o,r),N=_t(o,r);Xa(S,N);const Q=Xt(o,r,S,N),C=Qt(o,r),Ne=e.lint===!1?[]:Vt({adminRoutes:Ys(o,r),aiRawRuns:ir(o,r),aiToolSideEffects:mr(o,r),argumentDerivedFetches:yr(o,r),argumentValidators:Or(o,r),authApiCalls:Ht(o,r),authConfigs:Mr(o,r),browserUrlAccesses:Vr(o,r),configCalls:Jr(o,r),containerKeyAccesses:Yr(o,r),containerOverrides:an(o,r),containers:C,exportSinks:hn(o,r),failOpenGuards:vn(o,r),flagSecurityDefaults:Tn(o,r),geoIndexUsages:Kn(o,r),httpActionGuards:Un(o,r),httpHeaderWrites:ei(o,r),identityClaimReads:gi(o,r),imageDeliveryUrlAccesses:xi(o,r),inserts:ms(o,r),kvKeyAccesses:Ei(o,r),mailRecipientAccesses:vi(o,r),maskProcedures:xs(o,r),maskStrategies:hs(o,r),mutatorWrites:Oi(o,r),nondeterministicCalls:Ns(o,r),normalizeIdAuthorizations:Gi(o,r),notifyCalls:bs(o,r),notifyConfig:vs(o,r),ownerFieldWrites:eo(o,r),unrestrictedWhereBranches:Ka(o,r),paymentWebhooks:oo(o,r),privilegedDispatches:Ao(o,r),procedureProtections:Ro(o,r),queries:Ps(o,r),queues:T,r2sqlCalls:Is(o,r),ratelimitKeySelectors:Uo(o,r),rawRowReturns:Jo(o,r),relationLoads:ra(o,r),rlsProcedures:Ls(o,r),schema:a,secretLiterals:oa(o,r),shapes:y,softDeleteReads:da(o,r),sqlInterpolations:Ea(o,r),storageKeyAccesses:Aa(o,r),storageUploads:wa(o,r),vectorNamespaceAccesses:Ba(o,r),workflowCalls:Wa(o,r),workflows:S,wranglerVariables:e.wranglerVariables}),Dt=Os(o,r),Tt=Es(o,r),X=Ks(o,r),A=Pn(o,r),J=A.ai,Z=A.payments,ve=A.kv,be=A.access,Y=E(g(r,"flags.ts")),Ct=Y?fs(o,r):[],ee=E(g(r,"notify.ts")),te=A.hyperdrive,se=Fs(o,r),kt=se.usesSandboxBrowser||se.usesSandboxContainer,re=A.browser||se.usesSandboxBrowser,ne=A.images,ie=A.analytics,Pe=A.pipelines,oe=A.r2sql,ae=A.x402,w=to(e.projectRoot),M=wn(A,{containerCount:C.length,cronCount:Q.length,dependencies:w,hasPaymentTables:a.tables.some(p=>p.name==="subscriptions")&&a.tables.some(p=>p.name==="events"),queueCount:T.length,storageColumnCount:Object.keys(Jt(a)).length,storageRuleCount:X.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:S.length}),F=w.has("lunorash"),we=t?ge.now():0,Ie=Zt(a,F),Le=Yt({agents:N,functions:c,httpRoutes:l,useUmbrella:F,workflows:S}),Oe=es({agents:N,containers:C,env:Se,hasAccessFacade:be,hasAi:J,hasAnalytics:ie,hasBrowser:re,hasFlags:Y,hasHyperdrive:te,hasImages:ne,hasKv:ve,hasNotify:ee,hasPayments:Z,hasPipelines:Pe,hasR2sql:oe,hasX402:ae,identity:R,queues:T,schema:a,storageRuleBuckets:X.rules.map(p=>p.bucket),useUmbrella:F,workflows:S}),Fe=ts({agents:N,functions:c,migrations:m,mutators:O,shapes:y,useUmbrella:F,usesSandbox:kt}),De=ss({advisories:Ne,agents:N,containers:C,env:Se,flagKeys:Ct,hasAccessFacade:be,hasAi:J,hasAnalytics:ie,hasBrowser:re,hasFlags:Y,hasHyperdrive:te,hasImages:ne,hasKv:ve,hasNotify:ee,hasPayments:Z,hasPipelines:Pe,hasR2sql:oe,hasX402:ae,maskMetadata:Tt,mutators:O,queues:T,rlsMetadata:Dt,schema:a,shapes:y,storageRules:X,studioFeatures:M,useUmbrella:F,workflows:S}),Te=rs(y,w.has("@lunora/db"),F),Ce=ns(C,a.jurisdiction),ke=is(S),Ke=os(N),Re=as(T),Me=cs(Q),ze=us(a.vectorIndexes),z=ls(a,F),je=ds(w.has("@lunora/seed")),j=e.apiSpec??"openapi",ce=j==="openapi"||j==="both",ue=j==="openrpc"||j==="both",qe=zs({emailAgents:N.filter(p=>p.onEmail===!0).map(p=>({bindingName:p.bindingName,exportName:p.exportName})),hasAccess:w.has("@lunora/cloudflare-access"),hasAi:J,hasAnalytics:ie,hasAuth:w.has("@lunora/auth"),hasBrowser:re,hasFramework:w.has("@lunora/astro")||w.has("@lunora/svelte")||w.has("@lunora/vue"),hasGlobal:a.tables.some(p=>p.shardMode==="global"&&p.globalBackend!=="hyperdrive"),hasHyperdrive:te,hasHyperdriveGlobal:a.tables.some(p=>p.shardMode==="global"&&p.globalBackend==="hyperdrive"),hasImages:ne,hasKv:M.kv,hasNotify:ee,hasPayments:Z,hasR2sql:oe,hasQueue:T.some(p=>p.mode==="push"),hasScheduler:M.scheduler,hasStorage:M.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:S.length>0,hasX402:ae,identity:R,jurisdiction:a.jurisdiction,useUmbrella:F,voiceAgents:N.filter(p=>p.voice===!0&&p.voiceBindingName!==void 0).map(p=>({bindingName:p.voiceBindingName,exportName:p.exportName})),wantsOpenApi:ce,wantsOpenRpc:ue}),Be=_a(e.projectRoot),Ve=js({functions:c,httpRoutes:l,version:Be}),Ue=Bs({functions:c,version:Be}),We=`${JSON.stringify(Ve,void 0,2)}
|
|
1
|
+
import{existsSync as E,readFileSync as ye,mkdirSync as jt,writeFileSync as qt,rmSync as Bt}from"node:fs";import{join as g,dirname as de}from"node:path";import{performance as ge}from"node:perf_hooks";import{LunoraError as q}from"@lunora/errors";import{Node as i,SyntaxKind as u,Project as Xe}from"ts-morph";import{lintSchema as Vt}from"./formatAdvisories-DZvv-0MG.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as f,classifyProcedureCall as K,inlineHandler as Ut,procedureHandler as ft,chainUsesWrappedCall as pt,isDatabaseAccessor as k,chainHasStep as Wt,discoverFunctions as Gt}from"./discoverFunctions-BdibLQmc.mjs";import{discoverAgents as _t}from"./AGENTS_FILENAME-BesaDYkL.mjs";import Ht from"./discoverAuthApiCalls-DOfSQqVK.mjs";import{discoverContainers as Qt}from"./CONTAINERS_FILENAME-CFwdyaCI.mjs";import Xt from"./discoverCrons-B09_uEuL.mjs";import{diagnosticAt as _}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{r as fe,a as Jt,G as Zt,n as Yt,u as es,g as ts,K as ss,o as rs,L as ns,D as is,E as os,_ as as,X as cs,Y as us,z as ls,b as ds,Z as gs}from"./emit-BYVxPDqO.mjs";import{discoverFlagKeys as fs}from"./FLAGS_FILENAME-DW5oGq1q.mjs";import ps from"./discoverHttpRoutes-BOWz6y_n.mjs";import ms from"./discoverInserts-BtteTyNy.mjs";import xs,{discoverMaskStrategies as hs,discoverMaskMetadata as Es}from"./discoverMaskProcedures-COPmwMBm.mjs";import ys from"./discoverMigrations-iGMlp9YJ.mjs";import{MUTATORS_FILENAME as As,isDefineMutatorCallee as $s,discoverMutators as Ss}from"./MUTATORS_FILENAME-BKKPROzu.mjs";import Ns from"./discoverNondeterministicCalls-Dmgc4QBx.mjs";import{discoverNotifyConfig as vs,discoverNotifyCalls as bs}from"./NOTIFY_FILENAME-C-c7Lg-U.mjs";import Ps from"./discoverQueries-CcfuGKHh.mjs";import{discoverQueues as ws}from"./QUEUES_FILENAME-CSE6i-ld.mjs";import Is from"./discoverR2sqlCalls-CjZKvg-N.mjs";import Ls,{discoverRlsMetadata as Os}from"./discoverRlsMetadata-BXmNOgry.mjs";import{discoverSandboxUsage as Fs}from"./discoverSandboxUsage-CDdBqWcM.mjs";import Ds from"./discoverSchema-m2voTncu.mjs";import{secretKindOf as Ts,redact as Cs}from"./redact-CQ8-to6l.mjs";import{discoverShapes as ks}from"./SHAPES_FILENAME-DTkSJSsg.mjs";import Ks from"./discoverStorageRulesMetadata-b71cJJHz.mjs";import{e as Rs}from"./discover-ast-CezKqEhE.mjs";import{discoverWorkflows as Ms}from"./WORKFLOWS_FILENAME-Bk5upkGM.mjs";import{emitApp as zs}from"./emitApp-CHCOfQer.mjs";import{buildOpenApiDocument as js,emitOpenApiModule as qs}from"./buildOpenApiDocument-BRCc5AIx.mjs";import{buildOpenRpcDocument as Bs,emitOpenRpcModule as Vs}from"./OPENRPC_VERSION-DWoqALFJ.mjs";import{buildSchemaSnapshot as Us,serializeSchemaSnapshot as Ws}from"./SCHEMA_SNAPSHOT_VERSION-Bpf1FGMG.mjs";const mt=new Set(["delete","get","head","options","patch","post","put"]),Gs=new Set(["handler","stream"]),_s=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,Je=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Hs=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!mt.has(t.getName()))return;const s=t.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpRoute")return;const r=e.getArguments()[0];if(!(!r||!i.isStringLiteral(r)))return{method:t.getName().toUpperCase(),path:r.getLiteralValue()}},Qs=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||mt.has(r.getName()))break;s=r.getExpression()}return Hs(s)},Xs=e=>{for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression))if(Je.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&Je.has(s.getText()))return!0}return!1},Js=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||!Gs.has(r.getName()))return;const n=Qs(s);if(!n||!_s.test(n.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&Xs(o);return{exportName:e.getName(),file:t,method:n.method,path:n.path,usesGuard:a}},Zs=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Js(n,t);o&&s.push(o)}return s},Ys=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Zs(n,f(t,r)))}return s},Ze=e=>{if(e.getText()!=="args")return!1;const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(i.isPropertyAssignment(t)&&t.getNameNode()===e)},Ye=e=>{if(e.getText()!=="ctx")return!1;const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(i.isPropertyAssignment(t)&&t.getNameNode()===e)},pe=e=>i.isIdentifier(e)?Ye(e):e.getDescendantsOfKind(u.Identifier).some(t=>Ye(t)),et=(e,t)=>{if(e.getText()!==t)return!1;const s=e.getParent();return i.isPropertyAccessExpression(s)&&s.getNameNode()===e?!1:!(i.isPropertyAssignment(s)&&s.getNameNode()===e)},er=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t:void 0},b=e=>{if(i.isIdentifier(e))return e.getText();if(i.isPropertyAccessExpression(e))return e.getName()},he=e=>i.isIdentifier(e)?Ze(e):e.getDescendantsOfKind(u.Identifier).some(t=>Ze(t)),L=e=>{if(!i.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a));if(s===void 0)return;const r=e.getStart();let n,o=-1;for(const a of s.getDescendantsOfKind(u.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<r&&l>o&&(n=c,o=l)}return n},P=e=>{if(he(e))return!0;const t=L(e);return t!==void 0&&he(t)},D=e=>{if(pe(e))return!0;const t=L(e);if(t!==void 0&&pe(t))return!0;const s=t??e;return(i.isIdentifier(s)?[s]:s.getDescendantsOfKind(u.Identifier)).some(r=>{const n=L(r);return n!==void 0&&pe(n)})},B=(e,t)=>i.isIdentifier(e)?et(e,t):e.getDescendantsOfKind(u.Identifier).some(s=>et(s,t)),tr=(e,t)=>{if(B(e,t))return!0;const s=L(e);if(s!==void 0&&B(s,t))return!0;const r=er(e);if(r!==void 0){const n=L(r);return n!==void 0&&B(n,t)}return!1},h=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)&&t.getVariableStatement()?.hasExportKeyword()===!0)return t.getName();return"<module>"},sr=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",rr=(e,t)=>{if(!sr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!P(s)||D(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},nr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=rr(r,t);n&&s.push(n)}return s},ir=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...nr(n,f(t,r)))}return s},or=new Set(["generateText","streamText"]),ar=new Set(["messages","prompt","system"]),cr=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],ur=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),r=t.getExpression().getText();for(const n of cr)if(n.methods.has(s)&&n.prefixes.some(o=>r===o||r.startsWith(`${o}.`)))return`${r}.${s}`},lr=e=>{for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=ur(t);if(s!==void 0)return s}},dr=e=>{const t=new Set,s=e.getFirstAncestor(o=>i.isArrowFunction(o)||i.isFunctionExpression(o)||i.isFunctionDeclaration(o)),[r]=s?.getParameters()??[],n=r?.getNameNode();if(n===void 0||!i.isObjectBindingPattern(n))return t;for(const o of n.getElements()){const a=o.getPropertyNameNode()?.getText()??o.getName(),c=o.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},gr=e=>{if(he(e))return!0;const t=dr(e);return t.size===0?!1:e.getDescendantsOfKind(u.Identifier).some(s=>t.has(s.getText()))},fr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!ar.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&gr(s))return!0}return!1},pr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=b(r.getExpression());if(n===void 0||!or.has(n))continue;const[o]=r.getArguments();if(o===void 0||!i.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(u.CallExpression))if(b(c.getExpression())==="tool"&&(a=lr(c),a!==void 0))break;a!==void 0&&s.push({exportName:h(r),file:t,line:r.getStartLineNumber(),method:n,sideEffect:a,userInputDerived:fr(o)})}return s},mr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...pr(n,f(t,r)))}return s},xr=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},hr=(e,t)=>{if(!xr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!P(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},Er=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=hr(r,t);n&&s.push(n)}return s},yr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Er(n,f(t,r)))}return s},Ar=/\.check\(|\.meta\(|length|max/iu,$r=/\bv\.any\s*\(/u,Sr=/\bv\.string\s*\(/u,Nr=e=>$r.test(e),vr=e=>Sr.test(e)&&!Ar.test(e),br=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("args");if(!s||!i.isPropertyAssignment(s))return;const r=s.getInitializer();return r&&i.isObjectLiteralExpression(r)?r:void 0},Pr=e=>{const t=[];let s=e;for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const n=s.getArguments()[0];n&&i.isObjectLiteralExpression(n)&&t.push(n)}s=r.getExpression()}return t},wr=e=>{const t=[],s=[];for(const r of e)for(const n of r.getProperties()){if(!i.isPropertyAssignment(n))continue;const o=n.getInitializer();if(!o)continue;const a=o.getText(),c=n.getName();Nr(a)?t.push(c):vr(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Ir=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=K(s);if(r?.visibility!=="public")return;const n=r.receiver?Pr(r.receiver):[br(s)].filter(c=>c!==void 0),{anyArgs:o,unboundedStringArgs:a}=wr(n);if(!(o.length===0&&a.length===0))return{anyArgs:o,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Lr=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Ir(n,t);o&&s.push(o)}return s},Or=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Lr(n,f(t,r)))}return s},I=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},me=e=>e?.getKind()===u.TrueKeyword,Fr=e=>e?.getKind()===u.FalseKeyword,Dr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Tr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),Cr=e=>{const t=I(e,"advanced"),s=I(e,"emailAndPassword"),r=I(e,"session");return{analyzable:!0,disableCsrfCheck:me(I(t,"disableCSRFCheck")),emailPasswordEnabled:me(I(s,"enabled")),requireEmailVerification:me(I(s,"requireEmailVerification")),secureCookiesDisabled:Fr(I(t,"useSecureCookies")),sessionFreshAgeZero:Dr(I(r,"freshAge")),trustedOriginsWildcard:Tr(I(e,"trustedOrigins"))}},kr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Kr=(e,t)=>{if(b(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],r=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(o=>i.isSpreadAssignment(o)),n=s!==void 0&&i.isObjectLiteralExpression(s)&&!r?Cr(s):kr();return{exportName:h(e),file:t,line:e.getStartLineNumber(),...n}},Rr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Kr(r,t);n&&s.push(n)}return s},Mr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Rr(n,f(t,r)))}return s},zr=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},jr=(e,t,s)=>{const r=zr(e.getExpression(),s);if(r===void 0)return;const n=e.getArguments()[s.argIndex];if(!(!n||!P(n)||D(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:r}},qr=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const o=jr(n,t,s);o&&r.push(o)}return r},H=(e,t,s)=>{const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(...qr(o,f(t,n),s))}return r},Br=new Set(["content","pdf","scrape","screenshot"]),Vr=(e,t)=>H(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Br}),Ur=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Wr=new Set(["RateLimiter"]),Gr=new Set(["extend"]),xt=e=>{const t=[],s=[];let r=!1;for(const n of e.getProperties()){if(i.isSpreadAssignment(n)){r=!0;continue}if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o),n.getInitializer()?.getKind()===u.TrueKeyword&&s.push(o);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,presentKeys:t,trueKeys:s}},tt=e=>e&&i.isObjectLiteralExpression(e)?xt(e):{analyzable:!1,presentKeys:[],trueKeys:[]},_r=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!i.isReturnStatement(s))return;const r=s.getExpression();return r!==void 0&&i.isObjectLiteralExpression(r)?r:void 0},Hr=e=>{if(i.isObjectLiteralExpression(e))return e;if(i.isParenthesizedExpression(e)){const t=e.getExpression();return i.isObjectLiteralExpression(t)?t:void 0}return i.isBlock(e)?_r(e):void 0},Qr=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&Hr(t.getBody());return s?xt(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Xr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=b(r.getExpression());n!==void 0&&(Ur.has(n)?s.push({callee:n,file:t,line:r.getStartLineNumber(),...tt(r.getArguments()[0])}):Gr.has(n)&&s.push({callee:n,file:t,line:r.getStartLineNumber(),...Qr(r.getArguments()[0])}))}for(const r of e.getDescendantsOfKind(u.NewExpression)){const n=b(r.getExpression());n===void 0||!Wr.has(n)||s.push({callee:n,file:t,line:r.getStartLineNumber(),...tt(r.getArguments()[0])})}return s},Jr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Xr(n,f(t,r)))}return s},st="ctx.containers.",Zr=e=>{if(!e.startsWith(st))return!1;const t=e.slice(st.length);return t.length>0&&!t.includes(".")},Yr=(e,t)=>H(e,t,{argIndex:0,matchReceiver:Zr,methods:new Set(["get"])}),en=new Set(["allow","deny","setAllowed"]),tn=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},sn=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!tn(e)))return{detail:"enableInternet: true",exportName:h(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},rn=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!en.has(s.getName()))return;const r=s.getExpression();if(!(!i.isPropertyAccessExpression(r)||r.getName()!=="egress"))return{detail:s.getName(),exportName:h(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},nn=(e,t)=>sn(e,t)??rn(e,t),on=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=nn(r,t);n&&s.push(n)}return s},an=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...on(n,f(t,r)))}return s},cn="env.ts",ht=new Set(["@lunora/server","lunorash/server"]),un=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return ht.has(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},ln=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const r=s.getFirstAncestorByKind(u.ImportDeclaration);return r!==void 0&&ht.has(r.getModuleSpecifierValue())}return!1},dn=e=>{if(i.isIdentifier(e))return un(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&ln(t)}return!1},gn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!dn(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw _(n,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},fn=(e,t)=>{const s=g(t,cn);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=gn(r);if(n.length!==0){if(n.length>1)throw _(r,`lunora/env.ts declares ${n.length.toString()} defineEnv() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},pn=new Set(["defineExportSink","r2Sink","webhookExportSink"]),mn=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return pn.has(s)?s:void 0},xn=e=>{const t=[],s=[];for(const r of e.getProperties()){if(i.isSpreadAssignment(r))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(r)){const n=r.getName();t.push(n);const o=r.getInitializer();o&&i.isStringLiteral(o)&&o.getLiteralText()===""&&s.push(n);continue}(i.isShorthandPropertyAssignment(r)||i.isMethodDeclaration(r)||i.isGetAccessorDeclaration(r))&&t.push(r.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},hn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){const c=mn(a);if(c===void 0)continue;const l=a.getArguments()[0],m=l&&i.isObjectLiteralExpression(l)?xn(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:m.analyzable,emptyKeys:m.emptyKeys,factory:c,file:o,line:a.getStartLineNumber(),presentKeys:m.presentKeys})}}return s},En=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),yn=new Set(["dbRateLimit","rateLimit"]),An=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&i.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===u.TrueKeyword},$n=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},Sn=(e,t)=>{const s=b(e.getExpression());if(s===void 0)return;const r=En.get(s);if(r!==void 0)return{callee:s,exportName:h(e),failOpen:An(e.getArguments()[r]),file:t,limitName:yn.has(s)?$n(e):"",line:e.getStartLineNumber()}},Nn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Sn(r,t);n&&s.push(n)}return s},vn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Nn(n,f(t,r)))}return s},bn=e=>{const t=r=>i.isIdentifier(r)&&r.getText()==="ctx",s=new Set;for(const r of e.getDescendantsOfKind(u.PropertyAccessExpression))t(r.getExpression())&&s.add(r.getName());for(const r of e.getDescendantsOfKind(u.VariableDeclaration)){const n=r.getInitializer(),o=r.getNameNode();if(!(n===void 0||!t(n)||!i.isObjectBindingPattern(o)))for(const a of o.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},Pn=(e,t)=>{const s=Object.fromEntries(fe.map(r=>[r.key,!1]));for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=new Set(n.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=bn(n);for(const c of fe)if(!s[c.key]){if(o.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(fe.every(c=>s[c.key]))break}return s},wn=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings/kv"),mail:e.mail||t.dependencies.has("@lunora/mail"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),In=e=>i.isIdentifier(e)&&e.getText()==="ctx",Ln=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&In(t.getExpression())},On=e=>{if(e?.getKind()===u.TrueKeyword)return!0;if(e?.getKind()===u.FalseKeyword)return!1},Fn=(e,t)=>{if(!Ln(e.getExpression()))return;const[s,r]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const n=s.getLiteralValue(),o=On(r);if(!(n.length===0||o===void 0))return{defaultValue:o,exportName:h(e),file:t,key:n,line:e.getStartLineNumber()}},Dn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Fn(r,t);n&&s.push(n)}return s},Tn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Dn(n,f(t,r)))}return s},Cn=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},kn=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Kn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression))Cn(a)&&s.push({file:o,indexName:kn(a),line:a.getStartLineNumber()})}return s},Rn=new Set(["delete","get","head","options","patch","post","put"]),Mn=new Set(["handler","stream"]),zn=new Set(["runAction","runMutation"]),jn=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),U=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,rt=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,nt=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const r=s.getNameNode();if(t)return i.isIdentifier(r)?r.getText():void 0;if(i.isObjectBindingPattern(r)){for(const n of r.getElements())if((n.getPropertyNameNode()?.getText()??n.getNameNode().getText())==="ctx"){const o=n.getNameNode();return i.isIdentifier(o)?o.getText():void 0}}},it=(e,t)=>{const s=e.getBody(),r=s.getDescendantsOfKind(u.CallExpression);i.isCallExpression(s)&&r.unshift(s);for(const n of r){const o=n.getExpression();if(!i.isPropertyAccessExpression(o))continue;const a=o.getName(),c=o.getExpression();if(zn.has(a)&&U(c,t))return a;if(jn.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&U(c.getExpression(),t))return`db.${a}`}},ot=(e,t)=>{const s=e.getBody();for(const r of s.getDescendantsOfKind(u.PropertyAccessExpression))if(r.getName()==="auth"&&U(r.getExpression(),t))return!0;for(const r of s.getDescendantsOfKind(u.VariableDeclaration)){const n=r.getNameNode();if(!(!i.isObjectBindingPattern(n)||!U(r.getInitializer(),t))){for(const o of n.getElements())if((o.getPropertyNameNode()?.getText()??o.getNameNode().getText())==="auth")return!0}}return!1},qn=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Mn.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))return;const n=r.getName();if(Rn.has(n)){const o=r.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?n.toUpperCase():void 0}s=r.getExpression()}},Bn=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=rt(e.getArguments()[0]),l=c&&nt(c,!0);if(!c||l===void 0)return;const m=it(c,l);return m===void 0?void 0:{exportName:h(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ot(c,l),sideEffect:m}}const r=qn(e);if(r===void 0)return;const n=rt(e.getArguments()[0]),o=n&&nt(n,!1);if(!n||o===void 0)return;const a=it(n,o);return a===void 0?void 0:{exportName:h(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:r,readsAuth:ot(n,o),sideEffect:a}},Vn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Bn(r,t);n&&s.push(n)}return s},Un=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Vn(n,f(t,r)))}return s},Wn=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),Gn=new Set(["append","set"]),Ae=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",Et=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",at=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(u.CallExpression)]:e.getDescendantsOfKind(u.CallExpression)).some(s=>Wn.has(Ae(s.getExpression()))&&B(s,t)),_n=(e,t)=>{if(at(e,t))return!0;const s=L(e);return s!==void 0&&at(s,t)},Ee=(e,t)=>tr(e,t)&&!_n(e,t),Hn=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=L(e);return t!==void 0&&i.isNewExpression(t)&&Ae(t.getExpression())==="Headers"},W=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=L(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},$e=(e,t,s)=>{for(const r of e.getProperties())if(i.isPropertyAssignment(r)){const n=r.getInitializer();n!==void 0&&Ee(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:Et(r.getNameNode()),line:n.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(r)){const n=r.getNameNode();Ee(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:r.getName(),line:n.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(r)){const n=W(r.getExpression());n!==void 0&&$e(n,t,s)}},yt=(e,t)=>{const s=W(e);if(s===void 0)return;const r=s.getProperty("headers");if(r===void 0||!i.isPropertyAssignment(r))return;const n=W(r.getInitializer());n!==void 0&&$e(n,"response-init",t)},Qn=(e,t)=>{const s=Ae(e.getExpression());if(s==="Response")yt(e.getArguments()[1],t);else if(s==="Headers"){const r=W(e.getArguments()[0]);r!==void 0&&$e(r,"headers-ctor",t)}},Xn=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const r=s.getName(),n=s.getExpression();if(r==="json"&&i.isIdentifier(n)&&n.getText()==="Response"){yt(e.getArguments()[1],t);return}if(Gn.has(r)&&Hn(n)){const o=e.getArguments()[1];o!==void 0&&Ee(o,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:Et(e.getArguments()[0]),line:o.getStartLineNumber(),via:r==="set"?"headers-set":"headers-append"})}},Jn=(e,t)=>{for(const s of e.getDescendantsOfKind(u.NewExpression))Qn(s,t);for(const s of e.getDescendantsOfKind(u.CallExpression))Xn(s,t)},Zn=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const r=Ut(e.getArguments()[0]);if(r===void 0)return[];const n=r.getParameters()[1];if(n===void 0)return[];const o=n.getNameNode();if(!i.isIdentifier(o))return[];const a=[];return Jn(r,{exportName:h(e),relativePath:t,requestName:o.getText(),rows:a}),a},Yn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...Zn(r,t));return s},ei=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Yn(n,f(t,r)))}return s},At="identity.ts",$t=new Set(["@lunora/server","lunorash/server"]),ti=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return $t.has(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},si=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const r=s.getFirstAncestorByKind(u.ImportDeclaration);return r!==void 0&&$t.has(r.getModuleSpecifierValue())}return!1},ri=e=>{if(i.isIdentifier(e))return ti(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&si(t)}return!1},ni=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!ri(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw _(n,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},ii=(e,t)=>{const s=g(t,At);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=ni(r);if(n.length!==0){if(n.length>1)throw _(r,`lunora/identity.ts declares ${n.length.toString()} defineIdentity() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},oi=new Set(["auth","context.auth","ctx.auth"]),ai="userId",ci=e=>{const t=new Set;for(const s of e.getProperties()){if(i.isSpreadAssignment(s))return;(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s))&&t.add(s.getName())}return t},ui=(e,t)=>{const s=g(t,At);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const n of r.getDescendantsOfKind(u.CallExpression)){if(b(n.getExpression())!=="defineIdentity")continue;const[o]=n.getArguments();return o&&i.isObjectLiteralExpression(o)?ci(o):void 0}},ct=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return oi.has(e.getExpression().getText())?e:void 0},li=e=>{if(i.isPropertyAccessExpression(e)&&ct(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&ct(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},di=(e,t,s)=>{const r=[];for(const n of e.getDescendants()){const o=li(n);o!==void 0&&r.push({declared:o===ai||s.has(o),exportName:h(n),file:t,key:o,line:n.getStartLineNumber()})}return r},gi=(e,t)=>{const s=ui(e,t);if(s===void 0)return[];const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(...di(o,f(t,n),s))}return r},fi=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},pi=(e,t)=>{if(b(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const r=fi(s);if(!(!r||!P(r)||D(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},mi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=pi(r,t);n&&s.push(n)}return s},xi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...mi(n,f(t,r)))}return s},hi=new Set(["delete","get","getRaw","getWithMetadata","put"]),Ei=(e,t)=>H(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:hi}),yi=new Set(["queue","send"]),ut=new Set(["bcc","cc","to"]),Ai=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!yi.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},$i=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const r=t.getNameNode();return ut.has(t.getName())&&P(r)&&!D(r)}if(!i.isPropertyAssignment(t)||!ut.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&P(s)&&!D(s)}):!1,Si=(e,t)=>{const s=Ai(e.getExpression());if(s===void 0)return;const r=e.getArguments()[0];if(!(!r||!$i(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Ni=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Si(r,t);n&&s.push(n)}return s},vi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ni(n,f(t,r)))}return s},bi=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},Pi=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},wi=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==u.CallExpression)return;const s=t;return $s(s.getExpression())?s:void 0},Ii=e=>{const t=wi(e),s=t===void 0?void 0:Pi(t);if(s===void 0)return[];const r=e.getNameNode(),n=i.isIdentifier(r)?r.getText():"";return s.getDescendantsOfKind(u.CallExpression).filter(o=>bi(o)).map(o=>({exportName:n,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},Li=e=>e.getVariableDeclarations().flatMap(t=>Ii(t)),Oi=(e,t)=>{const s=g(t,As);if(!E(s))return[];const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Li(r)},Fi=new Set(["delete","get","patch"]),Di=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Ti=new Set(["auth","identity","session","user"]),Ci=new Set([u.EqualsEqualsEqualsToken,u.EqualsEqualsToken,u.ExclamationEqualsEqualsToken,u.ExclamationEqualsToken]),ki=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!k(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},Ki=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(i.isAsExpression(s)||i.isParenthesizedExpression(s)||i.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!i.isVariableDeclaration(s))return;const r=s.getNameNode();return i.isIdentifier(r)?r.getText():void 0},Ri=(e,t)=>e.getDescendantsOfKind(u.Identifier).some(s=>s.getText()===t),Mi=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(u.ThrowStatement).length>0||e.getDescendantsOfKind(u.ReturnStatement).length>0,zi=(e,t)=>e.getDescendantsOfKind(u.IfStatement).some(s=>Ri(s.getExpression(),t)&&Mi(s.getThenStatement())),ji=(e,t)=>{for(const s of e.getDescendantsOfKind(u.CallExpression)){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))continue;const n=r.getName();if(!Fi.has(n))continue;const o=r.getExpression();if(!(k(o)||i.isPropertyAccessExpression(o)&&k(o.getExpression())))continue;const a=s.getArguments()[0];if(a!==void 0&&i.isIdentifier(a)&&a.getText()===t)return n}},qi=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t)||i.isParenthesizedExpression(t)||i.isAsExpression(t)||i.isAwaitExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t.getText():void 0},Bi=e=>e.getDescendantsOfKind(u.CallExpression).some(t=>t.getArguments().some(s=>qi(s)==="ctx")),Vi=e=>e.getDescendantsOfKind(u.BinaryExpression).some(t=>Ci.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),Ui=e=>{for(const t of e.getDescendantsOfKind(u.Identifier))if(Di.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&Ti.has(t.getName()))return!0}return Bi(e)||Vi(e)},Wi=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const r=K(s);if(r?.kind!=="query"&&r?.kind!=="mutation")return[];const n=ft(s);if(n===void 0)return[];const o=r.receiver!==void 0&&pt(r.receiver,"use","rls"),a=Ui(n),c=new Set,l=[];for(const m of n.getDescendantsOfKind(u.CallExpression)){const y=ki(m);if(y===void 0)continue;const O=Ki(m);if(O===void 0||c.has(O)||!zi(n,O))continue;const R=ji(n,O);R!==void 0&&(c.add(O),l.push({exportName:e.getName(),file:t,line:m.getStartLineNumber(),mentionsOwnership:a,sinkMethod:R,table:y,usesRls:o,visibility:r.visibility}))}return l},Gi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Wi(c,o))}return s},_i=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Hi=new Set(["insert","insertManyUnsafe","patch","replace"]),Qi=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Hi.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="db")return;const r=s.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"?t:void 0},Xi=(e,t)=>{if(t!=="insertManyUnsafe")return i.isObjectLiteralExpression(e)?[e]:[];if(!i.isArrayLiteralExpression(e))return[];const s=[];for(const r of e.getElements())i.isObjectLiteralExpression(r)&&s.push(r);return s},Ji=(e,t,s,r)=>{const n=[];for(const o of e.getProperties()){let a,c;i.isPropertyAssignment(o)?(a=o.getName(),c=o.getInitializer()):i.isShorthandPropertyAssignment(o)&&(a=o.getName(),c=o.getNameNode()),!(a===void 0||c===void 0||!_i.has(a))&&P(c)&&!D(c)&&n.push({exportName:h(s),field:a,file:r,line:s.getStartLineNumber(),method:t})}return n},Zi=(e,t)=>{const s=Qi(e.getExpression());if(s===void 0)return[];const r=e.getArguments()[1];return r?Xi(r,s).flatMap(n=>Ji(n,s,e,t)):[]},Yi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...Zi(r,t));return s},eo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Yi(n,f(t,r)))}return s},to=e=>{const t=g(e,"package.json");if(!E(t))return new Set;try{const s=JSON.parse(ye(t,"utf8")),r=new Set;for(const n of["dependencies","devDependencies","peerDependencies","optionalDependencies"]){const o=s[n];if(o!==null&&typeof o=="object")for(const a of Object.keys(o))r.add(a)}return r}catch{return new Set}},so=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),ro=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,no=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?ro(t.getInitializer()):void 0},io=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=b(r.getExpression());if(n===void 0||!so.has(n))continue;const[o]=r.getArguments(),a=o&&i.isObjectLiteralExpression(o)?no(o):void 0;s.push({callee:n,exportName:h(r),file:t,line:r.getStartLineNumber(),...a===void 0?{}:{toleranceSeconds:a}})}return s},oo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...io(n,f(t,r)))}return s},ao=new Set(["defineQueue","defineWorkflow"]),co=new Set(["run","runAction","runMutation","runQuery"]),uo=new Set(["api","internal"]),lo=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},go=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!i.isPropertyAssignment(s))return;const r=s.getInitializer();if(r&&(i.isArrowFunction(r)||i.isFunctionExpression(r)))return r},St=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},Nt=(e,t)=>e===t||e.startsWith(`${t}.`),vt=e=>{const t=e.getDescendantsOfKind(u.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},lt=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e||i.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(i.isBindingElement(t)&&t.getNameNode()===e)},bt=e=>{const t=e.getDescendantsOfKind(u.Identifier).filter(s=>lt(s));return i.isIdentifier(e)&<(e)&&t.push(e),t},fo=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(u.BindingElement).map(s=>s.getName())},po=e=>{const t=St(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const r of e.getDescendantsOfKind(u.ForOfStatement)){if(r.getExpression().getText()!==`${t}.messages`)continue;const n=r.getInitializer(),o=i.isVariableDeclarationList(n)?n.getDeclarations()[0]?.getNameNode():void 0;o&&i.isIdentifier(o)&&s.push(`${o.getText()}.body`)}return s},mo=(e,t,s)=>{const r=t==="workflow"?[`${s}.params`]:po(e),n=new Set,o=a=>vt(a).some(c=>r.some(l=>Nt(c.getText(),l)))?!0:bt(a).some(c=>n.has(c.getText()));for(const a of e.getDescendantsOfKind(u.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of fo(a))n.add(l)}return{names:n,prefixes:r}},xo=(e,t)=>vt(e).some(s=>t.prefixes.some(r=>Nt(s.getText(),r)))?!0:bt(e).some(s=>t.names.has(s.getText())),ho=e=>{if(e===void 0||!i.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;i.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const r=t.at(-1);if(!(r===void 0||!i.isIdentifier(s)||!uo.has(s.getText())||t.length<2))return{exportName:r,file:t.slice(0,-1).join("/")}},Eo=(e,t,s)=>{const r=St(e,0);if(r===void 0)return[];const n=mo(e,t,r),o=[];for(const a of e.getDescendantsOfKind(u.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!co.has(c.getName())||c.getExpression().getText()!==r)continue;const l=a.getArguments()[1];if(!l||!xo(l,n))continue;const m=ho(a.getArguments()[0]);m!==void 0&&o.push({dispatchKind:t,file:s,handlerExport:h(a),line:a.getStartLineNumber(),targetExport:m.exportName,targetFile:m.file})}return o},yo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=lo(r);if(n===void 0||!ao.has(n))continue;const o=go(r);o!==void 0&&s.push(...Eo(o,n==="defineQueue"?"queue":"workflow",t))}return s},Ao=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...yo(n,f(t,r)))}return s},dt={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},$o=/account|credential|member|passkey|session|user/iu,Pt=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},So=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},No=e=>{if(i.isCallExpression(e))return e;if(!i.isIdentifier(e))return;const t=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return t&&i.isCallExpression(t)?t:void 0},V={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},vo=e=>{const t=No(e),s=t?Pt(t):void 0;if(t&&s==="protectPublic"){const r=So(t);return{...V,usesCaptcha:r.usesCaptcha,usesRateLimit:r.usesRateLimit}}return s!==void 0&&s in dt?{...V,[dt[s]]:!0}:V},bo=e=>{const t={...V};let s=e;for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))break;const n=r.getName()==="use"?s.getArguments()[0]:void 0;if(n){const o=vo(n);t.usesCaptcha||=o.usesCaptcha,t.usesEmailGate||=o.usesEmailGate,t.usesMask||=o.usesMask,t.usesRateLimit||=o.usesRateLimit,t.usesRls||=o.usesRls}s=r.getExpression()}return t},Po=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insert")return!1;const s=t.getExpression();if(!(i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"))return!1;const r=e.getArguments()[0];return!!(r&&i.isStringLiteral(r)&&$o.test(r.getLiteralText()))},wo=new Set(["create","runAfter","runAt","send","sendBatch"]),Io=new Set(["queues","scheduler","workflows"]),Lo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!wo.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&Io.has(s.getName())){const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="ctx")return!0}s=s.getExpression()}return!1},Oo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},Fo=new Set(["generateObject","generateText","streamObject","streamText"]),Do=e=>{const t=Pt(e);if(t===void 0||!Fo.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(r=>i.isSpreadAssignment(r))?!1:!s.getProperty("maxOutputTokens")},To=e=>e.getDescendantsOfKind(u.PropertyAccessExpression).some(t=>{const s=t.getName();if(s!=="mail"&&s!=="email")return!1;const r=t.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"}),Co=e=>{let t=!1,s=!1,r=!1,n=!1;for(const o of e.getDescendantsOfKind(u.CallExpression))if(Po(o)&&(n=!0),Lo(o)&&(t=!0),Oo(o)&&(r=!0),Do(o)&&(s=!0),n&&t&&r&&s)break;return{callsMail:To(e),fanOut:t,unboundedAiGeneration:s,usesInsertManyUnsafe:r,writesUserTable:n}},ko=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=K(s);if(!r||r.kind!=="query"&&r.kind!=="mutation"&&r.kind!=="action")return;const n=r.receiver?bo(r.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},{callsMail:o,fanOut:a,unboundedAiGeneration:c,usesInsertManyUnsafe:l,writesUserTable:m}=Co(e);return{callsMail:o,exportName:e.getName(),fanOut:a,file:t,kind:r.kind,unboundedAiGeneration:c,usesCaptcha:n.usesCaptcha,usesEmailGate:n.usesEmailGate,usesInsertManyUnsafe:l,usesMask:n.usesMask,usesRateLimit:n.usesRateLimit,usesRls:n.usesRls,visibility:r.visibility,writesUserTable:m}},Ko=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=ko(n,t);o&&s.push(o)}return s},Ro=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ko(n,f(t,r)))}return s},Mo=new Set(["dbRateLimit","rateLimit"]),zo=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},jo=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},qo=e=>i.isArrowFunction(e)?e.getBody():e,Bo=(e,t)=>{const s=b(e.getExpression());if(s===void 0||!Mo.has(s))return;const r=e.getArguments()[2];if(!r)return;const n=zo(r);if(!n)return;const o=qo(n);if(!(!P(o)||D(o)))return{callee:s,exportName:h(e),file:t,limitName:jo(e),line:e.getStartLineNumber()}},Vo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Bo(r,t);n&&s.push(n)}return s},Uo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Vo(n,f(t,r)))}return s},Wo=new Set(["findFirst","findFirstOrThrow","findMany","get"]),Go=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Wo.has(t.getName()))return;const s=t.getExpression();if(k(s)){const r=e.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&k(s.getExpression()))return s.getName()},_o=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&k(s.getExpression())){const r=t.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}t=s.getExpression()}},Ho=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},wt=(e,t=!1)=>{const s=Ho(e);if(i.isIdentifier(s)){if(t)return;const r=L(s);return r===void 0?void 0:wt(r,!0)}if(i.isCallExpression(s))return Go(s)??_o(s)},Qo=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const r of e.getDescendantsOfKind(u.ReturnStatement)){const n=r.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),o=r.getExpression();n===e&&o!==void 0&&s.push(o)}return s},Xo=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const r=K(s);if(r?.kind!=="query")return[];const n=ft(s);if(n===void 0)return[];const o=r.receiver!==void 0&&Wt(r.receiver,"output"),a=r.receiver!==void 0&&pt(r.receiver,"use","mask"),c=new Set,l=[];for(const m of Qo(n)){const y=wt(m);y===void 0||c.has(y)||(c.add(y),l.push({exportName:e.getName(),file:t,line:m.getStartLineNumber(),table:y,usesMask:a,usesOutput:o,visibility:r.visibility}))}return l},Jo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Xo(c,o))}return s},Zo=new Set(["findFirst","findFirstOrThrow","findMany"]),Yo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Zo.has(t.getName()))return;const s=t.getExpression();if(i.isPropertyAccessExpression(s)&&s.getName()==="db"||i.isIdentifier(s)&&s.getText()==="db"){const r=e.getArguments()[0];return{options:e.getArguments()[1],table:r&&i.isStringLiteral(r)?r.getLiteralText():""}}if(i.isPropertyAccessExpression(s)){const r=s.getExpression();if(i.isPropertyAccessExpression(r)&&r.getName()==="db"||i.isIdentifier(r)&&r.getText()==="db")return{options:e.getArguments()[0],table:s.getName()}}},ea=e=>{if(!e||!i.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s)||i.isGetAccessorDeclaration(s))&&t.push(s.getName());return t},ta=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},sa=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&i.isCallExpression(s)?K(s):void 0;if(!r)return[];const n=[];for(const o of e.getDescendantsOfKind(u.CallExpression)){const a=Yo(o);if(a===void 0)continue;const c=ea(ta(a.options,"with"));c.length!==0&&n.push({exportName:e.getName(),file:t,line:o.getStartLineNumber(),parentTable:a.table,relations:c,visibility:r.visibility})}return n},ra=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...sa(c,o))}return s},G=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===u.PlusToken){const t=G(e.getLeft()),s=G(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},na=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===u.PlusToken;)t=s,s=t.getParent();return t!==e&&G(t)!==void 0},ia=(e,t)=>{const s=[],r=[...e.getDescendantsOfKind(u.BinaryExpression),...e.getDescendantsOfKind(u.StringLiteral),...e.getDescendantsOfKind(u.NoSubstitutionTemplateLiteral)],n=new Set;for(const o of r){if(na(o))continue;const a=G(o);if(a===void 0)continue;const c=Ts(a);if(c===void 0)continue;const l=o.getStartLineNumber(),m=`${String(l)}:${c}`;n.has(m)||(n.add(m),s.push({file:t,kind:c,line:l,preview:Cs(a)}))}return s},oa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ia(n,f(t,r)))}return s},aa=new Set(["findFirst","findFirstOrThrow","findMany"]),ca=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!aa.has(t.getName()))return;const s=t.getExpression();if(i.isPropertyAccessExpression(s)&&s.getName()==="db"||i.isIdentifier(s)&&s.getText()==="db"){const r=e.getArguments()[0];return{options:e.getArguments()[1],table:r&&i.isStringLiteral(r)?r.getLiteralText():""}}if(i.isPropertyAccessExpression(s)){const r=s.getExpression();if(i.isPropertyAccessExpression(r)&&r.getName()==="db"||i.isIdentifier(r)&&r.getText()==="db")return{options:e.getArguments()[0],table:s.getName()}}},ua=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},la=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&i.isCallExpression(s)?K(s):void 0;if(!r)return[];const n=[];for(const o of e.getDescendantsOfKind(u.CallExpression)){const a=ca(o);if(a===void 0)continue;const c=ua(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),m=!l&&P(c);!l&&!m||n.push({exportName:e.getName(),file:t,fromArgs:m,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:r.visibility})}return n},da=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...la(c,o))}return s},ga=new Set(["query","unsafe"]),fa=e=>{if(!i.isPropertyAccessExpression(e)||!ga.has(e.getName()))return!1;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return i.isIdentifier(s)&&s.getText()==="ctx"},pa=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),ma=e=>e.getFirstAncestorByKind(u.VariableDeclaration)?.getName()??"<module>",xa=(e,t)=>{if(!fa(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!pa(s)))return{exportName:ma(e),file:t,line:s.getStartLineNumber()}},ha=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=xa(r,t);n&&s.push(n)}return s},Ea=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ha(n,f(t,r)))}return s},ya=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Aa=(e,t)=>H(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.storage"||s.startsWith("ctx.storage."),methods:ya}),$a=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Sa=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Na=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!i.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,r=!1;for(const n of e.getProperties()){if(i.isSpreadAssignment(n)){r=!0;continue}if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o),o==="expiresInSeconds"&&(s=Sa(n.getInitializer()));continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,expiresInSeconds:s,presentKeys:t}},va=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=$a.get(t);if(s===void 0)return;const r=e.getExpression().getText();return r==="ctx.storage"||r.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},ba=(e,t)=>{const s=va(e.getExpression());if(s!==void 0)return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s.method,...Na(e.getArguments()[s.optionsIndex])}},Pa=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ba(r,t);n&&s.push(n)}return s},wa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Pa(n,f(t,r)))}return s},Ia=new Set(["when","where"]),xe=new Set(["definePolicy","defineShape"]),La=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const r=t.getName();return xe.has(r)?r:void 0}if(!i.isIdentifier(t))return;for(const r of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(r)){const n=r.getNameNode().getText();return xe.has(n)?n:void 0}const s=t.getText();return xe.has(s)?s:void 0},Oa=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,It=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===u.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Oa(e))return"empty-object";if(i.isParenthesizedExpression(e))return It(e.getExpression())}},Lt=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Ot=e=>e.getDescendantsOfKind(u.ReturnStatement).filter(t=>Lt(t)===e),Ft=e=>e.getDescendantsOfKind(u.ConditionalExpression).filter(t=>Lt(t)===e),Fa=e=>{const t=Ot(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(u.IfStatement)!==void 0)||Ft(e).length>0},Da=e=>{const t=[],s=e.getBody();i.isBlock(s)||t.push(s);for(const r of Ot(e)){const n=i.isReturnStatement(r)?r.getExpression():void 0;t.push(n??r)}for(const r of Ft(e))t.push(r.getWhenTrue(),r.getWhenFalse());return t},Ta=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},Ca=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[r]=e.getArguments();if(!r||!i.isObjectLiteralExpression(r))return[];const n=[];for(const o of r.getProperties()){if(!i.isPropertyAssignment(o)||!Ia.has(o.getName()))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Fa(a))for(const c of Da(a)){const l=It(c);l!==void 0&&n.push({exportName:Ta(e),file:s,form:l,key:o.getName(),line:c.getStartLineNumber(),owner:t})}}return n},ka=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=La(r);n!==void 0&&s.push(...Ca(r,n,t))}return s},Ka=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ka(n,f(t,r)))}return s},Ra=new Set(["query","upsert","upsertMany"]),Ma=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(Ra.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},za=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("namespace");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},ja=(e,t)=>{const s=Ma(e.getExpression());if(s===void 0)return;const r=e.getArguments()[1];if(!r)return;const n=za(r);if(!(!n||!P(n)||D(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},qa=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ja(r,t);n&&s.push(n)}return s},Ba=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...qa(n,f(t,r)))}return s},Va=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="workflows":i.isIdentifier(s)&&s.getText()==="workflows"},Ua=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Wa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){if(!Va(a))continue;const c=Rs(a);c!==""&&s.push({exportName:c,file:o,line:a.getStartLineNumber(),workflow:Ua(a)})}}return s},Ga=".lunora-schema.json",$=(e,t)=>{E(e)&&ye(e,"utf8")===t||qt(e,t,"utf8")},v=(e,t)=>{if(t===""){Bt(e,{force:!0});return}$(e,t)},_a=e=>{const t=g(e,"package.json");if(E(t))try{const s=JSON.parse(ye(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},Ha=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Qa=e=>{let t=E(e)?e:de(e);for(;t&&t!==de(t);){const s=g(t,"tsconfig.json");if(E(s))return s;t=de(t)}},gt=e=>e.replaceAll("\\","/"),Xa=(e,t)=>{const s=new Map,r=new Map,n=new Map;for(const o of e)s.set(o.name,`workflow "${o.exportName}"`),r.set(o.bindingName,`workflow "${o.exportName}"`),n.set(o.className,`workflow "${o.exportName}"`);for(const o of t){const a=s.get(o.name);if(a!==void 0)throw new q("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${o.name}": produced by both ${a} and agent "${o.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=r.get(o.bindingName);if(c!==void 0)throw new q("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${o.bindingName}": produced by both ${c} and agent "${o.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const l=n.get(o.className);if(l!==void 0)throw new q("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${o.className}": produced by both ${l} and agent "${o.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},Ja=e=>{const t=Qa(e);return t?new Xe({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Xe({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Cc=(e,t)=>{const s=d(t),r=g(t,"schema.ts");E(r)&&s.push(r);for(const c of s){const l=e.getSourceFile(c);l===void 0?e.addSourceFileAtPath(c):l.refreshFromFileSystemSync()}const n=new Set(s.map(c=>gt(c))),o=gt(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!n.has(l)&&e.removeSourceFile(c)}},kc=e=>{const t=Ha(),s=t?ge.now():0,r=g(e.projectRoot,e.lunoraDirectory??"lunora"),n=g(r,"schema.ts");if(!E(n))throw new q("INTERNAL",`schema.ts not found at ${n}`);const o=e.project??Ja(r),a=Ds(o,n,e.projectRoot),c=Gt(o,r),l=ps(o,r),m=ys(o,r),y=ks(o,r),O=Ss(o,r),R=ii(o,r),Se=fn(o,r),S=Ms(o,r),T=ws(o,r),N=_t(o,r);Xa(S,N);const Q=Xt(o,r,S,N),C=Qt(o,r),Ne=e.lint===!1?[]:Vt({adminRoutes:Ys(o,r),aiRawRuns:ir(o,r),aiToolSideEffects:mr(o,r),argumentDerivedFetches:yr(o,r),argumentValidators:Or(o,r),authApiCalls:Ht(o,r),authConfigs:Mr(o,r),browserUrlAccesses:Vr(o,r),configCalls:Jr(o,r),containerKeyAccesses:Yr(o,r),containerOverrides:an(o,r),containers:C,exportSinks:hn(o,r),failOpenGuards:vn(o,r),flagSecurityDefaults:Tn(o,r),geoIndexUsages:Kn(o,r),httpActionGuards:Un(o,r),httpHeaderWrites:ei(o,r),identityClaimReads:gi(o,r),imageDeliveryUrlAccesses:xi(o,r),inserts:ms(o,r),kvKeyAccesses:Ei(o,r),mailRecipientAccesses:vi(o,r),maskProcedures:xs(o,r),maskStrategies:hs(o,r),mutatorWrites:Oi(o,r),nondeterministicCalls:Ns(o,r),normalizeIdAuthorizations:Gi(o,r),notifyCalls:bs(o,r),notifyConfig:vs(o,r),ownerFieldWrites:eo(o,r),unrestrictedWhereBranches:Ka(o,r),paymentWebhooks:oo(o,r),privilegedDispatches:Ao(o,r),procedureProtections:Ro(o,r),queries:Ps(o,r),queues:T,r2sqlCalls:Is(o,r),ratelimitKeySelectors:Uo(o,r),rawRowReturns:Jo(o,r),relationLoads:ra(o,r),rlsProcedures:Ls(o,r),schema:a,secretLiterals:oa(o,r),shapes:y,softDeleteReads:da(o,r),sqlInterpolations:Ea(o,r),storageKeyAccesses:Aa(o,r),storageUploads:wa(o,r),vectorNamespaceAccesses:Ba(o,r),workflowCalls:Wa(o,r),workflows:S,wranglerVariables:e.wranglerVariables}),Dt=Os(o,r),Tt=Es(o,r),X=Ks(o,r),A=Pn(o,r),J=A.ai,Z=A.payments,ve=A.kv,be=A.access,Y=E(g(r,"flags.ts")),Ct=Y?fs(o,r):[],ee=E(g(r,"notify.ts")),te=A.hyperdrive,se=Fs(o,r),kt=se.usesSandboxBrowser||se.usesSandboxContainer,re=A.browser||se.usesSandboxBrowser,ne=A.images,ie=A.analytics,Pe=A.pipelines,oe=A.r2sql,ae=A.x402,w=to(e.projectRoot),M=wn(A,{containerCount:C.length,cronCount:Q.length,dependencies:w,hasPaymentTables:a.tables.some(p=>p.name==="subscriptions")&&a.tables.some(p=>p.name==="events"),queueCount:T.length,storageColumnCount:Object.keys(Jt(a)).length,storageRuleCount:X.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:S.length}),F=w.has("lunorash"),we=t?ge.now():0,Ie=Zt(a,F),Le=Yt({agents:N,functions:c,httpRoutes:l,useUmbrella:F,workflows:S}),Oe=es({agents:N,containers:C,env:Se,hasAccessFacade:be,hasAi:J,hasAnalytics:ie,hasBrowser:re,hasFlags:Y,hasHyperdrive:te,hasImages:ne,hasKv:ve,hasNotify:ee,hasPayments:Z,hasPipelines:Pe,hasR2sql:oe,hasX402:ae,identity:R,queues:T,schema:a,storageRuleBuckets:X.rules.map(p=>p.bucket),useUmbrella:F,workflows:S}),Fe=ts({agents:N,functions:c,migrations:m,mutators:O,shapes:y,useUmbrella:F,usesSandbox:kt}),De=ss({advisories:Ne,agents:N,containers:C,env:Se,flagKeys:Ct,hasAccessFacade:be,hasAi:J,hasAnalytics:ie,hasBrowser:re,hasFlags:Y,hasHyperdrive:te,hasImages:ne,hasKv:ve,hasNotify:ee,hasPayments:Z,hasPipelines:Pe,hasR2sql:oe,hasX402:ae,maskMetadata:Tt,mutators:O,queues:T,rlsMetadata:Dt,schema:a,shapes:y,storageRules:X,studioFeatures:M,useUmbrella:F,workflows:S}),Te=rs(y,w.has("@lunora/db"),F),Ce=ns(C,a.jurisdiction),ke=is(S),Ke=os(N),Re=as(T),Me=cs(Q),ze=us(a.vectorIndexes),z=ls(a,F),je=ds(w.has("@lunora/seed")),j=e.apiSpec??"openapi",ce=j==="openapi"||j==="both",ue=j==="openrpc"||j==="both",qe=zs({emailAgents:N.filter(p=>p.onEmail===!0).map(p=>({bindingName:p.bindingName,exportName:p.exportName})),hasAccess:w.has("@lunora/cloudflare-access"),hasAi:J,hasAnalytics:ie,hasAuth:w.has("@lunora/auth"),hasBrowser:re,hasFramework:w.has("@lunora/astro")||w.has("@lunora/svelte")||w.has("@lunora/vue"),hasGlobal:a.tables.some(p=>p.shardMode==="global"&&p.globalBackend!=="hyperdrive"),hasHyperdrive:te,hasHyperdriveGlobal:a.tables.some(p=>p.shardMode==="global"&&p.globalBackend==="hyperdrive"),hasImages:ne,hasKv:M.kv,hasNotify:ee,hasPayments:Z,hasR2sql:oe,hasQueue:T.some(p=>p.mode==="push"),hasScheduler:M.scheduler,hasStorage:M.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:S.length>0,hasX402:ae,identity:R,jurisdiction:a.jurisdiction,useUmbrella:F,voiceAgents:N.filter(p=>p.voice===!0&&p.voiceBindingName!==void 0).map(p=>({bindingName:p.voiceBindingName,exportName:p.exportName})),wantsOpenApi:ce,wantsOpenRpc:ue}),Be=_a(e.projectRoot),Ve=js({functions:c,httpRoutes:l,version:Be}),Ue=Bs({functions:c,version:Be}),We=`${JSON.stringify(Ve,void 0,2)}
|
|
2
2
|
`,Ge=`${JSON.stringify(Ue,void 0,2)}
|
|
3
3
|
`,_e=qs(Ve),He=Vs(Ue),Qe=Us(a,m.map(p=>p.id)),le=g(r,Ga),Kt=E(le),x=g(r,"_generated");if(e.dryRun||(E(x)||jt(x,{recursive:!0}),$(g(x,"app.ts"),qe),$(g(x,"dataModel.ts"),Ie),$(g(x,"api.ts"),Le),$(g(x,"server.ts"),Oe),$(g(x,"functions.ts"),Fe),$(g(x,"shard.ts"),De),$(g(x,"crons.ts"),Me),$(g(x,"vectors.ts"),ze),$(g(x,"drizzle.global.ts"),z.global),$(g(x,"drizzle.shard.ts"),z.shard),v(g(x,"containers.ts"),Ce),v(g(x,"workflows.ts"),ke),v(g(x,"agents.ts"),Ke),v(g(x,"queues.ts"),Re),v(g(x,"seed.ts"),je),v(g(x,"collections.ts"),Te),v(g(x,"openapi.json"),ce?We:""),v(g(x,"openapi.ts"),ce?_e:""),v(g(x,"openrpc.json"),ue?Ge:""),v(g(x,"openrpc.ts"),ue?He:""),(!Kt||e.updateSchemaBaseline===!0)&&$(le,Ws(Qe))),t){const p=ge.now(),Rt=Math.round(p-s),Mt=Math.round(we-s),zt=Math.round(p-we);console.error(`@lunora/codegen: codegen took ${Rt.toString()}ms (discovery ${Mt.toString()}ms, emit ${zt.toString()}ms)`)}return{advisories:Ne,agents:N,containers:C,cronTriggers:gs(Q),generated:{agents:Ke,api:Le,app:qe,collections:Te,containers:Ce,crons:Me,dataModel:Ie,drizzleGlobal:z.global,drizzleShard:z.shard,functions:Fe,openApi:We,openApiModule:_e,openRpc:Ge,openRpcModule:He,queues:Re,seed:je,server:Oe,shard:De,vectors:ze,workflows:ke},outputDirectory:x,queues:T,schemaSnapshot:Qe,schemaSnapshotPath:le,workflows:S}};export{Ga as SCHEMA_SNAPSHOT_FILENAME,Ja as createCodegenProject,Cc as refreshCodegenProject,kc as runCodegen};
|
package/dist/packem_shared/{buildOpenApiDocument-DXX1G3GZ.mjs → buildOpenApiDocument-BRCc5AIx.mjs}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{w as $}from"./emit-
|
|
1
|
+
import{w as $}from"./emit-BYVxPDqO.mjs";import{n as p}from"./paths-BmX5O1sG.mjs";import{LUNORA_ERROR_CODES as y,objectSchema as g,argsObjectSchema as h,validatorIrToJsonSchema as u}from"./LUNORA_ERROR_CODES-Um9hC1gr.mjs";const S="/_lunora/rest",O=e=>{const t=e.indexOf(":");if(!(t<=0||t>=e.length-1||e.indexOf(":",t+1)!==-1))return{name:e.slice(t+1),namespace:e.slice(0,t)}},b=e=>{const t=O(e);if(t!==void 0)return`${S}/${t.namespace}/${t.name}`},P=e=>e==="query"?"GET":"POST",l="#/components/responses/LunoraError",f=/:([A-Za-z_$][\w$]*)/gu,T=e=>[...e.matchAll(f)].map(t=>t[1]),k=e=>e.replaceAll(f,"{$1}"),v=e=>{const t=new Set(T(e.path)),n=[];for(const[o,s]of Object.entries(e.searchParams)){const c=s.kind==="optional"?s.inner??s:s;n.push({description:`Query parameter \`${o}\``,in:"query",name:o,required:s.kind!=="optional",schema:u(c)})}for(const[o,s]of Object.entries(e.params)){const c=s.kind==="optional"?s.inner??s:s;n.push({description:`Path parameter \`${o}\``,in:t.has(o)?"path":"query",name:o,required:t.has(o)?!0:s.kind!=="optional",schema:u(c)})}return n},j=e=>e?{content:{"application/json":{schema:u(e)}},description:"Successful response."}:{content:{"application/json":{schema:{description:"Return shape is TS-inferred (no `.output()` declared); best-effort — any JSON."}}},description:"Successful response. The return shape is TypeScript-inferred and not declared via `.output()`, so it is documented best-effort."},N=e=>{const t=p(e.filePath),n=v(e),o={description:`${e.stream?"Streaming (SSE) ":""}HTTP route handler \`${e.exportName}\` (${e.method} ${e.path}).`,operationId:`${e.method.toLowerCase()}_${p(e.path)}`,responses:{200:j(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:l}},summary:`${e.method} ${e.path}`,tags:[t]};return n.length>0&&(o.parameters=n),Object.keys(e.body).length>0&&(o.requestBody={content:{"application/json":{schema:g(e.body)}},required:!0}),e.stream&&(o["x-lunora-stream"]="text/event-stream"),o},q=e=>{const t=`${p(e.filePath)}:${e.exportName}`,n=p(e.filePath),o={additionalProperties:!1,properties:{args:h(e.args),functionPath:{const:t,type:"string"},shardKey:{description:"Optional shard key; omitted routes to the default shard.",type:"string"}},required:["functionPath"],type:"object"};return{operation:{description:`Invoke the \`${e.kind}\` \`${t}\` over the Lunora RPC envelope (POST /_lunora/rpc).`,operationId:t,requestBody:{content:{"application/json":{schema:o}},required:!0},responses:{200:{content:{"application/json":{schema:{description:"RPC result. The shape is TS-inferred from the function's return type; best-effort — any JSON."}}},description:"Successful RPC result (TypeScript-inferred return shape, documented best-effort)."},default:{$ref:l}},summary:`${e.kind}: ${t}`,tags:[n],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${t}`}},R=e=>{const t=`${p(e.filePath)}:${e.exportName}`,n=b(t);if(n===void 0)return;const o=p(e.filePath),s=P(e.kind),c=s==="GET",r={description:`Public REST endpoint for the \`${e.kind}\` \`${t}\` (opt-in via \`.expose({ rest: true })\`). Routed through the procedure, so auth / RLS / validators are enforced.`,operationId:`rest_${p(n)}`,responses:{200:{content:{"application/json":{schema:{description:"Procedure result. The shape is TS-inferred from the return type; best-effort — any JSON."}}},description:"Successful result (TypeScript-inferred return shape, documented best-effort)."},default:{$ref:l}},summary:`${s} ${n}`,tags:[o],"x-lunora-function-kind":e.kind};if(c){const a=Object.entries(e.args).map(([i,d])=>{const m=d.kind==="optional"?d.inner??d:d;return{description:`Argument \`${i}\` (JSON-encoded for non-string values).`,in:"query",name:i,required:d.kind!=="optional",schema:u(m)}});return a.length>0&&(r.parameters=a),{method:"get",operation:r,path:n}}return r.requestBody={content:{"application/json":{schema:h(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:r,path:n}},A=e=>{const t=e.version??"0.0.0",n={},o=new Set;for(const r of e.httpRoutes){const a=k(r.path),i=n[a]??{};i[r.method.toLowerCase()]=N(r),n[a]=i,o.add(p(r.filePath))}const s=e.functions.filter(r=>r.visibility!=="internal"&&r.kind!=="stream");for(const r of s){const{operation:a,pathKey:i}=q(r);n[i]={post:a},o.add(p(r.filePath))}for(const r of s){if(r.expose?.rest!==!0)continue;const a=R(r);if(a===void 0)continue;const i=n[a.path]??{};i[a.method]=a.operation,n[a.path]=i,o.add(p(r.filePath))}const c=[...o].toSorted((r,a)=>r.localeCompare(a)).map(r=>({description:`Operations declared in \`lunora/${r}\`.`,name:r}));return{components:{responses:{LunoraError:{content:{"application/json":{schema:{additionalProperties:!1,description:"Standard Lunora error envelope.",properties:{error:{additionalProperties:!1,properties:{code:{description:"Machine-readable error code. Clients switch on this value.",enum:y,type:"string"},message:{description:"Human-readable error message (never echoes internal details).",type:"string"}},required:["code","message"],type:"object"}},required:["error"],type:"object"}}},description:"A Lunora error response. The HTTP status reflects the error code (e.g. BAD_REQUEST→400, UNAUTHORIZED→401, FORBIDDEN→403, NOT_FOUND→404)."}}},info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora API",version:t},openapi:"3.1.0",paths:n,tags:c}},_=e=>`${JSON.stringify(A(e),void 0,2)}
|
|
2
2
|
`,I=e=>`${$}export const openApiSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
|
|
3
3
|
`;export{A as buildOpenApiDocument,_ as emitOpenApi,I as emitOpenApiModule};
|
|
@@ -1983,21 +1983,39 @@ ${Nt}${te}${Ft}${we}${ke}${ye}${Se}
|
|
|
1983
1983
|
// \`storageStub\` fallback satisfies SystemReaderStorageLike structurally
|
|
1984
1984
|
// (its \`list\`/\`getMetadata\` throw the "no storage configured" error).
|
|
1985
1985
|
const storage = asBucketStorage(config.storage?.(env) ?? storageStub) as unknown as SystemReaderStorageLike;
|
|
1986
|
-
${Ct} const db: DatabaseWriterLike = createShardCtxDb(${Ot});
|
|
1987
|
-
${Et}${Ne}
|
|
1988
1986
|
// \`ctx.log\`: the DO base builds the attributed logger (structured
|
|
1989
1987
|
// fields + \`.with(...)\` child + trace correlation) and routes each call
|
|
1990
1988
|
// to the optional \`observability\` sink. It also buffers the line (studio
|
|
1991
1989
|
// Logs panel) and emits a structured console event the dev-server formats.
|
|
1990
|
+
//
|
|
1991
|
+
// Resolved BEFORE \`ctx.db\` below, because the database is wrapped in
|
|
1992
|
+
// auto-instrumentation that needs the sink, the trace anchor, and the
|
|
1993
|
+
// dispatch's wide-event handle.
|
|
1992
1994
|
const observability = config.observability?.(env);
|
|
1993
1995
|
const logFunctionPath = options.functionPath ?? "";
|
|
1994
1996
|
const log = this.makeLogger(logFunctionPath, observability);
|
|
1997
|
+
const traceAnchor = this.resolveDispatchAnchor(Boolean(options.identity));
|
|
1998
|
+
|
|
1999
|
+
// \`ctx.span\`: the handle onto the DISPATCH's own span — the wide-event
|
|
2000
|
+
// surface. Attributes attached here accumulate for the whole request
|
|
2001
|
+
// and are folded into the one span it already emits, instead of
|
|
2002
|
+
// becoming N separate log lines. Shares \`traceAnchor\` with \`ctx.trace\`
|
|
2003
|
+
// so both write to the same trace.
|
|
2004
|
+
const span = this.makeDispatchSpan(traceAnchor, observability);
|
|
2005
|
+
|
|
2006
|
+
${Ct} // \`ctx.db\`, wrapped in automatic instrumentation: by default this
|
|
2007
|
+
// adds aggregate counters (call count, total time, per-operation
|
|
2008
|
+
// breakdown) to the wide event rather than a span per call, so a
|
|
2009
|
+
// handler making hundreds of queries stays readable. See
|
|
2010
|
+
// \`instrumentDatabase\` for the \`"spans"\` / \`"off"\` levels.
|
|
2011
|
+
const db: DatabaseWriterLike = this.instrumentDb(createShardCtxDb(${Ot}), logFunctionPath, traceAnchor, observability);
|
|
2012
|
+
${Et}${Ne}
|
|
1995
2013
|
|
|
1996
2014
|
// \`ctx.trace\` / \`ctx.metrics\`: spans and measurements to the same sink.
|
|
1997
2015
|
// The trace anchor is threaded explicitly for the same reason \`identity\`
|
|
1998
2016
|
// is — a deferred caller (a subscription re-run) must not inherit the
|
|
1999
2017
|
// writing mutation's trace from the shared per-request field.
|
|
2000
|
-
const trace = this.makeTracer(logFunctionPath, observability,
|
|
2018
|
+
const trace = this.makeTracer(logFunctionPath, observability, traceAnchor);
|
|
2001
2019
|
const metrics = this.makeMetrics(logFunctionPath, observability);
|
|
2002
2020
|
${qt}
|
|
2003
2021
|
// \`ctx.now\`: the wall-clock instant (epoch ms) this function began,
|
|
@@ -2014,12 +2032,17 @@ ${qt}
|
|
|
2014
2032
|
userId: userId ?? null,
|
|
2015
2033
|
},
|
|
2016
2034
|
db,
|
|
2017
|
-
fetch
|
|
2035
|
+
// Instrumented \`fetch\`: a CLIENT span per outbound call plus W3C
|
|
2036
|
+
// \`traceparent\` propagation, so time spent in a downstream service
|
|
2037
|
+
// is visible and its spans join this trace. Degrades to the bare
|
|
2038
|
+
// global when no sink is configured.
|
|
2039
|
+
fetch: this.makeFetch(logFunctionPath, traceAnchor, observability),
|
|
2018
2040
|
ip: this.getCurrentIp(),
|
|
2019
2041
|
log,
|
|
2020
2042
|
metrics,
|
|
2021
2043
|
now,${At}
|
|
2022
2044
|
scheduler,
|
|
2045
|
+
span,
|
|
2023
2046
|
storage,
|
|
2024
2047
|
trace,${Tt}${C}${Mt}${de}${xe}${ve}${ge}${se}
|
|
2025
2048
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as w,w as E}from"./emit-
|
|
1
|
+
import{c as w,w as E}from"./emit-BYVxPDqO.mjs";const D=e=>`has${e.charAt(0).toUpperCase()}${e.slice(1)}`,m=w.map(({appMethod:e,key:t})=>[D(t),e.method,e.configKey,e.doc]),g=e=>m.some(([t])=>e[t]),A=e=>e?['import * as lunoraIdentityContract from "../identity.js";']:[],x=(e,t)=>e?['import type { CreateAccessResolverOptions } from "@lunora/cloudflare-access";',`import { createAccessResolver${t?", composeResolvers":""} } from "@lunora/cloudflare-access";`]:[],R=e=>e?['import { createKvIntrospectorFromEnv } from "@lunora/bindings/kv";']:[],O=e=>e?['import notifyConfig from "../notify.js";']:[],k=e=>(e.emailAgents?.length??0)>0,C=e=>k(e)?['import { dispatchAgentEmail } from "@lunora/agent/inbound";']:[],L=e=>k(e)?['import * as lunoraAgentDefinitions from "../agents.js";']:[],T=e=>{const{hasAccess:t,hasAuth:r,hasFramework:a,hasGlobal:n,hasHyperdriveGlobal:o,hasKv:l,hasQueue:s,hasScheduler:u,hasStorage:d,hasWorkflow:h,useUmbrella:c,wantsOpenApi:p,wantsOpenRpc:v}=e,i=c?"lunorash/runtime":"@lunora/runtime",b=["ExecutionContextLike","LunoraWorker","Route","ScheduledControllerLike","ShardNamespaceLike","WorkerOptions"];n&&b.push("GlobalIntrospector"),a&&b.push("FrameworkHostHandler");const f=[...n||o?["createCrossShardRelationCapabilities"]:[],"createWorker","resolveLogArchiveFromEnv",...a?["withFrameworkWorker"]:[]].join(", ");return[...r?['import type { LunoraAuth, LunoraAuthOptions } from "@lunora/auth";','import { createAuth, createAuthAdmin, createAuthAuditReader, d1Executor, ensureMigrated, handleAuthRequest, lunoraD1Adapter } from "@lunora/auth";']:[],...x(t,r),...n?['import type { D1CtxDbOptions, D1DatabaseLike, D1Exec } from "@lunora/d1";','import { createD1CtxDb, facetGlobalColumn, listGlobalTables, readGlobalTablePage } from "@lunora/d1";']:[],...o?['import type { HyperdriveEngine } from "@lunora/hyperdrive/global";','import { createHyperdriveGlobalCtxDb } from "@lunora/hyperdrive/global";','import type { SqlCtxDbOptions, SqlExec } from "@lunora/sql-store";']:[],...R(l),...u?['import type { DurableObjectNamespaceLike } from "@lunora/scheduler";','import { createScheduler } from "@lunora/scheduler";']:[],...d?['import type { R2BucketLike, Storage } from "@lunora/storage";','import { createBucketStorage, createStorage } from "@lunora/storage";']:[],...h?['import { createWorkflowsRestClient } from "@lunora/workflow";']:[],...C(e),`import type { ${[...b].toSorted((S,y)=>S.localeCompare(y)).join(", ")} } from "${i}";`,`import { ${f} } from "${i}";`,"",...A(e.identity),...L(e),...n||o?['import schema from "../schema.js";']:[],...O(e.hasNotify),'import { LUNORA_CRONS } from "./crons.js";','import { LUNORA_FUNCTIONS } from "./functions.js";',...s?['import { createQueueCaptureSink, dispatchQueueBatch, shouldCaptureQueue } from "@lunora/queue";','import { LUNORA_QUEUE_REGISTRY } from "./queues.js";']:[],...p?['import { openApiSpec } from "./openapi.js";']:[],...v?['import { openRpcSpec } from "./openrpc.js";']:[],'import { createShardDO } from "./shard.js";']},$=e=>[...e.hasStorage?[`/** \`.storage(...)\` declaration — one bucket (required) plus optional extra named buckets and signed-URL config. Backs \`ctx.storage\` AND the studio file browser. */
|
|
2
2
|
interface StorageDeclaration<Env> {
|
|
3
3
|
/** The default R2 bucket binding (the bare \`ctx.storage\`). */
|
|
4
4
|
bucket: Selector<Env, R2BucketLike>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/codegen",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.57",
|
|
4
4
|
"description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@lunora/advisor": "1.0.0-alpha.
|
|
50
|
-
"@lunora/agent": "1.0.0-alpha.
|
|
49
|
+
"@lunora/advisor": "1.0.0-alpha.36",
|
|
50
|
+
"@lunora/agent": "1.0.0-alpha.12",
|
|
51
51
|
"@lunora/container": "1.0.0-alpha.16",
|
|
52
52
|
"@lunora/errors": "1.0.0-alpha.8",
|
|
53
53
|
"@lunora/queue": "1.0.0-alpha.10",
|