@lunora/codegen 1.0.0-alpha.67 → 1.0.0-alpha.69
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.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DVjBK4ud.mjs +3 -0
- package/dist/packem_shared/{emitApp-BzO6O7Lx.mjs → emitApp-Cm9yVOpP.mjs} +58 -27
- package/package.json +3 -3
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CthmqJlJ.mjs +0 -3
package/dist/index.d.mts
CHANGED
|
@@ -1338,11 +1338,13 @@ interface AuthConfigIR {
|
|
|
1338
1338
|
line: number;
|
|
1339
1339
|
/** `emailAndPassword.requireEmailVerification === true` present. */
|
|
1340
1340
|
requireEmailVerification: boolean;
|
|
1341
|
+
/** `trustedOrigins` array literal contains a `"*"` element. */
|
|
1342
|
+
/** `plugins` includes `scim(...)` while `database` is a non-transactional Lunora adapter — a combination that throws at runtime. */
|
|
1343
|
+
scimOnNonTransactionalAdapter: boolean;
|
|
1341
1344
|
/** `advanced.useSecureCookies === false`. */
|
|
1342
1345
|
secureCookiesDisabled: boolean;
|
|
1343
1346
|
/** `session.freshAge === 0` (explicit literal). */
|
|
1344
1347
|
sessionFreshAgeZero: boolean;
|
|
1345
|
-
/** `trustedOrigins` array literal contains a `"*"` element. */
|
|
1346
1348
|
trustedOriginsWildcard: boolean;
|
|
1347
1349
|
}
|
|
1348
1350
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1338,11 +1338,13 @@ interface AuthConfigIR {
|
|
|
1338
1338
|
line: number;
|
|
1339
1339
|
/** `emailAndPassword.requireEmailVerification === true` present. */
|
|
1340
1340
|
requireEmailVerification: boolean;
|
|
1341
|
+
/** `trustedOrigins` array literal contains a `"*"` element. */
|
|
1342
|
+
/** `plugins` includes `scim(...)` while `database` is a non-transactional Lunora adapter — a combination that throws at runtime. */
|
|
1343
|
+
scimOnNonTransactionalAdapter: boolean;
|
|
1341
1344
|
/** `advanced.useSecureCookies === false`. */
|
|
1342
1345
|
secureCookiesDisabled: boolean;
|
|
1343
1346
|
/** `session.freshAge === 0` (explicit literal). */
|
|
1344
1347
|
sessionFreshAgeZero: boolean;
|
|
1345
|
-
/** `trustedOrigins` array literal contains a `"*"` element. */
|
|
1346
1348
|
trustedOriginsWildcard: boolean;
|
|
1347
1349
|
}
|
|
1348
1350
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{formatAdvisories as t,lintSchema as s}from"./packem_shared/formatAdvisories-DZvv-0MG.mjs";import{CodegenDiagnosticError as i,diagnosticAt as m}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as f,discoverAgents as p}from"./packem_shared/AGENTS_FILENAME-BesaDYkL.mjs";import{default as n}from"./packem_shared/discoverAuthApiCalls-Ba6W92HB.mjs";import{CONTAINERS_FILENAME as l,discoverContainers as E}from"./packem_shared/CONTAINERS_FILENAME-CFwdyaCI.mjs";import{default as u}from"./packem_shared/discoverCrons-2nUpw6do.mjs";import{FLAGS_FILENAME as v,discoverFlags as N}from"./packem_shared/FLAGS_FILENAME-C1GWerCB.mjs";import{discoverFunctions as M}from"./packem_shared/discoverFunctions-zrIQk7J8.mjs";import{default as h}from"./packem_shared/discoverHttpRoutes-Bf_T_03b.mjs";import{default as _}from"./packem_shared/discoverInserts-DveVeP5h.mjs";import{default as g}from"./packem_shared/discoverMaskProcedures-BkBquCFR.mjs";import{default as F}from"./packem_shared/discoverMigrations-T2xb-1rn.mjs";import{MUTATORS_FILENAME as P,discoverMutators as D}from"./packem_shared/MUTATORS_FILENAME-BWPAtQ2T.mjs";import{default as H}from"./packem_shared/discoverNondeterministicCalls-BymnOR9k.mjs";import{NOTIFY_FILENAME as W,discoverNotifyCalls as G,discoverNotifyConfig as V}from"./packem_shared/NOTIFY_FILENAME-DP6qvFBX.mjs";import{default as w}from"./packem_shared/discoverQueries-DNRA-G2a.mjs";import{QUEUES_FILENAME as z,discoverQueues as Q}from"./packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs";import{default as B}from"./packem_shared/discoverR2sqlCalls-YEjvGcEq.mjs";import{discoverRlsMetadata as K,default as q}from"./packem_shared/discoverRlsMetadata-DO3qlLXX.mjs";import{discoverSandboxUsage as X}from"./packem_shared/discoverSandboxUsage-JwrmSN9l.mjs";import{default as $}from"./packem_shared/discoverSchema-m2voTncu.mjs";import{SHAPES_FILENAME as oe,discoverShapes as re}from"./packem_shared/SHAPES_FILENAME-maut3z1K.mjs";import{default as se}from"./packem_shared/discoverStorageRulesMetadata-CCztRKjw.mjs";import{WORKFLOWS_FILENAME as ie,discoverWorkflows as me}from"./packem_shared/WORKFLOWS_FILENAME-Bk5upkGM.mjs";import{w as fe,B as pe,s as ce,c as ne,_ as Se,t as le,H as Ee,e as xe,b as ue,h as Ae,J as ve,n as Ne,M as Oe,r as Me}from"./packem_shared/emit-Bp0nOR_O.mjs";import{emitApp as he}from"./packem_shared/emitApp-
|
|
1
|
+
import{formatAdvisories as t,lintSchema as s}from"./packem_shared/formatAdvisories-DZvv-0MG.mjs";import{CodegenDiagnosticError as i,diagnosticAt as m}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as f,discoverAgents as p}from"./packem_shared/AGENTS_FILENAME-BesaDYkL.mjs";import{default as n}from"./packem_shared/discoverAuthApiCalls-Ba6W92HB.mjs";import{CONTAINERS_FILENAME as l,discoverContainers as E}from"./packem_shared/CONTAINERS_FILENAME-CFwdyaCI.mjs";import{default as u}from"./packem_shared/discoverCrons-2nUpw6do.mjs";import{FLAGS_FILENAME as v,discoverFlags as N}from"./packem_shared/FLAGS_FILENAME-C1GWerCB.mjs";import{discoverFunctions as M}from"./packem_shared/discoverFunctions-zrIQk7J8.mjs";import{default as h}from"./packem_shared/discoverHttpRoutes-Bf_T_03b.mjs";import{default as _}from"./packem_shared/discoverInserts-DveVeP5h.mjs";import{default as g}from"./packem_shared/discoverMaskProcedures-BkBquCFR.mjs";import{default as F}from"./packem_shared/discoverMigrations-T2xb-1rn.mjs";import{MUTATORS_FILENAME as P,discoverMutators as D}from"./packem_shared/MUTATORS_FILENAME-BWPAtQ2T.mjs";import{default as H}from"./packem_shared/discoverNondeterministicCalls-BymnOR9k.mjs";import{NOTIFY_FILENAME as W,discoverNotifyCalls as G,discoverNotifyConfig as V}from"./packem_shared/NOTIFY_FILENAME-DP6qvFBX.mjs";import{default as w}from"./packem_shared/discoverQueries-DNRA-G2a.mjs";import{QUEUES_FILENAME as z,discoverQueues as Q}from"./packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs";import{default as B}from"./packem_shared/discoverR2sqlCalls-YEjvGcEq.mjs";import{discoverRlsMetadata as K,default as q}from"./packem_shared/discoverRlsMetadata-DO3qlLXX.mjs";import{discoverSandboxUsage as X}from"./packem_shared/discoverSandboxUsage-JwrmSN9l.mjs";import{default as $}from"./packem_shared/discoverSchema-m2voTncu.mjs";import{SHAPES_FILENAME as oe,discoverShapes as re}from"./packem_shared/SHAPES_FILENAME-maut3z1K.mjs";import{default as se}from"./packem_shared/discoverStorageRulesMetadata-CCztRKjw.mjs";import{WORKFLOWS_FILENAME as ie,discoverWorkflows as me}from"./packem_shared/WORKFLOWS_FILENAME-Bk5upkGM.mjs";import{w as fe,B as pe,s as ce,c as ne,_ as Se,t as le,H as Ee,e as xe,b as ue,h as Ae,J as ve,n as Ne,M as Oe,r as Me}from"./packem_shared/emit-Bp0nOR_O.mjs";import{emitApp as he}from"./packem_shared/emitApp-Cm9yVOpP.mjs";import{buildOpenApiDocument as _e,emitOpenApi as Ie,emitOpenApiModule as ge}from"./packem_shared/buildOpenApiDocument-BJudKDP_.mjs";import{OPENRPC_VERSION as Fe,buildOpenRpcDocument as Te,emitOpenRpc as Pe,emitOpenRpcModule as De}from"./packem_shared/OPENRPC_VERSION-BcivFYIX.mjs";import{SCHEMA_SNAPSHOT_FILENAME as He,createCodegenProject as be,refreshCodegenProject as We,runCodegen as Ge}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-DVjBK4ud.mjs";import{SCHEMA_SNAPSHOT_VERSION as ke,SchemaSnapshotParseError as we,buildSchemaSnapshot as ye,diffSchemaSnapshots as ze,evaluateSchemaDrift as Qe,parseSchemaSnapshot as je,serializeSchemaSnapshot as Be}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-Bpf1FGMG.mjs";import{schemaFromIr as Ke}from"./packem_shared/schemaFromIr-R1ZFzVyy.mjs";import{LUNORA_ERROR_CODES as Ye,validatorIrToJsonSchema as Xe}from"./packem_shared/LUNORA_ERROR_CODES-Um9hC1gr.mjs";import{redact as $e,secretKindOf as eo}from"./packem_shared/redact-CQ8-to6l.mjs";import{MESSAGE_SOLUTIONS as ro,findSolutionByMessage as to}from"@lunora/errors";const e="0.0.0";export{f as AGENTS_FILENAME,l as CONTAINERS_FILENAME,i as CodegenDiagnosticError,v as FLAGS_FILENAME,fe as GENERATED_HEADER,Ye as LUNORA_ERROR_CODES,ro as LUNORA_SOLUTION_RULES,P as MUTATORS_FILENAME,W as NOTIFY_FILENAME,Fe as OPENRPC_VERSION,z as QUEUES_FILENAME,He as SCHEMA_SNAPSHOT_FILENAME,ke as SCHEMA_SNAPSHOT_VERSION,oe as SHAPES_FILENAME,we as SchemaSnapshotParseError,e as VERSION,ie as WORKFLOWS_FILENAME,_e as buildOpenApiDocument,Te as buildOpenRpcDocument,ye as buildSchemaSnapshot,be as createCodegenProject,m as diagnosticAt,ze as diffSchemaSnapshots,p as discoverAgents,n as discoverAuthApiCalls,E as discoverContainers,u as discoverCrons,N as discoverFlags,M as discoverFunctions,h as discoverHttpRoutes,_ as discoverInserts,g as discoverMaskProcedures,F as discoverMigrations,D as discoverMutators,H as discoverNondeterministicCalls,G as discoverNotifyCalls,V as discoverNotifyConfig,w as discoverQueries,Q as discoverQueues,B as discoverR2sqlCalls,K as discoverRlsMetadata,q as discoverRlsProcedures,X as discoverSandboxUsage,$ as discoverSchema,re as discoverShapes,se as discoverStorageRulesMetadata,me as discoverWorkflows,pe as emitAgents,ce as emitApi,he as emitApp,ne as emitCollections,Se as emitContainers,le as emitCrons,Ee as emitDataModel,xe as emitDrizzleSchema,ue as emitFunctions,Ie as emitOpenApi,ge as emitOpenApiModule,Pe as emitOpenRpc,De as emitOpenRpcModule,Ae as emitServer,ve as emitShard,Ne as emitVectors,Oe as emitWorkflows,Me as emitWranglerCronTriggers,Qe as evaluateSchemaDrift,to as findLunoraSolution,t as formatAdvisories,s as lintSchema,je as parseSchemaSnapshot,$e as redact,We as refreshCodegenProject,Ge as runCodegen,Ke as schemaFromIr,eo as secretKindOf,Be as serializeSchemaSnapshot,Xe as validatorIrToJsonSchema};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{existsSync as E,readFileSync as Ae,mkdirSync as zt,writeFileSync as qt,rmSync as Bt}from"node:fs";import{join as g,dirname as ge}from"node:path";import{performance as fe}from"node:perf_hooks";import{LunoraError as q}from"@lunora/errors";import{Node as i,SyntaxKind as u,Project as Xe}from"ts-morph";import{lintSchema as Vt}from"./formatAdvisories-DZvv-0MG.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as f,classifyProcedureCall as K,inlineHandler as Ut,procedureHandler as mt,chainUsesWrappedCall as xt,isDatabaseAccessor as k,chainHasStep as Wt,discoverFunctions as Gt}from"./discoverFunctions-zrIQk7J8.mjs";import{discoverAgents as Ht}from"./AGENTS_FILENAME-BesaDYkL.mjs";import _t from"./discoverAuthApiCalls-Ba6W92HB.mjs";import{discoverContainers as Jt}from"./CONTAINERS_FILENAME-CFwdyaCI.mjs";import Qt from"./discoverCrons-2nUpw6do.mjs";import{diagnosticAt as H}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{o as _}from"./module-specifiers-8FEEiUcv.mjs";import{a as pe,X as Xt,H as Zt,s as Yt,h as es,b as ts,J as ss,c as rs,_ as ns,M as is,B as os,j as as,t as cs,n as us,e as ls,l as ds,r as gs}from"./emit-Bp0nOR_O.mjs";import{discoverFlagKeys as fs}from"./FLAGS_FILENAME-C1GWerCB.mjs";import ps from"./discoverHttpRoutes-Bf_T_03b.mjs";import ms from"./discoverInserts-DveVeP5h.mjs";import xs,{discoverMaskStrategies as hs,discoverMaskMetadata as Es}from"./discoverMaskProcedures-BkBquCFR.mjs";import ys from"./discoverMigrations-T2xb-1rn.mjs";import{MUTATORS_FILENAME as As,isDefineMutatorCallee as $s,discoverMutators as Ns}from"./MUTATORS_FILENAME-BWPAtQ2T.mjs";import Ss from"./discoverNondeterministicCalls-BymnOR9k.mjs";import{discoverNotifyConfig as vs,discoverNotifyCalls as bs}from"./NOTIFY_FILENAME-DP6qvFBX.mjs";import Ps from"./discoverQueries-DNRA-G2a.mjs";import{discoverQueues as ws}from"./QUEUES_FILENAME-CSE6i-ld.mjs";import Is from"./discoverR2sqlCalls-YEjvGcEq.mjs";import Os,{discoverRlsMetadata as Ls}from"./discoverRlsMetadata-DO3qlLXX.mjs";import{discoverSandboxUsage as Fs}from"./discoverSandboxUsage-JwrmSN9l.mjs";import Ts from"./discoverSchema-m2voTncu.mjs";import{secretKindOf as Ds,redact as Cs}from"./redact-CQ8-to6l.mjs";import{discoverShapes as ks}from"./SHAPES_FILENAME-maut3z1K.mjs";import Ks from"./discoverStorageRulesMetadata-CCztRKjw.mjs";import{e as Rs}from"./discover-ast-CezKqEhE.mjs";import{discoverWorkflows as Ms}from"./WORKFLOWS_FILENAME-Bk5upkGM.mjs";import{emitApp as js}from"./emitApp-Cm9yVOpP.mjs";import{buildOpenApiDocument as zs,emitOpenApiModule as qs}from"./buildOpenApiDocument-BJudKDP_.mjs";import{buildOpenRpcDocument as Bs,emitOpenRpcModule as Vs}from"./OPENRPC_VERSION-BcivFYIX.mjs";import{buildSchemaSnapshot as Us,serializeSchemaSnapshot as Ws}from"./SCHEMA_SNAPSHOT_VERSION-Bpf1FGMG.mjs";const ht=new Set(["delete","get","head","options","patch","post","put"]),Gs=new Set(["handler","stream"]),Hs=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,Ze=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),_s=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ht.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()}},Js=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)||ht.has(r.getName()))break;s=r.getExpression()}return _s(s)},Qs=e=>{for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression))if(Ze.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&Ze.has(s.getText()))return!0}return!1},Xs=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||!Gs.has(r.getName()))return;const n=Js(s);if(!n||!Hs.test(n.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&Qs(o);return{exportName:e.getName(),file:t,method:n.method,path:n.path,usesGuard:a}},Zs=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Xs(n,t);o&&s.push(o)}return s},Ys=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Zs(n,f(t,r)))}return s},Ye=e=>{if(e.getText()!=="args")return!1;const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(i.isPropertyAssignment(t)&&t.getNameNode()===e)},et=e=>{if(e.getText()!=="ctx")return!1;const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(i.isPropertyAssignment(t)&&t.getNameNode()===e)},me=e=>i.isIdentifier(e)?et(e):e.getDescendantsOfKind(u.Identifier).some(t=>et(t)),tt=(e,t)=>{if(e.getText()!==t)return!1;const s=e.getParent();return i.isPropertyAccessExpression(s)&&s.getNameNode()===e?!1:!(i.isPropertyAssignment(s)&&s.getNameNode()===e)},er=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t:void 0},N=e=>{if(i.isIdentifier(e))return e.getText();if(i.isPropertyAccessExpression(e))return e.getName()},Ee=e=>i.isIdentifier(e)?Ye(e):e.getDescendantsOfKind(u.Identifier).some(t=>Ye(t)),L=e=>{if(!i.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a));if(s===void 0)return;const r=e.getStart();let n,o=-1;for(const a of s.getDescendantsOfKind(u.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<r&&l>o&&(n=c,o=l)}return n},w=e=>{if(Ee(e))return!0;const t=L(e);return t!==void 0&&Ee(t)},T=e=>{if(me(e))return!0;const t=L(e);if(t!==void 0&&me(t))return!0;const s=t??e;return(i.isIdentifier(s)?[s]:s.getDescendantsOfKind(u.Identifier)).some(r=>{const n=L(r);return n!==void 0&&me(n)})},B=(e,t)=>i.isIdentifier(e)?tt(e,t):e.getDescendantsOfKind(u.Identifier).some(s=>tt(s,t)),tr=(e,t)=>{if(B(e,t))return!0;const s=L(e);if(s!==void 0&&B(s,t))return!0;const r=er(e);if(r!==void 0){const n=L(r);return n!==void 0&&B(n,t)}return!1},h=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)&&t.getVariableStatement()?.hasExportKeyword()===!0)return t.getName();return"<module>"},sr=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",rr=(e,t)=>{if(!sr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)||T(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},nr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=rr(r,t);n&&s.push(n)}return s},ir=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...nr(n,f(t,r)))}return s},or=new Set(["generateText","streamText"]),ar=new Set(["messages","prompt","system"]),cr=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],ur=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),r=t.getExpression().getText();for(const n of cr)if(n.methods.has(s)&&n.prefixes.some(o=>r===o||r.startsWith(`${o}.`)))return`${r}.${s}`},lr=e=>{for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=ur(t);if(s!==void 0)return s}},dr=e=>{const t=new Set,s=e.getFirstAncestor(o=>i.isArrowFunction(o)||i.isFunctionExpression(o)||i.isFunctionDeclaration(o)),[r]=s?.getParameters()??[],n=r?.getNameNode();if(n===void 0||!i.isObjectBindingPattern(n))return t;for(const o of n.getElements()){const a=o.getPropertyNameNode()?.getText()??o.getName(),c=o.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},gr=e=>{if(Ee(e))return!0;const t=dr(e);return t.size===0?!1:e.getDescendantsOfKind(u.Identifier).some(s=>t.has(s.getText()))},fr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!ar.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&gr(s))return!0}return!1},pr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=N(r.getExpression());if(n===void 0||!or.has(n))continue;const[o]=r.getArguments();if(o===void 0||!i.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(u.CallExpression))if(N(c.getExpression())==="tool"&&(a=lr(c),a!==void 0))break;a!==void 0&&s.push({exportName:h(r),file:t,line:r.getStartLineNumber(),method:n,sideEffect:a,userInputDerived:fr(o)})}return s},mr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...pr(n,f(t,r)))}return s},xr=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},hr=(e,t)=>{if(!xr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},Er=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=hr(r,t);n&&s.push(n)}return s},yr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Er(n,f(t,r)))}return s},Ar=/\.check\(|\.meta\(|length|max/iu,$r=/\bv\.any\s*\(/u,Nr=/\bv\.string\s*\(/u,Sr=e=>$r.test(e),vr=e=>Nr.test(e)&&!Ar.test(e),br=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("args");if(!s||!i.isPropertyAssignment(s))return;const r=s.getInitializer();return r&&i.isObjectLiteralExpression(r)?r:void 0},Pr=e=>{const t=[];let s=e;for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const n=s.getArguments()[0];n&&i.isObjectLiteralExpression(n)&&t.push(n)}s=r.getExpression()}return t},wr=e=>{const t=[],s=[];for(const r of e)for(const n of r.getProperties()){if(!i.isPropertyAssignment(n))continue;const o=n.getInitializer();if(!o)continue;const a=o.getText(),c=n.getName();Sr(a)?t.push(c):vr(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Ir=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=K(s);if(r?.visibility!=="public")return;const n=r.receiver?Pr(r.receiver):[br(s)].filter(c=>c!==void 0),{anyArgs:o,unboundedStringArgs:a}=wr(n);if(!(o.length===0&&a.length===0))return{anyArgs:o,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Or=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Ir(n,t);o&&s.push(o)}return s},Lr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Or(n,f(t,r)))}return s},S=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},xe=e=>e?.getKind()===u.TrueKeyword,Fr=e=>e?.getKind()===u.FalseKeyword,Tr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Dr=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Cr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&N(t.getExpression())==="scim"),kr=e=>e!==void 0&&i.isCallExpression(e)&&Dr.has(N(e.getExpression())??""),Kr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),Rr=e=>{const t=S(e,"advanced"),s=S(e,"emailAndPassword"),r=S(e,"session");return{analyzable:!0,disableCsrfCheck:xe(S(t,"disableCSRFCheck")),emailPasswordEnabled:xe(S(s,"enabled")),requireEmailVerification:xe(S(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Cr(S(e,"plugins"))&&kr(S(e,"database")),secureCookiesDisabled:Fr(S(t,"useSecureCookies")),sessionFreshAgeZero:Tr(S(r,"freshAge")),trustedOriginsWildcard:Kr(S(e,"trustedOrigins"))}},Mr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),jr=(e,t)=>{if(N(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?Rr(s):Mr();return{exportName:h(e),file:t,line:e.getStartLineNumber(),...n}},zr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=jr(r,t);n&&s.push(n)}return s},qr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...zr(n,f(t,r)))}return s},Br=(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},Vr=(e,t,s)=>{const r=Br(e.getExpression(),s);if(r===void 0)return;const n=e.getArguments()[s.argIndex];if(!(!n||!w(n)||T(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:r}},Ur=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const o=Vr(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(...Ur(o,f(t,n),s))}return r},Wr=new Set(["content","pdf","scrape","screenshot"]),Gr=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Wr}),Hr=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),_r=new Set(["RateLimiter"]),Jr=new Set(["extend"]),Et=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}},st=e=>e&&i.isObjectLiteralExpression(e)?Et(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Qr=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},Xr=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)?Qr(e):void 0},Zr=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&Xr(t.getBody());return s?Et(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Yr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=N(r.getExpression());n!==void 0&&(Hr.has(n)?s.push({callee:n,file:t,line:r.getStartLineNumber(),...st(r.getArguments()[0])}):Jr.has(n)&&s.push({callee:n,file:t,line:r.getStartLineNumber(),...Zr(r.getArguments()[0])}))}for(const r of e.getDescendantsOfKind(u.NewExpression)){const n=N(r.getExpression());n===void 0||!_r.has(n)||s.push({callee:n,file:t,line:r.getStartLineNumber(),...st(r.getArguments()[0])})}return s},en=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Yr(n,f(t,r)))}return s},rt="ctx.containers.",tn=e=>{if(!e.startsWith(rt))return!1;const t=e.slice(rt.length);return t.length>0&&!t.includes(".")},sn=(e,t)=>J(e,t,{argIndex:0,matchReceiver:tn,methods:new Set(["get"])}),rn=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())},on=(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()}},an=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!rn.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()}},cn=(e,t)=>on(e,t)??an(e,t),un=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=cn(r,t);n&&s.push(n)}return s},ln=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...un(n,f(t,r)))}return s},dn="env.ts",gn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return _(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},fn=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&&_(r.getModuleSpecifierValue())}return!1},pn=e=>{if(i.isIdentifier(e))return gn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&fn(t)}return!1},mn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!pn(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},xn=(e,t)=>{const s=g(t,dn);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=mn(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]}},hn=new Set(["defineExportSink","r2Sink","webhookExportSink"]),En=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return hn.has(s)?s:void 0},yn=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}},An=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){const c=En(a);if(c===void 0)continue;const l=a.getArguments()[0],p=l&&i.isObjectLiteralExpression(l)?yn(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:p.analyzable,emptyKeys:p.emptyKeys,factory:c,file:o,line:a.getStartLineNumber(),presentKeys:p.presentKeys})}}return s},$n=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Nn=new Set(["dbRateLimit","rateLimit"]),Sn=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},vn=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},bn=(e,t)=>{const s=N(e.getExpression());if(s===void 0)return;const r=$n.get(s);if(r!==void 0)return{callee:s,exportName:h(e),failOpen:Sn(e.getArguments()[r]),file:t,limitName:Nn.has(s)?vn(e):"",line:e.getStartLineNumber()}},Pn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=bn(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(...Pn(n,f(t,r)))}return s},In=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},On=(e,t)=>{const s=Object.fromEntries(pe.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=In(n);for(const c of pe)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(pe.every(c=>s[c.key]))break}return s},Ln=["providerSubscriptionId","state"],Fn=["providerEventId","processedAt"],nt=(e,t)=>t.every(s=>s in e.shape),Tn=e=>{const t=e.find(r=>r.name==="subscriptions"),s=e.find(r=>r.name==="events");return t!==void 0&&s!==void 0&&nt(t,Ln)&&nt(s,Fn)},Dn=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings/kv"),mail:e.mail||t.dependencies.has("@lunora/mail"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),Cn=e=>i.isIdentifier(e)&&e.getText()==="ctx",kn=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Cn(t.getExpression())},Kn=e=>{if(e?.getKind()===u.TrueKeyword)return!0;if(e?.getKind()===u.FalseKeyword)return!1},Rn=(e,t)=>{if(!kn(e.getExpression()))return;const[s,r]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const n=s.getLiteralValue(),o=Kn(r);if(!(n.length===0||o===void 0))return{defaultValue:o,exportName:h(e),file:t,key:n,line:e.getStartLineNumber()}},Mn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Rn(r,t);n&&s.push(n)}return s},jn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Mn(n,f(t,r)))}return s},zn=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},qn=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Bn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression))zn(a)&&s.push({file:o,indexName:qn(a),line:a.getStartLineNumber()})}return s},Vn=new Set(["delete","get","head","options","patch","post","put"]),Un=new Set(["handler","stream"]),Wn=new Set(["runAction","runMutation"]),Gn=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),U=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,it=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,ot=(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}}},at=(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(Wn.has(a)&&U(c,t))return a;if(Gn.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&U(c.getExpression(),t))return`db.${a}`}},ct=(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},Hn=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Un.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(Vn.has(n)){const o=r.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?n.toUpperCase():void 0}s=r.getExpression()}},_n=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=it(e.getArguments()[0]),l=c&&ot(c,!0);if(!c||l===void 0)return;const p=at(c,l);return p===void 0?void 0:{exportName:h(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ct(c,l),sideEffect:p}}const r=Hn(e);if(r===void 0)return;const n=it(e.getArguments()[0]),o=n&&ot(n,!1);if(!n||o===void 0)return;const a=at(n,o);return a===void 0?void 0:{exportName:h(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:r,readsAuth:ct(n,o),sideEffect:a}},Jn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=_n(r,t);n&&s.push(n)}return s},Qn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Jn(n,f(t,r)))}return s},Xn=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),Zn=new Set(["append","set"]),$e=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",yt=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",ut=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(u.CallExpression)]:e.getDescendantsOfKind(u.CallExpression)).some(s=>Xn.has($e(s.getExpression()))&&B(s,t)),Yn=(e,t)=>{if(ut(e,t))return!0;const s=L(e);return s!==void 0&&ut(s,t)},ye=(e,t)=>tr(e,t)&&!Yn(e,t),ei=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=L(e);return t!==void 0&&i.isNewExpression(t)&&$e(t.getExpression())==="Headers"},W=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=L(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},Ne=(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:yt(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&&Ne(n,t,s)}},At=(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&&Ne(n,"response-init",t)},ti=(e,t)=>{const s=$e(e.getExpression());if(s==="Response")At(e.getArguments()[1],t);else if(s==="Headers"){const r=W(e.getArguments()[0]);r!==void 0&&Ne(r,"headers-ctor",t)}},si=(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"){At(e.getArguments()[1],t);return}if(Zn.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:yt(e.getArguments()[0]),line:o.getStartLineNumber(),via:r==="set"?"headers-set":"headers-append"})}},ri=(e,t)=>{for(const s of e.getDescendantsOfKind(u.NewExpression))ti(s,t);for(const s of e.getDescendantsOfKind(u.CallExpression))si(s,t)},ni=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const r=Ut(e.getArguments()[0]);if(r===void 0)return[];const n=r.getParameters()[1];if(n===void 0)return[];const o=n.getNameNode();if(!i.isIdentifier(o))return[];const a=[];return ri(r,{exportName:h(e),relativePath:t,requestName:o.getText(),rows:a}),a},ii=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...ni(r,t));return s},oi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ii(n,f(t,r)))}return s},$t="identity.ts",ai=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return _(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},ci=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&&_(r.getModuleSpecifierValue())}return!1},ui=e=>{if(i.isIdentifier(e))return ai(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&ci(t)}return!1},li=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!ui(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},di=(e,t)=>{const s=g(t,$t);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=li(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]}},gi=new Set(["auth","context.auth","ctx.auth"]),fi="userId",pi=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},mi=(e,t)=>{const s=g(t,$t);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const n of r.getDescendantsOfKind(u.CallExpression)){if(N(n.getExpression())!=="defineIdentity")continue;const[o]=n.getArguments();return o&&i.isObjectLiteralExpression(o)?pi(o):void 0}},lt=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return gi.has(e.getExpression().getText())?e:void 0},xi=e=>{if(i.isPropertyAccessExpression(e)&<(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&<(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},hi=(e,t,s)=>{const r=[];for(const n of e.getDescendants()){const o=xi(n);o!==void 0&&r.push({declared:o===fi||s.has(o),exportName:h(n),file:t,key:o,line:n.getStartLineNumber()})}return r},Ei=(e,t)=>{const s=mi(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(...hi(o,f(t,n),s))}return r},yi=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Ai=(e,t)=>{if(N(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const r=yi(s);if(!(!r||!w(r)||T(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},$i=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ai(r,t);n&&s.push(n)}return s},Ni=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...$i(n,f(t,r)))}return s},Si=new Set(["delete","get","getRaw","getWithMetadata","put"]),vi=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:Si}),bi=new Set(["queue","send"]),dt=new Set(["bcc","cc","to"]),Pi=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!bi.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 dt.has(t.getName())&&w(r)&&!T(r)}if(!i.isPropertyAssignment(t)||!dt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&w(s)&&!T(s)}):!1,Ii=(e,t)=>{const s=Pi(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}},Oi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ii(r,t);n&&s.push(n)}return s},Li=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Oi(n,f(t,r)))}return s},Fi=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"},Ti=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},Di=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==u.CallExpression)return;const s=t;return $s(s.getExpression())?s:void 0},Ci=e=>{const t=Di(e),s=t===void 0?void 0:Ti(t);if(s===void 0)return[];const r=e.getNameNode(),n=i.isIdentifier(r)?r.getText():"";return s.getDescendantsOfKind(u.CallExpression).filter(o=>Fi(o)).map(o=>({exportName:n,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},ki=e=>e.getVariableDeclarations().flatMap(t=>Ci(t)),Ki=(e,t)=>{const s=g(t,As);if(!E(s))return[];const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);return ki(r)},Ri=new Set(["delete","get","patch"]),Mi=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),ji=new Set(["auth","identity","session","user"]),zi=new Set([u.EqualsEqualsEqualsToken,u.EqualsEqualsToken,u.ExclamationEqualsEqualsToken,u.ExclamationEqualsToken]),qi=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!k(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},Bi=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},Vi=(e,t)=>e.getDescendantsOfKind(u.Identifier).some(s=>s.getText()===t),Ui=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(u.ThrowStatement).length>0||e.getDescendantsOfKind(u.ReturnStatement).length>0,Wi=(e,t)=>e.getDescendantsOfKind(u.IfStatement).some(s=>Vi(s.getExpression(),t)&&Ui(s.getThenStatement())),Gi=(e,t)=>{for(const s of e.getDescendantsOfKind(u.CallExpression)){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))continue;const n=r.getName();if(!Ri.has(n))continue;const o=r.getExpression();if(!(k(o)||i.isPropertyAccessExpression(o)&&k(o.getExpression())))continue;const a=s.getArguments()[0];if(a!==void 0&&i.isIdentifier(a)&&a.getText()===t)return n}},Hi=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},_i=e=>e.getDescendantsOfKind(u.CallExpression).some(t=>t.getArguments().some(s=>Hi(s)==="ctx")),Ji=e=>e.getDescendantsOfKind(u.BinaryExpression).some(t=>zi.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),Qi=e=>{for(const t of e.getDescendantsOfKind(u.Identifier))if(Mi.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&ji.has(t.getName()))return!0}return _i(e)||Ji(e)},Xi=(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=mt(s);if(n===void 0)return[];const o=r.receiver!==void 0&&xt(r.receiver,"use","rls"),a=Qi(n),c=new Set,l=[];for(const p of n.getDescendantsOfKind(u.CallExpression)){const y=qi(p);if(y===void 0)continue;const I=Bi(p);if(I===void 0||c.has(I)||!Wi(n,I))continue;const R=Gi(n,I);R!==void 0&&(c.add(I),l.push({exportName:e.getName(),file:t,line:p.getStartLineNumber(),mentionsOwnership:a,sinkMethod:R,table:y,usesRls:o,visibility:r.visibility}))}return l},Zi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Xi(c,o))}return s},Yi=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),eo=new Set(["insert","insertManyUnsafe","patch","replace"]),to=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!eo.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},so=(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},ro=(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||!Yi.has(a))&&w(c)&&!T(c)&&n.push({exportName:h(s),field:a,file:r,line:s.getStartLineNumber(),method:t})}return n},no=(e,t)=>{const s=to(e.getExpression());if(s===void 0)return[];const r=e.getArguments()[1];return r?so(r,s).flatMap(n=>ro(n,s,e,t)):[]},io=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...no(r,t));return s},oo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...io(n,f(t,r)))}return s},ao=e=>{const t=g(e,"package.json");if(!E(t))return new Set;try{const s=JSON.parse(Ae(t,"utf8")),r=new Set;for(const n of["dependencies","devDependencies","peerDependencies","optionalDependencies"]){const o=s[n];if(o!==null&&typeof o=="object")for(const a of Object.keys(o))r.add(a)}return r}catch{return new Set}},co=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),uo=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,lo=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?uo(t.getInitializer()):void 0},go=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=N(r.getExpression());if(n===void 0||!co.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},fo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...go(n,f(t,r)))}return s},po=new Set(["defineQueue","defineWorkflow"]),mo=new Set(["run","runAction","runMutation","runQuery"]),xo=new Set(["api","internal"]),ho=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},Eo=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},Nt=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},St=(e,t)=>e===t||e.startsWith(`${t}.`),vt=e=>{const t=e.getDescendantsOfKind(u.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},gt=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e||i.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(i.isBindingElement(t)&&t.getNameNode()===e)},bt=e=>{const t=e.getDescendantsOfKind(u.Identifier).filter(s=>gt(s));return i.isIdentifier(e)&>(e)&&t.push(e),t},yo=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(u.BindingElement).map(s=>s.getName())},Ao=e=>{const t=Nt(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},$o=(e,t,s)=>{const r=t==="workflow"?[`${s}.params`]:Ao(e),n=new Set,o=a=>vt(a).some(c=>r.some(l=>St(c.getText(),l)))?!0:bt(a).some(c=>n.has(c.getText()));for(const a of e.getDescendantsOfKind(u.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of yo(a))n.add(l)}return{names:n,prefixes:r}},No=(e,t)=>vt(e).some(s=>t.prefixes.some(r=>St(s.getText(),r)))?!0:bt(e).some(s=>t.names.has(s.getText())),So=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)||!xo.has(s.getText())||t.length<2))return{exportName:r,file:t.slice(0,-1).join("/")}},vo=(e,t,s)=>{const r=Nt(e,0);if(r===void 0)return[];const n=$o(e,t,r),o=[];for(const a of e.getDescendantsOfKind(u.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!mo.has(c.getName())||c.getExpression().getText()!==r)continue;const l=a.getArguments()[1];if(!l||!No(l,n))continue;const p=So(a.getArguments()[0]);p!==void 0&&o.push({dispatchKind:t,file:s,handlerExport:h(a),line:a.getStartLineNumber(),targetExport:p.exportName,targetFile:p.file})}return o},bo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ho(r);if(n===void 0||!po.has(n))continue;const o=Eo(r);o!==void 0&&s.push(...vo(o,n==="defineQueue"?"queue":"workflow",t))}return s},Po=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...bo(n,f(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,Pt=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},Io=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Oo=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},Lo=e=>{const t=Oo(e),s=t?Pt(t):void 0;if(t&&s==="protectPublic"){const r=Io(t);return{...V,usesCaptcha:r.usesCaptcha,usesRateLimit:r.usesRateLimit}}return s!==void 0&&s in ft?{...V,[ft[s]]:!0}:V},Fo=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=Lo(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},To=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()))},Do=new Set(["create","runAfter","runAt","send","sendBatch"]),Co=new Set(["queues","scheduler","workflows"]),ko=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Do.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&Co.has(s.getName())){const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="ctx")return!0}s=s.getExpression()}return!1},Ko=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"},Ro=new Set(["generateObject","generateText","streamObject","streamText"]),Mo=e=>{const t=Pt(e);if(t===void 0||!Ro.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")},jo=e=>e.getDescendantsOfKind(u.PropertyAccessExpression).some(t=>{const s=t.getName();if(s!=="mail"&&s!=="email")return!1;const r=t.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"}),zo=e=>{let t=!1,s=!1,r=!1,n=!1;for(const o of e.getDescendantsOfKind(u.CallExpression))if(To(o)&&(n=!0),ko(o)&&(t=!0),Ko(o)&&(r=!0),Mo(o)&&(s=!0),n&&t&&r&&s)break;return{callsMail:jo(e),fanOut:t,unboundedAiGeneration:s,usesInsertManyUnsafe:r,writesUserTable:n}},qo=(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?Fo(r.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},{callsMail:o,fanOut:a,unboundedAiGeneration:c,usesInsertManyUnsafe:l,writesUserTable:p}=zo(e);return{callsMail:o,exportName:e.getName(),fanOut:a,file:t,kind:r.kind,unboundedAiGeneration:c,usesCaptcha:n.usesCaptcha,usesEmailGate:n.usesEmailGate,usesInsertManyUnsafe:l,usesMask:n.usesMask,usesRateLimit:n.usesRateLimit,usesRls:n.usesRls,visibility:r.visibility,writesUserTable:p}},Bo=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=qo(n,t);o&&s.push(o)}return s},Vo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Bo(n,f(t,r)))}return s},Uo=new Set(["dbRateLimit","rateLimit"]),Wo=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Go=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},Ho=e=>i.isArrowFunction(e)?e.getBody():e,_o=(e,t)=>{const s=N(e.getExpression());if(s===void 0||!Uo.has(s))return;const r=e.getArguments()[2];if(!r)return;const n=Wo(r);if(!n)return;const o=Ho(n);if(!(!w(o)||T(o)))return{callee:s,exportName:h(e),file:t,limitName:Go(e),line:e.getStartLineNumber()}},Jo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=_o(r,t);n&&s.push(n)}return s},Qo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Jo(n,f(t,r)))}return s},Xo=new Set(["findFirst","findFirstOrThrow","findMany","get"]),Zo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Xo.has(t.getName()))return;const s=t.getExpression();if(k(s)){const r=e.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&k(s.getExpression()))return s.getName()},Yo=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&k(s.getExpression())){const r=t.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}t=s.getExpression()}},ea=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},wt=(e,t=!1)=>{const s=ea(e);if(i.isIdentifier(s)){if(t)return;const r=L(s);return r===void 0?void 0:wt(r,!0)}if(i.isCallExpression(s))return Zo(s)??Yo(s)},ta=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},sa=(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=mt(s);if(n===void 0)return[];const o=r.receiver!==void 0&&Wt(r.receiver,"output"),a=r.receiver!==void 0&&xt(r.receiver,"use","mask"),c=new Set,l=[];for(const p of ta(n)){const y=wt(p);y===void 0||c.has(y)||(c.add(y),l.push({exportName:e.getName(),file:t,line:p.getStartLineNumber(),table:y,usesMask:a,usesOutput:o,visibility:r.visibility}))}return l},ra=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...sa(c,o))}return s},na=new Set(["findFirst","findFirstOrThrow","findMany"]),ia=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!na.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()}}},oa=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},aa=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},ca=(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=ia(o);if(a===void 0)continue;const c=oa(aa(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},ua=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...ca(c,o))}return s},G=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===u.PlusToken){const t=G(e.getLeft()),s=G(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},la=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===u.PlusToken;)t=s,s=t.getParent();return t!==e&&G(t)!==void 0},da=(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(la(o))continue;const a=G(o);if(a===void 0)continue;const c=Ds(a);if(c===void 0)continue;const l=o.getStartLineNumber(),p=`${String(l)}:${c}`;n.has(p)||(n.add(p),s.push({file:t,kind:c,line:l,preview:Cs(a)}))}return s},ga=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...da(n,f(t,r)))}return s},fa=new Set(["findFirst","findFirstOrThrow","findMany"]),pa=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!fa.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()}}},ma=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},xa=(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=pa(o);if(a===void 0)continue;const c=ma(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),p=!l&&w(c);!l&&!p||n.push({exportName:e.getName(),file:t,fromArgs:p,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:r.visibility})}return n},ha=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...xa(c,o))}return s},Ea=new Set(["query","unsafe"]),ya=e=>{if(!i.isPropertyAccessExpression(e)||!Ea.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"},Aa=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),$a=e=>e.getFirstAncestorByKind(u.VariableDeclaration)?.getName()??"<module>",Na=(e,t)=>{if(!ya(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Aa(s)))return{exportName:$a(e),file:t,line:s.getStartLineNumber()}},Sa=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Na(r,t);n&&s.push(n)}return s},va=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Sa(n,f(t,r)))}return s},ba=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Pa=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.storage"||s.startsWith("ctx.storage."),methods:ba}),wa=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Ia=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Oa=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=Ia(n.getInitializer()));continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,expiresInSeconds:s,presentKeys:t}},La=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=wa.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},Fa=(e,t)=>{const s=La(e.getExpression());if(s!==void 0)return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s.method,...Oa(e.getArguments()[s.optionsIndex])}},Ta=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Fa(r,t);n&&s.push(n)}return s},Da=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ta(n,f(t,r)))}return s},Ca=new Set(["when","where"]),he=new Set(["definePolicy","defineShape"]),ka=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const r=t.getName();return he.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 he.has(n)?n:void 0}const s=t.getText();return he.has(s)?s:void 0},Ka=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,It=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===u.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Ka(e))return"empty-object";if(i.isParenthesizedExpression(e))return It(e.getExpression())}},Ot=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Lt=e=>e.getDescendantsOfKind(u.ReturnStatement).filter(t=>Ot(t)===e),Ft=e=>e.getDescendantsOfKind(u.ConditionalExpression).filter(t=>Ot(t)===e),Ra=e=>{const t=Lt(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(u.IfStatement)!==void 0)||Ft(e).length>0},Ma=e=>{const t=[],s=e.getBody();i.isBlock(s)||t.push(s);for(const r of Lt(e)){const n=i.isReturnStatement(r)?r.getExpression():void 0;t.push(n??r)}for(const r of Ft(e))t.push(r.getWhenTrue(),r.getWhenFalse());return t},ja=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},za=(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)||!Ca.has(o.getName()))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Ra(a))for(const c of Ma(a)){const l=It(c);l!==void 0&&n.push({exportName:ja(e),file:s,form:l,key:o.getName(),line:c.getStartLineNumber(),owner:t})}}return n},qa=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ka(r);n!==void 0&&s.push(...za(r,n,t))}return s},Ba=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...qa(n,f(t,r)))}return s},Va=new Set(["query","upsert","upsertMany"]),Ua=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(Va.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Wa=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("namespace");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Ga=(e,t)=>{const s=Ua(e.getExpression());if(s===void 0)return;const r=e.getArguments()[1];if(!r)return;const n=Wa(r);if(!(!n||!w(n)||T(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Ha=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ga(r,t);n&&s.push(n)}return s},_a=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ha(n,f(t,r)))}return s},Ja=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"},Qa=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Xa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){if(!Ja(a))continue;const c=Rs(a);c!==""&&s.push({exportName:c,file:o,line:a.getStartLineNumber(),workflow:Qa(a)})}}return s},Za=".lunora-schema.json",$=(e,t)=>{E(e)&&Ae(e,"utf8")===t||qt(e,t,"utf8")},P=(e,t)=>{if(t===""){Bt(e,{force:!0});return}$(e,t)},Ya=e=>{const t=g(e,"package.json");if(E(t))try{const s=JSON.parse(Ae(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},ec=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},tc=e=>{let t=E(e)?e:ge(e);for(;t&&t!==ge(t);){const s=g(t,"tsconfig.json");if(E(s))return s;t=ge(t)}},pt=e=>e.replaceAll("\\","/"),sc=(e,t)=>{const s=new Map,r=new Map,n=new Map;for(const o of e)s.set(o.name,`workflow "${o.exportName}"`),r.set(o.bindingName,`workflow "${o.exportName}"`),n.set(o.className,`workflow "${o.exportName}"`);for(const o of t){const a=s.get(o.name);if(a!==void 0)throw new q("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${o.name}": produced by both ${a} and agent "${o.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=r.get(o.bindingName);if(c!==void 0)throw new q("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${o.bindingName}": produced by both ${c} and agent "${o.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const l=n.get(o.className);if(l!==void 0)throw new q("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${o.className}": produced by both ${l} and agent "${o.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},rc=e=>{const t=tc(e);return t?new Xe({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Xe({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},qc=(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=>pt(c))),o=pt(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!n.has(l)&&e.removeSourceFile(c)}},Bc=e=>{const t=ec(),s=t?fe.now():0,r=g(e.projectRoot,e.lunoraDirectory??"lunora"),n=g(r,"schema.ts");if(!E(n))throw new q("INTERNAL",`schema.ts not found at ${n}`);const o=e.project??rc(r),a=Ts(o,n,e.projectRoot),c=Gt(o,r),l=ps(o,r),p=ys(o,r),y=ks(o,r),I=Ns(o,r),R=di(o,r),Se=xn(o,r),v=Ms(o,r),D=ws(o,r),b=Ht(o,r);sc(v,b);const Q=Qt(o,r,v,b),C=Jt(o,r),ve=e.lint===!1?[]:Vt({adminRoutes:Ys(o,r),aiRawRuns:ir(o,r),aiToolSideEffects:mr(o,r),argumentDerivedFetches:yr(o,r),argumentValidators:Lr(o,r),authApiCalls:_t(o,r),authConfigs:qr(o,r),browserUrlAccesses:Gr(o,r),configCalls:en(o,r),containerKeyAccesses:sn(o,r),containerOverrides:ln(o,r),containers:C,exportSinks:An(o,r),failOpenGuards:wn(o,r),flagSecurityDefaults:jn(o,r),geoIndexUsages:Bn(o,r),httpActionGuards:Qn(o,r),httpHeaderWrites:oi(o,r),identityClaimReads:Ei(o,r),imageDeliveryUrlAccesses:Ni(o,r),inserts:ms(o,r),kvKeyAccesses:vi(o,r),mailRecipientAccesses:Li(o,r),maskProcedures:xs(o,r),maskStrategies:hs(o,r),mutatorWrites:Ki(o,r),nondeterministicCalls:Ss(o,r),normalizeIdAuthorizations:Zi(o,r),notifyCalls:bs(o,r),notifyConfig:vs(o,r),ownerFieldWrites:oo(o,r),unrestrictedWhereBranches:Ba(o,r),paymentWebhooks:fo(o,r),privilegedDispatches:Po(o,r),procedureProtections:Vo(o,r),queries:Ps(o,r),queues:D,r2sqlCalls:Is(o,r),ratelimitKeySelectors:Qo(o,r),rawRowReturns:ra(o,r),relationLoads:ua(o,r),rlsProcedures:Os(o,r),schema:a,secretLiterals:ga(o,r),shapes:y,softDeleteReads:ha(o,r),sqlInterpolations:va(o,r),storageKeyAccesses:Pa(o,r),storageUploads:Da(o,r),vectorNamespaceAccesses:_a(o,r),workflowCalls:Xa(o,r),workflows:v,wranglerVariables:e.wranglerVariables}),Tt=Ls(o,r),Dt=Es(o,r),X=Ks(o,r),A=On(o,r),Z=A.ai,Y=A.payments,be=A.kv,Pe=A.access,ee=E(g(r,"flags.ts")),Ct=ee?fs(o,r):[],te=E(g(r,"notify.ts")),se=A.hyperdrive,re=Fs(o,r),kt=re.usesSandboxBrowser||re.usesSandboxContainer,ne=A.browser||re.usesSandboxBrowser,ie=A.images,oe=A.analytics,we=A.pipelines,ae=A.r2sql,ce=A.x402,O=ao(e.projectRoot),M=Dn(A,{containerCount:C.length,cronCount:Q.length,dependencies:O,hasPaymentTables:Tn(a.tables),queueCount:D.length,storageColumnCount:Object.keys(Xt(a)).length,storageRuleCount:X.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:v.length}),F=O.has("lunorash"),Ie=t?fe.now():0,Oe=Zt(a,F),Le=Yt({agents:b,functions:c,httpRoutes:l,mutators:I,useUmbrella:F,workflows:v}),Fe=es({agents:b,containers:C,env:Se,hasAccessFacade:Pe,hasAi:Z,hasAnalytics:oe,hasBrowser:ne,hasFlags:ee,hasHyperdrive:se,hasImages:ie,hasKv:be,hasNotify:te,hasPayments:Y,hasPipelines:we,hasR2sql:ae,hasX402:ce,identity:R,queues:D,schema:a,storageRuleBuckets:X.rules.map(m=>m.bucket),useUmbrella:F,workflows:v}),Te=ts({agents:b,functions:c,migrations:p,mutators:I,shapes:y,useUmbrella:F,usesSandbox:kt}),De=ss({advisories:ve,agents:b,containers:C,env:Se,flagKeys:Ct,hasAccessFacade:Pe,hasAi:Z,hasAnalytics:oe,hasBrowser:ne,hasFlags:ee,hasHyperdrive:se,hasImages:ie,hasKv:be,hasNotify:te,hasPayments:Y,hasPipelines:we,hasR2sql:ae,hasX402:ce,maskMetadata:Dt,mutators:I,queues:D,rlsMetadata:Tt,schema:a,shapes:y,storageRules:X,studioFeatures:M,useUmbrella:F,workflows:v}),Ce=rs(y,O.has("@lunora/db"),F),ke=ns(C,a.jurisdiction),Ke=is(v),Re=os(b),Me=as(D),je=cs(Q),ze=us(a.vectorIndexes),j=ls(a,F),qe=ds(O.has("@lunora/seed")),z=e.apiSpec??"openapi",ue=z==="openapi"||z==="both",le=z==="openrpc"||z==="both",Be=js({emailAgents:b.filter(m=>m.onEmail===!0).map(m=>({bindingName:m.bindingName,exportName:m.exportName})),hasAccess:O.has("@lunora/cloudflare-access"),hasAi:Z,hasAnalytics:oe,hasAuth:O.has("@lunora/auth"),hasBrowser:ne,hasFramework:O.has("@lunora/astro")||O.has("@lunora/svelte")||O.has("@lunora/vue"),hasGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend!=="hyperdrive"),hasHyperdrive:se,hasHyperdriveGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend==="hyperdrive"),hasImages:ie,hasKv:M.kv,hasNotify:te,hasPayments:Y,hasR2sql:ae,hasQueue:D.some(m=>m.mode==="push"),hasScheduler:M.scheduler,hasStorage:M.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:v.length>0,hasX402:ce,identity:R,jurisdiction:a.jurisdiction,useUmbrella:F,voiceAgents:b.filter(m=>m.voice===!0&&m.voiceBindingName!==void 0).map(m=>({bindingName:m.voiceBindingName,exportName:m.exportName})),wantsOpenApi:ue,wantsOpenRpc:le}),Ve=Ya(e.projectRoot),Ue=zs({functions:c,httpRoutes:l,version:Ve}),We=Bs({functions:c,version:Ve}),Ge=`${JSON.stringify(Ue,void 0,2)}
|
|
2
|
+
`,He=`${JSON.stringify(We,void 0,2)}
|
|
3
|
+
`,_e=qs(Ue),Je=Vs(We),Qe=Us(a,p.map(m=>m.id)),de=g(r,Za),Kt=E(de),x=g(r,"_generated");if(e.dryRun||(E(x)||zt(x,{recursive:!0}),$(g(x,"app.ts"),Be),$(g(x,"dataModel.ts"),Oe),$(g(x,"api.ts"),Le),$(g(x,"server.ts"),Fe),$(g(x,"functions.ts"),Te),$(g(x,"shard.ts"),De),$(g(x,"crons.ts"),je),$(g(x,"vectors.ts"),ze),$(g(x,"drizzle.global.ts"),j.global),$(g(x,"drizzle.shard.ts"),j.shard),P(g(x,"containers.ts"),ke),P(g(x,"workflows.ts"),Ke),P(g(x,"agents.ts"),Re),P(g(x,"queues.ts"),Me),P(g(x,"seed.ts"),qe),P(g(x,"collections.ts"),Ce),P(g(x,"openapi.json"),ue?Ge:""),P(g(x,"openapi.ts"),ue?_e:""),P(g(x,"openrpc.json"),le?He:""),P(g(x,"openrpc.ts"),le?Je:""),(!Kt||e.updateSchemaBaseline===!0)&&$(de,Ws(Qe))),t){const m=fe.now(),Rt=Math.round(m-s),Mt=Math.round(Ie-s),jt=Math.round(m-Ie);console.error(`@lunora/codegen: codegen took ${Rt.toString()}ms (discovery ${Mt.toString()}ms, emit ${jt.toString()}ms)`)}return{advisories:ve,agents:b,containers:C,cronTriggers:gs(Q),generated:{agents:Re,api:Le,app:Be,collections:Ce,containers:ke,crons:je,dataModel:Oe,drizzleGlobal:j.global,drizzleShard:j.shard,functions:Te,openApi:Ge,openApiModule:_e,openRpc:He,openRpcModule:Je,queues:Me,seed:qe,server:Fe,shard:De,vectors:ze,workflows:Ke},outputDirectory:x,queues:D,schemaSnapshot:Qe,schemaSnapshotPath:de,workflows:v}};export{Za as SCHEMA_SNAPSHOT_FILENAME,rc as createCodegenProject,qc as refreshCodegenProject,Bc as runCodegen};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{d as
|
|
1
|
+
import{d as S,w as D}from"./emit-Bp0nOR_O.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";']:[],x=(e,t)=>e?['import type { CreateAccessResolverOptions } from "@lunora/cloudflare-access";',`import { createAccessResolver${t?", composeResolvers":""} } from "@lunora/cloudflare-access";`]:[],R=e=>e?['import { createKvIntrospectorFromEnv } from "@lunora/bindings/kv";']:[],O=e=>e?['import notifyConfig from "../notify.js";']:[],k=e=>(e.emailAgents?.length??0)>0,C=e=>k(e)?['import { dispatchAgentEmail } from "@lunora/agent/inbound";']:[],j=e=>k(e)?['import * as lunoraAgentDefinitions from "../agents.js";']:[],L=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","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";']:[],...x(t,r),...n?['import type { D1CtxDbOptions, D1DatabaseLike, D1Exec } from "@lunora/d1";','import { createD1CtxDb, facetGlobalColumn, listGlobalTables, readGlobalTablePage } from "@lunora/d1";']:[],...o?['import type { HyperdriveEngine } from "@lunora/hyperdrive/global";','import { createHyperdriveGlobalCtxDb } from "@lunora/hyperdrive/global";','import type { SqlCtxDbOptions, SqlExec } from "@lunora/sql-store";']:[],...R(l),...u?['import type { DurableObjectNamespaceLike } from "@lunora/scheduler";','import { createScheduler } from "@lunora/scheduler";']:[],...d?['import type { R2BucketLike, Storage } from "@lunora/storage";','import { createBucketStorage, createStorage } from "@lunora/storage";']:[],...h?['import { createWorkflowsRestClient } from "@lunora/workflow";']:[],...C(e),`import type { ${[...g].toSorted((w,y)=>w.localeCompare(y)).join(", ")} } from "${i}";`,`import { ${f} } from "${i}";`,"",...A(e.identity),...j(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";']},q=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>;
|
|
@@ -8,22 +8,17 @@ interface StorageDeclaration<Env> {
|
|
|
8
8
|
publicBaseUrl?: Selector<Env, string>;
|
|
9
9
|
/** HMAC secret for signed URLs. */
|
|
10
10
|
signingSecret?: Selector<Env, string>;
|
|
11
|
-
}`]:[],...e.hasScheduler?["/** `.scheduler(...)` declaration — the `SchedulerDO` namespace plus the worker origin its callbacks dispatch back to. Backs `ctx.scheduler` AND the studio's scheduled-jobs view. */\ninterface SchedulerDeclaration<Env> {\n /** The `SchedulerDO` namespace binding (typically `env.SCHEDULER`). */\n namespace: Selector<Env, DurableObjectNamespaceLike & ShardNamespaceLike>;\n /** The worker origin the `SchedulerDO` dispatches HTTP job callbacks back to. */\n origin?: Selector<Env, string>;\n}"]:[],...e.hasGlobal?["/** `.global(...)` declaration — the D1 binding backing `.global()` tables. Backs cross-tenant `ctx.db` reads/writes AND the studio's global data browser. */\ninterface GlobalDeclaration<Env> {\n /** The D1 binding (typically `env.DB`). */\n d1: Selector<Env, D1DatabaseLike>;\n /** The worker origin used to fan reverse cross-backend relations across shards. Without it, such a relation throws a clear error. */\n origin?: Selector<Env, string>;\n}"]:[],...e.hasHyperdriveGlobal?['/** `.hyperdriveGlobal(...)` declaration — backs `.global({ backend: "hyperdrive" })` tables on a Postgres/MySQL database via Hyperdrive. Stays reactive: the writer is injected as `globalDb` and the broadcast hook drives live queries. */\ninterface HyperdriveGlobalDeclaration<Env> {\n /** The Hyperdrive engine — selects the Postgres or MySQL dialect. */\n engine: HyperdriveEngine;\n /** Build the `SqlExec` from `env` — e.g. `buildPgExec(fromPostgresJs(postgres(env.HYPERDRIVE.connectionString)))`. Cache the driver on the DO instance; rebuild lazily after hibernation. */\n exec: (env: Env) => SqlExec;\n /** The worker origin used to fan reverse cross-backend relations across shards. Without it, such a relation throws a clear error. */\n origin?: Selector<Env, string>;\n}']:[],...e.hasAuth?[
|
|
11
|
+
}`]:[],...e.hasScheduler?["/** `.scheduler(...)` declaration — the `SchedulerDO` namespace plus the worker origin its callbacks dispatch back to. Backs `ctx.scheduler` AND the studio's scheduled-jobs view. */\ninterface SchedulerDeclaration<Env> {\n /** The `SchedulerDO` namespace binding (typically `env.SCHEDULER`). */\n namespace: Selector<Env, DurableObjectNamespaceLike & ShardNamespaceLike>;\n /** The worker origin the `SchedulerDO` dispatches HTTP job callbacks back to. */\n origin?: Selector<Env, string>;\n}"]:[],...e.hasGlobal?["/** `.global(...)` declaration — the D1 binding backing `.global()` tables. Backs cross-tenant `ctx.db` reads/writes AND the studio's global data browser. */\ninterface GlobalDeclaration<Env> {\n /** The D1 binding (typically `env.DB`). */\n d1: Selector<Env, D1DatabaseLike>;\n /** The worker origin used to fan reverse cross-backend relations across shards. Without it, such a relation throws a clear error. */\n origin?: Selector<Env, string>;\n}"]:[],...e.hasHyperdriveGlobal?['/** `.hyperdriveGlobal(...)` declaration — backs `.global({ backend: "hyperdrive" })` tables on a Postgres/MySQL database via Hyperdrive. Stays reactive: the writer is injected as `globalDb` and the broadcast hook drives live queries. */\ninterface HyperdriveGlobalDeclaration<Env> {\n /** The Hyperdrive engine — selects the Postgres or MySQL dialect. */\n engine: HyperdriveEngine;\n /** Build the `SqlExec` from `env` — e.g. `buildPgExec(fromPostgresJs(postgres(env.HYPERDRIVE.connectionString)))`. Cache the driver on the DO instance; rebuild lazily after hibernation. */\n exec: (env: Env) => SqlExec;\n /** The worker origin used to fan reverse cross-backend relations across shards. Without it, such a relation throws a clear error. */\n origin?: Selector<Env, string>;\n}']:[],...e.hasAuth?['/** `.auth(...)` declaration — better-auth options plus the storage the adapter reads. Give it `d1` (the default) or `namespace` (a Durable Object that hosts the auth tables), never both. The builder owns the lazy build + `ensureMigrated` dance and wires `authHandler` / `resolveIdentity` / `authAdmin`. */\ninterface AuthDeclaration<Env> {\n /** The D1 binding the auth SQL adapter is wired over (via `lunoraD1Adapter`). Omit only when using `namespace`. */\n d1?: Selector<Env, unknown>;\n /** Shared secret the worker presents on the object\'s internal session route. REQUIRED with `namespace`: the binding is reachable from any worker bound to it, so the secret — not the binding — is the authorization boundary. Without it identity resolution fails closed. */\n internalSecret?: Selector<Env, string>;\n /** Name of the Durable Object instance holding the auth tables. Defaults to `"auth"`. Set it to run separate auth objects (per deployment, per tenant) off one namespace. */\n objectName?: Selector<Env, string>;\n /** The auth Durable Object namespace — the DO-backed mode. Needed for `@better-auth/scim`, which requires native transactions that D1 has none of. The object owns the auth tables, so `/api/auth/*` and identity resolution both go through it. */\n namespace?: Selector<Env, ShardNamespaceLike>;\n /** Build the better-auth options from `env` (secret, plugins, email/password, …). */\n options: (env: Env) => LunoraAuthOptions;\n}']:[]],T=e=>[...e.hasAccess?[" private accessSelector?: Selector<Env, CreateAccessResolverOptions>;"]:[]," private adminToken?: Selector<Env, string>;",...e.hasAuth?[" private authDeclaration?: AuthDeclaration<Env>;"]:[]," private readonly extendFns: ((env: Env, derived: Readonly<WorkerOptions>) => Partial<WorkerOptions>)[] = [];",...e.hasGlobal?[" private globalDeclaration?: GlobalDeclaration<Env>;"]:[],...e.hasHyperdriveGlobal?[" private hyperdriveGlobalDeclaration?: HyperdriveGlobalDeclaration<Env>;"]:[]," private readonly routeMap: Record<string, Route> = {};",...e.hasScheduler?[" private schedulerDeclaration?: SchedulerDeclaration<Env>;"]:[],...v(e)?[" private readonly shardExtras: Partial<ShardConfig> = {};"]:[]," private shardSelector?: Selector<Env, ShardNamespaceLike>;",...e.hasStorage?[" private storageDeclaration?: StorageDeclaration<Env>;"]:[]],N=e=>m.filter(([t])=>e[t]).map(([,t,r,a])=>` /** ${a} */
|
|
12
12
|
public ${t}(factory: NonNullable<ShardConfig["${r}"]>): this {
|
|
13
13
|
this.shardExtras.${r} = factory;
|
|
14
14
|
|
|
15
15
|
return this;
|
|
16
|
-
}`),
|
|
16
|
+
}`),W=e=>[...e.hasAccess?[" /** Wire Cloudflare Access (Zero Trust) — verifies the `Cf-Access-Jwt-Assertion` JWT and feeds the identity into `ctx.auth` / RLS via `resolveIdentity`. When `.auth(...)` is also configured, Access is composed ahead of it (Access wins when its JWT is present; everyone else falls through to the app session). */\n public access(selector: Selector<Env, CreateAccessResolverOptions>): this {\n this.accessSelector = selector;\n\n return this;\n }"]:[],` /** Bearer token gating the \`/_lunora/admin/*\` endpoints the studio calls. */
|
|
17
17
|
public admin(selector: Selector<Env, string>): this {
|
|
18
18
|
this.adminToken = selector;
|
|
19
19
|
|
|
20
20
|
return this;
|
|
21
|
-
}`,...e.hasAuth?[
|
|
22
|
-
public auth(declaration: AuthDeclaration<Env>): this {
|
|
23
|
-
this.authDeclaration = declaration;
|
|
24
|
-
|
|
25
|
-
return this;
|
|
26
|
-
}`]:[]," /** Escape hatch — merge raw `WorkerOptions` (anything not yet sugared) over the derived options at build time. The second `derived` argument is a snapshot of the options assembled so far (after `.auth(...)` etc.), so you can compose rather than clobber — e.g. wrap `derived.resolveIdentity` instead of replacing it. */\n public extend(fn: (env: Env, derived: Readonly<WorkerOptions>) => Partial<WorkerOptions>): this {\n this.extendFns.push(fn);\n\n return this;\n }",...e.hasGlobal?[` /** Back \`.global()\` (cross-tenant) tables with D1 — wires \`ctx.db\` routing, the studio global browser, and reverse cross-shard relations. */
|
|
21
|
+
}`,...e.hasAuth?[' /** Wire better-auth — the builder lazily builds the instance, runs `ensureMigrated`, and dispatches `/api/auth/*` inside the worker (instrumented for the auth-failure SLO). Pass `d1` for the D1-backed default, or `namespace` + `internalSecret` to host the auth tables in a Durable Object (what `@better-auth/scim` needs). */\n public auth(declaration: AuthDeclaration<Env>): this {\n // Reject the ambiguous and the empty shapes here rather than at the first\n // request: with neither storage set, auth would silently never answer, and\n // with both it is unclear which one owns the tables.\n if (declaration.d1 && declaration.namespace) {\n throw new Error(".auth(): pass either `d1` or `namespace`, not both — they are two different homes for the same tables.");\n }\n\n if (!declaration.d1 && !declaration.namespace) {\n throw new Error(".auth(): needs `d1` (D1-backed) or `namespace` (Durable-Object-backed) to know where the auth tables live.");\n }\n\n if (declaration.namespace && !declaration.internalSecret) {\n throw new Error(\n ".auth(): `namespace` requires `internalSecret` — the auth DO binding is reachable from any worker bound to it, so identity resolution is gated on a shared secret and would otherwise fail closed on every request.",\n );\n }\n\n this.authDeclaration = declaration;\n\n return this;\n }']:[]," /** Escape hatch — merge raw `WorkerOptions` (anything not yet sugared) over the derived options at build time. The second `derived` argument is a snapshot of the options assembled so far (after `.auth(...)` etc.), so you can compose rather than clobber — e.g. wrap `derived.resolveIdentity` instead of replacing it. */\n public extend(fn: (env: Env, derived: Readonly<WorkerOptions>) => Partial<WorkerOptions>): this {\n this.extendFns.push(fn);\n\n return this;\n }",...e.hasGlobal?[` /** Back \`.global()\` (cross-tenant) tables with D1 — wires \`ctx.db\` routing, the studio global browser, and reverse cross-shard relations. */
|
|
27
22
|
public global(declaration: GlobalDeclaration<Env>): this {
|
|
28
23
|
this.globalDeclaration = declaration;
|
|
29
24
|
|
|
@@ -58,7 +53,7 @@ interface StorageDeclaration<Env> {
|
|
|
58
53
|
this.storageDeclaration = declaration;
|
|
59
54
|
|
|
60
55
|
return this;
|
|
61
|
-
}`]:[],...
|
|
56
|
+
}`]:[],...N(e)],$=e=>{const t=[...e.hasGlobal?[` ...(this.globalDeclaration
|
|
62
57
|
? {
|
|
63
58
|
d1: (rawEnv: Record<string, unknown>, request?: { identity?: Record<string, unknown>; userId?: string | null }) => {
|
|
64
59
|
const env = rawEnv as Env;
|
|
@@ -115,10 +110,10 @@ interface StorageDeclaration<Env> {
|
|
|
115
110
|
return namespace && origin ? createScheduler({${e.jurisdiction?` jurisdiction: ${JSON.stringify(e.jurisdiction)},`:""} namespace, originUrl: origin }) : undefined;
|
|
116
111
|
},
|
|
117
112
|
}
|
|
118
|
-
: {}),`]:[],...e.hasStorage?[" ...(this.storageDeclaration ? { storage: (rawEnv: Record<string, unknown>) => this.resolveStorage(rawEnv as Env) } : {}),"]:[],...
|
|
113
|
+
: {}),`]:[],...e.hasStorage?[" ...(this.storageDeclaration ? { storage: (rawEnv: Record<string, unknown>) => this.resolveStorage(rawEnv as Env) } : {}),"]:[],...v(e)?[" ...this.shardExtras,"]:[]];return t.length>0?`
|
|
119
114
|
${t.join(`
|
|
120
115
|
`)}
|
|
121
|
-
`:""},
|
|
116
|
+
`:""},I=e=>[...e.hasScheduler?[` if (this.schedulerDeclaration) {
|
|
122
117
|
options.schedulerDO = this.schedulerDeclaration.namespace(env);
|
|
123
118
|
}`]:[],...e.hasWorkflow?[` options.workflowsClient = (workflowEnv) => {
|
|
124
119
|
const source = workflowEnv as Record<string, unknown>;
|
|
@@ -137,7 +132,34 @@ ${t.join(`
|
|
|
137
132
|
}
|
|
138
133
|
}`]:[],...e.hasStorage?[` if (this.storageDeclaration) {
|
|
139
134
|
Object.assign(options, this.buildStorageAdmin(env));
|
|
140
|
-
}`]:[],...e.hasKv?[" options.kvIntrospector = createKvIntrospectorFromEnv(env);"]:[],...e.hasNotify?[" options.notifySubscriptionStore = notifyConfig.store ? notifyConfig.store(env as Record<string, unknown>) : undefined;"]:[]," options.logArchive = resolveLogArchiveFromEnv(env);",...e.hasAuth?[`
|
|
135
|
+
}`]:[],...e.hasKv?[" options.kvIntrospector = createKvIntrospectorFromEnv(env);"]:[],...e.hasNotify?[" options.notifySubscriptionStore = notifyConfig.store ? notifyConfig.store(env as Record<string, unknown>) : undefined;"]:[]," options.logArchive = resolveLogArchiveFromEnv(env);",...e.hasAuth?[` // Captured before the branch so the narrowing survives — reading
|
|
136
|
+
// \`this.authDeclaration.namespace\` again below would be optional all over again.
|
|
137
|
+
const authDeclaration = this.authDeclaration;
|
|
138
|
+
const authNamespace = authDeclaration?.namespace;
|
|
139
|
+
const authD1 = authDeclaration?.d1;
|
|
140
|
+
|
|
141
|
+
if (authDeclaration && authNamespace) {
|
|
142
|
+
// DO-backed mode. The auth tables live inside the object and DO storage is
|
|
143
|
+
// unreachable from here, so better-auth runs in there and this worker talks
|
|
144
|
+
// to it. \`createDoAuthWiring\` is a tested function in \`@lunora/auth\` rather
|
|
145
|
+
// than more emitted code: request-path logic in generated output can only be
|
|
146
|
+
// typechecked, never unit-tested.
|
|
147
|
+
const authWiring = createDoAuthWiring({
|
|
148
|
+
internalSecret: authDeclaration.internalSecret?.(env),
|
|
149
|
+
namespace: authNamespace(env),
|
|
150
|
+
objectName: authDeclaration.objectName?.(env),
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
options.authHandler = authWiring.authHandler;
|
|
154
|
+
options.resolveIdentity = authWiring.resolveIdentity;
|
|
155
|
+
// The audit log lives in the object like every other auth table, so the feed
|
|
156
|
+
// reads through it rather than querying D1.
|
|
157
|
+
options.authAuditReader = authWiring.auditReader;
|
|
158
|
+
// \`authAdmin\` stays D1-only: its ~30 methods read the auth tables directly
|
|
159
|
+
// from the worker, which DO storage does not allow. The studio's auth pages
|
|
160
|
+
// therefore report "not configured" in this mode rather than silently
|
|
161
|
+
// returning empty data.
|
|
162
|
+
} else if (authDeclaration && authD1) {
|
|
141
163
|
options.authHandler = (request) => {
|
|
142
164
|
const auth = getAuth();
|
|
143
165
|
|
|
@@ -157,7 +179,7 @@ ${t.join(`
|
|
|
157
179
|
const authInstance = getAuth();
|
|
158
180
|
|
|
159
181
|
options.authAdmin = authInstance ? createAuthAdmin(authInstance) : undefined;
|
|
160
|
-
options.authAuditReader = createAuthAuditReader(d1Executor(
|
|
182
|
+
options.authAuditReader = createAuthAuditReader(d1Executor(authD1(env) as never));
|
|
161
183
|
}`]:[],...e.hasAccess?[e.hasAuth?` if (this.accessSelector) {
|
|
162
184
|
const accessResolver = createAccessResolver(this.accessSelector(env));
|
|
163
185
|
const fallback = options.resolveIdentity;
|
|
@@ -270,17 +292,26 @@ const buildGlobalIntrospector = (database: D1DatabaseLike): GlobalIntrospector =
|
|
|
270
292
|
readTablePage: (options) => readGlobalTablePage(exec, schema as never, options),
|
|
271
293
|
};
|
|
272
294
|
};
|
|
273
|
-
`:"",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
|
|
295
|
+
`:"",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=q(e),a=I(e),n=t?` let auth: LunoraAuth | null = null;
|
|
274
296
|
`:"",o=t?`
|
|
275
297
|
const ensureAuth = async (env: Env): Promise<void> => {
|
|
276
298
|
if (!this.authDeclaration || auth) {
|
|
277
299
|
return;
|
|
278
300
|
}
|
|
279
301
|
|
|
280
|
-
|
|
302
|
+
const d1 = this.authDeclaration.d1;
|
|
303
|
+
|
|
304
|
+
// DO-backed mode builds no instance here: better-auth runs inside the
|
|
305
|
+
// object, which materialises its own schema (the Kysely migrator below is
|
|
306
|
+
// dialect-bound and cannot target DO storage).
|
|
307
|
+
if (!d1) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
auth = createAuth({ ...this.authDeclaration.options(env), database: lunoraD1Adapter(d1(env) as never) });
|
|
281
312
|
// Apply the better-auth schema lazily on first request (raw-D1 Kysely
|
|
282
313
|
// migrator). For production run the migrate command ahead of deploy.
|
|
283
|
-
await ensureMigrated(createAuth({ ...this.authDeclaration.options(env), database:
|
|
314
|
+
await ensureMigrated(createAuth({ ...this.authDeclaration.options(env), database: d1(env) as never }));
|
|
284
315
|
};
|
|
285
316
|
`:"",l=t?`
|
|
286
317
|
await ensureAuth(env);`:"",s=t?"() => auth":"() => null",u=t?"getAuth: () => LunoraAuth | null":"_getAuth: () => null",d=e.hasFramework?` const buildWorker = (env: Env): LunoraWorker =>
|
|
@@ -289,15 +320,15 @@ ${c.map(i=>` { agent: lunoraAgentDefinitions.${i.exportName}, binding
|
|
|
289
320
|
`)}
|
|
290
321
|
]);
|
|
291
322
|
|
|
292
|
-
`:"",
|
|
323
|
+
`:"",b=` /** Materialise the standalone Cloudflare worker + \`ShardDO\` class. */
|
|
293
324
|
public build(): ComposedApp {
|
|
294
325
|
return this.assemble();
|
|
295
|
-
}${e.hasFramework?"\n\n /** Compose Lunora's realtime plane INTO a meta-framework's Cloudflare handler (SvelteKit/Astro/Nuxt). The framework `host` serves everything except the reserved `/_lunora/*` endpoints; pass the adapter-emitted worker (e.g. SvelteKit's `_worker.js`, Astro's `handle`). */\n public buildFrameworkWorker(host: FrameworkHostHandler): ComposedApp {\n return this.assemble(host);\n }":""}`;return`${
|
|
326
|
+
}${e.hasFramework?"\n\n /** Compose Lunora's realtime plane INTO a meta-framework's Cloudflare handler (SvelteKit/Astro/Nuxt). The framework `host` serves everything except the reserved `/_lunora/*` endpoints; pass the adapter-emitted worker (e.g. SvelteKit's `_worker.js`, Astro's `handle`). */\n public buildFrameworkWorker(host: FrameworkHostHandler): ComposedApp {\n return this.assemble(host);\n }":""}`;return`${D}${L(e).join(`
|
|
296
327
|
`)}
|
|
297
328
|
|
|
298
329
|
/** Read a value off the per-request \`env\`. Returns \`undefined\` to leave the capability unconfigured (its \`ctx.*\`/admin surface stays a clear-error stub). */
|
|
299
330
|
type Selector<Env, T> = (env: Env) => T | undefined;
|
|
300
|
-
${
|
|
331
|
+
${v(e)?"\n/** The generated `createShardDO` config — the long-tail `.ai()` / `.kv()` / … methods pass straight through to it. */\ntype ShardConfig = NonNullable<Parameters<typeof createShardDO>[0]>;\n":""}
|
|
301
332
|
${r.join(`
|
|
302
333
|
|
|
303
334
|
`)}${r.length>0?`
|
|
@@ -317,26 +348,26 @@ interface ComposedApp extends LunoraWorker {
|
|
|
317
348
|
* first request so per-isolate singletons are built once.
|
|
318
349
|
*/
|
|
319
350
|
class AppBuilder<Env extends object> {
|
|
320
|
-
${
|
|
351
|
+
${T(e).join(`
|
|
321
352
|
`)}
|
|
322
353
|
|
|
323
354
|
private emailHandler?: (env: Env) => (message: unknown, env: unknown, context: ExecutionContextLike) => Promise<void>;
|
|
324
355
|
|
|
325
|
-
${
|
|
356
|
+
${W(e).join(`
|
|
326
357
|
|
|
327
358
|
`)}
|
|
328
359
|
|
|
329
|
-
${
|
|
360
|
+
${b}
|
|
330
361
|
|
|
331
362
|
/** Build the shard DO + compose the worker (standalone or framework-hosted), wrapping the lazy per-isolate singletons + auth init. */
|
|
332
363
|
private assemble(${h}): ComposedApp {
|
|
333
|
-
const ShardDO = createShardDO({${
|
|
364
|
+
const ShardDO = createShardDO({${$(e)}});
|
|
334
365
|
|
|
335
366
|
// Per-isolate singletons: the worker (and auth instance) are expensive to
|
|
336
367
|
// build, so the first request constructs them and every later request on
|
|
337
368
|
// the same isolate reuses them.
|
|
338
369
|
let worker: LunoraWorker | null = null;
|
|
339
|
-
${
|
|
370
|
+
${n}${o}
|
|
340
371
|
${d}
|
|
341
372
|
|
|
342
373
|
const composed: ComposedApp = {
|
|
@@ -384,9 +415,9 @@ ${G(e).join(`
|
|
|
384
415
|
options.adminToken = this.adminToken(env);
|
|
385
416
|
}
|
|
386
417
|
|
|
387
|
-
${
|
|
418
|
+
${a.join(`
|
|
388
419
|
|
|
389
|
-
`)}${
|
|
420
|
+
`)}${a.length>0?`
|
|
390
421
|
|
|
391
422
|
`:""} for (const fn of this.extendFns) {
|
|
392
423
|
Object.assign(options, fn(env, { ...options }));
|
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.69",
|
|
4
4
|
"description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@lunora/advisor": "1.0.0-alpha.
|
|
50
|
-
"@lunora/agent": "1.0.0-alpha.
|
|
49
|
+
"@lunora/advisor": "1.0.0-alpha.48",
|
|
50
|
+
"@lunora/agent": "1.0.0-alpha.24",
|
|
51
51
|
"@lunora/container": "1.0.0-alpha.16",
|
|
52
52
|
"@lunora/errors": "1.0.0-alpha.8",
|
|
53
53
|
"@lunora/queue": "1.0.0-alpha.10",
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{existsSync as E,readFileSync as Ae,mkdirSync as zt,writeFileSync as qt,rmSync as Bt}from"node:fs";import{join as g,dirname as ge}from"node:path";import{performance as fe}from"node:perf_hooks";import{LunoraError as q}from"@lunora/errors";import{Node as i,SyntaxKind as u,Project as Xe}from"ts-morph";import{lintSchema as Vt}from"./formatAdvisories-DZvv-0MG.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as f,classifyProcedureCall as K,inlineHandler as Ut,procedureHandler as mt,chainUsesWrappedCall as xt,isDatabaseAccessor as k,chainHasStep as Wt,discoverFunctions as Gt}from"./discoverFunctions-zrIQk7J8.mjs";import{discoverAgents as Ht}from"./AGENTS_FILENAME-BesaDYkL.mjs";import _t from"./discoverAuthApiCalls-Ba6W92HB.mjs";import{discoverContainers as Jt}from"./CONTAINERS_FILENAME-CFwdyaCI.mjs";import Qt from"./discoverCrons-2nUpw6do.mjs";import{diagnosticAt as H}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{o as _}from"./module-specifiers-8FEEiUcv.mjs";import{a as pe,X as Xt,H as Zt,s as Yt,h as es,b as ts,J as ss,c as rs,_ as ns,M as is,B as os,j as as,t as cs,n as us,e as ls,l as ds,r as gs}from"./emit-Bp0nOR_O.mjs";import{discoverFlagKeys as fs}from"./FLAGS_FILENAME-C1GWerCB.mjs";import ps from"./discoverHttpRoutes-Bf_T_03b.mjs";import ms from"./discoverInserts-DveVeP5h.mjs";import xs,{discoverMaskStrategies as hs,discoverMaskMetadata as Es}from"./discoverMaskProcedures-BkBquCFR.mjs";import ys from"./discoverMigrations-T2xb-1rn.mjs";import{MUTATORS_FILENAME as As,isDefineMutatorCallee as $s,discoverMutators as Ss}from"./MUTATORS_FILENAME-BWPAtQ2T.mjs";import Ns from"./discoverNondeterministicCalls-BymnOR9k.mjs";import{discoverNotifyConfig as vs,discoverNotifyCalls as bs}from"./NOTIFY_FILENAME-DP6qvFBX.mjs";import Ps from"./discoverQueries-DNRA-G2a.mjs";import{discoverQueues as ws}from"./QUEUES_FILENAME-CSE6i-ld.mjs";import Is from"./discoverR2sqlCalls-YEjvGcEq.mjs";import Os,{discoverRlsMetadata as Fs}from"./discoverRlsMetadata-DO3qlLXX.mjs";import{discoverSandboxUsage as Ls}from"./discoverSandboxUsage-JwrmSN9l.mjs";import Ts from"./discoverSchema-m2voTncu.mjs";import{secretKindOf as Ds,redact as Cs}from"./redact-CQ8-to6l.mjs";import{discoverShapes as ks}from"./SHAPES_FILENAME-maut3z1K.mjs";import Ks from"./discoverStorageRulesMetadata-CCztRKjw.mjs";import{e as Rs}from"./discover-ast-CezKqEhE.mjs";import{discoverWorkflows as Ms}from"./WORKFLOWS_FILENAME-Bk5upkGM.mjs";import{emitApp as js}from"./emitApp-BzO6O7Lx.mjs";import{buildOpenApiDocument as zs,emitOpenApiModule as qs}from"./buildOpenApiDocument-BJudKDP_.mjs";import{buildOpenRpcDocument as Bs,emitOpenRpcModule as Vs}from"./OPENRPC_VERSION-BcivFYIX.mjs";import{buildSchemaSnapshot as Us,serializeSchemaSnapshot as Ws}from"./SCHEMA_SNAPSHOT_VERSION-Bpf1FGMG.mjs";const ht=new Set(["delete","get","head","options","patch","post","put"]),Gs=new Set(["handler","stream"]),Hs=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,Ze=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),_s=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ht.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()}},Js=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)||ht.has(r.getName()))break;s=r.getExpression()}return _s(s)},Qs=e=>{for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression))if(Ze.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&Ze.has(s.getText()))return!0}return!1},Xs=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||!Gs.has(r.getName()))return;const n=Js(s);if(!n||!Hs.test(n.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&Qs(o);return{exportName:e.getName(),file:t,method:n.method,path:n.path,usesGuard:a}},Zs=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Xs(n,t);o&&s.push(o)}return s},Ys=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Zs(n,f(t,r)))}return s},Ye=e=>{if(e.getText()!=="args")return!1;const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(i.isPropertyAssignment(t)&&t.getNameNode()===e)},et=e=>{if(e.getText()!=="ctx")return!1;const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(i.isPropertyAssignment(t)&&t.getNameNode()===e)},me=e=>i.isIdentifier(e)?et(e):e.getDescendantsOfKind(u.Identifier).some(t=>et(t)),tt=(e,t)=>{if(e.getText()!==t)return!1;const s=e.getParent();return i.isPropertyAccessExpression(s)&&s.getNameNode()===e?!1:!(i.isPropertyAssignment(s)&&s.getNameNode()===e)},er=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t:void 0},b=e=>{if(i.isIdentifier(e))return e.getText();if(i.isPropertyAccessExpression(e))return e.getName()},Ee=e=>i.isIdentifier(e)?Ye(e):e.getDescendantsOfKind(u.Identifier).some(t=>Ye(t)),F=e=>{if(!i.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a));if(s===void 0)return;const r=e.getStart();let n,o=-1;for(const a of s.getDescendantsOfKind(u.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<r&&l>o&&(n=c,o=l)}return n},P=e=>{if(Ee(e))return!0;const t=F(e);return t!==void 0&&Ee(t)},T=e=>{if(me(e))return!0;const t=F(e);if(t!==void 0&&me(t))return!0;const s=t??e;return(i.isIdentifier(s)?[s]:s.getDescendantsOfKind(u.Identifier)).some(r=>{const n=F(r);return n!==void 0&&me(n)})},B=(e,t)=>i.isIdentifier(e)?tt(e,t):e.getDescendantsOfKind(u.Identifier).some(s=>tt(s,t)),tr=(e,t)=>{if(B(e,t))return!0;const s=F(e);if(s!==void 0&&B(s,t))return!0;const r=er(e);if(r!==void 0){const n=F(r);return n!==void 0&&B(n,t)}return!1},h=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)&&t.getVariableStatement()?.hasExportKeyword()===!0)return t.getName();return"<module>"},sr=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",rr=(e,t)=>{if(!sr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!P(s)||T(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},nr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=rr(r,t);n&&s.push(n)}return s},ir=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...nr(n,f(t,r)))}return s},or=new Set(["generateText","streamText"]),ar=new Set(["messages","prompt","system"]),cr=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],ur=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),r=t.getExpression().getText();for(const n of cr)if(n.methods.has(s)&&n.prefixes.some(o=>r===o||r.startsWith(`${o}.`)))return`${r}.${s}`},lr=e=>{for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=ur(t);if(s!==void 0)return s}},dr=e=>{const t=new Set,s=e.getFirstAncestor(o=>i.isArrowFunction(o)||i.isFunctionExpression(o)||i.isFunctionDeclaration(o)),[r]=s?.getParameters()??[],n=r?.getNameNode();if(n===void 0||!i.isObjectBindingPattern(n))return t;for(const o of n.getElements()){const a=o.getPropertyNameNode()?.getText()??o.getName(),c=o.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},gr=e=>{if(Ee(e))return!0;const t=dr(e);return t.size===0?!1:e.getDescendantsOfKind(u.Identifier).some(s=>t.has(s.getText()))},fr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!ar.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&gr(s))return!0}return!1},pr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=b(r.getExpression());if(n===void 0||!or.has(n))continue;const[o]=r.getArguments();if(o===void 0||!i.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(u.CallExpression))if(b(c.getExpression())==="tool"&&(a=lr(c),a!==void 0))break;a!==void 0&&s.push({exportName:h(r),file:t,line:r.getStartLineNumber(),method:n,sideEffect:a,userInputDerived:fr(o)})}return s},mr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...pr(n,f(t,r)))}return s},xr=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},hr=(e,t)=>{if(!xr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!P(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},Er=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=hr(r,t);n&&s.push(n)}return s},yr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Er(n,f(t,r)))}return s},Ar=/\.check\(|\.meta\(|length|max/iu,$r=/\bv\.any\s*\(/u,Sr=/\bv\.string\s*\(/u,Nr=e=>$r.test(e),vr=e=>Sr.test(e)&&!Ar.test(e),br=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("args");if(!s||!i.isPropertyAssignment(s))return;const r=s.getInitializer();return r&&i.isObjectLiteralExpression(r)?r:void 0},Pr=e=>{const t=[];let s=e;for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const n=s.getArguments()[0];n&&i.isObjectLiteralExpression(n)&&t.push(n)}s=r.getExpression()}return t},wr=e=>{const t=[],s=[];for(const r of e)for(const n of r.getProperties()){if(!i.isPropertyAssignment(n))continue;const o=n.getInitializer();if(!o)continue;const a=o.getText(),c=n.getName();Nr(a)?t.push(c):vr(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Ir=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=K(s);if(r?.visibility!=="public")return;const n=r.receiver?Pr(r.receiver):[br(s)].filter(c=>c!==void 0),{anyArgs:o,unboundedStringArgs:a}=wr(n);if(!(o.length===0&&a.length===0))return{anyArgs:o,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Or=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Ir(n,t);o&&s.push(o)}return s},Fr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Or(n,f(t,r)))}return s},O=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},xe=e=>e?.getKind()===u.TrueKeyword,Lr=e=>e?.getKind()===u.FalseKeyword,Tr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Dr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),Cr=e=>{const t=O(e,"advanced"),s=O(e,"emailAndPassword"),r=O(e,"session");return{analyzable:!0,disableCsrfCheck:xe(O(t,"disableCSRFCheck")),emailPasswordEnabled:xe(O(s,"enabled")),requireEmailVerification:xe(O(s,"requireEmailVerification")),secureCookiesDisabled:Lr(O(t,"useSecureCookies")),sessionFreshAgeZero:Tr(O(r,"freshAge")),trustedOriginsWildcard:Dr(O(e,"trustedOrigins"))}},kr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Kr=(e,t)=>{if(b(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],r=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(o=>i.isSpreadAssignment(o)),n=s!==void 0&&i.isObjectLiteralExpression(s)&&!r?Cr(s):kr();return{exportName:h(e),file:t,line:e.getStartLineNumber(),...n}},Rr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Kr(r,t);n&&s.push(n)}return s},Mr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Rr(n,f(t,r)))}return s},jr=(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},zr=(e,t,s)=>{const r=jr(e.getExpression(),s);if(r===void 0)return;const n=e.getArguments()[s.argIndex];if(!(!n||!P(n)||T(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:r}},qr=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const o=zr(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(...qr(o,f(t,n),s))}return r},Br=new Set(["content","pdf","scrape","screenshot"]),Vr=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Br}),Ur=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Wr=new Set(["RateLimiter"]),Gr=new Set(["extend"]),Et=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}},st=e=>e&&i.isObjectLiteralExpression(e)?Et(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Hr=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},_r=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)?Hr(e):void 0},Jr=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&_r(t.getBody());return s?Et(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Qr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=b(r.getExpression());n!==void 0&&(Ur.has(n)?s.push({callee:n,file:t,line:r.getStartLineNumber(),...st(r.getArguments()[0])}):Gr.has(n)&&s.push({callee:n,file:t,line:r.getStartLineNumber(),...Jr(r.getArguments()[0])}))}for(const r of e.getDescendantsOfKind(u.NewExpression)){const n=b(r.getExpression());n===void 0||!Wr.has(n)||s.push({callee:n,file:t,line:r.getStartLineNumber(),...st(r.getArguments()[0])})}return s},Xr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Qr(n,f(t,r)))}return s},rt="ctx.containers.",Zr=e=>{if(!e.startsWith(rt))return!1;const t=e.slice(rt.length);return t.length>0&&!t.includes(".")},Yr=(e,t)=>J(e,t,{argIndex:0,matchReceiver:Zr,methods:new Set(["get"])}),en=new Set(["allow","deny","setAllowed"]),tn=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},sn=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!tn(e)))return{detail:"enableInternet: true",exportName:h(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},rn=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!en.has(s.getName()))return;const r=s.getExpression();if(!(!i.isPropertyAccessExpression(r)||r.getName()!=="egress"))return{detail:s.getName(),exportName:h(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},nn=(e,t)=>sn(e,t)??rn(e,t),on=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=nn(r,t);n&&s.push(n)}return s},an=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...on(n,f(t,r)))}return s},cn="env.ts",un=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return _(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},ln=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const r=s.getFirstAncestorByKind(u.ImportDeclaration);return r!==void 0&&_(r.getModuleSpecifierValue())}return!1},dn=e=>{if(i.isIdentifier(e))return un(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&ln(t)}return!1},gn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!dn(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw H(n,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},fn=(e,t)=>{const s=g(t,cn);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=gn(r);if(n.length!==0){if(n.length>1)throw H(r,`lunora/env.ts declares ${n.length.toString()} defineEnv() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},pn=new Set(["defineExportSink","r2Sink","webhookExportSink"]),mn=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return pn.has(s)?s:void 0},xn=e=>{const t=[],s=[];for(const r of e.getProperties()){if(i.isSpreadAssignment(r))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(r)){const n=r.getName();t.push(n);const o=r.getInitializer();o&&i.isStringLiteral(o)&&o.getLiteralText()===""&&s.push(n);continue}(i.isShorthandPropertyAssignment(r)||i.isMethodDeclaration(r)||i.isGetAccessorDeclaration(r))&&t.push(r.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},hn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){const c=mn(a);if(c===void 0)continue;const l=a.getArguments()[0],p=l&&i.isObjectLiteralExpression(l)?xn(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:p.analyzable,emptyKeys:p.emptyKeys,factory:c,file:o,line:a.getStartLineNumber(),presentKeys:p.presentKeys})}}return s},En=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),yn=new Set(["dbRateLimit","rateLimit"]),An=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&i.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===u.TrueKeyword},$n=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},Sn=(e,t)=>{const s=b(e.getExpression());if(s===void 0)return;const r=En.get(s);if(r!==void 0)return{callee:s,exportName:h(e),failOpen:An(e.getArguments()[r]),file:t,limitName:yn.has(s)?$n(e):"",line:e.getStartLineNumber()}},Nn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Sn(r,t);n&&s.push(n)}return s},vn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Nn(n,f(t,r)))}return s},bn=e=>{const t=r=>i.isIdentifier(r)&&r.getText()==="ctx",s=new Set;for(const r of e.getDescendantsOfKind(u.PropertyAccessExpression))t(r.getExpression())&&s.add(r.getName());for(const r of e.getDescendantsOfKind(u.VariableDeclaration)){const n=r.getInitializer(),o=r.getNameNode();if(!(n===void 0||!t(n)||!i.isObjectBindingPattern(o)))for(const a of o.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},Pn=(e,t)=>{const s=Object.fromEntries(pe.map(r=>[r.key,!1]));for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=new Set(n.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=bn(n);for(const c of pe)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(pe.every(c=>s[c.key]))break}return s},wn=["providerSubscriptionId","state"],In=["providerEventId","processedAt"],nt=(e,t)=>t.every(s=>s in e.shape),On=e=>{const t=e.find(r=>r.name==="subscriptions"),s=e.find(r=>r.name==="events");return t!==void 0&&s!==void 0&&nt(t,wn)&&nt(s,In)},Fn=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings/kv"),mail:e.mail||t.dependencies.has("@lunora/mail"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),Ln=e=>i.isIdentifier(e)&&e.getText()==="ctx",Tn=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Ln(t.getExpression())},Dn=e=>{if(e?.getKind()===u.TrueKeyword)return!0;if(e?.getKind()===u.FalseKeyword)return!1},Cn=(e,t)=>{if(!Tn(e.getExpression()))return;const[s,r]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const n=s.getLiteralValue(),o=Dn(r);if(!(n.length===0||o===void 0))return{defaultValue:o,exportName:h(e),file:t,key:n,line:e.getStartLineNumber()}},kn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Cn(r,t);n&&s.push(n)}return s},Kn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...kn(n,f(t,r)))}return s},Rn=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Mn=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},jn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression))Rn(a)&&s.push({file:o,indexName:Mn(a),line:a.getStartLineNumber()})}return s},zn=new Set(["delete","get","head","options","patch","post","put"]),qn=new Set(["handler","stream"]),Bn=new Set(["runAction","runMutation"]),Vn=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),U=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,it=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,ot=(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}}},at=(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(Bn.has(a)&&U(c,t))return a;if(Vn.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&U(c.getExpression(),t))return`db.${a}`}},ct=(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},Un=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!qn.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(zn.has(n)){const o=r.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?n.toUpperCase():void 0}s=r.getExpression()}},Wn=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=it(e.getArguments()[0]),l=c&&ot(c,!0);if(!c||l===void 0)return;const p=at(c,l);return p===void 0?void 0:{exportName:h(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ct(c,l),sideEffect:p}}const r=Un(e);if(r===void 0)return;const n=it(e.getArguments()[0]),o=n&&ot(n,!1);if(!n||o===void 0)return;const a=at(n,o);return a===void 0?void 0:{exportName:h(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:r,readsAuth:ct(n,o),sideEffect:a}},Gn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Wn(r,t);n&&s.push(n)}return s},Hn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Gn(n,f(t,r)))}return s},_n=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),Jn=new Set(["append","set"]),$e=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",yt=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",ut=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(u.CallExpression)]:e.getDescendantsOfKind(u.CallExpression)).some(s=>_n.has($e(s.getExpression()))&&B(s,t)),Qn=(e,t)=>{if(ut(e,t))return!0;const s=F(e);return s!==void 0&&ut(s,t)},ye=(e,t)=>tr(e,t)&&!Qn(e,t),Xn=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=F(e);return t!==void 0&&i.isNewExpression(t)&&$e(t.getExpression())==="Headers"},W=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=F(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:yt(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)}},At=(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)},Zn=(e,t)=>{const s=$e(e.getExpression());if(s==="Response")At(e.getArguments()[1],t);else if(s==="Headers"){const r=W(e.getArguments()[0]);r!==void 0&&Se(r,"headers-ctor",t)}},Yn=(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"){At(e.getArguments()[1],t);return}if(Jn.has(r)&&Xn(n)){const o=e.getArguments()[1];o!==void 0&&ye(o,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:yt(e.getArguments()[0]),line:o.getStartLineNumber(),via:r==="set"?"headers-set":"headers-append"})}},ei=(e,t)=>{for(const s of e.getDescendantsOfKind(u.NewExpression))Zn(s,t);for(const s of e.getDescendantsOfKind(u.CallExpression))Yn(s,t)},ti=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const r=Ut(e.getArguments()[0]);if(r===void 0)return[];const n=r.getParameters()[1];if(n===void 0)return[];const o=n.getNameNode();if(!i.isIdentifier(o))return[];const a=[];return ei(r,{exportName:h(e),relativePath:t,requestName:o.getText(),rows:a}),a},si=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...ti(r,t));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,f(t,r)))}return s},$t="identity.ts",ni=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return _(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},ii=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&&_(r.getModuleSpecifierValue())}return!1},oi=e=>{if(i.isIdentifier(e))return ni(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&ii(t)}return!1},ai=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!oi(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},ci=(e,t)=>{const s=g(t,$t);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=ai(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]}},ui=new Set(["auth","context.auth","ctx.auth"]),li="userId",di=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},gi=(e,t)=>{const s=g(t,$t);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const n of r.getDescendantsOfKind(u.CallExpression)){if(b(n.getExpression())!=="defineIdentity")continue;const[o]=n.getArguments();return o&&i.isObjectLiteralExpression(o)?di(o):void 0}},lt=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return ui.has(e.getExpression().getText())?e:void 0},fi=e=>{if(i.isPropertyAccessExpression(e)&<(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&<(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},pi=(e,t,s)=>{const r=[];for(const n of e.getDescendants()){const o=fi(n);o!==void 0&&r.push({declared:o===li||s.has(o),exportName:h(n),file:t,key:o,line:n.getStartLineNumber()})}return r},mi=(e,t)=>{const s=gi(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(...pi(o,f(t,n),s))}return r},xi=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},hi=(e,t)=>{if(b(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const r=xi(s);if(!(!r||!P(r)||T(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},Ei=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=hi(r,t);n&&s.push(n)}return s},yi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ei(n,f(t,r)))}return s},Ai=new Set(["delete","get","getRaw","getWithMetadata","put"]),$i=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:Ai}),Si=new Set(["queue","send"]),dt=new Set(["bcc","cc","to"]),Ni=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Si.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},vi=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const r=t.getNameNode();return dt.has(t.getName())&&P(r)&&!T(r)}if(!i.isPropertyAssignment(t)||!dt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&P(s)&&!T(s)}):!1,bi=(e,t)=>{const s=Ni(e.getExpression());if(s===void 0)return;const r=e.getArguments()[0];if(!(!r||!vi(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Pi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=bi(r,t);n&&s.push(n)}return s},wi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Pi(n,f(t,r)))}return s},Ii=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"},Oi=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},Fi=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==u.CallExpression)return;const s=t;return $s(s.getExpression())?s:void 0},Li=e=>{const t=Fi(e),s=t===void 0?void 0:Oi(t);if(s===void 0)return[];const r=e.getNameNode(),n=i.isIdentifier(r)?r.getText():"";return s.getDescendantsOfKind(u.CallExpression).filter(o=>Ii(o)).map(o=>({exportName:n,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},Ti=e=>e.getVariableDeclarations().flatMap(t=>Li(t)),Di=(e,t)=>{const s=g(t,As);if(!E(s))return[];const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Ti(r)},Ci=new Set(["delete","get","patch"]),ki=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Ki=new Set(["auth","identity","session","user"]),Ri=new Set([u.EqualsEqualsEqualsToken,u.EqualsEqualsToken,u.ExclamationEqualsEqualsToken,u.ExclamationEqualsToken]),Mi=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!k(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},ji=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},zi=(e,t)=>e.getDescendantsOfKind(u.Identifier).some(s=>s.getText()===t),qi=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(u.ThrowStatement).length>0||e.getDescendantsOfKind(u.ReturnStatement).length>0,Bi=(e,t)=>e.getDescendantsOfKind(u.IfStatement).some(s=>zi(s.getExpression(),t)&&qi(s.getThenStatement())),Vi=(e,t)=>{for(const s of e.getDescendantsOfKind(u.CallExpression)){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))continue;const n=r.getName();if(!Ci.has(n))continue;const o=r.getExpression();if(!(k(o)||i.isPropertyAccessExpression(o)&&k(o.getExpression())))continue;const a=s.getArguments()[0];if(a!==void 0&&i.isIdentifier(a)&&a.getText()===t)return n}},Ui=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},Wi=e=>e.getDescendantsOfKind(u.CallExpression).some(t=>t.getArguments().some(s=>Ui(s)==="ctx")),Gi=e=>e.getDescendantsOfKind(u.BinaryExpression).some(t=>Ri.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),Hi=e=>{for(const t of e.getDescendantsOfKind(u.Identifier))if(ki.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&Ki.has(t.getName()))return!0}return Wi(e)||Gi(e)},_i=(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=mt(s);if(n===void 0)return[];const o=r.receiver!==void 0&&xt(r.receiver,"use","rls"),a=Hi(n),c=new Set,l=[];for(const p of n.getDescendantsOfKind(u.CallExpression)){const y=Mi(p);if(y===void 0)continue;const w=ji(p);if(w===void 0||c.has(w)||!Bi(n,w))continue;const R=Vi(n,w);R!==void 0&&(c.add(w),l.push({exportName:e.getName(),file:t,line:p.getStartLineNumber(),mentionsOwnership:a,sinkMethod:R,table:y,usesRls:o,visibility:r.visibility}))}return l},Ji=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(..._i(c,o))}return s},Qi=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Xi=new Set(["insert","insertManyUnsafe","patch","replace"]),Zi=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Xi.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},Yi=(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},eo=(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||!Qi.has(a))&&P(c)&&!T(c)&&n.push({exportName:h(s),field:a,file:r,line:s.getStartLineNumber(),method:t})}return n},to=(e,t)=>{const s=Zi(e.getExpression());if(s===void 0)return[];const r=e.getArguments()[1];return r?Yi(r,s).flatMap(n=>eo(n,s,e,t)):[]},so=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...to(r,t));return s},ro=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...so(n,f(t,r)))}return s},no=e=>{const t=g(e,"package.json");if(!E(t))return new Set;try{const s=JSON.parse(Ae(t,"utf8")),r=new Set;for(const n of["dependencies","devDependencies","peerDependencies","optionalDependencies"]){const o=s[n];if(o!==null&&typeof o=="object")for(const a of Object.keys(o))r.add(a)}return r}catch{return new Set}},io=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),oo=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,ao=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?oo(t.getInitializer()):void 0},co=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=b(r.getExpression());if(n===void 0||!io.has(n))continue;const[o]=r.getArguments(),a=o&&i.isObjectLiteralExpression(o)?ao(o):void 0;s.push({callee:n,exportName:h(r),file:t,line:r.getStartLineNumber(),...a===void 0?{}:{toleranceSeconds:a}})}return s},uo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...co(n,f(t,r)))}return s},lo=new Set(["defineQueue","defineWorkflow"]),go=new Set(["run","runAction","runMutation","runQuery"]),fo=new Set(["api","internal"]),po=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},mo=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!i.isPropertyAssignment(s))return;const r=s.getInitializer();if(r&&(i.isArrowFunction(r)||i.isFunctionExpression(r)))return r},St=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},Nt=(e,t)=>e===t||e.startsWith(`${t}.`),vt=e=>{const t=e.getDescendantsOfKind(u.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},gt=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e||i.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(i.isBindingElement(t)&&t.getNameNode()===e)},bt=e=>{const t=e.getDescendantsOfKind(u.Identifier).filter(s=>gt(s));return i.isIdentifier(e)&>(e)&&t.push(e),t},xo=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(u.BindingElement).map(s=>s.getName())},ho=e=>{const t=St(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const r of e.getDescendantsOfKind(u.ForOfStatement)){if(r.getExpression().getText()!==`${t}.messages`)continue;const n=r.getInitializer(),o=i.isVariableDeclarationList(n)?n.getDeclarations()[0]?.getNameNode():void 0;o&&i.isIdentifier(o)&&s.push(`${o.getText()}.body`)}return s},Eo=(e,t,s)=>{const r=t==="workflow"?[`${s}.params`]:ho(e),n=new Set,o=a=>vt(a).some(c=>r.some(l=>Nt(c.getText(),l)))?!0:bt(a).some(c=>n.has(c.getText()));for(const a of e.getDescendantsOfKind(u.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of xo(a))n.add(l)}return{names:n,prefixes:r}},yo=(e,t)=>vt(e).some(s=>t.prefixes.some(r=>Nt(s.getText(),r)))?!0:bt(e).some(s=>t.names.has(s.getText())),Ao=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)||!fo.has(s.getText())||t.length<2))return{exportName:r,file:t.slice(0,-1).join("/")}},$o=(e,t,s)=>{const r=St(e,0);if(r===void 0)return[];const n=Eo(e,t,r),o=[];for(const a of e.getDescendantsOfKind(u.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!go.has(c.getName())||c.getExpression().getText()!==r)continue;const l=a.getArguments()[1];if(!l||!yo(l,n))continue;const p=Ao(a.getArguments()[0]);p!==void 0&&o.push({dispatchKind:t,file:s,handlerExport:h(a),line:a.getStartLineNumber(),targetExport:p.exportName,targetFile:p.file})}return o},So=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=po(r);if(n===void 0||!lo.has(n))continue;const o=mo(r);o!==void 0&&s.push(...$o(o,n==="defineQueue"?"queue":"workflow",t))}return s},No=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...So(n,f(t,r)))}return s},ft={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},vo=/account|credential|member|passkey|session|user/iu,Pt=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},bo=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Po=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},wo=e=>{const t=Po(e),s=t?Pt(t):void 0;if(t&&s==="protectPublic"){const r=bo(t);return{...V,usesCaptcha:r.usesCaptcha,usesRateLimit:r.usesRateLimit}}return s!==void 0&&s in ft?{...V,[ft[s]]:!0}:V},Io=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=wo(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},Oo=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)&&vo.test(r.getLiteralText()))},Fo=new Set(["create","runAfter","runAt","send","sendBatch"]),Lo=new Set(["queues","scheduler","workflows"]),To=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Fo.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&Lo.has(s.getName())){const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="ctx")return!0}s=s.getExpression()}return!1},Do=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"},Co=new Set(["generateObject","generateText","streamObject","streamText"]),ko=e=>{const t=Pt(e);if(t===void 0||!Co.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")},Ko=e=>e.getDescendantsOfKind(u.PropertyAccessExpression).some(t=>{const s=t.getName();if(s!=="mail"&&s!=="email")return!1;const r=t.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"}),Ro=e=>{let t=!1,s=!1,r=!1,n=!1;for(const o of e.getDescendantsOfKind(u.CallExpression))if(Oo(o)&&(n=!0),To(o)&&(t=!0),Do(o)&&(r=!0),ko(o)&&(s=!0),n&&t&&r&&s)break;return{callsMail:Ko(e),fanOut:t,unboundedAiGeneration:s,usesInsertManyUnsafe:r,writesUserTable:n}},Mo=(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?Io(r.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},{callsMail:o,fanOut:a,unboundedAiGeneration:c,usesInsertManyUnsafe:l,writesUserTable:p}=Ro(e);return{callsMail:o,exportName:e.getName(),fanOut:a,file:t,kind:r.kind,unboundedAiGeneration:c,usesCaptcha:n.usesCaptcha,usesEmailGate:n.usesEmailGate,usesInsertManyUnsafe:l,usesMask:n.usesMask,usesRateLimit:n.usesRateLimit,usesRls:n.usesRls,visibility:r.visibility,writesUserTable:p}},jo=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Mo(n,t);o&&s.push(o)}return s},zo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...jo(n,f(t,r)))}return s},qo=new Set(["dbRateLimit","rateLimit"]),Bo=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Vo=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},Uo=e=>i.isArrowFunction(e)?e.getBody():e,Wo=(e,t)=>{const s=b(e.getExpression());if(s===void 0||!qo.has(s))return;const r=e.getArguments()[2];if(!r)return;const n=Bo(r);if(!n)return;const o=Uo(n);if(!(!P(o)||T(o)))return{callee:s,exportName:h(e),file:t,limitName:Vo(e),line:e.getStartLineNumber()}},Go=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Wo(r,t);n&&s.push(n)}return s},Ho=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Go(n,f(t,r)))}return s},_o=new Set(["findFirst","findFirstOrThrow","findMany","get"]),Jo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!_o.has(t.getName()))return;const s=t.getExpression();if(k(s)){const r=e.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&k(s.getExpression()))return s.getName()},Qo=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&k(s.getExpression())){const r=t.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}t=s.getExpression()}},Xo=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},wt=(e,t=!1)=>{const s=Xo(e);if(i.isIdentifier(s)){if(t)return;const r=F(s);return r===void 0?void 0:wt(r,!0)}if(i.isCallExpression(s))return Jo(s)??Qo(s)},Zo=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},Yo=(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=mt(s);if(n===void 0)return[];const o=r.receiver!==void 0&&Wt(r.receiver,"output"),a=r.receiver!==void 0&&xt(r.receiver,"use","mask"),c=new Set,l=[];for(const p of Zo(n)){const y=wt(p);y===void 0||c.has(y)||(c.add(y),l.push({exportName:e.getName(),file:t,line:p.getStartLineNumber(),table:y,usesMask:a,usesOutput:o,visibility:r.visibility}))}return l},ea=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Yo(c,o))}return s},ta=new Set(["findFirst","findFirstOrThrow","findMany"]),sa=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ta.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()}}},ra=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},na=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},ia=(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=sa(o);if(a===void 0)continue;const c=ra(na(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},oa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...ia(c,o))}return s},G=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===u.PlusToken){const t=G(e.getLeft()),s=G(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},aa=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===u.PlusToken;)t=s,s=t.getParent();return t!==e&&G(t)!==void 0},ca=(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(aa(o))continue;const a=G(o);if(a===void 0)continue;const c=Ds(a);if(c===void 0)continue;const l=o.getStartLineNumber(),p=`${String(l)}:${c}`;n.has(p)||(n.add(p),s.push({file:t,kind:c,line:l,preview:Cs(a)}))}return s},ua=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ca(n,f(t,r)))}return s},la=new Set(["findFirst","findFirstOrThrow","findMany"]),da=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!la.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},fa=(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=da(o);if(a===void 0)continue;const c=ga(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),p=!l&&P(c);!l&&!p||n.push({exportName:e.getName(),file:t,fromArgs:p,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:r.visibility})}return n},pa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...fa(c,o))}return s},ma=new Set(["query","unsafe"]),xa=e=>{if(!i.isPropertyAccessExpression(e)||!ma.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"},ha=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),Ea=e=>e.getFirstAncestorByKind(u.VariableDeclaration)?.getName()??"<module>",ya=(e,t)=>{if(!xa(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!ha(s)))return{exportName:Ea(e),file:t,line:s.getStartLineNumber()}},Aa=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ya(r,t);n&&s.push(n)}return s},$a=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Aa(n,f(t,r)))}return s},Sa=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Na=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.storage"||s.startsWith("ctx.storage."),methods:Sa}),va=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),ba=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Pa=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=ba(n.getInitializer()));continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,expiresInSeconds:s,presentKeys:t}},wa=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=va.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},Ia=(e,t)=>{const s=wa(e.getExpression());if(s!==void 0)return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s.method,...Pa(e.getArguments()[s.optionsIndex])}},Oa=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ia(r,t);n&&s.push(n)}return s},Fa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Oa(n,f(t,r)))}return s},La=new Set(["when","where"]),he=new Set(["definePolicy","defineShape"]),Ta=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const r=t.getName();return he.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 he.has(n)?n:void 0}const s=t.getText();return he.has(s)?s:void 0},Da=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,It=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===u.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Da(e))return"empty-object";if(i.isParenthesizedExpression(e))return It(e.getExpression())}},Ot=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Ft=e=>e.getDescendantsOfKind(u.ReturnStatement).filter(t=>Ot(t)===e),Lt=e=>e.getDescendantsOfKind(u.ConditionalExpression).filter(t=>Ot(t)===e),Ca=e=>{const t=Ft(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(u.IfStatement)!==void 0)||Lt(e).length>0},ka=e=>{const t=[],s=e.getBody();i.isBlock(s)||t.push(s);for(const r of Ft(e)){const n=i.isReturnStatement(r)?r.getExpression():void 0;t.push(n??r)}for(const r of Lt(e))t.push(r.getWhenTrue(),r.getWhenFalse());return t},Ka=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},Ra=(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)||!La.has(o.getName()))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Ca(a))for(const c of ka(a)){const l=It(c);l!==void 0&&n.push({exportName:Ka(e),file:s,form:l,key:o.getName(),line:c.getStartLineNumber(),owner:t})}}return n},Ma=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ta(r);n!==void 0&&s.push(...Ra(r,n,t))}return s},ja=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ma(n,f(t,r)))}return s},za=new Set(["query","upsert","upsertMany"]),qa=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(za.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Ba=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("namespace");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Va=(e,t)=>{const s=qa(e.getExpression());if(s===void 0)return;const r=e.getArguments()[1];if(!r)return;const n=Ba(r);if(!(!n||!P(n)||T(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Ua=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Va(r,t);n&&s.push(n)}return s},Wa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ua(n,f(t,r)))}return s},Ga=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"},Ha=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},_a=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){if(!Ga(a))continue;const c=Rs(a);c!==""&&s.push({exportName:c,file:o,line:a.getStartLineNumber(),workflow:Ha(a)})}}return s},Ja=".lunora-schema.json",$=(e,t)=>{E(e)&&Ae(e,"utf8")===t||qt(e,t,"utf8")},v=(e,t)=>{if(t===""){Bt(e,{force:!0});return}$(e,t)},Qa=e=>{const t=g(e,"package.json");if(E(t))try{const s=JSON.parse(Ae(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},Xa=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Za=e=>{let t=E(e)?e:ge(e);for(;t&&t!==ge(t);){const s=g(t,"tsconfig.json");if(E(s))return s;t=ge(t)}},pt=e=>e.replaceAll("\\","/"),Ya=(e,t)=>{const s=new Map,r=new Map,n=new Map;for(const o of e)s.set(o.name,`workflow "${o.exportName}"`),r.set(o.bindingName,`workflow "${o.exportName}"`),n.set(o.className,`workflow "${o.exportName}"`);for(const o of t){const a=s.get(o.name);if(a!==void 0)throw new q("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${o.name}": produced by both ${a} and agent "${o.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=r.get(o.bindingName);if(c!==void 0)throw new q("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${o.bindingName}": produced by both ${c} and agent "${o.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const l=n.get(o.className);if(l!==void 0)throw new q("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${o.className}": produced by both ${l} and agent "${o.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},ec=e=>{const t=Za(e);return t?new Xe({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Xe({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Mc=(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=>pt(c))),o=pt(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!n.has(l)&&e.removeSourceFile(c)}},jc=e=>{const t=Xa(),s=t?fe.now():0,r=g(e.projectRoot,e.lunoraDirectory??"lunora"),n=g(r,"schema.ts");if(!E(n))throw new q("INTERNAL",`schema.ts not found at ${n}`);const o=e.project??ec(r),a=Ts(o,n,e.projectRoot),c=Gt(o,r),l=ps(o,r),p=ys(o,r),y=ks(o,r),w=Ss(o,r),R=ci(o,r),Ne=fn(o,r),S=Ms(o,r),D=ws(o,r),N=Ht(o,r);Ya(S,N);const Q=Qt(o,r,S,N),C=Jt(o,r),ve=e.lint===!1?[]:Vt({adminRoutes:Ys(o,r),aiRawRuns:ir(o,r),aiToolSideEffects:mr(o,r),argumentDerivedFetches:yr(o,r),argumentValidators:Fr(o,r),authApiCalls:_t(o,r),authConfigs:Mr(o,r),browserUrlAccesses:Vr(o,r),configCalls:Xr(o,r),containerKeyAccesses:Yr(o,r),containerOverrides:an(o,r),containers:C,exportSinks:hn(o,r),failOpenGuards:vn(o,r),flagSecurityDefaults:Kn(o,r),geoIndexUsages:jn(o,r),httpActionGuards:Hn(o,r),httpHeaderWrites:ri(o,r),identityClaimReads:mi(o,r),imageDeliveryUrlAccesses:yi(o,r),inserts:ms(o,r),kvKeyAccesses:$i(o,r),mailRecipientAccesses:wi(o,r),maskProcedures:xs(o,r),maskStrategies:hs(o,r),mutatorWrites:Di(o,r),nondeterministicCalls:Ns(o,r),normalizeIdAuthorizations:Ji(o,r),notifyCalls:bs(o,r),notifyConfig:vs(o,r),ownerFieldWrites:ro(o,r),unrestrictedWhereBranches:ja(o,r),paymentWebhooks:uo(o,r),privilegedDispatches:No(o,r),procedureProtections:zo(o,r),queries:Ps(o,r),queues:D,r2sqlCalls:Is(o,r),ratelimitKeySelectors:Ho(o,r),rawRowReturns:ea(o,r),relationLoads:oa(o,r),rlsProcedures:Os(o,r),schema:a,secretLiterals:ua(o,r),shapes:y,softDeleteReads:pa(o,r),sqlInterpolations:$a(o,r),storageKeyAccesses:Na(o,r),storageUploads:Fa(o,r),vectorNamespaceAccesses:Wa(o,r),workflowCalls:_a(o,r),workflows:S,wranglerVariables:e.wranglerVariables}),Tt=Fs(o,r),Dt=Es(o,r),X=Ks(o,r),A=Pn(o,r),Z=A.ai,Y=A.payments,be=A.kv,Pe=A.access,ee=E(g(r,"flags.ts")),Ct=ee?fs(o,r):[],te=E(g(r,"notify.ts")),se=A.hyperdrive,re=Ls(o,r),kt=re.usesSandboxBrowser||re.usesSandboxContainer,ne=A.browser||re.usesSandboxBrowser,ie=A.images,oe=A.analytics,we=A.pipelines,ae=A.r2sql,ce=A.x402,I=no(e.projectRoot),M=Fn(A,{containerCount:C.length,cronCount:Q.length,dependencies:I,hasPaymentTables:On(a.tables),queueCount:D.length,storageColumnCount:Object.keys(Xt(a)).length,storageRuleCount:X.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:S.length}),L=I.has("lunorash"),Ie=t?fe.now():0,Oe=Zt(a,L),Fe=Yt({agents:N,functions:c,httpRoutes:l,mutators:w,useUmbrella:L,workflows:S}),Le=es({agents:N,containers:C,env:Ne,hasAccessFacade:Pe,hasAi:Z,hasAnalytics:oe,hasBrowser:ne,hasFlags:ee,hasHyperdrive:se,hasImages:ie,hasKv:be,hasNotify:te,hasPayments:Y,hasPipelines:we,hasR2sql:ae,hasX402:ce,identity:R,queues:D,schema:a,storageRuleBuckets:X.rules.map(m=>m.bucket),useUmbrella:L,workflows:S}),Te=ts({agents:N,functions:c,migrations:p,mutators:w,shapes:y,useUmbrella:L,usesSandbox:kt}),De=ss({advisories:ve,agents:N,containers:C,env:Ne,flagKeys:Ct,hasAccessFacade:Pe,hasAi:Z,hasAnalytics:oe,hasBrowser:ne,hasFlags:ee,hasHyperdrive:se,hasImages:ie,hasKv:be,hasNotify:te,hasPayments:Y,hasPipelines:we,hasR2sql:ae,hasX402:ce,maskMetadata:Dt,mutators:w,queues:D,rlsMetadata:Tt,schema:a,shapes:y,storageRules:X,studioFeatures:M,useUmbrella:L,workflows:S}),Ce=rs(y,I.has("@lunora/db"),L),ke=ns(C,a.jurisdiction),Ke=is(S),Re=os(N),Me=as(D),je=cs(Q),ze=us(a.vectorIndexes),j=ls(a,L),qe=ds(I.has("@lunora/seed")),z=e.apiSpec??"openapi",ue=z==="openapi"||z==="both",le=z==="openrpc"||z==="both",Be=js({emailAgents:N.filter(m=>m.onEmail===!0).map(m=>({bindingName:m.bindingName,exportName:m.exportName})),hasAccess:I.has("@lunora/cloudflare-access"),hasAi:Z,hasAnalytics:oe,hasAuth:I.has("@lunora/auth"),hasBrowser:ne,hasFramework:I.has("@lunora/astro")||I.has("@lunora/svelte")||I.has("@lunora/vue"),hasGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend!=="hyperdrive"),hasHyperdrive:se,hasHyperdriveGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend==="hyperdrive"),hasImages:ie,hasKv:M.kv,hasNotify:te,hasPayments:Y,hasR2sql:ae,hasQueue:D.some(m=>m.mode==="push"),hasScheduler:M.scheduler,hasStorage:M.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:S.length>0,hasX402:ce,identity:R,jurisdiction:a.jurisdiction,useUmbrella:L,voiceAgents:N.filter(m=>m.voice===!0&&m.voiceBindingName!==void 0).map(m=>({bindingName:m.voiceBindingName,exportName:m.exportName})),wantsOpenApi:ue,wantsOpenRpc:le}),Ve=Qa(e.projectRoot),Ue=zs({functions:c,httpRoutes:l,version:Ve}),We=Bs({functions:c,version:Ve}),Ge=`${JSON.stringify(Ue,void 0,2)}
|
|
2
|
-
`,He=`${JSON.stringify(We,void 0,2)}
|
|
3
|
-
`,_e=qs(Ue),Je=Vs(We),Qe=Us(a,p.map(m=>m.id)),de=g(r,Ja),Kt=E(de),x=g(r,"_generated");if(e.dryRun||(E(x)||zt(x,{recursive:!0}),$(g(x,"app.ts"),Be),$(g(x,"dataModel.ts"),Oe),$(g(x,"api.ts"),Fe),$(g(x,"server.ts"),Le),$(g(x,"functions.ts"),Te),$(g(x,"shard.ts"),De),$(g(x,"crons.ts"),je),$(g(x,"vectors.ts"),ze),$(g(x,"drizzle.global.ts"),j.global),$(g(x,"drizzle.shard.ts"),j.shard),v(g(x,"containers.ts"),ke),v(g(x,"workflows.ts"),Ke),v(g(x,"agents.ts"),Re),v(g(x,"queues.ts"),Me),v(g(x,"seed.ts"),qe),v(g(x,"collections.ts"),Ce),v(g(x,"openapi.json"),ue?Ge:""),v(g(x,"openapi.ts"),ue?_e:""),v(g(x,"openrpc.json"),le?He:""),v(g(x,"openrpc.ts"),le?Je:""),(!Kt||e.updateSchemaBaseline===!0)&&$(de,Ws(Qe))),t){const m=fe.now(),Rt=Math.round(m-s),Mt=Math.round(Ie-s),jt=Math.round(m-Ie);console.error(`@lunora/codegen: codegen took ${Rt.toString()}ms (discovery ${Mt.toString()}ms, emit ${jt.toString()}ms)`)}return{advisories:ve,agents:N,containers:C,cronTriggers:gs(Q),generated:{agents:Re,api:Fe,app:Be,collections:Ce,containers:ke,crons:je,dataModel:Oe,drizzleGlobal:j.global,drizzleShard:j.shard,functions:Te,openApi:Ge,openApiModule:_e,openRpc:He,openRpcModule:Je,queues:Me,seed:qe,server:Le,shard:De,vectors:ze,workflows:Ke},outputDirectory:x,queues:D,schemaSnapshot:Qe,schemaSnapshotPath:de,workflows:S}};export{Ja as SCHEMA_SNAPSHOT_FILENAME,ec as createCodegenProject,Mc as refreshCodegenProject,jc as runCodegen};
|