@lunora/codegen 1.0.0-alpha.355 → 1.0.0-alpha.356
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{SCHEMA_SNAPSHOT_FILENAME-BQwNonnN.mjs → SCHEMA_SNAPSHOT_FILENAME-DB8KkcgP.mjs} +2 -2
- package/dist/packem_shared/{emitServer-DqjvPPKJ.mjs → emitServer-RXgOOH_b.mjs} +1 -1
- package/dist/packem_shared/{server-DlEPJi5i.mjs → server-CeYggUIZ.mjs} +4 -4
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as a,serializeSchemaSnapshot as i}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-C7Um0EnM.mjs";import{formatAdvisories as f,lintSchema as m,toAdvisorContext as d}from"./packem_shared/formatAdvisories-BCVASH7N.mjs";import{describeErrorLevelFindings as n,errorAdvisoryNames as c,errorPlatformDiagnosticNames as l,sortedUniqueNames as x}from"./packem_shared/describeErrorLevelFindings-vzaGS9KL.mjs";import{CAPABILITY_PROBES as E}from"./packem_shared/CAPABILITY_PROBES-brcmKenl.mjs";import{CodegenDiagnosticError as A,diagnosticAt as g}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as C,discoverAgents as N}from"./packem_shared/AGENTS_FILENAME-isdHqPIt.mjs";import{isTestPath as R,listLunoraSourceFiles as T}from"./packem_shared/isTestPath-C3QumE88.mjs";import{default as I}from"./packem_shared/discoverAuthApiCalls-CScPrUD-.mjs";import{CONTAINERS_FILENAME as F,discoverContainers as L}from"./packem_shared/CONTAINERS_FILENAME-mK4cZpcz.mjs";import{default as P}from"./packem_shared/discoverCrons-B1_NUt19.mjs";import{capabilitiesUsedBy as b,createTargetScope as y,foldCapabilitySignals as U,mayReadCapabilityContext as G,sourceCapabilitySignals as H}from"./packem_shared/capabilitiesUsedBy-DjRHg-Zk.mjs";import{FLAGS_FILENAME as B,discoverFlags as k}from"./packem_shared/FLAGS_FILENAME-BQk3SX8D.mjs";import{default as K}from"./packem_shared/discoverFunctions-CJG4S6CK.mjs";import{default as z}from"./packem_shared/discoverHttpRoutes-DCDgDIYv.mjs";import{default as q}from"./packem_shared/discoverHyperdriveCalls-CL-d0IVo.mjs";import{default as J}from"./packem_shared/discoverInserts-BcoTjXqI.mjs";import{d as X}from"./packem_shared/index-CN8FVvr-.mjs";import{default as $}from"./packem_shared/discoverMigrations-BWxx8Wv9.mjs";import{MUTATORS_FILENAME as re,discoverMutators as oe}from"./packem_shared/MUTATORS_FILENAME-Cy9h3EVW.mjs";import{default as ae}from"./packem_shared/discoverNondeterministicCalls-mFJNU8qY.mjs";import{NOTIFY_FILENAME as se,discoverNotifyCalls as fe,discoverNotifyChannels as me,discoverNotifyConfig as de}from"./packem_shared/NOTIFY_FILENAME-9to_l_Kh.mjs";import{default as ne}from"./packem_shared/readPackageDependencies-RHhGiz0k.mjs";import{default as le}from"./packem_shared/discoverQueries-CxQRVuIV.mjs";import{QUEUES_FILENAME as Se,discoverQueues as Ee}from"./packem_shared/QUEUES_FILENAME-Civ-7SiI.mjs";import{default as Ae}from"./packem_shared/discoverR2sqlCalls-B4oeTYEM.mjs";import{default as ve}from"./packem_shared/discoverRlsProcedures-Cl6UKT7L.mjs";import{default as Ne}from"./packem_shared/discoverRlsMetadata-D0B4nCmG.mjs";import{discoverSandboxUsage as Re}from"./packem_shared/discoverSandboxUsage--Z1vx7GM.mjs";import{default as he}from"./packem_shared/discoverSchema-CGAFQxFU.mjs";import{readServiceBindings as _e,resolveServiceBindings as Fe}from"./packem_shared/readServiceBindings-BA49C6aN.mjs";import{SHAPES_FILENAME as Me,discoverShapes as Pe}from"./packem_shared/SHAPES_FILENAME-DVJbfDZ8.mjs";import{default as be}from"./packem_shared/discoverStorageRulesMetadata-CitX6ziW.mjs";import{WORKFLOWS_FILENAME as Ue,discoverWorkflows as Ge}from"./packem_shared/WORKFLOWS_FILENAME-kXq07aGl.mjs";import{emitApp as je}from"./packem_shared/emitApp-C0shqv7S.mjs";import{isD1GlobalTable as ke,isHyperdriveGlobalTable as We}from"./packem_shared/isD1GlobalTable-udvHAAzD.mjs";import{buildOpenApiDocument as Ve,emitOpenApi as ze,emitOpenApiModule as Qe}from"./packem_shared/buildOpenApiDocument-DWdj2jvW.mjs";import{OPENRPC_VERSION as we,buildOpenRpcDocument as Je,emitOpenRpc as Ye,emitOpenRpcModule as Xe}from"./packem_shared/OPENRPC_VERSION-DfSmacMR.mjs";import{DEFAULT_TARGET as $e,platformMatrixIds as er,readProjectTarget as rr,resolveCodegenTarget as or}from"./packem_shared/DEFAULT_TARGET-3OLdJhTj.mjs";import{loadProjectConfig as ar,readProjectConfigLiterals as ir}from"./packem_shared/loadProjectConfig-B7RmxIeD.mjs";import{PROJECT_CONFIG_FILENAMES as fr,findCodegenConfigFile as mr,findProjectConfigFile as dr,projectConfigCandidatePaths as pr}from"./packem_shared/PROJECT_CONFIG_FILENAMES-CLfsyvjA.mjs";import{SCHEMA_SNAPSHOT_FILENAME as cr,runCodegen as lr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-
|
|
1
|
+
import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as a,serializeSchemaSnapshot as i}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-C7Um0EnM.mjs";import{formatAdvisories as f,lintSchema as m,toAdvisorContext as d}from"./packem_shared/formatAdvisories-BCVASH7N.mjs";import{describeErrorLevelFindings as n,errorAdvisoryNames as c,errorPlatformDiagnosticNames as l,sortedUniqueNames as x}from"./packem_shared/describeErrorLevelFindings-vzaGS9KL.mjs";import{CAPABILITY_PROBES as E}from"./packem_shared/CAPABILITY_PROBES-brcmKenl.mjs";import{CodegenDiagnosticError as A,diagnosticAt as g}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as C,discoverAgents as N}from"./packem_shared/AGENTS_FILENAME-isdHqPIt.mjs";import{isTestPath as R,listLunoraSourceFiles as T}from"./packem_shared/isTestPath-C3QumE88.mjs";import{default as I}from"./packem_shared/discoverAuthApiCalls-CScPrUD-.mjs";import{CONTAINERS_FILENAME as F,discoverContainers as L}from"./packem_shared/CONTAINERS_FILENAME-mK4cZpcz.mjs";import{default as P}from"./packem_shared/discoverCrons-B1_NUt19.mjs";import{capabilitiesUsedBy as b,createTargetScope as y,foldCapabilitySignals as U,mayReadCapabilityContext as G,sourceCapabilitySignals as H}from"./packem_shared/capabilitiesUsedBy-DjRHg-Zk.mjs";import{FLAGS_FILENAME as B,discoverFlags as k}from"./packem_shared/FLAGS_FILENAME-BQk3SX8D.mjs";import{default as K}from"./packem_shared/discoverFunctions-CJG4S6CK.mjs";import{default as z}from"./packem_shared/discoverHttpRoutes-DCDgDIYv.mjs";import{default as q}from"./packem_shared/discoverHyperdriveCalls-CL-d0IVo.mjs";import{default as J}from"./packem_shared/discoverInserts-BcoTjXqI.mjs";import{d as X}from"./packem_shared/index-CN8FVvr-.mjs";import{default as $}from"./packem_shared/discoverMigrations-BWxx8Wv9.mjs";import{MUTATORS_FILENAME as re,discoverMutators as oe}from"./packem_shared/MUTATORS_FILENAME-Cy9h3EVW.mjs";import{default as ae}from"./packem_shared/discoverNondeterministicCalls-mFJNU8qY.mjs";import{NOTIFY_FILENAME as se,discoverNotifyCalls as fe,discoverNotifyChannels as me,discoverNotifyConfig as de}from"./packem_shared/NOTIFY_FILENAME-9to_l_Kh.mjs";import{default as ne}from"./packem_shared/readPackageDependencies-RHhGiz0k.mjs";import{default as le}from"./packem_shared/discoverQueries-CxQRVuIV.mjs";import{QUEUES_FILENAME as Se,discoverQueues as Ee}from"./packem_shared/QUEUES_FILENAME-Civ-7SiI.mjs";import{default as Ae}from"./packem_shared/discoverR2sqlCalls-B4oeTYEM.mjs";import{default as ve}from"./packem_shared/discoverRlsProcedures-Cl6UKT7L.mjs";import{default as Ne}from"./packem_shared/discoverRlsMetadata-D0B4nCmG.mjs";import{discoverSandboxUsage as Re}from"./packem_shared/discoverSandboxUsage--Z1vx7GM.mjs";import{default as he}from"./packem_shared/discoverSchema-CGAFQxFU.mjs";import{readServiceBindings as _e,resolveServiceBindings as Fe}from"./packem_shared/readServiceBindings-BA49C6aN.mjs";import{SHAPES_FILENAME as Me,discoverShapes as Pe}from"./packem_shared/SHAPES_FILENAME-DVJbfDZ8.mjs";import{default as be}from"./packem_shared/discoverStorageRulesMetadata-CitX6ziW.mjs";import{WORKFLOWS_FILENAME as Ue,discoverWorkflows as Ge}from"./packem_shared/WORKFLOWS_FILENAME-kXq07aGl.mjs";import{emitApp as je}from"./packem_shared/emitApp-C0shqv7S.mjs";import{isD1GlobalTable as ke,isHyperdriveGlobalTable as We}from"./packem_shared/isD1GlobalTable-udvHAAzD.mjs";import{buildOpenApiDocument as Ve,emitOpenApi as ze,emitOpenApiModule as Qe}from"./packem_shared/buildOpenApiDocument-DWdj2jvW.mjs";import{OPENRPC_VERSION as we,buildOpenRpcDocument as Je,emitOpenRpc as Ye,emitOpenRpcModule as Xe}from"./packem_shared/OPENRPC_VERSION-DfSmacMR.mjs";import{DEFAULT_TARGET as $e,platformMatrixIds as er,readProjectTarget as rr,resolveCodegenTarget as or}from"./packem_shared/DEFAULT_TARGET-3OLdJhTj.mjs";import{loadProjectConfig as ar,readProjectConfigLiterals as ir}from"./packem_shared/loadProjectConfig-B7RmxIeD.mjs";import{PROJECT_CONFIG_FILENAMES as fr,findCodegenConfigFile as mr,findProjectConfigFile as dr,projectConfigCandidatePaths as pr}from"./packem_shared/PROJECT_CONFIG_FILENAMES-CLfsyvjA.mjs";import{SCHEMA_SNAPSHOT_FILENAME as cr,runCodegen as lr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-DB8KkcgP.mjs";import{SchemaSnapshotParseError as Sr,buildSchemaSnapshot as Er,evaluateSchemaDrift as ur,parseSchemaSnapshot as Ar}from"./packem_shared/SchemaSnapshotParseError-H9eQX4ui.mjs";import{default as vr}from"./packem_shared/fingerprintSchemaSources-BKXkgkj4.mjs";import{schemaFromIr as Nr}from"./packem_shared/schemaFromIr-CByOxuZb.mjs";import{LUNORA_ERROR_CODES as Rr,validatorIrToJsonSchema as Tr}from"./packem_shared/LUNORA_ERROR_CODES-CIAJQeKB.mjs";import{SDK_LANGUAGES as Ir,SDK_TARGETS as _r,generateSdk as Fr}from"./sdk/index.mjs";import{redact as Mr,secretKindOf as Pr}from"./packem_shared/redact-Cy14LEnc.mjs";import{default as br}from"./packem_shared/emitDrizzleSchema-bct1OuH5.mjs";import{e as Ur}from"./packem_shared/server-CeYggUIZ.mjs";import{e as Hr}from"./packem_shared/shard-ByB2lGh0.mjs";import{G as Br}from"./packem_shared/shared-8vTRkL2-.mjs";import{MESSAGE_SOLUTIONS as Wr,findSolutionByMessage as Kr}from"@lunora/errors";import{createCodegenProject as zr,findTsconfig as Qr,refreshCodegenProject as qr,tsconfigFingerprint as wr}from"./packem_shared/createCodegenProject-ClPr_MXM.mjs";import{s as Yr,t as Xr,u as Zr}from"./packem_shared/shard-runtime-ByYXjCKY.mjs";import{emitApi as eo,emitCollections as ro,emitInternalApi as oo}from"./packem_shared/emitApi-zynTVppI.mjs";import{emitCrons as ao,emitScheduler as io,emitVectors as so,emitWranglerCronTriggers as fo}from"./packem_shared/emitCrons-DF9vt_z_.mjs";import{emitDataModel as po}from"./packem_shared/emitDataModel-CuFqq97x.mjs";import{emitFunctions as co}from"./packem_shared/emitFunctions-D7mopPiT.mjs";import{isTypedSchema as xo}from"./packem_shared/isTypedSchema-CDv3pJB6.mjs";const e="0.0.0";export{C as AGENTS_FILENAME,E as CAPABILITY_PROBES,F as CONTAINERS_FILENAME,A as CodegenDiagnosticError,$e as DEFAULT_TARGET,B as FLAGS_FILENAME,Br as GENERATED_HEADER,Rr as LUNORA_ERROR_CODES,Wr as LUNORA_SOLUTION_RULES,re as MUTATORS_FILENAME,se as NOTIFY_FILENAME,we as OPENRPC_VERSION,fr as PROJECT_CONFIG_FILENAMES,Se as QUEUES_FILENAME,cr as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,Ir as SDK_LANGUAGES,_r as SDK_TARGETS,Me as SHAPES_FILENAME,Sr as SchemaSnapshotParseError,e as VERSION,Ue as WORKFLOWS_FILENAME,Ve as buildOpenApiDocument,Je as buildOpenRpcDocument,Er as buildSchemaSnapshot,b as capabilitiesUsedBy,zr as createCodegenProject,y as createTargetScope,n as describeErrorLevelFindings,g as diagnosticAt,a as diffSchemaSnapshots,N as discoverAgents,I as discoverAuthApiCalls,L as discoverContainers,P as discoverCrons,k as discoverFlags,K as discoverFunctions,z as discoverHttpRoutes,q as discoverHyperdriveCalls,J as discoverInserts,X as discoverMaskProcedures,$ as discoverMigrations,oe as discoverMutators,ae as discoverNondeterministicCalls,fe as discoverNotifyCalls,me as discoverNotifyChannels,de as discoverNotifyConfig,le as discoverQueries,Ee as discoverQueues,Ae as discoverR2sqlCalls,Ne as discoverRlsMetadata,ve as discoverRlsProcedures,Re as discoverSandboxUsage,he as discoverSchema,Pe as discoverShapes,be as discoverStorageRulesMetadata,Ge as discoverWorkflows,Yr as emitAgents,eo as emitApi,je as emitApp,ro as emitCollections,Xr as emitContainers,ao as emitCrons,po as emitDataModel,br as emitDrizzleSchema,co as emitFunctions,oo as emitInternalApi,ze as emitOpenApi,Qe as emitOpenApiModule,Ye as emitOpenRpc,Xe as emitOpenRpcModule,io as emitScheduler,Ur as emitServer,Hr as emitShard,so as emitVectors,Zr as emitWorkflows,fo as emitWranglerCronTriggers,c as errorAdvisoryNames,l as errorPlatformDiagnosticNames,ur as evaluateSchemaDrift,mr as findCodegenConfigFile,Kr as findLunoraSolution,dr as findProjectConfigFile,Qr as findTsconfig,vr as fingerprintSchemaSources,U as foldCapabilitySignals,f as formatAdvisories,Fr as generateSdk,ke as isD1GlobalTable,We as isHyperdriveGlobalTable,R as isTestPath,xo as isTypedSchema,m as lintSchema,T as listLunoraSourceFiles,ar as loadProjectConfig,G as mayReadCapabilityContext,Ar as parseSchemaSnapshot,er as platformMatrixIds,pr as projectConfigCandidatePaths,ne as readPackageDependencies,ir as readProjectConfigLiterals,rr as readProjectTarget,_e as readServiceBindings,Mr as redact,qr as refreshCodegenProject,or as resolveCodegenTarget,Fe as resolveServiceBindings,lr as runCodegen,Nr as schemaFromIr,Pr as secretKindOf,i as serializeSchemaSnapshot,x as sortedUniqueNames,H as sourceCapabilitySignals,d as toAdvisorContext,wr as tsconfigFingerprint,Tr as validatorIrToJsonSchema};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{existsSync as M,readFileSync as Ge,mkdirSync as Bt,writeFileSync as gr,rmSync as ye,readdirSync as Cn}from"node:fs";import{dirname as Vt,join as E,relative as Tn}from"node:path";import{performance as ht}from"node:perf_hooks";import{runAdvisor as pr}from"@lunora/advisor";import{LunoraError as _}from"@lunora/errors";import{serializeSchemaSnapshot as mr}from"./SCHEMA_SNAPSHOT_VERSION-C7Um0EnM.mjs";import{toAdvisorContext as hr}from"./formatAdvisories-BCVASH7N.mjs";import{Node as r,SyntaxKind as d,Project as Ut,ts as vr,VariableDeclarationKind as Er}from"ts-morph";import{listLunoraSourceFiles as A,lunoraRelativePath as w,bindingKeyName as ce,collectCallRows as C,findObjectProperty as V,collectSecurityCallRows as xr,propertyInitializer as R,listSecurityScanFiles as Ye,objectLiteralFromCallbackBody as On,limitNameOf as kn,optionsObjectLiteral as Rn,handlerOf as Sr,collectNodeRows as ne,chainRootOf as Qe,outermostValueWrapper as I,isWriteTarget as Xe,isSameNode as y,unwrapExpression as h,isConstDeclaration as ie,memberAccessOf as Wt,returningFunctionOf as wt,walkChain as Ar,RUN_METHODS as Fn,functionReferenceSegments as yr,isTestPath as br,isFunctionLike as re,functionKeyOf as Ln}from"./isTestPath-C3QumE88.mjs";import{b as Q,d as j,f as L,g as qt,c as x,a as jt,w as Ht,k as Nr,l as Pr,h as wr,m as Ir,j as It,i as Cr}from"./attribution-CG8-kUcl.mjs";import{a as Fs,r as vt,i as G,b as Tr,m as Dn,c as Je,e as Gt,E as Mn,C as _n,d as Or,f as kr,g as Rr}from"./context-root-CNR6TAsP.mjs";import{a as P,i as Fr,c as ee,d as Kn,e as Lr,f as Dr,g as zn}from"./classify-procedure-call-BkaeM9Ej.mjs";import{a as S,s as Mr}from"./property-name-7cBlgK_O.mjs";import{b as _r,a as Ze}from"./module-specifiers-BctA0m_p.mjs";import{r as et,s as Kr}from"./parse-validator-iVTounLK.mjs";import zr from"./discoverAuthApiCalls-CScPrUD-.mjs";import{i as z,r as $n}from"./database-calls-UPlhi3Ks.mjs";import $r from"./discoverHyperdriveCalls-CL-d0IVo.mjs";import{diagnosticAt as de}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{m as Yt,a as Be,s as Bn,d as Br}from"./index-CN8FVvr-.mjs";import{MUTATORS_FILENAME as Vr,isDefineMutatorCallee as Ur,mutatorServerImplOf as Wr,discoverMutators as qr}from"./MUTATORS_FILENAME-Cy9h3EVW.mjs";import jr from"./discoverNondeterministicCalls-mFJNU8qY.mjs";import{discoverNotifyConfig as Hr,discoverNotifyCalls as Gr}from"./NOTIFY_FILENAME-9to_l_Kh.mjs";import Yr from"./discoverR2sqlCalls-B4oeTYEM.mjs";import Qr from"./discoverRlsProcedures-Cl6UKT7L.mjs";import{s as Qt,n as Xr}from"./dispatch-namespace-DwTjD7BU.mjs";import{secretKindOf as Jr,redact as Zr,isHeuristicSecretKind as eo,isSecretishName as to}from"./redact-Cy14LEnc.mjs";import{readProjectConfigLiterals as Vn,readMergeDurableObjects as so}from"./loadProjectConfig-B7RmxIeD.mjs";import{a as Le,d as no,r as io}from"./modules-l-Db0C4S.mjs";import{WORKFLOWS_FILENAME as ro,discoverWorkflows as oo}from"./WORKFLOWS_FILENAME-kXq07aGl.mjs";import{r as ao}from"./json-data-Chfs2Cz5.mjs";import{a as co,I as lo,g as uo,G as Un,d as fo,i as go}from"./shared-8vTRkL2-.mjs";import{createCodegenProject as po}from"./createCodegenProject-ClPr_MXM.mjs";import{findTsconfig as wE,refreshCodegenProject as IE,tsconfigFingerprint as CE}from"./createCodegenProject-ClPr_MXM.mjs";import{CAPABILITIES as mo,usedCapabilities as ho}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{isD1GlobalTable as Wn,isHyperdriveGlobalTable as qn}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as vo}from"./AGENTS_FILENAME-isdHqPIt.mjs";import{discoverContainers as Eo}from"./CONTAINERS_FILENAME-mK4cZpcz.mjs";import xo from"./discoverCrons-B1_NUt19.mjs";import{contextPropertiesRead as So,fileWiresRequestSecretTool as Ao,createTargetScope as yo,discoverFeatureUsage as bo}from"./capabilitiesUsedBy-DjRHg-Zk.mjs";import jn from"./readPackageDependencies-RHhGiz0k.mjs";import{PROJECT_CONFIG_FILENAMES as No,findProjectConfigFile as Po}from"./PROJECT_CONFIG_FILENAMES-CLfsyvjA.mjs";import{discoverQueueDeclarations as wo}from"./QUEUES_FILENAME-Civ-7SiI.mjs";import{discoverSandboxUsage as Io}from"./discoverSandboxUsage--Z1vx7GM.mjs";import{resolveServiceBindings as Co}from"./readServiceBindings-BA49C6aN.mjs";import To from"./discoverStorageRulesMetadata-CitX6ziW.mjs";import{resolveCodegenTarget as Ct,gatePlatformFeatures as Oo,readTargetDiagnostics as ko,vectorizeDimensionDiagnostics as Ro,liveStreamsDeliveryAuthorizationDiagnostic as Fo,socketRoutesDeliveryAuthorizationDiagnostic as Lo,studioPlatformFor as Do,platformFeatureAvailable as Mo}from"./DEFAULT_TARGET-3OLdJhTj.mjs";import{i as _o}from"./schema-BgM8A3XV.mjs";import{b as Hn,e as Ko}from"./shard-ByB2lGh0.mjs";import{e as zo,a as $o}from"./server-
|
|
1
|
+
import{existsSync as M,readFileSync as Ge,mkdirSync as Bt,writeFileSync as gr,rmSync as ye,readdirSync as Cn}from"node:fs";import{dirname as Vt,join as E,relative as Tn}from"node:path";import{performance as ht}from"node:perf_hooks";import{runAdvisor as pr}from"@lunora/advisor";import{LunoraError as _}from"@lunora/errors";import{serializeSchemaSnapshot as mr}from"./SCHEMA_SNAPSHOT_VERSION-C7Um0EnM.mjs";import{toAdvisorContext as hr}from"./formatAdvisories-BCVASH7N.mjs";import{Node as r,SyntaxKind as d,Project as Ut,ts as vr,VariableDeclarationKind as Er}from"ts-morph";import{listLunoraSourceFiles as A,lunoraRelativePath as w,bindingKeyName as ce,collectCallRows as C,findObjectProperty as V,collectSecurityCallRows as xr,propertyInitializer as R,listSecurityScanFiles as Ye,objectLiteralFromCallbackBody as On,limitNameOf as kn,optionsObjectLiteral as Rn,handlerOf as Sr,collectNodeRows as ne,chainRootOf as Qe,outermostValueWrapper as I,isWriteTarget as Xe,isSameNode as y,unwrapExpression as h,isConstDeclaration as ie,memberAccessOf as Wt,returningFunctionOf as wt,walkChain as Ar,RUN_METHODS as Fn,functionReferenceSegments as yr,isTestPath as br,isFunctionLike as re,functionKeyOf as Ln}from"./isTestPath-C3QumE88.mjs";import{b as Q,d as j,f as L,g as qt,c as x,a as jt,w as Ht,k as Nr,l as Pr,h as wr,m as Ir,j as It,i as Cr}from"./attribution-CG8-kUcl.mjs";import{a as Fs,r as vt,i as G,b as Tr,m as Dn,c as Je,e as Gt,E as Mn,C as _n,d as Or,f as kr,g as Rr}from"./context-root-CNR6TAsP.mjs";import{a as P,i as Fr,c as ee,d as Kn,e as Lr,f as Dr,g as zn}from"./classify-procedure-call-BkaeM9Ej.mjs";import{a as S,s as Mr}from"./property-name-7cBlgK_O.mjs";import{b as _r,a as Ze}from"./module-specifiers-BctA0m_p.mjs";import{r as et,s as Kr}from"./parse-validator-iVTounLK.mjs";import zr from"./discoverAuthApiCalls-CScPrUD-.mjs";import{i as z,r as $n}from"./database-calls-UPlhi3Ks.mjs";import $r from"./discoverHyperdriveCalls-CL-d0IVo.mjs";import{diagnosticAt as de}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{m as Yt,a as Be,s as Bn,d as Br}from"./index-CN8FVvr-.mjs";import{MUTATORS_FILENAME as Vr,isDefineMutatorCallee as Ur,mutatorServerImplOf as Wr,discoverMutators as qr}from"./MUTATORS_FILENAME-Cy9h3EVW.mjs";import jr from"./discoverNondeterministicCalls-mFJNU8qY.mjs";import{discoverNotifyConfig as Hr,discoverNotifyCalls as Gr}from"./NOTIFY_FILENAME-9to_l_Kh.mjs";import Yr from"./discoverR2sqlCalls-B4oeTYEM.mjs";import Qr from"./discoverRlsProcedures-Cl6UKT7L.mjs";import{s as Qt,n as Xr}from"./dispatch-namespace-DwTjD7BU.mjs";import{secretKindOf as Jr,redact as Zr,isHeuristicSecretKind as eo,isSecretishName as to}from"./redact-Cy14LEnc.mjs";import{readProjectConfigLiterals as Vn,readMergeDurableObjects as so}from"./loadProjectConfig-B7RmxIeD.mjs";import{a as Le,d as no,r as io}from"./modules-l-Db0C4S.mjs";import{WORKFLOWS_FILENAME as ro,discoverWorkflows as oo}from"./WORKFLOWS_FILENAME-kXq07aGl.mjs";import{r as ao}from"./json-data-Chfs2Cz5.mjs";import{a as co,I as lo,g as uo,G as Un,d as fo,i as go}from"./shared-8vTRkL2-.mjs";import{createCodegenProject as po}from"./createCodegenProject-ClPr_MXM.mjs";import{findTsconfig as wE,refreshCodegenProject as IE,tsconfigFingerprint as CE}from"./createCodegenProject-ClPr_MXM.mjs";import{CAPABILITIES as mo,usedCapabilities as ho}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{isD1GlobalTable as Wn,isHyperdriveGlobalTable as qn}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as vo}from"./AGENTS_FILENAME-isdHqPIt.mjs";import{discoverContainers as Eo}from"./CONTAINERS_FILENAME-mK4cZpcz.mjs";import xo from"./discoverCrons-B1_NUt19.mjs";import{contextPropertiesRead as So,fileWiresRequestSecretTool as Ao,createTargetScope as yo,discoverFeatureUsage as bo}from"./capabilitiesUsedBy-DjRHg-Zk.mjs";import jn from"./readPackageDependencies-RHhGiz0k.mjs";import{PROJECT_CONFIG_FILENAMES as No,findProjectConfigFile as Po}from"./PROJECT_CONFIG_FILENAMES-CLfsyvjA.mjs";import{discoverQueueDeclarations as wo}from"./QUEUES_FILENAME-Civ-7SiI.mjs";import{discoverSandboxUsage as Io}from"./discoverSandboxUsage--Z1vx7GM.mjs";import{resolveServiceBindings as Co}from"./readServiceBindings-BA49C6aN.mjs";import To from"./discoverStorageRulesMetadata-CitX6ziW.mjs";import{resolveCodegenTarget as Ct,gatePlatformFeatures as Oo,readTargetDiagnostics as ko,vectorizeDimensionDiagnostics as Ro,liveStreamsDeliveryAuthorizationDiagnostic as Fo,socketRoutesDeliveryAuthorizationDiagnostic as Lo,studioPlatformFor as Do,platformFeatureAvailable as Mo}from"./DEFAULT_TARGET-3OLdJhTj.mjs";import{i as _o}from"./schema-BgM8A3XV.mjs";import{b as Hn,e as Ko}from"./shard-ByB2lGh0.mjs";import{e as zo,a as $o}from"./server-CeYggUIZ.mjs";import{emitDataModel as Bo}from"./emitDataModel-CuFqq97x.mjs";import{i as Vo,a as Uo,e as Wo,b as qo,d as jo,c as Ho}from"./unwrap-handler-return-CGdJGvGh.mjs";import Go from"./discoverFunctions-CJG4S6CK.mjs";import Yo from"./discoverHttpRoutes-DCDgDIYv.mjs";import Qo from"./discoverInserts-BcoTjXqI.mjs";import{e as Gn}from"./exported-procedure-chains-D1WlRfqJ.mjs";import Xo from"./discoverMigrations-BWxx8Wv9.mjs";import Jo from"./discoverQueries-CxQRVuIV.mjs";import Zo from"./discoverRlsMetadata-D0B4nCmG.mjs";import ea from"./discoverSchema-CGAFQxFU.mjs";import{discoverShapes as ta}from"./SHAPES_FILENAME-DVJbfDZ8.mjs";import{i as sa}from"./reserved-words-CW1QFbTd.mjs";import{emitApp as na}from"./emitApp-C0shqv7S.mjs";import{readJsonSync as ia}from"@visulima/fs";import{buildSchemaSnapshot as ra}from"./SchemaSnapshotParseError-H9eQX4ui.mjs";import{buildOpenApiDocument as oa,emitOpenApiModule as aa}from"./buildOpenApiDocument-DWdj2jvW.mjs";import{buildOpenRpcDocument as ca,emitOpenRpcModule as la}from"./OPENRPC_VERSION-DfSmacMR.mjs";import{v as da,t as ua,u as fa,s as ga,w as pa}from"./shard-runtime-ByYXjCKY.mjs";import{emitCollections as ma,emitSeed as ha,emitApi as va,emitInternalApi as Ea}from"./emitApi-zynTVppI.mjs";import{emitCrons as xa,emitScheduler as Sa,emitShardRegistry as Aa,emitDurableObjects as ya,emitVectors as ba,emitWranglerCronTriggers as Na}from"./emitCrons-DF9vt_z_.mjs";import Pa from"./emitDrizzleSchema-bct1OuH5.mjs";import{LAZY_FUNCTION_DIRECTORY as Yn,emitFunctions as wa,emitLazyFunctionModules as Ia}from"./emitFunctions-D7mopPiT.mjs";const Ca=(e,t=!1)=>{if(e.length===0)return"";const s=fo(t),n=e.map(c=>{if(co(c.exportName,"live stream export name"),!lo.test(c.filePath))throw new Error(`@lunora/codegen: live stream file path is not safe to import: ${JSON.stringify(c.filePath)}`);return`import type { ${c.exportName} as ${c.exportName}Stream } from "../${c.filePath}.js";`}),i=e.map(c=>{const l=c.topics.map(u=>{uo(u.name,"live topic name");const f=`(typeof ${c.exportName}Stream)["topics"]["${u.name}"]`,g=`LiveTopicRef<LiveTopicPayload<${f}>>`,m=JSON.stringify(c.id);if(u.fields.length===0)return` ${u.name}: (): ${g} => ({ __lunoraLive: ${m}, topic: ${JSON.stringify(u.name)} }),`;const v=u.fields.map($=>`\${encodeURIComponent(key.${$})}`).join(":");return` ${u.name}: (key: LiveTopicKey<${f}>): ${g} => ({
|
|
2
2
|
__lunoraLive: ${m},
|
|
3
3
|
topic: \`${u.name}:${v}\`,
|
|
4
4
|
}),`});return` ${c.exportName}: {
|
|
@@ -18,7 +18,7 @@ export const live = {
|
|
|
18
18
|
${i.join(`
|
|
19
19
|
`)}
|
|
20
20
|
};
|
|
21
|
-
`},Qn=new Set(["delete","get","head","options","patch","post","put"]),Ta=new Set(["handler","stream"]),Oa=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,Ls=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),ka=e=>{if(!r.isCallExpression(e))return;const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!Qn.has(t.getName()))return;const s=t.getExpression();if(!r.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!r.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},Ra=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;r.isCallExpression(s);){const n=s.getExpression();if(!r.isPropertyAccessExpression(n)||Qn.has(n.getName()))break;s=n.getExpression()}return ka(s)},Fa=e=>{for(const t of e.getDescendantsOfKind(d.PropertyAccessExpression))if(Ls.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=t.getExpression();if(r.isIdentifier(s)&&Ls.has(s.getText()))return!0}return!1},La=(e,t)=>{const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const n=s.getExpression();if(!r.isPropertyAccessExpression(n)||!Ta.has(n.getName()))return;const i=Ra(s);if(!i||!Oa.test(i.path))return;const o=s.getArguments()[0],a=o!==void 0&&(r.isArrowFunction(o)||r.isFunctionExpression(o))&&Fa(o);return{exportName:j(e)??e.getName(),file:t,method:i.method,path:i.path,usesGuard:a}},Da=(e,t)=>{const s=[];for(const n of Q(e)){const i=La(n,t);i&&s.push(i)}return s},Ma=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Da(i,w(t,n)))}return s},_a=e=>{const t=e.getText(),s=n=>{const i=n.getNameNode();return r.isIdentifier(i)&&i.getText()===t};for(const n of e.getAncestors())if(!(!r.isArrowFunction(n)&&!r.isFunctionExpression(n)&&!r.isFunctionDeclaration(n)))for(const i of n.getParameters()){const o=i.getDescendantsOfKind(d.BindingElement).find(a=>s(a));if(o!==void 0)return o}},Ka=e=>{let t=e;for(;;){const s=t.getParent();if(!r.isObjectBindingPattern(s))return;const n=s.getParent();if(r.isBindingElement(n)){t=n;continue}return r.isParameterDeclaration(n)?ce(t):void 0}},za=e=>{const t=e.getText();if(!e.getAncestors().some(o=>{const a=r.isFunctionLikeDeclaration(o)||r.isArrowFunction(o)?o.getParameters()[1]:void 0,c=a?.getNameNode();return a!==void 0&&(r.isIdentifier(c)?c.getText()===t:a.getDescendantsOfKind(d.BindingElement).some(l=>l.getName()===t))&&Fs(a)}))return!1;const n=L(e),i=r.isParameterDeclaration(n)?n:n?.getFirstAncestorByKind(d.Parameter);return i!==void 0&&(r.isParameterDeclaration(n)||r.isBindingElement(n))&&Fs(i)},Ds=(e,t)=>{const s=e.getParent();if(r.isPropertyAccessExpression(s)&&s.getNameNode()===e||r.isPropertyAssignment(s)&&s.getNameNode()===e)return!1;if(e.getText()===t)return!0;const n=_a(e);return n!==void 0&&Ka(n)===t?!0:t==="args"&&za(e)},Xn=(e,t)=>r.isIdentifier(e)?Ds(e,t):e.getDescendantsOfKind(d.Identifier).some(s=>Ds(s,t)),$a=e=>{let t=e;for(;r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t)||r.isNonNullExpression(t);)t=t.getExpression();return r.isIdentifier(t)?t:void 0},Ms=e=>{const t=r.isIdentifier(e)?L(e):void 0;return r.isVariableDeclaration(t)&&r.isIdentifier(t.getNameNode())&&!qt(t)?t.getInitializer():void 0},Tt=e=>Xn(e,"args"),Y=e=>{if(!r.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>r.isArrowFunction(a)||r.isFunctionExpression(a)||r.isFunctionDeclaration(a));if(s===void 0)return;const n=e.getStart();let i,o=-1;for(const a of s.getDescendantsOfKind(d.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<n&&l>o&&(i=c,o=l)}return i},q=e=>{if(Tt(e))return!0;const t=Y(e);return t!==void 0&&Tt(t)},Ba=e=>{if(r.isCallExpression(e)||r.isNewExpression(e))return!1;const t=Y(e);return t===void 0||!(r.isCallExpression(t)||r.isNewExpression(t))},le=e=>{if(vt(e))return!0;const t=Ms(e);if(t!==void 0&&vt(t))return!0;const s=t??e;return(r.isIdentifier(s)?[s]:s.getDescendantsOfKind(d.Identifier)).some(i=>{const o=Ms(i);return o!==void 0&&vt(o)})},De=(e,t)=>Xn(e,t),Va=(e,t)=>{if(De(e,t))return!0;const s=Y(e);if(s!==void 0&&De(s,t))return!0;const n=$a(e);if(n!==void 0){const i=Y(n);return i!==void 0&&De(i,t)}return!1},Ua=e=>!r.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:G(e.getExpression(),["ai"]),Wa=(e,t)=>{if(!Ua(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!q(s)||le(s)))return{scope:x(e),file:t,line:e.getStartLineNumber()}},qa=(e,t)=>C(e,t,Wa),ja=new Set(["generateText","streamText"]),Ha=new Set(["messages","prompt","system"]),Ga=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","patchIf","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"]}],Ya=(e,t)=>Ga.some(s=>s.methods.has(t)&&s.prefixes.some(n=>e===n||e.startsWith(`${n}.`))),Qa=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return;const s=t.getName(),n=[Tr(t.getExpression()),t.getExpression().getText()].find(i=>i!==void 0&&Ya(i,s));return n===void 0?void 0:`${n}.${s}`},Xa=e=>{for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=Qa(t);if(s!==void 0)return s}},Ja=e=>{const t=new Set,s=e.getFirstAncestor(o=>r.isArrowFunction(o)||r.isFunctionExpression(o)||r.isFunctionDeclaration(o)),[n]=s?.getParameters()??[],i=n?.getNameNode();if(i===void 0||!r.isObjectBindingPattern(i))return t;for(const o of i.getElements()){const a=ce(o),c=o.getNameNode();if(a==="args"&&r.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},Za=e=>{if(Tt(e))return!0;const t=Ja(e);return t.size===0?!1:e.getDescendantsOfKind(d.Identifier).some(s=>t.has(s.getText()))},ec=e=>{for(const t of e.getProperties()){if(!r.isPropertyAssignment(t)||!Ha.has(S(t)))continue;const s=t.getInitializer();if(s!==void 0&&Za(s))return!0}return!1},tc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=P(n.getExpression());if(i===void 0||!ja.has(i))continue;const[o]=n.getArguments();if(o===void 0||!r.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(d.CallExpression))if(P(c.getExpression())==="tool"&&(a=Xa(c),a!==void 0))break;a!==void 0&&s.push({scope:x(n),file:t,line:n.getStartLineNumber(),method:i,sideEffect:a,userInputDerived:ec(o)})}return s},sc=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...tc(i,w(t,n)))}return s},nc=e=>G(e,["fetch"]),ic=(e,t)=>{if(!nc(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!q(s)))return{scope:x(e),file:t,line:e.getStartLineNumber()}},rc=(e,t)=>C(e,t,ic),Xt=(e,t=new Set)=>{if(t.has(e))return!0;t.add(e);try{return e.getProperties().some(s=>{if(!r.isSpreadAssignment(s))return!1;const n=et(s.getExpression());return n===void 0||Xt(n,t)})}finally{t.delete(e)}},oc=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=V(t,"args");if(!s)return{objects:[],opaque:!1};if(!r.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer(),i=n===void 0?void 0:et(n);return i===void 0?{objects:[],opaque:!0}:{objects:[i],opaque:Xt(i)}},ac=e=>{const t=[];let s=!1,n=e;for(;r.isCallExpression(n);){const i=n.getExpression();if(!r.isPropertyAccessExpression(i))break;if(i.getName()==="input"){const o=n.getArguments()[0],a=o!==void 0&&r.isExpression(o)?et(o):void 0;a===void 0?s=!0:(t.push(a),s||=Xt(a))}n=i.getExpression()}return{objects:t,opaque:s}},Jt=(e,t)=>t?ac(t):oc(e),Jn=(e,t)=>{if(t.has(e))return[];t.add(e);try{return e.getProperties().flatMap(s=>{if(r.isSpreadAssignment(s)){const n=et(s.getExpression());return n===void 0?[]:Jn(n,t)}return r.isPropertyAssignment(s)||r.isShorthandPropertyAssignment(s)?[S(s)]:[]})}finally{t.delete(e)}},cc=e=>e.flatMap(t=>Jn(t,new Set)),lc=new Set(["check","length","max"]),Ot=e=>{let t=e;for(;;){const s=t.getParent();if(!s||!r.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;const n=s.getParent();if(!n||!r.isCallExpression(n)||n.getExpression()!==s)return!1;if(lc.has(s.getName()))return!0;t=n}},kt=e=>_r(e)||e==="@lunora/values",dc=e=>{const t=new Set(["v"]);for(const s of Fr(e,"v",kt))t.add(s);for(const s of e.getImportDeclarations()){const n=s.getNamespaceImport();n&&kt(s.getModuleSpecifierValue())&&t.add(`${n.getText()}.v`)}return t},uc=(e,t)=>{const s=new Map;for(const n of e.getVariableStatements())for(const i of n.getDeclarations()){const o=i.getNameNode(),a=i.getInitializer();if(!(!r.isObjectBindingPattern(o)||!a||!t.has(a.getText())))for(const c of o.getElements())c.getDotDotDotToken()||s.set(c.getName(),c.getPropertyNameNode()?.getText()??c.getName())}return s},fc=e=>(e.getSymbol()?.getDeclarations()??[]).some(t=>!t.getSourceFile().isDeclarationFile()&&!r.isImportSpecifier(t)&&!r.isNamespaceImport(t)&&!r.isImportClause(t)),gc=e=>(e.getSymbol()?.getDeclarations()??[]).some(t=>r.isNamespaceImport(t)&&kt(t.getFirstAncestorByKindOrThrow(d.ImportDeclaration).getModuleSpecifierValue())),Zt=(e,t)=>{if(!r.isCallExpression(e))return;const s=e.getExpression();if(r.isPropertyAccessExpression(s)){const n=s.getExpression();if(!t.namespaces.has(n.getText()))return;if(r.isIdentifier(n))return fc(n)?void 0:s.getName();const i=r.isPropertyAccessExpression(n)?n.getExpression():void 0;return r.isIdentifier(i)&&gc(i)?s.getName():void 0}if(r.isIdentifier(s))return t.destructured.get(s.getText())},pc=(e,t)=>{if(!r.isIdentifier(e))return;const s=e.getText(),n=t.getVariableDeclaration(s)?.getInitializer();return n&&(r.isArrowFunction(n)||r.isFunctionExpression(n))?n:t.getFunction(s)},mc=e=>{let t=e.getParent();for(;t&&!r.isFunctionLikeDeclaration(t);)t=t.getParent();return t},hc=e=>r.isReturnStatement(e)?e.getExpression():void 0,vc=e=>r.isArrowFunction(e)&&!r.isBlock(e.getBody())?[e.getBody()]:e.getDescendantsOfKind(d.ReturnStatement).filter(t=>mc(t)?.compilerNode===e.compilerNode).flatMap(t=>{const s=hc(t);return s?[s]:[]}),Zn=(e,t)=>{if(Zt(e,t)!==void 0)return e;if(r.isCallExpression(e)||r.isPropertyAccessExpression(e))return Zn(e.getExpression(),t)},Ec=(e,t)=>{const s=pc(e.getExpression(),e.getSourceFile());if(!s)return[];const n=Ot(e),i=new Set(vc(s).map(o=>Zn(o,t)).filter(o=>o!==void 0));return[s,...s.getDescendants()].flatMap(o=>{const a=Zt(o,t);return a===void 0?[]:[{bounded:Ot(o)||n&&i.has(o),factory:a}]})},xc=(e,t)=>[e,...e.getDescendants()].flatMap(s=>{const n=Zt(s,t),i=n===void 0?[]:[{bounded:Ot(s),factory:n}];return r.isCallExpression(s)?[...i,...Ec(s,t)]:i}),Sc=(e,t)=>{const s=[],n=[];for(const i of e)for(const o of i.getProperties()){if(!r.isPropertyAssignment(o))continue;const a=o.getInitializer();if(!a)continue;const c=xc(a,t),l=S(o);c.some(u=>u.factory==="any")?s.push(l):c.some(u=>u.factory==="string"&&!u.bounded)&&n.push(l)}return{anyArgs:s,unboundedStringArgs:n}},Ac=(e,t,s)=>{const n=e.getInitializer();if(!n||!r.isCallExpression(n))return;const i=ee(n);if(i?.visibility!=="public")return;const{objects:o}=Jt(n,i.receiver),{anyArgs:a,unboundedStringArgs:c}=Sc(o,s);if(!(a.length===0&&c.length===0))return{anyArgs:a,exportName:j(e)??e.getName(),file:t,line:n.getStartLineNumber(),unboundedStringArgs:c}},yc=(e,t)=>{const s=[],n=dc(e),i={destructured:uc(e,n),namespaces:n};for(const o of Q(e)){const a=Ac(o,t,i);a&&s.push(a)}return s},bc=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...yc(i,w(t,n)))}return s},Et=e=>e?.getKind()===d.TrueKeyword,Nc=e=>e?.getKind()===d.FalseKeyword,Pc=e=>e!==void 0&&r.isNumericLiteral(e)&&e.getLiteralValue()===0,wc=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Ic=e=>!e||!r.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>r.isCallExpression(t)&&P(t.getExpression())==="scim"),Cc=e=>e!==void 0&&r.isCallExpression(e)&&wc.has(P(e.getExpression())??""),Tc=e=>!e||!r.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>r.isStringLiteral(t)&&t.getLiteralText()==="*"),Oc=e=>{const t=R(e,"advanced"),s=R(e,"emailAndPassword"),n=R(e,"session");return{analyzable:!0,disableCsrfCheck:Et(R(t,"disableCSRFCheck")),emailPasswordEnabled:Et(R(s,"enabled")),requireEmailVerification:Et(R(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Ic(R(e,"plugins"))&&Cc(R(e,"database")),secureCookiesDisabled:Nc(R(t,"useSecureCookies")),sessionFreshAgeZero:Pc(R(n,"freshAge")),trustedOriginsWildcard:Tc(R(e,"trustedOrigins"))}},kc=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Rc=(e,t)=>{if(P(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&r.isObjectLiteralExpression(s)&&s.getProperties().some(o=>r.isSpreadAssignment(o)),i=s!==void 0&&r.isObjectLiteralExpression(s)&&!n?Oc(s):kc();return{scope:x(e),file:t,line:e.getStartLineNumber(),...i}},Fc=(e,t)=>xr(e,t,Rc),Lc=(e,t)=>{if(!r.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return Dn(e.getExpression(),t.matchReceiver)?s:void 0},Dc=(e,t,s)=>{const n=Lc(e.getExpression(),s);if(n===void 0)return;const i=e.getArguments()[s.argIndex];if(!(!i||!q(i)||le(i))&&!(s.requireUnmodifiedReach===!0&&!Ba(i)))return{scope:x(e),file:t,line:e.getStartLineNumber(),method:n}},tt=(e,t,s)=>C(e,t,(n,i)=>Dc(n,i,s)),Mc=new Set(["content","pdf","scrape","screenshot"]),_c=(e,t)=>tt(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Mc}),Kc=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),zc=new Set(["RateLimiter"]),$c=new Set(["extend"]),_s="lunora",Bc=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],ei=e=>{const t=[],s=[];let n=!1;for(const i of e.getProperties()){if(r.isSpreadAssignment(i)){n=!0;continue}if(r.isPropertyAssignment(i)){const o=S(i);t.push(o),i.getInitializer()?.getKind()===d.TrueKeyword&&s.push(o);continue}(r.isShorthandPropertyAssignment(i)||r.isMethodDeclaration(i))&&t.push(S(i))}return{analyzable:!n,presentKeys:t,trueKeys:s}},Rt=e=>e&&r.isObjectLiteralExpression(e)?ei(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Vc=e=>{const t=e&&(r.isArrowFunction(e)||r.isFunctionExpression(e))?e:void 0,s=t&&On(t.getBody());return s?ei(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Uc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=P(n.getExpression());i!==void 0&&(Kc.has(i)?s.push({callee:i,file:t,line:n.getStartLineNumber(),...Rt(n.getArguments()[0])}):$c.has(i)&&s.push({callee:i,file:t,line:n.getStartLineNumber(),...Vc(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(d.NewExpression)){const i=P(n.getExpression());i===void 0||!zc.has(i)||s.push({callee:i,file:t,line:n.getStartLineNumber(),...Rt(n.getArguments()[0])})}return s},Wc=e=>{for(const t of Bc){const s=E(e,t);if(!M(s))continue;const n=new Ut({compilerOptions:{allowJs:!0},skipFileDependencyResolution:!0,skipLoadingLibFiles:!0,useInMemoryFileSystem:!0}).createSourceFile(t,Ge(s,"utf8")),i=[];for(const o of n.getDescendantsOfKind(d.CallExpression))P(o.getExpression())===_s&&i.push({callee:_s,file:t,line:o.getStartLineNumber(),...Rt(o.getArguments()[0])});return i}return[]},qc=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of Ye(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);s.push(...Uc(o,n))}return s.push(...Wc(Vt(t))),s},Ks="ctx.containers.",jc=e=>{if(!e.startsWith(Ks))return!1;const t=e.slice(Ks.length);return t.length>0&&!t.includes(".")},Hc=(e,t)=>tt(e,t,{argIndex:0,matchReceiver:jc,methods:new Set(["get"])}),Gc=new Set(["allow","deny","setAllowed"]),Yc=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return!1;const s=V(t,"enableInternet");return s!==void 0&&r.isPropertyAssignment(s)&&r.isTrueLiteral(s.getInitializerOrThrow())},Qc=(e,t)=>{const s=e.getExpression();if(!(!r.isPropertyAccessExpression(s)||s.getName()!=="start"||!Yc(e)))return{detail:"enableInternet: true",scope:x(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},Xc=(e,t)=>{const s=e.getExpression();if(!r.isPropertyAccessExpression(s)||!Gc.has(s.getName()))return;const n=s.getExpression();if(!(!r.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),scope:x(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},Jc=(e,t)=>Qc(e,t)??Xc(e,t),Zc=(e,t)=>C(e,t,Jc),el=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="count")return;const s=t.getExpression();if(z(s)){const n=e.getArguments()[0];return n&&r.isStringLiteral(n)?n.getLiteralText():""}return r.isPropertyAccessExpression(s)&&z(s.getExpression())?s.getName():void 0},tl=e=>{const t=e.getExpression(),s=r.isPropertyAccessExpression(t)?t.getExpression():void 0;return e.getArguments()[s!==void 0&&z(s)?1:0]},sl=new Set(["baseWhere","relationBaseWhere","restrictsCounts","where"]),nl=e=>{if(e===void 0||!r.isObjectLiteralExpression(e))return;const t=[];for(const n of e.getProperties()){if(!r.isPropertyAssignment(n)&&!r.isShorthandPropertyAssignment(n))return;t.push(n.getName())}return t.length>0&&t.every(n=>sl.has(n))||t.some(n=>n==="AND"||n==="OR"||n==="NOT")?void 0:t},il=(e,t,s)=>{const n=new Map(s.map(i=>[i.name,i.aggregateIndexed===!0]));return C(e,t,(i,o)=>{const a=el(i);if(a===void 0)return;const c=nl(tl(i));return{file:o,indexed:n.get(a)!==!1,...c===void 0?{}:{filterFields:c},line:i.getStartLineNumber(),scope:x(i),table:a}})},rl=new Set(["defineExportSink","r2Sink","webhookExportSink"]),ol=e=>{const t=e.getExpression();if(!r.isIdentifier(t))return;const s=t.getText();return rl.has(s)?s:void 0},al=e=>{const t=[],s=[];for(const n of e.getProperties()){if(r.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(r.isPropertyAssignment(n)){const i=S(n);t.push(i);const o=n.getInitializer();o&&r.isStringLiteral(o)&&o.getLiteralText()===""&&s.push(i);continue}(r.isShorthandPropertyAssignment(n)||r.isMethodDeclaration(n)||r.isGetAccessorDeclaration(n))&&t.push(S(n))}return{analyzable:!0,emptyKeys:s,presentKeys:t}},cl=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of Ye(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);for(const a of o.getDescendantsOfKind(d.CallExpression)){const c=ol(a);if(c===void 0)continue;const l=a.getArguments()[0],u=l&&r.isObjectLiteralExpression(l)?al(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:u.analyzable,emptyKeys:u.emptyKeys,factory:c,file:n,line:a.getStartLineNumber(),presentKeys:u.presentKeys})}}return s},ll=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),dl=new Set(["dbRateLimit","rateLimit"]),ul=e=>{const t=Rn(e);if(!t)return!1;const s=V(t,"failOpen");return s!==void 0&&r.isPropertyAssignment(s)&&s.getInitializer()?.getKind()===d.TrueKeyword},fl=(e,t)=>{const s=P(e.getExpression());if(s===void 0)return;const n=ll.get(s);if(n!==void 0)return{callee:s,scope:x(e),failOpen:ul(e.getArguments()[n]),file:t,limitName:dl.has(s)?kn(e):"",line:e.getStartLineNumber()}},gl=(e,t)=>C(e,t,fl),pl=e=>{const t=e.getInitializer();if(!t||!r.isCallExpression(t))return;const s=ee(t);if(s?.kind!=="query")return;const n=Sr(t,s.receiver);return n?{exportName:j(e)??e.getName(),handler:n}:void 0},zs=e=>{const t=e.getParent();return t&&r.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},ml=e=>{const t=zs(e);if(!t)return"ctx.flags";if(t.getName()==="details"){const s=zs(t);return s?`ctx.flags.details.${s.getName()}`:"ctx.flags.details"}return`ctx.flags.${t.getName()}`},hl=(e,t)=>{const s=[];for(const n of Je(e.handler,"flags"))s.push({callee:ml(n),exportName:e.exportName,file:t,line:n.getStartLineNumber()});return s},vl=(e,t)=>{const s=[];for(const n of Q(e)){const i=pl(n);i&&s.push(...hl(i,t))}return s},El=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...vl(i,w(t,n)))}return s},xl=e=>!r.isPropertyAccessExpression(e)||e.getName()!=="boolean"?!1:G(e.getExpression(),["flags"]),Sl=e=>{if(e?.getKind()===d.TrueKeyword)return!0;if(e?.getKind()===d.FalseKeyword)return!1},Al=(e,t)=>{if(!xl(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(r.isStringLiteral(s)||r.isNoSubstitutionTemplateLiteral(s)))return;const i=s.getLiteralValue(),o=Sl(n);if(!(i.length===0||o===void 0))return{defaultValue:o,scope:x(e),file:t,key:i,line:e.getStartLineNumber()}},yl=(e,t)=>C(e,t,Al),bl=e=>{const t=e.getExpression();return r.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Nl=e=>{const t=e.getArguments()[0];return t&&r.isStringLiteral(t)?t.getLiteralText():""},Pl=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=w(t,n);for(const a of i.getDescendantsOfKind(d.CallExpression))bl(a)&&s.push({file:o,indexName:Nl(a),line:a.getStartLineNumber()})}return s},be=e=>e!==void 0&&(r.isArrowFunction(e)||r.isFunctionExpression(e))?e:void 0,ti=e=>{const t=e.getArguments()[0],s=be(t);if(s!==void 0)return s;if(t===void 0||!r.isObjectLiteralExpression(t))return;const n=V(t,"handler");return n!==void 0&&r.isPropertyAssignment(n)?be(n.getInitializer()):void 0},wl=new Set(["delete","get","head","options","patch","post","put"]),Il=new Set(["handler","stream"]),Cl=new Set(["runAction","runMutation"]),Tl=new Set(["delete","insert","insertManyUnsafe","patch","patchIf","replace"]),Ne=(e,t)=>e!==void 0&&r.isIdentifier(e)&&e.getText()===t,si=(e,t)=>{if(!(e===void 0||!r.isObjectBindingPattern(e))){for(const s of e.getElements())if(ce(s)===t){const i=s.getNameNode();return r.isIdentifier(i)?i.getText():void 0}}},$s=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?r.isIdentifier(s)?s.getText():void 0:si(s,"ctx")},Bs=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&r.isIdentifier(s)?s.getText():void 0:si(s,"request")},Vs=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(d.CallExpression);r.isCallExpression(s)&&n.unshift(s);for(const i of n){const o=i.getExpression();if(!r.isPropertyAccessExpression(o))continue;const a=o.getName(),c=o.getExpression();if(Cl.has(a)&&Ne(c,t))return a;if(Tl.has(a)&&r.isPropertyAccessExpression(c)&&c.getName()==="db"&&Ne(c.getExpression(),t))return`db.${a}`}},Us=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(d.PropertyAccessExpression))if(n.getName()==="auth"&&Ne(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(d.VariableDeclaration)){const i=n.getNameNode();if(!(!r.isObjectBindingPattern(i)||!Ne(n.getInitializer(),t))){for(const o of i.getElements())if(ce(o)==="auth")return!0}}return!1},Ol=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,kl=(e,t)=>{const s=e.getExpression();if(!r.isPropertyAccessExpression(s)||s.getName()!=="get"&&s.getName()!=="has")return!1;const n=s.getExpression();return r.isPropertyAccessExpression(n)&&n.getName()==="headers"&&Ne(n.getExpression(),t)},Rl=e=>[...r.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(d.StringLiteral).map(t=>t.getLiteralText())],ni=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:Rl(s)},Fl=(e,t)=>{const s=e.getText();for(let n=e.getParent();n!==void 0;n=n.getParent()){if(!r.isArrowFunction(n)&&!r.isFunctionExpression(n)||!n.getParameters().some(c=>c.getName()===s))continue;const i=n.getParent();if(!r.isCallExpression(i))return[];const o=i.getExpression();if(!r.isPropertyAccessExpression(o))return[];const a=o.getExpression();return r.isIdentifier(a)?ni(t,a.getText()):[]}return[]},Ll=e=>{const t=e.getArguments()[0];if(t===void 0)return[];if(r.isStringLiteral(t))return[t.getLiteralText()];if(!r.isIdentifier(t))return[];const s=e.getSourceFile(),n=ni(s,t.getText());return n.length>0?n:Fl(t,s)},Ws=(e,t)=>{if(t===void 0)return!1;const s=e.getBody(),n=s.getDescendantsOfKind(d.CallExpression);return r.isCallExpression(s)&&n.unshift(s),n.some(i=>kl(i,t)&&Ll(i).some(o=>Ol.test(o)))},Dl=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!Il.has(t.getName()))return;let s=t.getExpression();for(;r.isCallExpression(s);){const n=s.getExpression();if(!r.isPropertyAccessExpression(n))return;const i=n.getName();if(wl.has(i)){const o=n.getExpression();return r.isIdentifier(o)&&o.getText()==="httpRoute"?i.toUpperCase():void 0}s=n.getExpression()}},Ml=(e,t)=>{const s=e.getExpression();if(r.isIdentifier(s)&&s.getText()==="httpAction"){const c=be(e.getArguments()[0]),l=c&&$s(c,!0);if(!c||l===void 0||Ws(c,Bs(c,!0)))return;const u=Vs(c,l);return u===void 0?void 0:{scope:x(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:Us(c,l),sideEffect:u}}const n=Dl(e);if(n===void 0)return;const i=be(e.getArguments()[0]),o=i&&$s(i,!1);if(!i||o===void 0||Ws(i,Bs(i,!1)))return;const a=Vs(i,o);return a===void 0?void 0:{scope:x(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:Us(i,o),sideEffect:a}},_l=(e,t)=>C(e,t,Ml),Kl=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),zl=new Set(["append","set"]),ii=e=>e!==void 0&&(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",qs=(e,t)=>(r.isCallExpression(e)?[e,...e.getDescendantsOfKind(d.CallExpression)]:e.getDescendantsOfKind(d.CallExpression)).some(n=>Kl.has(P(n.getExpression())??"")&&De(n,t)),$l=(e,t)=>{if(qs(e,t))return!0;const s=Y(e);return s!==void 0&&qs(s,t)},Ft=(e,t)=>Va(e,t)&&!$l(e,t),Bl=e=>{if(r.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=Y(e);return t!==void 0&&r.isNewExpression(t)&&P(t.getExpression())==="Headers"},Ve=e=>{if(e===void 0)return;if(r.isObjectLiteralExpression(e))return e;const t=Y(e);return t!==void 0&&r.isObjectLiteralExpression(t)?t:void 0},es=(e,t,s)=>{for(const n of e.getProperties())if(r.isPropertyAssignment(n)){const i=n.getInitializer();i!==void 0&&Ft(i,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:ii(n.getNameNode()),line:i.getStartLineNumber(),via:t})}else if(r.isShorthandPropertyAssignment(n)){const i=n.getNameNode();Ft(i,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:S(n),line:i.getStartLineNumber(),via:t})}else if(r.isSpreadAssignment(n)){const i=Ve(n.getExpression());i!==void 0&&es(i,t,s)}},ri=(e,t)=>{const s=Ve(e);if(s===void 0)return;const n=V(s,"headers");if(n===void 0||!r.isPropertyAssignment(n))return;const i=Ve(n.getInitializer());i!==void 0&&es(i,"response-init",t)},Vl=(e,t)=>{const s=P(e.getExpression());if(s==="Response")ri(e.getArguments()[1],t);else if(s==="Headers"){const n=Ve(e.getArguments()[0]);n!==void 0&&es(n,"headers-ctor",t)}},Ul=(e,t)=>{const s=e.getExpression();if(!r.isPropertyAccessExpression(s))return;const n=s.getName(),i=s.getExpression();if(n==="json"&&r.isIdentifier(i)&&i.getText()==="Response"){ri(e.getArguments()[1],t);return}if(zl.has(n)&&Bl(i)){const o=e.getArguments()[1];o!==void 0&&Ft(o,t.requestName)&&t.rows.push({scope:t.scope,file:t.relativePath,headerName:ii(e.getArguments()[0]),line:o.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},Wl=(e,t)=>{for(const s of e.getDescendantsOfKind(d.NewExpression))Vl(s,t);for(const s of e.getDescendantsOfKind(d.CallExpression))Ul(s,t)},ql=(e,t)=>{const s=e.getExpression();if(!r.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=be(e.getArguments()[0]);if(n===void 0)return[];const i=n.getParameters()[1];if(i===void 0)return[];const o=i.getNameNode();if(!r.isIdentifier(o))return[];const a=[];return Wl(n,{scope:x(e),relativePath:t,requestName:o.getText(),rows:a}),a},jl=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression))s.push(...ql(n,t));return s},Hl=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...jl(i,w(t,n)))}return s},oi="identity.ts",Gl=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(r.isImportSpecifier(s))return Ze(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Yl=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!r.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(d.ImportDeclaration);return n!==void 0&&Ze(n.getModuleSpecifierValue())}return!1},Ql=e=>{if(r.isIdentifier(e))return Gl(e);if(r.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&r.isIdentifier(t)&&Yl(t)}return!1},Xl=e=>{const t=[];for(const s of e.getVariableDeclarations()){const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!Ql(n.getExpression()))continue;const o=s.getNameNode();if(!r.isIdentifier(o)){if(s.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw de(o,"defineIdentity exports must be plain named exports (no destructuring)")}const a=jt(s,"member");a!==void 0&&t.push({exportName:a})}return t},Jl=(e,t)=>{const s=E(t,oi);if(!M(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=Xl(n);if(i.length!==0){if(i.length>1)throw de(n,`lunora/identity.ts declares ${i.length.toString()} defineIdentity() contracts (${i.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Zl=new Set(["auth","context.auth"]),ed="userId",td=e=>{const t=new Set;for(const s of e.getProperties()){if(r.isSpreadAssignment(s))return;(r.isPropertyAssignment(s)||r.isShorthandPropertyAssignment(s)||r.isMethodDeclaration(s))&&t.add(S(s))}return t},sd=(e,t)=>{const s=E(t,oi);if(!M(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const i of n.getDescendantsOfKind(d.CallExpression)){if(P(i.getExpression())!=="defineIdentity")continue;const[o]=i.getArguments();return o&&r.isObjectLiteralExpression(o)?td(o):void 0}},js=e=>{if(e===void 0||!r.isPropertyAccessExpression(e)||e.getName()!=="identity")return;const t=e.getExpression();return Zl.has(t.getText())||G(t,["auth"])?e:void 0},nd=e=>{if(r.isPropertyAccessExpression(e)&&js(e.getExpression())!==void 0)return e.getName();if(r.isElementAccessExpression(e)&&js(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&r.isStringLiteral(t)?t.getLiteralValue():void 0}},Hs=(e,t,s)=>{const n=nd(e);return n===void 0?void 0:{declared:n===ed||s.has(n),file:t,key:n,line:e.getStartLineNumber(),scope:x(e)}},id=(e,t)=>{const s=sd(e,t);return s===void 0?[]:[...ne(e,t,d.PropertyAccessExpression,(n,i)=>Hs(n,i,s)),...ne(e,t,d.ElementAccessExpression,(n,i)=>Hs(n,i,s))]},rd=(e,t)=>{if(P(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=R(s,"key");if(!(!n||!q(n)||le(n)))return{scope:x(e),file:t,line:e.getStartLineNumber()}},od=(e,t)=>C(e,t,rd),ad=new Set(["delete","get","getRaw","getWithMetadata","put"]),cd=(e,t,s=[])=>{const n=tt(e,t,{argIndex:0,matchReceiver:i=>i==="ctx.kv"||i.startsWith("ctx.kv."),methods:ad});return Ht(n,s)},ld=new Set(["queue","send"]),Gs=new Set(["bcc","cc","to"]),dd=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();if(!ld.has(t))return;const s=e.getExpression();return G(s,["mail"])||G(s,["email"])?t:void 0},ud=e=>r.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(r.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return Gs.has(S(t))&&q(n)&&!le(n)}if(!r.isPropertyAssignment(t)||!Gs.has(S(t)))return!1;const s=t.getInitializer();return s!==void 0&&q(s)&&!le(s)}):!1,fd=(e,t)=>{const s=dd(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!ud(n)))return{scope:x(e),file:t,line:e.getStartLineNumber(),method:s}},gd=(e,t)=>C(e,t,fd),pd=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!r.isObjectLiteralExpression(n))return[];const i=[];for(const o of n.getProperties()){const a=Be(o);if(a===void 0||!r.isPropertyAssignment(o))continue;const c=o.getInitializer();if(!(!c||!r.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const u=Be(l);if(u===void 0)continue;const f=Bn(l);f!=="custom"&&i.push({column:u,exportName:t,file:s,line:l.getStartLineNumber(),strategy:f,table:a})}}return i},md=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&r.isCallExpression(s)?ee(s):void 0;return n?.receiver?Yt(n.receiver).flatMap(i=>pd(i,j(e)??e.getName(),t)):[]},hd=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=w(t,n);for(const a of Q(i))s.push(...md(a,o))}return s},vd=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return z(s)},Ed=e=>{const t=e.getArguments()[0];if(t===void 0||!r.isObjectLiteralExpression(t))return;const s=V(t,"server");if(s!==void 0)return r.isPropertyAssignment(s)?s.getInitializer():s},xd=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==d.CallExpression)return;const s=t;return Ur(s.getExpression())?s:void 0},Sd=e=>{const t=xd(e),s=t===void 0?void 0:Ed(t);if(s===void 0)return[];const n=e.getNameNode(),i=r.isIdentifier(n)?j(e)??n.getText():"";return s.getDescendantsOfKind(d.CallExpression).filter(o=>vd(o)).map(o=>({exportName:i,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},Ad=e=>e.getVariableDeclarations().flatMap(t=>Sd(t)),yd=(e,t)=>{const s=E(t,Vr);if(!M(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Ad(n)},bd=new Set(["delete","get","patch"]),Nd=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Pd=new Set(["auth","identity","session","user"]),wd=new Set([d.EqualsEqualsEqualsToken,d.EqualsEqualsToken,d.ExclamationEqualsEqualsToken,d.ExclamationEqualsToken]),Id=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!z(t.getExpression()))return;const s=e.getArguments()[0];return s&&r.isStringLiteral(s)?s.getLiteralText():""},Cd=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(r.isAsExpression(s)||r.isParenthesizedExpression(s)||r.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!r.isVariableDeclaration(s))return;const n=s.getNameNode();return r.isIdentifier(n)?n.getText():void 0},Td=(e,t)=>e.getDescendantsOfKind(d.Identifier).some(s=>s.getText()===t),Od=e=>r.isThrowStatement(e)||r.isReturnStatement(e)||e.getDescendantsOfKind(d.ThrowStatement).length>0||e.getDescendantsOfKind(d.ReturnStatement).length>0,kd=(e,t)=>e.getDescendantsOfKind(d.IfStatement).some(s=>Td(s.getExpression(),t)&&Od(s.getThenStatement())),Rd=(e,t)=>{for(const s of e.getDescendantsOfKind(d.CallExpression)){const n=s.getExpression();if(!r.isPropertyAccessExpression(n))continue;const i=n.getName();if(!bd.has(i))continue;const o=n.getExpression();if(!(z(o)||r.isPropertyAccessExpression(o)&&z(o.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&r.isIdentifier(c)&&c.getText()===t)return i}},Fd=e=>e.getDescendantsOfKind(d.CallExpression).some(t=>t.getArguments().some(s=>Gt(Qe(s))!==void 0)),Ld=e=>e.getDescendantsOfKind(d.BinaryExpression).some(t=>wd.has(t.getOperatorToken().getKind())?r.isPropertyAccessExpression(t.getLeft())||r.isPropertyAccessExpression(t.getRight()):!1),Dd=e=>{for(const t of e.getDescendantsOfKind(d.Identifier))if(Nd.has(t.getText()))return!0;return[...Pd].some(t=>Je(e,t).length>0)?!0:Fd(e)||Ld(e)},Md=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!r.isCallExpression(s))return[];const n=ee(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const i=ti(s);if(i===void 0)return[];const o=n.receiver!==void 0&&Kn(n.receiver,"use","rls"),a=Dd(i),c=new Set,l=[];for(const u of i.getDescendantsOfKind(d.CallExpression)){const f=Id(u);if(f===void 0)continue;const g=Cd(u);if(g===void 0||c.has(g)||!kd(i,g))continue;const m=Rd(i,g);m!==void 0&&(c.add(g),l.push({exportName:j(e)??e.getName(),file:t,line:u.getStartLineNumber(),mentionsOwnership:a,sinkMethod:m,table:f,usesRls:o,visibility:n.visibility}))}return l},_d=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=w(t,n);for(const a of Q(i))s.push(...Md(a,o))}return s},ai=(e,t)=>{const s=r.isIdentifier(e)&&t!==void 0?L(e):void 0;return s===void 0||t===void 0?!1:s.compilerNode===t.compilerNode?r.isIdentifier(t.getNameNode()):r.isBindingElement(s)&&s.getFirstAncestorByKind(d.Parameter)?.compilerNode===t.compilerNode},Kd=e=>{const t=I(e),s=t.getParent();return(r.isPropertyAccessExpression(s)||r.isElementAccessExpression(s))&&s.getExpression()===t&&!Xe(s)},zd=e=>{const t=I(e).getParent();return r.isVariableDeclaration(t)&&r.isObjectBindingPattern(t.getNameNode())},$d=e=>{const s=I(e).getParent();if(r.isSpreadAssignment(s)||r.isSpreadElement(s)){const n=s.getParent();return(r.isObjectLiteralExpression(n)||r.isArrayLiteralExpression(n))&&!Xe(n)}return r.isTemplateSpan(s)&&!r.isTaggedTemplateExpression(s.getParent().getParent())},Ue=e=>{const t=L(e);return t===void 0||Pr(t.getSourceFile())},Lt=(e,t)=>{const s=I(e),n=s.getParent();if(!r.isCallExpression(n))return!1;const i=n.getArguments().indexOf(s),o=h(n.getExpression());if(i===-1||o===void 0)return!1;if(r.isIdentifier(o))return o.getText()==="structuredClone"&&Ue(o);if(ai(Qe(o),t))return!(r.isPropertyAccessExpression(o)&&Mn.has(o.getName()))||r.isExpressionStatement(I(r.isAwaitExpression(n.getParent())?n.getParentOrThrow():n).getParent());if(!r.isPropertyAccessExpression(o))return!1;const a=o.getExpression();if(!r.isIdentifier(a)||!Ue(a))return!1;const c=a.getText(),l=o.getName();switch(c){case"console":return!0;case"JSON":return l==="stringify";case"Object":return["entries","freeze","isFrozen","keys","values"].includes(l)||l==="assign"&&i>0;default:return!1}},Me={kind:"opaque"},Bd={kind:"unreached"},Vd=e=>{const t=e.getSymbol()?.getDeclarations()??[],s=t.filter(o=>r.isFunctionDeclaration(o)&&o.hasBody()),[n]=s;return t.every(o=>r.isFunctionDeclaration(o)&&o.getSourceFile()===e.getSourceFile())&&s.length===1&&r.isFunctionDeclaration(n)?n:void 0},Dt=e=>{const t=h(e);if(r.isArrowFunction(t)||r.isFunctionExpression(t))return t;const s=r.isIdentifier(t)?L(t):void 0;if(s?.getSourceFile()!==e.getSourceFile())return;if(r.isFunctionDeclaration(s)){const i=Vd(s);return i===void 0||qt(i)?void 0:i}const n=ie(s)?h(s.getInitializer()):void 0;return r.isArrowFunction(n)||r.isFunctionExpression(n)?n:void 0},ci=(e,t,s)=>{const n=t.getArguments(),i=n.indexOf(s),o=i===-1||n.slice(0,i+1).some(l=>r.isSpreadElement(l))||e.getDescendantsOfKind(d.Identifier).some(l=>l.getText()==="arguments"),a=e.getParameters(),c=a[i];return o?Me:c===void 0?a.some(l=>l.isRestParameter())?Me:Bd:c.isRestParameter()?Me:{kind:"parameter",parameter:c}},Ud=e=>{const t=I(e),s=t.getParent();if(!r.isCallExpression(s)||s.getExpression()===t)return;const n=Dt(s.getExpression());return n===void 0?Me:ci(n,s,t)},Wd=new Set(["__defineGetter__","__defineSetter__","__proto__"]),qd=e=>r.isForInStatement(e)?e.getExpression():r.isConditionalExpression(e)?e.getCondition():r.isElementAccessExpression(e)?e.getArgumentExpression():void 0,li=e=>{const t=I(e),s=t.getParent();if(r.isIfStatement(s)||r.isWhileStatement(s)||r.isDoStatement(s)||r.isSwitchStatement(s)||r.isCaseClause(s)||r.isTypeOfExpression(s)||r.isVoidExpression(s)||r.isComputedPropertyName(s))return!0;if(r.isTemplateSpan(s))return!r.isTaggedTemplateExpression(s.getParent().getParent());const n=qd(s);if(n!==void 0)return y(n,t);if(r.isPrefixUnaryExpression(s))return s.getOperatorToken()!==d.PlusPlusToken&&s.getOperatorToken()!==d.MinusMinusToken;if(!r.isBinaryExpression(s))return!1;const i=s.getOperatorToken().getKind(),o=i>=d.FirstAssignment&&i<=d.LastAssignment,a=i===d.QuestionQuestionToken||i===d.BarBarToken||i===d.AmpersandAmpersandToken;return!o&&!a},jd=4,di=(e,t,s=0)=>{if(Nr(e))return!0;if(Kd(e)){const i=I(e).getParent(),o=r.isElementAccessExpression(i)?i.getArgumentExpression():void 0,a=r.isStringLiteral(o)?o.getLiteralValue():void 0,c=r.isPropertyAccessExpression(i)?i.getName():a;return c===void 0||!Wd.has(c)}if(zd(e)||$d(e)||li(e)||Lt(e,t))return!0;const n=Ud(e);return n?.kind==="unreached"||n?.kind==="parameter"&&Hd(n.parameter,s+1)},Ys=new WeakMap,Hd=(e,t=0)=>{const s=e.getNameNode();if(!r.isIdentifier(s))return!0;const n=Ys.get(e.compilerNode);if(n!==void 0)return n;if(t>jd)return!1;const o=(s.getSymbol()?.getDeclarations().length??0)===1&&e.getParentOrThrow().getDescendantsOfKind(d.Identifier).every(a=>a===s||a.getText()!==s.getText()||L(a)?.compilerNode!==e.compilerNode||di(a,void 0,t));return(o||t===0)&&Ys.set(e.compilerNode,o),o},Qs=new WeakMap,Gd=(e,t)=>{const s=r.isFunctionExpression(e)?e.getNameNode():void 0;if(!r.isArrowFunction(e)&&e.getFirstDescendantByKind(d.ThisKeyword)!==void 0)return!0;const n=new Set([t.getName(),...s===void 0?[]:[s.getText()]]);return e.getDescendantsOfKind(d.Identifier).some(i=>{if(i===s||!n.has(i.getText()))return!1;const o=L(i)?.compilerNode;return o!==void 0&&(o===t.compilerNode||s!==void 0&&o===e.compilerNode)})},Yd=(e,t,s)=>{const{context:n,impl:i}=e,o=Qs.get(i.compilerNode);if(o!==void 0)return o;const a=t.getNameNode(),c=r.isIdentifier(a)?[a]:a.getDescendantsOfKind(d.BindingElement).flatMap(g=>{const m=g.getNameNode();return r.isIdentifier(m)?[m]:[]}),l=new Map(c.map(g=>[g.getText(),g.getParentOrThrow().compilerNode])),u=g=>r.isIdentifier(a)?di(g,n):!Xe(g),f=!Gd(i,s)&&c.every(g=>(g.getSymbol()?.getDeclarations().length??0)===1)&&i.getDescendantsOfKind(d.Identifier).every(g=>{const m=g.getText();if(m==="arguments")return!1;const v=l.get(m);return v===void 0||c.includes(g)||L(g)?.compilerNode!==v?!0:u(g)});return Qs.set(i.compilerNode,f),f},Xs=new WeakMap,Qd=e=>{let t=Xs.get(e.compilerNode);return t===void 0&&(t=new Map(e.getVariableDeclarations().flatMap(s=>{const n=Wr(s);return n===void 0?[]:[[n.compilerNode,s]]})),Xs.set(e.compilerNode,t)),t},Xd=e=>{const t=Qd(e.getSourceFile()),s=e.getAncestors().find(l=>t.has(l.compilerNode)),n=s===void 0?void 0:t.get(s.compilerNode);if(s===void 0||n===void 0)return;const[i,o]=s.getParameters(),a=o===void 0||o.isRestParameter()?void 0:o,c={context:i,impl:s,mutatorName:j(n)??n.getName()};return a!==void 0&&Yd(c,a,n)?{...c,parameter:a,pristine:!0}:{...c,parameter:a,pristine:!1}},xt="args",Ee=e=>{const t=Wt(e);if(t!==void 0){const c=h(t.object);return r.isIdentifier(c)&&c.getText()===xt?t.member:void 0}if(!r.isIdentifier(e))return;const s=L(e);if(!r.isBindingElement(s)||s.getDotDotDotToken()!==void 0)return;const n=s.getParent();if(!r.isObjectBindingPattern(n))return;const i=n.getParent(),o=ie(i)?h(i.getInitializer()):void 0;return r.isBindingElement(i)&&ce(i)===xt||r.isIdentifier(o)&&o.getText()===xt?ce(s):void 0},Jd=new Set(["auth","identity","user"]),Mt=e=>{const t=i=>{const o=Gt(i);return o!==void 0&&o.length>0&&Jd.has(o[0]??"")},s=h(e)??e;if(t(s))return!0;const n=Y(s);return n!==void 0&&t(n)},ui=(e,t=2)=>{const s=new Set;for(const n of[e,...e.getDescendants()]){const i=Ee(n);i!==void 0&&s.add(i);const o=t>0&&r.isIdentifier(n)?Y(n):void 0;if(o!==void 0)for(const a of ui(o,t-1))s.add(a)}return s},_e=e=>{const t=h(e)??e;if(!r.isBinaryExpression(t))return[];const s=t.getOperatorToken().getKind(),n=t.getLeft(),i=t.getRight();if(s===d.BarBarToken)return[..._e(n),..._e(i)];if(s===d.AmpersandAmpersandToken){const l=(u,f)=>{const g=Ee(h(u)??u);return g===void 0?[]:_e(f).filter(m=>m===g)};return[...l(n,i),...l(i,n)]}if(s!==d.ExclamationEqualsEqualsToken&&s!==d.ExclamationEqualsToken)return[];const o=[],a=Ee(h(n)??n),c=Ee(h(i)??i);return a!==void 0&&Mt(i)&&o.push(a),c!==void 0&&Mt(n)&&o.push(c),o},Zd=e=>{const t=h(e)??e;if(!r.isIdentifier(t))return!1;const s=t.getSymbol(),n=s?.getAliasedSymbol()?.getValueDeclaration()??s?.getValueDeclaration();if(!r.isVariableDeclaration(n))return!1;const i=h(n.getInitializer());return r.isCallExpression(i)&&Lr(i.getExpression(),"defineIdentityGuard")},eu=e=>{if(!Zd(e.getExpression()))return[];const t=e.getArguments();return t.flatMap((s,n)=>{const i=Ee(h(s)??s),o=t.some((a,c)=>c!==n&&Mt(a));return i!==void 0&&o?[i]:[]})},tu=e=>{if(r.isThrowStatement(e))return!0;if(!r.isBlock(e))return!1;const t=e.getStatements().at(-1);return t!==void 0&&r.isThrowStatement(t)},su=e=>r.isArrowFunction(e)||r.isFunctionExpression(e)||r.isFunctionDeclaration(e)||r.isMethodDeclaration(e),Js=(e,t)=>{for(let s=e.getParent();s!==void 0;s=s.getParent()){if(s===t||s.compilerNode===t.compilerNode)return!0;if(!(r.isBlock(s)||r.isExpressionStatement(s)||r.isAwaitExpression(s)||r.isParenthesizedExpression(s)||r.isVariableStatement(s)||r.isVariableDeclarationList(s)||r.isVariableDeclaration(s)))return!1}return!1},nu=e=>r.isAwaitExpression(e.getParent())||e.getType().isVoid(),iu=(e,t)=>{const s=new Set;for(const n of e.getDescendantsOfKind(d.IfStatement))if(n.getEnd()<=t&&Js(n,e)&&tu(n.getThenStatement()))for(const i of _e(n.getExpression()))s.add(i);for(const n of e.getDescendantsOfKind(d.CallExpression))if(n.getEnd()<=t&&nu(n)&&Js(n,e))for(const i of eu(n))s.add(i);return s},ru=(e,t)=>{const s=ui(t);if(s.size===0)return!1;const n=e.getFirstAncestor(su);if(n===void 0)return!1;const i=iu(n,e.getStart());return[...s].every(o=>i.has(o))},ou=new Set(["at","concat","filter","find","findLast","flat","reverse","slice","sort","toReversed","toSorted"]),au=new Map([["Array",new Set(["from","of"])],["Object",new Set(["entries","values"])]]),_t=new Set(["catch","every","filter","finally","find","findIndex","findLast","findLastIndex","flatMap","forEach","map","reduce","reduceRight","some","sort","then"]),fi=e=>e.getNameNode().getDescendantsOfKind(d.BindingElement).filter(t=>r.isIdentifier(t.getNameNode())),cu=e=>{const t=I(e),s=t.getParent();if(r.isVariableDeclaration(s))return y(s.getInitializer(),t)?s:void 0;const n=r.isForOfStatement(s)&&s.getExpression()===t?s.getInitializer():void 0;return r.isVariableDeclarationList(n)?n.getDeclarations()[0]:void 0},lu=e=>{const t=cu(e);return t===void 0?void 0:r.isIdentifier(t.getNameNode())?r.isForOfStatement(t.getParent().getParent())||ie(t)?[t]:void 0:fi(t)},xe=e=>e.isUnion()?e.getUnionTypes().every(t=>xe(t)):e.isIntersection()?e.getIntersectionTypes().some(t=>xe(t)):!e.isAny()&&!e.isUnknown()&&!e.isObject()&&!e.isTypeParameter(),We=(e,t,s)=>{const n=r.isCallExpression(e)?h(e.getExpression()):void 0;return r.isPropertyAccessExpression(n)&&t.has(n.getName())&&(s===void 0||n.getExpression()===s)},Ke=e=>{const t=h(e);if(!r.isArrowFunction(t)&&!r.isFunctionExpression(t))return;const s=t.getBody();return r.isBlock(s)?s.getDescendantsOfKind(d.ReturnStatement).filter(n=>n.getFirstAncestor(i=>r.isFunctionLikeDeclaration(i))===t).map(n=>n.getExpression()):[s]},du=e=>{const t=r.isCallExpression(e)?h(e.getExpression()):void 0,s=r.isPropertyAccessExpression(t)?t.getExpression():void 0;return r.isPropertyAccessExpression(t)&&r.isIdentifier(s)&&au.get(s.getText())?.has(t.getName())===!0&&Ue(s)},uu=e=>{const t=wt(e);if(!r.isArrowFunction(t)&&!r.isFunctionExpression(t))return;const s=I(t),n=s.getParent();return r.isCallExpression(n)&&n.getArguments().includes(s)&&We(n,_n)?n:void 0},fu=(e,t)=>{if(!(r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e))||e.getExpression()!==t)return;const s=I(e),n=s.getParent();return!r.isCallExpression(n)||n.getExpression()!==s?e:We(n,ou,t)?n:void 0},gu=(e,t)=>{if(r.isAwaitExpression(e))return e;if(r.isConditionalExpression(e))return e.getCondition()===t?void 0:e;const s=r.isBinaryExpression(e)?e.getOperatorToken().getKind():void 0;return s===d.QuestionQuestionToken||s===d.BarBarToken||s===d.AmpersandAmpersandToken?e:void 0},pu=(e,t)=>{if(r.isArrayLiteralExpression(e))return e;const n=r.isSpreadElement(e)||r.isSpreadAssignment(e)||r.isShorthandPropertyAssignment(e)||r.isPropertyAssignment(e)&&y(e.getInitializer(),t)?e.getParent():void 0;return r.isArrayLiteralExpression(n)||r.isObjectLiteralExpression(n)?n:void 0},Zs=e=>{const t=I(e),s=t.getParent();if(s===void 0)return;const n=r.isCallExpression(s)&&s.getArguments().includes(t)&&du(s);return fu(s,t)??gu(s,t)??pu(s,t)??(n?s:uu(t))},mu=5e4,gi=()=>({inProgress:new Set,verdicts:new Map});class hu{cuts=0;work=0;reset(){this.work=0}cut(){return this.cuts+=1,!0}spend(){return this.work+=1,this.work>mu&&this.cut()}memoized(t,s,n){const i=n.verdicts.get(t);if(i!==void 0)return i;if(n.inProgress.has(t))return this.cuts+=1,!1;if(this.spend())return!0;const o=this.cuts;n.inProgress.add(t);let a;try{a=s()}finally{n.inProgress.delete(t)}return this.cuts===o&&n.verdicts.set(t,a),a}}const vu=8,Eu=8;class xu{budget;scope;taint;verdicts=gi();constructor(t,s,n){this.scope=t,this.budget=s,this.taint=n}isCompromised(t){return this.flowHasCompromisingUse(t)&&!xe(t.getType())}flowHasCompromisingUse(t){return this.budget.memoized(t.compilerNode,()=>{const s=this.budget.cuts,n=[],i=new Set,o=(c,l)=>{i.has(c.compilerNode)||(i.add(c.compilerNode),n.push({binding:c,hops:l}))};let a=!1;o(t,0);for(const c of n)if(a=(c.binding===t?void 0:this.verdicts.verdicts.get(c.binding.compilerNode))??this.visitBinding(c,t,o),a)break;if(!a&&this.budget.cuts===s)for(const c of i)this.verdicts.verdicts.set(c,!1);return a},this.verdicts)}visitBinding({binding:t,hops:s},n,i){const o=t.getNameNode();if(!r.isIdentifier(o)){for(const l of r.isParameterDeclaration(t)?fi(t):[])i(l,s);return!1}if(this.budget.spend())return!0;const a=(l,u)=>u&&s>=vu?this.budget.cut():(i(l,u?s+1:s),!1);return this.taint.referencesTo(t,o.getText()).some(l=>this.valueCompromises(I(l),!0,a,0))&&(t===n||!xe(t.getType()))}valueCompromises(t,s,n,i){let o=t;for(let m=Zs(o);m!==void 0;m=Zs(o)){if(r.isCallExpression(m)&&this.callbackCompromises(m,n))return!0;o=I(m)}const a=o.getParent(),c=o===t&&s,l=()=>!c&&xe(o.getType());if(Xe(o))return!c&&(!r.isBinaryExpression(a)||this.taint.isTaintedValue(a.getRight(),!1));const u=lu(o);if(u!==void 0)return u.some(m=>n(m,!0));const f=r.isPropertyAccessExpression(a)&&a.getExpression()===o?a.getParent():void 0;if(r.isCallExpression(f)&&f.getExpression()===a)return this.methodCallCompromises(f,n);const g=this.nestedReturningFunctionOf(o);return g!==void 0?this.resultCompromises(g,n,i)&&!l():this.positionCompromises(o,n)&&!l()}resultCompromises(t,s,n){const i=I(t).getParent();if(n>=Eu)return this.budget.cut();if(r.isCallExpression(i))return i.getExpression()===I(t)?this.valueCompromises(i,!1,s,n+1):!We(i,_t);const o=r.isFunctionDeclaration(t)?t:i,a=r.isFunctionDeclaration(o)||ie(o)?o.getNameNode():void 0;return o===void 0||!r.isIdentifier(a)?!0:this.taint.referencesTo(o,a.getText()).some(c=>{const l=I(c),u=l.getParent();return!r.isCallExpression(u)||u.getExpression()!==l||this.valueCompromises(u,!1,s,n+1)})}methodCallCompromises(t,s){return t.getArguments().filter(i=>Ke(i)===void 0).some(i=>this.taint.isTaintedValue(i,!1))||this.callbackCompromises(t,s)}callbackCompromises(t,s){const n=We(t,_t)?t.getArguments()[0]:void 0;if(n===void 0)return!1;const i=Dt(n);return i!==void 0&&this.taint.isInImpl(i)?i.getParameters().some(o=>s(o,!1)):this.taint.isTaintedValue(n,!1)}positionCompromises(t,s){const n=t.getParent();if(r.isCallExpression(n)&&n.getArguments().includes(t))return this.argumentCompromises(n,t,s);const i=r.isSpreadElement(n)?n.getParent():void 0;if(n!==void 0&&r.isCallExpression(i))return!Lt(n,this.scope.context)&&this.isOpaqueCallTainted(i.getExpression(),i.getArguments(),n);if(r.isNewExpression(n))return this.isOpaqueCallTainted(n.getExpression(),n.getArguments(),t);if(r.isTemplateSpan(n)){const o=n.getParent(),a=o.getParent(),c=o.getTemplateSpans().map(l=>l.getExpression());return r.isTaggedTemplateExpression(a)&&this.isOpaqueCallTainted(a.getTag(),c,t)}return!this.isReadPosition(t)}argumentCompromises(t,s,n){if(Lt(s,this.scope.context))return!1;const i=Dt(t.getExpression()),o=i===void 0?void 0:ci(i,t,s);return o?.kind==="unreached"?!1:o?.kind==="parameter"&&i!==void 0&&this.taint.isInImpl(i)?n(o.parameter,!1):this.isOpaqueCallTainted(t.getExpression(),t.getArguments(),s)}isReadPosition(t){const s=t.getParent();return s===void 0||r.isExpressionStatement(s)||r.isForStatement(s)||r.isElementAccessExpression(s)||li(t)||y(wt(t),this.scope.impl)}isOpaqueCallTainted(t,s,n){const i=!r.isIdentifier(h(n));return this.taint.isTaintedValue(t,!1)||s.some(o=>(o!==n||i)&&this.taint.isTaintedValue(o,!1))}nestedReturningFunctionOf(t){const s=wt(t);return y(s,this.scope.impl)?void 0:s}}const Su=new Set(["at","every","filter","finally","find","findIndex","findLast","findLastIndex","forEach","order","slice","some","sort","withIndex","withSearchIndex"]),Au=e=>{const t=h(e);if(!r.isIdentifier(t))return r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t);const s=L(t),n=r.isVariableDeclaration(s)?h(s.getInitializer()):void 0;return s===void 0||r.isFunctionDeclaration(s)||r.isParameterDeclaration(s)||r.isArrowFunction(n)||r.isFunctionExpression(n)},yu=new Set(["all","allSettled","any","race"]),en=e=>r.isParameterDeclaration(e)?e:r.isBindingElement(e)?e.getFirstAncestorByKind(d.Parameter):void 0,St=8;class bu{budget=new hu;referencesByDeclaration=new Map;referencesByName=new Map;scope;verdicts=gi();walk;variableDepth=0;queryDepth=0;constructor(t){this.scope=t,this.walk=new xu(t,this.budget,this);for(const s of t.impl.getDescendantsOfKind(d.Identifier)){const n=s.getText();this.referencesByName.set(n,[...this.referencesByName.get(n)??[],s])}}isTaintedValue(t,s){this.queryDepth===0&&this.budget.reset(),this.queryDepth+=1;try{return s&&this.isRootedInContext(t,St)?!1:(r.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(i=>wr(i)&&this.isIdentifierTainted(i))}finally{this.queryDepth-=1}}isInImpl(t){const{impl:s}=this.scope;return t!==s&&s.getPos()<=t.getPos()&&t.getEnd()<=s.getEnd()}referencesTo(t,s){let n=this.referencesByDeclaration.get(s);if(n===void 0){n=new Map;for(const i of this.referencesByName.get(s)??[]){const o=L(i)?.compilerNode;o!==void 0&&n.set(o,[...n.get(o)??[],i])}this.referencesByDeclaration.set(s,n)}return(n.get(t.compilerNode)??[]).filter(i=>i.getParent()!==t)}flowsIntoTainted(t){if([t.getInitializer(),...t.getDescendantsOfKind(d.BindingElement).map(g=>g.getInitializer())].some(g=>g!==void 0&&this.isTaintedValue(g,!1)))return!0;const n=t.getParentOrThrow(),i=r.isFunctionLikeDeclaration(n)?n.getParameters().findIndex(g=>g.compilerNode===t.compilerNode):-1,o=I(n),a=o.getParent();if(i===-1)return!0;if(r.isCallExpression(a)){if(a.getExpression()===o)return this.isCallSiteTainted(a,i,t.isRestParameter());const g=h(a.getExpression());if(!r.isPropertyAccessExpression(g)||!_t.has(g.getName()))return!0;const m=a.getArguments().filter(v=>v!==o);return this.isTaintedValue(g.getExpression(),!0)||m.some(v=>this.isTaintedValue(v,!1))}const c=r.isVariableDeclaration(a)&&ie(a)?a:void 0,l=r.isFunctionDeclaration(n)?n:c,u=l?.getNameNode();if(l===void 0||!r.isIdentifier(u))return!0;const f=this.referencesTo(l,u.getText());return f.length===0||f.some(g=>{const m=I(g),v=m.getParent();return!r.isCallExpression(v)||v.getExpression()!==m||this.isCallSiteTainted(v,i,t.isRestParameter())})}isCallSiteTainted(t,s,n){const i=t.getArguments(),o=i.findIndex(c=>r.isSpreadElement(c)),a=c=>c===s||n&&c>s||o!==-1&&o<=s&&c>=o;return i.some((c,l)=>a(l)&&this.isTaintedValue(c,!1))}isContextRootedCombinator(t,s){const n=h(t.getExpression()),i=r.isPropertyAccessExpression(n)?n.getExpression():void 0,a=r.isPropertyAccessExpression(n)&&r.isIdentifier(i)&&i.getText()==="Promise"&&Ue(i)&&yu.has(n.getName())?h(t.getArguments()[0]):void 0;if(r.isArrayLiteralExpression(a)){const f=a.getElements();return f.length>0&&f.every(g=>!r.isSpreadElement(g)&&this.isRootedInContext(g,s))}const c=r.isCallExpression(a)?h(a.getExpression()):void 0,l=r.isCallExpression(a)&&r.isPropertyAccessExpression(c)&&c.getName()==="map"?h(a.getArguments()[0]):void 0,u=l===void 0?void 0:Ke(l);return u!==void 0&&u.length>0&&u.every(f=>f!==void 0&&this.isRootedInContext(f,s))}isIdentifierTainted(t){const s=t.getText();if(s==="arguments")return!0;const n=L(t),i=en(n);if(i!==void 0)return this.isSource(i);if(s==="args")return!0;if(n===void 0||!this.isInImpl(n))return!1;if(r.isFunctionDeclaration(n))return this.budget.memoized(n.compilerNode,()=>this.isTaintedValue(n,!1),this.verdicts);if(r.isBindingElement(n)&&this.walk.isCompromised(n))return!0;const o=r.isBindingElement(n)?n.getFirstAncestorByKind(d.VariableDeclaration):n;return r.isVariableDeclaration(o)&&this.isVariableTainted(o)}callChainVerdict(t,s){if(this.isContextRootedCombinator(t,s))return!0;const n=h(t.getExpression()),i=r.isPropertyAccessExpression(n)?n.getName():void 0;return i!==void 0&&Mn.has(i)?!1:i!==void 0&&_n.has(i)?this.isCallbackResultServerScoped(t,s)?void 0:!1:t.getArguments().some(a=>Ke(a)!==void 0)&&(i===void 0||!Su.has(i))?!1:void 0}isCallbackResultServerScoped(t,s){const n=(i,o=[])=>{const a=Qe(i),c=r.isIdentifier(a)?en(L(a)):void 0;return c!==void 0&&o.includes(c)?!0:this.isRootedInContext(i,s)||!this.isTaintedValue(i,!1)};return t.getArguments().every(i=>{const o=Ke(i);if(o===void 0)return!Au(i)&&n(i);const a=h(i),c=r.isArrowFunction(a)||r.isFunctionExpression(a)?a.getParameters():[];return o.every(l=>l===void 0||n(l,c))})}isRootedInContext(t,s){const n=Ar(t,u=>this.callChainVerdict(u,s)),i=n.root;if(n.verdict!==void 0)return n.verdict;if(ai(i,this.scope.context))return!0;const o=r.isIdentifier(i)?L(i):void 0,a=r.isBindingElement(o)?o.getFirstAncestorByKind(d.VariableDeclaration):o,c=ie(a)&&this.isInImpl(a)?a.getInitializer():void 0,l=r.isBindingElement(o)?o:a;return s>0&&c!==void 0&&(r.isBindingElement(l)||r.isVariableDeclaration(l))&&!this.walk.isCompromised(l)&&this.isRootedInContext(c,s-1)}isSource(t){const{impl:s,parameter:n}=this.scope;return t.compilerNode===n?.compilerNode?!0:t.getParent()!==s&&this.isInImpl(t)&&(this.budget.memoized(t.compilerNode,()=>this.flowsIntoTainted(t),this.verdicts)||this.walk.isCompromised(t))}isVariableTainted(t){return this.budget.memoized(t.compilerNode,()=>{const s=t.getParent().getParent();if(r.isCatchClause(t.getParent())||this.walk.isCompromised(t))return!0;if(r.isForOfStatement(s)||r.isForInStatement(s))return this.isTaintedValue(s.getExpression(),!0);const n=t.getInitializer(),i=qt(t);if(n===void 0||i)return!0;if(this.isRootedInContext(n,St))return!1;if(this.variableDepth>=St)return this.budget.cut();this.variableDepth+=1;try{return this.isTaintedValue(n,!1)}finally{this.variableDepth-=1}},this.verdicts)}}const tn=new WeakMap,Nu=e=>{const t=tn.get(e.impl.compilerNode);if(t!==void 0)return t;const s=new bu(e);return tn.set(e.impl.compilerNode,s),s},Pu=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),wu=new Set(["insert","insertManyUnsafe","patch","replace"]),Iu=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();return wu.has(t)&&Or(e.getExpression())?t:void 0},Cu=(e,t)=>{if(t!=="insertManyUnsafe")return r.isObjectLiteralExpression(e)?[e]:[];if(!r.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())r.isObjectLiteralExpression(n)&&s.push(n);return s},Tu=(e,t)=>{const s=Wt(e);return s?.member===t?h(s.object):void 0},sn=(e,t)=>r.isIdentifier(e)&&L(e)?.compilerNode===t.compilerNode,pi=(e,t,s,n=1)=>{const i=Tu(e,s);if(i!==void 0)return sn(i,t);const o=r.isIdentifier(e)?L(e):void 0;if(r.isBindingElement(o)){const c=o.getParent(),l=c.getParent();return o.getDotDotDotToken()===void 0&&ce(o)===s&&r.isObjectBindingPattern(c)&&(l.compilerNode===t.compilerNode||ie(l)&&sn(h(l.getInitializer()),t))}const a=ie(o)?o.getInitializer():void 0;return n>0&&a!==void 0&&pi(a,t,s,n-1)},Kt=e=>{const t=h(e)??e;return r.isConditionalExpression(t)?[...Kt(t.getWhenTrue()),...Kt(t.getWhenFalse())]:[t]},Ou=(e,t,s)=>{const n=[],i=s===void 0?void 0:Nu(s);for(const o of e.getProperties()){let a,c;if(r.isPropertyAssignment(o)?(a=S(o),c=o.getInitializer()):r.isShorthandPropertyAssignment(o)&&(a=S(o),c=o.getNameNode()),a===void 0||c===void 0||!Pu.has(a))continue;const l=Kt(c).filter(f=>i===void 0?q(f)&&!kr(f):i.isTaintedValue(f,!0));if(l.length>0){const f=t.ownerField===a&&s?.pristine===!0&&pi(c,s.parameter,a),g=l.every(m=>ru(t.call,m));n.push({field:a,file:t.relativePath,line:t.call.getStartLineNumber(),method:t.method,scope:t.scope,...f&&{ownerScoped:!0},...g&&{guarded:!0}})}}return n},ku=(e,t,s)=>{const n=Iu(e.getExpression()),i=n===void 0?void 0:e.getArguments()[1];if(n===void 0||i===void 0)return[];const o=Cu(i,n);if(o.length===0)return[];const a=x(e),c=Xd(e),l={call:e,method:n,ownerField:c===void 0?void 0:s(c.mutatorName),relativePath:t,scope:a};return o.flatMap(u=>Ou(u,l,c))},Ru=(e,t,s=[],n=[])=>{const i=new Map(n.map(c=>[`${c.filePath}:${c.exportName}`,c.owner])),o=C(e,t,(c,l)=>ku(c,l,u=>i.get(`${l}:${u}`))),a=new Map(s.map(c=>[`${c.filePath}:${c.exportName}`,c.adminOnly===!0]));return Ht(o,s).map(c=>Ir(c.scope)?.every(f=>a.get(`${c.file}:${f}`)===!0)===!0?{...c,adminOnly:!0}:c)},Fu=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Lu=e=>e&&r.isNumericLiteral(e)?Number(e.getText()):void 0,Du=e=>{const t=V(e,"webhookToleranceSeconds");return t&&r.isPropertyAssignment(t)?Lu(t.getInitializer()):void 0},Mu=(e,t)=>{const s=P(e.getExpression());if(s===void 0||!Fu.has(s))return;const[n]=e.getArguments(),i=n&&r.isObjectLiteralExpression(n)?Du(n):void 0;return{callee:s,scope:x(e),file:t,line:e.getStartLineNumber(),...i===void 0?{}:{toleranceSeconds:i}}},_u=(e,t)=>C(e,t,Mu),Ku=new Map([["defineQueue",0],["defineSubscription",1],["defineWorkflow",0]]),zu=e=>{const t=e.getExpression();return r.isIdentifier(t)?t.getText():void 0},$u=(e,t)=>{const s=e.getArguments()[t];if(!s||!r.isObjectLiteralExpression(s))return;const n=V(s,"handler");if(n===void 0||!r.isPropertyAssignment(n))return;const i=n.getInitializer();if(i&&(r.isArrowFunction(i)||r.isFunctionExpression(i)))return i},mi=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&r.isIdentifier(s)?s.getText():void 0},hi=(e,t)=>e===t||e.startsWith(`${t}.`),vi=e=>{const t=e.getDescendantsOfKind(d.PropertyAccessExpression);return r.isPropertyAccessExpression(e)&&t.push(e),t},nn=e=>{const t=e.getParent();return r.isPropertyAccessExpression(t)&&t.getNameNode()===e||r.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(r.isBindingElement(t)&&t.getNameNode()===e)},Ei=e=>{const t=e.getDescendantsOfKind(d.Identifier).filter(s=>nn(s));return r.isIdentifier(e)&&nn(e)&&t.push(e),t},Bu=e=>{if(!r.isVariableDeclaration(e))return[];const t=e.getNameNode();return r.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(d.BindingElement).map(s=>s.getName())},Vu=e=>{const t=mi(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(d.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const i=n.getInitializer(),o=r.isVariableDeclarationList(i)?i.getDeclarations()[0]?.getNameNode():void 0;o&&r.isIdentifier(o)&&s.push(`${o.getText()}.body`)}return s},Uu=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:Vu(e),i=new Set,o=a=>vi(a).some(c=>n.some(l=>hi(c.getText(),l)))?!0:Ei(a).some(c=>i.has(c.getText()));for(const a of e.getDescendantsOfKind(d.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of Bu(a))i.add(l)}return{names:i,prefixes:n}},Wu=(e,t)=>vi(e).some(s=>t.prefixes.some(n=>hi(s.getText(),n)))?!0:Ei(e).some(s=>t.names.has(s.getText())),qu=e=>{const t=yr(e);return t===void 0?void 0:{exportName:String(t.at(-1)),file:t.slice(0,-1).join("/")}},ju=(e,t,s)=>{const n=mi(e,0);if(n===void 0)return[];const i=Uu(e,t,n),o=new Set([n,...i.prefixes.filter(c=>c.endsWith(".body")).map(c=>c.slice(0,-5))]),a=[];for(const c of e.getDescendantsOfKind(d.CallExpression)){const l=c.getExpression();if(!r.isPropertyAccessExpression(l)||!Fn.has(l.getName())||!o.has(l.getExpression().getText()))continue;const u=c.getArguments()[1];if(!u||!Wu(u,i))continue;const f=qu(c.getArguments()[0]);f!==void 0&&a.push({dispatchKind:t,file:s,scope:x(c),line:c.getStartLineNumber(),targetExport:f.exportName,targetFile:f.file})}return a},Hu=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=zu(n),o=i===void 0?void 0:Ku.get(i);if(o===void 0)continue;const a=$u(n,o);a!==void 0&&s.push(...ju(a,i==="defineWorkflow"?"workflow":"queue",t))}return s},Gu=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Hu(i,w(t,n)))}return s},rn={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},on=new Set(["account","credential","member","passkey","session","user"]),Yu=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),Qu=e=>{const s=Yu(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return on.has(s)||on.has(n)},Xu=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Ju=(e,t)=>{const{objects:s,opaque:n}=Jt(e,t);return cc(s).some(i=>Xu(i))?!0:n?void 0:!1},Zu=e=>{const t=e.getArguments()[0];return!t||!r.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!V(t,"captcha"),usesRateLimit:!!V(t,"rateLimit")}},ef=e=>{if(r.isCallExpression(e))return e;if(!r.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&r.isCallExpression(s)?s:void 0},ze={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},tf=e=>{const t=ef(e),s=t?P(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=Zu(t);return{...ze,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in rn?{...ze,[rn[s]]:!0}:ze},sf=e=>{const t={...ze};let s=e;for(;r.isCallExpression(s);){const n=s.getExpression();if(!r.isPropertyAccessExpression(n))break;const i=n.getName()==="use"?s.getArguments()[0]:void 0;if(i){const o=tf(i);t.usesCaptcha||=o.usesCaptcha,t.usesEmailGate||=o.usesEmailGate,t.usesMask||=o.usesMask,t.usesRateLimit||=o.usesRateLimit,t.usesRls||=o.usesRls}s=n.getExpression()}return t},nf=new Set(["insert","insertMany","insertManyUnsafe","replace"]),rf=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!nf.has(t.getName()))return!1;const s=t.getExpression();if(!z(s))return!1;const i=e.getArguments()[0];return!i||!(r.isStringLiteral(i)||r.isNoSubstitutionTemplateLiteral(i))?!1:Qu(i.getLiteralText())},of=new Set(["create","publish","publishBatch","runAfter","runAt","send","sendBatch"]),an=new Set(["queues","scheduler","topics","workflows"]),af=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!of.has(t.getName()))return!1;let s=t.getExpression();for(;r.isCallExpression(s)||r.isElementAccessExpression(s)||r.isPropertyAccessExpression(s);){if(r.isPropertyAccessExpression(s)&&an.has(s.getName())&&Rr(s.getExpression()))return!0;s=s.getExpression()}const n=Gt(s);return n?.length===1&&an.has(n[0]??"")},cf=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return z(s)},xi=new Set(["generateObject","generateText","streamObject","streamText"]),lf=e=>{const t=P(e.getExpression());return t!==void 0&&xi.has(t)},df=e=>{const t=P(e.getExpression());if(t===void 0||!xi.has(t))return!1;const s=e.getArguments()[0];return!s||!r.isObjectLiteralExpression(s)||s.getProperties().some(n=>r.isSpreadAssignment(n))?!1:!V(s,"maxOutputTokens")},uf=new Set(["log","span","trace"]),ff=new Set(["ai"]),gf=new Set(["email","mail"]),pf=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","topics","workflows"]),At=(e,t)=>[...t].some(s=>Je(e,s).length>0),Si=new Set([d.ArrowFunction,d.FunctionDeclaration,d.FunctionExpression,d.GetAccessor,d.MethodDeclaration,d.SetAccessor]),mf=new Set(["every","filter","flatMap","forEach","map","some"]),hf=new Set(["all","allSettled","race"]),Ai=e=>{const t=e.getParent();if(!t||!r.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!r.isPropertyAccessExpression(s))return;const n=s.getName();if(mf.has(n))return t;const i=s.getExpression();if(r.isIdentifier(i)&&i.getText()==="Promise"&&hf.has(n))return t},vf=e=>{let t=e.getParent();for(;t;){if(r.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(Si.has(t.getKind())){const s=Ai(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},Ef=e=>{let t=e.getParent();for(;t!==void 0;){if(r.isCallExpression(t)&&t.getExpression().getText()==="Promise.allSettled")return!0;if(Si.has(t.getKind())){if(t=Ai(t),t===void 0)return!1;continue}t=t.getParent()}return!1},xf=e=>{const t=e.getFirstAncestor(u=>r.isArrowFunction(u)||r.isFunctionExpression(u)),s=t?.getParent();if(!t||!r.isCallExpression(s)||!s.getArguments().includes(t))return!1;const n=s.getExpression();if(!r.isIdentifier(n))return!1;const i=n.getSymbol(),o=i?.getAliasedSymbol()?.getValueDeclaration()??i?.getValueDeclaration(),a=r.isVariableDeclaration(o)?o.getInitializer():o;if(!r.isArrowFunction(a)&&!r.isFunctionExpression(a)&&!r.isFunctionDeclaration(a))return!1;const c=s.getArguments().indexOf(t),l=a.getParameters()[c]?.getName();return l===void 0?!1:a.getDescendantsOfKind(d.TryStatement).some(u=>{const f=u.getTryBlock().getDescendantsOfKind(d.CallExpression).some(m=>{const v=m.getExpression();return r.isIdentifier(v)&&v.getText()===l&&r.isAwaitExpression(m.getParent())}),g=u.getCatchClause();return f&&g!==void 0&&g.getDescendantsOfKind(d.ThrowStatement).length>0})},Sf=e=>{let t=e;for(;;){const s=t.getParent();if(!r.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(!r.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},Af=e=>{let t=e;for(;;){const s=t.getParent();if(r.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return r.isCallExpression(s)&&s.getExpression()===t?s:void 0}},yf=e=>{let t=!1,s=!0;for(const n of[...pf].flatMap(i=>Je(e,i))){const i=Af(n);i&&(t=!0,!vf(i)&&!Sf(i)&&!xf(i)&&!Ef(i)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},bf=e=>e.getDescendantsOfKind(d.ThrowStatement).some(t=>{const s=t.getExpression();if(!r.isNewExpression(s))return!1;const n=s.getExpression();return r.isIdentifier(n)&&n.getText()==="Error"}),cn="lunora-advisor-exempt",Nf=/^[\s*/]+/u,Pf=/[\w-]/u,wf=e=>{const s=(e.getFirstAncestorByKind(d.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
|
|
21
|
+
`},Qn=new Set(["delete","get","head","options","patch","post","put"]),Ta=new Set(["handler","stream"]),Oa=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,Ls=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),ka=e=>{if(!r.isCallExpression(e))return;const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!Qn.has(t.getName()))return;const s=t.getExpression();if(!r.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!r.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},Ra=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;r.isCallExpression(s);){const n=s.getExpression();if(!r.isPropertyAccessExpression(n)||Qn.has(n.getName()))break;s=n.getExpression()}return ka(s)},Fa=e=>{for(const t of e.getDescendantsOfKind(d.PropertyAccessExpression))if(Ls.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=t.getExpression();if(r.isIdentifier(s)&&Ls.has(s.getText()))return!0}return!1},La=(e,t)=>{const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const n=s.getExpression();if(!r.isPropertyAccessExpression(n)||!Ta.has(n.getName()))return;const i=Ra(s);if(!i||!Oa.test(i.path))return;const o=s.getArguments()[0],a=o!==void 0&&(r.isArrowFunction(o)||r.isFunctionExpression(o))&&Fa(o);return{exportName:j(e)??e.getName(),file:t,method:i.method,path:i.path,usesGuard:a}},Da=(e,t)=>{const s=[];for(const n of Q(e)){const i=La(n,t);i&&s.push(i)}return s},Ma=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Da(i,w(t,n)))}return s},_a=e=>{const t=e.getText(),s=n=>{const i=n.getNameNode();return r.isIdentifier(i)&&i.getText()===t};for(const n of e.getAncestors())if(!(!r.isArrowFunction(n)&&!r.isFunctionExpression(n)&&!r.isFunctionDeclaration(n)))for(const i of n.getParameters()){const o=i.getDescendantsOfKind(d.BindingElement).find(a=>s(a));if(o!==void 0)return o}},Ka=e=>{let t=e;for(;;){const s=t.getParent();if(!r.isObjectBindingPattern(s))return;const n=s.getParent();if(r.isBindingElement(n)){t=n;continue}return r.isParameterDeclaration(n)?ce(t):void 0}},za=e=>{const t=e.getText();if(!e.getAncestors().some(o=>{const a=r.isFunctionLikeDeclaration(o)||r.isArrowFunction(o)?o.getParameters()[1]:void 0,c=a?.getNameNode();return a!==void 0&&(r.isIdentifier(c)?c.getText()===t:a.getDescendantsOfKind(d.BindingElement).some(l=>l.getName()===t))&&Fs(a)}))return!1;const n=L(e),i=r.isParameterDeclaration(n)?n:n?.getFirstAncestorByKind(d.Parameter);return i!==void 0&&(r.isParameterDeclaration(n)||r.isBindingElement(n))&&Fs(i)},Ds=(e,t)=>{const s=e.getParent();if(r.isPropertyAccessExpression(s)&&s.getNameNode()===e||r.isPropertyAssignment(s)&&s.getNameNode()===e)return!1;if(e.getText()===t)return!0;const n=_a(e);return n!==void 0&&Ka(n)===t?!0:t==="args"&&za(e)},Xn=(e,t)=>r.isIdentifier(e)?Ds(e,t):e.getDescendantsOfKind(d.Identifier).some(s=>Ds(s,t)),$a=e=>{let t=e;for(;r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t)||r.isNonNullExpression(t);)t=t.getExpression();return r.isIdentifier(t)?t:void 0},Ms=e=>{const t=r.isIdentifier(e)?L(e):void 0;return r.isVariableDeclaration(t)&&r.isIdentifier(t.getNameNode())&&!qt(t)?t.getInitializer():void 0},Tt=e=>Xn(e,"args"),Y=e=>{if(!r.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>r.isArrowFunction(a)||r.isFunctionExpression(a)||r.isFunctionDeclaration(a));if(s===void 0)return;const n=e.getStart();let i,o=-1;for(const a of s.getDescendantsOfKind(d.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<n&&l>o&&(i=c,o=l)}return i},q=e=>{if(Tt(e))return!0;const t=Y(e);return t!==void 0&&Tt(t)},Ba=e=>{if(r.isCallExpression(e)||r.isNewExpression(e))return!1;const t=Y(e);return t===void 0||!(r.isCallExpression(t)||r.isNewExpression(t))},le=e=>{if(vt(e))return!0;const t=Ms(e);if(t!==void 0&&vt(t))return!0;const s=t??e;return(r.isIdentifier(s)?[s]:s.getDescendantsOfKind(d.Identifier)).some(i=>{const o=Ms(i);return o!==void 0&&vt(o)})},De=(e,t)=>Xn(e,t),Va=(e,t)=>{if(De(e,t))return!0;const s=Y(e);if(s!==void 0&&De(s,t))return!0;const n=$a(e);if(n!==void 0){const i=Y(n);return i!==void 0&&De(i,t)}return!1},Ua=e=>!r.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:G(e.getExpression(),["ai"]),Wa=(e,t)=>{if(!Ua(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!q(s)||le(s)))return{scope:x(e),file:t,line:e.getStartLineNumber()}},qa=(e,t)=>C(e,t,Wa),ja=new Set(["generateText","streamText"]),Ha=new Set(["messages","prompt","system"]),Ga=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","patchIf","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"]}],Ya=(e,t)=>Ga.some(s=>s.methods.has(t)&&s.prefixes.some(n=>e===n||e.startsWith(`${n}.`))),Qa=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return;const s=t.getName(),n=[Tr(t.getExpression()),t.getExpression().getText()].find(i=>i!==void 0&&Ya(i,s));return n===void 0?void 0:`${n}.${s}`},Xa=e=>{for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=Qa(t);if(s!==void 0)return s}},Ja=e=>{const t=new Set,s=e.getFirstAncestor(o=>r.isArrowFunction(o)||r.isFunctionExpression(o)||r.isFunctionDeclaration(o)),[n]=s?.getParameters()??[],i=n?.getNameNode();if(i===void 0||!r.isObjectBindingPattern(i))return t;for(const o of i.getElements()){const a=ce(o),c=o.getNameNode();if(a==="args"&&r.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},Za=e=>{if(Tt(e))return!0;const t=Ja(e);return t.size===0?!1:e.getDescendantsOfKind(d.Identifier).some(s=>t.has(s.getText()))},ec=e=>{for(const t of e.getProperties()){if(!r.isPropertyAssignment(t)||!Ha.has(S(t)))continue;const s=t.getInitializer();if(s!==void 0&&Za(s))return!0}return!1},tc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=P(n.getExpression());if(i===void 0||!ja.has(i))continue;const[o]=n.getArguments();if(o===void 0||!r.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(d.CallExpression))if(P(c.getExpression())==="tool"&&(a=Xa(c),a!==void 0))break;a!==void 0&&s.push({scope:x(n),file:t,line:n.getStartLineNumber(),method:i,sideEffect:a,userInputDerived:ec(o)})}return s},sc=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...tc(i,w(t,n)))}return s},nc=e=>G(e,["fetch"]),ic=(e,t)=>{if(!nc(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!q(s)))return{scope:x(e),file:t,line:e.getStartLineNumber()}},rc=(e,t)=>C(e,t,ic),Xt=(e,t=new Set)=>{if(t.has(e))return!0;t.add(e);try{return e.getProperties().some(s=>{if(!r.isSpreadAssignment(s))return!1;const n=et(s.getExpression());return n===void 0||Xt(n,t)})}finally{t.delete(e)}},oc=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=V(t,"args");if(!s)return{objects:[],opaque:!1};if(!r.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer(),i=n===void 0?void 0:et(n);return i===void 0?{objects:[],opaque:!0}:{objects:[i],opaque:Xt(i)}},ac=e=>{const t=[];let s=!1,n=e;for(;r.isCallExpression(n);){const i=n.getExpression();if(!r.isPropertyAccessExpression(i))break;if(i.getName()==="input"){const o=n.getArguments()[0],a=o!==void 0&&r.isExpression(o)?et(o):void 0;a===void 0?s=!0:(t.push(a),s||=Xt(a))}n=i.getExpression()}return{objects:t,opaque:s}},Jt=(e,t)=>t?ac(t):oc(e),Jn=(e,t)=>{if(t.has(e))return[];t.add(e);try{return e.getProperties().flatMap(s=>{if(r.isSpreadAssignment(s)){const n=et(s.getExpression());return n===void 0?[]:Jn(n,t)}return r.isPropertyAssignment(s)||r.isShorthandPropertyAssignment(s)?[S(s)]:[]})}finally{t.delete(e)}},cc=e=>e.flatMap(t=>Jn(t,new Set)),lc=new Set(["check","length","max"]),Ot=e=>{let t=e;for(;;){const s=t.getParent();if(!s||!r.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;const n=s.getParent();if(!n||!r.isCallExpression(n)||n.getExpression()!==s)return!1;if(lc.has(s.getName()))return!0;t=n}},kt=e=>_r(e)||e==="@lunora/values",dc=e=>{const t=new Set(["v"]);for(const s of Fr(e,"v",kt))t.add(s);for(const s of e.getImportDeclarations()){const n=s.getNamespaceImport();n&&kt(s.getModuleSpecifierValue())&&t.add(`${n.getText()}.v`)}return t},uc=(e,t)=>{const s=new Map;for(const n of e.getVariableStatements())for(const i of n.getDeclarations()){const o=i.getNameNode(),a=i.getInitializer();if(!(!r.isObjectBindingPattern(o)||!a||!t.has(a.getText())))for(const c of o.getElements())c.getDotDotDotToken()||s.set(c.getName(),c.getPropertyNameNode()?.getText()??c.getName())}return s},fc=e=>(e.getSymbol()?.getDeclarations()??[]).some(t=>!t.getSourceFile().isDeclarationFile()&&!r.isImportSpecifier(t)&&!r.isNamespaceImport(t)&&!r.isImportClause(t)),gc=e=>(e.getSymbol()?.getDeclarations()??[]).some(t=>r.isNamespaceImport(t)&&kt(t.getFirstAncestorByKindOrThrow(d.ImportDeclaration).getModuleSpecifierValue())),Zt=(e,t)=>{if(!r.isCallExpression(e))return;const s=e.getExpression();if(r.isPropertyAccessExpression(s)){const n=s.getExpression();if(!t.namespaces.has(n.getText()))return;if(r.isIdentifier(n))return fc(n)?void 0:s.getName();const i=r.isPropertyAccessExpression(n)?n.getExpression():void 0;return r.isIdentifier(i)&&gc(i)?s.getName():void 0}if(r.isIdentifier(s))return t.destructured.get(s.getText())},pc=(e,t)=>{if(!r.isIdentifier(e))return;const s=e.getText(),n=t.getVariableDeclaration(s)?.getInitializer();return n&&(r.isArrowFunction(n)||r.isFunctionExpression(n))?n:t.getFunction(s)},mc=e=>{let t=e.getParent();for(;t&&!r.isFunctionLikeDeclaration(t);)t=t.getParent();return t},hc=e=>r.isReturnStatement(e)?e.getExpression():void 0,vc=e=>r.isArrowFunction(e)&&!r.isBlock(e.getBody())?[e.getBody()]:e.getDescendantsOfKind(d.ReturnStatement).filter(t=>mc(t)?.compilerNode===e.compilerNode).flatMap(t=>{const s=hc(t);return s?[s]:[]}),Zn=(e,t)=>{if(Zt(e,t)!==void 0)return e;if(r.isCallExpression(e)||r.isPropertyAccessExpression(e))return Zn(e.getExpression(),t)},Ec=(e,t)=>{const s=pc(e.getExpression(),e.getSourceFile());if(!s)return[];const n=Ot(e),i=new Set(vc(s).map(o=>Zn(o,t)).filter(o=>o!==void 0));return[s,...s.getDescendants()].flatMap(o=>{const a=Zt(o,t);return a===void 0?[]:[{bounded:Ot(o)||n&&i.has(o),factory:a}]})},xc=(e,t)=>[e,...e.getDescendants()].flatMap(s=>{const n=Zt(s,t),i=n===void 0?[]:[{bounded:Ot(s),factory:n}];return r.isCallExpression(s)?[...i,...Ec(s,t)]:i}),Sc=(e,t)=>{const s=[],n=[];for(const i of e)for(const o of i.getProperties()){if(!r.isPropertyAssignment(o))continue;const a=o.getInitializer();if(!a)continue;const c=xc(a,t),l=S(o);c.some(u=>u.factory==="any")?s.push(l):c.some(u=>u.factory==="string"&&!u.bounded)&&n.push(l)}return{anyArgs:s,unboundedStringArgs:n}},Ac=(e,t,s)=>{const n=e.getInitializer();if(!n||!r.isCallExpression(n))return;const i=ee(n);if(i?.visibility!=="public")return;const{objects:o}=Jt(n,i.receiver),{anyArgs:a,unboundedStringArgs:c}=Sc(o,s);if(!(a.length===0&&c.length===0))return{anyArgs:a,exportName:j(e)??e.getName(),file:t,line:n.getStartLineNumber(),unboundedStringArgs:c}},yc=(e,t)=>{const s=[],n=dc(e),i={destructured:uc(e,n),namespaces:n};for(const o of Q(e)){const a=Ac(o,t,i);a&&s.push(a)}return s},bc=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...yc(i,w(t,n)))}return s},Et=e=>e?.getKind()===d.TrueKeyword,Nc=e=>e?.getKind()===d.FalseKeyword,Pc=e=>e!==void 0&&r.isNumericLiteral(e)&&e.getLiteralValue()===0,wc=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Ic=e=>!e||!r.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>r.isCallExpression(t)&&P(t.getExpression())==="scim"),Cc=e=>e!==void 0&&r.isCallExpression(e)&&wc.has(P(e.getExpression())??""),Tc=e=>!e||!r.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>r.isStringLiteral(t)&&t.getLiteralText()==="*"),Oc=e=>{const t=R(e,"advanced"),s=R(e,"emailAndPassword"),n=R(e,"session");return{analyzable:!0,disableCsrfCheck:Et(R(t,"disableCSRFCheck")),emailPasswordEnabled:Et(R(s,"enabled")),requireEmailVerification:Et(R(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Ic(R(e,"plugins"))&&Cc(R(e,"database")),secureCookiesDisabled:Nc(R(t,"useSecureCookies")),sessionFreshAgeZero:Pc(R(n,"freshAge")),trustedOriginsWildcard:Tc(R(e,"trustedOrigins"))}},kc=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Rc=(e,t)=>{if(P(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&r.isObjectLiteralExpression(s)&&s.getProperties().some(o=>r.isSpreadAssignment(o)),i=s!==void 0&&r.isObjectLiteralExpression(s)&&!n?Oc(s):kc();return{scope:x(e),file:t,line:e.getStartLineNumber(),...i}},Fc=(e,t)=>xr(e,t,Rc),Lc=(e,t)=>{if(!r.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return Dn(e.getExpression(),t.matchReceiver)?s:void 0},Dc=(e,t,s)=>{const n=Lc(e.getExpression(),s);if(n===void 0)return;const i=e.getArguments()[s.argIndex];if(!(!i||!q(i)||le(i))&&!(s.requireUnmodifiedReach===!0&&!Ba(i)))return{scope:x(e),file:t,line:e.getStartLineNumber(),method:n}},tt=(e,t,s)=>C(e,t,(n,i)=>Dc(n,i,s)),Mc=new Set(["content","pdf","scrape","screenshot"]),_c=(e,t)=>tt(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Mc}),Kc=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),zc=new Set(["RateLimiter"]),$c=new Set(["extend"]),_s="lunora",Bc=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],ei=e=>{const t=[],s=[];let n=!1;for(const i of e.getProperties()){if(r.isSpreadAssignment(i)){n=!0;continue}if(r.isPropertyAssignment(i)){const o=S(i);t.push(o),i.getInitializer()?.getKind()===d.TrueKeyword&&s.push(o);continue}(r.isShorthandPropertyAssignment(i)||r.isMethodDeclaration(i))&&t.push(S(i))}return{analyzable:!n,presentKeys:t,trueKeys:s}},Rt=e=>e&&r.isObjectLiteralExpression(e)?ei(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Vc=e=>{const t=e&&(r.isArrowFunction(e)||r.isFunctionExpression(e))?e:void 0,s=t&&On(t.getBody());return s?ei(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Uc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=P(n.getExpression());i!==void 0&&(Kc.has(i)?s.push({callee:i,file:t,line:n.getStartLineNumber(),...Rt(n.getArguments()[0])}):$c.has(i)&&s.push({callee:i,file:t,line:n.getStartLineNumber(),...Vc(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(d.NewExpression)){const i=P(n.getExpression());i===void 0||!zc.has(i)||s.push({callee:i,file:t,line:n.getStartLineNumber(),...Rt(n.getArguments()[0])})}return s},Wc=e=>{for(const t of Bc){const s=E(e,t);if(!M(s))continue;const n=new Ut({compilerOptions:{allowJs:!0},skipFileDependencyResolution:!0,skipLoadingLibFiles:!0,useInMemoryFileSystem:!0}).createSourceFile(t,Ge(s,"utf8")),i=[];for(const o of n.getDescendantsOfKind(d.CallExpression))P(o.getExpression())===_s&&i.push({callee:_s,file:t,line:o.getStartLineNumber(),...Rt(o.getArguments()[0])});return i}return[]},qc=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of Ye(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);s.push(...Uc(o,n))}return s.push(...Wc(Vt(t))),s},Ks="ctx.containers.",jc=e=>{if(!e.startsWith(Ks))return!1;const t=e.slice(Ks.length);return t.length>0&&!t.includes(".")},Hc=(e,t)=>tt(e,t,{argIndex:0,matchReceiver:jc,methods:new Set(["get"])}),Gc=new Set(["allow","deny","setAllowed"]),Yc=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return!1;const s=V(t,"enableInternet");return s!==void 0&&r.isPropertyAssignment(s)&&r.isTrueLiteral(s.getInitializerOrThrow())},Qc=(e,t)=>{const s=e.getExpression();if(!(!r.isPropertyAccessExpression(s)||s.getName()!=="start"||!Yc(e)))return{detail:"enableInternet: true",scope:x(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},Xc=(e,t)=>{const s=e.getExpression();if(!r.isPropertyAccessExpression(s)||!Gc.has(s.getName()))return;const n=s.getExpression();if(!(!r.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),scope:x(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},Jc=(e,t)=>Qc(e,t)??Xc(e,t),Zc=(e,t)=>C(e,t,Jc),el=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="count")return;const s=t.getExpression();if(z(s)){const n=e.getArguments()[0];return n&&r.isStringLiteral(n)?n.getLiteralText():""}return r.isPropertyAccessExpression(s)&&z(s.getExpression())?s.getName():void 0},tl=e=>{const t=e.getExpression(),s=r.isPropertyAccessExpression(t)?t.getExpression():void 0;return e.getArguments()[s!==void 0&&z(s)?1:0]},sl=new Set(["baseWhere","relationBaseWhere","restrictsCounts","where"]),nl=e=>{if(e===void 0||!r.isObjectLiteralExpression(e))return;const t=[];for(const n of e.getProperties()){if(!r.isPropertyAssignment(n)&&!r.isShorthandPropertyAssignment(n))return;t.push(n.getName())}return t.length>0&&t.every(n=>sl.has(n))||t.some(n=>n==="AND"||n==="OR"||n==="NOT")?void 0:t},il=(e,t,s)=>{const n=new Map(s.map(i=>[i.name,i.aggregateIndexed===!0]));return C(e,t,(i,o)=>{const a=el(i);if(a===void 0)return;const c=nl(tl(i));return{file:o,indexed:n.get(a)!==!1,...c===void 0?{}:{filterFields:c},line:i.getStartLineNumber(),scope:x(i),table:a}})},rl=new Set(["defineExportSink","r2Sink","webhookExportSink"]),ol=e=>{const t=e.getExpression();if(!r.isIdentifier(t))return;const s=t.getText();return rl.has(s)?s:void 0},al=e=>{const t=[],s=[];for(const n of e.getProperties()){if(r.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(r.isPropertyAssignment(n)){const i=S(n);t.push(i);const o=n.getInitializer();o&&r.isStringLiteral(o)&&o.getLiteralText()===""&&s.push(i);continue}(r.isShorthandPropertyAssignment(n)||r.isMethodDeclaration(n)||r.isGetAccessorDeclaration(n))&&t.push(S(n))}return{analyzable:!0,emptyKeys:s,presentKeys:t}},cl=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of Ye(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);for(const a of o.getDescendantsOfKind(d.CallExpression)){const c=ol(a);if(c===void 0)continue;const l=a.getArguments()[0],u=l&&r.isObjectLiteralExpression(l)?al(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:u.analyzable,emptyKeys:u.emptyKeys,factory:c,file:n,line:a.getStartLineNumber(),presentKeys:u.presentKeys})}}return s},ll=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),dl=new Set(["dbRateLimit","rateLimit"]),ul=e=>{const t=Rn(e);if(!t)return!1;const s=V(t,"failOpen");return s!==void 0&&r.isPropertyAssignment(s)&&s.getInitializer()?.getKind()===d.TrueKeyword},fl=(e,t)=>{const s=P(e.getExpression());if(s===void 0)return;const n=ll.get(s);if(n!==void 0)return{callee:s,scope:x(e),failOpen:ul(e.getArguments()[n]),file:t,limitName:dl.has(s)?kn(e):"",line:e.getStartLineNumber()}},gl=(e,t)=>C(e,t,fl),pl=e=>{const t=e.getInitializer();if(!t||!r.isCallExpression(t))return;const s=ee(t);if(s?.kind!=="query")return;const n=Sr(t,s.receiver);return n?{exportName:j(e)??e.getName(),handler:n}:void 0},zs=e=>{const t=e.getParent();return t&&r.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},ml=e=>{const t=zs(e);if(!t)return"ctx.flags";if(t.getName()==="details"){const s=zs(t);return s?`ctx.flags.details.${s.getName()}`:"ctx.flags.details"}return`ctx.flags.${t.getName()}`},hl=(e,t)=>{const s=[];for(const n of Je(e.handler,"flags"))s.push({callee:ml(n),exportName:e.exportName,file:t,line:n.getStartLineNumber()});return s},vl=(e,t)=>{const s=[];for(const n of Q(e)){const i=pl(n);i&&s.push(...hl(i,t))}return s},El=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...vl(i,w(t,n)))}return s},xl=e=>!r.isPropertyAccessExpression(e)||e.getName()!=="boolean"?!1:G(e.getExpression(),["flags"]),Sl=e=>{if(e?.getKind()===d.TrueKeyword)return!0;if(e?.getKind()===d.FalseKeyword)return!1},Al=(e,t)=>{if(!xl(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(r.isStringLiteral(s)||r.isNoSubstitutionTemplateLiteral(s)))return;const i=s.getLiteralValue(),o=Sl(n);if(!(i.length===0||o===void 0))return{defaultValue:o,scope:x(e),file:t,key:i,line:e.getStartLineNumber()}},yl=(e,t)=>C(e,t,Al),bl=e=>{const t=e.getExpression();return r.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Nl=e=>{const t=e.getArguments()[0];return t&&r.isStringLiteral(t)?t.getLiteralText():""},Pl=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=w(t,n);for(const a of i.getDescendantsOfKind(d.CallExpression))bl(a)&&s.push({file:o,indexName:Nl(a),line:a.getStartLineNumber()})}return s},be=e=>e!==void 0&&(r.isArrowFunction(e)||r.isFunctionExpression(e))?e:void 0,ti=e=>{const t=e.getArguments()[0],s=be(t);if(s!==void 0)return s;if(t===void 0||!r.isObjectLiteralExpression(t))return;const n=V(t,"handler");return n!==void 0&&r.isPropertyAssignment(n)?be(n.getInitializer()):void 0},wl=new Set(["delete","get","head","options","patch","post","put"]),Il=new Set(["handler","stream"]),Cl=new Set(["runAction","runMutation"]),Tl=new Set(["delete","insert","insertManyUnsafe","patch","patchIf","replace"]),Ne=(e,t)=>e!==void 0&&r.isIdentifier(e)&&e.getText()===t,si=(e,t)=>{if(!(e===void 0||!r.isObjectBindingPattern(e))){for(const s of e.getElements())if(ce(s)===t){const i=s.getNameNode();return r.isIdentifier(i)?i.getText():void 0}}},$s=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?r.isIdentifier(s)?s.getText():void 0:si(s,"ctx")},Bs=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&r.isIdentifier(s)?s.getText():void 0:si(s,"request")},Vs=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(d.CallExpression);r.isCallExpression(s)&&n.unshift(s);for(const i of n){const o=i.getExpression();if(!r.isPropertyAccessExpression(o))continue;const a=o.getName(),c=o.getExpression();if(Cl.has(a)&&Ne(c,t))return a;if(Tl.has(a)&&r.isPropertyAccessExpression(c)&&c.getName()==="db"&&Ne(c.getExpression(),t))return`db.${a}`}},Us=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(d.PropertyAccessExpression))if(n.getName()==="auth"&&Ne(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(d.VariableDeclaration)){const i=n.getNameNode();if(!(!r.isObjectBindingPattern(i)||!Ne(n.getInitializer(),t))){for(const o of i.getElements())if(ce(o)==="auth")return!0}}return!1},Ol=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,kl=(e,t)=>{const s=e.getExpression();if(!r.isPropertyAccessExpression(s)||s.getName()!=="get"&&s.getName()!=="has")return!1;const n=s.getExpression();return r.isPropertyAccessExpression(n)&&n.getName()==="headers"&&Ne(n.getExpression(),t)},Rl=e=>[...r.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(d.StringLiteral).map(t=>t.getLiteralText())],ni=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:Rl(s)},Fl=(e,t)=>{const s=e.getText();for(let n=e.getParent();n!==void 0;n=n.getParent()){if(!r.isArrowFunction(n)&&!r.isFunctionExpression(n)||!n.getParameters().some(c=>c.getName()===s))continue;const i=n.getParent();if(!r.isCallExpression(i))return[];const o=i.getExpression();if(!r.isPropertyAccessExpression(o))return[];const a=o.getExpression();return r.isIdentifier(a)?ni(t,a.getText()):[]}return[]},Ll=e=>{const t=e.getArguments()[0];if(t===void 0)return[];if(r.isStringLiteral(t))return[t.getLiteralText()];if(!r.isIdentifier(t))return[];const s=e.getSourceFile(),n=ni(s,t.getText());return n.length>0?n:Fl(t,s)},Ws=(e,t)=>{if(t===void 0)return!1;const s=e.getBody(),n=s.getDescendantsOfKind(d.CallExpression);return r.isCallExpression(s)&&n.unshift(s),n.some(i=>kl(i,t)&&Ll(i).some(o=>Ol.test(o)))},Dl=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!Il.has(t.getName()))return;let s=t.getExpression();for(;r.isCallExpression(s);){const n=s.getExpression();if(!r.isPropertyAccessExpression(n))return;const i=n.getName();if(wl.has(i)){const o=n.getExpression();return r.isIdentifier(o)&&o.getText()==="httpRoute"?i.toUpperCase():void 0}s=n.getExpression()}},Ml=(e,t)=>{const s=e.getExpression();if(r.isIdentifier(s)&&s.getText()==="httpAction"){const c=be(e.getArguments()[0]),l=c&&$s(c,!0);if(!c||l===void 0||Ws(c,Bs(c,!0)))return;const u=Vs(c,l);return u===void 0?void 0:{scope:x(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:Us(c,l),sideEffect:u}}const n=Dl(e);if(n===void 0)return;const i=be(e.getArguments()[0]),o=i&&$s(i,!1);if(!i||o===void 0||Ws(i,Bs(i,!1)))return;const a=Vs(i,o);return a===void 0?void 0:{scope:x(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:Us(i,o),sideEffect:a}},_l=(e,t)=>C(e,t,Ml),Kl=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),zl=new Set(["append","set"]),ii=e=>e!==void 0&&(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",qs=(e,t)=>(r.isCallExpression(e)?[e,...e.getDescendantsOfKind(d.CallExpression)]:e.getDescendantsOfKind(d.CallExpression)).some(n=>Kl.has(P(n.getExpression())??"")&&De(n,t)),$l=(e,t)=>{if(qs(e,t))return!0;const s=Y(e);return s!==void 0&&qs(s,t)},Ft=(e,t)=>Va(e,t)&&!$l(e,t),Bl=e=>{if(r.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=Y(e);return t!==void 0&&r.isNewExpression(t)&&P(t.getExpression())==="Headers"},Ve=e=>{if(e===void 0)return;if(r.isObjectLiteralExpression(e))return e;const t=Y(e);return t!==void 0&&r.isObjectLiteralExpression(t)?t:void 0},es=(e,t,s)=>{for(const n of e.getProperties())if(r.isPropertyAssignment(n)){const i=n.getInitializer();i!==void 0&&Ft(i,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:ii(n.getNameNode()),line:i.getStartLineNumber(),via:t})}else if(r.isShorthandPropertyAssignment(n)){const i=n.getNameNode();Ft(i,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:S(n),line:i.getStartLineNumber(),via:t})}else if(r.isSpreadAssignment(n)){const i=Ve(n.getExpression());i!==void 0&&es(i,t,s)}},ri=(e,t)=>{const s=Ve(e);if(s===void 0)return;const n=V(s,"headers");if(n===void 0||!r.isPropertyAssignment(n))return;const i=Ve(n.getInitializer());i!==void 0&&es(i,"response-init",t)},Vl=(e,t)=>{const s=P(e.getExpression());if(s==="Response")ri(e.getArguments()[1],t);else if(s==="Headers"){const n=Ve(e.getArguments()[0]);n!==void 0&&es(n,"headers-ctor",t)}},Ul=(e,t)=>{const s=e.getExpression();if(!r.isPropertyAccessExpression(s))return;const n=s.getName(),i=s.getExpression();if(n==="json"&&r.isIdentifier(i)&&i.getText()==="Response"){ri(e.getArguments()[1],t);return}if(zl.has(n)&&Bl(i)){const o=e.getArguments()[1];o!==void 0&&Ft(o,t.requestName)&&t.rows.push({scope:t.scope,file:t.relativePath,headerName:ii(e.getArguments()[0]),line:o.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},Wl=(e,t)=>{for(const s of e.getDescendantsOfKind(d.NewExpression))Vl(s,t);for(const s of e.getDescendantsOfKind(d.CallExpression))Ul(s,t)},ql=(e,t)=>{const s=e.getExpression();if(!r.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=be(e.getArguments()[0]);if(n===void 0)return[];const i=n.getParameters()[1];if(i===void 0)return[];const o=i.getNameNode();if(!r.isIdentifier(o))return[];const a=[];return Wl(n,{scope:x(e),relativePath:t,requestName:o.getText(),rows:a}),a},jl=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression))s.push(...ql(n,t));return s},Hl=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...jl(i,w(t,n)))}return s},oi="identity.ts",Gl=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(r.isImportSpecifier(s))return Ze(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Yl=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!r.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(d.ImportDeclaration);return n!==void 0&&Ze(n.getModuleSpecifierValue())}return!1},Ql=e=>{if(r.isIdentifier(e))return Gl(e);if(r.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&r.isIdentifier(t)&&Yl(t)}return!1},Xl=e=>{const t=[];for(const s of e.getVariableDeclarations()){const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!Ql(n.getExpression()))continue;const o=s.getNameNode();if(!r.isIdentifier(o)){if(s.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw de(o,"defineIdentity exports must be plain named exports (no destructuring)")}const a=jt(s,"member");a!==void 0&&t.push({exportName:a})}return t},Jl=(e,t)=>{const s=E(t,oi);if(!M(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=Xl(n);if(i.length!==0){if(i.length>1)throw de(n,`lunora/identity.ts declares ${i.length.toString()} defineIdentity() contracts (${i.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Zl=new Set(["auth","context.auth"]),ed="userId",td=e=>{const t=new Set;for(const s of e.getProperties()){if(r.isSpreadAssignment(s))return;(r.isPropertyAssignment(s)||r.isShorthandPropertyAssignment(s)||r.isMethodDeclaration(s))&&t.add(S(s))}return t},sd=(e,t)=>{const s=E(t,oi);if(!M(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const i of n.getDescendantsOfKind(d.CallExpression)){if(P(i.getExpression())!=="defineIdentity")continue;const[o]=i.getArguments();return o&&r.isObjectLiteralExpression(o)?td(o):void 0}},js=e=>{if(e===void 0||!r.isPropertyAccessExpression(e)||e.getName()!=="identity")return;const t=e.getExpression();return Zl.has(t.getText())||G(t,["auth"])?e:void 0},nd=e=>{if(r.isPropertyAccessExpression(e)&&js(e.getExpression())!==void 0)return e.getName();if(r.isElementAccessExpression(e)&&js(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&r.isStringLiteral(t)?t.getLiteralValue():void 0}},Hs=(e,t,s)=>{const n=nd(e);return n===void 0?void 0:{declared:n===ed||s.has(n),file:t,key:n,line:e.getStartLineNumber(),scope:x(e)}},id=(e,t)=>{const s=sd(e,t);return s===void 0?[]:[...ne(e,t,d.PropertyAccessExpression,(n,i)=>Hs(n,i,s)),...ne(e,t,d.ElementAccessExpression,(n,i)=>Hs(n,i,s))]},rd=(e,t)=>{if(P(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=R(s,"key");if(!(!n||!q(n)||le(n)))return{scope:x(e),file:t,line:e.getStartLineNumber()}},od=(e,t)=>C(e,t,rd),ad=new Set(["delete","get","getRaw","getWithMetadata","put"]),cd=(e,t,s=[])=>{const n=tt(e,t,{argIndex:0,matchReceiver:i=>i==="ctx.kv"||i.startsWith("ctx.kv."),methods:ad});return Ht(n,s)},ld=new Set(["queue","send"]),Gs=new Set(["bcc","cc","to"]),dd=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();if(!ld.has(t))return;const s=e.getExpression();return G(s,["mail"])||G(s,["email"])?t:void 0},ud=e=>r.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(r.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return Gs.has(S(t))&&q(n)&&!le(n)}if(!r.isPropertyAssignment(t)||!Gs.has(S(t)))return!1;const s=t.getInitializer();return s!==void 0&&q(s)&&!le(s)}):!1,fd=(e,t)=>{const s=dd(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!ud(n)))return{scope:x(e),file:t,line:e.getStartLineNumber(),method:s}},gd=(e,t)=>C(e,t,fd),pd=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!r.isObjectLiteralExpression(n))return[];const i=[];for(const o of n.getProperties()){const a=Be(o);if(a===void 0||!r.isPropertyAssignment(o))continue;const c=o.getInitializer();if(!(!c||!r.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const u=Be(l);if(u===void 0)continue;const f=Bn(l);f!=="custom"&&i.push({column:u,exportName:t,file:s,line:l.getStartLineNumber(),strategy:f,table:a})}}return i},md=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&r.isCallExpression(s)?ee(s):void 0;return n?.receiver?Yt(n.receiver).flatMap(i=>pd(i,j(e)??e.getName(),t)):[]},hd=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=w(t,n);for(const a of Q(i))s.push(...md(a,o))}return s},vd=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return z(s)},Ed=e=>{const t=e.getArguments()[0];if(t===void 0||!r.isObjectLiteralExpression(t))return;const s=V(t,"server");if(s!==void 0)return r.isPropertyAssignment(s)?s.getInitializer():s},xd=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==d.CallExpression)return;const s=t;return Ur(s.getExpression())?s:void 0},Sd=e=>{const t=xd(e),s=t===void 0?void 0:Ed(t);if(s===void 0)return[];const n=e.getNameNode(),i=r.isIdentifier(n)?j(e)??n.getText():"";return s.getDescendantsOfKind(d.CallExpression).filter(o=>vd(o)).map(o=>({exportName:i,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},Ad=e=>e.getVariableDeclarations().flatMap(t=>Sd(t)),yd=(e,t)=>{const s=E(t,Vr);if(!M(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Ad(n)},bd=new Set(["delete","get","patch"]),Nd=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Pd=new Set(["auth","identity","session","user"]),wd=new Set([d.EqualsEqualsEqualsToken,d.EqualsEqualsToken,d.ExclamationEqualsEqualsToken,d.ExclamationEqualsToken]),Id=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!z(t.getExpression()))return;const s=e.getArguments()[0];return s&&r.isStringLiteral(s)?s.getLiteralText():""},Cd=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(r.isAsExpression(s)||r.isParenthesizedExpression(s)||r.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!r.isVariableDeclaration(s))return;const n=s.getNameNode();return r.isIdentifier(n)?n.getText():void 0},Td=(e,t)=>e.getDescendantsOfKind(d.Identifier).some(s=>s.getText()===t),Od=e=>r.isThrowStatement(e)||r.isReturnStatement(e)||e.getDescendantsOfKind(d.ThrowStatement).length>0||e.getDescendantsOfKind(d.ReturnStatement).length>0,kd=(e,t)=>e.getDescendantsOfKind(d.IfStatement).some(s=>Td(s.getExpression(),t)&&Od(s.getThenStatement())),Rd=(e,t)=>{for(const s of e.getDescendantsOfKind(d.CallExpression)){const n=s.getExpression();if(!r.isPropertyAccessExpression(n))continue;const i=n.getName();if(!bd.has(i))continue;const o=n.getExpression(),a=z(o);if(!(a||r.isPropertyAccessExpression(o)&&z(o.getExpression())))continue;const l=a&&i==="get"?2:1;if(s.getArguments().slice(0,l).some(f=>r.isIdentifier(f)&&f.getText()===t))return i}},Fd=e=>e.getDescendantsOfKind(d.CallExpression).some(t=>t.getArguments().some(s=>Gt(Qe(s))!==void 0)),Ld=e=>e.getDescendantsOfKind(d.BinaryExpression).some(t=>wd.has(t.getOperatorToken().getKind())?r.isPropertyAccessExpression(t.getLeft())||r.isPropertyAccessExpression(t.getRight()):!1),Dd=e=>{for(const t of e.getDescendantsOfKind(d.Identifier))if(Nd.has(t.getText()))return!0;return[...Pd].some(t=>Je(e,t).length>0)?!0:Fd(e)||Ld(e)},Md=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!r.isCallExpression(s))return[];const n=ee(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const i=ti(s);if(i===void 0)return[];const o=n.receiver!==void 0&&Kn(n.receiver,"use","rls"),a=Dd(i),c=new Set,l=[];for(const u of i.getDescendantsOfKind(d.CallExpression)){const f=Id(u);if(f===void 0)continue;const g=Cd(u);if(g===void 0||c.has(g)||!kd(i,g))continue;const m=Rd(i,g);m!==void 0&&(c.add(g),l.push({exportName:j(e)??e.getName(),file:t,line:u.getStartLineNumber(),mentionsOwnership:a,sinkMethod:m,table:f,usesRls:o,visibility:n.visibility}))}return l},_d=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=w(t,n);for(const a of Q(i))s.push(...Md(a,o))}return s},ai=(e,t)=>{const s=r.isIdentifier(e)&&t!==void 0?L(e):void 0;return s===void 0||t===void 0?!1:s.compilerNode===t.compilerNode?r.isIdentifier(t.getNameNode()):r.isBindingElement(s)&&s.getFirstAncestorByKind(d.Parameter)?.compilerNode===t.compilerNode},Kd=e=>{const t=I(e),s=t.getParent();return(r.isPropertyAccessExpression(s)||r.isElementAccessExpression(s))&&s.getExpression()===t&&!Xe(s)},zd=e=>{const t=I(e).getParent();return r.isVariableDeclaration(t)&&r.isObjectBindingPattern(t.getNameNode())},$d=e=>{const s=I(e).getParent();if(r.isSpreadAssignment(s)||r.isSpreadElement(s)){const n=s.getParent();return(r.isObjectLiteralExpression(n)||r.isArrayLiteralExpression(n))&&!Xe(n)}return r.isTemplateSpan(s)&&!r.isTaggedTemplateExpression(s.getParent().getParent())},Ue=e=>{const t=L(e);return t===void 0||Pr(t.getSourceFile())},Lt=(e,t)=>{const s=I(e),n=s.getParent();if(!r.isCallExpression(n))return!1;const i=n.getArguments().indexOf(s),o=h(n.getExpression());if(i===-1||o===void 0)return!1;if(r.isIdentifier(o))return o.getText()==="structuredClone"&&Ue(o);if(ai(Qe(o),t))return!(r.isPropertyAccessExpression(o)&&Mn.has(o.getName()))||r.isExpressionStatement(I(r.isAwaitExpression(n.getParent())?n.getParentOrThrow():n).getParent());if(!r.isPropertyAccessExpression(o))return!1;const a=o.getExpression();if(!r.isIdentifier(a)||!Ue(a))return!1;const c=a.getText(),l=o.getName();switch(c){case"console":return!0;case"JSON":return l==="stringify";case"Object":return["entries","freeze","isFrozen","keys","values"].includes(l)||l==="assign"&&i>0;default:return!1}},Me={kind:"opaque"},Bd={kind:"unreached"},Vd=e=>{const t=e.getSymbol()?.getDeclarations()??[],s=t.filter(o=>r.isFunctionDeclaration(o)&&o.hasBody()),[n]=s;return t.every(o=>r.isFunctionDeclaration(o)&&o.getSourceFile()===e.getSourceFile())&&s.length===1&&r.isFunctionDeclaration(n)?n:void 0},Dt=e=>{const t=h(e);if(r.isArrowFunction(t)||r.isFunctionExpression(t))return t;const s=r.isIdentifier(t)?L(t):void 0;if(s?.getSourceFile()!==e.getSourceFile())return;if(r.isFunctionDeclaration(s)){const i=Vd(s);return i===void 0||qt(i)?void 0:i}const n=ie(s)?h(s.getInitializer()):void 0;return r.isArrowFunction(n)||r.isFunctionExpression(n)?n:void 0},ci=(e,t,s)=>{const n=t.getArguments(),i=n.indexOf(s),o=i===-1||n.slice(0,i+1).some(l=>r.isSpreadElement(l))||e.getDescendantsOfKind(d.Identifier).some(l=>l.getText()==="arguments"),a=e.getParameters(),c=a[i];return o?Me:c===void 0?a.some(l=>l.isRestParameter())?Me:Bd:c.isRestParameter()?Me:{kind:"parameter",parameter:c}},Ud=e=>{const t=I(e),s=t.getParent();if(!r.isCallExpression(s)||s.getExpression()===t)return;const n=Dt(s.getExpression());return n===void 0?Me:ci(n,s,t)},Wd=new Set(["__defineGetter__","__defineSetter__","__proto__"]),qd=e=>r.isForInStatement(e)?e.getExpression():r.isConditionalExpression(e)?e.getCondition():r.isElementAccessExpression(e)?e.getArgumentExpression():void 0,li=e=>{const t=I(e),s=t.getParent();if(r.isIfStatement(s)||r.isWhileStatement(s)||r.isDoStatement(s)||r.isSwitchStatement(s)||r.isCaseClause(s)||r.isTypeOfExpression(s)||r.isVoidExpression(s)||r.isComputedPropertyName(s))return!0;if(r.isTemplateSpan(s))return!r.isTaggedTemplateExpression(s.getParent().getParent());const n=qd(s);if(n!==void 0)return y(n,t);if(r.isPrefixUnaryExpression(s))return s.getOperatorToken()!==d.PlusPlusToken&&s.getOperatorToken()!==d.MinusMinusToken;if(!r.isBinaryExpression(s))return!1;const i=s.getOperatorToken().getKind(),o=i>=d.FirstAssignment&&i<=d.LastAssignment,a=i===d.QuestionQuestionToken||i===d.BarBarToken||i===d.AmpersandAmpersandToken;return!o&&!a},jd=4,di=(e,t,s=0)=>{if(Nr(e))return!0;if(Kd(e)){const i=I(e).getParent(),o=r.isElementAccessExpression(i)?i.getArgumentExpression():void 0,a=r.isStringLiteral(o)?o.getLiteralValue():void 0,c=r.isPropertyAccessExpression(i)?i.getName():a;return c===void 0||!Wd.has(c)}if(zd(e)||$d(e)||li(e)||Lt(e,t))return!0;const n=Ud(e);return n?.kind==="unreached"||n?.kind==="parameter"&&Hd(n.parameter,s+1)},Ys=new WeakMap,Hd=(e,t=0)=>{const s=e.getNameNode();if(!r.isIdentifier(s))return!0;const n=Ys.get(e.compilerNode);if(n!==void 0)return n;if(t>jd)return!1;const o=(s.getSymbol()?.getDeclarations().length??0)===1&&e.getParentOrThrow().getDescendantsOfKind(d.Identifier).every(a=>a===s||a.getText()!==s.getText()||L(a)?.compilerNode!==e.compilerNode||di(a,void 0,t));return(o||t===0)&&Ys.set(e.compilerNode,o),o},Qs=new WeakMap,Gd=(e,t)=>{const s=r.isFunctionExpression(e)?e.getNameNode():void 0;if(!r.isArrowFunction(e)&&e.getFirstDescendantByKind(d.ThisKeyword)!==void 0)return!0;const n=new Set([t.getName(),...s===void 0?[]:[s.getText()]]);return e.getDescendantsOfKind(d.Identifier).some(i=>{if(i===s||!n.has(i.getText()))return!1;const o=L(i)?.compilerNode;return o!==void 0&&(o===t.compilerNode||s!==void 0&&o===e.compilerNode)})},Yd=(e,t,s)=>{const{context:n,impl:i}=e,o=Qs.get(i.compilerNode);if(o!==void 0)return o;const a=t.getNameNode(),c=r.isIdentifier(a)?[a]:a.getDescendantsOfKind(d.BindingElement).flatMap(g=>{const m=g.getNameNode();return r.isIdentifier(m)?[m]:[]}),l=new Map(c.map(g=>[g.getText(),g.getParentOrThrow().compilerNode])),u=g=>r.isIdentifier(a)?di(g,n):!Xe(g),f=!Gd(i,s)&&c.every(g=>(g.getSymbol()?.getDeclarations().length??0)===1)&&i.getDescendantsOfKind(d.Identifier).every(g=>{const m=g.getText();if(m==="arguments")return!1;const v=l.get(m);return v===void 0||c.includes(g)||L(g)?.compilerNode!==v?!0:u(g)});return Qs.set(i.compilerNode,f),f},Xs=new WeakMap,Qd=e=>{let t=Xs.get(e.compilerNode);return t===void 0&&(t=new Map(e.getVariableDeclarations().flatMap(s=>{const n=Wr(s);return n===void 0?[]:[[n.compilerNode,s]]})),Xs.set(e.compilerNode,t)),t},Xd=e=>{const t=Qd(e.getSourceFile()),s=e.getAncestors().find(l=>t.has(l.compilerNode)),n=s===void 0?void 0:t.get(s.compilerNode);if(s===void 0||n===void 0)return;const[i,o]=s.getParameters(),a=o===void 0||o.isRestParameter()?void 0:o,c={context:i,impl:s,mutatorName:j(n)??n.getName()};return a!==void 0&&Yd(c,a,n)?{...c,parameter:a,pristine:!0}:{...c,parameter:a,pristine:!1}},xt="args",Ee=e=>{const t=Wt(e);if(t!==void 0){const c=h(t.object);return r.isIdentifier(c)&&c.getText()===xt?t.member:void 0}if(!r.isIdentifier(e))return;const s=L(e);if(!r.isBindingElement(s)||s.getDotDotDotToken()!==void 0)return;const n=s.getParent();if(!r.isObjectBindingPattern(n))return;const i=n.getParent(),o=ie(i)?h(i.getInitializer()):void 0;return r.isBindingElement(i)&&ce(i)===xt||r.isIdentifier(o)&&o.getText()===xt?ce(s):void 0},Jd=new Set(["auth","identity","user"]),Mt=e=>{const t=i=>{const o=Gt(i);return o!==void 0&&o.length>0&&Jd.has(o[0]??"")},s=h(e)??e;if(t(s))return!0;const n=Y(s);return n!==void 0&&t(n)},ui=(e,t=2)=>{const s=new Set;for(const n of[e,...e.getDescendants()]){const i=Ee(n);i!==void 0&&s.add(i);const o=t>0&&r.isIdentifier(n)?Y(n):void 0;if(o!==void 0)for(const a of ui(o,t-1))s.add(a)}return s},_e=e=>{const t=h(e)??e;if(!r.isBinaryExpression(t))return[];const s=t.getOperatorToken().getKind(),n=t.getLeft(),i=t.getRight();if(s===d.BarBarToken)return[..._e(n),..._e(i)];if(s===d.AmpersandAmpersandToken){const l=(u,f)=>{const g=Ee(h(u)??u);return g===void 0?[]:_e(f).filter(m=>m===g)};return[...l(n,i),...l(i,n)]}if(s!==d.ExclamationEqualsEqualsToken&&s!==d.ExclamationEqualsToken)return[];const o=[],a=Ee(h(n)??n),c=Ee(h(i)??i);return a!==void 0&&Mt(i)&&o.push(a),c!==void 0&&Mt(n)&&o.push(c),o},Zd=e=>{const t=h(e)??e;if(!r.isIdentifier(t))return!1;const s=t.getSymbol(),n=s?.getAliasedSymbol()?.getValueDeclaration()??s?.getValueDeclaration();if(!r.isVariableDeclaration(n))return!1;const i=h(n.getInitializer());return r.isCallExpression(i)&&Lr(i.getExpression(),"defineIdentityGuard")},eu=e=>{if(!Zd(e.getExpression()))return[];const t=e.getArguments();return t.flatMap((s,n)=>{const i=Ee(h(s)??s),o=t.some((a,c)=>c!==n&&Mt(a));return i!==void 0&&o?[i]:[]})},tu=e=>{if(r.isThrowStatement(e))return!0;if(!r.isBlock(e))return!1;const t=e.getStatements().at(-1);return t!==void 0&&r.isThrowStatement(t)},su=e=>r.isArrowFunction(e)||r.isFunctionExpression(e)||r.isFunctionDeclaration(e)||r.isMethodDeclaration(e),Js=(e,t)=>{for(let s=e.getParent();s!==void 0;s=s.getParent()){if(s===t||s.compilerNode===t.compilerNode)return!0;if(!(r.isBlock(s)||r.isExpressionStatement(s)||r.isAwaitExpression(s)||r.isParenthesizedExpression(s)||r.isVariableStatement(s)||r.isVariableDeclarationList(s)||r.isVariableDeclaration(s)))return!1}return!1},nu=e=>r.isAwaitExpression(e.getParent())||e.getType().isVoid(),iu=(e,t)=>{const s=new Set;for(const n of e.getDescendantsOfKind(d.IfStatement))if(n.getEnd()<=t&&Js(n,e)&&tu(n.getThenStatement()))for(const i of _e(n.getExpression()))s.add(i);for(const n of e.getDescendantsOfKind(d.CallExpression))if(n.getEnd()<=t&&nu(n)&&Js(n,e))for(const i of eu(n))s.add(i);return s},ru=(e,t)=>{const s=ui(t);if(s.size===0)return!1;const n=e.getFirstAncestor(su);if(n===void 0)return!1;const i=iu(n,e.getStart());return[...s].every(o=>i.has(o))},ou=new Set(["at","concat","filter","find","findLast","flat","reverse","slice","sort","toReversed","toSorted"]),au=new Map([["Array",new Set(["from","of"])],["Object",new Set(["entries","values"])]]),_t=new Set(["catch","every","filter","finally","find","findIndex","findLast","findLastIndex","flatMap","forEach","map","reduce","reduceRight","some","sort","then"]),fi=e=>e.getNameNode().getDescendantsOfKind(d.BindingElement).filter(t=>r.isIdentifier(t.getNameNode())),cu=e=>{const t=I(e),s=t.getParent();if(r.isVariableDeclaration(s))return y(s.getInitializer(),t)?s:void 0;const n=r.isForOfStatement(s)&&s.getExpression()===t?s.getInitializer():void 0;return r.isVariableDeclarationList(n)?n.getDeclarations()[0]:void 0},lu=e=>{const t=cu(e);return t===void 0?void 0:r.isIdentifier(t.getNameNode())?r.isForOfStatement(t.getParent().getParent())||ie(t)?[t]:void 0:fi(t)},xe=e=>e.isUnion()?e.getUnionTypes().every(t=>xe(t)):e.isIntersection()?e.getIntersectionTypes().some(t=>xe(t)):!e.isAny()&&!e.isUnknown()&&!e.isObject()&&!e.isTypeParameter(),We=(e,t,s)=>{const n=r.isCallExpression(e)?h(e.getExpression()):void 0;return r.isPropertyAccessExpression(n)&&t.has(n.getName())&&(s===void 0||n.getExpression()===s)},Ke=e=>{const t=h(e);if(!r.isArrowFunction(t)&&!r.isFunctionExpression(t))return;const s=t.getBody();return r.isBlock(s)?s.getDescendantsOfKind(d.ReturnStatement).filter(n=>n.getFirstAncestor(i=>r.isFunctionLikeDeclaration(i))===t).map(n=>n.getExpression()):[s]},du=e=>{const t=r.isCallExpression(e)?h(e.getExpression()):void 0,s=r.isPropertyAccessExpression(t)?t.getExpression():void 0;return r.isPropertyAccessExpression(t)&&r.isIdentifier(s)&&au.get(s.getText())?.has(t.getName())===!0&&Ue(s)},uu=e=>{const t=wt(e);if(!r.isArrowFunction(t)&&!r.isFunctionExpression(t))return;const s=I(t),n=s.getParent();return r.isCallExpression(n)&&n.getArguments().includes(s)&&We(n,_n)?n:void 0},fu=(e,t)=>{if(!(r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e))||e.getExpression()!==t)return;const s=I(e),n=s.getParent();return!r.isCallExpression(n)||n.getExpression()!==s?e:We(n,ou,t)?n:void 0},gu=(e,t)=>{if(r.isAwaitExpression(e))return e;if(r.isConditionalExpression(e))return e.getCondition()===t?void 0:e;const s=r.isBinaryExpression(e)?e.getOperatorToken().getKind():void 0;return s===d.QuestionQuestionToken||s===d.BarBarToken||s===d.AmpersandAmpersandToken?e:void 0},pu=(e,t)=>{if(r.isArrayLiteralExpression(e))return e;const n=r.isSpreadElement(e)||r.isSpreadAssignment(e)||r.isShorthandPropertyAssignment(e)||r.isPropertyAssignment(e)&&y(e.getInitializer(),t)?e.getParent():void 0;return r.isArrayLiteralExpression(n)||r.isObjectLiteralExpression(n)?n:void 0},Zs=e=>{const t=I(e),s=t.getParent();if(s===void 0)return;const n=r.isCallExpression(s)&&s.getArguments().includes(t)&&du(s);return fu(s,t)??gu(s,t)??pu(s,t)??(n?s:uu(t))},mu=5e4,gi=()=>({inProgress:new Set,verdicts:new Map});class hu{cuts=0;work=0;reset(){this.work=0}cut(){return this.cuts+=1,!0}spend(){return this.work+=1,this.work>mu&&this.cut()}memoized(t,s,n){const i=n.verdicts.get(t);if(i!==void 0)return i;if(n.inProgress.has(t))return this.cuts+=1,!1;if(this.spend())return!0;const o=this.cuts;n.inProgress.add(t);let a;try{a=s()}finally{n.inProgress.delete(t)}return this.cuts===o&&n.verdicts.set(t,a),a}}const vu=8,Eu=8;class xu{budget;scope;taint;verdicts=gi();constructor(t,s,n){this.scope=t,this.budget=s,this.taint=n}isCompromised(t){return this.flowHasCompromisingUse(t)&&!xe(t.getType())}flowHasCompromisingUse(t){return this.budget.memoized(t.compilerNode,()=>{const s=this.budget.cuts,n=[],i=new Set,o=(c,l)=>{i.has(c.compilerNode)||(i.add(c.compilerNode),n.push({binding:c,hops:l}))};let a=!1;o(t,0);for(const c of n)if(a=(c.binding===t?void 0:this.verdicts.verdicts.get(c.binding.compilerNode))??this.visitBinding(c,t,o),a)break;if(!a&&this.budget.cuts===s)for(const c of i)this.verdicts.verdicts.set(c,!1);return a},this.verdicts)}visitBinding({binding:t,hops:s},n,i){const o=t.getNameNode();if(!r.isIdentifier(o)){for(const l of r.isParameterDeclaration(t)?fi(t):[])i(l,s);return!1}if(this.budget.spend())return!0;const a=(l,u)=>u&&s>=vu?this.budget.cut():(i(l,u?s+1:s),!1);return this.taint.referencesTo(t,o.getText()).some(l=>this.valueCompromises(I(l),!0,a,0))&&(t===n||!xe(t.getType()))}valueCompromises(t,s,n,i){let o=t;for(let m=Zs(o);m!==void 0;m=Zs(o)){if(r.isCallExpression(m)&&this.callbackCompromises(m,n))return!0;o=I(m)}const a=o.getParent(),c=o===t&&s,l=()=>!c&&xe(o.getType());if(Xe(o))return!c&&(!r.isBinaryExpression(a)||this.taint.isTaintedValue(a.getRight(),!1));const u=lu(o);if(u!==void 0)return u.some(m=>n(m,!0));const f=r.isPropertyAccessExpression(a)&&a.getExpression()===o?a.getParent():void 0;if(r.isCallExpression(f)&&f.getExpression()===a)return this.methodCallCompromises(f,n);const g=this.nestedReturningFunctionOf(o);return g!==void 0?this.resultCompromises(g,n,i)&&!l():this.positionCompromises(o,n)&&!l()}resultCompromises(t,s,n){const i=I(t).getParent();if(n>=Eu)return this.budget.cut();if(r.isCallExpression(i))return i.getExpression()===I(t)?this.valueCompromises(i,!1,s,n+1):!We(i,_t);const o=r.isFunctionDeclaration(t)?t:i,a=r.isFunctionDeclaration(o)||ie(o)?o.getNameNode():void 0;return o===void 0||!r.isIdentifier(a)?!0:this.taint.referencesTo(o,a.getText()).some(c=>{const l=I(c),u=l.getParent();return!r.isCallExpression(u)||u.getExpression()!==l||this.valueCompromises(u,!1,s,n+1)})}methodCallCompromises(t,s){return t.getArguments().filter(i=>Ke(i)===void 0).some(i=>this.taint.isTaintedValue(i,!1))||this.callbackCompromises(t,s)}callbackCompromises(t,s){const n=We(t,_t)?t.getArguments()[0]:void 0;if(n===void 0)return!1;const i=Dt(n);return i!==void 0&&this.taint.isInImpl(i)?i.getParameters().some(o=>s(o,!1)):this.taint.isTaintedValue(n,!1)}positionCompromises(t,s){const n=t.getParent();if(r.isCallExpression(n)&&n.getArguments().includes(t))return this.argumentCompromises(n,t,s);const i=r.isSpreadElement(n)?n.getParent():void 0;if(n!==void 0&&r.isCallExpression(i))return!Lt(n,this.scope.context)&&this.isOpaqueCallTainted(i.getExpression(),i.getArguments(),n);if(r.isNewExpression(n))return this.isOpaqueCallTainted(n.getExpression(),n.getArguments(),t);if(r.isTemplateSpan(n)){const o=n.getParent(),a=o.getParent(),c=o.getTemplateSpans().map(l=>l.getExpression());return r.isTaggedTemplateExpression(a)&&this.isOpaqueCallTainted(a.getTag(),c,t)}return!this.isReadPosition(t)}argumentCompromises(t,s,n){if(Lt(s,this.scope.context))return!1;const i=Dt(t.getExpression()),o=i===void 0?void 0:ci(i,t,s);return o?.kind==="unreached"?!1:o?.kind==="parameter"&&i!==void 0&&this.taint.isInImpl(i)?n(o.parameter,!1):this.isOpaqueCallTainted(t.getExpression(),t.getArguments(),s)}isReadPosition(t){const s=t.getParent();return s===void 0||r.isExpressionStatement(s)||r.isForStatement(s)||r.isElementAccessExpression(s)||li(t)||y(wt(t),this.scope.impl)}isOpaqueCallTainted(t,s,n){const i=!r.isIdentifier(h(n));return this.taint.isTaintedValue(t,!1)||s.some(o=>(o!==n||i)&&this.taint.isTaintedValue(o,!1))}nestedReturningFunctionOf(t){const s=wt(t);return y(s,this.scope.impl)?void 0:s}}const Su=new Set(["at","every","filter","finally","find","findIndex","findLast","findLastIndex","forEach","order","slice","some","sort","withIndex","withSearchIndex"]),Au=e=>{const t=h(e);if(!r.isIdentifier(t))return r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t);const s=L(t),n=r.isVariableDeclaration(s)?h(s.getInitializer()):void 0;return s===void 0||r.isFunctionDeclaration(s)||r.isParameterDeclaration(s)||r.isArrowFunction(n)||r.isFunctionExpression(n)},yu=new Set(["all","allSettled","any","race"]),en=e=>r.isParameterDeclaration(e)?e:r.isBindingElement(e)?e.getFirstAncestorByKind(d.Parameter):void 0,St=8;class bu{budget=new hu;referencesByDeclaration=new Map;referencesByName=new Map;scope;verdicts=gi();walk;variableDepth=0;queryDepth=0;constructor(t){this.scope=t,this.walk=new xu(t,this.budget,this);for(const s of t.impl.getDescendantsOfKind(d.Identifier)){const n=s.getText();this.referencesByName.set(n,[...this.referencesByName.get(n)??[],s])}}isTaintedValue(t,s){this.queryDepth===0&&this.budget.reset(),this.queryDepth+=1;try{return s&&this.isRootedInContext(t,St)?!1:(r.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(i=>wr(i)&&this.isIdentifierTainted(i))}finally{this.queryDepth-=1}}isInImpl(t){const{impl:s}=this.scope;return t!==s&&s.getPos()<=t.getPos()&&t.getEnd()<=s.getEnd()}referencesTo(t,s){let n=this.referencesByDeclaration.get(s);if(n===void 0){n=new Map;for(const i of this.referencesByName.get(s)??[]){const o=L(i)?.compilerNode;o!==void 0&&n.set(o,[...n.get(o)??[],i])}this.referencesByDeclaration.set(s,n)}return(n.get(t.compilerNode)??[]).filter(i=>i.getParent()!==t)}flowsIntoTainted(t){if([t.getInitializer(),...t.getDescendantsOfKind(d.BindingElement).map(g=>g.getInitializer())].some(g=>g!==void 0&&this.isTaintedValue(g,!1)))return!0;const n=t.getParentOrThrow(),i=r.isFunctionLikeDeclaration(n)?n.getParameters().findIndex(g=>g.compilerNode===t.compilerNode):-1,o=I(n),a=o.getParent();if(i===-1)return!0;if(r.isCallExpression(a)){if(a.getExpression()===o)return this.isCallSiteTainted(a,i,t.isRestParameter());const g=h(a.getExpression());if(!r.isPropertyAccessExpression(g)||!_t.has(g.getName()))return!0;const m=a.getArguments().filter(v=>v!==o);return this.isTaintedValue(g.getExpression(),!0)||m.some(v=>this.isTaintedValue(v,!1))}const c=r.isVariableDeclaration(a)&&ie(a)?a:void 0,l=r.isFunctionDeclaration(n)?n:c,u=l?.getNameNode();if(l===void 0||!r.isIdentifier(u))return!0;const f=this.referencesTo(l,u.getText());return f.length===0||f.some(g=>{const m=I(g),v=m.getParent();return!r.isCallExpression(v)||v.getExpression()!==m||this.isCallSiteTainted(v,i,t.isRestParameter())})}isCallSiteTainted(t,s,n){const i=t.getArguments(),o=i.findIndex(c=>r.isSpreadElement(c)),a=c=>c===s||n&&c>s||o!==-1&&o<=s&&c>=o;return i.some((c,l)=>a(l)&&this.isTaintedValue(c,!1))}isContextRootedCombinator(t,s){const n=h(t.getExpression()),i=r.isPropertyAccessExpression(n)?n.getExpression():void 0,a=r.isPropertyAccessExpression(n)&&r.isIdentifier(i)&&i.getText()==="Promise"&&Ue(i)&&yu.has(n.getName())?h(t.getArguments()[0]):void 0;if(r.isArrayLiteralExpression(a)){const f=a.getElements();return f.length>0&&f.every(g=>!r.isSpreadElement(g)&&this.isRootedInContext(g,s))}const c=r.isCallExpression(a)?h(a.getExpression()):void 0,l=r.isCallExpression(a)&&r.isPropertyAccessExpression(c)&&c.getName()==="map"?h(a.getArguments()[0]):void 0,u=l===void 0?void 0:Ke(l);return u!==void 0&&u.length>0&&u.every(f=>f!==void 0&&this.isRootedInContext(f,s))}isIdentifierTainted(t){const s=t.getText();if(s==="arguments")return!0;const n=L(t),i=en(n);if(i!==void 0)return this.isSource(i);if(s==="args")return!0;if(n===void 0||!this.isInImpl(n))return!1;if(r.isFunctionDeclaration(n))return this.budget.memoized(n.compilerNode,()=>this.isTaintedValue(n,!1),this.verdicts);if(r.isBindingElement(n)&&this.walk.isCompromised(n))return!0;const o=r.isBindingElement(n)?n.getFirstAncestorByKind(d.VariableDeclaration):n;return r.isVariableDeclaration(o)&&this.isVariableTainted(o)}callChainVerdict(t,s){if(this.isContextRootedCombinator(t,s))return!0;const n=h(t.getExpression()),i=r.isPropertyAccessExpression(n)?n.getName():void 0;return i!==void 0&&Mn.has(i)?!1:i!==void 0&&_n.has(i)?this.isCallbackResultServerScoped(t,s)?void 0:!1:t.getArguments().some(a=>Ke(a)!==void 0)&&(i===void 0||!Su.has(i))?!1:void 0}isCallbackResultServerScoped(t,s){const n=(i,o=[])=>{const a=Qe(i),c=r.isIdentifier(a)?en(L(a)):void 0;return c!==void 0&&o.includes(c)?!0:this.isRootedInContext(i,s)||!this.isTaintedValue(i,!1)};return t.getArguments().every(i=>{const o=Ke(i);if(o===void 0)return!Au(i)&&n(i);const a=h(i),c=r.isArrowFunction(a)||r.isFunctionExpression(a)?a.getParameters():[];return o.every(l=>l===void 0||n(l,c))})}isRootedInContext(t,s){const n=Ar(t,u=>this.callChainVerdict(u,s)),i=n.root;if(n.verdict!==void 0)return n.verdict;if(ai(i,this.scope.context))return!0;const o=r.isIdentifier(i)?L(i):void 0,a=r.isBindingElement(o)?o.getFirstAncestorByKind(d.VariableDeclaration):o,c=ie(a)&&this.isInImpl(a)?a.getInitializer():void 0,l=r.isBindingElement(o)?o:a;return s>0&&c!==void 0&&(r.isBindingElement(l)||r.isVariableDeclaration(l))&&!this.walk.isCompromised(l)&&this.isRootedInContext(c,s-1)}isSource(t){const{impl:s,parameter:n}=this.scope;return t.compilerNode===n?.compilerNode?!0:t.getParent()!==s&&this.isInImpl(t)&&(this.budget.memoized(t.compilerNode,()=>this.flowsIntoTainted(t),this.verdicts)||this.walk.isCompromised(t))}isVariableTainted(t){return this.budget.memoized(t.compilerNode,()=>{const s=t.getParent().getParent();if(r.isCatchClause(t.getParent())||this.walk.isCompromised(t))return!0;if(r.isForOfStatement(s)||r.isForInStatement(s))return this.isTaintedValue(s.getExpression(),!0);const n=t.getInitializer(),i=qt(t);if(n===void 0||i)return!0;if(this.isRootedInContext(n,St))return!1;if(this.variableDepth>=St)return this.budget.cut();this.variableDepth+=1;try{return this.isTaintedValue(n,!1)}finally{this.variableDepth-=1}},this.verdicts)}}const tn=new WeakMap,Nu=e=>{const t=tn.get(e.impl.compilerNode);if(t!==void 0)return t;const s=new bu(e);return tn.set(e.impl.compilerNode,s),s},Pu=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),wu=new Set(["insert","insertManyUnsafe","patch","replace"]),Iu=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();return wu.has(t)&&Or(e.getExpression())?t:void 0},Cu=(e,t)=>{if(t!=="insertManyUnsafe")return r.isObjectLiteralExpression(e)?[e]:[];if(!r.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())r.isObjectLiteralExpression(n)&&s.push(n);return s},Tu=(e,t)=>{const s=Wt(e);return s?.member===t?h(s.object):void 0},sn=(e,t)=>r.isIdentifier(e)&&L(e)?.compilerNode===t.compilerNode,pi=(e,t,s,n=1)=>{const i=Tu(e,s);if(i!==void 0)return sn(i,t);const o=r.isIdentifier(e)?L(e):void 0;if(r.isBindingElement(o)){const c=o.getParent(),l=c.getParent();return o.getDotDotDotToken()===void 0&&ce(o)===s&&r.isObjectBindingPattern(c)&&(l.compilerNode===t.compilerNode||ie(l)&&sn(h(l.getInitializer()),t))}const a=ie(o)?o.getInitializer():void 0;return n>0&&a!==void 0&&pi(a,t,s,n-1)},Kt=e=>{const t=h(e)??e;return r.isConditionalExpression(t)?[...Kt(t.getWhenTrue()),...Kt(t.getWhenFalse())]:[t]},Ou=(e,t,s)=>{const n=[],i=s===void 0?void 0:Nu(s);for(const o of e.getProperties()){let a,c;if(r.isPropertyAssignment(o)?(a=S(o),c=o.getInitializer()):r.isShorthandPropertyAssignment(o)&&(a=S(o),c=o.getNameNode()),a===void 0||c===void 0||!Pu.has(a))continue;const l=Kt(c).filter(f=>i===void 0?q(f)&&!kr(f):i.isTaintedValue(f,!0));if(l.length>0){const f=t.ownerField===a&&s?.pristine===!0&&pi(c,s.parameter,a),g=l.every(m=>ru(t.call,m));n.push({field:a,file:t.relativePath,line:t.call.getStartLineNumber(),method:t.method,scope:t.scope,...f&&{ownerScoped:!0},...g&&{guarded:!0}})}}return n},ku=(e,t,s)=>{const n=Iu(e.getExpression()),i=n===void 0?void 0:e.getArguments()[1];if(n===void 0||i===void 0)return[];const o=Cu(i,n);if(o.length===0)return[];const a=x(e),c=Xd(e),l={call:e,method:n,ownerField:c===void 0?void 0:s(c.mutatorName),relativePath:t,scope:a};return o.flatMap(u=>Ou(u,l,c))},Ru=(e,t,s=[],n=[])=>{const i=new Map(n.map(c=>[`${c.filePath}:${c.exportName}`,c.owner])),o=C(e,t,(c,l)=>ku(c,l,u=>i.get(`${l}:${u}`))),a=new Map(s.map(c=>[`${c.filePath}:${c.exportName}`,c.adminOnly===!0]));return Ht(o,s).map(c=>Ir(c.scope)?.every(f=>a.get(`${c.file}:${f}`)===!0)===!0?{...c,adminOnly:!0}:c)},Fu=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Lu=e=>e&&r.isNumericLiteral(e)?Number(e.getText()):void 0,Du=e=>{const t=V(e,"webhookToleranceSeconds");return t&&r.isPropertyAssignment(t)?Lu(t.getInitializer()):void 0},Mu=(e,t)=>{const s=P(e.getExpression());if(s===void 0||!Fu.has(s))return;const[n]=e.getArguments(),i=n&&r.isObjectLiteralExpression(n)?Du(n):void 0;return{callee:s,scope:x(e),file:t,line:e.getStartLineNumber(),...i===void 0?{}:{toleranceSeconds:i}}},_u=(e,t)=>C(e,t,Mu),Ku=new Map([["defineQueue",0],["defineSubscription",1],["defineWorkflow",0]]),zu=e=>{const t=e.getExpression();return r.isIdentifier(t)?t.getText():void 0},$u=(e,t)=>{const s=e.getArguments()[t];if(!s||!r.isObjectLiteralExpression(s))return;const n=V(s,"handler");if(n===void 0||!r.isPropertyAssignment(n))return;const i=n.getInitializer();if(i&&(r.isArrowFunction(i)||r.isFunctionExpression(i)))return i},mi=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&r.isIdentifier(s)?s.getText():void 0},hi=(e,t)=>e===t||e.startsWith(`${t}.`),vi=e=>{const t=e.getDescendantsOfKind(d.PropertyAccessExpression);return r.isPropertyAccessExpression(e)&&t.push(e),t},nn=e=>{const t=e.getParent();return r.isPropertyAccessExpression(t)&&t.getNameNode()===e||r.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(r.isBindingElement(t)&&t.getNameNode()===e)},Ei=e=>{const t=e.getDescendantsOfKind(d.Identifier).filter(s=>nn(s));return r.isIdentifier(e)&&nn(e)&&t.push(e),t},Bu=e=>{if(!r.isVariableDeclaration(e))return[];const t=e.getNameNode();return r.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(d.BindingElement).map(s=>s.getName())},Vu=e=>{const t=mi(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(d.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const i=n.getInitializer(),o=r.isVariableDeclarationList(i)?i.getDeclarations()[0]?.getNameNode():void 0;o&&r.isIdentifier(o)&&s.push(`${o.getText()}.body`)}return s},Uu=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:Vu(e),i=new Set,o=a=>vi(a).some(c=>n.some(l=>hi(c.getText(),l)))?!0:Ei(a).some(c=>i.has(c.getText()));for(const a of e.getDescendantsOfKind(d.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of Bu(a))i.add(l)}return{names:i,prefixes:n}},Wu=(e,t)=>vi(e).some(s=>t.prefixes.some(n=>hi(s.getText(),n)))?!0:Ei(e).some(s=>t.names.has(s.getText())),qu=e=>{const t=yr(e);return t===void 0?void 0:{exportName:String(t.at(-1)),file:t.slice(0,-1).join("/")}},ju=(e,t,s)=>{const n=mi(e,0);if(n===void 0)return[];const i=Uu(e,t,n),o=new Set([n,...i.prefixes.filter(c=>c.endsWith(".body")).map(c=>c.slice(0,-5))]),a=[];for(const c of e.getDescendantsOfKind(d.CallExpression)){const l=c.getExpression();if(!r.isPropertyAccessExpression(l)||!Fn.has(l.getName())||!o.has(l.getExpression().getText()))continue;const u=c.getArguments()[1];if(!u||!Wu(u,i))continue;const f=qu(c.getArguments()[0]);f!==void 0&&a.push({dispatchKind:t,file:s,scope:x(c),line:c.getStartLineNumber(),targetExport:f.exportName,targetFile:f.file})}return a},Hu=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=zu(n),o=i===void 0?void 0:Ku.get(i);if(o===void 0)continue;const a=$u(n,o);a!==void 0&&s.push(...ju(a,i==="defineWorkflow"?"workflow":"queue",t))}return s},Gu=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Hu(i,w(t,n)))}return s},rn={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},on=new Set(["account","credential","member","passkey","session","user"]),Yu=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),Qu=e=>{const s=Yu(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return on.has(s)||on.has(n)},Xu=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Ju=(e,t)=>{const{objects:s,opaque:n}=Jt(e,t);return cc(s).some(i=>Xu(i))?!0:n?void 0:!1},Zu=e=>{const t=e.getArguments()[0];return!t||!r.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!V(t,"captcha"),usesRateLimit:!!V(t,"rateLimit")}},ef=e=>{if(r.isCallExpression(e))return e;if(!r.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&r.isCallExpression(s)?s:void 0},ze={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},tf=e=>{const t=ef(e),s=t?P(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=Zu(t);return{...ze,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in rn?{...ze,[rn[s]]:!0}:ze},sf=e=>{const t={...ze};let s=e;for(;r.isCallExpression(s);){const n=s.getExpression();if(!r.isPropertyAccessExpression(n))break;const i=n.getName()==="use"?s.getArguments()[0]:void 0;if(i){const o=tf(i);t.usesCaptcha||=o.usesCaptcha,t.usesEmailGate||=o.usesEmailGate,t.usesMask||=o.usesMask,t.usesRateLimit||=o.usesRateLimit,t.usesRls||=o.usesRls}s=n.getExpression()}return t},nf=new Set(["insert","insertMany","insertManyUnsafe","replace"]),rf=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!nf.has(t.getName()))return!1;const s=t.getExpression();if(!z(s))return!1;const i=e.getArguments()[0];return!i||!(r.isStringLiteral(i)||r.isNoSubstitutionTemplateLiteral(i))?!1:Qu(i.getLiteralText())},of=new Set(["create","publish","publishBatch","runAfter","runAt","send","sendBatch"]),an=new Set(["queues","scheduler","topics","workflows"]),af=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!of.has(t.getName()))return!1;let s=t.getExpression();for(;r.isCallExpression(s)||r.isElementAccessExpression(s)||r.isPropertyAccessExpression(s);){if(r.isPropertyAccessExpression(s)&&an.has(s.getName())&&Rr(s.getExpression()))return!0;s=s.getExpression()}const n=Gt(s);return n?.length===1&&an.has(n[0]??"")},cf=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return z(s)},xi=new Set(["generateObject","generateText","streamObject","streamText"]),lf=e=>{const t=P(e.getExpression());return t!==void 0&&xi.has(t)},df=e=>{const t=P(e.getExpression());if(t===void 0||!xi.has(t))return!1;const s=e.getArguments()[0];return!s||!r.isObjectLiteralExpression(s)||s.getProperties().some(n=>r.isSpreadAssignment(n))?!1:!V(s,"maxOutputTokens")},uf=new Set(["log","span","trace"]),ff=new Set(["ai"]),gf=new Set(["email","mail"]),pf=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","topics","workflows"]),At=(e,t)=>[...t].some(s=>Je(e,s).length>0),Si=new Set([d.ArrowFunction,d.FunctionDeclaration,d.FunctionExpression,d.GetAccessor,d.MethodDeclaration,d.SetAccessor]),mf=new Set(["every","filter","flatMap","forEach","map","some"]),hf=new Set(["all","allSettled","race"]),Ai=e=>{const t=e.getParent();if(!t||!r.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!r.isPropertyAccessExpression(s))return;const n=s.getName();if(mf.has(n))return t;const i=s.getExpression();if(r.isIdentifier(i)&&i.getText()==="Promise"&&hf.has(n))return t},vf=e=>{let t=e.getParent();for(;t;){if(r.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(Si.has(t.getKind())){const s=Ai(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},Ef=e=>{let t=e.getParent();for(;t!==void 0;){if(r.isCallExpression(t)&&t.getExpression().getText()==="Promise.allSettled")return!0;if(Si.has(t.getKind())){if(t=Ai(t),t===void 0)return!1;continue}t=t.getParent()}return!1},xf=e=>{const t=e.getFirstAncestor(u=>r.isArrowFunction(u)||r.isFunctionExpression(u)),s=t?.getParent();if(!t||!r.isCallExpression(s)||!s.getArguments().includes(t))return!1;const n=s.getExpression();if(!r.isIdentifier(n))return!1;const i=n.getSymbol(),o=i?.getAliasedSymbol()?.getValueDeclaration()??i?.getValueDeclaration(),a=r.isVariableDeclaration(o)?o.getInitializer():o;if(!r.isArrowFunction(a)&&!r.isFunctionExpression(a)&&!r.isFunctionDeclaration(a))return!1;const c=s.getArguments().indexOf(t),l=a.getParameters()[c]?.getName();return l===void 0?!1:a.getDescendantsOfKind(d.TryStatement).some(u=>{const f=u.getTryBlock().getDescendantsOfKind(d.CallExpression).some(m=>{const v=m.getExpression();return r.isIdentifier(v)&&v.getText()===l&&r.isAwaitExpression(m.getParent())}),g=u.getCatchClause();return f&&g!==void 0&&g.getDescendantsOfKind(d.ThrowStatement).length>0})},Sf=e=>{let t=e;for(;;){const s=t.getParent();if(!r.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(!r.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},Af=e=>{let t=e;for(;;){const s=t.getParent();if(r.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return r.isCallExpression(s)&&s.getExpression()===t?s:void 0}},yf=e=>{let t=!1,s=!0;for(const n of[...pf].flatMap(i=>Je(e,i))){const i=Af(n);i&&(t=!0,!vf(i)&&!Sf(i)&&!xf(i)&&!Ef(i)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},bf=e=>e.getDescendantsOfKind(d.ThrowStatement).some(t=>{const s=t.getExpression();if(!r.isNewExpression(s))return!1;const n=s.getExpression();return r.isIdentifier(n)&&n.getText()==="Error"}),cn="lunora-advisor-exempt",Nf=/^[\s*/]+/u,Pf=/[\w-]/u,wf=e=>{const s=(e.getFirstAncestorByKind(d.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
|
|
22
22
|
`);for(const n of s.split(`
|
|
23
23
|
`)){const i=n.replace(Nf,"");if(!i.startsWith(cn))continue;const o=i.slice(cn.length);if(Pf.test(o.charAt(0)))continue;const a=o.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":o.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},If=e=>{const[t]=e.getArguments();if(t){if(r.isObjectLiteralExpression(t)){const s=V(t,"handler");return s?r.isPropertyAssignment(s)?s.getInitializer():r.isShorthandPropertyAssignment(s)?s.getNameNode():r.isMethodDeclaration(s)?s:void 0:void 0}return t}},Cf=(e,t)=>{const s=If(t);if(!s)return;if(r.isArrowFunction(s)||r.isFunctionExpression(s)||r.isMethodDeclaration(s))return e;if(!r.isIdentifier(s))return;const n=s.getSourceFile(),i=s.getText(),o=n.getVariableDeclaration(i)?.getInitializer();return o&&(r.isArrowFunction(o)||r.isFunctionExpression(o))?o:n.getFunction(i)},Tf=e=>{let t=!1,s=!1,n=!1,i=!1,o=!1;for(const l of e.getDescendantsOfKind(d.CallExpression))if(rf(l)&&(o=!0),af(l)&&(t=!0),cf(l)&&(i=!0),lf(l)&&(s=!0),df(l)&&(n=!0),o&&t&&i&&n)break;const{handlesErrors:a,reachesOutbound:c}=yf(e);return{callsMail:At(e,gf),emitsEvent:At(e,uf),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||At(e,ff),throwsBareError:bf(e),unboundedAiGeneration:n,usesInsertManyUnsafe:i,writesUserTable:o}},Of=(e,t)=>{const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const n=ee(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const i=n.receiver?sf(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},o=Cf(e,s);return{...o?Tf(o):{},...wf(e),...i,analyzableBody:o!==void 0,exportName:j(e)??e.getName(),file:t,hasEmailArg:Ju(s,n.receiver),kind:n.kind,visibility:n.visibility}},kf=(e,t)=>{const s=[];for(const n of Q(e)){const i=Of(n,t);i&&s.push(i)}return s},Rf=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...kf(i,w(t,n)))}return s},Ff=new Set(["dbRateLimit","rateLimit"]),Lf=e=>r.isArrowFunction(e)?e.getBody():e,Df=e=>{if(!r.isArrowFunction(e))return;const t=e.getParameters()[0]?.getNameNode();return t!==void 0&&r.isIdentifier(t)?t:void 0},yi=e=>{const t=e.getParent();return r.isPropertyAccessExpression(t)&&t.getExpression()===e&&t.getName()==="args"},bi=(e,t)=>{const s=t.getSymbol();return s===void 0?[]:e.getDescendantsOfKind(d.Identifier).filter(n=>{if(n.getSymbol()!==s)return!1;const i=n.getParent();return!(r.isPropertyAccessExpression(i)&&i.getNameNode()===n)})},Mf=(e,t)=>q(e)||t!==void 0&&bi(e,t).some(s=>yi(s)),_f=(e,t)=>t===void 0?le(e):bi(e,t).some(s=>!yi(s)),Kf=(e,t)=>{const s=P(e.getExpression());if(s===void 0||!Ff.has(s))return;const n=R(Rn(e.getArguments()[2]),"key");if(!n)return;const i=Lf(n),o=Df(n);if(!(!Mf(i,o)||_f(i,o)))return{callee:s,scope:x(e),file:t,limitName:kn(e),line:e.getStartLineNumber()}},zf=(e,t)=>C(e,t,Kf),$f=new Set(["findFirst","findFirstOrThrow","findMany","findUnique","get"]),Bf=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!$f.has(t.getName()))return;const s=t.getExpression();if(z(s)){const n=e.getArguments()[0];return n&&r.isStringLiteral(n)?n.getLiteralText():""}if(r.isPropertyAccessExpression(s)&&z(s.getExpression()))return s.getName()},Vf=e=>{let t=e;for(;r.isCallExpression(t);){const s=t.getExpression();if(!r.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&z(s.getExpression())){const n=t.getArguments()[0];return n&&r.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},Uf=e=>{let t=h(e)??e;for(;r.isAwaitExpression(t);)t=h(t.getExpression())??t.getExpression();return t},Ni=(e,t=!1)=>{const s=Uf(e);if(r.isIdentifier(s)){if(t)return;const n=Y(s);return n===void 0?void 0:Ni(n,!0)}if(r.isCallExpression(s))return Bf(s)??Vf(s)},Wf=e=>{const t=e.getBody();if(!r.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(d.ReturnStatement)){const i=n.getFirstAncestor(a=>r.isArrowFunction(a)||r.isFunctionExpression(a)||r.isFunctionDeclaration(a)),o=n.getExpression();i===e&&o!==void 0&&s.push(o)}return s},qf=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!r.isCallExpression(s))return[];const n=ee(s);if(n?.kind!=="query")return[];const i=ti(s);if(i===void 0)return[];const o=n.receiver!==void 0&&Dr(n.receiver,"output"),a=n.receiver!==void 0&&Kn(n.receiver,"use","mask"),c=new Set,l=[];for(const u of Wf(i)){const f=Ni(u);f===void 0||c.has(f)||(c.add(f),l.push({exportName:j(e)??e.getName(),file:t,line:u.getStartLineNumber(),table:f,usesMask:a,usesOutput:o,visibility:n.visibility}))}return l},jf=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=w(t,n);for(const a of Q(i))s.push(...qf(a,o))}return s},Hf=e=>{if(!e||!r.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(r.isPropertyAssignment(s)||r.isShorthandPropertyAssignment(s)||r.isMethodDeclaration(s)||r.isGetAccessorDeclaration(s))&&t.push(S(s));return t},Gf=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&r.isCallExpression(s)?ee(s):void 0;if(!n)return[];const i=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=$n(o);if(a===void 0)continue;const c=Hf(R(a.options,"with"));c.length!==0&&i.push({exportName:j(e)??e.getName(),file:t,line:o.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return i},Yf=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=w(t,n);for(const a of Q(i))s.push(...Gf(a,o))}return s},W=(e,t)=>`${e}:${t}`,ln=(e,t,s,n)=>s===void 0?void 0:{endLine:e.getEndLineNumber(),exported:n,file:t,name:s,node:e,startLine:e.getStartLineNumber()},Qf=(e,t)=>[...ne(e,t,d.FunctionDeclaration,(s,n)=>s.getParent().getKind()===d.SourceFile?ln(s,n,s.getName(),s.isExported()):void 0),...ne(e,t,d.VariableDeclaration,(s,n)=>{const i=s.getVariableStatement();return i?.getParent().getKind()===d.SourceFile?ln(i,n,s.getName(),i.isExported()):void 0})],Xf=(e,t,s)=>{const n=e.getExpression();if(!r.isIdentifier(n))return;const i=n.getSymbol(),o=(i?.getAliasedSymbol()??i)?.getDeclarations()[0];if(o===void 0||!(r.isFunctionDeclaration(o)||r.isVariableDeclaration(o)))return;const a=o.getName(),c=w(s,o.getSourceFile().getFilePath());return a===void 0?void 0:t.get(W(c,a))},Jf=e=>`${e.table}|${e.method}|${e.fields?.join(",")??"*"}`,Zf=(e,t)=>{const s=new Map(e.map(n=>[W(n.file,n.name),new Map]));for(const n of t){const i=e.find(o=>o.file===n.file&&o.startLine<=n.line&&n.line<=o.endLine);i!==void 0&&n.table!==""&&s.get(W(i.file,i.name))?.set(Jf(n),{fields:n.fields,method:n.method,table:n.table})}return s},eg=(e,t,s)=>e.node.getDescendantsOfKind(d.CallExpression).map(n=>Xf(n,t,s)).filter(n=>n!==void 0),tg=(e,t,s,n)=>{for(const i of e){const o=i.scope.kind==="module"?void 0:t.get(W(i.file,i.scope.name)),a=i.target===void 0?void 0:s.get(i.target);i.kind==="call"&&o!==void 0&&a!==void 0&&n.get(W(o.file,o.name))?.push(a)}},sg=(e,t,s)=>{const n=new Map(e.map(a=>[W(a.file,a.name),a])),i=new Map(e.map(a=>[`${Qt(a.file)}:${a.name}`,a])),o=new Map(e.map(a=>[W(a.file,a.name),eg(a,n,t)]));return tg(s,n,i,o),o},ng=(e,t)=>{let s=!1;for(const[n,i]of t??[])e!==void 0&&!e.has(n)&&(e.set(n,i),s=!0);return s},ig=(e,t,s)=>{let n=!0;for(;n;){n=!1;for(const i of e)for(const o of s.get(W(i.file,i.name))??[])ng(t.get(W(i.file,i.name)),t.get(W(o.file,o.name)))&&(n=!0)}},rg=(e,t,s,n)=>{const i=Qf(e,t),o=Zf(i,s);return ig(i,o,sg(i,t,n)),i.filter(a=>a.exported).flatMap(a=>[...o.get(W(a.file,a.name))?.values()??[]].map(c=>({...c,exportName:a.name,file:a.file})))},qe=e=>{if(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(r.isBinaryExpression(e)&&e.getOperatorToken().getKind()===d.PlusToken){const t=qe(e.getLeft()),s=qe(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},og=e=>{let t=e,s=t.getParent();for(;s!==void 0&&r.isBinaryExpression(s)&&s.getOperatorToken().getKind()===d.PlusToken;)t=s,s=t.getParent();return t!==e&&qe(t)!==void 0},ag=e=>{const t=e.getParent();if(t!==void 0){if(r.isVariableDeclaration(t)||r.isPropertyAssignment(t)||r.isPropertySignature(t))return S(t);if(r.isBinaryExpression(t)&&t.getOperatorToken().getKind()===d.EqualsToken)return t.getLeft().getText()}},cg=(e,t,s)=>eo(e)?!br(s)&&to(ag(t)):!0,lg=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(d.BinaryExpression),...e.getDescendantsOfKind(d.StringLiteral),...e.getDescendantsOfKind(d.NoSubstitutionTemplateLiteral)],i=new Set;for(const o of n){if(og(o))continue;const a=qe(o);if(a===void 0)continue;const c=Jr(a);if(c===void 0||!cg(c,o,t))continue;const l=o.getStartLineNumber(),u=`${String(l)}:${c}`;i.has(u)||(i.add(u),s.push({file:t,kind:c,line:l,preview:Zr(a)}))}return s},dg=(e,t)=>{const s=[],n=new Ut({compilerOptions:{allowJs:!0},skipFileDependencyResolution:!0,skipLoadingLibFiles:!0,useInMemoryFileSystem:!0});for(const i of A(t,{includeSkipped:!0})){const o=e.getSourceFile(i)??n.createSourceFile(i,Ge(i,"utf8"),{overwrite:!0});s.push(...lg(o,w(t,i)))}return s},ug=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&r.isCallExpression(s)?ee(s):void 0;if(!n)return[];const i=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=$n(o);if(a===void 0)continue;const c=R(a.options,"includeDeleted");if(c===void 0)continue;const l=r.isTrueLiteral(c),u=!l&&q(c);!l&&!u||i.push({exportName:j(e)??e.getName(),file:t,fromArgs:u,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:n.visibility})}return i},fg=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=w(t,n);for(const a of Q(i))s.push(...ug(a,o))}return s},gg=new Set(["query","unsafe"]),pg=e=>!r.isPropertyAccessExpression(e)||!gg.has(e.getName())?!1:G(e.getExpression(),["sql"]),mg=e=>r.isBinaryExpression(e)||r.isTemplateExpression(e),hg=(e,t)=>{if(!pg(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!mg(s)))return{file:t,line:s.getStartLineNumber(),scope:x(e)}},vg=(e,t)=>C(e,t,hg),Eg=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],xg=e=>{for(const[t,s]of Eg)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},Sg=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of i.getImportDeclarations()){const a=o.getModuleSpecifierValue(),c=xg(a);c!==void 0&&s.push({file:w(t,n),line:o.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},Ag=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),yg=(e,t,s=[])=>{const n=tt(e,t,{argIndex:0,matchReceiver:i=>i==="ctx.storage"||i.startsWith("ctx.storage."),methods:Ag,requireUnmodifiedReach:!0});return Ht(n,s)},bg=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Ng=e=>e&&r.isNumericLiteral(e)?Number(e.getText()):void 0,Pg=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!r.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const i of e.getProperties()){if(r.isSpreadAssignment(i)){n=!0;continue}if(r.isPropertyAssignment(i)){const o=S(i);t.push(o),o==="expiresInSeconds"&&(s=Ng(i.getInitializer()));continue}(r.isShorthandPropertyAssignment(i)||r.isMethodDeclaration(i))&&t.push(S(i))}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},wg=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName(),s=bg.get(t);return s===void 0?void 0:Dn(e.getExpression(),i=>i==="ctx.storage"||i.startsWith("ctx.storage."))?{method:t,optionsIndex:s}:void 0},Ig=(e,t)=>{const s=wg(e.getExpression());if(s!==void 0)return{scope:x(e),file:t,line:e.getStartLineNumber(),method:s.method,...Pg(e.getArguments()[s.optionsIndex])}},Cg=(e,t)=>C(e,t,Ig),Tg=e=>r.isDoStatement(e)||r.isForInStatement(e)||r.isForOfStatement(e)||r.isForStatement(e)||r.isWhileStatement(e),Pi=e=>{const t=e.getLabel()?.getText(),s=i=>t!==void 0?r.isLabeledStatement(i)&&i.getLabel().getText()===t:Tg(i)||r.isBreakStatement(e)&&r.isSwitchStatement(i);let n=e.getFirstAncestor(i=>re(i)||s(i));if(!(n===void 0||re(n))){for(;r.isContinueStatement(e)&&r.isLabeledStatement(n);)n=n.getStatement();return n}},ts=(e,t)=>y(e.getFirstAncestor(s=>y(s,t)||re(s)),t),Og=(e,t)=>y(e,t)||e.getFirstAncestor(s=>y(s,t))!==void 0,wi=(e,t)=>{if(r.isReturnStatement(e)||r.isThrowStatement(e))return y(e,t)||ts(e,t);if(r.isBreakStatement(e)||r.isContinueStatement(e)){const s=Pi(e);return s!==void 0&&!Og(s,t)}return!1},Ii=e=>[...r.isBreakStatement(e)||r.isContinueStatement(e)||r.isReturnStatement(e)||r.isThrowStatement(e)?[e]:[],...e.getDescendantsOfKind(d.BreakStatement),...e.getDescendantsOfKind(d.ContinueStatement),...e.getDescendantsOfKind(d.ReturnStatement),...e.getDescendantsOfKind(d.ThrowStatement)],kg=e=>Ii(e).some(t=>wi(t,e)),Rg=e=>{const t=r.isCallExpression(e)?e.getExpression():void 0;return r.isPropertyAccessExpression(t)&&t.getName()==="throwIfAborted"},Fg=e=>Ii(e).some(t=>wi(t,e)||r.isBreakStatement(t)&&y(Pi(t),e))||e.getDescendantsOfKind(d.CallExpression).some(t=>Rg(t)&&ts(t,e)),Lg=e=>e.getDescendantsOfKind(d.YieldExpression).some(t=>ts(t,e)),Dg=e=>r.isDoStatement(e)||r.isWhileStatement(e)?e.getExpression():e.getCondition(),Mg=e=>r.isDoStatement(e)?"do":r.isWhileStatement(e)?"while":"for",yt=(e,t)=>{const s=Dg(e);if(!(s===void 0||r.isTrueLiteral(h(s)))||Fg(e)||Lg(e))return;const i=x(e);if(!(i.kind==="module"&&e.getFirstAncestor(re)!==void 0))return{file:t,kind:Mg(e),line:e.getStartLineNumber(),scope:i}},_g=(e,t)=>[...ne(e,t,d.WhileStatement,yt),...ne(e,t,d.ForStatement,yt),...ne(e,t,d.DoStatement,yt)].toSorted((s,n)=>s.file.localeCompare(n.file)||s.line-n.line),Kg=new Set(["when","where"]),bt=new Set(["definePolicy","defineShape"]),zg=e=>{if(!r.isCallExpression(e))return;const t=e.getExpression();if(r.isPropertyAccessExpression(t)){const n=t.getName();return bt.has(n)?n:void 0}if(!r.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(r.isImportSpecifier(n)){const i=n.getNameNode().getText();return bt.has(i)?i:void 0}const s=t.getText();return bt.has(s)?s:void 0},$g=e=>r.isObjectLiteralExpression(e)&&e.getProperties().length===0,Ci=e=>{if(e!==void 0){if(r.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===d.UndefinedKeyword||e.getText()==="undefined")return"undefined";if($g(e))return"empty-object";if(r.isParenthesizedExpression(e))return Ci(e.getExpression())}},ss=e=>e.getAncestors().find(t=>r.isArrowFunction(t)||r.isFunctionExpression(t)||r.isFunctionDeclaration(t)),Bg=e=>e.getDescendantsOfKind(d.ReturnStatement).filter(t=>ss(t)===e),Ti=e=>e.getDescendantsOfKind(d.ConditionalExpression).filter(t=>ss(t)===e),Vg=e=>{const t=Bg(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(d.IfStatement)!==void 0)||Ti(e).length>0},Ug=e=>e.getDescendantsOfKind(d.IfStatement).filter(t=>ss(t)===e),zt=e=>e.getKind()===d.NullKeyword||e.getKind()===d.FalseKeyword||r.isIdentifier(e)&&e.getText()==="undefined"?!0:r.isNumericLiteral(e)?e.getLiteralValue()===0:r.isStringLiteral(e)&&e.getLiteralValue()==="",Wg=(e,t)=>zt(e)||zt(t),qg=new Map([[d.EqualsEqualsEqualsToken,"positive"],[d.EqualsEqualsToken,"positive"],[d.ExclamationEqualsEqualsToken,"negative"],[d.ExclamationEqualsToken,"negative"]]),dn=e=>!zt(e)&&(r.isLiteralExpression(e)||e.getKind()===d.TrueKeyword),jg=(e,t,s)=>{const n=qg.get(e);if(n!==void 0)return Wg(t,s)?n==="positive"?"negative":"positive":dn(t)||dn(s)?void 0:n},Se=e=>{if(r.isParenthesizedExpression(e))return Se(e.getExpression());if(r.isPrefixUnaryExpression(e)&&e.getOperatorToken()===d.ExclamationToken)return"negative";if(r.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=jg(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===d.AmpersandAmpersandToken||t===d.BarBarToken){const n=Se(e.getLeft()),i=Se(e.getRight());return n===i?n:"indeterminate"}}return r.isIdentifier(e)||r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e)||r.isCallExpression(e)?"positive":"indeterminate"},un=e=>{if(e!==void 0){if(r.isReturnStatement(e))return e;if(r.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&r.isReturnStatement(t)?t:void 0}}},Hg=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(d.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Gg=e=>r.isReturnStatement(e)?e.getExpression()??e:e,Yg=e=>{const t=[];for(const s of Ti(e)){const n=Se(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of Ug(e)){const n=Se(s.getExpression());if(n==="indeterminate")continue;const i=n==="negative"?un(s.getThenStatement()):un(s.getElseStatement())??Hg(s);i!==void 0&&t.push(Gg(i))}return t},Qg=e=>{for(const t of e.getAncestors())if(r.isVariableDeclaration(t)){const s=t.getNameNode();if(r.isIdentifier(s))return s.getText()}return"<anonymous>"},Xg=(e,t,s)=>{if(!r.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!r.isObjectLiteralExpression(n))return[];const i=[];for(const o of n.getProperties()){if(!r.isPropertyAssignment(o)||!Kg.has(S(o)))continue;const a=o.getInitializer();if(!(!a||!(r.isArrowFunction(a)||r.isFunctionExpression(a)))&&Vg(a))for(const c of Yg(a)){const l=Ci(c);l!==void 0&&i.push({exportName:Qg(e),file:s,form:l,key:S(o),line:c.getStartLineNumber(),owner:t})}}return i},Jg=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=zg(n);i!==void 0&&s.push(...Xg(n,i,t))}return s},Zg=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Jg(i,w(t,n)))}return s},ep=new Set(["query","upsert","upsertMany","upsertNow"]),pe=new Set,tp=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();if(ep.has(t))return G(e.getExpression(),["vectors"])?t:void 0},ns=e=>{let t=e;for(;r.isParenthesizedExpression(t)||r.isAsExpression(t)||r.isSatisfiesExpression(t)||r.isNonNullExpression(t)||r.isTypeAssertion(t);)t=t.getExpression();return t},Oi=e=>{const t=e.getParent();return r.isShorthandPropertyAssignment(t)&&t.getNameNode()===e?t.getValueSymbol():e.getSymbol()},ki=e=>Oi(e)?.getDeclarations()[0],sp=e=>{const t=e.getParent();return r.isBindingElement(t)||(r.isPropertyAccessExpression(t)||r.isPropertyAssignment(t)||r.isVariableDeclaration(t)||r.isParameterDeclaration(t)||r.isMethodDeclaration(t))&&t.getNameNode()===e?!1:!r.isQualifiedName(t)||t.getLeft()===e},Ri=e=>{let t=e;for(;t!==void 0&&(r.isBindingElement(t)||r.isObjectBindingPattern(t)||r.isArrayBindingPattern(t));)t=t.getParent();return t!==void 0&&r.isVariableDeclaration(t)?t:void 0},fn=(e,t,s)=>{const n=Oi(e)?.compilerSymbol;if(n!==void 0&&t.has(n))return!0;if(s>0){const i=Ri(ki(e)),o=i!==void 0&&r.isVariableDeclaration(i)?i.getInitializer():void 0;if(o!==void 0)return is(o,t,s-1)}return q(e)},is=(e,t,s)=>{const n=ns(e);return le(n)?!1:r.isIdentifier(n)?fn(n,t,s):q(n)?!0:n.getDescendantsOfKind(d.Identifier).some(i=>sp(i)&&fn(i,t,s))},Fi=e=>{const t=Ri(ki(e));return t!==void 0&&r.isVariableDeclaration(t)?t.getInitializer():void 0},Z=(e,t)=>{const s=ns(e);if(r.isObjectLiteralExpression(s))return[s];if(r.isConditionalExpression(s))return[...Z(s.getWhenTrue(),t),...Z(s.getWhenFalse(),t)];if(r.isBinaryExpression(s)){const n=s.getOperatorToken().getKind();if(n===d.BarBarToken||n===d.QuestionQuestionToken||n===d.AmpersandAmpersandToken)return[...Z(s.getLeft(),t),...Z(s.getRight(),t)]}if(r.isIdentifier(s)&&t){const n=Fi(s);return n===void 0?[]:Z(n,!1)}return[]},np=(e,t)=>{const s=Z(e,t);if(s.length===0)return{replaces:!0,sources:[e]};const n=s.map(o=>je(o,!1)),i=n.flat();if(i.length!==0)return{replaces:n.every(o=>o.length>0),sources:i}},ip=e=>(r.isPropertyAssignment(e)||r.isShorthandPropertyAssignment(e))&&e.getName()==="namespace",rp=e=>r.isShorthandPropertyAssignment(e)?e.getNameNode():e.getInitializer()??e.getNameNode(),je=(e,t)=>{let s=[];for(const n of e.getProperties())if(r.isSpreadAssignment(n)){const i=np(n.getExpression(),t);i!==void 0&&(s=i.replaces?i.sources:[...s,...i.sources])}else ip(n)&&(s=[rp(n)]);return s},op=e=>{if(!e||!(r.isArrowFunction(e)||r.isFunctionExpression(e)))return[];const t=e.getBody();return r.isBlock(t)?t.getDescendantsOfKind(d.ReturnStatement).filter(s=>s.getFirstAncestor(n=>r.isFunctionLikeDeclaration(n))===e).flatMap(s=>s.getExpression()??[]):[t]},ap=e=>{if(!e||!(r.isArrowFunction(e)||r.isFunctionExpression(e)))return pe;const t=e.getParameters()[0]?.getNameNode();if(t===void 0)return pe;const s=r.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.BindingElement).map(n=>n.getNameNode());return new Set(s.flatMap(n=>r.isIdentifier(n)?n.getSymbol()?.compilerSymbol??[]:[]))},$t=(e,t=!0,s=pe)=>{const n=ns(e);if(r.isIdentifier(n)){const o=t?Fi(n):void 0;return o===void 0?[{node:n,parameters:s}]:$t(o,!1,s)}if(r.isArrayLiteralExpression(n))return n.getElements().flatMap(o=>r.isSpreadElement(o)?$t(o.getExpression(),t,s):Z(o,!0).flatMap(a=>je(a,!0).map(c=>({node:c,parameters:s}))));const i=r.isCallExpression(n)?n.getExpression():void 0;if(r.isCallExpression(n)&&r.isPropertyAccessExpression(i)&&i.getName()==="map"){const o=n.getArguments()[0],a=is(i.getExpression(),pe,1)?ap(o):pe;return op(o).flatMap(c=>Z(c,!0).flatMap(l=>je(l,!0).map(u=>({node:u,parameters:a}))))}return[{node:n,parameters:s}]},cp=(e,t)=>{const s=tp(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!(!n||!(s==="upsertMany"?$t(n):Z(n,!0).flatMap(o=>je(o,!0).map(a=>({node:a,parameters:pe})))).some(({node:o,parameters:a})=>is(o,a,1))))return{scope:x(e),file:t,line:e.getStartLineNumber(),method:s}},lp=(e,t)=>C(e,t,cp),dp=(e,t,s)=>{const{callSites:n,containers:i,crons:o,functions:a,modules:c,mutators:l,queues:u,schema:f,shapes:g,wranglerVariables:m,workflows:v}=s;return hr({adminRoutes:Ma(e,t),aiRawRuns:qa(e,t),aiToolSideEffects:sc(e,t),argumentDerivedFetches:rc(e,t),argumentValidators:bc(e,t),authApiCalls:zr(e,t),authConfigs:Fc(e,t),browserUrlAccesses:_c(e,t),callEdges:n.callEdges,configCalls:qc(e,t),containerKeyAccesses:Hc(e,t),containerOverrides:Zc(e,t),containers:i,countReads:il(e,t,f.tables),crons:o,cronTargets:o.flatMap($=>$.functionPath===void 0?[]:[$.functionPath]),exportSinks:cl(e,t),staleMigrationImports:Sg(e,t),failOpenGuards:gl(e,t),flagReads:El(e,t),flagSecurityDefaults:yl(e,t),geoIndexUsages:Pl(e,t),httpActionGuards:_l(e,t),httpHeaderWrites:Hl(e,t),hyperdriveCalls:$r(e,t),identityClaimReads:id(e,t),imageDeliveryUrlAccesses:od(e,t),inserts:n.inserts,kvKeyAccesses:cd(e,t,a),mailRecipientAccesses:gd(e,t),maskProcedures:Br(e,t),maskStrategies:hd(e,t),mutatorWrites:yd(e,t),nondeterministicCalls:jr(e,t),normalizeIdAuthorizations:_d(e,t),notifyCalls:Gr(e,t),notifyConfig:Hr(e,t),mutators:l,ownerFieldWrites:Ru(e,t,a,l),unrestrictedWhereBranches:Zg(e,t),paymentWebhooks:_u(e,t),privilegedDispatches:Gu(e,t),procedureProtections:Rf(e,t),queries:n.queries,queues:u,r2sqlCalls:Yr(e,t),ratelimitKeySelectors:zf(e,t),rawRowReturns:jf(e,t),relationLoads:Yf(e,t),rlsProcedures:Qr(e,t),schema:f,secretLiterals:dg(e,t),modules:c,shapes:g,softDeleteReads:fg(e,t),sqlInterpolations:vg(e,t),storageKeyAccesses:yg(e,t,a),storageUploads:Cg(e,t),tableWrites:n.tableWrites,rowEffects:rg(e,t,n.tableWrites,n.callEdges),unboundedLoops:_g(e,t),vectorNamespaceAccesses:lp(e,t),workflowCalls:n.workflowCalls,workflows:v,wranglerVariables:m})},up=e=>({cacheKey:`advisor_accept_unused:${e.rule}:${e.file}:${e.exportName}`,categories:["SCHEMA"],description:"`advisor.accept` in `lunora.config.*` accepts a finding the advisor does not report as an error.",detail:`No ERROR \`${e.rule}\` in \`${e.file}\` for \`${e.exportName}\` — the acceptance no longer applies.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e.exportName,file:e.file,rule:e.rule},name:"advisor_accept_unused",remediation:"Remove the entry, or correct the rule, file and export name it names.",title:"An accepted advisor finding matches no error"}),fp=(e,t)=>{const s=new Set;return[...e.map(i=>{if(i.level!=="ERROR")return i;const o=t.find(a=>a.rule===i.name&&a.file===i.metadata.file&&a.exportName===i.metadata.exportName);return o===void 0?i:(s.add(o),{...i,detail:`Accepted: ${o.reason}. ${i.detail}`,level:"INFO",metadata:{...i.metadata,accepted:o.reason}})}),...t.filter(i=>!s.has(i)).map(i=>up(i))]},gp=()=>({cacheKey:"advisor_accept_invalid",categories:["SCHEMA"],description:"`advisor.accept` in `lunora.config.*` is read by parsing the file, so every entry must be a literal.",detail:"`advisor.accept` is not an array of literal `{ rule, file, exportName, reason }` objects with non-empty strings, so codegen ignored all of it and every ERROR still fails the gate.",facing:"INTERNAL",level:"WARN",metadata:{},name:"advisor_accept_invalid",remediation:'Write `advisor: { accept: [{ rule: "owner_field_from_args_not_auth", file: "lunora/auth/team.ts", exportName: "addTeamMember", reason: "…" }] }` as literals on the config\'s default export.',title:"`advisor.accept` is not a list codegen can read, so no acceptance applies"}),pp=e=>e.metadata.accepted!==void 0||e.name==="advisor_accept_unused"||e.name==="advisor_accept_invalid",gn={error:"ERROR",info:"INFO",warn:"WARN"},pn={ERROR:2,INFO:0,WARN:1},mp=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"}),hp=(e,t)=>{const{advisor:s}=Vn(e);if(s===void 0||s.minSeverity===void 0&&s.unreadable!==!0)return[...t];const{minSeverity:n}=s,i=n!==void 0&&Object.hasOwn(gn,n)?gn[n]:void 0;return i===void 0?[...t,mp(n===void 0?"`advisor.minSeverity` is not a string literal codegen can read without evaluating the config: a computed value or key, or a spread that could set or override it.":`\`advisor.minSeverity\` is "${n}", which is not one of "info", "warn" or "error".`)]:t.filter(o=>pp(o)||pn[o.level]>=pn[i])},vp=(e,t)=>{const{advisor:s}=Vn(e),n=fp(t,s?.accept??[]);return hp(e,s?.acceptUnreadable===!0?[...n,gp()]:n)},Ep={call:"function",enqueue:"queue",invoke:"service",publish:"topic",schedule:"function"},xp="crons",Sp=ro.replace(/\.ts$/u,""),ge=(e,t)=>`${Qt(e)}:${t}`,Nt=(e,t,s)=>t===""?{reason:`the ${s} is not a string literal`}:{to:`${e}:${t}`},Ap=e=>[...e.callEdges.map(t=>{const s=t.target===void 0?{reason:t.reason??"unreadable target"}:{to:`${Ep[t.kind]}:${t.target}`};return{file:t.file,kind:t.kind,line:t.line,scope:t.scope,...s}}),...e.queries.map(t=>({file:t.file,kind:"read",line:t.line,scope:t.scope,...Nt("table",t.table,"table name")})),...[...e.inserts,...e.tableWrites].map(t=>({file:t.file,kind:"write",line:t.line,scope:t.scope,...Nt("table",t.table,"written table")})),...e.workflowCalls.map(t=>({file:t.file,kind:"start",line:t.line,scope:t.scope,...Nt("workflow",t.workflow,"workflow name")}))],yp=e=>e.untracked===!0?"inside a helper only code outside any export calls":"inside a non-exported helper",bp=e=>{const{scope:t}=e;switch(t.kind){case"export":return[{...e,exportName:t.name}];case"helper":return t.callers.length===0?[{...e,unattributed:yp(t)}]:t.callers.map(s=>({...e,exportName:s}));default:return[{...e,unattributed:"at module scope"}]}},Np=e=>Ap(e).flatMap(t=>bp(t)),Pp=e=>[...e.queues.flatMap(t=>t.topic===void 0?[]:[{file:t.filePath,from:`topic:${t.topic}`,kind:"subscribe",line:0,to:`queue:${t.exportName}`}]),...e.crons.map(t=>{const s=t.workflow===void 0?void 0:`workflow:${t.workflow.exportName}`,n=t.functionPath===void 0?void 0:`function:${t.functionPath}`,i=s??n;return{file:xp,from:`cron:${t.name}`,kind:"trigger",line:0,...i===void 0?{reason:"the cron has no target"}:{to:i}}})],wp=e=>new Map(e.flatMap(t=>t.tables.map(s=>[s,t.name]))),ve=(e,t)=>t===void 0?e:{...e,module:t},Ip=e=>{const t=new Map,s=new Map,n=wp(e.modules),i=(c,l)=>{s.set(c,[...s.get(c)??[],l])},o=(c,l)=>{t.set(c.id,c),l!==void 0&&i(l,c.id)},a=(c,l)=>{c!==void 0&&i(ge(c.file,c.exportName),l)};for(const c of e.functions){const l=ge(c.filePath,c.exportName),u=[...Xr(c.filePath),c.exportName].join(".");o(ve({detail:c.kind,id:`function:${l}`,kind:"function",name:u},Le(e.modules,c.filePath)),l)}for(const c of e.httpRoutes){const l=ge(c.filePath,c.exportName);o(ve({id:`http:${l}`,kind:"http",name:`${c.method} ${c.path}`},Le(e.modules,c.filePath)),l)}for(const c of e.schema.tables)o(ve({id:`table:${c.name}`,kind:"table",name:c.name},n.get(c.name)));for(const c of e.queues){const l=c.topic===void 0?{}:{detail:"subscription"};o(ve({...l,id:`queue:${c.exportName}`,kind:"queue",name:c.exportName},Le(e.modules,c.filePath)),ge(c.filePath,c.exportName)),a(c.handlerSite,`queue:${c.exportName}`)}for(const c of e.topics)o(ve({id:`topic:${c.exportName}`,kind:"topic",name:c.exportName},Le(e.modules,c.filePath)));for(const c of e.workflows)o({id:`workflow:${c.exportName}`,kind:"workflow",name:c.exportName},ge(Sp,c.exportName)),a(c.handlerSite,`workflow:${c.exportName}`);for(const c of e.crons)o({detail:c.cron,id:`cron:${c.name}`,kind:"cron",name:c.name});for(const c of e.services){const l=c.rpcEntrypoint===void 0?"fetch":"rpc";o({detail:c.entrypoint===void 0?l:`${l} · ${c.entrypoint}`,id:`service:${c.name}`,kind:"service",name:c.worker})}return{nodes:t,sites:s}},Cp=e=>e==="default"?"the default export is not a registered function":`"${e}" is not a registered function`,Tp=(e,t)=>"from"in e?[e.from]:"unattributed"in e?{reason:e.unattributed}:t.get(ge(e.file,e.exportName))??{reason:Cp(e.exportName)},Op=(e,t,s)=>{if("reason"in e)return{reason:e.reason};const n=Tp(e,t);if("reason"in n)return n;const{to:i}=e;return s.has(i)?{drawn:n.map(o=>({from:o,kind:e.kind,to:i}))}:{reason:`${i} is not declared`}},Pt=e=>`${e.from}|${e.kind}|${e.to}`,kp=e=>`${e.file}|${String(e.line)}|${e.kind}|${e.reason}`,Rp=e=>{const{nodes:t,sites:s}=Ip(e),n=new Map,i=new Map;for(const o of[...Pp(e),...Np(e)]){const a=Op(o,s,t);if("drawn"in a)for(const c of a.drawn)n.set(Pt(c),c);else{const c={file:o.file,kind:o.kind,line:o.line,reason:a.reason};i.set(kp(c),c)}}return{edges:[...n.values()].toSorted((o,a)=>Pt(o).localeCompare(Pt(a))),nodes:[...t.values()].toSorted((o,a)=>o.id.localeCompare(a.id)),modules:e.modules.map(o=>({...o.description===void 0?{}:{description:o.description},...o.installed===!0?{installed:!0}:{},...o.ownsFolder===!1?{ownsFolder:!1}:{},name:o.name,tables:[...o.tables]})),unresolved:[...i.values()].toSorted((o,a)=>o.file.localeCompare(a.file)||o.line-a.line),version:1}},Fp=e=>`${Un}export const architecture = ${ao(e,"Record<string, unknown>")};
|
|
24
24
|
`,mn=(e,t="api")=>{const s=new Map;for(const n of e){const i=Qt(n),o=s.get(i);if(o===void 0){s.set(i,n);continue}if(o!==n){const a=t==="api"?`the generated api.ts would declare "${i}" twice and the dispatch key "${i}:<fn>" would be ambiguous`:`the generated api.ts would declare "${i}" twice in HttpStreamsRef and again in the httpStreams object literal`;throw new _("INTERNAL",`@lunora/codegen: "${o}" and "${n}" both map to the ${t} namespace "${i}" — ${a}. Rename one file so the two differ by more than a non-identifier character (\`-\`, \`.\`, \`/\` and \`_\` all sanitize to \`_\`).`,{status:500})}}},Lp=(e,t={})=>{const{hasVectors:s=!0,scheduler:n=!1,storage:i=!1,usage:o}=t,a=[];e.tables.some(c=>Wn(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=>qn(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`"}),i&&a.push({name:"@lunora/storage",reason:"a `v.storage()` column, a storage access rule (or `ctx.storage` use) makes `_generated/app.ts` import `createStorage`"}),e.vectorIndexes.length>0&&s&&a.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/shard.ts` import `@lunora/bindings/vectors`"});for(const c of o===void 0?[]:mo)c.requiredPackage!==void 0&&o?.[c.key]===!0&&a.push({name:c.requiredPackage,reason:`\`ctx.${c.contextProperty??c.key}\` usage makes \`_generated/\` import \`${c.moduleSpecifier}\``});return a.filter((c,l)=>a.findIndex(u=>u.name===c.name)===l)},Dp=(e,t,s={})=>{if(t===void 0)return;const n=Lp(e,s).filter(o=>!t.has(o.name));if(n.length===0)return;const i=n.map(o=>` - ${o.name} — ${o.reason}`).join(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./CAPABILITY_PROBES-brcmKenl.mjs";import{e}from"./server-
|
|
1
|
+
import"./CAPABILITY_PROBES-brcmKenl.mjs";import{e}from"./server-CeYggUIZ.mjs";import"./shared-8vTRkL2-.mjs";import"./platform-8oj7iXQy.mjs";export{e as default};
|
|
@@ -245,11 +245,11 @@ type TypedTableQuery = (<T extends TableName>(
|
|
|
245
245
|
((table: string) => TableReader);
|
|
246
246
|
|
|
247
247
|
/**
|
|
248
|
-
* The point read \`ctx.db.get(id)\`, bound to this schema:
|
|
249
|
-
*
|
|
250
|
-
* \`null\` when absent) with no \`as Doc<...>\` cast. Mirrors {@link TypedTableQuery}.
|
|
248
|
+
* The point read \`ctx.db.get(table, id)\`, bound to this schema: the table literal
|
|
249
|
+
* fixes \`T\`, so the id must be an \`Id<T>\` and the resolved document is typed
|
|
250
|
+
* \`Doc<T>\` (or \`null\` when absent) with no \`as Doc<...>\` cast. Mirrors {@link TypedTableQuery}.
|
|
251
251
|
*/
|
|
252
|
-
type TypedTableGet = <T extends TableName>(id: IdOfTable<T>) => Promise<Doc<T> | null>;
|
|
252
|
+
type TypedTableGet = <T extends TableName>(table: T, id: IdOfTable<T>) => Promise<Doc<T> | null>;
|
|
253
253
|
|
|
254
254
|
/**
|
|
255
255
|
* Resolves the \`asId\` table argument: a literal in {@link TableName} passes through, a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/codegen",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.356",
|
|
4
4
|
"description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@lunora/advisor": "1.0.0-alpha.
|
|
54
|
-
"@lunora/agent": "1.0.0-alpha.
|
|
53
|
+
"@lunora/advisor": "1.0.0-alpha.259",
|
|
54
|
+
"@lunora/agent": "1.0.0-alpha.249",
|
|
55
55
|
"@lunora/container": "1.0.0-alpha.92",
|
|
56
56
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
57
57
|
"@lunora/platform": "1.0.0-alpha.75",
|