@lunora/codegen 1.0.0-alpha.283 → 1.0.0-alpha.285
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{MUTATORS_FILENAME-YOl15Grm.mjs → MUTATORS_FILENAME-Ba-gcGFd.mjs} +1 -1
- package/dist/packem_shared/{NOTIFY_FILENAME-B8Wb9kiq.mjs → NOTIFY_FILENAME-BFN2W2OF.mjs} +1 -1
- package/dist/packem_shared/{SCHEMA_SNAPSHOT_FILENAME-BitR_Ty7.mjs → SCHEMA_SNAPSHOT_FILENAME-DZhA1rb3.mjs} +6 -6
- package/dist/packem_shared/{context-property-calls-0qzW2Joh.mjs → context-property-calls-Bt-91_2v.mjs} +1 -1
- package/dist/packem_shared/{context-root-DKsAPUmn.mjs → context-root-BP60x_VP.mjs} +1 -1
- package/dist/packem_shared/{database-calls-CBlsQTga.mjs → database-calls-AHFbJnIy.mjs} +1 -1
- package/dist/packem_shared/{discoverFunctions-BswBeUWK.mjs → discoverFunctions-DMW7bLkD.mjs} +1 -1
- package/dist/packem_shared/{discoverHttpRoutes-6utMwfNf.mjs → discoverHttpRoutes-C2ARoV_3.mjs} +1 -1
- package/dist/packem_shared/discoverHyperdriveCalls-CuJGFhqZ.mjs +1 -0
- package/dist/packem_shared/{discoverInserts-Ao36AnSp.mjs → discoverInserts-yC-_-56C.mjs} +1 -1
- package/dist/packem_shared/discoverMaskProcedures-CntqcTXj.mjs +1 -0
- package/dist/packem_shared/{discoverQueries-4lacKgx_.mjs → discoverQueries-BnLL5w1Q.mjs} +1 -1
- package/dist/packem_shared/discoverR2sqlCalls-C-5wNVBz.mjs +1 -0
- package/dist/packem_shared/{discoverRlsProcedures-DllbV6_E.mjs → discoverRlsProcedures-D4udDEM2.mjs} +1 -1
- package/dist/packem_shared/{index-BfaSHMNi.mjs → index-DET6xe1e.mjs} +1 -1
- package/dist/packem_shared/unwrap-handler-return-BedChFbC.mjs +1 -0
- package/package.json +3 -3
- package/dist/packem_shared/discoverHyperdriveCalls-HGl9zBnw.mjs +0 -1
- package/dist/packem_shared/discoverMaskProcedures-B29pl7an.mjs +0 -1
- package/dist/packem_shared/discoverR2sqlCalls-BDomQsRO.mjs +0 -1
- package/dist/packem_shared/unwrap-handler-return-BTKoWeJc.mjs +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{formatAdvisories as m,lintSchema as f,toAdvisorContext as d}from"./packem_shared/formatAdvisories-DwmUKYuc.mjs";import{describeErrorLevelFindings as n,errorAdvisoryNames as l,errorPlatformDiagnosticNames as c,sortedUniqueNames as x}from"./packem_shared/describeErrorLevelFindings-vzaGS9KL.mjs";import{CAPABILITY_PROBES as E}from"./packem_shared/CAPABILITY_PROBES-brcmKenl.mjs";import{CodegenDiagnosticError as A,diagnosticAt as v}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as N,discoverAgents as g}from"./packem_shared/AGENTS_FILENAME-Dntm1vDe.mjs";import{isTestPath as R,listLunoraSourceFiles as T}from"./packem_shared/isTestPath-CiIyKqhF.mjs";import{default as I}from"./packem_shared/discoverAuthApiCalls-CeFyWdQy.mjs";import{CONTAINERS_FILENAME as L,discoverContainers as M}from"./packem_shared/CONTAINERS_FILENAME-D5xnZUl6.mjs";import{default as P}from"./packem_shared/discoverCrons-DBuEbNrB.mjs";import{capabilitiesUsedBy as b,foldCapabilitySignals as y,mayReadCapabilityContext as U,sourceCapabilitySignals as G}from"./packem_shared/capabilitiesUsedBy-CmSX6ODG.mjs";import{FLAGS_FILENAME as j,discoverFlags as B}from"./packem_shared/FLAGS_FILENAME-C1RHlinh.mjs";import{default as W}from"./packem_shared/discoverFunctions-
|
|
1
|
+
import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{formatAdvisories as m,lintSchema as f,toAdvisorContext as d}from"./packem_shared/formatAdvisories-DwmUKYuc.mjs";import{describeErrorLevelFindings as n,errorAdvisoryNames as l,errorPlatformDiagnosticNames as c,sortedUniqueNames as x}from"./packem_shared/describeErrorLevelFindings-vzaGS9KL.mjs";import{CAPABILITY_PROBES as E}from"./packem_shared/CAPABILITY_PROBES-brcmKenl.mjs";import{CodegenDiagnosticError as A,diagnosticAt as v}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as N,discoverAgents as g}from"./packem_shared/AGENTS_FILENAME-Dntm1vDe.mjs";import{isTestPath as R,listLunoraSourceFiles as T}from"./packem_shared/isTestPath-CiIyKqhF.mjs";import{default as I}from"./packem_shared/discoverAuthApiCalls-CeFyWdQy.mjs";import{CONTAINERS_FILENAME as L,discoverContainers as M}from"./packem_shared/CONTAINERS_FILENAME-D5xnZUl6.mjs";import{default as P}from"./packem_shared/discoverCrons-DBuEbNrB.mjs";import{capabilitiesUsedBy as b,foldCapabilitySignals as y,mayReadCapabilityContext as U,sourceCapabilitySignals as G}from"./packem_shared/capabilitiesUsedBy-CmSX6ODG.mjs";import{FLAGS_FILENAME as j,discoverFlags as B}from"./packem_shared/FLAGS_FILENAME-C1RHlinh.mjs";import{default as W}from"./packem_shared/discoverFunctions-DMW7bLkD.mjs";import{default as V}from"./packem_shared/discoverHttpRoutes-C2ARoV_3.mjs";import{default as Q}from"./packem_shared/discoverHyperdriveCalls-CuJGFhqZ.mjs";import{default as w}from"./packem_shared/discoverInserts-yC-_-56C.mjs";import{d as Y}from"./packem_shared/index-DET6xe1e.mjs";import{default as Z}from"./packem_shared/discoverMigrations-CM6L8k6b.mjs";import{MUTATORS_FILENAME as ee,discoverMutators as re}from"./packem_shared/MUTATORS_FILENAME-Ba-gcGFd.mjs";import{default as te}from"./packem_shared/discoverNondeterministicCalls-C6iIjMHn.mjs";import{NOTIFY_FILENAME as ae,discoverNotifyCalls as ie,discoverNotifyChannels as me,discoverNotifyConfig as fe}from"./packem_shared/NOTIFY_FILENAME-BFN2W2OF.mjs";import{default as pe}from"./packem_shared/readPackageDependencies-RHhGiz0k.mjs";import{default as le}from"./packem_shared/discoverQueries-BnLL5w1Q.mjs";import{QUEUES_FILENAME as xe,discoverQueues as Se}from"./packem_shared/QUEUES_FILENAME-hTuq7XDL.mjs";import{default as ue}from"./packem_shared/discoverR2sqlCalls-C-5wNVBz.mjs";import{default as ve}from"./packem_shared/discoverRlsProcedures-D4udDEM2.mjs";import{default as Ne}from"./packem_shared/discoverRlsMetadata-CTQN6hgU.mjs";import{discoverSandboxUsage as Oe}from"./packem_shared/discoverSandboxUsage-ejLtE6Ky.mjs";import{default as Te}from"./packem_shared/discoverSchema-C3WOG-xt.mjs";import{readServiceBindings as Ie,resolveServiceBindings as _e}from"./packem_shared/readServiceBindings-DuE9xlvV.mjs";import{SHAPES_FILENAME as Me,discoverShapes as Fe}from"./packem_shared/SHAPES_FILENAME-BrqrIhBv.mjs";import{default as De}from"./packem_shared/discoverStorageRulesMetadata-CyZ44b1b.mjs";import{WORKFLOWS_FILENAME as ye,discoverWorkflows as Ue}from"./packem_shared/WORKFLOWS_FILENAME-eLdktkM5.mjs";import{emitApp as He}from"./packem_shared/emitApp-CBIXVzkw.mjs";import{isD1GlobalTable as Be,isHyperdriveGlobalTable as ke}from"./packem_shared/isD1GlobalTable-udvHAAzD.mjs";import{buildOpenApiDocument as Ke,emitOpenApi as Ve,emitOpenApiModule as ze}from"./packem_shared/buildOpenApiDocument-D_8TtHK1.mjs";import{OPENRPC_VERSION as qe,buildOpenRpcDocument as we,emitOpenRpc as Je,emitOpenRpcModule as Ye}from"./packem_shared/OPENRPC_VERSION-DnYKkFP6.mjs";import{DEFAULT_TARGET as Ze,platformMatrixIds as $e,readProjectTarget as er,resolveCodegenTarget as rr}from"./packem_shared/DEFAULT_TARGET-GPPgJNTn.mjs";import{l as tr,r as sr}from"./packem_shared/project-config-file-Bv2l-Kmm.mjs";import{SCHEMA_SNAPSHOT_FILENAME as ir,createCodegenProject as mr,findTsconfig as fr,refreshCodegenProject as dr,runCodegen as pr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-DZhA1rb3.mjs";import{SchemaSnapshotParseError as lr,buildSchemaSnapshot as cr,evaluateSchemaDrift as xr,parseSchemaSnapshot as Sr}from"./packem_shared/SchemaSnapshotParseError-CPOXlFhI.mjs";import{default as ur}from"./packem_shared/fingerprintSchemaSources-C4PkhFFQ.mjs";import{schemaFromIr as vr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as Nr,validatorIrToJsonSchema as gr}from"./packem_shared/LUNORA_ERROR_CODES-C2s0xWQD.mjs";import{SDK_LANGUAGES as Rr,SDK_TARGETS as Tr,generateSdk as hr}from"./packem_shared/SDK_LANGUAGES-Df_CnJx5.mjs";import{redact as _r,secretKindOf as Lr}from"./packem_shared/redact-Cy14LEnc.mjs";import{default as Fr}from"./packem_shared/emitDrizzleSchema-CpOGYfyl.mjs";import{default as Dr}from"./packem_shared/emitFunctions-BeKgL3dl.mjs";import{e as yr}from"./packem_shared/server-DSUfd6Tc.mjs";import{e as Gr}from"./packem_shared/shard-BTfJuEeP.mjs";import{G as jr}from"./packem_shared/shared-DnCokNcE.mjs";import{MESSAGE_SOLUTIONS as kr,findSolutionByMessage as Wr}from"@lunora/errors";import{PROJECT_CONFIG_FILENAMES as Vr,findProjectConfigFile as zr}from"./packem_shared/PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";import{s as qr,t as wr,u as Jr}from"./packem_shared/shard-runtime-CkaEBSdL.mjs";import{emitApi as Xr,emitCollections as Zr,emitInternalApi as $r}from"./packem_shared/emitApi-Zx6VPN-7.mjs";import{emitCrons as ro,emitScheduler as oo,emitVectors as to,emitWranglerCronTriggers as so}from"./packem_shared/emitCrons-Gd8jD8jF.mjs";import{emitDataModel as io}from"./packem_shared/emitDataModel-DdtjdNg3.mjs";import{isTypedSchema as fo}from"./packem_shared/isTypedSchema-CKzc3ioR.mjs";const e="0.0.0";export{N as AGENTS_FILENAME,E as CAPABILITY_PROBES,L as CONTAINERS_FILENAME,A as CodegenDiagnosticError,Ze as DEFAULT_TARGET,j as FLAGS_FILENAME,jr as GENERATED_HEADER,Nr as LUNORA_ERROR_CODES,kr as LUNORA_SOLUTION_RULES,ee as MUTATORS_FILENAME,ae as NOTIFY_FILENAME,qe as OPENRPC_VERSION,Vr as PROJECT_CONFIG_FILENAMES,xe as QUEUES_FILENAME,ir as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,Rr as SDK_LANGUAGES,Tr as SDK_TARGETS,Me as SHAPES_FILENAME,lr as SchemaSnapshotParseError,e as VERSION,ye as WORKFLOWS_FILENAME,Ke as buildOpenApiDocument,we as buildOpenRpcDocument,cr as buildSchemaSnapshot,b as capabilitiesUsedBy,mr as createCodegenProject,n as describeErrorLevelFindings,v as diagnosticAt,s as diffSchemaSnapshots,g as discoverAgents,I as discoverAuthApiCalls,M as discoverContainers,P as discoverCrons,B as discoverFlags,W as discoverFunctions,V as discoverHttpRoutes,Q as discoverHyperdriveCalls,w as discoverInserts,Y as discoverMaskProcedures,Z as discoverMigrations,re as discoverMutators,te as discoverNondeterministicCalls,ie as discoverNotifyCalls,me as discoverNotifyChannels,fe as discoverNotifyConfig,le as discoverQueries,Se as discoverQueues,ue as discoverR2sqlCalls,Ne as discoverRlsMetadata,ve as discoverRlsProcedures,Oe as discoverSandboxUsage,Te as discoverSchema,Fe as discoverShapes,De as discoverStorageRulesMetadata,Ue as discoverWorkflows,qr as emitAgents,Xr as emitApi,He as emitApp,Zr as emitCollections,wr as emitContainers,ro as emitCrons,io as emitDataModel,Fr as emitDrizzleSchema,Dr as emitFunctions,$r as emitInternalApi,Ve as emitOpenApi,ze as emitOpenApiModule,Je as emitOpenRpc,Ye as emitOpenRpcModule,oo as emitScheduler,yr as emitServer,Gr as emitShard,to as emitVectors,Jr as emitWorkflows,so as emitWranglerCronTriggers,l as errorAdvisoryNames,c as errorPlatformDiagnosticNames,xr as evaluateSchemaDrift,Wr as findLunoraSolution,zr as findProjectConfigFile,fr as findTsconfig,ur as fingerprintSchemaSources,y as foldCapabilitySignals,m as formatAdvisories,hr as generateSdk,Be as isD1GlobalTable,ke as isHyperdriveGlobalTable,R as isTestPath,fo as isTypedSchema,f as lintSchema,T as listLunoraSourceFiles,tr as loadProjectConfig,U as mayReadCapabilityContext,Sr as parseSchemaSnapshot,$e as platformMatrixIds,pe as readPackageDependencies,sr as readProjectConfigLiterals,er as readProjectTarget,Ie as readServiceBindings,_r as redact,dr as refreshCodegenProject,rr as resolveCodegenTarget,_e as resolveServiceBindings,pr as runCodegen,vr as schemaFromIr,Lr as secretKindOf,a as serializeSchemaSnapshot,x as sortedUniqueNames,G as sourceCapabilitySignals,d as toAdvisorContext,gr as validatorIrToJsonSchema};
|
package/dist/packem_shared/{MUTATORS_FILENAME-YOl15Grm.mjs → MUTATORS_FILENAME-Ba-gcGFd.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as E}from"node:fs";import{join as y}from"node:path";import{Node as o,SyntaxKind as l}from"ts-morph";import{diagnosticAt as I}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as M}from"./module-specifiers-WF8iAydP.mjs";import{p as A}from"./parse-validator-DYdT7Hyf.mjs";import{findObjectProperty as c,unwrapExpression as d,isConstDeclaration as P}from"./isTestPath-CiIyKqhF.mjs";import{j as D,i as b,f as g,d as O}from"./attribution-DqqCSywo.mjs";import{u as w}from"./unwrap-handler-return-
|
|
1
|
+
import{existsSync as E}from"node:fs";import{join as y}from"node:path";import{Node as o,SyntaxKind as l}from"ts-morph";import{diagnosticAt as I}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as M}from"./module-specifiers-WF8iAydP.mjs";import{p as A}from"./parse-validator-DYdT7Hyf.mjs";import{findObjectProperty as c,unwrapExpression as d,isConstDeclaration as P}from"./isTestPath-CiIyKqhF.mjs";import{j as D,i as b,f as g,d as O}from"./attribution-DqqCSywo.mjs";import{u as w}from"./unwrap-handler-return-BedChFbC.mjs";const z="mutators.ts",x=M,h=r=>{const e=r.getSymbol();if(!e)return r.getText()==="defineMutator";for(const t of e.getDeclarations())if(o.isImportSpecifier(t))return x(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMutator":!1;return!1},C=r=>{const e=r.getSymbol();if(!e)return!1;for(const t of e.getDeclarations()){if(!o.isNamespaceImport(t))continue;const i=t.getFirstAncestorByKind(l.ImportDeclaration);return i!==void 0&&x(i.getModuleSpecifierValue())}return!1},N=r=>{if(o.isIdentifier(r))return h(r);if(o.isPropertyAccessExpression(r)){const e=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(e)&&C(e)}return!1},S=r=>{const e=r.getArguments()[0];return e&&o.isObjectLiteralExpression(e)?e:void 0},m=new WeakMap,p=r=>{let e=m.get(r.compilerNode);if(e===void 0){const t=r.getNameNode(),i=t?.getText();e=r.getSourceFile().getDescendantsOfKind(l.Identifier).filter(s=>s!==t&&s.getText()===i&&g(s)?.compilerNode===r.compilerNode).length===1&&O(r)===void 0,m.set(r.compilerNode,e)}return e},f=r=>{const e=o.isIdentifier(r)?g(r):void 0,t=o.isSourceFile(e?.getParent())||o.isSourceFile(e?.getParent()?.getParent()?.getParent());if(e===void 0||e.getSourceFile()!==r?.getSourceFile()||!t)return;if(o.isFunctionDeclaration(e))return e.hasBody()&&p(e)?e:void 0;const i=P(e)?d(e.getInitializer()):void 0;return(o.isArrowFunction(i)||o.isFunctionExpression(i))&&o.isVariableDeclaration(e)&&p(e)?i:void 0},G=r=>{const e=r.getInitializer();if(!o.isCallExpression(e)||!N(e.getExpression()))return;const t=c(S(e),"server");if(o.isMethodDeclaration(t))return t;if(o.isShorthandPropertyAssignment(t))return f(t.getNameNode());const i=o.isPropertyAssignment(t)?d(t.getInitializer()):void 0;return o.isArrowFunction(i)||o.isFunctionExpression(i)?i:f(i)},T=r=>{const e=c(r,"args");if(!e||!o.isPropertyAssignment(e))return{};const t=e.getInitializer();return t&&o.isObjectLiteralExpression(t)?A(t):{}},L=r=>{const e=c(r,"server");if(!e||!o.isPropertyAssignment(e))return"unknown";const t=e.getInitializer();return!t||!(o.isArrowFunction(t)||o.isFunctionExpression(t))?"unknown":w(t)},j=r=>{const e=c(r,"owner");if(!e||!o.isPropertyAssignment(e))return;const t=e.getInitializer();return t&&o.isStringLiteral(t)?t.getLiteralValue():void 0},R=r=>{const e=[];for(const t of r.getVariableDeclarations()){if(!t.isExported())continue;const i=t.getInitializer();if(i?.getKind()!==l.CallExpression)continue;const n=i,s=n.getExpression();if(!N(s))continue;const a=t.getNameNode();if(!o.isIdentifier(a))throw I(a,"defineMutator exports must be plain named exports (no destructuring)");const u=S(n);for(const v of D(t).filter(F=>b(F)))e.push({args:T(u),exportName:v,filePath:"mutators",line:n.getStartLineNumber(),owner:j(u),returnType:L(u)})}return e},J=(r,e)=>{const t=y(e,z);if(!E(t))return[];const i=r.getSourceFile(t)??r.addSourceFileAtPath(t),n=R(i);return n.sort((s,a)=>s.exportName.localeCompare(a.exportName)),n};export{z as MUTATORS_FILENAME,J as discoverMutators,N as isDefineMutatorCallee,S as mutatorLiteral,G as mutatorServerImplOf};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as v}from"node:fs";import{join as N}from"node:path";import{SyntaxKind as u,Node as r,VariableDeclarationKind as F}from"ts-morph";import{listLunoraSourceFiles as m,lunoraRelativePath as O,findObjectProperty as g,defaultExportExpression as D,handlerOf as A}from"./isTestPath-CiIyKqhF.mjs";import{b as I,d as T}from"./attribution-DqqCSywo.mjs";import{i as l}from"./context-root-
|
|
1
|
+
import{existsSync as v}from"node:fs";import{join as N}from"node:path";import{SyntaxKind as u,Node as r,VariableDeclarationKind as F}from"ts-morph";import{listLunoraSourceFiles as m,lunoraRelativePath as O,findObjectProperty as g,defaultExportExpression as D,handlerOf as A}from"./isTestPath-CiIyKqhF.mjs";import{b as I,d as T}from"./attribution-DqqCSywo.mjs";import{i as l}from"./context-root-BP60x_VP.mjs";import{c as C}from"./classify-procedure-call-HrUyDQX0.mjs";const k="notify.ts",L=new Set(["chat","inApp","send","webhook"]),h=new Set(["broadcast","send"]),M=e=>{const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const t=C(s);if(!t)return;const i=A(s,t.receiver);return i?{exportName:T(e)??e.getName(),handler:i,kind:t.kind}:void 0},x=e=>{const s=[];for(const t of I(e)){const i=M(t);i&&s.push(i)}return s},y=e=>l(e,["notify"])?"notify":l(e,["push"])||l(e,["notify","push"])?"push":void 0,w=e=>{if(!r.isPropertyAccessExpression(e))return;const s=e.getName(),t=y(e.getExpression());if(t==="notify"&&L.has(s))return`ctx.notify.${s}`;if(t==="push"&&h.has(s))return`ctx.push.${s}`},_=e=>r.isPropertyAccessExpression(e)?y(e.getExpression())==="push"&&h.has(e.getName()):!1,Z=(e,s)=>{const t=[];for(const i of m(s)){const n=e.getSourceFile(i)??e.addSourceFileAtPath(i),o=O(s,i);for(const c of x(n))if(!(c.kind!=="query"&&c.kind!=="mutation"))for(const a of c.handler.getDescendantsOfKind(u.PropertyAccessExpression)){const f=w(a);f!==void 0&&t.push({callee:f,exportName:c.exportName,file:o,kind:c.kind,line:a.getStartLineNumber()})}}return t},K=(e,s)=>{for(const t of m(s)){const i=e.getSourceFile(t)??e.addSourceFileAtPath(t);for(const n of x(i))for(const o of n.handler.getDescendantsOfKind(u.PropertyAccessExpression))if(_(o))return!0}return!1},R=new Set(["@lunora/notify"]),U=e=>{const s=e.getSymbol();if(!s)return e.getText()==="defineNotify";for(const t of s.getDeclarations())if(r.isImportSpecifier(t))return R.has(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineNotify":!1;return!1},E=(e,s=new Set)=>{const t=D(e);if(!t)return;if(!r.isIdentifier(t))return t;const i=t.getSymbol();if(!i?.isAlias())return t;const n=i.getAliasedSymbol();if(!n)return t;const o=n.getDeclarations().find(a=>r.isExportAssignment(a));if(!o)return t;const c=o.getSourceFile();if(!s.has(c.getFilePath()))return E(c,s.add(c.getFilePath()))},V=new Set(["%=","&&=","&=","**=","+=","-=","/=","<<=","=",">>=",">>>=","??=","^=","|=","||="]),p=e=>{const s=e.getSymbol();return s?.getAliasedSymbol()?.getDeclarations()[0]??s?.getDeclarations()[0]},P=e=>{if(r.isIdentifier(e))return e;if(r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e))return P(e.getExpression())},d=(e,s)=>{const t=P(e);return t!==void 0&&p(t)===s},j=(e,s)=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return!1;const i=t.getName(),n=t.getExpression(),o=r.isIdentifier(n)?n.getText():"";if(!((i==="assign"||i==="defineProperty"||i==="defineProperties")&&o==="Object"||i==="set"&&o==="Reflect"))return!1;const a=e.getArguments()[0];return a!==void 0&&r.isIdentifier(a)&&p(a)===s},z=(e,s)=>{if(r.isBinaryExpression(e))return V.has(e.getOperatorToken().getText())&&d(e.getLeft(),s);if(r.isDeleteExpression(e))return d(e.getExpression(),s);if(r.isPrefixUnaryExpression(e)||r.isPostfixUnaryExpression(e)){const t=e.getOperatorToken();return(t===u.PlusPlusToken||t===u.MinusMinusToken)&&d(e.getOperand(),s)}return r.isCallExpression(e)?j(e,s):!1},H=(e,s)=>{const t=p(e);return t===void 0?!0:s.some(i=>i.getDescendants().some(n=>z(n,t)))},W=e=>{if(r.isObjectLiteralExpression(e))return e;if(!r.isIdentifier(e))return;const s=e.getSymbol(),t=s?.getAliasedSymbol()?.getDeclarations()??s?.getDeclarations()??[];for(const i of t){if(!r.isVariableDeclaration(i))continue;const n=i.getInitializer();if(!n||!r.isObjectLiteralExpression(n))continue;const o=i.getParent();if(!r.isVariableDeclarationList(o)||o.getDeclarationKind()!==F.Const)continue;const c=[i.getSourceFile(),e.getSourceFile()].filter((a,f,S)=>S.findIndex(b=>b.getFilePath()===a.getFilePath())===f);if(!H(e,c))return n}},Y=(e,s)=>{const t=N(s,k);if(!v(t))return;const i=e.getSourceFile(t)??e.addSourceFileAtPath(t),n=E(i);if(!n||!r.isCallExpression(n))return{hasFcm:!0,hasWebPush:!0};const o=n.getExpression(),c=r.isIdentifier(o)&&U(o)?n.getArguments()[0]:void 0,a=c===void 0?void 0:W(c);return!a||a.getProperties().some(f=>r.isSpreadAssignment(f))?{hasFcm:!0,hasWebPush:!0}:{hasFcm:g(a,"fcm")!==void 0,hasWebPush:g(a,"webPush")!==void 0}},ee=(e,s)=>{const t=Y(e,s);return t===void 0?void 0:{...t,usesPush:K(e,s)}};export{k as NOTIFY_FILENAME,Z as discoverNotifyCalls,Y as discoverNotifyChannels,ee as discoverNotifyConfig};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{existsSync as R,mkdirSync as Xs,rmSync as mt,readdirSync as pr,readFileSync as mr,writeFileSync as hr}from"node:fs";import{join as v,dirname as he,relative as vr}from"node:path";import{performance as rt}from"node:perf_hooks";import{runAdvisor as Er}from"@lunora/advisor";import{LunoraError as J}from"@lunora/errors";import{readJsonSync as xr}from"@visulima/fs";import{SyntaxKind as d,Node as i,ts as Sr,Project as ls}from"ts-morph";import{serializeSchemaSnapshot as Ar}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{toAdvisorContext as yr}from"./formatAdvisories-DwmUKYuc.mjs";import{r as br,a as S,s as Nr,b as Pr}from"./project-config-file-Bv2l-Kmm.mjs";import{a as ke,d as wr,r as Ir}from"./modules-Cuogms61.mjs";import{WORKFLOWS_FILENAME as Cr,discoverWorkflows as Tr}from"./WORKFLOWS_FILENAME-eLdktkM5.mjs";import{r as Or}from"./json-data-Chfs2Cz5.mjs";import{G as kr}from"./shared-DnCokNcE.mjs";import{n as Rr,s as Js}from"./dispatch-namespace-DwTjD7BU.mjs";import{CAPABILITIES as Fr,usedCapabilities as Dr}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{isD1GlobalTable as Zs,isHyperdriveGlobalTable as en}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as Lr}from"./AGENTS_FILENAME-Dntm1vDe.mjs";import{discoverContainers as Mr}from"./CONTAINERS_FILENAME-D5xnZUl6.mjs";import _r from"./discoverCrons-DBuEbNrB.mjs";import{diagnosticAt as ye}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as qe}from"./module-specifiers-WF8iAydP.mjs";import{a as tn,b as H,d as U,f as F,g as Ct,c as E,w as Tt,k as Kr,l as Br,h as zr,j as ht,i as $r}from"./attribution-DqqCSywo.mjs";import{contextPropertiesRead as Ur,discoverFeatureUsage as Vr}from"./capabilitiesUsedBy-CmSX6ODG.mjs";import qr from"./readPackageDependencies-RHhGiz0k.mjs";import{listLunoraSourceFiles as x,unwrapExpression as h,listSecurityScanFiles as je,objectLiteralFromCallbackBody as sn,propertyInitializer as C,lunoraRelativePath as T,bindingKeyName as se,collectCallRows as O,findObjectProperty as M,collectSecurityCallRows as jr,isSameNode as A,isFunctionLike as Z,collectNodeRows as de,RUN_METHODS as nn,functionKeyOf as rn,limitNameOf as on,optionsObjectLiteral as an,handlerOf as Wr,chainRootOf as Ot,outermostValueWrapper as I,isWriteTarget as We,isConstDeclaration as ee,memberAccessOf as cn,returningFunctionOf as vt,walkChain as Hr,functionReferenceSegments as Gr,isTestPath as Yr}from"./isTestPath-CiIyKqhF.mjs";import{discoverQueueDeclarations as Qr}from"./QUEUES_FILENAME-hTuq7XDL.mjs";import{discoverSandboxUsage as Xr}from"./discoverSandboxUsage-ejLtE6Ky.mjs";import{resolveServiceBindings as Jr}from"./readServiceBindings-DuE9xlvV.mjs";import Zr from"./discoverStorageRulesMetadata-CyZ44b1b.mjs";import{a as y,c as G,d as ln,e as ei}from"./classify-procedure-call-HrUyDQX0.mjs";import{i as ti}from"./ir-DBSvhNa-.mjs";import{gatePlatformFeatures as si,resolveCodegenTarget as dn,readTargetDiagnostics as ni,studioPlatformFor as ri}from"./DEFAULT_TARGET-GPPgJNTn.mjs";import{b as un,e as ii}from"./shard-BTfJuEeP.mjs";import{e as oi,a as ai}from"./server-DSUfd6Tc.mjs";import{emitDataModel as ci}from"./emitDataModel-DdtjdNg3.mjs";import{a as ds,r as it,i as q,b as li,m as fn,c as He,e as kt,E as gn,C as pn,d as di,f as ui,g as fi}from"./context-root-DKsAPUmn.mjs";import{r as Ge,s as gi}from"./parse-validator-DYdT7Hyf.mjs";import pi from"./discoverAuthApiCalls-CeFyWdQy.mjs";import{i as mi,a as hi,e as vi,b as Ei,d as xi,c as Si}from"./unwrap-handler-return-BTKoWeJc.mjs";import Ai from"./discoverFunctions-BswBeUWK.mjs";import yi from"./discoverHttpRoutes-6utMwfNf.mjs";import bi from"./discoverHyperdriveCalls-HGl9zBnw.mjs";import Ni from"./discoverInserts-Ao36AnSp.mjs";import{m as Rt,a as _e,s as mn,d as Pi}from"./index-BfaSHMNi.mjs";import{e as hn}from"./exported-procedure-chains--nYG8cid.mjs";import wi from"./discoverMigrations-CM6L8k6b.mjs";import{i as $,r as vn}from"./database-calls-CBlsQTga.mjs";import{MUTATORS_FILENAME as Ii,isDefineMutatorCallee as Ci,mutatorServerImplOf as Ti,discoverMutators as Oi}from"./MUTATORS_FILENAME-YOl15Grm.mjs";import ki from"./discoverNondeterministicCalls-C6iIjMHn.mjs";import{discoverNotifyConfig as Ri,discoverNotifyCalls as Fi}from"./NOTIFY_FILENAME-B8Wb9kiq.mjs";import Di from"./discoverQueries-4lacKgx_.mjs";import Li from"./discoverR2sqlCalls-BDomQsRO.mjs";import Mi from"./discoverRlsProcedures-DllbV6_E.mjs";import _i from"./discoverRlsMetadata-CTQN6hgU.mjs";import Ki from"./discoverSchema-C3WOG-xt.mjs";import{secretKindOf as Bi,redact as zi,isHeuristicSecretKind as $i,isSecretishName as Ui}from"./redact-Cy14LEnc.mjs";import{discoverShapes as Vi}from"./SHAPES_FILENAME-BrqrIhBv.mjs";import{i as qi}from"./reserved-words-CW1QFbTd.mjs";import{emitApp as ji}from"./emitApp-CBIXVzkw.mjs";import{buildOpenApiDocument as Wi,emitOpenApiModule as Hi}from"./buildOpenApiDocument-D_8TtHK1.mjs";import{buildOpenRpcDocument as Gi,emitOpenRpcModule as Yi}from"./OPENRPC_VERSION-DnYKkFP6.mjs";import{buildSchemaSnapshot as Qi}from"./SchemaSnapshotParseError-CPOXlFhI.mjs";import{v as Xi,t as Ji,u as Zi,s as eo,w as to}from"./shard-runtime-CkaEBSdL.mjs";import{emitCollections as so,emitSeed as no,emitApi as ro,emitInternalApi as io}from"./emitApi-Zx6VPN-7.mjs";import{emitCrons as oo,emitScheduler as ao,emitShardRegistry as co,emitDurableObjects as lo,emitVectors as uo,emitWranglerCronTriggers as fo}from"./emitCrons-Gd8jD8jF.mjs";import go from"./emitDrizzleSchema-CpOGYfyl.mjs";import po from"./emitFunctions-BeKgL3dl.mjs";const us={error:"ERROR",info:"INFO",warn:"WARN"},fs={ERROR:2,INFO:0,WARN:1},mo=e=>({cacheKey:"advisor_min_severity_invalid",categories:["SCHEMA"],description:"`advisor.minSeverity` in `lunora.config.*` sets the lowest advisory level codegen reports and writes into `_generated/shard.ts`. Codegen reads it by parsing the file, so it has to be a string literal.",detail:e,facing:"INTERNAL",level:"WARN",metadata:{},name:"advisor_min_severity_invalid",remediation:'Set `advisor: { minSeverity: "info" | "warn" | "error" }` as a literal on the config\'s default export.',title:"`advisor.minSeverity` is not a level codegen can read, so every advisory was reported"}),ho=(e,t)=>{const{advisor:s}=br(e);if(s===void 0||s.minSeverity===void 0&&s.unreadable!==!0)return[...t];const{minSeverity:n}=s,r=n!==void 0&&Object.hasOwn(us,n)?us[n]:void 0;return r===void 0?[...t,mo(n===void 0?"`advisor.minSeverity` is not a string literal codegen can read without evaluating the config: a computed value or key, or a spread that could set or override it.":`\`advisor.minSeverity\` is "${n}", which is not one of "info", "warn" or "error".`)]:t.filter(o=>fs[o.level]>=fs[r])},vo={call:"function",enqueue:"queue",invoke:"service",publish:"topic",schedule:"function"},Eo="crons",xo=Cr.replace(/\.ts$/u,""),le=(e,t)=>`${Js(e)}:${t}`,ot=(e,t,s)=>t===""?{reason:`the ${s} is not a string literal`}:{to:`${e}:${t}`},So=e=>[...e.callEdges.map(t=>{const s=t.target===void 0?{reason:t.reason??"unreadable target"}:{to:`${vo[t.kind]}:${t.target}`};return{file:t.file,kind:t.kind,line:t.line,scope:t.scope,...s}}),...e.queries.map(t=>({file:t.file,kind:"read",line:t.line,scope:t.scope,...ot("table",t.table,"table name")})),...[...e.inserts,...e.tableWrites].map(t=>({file:t.file,kind:"write",line:t.line,scope:t.scope,...ot("table",t.table,"written table")})),...e.workflowCalls.map(t=>({file:t.file,kind:"start",line:t.line,scope:t.scope,...ot("workflow",t.workflow,"workflow name")}))],Ao=e=>e.untracked===!0?"inside a helper only code outside any export calls":"inside a non-exported helper",yo=e=>{const{scope:t}=e;switch(t.kind){case"export":return[{...e,exportName:t.name}];case"helper":return t.callers.length===0?[{...e,unattributed:Ao(t)}]:t.callers.map(s=>({...e,exportName:s}));default:return[{...e,unattributed:"at module scope"}]}},bo=e=>So(e).flatMap(t=>yo(t)),No=e=>[...e.queues.flatMap(t=>t.topic===void 0?[]:[{file:t.filePath,from:`topic:${t.topic}`,kind:"subscribe",line:0,to:`queue:${t.exportName}`}]),...e.crons.map(t=>{const s=t.workflow===void 0?void 0:`workflow:${t.workflow.exportName}`,n=t.functionPath===void 0?void 0:`function:${t.functionPath}`,r=s??n;return{file:Eo,from:`cron:${t.name}`,kind:"trigger",line:0,...r===void 0?{reason:"the cron has no target"}:{to:r}}})],Po=e=>new Map(e.flatMap(t=>t.tables.map(s=>[s,t.name]))),me=(e,t)=>t===void 0?e:{...e,module:t},wo=e=>{const t=new Map,s=new Map,n=Po(e.modules),r=(c,l)=>{s.set(c,[...s.get(c)??[],l])},o=(c,l)=>{t.set(c.id,c),l!==void 0&&r(l,c.id)},a=(c,l)=>{c!==void 0&&r(le(c.file,c.exportName),l)};for(const c of e.functions){const l=le(c.filePath,c.exportName),u=[...Rr(c.filePath),c.exportName].join(".");o(me({detail:c.kind,id:`function:${l}`,kind:"function",name:u},ke(e.modules,c.filePath)),l)}for(const c of e.httpRoutes){const l=le(c.filePath,c.exportName);o(me({id:`http:${l}`,kind:"http",name:`${c.method} ${c.path}`},ke(e.modules,c.filePath)),l)}for(const c of e.schema.tables)o(me({id:`table:${c.name}`,kind:"table",name:c.name},n.get(c.name)));for(const c of e.queues){const l=c.topic===void 0?{}:{detail:"subscription"};o(me({...l,id:`queue:${c.exportName}`,kind:"queue",name:c.exportName},ke(e.modules,c.filePath)),le(c.filePath,c.exportName)),a(c.handlerSite,`queue:${c.exportName}`)}for(const c of e.topics)o(me({id:`topic:${c.exportName}`,kind:"topic",name:c.exportName},ke(e.modules,c.filePath)));for(const c of e.workflows)o({id:`workflow:${c.exportName}`,kind:"workflow",name:c.exportName},le(xo,c.exportName)),a(c.handlerSite,`workflow:${c.exportName}`);for(const c of e.crons)o({detail:c.cron,id:`cron:${c.name}`,kind:"cron",name:c.name});for(const c of e.services){const l=c.rpcEntrypoint===void 0?"fetch":"rpc";o({detail:c.entrypoint===void 0?l:`${l} · ${c.entrypoint}`,id:`service:${c.name}`,kind:"service",name:c.worker})}return{nodes:t,sites:s}},Io=e=>e==="default"?"the default export is not a registered function":`"${e}" is not a registered function`,Co=(e,t)=>"from"in e?[e.from]:"unattributed"in e?{reason:e.unattributed}:t.get(le(e.file,e.exportName))??{reason:Io(e.exportName)},To=(e,t,s)=>{if("reason"in e)return{reason:e.reason};const n=Co(e,t);if("reason"in n)return n;const{to:r}=e;return s.has(r)?{drawn:n.map(o=>({from:o,kind:e.kind,to:r}))}:{reason:`${r} is not declared`}},at=e=>`${e.from}|${e.kind}|${e.to}`,Oo=e=>`${e.file}|${String(e.line)}|${e.kind}|${e.reason}`,ko=e=>{const{nodes:t,sites:s}=wo(e),n=new Map,r=new Map;for(const o of[...No(e),...bo(e)]){const a=To(o,s,t);if("drawn"in a)for(const c of a.drawn)n.set(at(c),c);else{const c={file:o.file,kind:o.kind,line:o.line,reason:a.reason};r.set(Oo(c),c)}}return{edges:[...n.values()].toSorted((o,a)=>at(o).localeCompare(at(a))),nodes:[...t.values()].toSorted((o,a)=>o.id.localeCompare(a.id)),modules:e.modules.map(o=>({...o.description===void 0?{}:{description:o.description},...o.installed===!0?{installed:!0}:{},...o.ownsFolder===!1?{ownsFolder:!1}:{},name:o.name,tables:[...o.tables]})),unresolved:[...r.values()].toSorted((o,a)=>o.file.localeCompare(a.file)||o.line-a.line),version:1}},Ro=e=>`${kr}export const architecture = ${Or(e,"Record<string, unknown>")};
|
|
2
|
-
`,gs=(e,t="api")=>{const s=new Map;for(const n of e){const r=Js(n),o=s.get(r);if(o===void 0){s.set(r,n);continue}if(o!==n){const a=t==="api"?`the generated api.ts would declare "${r}" twice and the dispatch key "${r}:<fn>" would be ambiguous`:`the generated api.ts would declare "${r}" twice in HttpStreamsRef and again in the httpStreams object literal`;throw new J("INTERNAL",`@lunora/codegen: "${o}" and "${n}" both map to the ${t} namespace "${r}" — ${a}. Rename one file so the two differ by more than a non-identifier character (\`-\`, \`.\`, \`/\` and \`_\` all sanitize to \`_\`).`,{status:500})}}},
|
|
1
|
+
import{existsSync as R,mkdirSync as Xs,rmSync as mt,readdirSync as hr,readFileSync as vr,writeFileSync as Er}from"node:fs";import{join as v,dirname as he,relative as xr}from"node:path";import{performance as rt}from"node:perf_hooks";import{runAdvisor as Sr}from"@lunora/advisor";import{LunoraError as J}from"@lunora/errors";import{readJsonSync as Ar}from"@visulima/fs";import{SyntaxKind as d,Node as i,ts as yr,Project as ls}from"ts-morph";import{serializeSchemaSnapshot as br}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{toAdvisorContext as Nr}from"./formatAdvisories-DwmUKYuc.mjs";import{r as Pr,a as A,s as wr,b as Ir}from"./project-config-file-Bv2l-Kmm.mjs";import{a as ke,d as Cr,r as Tr}from"./modules-Cuogms61.mjs";import{WORKFLOWS_FILENAME as Or,discoverWorkflows as kr}from"./WORKFLOWS_FILENAME-eLdktkM5.mjs";import{r as Rr}from"./json-data-Chfs2Cz5.mjs";import{G as Fr}from"./shared-DnCokNcE.mjs";import{n as Dr,s as Js}from"./dispatch-namespace-DwTjD7BU.mjs";import{CAPABILITIES as Lr,usedCapabilities as Mr}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{isD1GlobalTable as Zs,isHyperdriveGlobalTable as en}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as _r}from"./AGENTS_FILENAME-Dntm1vDe.mjs";import{discoverContainers as Kr}from"./CONTAINERS_FILENAME-D5xnZUl6.mjs";import Br from"./discoverCrons-DBuEbNrB.mjs";import{diagnosticAt as ye}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as qe}from"./module-specifiers-WF8iAydP.mjs";import{a as tn,b as H,d as U,f as F,g as Ct,c as E,w as Tt,k as zr,l as $r,h as Ur,j as ht,i as Vr}from"./attribution-DqqCSywo.mjs";import{contextPropertiesRead as qr,discoverFeatureUsage as jr}from"./capabilitiesUsedBy-CmSX6ODG.mjs";import Wr from"./readPackageDependencies-RHhGiz0k.mjs";import{listLunoraSourceFiles as x,unwrapExpression as h,listSecurityScanFiles as je,objectLiteralFromCallbackBody as sn,propertyInitializer as C,lunoraRelativePath as T,bindingKeyName as se,collectCallRows as O,findObjectProperty as M,collectSecurityCallRows as Hr,isSameNode as y,isFunctionLike as Z,collectNodeRows as de,RUN_METHODS as nn,functionKeyOf as rn,limitNameOf as on,optionsObjectLiteral as an,handlerOf as Gr,chainRootOf as Ot,outermostValueWrapper as I,isWriteTarget as We,isConstDeclaration as ee,memberAccessOf as cn,returningFunctionOf as vt,walkChain as Yr,functionReferenceSegments as Qr,isTestPath as Xr}from"./isTestPath-CiIyKqhF.mjs";import{discoverQueueDeclarations as Jr}from"./QUEUES_FILENAME-hTuq7XDL.mjs";import{discoverSandboxUsage as Zr}from"./discoverSandboxUsage-ejLtE6Ky.mjs";import{resolveServiceBindings as ei}from"./readServiceBindings-DuE9xlvV.mjs";import ti from"./discoverStorageRulesMetadata-CyZ44b1b.mjs";import{a as b,c as G,d as ln,e as si}from"./classify-procedure-call-HrUyDQX0.mjs";import{i as ni}from"./ir-DBSvhNa-.mjs";import{gatePlatformFeatures as ri,resolveCodegenTarget as dn,readTargetDiagnostics as ii,studioPlatformFor as oi}from"./DEFAULT_TARGET-GPPgJNTn.mjs";import{b as un,e as ai}from"./shard-BTfJuEeP.mjs";import{e as ci,a as li}from"./server-DSUfd6Tc.mjs";import{emitDataModel as di}from"./emitDataModel-DdtjdNg3.mjs";import{a as ds,r as it,i as q,b as ui,m as fn,c as He,e as kt,E as gn,C as pn,d as fi,f as gi,g as pi}from"./context-root-BP60x_VP.mjs";import{r as Ge,s as mi}from"./parse-validator-DYdT7Hyf.mjs";import hi from"./discoverAuthApiCalls-CeFyWdQy.mjs";import{i as vi,a as Ei,e as xi,b as Si,d as Ai,c as yi}from"./unwrap-handler-return-BedChFbC.mjs";import bi from"./discoverFunctions-DMW7bLkD.mjs";import Ni from"./discoverHttpRoutes-C2ARoV_3.mjs";import Pi from"./discoverHyperdriveCalls-CuJGFhqZ.mjs";import wi from"./discoverInserts-yC-_-56C.mjs";import{m as Rt,a as _e,s as mn,d as Ii}from"./index-DET6xe1e.mjs";import{e as hn}from"./exported-procedure-chains--nYG8cid.mjs";import Ci from"./discoverMigrations-CM6L8k6b.mjs";import{i as $,r as vn}from"./database-calls-AHFbJnIy.mjs";import{MUTATORS_FILENAME as Ti,isDefineMutatorCallee as Oi,mutatorServerImplOf as ki,discoverMutators as Ri}from"./MUTATORS_FILENAME-Ba-gcGFd.mjs";import Fi from"./discoverNondeterministicCalls-C6iIjMHn.mjs";import{discoverNotifyConfig as Di,discoverNotifyCalls as Li}from"./NOTIFY_FILENAME-BFN2W2OF.mjs";import Mi from"./discoverQueries-BnLL5w1Q.mjs";import _i from"./discoverR2sqlCalls-C-5wNVBz.mjs";import Ki from"./discoverRlsProcedures-D4udDEM2.mjs";import Bi from"./discoverRlsMetadata-CTQN6hgU.mjs";import zi from"./discoverSchema-C3WOG-xt.mjs";import{secretKindOf as $i,redact as Ui,isHeuristicSecretKind as Vi,isSecretishName as qi}from"./redact-Cy14LEnc.mjs";import{discoverShapes as ji}from"./SHAPES_FILENAME-BrqrIhBv.mjs";import{i as Wi}from"./reserved-words-CW1QFbTd.mjs";import{emitApp as Hi}from"./emitApp-CBIXVzkw.mjs";import{buildOpenApiDocument as Gi,emitOpenApiModule as Yi}from"./buildOpenApiDocument-D_8TtHK1.mjs";import{buildOpenRpcDocument as Qi,emitOpenRpcModule as Xi}from"./OPENRPC_VERSION-DnYKkFP6.mjs";import{buildSchemaSnapshot as Ji}from"./SchemaSnapshotParseError-CPOXlFhI.mjs";import{v as Zi,t as eo,u as to,s as so,w as no}from"./shard-runtime-CkaEBSdL.mjs";import{emitCollections as ro,emitSeed as io,emitApi as oo,emitInternalApi as ao}from"./emitApi-Zx6VPN-7.mjs";import{emitCrons as co,emitScheduler as lo,emitShardRegistry as uo,emitDurableObjects as fo,emitVectors as go,emitWranglerCronTriggers as po}from"./emitCrons-Gd8jD8jF.mjs";import mo from"./emitDrizzleSchema-CpOGYfyl.mjs";import ho from"./emitFunctions-BeKgL3dl.mjs";const us={error:"ERROR",info:"INFO",warn:"WARN"},fs={ERROR:2,INFO:0,WARN:1},vo=e=>({cacheKey:"advisor_min_severity_invalid",categories:["SCHEMA"],description:"`advisor.minSeverity` in `lunora.config.*` sets the lowest advisory level codegen reports and writes into `_generated/shard.ts`. Codegen reads it by parsing the file, so it has to be a string literal.",detail:e,facing:"INTERNAL",level:"WARN",metadata:{},name:"advisor_min_severity_invalid",remediation:'Set `advisor: { minSeverity: "info" | "warn" | "error" }` as a literal on the config\'s default export.',title:"`advisor.minSeverity` is not a level codegen can read, so every advisory was reported"}),Eo=(e,t)=>{const{advisor:s}=Pr(e);if(s===void 0||s.minSeverity===void 0&&s.unreadable!==!0)return[...t];const{minSeverity:n}=s,r=n!==void 0&&Object.hasOwn(us,n)?us[n]:void 0;return r===void 0?[...t,vo(n===void 0?"`advisor.minSeverity` is not a string literal codegen can read without evaluating the config: a computed value or key, or a spread that could set or override it.":`\`advisor.minSeverity\` is "${n}", which is not one of "info", "warn" or "error".`)]:t.filter(o=>fs[o.level]>=fs[r])},xo={call:"function",enqueue:"queue",invoke:"service",publish:"topic",schedule:"function"},So="crons",Ao=Or.replace(/\.ts$/u,""),le=(e,t)=>`${Js(e)}:${t}`,ot=(e,t,s)=>t===""?{reason:`the ${s} is not a string literal`}:{to:`${e}:${t}`},yo=e=>[...e.callEdges.map(t=>{const s=t.target===void 0?{reason:t.reason??"unreadable target"}:{to:`${xo[t.kind]}:${t.target}`};return{file:t.file,kind:t.kind,line:t.line,scope:t.scope,...s}}),...e.queries.map(t=>({file:t.file,kind:"read",line:t.line,scope:t.scope,...ot("table",t.table,"table name")})),...[...e.inserts,...e.tableWrites].map(t=>({file:t.file,kind:"write",line:t.line,scope:t.scope,...ot("table",t.table,"written table")})),...e.workflowCalls.map(t=>({file:t.file,kind:"start",line:t.line,scope:t.scope,...ot("workflow",t.workflow,"workflow name")}))],bo=e=>e.untracked===!0?"inside a helper only code outside any export calls":"inside a non-exported helper",No=e=>{const{scope:t}=e;switch(t.kind){case"export":return[{...e,exportName:t.name}];case"helper":return t.callers.length===0?[{...e,unattributed:bo(t)}]:t.callers.map(s=>({...e,exportName:s}));default:return[{...e,unattributed:"at module scope"}]}},Po=e=>yo(e).flatMap(t=>No(t)),wo=e=>[...e.queues.flatMap(t=>t.topic===void 0?[]:[{file:t.filePath,from:`topic:${t.topic}`,kind:"subscribe",line:0,to:`queue:${t.exportName}`}]),...e.crons.map(t=>{const s=t.workflow===void 0?void 0:`workflow:${t.workflow.exportName}`,n=t.functionPath===void 0?void 0:`function:${t.functionPath}`,r=s??n;return{file:So,from:`cron:${t.name}`,kind:"trigger",line:0,...r===void 0?{reason:"the cron has no target"}:{to:r}}})],Io=e=>new Map(e.flatMap(t=>t.tables.map(s=>[s,t.name]))),me=(e,t)=>t===void 0?e:{...e,module:t},Co=e=>{const t=new Map,s=new Map,n=Io(e.modules),r=(c,l)=>{s.set(c,[...s.get(c)??[],l])},o=(c,l)=>{t.set(c.id,c),l!==void 0&&r(l,c.id)},a=(c,l)=>{c!==void 0&&r(le(c.file,c.exportName),l)};for(const c of e.functions){const l=le(c.filePath,c.exportName),u=[...Dr(c.filePath),c.exportName].join(".");o(me({detail:c.kind,id:`function:${l}`,kind:"function",name:u},ke(e.modules,c.filePath)),l)}for(const c of e.httpRoutes){const l=le(c.filePath,c.exportName);o(me({id:`http:${l}`,kind:"http",name:`${c.method} ${c.path}`},ke(e.modules,c.filePath)),l)}for(const c of e.schema.tables)o(me({id:`table:${c.name}`,kind:"table",name:c.name},n.get(c.name)));for(const c of e.queues){const l=c.topic===void 0?{}:{detail:"subscription"};o(me({...l,id:`queue:${c.exportName}`,kind:"queue",name:c.exportName},ke(e.modules,c.filePath)),le(c.filePath,c.exportName)),a(c.handlerSite,`queue:${c.exportName}`)}for(const c of e.topics)o(me({id:`topic:${c.exportName}`,kind:"topic",name:c.exportName},ke(e.modules,c.filePath)));for(const c of e.workflows)o({id:`workflow:${c.exportName}`,kind:"workflow",name:c.exportName},le(Ao,c.exportName)),a(c.handlerSite,`workflow:${c.exportName}`);for(const c of e.crons)o({detail:c.cron,id:`cron:${c.name}`,kind:"cron",name:c.name});for(const c of e.services){const l=c.rpcEntrypoint===void 0?"fetch":"rpc";o({detail:c.entrypoint===void 0?l:`${l} · ${c.entrypoint}`,id:`service:${c.name}`,kind:"service",name:c.worker})}return{nodes:t,sites:s}},To=e=>e==="default"?"the default export is not a registered function":`"${e}" is not a registered function`,Oo=(e,t)=>"from"in e?[e.from]:"unattributed"in e?{reason:e.unattributed}:t.get(le(e.file,e.exportName))??{reason:To(e.exportName)},ko=(e,t,s)=>{if("reason"in e)return{reason:e.reason};const n=Oo(e,t);if("reason"in n)return n;const{to:r}=e;return s.has(r)?{drawn:n.map(o=>({from:o,kind:e.kind,to:r}))}:{reason:`${r} is not declared`}},at=e=>`${e.from}|${e.kind}|${e.to}`,Ro=e=>`${e.file}|${String(e.line)}|${e.kind}|${e.reason}`,Fo=e=>{const{nodes:t,sites:s}=Co(e),n=new Map,r=new Map;for(const o of[...wo(e),...Po(e)]){const a=ko(o,s,t);if("drawn"in a)for(const c of a.drawn)n.set(at(c),c);else{const c={file:o.file,kind:o.kind,line:o.line,reason:a.reason};r.set(Ro(c),c)}}return{edges:[...n.values()].toSorted((o,a)=>at(o).localeCompare(at(a))),nodes:[...t.values()].toSorted((o,a)=>o.id.localeCompare(a.id)),modules:e.modules.map(o=>({...o.description===void 0?{}:{description:o.description},...o.installed===!0?{installed:!0}:{},...o.ownsFolder===!1?{ownsFolder:!1}:{},name:o.name,tables:[...o.tables]})),unresolved:[...r.values()].toSorted((o,a)=>o.file.localeCompare(a.file)||o.line-a.line),version:1}},Do=e=>`${Fr}export const architecture = ${Rr(e,"Record<string, unknown>")};
|
|
2
|
+
`,gs=(e,t="api")=>{const s=new Map;for(const n of e){const r=Js(n),o=s.get(r);if(o===void 0){s.set(r,n);continue}if(o!==n){const a=t==="api"?`the generated api.ts would declare "${r}" twice and the dispatch key "${r}:<fn>" would be ambiguous`:`the generated api.ts would declare "${r}" twice in HttpStreamsRef and again in the httpStreams object literal`;throw new J("INTERNAL",`@lunora/codegen: "${o}" and "${n}" both map to the ${t} namespace "${r}" — ${a}. Rename one file so the two differ by more than a non-identifier character (\`-\`, \`.\`, \`/\` and \`_\` all sanitize to \`_\`).`,{status:500})}}},Lo=(e,t={})=>{const{hasVectors:s=!0,scheduler:n=!1,storage:r=!1,usage:o}=t,a=[];e.tables.some(c=>Zs(c))&&a.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),e.tables.some(c=>en(c))&&a.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'},{name:"@lunora/sql-store",reason:'`.global({ backend: "hyperdrive" })` makes `_generated/app.ts` import the `SqlCtxDbOptions` / `SqlExec` types'}),n&&a.push({name:"@lunora/scheduler",reason:"a declared cron (or `ctx.scheduler` use) makes `_generated/app.ts` import `createScheduler`"}),r&&a.push({name:"@lunora/storage",reason:"a `v.storage()` column, a storage access rule (or `ctx.storage` use) makes `_generated/app.ts` import `createStorage`"}),e.vectorIndexes.length>0&&s&&a.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/shard.ts` import `@lunora/bindings/vectors`"});for(const c of o===void 0?[]:Lr)c.requiredPackage!==void 0&&o?.[c.key]===!0&&a.push({name:c.requiredPackage,reason:`\`ctx.${c.contextProperty??c.key}\` usage makes \`_generated/\` import \`${c.moduleSpecifier}\``});return a.filter((c,l)=>a.findIndex(u=>u.name===c.name)===l)},Mo=(e,t,s={})=>{if(t===void 0)return;const n=Lo(e,s).filter(o=>!t.has(o.name));if(n.length===0)return;const r=n.map(o=>` - ${o.name} — ${o.reason}`).join(`
|
|
3
3
|
`);throw new J("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
|
|
4
4
|
${r}
|
|
5
5
|
|
|
6
|
-
Install them with your package manager, then re-run codegen.`)},Lo="env.ts",Mo=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return qe(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},_o=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(d.ImportDeclaration);return n!==void 0&&qe(n.getModuleSpecifierValue())}return!1},Ko=e=>{if(i.isIdentifier(e))return Mo(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&_o(t)}return!1},Bo=e=>{const t=[];for(const s of e.getVariableDeclarations()){const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!Ko(n.getExpression()))continue;const o=s.getNameNode();if(!i.isIdentifier(o)){if(s.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw ye(o,"defineEnv exports must be plain named exports (no destructuring)")}const a=tn(s,"member");a!==void 0&&t.push({exportName:a})}return t},zo=(e,t)=>{const s=v(t,Lo);if(!R(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),r=Bo(n);if(r.length!==0){if(r.length>1)throw ye(n,`lunora/env.ts declares ${r.length.toString()} defineEnv() contracts (${r.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return r[0]}},En="identity.ts",$o=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return qe(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Uo=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(d.ImportDeclaration);return n!==void 0&&qe(n.getModuleSpecifierValue())}return!1},Vo=e=>{if(i.isIdentifier(e))return $o(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&Uo(t)}return!1},qo=e=>{const t=[];for(const s of e.getVariableDeclarations()){const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!Vo(n.getExpression()))continue;const o=s.getNameNode();if(!i.isIdentifier(o)){if(s.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw ye(o,"defineIdentity exports must be plain named exports (no destructuring)")}const a=tn(s,"member");a!==void 0&&t.push({exportName:a})}return t},jo=(e,t)=>{const s=v(t,En);if(!R(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),r=qo(n);if(r.length!==0){if(r.length>1)throw ye(n,`lunora/identity.ts declares ${r.length.toString()} defineIdentity() contracts (${r.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return r[0]}},Wo=new Set(["allowedHosts","deniedHosts","interceptHttps"]),Ho=(e,t)=>{const s=h(t);if(s===void 0||!i.isIdentifier(s))return s;const n=s.getText();return h(e.getDescendantsOfKind(d.VariableDeclaration).find(r=>r.getName()===n)?.getInitializer())},Go=(e,t)=>e!==void 0&&i.isObjectLiteralExpression(e)&&e.getProperties().some(s=>{if(i.isShorthandPropertyAssignment(s))return t.has(S(s));if(!i.isPropertyAssignment(s)||!t.has(S(s)))return!1;const n=h(s.getInitializer())?.getText();return n!=="false"&&n!=="undefined"}),Yo=new Set(["durable"]),Qo=new Set(["rollback"]),Xo=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)?t.getName():t.getText()},Jo=new Map([["defineContainer",{keys:Wo,signal:"containerEgressPolicy"}],["defineStep",{keys:Qo,signal:"workflowRollback"}],["stream",{keys:Yo,signal:"durableStreams"}]]),Zo=(e,t)=>{const s=Jo.get(Xo(t));if(s!==void 0)return t.getArguments().some(n=>Go(Ho(e,n),s.keys))?s.signal:void 0},ea=(e,t)=>{const s={containerEgressPolicy:!1,durableStreams:!1,secrets:!1,workflowRollback:!1};for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.secrets||(s.secrets=Ur(r).has("secrets"));for(const o of r.getDescendantsOfKind(d.CallExpression)){const a=Zo(r,o);a!==void 0&&(s[a]=!0)}if(Object.values(s).every(Boolean))break}return s},ta="createWorker",sa="extend",ps=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralValue():void 0,ms=e=>{const t=[],s=ps(C(e,"backupCron"));s!==void 0&&t.push(s);const n=C(e,"crons");if(n===void 0||!i.isObjectLiteralExpression(n))return t;for(const r of n.getProperties()){if(!i.isPropertyAssignment(r)&&!i.isMethodDeclaration(r))continue;const o=ps(r.getNameNode());o!==void 0&&t.push(o)}return t},na=e=>{const t=y(e.getExpression()),[s]=e.getArguments();if(s===void 0)return[];if(t===ta)return i.isObjectLiteralExpression(s)?ms(s):[];if(t!==sa||!(i.isArrowFunction(s)||i.isFunctionExpression(s)))return[];const n=sn(s.getBody());return n===void 0?[]:ms(n)},ra=(e,t)=>{const s=[];for(const{filePath:n}of je(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of r.getDescendantsOfKind(d.CallExpression))s.push(...na(o))}return[...new Set(s)]},xn=e=>{if(e.kind==="id")return e.tableName;if(!(e.kind!=="array"&&e.kind!=="optional"))return e.inner===void 0?void 0:xn(e.inner)},ia=e=>{const t=new Set(e.tables.map(s=>s.name));return e.tables.some(s=>Object.values(s.shape).some(n=>{const r=xn(n);return r!==void 0&&t.has(r)}))},oa=(e,t)=>{const s=new Map,n=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const o=s.get(r.name);if(o!==void 0)throw new J("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${o} and agent "${r.exportName}". Workflow and agent names share one account-wide namespace and must be unique together.`,{status:500});const a=n.get(r.className);if(a!==void 0)throw new J("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${a} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},aa=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:r}=e,o=jo(s,t),a=zo(s,t),c=Tr(s,t),{queues:l,topics:u}=Qr(s,t),g=Jr(n),f=Lr(s,t);oa(c,f);const m=Mr(s,t),b=Zr(s,t),_=_r(s,t,c,f),Y=ra(s,t),L=ea(s,t),N=Xr(s,t),z=Vr(s,t);z.browser=z.browser||N.usesSandboxBrowser;const K=si(z,dn(n,e.target),{agents:f.length>0,commitOrderedTables:r.tables.some(D=>D.commitOrdered===!0),cronTriggers:_.length>0,crossShardFanout:r.tables.some(D=>ti(D)),containerEgressPolicy:L.containerEgressPolicy,containerRuntimeScheduling:m.some(D=>D.schedulingPolicy==="durable_object"),containerSandboxTools:m.some(D=>D.sandbox===!0),durableStreams:L.durableStreams,globalTables:r.tables.some(D=>D.shardMode==="global"),queues:l.length>0,relationGraph:ia(r),secrets:L.secrets,services:g.length>0,topics:u.length>0,vectorStore:r.vectorIndexes.length>0,workerLoaders:N.usesSandboxLoader,workflowRollback:L.workflowRollback,workflowSchedules:c.some(D=>D.schedules!==void 0)}),P=K.usage,re=Dr(P),ie=K.signals.vectorStore!==!1,fe=K.signals.services===!1?[]:g,oe=qr(n),be=oe??new Set,V=be.has("lunorash");Do(r,oe,{hasVectors:ie,scheduler:P.scheduler||_.length>0,storage:P.storage||b.rules.length>0||Object.keys(un(r)).length>0,usage:P});const B=R(v(t,"flags.ts")),k=R(v(t,"notify.ts"));return{agents:f,capabilities:re,containers:m,crons:_,dataModelContent:ci(r),declaredDependencies:oe,dependencies:be,entryCronTriggers:Y,env:a,featureUsage:P,hasFlags:B,hasNotify:k,identity:o,platformGate:{...K,diagnostics:[...ni(n,e.target),...K.diagnostics]},queues:l,serverContent:oi({agents:f,capabilities:re,containers:m,env:a,hasVectors:ie,hasFlags:B,hasNotify:k,identity:o,queues:l,schema:r,services:fe,storageRuleBuckets:b.rules.map(D=>D.bucket),topics:u,useUmbrella:V,workflows:c}),services:fe,storageRulesMetadata:b,topics:u,usesSandbox:N.usesSandboxBrowser||N.usesSandboxContainer||N.usesSandboxFs,useUmbrella:V,workflows:c}},Sn=new Set(["delete","get","head","options","patch","post","put"]),ca=new Set(["handler","stream"]),la=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,hs=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),da=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Sn.has(t.getName()))return;const s=t.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!i.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},ua=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||Sn.has(n.getName()))break;s=n.getExpression()}return da(s)},fa=e=>{for(const t of e.getDescendantsOfKind(d.PropertyAccessExpression))if(hs.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&hs.has(s.getText()))return!0}return!1},ga=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||!ca.has(n.getName()))return;const r=ua(s);if(!r||!la.test(r.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&fa(o);return{exportName:U(e)??e.getName(),file:t,method:r.method,path:r.path,usesGuard:a}},pa=(e,t)=>{const s=[];for(const n of H(e)){const r=ga(n,t);r&&s.push(r)}return s},ma=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...pa(r,T(t,n)))}return s},ha=e=>{const t=e.getText(),s=n=>{const r=n.getNameNode();return i.isIdentifier(r)&&r.getText()===t};for(const n of e.getAncestors())if(!(!i.isArrowFunction(n)&&!i.isFunctionExpression(n)&&!i.isFunctionDeclaration(n)))for(const r of n.getParameters()){const o=r.getDescendantsOfKind(d.BindingElement).find(a=>s(a));if(o!==void 0)return o}},va=e=>{let t=e;for(;;){const s=t.getParent();if(!i.isObjectBindingPattern(s))return;const n=s.getParent();if(i.isBindingElement(n)){t=n;continue}return i.isParameterDeclaration(n)?se(t):void 0}},Ea=e=>{const t=e.getText();if(!e.getAncestors().some(o=>{const a=i.isFunctionLikeDeclaration(o)||i.isArrowFunction(o)?o.getParameters()[1]:void 0,c=a?.getNameNode();return a!==void 0&&(i.isIdentifier(c)?c.getText()===t:a.getDescendantsOfKind(d.BindingElement).some(l=>l.getName()===t))&&ds(a)}))return!1;const n=F(e),r=i.isParameterDeclaration(n)?n:n?.getFirstAncestorByKind(d.Parameter);return r!==void 0&&(i.isParameterDeclaration(n)||i.isBindingElement(n))&&ds(r)},vs=(e,t)=>{const s=e.getParent();if(i.isPropertyAccessExpression(s)&&s.getNameNode()===e||i.isPropertyAssignment(s)&&s.getNameNode()===e)return!1;if(e.getText()===t)return!0;const n=ha(e);return n!==void 0&&va(n)===t?!0:t==="args"&&Ea(e)},An=(e,t)=>i.isIdentifier(e)?vs(e,t):e.getDescendantsOfKind(d.Identifier).some(s=>vs(s,t)),xa=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t:void 0},Es=e=>{const t=i.isIdentifier(e)?F(e):void 0;return i.isVariableDeclaration(t)&&i.isIdentifier(t.getNameNode())&&!Ct(t)?t.getInitializer():void 0},Et=e=>An(e,"args"),j=e=>{if(!i.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a));if(s===void 0)return;const n=e.getStart();let r,o=-1;for(const a of s.getDescendantsOfKind(d.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<n&&l>o&&(r=c,o=l)}return r},W=e=>{if(Et(e))return!0;const t=j(e);return t!==void 0&&Et(t)},Sa=e=>{if(i.isCallExpression(e)||i.isNewExpression(e))return!1;const t=j(e);return t===void 0||!(i.isCallExpression(t)||i.isNewExpression(t))},ne=e=>{if(it(e))return!0;const t=Es(e);if(t!==void 0&&it(t))return!0;const s=t??e;return(i.isIdentifier(s)?[s]:s.getDescendantsOfKind(d.Identifier)).some(r=>{const o=Es(r);return o!==void 0&&it(o)})},Re=(e,t)=>An(e,t),Aa=(e,t)=>{if(Re(e,t))return!0;const s=j(e);if(s!==void 0&&Re(s,t))return!0;const n=xa(e);if(n!==void 0){const r=j(n);return r!==void 0&&Re(r,t)}return!1},ya=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:q(e.getExpression(),["ai"]),ba=(e,t)=>{if(!ya(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!W(s)||ne(s)))return{scope:E(e),file:t,line:e.getStartLineNumber()}},Na=(e,t)=>O(e,t,ba),Pa=new Set(["generateText","streamText"]),wa=new Set(["messages","prompt","system"]),Ia=[{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"]}],Ca=(e,t)=>Ia.some(s=>s.methods.has(t)&&s.prefixes.some(n=>e===n||e.startsWith(`${n}.`))),Ta=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),n=[li(t.getExpression()),t.getExpression().getText()].find(r=>r!==void 0&&Ca(r,s));return n===void 0?void 0:`${n}.${s}`},Oa=e=>{for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=Ta(t);if(s!==void 0)return s}},ka=e=>{const t=new Set,s=e.getFirstAncestor(o=>i.isArrowFunction(o)||i.isFunctionExpression(o)||i.isFunctionDeclaration(o)),[n]=s?.getParameters()??[],r=n?.getNameNode();if(r===void 0||!i.isObjectBindingPattern(r))return t;for(const o of r.getElements()){const a=se(o),c=o.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},Ra=e=>{if(Et(e))return!0;const t=ka(e);return t.size===0?!1:e.getDescendantsOfKind(d.Identifier).some(s=>t.has(s.getText()))},Fa=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!wa.has(S(t)))continue;const s=t.getInitializer();if(s!==void 0&&Ra(s))return!0}return!1},Da=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=y(n.getExpression());if(r===void 0||!Pa.has(r))continue;const[o]=n.getArguments();if(o===void 0||!i.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(d.CallExpression))if(y(c.getExpression())==="tool"&&(a=Oa(c),a!==void 0))break;a!==void 0&&s.push({scope:E(n),file:t,line:n.getStartLineNumber(),method:r,sideEffect:a,userInputDerived:Fa(o)})}return s},La=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Da(r,T(t,n)))}return s},Ma=e=>q(e,["fetch"]),_a=(e,t)=>{if(!Ma(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!W(s)))return{scope:E(e),file:t,line:e.getStartLineNumber()}},Ka=(e,t)=>O(e,t,_a),Ft=(e,t=new Set)=>{if(t.has(e))return!0;t.add(e);try{return e.getProperties().some(s=>{if(!i.isSpreadAssignment(s))return!1;const n=Ge(s.getExpression());return n===void 0||Ft(n,t)})}finally{t.delete(e)}},Ba=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=M(t,"args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer(),r=n===void 0?void 0:Ge(n);return r===void 0?{objects:[],opaque:!0}:{objects:[r],opaque:Ft(r)}},za=e=>{const t=[];let s=!1,n=e;for(;i.isCallExpression(n);){const r=n.getExpression();if(!i.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const o=n.getArguments()[0],a=o!==void 0&&i.isExpression(o)?Ge(o):void 0;a===void 0?s=!0:(t.push(a),s||=Ft(a))}n=r.getExpression()}return{objects:t,opaque:s}},Dt=(e,t)=>t?za(t):Ba(e),yn=(e,t)=>{if(t.has(e))return[];t.add(e);try{return e.getProperties().flatMap(s=>{if(i.isSpreadAssignment(s)){const n=Ge(s.getExpression());return n===void 0?[]:yn(n,t)}return i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)?[S(s)]:[]})}finally{t.delete(e)}},$a=e=>e.flatMap(t=>yn(t,new Set)),Ua=new Set(["check","length","max"]),xt=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!(!i.isPropertyAccessExpression(t)||t.getExpression().getText()!=="v"))return t.getName()},Va=e=>[e,...e.getDescendants()].filter(t=>xt(t)!==void 0),qa=e=>{let t=e;for(;;){const s=t.getParent();if(!s||!i.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;const n=s.getParent();if(!n||!i.isCallExpression(n)||n.getExpression()!==s)return!1;if(Ua.has(s.getName()))return!0;t=n}},ja=e=>{const t=[],s=[];for(const n of e)for(const r of n.getProperties()){if(!i.isPropertyAssignment(r))continue;const o=r.getInitializer();if(!o)continue;const a=Va(o),c=S(r);a.some(l=>xt(l)==="any")?t.push(c):a.some(l=>xt(l)==="string"&&!qa(l))&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Wa=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=G(s);if(n?.visibility!=="public")return;const{objects:r}=Dt(s,n.receiver),{anyArgs:o,unboundedStringArgs:a}=ja(r);if(!(o.length===0&&a.length===0))return{anyArgs:o,exportName:U(e)??e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Ha=(e,t)=>{const s=[];for(const n of H(e)){const r=Wa(n,t);r&&s.push(r)}return s},Ga=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ha(r,T(t,n)))}return s},ct=e=>e?.getKind()===d.TrueKeyword,Ya=e=>e?.getKind()===d.FalseKeyword,Qa=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Xa=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Ja=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&y(t.getExpression())==="scim"),Za=e=>e!==void 0&&i.isCallExpression(e)&&Xa.has(y(e.getExpression())??""),ec=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),tc=e=>{const t=C(e,"advanced"),s=C(e,"emailAndPassword"),n=C(e,"session");return{analyzable:!0,disableCsrfCheck:ct(C(t,"disableCSRFCheck")),emailPasswordEnabled:ct(C(s,"enabled")),requireEmailVerification:ct(C(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Ja(C(e,"plugins"))&&Za(C(e,"database")),secureCookiesDisabled:Ya(C(t,"useSecureCookies")),sessionFreshAgeZero:Qa(C(n,"freshAge")),trustedOriginsWildcard:ec(C(e,"trustedOrigins"))}},sc=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),nc=(e,t)=>{if(y(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(o=>i.isSpreadAssignment(o)),r=s!==void 0&&i.isObjectLiteralExpression(s)&&!n?tc(s):sc();return{scope:E(e),file:t,line:e.getStartLineNumber(),...r}},rc=(e,t)=>jr(e,t,nc),ic=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return fn(e.getExpression(),t.matchReceiver)?s:void 0},oc=(e,t,s)=>{const n=ic(e.getExpression(),s);if(n===void 0)return;const r=e.getArguments()[s.argIndex];if(!(!r||!W(r)||ne(r))&&!(s.requireUnmodifiedReach===!0&&!Sa(r)))return{scope:E(e),file:t,line:e.getStartLineNumber(),method:n}},Ye=(e,t,s)=>O(e,t,(n,r)=>oc(n,r,s)),ac=new Set(["content","pdf","scrape","screenshot"]),cc=(e,t)=>Ye(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:ac}),lc=e=>i.isDoStatement(e)||i.isForInStatement(e)||i.isForOfStatement(e)||i.isForStatement(e)||i.isWhileStatement(e),bn=e=>{const t=e.getLabel()?.getText(),s=r=>t!==void 0?i.isLabeledStatement(r)&&r.getLabel().getText()===t:lc(r)||i.isBreakStatement(e)&&i.isSwitchStatement(r);let n=e.getFirstAncestor(r=>Z(r)||s(r));if(!(n===void 0||Z(n))){for(;i.isContinueStatement(e)&&i.isLabeledStatement(n);)n=n.getStatement();return n}},Lt=(e,t)=>A(e.getFirstAncestor(s=>A(s,t)||Z(s)),t),dc=(e,t)=>A(e,t)||e.getFirstAncestor(s=>A(s,t))!==void 0,Nn=(e,t)=>{if(i.isReturnStatement(e)||i.isThrowStatement(e))return A(e,t)||Lt(e,t);if(i.isBreakStatement(e)||i.isContinueStatement(e)){const s=bn(e);return s!==void 0&&!dc(s,t)}return!1},Pn=e=>[...i.isBreakStatement(e)||i.isContinueStatement(e)||i.isReturnStatement(e)||i.isThrowStatement(e)?[e]:[],...e.getDescendantsOfKind(d.BreakStatement),...e.getDescendantsOfKind(d.ContinueStatement),...e.getDescendantsOfKind(d.ReturnStatement),...e.getDescendantsOfKind(d.ThrowStatement)],uc=e=>Pn(e).some(t=>Nn(t,e)),wn=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getExpression();return i.isPropertyAccessExpression(n)&&n.getName()===t?s.getName():void 0},fc=e=>{if(!i.isPropertyAccessExpression(e))return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="scheduler"||i.isIdentifier(t)&&t.getText()==="scheduler"},gc=new Map([["publish",{kind:"publish",surface:"topics"}],["publishBatch",{kind:"publish",surface:"topics"}],["send",{kind:"enqueue",surface:"queues"}],["sendBatch",{kind:"enqueue",surface:"queues"}]]),pc=/^[\w$]+:[\w$]+$/u,mc=(e,t)=>{const s=rn(t);return s!==void 0?{kind:"call",target:s}:e!=="run"&&t!==void 0?{kind:"call",reason:'the function reference is not a static api.* / internal.* chain or a "namespace:export" key'}:void 0},hc=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),[n,r]=e.getArguments();if(nn.has(s))return mc(s,n);if((s==="runAfter"||s==="runAt")&&fc(t)){const c=rn(r)??(i.isStringLiteral(r)&&pc.test(r.getLiteralText())?r.getLiteralText():void 0);return c===void 0?{kind:"schedule",reason:'the scheduled function is not a static api.* / internal.* chain or a "namespace:export" key'}:{kind:"schedule",target:c}}const o=gc.get(s),a=o===void 0?void 0:wn(t,o.surface);return o===void 0||a===void 0?void 0:{kind:o.kind,target:a}},vc=new Set([d.AmpersandAmpersandEqualsToken,d.AmpersandAmpersandToken,d.BarBarEqualsToken,d.BarBarToken,d.QuestionQuestionEqualsToken,d.QuestionQuestionToken]),In=e=>Sr.isOptionalChain(e.compilerNode),Ec=(e,t)=>i.isIfStatement(t)?!A(e,t.getExpression()):i.isWhileStatement(t)||i.isForInStatement(t)||i.isForOfStatement(t)?A(e,t.getStatement()):i.isForStatement(t)?A(e,t.getStatement())||A(t.getIncrementor(),e):i.isCaseClause(t)||i.isDefaultClause(t)||i.isCatchClause(t)?!0:Z(t)?t.getFirstAncestor(Z)!==void 0:i.isConditionalExpression(t)?!A(e,t.getCondition()):i.isBinaryExpression(t)?!A(e,t.getLeft())&&vc.has(t.getOperatorToken().getKind()):(i.isCallExpression(t)||i.isElementAccessExpression(t))&&In(t)?!A(e,t.getExpression()):i.isBlock(t)&&t.getStatements().some(s=>s.getEnd()<=e.getStart()&&uc(s)),xc=e=>{let t=e,s=e.getParent();for(;s!==void 0&&(i.isAwaitExpression(s)||i.isParenthesizedExpression(s));)t=s,s=s.getParent();const n=i.isVariableDeclaration(s)||i.isBinaryExpression(s)&&A(t,s.getRight())&&s.getOperatorToken().getKind()===d.EqualsToken,r=e.getFirstAncestor(Z);return n||r?.getDescendantsOfKind(d.ThrowStatement).some(o=>o.getStart()>=e.getEnd()&&A(o.getFirstAncestor(Z),r))===!0},Sc=(e,t)=>{if(In(e)||t==="schedule"&&xc(e))return!0;let s=e;for(let n=s.getParent();n!==void 0&&!i.isSourceFile(n);n=n.getParent()){if(Ec(s,n))return!0;s=n}return!1},xs=(e,t,s)=>s===void 0?void 0:{...s,...Sc(e,s.kind)?{conditional:!0}:{},file:t,line:e.getStartLineNumber(),scope:E(e)},Ac=(e,t)=>[...O(e,t,(s,n)=>xs(s,n,hc(s))),...de(e,t,d.PropertyAccessExpression,(s,n)=>{const r=wn(s,"services");return xs(s,n,r===void 0?void 0:{kind:"invoke",target:r})})],yc=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),bc=new Set(["RateLimiter"]),Nc=new Set(["extend"]),Ss="lunora",Pc=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],Cn=e=>{const t=[],s=[];let n=!1;for(const r of e.getProperties()){if(i.isSpreadAssignment(r)){n=!0;continue}if(i.isPropertyAssignment(r)){const o=S(r);t.push(o),r.getInitializer()?.getKind()===d.TrueKeyword&&s.push(o);continue}(i.isShorthandPropertyAssignment(r)||i.isMethodDeclaration(r))&&t.push(S(r))}return{analyzable:!n,presentKeys:t,trueKeys:s}},St=e=>e&&i.isObjectLiteralExpression(e)?Cn(e):{analyzable:!1,presentKeys:[],trueKeys:[]},wc=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&sn(t.getBody());return s?Cn(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Ic=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=y(n.getExpression());r!==void 0&&(yc.has(r)?s.push({callee:r,file:t,line:n.getStartLineNumber(),...St(n.getArguments()[0])}):Nc.has(r)&&s.push({callee:r,file:t,line:n.getStartLineNumber(),...wc(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(d.NewExpression)){const r=y(n.getExpression());r===void 0||!bc.has(r)||s.push({callee:r,file:t,line:n.getStartLineNumber(),...St(n.getArguments()[0])})}return s},Cc=(e,t)=>{for(const s of Pc){const n=v(t,s);if(!R(n))continue;const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=[];for(const a of r.getDescendantsOfKind(d.CallExpression))y(a.getExpression())===Ss&&o.push({callee:Ss,file:s,line:a.getStartLineNumber(),...St(a.getArguments()[0])});return o}return[]},Tc=(e,t)=>{const s=[];for(const{displayPath:n,filePath:r}of je(t)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ic(o,n))}return s.push(...Cc(e,he(t))),s},As="ctx.containers.",Oc=e=>{if(!e.startsWith(As))return!1;const t=e.slice(As.length);return t.length>0&&!t.includes(".")},kc=(e,t)=>Ye(e,t,{argIndex:0,matchReceiver:Oc,methods:new Set(["get"])}),Rc=new Set(["allow","deny","setAllowed"]),Fc=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=M(t,"enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},Dc=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!Fc(e)))return{detail:"enableInternet: true",scope:E(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},Lc=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!Rc.has(s.getName()))return;const n=s.getExpression();if(!(!i.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),scope:E(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},Mc=(e,t)=>Dc(e,t)??Lc(e,t),_c=(e,t)=>O(e,t,Mc),Kc=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Bc=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return Kc.has(s)?s:void 0},zc=e=>{const t=[],s=[];for(const n of e.getProperties()){if(i.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(n)){const r=S(n);t.push(r);const o=n.getInitializer();o&&i.isStringLiteral(o)&&o.getLiteralText()===""&&s.push(r);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n)||i.isGetAccessorDeclaration(n))&&t.push(S(n))}return{analyzable:!0,emptyKeys:s,presentKeys:t}},$c=(e,t)=>{const s=[];for(const{displayPath:n,filePath:r}of je(t)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r);for(const a of o.getDescendantsOfKind(d.CallExpression)){const c=Bc(a);if(c===void 0)continue;const l=a.getArguments()[0],u=l&&i.isObjectLiteralExpression(l)?zc(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:u.analyzable,emptyKeys:u.emptyKeys,factory:c,file:n,line:a.getStartLineNumber(),presentKeys:u.presentKeys})}}return s},Uc=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Vc=new Set(["dbRateLimit","rateLimit"]),qc=e=>{const t=an(e);if(!t)return!1;const s=M(t,"failOpen");return s!==void 0&&i.isPropertyAssignment(s)&&s.getInitializer()?.getKind()===d.TrueKeyword},jc=(e,t)=>{const s=y(e.getExpression());if(s===void 0)return;const n=Uc.get(s);if(n!==void 0)return{callee:s,scope:E(e),failOpen:qc(e.getArguments()[n]),file:t,limitName:Vc.has(s)?on(e):"",line:e.getStartLineNumber()}},Wc=(e,t)=>O(e,t,jc),Hc=new Set(["boolean","number","object","string"]),Gc=e=>{const t=e.getName();if(!Hc.has(t))return;const s=e.getExpression();return q(s,["flags"])||q(s,["flags","details"])?t:void 0},Yc=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=Gc(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(i.isStringLiteral(n)||i.isNoSubstitutionTemplateLiteral(n)))return;const r=n.getLiteralValue();return r.length>0?{key:r,type:s}:void 0},Qc=(e,t)=>{const s=new Map;for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of r.getDescendantsOfKind(d.CallExpression)){const a=Yc(o);a&&!s.has(a.key)&&s.set(a.key,a.type)}}return[...s.entries()].map(([n,r])=>({key:n,type:r})).toSorted((n,r)=>n.key.localeCompare(r.key))},Xc=e=>{const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const s=G(t);if(s?.kind!=="query")return;const n=Wr(t,s.receiver);return n?{exportName:U(e)??e.getName(),handler:n}:void 0},ys=e=>{const t=e.getParent();return t&&i.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},Jc=e=>{const t=ys(e);if(!t)return"ctx.flags";if(t.getName()==="details"){const s=ys(t);return s?`ctx.flags.details.${s.getName()}`:"ctx.flags.details"}return`ctx.flags.${t.getName()}`},Zc=(e,t)=>{const s=[];for(const n of He(e.handler,"flags"))s.push({callee:Jc(n),exportName:e.exportName,file:t,line:n.getStartLineNumber()});return s},el=(e,t)=>{const s=[];for(const n of H(e)){const r=Xc(n);r&&s.push(...Zc(r,t))}return s},tl=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...el(r,T(t,n)))}return s},sl=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="boolean"?!1:q(e.getExpression(),["flags"]),nl=e=>{if(e?.getKind()===d.TrueKeyword)return!0;if(e?.getKind()===d.FalseKeyword)return!1},rl=(e,t)=>{if(!sl(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const r=s.getLiteralValue(),o=nl(n);if(!(r.length===0||o===void 0))return{defaultValue:o,scope:E(e),file:t,key:r,line:e.getStartLineNumber()}},il=(e,t)=>O(e,t,rl),ol=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 r=n.getTypeAtLocation(e),o=r.getText(e);if(!o||o==="any"||o==="never"||mi(o))return;const a=e.getSourceFile().getFilePath();if(hi(r,e,a)){const c=vi(r,e,a,0,new Set);return c===void 0&&Ei(o),c}return o},al=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},cl=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},ll=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=T(t,n);for(const a of r.getDescendantsOfKind(d.CallExpression))al(a)&&s.push({file:o,indexName:cl(a),line:a.getStartLineNumber()})}return s},Se=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,Tn=e=>{const t=e.getArguments()[0],s=Se(t);if(s!==void 0)return s;if(t===void 0||!i.isObjectLiteralExpression(t))return;const n=M(t,"handler");return n!==void 0&&i.isPropertyAssignment(n)?Se(n.getInitializer()):void 0},dl=new Set(["delete","get","head","options","patch","post","put"]),ul=new Set(["handler","stream"]),fl=new Set(["runAction","runMutation"]),gl=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),Ae=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,On=(e,t)=>{if(!(e===void 0||!i.isObjectBindingPattern(e))){for(const s of e.getElements())if(se(s)===t){const r=s.getNameNode();return i.isIdentifier(r)?r.getText():void 0}}},bs=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?i.isIdentifier(s)?s.getText():void 0:On(s,"ctx")},Ns=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&i.isIdentifier(s)?s.getText():void 0:On(s,"request")},Ps=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(d.CallExpression);i.isCallExpression(s)&&n.unshift(s);for(const r of n){const o=r.getExpression();if(!i.isPropertyAccessExpression(o))continue;const a=o.getName(),c=o.getExpression();if(fl.has(a)&&Ae(c,t))return a;if(gl.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&Ae(c.getExpression(),t))return`db.${a}`}},ws=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(d.PropertyAccessExpression))if(n.getName()==="auth"&&Ae(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(d.VariableDeclaration)){const r=n.getNameNode();if(!(!i.isObjectBindingPattern(r)||!Ae(n.getInitializer(),t))){for(const o of r.getElements())if(se(o)==="auth")return!0}}return!1},pl=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,ml=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="get"&&s.getName()!=="has")return!1;const n=s.getExpression();return i.isPropertyAccessExpression(n)&&n.getName()==="headers"&&Ae(n.getExpression(),t)},hl=e=>[...i.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(d.StringLiteral).map(t=>t.getLiteralText())],kn=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:hl(s)},vl=(e,t)=>{const s=e.getText();for(let n=e.getParent();n!==void 0;n=n.getParent()){if(!i.isArrowFunction(n)&&!i.isFunctionExpression(n)||!n.getParameters().some(c=>c.getName()===s))continue;const r=n.getParent();if(!i.isCallExpression(r))return[];const o=r.getExpression();if(!i.isPropertyAccessExpression(o))return[];const a=o.getExpression();return i.isIdentifier(a)?kn(t,a.getText()):[]}return[]},El=e=>{const t=e.getArguments()[0];if(t===void 0)return[];if(i.isStringLiteral(t))return[t.getLiteralText()];if(!i.isIdentifier(t))return[];const s=e.getSourceFile(),n=kn(s,t.getText());return n.length>0?n:vl(t,s)},Is=(e,t)=>{if(t===void 0)return!1;const s=e.getBody(),n=s.getDescendantsOfKind(d.CallExpression);return i.isCallExpression(s)&&n.unshift(s),n.some(r=>ml(r,t)&&El(r).some(o=>pl.test(o)))},xl=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ul.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))return;const r=n.getName();if(dl.has(r)){const o=n.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?r.toUpperCase():void 0}s=n.getExpression()}},Sl=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=Se(e.getArguments()[0]),l=c&&bs(c,!0);if(!c||l===void 0||Is(c,Ns(c,!0)))return;const u=Ps(c,l);return u===void 0?void 0:{scope:E(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ws(c,l),sideEffect:u}}const n=xl(e);if(n===void 0)return;const r=Se(e.getArguments()[0]),o=r&&bs(r,!1);if(!r||o===void 0||Is(r,Ns(r,!1)))return;const a=Ps(r,o);return a===void 0?void 0:{scope:E(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:ws(r,o),sideEffect:a}},Al=(e,t)=>O(e,t,Sl),yl=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),bl=new Set(["append","set"]),Rn=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",Cs=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(d.CallExpression)]:e.getDescendantsOfKind(d.CallExpression)).some(n=>yl.has(y(n.getExpression())??"")&&Re(n,t)),Nl=(e,t)=>{if(Cs(e,t))return!0;const s=j(e);return s!==void 0&&Cs(s,t)},At=(e,t)=>Aa(e,t)&&!Nl(e,t),Pl=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=j(e);return t!==void 0&&i.isNewExpression(t)&&y(t.getExpression())==="Headers"},Ke=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=j(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},Mt=(e,t,s)=>{for(const n of e.getProperties())if(i.isPropertyAssignment(n)){const r=n.getInitializer();r!==void 0&&At(r,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:Rn(n.getNameNode()),line:r.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(n)){const r=n.getNameNode();At(r,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:S(n),line:r.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(n)){const r=Ke(n.getExpression());r!==void 0&&Mt(r,t,s)}},Fn=(e,t)=>{const s=Ke(e);if(s===void 0)return;const n=M(s,"headers");if(n===void 0||!i.isPropertyAssignment(n))return;const r=Ke(n.getInitializer());r!==void 0&&Mt(r,"response-init",t)},wl=(e,t)=>{const s=y(e.getExpression());if(s==="Response")Fn(e.getArguments()[1],t);else if(s==="Headers"){const n=Ke(e.getArguments()[0]);n!==void 0&&Mt(n,"headers-ctor",t)}},Il=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName(),r=s.getExpression();if(n==="json"&&i.isIdentifier(r)&&r.getText()==="Response"){Fn(e.getArguments()[1],t);return}if(bl.has(n)&&Pl(r)){const o=e.getArguments()[1];o!==void 0&&At(o,t.requestName)&&t.rows.push({scope:t.scope,file:t.relativePath,headerName:Rn(e.getArguments()[0]),line:o.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},Cl=(e,t)=>{for(const s of e.getDescendantsOfKind(d.NewExpression))wl(s,t);for(const s of e.getDescendantsOfKind(d.CallExpression))Il(s,t)},Tl=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=Se(e.getArguments()[0]);if(n===void 0)return[];const r=n.getParameters()[1];if(r===void 0)return[];const o=r.getNameNode();if(!i.isIdentifier(o))return[];const a=[];return Cl(n,{scope:E(e),relativePath:t,requestName:o.getText(),rows:a}),a},Ol=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression))s.push(...Tl(n,t));return s},kl=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ol(r,T(t,n)))}return s},Rl=new Set(["auth","context.auth"]),Fl="userId",Dl=e=>{const t=new Set;for(const s of e.getProperties()){if(i.isSpreadAssignment(s))return;(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s))&&t.add(S(s))}return t},Ll=(e,t)=>{const s=v(t,En);if(!R(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const r of n.getDescendantsOfKind(d.CallExpression)){if(y(r.getExpression())!=="defineIdentity")continue;const[o]=r.getArguments();return o&&i.isObjectLiteralExpression(o)?Dl(o):void 0}},Ts=e=>{if(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity")return;const t=e.getExpression();return Rl.has(t.getText())||q(t,["auth"])?e:void 0},Ml=e=>{if(i.isPropertyAccessExpression(e)&&Ts(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&Ts(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},Os=(e,t,s)=>{const n=Ml(e);return n===void 0?void 0:{declared:n===Fl||s.has(n),file:t,key:n,line:e.getStartLineNumber(),scope:E(e)}},_l=(e,t)=>{const s=Ll(e,t);return s===void 0?[]:[...de(e,t,d.PropertyAccessExpression,(n,r)=>Os(n,r,s)),...de(e,t,d.ElementAccessExpression,(n,r)=>Os(n,r,s))]},Kl=(e,t)=>{if(y(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=C(s,"key");if(!(!n||!W(n)||ne(n)))return{scope:E(e),file:t,line:e.getStartLineNumber()}},Bl=(e,t)=>O(e,t,Kl),zl=e=>e.getProperties().some(t=>{if(i.isSpreadAssignment(t))return!0;const s=Nr(t.getNameNode());return s===void 0||s==="namespace"}),$l=(e,t)=>{for(const{filePath:s}of je(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const r of n.getDescendantsOfKind(d.CallExpression)){const o=r.getExpression(),[a]=r.getArguments();if(!(!i.isPropertyAccessExpression(o)||o.getName()!=="auth"||a===void 0)&&(!i.isObjectLiteralExpression(a)||zl(a)))return r}}},Ul="https://lunora.sh/docs/concepts/data-residency#pinning-auth-and-voice",Vl=(e,t)=>{if(!(e.jurisdiction===void 0||e.jurisdictionPinsAuth===!0||t===void 0))throw ye(t,`the schema pins Durable Objects to the "${e.jurisdiction}" jurisdiction, and this project also has DO-backed auth (users, sessions, accounts, credentials). Pinning the auth object resolves it to a NEW, EMPTY object: existing users stay in the unpinned one until you copy them across (${Ul}). Acknowledge with \`.jurisdiction("${e.jurisdiction}", { pinAuth: true })\`, deploy, then run the copy. For D1-mode auth the acknowledgement changes nothing.`,{code:"JURISDICTION_MOVE",status:422})},ql=new Set(["delete","get","getRaw","getWithMetadata","put"]),jl=(e,t,s=[])=>{const n=Ye(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.kv"||r.startsWith("ctx.kv."),methods:ql});return Tt(n,s)},Wl=new Set(["queue","send"]),ks=new Set(["bcc","cc","to"]),Hl=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Wl.has(t))return;const s=e.getExpression();return q(s,["mail"])||q(s,["email"])?t:void 0},Gl=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return ks.has(S(t))&&W(n)&&!ne(n)}if(!i.isPropertyAssignment(t)||!ks.has(S(t)))return!1;const s=t.getInitializer();return s!==void 0&&W(s)&&!ne(s)}):!1,Yl=(e,t)=>{const s=Hl(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!Gl(n)))return{scope:E(e),file:t,line:e.getStartLineNumber(),method:s}},Ql=(e,t)=>O(e,t,Yl),Xl=e=>i.isPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?i.isComputedPropertyName(e.getNameNode()):!1,Jl=e=>i.isPropertyAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?Xl(e):!0,Dn=(e,t=!1)=>{for(const s of e.getProperties()){if(Jl(s))return!0;if(t)continue;if(!i.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!i.isObjectLiteralExpression(n)||Dn(n,!0))return!0}return!1},Zl=(e,t)=>{for(const s of x(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:r}of hn(n))for(const o of Rt(r)){const a=o.getArguments()[0];if(a!==void 0&&(!i.isObjectLiteralExpression(a)||Dn(a)))return!0}}return!1},ed=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const r=_e(n);if(r===void 0||!i.isPropertyAssignment(n))continue;const o=n.getInitializer();if(!(!o||!i.isObjectLiteralExpression(o)))for(const a of o.getProperties()){const c=_e(a);c!==void 0&&s.push({column:c,strategy:mn(a),table:r})}}return s},td=(e,t)=>{const s=new Map;for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:o}of hn(r))for(const a of Rt(o))for(const c of ed(a)){const l=`${c.table}\0${c.column}`;s.has(l)||s.set(l,c)}}return{columns:[...s.values()]}},sd=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!i.isObjectLiteralExpression(n))return[];const r=[];for(const o of n.getProperties()){const a=_e(o);if(a===void 0||!i.isPropertyAssignment(o))continue;const c=o.getInitializer();if(!(!c||!i.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const u=_e(l);if(u===void 0)continue;const g=mn(l);g!=="custom"&&r.push({column:u,exportName:t,file:s,line:l.getStartLineNumber(),strategy:g,table:a})}}return r},nd=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?G(s):void 0;return n?.receiver?Rt(n.receiver).flatMap(r=>sd(r,U(e)??e.getName(),t)):[]},rd=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=T(t,n);for(const a of H(r))s.push(...nd(a,o))}return s},id=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return $(s)},od=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=M(t,"server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},ad=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==d.CallExpression)return;const s=t;return Ci(s.getExpression())?s:void 0},cd=e=>{const t=ad(e),s=t===void 0?void 0:od(t);if(s===void 0)return[];const n=e.getNameNode(),r=i.isIdentifier(n)?U(e)??n.getText():"";return s.getDescendantsOfKind(d.CallExpression).filter(o=>id(o)).map(o=>({exportName:r,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},ld=e=>e.getVariableDeclarations().flatMap(t=>cd(t)),dd=(e,t)=>{const s=v(t,Ii);if(!R(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return ld(n)},ud=new Set(["delete","get","patch"]),fd=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),gd=new Set(["auth","identity","session","user"]),pd=new Set([d.EqualsEqualsEqualsToken,d.EqualsEqualsToken,d.ExclamationEqualsEqualsToken,d.ExclamationEqualsToken]),md=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!$(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},hd=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(i.isAsExpression(s)||i.isParenthesizedExpression(s)||i.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!i.isVariableDeclaration(s))return;const n=s.getNameNode();return i.isIdentifier(n)?n.getText():void 0},vd=(e,t)=>e.getDescendantsOfKind(d.Identifier).some(s=>s.getText()===t),Ed=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(d.ThrowStatement).length>0||e.getDescendantsOfKind(d.ReturnStatement).length>0,xd=(e,t)=>e.getDescendantsOfKind(d.IfStatement).some(s=>vd(s.getExpression(),t)&&Ed(s.getThenStatement())),Sd=(e,t)=>{for(const s of e.getDescendantsOfKind(d.CallExpression)){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))continue;const r=n.getName();if(!ud.has(r))continue;const o=n.getExpression();if(!($(o)||i.isPropertyAccessExpression(o)&&$(o.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&i.isIdentifier(c)&&c.getText()===t)return r}},Ad=e=>e.getDescendantsOfKind(d.CallExpression).some(t=>t.getArguments().some(s=>kt(Ot(s))!==void 0)),yd=e=>e.getDescendantsOfKind(d.BinaryExpression).some(t=>pd.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),bd=e=>{for(const t of e.getDescendantsOfKind(d.Identifier))if(fd.has(t.getText()))return!0;return[...gd].some(t=>He(e,t).length>0)?!0:Ad(e)||yd(e)},Nd=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=G(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const r=Tn(s);if(r===void 0)return[];const o=n.receiver!==void 0&&ln(n.receiver,"use","rls"),a=bd(r),c=new Set,l=[];for(const u of r.getDescendantsOfKind(d.CallExpression)){const g=md(u);if(g===void 0)continue;const f=hd(u);if(f===void 0||c.has(f)||!xd(r,f))continue;const m=Sd(r,f);m!==void 0&&(c.add(f),l.push({exportName:U(e)??e.getName(),file:t,line:u.getStartLineNumber(),mentionsOwnership:a,sinkMethod:m,table:g,usesRls:o,visibility:n.visibility}))}return l},Pd=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=T(t,n);for(const a of H(r))s.push(...Nd(a,o))}return s},Ln=(e,t)=>{const s=i.isIdentifier(e)&&t!==void 0?F(e):void 0;return s===void 0||t===void 0?!1:s.compilerNode===t.compilerNode?i.isIdentifier(t.getNameNode()):i.isBindingElement(s)&&s.getFirstAncestorByKind(d.Parameter)?.compilerNode===t.compilerNode},wd=e=>{const t=I(e),s=t.getParent();return(i.isPropertyAccessExpression(s)||i.isElementAccessExpression(s))&&s.getExpression()===t&&!We(s)},Id=e=>{const t=I(e).getParent();return i.isVariableDeclaration(t)&&i.isObjectBindingPattern(t.getNameNode())},Cd=e=>{const s=I(e).getParent();if(i.isSpreadAssignment(s)||i.isSpreadElement(s)){const n=s.getParent();return(i.isObjectLiteralExpression(n)||i.isArrayLiteralExpression(n))&&!We(n)}return i.isTemplateSpan(s)&&!i.isTaggedTemplateExpression(s.getParent().getParent())},Be=e=>{const t=F(e);return t===void 0||Br(t.getSourceFile())},yt=(e,t)=>{const s=I(e),n=s.getParent();if(!i.isCallExpression(n))return!1;const r=n.getArguments().indexOf(s),o=h(n.getExpression());if(r===-1||o===void 0)return!1;if(i.isIdentifier(o))return o.getText()==="structuredClone"&&Be(o);if(Ln(Ot(o),t))return!(i.isPropertyAccessExpression(o)&&gn.has(o.getName()))||i.isExpressionStatement(I(i.isAwaitExpression(n.getParent())?n.getParentOrThrow():n).getParent());if(!i.isPropertyAccessExpression(o))return!1;const a=o.getExpression();if(!i.isIdentifier(a)||!Be(a))return!1;const c=a.getText(),l=o.getName();switch(c){case"console":return!0;case"JSON":return l==="stringify";case"Object":return["entries","freeze","isFrozen","keys","values"].includes(l)||l==="assign"&&r>0;default:return!1}},Fe={kind:"opaque"},Td={kind:"unreached"},Od=e=>{const t=e.getSymbol()?.getDeclarations()??[],s=t.filter(o=>i.isFunctionDeclaration(o)&&o.hasBody()),[n]=s;return t.every(o=>i.isFunctionDeclaration(o)&&o.getSourceFile()===e.getSourceFile())&&s.length===1&&i.isFunctionDeclaration(n)?n:void 0},bt=e=>{const t=h(e);if(i.isArrowFunction(t)||i.isFunctionExpression(t))return t;const s=i.isIdentifier(t)?F(t):void 0;if(s?.getSourceFile()!==e.getSourceFile())return;if(i.isFunctionDeclaration(s)){const r=Od(s);return r===void 0||Ct(r)?void 0:r}const n=ee(s)?h(s.getInitializer()):void 0;return i.isArrowFunction(n)||i.isFunctionExpression(n)?n:void 0},Mn=(e,t,s)=>{const n=t.getArguments(),r=n.indexOf(s),o=r===-1||n.slice(0,r+1).some(l=>i.isSpreadElement(l))||e.getDescendantsOfKind(d.Identifier).some(l=>l.getText()==="arguments"),a=e.getParameters(),c=a[r];return o?Fe:c===void 0?a.some(l=>l.isRestParameter())?Fe:Td:c.isRestParameter()?Fe:{kind:"parameter",parameter:c}},kd=e=>{const t=I(e),s=t.getParent();if(!i.isCallExpression(s)||s.getExpression()===t)return;const n=bt(s.getExpression());return n===void 0?Fe:Mn(n,s,t)},Rd=new Set(["__defineGetter__","__defineSetter__","__proto__"]),Fd=e=>i.isForInStatement(e)?e.getExpression():i.isConditionalExpression(e)?e.getCondition():i.isElementAccessExpression(e)?e.getArgumentExpression():void 0,_n=e=>{const t=I(e),s=t.getParent();if(i.isIfStatement(s)||i.isWhileStatement(s)||i.isDoStatement(s)||i.isSwitchStatement(s)||i.isCaseClause(s)||i.isTypeOfExpression(s)||i.isVoidExpression(s)||i.isComputedPropertyName(s))return!0;if(i.isTemplateSpan(s))return!i.isTaggedTemplateExpression(s.getParent().getParent());const n=Fd(s);if(n!==void 0)return A(n,t);if(i.isPrefixUnaryExpression(s))return s.getOperatorToken()!==d.PlusPlusToken&&s.getOperatorToken()!==d.MinusMinusToken;if(!i.isBinaryExpression(s))return!1;const r=s.getOperatorToken().getKind(),o=r>=d.FirstAssignment&&r<=d.LastAssignment,a=r===d.QuestionQuestionToken||r===d.BarBarToken||r===d.AmpersandAmpersandToken;return!o&&!a},Dd=4,Kn=(e,t,s=0)=>{if(Kr(e))return!0;if(wd(e)){const r=I(e).getParent(),o=i.isElementAccessExpression(r)?r.getArgumentExpression():void 0,a=i.isStringLiteral(o)?o.getLiteralValue():void 0,c=i.isPropertyAccessExpression(r)?r.getName():a;return c===void 0||!Rd.has(c)}if(Id(e)||Cd(e)||_n(e)||yt(e,t))return!0;const n=kd(e);return n?.kind==="unreached"||n?.kind==="parameter"&&Ld(n.parameter,s+1)},Rs=new WeakMap,Ld=(e,t=0)=>{const s=e.getNameNode();if(!i.isIdentifier(s))return!0;const n=Rs.get(e.compilerNode);if(n!==void 0)return n;if(t>Dd)return!1;const o=(s.getSymbol()?.getDeclarations().length??0)===1&&e.getParentOrThrow().getDescendantsOfKind(d.Identifier).every(a=>a===s||a.getText()!==s.getText()||F(a)?.compilerNode!==e.compilerNode||Kn(a,void 0,t));return(o||t===0)&&Rs.set(e.compilerNode,o),o},Fs=new WeakMap,Md=(e,t)=>{const s=i.isFunctionExpression(e)?e.getNameNode():void 0;if(!i.isArrowFunction(e)&&e.getFirstDescendantByKind(d.ThisKeyword)!==void 0)return!0;const n=new Set([t.getName(),...s===void 0?[]:[s.getText()]]);return e.getDescendantsOfKind(d.Identifier).some(r=>{if(r===s||!n.has(r.getText()))return!1;const o=F(r)?.compilerNode;return o!==void 0&&(o===t.compilerNode||s!==void 0&&o===e.compilerNode)})},_d=(e,t,s)=>{const{context:n,impl:r}=e,o=Fs.get(r.compilerNode);if(o!==void 0)return o;const a=t.getNameNode(),c=i.isIdentifier(a)?[a]:a.getDescendantsOfKind(d.BindingElement).flatMap(f=>{const m=f.getNameNode();return i.isIdentifier(m)?[m]:[]}),l=new Map(c.map(f=>[f.getText(),f.getParentOrThrow().compilerNode])),u=f=>i.isIdentifier(a)?Kn(f,n):!We(f),g=!Md(r,s)&&c.every(f=>(f.getSymbol()?.getDeclarations().length??0)===1)&&r.getDescendantsOfKind(d.Identifier).every(f=>{const m=f.getText();if(m==="arguments")return!1;const b=l.get(m);return b===void 0||c.includes(f)||F(f)?.compilerNode!==b?!0:u(f)});return Fs.set(r.compilerNode,g),g},Ds=new WeakMap,Kd=e=>{let t=Ds.get(e.compilerNode);return t===void 0&&(t=new Map(e.getVariableDeclarations().flatMap(s=>{const n=Ti(s);return n===void 0?[]:[[n.compilerNode,s]]})),Ds.set(e.compilerNode,t)),t},Bd=e=>{const t=Kd(e.getSourceFile()),s=e.getAncestors().find(l=>t.has(l.compilerNode)),n=s===void 0?void 0:t.get(s.compilerNode);if(s===void 0||n===void 0)return;const[r,o]=s.getParameters(),a=o===void 0||o.isRestParameter()?void 0:o,c={context:r,impl:s,mutatorName:U(n)??n.getName()};return a!==void 0&&_d(c,a,n)?{...c,parameter:a,pristine:!0}:{...c,parameter:a,pristine:!1}},lt="args",ve=e=>{const t=cn(e);if(t!==void 0){const c=h(t.object);return i.isIdentifier(c)&&c.getText()===lt?t.member:void 0}if(!i.isIdentifier(e))return;const s=F(e);if(!i.isBindingElement(s)||s.getDotDotDotToken()!==void 0)return;const n=s.getParent();if(!i.isObjectBindingPattern(n))return;const r=n.getParent(),o=ee(r)?h(r.getInitializer()):void 0;return i.isBindingElement(r)&&se(r)===lt||i.isIdentifier(o)&&o.getText()===lt?se(s):void 0},zd=new Set(["auth","identity","user"]),Nt=e=>{const t=r=>{const o=kt(r);return o!==void 0&&o.length>0&&zd.has(o[0]??"")},s=h(e)??e;if(t(s))return!0;const n=j(s);return n!==void 0&&t(n)},Bn=(e,t=2)=>{const s=new Set;for(const n of[e,...e.getDescendants()]){const r=ve(n);r!==void 0&&s.add(r);const o=t>0&&i.isIdentifier(n)?j(n):void 0;if(o!==void 0)for(const a of Bn(o,t-1))s.add(a)}return s},De=e=>{const t=h(e)??e;if(!i.isBinaryExpression(t))return[];const s=t.getOperatorToken().getKind(),n=t.getLeft(),r=t.getRight();if(s===d.BarBarToken)return[...De(n),...De(r)];if(s===d.AmpersandAmpersandToken){const l=(u,g)=>{const f=ve(h(u)??u);return f===void 0?[]:De(g).filter(m=>m===f)};return[...l(n,r),...l(r,n)]}if(s!==d.ExclamationEqualsEqualsToken&&s!==d.ExclamationEqualsToken)return[];const o=[],a=ve(h(n)??n),c=ve(h(r)??r);return a!==void 0&&Nt(r)&&o.push(a),c!==void 0&&Nt(n)&&o.push(c),o},$d=e=>{const t=h(e.getExpression())??e.getExpression();return i.isIdentifier(t)?t.getText():i.isPropertyAccessExpression(t)?t.getName():void 0},Ud=e=>{if(!$d(e)?.startsWith("assert"))return[];const t=e.getArguments();return t.flatMap((s,n)=>{const r=ve(h(s)??s),o=t.some((a,c)=>c!==n&&Nt(a));return r!==void 0&&o?[r]:[]})},Vd=e=>{if(i.isThrowStatement(e))return!0;if(!i.isBlock(e))return!1;const t=e.getStatements().at(-1);return t!==void 0&&i.isThrowStatement(t)},qd=e=>i.isArrowFunction(e)||i.isFunctionExpression(e)||i.isFunctionDeclaration(e)||i.isMethodDeclaration(e),Ls=(e,t)=>{for(let s=e.getParent();s!==void 0;s=s.getParent()){if(s===t||s.compilerNode===t.compilerNode)return!0;if(!(i.isBlock(s)||i.isExpressionStatement(s)||i.isAwaitExpression(s)||i.isParenthesizedExpression(s)||i.isVariableStatement(s)||i.isVariableDeclarationList(s)||i.isVariableDeclaration(s)))return!1}return!1},jd=(e,t)=>{const s=new Set;for(const n of e.getDescendantsOfKind(d.IfStatement))if(n.getEnd()<=t&&Ls(n,e)&&Vd(n.getThenStatement()))for(const r of De(n.getExpression()))s.add(r);for(const n of e.getDescendantsOfKind(d.CallExpression))if(n.getEnd()<=t&&Ls(n,e))for(const r of Ud(n))s.add(r);return s},Wd=(e,t)=>{const s=Bn(t);if(s.size===0)return!1;const n=e.getFirstAncestor(qd);if(n===void 0)return!1;const r=jd(n,e.getStart());return[...s].every(o=>r.has(o))},Hd=new Set(["at","concat","filter","find","findLast","flat","reverse","slice","sort","toReversed","toSorted"]),Gd=new Map([["Array",new Set(["from","of"])],["Object",new Set(["entries","values"])]]),Pt=new Set(["catch","every","filter","finally","find","findIndex","findLast","findLastIndex","flatMap","forEach","map","reduce","reduceRight","some","sort","then"]),zn=e=>e.getNameNode().getDescendantsOfKind(d.BindingElement).filter(t=>i.isIdentifier(t.getNameNode())),Yd=e=>{const t=I(e),s=t.getParent();if(i.isVariableDeclaration(s))return A(s.getInitializer(),t)?s:void 0;const n=i.isForOfStatement(s)&&s.getExpression()===t?s.getInitializer():void 0;return i.isVariableDeclarationList(n)?n.getDeclarations()[0]:void 0},Qd=e=>{const t=Yd(e);return t===void 0?void 0:i.isIdentifier(t.getNameNode())?i.isForOfStatement(t.getParent().getParent())||ee(t)?[t]:void 0:zn(t)},Ee=e=>e.isUnion()?e.getUnionTypes().every(t=>Ee(t)):e.isIntersection()?e.getIntersectionTypes().some(t=>Ee(t)):!e.isAny()&&!e.isUnknown()&&!e.isObject()&&!e.isTypeParameter(),ze=(e,t,s)=>{const n=i.isCallExpression(e)?h(e.getExpression()):void 0;return i.isPropertyAccessExpression(n)&&t.has(n.getName())&&(s===void 0||n.getExpression()===s)},Le=e=>{const t=h(e);if(!i.isArrowFunction(t)&&!i.isFunctionExpression(t))return;const s=t.getBody();return i.isBlock(s)?s.getDescendantsOfKind(d.ReturnStatement).filter(n=>n.getFirstAncestor(r=>i.isFunctionLikeDeclaration(r))===t).map(n=>n.getExpression()):[s]},Xd=e=>{const t=i.isCallExpression(e)?h(e.getExpression()):void 0,s=i.isPropertyAccessExpression(t)?t.getExpression():void 0;return i.isPropertyAccessExpression(t)&&i.isIdentifier(s)&&Gd.get(s.getText())?.has(t.getName())===!0&&Be(s)},Jd=e=>{const t=vt(e);if(!i.isArrowFunction(t)&&!i.isFunctionExpression(t))return;const s=I(t),n=s.getParent();return i.isCallExpression(n)&&n.getArguments().includes(s)&&ze(n,pn)?n:void 0},Zd=(e,t)=>{if(!(i.isPropertyAccessExpression(e)||i.isElementAccessExpression(e))||e.getExpression()!==t)return;const s=I(e),n=s.getParent();return!i.isCallExpression(n)||n.getExpression()!==s?e:ze(n,Hd,t)?n:void 0},eu=(e,t)=>{if(i.isAwaitExpression(e))return e;if(i.isConditionalExpression(e))return e.getCondition()===t?void 0:e;const s=i.isBinaryExpression(e)?e.getOperatorToken().getKind():void 0;return s===d.QuestionQuestionToken||s===d.BarBarToken||s===d.AmpersandAmpersandToken?e:void 0},tu=(e,t)=>{if(i.isArrayLiteralExpression(e))return e;const n=i.isSpreadElement(e)||i.isSpreadAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isPropertyAssignment(e)&&A(e.getInitializer(),t)?e.getParent():void 0;return i.isArrayLiteralExpression(n)||i.isObjectLiteralExpression(n)?n:void 0},Ms=e=>{const t=I(e),s=t.getParent();if(s===void 0)return;const n=i.isCallExpression(s)&&s.getArguments().includes(t)&&Xd(s);return Zd(s,t)??eu(s,t)??tu(s,t)??(n?s:Jd(t))},su=5e4,$n=()=>({inProgress:new Set,verdicts:new Map});class nu{cuts=0;work=0;reset(){this.work=0}cut(){return this.cuts+=1,!0}spend(){return this.work+=1,this.work>su&&this.cut()}memoized(t,s,n){const r=n.verdicts.get(t);if(r!==void 0)return r;if(n.inProgress.has(t))return this.cuts+=1,!1;if(this.spend())return!0;const o=this.cuts;n.inProgress.add(t);let a;try{a=s()}finally{n.inProgress.delete(t)}return this.cuts===o&&n.verdicts.set(t,a),a}}const ru=8,iu=8;class ou{budget;scope;taint;verdicts=$n();constructor(t,s,n){this.scope=t,this.budget=s,this.taint=n}isCompromised(t){return this.flowHasCompromisingUse(t)&&!Ee(t.getType())}flowHasCompromisingUse(t){return this.budget.memoized(t.compilerNode,()=>{const s=this.budget.cuts,n=[],r=new Set,o=(c,l)=>{r.has(c.compilerNode)||(r.add(c.compilerNode),n.push({binding:c,hops:l}))};let a=!1;o(t,0);for(const c of n)if(a=(c.binding===t?void 0:this.verdicts.verdicts.get(c.binding.compilerNode))??this.visitBinding(c,t,o),a)break;if(!a&&this.budget.cuts===s)for(const c of r)this.verdicts.verdicts.set(c,!1);return a},this.verdicts)}visitBinding({binding:t,hops:s},n,r){const o=t.getNameNode();if(!i.isIdentifier(o)){for(const l of i.isParameterDeclaration(t)?zn(t):[])r(l,s);return!1}if(this.budget.spend())return!0;const a=(l,u)=>u&&s>=ru?this.budget.cut():(r(l,u?s+1:s),!1);return this.taint.referencesTo(t,o.getText()).some(l=>this.valueCompromises(I(l),!0,a,0))&&(t===n||!Ee(t.getType()))}valueCompromises(t,s,n,r){let o=t;for(let m=Ms(o);m!==void 0;m=Ms(o)){if(i.isCallExpression(m)&&this.callbackCompromises(m,n))return!0;o=I(m)}const a=o.getParent(),c=o===t&&s,l=()=>!c&&Ee(o.getType());if(We(o))return!c&&(!i.isBinaryExpression(a)||this.taint.isTaintedValue(a.getRight(),!1));const u=Qd(o);if(u!==void 0)return u.some(m=>n(m,!0));const g=i.isPropertyAccessExpression(a)&&a.getExpression()===o?a.getParent():void 0;if(i.isCallExpression(g)&&g.getExpression()===a)return this.methodCallCompromises(g,n);const f=this.nestedReturningFunctionOf(o);return f!==void 0?this.resultCompromises(f,n,r)&&!l():this.positionCompromises(o,n)&&!l()}resultCompromises(t,s,n){const r=I(t).getParent();if(n>=iu)return this.budget.cut();if(i.isCallExpression(r))return r.getExpression()===I(t)?this.valueCompromises(r,!1,s,n+1):!ze(r,Pt);const o=i.isFunctionDeclaration(t)?t:r,a=i.isFunctionDeclaration(o)||ee(o)?o.getNameNode():void 0;return o===void 0||!i.isIdentifier(a)?!0:this.taint.referencesTo(o,a.getText()).some(c=>{const l=I(c),u=l.getParent();return!i.isCallExpression(u)||u.getExpression()!==l||this.valueCompromises(u,!1,s,n+1)})}methodCallCompromises(t,s){return t.getArguments().filter(r=>Le(r)===void 0).some(r=>this.taint.isTaintedValue(r,!1))||this.callbackCompromises(t,s)}callbackCompromises(t,s){const n=ze(t,Pt)?t.getArguments()[0]:void 0;if(n===void 0)return!1;const r=bt(n);return r!==void 0&&this.taint.isInImpl(r)?r.getParameters().some(o=>s(o,!1)):this.taint.isTaintedValue(n,!1)}positionCompromises(t,s){const n=t.getParent();if(i.isCallExpression(n)&&n.getArguments().includes(t))return this.argumentCompromises(n,t,s);const r=i.isSpreadElement(n)?n.getParent():void 0;if(n!==void 0&&i.isCallExpression(r))return!yt(n,this.scope.context)&&this.isOpaqueCallTainted(r.getExpression(),r.getArguments(),n);if(i.isNewExpression(n))return this.isOpaqueCallTainted(n.getExpression(),n.getArguments(),t);if(i.isTemplateSpan(n)){const o=n.getParent(),a=o.getParent(),c=o.getTemplateSpans().map(l=>l.getExpression());return i.isTaggedTemplateExpression(a)&&this.isOpaqueCallTainted(a.getTag(),c,t)}return!this.isReadPosition(t)}argumentCompromises(t,s,n){if(yt(s,this.scope.context))return!1;const r=bt(t.getExpression()),o=r===void 0?void 0:Mn(r,t,s);return o?.kind==="unreached"?!1:o?.kind==="parameter"&&r!==void 0&&this.taint.isInImpl(r)?n(o.parameter,!1):this.isOpaqueCallTainted(t.getExpression(),t.getArguments(),s)}isReadPosition(t){const s=t.getParent();return s===void 0||i.isExpressionStatement(s)||i.isForStatement(s)||i.isElementAccessExpression(s)||_n(t)||A(vt(t),this.scope.impl)}isOpaqueCallTainted(t,s,n){const r=!i.isIdentifier(h(n));return this.taint.isTaintedValue(t,!1)||s.some(o=>(o!==n||r)&&this.taint.isTaintedValue(o,!1))}nestedReturningFunctionOf(t){const s=vt(t);return A(s,this.scope.impl)?void 0:s}}const au=new Set(["at","every","filter","finally","find","findIndex","findLast","findLastIndex","forEach","order","slice","some","sort","withIndex","withSearchIndex"]),cu=e=>{const t=h(e);if(!i.isIdentifier(t))return i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t);const s=F(t),n=i.isVariableDeclaration(s)?h(s.getInitializer()):void 0;return s===void 0||i.isFunctionDeclaration(s)||i.isParameterDeclaration(s)||i.isArrowFunction(n)||i.isFunctionExpression(n)},lu=new Set(["all","allSettled","any","race"]),_s=e=>i.isParameterDeclaration(e)?e:i.isBindingElement(e)?e.getFirstAncestorByKind(d.Parameter):void 0,dt=8;class du{budget=new nu;referencesByDeclaration=new Map;referencesByName=new Map;scope;verdicts=$n();walk;variableDepth=0;queryDepth=0;constructor(t){this.scope=t,this.walk=new ou(t,this.budget,this);for(const s of t.impl.getDescendantsOfKind(d.Identifier)){const n=s.getText();this.referencesByName.set(n,[...this.referencesByName.get(n)??[],s])}}isTaintedValue(t,s){this.queryDepth===0&&this.budget.reset(),this.queryDepth+=1;try{return s&&this.isRootedInContext(t,dt)?!1:(i.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(r=>zr(r)&&this.isIdentifierTainted(r))}finally{this.queryDepth-=1}}isInImpl(t){const{impl:s}=this.scope;return t!==s&&s.getPos()<=t.getPos()&&t.getEnd()<=s.getEnd()}referencesTo(t,s){let n=this.referencesByDeclaration.get(s);if(n===void 0){n=new Map;for(const r of this.referencesByName.get(s)??[]){const o=F(r)?.compilerNode;o!==void 0&&n.set(o,[...n.get(o)??[],r])}this.referencesByDeclaration.set(s,n)}return(n.get(t.compilerNode)??[]).filter(r=>r.getParent()!==t)}flowsIntoTainted(t){if([t.getInitializer(),...t.getDescendantsOfKind(d.BindingElement).map(f=>f.getInitializer())].some(f=>f!==void 0&&this.isTaintedValue(f,!1)))return!0;const n=t.getParentOrThrow(),r=i.isFunctionLikeDeclaration(n)?n.getParameters().findIndex(f=>f.compilerNode===t.compilerNode):-1,o=I(n),a=o.getParent();if(r===-1)return!0;if(i.isCallExpression(a)){if(a.getExpression()===o)return this.isCallSiteTainted(a,r,t.isRestParameter());const f=h(a.getExpression());if(!i.isPropertyAccessExpression(f)||!Pt.has(f.getName()))return!0;const m=a.getArguments().filter(b=>b!==o);return this.isTaintedValue(f.getExpression(),!0)||m.some(b=>this.isTaintedValue(b,!1))}const c=i.isVariableDeclaration(a)&&ee(a)?a:void 0,l=i.isFunctionDeclaration(n)?n:c,u=l?.getNameNode();if(l===void 0||!i.isIdentifier(u))return!0;const g=this.referencesTo(l,u.getText());return g.length===0||g.some(f=>{const m=I(f),b=m.getParent();return!i.isCallExpression(b)||b.getExpression()!==m||this.isCallSiteTainted(b,r,t.isRestParameter())})}isCallSiteTainted(t,s,n){const r=t.getArguments(),o=r.findIndex(c=>i.isSpreadElement(c)),a=c=>c===s||n&&c>s||o!==-1&&o<=s&&c>=o;return r.some((c,l)=>a(l)&&this.isTaintedValue(c,!1))}isContextRootedCombinator(t,s){const n=h(t.getExpression()),r=i.isPropertyAccessExpression(n)?n.getExpression():void 0,a=i.isPropertyAccessExpression(n)&&i.isIdentifier(r)&&r.getText()==="Promise"&&Be(r)&&lu.has(n.getName())?h(t.getArguments()[0]):void 0;if(i.isArrayLiteralExpression(a)){const g=a.getElements();return g.length>0&&g.every(f=>!i.isSpreadElement(f)&&this.isRootedInContext(f,s))}const c=i.isCallExpression(a)?h(a.getExpression()):void 0,l=i.isCallExpression(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="map"?h(a.getArguments()[0]):void 0,u=l===void 0?void 0:Le(l);return u!==void 0&&u.length>0&&u.every(g=>g!==void 0&&this.isRootedInContext(g,s))}isIdentifierTainted(t){const s=t.getText();if(s==="arguments")return!0;const n=F(t),r=_s(n);if(r!==void 0)return this.isSource(r);if(s==="args")return!0;if(n===void 0||!this.isInImpl(n))return!1;if(i.isFunctionDeclaration(n))return this.budget.memoized(n.compilerNode,()=>this.isTaintedValue(n,!1),this.verdicts);if(i.isBindingElement(n)&&this.walk.isCompromised(n))return!0;const o=i.isBindingElement(n)?n.getFirstAncestorByKind(d.VariableDeclaration):n;return i.isVariableDeclaration(o)&&this.isVariableTainted(o)}callChainVerdict(t,s){if(this.isContextRootedCombinator(t,s))return!0;const n=h(t.getExpression()),r=i.isPropertyAccessExpression(n)?n.getName():void 0;return r!==void 0&&gn.has(r)?!1:r!==void 0&&pn.has(r)?this.isCallbackResultServerScoped(t,s)?void 0:!1:t.getArguments().some(a=>Le(a)!==void 0)&&(r===void 0||!au.has(r))?!1:void 0}isCallbackResultServerScoped(t,s){const n=(r,o=[])=>{const a=Ot(r),c=i.isIdentifier(a)?_s(F(a)):void 0;return c!==void 0&&o.includes(c)?!0:this.isRootedInContext(r,s)||!this.isTaintedValue(r,!1)};return t.getArguments().every(r=>{const o=Le(r);if(o===void 0)return!cu(r)&&n(r);const a=h(r),c=i.isArrowFunction(a)||i.isFunctionExpression(a)?a.getParameters():[];return o.every(l=>l===void 0||n(l,c))})}isRootedInContext(t,s){const n=Hr(t,u=>this.callChainVerdict(u,s)),r=n.root;if(n.verdict!==void 0)return n.verdict;if(Ln(r,this.scope.context))return!0;const o=i.isIdentifier(r)?F(r):void 0,a=i.isBindingElement(o)?o.getFirstAncestorByKind(d.VariableDeclaration):o,c=ee(a)&&this.isInImpl(a)?a.getInitializer():void 0,l=i.isBindingElement(o)?o:a;return s>0&&c!==void 0&&(i.isBindingElement(l)||i.isVariableDeclaration(l))&&!this.walk.isCompromised(l)&&this.isRootedInContext(c,s-1)}isSource(t){const{impl:s,parameter:n}=this.scope;return t.compilerNode===n?.compilerNode?!0:t.getParent()!==s&&this.isInImpl(t)&&(this.budget.memoized(t.compilerNode,()=>this.flowsIntoTainted(t),this.verdicts)||this.walk.isCompromised(t))}isVariableTainted(t){return this.budget.memoized(t.compilerNode,()=>{const s=t.getParent().getParent();if(i.isCatchClause(t.getParent())||this.walk.isCompromised(t))return!0;if(i.isForOfStatement(s)||i.isForInStatement(s))return this.isTaintedValue(s.getExpression(),!0);const n=t.getInitializer(),r=Ct(t);if(n===void 0||r)return!0;if(this.isRootedInContext(n,dt))return!1;if(this.variableDepth>=dt)return this.budget.cut();this.variableDepth+=1;try{return this.isTaintedValue(n,!1)}finally{this.variableDepth-=1}},this.verdicts)}}const Ks=new WeakMap,uu=e=>{const t=Ks.get(e.impl.compilerNode);if(t!==void 0)return t;const s=new du(e);return Ks.set(e.impl.compilerNode,s),s},fu=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),gu=new Set(["insert","insertManyUnsafe","patch","replace"]),pu=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();return gu.has(t)&&di(e.getExpression())?t:void 0},mu=(e,t)=>{if(t!=="insertManyUnsafe")return i.isObjectLiteralExpression(e)?[e]:[];if(!i.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())i.isObjectLiteralExpression(n)&&s.push(n);return s},hu=(e,t)=>{const s=cn(e);return s?.member===t?h(s.object):void 0},Bs=(e,t)=>i.isIdentifier(e)&&F(e)?.compilerNode===t.compilerNode,Un=(e,t,s,n=1)=>{const r=hu(e,s);if(r!==void 0)return Bs(r,t);const o=i.isIdentifier(e)?F(e):void 0;if(i.isBindingElement(o)){const c=o.getParent(),l=c.getParent();return o.getDotDotDotToken()===void 0&&se(o)===s&&i.isObjectBindingPattern(c)&&(l.compilerNode===t.compilerNode||ee(l)&&Bs(h(l.getInitializer()),t))}const a=ee(o)?o.getInitializer():void 0;return n>0&&a!==void 0&&Un(a,t,s,n-1)},wt=e=>{const t=h(e)??e;return i.isConditionalExpression(t)?[...wt(t.getWhenTrue()),...wt(t.getWhenFalse())]:[t]},vu=(e,t,s)=>{const n=[],r=s===void 0?void 0:uu(s);for(const o of e.getProperties()){let a,c;if(i.isPropertyAssignment(o)?(a=S(o),c=o.getInitializer()):i.isShorthandPropertyAssignment(o)&&(a=S(o),c=o.getNameNode()),a===void 0||c===void 0||!fu.has(a))continue;const l=wt(c).filter(g=>r===void 0?W(g)&&!ui(g):r.isTaintedValue(g,!0));if(l.length>0){const g=t.ownerField===a&&s?.pristine===!0&&Un(c,s.parameter,a),f=l.every(m=>Wd(t.call,m));n.push({field:a,file:t.relativePath,line:t.call.getStartLineNumber(),method:t.method,scope:t.scope,...g&&{ownerScoped:!0},...f&&{guarded:!0}})}}return n},Eu=(e,t,s)=>{const n=pu(e.getExpression()),r=n===void 0?void 0:e.getArguments()[1];if(n===void 0||r===void 0)return[];const o=mu(r,n);if(o.length===0)return[];const a=E(e),c=Bd(e),l={call:e,method:n,ownerField:c===void 0?void 0:s(c.mutatorName),relativePath:t,scope:a};return o.flatMap(u=>vu(u,l,c))},xu=(e,t,s=[],n=[])=>{const r=new Map(n.map(a=>[`${a.filePath}:${a.exportName}`,a.owner])),o=O(e,t,(a,c)=>Eu(a,c,l=>r.get(`${c}:${l}`)));return Tt(o,s)},Su=["providerSubscriptionId","state"],Au=["providerEventId","processedAt"],zs=(e,t)=>t.every(s=>s in e.shape),yu=e=>{const t=e.find(n=>n.name==="payment_subscriptions"),s=e.find(n=>n.name==="payment_events");return t!==void 0&&s!==void 0&&zs(t,Su)&&zs(s,Au)},bu=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Nu=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Pu=e=>{const t=M(e,"webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?Nu(t.getInitializer()):void 0},wu=(e,t)=>{const s=y(e.getExpression());if(s===void 0||!bu.has(s))return;const[n]=e.getArguments(),r=n&&i.isObjectLiteralExpression(n)?Pu(n):void 0;return{callee:s,scope:E(e),file:t,line:e.getStartLineNumber(),...r===void 0?{}:{toleranceSeconds:r}}},Iu=(e,t)=>O(e,t,wu),Cu=new Map([["defineQueue",0],["defineSubscription",1],["defineWorkflow",0]]),Tu=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},Ou=(e,t)=>{const s=e.getArguments()[t];if(!s||!i.isObjectLiteralExpression(s))return;const n=M(s,"handler");if(n===void 0||!i.isPropertyAssignment(n))return;const r=n.getInitializer();if(r&&(i.isArrowFunction(r)||i.isFunctionExpression(r)))return r},Vn=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},qn=(e,t)=>e===t||e.startsWith(`${t}.`),jn=e=>{const t=e.getDescendantsOfKind(d.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},$s=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e||i.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(i.isBindingElement(t)&&t.getNameNode()===e)},Wn=e=>{const t=e.getDescendantsOfKind(d.Identifier).filter(s=>$s(s));return i.isIdentifier(e)&&$s(e)&&t.push(e),t},ku=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(d.BindingElement).map(s=>s.getName())},Ru=e=>{const t=Vn(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(d.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const r=n.getInitializer(),o=i.isVariableDeclarationList(r)?r.getDeclarations()[0]?.getNameNode():void 0;o&&i.isIdentifier(o)&&s.push(`${o.getText()}.body`)}return s},Fu=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:Ru(e),r=new Set,o=a=>jn(a).some(c=>n.some(l=>qn(c.getText(),l)))?!0:Wn(a).some(c=>r.has(c.getText()));for(const a of e.getDescendantsOfKind(d.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of ku(a))r.add(l)}return{names:r,prefixes:n}},Du=(e,t)=>jn(e).some(s=>t.prefixes.some(n=>qn(s.getText(),n)))?!0:Wn(e).some(s=>t.names.has(s.getText())),Lu=e=>{const t=Gr(e);return t===void 0?void 0:{exportName:String(t.at(-1)),file:t.slice(0,-1).join("/")}},Mu=(e,t,s)=>{const n=Vn(e,0);if(n===void 0)return[];const r=Fu(e,t,n),o=new Set([n,...r.prefixes.filter(c=>c.endsWith(".body")).map(c=>c.slice(0,-5))]),a=[];for(const c of e.getDescendantsOfKind(d.CallExpression)){const l=c.getExpression();if(!i.isPropertyAccessExpression(l)||!nn.has(l.getName())||!o.has(l.getExpression().getText()))continue;const u=c.getArguments()[1];if(!u||!Du(u,r))continue;const g=Lu(c.getArguments()[0]);g!==void 0&&a.push({dispatchKind:t,file:s,scope:E(c),line:c.getStartLineNumber(),targetExport:g.exportName,targetFile:g.file})}return a},_u=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=Tu(n),o=r===void 0?void 0:Cu.get(r);if(o===void 0)continue;const a=Ou(n,o);a!==void 0&&s.push(...Mu(a,r==="defineWorkflow"?"workflow":"queue",t))}return s},Ku=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(..._u(r,T(t,n)))}return s},Us={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},Vs=new Set(["account","credential","member","passkey","session","user"]),Bu=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),zu=e=>{const s=Bu(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return Vs.has(s)||Vs.has(n)},$u=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Uu=(e,t)=>{const{objects:s,opaque:n}=Dt(e,t);return $a(s).some(r=>$u(r))?!0:n?void 0:!1},Vu=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!M(t,"captcha"),usesRateLimit:!!M(t,"rateLimit")}},qu=e=>{if(i.isCallExpression(e))return e;if(!i.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&i.isCallExpression(s)?s:void 0},Me={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},ju=e=>{const t=qu(e),s=t?y(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=Vu(t);return{...Me,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in Us?{...Me,[Us[s]]:!0}:Me},Wu=e=>{const t={...Me};let s=e;for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))break;const r=n.getName()==="use"?s.getArguments()[0]:void 0;if(r){const o=ju(r);t.usesCaptcha||=o.usesCaptcha,t.usesEmailGate||=o.usesEmailGate,t.usesMask||=o.usesMask,t.usesRateLimit||=o.usesRateLimit,t.usesRls||=o.usesRls}s=n.getExpression()}return t},Hu=new Set(["insert","insertMany","insertManyUnsafe","replace"]),Gu=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Hu.has(t.getName()))return!1;const s=t.getExpression();if(!$(s))return!1;const r=e.getArguments()[0];return!r||!(i.isStringLiteral(r)||i.isNoSubstitutionTemplateLiteral(r))?!1:zu(r.getLiteralText())},Yu=new Set(["create","publish","publishBatch","runAfter","runAt","send","sendBatch"]),qs=new Set(["queues","scheduler","topics","workflows"]),Qu=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Yu.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&qs.has(s.getName())&&fi(s.getExpression()))return!0;s=s.getExpression()}const n=kt(s);return n?.length===1&&qs.has(n[0]??"")},Xu=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return $(s)},Hn=new Set(["generateObject","generateText","streamObject","streamText"]),Ju=e=>{const t=y(e.getExpression());return t!==void 0&&Hn.has(t)},Zu=e=>{const t=y(e.getExpression());if(t===void 0||!Hn.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(n=>i.isSpreadAssignment(n))?!1:!M(s,"maxOutputTokens")},ef=new Set(["log","span","trace"]),tf=new Set(["ai"]),sf=new Set(["email","mail"]),nf=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","topics","workflows"]),ut=(e,t)=>[...t].some(s=>He(e,s).length>0),rf=new Set([d.ArrowFunction,d.FunctionDeclaration,d.FunctionExpression,d.GetAccessor,d.MethodDeclaration,d.SetAccessor]),of=new Set(["every","filter","flatMap","forEach","map","some"]),af=new Set(["all","allSettled","race"]),cf=e=>{const t=e.getParent();if(!t||!i.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName();if(of.has(n))return t;const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="Promise"&&af.has(n))return t},lf=e=>{let t=e.getParent();for(;t;){if(i.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(rf.has(t.getKind())){const s=cf(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},df=e=>{let t=e;for(;;){const s=t.getParent();if(!i.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;if(s.getName()==="catch")return!0;if(s.getName()!=="then"&&s.getName()!=="finally")return!1;const n=s.getParent();if(!i.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},uf=e=>{let t=e;for(;;){const s=t.getParent();if(i.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return i.isCallExpression(s)&&s.getExpression()===t?s:void 0}},ff=e=>{let t=!1,s=!0;for(const n of[...nf].flatMap(r=>He(e,r))){const r=uf(n);r&&(t=!0,!lf(r)&&!df(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},gf=e=>e.getDescendantsOfKind(d.ThrowStatement).some(t=>{const s=t.getExpression();if(!i.isNewExpression(s))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="Error"}),js="lunora-advisor-exempt",pf=/^[\s*/]+/u,mf=/[\w-]/u,hf=e=>{const s=(e.getFirstAncestorByKind(d.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
|
|
6
|
+
Install them with your package manager, then re-run codegen.`)},_o="env.ts",Ko=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return qe(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},Bo=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(d.ImportDeclaration);return n!==void 0&&qe(n.getModuleSpecifierValue())}return!1},zo=e=>{if(i.isIdentifier(e))return Ko(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&Bo(t)}return!1},$o=e=>{const t=[];for(const s of e.getVariableDeclarations()){const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!zo(n.getExpression()))continue;const o=s.getNameNode();if(!i.isIdentifier(o)){if(s.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw ye(o,"defineEnv exports must be plain named exports (no destructuring)")}const a=tn(s,"member");a!==void 0&&t.push({exportName:a})}return t},Uo=(e,t)=>{const s=v(t,_o);if(!R(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),r=$o(n);if(r.length!==0){if(r.length>1)throw ye(n,`lunora/env.ts declares ${r.length.toString()} defineEnv() contracts (${r.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return r[0]}},En="identity.ts",Vo=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return qe(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},qo=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(d.ImportDeclaration);return n!==void 0&&qe(n.getModuleSpecifierValue())}return!1},jo=e=>{if(i.isIdentifier(e))return Vo(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&qo(t)}return!1},Wo=e=>{const t=[];for(const s of e.getVariableDeclarations()){const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!jo(n.getExpression()))continue;const o=s.getNameNode();if(!i.isIdentifier(o)){if(s.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw ye(o,"defineIdentity exports must be plain named exports (no destructuring)")}const a=tn(s,"member");a!==void 0&&t.push({exportName:a})}return t},Ho=(e,t)=>{const s=v(t,En);if(!R(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),r=Wo(n);if(r.length!==0){if(r.length>1)throw ye(n,`lunora/identity.ts declares ${r.length.toString()} defineIdentity() contracts (${r.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return r[0]}},Go=new Set(["allowedHosts","deniedHosts","interceptHttps"]),Yo=(e,t)=>{const s=h(t);if(s===void 0||!i.isIdentifier(s))return s;const n=s.getText();return h(e.getDescendantsOfKind(d.VariableDeclaration).find(r=>r.getName()===n)?.getInitializer())},Qo=(e,t)=>e!==void 0&&i.isObjectLiteralExpression(e)&&e.getProperties().some(s=>{if(i.isShorthandPropertyAssignment(s))return t.has(A(s));if(!i.isPropertyAssignment(s)||!t.has(A(s)))return!1;const n=h(s.getInitializer())?.getText();return n!=="false"&&n!=="undefined"}),Xo=new Set(["durable"]),Jo=new Set(["rollback"]),Zo=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)?t.getName():t.getText()},ea=new Map([["defineContainer",{keys:Go,signal:"containerEgressPolicy"}],["defineStep",{keys:Jo,signal:"workflowRollback"}],["stream",{keys:Xo,signal:"durableStreams"}]]),ta=(e,t)=>{const s=ea.get(Zo(t));if(s!==void 0)return t.getArguments().some(n=>Qo(Yo(e,n),s.keys))?s.signal:void 0},sa=(e,t)=>{const s={containerEgressPolicy:!1,durableStreams:!1,secrets:!1,workflowRollback:!1};for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.secrets||(s.secrets=qr(r).has("secrets"));for(const o of r.getDescendantsOfKind(d.CallExpression)){const a=ta(r,o);a!==void 0&&(s[a]=!0)}if(Object.values(s).every(Boolean))break}return s},na="createWorker",ra="extend",ps=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralValue():void 0,ms=e=>{const t=[],s=ps(C(e,"backupCron"));s!==void 0&&t.push(s);const n=C(e,"crons");if(n===void 0||!i.isObjectLiteralExpression(n))return t;for(const r of n.getProperties()){if(!i.isPropertyAssignment(r)&&!i.isMethodDeclaration(r))continue;const o=ps(r.getNameNode());o!==void 0&&t.push(o)}return t},ia=e=>{const t=b(e.getExpression()),[s]=e.getArguments();if(s===void 0)return[];if(t===na)return i.isObjectLiteralExpression(s)?ms(s):[];if(t!==ra||!(i.isArrowFunction(s)||i.isFunctionExpression(s)))return[];const n=sn(s.getBody());return n===void 0?[]:ms(n)},oa=(e,t)=>{const s=[];for(const{filePath:n}of je(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of r.getDescendantsOfKind(d.CallExpression))s.push(...ia(o))}return[...new Set(s)]},xn=e=>{if(e.kind==="id")return e.tableName;if(!(e.kind!=="array"&&e.kind!=="optional"))return e.inner===void 0?void 0:xn(e.inner)},aa=e=>{const t=new Set(e.tables.map(s=>s.name));return e.tables.some(s=>Object.values(s.shape).some(n=>{const r=xn(n);return r!==void 0&&t.has(r)}))},ca=(e,t)=>{const s=new Map,n=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const o=s.get(r.name);if(o!==void 0)throw new J("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${o} and agent "${r.exportName}". Workflow and agent names share one account-wide namespace and must be unique together.`,{status:500});const a=n.get(r.className);if(a!==void 0)throw new J("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${a} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},la=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:r}=e,o=Ho(s,t),a=Uo(s,t),c=kr(s,t),{queues:l,topics:u}=Jr(s,t),g=ei(n),f=_r(s,t);ca(c,f);const m=Kr(s,t),S=ti(s,t),_=Br(s,t,c,f),Y=oa(s,t),L=sa(s,t),N=Zr(s,t),z=jr(s,t);z.browser=z.browser||N.usesSandboxBrowser;const K=ri(z,dn(n,e.target),{agents:f.length>0,commitOrderedTables:r.tables.some(D=>D.commitOrdered===!0),cronTriggers:_.length>0,crossShardFanout:r.tables.some(D=>ni(D)),containerEgressPolicy:L.containerEgressPolicy,containerRuntimeScheduling:m.some(D=>D.schedulingPolicy==="durable_object"),containerSandboxTools:m.some(D=>D.sandbox===!0),durableStreams:L.durableStreams,globalTables:r.tables.some(D=>D.shardMode==="global"),queues:l.length>0,relationGraph:aa(r),secrets:L.secrets,services:g.length>0,topics:u.length>0,vectorStore:r.vectorIndexes.length>0,workerLoaders:N.usesSandboxLoader,workflowRollback:L.workflowRollback,workflowSchedules:c.some(D=>D.schedules!==void 0)}),P=K.usage,re=Mr(P),ie=K.signals.vectorStore!==!1,fe=K.signals.services===!1?[]:g,oe=Wr(n),be=oe??new Set,V=be.has("lunorash");Mo(r,oe,{hasVectors:ie,scheduler:P.scheduler||_.length>0,storage:P.storage||S.rules.length>0||Object.keys(un(r)).length>0,usage:P});const B=R(v(t,"flags.ts")),k=R(v(t,"notify.ts"));return{agents:f,capabilities:re,containers:m,crons:_,dataModelContent:di(r),declaredDependencies:oe,dependencies:be,entryCronTriggers:Y,env:a,featureUsage:P,hasFlags:B,hasNotify:k,identity:o,platformGate:{...K,diagnostics:[...ii(n,e.target),...K.diagnostics]},queues:l,serverContent:ci({agents:f,capabilities:re,containers:m,env:a,hasVectors:ie,hasFlags:B,hasNotify:k,identity:o,queues:l,schema:r,services:fe,storageRuleBuckets:S.rules.map(D=>D.bucket),topics:u,useUmbrella:V,workflows:c}),services:fe,storageRulesMetadata:S,topics:u,usesSandbox:N.usesSandboxBrowser||N.usesSandboxContainer||N.usesSandboxFs,useUmbrella:V,workflows:c}},Sn=new Set(["delete","get","head","options","patch","post","put"]),da=new Set(["handler","stream"]),ua=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,hs=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),fa=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Sn.has(t.getName()))return;const s=t.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!i.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},ga=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||Sn.has(n.getName()))break;s=n.getExpression()}return fa(s)},pa=e=>{for(const t of e.getDescendantsOfKind(d.PropertyAccessExpression))if(hs.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&hs.has(s.getText()))return!0}return!1},ma=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||!da.has(n.getName()))return;const r=ga(s);if(!r||!ua.test(r.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&pa(o);return{exportName:U(e)??e.getName(),file:t,method:r.method,path:r.path,usesGuard:a}},ha=(e,t)=>{const s=[];for(const n of H(e)){const r=ma(n,t);r&&s.push(r)}return s},va=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ha(r,T(t,n)))}return s},Ea=e=>{const t=e.getText(),s=n=>{const r=n.getNameNode();return i.isIdentifier(r)&&r.getText()===t};for(const n of e.getAncestors())if(!(!i.isArrowFunction(n)&&!i.isFunctionExpression(n)&&!i.isFunctionDeclaration(n)))for(const r of n.getParameters()){const o=r.getDescendantsOfKind(d.BindingElement).find(a=>s(a));if(o!==void 0)return o}},xa=e=>{let t=e;for(;;){const s=t.getParent();if(!i.isObjectBindingPattern(s))return;const n=s.getParent();if(i.isBindingElement(n)){t=n;continue}return i.isParameterDeclaration(n)?se(t):void 0}},Sa=e=>{const t=e.getText();if(!e.getAncestors().some(o=>{const a=i.isFunctionLikeDeclaration(o)||i.isArrowFunction(o)?o.getParameters()[1]:void 0,c=a?.getNameNode();return a!==void 0&&(i.isIdentifier(c)?c.getText()===t:a.getDescendantsOfKind(d.BindingElement).some(l=>l.getName()===t))&&ds(a)}))return!1;const n=F(e),r=i.isParameterDeclaration(n)?n:n?.getFirstAncestorByKind(d.Parameter);return r!==void 0&&(i.isParameterDeclaration(n)||i.isBindingElement(n))&&ds(r)},vs=(e,t)=>{const s=e.getParent();if(i.isPropertyAccessExpression(s)&&s.getNameNode()===e||i.isPropertyAssignment(s)&&s.getNameNode()===e)return!1;if(e.getText()===t)return!0;const n=Ea(e);return n!==void 0&&xa(n)===t?!0:t==="args"&&Sa(e)},An=(e,t)=>i.isIdentifier(e)?vs(e,t):e.getDescendantsOfKind(d.Identifier).some(s=>vs(s,t)),Aa=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t:void 0},Es=e=>{const t=i.isIdentifier(e)?F(e):void 0;return i.isVariableDeclaration(t)&&i.isIdentifier(t.getNameNode())&&!Ct(t)?t.getInitializer():void 0},Et=e=>An(e,"args"),j=e=>{if(!i.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a));if(s===void 0)return;const n=e.getStart();let r,o=-1;for(const a of s.getDescendantsOfKind(d.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<n&&l>o&&(r=c,o=l)}return r},W=e=>{if(Et(e))return!0;const t=j(e);return t!==void 0&&Et(t)},ya=e=>{if(i.isCallExpression(e)||i.isNewExpression(e))return!1;const t=j(e);return t===void 0||!(i.isCallExpression(t)||i.isNewExpression(t))},ne=e=>{if(it(e))return!0;const t=Es(e);if(t!==void 0&&it(t))return!0;const s=t??e;return(i.isIdentifier(s)?[s]:s.getDescendantsOfKind(d.Identifier)).some(r=>{const o=Es(r);return o!==void 0&&it(o)})},Re=(e,t)=>An(e,t),ba=(e,t)=>{if(Re(e,t))return!0;const s=j(e);if(s!==void 0&&Re(s,t))return!0;const n=Aa(e);if(n!==void 0){const r=j(n);return r!==void 0&&Re(r,t)}return!1},Na=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:q(e.getExpression(),["ai"]),Pa=(e,t)=>{if(!Na(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!W(s)||ne(s)))return{scope:E(e),file:t,line:e.getStartLineNumber()}},wa=(e,t)=>O(e,t,Pa),Ia=new Set(["generateText","streamText"]),Ca=new Set(["messages","prompt","system"]),Ta=[{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"]}],Oa=(e,t)=>Ta.some(s=>s.methods.has(t)&&s.prefixes.some(n=>e===n||e.startsWith(`${n}.`))),ka=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),n=[ui(t.getExpression()),t.getExpression().getText()].find(r=>r!==void 0&&Oa(r,s));return n===void 0?void 0:`${n}.${s}`},Ra=e=>{for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=ka(t);if(s!==void 0)return s}},Fa=e=>{const t=new Set,s=e.getFirstAncestor(o=>i.isArrowFunction(o)||i.isFunctionExpression(o)||i.isFunctionDeclaration(o)),[n]=s?.getParameters()??[],r=n?.getNameNode();if(r===void 0||!i.isObjectBindingPattern(r))return t;for(const o of r.getElements()){const a=se(o),c=o.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},Da=e=>{if(Et(e))return!0;const t=Fa(e);return t.size===0?!1:e.getDescendantsOfKind(d.Identifier).some(s=>t.has(s.getText()))},La=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!Ca.has(A(t)))continue;const s=t.getInitializer();if(s!==void 0&&Da(s))return!0}return!1},Ma=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=b(n.getExpression());if(r===void 0||!Ia.has(r))continue;const[o]=n.getArguments();if(o===void 0||!i.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(d.CallExpression))if(b(c.getExpression())==="tool"&&(a=Ra(c),a!==void 0))break;a!==void 0&&s.push({scope:E(n),file:t,line:n.getStartLineNumber(),method:r,sideEffect:a,userInputDerived:La(o)})}return s},_a=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ma(r,T(t,n)))}return s},Ka=e=>q(e,["fetch"]),Ba=(e,t)=>{if(!Ka(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!W(s)))return{scope:E(e),file:t,line:e.getStartLineNumber()}},za=(e,t)=>O(e,t,Ba),Ft=(e,t=new Set)=>{if(t.has(e))return!0;t.add(e);try{return e.getProperties().some(s=>{if(!i.isSpreadAssignment(s))return!1;const n=Ge(s.getExpression());return n===void 0||Ft(n,t)})}finally{t.delete(e)}},$a=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=M(t,"args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer(),r=n===void 0?void 0:Ge(n);return r===void 0?{objects:[],opaque:!0}:{objects:[r],opaque:Ft(r)}},Ua=e=>{const t=[];let s=!1,n=e;for(;i.isCallExpression(n);){const r=n.getExpression();if(!i.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const o=n.getArguments()[0],a=o!==void 0&&i.isExpression(o)?Ge(o):void 0;a===void 0?s=!0:(t.push(a),s||=Ft(a))}n=r.getExpression()}return{objects:t,opaque:s}},Dt=(e,t)=>t?Ua(t):$a(e),yn=(e,t)=>{if(t.has(e))return[];t.add(e);try{return e.getProperties().flatMap(s=>{if(i.isSpreadAssignment(s)){const n=Ge(s.getExpression());return n===void 0?[]:yn(n,t)}return i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)?[A(s)]:[]})}finally{t.delete(e)}},Va=e=>e.flatMap(t=>yn(t,new Set)),qa=new Set(["check","length","max"]),xt=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!(!i.isPropertyAccessExpression(t)||t.getExpression().getText()!=="v"))return t.getName()},ja=e=>[e,...e.getDescendants()].filter(t=>xt(t)!==void 0),Wa=e=>{let t=e;for(;;){const s=t.getParent();if(!s||!i.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;const n=s.getParent();if(!n||!i.isCallExpression(n)||n.getExpression()!==s)return!1;if(qa.has(s.getName()))return!0;t=n}},Ha=e=>{const t=[],s=[];for(const n of e)for(const r of n.getProperties()){if(!i.isPropertyAssignment(r))continue;const o=r.getInitializer();if(!o)continue;const a=ja(o),c=A(r);a.some(l=>xt(l)==="any")?t.push(c):a.some(l=>xt(l)==="string"&&!Wa(l))&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Ga=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=G(s);if(n?.visibility!=="public")return;const{objects:r}=Dt(s,n.receiver),{anyArgs:o,unboundedStringArgs:a}=Ha(r);if(!(o.length===0&&a.length===0))return{anyArgs:o,exportName:U(e)??e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Ya=(e,t)=>{const s=[];for(const n of H(e)){const r=Ga(n,t);r&&s.push(r)}return s},Qa=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ya(r,T(t,n)))}return s},ct=e=>e?.getKind()===d.TrueKeyword,Xa=e=>e?.getKind()===d.FalseKeyword,Ja=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Za=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),ec=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&b(t.getExpression())==="scim"),tc=e=>e!==void 0&&i.isCallExpression(e)&&Za.has(b(e.getExpression())??""),sc=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),nc=e=>{const t=C(e,"advanced"),s=C(e,"emailAndPassword"),n=C(e,"session");return{analyzable:!0,disableCsrfCheck:ct(C(t,"disableCSRFCheck")),emailPasswordEnabled:ct(C(s,"enabled")),requireEmailVerification:ct(C(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:ec(C(e,"plugins"))&&tc(C(e,"database")),secureCookiesDisabled:Xa(C(t,"useSecureCookies")),sessionFreshAgeZero:Ja(C(n,"freshAge")),trustedOriginsWildcard:sc(C(e,"trustedOrigins"))}},rc=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),ic=(e,t)=>{if(b(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(o=>i.isSpreadAssignment(o)),r=s!==void 0&&i.isObjectLiteralExpression(s)&&!n?nc(s):rc();return{scope:E(e),file:t,line:e.getStartLineNumber(),...r}},oc=(e,t)=>Hr(e,t,ic),ac=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return fn(e.getExpression(),t.matchReceiver)?s:void 0},cc=(e,t,s)=>{const n=ac(e.getExpression(),s);if(n===void 0)return;const r=e.getArguments()[s.argIndex];if(!(!r||!W(r)||ne(r))&&!(s.requireUnmodifiedReach===!0&&!ya(r)))return{scope:E(e),file:t,line:e.getStartLineNumber(),method:n}},Ye=(e,t,s)=>O(e,t,(n,r)=>cc(n,r,s)),lc=new Set(["content","pdf","scrape","screenshot"]),dc=(e,t)=>Ye(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:lc}),uc=e=>i.isDoStatement(e)||i.isForInStatement(e)||i.isForOfStatement(e)||i.isForStatement(e)||i.isWhileStatement(e),bn=e=>{const t=e.getLabel()?.getText(),s=r=>t!==void 0?i.isLabeledStatement(r)&&r.getLabel().getText()===t:uc(r)||i.isBreakStatement(e)&&i.isSwitchStatement(r);let n=e.getFirstAncestor(r=>Z(r)||s(r));if(!(n===void 0||Z(n))){for(;i.isContinueStatement(e)&&i.isLabeledStatement(n);)n=n.getStatement();return n}},Lt=(e,t)=>y(e.getFirstAncestor(s=>y(s,t)||Z(s)),t),fc=(e,t)=>y(e,t)||e.getFirstAncestor(s=>y(s,t))!==void 0,Nn=(e,t)=>{if(i.isReturnStatement(e)||i.isThrowStatement(e))return y(e,t)||Lt(e,t);if(i.isBreakStatement(e)||i.isContinueStatement(e)){const s=bn(e);return s!==void 0&&!fc(s,t)}return!1},Pn=e=>[...i.isBreakStatement(e)||i.isContinueStatement(e)||i.isReturnStatement(e)||i.isThrowStatement(e)?[e]:[],...e.getDescendantsOfKind(d.BreakStatement),...e.getDescendantsOfKind(d.ContinueStatement),...e.getDescendantsOfKind(d.ReturnStatement),...e.getDescendantsOfKind(d.ThrowStatement)],gc=e=>Pn(e).some(t=>Nn(t,e)),wn=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getExpression();return i.isPropertyAccessExpression(n)&&n.getName()===t?s.getName():void 0},pc=e=>{if(!i.isPropertyAccessExpression(e))return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="scheduler"||i.isIdentifier(t)&&t.getText()==="scheduler"},mc=new Map([["publish",{kind:"publish",surface:"topics"}],["publishBatch",{kind:"publish",surface:"topics"}],["send",{kind:"enqueue",surface:"queues"}],["sendBatch",{kind:"enqueue",surface:"queues"}]]),hc=/^[\w$]+:[\w$]+$/u,vc=(e,t)=>{const s=rn(t);return s!==void 0?{kind:"call",target:s}:e!=="run"&&t!==void 0?{kind:"call",reason:'the function reference is not a static api.* / internal.* chain or a "namespace:export" key'}:void 0},Ec=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),[n,r]=e.getArguments();if(nn.has(s))return vc(s,n);if((s==="runAfter"||s==="runAt")&&pc(t)){const c=rn(r)??(i.isStringLiteral(r)&&hc.test(r.getLiteralText())?r.getLiteralText():void 0);return c===void 0?{kind:"schedule",reason:'the scheduled function is not a static api.* / internal.* chain or a "namespace:export" key'}:{kind:"schedule",target:c}}const o=mc.get(s),a=o===void 0?void 0:wn(t,o.surface);return o===void 0||a===void 0?void 0:{kind:o.kind,target:a}},xc=new Set([d.AmpersandAmpersandEqualsToken,d.AmpersandAmpersandToken,d.BarBarEqualsToken,d.BarBarToken,d.QuestionQuestionEqualsToken,d.QuestionQuestionToken]),In=e=>yr.isOptionalChain(e.compilerNode),Sc=(e,t)=>i.isIfStatement(t)?!y(e,t.getExpression()):i.isWhileStatement(t)||i.isForInStatement(t)||i.isForOfStatement(t)?y(e,t.getStatement()):i.isForStatement(t)?y(e,t.getStatement())||y(t.getIncrementor(),e):i.isCaseClause(t)||i.isDefaultClause(t)||i.isCatchClause(t)?!0:Z(t)?t.getFirstAncestor(Z)!==void 0:i.isConditionalExpression(t)?!y(e,t.getCondition()):i.isBinaryExpression(t)?!y(e,t.getLeft())&&xc.has(t.getOperatorToken().getKind()):(i.isCallExpression(t)||i.isElementAccessExpression(t))&&In(t)?!y(e,t.getExpression()):i.isBlock(t)&&t.getStatements().some(s=>s.getEnd()<=e.getStart()&&gc(s)),Ac=e=>{let t=e,s=e.getParent();for(;s!==void 0&&(i.isAwaitExpression(s)||i.isParenthesizedExpression(s));)t=s,s=s.getParent();const n=i.isVariableDeclaration(s)||i.isBinaryExpression(s)&&y(t,s.getRight())&&s.getOperatorToken().getKind()===d.EqualsToken,r=e.getFirstAncestor(Z);return n||r?.getDescendantsOfKind(d.ThrowStatement).some(o=>o.getStart()>=e.getEnd()&&y(o.getFirstAncestor(Z),r))===!0},yc=(e,t)=>{if(In(e)||t==="schedule"&&Ac(e))return!0;let s=e;for(let n=s.getParent();n!==void 0&&!i.isSourceFile(n);n=n.getParent()){if(Sc(s,n))return!0;s=n}return!1},xs=(e,t,s)=>s===void 0?void 0:{...s,...yc(e,s.kind)?{conditional:!0}:{},file:t,line:e.getStartLineNumber(),scope:E(e)},bc=(e,t)=>[...O(e,t,(s,n)=>xs(s,n,Ec(s))),...de(e,t,d.PropertyAccessExpression,(s,n)=>{const r=wn(s,"services");return xs(s,n,r===void 0?void 0:{kind:"invoke",target:r})})],Nc=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Pc=new Set(["RateLimiter"]),wc=new Set(["extend"]),Ss="lunora",Ic=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],Cn=e=>{const t=[],s=[];let n=!1;for(const r of e.getProperties()){if(i.isSpreadAssignment(r)){n=!0;continue}if(i.isPropertyAssignment(r)){const o=A(r);t.push(o),r.getInitializer()?.getKind()===d.TrueKeyword&&s.push(o);continue}(i.isShorthandPropertyAssignment(r)||i.isMethodDeclaration(r))&&t.push(A(r))}return{analyzable:!n,presentKeys:t,trueKeys:s}},St=e=>e&&i.isObjectLiteralExpression(e)?Cn(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Cc=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&sn(t.getBody());return s?Cn(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Tc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=b(n.getExpression());r!==void 0&&(Nc.has(r)?s.push({callee:r,file:t,line:n.getStartLineNumber(),...St(n.getArguments()[0])}):wc.has(r)&&s.push({callee:r,file:t,line:n.getStartLineNumber(),...Cc(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(d.NewExpression)){const r=b(n.getExpression());r===void 0||!Pc.has(r)||s.push({callee:r,file:t,line:n.getStartLineNumber(),...St(n.getArguments()[0])})}return s},Oc=(e,t)=>{for(const s of Ic){const n=v(t,s);if(!R(n))continue;const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=[];for(const a of r.getDescendantsOfKind(d.CallExpression))b(a.getExpression())===Ss&&o.push({callee:Ss,file:s,line:a.getStartLineNumber(),...St(a.getArguments()[0])});return o}return[]},kc=(e,t)=>{const s=[];for(const{displayPath:n,filePath:r}of je(t)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Tc(o,n))}return s.push(...Oc(e,he(t))),s},As="ctx.containers.",Rc=e=>{if(!e.startsWith(As))return!1;const t=e.slice(As.length);return t.length>0&&!t.includes(".")},Fc=(e,t)=>Ye(e,t,{argIndex:0,matchReceiver:Rc,methods:new Set(["get"])}),Dc=new Set(["allow","deny","setAllowed"]),Lc=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=M(t,"enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},Mc=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!Lc(e)))return{detail:"enableInternet: true",scope:E(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},_c=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!Dc.has(s.getName()))return;const n=s.getExpression();if(!(!i.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),scope:E(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},Kc=(e,t)=>Mc(e,t)??_c(e,t),Bc=(e,t)=>O(e,t,Kc),zc=new Set(["defineExportSink","r2Sink","webhookExportSink"]),$c=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return zc.has(s)?s:void 0},Uc=e=>{const t=[],s=[];for(const n of e.getProperties()){if(i.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(n)){const r=A(n);t.push(r);const o=n.getInitializer();o&&i.isStringLiteral(o)&&o.getLiteralText()===""&&s.push(r);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n)||i.isGetAccessorDeclaration(n))&&t.push(A(n))}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Vc=(e,t)=>{const s=[];for(const{displayPath:n,filePath:r}of je(t)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r);for(const a of o.getDescendantsOfKind(d.CallExpression)){const c=$c(a);if(c===void 0)continue;const l=a.getArguments()[0],u=l&&i.isObjectLiteralExpression(l)?Uc(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:u.analyzable,emptyKeys:u.emptyKeys,factory:c,file:n,line:a.getStartLineNumber(),presentKeys:u.presentKeys})}}return s},qc=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),jc=new Set(["dbRateLimit","rateLimit"]),Wc=e=>{const t=an(e);if(!t)return!1;const s=M(t,"failOpen");return s!==void 0&&i.isPropertyAssignment(s)&&s.getInitializer()?.getKind()===d.TrueKeyword},Hc=(e,t)=>{const s=b(e.getExpression());if(s===void 0)return;const n=qc.get(s);if(n!==void 0)return{callee:s,scope:E(e),failOpen:Wc(e.getArguments()[n]),file:t,limitName:jc.has(s)?on(e):"",line:e.getStartLineNumber()}},Gc=(e,t)=>O(e,t,Hc),Yc=new Set(["boolean","number","object","string"]),Qc=e=>{const t=e.getName();if(!Yc.has(t))return;const s=e.getExpression();return q(s,["flags"])||q(s,["flags","details"])?t:void 0},Xc=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=Qc(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(i.isStringLiteral(n)||i.isNoSubstitutionTemplateLiteral(n)))return;const r=n.getLiteralValue();return r.length>0?{key:r,type:s}:void 0},Jc=(e,t)=>{const s=new Map;for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of r.getDescendantsOfKind(d.CallExpression)){const a=Xc(o);a&&!s.has(a.key)&&s.set(a.key,a.type)}}return[...s.entries()].map(([n,r])=>({key:n,type:r})).toSorted((n,r)=>n.key.localeCompare(r.key))},Zc=e=>{const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const s=G(t);if(s?.kind!=="query")return;const n=Gr(t,s.receiver);return n?{exportName:U(e)??e.getName(),handler:n}:void 0},ys=e=>{const t=e.getParent();return t&&i.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},el=e=>{const t=ys(e);if(!t)return"ctx.flags";if(t.getName()==="details"){const s=ys(t);return s?`ctx.flags.details.${s.getName()}`:"ctx.flags.details"}return`ctx.flags.${t.getName()}`},tl=(e,t)=>{const s=[];for(const n of He(e.handler,"flags"))s.push({callee:el(n),exportName:e.exportName,file:t,line:n.getStartLineNumber()});return s},sl=(e,t)=>{const s=[];for(const n of H(e)){const r=Zc(n);r&&s.push(...tl(r,t))}return s},nl=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...sl(r,T(t,n)))}return s},rl=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="boolean"?!1:q(e.getExpression(),["flags"]),il=e=>{if(e?.getKind()===d.TrueKeyword)return!0;if(e?.getKind()===d.FalseKeyword)return!1},ol=(e,t)=>{if(!rl(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const r=s.getLiteralValue(),o=il(n);if(!(r.length===0||o===void 0))return{defaultValue:o,scope:E(e),file:t,key:r,line:e.getStartLineNumber()}},al=(e,t)=>O(e,t,ol),cl=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 r=n.getTypeAtLocation(e),o=r.getText(e);if(!o||o==="any"||o==="never"||vi(o))return;const a=e.getSourceFile().getFilePath();if(Ei(r,e,a)){const c=xi(r,e,a,0,new Set);return c===void 0&&Si(o),c}return o},ll=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},dl=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},ul=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=T(t,n);for(const a of r.getDescendantsOfKind(d.CallExpression))ll(a)&&s.push({file:o,indexName:dl(a),line:a.getStartLineNumber()})}return s},Se=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,Tn=e=>{const t=e.getArguments()[0],s=Se(t);if(s!==void 0)return s;if(t===void 0||!i.isObjectLiteralExpression(t))return;const n=M(t,"handler");return n!==void 0&&i.isPropertyAssignment(n)?Se(n.getInitializer()):void 0},fl=new Set(["delete","get","head","options","patch","post","put"]),gl=new Set(["handler","stream"]),pl=new Set(["runAction","runMutation"]),ml=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),Ae=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,On=(e,t)=>{if(!(e===void 0||!i.isObjectBindingPattern(e))){for(const s of e.getElements())if(se(s)===t){const r=s.getNameNode();return i.isIdentifier(r)?r.getText():void 0}}},bs=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?i.isIdentifier(s)?s.getText():void 0:On(s,"ctx")},Ns=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&i.isIdentifier(s)?s.getText():void 0:On(s,"request")},Ps=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(d.CallExpression);i.isCallExpression(s)&&n.unshift(s);for(const r of n){const o=r.getExpression();if(!i.isPropertyAccessExpression(o))continue;const a=o.getName(),c=o.getExpression();if(pl.has(a)&&Ae(c,t))return a;if(ml.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&Ae(c.getExpression(),t))return`db.${a}`}},ws=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(d.PropertyAccessExpression))if(n.getName()==="auth"&&Ae(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(d.VariableDeclaration)){const r=n.getNameNode();if(!(!i.isObjectBindingPattern(r)||!Ae(n.getInitializer(),t))){for(const o of r.getElements())if(se(o)==="auth")return!0}}return!1},hl=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,vl=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="get"&&s.getName()!=="has")return!1;const n=s.getExpression();return i.isPropertyAccessExpression(n)&&n.getName()==="headers"&&Ae(n.getExpression(),t)},El=e=>[...i.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(d.StringLiteral).map(t=>t.getLiteralText())],kn=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:El(s)},xl=(e,t)=>{const s=e.getText();for(let n=e.getParent();n!==void 0;n=n.getParent()){if(!i.isArrowFunction(n)&&!i.isFunctionExpression(n)||!n.getParameters().some(c=>c.getName()===s))continue;const r=n.getParent();if(!i.isCallExpression(r))return[];const o=r.getExpression();if(!i.isPropertyAccessExpression(o))return[];const a=o.getExpression();return i.isIdentifier(a)?kn(t,a.getText()):[]}return[]},Sl=e=>{const t=e.getArguments()[0];if(t===void 0)return[];if(i.isStringLiteral(t))return[t.getLiteralText()];if(!i.isIdentifier(t))return[];const s=e.getSourceFile(),n=kn(s,t.getText());return n.length>0?n:xl(t,s)},Is=(e,t)=>{if(t===void 0)return!1;const s=e.getBody(),n=s.getDescendantsOfKind(d.CallExpression);return i.isCallExpression(s)&&n.unshift(s),n.some(r=>vl(r,t)&&Sl(r).some(o=>hl.test(o)))},Al=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!gl.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))return;const r=n.getName();if(fl.has(r)){const o=n.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?r.toUpperCase():void 0}s=n.getExpression()}},yl=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=Se(e.getArguments()[0]),l=c&&bs(c,!0);if(!c||l===void 0||Is(c,Ns(c,!0)))return;const u=Ps(c,l);return u===void 0?void 0:{scope:E(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ws(c,l),sideEffect:u}}const n=Al(e);if(n===void 0)return;const r=Se(e.getArguments()[0]),o=r&&bs(r,!1);if(!r||o===void 0||Is(r,Ns(r,!1)))return;const a=Ps(r,o);return a===void 0?void 0:{scope:E(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:ws(r,o),sideEffect:a}},bl=(e,t)=>O(e,t,yl),Nl=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),Pl=new Set(["append","set"]),Rn=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",Cs=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(d.CallExpression)]:e.getDescendantsOfKind(d.CallExpression)).some(n=>Nl.has(b(n.getExpression())??"")&&Re(n,t)),wl=(e,t)=>{if(Cs(e,t))return!0;const s=j(e);return s!==void 0&&Cs(s,t)},At=(e,t)=>ba(e,t)&&!wl(e,t),Il=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=j(e);return t!==void 0&&i.isNewExpression(t)&&b(t.getExpression())==="Headers"},Ke=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=j(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},Mt=(e,t,s)=>{for(const n of e.getProperties())if(i.isPropertyAssignment(n)){const r=n.getInitializer();r!==void 0&&At(r,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:Rn(n.getNameNode()),line:r.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(n)){const r=n.getNameNode();At(r,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:A(n),line:r.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(n)){const r=Ke(n.getExpression());r!==void 0&&Mt(r,t,s)}},Fn=(e,t)=>{const s=Ke(e);if(s===void 0)return;const n=M(s,"headers");if(n===void 0||!i.isPropertyAssignment(n))return;const r=Ke(n.getInitializer());r!==void 0&&Mt(r,"response-init",t)},Cl=(e,t)=>{const s=b(e.getExpression());if(s==="Response")Fn(e.getArguments()[1],t);else if(s==="Headers"){const n=Ke(e.getArguments()[0]);n!==void 0&&Mt(n,"headers-ctor",t)}},Tl=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName(),r=s.getExpression();if(n==="json"&&i.isIdentifier(r)&&r.getText()==="Response"){Fn(e.getArguments()[1],t);return}if(Pl.has(n)&&Il(r)){const o=e.getArguments()[1];o!==void 0&&At(o,t.requestName)&&t.rows.push({scope:t.scope,file:t.relativePath,headerName:Rn(e.getArguments()[0]),line:o.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},Ol=(e,t)=>{for(const s of e.getDescendantsOfKind(d.NewExpression))Cl(s,t);for(const s of e.getDescendantsOfKind(d.CallExpression))Tl(s,t)},kl=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=Se(e.getArguments()[0]);if(n===void 0)return[];const r=n.getParameters()[1];if(r===void 0)return[];const o=r.getNameNode();if(!i.isIdentifier(o))return[];const a=[];return Ol(n,{scope:E(e),relativePath:t,requestName:o.getText(),rows:a}),a},Rl=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression))s.push(...kl(n,t));return s},Fl=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Rl(r,T(t,n)))}return s},Dl=new Set(["auth","context.auth"]),Ll="userId",Ml=e=>{const t=new Set;for(const s of e.getProperties()){if(i.isSpreadAssignment(s))return;(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s))&&t.add(A(s))}return t},_l=(e,t)=>{const s=v(t,En);if(!R(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const r of n.getDescendantsOfKind(d.CallExpression)){if(b(r.getExpression())!=="defineIdentity")continue;const[o]=r.getArguments();return o&&i.isObjectLiteralExpression(o)?Ml(o):void 0}},Ts=e=>{if(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity")return;const t=e.getExpression();return Dl.has(t.getText())||q(t,["auth"])?e:void 0},Kl=e=>{if(i.isPropertyAccessExpression(e)&&Ts(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&Ts(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},Os=(e,t,s)=>{const n=Kl(e);return n===void 0?void 0:{declared:n===Ll||s.has(n),file:t,key:n,line:e.getStartLineNumber(),scope:E(e)}},Bl=(e,t)=>{const s=_l(e,t);return s===void 0?[]:[...de(e,t,d.PropertyAccessExpression,(n,r)=>Os(n,r,s)),...de(e,t,d.ElementAccessExpression,(n,r)=>Os(n,r,s))]},zl=(e,t)=>{if(b(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=C(s,"key");if(!(!n||!W(n)||ne(n)))return{scope:E(e),file:t,line:e.getStartLineNumber()}},$l=(e,t)=>O(e,t,zl),Ul=e=>e.getProperties().some(t=>{if(i.isSpreadAssignment(t))return!0;const s=wr(t.getNameNode());return s===void 0||s==="namespace"}),Vl=(e,t)=>{for(const{filePath:s}of je(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const r of n.getDescendantsOfKind(d.CallExpression)){const o=r.getExpression(),[a]=r.getArguments();if(!(!i.isPropertyAccessExpression(o)||o.getName()!=="auth"||a===void 0)&&(!i.isObjectLiteralExpression(a)||Ul(a)))return r}}},ql="https://lunora.sh/docs/concepts/data-residency#pinning-auth-and-voice",jl=(e,t)=>{if(!(e.jurisdiction===void 0||e.jurisdictionPinsAuth===!0||t===void 0))throw ye(t,`the schema pins Durable Objects to the "${e.jurisdiction}" jurisdiction, and this project also has DO-backed auth (users, sessions, accounts, credentials). Pinning the auth object resolves it to a NEW, EMPTY object: existing users stay in the unpinned one until you copy them across (${ql}). Acknowledge with \`.jurisdiction("${e.jurisdiction}", { pinAuth: true })\`, deploy, then run the copy. For D1-mode auth the acknowledgement changes nothing.`,{code:"JURISDICTION_MOVE",status:422})},Wl=new Set(["delete","get","getRaw","getWithMetadata","put"]),Hl=(e,t,s=[])=>{const n=Ye(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.kv"||r.startsWith("ctx.kv."),methods:Wl});return Tt(n,s)},Gl=new Set(["queue","send"]),ks=new Set(["bcc","cc","to"]),Yl=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Gl.has(t))return;const s=e.getExpression();return q(s,["mail"])||q(s,["email"])?t:void 0},Ql=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return ks.has(A(t))&&W(n)&&!ne(n)}if(!i.isPropertyAssignment(t)||!ks.has(A(t)))return!1;const s=t.getInitializer();return s!==void 0&&W(s)&&!ne(s)}):!1,Xl=(e,t)=>{const s=Yl(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!Ql(n)))return{scope:E(e),file:t,line:e.getStartLineNumber(),method:s}},Jl=(e,t)=>O(e,t,Xl),Zl=e=>i.isPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?i.isComputedPropertyName(e.getNameNode()):!1,ed=e=>i.isPropertyAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?Zl(e):!0,Dn=(e,t=!1)=>{for(const s of e.getProperties()){if(ed(s))return!0;if(t)continue;if(!i.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!i.isObjectLiteralExpression(n)||Dn(n,!0))return!0}return!1},td=(e,t)=>{for(const s of x(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:r}of hn(n))for(const o of Rt(r)){const a=o.getArguments()[0];if(a!==void 0&&(!i.isObjectLiteralExpression(a)||Dn(a)))return!0}}return!1},sd=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const r=_e(n);if(r===void 0||!i.isPropertyAssignment(n))continue;const o=n.getInitializer();if(!(!o||!i.isObjectLiteralExpression(o)))for(const a of o.getProperties()){const c=_e(a);c!==void 0&&s.push({column:c,strategy:mn(a),table:r})}}return s},nd=(e,t)=>{const s=new Map;for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:o}of hn(r))for(const a of Rt(o))for(const c of sd(a)){const l=`${c.table}\0${c.column}`;s.has(l)||s.set(l,c)}}return{columns:[...s.values()]}},rd=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!i.isObjectLiteralExpression(n))return[];const r=[];for(const o of n.getProperties()){const a=_e(o);if(a===void 0||!i.isPropertyAssignment(o))continue;const c=o.getInitializer();if(!(!c||!i.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const u=_e(l);if(u===void 0)continue;const g=mn(l);g!=="custom"&&r.push({column:u,exportName:t,file:s,line:l.getStartLineNumber(),strategy:g,table:a})}}return r},id=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?G(s):void 0;return n?.receiver?Rt(n.receiver).flatMap(r=>rd(r,U(e)??e.getName(),t)):[]},od=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=T(t,n);for(const a of H(r))s.push(...id(a,o))}return s},ad=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return $(s)},cd=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=M(t,"server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},ld=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==d.CallExpression)return;const s=t;return Oi(s.getExpression())?s:void 0},dd=e=>{const t=ld(e),s=t===void 0?void 0:cd(t);if(s===void 0)return[];const n=e.getNameNode(),r=i.isIdentifier(n)?U(e)??n.getText():"";return s.getDescendantsOfKind(d.CallExpression).filter(o=>ad(o)).map(o=>({exportName:r,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},ud=e=>e.getVariableDeclarations().flatMap(t=>dd(t)),fd=(e,t)=>{const s=v(t,Ti);if(!R(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return ud(n)},gd=new Set(["delete","get","patch"]),pd=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),md=new Set(["auth","identity","session","user"]),hd=new Set([d.EqualsEqualsEqualsToken,d.EqualsEqualsToken,d.ExclamationEqualsEqualsToken,d.ExclamationEqualsToken]),vd=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!$(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},Ed=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(i.isAsExpression(s)||i.isParenthesizedExpression(s)||i.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!i.isVariableDeclaration(s))return;const n=s.getNameNode();return i.isIdentifier(n)?n.getText():void 0},xd=(e,t)=>e.getDescendantsOfKind(d.Identifier).some(s=>s.getText()===t),Sd=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(d.ThrowStatement).length>0||e.getDescendantsOfKind(d.ReturnStatement).length>0,Ad=(e,t)=>e.getDescendantsOfKind(d.IfStatement).some(s=>xd(s.getExpression(),t)&&Sd(s.getThenStatement())),yd=(e,t)=>{for(const s of e.getDescendantsOfKind(d.CallExpression)){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))continue;const r=n.getName();if(!gd.has(r))continue;const o=n.getExpression();if(!($(o)||i.isPropertyAccessExpression(o)&&$(o.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&i.isIdentifier(c)&&c.getText()===t)return r}},bd=e=>e.getDescendantsOfKind(d.CallExpression).some(t=>t.getArguments().some(s=>kt(Ot(s))!==void 0)),Nd=e=>e.getDescendantsOfKind(d.BinaryExpression).some(t=>hd.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),Pd=e=>{for(const t of e.getDescendantsOfKind(d.Identifier))if(pd.has(t.getText()))return!0;return[...md].some(t=>He(e,t).length>0)?!0:bd(e)||Nd(e)},wd=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=G(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const r=Tn(s);if(r===void 0)return[];const o=n.receiver!==void 0&&ln(n.receiver,"use","rls"),a=Pd(r),c=new Set,l=[];for(const u of r.getDescendantsOfKind(d.CallExpression)){const g=vd(u);if(g===void 0)continue;const f=Ed(u);if(f===void 0||c.has(f)||!Ad(r,f))continue;const m=yd(r,f);m!==void 0&&(c.add(f),l.push({exportName:U(e)??e.getName(),file:t,line:u.getStartLineNumber(),mentionsOwnership:a,sinkMethod:m,table:g,usesRls:o,visibility:n.visibility}))}return l},Id=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=T(t,n);for(const a of H(r))s.push(...wd(a,o))}return s},Ln=(e,t)=>{const s=i.isIdentifier(e)&&t!==void 0?F(e):void 0;return s===void 0||t===void 0?!1:s.compilerNode===t.compilerNode?i.isIdentifier(t.getNameNode()):i.isBindingElement(s)&&s.getFirstAncestorByKind(d.Parameter)?.compilerNode===t.compilerNode},Cd=e=>{const t=I(e),s=t.getParent();return(i.isPropertyAccessExpression(s)||i.isElementAccessExpression(s))&&s.getExpression()===t&&!We(s)},Td=e=>{const t=I(e).getParent();return i.isVariableDeclaration(t)&&i.isObjectBindingPattern(t.getNameNode())},Od=e=>{const s=I(e).getParent();if(i.isSpreadAssignment(s)||i.isSpreadElement(s)){const n=s.getParent();return(i.isObjectLiteralExpression(n)||i.isArrayLiteralExpression(n))&&!We(n)}return i.isTemplateSpan(s)&&!i.isTaggedTemplateExpression(s.getParent().getParent())},Be=e=>{const t=F(e);return t===void 0||$r(t.getSourceFile())},yt=(e,t)=>{const s=I(e),n=s.getParent();if(!i.isCallExpression(n))return!1;const r=n.getArguments().indexOf(s),o=h(n.getExpression());if(r===-1||o===void 0)return!1;if(i.isIdentifier(o))return o.getText()==="structuredClone"&&Be(o);if(Ln(Ot(o),t))return!(i.isPropertyAccessExpression(o)&&gn.has(o.getName()))||i.isExpressionStatement(I(i.isAwaitExpression(n.getParent())?n.getParentOrThrow():n).getParent());if(!i.isPropertyAccessExpression(o))return!1;const a=o.getExpression();if(!i.isIdentifier(a)||!Be(a))return!1;const c=a.getText(),l=o.getName();switch(c){case"console":return!0;case"JSON":return l==="stringify";case"Object":return["entries","freeze","isFrozen","keys","values"].includes(l)||l==="assign"&&r>0;default:return!1}},Fe={kind:"opaque"},kd={kind:"unreached"},Rd=e=>{const t=e.getSymbol()?.getDeclarations()??[],s=t.filter(o=>i.isFunctionDeclaration(o)&&o.hasBody()),[n]=s;return t.every(o=>i.isFunctionDeclaration(o)&&o.getSourceFile()===e.getSourceFile())&&s.length===1&&i.isFunctionDeclaration(n)?n:void 0},bt=e=>{const t=h(e);if(i.isArrowFunction(t)||i.isFunctionExpression(t))return t;const s=i.isIdentifier(t)?F(t):void 0;if(s?.getSourceFile()!==e.getSourceFile())return;if(i.isFunctionDeclaration(s)){const r=Rd(s);return r===void 0||Ct(r)?void 0:r}const n=ee(s)?h(s.getInitializer()):void 0;return i.isArrowFunction(n)||i.isFunctionExpression(n)?n:void 0},Mn=(e,t,s)=>{const n=t.getArguments(),r=n.indexOf(s),o=r===-1||n.slice(0,r+1).some(l=>i.isSpreadElement(l))||e.getDescendantsOfKind(d.Identifier).some(l=>l.getText()==="arguments"),a=e.getParameters(),c=a[r];return o?Fe:c===void 0?a.some(l=>l.isRestParameter())?Fe:kd:c.isRestParameter()?Fe:{kind:"parameter",parameter:c}},Fd=e=>{const t=I(e),s=t.getParent();if(!i.isCallExpression(s)||s.getExpression()===t)return;const n=bt(s.getExpression());return n===void 0?Fe:Mn(n,s,t)},Dd=new Set(["__defineGetter__","__defineSetter__","__proto__"]),Ld=e=>i.isForInStatement(e)?e.getExpression():i.isConditionalExpression(e)?e.getCondition():i.isElementAccessExpression(e)?e.getArgumentExpression():void 0,_n=e=>{const t=I(e),s=t.getParent();if(i.isIfStatement(s)||i.isWhileStatement(s)||i.isDoStatement(s)||i.isSwitchStatement(s)||i.isCaseClause(s)||i.isTypeOfExpression(s)||i.isVoidExpression(s)||i.isComputedPropertyName(s))return!0;if(i.isTemplateSpan(s))return!i.isTaggedTemplateExpression(s.getParent().getParent());const n=Ld(s);if(n!==void 0)return y(n,t);if(i.isPrefixUnaryExpression(s))return s.getOperatorToken()!==d.PlusPlusToken&&s.getOperatorToken()!==d.MinusMinusToken;if(!i.isBinaryExpression(s))return!1;const r=s.getOperatorToken().getKind(),o=r>=d.FirstAssignment&&r<=d.LastAssignment,a=r===d.QuestionQuestionToken||r===d.BarBarToken||r===d.AmpersandAmpersandToken;return!o&&!a},Md=4,Kn=(e,t,s=0)=>{if(zr(e))return!0;if(Cd(e)){const r=I(e).getParent(),o=i.isElementAccessExpression(r)?r.getArgumentExpression():void 0,a=i.isStringLiteral(o)?o.getLiteralValue():void 0,c=i.isPropertyAccessExpression(r)?r.getName():a;return c===void 0||!Dd.has(c)}if(Td(e)||Od(e)||_n(e)||yt(e,t))return!0;const n=Fd(e);return n?.kind==="unreached"||n?.kind==="parameter"&&_d(n.parameter,s+1)},Rs=new WeakMap,_d=(e,t=0)=>{const s=e.getNameNode();if(!i.isIdentifier(s))return!0;const n=Rs.get(e.compilerNode);if(n!==void 0)return n;if(t>Md)return!1;const o=(s.getSymbol()?.getDeclarations().length??0)===1&&e.getParentOrThrow().getDescendantsOfKind(d.Identifier).every(a=>a===s||a.getText()!==s.getText()||F(a)?.compilerNode!==e.compilerNode||Kn(a,void 0,t));return(o||t===0)&&Rs.set(e.compilerNode,o),o},Fs=new WeakMap,Kd=(e,t)=>{const s=i.isFunctionExpression(e)?e.getNameNode():void 0;if(!i.isArrowFunction(e)&&e.getFirstDescendantByKind(d.ThisKeyword)!==void 0)return!0;const n=new Set([t.getName(),...s===void 0?[]:[s.getText()]]);return e.getDescendantsOfKind(d.Identifier).some(r=>{if(r===s||!n.has(r.getText()))return!1;const o=F(r)?.compilerNode;return o!==void 0&&(o===t.compilerNode||s!==void 0&&o===e.compilerNode)})},Bd=(e,t,s)=>{const{context:n,impl:r}=e,o=Fs.get(r.compilerNode);if(o!==void 0)return o;const a=t.getNameNode(),c=i.isIdentifier(a)?[a]:a.getDescendantsOfKind(d.BindingElement).flatMap(f=>{const m=f.getNameNode();return i.isIdentifier(m)?[m]:[]}),l=new Map(c.map(f=>[f.getText(),f.getParentOrThrow().compilerNode])),u=f=>i.isIdentifier(a)?Kn(f,n):!We(f),g=!Kd(r,s)&&c.every(f=>(f.getSymbol()?.getDeclarations().length??0)===1)&&r.getDescendantsOfKind(d.Identifier).every(f=>{const m=f.getText();if(m==="arguments")return!1;const S=l.get(m);return S===void 0||c.includes(f)||F(f)?.compilerNode!==S?!0:u(f)});return Fs.set(r.compilerNode,g),g},Ds=new WeakMap,zd=e=>{let t=Ds.get(e.compilerNode);return t===void 0&&(t=new Map(e.getVariableDeclarations().flatMap(s=>{const n=ki(s);return n===void 0?[]:[[n.compilerNode,s]]})),Ds.set(e.compilerNode,t)),t},$d=e=>{const t=zd(e.getSourceFile()),s=e.getAncestors().find(l=>t.has(l.compilerNode)),n=s===void 0?void 0:t.get(s.compilerNode);if(s===void 0||n===void 0)return;const[r,o]=s.getParameters(),a=o===void 0||o.isRestParameter()?void 0:o,c={context:r,impl:s,mutatorName:U(n)??n.getName()};return a!==void 0&&Bd(c,a,n)?{...c,parameter:a,pristine:!0}:{...c,parameter:a,pristine:!1}},lt="args",ve=e=>{const t=cn(e);if(t!==void 0){const c=h(t.object);return i.isIdentifier(c)&&c.getText()===lt?t.member:void 0}if(!i.isIdentifier(e))return;const s=F(e);if(!i.isBindingElement(s)||s.getDotDotDotToken()!==void 0)return;const n=s.getParent();if(!i.isObjectBindingPattern(n))return;const r=n.getParent(),o=ee(r)?h(r.getInitializer()):void 0;return i.isBindingElement(r)&&se(r)===lt||i.isIdentifier(o)&&o.getText()===lt?se(s):void 0},Ud=new Set(["auth","identity","user"]),Nt=e=>{const t=r=>{const o=kt(r);return o!==void 0&&o.length>0&&Ud.has(o[0]??"")},s=h(e)??e;if(t(s))return!0;const n=j(s);return n!==void 0&&t(n)},Bn=(e,t=2)=>{const s=new Set;for(const n of[e,...e.getDescendants()]){const r=ve(n);r!==void 0&&s.add(r);const o=t>0&&i.isIdentifier(n)?j(n):void 0;if(o!==void 0)for(const a of Bn(o,t-1))s.add(a)}return s},De=e=>{const t=h(e)??e;if(!i.isBinaryExpression(t))return[];const s=t.getOperatorToken().getKind(),n=t.getLeft(),r=t.getRight();if(s===d.BarBarToken)return[...De(n),...De(r)];if(s===d.AmpersandAmpersandToken){const l=(u,g)=>{const f=ve(h(u)??u);return f===void 0?[]:De(g).filter(m=>m===f)};return[...l(n,r),...l(r,n)]}if(s!==d.ExclamationEqualsEqualsToken&&s!==d.ExclamationEqualsToken)return[];const o=[],a=ve(h(n)??n),c=ve(h(r)??r);return a!==void 0&&Nt(r)&&o.push(a),c!==void 0&&Nt(n)&&o.push(c),o},Vd=e=>{const t=h(e.getExpression())??e.getExpression();return i.isIdentifier(t)?t.getText():i.isPropertyAccessExpression(t)?t.getName():void 0},qd=e=>{if(!Vd(e)?.startsWith("assert"))return[];const t=e.getArguments();return t.flatMap((s,n)=>{const r=ve(h(s)??s),o=t.some((a,c)=>c!==n&&Nt(a));return r!==void 0&&o?[r]:[]})},jd=e=>{if(i.isThrowStatement(e))return!0;if(!i.isBlock(e))return!1;const t=e.getStatements().at(-1);return t!==void 0&&i.isThrowStatement(t)},Wd=e=>i.isArrowFunction(e)||i.isFunctionExpression(e)||i.isFunctionDeclaration(e)||i.isMethodDeclaration(e),Ls=(e,t)=>{for(let s=e.getParent();s!==void 0;s=s.getParent()){if(s===t||s.compilerNode===t.compilerNode)return!0;if(!(i.isBlock(s)||i.isExpressionStatement(s)||i.isAwaitExpression(s)||i.isParenthesizedExpression(s)||i.isVariableStatement(s)||i.isVariableDeclarationList(s)||i.isVariableDeclaration(s)))return!1}return!1},Hd=(e,t)=>{const s=new Set;for(const n of e.getDescendantsOfKind(d.IfStatement))if(n.getEnd()<=t&&Ls(n,e)&&jd(n.getThenStatement()))for(const r of De(n.getExpression()))s.add(r);for(const n of e.getDescendantsOfKind(d.CallExpression))if(n.getEnd()<=t&&Ls(n,e))for(const r of qd(n))s.add(r);return s},Gd=(e,t)=>{const s=Bn(t);if(s.size===0)return!1;const n=e.getFirstAncestor(Wd);if(n===void 0)return!1;const r=Hd(n,e.getStart());return[...s].every(o=>r.has(o))},Yd=new Set(["at","concat","filter","find","findLast","flat","reverse","slice","sort","toReversed","toSorted"]),Qd=new Map([["Array",new Set(["from","of"])],["Object",new Set(["entries","values"])]]),Pt=new Set(["catch","every","filter","finally","find","findIndex","findLast","findLastIndex","flatMap","forEach","map","reduce","reduceRight","some","sort","then"]),zn=e=>e.getNameNode().getDescendantsOfKind(d.BindingElement).filter(t=>i.isIdentifier(t.getNameNode())),Xd=e=>{const t=I(e),s=t.getParent();if(i.isVariableDeclaration(s))return y(s.getInitializer(),t)?s:void 0;const n=i.isForOfStatement(s)&&s.getExpression()===t?s.getInitializer():void 0;return i.isVariableDeclarationList(n)?n.getDeclarations()[0]:void 0},Jd=e=>{const t=Xd(e);return t===void 0?void 0:i.isIdentifier(t.getNameNode())?i.isForOfStatement(t.getParent().getParent())||ee(t)?[t]:void 0:zn(t)},Ee=e=>e.isUnion()?e.getUnionTypes().every(t=>Ee(t)):e.isIntersection()?e.getIntersectionTypes().some(t=>Ee(t)):!e.isAny()&&!e.isUnknown()&&!e.isObject()&&!e.isTypeParameter(),ze=(e,t,s)=>{const n=i.isCallExpression(e)?h(e.getExpression()):void 0;return i.isPropertyAccessExpression(n)&&t.has(n.getName())&&(s===void 0||n.getExpression()===s)},Le=e=>{const t=h(e);if(!i.isArrowFunction(t)&&!i.isFunctionExpression(t))return;const s=t.getBody();return i.isBlock(s)?s.getDescendantsOfKind(d.ReturnStatement).filter(n=>n.getFirstAncestor(r=>i.isFunctionLikeDeclaration(r))===t).map(n=>n.getExpression()):[s]},Zd=e=>{const t=i.isCallExpression(e)?h(e.getExpression()):void 0,s=i.isPropertyAccessExpression(t)?t.getExpression():void 0;return i.isPropertyAccessExpression(t)&&i.isIdentifier(s)&&Qd.get(s.getText())?.has(t.getName())===!0&&Be(s)},eu=e=>{const t=vt(e);if(!i.isArrowFunction(t)&&!i.isFunctionExpression(t))return;const s=I(t),n=s.getParent();return i.isCallExpression(n)&&n.getArguments().includes(s)&&ze(n,pn)?n:void 0},tu=(e,t)=>{if(!(i.isPropertyAccessExpression(e)||i.isElementAccessExpression(e))||e.getExpression()!==t)return;const s=I(e),n=s.getParent();return!i.isCallExpression(n)||n.getExpression()!==s?e:ze(n,Yd,t)?n:void 0},su=(e,t)=>{if(i.isAwaitExpression(e))return e;if(i.isConditionalExpression(e))return e.getCondition()===t?void 0:e;const s=i.isBinaryExpression(e)?e.getOperatorToken().getKind():void 0;return s===d.QuestionQuestionToken||s===d.BarBarToken||s===d.AmpersandAmpersandToken?e:void 0},nu=(e,t)=>{if(i.isArrayLiteralExpression(e))return e;const n=i.isSpreadElement(e)||i.isSpreadAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isPropertyAssignment(e)&&y(e.getInitializer(),t)?e.getParent():void 0;return i.isArrayLiteralExpression(n)||i.isObjectLiteralExpression(n)?n:void 0},Ms=e=>{const t=I(e),s=t.getParent();if(s===void 0)return;const n=i.isCallExpression(s)&&s.getArguments().includes(t)&&Zd(s);return tu(s,t)??su(s,t)??nu(s,t)??(n?s:eu(t))},ru=5e4,$n=()=>({inProgress:new Set,verdicts:new Map});class iu{cuts=0;work=0;reset(){this.work=0}cut(){return this.cuts+=1,!0}spend(){return this.work+=1,this.work>ru&&this.cut()}memoized(t,s,n){const r=n.verdicts.get(t);if(r!==void 0)return r;if(n.inProgress.has(t))return this.cuts+=1,!1;if(this.spend())return!0;const o=this.cuts;n.inProgress.add(t);let a;try{a=s()}finally{n.inProgress.delete(t)}return this.cuts===o&&n.verdicts.set(t,a),a}}const ou=8,au=8;class cu{budget;scope;taint;verdicts=$n();constructor(t,s,n){this.scope=t,this.budget=s,this.taint=n}isCompromised(t){return this.flowHasCompromisingUse(t)&&!Ee(t.getType())}flowHasCompromisingUse(t){return this.budget.memoized(t.compilerNode,()=>{const s=this.budget.cuts,n=[],r=new Set,o=(c,l)=>{r.has(c.compilerNode)||(r.add(c.compilerNode),n.push({binding:c,hops:l}))};let a=!1;o(t,0);for(const c of n)if(a=(c.binding===t?void 0:this.verdicts.verdicts.get(c.binding.compilerNode))??this.visitBinding(c,t,o),a)break;if(!a&&this.budget.cuts===s)for(const c of r)this.verdicts.verdicts.set(c,!1);return a},this.verdicts)}visitBinding({binding:t,hops:s},n,r){const o=t.getNameNode();if(!i.isIdentifier(o)){for(const l of i.isParameterDeclaration(t)?zn(t):[])r(l,s);return!1}if(this.budget.spend())return!0;const a=(l,u)=>u&&s>=ou?this.budget.cut():(r(l,u?s+1:s),!1);return this.taint.referencesTo(t,o.getText()).some(l=>this.valueCompromises(I(l),!0,a,0))&&(t===n||!Ee(t.getType()))}valueCompromises(t,s,n,r){let o=t;for(let m=Ms(o);m!==void 0;m=Ms(o)){if(i.isCallExpression(m)&&this.callbackCompromises(m,n))return!0;o=I(m)}const a=o.getParent(),c=o===t&&s,l=()=>!c&&Ee(o.getType());if(We(o))return!c&&(!i.isBinaryExpression(a)||this.taint.isTaintedValue(a.getRight(),!1));const u=Jd(o);if(u!==void 0)return u.some(m=>n(m,!0));const g=i.isPropertyAccessExpression(a)&&a.getExpression()===o?a.getParent():void 0;if(i.isCallExpression(g)&&g.getExpression()===a)return this.methodCallCompromises(g,n);const f=this.nestedReturningFunctionOf(o);return f!==void 0?this.resultCompromises(f,n,r)&&!l():this.positionCompromises(o,n)&&!l()}resultCompromises(t,s,n){const r=I(t).getParent();if(n>=au)return this.budget.cut();if(i.isCallExpression(r))return r.getExpression()===I(t)?this.valueCompromises(r,!1,s,n+1):!ze(r,Pt);const o=i.isFunctionDeclaration(t)?t:r,a=i.isFunctionDeclaration(o)||ee(o)?o.getNameNode():void 0;return o===void 0||!i.isIdentifier(a)?!0:this.taint.referencesTo(o,a.getText()).some(c=>{const l=I(c),u=l.getParent();return!i.isCallExpression(u)||u.getExpression()!==l||this.valueCompromises(u,!1,s,n+1)})}methodCallCompromises(t,s){return t.getArguments().filter(r=>Le(r)===void 0).some(r=>this.taint.isTaintedValue(r,!1))||this.callbackCompromises(t,s)}callbackCompromises(t,s){const n=ze(t,Pt)?t.getArguments()[0]:void 0;if(n===void 0)return!1;const r=bt(n);return r!==void 0&&this.taint.isInImpl(r)?r.getParameters().some(o=>s(o,!1)):this.taint.isTaintedValue(n,!1)}positionCompromises(t,s){const n=t.getParent();if(i.isCallExpression(n)&&n.getArguments().includes(t))return this.argumentCompromises(n,t,s);const r=i.isSpreadElement(n)?n.getParent():void 0;if(n!==void 0&&i.isCallExpression(r))return!yt(n,this.scope.context)&&this.isOpaqueCallTainted(r.getExpression(),r.getArguments(),n);if(i.isNewExpression(n))return this.isOpaqueCallTainted(n.getExpression(),n.getArguments(),t);if(i.isTemplateSpan(n)){const o=n.getParent(),a=o.getParent(),c=o.getTemplateSpans().map(l=>l.getExpression());return i.isTaggedTemplateExpression(a)&&this.isOpaqueCallTainted(a.getTag(),c,t)}return!this.isReadPosition(t)}argumentCompromises(t,s,n){if(yt(s,this.scope.context))return!1;const r=bt(t.getExpression()),o=r===void 0?void 0:Mn(r,t,s);return o?.kind==="unreached"?!1:o?.kind==="parameter"&&r!==void 0&&this.taint.isInImpl(r)?n(o.parameter,!1):this.isOpaqueCallTainted(t.getExpression(),t.getArguments(),s)}isReadPosition(t){const s=t.getParent();return s===void 0||i.isExpressionStatement(s)||i.isForStatement(s)||i.isElementAccessExpression(s)||_n(t)||y(vt(t),this.scope.impl)}isOpaqueCallTainted(t,s,n){const r=!i.isIdentifier(h(n));return this.taint.isTaintedValue(t,!1)||s.some(o=>(o!==n||r)&&this.taint.isTaintedValue(o,!1))}nestedReturningFunctionOf(t){const s=vt(t);return y(s,this.scope.impl)?void 0:s}}const lu=new Set(["at","every","filter","finally","find","findIndex","findLast","findLastIndex","forEach","order","slice","some","sort","withIndex","withSearchIndex"]),du=e=>{const t=h(e);if(!i.isIdentifier(t))return i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t);const s=F(t),n=i.isVariableDeclaration(s)?h(s.getInitializer()):void 0;return s===void 0||i.isFunctionDeclaration(s)||i.isParameterDeclaration(s)||i.isArrowFunction(n)||i.isFunctionExpression(n)},uu=new Set(["all","allSettled","any","race"]),_s=e=>i.isParameterDeclaration(e)?e:i.isBindingElement(e)?e.getFirstAncestorByKind(d.Parameter):void 0,dt=8;class fu{budget=new iu;referencesByDeclaration=new Map;referencesByName=new Map;scope;verdicts=$n();walk;variableDepth=0;queryDepth=0;constructor(t){this.scope=t,this.walk=new cu(t,this.budget,this);for(const s of t.impl.getDescendantsOfKind(d.Identifier)){const n=s.getText();this.referencesByName.set(n,[...this.referencesByName.get(n)??[],s])}}isTaintedValue(t,s){this.queryDepth===0&&this.budget.reset(),this.queryDepth+=1;try{return s&&this.isRootedInContext(t,dt)?!1:(i.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(r=>Ur(r)&&this.isIdentifierTainted(r))}finally{this.queryDepth-=1}}isInImpl(t){const{impl:s}=this.scope;return t!==s&&s.getPos()<=t.getPos()&&t.getEnd()<=s.getEnd()}referencesTo(t,s){let n=this.referencesByDeclaration.get(s);if(n===void 0){n=new Map;for(const r of this.referencesByName.get(s)??[]){const o=F(r)?.compilerNode;o!==void 0&&n.set(o,[...n.get(o)??[],r])}this.referencesByDeclaration.set(s,n)}return(n.get(t.compilerNode)??[]).filter(r=>r.getParent()!==t)}flowsIntoTainted(t){if([t.getInitializer(),...t.getDescendantsOfKind(d.BindingElement).map(f=>f.getInitializer())].some(f=>f!==void 0&&this.isTaintedValue(f,!1)))return!0;const n=t.getParentOrThrow(),r=i.isFunctionLikeDeclaration(n)?n.getParameters().findIndex(f=>f.compilerNode===t.compilerNode):-1,o=I(n),a=o.getParent();if(r===-1)return!0;if(i.isCallExpression(a)){if(a.getExpression()===o)return this.isCallSiteTainted(a,r,t.isRestParameter());const f=h(a.getExpression());if(!i.isPropertyAccessExpression(f)||!Pt.has(f.getName()))return!0;const m=a.getArguments().filter(S=>S!==o);return this.isTaintedValue(f.getExpression(),!0)||m.some(S=>this.isTaintedValue(S,!1))}const c=i.isVariableDeclaration(a)&&ee(a)?a:void 0,l=i.isFunctionDeclaration(n)?n:c,u=l?.getNameNode();if(l===void 0||!i.isIdentifier(u))return!0;const g=this.referencesTo(l,u.getText());return g.length===0||g.some(f=>{const m=I(f),S=m.getParent();return!i.isCallExpression(S)||S.getExpression()!==m||this.isCallSiteTainted(S,r,t.isRestParameter())})}isCallSiteTainted(t,s,n){const r=t.getArguments(),o=r.findIndex(c=>i.isSpreadElement(c)),a=c=>c===s||n&&c>s||o!==-1&&o<=s&&c>=o;return r.some((c,l)=>a(l)&&this.isTaintedValue(c,!1))}isContextRootedCombinator(t,s){const n=h(t.getExpression()),r=i.isPropertyAccessExpression(n)?n.getExpression():void 0,a=i.isPropertyAccessExpression(n)&&i.isIdentifier(r)&&r.getText()==="Promise"&&Be(r)&&uu.has(n.getName())?h(t.getArguments()[0]):void 0;if(i.isArrayLiteralExpression(a)){const g=a.getElements();return g.length>0&&g.every(f=>!i.isSpreadElement(f)&&this.isRootedInContext(f,s))}const c=i.isCallExpression(a)?h(a.getExpression()):void 0,l=i.isCallExpression(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="map"?h(a.getArguments()[0]):void 0,u=l===void 0?void 0:Le(l);return u!==void 0&&u.length>0&&u.every(g=>g!==void 0&&this.isRootedInContext(g,s))}isIdentifierTainted(t){const s=t.getText();if(s==="arguments")return!0;const n=F(t),r=_s(n);if(r!==void 0)return this.isSource(r);if(s==="args")return!0;if(n===void 0||!this.isInImpl(n))return!1;if(i.isFunctionDeclaration(n))return this.budget.memoized(n.compilerNode,()=>this.isTaintedValue(n,!1),this.verdicts);if(i.isBindingElement(n)&&this.walk.isCompromised(n))return!0;const o=i.isBindingElement(n)?n.getFirstAncestorByKind(d.VariableDeclaration):n;return i.isVariableDeclaration(o)&&this.isVariableTainted(o)}callChainVerdict(t,s){if(this.isContextRootedCombinator(t,s))return!0;const n=h(t.getExpression()),r=i.isPropertyAccessExpression(n)?n.getName():void 0;return r!==void 0&&gn.has(r)?!1:r!==void 0&&pn.has(r)?this.isCallbackResultServerScoped(t,s)?void 0:!1:t.getArguments().some(a=>Le(a)!==void 0)&&(r===void 0||!lu.has(r))?!1:void 0}isCallbackResultServerScoped(t,s){const n=(r,o=[])=>{const a=Ot(r),c=i.isIdentifier(a)?_s(F(a)):void 0;return c!==void 0&&o.includes(c)?!0:this.isRootedInContext(r,s)||!this.isTaintedValue(r,!1)};return t.getArguments().every(r=>{const o=Le(r);if(o===void 0)return!du(r)&&n(r);const a=h(r),c=i.isArrowFunction(a)||i.isFunctionExpression(a)?a.getParameters():[];return o.every(l=>l===void 0||n(l,c))})}isRootedInContext(t,s){const n=Yr(t,u=>this.callChainVerdict(u,s)),r=n.root;if(n.verdict!==void 0)return n.verdict;if(Ln(r,this.scope.context))return!0;const o=i.isIdentifier(r)?F(r):void 0,a=i.isBindingElement(o)?o.getFirstAncestorByKind(d.VariableDeclaration):o,c=ee(a)&&this.isInImpl(a)?a.getInitializer():void 0,l=i.isBindingElement(o)?o:a;return s>0&&c!==void 0&&(i.isBindingElement(l)||i.isVariableDeclaration(l))&&!this.walk.isCompromised(l)&&this.isRootedInContext(c,s-1)}isSource(t){const{impl:s,parameter:n}=this.scope;return t.compilerNode===n?.compilerNode?!0:t.getParent()!==s&&this.isInImpl(t)&&(this.budget.memoized(t.compilerNode,()=>this.flowsIntoTainted(t),this.verdicts)||this.walk.isCompromised(t))}isVariableTainted(t){return this.budget.memoized(t.compilerNode,()=>{const s=t.getParent().getParent();if(i.isCatchClause(t.getParent())||this.walk.isCompromised(t))return!0;if(i.isForOfStatement(s)||i.isForInStatement(s))return this.isTaintedValue(s.getExpression(),!0);const n=t.getInitializer(),r=Ct(t);if(n===void 0||r)return!0;if(this.isRootedInContext(n,dt))return!1;if(this.variableDepth>=dt)return this.budget.cut();this.variableDepth+=1;try{return this.isTaintedValue(n,!1)}finally{this.variableDepth-=1}},this.verdicts)}}const Ks=new WeakMap,gu=e=>{const t=Ks.get(e.impl.compilerNode);if(t!==void 0)return t;const s=new fu(e);return Ks.set(e.impl.compilerNode,s),s},pu=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),mu=new Set(["insert","insertManyUnsafe","patch","replace"]),hu=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();return mu.has(t)&&fi(e.getExpression())?t:void 0},vu=(e,t)=>{if(t!=="insertManyUnsafe")return i.isObjectLiteralExpression(e)?[e]:[];if(!i.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())i.isObjectLiteralExpression(n)&&s.push(n);return s},Eu=(e,t)=>{const s=cn(e);return s?.member===t?h(s.object):void 0},Bs=(e,t)=>i.isIdentifier(e)&&F(e)?.compilerNode===t.compilerNode,Un=(e,t,s,n=1)=>{const r=Eu(e,s);if(r!==void 0)return Bs(r,t);const o=i.isIdentifier(e)?F(e):void 0;if(i.isBindingElement(o)){const c=o.getParent(),l=c.getParent();return o.getDotDotDotToken()===void 0&&se(o)===s&&i.isObjectBindingPattern(c)&&(l.compilerNode===t.compilerNode||ee(l)&&Bs(h(l.getInitializer()),t))}const a=ee(o)?o.getInitializer():void 0;return n>0&&a!==void 0&&Un(a,t,s,n-1)},wt=e=>{const t=h(e)??e;return i.isConditionalExpression(t)?[...wt(t.getWhenTrue()),...wt(t.getWhenFalse())]:[t]},xu=(e,t,s)=>{const n=[],r=s===void 0?void 0:gu(s);for(const o of e.getProperties()){let a,c;if(i.isPropertyAssignment(o)?(a=A(o),c=o.getInitializer()):i.isShorthandPropertyAssignment(o)&&(a=A(o),c=o.getNameNode()),a===void 0||c===void 0||!pu.has(a))continue;const l=wt(c).filter(g=>r===void 0?W(g)&&!gi(g):r.isTaintedValue(g,!0));if(l.length>0){const g=t.ownerField===a&&s?.pristine===!0&&Un(c,s.parameter,a),f=l.every(m=>Gd(t.call,m));n.push({field:a,file:t.relativePath,line:t.call.getStartLineNumber(),method:t.method,scope:t.scope,...g&&{ownerScoped:!0},...f&&{guarded:!0}})}}return n},Su=(e,t,s)=>{const n=hu(e.getExpression()),r=n===void 0?void 0:e.getArguments()[1];if(n===void 0||r===void 0)return[];const o=vu(r,n);if(o.length===0)return[];const a=E(e),c=$d(e),l={call:e,method:n,ownerField:c===void 0?void 0:s(c.mutatorName),relativePath:t,scope:a};return o.flatMap(u=>xu(u,l,c))},Au=(e,t,s=[],n=[])=>{const r=new Map(n.map(a=>[`${a.filePath}:${a.exportName}`,a.owner])),o=O(e,t,(a,c)=>Su(a,c,l=>r.get(`${c}:${l}`)));return Tt(o,s)},yu=["providerSubscriptionId","state"],bu=["providerEventId","processedAt"],zs=(e,t)=>t.every(s=>s in e.shape),Nu=e=>{const t=e.find(n=>n.name==="payment_subscriptions"),s=e.find(n=>n.name==="payment_events");return t!==void 0&&s!==void 0&&zs(t,yu)&&zs(s,bu)},Pu=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),wu=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Iu=e=>{const t=M(e,"webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?wu(t.getInitializer()):void 0},Cu=(e,t)=>{const s=b(e.getExpression());if(s===void 0||!Pu.has(s))return;const[n]=e.getArguments(),r=n&&i.isObjectLiteralExpression(n)?Iu(n):void 0;return{callee:s,scope:E(e),file:t,line:e.getStartLineNumber(),...r===void 0?{}:{toleranceSeconds:r}}},Tu=(e,t)=>O(e,t,Cu),Ou=new Map([["defineQueue",0],["defineSubscription",1],["defineWorkflow",0]]),ku=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},Ru=(e,t)=>{const s=e.getArguments()[t];if(!s||!i.isObjectLiteralExpression(s))return;const n=M(s,"handler");if(n===void 0||!i.isPropertyAssignment(n))return;const r=n.getInitializer();if(r&&(i.isArrowFunction(r)||i.isFunctionExpression(r)))return r},Vn=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},qn=(e,t)=>e===t||e.startsWith(`${t}.`),jn=e=>{const t=e.getDescendantsOfKind(d.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},$s=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e||i.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(i.isBindingElement(t)&&t.getNameNode()===e)},Wn=e=>{const t=e.getDescendantsOfKind(d.Identifier).filter(s=>$s(s));return i.isIdentifier(e)&&$s(e)&&t.push(e),t},Fu=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(d.BindingElement).map(s=>s.getName())},Du=e=>{const t=Vn(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(d.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const r=n.getInitializer(),o=i.isVariableDeclarationList(r)?r.getDeclarations()[0]?.getNameNode():void 0;o&&i.isIdentifier(o)&&s.push(`${o.getText()}.body`)}return s},Lu=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:Du(e),r=new Set,o=a=>jn(a).some(c=>n.some(l=>qn(c.getText(),l)))?!0:Wn(a).some(c=>r.has(c.getText()));for(const a of e.getDescendantsOfKind(d.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of Fu(a))r.add(l)}return{names:r,prefixes:n}},Mu=(e,t)=>jn(e).some(s=>t.prefixes.some(n=>qn(s.getText(),n)))?!0:Wn(e).some(s=>t.names.has(s.getText())),_u=e=>{const t=Qr(e);return t===void 0?void 0:{exportName:String(t.at(-1)),file:t.slice(0,-1).join("/")}},Ku=(e,t,s)=>{const n=Vn(e,0);if(n===void 0)return[];const r=Lu(e,t,n),o=new Set([n,...r.prefixes.filter(c=>c.endsWith(".body")).map(c=>c.slice(0,-5))]),a=[];for(const c of e.getDescendantsOfKind(d.CallExpression)){const l=c.getExpression();if(!i.isPropertyAccessExpression(l)||!nn.has(l.getName())||!o.has(l.getExpression().getText()))continue;const u=c.getArguments()[1];if(!u||!Mu(u,r))continue;const g=_u(c.getArguments()[0]);g!==void 0&&a.push({dispatchKind:t,file:s,scope:E(c),line:c.getStartLineNumber(),targetExport:g.exportName,targetFile:g.file})}return a},Bu=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=ku(n),o=r===void 0?void 0:Ou.get(r);if(o===void 0)continue;const a=Ru(n,o);a!==void 0&&s.push(...Ku(a,r==="defineWorkflow"?"workflow":"queue",t))}return s},zu=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Bu(r,T(t,n)))}return s},Us={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},Vs=new Set(["account","credential","member","passkey","session","user"]),$u=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),Uu=e=>{const s=$u(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return Vs.has(s)||Vs.has(n)},Vu=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},qu=(e,t)=>{const{objects:s,opaque:n}=Dt(e,t);return Va(s).some(r=>Vu(r))?!0:n?void 0:!1},ju=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!M(t,"captcha"),usesRateLimit:!!M(t,"rateLimit")}},Wu=e=>{if(i.isCallExpression(e))return e;if(!i.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&i.isCallExpression(s)?s:void 0},Me={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Hu=e=>{const t=Wu(e),s=t?b(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=ju(t);return{...Me,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in Us?{...Me,[Us[s]]:!0}:Me},Gu=e=>{const t={...Me};let s=e;for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))break;const r=n.getName()==="use"?s.getArguments()[0]:void 0;if(r){const o=Hu(r);t.usesCaptcha||=o.usesCaptcha,t.usesEmailGate||=o.usesEmailGate,t.usesMask||=o.usesMask,t.usesRateLimit||=o.usesRateLimit,t.usesRls||=o.usesRls}s=n.getExpression()}return t},Yu=new Set(["insert","insertMany","insertManyUnsafe","replace"]),Qu=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Yu.has(t.getName()))return!1;const s=t.getExpression();if(!$(s))return!1;const r=e.getArguments()[0];return!r||!(i.isStringLiteral(r)||i.isNoSubstitutionTemplateLiteral(r))?!1:Uu(r.getLiteralText())},Xu=new Set(["create","publish","publishBatch","runAfter","runAt","send","sendBatch"]),qs=new Set(["queues","scheduler","topics","workflows"]),Ju=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Xu.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&qs.has(s.getName())&&pi(s.getExpression()))return!0;s=s.getExpression()}const n=kt(s);return n?.length===1&&qs.has(n[0]??"")},Zu=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return $(s)},Hn=new Set(["generateObject","generateText","streamObject","streamText"]),ef=e=>{const t=b(e.getExpression());return t!==void 0&&Hn.has(t)},tf=e=>{const t=b(e.getExpression());if(t===void 0||!Hn.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(n=>i.isSpreadAssignment(n))?!1:!M(s,"maxOutputTokens")},sf=new Set(["log","span","trace"]),nf=new Set(["ai"]),rf=new Set(["email","mail"]),of=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","topics","workflows"]),ut=(e,t)=>[...t].some(s=>He(e,s).length>0),Gn=new Set([d.ArrowFunction,d.FunctionDeclaration,d.FunctionExpression,d.GetAccessor,d.MethodDeclaration,d.SetAccessor]),af=new Set(["every","filter","flatMap","forEach","map","some"]),cf=new Set(["all","allSettled","race"]),Yn=e=>{const t=e.getParent();if(!t||!i.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName();if(af.has(n))return t;const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="Promise"&&cf.has(n))return t},lf=e=>{let t=e.getParent();for(;t;){if(i.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(Gn.has(t.getKind())){const s=Yn(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},df=e=>{let t=e.getParent();for(;t!==void 0;){if(i.isCallExpression(t)&&t.getExpression().getText()==="Promise.allSettled")return!0;if(Gn.has(t.getKind())){if(t=Yn(t),t===void 0)return!1;continue}t=t.getParent()}return!1},uf=e=>{const t=e.getFirstAncestor(u=>i.isArrowFunction(u)||i.isFunctionExpression(u)),s=t?.getParent();if(!t||!i.isCallExpression(s)||!s.getArguments().includes(t))return!1;const n=s.getExpression();if(!i.isIdentifier(n))return!1;const r=n.getSymbol(),o=r?.getAliasedSymbol()?.getValueDeclaration()??r?.getValueDeclaration(),a=i.isVariableDeclaration(o)?o.getInitializer():o;if(!i.isArrowFunction(a)&&!i.isFunctionExpression(a)&&!i.isFunctionDeclaration(a))return!1;const c=s.getArguments().indexOf(t),l=a.getParameters()[c]?.getName();return l===void 0?!1:a.getDescendantsOfKind(d.TryStatement).some(u=>{const g=u.getTryBlock().getDescendantsOfKind(d.CallExpression).some(m=>{const S=m.getExpression();return i.isIdentifier(S)&&S.getText()===l&&i.isAwaitExpression(m.getParent())}),f=u.getCatchClause();return g&&f!==void 0&&f.getDescendantsOfKind(d.ThrowStatement).length>0})},ff=e=>{let t=e;for(;;){const s=t.getParent();if(!i.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;if(s.getName()==="catch")return!0;if(s.getName()!=="then"&&s.getName()!=="finally")return!1;const n=s.getParent();if(!i.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},gf=e=>{let t=e;for(;;){const s=t.getParent();if(i.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return i.isCallExpression(s)&&s.getExpression()===t?s:void 0}},pf=e=>{let t=!1,s=!0;for(const n of[...of].flatMap(r=>He(e,r))){const r=gf(n);r&&(t=!0,!lf(r)&&!ff(r)&&!uf(r)&&!df(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},mf=e=>e.getDescendantsOfKind(d.ThrowStatement).some(t=>{const s=t.getExpression();if(!i.isNewExpression(s))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="Error"}),js="lunora-advisor-exempt",hf=/^[\s*/]+/u,vf=/[\w-]/u,Ef=e=>{const s=(e.getFirstAncestorByKind(d.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
|
|
7
7
|
`);for(const n of s.split(`
|
|
8
|
-
`)){const r=n.replace(pf,"");if(!r.startsWith(js))continue;const o=r.slice(js.length);if(mf.test(o.charAt(0)))continue;const a=o.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":o.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},vf=e=>{const[t]=e.getArguments();if(t){if(i.isObjectLiteralExpression(t)){const s=M(t,"handler");return s?i.isPropertyAssignment(s)?s.getInitializer():i.isShorthandPropertyAssignment(s)?s.getNameNode():i.isMethodDeclaration(s)?s:void 0:void 0}return t}},Ef=(e,t)=>{const s=vf(t);if(!s)return;if(i.isArrowFunction(s)||i.isFunctionExpression(s)||i.isMethodDeclaration(s))return e;if(!i.isIdentifier(s))return;const n=s.getSourceFile(),r=s.getText(),o=n.getVariableDeclaration(r)?.getInitializer();return o&&(i.isArrowFunction(o)||i.isFunctionExpression(o))?o:n.getFunction(r)},xf=e=>{let t=!1,s=!1,n=!1,r=!1,o=!1;for(const l of e.getDescendantsOfKind(d.CallExpression))if(Gu(l)&&(o=!0),Qu(l)&&(t=!0),Xu(l)&&(r=!0),Ju(l)&&(s=!0),Zu(l)&&(n=!0),o&&t&&r&&n)break;const{handlesErrors:a,reachesOutbound:c}=ff(e);return{callsMail:ut(e,sf),emitsEvent:ut(e,ef),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||ut(e,tf),throwsBareError:gf(e),unboundedAiGeneration:n,usesInsertManyUnsafe:r,writesUserTable:o}},Sf=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=G(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const r=n.receiver?Wu(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},o=Ef(e,s);return{...o?xf(o):{},...hf(e),...r,analyzableBody:o!==void 0,exportName:U(e)??e.getName(),file:t,hasEmailArg:Uu(s,n.receiver),kind:n.kind,visibility:n.visibility}},Af=(e,t)=>{const s=[];for(const n of H(e)){const r=Sf(n,t);r&&s.push(r)}return s},yf=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Af(r,T(t,n)))}return s},bf=new Set(["dbRateLimit","rateLimit"]),Nf=e=>i.isArrowFunction(e)?e.getBody():e,Pf=e=>{if(!i.isArrowFunction(e))return;const t=e.getParameters()[0]?.getNameNode();return t!==void 0&&i.isIdentifier(t)?t:void 0},Gn=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getExpression()===e&&t.getName()==="args"},Yn=(e,t)=>{const s=t.getSymbol();return s===void 0?[]:e.getDescendantsOfKind(d.Identifier).filter(n=>{if(n.getSymbol()!==s)return!1;const r=n.getParent();return!(i.isPropertyAccessExpression(r)&&r.getNameNode()===n)})},wf=(e,t)=>W(e)||t!==void 0&&Yn(e,t).some(s=>Gn(s)),If=(e,t)=>t===void 0?ne(e):Yn(e,t).some(s=>!Gn(s)),Cf=(e,t)=>{const s=y(e.getExpression());if(s===void 0||!bf.has(s))return;const n=C(an(e.getArguments()[2]),"key");if(!n)return;const r=Nf(n),o=Pf(n);if(!(!wf(r,o)||If(r,o)))return{callee:s,scope:E(e),file:t,limitName:on(e),line:e.getStartLineNumber()}},Tf=(e,t)=>O(e,t,Cf),Of=new Set(["findFirst","findFirstOrThrow","findMany","findUnique","get"]),kf=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Of.has(t.getName()))return;const s=t.getExpression();if($(s)){const n=e.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&$(s.getExpression()))return s.getName()},Rf=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&$(s.getExpression())){const n=t.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},Ff=e=>{let t=h(e)??e;for(;i.isAwaitExpression(t);)t=h(t.getExpression())??t.getExpression();return t},Qn=(e,t=!1)=>{const s=Ff(e);if(i.isIdentifier(s)){if(t)return;const n=j(s);return n===void 0?void 0:Qn(n,!0)}if(i.isCallExpression(s))return kf(s)??Rf(s)},Df=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(d.ReturnStatement)){const r=n.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),o=n.getExpression();r===e&&o!==void 0&&s.push(o)}return s},Lf=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=G(s);if(n?.kind!=="query")return[];const r=Tn(s);if(r===void 0)return[];const o=n.receiver!==void 0&&ei(n.receiver,"output"),a=n.receiver!==void 0&&ln(n.receiver,"use","mask"),c=new Set,l=[];for(const u of Df(r)){const g=Qn(u);g===void 0||c.has(g)||(c.add(g),l.push({exportName:U(e)??e.getName(),file:t,line:u.getStartLineNumber(),table:g,usesMask:a,usesOutput:o,visibility:n.visibility}))}return l},Mf=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=T(t,n);for(const a of H(r))s.push(...Lf(a,o))}return s},_f=e=>{if(!e||!i.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s)||i.isGetAccessorDeclaration(s))&&t.push(S(s));return t},Kf=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?G(s):void 0;if(!n)return[];const r=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=vn(o);if(a===void 0)continue;const c=_f(C(a.options,"with"));c.length!==0&&r.push({exportName:U(e)??e.getName(),file:t,line:o.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return r},Bf=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=T(t,n);for(const a of H(r))s.push(...Kf(a,o))}return s},$e=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===d.PlusToken){const t=$e(e.getLeft()),s=$e(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},zf=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===d.PlusToken;)t=s,s=t.getParent();return t!==e&&$e(t)!==void 0},$f=e=>{const t=e.getParent();if(t!==void 0){if(i.isVariableDeclaration(t)||i.isPropertyAssignment(t)||i.isPropertySignature(t))return S(t);if(i.isBinaryExpression(t)&&t.getOperatorToken().getKind()===d.EqualsToken)return t.getLeft().getText()}},Uf=(e,t,s)=>$i(e)?!Yr(s)&&Ui($f(t)):!0,Vf=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(d.BinaryExpression),...e.getDescendantsOfKind(d.StringLiteral),...e.getDescendantsOfKind(d.NoSubstitutionTemplateLiteral)],r=new Set;for(const o of n){if(zf(o))continue;const a=$e(o);if(a===void 0)continue;const c=Bi(a);if(c===void 0||!Uf(c,o,t))continue;const l=o.getStartLineNumber(),u=`${String(l)}:${c}`;r.has(u)||(r.add(u),s.push({file:t,kind:c,line:l,preview:zi(a)}))}return s},qf=(e,t)=>{const s=[];for(const n of x(t,{includeSkipped:!0})){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Vf(r,T(t,n)))}return s},jf=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?G(s):void 0;if(!n)return[];const r=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=vn(o);if(a===void 0)continue;const c=C(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),u=!l&&W(c);!l&&!u||r.push({exportName:U(e)??e.getName(),file:t,fromArgs:u,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:n.visibility})}return r},Wf=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=T(t,n);for(const a of H(r))s.push(...jf(a,o))}return s},Hf=new Set(["query","unsafe"]),Gf=e=>!i.isPropertyAccessExpression(e)||!Hf.has(e.getName())?!1:q(e.getExpression(),["sql"]),Yf=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),Qf=(e,t)=>{if(!Gf(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Yf(s)))return{file:t,line:s.getStartLineNumber(),scope:E(e)}},Xf=(e,t)=>O(e,t,Qf),Jf=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],Zf=e=>{for(const[t,s]of Jf)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},eg=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of r.getImportDeclarations()){const a=o.getModuleSpecifierValue(),c=Zf(a);c!==void 0&&s.push({file:T(t,n),line:o.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},tg=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),sg=(e,t,s=[])=>{const n=Ye(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:tg,requireUnmodifiedReach:!0});return Tt(n,s)},ng=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),rg=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,ig=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!i.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const r of e.getProperties()){if(i.isSpreadAssignment(r)){n=!0;continue}if(i.isPropertyAssignment(r)){const o=S(r);t.push(o),o==="expiresInSeconds"&&(s=rg(r.getInitializer()));continue}(i.isShorthandPropertyAssignment(r)||i.isMethodDeclaration(r))&&t.push(S(r))}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},og=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=ng.get(t);return s===void 0?void 0:fn(e.getExpression(),r=>r==="ctx.storage"||r.startsWith("ctx.storage."))?{method:t,optionsIndex:s}:void 0},ag=(e,t)=>{const s=og(e.getExpression());if(s!==void 0)return{scope:E(e),file:t,line:e.getStartLineNumber(),method:s.method,...ig(e.getArguments()[s.optionsIndex])}},cg=(e,t)=>O(e,t,ag),lg=(e,t)=>{const s=ri(t.target);return{...s===void 0?{}:{platform:s},analytics:e.analytics||t.dependencies.has("@lunora/bindings"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:t.vectorStoreSupported&&t.vectorIndexCount>0,workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}},dg=new Set(["delete","hardDelete","patch","replace","restore"]),ug=new Set(["insertMany","insertManyUnsafe","patchWhere"]),fg=new Set(["delete","deleteMany","hardDelete","insert","insertMany","patch","patchMany","replace","restore","upsert","upsertMany"]),Ws=(e,t)=>{const s=e.getNonNullableType().getProperty("__table")?.getTypeAtLocation(t);if(s===void 0)return[];const n=s.isUnion()?s.getUnionTypes():[s],r=n.map(o=>o.getLiteralValue()).filter(o=>typeof o=="string");return r.length===n.length?r:[]},gg=(e,t)=>{const s=e.getType();if(t==="deleteMany"||t==="patchMany"){const n=s.getArrayElementType();if(n===void 0)return[];const r=t==="patchMany"?n.getProperty("id")?.getTypeAtLocation(e):n;return r===void 0?[]:Ws(r,e)}return Ws(s,e)},Hs="",pg=(e,t)=>{if(ug.has(e))return{method:e,tables:[t!==void 0&&i.isStringLiteral(t)?t.getLiteralText():Hs]};if(dg.has(e)||e==="deleteMany"||e==="patchMany"){const s=t===void 0?[]:gg(t,e);return{method:e,tables:s.length===0?[Hs]:s}}},mg=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression();if($(n))return pg(s,e.getArguments()[0]);if(fg.has(s)&&i.isPropertyAccessExpression(n)&&$(n.getExpression()))return{method:s,tables:[n.getName()]}},hg=(e,t)=>O(e,t,(s,n)=>{const r=mg(s);if(r===void 0)return;const o=E(s),a=s.getStartLineNumber();return r.tables.map(c=>({file:n,line:a,method:r.method,scope:o,table:c}))}),vg=e=>{const t=i.isCallExpression(e)?e.getExpression():void 0;return i.isPropertyAccessExpression(t)&&t.getName()==="throwIfAborted"},Eg=e=>Pn(e).some(t=>Nn(t,e)||i.isBreakStatement(t)&&A(bn(t),e))||e.getDescendantsOfKind(d.CallExpression).some(t=>vg(t)&&Lt(t,e)),xg=e=>e.getDescendantsOfKind(d.YieldExpression).some(t=>Lt(t,e)),Sg=e=>i.isDoStatement(e)||i.isWhileStatement(e)?e.getExpression():e.getCondition(),Ag=e=>i.isDoStatement(e)?"do":i.isWhileStatement(e)?"while":"for",ft=(e,t)=>{const s=Sg(e);if(!(s===void 0||i.isTrueLiteral(h(s)))||Eg(e)||xg(e))return;const r=E(e);if(!(r.kind==="module"&&e.getFirstAncestor(Z)!==void 0))return{file:t,kind:Ag(e),line:e.getStartLineNumber(),scope:r}},yg=(e,t)=>[...de(e,t,d.WhileStatement,ft),...de(e,t,d.ForStatement,ft),...de(e,t,d.DoStatement,ft)].toSorted((s,n)=>s.file.localeCompare(n.file)||s.line-n.line),bg=(e,t,s)=>({cacheKey:`procedure_arguments_unreadable:${e}:${t}`,categories:["SCHEMA"],description:"Codegen reads an argument record statically. One built at runtime — a factory call, or a property off a value it cannot follow — has no literal to read, so the generated `FunctionReference` carries only the arguments it could see while the runtime validator still enforces all of them.",detail:`\`${t}\` in \`${e}\` (line ${s.toString()}) declares arguments codegen could not read, so its generated type is missing some of them.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:s},name:"procedure_arguments_unreadable",remediation:`Declare the arguments as an object literal, or as a \`const\` object literal the chain names — \`const ${t}Args = { … };\` then \`.input(${t}Args)\`. Both resolve; a record returned by a call does not.`,title:"Procedure arguments are missing from the generated type"}),Ng=(e,t)=>{if(t===void 0){const s=e.getArguments()[0];if(s===void 0||!i.isObjectLiteralExpression(s)||M(s,"args")===void 0)return!1}return Dt(e,t).opaque},Pg=(e,t)=>{const s=[],n=(r,o)=>{const a=r.getInitializer();if(a===void 0||!i.isCallExpression(a))return;const c=G(a);c!==void 0&&Ng(a,c.receiver)&&s.push(bg(t,o,a.getStartLineNumber()))};for(const r of e.getVariableStatements().filter(o=>o.isExported()))for(const o of r.getDeclarations())n(o,o.getName());return s},wg=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n);r!==void 0&&s.push(...Pg(r,T(t,n)))}return s.toSorted((n,r)=>n.cacheKey.localeCompare(r.cacheKey))},Ig=new Map([["AgentDefinition",{call:"defineAgent({ … })",file:"agents"}],["ContainerDefinition",{call:"defineContainer({ … })",file:"containers"}],["QueueDefinition",{call:"defineQueue({ … })",file:"queues",note:"A dropped queue has no caller to fail — its consumer is simply never wired."}],["RegisteredAction",{call:"action.input({ … }).action(handler)"}],["RegisteredLifecycleHook",{call:"onConnect(handler)",note:"Substitute the hook you called: `onConnect`, `onDisconnect` and `onShardInit` share one type, so codegen cannot tell which you wrote. A dropped hook has no caller to fail — it silently never fires."}],["RegisteredMigration",{call:"defineMigration({ … })",note:"A dropped migration never runs, so `lunora migrate up` reports nothing to do."}],["RegisteredMutation",{call:"mutation.input({ … }).mutation(handler)"}],["RegisteredMutator",{call:"defineMutator({ … })",file:"mutators"}],["RegisteredQuery",{call:"query.input({ … }).query(handler)"}],["RegisteredReactor",{call:"onQueryChange(select, handler)",note:"A dropped reactor has no caller to fail — it silently never runs."}],["RegisteredShape",{call:"defineShape({ … })",file:"shapes"}],["RegisteredStream",{call:"query.input({ … }).stream(handler)"}],["RegisteredWhisperAuthorizer",{call:"onWhisper(handler)",note:"A dropped authorizer has no caller to fail — the whisper topics it was meant to gate silently stay open to every socket on the shard."}],["SubscriptionDefinition",{call:"defineSubscription(topic, { … })",file:"queues",note:"A dropped subscription is never published to — its topic's messages simply never reach it."}],["WorkflowDefinition",{call:"defineWorkflow({ … })",file:"workflows"}]]),Ue=({byName:e,byPath:t},s,n)=>t.has(`${s}:${n}`)||e.has(n),Xn=e=>!e.isAny(),Jn=e=>{const t=e.getType();if(!Xn(t))return;const s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName(),n=s===void 0?void 0:Ig.get(s);return n===void 0||s===void 0?void 0:{...n,typeName:s}},Cg=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},Zn={cause:"codegen recognises a registration only when the initializer is the registering call itself, and this one comes from a factory or an alias",remediation:"A factory that returns a registration cannot be read statically — inline it, or export what the factory builds."},Tg=e=>({cause:`codegen reads this kind of registration only from \`lunora/${e}.ts\`, and this is a different module`,remediation:`Move it into \`lunora/${e}.ts\` — the declaration itself is fine.`}),Og={cause:"it is exported only under a string name that is not an identifier, which the generated `api.ts` and dispatch table cannot address as `<module>.<name>`",remediation:"Export it under an identifier name as well (or instead)."},kg=new Set(["AgentDefinition","ContainerDefinition","QueueDefinition","RegisteredShape","SubscriptionDefinition","WorkflowDefinition"]),Rg={cause:"it is exported only as `default` or under a reserved word, and this kind's name becomes an import binding and a generated class / binding name, where that is a syntax error",remediation:"Export it under a plain identifier: `export const <name> = …` (an extra `export default <name>` is fine)."},Fg=(e,t,s)=>{if(!t.some(r=>$r(r)))return Og;const n=e.getVariableStatement()?.hasExportKeyword()===!0;return kg.has(s.typeName)&&!n&&!t.some(r=>qi(r))?Rg:Zn},er=(e,t,s,n,r)=>{const{call:o,file:a,note:c,typeName:l}=s,u=a!==void 0&&e!==a?a:void 0,g=u===void 0?r:Tg(u),f=c===void 0?g.remediation:`${c} ${g.remediation}`;return{cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when its initializer is literally the registering call and the module exports it under an identifier name — by the `export` keyword, a local `export { … }`, or `export default`. Written any other way it exists at runtime but never reaches the generated output — `_generated/api.ts` for a procedure, the lifecycle manifest for a hook or reactor — so a caller cannot address it and a hook never fires.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${l}\` but was not registered — ${g.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:l},name:"procedure_not_registered",remediation:u===void 0?`Assign the registration directly: \`export const ${t} = ${o};\`. ${f}`:f,title:"Procedure exists at runtime but is missing from the generated API"}},Dg=(e,t,s)=>{const n=[];for(const r of H(e)){const o=i.isIdentifier(r.getNameNode())?ht(r):[r.getName()],c=o.some(u=>Ue(s,t,u))||!Cg(r)?void 0:Jn(r),[l=r.getName()]=o;c!==void 0&&n.push(er(t,l,c,r.getStartLineNumber(),Fg(r,o,c)))}return n},Lg=(e,t,s)=>{if(Ue(s,t,"default"))return[];const n=[];for(const r of e.getExportAssignments().filter(o=>!o.isExportEquals()&&!i.isIdentifier(o.getExpression()))){const o=Jn(r.getExpression());o!==void 0&&n.push(er(t,"default",o,r.getStartLineNumber(),Zn))}return n},Mg=(e,t,s)=>[...Dg(e,t,s),...Lg(e,t,s)],_g=(e,t,s)=>e.getVariableStatements().flatMap(n=>n.getDeclarations()).filter(n=>i.isIdentifier(n.getNameNode())).filter(n=>ht(n).some(r=>Ue(s,t,r))).filter(n=>{const r=n.getInitializer();return r!==void 0&&i.isCallExpression(r)&&i.isPropertyAccessExpression(r.getExpression())}).map(n=>{const r=ht(n).find(o=>Ue(s,t,o))??n.getName();return{declaration:n,exportName:r,relativePath:t}}),Kg=({exportName:e,relativePath:t})=>({cacheKey:"procedure_type_check_unavailable",categories:["SCHEMA"],description:"Codegen cross-checks every export in `lunora/` against its TYPE to catch a procedure the syntactic scan dropped — a factory-assigned export, an alias, a separate `export { … }`. That check needs the type checker to resolve `@lunora/server`; when it cannot, the check reports nothing regardless of what the code does.",detail:`Type resolution for \`lunora/\` is unavailable — the registered procedure \`${e}\` in \`${t}\` types as \`any\`, as does every other one — so codegen cannot tell you when an export is dropped from \`_generated/api.ts\`. A dropped procedure will surface as \`Property '<name>' does not exist\` at its call site instead.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e,filePath:t},name:"procedure_type_check_unavailable",remediation:`Check what codegen sees: \`${e}\` should have a procedure type, not \`any\`. It needs a \`tsconfig.json\` at or above \`lunora/\` — the one codegen finds walking up from there, which is not necessarily the one your editor uses — resolving \`lunorash\` / \`@lunora/server\` to declarations that exist on disk (a workspace dependency has to be built first).`,title:"Codegen cannot type-check `lunora/`, so dropped procedures go unreported"}),Bg=(e,t,s)=>{const n=[],r=[];for(const a of x(t)){const c=e.getSourceFile(a);if(c===void 0)continue;const l=T(t,a);n.push(...Mg(c,l,s)),r.push(..._g(c,l,s))}const[o]=r;return o!==void 0&&r.every(({declaration:a})=>!Xn(a.getType()))&&n.push(Kg(o)),n.toSorted((a,c)=>a.cacheKey.localeCompare(c.cacheKey))},zg=new Set(["when","where"]),gt=new Set(["definePolicy","defineShape"]),$g=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const n=t.getName();return gt.has(n)?n:void 0}if(!i.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(n)){const r=n.getNameNode().getText();return gt.has(r)?r:void 0}const s=t.getText();return gt.has(s)?s:void 0},Ug=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,tr=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===d.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Ug(e))return"empty-object";if(i.isParenthesizedExpression(e))return tr(e.getExpression())}},_t=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Vg=e=>e.getDescendantsOfKind(d.ReturnStatement).filter(t=>_t(t)===e),sr=e=>e.getDescendantsOfKind(d.ConditionalExpression).filter(t=>_t(t)===e),qg=e=>{const t=Vg(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(d.IfStatement)!==void 0)||sr(e).length>0},jg=e=>e.getDescendantsOfKind(d.IfStatement).filter(t=>_t(t)===e),It=e=>e.getKind()===d.NullKeyword||e.getKind()===d.FalseKeyword||i.isIdentifier(e)&&e.getText()==="undefined"?!0:i.isNumericLiteral(e)?e.getLiteralValue()===0:i.isStringLiteral(e)&&e.getLiteralValue()==="",Wg=(e,t)=>It(e)||It(t),Hg=new Map([[d.EqualsEqualsEqualsToken,"positive"],[d.EqualsEqualsToken,"positive"],[d.ExclamationEqualsEqualsToken,"negative"],[d.ExclamationEqualsToken,"negative"]]),Gs=e=>!It(e)&&(i.isLiteralExpression(e)||e.getKind()===d.TrueKeyword),Gg=(e,t,s)=>{const n=Hg.get(e);if(n!==void 0)return Wg(t,s)?n==="positive"?"negative":"positive":Gs(t)||Gs(s)?void 0:n},xe=e=>{if(i.isParenthesizedExpression(e))return xe(e.getExpression());if(i.isPrefixUnaryExpression(e)&&e.getOperatorToken()===d.ExclamationToken)return"negative";if(i.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=Gg(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===d.AmpersandAmpersandToken||t===d.BarBarToken){const n=xe(e.getLeft()),r=xe(e.getRight());return n===r?n:"indeterminate"}}return i.isIdentifier(e)||i.isPropertyAccessExpression(e)||i.isElementAccessExpression(e)||i.isCallExpression(e)?"positive":"indeterminate"},Ys=e=>{if(e!==void 0){if(i.isReturnStatement(e))return e;if(i.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&i.isReturnStatement(t)?t:void 0}}},Yg=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(d.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Qg=e=>i.isReturnStatement(e)?e.getExpression()??e:e,Xg=e=>{const t=[];for(const s of sr(e)){const n=xe(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of jg(e)){const n=xe(s.getExpression());if(n==="indeterminate")continue;const r=n==="negative"?Ys(s.getThenStatement()):Ys(s.getElseStatement())??Yg(s);r!==void 0&&t.push(Qg(r))}return t},Jg=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},Zg=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!i.isObjectLiteralExpression(n))return[];const r=[];for(const o of n.getProperties()){if(!i.isPropertyAssignment(o)||!zg.has(S(o)))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&qg(a))for(const c of Xg(a)){const l=tr(c);l!==void 0&&r.push({exportName:Jg(e),file:s,form:l,key:S(o),line:c.getStartLineNumber(),owner:t})}}return r},ep=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=$g(n);r!==void 0&&s.push(...Zg(n,r,t))}return s},tp=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ep(r,T(t,n)))}return s},sp=new Set(["query","upsert","upsertNow"]),np=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(sp.has(t))return q(e.getExpression(),["vectors"])?t:void 0},rp=(e,t)=>{const s=np(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const r=C(n,"namespace");if(!(!r||!W(r)||ne(r)))return{scope:E(e),file:t,line:e.getStartLineNumber(),method:s}},ip=(e,t)=>O(e,t,rp),op=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="workflows":i.isIdentifier(s)&&s.getText()==="workflows"},ap=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},cp=(e,t)=>O(e,t,(s,n)=>op(s)?{file:n,line:s.getStartLineNumber(),scope:E(s),workflow:ap(s)}:void 0),lp=".lunora-schema.json",Ve=(e,t)=>{R(e)&&mr(e,"utf8")===t||hr(e,t,"utf8")},dp=(e,t)=>{if(t===""){mt(e,{force:!0});return}Ve(e,t)},up=(e,t)=>{const s=v(e,"services");if(Object.keys(t).length===0){mt(s,{force:!0,recursive:!0});return}if(R(s))for(const n of pr(s,{recursive:!0,withFileTypes:!0})){const r=v(n.parentPath,n.name);n.isFile()&&t[vr(e,r)]===void 0&&mt(r)}for(const[n,r]of Object.entries(t))Xs(he(v(e,n)),{recursive:!0}),Ve(v(e,n),r)},fp=e=>{try{const t=xr(v(e,"package.json"));return typeof t.version=="string"&&t.version!==""?t.version:void 0}catch{return}},gp=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},pp=e=>{let t=R(e)?e:he(e);for(;t&&t!==he(t);){const s=v(t,"tsconfig.json");if(R(s))return s;t=he(t)}},Qs=e=>e.replaceAll("\\","/"),mp=(e,t,s)=>{if(s&&e.length>0){const o=e.map(a=>`"${a.exportName}"`).join(", ");throw new J("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${o}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const o of t.columns){const a=n.get(o.table)??[];a.push(o.column),n.set(o.table,a)}const r=t.columns.length>0;for(const o of e){if(o.table===void 0){if(r)throw new J("MASK_UNSUPPORTED",`defineShape "${o.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${o.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(o.table);if(a===void 0)continue;const c=a.map(l=>`"${l}"`).join(", ");throw new J("MASK_UNSUPPORTED",`defineShape "${o.exportName}" replicates table "${o.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},ue=(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)},pt=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,hp=8,vp=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,internalPath:r,lunoraDirectory:o,migrations:a,project:c,shapes:l,usesSandbox:u,useUmbrella:g,workflows:f}=e,m=()=>Si(()=>{const N=Ai(c,o),z=Oi(c,o);return{functions:N,httpRoutes:yi(c,o),mutators:z}});let{erased:b,value:{functions:_,httpRoutes:Y,mutators:L}}=m();gs([..._,...L].map(N=>N.filePath)),gs(Y.filter(N=>N.stream).map(N=>N.filePath),"http-stream");for(let N=1;;N+=1){const z=ro({agents:t,functions:_,httpRoutes:Y,mutators:L,useUmbrella:g,workflows:f}),K=po({agents:t,functions:_,migrations:a,mutators:L,shapes:l,useUmbrella:g,usesSandbox:u}),P=io({functions:_,useUmbrella:g});if(N>=hp||pt(c,s,z)&&pt(c,r,P)&&pt(c,n,K))return{apiContent:z,erased:b,functions:_,functionsContent:K,httpRoutes:Y,internalContent:P,mutators:L};ue(c,s,z),ue(c,r,P),ue(c,n,K),{erased:b,value:{functions:_,httpRoutes:Y,mutators:L}}=m()}},Ep=e=>{const t=pp(e);return t?new ls({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new ls({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Fm=(e,t)=>{const s=x(t),n=v(t,"schema.ts");R(n)&&s.push(n);for(const c of s){const l=e.getSourceFile(c);l===void 0?e.addSourceFileAtPath(c):l.refreshFromFileSystemSync()}const r=new Set(s.map(c=>Qs(c))),o=Qs(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!r.has(l)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const l=c.getFilePath();if(!(l===o||l.startsWith(a)||l.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},Dm=e=>{const t=gp(),s=t?rt.now():0,n=v(e.projectRoot,e.lunoraDirectory??"lunora"),r=v(n,"schema.ts");if(!R(r))throw new J("INTERNAL",`schema.ts not found at ${r}`);const o=e.project??Ep(n);gi(ol);const a=Ki(o,r,e.projectRoot),{agents:c,capabilities:l,containers:u,crons:g,dataModelContent:f,dependencies:m,entryCronTriggers:b,env:_,featureUsage:Y,hasFlags:L,hasNotify:N,identity:z,platformGate:K,queues:P,serverContent:re,services:ie,storageRulesMetadata:fe,topics:oe,usesSandbox:be,useUmbrella:V,workflows:B}=aa({lunoraDirectory:n,project:o,projectRoot:e.projectRoot,schema:a,target:e.target});Vl(a,a.jurisdiction===void 0?void 0:$l(o,n));const k=v(n,"_generated"),D=v(k,"dataModel.ts"),nr=v(k,"server.ts"),rr=v(k,"api.ts"),ir=v(k,"internal.ts"),or=v(k,"functions.ts");ue(o,D,f),ue(o,nr,re);const Qe=Object.fromEntries(ie.filter(p=>p.rpcEntrypoint!==void 0).flatMap(p=>Object.entries(ai(p,k))));for(const[p,w]of Object.entries(Qe))ue(o,v(k,p),w);const Ne=wi(o,n),ae=Vi(o,n),{apiContent:Kt,erased:ar,functions:Q,functionsContent:Bt,httpRoutes:Xe,internalContent:zt,mutators:Pe}=vp({agents:c,apiPath:rr,generatedFunctionsPath:or,internalPath:ir,lunoraDirectory:n,migrations:Ne,project:o,shapes:ae,useUmbrella:V,usesSandbox:be,workflows:B}),$t=wr(o,n),Je=Ir($t,a,[...Q,...Xe].map(p=>p.filePath)),we=$t.length>0,X=e.lint===!1&&!we?void 0:{callEdges:Ac(o,n),inserts:Ni(o,n),queries:Di(o,n),tableWrites:hg(o,n),workflowCalls:cp(o,n)},Ie=e.lint===!1||X===void 0?void 0:yr({adminRoutes:ma(o,n),aiRawRuns:Na(o,n),aiToolSideEffects:La(o,n),argumentDerivedFetches:Ka(o,n),argumentValidators:Ga(o,n),authApiCalls:pi(o,n),authConfigs:rc(o,n),browserUrlAccesses:cc(o,n),callEdges:X.callEdges,configCalls:Tc(o,n),containerKeyAccesses:kc(o,n),containerOverrides:_c(o,n),containers:u,exportSinks:$c(o,n),staleMigrationImports:eg(o,n),failOpenGuards:Wc(o,n),flagReads:tl(o,n),flagSecurityDefaults:il(o,n),geoIndexUsages:ll(o,n),httpActionGuards:Al(o,n),httpHeaderWrites:kl(o,n),hyperdriveCalls:bi(o,n),identityClaimReads:_l(o,n),imageDeliveryUrlAccesses:Bl(o,n),inserts:X.inserts,kvKeyAccesses:jl(o,n,Q),mailRecipientAccesses:Ql(o,n),maskProcedures:Pi(o,n),maskStrategies:rd(o,n),mutatorWrites:dd(o,n),nondeterministicCalls:ki(o,n),normalizeIdAuthorizations:Pd(o,n),notifyCalls:Fi(o,n),notifyConfig:Ri(o,n),mutators:Pe,ownerFieldWrites:xu(o,n,Q,Pe),unrestrictedWhereBranches:tp(o,n),paymentWebhooks:Iu(o,n),privilegedDispatches:Ku(o,n),procedureProtections:yf(o,n),queries:X.queries,queues:P,r2sqlCalls:Li(o,n),ratelimitKeySelectors:Tf(o,n),rawRowReturns:Mf(o,n),relationLoads:Bf(o,n),rlsProcedures:Mi(o,n),schema:a,secretLiterals:qf(o,n),modules:Je,shapes:ae,softDeleteReads:Wf(o,n),sqlInterpolations:Xf(o,n),storageKeyAccesses:sg(o,n,Q),storageUploads:cg(o,n),tableWrites:X.tableWrites,unboundedLoops:yg(o,n),vectorNamespaceAccesses:ip(o,n),workflowCalls:X.workflowCalls,workflows:B,wranglerVariables:e.wranglerVariables}),Ut=Ie===void 0?[]:ho(e.projectRoot,[...Er(Ie,{source:"static"}),...Bg(o,n,{byName:new Set([...B,...P,...c,...u].map(p=>p.exportName)),byPath:new Set([...Q,...Pe,...ae,...Ne].map(p=>`${p.filePath}:${p.exportName}`))}),...wg(o,n),...xi(ar,n),...Xi(P,e.wranglerQueueProducers)]),cr=_i(o,n),Vt=td(o,n);mp(ae,Vt,Zl(o,n));const lr=L?Qc(o,n):[],Ze=K.signals.vectorStore!==!1,ge=lg(Y,{containerCount:u.length,cronCount:g.length,dependencies:m,hasPaymentTables:yu(a.tables),queueCount:P.length,storageColumnCount:Object.keys(un(a)).length,storageRuleCount:fe.rules.length,vectorIndexCount:a.vectorIndexes.length,target:dn(e.projectRoot,e.target),vectorStoreSupported:Ze,workflowCount:B.length}),qt=t?rt.now():0,et=Qi(a,Ne.map(p=>p.id)),jt=ii({advisories:Ut.filter(p=>p.name!=="procedure_type_check_unavailable"),advisorProcedures:Ie?.procedureProtections??[],agents:c,capabilities:l,containers:u,env:_,flagKeys:lr,hasFlags:L,hasNotify:N,hasVectors:Ze,maskMetadata:Vt,mutators:Pe,queues:P,rlsMetadata:cr,schema:a,schemaSnapshot:et,shapes:ae,services:ie,storageRules:fe,studioFeatures:ge,topics:oe,useUmbrella:V,workflows:B}),Wt=so(ae,m.has("@lunora/db"),V),Ht=Ji(u,a.jurisdiction),Gt=Zi(B),Yt=eo(c),Qt=to(P,e.wranglerQueueProducers),Xt=oo(g),dr=ao(ge.scheduler),ur=co(a.tables,V),fr=Pr(e.projectRoot)?lo(V):"",Jt=uo(a.vectorIndexes),Ce=go(a,V),Zt=no(m.has("@lunora/seed")),Te=e.apiSpec??"openapi",tt=Te==="openapi"||Te==="both",st=Te==="openrpc"||Te==="both",es=ji({capabilities:l,emailAgents:c.filter(p=>p.onEmail===!0).map(p=>({className:p.className,exportName:p.exportName})),hasAccess:m.has("@lunora/cloudflare-access"),hasAuth:m.has("@lunora/auth"),hasFramework:m.has("@lunora/astro")||m.has("@lunora/svelte")||m.has("@lunora/vue")||R(v(e.projectRoot,"src","worker.ts")),hasGlobal:a.tables.some(p=>Zs(p)),hasHyperdriveGlobal:a.tables.some(p=>en(p)),hasKvIntrospector:ge.kv,hasNotify:N,hasQueue:P.some(p=>p.mode==="push"),hasScheduler:ge.scheduler,hasSourcedTables:a.tables.some(p=>p.externalSource!==void 0),hasStorage:ge.storage,hasVectors:Ze,hasWorkflow:B.length>0,identity:z,jurisdiction:a.jurisdiction,jurisdictionPinsAuth:a.jurisdictionPinsAuth===!0,tables:a.tables.map(p=>({name:p.name,shardMode:p.shardMode})),useUmbrella:V,vectorIndexCount:a.vectorIndexes.length,voiceAgents:c.filter(p=>p.voice===!0&&p.voiceBindingName!==void 0).map(p=>({bindingName:p.voiceBindingName,exportName:p.exportName})),wantsArchitecture:we,wantsOpenApi:tt,wantsOpenRpc:st}),ts=fp(e.projectRoot),ss=we?Je:[],ns=Wi({functions:Q,httpRoutes:Xe,modules:ss,version:ts}),rs=Gi({functions:Q,modules:ss,version:ts}),is=`${JSON.stringify(ns,void 0,2)}
|
|
8
|
+
`)){const r=n.replace(hf,"");if(!r.startsWith(js))continue;const o=r.slice(js.length);if(vf.test(o.charAt(0)))continue;const a=o.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":o.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},xf=e=>{const[t]=e.getArguments();if(t){if(i.isObjectLiteralExpression(t)){const s=M(t,"handler");return s?i.isPropertyAssignment(s)?s.getInitializer():i.isShorthandPropertyAssignment(s)?s.getNameNode():i.isMethodDeclaration(s)?s:void 0:void 0}return t}},Sf=(e,t)=>{const s=xf(t);if(!s)return;if(i.isArrowFunction(s)||i.isFunctionExpression(s)||i.isMethodDeclaration(s))return e;if(!i.isIdentifier(s))return;const n=s.getSourceFile(),r=s.getText(),o=n.getVariableDeclaration(r)?.getInitializer();return o&&(i.isArrowFunction(o)||i.isFunctionExpression(o))?o:n.getFunction(r)},Af=e=>{let t=!1,s=!1,n=!1,r=!1,o=!1;for(const l of e.getDescendantsOfKind(d.CallExpression))if(Qu(l)&&(o=!0),Ju(l)&&(t=!0),Zu(l)&&(r=!0),ef(l)&&(s=!0),tf(l)&&(n=!0),o&&t&&r&&n)break;const{handlesErrors:a,reachesOutbound:c}=pf(e);return{callsMail:ut(e,rf),emitsEvent:ut(e,sf),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||ut(e,nf),throwsBareError:mf(e),unboundedAiGeneration:n,usesInsertManyUnsafe:r,writesUserTable:o}},yf=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=G(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const r=n.receiver?Gu(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},o=Sf(e,s);return{...o?Af(o):{},...Ef(e),...r,analyzableBody:o!==void 0,exportName:U(e)??e.getName(),file:t,hasEmailArg:qu(s,n.receiver),kind:n.kind,visibility:n.visibility}},bf=(e,t)=>{const s=[];for(const n of H(e)){const r=yf(n,t);r&&s.push(r)}return s},Nf=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...bf(r,T(t,n)))}return s},Pf=new Set(["dbRateLimit","rateLimit"]),wf=e=>i.isArrowFunction(e)?e.getBody():e,If=e=>{if(!i.isArrowFunction(e))return;const t=e.getParameters()[0]?.getNameNode();return t!==void 0&&i.isIdentifier(t)?t:void 0},Qn=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getExpression()===e&&t.getName()==="args"},Xn=(e,t)=>{const s=t.getSymbol();return s===void 0?[]:e.getDescendantsOfKind(d.Identifier).filter(n=>{if(n.getSymbol()!==s)return!1;const r=n.getParent();return!(i.isPropertyAccessExpression(r)&&r.getNameNode()===n)})},Cf=(e,t)=>W(e)||t!==void 0&&Xn(e,t).some(s=>Qn(s)),Tf=(e,t)=>t===void 0?ne(e):Xn(e,t).some(s=>!Qn(s)),Of=(e,t)=>{const s=b(e.getExpression());if(s===void 0||!Pf.has(s))return;const n=C(an(e.getArguments()[2]),"key");if(!n)return;const r=wf(n),o=If(n);if(!(!Cf(r,o)||Tf(r,o)))return{callee:s,scope:E(e),file:t,limitName:on(e),line:e.getStartLineNumber()}},kf=(e,t)=>O(e,t,Of),Rf=new Set(["findFirst","findFirstOrThrow","findMany","findUnique","get"]),Ff=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Rf.has(t.getName()))return;const s=t.getExpression();if($(s)){const n=e.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&$(s.getExpression()))return s.getName()},Df=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&$(s.getExpression())){const n=t.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},Lf=e=>{let t=h(e)??e;for(;i.isAwaitExpression(t);)t=h(t.getExpression())??t.getExpression();return t},Jn=(e,t=!1)=>{const s=Lf(e);if(i.isIdentifier(s)){if(t)return;const n=j(s);return n===void 0?void 0:Jn(n,!0)}if(i.isCallExpression(s))return Ff(s)??Df(s)},Mf=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(d.ReturnStatement)){const r=n.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),o=n.getExpression();r===e&&o!==void 0&&s.push(o)}return s},_f=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=G(s);if(n?.kind!=="query")return[];const r=Tn(s);if(r===void 0)return[];const o=n.receiver!==void 0&&si(n.receiver,"output"),a=n.receiver!==void 0&&ln(n.receiver,"use","mask"),c=new Set,l=[];for(const u of Mf(r)){const g=Jn(u);g===void 0||c.has(g)||(c.add(g),l.push({exportName:U(e)??e.getName(),file:t,line:u.getStartLineNumber(),table:g,usesMask:a,usesOutput:o,visibility:n.visibility}))}return l},Kf=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=T(t,n);for(const a of H(r))s.push(..._f(a,o))}return s},Bf=e=>{if(!e||!i.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s)||i.isGetAccessorDeclaration(s))&&t.push(A(s));return t},zf=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?G(s):void 0;if(!n)return[];const r=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=vn(o);if(a===void 0)continue;const c=Bf(C(a.options,"with"));c.length!==0&&r.push({exportName:U(e)??e.getName(),file:t,line:o.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return r},$f=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=T(t,n);for(const a of H(r))s.push(...zf(a,o))}return s},$e=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===d.PlusToken){const t=$e(e.getLeft()),s=$e(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},Uf=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===d.PlusToken;)t=s,s=t.getParent();return t!==e&&$e(t)!==void 0},Vf=e=>{const t=e.getParent();if(t!==void 0){if(i.isVariableDeclaration(t)||i.isPropertyAssignment(t)||i.isPropertySignature(t))return A(t);if(i.isBinaryExpression(t)&&t.getOperatorToken().getKind()===d.EqualsToken)return t.getLeft().getText()}},qf=(e,t,s)=>Vi(e)?!Xr(s)&&qi(Vf(t)):!0,jf=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(d.BinaryExpression),...e.getDescendantsOfKind(d.StringLiteral),...e.getDescendantsOfKind(d.NoSubstitutionTemplateLiteral)],r=new Set;for(const o of n){if(Uf(o))continue;const a=$e(o);if(a===void 0)continue;const c=$i(a);if(c===void 0||!qf(c,o,t))continue;const l=o.getStartLineNumber(),u=`${String(l)}:${c}`;r.has(u)||(r.add(u),s.push({file:t,kind:c,line:l,preview:Ui(a)}))}return s},Wf=(e,t)=>{const s=[];for(const n of x(t,{includeSkipped:!0})){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...jf(r,T(t,n)))}return s},Hf=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?G(s):void 0;if(!n)return[];const r=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=vn(o);if(a===void 0)continue;const c=C(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),u=!l&&W(c);!l&&!u||r.push({exportName:U(e)??e.getName(),file:t,fromArgs:u,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:n.visibility})}return r},Gf=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=T(t,n);for(const a of H(r))s.push(...Hf(a,o))}return s},Yf=new Set(["query","unsafe"]),Qf=e=>!i.isPropertyAccessExpression(e)||!Yf.has(e.getName())?!1:q(e.getExpression(),["sql"]),Xf=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),Jf=(e,t)=>{if(!Qf(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Xf(s)))return{file:t,line:s.getStartLineNumber(),scope:E(e)}},Zf=(e,t)=>O(e,t,Jf),eg=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],tg=e=>{for(const[t,s]of eg)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},sg=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of r.getImportDeclarations()){const a=o.getModuleSpecifierValue(),c=tg(a);c!==void 0&&s.push({file:T(t,n),line:o.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},ng=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),rg=(e,t,s=[])=>{const n=Ye(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:ng,requireUnmodifiedReach:!0});return Tt(n,s)},ig=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),og=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,ag=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!i.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const r of e.getProperties()){if(i.isSpreadAssignment(r)){n=!0;continue}if(i.isPropertyAssignment(r)){const o=A(r);t.push(o),o==="expiresInSeconds"&&(s=og(r.getInitializer()));continue}(i.isShorthandPropertyAssignment(r)||i.isMethodDeclaration(r))&&t.push(A(r))}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},cg=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=ig.get(t);return s===void 0?void 0:fn(e.getExpression(),r=>r==="ctx.storage"||r.startsWith("ctx.storage."))?{method:t,optionsIndex:s}:void 0},lg=(e,t)=>{const s=cg(e.getExpression());if(s!==void 0)return{scope:E(e),file:t,line:e.getStartLineNumber(),method:s.method,...ag(e.getArguments()[s.optionsIndex])}},dg=(e,t)=>O(e,t,lg),ug=(e,t)=>{const s=oi(t.target);return{...s===void 0?{}:{platform:s},analytics:e.analytics||t.dependencies.has("@lunora/bindings"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:t.vectorStoreSupported&&t.vectorIndexCount>0,workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}},fg=new Set(["delete","hardDelete","patch","replace","restore"]),gg=new Set(["insertMany","insertManyUnsafe","patchWhere"]),pg=new Set(["delete","deleteMany","hardDelete","insert","insertMany","patch","patchMany","replace","restore","upsert","upsertMany"]),Ws=(e,t)=>{const s=e.getNonNullableType().getProperty("__table")?.getTypeAtLocation(t);if(s===void 0)return[];const n=s.isUnion()?s.getUnionTypes():[s],r=n.map(o=>o.getLiteralValue()).filter(o=>typeof o=="string");return r.length===n.length?r:[]},mg=(e,t)=>{const s=e.getType();if(t==="deleteMany"||t==="patchMany"){const n=s.getArrayElementType();if(n===void 0)return[];const r=t==="patchMany"?n.getProperty("id")?.getTypeAtLocation(e):n;return r===void 0?[]:Ws(r,e)}return Ws(s,e)},Hs="",hg=(e,t)=>{if(gg.has(e))return{method:e,tables:[t!==void 0&&i.isStringLiteral(t)?t.getLiteralText():Hs]};if(fg.has(e)||e==="deleteMany"||e==="patchMany"){const s=t===void 0?[]:mg(t,e);return{method:e,tables:s.length===0?[Hs]:s}}},vg=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression();if($(n))return hg(s,e.getArguments()[0]);if(pg.has(s)&&i.isPropertyAccessExpression(n)&&$(n.getExpression()))return{method:s,tables:[n.getName()]}},Eg=(e,t)=>O(e,t,(s,n)=>{const r=vg(s);if(r===void 0)return;const o=E(s),a=s.getStartLineNumber();return r.tables.map(c=>({file:n,line:a,method:r.method,scope:o,table:c}))}),xg=e=>{const t=i.isCallExpression(e)?e.getExpression():void 0;return i.isPropertyAccessExpression(t)&&t.getName()==="throwIfAborted"},Sg=e=>Pn(e).some(t=>Nn(t,e)||i.isBreakStatement(t)&&y(bn(t),e))||e.getDescendantsOfKind(d.CallExpression).some(t=>xg(t)&&Lt(t,e)),Ag=e=>e.getDescendantsOfKind(d.YieldExpression).some(t=>Lt(t,e)),yg=e=>i.isDoStatement(e)||i.isWhileStatement(e)?e.getExpression():e.getCondition(),bg=e=>i.isDoStatement(e)?"do":i.isWhileStatement(e)?"while":"for",ft=(e,t)=>{const s=yg(e);if(!(s===void 0||i.isTrueLiteral(h(s)))||Sg(e)||Ag(e))return;const r=E(e);if(!(r.kind==="module"&&e.getFirstAncestor(Z)!==void 0))return{file:t,kind:bg(e),line:e.getStartLineNumber(),scope:r}},Ng=(e,t)=>[...de(e,t,d.WhileStatement,ft),...de(e,t,d.ForStatement,ft),...de(e,t,d.DoStatement,ft)].toSorted((s,n)=>s.file.localeCompare(n.file)||s.line-n.line),Pg=(e,t,s)=>({cacheKey:`procedure_arguments_unreadable:${e}:${t}`,categories:["SCHEMA"],description:"Codegen reads an argument record statically. One built at runtime — a factory call, or a property off a value it cannot follow — has no literal to read, so the generated `FunctionReference` carries only the arguments it could see while the runtime validator still enforces all of them.",detail:`\`${t}\` in \`${e}\` (line ${s.toString()}) declares arguments codegen could not read, so its generated type is missing some of them.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:s},name:"procedure_arguments_unreadable",remediation:`Declare the arguments as an object literal, or as a \`const\` object literal the chain names — \`const ${t}Args = { … };\` then \`.input(${t}Args)\`. Both resolve; a record returned by a call does not.`,title:"Procedure arguments are missing from the generated type"}),wg=(e,t)=>{if(t===void 0){const s=e.getArguments()[0];if(s===void 0||!i.isObjectLiteralExpression(s)||M(s,"args")===void 0)return!1}return Dt(e,t).opaque},Ig=(e,t)=>{const s=[],n=(r,o)=>{const a=r.getInitializer();if(a===void 0||!i.isCallExpression(a))return;const c=G(a);c!==void 0&&wg(a,c.receiver)&&s.push(Pg(t,o,a.getStartLineNumber()))};for(const r of e.getVariableStatements().filter(o=>o.isExported()))for(const o of r.getDeclarations())n(o,o.getName());return s},Cg=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n);r!==void 0&&s.push(...Ig(r,T(t,n)))}return s.toSorted((n,r)=>n.cacheKey.localeCompare(r.cacheKey))},Tg=new Map([["AgentDefinition",{call:"defineAgent({ … })",file:"agents"}],["ContainerDefinition",{call:"defineContainer({ … })",file:"containers"}],["QueueDefinition",{call:"defineQueue({ … })",file:"queues",note:"A dropped queue has no caller to fail — its consumer is simply never wired."}],["RegisteredAction",{call:"action.input({ … }).action(handler)"}],["RegisteredLifecycleHook",{call:"onConnect(handler)",note:"Substitute the hook you called: `onConnect`, `onDisconnect` and `onShardInit` share one type, so codegen cannot tell which you wrote. A dropped hook has no caller to fail — it silently never fires."}],["RegisteredMigration",{call:"defineMigration({ … })",note:"A dropped migration never runs, so `lunora migrate up` reports nothing to do."}],["RegisteredMutation",{call:"mutation.input({ … }).mutation(handler)"}],["RegisteredMutator",{call:"defineMutator({ … })",file:"mutators"}],["RegisteredQuery",{call:"query.input({ … }).query(handler)"}],["RegisteredReactor",{call:"onQueryChange(select, handler)",note:"A dropped reactor has no caller to fail — it silently never runs."}],["RegisteredShape",{call:"defineShape({ … })",file:"shapes"}],["RegisteredStream",{call:"query.input({ … }).stream(handler)"}],["RegisteredWhisperAuthorizer",{call:"onWhisper(handler)",note:"A dropped authorizer has no caller to fail — the whisper topics it was meant to gate silently stay open to every socket on the shard."}],["SubscriptionDefinition",{call:"defineSubscription(topic, { … })",file:"queues",note:"A dropped subscription is never published to — its topic's messages simply never reach it."}],["WorkflowDefinition",{call:"defineWorkflow({ … })",file:"workflows"}]]),Ue=({byName:e,byPath:t},s,n)=>t.has(`${s}:${n}`)||e.has(n),Zn=e=>!e.isAny(),er=e=>{const t=e.getType();if(!Zn(t))return;const s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName(),n=s===void 0?void 0:Tg.get(s);return n===void 0||s===void 0?void 0:{...n,typeName:s}},Og=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},tr={cause:"codegen recognises a registration only when the initializer is the registering call itself, and this one comes from a factory or an alias",remediation:"A factory that returns a registration cannot be read statically — inline it, or export what the factory builds."},kg=e=>({cause:`codegen reads this kind of registration only from \`lunora/${e}.ts\`, and this is a different module`,remediation:`Move it into \`lunora/${e}.ts\` — the declaration itself is fine.`}),Rg={cause:"it is exported only under a string name that is not an identifier, which the generated `api.ts` and dispatch table cannot address as `<module>.<name>`",remediation:"Export it under an identifier name as well (or instead)."},Fg=new Set(["AgentDefinition","ContainerDefinition","QueueDefinition","RegisteredShape","SubscriptionDefinition","WorkflowDefinition"]),Dg={cause:"it is exported only as `default` or under a reserved word, and this kind's name becomes an import binding and a generated class / binding name, where that is a syntax error",remediation:"Export it under a plain identifier: `export const <name> = …` (an extra `export default <name>` is fine)."},Lg=(e,t,s)=>{if(!t.some(r=>Vr(r)))return Rg;const n=e.getVariableStatement()?.hasExportKeyword()===!0;return Fg.has(s.typeName)&&!n&&!t.some(r=>Wi(r))?Dg:tr},sr=(e,t,s,n,r)=>{const{call:o,file:a,note:c,typeName:l}=s,u=a!==void 0&&e!==a?a:void 0,g=u===void 0?r:kg(u),f=c===void 0?g.remediation:`${c} ${g.remediation}`;return{cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when its initializer is literally the registering call and the module exports it under an identifier name — by the `export` keyword, a local `export { … }`, or `export default`. Written any other way it exists at runtime but never reaches the generated output — `_generated/api.ts` for a procedure, the lifecycle manifest for a hook or reactor — so a caller cannot address it and a hook never fires.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${l}\` but was not registered — ${g.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:l},name:"procedure_not_registered",remediation:u===void 0?`Assign the registration directly: \`export const ${t} = ${o};\`. ${f}`:f,title:"Procedure exists at runtime but is missing from the generated API"}},Mg=(e,t,s)=>{const n=[];for(const r of H(e)){const o=i.isIdentifier(r.getNameNode())?ht(r):[r.getName()],c=o.some(u=>Ue(s,t,u))||!Og(r)?void 0:er(r),[l=r.getName()]=o;c!==void 0&&n.push(sr(t,l,c,r.getStartLineNumber(),Lg(r,o,c)))}return n},_g=(e,t,s)=>{if(Ue(s,t,"default"))return[];const n=[];for(const r of e.getExportAssignments().filter(o=>!o.isExportEquals()&&!i.isIdentifier(o.getExpression()))){const o=er(r.getExpression());o!==void 0&&n.push(sr(t,"default",o,r.getStartLineNumber(),tr))}return n},Kg=(e,t,s)=>[...Mg(e,t,s),..._g(e,t,s)],Bg=(e,t,s)=>e.getVariableStatements().flatMap(n=>n.getDeclarations()).filter(n=>i.isIdentifier(n.getNameNode())).filter(n=>ht(n).some(r=>Ue(s,t,r))).filter(n=>{const r=n.getInitializer();return r!==void 0&&i.isCallExpression(r)&&i.isPropertyAccessExpression(r.getExpression())}).map(n=>{const r=ht(n).find(o=>Ue(s,t,o))??n.getName();return{declaration:n,exportName:r,relativePath:t}}),zg=({exportName:e,relativePath:t})=>({cacheKey:"procedure_type_check_unavailable",categories:["SCHEMA"],description:"Codegen cross-checks every export in `lunora/` against its TYPE to catch a procedure the syntactic scan dropped — a factory-assigned export, an alias, a separate `export { … }`. That check needs the type checker to resolve `@lunora/server`; when it cannot, the check reports nothing regardless of what the code does.",detail:`Type resolution for \`lunora/\` is unavailable — the registered procedure \`${e}\` in \`${t}\` types as \`any\`, as does every other one — so codegen cannot tell you when an export is dropped from \`_generated/api.ts\`. A dropped procedure will surface as \`Property '<name>' does not exist\` at its call site instead.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e,filePath:t},name:"procedure_type_check_unavailable",remediation:`Check what codegen sees: \`${e}\` should have a procedure type, not \`any\`. It needs a \`tsconfig.json\` at or above \`lunora/\` — the one codegen finds walking up from there, which is not necessarily the one your editor uses — resolving \`lunorash\` / \`@lunora/server\` to declarations that exist on disk (a workspace dependency has to be built first).`,title:"Codegen cannot type-check `lunora/`, so dropped procedures go unreported"}),$g=(e,t,s)=>{const n=[],r=[];for(const a of x(t)){const c=e.getSourceFile(a);if(c===void 0)continue;const l=T(t,a);n.push(...Kg(c,l,s)),r.push(...Bg(c,l,s))}const[o]=r;return o!==void 0&&r.every(({declaration:a})=>!Zn(a.getType()))&&n.push(zg(o)),n.toSorted((a,c)=>a.cacheKey.localeCompare(c.cacheKey))},Ug=new Set(["when","where"]),gt=new Set(["definePolicy","defineShape"]),Vg=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const n=t.getName();return gt.has(n)?n:void 0}if(!i.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(n)){const r=n.getNameNode().getText();return gt.has(r)?r:void 0}const s=t.getText();return gt.has(s)?s:void 0},qg=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,nr=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===d.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(qg(e))return"empty-object";if(i.isParenthesizedExpression(e))return nr(e.getExpression())}},_t=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),jg=e=>e.getDescendantsOfKind(d.ReturnStatement).filter(t=>_t(t)===e),rr=e=>e.getDescendantsOfKind(d.ConditionalExpression).filter(t=>_t(t)===e),Wg=e=>{const t=jg(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(d.IfStatement)!==void 0)||rr(e).length>0},Hg=e=>e.getDescendantsOfKind(d.IfStatement).filter(t=>_t(t)===e),It=e=>e.getKind()===d.NullKeyword||e.getKind()===d.FalseKeyword||i.isIdentifier(e)&&e.getText()==="undefined"?!0:i.isNumericLiteral(e)?e.getLiteralValue()===0:i.isStringLiteral(e)&&e.getLiteralValue()==="",Gg=(e,t)=>It(e)||It(t),Yg=new Map([[d.EqualsEqualsEqualsToken,"positive"],[d.EqualsEqualsToken,"positive"],[d.ExclamationEqualsEqualsToken,"negative"],[d.ExclamationEqualsToken,"negative"]]),Gs=e=>!It(e)&&(i.isLiteralExpression(e)||e.getKind()===d.TrueKeyword),Qg=(e,t,s)=>{const n=Yg.get(e);if(n!==void 0)return Gg(t,s)?n==="positive"?"negative":"positive":Gs(t)||Gs(s)?void 0:n},xe=e=>{if(i.isParenthesizedExpression(e))return xe(e.getExpression());if(i.isPrefixUnaryExpression(e)&&e.getOperatorToken()===d.ExclamationToken)return"negative";if(i.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=Qg(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===d.AmpersandAmpersandToken||t===d.BarBarToken){const n=xe(e.getLeft()),r=xe(e.getRight());return n===r?n:"indeterminate"}}return i.isIdentifier(e)||i.isPropertyAccessExpression(e)||i.isElementAccessExpression(e)||i.isCallExpression(e)?"positive":"indeterminate"},Ys=e=>{if(e!==void 0){if(i.isReturnStatement(e))return e;if(i.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&i.isReturnStatement(t)?t:void 0}}},Xg=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(d.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Jg=e=>i.isReturnStatement(e)?e.getExpression()??e:e,Zg=e=>{const t=[];for(const s of rr(e)){const n=xe(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of Hg(e)){const n=xe(s.getExpression());if(n==="indeterminate")continue;const r=n==="negative"?Ys(s.getThenStatement()):Ys(s.getElseStatement())??Xg(s);r!==void 0&&t.push(Jg(r))}return t},ep=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},tp=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!i.isObjectLiteralExpression(n))return[];const r=[];for(const o of n.getProperties()){if(!i.isPropertyAssignment(o)||!Ug.has(A(o)))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Wg(a))for(const c of Zg(a)){const l=nr(c);l!==void 0&&r.push({exportName:ep(e),file:s,form:l,key:A(o),line:c.getStartLineNumber(),owner:t})}}return r},sp=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=Vg(n);r!==void 0&&s.push(...tp(n,r,t))}return s},np=(e,t)=>{const s=[];for(const n of x(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...sp(r,T(t,n)))}return s},rp=new Set(["query","upsert","upsertNow"]),ip=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(rp.has(t))return q(e.getExpression(),["vectors"])?t:void 0},op=(e,t)=>{const s=ip(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const r=C(n,"namespace");if(!(!r||!W(r)||ne(r)))return{scope:E(e),file:t,line:e.getStartLineNumber(),method:s}},ap=(e,t)=>O(e,t,op),cp=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="workflows":i.isIdentifier(s)&&s.getText()==="workflows"},lp=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},dp=(e,t)=>O(e,t,(s,n)=>cp(s)?{file:n,line:s.getStartLineNumber(),scope:E(s),workflow:lp(s)}:void 0),up=".lunora-schema.json",Ve=(e,t)=>{R(e)&&vr(e,"utf8")===t||Er(e,t,"utf8")},fp=(e,t)=>{if(t===""){mt(e,{force:!0});return}Ve(e,t)},gp=(e,t)=>{const s=v(e,"services");if(Object.keys(t).length===0){mt(s,{force:!0,recursive:!0});return}if(R(s))for(const n of hr(s,{recursive:!0,withFileTypes:!0})){const r=v(n.parentPath,n.name);n.isFile()&&t[xr(e,r)]===void 0&&mt(r)}for(const[n,r]of Object.entries(t))Xs(he(v(e,n)),{recursive:!0}),Ve(v(e,n),r)},pp=e=>{try{const t=Ar(v(e,"package.json"));return typeof t.version=="string"&&t.version!==""?t.version:void 0}catch{return}},mp=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},hp=e=>{let t=R(e)?e:he(e);for(;t&&t!==he(t);){const s=v(t,"tsconfig.json");if(R(s))return s;t=he(t)}},Qs=e=>e.replaceAll("\\","/"),vp=(e,t,s)=>{if(s&&e.length>0){const o=e.map(a=>`"${a.exportName}"`).join(", ");throw new J("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${o}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const o of t.columns){const a=n.get(o.table)??[];a.push(o.column),n.set(o.table,a)}const r=t.columns.length>0;for(const o of e){if(o.table===void 0){if(r)throw new J("MASK_UNSUPPORTED",`defineShape "${o.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${o.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(o.table);if(a===void 0)continue;const c=a.map(l=>`"${l}"`).join(", ");throw new J("MASK_UNSUPPORTED",`defineShape "${o.exportName}" replicates table "${o.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},ue=(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)},pt=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,Ep=8,xp=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,internalPath:r,lunoraDirectory:o,migrations:a,project:c,shapes:l,usesSandbox:u,useUmbrella:g,workflows:f}=e,m=()=>yi(()=>{const N=bi(c,o),z=Ri(c,o);return{functions:N,httpRoutes:Ni(c,o),mutators:z}});let{erased:S,value:{functions:_,httpRoutes:Y,mutators:L}}=m();gs([..._,...L].map(N=>N.filePath)),gs(Y.filter(N=>N.stream).map(N=>N.filePath),"http-stream");for(let N=1;;N+=1){const z=oo({agents:t,functions:_,httpRoutes:Y,mutators:L,useUmbrella:g,workflows:f}),K=ho({agents:t,functions:_,migrations:a,mutators:L,shapes:l,useUmbrella:g,usesSandbox:u}),P=ao({functions:_,useUmbrella:g});if(N>=Ep||pt(c,s,z)&&pt(c,r,P)&&pt(c,n,K))return{apiContent:z,erased:S,functions:_,functionsContent:K,httpRoutes:Y,internalContent:P,mutators:L};ue(c,s,z),ue(c,r,P),ue(c,n,K),{erased:S,value:{functions:_,httpRoutes:Y,mutators:L}}=m()}},Sp=e=>{const t=hp(e);return t?new ls({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new ls({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Lm=(e,t)=>{const s=x(t),n=v(t,"schema.ts");R(n)&&s.push(n);for(const c of s){const l=e.getSourceFile(c);l===void 0?e.addSourceFileAtPath(c):l.refreshFromFileSystemSync()}const r=new Set(s.map(c=>Qs(c))),o=Qs(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!r.has(l)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const l=c.getFilePath();if(!(l===o||l.startsWith(a)||l.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},Mm=e=>{const t=mp(),s=t?rt.now():0,n=v(e.projectRoot,e.lunoraDirectory??"lunora"),r=v(n,"schema.ts");if(!R(r))throw new J("INTERNAL",`schema.ts not found at ${r}`);const o=e.project??Sp(n);mi(cl);const a=zi(o,r,e.projectRoot),{agents:c,capabilities:l,containers:u,crons:g,dataModelContent:f,dependencies:m,entryCronTriggers:S,env:_,featureUsage:Y,hasFlags:L,hasNotify:N,identity:z,platformGate:K,queues:P,serverContent:re,services:ie,storageRulesMetadata:fe,topics:oe,usesSandbox:be,useUmbrella:V,workflows:B}=la({lunoraDirectory:n,project:o,projectRoot:e.projectRoot,schema:a,target:e.target});jl(a,a.jurisdiction===void 0?void 0:Vl(o,n));const k=v(n,"_generated"),D=v(k,"dataModel.ts"),ir=v(k,"server.ts"),or=v(k,"api.ts"),ar=v(k,"internal.ts"),cr=v(k,"functions.ts");ue(o,D,f),ue(o,ir,re);const Qe=Object.fromEntries(ie.filter(p=>p.rpcEntrypoint!==void 0).flatMap(p=>Object.entries(li(p,k))));for(const[p,w]of Object.entries(Qe))ue(o,v(k,p),w);const Ne=Ci(o,n),ae=ji(o,n),{apiContent:Kt,erased:lr,functions:Q,functionsContent:Bt,httpRoutes:Xe,internalContent:zt,mutators:Pe}=xp({agents:c,apiPath:or,generatedFunctionsPath:cr,internalPath:ar,lunoraDirectory:n,migrations:Ne,project:o,shapes:ae,useUmbrella:V,usesSandbox:be,workflows:B}),$t=Cr(o,n),Je=Tr($t,a,[...Q,...Xe].map(p=>p.filePath)),we=$t.length>0,X=e.lint===!1&&!we?void 0:{callEdges:bc(o,n),inserts:wi(o,n),queries:Mi(o,n),tableWrites:Eg(o,n),workflowCalls:dp(o,n)},Ie=e.lint===!1||X===void 0?void 0:Nr({adminRoutes:va(o,n),aiRawRuns:wa(o,n),aiToolSideEffects:_a(o,n),argumentDerivedFetches:za(o,n),argumentValidators:Qa(o,n),authApiCalls:hi(o,n),authConfigs:oc(o,n),browserUrlAccesses:dc(o,n),callEdges:X.callEdges,configCalls:kc(o,n),containerKeyAccesses:Fc(o,n),containerOverrides:Bc(o,n),containers:u,exportSinks:Vc(o,n),staleMigrationImports:sg(o,n),failOpenGuards:Gc(o,n),flagReads:nl(o,n),flagSecurityDefaults:al(o,n),geoIndexUsages:ul(o,n),httpActionGuards:bl(o,n),httpHeaderWrites:Fl(o,n),hyperdriveCalls:Pi(o,n),identityClaimReads:Bl(o,n),imageDeliveryUrlAccesses:$l(o,n),inserts:X.inserts,kvKeyAccesses:Hl(o,n,Q),mailRecipientAccesses:Jl(o,n),maskProcedures:Ii(o,n),maskStrategies:od(o,n),mutatorWrites:fd(o,n),nondeterministicCalls:Fi(o,n),normalizeIdAuthorizations:Id(o,n),notifyCalls:Li(o,n),notifyConfig:Di(o,n),mutators:Pe,ownerFieldWrites:Au(o,n,Q,Pe),unrestrictedWhereBranches:np(o,n),paymentWebhooks:Tu(o,n),privilegedDispatches:zu(o,n),procedureProtections:Nf(o,n),queries:X.queries,queues:P,r2sqlCalls:_i(o,n),ratelimitKeySelectors:kf(o,n),rawRowReturns:Kf(o,n),relationLoads:$f(o,n),rlsProcedures:Ki(o,n),schema:a,secretLiterals:Wf(o,n),modules:Je,shapes:ae,softDeleteReads:Gf(o,n),sqlInterpolations:Zf(o,n),storageKeyAccesses:rg(o,n,Q),storageUploads:dg(o,n),tableWrites:X.tableWrites,unboundedLoops:Ng(o,n),vectorNamespaceAccesses:ap(o,n),workflowCalls:X.workflowCalls,workflows:B,wranglerVariables:e.wranglerVariables}),Ut=Ie===void 0?[]:Eo(e.projectRoot,[...Sr(Ie,{source:"static"}),...$g(o,n,{byName:new Set([...B,...P,...c,...u].map(p=>p.exportName)),byPath:new Set([...Q,...Pe,...ae,...Ne].map(p=>`${p.filePath}:${p.exportName}`))}),...Cg(o,n),...Ai(lr,n),...Zi(P,e.wranglerQueueProducers)]),dr=Bi(o,n),Vt=nd(o,n);vp(ae,Vt,td(o,n));const ur=L?Jc(o,n):[],Ze=K.signals.vectorStore!==!1,ge=ug(Y,{containerCount:u.length,cronCount:g.length,dependencies:m,hasPaymentTables:Nu(a.tables),queueCount:P.length,storageColumnCount:Object.keys(un(a)).length,storageRuleCount:fe.rules.length,vectorIndexCount:a.vectorIndexes.length,target:dn(e.projectRoot,e.target),vectorStoreSupported:Ze,workflowCount:B.length}),qt=t?rt.now():0,et=Ji(a,Ne.map(p=>p.id)),jt=ai({advisories:Ut.filter(p=>p.name!=="procedure_type_check_unavailable"),advisorProcedures:Ie?.procedureProtections??[],agents:c,capabilities:l,containers:u,env:_,flagKeys:ur,hasFlags:L,hasNotify:N,hasVectors:Ze,maskMetadata:Vt,mutators:Pe,queues:P,rlsMetadata:dr,schema:a,schemaSnapshot:et,shapes:ae,services:ie,storageRules:fe,studioFeatures:ge,topics:oe,useUmbrella:V,workflows:B}),Wt=ro(ae,m.has("@lunora/db"),V),Ht=eo(u,a.jurisdiction),Gt=to(B),Yt=so(c),Qt=no(P,e.wranglerQueueProducers),Xt=co(g),fr=lo(ge.scheduler),gr=uo(a.tables,V),pr=Ir(e.projectRoot)?fo(V):"",Jt=go(a.vectorIndexes),Ce=mo(a,V),Zt=io(m.has("@lunora/seed")),Te=e.apiSpec??"openapi",tt=Te==="openapi"||Te==="both",st=Te==="openrpc"||Te==="both",es=Hi({capabilities:l,emailAgents:c.filter(p=>p.onEmail===!0).map(p=>({className:p.className,exportName:p.exportName})),hasAccess:m.has("@lunora/cloudflare-access"),hasAuth:m.has("@lunora/auth"),hasFramework:m.has("@lunora/astro")||m.has("@lunora/svelte")||m.has("@lunora/vue")||R(v(e.projectRoot,"src","worker.ts")),hasGlobal:a.tables.some(p=>Zs(p)),hasHyperdriveGlobal:a.tables.some(p=>en(p)),hasKvIntrospector:ge.kv,hasNotify:N,hasQueue:P.some(p=>p.mode==="push"),hasScheduler:ge.scheduler,hasSourcedTables:a.tables.some(p=>p.externalSource!==void 0),hasStorage:ge.storage,hasVectors:Ze,hasWorkflow:B.length>0,identity:z,jurisdiction:a.jurisdiction,jurisdictionPinsAuth:a.jurisdictionPinsAuth===!0,tables:a.tables.map(p=>({name:p.name,shardMode:p.shardMode})),useUmbrella:V,vectorIndexCount:a.vectorIndexes.length,voiceAgents:c.filter(p=>p.voice===!0&&p.voiceBindingName!==void 0).map(p=>({bindingName:p.voiceBindingName,exportName:p.exportName})),wantsArchitecture:we,wantsOpenApi:tt,wantsOpenRpc:st}),ts=pp(e.projectRoot),ss=we?Je:[],ns=Gi({functions:Q,httpRoutes:Xe,modules:ss,version:ts}),rs=Qi({functions:Q,modules:ss,version:ts}),is=`${JSON.stringify(ns,void 0,2)}
|
|
9
9
|
`,os=`${JSON.stringify(rs,void 0,2)}
|
|
10
|
-
`,pe=we&&X!==void 0?
|
|
11
|
-
`),w("architecture.ts",pe===void 0?"":
|
|
10
|
+
`,pe=we&&X!==void 0?Fo({...X,crons:g,functions:Q,httpRoutes:Xe,modules:Je,queues:P,schema:a,services:ie,topics:oe,workflows:B}):void 0,as=Yi(ns),cs=Xi(rs),nt=v(n,up),mr=R(nt),Oe=[];if(!e.dryRun){R(k)||Xs(k,{recursive:!0});const p=(te,ce)=>{Ve(v(k,te),ce),Oe.push(te)},w=(te,ce)=>{fp(v(k,te),ce),ce!==""&&Oe.push(te)};p("app.ts",es),p("dataModel.ts",f),p("api.ts",Kt),p("internal.ts",zt),p("server.ts",re),p("functions.ts",Bt),p("shard.ts",jt),p("crons.ts",Xt),p("vectors.ts",Jt),p("drizzle.global.ts",Ce.global),p("drizzle.shard.ts",Ce.shard),w("containers.ts",Ht),w("workflows.ts",Gt),w("agents.ts",Yt),w("queues.ts",Qt),w("scheduler.ts",fr),w("shardRegistry.ts",gr),w("durableObjects.ts",pr),w("seed.ts",Zt),w("collections.ts",Wt),gp(k,Qe),Oe.push(...Object.keys(Qe)),w("openapi.json",tt?is:""),w("openapi.ts",tt?as:""),w("openrpc.json",st?os:""),w("openrpc.ts",st?cs:""),w("architecture.json",pe===void 0?"":`${JSON.stringify(pe,void 0,2)}
|
|
11
|
+
`),w("architecture.ts",pe===void 0?"":Do(pe)),(!mr||e.updateSchemaBaseline===!0)&&Ve(nt,br(et))}if(t){const p=rt.now(),w=Math.round(p-s),te=Math.round(qt-s),ce=Math.round(p-qt);console.error(`@lunora/codegen: codegen took ${w.toString()}ms (discovery ${te.toString()}ms, emit ${ce.toString()}ms)`)}return{advisories:Ut,advisorContext:Ie,agents:c,architecture:pe,containers:u,cronTriggers:[...new Set([...po(g),...S])],generated:{agents:Yt,api:Kt,app:es,collections:Wt,containers:Ht,crons:Xt,dataModel:f,drizzleGlobal:Ce.global,drizzleShard:Ce.shard,functions:Bt,internal:zt,openApi:is,openApiModule:as,openRpc:os,openRpcModule:cs,queues:Qt,seed:Zt,server:re,shard:jt,vectors:Jt,workflows:Gt},migrations:Ne,outputDirectory:k,platformDiagnostics:K.diagnostics,queues:P,schemaSnapshot:et,schemaSnapshotPath:nt,workflows:B,writtenFiles:Oe}};export{up as SCHEMA_SNAPSHOT_FILENAME,Sp as createCodegenProject,hp as findTsconfig,Lm as refreshCodegenProject,Mm as runCodegen};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i}from"ts-morph";import{listLunoraSourceFiles as a,lunoraRelativePath as c,handlerOf as l}from"./isTestPath-CiIyKqhF.mjs";import{b as d,d as f}from"./attribution-DqqCSywo.mjs";import{c as u}from"./context-root-
|
|
1
|
+
import{Node as i}from"ts-morph";import{listLunoraSourceFiles as a,lunoraRelativePath as c,handlerOf as l}from"./isTestPath-CiIyKqhF.mjs";import{b as d,d as f}from"./attribution-DqqCSywo.mjs";import{c as u}from"./context-root-BP60x_VP.mjs";import{c as m}from"./classify-procedure-call-HrUyDQX0.mjs";const p=t=>{const r=t.getInitializer();if(!r||!i.isCallExpression(r))return;const e=m(r);if(!e||e.kind!=="query"&&e.kind!=="mutation")return;const o=l(r,e.receiver);return o?{exportName:f(t)??t.getName(),handler:o,kind:e.kind}:void 0},x=(t,r)=>{const e=t.getParent();return e&&i.isPropertyAccessExpression(e)&&e.getExpression()===t?`ctx.${r}.${e.getName()}`:`ctx.${r}`},h=(t,r,e)=>{const o=[];for(const n of u(t.handler,e))o.push({callee:x(n,e),exportName:t.exportName,file:r,kind:t.kind,line:n.getStartLineNumber()});return o},N=(t,r,e)=>{const o=[];for(const n of d(t)){const s=p(n);s&&o.push(...h(s,r,e))}return o},F=(t,r,e)=>{const o=[];for(const n of a(r)){const s=t.getSourceFile(n)??t.addSourceFileAtPath(n);o.push(...N(s,c(r,n),e))}return o};export{F as d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as s,SyntaxKind as d}from"ts-morph";import{unwrapExpression as l,memberAccessOf as P,bindingKeyName as C,findObjectProperty as p,isConstDeclaration as D,walkChain as A}from"./isTestPath-CiIyKqhF.mjs";import{f as v,g as I,h as M}from"./attribution-DqqCSywo.mjs";import{c as F}from"./classify-procedure-call-HrUyDQX0.mjs";import{isDefineMutatorCallee as b}from"./MUTATORS_FILENAME-
|
|
1
|
+
import{Node as s,SyntaxKind as d}from"ts-morph";import{unwrapExpression as l,memberAccessOf as P,bindingKeyName as C,findObjectProperty as p,isConstDeclaration as D,walkChain as A}from"./isTestPath-CiIyKqhF.mjs";import{f as v,g as I,h as M}from"./attribution-DqqCSywo.mjs";import{c as F}from"./classify-procedure-call-HrUyDQX0.mjs";import{isDefineMutatorCallee as b}from"./MUTATORS_FILENAME-Ba-gcGFd.mjs";const x=8,E=t=>{if(s.isMethodDeclaration(t))return t;const e=s.isPropertyAssignment(t)?l(t.getInitializer()):void 0,o=s.isShorthandPropertyAssignment(t)?t.getNameNode():e;if(s.isArrowFunction(o)||s.isFunctionExpression(o))return o;const i=s.isIdentifier(o)?v(o):void 0;if(s.isFunctionDeclaration(i))return i;const n=D(i)?l(i.getInitializer()):void 0;return s.isArrowFunction(n)||s.isFunctionExpression(n)?n:void 0},w=t=>{const e=l(t.getArguments()[0]),o=s.isObjectLiteralExpression(e)?e:void 0,i=p(o,"server"),n=p(o,"handler"),r=i!==void 0&&b(t.getExpression()),a=n===void 0?void 0:F(t),u=a!==void 0&&a.receiver===void 0;return[r?E(i):void 0,u?E(n):void 0].filter(f=>f!==void 0)},h=new WeakMap,O=t=>{const e=t.getSourceFile(),o=h.get(e.compilerNode);if(o!==void 0)return o;const i=new Set(e.getDescendantsOfKind(d.CallExpression).flatMap(n=>w(n)).map(n=>n.compilerNode));return h.set(e.compilerNode,i),i},S=t=>{const e=t.getParent();return(s.isArrowFunction(e)||s.isFunctionExpression(e)||s.isFunctionDeclaration(e)||s.isMethodDeclaration(e))&&e.getParameters()[0]===t&&O(t).has(e.compilerNode)},G=t=>{const e=t.getParent();return(s.isArrowFunction(e)||s.isFunctionExpression(e)||s.isFunctionDeclaration(e)||s.isMethodDeclaration(e))&&e.getParameters()[1]===t&&O(t).has(e.compilerNode)},T=t=>t.getNameNode().getDescendantsOfKind(d.BindingElement).some(e=>e.getParent().getParent()===t&&["args","ctx"].includes(C(e))),g=(t,e,o)=>{const i=t.getParent().getParent(),n=C(t);if(t.getDotDotDotToken()!==void 0||e==="trust"&&I(t))return;let r;if(s.isParameterDeclaration(i)){if(!S(i)||T(i))return n==="ctx"?[]:void 0;r=[]}else s.isBindingElement(i)?r=g(i,e,o):s.isVariableDeclaration(i)&&o>0&&(r=c(i.getInitializer(),e,o-1));return r===void 0?void 0:[...r,n]},c=(t,e="discover",o=x)=>{const i=l(t),n=P(i);if(n!==void 0){const r=c(n.object,e,o);return r===void 0?void 0:[...r,n.member]}return s.isIdentifier(i)?B(i,e,o):void 0},B=(t,e,o)=>{const i=t.getText()==="ctx",n=e==="trust"||!i?v(t):void 0;return i&&!s.isVariableDeclaration(n)?s.isBindingElement(n)?g(n,e,o):[]:s.isParameterDeclaration(n)?s.isIdentifier(n.getNameNode())&&S(n)?[]:void 0:s.isBindingElement(n)?g(n,e,o):!(s.isVariableDeclaration(n)&&s.isIdentifier(n.getNameNode())&&o>0)||e==="trust"&&I(n)?void 0:c(n.getInitializer(),e,o-1)},Q=t=>c(t,"discover"),H=t=>{const e=c(t);return e===void 0?void 0:["ctx",...e].join(".")},q=(t,e)=>{if(e(t.getText()))return!0;const o=H(t);return o!==void 0&&e(o)},J=(t,e)=>{const o=l(t),i=P(o);if(i!==void 0&&i.member!==e.at(-1))return!1;const n=o===void 0?void 0:c(o);return n?.length===e.length&&n.every((r,a)=>r===e[a])},Y=(t,e)=>U(t).get(e)??[],K=t=>{const e=new Map;for(const i of t.getDescendantsOfKind(d.BindingElement)){const n=s.isIdentifier(i.getNameNode())?g(i,"discover",x):void 0;n?.length===1&&n[0]!==void 0&&e.set(i.compilerNode,n[0])}const o=new Set([...e.keys()].map(i=>i.name.getText()));return t.getDescendantsOfKind(d.Identifier).flatMap(i=>{const r=o.has(i.getText())&&!s.isBindingElement(i.getParent())?v(i):void 0,a=r===void 0?void 0:e.get(r.compilerNode);return a===void 0?[]:[[a,i]]})},N=new WeakMap,U=t=>{const e=N.get(t.compilerNode);if(e!==void 0)return e;const o=new Map;for(const[n,r]of[...y(t),...K(t)])o.set(n,[...o.get(n)??[],r]);const i=new Map([...o].map(([n,r])=>[n,r.toSorted((a,u)=>a.getPos()-u.getPos())]));return N.set(t.compilerNode,i),i},y=t=>t.getDescendantsOfKind(d.PropertyAccessExpression).flatMap(e=>z(e.getExpression())?[[e.getName(),e]]:[]),z=t=>s.isIdentifier(t)&&c(t)?.length===0,Z=t=>{const e=c(t);return e?.length===1&&e[0]==="db"},_=new Set(["asId","createMultipartUpload","fetch","generateUploadUrl","getPresignedUrl","getSignedUrl","getUrl","normalizeId","resumeMultipartUpload","runAction","runMutation","runQuery","store","upload"]),R=new Set(["catch","flatMap","map","reduce","reduceRight","then"]),k=(t,e=x)=>{const o=A(t,u=>{const f=l(u.getExpression()),m=s.isPropertyAccessExpression(f)?f.getName():void 0;return m!==void 0&&(_.has(m)||R.has(m))?!1:void 0}),i=o.root;if(o.verdict!==void 0||!s.isIdentifier(i))return o.verdict??!1;if(c(i,"trust")!==void 0)return!0;const n=v(i),r=s.isBindingElement(n)?n.getFirstAncestorByKind(d.VariableDeclaration):n,a=D(r)&&e>0?r.getInitializer():void 0;return a!==void 0&&k(a,e-1)},$=t=>(s.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(o=>M(o)&&c(o,"trust")!==void 0);export{R as C,_ as E,G as a,H as b,Y as c,Z as d,Q as e,k as f,z as g,J as i,q as m,$ as r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SyntaxKind as g,Node as n}from"ts-morph";import{d as p}from"./context-root-
|
|
1
|
+
import{SyntaxKind as g,Node as n}from"ts-morph";import{d as p}from"./context-root-BP60x_VP.mjs";const c=e=>n.isPropertyAccessExpression(e)&&e.getName()==="db"||n.isIdentifier(e)&&e.getText()==="db"||p(e),l=new Set(["findFirst","findFirstOrThrow","findMany","findUnique"]),u=e=>{const t=e.getExpression();if(!n.isPropertyAccessExpression(t)||!l.has(t.getName()))return;const s=t.getExpression();if(c(s))return{options:e.getArguments()[1],table:d(e)};if(n.isPropertyAccessExpression(s)){const o=s.getExpression();if(c(o))return{options:e.getArguments()[0],table:s.getName()}}},f=(e,t)=>{const s=e.getExpression();return!n.isPropertyAccessExpression(s)||!t.has(s.getName())?!1:c(s.getExpression())},d=e=>{const t=e.getArguments()[0];return t&&n.isStringLiteral(t)?t.getLiteralText():""},m=(e,t,s)=>{const o=new Set,i=new Set;for(const a of e.getDescendantsOfKind(g.CallExpression))if(f(a,t)){const r=d(a);r!==""&&o.add(r)}else if(f(a,s)){const r=d(a);r!==""&&i.add(r)}return{tablesRead:[...o],tablesWritten:[...i]}};export{c as i,u as r,m as t};
|
package/dist/packem_shared/{discoverFunctions-BswBeUWK.mjs → discoverFunctions-DMW7bLkD.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as P}from"./declared-output-Iaar469J.mjs";import{findObjectProperty as c,bindingKeyName as b,listLunoraSourceFiles as N,lunoraRelativePath as A}from"./isTestPath-CiIyKqhF.mjs";import{e as F,i as O}from"./attribution-DqqCSywo.mjs";import{u as y,p as z,c as g,r as C}from"./unwrap-handler-return-
|
|
1
|
+
import{d as P}from"./declared-output-Iaar469J.mjs";import{findObjectProperty as c,bindingKeyName as b,listLunoraSourceFiles as N,lunoraRelativePath as A}from"./isTestPath-CiIyKqhF.mjs";import{e as F,i as O}from"./attribution-DqqCSywo.mjs";import{u as y,p as z,c as g,r as C}from"./unwrap-handler-return-BedChFbC.mjs";import{b as d,c as S}from"./classify-procedure-call-HrUyDQX0.mjs";import{Node as n,SyntaxKind as L}from"ts-morph";import{r as h,p as x,a as k}from"./parse-validator-DYdT7Hyf.mjs";import{s as I}from"./dispatch-namespace-DwTjD7BU.mjs";const T=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return"unknown";const t=c(e,"handler");if(!t||!n.isPropertyAssignment(t))return"unknown";const r=t.getInitializer();return!r||!(n.isArrowFunction(r)||n.isFunctionExpression(r))?"unknown":y(r)},w=i=>{const e=i.getArguments()[0];return!e||!(n.isArrowFunction(e)||n.isFunctionExpression(e))?"unknown":y(e)},V=i=>{let e={};for(const t of d(i)){if(t.name!=="input")continue;const r=t.call.getArguments()[0],s=r!==void 0&&n.isExpression(r)?h(r):void 0;s!==void 0&&(e={...x(s),...e})}return e},D=i=>{const e=d(i).find(r=>r.name==="output");if(!e)return;const t=e.call.getArguments()[0];return t&&n.isExpression(t)?z(e.call,()=>k(t)):void 0},p=(i,e)=>{const t=c(i,e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isStringLiteral(r)?r.getLiteralValue():void 0},v=(i,e)=>{const t=c(i,e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isNumericLiteral(r)?r.getLiteralValue():void 0},j=i=>{const e=c(i,"cache");if(e===void 0||!n.isPropertyAssignment(e))return;const t=e.getInitializer();if(t===void 0||!n.isObjectLiteralExpression(t))return;const r=p(t,"scope"),s=v(t,"maxAge"),o=v(t,"staleWhileRevalidate"),a=p(t,"tag"),l=p(t,"vary"),m={...s===void 0?{}:{maxAge:s},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...l===void 0?{}:{vary:l}};return Object.keys(m).length===0?void 0:m},B=i=>{if(i===void 0||!n.isObjectLiteralExpression(i))return{};const e=j(i),t=c(i,"rest");return t!==void 0&&n.isPropertyAssignment(t)?{...e===void 0?{}:{cache:e},rest:t.getInitializer()?.getText()==="true"}:e===void 0?{}:{cache:e}},R=i=>{const e=d(i).find(t=>t.name==="expose");return e?B(e.call.getArguments()[0]):void 0},M=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return{};const t=c(e,"args");if(!t||!n.isPropertyAssignment(t))return{};const r=t.getInitializer(),s=r===void 0?void 0:h(r);return s===void 0?{}:x(s)},$=8,u=(i,e=0)=>{if(e>$)return;if(n.isCallExpression(i))return i;if(n.isParenthesizedExpression(i)||n.isAsExpression(i)||n.isSatisfiesExpression(i)||n.isNonNullExpression(i))return u(i.getExpression(),e+1);if(!n.isIdentifier(i)&&!n.isPropertyAccessExpression(i))return;const t=i.getSymbol()?.getValueDeclaration();return t?f(t,e+1):void 0},f=(i,e)=>{if(n.isVariableDeclaration(i)||n.isPropertyAssignment(i)){const t=i.getInitializer();return t?u(t,e):void 0}if(n.isShorthandPropertyAssignment(i)){const t=i.getValueSymbol()?.getValueDeclaration();return t?f(t,e+1):void 0}if(n.isBindingElement(i)){const t=b(i),o=i.getFirstAncestorByKind(L.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return o?f(o,e+1):void 0}},W=(i,e=()=>!0)=>{const t=i.getNameNode();if(n.isObjectBindingPattern(t)){const o=[];for(const a of t.getElements().filter(l=>e(l.getName()))){const l=u(a.getNameNode());l&&o.push([a.getName(),l])}return o}if(!e(i.getName()))return[];const r=i.getInitializer(),s=r&&(n.isCallExpression(r)?r:u(r));return s?[[i.getName(),s]]:[]},_=i=>{const e=S(i);if(!e)return;const{receiver:t}=e;if(t){const r=R(t),s=g(()=>D(t)),o=g(()=>w(i)),a=P({kind:e.kind,output:s.value});return C(a?s.erased:o.erased),{args:V(t),...r?{expose:r}:{},kind:e.kind,...s.value?{output:s.value}:{},returnType:o.value,visibility:e.visibility}}return e.lifecycle?{args:{},kind:e.kind,lifecycle:e.lifecycle,returnType:"void",visibility:e.visibility}:{args:M(i),kind:e.kind,returnType:T(i),visibility:e.visibility}},E=(i,e,t)=>{const r=_(i);if(r)return{args:r.args,exportName:e,filePath:t,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},H=(i,e)=>{const t=[];for(const r of i.getExportAssignments()){if(r.isExportEquals())continue;const s=u(r.getExpression()),o=s?E(s,"default",e):void 0;o&&t.push(o)}return t},K=(i,e)=>{const t=F(i),r=i.getVariableStatements().flatMap(o=>o.getDeclarations()).flatMap(o=>W(o,a=>t.has(a))).flatMap(([o,a])=>(t.get(o)??[]).filter(l=>O(l)).flatMap(l=>E(a,l,e)??[])),s=new Set(r.map(o=>o.exportName));return r.push(...H(i,e).filter(o=>!s.has(o.exportName))),r},q=i=>{const e=new Map;for(const t of i){const r=I(t.filePath),s=e.get(r);if(s&&s!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${s}" and "${t.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[s,t.filePath],status:500});e.set(r,t.filePath)}},te=(i,e)=>{const t=N(e),r=[];for(const s of t){const o=i.getSourceFile(s)??i.addSourceFileAtPath(s),a=A(e,s);r.push(...K(o,a))}return r.sort((s,o)=>`${s.filePath}:${s.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),q(r),r};export{te as default};
|
package/dist/packem_shared/{discoverHttpRoutes-6utMwfNf.mjs → discoverHttpRoutes-C2ARoV_3.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as n}from"ts-morph";import{a as m,p as l}from"./parse-validator-DYdT7Hyf.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./isTestPath-CiIyKqhF.mjs";import{b as f,d as g}from"./attribution-DqqCSywo.mjs";import{u as x}from"./unwrap-handler-return-
|
|
1
|
+
import{Node as n}from"ts-morph";import{a as m,p as l}from"./parse-validator-DYdT7Hyf.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./isTestPath-CiIyKqhF.mjs";import{b as f,d as g}from"./attribution-DqqCSywo.mjs";import{u as x}from"./unwrap-handler-return-BedChFbC.mjs";const u=new Set(["delete","get","head","options","patch","post","put"]),E=new Set(["body","params","searchParams"]),v=new Set(["handler","stream"]),P=s=>{const e=s.getArguments()[0];if(e&&n.isStringLiteral(e))return e.getLiteralValue()},S=s=>{const e=s.getArguments()[0];return e&&n.isObjectLiteralExpression(e)?l(e):{}},A=s=>{if(!n.isCallExpression(s))return;const e=s.getExpression();if(!n.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const a=e.getExpression();if(!n.isIdentifier(a)||a.getText()!=="httpRoute")return;const t=P(s);return t===void 0?void 0:{method:o.toUpperCase(),path:t}},b=(s,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},a=s.getExpression();if(!n.isPropertyAccessExpression(a))return;let t=a.getExpression();for(;n.isCallExpression(t);){const i=t.getExpression();if(!n.isPropertyAccessExpression(i))break;const c=i.getName();if(u.has(c))break;if(E.has(c)){const p=S(t);o[c]={...p,...o[c]}}else if(c==="output"&&o.output===void 0){const p=t.getArguments()[0];p&&n.isExpression(p)&&(o.output=m(p))}t=i.getExpression()}const r=A(t);if(r)return o.method=r.method,o.path=r.path,o},T=s=>{const e=s.getArguments()[0];return!e||!(n.isArrowFunction(e)||n.isFunctionExpression(e))?"unknown":x(e)},y=(s,e,o,a)=>{const t=e.getName();if(!v.has(t))return;const r=b(s,t);if(!(r?.method===void 0||r.path===void 0))return{body:r.body,exportName:o,filePath:a,method:r.method,params:r.params,path:r.path,searchParams:r.searchParams,stream:r.stream,...r.stream?{chunkType:T(s)}:{},...r.output?{output:r.output}:{}}},R=(s,e)=>{const o=[];for(const a of f(s)){const t=a.getInitializer();if(!t||!n.isCallExpression(t))continue;const r=t.getExpression();if(!n.isPropertyAccessExpression(r))continue;const i=y(t,r,g(a)??a.getName(),e);i&&o.push(i)}return o},L=(s,e)=>{const o=d(e),a=[];for(const t of o){const r=s.getSourceFile(t)??s.addSourceFileAtPath(t),i=h(e,t);a.push(...R(r,i))}return a.sort((t,r)=>`${t.method} ${t.path}`.localeCompare(`${r.method} ${r.path}`)||t.filePath.localeCompare(r.filePath)),a};export{L as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as o}from"./context-property-calls-Bt-91_2v.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i}from"ts-morph";import{collectCallRows as n}from"./isTestPath-CiIyKqhF.mjs";import{c as a}from"./attribution-DqqCSywo.mjs";import{i as c}from"./database-calls-
|
|
1
|
+
import{Node as i}from"ts-morph";import{collectCallRows as n}from"./isTestPath-CiIyKqhF.mjs";import{c as a}from"./attribution-DqqCSywo.mjs";import{i as c}from"./database-calls-AHFbJnIy.mjs";const l=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="insert")return!1;const r=e.getExpression();return c(r)},g=t=>{if(!i.isIdentifier(t))return;const e=t.getSymbol(),r=e?.getAliasedSymbol()?.getDeclarations()??e?.getDeclarations()??[];for(const s of r)if(i.isVariableDeclaration(s)){const o=s.getInitializer();if(o&&i.isStringLiteral(o))return o.getLiteralText()}},f=t=>{const e=t.getArguments()[0];return e?i.isStringLiteral(e)?e.getLiteralText():g(e)??"":""},d=(t,e)=>n(t,e,(r,s)=>l(r)?{file:s,line:r.getStartLineNumber(),scope:a(r),table:f(r)}:void 0);export{d as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./isTestPath-CiIyKqhF.mjs";import"./attribution-DqqCSywo.mjs";import"./database-calls-AHFbJnIy.mjs";import"./classify-procedure-call-HrUyDQX0.mjs";import{d as a}from"./index-DET6xe1e.mjs";export{a as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i}from"ts-morph";import{collectCallRows as c}from"./isTestPath-CiIyKqhF.mjs";import{c as l}from"./attribution-DqqCSywo.mjs";import{i as f}from"./database-calls-
|
|
1
|
+
import{Node as i}from"ts-morph";import{collectCallRows as c}from"./isTestPath-CiIyKqhF.mjs";import{c as l}from"./attribution-DqqCSywo.mjs";import{i as f}from"./database-calls-AHFbJnIy.mjs";const u=new Set(["withGeoIndex","withIndex","withSearchIndex"]),p=new Set(["collect","collectWithScores","first","paginate","take","unique"]),m=n=>{const t=n.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="query")return!1;const e=t.getExpression();return f(e)},g=n=>{const t=[];let e=n;for(;;){const r=e.getParent();if(!r||!i.isPropertyAccessExpression(r))break;const s=r.getParent();if(!s||!i.isCallExpression(s))break;t.push(r.getName()),e=s}return t},d=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,E=n=>{let t=n;for(;;){const e=t.getParent();if(!e||!i.isPropertyAccessExpression(e))return!1;const r=e.getParent();if(!r||!i.isCallExpression(r))return!1;if(e.getName()==="filter"){const s=r.getArguments()[0];if(s&&d.test(s.getText()))return!0}t=r}},h=n=>{const t=n.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},y=(n,t)=>c(n,t,(e,r)=>{if(!m(e))return;const s=g(e),a=s.includes("filter");return{file:r,filtersPrimaryKey:a&&E(e),hasFilter:a,hasIndex:s.some(o=>u.has(o)),line:e.getStartLineNumber(),scope:l(e),table:h(e),terminal:s.findLast(o=>p.has(o))}});export{y as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as r}from"./context-property-calls-Bt-91_2v.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
|
package/dist/packem_shared/{discoverRlsProcedures-DllbV6_E.mjs → discoverRlsProcedures-D4udDEM2.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as o}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as f,findObjectProperty as u}from"./isTestPath-CiIyKqhF.mjs";import{b as p,d}from"./attribution-DqqCSywo.mjs";import{t as m}from"./database-calls-
|
|
1
|
+
import{Node as o}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as f,findObjectProperty as u}from"./isTestPath-CiIyKqhF.mjs";import{b as p,d}from"./attribution-DqqCSywo.mjs";import{t as m}from"./database-calls-AHFbJnIy.mjs";import{c as b}from"./classify-procedure-call-HrUyDQX0.mjs";import{r as g}from"./chain-DmRSLvAh.mjs";const h=e=>{const t=e.getArguments()[0];if(!t||!o.isArrayLiteralExpression(t))return[];const r=[];for(const s of t.getElements()){if(!o.isObjectLiteralExpression(s))continue;const i=u(s,"table");if(!i||!o.isPropertyAssignment(i))continue;const n=i.getInitializer();n&&o.isStringLiteral(n)&&r.push(n.getLiteralText())}return r},y=e=>{const t=g(e);return{rlsTables:t.flatMap(r=>h(r)),usesRls:t.length>0}},v=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),P=new Set(["delete","deleteMany","insert","insertMany","patch","patchMany","replace"]),T=(e,t)=>{if(!o.isVariableDeclaration(e))return;const r=e.getInitializer();if(!r||!o.isCallExpression(r))return;const s=b(r);if(!s)return;const i=s.receiver?y(s.receiver):{rlsTables:[],usesRls:!1},{tablesRead:n,tablesWritten:a}=m(e,v,P);return{exportName:d(e)??e.getName(),file:t,rlsTables:i.rlsTables,tablesRead:n,tablesWritten:a,usesRls:i.usesRls,visibility:s.visibility}},O=(e,t)=>{const r=[];for(const s of c(t)){const i=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=f(t,s);for(const a of p(i)){const l=T(a,n);l&&r.push(l)}}return r};export{O as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as f}from"./isTestPath-CiIyKqhF.mjs";import{b as m,d as p}from"./attribution-DqqCSywo.mjs";import{t as d}from"./database-calls-
|
|
1
|
+
import{Node as i}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as f}from"./isTestPath-CiIyKqhF.mjs";import{b as m,d as p}from"./attribution-DqqCSywo.mjs";import{t as d}from"./database-calls-AHFbJnIy.mjs";import{w as g,c as h}from"./classify-procedure-call-HrUyDQX0.mjs";import{a as k}from"./project-config-file-Bv2l-Kmm.mjs";const l=e=>{if(!(!i.isPropertyAssignment(e)&&!i.isShorthandPropertyAssignment(e)&&!i.isMethodDeclaration(e)&&!i.isGetAccessorDeclaration(e)))return k(e)},v=e=>g(e,"use","mask"),D=e=>{if(i.isPropertyAssignment(e)){const s=e.getInitializer();if(s&&i.isStringLiteral(s)){const t=s.getLiteralText();if(t==="redact"||t==="hash")return t}}return"custom"},P=e=>{const s=e.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return[];const t=[];for(const r of s.getProperties()){const o=l(r);if(o===void 0||!i.isPropertyAssignment(r))continue;const n=r.getInitializer();if(!(!n||!i.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=l(a);c!==void 0&&t.push({column:c,table:o})}}return t},y=e=>{const s=v(e);return{maskColumns:s.flatMap(t=>P(t)),usesMask:s.length>0}},C=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),M=new Set(["delete","insert","patch","replace"]),b=(e,s)=>{if(!i.isVariableDeclaration(e))return;const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const r=h(t);if(!r)return;const o=r.receiver?y(r.receiver):{maskColumns:[],usesMask:!1},{tablesRead:n,tablesWritten:a}=d(e,C,M);return{exportName:p(e)??e.getName(),file:s,maskColumns:o.maskColumns,tablesRead:n,tablesWritten:a,usesMask:o.usesMask,visibility:r.visibility}},E=(e,s)=>{const t=[];for(const r of u(s)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=f(s,r);for(const a of m(o)){const c=b(a,n);c&&t.push(c)}}return t};export{l as a,E as d,v as m,D as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as l,SyntaxKind as g,DiagnosticCategory as j}from"ts-morph";import{lunoraRelativePath as P}from"./isTestPath-CiIyKqhF.mjs";import{posix as h}from"node:path";let S,v;const _e=e=>{const t=S,r=[];S=r;try{return{erased:r,value:e()}}finally{S=t}},Re=e=>{S?.push(...e)},U=e=>{for(const t of e.getAncestors())if(l.isVariableDeclaration(t))return t.getName()},E=(e,t)=>{S?.push({exportName:U(e),filePath:e.getSourceFile().getFilePath(),line:e.getStartLineNumber(),rendered:t})},$e=e=>{v!==void 0&&E(v,e)},Ce=(e,t)=>{const r=v;v=e;try{return t()}finally{v=r}},K=(e,t)=>{const r=e.exportName??`line ${e.line.toString()}`;return{cacheKey:`procedure_return_type_erased:${t}:${r}`,categories:["SCHEMA"],description:"Codegen renders a procedure's return type into `_generated/`, where only names that resolve from that directory may appear. A type it can neither name nor reproduce structurally — a class instance, a call or index signature, a recursive or very deeply nested shape — is emitted as `unknown` instead, so callers lose the shape while the runtime still returns it.",detail:`\`${r}\` in \`${t}\` (line ${e.line.toString()}) returns \`${e.rendered}\`, which codegen could not reproduce — its generated type is \`unknown\`.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e.exportName,filePath:t,line:e.line,rendered:e.rendered},name:"procedure_return_type_erased",remediation:"Declare the shape explicitly with `.output(...)`, or export the type from the module that declares it so codegen can name it. A class instance cannot cross the wire at all — return a plain object.",title:"Procedure return type is missing from the generated type"}},ke=(e,t)=>{const r=new Map;for(const n of e){const s=K(n,P(t,n.filePath));r.set(s.cacheKey,s)}return[...r.values()].toSorted((n,s)=>n.cacheKey.localeCompare(s.cacheKey))},F=/\bany\b(?!\s*(?:\?\s*)?:)/u,B=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,V=e=>F.test(e.replaceAll(B,"")),W="/_generated/",q=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(r=>r?.getDeclarations()??[]);return t.length>0&&t.every(r=>r.getSourceFile().getSymbol()===void 0)},G=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,N=e=>{for(const t of e.getAncestors())if(l.isModuleDeclaration(t)){const r=G.exec(t.getName());if(r?.groups?.specifier!==void 0)return r.groups.specifier}},w=new WeakMap,X=(e,t)=>{const r=e.getSymbol();if(r===void 0)return;let n=w.get(r.compilerSymbol);return n===void 0&&(n=new Map,w.set(r.compilerSymbol,n)),n.has(t)||n.set(t,r.getExport(t)??e.getExportSymbols().find(s=>s.getName()===t)),n.get(t)},$=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(r=>r.getName()===t),H=(e,t,r)=>e.getModuleSpecifierValue()===t&&$(e,r)?r:void 0,Y=(e,t)=>{const r=e.getDefaultImport();if(r===void 0)return;const n=r.getSymbol();return(n?.getAliasedSymbol()??n)?.getDeclarations().includes(t)===!0?"default":void 0},J=(e,t,r)=>{if(!$(e,r))return;const n=e.getModuleSpecifierSourceFile(),s=n===void 0?void 0:X(n,r);return(s?.getAliasedSymbol()??s)?.getDeclarations().includes(t)===!0?r:void 0},z=/^\.\.?(?:$|\/)/u,Q=new Map([[".cjs",".cjs"],[".cts",".cjs"],[".d.ts",".js"],[".js",".js"],[".jsx",".jsx"],[".mjs",".mjs"],[".mts",".mjs"],[".ts",".js"],[".tsx",".js"]]),Z=(e,t)=>{const r=t.getModuleSpecifierValue();if(!z.test(r))return;const n=t.getModuleSpecifierSourceFile(),s=n===void 0?void 0:Q.get(n.getExtension());if(n===void 0||s===void 0)return;const o=`${h.join(n.getDirectoryPath(),n.getBaseNameWithoutExtension())}${s}`,i=h.relative(e.getDirectoryPath(),o);return i.startsWith(".")?i:`./${i}`},ee=(e,t,r)=>{const n=N(t);for(const s of e.getImportDeclarations()){const o=n===void 0?Y(s,t)??J(s,t,r):H(s,n,r);if(o!==void 0)return{exportName:o,specifier:Z(e,s)??s.getModuleSpecifierValue()}}},te=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(r=>{const n=r.indexOf("*");return n===-1?e===r:e.startsWith(r.slice(0,n))&&e.endsWith(r.slice(n+1))}),f={kind:"verbatim"},p={kind:"expand"},re=new Set([g.ClassDeclaration,g.EnumDeclaration,g.EnumMember,g.InterfaceDeclaration,g.TypeAliasDeclaration]),ne=e=>N(e)!==void 0||l.isExportable(e)&&e.isExported(),se=(e,t)=>new RegExp(String.raw`(?<![$\w])${t.replaceAll(/[$()*+.?[\\\]^{|}]/gu,String.raw`\$&`)}(?![$\w])`,"u").test(e),C=(e,t,r,n)=>{const s=e.getSourceFile();if(s.getSymbol()===void 0&&N(e)===void 0||!re.has(e.getKind()))return f;const o=s.getFilePath();if(o.includes(W))return f;if(o===r)return p;const i=l.isEnumMember(e)?e.getParent():e;if(!l.hasName(i))return p;const a=ee(t.getSourceFile(),i,i.getName());return a===void 0?ne(i)||!se(n(),i.getName())?f:p:te(a.specifier,t)?p:{kind:"qualify",qualified:a}},oe=new Set([g.ClassDeclaration,g.EnumDeclaration,g.FunctionDeclaration,g.ModuleDeclaration]),M=e=>{const t=e?.getDeclarations()??[];return t.length>0&&t.every(r=>r.getSourceFile().getSymbol()===void 0)},ie=e=>{for(const t of e.getDeclarations()){const r=t.getFirstChildByKind(g.ComputedPropertyName);if(r!==void 0){let n=r.getExpression();for(;l.isPropertyAccessExpression(n);)n=n.getExpression();return n}}},ae=(e,t)=>{if(e.getProperties().some(s=>{if(!s.getName().startsWith("__@"))return!1;const o=ie(s);return o===void 0||!M(o.getSymbol())}))return!0;const n=e.getSymbol();return n!==void 0&&n.getDeclarations().some(s=>oe.has(s.getKind()))&&!M(n)&&t().startsWith("typeof ")},k=(e,t,r)=>{const n=e.getAliasSymbol(),s=e.getSymbol(),o=new Set((n??s)?.getDeclarations());let i=!1,a;const c=()=>(a??=e.getText(t),a);for(const u of[s,n].flatMap(d=>d?.getDeclarations()??[])){const d=C(u,t,r,c);if(d.kind==="qualify"&&o.has(u))return d;i||=d.kind!=="verbatim"}return i||ae(e,c)?p:f},ce=(e,t,r)=>{const n=l.isPropertySignature(e)||l.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(n===void 0)return f;let s=!1;for(const o of[n,...n.getDescendantsOfKind(g.TypeReference)].filter(i=>l.isTypeReference(i))){const i=o.getTypeName().getSymbol();for(const a of(i?.getAliasedSymbol()??i)?.getDeclarations()??[]){const c=C(a,t,r,()=>o.getText());if(c.kind==="qualify")return c;s||=c.kind!=="verbatim"}}return s?p:f},ue=/^[A-Za-z_$][\w$]*$/u,le=e=>ue.test(e)?e:JSON.stringify(e),O=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},A=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0&&!e.getProperties().some(t=>t.getName().startsWith("__@")),T=(e,t,r,n=new Set)=>n.has(e)?!1:(n.add(e),k(e,t,r).kind!=="verbatim"||O(e).some(s=>T(s,t,r,n))?!0:A(e)?e.getProperties().some(s=>s.getDeclarations().some(o=>ce(o,t,r).kind!=="verbatim")?!0:T(s.getTypeAtLocation(t),t,r,n)):!1),ge=(e,t)=>{const r=e.getValueDeclaration()??e.getDeclarations()[0];return r&&(l.isPropertySignature(r)||l.isPropertyDeclaration(r))&&r.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(n=>n.isUndefined())},L=(e,t)=>e!==void 0&&(A(e)||e.isString()||e.isNumber()||e.isBigInt()||e.isBoolean()||e.isLiteral()||e.isBooleanLiteral()||e.isEnumLiteral()||e.isTemplateLiteral()||e.isNull()||e.isUndefined()||e.isAny()||e.isUnknown()||e.isNever()||e.isVoid())?t:`(${t})`,de=32,fe=8,me=(e,t,r,n,s,o)=>{const i=e.getArrayElementType(),a=i?o(i,t,r,n,s):void 0;if(a!==void 0)return`${L(i,a)}[]`},pe=(e,t,r,n,s,o)=>{const i=[];for(const a of e.getUnionTypes()){const c=o(a,t,r,n,s);if(c===void 0)return;i.push(c)}return i.join(" | ")},Se=(e,t,r,n,s,o)=>{const i=[];for(const a of e.getIntersectionTypes()){const c=o(a,t,r,n,s);if(c===void 0)return;i.push(L(a,c))}return i.join(" & ")},ve=(e,t,r,n,s,o)=>{if(!A(e))return;const i=[];for(const a of e.getProperties()){const c=a.getTypeAtLocation(t),u=ge(a,c),d=u&&c.isUnion()?c.getUnionTypes().filter(x=>!x.isUndefined()):[c],D=[];for(const x of d){const I=o(x,t,r,n+1,s);if(I===void 0)return;D.push(I)}i.push(`${le(a.getName())}${u?"?":""}: ${D.join(" | ")}`)}return i.length>0?`{ ${i.join("; ")} }`:"{}"},Ee=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},be=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isClassDeclaration(t)||l.isClassExpression(t)),b=(e,t,r,n,s=new Set)=>{if(n.has(e)||s.has(e))return!1;if(r>de)return!0;const o=new Set(n).add(e);if(O(e).some(u=>b(u,t,r+1,o,s)))return!0;const i=e.getArrayElementType();if(i!==void 0)return b(i,t,r+1,o,s);if(q(e))return s.add(e),!1;if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(u=>u?.getDeclarations()??[]).some(u=>l.isClassDeclaration(u)||l.isClassExpression(u)))return!0;const c=A(e)&&e.getProperties().some(u=>b(u.getTypeAtLocation(t),t,r+1,o,s));return c||s.add(e),c},ye=(e,t,r,n,s,o,i)=>{const a=[];for(const c of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const u=i(c,r,n,s+1,o);if(u===void 0)return;a.push(u)}return`import("${e.specifier}").${e.exportName}${a.length>0?`<${a.join(", ")}>`:""}`},Te=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isEnumDeclaration(t)||l.isEnumMember(t)),m=(e,t,r,n,s)=>{if(n>fe||s.has(e))return;const o=k(e,t,r);if(o.kind==="verbatim"&&!T(e,t,r))return e.getText(t);const i=new Set(s).add(e);if(!be(e)){if(e.isEnumLiteral())return Ee(e);if(o.kind==="qualify"&&!Te(e)){const a=ye(o.qualified,e,t,r,n,i,m);if(a!==void 0)return a}return e.isArray()?me(e,t,r,n,i,m):e.isUnion()?pe(e,t,r,n,i,m):e.isIntersection()?Se(e,t,r,n,i,m):ve(e,t,r,n,i,m)}},_=new WeakMap,Ae=e=>{const t=_.get(e);if(t)return t;const r=e.getPreEmitDiagnostics().filter(n=>n.getCategory()===j.Error);return _.set(e,r),r},y=e=>{const t=e.getMessageText();return typeof t=="string"?t:t.getMessageText()},xe=/is of type 'unknown'|on type '\{\}'/,Ne=e=>xe.test(e),De=/has no exported member '([^']+)'/,Ie=(e,t,r,n)=>{const s=e.getSourceFile();for(const o of e.getDescendantsOfKind(g.Identifier))for(const i of o.getSymbol()?.getDeclarations()??[]){const a=i.getStart();if(i.getSourceFile()!==s||a>=r&&a<=n)continue;const c=t.find(u=>{const d=u.getStart();return d!==void 0&&d>=i.getStart()&&d<=i.getEnd()});if(c!==void 0)return y(c)}},R=e=>{const t=e.getStart(),r=e.getEnd(),n=Ae(e.getSourceFile()),s=n.find(c=>{const u=c.getStart();return u!==void 0&&u>=t&&u<=r});if(s===void 0){const c=Ie(e,n,t,r);return c===void 0?void 0:{derivative:!0,message:c}}const o=y(s);if(!Ne(o))return{derivative:!1,message:o};const i=new Set(e.getDescendantsOfKind(g.Identifier).map(c=>c.getText())),a=n.find(c=>{const u=De.exec(y(c))?.[1];return u!==void 0&&i.has(u)});return{derivative:!0,message:a?`${o}; caused by: ${y(a)}`:o}},Oe=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let r=t.getReturnType();const s=(r.getSymbol()??r.getAliasSymbol())?.getName();if(s==="Promise"||s==="AsyncIterable"||s==="AsyncIterableIterator"||s==="AsyncGenerator"){const a=r.getTypeArguments()[0];a&&(r=a)}const o=r.getText(e);if(!o||o==="any"||o==="never"||o==="unknown"){const a=R(e);return a!==void 0&&(o!=="unknown"||a.derivative)&&E(e,`${o||"any"} (${a.message})`),"unknown"}if(V(o)){const a=R(e);return a!==void 0&&E(e,`${o} (${a.message})`),"unknown"}if(b(r,e,0,new Set))return"unknown";const i=e.getSourceFile().getFilePath();if(T(r,e,i)){const a=m(r,e,i,0,new Set);return a===void 0&&E(e,o),a??"unknown"}return o};export{T as a,$e as b,_e as c,ke as d,m as e,V as i,Ce as p,Re as r,Oe as u};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/codegen",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.285",
|
|
4
4
|
"description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@lunora/advisor": "1.0.0-alpha.203",
|
|
50
|
-
"@lunora/agent": "1.0.0-alpha.
|
|
51
|
-
"@lunora/container": "1.0.0-alpha.
|
|
50
|
+
"@lunora/agent": "1.0.0-alpha.191",
|
|
51
|
+
"@lunora/container": "1.0.0-alpha.72",
|
|
52
52
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
53
53
|
"@lunora/platform": "1.0.0-alpha.58",
|
|
54
54
|
"@lunora/queue": "1.0.0-alpha.97",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as o}from"./context-property-calls-0qzW2Joh.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./isTestPath-CiIyKqhF.mjs";import"./attribution-DqqCSywo.mjs";import"./database-calls-CBlsQTga.mjs";import"./classify-procedure-call-HrUyDQX0.mjs";import{d as a}from"./index-BfaSHMNi.mjs";export{a as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as r}from"./context-property-calls-0qzW2Joh.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Node as l,SyntaxKind as g}from"ts-morph";import{lunoraRelativePath as L}from"./isTestPath-CiIyKqhF.mjs";import{posix as D}from"node:path";let S,v;const Ae=e=>{const t=S,n=[];S=n;try{return{erased:n,value:e()}}finally{S=t}},Te=e=>{S?.push(...e)},j=e=>{for(const t of e.getAncestors())if(l.isVariableDeclaration(t))return t.getName()},w=(e,t)=>{S?.push({exportName:j(e),filePath:e.getSourceFile().getFilePath(),line:e.getStartLineNumber(),rendered:t})},Ne=e=>{v!==void 0&&w(v,e)},xe=(e,t)=>{const n=v;v=e;try{return t()}finally{v=n}},k=(e,t)=>{const n=e.exportName??`line ${e.line.toString()}`;return{cacheKey:`procedure_return_type_erased:${t}:${n}`,categories:["SCHEMA"],description:"Codegen renders a procedure's return type into `_generated/`, where only names that resolve from that directory may appear. A type it can neither name nor reproduce structurally — a class instance, a call or index signature, a recursive or very deeply nested shape — is emitted as `unknown` instead, so callers lose the shape while the runtime still returns it.",detail:`\`${n}\` in \`${t}\` (line ${e.line.toString()}) returns \`${e.rendered}\`, which codegen could not reproduce — its generated type is \`unknown\`.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e.exportName,filePath:t,line:e.line,rendered:e.rendered},name:"procedure_return_type_erased",remediation:"Declare the shape explicitly with `.output(...)`, or export the type from the module that declares it so codegen can name it. A class instance cannot cross the wire at all — return a plain object.",title:"Procedure return type is missing from the generated type"}},De=(e,t)=>{const n=new Map;for(const r of e){const s=k(r,L(t,r.filePath));n.set(s.cacheKey,s)}return[...n.values()].toSorted((r,s)=>r.cacheKey.localeCompare(s.cacheKey))},P=/\bany\b(?!\s*(?:\?\s*)?:)/u,U=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,O=e=>P.test(e.replaceAll(U,"")),K="/_generated/",B=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(n=>n?.getDeclarations()??[]);return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},F=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,T=e=>{for(const t of e.getAncestors())if(l.isModuleDeclaration(t)){const n=F.exec(t.getName());if(n?.groups?.specifier!==void 0)return n.groups.specifier}},h=new WeakMap,V=(e,t)=>{const n=e.getSymbol();if(n===void 0)return;let r=h.get(n.compilerSymbol);return r===void 0&&(r=new Map,h.set(n.compilerSymbol,r)),r.has(t)||r.set(t,n.getExport(t)??e.getExportSymbols().find(s=>s.getName()===t)),r.get(t)},_=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(n=>n.getName()===t),W=(e,t,n)=>e.getModuleSpecifierValue()===t&&_(e,n)?n:void 0,q=(e,t)=>{const n=e.getDefaultImport();if(n===void 0)return;const r=n.getSymbol();return(r?.getAliasedSymbol()??r)?.getDeclarations().includes(t)===!0?"default":void 0},G=(e,t,n)=>{if(!_(e,n))return;const r=e.getModuleSpecifierSourceFile(),s=r===void 0?void 0:V(r,n);return(s?.getAliasedSymbol()??s)?.getDeclarations().includes(t)===!0?n:void 0},X=/^\.\.?(?:$|\/)/u,H=new Map([[".cjs",".cjs"],[".cts",".cjs"],[".d.ts",".js"],[".js",".js"],[".jsx",".jsx"],[".mjs",".mjs"],[".mts",".mjs"],[".ts",".js"],[".tsx",".js"]]),Y=(e,t)=>{const n=t.getModuleSpecifierValue();if(!X.test(n))return;const r=t.getModuleSpecifierSourceFile(),s=r===void 0?void 0:H.get(r.getExtension());if(r===void 0||s===void 0)return;const i=`${D.join(r.getDirectoryPath(),r.getBaseNameWithoutExtension())}${s}`,o=D.relative(e.getDirectoryPath(),i);return o.startsWith(".")?o:`./${o}`},J=(e,t,n)=>{const r=T(t);for(const s of e.getImportDeclarations()){const i=r===void 0?q(s,t)??G(s,t,n):W(s,r,n);if(i!==void 0)return{exportName:i,specifier:Y(e,s)??s.getModuleSpecifierValue()}}},z=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(n=>{const r=n.indexOf("*");return r===-1?e===n:e.startsWith(n.slice(0,r))&&e.endsWith(n.slice(r+1))}),m={kind:"verbatim"},p={kind:"expand"},Q=new Set([g.ClassDeclaration,g.EnumDeclaration,g.EnumMember,g.InterfaceDeclaration,g.TypeAliasDeclaration]),Z=e=>T(e)!==void 0||l.isExportable(e)&&e.isExported(),ee=(e,t)=>new RegExp(String.raw`(?<![$\w])${t.replaceAll(/[$()*+.?[\\\]^{|}]/gu,String.raw`\$&`)}(?![$\w])`,"u").test(e),M=(e,t,n,r)=>{const s=e.getSourceFile();if(s.getSymbol()===void 0&&T(e)===void 0||!Q.has(e.getKind()))return m;const i=s.getFilePath();if(i.includes(K))return m;if(i===n)return p;const o=l.isEnumMember(e)?e.getParent():e;if(!l.hasName(o))return p;const a=J(t.getSourceFile(),o,o.getName());return a===void 0?Z(o)||!ee(r(),o.getName())?m:p:z(a.specifier,t)?p:{kind:"qualify",qualified:a}},te=new Set([g.ClassDeclaration,g.EnumDeclaration,g.FunctionDeclaration,g.ModuleDeclaration]),I=e=>{const t=e?.getDeclarations()??[];return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},ne=e=>{for(const t of e.getDeclarations()){const n=t.getFirstChildByKind(g.ComputedPropertyName);if(n!==void 0){let r=n.getExpression();for(;l.isPropertyAccessExpression(r);)r=r.getExpression();return r}}},re=(e,t)=>{if(e.getProperties().some(s=>{if(!s.getName().startsWith("__@"))return!1;const i=ne(s);return i===void 0||!I(i.getSymbol())}))return!0;const r=e.getSymbol();return r!==void 0&&r.getDeclarations().some(s=>te.has(s.getKind()))&&!I(r)&&t().startsWith("typeof ")},R=(e,t,n)=>{const r=e.getAliasSymbol(),s=e.getSymbol(),i=new Set((r??s)?.getDeclarations());let o=!1,a;const c=()=>(a??=e.getText(t),a);for(const u of[s,r].flatMap(d=>d?.getDeclarations()??[])){const d=M(u,t,n,c);if(d.kind==="qualify"&&i.has(u))return d;o||=d.kind!=="verbatim"}return o||re(e,c)?p:m},se=(e,t,n)=>{const r=l.isPropertySignature(e)||l.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(r===void 0)return m;let s=!1;for(const i of[r,...r.getDescendantsOfKind(g.TypeReference)].filter(o=>l.isTypeReference(o))){const o=i.getTypeName().getSymbol();for(const a of(o?.getAliasedSymbol()??o)?.getDeclarations()??[]){const c=M(a,t,n,()=>i.getText());if(c.kind==="qualify")return c;s||=c.kind!=="verbatim"}}return s?p:m},oe=/^[A-Za-z_$][\w$]*$/u,ie=e=>oe.test(e)?e:JSON.stringify(e),$=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},y=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0&&!e.getProperties().some(t=>t.getName().startsWith("__@")),E=(e,t,n,r=new Set)=>r.has(e)?!1:(r.add(e),R(e,t,n).kind!=="verbatim"||$(e).some(s=>E(s,t,n,r))?!0:y(e)?e.getProperties().some(s=>s.getDeclarations().some(i=>se(i,t,n).kind!=="verbatim")?!0:E(s.getTypeAtLocation(t),t,n,r)):!1),ae=(e,t)=>{const n=e.getValueDeclaration()??e.getDeclarations()[0];return n&&(l.isPropertySignature(n)||l.isPropertyDeclaration(n))&&n.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},C=(e,t)=>e!==void 0&&(y(e)||e.isString()||e.isNumber()||e.isBigInt()||e.isBoolean()||e.isLiteral()||e.isBooleanLiteral()||e.isEnumLiteral()||e.isTemplateLiteral()||e.isNull()||e.isUndefined()||e.isAny()||e.isUnknown()||e.isNever()||e.isVoid())?t:`(${t})`,ce=32,ue=8,le=(e,t,n,r,s,i)=>{const o=e.getArrayElementType(),a=o?i(o,t,n,r,s):void 0;if(a!==void 0)return`${C(o,a)}[]`},ge=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getUnionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(c)}return o.join(" | ")},de=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getIntersectionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(C(a,c))}return o.join(" & ")},me=(e,t,n,r,s,i)=>{if(!y(e))return;const o=[];for(const a of e.getProperties()){const c=a.getTypeAtLocation(t),u=ae(a,c),d=u&&c.isUnion()?c.getUnionTypes().filter(A=>!A.isUndefined()):[c],N=[];for(const A of d){const x=i(A,t,n,r+1,s);if(x===void 0)return;N.push(x)}o.push(`${ie(a.getName())}${u?"?":""}: ${N.join(" | ")}`)}return o.length>0?`{ ${o.join("; ")} }`:"{}"},fe=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},pe=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isClassDeclaration(t)||l.isClassExpression(t)),b=(e,t,n,r,s=new Set)=>{if(r.has(e)||s.has(e))return!1;if(n>ce)return!0;const i=new Set(r).add(e);if($(e).some(u=>b(u,t,n+1,i,s)))return!0;const o=e.getArrayElementType();if(o!==void 0)return b(o,t,n+1,i,s);if(B(e))return s.add(e),!1;if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(u=>u?.getDeclarations()??[]).some(u=>l.isClassDeclaration(u)||l.isClassExpression(u)))return!0;const c=y(e)&&e.getProperties().some(u=>b(u.getTypeAtLocation(t),t,n+1,i,s));return c||s.add(e),c},Se=(e,t,n,r,s,i,o)=>{const a=[];for(const c of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const u=o(c,n,r,s+1,i);if(u===void 0)return;a.push(u)}return`import("${e.specifier}").${e.exportName}${a.length>0?`<${a.join(", ")}>`:""}`},ve=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isEnumDeclaration(t)||l.isEnumMember(t)),f=(e,t,n,r,s)=>{if(r>ue||s.has(e))return;const i=R(e,t,n);if(i.kind==="verbatim"&&!E(e,t,n))return e.getText(t);const o=new Set(s).add(e);if(!pe(e)){if(e.isEnumLiteral())return fe(e);if(i.kind==="qualify"&&!ve(e)){const a=Se(i.qualified,e,t,n,r,o,f);if(a!==void 0)return a}return e.isArray()?le(e,t,n,r,o,f):e.isUnion()?ge(e,t,n,r,o,f):e.isIntersection()?de(e,t,n,r,o,f):me(e,t,n,r,o,f)}},he=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let n=t.getReturnType();const s=(n.getSymbol()??n.getAliasSymbol())?.getName();if(s==="Promise"||s==="AsyncIterable"||s==="AsyncIterableIterator"||s==="AsyncGenerator"){const a=n.getTypeArguments()[0];a&&(n=a)}const i=n.getText(e);if(!i||i==="any"||i==="never"||O(i)||b(n,e,0,new Set))return"unknown";const o=e.getSourceFile().getFilePath();if(E(n,e,o)){const a=f(n,e,o,0,new Set);return a===void 0&&w(e,i),a??"unknown"}return i};export{E as a,Ne as b,Ae as c,De as d,f as e,O as i,xe as p,Te as r,he as u};
|