@lunora/codegen 1.0.0-alpha.279 → 1.0.0-alpha.280
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 +44 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{AGENTS_FILENAME-NQIB6wh3.mjs → AGENTS_FILENAME-Dntm1vDe.mjs} +1 -1
- package/dist/packem_shared/{CONTAINERS_FILENAME-CK3xJGwm.mjs → CONTAINERS_FILENAME-D5xnZUl6.mjs} +1 -1
- package/dist/packem_shared/{FLAGS_FILENAME-DYMd1xqw.mjs → FLAGS_FILENAME-C1RHlinh.mjs} +1 -1
- package/dist/packem_shared/GENERATED_HEADER-Ck_WOHzE.mjs +1 -0
- package/dist/packem_shared/{MUTATORS_FILENAME-BrEGrcPU.mjs → MUTATORS_FILENAME-YOl15Grm.mjs} +1 -1
- package/dist/packem_shared/{NOTIFY_FILENAME-D7DAtpNJ.mjs → NOTIFY_FILENAME-B8Wb9kiq.mjs} +1 -1
- package/dist/packem_shared/OPENRPC_VERSION-DnYKkFP6.mjs +3 -0
- package/dist/packem_shared/{QUEUES_FILENAME-CG1CuK-T.mjs → QUEUES_FILENAME-hTuq7XDL.mjs} +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CqU4KTnp.mjs +11 -0
- package/dist/packem_shared/{SHAPES_FILENAME-CVc2VCnS.mjs → SHAPES_FILENAME-BrqrIhBv.mjs} +1 -1
- package/dist/packem_shared/{WORKFLOWS_FILENAME-Ze98LsB3.mjs → WORKFLOWS_FILENAME-eLdktkM5.mjs} +1 -1
- package/dist/packem_shared/{attribution-Dw35rOaJ.mjs → attribution-DqqCSywo.mjs} +1 -1
- package/dist/packem_shared/buildOpenApiDocument-D_8TtHK1.mjs +3 -0
- package/dist/packem_shared/{capabilitiesUsedBy-FnnYmnSl.mjs → capabilitiesUsedBy-CmSX6ODG.mjs} +1 -1
- package/dist/packem_shared/chain-DmRSLvAh.mjs +1 -0
- package/dist/packem_shared/{classify-procedure-call-DxuPQkJA.mjs → classify-procedure-call-HrUyDQX0.mjs} +1 -1
- package/dist/packem_shared/{context-property-calls-BLTVj9HH.mjs → context-property-calls-0qzW2Joh.mjs} +1 -1
- package/dist/packem_shared/{context-root-B04bYCE-.mjs → context-root-DKsAPUmn.mjs} +1 -1
- package/dist/packem_shared/{database-calls-DWDtdDbS.mjs → database-calls-CBlsQTga.mjs} +1 -1
- package/dist/packem_shared/{discoverAuthApiCalls-XK_WCMDG.mjs → discoverAuthApiCalls-CeFyWdQy.mjs} +1 -1
- package/dist/packem_shared/{discoverCrons-B5bVCaNF.mjs → discoverCrons-DBuEbNrB.mjs} +1 -1
- package/dist/packem_shared/discoverFunctions-BswBeUWK.mjs +1 -0
- package/dist/packem_shared/{discoverHttpRoutes-CMOxt2Y9.mjs → discoverHttpRoutes-6utMwfNf.mjs} +1 -1
- package/dist/packem_shared/discoverHyperdriveCalls-HGl9zBnw.mjs +1 -0
- package/dist/packem_shared/{discoverInserts-BhIpUWXN.mjs → discoverInserts-Ao36AnSp.mjs} +1 -1
- package/dist/packem_shared/discoverMaskProcedures-B29pl7an.mjs +1 -0
- package/dist/packem_shared/{discoverMigrations-dVVZtuJa.mjs → discoverMigrations-CM6L8k6b.mjs} +1 -1
- package/dist/packem_shared/{discoverNondeterministicCalls-Dtb1aoGV.mjs → discoverNondeterministicCalls-C6iIjMHn.mjs} +1 -1
- package/dist/packem_shared/{discoverQueries-BSOjEsk3.mjs → discoverQueries-4lacKgx_.mjs} +1 -1
- package/dist/packem_shared/discoverR2sqlCalls-BDomQsRO.mjs +1 -0
- package/dist/packem_shared/{discoverRlsMetadata-9YDlDDoh.mjs → discoverRlsMetadata-CTQN6hgU.mjs} +1 -1
- package/dist/packem_shared/{discoverRlsProcedures-c0DnIR4z.mjs → discoverRlsProcedures-DllbV6_E.mjs} +1 -1
- package/dist/packem_shared/{discoverSandboxUsage-CfEU2hM-.mjs → discoverSandboxUsage-ejLtE6Ky.mjs} +1 -1
- package/dist/packem_shared/{discoverSchema-BTFFWy3i.mjs → discoverSchema-C3WOG-xt.mjs} +1 -1
- package/dist/packem_shared/{discoverStorageRulesMetadata-f89BWody.mjs → discoverStorageRulesMetadata-CyZ44b1b.mjs} +1 -1
- package/dist/packem_shared/{emitAgents-BPxcXbC6.mjs → emitAgents-BedQefBj.mjs} +1 -1
- package/dist/packem_shared/{emitApi-zY6egN77.mjs → emitApi-Zx6VPN-7.mjs} +1 -1
- package/dist/packem_shared/{emitApp-DUGS6Ve2.mjs → emitApp-CBIXVzkw.mjs} +1 -1
- package/dist/packem_shared/{emitCrons-B8TBAOZ4.mjs → emitCrons-Gd8jD8jF.mjs} +1 -1
- package/dist/packem_shared/{emitDataModel-B68T_eX6.mjs → emitDataModel-DdtjdNg3.mjs} +1 -1
- package/dist/packem_shared/{emitDrizzleSchema-DLtfKTI4.mjs → emitDrizzleSchema-CpOGYfyl.mjs} +1 -1
- package/dist/packem_shared/{emitFunctions-DkkcTDqh.mjs → emitFunctions-BeKgL3dl.mjs} +1 -1
- package/dist/packem_shared/{emitServer-BbjIwe2-.mjs → emitServer-DlOheWku.mjs} +1 -1
- package/dist/packem_shared/{emitShard-HJfeP8nZ.mjs → emitShard-CngydZFL.mjs} +1 -1
- package/dist/packem_shared/{exported-procedure-chains-C5VKkd9T.mjs → exported-procedure-chains--nYG8cid.mjs} +1 -1
- package/dist/packem_shared/{fingerprintSchemaSources-BJSIxwhY.mjs → fingerprintSchemaSources-C4PkhFFQ.mjs} +1 -1
- package/dist/packem_shared/{handler-reference-2Hs4WKnz.mjs → handler-reference-CpEEELL0.mjs} +1 -1
- package/dist/packem_shared/{index-CefI-Sba.mjs → index-BfaSHMNi.mjs} +1 -1
- package/dist/packem_shared/isTestPath-CiIyKqhF.mjs +1 -0
- package/dist/packem_shared/modules-Cuogms61.mjs +1 -0
- package/dist/packem_shared/{qualifiers-COHdrghK.mjs → qualifiers-DEdXn5wP.mjs} +1 -1
- package/dist/packem_shared/{server-BmY5wwKY.mjs → server-DSUfd6Tc.mjs} +1 -1
- package/dist/packem_shared/{shard-D39UvC5v.mjs → shard-BTfJuEeP.mjs} +1 -1
- package/dist/packem_shared/{shard-runtime-B7YKtoEK.mjs → shard-runtime-CkaEBSdL.mjs} +1 -1
- package/dist/packem_shared/{shared-Be3TGzxM.mjs → shared-DnCokNcE.mjs} +1 -1
- package/dist/packem_shared/{unwrap-handler-return-T5sJhEss.mjs → unwrap-handler-return-BTKoWeJc.mjs} +1 -1
- package/package.json +2 -2
- package/dist/packem_shared/GENERATED_HEADER-D-P7ii4H.mjs +0 -1
- package/dist/packem_shared/OPENRPC_VERSION-BaD2A2YR.mjs +0 -3
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BNGM7Peq.mjs +0 -11
- package/dist/packem_shared/buildOpenApiDocument-BjHdW7b2.mjs +0 -3
- package/dist/packem_shared/chain-nWiSr1yy.mjs +0 -1
- package/dist/packem_shared/discoverFunctions-Be-XuuSW.mjs +0 -1
- package/dist/packem_shared/discoverHyperdriveCalls-mrho5AnY.mjs +0 -1
- package/dist/packem_shared/discoverMaskProcedures-DCw165tP.mjs +0 -1
- package/dist/packem_shared/discoverR2sqlCalls-KONCqZr2.mjs +0 -1
- package/dist/packem_shared/isTestPath-CgyyLk8U.mjs +0 -1
- package/dist/packem_shared/modules-BIpFLz3Z.mjs +0 -1
- /package/dist/packem_shared/{paths-DwTjD7BU.mjs → dispatch-namespace-DwTjD7BU.mjs} +0 -0
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import{existsSync as R,mkdirSync as Us,rmSync as lt,readdirSync as er,readFileSync as tr,writeFileSync as sr}from"node:fs";import{join as h,dirname as fe,relative as nr}from"node:path";import{performance as et}from"node:perf_hooks";import{runAdvisor as rr}from"@lunora/advisor";import{LunoraError as Y}from"@lunora/errors";import{readJsonSync as ir}from"@visulima/fs";import{SyntaxKind as d,Node as i,Project as ts}from"ts-morph";import{serializeSchemaSnapshot as or}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{toAdvisorContext as ar}from"./formatAdvisories-DwmUKYuc.mjs";import{r as cr,a as S,s as lr,b as dr}from"./project-config-file-Bv2l-Kmm.mjs";import{a as Ce,d as ur,r as fr}from"./modules-BIpFLz3Z.mjs";import{WORKFLOWS_FILENAME as gr,discoverWorkflows as pr}from"./WORKFLOWS_FILENAME-Ze98LsB3.mjs";import{r as mr}from"./json-data-Chfs2Cz5.mjs";import{n as hr,s as js}from"./paths-DwTjD7BU.mjs";import{G as vr}from"./shared-Be3TGzxM.mjs";import{CAPABILITIES as Er,usedCapabilities as xr}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{isD1GlobalTable as Vs,isHyperdriveGlobalTable as qs}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as Sr}from"./AGENTS_FILENAME-NQIB6wh3.mjs";import{discoverContainers as yr}from"./CONTAINERS_FILENAME-CK3xJGwm.mjs";import Ar from"./discoverCrons-B5bVCaNF.mjs";import{diagnosticAt as Ee}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as Be}from"./module-specifiers-WF8iAydP.mjs";import{a as Ws,b as q,d as $,f as F,g as At,c as v,w as bt,k as br,l as Nr,h as Pr,j as dt,i as wr}from"./attribution-Dw35rOaJ.mjs";import{contextPropertiesRead as Ir,discoverFeatureUsage as Cr}from"./capabilitiesUsedBy-FnnYmnSl.mjs";import Tr from"./readPackageDependencies-RHhGiz0k.mjs";import{listLunoraSourceFiles as x,unwrapExpression as E,listSecurityScanFiles as $e,objectLiteralFromCallbackBody as Hs,propertyInitializer as I,lunoraRelativePath as C,bindingKeyName as xe,collectCallRows as T,findObjectProperty as L,collectSecurityCallRows as Or,collectNodeRows as ut,RUN_METHODS as Gs,functionKeyOf as Ys,limitNameOf as Qs,optionsObjectLiteral as Xs,handlerOf as Rr,chainRootOf as Nt,outermostValueWrapper as w,isWriteTarget as Ue,isSameNode as me,isConstDeclaration as Z,returningFunctionOf as ft,walkChain as kr,memberAccessOf as Fr,functionReferenceSegments as Dr,isTestPath as Lr}from"./isTestPath-CgyyLk8U.mjs";import{discoverQueueDeclarations as Mr}from"./QUEUES_FILENAME-CG1CuK-T.mjs";import{discoverSandboxUsage as _r}from"./discoverSandboxUsage-CfEU2hM-.mjs";import{resolveServiceBindings as Kr}from"./readServiceBindings-DuE9xlvV.mjs";import zr from"./discoverStorageRulesMetadata-f89BWody.mjs";import{a as y,c as W,d as Js,e as Br}from"./classify-procedure-call-DxuPQkJA.mjs";import{i as $r}from"./ir-DBSvhNa-.mjs";import{gatePlatformFeatures as Ur,resolveCodegenTarget as Zs,readTargetDiagnostics as jr,studioPlatformFor as Vr}from"./DEFAULT_TARGET-GPPgJNTn.mjs";import{b as en,e as qr}from"./shard-D39UvC5v.mjs";import{e as Wr,a as Hr}from"./server-BmY5wwKY.mjs";import{emitDataModel as Gr}from"./emitDataModel-B68T_eX6.mjs";import{a as ss,r as tt,i as j,b as Yr,m as tn,c as je,e as sn,E as nn,C as rn,d as Qr,f as Xr,g as Jr}from"./context-root-B04bYCE-.mjs";import{r as Ve,s as Zr}from"./parse-validator-DYdT7Hyf.mjs";import ei from"./discoverAuthApiCalls-XK_WCMDG.mjs";import{i as ti,a as si,e as ni,b as ri,d as ii,c as oi}from"./unwrap-handler-return-T5sJhEss.mjs";import ai from"./discoverFunctions-Be-XuuSW.mjs";import ci from"./discoverHttpRoutes-CMOxt2Y9.mjs";import li from"./discoverHyperdriveCalls-mrho5AnY.mjs";import di from"./discoverInserts-BhIpUWXN.mjs";import{m as Pt,a as Fe,s as on,d as ui}from"./index-CefI-Sba.mjs";import{e as an}from"./exported-procedure-chains-C5VKkd9T.mjs";import fi from"./discoverMigrations-dVVZtuJa.mjs";import{i as B,r as cn}from"./database-calls-DWDtdDbS.mjs";import{MUTATORS_FILENAME as gi,isDefineMutatorCallee as pi,mutatorServerImplOf as mi,discoverMutators as hi}from"./MUTATORS_FILENAME-BrEGrcPU.mjs";import vi from"./discoverNondeterministicCalls-Dtb1aoGV.mjs";import{discoverNotifyConfig as Ei,discoverNotifyCalls as xi}from"./NOTIFY_FILENAME-D7DAtpNJ.mjs";import Si from"./discoverQueries-BSOjEsk3.mjs";import yi from"./discoverR2sqlCalls-KONCqZr2.mjs";import Ai from"./discoverRlsProcedures-c0DnIR4z.mjs";import bi from"./discoverRlsMetadata-9YDlDDoh.mjs";import Ni from"./discoverSchema-BTFFWy3i.mjs";import{secretKindOf as Pi,redact as wi,isHeuristicSecretKind as Ii,isSecretishName as Ci}from"./redact-Cy14LEnc.mjs";import{discoverShapes as Ti}from"./SHAPES_FILENAME-CVc2VCnS.mjs";import{i as Oi}from"./reserved-words-CW1QFbTd.mjs";import{emitApp as Ri}from"./emitApp-DUGS6Ve2.mjs";import{buildOpenApiDocument as ki,emitOpenApiModule as Fi}from"./buildOpenApiDocument-BjHdW7b2.mjs";import{buildOpenRpcDocument as Di,emitOpenRpcModule as Li}from"./OPENRPC_VERSION-BaD2A2YR.mjs";import{buildSchemaSnapshot as Mi}from"./SchemaSnapshotParseError-CPOXlFhI.mjs";import{v as _i,t as Ki,u as zi,s as Bi,w as $i}from"./shard-runtime-B7YKtoEK.mjs";import{emitCollections as Ui,emitSeed as ji,emitApi as Vi,emitInternalApi as qi}from"./emitApi-zY6egN77.mjs";import{emitCrons as Wi,emitScheduler as Hi,emitShardRegistry as Gi,emitDurableObjects as Yi,emitVectors as Qi,emitWranglerCronTriggers as Xi}from"./emitCrons-B8TBAOZ4.mjs";import Ji from"./emitDrizzleSchema-DLtfKTI4.mjs";import Zi from"./emitFunctions-DkkcTDqh.mjs";const ns={error:"ERROR",info:"INFO",warn:"WARN"},rs={ERROR:2,INFO:0,WARN:1},eo=e=>({cacheKey:"advisor_min_severity_invalid",categories:["SCHEMA"],description:"`advisor.minSeverity` in `lunora.config.*` sets the lowest advisory level codegen reports and writes into `_generated/shard.ts`. Codegen reads it by parsing the file, so it has to be a string literal.",detail:e,facing:"INTERNAL",level:"WARN",metadata:{},name:"advisor_min_severity_invalid",remediation:'Set `advisor: { minSeverity: "info" | "warn" | "error" }` as a literal on the config\'s default export.',title:"`advisor.minSeverity` is not a level codegen can read, so every advisory was reported"}),to=(e,t)=>{const{advisor:s}=cr(e);if(s===void 0||s.minSeverity===void 0&&s.unreadable!==!0)return[...t];const{minSeverity:n}=s,r=n!==void 0&&Object.hasOwn(ns,n)?ns[n]:void 0;return r===void 0?[...t,eo(n===void 0?"`advisor.minSeverity` is not a string literal codegen can read without evaluating the config: a computed value or key, or a spread that could set or override it.":`\`advisor.minSeverity\` is "${n}", which is not one of "info", "warn" or "error".`)]:t.filter(o=>rs[o.level]>=rs[r])},so={call:"function",enqueue:"queue",invoke:"service",publish:"topic",schedule:"function"},no="crons",ro=gr.replace(/\.ts$/u,""),oe=(e,t)=>`${js(e)}:${t}`,st=(e,t,s)=>t===""?{reason:`the ${s} is not a string literal`}:{to:`${e}:${t}`},io=e=>[...e.callEdges.map(t=>{const s=t.target===void 0?{reason:t.reason??"unreadable target"}:{to:`${so[t.kind]}:${t.target}`};return{file:t.file,kind:t.kind,line:t.line,scope:t.scope,...s}}),...e.queries.map(t=>({file:t.file,kind:"read",line:t.line,scope:t.scope,...st("table",t.table,"table name")})),...[...e.inserts,...e.tableWrites].map(t=>({file:t.file,kind:"write",line:t.line,scope:t.scope,...st("table",t.table,"written table")})),...e.workflowCalls.map(t=>({file:t.file,kind:"start",line:t.line,scope:t.scope,...st("workflow",t.workflow,"workflow name")}))],oo=e=>e.untracked===!0?"inside a helper only code outside any export calls":"inside a non-exported helper",ao=e=>{const{scope:t}=e;switch(t.kind){case"export":return[{...e,exportName:t.name}];case"helper":return t.callers.length===0?[{...e,unattributed:oo(t)}]:t.callers.map(s=>({...e,exportName:s}));default:return[{...e,unattributed:"at module scope"}]}},co=e=>io(e).flatMap(t=>ao(t)),lo=e=>[...e.queues.flatMap(t=>t.topic===void 0?[]:[{file:t.filePath,from:`topic:${t.topic}`,kind:"subscribe",line:0,to:`queue:${t.exportName}`}]),...e.crons.map(t=>{const s=t.workflow===void 0?void 0:`workflow:${t.workflow.exportName}`,n=t.functionPath===void 0?void 0:`function:${t.functionPath}`,r=s??n;return{file:no,from:`cron:${t.name}`,kind:"trigger",line:0,...r===void 0?{reason:"the cron has no target"}:{to:r}}})],uo=e=>new Map(e.flatMap(t=>t.tables.map(s=>[s,t.name]))),ue=(e,t)=>t===void 0?e:{...e,module:t},fo=e=>{const t=new Map,s=new Map,n=uo(e.modules),r=(c,l)=>{s.set(c,[...s.get(c)??[],l])},o=(c,l)=>{t.set(c.id,c),l!==void 0&&r(l,c.id)},a=(c,l)=>{c!==void 0&&r(oe(c.file,c.exportName),l)};for(const c of e.functions){const l=oe(c.filePath,c.exportName),u=[...hr(c.filePath),c.exportName].join(".");o(ue({detail:c.kind,id:`function:${l}`,kind:"function",name:u},Ce(e.modules,c.filePath)),l)}for(const c of e.httpRoutes){const l=oe(c.filePath,c.exportName);o(ue({id:`http:${l}`,kind:"http",name:`${c.method} ${c.path}`},Ce(e.modules,c.filePath)),l)}for(const c of e.schema.tables)o(ue({id:`table:${c.name}`,kind:"table",name:c.name},n.get(c.name)));for(const c of e.queues){const l=c.topic===void 0?{}:{detail:"subscription"};o(ue({...l,id:`queue:${c.exportName}`,kind:"queue",name:c.exportName},Ce(e.modules,c.filePath)),oe(c.filePath,c.exportName)),a(c.handlerSite,`queue:${c.exportName}`)}for(const c of e.topics)o(ue({id:`topic:${c.exportName}`,kind:"topic",name:c.exportName},Ce(e.modules,c.filePath)));for(const c of e.workflows)o({id:`workflow:${c.exportName}`,kind:"workflow",name:c.exportName},oe(ro,c.exportName)),a(c.handlerSite,`workflow:${c.exportName}`);for(const c of e.crons)o({detail:c.cron,id:`cron:${c.name}`,kind:"cron",name:c.name});for(const c of e.services){const l=c.rpcEntrypoint===void 0?"fetch":"rpc";o({detail:c.entrypoint===void 0?l:`${l} · ${c.entrypoint}`,id:`service:${c.name}`,kind:"service",name:c.worker})}return{nodes:t,sites:s}},go=e=>e==="default"?"the default export is not a registered function":`"${e}" is not a registered function`,po=(e,t)=>"from"in e?[e.from]:"unattributed"in e?{reason:e.unattributed}:t.get(oe(e.file,e.exportName))??{reason:go(e.exportName)},mo=(e,t,s)=>{if("reason"in e)return{reason:e.reason};const n=po(e,t);if("reason"in n)return n;const{to:r}=e;return s.has(r)?{drawn:n.map(o=>({from:o,kind:e.kind,to:r}))}:{reason:`${r} is not declared`}},nt=e=>`${e.from}|${e.kind}|${e.to}`,ho=e=>`${e.file}|${String(e.line)}|${e.kind}|${e.reason}`,vo=e=>{const{nodes:t,sites:s}=fo(e),n=new Map,r=new Map;for(const o of[...lo(e),...co(e)]){const a=mo(o,s,t);if("drawn"in a)for(const c of a.drawn)n.set(nt(c),c);else{const c={file:o.file,kind:o.kind,line:o.line,reason:a.reason};r.set(ho(c),c)}}return{edges:[...n.values()].toSorted((o,a)=>nt(o).localeCompare(nt(a))),nodes:[...t.values()].toSorted((o,a)=>o.id.localeCompare(a.id)),modules:e.modules.map(o=>({...o.description===void 0?{}:{description:o.description},...o.installed===!0?{installed:!0}:{},...o.ownsFolder===!1?{ownsFolder:!1}:{},name:o.name,tables:[...o.tables]})),unresolved:[...r.values()].toSorted((o,a)=>o.file.localeCompare(a.file)||o.line-a.line),version:1}},Eo=e=>`${vr}export const architecture = ${mr(e,"Record<string, unknown>")};
|
|
2
|
-
`,is=(e,t="api")=>{const s=new Map;for(const n of e){const r=js(n),o=s.get(r);if(o===void 0){s.set(r,n);continue}if(o!==n){const a=t==="api"?`the generated api.ts would declare "${r}" twice and the dispatch key "${r}:<fn>" would be ambiguous`:`the generated api.ts would declare "${r}" twice in HttpStreamsRef and again in the httpStreams object literal`;throw new Y("INTERNAL",`@lunora/codegen: "${o}" and "${n}" both map to the ${t} namespace "${r}" — ${a}. Rename one file so the two differ by more than a non-identifier character (\`-\`, \`.\`, \`/\` and \`_\` all sanitize to \`_\`).`,{status:500})}}},xo=(e,t={})=>{const{hasVectors:s=!0,scheduler:n=!1,storage:r=!1,usage:o}=t,a=[];e.tables.some(c=>Vs(c))&&a.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),e.tables.some(c=>qs(c))&&a.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'},{name:"@lunora/sql-store",reason:'`.global({ backend: "hyperdrive" })` makes `_generated/app.ts` import the `SqlCtxDbOptions` / `SqlExec` types'}),n&&a.push({name:"@lunora/scheduler",reason:"a declared cron (or `ctx.scheduler` use) makes `_generated/app.ts` import `createScheduler`"}),r&&a.push({name:"@lunora/storage",reason:"a `v.storage()` column, a storage access rule (or `ctx.storage` use) makes `_generated/app.ts` import `createStorage`"}),e.vectorIndexes.length>0&&s&&a.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/shard.ts` import `@lunora/bindings/vectors`"});for(const c of o===void 0?[]:Er)c.requiredPackage!==void 0&&o?.[c.key]===!0&&a.push({name:c.requiredPackage,reason:`\`ctx.${c.contextProperty??c.key}\` usage makes \`_generated/\` import \`${c.moduleSpecifier}\``});return a.filter((c,l)=>a.findIndex(u=>u.name===c.name)===l)},So=(e,t,s={})=>{if(t===void 0)return;const n=xo(e,s).filter(o=>!t.has(o.name));if(n.length===0)return;const r=n.map(o=>` - ${o.name} — ${o.reason}`).join(`
|
|
3
|
-
`);throw new Y("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
|
|
4
|
-
${r}
|
|
5
|
-
|
|
6
|
-
Install them with your package manager, then re-run codegen.`)},yo="env.ts",Ao=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return Be(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},bo=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(d.ImportDeclaration);return n!==void 0&&Be(n.getModuleSpecifierValue())}return!1},No=e=>{if(i.isIdentifier(e))return Ao(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&bo(t)}return!1},Po=e=>{const t=[];for(const s of e.getVariableDeclarations()){const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!No(n.getExpression()))continue;const o=s.getNameNode();if(!i.isIdentifier(o)){if(s.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw Ee(o,"defineEnv exports must be plain named exports (no destructuring)")}const a=Ws(s,"member");a!==void 0&&t.push({exportName:a})}return t},wo=(e,t)=>{const s=h(t,yo);if(!R(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),r=Po(n);if(r.length!==0){if(r.length>1)throw Ee(n,`lunora/env.ts declares ${r.length.toString()} defineEnv() contracts (${r.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return r[0]}},ln="identity.ts",Io=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return Be(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Co=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(d.ImportDeclaration);return n!==void 0&&Be(n.getModuleSpecifierValue())}return!1},To=e=>{if(i.isIdentifier(e))return Io(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&Co(t)}return!1},Oo=e=>{const t=[];for(const s of e.getVariableDeclarations()){const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!To(n.getExpression()))continue;const o=s.getNameNode();if(!i.isIdentifier(o)){if(s.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw Ee(o,"defineIdentity exports must be plain named exports (no destructuring)")}const a=Ws(s,"member");a!==void 0&&t.push({exportName:a})}return t},Ro=(e,t)=>{const s=h(t,ln);if(!R(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),r=Oo(n);if(r.length!==0){if(r.length>1)throw Ee(n,`lunora/identity.ts declares ${r.length.toString()} defineIdentity() contracts (${r.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return r[0]}},ko=new Set(["allowedHosts","deniedHosts","interceptHttps"]),Fo=(e,t)=>{const s=E(t);if(s===void 0||!i.isIdentifier(s))return s;const n=s.getText();return E(e.getDescendantsOfKind(d.VariableDeclaration).find(r=>r.getName()===n)?.getInitializer())},Do=(e,t)=>e!==void 0&&i.isObjectLiteralExpression(e)&&e.getProperties().some(s=>{if(i.isShorthandPropertyAssignment(s))return t.has(S(s));if(!i.isPropertyAssignment(s)||!t.has(S(s)))return!1;const n=E(s.getInitializer())?.getText();return n!=="false"&&n!=="undefined"}),Lo=new Set(["durable"]),Mo=new Set(["rollback"]),_o=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)?t.getName():t.getText()},Ko=new Map([["defineContainer",{keys:ko,signal:"containerEgressPolicy"}],["defineStep",{keys:Mo,signal:"workflowRollback"}],["stream",{keys:Lo,signal:"durableStreams"}]]),zo=(e,t)=>{const s=Ko.get(_o(t));if(s!==void 0)return t.getArguments().some(n=>Do(Fo(e,n),s.keys))?s.signal:void 0},Bo=(e,t)=>{const s={containerEgressPolicy:!1,durableStreams:!1,secrets:!1,workflowRollback:!1};for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.secrets||(s.secrets=Ir(r).has("secrets"));for(const o of r.getDescendantsOfKind(d.CallExpression)){const a=zo(r,o);a!==void 0&&(s[a]=!0)}if(Object.values(s).every(Boolean))break}return s},$o="createWorker",Uo="extend",os=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralValue():void 0,as=e=>{const t=[],s=os(I(e,"backupCron"));s!==void 0&&t.push(s);const n=I(e,"crons");if(n===void 0||!i.isObjectLiteralExpression(n))return t;for(const r of n.getProperties()){if(!i.isPropertyAssignment(r)&&!i.isMethodDeclaration(r))continue;const o=os(r.getNameNode());o!==void 0&&t.push(o)}return t},jo=e=>{const t=y(e.getExpression()),[s]=e.getArguments();if(s===void 0)return[];if(t===$o)return i.isObjectLiteralExpression(s)?as(s):[];if(t!==Uo||!(i.isArrowFunction(s)||i.isFunctionExpression(s)))return[];const n=Hs(s.getBody());return n===void 0?[]:as(n)},Vo=(e,t)=>{const s=[];for(const{filePath:n}of $e(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of r.getDescendantsOfKind(d.CallExpression))s.push(...jo(o))}return[...new Set(s)]},dn=e=>{if(e.kind==="id")return e.tableName;if(!(e.kind!=="array"&&e.kind!=="optional"))return e.inner===void 0?void 0:dn(e.inner)},qo=e=>{const t=new Set(e.tables.map(s=>s.name));return e.tables.some(s=>Object.values(s.shape).some(n=>{const r=dn(n);return r!==void 0&&t.has(r)}))},Wo=(e,t)=>{const s=new Map,n=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const o=s.get(r.name);if(o!==void 0)throw new Y("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${o} and agent "${r.exportName}". Workflow and agent names share one account-wide namespace and must be unique together.`,{status:500});const a=n.get(r.className);if(a!==void 0)throw new Y("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${a} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},Ho=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:r}=e,o=Ro(s,t),a=wo(s,t),c=pr(s,t),{queues:l,topics:u}=Mr(s,t),p=Kr(n),f=Sr(s,t);Wo(c,f);const m=yr(s,t),A=zr(s,t),M=Ar(s,t,c,f),H=Vo(s,t),D=Bo(s,t),b=_r(s,t),z=Cr(s,t);z.browser=z.browser||b.usesSandboxBrowser;const _=Ur(z,Zs(n,e.target),{agents:f.length>0,commitOrderedTables:r.tables.some(k=>k.commitOrdered===!0),cronTriggers:M.length>0,crossShardFanout:r.tables.some(k=>$r(k)),containerEgressPolicy:D.containerEgressPolicy,containerRuntimeScheduling:m.some(k=>k.schedulingPolicy==="durable_object"),containerSandboxTools:m.some(k=>k.sandbox===!0),durableStreams:D.durableStreams,globalTables:r.tables.some(k=>k.shardMode==="global"),queues:l.length>0,relationGraph:qo(r),secrets:D.secrets,services:p.length>0,topics:u.length>0,vectorStore:r.vectorIndexes.length>0,workerLoaders:b.usesSandboxLoader,workflowRollback:D.workflowRollback,workflowSchedules:c.some(k=>k.schedules!==void 0)}),N=_.usage,te=xr(N),se=_.signals.vectorStore!==!1,ce=_.signals.services===!1?[]:p,ne=Tr(n),Se=ne??new Set,U=Se.has("lunorash");So(r,ne,{hasVectors:se,scheduler:N.scheduler||M.length>0,storage:N.storage||A.rules.length>0||Object.keys(en(r)).length>0,usage:N});const K=R(h(t,"flags.ts")),O=R(h(t,"notify.ts"));return{agents:f,capabilities:te,containers:m,crons:M,dataModelContent:Gr(r),declaredDependencies:ne,dependencies:Se,entryCronTriggers:H,env:a,featureUsage:N,hasFlags:K,hasNotify:O,identity:o,platformGate:{..._,diagnostics:[...jr(n,e.target),..._.diagnostics]},queues:l,serverContent:Wr({agents:f,capabilities:te,containers:m,env:a,hasVectors:se,hasFlags:K,hasNotify:O,identity:o,queues:l,schema:r,services:ce,storageRuleBuckets:A.rules.map(k=>k.bucket),topics:u,useUmbrella:U,workflows:c}),services:ce,storageRulesMetadata:A,topics:u,usesSandbox:b.usesSandboxBrowser||b.usesSandboxContainer||b.usesSandboxFs,useUmbrella:U,workflows:c}},un=new Set(["delete","get","head","options","patch","post","put"]),Go=new Set(["handler","stream"]),Yo=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,cs=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Qo=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!un.has(t.getName()))return;const s=t.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!i.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},Xo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||un.has(n.getName()))break;s=n.getExpression()}return Qo(s)},Jo=e=>{for(const t of e.getDescendantsOfKind(d.PropertyAccessExpression))if(cs.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&cs.has(s.getText()))return!0}return!1},Zo=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||!Go.has(n.getName()))return;const r=Xo(s);if(!r||!Yo.test(r.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&Jo(o);return{exportName:$(e)??e.getName(),file:t,method:r.method,path:r.path,usesGuard:a}},ea=(e,t)=>{const s=[];for(const n of q(e)){const r=Zo(n,t);r&&s.push(r)}return s},ta=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ea(r,C(t,n)))}return s},sa=e=>{const t=e.getText(),s=n=>{const r=n.getNameNode();return i.isIdentifier(r)&&r.getText()===t};for(const n of e.getAncestors())if(!(!i.isArrowFunction(n)&&!i.isFunctionExpression(n)&&!i.isFunctionDeclaration(n)))for(const r of n.getParameters()){const o=r.getDescendantsOfKind(d.BindingElement).find(a=>s(a));if(o!==void 0)return o}},na=e=>{let t=e;for(;;){const s=t.getParent();if(!i.isObjectBindingPattern(s))return;const n=s.getParent();if(i.isBindingElement(n)){t=n;continue}return i.isParameterDeclaration(n)?xe(t):void 0}},ra=e=>{const t=e.getText();if(!e.getAncestors().some(o=>{const a=i.isFunctionLikeDeclaration(o)||i.isArrowFunction(o)?o.getParameters()[1]:void 0,c=a?.getNameNode();return a!==void 0&&(i.isIdentifier(c)?c.getText()===t:a.getDescendantsOfKind(d.BindingElement).some(l=>l.getName()===t))&&ss(a)}))return!1;const n=F(e),r=i.isParameterDeclaration(n)?n:n?.getFirstAncestorByKind(d.Parameter);return r!==void 0&&(i.isParameterDeclaration(n)||i.isBindingElement(n))&&ss(r)},ls=(e,t)=>{const s=e.getParent();if(i.isPropertyAccessExpression(s)&&s.getNameNode()===e||i.isPropertyAssignment(s)&&s.getNameNode()===e)return!1;if(e.getText()===t)return!0;const n=sa(e);return n!==void 0&&na(n)===t?!0:t==="args"&&ra(e)},fn=(e,t)=>i.isIdentifier(e)?ls(e,t):e.getDescendantsOfKind(d.Identifier).some(s=>ls(s,t)),ia=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t:void 0},ds=e=>{const t=i.isIdentifier(e)?F(e):void 0;return i.isVariableDeclaration(t)&&i.isIdentifier(t.getNameNode())&&!At(t)?t.getInitializer():void 0},gt=e=>fn(e,"args"),Q=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 n=e.getStart();let r,o=-1;for(const a of s.getDescendantsOfKind(d.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<n&&l>o&&(r=c,o=l)}return r},V=e=>{if(gt(e))return!0;const t=Q(e);return t!==void 0&>(t)},oa=e=>{if(i.isCallExpression(e)||i.isNewExpression(e))return!1;const t=Q(e);return t===void 0||!(i.isCallExpression(t)||i.isNewExpression(t))},ee=e=>{if(tt(e))return!0;const t=ds(e);if(t!==void 0&&tt(t))return!0;const s=t??e;return(i.isIdentifier(s)?[s]:s.getDescendantsOfKind(d.Identifier)).some(r=>{const o=ds(r);return o!==void 0&&tt(o)})},Te=(e,t)=>fn(e,t),aa=(e,t)=>{if(Te(e,t))return!0;const s=Q(e);if(s!==void 0&&Te(s,t))return!0;const n=ia(e);if(n!==void 0){const r=Q(n);return r!==void 0&&Te(r,t)}return!1},ca=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:j(e.getExpression(),["ai"]),la=(e,t)=>{if(!ca(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!V(s)||ee(s)))return{scope:v(e),file:t,line:e.getStartLineNumber()}},da=(e,t)=>T(e,t,la),ua=new Set(["generateText","streamText"]),fa=new Set(["messages","prompt","system"]),ga=[{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"]}],pa=(e,t)=>ga.some(s=>s.methods.has(t)&&s.prefixes.some(n=>e===n||e.startsWith(`${n}.`))),ma=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),n=[Yr(t.getExpression()),t.getExpression().getText()].find(r=>r!==void 0&&pa(r,s));return n===void 0?void 0:`${n}.${s}`},ha=e=>{for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=ma(t);if(s!==void 0)return s}},va=e=>{const t=new Set,s=e.getFirstAncestor(o=>i.isArrowFunction(o)||i.isFunctionExpression(o)||i.isFunctionDeclaration(o)),[n]=s?.getParameters()??[],r=n?.getNameNode();if(r===void 0||!i.isObjectBindingPattern(r))return t;for(const o of r.getElements()){const a=xe(o),c=o.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},Ea=e=>{if(gt(e))return!0;const t=va(e);return t.size===0?!1:e.getDescendantsOfKind(d.Identifier).some(s=>t.has(s.getText()))},xa=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!fa.has(S(t)))continue;const s=t.getInitializer();if(s!==void 0&&Ea(s))return!0}return!1},Sa=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=y(n.getExpression());if(r===void 0||!ua.has(r))continue;const[o]=n.getArguments();if(o===void 0||!i.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(d.CallExpression))if(y(c.getExpression())==="tool"&&(a=ha(c),a!==void 0))break;a!==void 0&&s.push({scope:v(n),file:t,line:n.getStartLineNumber(),method:r,sideEffect:a,userInputDerived:xa(o)})}return s},ya=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Sa(r,C(t,n)))}return s},Aa=e=>j(e,["fetch"]),ba=(e,t)=>{if(!Aa(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!V(s)))return{scope:v(e),file:t,line:e.getStartLineNumber()}},Na=(e,t)=>T(e,t,ba),wt=(e,t=new Set)=>{if(t.has(e))return!0;t.add(e);try{return e.getProperties().some(s=>{if(!i.isSpreadAssignment(s))return!1;const n=Ve(s.getExpression());return n===void 0||wt(n,t)})}finally{t.delete(e)}},Pa=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=L(t,"args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer(),r=n===void 0?void 0:Ve(n);return r===void 0?{objects:[],opaque:!0}:{objects:[r],opaque:wt(r)}},wa=e=>{const t=[];let s=!1,n=e;for(;i.isCallExpression(n);){const r=n.getExpression();if(!i.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const o=n.getArguments()[0],a=o!==void 0&&i.isExpression(o)?Ve(o):void 0;a===void 0?s=!0:(t.push(a),s||=wt(a))}n=r.getExpression()}return{objects:t,opaque:s}},It=(e,t)=>t?wa(t):Pa(e),gn=(e,t)=>{if(t.has(e))return[];t.add(e);try{return e.getProperties().flatMap(s=>{if(i.isSpreadAssignment(s)){const n=Ve(s.getExpression());return n===void 0?[]:gn(n,t)}return i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)?[S(s)]:[]})}finally{t.delete(e)}},Ia=e=>e.flatMap(t=>gn(t,new Set)),Ca=new Set(["check","length","max"]),pt=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!(!i.isPropertyAccessExpression(t)||t.getExpression().getText()!=="v"))return t.getName()},Ta=e=>[e,...e.getDescendants()].filter(t=>pt(t)!==void 0),Oa=e=>{let t=e;for(;;){const s=t.getParent();if(!s||!i.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;const n=s.getParent();if(!n||!i.isCallExpression(n)||n.getExpression()!==s)return!1;if(Ca.has(s.getName()))return!0;t=n}},Ra=e=>{const t=[],s=[];for(const n of e)for(const r of n.getProperties()){if(!i.isPropertyAssignment(r))continue;const o=r.getInitializer();if(!o)continue;const a=Ta(o),c=S(r);a.some(l=>pt(l)==="any")?t.push(c):a.some(l=>pt(l)==="string"&&!Oa(l))&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},ka=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=W(s);if(n?.visibility!=="public")return;const{objects:r}=It(s,n.receiver),{anyArgs:o,unboundedStringArgs:a}=Ra(r);if(!(o.length===0&&a.length===0))return{anyArgs:o,exportName:$(e)??e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Fa=(e,t)=>{const s=[];for(const n of q(e)){const r=ka(n,t);r&&s.push(r)}return s},Da=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Fa(r,C(t,n)))}return s},rt=e=>e?.getKind()===d.TrueKeyword,La=e=>e?.getKind()===d.FalseKeyword,Ma=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,_a=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Ka=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&y(t.getExpression())==="scim"),za=e=>e!==void 0&&i.isCallExpression(e)&&_a.has(y(e.getExpression())??""),Ba=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),$a=e=>{const t=I(e,"advanced"),s=I(e,"emailAndPassword"),n=I(e,"session");return{analyzable:!0,disableCsrfCheck:rt(I(t,"disableCSRFCheck")),emailPasswordEnabled:rt(I(s,"enabled")),requireEmailVerification:rt(I(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Ka(I(e,"plugins"))&&za(I(e,"database")),secureCookiesDisabled:La(I(t,"useSecureCookies")),sessionFreshAgeZero:Ma(I(n,"freshAge")),trustedOriginsWildcard:Ba(I(e,"trustedOrigins"))}},Ua=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),ja=(e,t)=>{if(y(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(o=>i.isSpreadAssignment(o)),r=s!==void 0&&i.isObjectLiteralExpression(s)&&!n?$a(s):Ua();return{scope:v(e),file:t,line:e.getStartLineNumber(),...r}},Va=(e,t)=>Or(e,t,ja),qa=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return tn(e.getExpression(),t.matchReceiver)?s:void 0},Wa=(e,t,s)=>{const n=qa(e.getExpression(),s);if(n===void 0)return;const r=e.getArguments()[s.argIndex];if(!(!r||!V(r)||ee(r))&&!(s.requireUnmodifiedReach===!0&&!oa(r)))return{scope:v(e),file:t,line:e.getStartLineNumber(),method:n}},qe=(e,t,s)=>T(e,t,(n,r)=>Wa(n,r,s)),Ha=new Set(["content","pdf","scrape","screenshot"]),Ga=(e,t)=>qe(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Ha}),pn=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getExpression();return i.isPropertyAccessExpression(n)&&n.getName()===t?s.getName():void 0},Ya=e=>{if(!i.isPropertyAccessExpression(e))return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="scheduler"||i.isIdentifier(t)&&t.getText()==="scheduler"},Qa=new Map([["publish",{kind:"publish",surface:"topics"}],["publishBatch",{kind:"publish",surface:"topics"}],["send",{kind:"enqueue",surface:"queues"}],["sendBatch",{kind:"enqueue",surface:"queues"}]]),Xa=(e,t)=>{const s=Ys(t);return s!==void 0?{kind:"call",target:s}:e!=="run"&&t!==void 0?{kind:"call",reason:"the function reference is not a static api.* / internal.* chain"}:void 0},Ja=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),[n,r]=e.getArguments();if(Gs.has(s))return Xa(s,n);if((s==="runAfter"||s==="runAt")&&Ya(t)){const c=Ys(r);return c===void 0?{kind:"schedule",reason:"the scheduled function is not a static api.* / internal.* chain"}:{kind:"schedule",target:c}}const o=Qa.get(s),a=o===void 0?void 0:pn(t,o.surface);return o===void 0||a===void 0?void 0:{kind:o.kind,target:a}},us=(e,t,s)=>s===void 0?void 0:{...s,file:t,line:e.getStartLineNumber(),scope:v(e)},Za=(e,t)=>[...T(e,t,(s,n)=>us(s,n,Ja(s))),...ut(e,t,d.PropertyAccessExpression,(s,n)=>{const r=pn(s,"services");return us(s,n,r===void 0?void 0:{kind:"invoke",target:r})})],ec=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),tc=new Set(["RateLimiter"]),sc=new Set(["extend"]),fs="lunora",nc=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],mn=e=>{const t=[],s=[];let n=!1;for(const r of e.getProperties()){if(i.isSpreadAssignment(r)){n=!0;continue}if(i.isPropertyAssignment(r)){const o=S(r);t.push(o),r.getInitializer()?.getKind()===d.TrueKeyword&&s.push(o);continue}(i.isShorthandPropertyAssignment(r)||i.isMethodDeclaration(r))&&t.push(S(r))}return{analyzable:!n,presentKeys:t,trueKeys:s}},mt=e=>e&&i.isObjectLiteralExpression(e)?mn(e):{analyzable:!1,presentKeys:[],trueKeys:[]},rc=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&Hs(t.getBody());return s?mn(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},ic=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=y(n.getExpression());r!==void 0&&(ec.has(r)?s.push({callee:r,file:t,line:n.getStartLineNumber(),...mt(n.getArguments()[0])}):sc.has(r)&&s.push({callee:r,file:t,line:n.getStartLineNumber(),...rc(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(d.NewExpression)){const r=y(n.getExpression());r===void 0||!tc.has(r)||s.push({callee:r,file:t,line:n.getStartLineNumber(),...mt(n.getArguments()[0])})}return s},oc=(e,t)=>{for(const s of nc){const n=h(t,s);if(!R(n))continue;const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=[];for(const a of r.getDescendantsOfKind(d.CallExpression))y(a.getExpression())===fs&&o.push({callee:fs,file:s,line:a.getStartLineNumber(),...mt(a.getArguments()[0])});return o}return[]},ac=(e,t)=>{const s=[];for(const{displayPath:n,filePath:r}of $e(t)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ic(o,n))}return s.push(...oc(e,fe(t))),s},gs="ctx.containers.",cc=e=>{if(!e.startsWith(gs))return!1;const t=e.slice(gs.length);return t.length>0&&!t.includes(".")},lc=(e,t)=>qe(e,t,{argIndex:0,matchReceiver:cc,methods:new Set(["get"])}),dc=new Set(["allow","deny","setAllowed"]),uc=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=L(t,"enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},fc=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!uc(e)))return{detail:"enableInternet: true",scope:v(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},gc=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!dc.has(s.getName()))return;const n=s.getExpression();if(!(!i.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),scope:v(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},pc=(e,t)=>fc(e,t)??gc(e,t),mc=(e,t)=>T(e,t,pc),hc=new Set(["defineExportSink","r2Sink","webhookExportSink"]),vc=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return hc.has(s)?s:void 0},Ec=e=>{const t=[],s=[];for(const n of e.getProperties()){if(i.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(n)){const r=S(n);t.push(r);const o=n.getInitializer();o&&i.isStringLiteral(o)&&o.getLiteralText()===""&&s.push(r);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n)||i.isGetAccessorDeclaration(n))&&t.push(S(n))}return{analyzable:!0,emptyKeys:s,presentKeys:t}},xc=(e,t)=>{const s=[];for(const{displayPath:n,filePath:r}of $e(t)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r);for(const a of o.getDescendantsOfKind(d.CallExpression)){const c=vc(a);if(c===void 0)continue;const l=a.getArguments()[0],u=l&&i.isObjectLiteralExpression(l)?Ec(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:u.analyzable,emptyKeys:u.emptyKeys,factory:c,file:n,line:a.getStartLineNumber(),presentKeys:u.presentKeys})}}return s},Sc=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),yc=new Set(["dbRateLimit","rateLimit"]),Ac=e=>{const t=Xs(e);if(!t)return!1;const s=L(t,"failOpen");return s!==void 0&&i.isPropertyAssignment(s)&&s.getInitializer()?.getKind()===d.TrueKeyword},bc=(e,t)=>{const s=y(e.getExpression());if(s===void 0)return;const n=Sc.get(s);if(n!==void 0)return{callee:s,scope:v(e),failOpen:Ac(e.getArguments()[n]),file:t,limitName:yc.has(s)?Qs(e):"",line:e.getStartLineNumber()}},Nc=(e,t)=>T(e,t,bc),Pc=new Set(["boolean","number","object","string"]),wc=e=>{const t=e.getName();if(!Pc.has(t))return;const s=e.getExpression();return j(s,["flags"])||j(s,["flags","details"])?t:void 0},Ic=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=wc(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(i.isStringLiteral(n)||i.isNoSubstitutionTemplateLiteral(n)))return;const r=n.getLiteralValue();return r.length>0?{key:r,type:s}:void 0},Cc=(e,t)=>{const s=new Map;for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of r.getDescendantsOfKind(d.CallExpression)){const a=Ic(o);a&&!s.has(a.key)&&s.set(a.key,a.type)}}return[...s.entries()].map(([n,r])=>({key:n,type:r})).toSorted((n,r)=>n.key.localeCompare(r.key))},Tc=e=>{const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const s=W(t);if(s?.kind!=="query")return;const n=Rr(t,s.receiver);return n?{exportName:$(e)??e.getName(),handler:n}:void 0},ps=e=>{const t=e.getParent();return t&&i.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},Oc=e=>{const t=ps(e);if(!t)return"ctx.flags";if(t.getName()==="details"){const s=ps(t);return s?`ctx.flags.details.${s.getName()}`:"ctx.flags.details"}return`ctx.flags.${t.getName()}`},Rc=(e,t)=>{const s=[];for(const n of je(e.handler,"flags"))s.push({callee:Oc(n),exportName:e.exportName,file:t,line:n.getStartLineNumber()});return s},kc=(e,t)=>{const s=[];for(const n of q(e)){const r=Tc(n);r&&s.push(...Rc(r,t))}return s},Fc=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...kc(r,C(t,n)))}return s},Dc=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="boolean"?!1:j(e.getExpression(),["flags"]),Lc=e=>{if(e?.getKind()===d.TrueKeyword)return!0;if(e?.getKind()===d.FalseKeyword)return!1},Mc=(e,t)=>{if(!Dc(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const r=s.getLiteralValue(),o=Lc(n);if(!(r.length===0||o===void 0))return{defaultValue:o,scope:v(e),file:t,key:r,line:e.getStartLineNumber()}},_c=(e,t)=>T(e,t,Mc),Kc=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const s=t.getTypeAtLocation(e).getProperty("types");if(!s)return;const n=s.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!n)return;const r=n.getTypeAtLocation(e),o=r.getText(e);if(!o||o==="any"||o==="never"||ti(o))return;const a=e.getSourceFile().getFilePath();if(si(r,e,a)){const c=ni(r,e,a,0,new Set);return c===void 0&&ri(o),c}return o},zc=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Bc=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},$c=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=C(t,n);for(const a of r.getDescendantsOfKind(d.CallExpression))zc(a)&&s.push({file:o,indexName:Bc(a),line:a.getStartLineNumber()})}return s},he=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,hn=e=>{const t=e.getArguments()[0],s=he(t);if(s!==void 0)return s;if(t===void 0||!i.isObjectLiteralExpression(t))return;const n=L(t,"handler");return n!==void 0&&i.isPropertyAssignment(n)?he(n.getInitializer()):void 0},Uc=new Set(["delete","get","head","options","patch","post","put"]),jc=new Set(["handler","stream"]),Vc=new Set(["runAction","runMutation"]),qc=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),ve=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,vn=(e,t)=>{if(!(e===void 0||!i.isObjectBindingPattern(e))){for(const s of e.getElements())if(xe(s)===t){const r=s.getNameNode();return i.isIdentifier(r)?r.getText():void 0}}},ms=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?i.isIdentifier(s)?s.getText():void 0:vn(s,"ctx")},hs=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&i.isIdentifier(s)?s.getText():void 0:vn(s,"request")},vs=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(d.CallExpression);i.isCallExpression(s)&&n.unshift(s);for(const r of n){const o=r.getExpression();if(!i.isPropertyAccessExpression(o))continue;const a=o.getName(),c=o.getExpression();if(Vc.has(a)&&ve(c,t))return a;if(qc.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&ve(c.getExpression(),t))return`db.${a}`}},Es=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(d.PropertyAccessExpression))if(n.getName()==="auth"&&ve(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(d.VariableDeclaration)){const r=n.getNameNode();if(!(!i.isObjectBindingPattern(r)||!ve(n.getInitializer(),t))){for(const o of r.getElements())if(xe(o)==="auth")return!0}}return!1},Wc=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,Hc=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="get"&&s.getName()!=="has")return!1;const n=s.getExpression();return i.isPropertyAccessExpression(n)&&n.getName()==="headers"&&ve(n.getExpression(),t)},Gc=e=>[...i.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(d.StringLiteral).map(t=>t.getLiteralText())],En=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:Gc(s)},Yc=(e,t)=>{const s=e.getText();for(let n=e.getParent();n!==void 0;n=n.getParent()){if(!i.isArrowFunction(n)&&!i.isFunctionExpression(n)||!n.getParameters().some(c=>c.getName()===s))continue;const r=n.getParent();if(!i.isCallExpression(r))return[];const o=r.getExpression();if(!i.isPropertyAccessExpression(o))return[];const a=o.getExpression();return i.isIdentifier(a)?En(t,a.getText()):[]}return[]},Qc=e=>{const t=e.getArguments()[0];if(t===void 0)return[];if(i.isStringLiteral(t))return[t.getLiteralText()];if(!i.isIdentifier(t))return[];const s=e.getSourceFile(),n=En(s,t.getText());return n.length>0?n:Yc(t,s)},xs=(e,t)=>{if(t===void 0)return!1;const s=e.getBody(),n=s.getDescendantsOfKind(d.CallExpression);return i.isCallExpression(s)&&n.unshift(s),n.some(r=>Hc(r,t)&&Qc(r).some(o=>Wc.test(o)))},Xc=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!jc.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))return;const r=n.getName();if(Uc.has(r)){const o=n.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?r.toUpperCase():void 0}s=n.getExpression()}},Jc=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=he(e.getArguments()[0]),l=c&&ms(c,!0);if(!c||l===void 0||xs(c,hs(c,!0)))return;const u=vs(c,l);return u===void 0?void 0:{scope:v(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:Es(c,l),sideEffect:u}}const n=Xc(e);if(n===void 0)return;const r=he(e.getArguments()[0]),o=r&&ms(r,!1);if(!r||o===void 0||xs(r,hs(r,!1)))return;const a=vs(r,o);return a===void 0?void 0:{scope:v(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:Es(r,o),sideEffect:a}},Zc=(e,t)=>T(e,t,Jc),el=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),tl=new Set(["append","set"]),xn=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",Ss=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(d.CallExpression)]:e.getDescendantsOfKind(d.CallExpression)).some(n=>el.has(y(n.getExpression())??"")&&Te(n,t)),sl=(e,t)=>{if(Ss(e,t))return!0;const s=Q(e);return s!==void 0&&Ss(s,t)},ht=(e,t)=>aa(e,t)&&!sl(e,t),nl=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=Q(e);return t!==void 0&&i.isNewExpression(t)&&y(t.getExpression())==="Headers"},De=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=Q(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},Ct=(e,t,s)=>{for(const n of e.getProperties())if(i.isPropertyAssignment(n)){const r=n.getInitializer();r!==void 0&&ht(r,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:xn(n.getNameNode()),line:r.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(n)){const r=n.getNameNode();ht(r,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:S(n),line:r.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(n)){const r=De(n.getExpression());r!==void 0&&Ct(r,t,s)}},Sn=(e,t)=>{const s=De(e);if(s===void 0)return;const n=L(s,"headers");if(n===void 0||!i.isPropertyAssignment(n))return;const r=De(n.getInitializer());r!==void 0&&Ct(r,"response-init",t)},rl=(e,t)=>{const s=y(e.getExpression());if(s==="Response")Sn(e.getArguments()[1],t);else if(s==="Headers"){const n=De(e.getArguments()[0]);n!==void 0&&Ct(n,"headers-ctor",t)}},il=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName(),r=s.getExpression();if(n==="json"&&i.isIdentifier(r)&&r.getText()==="Response"){Sn(e.getArguments()[1],t);return}if(tl.has(n)&&nl(r)){const o=e.getArguments()[1];o!==void 0&&ht(o,t.requestName)&&t.rows.push({scope:t.scope,file:t.relativePath,headerName:xn(e.getArguments()[0]),line:o.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},ol=(e,t)=>{for(const s of e.getDescendantsOfKind(d.NewExpression))rl(s,t);for(const s of e.getDescendantsOfKind(d.CallExpression))il(s,t)},al=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=he(e.getArguments()[0]);if(n===void 0)return[];const r=n.getParameters()[1];if(r===void 0)return[];const o=r.getNameNode();if(!i.isIdentifier(o))return[];const a=[];return ol(n,{scope:v(e),relativePath:t,requestName:o.getText(),rows:a}),a},cl=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression))s.push(...al(n,t));return s},ll=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...cl(r,C(t,n)))}return s},dl=new Set(["auth","context.auth"]),ul="userId",fl=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(s))}return t},gl=(e,t)=>{const s=h(t,ln);if(!R(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const r of n.getDescendantsOfKind(d.CallExpression)){if(y(r.getExpression())!=="defineIdentity")continue;const[o]=r.getArguments();return o&&i.isObjectLiteralExpression(o)?fl(o):void 0}},ys=e=>{if(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity")return;const t=e.getExpression();return dl.has(t.getText())||j(t,["auth"])?e:void 0},pl=e=>{if(i.isPropertyAccessExpression(e)&&ys(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&ys(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},As=(e,t,s)=>{const n=pl(e);return n===void 0?void 0:{declared:n===ul||s.has(n),file:t,key:n,line:e.getStartLineNumber(),scope:v(e)}},ml=(e,t)=>{const s=gl(e,t);return s===void 0?[]:[...ut(e,t,d.PropertyAccessExpression,(n,r)=>As(n,r,s)),...ut(e,t,d.ElementAccessExpression,(n,r)=>As(n,r,s))]},hl=(e,t)=>{if(y(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=I(s,"key");if(!(!n||!V(n)||ee(n)))return{scope:v(e),file:t,line:e.getStartLineNumber()}},vl=(e,t)=>T(e,t,hl),El=e=>e.getProperties().some(t=>{if(i.isSpreadAssignment(t))return!0;const s=lr(t.getNameNode());return s===void 0||s==="namespace"}),xl=(e,t)=>{for(const{filePath:s}of $e(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const r of n.getDescendantsOfKind(d.CallExpression)){const o=r.getExpression(),[a]=r.getArguments();if(!(!i.isPropertyAccessExpression(o)||o.getName()!=="auth"||a===void 0)&&(!i.isObjectLiteralExpression(a)||El(a)))return r}}},Sl="https://lunora.sh/docs/concepts/data-residency#pinning-auth-and-voice",yl=(e,t)=>{if(!(e.jurisdiction===void 0||e.jurisdictionPinsAuth===!0||t===void 0))throw Ee(t,`the schema pins Durable Objects to the "${e.jurisdiction}" jurisdiction, and this project also has DO-backed auth (users, sessions, accounts, credentials). Pinning the auth object resolves it to a NEW, EMPTY object: existing users stay in the unpinned one until you copy them across (${Sl}). Acknowledge with \`.jurisdiction("${e.jurisdiction}", { pinAuth: true })\`, deploy, then run the copy. For D1-mode auth the acknowledgement changes nothing.`,{code:"JURISDICTION_MOVE",status:422})},Al=new Set(["delete","get","getRaw","getWithMetadata","put"]),bl=(e,t,s=[])=>{const n=qe(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.kv"||r.startsWith("ctx.kv."),methods:Al});return bt(n,s)},Nl=new Set(["queue","send"]),bs=new Set(["bcc","cc","to"]),Pl=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Nl.has(t))return;const s=e.getExpression();return j(s,["mail"])||j(s,["email"])?t:void 0},wl=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return bs.has(S(t))&&V(n)&&!ee(n)}if(!i.isPropertyAssignment(t)||!bs.has(S(t)))return!1;const s=t.getInitializer();return s!==void 0&&V(s)&&!ee(s)}):!1,Il=(e,t)=>{const s=Pl(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!wl(n)))return{scope:v(e),file:t,line:e.getStartLineNumber(),method:s}},Cl=(e,t)=>T(e,t,Il),Tl=e=>i.isPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?i.isComputedPropertyName(e.getNameNode()):!1,Ol=e=>i.isPropertyAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?Tl(e):!0,yn=(e,t=!1)=>{for(const s of e.getProperties()){if(Ol(s))return!0;if(t)continue;if(!i.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!i.isObjectLiteralExpression(n)||yn(n,!0))return!0}return!1},Rl=(e,t)=>{for(const s of x(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:r}of an(n))for(const o of Pt(r)){const a=o.getArguments()[0];if(a!==void 0&&(!i.isObjectLiteralExpression(a)||yn(a)))return!0}}return!1},kl=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const r=Fe(n);if(r===void 0||!i.isPropertyAssignment(n))continue;const o=n.getInitializer();if(!(!o||!i.isObjectLiteralExpression(o)))for(const a of o.getProperties()){const c=Fe(a);c!==void 0&&s.push({column:c,strategy:on(a),table:r})}}return s},Fl=(e,t)=>{const s=new Map;for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:o}of an(r))for(const a of Pt(o))for(const c of kl(a)){const l=`${c.table}\0${c.column}`;s.has(l)||s.set(l,c)}}return{columns:[...s.values()]}},Dl=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!i.isObjectLiteralExpression(n))return[];const r=[];for(const o of n.getProperties()){const a=Fe(o);if(a===void 0||!i.isPropertyAssignment(o))continue;const c=o.getInitializer();if(!(!c||!i.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const u=Fe(l);if(u===void 0)continue;const p=on(l);p!=="custom"&&r.push({column:u,exportName:t,file:s,line:l.getStartLineNumber(),strategy:p,table:a})}}return r},Ll=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?W(s):void 0;return n?.receiver?Pt(n.receiver).flatMap(r=>Dl(r,$(e)??e.getName(),t)):[]},Ml=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=C(t,n);for(const a of q(r))s.push(...Ll(a,o))}return s},_l=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return B(s)},Kl=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=L(t,"server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},zl=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==d.CallExpression)return;const s=t;return pi(s.getExpression())?s:void 0},Bl=e=>{const t=zl(e),s=t===void 0?void 0:Kl(t);if(s===void 0)return[];const n=e.getNameNode(),r=i.isIdentifier(n)?$(e)??n.getText():"";return s.getDescendantsOfKind(d.CallExpression).filter(o=>_l(o)).map(o=>({exportName:r,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},$l=e=>e.getVariableDeclarations().flatMap(t=>Bl(t)),Ul=(e,t)=>{const s=h(t,gi);if(!R(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return $l(n)},jl=new Set(["delete","get","patch"]),Vl=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),ql=new Set(["auth","identity","session","user"]),Wl=new Set([d.EqualsEqualsEqualsToken,d.EqualsEqualsToken,d.ExclamationEqualsEqualsToken,d.ExclamationEqualsToken]),Hl=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!B(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},Gl=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 n=s.getNameNode();return i.isIdentifier(n)?n.getText():void 0},Yl=(e,t)=>e.getDescendantsOfKind(d.Identifier).some(s=>s.getText()===t),Ql=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(d.ThrowStatement).length>0||e.getDescendantsOfKind(d.ReturnStatement).length>0,Xl=(e,t)=>e.getDescendantsOfKind(d.IfStatement).some(s=>Yl(s.getExpression(),t)&&Ql(s.getThenStatement())),Jl=(e,t)=>{for(const s of e.getDescendantsOfKind(d.CallExpression)){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))continue;const r=n.getName();if(!jl.has(r))continue;const o=n.getExpression();if(!(B(o)||i.isPropertyAccessExpression(o)&&B(o.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&i.isIdentifier(c)&&c.getText()===t)return r}},Zl=e=>e.getDescendantsOfKind(d.CallExpression).some(t=>t.getArguments().some(s=>sn(Nt(s))!==void 0)),ed=e=>e.getDescendantsOfKind(d.BinaryExpression).some(t=>Wl.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),td=e=>{for(const t of e.getDescendantsOfKind(d.Identifier))if(Vl.has(t.getText()))return!0;return[...ql].some(t=>je(e,t).length>0)?!0:Zl(e)||ed(e)},sd=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=W(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const r=hn(s);if(r===void 0)return[];const o=n.receiver!==void 0&&Js(n.receiver,"use","rls"),a=td(r),c=new Set,l=[];for(const u of r.getDescendantsOfKind(d.CallExpression)){const p=Hl(u);if(p===void 0)continue;const f=Gl(u);if(f===void 0||c.has(f)||!Xl(r,f))continue;const m=Jl(r,f);m!==void 0&&(c.add(f),l.push({exportName:$(e)??e.getName(),file:t,line:u.getStartLineNumber(),mentionsOwnership:a,sinkMethod:m,table:p,usesRls:o,visibility:n.visibility}))}return l},nd=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=C(t,n);for(const a of q(r))s.push(...sd(a,o))}return s},An=(e,t)=>{const s=i.isIdentifier(e)&&t!==void 0?F(e):void 0;return s===void 0||t===void 0?!1:s.compilerNode===t.compilerNode?i.isIdentifier(t.getNameNode()):i.isBindingElement(s)&&s.getFirstAncestorByKind(d.Parameter)?.compilerNode===t.compilerNode},rd=e=>{const t=w(e),s=t.getParent();return(i.isPropertyAccessExpression(s)||i.isElementAccessExpression(s))&&s.getExpression()===t&&!Ue(s)},id=e=>{const t=w(e).getParent();return i.isVariableDeclaration(t)&&i.isObjectBindingPattern(t.getNameNode())},od=e=>{const s=w(e).getParent();if(i.isSpreadAssignment(s)||i.isSpreadElement(s)){const n=s.getParent();return(i.isObjectLiteralExpression(n)||i.isArrayLiteralExpression(n))&&!Ue(n)}return i.isTemplateSpan(s)&&!i.isTaggedTemplateExpression(s.getParent().getParent())},Le=e=>{const t=F(e);return t===void 0||Nr(t.getSourceFile())},vt=(e,t)=>{const s=w(e),n=s.getParent();if(!i.isCallExpression(n))return!1;const r=n.getArguments().indexOf(s),o=E(n.getExpression());if(r===-1||o===void 0)return!1;if(i.isIdentifier(o))return o.getText()==="structuredClone"&&Le(o);if(An(Nt(o),t))return!(i.isPropertyAccessExpression(o)&&nn.has(o.getName()))||i.isExpressionStatement(w(i.isAwaitExpression(n.getParent())?n.getParentOrThrow():n).getParent());if(!i.isPropertyAccessExpression(o))return!1;const a=o.getExpression();if(!i.isIdentifier(a)||!Le(a))return!1;const c=a.getText(),l=o.getName();switch(c){case"console":return!0;case"JSON":return l==="stringify";case"Object":return["entries","freeze","isFrozen","keys","values"].includes(l)||l==="assign"&&r>0;default:return!1}},Oe={kind:"opaque"},ad={kind:"unreached"},cd=e=>{const t=e.getSymbol()?.getDeclarations()??[],s=t.filter(o=>i.isFunctionDeclaration(o)&&o.hasBody()),[n]=s;return t.every(o=>i.isFunctionDeclaration(o)&&o.getSourceFile()===e.getSourceFile())&&s.length===1&&i.isFunctionDeclaration(n)?n:void 0},Et=e=>{const t=E(e);if(i.isArrowFunction(t)||i.isFunctionExpression(t))return t;const s=i.isIdentifier(t)?F(t):void 0;if(s?.getSourceFile()!==e.getSourceFile())return;if(i.isFunctionDeclaration(s)){const r=cd(s);return r===void 0||At(r)?void 0:r}const n=Z(s)?E(s.getInitializer()):void 0;return i.isArrowFunction(n)||i.isFunctionExpression(n)?n:void 0},bn=(e,t,s)=>{const n=t.getArguments(),r=n.indexOf(s),o=r===-1||n.slice(0,r+1).some(l=>i.isSpreadElement(l))||e.getDescendantsOfKind(d.Identifier).some(l=>l.getText()==="arguments"),a=e.getParameters(),c=a[r];return o?Oe:c===void 0?a.some(l=>l.isRestParameter())?Oe:ad:c.isRestParameter()?Oe:{kind:"parameter",parameter:c}},ld=e=>{const t=w(e),s=t.getParent();if(!i.isCallExpression(s)||s.getExpression()===t)return;const n=Et(s.getExpression());return n===void 0?Oe:bn(n,s,t)},dd=new Set(["__defineGetter__","__defineSetter__","__proto__"]),ud=e=>i.isForInStatement(e)?e.getExpression():i.isConditionalExpression(e)?e.getCondition():i.isElementAccessExpression(e)?e.getArgumentExpression():void 0,Nn=e=>{const t=w(e),s=t.getParent();if(i.isIfStatement(s)||i.isWhileStatement(s)||i.isDoStatement(s)||i.isSwitchStatement(s)||i.isCaseClause(s)||i.isTypeOfExpression(s)||i.isVoidExpression(s)||i.isComputedPropertyName(s))return!0;if(i.isTemplateSpan(s))return!i.isTaggedTemplateExpression(s.getParent().getParent());const n=ud(s);if(n!==void 0)return me(n,t);if(i.isPrefixUnaryExpression(s))return s.getOperatorToken()!==d.PlusPlusToken&&s.getOperatorToken()!==d.MinusMinusToken;if(!i.isBinaryExpression(s))return!1;const r=s.getOperatorToken().getKind(),o=r>=d.FirstAssignment&&r<=d.LastAssignment,a=r===d.QuestionQuestionToken||r===d.BarBarToken||r===d.AmpersandAmpersandToken;return!o&&!a},fd=4,Pn=(e,t,s=0)=>{if(br(e))return!0;if(rd(e)){const r=w(e).getParent(),o=i.isElementAccessExpression(r)?r.getArgumentExpression():void 0,a=i.isStringLiteral(o)?o.getLiteralValue():void 0,c=i.isPropertyAccessExpression(r)?r.getName():a;return c===void 0||!dd.has(c)}if(id(e)||od(e)||Nn(e)||vt(e,t))return!0;const n=ld(e);return n?.kind==="unreached"||n?.kind==="parameter"&&gd(n.parameter,s+1)},Ns=new WeakMap,gd=(e,t=0)=>{const s=e.getNameNode();if(!i.isIdentifier(s))return!0;const n=Ns.get(e.compilerNode);if(n!==void 0)return n;if(t>fd)return!1;const o=(s.getSymbol()?.getDeclarations().length??0)===1&&e.getParentOrThrow().getDescendantsOfKind(d.Identifier).every(a=>a===s||a.getText()!==s.getText()||F(a)?.compilerNode!==e.compilerNode||Pn(a,void 0,t));return(o||t===0)&&Ns.set(e.compilerNode,o),o},Ps=new WeakMap,pd=(e,t)=>{const s=i.isFunctionExpression(e)?e.getNameNode():void 0;if(!i.isArrowFunction(e)&&e.getFirstDescendantByKind(d.ThisKeyword)!==void 0)return!0;const n=new Set([t.getName(),...s===void 0?[]:[s.getText()]]);return e.getDescendantsOfKind(d.Identifier).some(r=>{if(r===s||!n.has(r.getText()))return!1;const o=F(r)?.compilerNode;return o!==void 0&&(o===t.compilerNode||s!==void 0&&o===e.compilerNode)})},md=(e,t,s)=>{const{context:n,impl:r}=e,o=Ps.get(r.compilerNode);if(o!==void 0)return o;const a=t.getNameNode(),c=i.isIdentifier(a)?[a]:a.getDescendantsOfKind(d.BindingElement).flatMap(f=>{const m=f.getNameNode();return i.isIdentifier(m)?[m]:[]}),l=new Map(c.map(f=>[f.getText(),f.getParentOrThrow().compilerNode])),u=f=>i.isIdentifier(a)?Pn(f,n):!Ue(f),p=!pd(r,s)&&c.every(f=>(f.getSymbol()?.getDeclarations().length??0)===1)&&r.getDescendantsOfKind(d.Identifier).every(f=>{const m=f.getText();if(m==="arguments")return!1;const A=l.get(m);return A===void 0||c.includes(f)||F(f)?.compilerNode!==A?!0:u(f)});return Ps.set(r.compilerNode,p),p},ws=new WeakMap,hd=e=>{let t=ws.get(e.compilerNode);return t===void 0&&(t=new Map(e.getVariableDeclarations().flatMap(s=>{const n=mi(s);return n===void 0?[]:[[n.compilerNode,s]]})),ws.set(e.compilerNode,t)),t},vd=e=>{const t=hd(e.getSourceFile()),s=e.getAncestors().find(l=>t.has(l.compilerNode)),n=s===void 0?void 0:t.get(s.compilerNode);if(s===void 0||n===void 0)return;const[r,o]=s.getParameters(),a=o===void 0||o.isRestParameter()?void 0:o,c={context:r,impl:s,mutatorName:$(n)??n.getName()};return a!==void 0&&md(c,a,n)?{...c,parameter:a,pristine:!0}:{...c,parameter:a,pristine:!1}},Ed=new Set(["at","concat","filter","find","findLast","flat","reverse","slice","sort","toReversed","toSorted"]),xd=new Map([["Array",new Set(["from","of"])],["Object",new Set(["entries","values"])]]),xt=new Set(["catch","every","filter","finally","find","findIndex","findLast","findLastIndex","flatMap","forEach","map","reduce","reduceRight","some","sort","then"]),wn=e=>e.getNameNode().getDescendantsOfKind(d.BindingElement).filter(t=>i.isIdentifier(t.getNameNode())),Sd=e=>{const t=w(e),s=t.getParent();if(i.isVariableDeclaration(s))return me(s.getInitializer(),t)?s:void 0;const n=i.isForOfStatement(s)&&s.getExpression()===t?s.getInitializer():void 0;return i.isVariableDeclarationList(n)?n.getDeclarations()[0]:void 0},yd=e=>{const t=Sd(e);return t===void 0?void 0:i.isIdentifier(t.getNameNode())?i.isForOfStatement(t.getParent().getParent())||Z(t)?[t]:void 0:wn(t)},ge=e=>e.isUnion()?e.getUnionTypes().every(t=>ge(t)):e.isIntersection()?e.getIntersectionTypes().some(t=>ge(t)):!e.isAny()&&!e.isUnknown()&&!e.isObject()&&!e.isTypeParameter(),Me=(e,t,s)=>{const n=i.isCallExpression(e)?E(e.getExpression()):void 0;return i.isPropertyAccessExpression(n)&&t.has(n.getName())&&(s===void 0||n.getExpression()===s)},Re=e=>{const t=E(e);if(!i.isArrowFunction(t)&&!i.isFunctionExpression(t))return;const s=t.getBody();return i.isBlock(s)?s.getDescendantsOfKind(d.ReturnStatement).filter(n=>n.getFirstAncestor(r=>i.isFunctionLikeDeclaration(r))===t).map(n=>n.getExpression()):[s]},Ad=e=>{const t=i.isCallExpression(e)?E(e.getExpression()):void 0,s=i.isPropertyAccessExpression(t)?t.getExpression():void 0;return i.isPropertyAccessExpression(t)&&i.isIdentifier(s)&&xd.get(s.getText())?.has(t.getName())===!0&&Le(s)},bd=e=>{const t=ft(e);if(!i.isArrowFunction(t)&&!i.isFunctionExpression(t))return;const s=w(t),n=s.getParent();return i.isCallExpression(n)&&n.getArguments().includes(s)&&Me(n,rn)?n:void 0},Nd=(e,t)=>{if(!(i.isPropertyAccessExpression(e)||i.isElementAccessExpression(e))||e.getExpression()!==t)return;const s=w(e),n=s.getParent();return!i.isCallExpression(n)||n.getExpression()!==s?e:Me(n,Ed,t)?n:void 0},Pd=(e,t)=>{if(i.isAwaitExpression(e))return e;if(i.isConditionalExpression(e))return e.getCondition()===t?void 0:e;const s=i.isBinaryExpression(e)?e.getOperatorToken().getKind():void 0;return s===d.QuestionQuestionToken||s===d.BarBarToken||s===d.AmpersandAmpersandToken?e:void 0},wd=(e,t)=>{if(i.isArrayLiteralExpression(e))return e;const n=i.isSpreadElement(e)||i.isSpreadAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isPropertyAssignment(e)&&me(e.getInitializer(),t)?e.getParent():void 0;return i.isArrayLiteralExpression(n)||i.isObjectLiteralExpression(n)?n:void 0},Is=e=>{const t=w(e),s=t.getParent();if(s===void 0)return;const n=i.isCallExpression(s)&&s.getArguments().includes(t)&&Ad(s);return Nd(s,t)??Pd(s,t)??wd(s,t)??(n?s:bd(t))},Id=5e4,In=()=>({inProgress:new Set,verdicts:new Map});class Cd{cuts=0;work=0;reset(){this.work=0}cut(){return this.cuts+=1,!0}spend(){return this.work+=1,this.work>Id&&this.cut()}memoized(t,s,n){const r=n.verdicts.get(t);if(r!==void 0)return r;if(n.inProgress.has(t))return this.cuts+=1,!1;if(this.spend())return!0;const o=this.cuts;n.inProgress.add(t);let a;try{a=s()}finally{n.inProgress.delete(t)}return this.cuts===o&&n.verdicts.set(t,a),a}}const Td=8,Od=8;class Rd{budget;scope;taint;verdicts=In();constructor(t,s,n){this.scope=t,this.budget=s,this.taint=n}isCompromised(t){return this.flowHasCompromisingUse(t)&&!ge(t.getType())}flowHasCompromisingUse(t){return this.budget.memoized(t.compilerNode,()=>{const s=this.budget.cuts,n=[],r=new Set,o=(c,l)=>{r.has(c.compilerNode)||(r.add(c.compilerNode),n.push({binding:c,hops:l}))};let a=!1;o(t,0);for(const c of n)if(a=(c.binding===t?void 0:this.verdicts.verdicts.get(c.binding.compilerNode))??this.visitBinding(c,t,o),a)break;if(!a&&this.budget.cuts===s)for(const c of r)this.verdicts.verdicts.set(c,!1);return a},this.verdicts)}visitBinding({binding:t,hops:s},n,r){const o=t.getNameNode();if(!i.isIdentifier(o)){for(const l of i.isParameterDeclaration(t)?wn(t):[])r(l,s);return!1}if(this.budget.spend())return!0;const a=(l,u)=>u&&s>=Td?this.budget.cut():(r(l,u?s+1:s),!1);return this.taint.referencesTo(t,o.getText()).some(l=>this.valueCompromises(w(l),!0,a,0))&&(t===n||!ge(t.getType()))}valueCompromises(t,s,n,r){let o=t;for(let m=Is(o);m!==void 0;m=Is(o)){if(i.isCallExpression(m)&&this.callbackCompromises(m,n))return!0;o=w(m)}const a=o.getParent(),c=o===t&&s,l=()=>!c&&ge(o.getType());if(Ue(o))return!c&&(!i.isBinaryExpression(a)||this.taint.isTaintedValue(a.getRight(),!1));const u=yd(o);if(u!==void 0)return u.some(m=>n(m,!0));const p=i.isPropertyAccessExpression(a)&&a.getExpression()===o?a.getParent():void 0;if(i.isCallExpression(p)&&p.getExpression()===a)return this.methodCallCompromises(p,n);const f=this.nestedReturningFunctionOf(o);return f!==void 0?this.resultCompromises(f,n,r)&&!l():this.positionCompromises(o,n)&&!l()}resultCompromises(t,s,n){const r=w(t).getParent();if(n>=Od)return this.budget.cut();if(i.isCallExpression(r))return r.getExpression()===w(t)?this.valueCompromises(r,!1,s,n+1):!Me(r,xt);const o=i.isFunctionDeclaration(t)?t:r,a=i.isFunctionDeclaration(o)||Z(o)?o.getNameNode():void 0;return o===void 0||!i.isIdentifier(a)?!0:this.taint.referencesTo(o,a.getText()).some(c=>{const l=w(c),u=l.getParent();return!i.isCallExpression(u)||u.getExpression()!==l||this.valueCompromises(u,!1,s,n+1)})}methodCallCompromises(t,s){return t.getArguments().filter(r=>Re(r)===void 0).some(r=>this.taint.isTaintedValue(r,!1))||this.callbackCompromises(t,s)}callbackCompromises(t,s){const n=Me(t,xt)?t.getArguments()[0]:void 0;if(n===void 0)return!1;const r=Et(n);return r!==void 0&&this.taint.isInImpl(r)?r.getParameters().some(o=>s(o,!1)):this.taint.isTaintedValue(n,!1)}positionCompromises(t,s){const n=t.getParent();if(i.isCallExpression(n)&&n.getArguments().includes(t))return this.argumentCompromises(n,t,s);const r=i.isSpreadElement(n)?n.getParent():void 0;if(n!==void 0&&i.isCallExpression(r))return!vt(n,this.scope.context)&&this.isOpaqueCallTainted(r.getExpression(),r.getArguments(),n);if(i.isNewExpression(n))return this.isOpaqueCallTainted(n.getExpression(),n.getArguments(),t);if(i.isTemplateSpan(n)){const o=n.getParent(),a=o.getParent(),c=o.getTemplateSpans().map(l=>l.getExpression());return i.isTaggedTemplateExpression(a)&&this.isOpaqueCallTainted(a.getTag(),c,t)}return!this.isReadPosition(t)}argumentCompromises(t,s,n){if(vt(s,this.scope.context))return!1;const r=Et(t.getExpression()),o=r===void 0?void 0:bn(r,t,s);return o?.kind==="unreached"?!1:o?.kind==="parameter"&&r!==void 0&&this.taint.isInImpl(r)?n(o.parameter,!1):this.isOpaqueCallTainted(t.getExpression(),t.getArguments(),s)}isReadPosition(t){const s=t.getParent();return s===void 0||i.isExpressionStatement(s)||i.isForStatement(s)||i.isElementAccessExpression(s)||Nn(t)||me(ft(t),this.scope.impl)}isOpaqueCallTainted(t,s,n){const r=!i.isIdentifier(E(n));return this.taint.isTaintedValue(t,!1)||s.some(o=>(o!==n||r)&&this.taint.isTaintedValue(o,!1))}nestedReturningFunctionOf(t){const s=ft(t);return me(s,this.scope.impl)?void 0:s}}const kd=new Set(["at","every","filter","finally","find","findIndex","findLast","findLastIndex","forEach","order","slice","some","sort","withIndex","withSearchIndex"]),Fd=e=>{const t=E(e);if(!i.isIdentifier(t))return i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t);const s=F(t),n=i.isVariableDeclaration(s)?E(s.getInitializer()):void 0;return s===void 0||i.isFunctionDeclaration(s)||i.isParameterDeclaration(s)||i.isArrowFunction(n)||i.isFunctionExpression(n)},Dd=new Set(["all","allSettled","any","race"]),Cs=e=>i.isParameterDeclaration(e)?e:i.isBindingElement(e)?e.getFirstAncestorByKind(d.Parameter):void 0,it=8;class Ld{budget=new Cd;referencesByDeclaration=new Map;referencesByName=new Map;scope;verdicts=In();walk;variableDepth=0;queryDepth=0;constructor(t){this.scope=t,this.walk=new Rd(t,this.budget,this);for(const s of t.impl.getDescendantsOfKind(d.Identifier)){const n=s.getText();this.referencesByName.set(n,[...this.referencesByName.get(n)??[],s])}}isTaintedValue(t,s){this.queryDepth===0&&this.budget.reset(),this.queryDepth+=1;try{return s&&this.isRootedInContext(t,it)?!1:(i.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(r=>Pr(r)&&this.isIdentifierTainted(r))}finally{this.queryDepth-=1}}isInImpl(t){const{impl:s}=this.scope;return t!==s&&s.getPos()<=t.getPos()&&t.getEnd()<=s.getEnd()}referencesTo(t,s){let n=this.referencesByDeclaration.get(s);if(n===void 0){n=new Map;for(const r of this.referencesByName.get(s)??[]){const o=F(r)?.compilerNode;o!==void 0&&n.set(o,[...n.get(o)??[],r])}this.referencesByDeclaration.set(s,n)}return(n.get(t.compilerNode)??[]).filter(r=>r.getParent()!==t)}flowsIntoTainted(t){if([t.getInitializer(),...t.getDescendantsOfKind(d.BindingElement).map(f=>f.getInitializer())].some(f=>f!==void 0&&this.isTaintedValue(f,!1)))return!0;const n=t.getParentOrThrow(),r=i.isFunctionLikeDeclaration(n)?n.getParameters().findIndex(f=>f.compilerNode===t.compilerNode):-1,o=w(n),a=o.getParent();if(r===-1)return!0;if(i.isCallExpression(a)){if(a.getExpression()===o)return this.isCallSiteTainted(a,r,t.isRestParameter());const f=E(a.getExpression());if(!i.isPropertyAccessExpression(f)||!xt.has(f.getName()))return!0;const m=a.getArguments().filter(A=>A!==o);return this.isTaintedValue(f.getExpression(),!0)||m.some(A=>this.isTaintedValue(A,!1))}const c=i.isVariableDeclaration(a)&&Z(a)?a:void 0,l=i.isFunctionDeclaration(n)?n:c,u=l?.getNameNode();if(l===void 0||!i.isIdentifier(u))return!0;const p=this.referencesTo(l,u.getText());return p.length===0||p.some(f=>{const m=w(f),A=m.getParent();return!i.isCallExpression(A)||A.getExpression()!==m||this.isCallSiteTainted(A,r,t.isRestParameter())})}isCallSiteTainted(t,s,n){const r=t.getArguments(),o=r.findIndex(c=>i.isSpreadElement(c)),a=c=>c===s||n&&c>s||o!==-1&&o<=s&&c>=o;return r.some((c,l)=>a(l)&&this.isTaintedValue(c,!1))}isContextRootedCombinator(t,s){const n=E(t.getExpression()),r=i.isPropertyAccessExpression(n)?n.getExpression():void 0,a=i.isPropertyAccessExpression(n)&&i.isIdentifier(r)&&r.getText()==="Promise"&&Le(r)&&Dd.has(n.getName())?E(t.getArguments()[0]):void 0;if(i.isArrayLiteralExpression(a)){const p=a.getElements();return p.length>0&&p.every(f=>!i.isSpreadElement(f)&&this.isRootedInContext(f,s))}const c=i.isCallExpression(a)?E(a.getExpression()):void 0,l=i.isCallExpression(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="map"?E(a.getArguments()[0]):void 0,u=l===void 0?void 0:Re(l);return u!==void 0&&u.length>0&&u.every(p=>p!==void 0&&this.isRootedInContext(p,s))}isIdentifierTainted(t){const s=t.getText();if(s==="arguments")return!0;const n=F(t),r=Cs(n);if(r!==void 0)return this.isSource(r);if(s==="args")return!0;if(n===void 0||!this.isInImpl(n))return!1;if(i.isFunctionDeclaration(n))return this.budget.memoized(n.compilerNode,()=>this.isTaintedValue(n,!1),this.verdicts);if(i.isBindingElement(n)&&this.walk.isCompromised(n))return!0;const o=i.isBindingElement(n)?n.getFirstAncestorByKind(d.VariableDeclaration):n;return i.isVariableDeclaration(o)&&this.isVariableTainted(o)}callChainVerdict(t,s){if(this.isContextRootedCombinator(t,s))return!0;const n=E(t.getExpression()),r=i.isPropertyAccessExpression(n)?n.getName():void 0;return r!==void 0&&nn.has(r)?!1:r!==void 0&&rn.has(r)?this.isCallbackResultServerScoped(t,s)?void 0:!1:t.getArguments().some(a=>Re(a)!==void 0)&&(r===void 0||!kd.has(r))?!1:void 0}isCallbackResultServerScoped(t,s){const n=(r,o=[])=>{const a=Nt(r),c=i.isIdentifier(a)?Cs(F(a)):void 0;return c!==void 0&&o.includes(c)?!0:this.isRootedInContext(r,s)||!this.isTaintedValue(r,!1)};return t.getArguments().every(r=>{const o=Re(r);if(o===void 0)return!Fd(r)&&n(r);const a=E(r),c=i.isArrowFunction(a)||i.isFunctionExpression(a)?a.getParameters():[];return o.every(l=>l===void 0||n(l,c))})}isRootedInContext(t,s){const n=kr(t,u=>this.callChainVerdict(u,s)),r=n.root;if(n.verdict!==void 0)return n.verdict;if(An(r,this.scope.context))return!0;const o=i.isIdentifier(r)?F(r):void 0,a=i.isBindingElement(o)?o.getFirstAncestorByKind(d.VariableDeclaration):o,c=Z(a)&&this.isInImpl(a)?a.getInitializer():void 0,l=i.isBindingElement(o)?o:a;return s>0&&c!==void 0&&(i.isBindingElement(l)||i.isVariableDeclaration(l))&&!this.walk.isCompromised(l)&&this.isRootedInContext(c,s-1)}isSource(t){const{impl:s,parameter:n}=this.scope;return t.compilerNode===n?.compilerNode?!0:t.getParent()!==s&&this.isInImpl(t)&&(this.budget.memoized(t.compilerNode,()=>this.flowsIntoTainted(t),this.verdicts)||this.walk.isCompromised(t))}isVariableTainted(t){return this.budget.memoized(t.compilerNode,()=>{const s=t.getParent().getParent();if(i.isCatchClause(t.getParent())||this.walk.isCompromised(t))return!0;if(i.isForOfStatement(s)||i.isForInStatement(s))return this.isTaintedValue(s.getExpression(),!0);const n=t.getInitializer(),r=At(t);if(n===void 0||r)return!0;if(this.isRootedInContext(n,it))return!1;if(this.variableDepth>=it)return this.budget.cut();this.variableDepth+=1;try{return this.isTaintedValue(n,!1)}finally{this.variableDepth-=1}},this.verdicts)}}const Ts=new WeakMap,Md=e=>{const t=Ts.get(e.impl.compilerNode);if(t!==void 0)return t;const s=new Ld(e);return Ts.set(e.impl.compilerNode,s),s},_d=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Kd=new Set(["insert","insertManyUnsafe","patch","replace"]),zd=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();return Kd.has(t)&&Qr(e.getExpression())?t:void 0},Bd=(e,t)=>{if(t!=="insertManyUnsafe")return i.isObjectLiteralExpression(e)?[e]:[];if(!i.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())i.isObjectLiteralExpression(n)&&s.push(n);return s},$d=(e,t)=>{const s=Fr(e);return s?.member===t?E(s.object):void 0},Os=(e,t)=>i.isIdentifier(e)&&F(e)?.compilerNode===t.compilerNode,Cn=(e,t,s,n=1)=>{const r=$d(e,s);if(r!==void 0)return Os(r,t);const o=i.isIdentifier(e)?F(e):void 0;if(i.isBindingElement(o)){const c=o.getParent(),l=c.getParent();return o.getDotDotDotToken()===void 0&&xe(o)===s&&i.isObjectBindingPattern(c)&&(l.compilerNode===t.compilerNode||Z(l)&&Os(E(l.getInitializer()),t))}const a=Z(o)?o.getInitializer():void 0;return n>0&&a!==void 0&&Cn(a,t,s,n-1)},St=e=>{const t=E(e)??e;return i.isConditionalExpression(t)?[...St(t.getWhenTrue()),...St(t.getWhenFalse())]:[t]},Ud=(e,t,s)=>{const n=[],r=s===void 0?void 0:Md(s);for(const o of e.getProperties()){let a,c;if(i.isPropertyAssignment(o)?(a=S(o),c=o.getInitializer()):i.isShorthandPropertyAssignment(o)&&(a=S(o),c=o.getNameNode()),a===void 0||c===void 0||!_d.has(a))continue;if(St(c).some(u=>r===void 0?V(u)&&!Xr(u):r.isTaintedValue(u,!0))){const u=t.ownerField===a&&s?.pristine===!0&&Cn(c,s.parameter,a);n.push({field:a,file:t.relativePath,line:t.call.getStartLineNumber(),method:t.method,scope:t.scope,...u&&{ownerScoped:!0}})}}return n},jd=(e,t,s)=>{const n=zd(e.getExpression()),r=n===void 0?void 0:e.getArguments()[1];if(n===void 0||r===void 0)return[];const o=Bd(r,n);if(o.length===0)return[];const a=v(e),c=vd(e),l={call:e,method:n,ownerField:c===void 0?void 0:s(c.mutatorName),relativePath:t,scope:a};return o.flatMap(u=>Ud(u,l,c))},Vd=(e,t,s=[],n=[])=>{const r=new Map(n.map(a=>[`${a.filePath}:${a.exportName}`,a.owner])),o=T(e,t,(a,c)=>jd(a,c,l=>r.get(`${c}:${l}`)));return bt(o,s)},qd=["providerSubscriptionId","state"],Wd=["providerEventId","processedAt"],Rs=(e,t)=>t.every(s=>s in e.shape),Hd=e=>{const t=e.find(n=>n.name==="payment_subscriptions"),s=e.find(n=>n.name==="payment_events");return t!==void 0&&s!==void 0&&Rs(t,qd)&&Rs(s,Wd)},Gd=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Yd=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Qd=e=>{const t=L(e,"webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?Yd(t.getInitializer()):void 0},Xd=(e,t)=>{const s=y(e.getExpression());if(s===void 0||!Gd.has(s))return;const[n]=e.getArguments(),r=n&&i.isObjectLiteralExpression(n)?Qd(n):void 0;return{callee:s,scope:v(e),file:t,line:e.getStartLineNumber(),...r===void 0?{}:{toleranceSeconds:r}}},Jd=(e,t)=>T(e,t,Xd),Zd=new Map([["defineQueue",0],["defineSubscription",1],["defineWorkflow",0]]),eu=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},tu=(e,t)=>{const s=e.getArguments()[t];if(!s||!i.isObjectLiteralExpression(s))return;const n=L(s,"handler");if(n===void 0||!i.isPropertyAssignment(n))return;const r=n.getInitializer();if(r&&(i.isArrowFunction(r)||i.isFunctionExpression(r)))return r},Tn=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},On=(e,t)=>e===t||e.startsWith(`${t}.`),Rn=e=>{const t=e.getDescendantsOfKind(d.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},ks=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)},kn=e=>{const t=e.getDescendantsOfKind(d.Identifier).filter(s=>ks(s));return i.isIdentifier(e)&&ks(e)&&t.push(e),t},su=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(d.BindingElement).map(s=>s.getName())},nu=e=>{const t=Tn(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(d.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const r=n.getInitializer(),o=i.isVariableDeclarationList(r)?r.getDeclarations()[0]?.getNameNode():void 0;o&&i.isIdentifier(o)&&s.push(`${o.getText()}.body`)}return s},ru=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:nu(e),r=new Set,o=a=>Rn(a).some(c=>n.some(l=>On(c.getText(),l)))?!0:kn(a).some(c=>r.has(c.getText()));for(const a of e.getDescendantsOfKind(d.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of su(a))r.add(l)}return{names:r,prefixes:n}},iu=(e,t)=>Rn(e).some(s=>t.prefixes.some(n=>On(s.getText(),n)))?!0:kn(e).some(s=>t.names.has(s.getText())),ou=e=>{const t=Dr(e);return t===void 0?void 0:{exportName:String(t.at(-1)),file:t.slice(0,-1).join("/")}},au=(e,t,s)=>{const n=Tn(e,0);if(n===void 0)return[];const r=ru(e,t,n),o=new Set([n,...r.prefixes.filter(c=>c.endsWith(".body")).map(c=>c.slice(0,-5))]),a=[];for(const c of e.getDescendantsOfKind(d.CallExpression)){const l=c.getExpression();if(!i.isPropertyAccessExpression(l)||!Gs.has(l.getName())||!o.has(l.getExpression().getText()))continue;const u=c.getArguments()[1];if(!u||!iu(u,r))continue;const p=ou(c.getArguments()[0]);p!==void 0&&a.push({dispatchKind:t,file:s,scope:v(c),line:c.getStartLineNumber(),targetExport:p.exportName,targetFile:p.file})}return a},cu=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=eu(n),o=r===void 0?void 0:Zd.get(r);if(o===void 0)continue;const a=tu(n,o);a!==void 0&&s.push(...au(a,r==="defineWorkflow"?"workflow":"queue",t))}return s},lu=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...cu(r,C(t,n)))}return s},Fs={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},Ds=new Set(["account","credential","member","passkey","session","user"]),du=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),uu=e=>{const s=du(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return Ds.has(s)||Ds.has(n)},fu=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},gu=(e,t)=>{const{objects:s,opaque:n}=It(e,t);return Ia(s).some(r=>fu(r))?!0:n?void 0:!1},pu=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!L(t,"captcha"),usesRateLimit:!!L(t,"rateLimit")}},mu=e=>{if(i.isCallExpression(e))return e;if(!i.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&i.isCallExpression(s)?s:void 0},ke={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},hu=e=>{const t=mu(e),s=t?y(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=pu(t);return{...ke,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in Fs?{...ke,[Fs[s]]:!0}:ke},vu=e=>{const t={...ke};let s=e;for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))break;const r=n.getName()==="use"?s.getArguments()[0]:void 0;if(r){const o=hu(r);t.usesCaptcha||=o.usesCaptcha,t.usesEmailGate||=o.usesEmailGate,t.usesMask||=o.usesMask,t.usesRateLimit||=o.usesRateLimit,t.usesRls||=o.usesRls}s=n.getExpression()}return t},Eu=new Set(["insert","insertMany","insertManyUnsafe","replace"]),xu=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Eu.has(t.getName()))return!1;const s=t.getExpression();if(!B(s))return!1;const r=e.getArguments()[0];return!r||!(i.isStringLiteral(r)||i.isNoSubstitutionTemplateLiteral(r))?!1:uu(r.getLiteralText())},Su=new Set(["create","publish","publishBatch","runAfter","runAt","send","sendBatch"]),Ls=new Set(["queues","scheduler","topics","workflows"]),yu=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Su.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&Ls.has(s.getName())&&Jr(s.getExpression()))return!0;s=s.getExpression()}const n=sn(s);return n?.length===1&&Ls.has(n[0]??"")},Au=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return B(s)},Fn=new Set(["generateObject","generateText","streamObject","streamText"]),bu=e=>{const t=y(e.getExpression());return t!==void 0&&Fn.has(t)},Nu=e=>{const t=y(e.getExpression());if(t===void 0||!Fn.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(n=>i.isSpreadAssignment(n))?!1:!L(s,"maxOutputTokens")},Pu=new Set(["log","span","trace"]),wu=new Set(["ai"]),Iu=new Set(["email","mail"]),Cu=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","topics","workflows"]),ot=(e,t)=>[...t].some(s=>je(e,s).length>0),Tu=new Set([d.ArrowFunction,d.FunctionDeclaration,d.FunctionExpression,d.GetAccessor,d.MethodDeclaration,d.SetAccessor]),Ou=new Set(["every","filter","flatMap","forEach","map","some"]),Ru=new Set(["all","allSettled","race"]),ku=e=>{const t=e.getParent();if(!t||!i.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName();if(Ou.has(n))return t;const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="Promise"&&Ru.has(n))return t},Fu=e=>{let t=e.getParent();for(;t;){if(i.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(Tu.has(t.getKind())){const s=ku(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},Du=e=>{let t=e;for(;;){const s=t.getParent();if(!i.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;if(s.getName()==="catch")return!0;if(s.getName()!=="then"&&s.getName()!=="finally")return!1;const n=s.getParent();if(!i.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},Lu=e=>{let t=e;for(;;){const s=t.getParent();if(i.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return i.isCallExpression(s)&&s.getExpression()===t?s:void 0}},Mu=e=>{let t=!1,s=!0;for(const n of[...Cu].flatMap(r=>je(e,r))){const r=Lu(n);r&&(t=!0,!Fu(r)&&!Du(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},_u=e=>e.getDescendantsOfKind(d.ThrowStatement).some(t=>{const s=t.getExpression();if(!i.isNewExpression(s))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="Error"}),Ms="lunora-advisor-exempt",Ku=/^[\s*/]+/u,zu=/[\w-]/u,Bu=e=>{const s=(e.getFirstAncestorByKind(d.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
|
|
7
|
-
`);for(const n of s.split(`
|
|
8
|
-
`)){const r=n.replace(Ku,"");if(!r.startsWith(Ms))continue;const o=r.slice(Ms.length);if(zu.test(o.charAt(0)))continue;const a=o.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":o.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},$u=e=>{const[t]=e.getArguments();if(t){if(i.isObjectLiteralExpression(t)){const s=L(t,"handler");return s?i.isPropertyAssignment(s)?s.getInitializer():i.isShorthandPropertyAssignment(s)?s.getNameNode():i.isMethodDeclaration(s)?s:void 0:void 0}return t}},Uu=(e,t)=>{const s=$u(t);if(!s)return;if(i.isArrowFunction(s)||i.isFunctionExpression(s)||i.isMethodDeclaration(s))return e;if(!i.isIdentifier(s))return;const n=s.getSourceFile(),r=s.getText(),o=n.getVariableDeclaration(r)?.getInitializer();return o&&(i.isArrowFunction(o)||i.isFunctionExpression(o))?o:n.getFunction(r)},ju=e=>{let t=!1,s=!1,n=!1,r=!1,o=!1;for(const l of e.getDescendantsOfKind(d.CallExpression))if(xu(l)&&(o=!0),yu(l)&&(t=!0),Au(l)&&(r=!0),bu(l)&&(s=!0),Nu(l)&&(n=!0),o&&t&&r&&n)break;const{handlesErrors:a,reachesOutbound:c}=Mu(e);return{callsMail:ot(e,Iu),emitsEvent:ot(e,Pu),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||ot(e,wu),throwsBareError:_u(e),unboundedAiGeneration:n,usesInsertManyUnsafe:r,writesUserTable:o}},Vu=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=W(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const r=n.receiver?vu(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},o=Uu(e,s);return{...o?ju(o):{},...Bu(e),...r,analyzableBody:o!==void 0,exportName:$(e)??e.getName(),file:t,hasEmailArg:gu(s,n.receiver),kind:n.kind,visibility:n.visibility}},qu=(e,t)=>{const s=[];for(const n of q(e)){const r=Vu(n,t);r&&s.push(r)}return s},Wu=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...qu(r,C(t,n)))}return s},Hu=new Set(["dbRateLimit","rateLimit"]),Gu=e=>i.isArrowFunction(e)?e.getBody():e,Yu=e=>{if(!i.isArrowFunction(e))return;const t=e.getParameters()[0]?.getNameNode();return t!==void 0&&i.isIdentifier(t)?t:void 0},Dn=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getExpression()===e&&t.getName()==="args"},Ln=(e,t)=>{const s=t.getSymbol();return s===void 0?[]:e.getDescendantsOfKind(d.Identifier).filter(n=>{if(n.getSymbol()!==s)return!1;const r=n.getParent();return!(i.isPropertyAccessExpression(r)&&r.getNameNode()===n)})},Qu=(e,t)=>V(e)||t!==void 0&&Ln(e,t).some(s=>Dn(s)),Xu=(e,t)=>t===void 0?ee(e):Ln(e,t).some(s=>!Dn(s)),Ju=(e,t)=>{const s=y(e.getExpression());if(s===void 0||!Hu.has(s))return;const n=I(Xs(e.getArguments()[2]),"key");if(!n)return;const r=Gu(n),o=Yu(n);if(!(!Qu(r,o)||Xu(r,o)))return{callee:s,scope:v(e),file:t,limitName:Qs(e),line:e.getStartLineNumber()}},Zu=(e,t)=>T(e,t,Ju),ef=new Set(["findFirst","findFirstOrThrow","findMany","findUnique","get"]),tf=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ef.has(t.getName()))return;const s=t.getExpression();if(B(s)){const n=e.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&B(s.getExpression()))return s.getName()},sf=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&B(s.getExpression())){const n=t.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},nf=e=>{let t=E(e)??e;for(;i.isAwaitExpression(t);)t=E(t.getExpression())??t.getExpression();return t},Mn=(e,t=!1)=>{const s=nf(e);if(i.isIdentifier(s)){if(t)return;const n=Q(s);return n===void 0?void 0:Mn(n,!0)}if(i.isCallExpression(s))return tf(s)??sf(s)},rf=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(d.ReturnStatement)){const r=n.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),o=n.getExpression();r===e&&o!==void 0&&s.push(o)}return s},of=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=W(s);if(n?.kind!=="query")return[];const r=hn(s);if(r===void 0)return[];const o=n.receiver!==void 0&&Br(n.receiver,"output"),a=n.receiver!==void 0&&Js(n.receiver,"use","mask"),c=new Set,l=[];for(const u of rf(r)){const p=Mn(u);p===void 0||c.has(p)||(c.add(p),l.push({exportName:$(e)??e.getName(),file:t,line:u.getStartLineNumber(),table:p,usesMask:a,usesOutput:o,visibility:n.visibility}))}return l},af=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=C(t,n);for(const a of q(r))s.push(...of(a,o))}return s},cf=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(s));return t},lf=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?W(s):void 0;if(!n)return[];const r=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=cn(o);if(a===void 0)continue;const c=cf(I(a.options,"with"));c.length!==0&&r.push({exportName:$(e)??e.getName(),file:t,line:o.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return r},df=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=C(t,n);for(const a of q(r))s.push(...lf(a,o))}return s},_e=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===d.PlusToken){const t=_e(e.getLeft()),s=_e(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},uf=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===d.PlusToken;)t=s,s=t.getParent();return t!==e&&_e(t)!==void 0},ff=e=>{const t=e.getParent();if(t!==void 0){if(i.isVariableDeclaration(t)||i.isPropertyAssignment(t)||i.isPropertySignature(t))return S(t);if(i.isBinaryExpression(t)&&t.getOperatorToken().getKind()===d.EqualsToken)return t.getLeft().getText()}},gf=(e,t,s)=>Ii(e)?!Lr(s)&&Ci(ff(t)):!0,pf=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(d.BinaryExpression),...e.getDescendantsOfKind(d.StringLiteral),...e.getDescendantsOfKind(d.NoSubstitutionTemplateLiteral)],r=new Set;for(const o of n){if(uf(o))continue;const a=_e(o);if(a===void 0)continue;const c=Pi(a);if(c===void 0||!gf(c,o,t))continue;const l=o.getStartLineNumber(),u=`${String(l)}:${c}`;r.has(u)||(r.add(u),s.push({file:t,kind:c,line:l,preview:wi(a)}))}return s},mf=(e,t)=>{const s=[];for(const n of x(t,{includeSkipped:!0})){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...pf(r,C(t,n)))}return s},hf=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?W(s):void 0;if(!n)return[];const r=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=cn(o);if(a===void 0)continue;const c=I(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),u=!l&&V(c);!l&&!u||r.push({exportName:$(e)??e.getName(),file:t,fromArgs:u,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:n.visibility})}return r},vf=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=C(t,n);for(const a of q(r))s.push(...hf(a,o))}return s},Ef=new Set(["query","unsafe"]),xf=e=>!i.isPropertyAccessExpression(e)||!Ef.has(e.getName())?!1:j(e.getExpression(),["sql"]),Sf=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),yf=(e,t)=>{if(!xf(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Sf(s)))return{file:t,line:s.getStartLineNumber(),scope:v(e)}},Af=(e,t)=>T(e,t,yf),bf=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],Nf=e=>{for(const[t,s]of bf)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},Pf=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of r.getImportDeclarations()){const a=o.getModuleSpecifierValue(),c=Nf(a);c!==void 0&&s.push({file:C(t,n),line:o.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},wf=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),If=(e,t,s=[])=>{const n=qe(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:wf,requireUnmodifiedReach:!0});return bt(n,s)},Cf=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Tf=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Of=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!i.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const r of e.getProperties()){if(i.isSpreadAssignment(r)){n=!0;continue}if(i.isPropertyAssignment(r)){const o=S(r);t.push(o),o==="expiresInSeconds"&&(s=Tf(r.getInitializer()));continue}(i.isShorthandPropertyAssignment(r)||i.isMethodDeclaration(r))&&t.push(S(r))}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},Rf=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=Cf.get(t);return s===void 0?void 0:tn(e.getExpression(),r=>r==="ctx.storage"||r.startsWith("ctx.storage."))?{method:t,optionsIndex:s}:void 0},kf=(e,t)=>{const s=Rf(e.getExpression());if(s!==void 0)return{scope:v(e),file:t,line:e.getStartLineNumber(),method:s.method,...Of(e.getArguments()[s.optionsIndex])}},Ff=(e,t)=>T(e,t,kf),Df=(e,t)=>{const s=Vr(t.target);return{...s===void 0?{}:{platform:s},analytics:e.analytics||t.dependencies.has("@lunora/bindings"),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"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:t.vectorStoreSupported&&t.vectorIndexCount>0,workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}},Lf=new Set(["delete","hardDelete","patch","replace","restore"]),Mf=new Set(["insertMany","insertManyUnsafe","patchWhere"]),_f=new Set(["delete","deleteMany","hardDelete","insert","insertMany","patch","patchMany","replace","restore","upsert","upsertMany"]),_s=(e,t)=>{const s=e.getNonNullableType().getProperty("__table")?.getTypeAtLocation(t);if(s===void 0)return[];const n=s.isUnion()?s.getUnionTypes():[s],r=n.map(o=>o.getLiteralValue()).filter(o=>typeof o=="string");return r.length===n.length?r:[]},Kf=(e,t)=>{const s=e.getType();if(t==="deleteMany"||t==="patchMany"){const n=s.getArrayElementType();if(n===void 0)return[];const r=t==="patchMany"?n.getProperty("id")?.getTypeAtLocation(e):n;return r===void 0?[]:_s(r,e)}return _s(s,e)},Ks="",zf=(e,t)=>{if(Mf.has(e))return{method:e,tables:[t!==void 0&&i.isStringLiteral(t)?t.getLiteralText():Ks]};if(Lf.has(e)||e==="deleteMany"||e==="patchMany"){const s=t===void 0?[]:Kf(t,e);return{method:e,tables:s.length===0?[Ks]:s}}},Bf=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression();if(B(n))return zf(s,e.getArguments()[0]);if(_f.has(s)&&i.isPropertyAccessExpression(n)&&B(n.getExpression()))return{method:s,tables:[n.getName()]}},$f=(e,t)=>T(e,t,(s,n)=>{const r=Bf(s);if(r===void 0)return;const o=v(s),a=s.getStartLineNumber();return r.tables.map(c=>({file:n,line:a,method:r.method,scope:o,table:c}))}),Uf=(e,t,s)=>({cacheKey:`procedure_arguments_unreadable:${e}:${t}`,categories:["SCHEMA"],description:"Codegen reads an argument record statically. One built at runtime — a factory call, or a property off a value it cannot follow — has no literal to read, so the generated `FunctionReference` carries only the arguments it could see while the runtime validator still enforces all of them.",detail:`\`${t}\` in \`${e}\` (line ${s.toString()}) declares arguments codegen could not read, so its generated type is missing some of them.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:s},name:"procedure_arguments_unreadable",remediation:`Declare the arguments as an object literal, or as a \`const\` object literal the chain names — \`const ${t}Args = { … };\` then \`.input(${t}Args)\`. Both resolve; a record returned by a call does not.`,title:"Procedure arguments are missing from the generated type"}),jf=(e,t)=>{if(t===void 0){const s=e.getArguments()[0];if(s===void 0||!i.isObjectLiteralExpression(s)||L(s,"args")===void 0)return!1}return It(e,t).opaque},Vf=(e,t)=>{const s=[],n=(r,o)=>{const a=r.getInitializer();if(a===void 0||!i.isCallExpression(a))return;const c=W(a);c!==void 0&&jf(a,c.receiver)&&s.push(Uf(t,o,a.getStartLineNumber()))};for(const r of e.getVariableStatements().filter(o=>o.isExported()))for(const o of r.getDeclarations())n(o,o.getName());return s},qf=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n);r!==void 0&&s.push(...Vf(r,C(t,n)))}return s.toSorted((n,r)=>n.cacheKey.localeCompare(r.cacheKey))},Wf=new Map([["AgentDefinition",{call:"defineAgent({ … })",file:"agents"}],["ContainerDefinition",{call:"defineContainer({ … })",file:"containers"}],["QueueDefinition",{call:"defineQueue({ … })",file:"queues",note:"A dropped queue has no caller to fail — its consumer is simply never wired."}],["RegisteredAction",{call:"action.input({ … }).action(handler)"}],["RegisteredLifecycleHook",{call:"onConnect(handler)",note:"Substitute the hook you called: `onConnect`, `onDisconnect` and `onShardInit` share one type, so codegen cannot tell which you wrote. A dropped hook has no caller to fail — it silently never fires."}],["RegisteredMigration",{call:"defineMigration({ … })",note:"A dropped migration never runs, so `lunora migrate up` reports nothing to do."}],["RegisteredMutation",{call:"mutation.input({ … }).mutation(handler)"}],["RegisteredMutator",{call:"defineMutator({ … })",file:"mutators"}],["RegisteredQuery",{call:"query.input({ … }).query(handler)"}],["RegisteredReactor",{call:"onQueryChange(select, handler)",note:"A dropped reactor has no caller to fail — it silently never runs."}],["RegisteredShape",{call:"defineShape({ … })",file:"shapes"}],["RegisteredStream",{call:"query.input({ … }).stream(handler)"}],["RegisteredWhisperAuthorizer",{call:"onWhisper(handler)",note:"A dropped authorizer has no caller to fail — the whisper topics it was meant to gate silently stay open to every socket on the shard."}],["SubscriptionDefinition",{call:"defineSubscription(topic, { … })",file:"queues",note:"A dropped subscription is never published to — its topic's messages simply never reach it."}],["WorkflowDefinition",{call:"defineWorkflow({ … })",file:"workflows"}]]),Ke=({byName:e,byPath:t},s,n)=>t.has(`${s}:${n}`)||e.has(n),_n=e=>!e.isAny(),Kn=e=>{const t=e.getType();if(!_n(t))return;const s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName(),n=s===void 0?void 0:Wf.get(s);return n===void 0||s===void 0?void 0:{...n,typeName:s}},Hf=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},zn={cause:"codegen recognises a registration only when the initializer is the registering call itself, and this one comes from a factory or an alias",remediation:"A factory that returns a registration cannot be read statically — inline it, or export what the factory builds."},Gf=e=>({cause:`codegen reads this kind of registration only from \`lunora/${e}.ts\`, and this is a different module`,remediation:`Move it into \`lunora/${e}.ts\` — the declaration itself is fine.`}),Yf={cause:"it is exported only under a string name that is not an identifier, which the generated `api.ts` and dispatch table cannot address as `<module>.<name>`",remediation:"Export it under an identifier name as well (or instead)."},Qf=new Set(["AgentDefinition","ContainerDefinition","QueueDefinition","RegisteredShape","SubscriptionDefinition","WorkflowDefinition"]),Xf={cause:"it is exported only as `default` or under a reserved word, and this kind's name becomes an import binding and a generated class / binding name, where that is a syntax error",remediation:"Export it under a plain identifier: `export const <name> = …` (an extra `export default <name>` is fine)."},Jf=(e,t,s)=>{if(!t.some(r=>wr(r)))return Yf;const n=e.getVariableStatement()?.hasExportKeyword()===!0;return Qf.has(s.typeName)&&!n&&!t.some(r=>Oi(r))?Xf:zn},Bn=(e,t,s,n,r)=>{const{call:o,file:a,note:c,typeName:l}=s,u=a!==void 0&&e!==a?a:void 0,p=u===void 0?r:Gf(u),f=c===void 0?p.remediation:`${c} ${p.remediation}`;return{cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when its initializer is literally the registering call and the module exports it under an identifier name — by the `export` keyword, a local `export { … }`, or `export default`. Written any other way it exists at runtime but never reaches the generated output — `_generated/api.ts` for a procedure, the lifecycle manifest for a hook or reactor — so a caller cannot address it and a hook never fires.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${l}\` but was not registered — ${p.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:l},name:"procedure_not_registered",remediation:u===void 0?`Assign the registration directly: \`export const ${t} = ${o};\`. ${f}`:f,title:"Procedure exists at runtime but is missing from the generated API"}},Zf=(e,t,s)=>{const n=[];for(const r of q(e)){const o=i.isIdentifier(r.getNameNode())?dt(r):[r.getName()],c=o.some(u=>Ke(s,t,u))||!Hf(r)?void 0:Kn(r),[l=r.getName()]=o;c!==void 0&&n.push(Bn(t,l,c,r.getStartLineNumber(),Jf(r,o,c)))}return n},eg=(e,t,s)=>{if(Ke(s,t,"default"))return[];const n=[];for(const r of e.getExportAssignments().filter(o=>!o.isExportEquals()&&!i.isIdentifier(o.getExpression()))){const o=Kn(r.getExpression());o!==void 0&&n.push(Bn(t,"default",o,r.getStartLineNumber(),zn))}return n},tg=(e,t,s)=>[...Zf(e,t,s),...eg(e,t,s)],sg=(e,t,s)=>e.getVariableStatements().flatMap(n=>n.getDeclarations()).filter(n=>i.isIdentifier(n.getNameNode())).filter(n=>dt(n).some(r=>Ke(s,t,r))).filter(n=>{const r=n.getInitializer();return r!==void 0&&i.isCallExpression(r)&&i.isPropertyAccessExpression(r.getExpression())}).map(n=>{const r=dt(n).find(o=>Ke(s,t,o))??n.getName();return{declaration:n,exportName:r,relativePath:t}}),ng=({exportName:e,relativePath:t})=>({cacheKey:"procedure_type_check_unavailable",categories:["SCHEMA"],description:"Codegen cross-checks every export in `lunora/` against its TYPE to catch a procedure the syntactic scan dropped — a factory-assigned export, an alias, a separate `export { … }`. That check needs the type checker to resolve `@lunora/server`; when it cannot, the check reports nothing regardless of what the code does.",detail:`Type resolution for \`lunora/\` is unavailable — the registered procedure \`${e}\` in \`${t}\` types as \`any\`, as does every other one — so codegen cannot tell you when an export is dropped from \`_generated/api.ts\`. A dropped procedure will surface as \`Property '<name>' does not exist\` at its call site instead.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e,filePath:t},name:"procedure_type_check_unavailable",remediation:`Check what codegen sees: \`${e}\` should have a procedure type, not \`any\`. It needs a \`tsconfig.json\` at or above \`lunora/\` — the one codegen finds walking up from there, which is not necessarily the one your editor uses — resolving \`lunorash\` / \`@lunora/server\` to declarations that exist on disk (a workspace dependency has to be built first).`,title:"Codegen cannot type-check `lunora/`, so dropped procedures go unreported"}),rg=(e,t,s)=>{const n=[],r=[];for(const a of x(t)){const c=e.getSourceFile(a);if(c===void 0)continue;const l=C(t,a);n.push(...tg(c,l,s)),r.push(...sg(c,l,s))}const[o]=r;return o!==void 0&&r.every(({declaration:a})=>!_n(a.getType()))&&n.push(ng(o)),n.toSorted((a,c)=>a.cacheKey.localeCompare(c.cacheKey))},ig=new Set(["when","where"]),at=new Set(["definePolicy","defineShape"]),og=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const n=t.getName();return at.has(n)?n:void 0}if(!i.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(n)){const r=n.getNameNode().getText();return at.has(r)?r:void 0}const s=t.getText();return at.has(s)?s:void 0},ag=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,$n=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===d.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(ag(e))return"empty-object";if(i.isParenthesizedExpression(e))return $n(e.getExpression())}},Tt=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),cg=e=>e.getDescendantsOfKind(d.ReturnStatement).filter(t=>Tt(t)===e),Un=e=>e.getDescendantsOfKind(d.ConditionalExpression).filter(t=>Tt(t)===e),lg=e=>{const t=cg(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(d.IfStatement)!==void 0)||Un(e).length>0},dg=e=>e.getDescendantsOfKind(d.IfStatement).filter(t=>Tt(t)===e),yt=e=>e.getKind()===d.NullKeyword||e.getKind()===d.FalseKeyword||i.isIdentifier(e)&&e.getText()==="undefined"?!0:i.isNumericLiteral(e)?e.getLiteralValue()===0:i.isStringLiteral(e)&&e.getLiteralValue()==="",ug=(e,t)=>yt(e)||yt(t),fg=new Map([[d.EqualsEqualsEqualsToken,"positive"],[d.EqualsEqualsToken,"positive"],[d.ExclamationEqualsEqualsToken,"negative"],[d.ExclamationEqualsToken,"negative"]]),zs=e=>!yt(e)&&(i.isLiteralExpression(e)||e.getKind()===d.TrueKeyword),gg=(e,t,s)=>{const n=fg.get(e);if(n!==void 0)return ug(t,s)?n==="positive"?"negative":"positive":zs(t)||zs(s)?void 0:n},pe=e=>{if(i.isParenthesizedExpression(e))return pe(e.getExpression());if(i.isPrefixUnaryExpression(e)&&e.getOperatorToken()===d.ExclamationToken)return"negative";if(i.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=gg(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===d.AmpersandAmpersandToken||t===d.BarBarToken){const n=pe(e.getLeft()),r=pe(e.getRight());return n===r?n:"indeterminate"}}return i.isIdentifier(e)||i.isPropertyAccessExpression(e)||i.isElementAccessExpression(e)||i.isCallExpression(e)?"positive":"indeterminate"},Bs=e=>{if(e!==void 0){if(i.isReturnStatement(e))return e;if(i.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&i.isReturnStatement(t)?t:void 0}}},pg=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(d.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},mg=e=>i.isReturnStatement(e)?e.getExpression()??e:e,hg=e=>{const t=[];for(const s of Un(e)){const n=pe(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of dg(e)){const n=pe(s.getExpression());if(n==="indeterminate")continue;const r=n==="negative"?Bs(s.getThenStatement()):Bs(s.getElseStatement())??pg(s);r!==void 0&&t.push(mg(r))}return t},vg=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},Eg=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!i.isObjectLiteralExpression(n))return[];const r=[];for(const o of n.getProperties()){if(!i.isPropertyAssignment(o)||!ig.has(S(o)))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&lg(a))for(const c of hg(a)){const l=$n(c);l!==void 0&&r.push({exportName:vg(e),file:s,form:l,key:S(o),line:c.getStartLineNumber(),owner:t})}}return r},xg=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=og(n);r!==void 0&&s.push(...Eg(n,r,t))}return s},Sg=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...xg(r,C(t,n)))}return s},yg=new Set(["query","upsert","upsertNow"]),Ag=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(yg.has(t))return j(e.getExpression(),["vectors"])?t:void 0},bg=(e,t)=>{const s=Ag(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const r=I(n,"namespace");if(!(!r||!V(r)||ee(r)))return{scope:v(e),file:t,line:e.getStartLineNumber(),method:s}},Ng=(e,t)=>T(e,t,bg),Pg=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"},wg=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Ig=(e,t)=>T(e,t,(s,n)=>Pg(s)?{file:n,line:s.getStartLineNumber(),scope:v(s),workflow:wg(s)}:void 0),Cg=".lunora-schema.json",ze=(e,t)=>{R(e)&&tr(e,"utf8")===t||sr(e,t,"utf8")},Tg=(e,t)=>{if(t===""){lt(e,{force:!0});return}ze(e,t)},Og=(e,t)=>{const s=h(e,"services");if(Object.keys(t).length===0){lt(s,{force:!0,recursive:!0});return}if(R(s))for(const n of er(s,{recursive:!0,withFileTypes:!0})){const r=h(n.parentPath,n.name);n.isFile()&&t[nr(e,r)]===void 0&<(r)}for(const[n,r]of Object.entries(t))Us(fe(h(e,n)),{recursive:!0}),ze(h(e,n),r)},Rg=e=>{try{const t=ir(h(e,"package.json"));return typeof t.version=="string"&&t.version!==""?t.version:void 0}catch{return}},kg=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Fg=e=>{let t=R(e)?e:fe(e);for(;t&&t!==fe(t);){const s=h(t,"tsconfig.json");if(R(s))return s;t=fe(t)}},$s=e=>e.replaceAll("\\","/"),Dg=(e,t,s)=>{if(s&&e.length>0){const o=e.map(a=>`"${a.exportName}"`).join(", ");throw new Y("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${o}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const o of t.columns){const a=n.get(o.table)??[];a.push(o.column),n.set(o.table,a)}const r=t.columns.length>0;for(const o of e){if(o.table===void 0){if(r)throw new Y("MASK_UNSUPPORTED",`defineShape "${o.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${o.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(o.table);if(a===void 0)continue;const c=a.map(l=>`"${l}"`).join(", ");throw new Y("MASK_UNSUPPORTED",`defineShape "${o.exportName}" replicates table "${o.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},ae=(e,t,s)=>{const n=e.getSourceFile(t);if(n===void 0){e.createSourceFile(t,s,{overwrite:!0});return}n.getFullText()!==s&&n.replaceWithText(s)},ct=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,Lg=8,Mg=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,internalPath:r,lunoraDirectory:o,migrations:a,project:c,shapes:l,usesSandbox:u,useUmbrella:p,workflows:f}=e,m=()=>oi(()=>{const b=ai(c,o),z=hi(c,o);return{functions:b,httpRoutes:ci(c,o),mutators:z}});let{erased:A,value:{functions:M,httpRoutes:H,mutators:D}}=m();is([...M,...D].map(b=>b.filePath)),is(H.filter(b=>b.stream).map(b=>b.filePath),"http-stream");for(let b=1;;b+=1){const z=Vi({agents:t,functions:M,httpRoutes:H,mutators:D,useUmbrella:p,workflows:f}),_=Zi({agents:t,functions:M,migrations:a,mutators:D,shapes:l,useUmbrella:p,usesSandbox:u}),N=qi({functions:M,useUmbrella:p});if(b>=Lg||ct(c,s,z)&&ct(c,r,N)&&ct(c,n,_))return{apiContent:z,erased:A,functions:M,functionsContent:_,httpRoutes:H,internalContent:N,mutators:D};ae(c,s,z),ae(c,r,N),ae(c,n,_),{erased:A,value:{functions:M,httpRoutes:H,mutators:D}}=m()}},_g=e=>{const t=Fg(e);return t?new ts({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new ts({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Jp=(e,t)=>{const s=x(t),n=h(t,"schema.ts");R(n)&&s.push(n);for(const c of s){const l=e.getSourceFile(c);l===void 0?e.addSourceFileAtPath(c):l.refreshFromFileSystemSync()}const r=new Set(s.map(c=>$s(c))),o=$s(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!r.has(l)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const l=c.getFilePath();if(!(l===o||l.startsWith(a)||l.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},Zp=e=>{const t=kg(),s=t?et.now():0,n=h(e.projectRoot,e.lunoraDirectory??"lunora"),r=h(n,"schema.ts");if(!R(r))throw new Y("INTERNAL",`schema.ts not found at ${r}`);const o=e.project??_g(n);Zr(Kc);const a=Ni(o,r,e.projectRoot),{agents:c,capabilities:l,containers:u,crons:p,dataModelContent:f,dependencies:m,entryCronTriggers:A,env:M,featureUsage:H,hasFlags:D,hasNotify:b,identity:z,platformGate:_,queues:N,serverContent:te,services:se,storageRulesMetadata:ce,topics:ne,usesSandbox:Se,useUmbrella:U,workflows:K}=Ho({lunoraDirectory:n,project:o,projectRoot:e.projectRoot,schema:a,target:e.target});yl(a,a.jurisdiction===void 0?void 0:xl(o,n));const O=h(n,"_generated"),k=h(O,"dataModel.ts"),jn=h(O,"server.ts"),Vn=h(O,"api.ts"),qn=h(O,"internal.ts"),Wn=h(O,"functions.ts");ae(o,k,f),ae(o,jn,te);const We=Object.fromEntries(se.filter(g=>g.rpcEntrypoint!==void 0).flatMap(g=>Object.entries(Hr(g,O))));for(const[g,P]of Object.entries(We))ae(o,h(O,g),P);const ye=fi(o,n),re=Ti(o,n),{apiContent:Ot,erased:Hn,functions:G,functionsContent:Rt,httpRoutes:He,internalContent:kt,mutators:Ae}=Mg({agents:c,apiPath:Vn,generatedFunctionsPath:Wn,internalPath:qn,lunoraDirectory:n,migrations:ye,project:o,shapes:re,useUmbrella:U,usesSandbox:Se,workflows:K}),Ft=ur(o,n),Ge=fr(Ft,a,[...G,...He].map(g=>g.filePath)),be=Ft.length>0,X=e.lint===!1&&!be?void 0:{inserts:di(o,n),queries:Si(o,n),tableWrites:$f(o,n),workflowCalls:Ig(o,n)},Ne=e.lint===!1||X===void 0?void 0:ar({adminRoutes:ta(o,n),aiRawRuns:da(o,n),aiToolSideEffects:ya(o,n),argumentDerivedFetches:Na(o,n),argumentValidators:Da(o,n),authApiCalls:ei(o,n),authConfigs:Va(o,n),browserUrlAccesses:Ga(o,n),configCalls:ac(o,n),containerKeyAccesses:lc(o,n),containerOverrides:mc(o,n),containers:u,exportSinks:xc(o,n),staleMigrationImports:Pf(o,n),failOpenGuards:Nc(o,n),flagReads:Fc(o,n),flagSecurityDefaults:_c(o,n),geoIndexUsages:$c(o,n),httpActionGuards:Zc(o,n),httpHeaderWrites:ll(o,n),hyperdriveCalls:li(o,n),identityClaimReads:ml(o,n),imageDeliveryUrlAccesses:vl(o,n),inserts:X.inserts,kvKeyAccesses:bl(o,n,G),mailRecipientAccesses:Cl(o,n),maskProcedures:ui(o,n),maskStrategies:Ml(o,n),mutatorWrites:Ul(o,n),nondeterministicCalls:vi(o,n),normalizeIdAuthorizations:nd(o,n),notifyCalls:xi(o,n),notifyConfig:Ei(o,n),mutators:Ae,ownerFieldWrites:Vd(o,n,G,Ae),unrestrictedWhereBranches:Sg(o,n),paymentWebhooks:Jd(o,n),privilegedDispatches:lu(o,n),procedureProtections:Wu(o,n),queries:X.queries,queues:N,r2sqlCalls:yi(o,n),ratelimitKeySelectors:Zu(o,n),rawRowReturns:af(o,n),relationLoads:df(o,n),rlsProcedures:Ai(o,n),schema:a,secretLiterals:mf(o,n),modules:Ge,shapes:re,softDeleteReads:vf(o,n),sqlInterpolations:Af(o,n),storageKeyAccesses:If(o,n,G),storageUploads:Ff(o,n),tableWrites:X.tableWrites,vectorNamespaceAccesses:Ng(o,n),workflowCalls:X.workflowCalls,workflows:K,wranglerVariables:e.wranglerVariables}),Dt=Ne===void 0?[]:to(e.projectRoot,[...rr(Ne,{source:"static"}),...rg(o,n,{byName:new Set([...K,...N,...c,...u].map(g=>g.exportName)),byPath:new Set([...G,...Ae,...re,...ye].map(g=>`${g.filePath}:${g.exportName}`))}),...qf(o,n),...ii(Hn,n),..._i(N,e.wranglerQueueProducers)]),Gn=bi(o,n),Lt=Fl(o,n);Dg(re,Lt,Rl(o,n));const Yn=D?Cc(o,n):[],Ye=_.signals.vectorStore!==!1,le=Df(H,{containerCount:u.length,cronCount:p.length,dependencies:m,hasPaymentTables:Hd(a.tables),queueCount:N.length,storageColumnCount:Object.keys(en(a)).length,storageRuleCount:ce.rules.length,vectorIndexCount:a.vectorIndexes.length,target:Zs(e.projectRoot,e.target),vectorStoreSupported:Ye,workflowCount:K.length}),Mt=t?et.now():0,Qe=Mi(a,ye.map(g=>g.id)),_t=qr({advisories:Dt.filter(g=>g.name!=="procedure_type_check_unavailable"),advisorProcedures:Ne?.procedureProtections??[],agents:c,capabilities:l,containers:u,env:M,flagKeys:Yn,hasFlags:D,hasNotify:b,hasVectors:Ye,maskMetadata:Lt,mutators:Ae,queues:N,rlsMetadata:Gn,schema:a,schemaSnapshot:Qe,shapes:re,services:se,storageRules:ce,studioFeatures:le,topics:ne,useUmbrella:U,workflows:K}),Kt=Ui(re,m.has("@lunora/db"),U),zt=Ki(u,a.jurisdiction),Bt=zi(K),$t=Bi(c),Ut=$i(N,e.wranglerQueueProducers),jt=Wi(p),Qn=Hi(le.scheduler),Xn=Gi(a.tables,U),Jn=dr(e.projectRoot)?Yi(U):"",Vt=Qi(a.vectorIndexes),Pe=Ji(a,U),qt=ji(m.has("@lunora/seed")),we=e.apiSpec??"openapi",Xe=we==="openapi"||we==="both",Je=we==="openrpc"||we==="both",Wt=Ri({capabilities:l,emailAgents:c.filter(g=>g.onEmail===!0).map(g=>({className:g.className,exportName:g.exportName})),hasAccess:m.has("@lunora/cloudflare-access"),hasAuth:m.has("@lunora/auth"),hasFramework:m.has("@lunora/astro")||m.has("@lunora/svelte")||m.has("@lunora/vue")||R(h(e.projectRoot,"src","worker.ts")),hasGlobal:a.tables.some(g=>Vs(g)),hasHyperdriveGlobal:a.tables.some(g=>qs(g)),hasKvIntrospector:le.kv,hasNotify:b,hasQueue:N.some(g=>g.mode==="push"),hasScheduler:le.scheduler,hasSourcedTables:a.tables.some(g=>g.externalSource!==void 0),hasStorage:le.storage,hasVectors:Ye,hasWorkflow:K.length>0,identity:z,jurisdiction:a.jurisdiction,jurisdictionPinsAuth:a.jurisdictionPinsAuth===!0,tables:a.tables.map(g=>({name:g.name,shardMode:g.shardMode})),useUmbrella:U,vectorIndexCount:a.vectorIndexes.length,voiceAgents:c.filter(g=>g.voice===!0&&g.voiceBindingName!==void 0).map(g=>({bindingName:g.voiceBindingName,exportName:g.exportName})),wantsArchitecture:be,wantsOpenApi:Xe,wantsOpenRpc:Je}),Ht=Rg(e.projectRoot),Gt=be?Ge:[],Yt=ki({functions:G,httpRoutes:He,modules:Gt,version:Ht}),Qt=Di({functions:G,modules:Gt,version:Ht}),Xt=`${JSON.stringify(Yt,void 0,2)}
|
|
9
|
-
`,Jt=`${JSON.stringify(Qt,void 0,2)}
|
|
10
|
-
`,de=be&&X!==void 0?vo({...X,callEdges:Za(o,n),crons:p,functions:G,httpRoutes:He,modules:Ge,queues:N,schema:a,services:se,topics:ne,workflows:K}):void 0,Zt=Fi(Yt),es=Li(Qt),Ze=h(n,Cg),Zn=R(Ze),Ie=[];if(!e.dryRun){R(O)||Us(O,{recursive:!0});const g=(J,ie)=>{ze(h(O,J),ie),Ie.push(J)},P=(J,ie)=>{Tg(h(O,J),ie),ie!==""&&Ie.push(J)};g("app.ts",Wt),g("dataModel.ts",f),g("api.ts",Ot),g("internal.ts",kt),g("server.ts",te),g("functions.ts",Rt),g("shard.ts",_t),g("crons.ts",jt),g("vectors.ts",Vt),g("drizzle.global.ts",Pe.global),g("drizzle.shard.ts",Pe.shard),P("containers.ts",zt),P("workflows.ts",Bt),P("agents.ts",$t),P("queues.ts",Ut),P("scheduler.ts",Qn),P("shardRegistry.ts",Xn),P("durableObjects.ts",Jn),P("seed.ts",qt),P("collections.ts",Kt),Og(O,We),Ie.push(...Object.keys(We)),P("openapi.json",Xe?Xt:""),P("openapi.ts",Xe?Zt:""),P("openrpc.json",Je?Jt:""),P("openrpc.ts",Je?es:""),P("architecture.json",de===void 0?"":`${JSON.stringify(de,void 0,2)}
|
|
11
|
-
`),P("architecture.ts",de===void 0?"":Eo(de)),(!Zn||e.updateSchemaBaseline===!0)&&ze(Ze,or(Qe))}if(t){const g=et.now(),P=Math.round(g-s),J=Math.round(Mt-s),ie=Math.round(g-Mt);console.error(`@lunora/codegen: codegen took ${P.toString()}ms (discovery ${J.toString()}ms, emit ${ie.toString()}ms)`)}return{advisories:Dt,advisorContext:Ne,agents:c,architecture:de,containers:u,cronTriggers:[...new Set([...Xi(p),...A])],generated:{agents:$t,api:Ot,app:Wt,collections:Kt,containers:zt,crons:jt,dataModel:f,drizzleGlobal:Pe.global,drizzleShard:Pe.shard,functions:Rt,internal:kt,openApi:Xt,openApiModule:Zt,openRpc:Jt,openRpcModule:es,queues:Ut,seed:qt,server:te,shard:_t,vectors:Vt,workflows:Bt},migrations:ye,outputDirectory:O,platformDiagnostics:_.diagnostics,queues:N,schemaSnapshot:Qe,schemaSnapshotPath:Ze,workflows:K,writtenFiles:Ie}};export{Cg as SCHEMA_SNAPSHOT_FILENAME,_g as createCodegenProject,Fg as findTsconfig,Jp as refreshCodegenProject,Zp as runCodegen};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{m as b}from"./modules-BIpFLz3Z.mjs";import{r as E}from"./json-data-Chfs2Cz5.mjs";import{s as l}from"./paths-DwTjD7BU.mjs";import{LUNORA_ERROR_CODES as P,objectSchema as g,validatorIrToJsonSchema as m}from"./LUNORA_ERROR_CODES-C2s0xWQD.mjs";import{G as A}from"./shared-Be3TGzxM.mjs";const T="/_lunora/rest",x=["authorization","cf-access-jwt-assertion","cookie","payment-signature","x-payment"],v=["x-d1-bookmark","x-lunora-shard-key"],j=e=>[...x,...(e.credentialHeaders??[]).map(t=>t.toLowerCase())],O=e=>Number.isFinite(e)?Math.max(0,Math.floor(e)):0,$=(...e)=>{const t=[];for(const r of e)for(const n of r?.split(",")??[]){const s=n.trim().toLowerCase();s!==""&&!t.includes(s)&&t.push(s)}return t.length===0?void 0:t.join(", ")},k=(e,t)=>{const r=[t,`max-age=${String(O(e.maxAge))}`];return e.staleWhileRevalidate!==void 0&&r.push(`stale-while-revalidate=${String(O(e.staleWhileRevalidate))}`),r.join(", ")},N=e=>e.scope==="public"?$(e.vary,...j(e),...v):$(e.vary,...v),q=e=>{const t=e.indexOf(":");if(!(t<=0||t>=e.length-1||e.indexOf(":",t+1)!==-1))return{name:e.slice(t+1),namespace:e.slice(0,t)}},_=e=>{const t=q(e);if(t!==void 0)return`${T}/${t.namespace}/${t.name}`},C=e=>e==="query"?"GET":"POST",y="#/components/responses/LunoraError",R=/:([A-Za-z_$][\w$]*)/gu,w=e=>[...e.matchAll(R)].map(t=>t[1]),D=e=>e.replaceAll(R,"{$1}"),f=e=>e.kind==="optional"?e.inner??e:e,I=e=>{const t=new Set(w(e.path)),r=[];for(const[n,s]of Object.entries(e.searchParams)){const c=f(s);r.push({description:`Query parameter \`${n}\``,in:"query",name:n,required:s.kind!=="optional",schema:m(c)})}for(const[n,s]of Object.entries(e.params)){const c=f(s);r.push({description:`Path parameter \`${n}\``,in:t.has(n)?"path":"query",name:n,required:t.has(n)?!0:s.kind!=="optional",schema:m(c)})}return r},S=e=>e?{content:{"application/json":{schema:m(e)}},description:"Successful response."}:{content:{"application/json":{schema:{description:"Return shape is TS-inferred (no `.output()` declared); best-effort — any JSON."}}},description:"Successful response. The return shape is TypeScript-inferred and not declared via `.output()`, so it is documented best-effort."},L=(e,t)=>{const r=I(e),n={description:`${e.stream?"Streaming (SSE) ":""}HTTP route handler \`${e.exportName}\` (${e.method} ${e.path}).`,operationId:`${e.method.toLowerCase()}_${l(e.path)}`,responses:{200:S(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:y}},summary:`${e.method} ${e.path}`,tags:[t]};return r.length>0&&(n.parameters=r),Object.keys(e.body).length>0&&(n.requestBody={content:{"application/json":{schema:g(e.body)}},required:!0}),e.stream&&(n["x-lunora-stream"]="text/event-stream"),n},F=(e,t)=>{const r=`${l(e.filePath)}:${e.exportName}`,n={additionalProperties:!1,properties:{args:g(e.args),functionPath:{const:r,type:"string"},shardKey:{description:"Optional shard key; omitted routes to the default shard.",type:"string"}},required:["functionPath"],type:"object"};return{operation:{description:`Invoke the \`${e.kind}\` \`${r}\` over the Lunora RPC envelope (POST /_lunora/rpc).`,operationId:r,requestBody:{content:{"application/json":{schema:n}},required:!0},responses:{200:S(e.output),default:{$ref:y}},summary:`${e.kind}: ${r}`,tags:[t],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${r}`}},H=(e,t)=>{if(e===void 0||t!=="get"||e.scope===void 0||e.maxAge===void 0)return{};const r={maxAge:e.maxAge,scope:e.scope,...e.staleWhileRevalidate===void 0?{}:{staleWhileRevalidate:e.staleWhileRevalidate},...e.tag===void 0?{}:{tag:e.tag},...e.vary===void 0?{}:{vary:e.vary}},n={"Cache-Control":{description:r.scope==="public"?"Caching policy. `public` applies only to an uncredentialed request — a request carrying `Authorization` or `Cookie` is always answered `private`.":"Caching policy. Restricted to the caller's own cache; never stored by a shared/edge cache.",schema:{example:k(r,r.scope),type:"string"}}};r.tag!==void 0&&(n["Cache-Tag"]={description:"Purge tag for `ctx.cache.purge({ tags: [...] })`.",schema:{example:r.tag,type:"string"}});const s=N(r);return s!==void 0&&(n.Vary={description:"Request headers this response varies by. The endpoint's own negotiated headers are merged in at runtime.",schema:{example:s,type:"string"}}),{headers:n}},M=(e,t)=>{const r=`${l(e.filePath)}:${e.exportName}`,n=_(r);if(n===void 0)return;const s=C(e.kind),c=s==="GET",i={description:`Public REST endpoint for the \`${e.kind}\` \`${r}\` (opt-in via \`.expose({ rest: true })\`). Routed through the procedure, so auth / RLS / validators are enforced.`,operationId:`rest_${l(n)}`,responses:{200:{content:{"application/json":{schema:{description:"Procedure result. The shape is TS-inferred from the return type; best-effort — any JSON."}}},description:"Successful result (TypeScript-inferred return shape, documented best-effort).",...H(e.expose?.cache,c?"get":"post")},default:{$ref:y}},summary:`${s} ${n}`,tags:[t],"x-lunora-function-kind":e.kind};if(c){const d=Object.entries(e.args).map(([u,h])=>{const o=f(h);return{description:`Argument \`${u}\` (JSON-encoded for non-string values).`,in:"query",name:u,required:h.kind!=="optional",schema:m(o)}});return d.length>0&&(i.parameters=d),{method:"get",operation:i,path:n}}return i.requestBody={content:{"application/json":{schema:g(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:i,path:n}},J=e=>{const t=e.version??"0.0.0",r=Object.create(null),n=o=>r[o]??Object.create(null),s=new Set,c=e.modules??[],i=o=>b(c,o);for(const o of e.httpRoutes){const a=D(o.path),p=n(a);p[o.method.toLowerCase()]=L(o,i(o.filePath)),r[a]=p,s.add(i(o.filePath))}const d=e.functions.filter(o=>o.visibility!=="internal"&&o.kind!=="stream");for(const o of d){const{operation:a,pathKey:p}=F(o,i(o.filePath));r[p]={post:a},s.add(i(o.filePath))}for(const o of d){if(o.expose?.rest!==!0)continue;const a=M(o,i(o.filePath));if(a===void 0)continue;const p=n(a.path);p[a.method]=a.operation,r[a.path]=p}const u=[...s].toSorted((o,a)=>o.localeCompare(a)).map(o=>({description:c.find(p=>p.name===o)?.description??`Operations declared in \`lunora/${o}\`.`,name:o}));return{components:{responses:{LunoraError:{content:{"application/json":{schema:{additionalProperties:!1,description:"Standard Lunora error envelope.",properties:{error:{additionalProperties:!1,properties:{code:{description:"Machine-readable error code. Clients switch on this value.",enum:P,type:"string"},message:{description:"Human-readable error message (never echoes internal details).",type:"string"}},required:["code","message"],type:"object"}},required:["error"],type:"object"}}},description:"A Lunora error response. The HTTP status reflects the error code (e.g. BAD_REQUEST→400, UNAUTHORIZED→401, FORBIDDEN→403, NOT_FOUND→404)."}}},info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora API",version:t},openapi:"3.1.0",paths:Object.fromEntries(Object.entries(r).map(([o,a])=>[o,{...a}])),tags:u}},z=e=>`${JSON.stringify(J(e),void 0,2)}
|
|
2
|
-
`,K=e=>`${A}export const openApiSpec = ${E(e,"Record<string, unknown>")};
|
|
3
|
-
`;export{J as buildOpenApiDocument,z as emitOpenApi,K as emitOpenApiModule};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{w as a}from"./classify-procedure-call-DxuPQkJA.mjs";const l=s=>a(s,"use","rls");export{l as r};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as P}from"./declared-output-Iaar469J.mjs";import{s as b}from"./paths-DwTjD7BU.mjs";import{findObjectProperty as c,bindingKeyName as N,listLunoraSourceFiles as A,lunoraRelativePath as F}from"./isTestPath-CgyyLk8U.mjs";import{e as O,i as z}from"./attribution-Dw35rOaJ.mjs";import{u as y,p as C,c as g,r as S}from"./unwrap-handler-return-T5sJhEss.mjs";import{b as d,c as L}from"./classify-procedure-call-DxuPQkJA.mjs";import{Node as n,SyntaxKind as k}from"ts-morph";import{r as h,p as x,a as I}from"./parse-validator-DYdT7Hyf.mjs";const T=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return"unknown";const t=c(e,"handler");if(!t||!n.isPropertyAssignment(t))return"unknown";const r=t.getInitializer();return!r||!(n.isArrowFunction(r)||n.isFunctionExpression(r))?"unknown":y(r)},w=i=>{const e=i.getArguments()[0];return!e||!(n.isArrowFunction(e)||n.isFunctionExpression(e))?"unknown":y(e)},V=i=>{let e={};for(const t of d(i)){if(t.name!=="input")continue;const r=t.call.getArguments()[0],s=r!==void 0&&n.isExpression(r)?h(r):void 0;s!==void 0&&(e={...x(s),...e})}return e},D=i=>{const e=d(i).find(r=>r.name==="output");if(!e)return;const t=e.call.getArguments()[0];return t&&n.isExpression(t)?C(e.call,()=>I(t)):void 0},p=(i,e)=>{const t=c(i,e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isStringLiteral(r)?r.getLiteralValue():void 0},v=(i,e)=>{const t=c(i,e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isNumericLiteral(r)?r.getLiteralValue():void 0},j=i=>{const e=c(i,"cache");if(e===void 0||!n.isPropertyAssignment(e))return;const t=e.getInitializer();if(t===void 0||!n.isObjectLiteralExpression(t))return;const r=p(t,"scope"),s=v(t,"maxAge"),o=v(t,"staleWhileRevalidate"),a=p(t,"tag"),l=p(t,"vary"),m={...s===void 0?{}:{maxAge:s},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...l===void 0?{}:{vary:l}};return Object.keys(m).length===0?void 0:m},B=i=>{if(i===void 0||!n.isObjectLiteralExpression(i))return{};const e=j(i),t=c(i,"rest");return t!==void 0&&n.isPropertyAssignment(t)?{...e===void 0?{}:{cache:e},rest:t.getInitializer()?.getText()==="true"}:e===void 0?{}:{cache:e}},R=i=>{const e=d(i).find(t=>t.name==="expose");return e?B(e.call.getArguments()[0]):void 0},M=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return{};const t=c(e,"args");if(!t||!n.isPropertyAssignment(t))return{};const r=t.getInitializer(),s=r===void 0?void 0:h(r);return s===void 0?{}:x(s)},$=8,u=(i,e=0)=>{if(e>$)return;if(n.isCallExpression(i))return i;if(n.isParenthesizedExpression(i)||n.isAsExpression(i)||n.isSatisfiesExpression(i)||n.isNonNullExpression(i))return u(i.getExpression(),e+1);if(!n.isIdentifier(i)&&!n.isPropertyAccessExpression(i))return;const t=i.getSymbol()?.getValueDeclaration();return t?f(t,e+1):void 0},f=(i,e)=>{if(n.isVariableDeclaration(i)||n.isPropertyAssignment(i)){const t=i.getInitializer();return t?u(t,e):void 0}if(n.isShorthandPropertyAssignment(i)){const t=i.getValueSymbol()?.getValueDeclaration();return t?f(t,e+1):void 0}if(n.isBindingElement(i)){const t=N(i),o=i.getFirstAncestorByKind(k.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return o?f(o,e+1):void 0}},W=(i,e=()=>!0)=>{const t=i.getNameNode();if(n.isObjectBindingPattern(t)){const o=[];for(const a of t.getElements().filter(l=>e(l.getName()))){const l=u(a.getNameNode());l&&o.push([a.getName(),l])}return o}if(!e(i.getName()))return[];const r=i.getInitializer(),s=r&&(n.isCallExpression(r)?r:u(r));return s?[[i.getName(),s]]:[]},_=i=>{const e=L(i);if(!e)return;const{receiver:t}=e;if(t){const r=R(t),s=g(()=>D(t)),o=g(()=>w(i)),a=P({kind:e.kind,output:s.value});return S(a?s.erased:o.erased),{args:V(t),...r?{expose:r}:{},kind:e.kind,...s.value?{output:s.value}:{},returnType:o.value,visibility:e.visibility}}return e.lifecycle?{args:{},kind:e.kind,lifecycle:e.lifecycle,returnType:"void",visibility:e.visibility}:{args:M(i),kind:e.kind,returnType:T(i),visibility:e.visibility}},E=(i,e,t)=>{const r=_(i);if(r)return{args:r.args,exportName:e,filePath:t,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},H=(i,e)=>{const t=[];for(const r of i.getExportAssignments()){if(r.isExportEquals())continue;const s=u(r.getExpression()),o=s?E(s,"default",e):void 0;o&&t.push(o)}return t},K=(i,e)=>{const t=O(i),r=i.getVariableStatements().flatMap(o=>o.getDeclarations()).flatMap(o=>W(o,a=>t.has(a))).flatMap(([o,a])=>(t.get(o)??[]).filter(l=>z(l)).flatMap(l=>E(a,l,e)??[])),s=new Set(r.map(o=>o.exportName));return r.push(...H(i,e).filter(o=>!s.has(o.exportName))),r},q=i=>{const e=new Map;for(const t of i){const r=b(t.filePath),s=e.get(r);if(s&&s!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${s}" and "${t.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[s,t.filePath],status:500});e.set(r,t.filePath)}},te=(i,e)=>{const t=A(e),r=[];for(const s of t){const o=i.getSourceFile(s)??i.addSourceFileAtPath(s),a=F(e,s);r.push(...K(o,a))}return r.sort((s,o)=>`${s.filePath}:${s.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),q(r),r};export{te as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as o}from"./context-property-calls-BLTVj9HH.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./isTestPath-CgyyLk8U.mjs";import"./attribution-Dw35rOaJ.mjs";import"./database-calls-DWDtdDbS.mjs";import"./classify-procedure-call-DxuPQkJA.mjs";import{d as a}from"./index-CefI-Sba.mjs";export{a as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as r}from"./context-property-calls-BLTVj9HH.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{existsSync as h,statSync as P,readdirSync as A,realpathSync as C,lstatSync as j}from"node:fs";import{dirname as d,join as g,relative as w,sep as O,resolve as k,extname as F,basename as D}from"node:path";import{findUpSync as z,FIND_UP_STOP as V,matcher as K}from"@visulima/fs";import{SyntaxKind as p,Node as i,VariableDeclarationKind as $}from"ts-morph";import{diagnosticAt as M}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{p as U,a as B,r as W}from"./project-config-file-Bv2l-Kmm.mjs";import{findProjectConfigFile as N}from"./PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";const X=/\.ts$/u,f=(t,e)=>w(t,e).split(O).join("/").replace(X,""),H=new Set(["_generated","node_modules"]),_=new Set(["__fixtures__","__mocks__","__snapshots__","__tests__"]),L=/\.(?:bench|e2e|e2e-spec|spec|spec-d|test|test-d)(?:\.tsx?)?$/u,Se=t=>{const e=t.split("/");return L.test(e.at(-1)??"")||e.slice(0,-1).some(s=>_.has(s))},E=(t,e,s)=>e?H.has(t)||!s&&_.has(t):!s&&L.test(t),v=new Map,m=()=>!1,Y=t=>{const e=z(c=>N(c)??(h(g(c,"package.json"))||h(g(c,".git"))?V:void 0),{cwd:d(k(t))}),s=e===void 0?void 0:P(e,{throwIfNoEntry:!1});if(e===void 0||s===void 0)return m;const n=`${String(s.mtimeMs)}:${String(s.size)}`,r=v.get(e);if(r?.key===n)return r.isExcluded;const{codegen:o}=W(d(e));o?.unreadable&&console.warn("@lunora/codegen: `codegen.exclude` in lunora.config is not an array of string literals without `!` negations — ignoring it.");const a=o?.exclude?.length?K(o.exclude):m;return v.set(e,{isExcluded:a,key:n}),a},q=(t,e,s)=>t==="schema.ts"&&e===s,G=t=>{try{return P(t)}catch{console.warn(`@lunora/codegen: skipping ${t} — it is a symlink that does not resolve (or vanished mid-scan).`);return}},R=(t,e,s,n,r)=>{let o,a;try{o=A(t),a=C(t)}catch{return e}if(n.has(a))return e;n.add(a);for(const c of o){const u=g(t,c),l=G(u);l===void 0||r(c,w(s,u).split(O).join("/"),l.isDirectory())||(l.isDirectory()?R(u,e,s,n,r):l.isFile()&&F(c)===".ts"&&!q(c,t,s)&&e.push(u))}return e},T=(t,e={})=>{const s=e.includeSkipped??!1,n=s?m:Y(t);return R(t,[],t,new Set,(r,o,a)=>E(r,a,s)||n(o))},Q=["src/server","src/index.ts","src/worker.ts"],J=new Set([".ts",".tsx"]),b=(t,e=[])=>{let s;try{s=j(t)}catch{return e}if(s.isFile())return J.has(F(t))&&!E(D(t),!1,!1)&&e.push(t),e;if(!s.isDirectory())return e;for(const n of A(t))E(n,!0,!1)||b(g(t,n),e);return e},Z=t=>{const e=d(t),s=T(t).map(o=>({displayPath:f(t,o),filePath:o})),n=new Set(s.map(o=>o.filePath)),r=N(e);for(const o of[...Q.flatMap(a=>b(g(e,a))),...r===void 0?[]:[r]])n.has(o)||(n.add(o),s.push({displayPath:f(e,o),filePath:o}));return s},ee=t=>Array.isArray(t),I=(t,e,s,n)=>{const r=[];for(const{displayPath:o,filePath:a}of e){const c=t.getSourceFile(a)??t.addSourceFileAtPath(a);for(const u of c.getDescendantsOfKind(s)){const l=n(u,o);ee(l)?r.push(...l):l!==void 0&&r.push(l)}}return r},te=t=>T(t).map(e=>({displayPath:f(t,e),filePath:e})),se=(t,e,s,n)=>I(t,te(e),s,n),he=(t,e,s)=>se(t,e,p.CallExpression,s),ve=(t,e,s)=>I(t,Z(e),p.CallExpression,s),ye=t=>U(t.getPropertyNameNode()??t.getNameNode()),S=(t,e)=>t?.getProperties().find(s=>!i.isSpreadAssignment(s)&&B(s)===e),Pe=(t,e)=>{if(e){const o=t.getArguments()[0];return o&&(i.isArrowFunction(o)||i.isFunctionExpression(o))?o:void 0}const s=t.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return;const n=S(s,"handler");if(!n||!i.isPropertyAssignment(n))return;const r=n.getInitializer();return r&&(i.isArrowFunction(r)||i.isFunctionExpression(r))?r:void 0},Ae=(t,e)=>{if(!t||!i.isObjectLiteralExpression(t))return;const s=S(t,e);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},ie=t=>{const e=t?.getParent();return i.isVariableDeclaration(t)&&i.isVariableDeclarationList(e)&&e.getDeclarationKind()===$.Const},ne=t=>{let e=t,s=e.getParent();for(;s!==void 0&&(i.isParenthesizedExpression(s)||i.isAsExpression(s)||i.isSatisfiesExpression(s)||i.isTypeAssertion(s)||i.isNonNullExpression(s));)e=s,s=e.getParent();return e},y=t=>{const e=ne(t),s=e.getParent();if(s===void 0)return!1;if(i.isBinaryExpression(s)){const r=s.getOperatorToken().getKind();return s.getLeft()===e&&r>=p.FirstAssignment&&r<=p.LastAssignment}if(i.isPrefixUnaryExpression(s)||i.isPostfixUnaryExpression(s)){const r=s.getOperatorToken();return r===p.PlusPlusToken||r===p.MinusMinusToken}return i.isDeleteExpression(s)?!0:i.isForOfStatement(s)||i.isForInStatement(s)?s.getInitializer()===e:i.isPropertyAssignment(s)?s.getInitializer()===e&&y(s):(i.isShorthandPropertyAssignment(s)||i.isSpreadAssignment(s)||i.isSpreadElement(s)||i.isObjectLiteralExpression(s)||i.isArrayLiteralExpression(s))&&y(s)},re=t=>{const e=t?.getDeclarations().find(n=>i.isVariableDeclaration(n));if(!ie(e))return;const s=e.getParent().getParent();return i.isVariableStatement(s)&&i.isSourceFile(s.getParent())?e.getInitializer():void 0},oe=t=>re(t.getSymbol()),we=t=>{if(!t)return;if(i.isObjectLiteralExpression(t))return t;if(!i.isIdentifier(t))return;const e=oe(t);return e!==void 0&&i.isObjectLiteralExpression(e)?e:void 0},x=t=>{let e=t;for(;e&&(i.isAsExpression(e)||i.isSatisfiesExpression(e)||i.isParenthesizedExpression(e)||i.isNonNullExpression(e));)e=e.getExpression();return e},ae=(t,e)=>{let s=x(t);for(;i.isAwaitExpression(s)||i.isPropertyAccessExpression(s)||i.isElementAccessExpression(s)||i.isCallExpression(s);){const n=i.isCallExpression(s)?e?.(s):void 0;if(n!==void 0)return{verdict:n};s=x(s.getExpression())}return{root:s}},Oe=t=>ae(t).root,Fe=(t,e)=>t?.compilerNode===e.compilerNode,Ne=t=>{if(i.isPropertyAccessExpression(t))return{member:t.getName(),object:t.getExpression()};const e=i.isElementAccessExpression(t)?t.getArgumentExpression():void 0;return i.isElementAccessExpression(t)&&i.isStringLiteral(e)?{member:e.getLiteralValue(),object:t.getExpression()}:void 0},_e=t=>{const e=t.getParent();return i.isReturnStatement(e)||i.isArrowFunction(e)&&e.getBody()===t?t.getFirstAncestor(n=>i.isFunctionLikeDeclaration(n)||i.isArrowFunction(n)):void 0},Le=t=>{const e=x(t);return e&&i.isCallExpression(e)?e:void 0},Re=t=>{const e=t.getExportAssignment(r=>!r.isExportEquals());if(!e)return;const s=e.getExpression();if(!i.isIdentifier(s))return s;const n=s.getSymbol()?.getValueDeclaration();return n&&i.isVariableDeclaration(n)?n.getInitializer():s},Te=t=>{const e=t.getArguments()[1];return e&&i.isStringLiteral(e)?e.getLiteralValue():""},be=(t,e)=>{if(!i.isObjectLiteralExpression(t))return;const s=S(t,e);if(!s||!i.isPropertyAssignment(s))return;const n=s.getInitializer();return n&&i.isStringLiteral(n)?n.getLiteralText():void 0},ce=t=>{const e=t.getStatements(),[s]=e;if(e.length!==1||s===void 0||!i.isReturnStatement(s))return;const n=s.getExpression();return n!==void 0&&i.isObjectLiteralExpression(n)?n:void 0},Ie=t=>{if(i.isObjectLiteralExpression(t))return t;if(i.isParenthesizedExpression(t)){const e=t.getExpression();return i.isObjectLiteralExpression(e)?e:void 0}return i.isBlock(t)?ce(t):void 0},Ce=t=>(e,s,n)=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw M(e,`${t} "${s}": \`${n}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)},le=new Set(["api","internal"]),je=new Set(["run","runAction","runMutation","runQuery"]),ue=t=>{if(t===void 0||!i.isPropertyAccessExpression(t))return;const e=[];let s=t;for(;i.isPropertyAccessExpression(s);)e.unshift(s.getName()),s=s.getExpression();return i.isIdentifier(s)&&le.has(s.getText())&&e.length>=2?e:void 0},ke=t=>{const e=ue(t);return e===void 0?void 0:`${e.slice(0,-1).join("_")}:${String(e.at(-1))}`};export{je as RUN_METHODS,X as TS_EXTENSION_RE,ye as bindingKeyName,Oe as chainRootOf,he as collectCallRows,se as collectNodeRows,ve as collectSecurityCallRows,Re as defaultExportExpression,S as findObjectProperty,ke as functionKeyOf,ue as functionReferenceSegments,Pe as handlerOf,ie as isConstDeclaration,Fe as isSameNode,Se as isTestPath,y as isWriteTarget,Te as limitNameOf,T as listLunoraSourceFiles,Z as listSecurityScanFiles,f as lunoraRelativePath,Ne as memberAccessOf,Ie as objectLiteralFromCallbackBody,we as optionsObjectLiteral,ne as outermostValueWrapper,Ae as propertyInitializer,B as propertyKeyName,U as propertyNameText,_e as returningFunctionOf,Ce as stringPropertyFor,be as stringPropertyOf,re as symbolConstInitializer,x as unwrapExpression,Le as unwrapToCallExpression,ae as walkChain};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{basename as b}from"node:path";import{Node as d}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{s as g}from"./paths-DwTjD7BU.mjs";import{listLunoraSourceFiles as $,lunoraRelativePath as v,unwrapToCallExpression as E,defaultExportExpression as S,findObjectProperty as M}from"./isTestPath-CgyyLk8U.mjs";const h=(e,o)=>e.find(t=>t.ownsFolder!==!1&&o.startsWith(`${t.name}/`))?.name,F="module.ts",w=(e,o,t)=>{if(d.isStringLiteral(e)||d.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw c(e,`module "${o}": \`${t}\` must be a static string literal — codegen reads it without running the file`)},L=(e,o,t)=>{if(!d.isArrayLiteralExpression(e))throw c(e,`module "${o}": \`${t}\` must be an inline array of table names`);return e.getElements().map(n=>w(n,o,t))},p=(e,o,t)=>{const n=M(e,o);if(n!==void 0){if(!d.isPropertyAssignment(n))throw c(n,`module "${t}": write \`${o}\` inline as \`${o}: …\` — codegen reads it without running the file`);return n.getInitializerOrThrow()}},A=(e,o,t)=>{const n=e.getSourceFile(o)??e.addSourceFileAtPath(o),s=E(S(n)),a=s?.getExpression();if(!s||!a||!d.isIdentifier(a)||a.getText()!=="defineModule")return;if(t==="")throw c(s,"defineModule: lunora/module.ts would make the whole app one module — move it into the folder it describes (lunora/<module>/module.ts)");const i=s.getArguments()[0],m={name:t,tables:[]};if(i===void 0)return m;if(!d.isObjectLiteralExpression(i))throw c(i,`module "${t}": defineModule must be passed an inline object literal`);const r=p(i,"description",t);r!==void 0&&(m.description=w(r,t,"description"));const l=p(i,"tables",t);return l!==void 0&&(m.tables=L(l,t,"tables")),m},k=(e,o)=>{const t=[];for(const n of $(o)){if(b(n)!==F)continue;const s=v(o,n),a=A(e,n,s==="module"?"":s.slice(0,-7));a&&t.push(a)}return t.toSorted((n,s)=>n.name.localeCompare(s.name))},T=(e,o)=>{const t=new Set(e.map(r=>r.name)),n=new Set(e.flatMap(r=>r.tables)),s=o.tables.filter(r=>r.extensionKey!==void 0&&!n.has(r.name)),a=Map.groupBy(s,r=>String(r.extensionKey)),i=e.map(r=>{const l=a.get(r.name);return l===void 0?r:{...r,tables:[...r.tables,...l.map(u=>u.name)]}}),m=[...a].filter(([r])=>!t.has(r)).map(([r,l])=>{const u=l.every(f=>f.extensionFromPackage===!0);return{installed:!0,name:r,...u?{ownsFolder:!1}:{},tables:l.map(f=>f.name)}});return[...i,...m].toSorted((r,l)=>r.name.localeCompare(l.name))},x=e=>{for(const o of e){const t=e.find(n=>n.name.startsWith(`${o.name}/`));if(t)throw new Error(`@lunora/codegen: module "${t.name}" is nested inside ${o.installed===!0?"installed component":"module"} "${o.name}" — a file can belong to one module only, so move one of the two`)}},y=(e,o)=>{const t=new Set(o.tables.map(s=>s.name)),n=new Map;for(const s of e)for(const a of s.tables){if(!t.has(a))throw new Error(`@lunora/codegen: module "${s.name}" declares table "${a}", which lunora/schema.ts does not define`);const i=n.get(a);if(i!==void 0)throw new Error(`@lunora/codegen: table "${a}" is claimed by both module "${i}" and module "${s.name}" — a table has one owner`);n.set(a,s.name)}},C=(e,o,t)=>{if(e.length===0)return;const n=new Set(o.map(s=>s.name));for(const s of t){const a=g(s);if(h(o,s)===void 0&&n.has(a))throw new Error(`@lunora/codegen: lunora/${s}.ts sits beside module "${a}" and shares its name — move it into lunora/${a}/ or rename one of them`)}},z=(e,o,t)=>{const n=T(e,o);return x(n),y(n,o),C(e,n,t),n},K=(e,o)=>h(e,o)??g(o);export{h as a,k as d,K as m,z as r};
|
|
File without changes
|