@lunora/codegen 1.0.0-alpha.291 → 1.0.0-alpha.292

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 (56) hide show
  1. package/dist/index.d.mts +1993 -1926
  2. package/dist/index.d.ts +1993 -1926
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/{AGENTS_FILENAME-CwwSEW6a.mjs → AGENTS_FILENAME-B6-kjzM3.mjs} +1 -1
  5. package/dist/packem_shared/{CONTAINERS_FILENAME-BtX5vWh8.mjs → CONTAINERS_FILENAME-Bk0u9QUu.mjs} +1 -1
  6. package/dist/packem_shared/{MUTATORS_FILENAME-Dl1tElqi.mjs → MUTATORS_FILENAME-Bw0YtaO8.mjs} +1 -1
  7. package/dist/packem_shared/{NOTIFY_FILENAME-BeTurUSC.mjs → NOTIFY_FILENAME-CPjbiHQl.mjs} +1 -1
  8. package/dist/packem_shared/{QUEUES_FILENAME-D588u733.mjs → QUEUES_FILENAME-CsRy4VTF.mjs} +1 -1
  9. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DndbpsGL.mjs +11 -0
  10. package/dist/packem_shared/{SHAPES_FILENAME-D-Q8lSEw.mjs → SHAPES_FILENAME-DkBUN9dK.mjs} +1 -1
  11. package/dist/packem_shared/{WORKFLOWS_FILENAME-BGMSNTDC.mjs → WORKFLOWS_FILENAME-CQR8fE9B.mjs} +1 -1
  12. package/dist/packem_shared/{attribution-BUciBs1M.mjs → attribution-hVBriwzy.mjs} +1 -1
  13. package/dist/packem_shared/chain-CRDaTj2c.mjs +1 -0
  14. package/dist/packem_shared/classify-procedure-call-BAj0D1u2.mjs +1 -0
  15. package/dist/packem_shared/{context-property-calls-DPnUYWSX.mjs → context-property-calls-DJ_A1R5i.mjs} +1 -1
  16. package/dist/packem_shared/{context-root-Dlo21ybw.mjs → context-root-wBahDTzk.mjs} +1 -1
  17. package/dist/packem_shared/createCodegenProject-V51_yBw3.mjs +1 -0
  18. package/dist/packem_shared/{database-calls-ONnjnkMd.mjs → database-calls-CHZbBUCZ.mjs} +1 -1
  19. package/dist/packem_shared/{discoverAuthApiCalls-DAaK0HUK.mjs → discoverAuthApiCalls-xs0ONfI-.mjs} +1 -1
  20. package/dist/packem_shared/{discoverFunctions-DsQwrwWq.mjs → discoverFunctions-DaEZl3uE.mjs} +1 -1
  21. package/dist/packem_shared/{discoverHttpRoutes-Cv-h-Yuc.mjs → discoverHttpRoutes-C_u9YiFb.mjs} +1 -1
  22. package/dist/packem_shared/discoverHyperdriveCalls-BUrA_96X.mjs +1 -0
  23. package/dist/packem_shared/{discoverInserts-CQsoloGk.mjs → discoverInserts-OT_fiEGq.mjs} +1 -1
  24. package/dist/packem_shared/discoverMaskProcedures--hMyCNud.mjs +1 -0
  25. package/dist/packem_shared/{discoverMigrations-uxm9qHrr.mjs → discoverMigrations-C9mLIhGZ.mjs} +1 -1
  26. package/dist/packem_shared/{discoverNondeterministicCalls-Dm7_PJoA.mjs → discoverNondeterministicCalls-9ZDpRptb.mjs} +1 -1
  27. package/dist/packem_shared/discoverQueries-C8V4cMIP.mjs +1 -0
  28. package/dist/packem_shared/discoverR2sqlCalls-COKmDnih.mjs +1 -0
  29. package/dist/packem_shared/{discoverRlsMetadata-Cu4bc5KZ.mjs → discoverRlsMetadata-Cb8JR1b4.mjs} +1 -1
  30. package/dist/packem_shared/{discoverRlsProcedures-Bkohn4ZR.mjs → discoverRlsProcedures-BMqosvx6.mjs} +1 -1
  31. package/dist/packem_shared/{discoverStorageRulesMetadata-D6rjgKYC.mjs → discoverStorageRulesMetadata-BPJplDfz.mjs} +1 -1
  32. package/dist/packem_shared/emitAgents-D_UUdNe1.mjs +1 -0
  33. package/dist/packem_shared/{emitApp-D7G7gmV7.mjs → emitApp-DAZCUDbr.mjs} +1 -1
  34. package/dist/packem_shared/{emitCrons-Gd8jD8jF.mjs → emitCrons-BQW2lviZ.mjs} +1 -1
  35. package/dist/packem_shared/emitServer-D1vA5_X1.mjs +1 -0
  36. package/dist/packem_shared/emitShard-DY0iaXec.mjs +1 -0
  37. package/dist/packem_shared/{exported-procedure-chains-BZk1-hro.mjs → exported-procedure-chains-DKK5HoK3.mjs} +1 -1
  38. package/dist/packem_shared/{handler-reference-DXkpwoAq.mjs → handler-reference-vIeqkhV_.mjs} +1 -1
  39. package/dist/packem_shared/{index-BoPXSW7g.mjs → index-BW4hJ4Wm.mjs} +1 -1
  40. package/dist/packem_shared/platform-8oj7iXQy.mjs +1 -0
  41. package/dist/packem_shared/schema-BgM8A3XV.mjs +1 -0
  42. package/dist/packem_shared/{server-DSUfd6Tc.mjs → server-DAvi_bv_.mjs} +2 -2
  43. package/dist/packem_shared/{shard-BNhX5R-a.mjs → shard-DfBMIpi9.mjs} +6 -6
  44. package/dist/packem_shared/{shard-runtime-CkaEBSdL.mjs → shard-runtime-BX0xmo0P.mjs} +3 -3
  45. package/package.json +6 -6
  46. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-3FEkspbx.mjs +0 -11
  47. package/dist/packem_shared/chain-BUxIVIw_.mjs +0 -1
  48. package/dist/packem_shared/classify-procedure-call-BJdf_-M6.mjs +0 -1
  49. package/dist/packem_shared/discoverHyperdriveCalls-xy2G6igG.mjs +0 -1
  50. package/dist/packem_shared/discoverMaskProcedures-Dr1UccD6.mjs +0 -1
  51. package/dist/packem_shared/discoverQueries-BqECbkm9.mjs +0 -1
  52. package/dist/packem_shared/discoverR2sqlCalls-I9IqJFcy.mjs +0 -1
  53. package/dist/packem_shared/emitAgents-BedQefBj.mjs +0 -1
  54. package/dist/packem_shared/emitServer-DlOheWku.mjs +0 -1
  55. package/dist/packem_shared/emitShard-DguoZWGv.mjs +0 -1
  56. package/dist/packem_shared/ir-DBSvhNa-.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-DwmUKYuc.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-CwwSEW6a.mjs";import{isTestPath as R,listLunoraSourceFiles as T}from"./packem_shared/isTestPath-B81lOULB.mjs";import{default as I}from"./packem_shared/discoverAuthApiCalls-DAaK0HUK.mjs";import{CONTAINERS_FILENAME as L,discoverContainers as M}from"./packem_shared/CONTAINERS_FILENAME-BtX5vWh8.mjs";import{default as P}from"./packem_shared/discoverCrons-DF7dOP9x.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-DsQwrwWq.mjs";import{default as V}from"./packem_shared/discoverHttpRoutes-Cv-h-Yuc.mjs";import{default as Q}from"./packem_shared/discoverHyperdriveCalls-xy2G6igG.mjs";import{default as w}from"./packem_shared/discoverInserts-CQsoloGk.mjs";import{d as Y}from"./packem_shared/index-BoPXSW7g.mjs";import{default as Z}from"./packem_shared/discoverMigrations-uxm9qHrr.mjs";import{MUTATORS_FILENAME as ee,discoverMutators as re}from"./packem_shared/MUTATORS_FILENAME-Dl1tElqi.mjs";import{default as te}from"./packem_shared/discoverNondeterministicCalls-Dm7_PJoA.mjs";import{NOTIFY_FILENAME as ae,discoverNotifyCalls as ie,discoverNotifyChannels as me,discoverNotifyConfig as fe}from"./packem_shared/NOTIFY_FILENAME-BeTurUSC.mjs";import{default as pe}from"./packem_shared/readPackageDependencies-RHhGiz0k.mjs";import{default as le}from"./packem_shared/discoverQueries-BqECbkm9.mjs";import{QUEUES_FILENAME as xe,discoverQueues as Se}from"./packem_shared/QUEUES_FILENAME-D588u733.mjs";import{default as ue}from"./packem_shared/discoverR2sqlCalls-I9IqJFcy.mjs";import{default as ve}from"./packem_shared/discoverRlsProcedures-Bkohn4ZR.mjs";import{default as Ne}from"./packem_shared/discoverRlsMetadata-Cu4bc5KZ.mjs";import{discoverSandboxUsage as Oe}from"./packem_shared/discoverSandboxUsage-w6Q3RvxZ.mjs";import{default as Te}from"./packem_shared/discoverSchema-BCxeD80d.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-D-Q8lSEw.mjs";import{default as De}from"./packem_shared/discoverStorageRulesMetadata-D6rjgKYC.mjs";import{WORKFLOWS_FILENAME as ye,discoverWorkflows as Ue}from"./packem_shared/WORKFLOWS_FILENAME-BGMSNTDC.mjs";import{emitApp as He}from"./packem_shared/emitApp-D7G7gmV7.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-3U7x981M.mjs";import{l as tr,r as sr}from"./packem_shared/project-config-file-BV7RR-l6.mjs";import{SCHEMA_SNAPSHOT_FILENAME as ir,createCodegenProject as mr,findTsconfig as fr,refreshCodegenProject as dr,runCodegen as pr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-3FEkspbx.mjs";import{SchemaSnapshotParseError as lr,buildSchemaSnapshot as cr,evaluateSchemaDrift as xr,parseSchemaSnapshot as Sr}from"./packem_shared/SchemaSnapshotParseError-CPOXlFhI.mjs";import{default as ur}from"./packem_shared/fingerprintSchemaSources-eVG9aVt0.mjs";import{schemaFromIr as vr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as Nr,validatorIrToJsonSchema as gr}from"./packem_shared/LUNORA_ERROR_CODES-C2s0xWQD.mjs";import{SDK_LANGUAGES as Rr,SDK_TARGETS as Tr,generateSdk as hr}from"./packem_shared/SDK_LANGUAGES-Df_CnJx5.mjs";import{redact as _r,secretKindOf as Lr}from"./packem_shared/redact-Cy14LEnc.mjs";import{default as Fr}from"./packem_shared/emitDrizzleSchema-CpOGYfyl.mjs";import{default as Dr}from"./packem_shared/emitFunctions-BeKgL3dl.mjs";import{e as yr}from"./packem_shared/server-DSUfd6Tc.mjs";import{e as Gr}from"./packem_shared/shard-BNhX5R-a.mjs";import{G as jr}from"./packem_shared/shared-DnCokNcE.mjs";import{MESSAGE_SOLUTIONS as kr,findSolutionByMessage as Wr}from"@lunora/errors";import{PROJECT_CONFIG_FILENAMES as Vr,findProjectConfigFile as zr}from"./packem_shared/PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";import{s as qr,t as wr,u as Jr}from"./packem_shared/shard-runtime-CkaEBSdL.mjs";import{emitApi as Xr,emitCollections as Zr,emitInternalApi as $r}from"./packem_shared/emitApi-Zx6VPN-7.mjs";import{emitCrons as ro,emitScheduler as oo,emitVectors as to,emitWranglerCronTriggers as so}from"./packem_shared/emitCrons-Gd8jD8jF.mjs";import{emitDataModel as io}from"./packem_shared/emitDataModel-DdtjdNg3.mjs";import{isTypedSchema as fo}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,jr as GENERATED_HEADER,Nr as LUNORA_ERROR_CODES,kr as LUNORA_SOLUTION_RULES,ee as MUTATORS_FILENAME,ae as NOTIFY_FILENAME,qe as OPENRPC_VERSION,Vr as PROJECT_CONFIG_FILENAMES,xe as QUEUES_FILENAME,ir as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,Rr as SDK_LANGUAGES,Tr as SDK_TARGETS,Me as SHAPES_FILENAME,lr as SchemaSnapshotParseError,e as VERSION,ye as WORKFLOWS_FILENAME,Ke as buildOpenApiDocument,we as buildOpenRpcDocument,cr as buildSchemaSnapshot,b as capabilitiesUsedBy,mr 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,qr as emitAgents,Xr as emitApi,He as emitApp,Zr as emitCollections,wr as emitContainers,ro as emitCrons,io as emitDataModel,Fr as emitDrizzleSchema,Dr as emitFunctions,$r as emitInternalApi,Ve as emitOpenApi,ze as emitOpenApiModule,Je as emitOpenRpc,Ye as emitOpenRpcModule,oo as emitScheduler,yr as emitServer,Gr as emitShard,to as emitVectors,Jr as emitWorkflows,so as emitWranglerCronTriggers,l as errorAdvisoryNames,c as errorPlatformDiagnosticNames,xr as evaluateSchemaDrift,Wr as findLunoraSolution,zr as findProjectConfigFile,fr as findTsconfig,ur as fingerprintSchemaSources,y as foldCapabilitySignals,m as formatAdvisories,hr as generateSdk,Be as isD1GlobalTable,ke as isHyperdriveGlobalTable,R as isTestPath,fo as isTypedSchema,f as lintSchema,T as listLunoraSourceFiles,tr as loadProjectConfig,U as mayReadCapabilityContext,Sr as parseSchemaSnapshot,$e as platformMatrixIds,pe as readPackageDependencies,sr as readProjectConfigLiterals,er as readProjectTarget,Ie as readServiceBindings,_r as redact,dr as refreshCodegenProject,rr as resolveCodegenTarget,_e as resolveServiceBindings,pr as runCodegen,vr as schemaFromIr,Lr as secretKindOf,a as serializeSchemaSnapshot,x as sortedUniqueNames,G as sourceCapabilitySignals,d as toAdvisorContext,gr 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-DwmUKYuc.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-Bk0u9QUu.mjs";import{default as P}from"./packem_shared/discoverCrons-DF7dOP9x.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-DaEZl3uE.mjs";import{default as V}from"./packem_shared/discoverHttpRoutes-C_u9YiFb.mjs";import{default as Q}from"./packem_shared/discoverHyperdriveCalls-BUrA_96X.mjs";import{default as w}from"./packem_shared/discoverInserts-OT_fiEGq.mjs";import{d as Y}from"./packem_shared/index-BW4hJ4Wm.mjs";import{default as Z}from"./packem_shared/discoverMigrations-C9mLIhGZ.mjs";import{MUTATORS_FILENAME as ee,discoverMutators as re}from"./packem_shared/MUTATORS_FILENAME-Bw0YtaO8.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-CPjbiHQl.mjs";import{default as pe}from"./packem_shared/readPackageDependencies-RHhGiz0k.mjs";import{default as le}from"./packem_shared/discoverQueries-C8V4cMIP.mjs";import{QUEUES_FILENAME as xe,discoverQueues as Se}from"./packem_shared/QUEUES_FILENAME-CsRy4VTF.mjs";import{default as ue}from"./packem_shared/discoverR2sqlCalls-COKmDnih.mjs";import{default as ve}from"./packem_shared/discoverRlsProcedures-BMqosvx6.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-BCxeD80d.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-CQR8fE9B.mjs";import{emitApp as He}from"./packem_shared/emitApp-DAZCUDbr.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-3U7x981M.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-DndbpsGL.mjs";import{SchemaSnapshotParseError as dr,buildSchemaSnapshot as pr,evaluateSchemaDrift as nr,parseSchemaSnapshot as lr}from"./packem_shared/SchemaSnapshotParseError-CPOXlFhI.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"./packem_shared/SDK_LANGUAGES-Df_CnJx5.mjs";import{redact as Tr,secretKindOf as hr}from"./packem_shared/redact-Cy14LEnc.mjs";import{default as _r}from"./packem_shared/emitDrizzleSchema-CpOGYfyl.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-DfBMIpi9.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-BX0xmo0P.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-DdtjdNg3.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 p}from"node:fs";import{join as f}from"node:path";import{agentDefaultName as d,agentClassName as b,voiceBindingName as N,voiceClassName as y}from"@lunora/agent/naming";import{LunoraError as g}from"@lunora/errors";import{Node as a,SyntaxKind as u}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapToCallExpression as A,findObjectProperty as c,stringPropertyFor as w}from"./isTestPath-B81lOULB.mjs";import{a as h}from"./attribution-BUciBs1M.mjs";const E="agents.ts",v=o=>{const n=o.getSymbol();if(!n)return o.getText()==="defineAgent";for(const e of n.getDeclarations())if(a.isImportSpecifier(e))return e.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/agent"?!1:e.getNameNode().getText()==="defineAgent";return!1},P=w("agent"),x=(o,n,e)=>{if(o.getKind()===u.TrueKeyword)return!0;if(o.getKind()===u.FalseKeyword)return!1;throw l(o,`agent "${n}": \`${e}\` must be a static boolean literal — it is deploy configuration codegen writes into the ctx.agents wiring spec`)},I=(o,n)=>{const e=o.getArguments()[0];if(!e||!a.isObjectLiteralExpression(e))throw l(o,`agent "${n}": defineAgent must be passed an inline object literal`);const t={className:b(n),exportName:n,name:d(n)},i=c(e,"name");i&&a.isPropertyAssignment(i)&&(t.name=P(i.getInitializerOrThrow(),n,"name"));const r=c(e,"publicRun");r&&a.isPropertyAssignment(r)&&x(r.getInitializerOrThrow(),n,"publicRun")&&(t.publicRun=!0);const s=c(e,"voice");if(s&&a.isPropertyAssignment(s)){const m=s.getInitializerOrThrow();if(!a.isObjectLiteralExpression(m))throw l(m,`agent "${n}": \`voice\` must be an inline object literal — its presence tells codegen to emit the voice-session Durable Object`);t.voice=!0,t.voiceBindingName=N(n),t.voiceClassName=y(n)}return c(e,"onEmail")&&(t.onEmail=!0),t},S=o=>{const n=[];for(const e of o.getVariableDeclarations()){const t=A(e.getInitializer());if(!t)continue;const i=t.getExpression();if(!a.isIdentifier(i)||!v(i))continue;const r=e.getNameNode();if(!a.isIdentifier(r)){if(e.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw l(r,"defineAgent exports must be plain named exports (no destructuring)")}const s=h(e,"binding");s!==void 0&&n.push(I(t,s))}return n},T=o=>{const n=new Map,e=new Map;for(const t of o){const i=n.get(t.name);if(i!==void 0)throw new g("DUPLICATE_AGENT_NAME",`Duplicate agent name "${t.name}": produced by both "${i}" and "${t.exportName}". Deployed agent names must be unique across the project.`,{status:500});n.set(t.name,t.exportName);const r=e.get(t.className);if(r!==void 0)throw new g("DUPLICATE_AGENT_CLASS",`Duplicate agent class "${t.className}": produced by both "${r}" and "${t.exportName}". Agent export names must yield unique generated class names.`,{status:500});e.set(t.className,t.exportName)}},z=(o,n)=>{const e=f(n,E);if(!p(e))return[];const t=o.getSourceFile(e)??o.addSourceFileAtPath(e),i=S(t);return i.sort((r,s)=>r.exportName.localeCompare(s.exportName)),T(i),i};export{E as AGENTS_FILENAME,z as discoverAgents};
1
+ import{existsSync as p}from"node:fs";import{join as f}from"node:path";import{agentDefaultName as d,agentClassName as b,voiceBindingName as N,voiceClassName as y}from"@lunora/agent/naming";import{LunoraError as g}from"@lunora/errors";import{Node as a,SyntaxKind as u}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapToCallExpression as A,findObjectProperty as c,stringPropertyFor as w}from"./isTestPath-B81lOULB.mjs";import{a as h}from"./attribution-hVBriwzy.mjs";const E="agents.ts",v=o=>{const n=o.getSymbol();if(!n)return o.getText()==="defineAgent";for(const e of n.getDeclarations())if(a.isImportSpecifier(e))return e.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/agent"?!1:e.getNameNode().getText()==="defineAgent";return!1},P=w("agent"),x=(o,n,e)=>{if(o.getKind()===u.TrueKeyword)return!0;if(o.getKind()===u.FalseKeyword)return!1;throw l(o,`agent "${n}": \`${e}\` must be a static boolean literal — it is deploy configuration codegen writes into the ctx.agents wiring spec`)},I=(o,n)=>{const e=o.getArguments()[0];if(!e||!a.isObjectLiteralExpression(e))throw l(o,`agent "${n}": defineAgent must be passed an inline object literal`);const t={className:b(n),exportName:n,name:d(n)},i=c(e,"name");i&&a.isPropertyAssignment(i)&&(t.name=P(i.getInitializerOrThrow(),n,"name"));const r=c(e,"publicRun");r&&a.isPropertyAssignment(r)&&x(r.getInitializerOrThrow(),n,"publicRun")&&(t.publicRun=!0);const s=c(e,"voice");if(s&&a.isPropertyAssignment(s)){const m=s.getInitializerOrThrow();if(!a.isObjectLiteralExpression(m))throw l(m,`agent "${n}": \`voice\` must be an inline object literal — its presence tells codegen to emit the voice-session Durable Object`);t.voice=!0,t.voiceBindingName=N(n),t.voiceClassName=y(n)}return c(e,"onEmail")&&(t.onEmail=!0),t},S=o=>{const n=[];for(const e of o.getVariableDeclarations()){const t=A(e.getInitializer());if(!t)continue;const i=t.getExpression();if(!a.isIdentifier(i)||!v(i))continue;const r=e.getNameNode();if(!a.isIdentifier(r)){if(e.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw l(r,"defineAgent exports must be plain named exports (no destructuring)")}const s=h(e,"binding");s!==void 0&&n.push(I(t,s))}return n},T=o=>{const n=new Map,e=new Map;for(const t of o){const i=n.get(t.name);if(i!==void 0)throw new g("DUPLICATE_AGENT_NAME",`Duplicate agent name "${t.name}": produced by both "${i}" and "${t.exportName}". Deployed agent names must be unique across the project.`,{status:500});n.set(t.name,t.exportName);const r=e.get(t.className);if(r!==void 0)throw new g("DUPLICATE_AGENT_CLASS",`Duplicate agent class "${t.className}": produced by both "${r}" and "${t.exportName}". Agent export names must yield unique generated class names.`,{status:500});e.set(t.className,t.exportName)}},z=(o,n)=>{const e=f(n,E);if(!p(e))return[];const t=o.getSourceFile(e)??o.addSourceFileAtPath(e),i=S(t);return i.sort((r,s)=>r.exportName.localeCompare(s.exportName)),T(i),i};export{E as AGENTS_FILENAME,z as discoverAgents};
@@ -1 +1 @@
1
- import{existsSync as T}from"node:fs";import{join as j}from"node:path";import{containerClassName as I,containerBindingName as A,DURABLE_OBJECT_POLICY_FORBIDDEN_KEYS as O,isManagedImage as k,isCloudflareRegistryDigest as C,normalizeContainerImage as f}from"@lunora/container";import{SyntaxKind as S,Node as s}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{stringPropertyFor as _,findObjectProperty as p,symbolConstInitializer as D,outermostValueWrapper as w,isWriteTarget as M}from"./isTestPath-B81lOULB.mjs";import{a as F}from"./attribution-BUciBs1M.mjs";import{a as b}from"./project-config-file-BV7RR-l6.mjs";const V="containers.ts",K=t=>{const e=t.getSymbol();if(!e)return t.getText()==="defineContainer";for(const n of e.getDeclarations())if(s.isImportSpecifier(n))return n.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/container"?!1:n.getNameNode().getText()==="defineContainer";return!1},d=_("container"),y=(t,e,n)=>{if(s.isNumericLiteral(t))return t.getLiteralValue();throw a(t,`container "${e}": \`${n}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},$=(t,e)=>{if(s.isStringLiteral(t)||s.isNoSubstitutionTemplateLiteral(t))return f(t.getLiteralValue());if(s.isObjectLiteralExpression(t)){const n=p(t,"registry");if(n&&s.isPropertyAssignment(n)){const r=n.getInitializerOrThrow();return f({registry:d(r,e,"image.registry")})}const i=p(t,"build");if(i&&s.isPropertyAssignment(i)){const r=i.getInitializerOrThrow();return f({build:d(r,e,"image.build")})}}throw a(t,`container "${e}": \`image\` must be a static string path, { registry: "…" }, or { build: "…" } literal`)},B=new Set(["buildArgs","image","images","instanceType","maxInstances","name","rollout","sandbox","schedulingPolicy"]),R=new Set(["gracePeriodSeconds","stepPercentage"]),E=t=>{let e=t;for(;s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isTypeAssertion(e)||s.isParenthesizedExpression(e);)e=e.getExpression();return e},U=(t,e)=>e.getDescendantsOfKind(S.Identifier).some(n=>{if(n.getSymbol()!==t)return!1;let i=w(n),r=i.getParent();if(s.isCallExpression(r)&&r.getExpression().getText()==="Object.assign")return r.getArguments()[0]===i;for(;(s.isPropertyAccessExpression(r)||s.isElementAccessExpression(r))&&r.getExpression()===i;){if(M(r))return!0;i=w(r),r=i.getParent()}return!1}),z=16,L=(t,e,n,i)=>{let r={name:n,symbol:t},o;for(let c=0;c<z;c+=1){const l=D(r.symbol);if(l===void 0||!s.isExpression(l))return o;if(o=E(l),s.isObjectLiteralExpression(o)&&r.symbol!==void 0&&U(r.symbol,e.getSourceFile()))throw a(e,`${i}: \`${r.name}\` is a const object that is written to elsewhere in this file, so its initializer is not the value the container runs with. Declare the settings where they are final.`);if(!s.isIdentifier(o))return o;r={name:o.getText(),symbol:o.getSymbol()}}return o},P=(t,e)=>{const n=E(t);return s.isIdentifier(n)?L(n.getSymbol(),n,n.getText(),e)??n:n},N=t=>{const e=t.getNonNullableType();return(e.isUnion()?e.getUnionTypes():[e]).flatMap(i=>i.getApparentType().getProperties().map(r=>r.getName()))},Y=(t,e,n)=>{const i=t.getExpression().getType(),r=e==="every"||i.isAny()||i.isUnknown()?["its keys"]:[...new Set(N(i))].filter(o=>e.has(o)).map(o=>`\`${o}\``);if(r.length>0)throw a(t,`${n}: this spread can set ${r.join(", ")}, which codegen writes into wrangler.jsonc and so must read statically. Spread a module-scope \`const\` object literal, or write the keys inline.`)},W=(t,e,n)=>{const i=b(t),r=s.isShorthandPropertyAssignment(t)?L(t.getValueSymbol(),t,i,n):void 0;if(r!==void 0)return[i,r];if(e==="every"||e.has(i))throw a(t,`${n}: \`${i}\` is deploy configuration codegen writes into wrangler.jsonc, so it must be a static literal — inline it, or name a module-scope \`const\` initialized with one.`)},m=(t,e,n,i=new Set)=>{const r=[],o=new Set(i).add(t);for(const c of t.getProperties())if(s.isPropertyAssignment(c))r.push([b(c),P(c.getInitializerOrThrow(),n)]);else if(s.isSpreadAssignment(c))r.push(...q(c,e,n,o));else{const l=W(c,e,n);l!==void 0&&r.push(l)}return r},q=(t,e,n,i)=>{const r=P(t.getExpression(),n);if(!s.isObjectLiteralExpression(r))return Y(t,e,n),[];if(i.has(r))throw a(t,`${n}: this spread refers back to an object it is part of, so it has no static value.`);return m(r,e,n,i)},x=(t,e)=>{if(!s.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`buildArgs\` must be a static object literal — it is deploy configuration codegen writes into wrangler.jsonc`);const n={};for(const[i,r]of m(t,"every",`container "${e}" buildArgs`))n[i]=d(r,e,`buildArgs.${i}`);return Object.keys(n).length>0?n:void 0},H=(t,e)=>{if(!s.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`rollout\` must be a static object literal — it is deploy configuration codegen writes into wrangler.jsonc`);const n={};for(const[i,r]of m(t,R,`container "${e}" rollout`))(i==="gracePeriodSeconds"||i==="stepPercentage")&&(n[i]=y(r,e,`rollout.${i}`));return n.gracePeriodSeconds===void 0&&n.stepPercentage===void 0?void 0:n},v=t=>{if(s.isTrueLiteral(t))return!0;if(s.isFalseLiteral(t))return!1},J=t=>{if(s.isStringLiteral(t)||s.isNoSubstitutionTemplateLiteral(t)||s.isNumericLiteral(t))return t.getLiteralValue()},X=(t,e)=>{if(s.isStringLiteral(t))return t.getLiteralValue();if(s.isObjectLiteralExpression(t)){const n={};for(const i of t.getProperties()){if(!s.isPropertyAssignment(i))throw a(i,`container "${e}": \`instanceType\` must be an object of static number literals`);const r=b(i);if(r!=="diskMb"&&r!=="memoryMib"&&r!=="vcpu")throw a(i,`container "${e}": unknown \`instanceType\` field "${r}" — expected vcpu, memoryMib, or diskMb`);n[r]=y(i.getInitializerOrThrow(),e,`instanceType.${r}`)}return n}throw a(t,`container "${e}": \`instanceType\` must be a static string or { vcpu, memoryMib, diskMb } literal`)},G=(t,e)=>{if(!s.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`images\` must be a static object literal — codegen writes it into wrangler.jsonc`);const n={};for(const[i,r]of m(t,"every",`container "${e}" images`)){const o=$(r,e);if(o.kind==="build")throw a(r,`container "${e}": \`images["${i}"]\` cannot be a Railpack { build } source — use a Dockerfile path or a { registry } reference`);if(o.kind==="registry"&&!C(o.reference))throw a(r,`container "${e}": \`images["${i}"].registry\` must be a digest-pinned (@sha256) reference under registry.cloudflare.com — push other registries' images there first`);n[i]=o}return n},Q=(t,e)=>{const n=t.findLast(([r])=>r==="schedulingPolicy");if(n===void 0)return;const i=d(n[1],e,"schedulingPolicy");if(i!=="default"&&i!=="durable_object")throw a(n[1],`container "${e}": unknown \`schedulingPolicy\` "${i}" — use "default" or "durable_object"`);return i==="durable_object"?i:void 0},Z=(t,e,n,i)=>{if(n!==void 0&&O.includes(t))throw a(e,`container "${i}": \`${t}\` is not supported with schedulingPolicy "durable_object"`);if(n===void 0&&t==="images")throw a(e,`container "${i}": \`images\` needs schedulingPolicy "durable_object"`)},ee=(t,e,n,i)=>{const{base:r,policy:o}=n;switch(t){case"buildArgs":{r.buildArgs=x(e,i);break}case"enableInternet":{r.enableInternet=v(e);break}case"image":{n.scheduled||(o.image=$(e,i));break}case"images":{o.images=G(e,i);break}case"instanceType":{r.instanceType=X(e,i);break}case"maxInstances":{o.maxInstances=y(e,i,"maxInstances");break}case"name":{r.name=d(e,i,"name");break}case"rollout":{o.rollout=H(e,i);break}case"sandbox":{const c=v(e);if(c===void 0)throw a(e,`container "${i}": \`sandbox\` must be a static true/false literal`);r.sandbox=c;break}case"sleepAfter":{r.sleepAfter=J(e);break}}},te=(t,e,n)=>{const i=t.findLast(([o])=>o==="image")?.[1];if(i===void 0||!(s.isStringLiteral(i)||s.isNoSubstitutionTemplateLiteral(i)))return;const r=i.getLiteralValue();if(!Object.hasOwn(e??{},r)&&!k(r))throw a(i,`container "${n}": \`image\` "${r}" must name an entry of \`images\` or a Cloudflare-managed "cloudflare/…" image`)},ie=(t,e)=>{const n=t.getArguments()[0];if(!n||!s.isObjectLiteralExpression(n))throw a(t,`container "${e}": defineContainer must be passed an inline object literal`);const i=m(n,B,`container "${e}"`),r=Q(i,e),o={base:{bindingName:A(e),className:I(e),exportName:e},policy:{},scheduled:r!==void 0};for(const[g,u]of i)Z(g,u,r,e),ee(g,u,o,e);const{base:c,policy:l}=o;if(r==="durable_object")return te(i,l.images,e),{...c,...l.images===void 0?{}:{images:l.images},schedulingPolicy:r};if(l.image===void 0)throw a(n,`container "${e}": defineContainer requires a static \`image\` property`);return{...c,image:l.image,...l.maxInstances===void 0?{}:{maxInstances:l.maxInstances},...l.rollout===void 0?{}:{rollout:l.rollout}}},ne=t=>{const e=[],n=new Map;for(const i of t.getVariableDeclarations()){const r=i.getInitializer();if(r?.getKind()!==S.CallExpression)continue;const o=r,c=o.getExpression();if(!s.isIdentifier(c)||!K(c))continue;const l=i.getNameNode();if(!s.isIdentifier(l)){if(i.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw a(l,"defineContainer exports must be plain named exports (no destructuring)")}const g=F(i,"binding");if(g===void 0)continue;const u=ie(o,g),h=n.get(u.bindingName);if(h!==void 0)throw a(l,`containers "${h}" and "${u.exportName}" both map to the binding ${u.bindingName} — rename one so each container gets its own Durable Object binding`);n.set(u.bindingName,u.exportName),e.push(u)}return e},de=(t,e)=>{const n=j(e,V);if(!T(n))return[];const i=t.getSourceFile(n)??t.addSourceFileAtPath(n),r=ne(i);return r.sort((o,c)=>o.exportName.localeCompare(c.exportName)),r};export{V as CONTAINERS_FILENAME,de as discoverContainers};
1
+ import{existsSync as T}from"node:fs";import{join as j}from"node:path";import{containerClassName as I,containerBindingName as A,DURABLE_OBJECT_POLICY_FORBIDDEN_KEYS as O,isManagedImage as k,isCloudflareRegistryDigest as C,normalizeContainerImage as f}from"@lunora/container";import{SyntaxKind as S,Node as s}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{stringPropertyFor as _,findObjectProperty as p,symbolConstInitializer as D,outermostValueWrapper as w,isWriteTarget as M}from"./isTestPath-B81lOULB.mjs";import{a as F}from"./attribution-hVBriwzy.mjs";import{a as b}from"./project-config-file-BV7RR-l6.mjs";const V="containers.ts",K=t=>{const e=t.getSymbol();if(!e)return t.getText()==="defineContainer";for(const n of e.getDeclarations())if(s.isImportSpecifier(n))return n.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/container"?!1:n.getNameNode().getText()==="defineContainer";return!1},d=_("container"),y=(t,e,n)=>{if(s.isNumericLiteral(t))return t.getLiteralValue();throw a(t,`container "${e}": \`${n}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},$=(t,e)=>{if(s.isStringLiteral(t)||s.isNoSubstitutionTemplateLiteral(t))return f(t.getLiteralValue());if(s.isObjectLiteralExpression(t)){const n=p(t,"registry");if(n&&s.isPropertyAssignment(n)){const r=n.getInitializerOrThrow();return f({registry:d(r,e,"image.registry")})}const i=p(t,"build");if(i&&s.isPropertyAssignment(i)){const r=i.getInitializerOrThrow();return f({build:d(r,e,"image.build")})}}throw a(t,`container "${e}": \`image\` must be a static string path, { registry: "…" }, or { build: "…" } literal`)},B=new Set(["buildArgs","image","images","instanceType","maxInstances","name","rollout","sandbox","schedulingPolicy"]),R=new Set(["gracePeriodSeconds","stepPercentage"]),E=t=>{let e=t;for(;s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isTypeAssertion(e)||s.isParenthesizedExpression(e);)e=e.getExpression();return e},U=(t,e)=>e.getDescendantsOfKind(S.Identifier).some(n=>{if(n.getSymbol()!==t)return!1;let i=w(n),r=i.getParent();if(s.isCallExpression(r)&&r.getExpression().getText()==="Object.assign")return r.getArguments()[0]===i;for(;(s.isPropertyAccessExpression(r)||s.isElementAccessExpression(r))&&r.getExpression()===i;){if(M(r))return!0;i=w(r),r=i.getParent()}return!1}),z=16,L=(t,e,n,i)=>{let r={name:n,symbol:t},o;for(let c=0;c<z;c+=1){const l=D(r.symbol);if(l===void 0||!s.isExpression(l))return o;if(o=E(l),s.isObjectLiteralExpression(o)&&r.symbol!==void 0&&U(r.symbol,e.getSourceFile()))throw a(e,`${i}: \`${r.name}\` is a const object that is written to elsewhere in this file, so its initializer is not the value the container runs with. Declare the settings where they are final.`);if(!s.isIdentifier(o))return o;r={name:o.getText(),symbol:o.getSymbol()}}return o},P=(t,e)=>{const n=E(t);return s.isIdentifier(n)?L(n.getSymbol(),n,n.getText(),e)??n:n},N=t=>{const e=t.getNonNullableType();return(e.isUnion()?e.getUnionTypes():[e]).flatMap(i=>i.getApparentType().getProperties().map(r=>r.getName()))},Y=(t,e,n)=>{const i=t.getExpression().getType(),r=e==="every"||i.isAny()||i.isUnknown()?["its keys"]:[...new Set(N(i))].filter(o=>e.has(o)).map(o=>`\`${o}\``);if(r.length>0)throw a(t,`${n}: this spread can set ${r.join(", ")}, which codegen writes into wrangler.jsonc and so must read statically. Spread a module-scope \`const\` object literal, or write the keys inline.`)},W=(t,e,n)=>{const i=b(t),r=s.isShorthandPropertyAssignment(t)?L(t.getValueSymbol(),t,i,n):void 0;if(r!==void 0)return[i,r];if(e==="every"||e.has(i))throw a(t,`${n}: \`${i}\` is deploy configuration codegen writes into wrangler.jsonc, so it must be a static literal — inline it, or name a module-scope \`const\` initialized with one.`)},m=(t,e,n,i=new Set)=>{const r=[],o=new Set(i).add(t);for(const c of t.getProperties())if(s.isPropertyAssignment(c))r.push([b(c),P(c.getInitializerOrThrow(),n)]);else if(s.isSpreadAssignment(c))r.push(...q(c,e,n,o));else{const l=W(c,e,n);l!==void 0&&r.push(l)}return r},q=(t,e,n,i)=>{const r=P(t.getExpression(),n);if(!s.isObjectLiteralExpression(r))return Y(t,e,n),[];if(i.has(r))throw a(t,`${n}: this spread refers back to an object it is part of, so it has no static value.`);return m(r,e,n,i)},x=(t,e)=>{if(!s.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`buildArgs\` must be a static object literal — it is deploy configuration codegen writes into wrangler.jsonc`);const n={};for(const[i,r]of m(t,"every",`container "${e}" buildArgs`))n[i]=d(r,e,`buildArgs.${i}`);return Object.keys(n).length>0?n:void 0},H=(t,e)=>{if(!s.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`rollout\` must be a static object literal — it is deploy configuration codegen writes into wrangler.jsonc`);const n={};for(const[i,r]of m(t,R,`container "${e}" rollout`))(i==="gracePeriodSeconds"||i==="stepPercentage")&&(n[i]=y(r,e,`rollout.${i}`));return n.gracePeriodSeconds===void 0&&n.stepPercentage===void 0?void 0:n},v=t=>{if(s.isTrueLiteral(t))return!0;if(s.isFalseLiteral(t))return!1},J=t=>{if(s.isStringLiteral(t)||s.isNoSubstitutionTemplateLiteral(t)||s.isNumericLiteral(t))return t.getLiteralValue()},X=(t,e)=>{if(s.isStringLiteral(t))return t.getLiteralValue();if(s.isObjectLiteralExpression(t)){const n={};for(const i of t.getProperties()){if(!s.isPropertyAssignment(i))throw a(i,`container "${e}": \`instanceType\` must be an object of static number literals`);const r=b(i);if(r!=="diskMb"&&r!=="memoryMib"&&r!=="vcpu")throw a(i,`container "${e}": unknown \`instanceType\` field "${r}" — expected vcpu, memoryMib, or diskMb`);n[r]=y(i.getInitializerOrThrow(),e,`instanceType.${r}`)}return n}throw a(t,`container "${e}": \`instanceType\` must be a static string or { vcpu, memoryMib, diskMb } literal`)},G=(t,e)=>{if(!s.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`images\` must be a static object literal — codegen writes it into wrangler.jsonc`);const n={};for(const[i,r]of m(t,"every",`container "${e}" images`)){const o=$(r,e);if(o.kind==="build")throw a(r,`container "${e}": \`images["${i}"]\` cannot be a Railpack { build } source — use a Dockerfile path or a { registry } reference`);if(o.kind==="registry"&&!C(o.reference))throw a(r,`container "${e}": \`images["${i}"].registry\` must be a digest-pinned (@sha256) reference under registry.cloudflare.com — push other registries' images there first`);n[i]=o}return n},Q=(t,e)=>{const n=t.findLast(([r])=>r==="schedulingPolicy");if(n===void 0)return;const i=d(n[1],e,"schedulingPolicy");if(i!=="default"&&i!=="durable_object")throw a(n[1],`container "${e}": unknown \`schedulingPolicy\` "${i}" — use "default" or "durable_object"`);return i==="durable_object"?i:void 0},Z=(t,e,n,i)=>{if(n!==void 0&&O.includes(t))throw a(e,`container "${i}": \`${t}\` is not supported with schedulingPolicy "durable_object"`);if(n===void 0&&t==="images")throw a(e,`container "${i}": \`images\` needs schedulingPolicy "durable_object"`)},ee=(t,e,n,i)=>{const{base:r,policy:o}=n;switch(t){case"buildArgs":{r.buildArgs=x(e,i);break}case"enableInternet":{r.enableInternet=v(e);break}case"image":{n.scheduled||(o.image=$(e,i));break}case"images":{o.images=G(e,i);break}case"instanceType":{r.instanceType=X(e,i);break}case"maxInstances":{o.maxInstances=y(e,i,"maxInstances");break}case"name":{r.name=d(e,i,"name");break}case"rollout":{o.rollout=H(e,i);break}case"sandbox":{const c=v(e);if(c===void 0)throw a(e,`container "${i}": \`sandbox\` must be a static true/false literal`);r.sandbox=c;break}case"sleepAfter":{r.sleepAfter=J(e);break}}},te=(t,e,n)=>{const i=t.findLast(([o])=>o==="image")?.[1];if(i===void 0||!(s.isStringLiteral(i)||s.isNoSubstitutionTemplateLiteral(i)))return;const r=i.getLiteralValue();if(!Object.hasOwn(e??{},r)&&!k(r))throw a(i,`container "${n}": \`image\` "${r}" must name an entry of \`images\` or a Cloudflare-managed "cloudflare/…" image`)},ie=(t,e)=>{const n=t.getArguments()[0];if(!n||!s.isObjectLiteralExpression(n))throw a(t,`container "${e}": defineContainer must be passed an inline object literal`);const i=m(n,B,`container "${e}"`),r=Q(i,e),o={base:{bindingName:A(e),className:I(e),exportName:e},policy:{},scheduled:r!==void 0};for(const[g,u]of i)Z(g,u,r,e),ee(g,u,o,e);const{base:c,policy:l}=o;if(r==="durable_object")return te(i,l.images,e),{...c,...l.images===void 0?{}:{images:l.images},schedulingPolicy:r};if(l.image===void 0)throw a(n,`container "${e}": defineContainer requires a static \`image\` property`);return{...c,image:l.image,...l.maxInstances===void 0?{}:{maxInstances:l.maxInstances},...l.rollout===void 0?{}:{rollout:l.rollout}}},ne=t=>{const e=[],n=new Map;for(const i of t.getVariableDeclarations()){const r=i.getInitializer();if(r?.getKind()!==S.CallExpression)continue;const o=r,c=o.getExpression();if(!s.isIdentifier(c)||!K(c))continue;const l=i.getNameNode();if(!s.isIdentifier(l)){if(i.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw a(l,"defineContainer exports must be plain named exports (no destructuring)")}const g=F(i,"binding");if(g===void 0)continue;const u=ie(o,g),h=n.get(u.bindingName);if(h!==void 0)throw a(l,`containers "${h}" and "${u.exportName}" both map to the binding ${u.bindingName} — rename one so each container gets its own Durable Object binding`);n.set(u.bindingName,u.exportName),e.push(u)}return e},de=(t,e)=>{const n=j(e,V);if(!T(n))return[];const i=t.getSourceFile(n)??t.addSourceFileAtPath(n),r=ne(i);return r.sort((o,c)=>o.exportName.localeCompare(c.exportName)),r};export{V as CONTAINERS_FILENAME,de as discoverContainers};
@@ -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-BUciBs1M.mjs";import{u as w}from"./unwrap-handler-return-B-jQde6M.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-B-jQde6M.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-BUciBs1M.mjs";import{i as l}from"./context-root-Dlo21ybw.mjs";import{c as C}from"./classify-procedure-call-BJdf_-M6.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-wBahDTzk.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 +1 @@
1
- import{existsSync as x}from"node:fs";import{join as f}from"node:path";import{LunoraError as b}from"@lunora/errors";import{queueDefaultName as q,queueBindingName as y}from"@lunora/queue";import{SyntaxKind as S,Node as u}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{lunoraRelativePath as g,findObjectProperty as l,stringPropertyFor as w}from"./isTestPath-B81lOULB.mjs";import{a as v}from"./attribution-BUciBs1M.mjs";import{r as $}from"./handler-reference-DXkpwoAq.mjs";import{d as F}from"./modules-CjOcuQnK.mjs";const h="queues.ts",P=o=>{const e=t=>t==="defineQueue"||t==="defineSubscription"||t==="defineTopic",i=o.getSymbol();if(!i){const t=o.getText();return e(t)?t:void 0}for(const t of i.getDeclarations()){if(!u.isImportSpecifier(t))continue;if(t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/queue")return;const n=t.getNameNode().getText();return e(n)?n:void 0}},d=w("queue"),E=(o,e,i)=>{if(u.isNumericLiteral(o))return o.getLiteralValue();throw c(o,`queue "${e}": \`${i}\` must be a static numeric literal — it is deploy configuration codegen writes into wrangler.jsonc`)},I={maxBatchSize:{integer:!0,max:100,min:1},maxBatchTimeout:{integer:!1,max:60,min:0},maxConcurrency:{integer:!0,max:250,min:1},maxRetries:{integer:!0,max:100,min:0},retryDelay:{integer:!0,max:86400,min:0}},A=(o,e)=>{const i={};for(const[t,n]of Object.entries(I)){const r=l(o,t);if(r&&u.isPropertyAssignment(r)){const a=E(r.getInitializerOrThrow(),e,t);if(a<n.min||a>n.max||n.integer&&!Number.isInteger(a))throw c(r,`queue "${e}": \`${t}\` must be ${n.integer?"an integer":"a number"} from ${n.min.toString()} to ${n.max.toString()} (got ${a.toString()})`);i[t]=a}}return i},T=(o,e)=>{const i=l(o,"name");if(!i||!u.isPropertyAssignment(i))return;const t=d(i.getInitializerOrThrow(),e,"name");if(t.length===0)throw c(i,`queue "${e}": \`name\` must be a non-empty string when provided`);return t},N=(o,e,i,t)=>{const n=$(l(o,"handler"),t)?.site,r={bindingName:y(e),exportName:e,filePath:g(t,o.getSourceFile().getFilePath()),mode:"push",name:T(o,e)??q(e),...i===void 0?{}:{topic:i},...n===void 0?{}:{handlerSite:n},tuning:{}},a=l(o,"mode");if(a&&u.isPropertyAssignment(a)){if(i!==void 0)throw c(a,`subscription "${e}": \`mode\` is not allowed — a subscription is always a push consumer`);const m=d(a.getInitializerOrThrow(),e,"mode");if(m!=="push"&&m!=="pull")throw c(a,`queue "${e}": \`mode\` must be "push" or "pull" (got ${JSON.stringify(m)})`);r.mode=m}const s=l(o,"deadLetterQueue");return s&&u.isPropertyAssignment(s)&&(r.tuning.deadLetterQueue=d(s.getInitializerOrThrow(),e,"deadLetterQueue")),Object.assign(r.tuning,A(o,e)),r},O=(o,e,i)=>{const t=o.getArguments()[0];if(!t||!u.isObjectLiteralExpression(t))throw c(o,`queue "${e}": defineQueue must be passed an inline object literal`);return N(t,e,void 0,i)},p=(o,e)=>`${o}:${e}`,Q=o=>{const e=o.getSymbol(),i=(e?.isAlias()===!0?e.getAliasedSymbol():e)?.getDeclarations()[0];return i!==void 0&&u.isVariableDeclaration(i)?p(i.getSourceFile().getFilePath(),i.getName()):p(o.getSourceFile().getFilePath(),o.getText())},L=(o,e,i,t)=>{const[n,r]=o.getArguments(),a=n!==void 0&&u.isIdentifier(n)?i.get(Q(n)):void 0;if(a===void 0)throw c(n??o,`subscription "${e}": the first argument must name a \`defineTopic()\` export of lunora/queues.ts or a module's queues.ts`);if(!r||!u.isObjectLiteralExpression(r))throw c(o,`subscription "${e}": defineSubscription must be passed an inline object literal`);return N(r,e,a,t)},U=o=>{const e=[];for(const i of o.getVariableDeclarations()){const t=i.getInitializer();if(t?.getKind()!==S.CallExpression)continue;const n=t,r=n.getExpression(),a=u.isIdentifier(r)?P(r):void 0;if(a===void 0)continue;const s=i.getNameNode();if(!u.isIdentifier(s)){if(i.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw c(s,`${a} exports must be plain named exports (no destructuring)`)}const m=v(i,"binding");m!==void 0&&e.push({call:n,exportName:m,factory:a,localName:s.getText()})}return e},C=(o,e)=>{const i=new Map;for(const t of o){const n=g(e,t.call.getSourceFile().getFilePath()),r=i.get(t.exportName);if(r!==void 0)throw c(t.call,`"${t.exportName}" is exported by both lunora/${r}.ts and lunora/${n}.ts — queue and topic export names must be unique across the app`);i.set(t.exportName,n)}},M=(o,e)=>{const i=o.flatMap(s=>U(s));C(i,e);const t=i.filter(s=>s.factory==="defineTopic"),n=new Map(t.map(s=>[p(s.call.getSourceFile().getFilePath(),s.localName),s.exportName])),r=[];for(const s of i)s.factory==="defineQueue"?r.push(O(s.call,s.exportName,e)):s.factory==="defineSubscription"&&r.push(L(s.call,s.exportName,n,e));const a=t.map(s=>({exportName:s.exportName,filePath:g(e,s.call.getSourceFile().getFilePath())}));return{queues:r,topics:a}},j=(o,e)=>[f(e,h),...F(o,e).map(i=>f(e,i.name,h))].filter(i=>x(i)),z=o=>{const e=new Map,i=new Map;for(const t of o){const n=e.get(t.name);if(n!==void 0)throw new b("DUPLICATE_QUEUE_NAME",`Duplicate queue name "${t.name}": produced by both "${n}" and "${t.exportName}". Deployed queue names must be unique across the project.`,{status:500});e.set(t.name,t.exportName);const r=i.get(t.bindingName);if(r!==void 0)throw new b("DUPLICATE_QUEUE_BINDING",`Duplicate queue binding "${t.bindingName}": produced by both "${r}" and "${t.exportName}". Queue export names must yield unique binding names.`,{status:500});i.set(t.bindingName,t.exportName)}},D=(o,e)=>{const i=j(o,e).map(a=>o.getSourceFile(a)??o.addSourceFileAtPath(a)),{queues:t,topics:n}=M(i,e),r=t.toSorted((a,s)=>a.exportName.localeCompare(s.exportName));return z(r),{queues:r,topics:n.toSorted((a,s)=>a.exportName.localeCompare(s.exportName))}},X=(o,e)=>D(o,e).queues;export{h as QUEUES_FILENAME,D as discoverQueueDeclarations,X as discoverQueues};
1
+ import{existsSync as x}from"node:fs";import{join as f}from"node:path";import{LunoraError as b}from"@lunora/errors";import{queueDefaultName as q,queueBindingName as y}from"@lunora/queue";import{SyntaxKind as S,Node as u}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{lunoraRelativePath as g,findObjectProperty as l,stringPropertyFor as w}from"./isTestPath-B81lOULB.mjs";import{a as v}from"./attribution-hVBriwzy.mjs";import{r as $}from"./handler-reference-vIeqkhV_.mjs";import{d as F}from"./modules-CjOcuQnK.mjs";const h="queues.ts",P=o=>{const e=t=>t==="defineQueue"||t==="defineSubscription"||t==="defineTopic",i=o.getSymbol();if(!i){const t=o.getText();return e(t)?t:void 0}for(const t of i.getDeclarations()){if(!u.isImportSpecifier(t))continue;if(t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/queue")return;const n=t.getNameNode().getText();return e(n)?n:void 0}},d=w("queue"),E=(o,e,i)=>{if(u.isNumericLiteral(o))return o.getLiteralValue();throw c(o,`queue "${e}": \`${i}\` must be a static numeric literal — it is deploy configuration codegen writes into wrangler.jsonc`)},I={maxBatchSize:{integer:!0,max:100,min:1},maxBatchTimeout:{integer:!1,max:60,min:0},maxConcurrency:{integer:!0,max:250,min:1},maxRetries:{integer:!0,max:100,min:0},retryDelay:{integer:!0,max:86400,min:0}},A=(o,e)=>{const i={};for(const[t,n]of Object.entries(I)){const r=l(o,t);if(r&&u.isPropertyAssignment(r)){const a=E(r.getInitializerOrThrow(),e,t);if(a<n.min||a>n.max||n.integer&&!Number.isInteger(a))throw c(r,`queue "${e}": \`${t}\` must be ${n.integer?"an integer":"a number"} from ${n.min.toString()} to ${n.max.toString()} (got ${a.toString()})`);i[t]=a}}return i},T=(o,e)=>{const i=l(o,"name");if(!i||!u.isPropertyAssignment(i))return;const t=d(i.getInitializerOrThrow(),e,"name");if(t.length===0)throw c(i,`queue "${e}": \`name\` must be a non-empty string when provided`);return t},N=(o,e,i,t)=>{const n=$(l(o,"handler"),t)?.site,r={bindingName:y(e),exportName:e,filePath:g(t,o.getSourceFile().getFilePath()),mode:"push",name:T(o,e)??q(e),...i===void 0?{}:{topic:i},...n===void 0?{}:{handlerSite:n},tuning:{}},a=l(o,"mode");if(a&&u.isPropertyAssignment(a)){if(i!==void 0)throw c(a,`subscription "${e}": \`mode\` is not allowed — a subscription is always a push consumer`);const m=d(a.getInitializerOrThrow(),e,"mode");if(m!=="push"&&m!=="pull")throw c(a,`queue "${e}": \`mode\` must be "push" or "pull" (got ${JSON.stringify(m)})`);r.mode=m}const s=l(o,"deadLetterQueue");return s&&u.isPropertyAssignment(s)&&(r.tuning.deadLetterQueue=d(s.getInitializerOrThrow(),e,"deadLetterQueue")),Object.assign(r.tuning,A(o,e)),r},O=(o,e,i)=>{const t=o.getArguments()[0];if(!t||!u.isObjectLiteralExpression(t))throw c(o,`queue "${e}": defineQueue must be passed an inline object literal`);return N(t,e,void 0,i)},p=(o,e)=>`${o}:${e}`,Q=o=>{const e=o.getSymbol(),i=(e?.isAlias()===!0?e.getAliasedSymbol():e)?.getDeclarations()[0];return i!==void 0&&u.isVariableDeclaration(i)?p(i.getSourceFile().getFilePath(),i.getName()):p(o.getSourceFile().getFilePath(),o.getText())},L=(o,e,i,t)=>{const[n,r]=o.getArguments(),a=n!==void 0&&u.isIdentifier(n)?i.get(Q(n)):void 0;if(a===void 0)throw c(n??o,`subscription "${e}": the first argument must name a \`defineTopic()\` export of lunora/queues.ts or a module's queues.ts`);if(!r||!u.isObjectLiteralExpression(r))throw c(o,`subscription "${e}": defineSubscription must be passed an inline object literal`);return N(r,e,a,t)},U=o=>{const e=[];for(const i of o.getVariableDeclarations()){const t=i.getInitializer();if(t?.getKind()!==S.CallExpression)continue;const n=t,r=n.getExpression(),a=u.isIdentifier(r)?P(r):void 0;if(a===void 0)continue;const s=i.getNameNode();if(!u.isIdentifier(s)){if(i.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw c(s,`${a} exports must be plain named exports (no destructuring)`)}const m=v(i,"binding");m!==void 0&&e.push({call:n,exportName:m,factory:a,localName:s.getText()})}return e},C=(o,e)=>{const i=new Map;for(const t of o){const n=g(e,t.call.getSourceFile().getFilePath()),r=i.get(t.exportName);if(r!==void 0)throw c(t.call,`"${t.exportName}" is exported by both lunora/${r}.ts and lunora/${n}.ts — queue and topic export names must be unique across the app`);i.set(t.exportName,n)}},M=(o,e)=>{const i=o.flatMap(s=>U(s));C(i,e);const t=i.filter(s=>s.factory==="defineTopic"),n=new Map(t.map(s=>[p(s.call.getSourceFile().getFilePath(),s.localName),s.exportName])),r=[];for(const s of i)s.factory==="defineQueue"?r.push(O(s.call,s.exportName,e)):s.factory==="defineSubscription"&&r.push(L(s.call,s.exportName,n,e));const a=t.map(s=>({exportName:s.exportName,filePath:g(e,s.call.getSourceFile().getFilePath())}));return{queues:r,topics:a}},j=(o,e)=>[f(e,h),...F(o,e).map(i=>f(e,i.name,h))].filter(i=>x(i)),z=o=>{const e=new Map,i=new Map;for(const t of o){const n=e.get(t.name);if(n!==void 0)throw new b("DUPLICATE_QUEUE_NAME",`Duplicate queue name "${t.name}": produced by both "${n}" and "${t.exportName}". Deployed queue names must be unique across the project.`,{status:500});e.set(t.name,t.exportName);const r=i.get(t.bindingName);if(r!==void 0)throw new b("DUPLICATE_QUEUE_BINDING",`Duplicate queue binding "${t.bindingName}": produced by both "${r}" and "${t.exportName}". Queue export names must yield unique binding names.`,{status:500});i.set(t.bindingName,t.exportName)}},D=(o,e)=>{const i=j(o,e).map(a=>o.getSourceFile(a)??o.addSourceFileAtPath(a)),{queues:t,topics:n}=M(i,e),r=t.toSorted((a,s)=>a.exportName.localeCompare(s.exportName));return z(r),{queues:r,topics:n.toSorted((a,s)=>a.exportName.localeCompare(s.exportName))}},X=(o,e)=>D(o,e).queues;export{h as QUEUES_FILENAME,D as discoverQueueDeclarations,X as discoverQueues};
@@ -0,0 +1,11 @@
1
+ import{existsSync as L,mkdirSync as Gs,readFileSync as Ei,writeFileSync as xi,rmSync as ut,readdirSync as Si}from"node:fs";import{dirname as Ys,join as E,relative as Ai}from"node:path";import{performance as et}from"node:perf_hooks";import{runAdvisor as yi}from"@lunora/advisor";import{LunoraError as Q}from"@lunora/errors";import{serializeSchemaSnapshot as bi}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{toAdvisorContext as Ni}from"./formatAdvisories-DwmUKYuc.mjs";import{Node as r,SyntaxKind as d,ts as wi,VariableDeclarationKind as Pi}from"ts-morph";import{listLunoraSourceFiles as S,lunoraRelativePath as I,bindingKeyName as ee,collectCallRows as T,findObjectProperty as D,collectSecurityCallRows as Ii,propertyInitializer as C,listSecurityScanFiles as Ke,objectLiteralFromCallbackBody as Qs,limitNameOf as Xs,optionsObjectLiteral as Js,handlerOf as Ci,collectNodeRows as X,chainRootOf as wt,outermostValueWrapper as P,isWriteTarget as Be,isSameNode as y,unwrapExpression as h,isConstDeclaration as J,memberAccessOf as Zs,returningFunctionOf as ft,walkChain as Ti,RUN_METHODS as en,functionReferenceSegments as Oi,isTestPath as ki,isFunctionLike as Z,functionKeyOf as tn}from"./isTestPath-B81lOULB.mjs";import{b as j,d as V,f as O,g as Pt,c as v,a as sn,w as It,k as Ri,l as Fi,h as Li,m as Di,j as gt,i as Mi}from"./attribution-hVBriwzy.mjs";import{a as rs,r as tt,i as q,b as _i,m as nn,c as ze,e as Ct,E as rn,C as on,d as Ki,f as Bi,g as zi}from"./context-root-wBahDTzk.mjs";import{a as b,i as $i,c as G,d as an,e as Vi,f as Ui}from"./classify-procedure-call-BAj0D1u2.mjs";import{a as A,r as cn,s as qi,b as Wi}from"./project-config-file-BV7RR-l6.mjs";import{a as Hi,b as $e}from"./module-specifiers-WF8iAydP.mjs";import{r as Ve,s as ji}from"./parse-validator-IDBKIT7M.mjs";import Gi from"./discoverAuthApiCalls-xs0ONfI-.mjs";import Yi from"./discoverHyperdriveCalls-BUrA_96X.mjs";import{diagnosticAt as Ee}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{m as Tt,a as Re,s as ln,d as Qi}from"./index-BW4hJ4Wm.mjs";import{i as $,r as dn}from"./database-calls-CHZbBUCZ.mjs";import{MUTATORS_FILENAME as Xi,isDefineMutatorCallee as Ji,mutatorServerImplOf as Zi,discoverMutators as er}from"./MUTATORS_FILENAME-Bw0YtaO8.mjs";import tr from"./discoverNondeterministicCalls-9ZDpRptb.mjs";import{discoverNotifyConfig as sr,discoverNotifyCalls as nr}from"./NOTIFY_FILENAME-CPjbiHQl.mjs";import ir from"./discoverR2sqlCalls-COKmDnih.mjs";import rr from"./discoverRlsProcedures-BMqosvx6.mjs";import{s as Ot,n as or}from"./dispatch-namespace-DwTjD7BU.mjs";import{secretKindOf as ar,redact as cr,isHeuristicSecretKind as lr,isSecretishName as dr}from"./redact-Cy14LEnc.mjs";import{a as Pe,d as ur,r as fr}from"./modules-CjOcuQnK.mjs";import{WORKFLOWS_FILENAME as gr,discoverWorkflows as pr}from"./WORKFLOWS_FILENAME-CQR8fE9B.mjs";import{r as mr}from"./json-data-Chfs2Cz5.mjs";import{G as hr}from"./shared-DnCokNcE.mjs";import{createCodegenProject as vr}from"./createCodegenProject-V51_yBw3.mjs";import{findTsconfig as Sh,refreshCodegenProject as Ah}from"./createCodegenProject-V51_yBw3.mjs";import{CAPABILITIES as Er,usedCapabilities as xr}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{isD1GlobalTable as un,isHyperdriveGlobalTable as fn}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as Sr}from"./AGENTS_FILENAME-B6-kjzM3.mjs";import{discoverContainers as Ar}from"./CONTAINERS_FILENAME-Bk0u9QUu.mjs";import yr from"./discoverCrons-DF7dOP9x.mjs";import{contextPropertiesRead as br,discoverFeatureUsage as Nr}from"./capabilitiesUsedBy-QgSZyE0T.mjs";import wr from"./readPackageDependencies-RHhGiz0k.mjs";import{discoverQueueDeclarations as Pr}from"./QUEUES_FILENAME-CsRy4VTF.mjs";import{discoverSandboxUsage as Ir}from"./discoverSandboxUsage-w6Q3RvxZ.mjs";import{resolveServiceBindings as Cr}from"./readServiceBindings-DvqIThzd.mjs";import Tr from"./discoverStorageRulesMetadata-BPJplDfz.mjs";import{gatePlatformFeatures as Or,resolveCodegenTarget as gn,readTargetDiagnostics as kr,studioPlatformFor as Rr}from"./DEFAULT_TARGET-3U7x981M.mjs";import{i as Fr}from"./schema-BgM8A3XV.mjs";import{b as pn,e as Lr}from"./shard-DfBMIpi9.mjs";import{e as Dr,a as Mr}from"./server-DAvi_bv_.mjs";import{emitDataModel as _r}from"./emitDataModel-DdtjdNg3.mjs";import{i as Kr,a as Br,e as zr,b as $r,d as Vr,c as Ur}from"./unwrap-handler-return-B-jQde6M.mjs";import qr from"./discoverFunctions-DaEZl3uE.mjs";import Wr from"./discoverHttpRoutes-C_u9YiFb.mjs";import Hr from"./discoverInserts-OT_fiEGq.mjs";import{e as mn}from"./exported-procedure-chains-DKK5HoK3.mjs";import jr from"./discoverMigrations-C9mLIhGZ.mjs";import Gr from"./discoverQueries-C8V4cMIP.mjs";import Yr from"./discoverRlsMetadata-Cb8JR1b4.mjs";import Qr from"./discoverSchema-BCxeD80d.mjs";import{discoverShapes as Xr}from"./SHAPES_FILENAME-DkBUN9dK.mjs";import{i as Jr}from"./reserved-words-CW1QFbTd.mjs";import{emitApp as Zr}from"./emitApp-DAZCUDbr.mjs";import{readJsonSync as eo}from"@visulima/fs";import{buildSchemaSnapshot as to}from"./SchemaSnapshotParseError-CPOXlFhI.mjs";import{buildOpenApiDocument as so,emitOpenApiModule as no}from"./buildOpenApiDocument-DFv-RYZU.mjs";import{buildOpenRpcDocument as io,emitOpenRpcModule as ro}from"./OPENRPC_VERSION-CCY7xqSL.mjs";import{v as oo,t as ao,u as co,s as lo,w as uo}from"./shard-runtime-BX0xmo0P.mjs";import{emitCollections as fo,emitSeed as go,emitApi as po,emitInternalApi as mo}from"./emitApi-Zx6VPN-7.mjs";import{emitCrons as ho,emitScheduler as vo,emitShardRegistry as Eo,emitDurableObjects as xo,emitVectors as So,emitWranglerCronTriggers as Ao}from"./emitCrons-BQW2lviZ.mjs";import yo from"./emitDrizzleSchema-CpOGYfyl.mjs";import bo from"./emitFunctions-BeKgL3dl.mjs";const hn=new Set(["delete","get","head","options","patch","post","put"]),No=new Set(["handler","stream"]),wo=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,os=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Po=e=>{if(!r.isCallExpression(e))return;const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!hn.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()}},Io=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)||hn.has(n.getName()))break;s=n.getExpression()}return Po(s)},Co=e=>{for(const t of e.getDescendantsOfKind(d.PropertyAccessExpression))if(os.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=t.getExpression();if(r.isIdentifier(s)&&os.has(s.getText()))return!0}return!1},To=(e,t)=>{const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const n=s.getExpression();if(!r.isPropertyAccessExpression(n)||!No.has(n.getName()))return;const i=Io(s);if(!i||!wo.test(i.path))return;const o=s.getArguments()[0],a=o!==void 0&&(r.isArrowFunction(o)||r.isFunctionExpression(o))&&Co(o);return{exportName:V(e)??e.getName(),file:t,method:i.method,path:i.path,usesGuard:a}},Oo=(e,t)=>{const s=[];for(const n of j(e)){const i=To(n,t);i&&s.push(i)}return s},ko=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Oo(i,I(t,n)))}return s},Ro=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}},Fo=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)?ee(t):void 0}},Lo=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))&&rs(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))&&rs(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=Ro(e);return n!==void 0&&Fo(n)===t?!0:t==="args"&&Lo(e)},vn=(e,t)=>r.isIdentifier(e)?as(e,t):e.getDescendantsOfKind(d.Identifier).some(s=>as(s,t)),Do=e=>{let t=e;for(;r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t)||r.isNonNullExpression(t);)t=t.getExpression();return r.isIdentifier(t)?t:void 0},cs=e=>{const t=r.isIdentifier(e)?O(e):void 0;return r.isVariableDeclaration(t)&&r.isIdentifier(t.getNameNode())&&!Pt(t)?t.getInitializer():void 0},pt=e=>vn(e,"args"),W=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},H=e=>{if(pt(e))return!0;const t=W(e);return t!==void 0&&pt(t)},Mo=e=>{if(r.isCallExpression(e)||r.isNewExpression(e))return!1;const t=W(e);return t===void 0||!(r.isCallExpression(t)||r.isNewExpression(t))},te=e=>{if(tt(e))return!0;const t=cs(e);if(t!==void 0&&tt(t))return!0;const s=t??e;return(r.isIdentifier(s)?[s]:s.getDescendantsOfKind(d.Identifier)).some(i=>{const o=cs(i);return o!==void 0&&tt(o)})},Ie=(e,t)=>vn(e,t),_o=(e,t)=>{if(Ie(e,t))return!0;const s=W(e);if(s!==void 0&&Ie(s,t))return!0;const n=Do(e);if(n!==void 0){const i=W(n);return i!==void 0&&Ie(i,t)}return!1},Ko=e=>!r.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:q(e.getExpression(),["ai"]),Bo=(e,t)=>{if(!Ko(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!H(s)||te(s)))return{scope:v(e),file:t,line:e.getStartLineNumber()}},zo=(e,t)=>T(e,t,Bo),$o=new Set(["generateText","streamText"]),Vo=new Set(["messages","prompt","system"]),Uo=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],qo=(e,t)=>Uo.some(s=>s.methods.has(t)&&s.prefixes.some(n=>e===n||e.startsWith(`${n}.`))),Wo=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return;const s=t.getName(),n=[_i(t.getExpression()),t.getExpression().getText()].find(i=>i!==void 0&&qo(i,s));return n===void 0?void 0:`${n}.${s}`},Ho=e=>{for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=Wo(t);if(s!==void 0)return s}},jo=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=ee(o),c=o.getNameNode();if(a==="args"&&r.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},Go=e=>{if(pt(e))return!0;const t=jo(e);return t.size===0?!1:e.getDescendantsOfKind(d.Identifier).some(s=>t.has(s.getText()))},Yo=e=>{for(const t of e.getProperties()){if(!r.isPropertyAssignment(t)||!Vo.has(A(t)))continue;const s=t.getInitializer();if(s!==void 0&&Go(s))return!0}return!1},Qo=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=b(n.getExpression());if(i===void 0||!$o.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=Ho(c),a!==void 0))break;a!==void 0&&s.push({scope:v(n),file:t,line:n.getStartLineNumber(),method:i,sideEffect:a,userInputDerived:Yo(o)})}return s},Xo=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Qo(i,I(t,n)))}return s},Jo=e=>q(e,["fetch"]),Zo=(e,t)=>{if(!Jo(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!H(s)))return{scope:v(e),file:t,line:e.getStartLineNumber()}},ea=(e,t)=>T(e,t,Zo),kt=(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=Ve(s.getExpression());return n===void 0||kt(n,t)})}finally{t.delete(e)}},ta=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=D(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:Ve(n);return i===void 0?{objects:[],opaque:!0}:{objects:[i],opaque:kt(i)}},sa=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)?Ve(o):void 0;a===void 0?s=!0:(t.push(a),s||=kt(a))}n=i.getExpression()}return{objects:t,opaque:s}},Rt=(e,t)=>t?sa(t):ta(e),En=(e,t)=>{if(t.has(e))return[];t.add(e);try{return e.getProperties().flatMap(s=>{if(r.isSpreadAssignment(s)){const n=Ve(s.getExpression());return n===void 0?[]:En(n,t)}return r.isPropertyAssignment(s)||r.isShorthandPropertyAssignment(s)?[A(s)]:[]})}finally{t.delete(e)}},na=e=>e.flatMap(t=>En(t,new Set)),ia=new Set(["check","length","max"]),mt=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(ia.has(s.getName()))return!0;t=n}},ht=e=>Hi(e)||e==="@lunora/values",ra=e=>{const t=new Set(["v"]);for(const s of $i(e,"v",ht))t.add(s);for(const s of e.getImportDeclarations()){const n=s.getNamespaceImport();n&&ht(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},aa=e=>(e.getSymbol()?.getDeclarations()??[]).some(t=>!t.getSourceFile().isDeclarationFile()&&!r.isImportSpecifier(t)&&!r.isNamespaceImport(t)&&!r.isImportClause(t)),ca=e=>(e.getSymbol()?.getDeclarations()??[]).some(t=>r.isNamespaceImport(t)&&ht(t.getFirstAncestorByKindOrThrow(d.ImportDeclaration).getModuleSpecifierValue())),Ft=(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 aa(n)?void 0:s.getName();const i=r.isPropertyAccessExpression(n)?n.getExpression():void 0;return r.isIdentifier(i)&&ca(i)?s.getName():void 0}if(r.isIdentifier(s))return t.destructured.get(s.getText())},la=(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)},da=e=>{let t=e.getParent();for(;t&&!r.isFunctionLikeDeclaration(t);)t=t.getParent();return t},ua=e=>r.isReturnStatement(e)?e.getExpression():void 0,fa=e=>r.isArrowFunction(e)&&!r.isBlock(e.getBody())?[e.getBody()]:e.getDescendantsOfKind(d.ReturnStatement).filter(t=>da(t)?.compilerNode===e.compilerNode).flatMap(t=>{const s=ua(t);return s?[s]:[]}),xn=(e,t)=>{if(Ft(e,t)!==void 0)return e;if(r.isCallExpression(e)||r.isPropertyAccessExpression(e))return xn(e.getExpression(),t)},ga=(e,t)=>{const s=la(e.getExpression(),e.getSourceFile());if(!s)return[];const n=mt(e),i=new Set(fa(s).map(o=>xn(o,t)).filter(o=>o!==void 0));return[s,...s.getDescendants()].flatMap(o=>{const a=Ft(o,t);return a===void 0?[]:[{bounded:mt(o)||n&&i.has(o),factory:a}]})},pa=(e,t)=>[e,...e.getDescendants()].flatMap(s=>{const n=Ft(s,t),i=n===void 0?[]:[{bounded:mt(s),factory:n}];return r.isCallExpression(s)?[...i,...ga(s,t)]:i}),ma=(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=pa(a,t),l=A(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}},ha=(e,t,s)=>{const n=e.getInitializer();if(!n||!r.isCallExpression(n))return;const i=G(n);if(i?.visibility!=="public")return;const{objects:o}=Rt(n,i.receiver),{anyArgs:a,unboundedStringArgs:c}=ma(o,s);if(!(a.length===0&&c.length===0))return{anyArgs:a,exportName:V(e)??e.getName(),file:t,line:n.getStartLineNumber(),unboundedStringArgs:c}},va=(e,t)=>{const s=[],n=ra(e),i={destructured:oa(e,n),namespaces:n};for(const o of j(e)){const a=ha(o,t,i);a&&s.push(a)}return s},Ea=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...va(i,I(t,n)))}return s},st=e=>e?.getKind()===d.TrueKeyword,xa=e=>e?.getKind()===d.FalseKeyword,Sa=e=>e!==void 0&&r.isNumericLiteral(e)&&e.getLiteralValue()===0,Aa=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),ya=e=>!e||!r.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>r.isCallExpression(t)&&b(t.getExpression())==="scim"),ba=e=>e!==void 0&&r.isCallExpression(e)&&Aa.has(b(e.getExpression())??""),Na=e=>!e||!r.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>r.isStringLiteral(t)&&t.getLiteralText()==="*"),wa=e=>{const t=C(e,"advanced"),s=C(e,"emailAndPassword"),n=C(e,"session");return{analyzable:!0,disableCsrfCheck:st(C(t,"disableCSRFCheck")),emailPasswordEnabled:st(C(s,"enabled")),requireEmailVerification:st(C(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:ya(C(e,"plugins"))&&ba(C(e,"database")),secureCookiesDisabled:xa(C(t,"useSecureCookies")),sessionFreshAgeZero:Sa(C(n,"freshAge")),trustedOriginsWildcard:Na(C(e,"trustedOrigins"))}},Pa=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Ia=(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?wa(s):Pa();return{scope:v(e),file:t,line:e.getStartLineNumber(),...i}},Ca=(e,t)=>Ii(e,t,Ia),Ta=(e,t)=>{if(!r.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return nn(e.getExpression(),t.matchReceiver)?s:void 0},Oa=(e,t,s)=>{const n=Ta(e.getExpression(),s);if(n===void 0)return;const i=e.getArguments()[s.argIndex];if(!(!i||!H(i)||te(i))&&!(s.requireUnmodifiedReach===!0&&!Mo(i)))return{scope:v(e),file:t,line:e.getStartLineNumber(),method:n}},Ue=(e,t,s)=>T(e,t,(n,i)=>Oa(n,i,s)),ka=new Set(["content","pdf","scrape","screenshot"]),Ra=(e,t)=>Ue(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:ka}),Fa=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),La=new Set(["RateLimiter"]),Da=new Set(["extend"]),ls="lunora",Ma=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],Sn=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=A(i);t.push(o),i.getInitializer()?.getKind()===d.TrueKeyword&&s.push(o);continue}(r.isShorthandPropertyAssignment(i)||r.isMethodDeclaration(i))&&t.push(A(i))}return{analyzable:!n,presentKeys:t,trueKeys:s}},vt=e=>e&&r.isObjectLiteralExpression(e)?Sn(e):{analyzable:!1,presentKeys:[],trueKeys:[]},_a=e=>{const t=e&&(r.isArrowFunction(e)||r.isFunctionExpression(e))?e:void 0,s=t&&Qs(t.getBody());return s?Sn(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Ka=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=b(n.getExpression());i!==void 0&&(Fa.has(i)?s.push({callee:i,file:t,line:n.getStartLineNumber(),...vt(n.getArguments()[0])}):Da.has(i)&&s.push({callee:i,file:t,line:n.getStartLineNumber(),..._a(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(d.NewExpression)){const i=b(n.getExpression());i===void 0||!La.has(i)||s.push({callee:i,file:t,line:n.getStartLineNumber(),...vt(n.getArguments()[0])})}return s},Ba=(e,t)=>{for(const s of Ma){const n=E(t,s);if(!L(n))continue;const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=[];for(const a of i.getDescendantsOfKind(d.CallExpression))b(a.getExpression())===ls&&o.push({callee:ls,file:s,line:a.getStartLineNumber(),...vt(a.getArguments()[0])});return o}return[]},za=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of Ke(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);s.push(...Ka(o,n))}return s.push(...Ba(e,Ys(t))),s},ds="ctx.containers.",$a=e=>{if(!e.startsWith(ds))return!1;const t=e.slice(ds.length);return t.length>0&&!t.includes(".")},Va=(e,t)=>Ue(e,t,{argIndex:0,matchReceiver:$a,methods:new Set(["get"])}),Ua=new Set(["allow","deny","setAllowed"]),qa=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return!1;const s=D(t,"enableInternet");return s!==void 0&&r.isPropertyAssignment(s)&&r.isTrueLiteral(s.getInitializerOrThrow())},Wa=(e,t)=>{const s=e.getExpression();if(!(!r.isPropertyAccessExpression(s)||s.getName()!=="start"||!qa(e)))return{detail:"enableInternet: true",scope:v(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},Ha=(e,t)=>{const s=e.getExpression();if(!r.isPropertyAccessExpression(s)||!Ua.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()}},ja=(e,t)=>Wa(e,t)??Ha(e,t),Ga=(e,t)=>T(e,t,ja),Ya=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Qa=e=>{const t=e.getExpression();if(!r.isIdentifier(t))return;const s=t.getText();return Ya.has(s)?s:void 0},Xa=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=A(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(A(n))}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Ja=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of Ke(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);for(const a of o.getDescendantsOfKind(d.CallExpression)){const c=Qa(a);if(c===void 0)continue;const l=a.getArguments()[0],u=l&&r.isObjectLiteralExpression(l)?Xa(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},Za=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),ec=new Set(["dbRateLimit","rateLimit"]),tc=e=>{const t=Js(e);if(!t)return!1;const s=D(t,"failOpen");return s!==void 0&&r.isPropertyAssignment(s)&&s.getInitializer()?.getKind()===d.TrueKeyword},sc=(e,t)=>{const s=b(e.getExpression());if(s===void 0)return;const n=Za.get(s);if(n!==void 0)return{callee:s,scope:v(e),failOpen:tc(e.getArguments()[n]),file:t,limitName:ec.has(s)?Xs(e):"",line:e.getStartLineNumber()}},nc=(e,t)=>T(e,t,sc),ic=e=>{const t=e.getInitializer();if(!t||!r.isCallExpression(t))return;const s=G(t);if(s?.kind!=="query")return;const n=Ci(t,s.receiver);return n?{exportName:V(e)??e.getName(),handler:n}:void 0},us=e=>{const t=e.getParent();return t&&r.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},rc=e=>{const t=us(e);if(!t)return"ctx.flags";if(t.getName()==="details"){const s=us(t);return s?`ctx.flags.details.${s.getName()}`:"ctx.flags.details"}return`ctx.flags.${t.getName()}`},oc=(e,t)=>{const s=[];for(const n of ze(e.handler,"flags"))s.push({callee:rc(n),exportName:e.exportName,file:t,line:n.getStartLineNumber()});return s},ac=(e,t)=>{const s=[];for(const n of j(e)){const i=ic(n);i&&s.push(...oc(i,t))}return s},cc=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ac(i,I(t,n)))}return s},lc=e=>!r.isPropertyAccessExpression(e)||e.getName()!=="boolean"?!1:q(e.getExpression(),["flags"]),dc=e=>{if(e?.getKind()===d.TrueKeyword)return!0;if(e?.getKind()===d.FalseKeyword)return!1},uc=(e,t)=>{if(!lc(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(r.isStringLiteral(s)||r.isNoSubstitutionTemplateLiteral(s)))return;const i=s.getLiteralValue(),o=dc(n);if(!(i.length===0||o===void 0))return{defaultValue:o,scope:v(e),file:t,key:i,line:e.getStartLineNumber()}},fc=(e,t)=>T(e,t,uc),gc=e=>{const t=e.getExpression();return r.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},pc=e=>{const t=e.getArguments()[0];return t&&r.isStringLiteral(t)?t.getLiteralText():""},mc=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=I(t,n);for(const a of i.getDescendantsOfKind(d.CallExpression))gc(a)&&s.push({file:o,indexName:pc(a),line:a.getStartLineNumber()})}return s},he=e=>e!==void 0&&(r.isArrowFunction(e)||r.isFunctionExpression(e))?e:void 0,An=e=>{const t=e.getArguments()[0],s=he(t);if(s!==void 0)return s;if(t===void 0||!r.isObjectLiteralExpression(t))return;const n=D(t,"handler");return n!==void 0&&r.isPropertyAssignment(n)?he(n.getInitializer()):void 0},hc=new Set(["delete","get","head","options","patch","post","put"]),vc=new Set(["handler","stream"]),Ec=new Set(["runAction","runMutation"]),xc=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),ve=(e,t)=>e!==void 0&&r.isIdentifier(e)&&e.getText()===t,yn=(e,t)=>{if(!(e===void 0||!r.isObjectBindingPattern(e))){for(const s of e.getElements())if(ee(s)===t){const i=s.getNameNode();return r.isIdentifier(i)?i.getText():void 0}}},fs=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?r.isIdentifier(s)?s.getText():void 0:yn(s,"ctx")},gs=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&r.isIdentifier(s)?s.getText():void 0:yn(s,"request")},ps=(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(Ec.has(a)&&ve(c,t))return a;if(xc.has(a)&&r.isPropertyAccessExpression(c)&&c.getName()==="db"&&ve(c.getExpression(),t))return`db.${a}`}},ms=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(d.PropertyAccessExpression))if(n.getName()==="auth"&&ve(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(d.VariableDeclaration)){const i=n.getNameNode();if(!(!r.isObjectBindingPattern(i)||!ve(n.getInitializer(),t))){for(const o of i.getElements())if(ee(o)==="auth")return!0}}return!1},Sc=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,Ac=(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"&&ve(n.getExpression(),t)},yc=e=>[...r.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(d.StringLiteral).map(t=>t.getLiteralText())],bn=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:yc(s)},bc=(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)?bn(t,a.getText()):[]}return[]},Nc=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=bn(s,t.getText());return n.length>0?n:bc(t,s)},hs=(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=>Ac(i,t)&&Nc(i).some(o=>Sc.test(o)))},wc=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!vc.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(hc.has(i)){const o=n.getExpression();return r.isIdentifier(o)&&o.getText()==="httpRoute"?i.toUpperCase():void 0}s=n.getExpression()}},Pc=(e,t)=>{const s=e.getExpression();if(r.isIdentifier(s)&&s.getText()==="httpAction"){const c=he(e.getArguments()[0]),l=c&&fs(c,!0);if(!c||l===void 0||hs(c,gs(c,!0)))return;const u=ps(c,l);return u===void 0?void 0:{scope:v(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ms(c,l),sideEffect:u}}const n=wc(e);if(n===void 0)return;const i=he(e.getArguments()[0]),o=i&&fs(i,!1);if(!i||o===void 0||hs(i,gs(i,!1)))return;const a=ps(i,o);return a===void 0?void 0:{scope:v(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:ms(i,o),sideEffect:a}},Ic=(e,t)=>T(e,t,Pc),Cc=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),Tc=new Set(["append","set"]),Nn=e=>e!==void 0&&(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",vs=(e,t)=>(r.isCallExpression(e)?[e,...e.getDescendantsOfKind(d.CallExpression)]:e.getDescendantsOfKind(d.CallExpression)).some(n=>Cc.has(b(n.getExpression())??"")&&Ie(n,t)),Oc=(e,t)=>{if(vs(e,t))return!0;const s=W(e);return s!==void 0&&vs(s,t)},Et=(e,t)=>_o(e,t)&&!Oc(e,t),kc=e=>{if(r.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=W(e);return t!==void 0&&r.isNewExpression(t)&&b(t.getExpression())==="Headers"},Fe=e=>{if(e===void 0)return;if(r.isObjectLiteralExpression(e))return e;const t=W(e);return t!==void 0&&r.isObjectLiteralExpression(t)?t:void 0},Lt=(e,t,s)=>{for(const n of e.getProperties())if(r.isPropertyAssignment(n)){const i=n.getInitializer();i!==void 0&&Et(i,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:Nn(n.getNameNode()),line:i.getStartLineNumber(),via:t})}else if(r.isShorthandPropertyAssignment(n)){const i=n.getNameNode();Et(i,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:A(n),line:i.getStartLineNumber(),via:t})}else if(r.isSpreadAssignment(n)){const i=Fe(n.getExpression());i!==void 0&&Lt(i,t,s)}},wn=(e,t)=>{const s=Fe(e);if(s===void 0)return;const n=D(s,"headers");if(n===void 0||!r.isPropertyAssignment(n))return;const i=Fe(n.getInitializer());i!==void 0&&Lt(i,"response-init",t)},Rc=(e,t)=>{const s=b(e.getExpression());if(s==="Response")wn(e.getArguments()[1],t);else if(s==="Headers"){const n=Fe(e.getArguments()[0]);n!==void 0&&Lt(n,"headers-ctor",t)}},Fc=(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"){wn(e.getArguments()[1],t);return}if(Tc.has(n)&&kc(i)){const o=e.getArguments()[1];o!==void 0&&Et(o,t.requestName)&&t.rows.push({scope:t.scope,file:t.relativePath,headerName:Nn(e.getArguments()[0]),line:o.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},Lc=(e,t)=>{for(const s of e.getDescendantsOfKind(d.NewExpression))Rc(s,t);for(const s of e.getDescendantsOfKind(d.CallExpression))Fc(s,t)},Dc=(e,t)=>{const s=e.getExpression();if(!r.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=he(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 Lc(n,{scope:v(e),relativePath:t,requestName:o.getText(),rows:a}),a},Mc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression))s.push(...Dc(n,t));return s},_c=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Mc(i,I(t,n)))}return s},Pn="identity.ts",Kc=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(r.isImportSpecifier(s))return $e(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Bc=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&&$e(n.getModuleSpecifierValue())}return!1},zc=e=>{if(r.isIdentifier(e))return Kc(e);if(r.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&r.isIdentifier(t)&&Bc(t)}return!1},$c=e=>{const t=[];for(const s of e.getVariableDeclarations()){const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!zc(n.getExpression()))continue;const o=s.getNameNode();if(!r.isIdentifier(o)){if(s.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw Ee(o,"defineIdentity exports must be plain named exports (no destructuring)")}const a=sn(s,"member");a!==void 0&&t.push({exportName:a})}return t},Vc=(e,t)=>{const s=E(t,Pn);if(!L(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=$c(n);if(i.length!==0){if(i.length>1)throw Ee(n,`lunora/identity.ts declares ${i.length.toString()} defineIdentity() contracts (${i.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Uc=new Set(["auth","context.auth"]),qc="userId",Wc=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(A(s))}return t},Hc=(e,t)=>{const s=E(t,Pn);if(!L(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)?Wc(o):void 0}},Es=e=>{if(e===void 0||!r.isPropertyAccessExpression(e)||e.getName()!=="identity")return;const t=e.getExpression();return Uc.has(t.getText())||q(t,["auth"])?e:void 0},jc=e=>{if(r.isPropertyAccessExpression(e)&&Es(e.getExpression())!==void 0)return e.getName();if(r.isElementAccessExpression(e)&&Es(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&r.isStringLiteral(t)?t.getLiteralValue():void 0}},xs=(e,t,s)=>{const n=jc(e);return n===void 0?void 0:{declared:n===qc||s.has(n),file:t,key:n,line:e.getStartLineNumber(),scope:v(e)}},Gc=(e,t)=>{const s=Hc(e,t);return s===void 0?[]:[...X(e,t,d.PropertyAccessExpression,(n,i)=>xs(n,i,s)),...X(e,t,d.ElementAccessExpression,(n,i)=>xs(n,i,s))]},Yc=(e,t)=>{if(b(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=C(s,"key");if(!(!n||!H(n)||te(n)))return{scope:v(e),file:t,line:e.getStartLineNumber()}},Qc=(e,t)=>T(e,t,Yc),Xc=new Set(["delete","get","getRaw","getWithMetadata","put"]),Jc=(e,t,s=[])=>{const n=Ue(e,t,{argIndex:0,matchReceiver:i=>i==="ctx.kv"||i.startsWith("ctx.kv."),methods:Xc});return It(n,s)},Zc=new Set(["queue","send"]),Ss=new Set(["bcc","cc","to"]),el=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();if(!Zc.has(t))return;const s=e.getExpression();return q(s,["mail"])||q(s,["email"])?t:void 0},tl=e=>r.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(r.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return Ss.has(A(t))&&H(n)&&!te(n)}if(!r.isPropertyAssignment(t)||!Ss.has(A(t)))return!1;const s=t.getInitializer();return s!==void 0&&H(s)&&!te(s)}):!1,sl=(e,t)=>{const s=el(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!tl(n)))return{scope:v(e),file:t,line:e.getStartLineNumber(),method:s}},nl=(e,t)=>T(e,t,sl),il=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!r.isObjectLiteralExpression(n))return[];const i=[];for(const o of n.getProperties()){const a=Re(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=Re(l);if(u===void 0)continue;const g=ln(l);g!=="custom"&&i.push({column:u,exportName:t,file:s,line:l.getStartLineNumber(),strategy:g,table:a})}}return i},rl=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&r.isCallExpression(s)?G(s):void 0;return n?.receiver?Tt(n.receiver).flatMap(i=>il(i,V(e)??e.getName(),t)):[]},ol=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=I(t,n);for(const a of j(i))s.push(...rl(a,o))}return s},al=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return $(s)},cl=e=>{const t=e.getArguments()[0];if(t===void 0||!r.isObjectLiteralExpression(t))return;const s=D(t,"server");if(s!==void 0)return r.isPropertyAssignment(s)?s.getInitializer():s},ll=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==d.CallExpression)return;const s=t;return Ji(s.getExpression())?s:void 0},dl=e=>{const t=ll(e),s=t===void 0?void 0:cl(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=>al(o)).map(o=>({exportName:i,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},ul=e=>e.getVariableDeclarations().flatMap(t=>dl(t)),fl=(e,t)=>{const s=E(t,Xi);if(!L(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return ul(n)},gl=new Set(["delete","get","patch"]),pl=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),ml=new Set(["auth","identity","session","user"]),hl=new Set([d.EqualsEqualsEqualsToken,d.EqualsEqualsToken,d.ExclamationEqualsEqualsToken,d.ExclamationEqualsToken]),vl=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!$(t.getExpression()))return;const s=e.getArguments()[0];return s&&r.isStringLiteral(s)?s.getLiteralText():""},El=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},xl=(e,t)=>e.getDescendantsOfKind(d.Identifier).some(s=>s.getText()===t),Sl=e=>r.isThrowStatement(e)||r.isReturnStatement(e)||e.getDescendantsOfKind(d.ThrowStatement).length>0||e.getDescendantsOfKind(d.ReturnStatement).length>0,Al=(e,t)=>e.getDescendantsOfKind(d.IfStatement).some(s=>xl(s.getExpression(),t)&&Sl(s.getThenStatement())),yl=(e,t)=>{for(const s of e.getDescendantsOfKind(d.CallExpression)){const n=s.getExpression();if(!r.isPropertyAccessExpression(n))continue;const i=n.getName();if(!gl.has(i))continue;const o=n.getExpression();if(!($(o)||r.isPropertyAccessExpression(o)&&$(o.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&r.isIdentifier(c)&&c.getText()===t)return i}},bl=e=>e.getDescendantsOfKind(d.CallExpression).some(t=>t.getArguments().some(s=>Ct(wt(s))!==void 0)),Nl=e=>e.getDescendantsOfKind(d.BinaryExpression).some(t=>hl.has(t.getOperatorToken().getKind())?r.isPropertyAccessExpression(t.getLeft())||r.isPropertyAccessExpression(t.getRight()):!1),wl=e=>{for(const t of e.getDescendantsOfKind(d.Identifier))if(pl.has(t.getText()))return!0;return[...ml].some(t=>ze(e,t).length>0)?!0:bl(e)||Nl(e)},Pl=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!r.isCallExpression(s))return[];const n=G(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const i=An(s);if(i===void 0)return[];const o=n.receiver!==void 0&&an(n.receiver,"use","rls"),a=wl(i),c=new Set,l=[];for(const u of i.getDescendantsOfKind(d.CallExpression)){const g=vl(u);if(g===void 0)continue;const f=El(u);if(f===void 0||c.has(f)||!Al(i,f))continue;const p=yl(i,f);p!==void 0&&(c.add(f),l.push({exportName:V(e)??e.getName(),file:t,line:u.getStartLineNumber(),mentionsOwnership:a,sinkMethod:p,table:g,usesRls:o,visibility:n.visibility}))}return l},Il=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=I(t,n);for(const a of j(i))s.push(...Pl(a,o))}return s},In=(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},Cl=e=>{const t=P(e),s=t.getParent();return(r.isPropertyAccessExpression(s)||r.isElementAccessExpression(s))&&s.getExpression()===t&&!Be(s)},Tl=e=>{const t=P(e).getParent();return r.isVariableDeclaration(t)&&r.isObjectBindingPattern(t.getNameNode())},Ol=e=>{const s=P(e).getParent();if(r.isSpreadAssignment(s)||r.isSpreadElement(s)){const n=s.getParent();return(r.isObjectLiteralExpression(n)||r.isArrayLiteralExpression(n))&&!Be(n)}return r.isTemplateSpan(s)&&!r.isTaggedTemplateExpression(s.getParent().getParent())},Le=e=>{const t=O(e);return t===void 0||Fi(t.getSourceFile())},xt=(e,t)=>{const s=P(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"&&Le(o);if(In(wt(o),t))return!(r.isPropertyAccessExpression(o)&&rn.has(o.getName()))||r.isExpressionStatement(P(r.isAwaitExpression(n.getParent())?n.getParentOrThrow():n).getParent());if(!r.isPropertyAccessExpression(o))return!1;const a=o.getExpression();if(!r.isIdentifier(a)||!Le(a))return!1;const c=a.getText(),l=o.getName();switch(c){case"console":return!0;case"JSON":return l==="stringify";case"Object":return["entries","freeze","isFrozen","keys","values"].includes(l)||l==="assign"&&i>0;default:return!1}},Ce={kind:"opaque"},kl={kind:"unreached"},Rl=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},St=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=Rl(s);return i===void 0||Pt(i)?void 0:i}const n=J(s)?h(s.getInitializer()):void 0;return r.isArrowFunction(n)||r.isFunctionExpression(n)?n:void 0},Cn=(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?Ce:c===void 0?a.some(l=>l.isRestParameter())?Ce:kl:c.isRestParameter()?Ce:{kind:"parameter",parameter:c}},Fl=e=>{const t=P(e),s=t.getParent();if(!r.isCallExpression(s)||s.getExpression()===t)return;const n=St(s.getExpression());return n===void 0?Ce:Cn(n,s,t)},Ll=new Set(["__defineGetter__","__defineSetter__","__proto__"]),Dl=e=>r.isForInStatement(e)?e.getExpression():r.isConditionalExpression(e)?e.getCondition():r.isElementAccessExpression(e)?e.getArgumentExpression():void 0,Tn=e=>{const t=P(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=Dl(s);if(n!==void 0)return y(n,t);if(r.isPrefixUnaryExpression(s))return s.getOperatorToken()!==d.PlusPlusToken&&s.getOperatorToken()!==d.MinusMinusToken;if(!r.isBinaryExpression(s))return!1;const i=s.getOperatorToken().getKind(),o=i>=d.FirstAssignment&&i<=d.LastAssignment,a=i===d.QuestionQuestionToken||i===d.BarBarToken||i===d.AmpersandAmpersandToken;return!o&&!a},Ml=4,On=(e,t,s=0)=>{if(Ri(e))return!0;if(Cl(e)){const i=P(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||!Ll.has(c)}if(Tl(e)||Ol(e)||Tn(e)||xt(e,t))return!0;const n=Fl(e);return n?.kind==="unreached"||n?.kind==="parameter"&&_l(n.parameter,s+1)},As=new WeakMap,_l=(e,t=0)=>{const s=e.getNameNode();if(!r.isIdentifier(s))return!0;const n=As.get(e.compilerNode);if(n!==void 0)return n;if(t>Ml)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||On(a,void 0,t));return(o||t===0)&&As.set(e.compilerNode,o),o},ys=new WeakMap,Kl=(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)})},Bl=(e,t,s)=>{const{context:n,impl:i}=e,o=ys.get(i.compilerNode);if(o!==void 0)return o;const a=t.getNameNode(),c=r.isIdentifier(a)?[a]:a.getDescendantsOfKind(d.BindingElement).flatMap(f=>{const p=f.getNameNode();return r.isIdentifier(p)?[p]:[]}),l=new Map(c.map(f=>[f.getText(),f.getParentOrThrow().compilerNode])),u=f=>r.isIdentifier(a)?On(f,n):!Be(f),g=!Kl(i,s)&&c.every(f=>(f.getSymbol()?.getDeclarations().length??0)===1)&&i.getDescendantsOfKind(d.Identifier).every(f=>{const p=f.getText();if(p==="arguments")return!1;const x=l.get(p);return x===void 0||c.includes(f)||O(f)?.compilerNode!==x?!0:u(f)});return ys.set(i.compilerNode,g),g},bs=new WeakMap,zl=e=>{let t=bs.get(e.compilerNode);return t===void 0&&(t=new Map(e.getVariableDeclarations().flatMap(s=>{const n=Zi(s);return n===void 0?[]:[[n.compilerNode,s]]})),bs.set(e.compilerNode,t)),t},$l=e=>{const t=zl(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&&Bl(c,a,n)?{...c,parameter:a,pristine:!0}:{...c,parameter:a,pristine:!1}},nt="args",ge=e=>{const t=Zs(e);if(t!==void 0){const c=h(t.object);return r.isIdentifier(c)&&c.getText()===nt?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=J(i)?h(i.getInitializer()):void 0;return r.isBindingElement(i)&&ee(i)===nt||r.isIdentifier(o)&&o.getText()===nt?ee(s):void 0},Vl=new Set(["auth","identity","user"]),At=e=>{const t=i=>{const o=Ct(i);return o!==void 0&&o.length>0&&Vl.has(o[0]??"")},s=h(e)??e;if(t(s))return!0;const n=W(s);return n!==void 0&&t(n)},kn=(e,t=2)=>{const s=new Set;for(const n of[e,...e.getDescendants()]){const i=ge(n);i!==void 0&&s.add(i);const o=t>0&&r.isIdentifier(n)?W(n):void 0;if(o!==void 0)for(const a of kn(o,t-1))s.add(a)}return s},Te=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[...Te(n),...Te(i)];if(s===d.AmpersandAmpersandToken){const l=(u,g)=>{const f=ge(h(u)??u);return f===void 0?[]:Te(g).filter(p=>p===f)};return[...l(n,i),...l(i,n)]}if(s!==d.ExclamationEqualsEqualsToken&&s!==d.ExclamationEqualsToken)return[];const o=[],a=ge(h(n)??n),c=ge(h(i)??i);return a!==void 0&&At(i)&&o.push(a),c!==void 0&&At(n)&&o.push(c),o},Ul=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)&&Vi(i.getExpression(),"defineIdentityGuard")},ql=e=>{if(!Ul(e.getExpression()))return[];const t=e.getArguments();return t.flatMap((s,n)=>{const i=ge(h(s)??s),o=t.some((a,c)=>c!==n&&At(a));return i!==void 0&&o?[i]:[]})},Wl=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)},Hl=e=>r.isArrowFunction(e)||r.isFunctionExpression(e)||r.isFunctionDeclaration(e)||r.isMethodDeclaration(e),Ns=(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},jl=e=>r.isAwaitExpression(e.getParent())||e.getType().isVoid(),Gl=(e,t)=>{const s=new Set;for(const n of e.getDescendantsOfKind(d.IfStatement))if(n.getEnd()<=t&&Ns(n,e)&&Wl(n.getThenStatement()))for(const i of Te(n.getExpression()))s.add(i);for(const n of e.getDescendantsOfKind(d.CallExpression))if(n.getEnd()<=t&&jl(n)&&Ns(n,e))for(const i of ql(n))s.add(i);return s},Yl=(e,t)=>{const s=kn(t);if(s.size===0)return!1;const n=e.getFirstAncestor(Hl);if(n===void 0)return!1;const i=Gl(n,e.getStart());return[...s].every(o=>i.has(o))},Ql=new Set(["at","concat","filter","find","findLast","flat","reverse","slice","sort","toReversed","toSorted"]),Xl=new Map([["Array",new Set(["from","of"])],["Object",new Set(["entries","values"])]]),yt=new Set(["catch","every","filter","finally","find","findIndex","findLast","findLastIndex","flatMap","forEach","map","reduce","reduceRight","some","sort","then"]),Rn=e=>e.getNameNode().getDescendantsOfKind(d.BindingElement).filter(t=>r.isIdentifier(t.getNameNode())),Jl=e=>{const t=P(e),s=t.getParent();if(r.isVariableDeclaration(s))return y(s.getInitializer(),t)?s:void 0;const n=r.isForOfStatement(s)&&s.getExpression()===t?s.getInitializer():void 0;return r.isVariableDeclarationList(n)?n.getDeclarations()[0]:void 0},Zl=e=>{const t=Jl(e);return t===void 0?void 0:r.isIdentifier(t.getNameNode())?r.isForOfStatement(t.getParent().getParent())||J(t)?[t]:void 0:Rn(t)},pe=e=>e.isUnion()?e.getUnionTypes().every(t=>pe(t)):e.isIntersection()?e.getIntersectionTypes().some(t=>pe(t)):!e.isAny()&&!e.isUnknown()&&!e.isObject()&&!e.isTypeParameter(),De=(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)},Oe=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]},ed=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)&&Xl.get(s.getText())?.has(t.getName())===!0&&Le(s)},td=e=>{const t=ft(e);if(!r.isArrowFunction(t)&&!r.isFunctionExpression(t))return;const s=P(t),n=s.getParent();return r.isCallExpression(n)&&n.getArguments().includes(s)&&De(n,on)?n:void 0},sd=(e,t)=>{if(!(r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e))||e.getExpression()!==t)return;const s=P(e),n=s.getParent();return!r.isCallExpression(n)||n.getExpression()!==s?e:De(n,Ql,t)?n:void 0},nd=(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},id=(e,t)=>{if(r.isArrayLiteralExpression(e))return e;const n=r.isSpreadElement(e)||r.isSpreadAssignment(e)||r.isShorthandPropertyAssignment(e)||r.isPropertyAssignment(e)&&y(e.getInitializer(),t)?e.getParent():void 0;return r.isArrayLiteralExpression(n)||r.isObjectLiteralExpression(n)?n:void 0},ws=e=>{const t=P(e),s=t.getParent();if(s===void 0)return;const n=r.isCallExpression(s)&&s.getArguments().includes(t)&&ed(s);return sd(s,t)??nd(s,t)??id(s,t)??(n?s:td(t))},rd=5e4,Fn=()=>({inProgress:new Set,verdicts:new Map});class od{cuts=0;work=0;reset(){this.work=0}cut(){return this.cuts+=1,!0}spend(){return this.work+=1,this.work>rd&&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 ad=8,cd=8;class ld{budget;scope;taint;verdicts=Fn();constructor(t,s,n){this.scope=t,this.budget=s,this.taint=n}isCompromised(t){return this.flowHasCompromisingUse(t)&&!pe(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)?Rn(t):[])i(l,s);return!1}if(this.budget.spend())return!0;const a=(l,u)=>u&&s>=ad?this.budget.cut():(i(l,u?s+1:s),!1);return this.taint.referencesTo(t,o.getText()).some(l=>this.valueCompromises(P(l),!0,a,0))&&(t===n||!pe(t.getType()))}valueCompromises(t,s,n,i){let o=t;for(let p=ws(o);p!==void 0;p=ws(o)){if(r.isCallExpression(p)&&this.callbackCompromises(p,n))return!0;o=P(p)}const a=o.getParent(),c=o===t&&s,l=()=>!c&&pe(o.getType());if(Be(o))return!c&&(!r.isBinaryExpression(a)||this.taint.isTaintedValue(a.getRight(),!1));const u=Zl(o);if(u!==void 0)return u.some(p=>n(p,!0));const g=r.isPropertyAccessExpression(a)&&a.getExpression()===o?a.getParent():void 0;if(r.isCallExpression(g)&&g.getExpression()===a)return this.methodCallCompromises(g,n);const f=this.nestedReturningFunctionOf(o);return f!==void 0?this.resultCompromises(f,n,i)&&!l():this.positionCompromises(o,n)&&!l()}resultCompromises(t,s,n){const i=P(t).getParent();if(n>=cd)return this.budget.cut();if(r.isCallExpression(i))return i.getExpression()===P(t)?this.valueCompromises(i,!1,s,n+1):!De(i,yt);const o=r.isFunctionDeclaration(t)?t:i,a=r.isFunctionDeclaration(o)||J(o)?o.getNameNode():void 0;return o===void 0||!r.isIdentifier(a)?!0:this.taint.referencesTo(o,a.getText()).some(c=>{const l=P(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=>Oe(i)===void 0).some(i=>this.taint.isTaintedValue(i,!1))||this.callbackCompromises(t,s)}callbackCompromises(t,s){const n=De(t,yt)?t.getArguments()[0]:void 0;if(n===void 0)return!1;const i=St(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!xt(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(xt(s,this.scope.context))return!1;const i=St(t.getExpression()),o=i===void 0?void 0:Cn(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)||Tn(t)||y(ft(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=ft(t);return y(s,this.scope.impl)?void 0:s}}const dd=new Set(["at","every","filter","finally","find","findIndex","findLast","findLastIndex","forEach","order","slice","some","sort","withIndex","withSearchIndex"]),ud=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)},fd=new Set(["all","allSettled","any","race"]),Ps=e=>r.isParameterDeclaration(e)?e:r.isBindingElement(e)?e.getFirstAncestorByKind(d.Parameter):void 0,it=8;class gd{budget=new od;referencesByDeclaration=new Map;referencesByName=new Map;scope;verdicts=Fn();walk;variableDepth=0;queryDepth=0;constructor(t){this.scope=t,this.walk=new ld(t,this.budget,this);for(const s of t.impl.getDescendantsOfKind(d.Identifier)){const n=s.getText();this.referencesByName.set(n,[...this.referencesByName.get(n)??[],s])}}isTaintedValue(t,s){this.queryDepth===0&&this.budget.reset(),this.queryDepth+=1;try{return s&&this.isRootedInContext(t,it)?!1:(r.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(i=>Li(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(f=>f.getInitializer())].some(f=>f!==void 0&&this.isTaintedValue(f,!1)))return!0;const n=t.getParentOrThrow(),i=r.isFunctionLikeDeclaration(n)?n.getParameters().findIndex(f=>f.compilerNode===t.compilerNode):-1,o=P(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 f=h(a.getExpression());if(!r.isPropertyAccessExpression(f)||!yt.has(f.getName()))return!0;const p=a.getArguments().filter(x=>x!==o);return this.isTaintedValue(f.getExpression(),!0)||p.some(x=>this.isTaintedValue(x,!1))}const c=r.isVariableDeclaration(a)&&J(a)?a:void 0,l=r.isFunctionDeclaration(n)?n:c,u=l?.getNameNode();if(l===void 0||!r.isIdentifier(u))return!0;const g=this.referencesTo(l,u.getText());return g.length===0||g.some(f=>{const p=P(f),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"&&Le(i)&&fd.has(n.getName())?h(t.getArguments()[0]):void 0;if(r.isArrayLiteralExpression(a)){const g=a.getElements();return g.length>0&&g.every(f=>!r.isSpreadElement(f)&&this.isRootedInContext(f,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:Oe(l);return u!==void 0&&u.length>0&&u.every(g=>g!==void 0&&this.isRootedInContext(g,s))}isIdentifierTainted(t){const s=t.getText();if(s==="arguments")return!0;const n=O(t),i=Ps(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&&rn.has(i)?!1:i!==void 0&&on.has(i)?this.isCallbackResultServerScoped(t,s)?void 0:!1:t.getArguments().some(a=>Oe(a)!==void 0)&&(i===void 0||!dd.has(i))?!1:void 0}isCallbackResultServerScoped(t,s){const n=(i,o=[])=>{const a=wt(i),c=r.isIdentifier(a)?Ps(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=Oe(i);if(o===void 0)return!ud(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=Ti(t,u=>this.callChainVerdict(u,s)),i=n.root;if(n.verdict!==void 0)return n.verdict;if(In(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=J(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=Pt(t);if(n===void 0||i)return!0;if(this.isRootedInContext(n,it))return!1;if(this.variableDepth>=it)return this.budget.cut();this.variableDepth+=1;try{return this.isTaintedValue(n,!1)}finally{this.variableDepth-=1}},this.verdicts)}}const Is=new WeakMap,pd=e=>{const t=Is.get(e.impl.compilerNode);if(t!==void 0)return t;const s=new gd(e);return Is.set(e.impl.compilerNode,s),s},md=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),hd=new Set(["insert","insertManyUnsafe","patch","replace"]),vd=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();return hd.has(t)&&Ki(e.getExpression())?t:void 0},Ed=(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},xd=(e,t)=>{const s=Zs(e);return s?.member===t?h(s.object):void 0},Cs=(e,t)=>r.isIdentifier(e)&&O(e)?.compilerNode===t.compilerNode,Ln=(e,t,s,n=1)=>{const i=xd(e,s);if(i!==void 0)return Cs(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&&ee(o)===s&&r.isObjectBindingPattern(c)&&(l.compilerNode===t.compilerNode||J(l)&&Cs(h(l.getInitializer()),t))}const a=J(o)?o.getInitializer():void 0;return n>0&&a!==void 0&&Ln(a,t,s,n-1)},bt=e=>{const t=h(e)??e;return r.isConditionalExpression(t)?[...bt(t.getWhenTrue()),...bt(t.getWhenFalse())]:[t]},Sd=(e,t,s)=>{const n=[],i=s===void 0?void 0:pd(s);for(const o of e.getProperties()){let a,c;if(r.isPropertyAssignment(o)?(a=A(o),c=o.getInitializer()):r.isShorthandPropertyAssignment(o)&&(a=A(o),c=o.getNameNode()),a===void 0||c===void 0||!md.has(a))continue;const l=bt(c).filter(g=>i===void 0?H(g)&&!Bi(g):i.isTaintedValue(g,!0));if(l.length>0){const g=t.ownerField===a&&s?.pristine===!0&&Ln(c,s.parameter,a),f=l.every(p=>Yl(t.call,p));n.push({field:a,file:t.relativePath,line:t.call.getStartLineNumber(),method:t.method,scope:t.scope,...g&&{ownerScoped:!0},...f&&{guarded:!0}})}}return n},Ad=(e,t,s)=>{const n=vd(e.getExpression()),i=n===void 0?void 0:e.getArguments()[1];if(n===void 0||i===void 0)return[];const o=Ed(i,n);if(o.length===0)return[];const a=v(e),c=$l(e),l={call:e,method:n,ownerField:c===void 0?void 0:s(c.mutatorName),relativePath:t,scope:a};return o.flatMap(u=>Sd(u,l,c))},yd=(e,t,s=[],n=[])=>{const i=new Map(n.map(c=>[`${c.filePath}:${c.exportName}`,c.owner])),o=T(e,t,(c,l)=>Ad(c,l,u=>i.get(`${l}:${u}`))),a=new Map(s.map(c=>[`${c.filePath}:${c.exportName}`,c.adminOnly===!0]));return It(o,s).map(c=>Di(c.scope)?.every(g=>a.get(`${c.file}:${g}`)===!0)===!0?{...c,adminOnly:!0}:c)},bd=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Nd=e=>e&&r.isNumericLiteral(e)?Number(e.getText()):void 0,wd=e=>{const t=D(e,"webhookToleranceSeconds");return t&&r.isPropertyAssignment(t)?Nd(t.getInitializer()):void 0},Pd=(e,t)=>{const s=b(e.getExpression());if(s===void 0||!bd.has(s))return;const[n]=e.getArguments(),i=n&&r.isObjectLiteralExpression(n)?wd(n):void 0;return{callee:s,scope:v(e),file:t,line:e.getStartLineNumber(),...i===void 0?{}:{toleranceSeconds:i}}},Id=(e,t)=>T(e,t,Pd),Cd=new Map([["defineQueue",0],["defineSubscription",1],["defineWorkflow",0]]),Td=e=>{const t=e.getExpression();return r.isIdentifier(t)?t.getText():void 0},Od=(e,t)=>{const s=e.getArguments()[t];if(!s||!r.isObjectLiteralExpression(s))return;const n=D(s,"handler");if(n===void 0||!r.isPropertyAssignment(n))return;const i=n.getInitializer();if(i&&(r.isArrowFunction(i)||r.isFunctionExpression(i)))return i},Dn=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&r.isIdentifier(s)?s.getText():void 0},Mn=(e,t)=>e===t||e.startsWith(`${t}.`),_n=e=>{const t=e.getDescendantsOfKind(d.PropertyAccessExpression);return r.isPropertyAccessExpression(e)&&t.push(e),t},Ts=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)},Kn=e=>{const t=e.getDescendantsOfKind(d.Identifier).filter(s=>Ts(s));return r.isIdentifier(e)&&Ts(e)&&t.push(e),t},kd=e=>{if(!r.isVariableDeclaration(e))return[];const t=e.getNameNode();return r.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(d.BindingElement).map(s=>s.getName())},Rd=e=>{const t=Dn(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},Fd=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:Rd(e),i=new Set,o=a=>_n(a).some(c=>n.some(l=>Mn(c.getText(),l)))?!0:Kn(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 kd(a))i.add(l)}return{names:i,prefixes:n}},Ld=(e,t)=>_n(e).some(s=>t.prefixes.some(n=>Mn(s.getText(),n)))?!0:Kn(e).some(s=>t.names.has(s.getText())),Dd=e=>{const t=Oi(e);return t===void 0?void 0:{exportName:String(t.at(-1)),file:t.slice(0,-1).join("/")}},Md=(e,t,s)=>{const n=Dn(e,0);if(n===void 0)return[];const i=Fd(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)||!en.has(l.getName())||!o.has(l.getExpression().getText()))continue;const u=c.getArguments()[1];if(!u||!Ld(u,i))continue;const g=Dd(c.getArguments()[0]);g!==void 0&&a.push({dispatchKind:t,file:s,scope:v(c),line:c.getStartLineNumber(),targetExport:g.exportName,targetFile:g.file})}return a},_d=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=Td(n),o=i===void 0?void 0:Cd.get(i);if(o===void 0)continue;const a=Od(n,o);a!==void 0&&s.push(...Md(a,i==="defineWorkflow"?"workflow":"queue",t))}return s},Kd=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(..._d(i,I(t,n)))}return s},Os={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},ks=new Set(["account","credential","member","passkey","session","user"]),Bd=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),zd=e=>{const s=Bd(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return ks.has(s)||ks.has(n)},$d=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Vd=(e,t)=>{const{objects:s,opaque:n}=Rt(e,t);return na(s).some(i=>$d(i))?!0:n?void 0:!1},Ud=e=>{const t=e.getArguments()[0];return!t||!r.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!D(t,"captcha"),usesRateLimit:!!D(t,"rateLimit")}},qd=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},ke={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Wd=e=>{const t=qd(e),s=t?b(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=Ud(t);return{...ke,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in Os?{...ke,[Os[s]]:!0}:ke},Hd=e=>{const t={...ke};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=Wd(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},jd=new Set(["insert","insertMany","insertManyUnsafe","replace"]),Gd=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!jd.has(t.getName()))return!1;const s=t.getExpression();if(!$(s))return!1;const i=e.getArguments()[0];return!i||!(r.isStringLiteral(i)||r.isNoSubstitutionTemplateLiteral(i))?!1:zd(i.getLiteralText())},Yd=new Set(["create","publish","publishBatch","runAfter","runAt","send","sendBatch"]),Rs=new Set(["queues","scheduler","topics","workflows"]),Qd=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!Yd.has(t.getName()))return!1;let s=t.getExpression();for(;r.isCallExpression(s)||r.isElementAccessExpression(s)||r.isPropertyAccessExpression(s);){if(r.isPropertyAccessExpression(s)&&Rs.has(s.getName())&&zi(s.getExpression()))return!0;s=s.getExpression()}const n=Ct(s);return n?.length===1&&Rs.has(n[0]??"")},Xd=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return $(s)},Bn=new Set(["generateObject","generateText","streamObject","streamText"]),Jd=e=>{const t=b(e.getExpression());return t!==void 0&&Bn.has(t)},Zd=e=>{const t=b(e.getExpression());if(t===void 0||!Bn.has(t))return!1;const s=e.getArguments()[0];return!s||!r.isObjectLiteralExpression(s)||s.getProperties().some(n=>r.isSpreadAssignment(n))?!1:!D(s,"maxOutputTokens")},eu=new Set(["log","span","trace"]),tu=new Set(["ai"]),su=new Set(["email","mail"]),nu=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","topics","workflows"]),rt=(e,t)=>[...t].some(s=>ze(e,s).length>0),zn=new Set([d.ArrowFunction,d.FunctionDeclaration,d.FunctionExpression,d.GetAccessor,d.MethodDeclaration,d.SetAccessor]),iu=new Set(["every","filter","flatMap","forEach","map","some"]),ru=new Set(["all","allSettled","race"]),$n=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(iu.has(n))return t;const i=s.getExpression();if(r.isIdentifier(i)&&i.getText()==="Promise"&&ru.has(n))return t},ou=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(zn.has(t.getKind())){const s=$n(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},au=e=>{let t=e.getParent();for(;t!==void 0;){if(r.isCallExpression(t)&&t.getExpression().getText()==="Promise.allSettled")return!0;if(zn.has(t.getKind())){if(t=$n(t),t===void 0)return!1;continue}t=t.getParent()}return!1},cu=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 g=u.getTryBlock().getDescendantsOfKind(d.CallExpression).some(p=>{const x=p.getExpression();return r.isIdentifier(x)&&x.getText()===l&&r.isAwaitExpression(p.getParent())}),f=u.getCatchClause();return g&&f!==void 0&&f.getDescendantsOfKind(d.ThrowStatement).length>0})},lu=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}},du=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}},uu=e=>{let t=!1,s=!0;for(const n of[...nu].flatMap(i=>ze(e,i))){const i=du(n);i&&(t=!0,!ou(i)&&!lu(i)&&!cu(i)&&!au(i)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},fu=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"}),Fs="lunora-advisor-exempt",gu=/^[\s*/]+/u,pu=/[\w-]/u,mu=e=>{const s=(e.getFirstAncestorByKind(d.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
2
+ `);for(const n of s.split(`
3
+ `)){const i=n.replace(gu,"");if(!i.startsWith(Fs))continue;const o=i.slice(Fs.length);if(pu.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:""}},hu=e=>{const[t]=e.getArguments();if(t){if(r.isObjectLiteralExpression(t)){const s=D(t,"handler");return s?r.isPropertyAssignment(s)?s.getInitializer():r.isShorthandPropertyAssignment(s)?s.getNameNode():r.isMethodDeclaration(s)?s:void 0:void 0}return t}},vu=(e,t)=>{const s=hu(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)},Eu=e=>{let t=!1,s=!1,n=!1,i=!1,o=!1;for(const l of e.getDescendantsOfKind(d.CallExpression))if(Gd(l)&&(o=!0),Qd(l)&&(t=!0),Xd(l)&&(i=!0),Jd(l)&&(s=!0),Zd(l)&&(n=!0),o&&t&&i&&n)break;const{handlesErrors:a,reachesOutbound:c}=uu(e);return{callsMail:rt(e,su),emitsEvent:rt(e,eu),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||rt(e,tu),throwsBareError:fu(e),unboundedAiGeneration:n,usesInsertManyUnsafe:i,writesUserTable:o}},xu=(e,t)=>{const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const n=G(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const i=n.receiver?Hd(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},o=vu(e,s);return{...o?Eu(o):{},...mu(e),...i,analyzableBody:o!==void 0,exportName:V(e)??e.getName(),file:t,hasEmailArg:Vd(s,n.receiver),kind:n.kind,visibility:n.visibility}},Su=(e,t)=>{const s=[];for(const n of j(e)){const i=xu(n,t);i&&s.push(i)}return s},Au=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Su(i,I(t,n)))}return s},yu=new Set(["dbRateLimit","rateLimit"]),bu=e=>r.isArrowFunction(e)?e.getBody():e,Nu=e=>{if(!r.isArrowFunction(e))return;const t=e.getParameters()[0]?.getNameNode();return t!==void 0&&r.isIdentifier(t)?t:void 0},Vn=e=>{const t=e.getParent();return r.isPropertyAccessExpression(t)&&t.getExpression()===e&&t.getName()==="args"},Un=(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)})},wu=(e,t)=>H(e)||t!==void 0&&Un(e,t).some(s=>Vn(s)),Pu=(e,t)=>t===void 0?te(e):Un(e,t).some(s=>!Vn(s)),Iu=(e,t)=>{const s=b(e.getExpression());if(s===void 0||!yu.has(s))return;const n=C(Js(e.getArguments()[2]),"key");if(!n)return;const i=bu(n),o=Nu(n);if(!(!wu(i,o)||Pu(i,o)))return{callee:s,scope:v(e),file:t,limitName:Xs(e),line:e.getStartLineNumber()}},Cu=(e,t)=>T(e,t,Iu),Tu=new Set(["findFirst","findFirstOrThrow","findMany","findUnique","get"]),Ou=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!Tu.has(t.getName()))return;const s=t.getExpression();if($(s)){const n=e.getArguments()[0];return n&&r.isStringLiteral(n)?n.getLiteralText():""}if(r.isPropertyAccessExpression(s)&&$(s.getExpression()))return s.getName()},ku=e=>{let t=e;for(;r.isCallExpression(t);){const s=t.getExpression();if(!r.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&$(s.getExpression())){const n=t.getArguments()[0];return n&&r.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},Ru=e=>{let t=h(e)??e;for(;r.isAwaitExpression(t);)t=h(t.getExpression())??t.getExpression();return t},qn=(e,t=!1)=>{const s=Ru(e);if(r.isIdentifier(s)){if(t)return;const n=W(s);return n===void 0?void 0:qn(n,!0)}if(r.isCallExpression(s))return Ou(s)??ku(s)},Fu=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},Lu=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!r.isCallExpression(s))return[];const n=G(s);if(n?.kind!=="query")return[];const i=An(s);if(i===void 0)return[];const o=n.receiver!==void 0&&Ui(n.receiver,"output"),a=n.receiver!==void 0&&an(n.receiver,"use","mask"),c=new Set,l=[];for(const u of Fu(i)){const g=qn(u);g===void 0||c.has(g)||(c.add(g),l.push({exportName:V(e)??e.getName(),file:t,line:u.getStartLineNumber(),table:g,usesMask:a,usesOutput:o,visibility:n.visibility}))}return l},Du=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=I(t,n);for(const a of j(i))s.push(...Lu(a,o))}return s},Mu=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(A(s));return t},_u=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&r.isCallExpression(s)?G(s):void 0;if(!n)return[];const i=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=dn(o);if(a===void 0)continue;const c=Mu(C(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},Ku=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=I(t,n);for(const a of j(i))s.push(..._u(a,o))}return s},z=(e,t)=>`${e}:${t}`,Ls=(e,t,s,n)=>s===void 0?void 0:{endLine:e.getEndLineNumber(),exported:n,file:t,name:s,node:e,startLine:e.getStartLineNumber()},Bu=(e,t)=>[...X(e,t,d.FunctionDeclaration,(s,n)=>s.getParent().getKind()===d.SourceFile?Ls(s,n,s.getName(),s.isExported()):void 0),...X(e,t,d.VariableDeclaration,(s,n)=>{const i=s.getVariableStatement();return i?.getParent().getKind()===d.SourceFile?Ls(i,n,s.getName(),i.isExported()):void 0})],zu=(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))},$u=e=>`${e.table}|${e.method}|${e.fields?.join(",")??"*"}`,Vu=(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($u(n),{fields:n.fields,method:n.method,table:n.table})}return s},Uu=(e,t,s)=>e.node.getDescendantsOfKind(d.CallExpression).map(n=>zu(n,t,s)).filter(n=>n!==void 0),qu=(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)}},Wu=(e,t,s)=>{const n=new Map(e.map(a=>[z(a.file,a.name),a])),i=new Map(e.map(a=>[`${Ot(a.file)}:${a.name}`,a])),o=new Map(e.map(a=>[z(a.file,a.name),Uu(a,n,t)]));return qu(s,n,i,o),o},Hu=(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},ju=(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))??[])Hu(t.get(z(i.file,i.name)),t.get(z(o.file,o.name)))&&(n=!0)}},Gu=(e,t,s,n)=>{const i=Bu(e,t),o=Vu(i,s);return ju(i,o,Wu(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})))},Me=e=>{if(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(r.isBinaryExpression(e)&&e.getOperatorToken().getKind()===d.PlusToken){const t=Me(e.getLeft()),s=Me(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},Yu=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&&Me(t)!==void 0},Qu=e=>{const t=e.getParent();if(t!==void 0){if(r.isVariableDeclaration(t)||r.isPropertyAssignment(t)||r.isPropertySignature(t))return A(t);if(r.isBinaryExpression(t)&&t.getOperatorToken().getKind()===d.EqualsToken)return t.getLeft().getText()}},Xu=(e,t,s)=>lr(e)?!ki(s)&&dr(Qu(t)):!0,Ju=(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(Yu(o))continue;const a=Me(o);if(a===void 0)continue;const c=ar(a);if(c===void 0||!Xu(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:cr(a)}))}return s},Zu=(e,t)=>{const s=[];for(const n of S(t,{includeSkipped:!0})){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ju(i,I(t,n)))}return s},ef=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&r.isCallExpression(s)?G(s):void 0;if(!n)return[];const i=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=dn(o);if(a===void 0)continue;const c=C(a.options,"includeDeleted");if(c===void 0)continue;const l=r.isTrueLiteral(c),u=!l&&H(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},tf=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=I(t,n);for(const a of j(i))s.push(...ef(a,o))}return s},sf=new Set(["query","unsafe"]),nf=e=>!r.isPropertyAccessExpression(e)||!sf.has(e.getName())?!1:q(e.getExpression(),["sql"]),rf=e=>r.isBinaryExpression(e)||r.isTemplateExpression(e),of=(e,t)=>{if(!nf(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!rf(s)))return{file:t,line:s.getStartLineNumber(),scope:v(e)}},af=(e,t)=>T(e,t,of),cf=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],lf=e=>{for(const[t,s]of cf)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},df=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of i.getImportDeclarations()){const a=o.getModuleSpecifierValue(),c=lf(a);c!==void 0&&s.push({file:I(t,n),line:o.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},uf=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),ff=(e,t,s=[])=>{const n=Ue(e,t,{argIndex:0,matchReceiver:i=>i==="ctx.storage"||i.startsWith("ctx.storage."),methods:uf,requireUnmodifiedReach:!0});return It(n,s)},gf=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),pf=e=>e&&r.isNumericLiteral(e)?Number(e.getText()):void 0,mf=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=A(i);t.push(o),o==="expiresInSeconds"&&(s=pf(i.getInitializer()));continue}(r.isShorthandPropertyAssignment(i)||r.isMethodDeclaration(i))&&t.push(A(i))}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},hf=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName(),s=gf.get(t);return s===void 0?void 0:nn(e.getExpression(),i=>i==="ctx.storage"||i.startsWith("ctx.storage."))?{method:t,optionsIndex:s}:void 0},vf=(e,t)=>{const s=hf(e.getExpression());if(s!==void 0)return{scope:v(e),file:t,line:e.getStartLineNumber(),method:s.method,...mf(e.getArguments()[s.optionsIndex])}},Ef=(e,t)=>T(e,t,vf),xf=e=>r.isDoStatement(e)||r.isForInStatement(e)||r.isForOfStatement(e)||r.isForStatement(e)||r.isWhileStatement(e),Wn=e=>{const t=e.getLabel()?.getText(),s=i=>t!==void 0?r.isLabeledStatement(i)&&i.getLabel().getText()===t:xf(i)||r.isBreakStatement(e)&&r.isSwitchStatement(i);let n=e.getFirstAncestor(i=>Z(i)||s(i));if(!(n===void 0||Z(n))){for(;r.isContinueStatement(e)&&r.isLabeledStatement(n);)n=n.getStatement();return n}},Dt=(e,t)=>y(e.getFirstAncestor(s=>y(s,t)||Z(s)),t),Sf=(e,t)=>y(e,t)||e.getFirstAncestor(s=>y(s,t))!==void 0,Hn=(e,t)=>{if(r.isReturnStatement(e)||r.isThrowStatement(e))return y(e,t)||Dt(e,t);if(r.isBreakStatement(e)||r.isContinueStatement(e)){const s=Wn(e);return s!==void 0&&!Sf(s,t)}return!1},jn=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)],Af=e=>jn(e).some(t=>Hn(t,e)),yf=e=>{const t=r.isCallExpression(e)?e.getExpression():void 0;return r.isPropertyAccessExpression(t)&&t.getName()==="throwIfAborted"},bf=e=>jn(e).some(t=>Hn(t,e)||r.isBreakStatement(t)&&y(Wn(t),e))||e.getDescendantsOfKind(d.CallExpression).some(t=>yf(t)&&Dt(t,e)),Nf=e=>e.getDescendantsOfKind(d.YieldExpression).some(t=>Dt(t,e)),wf=e=>r.isDoStatement(e)||r.isWhileStatement(e)?e.getExpression():e.getCondition(),Pf=e=>r.isDoStatement(e)?"do":r.isWhileStatement(e)?"while":"for",ot=(e,t)=>{const s=wf(e);if(!(s===void 0||r.isTrueLiteral(h(s)))||bf(e)||Nf(e))return;const i=v(e);if(!(i.kind==="module"&&e.getFirstAncestor(Z)!==void 0))return{file:t,kind:Pf(e),line:e.getStartLineNumber(),scope:i}},If=(e,t)=>[...X(e,t,d.WhileStatement,ot),...X(e,t,d.ForStatement,ot),...X(e,t,d.DoStatement,ot)].toSorted((s,n)=>s.file.localeCompare(n.file)||s.line-n.line),Cf=new Set(["when","where"]),at=new Set(["definePolicy","defineShape"]),Tf=e=>{if(!r.isCallExpression(e))return;const t=e.getExpression();if(r.isPropertyAccessExpression(t)){const n=t.getName();return at.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 at.has(i)?i:void 0}const s=t.getText();return at.has(s)?s:void 0},Of=e=>r.isObjectLiteralExpression(e)&&e.getProperties().length===0,Gn=e=>{if(e!==void 0){if(r.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===d.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Of(e))return"empty-object";if(r.isParenthesizedExpression(e))return Gn(e.getExpression())}},Mt=e=>e.getAncestors().find(t=>r.isArrowFunction(t)||r.isFunctionExpression(t)||r.isFunctionDeclaration(t)),kf=e=>e.getDescendantsOfKind(d.ReturnStatement).filter(t=>Mt(t)===e),Yn=e=>e.getDescendantsOfKind(d.ConditionalExpression).filter(t=>Mt(t)===e),Rf=e=>{const t=kf(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(d.IfStatement)!==void 0)||Yn(e).length>0},Ff=e=>e.getDescendantsOfKind(d.IfStatement).filter(t=>Mt(t)===e),Nt=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()==="",Lf=(e,t)=>Nt(e)||Nt(t),Df=new Map([[d.EqualsEqualsEqualsToken,"positive"],[d.EqualsEqualsToken,"positive"],[d.ExclamationEqualsEqualsToken,"negative"],[d.ExclamationEqualsToken,"negative"]]),Ds=e=>!Nt(e)&&(r.isLiteralExpression(e)||e.getKind()===d.TrueKeyword),Mf=(e,t,s)=>{const n=Df.get(e);if(n!==void 0)return Lf(t,s)?n==="positive"?"negative":"positive":Ds(t)||Ds(s)?void 0:n},me=e=>{if(r.isParenthesizedExpression(e))return me(e.getExpression());if(r.isPrefixUnaryExpression(e)&&e.getOperatorToken()===d.ExclamationToken)return"negative";if(r.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=Mf(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===d.AmpersandAmpersandToken||t===d.BarBarToken){const n=me(e.getLeft()),i=me(e.getRight());return n===i?n:"indeterminate"}}return r.isIdentifier(e)||r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e)||r.isCallExpression(e)?"positive":"indeterminate"},Ms=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}}},_f=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(d.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Kf=e=>r.isReturnStatement(e)?e.getExpression()??e:e,Bf=e=>{const t=[];for(const s of Yn(e)){const n=me(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of Ff(e)){const n=me(s.getExpression());if(n==="indeterminate")continue;const i=n==="negative"?Ms(s.getThenStatement()):Ms(s.getElseStatement())??_f(s);i!==void 0&&t.push(Kf(i))}return t},zf=e=>{for(const t of e.getAncestors())if(r.isVariableDeclaration(t)){const s=t.getNameNode();if(r.isIdentifier(s))return s.getText()}return"<anonymous>"},$f=(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)||!Cf.has(A(o)))continue;const a=o.getInitializer();if(!(!a||!(r.isArrowFunction(a)||r.isFunctionExpression(a)))&&Rf(a))for(const c of Bf(a)){const l=Gn(c);l!==void 0&&i.push({exportName:zf(e),file:s,form:l,key:A(o),line:c.getStartLineNumber(),owner:t})}}return i},Vf=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=Tf(n);i!==void 0&&s.push(...$f(n,i,t))}return s},Uf=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Vf(i,I(t,n)))}return s},qf=new Set(["query","upsert","upsertNow"]),Wf=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();if(qf.has(t))return q(e.getExpression(),["vectors"])?t:void 0},Hf=(e,t)=>{const s=Wf(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const i=C(n,"namespace");if(!(!i||!H(i)||te(i)))return{scope:v(e),file:t,line:e.getStartLineNumber(),method:s}},jf=(e,t)=>T(e,t,Hf),Gf=(e,t,s)=>{const{callSites:n,containers:i,crons:o,functions:a,modules:c,mutators:l,queues:u,schema:g,shapes:f,wranglerVariables:p,workflows:x}=s;return Ni({adminRoutes:ko(e,t),aiRawRuns:zo(e,t),aiToolSideEffects:Xo(e,t),argumentDerivedFetches:ea(e,t),argumentValidators:Ea(e,t),authApiCalls:Gi(e,t),authConfigs:Ca(e,t),browserUrlAccesses:Ra(e,t),callEdges:n.callEdges,configCalls:za(e,t),containerKeyAccesses:Va(e,t),containerOverrides:Ga(e,t),containers:i,cronTargets:o.flatMap(k=>k.functionPath===void 0?[]:[k.functionPath]),exportSinks:Ja(e,t),staleMigrationImports:df(e,t),failOpenGuards:nc(e,t),flagReads:cc(e,t),flagSecurityDefaults:fc(e,t),geoIndexUsages:mc(e,t),httpActionGuards:Ic(e,t),httpHeaderWrites:_c(e,t),hyperdriveCalls:Yi(e,t),identityClaimReads:Gc(e,t),imageDeliveryUrlAccesses:Qc(e,t),inserts:n.inserts,kvKeyAccesses:Jc(e,t,a),mailRecipientAccesses:nl(e,t),maskProcedures:Qi(e,t),maskStrategies:ol(e,t),mutatorWrites:fl(e,t),nondeterministicCalls:tr(e,t),normalizeIdAuthorizations:Il(e,t),notifyCalls:nr(e,t),notifyConfig:sr(e,t),mutators:l,ownerFieldWrites:yd(e,t,a,l),unrestrictedWhereBranches:Uf(e,t),paymentWebhooks:Id(e,t),privilegedDispatches:Kd(e,t),procedureProtections:Au(e,t),queries:n.queries,queues:u,r2sqlCalls:ir(e,t),ratelimitKeySelectors:Cu(e,t),rawRowReturns:Du(e,t),relationLoads:Ku(e,t),rlsProcedures:rr(e,t),schema:g,secretLiterals:Zu(e,t),modules:c,shapes:f,softDeleteReads:tf(e,t),sqlInterpolations:af(e,t),storageKeyAccesses:ff(e,t,a),storageUploads:Ef(e,t),tableWrites:n.tableWrites,rowEffects:Gu(e,t,n.tableWrites,n.callEdges),unboundedLoops:If(e,t),vectorNamespaceAccesses:jf(e,t),workflowCalls:n.workflowCalls,workflows:x,wranglerVariables:p})},Yf=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"}),Qf=(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=>Yf(i))]},Xf=()=>({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"}),Jf=e=>e.metadata.accepted!==void 0||e.name==="advisor_accept_unused"||e.name==="advisor_accept_invalid",_s={error:"ERROR",info:"INFO",warn:"WARN"},Ks={ERROR:2,INFO:0,WARN:1},Zf=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"}),eg=(e,t)=>{const{advisor:s}=cn(e);if(s===void 0||s.minSeverity===void 0&&s.unreadable!==!0)return[...t];const{minSeverity:n}=s,i=n!==void 0&&Object.hasOwn(_s,n)?_s[n]:void 0;return i===void 0?[...t,Zf(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=>Jf(o)||Ks[o.level]>=Ks[i])},tg=(e,t)=>{const{advisor:s}=cn(e),n=Qf(t,s?.accept??[]);return eg(e,s?.acceptUnreadable===!0?[...n,Xf()]:n)},sg={call:"function",enqueue:"queue",invoke:"service",publish:"topic",schedule:"function"},ng="crons",ig=gr.replace(/\.ts$/u,""),ae=(e,t)=>`${Ot(e)}:${t}`,ct=(e,t,s)=>t===""?{reason:`the ${s} is not a string literal`}:{to:`${e}:${t}`},rg=e=>[...e.callEdges.map(t=>{const s=t.target===void 0?{reason:t.reason??"unreadable target"}:{to:`${sg[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,...ct("table",t.table,"table name")})),...[...e.inserts,...e.tableWrites].map(t=>({file:t.file,kind:"write",line:t.line,scope:t.scope,...ct("table",t.table,"written table")})),...e.workflowCalls.map(t=>({file:t.file,kind:"start",line:t.line,scope:t.scope,...ct("workflow",t.workflow,"workflow name")}))],og=e=>e.untracked===!0?"inside a helper only code outside any export calls":"inside a non-exported helper",ag=e=>{const{scope:t}=e;switch(t.kind){case"export":return[{...e,exportName:t.name}];case"helper":return t.callers.length===0?[{...e,unattributed:og(t)}]:t.callers.map(s=>({...e,exportName:s}));default:return[{...e,unattributed:"at module scope"}]}},cg=e=>rg(e).flatMap(t=>ag(t)),lg=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:ng,from:`cron:${t.name}`,kind:"trigger",line:0,...i===void 0?{reason:"the cron has no target"}:{to:i}}})],dg=e=>new Map(e.flatMap(t=>t.tables.map(s=>[s,t.name]))),fe=(e,t)=>t===void 0?e:{...e,module:t},ug=e=>{const t=new Map,s=new Map,n=dg(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(fe({detail:c.kind,id:`function:${l}`,kind:"function",name:u},Pe(e.modules,c.filePath)),l)}for(const c of e.httpRoutes){const l=ae(c.filePath,c.exportName);o(fe({id:`http:${l}`,kind:"http",name:`${c.method} ${c.path}`},Pe(e.modules,c.filePath)),l)}for(const c of e.schema.tables)o(fe({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(fe({...l,id:`queue:${c.exportName}`,kind:"queue",name:c.exportName},Pe(e.modules,c.filePath)),ae(c.filePath,c.exportName)),a(c.handlerSite,`queue:${c.exportName}`)}for(const c of e.topics)o(fe({id:`topic:${c.exportName}`,kind:"topic",name:c.exportName},Pe(e.modules,c.filePath)));for(const c of e.workflows)o({id:`workflow:${c.exportName}`,kind:"workflow",name:c.exportName},ae(ig,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}},fg=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:fg(e.exportName)},pg=(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`}},lt=e=>`${e.from}|${e.kind}|${e.to}`,mg=e=>`${e.file}|${String(e.line)}|${e.kind}|${e.reason}`,hg=e=>{const{nodes:t,sites:s}=ug(e),n=new Map,i=new Map;for(const o of[...lg(e),...cg(e)]){const a=pg(o,s,t);if("drawn"in a)for(const c of a.drawn)n.set(lt(c),c);else{const c={file:o.file,kind:o.kind,line:o.line,reason:a.reason};i.set(mg(c),c)}}return{edges:[...n.values()].toSorted((o,a)=>lt(o).localeCompare(lt(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}},vg=e=>`${hr}export const architecture = ${mr(e,"Record<string, unknown>")};
4
+ `,Bs=(e,t="api")=>{const s=new Map;for(const n of e){const i=Ot(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})}}},Eg=(e,t={})=>{const{hasVectors:s=!0,scheduler:n=!1,storage:i=!1,usage:o}=t,a=[];e.tables.some(c=>un(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=>fn(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?[]:Er)c.requiredPackage!==void 0&&o?.[c.key]===!0&&a.push({name:c.requiredPackage,reason:`\`ctx.${c.contextProperty??c.key}\` usage makes \`_generated/\` import \`${c.moduleSpecifier}\``});return a.filter((c,l)=>a.findIndex(u=>u.name===c.name)===l)},xg=(e,t,s={})=>{if(t===void 0)return;const n=Eg(e,s).filter(o=>!t.has(o.name));if(n.length===0)return;const i=n.map(o=>` - ${o.name} — ${o.reason}`).join(`
5
+ `);throw new Q("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
6
+ ${i}
7
+
8
+ Install them with your package manager, then re-run codegen.`)},Sg="env.ts",Ag=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(r.isImportSpecifier(s))return $e(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},yg=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&&$e(n.getModuleSpecifierValue())}return!1},bg=e=>{if(r.isIdentifier(e))return Ag(e);if(r.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&r.isIdentifier(t)&&yg(t)}return!1},Ng=e=>{const t=[];for(const s of e.getVariableDeclarations()){const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!bg(n.getExpression()))continue;const o=s.getNameNode();if(!r.isIdentifier(o)){if(s.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw Ee(o,"defineEnv exports must be plain named exports (no destructuring)")}const a=sn(s,"member");a!==void 0&&t.push({exportName:a})}return t},wg=(e,t)=>{const s=E(t,Sg);if(!L(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=Ng(n);if(i.length!==0){if(i.length>1)throw Ee(n,`lunora/env.ts declares ${i.length.toString()} defineEnv() contracts (${i.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Pg=new Set(["allowedHosts","deniedHosts","interceptHttps"]),Ig=(e,t)=>{const s=h(t);if(s===void 0||!r.isIdentifier(s))return s;const n=s.getText();return h(e.getDescendantsOfKind(d.VariableDeclaration).find(i=>i.getName()===n)?.getInitializer())},Cg=(e,t)=>e!==void 0&&r.isObjectLiteralExpression(e)&&e.getProperties().some(s=>{if(r.isShorthandPropertyAssignment(s))return t.has(A(s));if(!r.isPropertyAssignment(s)||!t.has(A(s)))return!1;const n=h(s.getInitializer())?.getText();return n!=="false"&&n!=="undefined"}),Tg=new Set(["durable"]),Og=new Set(["rollback"]),kg=e=>{const t=e.getExpression();return r.isPropertyAccessExpression(t)?t.getName():t.getText()},Rg=new Map([["defineContainer",{keys:Pg,signal:"containerEgressPolicy"}],["defineStep",{keys:Og,signal:"workflowRollback"}],["stream",{keys:Tg,signal:"durableStreams"}]]),Fg=(e,t)=>{const s=Rg.get(kg(t));if(s!==void 0)return t.getArguments().some(n=>Cg(Ig(e,n),s.keys))?s.signal:void 0},Lg=(e,t)=>{const s={containerEgressPolicy:!1,durableStreams:!1,secrets:!1,workflowRollback:!1};for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.secrets||(s.secrets=br(i).has("secrets"));for(const o of i.getDescendantsOfKind(d.CallExpression)){const a=Fg(i,o);a!==void 0&&(s[a]=!0)}if(Object.values(s).every(Boolean))break}return s},Dg="createWorker",Mg="extend",zs=e=>e!==void 0&&(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))?e.getLiteralValue():void 0,$s=e=>{const t=[],s=zs(C(e,"backupCron"));s!==void 0&&t.push(s);const n=C(e,"crons");if(n===void 0||!r.isObjectLiteralExpression(n))return t;for(const i of n.getProperties()){if(!r.isPropertyAssignment(i)&&!r.isMethodDeclaration(i))continue;const o=zs(i.getNameNode());o!==void 0&&t.push(o)}return t},_g=e=>{const t=b(e.getExpression()),[s]=e.getArguments();if(s===void 0)return[];if(t===Dg)return r.isObjectLiteralExpression(s)?$s(s):[];if(t!==Mg||!(r.isArrowFunction(s)||r.isFunctionExpression(s)))return[];const n=Qs(s.getBody());return n===void 0?[]:$s(n)},Kg=(e,t)=>{const s=[];for(const{filePath:n}of Ke(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of i.getDescendantsOfKind(d.CallExpression))s.push(..._g(o))}return[...new Set(s)]},Qn=e=>{if(e.kind==="id")return e.tableName;if(!(e.kind!=="array"&&e.kind!=="optional"))return e.inner===void 0?void 0:Qn(e.inner)},Bg=e=>{const t=new Set(e.tables.map(s=>s.name));return e.tables.some(s=>Object.values(s.shape).some(n=>{const i=Qn(n);return i!==void 0&&t.has(i)}))},zg=(e,t)=>{const s=new Map,n=new Map;for(const i of e)s.set(i.name,`workflow "${i.exportName}"`),n.set(i.className,`workflow "${i.exportName}"`);for(const i of t){const o=s.get(i.name);if(o!==void 0)throw new Q("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${i.name}": produced by both ${o} and agent "${i.exportName}". Workflow and agent names share one account-wide namespace and must be unique together.`,{status:500});const a=n.get(i.className);if(a!==void 0)throw new Q("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${i.className}": produced by both ${a} and agent "${i.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},$g=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:i}=e,o=Vc(s,t),a=wg(s,t),c=pr(s,t),{queues:l,topics:u}=Pr(s,t),g=Cr(n),f=Sr(s,t);zg(c,f);const p=Ar(s,t),x=Tr(s,t),k=yr(s,t,c,f),Y=Kg(s,t),F=Lg(s,t),N=Ir(s,t),B=Nr(s,t);B.browser=B.browser||N.usesSandboxBrowser;const M=Or(B,gn(n,e.target),{agents:f.length>0,commitOrderedTables:i.tables.some(R=>R.commitOrdered===!0),cronTriggers:k.length>0,crossShardFanout:i.tables.some(R=>Fr(R)),containerEgressPolicy:F.containerEgressPolicy,containerRuntimeScheduling:p.some(R=>R.schedulingPolicy==="durable_object"),containerSandboxTools:p.some(R=>R.sandbox===!0),durableStreams:F.durableStreams,globalTables:i.tables.some(R=>R.shardMode==="global"),queues:l.length>0,relationGraph:Bg(i),secrets:F.secrets,services:g.length>0,topics:u.length>0,vectorStore:i.vectorIndexes.length>0,workerLoaders:N.usesSandboxLoader,workflowRollback:F.workflowRollback,workflowSchedules:c.some(R=>R.schedules!==void 0)}),w=M.usage,se=xr(w),ne=M.signals.vectorStore!==!1,le=M.signals.services===!1?[]:g,ie=wr(n),xe=ie??new Set,U=xe.has("lunorash");xg(i,ie,{hasVectors:ne,scheduler:w.scheduler||k.length>0,storage:w.storage||x.rules.length>0||Object.keys(pn(i)).length>0,usage:w});const _=L(E(t,"flags.ts")),K=L(E(t,"notify.ts"));return{agents:f,capabilities:se,containers:p,crons:k,dataModelContent:_r(i),declaredDependencies:ie,dependencies:xe,entryCronTriggers:Y,env:a,featureUsage:w,hasFlags:_,hasNotify:K,identity:o,platformGate:{...M,diagnostics:[...kr(n,e.target),...M.diagnostics]},queues:l,serverContent:Dr({agents:f,capabilities:se,containers:p,env:a,hasVectors:ne,hasFlags:_,hasNotify:K,identity:o,queues:l,schema:i,services:le,storageRuleBuckets:x.rules.map(R=>R.bucket),topics:u,useUmbrella:U,workflows:c}),services:le,storageRulesMetadata:x,topics:u,usesSandbox:N.usesSandboxBrowser||N.usesSandboxContainer||N.usesSandboxFs,useUmbrella:U,workflows:c}},Xn=(e,t)=>{if(!r.isPropertyAccessExpression(e))return;const s=e.getExpression();if(!r.isPropertyAccessExpression(s))return;const n=s.getExpression();return r.isPropertyAccessExpression(n)&&n.getName()===t?s.getName():void 0},Vg=e=>{if(!r.isPropertyAccessExpression(e))return!1;const t=e.getExpression();return r.isPropertyAccessExpression(t)&&t.getName()==="scheduler"||r.isIdentifier(t)&&t.getText()==="scheduler"},Ug=new Map([["publish",{kind:"publish",surface:"topics"}],["publishBatch",{kind:"publish",surface:"topics"}],["send",{kind:"enqueue",surface:"queues"}],["sendBatch",{kind:"enqueue",surface:"queues"}]]),qg=/^[\w$]+:[\w$]+$/u,Wg=(e,t)=>{const s=tn(t);return s!==void 0?{kind:"call",target:s}:e!=="run"&&t!==void 0?{kind:"call",reason:'the function reference is not a static api.* / internal.* chain or a "namespace:export" key'}:void 0},Vs=e=>{const t=[];for(const s of e.getProperties()){if(!r.isPropertyAssignment(s)&&!r.isShorthandPropertyAssignment(s))return;t.push(s.getName())}return t},Hg=e=>{if(e===void 0)return[];if(r.isObjectLiteralExpression(e))return Vs(e);if(r.isIdentifier(e)){const t=e.getSymbol()?.getDeclarations()[0];if(r.isVariableDeclaration(t)&&t.getVariableStatement()?.getDeclarationKind()===Pi.Const){const s=t.getInitializer();return r.isObjectLiteralExpression(s)?Vs(s):void 0}}},jg=(e,t,s)=>({schedule:{argKeys:Hg(s),...e==="runAfter"&&t!==void 0&&r.isNumericLiteral(t)?{delayMs:t.getLiteralValue()}:{}}}),Gg=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return;const s=t.getName(),[n,i,o]=e.getArguments();if(en.has(s))return Wg(s,n);if((s==="runAfter"||s==="runAt")&&Vg(t)){const l=tn(i)??(r.isStringLiteral(i)&&qg.test(i.getLiteralText())?i.getLiteralText():void 0);return l===void 0?{kind:"schedule",reason:'the scheduled function is not a static api.* / internal.* chain or a "namespace:export" key'}:{kind:"schedule",target:l,...jg(s,n,o)}}const a=Ug.get(s),c=a===void 0?void 0:Xn(t,a.surface);return a===void 0||c===void 0?void 0:{kind:a.kind,target:c}},Yg=new Set([d.AmpersandAmpersandEqualsToken,d.AmpersandAmpersandToken,d.BarBarEqualsToken,d.BarBarToken,d.QuestionQuestionEqualsToken,d.QuestionQuestionToken]),Jn=e=>wi.isOptionalChain(e.compilerNode),Qg=(e,t)=>r.isIfStatement(t)?!y(e,t.getExpression()):r.isWhileStatement(t)||r.isForInStatement(t)||r.isForOfStatement(t)?y(e,t.getStatement()):r.isForStatement(t)?y(e,t.getStatement())||y(t.getIncrementor(),e):r.isCaseClause(t)||r.isDefaultClause(t)||r.isCatchClause(t)?!0:Z(t)?t.getFirstAncestor(Z)!==void 0:r.isConditionalExpression(t)?!y(e,t.getCondition()):r.isBinaryExpression(t)?!y(e,t.getLeft())&&Yg.has(t.getOperatorToken().getKind()):(r.isCallExpression(t)||r.isElementAccessExpression(t))&&Jn(t)?!y(e,t.getExpression()):r.isBlock(t)&&t.getStatements().some(s=>s.getEnd()<=e.getStart()&&Af(s)),Xg=e=>{let t=e,s=e.getParent();for(;s!==void 0&&(r.isAwaitExpression(s)||r.isParenthesizedExpression(s));)t=s,s=s.getParent();const n=r.isVariableDeclaration(s)||r.isBinaryExpression(s)&&y(t,s.getRight())&&s.getOperatorToken().getKind()===d.EqualsToken,i=e.getFirstAncestor(Z);return n||i?.getDescendantsOfKind(d.ThrowStatement).some(o=>o.getStart()>=e.getEnd()&&y(o.getFirstAncestor(Z),i))===!0},Jg=(e,t)=>{if(Jn(e)||t==="schedule"&&Xg(e))return!0;let s=e;for(let n=s.getParent();n!==void 0&&!r.isSourceFile(n);n=n.getParent()){if(Qg(s,n))return!0;s=n}return!1},Us=(e,t,s)=>s===void 0?void 0:{...s,...Jg(e,s.kind)?{conditional:!0}:{},file:t,line:e.getStartLineNumber(),scope:v(e)},Zg=(e,t)=>[...T(e,t,(s,n)=>Us(s,n,Gg(s))),...X(e,t,d.PropertyAccessExpression,(s,n)=>{const i=Xn(s,"services");return Us(s,n,i===void 0?void 0:{kind:"invoke",target:i})})],ep=new Set(["boolean","number","object","string"]),tp=e=>{const t=e.getName();if(!ep.has(t))return;const s=e.getExpression();return q(s,["flags"])||q(s,["flags","details"])?t:void 0},sp=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return;const s=tp(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(r.isStringLiteral(n)||r.isNoSubstitutionTemplateLiteral(n)))return;const i=n.getLiteralValue();return i.length>0?{key:i,type:s}:void 0},np=(e,t)=>{const s=new Map;for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of i.getDescendantsOfKind(d.CallExpression)){const a=sp(o);a&&!s.has(a.key)&&s.set(a.key,a.type)}}return[...s.entries()].map(([n,i])=>({key:n,type:i})).toSorted((n,i)=>n.key.localeCompare(i.key))},ip=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const s=t.getTypeAtLocation(e).getProperty("types");if(!s)return;const n=s.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!n)return;const i=n.getTypeAtLocation(e),o=i.getText(e);if(!o||o==="any"||o==="never"||Kr(o))return;const a=e.getSourceFile().getFilePath();if(Br(i,e,a)){const c=zr(i,e,a,0,new Set);return c===void 0&&$r(o),c}return o},rp=e=>e.getProperties().some(t=>{if(r.isSpreadAssignment(t))return!0;const s=qi(t.getNameNode());return s===void 0||s==="namespace"}),op=(e,t)=>{for(const{filePath:s}of Ke(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const i of n.getDescendantsOfKind(d.CallExpression)){const o=i.getExpression(),[a]=i.getArguments();if(!(!r.isPropertyAccessExpression(o)||o.getName()!=="auth"||a===void 0)&&(!r.isObjectLiteralExpression(a)||rp(a)))return i}}},ap="https://lunora.sh/docs/concepts/data-residency#pinning-auth-and-voice",cp=(e,t)=>{if(!(e.jurisdiction===void 0||e.jurisdictionPinsAuth===!0||t===void 0))throw Ee(t,`the schema pins Durable Objects to the "${e.jurisdiction}" jurisdiction, and this project also has DO-backed auth (users, sessions, accounts, credentials). Pinning the auth object resolves it to a NEW, EMPTY object: existing users stay in the unpinned one until you copy them across (${ap}). Acknowledge with \`.jurisdiction("${e.jurisdiction}", { pinAuth: true })\`, deploy, then run the copy. For D1-mode auth the acknowledgement changes nothing.`,{code:"JURISDICTION_MOVE",status:422})},lp=e=>r.isPropertyAssignment(e)||r.isMethodDeclaration(e)||r.isGetAccessorDeclaration(e)?r.isComputedPropertyName(e.getNameNode()):!1,dp=e=>r.isPropertyAssignment(e)||r.isShorthandPropertyAssignment(e)||r.isMethodDeclaration(e)||r.isGetAccessorDeclaration(e)?lp(e):!0,Zn=(e,t=!1)=>{for(const s of e.getProperties()){if(dp(s))return!0;if(t)continue;if(!r.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!r.isObjectLiteralExpression(n)||Zn(n,!0))return!0}return!1},up=(e,t)=>{for(const s of S(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:i}of mn(n))for(const o of Tt(i)){const a=o.getArguments()[0];if(a!==void 0&&(!r.isObjectLiteralExpression(a)||Zn(a)))return!0}}return!1},fp=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const i=Re(n);if(i===void 0||!r.isPropertyAssignment(n))continue;const o=n.getInitializer();if(!(!o||!r.isObjectLiteralExpression(o)))for(const a of o.getProperties()){const c=Re(a);c!==void 0&&s.push({column:c,strategy:ln(a),table:i})}}return s},gp=(e,t)=>{const s=new Map;for(const n of S(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:o}of mn(i))for(const a of Tt(o))for(const c of fp(a)){const l=`${c.table}\0${c.column}`;s.has(l)||s.set(l,c)}}return{columns:[...s.values()]}},pp=["providerSubscriptionId","state"],mp=["providerEventId","processedAt"],qs=(e,t)=>t.every(s=>s in e.shape),hp=e=>{const t=e.find(n=>n.name==="payment_subscriptions"),s=e.find(n=>n.name==="payment_events");return t!==void 0&&s!==void 0&&qs(t,pp)&&qs(s,mp)},vp=(e,t)=>{const s=Rr(t.target);return{...s===void 0?{}:{platform:s},analytics:e.analytics||t.dependencies.has("@lunora/bindings"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:t.vectorStoreSupported&&t.vectorIndexCount>0,workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}},Ep=new Set(["delete","hardDelete","patch","replace","restore"]),xp=new Set(["insertMany","insertManyUnsafe","patchWhere"]),Sp=new Set(["delete","deleteMany","hardDelete","insert","insertMany","patch","patchMany","replace","restore","upsert","upsertMany"]),Ws=(e,t)=>{const s=e.getNonNullableType().getProperty("__table")?.getTypeAtLocation(t);if(s===void 0)return[];const n=s.isUnion()?s.getUnionTypes():[s],i=n.map(o=>o.getLiteralValue()).filter(o=>typeof o=="string");return i.length===n.length?i:[]},Ap=(e,t)=>{const s=e.getType();if(t==="deleteMany"||t==="patchMany"){const n=s.getArrayElementType();if(n===void 0)return[];const i=t==="patchMany"?n.getProperty("id")?.getTypeAtLocation(e):n;return i===void 0?[]:Ws(i,e)}return Ws(s,e)},Hs="",yp=(e,t)=>{if(t!=="patch"&&t!=="patchMany")return;const s=e.getArguments()[1];if(s===void 0||!r.isObjectLiteralExpression(s))return;const n=[];for(const i of s.getProperties()){if(!r.isPropertyAssignment(i)&&!r.isShorthandPropertyAssignment(i))return;n.push(i.getName())}return n},bp=(e,t)=>{if(xp.has(e))return{method:e,tables:[t!==void 0&&r.isStringLiteral(t)?t.getLiteralText():Hs]};if(Ep.has(e)||e==="deleteMany"||e==="patchMany"){const s=t===void 0?[]:Ap(t,e);return{method:e,tables:s.length===0?[Hs]:s}}},js=(e,t)=>e===void 0?void 0:{...e,fields:yp(t,e.method)},Np=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression();if($(n))return js(bp(s,e.getArguments()[0]),e);if(Sp.has(s)&&r.isPropertyAccessExpression(n)&&$(n.getExpression()))return js({method:s,tables:[n.getName()]},e)},wp=(e,t)=>T(e,t,(s,n)=>{const i=Np(s);if(i===void 0)return;const o=v(s),a=s.getStartLineNumber();return i.tables.map(c=>({...i.fields===void 0?{}:{fields:i.fields},file:n,line:a,method:i.method,scope:o,table:c}))}),Pp=(e,t,s)=>({cacheKey:`procedure_arguments_unreadable:${e}:${t}`,categories:["SCHEMA"],description:"Codegen reads an argument record statically. One built at runtime — a factory call, or a property off a value it cannot follow — has no literal to read, so the generated `FunctionReference` carries only the arguments it could see while the runtime validator still enforces all of them.",detail:`\`${t}\` in \`${e}\` (line ${s.toString()}) declares arguments codegen could not read, so its generated type is missing some of them.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:s},name:"procedure_arguments_unreadable",remediation:`Declare the arguments as an object literal, or as a \`const\` object literal the chain names — \`const ${t}Args = { … };\` then \`.input(${t}Args)\`. Both resolve; a record returned by a call does not.`,title:"Procedure arguments are missing from the generated type"}),Ip=(e,t)=>{if(t===void 0){const s=e.getArguments()[0];if(s===void 0||!r.isObjectLiteralExpression(s)||D(s,"args")===void 0)return!1}return Rt(e,t).opaque},Cp=(e,t)=>{const s=[],n=(i,o)=>{const a=i.getInitializer();if(a===void 0||!r.isCallExpression(a))return;const c=G(a);c!==void 0&&Ip(a,c.receiver)&&s.push(Pp(t,o,a.getStartLineNumber()))};for(const i of e.getVariableStatements().filter(o=>o.isExported()))for(const o of i.getDeclarations())n(o,o.getName());return s},Tp=(e,t)=>{const s=[];for(const n of S(t)){const i=e.getSourceFile(n);i!==void 0&&s.push(...Cp(i,I(t,n)))}return s.toSorted((n,i)=>n.cacheKey.localeCompare(i.cacheKey))},Op=new Map([["AgentDefinition",{call:"defineAgent({ … })",file:"agents"}],["ContainerDefinition",{call:"defineContainer({ … })",file:"containers"}],["QueueDefinition",{call:"defineQueue({ … })",file:"queues",note:"A dropped queue has no caller to fail — its consumer is simply never wired."}],["RegisteredAction",{call:"action.input({ … }).action(handler)"}],["RegisteredLifecycleHook",{call:"onConnect(handler)",note:"Substitute the hook you called: `onConnect`, `onDisconnect` and `onShardInit` share one type, so codegen cannot tell which you wrote. A dropped hook has no caller to fail — it silently never fires."}],["RegisteredMigration",{call:"defineMigration({ … })",note:"A dropped migration never runs, so `lunora migrate up` reports nothing to do."}],["RegisteredMutation",{call:"mutation.input({ … }).mutation(handler)"}],["RegisteredMutator",{call:"defineMutator({ … })",file:"mutators"}],["RegisteredQuery",{call:"query.input({ … }).query(handler)"}],["RegisteredReactor",{call:"onQueryChange(select, handler)",note:"A dropped reactor has no caller to fail — it silently never runs."}],["RegisteredShape",{call:"defineShape({ … })",file:"shapes"}],["RegisteredStream",{call:"query.input({ … }).stream(handler)"}],["RegisteredWhisperAuthorizer",{call:"onWhisper(handler)",note:"A dropped authorizer has no caller to fail — the whisper topics it was meant to gate silently stay open to every socket on the shard."}],["SubscriptionDefinition",{call:"defineSubscription(topic, { … })",file:"queues",note:"A dropped subscription is never published to — its topic's messages simply never reach it."}],["WorkflowDefinition",{call:"defineWorkflow({ … })",file:"workflows"}]]),_e=({byName:e,byPath:t},s,n)=>t.has(`${s}:${n}`)||e.has(n),ei=e=>!e.isAny(),ti=e=>{const t=e.getType();if(!ei(t))return;const s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName(),n=s===void 0?void 0:Op.get(s);return n===void 0||s===void 0?void 0:{...n,typeName:s}},kp=e=>{const t=e.getInitializer();return t===void 0?!1:r.isCallExpression(t)||r.isIdentifier(t)||r.isPropertyAccessExpression(t)},si={cause:"codegen recognises a registration only when the initializer is the registering call itself, and this one comes from a factory or an alias",remediation:"A factory that returns a registration cannot be read statically — inline it, or export what the factory builds."},Rp=e=>({cause:`codegen reads this kind of registration only from \`lunora/${e}.ts\`, and this is a different module`,remediation:`Move it into \`lunora/${e}.ts\` — the declaration itself is fine.`}),Fp={cause:"it is exported only under a string name that is not an identifier, which the generated `api.ts` and dispatch table cannot address as `<module>.<name>`",remediation:"Export it under an identifier name as well (or instead)."},Lp=new Set(["AgentDefinition","ContainerDefinition","QueueDefinition","RegisteredShape","SubscriptionDefinition","WorkflowDefinition"]),Dp={cause:"it is exported only as `default` or under a reserved word, and this kind's name becomes an import binding and a generated class / binding name, where that is a syntax error",remediation:"Export it under a plain identifier: `export const <name> = …` (an extra `export default <name>` is fine)."},Mp=(e,t,s)=>{if(!t.some(i=>Mi(i)))return Fp;const n=e.getVariableStatement()?.hasExportKeyword()===!0;return Lp.has(s.typeName)&&!n&&!t.some(i=>Jr(i))?Dp:si},ni=(e,t,s,n,i)=>{const{call:o,file:a,note:c,typeName:l}=s,u=a!==void 0&&e!==a?a:void 0,g=u===void 0?i:Rp(u),f=c===void 0?g.remediation:`${c} ${g.remediation}`;return{cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when its initializer is literally the registering call and the module exports it under an identifier name — by the `export` keyword, a local `export { … }`, or `export default`. Written any other way it exists at runtime but never reaches the generated output — `_generated/api.ts` for a procedure, the lifecycle manifest for a hook or reactor — so a caller cannot address it and a hook never fires.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${l}\` but was not registered — ${g.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:l},name:"procedure_not_registered",remediation:u===void 0?`Assign the registration directly: \`export const ${t} = ${o};\`. ${f}`:f,title:"Procedure exists at runtime but is missing from the generated API"}},_p=(e,t,s)=>{const n=[];for(const i of j(e)){const o=r.isIdentifier(i.getNameNode())?gt(i):[i.getName()],c=o.some(u=>_e(s,t,u))||!kp(i)?void 0:ti(i),[l=i.getName()]=o;c!==void 0&&n.push(ni(t,l,c,i.getStartLineNumber(),Mp(i,o,c)))}return n},Kp=(e,t,s)=>{if(_e(s,t,"default"))return[];const n=[];for(const i of e.getExportAssignments().filter(o=>!o.isExportEquals()&&!r.isIdentifier(o.getExpression()))){const o=ti(i.getExpression());o!==void 0&&n.push(ni(t,"default",o,i.getStartLineNumber(),si))}return n},Bp=(e,t,s)=>[..._p(e,t,s),...Kp(e,t,s)],zp=(e,t,s)=>e.getVariableStatements().flatMap(n=>n.getDeclarations()).filter(n=>r.isIdentifier(n.getNameNode())).filter(n=>gt(n).some(i=>_e(s,t,i))).filter(n=>{const i=n.getInitializer();return i!==void 0&&r.isCallExpression(i)&&r.isPropertyAccessExpression(i.getExpression())}).map(n=>{const i=gt(n).find(o=>_e(s,t,o))??n.getName();return{declaration:n,exportName:i,relativePath:t}}),$p=({exportName:e,relativePath:t})=>({cacheKey:"procedure_type_check_unavailable",categories:["SCHEMA"],description:"Codegen cross-checks every export in `lunora/` against its TYPE to catch a procedure the syntactic scan dropped — a factory-assigned export, an alias, a separate `export { … }`. That check needs the type checker to resolve `@lunora/server`; when it cannot, the check reports nothing regardless of what the code does.",detail:`Type resolution for \`lunora/\` is unavailable — the registered procedure \`${e}\` in \`${t}\` types as \`any\`, as does every other one — so codegen cannot tell you when an export is dropped from \`_generated/api.ts\`. A dropped procedure will surface as \`Property '<name>' does not exist\` at its call site instead.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e,filePath:t},name:"procedure_type_check_unavailable",remediation:`Check what codegen sees: \`${e}\` should have a procedure type, not \`any\`. It needs a \`tsconfig.json\` at or above \`lunora/\` — the one codegen finds walking up from there, which is not necessarily the one your editor uses — resolving \`lunorash\` / \`@lunora/server\` to declarations that exist on disk (a workspace dependency has to be built first).`,title:"Codegen cannot type-check `lunora/`, so dropped procedures go unreported"}),Vp=(e,t,s)=>{const n=[],i=[];for(const a of S(t)){const c=e.getSourceFile(a);if(c===void 0)continue;const l=I(t,a);n.push(...Bp(c,l,s)),i.push(...zp(c,l,s))}const[o]=i;return o!==void 0&&i.every(({declaration:a})=>!ei(a.getType()))&&n.push($p(o)),n.toSorted((a,c)=>a.cacheKey.localeCompare(c.cacheKey))},Up=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return r.isPropertyAccessExpression(s)?s.getName()==="workflows":r.isIdentifier(s)&&s.getText()==="workflows"},qp=e=>{const t=e.getArguments()[0];return t&&r.isStringLiteral(t)?t.getLiteralText():""},Wp=(e,t)=>T(e,t,(s,n)=>Up(s)?{file:n,line:s.getStartLineNumber(),scope:v(s),workflow:qp(s)}:void 0),qe=(e,t)=>{L(e)&&Ei(e,"utf8")===t||xi(e,t,"utf8")},Hp=(e,t)=>{if(t===""){ut(e,{force:!0});return}qe(e,t)},jp=(e,t)=>{const s=E(e,"services");if(Object.keys(t).length===0){ut(s,{force:!0,recursive:!0});return}if(L(s))for(const n of Si(s,{recursive:!0,withFileTypes:!0})){const i=E(n.parentPath,n.name);n.isFile()&&t[Ai(e,i)]===void 0&&ut(i)}for(const[n,i]of Object.entries(t))Gs(Ys(E(e,n)),{recursive:!0}),qe(E(e,n),i)},Gp=e=>{try{const t=eo(E(e,"package.json"));return typeof t.version=="string"&&t.version!==""?t.version:void 0}catch{return}},ce=(e,t,s)=>{const n=e.getSourceFile(t);if(n===void 0){e.createSourceFile(t,s,{overwrite:!0});return}n.getFullText()!==s&&n.replaceWithText(s)},dt=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,Yp=(e,t)=>{L(e)||Gs(e,{recursive:!0});const s=[];for(const n of t)n.kind==="services"?(jp(e,n.files),s.push(...Object.keys(n.files))):n.kind==="always"?(qe(E(e,n.name),n.content),s.push(n.name)):(Hp(E(e,n.name),n.content),n.content!==""&&s.push(n.name));return s},Qp=e=>{const t=Gp(e.projectRoot),s=e.wantsArchitecture?e.modules:[],n=so({functions:e.functions,httpRoutes:e.httpRoutes,modules:s,version:t}),i=io({functions:e.functions,modules:s,version:t});return{openApiContent:`${JSON.stringify(n,void 0,2)}
9
+ `,openApiModuleContent:no(n),openRpcContent:`${JSON.stringify(i,void 0,2)}
10
+ `,openRpcModuleContent:ro(i)}},Xp=".lunora-schema.json",Jp=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Zp=(e,t,s)=>{if(s&&e.length>0){const o=e.map(a=>`"${a.exportName}"`).join(", ");throw new Q("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${o}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const o of t.columns){const a=n.get(o.table)??[];a.push(o.column),n.set(o.table,a)}const i=t.columns.length>0;for(const o of e){if(o.table===void 0){if(i)throw new Q("MASK_UNSUPPORTED",`defineShape "${o.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${o.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(o.table);if(a===void 0)continue;const c=a.map(l=>`"${l}"`).join(", ");throw new Q("MASK_UNSUPPORTED",`defineShape "${o.exportName}" replicates table "${o.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},em=8,tm=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,internalPath:i,lunoraDirectory:o,migrations:a,project:c,shapes:l,usesSandbox:u,useUmbrella:g,workflows:f}=e,p=()=>Ur(()=>{const N=qr(c,o),B=er(c,o);return{functions:N,httpRoutes:Wr(c,o),mutators:B}});let{erased:x,value:{functions:k,httpRoutes:Y,mutators:F}}=p();Bs([...k,...F].map(N=>N.filePath)),Bs(Y.filter(N=>N.stream).map(N=>N.filePath),"http-stream");for(let N=1;;N+=1){const B=po({agents:t,functions:k,httpRoutes:Y,mutators:F,useUmbrella:g,workflows:f}),M=bo({agents:t,functions:k,migrations:a,mutators:F,shapes:l,useUmbrella:g,usesSandbox:u}),w=mo({functions:k,useUmbrella:g});if(N>=em||dt(c,s,B)&&dt(c,i,w)&&dt(c,n,M))return{apiContent:B,erased:x,functions:k,functionsContent:M,httpRoutes:Y,internalContent:w,mutators:F};ce(c,s,B),ce(c,i,w),ce(c,n,M),{erased:x,value:{functions:k,httpRoutes:Y,mutators:F}}=p()}},vh=e=>{const t=Jp(),s=t?et.now():0,n=E(e.projectRoot,e.lunoraDirectory??"lunora"),i=E(n,"schema.ts");if(!L(i))throw new Q("INTERNAL",`schema.ts not found at ${i}`);const o=e.project??vr(n);ji(ip);const a=Qr(o,i,e.projectRoot),{agents:c,capabilities:l,containers:u,crons:g,dataModelContent:f,dependencies:p,entryCronTriggers:x,env:k,featureUsage:Y,hasFlags:F,hasNotify:N,identity:B,platformGate:M,queues:w,serverContent:se,services:ne,storageRulesMetadata:le,topics:ie,usesSandbox:xe,useUmbrella:U,workflows:_}=$g({lunoraDirectory:n,project:o,projectRoot:e.projectRoot,schema:a,target:e.target});cp(a,a.jurisdiction===void 0?void 0:op(o,n));const K=E(n,"_generated"),R=E(K,"dataModel.ts"),ii=E(K,"server.ts"),ri=E(K,"api.ts"),oi=E(K,"internal.ts"),ai=E(K,"functions.ts");ce(o,R,f),ce(o,ii,se);const _t=Object.fromEntries(ne.filter(m=>m.rpcEntrypoint!==void 0).flatMap(m=>Object.entries(Mr(m,K))));for(const[m,Ze]of Object.entries(_t))ce(o,E(K,m),Ze);const Se=jr(o,n),re=Xr(o,n),{apiContent:Kt,erased:ci,functions:oe,functionsContent:Bt,httpRoutes:We,internalContent:zt,mutators:He}=tm({agents:c,apiPath:ri,generatedFunctionsPath:ai,internalPath:oi,lunoraDirectory:n,migrations:Se,project:o,shapes:re,useUmbrella:U,usesSandbox:xe,workflows:_}),$t=ur(o,n),je=fr($t,a,[...oe,...We].map(m=>m.filePath)),Ae=$t.length>0,ye=e.lint===!1&&!Ae?void 0:{callEdges:Zg(o,n),inserts:Hr(o,n),queries:Gr(o,n,oe),tableWrites:wp(o,n),workflowCalls:Wp(o,n)},be=e.lint===!1||ye===void 0?void 0:Gf(o,n,{callSites:ye,containers:u,crons:g,functions:oe,modules:je,mutators:He,queues:w,schema:a,shapes:re,workflows:_,wranglerVariables:e.wranglerVariables}),Vt=be===void 0?[]:tg(e.projectRoot,[...yi(be,{source:"static"}),...Vp(o,n,{byName:new Set([..._,...w,...c,...u].map(m=>m.exportName)),byPath:new Set([...oe,...He,...re,...Se].map(m=>`${m.filePath}:${m.exportName}`))}),...Tp(o,n),...Vr(ci,n),...oo(w,e.wranglerQueueProducers)]),li=Yr(o,n),Ut=gp(o,n);Zp(re,Ut,up(o,n));const di=F?np(o,n):[],Ge=M.signals.vectorStore!==!1,de=vp(Y,{containerCount:u.length,cronCount:g.length,dependencies:p,hasPaymentTables:hp(a.tables),queueCount:w.length,storageColumnCount:Object.keys(pn(a)).length,storageRuleCount:le.rules.length,vectorIndexCount:a.vectorIndexes.length,target:gn(e.projectRoot,e.target),vectorStoreSupported:Ge,workflowCount:_.length}),qt=t?et.now():0,Ye=to(a,Se.map(m=>m.id)),Wt=Lr({advisories:Vt.filter(m=>m.name!=="procedure_type_check_unavailable"),advisorProcedures:be?.procedureProtections??[],agents:c,capabilities:l,containers:u,env:k,flagKeys:di,hasFlags:F,hasNotify:N,hasVectors:Ge,maskMetadata:Ut,mutators:He,queues:w,rlsMetadata:li,schema:a,schemaSnapshot:Ye,shapes:re,services:ne,storageRules:le,studioFeatures:de,topics:ie,useUmbrella:U,workflows:_}),Ht=fo(re,p.has("@lunora/db"),U),jt=ao(u,a.jurisdiction),Gt=co(_),Yt=lo(c),Qt=uo(w,e.wranglerQueueProducers),Xt=ho(g),ui=vo(de.scheduler),fi=Eo(a.tables,U),gi=Wi(e.projectRoot)?xo(U):"",Jt=So(a.vectorIndexes),Ne=yo(a,U),Zt=go(p.has("@lunora/seed")),we=e.apiSpec??"openapi",Qe=we==="openapi"||we==="both",Xe=we==="openrpc"||we==="both",es=Zr({capabilities:l,emailAgents:c.filter(m=>m.onEmail===!0).map(m=>({className:m.className,exportName:m.exportName})),hasAccess:p.has("@lunora/cloudflare-access"),hasAuth:p.has("@lunora/auth"),hasFramework:p.has("@lunora/astro")||p.has("@lunora/svelte")||p.has("@lunora/vue")||L(E(e.projectRoot,"src","worker.ts")),hasGlobal:a.tables.some(m=>un(m)),hasHyperdriveGlobal:a.tables.some(m=>fn(m)),hasKvIntrospector:de.kv,hasNotify:N,hasQueue:w.some(m=>m.mode==="push"),hasScheduler:de.scheduler,hasSourcedTables:a.tables.some(m=>m.externalSource!==void 0),hasStorage:de.storage,hasVectors:Ge,hasWorkflow:_.length>0,identity:B,jurisdiction:a.jurisdiction,jurisdictionPinsAuth:a.jurisdictionPinsAuth===!0,tables:a.tables.map(m=>({name:m.name,shardMode:m.shardMode})),useUmbrella:U,vectorIndexCount:a.vectorIndexes.length,voiceAgents:c.filter(m=>m.voice===!0&&m.voiceBindingName!==void 0).map(m=>({bindingName:m.voiceBindingName,exportName:m.exportName})),wantsArchitecture:Ae,wantsOpenApi:Qe,wantsOpenRpc:Xe}),{openApiContent:ts,openApiModuleContent:ss,openRpcContent:ns,openRpcModuleContent:is}=Qp({functions:oe,httpRoutes:We,modules:je,projectRoot:e.projectRoot,wantsArchitecture:Ae}),ue=Ae&&ye!==void 0?hg({...ye,crons:g,functions:oe,httpRoutes:We,modules:je,queues:w,schema:a,services:ne,topics:ie,workflows:_}):void 0,Je=E(n,Xp),pi=L(Je),mi=e.dryRun?[]:Yp(K,[{content:es,kind:"always",name:"app.ts"},{content:f,kind:"always",name:"dataModel.ts"},{content:Kt,kind:"always",name:"api.ts"},{content:zt,kind:"always",name:"internal.ts"},{content:se,kind:"always",name:"server.ts"},{content:Bt,kind:"always",name:"functions.ts"},{content:Wt,kind:"always",name:"shard.ts"},{content:Xt,kind:"always",name:"crons.ts"},{content:Jt,kind:"always",name:"vectors.ts"},{content:Ne.global,kind:"always",name:"drizzle.global.ts"},{content:Ne.shard,kind:"always",name:"drizzle.shard.ts"},{content:jt,kind:"optional",name:"containers.ts"},{content:Gt,kind:"optional",name:"workflows.ts"},{content:Yt,kind:"optional",name:"agents.ts"},{content:Qt,kind:"optional",name:"queues.ts"},{content:ui,kind:"optional",name:"scheduler.ts"},{content:fi,kind:"optional",name:"shardRegistry.ts"},{content:gi,kind:"optional",name:"durableObjects.ts"},{content:Zt,kind:"optional",name:"seed.ts"},{content:Ht,kind:"optional",name:"collections.ts"},{files:_t,kind:"services"},{content:Qe?ts:"",kind:"optional",name:"openapi.json"},{content:Qe?ss:"",kind:"optional",name:"openapi.ts"},{content:Xe?ns:"",kind:"optional",name:"openrpc.json"},{content:Xe?is:"",kind:"optional",name:"openrpc.ts"},{content:ue===void 0?"":`${JSON.stringify(ue,void 0,2)}
11
+ `,kind:"optional",name:"architecture.json"},{content:ue===void 0?"":vg(ue),kind:"optional",name:"architecture.ts"}]);if(!e.dryRun&&(!pi||e.updateSchemaBaseline===!0)&&qe(Je,bi(Ye)),t){const m=et.now(),Ze=Math.round(m-s),hi=Math.round(qt-s),vi=Math.round(m-qt);console.error(`@lunora/codegen: codegen took ${Ze.toString()}ms (discovery ${hi.toString()}ms, emit ${vi.toString()}ms)`)}return{advisories:Vt,advisorContext:be,agents:c,architecture:ue,containers:u,cronTriggers:[...new Set([...Ao(g),...x])],generated:{agents:Yt,api:Kt,app:es,collections:Ht,containers:jt,crons:Xt,dataModel:f,drizzleGlobal:Ne.global,drizzleShard:Ne.shard,functions:Bt,internal:zt,openApi:ts,openApiModule:ss,openRpc:ns,openRpcModule:is,queues:Qt,seed:Zt,server:se,shard:Wt,vectors:Jt,workflows:Gt},migrations:Se,outputDirectory:K,platformDiagnostics:M.diagnostics,queues:w,schemaSnapshot:Ye,schemaSnapshotPath:Je,workflows:_,writtenFiles:mi}};export{Xp as SCHEMA_SNAPSHOT_FILENAME,vr as createCodegenProject,Sh as findTsconfig,Ah as refreshCodegenProject,vh as runCodegen};