@lunora/codegen 1.0.0-alpha.80 → 1.0.0-alpha.81
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-CR3xA8yO.mjs +1 -0
- package/dist/packem_shared/{OPENRPC_VERSION-Dco0Fvm4.mjs → OPENRPC_VERSION-DfKtsdPS.mjs} +1 -1
- package/dist/packem_shared/{SCHEMA_SNAPSHOT_FILENAME-fCPRec_w.mjs → SCHEMA_SNAPSHOT_FILENAME-DjpfF4p7.mjs} +3 -3
- package/dist/packem_shared/{buildOpenApiDocument-CfLCgKoc.mjs → buildOpenApiDocument-D46nZ7D_.mjs} +1 -1
- package/dist/packem_shared/{emit-B6-LPmOS.mjs → emit-CCw5fiXq.mjs} +64 -58
- package/dist/packem_shared/{emitApp-DGiGQ1P4.mjs → emitApp-DEHN578T.mjs} +5 -5
- package/package.json +9 -9
- package/dist/packem_shared/GENERATED_HEADER-BSvZOCvj.mjs +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as p}from"./packem_shared/formatAdvisories-BCEfzLT0.mjs";import{CodegenDiagnosticError as c,diagnosticAt as n}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as l,discoverAgents as E}from"./packem_shared/AGENTS_FILENAME-BesaDYkL.mjs";import{default as A}from"./packem_shared/discoverAuthApiCalls-CYdI8pkP.mjs";import{CONTAINERS_FILENAME as v,discoverContainers as N}from"./packem_shared/CONTAINERS_FILENAME-CFwdyaCI.mjs";import{default as R}from"./packem_shared/discoverCrons-CwtPaymU.mjs";import{FLAGS_FILENAME as C,discoverFlags as g}from"./packem_shared/FLAGS_FILENAME-UPE377GV.mjs";import{discoverFunctions as I}from"./packem_shared/discoverFunctions-CVYkUBTm.mjs";import{default as L}from"./packem_shared/discoverHttpRoutes-DmTedJlp.mjs";import{default as T}from"./packem_shared/discoverInserts-CssZuKb6.mjs";import{default as D}from"./packem_shared/discoverMaskProcedures-DQ-4yUUK.mjs";import{default as H}from"./packem_shared/discoverMigrations-qyXaVjw1.mjs";import{MUTATORS_FILENAME as
|
|
1
|
+
import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as p}from"./packem_shared/formatAdvisories-BCEfzLT0.mjs";import{CodegenDiagnosticError as c,diagnosticAt as n}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as l,discoverAgents as E}from"./packem_shared/AGENTS_FILENAME-BesaDYkL.mjs";import{default as A}from"./packem_shared/discoverAuthApiCalls-CYdI8pkP.mjs";import{CONTAINERS_FILENAME as v,discoverContainers as N}from"./packem_shared/CONTAINERS_FILENAME-CFwdyaCI.mjs";import{default as R}from"./packem_shared/discoverCrons-CwtPaymU.mjs";import{FLAGS_FILENAME as C,discoverFlags as g}from"./packem_shared/FLAGS_FILENAME-UPE377GV.mjs";import{discoverFunctions as I}from"./packem_shared/discoverFunctions-CVYkUBTm.mjs";import{default as L}from"./packem_shared/discoverHttpRoutes-DmTedJlp.mjs";import{default as T}from"./packem_shared/discoverInserts-CssZuKb6.mjs";import{default as D}from"./packem_shared/discoverMaskProcedures-DQ-4yUUK.mjs";import{default as H}from"./packem_shared/discoverMigrations-qyXaVjw1.mjs";import{MUTATORS_FILENAME as y,discoverMutators as W}from"./packem_shared/MUTATORS_FILENAME-CsAoG-d2.mjs";import{default as V}from"./packem_shared/discoverNondeterministicCalls-GNP4oKrf.mjs";import{NOTIFY_FILENAME as k,discoverNotifyCalls as z,discoverNotifyConfig as Q}from"./packem_shared/NOTIFY_FILENAME-zA5OFFbv.mjs";import{y as J}from"./packem_shared/discover-queries-Ctpk9SA-.mjs";import{QUEUES_FILENAME as q,discoverQueues as B}from"./packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs";import{default as $}from"./packem_shared/discoverR2sqlCalls-B7uqLnVS.mjs";import{discoverRlsMetadata as Z,default as ee}from"./packem_shared/discoverRlsMetadata-Bt0QK8VM.mjs";import{discoverSandboxUsage as re}from"./packem_shared/discoverSandboxUsage-Bb2JzaIW.mjs";import{default as se}from"./packem_shared/discoverSchema-DUl8rbP3.mjs";import{SHAPES_FILENAME as ie,discoverShapes as me}from"./packem_shared/SHAPES_FILENAME-DyVUZzIk.mjs";import{default as pe}from"./packem_shared/discoverStorageRulesMetadata-VJ_uXOFe.mjs";import{WORKFLOWS_FILENAME as ce,discoverWorkflows as ne}from"./packem_shared/WORKFLOWS_FILENAME-ClsYRKXp.mjs";import{R as le,J as Ee,y as xe,x as Ae,H as ue,p as ve,n as Ne,u as Oe,N as Re,$ as Me,a as Ce,g as ge,G as he,m as Ie}from"./packem_shared/emit-CCw5fiXq.mjs";import{emitApp as Le}from"./packem_shared/emitApp-DEHN578T.mjs";import{buildOpenApiDocument as Te,emitOpenApi as Pe,emitOpenApiModule as De}from"./packem_shared/buildOpenApiDocument-D46nZ7D_.mjs";import{OPENRPC_VERSION as He,buildOpenRpcDocument as Ge,emitOpenRpc as ye,emitOpenRpcModule as We}from"./packem_shared/OPENRPC_VERSION-DfKtsdPS.mjs";import{DEFAULT_TARGET as Ve,platformMatrixIds as je,readProjectTarget as ke,resolveCodegenTarget as ze}from"./packem_shared/DEFAULT_TARGET-BYPEwgZu.mjs";import{SCHEMA_SNAPSHOT_FILENAME as we,createCodegenProject as Je,refreshCodegenProject as Ke,runCodegen as qe}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-DjpfF4p7.mjs";import{SchemaSnapshotParseError as Ye,buildSchemaSnapshot as $e,evaluateSchemaDrift as Xe,parseSchemaSnapshot as Ze}from"./packem_shared/SchemaSnapshotParseError-0KRzSjo4.mjs";import{schemaFromIr as oo}from"./packem_shared/schemaFromIr-R1ZFzVyy.mjs";import{LUNORA_ERROR_CODES as to,validatorIrToJsonSchema as so}from"./packem_shared/LUNORA_ERROR_CODES-Um9hC1gr.mjs";import{redact as io,secretKindOf as mo}from"./packem_shared/redact-6jD4lAhq.mjs";import{MESSAGE_SOLUTIONS as fo,findSolutionByMessage as co}from"@lunora/errors";const e="0.0.0";export{l as AGENTS_FILENAME,v as CONTAINERS_FILENAME,c as CodegenDiagnosticError,Ve as DEFAULT_TARGET,C as FLAGS_FILENAME,le as GENERATED_HEADER,to as LUNORA_ERROR_CODES,fo as LUNORA_SOLUTION_RULES,y as MUTATORS_FILENAME,k as NOTIFY_FILENAME,He as OPENRPC_VERSION,q as QUEUES_FILENAME,we as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,ie as SHAPES_FILENAME,Ye as SchemaSnapshotParseError,e as VERSION,ce as WORKFLOWS_FILENAME,Te as buildOpenApiDocument,Ge as buildOpenRpcDocument,$e as buildSchemaSnapshot,Je as createCodegenProject,n as diagnosticAt,s as diffSchemaSnapshots,E as discoverAgents,A as discoverAuthApiCalls,N as discoverContainers,R as discoverCrons,g as discoverFlags,I as discoverFunctions,L as discoverHttpRoutes,T as discoverInserts,D as discoverMaskProcedures,H as discoverMigrations,W as discoverMutators,V as discoverNondeterministicCalls,z as discoverNotifyCalls,Q as discoverNotifyConfig,J as discoverQueries,B as discoverQueues,$ as discoverR2sqlCalls,Z as discoverRlsMetadata,ee as discoverRlsProcedures,re as discoverSandboxUsage,se as discoverSchema,me as discoverShapes,pe as discoverStorageRulesMetadata,ne as discoverWorkflows,Ee as emitAgents,xe as emitApi,Le as emitApp,Ae as emitCollections,ue as emitContainers,ve as emitCrons,Ne as emitDataModel,Oe as emitDrizzleSchema,Re as emitFunctions,Pe as emitOpenApi,De as emitOpenApiModule,ye as emitOpenRpc,We as emitOpenRpcModule,Me as emitServer,Ce as emitShard,ge as emitVectors,he as emitWorkflows,Ie as emitWranglerCronTriggers,Xe as evaluateSchemaDrift,co as findLunoraSolution,m as formatAdvisories,d as lintSchema,Ze as parseSchemaSnapshot,je as platformMatrixIds,ke as readProjectTarget,io as redact,Ke as refreshCodegenProject,ze as resolveCodegenTarget,qe as runCodegen,oo as schemaFromIr,mo as secretKindOf,a as serializeSchemaSnapshot,p as toAdvisorContext,so as validatorIrToJsonSchema};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"@lunora/agent/component";import"@lunora/errors";import"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{R as r,b as o,J as n,y as l,x as p,H as g,p as u,n as c,u as C,N as E,z as S,c as d,$ as A,a as D,g as z,G as R,m as b}from"./emit-CCw5fiXq.mjs";import"./paths-BmX5O1sG.mjs";export{r as GENERATED_HEADER,o as buildStorageColumns,n as emitAgents,l as emitApi,p as emitCollections,g as emitContainers,u as emitCrons,c as emitDataModel,C as emitDrizzleSchema,E as emitFunctions,S as emitQueues,d as emitSeed,A as emitServer,D as emitShard,z as emitVectors,R as emitWorkflows,b as emitWranglerCronTriggers};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{R as a}from"./emit-CCw5fiXq.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,12 +1,12 @@
|
|
|
1
|
-
import{existsSync as E,readFileSync as
|
|
1
|
+
import{existsSync as E,readFileSync as ye,mkdirSync as Gt,writeFileSync as Ht,rmSync as Qt}from"node:fs";import{join as g,dirname as fe}from"node:path";import{performance as me}from"node:perf_hooks";import{runAdvisor as Jt}from"@lunora/advisor";import{LunoraError as R}from"@lunora/errors";import{Node as i,SyntaxKind as u,Project as tt}from"ts-morph";import{serializeSchemaSnapshot as Xt}from"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{toAdvisorContext as Zt}from"./formatAdvisories-BCEfzLT0.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as p,classifyProcedureCall as k,inlineHandler as Yt,procedureHandler as ht,chainUsesWrappedCall as Et,isDatabaseAccessor as C,chainHasStep as es,discoverFunctions as ts,resolveStandardSchemaType as ss}from"./discoverFunctions-CVYkUBTm.mjs";import{discoverAgents as rs}from"./AGENTS_FILENAME-BesaDYkL.mjs";import{i as w,a as O,e as h,c as S,r as ns,s as G,b as is,d as os,y as as}from"./discover-queries-Ctpk9SA-.mjs";import cs from"./discoverAuthApiCalls-CYdI8pkP.mjs";import{discoverContainers as us}from"./CONTAINERS_FILENAME-CFwdyaCI.mjs";import ls from"./discoverCrons-CwtPaymU.mjs";import{diagnosticAt as H}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{o as Q}from"./module-specifiers-8FEEiUcv.mjs";import{r as xe,b as ds,n as gs,y as ps,$ as fs,N as ms,a as xs,x as hs,H as Es,G as $s,J as ys,z as As,p as Ss,g as Ns,u as bs,c as vs,m as Ps}from"./emit-CCw5fiXq.mjs";import{discoverFlagKeys as ws}from"./FLAGS_FILENAME-UPE377GV.mjs";import Is from"./discoverHttpRoutes-DmTedJlp.mjs";import Ls from"./discoverInserts-CssZuKb6.mjs";import Ts,{discoverMaskStrategies as Os,discoverMaskMetadata as Fs}from"./discoverMaskProcedures-DQ-4yUUK.mjs";import Ds from"./discoverMigrations-qyXaVjw1.mjs";import{MUTATORS_FILENAME as Cs,isDefineMutatorCallee as ks,discoverMutators as Ks}from"./MUTATORS_FILENAME-CsAoG-d2.mjs";import Rs from"./discoverNondeterministicCalls-GNP4oKrf.mjs";import{discoverNotifyConfig as js,discoverNotifyCalls as zs}from"./NOTIFY_FILENAME-zA5OFFbv.mjs";import{discoverQueues as Ms}from"./QUEUES_FILENAME-CSE6i-ld.mjs";import qs from"./discoverR2sqlCalls-B7uqLnVS.mjs";import Bs,{discoverRlsMetadata as Vs}from"./discoverRlsMetadata-Bt0QK8VM.mjs";import{discoverSandboxUsage as Us}from"./discoverSandboxUsage-Bb2JzaIW.mjs";import Ws from"./discoverSchema-DUl8rbP3.mjs";import{secretKindOf as _s,redact as Gs,isHeuristicSecretKind as Hs,isSecretishName as Qs}from"./redact-6jD4lAhq.mjs";import{discoverShapes as Js}from"./SHAPES_FILENAME-DyVUZzIk.mjs";import Xs from"./discoverStorageRulesMetadata-VJ_uXOFe.mjs";import{e as Zs}from"./discover-ast-CezKqEhE.mjs";import{discoverWorkflows as Ys}from"./WORKFLOWS_FILENAME-ClsYRKXp.mjs";import{emitApp as er}from"./emitApp-DEHN578T.mjs";import{buildOpenApiDocument as tr,emitOpenApiModule as sr}from"./buildOpenApiDocument-D46nZ7D_.mjs";import{buildOpenRpcDocument as rr,emitOpenRpcModule as nr}from"./OPENRPC_VERSION-DfKtsdPS.mjs";import{p as ir}from"./parse-validator-_jDrFxwt.mjs";import{gatePlatformFeatures as or,resolveCodegenTarget as ar}from"./DEFAULT_TARGET-BYPEwgZu.mjs";import{buildSchemaSnapshot as cr}from"./SchemaSnapshotParseError-0KRzSjo4.mjs";const ur=e=>{const t=[],s=e.tables.filter(r=>r.shardMode==="global");return s.some(r=>r.globalBackend!=="hyperdrive")&&t.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),s.some(r=>r.globalBackend==="hyperdrive")&&t.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'}),e.vectorIndexes.length>0&&t.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/vectors.ts` import `@lunora/bindings/vectors`"}),t},lr=(e,t)=>{if(t===void 0)return;const s=ur(e).filter(o=>!t.has(o.name));if(s.length===0)return;const r=s.map(o=>` - ${o.name} — ${o.reason}`).join(`
|
|
2
2
|
`),n=s.map(o=>o.name).join(" ");throw new R("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
|
|
3
3
|
${r}
|
|
4
4
|
|
|
5
5
|
Install them, then re-run codegen:
|
|
6
6
|
|
|
7
7
|
pnpm add ${n}
|
|
8
|
-
`)},yt=new Set(["delete","get","head","options","patch","post","put"]),dr=new Set(["handler","stream"]),gr=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,st=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),pr=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!yt.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()}},fr=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)||yt.has(r.getName()))break;s=r.getExpression()}return pr(s)},mr=e=>{for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression))if(st.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&st.has(s.getText()))return!0}return!1},xr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||!dr.has(r.getName()))return;const n=fr(s);if(!n||!gr.test(n.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&mr(o);return{exportName:e.getName(),file:t,method:n.method,path:n.path,usesGuard:a}},hr=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=xr(n,t);o&&s.push(o)}return s},Er=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...hr(n,p(t,r)))}return s},yr=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",$r=(e,t)=>{if(!yr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)||O(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},Ar=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=$r(r,t);n&&s.push(n)}return s},Sr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ar(n,p(t,r)))}return s},Nr=new Set(["generateText","streamText"]),br=new Set(["messages","prompt","system"]),vr=[{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"]}],Pr=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),r=t.getExpression().getText();for(const n of vr)if(n.methods.has(s)&&n.prefixes.some(o=>r===o||r.startsWith(`${o}.`)))return`${r}.${s}`},wr=e=>{for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=Pr(t);if(s!==void 0)return s}},Ir=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},Lr=e=>{if(ns(e))return!0;const t=Ir(e);return t.size===0?!1:e.getDescendantsOfKind(u.Identifier).some(s=>t.has(s.getText()))},Tr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!br.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&Lr(s))return!0}return!1},Or=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());if(n===void 0||!Nr.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(S(c.getExpression())==="tool"&&(a=wr(c),a!==void 0))break;a!==void 0&&s.push({exportName:h(r),file:t,line:r.getStartLineNumber(),method:n,sideEffect:a,userInputDerived:Tr(o)})}return s},Fr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Or(n,p(t,r)))}return s},Dr=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},Cr=(e,t)=>{if(!Dr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},kr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Cr(r,t);n&&s.push(n)}return s},Kr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...kr(n,p(t,r)))}return s},$t=e=>e.getProperties().some(t=>i.isSpreadAssignment(t)),Rr=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const r=s.getInitializer();return!r||!i.isObjectLiteralExpression(r)?{objects:[],opaque:!0}:{objects:[r],opaque:$t(r)}},jr=e=>{const t=[];let s=!1,r=e;for(;i.isCallExpression(r);){const n=r.getExpression();if(!i.isPropertyAccessExpression(n))break;if(n.getName()==="input"){const o=r.getArguments()[0];o&&i.isObjectLiteralExpression(o)?(t.push(o),s||=$t(o)):s=!0}r=n.getExpression()}return{objects:t,opaque:s}},At=(e,t)=>t?jr(t):Rr(e),zr=e=>e.flatMap(t=>t.getProperties().filter(s=>i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)).map(s=>s.getName())),Mr=/\.check\(|\.meta\(|length|max/iu,qr=/\bv\.any\s*\(/u,Br=/\bv\.string\s*\(/u,Vr=e=>qr.test(e),Ur=e=>Br.test(e)&&!Mr.test(e),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();Vr(a)?t.push(c):Ur(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},_r=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=k(s);if(r?.visibility!=="public")return;const{objects:n}=At(s,r.receiver),{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}},Gr=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=_r(n,t);o&&s.push(o)}return s},Hr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Gr(n,p(t,r)))}return s},N=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},he=e=>e?.getKind()===u.TrueKeyword,Qr=e=>e?.getKind()===u.FalseKeyword,Jr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Xr=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Zr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&S(t.getExpression())==="scim"),Yr=e=>e!==void 0&&i.isCallExpression(e)&&Xr.has(S(e.getExpression())??""),en=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),tn=e=>{const t=N(e,"advanced"),s=N(e,"emailAndPassword"),r=N(e,"session");return{analyzable:!0,disableCsrfCheck:he(N(t,"disableCSRFCheck")),emailPasswordEnabled:he(N(s,"enabled")),requireEmailVerification:he(N(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Zr(N(e,"plugins"))&&Yr(N(e,"database")),secureCookiesDisabled:Qr(N(t,"useSecureCookies")),sessionFreshAgeZero:Jr(N(r,"freshAge")),trustedOriginsWildcard:en(N(e,"trustedOrigins"))}},sn=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),rn=(e,t)=>{if(S(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?tn(s):sn();return{exportName:h(e),file:t,line:e.getStartLineNumber(),...n}},nn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=rn(r,t);n&&s.push(n)}return s},on=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...nn(n,p(t,r)))}return s},an=(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},cn=(e,t,s)=>{const r=an(e.getExpression(),s);if(r===void 0)return;const n=e.getArguments()[s.argIndex];if(!(!n||!w(n)||O(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:r}},un=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const o=cn(n,t,s);o&&r.push(o)}return r},J=(e,t,s)=>{const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(...un(o,p(t,n),s))}return r},ln=new Set(["content","pdf","scrape","screenshot"]),dn=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:ln}),gn=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),pn=new Set(["RateLimiter"]),fn=new Set(["extend"]),St=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}},rt=e=>e&&i.isObjectLiteralExpression(e)?St(e):{analyzable:!1,presentKeys:[],trueKeys:[]},mn=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},xn=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)?mn(e):void 0},hn=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&xn(t.getBody());return s?St(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},En=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());n!==void 0&&(gn.has(n)?s.push({callee:n,file:t,line:r.getStartLineNumber(),...rt(r.getArguments()[0])}):fn.has(n)&&s.push({callee:n,file:t,line:r.getStartLineNumber(),...hn(r.getArguments()[0])}))}for(const r of e.getDescendantsOfKind(u.NewExpression)){const n=S(r.getExpression());n===void 0||!pn.has(n)||s.push({callee:n,file:t,line:r.getStartLineNumber(),...rt(r.getArguments()[0])})}return s},yn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...En(n,p(t,r)))}return s},nt="ctx.containers.",$n=e=>{if(!e.startsWith(nt))return!1;const t=e.slice(nt.length);return t.length>0&&!t.includes(".")},An=(e,t)=>J(e,t,{argIndex:0,matchReceiver:$n,methods:new Set(["get"])}),Sn=new Set(["allow","deny","setAllowed"]),Nn=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())},bn=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!Nn(e)))return{detail:"enableInternet: true",exportName:h(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},vn=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!Sn.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()}},Pn=(e,t)=>bn(e,t)??vn(e,t),wn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Pn(r,t);n&&s.push(n)}return s},In=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...wn(n,p(t,r)))}return s},Ln="env.ts",Tn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return Q(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},On=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&&Q(r.getModuleSpecifierValue())}return!1},Fn=e=>{if(i.isIdentifier(e))return Tn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&On(t)}return!1},Dn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!Fn(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw H(n,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},Cn=(e,t)=>{const s=g(t,Ln);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=Dn(r);if(n.length!==0){if(n.length>1)throw H(r,`lunora/env.ts declares ${n.length.toString()} defineEnv() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},kn=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Kn=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return kn.has(s)?s:void 0},Rn=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}},jn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){const c=Kn(a);if(c===void 0)continue;const l=a.getArguments()[0],f=l&&i.isObjectLiteralExpression(l)?Rn(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:f.analyzable,emptyKeys:f.emptyKeys,factory:c,file:o,line:a.getStartLineNumber(),presentKeys:f.presentKeys})}}return s},zn=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Mn=new Set(["dbRateLimit","rateLimit"]),qn=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},Bn=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},Vn=(e,t)=>{const s=S(e.getExpression());if(s===void 0)return;const r=zn.get(s);if(r!==void 0)return{callee:s,exportName:h(e),failOpen:qn(e.getArguments()[r]),file:t,limitName:Mn.has(s)?Bn(e):"",line:e.getStartLineNumber()}},Un=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Vn(r,t);n&&s.push(n)}return s},Wn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Un(n,p(t,r)))}return s},_n=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},Gn=(e,t)=>{const s=Object.fromEntries(xe.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=_n(n);for(const c of xe)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(xe.every(c=>s[c.key]))break}return s},Hn=["providerSubscriptionId","state"],Qn=["providerEventId","processedAt"],it=(e,t)=>t.every(s=>s in e.shape),Jn=e=>{const t=e.find(r=>r.name==="subscriptions"),s=e.find(r=>r.name==="events");return t!==void 0&&s!==void 0&&it(t,Hn)&&it(s,Qn)},Xn=(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"),notifications:e.notify||t.dependencies.has("@lunora/notify"),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")}),Zn=e=>i.isIdentifier(e)&&e.getText()==="ctx",Yn=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Zn(t.getExpression())},ei=e=>{if(e?.getKind()===u.TrueKeyword)return!0;if(e?.getKind()===u.FalseKeyword)return!1},ti=(e,t)=>{if(!Yn(e.getExpression()))return;const[s,r]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const n=s.getLiteralValue(),o=ei(r);if(!(n.length===0||o===void 0))return{defaultValue:o,exportName:h(e),file:t,key:n,line:e.getStartLineNumber()}},si=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ti(r,t);n&&s.push(n)}return s},ri=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...si(n,p(t,r)))}return s},ni=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},ii=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},oi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression))ni(a)&&s.push({file:o,indexName:ii(a),line:a.getStartLineNumber()})}return s},ai=new Set(["delete","get","head","options","patch","post","put"]),ci=new Set(["handler","stream"]),ui=new Set(["runAction","runMutation"]),li=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),U=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,ot=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,at=(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}}},ct=(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(ui.has(a)&&U(c,t))return a;if(li.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&U(c.getExpression(),t))return`db.${a}`}},ut=(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},di=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ci.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(ai.has(n)){const o=r.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?n.toUpperCase():void 0}s=r.getExpression()}},gi=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=ot(e.getArguments()[0]),l=c&&at(c,!0);if(!c||l===void 0)return;const f=ct(c,l);return f===void 0?void 0:{exportName:h(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ut(c,l),sideEffect:f}}const r=di(e);if(r===void 0)return;const n=ot(e.getArguments()[0]),o=n&&at(n,!1);if(!n||o===void 0)return;const a=ct(n,o);return a===void 0?void 0:{exportName:h(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:r,readsAuth:ut(n,o),sideEffect:a}},pi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=gi(r,t);n&&s.push(n)}return s},fi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...pi(n,p(t,r)))}return s},mi=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),xi=new Set(["append","set"]),Ae=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",Nt=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",lt=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(u.CallExpression)]:e.getDescendantsOfKind(u.CallExpression)).some(s=>mi.has(Ae(s.getExpression()))&&os(s,t)),hi=(e,t)=>{if(lt(e,t))return!0;const s=G(e);return s!==void 0&<(s,t)},ye=(e,t)=>is(e,t)&&!hi(e,t),Ei=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=G(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=G(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},Se=(e,t,s)=>{for(const r of e.getProperties())if(i.isPropertyAssignment(r)){const n=r.getInitializer();n!==void 0&&ye(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:Nt(r.getNameNode()),line:n.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(r)){const n=r.getNameNode();ye(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&&Se(n,t,s)}},bt=(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&&Se(n,"response-init",t)},yi=(e,t)=>{const s=Ae(e.getExpression());if(s==="Response")bt(e.getArguments()[1],t);else if(s==="Headers"){const r=W(e.getArguments()[0]);r!==void 0&&Se(r,"headers-ctor",t)}},$i=(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"){bt(e.getArguments()[1],t);return}if(xi.has(r)&&Ei(n)){const o=e.getArguments()[1];o!==void 0&&ye(o,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:Nt(e.getArguments()[0]),line:o.getStartLineNumber(),via:r==="set"?"headers-set":"headers-append"})}},Ai=(e,t)=>{for(const s of e.getDescendantsOfKind(u.NewExpression))yi(s,t);for(const s of e.getDescendantsOfKind(u.CallExpression))$i(s,t)},Si=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const r=Yt(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 Ai(r,{exportName:h(e),relativePath:t,requestName:o.getText(),rows:a}),a},Ni=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...Si(r,t));return s},bi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ni(n,p(t,r)))}return s},vt="identity.ts",vi=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return Q(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Pi=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&&Q(r.getModuleSpecifierValue())}return!1},wi=e=>{if(i.isIdentifier(e))return vi(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&Pi(t)}return!1},Ii=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!wi(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw H(n,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},Li=(e,t)=>{const s=g(t,vt);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=Ii(r);if(n.length!==0){if(n.length>1)throw H(r,`lunora/identity.ts declares ${n.length.toString()} defineIdentity() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},Ti=new Set(["auth","context.auth","ctx.auth"]),Oi="userId",Fi=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},Di=(e,t)=>{const s=g(t,vt);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const n of r.getDescendantsOfKind(u.CallExpression)){if(S(n.getExpression())!=="defineIdentity")continue;const[o]=n.getArguments();return o&&i.isObjectLiteralExpression(o)?Fi(o):void 0}},dt=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Ti.has(e.getExpression().getText())?e:void 0},Ci=e=>{if(i.isPropertyAccessExpression(e)&&dt(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&dt(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},ki=(e,t,s)=>{const r=[];for(const n of e.getDescendants()){const o=Ci(n);o!==void 0&&r.push({declared:o===Oi||s.has(o),exportName:h(n),file:t,key:o,line:n.getStartLineNumber()})}return r},Ki=(e,t)=>{const s=Di(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(...ki(o,p(t,n),s))}return r},Ri=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},ji=(e,t)=>{if(S(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const r=Ri(s);if(!(!r||!w(r)||O(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},zi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ji(r,t);n&&s.push(n)}return s},Mi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...zi(n,p(t,r)))}return s},qi=new Set(["delete","get","getRaw","getWithMetadata","put"]),Bi=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:qi}),Vi=new Set(["queue","send"]),gt=new Set(["bcc","cc","to"]),Ui=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Vi.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},Wi=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const r=t.getNameNode();return gt.has(t.getName())&&w(r)&&!O(r)}if(!i.isPropertyAssignment(t)||!gt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&w(s)&&!O(s)}):!1,_i=(e,t)=>{const s=Ui(e.getExpression());if(s===void 0)return;const r=e.getArguments()[0];if(!(!r||!Wi(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Gi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=_i(r,t);n&&s.push(n)}return s},Hi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Gi(n,p(t,r)))}return s},Qi=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"},Ji=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},Xi=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==u.CallExpression)return;const s=t;return ks(s.getExpression())?s:void 0},Zi=e=>{const t=Xi(e),s=t===void 0?void 0:Ji(t);if(s===void 0)return[];const r=e.getNameNode(),n=i.isIdentifier(r)?r.getText():"";return s.getDescendantsOfKind(u.CallExpression).filter(o=>Qi(o)).map(o=>({exportName:n,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},Yi=e=>e.getVariableDeclarations().flatMap(t=>Zi(t)),eo=(e,t)=>{const s=g(t,Cs);if(!E(s))return[];const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Yi(r)},to=new Set(["delete","get","patch"]),so=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),ro=new Set(["auth","identity","session","user"]),no=new Set([u.EqualsEqualsEqualsToken,u.EqualsEqualsToken,u.ExclamationEqualsEqualsToken,u.ExclamationEqualsToken]),io=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!C(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},oo=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},ao=(e,t)=>e.getDescendantsOfKind(u.Identifier).some(s=>s.getText()===t),co=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(u.ThrowStatement).length>0||e.getDescendantsOfKind(u.ReturnStatement).length>0,uo=(e,t)=>e.getDescendantsOfKind(u.IfStatement).some(s=>ao(s.getExpression(),t)&&co(s.getThenStatement())),lo=(e,t)=>{for(const s of e.getDescendantsOfKind(u.CallExpression)){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))continue;const n=r.getName();if(!to.has(n))continue;const o=r.getExpression();if(!(C(o)||i.isPropertyAccessExpression(o)&&C(o.getExpression())))continue;const a=s.getArguments()[0];if(a!==void 0&&i.isIdentifier(a)&&a.getText()===t)return n}},go=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},po=e=>e.getDescendantsOfKind(u.CallExpression).some(t=>t.getArguments().some(s=>go(s)==="ctx")),fo=e=>e.getDescendantsOfKind(u.BinaryExpression).some(t=>no.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),mo=e=>{for(const t of e.getDescendantsOfKind(u.Identifier))if(so.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&ro.has(t.getName()))return!0}return po(e)||fo(e)},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"&&r?.kind!=="mutation")return[];const n=ht(s);if(n===void 0)return[];const o=r.receiver!==void 0&&Et(r.receiver,"use","rls"),a=mo(n),c=new Set,l=[];for(const f of n.getDescendantsOfKind(u.CallExpression)){const y=io(f);if(y===void 0)continue;const I=oo(f);if(I===void 0||c.has(I)||!uo(n,I))continue;const K=lo(n,I);K!==void 0&&(c.add(I),l.push({exportName:e.getName(),file:t,line:f.getStartLineNumber(),mentionsOwnership:a,sinkMethod:K,table:y,usesRls:o,visibility:r.visibility}))}return l},ho=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...xo(c,o))}return s},Eo=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),yo=new Set(["insert","insertManyUnsafe","patch","replace"]),$o=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!yo.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},Ao=(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},So=(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||!Eo.has(a))&&w(c)&&!O(c)&&n.push({exportName:h(s),field:a,file:r,line:s.getStartLineNumber(),method:t})}return n},No=(e,t)=>{const s=$o(e.getExpression());if(s===void 0)return[];const r=e.getArguments()[1];return r?Ao(r,s).flatMap(n=>So(n,s,e,t)):[]},bo=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression))for(const o of No(n,t)){const a=s(o.exportName);r.push(a===void 0?o:{...o,visibility:a})}return r},vo=(e,t,s=[])=>{const r=[],n=new Map(s.map(o=>[`${o.filePath}:${o.exportName}`,o.visibility]));for(const o of d(t)){const a=e.getSourceFile(o)??e.addSourceFileAtPath(o),c=p(t,o);r.push(...bo(a,c,l=>n.get(`${c}:${l}`)))}return r},Po=e=>{const t=g(e,"package.json");if(E(t))try{const s=JSON.parse($e(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}},wo=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Io=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Lo=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?Io(t.getInitializer()):void 0},To=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());if(n===void 0||!wo.has(n))continue;const[o]=r.getArguments(),a=o&&i.isObjectLiteralExpression(o)?Lo(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(...To(n,p(t,r)))}return s},Fo=new Set(["defineQueue","defineWorkflow"]),Do=new Set(["run","runAction","runMutation","runQuery"]),Co=new Set(["api","internal"]),ko=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},Ko=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},Pt=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},wt=(e,t)=>e===t||e.startsWith(`${t}.`),It=e=>{const t=e.getDescendantsOfKind(u.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},pt=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)},Lt=e=>{const t=e.getDescendantsOfKind(u.Identifier).filter(s=>pt(s));return i.isIdentifier(e)&&pt(e)&&t.push(e),t},Ro=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(u.BindingElement).map(s=>s.getName())},jo=e=>{const t=Pt(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},zo=(e,t,s)=>{const r=t==="workflow"?[`${s}.params`]:jo(e),n=new Set,o=a=>It(a).some(c=>r.some(l=>wt(c.getText(),l)))?!0:Lt(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 Ro(a))n.add(l)}return{names:n,prefixes:r}},Mo=(e,t)=>It(e).some(s=>t.prefixes.some(r=>wt(s.getText(),r)))?!0:Lt(e).some(s=>t.names.has(s.getText())),qo=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)||!Co.has(s.getText())||t.length<2))return{exportName:r,file:t.slice(0,-1).join("/")}},Bo=(e,t,s)=>{const r=Pt(e,0);if(r===void 0)return[];const n=zo(e,t,r),o=[];for(const a of e.getDescendantsOfKind(u.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!Do.has(c.getName())||c.getExpression().getText()!==r)continue;const l=a.getArguments()[1];if(!l||!Mo(l,n))continue;const f=qo(a.getArguments()[0]);f!==void 0&&o.push({dispatchKind:t,file:s,handlerExport:h(a),line:a.getStartLineNumber(),targetExport:f.exportName,targetFile:f.file})}return o},Vo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ko(r);if(n===void 0||!Fo.has(n))continue;const o=Ko(r);o!==void 0&&s.push(...Bo(o,n==="defineQueue"?"queue":"workflow",t))}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,p(t,r)))}return s},ft={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},Wo=/account|credential|member|passkey|session|user/iu,_o=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Go=(e,t)=>{const{objects:s,opaque:r}=At(e,t);return zr(s).some(n=>_o(n))?!0:r?void 0:!1},Ne=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},Ho=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Qo=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},Jo=e=>{const t=Qo(e),s=t?Ne(t):void 0;if(t&&s==="protectPublic"){const r=Ho(t);return{...V,usesCaptcha:r.usesCaptcha,usesRateLimit:r.usesRateLimit}}return s!==void 0&&s in ft?{...V,[ft[s]]:!0}:V},Xo=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=Jo(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},Zo=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)&&Wo.test(r.getLiteralText()))},Yo=new Set(["create","runAfter","runAt","send","sendBatch"]),ea=new Set(["queues","scheduler","workflows"]),ta=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Yo.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&ea.has(s.getName())){const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="ctx")return!0}s=s.getExpression()}return!1},sa=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"},Tt=new Set(["generateObject","generateText","streamObject","streamText"]),ra=e=>{const t=Ne(e);return t!==void 0&&Tt.has(t)},na=e=>{const t=Ne(e);if(t===void 0||!Tt.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")},ia=new Set(["log","span","trace"]),oa=new Set(["ai"]),aa=new Set(["email","mail"]),ca=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),B=(e,t)=>e.getDescendantsOfKind(u.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const r=s.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"}),ua=e=>e.getDescendantsOfKind(u.ThrowStatement).some(t=>{const s=t.getExpression();if(!i.isNewExpression(s))return!1;const r=s.getExpression();return i.isIdentifier(r)&&r.getText()==="Error"}),mt="lunora-advisor-exempt",la=/^[\s*/]+/u,da=/[\w-]/u,ga=e=>{const t=(e.getFirstAncestorByKind(u.VariableStatement)??e).getLeadingCommentRanges().map(s=>s.getText()).join(`
|
|
8
|
+
`)},$t=new Set(["delete","get","head","options","patch","post","put"]),dr=new Set(["handler","stream"]),gr=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,st=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),pr=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!$t.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()}},fr=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)||$t.has(r.getName()))break;s=r.getExpression()}return pr(s)},mr=e=>{for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression))if(st.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&st.has(s.getText()))return!0}return!1},xr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||!dr.has(r.getName()))return;const n=fr(s);if(!n||!gr.test(n.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&mr(o);return{exportName:e.getName(),file:t,method:n.method,path:n.path,usesGuard:a}},hr=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=xr(n,t);o&&s.push(o)}return s},Er=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...hr(n,p(t,r)))}return s},$r=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",yr=(e,t)=>{if(!$r(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)||O(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},Ar=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=yr(r,t);n&&s.push(n)}return s},Sr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ar(n,p(t,r)))}return s},Nr=new Set(["generateText","streamText"]),br=new Set(["messages","prompt","system"]),vr=[{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"]}],Pr=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),r=t.getExpression().getText();for(const n of vr)if(n.methods.has(s)&&n.prefixes.some(o=>r===o||r.startsWith(`${o}.`)))return`${r}.${s}`},wr=e=>{for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=Pr(t);if(s!==void 0)return s}},Ir=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},Lr=e=>{if(ns(e))return!0;const t=Ir(e);return t.size===0?!1:e.getDescendantsOfKind(u.Identifier).some(s=>t.has(s.getText()))},Tr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!br.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&Lr(s))return!0}return!1},Or=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());if(n===void 0||!Nr.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(S(c.getExpression())==="tool"&&(a=wr(c),a!==void 0))break;a!==void 0&&s.push({exportName:h(r),file:t,line:r.getStartLineNumber(),method:n,sideEffect:a,userInputDerived:Tr(o)})}return s},Fr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Or(n,p(t,r)))}return s},Dr=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},Cr=(e,t)=>{if(!Dr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},kr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Cr(r,t);n&&s.push(n)}return s},Kr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...kr(n,p(t,r)))}return s},yt=e=>e.getProperties().some(t=>i.isSpreadAssignment(t)),Rr=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const r=s.getInitializer();return!r||!i.isObjectLiteralExpression(r)?{objects:[],opaque:!0}:{objects:[r],opaque:yt(r)}},jr=e=>{const t=[];let s=!1,r=e;for(;i.isCallExpression(r);){const n=r.getExpression();if(!i.isPropertyAccessExpression(n))break;if(n.getName()==="input"){const o=r.getArguments()[0];o&&i.isObjectLiteralExpression(o)?(t.push(o),s||=yt(o)):s=!0}r=n.getExpression()}return{objects:t,opaque:s}},At=(e,t)=>t?jr(t):Rr(e),zr=e=>e.flatMap(t=>t.getProperties().filter(s=>i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)).map(s=>s.getName())),Mr=/\.check\(|\.meta\(|length|max/iu,qr=/\bv\.any\s*\(/u,Br=/\bv\.string\s*\(/u,Vr=e=>qr.test(e),Ur=e=>Br.test(e)&&!Mr.test(e),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();Vr(a)?t.push(c):Ur(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},_r=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=k(s);if(r?.visibility!=="public")return;const{objects:n}=At(s,r.receiver),{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}},Gr=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=_r(n,t);o&&s.push(o)}return s},Hr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Gr(n,p(t,r)))}return s},N=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},he=e=>e?.getKind()===u.TrueKeyword,Qr=e=>e?.getKind()===u.FalseKeyword,Jr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Xr=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Zr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&S(t.getExpression())==="scim"),Yr=e=>e!==void 0&&i.isCallExpression(e)&&Xr.has(S(e.getExpression())??""),en=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),tn=e=>{const t=N(e,"advanced"),s=N(e,"emailAndPassword"),r=N(e,"session");return{analyzable:!0,disableCsrfCheck:he(N(t,"disableCSRFCheck")),emailPasswordEnabled:he(N(s,"enabled")),requireEmailVerification:he(N(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Zr(N(e,"plugins"))&&Yr(N(e,"database")),secureCookiesDisabled:Qr(N(t,"useSecureCookies")),sessionFreshAgeZero:Jr(N(r,"freshAge")),trustedOriginsWildcard:en(N(e,"trustedOrigins"))}},sn=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),rn=(e,t)=>{if(S(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?tn(s):sn();return{exportName:h(e),file:t,line:e.getStartLineNumber(),...n}},nn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=rn(r,t);n&&s.push(n)}return s},on=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...nn(n,p(t,r)))}return s},an=(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},cn=(e,t,s)=>{const r=an(e.getExpression(),s);if(r===void 0)return;const n=e.getArguments()[s.argIndex];if(!(!n||!w(n)||O(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:r}},un=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const o=cn(n,t,s);o&&r.push(o)}return r},J=(e,t,s)=>{const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(...un(o,p(t,n),s))}return r},ln=new Set(["content","pdf","scrape","screenshot"]),dn=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:ln}),gn=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),pn=new Set(["RateLimiter"]),fn=new Set(["extend"]),St=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}},rt=e=>e&&i.isObjectLiteralExpression(e)?St(e):{analyzable:!1,presentKeys:[],trueKeys:[]},mn=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},xn=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)?mn(e):void 0},hn=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&xn(t.getBody());return s?St(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},En=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());n!==void 0&&(gn.has(n)?s.push({callee:n,file:t,line:r.getStartLineNumber(),...rt(r.getArguments()[0])}):fn.has(n)&&s.push({callee:n,file:t,line:r.getStartLineNumber(),...hn(r.getArguments()[0])}))}for(const r of e.getDescendantsOfKind(u.NewExpression)){const n=S(r.getExpression());n===void 0||!pn.has(n)||s.push({callee:n,file:t,line:r.getStartLineNumber(),...rt(r.getArguments()[0])})}return s},$n=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...En(n,p(t,r)))}return s},nt="ctx.containers.",yn=e=>{if(!e.startsWith(nt))return!1;const t=e.slice(nt.length);return t.length>0&&!t.includes(".")},An=(e,t)=>J(e,t,{argIndex:0,matchReceiver:yn,methods:new Set(["get"])}),Sn=new Set(["allow","deny","setAllowed"]),Nn=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())},bn=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!Nn(e)))return{detail:"enableInternet: true",exportName:h(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},vn=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!Sn.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()}},Pn=(e,t)=>bn(e,t)??vn(e,t),wn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Pn(r,t);n&&s.push(n)}return s},In=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...wn(n,p(t,r)))}return s},Ln="env.ts",Tn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return Q(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},On=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&&Q(r.getModuleSpecifierValue())}return!1},Fn=e=>{if(i.isIdentifier(e))return Tn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&On(t)}return!1},Dn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!Fn(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw H(n,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},Cn=(e,t)=>{const s=g(t,Ln);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=Dn(r);if(n.length!==0){if(n.length>1)throw H(r,`lunora/env.ts declares ${n.length.toString()} defineEnv() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},kn=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Kn=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return kn.has(s)?s:void 0},Rn=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}},jn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){const c=Kn(a);if(c===void 0)continue;const l=a.getArguments()[0],f=l&&i.isObjectLiteralExpression(l)?Rn(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:f.analyzable,emptyKeys:f.emptyKeys,factory:c,file:o,line:a.getStartLineNumber(),presentKeys:f.presentKeys})}}return s},zn=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Mn=new Set(["dbRateLimit","rateLimit"]),qn=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},Bn=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},Vn=(e,t)=>{const s=S(e.getExpression());if(s===void 0)return;const r=zn.get(s);if(r!==void 0)return{callee:s,exportName:h(e),failOpen:qn(e.getArguments()[r]),file:t,limitName:Mn.has(s)?Bn(e):"",line:e.getStartLineNumber()}},Un=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Vn(r,t);n&&s.push(n)}return s},Wn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Un(n,p(t,r)))}return s},_n=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},Gn=(e,t)=>{const s=Object.fromEntries(xe.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=_n(n);for(const c of xe)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(xe.every(c=>s[c.key]))break}return s},Hn=["providerSubscriptionId","state"],Qn=["providerEventId","processedAt"],it=(e,t)=>t.every(s=>s in e.shape),Jn=e=>{const t=e.find(r=>r.name==="subscriptions"),s=e.find(r=>r.name==="events");return t!==void 0&&s!==void 0&&it(t,Hn)&&it(s,Qn)},Xn=(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"),notifications:e.notify||t.dependencies.has("@lunora/notify"),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")}),Zn=e=>i.isIdentifier(e)&&e.getText()==="ctx",Yn=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Zn(t.getExpression())},ei=e=>{if(e?.getKind()===u.TrueKeyword)return!0;if(e?.getKind()===u.FalseKeyword)return!1},ti=(e,t)=>{if(!Yn(e.getExpression()))return;const[s,r]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const n=s.getLiteralValue(),o=ei(r);if(!(n.length===0||o===void 0))return{defaultValue:o,exportName:h(e),file:t,key:n,line:e.getStartLineNumber()}},si=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ti(r,t);n&&s.push(n)}return s},ri=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...si(n,p(t,r)))}return s},ni=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},ii=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},oi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression))ni(a)&&s.push({file:o,indexName:ii(a),line:a.getStartLineNumber()})}return s},ai=new Set(["delete","get","head","options","patch","post","put"]),ci=new Set(["handler","stream"]),ui=new Set(["runAction","runMutation"]),li=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),U=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,ot=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,at=(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}}},ct=(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(ui.has(a)&&U(c,t))return a;if(li.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&U(c.getExpression(),t))return`db.${a}`}},ut=(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},di=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ci.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(ai.has(n)){const o=r.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?n.toUpperCase():void 0}s=r.getExpression()}},gi=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=ot(e.getArguments()[0]),l=c&&at(c,!0);if(!c||l===void 0)return;const f=ct(c,l);return f===void 0?void 0:{exportName:h(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ut(c,l),sideEffect:f}}const r=di(e);if(r===void 0)return;const n=ot(e.getArguments()[0]),o=n&&at(n,!1);if(!n||o===void 0)return;const a=ct(n,o);return a===void 0?void 0:{exportName:h(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:r,readsAuth:ut(n,o),sideEffect:a}},pi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=gi(r,t);n&&s.push(n)}return s},fi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...pi(n,p(t,r)))}return s},mi=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),xi=new Set(["append","set"]),Ae=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",Nt=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",lt=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(u.CallExpression)]:e.getDescendantsOfKind(u.CallExpression)).some(s=>mi.has(Ae(s.getExpression()))&&os(s,t)),hi=(e,t)=>{if(lt(e,t))return!0;const s=G(e);return s!==void 0&<(s,t)},$e=(e,t)=>is(e,t)&&!hi(e,t),Ei=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=G(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=G(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},Se=(e,t,s)=>{for(const r of e.getProperties())if(i.isPropertyAssignment(r)){const n=r.getInitializer();n!==void 0&&$e(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:Nt(r.getNameNode()),line:n.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(r)){const n=r.getNameNode();$e(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&&Se(n,t,s)}},bt=(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&&Se(n,"response-init",t)},$i=(e,t)=>{const s=Ae(e.getExpression());if(s==="Response")bt(e.getArguments()[1],t);else if(s==="Headers"){const r=W(e.getArguments()[0]);r!==void 0&&Se(r,"headers-ctor",t)}},yi=(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"){bt(e.getArguments()[1],t);return}if(xi.has(r)&&Ei(n)){const o=e.getArguments()[1];o!==void 0&&$e(o,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:Nt(e.getArguments()[0]),line:o.getStartLineNumber(),via:r==="set"?"headers-set":"headers-append"})}},Ai=(e,t)=>{for(const s of e.getDescendantsOfKind(u.NewExpression))$i(s,t);for(const s of e.getDescendantsOfKind(u.CallExpression))yi(s,t)},Si=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const r=Yt(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 Ai(r,{exportName:h(e),relativePath:t,requestName:o.getText(),rows:a}),a},Ni=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...Si(r,t));return s},bi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ni(n,p(t,r)))}return s},vt="identity.ts",vi=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return Q(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Pi=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&&Q(r.getModuleSpecifierValue())}return!1},wi=e=>{if(i.isIdentifier(e))return vi(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&Pi(t)}return!1},Ii=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!wi(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw H(n,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},Li=(e,t)=>{const s=g(t,vt);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=Ii(r);if(n.length!==0){if(n.length>1)throw H(r,`lunora/identity.ts declares ${n.length.toString()} defineIdentity() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},Ti=new Set(["auth","context.auth","ctx.auth"]),Oi="userId",Fi=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},Di=(e,t)=>{const s=g(t,vt);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const n of r.getDescendantsOfKind(u.CallExpression)){if(S(n.getExpression())!=="defineIdentity")continue;const[o]=n.getArguments();return o&&i.isObjectLiteralExpression(o)?Fi(o):void 0}},dt=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Ti.has(e.getExpression().getText())?e:void 0},Ci=e=>{if(i.isPropertyAccessExpression(e)&&dt(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&dt(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},ki=(e,t,s)=>{const r=[];for(const n of e.getDescendants()){const o=Ci(n);o!==void 0&&r.push({declared:o===Oi||s.has(o),exportName:h(n),file:t,key:o,line:n.getStartLineNumber()})}return r},Ki=(e,t)=>{const s=Di(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(...ki(o,p(t,n),s))}return r},Ri=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},ji=(e,t)=>{if(S(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const r=Ri(s);if(!(!r||!w(r)||O(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},zi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ji(r,t);n&&s.push(n)}return s},Mi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...zi(n,p(t,r)))}return s},qi=new Set(["delete","get","getRaw","getWithMetadata","put"]),Bi=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:qi}),Vi=new Set(["queue","send"]),gt=new Set(["bcc","cc","to"]),Ui=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Vi.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},Wi=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const r=t.getNameNode();return gt.has(t.getName())&&w(r)&&!O(r)}if(!i.isPropertyAssignment(t)||!gt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&w(s)&&!O(s)}):!1,_i=(e,t)=>{const s=Ui(e.getExpression());if(s===void 0)return;const r=e.getArguments()[0];if(!(!r||!Wi(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Gi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=_i(r,t);n&&s.push(n)}return s},Hi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Gi(n,p(t,r)))}return s},Qi=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"},Ji=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},Xi=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==u.CallExpression)return;const s=t;return ks(s.getExpression())?s:void 0},Zi=e=>{const t=Xi(e),s=t===void 0?void 0:Ji(t);if(s===void 0)return[];const r=e.getNameNode(),n=i.isIdentifier(r)?r.getText():"";return s.getDescendantsOfKind(u.CallExpression).filter(o=>Qi(o)).map(o=>({exportName:n,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},Yi=e=>e.getVariableDeclarations().flatMap(t=>Zi(t)),eo=(e,t)=>{const s=g(t,Cs);if(!E(s))return[];const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Yi(r)},to=new Set(["delete","get","patch"]),so=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),ro=new Set(["auth","identity","session","user"]),no=new Set([u.EqualsEqualsEqualsToken,u.EqualsEqualsToken,u.ExclamationEqualsEqualsToken,u.ExclamationEqualsToken]),io=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!C(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},oo=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},ao=(e,t)=>e.getDescendantsOfKind(u.Identifier).some(s=>s.getText()===t),co=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(u.ThrowStatement).length>0||e.getDescendantsOfKind(u.ReturnStatement).length>0,uo=(e,t)=>e.getDescendantsOfKind(u.IfStatement).some(s=>ao(s.getExpression(),t)&&co(s.getThenStatement())),lo=(e,t)=>{for(const s of e.getDescendantsOfKind(u.CallExpression)){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))continue;const n=r.getName();if(!to.has(n))continue;const o=r.getExpression();if(!(C(o)||i.isPropertyAccessExpression(o)&&C(o.getExpression())))continue;const a=s.getArguments()[0];if(a!==void 0&&i.isIdentifier(a)&&a.getText()===t)return n}},go=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},po=e=>e.getDescendantsOfKind(u.CallExpression).some(t=>t.getArguments().some(s=>go(s)==="ctx")),fo=e=>e.getDescendantsOfKind(u.BinaryExpression).some(t=>no.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),mo=e=>{for(const t of e.getDescendantsOfKind(u.Identifier))if(so.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&ro.has(t.getName()))return!0}return po(e)||fo(e)},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"&&r?.kind!=="mutation")return[];const n=ht(s);if(n===void 0)return[];const o=r.receiver!==void 0&&Et(r.receiver,"use","rls"),a=mo(n),c=new Set,l=[];for(const f of n.getDescendantsOfKind(u.CallExpression)){const $=io(f);if($===void 0)continue;const I=oo(f);if(I===void 0||c.has(I)||!uo(n,I))continue;const K=lo(n,I);K!==void 0&&(c.add(I),l.push({exportName:e.getName(),file:t,line:f.getStartLineNumber(),mentionsOwnership:a,sinkMethod:K,table:$,usesRls:o,visibility:r.visibility}))}return l},ho=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...xo(c,o))}return s},Eo=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),$o=new Set(["insert","insertManyUnsafe","patch","replace"]),yo=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!$o.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},Ao=(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},So=(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||!Eo.has(a))&&w(c)&&!O(c)&&n.push({exportName:h(s),field:a,file:r,line:s.getStartLineNumber(),method:t})}return n},No=(e,t)=>{const s=yo(e.getExpression());if(s===void 0)return[];const r=e.getArguments()[1];return r?Ao(r,s).flatMap(n=>So(n,s,e,t)):[]},bo=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression))for(const o of No(n,t)){const a=s(o.exportName);r.push(a===void 0?o:{...o,visibility:a})}return r},vo=(e,t,s=[])=>{const r=[],n=new Map(s.map(o=>[`${o.filePath}:${o.exportName}`,o.visibility]));for(const o of d(t)){const a=e.getSourceFile(o)??e.addSourceFileAtPath(o),c=p(t,o);r.push(...bo(a,c,l=>n.get(`${c}:${l}`)))}return r},Po=e=>{const t=g(e,"package.json");if(E(t))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}},wo=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Io=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Lo=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?Io(t.getInitializer()):void 0},To=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());if(n===void 0||!wo.has(n))continue;const[o]=r.getArguments(),a=o&&i.isObjectLiteralExpression(o)?Lo(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(...To(n,p(t,r)))}return s},Fo=new Set(["defineQueue","defineWorkflow"]),Do=new Set(["run","runAction","runMutation","runQuery"]),Co=new Set(["api","internal"]),ko=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},Ko=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},Pt=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},wt=(e,t)=>e===t||e.startsWith(`${t}.`),It=e=>{const t=e.getDescendantsOfKind(u.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},pt=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)},Lt=e=>{const t=e.getDescendantsOfKind(u.Identifier).filter(s=>pt(s));return i.isIdentifier(e)&&pt(e)&&t.push(e),t},Ro=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(u.BindingElement).map(s=>s.getName())},jo=e=>{const t=Pt(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},zo=(e,t,s)=>{const r=t==="workflow"?[`${s}.params`]:jo(e),n=new Set,o=a=>It(a).some(c=>r.some(l=>wt(c.getText(),l)))?!0:Lt(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 Ro(a))n.add(l)}return{names:n,prefixes:r}},Mo=(e,t)=>It(e).some(s=>t.prefixes.some(r=>wt(s.getText(),r)))?!0:Lt(e).some(s=>t.names.has(s.getText())),qo=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)||!Co.has(s.getText())||t.length<2))return{exportName:r,file:t.slice(0,-1).join("/")}},Bo=(e,t,s)=>{const r=Pt(e,0);if(r===void 0)return[];const n=zo(e,t,r),o=[];for(const a of e.getDescendantsOfKind(u.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!Do.has(c.getName())||c.getExpression().getText()!==r)continue;const l=a.getArguments()[1];if(!l||!Mo(l,n))continue;const f=qo(a.getArguments()[0]);f!==void 0&&o.push({dispatchKind:t,file:s,handlerExport:h(a),line:a.getStartLineNumber(),targetExport:f.exportName,targetFile:f.file})}return o},Vo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ko(r);if(n===void 0||!Fo.has(n))continue;const o=Ko(r);o!==void 0&&s.push(...Bo(o,n==="defineQueue"?"queue":"workflow",t))}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,p(t,r)))}return s},ft={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},Wo=/account|credential|member|passkey|session|user/iu,_o=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Go=(e,t)=>{const{objects:s,opaque:r}=At(e,t);return zr(s).some(n=>_o(n))?!0:r?void 0:!1},Ne=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},Ho=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Qo=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},Jo=e=>{const t=Qo(e),s=t?Ne(t):void 0;if(t&&s==="protectPublic"){const r=Ho(t);return{...V,usesCaptcha:r.usesCaptcha,usesRateLimit:r.usesRateLimit}}return s!==void 0&&s in ft?{...V,[ft[s]]:!0}:V},Xo=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=Jo(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},Zo=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)&&Wo.test(r.getLiteralText()))},Yo=new Set(["create","runAfter","runAt","send","sendBatch"]),ea=new Set(["queues","scheduler","workflows"]),ta=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Yo.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&ea.has(s.getName())){const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="ctx")return!0}s=s.getExpression()}return!1},sa=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"},Tt=new Set(["generateObject","generateText","streamObject","streamText"]),ra=e=>{const t=Ne(e);return t!==void 0&&Tt.has(t)},na=e=>{const t=Ne(e);if(t===void 0||!Tt.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")},ia=new Set(["log","span","trace"]),oa=new Set(["ai"]),aa=new Set(["email","mail"]),ca=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),B=(e,t)=>e.getDescendantsOfKind(u.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const r=s.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"}),ua=e=>e.getDescendantsOfKind(u.ThrowStatement).some(t=>{const s=t.getExpression();if(!i.isNewExpression(s))return!1;const r=s.getExpression();return i.isIdentifier(r)&&r.getText()==="Error"}),mt="lunora-advisor-exempt",la=/^[\s*/]+/u,da=/[\w-]/u,ga=e=>{const t=(e.getFirstAncestorByKind(u.VariableStatement)??e).getLeadingCommentRanges().map(s=>s.getText()).join(`
|
|
9
9
|
`);for(const s of t.split(`
|
|
10
|
-
`)){const r=s.replace(la,"");if(!r.startsWith(mt))continue;const n=r.slice(mt.length);if(da.test(n.charAt(0)))continue;const o=n.indexOf("--");return{exempt:!0,exemptReason:(o===-1?"":n.slice(o+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},pa=e=>{let t=!1,s=!1,r=!1,n=!1,o=!1;for(const a of e.getDescendantsOfKind(u.CallExpression))if(Zo(a)&&(o=!0),ta(a)&&(t=!0),sa(a)&&(n=!0),ra(a)&&(s=!0),na(a)&&(r=!0),o&&t&&n&&r)break;return{callsMail:B(e,aa),emitsEvent:B(e,ia),fanOut:t,handlesErrors:e.getDescendantsOfKind(u.TryStatement).length>0,reachesOutbound:B(e,ca),runsAiGeneration:s||B(e,oa),throwsBareError:ua(e),unboundedAiGeneration:r,usesInsertManyUnsafe:n,writesUserTable:o}},fa=(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?Xo(r.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1};return{...pa(e),...ga(e),...n,exportName:e.getName(),file:t,hasEmailArg:Go(s,r.receiver),kind:r.kind,visibility:r.visibility}},ma=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=fa(n,t);o&&s.push(o)}return s},xa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ma(n,p(t,r)))}return s},ha=new Set(["dbRateLimit","rateLimit"]),Ea=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},ya=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},$a=e=>i.isArrowFunction(e)?e.getBody():e,Aa=(e,t)=>{const s=S(e.getExpression());if(s===void 0||!ha.has(s))return;const r=e.getArguments()[2];if(!r)return;const n=Ea(r);if(!n)return;const o=$a(n);if(!(!w(o)||O(o)))return{callee:s,exportName:h(e),file:t,limitName:ya(e),line:e.getStartLineNumber()}},Sa=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Aa(r,t);n&&s.push(n)}return s},Na=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Sa(n,p(t,r)))}return s},ba=new Set(["findFirst","findFirstOrThrow","findMany","get"]),va=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ba.has(t.getName()))return;const s=t.getExpression();if(C(s)){const r=e.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&C(s.getExpression()))return s.getName()},Pa=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&C(s.getExpression())){const r=t.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}t=s.getExpression()}},wa=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},Ot=(e,t=!1)=>{const s=wa(e);if(i.isIdentifier(s)){if(t)return;const r=G(s);return r===void 0?void 0:Ot(r,!0)}if(i.isCallExpression(s))return va(s)??Pa(s)},Ia=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},La=(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=ht(s);if(n===void 0)return[];const o=r.receiver!==void 0&&es(r.receiver,"output"),a=r.receiver!==void 0&&Et(r.receiver,"use","mask"),c=new Set,l=[];for(const f of Ia(n)){const y=Ot(f);y===void 0||c.has(y)||(c.add(y),l.push({exportName:e.getName(),file:t,line:f.getStartLineNumber(),table:y,usesMask:a,usesOutput:o,visibility:r.visibility}))}return l},Ta=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...La(c,o))}return s},Oa=new Set(["findFirst","findFirstOrThrow","findMany"]),Fa=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Oa.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()}}},Da=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},Ca=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},ka=(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=Fa(o);if(a===void 0)continue;const c=Da(Ca(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},Ka=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...ka(c,o))}return s},_=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===u.PlusToken){const t=_(e.getLeft()),s=_(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},Ra=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&&_(t)!==void 0},ja=/(?:^|\/)__tests__\//u,za=/\.(?:spec|test)$/u,Ma=e=>ja.test(e)||za.test(e),qa=e=>{const t=e.getParent();if(t!==void 0){if(i.isVariableDeclaration(t)||i.isPropertyAssignment(t)||i.isPropertySignature(t))return t.getName();if(i.isBinaryExpression(t)&&t.getOperatorToken().getKind()===u.EqualsToken)return t.getLeft().getText()}},Ba=(e,t,s)=>Hs(e)?!Ma(s)&&Qs(qa(t)):!0,Va=(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(Ra(o))continue;const a=_(o);if(a===void 0)continue;const c=_s(a);if(c===void 0||!Ba(c,o,t))continue;const l=o.getStartLineNumber(),f=`${String(l)}:${c}`;n.has(f)||(n.add(f),s.push({file:t,kind:c,line:l,preview:Gs(a)}))}return s},Ua=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Va(n,p(t,r)))}return s},Wa=new Set(["findFirst","findFirstOrThrow","findMany"]),_a=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Wa.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()}}},Ga=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},Ha=(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=_a(o);if(a===void 0)continue;const c=Ga(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),f=!l&&w(c);!l&&!f||n.push({exportName:e.getName(),file:t,fromArgs:f,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:r.visibility})}return n},Qa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Ha(c,o))}return s},Ja=new Set(["query","unsafe"]),Xa=e=>{if(!i.isPropertyAccessExpression(e)||!Ja.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"},Za=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),Ya=e=>e.getFirstAncestorByKind(u.VariableDeclaration)?.getName()??"<module>",ec=(e,t)=>{if(!Xa(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Za(s)))return{exportName:Ya(e),file:t,line:s.getStartLineNumber()}},tc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ec(r,t);n&&s.push(n)}return s},sc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...tc(n,p(t,r)))}return s},rc=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),nc=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.storage"||s.startsWith("ctx.storage."),methods:rc}),ic=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),oc=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,ac=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=oc(n.getInitializer()));continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,expiresInSeconds:s,presentKeys:t}},cc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=ic.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},uc=(e,t)=>{const s=cc(e.getExpression());if(s!==void 0)return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s.method,...ac(e.getArguments()[s.optionsIndex])}},lc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=uc(r,t);n&&s.push(n)}return s},dc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...lc(n,p(t,r)))}return s},gc=new Set(["RegisteredAction","RegisteredMutation","RegisteredQuery"]),be=e=>{const t=e.getType(),s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName();return s!==void 0&&gc.has(s)?s:void 0},Ft=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},Dt={cause:"codegen recognises a procedure only when the initializer is a builder chain, and this one is produced by a call or an alias",remediation:"A factory that returns a procedure cannot be read statically — inline it, or export the chain the factory builds."},pc={cause:"the binding is exported by a separate `export { … }` statement, and codegen reads the `export` keyword on the declaration itself",remediation:"Move the keyword onto the declaration and drop the separate export statement."},ve=(e,t,s,r,n)=>({cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally a builder chain. A procedure written any other way exists at runtime but never reaches `_generated/api.ts`, so no caller can address it.",detail:`\`${t}\` in \`${e}\` (line ${r.toString()}) has type \`${s}\` but was not registered — ${n.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:r,typeName:s},name:"procedure_not_registered",remediation:`Assign the builder chain directly: \`export const ${t} = query.input({ … }).query(handler);\`. ${n.remediation}`,title:"Procedure exists at runtime but is missing from the generated API"}),fc=(e,t,s)=>{const r=[];for(const n of e.getVariableStatements().filter(o=>o.isExported()))for(const o of n.getDeclarations()){const a=o.getName();if(s.has(`${t}:${a}`)||!Ft(o))continue;const c=be(o);c!==void 0&&r.push(ve(t,a,c,o.getStartLineNumber(),Dt))}return r},mc=(e,t,s)=>{if(s.has(`${t}:default`))return[];const r=[];for(const n of e.getExportAssignments().filter(o=>!o.isExportEquals())){const o=be(n.getExpression());o!==void 0&&r.push(ve(t,"default",o,n.getStartLineNumber(),Dt))}return r},xc=(e,t,s)=>{const r=[];for(const n of e.getExportDeclarations().filter(o=>o.getModuleSpecifier()===void 0))for(const o of n.getNamedExports()){const a=o.getAliasNode()?.getText()??o.getName();if(s.has(`${t}:${a}`))continue;const c=o.getLocalTargetDeclarations().find(f=>i.isVariableDeclaration(f));if(c===void 0||!Ft(c))continue;const l=be(c);l!==void 0&&r.push(ve(t,a,l,o.getStartLineNumber(),pc))}return r},hc=(e,t,s)=>[...fc(e,t,s),...mc(e,t,s),...xc(e,t,s)],Ec=(e,t,s)=>{const r=new Set(s.map(o=>`${o.filePath}:${o.exportName}`)),n=[];for(const o of d(t)){const a=e.getSourceFile(o);a!==void 0&&n.push(...hc(a,p(t,o),r))}return n.toSorted((o,a)=>o.cacheKey.localeCompare(a.cacheKey))},yc=new Set(["when","where"]),Ee=new Set(["definePolicy","defineShape"]),$c=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const r=t.getName();return Ee.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 Ee.has(n)?n:void 0}const s=t.getText();return Ee.has(s)?s:void 0},Ac=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,Ct=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===u.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Ac(e))return"empty-object";if(i.isParenthesizedExpression(e))return Ct(e.getExpression())}},kt=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Kt=e=>e.getDescendantsOfKind(u.ReturnStatement).filter(t=>kt(t)===e),Rt=e=>e.getDescendantsOfKind(u.ConditionalExpression).filter(t=>kt(t)===e),Sc=e=>{const t=Kt(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(u.IfStatement)!==void 0)||Rt(e).length>0},Nc=e=>{const t=[],s=e.getBody();i.isBlock(s)||t.push(s);for(const r of Kt(e)){const n=i.isReturnStatement(r)?r.getExpression():void 0;t.push(n??r)}for(const r of Rt(e))t.push(r.getWhenTrue(),r.getWhenFalse());return t},bc=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},vc=(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)||!yc.has(o.getName()))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Sc(a))for(const c of Nc(a)){const l=Ct(c);l!==void 0&&n.push({exportName:bc(e),file:s,form:l,key:o.getName(),line:c.getStartLineNumber(),owner:t})}}return n},Pc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=$c(r);n!==void 0&&s.push(...vc(r,n,t))}return s},wc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Pc(n,p(t,r)))}return s},Ic=new Set(["query","upsert","upsertMany"]),Lc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(Ic.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Tc=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("namespace");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Oc=(e,t)=>{const s=Lc(e.getExpression());if(s===void 0)return;const r=e.getArguments()[1];if(!r)return;const n=Tc(r);if(!(!n||!w(n)||O(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Fc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Oc(r,t);n&&s.push(n)}return s},Dc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Fc(n,p(t,r)))}return s},Cc=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"},kc=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Kc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){if(!Cc(a))continue;const c=Zs(a);c!==""&&s.push({exportName:c,file:o,line:a.getStartLineNumber(),workflow:kc(a)})}}return s},Rc=".lunora-schema.json",A=(e,t)=>{E(e)&&$e(e,"utf8")===t||Ht(e,t,"utf8")},P=(e,t)=>{if(t===""){Qt(e,{force:!0});return}A(e,t)},jc=e=>{const t=g(e,"package.json");if(E(t))try{const s=JSON.parse($e(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},zc=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Mc=e=>{let t=E(e)?e:fe(e);for(;t&&t!==fe(t);){const s=g(t,"tsconfig.json");if(E(s))return s;t=fe(t)}},xt=e=>e.replaceAll("\\","/"),qc=(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 R("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 R("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 R("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})}},Bc=e=>{const t=Mc(e);return t?new tt({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new tt({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Tu=(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=>xt(c))),o=xt(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!n.has(l)&&e.removeSourceFile(c)}},Ou=e=>{const t=zc(),s=t?me.now():0,r=g(e.projectRoot,e.lunoraDirectory??"lunora"),n=g(r,"schema.ts");if(!E(n))throw new R("INTERNAL",`schema.ts not found at ${n}`);const o=e.project??Bc(r);ir(ss);const a=Ws(o,n,e.projectRoot),c=ts(o,r),l=Is(o,r),f=Ds(o,r),y=Js(o,r),I=Ks(o,r),K=Li(o,r),Pe=Cn(o,r),b=Ys(o,r),F=Ms(o,r),v=rs(o,r);qc(b,v);const X=ls(o,r,b,v),D=us(o,r),j=e.lint===!1?void 0:Zt({adminRoutes:Er(o,r),aiRawRuns:Sr(o,r),aiToolSideEffects:Fr(o,r),argumentDerivedFetches:Kr(o,r),argumentValidators:Hr(o,r),authApiCalls:cs(o,r),authConfigs:on(o,r),browserUrlAccesses:dn(o,r),configCalls:yn(o,r),containerKeyAccesses:An(o,r),containerOverrides:In(o,r),containers:D,exportSinks:jn(o,r),failOpenGuards:Wn(o,r),flagSecurityDefaults:ri(o,r),geoIndexUsages:oi(o,r),httpActionGuards:fi(o,r),httpHeaderWrites:bi(o,r),identityClaimReads:Ki(o,r),imageDeliveryUrlAccesses:Mi(o,r),inserts:Ls(o,r),kvKeyAccesses:Bi(o,r),mailRecipientAccesses:Hi(o,r),maskProcedures:Ts(o,r),maskStrategies:Os(o,r),mutatorWrites:eo(o,r),nondeterministicCalls:Rs(o,r),normalizeIdAuthorizations:ho(o,r),notifyCalls:zs(o,r),notifyConfig:js(o,r),ownerFieldWrites:vo(o,r,c),unrestrictedWhereBranches:wc(o,r),paymentWebhooks:Oo(o,r),privilegedDispatches:Uo(o,r),procedureProtections:xa(o,r),queries:as(o,r),queues:F,r2sqlCalls:qs(o,r),ratelimitKeySelectors:Na(o,r),rawRowReturns:Ta(o,r),relationLoads:Ka(o,r),rlsProcedures:Bs(o,r),schema:a,secretLiterals:Ua(o,r),shapes:y,softDeleteReads:Qa(o,r),sqlInterpolations:sc(o,r),storageKeyAccesses:nc(o,r),storageUploads:dc(o,r),vectorNamespaceAccesses:Dc(o,r),workflowCalls:Kc(o,r),workflows:b,wranglerVariables:e.wranglerVariables}),we=j===void 0?[]:[...Jt(j,{source:"static"}),...Ec(o,r,c)],jt=Vs(o,r),zt=Fs(o,r),Z=Xs(o,r),Mt=Gn(o,r),Ie=or(Mt,ar(e.projectRoot,e.target)),$=Ie.usage,Y=$.ai,ee=$.payments,Le=$.kv,Te=$.access,te=E(g(r,"flags.ts")),qt=te?ws(o,r):[],se=E(g(r,"notify.ts")),re=$.hyperdrive,ne=Us(o,r),Bt=ne.usesSandboxBrowser||ne.usesSandboxContainer,ie=$.browser||ne.usesSandboxBrowser,oe=$.images,ae=$.analytics,Oe=$.pipelines,ce=$.r2sql,ue=$.x402,Fe=Po(e.projectRoot),L=Fe??new Set,z=Xn($,{containerCount:D.length,cronCount:X.length,dependencies:L,hasPaymentTables:Jn(a.tables),queueCount:F.length,storageColumnCount:Object.keys(ds(a)).length,storageRuleCount:Z.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:b.length}),T=L.has("lunorash");lr(a,Fe);const De=t?me.now():0,Ce=gs(a,T),ke=ps({agents:v,functions:c,httpRoutes:l,mutators:I,useUmbrella:T,workflows:b}),Ke=fs({agents:v,containers:D,env:Pe,hasAccessFacade:Te,hasAi:Y,hasAnalytics:ae,hasBrowser:ie,hasFlags:te,hasHyperdrive:re,hasImages:oe,hasKv:Le,hasNotify:se,hasPayments:ee,hasPipelines:Oe,hasR2sql:ce,hasX402:ue,identity:K,queues:F,schema:a,storageRuleBuckets:Z.rules.map(m=>m.bucket),useUmbrella:T,workflows:b}),Re=ms({agents:v,functions:c,migrations:f,mutators:I,shapes:y,useUmbrella:T,usesSandbox:Bt}),le=cr(a,f.map(m=>m.id)),je=xs({advisories:we,advisorProcedures:j?.procedureProtections??[],agents:v,containers:D,env:Pe,flagKeys:qt,hasAccessFacade:Te,hasAi:Y,hasAnalytics:ae,hasBrowser:ie,hasFlags:te,hasHyperdrive:re,hasImages:oe,hasKv:Le,hasNotify:se,hasPayments:ee,hasPipelines:Oe,hasR2sql:ce,hasX402:ue,maskMetadata:zt,mutators:I,queues:F,rlsMetadata:jt,schema:a,schemaSnapshot:le,shapes:y,storageRules:Z,studioFeatures:z,useUmbrella:T,workflows:b}),ze=hs(y,L.has("@lunora/db"),T),Me=Es(D,a.jurisdiction),qe=ys(b),Be=$s(v),Ve=As(F),Ue=Ss(X),We=Ns(a.vectorIndexes),M=bs(a,T),_e=vs(L.has("@lunora/seed")),q=e.apiSpec??"openapi",de=q==="openapi"||q==="both",ge=q==="openrpc"||q==="both",Ge=er({emailAgents:v.filter(m=>m.onEmail===!0).map(m=>({bindingName:m.bindingName,exportName:m.exportName})),hasAccess:L.has("@lunora/cloudflare-access"),hasAi:Y,hasAnalytics:ae,hasAuth:L.has("@lunora/auth"),hasBrowser:ie,hasFramework:L.has("@lunora/astro")||L.has("@lunora/svelte")||L.has("@lunora/vue"),hasGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend!=="hyperdrive"),hasHyperdrive:re,hasHyperdriveGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend==="hyperdrive"),hasImages:oe,hasKv:z.kv,hasNotify:se,hasPayments:ee,hasR2sql:ce,hasQueue:F.some(m=>m.mode==="push"),hasScheduler:z.scheduler,hasStorage:z.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:b.length>0,hasX402:ue,identity:K,jurisdiction:a.jurisdiction,useUmbrella:T,voiceAgents:v.filter(m=>m.voice===!0&&m.voiceBindingName!==void 0).map(m=>({bindingName:m.voiceBindingName,exportName:m.exportName})),wantsOpenApi:de,wantsOpenRpc:ge}),He=jc(e.projectRoot),Qe=tr({functions:c,httpRoutes:l,version:He}),Je=rr({functions:c,version:He}),Xe=`${JSON.stringify(Qe,void 0,2)}
|
|
10
|
+
`)){const r=s.replace(la,"");if(!r.startsWith(mt))continue;const n=r.slice(mt.length);if(da.test(n.charAt(0)))continue;const o=n.indexOf("--");return{exempt:!0,exemptReason:(o===-1?"":n.slice(o+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},pa=e=>{let t=!1,s=!1,r=!1,n=!1,o=!1;for(const a of e.getDescendantsOfKind(u.CallExpression))if(Zo(a)&&(o=!0),ta(a)&&(t=!0),sa(a)&&(n=!0),ra(a)&&(s=!0),na(a)&&(r=!0),o&&t&&n&&r)break;return{callsMail:B(e,aa),emitsEvent:B(e,ia),fanOut:t,handlesErrors:e.getDescendantsOfKind(u.TryStatement).length>0,reachesOutbound:B(e,ca),runsAiGeneration:s||B(e,oa),throwsBareError:ua(e),unboundedAiGeneration:r,usesInsertManyUnsafe:n,writesUserTable:o}},fa=(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?Xo(r.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1};return{...pa(e),...ga(e),...n,exportName:e.getName(),file:t,hasEmailArg:Go(s,r.receiver),kind:r.kind,visibility:r.visibility}},ma=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=fa(n,t);o&&s.push(o)}return s},xa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ma(n,p(t,r)))}return s},ha=new Set(["dbRateLimit","rateLimit"]),Ea=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},$a=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},ya=e=>i.isArrowFunction(e)?e.getBody():e,Aa=(e,t)=>{const s=S(e.getExpression());if(s===void 0||!ha.has(s))return;const r=e.getArguments()[2];if(!r)return;const n=Ea(r);if(!n)return;const o=ya(n);if(!(!w(o)||O(o)))return{callee:s,exportName:h(e),file:t,limitName:$a(e),line:e.getStartLineNumber()}},Sa=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Aa(r,t);n&&s.push(n)}return s},Na=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Sa(n,p(t,r)))}return s},ba=new Set(["findFirst","findFirstOrThrow","findMany","get"]),va=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ba.has(t.getName()))return;const s=t.getExpression();if(C(s)){const r=e.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&C(s.getExpression()))return s.getName()},Pa=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&C(s.getExpression())){const r=t.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}t=s.getExpression()}},wa=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},Ot=(e,t=!1)=>{const s=wa(e);if(i.isIdentifier(s)){if(t)return;const r=G(s);return r===void 0?void 0:Ot(r,!0)}if(i.isCallExpression(s))return va(s)??Pa(s)},Ia=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},La=(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=ht(s);if(n===void 0)return[];const o=r.receiver!==void 0&&es(r.receiver,"output"),a=r.receiver!==void 0&&Et(r.receiver,"use","mask"),c=new Set,l=[];for(const f of Ia(n)){const $=Ot(f);$===void 0||c.has($)||(c.add($),l.push({exportName:e.getName(),file:t,line:f.getStartLineNumber(),table:$,usesMask:a,usesOutput:o,visibility:r.visibility}))}return l},Ta=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...La(c,o))}return s},Oa=new Set(["findFirst","findFirstOrThrow","findMany"]),Fa=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Oa.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()}}},Da=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},Ca=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},ka=(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=Fa(o);if(a===void 0)continue;const c=Da(Ca(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},Ka=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...ka(c,o))}return s},_=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===u.PlusToken){const t=_(e.getLeft()),s=_(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},Ra=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&&_(t)!==void 0},ja=/(?:^|\/)__tests__\//u,za=/\.(?:spec|test)$/u,Ma=e=>ja.test(e)||za.test(e),qa=e=>{const t=e.getParent();if(t!==void 0){if(i.isVariableDeclaration(t)||i.isPropertyAssignment(t)||i.isPropertySignature(t))return t.getName();if(i.isBinaryExpression(t)&&t.getOperatorToken().getKind()===u.EqualsToken)return t.getLeft().getText()}},Ba=(e,t,s)=>Hs(e)?!Ma(s)&&Qs(qa(t)):!0,Va=(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(Ra(o))continue;const a=_(o);if(a===void 0)continue;const c=_s(a);if(c===void 0||!Ba(c,o,t))continue;const l=o.getStartLineNumber(),f=`${String(l)}:${c}`;n.has(f)||(n.add(f),s.push({file:t,kind:c,line:l,preview:Gs(a)}))}return s},Ua=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Va(n,p(t,r)))}return s},Wa=new Set(["findFirst","findFirstOrThrow","findMany"]),_a=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Wa.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()}}},Ga=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},Ha=(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=_a(o);if(a===void 0)continue;const c=Ga(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),f=!l&&w(c);!l&&!f||n.push({exportName:e.getName(),file:t,fromArgs:f,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:r.visibility})}return n},Qa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Ha(c,o))}return s},Ja=new Set(["query","unsafe"]),Xa=e=>{if(!i.isPropertyAccessExpression(e)||!Ja.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"},Za=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),Ya=e=>e.getFirstAncestorByKind(u.VariableDeclaration)?.getName()??"<module>",ec=(e,t)=>{if(!Xa(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Za(s)))return{exportName:Ya(e),file:t,line:s.getStartLineNumber()}},tc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ec(r,t);n&&s.push(n)}return s},sc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...tc(n,p(t,r)))}return s},rc=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),nc=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.storage"||s.startsWith("ctx.storage."),methods:rc}),ic=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),oc=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,ac=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=oc(n.getInitializer()));continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,expiresInSeconds:s,presentKeys:t}},cc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=ic.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},uc=(e,t)=>{const s=cc(e.getExpression());if(s!==void 0)return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s.method,...ac(e.getArguments()[s.optionsIndex])}},lc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=uc(r,t);n&&s.push(n)}return s},dc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...lc(n,p(t,r)))}return s},gc=new Set(["RegisteredAction","RegisteredMutation","RegisteredQuery"]),be=e=>{const t=e.getType(),s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName();return s!==void 0&&gc.has(s)?s:void 0},Ft=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},Dt={cause:"codegen recognises a procedure only when the initializer is a builder chain, and this one is produced by a call or an alias",remediation:"A factory that returns a procedure cannot be read statically — inline it, or export the chain the factory builds."},pc={cause:"the binding is exported by a separate `export { … }` statement, and codegen reads the `export` keyword on the declaration itself",remediation:"Move the keyword onto the declaration and drop the separate export statement."},ve=(e,t,s,r,n)=>({cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally a builder chain. A procedure written any other way exists at runtime but never reaches `_generated/api.ts`, so no caller can address it.",detail:`\`${t}\` in \`${e}\` (line ${r.toString()}) has type \`${s}\` but was not registered — ${n.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:r,typeName:s},name:"procedure_not_registered",remediation:`Assign the builder chain directly: \`export const ${t} = query.input({ … }).query(handler);\`. ${n.remediation}`,title:"Procedure exists at runtime but is missing from the generated API"}),fc=(e,t,s)=>{const r=[];for(const n of e.getVariableStatements().filter(o=>o.isExported()))for(const o of n.getDeclarations()){const a=o.getName();if(s.has(`${t}:${a}`)||!Ft(o))continue;const c=be(o);c!==void 0&&r.push(ve(t,a,c,o.getStartLineNumber(),Dt))}return r},mc=(e,t,s)=>{if(s.has(`${t}:default`))return[];const r=[];for(const n of e.getExportAssignments().filter(o=>!o.isExportEquals())){const o=be(n.getExpression());o!==void 0&&r.push(ve(t,"default",o,n.getStartLineNumber(),Dt))}return r},xc=(e,t,s)=>{const r=[];for(const n of e.getExportDeclarations().filter(o=>o.getModuleSpecifier()===void 0))for(const o of n.getNamedExports()){const a=o.getAliasNode()?.getText()??o.getName();if(s.has(`${t}:${a}`))continue;const c=o.getLocalTargetDeclarations().find(f=>i.isVariableDeclaration(f));if(c===void 0||!Ft(c))continue;const l=be(c);l!==void 0&&r.push(ve(t,a,l,o.getStartLineNumber(),pc))}return r},hc=(e,t,s)=>[...fc(e,t,s),...mc(e,t,s),...xc(e,t,s)],Ec=(e,t,s)=>{const r=new Set(s.map(o=>`${o.filePath}:${o.exportName}`)),n=[];for(const o of d(t)){const a=e.getSourceFile(o);a!==void 0&&n.push(...hc(a,p(t,o),r))}return n.toSorted((o,a)=>o.cacheKey.localeCompare(a.cacheKey))},$c=new Set(["when","where"]),Ee=new Set(["definePolicy","defineShape"]),yc=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const r=t.getName();return Ee.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 Ee.has(n)?n:void 0}const s=t.getText();return Ee.has(s)?s:void 0},Ac=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,Ct=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===u.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Ac(e))return"empty-object";if(i.isParenthesizedExpression(e))return Ct(e.getExpression())}},kt=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Kt=e=>e.getDescendantsOfKind(u.ReturnStatement).filter(t=>kt(t)===e),Rt=e=>e.getDescendantsOfKind(u.ConditionalExpression).filter(t=>kt(t)===e),Sc=e=>{const t=Kt(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(u.IfStatement)!==void 0)||Rt(e).length>0},Nc=e=>{const t=[],s=e.getBody();i.isBlock(s)||t.push(s);for(const r of Kt(e)){const n=i.isReturnStatement(r)?r.getExpression():void 0;t.push(n??r)}for(const r of Rt(e))t.push(r.getWhenTrue(),r.getWhenFalse());return t},bc=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},vc=(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)||!$c.has(o.getName()))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Sc(a))for(const c of Nc(a)){const l=Ct(c);l!==void 0&&n.push({exportName:bc(e),file:s,form:l,key:o.getName(),line:c.getStartLineNumber(),owner:t})}}return n},Pc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=yc(r);n!==void 0&&s.push(...vc(r,n,t))}return s},wc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Pc(n,p(t,r)))}return s},Ic=new Set(["query","upsert","upsertMany"]),Lc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(Ic.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Tc=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("namespace");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Oc=(e,t)=>{const s=Lc(e.getExpression());if(s===void 0)return;const r=e.getArguments()[1];if(!r)return;const n=Tc(r);if(!(!n||!w(n)||O(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Fc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Oc(r,t);n&&s.push(n)}return s},Dc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Fc(n,p(t,r)))}return s},Cc=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"},kc=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Kc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){if(!Cc(a))continue;const c=Zs(a);c!==""&&s.push({exportName:c,file:o,line:a.getStartLineNumber(),workflow:kc(a)})}}return s},Rc=".lunora-schema.json",A=(e,t)=>{E(e)&&ye(e,"utf8")===t||Ht(e,t,"utf8")},P=(e,t)=>{if(t===""){Qt(e,{force:!0});return}A(e,t)},jc=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}},zc=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Mc=e=>{let t=E(e)?e:fe(e);for(;t&&t!==fe(t);){const s=g(t,"tsconfig.json");if(E(s))return s;t=fe(t)}},xt=e=>e.replaceAll("\\","/"),qc=(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 R("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 R("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 R("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})}},Bc=e=>{const t=Mc(e);return t?new tt({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new tt({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Tu=(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=>xt(c))),o=xt(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!n.has(l)&&e.removeSourceFile(c)}},Ou=e=>{const t=zc(),s=t?me.now():0,r=g(e.projectRoot,e.lunoraDirectory??"lunora"),n=g(r,"schema.ts");if(!E(n))throw new R("INTERNAL",`schema.ts not found at ${n}`);const o=e.project??Bc(r);ir(ss);const a=Ws(o,n,e.projectRoot),c=ts(o,r),l=Is(o,r),f=Ds(o,r),$=Js(o,r),I=Ks(o,r),K=Li(o,r),Pe=Cn(o,r),b=Ys(o,r),F=Ms(o,r),v=rs(o,r);qc(b,v);const X=ls(o,r,b,v),D=us(o,r),j=e.lint===!1?void 0:Zt({adminRoutes:Er(o,r),aiRawRuns:Sr(o,r),aiToolSideEffects:Fr(o,r),argumentDerivedFetches:Kr(o,r),argumentValidators:Hr(o,r),authApiCalls:cs(o,r),authConfigs:on(o,r),browserUrlAccesses:dn(o,r),configCalls:$n(o,r),containerKeyAccesses:An(o,r),containerOverrides:In(o,r),containers:D,exportSinks:jn(o,r),failOpenGuards:Wn(o,r),flagSecurityDefaults:ri(o,r),geoIndexUsages:oi(o,r),httpActionGuards:fi(o,r),httpHeaderWrites:bi(o,r),identityClaimReads:Ki(o,r),imageDeliveryUrlAccesses:Mi(o,r),inserts:Ls(o,r),kvKeyAccesses:Bi(o,r),mailRecipientAccesses:Hi(o,r),maskProcedures:Ts(o,r),maskStrategies:Os(o,r),mutatorWrites:eo(o,r),nondeterministicCalls:Rs(o,r),normalizeIdAuthorizations:ho(o,r),notifyCalls:zs(o,r),notifyConfig:js(o,r),ownerFieldWrites:vo(o,r,c),unrestrictedWhereBranches:wc(o,r),paymentWebhooks:Oo(o,r),privilegedDispatches:Uo(o,r),procedureProtections:xa(o,r),queries:as(o,r),queues:F,r2sqlCalls:qs(o,r),ratelimitKeySelectors:Na(o,r),rawRowReturns:Ta(o,r),relationLoads:Ka(o,r),rlsProcedures:Bs(o,r),schema:a,secretLiterals:Ua(o,r),shapes:$,softDeleteReads:Qa(o,r),sqlInterpolations:sc(o,r),storageKeyAccesses:nc(o,r),storageUploads:dc(o,r),vectorNamespaceAccesses:Dc(o,r),workflowCalls:Kc(o,r),workflows:b,wranglerVariables:e.wranglerVariables}),we=j===void 0?[]:[...Jt(j,{source:"static"}),...Ec(o,r,c)],jt=Vs(o,r),zt=Fs(o,r),Z=Xs(o,r),Mt=Gn(o,r),Ie=or(Mt,ar(e.projectRoot,e.target)),y=Ie.usage,Y=y.ai,ee=y.payments,Le=y.kv,Te=y.access,te=E(g(r,"flags.ts")),qt=te?ws(o,r):[],se=E(g(r,"notify.ts")),re=y.hyperdrive,ne=Us(o,r),Bt=ne.usesSandboxBrowser||ne.usesSandboxContainer,ie=y.browser||ne.usesSandboxBrowser,oe=y.images,ae=y.analytics,Oe=y.pipelines,ce=y.r2sql,ue=y.x402,Fe=Po(e.projectRoot),L=Fe??new Set,z=Xn(y,{containerCount:D.length,cronCount:X.length,dependencies:L,hasPaymentTables:Jn(a.tables),queueCount:F.length,storageColumnCount:Object.keys(ds(a)).length,storageRuleCount:Z.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:b.length}),T=L.has("lunorash");lr(a,Fe);const De=t?me.now():0,Ce=gs(a,T),ke=ps({agents:v,functions:c,httpRoutes:l,mutators:I,useUmbrella:T,workflows:b}),Ke=fs({agents:v,containers:D,env:Pe,hasAccessFacade:Te,hasAi:Y,hasAnalytics:ae,hasBrowser:ie,hasFlags:te,hasHyperdrive:re,hasImages:oe,hasKv:Le,hasNotify:se,hasPayments:ee,hasPipelines:Oe,hasR2sql:ce,hasX402:ue,identity:K,queues:F,schema:a,storageRuleBuckets:Z.rules.map(m=>m.bucket),useUmbrella:T,workflows:b}),Re=ms({agents:v,functions:c,migrations:f,mutators:I,shapes:$,useUmbrella:T,usesSandbox:Bt}),le=cr(a,f.map(m=>m.id)),je=xs({advisories:we,advisorProcedures:j?.procedureProtections??[],agents:v,containers:D,env:Pe,flagKeys:qt,hasAccessFacade:Te,hasAi:Y,hasAnalytics:ae,hasBrowser:ie,hasFlags:te,hasHyperdrive:re,hasImages:oe,hasKv:Le,hasNotify:se,hasPayments:ee,hasPipelines:Oe,hasR2sql:ce,hasX402:ue,maskMetadata:zt,mutators:I,queues:F,rlsMetadata:jt,schema:a,schemaSnapshot:le,shapes:$,storageRules:Z,studioFeatures:z,useUmbrella:T,workflows:b}),ze=hs($,L.has("@lunora/db"),T),Me=Es(D,a.jurisdiction),qe=$s(b),Be=ys(v),Ve=As(F),Ue=Ss(X),We=Ns(a.vectorIndexes),M=bs(a,T),_e=vs(L.has("@lunora/seed")),q=e.apiSpec??"openapi",de=q==="openapi"||q==="both",ge=q==="openrpc"||q==="both",Ge=er({emailAgents:v.filter(m=>m.onEmail===!0).map(m=>({bindingName:m.bindingName,exportName:m.exportName})),hasAccess:L.has("@lunora/cloudflare-access"),hasAi:Y,hasAnalytics:ae,hasAuth:L.has("@lunora/auth"),hasBrowser:ie,hasFramework:L.has("@lunora/astro")||L.has("@lunora/svelte")||L.has("@lunora/vue"),hasGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend!=="hyperdrive"),hasHyperdrive:re,hasHyperdriveGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend==="hyperdrive"),hasImages:oe,hasKv:z.kv,hasNotify:se,hasPayments:ee,hasR2sql:ce,hasQueue:F.some(m=>m.mode==="push"),hasScheduler:z.scheduler,hasStorage:z.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:b.length>0,hasX402:ue,identity:K,jurisdiction:a.jurisdiction,useUmbrella:T,voiceAgents:v.filter(m=>m.voice===!0&&m.voiceBindingName!==void 0).map(m=>({bindingName:m.voiceBindingName,exportName:m.exportName})),wantsOpenApi:de,wantsOpenRpc:ge}),He=jc(e.projectRoot),Qe=tr({functions:c,httpRoutes:l,version:He}),Je=rr({functions:c,version:He}),Xe=`${JSON.stringify(Qe,void 0,2)}
|
|
11
11
|
`,Ze=`${JSON.stringify(Je,void 0,2)}
|
|
12
12
|
`,Ye=sr(Qe),et=nr(Je),pe=g(r,Rc),Vt=E(pe),x=g(r,"_generated");if(e.dryRun||(E(x)||Gt(x,{recursive:!0}),A(g(x,"app.ts"),Ge),A(g(x,"dataModel.ts"),Ce),A(g(x,"api.ts"),ke),A(g(x,"server.ts"),Ke),A(g(x,"functions.ts"),Re),A(g(x,"shard.ts"),je),A(g(x,"crons.ts"),Ue),A(g(x,"vectors.ts"),We),A(g(x,"drizzle.global.ts"),M.global),A(g(x,"drizzle.shard.ts"),M.shard),P(g(x,"containers.ts"),Me),P(g(x,"workflows.ts"),qe),P(g(x,"agents.ts"),Be),P(g(x,"queues.ts"),Ve),P(g(x,"seed.ts"),_e),P(g(x,"collections.ts"),ze),P(g(x,"openapi.json"),de?Xe:""),P(g(x,"openapi.ts"),de?Ye:""),P(g(x,"openrpc.json"),ge?Ze:""),P(g(x,"openrpc.ts"),ge?et:""),(!Vt||e.updateSchemaBaseline===!0)&&A(pe,Xt(le))),t){const m=me.now(),Ut=Math.round(m-s),Wt=Math.round(De-s),_t=Math.round(m-De);console.error(`@lunora/codegen: codegen took ${Ut.toString()}ms (discovery ${Wt.toString()}ms, emit ${_t.toString()}ms)`)}return{advisories:we,advisorContext:j,agents:v,containers:D,cronTriggers:Ps(X),generated:{agents:Be,api:ke,app:Ge,collections:ze,containers:Me,crons:Ue,dataModel:Ce,drizzleGlobal:M.global,drizzleShard:M.shard,functions:Re,openApi:Xe,openApiModule:Ye,openRpc:Ze,openRpcModule:et,queues:Ve,seed:_e,server:Ke,shard:je,vectors:We,workflows:qe},outputDirectory:x,platformDiagnostics:Ie.diagnostics,queues:F,schemaSnapshot:le,schemaSnapshotPath:pe,workflows:b}};export{Rc as SCHEMA_SNAPSHOT_FILENAME,Bc as createCodegenProject,Tu as refreshCodegenProject,Ou as runCodegen};
|
package/dist/packem_shared/{buildOpenApiDocument-CfLCgKoc.mjs → buildOpenApiDocument-D46nZ7D_.mjs}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{R as v}from"./emit-CCw5fiXq.mjs";import{n as c}from"./paths-BmX5O1sG.mjs";import{LUNORA_ERROR_CODES as S,objectSchema as b,argsObjectSchema as g,validatorIrToJsonSchema as u}from"./LUNORA_ERROR_CODES-Um9hC1gr.mjs";const O="/_lunora/rest",x=["authorization","cf-access-jwt-assertion","cookie"],h=["x-d1-bookmark","x-lunora-shard-key"],P=e=>[...x,...(e.credentialHeaders??[]).map(t=>t.toLowerCase())],m=e=>Number.isFinite(e)?Math.max(0,Math.floor(e)):0,f=(...e)=>{const t=[];for(const r of e)for(const o of r?.split(",")??[]){const n=o.trim().toLowerCase();n!==""&&!t.includes(n)&&t.push(n)}return t.length===0?void 0:t.join(", ")},T=(e,t)=>{const r=[t,`max-age=${String(m(e.maxAge))}`];return e.staleWhileRevalidate!==void 0&&r.push(`stale-while-revalidate=${String(m(e.staleWhileRevalidate))}`),r.join(", ")},k=e=>e.scope==="public"?f(e.vary,...P(e),...h):f(e.vary,...h),R=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)}},j=e=>{const t=R(e);if(t!==void 0)return`${O}/${t.namespace}/${t.name}`},q=e=>e==="query"?"GET":"POST",l="#/components/responses/LunoraError",y=/:([A-Za-z_$][\w$]*)/gu,A=e=>[...e.matchAll(y)].map(t=>t[1]),N=e=>e.replaceAll(y,"{$1}"),w=e=>{const t=new Set(A(e.path)),r=[];for(const[o,n]of Object.entries(e.searchParams)){const p=n.kind==="optional"?n.inner??n:n;r.push({description:`Query parameter \`${o}\``,in:"query",name:o,required:n.kind!=="optional",schema:u(p)})}for(const[o,n]of Object.entries(e.params)){const p=n.kind==="optional"?n.inner??n:n;r.push({description:`Path parameter \`${o}\``,in:t.has(o)?"path":"query",name:o,required:t.has(o)?!0:n.kind!=="optional",schema:u(p)})}return r},C=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."},E=e=>{const t=c(e.filePath),r=w(e),o={description:`${e.stream?"Streaming (SSE) ":""}HTTP route handler \`${e.exportName}\` (${e.method} ${e.path}).`,operationId:`${e.method.toLowerCase()}_${c(e.path)}`,responses:{200:C(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:l}},summary:`${e.method} ${e.path}`,tags:[t]};return r.length>0&&(o.parameters=r),Object.keys(e.body).length>0&&(o.requestBody={content:{"application/json":{schema:b(e.body)}},required:!0}),e.stream&&(o["x-lunora-stream"]="text/event-stream"),o},L=e=>{const t=`${c(e.filePath)}:${e.exportName}`,r=c(e.filePath),o={additionalProperties:!1,properties:{args:g(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:[r],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${t}`}},_=(e,t)=>{if(e===void 0||t!=="get"||e.scope===void 0||e.maxAge===void 0)return{};const r={maxAge:e.maxAge,scope:e.scope,...e.staleWhileRevalidate===void 0?{}:{staleWhileRevalidate:e.staleWhileRevalidate},...e.tag===void 0?{}:{tag:e.tag},...e.vary===void 0?{}:{vary:e.vary}},o={"Cache-Control":{description:r.scope==="public"?"Caching policy. `public` applies only to an uncredentialed request — a request carrying `Authorization` or `Cookie` is always answered `private`.":"Caching policy. Restricted to the caller's own cache; never stored by a shared/edge cache.",schema:{example:T(r,r.scope),type:"string"}}};r.tag!==void 0&&(o["Cache-Tag"]={description:"Purge tag for `ctx.cache.purge({ tags: [...] })`.",schema:{example:r.tag,type:"string"}});const n=k(r);return n!==void 0&&(o.Vary={description:"Request headers this response varies by. The endpoint's own negotiated headers are merged in at runtime.",schema:{example:n,type:"string"}}),{headers:o}},I=e=>{const t=`${c(e.filePath)}:${e.exportName}`,r=j(t);if(r===void 0)return;const o=c(e.filePath),n=q(e.kind),p=n==="GET",a={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_${c(r)}`,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).",..._(e.expose?.cache,p?"get":"post")},default:{$ref:l}},summary:`${n} ${r}`,tags:[o],"x-lunora-function-kind":e.kind};if(p){const s=Object.entries(e.args).map(([i,d])=>{const $=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($)}});return s.length>0&&(a.parameters=s),{method:"get",operation:a,path:r}}return a.requestBody={content:{"application/json":{schema:g(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:a,path:r}},D=e=>{const t=e.version??"0.0.0",r={},o=new Set;for(const a of e.httpRoutes){const s=N(a.path),i=r[s]??{};i[a.method.toLowerCase()]=E(a),r[s]=i,o.add(c(a.filePath))}const n=e.functions.filter(a=>a.visibility!=="internal"&&a.kind!=="stream");for(const a of n){const{operation:s,pathKey:i}=L(a);r[i]={post:s},o.add(c(a.filePath))}for(const a of n){if(a.expose?.rest!==!0)continue;const s=I(a);if(s===void 0)continue;const i=r[s.path]??{};i[s.method]=s.operation,r[s.path]=i,o.add(c(a.filePath))}const p=[...o].toSorted((a,s)=>a.localeCompare(s)).map(a=>({description:`Operations declared in \`lunora/${a}\`.`,name:a}));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:S,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:r,tags:p}},U=e=>`${JSON.stringify(D(e),void 0,2)}
|
|
2
2
|
`,W=e=>`${v}export const openApiSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
|
|
3
3
|
`;export{D as buildOpenApiDocument,U as emitOpenApi,W as emitOpenApiModule};
|
|
@@ -46,7 +46,7 @@ ${n.pre}return { ${n.entries} };
|
|
|
46
46
|
${t}
|
|
47
47
|
`:"";return`export interface Insert_${e.name} {
|
|
48
48
|
_id?: Id<"${e.name}">;
|
|
49
|
-
_creationTime?: number;${n}}`},fr=(e,t=!1)=>{const n=H(t);for(const c of e.tables)m(c.name,"table name");const r=e.tables.map(c=>`"${c.name}"`).join(" | ")||"never",a=e.tables.filter(c=>c.extensionKey===void 0).map(c=>`"${c.name}"`).join(" | ")||"never",o=e.tables.map(c=>{const g=Object.entries(c.shape).map(([x,v])=>{const
|
|
49
|
+
_creationTime?: number;${n}}`},fr=(e,t=!1)=>{const n=H(t);for(const c of e.tables)m(c.name,"table name");const r=e.tables.map(c=>`"${c.name}"`).join(" | ")||"never",a=e.tables.filter(c=>c.extensionKey===void 0).map(c=>`"${c.name}"`).join(" | ")||"never",o=e.tables.map(c=>{const g=Object.entries(c.shape).map(([x,v])=>{const T=D(x);if(v.kind==="optional"){const N=v.inner?O(v.inner):"unknown";return` ${T}?: ${N};`}return` ${T}: ${O(v)};`}).join(`
|
|
50
50
|
`),b=g?`
|
|
51
51
|
${g}
|
|
52
52
|
`:"";return`export interface Doc_${c.name} {
|
|
@@ -313,7 +313,7 @@ export const api = anyApi as unknown as ApiTypes;
|
|
|
313
313
|
export interface InternalApiTypes {${b}}
|
|
314
314
|
|
|
315
315
|
export const internal = anyApi as unknown as InternalApiTypes;
|
|
316
|
-
${x.block}${y.block}`,
|
|
316
|
+
${x.block}${y.block}`,T=[...v.includes("FunctionReference<")?["FunctionReference"]:[],...y.block===""?[]:["HttpStreamRef"]],N=T.length>0?`import type { ${T.join(", ")} } from "${i.client}";
|
|
317
317
|
`:"";return at(`${k}import { anyApi } from "${i.serverTypes}";
|
|
318
318
|
${N}${x.importLine}${c}
|
|
319
319
|
${v}`,o)},yr=e=>e?`${k}import { createSeedClient as createSeedClientBase } from "@lunora/seed";
|
|
@@ -395,7 +395,7 @@ ${o}
|
|
|
395
395
|
}
|
|
396
396
|
|
|
397
397
|
return (await registered.handler(context, args ?? {})) as R;
|
|
398
|
-
};`,
|
|
398
|
+
};`,Tn=(e,t,n=[],r=[])=>{const a=new Map,o=d=>{a.has(d)||a.set(d,Nn(d,a.size))};for(const d of e)o(d.filePath);for(const d of t)o(d.filePath);for(const d of n)o(d.filePath);for(const d of r)o(d.filePath);const s=[...a.entries()].map(([d,c])=>{if(!ln.test(d))throw new Z("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(d)}`);return`import * as ${c} from "../${d}.js";`}).join(`
|
|
399
399
|
`),i=e.map(d=>` "${S(d.filePath)}:${d.exportName}": ${a.get(d.filePath)??""}.${d.exportName} as unknown as RegisteredLunoraFunction,`).join(`
|
|
400
400
|
`),l=t.map(d=>` ${JSON.stringify(d.id)}: ${a.get(d.filePath)??""}.${d.exportName} as unknown as RegisteredDataMigration,`).join(`
|
|
401
401
|
`),u=n.map(d=>` "${S(d.filePath)}:${d.exportName}": ${a.get(d.filePath)??""}.${d.exportName} as unknown as RegisteredLunoraFunction,`).join(`
|
|
@@ -410,7 +410,7 @@ ${y}
|
|
|
410
410
|
${l}
|
|
411
411
|
`:"",mutatorPaths:f,shapeBody:p.length>0?`
|
|
412
412
|
${p}
|
|
413
|
-
`:""}},
|
|
413
|
+
`:""}},An=e=>{const t=new Map;for(const a of e){const o=t.get(a.filePath)??[];o.push(a),t.set(a.filePath,o)}const n=[...t.entries()].toSorted(([a],[o])=>a.localeCompare(o)),r=n.map(([a,o])=>{const s=o.map(i=>{const l=me(i.args),u=l==="{}"?"?":"",p=Me(i.returnType);return i.kind==="stream"?` ${i.exportName}: (args${u}: ${l}) => Promise<AsyncIterable<${p}>>;`:` ${i.exportName}: (args${u}: ${l}) => Promise<${p}>;`}).join(`
|
|
414
414
|
`);return` ${D(S(a))}: {
|
|
415
415
|
${s}
|
|
416
416
|
};`}).join(`
|
|
@@ -418,13 +418,13 @@ ${s}
|
|
|
418
418
|
`);return` ${D(s)}: {
|
|
419
419
|
${i}
|
|
420
420
|
},`}).join(`
|
|
421
|
-
`),types:r}},Ln=(e,t=[])=>{const n=new Set;for(const r of e.tables)for(const a of Object.values(r.shape)){const o=a.kind==="optional"&&a.inner?a.inner:a;o.kind==="storage"&&typeof o.bucket=="string"&&o.bucket!==""&&n.add(o.bucket)}for(const r of t)r!==""&&r!=="default"&&n.add(r);return["default",...[...n].toSorted((r,a)=>r.localeCompare(a))]},xr=({agents:e=[],containers:t=[],env:n,hasAccessFacade:r=!1,hasAi:a=!1,hasAnalytics:o=!1,hasBrowser:s=!1,hasFlags:i=!1,hasHyperdrive:l=!1,hasImages:u=!1,hasKv:p=!1,hasNotify:f=!1,hasPayments:y=!1,hasPipelines:R=!1,hasR2sql:d=!1,hasX402:c=!1,identity:g,queues:b=[],schema:x,storageRuleBuckets:v=[],useUmbrella:
|
|
421
|
+
`),types:r}},Ln=(e,t=[])=>{const n=new Set;for(const r of e.tables)for(const a of Object.values(r.shape)){const o=a.kind==="optional"&&a.inner?a.inner:a;o.kind==="storage"&&typeof o.bucket=="string"&&o.bucket!==""&&n.add(o.bucket)}for(const r of t)r!==""&&r!=="default"&&n.add(r);return["default",...[...n].toSorted((r,a)=>r.localeCompare(a))]},xr=({agents:e=[],containers:t=[],env:n,hasAccessFacade:r=!1,hasAi:a=!1,hasAnalytics:o=!1,hasBrowser:s=!1,hasFlags:i=!1,hasHyperdrive:l=!1,hasImages:u=!1,hasKv:p=!1,hasNotify:f=!1,hasPayments:y=!1,hasPipelines:R=!1,hasR2sql:d=!1,hasX402:c=!1,identity:g,queues:b=[],schema:x,storageRuleBuckets:v=[],useUmbrella:T=!1,workflows:N=[]}={})=>{const $=H(T),w=Ln(x??{tables:[]},v).map(h=>JSON.stringify(h)).join(" | "),E=a?`import type { LunoraAi } from "@lunora/ai";
|
|
422
422
|
`:"",ee=a?`
|
|
423
423
|
readonly ai: LunoraAi;`:"",F=y?`import type { LunoraPayment } from "@lunora/payment";
|
|
424
424
|
`:"",te=y?`
|
|
425
425
|
readonly payments: LunoraPayment;`:"",ne=c?`import type { X402Pay } from "@lunora/x402/pay";
|
|
426
426
|
`:"",B=c?`
|
|
427
|
-
readonly x402: X402Pay;`:"",
|
|
427
|
+
readonly x402: X402Pay;`:"",A=t.length>0?`import type { ContainerAccessor } from "@lunora/container";
|
|
428
428
|
`:"",z=t.length>0?`
|
|
429
429
|
readonly containers: {${t.map(h=>`
|
|
430
430
|
readonly ${h.exportName}: ContainerAccessor;`).join("")}
|
|
@@ -453,7 +453,7 @@ ${L}`:""}
|
|
|
453
453
|
/** Alias for {@link CloudflareBindings} — the typed shape of \`env\`. */
|
|
454
454
|
export type Env = CloudflareBindings;`,M=(h,_e)=>_e?Zt.get(h)?.field??"":"",re=M("kv",p),ae=M("analytics",o),xe=M("hyperdrive",l),ke=M("browser",s),ve=M("images",u),oe=M("pipelines",R),K=M("r2sql",d),P=(x?.vectorIndexes.length??0)>0,Q=P?' | "vectors"':"",X=P?`
|
|
455
455
|
readonly vectors: VectorSearch<VectorIndexName>;`:"",ie=P?`
|
|
456
|
-
readonly vectors: VectorSearchReader<VectorIndexName>;`:"",
|
|
456
|
+
readonly vectors: VectorSearchReader<VectorIndexName>;`:"",J=P?`import type { VectorSearch, VectorSearchReader } from "${$.server}";
|
|
457
457
|
import type { VectorIndexName } from "./dataModel.js";
|
|
458
458
|
`:"",j=r?`
|
|
459
459
|
/** Verified Cloudflare Access identity — a synchronous facade over the resolved claims (email / groups / hasGroup / claims). Anonymous when no Access token is present. */
|
|
@@ -499,9 +499,9 @@ export interface LunoraAgents {
|
|
|
499
499
|
${e.map(h=>(m(h.exportName,`agent export "${h.exportName}"`),` readonly ${h.exportName}: AgentHandle;`)).join(`
|
|
500
500
|
`)}
|
|
501
501
|
}`:"",we=le?`
|
|
502
|
-
readonly agents: LunoraAgents;`:"",
|
|
502
|
+
readonly agents: LunoraAgents;`:"",Te=g?`import type { InferIdentity } from "${$.server}";
|
|
503
503
|
import type * as lunoraIdentityContract from "../identity.js";
|
|
504
|
-
`:"",
|
|
504
|
+
`:"",Ae=g?`
|
|
505
505
|
|
|
506
506
|
/** This app's declared identity claim contract (\`defineIdentity\` in \`lunora/identity.ts\`) — the typed shape of \`ctx.auth.getIdentity()\`, the RLS policy \`ctx.auth.identity\`, and the \`authorizeShard\`/\`authorizeFanOut\` identity argument. */
|
|
507
507
|
export type Identity = InferIdentity<typeof lunoraIdentityContract.${g.exportName}>;
|
|
@@ -536,11 +536,11 @@ import type {
|
|
|
536
536
|
} from "${$.server}";
|
|
537
537
|
|
|
538
538
|
import type { DataModel, DatabaseReaderFacade, DatabaseWriterFacade, Doc, Id as IdOfTable, OrmReader, OrmWriter, Relations, TableName } from "./dataModel.js";
|
|
539
|
-
${
|
|
539
|
+
${J}${E}${F}${ne}${A}${Y}${Se}${Ne}${Te}${Ce}
|
|
540
540
|
export type { AppTableName, DataModel, Doc, Id, TableName } from "./dataModel.js";
|
|
541
541
|
|
|
542
542
|
/** Storage buckets this schema declares (\`v.storage("name")\`), narrowing \`ctx.storage.bucket(name)\`. */
|
|
543
|
-
export type StorageBucketName = ${w};${_}${$e}${Re}${Oe}${
|
|
543
|
+
export type StorageBucketName = ${w};${_}${$e}${Re}${Oe}${Ae}${De}
|
|
544
544
|
|
|
545
545
|
/**
|
|
546
546
|
* Project-typed contexts. The base contexts from \`@lunora/server\` are
|
|
@@ -684,12 +684,12 @@ export const definePolicy = createPolicyDsl<DataModel, Relations${Le}>();
|
|
|
684
684
|
export const v = vBase as unknown as Omit<typeof vBase, "id"> & {
|
|
685
685
|
id: <T extends TableName>(table: T) => ColumnValidator<IdOfTable<T>, IdOfTable<T>>;
|
|
686
686
|
};
|
|
687
|
-
`},Cn=e=>{const t={connect:[],disconnect:[]};for(const n of e)n.lifecycle&&t[n.lifecycle].push(`${S(n.filePath)}:${n.exportName}`);return t},kr=e=>{const{agents:t=[],functions:n,migrations:r=[],mutators:a=[],shapes:o=[],useUmbrella:s=!1,usesSandbox:i=!1}=e,l=n.length>0,u=H(s),{dispatchBody:p,importBlock:f,installBlock:y,migrationBody:R,mutatorPaths:d,shapeBody:c}=
|
|
687
|
+
`},Cn=e=>{const t={connect:[],disconnect:[]};for(const n of e)n.lifecycle&&t[n.lifecycle].push(`${S(n.filePath)}:${n.exportName}`);return t},kr=e=>{const{agents:t=[],functions:n,migrations:r=[],mutators:a=[],shapes:o=[],useUmbrella:s=!1,usesSandbox:i=!1}=e,l=n.length>0,u=H(s),{dispatchBody:p,importBlock:f,installBlock:y,migrationBody:R,mutatorPaths:d,shapeBody:c}=Tn(n,r,a,o),g=kn(t,n),b=vn(i,n),x=[g.lines,b.lines].filter(_=>_.length>0).join(`
|
|
688
688
|
`);let v=p;x.length>0&&(v=p.length>0?`${p.trimEnd()}
|
|
689
689
|
${x}
|
|
690
690
|
`:`
|
|
691
691
|
${x}
|
|
692
|
-
`);const
|
|
692
|
+
`);const T=Cn(n),N=o.length>0?`import type { RegisteredShape } from "${u.server}";
|
|
693
693
|
`:"",$=o.length>0?`
|
|
694
694
|
/**
|
|
695
695
|
* Replication-shape registry — one entry per \`defineShape\` in \`lunora/shapes.ts\`.
|
|
@@ -713,16 +713,16 @@ export const LUNORA_MUTATOR_PATHS: ReadonlySet<string> = new Set([${d.map(_=>JSO
|
|
|
713
713
|
* parser as a zero-allocation fast path; anything it can't model is deferred.
|
|
714
714
|
*/
|
|
715
715
|
${y}
|
|
716
|
-
`:"",F=
|
|
716
|
+
`:"",F=An(n),te=F.types?`
|
|
717
717
|
${F.types}
|
|
718
718
|
`:"",ne=F.implementation?`
|
|
719
719
|
${F.implementation}
|
|
720
|
-
`:"",B=qe(F.types),
|
|
720
|
+
`:"",B=qe(F.types),A=B.length>0?`import type { ${B.join(", ")} } from "./dataModel.js";
|
|
721
721
|
`:"",z=l?"context":"_context",L=l?`${On}
|
|
722
722
|
|
|
723
723
|
`:"";return at(`${k}${f}${g.importLine}${b.importLine}${E}${N}import { LunoraError } from "${u.server}";
|
|
724
724
|
import type { ActionCtx, MutationCtx, QueryCtx } from "./server.js";
|
|
725
|
-
${
|
|
725
|
+
${A}
|
|
726
726
|
/**
|
|
727
727
|
* Single registered function, narrowed to the shape \`handleRpc\` needs.
|
|
728
728
|
* The real argument validators / return types are checked elsewhere — at
|
|
@@ -755,8 +755,8 @@ ${ee}${$}${w}
|
|
|
755
755
|
* DO runs every hook under the socket's verified identity via system dispatch.
|
|
756
756
|
*/
|
|
757
757
|
export const LUNORA_LIFECYCLE_HOOKS: { connect: readonly string[]; disconnect: readonly string[] } = {
|
|
758
|
-
connect: [${
|
|
759
|
-
disconnect: [${
|
|
758
|
+
connect: [${T.connect.map(_=>JSON.stringify(_)).join(", ")}],
|
|
759
|
+
disconnect: [${T.disconnect.map(_=>JSON.stringify(_)).join(", ")}],
|
|
760
760
|
};
|
|
761
761
|
|
|
762
762
|
/**
|
|
@@ -972,7 +972,7 @@ const analyticsStub: AnalyticsClient = {
|
|
|
972
972
|
${t}
|
|
973
973
|
},
|
|
974
974
|
};
|
|
975
|
-
`}},
|
|
975
|
+
`}},Jn=e=>{if(!e)return I;const t='throw new Error("ctx.images: no Images binding found. Add an \\`images\\` binding (env.IMAGES) to wrangler.jsonc, or pass \\`images\\` to createShardDO().");';return{build:`
|
|
976
976
|
const imagesBinding = config.images?.(env) ?? (env as Record<string, unknown>).IMAGES;
|
|
977
977
|
const images: Images = imagesBinding ? createImages({ binding: imagesBinding as ImagesBindingLike }) : imagesStub;
|
|
978
978
|
`,configField:`
|
|
@@ -986,7 +986,7 @@ const imagesStub: Images = {
|
|
|
986
986
|
${t}
|
|
987
987
|
},
|
|
988
988
|
};
|
|
989
|
-
`}},
|
|
989
|
+
`}},Vn=e=>e?{build:`
|
|
990
990
|
const sql: SqlClient = config.sql ? config.sql(env) : sqlStub;
|
|
991
991
|
`,configField:`
|
|
992
992
|
sql?: (env: Record<string, unknown>) => SqlClient;`,contextField:`
|
|
@@ -1260,10 +1260,10 @@ const x402Stub: X402Pay = {
|
|
|
1260
1260
|
throw new Error("ctx.x402: no pay rail configured. Pass \\\`x402\\\` to createShardDO().");
|
|
1261
1261
|
},
|
|
1262
1262
|
} as unknown as X402Pay;
|
|
1263
|
-
`}:{build:"",configField:"",contextField:"",imports:[],stub:""},or=(e,t,n,r)=>["AdvisorProcedure","AdvisoryFinding","DatabaseWriterLike","DataMigrationLike",...r?["FlagsResult"]:[],"MaskPoliciesResult","MigrationRunResult",...n?["QueuesResult"]:[],"RunShardApplyCdcArgs","RunShardMigrationArgs","RlsPoliciesResult","RunShardRankBeforeArgs","RunShardRankPageArgs","RunShardWriteArgs","RunShardWriteResult","SchedulerLike","SchemaLike","ShardDOState","ShardRankPageResult","SqlExec","StorageRulesResult","StudioFeaturesResult","SystemReaderStorageLike","TelemetrySink",...t?["WorkflowsResult"]:[],...e?["WriteHook"]:[]],Nr=({advisories:e=[],advisorProcedures:t=[],agents:n=[],containers:r=[],env:a,flagKeys:o=[],hasAccessFacade:s=!1,hasAi:i=!1,hasAnalytics:l=!1,hasBrowser:u=!1,hasFlags:p=!1,hasHyperdrive:f=!1,hasImages:y=!1,hasKv:R=!1,hasNotify:d=!1,hasPayments:c=!1,hasPipelines:g=!1,hasR2sql:b=!1,hasX402:x=!1,maskMetadata:v,mutators:
|
|
1263
|
+
`}:{build:"",configField:"",contextField:"",imports:[],stub:""},or=(e,t,n,r)=>["AdvisorProcedure","AdvisoryFinding","DatabaseWriterLike","DataMigrationLike",...r?["FlagsResult"]:[],"KeyRange","MaskPoliciesResult","MigrationRunResult",...n?["QueuesResult"]:[],"RunShardApplyCdcArgs","RunShardMigrationArgs","RlsPoliciesResult","RunShardRankBeforeArgs","RunShardRankPageArgs","RunShardWriteArgs","RunShardWriteResult","SchedulerLike","TransactionHeadroomTracker","SchemaLike","ShardDOState","ShardRankPageResult","SqlExec","StorageRulesResult","StudioFeaturesResult","SystemReaderStorageLike","TelemetrySink",...t?["WorkflowsResult"]:[],...e?["WriteHook"]:[]],Nr=({advisories:e=[],advisorProcedures:t=[],agents:n=[],containers:r=[],env:a,flagKeys:o=[],hasAccessFacade:s=!1,hasAi:i=!1,hasAnalytics:l=!1,hasBrowser:u=!1,hasFlags:p=!1,hasHyperdrive:f=!1,hasImages:y=!1,hasKv:R=!1,hasNotify:d=!1,hasPayments:c=!1,hasPipelines:g=!1,hasR2sql:b=!1,hasX402:x=!1,maskMetadata:v,mutators:T=[],queues:N=[],rlsMetadata:$,schema:w,schemaSnapshot:E,shapes:ee=[],storageRules:F,studioFeatures:te,useUmbrella:ne=!1,workflows:B=[]})=>{const A=H(ne),z=T.length>0,L=ee.length>0,_=E===void 0?"":zt(E),M=E===void 0?"":`
|
|
1264
1264
|
/** Structural schema snapshot + its content hash, recorded in the shard's \`__lunora_schema_history\` ledger on cold start so the studio can show a schema-version timeline and diff any two versions. */
|
|
1265
1265
|
const LUNORA_SCHEMA_SNAPSHOT: { hash: string; json: string } = { hash: ${JSON.stringify(Xt(E))}, json: ${JSON.stringify(_)} };
|
|
1266
|
-
`,re=E===void 0?"":", schemaSnapshot: LUNORA_SCHEMA_SNAPSHOT",{build:ae,configField:xe,contextField:ke,stub:ve}=Mn(i),oe=Un(s),K=qn(R),P=Bn(p,
|
|
1266
|
+
`,re=E===void 0?"":", schemaSnapshot: LUNORA_SCHEMA_SNAPSHOT",{build:ae,configField:xe,contextField:ke,stub:ve}=Mn(i),oe=Un(s),K=qn(R),P=Bn(p,A.flags),Q=Kn(o,p,A.flags),X=jn(d),ie=Wn(a),J=Qn(l),j=Jn(y),W=Vn(f),U=Gn(u),q=Hn(b),Y=zn(g),{build:$e,contextField:fe,importLines:be,specs:se}=Zn(N),{build:Se,contextField:Re,importLines:ye,specs:le}=Xn(r,w.jurisdiction),{build:Ne,contextField:Oe,importLines:we,specs:Te}=Yn(B),{build:Ae,contextField:de,importLines:ce,specs:Le}=er(n),{build:Ce,configField:De,contextField:ue,imports:pe,stub:h}=rr(c),{build:_e,configField:st,imports:lt,stub:dt}=ar(x),ct=e,ut=t,pt=$??{policies:[],roles:[]},ht=v??{columns:[]},gt=F??{rules:[]},mt=te??{analytics:!1,auth:!1,containers:!1,flags:!1,kv:!1,mail:!1,notifications:!1,payments:!1,queues:!1,scheduler:!1,storage:!1,vectors:!1,workflows:!1},{constant:ft,override:bt}=tr(B),{constant:yt,override:wt}=nr(N),V=w.vectorIndexes.length>0,he=w.tables.some(C=>C.shardMode==="global"),Ie=w.tables.some(C=>C.shardMode==="global"&&C.globalBackend==="hyperdrive"),je=w.tables.some(C=>C.shardMode==="global"&&C.globalBackend!=="hyperdrive"),G=w.tables.some(C=>C.externalSource!==void 0);if(je&&Ie)throw new Z("INTERNAL",'lunora codegen: mixing `.global()` (D1) and `.global({ backend: "hyperdrive" })` tables in one app is not supported yet — use a single global backend.');const Pe=w.tables.length>0,xt=Dn(w),kt=In(w),vt=En(w),$t=_n(w),We=Pn(w),Ue=or(V,B.length>0,N.length>0,p);L&&Ue.push("WhereInput");const Ke=Fn(he),St=L?`
|
|
1267
1267
|
protected override resolveShape(name: string, args: Record<string, unknown>, identity?: { identity?: Record<string, unknown>; userId?: string }): { columns?: readonly string[]; effectiveWhere?: WhereInput; global?: boolean; table: string } | undefined {
|
|
1268
1268
|
const shape = LUNORA_SHAPES[name];
|
|
1269
1269
|
|
|
@@ -1320,11 +1320,11 @@ const LUNORA_SCHEMA_SNAPSHOT: { hash: string; json: string } = { hash: ${JSON.st
|
|
|
1320
1320
|
protected override isCustomMutator(functionPath: string): boolean {
|
|
1321
1321
|
return LUNORA_MUTATOR_PATHS.has(functionPath);
|
|
1322
1322
|
}
|
|
1323
|
-
`:"",Nt=L?"\n/** Per-table RLS read policies (hoisted from `.use(rls(...))` chains) the shape resolver AND-merges into each `defineShape` predicate so partial replication honours read policies. */\nconst LUNORA_RLS_READ_REGISTRY = buildRlsReadRegistry(Object.values(LUNORA_FUNCTIONS));\n":"",Ot=L?"assertShapeShardable, ":"",ge=[`import type { ${Ue.join(", ")} } from "${
|
|
1324
|
-
vectors?: (env: Record<string, unknown>) => Record<string, VectorizeIndexLike>;`:"",
|
|
1323
|
+
`:"",Nt=L?"\n/** Per-table RLS read policies (hoisted from `.use(rls(...))` chains) the shape resolver AND-merges into each `defineShape` predicate so partial replication honours read policies. */\nconst LUNORA_RLS_READ_REGISTRY = buildRlsReadRegistry(Object.values(LUNORA_FUNCTIONS));\n":"",Ot=L?"assertShapeShardable, ":"",ge=[`import type { ${Ue.join(", ")} } from "${A.do}";`,`import { applyCdcChanges, ${Ot}createReadFootprint, createShardCtxDb, ${G?"isSourceDue, pullExternalSourceIncrementalTick, pullExternalSourceTick, ":""}runDataMigration, runShardMigrations, ${Ke.importFragment}ShardDO as ShardDOBase } from "${A.do}";`,...G?[`import type { ExternalSourceLike, SourceClientLike } from "${A.do}";`]:[],L?`import { asBucketStorage, buildRlsReadRegistry, composeShapeReadWhere, createSecrets, LunoraError } from "${A.server}";`:`import { asBucketStorage, createSecrets, LunoraError } from "${A.server}";`];Pe&&ge.push(`import { bindOrm, bindTableFacade } from "${A.server}";`),V&&ge.push('import type { SchemaLike as VectorSchemaLike, VectorizeIndexLike, VectorSearchLike } from "@lunora/bindings/vectors";','import { createContextVectors, createVectors, createVectorSyncHook } from "@lunora/bindings/vectors";'),i&&ge.push('import type { AiBindingLike, LunoraAi } from "@lunora/ai";','import { createAi } from "@lunora/ai";'),ge.push(...oe.importLines,...K.importLines,...P.importLines,...X.importLines,...ie.importLines,...J.importLines,...j.importLines,...W.importLines,...U.importLines,...q.importLines,...Y.importLines,...ye,...we,...be,...ce,...pe,...lt,"",'import schema from "../schema.js";',`import { ${["LUNORA_FUNCTIONS","LUNORA_LIFECYCLE_HOOKS","LUNORA_MIGRATIONS",...z?["LUNORA_MUTATOR_PATHS"]:[],...L?["LUNORA_SHAPES"]:[]].join(", ")} } from "./functions.js";`);const Tt=V?`
|
|
1324
|
+
vectors?: (env: Record<string, unknown>) => Record<string, VectorizeIndexLike>;`:"",At=je?`
|
|
1325
1325
|
d1?: (env: Record<string, unknown>, request?: { identity?: Record<string, unknown>; userId?: string }) => DatabaseWriterLike | undefined;`:"",Lt=Ie?`
|
|
1326
1326
|
hyperdriveGlobal?: (env: Record<string, unknown>, request?: { identity?: Record<string, unknown>; userId?: string }) => DatabaseWriterLike | undefined;`:"",Ct=G?`
|
|
1327
|
-
sourceClient?: (env: Record<string, unknown>, binding: string) => { query: <Row = Record<string, unknown>>(text: string, params?: readonly unknown[]) => Promise<Row[]> } | undefined;`:"",Dt=he?'\nconst globalDbStub: DatabaseWriterLike = {\n aggregate: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n count: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n delete: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n findFirst: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n findFirstOrThrow: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n findMany: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n get: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n groupBy: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n insert: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n normalizeId: () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n patch: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n query: () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n rank: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n rankPage: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n replace: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n};\n':"",_t=
|
|
1327
|
+
sourceClient?: (env: Record<string, unknown>, binding: string) => { query: <Row = Record<string, unknown>>(text: string, params?: readonly unknown[]) => Promise<Row[]> } | undefined;`:"",Dt=he?'\nconst globalDbStub: DatabaseWriterLike = {\n aggregate: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n count: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n delete: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n findFirst: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n findFirstOrThrow: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n findMany: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n get: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n groupBy: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n insert: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n normalizeId: () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n patch: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n query: () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n rank: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n rankPage: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n replace: async () => {\n throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");\n },\n};\n':"",_t=V?`
|
|
1328
1328
|
const vectorsStub: VectorSearchLike = {
|
|
1329
1329
|
deleteByIds: async () => {
|
|
1330
1330
|
throw new Error("ctx.vectors: no vectors configured. Pass \`vectors\` to createShardDO().");
|
|
@@ -1342,7 +1342,7 @@ const vectorsStub: VectorSearchLike = {
|
|
|
1342
1342
|
throw new Error("ctx.vectors: no vectors configured. Pass \`vectors\` to createShardDO().");
|
|
1343
1343
|
},
|
|
1344
1344
|
};
|
|
1345
|
-
`:"",It=
|
|
1345
|
+
`:"",It=V?`
|
|
1346
1346
|
let vectors: VectorSearchLike;
|
|
1347
1347
|
let onWrite: WriteHook | undefined;
|
|
1348
1348
|
|
|
@@ -1356,39 +1356,43 @@ const vectorsStub: VectorSearchLike = {
|
|
|
1356
1356
|
onWrite = undefined;
|
|
1357
1357
|
}
|
|
1358
1358
|
`:"",Qe=he?`
|
|
1359
|
-
globalDb,`:"",
|
|
1360
|
-
auth: { identity: identity ?? null, userId: userId ?? null },`,Pt=
|
|
1359
|
+
globalDb,`:"",Je=`
|
|
1360
|
+
auth: { identity: identity ?? null, userId: userId ?? null },`,Pt=V?`{${Je}
|
|
1361
1361
|
broadcast: (delta) => {
|
|
1362
|
-
this.recordChangedTable(delta.table);
|
|
1362
|
+
this.recordChangedTable(delta.table, delta.indexKeys);
|
|
1363
1363
|
},
|
|
1364
1364
|
cdc: config.cdc ?? false,
|
|
1365
1365
|
enforceRls: true,
|
|
1366
|
+
headroom: options.headroom ?? this.transactionHeadroom(),
|
|
1366
1367
|
onIndexUse: this.getCtxDbIndexUseHook(),
|
|
1367
1368
|
onRead: options.onRead ?? this.getCtxDbReadHook(),
|
|
1369
|
+
onReadRange: options.onReadRange,
|
|
1368
1370
|
onWrite,
|
|
1369
1371
|
scheduler,
|
|
1370
1372
|
schema: schema as unknown as SchemaLike,
|
|
1371
1373
|
sql: this.sql as SqlExec,
|
|
1372
1374
|
storage,${Qe}
|
|
1373
|
-
}`:`{${
|
|
1375
|
+
}`:`{${Je}
|
|
1374
1376
|
broadcast: (delta) => {
|
|
1375
|
-
this.recordChangedTable(delta.table);
|
|
1377
|
+
this.recordChangedTable(delta.table, delta.indexKeys);
|
|
1376
1378
|
},
|
|
1377
1379
|
cdc: config.cdc ?? false,
|
|
1378
1380
|
enforceRls: true,
|
|
1381
|
+
headroom: options.headroom ?? this.transactionHeadroom(),
|
|
1379
1382
|
onIndexUse: this.getCtxDbIndexUseHook(),
|
|
1380
1383
|
onRead: options.onRead ?? this.getCtxDbReadHook(),
|
|
1384
|
+
onReadRange: options.onReadRange,
|
|
1381
1385
|
scheduler,
|
|
1382
1386
|
schema: schema as unknown as SchemaLike,
|
|
1383
1387
|
sql: this.sql as SqlExec,
|
|
1384
1388
|
storage,${Qe}
|
|
1385
|
-
}`,Et=
|
|
1389
|
+
}`,Et=V?`
|
|
1386
1390
|
vectors,`:"",Ft=Pe?`
|
|
1387
|
-
orm: bindOrm(facade),`:"",Mt="",
|
|
1391
|
+
orm: bindOrm(facade),`:"",Mt="",Ve=Ie?"config.hyperdriveGlobal":"config.d1",qt=he?` const globalDb: DatabaseWriterLike = ${Ve}?.(env, { identity, userId }) ?? globalDbStub;
|
|
1388
1392
|
`:"",Bt=L&&he?`
|
|
1389
1393
|
protected override async readGlobalShapeRows(resolved: { columns?: readonly string[]; effectiveWhere?: WhereInput; global?: boolean; table: string }, identity?: { identity?: Record<string, unknown>; userId?: string }): Promise<Array<{ doc: Record<string, unknown>; id: string }>> {
|
|
1390
1394
|
const env = this.env as Record<string, unknown>;
|
|
1391
|
-
const globalDb: DatabaseWriterLike = ${
|
|
1395
|
+
const globalDb: DatabaseWriterLike = ${Ve}?.(env, identity) ?? globalDbStub;
|
|
1392
1396
|
const rows: Array<{ doc: Record<string, unknown>; id: string }> = [];
|
|
1393
1397
|
|
|
1394
1398
|
let cursor: null | string = null;
|
|
@@ -1433,7 +1437,7 @@ const sourcePollAtCache = new WeakMap<object, Map<string, number>>();
|
|
|
1433
1437
|
const scheduler = (config.scheduler?.(env) ?? schedulerStub) as SchedulerLike;
|
|
1434
1438
|
const writer = createShardCtxDb({
|
|
1435
1439
|
broadcast: (delta) => {
|
|
1436
|
-
this.recordChangedTable(delta.table);
|
|
1440
|
+
this.recordChangedTable(delta.table, delta.indexKeys);
|
|
1437
1441
|
},
|
|
1438
1442
|
cdc: config.cdc ?? false,
|
|
1439
1443
|
scheduler,
|
|
@@ -1541,10 +1545,10 @@ ${G?`
|
|
|
1541
1545
|
const facade = db as unknown as Record<string, ReturnType<typeof bindTableFacade>>;
|
|
1542
1546
|
${w.tables.map(C=>` facade[${JSON.stringify(C.name)}] = bindTableFacade(db, ${JSON.stringify(C.name)});`).join(`
|
|
1543
1547
|
`)}
|
|
1544
|
-
`:"",Qt=`${oe.build}${K.build}${P.build}${
|
|
1548
|
+
`:"",Qt=`${oe.build}${K.build}${P.build}${J.build}${ie.build}
|
|
1545
1549
|
const secrets = createSecrets(env);
|
|
1546
|
-
`,
|
|
1547
|
-
secrets,`,
|
|
1550
|
+
`,Jt=`${oe.contextField}${K.contextField}${P.contextField}${X.contextField}${J.contextField}${ie.contextField}
|
|
1551
|
+
secrets,`,Vt=X.build,He=y||f||u||b||g||x,Gt=He?`
|
|
1548
1552
|
// ActionCtx-only helpers (external, non-deterministic I/O): constructed
|
|
1549
1553
|
// and attached only for an \`action\` so query/mutation ctx never carry them.
|
|
1550
1554
|
if (isAction) {
|
|
@@ -1593,14 +1597,14 @@ const LUNORA_STORAGE_RULES: StorageRulesResult = ${JSON.stringify(gt,void 0,4)};
|
|
|
1593
1597
|
|
|
1594
1598
|
/** Which optional package-backed features this app wires up (discovered from imports / \`ctx.*\` reads / schema signals) served via \`__lunora_admin__:studioFeatures\` so the studio hides nav pages whose package isn't enabled. */
|
|
1595
1599
|
const LUNORA_STUDIO_FEATURES: StudioFeaturesResult = ${JSON.stringify(mt,void 0,4)};
|
|
1596
|
-
${M}${Q.constant}${Nt}${ft}${yt}${le}${
|
|
1600
|
+
${M}${Q.constant}${Nt}${ft}${yt}${le}${Te}${se}${Le}
|
|
1597
1601
|
export interface ShardDOConfig {
|
|
1598
1602
|
/** Opt into change-data-capture: records a post-image to \`__cdc_log\` on every write (backs streaming export + replay-PITR). */
|
|
1599
1603
|
cdc?: boolean;
|
|
1600
1604
|
/** Optional telemetry sink. When supplied, each \`ctx.log.*\` call is forwarded to \`sink.onLog\`. Pass the SAME sink you give \`createWorker({ observability })\` (which drives \`onRpc\`) to route both RPC and log events. */
|
|
1601
1605
|
observability?: (env: Record<string, unknown>) => TelemetrySink | undefined;
|
|
1602
1606
|
scheduler?: (env: Record<string, unknown>) => unknown;
|
|
1603
|
-
storage?: (env: Record<string, unknown>) => unknown;${
|
|
1607
|
+
storage?: (env: Record<string, unknown>) => unknown;${Tt}${xe}${K.configField}${P.configField}${J.configField}${j.configField}${W.configField}${U.configField}${q.configField}${Y.configField}${De}${st}${At}${Lt}${Ct}
|
|
1604
1608
|
}
|
|
1605
1609
|
|
|
1606
1610
|
const schedulerStub = {
|
|
@@ -1638,7 +1642,7 @@ const storageStub = {
|
|
|
1638
1642
|
throw new Error("ctx.storage: no storage configured. Pass \`storage\` to createShardDO().");
|
|
1639
1643
|
},
|
|
1640
1644
|
};
|
|
1641
|
-
${Dt}${jt}${_t}${ve}${K.stub}${P.stub}${
|
|
1645
|
+
${Dt}${jt}${_t}${ve}${K.stub}${P.stub}${J.stub}${j.stub}${W.stub}${U.stub}${q.stub}${Y.stub}${h}${dt}${Mt}
|
|
1642
1646
|
// Bound in-process \`ctx.run*\` composition depth so a self- or cyclically-
|
|
1643
1647
|
// referencing call fails loudly with a clear error instead of overflowing the
|
|
1644
1648
|
// stack. Tracked across the awaited handler chain (one DO invocation is
|
|
@@ -1719,7 +1723,7 @@ export const createShardDO = (config: ShardDOConfig = {}): new (state: ShardDOSt
|
|
|
1719
1723
|
return registered.handler(ctx, args);
|
|
1720
1724
|
}
|
|
1721
1725
|
${Ke.override}
|
|
1722
|
-
protected override async executeSubscription(functionPath: string, args: Record<string, unknown>, identity?: { identity?: Record<string, unknown>; userId?: string }): Promise<{ result: unknown; tables: Set<string> } | null> {
|
|
1726
|
+
protected override async executeSubscription(functionPath: string, args: Record<string, unknown>, identity?: { identity?: Record<string, unknown>; userId?: string }): Promise<{ ranges?: Map<string, KeyRange[]>; result: unknown; tables: Set<string> } | null> {
|
|
1723
1727
|
const registered = LUNORA_FUNCTIONS[functionPath];
|
|
1724
1728
|
|
|
1725
1729
|
if (!registered || registered.kind !== "query" || registered.visibility === "internal") {
|
|
@@ -1728,14 +1732,16 @@ ${Ke.override}
|
|
|
1728
1732
|
|
|
1729
1733
|
this.ensureMigrated();
|
|
1730
1734
|
|
|
1731
|
-
const
|
|
1735
|
+
const footprint = createReadFootprint();
|
|
1732
1736
|
// Identity is threaded EXPLICITLY from the (deferred/interleaved)
|
|
1733
1737
|
// subscription caller — never read from the shared per-request field
|
|
1734
1738
|
// here — so a concurrent RPC can't leak its identity into this re-run.
|
|
1735
|
-
const ctx = this.buildCtx({ functionPath, identity, onRead:
|
|
1739
|
+
const ctx = this.buildCtx({ functionPath, headroom: this.subscriptionHeadroom(), identity, onRead: footprint.onRead, onReadRange: footprint.onReadRange });
|
|
1736
1740
|
const result = await registered.handler(ctx, args);
|
|
1737
1741
|
|
|
1738
|
-
|
|
1742
|
+
// Ranges come from THIS run's reads, never a shared field on the DO:
|
|
1743
|
+
// a deferred re-run interleaves with unrelated dispatches.
|
|
1744
|
+
return { ranges: footprint.ranges(), result, tables: footprint.tables };
|
|
1739
1745
|
}
|
|
1740
1746
|
|
|
1741
1747
|
protected override executeStream(functionPath: string, args: Record<string, unknown>): null | { iterator: (signal: AbortSignal) => AsyncIterable<unknown> } {
|
|
@@ -1813,7 +1819,7 @@ ${Q.evaluateOverride}${Q.subscriptionOverride}${bt}${wt}
|
|
|
1813
1819
|
const scheduler = (config.scheduler?.(env) ?? schedulerStub) as SchedulerLike;
|
|
1814
1820
|
const writer = createShardCtxDb({
|
|
1815
1821
|
broadcast: (delta) => {
|
|
1816
|
-
this.recordChangedTable(delta.table);
|
|
1822
|
+
this.recordChangedTable(delta.table, delta.indexKeys);
|
|
1817
1823
|
},
|
|
1818
1824
|
cdc: config.cdc ?? false,
|
|
1819
1825
|
scheduler,
|
|
@@ -1856,7 +1862,7 @@ ${Q.evaluateOverride}${Q.subscriptionOverride}${bt}${wt}
|
|
|
1856
1862
|
const scheduler = (config.scheduler?.(env) ?? schedulerStub) as SchedulerLike;
|
|
1857
1863
|
const writer = createShardCtxDb({
|
|
1858
1864
|
broadcast: (delta) => {
|
|
1859
|
-
this.recordChangedTable(delta.table);
|
|
1865
|
+
this.recordChangedTable(delta.table, delta.indexKeys);
|
|
1860
1866
|
},
|
|
1861
1867
|
cdc: config.cdc ?? false,
|
|
1862
1868
|
scheduler,
|
|
@@ -1906,7 +1912,7 @@ ${Q.evaluateOverride}${Q.subscriptionOverride}${bt}${wt}
|
|
|
1906
1912
|
const scheduler = (config.scheduler?.(env) ?? schedulerStub) as SchedulerLike;
|
|
1907
1913
|
const writer = createShardCtxDb({
|
|
1908
1914
|
broadcast: (delta) => {
|
|
1909
|
-
this.recordChangedTable(delta.table);
|
|
1915
|
+
this.recordChangedTable(delta.table, delta.indexKeys);
|
|
1910
1916
|
},
|
|
1911
1917
|
cdc: config.cdc ?? false,
|
|
1912
1918
|
scheduler,
|
|
@@ -1927,7 +1933,7 @@ ${Q.evaluateOverride}${Q.subscriptionOverride}${bt}${wt}
|
|
|
1927
1933
|
const scheduler = (config.scheduler?.(env) ?? schedulerStub) as SchedulerLike;
|
|
1928
1934
|
const writer = createShardCtxDb({
|
|
1929
1935
|
broadcast: (delta) => {
|
|
1930
|
-
this.recordChangedTable(delta.table);
|
|
1936
|
+
this.recordChangedTable(delta.table, delta.indexKeys);
|
|
1931
1937
|
},
|
|
1932
1938
|
cdc: config.cdc ?? false,
|
|
1933
1939
|
scheduler,
|
|
@@ -1955,7 +1961,7 @@ ${Q.evaluateOverride}${Q.subscriptionOverride}${bt}${wt}
|
|
|
1955
1961
|
const scheduler = (config.scheduler?.(env) ?? schedulerStub) as SchedulerLike;
|
|
1956
1962
|
const writer = createShardCtxDb({
|
|
1957
1963
|
broadcast: (delta) => {
|
|
1958
|
-
this.recordChangedTable(delta.table);
|
|
1964
|
+
this.recordChangedTable(delta.table, delta.indexKeys);
|
|
1959
1965
|
},
|
|
1960
1966
|
cdc: config.cdc ?? false,
|
|
1961
1967
|
scheduler,
|
|
@@ -1986,7 +1992,7 @@ ${Q.evaluateOverride}${Q.subscriptionOverride}${bt}${wt}
|
|
|
1986
1992
|
const scheduler = (config.scheduler?.(env) ?? schedulerStub) as SchedulerLike;
|
|
1987
1993
|
const writer = createShardCtxDb({
|
|
1988
1994
|
broadcast: (delta) => {
|
|
1989
|
-
this.recordChangedTable(delta.table);
|
|
1995
|
+
this.recordChangedTable(delta.table, delta.indexKeys);
|
|
1990
1996
|
},
|
|
1991
1997
|
cdc: config.cdc ?? false,
|
|
1992
1998
|
scheduler,
|
|
@@ -2008,7 +2014,7 @@ ${Q.evaluateOverride}${Q.subscriptionOverride}${bt}${wt}
|
|
|
2008
2014
|
this.migrated = true;
|
|
2009
2015
|
}
|
|
2010
2016
|
|
|
2011
|
-
private buildCtx(options: { functionPath?: string; identity?: { identity?: Record<string, unknown>; userId?: string }; onRead?: (table: string) => void } = {}): unknown {
|
|
2017
|
+
private buildCtx(options: { functionPath?: string; headroom?: TransactionHeadroomTracker; identity?: { identity?: Record<string, unknown>; userId?: string }; onRead?: (table: string, idOrScan?: string) => void; onReadRange?: (range: KeyRange) => void } = {}): unknown {
|
|
2012
2018
|
const env = (this.env ?? {}) as Record<string, unknown>;
|
|
2013
2019
|
// When the caller threads an explicit identity (subscription seed /
|
|
2014
2020
|
// refresh — both run in deferred/interleaved contexts), use it by
|
|
@@ -2017,7 +2023,7 @@ ${Q.evaluateOverride}${Q.subscriptionOverride}${bt}${wt}
|
|
|
2017
2023
|
// dispatch path) fall back to the per-request fields as before.
|
|
2018
2024
|
const userId = options.identity ? options.identity.userId : this.getCurrentUserId();
|
|
2019
2025
|
const identity = options.identity ? options.identity.identity : this.getCurrentIdentity();
|
|
2020
|
-
${It}${ae}${Qt}${Se}${Ne}${$e}${
|
|
2026
|
+
${It}${ae}${Qt}${Se}${Ne}${$e}${Ae}
|
|
2021
2027
|
const scheduler = (config.scheduler?.(env) ?? schedulerStub) as SchedulerLike;
|
|
2022
2028
|
// Build the storage adapter once and share it between \`ctx.storage\`
|
|
2023
2029
|
// and \`ctx.db.system._storage\` so both read the same R2 binding. The
|
|
@@ -2058,7 +2064,7 @@ ${Kt}${Ce}
|
|
|
2058
2064
|
// writing mutation's trace from the shared per-request field.
|
|
2059
2065
|
const trace = this.makeTracer(logFunctionPath, observability, traceAnchor);
|
|
2060
2066
|
const metrics = this.makeMetrics(logFunctionPath, observability);
|
|
2061
|
-
${
|
|
2067
|
+
${Vt}
|
|
2062
2068
|
// \`ctx.now\`: the wall-clock instant (epoch ms) this function began,
|
|
2063
2069
|
// captured ONCE so the whole handler body sees a single stable value.
|
|
2064
2070
|
// Query/mutation handlers must be deterministic (they may be re-run on
|
|
@@ -2085,7 +2091,7 @@ ${Jt}
|
|
|
2085
2091
|
scheduler,
|
|
2086
2092
|
span,
|
|
2087
2093
|
storage,
|
|
2088
|
-
trace,${Et}${ke}${
|
|
2094
|
+
trace,${Et}${ke}${Jt}${ue}${Re}${Oe}${fe}${de}
|
|
2089
2095
|
};
|
|
2090
2096
|
${Ht}${Gt}
|
|
2091
2097
|
ctx.runAction = (reference: FunctionReference, fnArgs: Record<string, unknown>) => dispatchRun("action", reference.__lunoraRef, fnArgs, ctx);
|
|
@@ -2109,7 +2115,7 @@ ${n}
|
|
|
2109
2115
|
`:""].join("");return`${k}import { ${l.join(", ")} } from "${n.serverDrizzle}";
|
|
2110
2116
|
${p}
|
|
2111
2117
|
${u}
|
|
2112
|
-
`},Or=(e,t=!1)=>{const n=e.tables.filter(a=>a.shardMode==="global"),r=e.tables.filter(a=>a.shardMode!=="global");return{global:Xe(n,t),shard:Xe(r,t)}},
|
|
2118
|
+
`},Or=(e,t=!1)=>{const n=e.tables.filter(a=>a.shardMode==="global"),r=e.tables.filter(a=>a.shardMode!=="global");return{global:Xe(n,t),shard:Xe(r,t)}},Tr=e=>{const t=[],n=new Map;for(const i of e){const l=n.get(i.cron);l?l.push(i):(n.set(i.cron,[i]),t.push(i.cron))}const r=t.map(i=>` ${JSON.stringify(i)},`).join(`
|
|
2113
2119
|
`),a=r.length>0?`
|
|
2114
2120
|
${r}
|
|
2115
2121
|
`:"",o=[...n.entries()].map(([i,l])=>{const u=l.map(p=>{const f=p.workflow?`workflow: ${JSON.stringify(p.workflow.binding)}`:`functionPath: ${JSON.stringify(p.functionPath)}`;return` { name: ${JSON.stringify(p.name)}, ${f}, args: ${JSON.stringify(p.args)} },`}).join(`
|
|
@@ -2143,7 +2149,7 @@ export const LUNORA_CRON_TRIGGERS: ReadonlyArray<string> = [${a}];
|
|
|
2143
2149
|
* looks up \`event.cron\` here and dispatches every job in the list.
|
|
2144
2150
|
*/
|
|
2145
2151
|
export const LUNORA_CRONS: Record<string, ReadonlyArray<LunoraCronJob>> = {${s}};
|
|
2146
|
-
`},
|
|
2152
|
+
`},Ar=e=>{const t=[...e].toSorted((r,a)=>r.name.localeCompare(a.name)).map(r=>{const a=[`name: ${JSON.stringify(r.name)}`,`table: ${JSON.stringify(r.table)}`];return r.field!==void 0&&a.push(`field: ${JSON.stringify(r.field)}`),r.dimensions!==void 0&&a.push(`dimensions: ${JSON.stringify(r.dimensions)}`),r.metric!==void 0&&a.push(`metric: ${JSON.stringify(r.metric)}`),r.metadata!==void 0&&a.push(`metadata: ${JSON.stringify(r.metadata)}`),` { ${a.join(", ")} },`}).join(`
|
|
2147
2153
|
`),n=t.length>0?`
|
|
2148
2154
|
${t}
|
|
2149
2155
|
`:"";return`${k}/**
|
|
@@ -2167,4 +2173,4 @@ export interface LunoraVectorIndex {
|
|
|
2167
2173
|
* \`createWorker({ vectorIntrospector })\` to back the studio's vector browser.
|
|
2168
2174
|
*/
|
|
2169
2175
|
export const LUNORA_VECTOR_INDEXES: ReadonlyArray<LunoraVectorIndex> = [${n}];
|
|
2170
|
-
`},Lr=e=>{const t=new Set,n=[];for(const r of e)t.has(r.cron)||(t.add(r.cron),n.push(r.cron));return n};export{
|
|
2176
|
+
`},Lr=e=>{const t=new Set,n=[];for(const r of e)t.has(r.cron)||(t.add(r.cron),n.push(r.cron));return n};export{xr as $,$r as G,vr as H,Sr as J,kr as N,k as R,Nr as a,_n as b,yr as c,mr as d,Ar as g,Lr as m,fr as n,Tr as p,Yt as r,Or as u,wr as x,br as y,Rr as z};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{d as S,
|
|
1
|
+
import{d as S,R as D}from"./emit-CCw5fiXq.mjs";const E=e=>`has${e.charAt(0).toUpperCase()}${e.slice(1)}`,m=S.map(({appMethod:e,key:t})=>[E(t),e.method,e.configKey,e.doc]),v=e=>m.some(([t])=>e[t]),A=e=>e?['import * as lunoraIdentityContract from "../identity.js";']:[],R=(e,t)=>e?['import type { CreateAccessResolverOptions } from "@lunora/cloudflare-access";',`import { createAccessResolver${t?", composeResolvers":""} } from "@lunora/cloudflare-access";`]:[],x=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";']:[],j=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:b}=e,i=c?"lunorash/runtime":"@lunora/runtime",g=["ExecutionContextLike","HttpRouterLike","LunoraWorker","Route","ScheduledControllerLike","ShardNamespaceLike","WorkerOptions"];n&&g.push("GlobalIntrospector"),a&&g.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, createDoAuthWiring, d1Executor, ensureMigrated, handleAuthRequest, lunoraD1Adapter } from "@lunora/auth";']:[],...R(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";']:[],...x(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 { ${[...g].toSorted((w,y)=>w.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";']:[],...b?['import { openRpcSpec } from "./openrpc.js";']:[],'import { createShardDO } from "./shard.js";']},T=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>;
|
|
@@ -53,7 +53,7 @@ interface StorageDeclaration<Env> {
|
|
|
53
53
|
this.storageDeclaration = declaration;
|
|
54
54
|
|
|
55
55
|
return this;
|
|
56
|
-
}`]:[],...N(e)]
|
|
56
|
+
}`]:[],...N(e)],$=e=>{const t=[...e.hasGlobal?[` ...(this.globalDeclaration
|
|
57
57
|
? {
|
|
58
58
|
d1: (rawEnv: Record<string, unknown>, request?: { identity?: Record<string, unknown>; userId?: string | null }) => {
|
|
59
59
|
const env = rawEnv as Env;
|
|
@@ -113,7 +113,7 @@ interface StorageDeclaration<Env> {
|
|
|
113
113
|
: {}),`]:[],...e.hasStorage?[" ...(this.storageDeclaration ? { storage: (rawEnv: Record<string, unknown>) => this.resolveStorage(rawEnv as Env) } : {}),"]:[],...v(e)?[" ...this.shardExtras,"]:[]];return t.length>0?`
|
|
114
114
|
${t.join(`
|
|
115
115
|
`)}
|
|
116
|
-
`:""}
|
|
116
|
+
`:""},I=e=>[...e.hasScheduler?[` if (this.schedulerDeclaration) {
|
|
117
117
|
options.schedulerDO = this.schedulerDeclaration.namespace(env);
|
|
118
118
|
}`]:[],...e.hasWorkflow?[` options.workflowsClient = (workflowEnv) => {
|
|
119
119
|
const source = workflowEnv as Record<string, unknown>;
|
|
@@ -297,7 +297,7 @@ const buildGlobalIntrospector = (database: D1DatabaseLike): GlobalIntrospector =
|
|
|
297
297
|
readTablePage: (options) => readGlobalTablePage(exec, schema as never, options),
|
|
298
298
|
};
|
|
299
299
|
};
|
|
300
|
-
`:"",U=e=>[...e.hasAuth?["AuthDeclaration"]:[],"ComposedApp",...e.hasGlobal?["GlobalDeclaration"]:[],...e.hasScheduler?["SchedulerDeclaration"]:[],"Selector",...e.hasStorage?["StorageDeclaration"]:[]].toSorted((t,r)=>t.localeCompare(r)).join(", "),F=e=>{const{hasAuth:t}=e,r=T(e),a
|
|
300
|
+
`:"",U=e=>[...e.hasAuth?["AuthDeclaration"]:[],"ComposedApp",...e.hasGlobal?["GlobalDeclaration"]:[],...e.hasScheduler?["SchedulerDeclaration"]:[],"Selector",...e.hasStorage?["StorageDeclaration"]:[]].toSorted((t,r)=>t.localeCompare(r)).join(", "),F=e=>{const{hasAuth:t}=e,r=T(e),a=I(e),n=t?` let auth: LunoraAuth | null = null;
|
|
301
301
|
`:"",o=t?`
|
|
302
302
|
const ensureAuth = async (env: Env): Promise<void> => {
|
|
303
303
|
if (!this.authDeclaration || auth) {
|
|
@@ -366,7 +366,7 @@ ${b}
|
|
|
366
366
|
|
|
367
367
|
/** Build the shard DO + compose the worker (standalone or framework-hosted), wrapping the lazy per-isolate singletons + auth init. */
|
|
368
368
|
private assemble(${h}): ComposedApp {
|
|
369
|
-
const ShardDO = createShardDO({${
|
|
369
|
+
const ShardDO = createShardDO({${$(e)}});
|
|
370
370
|
|
|
371
371
|
// Per-isolate singletons: the worker (and auth instance) are expensive to
|
|
372
372
|
// build, so the first request constructs them and every later request on
|
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.81",
|
|
4
4
|
"description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -46,15 +46,15 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@lunora/advisor": "1.0.0-alpha.
|
|
50
|
-
"@lunora/agent": "1.0.0-alpha.
|
|
51
|
-
"@lunora/container": "1.0.0-alpha.
|
|
52
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
49
|
+
"@lunora/advisor": "1.0.0-alpha.59",
|
|
50
|
+
"@lunora/agent": "1.0.0-alpha.34",
|
|
51
|
+
"@lunora/container": "1.0.0-alpha.18",
|
|
52
|
+
"@lunora/errors": "1.0.0-alpha.10",
|
|
53
53
|
"@lunora/platform": "1.0.0-alpha.1",
|
|
54
|
-
"@lunora/queue": "1.0.0-alpha.
|
|
55
|
-
"@lunora/scheduler": "1.0.0-alpha.
|
|
56
|
-
"@lunora/values": "1.0.0-alpha.
|
|
57
|
-
"@lunora/workflow": "1.0.0-alpha.
|
|
54
|
+
"@lunora/queue": "1.0.0-alpha.13",
|
|
55
|
+
"@lunora/scheduler": "1.0.0-alpha.16",
|
|
56
|
+
"@lunora/values": "1.0.0-alpha.13",
|
|
57
|
+
"@lunora/workflow": "1.0.0-alpha.15",
|
|
58
58
|
"jsonc-parser": "^3.3.1",
|
|
59
59
|
"ts-morph": "^28.0.0"
|
|
60
60
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"@lunora/agent/component";import"@lunora/errors";import"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{w as r,c as o,J as n,b as l,x as p,K as g,p as u,n as S,u as c,N as C,z as E,y as d,S as A,a as D,g as z,G as b,m as f}from"./emit-B6-LPmOS.mjs";import"./paths-BmX5O1sG.mjs";export{r as GENERATED_HEADER,o as buildStorageColumns,n as emitAgents,l as emitApi,p as emitCollections,g as emitContainers,u as emitCrons,S as emitDataModel,c as emitDrizzleSchema,C as emitFunctions,E as emitQueues,d as emitSeed,A as emitServer,D as emitShard,z as emitVectors,b as emitWorkflows,f as emitWranglerCronTriggers};
|