@lunora/codegen 1.0.0-alpha.238 → 1.0.0-alpha.239
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
CHANGED
|
@@ -3395,7 +3395,7 @@ interface EmitAppOptions {
|
|
|
3395
3395
|
hasAuth: boolean;
|
|
3396
3396
|
/** App uses `@lunora/browser` / `ctx.browser` → emit `.browser()`. */
|
|
3397
3397
|
hasBrowser: boolean;
|
|
3398
|
-
/** App depends on a worker-composition framework adapter (`@lunora/astro`/`@lunora/svelte`/`@lunora/vue`) → emit `.buildFrameworkWorker(host)`. */
|
|
3398
|
+
/** App depends on a worker-composition framework adapter (`@lunora/astro`/`@lunora/svelte`/`@lunora/vue`), or hand-composes one in `src/worker.ts` → emit `.buildFrameworkWorker(host)`. */
|
|
3399
3399
|
hasFramework: boolean;
|
|
3400
3400
|
/** Schema declares **D1-backed** `.global()` tables → emit `.global()` (D1 ctx-db + studio introspector + cross-shard relations). */
|
|
3401
3401
|
hasGlobal: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -3395,7 +3395,7 @@ interface EmitAppOptions {
|
|
|
3395
3395
|
hasAuth: boolean;
|
|
3396
3396
|
/** App uses `@lunora/browser` / `ctx.browser` → emit `.browser()`. */
|
|
3397
3397
|
hasBrowser: boolean;
|
|
3398
|
-
/** App depends on a worker-composition framework adapter (`@lunora/astro`/`@lunora/svelte`/`@lunora/vue`) → emit `.buildFrameworkWorker(host)`. */
|
|
3398
|
+
/** App depends on a worker-composition framework adapter (`@lunora/astro`/`@lunora/svelte`/`@lunora/vue`), or hand-composes one in `src/worker.ts` → emit `.buildFrameworkWorker(host)`. */
|
|
3399
3399
|
hasFramework: boolean;
|
|
3400
3400
|
/** Schema declares **D1-backed** `.global()` tables → emit `.global()` (D1 ctx-db + studio introspector + cross-shard relations). */
|
|
3401
3401
|
hasGlobal: boolean;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{formatAdvisories as m,lintSchema as f,toAdvisorContext as d}from"./packem_shared/formatAdvisories-DwmUKYuc.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as l,sortedUniqueNames as x}from"./packem_shared/describeErrorLevelFindings-vzaGS9KL.mjs";import{CodegenDiagnosticError as E,diagnosticAt as u}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as v,discoverAgents as N}from"./packem_shared/AGENTS_FILENAME-DoPI92Wu.mjs";import{listLunoraSourceFiles as C}from"./packem_shared/listLunoraSourceFiles-DP-5e-RE.mjs";import{default as R}from"./packem_shared/discoverAuthApiCalls-FxrdBeVt.mjs";import{CONTAINERS_FILENAME as T,discoverContainers as _}from"./packem_shared/CONTAINERS_FILENAME-B6TFs82W.mjs";import{default as L}from"./packem_shared/discoverCrons-MfKw7IFf.mjs";import{FLAGS_FILENAME as I,discoverFlags as P}from"./packem_shared/FLAGS_FILENAME-BedPDCsR.mjs";import{default as G}from"./packem_shared/discoverFunctions-BsmX-sEq.mjs";import{default as b}from"./packem_shared/discoverHttpRoutes-BcXI9CNt.mjs";import{default as y}from"./packem_shared/discoverHyperdriveCalls-D9qXqTq3.mjs";import{default as k}from"./packem_shared/discoverInserts-CFJ3IVeI.mjs";import{d as z}from"./packem_shared/index-BoaHhVtM.mjs";import{default as V}from"./packem_shared/discoverMigrations-DbrHwcGE.mjs";import{MUTATORS_FILENAME as q,discoverMutators as w}from"./packem_shared/MUTATORS_FILENAME-B6cKrN_m.mjs";import{default as B}from"./packem_shared/discoverNondeterministicCalls-CSQ_GDcA.mjs";import{NOTIFY_FILENAME as X,discoverNotifyCalls as Z,discoverNotifyConfig as $}from"./packem_shared/NOTIFY_FILENAME-Cri3NT5U.mjs";import{default as re}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as te}from"./packem_shared/queries-B-f4jO-x.mjs";import{QUEUES_FILENAME as ae,discoverQueues as ie}from"./packem_shared/QUEUES_FILENAME-CxkPcMH1.mjs";import{default as fe}from"./packem_shared/discoverR2sqlCalls-fu7fC0i_.mjs";import{default as pe}from"./packem_shared/discoverRlsProcedures-BO4qC77y.mjs";import{default as ne}from"./packem_shared/discoverRlsMetadata-CPmAGL0W.mjs";import{discoverSandboxUsage as xe}from"./packem_shared/discoverSandboxUsage-CrjZ6yNg.mjs";import{default as Ee}from"./packem_shared/discoverSchema-D8DBDHEg.mjs";import{SHAPES_FILENAME as Ae,discoverShapes as ve}from"./packem_shared/SHAPES_FILENAME-zJgzynXR.mjs";import{default as ge}from"./packem_shared/discoverStorageRulesMetadata-D8VYflWt.mjs";import{WORKFLOWS_FILENAME as Oe,discoverWorkflows as Re}from"./packem_shared/WORKFLOWS_FILENAME-B_ZJxRSx.mjs";import{emitApp as Te}from"./packem_shared/emitApp-BGhO5bhT.mjs";import{isD1GlobalTable as he,isHyperdriveGlobalTable as Le}from"./packem_shared/isD1GlobalTable-udvHAAzD.mjs";import{buildOpenApiDocument as Ie,emitOpenApi as Pe,emitOpenApiModule as De}from"./packem_shared/buildOpenApiDocument-nYvBhjxu.mjs";import{OPENRPC_VERSION as Ue,buildOpenRpcDocument as be,emitOpenRpc as He,emitOpenRpcModule as ye}from"./packem_shared/OPENRPC_VERSION-Cl6P9WGv.mjs";import{DEFAULT_TARGET as ke,platformMatrixIds as We,readProjectTarget as ze,resolveCodegenTarget as Ke}from"./packem_shared/DEFAULT_TARGET-DCpDuuUM.mjs";import{loadProjectConfig as Qe,readProjectConfigLiterals as qe}from"./packem_shared/loadProjectConfig-CKsFNgn3.mjs";import{SCHEMA_SNAPSHOT_FILENAME as Je,createCodegenProject as Be,findTsconfig as Ye,refreshCodegenProject as Xe,runCodegen as Ze}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-
|
|
1
|
+
import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{formatAdvisories as m,lintSchema as f,toAdvisorContext as d}from"./packem_shared/formatAdvisories-DwmUKYuc.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as l,sortedUniqueNames as x}from"./packem_shared/describeErrorLevelFindings-vzaGS9KL.mjs";import{CodegenDiagnosticError as E,diagnosticAt as u}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as v,discoverAgents as N}from"./packem_shared/AGENTS_FILENAME-DoPI92Wu.mjs";import{listLunoraSourceFiles as C}from"./packem_shared/listLunoraSourceFiles-DP-5e-RE.mjs";import{default as R}from"./packem_shared/discoverAuthApiCalls-FxrdBeVt.mjs";import{CONTAINERS_FILENAME as T,discoverContainers as _}from"./packem_shared/CONTAINERS_FILENAME-B6TFs82W.mjs";import{default as L}from"./packem_shared/discoverCrons-MfKw7IFf.mjs";import{FLAGS_FILENAME as I,discoverFlags as P}from"./packem_shared/FLAGS_FILENAME-BedPDCsR.mjs";import{default as G}from"./packem_shared/discoverFunctions-BsmX-sEq.mjs";import{default as b}from"./packem_shared/discoverHttpRoutes-BcXI9CNt.mjs";import{default as y}from"./packem_shared/discoverHyperdriveCalls-D9qXqTq3.mjs";import{default as k}from"./packem_shared/discoverInserts-CFJ3IVeI.mjs";import{d as z}from"./packem_shared/index-BoaHhVtM.mjs";import{default as V}from"./packem_shared/discoverMigrations-DbrHwcGE.mjs";import{MUTATORS_FILENAME as q,discoverMutators as w}from"./packem_shared/MUTATORS_FILENAME-B6cKrN_m.mjs";import{default as B}from"./packem_shared/discoverNondeterministicCalls-CSQ_GDcA.mjs";import{NOTIFY_FILENAME as X,discoverNotifyCalls as Z,discoverNotifyConfig as $}from"./packem_shared/NOTIFY_FILENAME-Cri3NT5U.mjs";import{default as re}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as te}from"./packem_shared/queries-B-f4jO-x.mjs";import{QUEUES_FILENAME as ae,discoverQueues as ie}from"./packem_shared/QUEUES_FILENAME-CxkPcMH1.mjs";import{default as fe}from"./packem_shared/discoverR2sqlCalls-fu7fC0i_.mjs";import{default as pe}from"./packem_shared/discoverRlsProcedures-BO4qC77y.mjs";import{default as ne}from"./packem_shared/discoverRlsMetadata-CPmAGL0W.mjs";import{discoverSandboxUsage as xe}from"./packem_shared/discoverSandboxUsage-CrjZ6yNg.mjs";import{default as Ee}from"./packem_shared/discoverSchema-D8DBDHEg.mjs";import{SHAPES_FILENAME as Ae,discoverShapes as ve}from"./packem_shared/SHAPES_FILENAME-zJgzynXR.mjs";import{default as ge}from"./packem_shared/discoverStorageRulesMetadata-D8VYflWt.mjs";import{WORKFLOWS_FILENAME as Oe,discoverWorkflows as Re}from"./packem_shared/WORKFLOWS_FILENAME-B_ZJxRSx.mjs";import{emitApp as Te}from"./packem_shared/emitApp-BGhO5bhT.mjs";import{isD1GlobalTable as he,isHyperdriveGlobalTable as Le}from"./packem_shared/isD1GlobalTable-udvHAAzD.mjs";import{buildOpenApiDocument as Ie,emitOpenApi as Pe,emitOpenApiModule as De}from"./packem_shared/buildOpenApiDocument-nYvBhjxu.mjs";import{OPENRPC_VERSION as Ue,buildOpenRpcDocument as be,emitOpenRpc as He,emitOpenRpcModule as ye}from"./packem_shared/OPENRPC_VERSION-Cl6P9WGv.mjs";import{DEFAULT_TARGET as ke,platformMatrixIds as We,readProjectTarget as ze,resolveCodegenTarget as Ke}from"./packem_shared/DEFAULT_TARGET-DCpDuuUM.mjs";import{loadProjectConfig as Qe,readProjectConfigLiterals as qe}from"./packem_shared/loadProjectConfig-CKsFNgn3.mjs";import{SCHEMA_SNAPSHOT_FILENAME as Je,createCodegenProject as Be,findTsconfig as Ye,refreshCodegenProject as Xe,runCodegen as Ze}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-BbHApV3q.mjs";import{SchemaSnapshotParseError as er,buildSchemaSnapshot as rr,evaluateSchemaDrift as or,parseSchemaSnapshot as tr}from"./packem_shared/SchemaSnapshotParseError-CPOXlFhI.mjs";import{default as ar}from"./packem_shared/fingerprintSchemaSources-L3nGKDQt.mjs";import{schemaFromIr as mr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as dr,validatorIrToJsonSchema as pr}from"./packem_shared/LUNORA_ERROR_CODES-C2s0xWQD.mjs";import{SDK_LANGUAGES as nr,SDK_TARGETS as lr,generateSdk as xr}from"./packem_shared/SDK_LANGUAGES-Df_CnJx5.mjs";import{redact as Er,secretKindOf as ur}from"./packem_shared/redact-Cy14LEnc.mjs";import{default as vr}from"./packem_shared/emitDrizzleSchema-Cv0HtLR3.mjs";import{default as gr}from"./packem_shared/emitFunctions-BqAz1ssY.mjs";import{default as Or}from"./packem_shared/emitServer-BEo_fCY8.mjs";import{e as Mr}from"./packem_shared/shard-B3LMNjIg.mjs";import{G as _r}from"./packem_shared/shared-DjUziztz.mjs";import{MESSAGE_SOLUTIONS as Lr,findSolutionByMessage as Fr}from"@lunora/errors";import{PROJECT_CONFIG_FILENAMES as Pr,findProjectConfigFile as Dr}from"./packem_shared/PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";import{y as Ur,z as br,A as Hr}from"./packem_shared/shard-runtime-B_ppYvOf.mjs";import{emitApi as jr,emitCollections as kr}from"./packem_shared/emitApi-CJ9ziZnP.mjs";import{emitCrons as zr,emitScheduler as Kr,emitVectors as Vr,emitWranglerCronTriggers as Qr}from"./packem_shared/emitCrons-mkwWkn0R.mjs";import{emitDataModel as wr}from"./packem_shared/emitDataModel-D3WuEZ4b.mjs";import{isTypedSchema as Br}from"./packem_shared/isTypedSchema-CKzc3ioR.mjs";const e="0.0.0";export{v as AGENTS_FILENAME,T as CONTAINERS_FILENAME,E as CodegenDiagnosticError,ke as DEFAULT_TARGET,I as FLAGS_FILENAME,_r as GENERATED_HEADER,dr as LUNORA_ERROR_CODES,Lr as LUNORA_SOLUTION_RULES,q as MUTATORS_FILENAME,X as NOTIFY_FILENAME,Ue as OPENRPC_VERSION,Pr as PROJECT_CONFIG_FILENAMES,ae as QUEUES_FILENAME,Je as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,nr as SDK_LANGUAGES,lr as SDK_TARGETS,Ae as SHAPES_FILENAME,er as SchemaSnapshotParseError,e as VERSION,Oe as WORKFLOWS_FILENAME,Ie as buildOpenApiDocument,be as buildOpenRpcDocument,rr as buildSchemaSnapshot,Be as createCodegenProject,c as describeErrorLevelFindings,u as diagnosticAt,s as diffSchemaSnapshots,N as discoverAgents,R as discoverAuthApiCalls,_ as discoverContainers,L as discoverCrons,P as discoverFlags,G as discoverFunctions,b as discoverHttpRoutes,y as discoverHyperdriveCalls,k as discoverInserts,z as discoverMaskProcedures,V as discoverMigrations,w as discoverMutators,B as discoverNondeterministicCalls,Z as discoverNotifyCalls,$ as discoverNotifyConfig,te as discoverQueries,ie as discoverQueues,fe as discoverR2sqlCalls,ne as discoverRlsMetadata,pe as discoverRlsProcedures,xe as discoverSandboxUsage,Ee as discoverSchema,ve as discoverShapes,ge as discoverStorageRulesMetadata,Re as discoverWorkflows,Ur as emitAgents,jr as emitApi,Te as emitApp,kr as emitCollections,br as emitContainers,zr as emitCrons,wr as emitDataModel,vr as emitDrizzleSchema,gr as emitFunctions,Pe as emitOpenApi,De as emitOpenApiModule,He as emitOpenRpc,ye as emitOpenRpcModule,Kr as emitScheduler,Or as emitServer,Mr as emitShard,Vr as emitVectors,Hr as emitWorkflows,Qr as emitWranglerCronTriggers,n as errorAdvisoryNames,l as errorPlatformDiagnosticNames,or as evaluateSchemaDrift,Fr as findLunoraSolution,Dr as findProjectConfigFile,Ye as findTsconfig,ar as fingerprintSchemaSources,m as formatAdvisories,xr as generateSdk,he as isD1GlobalTable,Le as isHyperdriveGlobalTable,Br as isTypedSchema,f as lintSchema,C as listLunoraSourceFiles,Qe as loadProjectConfig,tr as parseSchemaSnapshot,We as platformMatrixIds,re as readPackageDependencies,qe as readProjectConfigLiterals,ze as readProjectTarget,Er as redact,Xe as refreshCodegenProject,Ke as resolveCodegenTarget,Ze as runCodegen,mr as schemaFromIr,ur as secretKindOf,a as serializeSchemaSnapshot,x as sortedUniqueNames,d as toAdvisorContext,pr as validatorIrToJsonSchema};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{existsSync as w,mkdirSync as Ls,readFileSync as $t,writeFileSync as Ds,rmSync as ks}from"node:fs";import{join as
|
|
1
|
+
import{existsSync as w,mkdirSync as Ls,readFileSync as $t,writeFileSync as Ds,rmSync as ks}from"node:fs";import{join as E,dirname as ae}from"node:path";import{performance as we}from"node:perf_hooks";import{runAdvisor as Ms}from"@lunora/advisor";import{LunoraError as K}from"@lunora/errors";import{SyntaxKind as l,Node as i,VariableDeclarationKind as Ks,Project as dt}from"ts-morph";import{serializeSchemaSnapshot as _s}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{toAdvisorContext as zs}from"./formatAdvisories-DwmUKYuc.mjs";import{readProjectConfigLiterals as $s}from"./loadProjectConfig-CKsFNgn3.mjs";import{s as Us}from"./paths-C-9fwEgQ.mjs";import{C as ce}from"./capabilities-DJJWVEtk.mjs";import{isD1GlobalTable as Ut,isHyperdriveGlobalTable as Bt}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as Bs}from"./AGENTS_FILENAME-DoPI92Wu.mjs";import{discoverContainers as qs}from"./CONTAINERS_FILENAME-B6TFs82W.mjs";import js from"./discoverCrons-MfKw7IFf.mjs";import{diagnosticAt as ee}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as pe}from"./module-specifiers-WF8iAydP.mjs";import{listLunoraSourceFiles as p,bindingKeyName as Q,propertyKeyName as S,unwrapExpression as X,listSecurityScanFiles as me,objectLiteralFromCallbackBody as qt,propertyInitializer as b,lunoraRelativePath as x,collectCallRows as F,findObjectProperty as C,collectSecurityCallRows as Vs,limitNameOf as jt,optionsObjectLiteral as Vt,isContextIdentifier as Fe,handlerOf as Ws,isDatabaseAccessor as _,readTargetOf as Wt,enclosingExportName as Hs}from"./listLunoraSourceFiles-DP-5e-RE.mjs";import Gs from"./readPackageDependencies-C6h6FZuP.mjs";import{discoverQueues as Ys}from"./QUEUES_FILENAME-CxkPcMH1.mjs";import{discoverSandboxUsage as Qs}from"./discoverSandboxUsage-CrjZ6yNg.mjs";import Xs from"./discoverStorageRulesMetadata-D8VYflWt.mjs";import{a as A,c as z,d as Ht,e as Zs}from"./classify-procedure-call-BztLe76A.mjs";import{discoverWorkflows as Js}from"./WORKFLOWS_FILENAME-B_ZJxRSx.mjs";import{gatePlatformFeatures as en,resolveCodegenTarget as Gt,readTargetDiagnostics as tn,studioPlatformFor as sn}from"./DEFAULT_TARGET-DCpDuuUM.mjs";import{b as Yt,e as nn}from"./shard-B3LMNjIg.mjs";import rn from"./emitServer-BEo_fCY8.mjs";import{emitDataModel as on}from"./emitDataModel-D3WuEZ4b.mjs";import{i as k,a as U,e as y,r as an,b as cn,s as he,c as ln,f as un,d as dn}from"./queries-B-f4jO-x.mjs";import{r as ve,s as fn}from"./parse-validator-C94Yiabo.mjs";import gn from"./discoverAuthApiCalls-FxrdBeVt.mjs";import{i as pn,a as mn,e as hn,b as vn,d as xn,c as En}from"./unwrap-handler-return-CoV_GK33.mjs";import Sn from"./discoverFunctions-BsmX-sEq.mjs";import yn from"./discoverHttpRoutes-BcXI9CNt.mjs";import An from"./discoverHyperdriveCalls-D9qXqTq3.mjs";import bn from"./discoverInserts-CFJ3IVeI.mjs";import{m as Me,a as ue,s as Qt,d as Nn}from"./index-BoaHhVtM.mjs";import{e as Xt}from"./exported-procedure-chains-CmCDiPBV.mjs";import Pn from"./discoverMigrations-DbrHwcGE.mjs";import{MUTATORS_FILENAME as wn,isDefineMutatorCallee as In,discoverMutators as Tn}from"./MUTATORS_FILENAME-B6cKrN_m.mjs";import Cn from"./discoverNondeterministicCalls-CSQ_GDcA.mjs";import{discoverNotifyConfig as Fn,discoverNotifyCalls as On}from"./NOTIFY_FILENAME-Cri3NT5U.mjs";import Rn from"./discoverR2sqlCalls-fu7fC0i_.mjs";import Ln from"./discoverRlsProcedures-BO4qC77y.mjs";import Dn from"./discoverRlsMetadata-CPmAGL0W.mjs";import kn from"./discoverSchema-D8DBDHEg.mjs";import{secretKindOf as Mn,redact as Kn,isHeuristicSecretKind as _n,isSecretishName as zn}from"./redact-Cy14LEnc.mjs";import{discoverShapes as $n}from"./SHAPES_FILENAME-zJgzynXR.mjs";import{emitApp as Un}from"./emitApp-BGhO5bhT.mjs";import{buildOpenApiDocument as Bn,emitOpenApiModule as qn}from"./buildOpenApiDocument-nYvBhjxu.mjs";import{buildOpenRpcDocument as jn,emitOpenRpcModule as Vn}from"./OPENRPC_VERSION-Cl6P9WGv.mjs";import{buildSchemaSnapshot as Wn}from"./SchemaSnapshotParseError-CPOXlFhI.mjs";import{emitCollections as Hn,emitSeed as Gn,emitApi as Yn}from"./emitApi-CJ9ziZnP.mjs";import{z as Qn,A as Xn,y as Zn,B as Jn}from"./shard-runtime-B_ppYvOf.mjs";import{emitCrons as er,emitScheduler as tr,emitVectors as sr,emitWranglerCronTriggers as nr}from"./emitCrons-mkwWkn0R.mjs";import rr from"./emitDrizzleSchema-Cv0HtLR3.mjs";import or from"./emitFunctions-BqAz1ssY.mjs";const ft={error:"ERROR",info:"INFO",warn:"WARN"},gt={ERROR:2,INFO:0,WARN:1},ir=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"}),ar=(e,t)=>{const{advisor:s}=$s(e);if(s===void 0||s.minSeverity===void 0&&s.unreadable!==!0)return[...t];const{minSeverity:n}=s,o=n!==void 0&&Object.hasOwn(ft,n)?ft[n]:void 0;return o===void 0?[...t,ir(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(r=>gt[r.level]>=gt[o])},pt=(e,t="api")=>{const s=new Map;for(const n of e){const o=Us(n),r=s.get(o);if(r===void 0){s.set(o,n);continue}if(r!==n){const a=t==="api"?`the generated api.ts would declare "${o}" twice and the dispatch key "${o}:<fn>" would be ambiguous`:`the generated api.ts would declare "${o}" twice in HttpStreamsRef and again in the httpStreams object literal`;throw new K("INTERNAL",`@lunora/codegen: "${r}" and "${n}" both map to the ${t} namespace "${o}" — ${a}. Rename one file so the two differ by more than a non-identifier character (\`-\`, \`.\`, \`/\` and \`_\` all sanitize to \`_\`).`,{status:500})}}},cr=(e,t={})=>{const{hasVectors:s=!0,scheduler:n=!1,storage:o=!1,usage:r}=t,a=[];e.tables.some(c=>Ut(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=>Bt(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`"}),o&&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 r===void 0?[]:ce)c.requiredPackage!==void 0&&r?.[c.key]===!0&&a.push({name:c.requiredPackage,reason:`\`ctx.${c.contextProperty??c.key}\` usage makes \`_generated/\` import \`${c.moduleSpecifier}\``});return a.filter((c,u)=>a.findIndex(d=>d.name===c.name)===u)},lr=(e,t,s={})=>{if(t===void 0)return;const n=cr(e,s).filter(r=>!t.has(r.name));if(n.length===0)return;const o=n.map(r=>` - ${r.name} — ${r.reason}`).join(`
|
|
2
2
|
`);throw new K("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
|
|
3
3
|
${o}
|
|
4
4
|
|
|
5
|
-
Install them with your package manager, then re-run codegen.`)},ur="env.ts",dr=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return pe(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},fr=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&pe(n.getModuleSpecifierValue())}return!1},gr=e=>{if(i.isIdentifier(e))return dr(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&fr(t)}return!1},pr=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!gr(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw ee(r,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},mr=(e,t)=>{const s=y(t,ur);if(!w(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=pr(n);if(o.length!==0){if(o.length>1)throw ee(n,`lunora/env.ts declares ${o.length.toString()} defineEnv() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},mt="ctx",Zt=e=>{const t=new Set,s=new Set([mt]),n=r=>{if(i.isObjectBindingPattern(r))for(const a of r.getElements()){const c=Q(a);c&&t.add(c)}};for(const r of e.getDescendantsOfKind(l.BindingElement)){if(Q(r)!==mt)continue;const a=r.getNameNode();i.isIdentifier(a)?s.add(a.getText()):n(a)}const o=r=>i.isIdentifier(r)&&s.has(r.getText());for(const r of e.getDescendantsOfKind(l.PropertyAccessExpression))o(r.getExpression())&&t.add(r.getName());for(const r of e.getDescendantsOfKind(l.VariableDeclaration)){const a=r.getInitializer();a!==void 0&&o(a)&&n(r.getNameNode())}return t},hr=(e,t)=>{const s=Object.fromEntries(ce.map(n=>[n.key,!1]));for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=new Set(o.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=Zt(o);for(const c of ce)if(!s[c.key]){if(r.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(ce.every(c=>s[c.key]))break}return s},Jt="identity.ts",vr=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return pe(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},xr=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&pe(n.getModuleSpecifierValue())}return!1},Er=e=>{if(i.isIdentifier(e))return vr(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&xr(t)}return!1},Sr=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!Er(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw ee(r,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},yr=(e,t)=>{const s=y(t,Jt);if(!w(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=Sr(n);if(o.length!==0){if(o.length>1)throw ee(n,`lunora/identity.ts declares ${o.length.toString()} defineIdentity() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},Ar=new Set(["allowedHosts","deniedHosts","interceptHttps"]),br=(e,t)=>{const s=X(t);if(s===void 0||!i.isIdentifier(s))return s;const n=s.getText();return X(e.getDescendantsOfKind(l.VariableDeclaration).find(o=>o.getName()===n)?.getInitializer())},Nr=(e,t)=>e!==void 0&&i.isObjectLiteralExpression(e)&&e.getProperties().some(s=>{if(i.isShorthandPropertyAssignment(s))return t.has(E(s));if(!i.isPropertyAssignment(s)||!t.has(E(s)))return!1;const n=X(s.getInitializer())?.getText();return n!=="false"&&n!=="undefined"}),Pr=new Set(["durable"]),wr=new Set(["rollback"]),Ir=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)?t.getName():t.getText()},Tr=new Map([["defineContainer",{keys:Ar,signal:"containerEgressPolicy"}],["defineStep",{keys:wr,signal:"workflowRollback"}],["stream",{keys:Pr,signal:"durableStreams"}]]),Cr=(e,t)=>{const s=Tr.get(Ir(t));if(s!==void 0)return t.getArguments().some(n=>Nr(br(e,n),s.keys))?s.signal:void 0},Fr=(e,t)=>{const s={containerEgressPolicy:!1,durableStreams:!1,secrets:!1,workflowRollback:!1};for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.secrets||(s.secrets=Zt(o).has("secrets"));for(const r of o.getDescendantsOfKind(l.CallExpression)){const a=Cr(o,r);a!==void 0&&(s[a]=!0)}if(Object.values(s).every(Boolean))break}return s},Or="createWorker",Rr="extend",ht=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralValue():void 0,vt=e=>{const t=[],s=ht(b(e,"backupCron"));s!==void 0&&t.push(s);const n=b(e,"crons");if(n===void 0||!i.isObjectLiteralExpression(n))return t;for(const o of n.getProperties()){if(!i.isPropertyAssignment(o)&&!i.isMethodDeclaration(o))continue;const r=ht(o.getNameNode());r!==void 0&&t.push(r)}return t},Lr=e=>{const t=A(e.getExpression()),[s]=e.getArguments();if(s===void 0)return[];if(t===Or)return i.isObjectLiteralExpression(s)?vt(s):[];if(t!==Rr||!(i.isArrowFunction(s)||i.isFunctionExpression(s)))return[];const n=qt(s.getBody());return n===void 0?[]:vt(n)},Dr=(e,t)=>{const s=[];for(const{filePath:n}of me(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getDescendantsOfKind(l.CallExpression))s.push(...Lr(r))}return[...new Set(s)]},es=e=>{if(e.kind==="id")return e.tableName;if(!(e.kind!=="array"&&e.kind!=="optional"))return e.inner===void 0?void 0:es(e.inner)},kr=e=>{const t=new Set(e.tables.map(s=>s.name));return e.tables.some(s=>Object.values(s.shape).some(n=>{const o=es(n);return o!==void 0&&t.has(o)}))},Mr=(e,t)=>{const s=new Map,n=new Map,o=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.bindingName,`workflow "${r.exportName}"`),o.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const a=s.get(r.name);if(a!==void 0)throw new K("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${a} and agent "${r.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=n.get(r.bindingName);if(c!==void 0)throw new K("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${r.bindingName}": produced by both ${c} and agent "${r.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const u=o.get(r.className);if(u!==void 0)throw new K("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${u} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},Kr=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:o}=e,r=yr(s,t),a=mr(s,t),c=Js(s,t),u=Ys(s,t),d=Bs(s,t);Mr(c,d);const m=qs(s,t),h=Xs(s,t),R=js(s,t,c,d),M=Dr(s,t),g=Fr(s,t),I=Qs(s,t),N=hr(s,t);N.browser=N.browser||I.usesSandboxBrowser;const O=en(N,Gt(n,e.target),{agents:d.length>0,commitOrderedTables:o.tables.some(P=>P.commitOrdered===!0),cronTriggers:R.length>0,crossShardFanout:o.tables.some(P=>typeof P.shardMode=="object"),containerEgressPolicy:g.containerEgressPolicy,durableStreams:g.durableStreams,globalTables:o.tables.some(P=>P.shardMode==="global"),queues:u.length>0,relationGraph:kr(o),secrets:g.secrets,vectorStore:o.vectorIndexes.length>0,workerLoaders:I.usesSandboxLoader,workflowRollback:g.workflowRollback}),v=O.usage,D=O.signals.vectorStore!==!1,B=Gs(n),H=B??new Set,te=H.has("lunorash");lr(o,B,{hasVectors:D,scheduler:v.scheduler||R.length>0,storage:v.storage||h.rules.length>0||Object.keys(Yt(o)).length>0,usage:v});const $=w(y(t,"flags.ts")),L=w(y(t,"notify.ts"));return{agents:d,containers:m,crons:R,dataModelContent:on(o),declaredDependencies:B,dependencies:H,entryCronTriggers:M,env:a,featureUsage:v,hasFlags:$,hasNotify:L,identity:r,platformGate:{...O,diagnostics:[...tn(n,e.target),...O.diagnostics]},queues:u,serverContent:rn({agents:d,containers:m,env:a,hasAccessFacade:v.access,hasAi:v.ai,hasAnalytics:v.analytics,hasBrowser:v.browser,hasVectors:D,hasFlags:$,hasHyperdrive:v.hyperdrive,hasImages:v.images,hasKv:v.kv,hasNotify:L,hasPayments:v.payments,hasPipelines:v.pipelines,hasR2sql:v.r2sql,hasX402:v.x402,identity:r,queues:u,schema:o,storageRuleBuckets:h.rules.map(P=>P.bucket),useUmbrella:te,workflows:c}),storageRulesMetadata:h,usesSandbox:I.usesSandboxBrowser||I.usesSandboxContainer||I.usesSandboxFs,useUmbrella:te,workflows:c}},ts=new Set(["delete","get","head","options","patch","post","put"]),_r=new Set(["handler","stream"]),zr=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,xt=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),$r=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ts.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()}},Ur=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)||ts.has(n.getName()))break;s=n.getExpression()}return $r(s)},Br=e=>{for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression))if(xt.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&xt.has(s.getText()))return!0}return!1},qr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||!_r.has(n.getName()))return;const o=Ur(s);if(!o||!zr.test(o.path))return;const r=s.getArguments()[0],a=r!==void 0&&(i.isArrowFunction(r)||i.isFunctionExpression(r))&&Br(r);return{exportName:e.getName(),file:t,method:o.method,path:o.path,usesGuard:a}},jr=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=qr(o,t);r&&s.push(r)}return s},Vr=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...jr(o,x(t,n)))}return s},Wr=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",Hr=(e,t)=>{if(!Wr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!k(s)||U(s)))return{exportName:S(e),file:t,line:e.getStartLineNumber()}},Gr=(e,t)=>F(e,t,Hr),Yr=new Set(["generateText","streamText"]),Qr=new Set(["messages","prompt","system"]),Xr=[{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"]}],Zr=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const o of Xr)if(o.methods.has(s)&&o.prefixes.some(r=>n===r||n.startsWith(`${r}.`)))return`${n}.${s}`},Jr=e=>{for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=Zr(t);if(s!==void 0)return s}},eo=e=>{const t=new Set,s=e.getFirstAncestor(r=>i.isArrowFunction(r)||i.isFunctionExpression(r)||i.isFunctionDeclaration(r)),[n]=s?.getParameters()??[],o=n?.getNameNode();if(o===void 0||!i.isObjectBindingPattern(o))return t;for(const r of o.getElements()){const a=Q(r),c=r.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const u of c.getElements())t.add(u.getName())}return t},to=e=>{if(an(e))return!0;const t=eo(e);return t.size===0?!1:e.getDescendantsOfKind(l.Identifier).some(s=>t.has(s.getText()))},so=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!Qr.has(E(t)))continue;const s=t.getInitializer();if(s!==void 0&&to(s))return!0}return!1},no=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=A(n.getExpression());if(o===void 0||!Yr.has(o))continue;const[r]=n.getArguments();if(r===void 0||!i.isObjectLiteralExpression(r))continue;let a;for(const c of r.getDescendantsOfKind(l.CallExpression))if(A(c.getExpression())==="tool"&&(a=Jr(c),a!==void 0))break;a!==void 0&&s.push({exportName:S(n),file:t,line:n.getStartLineNumber(),method:o,sideEffect:a,userInputDerived:so(r)})}return s},ro=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...no(o,x(t,n)))}return s},oo=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},io=(e,t)=>{if(!oo(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!k(s)))return{exportName:S(e),file:t,line:e.getStartLineNumber()}},ao=(e,t)=>F(e,t,io),Ke=(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||Ke(n,t)})}finally{t.delete(e)}},co=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=C(t,"args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer(),o=n===void 0?void 0:ve(n);return o===void 0?{objects:[],opaque:!0}:{objects:[o],opaque:Ke(o)}},lo=e=>{const t=[];let s=!1,n=e;for(;i.isCallExpression(n);){const o=n.getExpression();if(!i.isPropertyAccessExpression(o))break;if(o.getName()==="input"){const r=n.getArguments()[0],a=r!==void 0&&i.isExpression(r)?ve(r):void 0;a===void 0?s=!0:(t.push(a),s||=Ke(a))}n=o.getExpression()}return{objects:t,opaque:s}},_e=(e,t)=>t?lo(t):co(e),ss=(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?[]:ss(n,t)}return i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)?[E(s)]:[]})}finally{t.delete(e)}},uo=e=>e.flatMap(t=>ss(t,new Set)),fo=new Set(["check","length","max"]),Oe=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!(!i.isPropertyAccessExpression(t)||t.getExpression().getText()!=="v"))return t.getName()},go=e=>[e,...e.getDescendants()].filter(t=>Oe(t)!==void 0),po=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(fo.has(s.getName()))return!0;t=n}},mo=e=>{const t=[],s=[];for(const n of e)for(const o of n.getProperties()){if(!i.isPropertyAssignment(o))continue;const r=o.getInitializer();if(!r)continue;const a=go(r),c=E(o);a.some(u=>Oe(u)==="any")?t.push(c):a.some(u=>Oe(u)==="string"&&!po(u))&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},ho=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=z(s);if(n?.visibility!=="public")return;const{objects:o}=_e(s,n.receiver),{anyArgs:r,unboundedStringArgs:a}=mo(o);if(!(r.length===0&&a.length===0))return{anyArgs:r,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},vo=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=ho(o,t);r&&s.push(r)}return s},xo=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...vo(o,x(t,n)))}return s},Ie=e=>e?.getKind()===l.TrueKeyword,Eo=e=>e?.getKind()===l.FalseKeyword,So=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,yo=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Ao=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&A(t.getExpression())==="scim"),bo=e=>e!==void 0&&i.isCallExpression(e)&&yo.has(A(e.getExpression())??""),No=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),Po=e=>{const t=b(e,"advanced"),s=b(e,"emailAndPassword"),n=b(e,"session");return{analyzable:!0,disableCsrfCheck:Ie(b(t,"disableCSRFCheck")),emailPasswordEnabled:Ie(b(s,"enabled")),requireEmailVerification:Ie(b(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Ao(b(e,"plugins"))&&bo(b(e,"database")),secureCookiesDisabled:Eo(b(t,"useSecureCookies")),sessionFreshAgeZero:So(b(n,"freshAge")),trustedOriginsWildcard:No(b(e,"trustedOrigins"))}},wo=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Io=(e,t)=>{if(A(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(r=>i.isSpreadAssignment(r)),o=s!==void 0&&i.isObjectLiteralExpression(s)&&!n?Po(s):wo();return{exportName:S(e),file:t,line:e.getStartLineNumber(),...o}},To=(e,t)=>Vs(e,t,Io),Co=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},Fo=(e,t,s)=>{const n=Co(e.getExpression(),s);if(n===void 0)return;const o=e.getArguments()[s.argIndex];if(!(!o||!k(o)||U(o))&&!(s.requireUnmodifiedReach===!0&&!cn(o)))return{exportName:S(e),file:t,line:e.getStartLineNumber(),method:n}},Oo=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression)){const r=Fo(o,t,s);r&&n.push(r)}return n},xe=(e,t,s)=>{const n=[];for(const o of p(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...Oo(r,x(t,o),s))}return n},Ro=new Set(["content","pdf","scrape","screenshot"]),Lo=(e,t)=>xe(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Ro}),Do=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),ko=new Set(["RateLimiter"]),Mo=new Set(["extend"]),Et="lunora",Ko=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],ns=e=>{const t=[],s=[];let n=!1;for(const o of e.getProperties()){if(i.isSpreadAssignment(o)){n=!0;continue}if(i.isPropertyAssignment(o)){const r=E(o);t.push(r),o.getInitializer()?.getKind()===l.TrueKeyword&&s.push(r);continue}(i.isShorthandPropertyAssignment(o)||i.isMethodDeclaration(o))&&t.push(E(o))}return{analyzable:!n,presentKeys:t,trueKeys:s}},Re=e=>e&&i.isObjectLiteralExpression(e)?ns(e):{analyzable:!1,presentKeys:[],trueKeys:[]},_o=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&qt(t.getBody());return s?ns(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},zo=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=A(n.getExpression());o!==void 0&&(Do.has(o)?s.push({callee:o,file:t,line:n.getStartLineNumber(),...Re(n.getArguments()[0])}):Mo.has(o)&&s.push({callee:o,file:t,line:n.getStartLineNumber(),..._o(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(l.NewExpression)){const o=A(n.getExpression());o===void 0||!ko.has(o)||s.push({callee:o,file:t,line:n.getStartLineNumber(),...Re(n.getArguments()[0])})}return s},$o=(e,t)=>{for(const s of Ko){const n=y(t,s);if(!w(n))continue;const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=[];for(const a of o.getDescendantsOfKind(l.CallExpression))A(a.getExpression())===Et&&r.push({callee:Et,file:s,line:a.getStartLineNumber(),...Re(a.getArguments()[0])});return r}return[]},Uo=(e,t)=>{const s=[];for(const{displayPath:n,filePath:o}of me(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);s.push(...zo(r,n))}return s.push(...$o(e,ae(t))),s},St="ctx.containers.",Bo=e=>{if(!e.startsWith(St))return!1;const t=e.slice(St.length);return t.length>0&&!t.includes(".")},qo=(e,t)=>xe(e,t,{argIndex:0,matchReceiver:Bo,methods:new Set(["get"])}),jo=new Set(["allow","deny","setAllowed"]),Vo=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=C(t,"enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},Wo=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!Vo(e)))return{detail:"enableInternet: true",exportName:S(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},Ho=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!jo.has(s.getName()))return;const n=s.getExpression();if(!(!i.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),exportName:S(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},Go=(e,t)=>Wo(e,t)??Ho(e,t),Yo=(e,t)=>F(e,t,Go),Qo=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Xo=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return Qo.has(s)?s:void 0},Zo=e=>{const t=[],s=[];for(const n of e.getProperties()){if(i.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(n)){const o=E(n);t.push(o);const r=n.getInitializer();r&&i.isStringLiteral(r)&&r.getLiteralText()===""&&s.push(o);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n)||i.isGetAccessorDeclaration(n))&&t.push(E(n))}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Jo=(e,t)=>{const s=[];for(const{displayPath:n,filePath:o}of me(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);for(const a of r.getDescendantsOfKind(l.CallExpression)){const c=Xo(a);if(c===void 0)continue;const u=a.getArguments()[0],d=u&&i.isObjectLiteralExpression(u)?Zo(u):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:d.analyzable,emptyKeys:d.emptyKeys,factory:c,file:n,line:a.getStartLineNumber(),presentKeys:d.presentKeys})}}return s},ei=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),ti=new Set(["dbRateLimit","rateLimit"]),si=e=>{const t=Vt(e);if(!t)return!1;const s=C(t,"failOpen");return s!==void 0&&i.isPropertyAssignment(s)&&s.getInitializer()?.getKind()===l.TrueKeyword},ni=(e,t)=>{const s=A(e.getExpression());if(s===void 0)return;const n=ei.get(s);if(n!==void 0)return{callee:s,exportName:S(e),failOpen:si(e.getArguments()[n]),file:t,limitName:ti.has(s)?jt(e):"",line:e.getStartLineNumber()}},ri=(e,t)=>F(e,t,ni),oi=new Set(["boolean","number","object","string"]),ii=e=>{const t=e.getName();if(!oi.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="flags"&&Fe(s.getExpression()))return t;const n=s.getExpression();if(s.getName()==="details"&&i.isPropertyAccessExpression(n)&&n.getName()==="flags"&&Fe(n.getExpression()))return t},ai=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=ii(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(i.isStringLiteral(n)||i.isNoSubstitutionTemplateLiteral(n)))return;const o=n.getLiteralValue();return o.length>0?{key:o,type:s}:void 0},ci=(e,t)=>{const s=new Map;for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getDescendantsOfKind(l.CallExpression)){const a=ai(r);a&&!s.has(a.key)&&s.set(a.key,a.type)}}return[...s.entries()].map(([n,o])=>({key:n,type:o})).toSorted((n,o)=>n.key.localeCompare(o.key))},li=e=>{const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const s=z(t);if(s?.kind!=="query")return;const n=Ws(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},yt=e=>{const t=e.getParent();return t&&i.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},ui=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!i.isIdentifier(t)||t.getText()!=="ctx")return;const s=yt(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=yt(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},di=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const o=ui(n);o!==void 0&&s.push({callee:o,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},fi=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=li(o);r&&s.push(...di(r,t))}return s},gi=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...fi(o,x(t,n)))}return s},pi=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Fe(t.getExpression())},mi=e=>{if(e?.getKind()===l.TrueKeyword)return!0;if(e?.getKind()===l.FalseKeyword)return!1},hi=(e,t)=>{if(!pi(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const o=s.getLiteralValue(),r=mi(n);if(!(o.length===0||r===void 0))return{defaultValue:r,exportName:S(e),file:t,key:o,line:e.getStartLineNumber()}},vi=(e,t)=>F(e,t,hi),xi=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 o=n.getTypeAtLocation(e),r=o.getText(e);if(!r||r==="any"||r==="never"||pn(r))return;const a=e.getSourceFile().getFilePath();if(mn(o,e,a)){const c=hn(o,e,a,0,new Set);return c===void 0&&vn(r),c}return r},Ei=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Si=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},yi=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression))Ei(a)&&s.push({file:r,indexName:Si(a),line:a.getStartLineNumber()})}return s},Z=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,rs=e=>{const t=e.getArguments()[0],s=Z(t);if(s!==void 0)return s;if(t===void 0||!i.isObjectLiteralExpression(t))return;const n=C(t,"handler");return n!==void 0&&i.isPropertyAssignment(n)?Z(n.getInitializer()):void 0},Ai=new Set(["delete","get","head","options","patch","post","put"]),bi=new Set(["handler","stream"]),Ni=new Set(["runAction","runMutation"]),Pi=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),J=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,os=(e,t)=>{if(!(e===void 0||!i.isObjectBindingPattern(e))){for(const s of e.getElements())if(Q(s)===t){const o=s.getNameNode();return i.isIdentifier(o)?o.getText():void 0}}},At=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?i.isIdentifier(s)?s.getText():void 0:os(s,"ctx")},bt=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&i.isIdentifier(s)?s.getText():void 0:os(s,"request")},Nt=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);i.isCallExpression(s)&&n.unshift(s);for(const o of n){const r=o.getExpression();if(!i.isPropertyAccessExpression(r))continue;const a=r.getName(),c=r.getExpression();if(Ni.has(a)&&J(c,t))return a;if(Pi.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&J(c.getExpression(),t))return`db.${a}`}},Pt=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(l.PropertyAccessExpression))if(n.getName()==="auth"&&J(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(l.VariableDeclaration)){const o=n.getNameNode();if(!(!i.isObjectBindingPattern(o)||!J(n.getInitializer(),t))){for(const r of o.getElements())if(Q(r)==="auth")return!0}}return!1},wi=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,Ii=(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"&&J(n.getExpression(),t)},Ti=e=>[...i.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(l.StringLiteral).map(t=>t.getLiteralText())],is=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:Ti(s)},Ci=(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 o=n.getParent();if(!i.isCallExpression(o))return[];const r=o.getExpression();if(!i.isPropertyAccessExpression(r))return[];const a=r.getExpression();return i.isIdentifier(a)?is(t,a.getText()):[]}return[]},Fi=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=is(s,t.getText());return n.length>0?n:Ci(t,s)},wt=(e,t)=>{if(t===void 0)return!1;const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);return i.isCallExpression(s)&&n.unshift(s),n.some(o=>Ii(o,t)&&Fi(o).some(r=>wi.test(r)))},Oi=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!bi.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))return;const o=n.getName();if(Ai.has(o)){const r=n.getExpression();return i.isIdentifier(r)&&r.getText()==="httpRoute"?o.toUpperCase():void 0}s=n.getExpression()}},Ri=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=Z(e.getArguments()[0]),u=c&&At(c,!0);if(!c||u===void 0||wt(c,bt(c,!0)))return;const d=Nt(c,u);return d===void 0?void 0:{exportName:S(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:Pt(c,u),sideEffect:d}}const n=Oi(e);if(n===void 0)return;const o=Z(e.getArguments()[0]),r=o&&At(o,!1);if(!o||r===void 0||wt(o,bt(o,!1)))return;const a=Nt(o,r);return a===void 0?void 0:{exportName:S(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:Pt(o,r),sideEffect:a}},Li=(e,t)=>F(e,t,Ri),Di=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),ki=new Set(["append","set"]),as=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",It=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(l.CallExpression)]:e.getDescendantsOfKind(l.CallExpression)).some(n=>Di.has(A(n.getExpression())??"")&&un(n,t)),Mi=(e,t)=>{if(It(e,t))return!0;const s=he(e);return s!==void 0&&It(s,t)},Le=(e,t)=>ln(e,t)&&!Mi(e,t),Ki=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=he(e);return t!==void 0&&i.isNewExpression(t)&&A(t.getExpression())==="Headers"},de=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=he(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},ze=(e,t,s)=>{for(const n of e.getProperties())if(i.isPropertyAssignment(n)){const o=n.getInitializer();o!==void 0&&Le(o,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:as(n.getNameNode()),line:o.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(n)){const o=n.getNameNode();Le(o,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:E(n),line:o.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(n)){const o=de(n.getExpression());o!==void 0&&ze(o,t,s)}},cs=(e,t)=>{const s=de(e);if(s===void 0)return;const n=C(s,"headers");if(n===void 0||!i.isPropertyAssignment(n))return;const o=de(n.getInitializer());o!==void 0&&ze(o,"response-init",t)},_i=(e,t)=>{const s=A(e.getExpression());if(s==="Response")cs(e.getArguments()[1],t);else if(s==="Headers"){const n=de(e.getArguments()[0]);n!==void 0&&ze(n,"headers-ctor",t)}},zi=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName(),o=s.getExpression();if(n==="json"&&i.isIdentifier(o)&&o.getText()==="Response"){cs(e.getArguments()[1],t);return}if(ki.has(n)&&Ki(o)){const r=e.getArguments()[1];r!==void 0&&Le(r,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:as(e.getArguments()[0]),line:r.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},$i=(e,t)=>{for(const s of e.getDescendantsOfKind(l.NewExpression))_i(s,t);for(const s of e.getDescendantsOfKind(l.CallExpression))zi(s,t)},Ui=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=Z(e.getArguments()[0]);if(n===void 0)return[];const o=n.getParameters()[1];if(o===void 0)return[];const r=o.getNameNode();if(!i.isIdentifier(r))return[];const a=[];return $i(n,{exportName:S(e),relativePath:t,requestName:r.getText(),rows:a}),a},Bi=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression))s.push(...Ui(n,t));return s},qi=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Bi(o,x(t,n)))}return s},ji=new Set(["auth","context.auth","ctx.auth"]),Vi="userId",Wi=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(E(s))}return t},Hi=(e,t)=>{const s=y(t,Jt);if(!w(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const o of n.getDescendantsOfKind(l.CallExpression)){if(A(o.getExpression())!=="defineIdentity")continue;const[r]=o.getArguments();return r&&i.isObjectLiteralExpression(r)?Wi(r):void 0}},Tt=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return ji.has(e.getExpression().getText())?e:void 0},Gi=e=>{if(i.isPropertyAccessExpression(e)&&Tt(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&Tt(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},Yi=(e,t,s)=>{const n=[];for(const o of e.getDescendants()){const r=Gi(o);r!==void 0&&n.push({declared:r===Vi||s.has(r),exportName:S(o),file:t,key:r,line:o.getStartLineNumber()})}return n},Qi=(e,t)=>{const s=Hi(e,t);if(s===void 0)return[];const n=[];for(const o of p(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...Yi(r,x(t,o),s))}return n},Xi=(e,t)=>{if(A(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=b(s,"key");if(!(!n||!k(n)||U(n)))return{exportName:S(e),file:t,line:e.getStartLineNumber()}},Zi=(e,t)=>F(e,t,Xi),Ji=e=>{if(i.isComputedPropertyName(e)){const t=e.getExpression();return i.isStringLiteral(t)||i.isNoSubstitutionTemplateLiteral(t)?t.getLiteralValue():void 0}return i.isStringLiteral(e)?e.getLiteralValue():e.getText()},ea=e=>e.getProperties().some(t=>{if(i.isSpreadAssignment(t))return!0;const s=Ji(t.getNameNode());return s===void 0||s==="namespace"}),ta=(e,t)=>{for(const{filePath:s}of me(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const o of n.getDescendantsOfKind(l.CallExpression)){const r=o.getExpression(),[a]=o.getArguments();if(!(!i.isPropertyAccessExpression(r)||r.getName()!=="auth"||a===void 0)&&(!i.isObjectLiteralExpression(a)||ea(a)))return o}}},sa="https://lunora.sh/docs/concepts/data-residency#pinning-auth-and-voice",na=(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 (${sa}). 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})},ra=new Set(["delete","get","getRaw","getWithMetadata","put"]),oa=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return xe(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.kv"||r.startsWith("ctx.kv."),methods:ra}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},ia=new Set(["queue","send"]),Ct=new Set(["bcc","cc","to"]),aa=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!ia.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},ca=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return Ct.has(E(t))&&k(n)&&!U(n)}if(!i.isPropertyAssignment(t)||!Ct.has(E(t)))return!1;const s=t.getInitializer();return s!==void 0&&k(s)&&!U(s)}):!1,la=(e,t)=>{const s=aa(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!ca(n)))return{exportName:S(e),file:t,line:e.getStartLineNumber(),method:s}},ua=(e,t)=>F(e,t,la),da=e=>i.isPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?i.isComputedPropertyName(e.getNameNode()):!1,fa=e=>i.isPropertyAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?da(e):!0,ls=(e,t=!1)=>{for(const s of e.getProperties()){if(fa(s))return!0;if(t)continue;if(!i.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!i.isObjectLiteralExpression(n)||ls(n,!0))return!0}return!1},ga=(e,t)=>{for(const s of p(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:o}of Xt(n))for(const r of Me(o)){const a=r.getArguments()[0];if(a!==void 0&&(!i.isObjectLiteralExpression(a)||ls(a)))return!0}}return!1},pa=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const o=ue(n);if(o===void 0||!i.isPropertyAssignment(n))continue;const r=n.getInitializer();if(!(!r||!i.isObjectLiteralExpression(r)))for(const a of r.getProperties()){const c=ue(a);c!==void 0&&s.push({column:c,strategy:Qt(a),table:o})}}return s},ma=(e,t)=>{const s=new Map;for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:r}of Xt(o))for(const a of Me(r))for(const c of pa(a)){const u=`${c.table}\0${c.column}`;s.has(u)||s.set(u,c)}}return{columns:[...s.values()]}},ha=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!i.isObjectLiteralExpression(n))return[];const o=[];for(const r of n.getProperties()){const a=ue(r);if(a===void 0||!i.isPropertyAssignment(r))continue;const c=r.getInitializer();if(!(!c||!i.isObjectLiteralExpression(c)))for(const u of c.getProperties()){const d=ue(u);if(d===void 0)continue;const m=Qt(u);m!=="custom"&&o.push({column:d,exportName:t,file:s,line:u.getStartLineNumber(),strategy:m,table:a})}}return o},va=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?z(s):void 0;return n?.receiver?Me(n.receiver).flatMap(o=>ha(o,e.getName(),t)):[]},xa=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...va(c,r))}return s},Ea=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return _(s)},Sa=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=C(t,"server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},ya=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==l.CallExpression)return;const s=t;return In(s.getExpression())?s:void 0},Aa=e=>{const t=ya(e),s=t===void 0?void 0:Sa(t);if(s===void 0)return[];const n=e.getNameNode(),o=i.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(l.CallExpression).filter(r=>Ea(r)).map(r=>({exportName:o,file:"lunora/mutators.ts",line:r.getStartLineNumber()}))},ba=e=>e.getVariableDeclarations().flatMap(t=>Aa(t)),Na=(e,t)=>{const s=y(t,wn);if(!w(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return ba(n)},Pa=new Set(["delete","get","patch"]),wa=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Ia=new Set(["auth","identity","session","user"]),Ta=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),Ca=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!_(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},Fa=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},Oa=(e,t)=>e.getDescendantsOfKind(l.Identifier).some(s=>s.getText()===t),Ra=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(l.ThrowStatement).length>0||e.getDescendantsOfKind(l.ReturnStatement).length>0,La=(e,t)=>e.getDescendantsOfKind(l.IfStatement).some(s=>Oa(s.getExpression(),t)&&Ra(s.getThenStatement())),Da=(e,t)=>{for(const s of e.getDescendantsOfKind(l.CallExpression)){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))continue;const o=n.getName();if(!Pa.has(o))continue;const r=n.getExpression();if(!(_(r)||i.isPropertyAccessExpression(r)&&_(r.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&i.isIdentifier(c)&&c.getText()===t)return o}},ka=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t)||i.isParenthesizedExpression(t)||i.isAsExpression(t)||i.isAwaitExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t.getText():void 0},Ma=e=>e.getDescendantsOfKind(l.CallExpression).some(t=>t.getArguments().some(s=>ka(s)==="ctx")),Ka=e=>e.getDescendantsOfKind(l.BinaryExpression).some(t=>Ta.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),_a=e=>{for(const t of e.getDescendantsOfKind(l.Identifier))if(wa.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&Ia.has(t.getName()))return!0}return Ma(e)||Ka(e)},za=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=z(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const o=rs(s);if(o===void 0)return[];const r=n.receiver!==void 0&&Ht(n.receiver,"use","rls"),a=_a(o),c=new Set,u=[];for(const d of o.getDescendantsOfKind(l.CallExpression)){const m=Ca(d);if(m===void 0)continue;const h=Fa(d);if(h===void 0||c.has(h)||!La(o,h))continue;const R=Da(o,h);R!==void 0&&(c.add(h),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:R,table:m,usesRls:r,visibility:n.visibility}))}return u},$a=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...za(c,r))}return s},Ua=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Ba=new Set(["insert","insertManyUnsafe","patch","replace"]),qa=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Ba.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="db")return;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="ctx"?t:void 0},ja=(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},Ft=(e,t)=>{if(i.isPropertyAccessExpression(e)){const s=e.getExpression();return i.isIdentifier(s)&&s.getText()==="args"&&e.getName()===t}if(i.isElementAccessExpression(e)){const s=e.getExpression(),n=e.getArgumentExpression();return i.isIdentifier(s)&&s.getText()==="args"&&n!==void 0&&i.isStringLiteral(n)&&n.getLiteralValue()===t}return!1},Va=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;for(const a of s.getDescendantsOfKind(l.BinaryExpression)){const c=a.getLeft();if(i.isIdentifier(c)&&c.getText()===t&&a.getOperatorToken().getText().endsWith("="))return}const n=e.getStart();let o,r=-1;for(const a of s.getDescendantsOfKind(l.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getParent();if(!i.isVariableDeclarationList(c)||c.getDeclarationKind()!==Ks.Const)continue;const u=a.getInitializer(),d=a.getStart();u!==void 0&&d<n&&d>r&&(o=u,r=d)}return o},Wa=(e,t)=>{if(Ft(e,t))return!0;const s=Va(e);return s!==void 0&&Ft(s,t)},Ha=(e,t,s,n,o)=>{const r=[];for(const a of e.getProperties()){let c,u;if(i.isPropertyAssignment(a)?(c=E(a),u=a.getInitializer()):i.isShorthandPropertyAssignment(a)&&(c=E(a),u=a.getNameNode()),!(c===void 0||u===void 0||!Ua.has(c))&&k(u)&&!U(u)){const d=S(s),m=o(d)===c&&Wa(u,c);r.push({exportName:d,field:c,file:n,line:s.getStartLineNumber(),method:t,...m&&{ownerScoped:!0}})}}return r},Ga=(e,t,s)=>{const n=qa(e.getExpression());if(n===void 0)return[];const o=e.getArguments()[1];return o?ja(o,n).flatMap(r=>Ha(r,n,e,t,s)):[]},Ya=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression))for(const r of Ga(o,t,a=>s(a).owner)){const{visibility:a}=s(r.exportName);n.push(a===void 0?r:{...r,visibility:a})}return n},Qa=(e,t,s=[],n=[])=>{const o=[],r=new Map;for(const a of s)r.set(`${a.filePath}:${a.exportName}`,{visibility:a.visibility});for(const a of n){const c=`${a.filePath}:${a.exportName}`;r.set(c,{...r.get(c),owner:a.owner})}for(const a of p(t)){const c=e.getSourceFile(a)??e.addSourceFileAtPath(a),u=x(t,a);o.push(...Ya(c,u,d=>r.get(`${u}:${d}`)??{}))}return o},Xa=["providerSubscriptionId","state"],Za=["providerEventId","processedAt"],Ot=(e,t)=>t.every(s=>s in e.shape),Ja=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&Ot(t,Xa)&&Ot(s,Za)},ec=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),tc=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,sc=e=>{const t=C(e,"webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?tc(t.getInitializer()):void 0},nc=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!ec.has(s))return;const[n]=e.getArguments(),o=n&&i.isObjectLiteralExpression(n)?sc(n):void 0;return{callee:s,exportName:S(e),file:t,line:e.getStartLineNumber(),...o===void 0?{}:{toleranceSeconds:o}}},rc=(e,t)=>F(e,t,nc),oc=new Set(["defineQueue","defineWorkflow"]),ic=new Set(["run","runAction","runMutation","runQuery"]),ac=new Set(["api","internal"]),cc=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},lc=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=C(t,"handler");if(s===void 0||!i.isPropertyAssignment(s))return;const n=s.getInitializer();if(n&&(i.isArrowFunction(n)||i.isFunctionExpression(n)))return n},us=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},ds=(e,t)=>e===t||e.startsWith(`${t}.`),fs=e=>{const t=e.getDescendantsOfKind(l.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},Rt=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)},gs=e=>{const t=e.getDescendantsOfKind(l.Identifier).filter(s=>Rt(s));return i.isIdentifier(e)&&Rt(e)&&t.push(e),t},uc=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(l.BindingElement).map(s=>s.getName())},dc=e=>{const t=us(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(l.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const o=n.getInitializer(),r=i.isVariableDeclarationList(o)?o.getDeclarations()[0]?.getNameNode():void 0;r&&i.isIdentifier(r)&&s.push(`${r.getText()}.body`)}return s},fc=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:dc(e),o=new Set,r=a=>fs(a).some(c=>n.some(u=>ds(c.getText(),u)))?!0:gs(a).some(c=>o.has(c.getText()));for(const a of e.getDescendantsOfKind(l.VariableDeclaration)){const c=a.getInitializer();if(c&&r(c))for(const u of uc(a))o.add(u)}return{names:o,prefixes:n}},gc=(e,t)=>fs(e).some(s=>t.prefixes.some(n=>ds(s.getText(),n)))?!0:gs(e).some(s=>t.names.has(s.getText())),pc=e=>{if(e===void 0||!i.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;i.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const n=t.at(-1);if(!(n===void 0||!i.isIdentifier(s)||!ac.has(s.getText())||t.length<2))return{exportName:n,file:t.slice(0,-1).join("/")}},mc=(e,t,s)=>{const n=us(e,0);if(n===void 0)return[];const o=fc(e,t,n),r=[];for(const a of e.getDescendantsOfKind(l.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!ic.has(c.getName())||c.getExpression().getText()!==n)continue;const u=a.getArguments()[1];if(!u||!gc(u,o))continue;const d=pc(a.getArguments()[0]);d!==void 0&&r.push({dispatchKind:t,file:s,handlerExport:S(a),line:a.getStartLineNumber(),targetExport:d.exportName,targetFile:d.file})}return r},hc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=cc(n);if(o===void 0||!oc.has(o))continue;const r=lc(n);r!==void 0&&s.push(...mc(r,o==="defineQueue"?"queue":"workflow",t))}return s},vc=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...hc(o,x(t,n)))}return s},Lt={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},Dt=new Set(["account","credential","member","passkey","session","user"]),xc=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),Ec=e=>{const s=xc(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return Dt.has(s)||Dt.has(n)},Sc=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},yc=(e,t)=>{const{objects:s,opaque:n}=_e(e,t);return uo(s).some(o=>Sc(o))?!0:n?void 0:!1},Ac=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!C(t,"captcha"),usesRateLimit:!!C(t,"rateLimit")}},bc=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},le={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Nc=e=>{const t=bc(e),s=t?A(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=Ac(t);return{...le,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in Lt?{...le,[Lt[s]]:!0}:le},Pc=e=>{const t={...le};let s=e;for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))break;const o=n.getName()==="use"?s.getArguments()[0]:void 0;if(o){const r=Nc(o);t.usesCaptcha||=r.usesCaptcha,t.usesEmailGate||=r.usesEmailGate,t.usesMask||=r.usesMask,t.usesRateLimit||=r.usesRateLimit,t.usesRls||=r.usesRls}s=n.getExpression()}return t},wc=new Set(["insert","insertMany","insertManyUnsafe","replace"]),Ic=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!wc.has(t.getName()))return!1;const s=t.getExpression();if(!_(s))return!1;const o=e.getArguments()[0];return!o||!(i.isStringLiteral(o)||i.isNoSubstitutionTemplateLiteral(o))?!1:Ec(o.getLiteralText())},Tc=new Set(["create","runAfter","runAt","send","sendBatch"]),Cc=new Set(["queues","scheduler","workflows"]),Fc=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Tc.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&Cc.has(s.getName())){const n=s.getExpression();if(i.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},Oc=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return _(s)},ps=new Set(["generateObject","generateText","streamObject","streamText"]),Rc=e=>{const t=A(e.getExpression());return t!==void 0&&ps.has(t)},Lc=e=>{const t=A(e.getExpression());if(t===void 0||!ps.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(n=>i.isSpreadAssignment(n))?!1:!C(s,"maxOutputTokens")},Dc=new Set(["log","span","trace"]),kc=new Set(["ai"]),Mc=new Set(["email","mail"]),Kc=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),Te=(e,t)=>e.getDescendantsOfKind(l.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="ctx"}),_c=new Set([l.ArrowFunction,l.FunctionDeclaration,l.FunctionExpression,l.GetAccessor,l.MethodDeclaration,l.SetAccessor]),zc=new Set(["every","filter","flatMap","forEach","map","some"]),$c=new Set(["all","allSettled","race"]),Uc=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(zc.has(n))return t;const o=s.getExpression();if(i.isIdentifier(o)&&o.getText()==="Promise"&&$c.has(n))return t},Bc=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(_c.has(t.getKind())){const s=Uc(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},qc=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}},jc=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}},Vc=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression)){if(!Kc.has(n.getName()))continue;const o=n.getExpression();if(!i.isIdentifier(o)||o.getText()!=="ctx")continue;const r=jc(n);r&&(t=!0,!Bc(r)&&!qc(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},Wc=e=>e.getDescendantsOfKind(l.ThrowStatement).some(t=>{const s=t.getExpression();if(!i.isNewExpression(s))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="Error"}),kt="lunora-advisor-exempt",Hc=/^[\s*/]+/u,Gc=/[\w-]/u,Yc=e=>{const s=(e.getFirstAncestorByKind(l.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
|
|
5
|
+
Install them with your package manager, then re-run codegen.`)},ur="env.ts",dr=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return pe(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},fr=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&pe(n.getModuleSpecifierValue())}return!1},gr=e=>{if(i.isIdentifier(e))return dr(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&fr(t)}return!1},pr=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!gr(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw ee(r,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},mr=(e,t)=>{const s=E(t,ur);if(!w(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=pr(n);if(o.length!==0){if(o.length>1)throw ee(n,`lunora/env.ts declares ${o.length.toString()} defineEnv() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},mt="ctx",Zt=e=>{const t=new Set,s=new Set([mt]),n=r=>{if(i.isObjectBindingPattern(r))for(const a of r.getElements()){const c=Q(a);c&&t.add(c)}};for(const r of e.getDescendantsOfKind(l.BindingElement)){if(Q(r)!==mt)continue;const a=r.getNameNode();i.isIdentifier(a)?s.add(a.getText()):n(a)}const o=r=>i.isIdentifier(r)&&s.has(r.getText());for(const r of e.getDescendantsOfKind(l.PropertyAccessExpression))o(r.getExpression())&&t.add(r.getName());for(const r of e.getDescendantsOfKind(l.VariableDeclaration)){const a=r.getInitializer();a!==void 0&&o(a)&&n(r.getNameNode())}return t},hr=(e,t)=>{const s=Object.fromEntries(ce.map(n=>[n.key,!1]));for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=new Set(o.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=Zt(o);for(const c of ce)if(!s[c.key]){if(r.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(ce.every(c=>s[c.key]))break}return s},Jt="identity.ts",vr=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return pe(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},xr=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&pe(n.getModuleSpecifierValue())}return!1},Er=e=>{if(i.isIdentifier(e))return vr(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&xr(t)}return!1},Sr=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!Er(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw ee(r,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},yr=(e,t)=>{const s=E(t,Jt);if(!w(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=Sr(n);if(o.length!==0){if(o.length>1)throw ee(n,`lunora/identity.ts declares ${o.length.toString()} defineIdentity() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},Ar=new Set(["allowedHosts","deniedHosts","interceptHttps"]),br=(e,t)=>{const s=X(t);if(s===void 0||!i.isIdentifier(s))return s;const n=s.getText();return X(e.getDescendantsOfKind(l.VariableDeclaration).find(o=>o.getName()===n)?.getInitializer())},Nr=(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=X(s.getInitializer())?.getText();return n!=="false"&&n!=="undefined"}),Pr=new Set(["durable"]),wr=new Set(["rollback"]),Ir=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)?t.getName():t.getText()},Tr=new Map([["defineContainer",{keys:Ar,signal:"containerEgressPolicy"}],["defineStep",{keys:wr,signal:"workflowRollback"}],["stream",{keys:Pr,signal:"durableStreams"}]]),Cr=(e,t)=>{const s=Tr.get(Ir(t));if(s!==void 0)return t.getArguments().some(n=>Nr(br(e,n),s.keys))?s.signal:void 0},Fr=(e,t)=>{const s={containerEgressPolicy:!1,durableStreams:!1,secrets:!1,workflowRollback:!1};for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.secrets||(s.secrets=Zt(o).has("secrets"));for(const r of o.getDescendantsOfKind(l.CallExpression)){const a=Cr(o,r);a!==void 0&&(s[a]=!0)}if(Object.values(s).every(Boolean))break}return s},Or="createWorker",Rr="extend",ht=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralValue():void 0,vt=e=>{const t=[],s=ht(b(e,"backupCron"));s!==void 0&&t.push(s);const n=b(e,"crons");if(n===void 0||!i.isObjectLiteralExpression(n))return t;for(const o of n.getProperties()){if(!i.isPropertyAssignment(o)&&!i.isMethodDeclaration(o))continue;const r=ht(o.getNameNode());r!==void 0&&t.push(r)}return t},Lr=e=>{const t=A(e.getExpression()),[s]=e.getArguments();if(s===void 0)return[];if(t===Or)return i.isObjectLiteralExpression(s)?vt(s):[];if(t!==Rr||!(i.isArrowFunction(s)||i.isFunctionExpression(s)))return[];const n=qt(s.getBody());return n===void 0?[]:vt(n)},Dr=(e,t)=>{const s=[];for(const{filePath:n}of me(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getDescendantsOfKind(l.CallExpression))s.push(...Lr(r))}return[...new Set(s)]},es=e=>{if(e.kind==="id")return e.tableName;if(!(e.kind!=="array"&&e.kind!=="optional"))return e.inner===void 0?void 0:es(e.inner)},kr=e=>{const t=new Set(e.tables.map(s=>s.name));return e.tables.some(s=>Object.values(s.shape).some(n=>{const o=es(n);return o!==void 0&&t.has(o)}))},Mr=(e,t)=>{const s=new Map,n=new Map,o=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.bindingName,`workflow "${r.exportName}"`),o.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const a=s.get(r.name);if(a!==void 0)throw new K("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${a} and agent "${r.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=n.get(r.bindingName);if(c!==void 0)throw new K("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${r.bindingName}": produced by both ${c} and agent "${r.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const u=o.get(r.className);if(u!==void 0)throw new K("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${u} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},Kr=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:o}=e,r=yr(s,t),a=mr(s,t),c=Js(s,t),u=Ys(s,t),d=Bs(s,t);Mr(c,d);const m=qs(s,t),h=Xs(s,t),R=js(s,t,c,d),M=Dr(s,t),g=Fr(s,t),I=Qs(s,t),N=hr(s,t);N.browser=N.browser||I.usesSandboxBrowser;const O=en(N,Gt(n,e.target),{agents:d.length>0,commitOrderedTables:o.tables.some(P=>P.commitOrdered===!0),cronTriggers:R.length>0,crossShardFanout:o.tables.some(P=>typeof P.shardMode=="object"),containerEgressPolicy:g.containerEgressPolicy,durableStreams:g.durableStreams,globalTables:o.tables.some(P=>P.shardMode==="global"),queues:u.length>0,relationGraph:kr(o),secrets:g.secrets,vectorStore:o.vectorIndexes.length>0,workerLoaders:I.usesSandboxLoader,workflowRollback:g.workflowRollback}),v=O.usage,D=O.signals.vectorStore!==!1,B=Gs(n),H=B??new Set,te=H.has("lunorash");lr(o,B,{hasVectors:D,scheduler:v.scheduler||R.length>0,storage:v.storage||h.rules.length>0||Object.keys(Yt(o)).length>0,usage:v});const $=w(E(t,"flags.ts")),L=w(E(t,"notify.ts"));return{agents:d,containers:m,crons:R,dataModelContent:on(o),declaredDependencies:B,dependencies:H,entryCronTriggers:M,env:a,featureUsage:v,hasFlags:$,hasNotify:L,identity:r,platformGate:{...O,diagnostics:[...tn(n,e.target),...O.diagnostics]},queues:u,serverContent:rn({agents:d,containers:m,env:a,hasAccessFacade:v.access,hasAi:v.ai,hasAnalytics:v.analytics,hasBrowser:v.browser,hasVectors:D,hasFlags:$,hasHyperdrive:v.hyperdrive,hasImages:v.images,hasKv:v.kv,hasNotify:L,hasPayments:v.payments,hasPipelines:v.pipelines,hasR2sql:v.r2sql,hasX402:v.x402,identity:r,queues:u,schema:o,storageRuleBuckets:h.rules.map(P=>P.bucket),useUmbrella:te,workflows:c}),storageRulesMetadata:h,usesSandbox:I.usesSandboxBrowser||I.usesSandboxContainer||I.usesSandboxFs,useUmbrella:te,workflows:c}},ts=new Set(["delete","get","head","options","patch","post","put"]),_r=new Set(["handler","stream"]),zr=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,xt=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),$r=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ts.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()}},Ur=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)||ts.has(n.getName()))break;s=n.getExpression()}return $r(s)},Br=e=>{for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression))if(xt.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&xt.has(s.getText()))return!0}return!1},qr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||!_r.has(n.getName()))return;const o=Ur(s);if(!o||!zr.test(o.path))return;const r=s.getArguments()[0],a=r!==void 0&&(i.isArrowFunction(r)||i.isFunctionExpression(r))&&Br(r);return{exportName:e.getName(),file:t,method:o.method,path:o.path,usesGuard:a}},jr=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=qr(o,t);r&&s.push(r)}return s},Vr=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...jr(o,x(t,n)))}return s},Wr=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",Hr=(e,t)=>{if(!Wr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!k(s)||U(s)))return{exportName:y(e),file:t,line:e.getStartLineNumber()}},Gr=(e,t)=>F(e,t,Hr),Yr=new Set(["generateText","streamText"]),Qr=new Set(["messages","prompt","system"]),Xr=[{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"]}],Zr=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const o of Xr)if(o.methods.has(s)&&o.prefixes.some(r=>n===r||n.startsWith(`${r}.`)))return`${n}.${s}`},Jr=e=>{for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=Zr(t);if(s!==void 0)return s}},eo=e=>{const t=new Set,s=e.getFirstAncestor(r=>i.isArrowFunction(r)||i.isFunctionExpression(r)||i.isFunctionDeclaration(r)),[n]=s?.getParameters()??[],o=n?.getNameNode();if(o===void 0||!i.isObjectBindingPattern(o))return t;for(const r of o.getElements()){const a=Q(r),c=r.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const u of c.getElements())t.add(u.getName())}return t},to=e=>{if(an(e))return!0;const t=eo(e);return t.size===0?!1:e.getDescendantsOfKind(l.Identifier).some(s=>t.has(s.getText()))},so=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!Qr.has(S(t)))continue;const s=t.getInitializer();if(s!==void 0&&to(s))return!0}return!1},no=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=A(n.getExpression());if(o===void 0||!Yr.has(o))continue;const[r]=n.getArguments();if(r===void 0||!i.isObjectLiteralExpression(r))continue;let a;for(const c of r.getDescendantsOfKind(l.CallExpression))if(A(c.getExpression())==="tool"&&(a=Jr(c),a!==void 0))break;a!==void 0&&s.push({exportName:y(n),file:t,line:n.getStartLineNumber(),method:o,sideEffect:a,userInputDerived:so(r)})}return s},ro=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...no(o,x(t,n)))}return s},oo=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},io=(e,t)=>{if(!oo(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!k(s)))return{exportName:y(e),file:t,line:e.getStartLineNumber()}},ao=(e,t)=>F(e,t,io),Ke=(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||Ke(n,t)})}finally{t.delete(e)}},co=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=C(t,"args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer(),o=n===void 0?void 0:ve(n);return o===void 0?{objects:[],opaque:!0}:{objects:[o],opaque:Ke(o)}},lo=e=>{const t=[];let s=!1,n=e;for(;i.isCallExpression(n);){const o=n.getExpression();if(!i.isPropertyAccessExpression(o))break;if(o.getName()==="input"){const r=n.getArguments()[0],a=r!==void 0&&i.isExpression(r)?ve(r):void 0;a===void 0?s=!0:(t.push(a),s||=Ke(a))}n=o.getExpression()}return{objects:t,opaque:s}},_e=(e,t)=>t?lo(t):co(e),ss=(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?[]:ss(n,t)}return i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)?[S(s)]:[]})}finally{t.delete(e)}},uo=e=>e.flatMap(t=>ss(t,new Set)),fo=new Set(["check","length","max"]),Oe=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!(!i.isPropertyAccessExpression(t)||t.getExpression().getText()!=="v"))return t.getName()},go=e=>[e,...e.getDescendants()].filter(t=>Oe(t)!==void 0),po=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(fo.has(s.getName()))return!0;t=n}},mo=e=>{const t=[],s=[];for(const n of e)for(const o of n.getProperties()){if(!i.isPropertyAssignment(o))continue;const r=o.getInitializer();if(!r)continue;const a=go(r),c=S(o);a.some(u=>Oe(u)==="any")?t.push(c):a.some(u=>Oe(u)==="string"&&!po(u))&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},ho=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=z(s);if(n?.visibility!=="public")return;const{objects:o}=_e(s,n.receiver),{anyArgs:r,unboundedStringArgs:a}=mo(o);if(!(r.length===0&&a.length===0))return{anyArgs:r,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},vo=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=ho(o,t);r&&s.push(r)}return s},xo=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...vo(o,x(t,n)))}return s},Ie=e=>e?.getKind()===l.TrueKeyword,Eo=e=>e?.getKind()===l.FalseKeyword,So=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,yo=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Ao=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&A(t.getExpression())==="scim"),bo=e=>e!==void 0&&i.isCallExpression(e)&&yo.has(A(e.getExpression())??""),No=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),Po=e=>{const t=b(e,"advanced"),s=b(e,"emailAndPassword"),n=b(e,"session");return{analyzable:!0,disableCsrfCheck:Ie(b(t,"disableCSRFCheck")),emailPasswordEnabled:Ie(b(s,"enabled")),requireEmailVerification:Ie(b(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Ao(b(e,"plugins"))&&bo(b(e,"database")),secureCookiesDisabled:Eo(b(t,"useSecureCookies")),sessionFreshAgeZero:So(b(n,"freshAge")),trustedOriginsWildcard:No(b(e,"trustedOrigins"))}},wo=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Io=(e,t)=>{if(A(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(r=>i.isSpreadAssignment(r)),o=s!==void 0&&i.isObjectLiteralExpression(s)&&!n?Po(s):wo();return{exportName:y(e),file:t,line:e.getStartLineNumber(),...o}},To=(e,t)=>Vs(e,t,Io),Co=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},Fo=(e,t,s)=>{const n=Co(e.getExpression(),s);if(n===void 0)return;const o=e.getArguments()[s.argIndex];if(!(!o||!k(o)||U(o))&&!(s.requireUnmodifiedReach===!0&&!cn(o)))return{exportName:y(e),file:t,line:e.getStartLineNumber(),method:n}},Oo=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression)){const r=Fo(o,t,s);r&&n.push(r)}return n},xe=(e,t,s)=>{const n=[];for(const o of p(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...Oo(r,x(t,o),s))}return n},Ro=new Set(["content","pdf","scrape","screenshot"]),Lo=(e,t)=>xe(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Ro}),Do=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),ko=new Set(["RateLimiter"]),Mo=new Set(["extend"]),Et="lunora",Ko=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],ns=e=>{const t=[],s=[];let n=!1;for(const o of e.getProperties()){if(i.isSpreadAssignment(o)){n=!0;continue}if(i.isPropertyAssignment(o)){const r=S(o);t.push(r),o.getInitializer()?.getKind()===l.TrueKeyword&&s.push(r);continue}(i.isShorthandPropertyAssignment(o)||i.isMethodDeclaration(o))&&t.push(S(o))}return{analyzable:!n,presentKeys:t,trueKeys:s}},Re=e=>e&&i.isObjectLiteralExpression(e)?ns(e):{analyzable:!1,presentKeys:[],trueKeys:[]},_o=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&qt(t.getBody());return s?ns(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},zo=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=A(n.getExpression());o!==void 0&&(Do.has(o)?s.push({callee:o,file:t,line:n.getStartLineNumber(),...Re(n.getArguments()[0])}):Mo.has(o)&&s.push({callee:o,file:t,line:n.getStartLineNumber(),..._o(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(l.NewExpression)){const o=A(n.getExpression());o===void 0||!ko.has(o)||s.push({callee:o,file:t,line:n.getStartLineNumber(),...Re(n.getArguments()[0])})}return s},$o=(e,t)=>{for(const s of Ko){const n=E(t,s);if(!w(n))continue;const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=[];for(const a of o.getDescendantsOfKind(l.CallExpression))A(a.getExpression())===Et&&r.push({callee:Et,file:s,line:a.getStartLineNumber(),...Re(a.getArguments()[0])});return r}return[]},Uo=(e,t)=>{const s=[];for(const{displayPath:n,filePath:o}of me(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);s.push(...zo(r,n))}return s.push(...$o(e,ae(t))),s},St="ctx.containers.",Bo=e=>{if(!e.startsWith(St))return!1;const t=e.slice(St.length);return t.length>0&&!t.includes(".")},qo=(e,t)=>xe(e,t,{argIndex:0,matchReceiver:Bo,methods:new Set(["get"])}),jo=new Set(["allow","deny","setAllowed"]),Vo=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=C(t,"enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},Wo=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!Vo(e)))return{detail:"enableInternet: true",exportName:y(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},Ho=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!jo.has(s.getName()))return;const n=s.getExpression();if(!(!i.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),exportName:y(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},Go=(e,t)=>Wo(e,t)??Ho(e,t),Yo=(e,t)=>F(e,t,Go),Qo=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Xo=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return Qo.has(s)?s:void 0},Zo=e=>{const t=[],s=[];for(const n of e.getProperties()){if(i.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(n)){const o=S(n);t.push(o);const r=n.getInitializer();r&&i.isStringLiteral(r)&&r.getLiteralText()===""&&s.push(o);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n)||i.isGetAccessorDeclaration(n))&&t.push(S(n))}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Jo=(e,t)=>{const s=[];for(const{displayPath:n,filePath:o}of me(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);for(const a of r.getDescendantsOfKind(l.CallExpression)){const c=Xo(a);if(c===void 0)continue;const u=a.getArguments()[0],d=u&&i.isObjectLiteralExpression(u)?Zo(u):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:d.analyzable,emptyKeys:d.emptyKeys,factory:c,file:n,line:a.getStartLineNumber(),presentKeys:d.presentKeys})}}return s},ei=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),ti=new Set(["dbRateLimit","rateLimit"]),si=e=>{const t=Vt(e);if(!t)return!1;const s=C(t,"failOpen");return s!==void 0&&i.isPropertyAssignment(s)&&s.getInitializer()?.getKind()===l.TrueKeyword},ni=(e,t)=>{const s=A(e.getExpression());if(s===void 0)return;const n=ei.get(s);if(n!==void 0)return{callee:s,exportName:y(e),failOpen:si(e.getArguments()[n]),file:t,limitName:ti.has(s)?jt(e):"",line:e.getStartLineNumber()}},ri=(e,t)=>F(e,t,ni),oi=new Set(["boolean","number","object","string"]),ii=e=>{const t=e.getName();if(!oi.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="flags"&&Fe(s.getExpression()))return t;const n=s.getExpression();if(s.getName()==="details"&&i.isPropertyAccessExpression(n)&&n.getName()==="flags"&&Fe(n.getExpression()))return t},ai=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=ii(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(i.isStringLiteral(n)||i.isNoSubstitutionTemplateLiteral(n)))return;const o=n.getLiteralValue();return o.length>0?{key:o,type:s}:void 0},ci=(e,t)=>{const s=new Map;for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getDescendantsOfKind(l.CallExpression)){const a=ai(r);a&&!s.has(a.key)&&s.set(a.key,a.type)}}return[...s.entries()].map(([n,o])=>({key:n,type:o})).toSorted((n,o)=>n.key.localeCompare(o.key))},li=e=>{const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const s=z(t);if(s?.kind!=="query")return;const n=Ws(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},yt=e=>{const t=e.getParent();return t&&i.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},ui=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!i.isIdentifier(t)||t.getText()!=="ctx")return;const s=yt(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=yt(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},di=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const o=ui(n);o!==void 0&&s.push({callee:o,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},fi=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=li(o);r&&s.push(...di(r,t))}return s},gi=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...fi(o,x(t,n)))}return s},pi=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Fe(t.getExpression())},mi=e=>{if(e?.getKind()===l.TrueKeyword)return!0;if(e?.getKind()===l.FalseKeyword)return!1},hi=(e,t)=>{if(!pi(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const o=s.getLiteralValue(),r=mi(n);if(!(o.length===0||r===void 0))return{defaultValue:r,exportName:y(e),file:t,key:o,line:e.getStartLineNumber()}},vi=(e,t)=>F(e,t,hi),xi=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 o=n.getTypeAtLocation(e),r=o.getText(e);if(!r||r==="any"||r==="never"||pn(r))return;const a=e.getSourceFile().getFilePath();if(mn(o,e,a)){const c=hn(o,e,a,0,new Set);return c===void 0&&vn(r),c}return r},Ei=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Si=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},yi=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression))Ei(a)&&s.push({file:r,indexName:Si(a),line:a.getStartLineNumber()})}return s},Z=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,rs=e=>{const t=e.getArguments()[0],s=Z(t);if(s!==void 0)return s;if(t===void 0||!i.isObjectLiteralExpression(t))return;const n=C(t,"handler");return n!==void 0&&i.isPropertyAssignment(n)?Z(n.getInitializer()):void 0},Ai=new Set(["delete","get","head","options","patch","post","put"]),bi=new Set(["handler","stream"]),Ni=new Set(["runAction","runMutation"]),Pi=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),J=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,os=(e,t)=>{if(!(e===void 0||!i.isObjectBindingPattern(e))){for(const s of e.getElements())if(Q(s)===t){const o=s.getNameNode();return i.isIdentifier(o)?o.getText():void 0}}},At=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?i.isIdentifier(s)?s.getText():void 0:os(s,"ctx")},bt=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&i.isIdentifier(s)?s.getText():void 0:os(s,"request")},Nt=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);i.isCallExpression(s)&&n.unshift(s);for(const o of n){const r=o.getExpression();if(!i.isPropertyAccessExpression(r))continue;const a=r.getName(),c=r.getExpression();if(Ni.has(a)&&J(c,t))return a;if(Pi.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&J(c.getExpression(),t))return`db.${a}`}},Pt=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(l.PropertyAccessExpression))if(n.getName()==="auth"&&J(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(l.VariableDeclaration)){const o=n.getNameNode();if(!(!i.isObjectBindingPattern(o)||!J(n.getInitializer(),t))){for(const r of o.getElements())if(Q(r)==="auth")return!0}}return!1},wi=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,Ii=(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"&&J(n.getExpression(),t)},Ti=e=>[...i.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(l.StringLiteral).map(t=>t.getLiteralText())],is=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:Ti(s)},Ci=(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 o=n.getParent();if(!i.isCallExpression(o))return[];const r=o.getExpression();if(!i.isPropertyAccessExpression(r))return[];const a=r.getExpression();return i.isIdentifier(a)?is(t,a.getText()):[]}return[]},Fi=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=is(s,t.getText());return n.length>0?n:Ci(t,s)},wt=(e,t)=>{if(t===void 0)return!1;const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);return i.isCallExpression(s)&&n.unshift(s),n.some(o=>Ii(o,t)&&Fi(o).some(r=>wi.test(r)))},Oi=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!bi.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))return;const o=n.getName();if(Ai.has(o)){const r=n.getExpression();return i.isIdentifier(r)&&r.getText()==="httpRoute"?o.toUpperCase():void 0}s=n.getExpression()}},Ri=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=Z(e.getArguments()[0]),u=c&&At(c,!0);if(!c||u===void 0||wt(c,bt(c,!0)))return;const d=Nt(c,u);return d===void 0?void 0:{exportName:y(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:Pt(c,u),sideEffect:d}}const n=Oi(e);if(n===void 0)return;const o=Z(e.getArguments()[0]),r=o&&At(o,!1);if(!o||r===void 0||wt(o,bt(o,!1)))return;const a=Nt(o,r);return a===void 0?void 0:{exportName:y(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:Pt(o,r),sideEffect:a}},Li=(e,t)=>F(e,t,Ri),Di=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),ki=new Set(["append","set"]),as=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",It=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(l.CallExpression)]:e.getDescendantsOfKind(l.CallExpression)).some(n=>Di.has(A(n.getExpression())??"")&&un(n,t)),Mi=(e,t)=>{if(It(e,t))return!0;const s=he(e);return s!==void 0&&It(s,t)},Le=(e,t)=>ln(e,t)&&!Mi(e,t),Ki=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=he(e);return t!==void 0&&i.isNewExpression(t)&&A(t.getExpression())==="Headers"},de=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=he(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},ze=(e,t,s)=>{for(const n of e.getProperties())if(i.isPropertyAssignment(n)){const o=n.getInitializer();o!==void 0&&Le(o,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:as(n.getNameNode()),line:o.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(n)){const o=n.getNameNode();Le(o,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:S(n),line:o.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(n)){const o=de(n.getExpression());o!==void 0&&ze(o,t,s)}},cs=(e,t)=>{const s=de(e);if(s===void 0)return;const n=C(s,"headers");if(n===void 0||!i.isPropertyAssignment(n))return;const o=de(n.getInitializer());o!==void 0&&ze(o,"response-init",t)},_i=(e,t)=>{const s=A(e.getExpression());if(s==="Response")cs(e.getArguments()[1],t);else if(s==="Headers"){const n=de(e.getArguments()[0]);n!==void 0&&ze(n,"headers-ctor",t)}},zi=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName(),o=s.getExpression();if(n==="json"&&i.isIdentifier(o)&&o.getText()==="Response"){cs(e.getArguments()[1],t);return}if(ki.has(n)&&Ki(o)){const r=e.getArguments()[1];r!==void 0&&Le(r,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:as(e.getArguments()[0]),line:r.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},$i=(e,t)=>{for(const s of e.getDescendantsOfKind(l.NewExpression))_i(s,t);for(const s of e.getDescendantsOfKind(l.CallExpression))zi(s,t)},Ui=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=Z(e.getArguments()[0]);if(n===void 0)return[];const o=n.getParameters()[1];if(o===void 0)return[];const r=o.getNameNode();if(!i.isIdentifier(r))return[];const a=[];return $i(n,{exportName:y(e),relativePath:t,requestName:r.getText(),rows:a}),a},Bi=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression))s.push(...Ui(n,t));return s},qi=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Bi(o,x(t,n)))}return s},ji=new Set(["auth","context.auth","ctx.auth"]),Vi="userId",Wi=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},Hi=(e,t)=>{const s=E(t,Jt);if(!w(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const o of n.getDescendantsOfKind(l.CallExpression)){if(A(o.getExpression())!=="defineIdentity")continue;const[r]=o.getArguments();return r&&i.isObjectLiteralExpression(r)?Wi(r):void 0}},Tt=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return ji.has(e.getExpression().getText())?e:void 0},Gi=e=>{if(i.isPropertyAccessExpression(e)&&Tt(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&Tt(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},Yi=(e,t,s)=>{const n=[];for(const o of e.getDescendants()){const r=Gi(o);r!==void 0&&n.push({declared:r===Vi||s.has(r),exportName:y(o),file:t,key:r,line:o.getStartLineNumber()})}return n},Qi=(e,t)=>{const s=Hi(e,t);if(s===void 0)return[];const n=[];for(const o of p(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...Yi(r,x(t,o),s))}return n},Xi=(e,t)=>{if(A(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=b(s,"key");if(!(!n||!k(n)||U(n)))return{exportName:y(e),file:t,line:e.getStartLineNumber()}},Zi=(e,t)=>F(e,t,Xi),Ji=e=>{if(i.isComputedPropertyName(e)){const t=e.getExpression();return i.isStringLiteral(t)||i.isNoSubstitutionTemplateLiteral(t)?t.getLiteralValue():void 0}return i.isStringLiteral(e)?e.getLiteralValue():e.getText()},ea=e=>e.getProperties().some(t=>{if(i.isSpreadAssignment(t))return!0;const s=Ji(t.getNameNode());return s===void 0||s==="namespace"}),ta=(e,t)=>{for(const{filePath:s}of me(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const o of n.getDescendantsOfKind(l.CallExpression)){const r=o.getExpression(),[a]=o.getArguments();if(!(!i.isPropertyAccessExpression(r)||r.getName()!=="auth"||a===void 0)&&(!i.isObjectLiteralExpression(a)||ea(a)))return o}}},sa="https://lunora.sh/docs/concepts/data-residency#pinning-auth-and-voice",na=(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 (${sa}). 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})},ra=new Set(["delete","get","getRaw","getWithMetadata","put"]),oa=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return xe(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.kv"||r.startsWith("ctx.kv."),methods:ra}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},ia=new Set(["queue","send"]),Ct=new Set(["bcc","cc","to"]),aa=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!ia.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},ca=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return Ct.has(S(t))&&k(n)&&!U(n)}if(!i.isPropertyAssignment(t)||!Ct.has(S(t)))return!1;const s=t.getInitializer();return s!==void 0&&k(s)&&!U(s)}):!1,la=(e,t)=>{const s=aa(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!ca(n)))return{exportName:y(e),file:t,line:e.getStartLineNumber(),method:s}},ua=(e,t)=>F(e,t,la),da=e=>i.isPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?i.isComputedPropertyName(e.getNameNode()):!1,fa=e=>i.isPropertyAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?da(e):!0,ls=(e,t=!1)=>{for(const s of e.getProperties()){if(fa(s))return!0;if(t)continue;if(!i.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!i.isObjectLiteralExpression(n)||ls(n,!0))return!0}return!1},ga=(e,t)=>{for(const s of p(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:o}of Xt(n))for(const r of Me(o)){const a=r.getArguments()[0];if(a!==void 0&&(!i.isObjectLiteralExpression(a)||ls(a)))return!0}}return!1},pa=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const o=ue(n);if(o===void 0||!i.isPropertyAssignment(n))continue;const r=n.getInitializer();if(!(!r||!i.isObjectLiteralExpression(r)))for(const a of r.getProperties()){const c=ue(a);c!==void 0&&s.push({column:c,strategy:Qt(a),table:o})}}return s},ma=(e,t)=>{const s=new Map;for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:r}of Xt(o))for(const a of Me(r))for(const c of pa(a)){const u=`${c.table}\0${c.column}`;s.has(u)||s.set(u,c)}}return{columns:[...s.values()]}},ha=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!i.isObjectLiteralExpression(n))return[];const o=[];for(const r of n.getProperties()){const a=ue(r);if(a===void 0||!i.isPropertyAssignment(r))continue;const c=r.getInitializer();if(!(!c||!i.isObjectLiteralExpression(c)))for(const u of c.getProperties()){const d=ue(u);if(d===void 0)continue;const m=Qt(u);m!=="custom"&&o.push({column:d,exportName:t,file:s,line:u.getStartLineNumber(),strategy:m,table:a})}}return o},va=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?z(s):void 0;return n?.receiver?Me(n.receiver).flatMap(o=>ha(o,e.getName(),t)):[]},xa=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...va(c,r))}return s},Ea=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return _(s)},Sa=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=C(t,"server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},ya=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==l.CallExpression)return;const s=t;return In(s.getExpression())?s:void 0},Aa=e=>{const t=ya(e),s=t===void 0?void 0:Sa(t);if(s===void 0)return[];const n=e.getNameNode(),o=i.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(l.CallExpression).filter(r=>Ea(r)).map(r=>({exportName:o,file:"lunora/mutators.ts",line:r.getStartLineNumber()}))},ba=e=>e.getVariableDeclarations().flatMap(t=>Aa(t)),Na=(e,t)=>{const s=E(t,wn);if(!w(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return ba(n)},Pa=new Set(["delete","get","patch"]),wa=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Ia=new Set(["auth","identity","session","user"]),Ta=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),Ca=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!_(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},Fa=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},Oa=(e,t)=>e.getDescendantsOfKind(l.Identifier).some(s=>s.getText()===t),Ra=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(l.ThrowStatement).length>0||e.getDescendantsOfKind(l.ReturnStatement).length>0,La=(e,t)=>e.getDescendantsOfKind(l.IfStatement).some(s=>Oa(s.getExpression(),t)&&Ra(s.getThenStatement())),Da=(e,t)=>{for(const s of e.getDescendantsOfKind(l.CallExpression)){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))continue;const o=n.getName();if(!Pa.has(o))continue;const r=n.getExpression();if(!(_(r)||i.isPropertyAccessExpression(r)&&_(r.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&i.isIdentifier(c)&&c.getText()===t)return o}},ka=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t)||i.isParenthesizedExpression(t)||i.isAsExpression(t)||i.isAwaitExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t.getText():void 0},Ma=e=>e.getDescendantsOfKind(l.CallExpression).some(t=>t.getArguments().some(s=>ka(s)==="ctx")),Ka=e=>e.getDescendantsOfKind(l.BinaryExpression).some(t=>Ta.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),_a=e=>{for(const t of e.getDescendantsOfKind(l.Identifier))if(wa.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&Ia.has(t.getName()))return!0}return Ma(e)||Ka(e)},za=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=z(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const o=rs(s);if(o===void 0)return[];const r=n.receiver!==void 0&&Ht(n.receiver,"use","rls"),a=_a(o),c=new Set,u=[];for(const d of o.getDescendantsOfKind(l.CallExpression)){const m=Ca(d);if(m===void 0)continue;const h=Fa(d);if(h===void 0||c.has(h)||!La(o,h))continue;const R=Da(o,h);R!==void 0&&(c.add(h),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:R,table:m,usesRls:r,visibility:n.visibility}))}return u},$a=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...za(c,r))}return s},Ua=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Ba=new Set(["insert","insertManyUnsafe","patch","replace"]),qa=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Ba.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="db")return;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="ctx"?t:void 0},ja=(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},Ft=(e,t)=>{if(i.isPropertyAccessExpression(e)){const s=e.getExpression();return i.isIdentifier(s)&&s.getText()==="args"&&e.getName()===t}if(i.isElementAccessExpression(e)){const s=e.getExpression(),n=e.getArgumentExpression();return i.isIdentifier(s)&&s.getText()==="args"&&n!==void 0&&i.isStringLiteral(n)&&n.getLiteralValue()===t}return!1},Va=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;for(const a of s.getDescendantsOfKind(l.BinaryExpression)){const c=a.getLeft();if(i.isIdentifier(c)&&c.getText()===t&&a.getOperatorToken().getText().endsWith("="))return}const n=e.getStart();let o,r=-1;for(const a of s.getDescendantsOfKind(l.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getParent();if(!i.isVariableDeclarationList(c)||c.getDeclarationKind()!==Ks.Const)continue;const u=a.getInitializer(),d=a.getStart();u!==void 0&&d<n&&d>r&&(o=u,r=d)}return o},Wa=(e,t)=>{if(Ft(e,t))return!0;const s=Va(e);return s!==void 0&&Ft(s,t)},Ha=(e,t,s,n,o)=>{const r=[];for(const a of e.getProperties()){let c,u;if(i.isPropertyAssignment(a)?(c=S(a),u=a.getInitializer()):i.isShorthandPropertyAssignment(a)&&(c=S(a),u=a.getNameNode()),!(c===void 0||u===void 0||!Ua.has(c))&&k(u)&&!U(u)){const d=y(s),m=o(d)===c&&Wa(u,c);r.push({exportName:d,field:c,file:n,line:s.getStartLineNumber(),method:t,...m&&{ownerScoped:!0}})}}return r},Ga=(e,t,s)=>{const n=qa(e.getExpression());if(n===void 0)return[];const o=e.getArguments()[1];return o?ja(o,n).flatMap(r=>Ha(r,n,e,t,s)):[]},Ya=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression))for(const r of Ga(o,t,a=>s(a).owner)){const{visibility:a}=s(r.exportName);n.push(a===void 0?r:{...r,visibility:a})}return n},Qa=(e,t,s=[],n=[])=>{const o=[],r=new Map;for(const a of s)r.set(`${a.filePath}:${a.exportName}`,{visibility:a.visibility});for(const a of n){const c=`${a.filePath}:${a.exportName}`;r.set(c,{...r.get(c),owner:a.owner})}for(const a of p(t)){const c=e.getSourceFile(a)??e.addSourceFileAtPath(a),u=x(t,a);o.push(...Ya(c,u,d=>r.get(`${u}:${d}`)??{}))}return o},Xa=["providerSubscriptionId","state"],Za=["providerEventId","processedAt"],Ot=(e,t)=>t.every(s=>s in e.shape),Ja=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&Ot(t,Xa)&&Ot(s,Za)},ec=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),tc=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,sc=e=>{const t=C(e,"webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?tc(t.getInitializer()):void 0},nc=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!ec.has(s))return;const[n]=e.getArguments(),o=n&&i.isObjectLiteralExpression(n)?sc(n):void 0;return{callee:s,exportName:y(e),file:t,line:e.getStartLineNumber(),...o===void 0?{}:{toleranceSeconds:o}}},rc=(e,t)=>F(e,t,nc),oc=new Set(["defineQueue","defineWorkflow"]),ic=new Set(["run","runAction","runMutation","runQuery"]),ac=new Set(["api","internal"]),cc=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},lc=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=C(t,"handler");if(s===void 0||!i.isPropertyAssignment(s))return;const n=s.getInitializer();if(n&&(i.isArrowFunction(n)||i.isFunctionExpression(n)))return n},us=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},ds=(e,t)=>e===t||e.startsWith(`${t}.`),fs=e=>{const t=e.getDescendantsOfKind(l.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},Rt=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)},gs=e=>{const t=e.getDescendantsOfKind(l.Identifier).filter(s=>Rt(s));return i.isIdentifier(e)&&Rt(e)&&t.push(e),t},uc=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(l.BindingElement).map(s=>s.getName())},dc=e=>{const t=us(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(l.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const o=n.getInitializer(),r=i.isVariableDeclarationList(o)?o.getDeclarations()[0]?.getNameNode():void 0;r&&i.isIdentifier(r)&&s.push(`${r.getText()}.body`)}return s},fc=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:dc(e),o=new Set,r=a=>fs(a).some(c=>n.some(u=>ds(c.getText(),u)))?!0:gs(a).some(c=>o.has(c.getText()));for(const a of e.getDescendantsOfKind(l.VariableDeclaration)){const c=a.getInitializer();if(c&&r(c))for(const u of uc(a))o.add(u)}return{names:o,prefixes:n}},gc=(e,t)=>fs(e).some(s=>t.prefixes.some(n=>ds(s.getText(),n)))?!0:gs(e).some(s=>t.names.has(s.getText())),pc=e=>{if(e===void 0||!i.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;i.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const n=t.at(-1);if(!(n===void 0||!i.isIdentifier(s)||!ac.has(s.getText())||t.length<2))return{exportName:n,file:t.slice(0,-1).join("/")}},mc=(e,t,s)=>{const n=us(e,0);if(n===void 0)return[];const o=fc(e,t,n),r=[];for(const a of e.getDescendantsOfKind(l.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!ic.has(c.getName())||c.getExpression().getText()!==n)continue;const u=a.getArguments()[1];if(!u||!gc(u,o))continue;const d=pc(a.getArguments()[0]);d!==void 0&&r.push({dispatchKind:t,file:s,handlerExport:y(a),line:a.getStartLineNumber(),targetExport:d.exportName,targetFile:d.file})}return r},hc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=cc(n);if(o===void 0||!oc.has(o))continue;const r=lc(n);r!==void 0&&s.push(...mc(r,o==="defineQueue"?"queue":"workflow",t))}return s},vc=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...hc(o,x(t,n)))}return s},Lt={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},Dt=new Set(["account","credential","member","passkey","session","user"]),xc=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),Ec=e=>{const s=xc(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return Dt.has(s)||Dt.has(n)},Sc=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},yc=(e,t)=>{const{objects:s,opaque:n}=_e(e,t);return uo(s).some(o=>Sc(o))?!0:n?void 0:!1},Ac=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!C(t,"captcha"),usesRateLimit:!!C(t,"rateLimit")}},bc=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},le={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Nc=e=>{const t=bc(e),s=t?A(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=Ac(t);return{...le,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in Lt?{...le,[Lt[s]]:!0}:le},Pc=e=>{const t={...le};let s=e;for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))break;const o=n.getName()==="use"?s.getArguments()[0]:void 0;if(o){const r=Nc(o);t.usesCaptcha||=r.usesCaptcha,t.usesEmailGate||=r.usesEmailGate,t.usesMask||=r.usesMask,t.usesRateLimit||=r.usesRateLimit,t.usesRls||=r.usesRls}s=n.getExpression()}return t},wc=new Set(["insert","insertMany","insertManyUnsafe","replace"]),Ic=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!wc.has(t.getName()))return!1;const s=t.getExpression();if(!_(s))return!1;const o=e.getArguments()[0];return!o||!(i.isStringLiteral(o)||i.isNoSubstitutionTemplateLiteral(o))?!1:Ec(o.getLiteralText())},Tc=new Set(["create","runAfter","runAt","send","sendBatch"]),Cc=new Set(["queues","scheduler","workflows"]),Fc=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Tc.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&Cc.has(s.getName())){const n=s.getExpression();if(i.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},Oc=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return _(s)},ps=new Set(["generateObject","generateText","streamObject","streamText"]),Rc=e=>{const t=A(e.getExpression());return t!==void 0&&ps.has(t)},Lc=e=>{const t=A(e.getExpression());if(t===void 0||!ps.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(n=>i.isSpreadAssignment(n))?!1:!C(s,"maxOutputTokens")},Dc=new Set(["log","span","trace"]),kc=new Set(["ai"]),Mc=new Set(["email","mail"]),Kc=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),Te=(e,t)=>e.getDescendantsOfKind(l.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="ctx"}),_c=new Set([l.ArrowFunction,l.FunctionDeclaration,l.FunctionExpression,l.GetAccessor,l.MethodDeclaration,l.SetAccessor]),zc=new Set(["every","filter","flatMap","forEach","map","some"]),$c=new Set(["all","allSettled","race"]),Uc=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(zc.has(n))return t;const o=s.getExpression();if(i.isIdentifier(o)&&o.getText()==="Promise"&&$c.has(n))return t},Bc=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(_c.has(t.getKind())){const s=Uc(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},qc=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}},jc=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}},Vc=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression)){if(!Kc.has(n.getName()))continue;const o=n.getExpression();if(!i.isIdentifier(o)||o.getText()!=="ctx")continue;const r=jc(n);r&&(t=!0,!Bc(r)&&!qc(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},Wc=e=>e.getDescendantsOfKind(l.ThrowStatement).some(t=>{const s=t.getExpression();if(!i.isNewExpression(s))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="Error"}),kt="lunora-advisor-exempt",Hc=/^[\s*/]+/u,Gc=/[\w-]/u,Yc=e=>{const s=(e.getFirstAncestorByKind(l.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
|
|
6
6
|
`);for(const n of s.split(`
|
|
7
|
-
`)){const o=n.replace(Hc,"");if(!o.startsWith(kt))continue;const r=o.slice(kt.length);if(Gc.test(r.charAt(0)))continue;const a=r.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":r.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},Qc=e=>{const[t]=e.getArguments();if(t){if(i.isObjectLiteralExpression(t)){const s=C(t,"handler");return s?i.isPropertyAssignment(s)?s.getInitializer():i.isShorthandPropertyAssignment(s)?s.getNameNode():i.isMethodDeclaration(s)?s:void 0:void 0}return t}},Xc=(e,t)=>{const s=Qc(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(),o=s.getText(),r=n.getVariableDeclaration(o)?.getInitializer();return r&&(i.isArrowFunction(r)||i.isFunctionExpression(r))?r:n.getFunction(o)},Zc=e=>{let t=!1,s=!1,n=!1,o=!1,r=!1;for(const u of e.getDescendantsOfKind(l.CallExpression))if(Ic(u)&&(r=!0),Fc(u)&&(t=!0),Oc(u)&&(o=!0),Rc(u)&&(s=!0),Lc(u)&&(n=!0),r&&t&&o&&n)break;const{handlesErrors:a,reachesOutbound:c}=Vc(e);return{callsMail:Te(e,Mc),emitsEvent:Te(e,Dc),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||Te(e,kc),throwsBareError:Wc(e),unboundedAiGeneration:n,usesInsertManyUnsafe:o,writesUserTable:r}},Jc=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=z(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const o=n.receiver?Pc(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},r=Xc(e,s);return{...r?Zc(r):{},...Yc(e),...o,analyzableBody:r!==void 0,exportName:e.getName(),file:t,hasEmailArg:yc(s,n.receiver),kind:n.kind,visibility:n.visibility}},el=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=Jc(o,t);r&&s.push(r)}return s},tl=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...el(o,x(t,n)))}return s},sl=new Set(["dbRateLimit","rateLimit"]),nl=e=>i.isArrowFunction(e)?e.getBody():e,rl=e=>{if(!i.isArrowFunction(e))return;const t=e.getParameters()[0]?.getNameNode();return t!==void 0&&i.isIdentifier(t)?t:void 0},ms=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getExpression()===e&&t.getName()==="args"},hs=(e,t)=>{const s=t.getSymbol();return s===void 0?[]:e.getDescendantsOfKind(l.Identifier).filter(n=>{if(n.getSymbol()!==s)return!1;const o=n.getParent();return!(i.isPropertyAccessExpression(o)&&o.getNameNode()===n)})},ol=(e,t)=>k(e)||t!==void 0&&hs(e,t).some(s=>ms(s)),il=(e,t)=>t===void 0?U(e):hs(e,t).some(s=>!ms(s)),al=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!sl.has(s))return;const n=b(Vt(e.getArguments()[2]),"key");if(!n)return;const o=nl(n),r=rl(n);if(!(!ol(o,r)||il(o,r)))return{callee:s,exportName:S(e),file:t,limitName:jt(e),line:e.getStartLineNumber()}},cl=(e,t)=>F(e,t,al),ll=new Set(["findFirst","findFirstOrThrow","findMany","findUnique","get"]),ul=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ll.has(t.getName()))return;const s=t.getExpression();if(_(s)){const n=e.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&_(s.getExpression()))return s.getName()},dl=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&_(s.getExpression())){const n=t.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},fl=e=>{let t=X(e)??e;for(;i.isAwaitExpression(t);)t=X(t.getExpression())??t.getExpression();return t},vs=(e,t=!1)=>{const s=fl(e);if(i.isIdentifier(s)){if(t)return;const n=he(s);return n===void 0?void 0:vs(n,!0)}if(i.isCallExpression(s))return ul(s)??dl(s)},gl=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(l.ReturnStatement)){const o=n.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),r=n.getExpression();o===e&&r!==void 0&&s.push(r)}return s},pl=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=z(s);if(n?.kind!=="query")return[];const o=rs(s);if(o===void 0)return[];const r=n.receiver!==void 0&&Zs(n.receiver,"output"),a=n.receiver!==void 0&&Ht(n.receiver,"use","mask"),c=new Set,u=[];for(const d of gl(o)){const m=vs(d);m===void 0||c.has(m)||(c.add(m),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:m,usesMask:a,usesOutput:r,visibility:n.visibility}))}return u},ml=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...pl(c,r))}return s},hl=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(E(s));return t},vl=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?z(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Wt(r);if(a===void 0)continue;const c=hl(b(a.options,"with"));c.length!==0&&o.push({exportName:e.getName(),file:t,line:r.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return o},xl=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...vl(c,r))}return s},fe=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===l.PlusToken){const t=fe(e.getLeft()),s=fe(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},El=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===l.PlusToken;)t=s,s=t.getParent();return t!==e&&fe(t)!==void 0},Sl=/(?:^|\/)__tests__\//u,yl=/\.(?:spec|test)$/u,Al=e=>Sl.test(e)||yl.test(e),bl=e=>{const t=e.getParent();if(t!==void 0){if(i.isVariableDeclaration(t)||i.isPropertyAssignment(t)||i.isPropertySignature(t))return E(t);if(i.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.EqualsToken)return t.getLeft().getText()}},Nl=(e,t,s)=>_n(e)?!Al(s)&&zn(bl(t)):!0,Pl=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(l.BinaryExpression),...e.getDescendantsOfKind(l.StringLiteral),...e.getDescendantsOfKind(l.NoSubstitutionTemplateLiteral)],o=new Set;for(const r of n){if(El(r))continue;const a=fe(r);if(a===void 0)continue;const c=Mn(a);if(c===void 0||!Nl(c,r,t))continue;const u=r.getStartLineNumber(),d=`${String(u)}:${c}`;o.has(d)||(o.add(d),s.push({file:t,kind:c,line:u,preview:Kn(a)}))}return s},wl=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Pl(o,x(t,n)))}return s},Il=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?z(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Wt(r);if(a===void 0)continue;const c=b(a.options,"includeDeleted");if(c===void 0)continue;const u=i.isTrueLiteral(c),d=!u&&k(c);!u&&!d||o.push({exportName:e.getName(),file:t,fromArgs:d,hardcodedTrue:u,line:r.getStartLineNumber(),table:a.table,visibility:n.visibility})}return o},Tl=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Il(c,r))}return s},Cl=new Set(["query","unsafe"]),Fl=e=>{if(!i.isPropertyAccessExpression(e)||!Cl.has(e.getName()))return!1;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return i.isIdentifier(s)&&s.getText()==="ctx"},Ol=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),Rl=e=>e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()??"<module>",Ll=(e,t)=>{if(!Fl(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Ol(s)))return{exportName:Rl(e),file:t,line:s.getStartLineNumber()}},Dl=(e,t)=>F(e,t,Ll),kl=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],Ml=e=>{for(const[t,s]of kl)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},Kl=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getImportDeclarations()){const a=r.getModuleSpecifierValue(),c=Ml(a);c!==void 0&&s.push({file:x(t,n),line:r.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},_l=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),zl=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return xe(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:_l,requireUnmodifiedReach:!0}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},$l=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Ul=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Bl=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 o of e.getProperties()){if(i.isSpreadAssignment(o)){n=!0;continue}if(i.isPropertyAssignment(o)){const r=E(o);t.push(r),r==="expiresInSeconds"&&(s=Ul(o.getInitializer()));continue}(i.isShorthandPropertyAssignment(o)||i.isMethodDeclaration(o))&&t.push(E(o))}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},ql=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=$l.get(t);if(s===void 0)return;const n=e.getExpression().getText();return n==="ctx.storage"||n.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},jl=(e,t)=>{const s=ql(e.getExpression());if(s!==void 0)return{exportName:S(e),file:t,line:e.getStartLineNumber(),method:s.method,...Bl(e.getArguments()[s.optionsIndex])}},Vl=(e,t)=>F(e,t,jl),Wl=(e,t)=>{const s=sn(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")}},Hl=(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"}),Gl=(e,t)=>{if(t===void 0){const s=e.getArguments()[0];if(s===void 0||!i.isObjectLiteralExpression(s)||C(s,"args")===void 0)return!1}return _e(e,t).opaque},Yl=(e,t)=>{const s=[],n=(o,r)=>{const a=o.getInitializer();if(a===void 0||!i.isCallExpression(a))return;const c=z(a);c!==void 0&&Gl(a,c.receiver)&&s.push(Hl(t,r,a.getStartLineNumber()))};for(const o of e.getVariableStatements().filter(r=>r.isExported()))for(const r of o.getDeclarations())n(r,r.getName());return s},Ql=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n);o!==void 0&&s.push(...Yl(o,x(t,n)))}return s.toSorted((n,o)=>n.cacheKey.localeCompare(o.cacheKey))},Xl=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."}],["WorkflowDefinition",{call:"defineWorkflow({ … })",file:"workflows"}]]),Ee=({byName:e,byPath:t},s,n)=>t.has(`${s}:${n}`)||e.has(n),xs=e=>!e.isAny(),$e=e=>{const t=e.getType();if(!xs(t))return;const s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName(),n=s===void 0?void 0:Xl.get(s);return n===void 0||s===void 0?void 0:{...n,typeName:s}},Es=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},Ss={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."},Zl=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.`}),Jl={cause:"the binding is exported by a separate `export { … }` statement, and codegen reads the `export` keyword on the declaration itself",remediation:"Move the keyword onto the declaration and drop the separate export statement."},Ue=(e,t,s,n,o)=>{const{call:r,file:a,note:c,typeName:u}=s,d=a!==void 0&&e!==a?a:void 0,m=d===void 0?o:Zl(d),h=c===void 0?m.remediation:`${c} ${m.remediation}`;return{cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally the registering call. 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 \`${u}\` but was not registered — ${m.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:u},name:"procedure_not_registered",remediation:d===void 0?`Assign the registration directly: \`export const ${t} = ${r};\`. ${h}`:h,title:"Procedure exists at runtime but is missing from the generated API"}},eu=(e,t,s)=>{const n=[];for(const o of e.getVariableStatements().filter(r=>r.isExported()))for(const r of o.getDeclarations()){const a=r.getName();if(Ee(s,t,a)||!Es(r))continue;const c=$e(r);c!==void 0&&n.push(Ue(t,a,c,r.getStartLineNumber(),Ss))}return n},tu=(e,t,s)=>{if(Ee(s,t,"default"))return[];const n=[];for(const o of e.getExportAssignments().filter(r=>!r.isExportEquals())){const r=$e(o.getExpression());r!==void 0&&n.push(Ue(t,"default",r,o.getStartLineNumber(),Ss))}return n},su=(e,t,s)=>{const n=[];for(const o of e.getExportDeclarations().filter(r=>r.getModuleSpecifier()===void 0))for(const r of o.getNamedExports()){const a=r.getAliasNode()?.getText()??r.getName();if(Ee(s,t,a))continue;const c=r.getLocalTargetDeclarations().find(d=>i.isVariableDeclaration(d));if(c===void 0||!Es(c))continue;const u=$e(c);u!==void 0&&n.push(Ue(t,a,u,r.getStartLineNumber(),Jl))}return n},nu=(e,t,s)=>[...eu(e,t,s),...tu(e,t,s),...su(e,t,s)],ru=(e,t,s)=>e.getVariableStatements().filter(n=>n.isExported()).flatMap(n=>n.getDeclarations()).filter(n=>Ee(s,t,n.getName())).filter(n=>{const o=n.getInitializer();return o!==void 0&&i.isCallExpression(o)&&i.isPropertyAccessExpression(o.getExpression())}).map(n=>({declaration:n,exportName:n.getName(),relativePath:t})),ou=({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"}),iu=(e,t,s)=>{const n=[],o=[];for(const a of p(t)){const c=e.getSourceFile(a);if(c===void 0)continue;const u=x(t,a);n.push(...nu(c,u,s)),o.push(...ru(c,u,s))}const[r]=o;return r!==void 0&&o.every(({declaration:a})=>!xs(a.getType()))&&n.push(ou(r)),n.toSorted((a,c)=>a.cacheKey.localeCompare(c.cacheKey))},au=new Set(["when","where"]),Ce=new Set(["definePolicy","defineShape"]),cu=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const n=t.getName();return Ce.has(n)?n:void 0}if(!i.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(n)){const o=n.getNameNode().getText();return Ce.has(o)?o:void 0}const s=t.getText();return Ce.has(s)?s:void 0},lu=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,ys=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===l.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(lu(e))return"empty-object";if(i.isParenthesizedExpression(e))return ys(e.getExpression())}},Be=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),uu=e=>e.getDescendantsOfKind(l.ReturnStatement).filter(t=>Be(t)===e),As=e=>e.getDescendantsOfKind(l.ConditionalExpression).filter(t=>Be(t)===e),du=e=>{const t=uu(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(l.IfStatement)!==void 0)||As(e).length>0},fu=e=>e.getDescendantsOfKind(l.IfStatement).filter(t=>Be(t)===e),De=e=>e.getKind()===l.NullKeyword||e.getKind()===l.FalseKeyword||i.isIdentifier(e)&&e.getText()==="undefined"?!0:i.isNumericLiteral(e)?e.getLiteralValue()===0:i.isStringLiteral(e)&&e.getLiteralValue()==="",gu=(e,t)=>De(e)||De(t),pu=new Map([[l.EqualsEqualsEqualsToken,"positive"],[l.EqualsEqualsToken,"positive"],[l.ExclamationEqualsEqualsToken,"negative"],[l.ExclamationEqualsToken,"negative"]]),Mt=e=>!De(e)&&(i.isLiteralExpression(e)||e.getKind()===l.TrueKeyword),mu=(e,t,s)=>{const n=pu.get(e);if(n!==void 0)return gu(t,s)?n==="positive"?"negative":"positive":Mt(t)||Mt(s)?void 0:n},Y=e=>{if(i.isParenthesizedExpression(e))return Y(e.getExpression());if(i.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken)return"negative";if(i.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=mu(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===l.AmpersandAmpersandToken||t===l.BarBarToken){const n=Y(e.getLeft()),o=Y(e.getRight());return n===o?n:"indeterminate"}}return i.isIdentifier(e)||i.isPropertyAccessExpression(e)||i.isElementAccessExpression(e)||i.isCallExpression(e)?"positive":"indeterminate"},Kt=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}}},hu=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(l.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},vu=e=>i.isReturnStatement(e)?e.getExpression()??e:e,xu=e=>{const t=[];for(const s of As(e)){const n=Y(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of fu(e)){const n=Y(s.getExpression());if(n==="indeterminate")continue;const o=n==="negative"?Kt(s.getThenStatement()):Kt(s.getElseStatement())??hu(s);o!==void 0&&t.push(vu(o))}return t},Eu=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},Su=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!i.isObjectLiteralExpression(n))return[];const o=[];for(const r of n.getProperties()){if(!i.isPropertyAssignment(r)||!au.has(E(r)))continue;const a=r.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&du(a))for(const c of xu(a)){const u=ys(c);u!==void 0&&o.push({exportName:Eu(e),file:s,form:u,key:E(r),line:c.getStartLineNumber(),owner:t})}}return o},yu=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=cu(n);o!==void 0&&s.push(...Su(n,o,t))}return s},Au=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...yu(o,x(t,n)))}return s},bu=new Set(["query","upsert","upsertNow"]),Nu=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(bu.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Pu=(e,t)=>{const s=Nu(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const o=b(n,"namespace");if(!(!o||!k(o)||U(o)))return{exportName:S(e),file:t,line:e.getStartLineNumber(),method:s}},wu=(e,t)=>F(e,t,Pu),Iu=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"},Tu=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Cu=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression)){if(!Iu(a))continue;const c=Hs(a);c!==""&&s.push({exportName:c,file:r,line:a.getStartLineNumber(),workflow:Tu(a)})}}return s},Fu=".lunora-schema.json",ke=(e,t)=>{w(e)&&$t(e,"utf8")===t||Ds(e,t,"utf8")},Ou=(e,t)=>{if(t===""){ks(e,{force:!0});return}ke(e,t)},Ru=e=>{const t=y(e,"package.json");if(w(t))try{const s=JSON.parse($t(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},Lu=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Du=e=>{let t=w(e)?e:ae(e);for(;t&&t!==ae(t);){const s=y(t,"tsconfig.json");if(w(s))return s;t=ae(t)}},_t=e=>e.replaceAll("\\","/"),ku=(e,t,s)=>{if(s&&e.length>0){const r=e.map(a=>`"${a.exportName}"`).join(", ");throw new K("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) (${r}), 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 r of t.columns){const a=n.get(r.table)??[];a.push(r.column),n.set(r.table,a)}const o=t.columns.length>0;for(const r of e){if(r.table===void 0){if(o)throw new K("MASK_UNSUPPORTED",`defineShape "${r.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 "${r.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(r.table);if(a===void 0)continue;const c=a.map(u=>`"${u}"`).join(", ");throw new K("MASK_UNSUPPORTED",`defineShape "${r.exportName}" replicates table "${r.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})}},ge=(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)},zt=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,Mu=8,Ku=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:o,migrations:r,project:a,shapes:c,usesSandbox:u,useUmbrella:d,workflows:m}=e,h=()=>En(()=>{const N=Sn(a,o),O=Tn(a,o);return{functions:N,httpRoutes:yn(a,o),mutators:O}});let{erased:R,value:{functions:M,httpRoutes:g,mutators:I}}=h();pt([...M,...I].map(N=>N.filePath)),pt(g.filter(N=>N.stream).map(N=>N.filePath),"http-stream");for(let N=1;;N+=1){const O=Yn({agents:t,functions:M,httpRoutes:g,mutators:I,useUmbrella:d,workflows:m}),v=or({agents:t,functions:M,migrations:r,mutators:I,shapes:c,useUmbrella:d,usesSandbox:u});if(N>=Mu||zt(a,s,O)&&zt(a,n,v))return{apiContent:O,erased:R,functions:M,functionsContent:v,httpRoutes:g,mutators:I};ge(a,s,O),ge(a,n,v),{erased:R,value:{functions:M,httpRoutes:g,mutators:I}}=h()}},_u=e=>{const t=Du(e);return t?new dt({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new dt({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Bd=(e,t)=>{const s=p(t),n=y(t,"schema.ts");w(n)&&s.push(n);for(const c of s){const u=e.getSourceFile(c);u===void 0?e.addSourceFileAtPath(c):u.refreshFromFileSystemSync()}const o=new Set(s.map(c=>_t(c))),r=_t(t),a=`${r}/`;for(const c of e.getSourceFiles()){const u=c.getFilePath();(u===r||u.startsWith(a))&&!o.has(u)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const u=c.getFilePath();if(!(u===r||u.startsWith(a)||u.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},qd=e=>{const t=Lu(),s=t?we.now():0,n=y(e.projectRoot,e.lunoraDirectory??"lunora"),o=y(n,"schema.ts");if(!w(o))throw new K("INTERNAL",`schema.ts not found at ${o}`);const r=e.project??_u(n);fn(xi);const a=kn(r,o,e.projectRoot),{agents:c,containers:u,crons:d,dataModelContent:m,dependencies:h,entryCronTriggers:R,env:M,featureUsage:g,hasFlags:I,hasNotify:N,identity:O,platformGate:v,queues:D,serverContent:B,storageRulesMetadata:H,usesSandbox:te,useUmbrella:$,workflows:L}=Kr({lunoraDirectory:n,project:r,projectRoot:e.projectRoot,schema:a,target:e.target});na(a,a.jurisdiction===void 0?void 0:ta(r,n));const P=y(n,"_generated"),bs=y(P,"dataModel.ts"),Ns=y(P,"server.ts"),Ps=y(P,"api.ts"),ws=y(P,"functions.ts");ge(r,bs,m),ge(r,Ns,B);const se=Pn(r,n),j=$n(r,n),{apiContent:qe,erased:Is,functions:V,functionsContent:je,httpRoutes:Ts,mutators:ne}=Ku({agents:c,apiPath:Ps,generatedFunctionsPath:ws,lunoraDirectory:n,migrations:se,project:r,shapes:j,useUmbrella:$,usesSandbox:te,workflows:L}),re=e.lint===!1?void 0:zs({adminRoutes:Vr(r,n),aiRawRuns:Gr(r,n),aiToolSideEffects:ro(r,n),argumentDerivedFetches:ao(r,n),argumentValidators:xo(r,n),authApiCalls:gn(r,n),authConfigs:To(r,n),browserUrlAccesses:Lo(r,n),configCalls:Uo(r,n),containerKeyAccesses:qo(r,n),containerOverrides:Yo(r,n),containers:u,exportSinks:Jo(r,n),staleMigrationImports:Kl(r,n),failOpenGuards:ri(r,n),flagReads:gi(r,n),flagSecurityDefaults:vi(r,n),geoIndexUsages:yi(r,n),httpActionGuards:Li(r,n),httpHeaderWrites:qi(r,n),hyperdriveCalls:An(r,n),identityClaimReads:Qi(r,n),imageDeliveryUrlAccesses:Zi(r,n),inserts:bn(r,n),kvKeyAccesses:oa(r,n,V),mailRecipientAccesses:ua(r,n),maskProcedures:Nn(r,n),maskStrategies:xa(r,n),mutatorWrites:Na(r,n),nondeterministicCalls:Cn(r,n),normalizeIdAuthorizations:$a(r,n),notifyCalls:On(r,n),notifyConfig:Fn(r,n),mutators:ne,ownerFieldWrites:Qa(r,n,V,ne),unrestrictedWhereBranches:Au(r,n),paymentWebhooks:rc(r,n),privilegedDispatches:vc(r,n),procedureProtections:tl(r,n),queries:dn(r,n),queues:D,r2sqlCalls:Rn(r,n),ratelimitKeySelectors:cl(r,n),rawRowReturns:ml(r,n),relationLoads:xl(r,n),rlsProcedures:Ln(r,n),schema:a,secretLiterals:wl(r,n),shapes:j,softDeleteReads:Tl(r,n),sqlInterpolations:Dl(r,n),storageKeyAccesses:zl(r,n,V),storageUploads:Vl(r,n),vectorNamespaceAccesses:wu(r,n),workflowCalls:Cu(r,n),workflows:L,wranglerVariables:e.wranglerVariables}),Ve=re===void 0?[]:ar(e.projectRoot,[...Ms(re,{source:"static"}),...iu(r,n,{byName:new Set([...L,...D,...c,...u].map(f=>f.exportName)),byPath:new Set([...V,...ne,...j,...se].map(f=>`${f.filePath}:${f.exportName}`))}),...Ql(r,n),...xn(Is,n)]),Cs=Dn(r,n),We=ma(r,n);ku(j,We,ga(r,n));const Fs=I?ci(r,n):[],Se=v.signals.vectorStore!==!1,G=Wl(g,{containerCount:u.length,cronCount:d.length,dependencies:h,hasPaymentTables:Ja(a.tables),queueCount:D.length,storageColumnCount:Object.keys(Yt(a)).length,storageRuleCount:H.rules.length,vectorIndexCount:a.vectorIndexes.length,target:Gt(e.projectRoot,e.target),vectorStoreSupported:Se,workflowCount:L.length}),He=t?we.now():0,ye=Wn(a,se.map(f=>f.id)),Ge=nn({advisories:Ve.filter(f=>f.name!=="procedure_type_check_unavailable"),advisorProcedures:re?.procedureProtections??[],agents:c,containers:u,env:M,flagKeys:Fs,hasAccessFacade:g.access,hasAi:g.ai,hasAnalytics:g.analytics,hasBrowser:g.browser,hasFlags:I,hasHyperdrive:g.hyperdrive,hasImages:g.images,hasKv:g.kv,hasNotify:N,hasPayments:g.payments,hasPipelines:g.pipelines,hasR2sql:g.r2sql,hasVectors:Se,hasX402:g.x402,maskMetadata:We,mutators:ne,queues:D,rlsMetadata:Cs,schema:a,schemaSnapshot:ye,shapes:j,storageRules:H,studioFeatures:G,useUmbrella:$,workflows:L}),Ye=Hn(j,h.has("@lunora/db"),$),Qe=Qn(u,a.jurisdiction),Xe=Xn(L),Ze=Zn(c),Je=Jn(D),et=er(d),Os=tr(G.scheduler),tt=sr(a.vectorIndexes),oe=rr(a,$),st=Gn(h.has("@lunora/seed")),ie=e.apiSpec??"openapi",Ae=ie==="openapi"||ie==="both",be=ie==="openrpc"||ie==="both",nt=Un({emailAgents:c.filter(f=>f.onEmail===!0).map(f=>({bindingName:f.bindingName,exportName:f.exportName})),hasAccess:h.has("@lunora/cloudflare-access"),hasAi:g.ai,hasAnalytics:g.analytics,hasAuth:h.has("@lunora/auth"),hasBrowser:g.browser,hasFramework:h.has("@lunora/astro")||h.has("@lunora/svelte")||h.has("@lunora/vue"),hasGlobal:a.tables.some(f=>Ut(f)),hasHyperdrive:g.hyperdrive,hasHyperdriveGlobal:a.tables.some(f=>Bt(f)),hasImages:g.images,hasKv:g.kv,hasKvIntrospector:G.kv,hasNotify:N,hasPayments:g.payments,hasR2sql:g.r2sql,hasQueue:D.some(f=>f.mode==="push"),hasScheduler:G.scheduler,hasSourcedTables:a.tables.some(f=>f.externalSource!==void 0),hasStorage:G.storage,hasVectors:Se,hasWorkflow:L.length>0,hasX402:g.x402,identity:O,jurisdiction:a.jurisdiction,jurisdictionPinsAuth:a.jurisdictionPinsAuth===!0,tableNames:a.tables.map(f=>f.name),useUmbrella:$,vectorIndexCount:a.vectorIndexes.length,voiceAgents:c.filter(f=>f.voice===!0&&f.voiceBindingName!==void 0).map(f=>({bindingName:f.voiceBindingName,exportName:f.exportName})),wantsOpenApi:Ae,wantsOpenRpc:be}),rt=Ru(e.projectRoot),ot=Bn({functions:V,httpRoutes:Ts,version:rt}),it=jn({functions:V,version:rt}),at=`${JSON.stringify(ot,void 0,2)}
|
|
7
|
+
`)){const o=n.replace(Hc,"");if(!o.startsWith(kt))continue;const r=o.slice(kt.length);if(Gc.test(r.charAt(0)))continue;const a=r.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":r.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},Qc=e=>{const[t]=e.getArguments();if(t){if(i.isObjectLiteralExpression(t)){const s=C(t,"handler");return s?i.isPropertyAssignment(s)?s.getInitializer():i.isShorthandPropertyAssignment(s)?s.getNameNode():i.isMethodDeclaration(s)?s:void 0:void 0}return t}},Xc=(e,t)=>{const s=Qc(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(),o=s.getText(),r=n.getVariableDeclaration(o)?.getInitializer();return r&&(i.isArrowFunction(r)||i.isFunctionExpression(r))?r:n.getFunction(o)},Zc=e=>{let t=!1,s=!1,n=!1,o=!1,r=!1;for(const u of e.getDescendantsOfKind(l.CallExpression))if(Ic(u)&&(r=!0),Fc(u)&&(t=!0),Oc(u)&&(o=!0),Rc(u)&&(s=!0),Lc(u)&&(n=!0),r&&t&&o&&n)break;const{handlesErrors:a,reachesOutbound:c}=Vc(e);return{callsMail:Te(e,Mc),emitsEvent:Te(e,Dc),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||Te(e,kc),throwsBareError:Wc(e),unboundedAiGeneration:n,usesInsertManyUnsafe:o,writesUserTable:r}},Jc=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=z(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const o=n.receiver?Pc(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},r=Xc(e,s);return{...r?Zc(r):{},...Yc(e),...o,analyzableBody:r!==void 0,exportName:e.getName(),file:t,hasEmailArg:yc(s,n.receiver),kind:n.kind,visibility:n.visibility}},el=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=Jc(o,t);r&&s.push(r)}return s},tl=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...el(o,x(t,n)))}return s},sl=new Set(["dbRateLimit","rateLimit"]),nl=e=>i.isArrowFunction(e)?e.getBody():e,rl=e=>{if(!i.isArrowFunction(e))return;const t=e.getParameters()[0]?.getNameNode();return t!==void 0&&i.isIdentifier(t)?t:void 0},ms=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getExpression()===e&&t.getName()==="args"},hs=(e,t)=>{const s=t.getSymbol();return s===void 0?[]:e.getDescendantsOfKind(l.Identifier).filter(n=>{if(n.getSymbol()!==s)return!1;const o=n.getParent();return!(i.isPropertyAccessExpression(o)&&o.getNameNode()===n)})},ol=(e,t)=>k(e)||t!==void 0&&hs(e,t).some(s=>ms(s)),il=(e,t)=>t===void 0?U(e):hs(e,t).some(s=>!ms(s)),al=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!sl.has(s))return;const n=b(Vt(e.getArguments()[2]),"key");if(!n)return;const o=nl(n),r=rl(n);if(!(!ol(o,r)||il(o,r)))return{callee:s,exportName:y(e),file:t,limitName:jt(e),line:e.getStartLineNumber()}},cl=(e,t)=>F(e,t,al),ll=new Set(["findFirst","findFirstOrThrow","findMany","findUnique","get"]),ul=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ll.has(t.getName()))return;const s=t.getExpression();if(_(s)){const n=e.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&_(s.getExpression()))return s.getName()},dl=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&_(s.getExpression())){const n=t.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},fl=e=>{let t=X(e)??e;for(;i.isAwaitExpression(t);)t=X(t.getExpression())??t.getExpression();return t},vs=(e,t=!1)=>{const s=fl(e);if(i.isIdentifier(s)){if(t)return;const n=he(s);return n===void 0?void 0:vs(n,!0)}if(i.isCallExpression(s))return ul(s)??dl(s)},gl=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(l.ReturnStatement)){const o=n.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),r=n.getExpression();o===e&&r!==void 0&&s.push(r)}return s},pl=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=z(s);if(n?.kind!=="query")return[];const o=rs(s);if(o===void 0)return[];const r=n.receiver!==void 0&&Zs(n.receiver,"output"),a=n.receiver!==void 0&&Ht(n.receiver,"use","mask"),c=new Set,u=[];for(const d of gl(o)){const m=vs(d);m===void 0||c.has(m)||(c.add(m),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:m,usesMask:a,usesOutput:r,visibility:n.visibility}))}return u},ml=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...pl(c,r))}return s},hl=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},vl=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?z(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Wt(r);if(a===void 0)continue;const c=hl(b(a.options,"with"));c.length!==0&&o.push({exportName:e.getName(),file:t,line:r.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return o},xl=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...vl(c,r))}return s},fe=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===l.PlusToken){const t=fe(e.getLeft()),s=fe(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},El=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===l.PlusToken;)t=s,s=t.getParent();return t!==e&&fe(t)!==void 0},Sl=/(?:^|\/)__tests__\//u,yl=/\.(?:spec|test)$/u,Al=e=>Sl.test(e)||yl.test(e),bl=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()===l.EqualsToken)return t.getLeft().getText()}},Nl=(e,t,s)=>_n(e)?!Al(s)&&zn(bl(t)):!0,Pl=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(l.BinaryExpression),...e.getDescendantsOfKind(l.StringLiteral),...e.getDescendantsOfKind(l.NoSubstitutionTemplateLiteral)],o=new Set;for(const r of n){if(El(r))continue;const a=fe(r);if(a===void 0)continue;const c=Mn(a);if(c===void 0||!Nl(c,r,t))continue;const u=r.getStartLineNumber(),d=`${String(u)}:${c}`;o.has(d)||(o.add(d),s.push({file:t,kind:c,line:u,preview:Kn(a)}))}return s},wl=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Pl(o,x(t,n)))}return s},Il=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?z(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Wt(r);if(a===void 0)continue;const c=b(a.options,"includeDeleted");if(c===void 0)continue;const u=i.isTrueLiteral(c),d=!u&&k(c);!u&&!d||o.push({exportName:e.getName(),file:t,fromArgs:d,hardcodedTrue:u,line:r.getStartLineNumber(),table:a.table,visibility:n.visibility})}return o},Tl=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Il(c,r))}return s},Cl=new Set(["query","unsafe"]),Fl=e=>{if(!i.isPropertyAccessExpression(e)||!Cl.has(e.getName()))return!1;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return i.isIdentifier(s)&&s.getText()==="ctx"},Ol=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),Rl=e=>e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()??"<module>",Ll=(e,t)=>{if(!Fl(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Ol(s)))return{exportName:Rl(e),file:t,line:s.getStartLineNumber()}},Dl=(e,t)=>F(e,t,Ll),kl=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],Ml=e=>{for(const[t,s]of kl)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},Kl=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getImportDeclarations()){const a=r.getModuleSpecifierValue(),c=Ml(a);c!==void 0&&s.push({file:x(t,n),line:r.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},_l=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),zl=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return xe(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:_l,requireUnmodifiedReach:!0}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},$l=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Ul=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Bl=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 o of e.getProperties()){if(i.isSpreadAssignment(o)){n=!0;continue}if(i.isPropertyAssignment(o)){const r=S(o);t.push(r),r==="expiresInSeconds"&&(s=Ul(o.getInitializer()));continue}(i.isShorthandPropertyAssignment(o)||i.isMethodDeclaration(o))&&t.push(S(o))}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},ql=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=$l.get(t);if(s===void 0)return;const n=e.getExpression().getText();return n==="ctx.storage"||n.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},jl=(e,t)=>{const s=ql(e.getExpression());if(s!==void 0)return{exportName:y(e),file:t,line:e.getStartLineNumber(),method:s.method,...Bl(e.getArguments()[s.optionsIndex])}},Vl=(e,t)=>F(e,t,jl),Wl=(e,t)=>{const s=sn(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")}},Hl=(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"}),Gl=(e,t)=>{if(t===void 0){const s=e.getArguments()[0];if(s===void 0||!i.isObjectLiteralExpression(s)||C(s,"args")===void 0)return!1}return _e(e,t).opaque},Yl=(e,t)=>{const s=[],n=(o,r)=>{const a=o.getInitializer();if(a===void 0||!i.isCallExpression(a))return;const c=z(a);c!==void 0&&Gl(a,c.receiver)&&s.push(Hl(t,r,a.getStartLineNumber()))};for(const o of e.getVariableStatements().filter(r=>r.isExported()))for(const r of o.getDeclarations())n(r,r.getName());return s},Ql=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n);o!==void 0&&s.push(...Yl(o,x(t,n)))}return s.toSorted((n,o)=>n.cacheKey.localeCompare(o.cacheKey))},Xl=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."}],["WorkflowDefinition",{call:"defineWorkflow({ … })",file:"workflows"}]]),Ee=({byName:e,byPath:t},s,n)=>t.has(`${s}:${n}`)||e.has(n),xs=e=>!e.isAny(),$e=e=>{const t=e.getType();if(!xs(t))return;const s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName(),n=s===void 0?void 0:Xl.get(s);return n===void 0||s===void 0?void 0:{...n,typeName:s}},Es=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},Ss={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."},Zl=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.`}),Jl={cause:"the binding is exported by a separate `export { … }` statement, and codegen reads the `export` keyword on the declaration itself",remediation:"Move the keyword onto the declaration and drop the separate export statement."},Ue=(e,t,s,n,o)=>{const{call:r,file:a,note:c,typeName:u}=s,d=a!==void 0&&e!==a?a:void 0,m=d===void 0?o:Zl(d),h=c===void 0?m.remediation:`${c} ${m.remediation}`;return{cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally the registering call. 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 \`${u}\` but was not registered — ${m.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:u},name:"procedure_not_registered",remediation:d===void 0?`Assign the registration directly: \`export const ${t} = ${r};\`. ${h}`:h,title:"Procedure exists at runtime but is missing from the generated API"}},eu=(e,t,s)=>{const n=[];for(const o of e.getVariableStatements().filter(r=>r.isExported()))for(const r of o.getDeclarations()){const a=r.getName();if(Ee(s,t,a)||!Es(r))continue;const c=$e(r);c!==void 0&&n.push(Ue(t,a,c,r.getStartLineNumber(),Ss))}return n},tu=(e,t,s)=>{if(Ee(s,t,"default"))return[];const n=[];for(const o of e.getExportAssignments().filter(r=>!r.isExportEquals())){const r=$e(o.getExpression());r!==void 0&&n.push(Ue(t,"default",r,o.getStartLineNumber(),Ss))}return n},su=(e,t,s)=>{const n=[];for(const o of e.getExportDeclarations().filter(r=>r.getModuleSpecifier()===void 0))for(const r of o.getNamedExports()){const a=r.getAliasNode()?.getText()??r.getName();if(Ee(s,t,a))continue;const c=r.getLocalTargetDeclarations().find(d=>i.isVariableDeclaration(d));if(c===void 0||!Es(c))continue;const u=$e(c);u!==void 0&&n.push(Ue(t,a,u,r.getStartLineNumber(),Jl))}return n},nu=(e,t,s)=>[...eu(e,t,s),...tu(e,t,s),...su(e,t,s)],ru=(e,t,s)=>e.getVariableStatements().filter(n=>n.isExported()).flatMap(n=>n.getDeclarations()).filter(n=>Ee(s,t,n.getName())).filter(n=>{const o=n.getInitializer();return o!==void 0&&i.isCallExpression(o)&&i.isPropertyAccessExpression(o.getExpression())}).map(n=>({declaration:n,exportName:n.getName(),relativePath:t})),ou=({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"}),iu=(e,t,s)=>{const n=[],o=[];for(const a of p(t)){const c=e.getSourceFile(a);if(c===void 0)continue;const u=x(t,a);n.push(...nu(c,u,s)),o.push(...ru(c,u,s))}const[r]=o;return r!==void 0&&o.every(({declaration:a})=>!xs(a.getType()))&&n.push(ou(r)),n.toSorted((a,c)=>a.cacheKey.localeCompare(c.cacheKey))},au=new Set(["when","where"]),Ce=new Set(["definePolicy","defineShape"]),cu=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const n=t.getName();return Ce.has(n)?n:void 0}if(!i.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(n)){const o=n.getNameNode().getText();return Ce.has(o)?o:void 0}const s=t.getText();return Ce.has(s)?s:void 0},lu=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,ys=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===l.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(lu(e))return"empty-object";if(i.isParenthesizedExpression(e))return ys(e.getExpression())}},Be=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),uu=e=>e.getDescendantsOfKind(l.ReturnStatement).filter(t=>Be(t)===e),As=e=>e.getDescendantsOfKind(l.ConditionalExpression).filter(t=>Be(t)===e),du=e=>{const t=uu(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(l.IfStatement)!==void 0)||As(e).length>0},fu=e=>e.getDescendantsOfKind(l.IfStatement).filter(t=>Be(t)===e),De=e=>e.getKind()===l.NullKeyword||e.getKind()===l.FalseKeyword||i.isIdentifier(e)&&e.getText()==="undefined"?!0:i.isNumericLiteral(e)?e.getLiteralValue()===0:i.isStringLiteral(e)&&e.getLiteralValue()==="",gu=(e,t)=>De(e)||De(t),pu=new Map([[l.EqualsEqualsEqualsToken,"positive"],[l.EqualsEqualsToken,"positive"],[l.ExclamationEqualsEqualsToken,"negative"],[l.ExclamationEqualsToken,"negative"]]),Mt=e=>!De(e)&&(i.isLiteralExpression(e)||e.getKind()===l.TrueKeyword),mu=(e,t,s)=>{const n=pu.get(e);if(n!==void 0)return gu(t,s)?n==="positive"?"negative":"positive":Mt(t)||Mt(s)?void 0:n},Y=e=>{if(i.isParenthesizedExpression(e))return Y(e.getExpression());if(i.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken)return"negative";if(i.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=mu(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===l.AmpersandAmpersandToken||t===l.BarBarToken){const n=Y(e.getLeft()),o=Y(e.getRight());return n===o?n:"indeterminate"}}return i.isIdentifier(e)||i.isPropertyAccessExpression(e)||i.isElementAccessExpression(e)||i.isCallExpression(e)?"positive":"indeterminate"},Kt=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}}},hu=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(l.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},vu=e=>i.isReturnStatement(e)?e.getExpression()??e:e,xu=e=>{const t=[];for(const s of As(e)){const n=Y(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of fu(e)){const n=Y(s.getExpression());if(n==="indeterminate")continue;const o=n==="negative"?Kt(s.getThenStatement()):Kt(s.getElseStatement())??hu(s);o!==void 0&&t.push(vu(o))}return t},Eu=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},Su=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!i.isObjectLiteralExpression(n))return[];const o=[];for(const r of n.getProperties()){if(!i.isPropertyAssignment(r)||!au.has(S(r)))continue;const a=r.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&du(a))for(const c of xu(a)){const u=ys(c);u!==void 0&&o.push({exportName:Eu(e),file:s,form:u,key:S(r),line:c.getStartLineNumber(),owner:t})}}return o},yu=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=cu(n);o!==void 0&&s.push(...Su(n,o,t))}return s},Au=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...yu(o,x(t,n)))}return s},bu=new Set(["query","upsert","upsertNow"]),Nu=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(bu.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Pu=(e,t)=>{const s=Nu(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const o=b(n,"namespace");if(!(!o||!k(o)||U(o)))return{exportName:y(e),file:t,line:e.getStartLineNumber(),method:s}},wu=(e,t)=>F(e,t,Pu),Iu=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"},Tu=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Cu=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression)){if(!Iu(a))continue;const c=Hs(a);c!==""&&s.push({exportName:c,file:r,line:a.getStartLineNumber(),workflow:Tu(a)})}}return s},Fu=".lunora-schema.json",ke=(e,t)=>{w(e)&&$t(e,"utf8")===t||Ds(e,t,"utf8")},Ou=(e,t)=>{if(t===""){ks(e,{force:!0});return}ke(e,t)},Ru=e=>{const t=E(e,"package.json");if(w(t))try{const s=JSON.parse($t(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},Lu=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Du=e=>{let t=w(e)?e:ae(e);for(;t&&t!==ae(t);){const s=E(t,"tsconfig.json");if(w(s))return s;t=ae(t)}},_t=e=>e.replaceAll("\\","/"),ku=(e,t,s)=>{if(s&&e.length>0){const r=e.map(a=>`"${a.exportName}"`).join(", ");throw new K("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) (${r}), 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 r of t.columns){const a=n.get(r.table)??[];a.push(r.column),n.set(r.table,a)}const o=t.columns.length>0;for(const r of e){if(r.table===void 0){if(o)throw new K("MASK_UNSUPPORTED",`defineShape "${r.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 "${r.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(r.table);if(a===void 0)continue;const c=a.map(u=>`"${u}"`).join(", ");throw new K("MASK_UNSUPPORTED",`defineShape "${r.exportName}" replicates table "${r.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})}},ge=(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)},zt=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,Mu=8,Ku=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:o,migrations:r,project:a,shapes:c,usesSandbox:u,useUmbrella:d,workflows:m}=e,h=()=>En(()=>{const N=Sn(a,o),O=Tn(a,o);return{functions:N,httpRoutes:yn(a,o),mutators:O}});let{erased:R,value:{functions:M,httpRoutes:g,mutators:I}}=h();pt([...M,...I].map(N=>N.filePath)),pt(g.filter(N=>N.stream).map(N=>N.filePath),"http-stream");for(let N=1;;N+=1){const O=Yn({agents:t,functions:M,httpRoutes:g,mutators:I,useUmbrella:d,workflows:m}),v=or({agents:t,functions:M,migrations:r,mutators:I,shapes:c,useUmbrella:d,usesSandbox:u});if(N>=Mu||zt(a,s,O)&&zt(a,n,v))return{apiContent:O,erased:R,functions:M,functionsContent:v,httpRoutes:g,mutators:I};ge(a,s,O),ge(a,n,v),{erased:R,value:{functions:M,httpRoutes:g,mutators:I}}=h()}},_u=e=>{const t=Du(e);return t?new dt({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new dt({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Bd=(e,t)=>{const s=p(t),n=E(t,"schema.ts");w(n)&&s.push(n);for(const c of s){const u=e.getSourceFile(c);u===void 0?e.addSourceFileAtPath(c):u.refreshFromFileSystemSync()}const o=new Set(s.map(c=>_t(c))),r=_t(t),a=`${r}/`;for(const c of e.getSourceFiles()){const u=c.getFilePath();(u===r||u.startsWith(a))&&!o.has(u)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const u=c.getFilePath();if(!(u===r||u.startsWith(a)||u.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},qd=e=>{const t=Lu(),s=t?we.now():0,n=E(e.projectRoot,e.lunoraDirectory??"lunora"),o=E(n,"schema.ts");if(!w(o))throw new K("INTERNAL",`schema.ts not found at ${o}`);const r=e.project??_u(n);fn(xi);const a=kn(r,o,e.projectRoot),{agents:c,containers:u,crons:d,dataModelContent:m,dependencies:h,entryCronTriggers:R,env:M,featureUsage:g,hasFlags:I,hasNotify:N,identity:O,platformGate:v,queues:D,serverContent:B,storageRulesMetadata:H,usesSandbox:te,useUmbrella:$,workflows:L}=Kr({lunoraDirectory:n,project:r,projectRoot:e.projectRoot,schema:a,target:e.target});na(a,a.jurisdiction===void 0?void 0:ta(r,n));const P=E(n,"_generated"),bs=E(P,"dataModel.ts"),Ns=E(P,"server.ts"),Ps=E(P,"api.ts"),ws=E(P,"functions.ts");ge(r,bs,m),ge(r,Ns,B);const se=Pn(r,n),j=$n(r,n),{apiContent:qe,erased:Is,functions:V,functionsContent:je,httpRoutes:Ts,mutators:ne}=Ku({agents:c,apiPath:Ps,generatedFunctionsPath:ws,lunoraDirectory:n,migrations:se,project:r,shapes:j,useUmbrella:$,usesSandbox:te,workflows:L}),re=e.lint===!1?void 0:zs({adminRoutes:Vr(r,n),aiRawRuns:Gr(r,n),aiToolSideEffects:ro(r,n),argumentDerivedFetches:ao(r,n),argumentValidators:xo(r,n),authApiCalls:gn(r,n),authConfigs:To(r,n),browserUrlAccesses:Lo(r,n),configCalls:Uo(r,n),containerKeyAccesses:qo(r,n),containerOverrides:Yo(r,n),containers:u,exportSinks:Jo(r,n),staleMigrationImports:Kl(r,n),failOpenGuards:ri(r,n),flagReads:gi(r,n),flagSecurityDefaults:vi(r,n),geoIndexUsages:yi(r,n),httpActionGuards:Li(r,n),httpHeaderWrites:qi(r,n),hyperdriveCalls:An(r,n),identityClaimReads:Qi(r,n),imageDeliveryUrlAccesses:Zi(r,n),inserts:bn(r,n),kvKeyAccesses:oa(r,n,V),mailRecipientAccesses:ua(r,n),maskProcedures:Nn(r,n),maskStrategies:xa(r,n),mutatorWrites:Na(r,n),nondeterministicCalls:Cn(r,n),normalizeIdAuthorizations:$a(r,n),notifyCalls:On(r,n),notifyConfig:Fn(r,n),mutators:ne,ownerFieldWrites:Qa(r,n,V,ne),unrestrictedWhereBranches:Au(r,n),paymentWebhooks:rc(r,n),privilegedDispatches:vc(r,n),procedureProtections:tl(r,n),queries:dn(r,n),queues:D,r2sqlCalls:Rn(r,n),ratelimitKeySelectors:cl(r,n),rawRowReturns:ml(r,n),relationLoads:xl(r,n),rlsProcedures:Ln(r,n),schema:a,secretLiterals:wl(r,n),shapes:j,softDeleteReads:Tl(r,n),sqlInterpolations:Dl(r,n),storageKeyAccesses:zl(r,n,V),storageUploads:Vl(r,n),vectorNamespaceAccesses:wu(r,n),workflowCalls:Cu(r,n),workflows:L,wranglerVariables:e.wranglerVariables}),Ve=re===void 0?[]:ar(e.projectRoot,[...Ms(re,{source:"static"}),...iu(r,n,{byName:new Set([...L,...D,...c,...u].map(f=>f.exportName)),byPath:new Set([...V,...ne,...j,...se].map(f=>`${f.filePath}:${f.exportName}`))}),...Ql(r,n),...xn(Is,n)]),Cs=Dn(r,n),We=ma(r,n);ku(j,We,ga(r,n));const Fs=I?ci(r,n):[],Se=v.signals.vectorStore!==!1,G=Wl(g,{containerCount:u.length,cronCount:d.length,dependencies:h,hasPaymentTables:Ja(a.tables),queueCount:D.length,storageColumnCount:Object.keys(Yt(a)).length,storageRuleCount:H.rules.length,vectorIndexCount:a.vectorIndexes.length,target:Gt(e.projectRoot,e.target),vectorStoreSupported:Se,workflowCount:L.length}),He=t?we.now():0,ye=Wn(a,se.map(f=>f.id)),Ge=nn({advisories:Ve.filter(f=>f.name!=="procedure_type_check_unavailable"),advisorProcedures:re?.procedureProtections??[],agents:c,containers:u,env:M,flagKeys:Fs,hasAccessFacade:g.access,hasAi:g.ai,hasAnalytics:g.analytics,hasBrowser:g.browser,hasFlags:I,hasHyperdrive:g.hyperdrive,hasImages:g.images,hasKv:g.kv,hasNotify:N,hasPayments:g.payments,hasPipelines:g.pipelines,hasR2sql:g.r2sql,hasVectors:Se,hasX402:g.x402,maskMetadata:We,mutators:ne,queues:D,rlsMetadata:Cs,schema:a,schemaSnapshot:ye,shapes:j,storageRules:H,studioFeatures:G,useUmbrella:$,workflows:L}),Ye=Hn(j,h.has("@lunora/db"),$),Qe=Qn(u,a.jurisdiction),Xe=Xn(L),Ze=Zn(c),Je=Jn(D),et=er(d),Os=tr(G.scheduler),tt=sr(a.vectorIndexes),oe=rr(a,$),st=Gn(h.has("@lunora/seed")),ie=e.apiSpec??"openapi",Ae=ie==="openapi"||ie==="both",be=ie==="openrpc"||ie==="both",nt=Un({emailAgents:c.filter(f=>f.onEmail===!0).map(f=>({bindingName:f.bindingName,exportName:f.exportName})),hasAccess:h.has("@lunora/cloudflare-access"),hasAi:g.ai,hasAnalytics:g.analytics,hasAuth:h.has("@lunora/auth"),hasBrowser:g.browser,hasFramework:h.has("@lunora/astro")||h.has("@lunora/svelte")||h.has("@lunora/vue")||w(E(e.projectRoot,"src","worker.ts")),hasGlobal:a.tables.some(f=>Ut(f)),hasHyperdrive:g.hyperdrive,hasHyperdriveGlobal:a.tables.some(f=>Bt(f)),hasImages:g.images,hasKv:g.kv,hasKvIntrospector:G.kv,hasNotify:N,hasPayments:g.payments,hasR2sql:g.r2sql,hasQueue:D.some(f=>f.mode==="push"),hasScheduler:G.scheduler,hasSourcedTables:a.tables.some(f=>f.externalSource!==void 0),hasStorage:G.storage,hasVectors:Se,hasWorkflow:L.length>0,hasX402:g.x402,identity:O,jurisdiction:a.jurisdiction,jurisdictionPinsAuth:a.jurisdictionPinsAuth===!0,tableNames:a.tables.map(f=>f.name),useUmbrella:$,vectorIndexCount:a.vectorIndexes.length,voiceAgents:c.filter(f=>f.voice===!0&&f.voiceBindingName!==void 0).map(f=>({bindingName:f.voiceBindingName,exportName:f.exportName})),wantsOpenApi:Ae,wantsOpenRpc:be}),rt=Ru(e.projectRoot),ot=Bn({functions:V,httpRoutes:Ts,version:rt}),it=jn({functions:V,version:rt}),at=`${JSON.stringify(ot,void 0,2)}
|
|
8
8
|
`,ct=`${JSON.stringify(it,void 0,2)}
|
|
9
|
-
`,lt=qn(ot),ut=Vn(it),Ne=
|
|
9
|
+
`,lt=qn(ot),ut=Vn(it),Ne=E(n,Fu),Rs=w(Ne),Pe=[];if(!e.dryRun){w(P)||Ls(P,{recursive:!0});const f=(q,W)=>{ke(E(P,q),W),Pe.push(q)},T=(q,W)=>{Ou(E(P,q),W),W!==""&&Pe.push(q)};f("app.ts",nt),f("dataModel.ts",m),f("api.ts",qe),f("server.ts",B),f("functions.ts",je),f("shard.ts",Ge),f("crons.ts",et),f("vectors.ts",tt),f("drizzle.global.ts",oe.global),f("drizzle.shard.ts",oe.shard),T("containers.ts",Qe),T("workflows.ts",Xe),T("agents.ts",Ze),T("queues.ts",Je),T("scheduler.ts",Os),T("seed.ts",st),T("collections.ts",Ye),T("openapi.json",Ae?at:""),T("openapi.ts",Ae?lt:""),T("openrpc.json",be?ct:""),T("openrpc.ts",be?ut:""),(!Rs||e.updateSchemaBaseline===!0)&&ke(Ne,_s(ye))}if(t){const f=we.now(),T=Math.round(f-s),q=Math.round(He-s),W=Math.round(f-He);console.error(`@lunora/codegen: codegen took ${T.toString()}ms (discovery ${q.toString()}ms, emit ${W.toString()}ms)`)}return{advisories:Ve,advisorContext:re,agents:c,containers:u,cronTriggers:[...new Set([...nr(d),...R])],generated:{agents:Ze,api:qe,app:nt,collections:Ye,containers:Qe,crons:et,dataModel:m,drizzleGlobal:oe.global,drizzleShard:oe.shard,functions:je,openApi:at,openApiModule:lt,openRpc:ct,openRpcModule:ut,queues:Je,seed:st,server:B,shard:Ge,vectors:tt,workflows:Xe},migrations:se,outputDirectory:P,platformDiagnostics:v.diagnostics,queues:D,schemaSnapshot:ye,schemaSnapshotPath:Ne,workflows:L,writtenFiles:Pe}};export{Fu as SCHEMA_SNAPSHOT_FILENAME,_u as createCodegenProject,Du as findTsconfig,Bd as refreshCodegenProject,qd as runCodegen};
|