@lunora/codegen 1.0.0-alpha.313 → 1.0.0-alpha.314

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.
Files changed (22) hide show
  1. package/dist/index.mjs +1 -1
  2. package/dist/packem_shared/{MUTATORS_FILENAME-qVDmv8st.mjs → MUTATORS_FILENAME--5kUJd5I.mjs} +1 -1
  3. package/dist/packem_shared/{NOTIFY_FILENAME-CLoeWMb5.mjs → NOTIFY_FILENAME-BOZ8G8zT.mjs} +1 -1
  4. package/dist/packem_shared/{SCHEMA_SNAPSHOT_FILENAME-CSjCtmZi.mjs → SCHEMA_SNAPSHOT_FILENAME-DM4csP6n.mjs} +1 -1
  5. package/dist/packem_shared/{context-property-calls-CQWCNUVH.mjs → context-property-calls-DdoCuhv4.mjs} +1 -1
  6. package/dist/packem_shared/{context-root-LyOsqj_o.mjs → context-root-lGZCyHyj.mjs} +1 -1
  7. package/dist/packem_shared/{database-calls-BPpefKqO.mjs → database-calls-CVsXSVhv.mjs} +1 -1
  8. package/dist/packem_shared/{discoverFunctions-CbxZGGj0.mjs → discoverFunctions-BiA7jv30.mjs} +1 -1
  9. package/dist/packem_shared/{discoverHttpRoutes-DgfoyNcf.mjs → discoverHttpRoutes-BccLtGKg.mjs} +1 -1
  10. package/dist/packem_shared/discoverHyperdriveCalls-DxYmsE3Y.mjs +1 -0
  11. package/dist/packem_shared/{discoverInserts-mHOX_dJR.mjs → discoverInserts-rFszl3Al.mjs} +1 -1
  12. package/dist/packem_shared/discoverMaskProcedures-BZlL43UV.mjs +1 -0
  13. package/dist/packem_shared/{discoverQueries-CfxkjP5X.mjs → discoverQueries-DDds61UD.mjs} +1 -1
  14. package/dist/packem_shared/discoverR2sqlCalls-CEbVN9V1.mjs +1 -0
  15. package/dist/packem_shared/{discoverRlsProcedures-TskedRMh.mjs → discoverRlsProcedures-BfEFJmU5.mjs} +1 -1
  16. package/dist/packem_shared/{index-CkS96b8a.mjs → index-Bxn8ZjS0.mjs} +1 -1
  17. package/dist/packem_shared/unwrap-handler-return-BwclbliB.mjs +1 -0
  18. package/package.json +9 -9
  19. package/dist/packem_shared/discoverHyperdriveCalls-CwnXgjFJ.mjs +0 -1
  20. package/dist/packem_shared/discoverMaskProcedures-BTePIpmk.mjs +0 -1
  21. package/dist/packem_shared/discoverR2sqlCalls-XBhs4XRZ.mjs +0 -1
  22. package/dist/packem_shared/unwrap-handler-return-CJrkfrSH.mjs +0 -1
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{formatAdvisories as m,lintSchema as f,toAdvisorContext as d}from"./packem_shared/formatAdvisories-BCVASH7N.mjs";import{describeErrorLevelFindings as n,errorAdvisoryNames as l,errorPlatformDiagnosticNames as c,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 v}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as N,discoverAgents as g}from"./packem_shared/AGENTS_FILENAME-B6-kjzM3.mjs";import{isTestPath as R,listLunoraSourceFiles as T}from"./packem_shared/isTestPath-B81lOULB.mjs";import{default as I}from"./packem_shared/discoverAuthApiCalls-xs0ONfI-.mjs";import{CONTAINERS_FILENAME as L,discoverContainers as M}from"./packem_shared/CONTAINERS_FILENAME-dFRtAyIe.mjs";import{default as P}from"./packem_shared/discoverCrons-DBnCama4.mjs";import{capabilitiesUsedBy as b,foldCapabilitySignals as y,mayReadCapabilityContext as U,sourceCapabilitySignals as G}from"./packem_shared/capabilitiesUsedBy-QgSZyE0T.mjs";import{FLAGS_FILENAME as j,discoverFlags as B}from"./packem_shared/FLAGS_FILENAME-Bf0MSlHH.mjs";import{default as W}from"./packem_shared/discoverFunctions-CbxZGGj0.mjs";import{default as V}from"./packem_shared/discoverHttpRoutes-DgfoyNcf.mjs";import{default as Q}from"./packem_shared/discoverHyperdriveCalls-CwnXgjFJ.mjs";import{default as w}from"./packem_shared/discoverInserts-mHOX_dJR.mjs";import{d as Y}from"./packem_shared/index-CkS96b8a.mjs";import{default as Z}from"./packem_shared/discoverMigrations-C9mLIhGZ.mjs";import{MUTATORS_FILENAME as ee,discoverMutators as re}from"./packem_shared/MUTATORS_FILENAME-qVDmv8st.mjs";import{default as te}from"./packem_shared/discoverNondeterministicCalls-9ZDpRptb.mjs";import{NOTIFY_FILENAME as ae,discoverNotifyCalls as ie,discoverNotifyChannels as me,discoverNotifyConfig as fe}from"./packem_shared/NOTIFY_FILENAME-CLoeWMb5.mjs";import{default as pe}from"./packem_shared/readPackageDependencies-RHhGiz0k.mjs";import{default as le}from"./packem_shared/discoverQueries-CfxkjP5X.mjs";import{QUEUES_FILENAME as xe,discoverQueues as Se}from"./packem_shared/QUEUES_FILENAME-CsRy4VTF.mjs";import{default as ue}from"./packem_shared/discoverR2sqlCalls-XBhs4XRZ.mjs";import{default as ve}from"./packem_shared/discoverRlsProcedures-TskedRMh.mjs";import{default as Ne}from"./packem_shared/discoverRlsMetadata-Cb8JR1b4.mjs";import{discoverSandboxUsage as Oe}from"./packem_shared/discoverSandboxUsage-w6Q3RvxZ.mjs";import{default as Te}from"./packem_shared/discoverSchema-BtsX-CN9.mjs";import{readServiceBindings as Ie,resolveServiceBindings as _e}from"./packem_shared/readServiceBindings-DvqIThzd.mjs";import{SHAPES_FILENAME as Me,discoverShapes as Fe}from"./packem_shared/SHAPES_FILENAME-DkBUN9dK.mjs";import{default as De}from"./packem_shared/discoverStorageRulesMetadata-BPJplDfz.mjs";import{WORKFLOWS_FILENAME as ye,discoverWorkflows as Ue}from"./packem_shared/WORKFLOWS_FILENAME-CdeS224T.mjs";import{emitApp as He}from"./packem_shared/emitApp-BOUdd-2R.mjs";import{isD1GlobalTable as Be,isHyperdriveGlobalTable as ke}from"./packem_shared/isD1GlobalTable-udvHAAzD.mjs";import{buildOpenApiDocument as Ke,emitOpenApi as Ve,emitOpenApiModule as ze}from"./packem_shared/buildOpenApiDocument-DFv-RYZU.mjs";import{OPENRPC_VERSION as qe,buildOpenRpcDocument as we,emitOpenRpc as Je,emitOpenRpcModule as Ye}from"./packem_shared/OPENRPC_VERSION-CCY7xqSL.mjs";import{DEFAULT_TARGET as Ze,platformMatrixIds as $e,readProjectTarget as er,resolveCodegenTarget as rr}from"./packem_shared/DEFAULT_TARGET-BnQiNNKu.mjs";import{l as tr,r as sr}from"./packem_shared/project-config-file-BV7RR-l6.mjs";import{SCHEMA_SNAPSHOT_FILENAME as ir,runCodegen as mr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-CSjCtmZi.mjs";import{SchemaSnapshotParseError as dr,buildSchemaSnapshot as pr,evaluateSchemaDrift as nr,parseSchemaSnapshot as lr}from"./packem_shared/SchemaSnapshotParseError-BRJT7c2k.mjs";import{default as xr}from"./packem_shared/fingerprintSchemaSources-eVG9aVt0.mjs";import{schemaFromIr as Er}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as Ar,validatorIrToJsonSchema as vr}from"./packem_shared/LUNORA_ERROR_CODES-C2s0xWQD.mjs";import{SDK_LANGUAGES as Nr,SDK_TARGETS as gr,generateSdk as Or}from"./sdk/index.mjs";import{redact as Tr,secretKindOf as hr}from"./packem_shared/redact-Cy14LEnc.mjs";import{default as _r}from"./packem_shared/emitDrizzleSchema-DitcRZ1a.mjs";import{default as Mr}from"./packem_shared/emitFunctions-BeKgL3dl.mjs";import{e as Pr}from"./packem_shared/server-DAvi_bv_.mjs";import{e as br}from"./packem_shared/shard-Av4rUyYS.mjs";import{G as Ur}from"./packem_shared/shared-DnCokNcE.mjs";import{MESSAGE_SOLUTIONS as Hr,findSolutionByMessage as jr}from"@lunora/errors";import{PROJECT_CONFIG_FILENAMES as kr,findProjectConfigFile as Wr}from"./packem_shared/PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";import{createCodegenProject as Vr,findTsconfig as zr,refreshCodegenProject as Qr}from"./packem_shared/createCodegenProject-V51_yBw3.mjs";import{s as wr,t as Jr,u as Yr}from"./packem_shared/shard-runtime-CkTgY8tL.mjs";import{emitApi as Zr,emitCollections as $r,emitInternalApi as eo}from"./packem_shared/emitApi-Zx6VPN-7.mjs";import{emitCrons as oo,emitScheduler as to,emitVectors as so,emitWranglerCronTriggers as ao}from"./packem_shared/emitCrons-BQW2lviZ.mjs";import{emitDataModel as mo}from"./packem_shared/emitDataModel-BskFt9Wv.mjs";import{isTypedSchema as po}from"./packem_shared/isTypedSchema-CKzc3ioR.mjs";const e="0.0.0";export{N as AGENTS_FILENAME,E as CAPABILITY_PROBES,L as CONTAINERS_FILENAME,A as CodegenDiagnosticError,Ze as DEFAULT_TARGET,j as FLAGS_FILENAME,Ur as GENERATED_HEADER,Ar as LUNORA_ERROR_CODES,Hr as LUNORA_SOLUTION_RULES,ee as MUTATORS_FILENAME,ae as NOTIFY_FILENAME,qe as OPENRPC_VERSION,kr as PROJECT_CONFIG_FILENAMES,xe as QUEUES_FILENAME,ir as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,Nr as SDK_LANGUAGES,gr as SDK_TARGETS,Me as SHAPES_FILENAME,dr as SchemaSnapshotParseError,e as VERSION,ye as WORKFLOWS_FILENAME,Ke as buildOpenApiDocument,we as buildOpenRpcDocument,pr as buildSchemaSnapshot,b as capabilitiesUsedBy,Vr as createCodegenProject,n as describeErrorLevelFindings,v as diagnosticAt,s as diffSchemaSnapshots,g as discoverAgents,I as discoverAuthApiCalls,M as discoverContainers,P as discoverCrons,B as discoverFlags,W as discoverFunctions,V as discoverHttpRoutes,Q as discoverHyperdriveCalls,w as discoverInserts,Y as discoverMaskProcedures,Z as discoverMigrations,re as discoverMutators,te as discoverNondeterministicCalls,ie as discoverNotifyCalls,me as discoverNotifyChannels,fe as discoverNotifyConfig,le as discoverQueries,Se as discoverQueues,ue as discoverR2sqlCalls,Ne as discoverRlsMetadata,ve as discoverRlsProcedures,Oe as discoverSandboxUsage,Te as discoverSchema,Fe as discoverShapes,De as discoverStorageRulesMetadata,Ue as discoverWorkflows,wr as emitAgents,Zr as emitApi,He as emitApp,$r as emitCollections,Jr as emitContainers,oo as emitCrons,mo as emitDataModel,_r as emitDrizzleSchema,Mr as emitFunctions,eo as emitInternalApi,Ve as emitOpenApi,ze as emitOpenApiModule,Je as emitOpenRpc,Ye as emitOpenRpcModule,to as emitScheduler,Pr as emitServer,br as emitShard,so as emitVectors,Yr as emitWorkflows,ao as emitWranglerCronTriggers,l as errorAdvisoryNames,c as errorPlatformDiagnosticNames,nr as evaluateSchemaDrift,jr as findLunoraSolution,Wr as findProjectConfigFile,zr as findTsconfig,xr as fingerprintSchemaSources,y as foldCapabilitySignals,m as formatAdvisories,Or as generateSdk,Be as isD1GlobalTable,ke as isHyperdriveGlobalTable,R as isTestPath,po as isTypedSchema,f as lintSchema,T as listLunoraSourceFiles,tr as loadProjectConfig,U as mayReadCapabilityContext,lr as parseSchemaSnapshot,$e as platformMatrixIds,pe as readPackageDependencies,sr as readProjectConfigLiterals,er as readProjectTarget,Ie as readServiceBindings,Tr as redact,Qr as refreshCodegenProject,rr as resolveCodegenTarget,_e as resolveServiceBindings,mr as runCodegen,Er as schemaFromIr,hr as secretKindOf,a as serializeSchemaSnapshot,x as sortedUniqueNames,G as sourceCapabilitySignals,d as toAdvisorContext,vr as validatorIrToJsonSchema};
1
+ import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{formatAdvisories as m,lintSchema as f,toAdvisorContext as d}from"./packem_shared/formatAdvisories-BCVASH7N.mjs";import{describeErrorLevelFindings as n,errorAdvisoryNames as l,errorPlatformDiagnosticNames as c,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 v}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as N,discoverAgents as g}from"./packem_shared/AGENTS_FILENAME-B6-kjzM3.mjs";import{isTestPath as R,listLunoraSourceFiles as T}from"./packem_shared/isTestPath-B81lOULB.mjs";import{default as I}from"./packem_shared/discoverAuthApiCalls-xs0ONfI-.mjs";import{CONTAINERS_FILENAME as L,discoverContainers as M}from"./packem_shared/CONTAINERS_FILENAME-dFRtAyIe.mjs";import{default as P}from"./packem_shared/discoverCrons-DBnCama4.mjs";import{capabilitiesUsedBy as b,foldCapabilitySignals as y,mayReadCapabilityContext as U,sourceCapabilitySignals as G}from"./packem_shared/capabilitiesUsedBy-QgSZyE0T.mjs";import{FLAGS_FILENAME as j,discoverFlags as B}from"./packem_shared/FLAGS_FILENAME-Bf0MSlHH.mjs";import{default as W}from"./packem_shared/discoverFunctions-BiA7jv30.mjs";import{default as V}from"./packem_shared/discoverHttpRoutes-BccLtGKg.mjs";import{default as Q}from"./packem_shared/discoverHyperdriveCalls-DxYmsE3Y.mjs";import{default as w}from"./packem_shared/discoverInserts-rFszl3Al.mjs";import{d as Y}from"./packem_shared/index-Bxn8ZjS0.mjs";import{default as Z}from"./packem_shared/discoverMigrations-C9mLIhGZ.mjs";import{MUTATORS_FILENAME as ee,discoverMutators as re}from"./packem_shared/MUTATORS_FILENAME--5kUJd5I.mjs";import{default as te}from"./packem_shared/discoverNondeterministicCalls-9ZDpRptb.mjs";import{NOTIFY_FILENAME as ae,discoverNotifyCalls as ie,discoverNotifyChannels as me,discoverNotifyConfig as fe}from"./packem_shared/NOTIFY_FILENAME-BOZ8G8zT.mjs";import{default as pe}from"./packem_shared/readPackageDependencies-RHhGiz0k.mjs";import{default as le}from"./packem_shared/discoverQueries-DDds61UD.mjs";import{QUEUES_FILENAME as xe,discoverQueues as Se}from"./packem_shared/QUEUES_FILENAME-CsRy4VTF.mjs";import{default as ue}from"./packem_shared/discoverR2sqlCalls-CEbVN9V1.mjs";import{default as ve}from"./packem_shared/discoverRlsProcedures-BfEFJmU5.mjs";import{default as Ne}from"./packem_shared/discoverRlsMetadata-Cb8JR1b4.mjs";import{discoverSandboxUsage as Oe}from"./packem_shared/discoverSandboxUsage-w6Q3RvxZ.mjs";import{default as Te}from"./packem_shared/discoverSchema-BtsX-CN9.mjs";import{readServiceBindings as Ie,resolveServiceBindings as _e}from"./packem_shared/readServiceBindings-DvqIThzd.mjs";import{SHAPES_FILENAME as Me,discoverShapes as Fe}from"./packem_shared/SHAPES_FILENAME-DkBUN9dK.mjs";import{default as De}from"./packem_shared/discoverStorageRulesMetadata-BPJplDfz.mjs";import{WORKFLOWS_FILENAME as ye,discoverWorkflows as Ue}from"./packem_shared/WORKFLOWS_FILENAME-CdeS224T.mjs";import{emitApp as He}from"./packem_shared/emitApp-BOUdd-2R.mjs";import{isD1GlobalTable as Be,isHyperdriveGlobalTable as ke}from"./packem_shared/isD1GlobalTable-udvHAAzD.mjs";import{buildOpenApiDocument as Ke,emitOpenApi as Ve,emitOpenApiModule as ze}from"./packem_shared/buildOpenApiDocument-DFv-RYZU.mjs";import{OPENRPC_VERSION as qe,buildOpenRpcDocument as we,emitOpenRpc as Je,emitOpenRpcModule as Ye}from"./packem_shared/OPENRPC_VERSION-CCY7xqSL.mjs";import{DEFAULT_TARGET as Ze,platformMatrixIds as $e,readProjectTarget as er,resolveCodegenTarget as rr}from"./packem_shared/DEFAULT_TARGET-BnQiNNKu.mjs";import{l as tr,r as sr}from"./packem_shared/project-config-file-BV7RR-l6.mjs";import{SCHEMA_SNAPSHOT_FILENAME as ir,runCodegen as mr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-DM4csP6n.mjs";import{SchemaSnapshotParseError as dr,buildSchemaSnapshot as pr,evaluateSchemaDrift as nr,parseSchemaSnapshot as lr}from"./packem_shared/SchemaSnapshotParseError-BRJT7c2k.mjs";import{default as xr}from"./packem_shared/fingerprintSchemaSources-eVG9aVt0.mjs";import{schemaFromIr as Er}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as Ar,validatorIrToJsonSchema as vr}from"./packem_shared/LUNORA_ERROR_CODES-C2s0xWQD.mjs";import{SDK_LANGUAGES as Nr,SDK_TARGETS as gr,generateSdk as Or}from"./sdk/index.mjs";import{redact as Tr,secretKindOf as hr}from"./packem_shared/redact-Cy14LEnc.mjs";import{default as _r}from"./packem_shared/emitDrizzleSchema-DitcRZ1a.mjs";import{default as Mr}from"./packem_shared/emitFunctions-BeKgL3dl.mjs";import{e as Pr}from"./packem_shared/server-DAvi_bv_.mjs";import{e as br}from"./packem_shared/shard-Av4rUyYS.mjs";import{G as Ur}from"./packem_shared/shared-DnCokNcE.mjs";import{MESSAGE_SOLUTIONS as Hr,findSolutionByMessage as jr}from"@lunora/errors";import{PROJECT_CONFIG_FILENAMES as kr,findProjectConfigFile as Wr}from"./packem_shared/PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";import{createCodegenProject as Vr,findTsconfig as zr,refreshCodegenProject as Qr}from"./packem_shared/createCodegenProject-V51_yBw3.mjs";import{s as wr,t as Jr,u as Yr}from"./packem_shared/shard-runtime-CkTgY8tL.mjs";import{emitApi as Zr,emitCollections as $r,emitInternalApi as eo}from"./packem_shared/emitApi-Zx6VPN-7.mjs";import{emitCrons as oo,emitScheduler as to,emitVectors as so,emitWranglerCronTriggers as ao}from"./packem_shared/emitCrons-BQW2lviZ.mjs";import{emitDataModel as mo}from"./packem_shared/emitDataModel-BskFt9Wv.mjs";import{isTypedSchema as po}from"./packem_shared/isTypedSchema-CKzc3ioR.mjs";const e="0.0.0";export{N as AGENTS_FILENAME,E as CAPABILITY_PROBES,L as CONTAINERS_FILENAME,A as CodegenDiagnosticError,Ze as DEFAULT_TARGET,j as FLAGS_FILENAME,Ur as GENERATED_HEADER,Ar as LUNORA_ERROR_CODES,Hr as LUNORA_SOLUTION_RULES,ee as MUTATORS_FILENAME,ae as NOTIFY_FILENAME,qe as OPENRPC_VERSION,kr as PROJECT_CONFIG_FILENAMES,xe as QUEUES_FILENAME,ir as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,Nr as SDK_LANGUAGES,gr as SDK_TARGETS,Me as SHAPES_FILENAME,dr as SchemaSnapshotParseError,e as VERSION,ye as WORKFLOWS_FILENAME,Ke as buildOpenApiDocument,we as buildOpenRpcDocument,pr as buildSchemaSnapshot,b as capabilitiesUsedBy,Vr as createCodegenProject,n as describeErrorLevelFindings,v as diagnosticAt,s as diffSchemaSnapshots,g as discoverAgents,I as discoverAuthApiCalls,M as discoverContainers,P as discoverCrons,B as discoverFlags,W as discoverFunctions,V as discoverHttpRoutes,Q as discoverHyperdriveCalls,w as discoverInserts,Y as discoverMaskProcedures,Z as discoverMigrations,re as discoverMutators,te as discoverNondeterministicCalls,ie as discoverNotifyCalls,me as discoverNotifyChannels,fe as discoverNotifyConfig,le as discoverQueries,Se as discoverQueues,ue as discoverR2sqlCalls,Ne as discoverRlsMetadata,ve as discoverRlsProcedures,Oe as discoverSandboxUsage,Te as discoverSchema,Fe as discoverShapes,De as discoverStorageRulesMetadata,Ue as discoverWorkflows,wr as emitAgents,Zr as emitApi,He as emitApp,$r as emitCollections,Jr as emitContainers,oo as emitCrons,mo as emitDataModel,_r as emitDrizzleSchema,Mr as emitFunctions,eo as emitInternalApi,Ve as emitOpenApi,ze as emitOpenApiModule,Je as emitOpenRpc,Ye as emitOpenRpcModule,to as emitScheduler,Pr as emitServer,br as emitShard,so as emitVectors,Yr as emitWorkflows,ao as emitWranglerCronTriggers,l as errorAdvisoryNames,c as errorPlatformDiagnosticNames,nr as evaluateSchemaDrift,jr as findLunoraSolution,Wr as findProjectConfigFile,zr as findTsconfig,xr as fingerprintSchemaSources,y as foldCapabilitySignals,m as formatAdvisories,Or as generateSdk,Be as isD1GlobalTable,ke as isHyperdriveGlobalTable,R as isTestPath,po as isTypedSchema,f as lintSchema,T as listLunoraSourceFiles,tr as loadProjectConfig,U as mayReadCapabilityContext,lr as parseSchemaSnapshot,$e as platformMatrixIds,pe as readPackageDependencies,sr as readProjectConfigLiterals,er as readProjectTarget,Ie as readServiceBindings,Tr as redact,Qr as refreshCodegenProject,rr as resolveCodegenTarget,_e as resolveServiceBindings,mr as runCodegen,Er as schemaFromIr,hr as secretKindOf,a as serializeSchemaSnapshot,x as sortedUniqueNames,G as sourceCapabilitySignals,d as toAdvisorContext,vr as validatorIrToJsonSchema};
@@ -1 +1 @@
1
- import{existsSync as E}from"node:fs";import{join as y}from"node:path";import{Node as o,SyntaxKind as l}from"ts-morph";import{diagnosticAt as I}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as M}from"./module-specifiers-WF8iAydP.mjs";import{p as A}from"./parse-validator-IDBKIT7M.mjs";import{findObjectProperty as c,unwrapExpression as d,isConstDeclaration as P}from"./isTestPath-B81lOULB.mjs";import{j as D,i as b,f as g,d as O}from"./attribution-hVBriwzy.mjs";import{u as w}from"./unwrap-handler-return-CJrkfrSH.mjs";const z="mutators.ts",x=M,h=r=>{const e=r.getSymbol();if(!e)return r.getText()==="defineMutator";for(const t of e.getDeclarations())if(o.isImportSpecifier(t))return x(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMutator":!1;return!1},C=r=>{const e=r.getSymbol();if(!e)return!1;for(const t of e.getDeclarations()){if(!o.isNamespaceImport(t))continue;const i=t.getFirstAncestorByKind(l.ImportDeclaration);return i!==void 0&&x(i.getModuleSpecifierValue())}return!1},N=r=>{if(o.isIdentifier(r))return h(r);if(o.isPropertyAccessExpression(r)){const e=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(e)&&C(e)}return!1},S=r=>{const e=r.getArguments()[0];return e&&o.isObjectLiteralExpression(e)?e:void 0},m=new WeakMap,p=r=>{let e=m.get(r.compilerNode);if(e===void 0){const t=r.getNameNode(),i=t?.getText();e=r.getSourceFile().getDescendantsOfKind(l.Identifier).filter(s=>s!==t&&s.getText()===i&&g(s)?.compilerNode===r.compilerNode).length===1&&O(r)===void 0,m.set(r.compilerNode,e)}return e},f=r=>{const e=o.isIdentifier(r)?g(r):void 0,t=o.isSourceFile(e?.getParent())||o.isSourceFile(e?.getParent()?.getParent()?.getParent());if(e===void 0||e.getSourceFile()!==r?.getSourceFile()||!t)return;if(o.isFunctionDeclaration(e))return e.hasBody()&&p(e)?e:void 0;const i=P(e)?d(e.getInitializer()):void 0;return(o.isArrowFunction(i)||o.isFunctionExpression(i))&&o.isVariableDeclaration(e)&&p(e)?i:void 0},G=r=>{const e=r.getInitializer();if(!o.isCallExpression(e)||!N(e.getExpression()))return;const t=c(S(e),"server");if(o.isMethodDeclaration(t))return t;if(o.isShorthandPropertyAssignment(t))return f(t.getNameNode());const i=o.isPropertyAssignment(t)?d(t.getInitializer()):void 0;return o.isArrowFunction(i)||o.isFunctionExpression(i)?i:f(i)},T=r=>{const e=c(r,"args");if(!e||!o.isPropertyAssignment(e))return{};const t=e.getInitializer();return t&&o.isObjectLiteralExpression(t)?A(t):{}},L=r=>{const e=c(r,"server");if(!e||!o.isPropertyAssignment(e))return"unknown";const t=e.getInitializer();return!t||!(o.isArrowFunction(t)||o.isFunctionExpression(t))?"unknown":w(t)},j=r=>{const e=c(r,"owner");if(!e||!o.isPropertyAssignment(e))return;const t=e.getInitializer();return t&&o.isStringLiteral(t)?t.getLiteralValue():void 0},R=r=>{const e=[];for(const t of r.getVariableDeclarations()){if(!t.isExported())continue;const i=t.getInitializer();if(i?.getKind()!==l.CallExpression)continue;const n=i,s=n.getExpression();if(!N(s))continue;const a=t.getNameNode();if(!o.isIdentifier(a))throw I(a,"defineMutator exports must be plain named exports (no destructuring)");const u=S(n);for(const v of D(t).filter(F=>b(F)))e.push({args:T(u),exportName:v,filePath:"mutators",line:n.getStartLineNumber(),owner:j(u),returnType:L(u)})}return e},J=(r,e)=>{const t=y(e,z);if(!E(t))return[];const i=r.getSourceFile(t)??r.addSourceFileAtPath(t),n=R(i);return n.sort((s,a)=>s.exportName.localeCompare(a.exportName)),n};export{z as MUTATORS_FILENAME,J as discoverMutators,N as isDefineMutatorCallee,S as mutatorLiteral,G as mutatorServerImplOf};
1
+ import{existsSync as E}from"node:fs";import{join as y}from"node:path";import{Node as o,SyntaxKind as l}from"ts-morph";import{diagnosticAt as I}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as M}from"./module-specifiers-WF8iAydP.mjs";import{p as A}from"./parse-validator-IDBKIT7M.mjs";import{findObjectProperty as c,unwrapExpression as d,isConstDeclaration as P}from"./isTestPath-B81lOULB.mjs";import{j as D,i as b,f as g,d as O}from"./attribution-hVBriwzy.mjs";import{u as w}from"./unwrap-handler-return-BwclbliB.mjs";const z="mutators.ts",x=M,h=r=>{const e=r.getSymbol();if(!e)return r.getText()==="defineMutator";for(const t of e.getDeclarations())if(o.isImportSpecifier(t))return x(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMutator":!1;return!1},C=r=>{const e=r.getSymbol();if(!e)return!1;for(const t of e.getDeclarations()){if(!o.isNamespaceImport(t))continue;const i=t.getFirstAncestorByKind(l.ImportDeclaration);return i!==void 0&&x(i.getModuleSpecifierValue())}return!1},N=r=>{if(o.isIdentifier(r))return h(r);if(o.isPropertyAccessExpression(r)){const e=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(e)&&C(e)}return!1},S=r=>{const e=r.getArguments()[0];return e&&o.isObjectLiteralExpression(e)?e:void 0},m=new WeakMap,p=r=>{let e=m.get(r.compilerNode);if(e===void 0){const t=r.getNameNode(),i=t?.getText();e=r.getSourceFile().getDescendantsOfKind(l.Identifier).filter(s=>s!==t&&s.getText()===i&&g(s)?.compilerNode===r.compilerNode).length===1&&O(r)===void 0,m.set(r.compilerNode,e)}return e},f=r=>{const e=o.isIdentifier(r)?g(r):void 0,t=o.isSourceFile(e?.getParent())||o.isSourceFile(e?.getParent()?.getParent()?.getParent());if(e===void 0||e.getSourceFile()!==r?.getSourceFile()||!t)return;if(o.isFunctionDeclaration(e))return e.hasBody()&&p(e)?e:void 0;const i=P(e)?d(e.getInitializer()):void 0;return(o.isArrowFunction(i)||o.isFunctionExpression(i))&&o.isVariableDeclaration(e)&&p(e)?i:void 0},G=r=>{const e=r.getInitializer();if(!o.isCallExpression(e)||!N(e.getExpression()))return;const t=c(S(e),"server");if(o.isMethodDeclaration(t))return t;if(o.isShorthandPropertyAssignment(t))return f(t.getNameNode());const i=o.isPropertyAssignment(t)?d(t.getInitializer()):void 0;return o.isArrowFunction(i)||o.isFunctionExpression(i)?i:f(i)},T=r=>{const e=c(r,"args");if(!e||!o.isPropertyAssignment(e))return{};const t=e.getInitializer();return t&&o.isObjectLiteralExpression(t)?A(t):{}},L=r=>{const e=c(r,"server");if(!e||!o.isPropertyAssignment(e))return"unknown";const t=e.getInitializer();return!t||!(o.isArrowFunction(t)||o.isFunctionExpression(t))?"unknown":w(t)},j=r=>{const e=c(r,"owner");if(!e||!o.isPropertyAssignment(e))return;const t=e.getInitializer();return t&&o.isStringLiteral(t)?t.getLiteralValue():void 0},R=r=>{const e=[];for(const t of r.getVariableDeclarations()){if(!t.isExported())continue;const i=t.getInitializer();if(i?.getKind()!==l.CallExpression)continue;const n=i,s=n.getExpression();if(!N(s))continue;const a=t.getNameNode();if(!o.isIdentifier(a))throw I(a,"defineMutator exports must be plain named exports (no destructuring)");const u=S(n);for(const v of D(t).filter(F=>b(F)))e.push({args:T(u),exportName:v,filePath:"mutators",line:n.getStartLineNumber(),owner:j(u),returnType:L(u)})}return e},J=(r,e)=>{const t=y(e,z);if(!E(t))return[];const i=r.getSourceFile(t)??r.addSourceFileAtPath(t),n=R(i);return n.sort((s,a)=>s.exportName.localeCompare(a.exportName)),n};export{z as MUTATORS_FILENAME,J as discoverMutators,N as isDefineMutatorCallee,S as mutatorLiteral,G as mutatorServerImplOf};
@@ -1 +1 @@
1
- import{existsSync as v}from"node:fs";import{join as N}from"node:path";import{SyntaxKind as u,Node as r,VariableDeclarationKind as F}from"ts-morph";import{listLunoraSourceFiles as m,lunoraRelativePath as O,findObjectProperty as g,defaultExportExpression as D,handlerOf as A}from"./isTestPath-B81lOULB.mjs";import{b as I,d as T}from"./attribution-hVBriwzy.mjs";import{i as l}from"./context-root-LyOsqj_o.mjs";import{c as C}from"./classify-procedure-call-BAj0D1u2.mjs";const k="notify.ts",L=new Set(["chat","inApp","send","webhook"]),h=new Set(["broadcast","send"]),M=e=>{const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const t=C(s);if(!t)return;const i=A(s,t.receiver);return i?{exportName:T(e)??e.getName(),handler:i,kind:t.kind}:void 0},x=e=>{const s=[];for(const t of I(e)){const i=M(t);i&&s.push(i)}return s},y=e=>l(e,["notify"])?"notify":l(e,["push"])||l(e,["notify","push"])?"push":void 0,w=e=>{if(!r.isPropertyAccessExpression(e))return;const s=e.getName(),t=y(e.getExpression());if(t==="notify"&&L.has(s))return`ctx.notify.${s}`;if(t==="push"&&h.has(s))return`ctx.push.${s}`},_=e=>r.isPropertyAccessExpression(e)?y(e.getExpression())==="push"&&h.has(e.getName()):!1,Z=(e,s)=>{const t=[];for(const i of m(s)){const n=e.getSourceFile(i)??e.addSourceFileAtPath(i),o=O(s,i);for(const c of x(n))if(!(c.kind!=="query"&&c.kind!=="mutation"))for(const a of c.handler.getDescendantsOfKind(u.PropertyAccessExpression)){const f=w(a);f!==void 0&&t.push({callee:f,exportName:c.exportName,file:o,kind:c.kind,line:a.getStartLineNumber()})}}return t},K=(e,s)=>{for(const t of m(s)){const i=e.getSourceFile(t)??e.addSourceFileAtPath(t);for(const n of x(i))for(const o of n.handler.getDescendantsOfKind(u.PropertyAccessExpression))if(_(o))return!0}return!1},R=new Set(["@lunora/notify"]),U=e=>{const s=e.getSymbol();if(!s)return e.getText()==="defineNotify";for(const t of s.getDeclarations())if(r.isImportSpecifier(t))return R.has(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineNotify":!1;return!1},E=(e,s=new Set)=>{const t=D(e);if(!t)return;if(!r.isIdentifier(t))return t;const i=t.getSymbol();if(!i?.isAlias())return t;const n=i.getAliasedSymbol();if(!n)return t;const o=n.getDeclarations().find(a=>r.isExportAssignment(a));if(!o)return t;const c=o.getSourceFile();if(!s.has(c.getFilePath()))return E(c,s.add(c.getFilePath()))},V=new Set(["%=","&&=","&=","**=","+=","-=","/=","<<=","=",">>=",">>>=","??=","^=","|=","||="]),p=e=>{const s=e.getSymbol();return s?.getAliasedSymbol()?.getDeclarations()[0]??s?.getDeclarations()[0]},P=e=>{if(r.isIdentifier(e))return e;if(r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e))return P(e.getExpression())},d=(e,s)=>{const t=P(e);return t!==void 0&&p(t)===s},j=(e,s)=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return!1;const i=t.getName(),n=t.getExpression(),o=r.isIdentifier(n)?n.getText():"";if(!((i==="assign"||i==="defineProperty"||i==="defineProperties")&&o==="Object"||i==="set"&&o==="Reflect"))return!1;const a=e.getArguments()[0];return a!==void 0&&r.isIdentifier(a)&&p(a)===s},z=(e,s)=>{if(r.isBinaryExpression(e))return V.has(e.getOperatorToken().getText())&&d(e.getLeft(),s);if(r.isDeleteExpression(e))return d(e.getExpression(),s);if(r.isPrefixUnaryExpression(e)||r.isPostfixUnaryExpression(e)){const t=e.getOperatorToken();return(t===u.PlusPlusToken||t===u.MinusMinusToken)&&d(e.getOperand(),s)}return r.isCallExpression(e)?j(e,s):!1},H=(e,s)=>{const t=p(e);return t===void 0?!0:s.some(i=>i.getDescendants().some(n=>z(n,t)))},W=e=>{if(r.isObjectLiteralExpression(e))return e;if(!r.isIdentifier(e))return;const s=e.getSymbol(),t=s?.getAliasedSymbol()?.getDeclarations()??s?.getDeclarations()??[];for(const i of t){if(!r.isVariableDeclaration(i))continue;const n=i.getInitializer();if(!n||!r.isObjectLiteralExpression(n))continue;const o=i.getParent();if(!r.isVariableDeclarationList(o)||o.getDeclarationKind()!==F.Const)continue;const c=[i.getSourceFile(),e.getSourceFile()].filter((a,f,S)=>S.findIndex(b=>b.getFilePath()===a.getFilePath())===f);if(!H(e,c))return n}},Y=(e,s)=>{const t=N(s,k);if(!v(t))return;const i=e.getSourceFile(t)??e.addSourceFileAtPath(t),n=E(i);if(!n||!r.isCallExpression(n))return{hasFcm:!0,hasWebPush:!0};const o=n.getExpression(),c=r.isIdentifier(o)&&U(o)?n.getArguments()[0]:void 0,a=c===void 0?void 0:W(c);return!a||a.getProperties().some(f=>r.isSpreadAssignment(f))?{hasFcm:!0,hasWebPush:!0}:{hasFcm:g(a,"fcm")!==void 0,hasWebPush:g(a,"webPush")!==void 0}},ee=(e,s)=>{const t=Y(e,s);return t===void 0?void 0:{...t,usesPush:K(e,s)}};export{k as NOTIFY_FILENAME,Z as discoverNotifyCalls,Y as discoverNotifyChannels,ee as discoverNotifyConfig};
1
+ import{existsSync as v}from"node:fs";import{join as N}from"node:path";import{SyntaxKind as u,Node as r,VariableDeclarationKind as F}from"ts-morph";import{listLunoraSourceFiles as m,lunoraRelativePath as O,findObjectProperty as g,defaultExportExpression as D,handlerOf as A}from"./isTestPath-B81lOULB.mjs";import{b as I,d as T}from"./attribution-hVBriwzy.mjs";import{i as l}from"./context-root-lGZCyHyj.mjs";import{c as C}from"./classify-procedure-call-BAj0D1u2.mjs";const k="notify.ts",L=new Set(["chat","inApp","send","webhook"]),h=new Set(["broadcast","send"]),M=e=>{const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const t=C(s);if(!t)return;const i=A(s,t.receiver);return i?{exportName:T(e)??e.getName(),handler:i,kind:t.kind}:void 0},x=e=>{const s=[];for(const t of I(e)){const i=M(t);i&&s.push(i)}return s},y=e=>l(e,["notify"])?"notify":l(e,["push"])||l(e,["notify","push"])?"push":void 0,w=e=>{if(!r.isPropertyAccessExpression(e))return;const s=e.getName(),t=y(e.getExpression());if(t==="notify"&&L.has(s))return`ctx.notify.${s}`;if(t==="push"&&h.has(s))return`ctx.push.${s}`},_=e=>r.isPropertyAccessExpression(e)?y(e.getExpression())==="push"&&h.has(e.getName()):!1,Z=(e,s)=>{const t=[];for(const i of m(s)){const n=e.getSourceFile(i)??e.addSourceFileAtPath(i),o=O(s,i);for(const c of x(n))if(!(c.kind!=="query"&&c.kind!=="mutation"))for(const a of c.handler.getDescendantsOfKind(u.PropertyAccessExpression)){const f=w(a);f!==void 0&&t.push({callee:f,exportName:c.exportName,file:o,kind:c.kind,line:a.getStartLineNumber()})}}return t},K=(e,s)=>{for(const t of m(s)){const i=e.getSourceFile(t)??e.addSourceFileAtPath(t);for(const n of x(i))for(const o of n.handler.getDescendantsOfKind(u.PropertyAccessExpression))if(_(o))return!0}return!1},R=new Set(["@lunora/notify"]),U=e=>{const s=e.getSymbol();if(!s)return e.getText()==="defineNotify";for(const t of s.getDeclarations())if(r.isImportSpecifier(t))return R.has(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineNotify":!1;return!1},E=(e,s=new Set)=>{const t=D(e);if(!t)return;if(!r.isIdentifier(t))return t;const i=t.getSymbol();if(!i?.isAlias())return t;const n=i.getAliasedSymbol();if(!n)return t;const o=n.getDeclarations().find(a=>r.isExportAssignment(a));if(!o)return t;const c=o.getSourceFile();if(!s.has(c.getFilePath()))return E(c,s.add(c.getFilePath()))},V=new Set(["%=","&&=","&=","**=","+=","-=","/=","<<=","=",">>=",">>>=","??=","^=","|=","||="]),p=e=>{const s=e.getSymbol();return s?.getAliasedSymbol()?.getDeclarations()[0]??s?.getDeclarations()[0]},P=e=>{if(r.isIdentifier(e))return e;if(r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e))return P(e.getExpression())},d=(e,s)=>{const t=P(e);return t!==void 0&&p(t)===s},j=(e,s)=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return!1;const i=t.getName(),n=t.getExpression(),o=r.isIdentifier(n)?n.getText():"";if(!((i==="assign"||i==="defineProperty"||i==="defineProperties")&&o==="Object"||i==="set"&&o==="Reflect"))return!1;const a=e.getArguments()[0];return a!==void 0&&r.isIdentifier(a)&&p(a)===s},z=(e,s)=>{if(r.isBinaryExpression(e))return V.has(e.getOperatorToken().getText())&&d(e.getLeft(),s);if(r.isDeleteExpression(e))return d(e.getExpression(),s);if(r.isPrefixUnaryExpression(e)||r.isPostfixUnaryExpression(e)){const t=e.getOperatorToken();return(t===u.PlusPlusToken||t===u.MinusMinusToken)&&d(e.getOperand(),s)}return r.isCallExpression(e)?j(e,s):!1},H=(e,s)=>{const t=p(e);return t===void 0?!0:s.some(i=>i.getDescendants().some(n=>z(n,t)))},W=e=>{if(r.isObjectLiteralExpression(e))return e;if(!r.isIdentifier(e))return;const s=e.getSymbol(),t=s?.getAliasedSymbol()?.getDeclarations()??s?.getDeclarations()??[];for(const i of t){if(!r.isVariableDeclaration(i))continue;const n=i.getInitializer();if(!n||!r.isObjectLiteralExpression(n))continue;const o=i.getParent();if(!r.isVariableDeclarationList(o)||o.getDeclarationKind()!==F.Const)continue;const c=[i.getSourceFile(),e.getSourceFile()].filter((a,f,S)=>S.findIndex(b=>b.getFilePath()===a.getFilePath())===f);if(!H(e,c))return n}},Y=(e,s)=>{const t=N(s,k);if(!v(t))return;const i=e.getSourceFile(t)??e.addSourceFileAtPath(t),n=E(i);if(!n||!r.isCallExpression(n))return{hasFcm:!0,hasWebPush:!0};const o=n.getExpression(),c=r.isIdentifier(o)&&U(o)?n.getArguments()[0]:void 0,a=c===void 0?void 0:W(c);return!a||a.getProperties().some(f=>r.isSpreadAssignment(f))?{hasFcm:!0,hasWebPush:!0}:{hasFcm:g(a,"fcm")!==void 0,hasWebPush:g(a,"webPush")!==void 0}},ee=(e,s)=>{const t=Y(e,s);return t===void 0?void 0:{...t,usesPush:K(e,s)}};export{k as NOTIFY_FILENAME,Z as discoverNotifyCalls,Y as discoverNotifyChannels,ee as discoverNotifyConfig};
@@ -1,4 +1,4 @@
1
- import{existsSync as F,mkdirSync as un,readFileSync as Vi,writeFileSync as Ui,rmSync as xt,readdirSync as qi}from"node:fs";import{dirname as fn,join as E,relative as Wi}from"node:path";import{performance as ct}from"node:perf_hooks";import{runAdvisor as Hi}from"@lunora/advisor";import{LunoraError as q}from"@lunora/errors";import{serializeSchemaSnapshot as ji}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{toAdvisorContext as Gi}from"./formatAdvisories-BCVASH7N.mjs";import{Node as r,SyntaxKind as d,ts as Yi,VariableDeclarationKind as Qi}from"ts-morph";import{listLunoraSourceFiles as A,lunoraRelativePath as I,bindingKeyName as se,collectCallRows as C,findObjectProperty as M,collectSecurityCallRows as Xi,propertyInitializer as T,listSecurityScanFiles as Ue,objectLiteralFromCallbackBody as gn,limitNameOf as pn,optionsObjectLiteral as mn,handlerOf as Ji,collectNodeRows as Z,chainRootOf as Lt,outermostValueWrapper as w,isWriteTarget as qe,isSameNode as S,unwrapExpression as h,isConstDeclaration as ee,memberAccessOf as hn,returningFunctionOf as St,walkChain as Zi,RUN_METHODS as vn,functionReferenceSegments as er,isTestPath as tr,isFunctionLike as te,functionKeyOf as En}from"./isTestPath-B81lOULB.mjs";import{b as j,d as V,f as O,g as Dt,c as v,a as xn,w as Mt,k as sr,l as nr,h as ir,m as rr,j as At,i as or}from"./attribution-hVBriwzy.mjs";import{a as xs,r as lt,i as W,b as ar,m as Sn,c as We,e as _t,E as An,C as yn,d as cr,f as lr,g as dr}from"./context-root-LyOsqj_o.mjs";import{a as b,i as ur,c as X,d as bn,e as fr,f as gr}from"./classify-procedure-call-BAj0D1u2.mjs";import{a as y,r as Nn,s as pr,b as mr}from"./project-config-file-BV7RR-l6.mjs";import{a as hr,b as He}from"./module-specifiers-WF8iAydP.mjs";import{r as je,s as vr}from"./parse-validator-IDBKIT7M.mjs";import Er from"./discoverAuthApiCalls-xs0ONfI-.mjs";import{i as L,r as Pn}from"./database-calls-BPpefKqO.mjs";import xr from"./discoverHyperdriveCalls-CwnXgjFJ.mjs";import{diagnosticAt as ye}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{m as Kt,a as Me,s as wn,d as Sr}from"./index-CkS96b8a.mjs";import{MUTATORS_FILENAME as Ar,isDefineMutatorCallee as yr,mutatorServerImplOf as br,discoverMutators as Nr}from"./MUTATORS_FILENAME-qVDmv8st.mjs";import Pr from"./discoverNondeterministicCalls-9ZDpRptb.mjs";import{discoverNotifyConfig as wr,discoverNotifyCalls as Ir}from"./NOTIFY_FILENAME-CLoeWMb5.mjs";import Cr from"./discoverR2sqlCalls-XBhs4XRZ.mjs";import Tr from"./discoverRlsProcedures-TskedRMh.mjs";import{s as Bt,n as Or}from"./dispatch-namespace-DwTjD7BU.mjs";import{secretKindOf as kr,redact as Rr,isHeuristicSecretKind as Fr,isSecretishName as Lr}from"./redact-Cy14LEnc.mjs";import{a as Oe,d as Dr,r as Mr}from"./modules-CjOcuQnK.mjs";import{WORKFLOWS_FILENAME as _r,discoverWorkflows as Kr}from"./WORKFLOWS_FILENAME-CdeS224T.mjs";import{r as Br}from"./json-data-Chfs2Cz5.mjs";import{G as zr}from"./shared-DnCokNcE.mjs";import{createCodegenProject as $r}from"./createCodegenProject-V51_yBw3.mjs";import{findTsconfig as Nv,refreshCodegenProject as Pv}from"./createCodegenProject-V51_yBw3.mjs";import{CAPABILITIES as Vr,usedCapabilities as Ur}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{isD1GlobalTable as In,isHyperdriveGlobalTable as Cn}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as qr}from"./AGENTS_FILENAME-B6-kjzM3.mjs";import{discoverContainers as Wr}from"./CONTAINERS_FILENAME-dFRtAyIe.mjs";import Hr from"./discoverCrons-DBnCama4.mjs";import{contextPropertiesRead as jr,discoverFeatureUsage as Gr}from"./capabilitiesUsedBy-QgSZyE0T.mjs";import Tn from"./readPackageDependencies-RHhGiz0k.mjs";import{discoverQueueDeclarations as Yr}from"./QUEUES_FILENAME-CsRy4VTF.mjs";import{discoverSandboxUsage as Qr}from"./discoverSandboxUsage-w6Q3RvxZ.mjs";import{resolveServiceBindings as Xr}from"./readServiceBindings-DvqIThzd.mjs";import Jr from"./discoverStorageRulesMetadata-BPJplDfz.mjs";import{resolveCodegenTarget as On,gatePlatformFeatures as Zr,readTargetDiagnostics as eo,vectorizeDimensionDiagnostics as to,studioPlatformFor as so}from"./DEFAULT_TARGET-BnQiNNKu.mjs";import{i as no}from"./schema-BgM8A3XV.mjs";import{b as kn,e as io}from"./shard-Av4rUyYS.mjs";import{e as ro,a as oo}from"./server-DAvi_bv_.mjs";import{emitDataModel as ao}from"./emitDataModel-BskFt9Wv.mjs";import{i as co,a as lo,e as uo,b as fo,d as go,c as po}from"./unwrap-handler-return-CJrkfrSH.mjs";import mo from"./discoverFunctions-CbxZGGj0.mjs";import ho from"./discoverHttpRoutes-DgfoyNcf.mjs";import vo from"./discoverInserts-mHOX_dJR.mjs";import{e as Rn}from"./exported-procedure-chains-DKK5HoK3.mjs";import Eo from"./discoverMigrations-C9mLIhGZ.mjs";import xo from"./discoverQueries-CfxkjP5X.mjs";import So from"./discoverRlsMetadata-Cb8JR1b4.mjs";import Ao from"./discoverSchema-BtsX-CN9.mjs";import{discoverShapes as yo}from"./SHAPES_FILENAME-DkBUN9dK.mjs";import{i as bo}from"./reserved-words-CW1QFbTd.mjs";import{emitApp as No}from"./emitApp-BOUdd-2R.mjs";import{readJsonSync as Po}from"@visulima/fs";import{buildSchemaSnapshot as wo}from"./SchemaSnapshotParseError-BRJT7c2k.mjs";import{buildOpenApiDocument as Io,emitOpenApiModule as Co}from"./buildOpenApiDocument-DFv-RYZU.mjs";import{buildOpenRpcDocument as To,emitOpenRpcModule as Oo}from"./OPENRPC_VERSION-CCY7xqSL.mjs";import{v as ko,t as Ro,u as Fo,s as Lo,w as Do}from"./shard-runtime-CkTgY8tL.mjs";import{emitCollections as Mo,emitSeed as _o,emitApi as Ko,emitInternalApi as Bo}from"./emitApi-Zx6VPN-7.mjs";import{emitCrons as zo,emitScheduler as $o,emitShardRegistry as Vo,emitDurableObjects as Uo,emitVectors as qo,emitWranglerCronTriggers as Wo}from"./emitCrons-BQW2lviZ.mjs";import Ho from"./emitDrizzleSchema-DitcRZ1a.mjs";import jo from"./emitFunctions-BeKgL3dl.mjs";const Fn=new Set(["delete","get","head","options","patch","post","put"]),Go=new Set(["handler","stream"]),Yo=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,Ss=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Qo=e=>{if(!r.isCallExpression(e))return;const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!Fn.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()}},Xo=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)||Fn.has(n.getName()))break;s=n.getExpression()}return Qo(s)},Jo=e=>{for(const t of e.getDescendantsOfKind(d.PropertyAccessExpression))if(Ss.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=t.getExpression();if(r.isIdentifier(s)&&Ss.has(s.getText()))return!0}return!1},Zo=(e,t)=>{const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const n=s.getExpression();if(!r.isPropertyAccessExpression(n)||!Go.has(n.getName()))return;const i=Xo(s);if(!i||!Yo.test(i.path))return;const o=s.getArguments()[0],a=o!==void 0&&(r.isArrowFunction(o)||r.isFunctionExpression(o))&&Jo(o);return{exportName:V(e)??e.getName(),file:t,method:i.method,path:i.path,usesGuard:a}},ea=(e,t)=>{const s=[];for(const n of j(e)){const i=Zo(n,t);i&&s.push(i)}return s},ta=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ea(i,I(t,n)))}return s},sa=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}},na=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)?se(t):void 0}},ia=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))&&xs(a)}))return!1;const n=O(e),i=r.isParameterDeclaration(n)?n:n?.getFirstAncestorByKind(d.Parameter);return i!==void 0&&(r.isParameterDeclaration(n)||r.isBindingElement(n))&&xs(i)},As=(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=sa(e);return n!==void 0&&na(n)===t?!0:t==="args"&&ia(e)},Ln=(e,t)=>r.isIdentifier(e)?As(e,t):e.getDescendantsOfKind(d.Identifier).some(s=>As(s,t)),ra=e=>{let t=e;for(;r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t)||r.isNonNullExpression(t);)t=t.getExpression();return r.isIdentifier(t)?t:void 0},ys=e=>{const t=r.isIdentifier(e)?O(e):void 0;return r.isVariableDeclaration(t)&&r.isIdentifier(t.getNameNode())&&!Dt(t)?t.getInitializer():void 0},yt=e=>Ln(e,"args"),H=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},$=e=>{if(yt(e))return!0;const t=H(e);return t!==void 0&&yt(t)},oa=e=>{if(r.isCallExpression(e)||r.isNewExpression(e))return!1;const t=H(e);return t===void 0||!(r.isCallExpression(t)||r.isNewExpression(t))},ne=e=>{if(lt(e))return!0;const t=ys(e);if(t!==void 0&&lt(t))return!0;const s=t??e;return(r.isIdentifier(s)?[s]:s.getDescendantsOfKind(d.Identifier)).some(i=>{const o=ys(i);return o!==void 0&&lt(o)})},ke=(e,t)=>Ln(e,t),aa=(e,t)=>{if(ke(e,t))return!0;const s=H(e);if(s!==void 0&&ke(s,t))return!0;const n=ra(e);if(n!==void 0){const i=H(n);return i!==void 0&&ke(i,t)}return!1},ca=e=>!r.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:W(e.getExpression(),["ai"]),la=(e,t)=>{if(!ca(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!$(s)||ne(s)))return{scope:v(e),file:t,line:e.getStartLineNumber()}},da=(e,t)=>C(e,t,la),ua=new Set(["generateText","streamText"]),fa=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"]}],pa=(e,t)=>ga.some(s=>s.methods.has(t)&&s.prefixes.some(n=>e===n||e.startsWith(`${n}.`))),ma=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return;const s=t.getName(),n=[ar(t.getExpression()),t.getExpression().getText()].find(i=>i!==void 0&&pa(i,s));return n===void 0?void 0:`${n}.${s}`},ha=e=>{for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=ma(t);if(s!==void 0)return s}},va=e=>{const t=new Set,s=e.getFirstAncestor(o=>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=se(o),c=o.getNameNode();if(a==="args"&&r.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},Ea=e=>{if(yt(e))return!0;const t=va(e);return t.size===0?!1:e.getDescendantsOfKind(d.Identifier).some(s=>t.has(s.getText()))},xa=e=>{for(const t of e.getProperties()){if(!r.isPropertyAssignment(t)||!fa.has(y(t)))continue;const s=t.getInitializer();if(s!==void 0&&Ea(s))return!0}return!1},Sa=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=b(n.getExpression());if(i===void 0||!ua.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(b(c.getExpression())==="tool"&&(a=ha(c),a!==void 0))break;a!==void 0&&s.push({scope:v(n),file:t,line:n.getStartLineNumber(),method:i,sideEffect:a,userInputDerived:xa(o)})}return s},Aa=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Sa(i,I(t,n)))}return s},ya=e=>W(e,["fetch"]),ba=(e,t)=>{if(!ya(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!$(s)))return{scope:v(e),file:t,line:e.getStartLineNumber()}},Na=(e,t)=>C(e,t,ba),zt=(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=je(s.getExpression());return n===void 0||zt(n,t)})}finally{t.delete(e)}},Pa=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=M(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:je(n);return i===void 0?{objects:[],opaque:!0}:{objects:[i],opaque:zt(i)}},wa=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)?je(o):void 0;a===void 0?s=!0:(t.push(a),s||=zt(a))}n=i.getExpression()}return{objects:t,opaque:s}},$t=(e,t)=>t?wa(t):Pa(e),Dn=(e,t)=>{if(t.has(e))return[];t.add(e);try{return e.getProperties().flatMap(s=>{if(r.isSpreadAssignment(s)){const n=je(s.getExpression());return n===void 0?[]:Dn(n,t)}return r.isPropertyAssignment(s)||r.isShorthandPropertyAssignment(s)?[y(s)]:[]})}finally{t.delete(e)}},Ia=e=>e.flatMap(t=>Dn(t,new Set)),Ca=new Set(["check","length","max"]),bt=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(Ca.has(s.getName()))return!0;t=n}},Nt=e=>hr(e)||e==="@lunora/values",Ta=e=>{const t=new Set(["v"]);for(const s of ur(e,"v",Nt))t.add(s);for(const s of e.getImportDeclarations()){const n=s.getNamespaceImport();n&&Nt(s.getModuleSpecifierValue())&&t.add(`${n.getText()}.v`)}return t},Oa=(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},ka=e=>(e.getSymbol()?.getDeclarations()??[]).some(t=>!t.getSourceFile().isDeclarationFile()&&!r.isImportSpecifier(t)&&!r.isNamespaceImport(t)&&!r.isImportClause(t)),Ra=e=>(e.getSymbol()?.getDeclarations()??[]).some(t=>r.isNamespaceImport(t)&&Nt(t.getFirstAncestorByKindOrThrow(d.ImportDeclaration).getModuleSpecifierValue())),Vt=(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 ka(n)?void 0:s.getName();const i=r.isPropertyAccessExpression(n)?n.getExpression():void 0;return r.isIdentifier(i)&&Ra(i)?s.getName():void 0}if(r.isIdentifier(s))return t.destructured.get(s.getText())},Fa=(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)},La=e=>{let t=e.getParent();for(;t&&!r.isFunctionLikeDeclaration(t);)t=t.getParent();return t},Da=e=>r.isReturnStatement(e)?e.getExpression():void 0,Ma=e=>r.isArrowFunction(e)&&!r.isBlock(e.getBody())?[e.getBody()]:e.getDescendantsOfKind(d.ReturnStatement).filter(t=>La(t)?.compilerNode===e.compilerNode).flatMap(t=>{const s=Da(t);return s?[s]:[]}),Mn=(e,t)=>{if(Vt(e,t)!==void 0)return e;if(r.isCallExpression(e)||r.isPropertyAccessExpression(e))return Mn(e.getExpression(),t)},_a=(e,t)=>{const s=Fa(e.getExpression(),e.getSourceFile());if(!s)return[];const n=bt(e),i=new Set(Ma(s).map(o=>Mn(o,t)).filter(o=>o!==void 0));return[s,...s.getDescendants()].flatMap(o=>{const a=Vt(o,t);return a===void 0?[]:[{bounded:bt(o)||n&&i.has(o),factory:a}]})},Ka=(e,t)=>[e,...e.getDescendants()].flatMap(s=>{const n=Vt(s,t),i=n===void 0?[]:[{bounded:bt(s),factory:n}];return r.isCallExpression(s)?[...i,..._a(s,t)]:i}),Ba=(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=Ka(a,t),l=y(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}},za=(e,t,s)=>{const n=e.getInitializer();if(!n||!r.isCallExpression(n))return;const i=X(n);if(i?.visibility!=="public")return;const{objects:o}=$t(n,i.receiver),{anyArgs:a,unboundedStringArgs:c}=Ba(o,s);if(!(a.length===0&&c.length===0))return{anyArgs:a,exportName:V(e)??e.getName(),file:t,line:n.getStartLineNumber(),unboundedStringArgs:c}},$a=(e,t)=>{const s=[],n=Ta(e),i={destructured:Oa(e,n),namespaces:n};for(const o of j(e)){const a=za(o,t,i);a&&s.push(a)}return s},Va=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...$a(i,I(t,n)))}return s},dt=e=>e?.getKind()===d.TrueKeyword,Ua=e=>e?.getKind()===d.FalseKeyword,qa=e=>e!==void 0&&r.isNumericLiteral(e)&&e.getLiteralValue()===0,Wa=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Ha=e=>!e||!r.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>r.isCallExpression(t)&&b(t.getExpression())==="scim"),ja=e=>e!==void 0&&r.isCallExpression(e)&&Wa.has(b(e.getExpression())??""),Ga=e=>!e||!r.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>r.isStringLiteral(t)&&t.getLiteralText()==="*"),Ya=e=>{const t=T(e,"advanced"),s=T(e,"emailAndPassword"),n=T(e,"session");return{analyzable:!0,disableCsrfCheck:dt(T(t,"disableCSRFCheck")),emailPasswordEnabled:dt(T(s,"enabled")),requireEmailVerification:dt(T(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Ha(T(e,"plugins"))&&ja(T(e,"database")),secureCookiesDisabled:Ua(T(t,"useSecureCookies")),sessionFreshAgeZero:qa(T(n,"freshAge")),trustedOriginsWildcard:Ga(T(e,"trustedOrigins"))}},Qa=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Xa=(e,t)=>{if(b(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?Ya(s):Qa();return{scope:v(e),file:t,line:e.getStartLineNumber(),...i}},Ja=(e,t)=>Xi(e,t,Xa),Za=(e,t)=>{if(!r.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return Sn(e.getExpression(),t.matchReceiver)?s:void 0},ec=(e,t,s)=>{const n=Za(e.getExpression(),s);if(n===void 0)return;const i=e.getArguments()[s.argIndex];if(!(!i||!$(i)||ne(i))&&!(s.requireUnmodifiedReach===!0&&!oa(i)))return{scope:v(e),file:t,line:e.getStartLineNumber(),method:n}},Ge=(e,t,s)=>C(e,t,(n,i)=>ec(n,i,s)),tc=new Set(["content","pdf","scrape","screenshot"]),sc=(e,t)=>Ge(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:tc}),nc=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),ic=new Set(["RateLimiter"]),rc=new Set(["extend"]),bs="lunora",oc=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],_n=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=y(i);t.push(o),i.getInitializer()?.getKind()===d.TrueKeyword&&s.push(o);continue}(r.isShorthandPropertyAssignment(i)||r.isMethodDeclaration(i))&&t.push(y(i))}return{analyzable:!n,presentKeys:t,trueKeys:s}},Pt=e=>e&&r.isObjectLiteralExpression(e)?_n(e):{analyzable:!1,presentKeys:[],trueKeys:[]},ac=e=>{const t=e&&(r.isArrowFunction(e)||r.isFunctionExpression(e))?e:void 0,s=t&&gn(t.getBody());return s?_n(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},cc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=b(n.getExpression());i!==void 0&&(nc.has(i)?s.push({callee:i,file:t,line:n.getStartLineNumber(),...Pt(n.getArguments()[0])}):rc.has(i)&&s.push({callee:i,file:t,line:n.getStartLineNumber(),...ac(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(d.NewExpression)){const i=b(n.getExpression());i===void 0||!ic.has(i)||s.push({callee:i,file:t,line:n.getStartLineNumber(),...Pt(n.getArguments()[0])})}return s},lc=(e,t)=>{for(const s of oc){const n=E(t,s);if(!F(n))continue;const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=[];for(const a of i.getDescendantsOfKind(d.CallExpression))b(a.getExpression())===bs&&o.push({callee:bs,file:s,line:a.getStartLineNumber(),...Pt(a.getArguments()[0])});return o}return[]},dc=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of Ue(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);s.push(...cc(o,n))}return s.push(...lc(e,fn(t))),s},Ns="ctx.containers.",uc=e=>{if(!e.startsWith(Ns))return!1;const t=e.slice(Ns.length);return t.length>0&&!t.includes(".")},fc=(e,t)=>Ge(e,t,{argIndex:0,matchReceiver:uc,methods:new Set(["get"])}),gc=new Set(["allow","deny","setAllowed"]),pc=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return!1;const s=M(t,"enableInternet");return s!==void 0&&r.isPropertyAssignment(s)&&r.isTrueLiteral(s.getInitializerOrThrow())},mc=(e,t)=>{const s=e.getExpression();if(!(!r.isPropertyAccessExpression(s)||s.getName()!=="start"||!pc(e)))return{detail:"enableInternet: true",scope:v(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},hc=(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:v(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},vc=(e,t)=>mc(e,t)??hc(e,t),Ec=(e,t)=>C(e,t,vc),xc=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="count")return;const s=t.getExpression();if(L(s)){const n=e.getArguments()[0];return n&&r.isStringLiteral(n)?n.getLiteralText():""}return r.isPropertyAccessExpression(s)&&L(s.getExpression())?s.getName():void 0},Sc=e=>{const t=e.getExpression(),s=r.isPropertyAccessExpression(t)?t.getExpression():void 0;return e.getArguments()[s!==void 0&&L(s)?1:0]},Ac=new Set(["baseWhere","relationBaseWhere","restrictsCounts","where"]),yc=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=>Ac.has(n))||t.some(n=>n==="AND"||n==="OR"||n==="NOT")?void 0:t},bc=(e,t,s)=>{const n=new Map(s.map(i=>[i.name,i.aggregateIndexed===!0]));return C(e,t,(i,o)=>{const a=xc(i);if(a===void 0)return;const c=yc(Sc(i));return{file:o,indexed:n.get(a)!==!1,...c===void 0?{}:{filterFields:c},line:i.getStartLineNumber(),scope:v(i),table:a}})},Nc=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Pc=e=>{const t=e.getExpression();if(!r.isIdentifier(t))return;const s=t.getText();return Nc.has(s)?s:void 0},wc=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=y(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(y(n))}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Ic=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of Ue(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);for(const a of o.getDescendantsOfKind(d.CallExpression)){const c=Pc(a);if(c===void 0)continue;const l=a.getArguments()[0],u=l&&r.isObjectLiteralExpression(l)?wc(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},Cc=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Tc=new Set(["dbRateLimit","rateLimit"]),Oc=e=>{const t=mn(e);if(!t)return!1;const s=M(t,"failOpen");return s!==void 0&&r.isPropertyAssignment(s)&&s.getInitializer()?.getKind()===d.TrueKeyword},kc=(e,t)=>{const s=b(e.getExpression());if(s===void 0)return;const n=Cc.get(s);if(n!==void 0)return{callee:s,scope:v(e),failOpen:Oc(e.getArguments()[n]),file:t,limitName:Tc.has(s)?pn(e):"",line:e.getStartLineNumber()}},Rc=(e,t)=>C(e,t,kc),Fc=e=>{const t=e.getInitializer();if(!t||!r.isCallExpression(t))return;const s=X(t);if(s?.kind!=="query")return;const n=Ji(t,s.receiver);return n?{exportName:V(e)??e.getName(),handler:n}:void 0},Ps=e=>{const t=e.getParent();return t&&r.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},Lc=e=>{const t=Ps(e);if(!t)return"ctx.flags";if(t.getName()==="details"){const s=Ps(t);return s?`ctx.flags.details.${s.getName()}`:"ctx.flags.details"}return`ctx.flags.${t.getName()}`},Dc=(e,t)=>{const s=[];for(const n of We(e.handler,"flags"))s.push({callee:Lc(n),exportName:e.exportName,file:t,line:n.getStartLineNumber()});return s},Mc=(e,t)=>{const s=[];for(const n of j(e)){const i=Fc(n);i&&s.push(...Dc(i,t))}return s},_c=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Mc(i,I(t,n)))}return s},Kc=e=>!r.isPropertyAccessExpression(e)||e.getName()!=="boolean"?!1:W(e.getExpression(),["flags"]),Bc=e=>{if(e?.getKind()===d.TrueKeyword)return!0;if(e?.getKind()===d.FalseKeyword)return!1},zc=(e,t)=>{if(!Kc(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(r.isStringLiteral(s)||r.isNoSubstitutionTemplateLiteral(s)))return;const i=s.getLiteralValue(),o=Bc(n);if(!(i.length===0||o===void 0))return{defaultValue:o,scope:v(e),file:t,key:i,line:e.getStartLineNumber()}},$c=(e,t)=>C(e,t,zc),Vc=e=>{const t=e.getExpression();return r.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Uc=e=>{const t=e.getArguments()[0];return t&&r.isStringLiteral(t)?t.getLiteralText():""},qc=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=I(t,n);for(const a of i.getDescendantsOfKind(d.CallExpression))Vc(a)&&s.push({file:o,indexName:Uc(a),line:a.getStartLineNumber()})}return s},xe=e=>e!==void 0&&(r.isArrowFunction(e)||r.isFunctionExpression(e))?e:void 0,Kn=e=>{const t=e.getArguments()[0],s=xe(t);if(s!==void 0)return s;if(t===void 0||!r.isObjectLiteralExpression(t))return;const n=M(t,"handler");return n!==void 0&&r.isPropertyAssignment(n)?xe(n.getInitializer()):void 0},Wc=new Set(["delete","get","head","options","patch","post","put"]),Hc=new Set(["handler","stream"]),jc=new Set(["runAction","runMutation"]),Gc=new Set(["delete","insert","insertManyUnsafe","patch","patchIf","replace"]),Se=(e,t)=>e!==void 0&&r.isIdentifier(e)&&e.getText()===t,Bn=(e,t)=>{if(!(e===void 0||!r.isObjectBindingPattern(e))){for(const s of e.getElements())if(se(s)===t){const i=s.getNameNode();return r.isIdentifier(i)?i.getText():void 0}}},ws=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?r.isIdentifier(s)?s.getText():void 0:Bn(s,"ctx")},Is=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&r.isIdentifier(s)?s.getText():void 0:Bn(s,"request")},Cs=(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(jc.has(a)&&Se(c,t))return a;if(Gc.has(a)&&r.isPropertyAccessExpression(c)&&c.getName()==="db"&&Se(c.getExpression(),t))return`db.${a}`}},Ts=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(d.PropertyAccessExpression))if(n.getName()==="auth"&&Se(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(d.VariableDeclaration)){const i=n.getNameNode();if(!(!r.isObjectBindingPattern(i)||!Se(n.getInitializer(),t))){for(const o of i.getElements())if(se(o)==="auth")return!0}}return!1},Yc=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,Qc=(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"&&Se(n.getExpression(),t)},Xc=e=>[...r.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(d.StringLiteral).map(t=>t.getLiteralText())],zn=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:Xc(s)},Jc=(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)?zn(t,a.getText()):[]}return[]},Zc=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=zn(s,t.getText());return n.length>0?n:Jc(t,s)},Os=(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=>Qc(i,t)&&Zc(i).some(o=>Yc.test(o)))},el=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!Hc.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(Wc.has(i)){const o=n.getExpression();return r.isIdentifier(o)&&o.getText()==="httpRoute"?i.toUpperCase():void 0}s=n.getExpression()}},tl=(e,t)=>{const s=e.getExpression();if(r.isIdentifier(s)&&s.getText()==="httpAction"){const c=xe(e.getArguments()[0]),l=c&&ws(c,!0);if(!c||l===void 0||Os(c,Is(c,!0)))return;const u=Cs(c,l);return u===void 0?void 0:{scope:v(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:Ts(c,l),sideEffect:u}}const n=el(e);if(n===void 0)return;const i=xe(e.getArguments()[0]),o=i&&ws(i,!1);if(!i||o===void 0||Os(i,Is(i,!1)))return;const a=Cs(i,o);return a===void 0?void 0:{scope:v(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:Ts(i,o),sideEffect:a}},sl=(e,t)=>C(e,t,tl),nl=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),il=new Set(["append","set"]),$n=e=>e!==void 0&&(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",ks=(e,t)=>(r.isCallExpression(e)?[e,...e.getDescendantsOfKind(d.CallExpression)]:e.getDescendantsOfKind(d.CallExpression)).some(n=>nl.has(b(n.getExpression())??"")&&ke(n,t)),rl=(e,t)=>{if(ks(e,t))return!0;const s=H(e);return s!==void 0&&ks(s,t)},wt=(e,t)=>aa(e,t)&&!rl(e,t),ol=e=>{if(r.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=H(e);return t!==void 0&&r.isNewExpression(t)&&b(t.getExpression())==="Headers"},_e=e=>{if(e===void 0)return;if(r.isObjectLiteralExpression(e))return e;const t=H(e);return t!==void 0&&r.isObjectLiteralExpression(t)?t:void 0},Ut=(e,t,s)=>{for(const n of e.getProperties())if(r.isPropertyAssignment(n)){const i=n.getInitializer();i!==void 0&&wt(i,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:$n(n.getNameNode()),line:i.getStartLineNumber(),via:t})}else if(r.isShorthandPropertyAssignment(n)){const i=n.getNameNode();wt(i,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:y(n),line:i.getStartLineNumber(),via:t})}else if(r.isSpreadAssignment(n)){const i=_e(n.getExpression());i!==void 0&&Ut(i,t,s)}},Vn=(e,t)=>{const s=_e(e);if(s===void 0)return;const n=M(s,"headers");if(n===void 0||!r.isPropertyAssignment(n))return;const i=_e(n.getInitializer());i!==void 0&&Ut(i,"response-init",t)},al=(e,t)=>{const s=b(e.getExpression());if(s==="Response")Vn(e.getArguments()[1],t);else if(s==="Headers"){const n=_e(e.getArguments()[0]);n!==void 0&&Ut(n,"headers-ctor",t)}},cl=(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"){Vn(e.getArguments()[1],t);return}if(il.has(n)&&ol(i)){const o=e.getArguments()[1];o!==void 0&&wt(o,t.requestName)&&t.rows.push({scope:t.scope,file:t.relativePath,headerName:$n(e.getArguments()[0]),line:o.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},ll=(e,t)=>{for(const s of e.getDescendantsOfKind(d.NewExpression))al(s,t);for(const s of e.getDescendantsOfKind(d.CallExpression))cl(s,t)},dl=(e,t)=>{const s=e.getExpression();if(!r.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=xe(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 ll(n,{scope:v(e),relativePath:t,requestName:o.getText(),rows:a}),a},ul=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression))s.push(...dl(n,t));return s},fl=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ul(i,I(t,n)))}return s},Un="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 He(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},pl=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&&He(n.getModuleSpecifierValue())}return!1},ml=e=>{if(r.isIdentifier(e))return gl(e);if(r.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&r.isIdentifier(t)&&pl(t)}return!1},hl=e=>{const t=[];for(const s of e.getVariableDeclarations()){const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!ml(n.getExpression()))continue;const o=s.getNameNode();if(!r.isIdentifier(o)){if(s.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw ye(o,"defineIdentity exports must be plain named exports (no destructuring)")}const a=xn(s,"member");a!==void 0&&t.push({exportName:a})}return t},vl=(e,t)=>{const s=E(t,Un);if(!F(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=hl(n);if(i.length!==0){if(i.length>1)throw ye(n,`lunora/identity.ts declares ${i.length.toString()} defineIdentity() contracts (${i.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return i[0]}},El=new Set(["auth","context.auth"]),xl="userId",Sl=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(y(s))}return t},Al=(e,t)=>{const s=E(t,Un);if(!F(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const i of n.getDescendantsOfKind(d.CallExpression)){if(b(i.getExpression())!=="defineIdentity")continue;const[o]=i.getArguments();return o&&r.isObjectLiteralExpression(o)?Sl(o):void 0}},Rs=e=>{if(e===void 0||!r.isPropertyAccessExpression(e)||e.getName()!=="identity")return;const t=e.getExpression();return El.has(t.getText())||W(t,["auth"])?e:void 0},yl=e=>{if(r.isPropertyAccessExpression(e)&&Rs(e.getExpression())!==void 0)return e.getName();if(r.isElementAccessExpression(e)&&Rs(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&r.isStringLiteral(t)?t.getLiteralValue():void 0}},Fs=(e,t,s)=>{const n=yl(e);return n===void 0?void 0:{declared:n===xl||s.has(n),file:t,key:n,line:e.getStartLineNumber(),scope:v(e)}},bl=(e,t)=>{const s=Al(e,t);return s===void 0?[]:[...Z(e,t,d.PropertyAccessExpression,(n,i)=>Fs(n,i,s)),...Z(e,t,d.ElementAccessExpression,(n,i)=>Fs(n,i,s))]},Nl=(e,t)=>{if(b(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=T(s,"key");if(!(!n||!$(n)||ne(n)))return{scope:v(e),file:t,line:e.getStartLineNumber()}},Pl=(e,t)=>C(e,t,Nl),wl=new Set(["delete","get","getRaw","getWithMetadata","put"]),Il=(e,t,s=[])=>{const n=Ge(e,t,{argIndex:0,matchReceiver:i=>i==="ctx.kv"||i.startsWith("ctx.kv."),methods:wl});return Mt(n,s)},Cl=new Set(["queue","send"]),Ls=new Set(["bcc","cc","to"]),Tl=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();if(!Cl.has(t))return;const s=e.getExpression();return W(s,["mail"])||W(s,["email"])?t:void 0},Ol=e=>r.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(r.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return Ls.has(y(t))&&$(n)&&!ne(n)}if(!r.isPropertyAssignment(t)||!Ls.has(y(t)))return!1;const s=t.getInitializer();return s!==void 0&&$(s)&&!ne(s)}):!1,kl=(e,t)=>{const s=Tl(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!Ol(n)))return{scope:v(e),file:t,line:e.getStartLineNumber(),method:s}},Rl=(e,t)=>C(e,t,kl),Fl=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!r.isObjectLiteralExpression(n))return[];const i=[];for(const o of n.getProperties()){const a=Me(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=Me(l);if(u===void 0)continue;const f=wn(l);f!=="custom"&&i.push({column:u,exportName:t,file:s,line:l.getStartLineNumber(),strategy:f,table:a})}}return i},Ll=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&r.isCallExpression(s)?X(s):void 0;return n?.receiver?Kt(n.receiver).flatMap(i=>Fl(i,V(e)??e.getName(),t)):[]},Dl=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=I(t,n);for(const a of j(i))s.push(...Ll(a,o))}return s},Ml=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return L(s)},_l=e=>{const t=e.getArguments()[0];if(t===void 0||!r.isObjectLiteralExpression(t))return;const s=M(t,"server");if(s!==void 0)return r.isPropertyAssignment(s)?s.getInitializer():s},Kl=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==d.CallExpression)return;const s=t;return yr(s.getExpression())?s:void 0},Bl=e=>{const t=Kl(e),s=t===void 0?void 0:_l(t);if(s===void 0)return[];const n=e.getNameNode(),i=r.isIdentifier(n)?V(e)??n.getText():"";return s.getDescendantsOfKind(d.CallExpression).filter(o=>Ml(o)).map(o=>({exportName:i,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},zl=e=>e.getVariableDeclarations().flatMap(t=>Bl(t)),$l=(e,t)=>{const s=E(t,Ar);if(!F(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return zl(n)},Vl=new Set(["delete","get","patch"]),Ul=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),ql=new Set(["auth","identity","session","user"]),Wl=new Set([d.EqualsEqualsEqualsToken,d.EqualsEqualsToken,d.ExclamationEqualsEqualsToken,d.ExclamationEqualsToken]),Hl=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!L(t.getExpression()))return;const s=e.getArguments()[0];return s&&r.isStringLiteral(s)?s.getLiteralText():""},jl=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},Gl=(e,t)=>e.getDescendantsOfKind(d.Identifier).some(s=>s.getText()===t),Yl=e=>r.isThrowStatement(e)||r.isReturnStatement(e)||e.getDescendantsOfKind(d.ThrowStatement).length>0||e.getDescendantsOfKind(d.ReturnStatement).length>0,Ql=(e,t)=>e.getDescendantsOfKind(d.IfStatement).some(s=>Gl(s.getExpression(),t)&&Yl(s.getThenStatement())),Xl=(e,t)=>{for(const s of e.getDescendantsOfKind(d.CallExpression)){const n=s.getExpression();if(!r.isPropertyAccessExpression(n))continue;const i=n.getName();if(!Vl.has(i))continue;const o=n.getExpression();if(!(L(o)||r.isPropertyAccessExpression(o)&&L(o.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&r.isIdentifier(c)&&c.getText()===t)return i}},Jl=e=>e.getDescendantsOfKind(d.CallExpression).some(t=>t.getArguments().some(s=>_t(Lt(s))!==void 0)),Zl=e=>e.getDescendantsOfKind(d.BinaryExpression).some(t=>Wl.has(t.getOperatorToken().getKind())?r.isPropertyAccessExpression(t.getLeft())||r.isPropertyAccessExpression(t.getRight()):!1),ed=e=>{for(const t of e.getDescendantsOfKind(d.Identifier))if(Ul.has(t.getText()))return!0;return[...ql].some(t=>We(e,t).length>0)?!0:Jl(e)||Zl(e)},td=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!r.isCallExpression(s))return[];const n=X(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const i=Kn(s);if(i===void 0)return[];const o=n.receiver!==void 0&&bn(n.receiver,"use","rls"),a=ed(i),c=new Set,l=[];for(const u of i.getDescendantsOfKind(d.CallExpression)){const f=Hl(u);if(f===void 0)continue;const g=jl(u);if(g===void 0||c.has(g)||!Ql(i,g))continue;const p=Xl(i,g);p!==void 0&&(c.add(g),l.push({exportName:V(e)??e.getName(),file:t,line:u.getStartLineNumber(),mentionsOwnership:a,sinkMethod:p,table:f,usesRls:o,visibility:n.visibility}))}return l},sd=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=I(t,n);for(const a of j(i))s.push(...td(a,o))}return s},qn=(e,t)=>{const s=r.isIdentifier(e)&&t!==void 0?O(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},nd=e=>{const t=w(e),s=t.getParent();return(r.isPropertyAccessExpression(s)||r.isElementAccessExpression(s))&&s.getExpression()===t&&!qe(s)},id=e=>{const t=w(e).getParent();return r.isVariableDeclaration(t)&&r.isObjectBindingPattern(t.getNameNode())},rd=e=>{const s=w(e).getParent();if(r.isSpreadAssignment(s)||r.isSpreadElement(s)){const n=s.getParent();return(r.isObjectLiteralExpression(n)||r.isArrayLiteralExpression(n))&&!qe(n)}return r.isTemplateSpan(s)&&!r.isTaggedTemplateExpression(s.getParent().getParent())},Ke=e=>{const t=O(e);return t===void 0||nr(t.getSourceFile())},It=(e,t)=>{const s=w(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"&&Ke(o);if(qn(Lt(o),t))return!(r.isPropertyAccessExpression(o)&&An.has(o.getName()))||r.isExpressionStatement(w(r.isAwaitExpression(n.getParent())?n.getParentOrThrow():n).getParent());if(!r.isPropertyAccessExpression(o))return!1;const a=o.getExpression();if(!r.isIdentifier(a)||!Ke(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}},Re={kind:"opaque"},od={kind:"unreached"},ad=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},Ct=e=>{const t=h(e);if(r.isArrowFunction(t)||r.isFunctionExpression(t))return t;const s=r.isIdentifier(t)?O(t):void 0;if(s?.getSourceFile()!==e.getSourceFile())return;if(r.isFunctionDeclaration(s)){const i=ad(s);return i===void 0||Dt(i)?void 0:i}const n=ee(s)?h(s.getInitializer()):void 0;return r.isArrowFunction(n)||r.isFunctionExpression(n)?n:void 0},Wn=(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?Re:c===void 0?a.some(l=>l.isRestParameter())?Re:od:c.isRestParameter()?Re:{kind:"parameter",parameter:c}},cd=e=>{const t=w(e),s=t.getParent();if(!r.isCallExpression(s)||s.getExpression()===t)return;const n=Ct(s.getExpression());return n===void 0?Re:Wn(n,s,t)},ld=new Set(["__defineGetter__","__defineSetter__","__proto__"]),dd=e=>r.isForInStatement(e)?e.getExpression():r.isConditionalExpression(e)?e.getCondition():r.isElementAccessExpression(e)?e.getArgumentExpression():void 0,Hn=e=>{const t=w(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=dd(s);if(n!==void 0)return S(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},ud=4,jn=(e,t,s=0)=>{if(sr(e))return!0;if(nd(e)){const i=w(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||!ld.has(c)}if(id(e)||rd(e)||Hn(e)||It(e,t))return!0;const n=cd(e);return n?.kind==="unreached"||n?.kind==="parameter"&&fd(n.parameter,s+1)},Ds=new WeakMap,fd=(e,t=0)=>{const s=e.getNameNode();if(!r.isIdentifier(s))return!0;const n=Ds.get(e.compilerNode);if(n!==void 0)return n;if(t>ud)return!1;const o=(s.getSymbol()?.getDeclarations().length??0)===1&&e.getParentOrThrow().getDescendantsOfKind(d.Identifier).every(a=>a===s||a.getText()!==s.getText()||O(a)?.compilerNode!==e.compilerNode||jn(a,void 0,t));return(o||t===0)&&Ds.set(e.compilerNode,o),o},Ms=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=O(i)?.compilerNode;return o!==void 0&&(o===t.compilerNode||s!==void 0&&o===e.compilerNode)})},pd=(e,t,s)=>{const{context:n,impl:i}=e,o=Ms.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 p=g.getNameNode();return r.isIdentifier(p)?[p]:[]}),l=new Map(c.map(g=>[g.getText(),g.getParentOrThrow().compilerNode])),u=g=>r.isIdentifier(a)?jn(g,n):!qe(g),f=!gd(i,s)&&c.every(g=>(g.getSymbol()?.getDeclarations().length??0)===1)&&i.getDescendantsOfKind(d.Identifier).every(g=>{const p=g.getText();if(p==="arguments")return!1;const x=l.get(p);return x===void 0||c.includes(g)||O(g)?.compilerNode!==x?!0:u(g)});return Ms.set(i.compilerNode,f),f},_s=new WeakMap,md=e=>{let t=_s.get(e.compilerNode);return t===void 0&&(t=new Map(e.getVariableDeclarations().flatMap(s=>{const n=br(s);return n===void 0?[]:[[n.compilerNode,s]]})),_s.set(e.compilerNode,t)),t},hd=e=>{const t=md(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:V(n)??n.getName()};return a!==void 0&&pd(c,a,n)?{...c,parameter:a,pristine:!0}:{...c,parameter:a,pristine:!1}},ut="args",he=e=>{const t=hn(e);if(t!==void 0){const c=h(t.object);return r.isIdentifier(c)&&c.getText()===ut?t.member:void 0}if(!r.isIdentifier(e))return;const s=O(e);if(!r.isBindingElement(s)||s.getDotDotDotToken()!==void 0)return;const n=s.getParent();if(!r.isObjectBindingPattern(n))return;const i=n.getParent(),o=ee(i)?h(i.getInitializer()):void 0;return r.isBindingElement(i)&&se(i)===ut||r.isIdentifier(o)&&o.getText()===ut?se(s):void 0},vd=new Set(["auth","identity","user"]),Tt=e=>{const t=i=>{const o=_t(i);return o!==void 0&&o.length>0&&vd.has(o[0]??"")},s=h(e)??e;if(t(s))return!0;const n=H(s);return n!==void 0&&t(n)},Gn=(e,t=2)=>{const s=new Set;for(const n of[e,...e.getDescendants()]){const i=he(n);i!==void 0&&s.add(i);const o=t>0&&r.isIdentifier(n)?H(n):void 0;if(o!==void 0)for(const a of Gn(o,t-1))s.add(a)}return s},Fe=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[...Fe(n),...Fe(i)];if(s===d.AmpersandAmpersandToken){const l=(u,f)=>{const g=he(h(u)??u);return g===void 0?[]:Fe(f).filter(p=>p===g)};return[...l(n,i),...l(i,n)]}if(s!==d.ExclamationEqualsEqualsToken&&s!==d.ExclamationEqualsToken)return[];const o=[],a=he(h(n)??n),c=he(h(i)??i);return a!==void 0&&Tt(i)&&o.push(a),c!==void 0&&Tt(n)&&o.push(c),o},Ed=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)&&fr(i.getExpression(),"defineIdentityGuard")},xd=e=>{if(!Ed(e.getExpression()))return[];const t=e.getArguments();return t.flatMap((s,n)=>{const i=he(h(s)??s),o=t.some((a,c)=>c!==n&&Tt(a));return i!==void 0&&o?[i]:[]})},Sd=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)},Ad=e=>r.isArrowFunction(e)||r.isFunctionExpression(e)||r.isFunctionDeclaration(e)||r.isMethodDeclaration(e),Ks=(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},yd=e=>r.isAwaitExpression(e.getParent())||e.getType().isVoid(),bd=(e,t)=>{const s=new Set;for(const n of e.getDescendantsOfKind(d.IfStatement))if(n.getEnd()<=t&&Ks(n,e)&&Sd(n.getThenStatement()))for(const i of Fe(n.getExpression()))s.add(i);for(const n of e.getDescendantsOfKind(d.CallExpression))if(n.getEnd()<=t&&yd(n)&&Ks(n,e))for(const i of xd(n))s.add(i);return s},Nd=(e,t)=>{const s=Gn(t);if(s.size===0)return!1;const n=e.getFirstAncestor(Ad);if(n===void 0)return!1;const i=bd(n,e.getStart());return[...s].every(o=>i.has(o))},Pd=new Set(["at","concat","filter","find","findLast","flat","reverse","slice","sort","toReversed","toSorted"]),wd=new Map([["Array",new Set(["from","of"])],["Object",new Set(["entries","values"])]]),Ot=new Set(["catch","every","filter","finally","find","findIndex","findLast","findLastIndex","flatMap","forEach","map","reduce","reduceRight","some","sort","then"]),Yn=e=>e.getNameNode().getDescendantsOfKind(d.BindingElement).filter(t=>r.isIdentifier(t.getNameNode())),Id=e=>{const t=w(e),s=t.getParent();if(r.isVariableDeclaration(s))return S(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},Cd=e=>{const t=Id(e);return t===void 0?void 0:r.isIdentifier(t.getNameNode())?r.isForOfStatement(t.getParent().getParent())||ee(t)?[t]:void 0:Yn(t)},ve=e=>e.isUnion()?e.getUnionTypes().every(t=>ve(t)):e.isIntersection()?e.getIntersectionTypes().some(t=>ve(t)):!e.isAny()&&!e.isUnknown()&&!e.isObject()&&!e.isTypeParameter(),Be=(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)},Le=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]},Td=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)&&wd.get(s.getText())?.has(t.getName())===!0&&Ke(s)},Od=e=>{const t=St(e);if(!r.isArrowFunction(t)&&!r.isFunctionExpression(t))return;const s=w(t),n=s.getParent();return r.isCallExpression(n)&&n.getArguments().includes(s)&&Be(n,yn)?n:void 0},kd=(e,t)=>{if(!(r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e))||e.getExpression()!==t)return;const s=w(e),n=s.getParent();return!r.isCallExpression(n)||n.getExpression()!==s?e:Be(n,Pd,t)?n:void 0},Rd=(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},Fd=(e,t)=>{if(r.isArrayLiteralExpression(e))return e;const n=r.isSpreadElement(e)||r.isSpreadAssignment(e)||r.isShorthandPropertyAssignment(e)||r.isPropertyAssignment(e)&&S(e.getInitializer(),t)?e.getParent():void 0;return r.isArrayLiteralExpression(n)||r.isObjectLiteralExpression(n)?n:void 0},Bs=e=>{const t=w(e),s=t.getParent();if(s===void 0)return;const n=r.isCallExpression(s)&&s.getArguments().includes(t)&&Td(s);return kd(s,t)??Rd(s,t)??Fd(s,t)??(n?s:Od(t))},Ld=5e4,Qn=()=>({inProgress:new Set,verdicts:new Map});class Dd{cuts=0;work=0;reset(){this.work=0}cut(){return this.cuts+=1,!0}spend(){return this.work+=1,this.work>Ld&&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 Md=8,_d=8;class Kd{budget;scope;taint;verdicts=Qn();constructor(t,s,n){this.scope=t,this.budget=s,this.taint=n}isCompromised(t){return this.flowHasCompromisingUse(t)&&!ve(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)?Yn(t):[])i(l,s);return!1}if(this.budget.spend())return!0;const a=(l,u)=>u&&s>=Md?this.budget.cut():(i(l,u?s+1:s),!1);return this.taint.referencesTo(t,o.getText()).some(l=>this.valueCompromises(w(l),!0,a,0))&&(t===n||!ve(t.getType()))}valueCompromises(t,s,n,i){let o=t;for(let p=Bs(o);p!==void 0;p=Bs(o)){if(r.isCallExpression(p)&&this.callbackCompromises(p,n))return!0;o=w(p)}const a=o.getParent(),c=o===t&&s,l=()=>!c&&ve(o.getType());if(qe(o))return!c&&(!r.isBinaryExpression(a)||this.taint.isTaintedValue(a.getRight(),!1));const u=Cd(o);if(u!==void 0)return u.some(p=>n(p,!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=w(t).getParent();if(n>=_d)return this.budget.cut();if(r.isCallExpression(i))return i.getExpression()===w(t)?this.valueCompromises(i,!1,s,n+1):!Be(i,Ot);const o=r.isFunctionDeclaration(t)?t:i,a=r.isFunctionDeclaration(o)||ee(o)?o.getNameNode():void 0;return o===void 0||!r.isIdentifier(a)?!0:this.taint.referencesTo(o,a.getText()).some(c=>{const l=w(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=>Le(i)===void 0).some(i=>this.taint.isTaintedValue(i,!1))||this.callbackCompromises(t,s)}callbackCompromises(t,s){const n=Be(t,Ot)?t.getArguments()[0]:void 0;if(n===void 0)return!1;const i=Ct(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!It(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(It(s,this.scope.context))return!1;const i=Ct(t.getExpression()),o=i===void 0?void 0:Wn(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)||Hn(t)||S(St(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=St(t);return S(s,this.scope.impl)?void 0:s}}const Bd=new Set(["at","every","filter","finally","find","findIndex","findLast","findLastIndex","forEach","order","slice","some","sort","withIndex","withSearchIndex"]),zd=e=>{const t=h(e);if(!r.isIdentifier(t))return r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t);const s=O(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)},$d=new Set(["all","allSettled","any","race"]),zs=e=>r.isParameterDeclaration(e)?e:r.isBindingElement(e)?e.getFirstAncestorByKind(d.Parameter):void 0,ft=8;class Vd{budget=new Dd;referencesByDeclaration=new Map;referencesByName=new Map;scope;verdicts=Qn();walk;variableDepth=0;queryDepth=0;constructor(t){this.scope=t,this.walk=new Kd(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,ft)?!1:(r.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(i=>ir(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=O(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=w(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)||!Ot.has(g.getName()))return!0;const p=a.getArguments().filter(x=>x!==o);return this.isTaintedValue(g.getExpression(),!0)||p.some(x=>this.isTaintedValue(x,!1))}const c=r.isVariableDeclaration(a)&&ee(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 p=w(g),x=p.getParent();return!r.isCallExpression(x)||x.getExpression()!==p||this.isCallSiteTainted(x,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"&&Ke(i)&&$d.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:Le(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=O(t),i=zs(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&&An.has(i)?!1:i!==void 0&&yn.has(i)?this.isCallbackResultServerScoped(t,s)?void 0:!1:t.getArguments().some(a=>Le(a)!==void 0)&&(i===void 0||!Bd.has(i))?!1:void 0}isCallbackResultServerScoped(t,s){const n=(i,o=[])=>{const a=Lt(i),c=r.isIdentifier(a)?zs(O(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=Le(i);if(o===void 0)return!zd(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=Zi(t,u=>this.callChainVerdict(u,s)),i=n.root;if(n.verdict!==void 0)return n.verdict;if(qn(i,this.scope.context))return!0;const o=r.isIdentifier(i)?O(i):void 0,a=r.isBindingElement(o)?o.getFirstAncestorByKind(d.VariableDeclaration):o,c=ee(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=Dt(t);if(n===void 0||i)return!0;if(this.isRootedInContext(n,ft))return!1;if(this.variableDepth>=ft)return this.budget.cut();this.variableDepth+=1;try{return this.isTaintedValue(n,!1)}finally{this.variableDepth-=1}},this.verdicts)}}const $s=new WeakMap,Ud=e=>{const t=$s.get(e.impl.compilerNode);if(t!==void 0)return t;const s=new Vd(e);return $s.set(e.impl.compilerNode,s),s},qd=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Wd=new Set(["insert","insertManyUnsafe","patch","replace"]),Hd=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();return Wd.has(t)&&cr(e.getExpression())?t:void 0},jd=(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},Gd=(e,t)=>{const s=hn(e);return s?.member===t?h(s.object):void 0},Vs=(e,t)=>r.isIdentifier(e)&&O(e)?.compilerNode===t.compilerNode,Xn=(e,t,s,n=1)=>{const i=Gd(e,s);if(i!==void 0)return Vs(i,t);const o=r.isIdentifier(e)?O(e):void 0;if(r.isBindingElement(o)){const c=o.getParent(),l=c.getParent();return o.getDotDotDotToken()===void 0&&se(o)===s&&r.isObjectBindingPattern(c)&&(l.compilerNode===t.compilerNode||ee(l)&&Vs(h(l.getInitializer()),t))}const a=ee(o)?o.getInitializer():void 0;return n>0&&a!==void 0&&Xn(a,t,s,n-1)},kt=e=>{const t=h(e)??e;return r.isConditionalExpression(t)?[...kt(t.getWhenTrue()),...kt(t.getWhenFalse())]:[t]},Yd=(e,t,s)=>{const n=[],i=s===void 0?void 0:Ud(s);for(const o of e.getProperties()){let a,c;if(r.isPropertyAssignment(o)?(a=y(o),c=o.getInitializer()):r.isShorthandPropertyAssignment(o)&&(a=y(o),c=o.getNameNode()),a===void 0||c===void 0||!qd.has(a))continue;const l=kt(c).filter(f=>i===void 0?$(f)&&!lr(f):i.isTaintedValue(f,!0));if(l.length>0){const f=t.ownerField===a&&s?.pristine===!0&&Xn(c,s.parameter,a),g=l.every(p=>Nd(t.call,p));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},Qd=(e,t,s)=>{const n=Hd(e.getExpression()),i=n===void 0?void 0:e.getArguments()[1];if(n===void 0||i===void 0)return[];const o=jd(i,n);if(o.length===0)return[];const a=v(e),c=hd(e),l={call:e,method:n,ownerField:c===void 0?void 0:s(c.mutatorName),relativePath:t,scope:a};return o.flatMap(u=>Yd(u,l,c))},Xd=(e,t,s=[],n=[])=>{const i=new Map(n.map(c=>[`${c.filePath}:${c.exportName}`,c.owner])),o=C(e,t,(c,l)=>Qd(c,l,u=>i.get(`${l}:${u}`))),a=new Map(s.map(c=>[`${c.filePath}:${c.exportName}`,c.adminOnly===!0]));return Mt(o,s).map(c=>rr(c.scope)?.every(f=>a.get(`${c.file}:${f}`)===!0)===!0?{...c,adminOnly:!0}:c)},Jd=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Zd=e=>e&&r.isNumericLiteral(e)?Number(e.getText()):void 0,eu=e=>{const t=M(e,"webhookToleranceSeconds");return t&&r.isPropertyAssignment(t)?Zd(t.getInitializer()):void 0},tu=(e,t)=>{const s=b(e.getExpression());if(s===void 0||!Jd.has(s))return;const[n]=e.getArguments(),i=n&&r.isObjectLiteralExpression(n)?eu(n):void 0;return{callee:s,scope:v(e),file:t,line:e.getStartLineNumber(),...i===void 0?{}:{toleranceSeconds:i}}},su=(e,t)=>C(e,t,tu),nu=new Map([["defineQueue",0],["defineSubscription",1],["defineWorkflow",0]]),iu=e=>{const t=e.getExpression();return r.isIdentifier(t)?t.getText():void 0},ru=(e,t)=>{const s=e.getArguments()[t];if(!s||!r.isObjectLiteralExpression(s))return;const n=M(s,"handler");if(n===void 0||!r.isPropertyAssignment(n))return;const i=n.getInitializer();if(i&&(r.isArrowFunction(i)||r.isFunctionExpression(i)))return i},Jn=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&r.isIdentifier(s)?s.getText():void 0},Zn=(e,t)=>e===t||e.startsWith(`${t}.`),ei=e=>{const t=e.getDescendantsOfKind(d.PropertyAccessExpression);return r.isPropertyAccessExpression(e)&&t.push(e),t},Us=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)},ti=e=>{const t=e.getDescendantsOfKind(d.Identifier).filter(s=>Us(s));return r.isIdentifier(e)&&Us(e)&&t.push(e),t},ou=e=>{if(!r.isVariableDeclaration(e))return[];const t=e.getNameNode();return r.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(d.BindingElement).map(s=>s.getName())},au=e=>{const t=Jn(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},cu=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:au(e),i=new Set,o=a=>ei(a).some(c=>n.some(l=>Zn(c.getText(),l)))?!0:ti(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 ou(a))i.add(l)}return{names:i,prefixes:n}},lu=(e,t)=>ei(e).some(s=>t.prefixes.some(n=>Zn(s.getText(),n)))?!0:ti(e).some(s=>t.names.has(s.getText())),du=e=>{const t=er(e);return t===void 0?void 0:{exportName:String(t.at(-1)),file:t.slice(0,-1).join("/")}},uu=(e,t,s)=>{const n=Jn(e,0);if(n===void 0)return[];const i=cu(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)||!vn.has(l.getName())||!o.has(l.getExpression().getText()))continue;const u=c.getArguments()[1];if(!u||!lu(u,i))continue;const f=du(c.getArguments()[0]);f!==void 0&&a.push({dispatchKind:t,file:s,scope:v(c),line:c.getStartLineNumber(),targetExport:f.exportName,targetFile:f.file})}return a},fu=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=iu(n),o=i===void 0?void 0:nu.get(i);if(o===void 0)continue;const a=ru(n,o);a!==void 0&&s.push(...uu(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(...fu(i,I(t,n)))}return s},qs={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},Ws=new Set(["account","credential","member","passkey","session","user"]),pu=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),mu=e=>{const s=pu(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return Ws.has(s)||Ws.has(n)},hu=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},vu=(e,t)=>{const{objects:s,opaque:n}=$t(e,t);return Ia(s).some(i=>hu(i))?!0:n?void 0:!1},Eu=e=>{const t=e.getArguments()[0];return!t||!r.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!M(t,"captcha"),usesRateLimit:!!M(t,"rateLimit")}},xu=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},De={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Su=e=>{const t=xu(e),s=t?b(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=Eu(t);return{...De,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in qs?{...De,[qs[s]]:!0}:De},Au=e=>{const t={...De};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=Su(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},yu=new Set(["insert","insertMany","insertManyUnsafe","replace"]),bu=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!yu.has(t.getName()))return!1;const s=t.getExpression();if(!L(s))return!1;const i=e.getArguments()[0];return!i||!(r.isStringLiteral(i)||r.isNoSubstitutionTemplateLiteral(i))?!1:mu(i.getLiteralText())},Nu=new Set(["create","publish","publishBatch","runAfter","runAt","send","sendBatch"]),Hs=new Set(["queues","scheduler","topics","workflows"]),Pu=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!Nu.has(t.getName()))return!1;let s=t.getExpression();for(;r.isCallExpression(s)||r.isElementAccessExpression(s)||r.isPropertyAccessExpression(s);){if(r.isPropertyAccessExpression(s)&&Hs.has(s.getName())&&dr(s.getExpression()))return!0;s=s.getExpression()}const n=_t(s);return n?.length===1&&Hs.has(n[0]??"")},wu=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return L(s)},si=new Set(["generateObject","generateText","streamObject","streamText"]),Iu=e=>{const t=b(e.getExpression());return t!==void 0&&si.has(t)},Cu=e=>{const t=b(e.getExpression());if(t===void 0||!si.has(t))return!1;const s=e.getArguments()[0];return!s||!r.isObjectLiteralExpression(s)||s.getProperties().some(n=>r.isSpreadAssignment(n))?!1:!M(s,"maxOutputTokens")},Tu=new Set(["log","span","trace"]),Ou=new Set(["ai"]),ku=new Set(["email","mail"]),Ru=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","topics","workflows"]),gt=(e,t)=>[...t].some(s=>We(e,s).length>0),ni=new Set([d.ArrowFunction,d.FunctionDeclaration,d.FunctionExpression,d.GetAccessor,d.MethodDeclaration,d.SetAccessor]),Fu=new Set(["every","filter","flatMap","forEach","map","some"]),Lu=new Set(["all","allSettled","race"]),ii=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(Fu.has(n))return t;const i=s.getExpression();if(r.isIdentifier(i)&&i.getText()==="Promise"&&Lu.has(n))return t},Du=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(ni.has(t.getKind())){const s=ii(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},Mu=e=>{let t=e.getParent();for(;t!==void 0;){if(r.isCallExpression(t)&&t.getExpression().getText()==="Promise.allSettled")return!0;if(ni.has(t.getKind())){if(t=ii(t),t===void 0)return!1;continue}t=t.getParent()}return!1},_u=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(p=>{const x=p.getExpression();return r.isIdentifier(x)&&x.getText()===l&&r.isAwaitExpression(p.getParent())}),g=u.getCatchClause();return f&&g!==void 0&&g.getDescendantsOfKind(d.ThrowStatement).length>0})},Ku=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}},Bu=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}},zu=e=>{let t=!1,s=!0;for(const n of[...Ru].flatMap(i=>We(e,i))){const i=Bu(n);i&&(t=!0,!Du(i)&&!Ku(i)&&!_u(i)&&!Mu(i)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},$u=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"}),js="lunora-advisor-exempt",Vu=/^[\s*/]+/u,Uu=/[\w-]/u,qu=e=>{const s=(e.getFirstAncestorByKind(d.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
1
+ import{existsSync as F,mkdirSync as un,readFileSync as Vi,writeFileSync as Ui,rmSync as xt,readdirSync as qi}from"node:fs";import{dirname as fn,join as E,relative as Wi}from"node:path";import{performance as ct}from"node:perf_hooks";import{runAdvisor as Hi}from"@lunora/advisor";import{LunoraError as q}from"@lunora/errors";import{serializeSchemaSnapshot as ji}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{toAdvisorContext as Gi}from"./formatAdvisories-BCVASH7N.mjs";import{Node as r,SyntaxKind as d,ts as Yi,VariableDeclarationKind as Qi}from"ts-morph";import{listLunoraSourceFiles as A,lunoraRelativePath as I,bindingKeyName as se,collectCallRows as C,findObjectProperty as M,collectSecurityCallRows as Xi,propertyInitializer as T,listSecurityScanFiles as Ue,objectLiteralFromCallbackBody as gn,limitNameOf as pn,optionsObjectLiteral as mn,handlerOf as Ji,collectNodeRows as Z,chainRootOf as Lt,outermostValueWrapper as w,isWriteTarget as qe,isSameNode as S,unwrapExpression as h,isConstDeclaration as ee,memberAccessOf as hn,returningFunctionOf as St,walkChain as Zi,RUN_METHODS as vn,functionReferenceSegments as er,isTestPath as tr,isFunctionLike as te,functionKeyOf as En}from"./isTestPath-B81lOULB.mjs";import{b as j,d as V,f as O,g as Dt,c as v,a as xn,w as Mt,k as sr,l as nr,h as ir,m as rr,j as At,i as or}from"./attribution-hVBriwzy.mjs";import{a as xs,r as lt,i as W,b as ar,m as Sn,c as We,e as _t,E as An,C as yn,d as cr,f as lr,g as dr}from"./context-root-lGZCyHyj.mjs";import{a as b,i as ur,c as X,d as bn,e as fr,f as gr}from"./classify-procedure-call-BAj0D1u2.mjs";import{a as y,r as Nn,s as pr,b as mr}from"./project-config-file-BV7RR-l6.mjs";import{a as hr,b as He}from"./module-specifiers-WF8iAydP.mjs";import{r as je,s as vr}from"./parse-validator-IDBKIT7M.mjs";import Er from"./discoverAuthApiCalls-xs0ONfI-.mjs";import{i as L,r as Pn}from"./database-calls-CVsXSVhv.mjs";import xr from"./discoverHyperdriveCalls-DxYmsE3Y.mjs";import{diagnosticAt as ye}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{m as Kt,a as Me,s as wn,d as Sr}from"./index-Bxn8ZjS0.mjs";import{MUTATORS_FILENAME as Ar,isDefineMutatorCallee as yr,mutatorServerImplOf as br,discoverMutators as Nr}from"./MUTATORS_FILENAME--5kUJd5I.mjs";import Pr from"./discoverNondeterministicCalls-9ZDpRptb.mjs";import{discoverNotifyConfig as wr,discoverNotifyCalls as Ir}from"./NOTIFY_FILENAME-BOZ8G8zT.mjs";import Cr from"./discoverR2sqlCalls-CEbVN9V1.mjs";import Tr from"./discoverRlsProcedures-BfEFJmU5.mjs";import{s as Bt,n as Or}from"./dispatch-namespace-DwTjD7BU.mjs";import{secretKindOf as kr,redact as Rr,isHeuristicSecretKind as Fr,isSecretishName as Lr}from"./redact-Cy14LEnc.mjs";import{a as Oe,d as Dr,r as Mr}from"./modules-CjOcuQnK.mjs";import{WORKFLOWS_FILENAME as _r,discoverWorkflows as Kr}from"./WORKFLOWS_FILENAME-CdeS224T.mjs";import{r as Br}from"./json-data-Chfs2Cz5.mjs";import{G as zr}from"./shared-DnCokNcE.mjs";import{createCodegenProject as $r}from"./createCodegenProject-V51_yBw3.mjs";import{findTsconfig as Nv,refreshCodegenProject as Pv}from"./createCodegenProject-V51_yBw3.mjs";import{CAPABILITIES as Vr,usedCapabilities as Ur}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{isD1GlobalTable as In,isHyperdriveGlobalTable as Cn}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as qr}from"./AGENTS_FILENAME-B6-kjzM3.mjs";import{discoverContainers as Wr}from"./CONTAINERS_FILENAME-dFRtAyIe.mjs";import Hr from"./discoverCrons-DBnCama4.mjs";import{contextPropertiesRead as jr,discoverFeatureUsage as Gr}from"./capabilitiesUsedBy-QgSZyE0T.mjs";import Tn from"./readPackageDependencies-RHhGiz0k.mjs";import{discoverQueueDeclarations as Yr}from"./QUEUES_FILENAME-CsRy4VTF.mjs";import{discoverSandboxUsage as Qr}from"./discoverSandboxUsage-w6Q3RvxZ.mjs";import{resolveServiceBindings as Xr}from"./readServiceBindings-DvqIThzd.mjs";import Jr from"./discoverStorageRulesMetadata-BPJplDfz.mjs";import{resolveCodegenTarget as On,gatePlatformFeatures as Zr,readTargetDiagnostics as eo,vectorizeDimensionDiagnostics as to,studioPlatformFor as so}from"./DEFAULT_TARGET-BnQiNNKu.mjs";import{i as no}from"./schema-BgM8A3XV.mjs";import{b as kn,e as io}from"./shard-Av4rUyYS.mjs";import{e as ro,a as oo}from"./server-DAvi_bv_.mjs";import{emitDataModel as ao}from"./emitDataModel-BskFt9Wv.mjs";import{i as co,a as lo,e as uo,b as fo,d as go,c as po}from"./unwrap-handler-return-BwclbliB.mjs";import mo from"./discoverFunctions-BiA7jv30.mjs";import ho from"./discoverHttpRoutes-BccLtGKg.mjs";import vo from"./discoverInserts-rFszl3Al.mjs";import{e as Rn}from"./exported-procedure-chains-DKK5HoK3.mjs";import Eo from"./discoverMigrations-C9mLIhGZ.mjs";import xo from"./discoverQueries-DDds61UD.mjs";import So from"./discoverRlsMetadata-Cb8JR1b4.mjs";import Ao from"./discoverSchema-BtsX-CN9.mjs";import{discoverShapes as yo}from"./SHAPES_FILENAME-DkBUN9dK.mjs";import{i as bo}from"./reserved-words-CW1QFbTd.mjs";import{emitApp as No}from"./emitApp-BOUdd-2R.mjs";import{readJsonSync as Po}from"@visulima/fs";import{buildSchemaSnapshot as wo}from"./SchemaSnapshotParseError-BRJT7c2k.mjs";import{buildOpenApiDocument as Io,emitOpenApiModule as Co}from"./buildOpenApiDocument-DFv-RYZU.mjs";import{buildOpenRpcDocument as To,emitOpenRpcModule as Oo}from"./OPENRPC_VERSION-CCY7xqSL.mjs";import{v as ko,t as Ro,u as Fo,s as Lo,w as Do}from"./shard-runtime-CkTgY8tL.mjs";import{emitCollections as Mo,emitSeed as _o,emitApi as Ko,emitInternalApi as Bo}from"./emitApi-Zx6VPN-7.mjs";import{emitCrons as zo,emitScheduler as $o,emitShardRegistry as Vo,emitDurableObjects as Uo,emitVectors as qo,emitWranglerCronTriggers as Wo}from"./emitCrons-BQW2lviZ.mjs";import Ho from"./emitDrizzleSchema-DitcRZ1a.mjs";import jo from"./emitFunctions-BeKgL3dl.mjs";const Fn=new Set(["delete","get","head","options","patch","post","put"]),Go=new Set(["handler","stream"]),Yo=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,Ss=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Qo=e=>{if(!r.isCallExpression(e))return;const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!Fn.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()}},Xo=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)||Fn.has(n.getName()))break;s=n.getExpression()}return Qo(s)},Jo=e=>{for(const t of e.getDescendantsOfKind(d.PropertyAccessExpression))if(Ss.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=t.getExpression();if(r.isIdentifier(s)&&Ss.has(s.getText()))return!0}return!1},Zo=(e,t)=>{const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const n=s.getExpression();if(!r.isPropertyAccessExpression(n)||!Go.has(n.getName()))return;const i=Xo(s);if(!i||!Yo.test(i.path))return;const o=s.getArguments()[0],a=o!==void 0&&(r.isArrowFunction(o)||r.isFunctionExpression(o))&&Jo(o);return{exportName:V(e)??e.getName(),file:t,method:i.method,path:i.path,usesGuard:a}},ea=(e,t)=>{const s=[];for(const n of j(e)){const i=Zo(n,t);i&&s.push(i)}return s},ta=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ea(i,I(t,n)))}return s},sa=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}},na=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)?se(t):void 0}},ia=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))&&xs(a)}))return!1;const n=O(e),i=r.isParameterDeclaration(n)?n:n?.getFirstAncestorByKind(d.Parameter);return i!==void 0&&(r.isParameterDeclaration(n)||r.isBindingElement(n))&&xs(i)},As=(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=sa(e);return n!==void 0&&na(n)===t?!0:t==="args"&&ia(e)},Ln=(e,t)=>r.isIdentifier(e)?As(e,t):e.getDescendantsOfKind(d.Identifier).some(s=>As(s,t)),ra=e=>{let t=e;for(;r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t)||r.isNonNullExpression(t);)t=t.getExpression();return r.isIdentifier(t)?t:void 0},ys=e=>{const t=r.isIdentifier(e)?O(e):void 0;return r.isVariableDeclaration(t)&&r.isIdentifier(t.getNameNode())&&!Dt(t)?t.getInitializer():void 0},yt=e=>Ln(e,"args"),H=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},$=e=>{if(yt(e))return!0;const t=H(e);return t!==void 0&&yt(t)},oa=e=>{if(r.isCallExpression(e)||r.isNewExpression(e))return!1;const t=H(e);return t===void 0||!(r.isCallExpression(t)||r.isNewExpression(t))},ne=e=>{if(lt(e))return!0;const t=ys(e);if(t!==void 0&&lt(t))return!0;const s=t??e;return(r.isIdentifier(s)?[s]:s.getDescendantsOfKind(d.Identifier)).some(i=>{const o=ys(i);return o!==void 0&&lt(o)})},ke=(e,t)=>Ln(e,t),aa=(e,t)=>{if(ke(e,t))return!0;const s=H(e);if(s!==void 0&&ke(s,t))return!0;const n=ra(e);if(n!==void 0){const i=H(n);return i!==void 0&&ke(i,t)}return!1},ca=e=>!r.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:W(e.getExpression(),["ai"]),la=(e,t)=>{if(!ca(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!$(s)||ne(s)))return{scope:v(e),file:t,line:e.getStartLineNumber()}},da=(e,t)=>C(e,t,la),ua=new Set(["generateText","streamText"]),fa=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"]}],pa=(e,t)=>ga.some(s=>s.methods.has(t)&&s.prefixes.some(n=>e===n||e.startsWith(`${n}.`))),ma=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return;const s=t.getName(),n=[ar(t.getExpression()),t.getExpression().getText()].find(i=>i!==void 0&&pa(i,s));return n===void 0?void 0:`${n}.${s}`},ha=e=>{for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=ma(t);if(s!==void 0)return s}},va=e=>{const t=new Set,s=e.getFirstAncestor(o=>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=se(o),c=o.getNameNode();if(a==="args"&&r.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},Ea=e=>{if(yt(e))return!0;const t=va(e);return t.size===0?!1:e.getDescendantsOfKind(d.Identifier).some(s=>t.has(s.getText()))},xa=e=>{for(const t of e.getProperties()){if(!r.isPropertyAssignment(t)||!fa.has(y(t)))continue;const s=t.getInitializer();if(s!==void 0&&Ea(s))return!0}return!1},Sa=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=b(n.getExpression());if(i===void 0||!ua.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(b(c.getExpression())==="tool"&&(a=ha(c),a!==void 0))break;a!==void 0&&s.push({scope:v(n),file:t,line:n.getStartLineNumber(),method:i,sideEffect:a,userInputDerived:xa(o)})}return s},Aa=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Sa(i,I(t,n)))}return s},ya=e=>W(e,["fetch"]),ba=(e,t)=>{if(!ya(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!$(s)))return{scope:v(e),file:t,line:e.getStartLineNumber()}},Na=(e,t)=>C(e,t,ba),zt=(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=je(s.getExpression());return n===void 0||zt(n,t)})}finally{t.delete(e)}},Pa=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=M(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:je(n);return i===void 0?{objects:[],opaque:!0}:{objects:[i],opaque:zt(i)}},wa=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)?je(o):void 0;a===void 0?s=!0:(t.push(a),s||=zt(a))}n=i.getExpression()}return{objects:t,opaque:s}},$t=(e,t)=>t?wa(t):Pa(e),Dn=(e,t)=>{if(t.has(e))return[];t.add(e);try{return e.getProperties().flatMap(s=>{if(r.isSpreadAssignment(s)){const n=je(s.getExpression());return n===void 0?[]:Dn(n,t)}return r.isPropertyAssignment(s)||r.isShorthandPropertyAssignment(s)?[y(s)]:[]})}finally{t.delete(e)}},Ia=e=>e.flatMap(t=>Dn(t,new Set)),Ca=new Set(["check","length","max"]),bt=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(Ca.has(s.getName()))return!0;t=n}},Nt=e=>hr(e)||e==="@lunora/values",Ta=e=>{const t=new Set(["v"]);for(const s of ur(e,"v",Nt))t.add(s);for(const s of e.getImportDeclarations()){const n=s.getNamespaceImport();n&&Nt(s.getModuleSpecifierValue())&&t.add(`${n.getText()}.v`)}return t},Oa=(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},ka=e=>(e.getSymbol()?.getDeclarations()??[]).some(t=>!t.getSourceFile().isDeclarationFile()&&!r.isImportSpecifier(t)&&!r.isNamespaceImport(t)&&!r.isImportClause(t)),Ra=e=>(e.getSymbol()?.getDeclarations()??[]).some(t=>r.isNamespaceImport(t)&&Nt(t.getFirstAncestorByKindOrThrow(d.ImportDeclaration).getModuleSpecifierValue())),Vt=(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 ka(n)?void 0:s.getName();const i=r.isPropertyAccessExpression(n)?n.getExpression():void 0;return r.isIdentifier(i)&&Ra(i)?s.getName():void 0}if(r.isIdentifier(s))return t.destructured.get(s.getText())},Fa=(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)},La=e=>{let t=e.getParent();for(;t&&!r.isFunctionLikeDeclaration(t);)t=t.getParent();return t},Da=e=>r.isReturnStatement(e)?e.getExpression():void 0,Ma=e=>r.isArrowFunction(e)&&!r.isBlock(e.getBody())?[e.getBody()]:e.getDescendantsOfKind(d.ReturnStatement).filter(t=>La(t)?.compilerNode===e.compilerNode).flatMap(t=>{const s=Da(t);return s?[s]:[]}),Mn=(e,t)=>{if(Vt(e,t)!==void 0)return e;if(r.isCallExpression(e)||r.isPropertyAccessExpression(e))return Mn(e.getExpression(),t)},_a=(e,t)=>{const s=Fa(e.getExpression(),e.getSourceFile());if(!s)return[];const n=bt(e),i=new Set(Ma(s).map(o=>Mn(o,t)).filter(o=>o!==void 0));return[s,...s.getDescendants()].flatMap(o=>{const a=Vt(o,t);return a===void 0?[]:[{bounded:bt(o)||n&&i.has(o),factory:a}]})},Ka=(e,t)=>[e,...e.getDescendants()].flatMap(s=>{const n=Vt(s,t),i=n===void 0?[]:[{bounded:bt(s),factory:n}];return r.isCallExpression(s)?[...i,..._a(s,t)]:i}),Ba=(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=Ka(a,t),l=y(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}},za=(e,t,s)=>{const n=e.getInitializer();if(!n||!r.isCallExpression(n))return;const i=X(n);if(i?.visibility!=="public")return;const{objects:o}=$t(n,i.receiver),{anyArgs:a,unboundedStringArgs:c}=Ba(o,s);if(!(a.length===0&&c.length===0))return{anyArgs:a,exportName:V(e)??e.getName(),file:t,line:n.getStartLineNumber(),unboundedStringArgs:c}},$a=(e,t)=>{const s=[],n=Ta(e),i={destructured:Oa(e,n),namespaces:n};for(const o of j(e)){const a=za(o,t,i);a&&s.push(a)}return s},Va=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...$a(i,I(t,n)))}return s},dt=e=>e?.getKind()===d.TrueKeyword,Ua=e=>e?.getKind()===d.FalseKeyword,qa=e=>e!==void 0&&r.isNumericLiteral(e)&&e.getLiteralValue()===0,Wa=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Ha=e=>!e||!r.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>r.isCallExpression(t)&&b(t.getExpression())==="scim"),ja=e=>e!==void 0&&r.isCallExpression(e)&&Wa.has(b(e.getExpression())??""),Ga=e=>!e||!r.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>r.isStringLiteral(t)&&t.getLiteralText()==="*"),Ya=e=>{const t=T(e,"advanced"),s=T(e,"emailAndPassword"),n=T(e,"session");return{analyzable:!0,disableCsrfCheck:dt(T(t,"disableCSRFCheck")),emailPasswordEnabled:dt(T(s,"enabled")),requireEmailVerification:dt(T(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Ha(T(e,"plugins"))&&ja(T(e,"database")),secureCookiesDisabled:Ua(T(t,"useSecureCookies")),sessionFreshAgeZero:qa(T(n,"freshAge")),trustedOriginsWildcard:Ga(T(e,"trustedOrigins"))}},Qa=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Xa=(e,t)=>{if(b(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?Ya(s):Qa();return{scope:v(e),file:t,line:e.getStartLineNumber(),...i}},Ja=(e,t)=>Xi(e,t,Xa),Za=(e,t)=>{if(!r.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return Sn(e.getExpression(),t.matchReceiver)?s:void 0},ec=(e,t,s)=>{const n=Za(e.getExpression(),s);if(n===void 0)return;const i=e.getArguments()[s.argIndex];if(!(!i||!$(i)||ne(i))&&!(s.requireUnmodifiedReach===!0&&!oa(i)))return{scope:v(e),file:t,line:e.getStartLineNumber(),method:n}},Ge=(e,t,s)=>C(e,t,(n,i)=>ec(n,i,s)),tc=new Set(["content","pdf","scrape","screenshot"]),sc=(e,t)=>Ge(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:tc}),nc=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),ic=new Set(["RateLimiter"]),rc=new Set(["extend"]),bs="lunora",oc=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],_n=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=y(i);t.push(o),i.getInitializer()?.getKind()===d.TrueKeyword&&s.push(o);continue}(r.isShorthandPropertyAssignment(i)||r.isMethodDeclaration(i))&&t.push(y(i))}return{analyzable:!n,presentKeys:t,trueKeys:s}},Pt=e=>e&&r.isObjectLiteralExpression(e)?_n(e):{analyzable:!1,presentKeys:[],trueKeys:[]},ac=e=>{const t=e&&(r.isArrowFunction(e)||r.isFunctionExpression(e))?e:void 0,s=t&&gn(t.getBody());return s?_n(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},cc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=b(n.getExpression());i!==void 0&&(nc.has(i)?s.push({callee:i,file:t,line:n.getStartLineNumber(),...Pt(n.getArguments()[0])}):rc.has(i)&&s.push({callee:i,file:t,line:n.getStartLineNumber(),...ac(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(d.NewExpression)){const i=b(n.getExpression());i===void 0||!ic.has(i)||s.push({callee:i,file:t,line:n.getStartLineNumber(),...Pt(n.getArguments()[0])})}return s},lc=(e,t)=>{for(const s of oc){const n=E(t,s);if(!F(n))continue;const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=[];for(const a of i.getDescendantsOfKind(d.CallExpression))b(a.getExpression())===bs&&o.push({callee:bs,file:s,line:a.getStartLineNumber(),...Pt(a.getArguments()[0])});return o}return[]},dc=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of Ue(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);s.push(...cc(o,n))}return s.push(...lc(e,fn(t))),s},Ns="ctx.containers.",uc=e=>{if(!e.startsWith(Ns))return!1;const t=e.slice(Ns.length);return t.length>0&&!t.includes(".")},fc=(e,t)=>Ge(e,t,{argIndex:0,matchReceiver:uc,methods:new Set(["get"])}),gc=new Set(["allow","deny","setAllowed"]),pc=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return!1;const s=M(t,"enableInternet");return s!==void 0&&r.isPropertyAssignment(s)&&r.isTrueLiteral(s.getInitializerOrThrow())},mc=(e,t)=>{const s=e.getExpression();if(!(!r.isPropertyAccessExpression(s)||s.getName()!=="start"||!pc(e)))return{detail:"enableInternet: true",scope:v(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},hc=(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:v(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},vc=(e,t)=>mc(e,t)??hc(e,t),Ec=(e,t)=>C(e,t,vc),xc=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="count")return;const s=t.getExpression();if(L(s)){const n=e.getArguments()[0];return n&&r.isStringLiteral(n)?n.getLiteralText():""}return r.isPropertyAccessExpression(s)&&L(s.getExpression())?s.getName():void 0},Sc=e=>{const t=e.getExpression(),s=r.isPropertyAccessExpression(t)?t.getExpression():void 0;return e.getArguments()[s!==void 0&&L(s)?1:0]},Ac=new Set(["baseWhere","relationBaseWhere","restrictsCounts","where"]),yc=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=>Ac.has(n))||t.some(n=>n==="AND"||n==="OR"||n==="NOT")?void 0:t},bc=(e,t,s)=>{const n=new Map(s.map(i=>[i.name,i.aggregateIndexed===!0]));return C(e,t,(i,o)=>{const a=xc(i);if(a===void 0)return;const c=yc(Sc(i));return{file:o,indexed:n.get(a)!==!1,...c===void 0?{}:{filterFields:c},line:i.getStartLineNumber(),scope:v(i),table:a}})},Nc=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Pc=e=>{const t=e.getExpression();if(!r.isIdentifier(t))return;const s=t.getText();return Nc.has(s)?s:void 0},wc=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=y(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(y(n))}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Ic=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of Ue(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);for(const a of o.getDescendantsOfKind(d.CallExpression)){const c=Pc(a);if(c===void 0)continue;const l=a.getArguments()[0],u=l&&r.isObjectLiteralExpression(l)?wc(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},Cc=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Tc=new Set(["dbRateLimit","rateLimit"]),Oc=e=>{const t=mn(e);if(!t)return!1;const s=M(t,"failOpen");return s!==void 0&&r.isPropertyAssignment(s)&&s.getInitializer()?.getKind()===d.TrueKeyword},kc=(e,t)=>{const s=b(e.getExpression());if(s===void 0)return;const n=Cc.get(s);if(n!==void 0)return{callee:s,scope:v(e),failOpen:Oc(e.getArguments()[n]),file:t,limitName:Tc.has(s)?pn(e):"",line:e.getStartLineNumber()}},Rc=(e,t)=>C(e,t,kc),Fc=e=>{const t=e.getInitializer();if(!t||!r.isCallExpression(t))return;const s=X(t);if(s?.kind!=="query")return;const n=Ji(t,s.receiver);return n?{exportName:V(e)??e.getName(),handler:n}:void 0},Ps=e=>{const t=e.getParent();return t&&r.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},Lc=e=>{const t=Ps(e);if(!t)return"ctx.flags";if(t.getName()==="details"){const s=Ps(t);return s?`ctx.flags.details.${s.getName()}`:"ctx.flags.details"}return`ctx.flags.${t.getName()}`},Dc=(e,t)=>{const s=[];for(const n of We(e.handler,"flags"))s.push({callee:Lc(n),exportName:e.exportName,file:t,line:n.getStartLineNumber()});return s},Mc=(e,t)=>{const s=[];for(const n of j(e)){const i=Fc(n);i&&s.push(...Dc(i,t))}return s},_c=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Mc(i,I(t,n)))}return s},Kc=e=>!r.isPropertyAccessExpression(e)||e.getName()!=="boolean"?!1:W(e.getExpression(),["flags"]),Bc=e=>{if(e?.getKind()===d.TrueKeyword)return!0;if(e?.getKind()===d.FalseKeyword)return!1},zc=(e,t)=>{if(!Kc(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(r.isStringLiteral(s)||r.isNoSubstitutionTemplateLiteral(s)))return;const i=s.getLiteralValue(),o=Bc(n);if(!(i.length===0||o===void 0))return{defaultValue:o,scope:v(e),file:t,key:i,line:e.getStartLineNumber()}},$c=(e,t)=>C(e,t,zc),Vc=e=>{const t=e.getExpression();return r.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Uc=e=>{const t=e.getArguments()[0];return t&&r.isStringLiteral(t)?t.getLiteralText():""},qc=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=I(t,n);for(const a of i.getDescendantsOfKind(d.CallExpression))Vc(a)&&s.push({file:o,indexName:Uc(a),line:a.getStartLineNumber()})}return s},xe=e=>e!==void 0&&(r.isArrowFunction(e)||r.isFunctionExpression(e))?e:void 0,Kn=e=>{const t=e.getArguments()[0],s=xe(t);if(s!==void 0)return s;if(t===void 0||!r.isObjectLiteralExpression(t))return;const n=M(t,"handler");return n!==void 0&&r.isPropertyAssignment(n)?xe(n.getInitializer()):void 0},Wc=new Set(["delete","get","head","options","patch","post","put"]),Hc=new Set(["handler","stream"]),jc=new Set(["runAction","runMutation"]),Gc=new Set(["delete","insert","insertManyUnsafe","patch","patchIf","replace"]),Se=(e,t)=>e!==void 0&&r.isIdentifier(e)&&e.getText()===t,Bn=(e,t)=>{if(!(e===void 0||!r.isObjectBindingPattern(e))){for(const s of e.getElements())if(se(s)===t){const i=s.getNameNode();return r.isIdentifier(i)?i.getText():void 0}}},ws=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?r.isIdentifier(s)?s.getText():void 0:Bn(s,"ctx")},Is=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&r.isIdentifier(s)?s.getText():void 0:Bn(s,"request")},Cs=(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(jc.has(a)&&Se(c,t))return a;if(Gc.has(a)&&r.isPropertyAccessExpression(c)&&c.getName()==="db"&&Se(c.getExpression(),t))return`db.${a}`}},Ts=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(d.PropertyAccessExpression))if(n.getName()==="auth"&&Se(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(d.VariableDeclaration)){const i=n.getNameNode();if(!(!r.isObjectBindingPattern(i)||!Se(n.getInitializer(),t))){for(const o of i.getElements())if(se(o)==="auth")return!0}}return!1},Yc=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,Qc=(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"&&Se(n.getExpression(),t)},Xc=e=>[...r.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(d.StringLiteral).map(t=>t.getLiteralText())],zn=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:Xc(s)},Jc=(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)?zn(t,a.getText()):[]}return[]},Zc=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=zn(s,t.getText());return n.length>0?n:Jc(t,s)},Os=(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=>Qc(i,t)&&Zc(i).some(o=>Yc.test(o)))},el=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!Hc.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(Wc.has(i)){const o=n.getExpression();return r.isIdentifier(o)&&o.getText()==="httpRoute"?i.toUpperCase():void 0}s=n.getExpression()}},tl=(e,t)=>{const s=e.getExpression();if(r.isIdentifier(s)&&s.getText()==="httpAction"){const c=xe(e.getArguments()[0]),l=c&&ws(c,!0);if(!c||l===void 0||Os(c,Is(c,!0)))return;const u=Cs(c,l);return u===void 0?void 0:{scope:v(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:Ts(c,l),sideEffect:u}}const n=el(e);if(n===void 0)return;const i=xe(e.getArguments()[0]),o=i&&ws(i,!1);if(!i||o===void 0||Os(i,Is(i,!1)))return;const a=Cs(i,o);return a===void 0?void 0:{scope:v(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:Ts(i,o),sideEffect:a}},sl=(e,t)=>C(e,t,tl),nl=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),il=new Set(["append","set"]),$n=e=>e!==void 0&&(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",ks=(e,t)=>(r.isCallExpression(e)?[e,...e.getDescendantsOfKind(d.CallExpression)]:e.getDescendantsOfKind(d.CallExpression)).some(n=>nl.has(b(n.getExpression())??"")&&ke(n,t)),rl=(e,t)=>{if(ks(e,t))return!0;const s=H(e);return s!==void 0&&ks(s,t)},wt=(e,t)=>aa(e,t)&&!rl(e,t),ol=e=>{if(r.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=H(e);return t!==void 0&&r.isNewExpression(t)&&b(t.getExpression())==="Headers"},_e=e=>{if(e===void 0)return;if(r.isObjectLiteralExpression(e))return e;const t=H(e);return t!==void 0&&r.isObjectLiteralExpression(t)?t:void 0},Ut=(e,t,s)=>{for(const n of e.getProperties())if(r.isPropertyAssignment(n)){const i=n.getInitializer();i!==void 0&&wt(i,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:$n(n.getNameNode()),line:i.getStartLineNumber(),via:t})}else if(r.isShorthandPropertyAssignment(n)){const i=n.getNameNode();wt(i,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:y(n),line:i.getStartLineNumber(),via:t})}else if(r.isSpreadAssignment(n)){const i=_e(n.getExpression());i!==void 0&&Ut(i,t,s)}},Vn=(e,t)=>{const s=_e(e);if(s===void 0)return;const n=M(s,"headers");if(n===void 0||!r.isPropertyAssignment(n))return;const i=_e(n.getInitializer());i!==void 0&&Ut(i,"response-init",t)},al=(e,t)=>{const s=b(e.getExpression());if(s==="Response")Vn(e.getArguments()[1],t);else if(s==="Headers"){const n=_e(e.getArguments()[0]);n!==void 0&&Ut(n,"headers-ctor",t)}},cl=(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"){Vn(e.getArguments()[1],t);return}if(il.has(n)&&ol(i)){const o=e.getArguments()[1];o!==void 0&&wt(o,t.requestName)&&t.rows.push({scope:t.scope,file:t.relativePath,headerName:$n(e.getArguments()[0]),line:o.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},ll=(e,t)=>{for(const s of e.getDescendantsOfKind(d.NewExpression))al(s,t);for(const s of e.getDescendantsOfKind(d.CallExpression))cl(s,t)},dl=(e,t)=>{const s=e.getExpression();if(!r.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=xe(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 ll(n,{scope:v(e),relativePath:t,requestName:o.getText(),rows:a}),a},ul=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression))s.push(...dl(n,t));return s},fl=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ul(i,I(t,n)))}return s},Un="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 He(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},pl=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&&He(n.getModuleSpecifierValue())}return!1},ml=e=>{if(r.isIdentifier(e))return gl(e);if(r.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&r.isIdentifier(t)&&pl(t)}return!1},hl=e=>{const t=[];for(const s of e.getVariableDeclarations()){const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!ml(n.getExpression()))continue;const o=s.getNameNode();if(!r.isIdentifier(o)){if(s.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw ye(o,"defineIdentity exports must be plain named exports (no destructuring)")}const a=xn(s,"member");a!==void 0&&t.push({exportName:a})}return t},vl=(e,t)=>{const s=E(t,Un);if(!F(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=hl(n);if(i.length!==0){if(i.length>1)throw ye(n,`lunora/identity.ts declares ${i.length.toString()} defineIdentity() contracts (${i.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return i[0]}},El=new Set(["auth","context.auth"]),xl="userId",Sl=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(y(s))}return t},Al=(e,t)=>{const s=E(t,Un);if(!F(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const i of n.getDescendantsOfKind(d.CallExpression)){if(b(i.getExpression())!=="defineIdentity")continue;const[o]=i.getArguments();return o&&r.isObjectLiteralExpression(o)?Sl(o):void 0}},Rs=e=>{if(e===void 0||!r.isPropertyAccessExpression(e)||e.getName()!=="identity")return;const t=e.getExpression();return El.has(t.getText())||W(t,["auth"])?e:void 0},yl=e=>{if(r.isPropertyAccessExpression(e)&&Rs(e.getExpression())!==void 0)return e.getName();if(r.isElementAccessExpression(e)&&Rs(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&r.isStringLiteral(t)?t.getLiteralValue():void 0}},Fs=(e,t,s)=>{const n=yl(e);return n===void 0?void 0:{declared:n===xl||s.has(n),file:t,key:n,line:e.getStartLineNumber(),scope:v(e)}},bl=(e,t)=>{const s=Al(e,t);return s===void 0?[]:[...Z(e,t,d.PropertyAccessExpression,(n,i)=>Fs(n,i,s)),...Z(e,t,d.ElementAccessExpression,(n,i)=>Fs(n,i,s))]},Nl=(e,t)=>{if(b(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=T(s,"key");if(!(!n||!$(n)||ne(n)))return{scope:v(e),file:t,line:e.getStartLineNumber()}},Pl=(e,t)=>C(e,t,Nl),wl=new Set(["delete","get","getRaw","getWithMetadata","put"]),Il=(e,t,s=[])=>{const n=Ge(e,t,{argIndex:0,matchReceiver:i=>i==="ctx.kv"||i.startsWith("ctx.kv."),methods:wl});return Mt(n,s)},Cl=new Set(["queue","send"]),Ls=new Set(["bcc","cc","to"]),Tl=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();if(!Cl.has(t))return;const s=e.getExpression();return W(s,["mail"])||W(s,["email"])?t:void 0},Ol=e=>r.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(r.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return Ls.has(y(t))&&$(n)&&!ne(n)}if(!r.isPropertyAssignment(t)||!Ls.has(y(t)))return!1;const s=t.getInitializer();return s!==void 0&&$(s)&&!ne(s)}):!1,kl=(e,t)=>{const s=Tl(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!Ol(n)))return{scope:v(e),file:t,line:e.getStartLineNumber(),method:s}},Rl=(e,t)=>C(e,t,kl),Fl=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!r.isObjectLiteralExpression(n))return[];const i=[];for(const o of n.getProperties()){const a=Me(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=Me(l);if(u===void 0)continue;const f=wn(l);f!=="custom"&&i.push({column:u,exportName:t,file:s,line:l.getStartLineNumber(),strategy:f,table:a})}}return i},Ll=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&r.isCallExpression(s)?X(s):void 0;return n?.receiver?Kt(n.receiver).flatMap(i=>Fl(i,V(e)??e.getName(),t)):[]},Dl=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=I(t,n);for(const a of j(i))s.push(...Ll(a,o))}return s},Ml=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return L(s)},_l=e=>{const t=e.getArguments()[0];if(t===void 0||!r.isObjectLiteralExpression(t))return;const s=M(t,"server");if(s!==void 0)return r.isPropertyAssignment(s)?s.getInitializer():s},Kl=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==d.CallExpression)return;const s=t;return yr(s.getExpression())?s:void 0},Bl=e=>{const t=Kl(e),s=t===void 0?void 0:_l(t);if(s===void 0)return[];const n=e.getNameNode(),i=r.isIdentifier(n)?V(e)??n.getText():"";return s.getDescendantsOfKind(d.CallExpression).filter(o=>Ml(o)).map(o=>({exportName:i,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},zl=e=>e.getVariableDeclarations().flatMap(t=>Bl(t)),$l=(e,t)=>{const s=E(t,Ar);if(!F(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return zl(n)},Vl=new Set(["delete","get","patch"]),Ul=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),ql=new Set(["auth","identity","session","user"]),Wl=new Set([d.EqualsEqualsEqualsToken,d.EqualsEqualsToken,d.ExclamationEqualsEqualsToken,d.ExclamationEqualsToken]),Hl=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!L(t.getExpression()))return;const s=e.getArguments()[0];return s&&r.isStringLiteral(s)?s.getLiteralText():""},jl=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},Gl=(e,t)=>e.getDescendantsOfKind(d.Identifier).some(s=>s.getText()===t),Yl=e=>r.isThrowStatement(e)||r.isReturnStatement(e)||e.getDescendantsOfKind(d.ThrowStatement).length>0||e.getDescendantsOfKind(d.ReturnStatement).length>0,Ql=(e,t)=>e.getDescendantsOfKind(d.IfStatement).some(s=>Gl(s.getExpression(),t)&&Yl(s.getThenStatement())),Xl=(e,t)=>{for(const s of e.getDescendantsOfKind(d.CallExpression)){const n=s.getExpression();if(!r.isPropertyAccessExpression(n))continue;const i=n.getName();if(!Vl.has(i))continue;const o=n.getExpression();if(!(L(o)||r.isPropertyAccessExpression(o)&&L(o.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&r.isIdentifier(c)&&c.getText()===t)return i}},Jl=e=>e.getDescendantsOfKind(d.CallExpression).some(t=>t.getArguments().some(s=>_t(Lt(s))!==void 0)),Zl=e=>e.getDescendantsOfKind(d.BinaryExpression).some(t=>Wl.has(t.getOperatorToken().getKind())?r.isPropertyAccessExpression(t.getLeft())||r.isPropertyAccessExpression(t.getRight()):!1),ed=e=>{for(const t of e.getDescendantsOfKind(d.Identifier))if(Ul.has(t.getText()))return!0;return[...ql].some(t=>We(e,t).length>0)?!0:Jl(e)||Zl(e)},td=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!r.isCallExpression(s))return[];const n=X(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const i=Kn(s);if(i===void 0)return[];const o=n.receiver!==void 0&&bn(n.receiver,"use","rls"),a=ed(i),c=new Set,l=[];for(const u of i.getDescendantsOfKind(d.CallExpression)){const f=Hl(u);if(f===void 0)continue;const g=jl(u);if(g===void 0||c.has(g)||!Ql(i,g))continue;const p=Xl(i,g);p!==void 0&&(c.add(g),l.push({exportName:V(e)??e.getName(),file:t,line:u.getStartLineNumber(),mentionsOwnership:a,sinkMethod:p,table:f,usesRls:o,visibility:n.visibility}))}return l},sd=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=I(t,n);for(const a of j(i))s.push(...td(a,o))}return s},qn=(e,t)=>{const s=r.isIdentifier(e)&&t!==void 0?O(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},nd=e=>{const t=w(e),s=t.getParent();return(r.isPropertyAccessExpression(s)||r.isElementAccessExpression(s))&&s.getExpression()===t&&!qe(s)},id=e=>{const t=w(e).getParent();return r.isVariableDeclaration(t)&&r.isObjectBindingPattern(t.getNameNode())},rd=e=>{const s=w(e).getParent();if(r.isSpreadAssignment(s)||r.isSpreadElement(s)){const n=s.getParent();return(r.isObjectLiteralExpression(n)||r.isArrayLiteralExpression(n))&&!qe(n)}return r.isTemplateSpan(s)&&!r.isTaggedTemplateExpression(s.getParent().getParent())},Ke=e=>{const t=O(e);return t===void 0||nr(t.getSourceFile())},It=(e,t)=>{const s=w(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"&&Ke(o);if(qn(Lt(o),t))return!(r.isPropertyAccessExpression(o)&&An.has(o.getName()))||r.isExpressionStatement(w(r.isAwaitExpression(n.getParent())?n.getParentOrThrow():n).getParent());if(!r.isPropertyAccessExpression(o))return!1;const a=o.getExpression();if(!r.isIdentifier(a)||!Ke(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}},Re={kind:"opaque"},od={kind:"unreached"},ad=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},Ct=e=>{const t=h(e);if(r.isArrowFunction(t)||r.isFunctionExpression(t))return t;const s=r.isIdentifier(t)?O(t):void 0;if(s?.getSourceFile()!==e.getSourceFile())return;if(r.isFunctionDeclaration(s)){const i=ad(s);return i===void 0||Dt(i)?void 0:i}const n=ee(s)?h(s.getInitializer()):void 0;return r.isArrowFunction(n)||r.isFunctionExpression(n)?n:void 0},Wn=(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?Re:c===void 0?a.some(l=>l.isRestParameter())?Re:od:c.isRestParameter()?Re:{kind:"parameter",parameter:c}},cd=e=>{const t=w(e),s=t.getParent();if(!r.isCallExpression(s)||s.getExpression()===t)return;const n=Ct(s.getExpression());return n===void 0?Re:Wn(n,s,t)},ld=new Set(["__defineGetter__","__defineSetter__","__proto__"]),dd=e=>r.isForInStatement(e)?e.getExpression():r.isConditionalExpression(e)?e.getCondition():r.isElementAccessExpression(e)?e.getArgumentExpression():void 0,Hn=e=>{const t=w(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=dd(s);if(n!==void 0)return S(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},ud=4,jn=(e,t,s=0)=>{if(sr(e))return!0;if(nd(e)){const i=w(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||!ld.has(c)}if(id(e)||rd(e)||Hn(e)||It(e,t))return!0;const n=cd(e);return n?.kind==="unreached"||n?.kind==="parameter"&&fd(n.parameter,s+1)},Ds=new WeakMap,fd=(e,t=0)=>{const s=e.getNameNode();if(!r.isIdentifier(s))return!0;const n=Ds.get(e.compilerNode);if(n!==void 0)return n;if(t>ud)return!1;const o=(s.getSymbol()?.getDeclarations().length??0)===1&&e.getParentOrThrow().getDescendantsOfKind(d.Identifier).every(a=>a===s||a.getText()!==s.getText()||O(a)?.compilerNode!==e.compilerNode||jn(a,void 0,t));return(o||t===0)&&Ds.set(e.compilerNode,o),o},Ms=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=O(i)?.compilerNode;return o!==void 0&&(o===t.compilerNode||s!==void 0&&o===e.compilerNode)})},pd=(e,t,s)=>{const{context:n,impl:i}=e,o=Ms.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 p=g.getNameNode();return r.isIdentifier(p)?[p]:[]}),l=new Map(c.map(g=>[g.getText(),g.getParentOrThrow().compilerNode])),u=g=>r.isIdentifier(a)?jn(g,n):!qe(g),f=!gd(i,s)&&c.every(g=>(g.getSymbol()?.getDeclarations().length??0)===1)&&i.getDescendantsOfKind(d.Identifier).every(g=>{const p=g.getText();if(p==="arguments")return!1;const x=l.get(p);return x===void 0||c.includes(g)||O(g)?.compilerNode!==x?!0:u(g)});return Ms.set(i.compilerNode,f),f},_s=new WeakMap,md=e=>{let t=_s.get(e.compilerNode);return t===void 0&&(t=new Map(e.getVariableDeclarations().flatMap(s=>{const n=br(s);return n===void 0?[]:[[n.compilerNode,s]]})),_s.set(e.compilerNode,t)),t},hd=e=>{const t=md(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:V(n)??n.getName()};return a!==void 0&&pd(c,a,n)?{...c,parameter:a,pristine:!0}:{...c,parameter:a,pristine:!1}},ut="args",he=e=>{const t=hn(e);if(t!==void 0){const c=h(t.object);return r.isIdentifier(c)&&c.getText()===ut?t.member:void 0}if(!r.isIdentifier(e))return;const s=O(e);if(!r.isBindingElement(s)||s.getDotDotDotToken()!==void 0)return;const n=s.getParent();if(!r.isObjectBindingPattern(n))return;const i=n.getParent(),o=ee(i)?h(i.getInitializer()):void 0;return r.isBindingElement(i)&&se(i)===ut||r.isIdentifier(o)&&o.getText()===ut?se(s):void 0},vd=new Set(["auth","identity","user"]),Tt=e=>{const t=i=>{const o=_t(i);return o!==void 0&&o.length>0&&vd.has(o[0]??"")},s=h(e)??e;if(t(s))return!0;const n=H(s);return n!==void 0&&t(n)},Gn=(e,t=2)=>{const s=new Set;for(const n of[e,...e.getDescendants()]){const i=he(n);i!==void 0&&s.add(i);const o=t>0&&r.isIdentifier(n)?H(n):void 0;if(o!==void 0)for(const a of Gn(o,t-1))s.add(a)}return s},Fe=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[...Fe(n),...Fe(i)];if(s===d.AmpersandAmpersandToken){const l=(u,f)=>{const g=he(h(u)??u);return g===void 0?[]:Fe(f).filter(p=>p===g)};return[...l(n,i),...l(i,n)]}if(s!==d.ExclamationEqualsEqualsToken&&s!==d.ExclamationEqualsToken)return[];const o=[],a=he(h(n)??n),c=he(h(i)??i);return a!==void 0&&Tt(i)&&o.push(a),c!==void 0&&Tt(n)&&o.push(c),o},Ed=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)&&fr(i.getExpression(),"defineIdentityGuard")},xd=e=>{if(!Ed(e.getExpression()))return[];const t=e.getArguments();return t.flatMap((s,n)=>{const i=he(h(s)??s),o=t.some((a,c)=>c!==n&&Tt(a));return i!==void 0&&o?[i]:[]})},Sd=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)},Ad=e=>r.isArrowFunction(e)||r.isFunctionExpression(e)||r.isFunctionDeclaration(e)||r.isMethodDeclaration(e),Ks=(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},yd=e=>r.isAwaitExpression(e.getParent())||e.getType().isVoid(),bd=(e,t)=>{const s=new Set;for(const n of e.getDescendantsOfKind(d.IfStatement))if(n.getEnd()<=t&&Ks(n,e)&&Sd(n.getThenStatement()))for(const i of Fe(n.getExpression()))s.add(i);for(const n of e.getDescendantsOfKind(d.CallExpression))if(n.getEnd()<=t&&yd(n)&&Ks(n,e))for(const i of xd(n))s.add(i);return s},Nd=(e,t)=>{const s=Gn(t);if(s.size===0)return!1;const n=e.getFirstAncestor(Ad);if(n===void 0)return!1;const i=bd(n,e.getStart());return[...s].every(o=>i.has(o))},Pd=new Set(["at","concat","filter","find","findLast","flat","reverse","slice","sort","toReversed","toSorted"]),wd=new Map([["Array",new Set(["from","of"])],["Object",new Set(["entries","values"])]]),Ot=new Set(["catch","every","filter","finally","find","findIndex","findLast","findLastIndex","flatMap","forEach","map","reduce","reduceRight","some","sort","then"]),Yn=e=>e.getNameNode().getDescendantsOfKind(d.BindingElement).filter(t=>r.isIdentifier(t.getNameNode())),Id=e=>{const t=w(e),s=t.getParent();if(r.isVariableDeclaration(s))return S(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},Cd=e=>{const t=Id(e);return t===void 0?void 0:r.isIdentifier(t.getNameNode())?r.isForOfStatement(t.getParent().getParent())||ee(t)?[t]:void 0:Yn(t)},ve=e=>e.isUnion()?e.getUnionTypes().every(t=>ve(t)):e.isIntersection()?e.getIntersectionTypes().some(t=>ve(t)):!e.isAny()&&!e.isUnknown()&&!e.isObject()&&!e.isTypeParameter(),Be=(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)},Le=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]},Td=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)&&wd.get(s.getText())?.has(t.getName())===!0&&Ke(s)},Od=e=>{const t=St(e);if(!r.isArrowFunction(t)&&!r.isFunctionExpression(t))return;const s=w(t),n=s.getParent();return r.isCallExpression(n)&&n.getArguments().includes(s)&&Be(n,yn)?n:void 0},kd=(e,t)=>{if(!(r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e))||e.getExpression()!==t)return;const s=w(e),n=s.getParent();return!r.isCallExpression(n)||n.getExpression()!==s?e:Be(n,Pd,t)?n:void 0},Rd=(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},Fd=(e,t)=>{if(r.isArrayLiteralExpression(e))return e;const n=r.isSpreadElement(e)||r.isSpreadAssignment(e)||r.isShorthandPropertyAssignment(e)||r.isPropertyAssignment(e)&&S(e.getInitializer(),t)?e.getParent():void 0;return r.isArrayLiteralExpression(n)||r.isObjectLiteralExpression(n)?n:void 0},Bs=e=>{const t=w(e),s=t.getParent();if(s===void 0)return;const n=r.isCallExpression(s)&&s.getArguments().includes(t)&&Td(s);return kd(s,t)??Rd(s,t)??Fd(s,t)??(n?s:Od(t))},Ld=5e4,Qn=()=>({inProgress:new Set,verdicts:new Map});class Dd{cuts=0;work=0;reset(){this.work=0}cut(){return this.cuts+=1,!0}spend(){return this.work+=1,this.work>Ld&&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 Md=8,_d=8;class Kd{budget;scope;taint;verdicts=Qn();constructor(t,s,n){this.scope=t,this.budget=s,this.taint=n}isCompromised(t){return this.flowHasCompromisingUse(t)&&!ve(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)?Yn(t):[])i(l,s);return!1}if(this.budget.spend())return!0;const a=(l,u)=>u&&s>=Md?this.budget.cut():(i(l,u?s+1:s),!1);return this.taint.referencesTo(t,o.getText()).some(l=>this.valueCompromises(w(l),!0,a,0))&&(t===n||!ve(t.getType()))}valueCompromises(t,s,n,i){let o=t;for(let p=Bs(o);p!==void 0;p=Bs(o)){if(r.isCallExpression(p)&&this.callbackCompromises(p,n))return!0;o=w(p)}const a=o.getParent(),c=o===t&&s,l=()=>!c&&ve(o.getType());if(qe(o))return!c&&(!r.isBinaryExpression(a)||this.taint.isTaintedValue(a.getRight(),!1));const u=Cd(o);if(u!==void 0)return u.some(p=>n(p,!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=w(t).getParent();if(n>=_d)return this.budget.cut();if(r.isCallExpression(i))return i.getExpression()===w(t)?this.valueCompromises(i,!1,s,n+1):!Be(i,Ot);const o=r.isFunctionDeclaration(t)?t:i,a=r.isFunctionDeclaration(o)||ee(o)?o.getNameNode():void 0;return o===void 0||!r.isIdentifier(a)?!0:this.taint.referencesTo(o,a.getText()).some(c=>{const l=w(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=>Le(i)===void 0).some(i=>this.taint.isTaintedValue(i,!1))||this.callbackCompromises(t,s)}callbackCompromises(t,s){const n=Be(t,Ot)?t.getArguments()[0]:void 0;if(n===void 0)return!1;const i=Ct(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!It(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(It(s,this.scope.context))return!1;const i=Ct(t.getExpression()),o=i===void 0?void 0:Wn(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)||Hn(t)||S(St(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=St(t);return S(s,this.scope.impl)?void 0:s}}const Bd=new Set(["at","every","filter","finally","find","findIndex","findLast","findLastIndex","forEach","order","slice","some","sort","withIndex","withSearchIndex"]),zd=e=>{const t=h(e);if(!r.isIdentifier(t))return r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t);const s=O(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)},$d=new Set(["all","allSettled","any","race"]),zs=e=>r.isParameterDeclaration(e)?e:r.isBindingElement(e)?e.getFirstAncestorByKind(d.Parameter):void 0,ft=8;class Vd{budget=new Dd;referencesByDeclaration=new Map;referencesByName=new Map;scope;verdicts=Qn();walk;variableDepth=0;queryDepth=0;constructor(t){this.scope=t,this.walk=new Kd(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,ft)?!1:(r.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(i=>ir(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=O(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=w(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)||!Ot.has(g.getName()))return!0;const p=a.getArguments().filter(x=>x!==o);return this.isTaintedValue(g.getExpression(),!0)||p.some(x=>this.isTaintedValue(x,!1))}const c=r.isVariableDeclaration(a)&&ee(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 p=w(g),x=p.getParent();return!r.isCallExpression(x)||x.getExpression()!==p||this.isCallSiteTainted(x,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"&&Ke(i)&&$d.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:Le(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=O(t),i=zs(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&&An.has(i)?!1:i!==void 0&&yn.has(i)?this.isCallbackResultServerScoped(t,s)?void 0:!1:t.getArguments().some(a=>Le(a)!==void 0)&&(i===void 0||!Bd.has(i))?!1:void 0}isCallbackResultServerScoped(t,s){const n=(i,o=[])=>{const a=Lt(i),c=r.isIdentifier(a)?zs(O(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=Le(i);if(o===void 0)return!zd(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=Zi(t,u=>this.callChainVerdict(u,s)),i=n.root;if(n.verdict!==void 0)return n.verdict;if(qn(i,this.scope.context))return!0;const o=r.isIdentifier(i)?O(i):void 0,a=r.isBindingElement(o)?o.getFirstAncestorByKind(d.VariableDeclaration):o,c=ee(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=Dt(t);if(n===void 0||i)return!0;if(this.isRootedInContext(n,ft))return!1;if(this.variableDepth>=ft)return this.budget.cut();this.variableDepth+=1;try{return this.isTaintedValue(n,!1)}finally{this.variableDepth-=1}},this.verdicts)}}const $s=new WeakMap,Ud=e=>{const t=$s.get(e.impl.compilerNode);if(t!==void 0)return t;const s=new Vd(e);return $s.set(e.impl.compilerNode,s),s},qd=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Wd=new Set(["insert","insertManyUnsafe","patch","replace"]),Hd=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();return Wd.has(t)&&cr(e.getExpression())?t:void 0},jd=(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},Gd=(e,t)=>{const s=hn(e);return s?.member===t?h(s.object):void 0},Vs=(e,t)=>r.isIdentifier(e)&&O(e)?.compilerNode===t.compilerNode,Xn=(e,t,s,n=1)=>{const i=Gd(e,s);if(i!==void 0)return Vs(i,t);const o=r.isIdentifier(e)?O(e):void 0;if(r.isBindingElement(o)){const c=o.getParent(),l=c.getParent();return o.getDotDotDotToken()===void 0&&se(o)===s&&r.isObjectBindingPattern(c)&&(l.compilerNode===t.compilerNode||ee(l)&&Vs(h(l.getInitializer()),t))}const a=ee(o)?o.getInitializer():void 0;return n>0&&a!==void 0&&Xn(a,t,s,n-1)},kt=e=>{const t=h(e)??e;return r.isConditionalExpression(t)?[...kt(t.getWhenTrue()),...kt(t.getWhenFalse())]:[t]},Yd=(e,t,s)=>{const n=[],i=s===void 0?void 0:Ud(s);for(const o of e.getProperties()){let a,c;if(r.isPropertyAssignment(o)?(a=y(o),c=o.getInitializer()):r.isShorthandPropertyAssignment(o)&&(a=y(o),c=o.getNameNode()),a===void 0||c===void 0||!qd.has(a))continue;const l=kt(c).filter(f=>i===void 0?$(f)&&!lr(f):i.isTaintedValue(f,!0));if(l.length>0){const f=t.ownerField===a&&s?.pristine===!0&&Xn(c,s.parameter,a),g=l.every(p=>Nd(t.call,p));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},Qd=(e,t,s)=>{const n=Hd(e.getExpression()),i=n===void 0?void 0:e.getArguments()[1];if(n===void 0||i===void 0)return[];const o=jd(i,n);if(o.length===0)return[];const a=v(e),c=hd(e),l={call:e,method:n,ownerField:c===void 0?void 0:s(c.mutatorName),relativePath:t,scope:a};return o.flatMap(u=>Yd(u,l,c))},Xd=(e,t,s=[],n=[])=>{const i=new Map(n.map(c=>[`${c.filePath}:${c.exportName}`,c.owner])),o=C(e,t,(c,l)=>Qd(c,l,u=>i.get(`${l}:${u}`))),a=new Map(s.map(c=>[`${c.filePath}:${c.exportName}`,c.adminOnly===!0]));return Mt(o,s).map(c=>rr(c.scope)?.every(f=>a.get(`${c.file}:${f}`)===!0)===!0?{...c,adminOnly:!0}:c)},Jd=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Zd=e=>e&&r.isNumericLiteral(e)?Number(e.getText()):void 0,eu=e=>{const t=M(e,"webhookToleranceSeconds");return t&&r.isPropertyAssignment(t)?Zd(t.getInitializer()):void 0},tu=(e,t)=>{const s=b(e.getExpression());if(s===void 0||!Jd.has(s))return;const[n]=e.getArguments(),i=n&&r.isObjectLiteralExpression(n)?eu(n):void 0;return{callee:s,scope:v(e),file:t,line:e.getStartLineNumber(),...i===void 0?{}:{toleranceSeconds:i}}},su=(e,t)=>C(e,t,tu),nu=new Map([["defineQueue",0],["defineSubscription",1],["defineWorkflow",0]]),iu=e=>{const t=e.getExpression();return r.isIdentifier(t)?t.getText():void 0},ru=(e,t)=>{const s=e.getArguments()[t];if(!s||!r.isObjectLiteralExpression(s))return;const n=M(s,"handler");if(n===void 0||!r.isPropertyAssignment(n))return;const i=n.getInitializer();if(i&&(r.isArrowFunction(i)||r.isFunctionExpression(i)))return i},Jn=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&r.isIdentifier(s)?s.getText():void 0},Zn=(e,t)=>e===t||e.startsWith(`${t}.`),ei=e=>{const t=e.getDescendantsOfKind(d.PropertyAccessExpression);return r.isPropertyAccessExpression(e)&&t.push(e),t},Us=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)},ti=e=>{const t=e.getDescendantsOfKind(d.Identifier).filter(s=>Us(s));return r.isIdentifier(e)&&Us(e)&&t.push(e),t},ou=e=>{if(!r.isVariableDeclaration(e))return[];const t=e.getNameNode();return r.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(d.BindingElement).map(s=>s.getName())},au=e=>{const t=Jn(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},cu=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:au(e),i=new Set,o=a=>ei(a).some(c=>n.some(l=>Zn(c.getText(),l)))?!0:ti(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 ou(a))i.add(l)}return{names:i,prefixes:n}},lu=(e,t)=>ei(e).some(s=>t.prefixes.some(n=>Zn(s.getText(),n)))?!0:ti(e).some(s=>t.names.has(s.getText())),du=e=>{const t=er(e);return t===void 0?void 0:{exportName:String(t.at(-1)),file:t.slice(0,-1).join("/")}},uu=(e,t,s)=>{const n=Jn(e,0);if(n===void 0)return[];const i=cu(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)||!vn.has(l.getName())||!o.has(l.getExpression().getText()))continue;const u=c.getArguments()[1];if(!u||!lu(u,i))continue;const f=du(c.getArguments()[0]);f!==void 0&&a.push({dispatchKind:t,file:s,scope:v(c),line:c.getStartLineNumber(),targetExport:f.exportName,targetFile:f.file})}return a},fu=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=iu(n),o=i===void 0?void 0:nu.get(i);if(o===void 0)continue;const a=ru(n,o);a!==void 0&&s.push(...uu(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(...fu(i,I(t,n)))}return s},qs={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},Ws=new Set(["account","credential","member","passkey","session","user"]),pu=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),mu=e=>{const s=pu(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return Ws.has(s)||Ws.has(n)},hu=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},vu=(e,t)=>{const{objects:s,opaque:n}=$t(e,t);return Ia(s).some(i=>hu(i))?!0:n?void 0:!1},Eu=e=>{const t=e.getArguments()[0];return!t||!r.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!M(t,"captcha"),usesRateLimit:!!M(t,"rateLimit")}},xu=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},De={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Su=e=>{const t=xu(e),s=t?b(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=Eu(t);return{...De,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in qs?{...De,[qs[s]]:!0}:De},Au=e=>{const t={...De};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=Su(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},yu=new Set(["insert","insertMany","insertManyUnsafe","replace"]),bu=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!yu.has(t.getName()))return!1;const s=t.getExpression();if(!L(s))return!1;const i=e.getArguments()[0];return!i||!(r.isStringLiteral(i)||r.isNoSubstitutionTemplateLiteral(i))?!1:mu(i.getLiteralText())},Nu=new Set(["create","publish","publishBatch","runAfter","runAt","send","sendBatch"]),Hs=new Set(["queues","scheduler","topics","workflows"]),Pu=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!Nu.has(t.getName()))return!1;let s=t.getExpression();for(;r.isCallExpression(s)||r.isElementAccessExpression(s)||r.isPropertyAccessExpression(s);){if(r.isPropertyAccessExpression(s)&&Hs.has(s.getName())&&dr(s.getExpression()))return!0;s=s.getExpression()}const n=_t(s);return n?.length===1&&Hs.has(n[0]??"")},wu=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return L(s)},si=new Set(["generateObject","generateText","streamObject","streamText"]),Iu=e=>{const t=b(e.getExpression());return t!==void 0&&si.has(t)},Cu=e=>{const t=b(e.getExpression());if(t===void 0||!si.has(t))return!1;const s=e.getArguments()[0];return!s||!r.isObjectLiteralExpression(s)||s.getProperties().some(n=>r.isSpreadAssignment(n))?!1:!M(s,"maxOutputTokens")},Tu=new Set(["log","span","trace"]),Ou=new Set(["ai"]),ku=new Set(["email","mail"]),Ru=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","topics","workflows"]),gt=(e,t)=>[...t].some(s=>We(e,s).length>0),ni=new Set([d.ArrowFunction,d.FunctionDeclaration,d.FunctionExpression,d.GetAccessor,d.MethodDeclaration,d.SetAccessor]),Fu=new Set(["every","filter","flatMap","forEach","map","some"]),Lu=new Set(["all","allSettled","race"]),ii=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(Fu.has(n))return t;const i=s.getExpression();if(r.isIdentifier(i)&&i.getText()==="Promise"&&Lu.has(n))return t},Du=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(ni.has(t.getKind())){const s=ii(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},Mu=e=>{let t=e.getParent();for(;t!==void 0;){if(r.isCallExpression(t)&&t.getExpression().getText()==="Promise.allSettled")return!0;if(ni.has(t.getKind())){if(t=ii(t),t===void 0)return!1;continue}t=t.getParent()}return!1},_u=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(p=>{const x=p.getExpression();return r.isIdentifier(x)&&x.getText()===l&&r.isAwaitExpression(p.getParent())}),g=u.getCatchClause();return f&&g!==void 0&&g.getDescendantsOfKind(d.ThrowStatement).length>0})},Ku=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}},Bu=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}},zu=e=>{let t=!1,s=!0;for(const n of[...Ru].flatMap(i=>We(e,i))){const i=Bu(n);i&&(t=!0,!Du(i)&&!Ku(i)&&!_u(i)&&!Mu(i)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},$u=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"}),js="lunora-advisor-exempt",Vu=/^[\s*/]+/u,Uu=/[\w-]/u,qu=e=>{const s=(e.getFirstAncestorByKind(d.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
2
2
  `);for(const n of s.split(`
3
3
  `)){const i=n.replace(Vu,"");if(!i.startsWith(js))continue;const o=i.slice(js.length);if(Uu.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:""}},Wu=e=>{const[t]=e.getArguments();if(t){if(r.isObjectLiteralExpression(t)){const s=M(t,"handler");return s?r.isPropertyAssignment(s)?s.getInitializer():r.isShorthandPropertyAssignment(s)?s.getNameNode():r.isMethodDeclaration(s)?s:void 0:void 0}return t}},Hu=(e,t)=>{const s=Wu(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)},ju=e=>{let t=!1,s=!1,n=!1,i=!1,o=!1;for(const l of e.getDescendantsOfKind(d.CallExpression))if(bu(l)&&(o=!0),Pu(l)&&(t=!0),wu(l)&&(i=!0),Iu(l)&&(s=!0),Cu(l)&&(n=!0),o&&t&&i&&n)break;const{handlesErrors:a,reachesOutbound:c}=zu(e);return{callsMail:gt(e,ku),emitsEvent:gt(e,Tu),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||gt(e,Ou),throwsBareError:$u(e),unboundedAiGeneration:n,usesInsertManyUnsafe:i,writesUserTable:o}},Gu=(e,t)=>{const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const n=X(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const i=n.receiver?Au(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},o=Hu(e,s);return{...o?ju(o):{},...qu(e),...i,analyzableBody:o!==void 0,exportName:V(e)??e.getName(),file:t,hasEmailArg:vu(s,n.receiver),kind:n.kind,visibility:n.visibility}},Yu=(e,t)=>{const s=[];for(const n of j(e)){const i=Gu(n,t);i&&s.push(i)}return s},Qu=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Yu(i,I(t,n)))}return s},Xu=new Set(["dbRateLimit","rateLimit"]),Ju=e=>r.isArrowFunction(e)?e.getBody():e,Zu=e=>{if(!r.isArrowFunction(e))return;const t=e.getParameters()[0]?.getNameNode();return t!==void 0&&r.isIdentifier(t)?t:void 0},ri=e=>{const t=e.getParent();return r.isPropertyAccessExpression(t)&&t.getExpression()===e&&t.getName()==="args"},oi=(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)})},ef=(e,t)=>$(e)||t!==void 0&&oi(e,t).some(s=>ri(s)),tf=(e,t)=>t===void 0?ne(e):oi(e,t).some(s=>!ri(s)),sf=(e,t)=>{const s=b(e.getExpression());if(s===void 0||!Xu.has(s))return;const n=T(mn(e.getArguments()[2]),"key");if(!n)return;const i=Ju(n),o=Zu(n);if(!(!ef(i,o)||tf(i,o)))return{callee:s,scope:v(e),file:t,limitName:pn(e),line:e.getStartLineNumber()}},nf=(e,t)=>C(e,t,sf),rf=new Set(["findFirst","findFirstOrThrow","findMany","findUnique","get"]),of=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!rf.has(t.getName()))return;const s=t.getExpression();if(L(s)){const n=e.getArguments()[0];return n&&r.isStringLiteral(n)?n.getLiteralText():""}if(r.isPropertyAccessExpression(s)&&L(s.getExpression()))return s.getName()},af=e=>{let t=e;for(;r.isCallExpression(t);){const s=t.getExpression();if(!r.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&L(s.getExpression())){const n=t.getArguments()[0];return n&&r.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},cf=e=>{let t=h(e)??e;for(;r.isAwaitExpression(t);)t=h(t.getExpression())??t.getExpression();return t},ai=(e,t=!1)=>{const s=cf(e);if(r.isIdentifier(s)){if(t)return;const n=H(s);return n===void 0?void 0:ai(n,!0)}if(r.isCallExpression(s))return of(s)??af(s)},lf=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},df=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!r.isCallExpression(s))return[];const n=X(s);if(n?.kind!=="query")return[];const i=Kn(s);if(i===void 0)return[];const o=n.receiver!==void 0&&gr(n.receiver,"output"),a=n.receiver!==void 0&&bn(n.receiver,"use","mask"),c=new Set,l=[];for(const u of lf(i)){const f=ai(u);f===void 0||c.has(f)||(c.add(f),l.push({exportName:V(e)??e.getName(),file:t,line:u.getStartLineNumber(),table:f,usesMask:a,usesOutput:o,visibility:n.visibility}))}return l},uf=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=I(t,n);for(const a of j(i))s.push(...df(a,o))}return s},ff=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(y(s));return t},gf=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&r.isCallExpression(s)?X(s):void 0;if(!n)return[];const i=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=Pn(o);if(a===void 0)continue;const c=ff(T(a.options,"with"));c.length!==0&&i.push({exportName:V(e)??e.getName(),file:t,line:o.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return i},pf=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=I(t,n);for(const a of j(i))s.push(...gf(a,o))}return s},z=(e,t)=>`${e}:${t}`,Gs=(e,t,s,n)=>s===void 0?void 0:{endLine:e.getEndLineNumber(),exported:n,file:t,name:s,node:e,startLine:e.getStartLineNumber()},mf=(e,t)=>[...Z(e,t,d.FunctionDeclaration,(s,n)=>s.getParent().getKind()===d.SourceFile?Gs(s,n,s.getName(),s.isExported()):void 0),...Z(e,t,d.VariableDeclaration,(s,n)=>{const i=s.getVariableStatement();return i?.getParent().getKind()===d.SourceFile?Gs(i,n,s.getName(),i.isExported()):void 0})],hf=(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=I(s,o.getSourceFile().getFilePath());return a===void 0?void 0:t.get(z(c,a))},vf=e=>`${e.table}|${e.method}|${e.fields?.join(",")??"*"}`,Ef=(e,t)=>{const s=new Map(e.map(n=>[z(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(z(i.file,i.name))?.set(vf(n),{fields:n.fields,method:n.method,table:n.table})}return s},xf=(e,t,s)=>e.node.getDescendantsOfKind(d.CallExpression).map(n=>hf(n,t,s)).filter(n=>n!==void 0),Sf=(e,t,s,n)=>{for(const i of e){const o=i.scope.kind==="module"?void 0:t.get(z(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(z(o.file,o.name))?.push(a)}},Af=(e,t,s)=>{const n=new Map(e.map(a=>[z(a.file,a.name),a])),i=new Map(e.map(a=>[`${Bt(a.file)}:${a.name}`,a])),o=new Map(e.map(a=>[z(a.file,a.name),xf(a,n,t)]));return Sf(s,n,i,o),o},yf=(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},bf=(e,t,s)=>{let n=!0;for(;n;){n=!1;for(const i of e)for(const o of s.get(z(i.file,i.name))??[])yf(t.get(z(i.file,i.name)),t.get(z(o.file,o.name)))&&(n=!0)}},Nf=(e,t,s,n)=>{const i=mf(e,t),o=Ef(i,s);return bf(i,o,Af(i,t,n)),i.filter(a=>a.exported).flatMap(a=>[...o.get(z(a.file,a.name))?.values()??[]].map(c=>({...c,exportName:a.name,file:a.file})))},ze=e=>{if(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(r.isBinaryExpression(e)&&e.getOperatorToken().getKind()===d.PlusToken){const t=ze(e.getLeft()),s=ze(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},Pf=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&&ze(t)!==void 0},wf=e=>{const t=e.getParent();if(t!==void 0){if(r.isVariableDeclaration(t)||r.isPropertyAssignment(t)||r.isPropertySignature(t))return y(t);if(r.isBinaryExpression(t)&&t.getOperatorToken().getKind()===d.EqualsToken)return t.getLeft().getText()}},If=(e,t,s)=>Fr(e)?!tr(s)&&Lr(wf(t)):!0,Cf=(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(Pf(o))continue;const a=ze(o);if(a===void 0)continue;const c=kr(a);if(c===void 0||!If(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:Rr(a)}))}return s},Tf=(e,t)=>{const s=[];for(const n of A(t,{includeSkipped:!0})){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Cf(i,I(t,n)))}return s},Of=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&r.isCallExpression(s)?X(s):void 0;if(!n)return[];const i=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=Pn(o);if(a===void 0)continue;const c=T(a.options,"includeDeleted");if(c===void 0)continue;const l=r.isTrueLiteral(c),u=!l&&$(c);!l&&!u||i.push({exportName:V(e)??e.getName(),file:t,fromArgs:u,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:n.visibility})}return i},kf=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=I(t,n);for(const a of j(i))s.push(...Of(a,o))}return s},Rf=new Set(["query","unsafe"]),Ff=e=>!r.isPropertyAccessExpression(e)||!Rf.has(e.getName())?!1:W(e.getExpression(),["sql"]),Lf=e=>r.isBinaryExpression(e)||r.isTemplateExpression(e),Df=(e,t)=>{if(!Ff(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Lf(s)))return{file:t,line:s.getStartLineNumber(),scope:v(e)}},Mf=(e,t)=>C(e,t,Df),_f=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],Kf=e=>{for(const[t,s]of _f)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},Bf=(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=Kf(a);c!==void 0&&s.push({file:I(t,n),line:o.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},zf=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),$f=(e,t,s=[])=>{const n=Ge(e,t,{argIndex:0,matchReceiver:i=>i==="ctx.storage"||i.startsWith("ctx.storage."),methods:zf,requireUnmodifiedReach:!0});return Mt(n,s)},Vf=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Uf=e=>e&&r.isNumericLiteral(e)?Number(e.getText()):void 0,qf=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=y(i);t.push(o),o==="expiresInSeconds"&&(s=Uf(i.getInitializer()));continue}(r.isShorthandPropertyAssignment(i)||r.isMethodDeclaration(i))&&t.push(y(i))}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},Wf=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName(),s=Vf.get(t);return s===void 0?void 0:Sn(e.getExpression(),i=>i==="ctx.storage"||i.startsWith("ctx.storage."))?{method:t,optionsIndex:s}:void 0},Hf=(e,t)=>{const s=Wf(e.getExpression());if(s!==void 0)return{scope:v(e),file:t,line:e.getStartLineNumber(),method:s.method,...qf(e.getArguments()[s.optionsIndex])}},jf=(e,t)=>C(e,t,Hf),Gf=e=>r.isDoStatement(e)||r.isForInStatement(e)||r.isForOfStatement(e)||r.isForStatement(e)||r.isWhileStatement(e),ci=e=>{const t=e.getLabel()?.getText(),s=i=>t!==void 0?r.isLabeledStatement(i)&&i.getLabel().getText()===t:Gf(i)||r.isBreakStatement(e)&&r.isSwitchStatement(i);let n=e.getFirstAncestor(i=>te(i)||s(i));if(!(n===void 0||te(n))){for(;r.isContinueStatement(e)&&r.isLabeledStatement(n);)n=n.getStatement();return n}},qt=(e,t)=>S(e.getFirstAncestor(s=>S(s,t)||te(s)),t),Yf=(e,t)=>S(e,t)||e.getFirstAncestor(s=>S(s,t))!==void 0,li=(e,t)=>{if(r.isReturnStatement(e)||r.isThrowStatement(e))return S(e,t)||qt(e,t);if(r.isBreakStatement(e)||r.isContinueStatement(e)){const s=ci(e);return s!==void 0&&!Yf(s,t)}return!1},di=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)],Qf=e=>di(e).some(t=>li(t,e)),Xf=e=>{const t=r.isCallExpression(e)?e.getExpression():void 0;return r.isPropertyAccessExpression(t)&&t.getName()==="throwIfAborted"},Jf=e=>di(e).some(t=>li(t,e)||r.isBreakStatement(t)&&S(ci(t),e))||e.getDescendantsOfKind(d.CallExpression).some(t=>Xf(t)&&qt(t,e)),Zf=e=>e.getDescendantsOfKind(d.YieldExpression).some(t=>qt(t,e)),eg=e=>r.isDoStatement(e)||r.isWhileStatement(e)?e.getExpression():e.getCondition(),tg=e=>r.isDoStatement(e)?"do":r.isWhileStatement(e)?"while":"for",pt=(e,t)=>{const s=eg(e);if(!(s===void 0||r.isTrueLiteral(h(s)))||Jf(e)||Zf(e))return;const i=v(e);if(!(i.kind==="module"&&e.getFirstAncestor(te)!==void 0))return{file:t,kind:tg(e),line:e.getStartLineNumber(),scope:i}},sg=(e,t)=>[...Z(e,t,d.WhileStatement,pt),...Z(e,t,d.ForStatement,pt),...Z(e,t,d.DoStatement,pt)].toSorted((s,n)=>s.file.localeCompare(n.file)||s.line-n.line),ng=new Set(["when","where"]),mt=new Set(["definePolicy","defineShape"]),ig=e=>{if(!r.isCallExpression(e))return;const t=e.getExpression();if(r.isPropertyAccessExpression(t)){const n=t.getName();return mt.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 mt.has(i)?i:void 0}const s=t.getText();return mt.has(s)?s:void 0},rg=e=>r.isObjectLiteralExpression(e)&&e.getProperties().length===0,ui=e=>{if(e!==void 0){if(r.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===d.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(rg(e))return"empty-object";if(r.isParenthesizedExpression(e))return ui(e.getExpression())}},Wt=e=>e.getAncestors().find(t=>r.isArrowFunction(t)||r.isFunctionExpression(t)||r.isFunctionDeclaration(t)),og=e=>e.getDescendantsOfKind(d.ReturnStatement).filter(t=>Wt(t)===e),fi=e=>e.getDescendantsOfKind(d.ConditionalExpression).filter(t=>Wt(t)===e),ag=e=>{const t=og(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(d.IfStatement)!==void 0)||fi(e).length>0},cg=e=>e.getDescendantsOfKind(d.IfStatement).filter(t=>Wt(t)===e),Rt=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()==="",lg=(e,t)=>Rt(e)||Rt(t),dg=new Map([[d.EqualsEqualsEqualsToken,"positive"],[d.EqualsEqualsToken,"positive"],[d.ExclamationEqualsEqualsToken,"negative"],[d.ExclamationEqualsToken,"negative"]]),Ys=e=>!Rt(e)&&(r.isLiteralExpression(e)||e.getKind()===d.TrueKeyword),ug=(e,t,s)=>{const n=dg.get(e);if(n!==void 0)return lg(t,s)?n==="positive"?"negative":"positive":Ys(t)||Ys(s)?void 0:n},Ee=e=>{if(r.isParenthesizedExpression(e))return Ee(e.getExpression());if(r.isPrefixUnaryExpression(e)&&e.getOperatorToken()===d.ExclamationToken)return"negative";if(r.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=ug(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===d.AmpersandAmpersandToken||t===d.BarBarToken){const n=Ee(e.getLeft()),i=Ee(e.getRight());return n===i?n:"indeterminate"}}return r.isIdentifier(e)||r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e)||r.isCallExpression(e)?"positive":"indeterminate"},Qs=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}}},fg=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,pg=e=>{const t=[];for(const s of fi(e)){const n=Ee(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of cg(e)){const n=Ee(s.getExpression());if(n==="indeterminate")continue;const i=n==="negative"?Qs(s.getThenStatement()):Qs(s.getElseStatement())??fg(s);i!==void 0&&t.push(gg(i))}return t},mg=e=>{for(const t of e.getAncestors())if(r.isVariableDeclaration(t)){const s=t.getNameNode();if(r.isIdentifier(s))return s.getText()}return"<anonymous>"},hg=(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)||!ng.has(y(o)))continue;const a=o.getInitializer();if(!(!a||!(r.isArrowFunction(a)||r.isFunctionExpression(a)))&&ag(a))for(const c of pg(a)){const l=ui(c);l!==void 0&&i.push({exportName:mg(e),file:s,form:l,key:y(o),line:c.getStartLineNumber(),owner:t})}}return i},vg=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=ig(n);i!==void 0&&s.push(...hg(n,i,t))}return s},Eg=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...vg(i,I(t,n)))}return s},xg=new Set(["query","upsert","upsertMany","upsertNow"]),ce=new Set,Sg=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();if(xg.has(t))return W(e.getExpression(),["vectors"])?t:void 0},Ht=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},gi=e=>{const t=e.getParent();return r.isShorthandPropertyAssignment(t)&&t.getNameNode()===e?t.getValueSymbol():e.getSymbol()},pi=e=>gi(e)?.getDeclarations()[0],Ag=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},mi=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},Xs=(e,t,s)=>{const n=gi(e)?.compilerSymbol;if(n!==void 0&&t.has(n))return!0;if(s>0){const i=mi(pi(e)),o=i!==void 0&&r.isVariableDeclaration(i)?i.getInitializer():void 0;if(o!==void 0)return jt(o,t,s-1)}return $(e)},jt=(e,t,s)=>{const n=Ht(e);return ne(n)?!1:r.isIdentifier(n)?Xs(n,t,s):$(n)?!0:n.getDescendantsOfKind(d.Identifier).some(i=>Ag(i)&&Xs(i,t,s))},hi=e=>{const t=mi(pi(e));return t!==void 0&&r.isVariableDeclaration(t)?t.getInitializer():void 0},Q=(e,t)=>{const s=Ht(e);if(r.isObjectLiteralExpression(s))return[s];if(r.isConditionalExpression(s))return[...Q(s.getWhenTrue(),t),...Q(s.getWhenFalse(),t)];if(r.isBinaryExpression(s)){const n=s.getOperatorToken().getKind();if(n===d.BarBarToken||n===d.QuestionQuestionToken||n===d.AmpersandAmpersandToken)return[...Q(s.getLeft(),t),...Q(s.getRight(),t)]}if(r.isIdentifier(s)&&t){const n=hi(s);return n===void 0?[]:Q(n,!1)}return[]},yg=(e,t)=>{const s=Q(e,t);if(s.length===0)return{replaces:!0,sources:[e]};const n=s.map(o=>$e(o,!1)),i=n.flat();if(i.length!==0)return{replaces:n.every(o=>o.length>0),sources:i}},bg=e=>(r.isPropertyAssignment(e)||r.isShorthandPropertyAssignment(e))&&e.getName()==="namespace",Ng=e=>r.isShorthandPropertyAssignment(e)?e.getNameNode():e.getInitializer()??e.getNameNode(),$e=(e,t)=>{let s=[];for(const n of e.getProperties())if(r.isSpreadAssignment(n)){const i=yg(n.getExpression(),t);i!==void 0&&(s=i.replaces?i.sources:[...s,...i.sources])}else bg(n)&&(s=[Ng(n)]);return s},Pg=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]},wg=e=>{if(!e||!(r.isArrowFunction(e)||r.isFunctionExpression(e)))return ce;const t=e.getParameters()[0]?.getNameNode();if(t===void 0)return ce;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??[]:[]))},Ft=(e,t=!0,s=ce)=>{const n=Ht(e);if(r.isIdentifier(n)){const o=t?hi(n):void 0;return o===void 0?[{node:n,parameters:s}]:Ft(o,!1,s)}if(r.isArrayLiteralExpression(n))return n.getElements().flatMap(o=>r.isSpreadElement(o)?Ft(o.getExpression(),t,s):Q(o,!0).flatMap(a=>$e(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=jt(i.getExpression(),ce,1)?wg(o):ce;return Pg(o).flatMap(c=>Q(c,!0).flatMap(l=>$e(l,!0).map(u=>({node:u,parameters:a}))))}return[{node:n,parameters:s}]},Ig=(e,t)=>{const s=Sg(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!(!n||!(s==="upsertMany"?Ft(n):Q(n,!0).flatMap(o=>$e(o,!0).map(a=>({node:a,parameters:ce})))).some(({node:o,parameters:a})=>jt(o,a,1))))return{scope:v(e),file:t,line:e.getStartLineNumber(),method:s}},Cg=(e,t)=>C(e,t,Ig),Tg=(e,t,s)=>{const{callSites:n,containers:i,crons:o,functions:a,modules:c,mutators:l,queues:u,schema:f,shapes:g,wranglerVariables:p,workflows:x}=s;return Gi({adminRoutes:ta(e,t),aiRawRuns:da(e,t),aiToolSideEffects:Aa(e,t),argumentDerivedFetches:Na(e,t),argumentValidators:Va(e,t),authApiCalls:Er(e,t),authConfigs:Ja(e,t),browserUrlAccesses:sc(e,t),callEdges:n.callEdges,configCalls:dc(e,t),containerKeyAccesses:fc(e,t),containerOverrides:Ec(e,t),containers:i,countReads:bc(e,t,f.tables),cronTargets:o.flatMap(k=>k.functionPath===void 0?[]:[k.functionPath]),exportSinks:Ic(e,t),staleMigrationImports:Bf(e,t),failOpenGuards:Rc(e,t),flagReads:_c(e,t),flagSecurityDefaults:$c(e,t),geoIndexUsages:qc(e,t),httpActionGuards:sl(e,t),httpHeaderWrites:fl(e,t),hyperdriveCalls:xr(e,t),identityClaimReads:bl(e,t),imageDeliveryUrlAccesses:Pl(e,t),inserts:n.inserts,kvKeyAccesses:Il(e,t,a),mailRecipientAccesses:Rl(e,t),maskProcedures:Sr(e,t),maskStrategies:Dl(e,t),mutatorWrites:$l(e,t),nondeterministicCalls:Pr(e,t),normalizeIdAuthorizations:sd(e,t),notifyCalls:Ir(e,t),notifyConfig:wr(e,t),mutators:l,ownerFieldWrites:Xd(e,t,a,l),unrestrictedWhereBranches:Eg(e,t),paymentWebhooks:su(e,t),privilegedDispatches:gu(e,t),procedureProtections:Qu(e,t),queries:n.queries,queues:u,r2sqlCalls:Cr(e,t),ratelimitKeySelectors:nf(e,t),rawRowReturns:uf(e,t),relationLoads:pf(e,t),rlsProcedures:Tr(e,t),schema:f,secretLiterals:Tf(e,t),modules:c,shapes:g,softDeleteReads:kf(e,t),sqlInterpolations:Mf(e,t),storageKeyAccesses:$f(e,t,a),storageUploads:jf(e,t),tableWrites:n.tableWrites,rowEffects:Nf(e,t,n.tableWrites,n.callEdges),unboundedLoops:sg(e,t),vectorNamespaceAccesses:Cg(e,t),workflowCalls:n.workflowCalls,workflows:x,wranglerVariables:p})},Og=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"}),kg=(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=>Og(i))]},Rg=()=>({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"}),Fg=e=>e.metadata.accepted!==void 0||e.name==="advisor_accept_unused"||e.name==="advisor_accept_invalid",Js={error:"ERROR",info:"INFO",warn:"WARN"},Zs={ERROR:2,INFO:0,WARN:1},Lg=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"}),Dg=(e,t)=>{const{advisor:s}=Nn(e);if(s===void 0||s.minSeverity===void 0&&s.unreadable!==!0)return[...t];const{minSeverity:n}=s,i=n!==void 0&&Object.hasOwn(Js,n)?Js[n]:void 0;return i===void 0?[...t,Lg(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=>Fg(o)||Zs[o.level]>=Zs[i])},Mg=(e,t)=>{const{advisor:s}=Nn(e),n=kg(t,s?.accept??[]);return Dg(e,s?.acceptUnreadable===!0?[...n,Rg()]:n)},_g={call:"function",enqueue:"queue",invoke:"service",publish:"topic",schedule:"function"},Kg="crons",Bg=_r.replace(/\.ts$/u,""),ae=(e,t)=>`${Bt(e)}:${t}`,ht=(e,t,s)=>t===""?{reason:`the ${s} is not a string literal`}:{to:`${e}:${t}`},zg=e=>[...e.callEdges.map(t=>{const s=t.target===void 0?{reason:t.reason??"unreadable target"}:{to:`${_g[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,...ht("table",t.table,"table name")})),...[...e.inserts,...e.tableWrites].map(t=>({file:t.file,kind:"write",line:t.line,scope:t.scope,...ht("table",t.table,"written table")})),...e.workflowCalls.map(t=>({file:t.file,kind:"start",line:t.line,scope:t.scope,...ht("workflow",t.workflow,"workflow name")}))],$g=e=>e.untracked===!0?"inside a helper only code outside any export calls":"inside a non-exported helper",Vg=e=>{const{scope:t}=e;switch(t.kind){case"export":return[{...e,exportName:t.name}];case"helper":return t.callers.length===0?[{...e,unattributed:$g(t)}]:t.callers.map(s=>({...e,exportName:s}));default:return[{...e,unattributed:"at module scope"}]}},Ug=e=>zg(e).flatMap(t=>Vg(t)),qg=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:Kg,from:`cron:${t.name}`,kind:"trigger",line:0,...i===void 0?{reason:"the cron has no target"}:{to:i}}})],Wg=e=>new Map(e.flatMap(t=>t.tables.map(s=>[s,t.name]))),me=(e,t)=>t===void 0?e:{...e,module:t},Hg=e=>{const t=new Map,s=new Map,n=Wg(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(ae(c.file,c.exportName),l)};for(const c of e.functions){const l=ae(c.filePath,c.exportName),u=[...Or(c.filePath),c.exportName].join(".");o(me({detail:c.kind,id:`function:${l}`,kind:"function",name:u},Oe(e.modules,c.filePath)),l)}for(const c of e.httpRoutes){const l=ae(c.filePath,c.exportName);o(me({id:`http:${l}`,kind:"http",name:`${c.method} ${c.path}`},Oe(e.modules,c.filePath)),l)}for(const c of e.schema.tables)o(me({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(me({...l,id:`queue:${c.exportName}`,kind:"queue",name:c.exportName},Oe(e.modules,c.filePath)),ae(c.filePath,c.exportName)),a(c.handlerSite,`queue:${c.exportName}`)}for(const c of e.topics)o(me({id:`topic:${c.exportName}`,kind:"topic",name:c.exportName},Oe(e.modules,c.filePath)));for(const c of e.workflows)o({id:`workflow:${c.exportName}`,kind:"workflow",name:c.exportName},ae(Bg,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}},jg=e=>e==="default"?"the default export is not a registered function":`"${e}" is not a registered function`,Gg=(e,t)=>"from"in e?[e.from]:"unattributed"in e?{reason:e.unattributed}:t.get(ae(e.file,e.exportName))??{reason:jg(e.exportName)},Yg=(e,t,s)=>{if("reason"in e)return{reason:e.reason};const n=Gg(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`}},vt=e=>`${e.from}|${e.kind}|${e.to}`,Qg=e=>`${e.file}|${String(e.line)}|${e.kind}|${e.reason}`,Xg=e=>{const{nodes:t,sites:s}=Hg(e),n=new Map,i=new Map;for(const o of[...qg(e),...Ug(e)]){const a=Yg(o,s,t);if("drawn"in a)for(const c of a.drawn)n.set(vt(c),c);else{const c={file:o.file,kind:o.kind,line:o.line,reason:a.reason};i.set(Qg(c),c)}}return{edges:[...n.values()].toSorted((o,a)=>vt(o).localeCompare(vt(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}},Jg=e=>`${zr}export const architecture = ${Br(e,"Record<string, unknown>")};
4
4
  `,en=(e,t="api")=>{const s=new Map;for(const n of e){const i=Bt(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 q("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})}}},Zg=(e,t={})=>{const{hasVectors:s=!0,scheduler:n=!1,storage:i=!1,usage:o}=t,a=[];e.tables.some(c=>In(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=>Cn(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?[]:Vr)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)},ep=(e,t,s={})=>{if(t===void 0)return;const n=Zg(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{Node as i}from"ts-morph";import{listLunoraSourceFiles as a,lunoraRelativePath as c,handlerOf as l}from"./isTestPath-B81lOULB.mjs";import{b as d,d as f}from"./attribution-hVBriwzy.mjs";import{c as u}from"./context-root-LyOsqj_o.mjs";import{c as m}from"./classify-procedure-call-BAj0D1u2.mjs";const p=t=>{const r=t.getInitializer();if(!r||!i.isCallExpression(r))return;const e=m(r);if(!e||e.kind!=="query"&&e.kind!=="mutation")return;const o=l(r,e.receiver);return o?{exportName:f(t)??t.getName(),handler:o,kind:e.kind}:void 0},x=(t,r)=>{const e=t.getParent();return e&&i.isPropertyAccessExpression(e)&&e.getExpression()===t?`ctx.${r}.${e.getName()}`:`ctx.${r}`},h=(t,r,e)=>{const o=[];for(const n of u(t.handler,e))o.push({callee:x(n,e),exportName:t.exportName,file:r,kind:t.kind,line:n.getStartLineNumber()});return o},N=(t,r,e)=>{const o=[];for(const n of d(t)){const s=p(n);s&&o.push(...h(s,r,e))}return o},F=(t,r,e)=>{const o=[];for(const n of a(r)){const s=t.getSourceFile(n)??t.addSourceFileAtPath(n);o.push(...N(s,c(r,n),e))}return o};export{F as d};
1
+ import{Node as i}from"ts-morph";import{listLunoraSourceFiles as a,lunoraRelativePath as c,handlerOf as l}from"./isTestPath-B81lOULB.mjs";import{b as d,d as f}from"./attribution-hVBriwzy.mjs";import{c as u}from"./context-root-lGZCyHyj.mjs";import{c as m}from"./classify-procedure-call-BAj0D1u2.mjs";const p=t=>{const r=t.getInitializer();if(!r||!i.isCallExpression(r))return;const e=m(r);if(!e||e.kind!=="query"&&e.kind!=="mutation")return;const o=l(r,e.receiver);return o?{exportName:f(t)??t.getName(),handler:o,kind:e.kind}:void 0},x=(t,r)=>{const e=t.getParent();return e&&i.isPropertyAccessExpression(e)&&e.getExpression()===t?`ctx.${r}.${e.getName()}`:`ctx.${r}`},h=(t,r,e)=>{const o=[];for(const n of u(t.handler,e))o.push({callee:x(n,e),exportName:t.exportName,file:r,kind:t.kind,line:n.getStartLineNumber()});return o},N=(t,r,e)=>{const o=[];for(const n of d(t)){const s=p(n);s&&o.push(...h(s,r,e))}return o},F=(t,r,e)=>{const o=[];for(const n of a(r)){const s=t.getSourceFile(n)??t.addSourceFileAtPath(n);o.push(...N(s,c(r,n),e))}return o};export{F as d};
@@ -1 +1 @@
1
- import{Node as s,SyntaxKind as d}from"ts-morph";import{unwrapExpression as l,memberAccessOf as P,bindingKeyName as C,findObjectProperty as p,isConstDeclaration as D,walkChain as A}from"./isTestPath-B81lOULB.mjs";import{f as v,g as I,h as M}from"./attribution-hVBriwzy.mjs";import{c as F}from"./classify-procedure-call-BAj0D1u2.mjs";import{isDefineMutatorCallee as b}from"./MUTATORS_FILENAME-qVDmv8st.mjs";const x=8,E=t=>{if(s.isMethodDeclaration(t))return t;const e=s.isPropertyAssignment(t)?l(t.getInitializer()):void 0,o=s.isShorthandPropertyAssignment(t)?t.getNameNode():e;if(s.isArrowFunction(o)||s.isFunctionExpression(o))return o;const i=s.isIdentifier(o)?v(o):void 0;if(s.isFunctionDeclaration(i))return i;const n=D(i)?l(i.getInitializer()):void 0;return s.isArrowFunction(n)||s.isFunctionExpression(n)?n:void 0},w=t=>{const e=l(t.getArguments()[0]),o=s.isObjectLiteralExpression(e)?e:void 0,i=p(o,"server"),n=p(o,"handler"),r=i!==void 0&&b(t.getExpression()),a=n===void 0?void 0:F(t),u=a!==void 0&&a.receiver===void 0;return[r?E(i):void 0,u?E(n):void 0].filter(f=>f!==void 0)},h=new WeakMap,O=t=>{const e=t.getSourceFile(),o=h.get(e.compilerNode);if(o!==void 0)return o;const i=new Set(e.getDescendantsOfKind(d.CallExpression).flatMap(n=>w(n)).map(n=>n.compilerNode));return h.set(e.compilerNode,i),i},S=t=>{const e=t.getParent();return(s.isArrowFunction(e)||s.isFunctionExpression(e)||s.isFunctionDeclaration(e)||s.isMethodDeclaration(e))&&e.getParameters()[0]===t&&O(t).has(e.compilerNode)},G=t=>{const e=t.getParent();return(s.isArrowFunction(e)||s.isFunctionExpression(e)||s.isFunctionDeclaration(e)||s.isMethodDeclaration(e))&&e.getParameters()[1]===t&&O(t).has(e.compilerNode)},T=t=>t.getNameNode().getDescendantsOfKind(d.BindingElement).some(e=>e.getParent().getParent()===t&&["args","ctx"].includes(C(e))),g=(t,e,o)=>{const i=t.getParent().getParent(),n=C(t);if(t.getDotDotDotToken()!==void 0||e==="trust"&&I(t))return;let r;if(s.isParameterDeclaration(i)){if(!S(i)||T(i))return n==="ctx"?[]:void 0;r=[]}else s.isBindingElement(i)?r=g(i,e,o):s.isVariableDeclaration(i)&&o>0&&(r=c(i.getInitializer(),e,o-1));return r===void 0?void 0:[...r,n]},c=(t,e="discover",o=x)=>{const i=l(t),n=P(i);if(n!==void 0){const r=c(n.object,e,o);return r===void 0?void 0:[...r,n.member]}return s.isIdentifier(i)?B(i,e,o):void 0},B=(t,e,o)=>{const i=t.getText()==="ctx",n=e==="trust"||!i?v(t):void 0;return i&&!s.isVariableDeclaration(n)?s.isBindingElement(n)?g(n,e,o):[]:s.isParameterDeclaration(n)?s.isIdentifier(n.getNameNode())&&S(n)?[]:void 0:s.isBindingElement(n)?g(n,e,o):!(s.isVariableDeclaration(n)&&s.isIdentifier(n.getNameNode())&&o>0)||e==="trust"&&I(n)?void 0:c(n.getInitializer(),e,o-1)},Q=t=>c(t,"discover"),H=t=>{const e=c(t);return e===void 0?void 0:["ctx",...e].join(".")},q=(t,e)=>{if(e(t.getText()))return!0;const o=H(t);return o!==void 0&&e(o)},J=(t,e)=>{const o=l(t),i=P(o);if(i!==void 0&&i.member!==e.at(-1))return!1;const n=o===void 0?void 0:c(o);return n?.length===e.length&&n.every((r,a)=>r===e[a])},Y=(t,e)=>U(t).get(e)??[],K=t=>{const e=new Map;for(const i of t.getDescendantsOfKind(d.BindingElement)){const n=s.isIdentifier(i.getNameNode())?g(i,"discover",x):void 0;n?.length===1&&n[0]!==void 0&&e.set(i.compilerNode,n[0])}const o=new Set([...e.keys()].map(i=>i.name.getText()));return t.getDescendantsOfKind(d.Identifier).flatMap(i=>{const r=o.has(i.getText())&&!s.isBindingElement(i.getParent())?v(i):void 0,a=r===void 0?void 0:e.get(r.compilerNode);return a===void 0?[]:[[a,i]]})},N=new WeakMap,U=t=>{const e=N.get(t.compilerNode);if(e!==void 0)return e;const o=new Map;for(const[n,r]of[...y(t),...K(t)])o.set(n,[...o.get(n)??[],r]);const i=new Map([...o].map(([n,r])=>[n,r.toSorted((a,u)=>a.getPos()-u.getPos())]));return N.set(t.compilerNode,i),i},y=t=>t.getDescendantsOfKind(d.PropertyAccessExpression).flatMap(e=>z(e.getExpression())?[[e.getName(),e]]:[]),z=t=>s.isIdentifier(t)&&c(t)?.length===0,Z=t=>{const e=c(t);return e?.length===1&&e[0]==="db"},_=new Set(["asId","createMultipartUpload","fetch","generateUploadUrl","getPresignedUrl","getSignedUrl","getUrl","normalizeId","resumeMultipartUpload","runAction","runMutation","runQuery","store","upload"]),R=new Set(["catch","flatMap","map","reduce","reduceRight","then"]),k=(t,e=x)=>{const o=A(t,u=>{const f=l(u.getExpression()),m=s.isPropertyAccessExpression(f)?f.getName():void 0;return m!==void 0&&(_.has(m)||R.has(m))?!1:void 0}),i=o.root;if(o.verdict!==void 0||!s.isIdentifier(i))return o.verdict??!1;if(c(i,"trust")!==void 0)return!0;const n=v(i),r=s.isBindingElement(n)?n.getFirstAncestorByKind(d.VariableDeclaration):n,a=D(r)&&e>0?r.getInitializer():void 0;return a!==void 0&&k(a,e-1)},$=t=>(s.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(o=>M(o)&&c(o,"trust")!==void 0);export{R as C,_ as E,G as a,H as b,Y as c,Z as d,Q as e,k as f,z as g,J as i,q as m,$ as r};
1
+ import{Node as s,SyntaxKind as d}from"ts-morph";import{unwrapExpression as l,memberAccessOf as P,bindingKeyName as C,findObjectProperty as p,isConstDeclaration as D,walkChain as A}from"./isTestPath-B81lOULB.mjs";import{f as v,g as I,h as M}from"./attribution-hVBriwzy.mjs";import{c as F}from"./classify-procedure-call-BAj0D1u2.mjs";import{isDefineMutatorCallee as b}from"./MUTATORS_FILENAME--5kUJd5I.mjs";const x=8,E=t=>{if(s.isMethodDeclaration(t))return t;const e=s.isPropertyAssignment(t)?l(t.getInitializer()):void 0,o=s.isShorthandPropertyAssignment(t)?t.getNameNode():e;if(s.isArrowFunction(o)||s.isFunctionExpression(o))return o;const i=s.isIdentifier(o)?v(o):void 0;if(s.isFunctionDeclaration(i))return i;const n=D(i)?l(i.getInitializer()):void 0;return s.isArrowFunction(n)||s.isFunctionExpression(n)?n:void 0},w=t=>{const e=l(t.getArguments()[0]),o=s.isObjectLiteralExpression(e)?e:void 0,i=p(o,"server"),n=p(o,"handler"),r=i!==void 0&&b(t.getExpression()),a=n===void 0?void 0:F(t),u=a!==void 0&&a.receiver===void 0;return[r?E(i):void 0,u?E(n):void 0].filter(f=>f!==void 0)},h=new WeakMap,O=t=>{const e=t.getSourceFile(),o=h.get(e.compilerNode);if(o!==void 0)return o;const i=new Set(e.getDescendantsOfKind(d.CallExpression).flatMap(n=>w(n)).map(n=>n.compilerNode));return h.set(e.compilerNode,i),i},S=t=>{const e=t.getParent();return(s.isArrowFunction(e)||s.isFunctionExpression(e)||s.isFunctionDeclaration(e)||s.isMethodDeclaration(e))&&e.getParameters()[0]===t&&O(t).has(e.compilerNode)},G=t=>{const e=t.getParent();return(s.isArrowFunction(e)||s.isFunctionExpression(e)||s.isFunctionDeclaration(e)||s.isMethodDeclaration(e))&&e.getParameters()[1]===t&&O(t).has(e.compilerNode)},T=t=>t.getNameNode().getDescendantsOfKind(d.BindingElement).some(e=>e.getParent().getParent()===t&&["args","ctx"].includes(C(e))),g=(t,e,o)=>{const i=t.getParent().getParent(),n=C(t);if(t.getDotDotDotToken()!==void 0||e==="trust"&&I(t))return;let r;if(s.isParameterDeclaration(i)){if(!S(i)||T(i))return n==="ctx"?[]:void 0;r=[]}else s.isBindingElement(i)?r=g(i,e,o):s.isVariableDeclaration(i)&&o>0&&(r=c(i.getInitializer(),e,o-1));return r===void 0?void 0:[...r,n]},c=(t,e="discover",o=x)=>{const i=l(t),n=P(i);if(n!==void 0){const r=c(n.object,e,o);return r===void 0?void 0:[...r,n.member]}return s.isIdentifier(i)?B(i,e,o):void 0},B=(t,e,o)=>{const i=t.getText()==="ctx",n=e==="trust"||!i?v(t):void 0;return i&&!s.isVariableDeclaration(n)?s.isBindingElement(n)?g(n,e,o):[]:s.isParameterDeclaration(n)?s.isIdentifier(n.getNameNode())&&S(n)?[]:void 0:s.isBindingElement(n)?g(n,e,o):!(s.isVariableDeclaration(n)&&s.isIdentifier(n.getNameNode())&&o>0)||e==="trust"&&I(n)?void 0:c(n.getInitializer(),e,o-1)},Q=t=>c(t,"discover"),H=t=>{const e=c(t);return e===void 0?void 0:["ctx",...e].join(".")},q=(t,e)=>{if(e(t.getText()))return!0;const o=H(t);return o!==void 0&&e(o)},J=(t,e)=>{const o=l(t),i=P(o);if(i!==void 0&&i.member!==e.at(-1))return!1;const n=o===void 0?void 0:c(o);return n?.length===e.length&&n.every((r,a)=>r===e[a])},Y=(t,e)=>U(t).get(e)??[],K=t=>{const e=new Map;for(const i of t.getDescendantsOfKind(d.BindingElement)){const n=s.isIdentifier(i.getNameNode())?g(i,"discover",x):void 0;n?.length===1&&n[0]!==void 0&&e.set(i.compilerNode,n[0])}const o=new Set([...e.keys()].map(i=>i.name.getText()));return t.getDescendantsOfKind(d.Identifier).flatMap(i=>{const r=o.has(i.getText())&&!s.isBindingElement(i.getParent())?v(i):void 0,a=r===void 0?void 0:e.get(r.compilerNode);return a===void 0?[]:[[a,i]]})},N=new WeakMap,U=t=>{const e=N.get(t.compilerNode);if(e!==void 0)return e;const o=new Map;for(const[n,r]of[...y(t),...K(t)])o.set(n,[...o.get(n)??[],r]);const i=new Map([...o].map(([n,r])=>[n,r.toSorted((a,u)=>a.getPos()-u.getPos())]));return N.set(t.compilerNode,i),i},y=t=>t.getDescendantsOfKind(d.PropertyAccessExpression).flatMap(e=>z(e.getExpression())?[[e.getName(),e]]:[]),z=t=>s.isIdentifier(t)&&c(t)?.length===0,Z=t=>{const e=c(t);return e?.length===1&&e[0]==="db"},_=new Set(["asId","createMultipartUpload","fetch","generateUploadUrl","getPresignedUrl","getSignedUrl","getUrl","normalizeId","resumeMultipartUpload","runAction","runMutation","runQuery","store","upload"]),R=new Set(["catch","flatMap","map","reduce","reduceRight","then"]),k=(t,e=x)=>{const o=A(t,u=>{const f=l(u.getExpression()),m=s.isPropertyAccessExpression(f)?f.getName():void 0;return m!==void 0&&(_.has(m)||R.has(m))?!1:void 0}),i=o.root;if(o.verdict!==void 0||!s.isIdentifier(i))return o.verdict??!1;if(c(i,"trust")!==void 0)return!0;const n=v(i),r=s.isBindingElement(n)?n.getFirstAncestorByKind(d.VariableDeclaration):n,a=D(r)&&e>0?r.getInitializer():void 0;return a!==void 0&&k(a,e-1)},$=t=>(s.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(o=>M(o)&&c(o,"trust")!==void 0);export{R as C,_ as E,G as a,H as b,Y as c,Z as d,Q as e,k as f,z as g,J as i,q as m,$ as r};
@@ -1 +1 @@
1
- import{SyntaxKind as g,Node as n}from"ts-morph";import{d as p}from"./context-root-LyOsqj_o.mjs";const c=e=>n.isPropertyAccessExpression(e)&&e.getName()==="db"||n.isIdentifier(e)&&e.getText()==="db"||p(e),l=new Set(["findFirst","findFirstOrThrow","findMany","findUnique"]),u=e=>{const t=e.getExpression();if(!n.isPropertyAccessExpression(t)||!l.has(t.getName()))return;const s=t.getExpression();if(c(s))return{options:e.getArguments()[1],table:d(e)};if(n.isPropertyAccessExpression(s)){const o=s.getExpression();if(c(o))return{options:e.getArguments()[0],table:s.getName()}}},f=(e,t)=>{const s=e.getExpression();return!n.isPropertyAccessExpression(s)||!t.has(s.getName())?!1:c(s.getExpression())},d=e=>{const t=e.getArguments()[0];return t&&n.isStringLiteral(t)?t.getLiteralText():""},m=(e,t,s)=>{const o=new Set,i=new Set;for(const a of e.getDescendantsOfKind(g.CallExpression))if(f(a,t)){const r=d(a);r!==""&&o.add(r)}else if(f(a,s)){const r=d(a);r!==""&&i.add(r)}return{tablesRead:[...o],tablesWritten:[...i]}};export{c as i,u as r,m as t};
1
+ import{SyntaxKind as g,Node as n}from"ts-morph";import{d as p}from"./context-root-lGZCyHyj.mjs";const c=e=>n.isPropertyAccessExpression(e)&&e.getName()==="db"||n.isIdentifier(e)&&e.getText()==="db"||p(e),l=new Set(["findFirst","findFirstOrThrow","findMany","findUnique"]),u=e=>{const t=e.getExpression();if(!n.isPropertyAccessExpression(t)||!l.has(t.getName()))return;const s=t.getExpression();if(c(s))return{options:e.getArguments()[1],table:d(e)};if(n.isPropertyAccessExpression(s)){const o=s.getExpression();if(c(o))return{options:e.getArguments()[0],table:s.getName()}}},f=(e,t)=>{const s=e.getExpression();return!n.isPropertyAccessExpression(s)||!t.has(s.getName())?!1:c(s.getExpression())},d=e=>{const t=e.getArguments()[0];return t&&n.isStringLiteral(t)?t.getLiteralText():""},m=(e,t,s)=>{const o=new Set,i=new Set;for(const a of e.getDescendantsOfKind(g.CallExpression))if(f(a,t)){const r=d(a);r!==""&&o.add(r)}else if(f(a,s)){const r=d(a);r!==""&&i.add(r)}return{tablesRead:[...o],tablesWritten:[...i]}};export{c as i,u as r,m as t};
@@ -1 +1 @@
1
- import{d as P}from"./declared-output-Iaar469J.mjs";import{findObjectProperty as c,bindingKeyName as b,listLunoraSourceFiles as N,lunoraRelativePath as A}from"./isTestPath-B81lOULB.mjs";import{e as O,i as F}from"./attribution-hVBriwzy.mjs";import{u as y,p as z,c as g,r as C}from"./unwrap-handler-return-CJrkfrSH.mjs";import{b as d,c as S}from"./classify-procedure-call-BAj0D1u2.mjs";import{Node as n,SyntaxKind as L}from"ts-morph";import{r as h,p as x,a as k}from"./parse-validator-IDBKIT7M.mjs";import{s as I}from"./dispatch-namespace-DwTjD7BU.mjs";const T=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return"unknown";const t=c(e,"handler");if(!t||!n.isPropertyAssignment(t))return"unknown";const r=t.getInitializer();return!r||!(n.isArrowFunction(r)||n.isFunctionExpression(r))?"unknown":y(r)},w=i=>{const e=i.getArguments()[0];return!e||!(n.isArrowFunction(e)||n.isFunctionExpression(e))?"unknown":y(e)},V=i=>{let e={};for(const t of d(i)){if(t.name!=="input")continue;const r=t.call.getArguments()[0],s=r!==void 0&&n.isExpression(r)?h(r):void 0;s!==void 0&&(e={...x(s),...e})}return e},D=i=>{const e=d(i).find(r=>r.name==="output");if(!e)return;const t=e.call.getArguments()[0];return t&&n.isExpression(t)?z(e.call,()=>k(t)):void 0},p=(i,e)=>{const t=c(i,e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isStringLiteral(r)?r.getLiteralValue():void 0},v=(i,e)=>{const t=c(i,e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isNumericLiteral(r)?r.getLiteralValue():void 0},j=i=>{const e=c(i,"cache");if(e===void 0||!n.isPropertyAssignment(e))return;const t=e.getInitializer();if(t===void 0||!n.isObjectLiteralExpression(t))return;const r=p(t,"scope"),s=v(t,"maxAge"),o=v(t,"staleWhileRevalidate"),a=p(t,"tag"),l=p(t,"vary"),m={...s===void 0?{}:{maxAge:s},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...l===void 0?{}:{vary:l}};return Object.keys(m).length===0?void 0:m},B=i=>{if(i===void 0||!n.isObjectLiteralExpression(i))return{};const e=j(i),t=c(i,"rest");return t!==void 0&&n.isPropertyAssignment(t)?{...e===void 0?{}:{cache:e},rest:t.getInitializer()?.getText()==="true"}:e===void 0?{}:{cache:e}},R=i=>{const e=d(i).find(t=>t.name==="expose");return e?B(e.call.getArguments()[0]):void 0},M=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return{};const t=c(e,"args");if(!t||!n.isPropertyAssignment(t))return{};const r=t.getInitializer(),s=r===void 0?void 0:h(r);return s===void 0?{}:x(s)},$=8,u=(i,e=0)=>{if(e>$)return;if(n.isCallExpression(i))return i;if(n.isParenthesizedExpression(i)||n.isAsExpression(i)||n.isSatisfiesExpression(i)||n.isNonNullExpression(i))return u(i.getExpression(),e+1);if(!n.isIdentifier(i)&&!n.isPropertyAccessExpression(i))return;const t=i.getSymbol()?.getValueDeclaration();return t?f(t,e+1):void 0},f=(i,e)=>{if(n.isVariableDeclaration(i)||n.isPropertyAssignment(i)){const t=i.getInitializer();return t?u(t,e):void 0}if(n.isShorthandPropertyAssignment(i)){const t=i.getValueSymbol()?.getValueDeclaration();return t?f(t,e+1):void 0}if(n.isBindingElement(i)){const t=b(i),o=i.getFirstAncestorByKind(L.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return o?f(o,e+1):void 0}},W=(i,e=()=>!0)=>{const t=i.getNameNode();if(n.isObjectBindingPattern(t)){const o=[];for(const a of t.getElements().filter(l=>e(l.getName()))){const l=u(a.getNameNode());l&&o.push([a.getName(),l])}return o}if(!e(i.getName()))return[];const r=i.getInitializer(),s=r&&(n.isCallExpression(r)?r:u(r));return s?[[i.getName(),s]]:[]},_=i=>{const e=S(i);if(!e)return;const{receiver:t}=e;if(t){const r=R(t),s=g(()=>D(t)),o=g(()=>w(i)),a=P({kind:e.kind,output:s.value});return C(a?s.erased:o.erased),{args:V(t),...r?{expose:r}:{},...e.adminOnly?{adminOnly:!0}:{},kind:e.kind,...s.value?{output:s.value}:{},returnType:o.value,visibility:e.visibility}}return e.lifecycle?{args:{},kind:e.kind,lifecycle:e.lifecycle,returnType:"void",visibility:e.visibility}:{args:M(i),kind:e.kind,returnType:T(i),visibility:e.visibility}},E=(i,e,t)=>{const r=_(i);if(r)return{args:r.args,exportName:e,filePath:t,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},visibility:r.visibility,...r.adminOnly?{adminOnly:!0}:{},...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},H=(i,e)=>{const t=[];for(const r of i.getExportAssignments()){if(r.isExportEquals())continue;const s=u(r.getExpression()),o=s?E(s,"default",e):void 0;o&&t.push(o)}return t},K=(i,e)=>{const t=O(i),r=i.getVariableStatements().flatMap(o=>o.getDeclarations()).flatMap(o=>W(o,a=>t.has(a))).flatMap(([o,a])=>(t.get(o)??[]).filter(l=>F(l)).flatMap(l=>E(a,l,e)??[])),s=new Set(r.map(o=>o.exportName));return r.push(...H(i,e).filter(o=>!s.has(o.exportName))),r},q=i=>{const e=new Map;for(const t of i){const r=I(t.filePath),s=e.get(r);if(s&&s!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${s}" and "${t.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[s,t.filePath],status:500});e.set(r,t.filePath)}},te=(i,e)=>{const t=N(e),r=[];for(const s of t){const o=i.getSourceFile(s)??i.addSourceFileAtPath(s),a=A(e,s);r.push(...K(o,a))}return r.sort((s,o)=>`${s.filePath}:${s.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),q(r),r};export{te as default};
1
+ import{d as P}from"./declared-output-Iaar469J.mjs";import{findObjectProperty as c,bindingKeyName as b,listLunoraSourceFiles as N,lunoraRelativePath as A}from"./isTestPath-B81lOULB.mjs";import{e as O,i as F}from"./attribution-hVBriwzy.mjs";import{u as y,p as z,c as g,r as C}from"./unwrap-handler-return-BwclbliB.mjs";import{b as d,c as S}from"./classify-procedure-call-BAj0D1u2.mjs";import{Node as n,SyntaxKind as L}from"ts-morph";import{r as h,p as x,a as k}from"./parse-validator-IDBKIT7M.mjs";import{s as I}from"./dispatch-namespace-DwTjD7BU.mjs";const T=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return"unknown";const t=c(e,"handler");if(!t||!n.isPropertyAssignment(t))return"unknown";const r=t.getInitializer();return!r||!(n.isArrowFunction(r)||n.isFunctionExpression(r))?"unknown":y(r)},w=i=>{const e=i.getArguments()[0];return!e||!(n.isArrowFunction(e)||n.isFunctionExpression(e))?"unknown":y(e)},V=i=>{let e={};for(const t of d(i)){if(t.name!=="input")continue;const r=t.call.getArguments()[0],s=r!==void 0&&n.isExpression(r)?h(r):void 0;s!==void 0&&(e={...x(s),...e})}return e},D=i=>{const e=d(i).find(r=>r.name==="output");if(!e)return;const t=e.call.getArguments()[0];return t&&n.isExpression(t)?z(e.call,()=>k(t)):void 0},p=(i,e)=>{const t=c(i,e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isStringLiteral(r)?r.getLiteralValue():void 0},v=(i,e)=>{const t=c(i,e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isNumericLiteral(r)?r.getLiteralValue():void 0},j=i=>{const e=c(i,"cache");if(e===void 0||!n.isPropertyAssignment(e))return;const t=e.getInitializer();if(t===void 0||!n.isObjectLiteralExpression(t))return;const r=p(t,"scope"),s=v(t,"maxAge"),o=v(t,"staleWhileRevalidate"),a=p(t,"tag"),l=p(t,"vary"),m={...s===void 0?{}:{maxAge:s},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...l===void 0?{}:{vary:l}};return Object.keys(m).length===0?void 0:m},B=i=>{if(i===void 0||!n.isObjectLiteralExpression(i))return{};const e=j(i),t=c(i,"rest");return t!==void 0&&n.isPropertyAssignment(t)?{...e===void 0?{}:{cache:e},rest:t.getInitializer()?.getText()==="true"}:e===void 0?{}:{cache:e}},R=i=>{const e=d(i).find(t=>t.name==="expose");return e?B(e.call.getArguments()[0]):void 0},M=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return{};const t=c(e,"args");if(!t||!n.isPropertyAssignment(t))return{};const r=t.getInitializer(),s=r===void 0?void 0:h(r);return s===void 0?{}:x(s)},$=8,u=(i,e=0)=>{if(e>$)return;if(n.isCallExpression(i))return i;if(n.isParenthesizedExpression(i)||n.isAsExpression(i)||n.isSatisfiesExpression(i)||n.isNonNullExpression(i))return u(i.getExpression(),e+1);if(!n.isIdentifier(i)&&!n.isPropertyAccessExpression(i))return;const t=i.getSymbol()?.getValueDeclaration();return t?f(t,e+1):void 0},f=(i,e)=>{if(n.isVariableDeclaration(i)||n.isPropertyAssignment(i)){const t=i.getInitializer();return t?u(t,e):void 0}if(n.isShorthandPropertyAssignment(i)){const t=i.getValueSymbol()?.getValueDeclaration();return t?f(t,e+1):void 0}if(n.isBindingElement(i)){const t=b(i),o=i.getFirstAncestorByKind(L.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return o?f(o,e+1):void 0}},W=(i,e=()=>!0)=>{const t=i.getNameNode();if(n.isObjectBindingPattern(t)){const o=[];for(const a of t.getElements().filter(l=>e(l.getName()))){const l=u(a.getNameNode());l&&o.push([a.getName(),l])}return o}if(!e(i.getName()))return[];const r=i.getInitializer(),s=r&&(n.isCallExpression(r)?r:u(r));return s?[[i.getName(),s]]:[]},_=i=>{const e=S(i);if(!e)return;const{receiver:t}=e;if(t){const r=R(t),s=g(()=>D(t)),o=g(()=>w(i)),a=P({kind:e.kind,output:s.value});return C(a?s.erased:o.erased),{args:V(t),...r?{expose:r}:{},...e.adminOnly?{adminOnly:!0}:{},kind:e.kind,...s.value?{output:s.value}:{},returnType:o.value,visibility:e.visibility}}return e.lifecycle?{args:{},kind:e.kind,lifecycle:e.lifecycle,returnType:"void",visibility:e.visibility}:{args:M(i),kind:e.kind,returnType:T(i),visibility:e.visibility}},E=(i,e,t)=>{const r=_(i);if(r)return{args:r.args,exportName:e,filePath:t,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},visibility:r.visibility,...r.adminOnly?{adminOnly:!0}:{},...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},H=(i,e)=>{const t=[];for(const r of i.getExportAssignments()){if(r.isExportEquals())continue;const s=u(r.getExpression()),o=s?E(s,"default",e):void 0;o&&t.push(o)}return t},K=(i,e)=>{const t=O(i),r=i.getVariableStatements().flatMap(o=>o.getDeclarations()).flatMap(o=>W(o,a=>t.has(a))).flatMap(([o,a])=>(t.get(o)??[]).filter(l=>F(l)).flatMap(l=>E(a,l,e)??[])),s=new Set(r.map(o=>o.exportName));return r.push(...H(i,e).filter(o=>!s.has(o.exportName))),r},q=i=>{const e=new Map;for(const t of i){const r=I(t.filePath),s=e.get(r);if(s&&s!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${s}" and "${t.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[s,t.filePath],status:500});e.set(r,t.filePath)}},te=(i,e)=>{const t=N(e),r=[];for(const s of t){const o=i.getSourceFile(s)??i.addSourceFileAtPath(s),a=A(e,s);r.push(...K(o,a))}return r.sort((s,o)=>`${s.filePath}:${s.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),q(r),r};export{te as default};
@@ -1 +1 @@
1
- import{Node as n}from"ts-morph";import{a as m,p as l}from"./parse-validator-IDBKIT7M.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./isTestPath-B81lOULB.mjs";import{b as f,d as g}from"./attribution-hVBriwzy.mjs";import{u as x}from"./unwrap-handler-return-CJrkfrSH.mjs";const u=new Set(["delete","get","head","options","patch","post","put"]),E=new Set(["body","params","searchParams"]),v=new Set(["handler","stream"]),P=s=>{const e=s.getArguments()[0];if(e&&n.isStringLiteral(e))return e.getLiteralValue()},S=s=>{const e=s.getArguments()[0];return e&&n.isObjectLiteralExpression(e)?l(e):{}},A=s=>{if(!n.isCallExpression(s))return;const e=s.getExpression();if(!n.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const a=e.getExpression();if(!n.isIdentifier(a)||a.getText()!=="httpRoute")return;const t=P(s);return t===void 0?void 0:{method:o.toUpperCase(),path:t}},b=(s,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},a=s.getExpression();if(!n.isPropertyAccessExpression(a))return;let t=a.getExpression();for(;n.isCallExpression(t);){const i=t.getExpression();if(!n.isPropertyAccessExpression(i))break;const c=i.getName();if(u.has(c))break;if(E.has(c)){const p=S(t);o[c]={...p,...o[c]}}else if(c==="output"&&o.output===void 0){const p=t.getArguments()[0];p&&n.isExpression(p)&&(o.output=m(p))}t=i.getExpression()}const r=A(t);if(r)return o.method=r.method,o.path=r.path,o},T=s=>{const e=s.getArguments()[0];return!e||!(n.isArrowFunction(e)||n.isFunctionExpression(e))?"unknown":x(e)},y=(s,e,o,a)=>{const t=e.getName();if(!v.has(t))return;const r=b(s,t);if(!(r?.method===void 0||r.path===void 0))return{body:r.body,exportName:o,filePath:a,method:r.method,params:r.params,path:r.path,searchParams:r.searchParams,stream:r.stream,...r.stream?{chunkType:T(s)}:{},...r.output?{output:r.output}:{}}},R=(s,e)=>{const o=[];for(const a of f(s)){const t=a.getInitializer();if(!t||!n.isCallExpression(t))continue;const r=t.getExpression();if(!n.isPropertyAccessExpression(r))continue;const i=y(t,r,g(a)??a.getName(),e);i&&o.push(i)}return o},L=(s,e)=>{const o=d(e),a=[];for(const t of o){const r=s.getSourceFile(t)??s.addSourceFileAtPath(t),i=h(e,t);a.push(...R(r,i))}return a.sort((t,r)=>`${t.method} ${t.path}`.localeCompare(`${r.method} ${r.path}`)||t.filePath.localeCompare(r.filePath)),a};export{L as default};
1
+ import{Node as n}from"ts-morph";import{a as m,p as l}from"./parse-validator-IDBKIT7M.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./isTestPath-B81lOULB.mjs";import{b as f,d as g}from"./attribution-hVBriwzy.mjs";import{u as x}from"./unwrap-handler-return-BwclbliB.mjs";const u=new Set(["delete","get","head","options","patch","post","put"]),E=new Set(["body","params","searchParams"]),v=new Set(["handler","stream"]),P=s=>{const e=s.getArguments()[0];if(e&&n.isStringLiteral(e))return e.getLiteralValue()},S=s=>{const e=s.getArguments()[0];return e&&n.isObjectLiteralExpression(e)?l(e):{}},A=s=>{if(!n.isCallExpression(s))return;const e=s.getExpression();if(!n.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const a=e.getExpression();if(!n.isIdentifier(a)||a.getText()!=="httpRoute")return;const t=P(s);return t===void 0?void 0:{method:o.toUpperCase(),path:t}},b=(s,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},a=s.getExpression();if(!n.isPropertyAccessExpression(a))return;let t=a.getExpression();for(;n.isCallExpression(t);){const i=t.getExpression();if(!n.isPropertyAccessExpression(i))break;const c=i.getName();if(u.has(c))break;if(E.has(c)){const p=S(t);o[c]={...p,...o[c]}}else if(c==="output"&&o.output===void 0){const p=t.getArguments()[0];p&&n.isExpression(p)&&(o.output=m(p))}t=i.getExpression()}const r=A(t);if(r)return o.method=r.method,o.path=r.path,o},T=s=>{const e=s.getArguments()[0];return!e||!(n.isArrowFunction(e)||n.isFunctionExpression(e))?"unknown":x(e,!0)},y=(s,e,o,a)=>{const t=e.getName();if(!v.has(t))return;const r=b(s,t);if(!(r?.method===void 0||r.path===void 0))return{body:r.body,exportName:o,filePath:a,method:r.method,params:r.params,path:r.path,searchParams:r.searchParams,stream:r.stream,...r.stream?{chunkType:T(s)}:{},...r.output?{output:r.output}:{}}},R=(s,e)=>{const o=[];for(const a of f(s)){const t=a.getInitializer();if(!t||!n.isCallExpression(t))continue;const r=t.getExpression();if(!n.isPropertyAccessExpression(r))continue;const i=y(t,r,g(a)??a.getName(),e);i&&o.push(i)}return o},L=(s,e)=>{const o=d(e),a=[];for(const t of o){const r=s.getSourceFile(t)??s.addSourceFileAtPath(t),i=h(e,t);a.push(...R(r,i))}return a.sort((t,r)=>`${t.method} ${t.path}`.localeCompare(`${r.method} ${r.path}`)||t.filePath.localeCompare(r.filePath)),a};export{L as default};
@@ -0,0 +1 @@
1
+ import{d as o}from"./context-property-calls-DdoCuhv4.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
@@ -1 +1 @@
1
- import{Node as i}from"ts-morph";import{collectCallRows as n}from"./isTestPath-B81lOULB.mjs";import{c as a}from"./attribution-hVBriwzy.mjs";import{i as c}from"./database-calls-BPpefKqO.mjs";const l=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="insert")return!1;const r=e.getExpression();return c(r)},g=t=>{if(!i.isIdentifier(t))return;const e=t.getSymbol(),r=e?.getAliasedSymbol()?.getDeclarations()??e?.getDeclarations()??[];for(const s of r)if(i.isVariableDeclaration(s)){const o=s.getInitializer();if(o&&i.isStringLiteral(o))return o.getLiteralText()}},f=t=>{const e=t.getArguments()[0];return e?i.isStringLiteral(e)?e.getLiteralText():g(e)??"":""},d=(t,e)=>n(t,e,(r,s)=>l(r)?{file:s,line:r.getStartLineNumber(),scope:a(r),table:f(r)}:void 0);export{d as default};
1
+ import{Node as i}from"ts-morph";import{collectCallRows as n}from"./isTestPath-B81lOULB.mjs";import{c as a}from"./attribution-hVBriwzy.mjs";import{i as c}from"./database-calls-CVsXSVhv.mjs";const l=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="insert")return!1;const r=e.getExpression();return c(r)},g=t=>{if(!i.isIdentifier(t))return;const e=t.getSymbol(),r=e?.getAliasedSymbol()?.getDeclarations()??e?.getDeclarations()??[];for(const s of r)if(i.isVariableDeclaration(s)){const o=s.getInitializer();if(o&&i.isStringLiteral(o))return o.getLiteralText()}},f=t=>{const e=t.getArguments()[0];return e?i.isStringLiteral(e)?e.getLiteralText():g(e)??"":""},d=(t,e)=>n(t,e,(r,s)=>l(r)?{file:s,line:r.getStartLineNumber(),scope:a(r),table:f(r)}:void 0);export{d as default};
@@ -0,0 +1 @@
1
+ import"./isTestPath-B81lOULB.mjs";import"./attribution-hVBriwzy.mjs";import"./database-calls-CVsXSVhv.mjs";import"./classify-procedure-call-BAj0D1u2.mjs";import{d as a}from"./index-Bxn8ZjS0.mjs";export{a as default};
@@ -1 +1 @@
1
- import{Node as i,SyntaxKind as u}from"ts-morph";import{collectCallRows as x}from"./isTestPath-B81lOULB.mjs";import{w as E,c as h}from"./attribution-hVBriwzy.mjs";import{i as v}from"./database-calls-BPpefKqO.mjs";const A=new Set(["withGeoIndex","withIndex","withSearchIndex"]),S=new Set(["collect","collectWithScores","first","paginate","take","unique"]),w=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="query")return!1;const n=e.getExpression();return v(n)},y=t=>{const e=[];let n=t;for(;;){const s=n.getParent();if(!s||!i.isPropertyAccessExpression(s))break;const r=s.getParent();if(!r||!i.isCallExpression(r))break;e.push(r),n=r}return e},l=t=>{const e=t.getExpression();return i.isPropertyAccessExpression(e)?e.getName():""},m=t=>{if(t===void 0||!(i.isArrowFunction(t)||i.isFunctionExpression(t)))return;const e=t.getParameters()[0]?.getNameNode();return e!==void 0&&i.isIdentifier(e)?e.getText():void 0},O=t=>{let e=t;for(;i.isCallExpression(e)||i.isPropertyAccessExpression(e);)e=e.getExpression();return e},P=(t,e)=>{const n=new Set,s=[t,...t.getDescendantsOfKind(u.CallExpression)].filter(r=>i.isCallExpression(r));for(const r of s){const c=r.getExpression();if(i.isPropertyAccessExpression(c)){const o=O(c);i.isIdentifier(o)&&o.getText()===e&&n.add(c.getName())}}return n},f=(t,e)=>{if(i.isParenthesizedExpression(t))return f(t.getExpression(),e);if(i.isConditionalExpression(t)){const n=f(t.getWhenFalse(),e);return new Set([...f(t.getWhenTrue(),e)].filter(s=>n.has(s)))}return P(t,e)},C=t=>{if(!(i.isArrowFunction(t)||i.isFunctionExpression(t)))return;const e=t.getBody();if(!i.isBlock(e))return i.isExpression(e)?[e]:void 0;const n=e.getDescendantsOfKind(u.ReturnStatement).filter(s=>s.getFirstAncestor(r=>i.isArrowFunction(r)||i.isFunctionExpression(r))?.compilerNode===t.compilerNode).map(s=>s.getExpression()).filter(s=>s!==void 0);return n.length===0?void 0:n},F=(t,e)=>{const n=C(t);if(n===void 0)return;const[s,...r]=n.map(o=>f(o,e));return[...s??new Set].filter(o=>r.every(d=>d.has(o))).toSorted((o,d)=>o.localeCompare(d))},I=(t,e)=>{const n=new Set;for(const s of t.getDescendantsOfKind(u.PropertyAccessExpression)){const r=s.getExpression();i.isIdentifier(r)&&r.getText()===e&&n.add(s.getName())}for(const s of t.getDescendantsOfKind(u.ElementAccessExpression)){const r=s.getExpression(),c=s.getArgumentExpression();i.isIdentifier(r)&&r.getText()===e&&c!==void 0&&i.isStringLiteral(c)&&n.add(c.getLiteralText())}return[...n]},N=t=>{if(t===void 0)return;const[e,n]=t.getArguments(),s=m(n),r=e!==void 0&&i.isStringLiteral(e)?e.getLiteralText():void 0;return n===void 0?{bounds:[],name:r}:{bounds:s===void 0?void 0:F(n,s),name:r}},T=t=>{const e=t.flatMap(n=>{const s=n.getArguments()[0],r=m(s);return s===void 0||r===void 0?[]:I(s,r)});if(e.length!==0)return[...new Set(e)].toSorted((n,s)=>n.localeCompare(s))},b=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,D=t=>t.some(e=>l(e)==="filter"&&b.test(e.getArguments()[0]?.getText()??"")),L=t=>{const e=t.getArguments()[0];return e&&i.isStringLiteral(e)?e.getLiteralText():""},k=(t,e,n=[])=>{const s=x(t,e,(r,c)=>{if(!w(r))return;const o=y(r),d=o.map(a=>l(a)),p=o.filter(a=>l(a)==="filter"),g=p.length>0;return{file:c,filterFields:g?T(p):void 0,filtersPrimaryKey:g&&D(o),hasFilter:g,hasIndex:d.some(a=>A.has(a)),index:N(o.find(a=>l(a)==="withIndex")),line:r.getStartLineNumber(),scope:h(r),table:L(r),terminal:d.findLast(a=>S.has(a))}});return E(s,n)};export{k as default};
1
+ import{Node as i,SyntaxKind as u}from"ts-morph";import{collectCallRows as x}from"./isTestPath-B81lOULB.mjs";import{w as E,c as h}from"./attribution-hVBriwzy.mjs";import{i as v}from"./database-calls-CVsXSVhv.mjs";const A=new Set(["withGeoIndex","withIndex","withSearchIndex"]),S=new Set(["collect","collectWithScores","first","paginate","take","unique"]),w=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="query")return!1;const n=e.getExpression();return v(n)},y=t=>{const e=[];let n=t;for(;;){const s=n.getParent();if(!s||!i.isPropertyAccessExpression(s))break;const r=s.getParent();if(!r||!i.isCallExpression(r))break;e.push(r),n=r}return e},l=t=>{const e=t.getExpression();return i.isPropertyAccessExpression(e)?e.getName():""},m=t=>{if(t===void 0||!(i.isArrowFunction(t)||i.isFunctionExpression(t)))return;const e=t.getParameters()[0]?.getNameNode();return e!==void 0&&i.isIdentifier(e)?e.getText():void 0},O=t=>{let e=t;for(;i.isCallExpression(e)||i.isPropertyAccessExpression(e);)e=e.getExpression();return e},P=(t,e)=>{const n=new Set,s=[t,...t.getDescendantsOfKind(u.CallExpression)].filter(r=>i.isCallExpression(r));for(const r of s){const c=r.getExpression();if(i.isPropertyAccessExpression(c)){const o=O(c);i.isIdentifier(o)&&o.getText()===e&&n.add(c.getName())}}return n},f=(t,e)=>{if(i.isParenthesizedExpression(t))return f(t.getExpression(),e);if(i.isConditionalExpression(t)){const n=f(t.getWhenFalse(),e);return new Set([...f(t.getWhenTrue(),e)].filter(s=>n.has(s)))}return P(t,e)},C=t=>{if(!(i.isArrowFunction(t)||i.isFunctionExpression(t)))return;const e=t.getBody();if(!i.isBlock(e))return i.isExpression(e)?[e]:void 0;const n=e.getDescendantsOfKind(u.ReturnStatement).filter(s=>s.getFirstAncestor(r=>i.isArrowFunction(r)||i.isFunctionExpression(r))?.compilerNode===t.compilerNode).map(s=>s.getExpression()).filter(s=>s!==void 0);return n.length===0?void 0:n},F=(t,e)=>{const n=C(t);if(n===void 0)return;const[s,...r]=n.map(o=>f(o,e));return[...s??new Set].filter(o=>r.every(d=>d.has(o))).toSorted((o,d)=>o.localeCompare(d))},I=(t,e)=>{const n=new Set;for(const s of t.getDescendantsOfKind(u.PropertyAccessExpression)){const r=s.getExpression();i.isIdentifier(r)&&r.getText()===e&&n.add(s.getName())}for(const s of t.getDescendantsOfKind(u.ElementAccessExpression)){const r=s.getExpression(),c=s.getArgumentExpression();i.isIdentifier(r)&&r.getText()===e&&c!==void 0&&i.isStringLiteral(c)&&n.add(c.getLiteralText())}return[...n]},N=t=>{if(t===void 0)return;const[e,n]=t.getArguments(),s=m(n),r=e!==void 0&&i.isStringLiteral(e)?e.getLiteralText():void 0;return n===void 0?{bounds:[],name:r}:{bounds:s===void 0?void 0:F(n,s),name:r}},T=t=>{const e=t.flatMap(n=>{const s=n.getArguments()[0],r=m(s);return s===void 0||r===void 0?[]:I(s,r)});if(e.length!==0)return[...new Set(e)].toSorted((n,s)=>n.localeCompare(s))},b=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,D=t=>t.some(e=>l(e)==="filter"&&b.test(e.getArguments()[0]?.getText()??"")),L=t=>{const e=t.getArguments()[0];return e&&i.isStringLiteral(e)?e.getLiteralText():""},k=(t,e,n=[])=>{const s=x(t,e,(r,c)=>{if(!w(r))return;const o=y(r),d=o.map(a=>l(a)),p=o.filter(a=>l(a)==="filter"),g=p.length>0;return{file:c,filterFields:g?T(p):void 0,filtersPrimaryKey:g&&D(o),hasFilter:g,hasIndex:d.some(a=>A.has(a)),index:N(o.find(a=>l(a)==="withIndex")),line:r.getStartLineNumber(),scope:h(r),table:L(r),terminal:d.findLast(a=>S.has(a))}});return E(s,n)};export{k as default};
@@ -0,0 +1 @@
1
+ import{d as r}from"./context-property-calls-DdoCuhv4.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
@@ -1 +1 @@
1
- import{Node as o}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as f,findObjectProperty as u}from"./isTestPath-B81lOULB.mjs";import{b as p,d}from"./attribution-hVBriwzy.mjs";import{t as m}from"./database-calls-BPpefKqO.mjs";import{c as b}from"./classify-procedure-call-BAj0D1u2.mjs";import{r as h}from"./chain-CRDaTj2c.mjs";const g=e=>{const t=e.getArguments()[0];if(!t||!o.isArrayLiteralExpression(t))return[];const r=[];for(const s of t.getElements()){if(!o.isObjectLiteralExpression(s))continue;const i=u(s,"table");if(!i||!o.isPropertyAssignment(i))continue;const n=i.getInitializer();n&&o.isStringLiteral(n)&&r.push(n.getLiteralText())}return r},y=e=>{const t=h(e);return{rlsTables:t.flatMap(r=>g(r)),usesRls:t.length>0}},v=new Set(["explain","findFirst","findFirstOrThrow","findMany","get","query"]),x=new Set(["delete","deleteMany","insert","insertMany","patch","patchIf","patchMany","replace"]),P=(e,t)=>{if(!o.isVariableDeclaration(e))return;const r=e.getInitializer();if(!r||!o.isCallExpression(r))return;const s=b(r);if(!s)return;const i=s.receiver?y(s.receiver):{rlsTables:[],usesRls:!1},{tablesRead:n,tablesWritten:a}=m(e,v,x);return{exportName:d(e)??e.getName(),file:t,rlsTables:i.rlsTables,tablesRead:n,tablesWritten:a,usesRls:i.usesRls,visibility:s.visibility}},M=(e,t)=>{const r=[];for(const s of c(t)){const i=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=f(t,s);for(const a of p(i)){const l=P(a,n);l&&r.push(l)}}return r};export{M as default};
1
+ import{Node as o}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as f,findObjectProperty as u}from"./isTestPath-B81lOULB.mjs";import{b as p,d}from"./attribution-hVBriwzy.mjs";import{t as m}from"./database-calls-CVsXSVhv.mjs";import{c as b}from"./classify-procedure-call-BAj0D1u2.mjs";import{r as h}from"./chain-CRDaTj2c.mjs";const g=e=>{const t=e.getArguments()[0];if(!t||!o.isArrayLiteralExpression(t))return[];const r=[];for(const s of t.getElements()){if(!o.isObjectLiteralExpression(s))continue;const i=u(s,"table");if(!i||!o.isPropertyAssignment(i))continue;const n=i.getInitializer();n&&o.isStringLiteral(n)&&r.push(n.getLiteralText())}return r},y=e=>{const t=h(e);return{rlsTables:t.flatMap(r=>g(r)),usesRls:t.length>0}},v=new Set(["explain","findFirst","findFirstOrThrow","findMany","get","query"]),x=new Set(["delete","deleteMany","insert","insertMany","patch","patchIf","patchMany","replace"]),P=(e,t)=>{if(!o.isVariableDeclaration(e))return;const r=e.getInitializer();if(!r||!o.isCallExpression(r))return;const s=b(r);if(!s)return;const i=s.receiver?y(s.receiver):{rlsTables:[],usesRls:!1},{tablesRead:n,tablesWritten:a}=m(e,v,x);return{exportName:d(e)??e.getName(),file:t,rlsTables:i.rlsTables,tablesRead:n,tablesWritten:a,usesRls:i.usesRls,visibility:s.visibility}},M=(e,t)=>{const r=[];for(const s of c(t)){const i=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=f(t,s);for(const a of p(i)){const l=P(a,n);l&&r.push(l)}}return r};export{M as default};
@@ -1 +1 @@
1
- import{Node as r}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as f}from"./isTestPath-B81lOULB.mjs";import{b as m,d as p}from"./attribution-hVBriwzy.mjs";import{t as d}from"./database-calls-BPpefKqO.mjs";import{w as g,c as h}from"./classify-procedure-call-BAj0D1u2.mjs";import{a as k}from"./project-config-file-BV7RR-l6.mjs";const l=e=>{if(!(!r.isPropertyAssignment(e)&&!r.isShorthandPropertyAssignment(e)&&!r.isMethodDeclaration(e)&&!r.isGetAccessorDeclaration(e)))return k(e)},v=e=>g(e,"use","mask"),D=e=>{if(r.isPropertyAssignment(e)){const s=e.getInitializer();if(s&&r.isStringLiteral(s)){const t=s.getLiteralText();if(t==="redact"||t==="hash")return t}}return"custom"},P=e=>{const s=e.getArguments()[0];if(!s||!r.isObjectLiteralExpression(s))return[];const t=[];for(const i of s.getProperties()){const o=l(i);if(o===void 0||!r.isPropertyAssignment(i))continue;const n=i.getInitializer();if(!(!n||!r.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=l(a);c!==void 0&&t.push({column:c,table:o})}}return t},y=e=>{const s=v(e);return{maskColumns:s.flatMap(t=>P(t)),usesMask:s.length>0}},C=new Set(["explain","findFirst","findFirstOrThrow","findMany","get","query"]),M=new Set(["delete","insert","patch","replace"]),x=(e,s)=>{if(!r.isVariableDeclaration(e))return;const t=e.getInitializer();if(!t||!r.isCallExpression(t))return;const i=h(t);if(!i)return;const o=i.receiver?y(i.receiver):{maskColumns:[],usesMask:!1},{tablesRead:n,tablesWritten:a}=d(e,C,M);return{exportName:p(e)??e.getName(),file:s,maskColumns:o.maskColumns,tablesRead:n,tablesWritten:a,usesMask:o.usesMask,visibility:i.visibility}},E=(e,s)=>{const t=[];for(const i of u(s)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i),n=f(s,i);for(const a of m(o)){const c=x(a,n);c&&t.push(c)}}return t};export{l as a,E as d,v as m,D as s};
1
+ import{Node as r}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as f}from"./isTestPath-B81lOULB.mjs";import{b as m,d as p}from"./attribution-hVBriwzy.mjs";import{t as d}from"./database-calls-CVsXSVhv.mjs";import{w as g,c as h}from"./classify-procedure-call-BAj0D1u2.mjs";import{a as k}from"./project-config-file-BV7RR-l6.mjs";const l=e=>{if(!(!r.isPropertyAssignment(e)&&!r.isShorthandPropertyAssignment(e)&&!r.isMethodDeclaration(e)&&!r.isGetAccessorDeclaration(e)))return k(e)},v=e=>g(e,"use","mask"),D=e=>{if(r.isPropertyAssignment(e)){const s=e.getInitializer();if(s&&r.isStringLiteral(s)){const t=s.getLiteralText();if(t==="redact"||t==="hash")return t}}return"custom"},P=e=>{const s=e.getArguments()[0];if(!s||!r.isObjectLiteralExpression(s))return[];const t=[];for(const i of s.getProperties()){const o=l(i);if(o===void 0||!r.isPropertyAssignment(i))continue;const n=i.getInitializer();if(!(!n||!r.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=l(a);c!==void 0&&t.push({column:c,table:o})}}return t},y=e=>{const s=v(e);return{maskColumns:s.flatMap(t=>P(t)),usesMask:s.length>0}},C=new Set(["explain","findFirst","findFirstOrThrow","findMany","get","query"]),M=new Set(["delete","insert","patch","replace"]),x=(e,s)=>{if(!r.isVariableDeclaration(e))return;const t=e.getInitializer();if(!t||!r.isCallExpression(t))return;const i=h(t);if(!i)return;const o=i.receiver?y(i.receiver):{maskColumns:[],usesMask:!1},{tablesRead:n,tablesWritten:a}=d(e,C,M);return{exportName:p(e)??e.getName(),file:s,maskColumns:o.maskColumns,tablesRead:n,tablesWritten:a,usesMask:o.usesMask,visibility:i.visibility}},E=(e,s)=>{const t=[];for(const i of u(s)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i),n=f(s,i);for(const a of m(o)){const c=x(a,n);c&&t.push(c)}}return t};export{l as a,E as d,v as m,D as s};
@@ -0,0 +1 @@
1
+ import{posix as w,dirname as h,join as F}from"node:path";import{Node as l,SyntaxKind as g,DiagnosticCategory as K}from"ts-morph";import{lunoraRelativePath as B}from"./isTestPath-B81lOULB.mjs";let p,v;const Oe=e=>{const t=p,n=[];p=n;try{return{erased:n,value:e()}}finally{p=t}},Ue=e=>{p?.push(...e)},V=e=>{for(const t of e.getAncestors())if(l.isVariableDeclaration(t))return t.getName()},E=(e,t)=>{p?.push({exportName:V(e),filePath:e.getSourceFile().getFilePath(),line:e.getStartLineNumber(),rendered:t})},Pe=e=>{v!==void 0&&E(v,e)},Le=(e,t)=>{const n=v;v=e;try{return t()}finally{v=n}},W=(e,t)=>{const n=e.exportName??`line ${e.line.toString()}`;return{cacheKey:`procedure_return_type_erased:${t}:${n}`,categories:["SCHEMA"],description:"Codegen renders a procedure's return type into `_generated/`, where only names that resolve from that directory may appear. A type it can neither name nor reproduce structurally — a class instance, a call or index signature, a recursive or very deeply nested shape — is emitted as `unknown` instead, so callers lose the shape while the runtime still returns it.",detail:`\`${n}\` in \`${t}\` (line ${e.line.toString()}) returns \`${e.rendered}\`, which codegen could not reproduce — its generated type is \`unknown\`.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e.exportName,filePath:t,line:e.line,rendered:e.rendered},name:"procedure_return_type_erased",remediation:"Declare the shape explicitly with `.output(...)`, or export the type from the module that declares it so codegen can name it. A class instance cannot cross the wire at all — return a plain object.",title:"Procedure return type is missing from the generated type"}},Fe=(e,t)=>{const n=new Map;for(const r of e){const s=W(r,B(t,r.filePath));n.set(s.cacheKey,s)}return[...n.values()].toSorted((r,s)=>r.cacheKey.localeCompare(s.cacheKey))},q=/\bany\b(?!\s*(?:\?\s*)?:)/u,G=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,X=e=>q.test(e.replaceAll(G,"")),H="/_generated/",J=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(n=>n?.getDeclarations()??[]);return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},Y=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,x=e=>{for(const t of e.getAncestors())if(l.isModuleDeclaration(t)){const n=Y.exec(t.getName());if(n?.groups?.specifier!==void 0)return n.groups.specifier}},M=new WeakMap,z=(e,t)=>{const n=e.getSymbol();if(n===void 0)return;let r=M.get(n.compilerSymbol);return r===void 0&&(r=new Map,M.set(n.compilerSymbol,r)),r.has(t)||r.set(t,n.getExport(t)??e.getExportSymbols().find(s=>s.getName()===t)),r.get(t)},C=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(n=>n.getName()===t),Q=(e,t,n)=>e.getModuleSpecifierValue()===t&&C(e,n)?n:void 0,Z=(e,t)=>{const n=e.getDefaultImport();if(n===void 0)return;const r=n.getSymbol();return(r?.getAliasedSymbol()??r)?.getDeclarations().includes(t)===!0?"default":void 0},ee=(e,t,n)=>{if(!C(e,n))return;const r=e.getModuleSpecifierSourceFile(),s=r===void 0?void 0:z(r,n);return(s?.getAliasedSymbol()??s)?.getDeclarations().includes(t)===!0?n:void 0},te=/^\.\.?(?:$|\/)/u,ne=new Map([[".cjs",".cjs"],[".cts",".cjs"],[".d.ts",".js"],[".js",".js"],[".jsx",".jsx"],[".mjs",".mjs"],[".mts",".mjs"],[".ts",".js"],[".tsx",".js"]]),re=(e,t)=>{const n=t.getModuleSpecifierValue();if(!te.test(n))return;const r=t.getModuleSpecifierSourceFile(),s=r===void 0?void 0:ne.get(r.getExtension());if(r===void 0||s===void 0)return;const i=`${w.join(r.getDirectoryPath(),r.getBaseNameWithoutExtension())}${s}`,o=w.relative(e.getDirectoryPath(),i);return o.startsWith(".")?o:`./${o}`},se=(e,t,n)=>{const r=x(t);for(const s of e.getImportDeclarations()){const i=r===void 0?Z(s,t)??ee(s,t,n):Q(s,r,n);if(i!==void 0)return{exportName:i,specifier:re(e,s)??s.getModuleSpecifierValue()}}},oe=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(n=>{const r=n.indexOf("*");return r===-1?e===n:e.startsWith(n.slice(0,r))&&e.endsWith(n.slice(r+1))}),f={kind:"verbatim"},S={kind:"expand"},ie=new Set([g.ClassDeclaration,g.EnumDeclaration,g.EnumMember,g.InterfaceDeclaration,g.TypeAliasDeclaration]),ae=e=>x(e)!==void 0||l.isExportable(e)&&e.isExported(),ce=(e,t)=>new RegExp(String.raw`(?<![$\w])${t.replaceAll(/[$()*+.?[\\\]^{|}]/gu,String.raw`\$&`)}(?![$\w])`,"u").test(e),O=(e,t,n,r)=>{const s=e.getSourceFile();if(s.getSymbol()===void 0&&x(e)===void 0||!ie.has(e.getKind()))return f;const i=s.getFilePath();if(i.includes(H))return f;if(i===n)return S;const o=l.isEnumMember(e)?e.getParent():e;if(!l.hasName(o))return S;const c=se(t.getSourceFile(),o,o.getName());return c===void 0?ae(o)||!ce(r(),o.getName())?f:S:oe(c.specifier,t)?S:{kind:"qualify",qualified:c}},ue=new Set([g.ClassDeclaration,g.EnumDeclaration,g.FunctionDeclaration,g.ModuleDeclaration]),_=e=>{const t=e?.getDeclarations()??[];return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},le=e=>{for(const t of e.getDeclarations()){const n=t.getFirstChildByKind(g.ComputedPropertyName);if(n!==void 0){let r=n.getExpression();for(;l.isPropertyAccessExpression(r);)r=r.getExpression();return r}}},ge=(e,t)=>{if(e.getProperties().some(s=>{if(!s.getName().startsWith("__@"))return!1;const i=le(s);return i===void 0||!_(i.getSymbol())}))return!0;const r=e.getSymbol();return r!==void 0&&r.getDeclarations().some(s=>ue.has(s.getKind()))&&!_(r)&&t().startsWith("typeof ")},U=(e,t,n)=>{const r=e.getAliasSymbol(),s=e.getSymbol(),i=new Set((r??s)?.getDeclarations());let o=!1,c;const a=()=>(c??=e.getText(t),c);for(const u of[s,r].flatMap(d=>d?.getDeclarations()??[])){const d=O(u,t,n,a);if(d.kind==="qualify"&&i.has(u))return d;o||=d.kind!=="verbatim"}return o||ge(e,a)?S:f},de=(e,t,n)=>{const r=l.isPropertySignature(e)||l.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(r===void 0)return f;let s=!1;for(const i of[r,...r.getDescendantsOfKind(g.TypeReference)].filter(o=>l.isTypeReference(o))){const o=i.getTypeName().getSymbol();for(const c of(o?.getAliasedSymbol()??o)?.getDeclarations()??[]){const a=O(c,t,n,()=>i.getText());if(a.kind==="qualify")return a;s||=a.kind!=="verbatim"}}return s?S:f},fe=/^[A-Za-z_$][\w$]*$/u,me=e=>fe.test(e)?e:JSON.stringify(e),P=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},A=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0&&!e.getProperties().some(t=>t.getName().startsWith("__@")),T=(e,t,n,r=new Set)=>r.has(e)?!1:(r.add(e),U(e,t,n).kind!=="verbatim"||P(e).some(s=>T(s,t,n,r))?!0:A(e)?e.getProperties().some(s=>s.getDeclarations().some(i=>de(i,t,n).kind!=="verbatim")?!0:T(s.getTypeAtLocation(t),t,n,r)):!1),Se=(e,t)=>{const n=e.getValueDeclaration()??e.getDeclarations()[0];return n&&(l.isPropertySignature(n)||l.isPropertyDeclaration(n))&&n.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},L=(e,t)=>e!==void 0&&(A(e)||e.isString()||e.isNumber()||e.isBigInt()||e.isBoolean()||e.isLiteral()||e.isBooleanLiteral()||e.isEnumLiteral()||e.isTemplateLiteral()||e.isNull()||e.isUndefined()||e.isAny()||e.isUnknown()||e.isNever()||e.isVoid())?t:`(${t})`,pe=32,ve=8,Ee=(e,t,n,r,s,i)=>{const o=e.getArrayElementType(),c=o?i(o,t,n,r,s):void 0;if(c!==void 0)return`${L(o,c)}[]`},ye=(e,t,n,r,s,i)=>{const o=[];for(const c of e.getUnionTypes()){const a=i(c,t,n,r,s);if(a===void 0)return;o.push(a)}return o.join(" | ")},be=(e,t,n,r,s,i)=>{const o=[];for(const c of e.getIntersectionTypes()){const a=i(c,t,n,r,s);if(a===void 0)return;o.push(L(c,a))}return o.join(" & ")},Te=(e,t,n,r,s,i)=>{if(!A(e))return;const o=[];for(const c of e.getProperties()){const a=c.getTypeAtLocation(t),u=Se(c,a),d=u&&a.isUnion()?a.getUnionTypes().filter(N=>!N.isUndefined()):[a],D=[];for(const N of d){const I=i(N,t,n,r+1,s);if(I===void 0)return;D.push(I)}o.push(`${me(c.getName())}${u?"?":""}: ${D.join(" | ")}`)}return o.length>0?`{ ${o.join("; ")} }`:"{}"},Ae=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},Ne=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isClassDeclaration(t)||l.isClassExpression(t)),y=(e,t,n,r,s=new Set)=>{if(r.has(e)||s.has(e))return!1;if(n>pe)return!0;const i=new Set(r).add(e);if(P(e).some(u=>y(u,t,n+1,i,s)))return!0;const o=e.getArrayElementType();if(o!==void 0)return y(o,t,n+1,i,s);if(J(e))return s.add(e),!1;if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(u=>u?.getDeclarations()??[]).some(u=>l.isClassDeclaration(u)||l.isClassExpression(u)))return!0;const a=A(e)&&e.getProperties().some(u=>y(u.getTypeAtLocation(t),t,n+1,i,s));return a||s.add(e),a},xe=(e,t,n,r,s,i,o)=>{const c=[];for(const a of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const u=o(a,n,r,s+1,i);if(u===void 0)return;c.push(u)}return`import("${e.specifier}").${e.exportName}${c.length>0?`<${c.join(", ")}>`:""}`},De=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isEnumDeclaration(t)||l.isEnumMember(t)),m=(e,t,n,r,s)=>{if(r>ve||s.has(e))return;const i=U(e,t,n);if(i.kind==="verbatim"&&!T(e,t,n))return e.getText(t);const o=new Set(s).add(e);if(!Ne(e)){if(e.isEnumLiteral())return Ae(e);if(i.kind==="qualify"&&!De(e)){const c=xe(i.qualified,e,t,n,r,o,m);if(c!==void 0)return c}return e.isArray()?Ee(e,t,n,r,o,m):e.isUnion()?ye(e,t,n,r,o,m):e.isIntersection()?be(e,t,n,r,o,m):Te(e,t,n,r,o,m)}},R=new WeakMap,Ie=e=>{const t=R.get(e.compilerNode);if(t)return t;const n=e.getPreEmitDiagnostics().filter(r=>r.getCategory()===K.Error);return R.set(e.compilerNode,n),n},b=e=>{const t=e.getMessageText();return typeof t=="string"?t:t.getMessageText()},we=/is of type 'unknown'|on type '\{\}'/,he=e=>we.test(e),Me=/has no exported member '([^']+)'/,_e=(e,t,n,r)=>{const s=e.getSourceFile();for(const i of e.getDescendantsOfKind(g.Identifier))for(const o of i.getSymbol()?.getDeclarations()??[]){const c=o.getStart();if(o.getSourceFile()!==s||c>=n&&c<=r)continue;const a=t.find(u=>{const d=u.getStart();return d!==void 0&&d>=o.getStart()&&d<=o.getEnd()});if(a!==void 0)return b(a)}},$=e=>{const t=e.getStart(),n=e.getEnd(),r=Ie(e.getSourceFile()),s=r.find(a=>{const u=a.getStart();return u!==void 0&&u>=t&&u<=n});if(s===void 0){const a=_e(e,r,t,n);return a===void 0?void 0:{derivative:!0,message:a}}const i=b(s);if(!he(i))return{derivative:!1,message:i};const o=new Set(e.getDescendantsOfKind(g.Identifier).map(a=>a.getText())),c=r.find(a=>{const u=Me.exec(b(a))?.[1];return u!==void 0&&o.has(u)});return{derivative:!0,message:c?`${i}; caused by: ${b(c)}`:i}},Re=e=>{const t=e.getProject().getFileSystem();let n=h(e.getFilePath());for(;;){const r=F(n,"package.json");if(t.fileExistsSync(r)){const{name:i}=JSON.parse(t.readFileSync(r));return typeof i=="string"?i:void 0}const s=h(n);if(s===n)return;n=s}},k=e=>{const t=e.getSymbol()??e.getAliasSymbol(),n=t?.getName()==="SseEvent"?t.getDeclarations()[0]:void 0;return n!==void 0&&Re(n.getSourceFile())==="@lunora/server"},$e=e=>{const t=e.isUnion()?e.getUnionTypes():[e];if(t.some(n=>k(n)))return t.flatMap(n=>{const r=k(n)?n.getTypeArguments()[0]??n:n;return r.isUnion()?r.getUnionTypes():[r]})},j=(e,t)=>{const n=e.getText(t);if(!n||n==="any"||n==="never"||n==="unknown"){const s=$(t);return s!==void 0&&(n!=="unknown"||s.derivative)&&E(t,`${n||"any"} (${s.message})`),"unknown"}if(X(n)){const s=$(t);return s!==void 0&&E(t,`${n} (${s.message})`),"unknown"}if(y(e,t,0,new Set))return"unknown";const r=t.getSourceFile().getFilePath();if(T(e,t,r)){const s=m(e,t,r,0,new Set);return s===void 0&&E(t,n),s??"unknown"}return n},Ke=(e,t=!1)=>{const n=e.getType().getCallSignatures()[0];if(!n)return"unknown";let r=n.getReturnType();const i=(r.getSymbol()??r.getAliasSymbol())?.getName();if(i==="Promise"||i==="AsyncIterable"||i==="AsyncIterableIterator"||i==="AsyncGenerator"){const a=r.getTypeArguments()[0];a&&(r=a)}const o=t?$e(r):void 0;if(o===void 0)return j(r,e);const c=o.map(a=>j(a,e));return c.includes("unknown")?"unknown":[...new Set(c)].join(" | ")};export{T as a,Pe as b,Oe as c,Fe as d,m as e,X as i,Le as p,Ue as r,Ke as u};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.313",
3
+ "version": "1.0.0-alpha.314",
4
4
  "description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -50,15 +50,15 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@lunora/advisor": "1.0.0-alpha.223",
54
- "@lunora/agent": "1.0.0-alpha.214",
55
- "@lunora/container": "1.0.0-alpha.76",
53
+ "@lunora/advisor": "1.0.0-alpha.225",
54
+ "@lunora/agent": "1.0.0-alpha.216",
55
+ "@lunora/container": "1.0.0-alpha.77",
56
56
  "@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
57
- "@lunora/platform": "1.0.0-alpha.64",
58
- "@lunora/queue": "1.0.0-alpha.107",
59
- "@lunora/scheduler": "1.0.0-alpha.129",
60
- "@lunora/values": "1.0.0-alpha.66",
61
- "@lunora/workflow": "1.0.0-alpha.78",
57
+ "@lunora/platform": "1.0.0-alpha.65",
58
+ "@lunora/queue": "1.0.0-alpha.108",
59
+ "@lunora/scheduler": "1.0.0-alpha.130",
60
+ "@lunora/values": "1.0.0-alpha.67",
61
+ "@lunora/workflow": "1.0.0-alpha.79",
62
62
  "@visulima/fs": "6.0.29",
63
63
  "jiti": "^2.7.0",
64
64
  "quicktype-core": "^26.0.0",
@@ -1 +0,0 @@
1
- import{d as o}from"./context-property-calls-CQWCNUVH.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
@@ -1 +0,0 @@
1
- import"./isTestPath-B81lOULB.mjs";import"./attribution-hVBriwzy.mjs";import"./database-calls-BPpefKqO.mjs";import"./classify-procedure-call-BAj0D1u2.mjs";import{d as a}from"./index-CkS96b8a.mjs";export{a as default};
@@ -1 +0,0 @@
1
- import{d as r}from"./context-property-calls-CQWCNUVH.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
@@ -1 +0,0 @@
1
- import{Node as l,SyntaxKind as g,DiagnosticCategory as j}from"ts-morph";import{lunoraRelativePath as P}from"./isTestPath-B81lOULB.mjs";import{posix as h}from"node:path";let S,v;const _e=e=>{const t=S,r=[];S=r;try{return{erased:r,value:e()}}finally{S=t}},Re=e=>{S?.push(...e)},U=e=>{for(const t of e.getAncestors())if(l.isVariableDeclaration(t))return t.getName()},E=(e,t)=>{S?.push({exportName:U(e),filePath:e.getSourceFile().getFilePath(),line:e.getStartLineNumber(),rendered:t})},$e=e=>{v!==void 0&&E(v,e)},Ce=(e,t)=>{const r=v;v=e;try{return t()}finally{v=r}},K=(e,t)=>{const r=e.exportName??`line ${e.line.toString()}`;return{cacheKey:`procedure_return_type_erased:${t}:${r}`,categories:["SCHEMA"],description:"Codegen renders a procedure's return type into `_generated/`, where only names that resolve from that directory may appear. A type it can neither name nor reproduce structurally — a class instance, a call or index signature, a recursive or very deeply nested shape — is emitted as `unknown` instead, so callers lose the shape while the runtime still returns it.",detail:`\`${r}\` in \`${t}\` (line ${e.line.toString()}) returns \`${e.rendered}\`, which codegen could not reproduce — its generated type is \`unknown\`.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e.exportName,filePath:t,line:e.line,rendered:e.rendered},name:"procedure_return_type_erased",remediation:"Declare the shape explicitly with `.output(...)`, or export the type from the module that declares it so codegen can name it. A class instance cannot cross the wire at all — return a plain object.",title:"Procedure return type is missing from the generated type"}},ke=(e,t)=>{const r=new Map;for(const n of e){const s=K(n,P(t,n.filePath));r.set(s.cacheKey,s)}return[...r.values()].toSorted((n,s)=>n.cacheKey.localeCompare(s.cacheKey))},F=/\bany\b(?!\s*(?:\?\s*)?:)/u,B=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,V=e=>F.test(e.replaceAll(B,"")),W="/_generated/",q=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(r=>r?.getDeclarations()??[]);return t.length>0&&t.every(r=>r.getSourceFile().getSymbol()===void 0)},G=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,N=e=>{for(const t of e.getAncestors())if(l.isModuleDeclaration(t)){const r=G.exec(t.getName());if(r?.groups?.specifier!==void 0)return r.groups.specifier}},w=new WeakMap,X=(e,t)=>{const r=e.getSymbol();if(r===void 0)return;let n=w.get(r.compilerSymbol);return n===void 0&&(n=new Map,w.set(r.compilerSymbol,n)),n.has(t)||n.set(t,r.getExport(t)??e.getExportSymbols().find(s=>s.getName()===t)),n.get(t)},$=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(r=>r.getName()===t),H=(e,t,r)=>e.getModuleSpecifierValue()===t&&$(e,r)?r:void 0,Y=(e,t)=>{const r=e.getDefaultImport();if(r===void 0)return;const n=r.getSymbol();return(n?.getAliasedSymbol()??n)?.getDeclarations().includes(t)===!0?"default":void 0},J=(e,t,r)=>{if(!$(e,r))return;const n=e.getModuleSpecifierSourceFile(),s=n===void 0?void 0:X(n,r);return(s?.getAliasedSymbol()??s)?.getDeclarations().includes(t)===!0?r:void 0},z=/^\.\.?(?:$|\/)/u,Q=new Map([[".cjs",".cjs"],[".cts",".cjs"],[".d.ts",".js"],[".js",".js"],[".jsx",".jsx"],[".mjs",".mjs"],[".mts",".mjs"],[".ts",".js"],[".tsx",".js"]]),Z=(e,t)=>{const r=t.getModuleSpecifierValue();if(!z.test(r))return;const n=t.getModuleSpecifierSourceFile(),s=n===void 0?void 0:Q.get(n.getExtension());if(n===void 0||s===void 0)return;const o=`${h.join(n.getDirectoryPath(),n.getBaseNameWithoutExtension())}${s}`,i=h.relative(e.getDirectoryPath(),o);return i.startsWith(".")?i:`./${i}`},ee=(e,t,r)=>{const n=N(t);for(const s of e.getImportDeclarations()){const o=n===void 0?Y(s,t)??J(s,t,r):H(s,n,r);if(o!==void 0)return{exportName:o,specifier:Z(e,s)??s.getModuleSpecifierValue()}}},te=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(r=>{const n=r.indexOf("*");return n===-1?e===r:e.startsWith(r.slice(0,n))&&e.endsWith(r.slice(n+1))}),f={kind:"verbatim"},p={kind:"expand"},re=new Set([g.ClassDeclaration,g.EnumDeclaration,g.EnumMember,g.InterfaceDeclaration,g.TypeAliasDeclaration]),ne=e=>N(e)!==void 0||l.isExportable(e)&&e.isExported(),se=(e,t)=>new RegExp(String.raw`(?<![$\w])${t.replaceAll(/[$()*+.?[\\\]^{|}]/gu,String.raw`\$&`)}(?![$\w])`,"u").test(e),C=(e,t,r,n)=>{const s=e.getSourceFile();if(s.getSymbol()===void 0&&N(e)===void 0||!re.has(e.getKind()))return f;const o=s.getFilePath();if(o.includes(W))return f;if(o===r)return p;const i=l.isEnumMember(e)?e.getParent():e;if(!l.hasName(i))return p;const a=ee(t.getSourceFile(),i,i.getName());return a===void 0?ne(i)||!se(n(),i.getName())?f:p:te(a.specifier,t)?p:{kind:"qualify",qualified:a}},oe=new Set([g.ClassDeclaration,g.EnumDeclaration,g.FunctionDeclaration,g.ModuleDeclaration]),M=e=>{const t=e?.getDeclarations()??[];return t.length>0&&t.every(r=>r.getSourceFile().getSymbol()===void 0)},ie=e=>{for(const t of e.getDeclarations()){const r=t.getFirstChildByKind(g.ComputedPropertyName);if(r!==void 0){let n=r.getExpression();for(;l.isPropertyAccessExpression(n);)n=n.getExpression();return n}}},ae=(e,t)=>{if(e.getProperties().some(s=>{if(!s.getName().startsWith("__@"))return!1;const o=ie(s);return o===void 0||!M(o.getSymbol())}))return!0;const n=e.getSymbol();return n!==void 0&&n.getDeclarations().some(s=>oe.has(s.getKind()))&&!M(n)&&t().startsWith("typeof ")},k=(e,t,r)=>{const n=e.getAliasSymbol(),s=e.getSymbol(),o=new Set((n??s)?.getDeclarations());let i=!1,a;const c=()=>(a??=e.getText(t),a);for(const u of[s,n].flatMap(d=>d?.getDeclarations()??[])){const d=C(u,t,r,c);if(d.kind==="qualify"&&o.has(u))return d;i||=d.kind!=="verbatim"}return i||ae(e,c)?p:f},ce=(e,t,r)=>{const n=l.isPropertySignature(e)||l.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(n===void 0)return f;let s=!1;for(const o of[n,...n.getDescendantsOfKind(g.TypeReference)].filter(i=>l.isTypeReference(i))){const i=o.getTypeName().getSymbol();for(const a of(i?.getAliasedSymbol()??i)?.getDeclarations()??[]){const c=C(a,t,r,()=>o.getText());if(c.kind==="qualify")return c;s||=c.kind!=="verbatim"}}return s?p:f},ue=/^[A-Za-z_$][\w$]*$/u,le=e=>ue.test(e)?e:JSON.stringify(e),O=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},A=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0&&!e.getProperties().some(t=>t.getName().startsWith("__@")),T=(e,t,r,n=new Set)=>n.has(e)?!1:(n.add(e),k(e,t,r).kind!=="verbatim"||O(e).some(s=>T(s,t,r,n))?!0:A(e)?e.getProperties().some(s=>s.getDeclarations().some(o=>ce(o,t,r).kind!=="verbatim")?!0:T(s.getTypeAtLocation(t),t,r,n)):!1),ge=(e,t)=>{const r=e.getValueDeclaration()??e.getDeclarations()[0];return r&&(l.isPropertySignature(r)||l.isPropertyDeclaration(r))&&r.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(n=>n.isUndefined())},L=(e,t)=>e!==void 0&&(A(e)||e.isString()||e.isNumber()||e.isBigInt()||e.isBoolean()||e.isLiteral()||e.isBooleanLiteral()||e.isEnumLiteral()||e.isTemplateLiteral()||e.isNull()||e.isUndefined()||e.isAny()||e.isUnknown()||e.isNever()||e.isVoid())?t:`(${t})`,de=32,fe=8,me=(e,t,r,n,s,o)=>{const i=e.getArrayElementType(),a=i?o(i,t,r,n,s):void 0;if(a!==void 0)return`${L(i,a)}[]`},pe=(e,t,r,n,s,o)=>{const i=[];for(const a of e.getUnionTypes()){const c=o(a,t,r,n,s);if(c===void 0)return;i.push(c)}return i.join(" | ")},Se=(e,t,r,n,s,o)=>{const i=[];for(const a of e.getIntersectionTypes()){const c=o(a,t,r,n,s);if(c===void 0)return;i.push(L(a,c))}return i.join(" & ")},ve=(e,t,r,n,s,o)=>{if(!A(e))return;const i=[];for(const a of e.getProperties()){const c=a.getTypeAtLocation(t),u=ge(a,c),d=u&&c.isUnion()?c.getUnionTypes().filter(x=>!x.isUndefined()):[c],D=[];for(const x of d){const I=o(x,t,r,n+1,s);if(I===void 0)return;D.push(I)}i.push(`${le(a.getName())}${u?"?":""}: ${D.join(" | ")}`)}return i.length>0?`{ ${i.join("; ")} }`:"{}"},Ee=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},be=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isClassDeclaration(t)||l.isClassExpression(t)),b=(e,t,r,n,s=new Set)=>{if(n.has(e)||s.has(e))return!1;if(r>de)return!0;const o=new Set(n).add(e);if(O(e).some(u=>b(u,t,r+1,o,s)))return!0;const i=e.getArrayElementType();if(i!==void 0)return b(i,t,r+1,o,s);if(q(e))return s.add(e),!1;if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(u=>u?.getDeclarations()??[]).some(u=>l.isClassDeclaration(u)||l.isClassExpression(u)))return!0;const c=A(e)&&e.getProperties().some(u=>b(u.getTypeAtLocation(t),t,r+1,o,s));return c||s.add(e),c},ye=(e,t,r,n,s,o,i)=>{const a=[];for(const c of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const u=i(c,r,n,s+1,o);if(u===void 0)return;a.push(u)}return`import("${e.specifier}").${e.exportName}${a.length>0?`<${a.join(", ")}>`:""}`},Te=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isEnumDeclaration(t)||l.isEnumMember(t)),m=(e,t,r,n,s)=>{if(n>fe||s.has(e))return;const o=k(e,t,r);if(o.kind==="verbatim"&&!T(e,t,r))return e.getText(t);const i=new Set(s).add(e);if(!be(e)){if(e.isEnumLiteral())return Ee(e);if(o.kind==="qualify"&&!Te(e)){const a=ye(o.qualified,e,t,r,n,i,m);if(a!==void 0)return a}return e.isArray()?me(e,t,r,n,i,m):e.isUnion()?pe(e,t,r,n,i,m):e.isIntersection()?Se(e,t,r,n,i,m):ve(e,t,r,n,i,m)}},_=new WeakMap,Ae=e=>{const t=_.get(e.compilerNode);if(t)return t;const r=e.getPreEmitDiagnostics().filter(n=>n.getCategory()===j.Error);return _.set(e.compilerNode,r),r},y=e=>{const t=e.getMessageText();return typeof t=="string"?t:t.getMessageText()},xe=/is of type 'unknown'|on type '\{\}'/,Ne=e=>xe.test(e),De=/has no exported member '([^']+)'/,Ie=(e,t,r,n)=>{const s=e.getSourceFile();for(const o of e.getDescendantsOfKind(g.Identifier))for(const i of o.getSymbol()?.getDeclarations()??[]){const a=i.getStart();if(i.getSourceFile()!==s||a>=r&&a<=n)continue;const c=t.find(u=>{const d=u.getStart();return d!==void 0&&d>=i.getStart()&&d<=i.getEnd()});if(c!==void 0)return y(c)}},R=e=>{const t=e.getStart(),r=e.getEnd(),n=Ae(e.getSourceFile()),s=n.find(c=>{const u=c.getStart();return u!==void 0&&u>=t&&u<=r});if(s===void 0){const c=Ie(e,n,t,r);return c===void 0?void 0:{derivative:!0,message:c}}const o=y(s);if(!Ne(o))return{derivative:!1,message:o};const i=new Set(e.getDescendantsOfKind(g.Identifier).map(c=>c.getText())),a=n.find(c=>{const u=De.exec(y(c))?.[1];return u!==void 0&&i.has(u)});return{derivative:!0,message:a?`${o}; caused by: ${y(a)}`:o}},Oe=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let r=t.getReturnType();const s=(r.getSymbol()??r.getAliasSymbol())?.getName();if(s==="Promise"||s==="AsyncIterable"||s==="AsyncIterableIterator"||s==="AsyncGenerator"){const a=r.getTypeArguments()[0];a&&(r=a)}const o=r.getText(e);if(!o||o==="any"||o==="never"||o==="unknown"){const a=R(e);return a!==void 0&&(o!=="unknown"||a.derivative)&&E(e,`${o||"any"} (${a.message})`),"unknown"}if(V(o)){const a=R(e);return a!==void 0&&E(e,`${o} (${a.message})`),"unknown"}if(b(r,e,0,new Set))return"unknown";const i=e.getSourceFile().getFilePath();if(T(r,e,i)){const a=m(r,e,i,0,new Set);return a===void 0&&E(e,o),a??"unknown"}return o};export{T as a,$e as b,_e as c,ke as d,m as e,V as i,Ce as p,Re as r,Oe as u};