@lunora/codegen 1.0.0-alpha.140 → 1.0.0-alpha.142

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -3184,6 +3184,14 @@ interface EmitAppOptions {
3184
3184
  identity?: IdentityIR;
3185
3185
  /** Schema declares `.jurisdiction("…")` → pin every DO the worker reaches (shards, fan-out, scheduler, containers) to the Cloudflare data-residency jurisdiction. */
3186
3186
  jurisdiction?: JurisdictionIR;
3187
+ /**
3188
+ * Every table the schema declares. Emitted as a literal `listSchemaTables`
3189
+ * so export can answer "every table" with a real list: shard discovery is
3190
+ * driven by the table list, so an export naming no tables reaches no shards.
3191
+ * A literal (rather than a read off the imported `schema`) keeps this working
3192
+ * for apps with no `.global()` tables, which never import `schema` at all.
3193
+ */
3194
+ tableNames: ReadonlyArray<string>;
3187
3195
  /** Project depends on the unscoped `lunorash` umbrella → import the runtime via `lunorash/runtime` instead of `@lunora/runtime`. */
3188
3196
  useUmbrella: boolean;
3189
3197
  /**
package/dist/index.d.ts CHANGED
@@ -3184,6 +3184,14 @@ interface EmitAppOptions {
3184
3184
  identity?: IdentityIR;
3185
3185
  /** Schema declares `.jurisdiction("…")` → pin every DO the worker reaches (shards, fan-out, scheduler, containers) to the Cloudflare data-residency jurisdiction. */
3186
3186
  jurisdiction?: JurisdictionIR;
3187
+ /**
3188
+ * Every table the schema declares. Emitted as a literal `listSchemaTables`
3189
+ * so export can answer "every table" with a real list: shard discovery is
3190
+ * driven by the table list, so an export naming no tables reaches no shards.
3191
+ * A literal (rather than a read off the imported `schema`) keeps this working
3192
+ * for apps with no `.global()` tables, which never import `schema` at all.
3193
+ */
3194
+ tableNames: ReadonlyArray<string>;
3187
3195
  /** Project depends on the unscoped `lunorash` umbrella → import the runtime via `lunorash/runtime` instead of `@lunora/runtime`. */
3188
3196
  useUmbrella: boolean;
3189
3197
  /**
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-DLXXalg2.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as S}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as E,diagnosticAt as x}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-D1qA0h5m.mjs";import{default as g}from"./packem_shared/discoverAuthApiCalls-C35kkayg.mjs";import{CONTAINERS_FILENAME as R,discoverContainers as M}from"./packem_shared/CONTAINERS_FILENAME-oKaARMoA.mjs";import{default as C}from"./packem_shared/discoverCrons-wXBfQcfn.mjs";import{FLAGS_FILENAME as T,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-BasxlnVS.mjs";import{default as F}from"./packem_shared/discoverFunctions-BBDziFXy.mjs";import{default as P}from"./packem_shared/discoverHttpRoutes-Dmow2gql.mjs";import{default as G}from"./packem_shared/discoverInserts-C5l2INmE.mjs";import{d as b}from"./packem_shared/index-CCDlo9L7.mjs";import{default as y}from"./packem_shared/discoverMigrations-CWH7T6qz.mjs";import{MUTATORS_FILENAME as j,discoverMutators as K}from"./packem_shared/MUTATORS_FILENAME-DJvAhDlD.mjs";import{default as z}from"./packem_shared/discoverNondeterministicCalls-JsO91i57.mjs";import{NOTIFY_FILENAME as w,discoverNotifyCalls as q,discoverNotifyConfig as B}from"./packem_shared/NOTIFY_FILENAME-B-eIjru_.mjs";import{default as Y}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as Z}from"./packem_shared/queries-B_xEHIeL.mjs";import{QUEUES_FILENAME as ee,discoverQueues as re}from"./packem_shared/QUEUES_FILENAME-D229WtRm.mjs";import{default as te}from"./packem_shared/discoverR2sqlCalls-BbfOpwE4.mjs";import{default as ae}from"./packem_shared/discoverRlsProcedures-CRshfYZE.mjs";import{default as me}from"./packem_shared/discoverRlsMetadata-DGUGYgWs.mjs";import{discoverSandboxUsage as fe}from"./packem_shared/discoverSandboxUsage-DdewAOuj.mjs";import{default as ce}from"./packem_shared/discoverSchema-Bp8DcNq7.mjs";import{SHAPES_FILENAME as Se,discoverShapes as le}from"./packem_shared/SHAPES_FILENAME-BTdasTq2.mjs";import{default as xe}from"./packem_shared/discoverStorageRulesMetadata-gyO60A5S.mjs";import{WORKFLOWS_FILENAME as ue,discoverWorkflows as ve}from"./packem_shared/WORKFLOWS_FILENAME-DRaiCNa6.mjs";import{G as ge,e as Oe,a as Re,b as Me,c as he,d as Ce,f as _e,g as Te,h as Ie,i as Le,j as Fe,k as De,l as Pe,m as Ue}from"./packem_shared/emit-s6mHBmXu.mjs";import{emitApp as He}from"./packem_shared/emitApp-1QfYpsq0.mjs";import{buildOpenApiDocument as ke,emitOpenApi as ye,emitOpenApiModule as We}from"./packem_shared/buildOpenApiDocument-DLEWgA5Y.mjs";import{OPENRPC_VERSION as Ke,buildOpenRpcDocument as Ve,emitOpenRpc as ze,emitOpenRpcModule as Qe}from"./packem_shared/OPENRPC_VERSION-B9ZC0SrC.mjs";import{DEFAULT_TARGET as qe,platformMatrixIds as Be,readProjectTarget as Je,resolveCodegenTarget as Ye}from"./packem_shared/DEFAULT_TARGET-CrhWLUK7.mjs";import{SCHEMA_SNAPSHOT_FILENAME as Ze,createCodegenProject as $e,findTsconfig as er,refreshCodegenProject as rr,runCodegen as or}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-BqXGGcOj.mjs";import{SchemaSnapshotParseError as sr,buildSchemaSnapshot as ar,evaluateSchemaDrift as ir,parseSchemaSnapshot as mr}from"./packem_shared/SchemaSnapshotParseError-CvPTjDrT.mjs";import{schemaFromIr as fr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as cr,validatorIrToJsonSchema as nr}from"./packem_shared/LUNORA_ERROR_CODES-BYg8Lpgb.mjs";import{SDK_LANGUAGES as lr,SDK_TARGETS as Er,generateSdk as xr}from"./packem_shared/SDK_LANGUAGES-CFyux-74.mjs";import{redact as ur,secretKindOf as vr}from"./packem_shared/redact-Cy14LEnc.mjs";import{MESSAGE_SOLUTIONS as gr,findSolutionByMessage as Or}from"@lunora/errors";import{isTypedSchema as Mr}from"./packem_shared/isTypedSchema-B_qlBbE-.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,R as CONTAINERS_FILENAME,E as CodegenDiagnosticError,qe as DEFAULT_TARGET,T as FLAGS_FILENAME,ge as GENERATED_HEADER,cr as LUNORA_ERROR_CODES,gr as LUNORA_SOLUTION_RULES,j as MUTATORS_FILENAME,w as NOTIFY_FILENAME,Ke as OPENRPC_VERSION,ee as QUEUES_FILENAME,Ze as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,lr as SDK_LANGUAGES,Er as SDK_TARGETS,Se as SHAPES_FILENAME,sr as SchemaSnapshotParseError,e as VERSION,ue as WORKFLOWS_FILENAME,ke as buildOpenApiDocument,Ve as buildOpenRpcDocument,ar as buildSchemaSnapshot,$e as createCodegenProject,c as describeErrorLevelFindings,x as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,g as discoverAuthApiCalls,M as discoverContainers,C as discoverCrons,I as discoverFlags,F as discoverFunctions,P as discoverHttpRoutes,G as discoverInserts,b as discoverMaskProcedures,y as discoverMigrations,K as discoverMutators,z as discoverNondeterministicCalls,q as discoverNotifyCalls,B as discoverNotifyConfig,Z as discoverQueries,re as discoverQueues,te as discoverR2sqlCalls,me as discoverRlsMetadata,ae as discoverRlsProcedures,fe as discoverSandboxUsage,ce as discoverSchema,le as discoverShapes,xe as discoverStorageRulesMetadata,ve as discoverWorkflows,Oe as emitAgents,Re as emitApi,He as emitApp,Me as emitCollections,he as emitContainers,Ce as emitCrons,_e as emitDataModel,Te as emitDrizzleSchema,Ie as emitFunctions,ye as emitOpenApi,We as emitOpenApiModule,ze as emitOpenRpc,Qe as emitOpenRpcModule,Le as emitServer,Fe as emitShard,De as emitVectors,Pe as emitWorkflows,Ue as emitWranglerCronTriggers,n as errorAdvisoryNames,S as errorPlatformDiagnosticNames,ir as evaluateSchemaDrift,Or as findLunoraSolution,er as findTsconfig,m as formatAdvisories,xr as generateSdk,Mr as isTypedSchema,d as lintSchema,mr as parseSchemaSnapshot,Be as platformMatrixIds,Y as readPackageDependencies,Je as readProjectTarget,ur as redact,rr as refreshCodegenProject,Ye as resolveCodegenTarget,or as runCodegen,fr as schemaFromIr,vr as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,nr as validatorIrToJsonSchema};
1
+ import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-DLXXalg2.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as S}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as E,diagnosticAt as x}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-D1qA0h5m.mjs";import{default as g}from"./packem_shared/discoverAuthApiCalls-C35kkayg.mjs";import{CONTAINERS_FILENAME as R,discoverContainers as M}from"./packem_shared/CONTAINERS_FILENAME-oKaARMoA.mjs";import{default as C}from"./packem_shared/discoverCrons-wXBfQcfn.mjs";import{FLAGS_FILENAME as T,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-BasxlnVS.mjs";import{default as F}from"./packem_shared/discoverFunctions-BBDziFXy.mjs";import{default as P}from"./packem_shared/discoverHttpRoutes-Dmow2gql.mjs";import{default as G}from"./packem_shared/discoverInserts-C5l2INmE.mjs";import{d as b}from"./packem_shared/index-CCDlo9L7.mjs";import{default as y}from"./packem_shared/discoverMigrations-CWH7T6qz.mjs";import{MUTATORS_FILENAME as j,discoverMutators as K}from"./packem_shared/MUTATORS_FILENAME-DJvAhDlD.mjs";import{default as z}from"./packem_shared/discoverNondeterministicCalls-JsO91i57.mjs";import{NOTIFY_FILENAME as w,discoverNotifyCalls as q,discoverNotifyConfig as B}from"./packem_shared/NOTIFY_FILENAME-B-eIjru_.mjs";import{default as Y}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as Z}from"./packem_shared/queries-B_xEHIeL.mjs";import{QUEUES_FILENAME as ee,discoverQueues as re}from"./packem_shared/QUEUES_FILENAME-D229WtRm.mjs";import{default as te}from"./packem_shared/discoverR2sqlCalls-BbfOpwE4.mjs";import{default as ae}from"./packem_shared/discoverRlsProcedures-CRshfYZE.mjs";import{default as me}from"./packem_shared/discoverRlsMetadata-DGUGYgWs.mjs";import{discoverSandboxUsage as fe}from"./packem_shared/discoverSandboxUsage-DdewAOuj.mjs";import{default as ce}from"./packem_shared/discoverSchema-Bp8DcNq7.mjs";import{SHAPES_FILENAME as Se,discoverShapes as le}from"./packem_shared/SHAPES_FILENAME-BTdasTq2.mjs";import{default as xe}from"./packem_shared/discoverStorageRulesMetadata-gyO60A5S.mjs";import{WORKFLOWS_FILENAME as ue,discoverWorkflows as ve}from"./packem_shared/WORKFLOWS_FILENAME-DRaiCNa6.mjs";import{G as ge,e as Oe,a as Re,b as Me,c as he,d as Ce,f as _e,g as Te,h as Ie,i as Le,j as Fe,k as De,l as Pe,m as Ue}from"./packem_shared/emit-s6mHBmXu.mjs";import{emitApp as He}from"./packem_shared/emitApp-D1qxNeh1.mjs";import{buildOpenApiDocument as ke,emitOpenApi as ye,emitOpenApiModule as We}from"./packem_shared/buildOpenApiDocument-DLEWgA5Y.mjs";import{OPENRPC_VERSION as Ke,buildOpenRpcDocument as Ve,emitOpenRpc as ze,emitOpenRpcModule as Qe}from"./packem_shared/OPENRPC_VERSION-B9ZC0SrC.mjs";import{DEFAULT_TARGET as qe,platformMatrixIds as Be,readProjectTarget as Je,resolveCodegenTarget as Ye}from"./packem_shared/DEFAULT_TARGET-CrhWLUK7.mjs";import{SCHEMA_SNAPSHOT_FILENAME as Ze,createCodegenProject as $e,findTsconfig as er,refreshCodegenProject as rr,runCodegen as or}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-iOZaWN69.mjs";import{SchemaSnapshotParseError as sr,buildSchemaSnapshot as ar,evaluateSchemaDrift as ir,parseSchemaSnapshot as mr}from"./packem_shared/SchemaSnapshotParseError-CvPTjDrT.mjs";import{schemaFromIr as fr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as cr,validatorIrToJsonSchema as nr}from"./packem_shared/LUNORA_ERROR_CODES-BYg8Lpgb.mjs";import{SDK_LANGUAGES as lr,SDK_TARGETS as Er,generateSdk as xr}from"./packem_shared/SDK_LANGUAGES-CFyux-74.mjs";import{redact as ur,secretKindOf as vr}from"./packem_shared/redact-Cy14LEnc.mjs";import{MESSAGE_SOLUTIONS as gr,findSolutionByMessage as Or}from"@lunora/errors";import{isTypedSchema as Mr}from"./packem_shared/isTypedSchema-B_qlBbE-.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,R as CONTAINERS_FILENAME,E as CodegenDiagnosticError,qe as DEFAULT_TARGET,T as FLAGS_FILENAME,ge as GENERATED_HEADER,cr as LUNORA_ERROR_CODES,gr as LUNORA_SOLUTION_RULES,j as MUTATORS_FILENAME,w as NOTIFY_FILENAME,Ke as OPENRPC_VERSION,ee as QUEUES_FILENAME,Ze as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,lr as SDK_LANGUAGES,Er as SDK_TARGETS,Se as SHAPES_FILENAME,sr as SchemaSnapshotParseError,e as VERSION,ue as WORKFLOWS_FILENAME,ke as buildOpenApiDocument,Ve as buildOpenRpcDocument,ar as buildSchemaSnapshot,$e as createCodegenProject,c as describeErrorLevelFindings,x as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,g as discoverAuthApiCalls,M as discoverContainers,C as discoverCrons,I as discoverFlags,F as discoverFunctions,P as discoverHttpRoutes,G as discoverInserts,b as discoverMaskProcedures,y as discoverMigrations,K as discoverMutators,z as discoverNondeterministicCalls,q as discoverNotifyCalls,B as discoverNotifyConfig,Z as discoverQueries,re as discoverQueues,te as discoverR2sqlCalls,me as discoverRlsMetadata,ae as discoverRlsProcedures,fe as discoverSandboxUsage,ce as discoverSchema,le as discoverShapes,xe as discoverStorageRulesMetadata,ve as discoverWorkflows,Oe as emitAgents,Re as emitApi,He as emitApp,Me as emitCollections,he as emitContainers,Ce as emitCrons,_e as emitDataModel,Te as emitDrizzleSchema,Ie as emitFunctions,ye as emitOpenApi,We as emitOpenApiModule,ze as emitOpenRpc,Qe as emitOpenRpcModule,Le as emitServer,Fe as emitShard,De as emitVectors,Pe as emitWorkflows,Ue as emitWranglerCronTriggers,n as errorAdvisoryNames,S as errorPlatformDiagnosticNames,ir as evaluateSchemaDrift,Or as findLunoraSolution,er as findTsconfig,m as formatAdvisories,xr as generateSdk,Mr as isTypedSchema,d as lintSchema,mr as parseSchemaSnapshot,Be as platformMatrixIds,Y as readPackageDependencies,Je as readProjectTarget,ur as redact,rr as refreshCodegenProject,Ye as resolveCodegenTarget,or as runCodegen,fr as schemaFromIr,vr as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,nr as validatorIrToJsonSchema};
@@ -1,9 +1,9 @@
1
- import{existsSync as b,mkdirSync as ss,readFileSync as At,writeFileSync as ns,rmSync as rs}from"node:fs";import{join as f,dirname as fe}from"node:path";import{performance as pe}from"node:perf_hooks";import{runAdvisor as is}from"@lunora/advisor";import{LunoraError as k}from"@lunora/errors";import{SyntaxKind as l,Node as o,Project as Xe}from"ts-morph";import{serializeSchemaSnapshot as os}from"./SCHEMA_SNAPSHOT_VERSION-DLXXalg2.mjs";import{toAdvisorContext as as}from"./formatAdvisories-CkEu1eye.mjs";import{discoverAgents as cs}from"./AGENTS_FILENAME-D1qA0h5m.mjs";import{discoverContainers as ls}from"./CONTAINERS_FILENAME-oKaARMoA.mjs";import{diagnosticAt as se}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as ne}from"./module-specifiers-WF8iAydP.mjs";import{C as ge,i as us,f as ds,n as fs,j as ps,b as gs,c as ms,l as hs,e as xs,o as Es,d as vs,k as Ss,g as As,p as ys,m as Ns,a as bs,h as Ps}from"./emit-s6mHBmXu.mjs";import{l as g,a as E,f as P,p as y,g as yt,j as Ee,h as Is,i as L,b as Ze,r as Nt,e as ws}from"./ast-CjWtsS6S.mjs";import Ts from"./readPackageDependencies-C6h6FZuP.mjs";import{discoverQueues as Cs}from"./QUEUES_FILENAME-D229WtRm.mjs";import{discoverSandboxUsage as Fs}from"./discoverSandboxUsage-DdewAOuj.mjs";import Os from"./discoverStorageRulesMetadata-gyO60A5S.mjs";import{discoverWorkflows as Rs}from"./WORKFLOWS_FILENAME-DRaiCNa6.mjs";import{gatePlatformFeatures as Ls,resolveCodegenTarget as Ds}from"./DEFAULT_TARGET-CrhWLUK7.mjs";import{i as T,a as M,e as v,r as ks,b as Ms,s as re,c as Ks,f as _s,d as zs}from"./queries-B_xEHIeL.mjs";import{a as A,c as K,d as bt,e as Us}from"./classify-procedure-call-AKeIK05y.mjs";import Bs from"./discoverAuthApiCalls-C35kkayg.mjs";import qs from"./discoverCrons-wXBfQcfn.mjs";import Je from"./discoverFunctions-BBDziFXy.mjs";import{i as $s,r as js,e as Vs}from"./unwrap-handler-return-CmIWbykC.mjs";import et from"./discoverHttpRoutes-Dmow2gql.mjs";import Ws from"./discoverInserts-C5l2INmE.mjs";import{m as Ae,a as X,s as Pt,d as Hs}from"./index-CCDlo9L7.mjs";import{e as It}from"./exported-procedure-chains-MlZRKqSD.mjs";import Gs from"./discoverMigrations-CWH7T6qz.mjs";import{MUTATORS_FILENAME as Ys,isDefineMutatorCallee as Qs,discoverMutators as tt}from"./MUTATORS_FILENAME-DJvAhDlD.mjs";import Xs from"./discoverNondeterministicCalls-JsO91i57.mjs";import{discoverNotifyConfig as Zs,discoverNotifyCalls as Js}from"./NOTIFY_FILENAME-B-eIjru_.mjs";import en from"./discoverR2sqlCalls-BbfOpwE4.mjs";import tn from"./discoverRlsProcedures-CRshfYZE.mjs";import sn from"./discoverRlsMetadata-DGUGYgWs.mjs";import nn from"./discoverSchema-Bp8DcNq7.mjs";import{secretKindOf as rn,redact as on,isHeuristicSecretKind as an,isSecretishName as cn}from"./redact-Cy14LEnc.mjs";import{discoverShapes as ln}from"./SHAPES_FILENAME-BTdasTq2.mjs";import{emitApp as un}from"./emitApp-1QfYpsq0.mjs";import{buildOpenApiDocument as dn,emitOpenApiModule as fn}from"./buildOpenApiDocument-DLEWgA5Y.mjs";import{buildOpenRpcDocument as pn,emitOpenRpcModule as gn}from"./OPENRPC_VERSION-B9ZC0SrC.mjs";import{s as mn}from"./parse-validator-BFTp87yz.mjs";import{buildSchemaSnapshot as hn}from"./SchemaSnapshotParseError-CvPTjDrT.mjs";const xn=e=>{const t=[],s=e.tables.filter(n=>n.shardMode==="global");return s.some(n=>n.globalBackend!=="hyperdrive")&&t.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),s.some(n=>n.globalBackend==="hyperdrive")&&t.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'}),e.vectorIndexes.length>0&&t.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/vectors.ts` import `@lunora/bindings/vectors`"}),t},En=(e,t)=>{if(t===void 0)return;const s=xn(e).filter(i=>!t.has(i.name));if(s.length===0)return;const n=s.map(i=>` - ${i.name} — ${i.reason}`).join(`
1
+ import{existsSync as b,mkdirSync as ss,readFileSync as At,writeFileSync as ns,rmSync as rs}from"node:fs";import{join as f,dirname as fe}from"node:path";import{performance as pe}from"node:perf_hooks";import{runAdvisor as is}from"@lunora/advisor";import{LunoraError as k}from"@lunora/errors";import{SyntaxKind as l,Node as o,Project as Xe}from"ts-morph";import{serializeSchemaSnapshot as os}from"./SCHEMA_SNAPSHOT_VERSION-DLXXalg2.mjs";import{toAdvisorContext as as}from"./formatAdvisories-CkEu1eye.mjs";import{discoverAgents as cs}from"./AGENTS_FILENAME-D1qA0h5m.mjs";import{discoverContainers as ls}from"./CONTAINERS_FILENAME-oKaARMoA.mjs";import{diagnosticAt as se}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as ne}from"./module-specifiers-WF8iAydP.mjs";import{C as ge,i as us,f as ds,n as fs,j as ps,b as gs,c as ms,l as hs,e as xs,o as Es,d as vs,k as Ss,g as As,p as ys,m as Ns,a as bs,h as Ps}from"./emit-s6mHBmXu.mjs";import{l as g,a as E,f as P,p as y,g as yt,j as Ee,h as Is,i as L,b as Ze,r as Nt,e as ws}from"./ast-CjWtsS6S.mjs";import Ts from"./readPackageDependencies-C6h6FZuP.mjs";import{discoverQueues as Cs}from"./QUEUES_FILENAME-D229WtRm.mjs";import{discoverSandboxUsage as Fs}from"./discoverSandboxUsage-DdewAOuj.mjs";import Os from"./discoverStorageRulesMetadata-gyO60A5S.mjs";import{discoverWorkflows as Rs}from"./WORKFLOWS_FILENAME-DRaiCNa6.mjs";import{gatePlatformFeatures as Ls,resolveCodegenTarget as Ds}from"./DEFAULT_TARGET-CrhWLUK7.mjs";import{i as T,a as M,e as v,r as ks,b as Ms,s as re,c as Ks,f as _s,d as zs}from"./queries-B_xEHIeL.mjs";import{a as A,c as K,d as bt,e as Us}from"./classify-procedure-call-AKeIK05y.mjs";import Bs from"./discoverAuthApiCalls-C35kkayg.mjs";import qs from"./discoverCrons-wXBfQcfn.mjs";import Je from"./discoverFunctions-BBDziFXy.mjs";import{i as $s,r as js,e as Vs}from"./unwrap-handler-return-CmIWbykC.mjs";import et from"./discoverHttpRoutes-Dmow2gql.mjs";import Ws from"./discoverInserts-C5l2INmE.mjs";import{m as Ae,a as X,s as Pt,d as Hs}from"./index-CCDlo9L7.mjs";import{e as It}from"./exported-procedure-chains-MlZRKqSD.mjs";import Gs from"./discoverMigrations-CWH7T6qz.mjs";import{MUTATORS_FILENAME as Ys,isDefineMutatorCallee as Qs,discoverMutators as tt}from"./MUTATORS_FILENAME-DJvAhDlD.mjs";import Xs from"./discoverNondeterministicCalls-JsO91i57.mjs";import{discoverNotifyConfig as Zs,discoverNotifyCalls as Js}from"./NOTIFY_FILENAME-B-eIjru_.mjs";import en from"./discoverR2sqlCalls-BbfOpwE4.mjs";import tn from"./discoverRlsProcedures-CRshfYZE.mjs";import sn from"./discoverRlsMetadata-DGUGYgWs.mjs";import nn from"./discoverSchema-Bp8DcNq7.mjs";import{secretKindOf as rn,redact as on,isHeuristicSecretKind as an,isSecretishName as cn}from"./redact-Cy14LEnc.mjs";import{discoverShapes as ln}from"./SHAPES_FILENAME-BTdasTq2.mjs";import{emitApp as un}from"./emitApp-D1qxNeh1.mjs";import{buildOpenApiDocument as dn,emitOpenApiModule as fn}from"./buildOpenApiDocument-DLEWgA5Y.mjs";import{buildOpenRpcDocument as pn,emitOpenRpcModule as gn}from"./OPENRPC_VERSION-B9ZC0SrC.mjs";import{s as mn}from"./parse-validator-BFTp87yz.mjs";import{buildSchemaSnapshot as hn}from"./SchemaSnapshotParseError-CvPTjDrT.mjs";const xn=e=>{const t=[],s=e.tables.filter(n=>n.shardMode==="global");return s.some(n=>n.globalBackend!=="hyperdrive")&&t.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),s.some(n=>n.globalBackend==="hyperdrive")&&t.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'}),e.vectorIndexes.length>0&&t.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/vectors.ts` import `@lunora/bindings/vectors`"}),t},En=(e,t)=>{if(t===void 0)return;const s=xn(e).filter(i=>!t.has(i.name));if(s.length===0)return;const n=s.map(i=>` - ${i.name} — ${i.reason}`).join(`
2
2
  `);throw new k("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
3
3
  ${n}
4
4
 
5
- Install them with your package manager, then re-run codegen.`)},vn="env.ts",Sn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return ne(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},An=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&ne(n.getModuleSpecifierValue())}return!1},yn=e=>{if(o.isIdentifier(e))return Sn(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&o.isIdentifier(t)&&An(t)}return!1},Nn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!yn(n.getExpression()))continue;const r=s.getNameNode();if(!o.isIdentifier(r))throw se(r,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},bn=(e,t)=>{const s=f(t,vn);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=Nn(n);if(i.length!==0){if(i.length>1)throw se(n,`lunora/env.ts declares ${i.length.toString()} defineEnv() contracts (${i.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Pn=e=>{const t=n=>o.isIdentifier(n)&&n.getText()==="ctx",s=new Set;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression))t(n.getExpression())&&s.add(n.getName());for(const n of e.getDescendantsOfKind(l.VariableDeclaration)){const i=n.getInitializer(),r=n.getNameNode();if(!(i===void 0||!t(i)||!o.isObjectBindingPattern(r)))for(const a of r.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},In=(e,t)=>{const s=Object.fromEntries(ge.map(n=>[n.key,!1]));for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=new Set(i.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=Pn(i);for(const c of ge)if(!s[c.key]){if(r.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(ge.every(c=>s[c.key]))break}return s},wt="identity.ts",wn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return ne(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Tn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&ne(n.getModuleSpecifierValue())}return!1},Cn=e=>{if(o.isIdentifier(e))return wn(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&o.isIdentifier(t)&&Tn(t)}return!1},Fn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!Cn(n.getExpression()))continue;const r=s.getNameNode();if(!o.isIdentifier(r))throw se(r,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},On=(e,t)=>{const s=f(t,wt);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=Fn(n);if(i.length!==0){if(i.length>1)throw se(n,`lunora/identity.ts declares ${i.length.toString()} defineIdentity() contracts (${i.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Rn=(e,t)=>{const s=new Map,n=new Map,i=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.bindingName,`workflow "${r.exportName}"`),i.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const a=s.get(r.name);if(a!==void 0)throw new k("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${a} and agent "${r.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=n.get(r.bindingName);if(c!==void 0)throw new k("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${r.bindingName}": produced by both ${c} and agent "${r.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const u=i.get(r.className);if(u!==void 0)throw new k("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${u} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},Ln=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:i}=e,r=On(s,t),a=bn(s,t),c=Rs(s,t),u=Cs(s,t),d=cs(s,t);Rn(c,d);const h=ls(s,t),N=Os(s,t),p=Ls(In(s,t),Ds(n,e.target)),S=p.usage,C=Fs(s,t),F=S.browser||C.usesSandboxBrowser,O=Ts(n),V=O??new Set,R=V.has("lunorash");En(i,O);const _=b(f(t,"flags.ts")),z=b(f(t,"notify.ts"));return{agents:d,containers:h,dataModelContent:ds(i),declaredDependencies:O,dependencies:V,env:a,featureUsage:S,hasBrowser:F,hasFlags:_,hasNotify:z,identity:r,platformGate:p,queues:u,serverContent:us({agents:d,containers:h,env:a,hasAccessFacade:S.access,hasAi:S.ai,hasAnalytics:S.analytics,hasBrowser:F,hasFlags:_,hasHyperdrive:S.hyperdrive,hasImages:S.images,hasKv:S.kv,hasNotify:z,hasPayments:S.payments,hasPipelines:S.pipelines,hasR2sql:S.r2sql,hasX402:S.x402,identity:r,queues:u,schema:i,storageRuleBuckets:N.rules.map(oe=>oe.bucket),useUmbrella:R,workflows:c}),storageRulesMetadata:N,usesSandbox:C.usesSandboxBrowser||C.usesSandboxContainer,useUmbrella:R,workflows:c}},Tt=new Set(["delete","get","head","options","patch","post","put"]),Dn=new Set(["handler","stream"]),kn=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,st=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Mn=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Tt.has(t.getName()))return;const s=t.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!o.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},Kn=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||Tt.has(n.getName()))break;s=n.getExpression()}return Mn(s)},_n=e=>{for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression))if(st.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&st.has(s.getText()))return!0}return!1},zn=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||!Dn.has(n.getName()))return;const i=Kn(s);if(!i||!kn.test(i.path))return;const r=s.getArguments()[0],a=r!==void 0&&(o.isArrowFunction(r)||o.isFunctionExpression(r))&&_n(r);return{exportName:e.getName(),file:t,method:i.method,path:i.path,usesGuard:a}},Un=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=zn(i,t);r&&s.push(r)}return s},Bn=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Un(i,E(t,n)))}return s},qn=e=>!o.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",$n=(e,t)=>{if(!qn(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!T(s)||M(s)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},jn=(e,t)=>P(e,t,$n),Vn=new Set(["generateText","streamText"]),Wn=new Set(["messages","prompt","system"]),Hn=[{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"]}],Gn=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const i of Hn)if(i.methods.has(s)&&i.prefixes.some(r=>n===r||n.startsWith(`${r}.`)))return`${n}.${s}`},Yn=e=>{for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=Gn(t);if(s!==void 0)return s}},Qn=e=>{const t=new Set,s=e.getFirstAncestor(r=>o.isArrowFunction(r)||o.isFunctionExpression(r)||o.isFunctionDeclaration(r)),[n]=s?.getParameters()??[],i=n?.getNameNode();if(i===void 0||!o.isObjectBindingPattern(i))return t;for(const r of i.getElements()){const a=r.getPropertyNameNode()?.getText()??r.getName(),c=r.getNameNode();if(a==="args"&&o.isObjectBindingPattern(c))for(const u of c.getElements())t.add(u.getName())}return t},Xn=e=>{if(ks(e))return!0;const t=Qn(e);return t.size===0?!1:e.getDescendantsOfKind(l.Identifier).some(s=>t.has(s.getText()))},Zn=e=>{for(const t of e.getProperties()){if(!o.isPropertyAssignment(t)||!Wn.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&Xn(s))return!0}return!1},Jn=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=A(n.getExpression());if(i===void 0||!Vn.has(i))continue;const[r]=n.getArguments();if(r===void 0||!o.isObjectLiteralExpression(r))continue;let a;for(const c of r.getDescendantsOfKind(l.CallExpression))if(A(c.getExpression())==="tool"&&(a=Yn(c),a!==void 0))break;a!==void 0&&s.push({exportName:v(n),file:t,line:n.getStartLineNumber(),method:i,sideEffect:a,userInputDerived:Zn(r)})}return s},er=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Jn(i,E(t,n)))}return s},tr=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return o.isIdentifier(t)&&t.getText()==="ctx"},sr=(e,t)=>{if(!tr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!T(s)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},nr=(e,t)=>P(e,t,sr),Ct=e=>e.getProperties().some(t=>o.isSpreadAssignment(t)),rr=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!o.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer();return!n||!o.isObjectLiteralExpression(n)?{objects:[],opaque:!0}:{objects:[n],opaque:Ct(n)}},ir=e=>{const t=[];let s=!1,n=e;for(;o.isCallExpression(n);){const i=n.getExpression();if(!o.isPropertyAccessExpression(i))break;if(i.getName()==="input"){const r=n.getArguments()[0];r&&o.isObjectLiteralExpression(r)?(t.push(r),s||=Ct(r)):s=!0}n=i.getExpression()}return{objects:t,opaque:s}},Ft=(e,t)=>t?ir(t):rr(e),or=e=>e.flatMap(t=>t.getProperties().filter(s=>o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)).map(s=>s.getName())),ar=/\.check\(|\.meta\(|length|max/iu,cr=/\bv\.any\s*\(/u,lr=/\bv\.string\s*\(/u,ur=e=>cr.test(e),dr=e=>lr.test(e)&&!ar.test(e),fr=e=>{const t=[],s=[];for(const n of e)for(const i of n.getProperties()){if(!o.isPropertyAssignment(i))continue;const r=i.getInitializer();if(!r)continue;const a=r.getText(),c=i.getName();ur(a)?t.push(c):dr(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},pr=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=K(s);if(n?.visibility!=="public")return;const{objects:i}=Ft(s,n.receiver),{anyArgs:r,unboundedStringArgs:a}=fr(i);if(!(r.length===0&&a.length===0))return{anyArgs:r,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},gr=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=pr(i,t);r&&s.push(r)}return s},mr=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...gr(i,E(t,n)))}return s},me=e=>e?.getKind()===l.TrueKeyword,hr=e=>e?.getKind()===l.FalseKeyword,xr=e=>e!==void 0&&o.isNumericLiteral(e)&&e.getLiteralValue()===0,Er=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),vr=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isCallExpression(t)&&A(t.getExpression())==="scim"),Sr=e=>e!==void 0&&o.isCallExpression(e)&&Er.has(A(e.getExpression())??""),Ar=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isStringLiteral(t)&&t.getLiteralText()==="*"),yr=e=>{const t=y(e,"advanced"),s=y(e,"emailAndPassword"),n=y(e,"session");return{analyzable:!0,disableCsrfCheck:me(y(t,"disableCSRFCheck")),emailPasswordEnabled:me(y(s,"enabled")),requireEmailVerification:me(y(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:vr(y(e,"plugins"))&&Sr(y(e,"database")),secureCookiesDisabled:hr(y(t,"useSecureCookies")),sessionFreshAgeZero:xr(y(n,"freshAge")),trustedOriginsWildcard:Ar(y(e,"trustedOrigins"))}},Nr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),br=(e,t)=>{if(A(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&o.isObjectLiteralExpression(s)&&s.getProperties().some(r=>o.isSpreadAssignment(r)),i=s!==void 0&&o.isObjectLiteralExpression(s)&&!n?yr(s):Nr();return{exportName:v(e),file:t,line:e.getStartLineNumber(),...i}},Pr=(e,t)=>P(e,t,br),Ir=(e,t)=>{if(!o.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},wr=(e,t,s)=>{const n=Ir(e.getExpression(),s);if(n===void 0)return;const i=e.getArguments()[s.argIndex];if(!(!i||!T(i)||M(i))&&!(s.requireUnmodifiedReach===!0&&!Ms(i)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:n}},Tr=(e,t,s)=>{const n=[];for(const i of e.getDescendantsOfKind(l.CallExpression)){const r=wr(i,t,s);r&&n.push(r)}return n},ie=(e,t,s)=>{const n=[];for(const i of g(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...Tr(r,E(t,i),s))}return n},Cr=new Set(["content","pdf","scrape","screenshot"]),Fr=(e,t)=>ie(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Cr}),Or=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Rr=new Set(["RateLimiter"]),Lr=new Set(["extend"]),Ot=e=>{const t=[],s=[];let n=!1;for(const i of e.getProperties()){if(o.isSpreadAssignment(i)){n=!0;continue}if(o.isPropertyAssignment(i)){const r=i.getName();t.push(r),i.getInitializer()?.getKind()===l.TrueKeyword&&s.push(r);continue}(o.isShorthandPropertyAssignment(i)||o.isMethodDeclaration(i))&&t.push(i.getName())}return{analyzable:!n,presentKeys:t,trueKeys:s}},nt=e=>e&&o.isObjectLiteralExpression(e)?Ot(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Dr=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!o.isReturnStatement(s))return;const n=s.getExpression();return n!==void 0&&o.isObjectLiteralExpression(n)?n:void 0},kr=e=>{if(o.isObjectLiteralExpression(e))return e;if(o.isParenthesizedExpression(e)){const t=e.getExpression();return o.isObjectLiteralExpression(t)?t:void 0}return o.isBlock(e)?Dr(e):void 0},Mr=e=>{const t=e&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,s=t&&kr(t.getBody());return s?Ot(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Kr=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=A(n.getExpression());i!==void 0&&(Or.has(i)?s.push({callee:i,file:t,line:n.getStartLineNumber(),...nt(n.getArguments()[0])}):Lr.has(i)&&s.push({callee:i,file:t,line:n.getStartLineNumber(),...Mr(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(l.NewExpression)){const i=A(n.getExpression());i===void 0||!Rr.has(i)||s.push({callee:i,file:t,line:n.getStartLineNumber(),...nt(n.getArguments()[0])})}return s},_r=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Kr(i,E(t,n)))}return s},rt="ctx.containers.",zr=e=>{if(!e.startsWith(rt))return!1;const t=e.slice(rt.length);return t.length>0&&!t.includes(".")},Ur=(e,t)=>ie(e,t,{argIndex:0,matchReceiver:zr,methods:new Set(["get"])}),Br=new Set(["allow","deny","setAllowed"]),qr=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&o.isPropertyAssignment(s)&&o.isTrueLiteral(s.getInitializerOrThrow())},$r=(e,t)=>{const s=e.getExpression();if(!(!o.isPropertyAccessExpression(s)||s.getName()!=="start"||!qr(e)))return{detail:"enableInternet: true",exportName:v(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},jr=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||!Br.has(s.getName()))return;const n=s.getExpression();if(!(!o.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),exportName:v(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},Vr=(e,t)=>$r(e,t)??jr(e,t),Wr=(e,t)=>P(e,t,Vr),Hr=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Gr=e=>{const t=e.getExpression();if(!o.isIdentifier(t))return;const s=t.getText();return Hr.has(s)?s:void 0},Yr=e=>{const t=[],s=[];for(const n of e.getProperties()){if(o.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(o.isPropertyAssignment(n)){const i=n.getName();t.push(i);const r=n.getInitializer();r&&o.isStringLiteral(r)&&r.getLiteralText()===""&&s.push(i);continue}(o.isShorthandPropertyAssignment(n)||o.isMethodDeclaration(n)||o.isGetAccessorDeclaration(n))&&t.push(n.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Qr=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getDescendantsOfKind(l.CallExpression)){const c=Gr(a);if(c===void 0)continue;const u=a.getArguments()[0],d=u&&o.isObjectLiteralExpression(u)?Yr(u):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:d.analyzable,emptyKeys:d.emptyKeys,factory:c,file:r,line:a.getStartLineNumber(),presentKeys:d.presentKeys})}}return s},Xr=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Zr=new Set(["dbRateLimit","rateLimit"]),Jr=e=>{if(!e||!o.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&o.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===l.TrueKeyword},ei=(e,t)=>{const s=A(e.getExpression());if(s===void 0)return;const n=Xr.get(s);if(n!==void 0)return{callee:s,exportName:v(e),failOpen:Jr(e.getArguments()[n]),file:t,limitName:Zr.has(s)?yt(e):"",line:e.getStartLineNumber()}},ti=(e,t)=>P(e,t,ei),si=new Set(["boolean","number","object","string"]),ni=e=>{const t=e.getName();if(!si.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="flags"&&Ee(s.getExpression()))return t;const n=s.getExpression();if(s.getName()==="details"&&o.isPropertyAccessExpression(n)&&n.getName()==="flags"&&Ee(n.getExpression()))return t},ri=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=ni(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(o.isStringLiteral(n)||o.isNoSubstitutionTemplateLiteral(n)))return;const i=n.getLiteralValue();return i.length>0?{key:i,type:s}:void 0},ii=(e,t)=>{const s=new Map;for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of i.getDescendantsOfKind(l.CallExpression)){const a=ri(r);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))},oi=e=>{const t=e.getInitializer();if(!t||!o.isCallExpression(t))return;const s=K(t);if(s?.kind!=="query")return;const n=Is(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},it=e=>{const t=e.getParent();return t&&o.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},ai=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!o.isIdentifier(t)||t.getText()!=="ctx")return;const s=it(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=it(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},ci=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const i=ai(n);i!==void 0&&s.push({callee:i,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},li=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=oi(i);r&&s.push(...ci(r,t))}return s},ui=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...li(i,E(t,n)))}return s},di=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Ee(t.getExpression())},fi=e=>{if(e?.getKind()===l.TrueKeyword)return!0;if(e?.getKind()===l.FalseKeyword)return!1},pi=(e,t)=>{if(!di(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(o.isStringLiteral(s)||o.isNoSubstitutionTemplateLiteral(s)))return;const i=s.getLiteralValue(),r=fi(n);if(!(i.length===0||r===void 0))return{defaultValue:r,exportName:v(e),file:t,key:i,line:e.getStartLineNumber()}},gi=(e,t)=>P(e,t,pi),mi=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),r=i.getText(e);if(!r||r==="any"||r==="never"||$s(r))return;const a=e.getSourceFile().getFilePath();return js(i,e,a)?Vs(i,e,a,0,new Set):r},hi=e=>{const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},xi=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},Ei=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getDescendantsOfKind(l.CallExpression))hi(a)&&s.push({file:r,indexName:xi(a),line:a.getStartLineNumber()})}return s},j=e=>e!==void 0&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,Rt=e=>{const t=e.getArguments()[0],s=j(t);if(s!==void 0)return s;if(t===void 0||!o.isObjectLiteralExpression(t))return;const n=t.getProperty("handler");return n!==void 0&&o.isPropertyAssignment(n)?j(n.getInitializer()):void 0},vi=new Set(["delete","get","head","options","patch","post","put"]),Si=new Set(["handler","stream"]),Ai=new Set(["runAction","runMutation"]),yi=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),Z=(e,t)=>e!==void 0&&o.isIdentifier(e)&&e.getText()===t,ot=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const n=s.getNameNode();if(t)return o.isIdentifier(n)?n.getText():void 0;if(o.isObjectBindingPattern(n)){for(const i of n.getElements())if((i.getPropertyNameNode()?.getText()??i.getNameNode().getText())==="ctx"){const a=i.getNameNode();return o.isIdentifier(a)?a.getText():void 0}}},at=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);o.isCallExpression(s)&&n.unshift(s);for(const i of n){const r=i.getExpression();if(!o.isPropertyAccessExpression(r))continue;const a=r.getName(),c=r.getExpression();if(Ai.has(a)&&Z(c,t))return a;if(yi.has(a)&&o.isPropertyAccessExpression(c)&&c.getName()==="db"&&Z(c.getExpression(),t))return`db.${a}`}},ct=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(l.PropertyAccessExpression))if(n.getName()==="auth"&&Z(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(l.VariableDeclaration)){const i=n.getNameNode();if(!(!o.isObjectBindingPattern(i)||!Z(n.getInitializer(),t))){for(const r of i.getElements())if((r.getPropertyNameNode()?.getText()??r.getNameNode().getText())==="auth")return!0}}return!1},Ni=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Si.has(t.getName()))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))return;const i=n.getName();if(vi.has(i)){const r=n.getExpression();return o.isIdentifier(r)&&r.getText()==="httpRoute"?i.toUpperCase():void 0}s=n.getExpression()}},bi=(e,t)=>{const s=e.getExpression();if(o.isIdentifier(s)&&s.getText()==="httpAction"){const c=j(e.getArguments()[0]),u=c&&ot(c,!0);if(!c||u===void 0)return;const d=at(c,u);return d===void 0?void 0:{exportName:v(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ct(c,u),sideEffect:d}}const n=Ni(e);if(n===void 0)return;const i=j(e.getArguments()[0]),r=i&&ot(i,!1);if(!i||r===void 0)return;const a=at(i,r);return a===void 0?void 0:{exportName:v(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:ct(i,r),sideEffect:a}},Pi=(e,t)=>P(e,t,bi),Ii=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),wi=new Set(["append","set"]),Lt=e=>e!==void 0&&(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",lt=(e,t)=>(o.isCallExpression(e)?[e,...e.getDescendantsOfKind(l.CallExpression)]:e.getDescendantsOfKind(l.CallExpression)).some(n=>Ii.has(A(n.getExpression())??"")&&_s(n,t)),Ti=(e,t)=>{if(lt(e,t))return!0;const s=re(e);return s!==void 0&&lt(s,t)},ve=(e,t)=>Ks(e,t)&&!Ti(e,t),Ci=e=>{if(o.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=re(e);return t!==void 0&&o.isNewExpression(t)&&A(t.getExpression())==="Headers"},J=e=>{if(e===void 0)return;if(o.isObjectLiteralExpression(e))return e;const t=re(e);return t!==void 0&&o.isObjectLiteralExpression(t)?t:void 0},ye=(e,t,s)=>{for(const n of e.getProperties())if(o.isPropertyAssignment(n)){const i=n.getInitializer();i!==void 0&&ve(i,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:Lt(n.getNameNode()),line:i.getStartLineNumber(),via:t})}else if(o.isShorthandPropertyAssignment(n)){const i=n.getNameNode();ve(i,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:n.getName(),line:i.getStartLineNumber(),via:t})}else if(o.isSpreadAssignment(n)){const i=J(n.getExpression());i!==void 0&&ye(i,t,s)}},Dt=(e,t)=>{const s=J(e);if(s===void 0)return;const n=s.getProperty("headers");if(n===void 0||!o.isPropertyAssignment(n))return;const i=J(n.getInitializer());i!==void 0&&ye(i,"response-init",t)},Fi=(e,t)=>{const s=A(e.getExpression());if(s==="Response")Dt(e.getArguments()[1],t);else if(s==="Headers"){const n=J(e.getArguments()[0]);n!==void 0&&ye(n,"headers-ctor",t)}},Oi=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName(),i=s.getExpression();if(n==="json"&&o.isIdentifier(i)&&i.getText()==="Response"){Dt(e.getArguments()[1],t);return}if(wi.has(n)&&Ci(i)){const r=e.getArguments()[1];r!==void 0&&ve(r,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:Lt(e.getArguments()[0]),line:r.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},Ri=(e,t)=>{for(const s of e.getDescendantsOfKind(l.NewExpression))Fi(s,t);for(const s of e.getDescendantsOfKind(l.CallExpression))Oi(s,t)},Li=(e,t)=>{const s=e.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=j(e.getArguments()[0]);if(n===void 0)return[];const i=n.getParameters()[1];if(i===void 0)return[];const r=i.getNameNode();if(!o.isIdentifier(r))return[];const a=[];return Ri(n,{exportName:v(e),relativePath:t,requestName:r.getText(),rows:a}),a},Di=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression))s.push(...Li(n,t));return s},ki=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Di(i,E(t,n)))}return s},Mi=new Set(["auth","context.auth","ctx.auth"]),Ki="userId",_i=e=>{const t=new Set;for(const s of e.getProperties()){if(o.isSpreadAssignment(s))return;(o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)||o.isMethodDeclaration(s))&&t.add(s.getName())}return t},zi=(e,t)=>{const s=f(t,wt);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const i of n.getDescendantsOfKind(l.CallExpression)){if(A(i.getExpression())!=="defineIdentity")continue;const[r]=i.getArguments();return r&&o.isObjectLiteralExpression(r)?_i(r):void 0}},ut=e=>{if(!(e===void 0||!o.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Mi.has(e.getExpression().getText())?e:void 0},Ui=e=>{if(o.isPropertyAccessExpression(e)&&ut(e.getExpression())!==void 0)return e.getName();if(o.isElementAccessExpression(e)&&ut(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&o.isStringLiteral(t)?t.getLiteralValue():void 0}},Bi=(e,t,s)=>{const n=[];for(const i of e.getDescendants()){const r=Ui(i);r!==void 0&&n.push({declared:r===Ki||s.has(r),exportName:v(i),file:t,key:r,line:i.getStartLineNumber()})}return n},qi=(e,t)=>{const s=zi(e,t);if(s===void 0)return[];const n=[];for(const i of g(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...Bi(r,E(t,i),s))}return n},$i=(e,t)=>{if(A(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=y(s,"key");if(!(!n||!T(n)||M(n)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},ji=(e,t)=>P(e,t,$i),Vi=new Set(["delete","get","getRaw","getWithMetadata","put"]),Wi=(e,t)=>ie(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:Vi}),Hi=new Set(["queue","send"]),dt=new Set(["bcc","cc","to"]),Gi=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!Hi.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},Yi=e=>o.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(o.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return dt.has(t.getName())&&T(n)&&!M(n)}if(!o.isPropertyAssignment(t)||!dt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&T(s)&&!M(s)}):!1,Qi=(e,t)=>{const s=Gi(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!Yi(n)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s}},Xi=(e,t)=>P(e,t,Qi),Zi=e=>o.isPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?o.isComputedPropertyName(e.getNameNode()):!1,Ji=e=>o.isPropertyAssignment(e)||o.isShorthandPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?Zi(e):!0,kt=(e,t=!1)=>{for(const s of e.getProperties()){if(Ji(s))return!0;if(t)continue;if(!o.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!o.isObjectLiteralExpression(n)||kt(n,!0))return!0}return!1},eo=(e,t)=>{for(const s of g(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:i}of It(n))for(const r of Ae(i)){const a=r.getArguments()[0];if(a!==void 0&&(!o.isObjectLiteralExpression(a)||kt(a)))return!0}}return!1},to=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const i=X(n);if(i===void 0||!o.isPropertyAssignment(n))continue;const r=n.getInitializer();if(!(!r||!o.isObjectLiteralExpression(r)))for(const a of r.getProperties()){const c=X(a);c!==void 0&&s.push({column:c,strategy:Pt(a),table:i})}}return s},so=(e,t)=>{const s=new Map;for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:r}of It(i))for(const a of Ae(r))for(const c of to(a)){const u=`${c.table}\0${c.column}`;s.has(u)||s.set(u,c)}}return{columns:[...s.values()]}},no=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!o.isObjectLiteralExpression(n))return[];const i=[];for(const r of n.getProperties()){const a=X(r);if(a===void 0||!o.isPropertyAssignment(r))continue;const c=r.getInitializer();if(!(!c||!o.isObjectLiteralExpression(c)))for(const u of c.getProperties()){const d=X(u);if(d===void 0)continue;const h=Pt(u);h!=="custom"&&i.push({column:d,exportName:t,file:s,line:u.getStartLineNumber(),strategy:h,table:a})}}return i},ro=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?K(s):void 0;return n?.receiver?Ae(n.receiver).flatMap(i=>no(i,e.getName(),t)):[]},io=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...ro(c,r))}return s},oo=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return L(s)},ao=e=>{const t=e.getArguments()[0];if(t===void 0||!o.isObjectLiteralExpression(t))return;const s=t.getProperty("server");if(s!==void 0)return o.isPropertyAssignment(s)?s.getInitializer():s},co=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==l.CallExpression)return;const s=t;return Qs(s.getExpression())?s:void 0},lo=e=>{const t=co(e),s=t===void 0?void 0:ao(t);if(s===void 0)return[];const n=e.getNameNode(),i=o.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(l.CallExpression).filter(r=>oo(r)).map(r=>({exportName:i,file:"lunora/mutators.ts",line:r.getStartLineNumber()}))},uo=e=>e.getVariableDeclarations().flatMap(t=>lo(t)),fo=(e,t)=>{const s=f(t,Ys);if(!b(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return uo(n)},po=new Set(["delete","get","patch"]),go=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),mo=new Set(["auth","identity","session","user"]),ho=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),xo=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!L(t.getExpression()))return;const s=e.getArguments()[0];return s&&o.isStringLiteral(s)?s.getLiteralText():""},Eo=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(o.isAsExpression(s)||o.isParenthesizedExpression(s)||o.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!o.isVariableDeclaration(s))return;const n=s.getNameNode();return o.isIdentifier(n)?n.getText():void 0},vo=(e,t)=>e.getDescendantsOfKind(l.Identifier).some(s=>s.getText()===t),So=e=>o.isThrowStatement(e)||o.isReturnStatement(e)||e.getDescendantsOfKind(l.ThrowStatement).length>0||e.getDescendantsOfKind(l.ReturnStatement).length>0,Ao=(e,t)=>e.getDescendantsOfKind(l.IfStatement).some(s=>vo(s.getExpression(),t)&&So(s.getThenStatement())),yo=(e,t)=>{for(const s of e.getDescendantsOfKind(l.CallExpression)){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))continue;const i=n.getName();if(!po.has(i))continue;const r=n.getExpression();if(!(L(r)||o.isPropertyAccessExpression(r)&&L(r.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&o.isIdentifier(c)&&c.getText()===t)return i}},No=e=>{let t=e;for(;o.isPropertyAccessExpression(t)||o.isElementAccessExpression(t)||o.isNonNullExpression(t)||o.isParenthesizedExpression(t)||o.isAsExpression(t)||o.isAwaitExpression(t);)t=t.getExpression();return o.isIdentifier(t)?t.getText():void 0},bo=e=>e.getDescendantsOfKind(l.CallExpression).some(t=>t.getArguments().some(s=>No(s)==="ctx")),Po=e=>e.getDescendantsOfKind(l.BinaryExpression).some(t=>ho.has(t.getOperatorToken().getKind())?o.isPropertyAccessExpression(t.getLeft())||o.isPropertyAccessExpression(t.getRight()):!1),Io=e=>{for(const t of e.getDescendantsOfKind(l.Identifier))if(go.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&s.getText()==="ctx"&&mo.has(t.getName()))return!0}return bo(e)||Po(e)},wo=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=K(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const i=Rt(s);if(i===void 0)return[];const r=n.receiver!==void 0&&bt(n.receiver,"use","rls"),a=Io(i),c=new Set,u=[];for(const d of i.getDescendantsOfKind(l.CallExpression)){const h=xo(d);if(h===void 0)continue;const N=Eo(d);if(N===void 0||c.has(N)||!Ao(i,N))continue;const p=yo(i,N);p!==void 0&&(c.add(N),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:p,table:h,usesRls:r,visibility:n.visibility}))}return u},To=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...wo(c,r))}return s},Co=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Fo=new Set(["insert","insertManyUnsafe","patch","replace"]),Oo=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!Fo.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||s.getName()!=="db")return;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"?t:void 0},Ro=(e,t)=>{if(t!=="insertManyUnsafe")return o.isObjectLiteralExpression(e)?[e]:[];if(!o.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())o.isObjectLiteralExpression(n)&&s.push(n);return s},Lo=(e,t,s,n)=>{const i=[];for(const r of e.getProperties()){let a,c;o.isPropertyAssignment(r)?(a=r.getName(),c=r.getInitializer()):o.isShorthandPropertyAssignment(r)&&(a=r.getName(),c=r.getNameNode()),!(a===void 0||c===void 0||!Co.has(a))&&T(c)&&!M(c)&&i.push({exportName:v(s),field:a,file:n,line:s.getStartLineNumber(),method:t})}return i},Do=(e,t)=>{const s=Oo(e.getExpression());if(s===void 0)return[];const n=e.getArguments()[1];return n?Ro(n,s).flatMap(i=>Lo(i,s,e,t)):[]},ko=(e,t,s)=>{const n=[];for(const i of e.getDescendantsOfKind(l.CallExpression))for(const r of Do(i,t)){const a=s(r.exportName);n.push(a===void 0?r:{...r,visibility:a})}return n},Mo=(e,t,s=[])=>{const n=[],i=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));for(const r of g(t)){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=E(t,r);n.push(...ko(a,c,u=>i.get(`${c}:${u}`)))}return n},Ko=["providerSubscriptionId","state"],_o=["providerEventId","processedAt"],ft=(e,t)=>t.every(s=>s in e.shape),zo=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&ft(t,Ko)&&ft(s,_o)},Uo=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Bo=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,qo=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&o.isPropertyAssignment(t)?Bo(t.getInitializer()):void 0},$o=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!Uo.has(s))return;const[n]=e.getArguments(),i=n&&o.isObjectLiteralExpression(n)?qo(n):void 0;return{callee:s,exportName:v(e),file:t,line:e.getStartLineNumber(),...i===void 0?{}:{toleranceSeconds:i}}},jo=(e,t)=>P(e,t,$o),Vo=new Set(["defineQueue","defineWorkflow"]),Wo=new Set(["run","runAction","runMutation","runQuery"]),Ho=new Set(["api","internal"]),Go=e=>{const t=e.getExpression();return o.isIdentifier(t)?t.getText():void 0},Yo=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!o.isPropertyAssignment(s))return;const n=s.getInitializer();if(n&&(o.isArrowFunction(n)||o.isFunctionExpression(n)))return n},Mt=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&o.isIdentifier(s)?s.getText():void 0},Kt=(e,t)=>e===t||e.startsWith(`${t}.`),_t=e=>{const t=e.getDescendantsOfKind(l.PropertyAccessExpression);return o.isPropertyAccessExpression(e)&&t.push(e),t},pt=e=>{const t=e.getParent();return o.isPropertyAccessExpression(t)&&t.getNameNode()===e||o.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(o.isBindingElement(t)&&t.getNameNode()===e)},zt=e=>{const t=e.getDescendantsOfKind(l.Identifier).filter(s=>pt(s));return o.isIdentifier(e)&&pt(e)&&t.push(e),t},Qo=e=>{if(!o.isVariableDeclaration(e))return[];const t=e.getNameNode();return o.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(l.BindingElement).map(s=>s.getName())},Xo=e=>{const t=Mt(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(l.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const i=n.getInitializer(),r=o.isVariableDeclarationList(i)?i.getDeclarations()[0]?.getNameNode():void 0;r&&o.isIdentifier(r)&&s.push(`${r.getText()}.body`)}return s},Zo=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:Xo(e),i=new Set,r=a=>_t(a).some(c=>n.some(u=>Kt(c.getText(),u)))?!0:zt(a).some(c=>i.has(c.getText()));for(const a of e.getDescendantsOfKind(l.VariableDeclaration)){const c=a.getInitializer();if(c&&r(c))for(const u of Qo(a))i.add(u)}return{names:i,prefixes:n}},Jo=(e,t)=>_t(e).some(s=>t.prefixes.some(n=>Kt(s.getText(),n)))?!0:zt(e).some(s=>t.names.has(s.getText())),ea=e=>{if(e===void 0||!o.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;o.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const n=t.at(-1);if(!(n===void 0||!o.isIdentifier(s)||!Ho.has(s.getText())||t.length<2))return{exportName:n,file:t.slice(0,-1).join("/")}},ta=(e,t,s)=>{const n=Mt(e,0);if(n===void 0)return[];const i=Zo(e,t,n),r=[];for(const a of e.getDescendantsOfKind(l.CallExpression)){const c=a.getExpression();if(!o.isPropertyAccessExpression(c)||!Wo.has(c.getName())||c.getExpression().getText()!==n)continue;const u=a.getArguments()[1];if(!u||!Jo(u,i))continue;const d=ea(a.getArguments()[0]);d!==void 0&&r.push({dispatchKind:t,file:s,handlerExport:v(a),line:a.getStartLineNumber(),targetExport:d.exportName,targetFile:d.file})}return r},sa=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=Go(n);if(i===void 0||!Vo.has(i))continue;const r=Yo(n);r!==void 0&&s.push(...ta(r,i==="defineQueue"?"queue":"workflow",t))}return s},na=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...sa(i,E(t,n)))}return s},gt={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},mt=new Set(["account","credential","member","passkey","session","user"]),ra=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),ia=e=>{const s=ra(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return mt.has(s)||mt.has(n)},oa=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},aa=(e,t)=>{const{objects:s,opaque:n}=Ft(e,t);return or(s).some(i=>oa(i))?!0:n?void 0:!1},ca=e=>{const t=e.getArguments()[0];return!t||!o.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},la=e=>{if(o.isCallExpression(e))return e;if(!o.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&o.isCallExpression(s)?s:void 0},Q={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},ua=e=>{const t=la(e),s=t?A(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=ca(t);return{...Q,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in gt?{...Q,[gt[s]]:!0}:Q},da=e=>{const t={...Q};let s=e;for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))break;const i=n.getName()==="use"?s.getArguments()[0]:void 0;if(i){const r=ua(i);t.usesCaptcha||=r.usesCaptcha,t.usesEmailGate||=r.usesEmailGate,t.usesMask||=r.usesMask,t.usesRateLimit||=r.usesRateLimit,t.usesRls||=r.usesRls}s=n.getExpression()}return t},fa=new Set(["insert","insertMany","insertManyUnsafe","replace"]),pa=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!fa.has(t.getName()))return!1;const s=t.getExpression();if(!L(s))return!1;const i=e.getArguments()[0];return!i||!(o.isStringLiteral(i)||o.isNoSubstitutionTemplateLiteral(i))?!1:ia(i.getLiteralText())},ga=new Set(["create","runAfter","runAt","send","sendBatch"]),ma=new Set(["queues","scheduler","workflows"]),ha=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!ga.has(t.getName()))return!1;let s=t.getExpression();for(;o.isCallExpression(s)||o.isElementAccessExpression(s)||o.isPropertyAccessExpression(s);){if(o.isPropertyAccessExpression(s)&&ma.has(s.getName())){const n=s.getExpression();if(o.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},xa=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return L(s)},Ut=new Set(["generateObject","generateText","streamObject","streamText"]),Ea=e=>{const t=A(e.getExpression());return t!==void 0&&Ut.has(t)},va=e=>{const t=A(e.getExpression());if(t===void 0||!Ut.has(t))return!1;const s=e.getArguments()[0];return!s||!o.isObjectLiteralExpression(s)||s.getProperties().some(n=>o.isSpreadAssignment(n))?!1:!s.getProperty("maxOutputTokens")},Sa=new Set(["log","span","trace"]),Aa=new Set(["ai"]),ya=new Set(["email","mail"]),Na=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),he=(e,t)=>e.getDescendantsOfKind(l.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"}),ba=new Set([l.ArrowFunction,l.FunctionDeclaration,l.FunctionExpression,l.GetAccessor,l.MethodDeclaration,l.SetAccessor]),Pa=new Set(["every","filter","flatMap","forEach","map","some"]),Ia=new Set(["all","allSettled","race"]),wa=e=>{const t=e.getParent();if(!t||!o.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName();if(Pa.has(n))return t;const i=s.getExpression();if(o.isIdentifier(i)&&i.getText()==="Promise"&&Ia.has(n))return t},Ta=e=>{let t=e.getParent();for(;t;){if(o.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(ba.has(t.getKind())){const s=wa(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},Ca=e=>{let t=e;for(;;){const s=t.getParent();if(!o.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(!o.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},Fa=e=>{let t=e;for(;;){const s=t.getParent();if(o.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return o.isCallExpression(s)&&s.getExpression()===t?s:void 0}},Oa=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression)){if(!Na.has(n.getName()))continue;const i=n.getExpression();if(!o.isIdentifier(i)||i.getText()!=="ctx")continue;const r=Fa(n);r&&(t=!0,!Ta(r)&&!Ca(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},Ra=e=>e.getDescendantsOfKind(l.ThrowStatement).some(t=>{const s=t.getExpression();if(!o.isNewExpression(s))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="Error"}),ht="lunora-advisor-exempt",La=/^[\s*/]+/u,Da=/[\w-]/u,ka=e=>{const s=(e.getFirstAncestorByKind(l.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
5
+ Install them with your package manager, then re-run codegen.`)},vn="env.ts",Sn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return ne(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},An=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&ne(n.getModuleSpecifierValue())}return!1},yn=e=>{if(o.isIdentifier(e))return Sn(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&o.isIdentifier(t)&&An(t)}return!1},Nn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!yn(n.getExpression()))continue;const r=s.getNameNode();if(!o.isIdentifier(r))throw se(r,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},bn=(e,t)=>{const s=f(t,vn);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=Nn(n);if(i.length!==0){if(i.length>1)throw se(n,`lunora/env.ts declares ${i.length.toString()} defineEnv() contracts (${i.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Pn=e=>{const t=n=>o.isIdentifier(n)&&n.getText()==="ctx",s=new Set;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression))t(n.getExpression())&&s.add(n.getName());for(const n of e.getDescendantsOfKind(l.VariableDeclaration)){const i=n.getInitializer(),r=n.getNameNode();if(!(i===void 0||!t(i)||!o.isObjectBindingPattern(r)))for(const a of r.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},In=(e,t)=>{const s=Object.fromEntries(ge.map(n=>[n.key,!1]));for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=new Set(i.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=Pn(i);for(const c of ge)if(!s[c.key]){if(r.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(ge.every(c=>s[c.key]))break}return s},wt="identity.ts",wn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return ne(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Tn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&ne(n.getModuleSpecifierValue())}return!1},Cn=e=>{if(o.isIdentifier(e))return wn(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&o.isIdentifier(t)&&Tn(t)}return!1},Fn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!Cn(n.getExpression()))continue;const r=s.getNameNode();if(!o.isIdentifier(r))throw se(r,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},On=(e,t)=>{const s=f(t,wt);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=Fn(n);if(i.length!==0){if(i.length>1)throw se(n,`lunora/identity.ts declares ${i.length.toString()} defineIdentity() contracts (${i.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Rn=(e,t)=>{const s=new Map,n=new Map,i=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.bindingName,`workflow "${r.exportName}"`),i.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const a=s.get(r.name);if(a!==void 0)throw new k("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${a} and agent "${r.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=n.get(r.bindingName);if(c!==void 0)throw new k("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${r.bindingName}": produced by both ${c} and agent "${r.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const u=i.get(r.className);if(u!==void 0)throw new k("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${u} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},Ln=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:i}=e,r=On(s,t),a=bn(s,t),c=Rs(s,t),u=Cs(s,t),d=cs(s,t);Rn(c,d);const x=ls(s,t),N=Os(s,t),p=Ls(In(s,t),Ds(n,e.target)),S=p.usage,C=Fs(s,t),F=S.browser||C.usesSandboxBrowser,O=Ts(n),V=O??new Set,R=V.has("lunorash");En(i,O);const _=b(f(t,"flags.ts")),z=b(f(t,"notify.ts"));return{agents:d,containers:x,dataModelContent:ds(i),declaredDependencies:O,dependencies:V,env:a,featureUsage:S,hasBrowser:F,hasFlags:_,hasNotify:z,identity:r,platformGate:p,queues:u,serverContent:us({agents:d,containers:x,env:a,hasAccessFacade:S.access,hasAi:S.ai,hasAnalytics:S.analytics,hasBrowser:F,hasFlags:_,hasHyperdrive:S.hyperdrive,hasImages:S.images,hasKv:S.kv,hasNotify:z,hasPayments:S.payments,hasPipelines:S.pipelines,hasR2sql:S.r2sql,hasX402:S.x402,identity:r,queues:u,schema:i,storageRuleBuckets:N.rules.map(oe=>oe.bucket),useUmbrella:R,workflows:c}),storageRulesMetadata:N,usesSandbox:C.usesSandboxBrowser||C.usesSandboxContainer,useUmbrella:R,workflows:c}},Tt=new Set(["delete","get","head","options","patch","post","put"]),Dn=new Set(["handler","stream"]),kn=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,st=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Mn=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Tt.has(t.getName()))return;const s=t.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!o.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},Kn=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||Tt.has(n.getName()))break;s=n.getExpression()}return Mn(s)},_n=e=>{for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression))if(st.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&st.has(s.getText()))return!0}return!1},zn=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||!Dn.has(n.getName()))return;const i=Kn(s);if(!i||!kn.test(i.path))return;const r=s.getArguments()[0],a=r!==void 0&&(o.isArrowFunction(r)||o.isFunctionExpression(r))&&_n(r);return{exportName:e.getName(),file:t,method:i.method,path:i.path,usesGuard:a}},Un=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=zn(i,t);r&&s.push(r)}return s},Bn=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Un(i,E(t,n)))}return s},qn=e=>!o.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",$n=(e,t)=>{if(!qn(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!T(s)||M(s)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},jn=(e,t)=>P(e,t,$n),Vn=new Set(["generateText","streamText"]),Wn=new Set(["messages","prompt","system"]),Hn=[{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"]}],Gn=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const i of Hn)if(i.methods.has(s)&&i.prefixes.some(r=>n===r||n.startsWith(`${r}.`)))return`${n}.${s}`},Yn=e=>{for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=Gn(t);if(s!==void 0)return s}},Qn=e=>{const t=new Set,s=e.getFirstAncestor(r=>o.isArrowFunction(r)||o.isFunctionExpression(r)||o.isFunctionDeclaration(r)),[n]=s?.getParameters()??[],i=n?.getNameNode();if(i===void 0||!o.isObjectBindingPattern(i))return t;for(const r of i.getElements()){const a=r.getPropertyNameNode()?.getText()??r.getName(),c=r.getNameNode();if(a==="args"&&o.isObjectBindingPattern(c))for(const u of c.getElements())t.add(u.getName())}return t},Xn=e=>{if(ks(e))return!0;const t=Qn(e);return t.size===0?!1:e.getDescendantsOfKind(l.Identifier).some(s=>t.has(s.getText()))},Zn=e=>{for(const t of e.getProperties()){if(!o.isPropertyAssignment(t)||!Wn.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&Xn(s))return!0}return!1},Jn=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=A(n.getExpression());if(i===void 0||!Vn.has(i))continue;const[r]=n.getArguments();if(r===void 0||!o.isObjectLiteralExpression(r))continue;let a;for(const c of r.getDescendantsOfKind(l.CallExpression))if(A(c.getExpression())==="tool"&&(a=Yn(c),a!==void 0))break;a!==void 0&&s.push({exportName:v(n),file:t,line:n.getStartLineNumber(),method:i,sideEffect:a,userInputDerived:Zn(r)})}return s},er=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Jn(i,E(t,n)))}return s},tr=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return o.isIdentifier(t)&&t.getText()==="ctx"},sr=(e,t)=>{if(!tr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!T(s)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},nr=(e,t)=>P(e,t,sr),Ct=e=>e.getProperties().some(t=>o.isSpreadAssignment(t)),rr=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!o.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer();return!n||!o.isObjectLiteralExpression(n)?{objects:[],opaque:!0}:{objects:[n],opaque:Ct(n)}},ir=e=>{const t=[];let s=!1,n=e;for(;o.isCallExpression(n);){const i=n.getExpression();if(!o.isPropertyAccessExpression(i))break;if(i.getName()==="input"){const r=n.getArguments()[0];r&&o.isObjectLiteralExpression(r)?(t.push(r),s||=Ct(r)):s=!0}n=i.getExpression()}return{objects:t,opaque:s}},Ft=(e,t)=>t?ir(t):rr(e),or=e=>e.flatMap(t=>t.getProperties().filter(s=>o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)).map(s=>s.getName())),ar=/\.check\(|\.meta\(|length|max/iu,cr=/\bv\.any\s*\(/u,lr=/\bv\.string\s*\(/u,ur=e=>cr.test(e),dr=e=>lr.test(e)&&!ar.test(e),fr=e=>{const t=[],s=[];for(const n of e)for(const i of n.getProperties()){if(!o.isPropertyAssignment(i))continue;const r=i.getInitializer();if(!r)continue;const a=r.getText(),c=i.getName();ur(a)?t.push(c):dr(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},pr=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=K(s);if(n?.visibility!=="public")return;const{objects:i}=Ft(s,n.receiver),{anyArgs:r,unboundedStringArgs:a}=fr(i);if(!(r.length===0&&a.length===0))return{anyArgs:r,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},gr=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=pr(i,t);r&&s.push(r)}return s},mr=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...gr(i,E(t,n)))}return s},me=e=>e?.getKind()===l.TrueKeyword,hr=e=>e?.getKind()===l.FalseKeyword,xr=e=>e!==void 0&&o.isNumericLiteral(e)&&e.getLiteralValue()===0,Er=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),vr=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isCallExpression(t)&&A(t.getExpression())==="scim"),Sr=e=>e!==void 0&&o.isCallExpression(e)&&Er.has(A(e.getExpression())??""),Ar=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isStringLiteral(t)&&t.getLiteralText()==="*"),yr=e=>{const t=y(e,"advanced"),s=y(e,"emailAndPassword"),n=y(e,"session");return{analyzable:!0,disableCsrfCheck:me(y(t,"disableCSRFCheck")),emailPasswordEnabled:me(y(s,"enabled")),requireEmailVerification:me(y(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:vr(y(e,"plugins"))&&Sr(y(e,"database")),secureCookiesDisabled:hr(y(t,"useSecureCookies")),sessionFreshAgeZero:xr(y(n,"freshAge")),trustedOriginsWildcard:Ar(y(e,"trustedOrigins"))}},Nr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),br=(e,t)=>{if(A(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&o.isObjectLiteralExpression(s)&&s.getProperties().some(r=>o.isSpreadAssignment(r)),i=s!==void 0&&o.isObjectLiteralExpression(s)&&!n?yr(s):Nr();return{exportName:v(e),file:t,line:e.getStartLineNumber(),...i}},Pr=(e,t)=>P(e,t,br),Ir=(e,t)=>{if(!o.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},wr=(e,t,s)=>{const n=Ir(e.getExpression(),s);if(n===void 0)return;const i=e.getArguments()[s.argIndex];if(!(!i||!T(i)||M(i))&&!(s.requireUnmodifiedReach===!0&&!Ms(i)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:n}},Tr=(e,t,s)=>{const n=[];for(const i of e.getDescendantsOfKind(l.CallExpression)){const r=wr(i,t,s);r&&n.push(r)}return n},ie=(e,t,s)=>{const n=[];for(const i of g(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...Tr(r,E(t,i),s))}return n},Cr=new Set(["content","pdf","scrape","screenshot"]),Fr=(e,t)=>ie(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Cr}),Or=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Rr=new Set(["RateLimiter"]),Lr=new Set(["extend"]),Ot=e=>{const t=[],s=[];let n=!1;for(const i of e.getProperties()){if(o.isSpreadAssignment(i)){n=!0;continue}if(o.isPropertyAssignment(i)){const r=i.getName();t.push(r),i.getInitializer()?.getKind()===l.TrueKeyword&&s.push(r);continue}(o.isShorthandPropertyAssignment(i)||o.isMethodDeclaration(i))&&t.push(i.getName())}return{analyzable:!n,presentKeys:t,trueKeys:s}},nt=e=>e&&o.isObjectLiteralExpression(e)?Ot(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Dr=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!o.isReturnStatement(s))return;const n=s.getExpression();return n!==void 0&&o.isObjectLiteralExpression(n)?n:void 0},kr=e=>{if(o.isObjectLiteralExpression(e))return e;if(o.isParenthesizedExpression(e)){const t=e.getExpression();return o.isObjectLiteralExpression(t)?t:void 0}return o.isBlock(e)?Dr(e):void 0},Mr=e=>{const t=e&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,s=t&&kr(t.getBody());return s?Ot(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Kr=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=A(n.getExpression());i!==void 0&&(Or.has(i)?s.push({callee:i,file:t,line:n.getStartLineNumber(),...nt(n.getArguments()[0])}):Lr.has(i)&&s.push({callee:i,file:t,line:n.getStartLineNumber(),...Mr(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(l.NewExpression)){const i=A(n.getExpression());i===void 0||!Rr.has(i)||s.push({callee:i,file:t,line:n.getStartLineNumber(),...nt(n.getArguments()[0])})}return s},_r=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Kr(i,E(t,n)))}return s},rt="ctx.containers.",zr=e=>{if(!e.startsWith(rt))return!1;const t=e.slice(rt.length);return t.length>0&&!t.includes(".")},Ur=(e,t)=>ie(e,t,{argIndex:0,matchReceiver:zr,methods:new Set(["get"])}),Br=new Set(["allow","deny","setAllowed"]),qr=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&o.isPropertyAssignment(s)&&o.isTrueLiteral(s.getInitializerOrThrow())},$r=(e,t)=>{const s=e.getExpression();if(!(!o.isPropertyAccessExpression(s)||s.getName()!=="start"||!qr(e)))return{detail:"enableInternet: true",exportName:v(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},jr=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||!Br.has(s.getName()))return;const n=s.getExpression();if(!(!o.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),exportName:v(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},Vr=(e,t)=>$r(e,t)??jr(e,t),Wr=(e,t)=>P(e,t,Vr),Hr=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Gr=e=>{const t=e.getExpression();if(!o.isIdentifier(t))return;const s=t.getText();return Hr.has(s)?s:void 0},Yr=e=>{const t=[],s=[];for(const n of e.getProperties()){if(o.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(o.isPropertyAssignment(n)){const i=n.getName();t.push(i);const r=n.getInitializer();r&&o.isStringLiteral(r)&&r.getLiteralText()===""&&s.push(i);continue}(o.isShorthandPropertyAssignment(n)||o.isMethodDeclaration(n)||o.isGetAccessorDeclaration(n))&&t.push(n.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Qr=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getDescendantsOfKind(l.CallExpression)){const c=Gr(a);if(c===void 0)continue;const u=a.getArguments()[0],d=u&&o.isObjectLiteralExpression(u)?Yr(u):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:d.analyzable,emptyKeys:d.emptyKeys,factory:c,file:r,line:a.getStartLineNumber(),presentKeys:d.presentKeys})}}return s},Xr=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Zr=new Set(["dbRateLimit","rateLimit"]),Jr=e=>{if(!e||!o.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&o.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===l.TrueKeyword},ei=(e,t)=>{const s=A(e.getExpression());if(s===void 0)return;const n=Xr.get(s);if(n!==void 0)return{callee:s,exportName:v(e),failOpen:Jr(e.getArguments()[n]),file:t,limitName:Zr.has(s)?yt(e):"",line:e.getStartLineNumber()}},ti=(e,t)=>P(e,t,ei),si=new Set(["boolean","number","object","string"]),ni=e=>{const t=e.getName();if(!si.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="flags"&&Ee(s.getExpression()))return t;const n=s.getExpression();if(s.getName()==="details"&&o.isPropertyAccessExpression(n)&&n.getName()==="flags"&&Ee(n.getExpression()))return t},ri=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=ni(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(o.isStringLiteral(n)||o.isNoSubstitutionTemplateLiteral(n)))return;const i=n.getLiteralValue();return i.length>0?{key:i,type:s}:void 0},ii=(e,t)=>{const s=new Map;for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of i.getDescendantsOfKind(l.CallExpression)){const a=ri(r);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))},oi=e=>{const t=e.getInitializer();if(!t||!o.isCallExpression(t))return;const s=K(t);if(s?.kind!=="query")return;const n=Is(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},it=e=>{const t=e.getParent();return t&&o.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},ai=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!o.isIdentifier(t)||t.getText()!=="ctx")return;const s=it(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=it(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},ci=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const i=ai(n);i!==void 0&&s.push({callee:i,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},li=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=oi(i);r&&s.push(...ci(r,t))}return s},ui=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...li(i,E(t,n)))}return s},di=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Ee(t.getExpression())},fi=e=>{if(e?.getKind()===l.TrueKeyword)return!0;if(e?.getKind()===l.FalseKeyword)return!1},pi=(e,t)=>{if(!di(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(o.isStringLiteral(s)||o.isNoSubstitutionTemplateLiteral(s)))return;const i=s.getLiteralValue(),r=fi(n);if(!(i.length===0||r===void 0))return{defaultValue:r,exportName:v(e),file:t,key:i,line:e.getStartLineNumber()}},gi=(e,t)=>P(e,t,pi),mi=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),r=i.getText(e);if(!r||r==="any"||r==="never"||$s(r))return;const a=e.getSourceFile().getFilePath();return js(i,e,a)?Vs(i,e,a,0,new Set):r},hi=e=>{const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},xi=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},Ei=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getDescendantsOfKind(l.CallExpression))hi(a)&&s.push({file:r,indexName:xi(a),line:a.getStartLineNumber()})}return s},j=e=>e!==void 0&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,Rt=e=>{const t=e.getArguments()[0],s=j(t);if(s!==void 0)return s;if(t===void 0||!o.isObjectLiteralExpression(t))return;const n=t.getProperty("handler");return n!==void 0&&o.isPropertyAssignment(n)?j(n.getInitializer()):void 0},vi=new Set(["delete","get","head","options","patch","post","put"]),Si=new Set(["handler","stream"]),Ai=new Set(["runAction","runMutation"]),yi=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),Z=(e,t)=>e!==void 0&&o.isIdentifier(e)&&e.getText()===t,ot=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const n=s.getNameNode();if(t)return o.isIdentifier(n)?n.getText():void 0;if(o.isObjectBindingPattern(n)){for(const i of n.getElements())if((i.getPropertyNameNode()?.getText()??i.getNameNode().getText())==="ctx"){const a=i.getNameNode();return o.isIdentifier(a)?a.getText():void 0}}},at=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);o.isCallExpression(s)&&n.unshift(s);for(const i of n){const r=i.getExpression();if(!o.isPropertyAccessExpression(r))continue;const a=r.getName(),c=r.getExpression();if(Ai.has(a)&&Z(c,t))return a;if(yi.has(a)&&o.isPropertyAccessExpression(c)&&c.getName()==="db"&&Z(c.getExpression(),t))return`db.${a}`}},ct=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(l.PropertyAccessExpression))if(n.getName()==="auth"&&Z(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(l.VariableDeclaration)){const i=n.getNameNode();if(!(!o.isObjectBindingPattern(i)||!Z(n.getInitializer(),t))){for(const r of i.getElements())if((r.getPropertyNameNode()?.getText()??r.getNameNode().getText())==="auth")return!0}}return!1},Ni=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Si.has(t.getName()))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))return;const i=n.getName();if(vi.has(i)){const r=n.getExpression();return o.isIdentifier(r)&&r.getText()==="httpRoute"?i.toUpperCase():void 0}s=n.getExpression()}},bi=(e,t)=>{const s=e.getExpression();if(o.isIdentifier(s)&&s.getText()==="httpAction"){const c=j(e.getArguments()[0]),u=c&&ot(c,!0);if(!c||u===void 0)return;const d=at(c,u);return d===void 0?void 0:{exportName:v(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ct(c,u),sideEffect:d}}const n=Ni(e);if(n===void 0)return;const i=j(e.getArguments()[0]),r=i&&ot(i,!1);if(!i||r===void 0)return;const a=at(i,r);return a===void 0?void 0:{exportName:v(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:ct(i,r),sideEffect:a}},Pi=(e,t)=>P(e,t,bi),Ii=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),wi=new Set(["append","set"]),Lt=e=>e!==void 0&&(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",lt=(e,t)=>(o.isCallExpression(e)?[e,...e.getDescendantsOfKind(l.CallExpression)]:e.getDescendantsOfKind(l.CallExpression)).some(n=>Ii.has(A(n.getExpression())??"")&&_s(n,t)),Ti=(e,t)=>{if(lt(e,t))return!0;const s=re(e);return s!==void 0&&lt(s,t)},ve=(e,t)=>Ks(e,t)&&!Ti(e,t),Ci=e=>{if(o.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=re(e);return t!==void 0&&o.isNewExpression(t)&&A(t.getExpression())==="Headers"},J=e=>{if(e===void 0)return;if(o.isObjectLiteralExpression(e))return e;const t=re(e);return t!==void 0&&o.isObjectLiteralExpression(t)?t:void 0},ye=(e,t,s)=>{for(const n of e.getProperties())if(o.isPropertyAssignment(n)){const i=n.getInitializer();i!==void 0&&ve(i,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:Lt(n.getNameNode()),line:i.getStartLineNumber(),via:t})}else if(o.isShorthandPropertyAssignment(n)){const i=n.getNameNode();ve(i,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:n.getName(),line:i.getStartLineNumber(),via:t})}else if(o.isSpreadAssignment(n)){const i=J(n.getExpression());i!==void 0&&ye(i,t,s)}},Dt=(e,t)=>{const s=J(e);if(s===void 0)return;const n=s.getProperty("headers");if(n===void 0||!o.isPropertyAssignment(n))return;const i=J(n.getInitializer());i!==void 0&&ye(i,"response-init",t)},Fi=(e,t)=>{const s=A(e.getExpression());if(s==="Response")Dt(e.getArguments()[1],t);else if(s==="Headers"){const n=J(e.getArguments()[0]);n!==void 0&&ye(n,"headers-ctor",t)}},Oi=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName(),i=s.getExpression();if(n==="json"&&o.isIdentifier(i)&&i.getText()==="Response"){Dt(e.getArguments()[1],t);return}if(wi.has(n)&&Ci(i)){const r=e.getArguments()[1];r!==void 0&&ve(r,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:Lt(e.getArguments()[0]),line:r.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},Ri=(e,t)=>{for(const s of e.getDescendantsOfKind(l.NewExpression))Fi(s,t);for(const s of e.getDescendantsOfKind(l.CallExpression))Oi(s,t)},Li=(e,t)=>{const s=e.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=j(e.getArguments()[0]);if(n===void 0)return[];const i=n.getParameters()[1];if(i===void 0)return[];const r=i.getNameNode();if(!o.isIdentifier(r))return[];const a=[];return Ri(n,{exportName:v(e),relativePath:t,requestName:r.getText(),rows:a}),a},Di=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression))s.push(...Li(n,t));return s},ki=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Di(i,E(t,n)))}return s},Mi=new Set(["auth","context.auth","ctx.auth"]),Ki="userId",_i=e=>{const t=new Set;for(const s of e.getProperties()){if(o.isSpreadAssignment(s))return;(o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)||o.isMethodDeclaration(s))&&t.add(s.getName())}return t},zi=(e,t)=>{const s=f(t,wt);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const i of n.getDescendantsOfKind(l.CallExpression)){if(A(i.getExpression())!=="defineIdentity")continue;const[r]=i.getArguments();return r&&o.isObjectLiteralExpression(r)?_i(r):void 0}},ut=e=>{if(!(e===void 0||!o.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Mi.has(e.getExpression().getText())?e:void 0},Ui=e=>{if(o.isPropertyAccessExpression(e)&&ut(e.getExpression())!==void 0)return e.getName();if(o.isElementAccessExpression(e)&&ut(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&o.isStringLiteral(t)?t.getLiteralValue():void 0}},Bi=(e,t,s)=>{const n=[];for(const i of e.getDescendants()){const r=Ui(i);r!==void 0&&n.push({declared:r===Ki||s.has(r),exportName:v(i),file:t,key:r,line:i.getStartLineNumber()})}return n},qi=(e,t)=>{const s=zi(e,t);if(s===void 0)return[];const n=[];for(const i of g(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...Bi(r,E(t,i),s))}return n},$i=(e,t)=>{if(A(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=y(s,"key");if(!(!n||!T(n)||M(n)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},ji=(e,t)=>P(e,t,$i),Vi=new Set(["delete","get","getRaw","getWithMetadata","put"]),Wi=(e,t)=>ie(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:Vi}),Hi=new Set(["queue","send"]),dt=new Set(["bcc","cc","to"]),Gi=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!Hi.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},Yi=e=>o.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(o.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return dt.has(t.getName())&&T(n)&&!M(n)}if(!o.isPropertyAssignment(t)||!dt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&T(s)&&!M(s)}):!1,Qi=(e,t)=>{const s=Gi(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!Yi(n)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s}},Xi=(e,t)=>P(e,t,Qi),Zi=e=>o.isPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?o.isComputedPropertyName(e.getNameNode()):!1,Ji=e=>o.isPropertyAssignment(e)||o.isShorthandPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?Zi(e):!0,kt=(e,t=!1)=>{for(const s of e.getProperties()){if(Ji(s))return!0;if(t)continue;if(!o.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!o.isObjectLiteralExpression(n)||kt(n,!0))return!0}return!1},eo=(e,t)=>{for(const s of g(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:i}of It(n))for(const r of Ae(i)){const a=r.getArguments()[0];if(a!==void 0&&(!o.isObjectLiteralExpression(a)||kt(a)))return!0}}return!1},to=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const i=X(n);if(i===void 0||!o.isPropertyAssignment(n))continue;const r=n.getInitializer();if(!(!r||!o.isObjectLiteralExpression(r)))for(const a of r.getProperties()){const c=X(a);c!==void 0&&s.push({column:c,strategy:Pt(a),table:i})}}return s},so=(e,t)=>{const s=new Map;for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:r}of It(i))for(const a of Ae(r))for(const c of to(a)){const u=`${c.table}\0${c.column}`;s.has(u)||s.set(u,c)}}return{columns:[...s.values()]}},no=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!o.isObjectLiteralExpression(n))return[];const i=[];for(const r of n.getProperties()){const a=X(r);if(a===void 0||!o.isPropertyAssignment(r))continue;const c=r.getInitializer();if(!(!c||!o.isObjectLiteralExpression(c)))for(const u of c.getProperties()){const d=X(u);if(d===void 0)continue;const x=Pt(u);x!=="custom"&&i.push({column:d,exportName:t,file:s,line:u.getStartLineNumber(),strategy:x,table:a})}}return i},ro=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?K(s):void 0;return n?.receiver?Ae(n.receiver).flatMap(i=>no(i,e.getName(),t)):[]},io=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...ro(c,r))}return s},oo=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return L(s)},ao=e=>{const t=e.getArguments()[0];if(t===void 0||!o.isObjectLiteralExpression(t))return;const s=t.getProperty("server");if(s!==void 0)return o.isPropertyAssignment(s)?s.getInitializer():s},co=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==l.CallExpression)return;const s=t;return Qs(s.getExpression())?s:void 0},lo=e=>{const t=co(e),s=t===void 0?void 0:ao(t);if(s===void 0)return[];const n=e.getNameNode(),i=o.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(l.CallExpression).filter(r=>oo(r)).map(r=>({exportName:i,file:"lunora/mutators.ts",line:r.getStartLineNumber()}))},uo=e=>e.getVariableDeclarations().flatMap(t=>lo(t)),fo=(e,t)=>{const s=f(t,Ys);if(!b(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return uo(n)},po=new Set(["delete","get","patch"]),go=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),mo=new Set(["auth","identity","session","user"]),ho=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),xo=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!L(t.getExpression()))return;const s=e.getArguments()[0];return s&&o.isStringLiteral(s)?s.getLiteralText():""},Eo=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(o.isAsExpression(s)||o.isParenthesizedExpression(s)||o.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!o.isVariableDeclaration(s))return;const n=s.getNameNode();return o.isIdentifier(n)?n.getText():void 0},vo=(e,t)=>e.getDescendantsOfKind(l.Identifier).some(s=>s.getText()===t),So=e=>o.isThrowStatement(e)||o.isReturnStatement(e)||e.getDescendantsOfKind(l.ThrowStatement).length>0||e.getDescendantsOfKind(l.ReturnStatement).length>0,Ao=(e,t)=>e.getDescendantsOfKind(l.IfStatement).some(s=>vo(s.getExpression(),t)&&So(s.getThenStatement())),yo=(e,t)=>{for(const s of e.getDescendantsOfKind(l.CallExpression)){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))continue;const i=n.getName();if(!po.has(i))continue;const r=n.getExpression();if(!(L(r)||o.isPropertyAccessExpression(r)&&L(r.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&o.isIdentifier(c)&&c.getText()===t)return i}},No=e=>{let t=e;for(;o.isPropertyAccessExpression(t)||o.isElementAccessExpression(t)||o.isNonNullExpression(t)||o.isParenthesizedExpression(t)||o.isAsExpression(t)||o.isAwaitExpression(t);)t=t.getExpression();return o.isIdentifier(t)?t.getText():void 0},bo=e=>e.getDescendantsOfKind(l.CallExpression).some(t=>t.getArguments().some(s=>No(s)==="ctx")),Po=e=>e.getDescendantsOfKind(l.BinaryExpression).some(t=>ho.has(t.getOperatorToken().getKind())?o.isPropertyAccessExpression(t.getLeft())||o.isPropertyAccessExpression(t.getRight()):!1),Io=e=>{for(const t of e.getDescendantsOfKind(l.Identifier))if(go.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&s.getText()==="ctx"&&mo.has(t.getName()))return!0}return bo(e)||Po(e)},wo=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=K(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const i=Rt(s);if(i===void 0)return[];const r=n.receiver!==void 0&&bt(n.receiver,"use","rls"),a=Io(i),c=new Set,u=[];for(const d of i.getDescendantsOfKind(l.CallExpression)){const x=xo(d);if(x===void 0)continue;const N=Eo(d);if(N===void 0||c.has(N)||!Ao(i,N))continue;const p=yo(i,N);p!==void 0&&(c.add(N),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:p,table:x,usesRls:r,visibility:n.visibility}))}return u},To=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...wo(c,r))}return s},Co=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Fo=new Set(["insert","insertManyUnsafe","patch","replace"]),Oo=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!Fo.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||s.getName()!=="db")return;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"?t:void 0},Ro=(e,t)=>{if(t!=="insertManyUnsafe")return o.isObjectLiteralExpression(e)?[e]:[];if(!o.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())o.isObjectLiteralExpression(n)&&s.push(n);return s},Lo=(e,t,s,n)=>{const i=[];for(const r of e.getProperties()){let a,c;o.isPropertyAssignment(r)?(a=r.getName(),c=r.getInitializer()):o.isShorthandPropertyAssignment(r)&&(a=r.getName(),c=r.getNameNode()),!(a===void 0||c===void 0||!Co.has(a))&&T(c)&&!M(c)&&i.push({exportName:v(s),field:a,file:n,line:s.getStartLineNumber(),method:t})}return i},Do=(e,t)=>{const s=Oo(e.getExpression());if(s===void 0)return[];const n=e.getArguments()[1];return n?Ro(n,s).flatMap(i=>Lo(i,s,e,t)):[]},ko=(e,t,s)=>{const n=[];for(const i of e.getDescendantsOfKind(l.CallExpression))for(const r of Do(i,t)){const a=s(r.exportName);n.push(a===void 0?r:{...r,visibility:a})}return n},Mo=(e,t,s=[])=>{const n=[],i=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));for(const r of g(t)){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=E(t,r);n.push(...ko(a,c,u=>i.get(`${c}:${u}`)))}return n},Ko=["providerSubscriptionId","state"],_o=["providerEventId","processedAt"],ft=(e,t)=>t.every(s=>s in e.shape),zo=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&ft(t,Ko)&&ft(s,_o)},Uo=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Bo=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,qo=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&o.isPropertyAssignment(t)?Bo(t.getInitializer()):void 0},$o=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!Uo.has(s))return;const[n]=e.getArguments(),i=n&&o.isObjectLiteralExpression(n)?qo(n):void 0;return{callee:s,exportName:v(e),file:t,line:e.getStartLineNumber(),...i===void 0?{}:{toleranceSeconds:i}}},jo=(e,t)=>P(e,t,$o),Vo=new Set(["defineQueue","defineWorkflow"]),Wo=new Set(["run","runAction","runMutation","runQuery"]),Ho=new Set(["api","internal"]),Go=e=>{const t=e.getExpression();return o.isIdentifier(t)?t.getText():void 0},Yo=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!o.isPropertyAssignment(s))return;const n=s.getInitializer();if(n&&(o.isArrowFunction(n)||o.isFunctionExpression(n)))return n},Mt=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&o.isIdentifier(s)?s.getText():void 0},Kt=(e,t)=>e===t||e.startsWith(`${t}.`),_t=e=>{const t=e.getDescendantsOfKind(l.PropertyAccessExpression);return o.isPropertyAccessExpression(e)&&t.push(e),t},pt=e=>{const t=e.getParent();return o.isPropertyAccessExpression(t)&&t.getNameNode()===e||o.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(o.isBindingElement(t)&&t.getNameNode()===e)},zt=e=>{const t=e.getDescendantsOfKind(l.Identifier).filter(s=>pt(s));return o.isIdentifier(e)&&pt(e)&&t.push(e),t},Qo=e=>{if(!o.isVariableDeclaration(e))return[];const t=e.getNameNode();return o.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(l.BindingElement).map(s=>s.getName())},Xo=e=>{const t=Mt(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(l.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const i=n.getInitializer(),r=o.isVariableDeclarationList(i)?i.getDeclarations()[0]?.getNameNode():void 0;r&&o.isIdentifier(r)&&s.push(`${r.getText()}.body`)}return s},Zo=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:Xo(e),i=new Set,r=a=>_t(a).some(c=>n.some(u=>Kt(c.getText(),u)))?!0:zt(a).some(c=>i.has(c.getText()));for(const a of e.getDescendantsOfKind(l.VariableDeclaration)){const c=a.getInitializer();if(c&&r(c))for(const u of Qo(a))i.add(u)}return{names:i,prefixes:n}},Jo=(e,t)=>_t(e).some(s=>t.prefixes.some(n=>Kt(s.getText(),n)))?!0:zt(e).some(s=>t.names.has(s.getText())),ea=e=>{if(e===void 0||!o.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;o.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const n=t.at(-1);if(!(n===void 0||!o.isIdentifier(s)||!Ho.has(s.getText())||t.length<2))return{exportName:n,file:t.slice(0,-1).join("/")}},ta=(e,t,s)=>{const n=Mt(e,0);if(n===void 0)return[];const i=Zo(e,t,n),r=[];for(const a of e.getDescendantsOfKind(l.CallExpression)){const c=a.getExpression();if(!o.isPropertyAccessExpression(c)||!Wo.has(c.getName())||c.getExpression().getText()!==n)continue;const u=a.getArguments()[1];if(!u||!Jo(u,i))continue;const d=ea(a.getArguments()[0]);d!==void 0&&r.push({dispatchKind:t,file:s,handlerExport:v(a),line:a.getStartLineNumber(),targetExport:d.exportName,targetFile:d.file})}return r},sa=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=Go(n);if(i===void 0||!Vo.has(i))continue;const r=Yo(n);r!==void 0&&s.push(...ta(r,i==="defineQueue"?"queue":"workflow",t))}return s},na=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...sa(i,E(t,n)))}return s},gt={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},mt=new Set(["account","credential","member","passkey","session","user"]),ra=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),ia=e=>{const s=ra(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return mt.has(s)||mt.has(n)},oa=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},aa=(e,t)=>{const{objects:s,opaque:n}=Ft(e,t);return or(s).some(i=>oa(i))?!0:n?void 0:!1},ca=e=>{const t=e.getArguments()[0];return!t||!o.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},la=e=>{if(o.isCallExpression(e))return e;if(!o.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&o.isCallExpression(s)?s:void 0},Q={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},ua=e=>{const t=la(e),s=t?A(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=ca(t);return{...Q,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in gt?{...Q,[gt[s]]:!0}:Q},da=e=>{const t={...Q};let s=e;for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))break;const i=n.getName()==="use"?s.getArguments()[0]:void 0;if(i){const r=ua(i);t.usesCaptcha||=r.usesCaptcha,t.usesEmailGate||=r.usesEmailGate,t.usesMask||=r.usesMask,t.usesRateLimit||=r.usesRateLimit,t.usesRls||=r.usesRls}s=n.getExpression()}return t},fa=new Set(["insert","insertMany","insertManyUnsafe","replace"]),pa=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!fa.has(t.getName()))return!1;const s=t.getExpression();if(!L(s))return!1;const i=e.getArguments()[0];return!i||!(o.isStringLiteral(i)||o.isNoSubstitutionTemplateLiteral(i))?!1:ia(i.getLiteralText())},ga=new Set(["create","runAfter","runAt","send","sendBatch"]),ma=new Set(["queues","scheduler","workflows"]),ha=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!ga.has(t.getName()))return!1;let s=t.getExpression();for(;o.isCallExpression(s)||o.isElementAccessExpression(s)||o.isPropertyAccessExpression(s);){if(o.isPropertyAccessExpression(s)&&ma.has(s.getName())){const n=s.getExpression();if(o.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},xa=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return L(s)},Ut=new Set(["generateObject","generateText","streamObject","streamText"]),Ea=e=>{const t=A(e.getExpression());return t!==void 0&&Ut.has(t)},va=e=>{const t=A(e.getExpression());if(t===void 0||!Ut.has(t))return!1;const s=e.getArguments()[0];return!s||!o.isObjectLiteralExpression(s)||s.getProperties().some(n=>o.isSpreadAssignment(n))?!1:!s.getProperty("maxOutputTokens")},Sa=new Set(["log","span","trace"]),Aa=new Set(["ai"]),ya=new Set(["email","mail"]),Na=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),he=(e,t)=>e.getDescendantsOfKind(l.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"}),ba=new Set([l.ArrowFunction,l.FunctionDeclaration,l.FunctionExpression,l.GetAccessor,l.MethodDeclaration,l.SetAccessor]),Pa=new Set(["every","filter","flatMap","forEach","map","some"]),Ia=new Set(["all","allSettled","race"]),wa=e=>{const t=e.getParent();if(!t||!o.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName();if(Pa.has(n))return t;const i=s.getExpression();if(o.isIdentifier(i)&&i.getText()==="Promise"&&Ia.has(n))return t},Ta=e=>{let t=e.getParent();for(;t;){if(o.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(ba.has(t.getKind())){const s=wa(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},Ca=e=>{let t=e;for(;;){const s=t.getParent();if(!o.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(!o.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},Fa=e=>{let t=e;for(;;){const s=t.getParent();if(o.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return o.isCallExpression(s)&&s.getExpression()===t?s:void 0}},Oa=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression)){if(!Na.has(n.getName()))continue;const i=n.getExpression();if(!o.isIdentifier(i)||i.getText()!=="ctx")continue;const r=Fa(n);r&&(t=!0,!Ta(r)&&!Ca(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},Ra=e=>e.getDescendantsOfKind(l.ThrowStatement).some(t=>{const s=t.getExpression();if(!o.isNewExpression(s))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="Error"}),ht="lunora-advisor-exempt",La=/^[\s*/]+/u,Da=/[\w-]/u,ka=e=>{const s=(e.getFirstAncestorByKind(l.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
6
6
  `);for(const n of s.split(`
7
- `)){const i=n.replace(La,"");if(!i.startsWith(ht))continue;const r=i.slice(ht.length);if(Da.test(r.charAt(0)))continue;const a=r.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":r.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},Ma=e=>{const[t]=e.getArguments();if(t){if(o.isObjectLiteralExpression(t)){const s=t.getProperty("handler");return s?o.isPropertyAssignment(s)?s.getInitializer():o.isShorthandPropertyAssignment(s)?s.getNameNode():o.isMethodDeclaration(s)?s:void 0:void 0}return t}},Ka=(e,t)=>{const s=Ma(t);if(!s)return;if(o.isArrowFunction(s)||o.isFunctionExpression(s)||o.isMethodDeclaration(s))return e;if(!o.isIdentifier(s))return;const n=s.getSourceFile(),i=s.getText(),r=n.getVariableDeclaration(i)?.getInitializer();return r&&(o.isArrowFunction(r)||o.isFunctionExpression(r))?r:n.getFunction(i)},_a=e=>{let t=!1,s=!1,n=!1,i=!1,r=!1;for(const u of e.getDescendantsOfKind(l.CallExpression))if(pa(u)&&(r=!0),ha(u)&&(t=!0),xa(u)&&(i=!0),Ea(u)&&(s=!0),va(u)&&(n=!0),r&&t&&i&&n)break;const{handlesErrors:a,reachesOutbound:c}=Oa(e);return{callsMail:he(e,ya),emitsEvent:he(e,Sa),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||he(e,Aa),throwsBareError:Ra(e),unboundedAiGeneration:n,usesInsertManyUnsafe:i,writesUserTable:r}},za=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=K(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const i=n.receiver?da(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},r=Ka(e,s);return{...r?_a(r):{},...ka(e),...i,analyzableBody:r!==void 0,exportName:e.getName(),file:t,hasEmailArg:aa(s,n.receiver),kind:n.kind,visibility:n.visibility}},Ua=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=za(i,t);r&&s.push(r)}return s},Ba=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ua(i,E(t,n)))}return s},qa=new Set(["dbRateLimit","rateLimit"]),$a=e=>o.isArrowFunction(e)?e.getBody():e,ja=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!qa.has(s))return;const n=e.getArguments()[2];if(!n)return;const i=y(n,"key");if(!i)return;const r=$a(i);if(!(!T(r)||M(r)))return{callee:s,exportName:v(e),file:t,limitName:yt(e),line:e.getStartLineNumber()}},Va=(e,t)=>P(e,t,ja),Wa=new Set(["findFirst","findFirstOrThrow","findMany","get"]),Ha=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Wa.has(t.getName()))return;const s=t.getExpression();if(L(s)){const n=e.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}if(o.isPropertyAccessExpression(s)&&L(s.getExpression()))return s.getName()},Ga=e=>{let t=e;for(;o.isCallExpression(t);){const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&L(s.getExpression())){const n=t.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},Ya=e=>{let t=Ze(e)??e;for(;o.isAwaitExpression(t);)t=Ze(t.getExpression())??t.getExpression();return t},Bt=(e,t=!1)=>{const s=Ya(e);if(o.isIdentifier(s)){if(t)return;const n=re(s);return n===void 0?void 0:Bt(n,!0)}if(o.isCallExpression(s))return Ha(s)??Ga(s)},Qa=e=>{const t=e.getBody();if(!o.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(l.ReturnStatement)){const i=n.getFirstAncestor(a=>o.isArrowFunction(a)||o.isFunctionExpression(a)||o.isFunctionDeclaration(a)),r=n.getExpression();i===e&&r!==void 0&&s.push(r)}return s},Xa=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=K(s);if(n?.kind!=="query")return[];const i=Rt(s);if(i===void 0)return[];const r=n.receiver!==void 0&&Us(n.receiver,"output"),a=n.receiver!==void 0&&bt(n.receiver,"use","mask"),c=new Set,u=[];for(const d of Qa(i)){const h=Bt(d);h===void 0||c.has(h)||(c.add(h),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:h,usesMask:a,usesOutput:r,visibility:n.visibility}))}return u},Za=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Xa(c,r))}return s},Ja=e=>{if(!e||!o.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)||o.isMethodDeclaration(s)||o.isGetAccessorDeclaration(s))&&t.push(s.getName());return t},ec=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?K(s):void 0;if(!n)return[];const i=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Nt(r);if(a===void 0)continue;const c=Ja(y(a.options,"with"));c.length!==0&&i.push({exportName:e.getName(),file:t,line:r.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return i},tc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...ec(c,r))}return s},ee=e=>{if(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(o.isBinaryExpression(e)&&e.getOperatorToken().getKind()===l.PlusToken){const t=ee(e.getLeft()),s=ee(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},sc=e=>{let t=e,s=t.getParent();for(;s!==void 0&&o.isBinaryExpression(s)&&s.getOperatorToken().getKind()===l.PlusToken;)t=s,s=t.getParent();return t!==e&&ee(t)!==void 0},nc=/(?:^|\/)__tests__\//u,rc=/\.(?:spec|test)$/u,ic=e=>nc.test(e)||rc.test(e),oc=e=>{const t=e.getParent();if(t!==void 0){if(o.isVariableDeclaration(t)||o.isPropertyAssignment(t)||o.isPropertySignature(t))return t.getName();if(o.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.EqualsToken)return t.getLeft().getText()}},ac=(e,t,s)=>an(e)?!ic(s)&&cn(oc(t)):!0,cc=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(l.BinaryExpression),...e.getDescendantsOfKind(l.StringLiteral),...e.getDescendantsOfKind(l.NoSubstitutionTemplateLiteral)],i=new Set;for(const r of n){if(sc(r))continue;const a=ee(r);if(a===void 0)continue;const c=rn(a);if(c===void 0||!ac(c,r,t))continue;const u=r.getStartLineNumber(),d=`${String(u)}:${c}`;i.has(d)||(i.add(d),s.push({file:t,kind:c,line:u,preview:on(a)}))}return s},lc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...cc(i,E(t,n)))}return s},uc=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?K(s):void 0;if(!n)return[];const i=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Nt(r);if(a===void 0)continue;const c=y(a.options,"includeDeleted");if(c===void 0)continue;const u=o.isTrueLiteral(c),d=!u&&T(c);!u&&!d||i.push({exportName:e.getName(),file:t,fromArgs:d,hardcodedTrue:u,line:r.getStartLineNumber(),table:a.table,visibility:n.visibility})}return i},dc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...uc(c,r))}return s},fc=new Set(["query","unsafe"]),pc=e=>{if(!o.isPropertyAccessExpression(e)||!fc.has(e.getName()))return!1;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return o.isIdentifier(s)&&s.getText()==="ctx"},gc=e=>o.isBinaryExpression(e)||o.isTemplateExpression(e),mc=e=>e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()??"<module>",hc=(e,t)=>{if(!pc(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!gc(s)))return{exportName:mc(e),file:t,line:s.getStartLineNumber()}},xc=(e,t)=>P(e,t,hc),Ec=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],vc=e=>{for(const[t,s]of Ec)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},Sc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of i.getImportDeclarations()){const a=r.getModuleSpecifierValue(),c=vc(a);c!==void 0&&s.push({file:E(t,n),line:r.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},Ac=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),yc=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return ie(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:Ac,requireUnmodifiedReach:!0}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},Nc=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),bc=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,Pc=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!o.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const i of e.getProperties()){if(o.isSpreadAssignment(i)){n=!0;continue}if(o.isPropertyAssignment(i)){const r=i.getName();t.push(r),r==="expiresInSeconds"&&(s=bc(i.getInitializer()));continue}(o.isShorthandPropertyAssignment(i)||o.isMethodDeclaration(i))&&t.push(i.getName())}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},Ic=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName(),s=Nc.get(t);if(s===void 0)return;const n=e.getExpression().getText();return n==="ctx.storage"||n.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},wc=(e,t)=>{const s=Ic(e.getExpression());if(s!==void 0)return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s.method,...Pc(e.getArguments()[s.optionsIndex])}},Tc=(e,t)=>P(e,t,wc),Cc=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),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/kv"),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:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),Fc=new Set(["RegisteredAction","RegisteredMutation","RegisteredQuery"]),Ne=e=>{const t=e.getType(),s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName();return s!==void 0&&Fc.has(s)?s:void 0},qt=e=>{const t=e.getInitializer();return t===void 0?!1:o.isCallExpression(t)||o.isIdentifier(t)||o.isPropertyAccessExpression(t)},$t={cause:"codegen recognises a procedure only when the initializer is a builder chain, and this one is produced by a call or an alias",remediation:"A factory that returns a procedure cannot be read statically — inline it, or export the chain the factory builds."},Oc={cause:"the binding is exported by a separate `export { … }` statement, and codegen reads the `export` keyword on the declaration itself",remediation:"Move the keyword onto the declaration and drop the separate export statement."},be=(e,t,s,n,i)=>({cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally a builder chain. A procedure written any other way exists at runtime but never reaches `_generated/api.ts`, so no caller can address it.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${s}\` but was not registered — ${i.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:s},name:"procedure_not_registered",remediation:`Assign the builder chain directly: \`export const ${t} = query.input({ … }).query(handler);\`. ${i.remediation}`,title:"Procedure exists at runtime but is missing from the generated API"}),Rc=(e,t,s)=>{const n=[];for(const i of e.getVariableStatements().filter(r=>r.isExported()))for(const r of i.getDeclarations()){const a=r.getName();if(s.has(`${t}:${a}`)||!qt(r))continue;const c=Ne(r);c!==void 0&&n.push(be(t,a,c,r.getStartLineNumber(),$t))}return n},Lc=(e,t,s)=>{if(s.has(`${t}:default`))return[];const n=[];for(const i of e.getExportAssignments().filter(r=>!r.isExportEquals())){const r=Ne(i.getExpression());r!==void 0&&n.push(be(t,"default",r,i.getStartLineNumber(),$t))}return n},Dc=(e,t,s)=>{const n=[];for(const i of e.getExportDeclarations().filter(r=>r.getModuleSpecifier()===void 0))for(const r of i.getNamedExports()){const a=r.getAliasNode()?.getText()??r.getName();if(s.has(`${t}:${a}`))continue;const c=r.getLocalTargetDeclarations().find(d=>o.isVariableDeclaration(d));if(c===void 0||!qt(c))continue;const u=Ne(c);u!==void 0&&n.push(be(t,a,u,r.getStartLineNumber(),Oc))}return n},kc=(e,t,s)=>[...Rc(e,t,s),...Lc(e,t,s),...Dc(e,t,s)],Mc=(e,t,s)=>{const n=new Set(s.map(r=>`${r.filePath}:${r.exportName}`)),i=[];for(const r of g(t)){const a=e.getSourceFile(r);a!==void 0&&i.push(...kc(a,E(t,r),n))}return i.toSorted((r,a)=>r.cacheKey.localeCompare(a.cacheKey))},Kc=new Set(["when","where"]),xe=new Set(["definePolicy","defineShape"]),_c=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(o.isPropertyAccessExpression(t)){const n=t.getName();return xe.has(n)?n:void 0}if(!o.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(o.isImportSpecifier(n)){const i=n.getNameNode().getText();return xe.has(i)?i:void 0}const s=t.getText();return xe.has(s)?s:void 0},zc=e=>o.isObjectLiteralExpression(e)&&e.getProperties().length===0,jt=e=>{if(e!==void 0){if(o.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===l.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(zc(e))return"empty-object";if(o.isParenthesizedExpression(e))return jt(e.getExpression())}},Pe=e=>e.getAncestors().find(t=>o.isArrowFunction(t)||o.isFunctionExpression(t)||o.isFunctionDeclaration(t)),Uc=e=>e.getDescendantsOfKind(l.ReturnStatement).filter(t=>Pe(t)===e),Vt=e=>e.getDescendantsOfKind(l.ConditionalExpression).filter(t=>Pe(t)===e),Bc=e=>{const t=Uc(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(l.IfStatement)!==void 0)||Vt(e).length>0},qc=e=>e.getDescendantsOfKind(l.IfStatement).filter(t=>Pe(t)===e),Se=e=>e.getKind()===l.NullKeyword||e.getKind()===l.FalseKeyword||o.isIdentifier(e)&&e.getText()==="undefined"?!0:o.isNumericLiteral(e)?e.getLiteralValue()===0:o.isStringLiteral(e)&&e.getLiteralValue()==="",$c=(e,t)=>Se(e)||Se(t),jc=new Map([[l.EqualsEqualsEqualsToken,"positive"],[l.EqualsEqualsToken,"positive"],[l.ExclamationEqualsEqualsToken,"negative"],[l.ExclamationEqualsToken,"negative"]]),xt=e=>!Se(e)&&(o.isLiteralExpression(e)||e.getKind()===l.TrueKeyword),Vc=(e,t,s)=>{const n=jc.get(e);if(n!==void 0)return $c(t,s)?n==="positive"?"negative":"positive":xt(t)||xt(s)?void 0:n},$=e=>{if(o.isParenthesizedExpression(e))return $(e.getExpression());if(o.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken)return"negative";if(o.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=Vc(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===l.AmpersandAmpersandToken||t===l.BarBarToken){const n=$(e.getLeft()),i=$(e.getRight());return n===i?n:"indeterminate"}}return o.isIdentifier(e)||o.isPropertyAccessExpression(e)||o.isElementAccessExpression(e)||o.isCallExpression(e)?"positive":"indeterminate"},Et=e=>{if(e!==void 0){if(o.isReturnStatement(e))return e;if(o.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&o.isReturnStatement(t)?t:void 0}}},Wc=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(l.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Hc=e=>o.isReturnStatement(e)?e.getExpression()??e:e,Gc=e=>{const t=[];for(const s of Vt(e)){const n=$(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of qc(e)){const n=$(s.getExpression());if(n==="indeterminate")continue;const i=n==="negative"?Et(s.getThenStatement()):Et(s.getElseStatement())??Wc(s);i!==void 0&&t.push(Hc(i))}return t},Yc=e=>{for(const t of e.getAncestors())if(o.isVariableDeclaration(t)){const s=t.getNameNode();if(o.isIdentifier(s))return s.getText()}return"<anonymous>"},Qc=(e,t,s)=>{if(!o.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!o.isObjectLiteralExpression(n))return[];const i=[];for(const r of n.getProperties()){if(!o.isPropertyAssignment(r)||!Kc.has(r.getName()))continue;const a=r.getInitializer();if(!(!a||!(o.isArrowFunction(a)||o.isFunctionExpression(a)))&&Bc(a))for(const c of Gc(a)){const u=jt(c);u!==void 0&&i.push({exportName:Yc(e),file:s,form:u,key:r.getName(),line:c.getStartLineNumber(),owner:t})}}return i},Xc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=_c(n);i!==void 0&&s.push(...Qc(n,i,t))}return s},Zc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Xc(i,E(t,n)))}return s},Jc=new Set(["query","upsert","upsertMany"]),el=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(Jc.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},tl=(e,t)=>{const s=el(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const i=y(n,"namespace");if(!(!i||!T(i)||M(i)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s}},sl=(e,t)=>P(e,t,tl),nl=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return o.isPropertyAccessExpression(s)?s.getName()==="workflows":o.isIdentifier(s)&&s.getText()==="workflows"},rl=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},il=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getDescendantsOfKind(l.CallExpression)){if(!nl(a))continue;const c=ws(a);c!==""&&s.push({exportName:c,file:r,line:a.getStartLineNumber(),workflow:rl(a)})}}return s},ol=".lunora-schema.json",I=(e,t)=>{b(e)&&At(e,"utf8")===t||ns(e,t,"utf8")},w=(e,t)=>{if(t===""){rs(e,{force:!0});return}I(e,t)},al=e=>{const t=f(e,"package.json");if(b(t))try{const s=JSON.parse(At(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},cl=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},ll=e=>{let t=b(e)?e:fe(e);for(;t&&t!==fe(t);){const s=f(t,"tsconfig.json");if(b(s))return s;t=fe(t)}},vt=e=>e.replaceAll("\\","/"),ul=(e,t,s)=>{if(s&&e.length>0){const r=e.map(a=>`"${a.exportName}"`).join(", ");throw new k("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${r}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const r of t.columns){const a=n.get(r.table)??[];a.push(r.column),n.set(r.table,a)}const i=t.columns.length>0;for(const r of e){if(r.table===void 0){if(i)throw new k("MASK_UNSUPPORTED",`defineShape "${r.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${r.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(r.table);if(a===void 0)continue;const c=a.map(u=>`"${u}"`).join(", ");throw new k("MASK_UNSUPPORTED",`defineShape "${r.exportName}" replicates table "${r.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},te=(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)},St=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,dl=8,fl=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:i,migrations:r,project:a,shapes:c,usesSandbox:u,useUmbrella:d,workflows:h}=e;let N=Je(a,i),p=tt(a,i),S=et(a,i);for(let C=1;;C+=1){const F=bs({agents:t,functions:N,httpRoutes:S,mutators:p,useUmbrella:d,workflows:h}),O=Ps({agents:t,functions:N,migrations:r,mutators:p,shapes:c,useUmbrella:d,usesSandbox:u});if(C>=dl||St(a,s,F)&&St(a,n,O))return{apiContent:F,functions:N,functionsContent:O,httpRoutes:S,mutators:p};te(a,s,F),te(a,n,O),N=Je(a,i),p=tt(a,i),S=et(a,i)}},pl=e=>{const t=ll(e);return t?new Xe({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Xe({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},iu=(e,t)=>{const s=g(t),n=f(t,"schema.ts");b(n)&&s.push(n);for(const c of s){const u=e.getSourceFile(c);u===void 0?e.addSourceFileAtPath(c):u.refreshFromFileSystemSync()}const i=new Set(s.map(c=>vt(c))),r=vt(t),a=`${r}/`;for(const c of e.getSourceFiles()){const u=c.getFilePath();(u===r||u.startsWith(a))&&!i.has(u)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const u=c.getFilePath();if(!(u===r||u.startsWith(a)||u.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},ou=e=>{const t=cl(),s=t?pe.now():0,n=f(e.projectRoot,e.lunoraDirectory??"lunora"),i=f(n,"schema.ts");if(!b(i))throw new k("INTERNAL",`schema.ts not found at ${i}`);const r=e.project??pl(n);mn(mi);const a=nn(r,i,e.projectRoot),{agents:c,containers:u,dataModelContent:d,dependencies:h,env:N,featureUsage:p,hasBrowser:S,hasFlags:C,hasNotify:F,identity:O,platformGate:V,queues:R,serverContent:_,storageRulesMetadata:z,usesSandbox:oe,useUmbrella:U,workflows:D}=Ln({lunoraDirectory:n,project:r,projectRoot:e.projectRoot,schema:a,target:e.target}),m=f(n,"_generated"),Ie=f(m,"dataModel.ts"),we=f(m,"server.ts"),Wt=f(m,"api.ts"),Ht=f(m,"functions.ts");te(r,Ie,d),te(r,we,_);const Te=Gs(r,n),B=ln(r,n),{apiContent:Ce,functions:q,functionsContent:Fe,httpRoutes:Gt,mutators:Yt}=fl({agents:c,apiPath:Wt,generatedFunctionsPath:Ht,lunoraDirectory:n,migrations:Te,project:r,shapes:B,useUmbrella:U,usesSandbox:oe,workflows:D}),ae=qs(r,n,D,c),W=e.lint===!1?void 0:as({adminRoutes:Bn(r,n),aiRawRuns:jn(r,n),aiToolSideEffects:er(r,n),argumentDerivedFetches:nr(r,n),argumentValidators:mr(r,n),authApiCalls:Bs(r,n),authConfigs:Pr(r,n),browserUrlAccesses:Fr(r,n),configCalls:_r(r,n),containerKeyAccesses:Ur(r,n),containerOverrides:Wr(r,n),containers:u,exportSinks:Qr(r,n),staleMigrationImports:Sc(r,n),failOpenGuards:ti(r,n),flagReads:ui(r,n),flagSecurityDefaults:gi(r,n),geoIndexUsages:Ei(r,n),httpActionGuards:Pi(r,n),httpHeaderWrites:ki(r,n),identityClaimReads:qi(r,n),imageDeliveryUrlAccesses:ji(r,n),inserts:Ws(r,n),kvKeyAccesses:Wi(r,n),mailRecipientAccesses:Xi(r,n),maskProcedures:Hs(r,n),maskStrategies:io(r,n),mutatorWrites:fo(r,n),nondeterministicCalls:Xs(r,n),normalizeIdAuthorizations:To(r,n),notifyCalls:Js(r,n),notifyConfig:Zs(r,n),ownerFieldWrites:Mo(r,n,q),unrestrictedWhereBranches:Zc(r,n),paymentWebhooks:jo(r,n),privilegedDispatches:na(r,n),procedureProtections:Ba(r,n),queries:zs(r,n),queues:R,r2sqlCalls:en(r,n),ratelimitKeySelectors:Va(r,n),rawRowReturns:Za(r,n),relationLoads:tc(r,n),rlsProcedures:tn(r,n),schema:a,secretLiterals:lc(r,n),shapes:B,softDeleteReads:dc(r,n),sqlInterpolations:xc(r,n),storageKeyAccesses:yc(r,n,q),storageUploads:Tc(r,n),vectorNamespaceAccesses:sl(r,n),workflowCalls:il(r,n),workflows:D,wranglerVariables:e.wranglerVariables}),Oe=W===void 0?[]:[...is(W,{source:"static"}),...Mc(r,n,q)],Qt=sn(r,n),Re=so(r,n);ul(B,Re,eo(r,n));const Xt=C?ii(r,n):[],H=Cc(p,{containerCount:u.length,cronCount:ae.length,dependencies:h,hasPaymentTables:zo(a.tables),queueCount:R.length,storageColumnCount:Object.keys(fs(a)).length,storageRuleCount:z.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:D.length}),Le=t?pe.now():0,ce=hn(a,Te.map(x=>x.id)),De=ps({advisories:Oe,advisorProcedures:W?.procedureProtections??[],agents:c,containers:u,env:N,flagKeys:Xt,hasAccessFacade:p.access,hasAi:p.ai,hasAnalytics:p.analytics,hasBrowser:S,hasFlags:C,hasHyperdrive:p.hyperdrive,hasImages:p.images,hasKv:p.kv,hasNotify:F,hasPayments:p.payments,hasPipelines:p.pipelines,hasR2sql:p.r2sql,hasX402:p.x402,maskMetadata:Re,mutators:Yt,queues:R,rlsMetadata:Qt,schema:a,schemaSnapshot:ce,shapes:B,storageRules:z,studioFeatures:H,useUmbrella:U,workflows:D}),ke=gs(B,h.has("@lunora/db"),U),Me=ms(u,a.jurisdiction),Ke=hs(D),_e=xs(c),ze=Es(R),Ue=vs(ae),Be=Ss(a.vectorIndexes),G=As(a,U),qe=ys(h.has("@lunora/seed")),Y=e.apiSpec??"openapi",le=Y==="openapi"||Y==="both",ue=Y==="openrpc"||Y==="both",$e=un({emailAgents:c.filter(x=>x.onEmail===!0).map(x=>({bindingName:x.bindingName,exportName:x.exportName})),hasAccess:h.has("@lunora/cloudflare-access"),hasAi:p.ai,hasAnalytics:p.analytics,hasAuth:h.has("@lunora/auth"),hasBrowser:S,hasFramework:h.has("@lunora/astro")||h.has("@lunora/svelte")||h.has("@lunora/vue"),hasGlobal:a.tables.some(x=>x.shardMode==="global"&&x.globalBackend!=="hyperdrive"),hasHyperdrive:p.hyperdrive,hasHyperdriveGlobal:a.tables.some(x=>x.shardMode==="global"&&x.globalBackend==="hyperdrive"),hasImages:p.images,hasKv:H.kv,hasNotify:F,hasPayments:p.payments,hasR2sql:p.r2sql,hasQueue:R.some(x=>x.mode==="push"),hasScheduler:H.scheduler,hasStorage:H.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:D.length>0,hasX402:p.x402,identity:O,jurisdiction:a.jurisdiction,useUmbrella:U,voiceAgents:c.filter(x=>x.voice===!0&&x.voiceBindingName!==void 0).map(x=>({bindingName:x.voiceBindingName,exportName:x.exportName})),wantsOpenApi:le,wantsOpenRpc:ue}),je=al(e.projectRoot),Ve=dn({functions:q,httpRoutes:Gt,version:je}),We=pn({functions:q,version:je}),He=`${JSON.stringify(Ve,void 0,2)}
7
+ `)){const i=n.replace(La,"");if(!i.startsWith(ht))continue;const r=i.slice(ht.length);if(Da.test(r.charAt(0)))continue;const a=r.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":r.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},Ma=e=>{const[t]=e.getArguments();if(t){if(o.isObjectLiteralExpression(t)){const s=t.getProperty("handler");return s?o.isPropertyAssignment(s)?s.getInitializer():o.isShorthandPropertyAssignment(s)?s.getNameNode():o.isMethodDeclaration(s)?s:void 0:void 0}return t}},Ka=(e,t)=>{const s=Ma(t);if(!s)return;if(o.isArrowFunction(s)||o.isFunctionExpression(s)||o.isMethodDeclaration(s))return e;if(!o.isIdentifier(s))return;const n=s.getSourceFile(),i=s.getText(),r=n.getVariableDeclaration(i)?.getInitializer();return r&&(o.isArrowFunction(r)||o.isFunctionExpression(r))?r:n.getFunction(i)},_a=e=>{let t=!1,s=!1,n=!1,i=!1,r=!1;for(const u of e.getDescendantsOfKind(l.CallExpression))if(pa(u)&&(r=!0),ha(u)&&(t=!0),xa(u)&&(i=!0),Ea(u)&&(s=!0),va(u)&&(n=!0),r&&t&&i&&n)break;const{handlesErrors:a,reachesOutbound:c}=Oa(e);return{callsMail:he(e,ya),emitsEvent:he(e,Sa),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||he(e,Aa),throwsBareError:Ra(e),unboundedAiGeneration:n,usesInsertManyUnsafe:i,writesUserTable:r}},za=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=K(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const i=n.receiver?da(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},r=Ka(e,s);return{...r?_a(r):{},...ka(e),...i,analyzableBody:r!==void 0,exportName:e.getName(),file:t,hasEmailArg:aa(s,n.receiver),kind:n.kind,visibility:n.visibility}},Ua=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=za(i,t);r&&s.push(r)}return s},Ba=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ua(i,E(t,n)))}return s},qa=new Set(["dbRateLimit","rateLimit"]),$a=e=>o.isArrowFunction(e)?e.getBody():e,ja=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!qa.has(s))return;const n=e.getArguments()[2];if(!n)return;const i=y(n,"key");if(!i)return;const r=$a(i);if(!(!T(r)||M(r)))return{callee:s,exportName:v(e),file:t,limitName:yt(e),line:e.getStartLineNumber()}},Va=(e,t)=>P(e,t,ja),Wa=new Set(["findFirst","findFirstOrThrow","findMany","get"]),Ha=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Wa.has(t.getName()))return;const s=t.getExpression();if(L(s)){const n=e.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}if(o.isPropertyAccessExpression(s)&&L(s.getExpression()))return s.getName()},Ga=e=>{let t=e;for(;o.isCallExpression(t);){const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&L(s.getExpression())){const n=t.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},Ya=e=>{let t=Ze(e)??e;for(;o.isAwaitExpression(t);)t=Ze(t.getExpression())??t.getExpression();return t},Bt=(e,t=!1)=>{const s=Ya(e);if(o.isIdentifier(s)){if(t)return;const n=re(s);return n===void 0?void 0:Bt(n,!0)}if(o.isCallExpression(s))return Ha(s)??Ga(s)},Qa=e=>{const t=e.getBody();if(!o.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(l.ReturnStatement)){const i=n.getFirstAncestor(a=>o.isArrowFunction(a)||o.isFunctionExpression(a)||o.isFunctionDeclaration(a)),r=n.getExpression();i===e&&r!==void 0&&s.push(r)}return s},Xa=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=K(s);if(n?.kind!=="query")return[];const i=Rt(s);if(i===void 0)return[];const r=n.receiver!==void 0&&Us(n.receiver,"output"),a=n.receiver!==void 0&&bt(n.receiver,"use","mask"),c=new Set,u=[];for(const d of Qa(i)){const x=Bt(d);x===void 0||c.has(x)||(c.add(x),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:x,usesMask:a,usesOutput:r,visibility:n.visibility}))}return u},Za=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Xa(c,r))}return s},Ja=e=>{if(!e||!o.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)||o.isMethodDeclaration(s)||o.isGetAccessorDeclaration(s))&&t.push(s.getName());return t},ec=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?K(s):void 0;if(!n)return[];const i=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Nt(r);if(a===void 0)continue;const c=Ja(y(a.options,"with"));c.length!==0&&i.push({exportName:e.getName(),file:t,line:r.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return i},tc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...ec(c,r))}return s},ee=e=>{if(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(o.isBinaryExpression(e)&&e.getOperatorToken().getKind()===l.PlusToken){const t=ee(e.getLeft()),s=ee(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},sc=e=>{let t=e,s=t.getParent();for(;s!==void 0&&o.isBinaryExpression(s)&&s.getOperatorToken().getKind()===l.PlusToken;)t=s,s=t.getParent();return t!==e&&ee(t)!==void 0},nc=/(?:^|\/)__tests__\//u,rc=/\.(?:spec|test)$/u,ic=e=>nc.test(e)||rc.test(e),oc=e=>{const t=e.getParent();if(t!==void 0){if(o.isVariableDeclaration(t)||o.isPropertyAssignment(t)||o.isPropertySignature(t))return t.getName();if(o.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.EqualsToken)return t.getLeft().getText()}},ac=(e,t,s)=>an(e)?!ic(s)&&cn(oc(t)):!0,cc=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(l.BinaryExpression),...e.getDescendantsOfKind(l.StringLiteral),...e.getDescendantsOfKind(l.NoSubstitutionTemplateLiteral)],i=new Set;for(const r of n){if(sc(r))continue;const a=ee(r);if(a===void 0)continue;const c=rn(a);if(c===void 0||!ac(c,r,t))continue;const u=r.getStartLineNumber(),d=`${String(u)}:${c}`;i.has(d)||(i.add(d),s.push({file:t,kind:c,line:u,preview:on(a)}))}return s},lc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...cc(i,E(t,n)))}return s},uc=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?K(s):void 0;if(!n)return[];const i=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Nt(r);if(a===void 0)continue;const c=y(a.options,"includeDeleted");if(c===void 0)continue;const u=o.isTrueLiteral(c),d=!u&&T(c);!u&&!d||i.push({exportName:e.getName(),file:t,fromArgs:d,hardcodedTrue:u,line:r.getStartLineNumber(),table:a.table,visibility:n.visibility})}return i},dc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...uc(c,r))}return s},fc=new Set(["query","unsafe"]),pc=e=>{if(!o.isPropertyAccessExpression(e)||!fc.has(e.getName()))return!1;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return o.isIdentifier(s)&&s.getText()==="ctx"},gc=e=>o.isBinaryExpression(e)||o.isTemplateExpression(e),mc=e=>e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()??"<module>",hc=(e,t)=>{if(!pc(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!gc(s)))return{exportName:mc(e),file:t,line:s.getStartLineNumber()}},xc=(e,t)=>P(e,t,hc),Ec=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],vc=e=>{for(const[t,s]of Ec)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},Sc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of i.getImportDeclarations()){const a=r.getModuleSpecifierValue(),c=vc(a);c!==void 0&&s.push({file:E(t,n),line:r.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},Ac=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),yc=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return ie(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:Ac,requireUnmodifiedReach:!0}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},Nc=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),bc=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,Pc=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!o.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const i of e.getProperties()){if(o.isSpreadAssignment(i)){n=!0;continue}if(o.isPropertyAssignment(i)){const r=i.getName();t.push(r),r==="expiresInSeconds"&&(s=bc(i.getInitializer()));continue}(o.isShorthandPropertyAssignment(i)||o.isMethodDeclaration(i))&&t.push(i.getName())}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},Ic=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName(),s=Nc.get(t);if(s===void 0)return;const n=e.getExpression().getText();return n==="ctx.storage"||n.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},wc=(e,t)=>{const s=Ic(e.getExpression());if(s!==void 0)return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s.method,...Pc(e.getArguments()[s.optionsIndex])}},Tc=(e,t)=>P(e,t,wc),Cc=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),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/kv"),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:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),Fc=new Set(["RegisteredAction","RegisteredMutation","RegisteredQuery"]),Ne=e=>{const t=e.getType(),s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName();return s!==void 0&&Fc.has(s)?s:void 0},qt=e=>{const t=e.getInitializer();return t===void 0?!1:o.isCallExpression(t)||o.isIdentifier(t)||o.isPropertyAccessExpression(t)},$t={cause:"codegen recognises a procedure only when the initializer is a builder chain, and this one is produced by a call or an alias",remediation:"A factory that returns a procedure cannot be read statically — inline it, or export the chain the factory builds."},Oc={cause:"the binding is exported by a separate `export { … }` statement, and codegen reads the `export` keyword on the declaration itself",remediation:"Move the keyword onto the declaration and drop the separate export statement."},be=(e,t,s,n,i)=>({cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally a builder chain. A procedure written any other way exists at runtime but never reaches `_generated/api.ts`, so no caller can address it.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${s}\` but was not registered — ${i.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:s},name:"procedure_not_registered",remediation:`Assign the builder chain directly: \`export const ${t} = query.input({ … }).query(handler);\`. ${i.remediation}`,title:"Procedure exists at runtime but is missing from the generated API"}),Rc=(e,t,s)=>{const n=[];for(const i of e.getVariableStatements().filter(r=>r.isExported()))for(const r of i.getDeclarations()){const a=r.getName();if(s.has(`${t}:${a}`)||!qt(r))continue;const c=Ne(r);c!==void 0&&n.push(be(t,a,c,r.getStartLineNumber(),$t))}return n},Lc=(e,t,s)=>{if(s.has(`${t}:default`))return[];const n=[];for(const i of e.getExportAssignments().filter(r=>!r.isExportEquals())){const r=Ne(i.getExpression());r!==void 0&&n.push(be(t,"default",r,i.getStartLineNumber(),$t))}return n},Dc=(e,t,s)=>{const n=[];for(const i of e.getExportDeclarations().filter(r=>r.getModuleSpecifier()===void 0))for(const r of i.getNamedExports()){const a=r.getAliasNode()?.getText()??r.getName();if(s.has(`${t}:${a}`))continue;const c=r.getLocalTargetDeclarations().find(d=>o.isVariableDeclaration(d));if(c===void 0||!qt(c))continue;const u=Ne(c);u!==void 0&&n.push(be(t,a,u,r.getStartLineNumber(),Oc))}return n},kc=(e,t,s)=>[...Rc(e,t,s),...Lc(e,t,s),...Dc(e,t,s)],Mc=(e,t,s)=>{const n=new Set(s.map(r=>`${r.filePath}:${r.exportName}`)),i=[];for(const r of g(t)){const a=e.getSourceFile(r);a!==void 0&&i.push(...kc(a,E(t,r),n))}return i.toSorted((r,a)=>r.cacheKey.localeCompare(a.cacheKey))},Kc=new Set(["when","where"]),xe=new Set(["definePolicy","defineShape"]),_c=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(o.isPropertyAccessExpression(t)){const n=t.getName();return xe.has(n)?n:void 0}if(!o.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(o.isImportSpecifier(n)){const i=n.getNameNode().getText();return xe.has(i)?i:void 0}const s=t.getText();return xe.has(s)?s:void 0},zc=e=>o.isObjectLiteralExpression(e)&&e.getProperties().length===0,jt=e=>{if(e!==void 0){if(o.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===l.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(zc(e))return"empty-object";if(o.isParenthesizedExpression(e))return jt(e.getExpression())}},Pe=e=>e.getAncestors().find(t=>o.isArrowFunction(t)||o.isFunctionExpression(t)||o.isFunctionDeclaration(t)),Uc=e=>e.getDescendantsOfKind(l.ReturnStatement).filter(t=>Pe(t)===e),Vt=e=>e.getDescendantsOfKind(l.ConditionalExpression).filter(t=>Pe(t)===e),Bc=e=>{const t=Uc(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(l.IfStatement)!==void 0)||Vt(e).length>0},qc=e=>e.getDescendantsOfKind(l.IfStatement).filter(t=>Pe(t)===e),Se=e=>e.getKind()===l.NullKeyword||e.getKind()===l.FalseKeyword||o.isIdentifier(e)&&e.getText()==="undefined"?!0:o.isNumericLiteral(e)?e.getLiteralValue()===0:o.isStringLiteral(e)&&e.getLiteralValue()==="",$c=(e,t)=>Se(e)||Se(t),jc=new Map([[l.EqualsEqualsEqualsToken,"positive"],[l.EqualsEqualsToken,"positive"],[l.ExclamationEqualsEqualsToken,"negative"],[l.ExclamationEqualsToken,"negative"]]),xt=e=>!Se(e)&&(o.isLiteralExpression(e)||e.getKind()===l.TrueKeyword),Vc=(e,t,s)=>{const n=jc.get(e);if(n!==void 0)return $c(t,s)?n==="positive"?"negative":"positive":xt(t)||xt(s)?void 0:n},$=e=>{if(o.isParenthesizedExpression(e))return $(e.getExpression());if(o.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken)return"negative";if(o.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=Vc(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===l.AmpersandAmpersandToken||t===l.BarBarToken){const n=$(e.getLeft()),i=$(e.getRight());return n===i?n:"indeterminate"}}return o.isIdentifier(e)||o.isPropertyAccessExpression(e)||o.isElementAccessExpression(e)||o.isCallExpression(e)?"positive":"indeterminate"},Et=e=>{if(e!==void 0){if(o.isReturnStatement(e))return e;if(o.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&o.isReturnStatement(t)?t:void 0}}},Wc=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(l.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Hc=e=>o.isReturnStatement(e)?e.getExpression()??e:e,Gc=e=>{const t=[];for(const s of Vt(e)){const n=$(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of qc(e)){const n=$(s.getExpression());if(n==="indeterminate")continue;const i=n==="negative"?Et(s.getThenStatement()):Et(s.getElseStatement())??Wc(s);i!==void 0&&t.push(Hc(i))}return t},Yc=e=>{for(const t of e.getAncestors())if(o.isVariableDeclaration(t)){const s=t.getNameNode();if(o.isIdentifier(s))return s.getText()}return"<anonymous>"},Qc=(e,t,s)=>{if(!o.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!o.isObjectLiteralExpression(n))return[];const i=[];for(const r of n.getProperties()){if(!o.isPropertyAssignment(r)||!Kc.has(r.getName()))continue;const a=r.getInitializer();if(!(!a||!(o.isArrowFunction(a)||o.isFunctionExpression(a)))&&Bc(a))for(const c of Gc(a)){const u=jt(c);u!==void 0&&i.push({exportName:Yc(e),file:s,form:u,key:r.getName(),line:c.getStartLineNumber(),owner:t})}}return i},Xc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=_c(n);i!==void 0&&s.push(...Qc(n,i,t))}return s},Zc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Xc(i,E(t,n)))}return s},Jc=new Set(["query","upsert","upsertMany"]),el=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(Jc.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},tl=(e,t)=>{const s=el(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const i=y(n,"namespace");if(!(!i||!T(i)||M(i)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s}},sl=(e,t)=>P(e,t,tl),nl=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return o.isPropertyAccessExpression(s)?s.getName()==="workflows":o.isIdentifier(s)&&s.getText()==="workflows"},rl=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},il=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getDescendantsOfKind(l.CallExpression)){if(!nl(a))continue;const c=ws(a);c!==""&&s.push({exportName:c,file:r,line:a.getStartLineNumber(),workflow:rl(a)})}}return s},ol=".lunora-schema.json",I=(e,t)=>{b(e)&&At(e,"utf8")===t||ns(e,t,"utf8")},w=(e,t)=>{if(t===""){rs(e,{force:!0});return}I(e,t)},al=e=>{const t=f(e,"package.json");if(b(t))try{const s=JSON.parse(At(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},cl=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},ll=e=>{let t=b(e)?e:fe(e);for(;t&&t!==fe(t);){const s=f(t,"tsconfig.json");if(b(s))return s;t=fe(t)}},vt=e=>e.replaceAll("\\","/"),ul=(e,t,s)=>{if(s&&e.length>0){const r=e.map(a=>`"${a.exportName}"`).join(", ");throw new k("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${r}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const r of t.columns){const a=n.get(r.table)??[];a.push(r.column),n.set(r.table,a)}const i=t.columns.length>0;for(const r of e){if(r.table===void 0){if(i)throw new k("MASK_UNSUPPORTED",`defineShape "${r.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${r.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(r.table);if(a===void 0)continue;const c=a.map(u=>`"${u}"`).join(", ");throw new k("MASK_UNSUPPORTED",`defineShape "${r.exportName}" replicates table "${r.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},te=(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)},St=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,dl=8,fl=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:i,migrations:r,project:a,shapes:c,usesSandbox:u,useUmbrella:d,workflows:x}=e;let N=Je(a,i),p=tt(a,i),S=et(a,i);for(let C=1;;C+=1){const F=bs({agents:t,functions:N,httpRoutes:S,mutators:p,useUmbrella:d,workflows:x}),O=Ps({agents:t,functions:N,migrations:r,mutators:p,shapes:c,useUmbrella:d,usesSandbox:u});if(C>=dl||St(a,s,F)&&St(a,n,O))return{apiContent:F,functions:N,functionsContent:O,httpRoutes:S,mutators:p};te(a,s,F),te(a,n,O),N=Je(a,i),p=tt(a,i),S=et(a,i)}},pl=e=>{const t=ll(e);return t?new Xe({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Xe({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},iu=(e,t)=>{const s=g(t),n=f(t,"schema.ts");b(n)&&s.push(n);for(const c of s){const u=e.getSourceFile(c);u===void 0?e.addSourceFileAtPath(c):u.refreshFromFileSystemSync()}const i=new Set(s.map(c=>vt(c))),r=vt(t),a=`${r}/`;for(const c of e.getSourceFiles()){const u=c.getFilePath();(u===r||u.startsWith(a))&&!i.has(u)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const u=c.getFilePath();if(!(u===r||u.startsWith(a)||u.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},ou=e=>{const t=cl(),s=t?pe.now():0,n=f(e.projectRoot,e.lunoraDirectory??"lunora"),i=f(n,"schema.ts");if(!b(i))throw new k("INTERNAL",`schema.ts not found at ${i}`);const r=e.project??pl(n);mn(mi);const a=nn(r,i,e.projectRoot),{agents:c,containers:u,dataModelContent:d,dependencies:x,env:N,featureUsage:p,hasBrowser:S,hasFlags:C,hasNotify:F,identity:O,platformGate:V,queues:R,serverContent:_,storageRulesMetadata:z,usesSandbox:oe,useUmbrella:U,workflows:D}=Ln({lunoraDirectory:n,project:r,projectRoot:e.projectRoot,schema:a,target:e.target}),m=f(n,"_generated"),Ie=f(m,"dataModel.ts"),we=f(m,"server.ts"),Wt=f(m,"api.ts"),Ht=f(m,"functions.ts");te(r,Ie,d),te(r,we,_);const Te=Gs(r,n),B=ln(r,n),{apiContent:Ce,functions:q,functionsContent:Fe,httpRoutes:Gt,mutators:Yt}=fl({agents:c,apiPath:Wt,generatedFunctionsPath:Ht,lunoraDirectory:n,migrations:Te,project:r,shapes:B,useUmbrella:U,usesSandbox:oe,workflows:D}),ae=qs(r,n,D,c),W=e.lint===!1?void 0:as({adminRoutes:Bn(r,n),aiRawRuns:jn(r,n),aiToolSideEffects:er(r,n),argumentDerivedFetches:nr(r,n),argumentValidators:mr(r,n),authApiCalls:Bs(r,n),authConfigs:Pr(r,n),browserUrlAccesses:Fr(r,n),configCalls:_r(r,n),containerKeyAccesses:Ur(r,n),containerOverrides:Wr(r,n),containers:u,exportSinks:Qr(r,n),staleMigrationImports:Sc(r,n),failOpenGuards:ti(r,n),flagReads:ui(r,n),flagSecurityDefaults:gi(r,n),geoIndexUsages:Ei(r,n),httpActionGuards:Pi(r,n),httpHeaderWrites:ki(r,n),identityClaimReads:qi(r,n),imageDeliveryUrlAccesses:ji(r,n),inserts:Ws(r,n),kvKeyAccesses:Wi(r,n),mailRecipientAccesses:Xi(r,n),maskProcedures:Hs(r,n),maskStrategies:io(r,n),mutatorWrites:fo(r,n),nondeterministicCalls:Xs(r,n),normalizeIdAuthorizations:To(r,n),notifyCalls:Js(r,n),notifyConfig:Zs(r,n),ownerFieldWrites:Mo(r,n,q),unrestrictedWhereBranches:Zc(r,n),paymentWebhooks:jo(r,n),privilegedDispatches:na(r,n),procedureProtections:Ba(r,n),queries:zs(r,n),queues:R,r2sqlCalls:en(r,n),ratelimitKeySelectors:Va(r,n),rawRowReturns:Za(r,n),relationLoads:tc(r,n),rlsProcedures:tn(r,n),schema:a,secretLiterals:lc(r,n),shapes:B,softDeleteReads:dc(r,n),sqlInterpolations:xc(r,n),storageKeyAccesses:yc(r,n,q),storageUploads:Tc(r,n),vectorNamespaceAccesses:sl(r,n),workflowCalls:il(r,n),workflows:D,wranglerVariables:e.wranglerVariables}),Oe=W===void 0?[]:[...is(W,{source:"static"}),...Mc(r,n,q)],Qt=sn(r,n),Re=so(r,n);ul(B,Re,eo(r,n));const Xt=C?ii(r,n):[],H=Cc(p,{containerCount:u.length,cronCount:ae.length,dependencies:x,hasPaymentTables:zo(a.tables),queueCount:R.length,storageColumnCount:Object.keys(fs(a)).length,storageRuleCount:z.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:D.length}),Le=t?pe.now():0,ce=hn(a,Te.map(h=>h.id)),De=ps({advisories:Oe,advisorProcedures:W?.procedureProtections??[],agents:c,containers:u,env:N,flagKeys:Xt,hasAccessFacade:p.access,hasAi:p.ai,hasAnalytics:p.analytics,hasBrowser:S,hasFlags:C,hasHyperdrive:p.hyperdrive,hasImages:p.images,hasKv:p.kv,hasNotify:F,hasPayments:p.payments,hasPipelines:p.pipelines,hasR2sql:p.r2sql,hasX402:p.x402,maskMetadata:Re,mutators:Yt,queues:R,rlsMetadata:Qt,schema:a,schemaSnapshot:ce,shapes:B,storageRules:z,studioFeatures:H,useUmbrella:U,workflows:D}),ke=gs(B,x.has("@lunora/db"),U),Me=ms(u,a.jurisdiction),Ke=hs(D),_e=xs(c),ze=Es(R),Ue=vs(ae),Be=Ss(a.vectorIndexes),G=As(a,U),qe=ys(x.has("@lunora/seed")),Y=e.apiSpec??"openapi",le=Y==="openapi"||Y==="both",ue=Y==="openrpc"||Y==="both",$e=un({emailAgents:c.filter(h=>h.onEmail===!0).map(h=>({bindingName:h.bindingName,exportName:h.exportName})),hasAccess:x.has("@lunora/cloudflare-access"),hasAi:p.ai,hasAnalytics:p.analytics,hasAuth:x.has("@lunora/auth"),hasBrowser:S,hasFramework:x.has("@lunora/astro")||x.has("@lunora/svelte")||x.has("@lunora/vue"),hasGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend!=="hyperdrive"),hasHyperdrive:p.hyperdrive,hasHyperdriveGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend==="hyperdrive"),hasImages:p.images,hasKv:H.kv,hasNotify:F,hasPayments:p.payments,hasR2sql:p.r2sql,hasQueue:R.some(h=>h.mode==="push"),hasScheduler:H.scheduler,hasStorage:H.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:D.length>0,hasX402:p.x402,identity:O,jurisdiction:a.jurisdiction,tableNames:a.tables.map(h=>h.name),useUmbrella:U,voiceAgents:c.filter(h=>h.voice===!0&&h.voiceBindingName!==void 0).map(h=>({bindingName:h.voiceBindingName,exportName:h.exportName})),wantsOpenApi:le,wantsOpenRpc:ue}),je=al(e.projectRoot),Ve=dn({functions:q,httpRoutes:Gt,version:je}),We=pn({functions:q,version:je}),He=`${JSON.stringify(Ve,void 0,2)}
8
8
  `,Ge=`${JSON.stringify(We,void 0,2)}
9
- `,Ye=fn(Ve),Qe=gn(We),de=f(n,ol),Zt=b(de);if(e.dryRun||(b(m)||ss(m,{recursive:!0}),I(f(m,"app.ts"),$e),I(Ie,d),I(f(m,"api.ts"),Ce),I(we,_),I(f(m,"functions.ts"),Fe),I(f(m,"shard.ts"),De),I(f(m,"crons.ts"),Ue),I(f(m,"vectors.ts"),Be),I(f(m,"drizzle.global.ts"),G.global),I(f(m,"drizzle.shard.ts"),G.shard),w(f(m,"containers.ts"),Me),w(f(m,"workflows.ts"),Ke),w(f(m,"agents.ts"),_e),w(f(m,"queues.ts"),ze),w(f(m,"seed.ts"),qe),w(f(m,"collections.ts"),ke),w(f(m,"openapi.json"),le?He:""),w(f(m,"openapi.ts"),le?Ye:""),w(f(m,"openrpc.json"),ue?Ge:""),w(f(m,"openrpc.ts"),ue?Qe:""),(!Zt||e.updateSchemaBaseline===!0)&&I(de,os(ce))),t){const x=pe.now(),Jt=Math.round(x-s),es=Math.round(Le-s),ts=Math.round(x-Le);console.error(`@lunora/codegen: codegen took ${Jt.toString()}ms (discovery ${es.toString()}ms, emit ${ts.toString()}ms)`)}return{advisories:Oe,advisorContext:W,agents:c,containers:u,cronTriggers:Ns(ae),generated:{agents:_e,api:Ce,app:$e,collections:ke,containers:Me,crons:Ue,dataModel:d,drizzleGlobal:G.global,drizzleShard:G.shard,functions:Fe,openApi:He,openApiModule:Ye,openRpc:Ge,openRpcModule:Qe,queues:ze,seed:qe,server:_,shard:De,vectors:Be,workflows:Ke},outputDirectory:m,platformDiagnostics:V.diagnostics,queues:R,schemaSnapshot:ce,schemaSnapshotPath:de,workflows:D}};export{ol as SCHEMA_SNAPSHOT_FILENAME,pl as createCodegenProject,ll as findTsconfig,iu as refreshCodegenProject,ou as runCodegen};
9
+ `,Ye=fn(Ve),Qe=gn(We),de=f(n,ol),Zt=b(de);if(e.dryRun||(b(m)||ss(m,{recursive:!0}),I(f(m,"app.ts"),$e),I(Ie,d),I(f(m,"api.ts"),Ce),I(we,_),I(f(m,"functions.ts"),Fe),I(f(m,"shard.ts"),De),I(f(m,"crons.ts"),Ue),I(f(m,"vectors.ts"),Be),I(f(m,"drizzle.global.ts"),G.global),I(f(m,"drizzle.shard.ts"),G.shard),w(f(m,"containers.ts"),Me),w(f(m,"workflows.ts"),Ke),w(f(m,"agents.ts"),_e),w(f(m,"queues.ts"),ze),w(f(m,"seed.ts"),qe),w(f(m,"collections.ts"),ke),w(f(m,"openapi.json"),le?He:""),w(f(m,"openapi.ts"),le?Ye:""),w(f(m,"openrpc.json"),ue?Ge:""),w(f(m,"openrpc.ts"),ue?Qe:""),(!Zt||e.updateSchemaBaseline===!0)&&I(de,os(ce))),t){const h=pe.now(),Jt=Math.round(h-s),es=Math.round(Le-s),ts=Math.round(h-Le);console.error(`@lunora/codegen: codegen took ${Jt.toString()}ms (discovery ${es.toString()}ms, emit ${ts.toString()}ms)`)}return{advisories:Oe,advisorContext:W,agents:c,containers:u,cronTriggers:Ns(ae),generated:{agents:_e,api:Ce,app:$e,collections:ke,containers:Me,crons:Ue,dataModel:d,drizzleGlobal:G.global,drizzleShard:G.shard,functions:Fe,openApi:He,openApiModule:Ye,openRpc:Ge,openRpcModule:Qe,queues:ze,seed:qe,server:_,shard:De,vectors:Be,workflows:Ke},outputDirectory:m,platformDiagnostics:V.diagnostics,queues:R,schemaSnapshot:ce,schemaSnapshotPath:de,workflows:D}};export{ol as SCHEMA_SNAPSHOT_FILENAME,pl as createCodegenProject,ll as findTsconfig,iu as refreshCodegenProject,ou as runCodegen};
@@ -117,7 +117,7 @@ interface StorageDeclaration<Env> {
117
117
  : {}),`]:[],...e.hasStorage?[" ...(this.storageDeclaration ? { storage: (rawEnv: Record<string, unknown>) => this.resolveStorage(rawEnv as Env) } : {}),"]:[],...m(e)?[" ...this.shardExtras,"]:[]];return a.length>0?`
118
118
  ${a.join(`
119
119
  `)}
120
- `:""},B=e=>[...e.hasScheduler?[` if (this.schedulerDeclaration) {
120
+ `:""},B=e=>[...e.tableNames.length>0?[` options.listSchemaTables = () => [${e.tableNames.map(t=>JSON.stringify(t)).join(", ")}];`]:[],...e.hasScheduler?[` if (this.schedulerDeclaration) {
121
121
  options.schedulerDO = this.schedulerDeclaration.namespace(env);
122
122
  }`]:[],...e.hasWorkflow?[` options.workflowsClient = (workflowEnv) => {
123
123
  const source = workflowEnv as Record<string, unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.140",
3
+ "version": "1.0.0-alpha.142",
4
4
  "description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@lunora/advisor": "1.0.0-alpha.99",
50
- "@lunora/agent": "1.0.0-alpha.74",
50
+ "@lunora/agent": "1.0.0-alpha.75",
51
51
  "@lunora/container": "1.0.0-alpha.37",
52
52
  "@lunora/errors": "1.0.0-alpha.26",
53
53
  "@lunora/platform": "1.0.0-alpha.21",