@lunora/codegen 1.0.0-alpha.134 → 1.0.0-alpha.136
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/{GENERATED_HEADER-etEAWhHs.mjs → GENERATED_HEADER-Juc2KRT1.mjs} +1 -1
- package/dist/packem_shared/{MUTATORS_FILENAME-cczs0N_f.mjs → MUTATORS_FILENAME-VnV3vpJh.mjs} +1 -1
- package/dist/packem_shared/{NOTIFY_FILENAME-3hraPVOT.mjs → NOTIFY_FILENAME-3xSHPaVK.mjs} +1 -1
- package/dist/packem_shared/{OPENRPC_VERSION-l-E_pTg8.mjs → OPENRPC_VERSION-CtO1oRu-.mjs} +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DIVmMUEJ.mjs +9 -0
- package/dist/packem_shared/{buildOpenApiDocument-DBUr_qe5.mjs → buildOpenApiDocument-B3l1QPs9.mjs} +1 -1
- package/dist/packem_shared/discoverFunctions-2ajN70Q9.mjs +1 -0
- package/dist/packem_shared/{discoverHttpRoutes-oVY4IQQz.mjs → discoverHttpRoutes-DDhmUyVN.mjs} +1 -1
- package/dist/packem_shared/{discoverMaskProcedures-BbiYrDLQ.mjs → discoverMaskProcedures-CjfyneNc.mjs} +1 -1
- package/dist/packem_shared/{discoverNondeterministicCalls-BcWKCkrg.mjs → discoverNondeterministicCalls-CSI5ir3L.mjs} +1 -1
- package/dist/packem_shared/{discoverR2sqlCalls-Dy7i757M.mjs → discoverR2sqlCalls-NtUJIKqo.mjs} +1 -1
- package/dist/packem_shared/{discoverRlsMetadata-BqCbCx8m.mjs → discoverRlsMetadata-BA9lVt-Q.mjs} +1 -1
- package/dist/packem_shared/{discoverStorageRulesMetadata-Demj7Q4c.mjs → discoverStorageRulesMetadata-DudvC-VM.mjs} +1 -1
- package/dist/packem_shared/{emit-DBZKVUBi.mjs → emit-khv5P1pH.mjs} +1 -1
- package/dist/packem_shared/{emitApp-wqZEBJxy.mjs → emitApp-CZ_yiNNO.mjs} +1 -1
- package/package.json +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DNjZUvv7.mjs +0 -9
- package/dist/packem_shared/discoverFunctions-5SwUVBO6.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-CftvRWB8.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as S}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as E,diagnosticAt as x}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-CPHo8Se5.mjs";import{default as g}from"./packem_shared/discoverAuthApiCalls-DUjcl0SB.mjs";import{CONTAINERS_FILENAME as R,discoverContainers as M}from"./packem_shared/CONTAINERS_FILENAME-Bvn6LZP6.mjs";import{default as C}from"./packem_shared/discoverCrons-BUJO2ipU.mjs";import{FLAGS_FILENAME as T,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-DtBWyUKq.mjs";import{discoverFunctions as F}from"./packem_shared/discoverFunctions-
|
|
1
|
+
import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CftvRWB8.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as S}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as E,diagnosticAt as x}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-CPHo8Se5.mjs";import{default as g}from"./packem_shared/discoverAuthApiCalls-DUjcl0SB.mjs";import{CONTAINERS_FILENAME as R,discoverContainers as M}from"./packem_shared/CONTAINERS_FILENAME-Bvn6LZP6.mjs";import{default as C}from"./packem_shared/discoverCrons-BUJO2ipU.mjs";import{FLAGS_FILENAME as T,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-DtBWyUKq.mjs";import{discoverFunctions as F}from"./packem_shared/discoverFunctions-2ajN70Q9.mjs";import{default as P}from"./packem_shared/discoverHttpRoutes-DDhmUyVN.mjs";import{default as G}from"./packem_shared/discoverInserts-YX8AmrzL.mjs";import{default as b}from"./packem_shared/discoverMaskProcedures-CjfyneNc.mjs";import{default as y}from"./packem_shared/discoverMigrations-4Jjf5DJE.mjs";import{MUTATORS_FILENAME as j,discoverMutators as K}from"./packem_shared/MUTATORS_FILENAME-VnV3vpJh.mjs";import{default as z}from"./packem_shared/discoverNondeterministicCalls-CSI5ir3L.mjs";import{NOTIFY_FILENAME as w,discoverNotifyCalls as q,discoverNotifyConfig as B}from"./packem_shared/NOTIFY_FILENAME-3xSHPaVK.mjs";import{default as Y}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as Z}from"./packem_shared/discover-queries-Dfj_0WJG.mjs";import{QUEUES_FILENAME as ee,discoverQueues as re}from"./packem_shared/QUEUES_FILENAME-BnGLtAIu.mjs";import{default as te}from"./packem_shared/discoverR2sqlCalls-NtUJIKqo.mjs";import{discoverRlsMetadata as ae,default as ie}from"./packem_shared/discoverRlsMetadata-BA9lVt-Q.mjs";import{discoverSandboxUsage as de}from"./packem_shared/discoverSandboxUsage-L0lV17de.mjs";import{default as pe}from"./packem_shared/discoverSchema-Hsu_1xIc.mjs";import{SHAPES_FILENAME as ne,discoverShapes as Se}from"./packem_shared/SHAPES_FILENAME-BTdasTq2.mjs";import{default as Ee}from"./packem_shared/discoverStorageRulesMetadata-DudvC-VM.mjs";import{WORKFLOWS_FILENAME as Ae,discoverWorkflows as ue}from"./packem_shared/WORKFLOWS_FILENAME-B8y51Frf.mjs";import{G as Ne,e as ge,a as Oe,b as Re,c as Me,d as he,f as Ce,g as _e,h as Te,i as Ie,j as Le,k as Fe,l as De,m as Pe}from"./packem_shared/emit-khv5P1pH.mjs";import{emitApp as Ge}from"./packem_shared/emitApp-CZ_yiNNO.mjs";import{buildOpenApiDocument as be,emitOpenApi as ke,emitOpenApiModule as ye}from"./packem_shared/buildOpenApiDocument-B3l1QPs9.mjs";import{OPENRPC_VERSION as je,buildOpenRpcDocument as Ke,emitOpenRpc as Ve,emitOpenRpcModule as ze}from"./packem_shared/OPENRPC_VERSION-CtO1oRu-.mjs";import{DEFAULT_TARGET as we,platformMatrixIds as qe,readProjectTarget as Be,resolveCodegenTarget as Je}from"./packem_shared/DEFAULT_TARGET-CrhWLUK7.mjs";import{SCHEMA_SNAPSHOT_FILENAME as Xe,createCodegenProject as Ze,findTsconfig as $e,refreshCodegenProject as er,runCodegen as rr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-DIVmMUEJ.mjs";import{SchemaSnapshotParseError as tr,buildSchemaSnapshot as sr,evaluateSchemaDrift as ar,parseSchemaSnapshot as ir}from"./packem_shared/SchemaSnapshotParseError-D2h88OHU.mjs";import{schemaFromIr as dr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as pr,validatorIrToJsonSchema as cr}from"./packem_shared/LUNORA_ERROR_CODES-BYg8Lpgb.mjs";import{SDK_LANGUAGES as Sr,SDK_TARGETS as lr,generateSdk as Er}from"./packem_shared/SDK_LANGUAGES-CFyux-74.mjs";import{redact as Ar,secretKindOf as ur}from"./packem_shared/redact-Cy14LEnc.mjs";import{MESSAGE_SOLUTIONS as Nr,findSolutionByMessage as gr}from"@lunora/errors";import{isTypedSchema as Rr}from"./packem_shared/isTypedSchema-B_qlBbE-.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,R as CONTAINERS_FILENAME,E as CodegenDiagnosticError,we as DEFAULT_TARGET,T as FLAGS_FILENAME,Ne as GENERATED_HEADER,pr as LUNORA_ERROR_CODES,Nr as LUNORA_SOLUTION_RULES,j as MUTATORS_FILENAME,w as NOTIFY_FILENAME,je as OPENRPC_VERSION,ee as QUEUES_FILENAME,Xe as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,Sr as SDK_LANGUAGES,lr as SDK_TARGETS,ne as SHAPES_FILENAME,tr as SchemaSnapshotParseError,e as VERSION,Ae as WORKFLOWS_FILENAME,be as buildOpenApiDocument,Ke as buildOpenRpcDocument,sr as buildSchemaSnapshot,Ze as createCodegenProject,c as describeErrorLevelFindings,x as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,g as discoverAuthApiCalls,M as discoverContainers,C as discoverCrons,I as discoverFlags,F as discoverFunctions,P as discoverHttpRoutes,G as discoverInserts,b as discoverMaskProcedures,y as discoverMigrations,K as discoverMutators,z as discoverNondeterministicCalls,q as discoverNotifyCalls,B as discoverNotifyConfig,Z as discoverQueries,re as discoverQueues,te as discoverR2sqlCalls,ae as discoverRlsMetadata,ie as discoverRlsProcedures,de as discoverSandboxUsage,pe as discoverSchema,Se as discoverShapes,Ee as discoverStorageRulesMetadata,ue as discoverWorkflows,ge as emitAgents,Oe as emitApi,Ge as emitApp,Re as emitCollections,Me as emitContainers,he as emitCrons,Ce as emitDataModel,_e as emitDrizzleSchema,Te as emitFunctions,ke as emitOpenApi,ye as emitOpenApiModule,Ve as emitOpenRpc,ze as emitOpenRpcModule,Ie as emitServer,Le as emitShard,Fe as emitVectors,De as emitWorkflows,Pe as emitWranglerCronTriggers,n as errorAdvisoryNames,S as errorPlatformDiagnosticNames,ar as evaluateSchemaDrift,gr as findLunoraSolution,$e as findTsconfig,m as formatAdvisories,Er as generateSdk,Rr as isTypedSchema,d as lintSchema,ir as parseSchemaSnapshot,qe as platformMatrixIds,Y as readPackageDependencies,Be as readProjectTarget,Ar as redact,er as refreshCodegenProject,Je as resolveCodegenTarget,rr as runCodegen,dr as schemaFromIr,ur as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,cr as validatorIrToJsonSchema};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./SCHEMA_SNAPSHOT_VERSION-CftvRWB8.mjs";import{G as t,U as m,n as r,e as o,a as n,b as l,c as A,d as E,f as S,g,h as C,o as c,p as d,i as p,j as u,k as D,l as f,m as h}from"./emit-
|
|
1
|
+
import"./SCHEMA_SNAPSHOT_VERSION-CftvRWB8.mjs";import{G as t,U as m,n as r,e as o,a as n,b as l,c as A,d as E,f as S,g,h as C,o as c,p as d,i as p,j as u,k as D,l as f,m as h}from"./emit-khv5P1pH.mjs";import"./paths-C-9fwEgQ.mjs";export{t as GENERATED_HEADER,m as UMBRELLA_BASE_PACKAGES,r as buildStorageColumns,o as emitAgents,n as emitApi,l as emitCollections,A as emitContainers,E as emitCrons,S as emitDataModel,g as emitDrizzleSchema,C as emitFunctions,c as emitQueues,d as emitSeed,p as emitServer,u as emitShard,D as emitVectors,f as emitWorkflows,h as emitWranglerCronTriggers};
|
package/dist/packem_shared/{MUTATORS_FILENAME-cczs0N_f.mjs → MUTATORS_FILENAME-VnV3vpJh.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as f}from"node:fs";import{join as p}from"node:path";import{Node as o,SyntaxKind as u}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapHandlerReturn as g}from"./discoverFunctions-
|
|
1
|
+
import{existsSync as f}from"node:fs";import{join as p}from"node:path";import{Node as o,SyntaxKind as u}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapHandlerReturn as g}from"./discoverFunctions-2ajN70Q9.mjs";import{a as d}from"./module-specifiers-WF8iAydP.mjs";import{a as x}from"./parse-validator-BFTp87yz.mjs";const M="mutators.ts",m=d,y=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineMutator";for(const e of t.getDeclarations())if(o.isImportSpecifier(e))return m(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineMutator":!1;return!1},S=r=>{const t=r.getSymbol();if(!t)return!1;for(const e of t.getDeclarations()){if(!o.isNamespaceImport(e))continue;const i=e.getFirstAncestorByKind(u.ImportDeclaration);return i!==void 0&&m(i.getModuleSpecifierValue())}return!1},N=r=>{if(o.isIdentifier(r))return y(r);if(o.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(t)&&S(t)}return!1},I=r=>{const t=r.getArguments()[0];return t&&o.isObjectLiteralExpression(t)?t:void 0},b=r=>{const t=r?.getProperty("args");if(!t||!o.isPropertyAssignment(t))return{};const e=t.getInitializer();return e&&o.isObjectLiteralExpression(e)?x(e):{}},A=r=>{const t=r?.getProperty("server");if(!t||!o.isPropertyAssignment(t))return"unknown";const e=t.getInitializer();return!e||!(o.isArrowFunction(e)||o.isFunctionExpression(e))?"unknown":g(e)},E=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const i=e.getInitializer();if(i?.getKind()!==u.CallExpression)continue;const n=i,a=n.getExpression();if(!N(a))continue;const s=e.getNameNode();if(!o.isIdentifier(s))throw l(s,"defineMutator exports must be plain named exports (no destructuring)");const c=I(n);t.push({args:b(c),exportName:s.getText(),filePath:"mutators",returnType:A(c)})}return t},w=(r,t)=>{const e=p(t,M);if(!f(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),n=E(i);return n.sort((a,s)=>a.exportName.localeCompare(s.exportName)),n};export{M as MUTATORS_FILENAME,w as discoverMutators,N as isDefineMutatorCallee};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as m}from"node:fs";import{join as x}from"node:path";import{SyntaxKind as d,Node as c}from"ts-morph";import{l,a as g,d as P,h as E}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as S}from"./discoverFunctions-
|
|
1
|
+
import{existsSync as m}from"node:fs";import{join as x}from"node:path";import{SyntaxKind as d,Node as c}from"ts-morph";import{l,a as g,d as P,h as E}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as S}from"./discoverFunctions-2ajN70Q9.mjs";const y="notify.ts",v=new Set(["chat","inApp","send","webhook"]),p=new Set(["broadcast","send"]),N=e=>{const t=e.getInitializer();if(!t||!c.isCallExpression(t))return;const o=S(t);if(!o)return;const s=E(t,o.receiver);return s?{exportName:e.getName(),handler:s,kind:o.kind}:void 0},h=e=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const s of o.getDeclarations()){const r=N(s);r&&t.push(r)}return t},f=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=e.getExpression();if((t==="notify"||t==="push")&&c.isIdentifier(o)&&o.getText()==="ctx")return t;if(t==="push"&&f(o)==="notify")return"push"},F=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=f(e.getExpression());if(o==="notify"&&v.has(t))return`ctx.notify.${t}`;if(o==="push"&&p.has(t))return`ctx.push.${t}`},A=e=>c.isPropertyAccessExpression(e)?f(e.getExpression())==="push"&&p.has(e.getName()):!1,T=(e,t)=>{const o=[];for(const s of l(t)){const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),a=g(t,s);for(const n of h(r))if(!(n.kind!=="query"&&n.kind!=="mutation"))for(const i of n.handler.getDescendantsOfKind(d.PropertyAccessExpression)){const u=F(i);u!==void 0&&o.push({callee:u,exportName:n.exportName,file:a,kind:n.kind,line:i.getStartLineNumber()})}}return o},O=(e,t)=>{for(const o of l(t)){const s=e.getSourceFile(o)??e.addSourceFileAtPath(o);for(const r of h(s))for(const a of r.handler.getDescendantsOfKind(d.PropertyAccessExpression))if(A(a))return!0}return!1},_=(e,t)=>{const o=x(t,y);if(!m(o))return;const s=e.getSourceFile(o)??e.addSourceFileAtPath(o),r=P(s);let a=!1,n=!1;if(r&&c.isCallExpression(r)){const i=r.getArguments()[0];i&&c.isObjectLiteralExpression(i)&&(a=i.getProperty("webPush")!==void 0,n=i.getProperty("fcm")!==void 0)}return{hasFcm:n,hasWebPush:a,usesPush:O(e,t)}};export{y as NOTIFY_FILENAME,T as discoverNotifyCalls,_ as discoverNotifyConfig};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{G as c}from"./emit-
|
|
1
|
+
import{G as c}from"./emit-khv5P1pH.mjs";import{s as u}from"./paths-C-9fwEgQ.mjs";import{validatorIrToJsonSchema as m,objectSchema as p,LUNORA_ERROR_CODES as i}from"./LUNORA_ERROR_CODES-BYg8Lpgb.mjs";const l="1.3.2",d={description:"Result is TS-inferred from the function's return type (no `.output()` declared); best-effort — any JSON."},R=e=>{const n=u(e.filePath),o=`${n}:${e.exportName}`;return{description:`Invoke the \`${e.kind}\` \`${o}\` over the Lunora RPC envelope (POST /_lunora/rpc, body \`{ "functionPath": "${o}", "args": { … } }\`).`,errors:i.map((r,s)=>({code:-32e3-s,data:{code:r},message:r})),name:o,params:[{description:"The function's argument object (the RPC envelope's `args`).",name:"args",required:Object.keys(e.args).length>0,schema:p(e.args)}],result:{name:"result",schema:e.output?m(e.output):d},summary:`${e.kind}: ${o}`,"x-lunora-function-kind":e.kind,"x-tags":[{name:n}]}},g=e=>{const n=e.version??"0.0.0",r=e.functions.filter(t=>t.visibility!=="internal"&&t.kind!=="stream").map(t=>R(t)).toSorted((t,a)=>t.name.localeCompare(a.name));return{info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora RPC",version:n},methods:r,openrpc:l}},S=e=>`${JSON.stringify(g(e),void 0,2)}
|
|
2
2
|
`,v=e=>`${c}export const openRpcSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
|
|
3
3
|
`;export{l as OPENRPC_VERSION,g as buildOpenRpcDocument,S as emitOpenRpc,v as emitOpenRpcModule};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import{existsSync as y,mkdirSync as Xt,readFileSync as vt,writeFileSync as Zt,rmSync as Jt}from"node:fs";import{join as f,dirname as ue}from"node:path";import{performance as de}from"node:perf_hooks";import{runAdvisor as es}from"@lunora/advisor";import{LunoraError as D}from"@lunora/errors";import{SyntaxKind as l,Node as i,Project as Ye}from"ts-morph";import{serializeSchemaSnapshot as ts}from"./SCHEMA_SNAPSHOT_VERSION-CftvRWB8.mjs";import{toAdvisorContext as ss}from"./formatAdvisories-CkEu1eye.mjs";import{discoverAgents as ns}from"./AGENTS_FILENAME-CPHo8Se5.mjs";import{discoverContainers as rs}from"./CONTAINERS_FILENAME-Bvn6LZP6.mjs";import{diagnosticAt as ee}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as te}from"./module-specifiers-WF8iAydP.mjs";import{C as fe,i as is,f as os,n as as,j as cs,b as ls,c as us,l as ds,e as fs,o as ps,d as gs,k as ms,g as hs,p as xs,m as Es,a as vs,h as Ss}from"./emit-khv5P1pH.mjs";import{l as m,a as x,c as b,p as A,f as St,h as As,i as Ns,r as At,e as ys}from"./discover-ast-D33zP-NZ.mjs";import bs from"./readPackageDependencies-C6h6FZuP.mjs";import{discoverQueues as Is}from"./QUEUES_FILENAME-BnGLtAIu.mjs";import{discoverSandboxUsage as Ps}from"./discoverSandboxUsage-L0lV17de.mjs";import ws from"./discoverStorageRulesMetadata-DudvC-VM.mjs";import{discoverWorkflows as Ts}from"./WORKFLOWS_FILENAME-B8y51Frf.mjs";import{gatePlatformFeatures as Cs,resolveCodegenTarget as Rs}from"./DEFAULT_TARGET-CrhWLUK7.mjs";import{i as T,a as k,e as v,c as P,r as Os,b as Fs,s as se,f as Ls,g as Ds,d as ks}from"./discover-queries-Dfj_0WJG.mjs";import{classifyProcedureCall as M,inlineHandler as Ms,procedureHandler as Nt,chainUsesWrappedCall as yt,isDatabaseAccessor as _,chainHasStep as Ks,discoverFunctions as Qe,resolveStandardSchemaType as _s}from"./discoverFunctions-2ajN70Q9.mjs";import zs from"./discoverAuthApiCalls-DUjcl0SB.mjs";import Us from"./discoverCrons-BUJO2ipU.mjs";import{discoverFlagKeys as Bs}from"./FLAGS_FILENAME-DtBWyUKq.mjs";import Xe from"./discoverHttpRoutes-DDhmUyVN.mjs";import qs from"./discoverInserts-YX8AmrzL.mjs";import $s,{discoverMaskStrategies as js,discoverMaskMetadata as Vs,discoverMaskHasNonLiteralPolicy as Ws}from"./discoverMaskProcedures-CjfyneNc.mjs";import Hs from"./discoverMigrations-4Jjf5DJE.mjs";import{MUTATORS_FILENAME as Gs,isDefineMutatorCallee as Ys,discoverMutators as Ze}from"./MUTATORS_FILENAME-VnV3vpJh.mjs";import Qs from"./discoverNondeterministicCalls-CSI5ir3L.mjs";import{discoverNotifyConfig as Xs,discoverNotifyCalls as Zs}from"./NOTIFY_FILENAME-3xSHPaVK.mjs";import Js from"./discoverR2sqlCalls-NtUJIKqo.mjs";import en,{discoverRlsMetadata as tn}from"./discoverRlsMetadata-BA9lVt-Q.mjs";import sn from"./discoverSchema-Hsu_1xIc.mjs";import{secretKindOf as nn,redact as rn,isHeuristicSecretKind as on,isSecretishName as an}from"./redact-Cy14LEnc.mjs";import{discoverShapes as cn}from"./SHAPES_FILENAME-BTdasTq2.mjs";import{emitApp as ln}from"./emitApp-CZ_yiNNO.mjs";import{buildOpenApiDocument as un,emitOpenApiModule as dn}from"./buildOpenApiDocument-B3l1QPs9.mjs";import{buildOpenRpcDocument as fn,emitOpenRpcModule as pn}from"./OPENRPC_VERSION-CtO1oRu-.mjs";import{s as gn}from"./parse-validator-BFTp87yz.mjs";import{buildSchemaSnapshot as mn}from"./SchemaSnapshotParseError-D2h88OHU.mjs";const hn=e=>{const t=[],s=e.tables.filter(n=>n.shardMode==="global");return s.some(n=>n.globalBackend!=="hyperdrive")&&t.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),s.some(n=>n.globalBackend==="hyperdrive")&&t.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'}),e.vectorIndexes.length>0&&t.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/vectors.ts` import `@lunora/bindings/vectors`"}),t},xn=(e,t)=>{if(t===void 0)return;const s=hn(e).filter(o=>!t.has(o.name));if(s.length===0)return;const n=s.map(o=>` - ${o.name} — ${o.reason}`).join(`
|
|
2
|
+
`);throw new D("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
|
|
3
|
+
${n}
|
|
4
|
+
|
|
5
|
+
Install them with your package manager, then re-run codegen.`)},En="env.ts",vn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return te(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},Sn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&te(n.getModuleSpecifierValue())}return!1},An=e=>{if(i.isIdentifier(e))return vn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&Sn(t)}return!1},Nn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!An(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw ee(r,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},yn=(e,t)=>{const s=f(t,En);if(!y(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=Nn(n);if(o.length!==0){if(o.length>1)throw ee(n,`lunora/env.ts declares ${o.length.toString()} defineEnv() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},bn=e=>{const t=n=>i.isIdentifier(n)&&n.getText()==="ctx",s=new Set;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression))t(n.getExpression())&&s.add(n.getName());for(const n of e.getDescendantsOfKind(l.VariableDeclaration)){const o=n.getInitializer(),r=n.getNameNode();if(!(o===void 0||!t(o)||!i.isObjectBindingPattern(r)))for(const a of r.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},In=(e,t)=>{const s=Object.fromEntries(fe.map(n=>[n.key,!1]));for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=new Set(o.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=bn(o);for(const c of fe)if(!s[c.key]){if(r.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(fe.every(c=>s[c.key]))break}return s},Pn=["providerSubscriptionId","state"],wn=["providerEventId","processedAt"],Je=(e,t)=>t.every(s=>s in e.shape),Tn=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&Je(t,Pn)&&Je(s,wn)},Cn=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings/kv"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),bt="identity.ts",Rn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return te(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},On=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&te(n.getModuleSpecifierValue())}return!1},Fn=e=>{if(i.isIdentifier(e))return Rn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&On(t)}return!1},Ln=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!Fn(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw ee(r,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},Dn=(e,t)=>{const s=f(t,bt);if(!y(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=Ln(n);if(o.length!==0){if(o.length>1)throw ee(n,`lunora/identity.ts declares ${o.length.toString()} defineIdentity() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},kn=(e,t)=>{const s=new Map,n=new Map,o=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.bindingName,`workflow "${r.exportName}"`),o.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const a=s.get(r.name);if(a!==void 0)throw new D("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${a} and agent "${r.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=n.get(r.bindingName);if(c!==void 0)throw new D("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${r.bindingName}": produced by both ${c} and agent "${r.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const u=o.get(r.className);if(u!==void 0)throw new D("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${u} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},Mn=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:o}=e,r=Dn(s,t),a=yn(s,t),c=Ts(s,t),u=Is(s,t),d=ns(s,t);kn(c,d);const E=rs(s,t),N=ws(s,t),p=Cs(In(s,t),Rs(n,e.target)),S=p.usage,C=Ps(s,t),R=S.browser||C.usesSandboxBrowser,O=bs(n),j=O??new Set,F=j.has("lunorash");xn(o,O);const K=y(f(t,"flags.ts")),z=y(f(t,"notify.ts"));return{agents:d,containers:E,dataModelContent:os(o),declaredDependencies:O,dependencies:j,env:a,featureUsage:S,hasBrowser:R,hasFlags:K,hasNotify:z,identity:r,platformGate:p,queues:u,serverContent:is({agents:d,containers:E,env:a,hasAccessFacade:S.access,hasAi:S.ai,hasAnalytics:S.analytics,hasBrowser:R,hasFlags:K,hasHyperdrive:S.hyperdrive,hasImages:S.images,hasKv:S.kv,hasNotify:z,hasPayments:S.payments,hasPipelines:S.pipelines,hasR2sql:S.r2sql,hasX402:S.x402,identity:r,queues:u,schema:o,storageRuleBuckets:N.rules.map(re=>re.bucket),useUmbrella:F,workflows:c}),storageRulesMetadata:N,usesSandbox:C.usesSandboxBrowser||C.usesSandboxContainer,useUmbrella:F,workflows:c}},It=new Set(["delete","get","head","options","patch","post","put"]),Kn=new Set(["handler","stream"]),_n=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,et=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),zn=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!It.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()}},Un=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)||It.has(n.getName()))break;s=n.getExpression()}return zn(s)},Bn=e=>{for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression))if(et.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&et.has(s.getText()))return!0}return!1},qn=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||!Kn.has(n.getName()))return;const o=Un(s);if(!o||!_n.test(o.path))return;const r=s.getArguments()[0],a=r!==void 0&&(i.isArrowFunction(r)||i.isFunctionExpression(r))&&Bn(r);return{exportName:e.getName(),file:t,method:o.method,path:o.path,usesGuard:a}},$n=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=qn(o,t);r&&s.push(r)}return s},jn=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...$n(o,x(t,n)))}return s},Vn=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",Wn=(e,t)=>{if(!Vn(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!T(s)||k(s)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},Hn=(e,t)=>b(e,t,Wn),Gn=new Set(["generateText","streamText"]),Yn=new Set(["messages","prompt","system"]),Qn=[{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"]}],Xn=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const o of Qn)if(o.methods.has(s)&&o.prefixes.some(r=>n===r||n.startsWith(`${r}.`)))return`${n}.${s}`},Zn=e=>{for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=Xn(t);if(s!==void 0)return s}},Jn=e=>{const t=new Set,s=e.getFirstAncestor(r=>i.isArrowFunction(r)||i.isFunctionExpression(r)||i.isFunctionDeclaration(r)),[n]=s?.getParameters()??[],o=n?.getNameNode();if(o===void 0||!i.isObjectBindingPattern(o))return t;for(const r of o.getElements()){const a=r.getPropertyNameNode()?.getText()??r.getName(),c=r.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const u of c.getElements())t.add(u.getName())}return t},er=e=>{if(Os(e))return!0;const t=Jn(e);return t.size===0?!1:e.getDescendantsOfKind(l.Identifier).some(s=>t.has(s.getText()))},tr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!Yn.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&er(s))return!0}return!1},sr=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=P(n.getExpression());if(o===void 0||!Gn.has(o))continue;const[r]=n.getArguments();if(r===void 0||!i.isObjectLiteralExpression(r))continue;let a;for(const c of r.getDescendantsOfKind(l.CallExpression))if(P(c.getExpression())==="tool"&&(a=Zn(c),a!==void 0))break;a!==void 0&&s.push({exportName:v(n),file:t,line:n.getStartLineNumber(),method:o,sideEffect:a,userInputDerived:tr(r)})}return s},nr=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...sr(o,x(t,n)))}return s},rr=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},ir=(e,t)=>{if(!rr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!T(s)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},or=(e,t)=>b(e,t,ir),Pt=e=>e.getProperties().some(t=>i.isSpreadAssignment(t)),ar=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer();return!n||!i.isObjectLiteralExpression(n)?{objects:[],opaque:!0}:{objects:[n],opaque:Pt(n)}},cr=e=>{const t=[];let s=!1,n=e;for(;i.isCallExpression(n);){const o=n.getExpression();if(!i.isPropertyAccessExpression(o))break;if(o.getName()==="input"){const r=n.getArguments()[0];r&&i.isObjectLiteralExpression(r)?(t.push(r),s||=Pt(r)):s=!0}n=o.getExpression()}return{objects:t,opaque:s}},wt=(e,t)=>t?cr(t):ar(e),lr=e=>e.flatMap(t=>t.getProperties().filter(s=>i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)).map(s=>s.getName())),ur=/\.check\(|\.meta\(|length|max/iu,dr=/\bv\.any\s*\(/u,fr=/\bv\.string\s*\(/u,pr=e=>dr.test(e),gr=e=>fr.test(e)&&!ur.test(e),mr=e=>{const t=[],s=[];for(const n of e)for(const o of n.getProperties()){if(!i.isPropertyAssignment(o))continue;const r=o.getInitializer();if(!r)continue;const a=r.getText(),c=o.getName();pr(a)?t.push(c):gr(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},hr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=M(s);if(n?.visibility!=="public")return;const{objects:o}=wt(s,n.receiver),{anyArgs:r,unboundedStringArgs:a}=mr(o);if(!(r.length===0&&a.length===0))return{anyArgs:r,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},xr=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=hr(o,t);r&&s.push(r)}return s},Er=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...xr(o,x(t,n)))}return s},pe=e=>e?.getKind()===l.TrueKeyword,vr=e=>e?.getKind()===l.FalseKeyword,Sr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Ar=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Nr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&P(t.getExpression())==="scim"),yr=e=>e!==void 0&&i.isCallExpression(e)&&Ar.has(P(e.getExpression())??""),br=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),Ir=e=>{const t=A(e,"advanced"),s=A(e,"emailAndPassword"),n=A(e,"session");return{analyzable:!0,disableCsrfCheck:pe(A(t,"disableCSRFCheck")),emailPasswordEnabled:pe(A(s,"enabled")),requireEmailVerification:pe(A(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Nr(A(e,"plugins"))&&yr(A(e,"database")),secureCookiesDisabled:vr(A(t,"useSecureCookies")),sessionFreshAgeZero:Sr(A(n,"freshAge")),trustedOriginsWildcard:br(A(e,"trustedOrigins"))}},Pr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),wr=(e,t)=>{if(P(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(r=>i.isSpreadAssignment(r)),o=s!==void 0&&i.isObjectLiteralExpression(s)&&!n?Ir(s):Pr();return{exportName:v(e),file:t,line:e.getStartLineNumber(),...o}},Tr=(e,t)=>b(e,t,wr),Cr=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},Rr=(e,t,s)=>{const n=Cr(e.getExpression(),s);if(n===void 0)return;const o=e.getArguments()[s.argIndex];if(!(!o||!T(o)||k(o))&&!(s.requireUnmodifiedReach===!0&&!Fs(o)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:n}},Or=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression)){const r=Rr(o,t,s);r&&n.push(r)}return n},ne=(e,t,s)=>{const n=[];for(const o of m(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...Or(r,x(t,o),s))}return n},Fr=new Set(["content","pdf","scrape","screenshot"]),Lr=(e,t)=>ne(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Fr}),Dr=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),kr=new Set(["RateLimiter"]),Mr=new Set(["extend"]),Tt=e=>{const t=[],s=[];let n=!1;for(const o of e.getProperties()){if(i.isSpreadAssignment(o)){n=!0;continue}if(i.isPropertyAssignment(o)){const r=o.getName();t.push(r),o.getInitializer()?.getKind()===l.TrueKeyword&&s.push(r);continue}(i.isShorthandPropertyAssignment(o)||i.isMethodDeclaration(o))&&t.push(o.getName())}return{analyzable:!n,presentKeys:t,trueKeys:s}},tt=e=>e&&i.isObjectLiteralExpression(e)?Tt(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Kr=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!i.isReturnStatement(s))return;const n=s.getExpression();return n!==void 0&&i.isObjectLiteralExpression(n)?n:void 0},_r=e=>{if(i.isObjectLiteralExpression(e))return e;if(i.isParenthesizedExpression(e)){const t=e.getExpression();return i.isObjectLiteralExpression(t)?t:void 0}return i.isBlock(e)?Kr(e):void 0},zr=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&_r(t.getBody());return s?Tt(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Ur=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=P(n.getExpression());o!==void 0&&(Dr.has(o)?s.push({callee:o,file:t,line:n.getStartLineNumber(),...tt(n.getArguments()[0])}):Mr.has(o)&&s.push({callee:o,file:t,line:n.getStartLineNumber(),...zr(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(l.NewExpression)){const o=P(n.getExpression());o===void 0||!kr.has(o)||s.push({callee:o,file:t,line:n.getStartLineNumber(),...tt(n.getArguments()[0])})}return s},Br=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ur(o,x(t,n)))}return s},st="ctx.containers.",qr=e=>{if(!e.startsWith(st))return!1;const t=e.slice(st.length);return t.length>0&&!t.includes(".")},$r=(e,t)=>ne(e,t,{argIndex:0,matchReceiver:qr,methods:new Set(["get"])}),jr=new Set(["allow","deny","setAllowed"]),Vr=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},Wr=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!Vr(e)))return{detail:"enableInternet: true",exportName:v(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},Hr=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!jr.has(s.getName()))return;const n=s.getExpression();if(!(!i.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),exportName:v(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},Gr=(e,t)=>Wr(e,t)??Hr(e,t),Yr=(e,t)=>b(e,t,Gr),Qr=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Xr=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return Qr.has(s)?s:void 0},Zr=e=>{const t=[],s=[];for(const n of e.getProperties()){if(i.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o);const r=n.getInitializer();r&&i.isStringLiteral(r)&&r.getLiteralText()===""&&s.push(o);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n)||i.isGetAccessorDeclaration(n))&&t.push(n.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Jr=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression)){const c=Xr(a);if(c===void 0)continue;const u=a.getArguments()[0],d=u&&i.isObjectLiteralExpression(u)?Zr(u):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:d.analyzable,emptyKeys:d.emptyKeys,factory:c,file:r,line:a.getStartLineNumber(),presentKeys:d.presentKeys})}}return s},ei=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),ti=new Set(["dbRateLimit","rateLimit"]),si=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&i.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===l.TrueKeyword},ni=(e,t)=>{const s=P(e.getExpression());if(s===void 0)return;const n=ei.get(s);if(n!==void 0)return{callee:s,exportName:v(e),failOpen:si(e.getArguments()[n]),file:t,limitName:ti.has(s)?St(e):"",line:e.getStartLineNumber()}},ri=(e,t)=>b(e,t,ni),ii=e=>{const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const s=M(t);if(s?.kind!=="query")return;const n=As(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},nt=e=>{const t=e.getParent();return t&&i.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},oi=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!i.isIdentifier(t)||t.getText()!=="ctx")return;const s=nt(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=nt(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},ai=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const o=oi(n);o!==void 0&&s.push({callee:o,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},ci=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=ii(o);r&&s.push(...ai(r,t))}return s},li=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ci(o,x(t,n)))}return s},ui=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Ns(t.getExpression())},di=e=>{if(e?.getKind()===l.TrueKeyword)return!0;if(e?.getKind()===l.FalseKeyword)return!1},fi=(e,t)=>{if(!ui(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const o=s.getLiteralValue(),r=di(n);if(!(o.length===0||r===void 0))return{defaultValue:r,exportName:v(e),file:t,key:o,line:e.getStartLineNumber()}},pi=(e,t)=>b(e,t,fi),gi=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},mi=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},hi=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression))gi(a)&&s.push({file:r,indexName:mi(a),line:a.getStartLineNumber()})}return s},xi=new Set(["delete","get","head","options","patch","post","put"]),Ei=new Set(["handler","stream"]),vi=new Set(["runAction","runMutation"]),Si=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),Q=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,rt=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,it=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const n=s.getNameNode();if(t)return i.isIdentifier(n)?n.getText():void 0;if(i.isObjectBindingPattern(n)){for(const o of n.getElements())if((o.getPropertyNameNode()?.getText()??o.getNameNode().getText())==="ctx"){const a=o.getNameNode();return i.isIdentifier(a)?a.getText():void 0}}},ot=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);i.isCallExpression(s)&&n.unshift(s);for(const o of n){const r=o.getExpression();if(!i.isPropertyAccessExpression(r))continue;const a=r.getName(),c=r.getExpression();if(vi.has(a)&&Q(c,t))return a;if(Si.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&Q(c.getExpression(),t))return`db.${a}`}},at=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(l.PropertyAccessExpression))if(n.getName()==="auth"&&Q(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(l.VariableDeclaration)){const o=n.getNameNode();if(!(!i.isObjectBindingPattern(o)||!Q(n.getInitializer(),t))){for(const r of o.getElements())if((r.getPropertyNameNode()?.getText()??r.getNameNode().getText())==="auth")return!0}}return!1},Ai=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Ei.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))return;const o=n.getName();if(xi.has(o)){const r=n.getExpression();return i.isIdentifier(r)&&r.getText()==="httpRoute"?o.toUpperCase():void 0}s=n.getExpression()}},Ni=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=rt(e.getArguments()[0]),u=c&&it(c,!0);if(!c||u===void 0)return;const d=ot(c,u);return d===void 0?void 0:{exportName:v(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:at(c,u),sideEffect:d}}const n=Ai(e);if(n===void 0)return;const o=rt(e.getArguments()[0]),r=o&&it(o,!1);if(!o||r===void 0)return;const a=ot(o,r);return a===void 0?void 0:{exportName:v(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:at(o,r),sideEffect:a}},yi=(e,t)=>b(e,t,Ni),bi=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),Ii=new Set(["append","set"]),Ee=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",Ct=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",ct=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(l.CallExpression)]:e.getDescendantsOfKind(l.CallExpression)).some(n=>bi.has(Ee(n.getExpression()))&&Ds(n,t)),Pi=(e,t)=>{if(ct(e,t))return!0;const s=se(e);return s!==void 0&&ct(s,t)},he=(e,t)=>Ls(e,t)&&!Pi(e,t),wi=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=se(e);return t!==void 0&&i.isNewExpression(t)&&Ee(t.getExpression())==="Headers"},X=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=se(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},ve=(e,t,s)=>{for(const n of e.getProperties())if(i.isPropertyAssignment(n)){const o=n.getInitializer();o!==void 0&&he(o,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:Ct(n.getNameNode()),line:o.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(n)){const o=n.getNameNode();he(o,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:n.getName(),line:o.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(n)){const o=X(n.getExpression());o!==void 0&&ve(o,t,s)}},Rt=(e,t)=>{const s=X(e);if(s===void 0)return;const n=s.getProperty("headers");if(n===void 0||!i.isPropertyAssignment(n))return;const o=X(n.getInitializer());o!==void 0&&ve(o,"response-init",t)},Ti=(e,t)=>{const s=Ee(e.getExpression());if(s==="Response")Rt(e.getArguments()[1],t);else if(s==="Headers"){const n=X(e.getArguments()[0]);n!==void 0&&ve(n,"headers-ctor",t)}},Ci=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName(),o=s.getExpression();if(n==="json"&&i.isIdentifier(o)&&o.getText()==="Response"){Rt(e.getArguments()[1],t);return}if(Ii.has(n)&&wi(o)){const r=e.getArguments()[1];r!==void 0&&he(r,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:Ct(e.getArguments()[0]),line:r.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},Ri=(e,t)=>{for(const s of e.getDescendantsOfKind(l.NewExpression))Ti(s,t);for(const s of e.getDescendantsOfKind(l.CallExpression))Ci(s,t)},Oi=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=Ms(e.getArguments()[0]);if(n===void 0)return[];const o=n.getParameters()[1];if(o===void 0)return[];const r=o.getNameNode();if(!i.isIdentifier(r))return[];const a=[];return Ri(n,{exportName:v(e),relativePath:t,requestName:r.getText(),rows:a}),a},Fi=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression))s.push(...Oi(n,t));return s},Li=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Fi(o,x(t,n)))}return s},Di=new Set(["auth","context.auth","ctx.auth"]),ki="userId",Mi=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.getName())}return t},Ki=(e,t)=>{const s=f(t,bt);if(!y(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const o of n.getDescendantsOfKind(l.CallExpression)){if(P(o.getExpression())!=="defineIdentity")continue;const[r]=o.getArguments();return r&&i.isObjectLiteralExpression(r)?Mi(r):void 0}},lt=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Di.has(e.getExpression().getText())?e:void 0},_i=e=>{if(i.isPropertyAccessExpression(e)&<(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&<(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},zi=(e,t,s)=>{const n=[];for(const o of e.getDescendants()){const r=_i(o);r!==void 0&&n.push({declared:r===ki||s.has(r),exportName:v(o),file:t,key:r,line:o.getStartLineNumber()})}return n},Ui=(e,t)=>{const s=Ki(e,t);if(s===void 0)return[];const n=[];for(const o of m(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...zi(r,x(t,o),s))}return n},Bi=(e,t)=>{if(P(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=A(s,"key");if(!(!n||!T(n)||k(n)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},qi=(e,t)=>b(e,t,Bi),$i=new Set(["delete","get","getRaw","getWithMetadata","put"]),ji=(e,t)=>ne(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:$i}),Vi=new Set(["queue","send"]),ut=new Set(["bcc","cc","to"]),Wi=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Vi.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},Hi=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return ut.has(t.getName())&&T(n)&&!k(n)}if(!i.isPropertyAssignment(t)||!ut.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&T(s)&&!k(s)}):!1,Gi=(e,t)=>{const s=Wi(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!Hi(n)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s}},Yi=(e,t)=>b(e,t,Gi),Qi=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},Xi=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},Zi=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==l.CallExpression)return;const s=t;return Ys(s.getExpression())?s:void 0},Ji=e=>{const t=Zi(e),s=t===void 0?void 0:Xi(t);if(s===void 0)return[];const n=e.getNameNode(),o=i.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(l.CallExpression).filter(r=>Qi(r)).map(r=>({exportName:o,file:"lunora/mutators.ts",line:r.getStartLineNumber()}))},eo=e=>e.getVariableDeclarations().flatMap(t=>Ji(t)),to=(e,t)=>{const s=f(t,Gs);if(!y(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return eo(n)},so=new Set(["delete","get","patch"]),no=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),ro=new Set(["auth","identity","session","user"]),io=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),oo=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():""},ao=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},co=(e,t)=>e.getDescendantsOfKind(l.Identifier).some(s=>s.getText()===t),lo=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(l.ThrowStatement).length>0||e.getDescendantsOfKind(l.ReturnStatement).length>0,uo=(e,t)=>e.getDescendantsOfKind(l.IfStatement).some(s=>co(s.getExpression(),t)&&lo(s.getThenStatement())),fo=(e,t)=>{for(const s of e.getDescendantsOfKind(l.CallExpression)){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))continue;const o=n.getName();if(!so.has(o))continue;const r=n.getExpression();if(!(_(r)||i.isPropertyAccessExpression(r)&&_(r.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&i.isIdentifier(c)&&c.getText()===t)return o}},po=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t)||i.isParenthesizedExpression(t)||i.isAsExpression(t)||i.isAwaitExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t.getText():void 0},go=e=>e.getDescendantsOfKind(l.CallExpression).some(t=>t.getArguments().some(s=>po(s)==="ctx")),mo=e=>e.getDescendantsOfKind(l.BinaryExpression).some(t=>io.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),ho=e=>{for(const t of e.getDescendantsOfKind(l.Identifier))if(no.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&ro.has(t.getName()))return!0}return go(e)||mo(e)},xo=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=M(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const o=Nt(s);if(o===void 0)return[];const r=n.receiver!==void 0&&yt(n.receiver,"use","rls"),a=ho(o),c=new Set,u=[];for(const d of o.getDescendantsOfKind(l.CallExpression)){const E=oo(d);if(E===void 0)continue;const N=ao(d);if(N===void 0||c.has(N)||!uo(o,N))continue;const p=fo(o,N);p!==void 0&&(c.add(N),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:p,table:E,usesRls:r,visibility:n.visibility}))}return u},Eo=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...xo(c,r))}return s},vo=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),So=new Set(["insert","insertManyUnsafe","patch","replace"]),Ao=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!So.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="db")return;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="ctx"?t:void 0},No=(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},yo=(e,t,s,n)=>{const o=[];for(const r of e.getProperties()){let a,c;i.isPropertyAssignment(r)?(a=r.getName(),c=r.getInitializer()):i.isShorthandPropertyAssignment(r)&&(a=r.getName(),c=r.getNameNode()),!(a===void 0||c===void 0||!vo.has(a))&&T(c)&&!k(c)&&o.push({exportName:v(s),field:a,file:n,line:s.getStartLineNumber(),method:t})}return o},bo=(e,t)=>{const s=Ao(e.getExpression());if(s===void 0)return[];const n=e.getArguments()[1];return n?No(n,s).flatMap(o=>yo(o,s,e,t)):[]},Io=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression))for(const r of bo(o,t)){const a=s(r.exportName);n.push(a===void 0?r:{...r,visibility:a})}return n},Po=(e,t,s=[])=>{const n=[],o=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));for(const r of m(t)){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=x(t,r);n.push(...Io(a,c,u=>o.get(`${c}:${u}`)))}return n},wo=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),To=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Co=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?To(t.getInitializer()):void 0},Ro=(e,t)=>{const s=P(e.getExpression());if(s===void 0||!wo.has(s))return;const[n]=e.getArguments(),o=n&&i.isObjectLiteralExpression(n)?Co(n):void 0;return{callee:s,exportName:v(e),file:t,line:e.getStartLineNumber(),...o===void 0?{}:{toleranceSeconds:o}}},Oo=(e,t)=>b(e,t,Ro),Fo=new Set(["defineQueue","defineWorkflow"]),Lo=new Set(["run","runAction","runMutation","runQuery"]),Do=new Set(["api","internal"]),ko=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},Mo=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!i.isPropertyAssignment(s))return;const n=s.getInitializer();if(n&&(i.isArrowFunction(n)||i.isFunctionExpression(n)))return n},Ot=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},Ft=(e,t)=>e===t||e.startsWith(`${t}.`),Lt=e=>{const t=e.getDescendantsOfKind(l.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},dt=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)},Dt=e=>{const t=e.getDescendantsOfKind(l.Identifier).filter(s=>dt(s));return i.isIdentifier(e)&&dt(e)&&t.push(e),t},Ko=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(l.BindingElement).map(s=>s.getName())},_o=e=>{const t=Ot(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(l.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const o=n.getInitializer(),r=i.isVariableDeclarationList(o)?o.getDeclarations()[0]?.getNameNode():void 0;r&&i.isIdentifier(r)&&s.push(`${r.getText()}.body`)}return s},zo=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:_o(e),o=new Set,r=a=>Lt(a).some(c=>n.some(u=>Ft(c.getText(),u)))?!0:Dt(a).some(c=>o.has(c.getText()));for(const a of e.getDescendantsOfKind(l.VariableDeclaration)){const c=a.getInitializer();if(c&&r(c))for(const u of Ko(a))o.add(u)}return{names:o,prefixes:n}},Uo=(e,t)=>Lt(e).some(s=>t.prefixes.some(n=>Ft(s.getText(),n)))?!0:Dt(e).some(s=>t.names.has(s.getText())),Bo=e=>{if(e===void 0||!i.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;i.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const n=t.at(-1);if(!(n===void 0||!i.isIdentifier(s)||!Do.has(s.getText())||t.length<2))return{exportName:n,file:t.slice(0,-1).join("/")}},qo=(e,t,s)=>{const n=Ot(e,0);if(n===void 0)return[];const o=zo(e,t,n),r=[];for(const a of e.getDescendantsOfKind(l.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!Lo.has(c.getName())||c.getExpression().getText()!==n)continue;const u=a.getArguments()[1];if(!u||!Uo(u,o))continue;const d=Bo(a.getArguments()[0]);d!==void 0&&r.push({dispatchKind:t,file:s,handlerExport:v(a),line:a.getStartLineNumber(),targetExport:d.exportName,targetFile:d.file})}return r},$o=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=ko(n);if(o===void 0||!Fo.has(o))continue;const r=Mo(n);r!==void 0&&s.push(...qo(r,o==="defineQueue"?"queue":"workflow",t))}return s},jo=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...$o(o,x(t,n)))}return s},ft={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},pt=new Set(["account","credential","member","passkey","session","user"]),Vo=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),Wo=e=>{const s=Vo(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return pt.has(s)||pt.has(n)},Ho=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Go=(e,t)=>{const{objects:s,opaque:n}=wt(e,t);return lr(s).some(o=>Ho(o))?!0:n?void 0:!1},Se=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},Yo=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Qo=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},Y={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Xo=e=>{const t=Qo(e),s=t?Se(t):void 0;if(t&&s==="protectPublic"){const n=Yo(t);return{...Y,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in ft?{...Y,[ft[s]]:!0}:Y},Zo=e=>{const t={...Y};let s=e;for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))break;const o=n.getName()==="use"?s.getArguments()[0]:void 0;if(o){const r=Xo(o);t.usesCaptcha||=r.usesCaptcha,t.usesEmailGate||=r.usesEmailGate,t.usesMask||=r.usesMask,t.usesRateLimit||=r.usesRateLimit,t.usesRls||=r.usesRls}s=n.getExpression()}return t},Jo=new Set(["insert","insertMany","insertManyUnsafe","replace"]),ea=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Jo.has(t.getName()))return!1;const s=t.getExpression();if(!(i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"))return!1;const o=e.getArguments()[0];return!o||!(i.isStringLiteral(o)||i.isNoSubstitutionTemplateLiteral(o))?!1:Wo(o.getLiteralText())},ta=new Set(["create","runAfter","runAt","send","sendBatch"]),sa=new Set(["queues","scheduler","workflows"]),na=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ta.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&sa.has(s.getName())){const n=s.getExpression();if(i.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},ra=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},kt=new Set(["generateObject","generateText","streamObject","streamText"]),ia=e=>{const t=Se(e);return t!==void 0&&kt.has(t)},oa=e=>{const t=Se(e);if(t===void 0||!kt.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(n=>i.isSpreadAssignment(n))?!1:!s.getProperty("maxOutputTokens")},aa=new Set(["log","span","trace"]),ca=new Set(["ai"]),la=new Set(["email","mail"]),ua=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),ge=(e,t)=>e.getDescendantsOfKind(l.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="ctx"}),da=new Set([l.ArrowFunction,l.FunctionDeclaration,l.FunctionExpression,l.GetAccessor,l.MethodDeclaration,l.SetAccessor]),fa=new Set(["every","filter","flatMap","forEach","map","some"]),pa=new Set(["all","allSettled","race"]),ga=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(fa.has(n))return t;const o=s.getExpression();if(i.isIdentifier(o)&&o.getText()==="Promise"&&pa.has(n))return t},ma=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(da.has(t.getKind())){const s=ga(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},ha=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}},xa=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}},Ea=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression)){if(!ua.has(n.getName()))continue;const o=n.getExpression();if(!i.isIdentifier(o)||o.getText()!=="ctx")continue;const r=xa(n);r&&(t=!0,!ma(r)&&!ha(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},va=e=>e.getDescendantsOfKind(l.ThrowStatement).some(t=>{const s=t.getExpression();if(!i.isNewExpression(s))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="Error"}),gt="lunora-advisor-exempt",Sa=/^[\s*/]+/u,Aa=/[\w-]/u,Na=e=>{const s=(e.getFirstAncestorByKind(l.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
|
|
6
|
+
`);for(const n of s.split(`
|
|
7
|
+
`)){const o=n.replace(Sa,"");if(!o.startsWith(gt))continue;const r=o.slice(gt.length);if(Aa.test(r.charAt(0)))continue;const a=r.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":r.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},ya=e=>{const[t]=e.getArguments();if(t){if(i.isObjectLiteralExpression(t)){const s=t.getProperty("handler");return s?i.isPropertyAssignment(s)?s.getInitializer():i.isShorthandPropertyAssignment(s)?s.getNameNode():i.isMethodDeclaration(s)?s:void 0:void 0}return t}},ba=(e,t)=>{const s=ya(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(),o=s.getText(),r=n.getVariableDeclaration(o)?.getInitializer();return r&&(i.isArrowFunction(r)||i.isFunctionExpression(r))?r:n.getFunction(o)},Ia=e=>{let t=!1,s=!1,n=!1,o=!1,r=!1;for(const u of e.getDescendantsOfKind(l.CallExpression))if(ea(u)&&(r=!0),na(u)&&(t=!0),ra(u)&&(o=!0),ia(u)&&(s=!0),oa(u)&&(n=!0),r&&t&&o&&n)break;const{handlesErrors:a,reachesOutbound:c}=Ea(e);return{callsMail:ge(e,la),emitsEvent:ge(e,aa),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||ge(e,ca),throwsBareError:va(e),unboundedAiGeneration:n,usesInsertManyUnsafe:o,writesUserTable:r}},Pa=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=M(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const o=n.receiver?Zo(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},r=ba(e,s);return{...r?Ia(r):{},...Na(e),...o,analyzableBody:r!==void 0,exportName:e.getName(),file:t,hasEmailArg:Go(s,n.receiver),kind:n.kind,visibility:n.visibility}},wa=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=Pa(o,t);r&&s.push(r)}return s},Ta=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...wa(o,x(t,n)))}return s},Ca=new Set(["dbRateLimit","rateLimit"]),Ra=e=>i.isArrowFunction(e)?e.getBody():e,Oa=(e,t)=>{const s=P(e.getExpression());if(s===void 0||!Ca.has(s))return;const n=e.getArguments()[2];if(!n)return;const o=A(n,"key");if(!o)return;const r=Ra(o);if(!(!T(r)||k(r)))return{callee:s,exportName:v(e),file:t,limitName:St(e),line:e.getStartLineNumber()}},Fa=(e,t)=>b(e,t,Oa),La=new Set(["findFirst","findFirstOrThrow","findMany","get"]),Da=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!La.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()},ka=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()}},Ma=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},Mt=(e,t=!1)=>{const s=Ma(e);if(i.isIdentifier(s)){if(t)return;const n=se(s);return n===void 0?void 0:Mt(n,!0)}if(i.isCallExpression(s))return Da(s)??ka(s)},Ka=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(l.ReturnStatement)){const o=n.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),r=n.getExpression();o===e&&r!==void 0&&s.push(r)}return s},_a=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=M(s);if(n?.kind!=="query")return[];const o=Nt(s);if(o===void 0)return[];const r=n.receiver!==void 0&&Ks(n.receiver,"output"),a=n.receiver!==void 0&&yt(n.receiver,"use","mask"),c=new Set,u=[];for(const d of Ka(o)){const E=Mt(d);E===void 0||c.has(E)||(c.add(E),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:E,usesMask:a,usesOutput:r,visibility:n.visibility}))}return u},za=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(..._a(c,r))}return s},Ua=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.getName());return t},Ba=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?M(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=At(r);if(a===void 0)continue;const c=Ua(A(a.options,"with"));c.length!==0&&o.push({exportName:e.getName(),file:t,line:r.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return o},qa=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Ba(c,r))}return s},Z=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===l.PlusToken){const t=Z(e.getLeft()),s=Z(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},$a=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===l.PlusToken;)t=s,s=t.getParent();return t!==e&&Z(t)!==void 0},ja=/(?:^|\/)__tests__\//u,Va=/\.(?:spec|test)$/u,Wa=e=>ja.test(e)||Va.test(e),Ha=e=>{const t=e.getParent();if(t!==void 0){if(i.isVariableDeclaration(t)||i.isPropertyAssignment(t)||i.isPropertySignature(t))return t.getName();if(i.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.EqualsToken)return t.getLeft().getText()}},Ga=(e,t,s)=>on(e)?!Wa(s)&&an(Ha(t)):!0,Ya=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(l.BinaryExpression),...e.getDescendantsOfKind(l.StringLiteral),...e.getDescendantsOfKind(l.NoSubstitutionTemplateLiteral)],o=new Set;for(const r of n){if($a(r))continue;const a=Z(r);if(a===void 0)continue;const c=nn(a);if(c===void 0||!Ga(c,r,t))continue;const u=r.getStartLineNumber(),d=`${String(u)}:${c}`;o.has(d)||(o.add(d),s.push({file:t,kind:c,line:u,preview:rn(a)}))}return s},Qa=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ya(o,x(t,n)))}return s},Xa=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?M(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=At(r);if(a===void 0)continue;const c=A(a.options,"includeDeleted");if(c===void 0)continue;const u=i.isTrueLiteral(c),d=!u&&T(c);!u&&!d||o.push({exportName:e.getName(),file:t,fromArgs:d,hardcodedTrue:u,line:r.getStartLineNumber(),table:a.table,visibility:n.visibility})}return o},Za=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Xa(c,r))}return s},Ja=new Set(["query","unsafe"]),ec=e=>{if(!i.isPropertyAccessExpression(e)||!Ja.has(e.getName()))return!1;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return i.isIdentifier(s)&&s.getText()==="ctx"},tc=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),sc=e=>e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()??"<module>",nc=(e,t)=>{if(!ec(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!tc(s)))return{exportName:sc(e),file:t,line:s.getStartLineNumber()}},rc=(e,t)=>b(e,t,nc),ic=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],oc=e=>{for(const[t,s]of ic)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},ac=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getImportDeclarations()){const a=r.getModuleSpecifierValue(),c=oc(a);c!==void 0&&s.push({file:x(t,n),line:r.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},cc=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),lc=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return ne(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:cc,requireUnmodifiedReach:!0}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},uc=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),dc=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,fc=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 o of e.getProperties()){if(i.isSpreadAssignment(o)){n=!0;continue}if(i.isPropertyAssignment(o)){const r=o.getName();t.push(r),r==="expiresInSeconds"&&(s=dc(o.getInitializer()));continue}(i.isShorthandPropertyAssignment(o)||i.isMethodDeclaration(o))&&t.push(o.getName())}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},pc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=uc.get(t);if(s===void 0)return;const n=e.getExpression().getText();return n==="ctx.storage"||n.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},gc=(e,t)=>{const s=pc(e.getExpression());if(s!==void 0)return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s.method,...fc(e.getArguments()[s.optionsIndex])}},mc=(e,t)=>b(e,t,gc),hc=new Set(["RegisteredAction","RegisteredMutation","RegisteredQuery"]),Ae=e=>{const t=e.getType(),s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName();return s!==void 0&&hc.has(s)?s:void 0},Kt=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},_t={cause:"codegen recognises a procedure only when the initializer is a builder chain, and this one is produced by a call or an alias",remediation:"A factory that returns a procedure cannot be read statically — inline it, or export the chain the factory builds."},xc={cause:"the binding is exported by a separate `export { … }` statement, and codegen reads the `export` keyword on the declaration itself",remediation:"Move the keyword onto the declaration and drop the separate export statement."},Ne=(e,t,s,n,o)=>({cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally a builder chain. A procedure written any other way exists at runtime but never reaches `_generated/api.ts`, so no caller can address it.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${s}\` but was not registered — ${o.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:s},name:"procedure_not_registered",remediation:`Assign the builder chain directly: \`export const ${t} = query.input({ … }).query(handler);\`. ${o.remediation}`,title:"Procedure exists at runtime but is missing from the generated API"}),Ec=(e,t,s)=>{const n=[];for(const o of e.getVariableStatements().filter(r=>r.isExported()))for(const r of o.getDeclarations()){const a=r.getName();if(s.has(`${t}:${a}`)||!Kt(r))continue;const c=Ae(r);c!==void 0&&n.push(Ne(t,a,c,r.getStartLineNumber(),_t))}return n},vc=(e,t,s)=>{if(s.has(`${t}:default`))return[];const n=[];for(const o of e.getExportAssignments().filter(r=>!r.isExportEquals())){const r=Ae(o.getExpression());r!==void 0&&n.push(Ne(t,"default",r,o.getStartLineNumber(),_t))}return n},Sc=(e,t,s)=>{const n=[];for(const o of e.getExportDeclarations().filter(r=>r.getModuleSpecifier()===void 0))for(const r of o.getNamedExports()){const a=r.getAliasNode()?.getText()??r.getName();if(s.has(`${t}:${a}`))continue;const c=r.getLocalTargetDeclarations().find(d=>i.isVariableDeclaration(d));if(c===void 0||!Kt(c))continue;const u=Ae(c);u!==void 0&&n.push(Ne(t,a,u,r.getStartLineNumber(),xc))}return n},Ac=(e,t,s)=>[...Ec(e,t,s),...vc(e,t,s),...Sc(e,t,s)],Nc=(e,t,s)=>{const n=new Set(s.map(r=>`${r.filePath}:${r.exportName}`)),o=[];for(const r of m(t)){const a=e.getSourceFile(r);a!==void 0&&o.push(...Ac(a,x(t,r),n))}return o.toSorted((r,a)=>r.cacheKey.localeCompare(a.cacheKey))},yc=new Set(["when","where"]),me=new Set(["definePolicy","defineShape"]),bc=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const n=t.getName();return me.has(n)?n:void 0}if(!i.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(n)){const o=n.getNameNode().getText();return me.has(o)?o:void 0}const s=t.getText();return me.has(s)?s:void 0},Ic=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,zt=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===l.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Ic(e))return"empty-object";if(i.isParenthesizedExpression(e))return zt(e.getExpression())}},ye=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Pc=e=>e.getDescendantsOfKind(l.ReturnStatement).filter(t=>ye(t)===e),Ut=e=>e.getDescendantsOfKind(l.ConditionalExpression).filter(t=>ye(t)===e),wc=e=>{const t=Pc(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(l.IfStatement)!==void 0)||Ut(e).length>0},Tc=e=>e.getDescendantsOfKind(l.IfStatement).filter(t=>ye(t)===e),xe=e=>e.getKind()===l.NullKeyword||e.getKind()===l.FalseKeyword||i.isIdentifier(e)&&e.getText()==="undefined"?!0:i.isNumericLiteral(e)?e.getLiteralValue()===0:i.isStringLiteral(e)&&e.getLiteralValue()==="",Cc=(e,t)=>xe(e)||xe(t),Rc=new Map([[l.EqualsEqualsEqualsToken,"positive"],[l.EqualsEqualsToken,"positive"],[l.ExclamationEqualsEqualsToken,"negative"],[l.ExclamationEqualsToken,"negative"]]),mt=e=>!xe(e)&&(i.isLiteralExpression(e)||e.getKind()===l.TrueKeyword),Oc=(e,t,s)=>{const n=Rc.get(e);if(n!==void 0)return Cc(t,s)?n==="positive"?"negative":"positive":mt(t)||mt(s)?void 0:n},$=e=>{if(i.isParenthesizedExpression(e))return $(e.getExpression());if(i.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken)return"negative";if(i.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=Oc(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===l.AmpersandAmpersandToken||t===l.BarBarToken){const n=$(e.getLeft()),o=$(e.getRight());return n===o?n:"indeterminate"}}return i.isIdentifier(e)||i.isPropertyAccessExpression(e)||i.isElementAccessExpression(e)||i.isCallExpression(e)?"positive":"indeterminate"},ht=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}}},Fc=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(l.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Lc=e=>i.isReturnStatement(e)?e.getExpression()??e:e,Dc=e=>{const t=[];for(const s of Ut(e)){const n=$(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of Tc(e)){const n=$(s.getExpression());if(n==="indeterminate")continue;const o=n==="negative"?ht(s.getThenStatement()):ht(s.getElseStatement())??Fc(s);o!==void 0&&t.push(Lc(o))}return t},kc=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},Mc=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!i.isObjectLiteralExpression(n))return[];const o=[];for(const r of n.getProperties()){if(!i.isPropertyAssignment(r)||!yc.has(r.getName()))continue;const a=r.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&wc(a))for(const c of Dc(a)){const u=zt(c);u!==void 0&&o.push({exportName:kc(e),file:s,form:u,key:r.getName(),line:c.getStartLineNumber(),owner:t})}}return o},Kc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=bc(n);o!==void 0&&s.push(...Mc(n,o,t))}return s},_c=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Kc(o,x(t,n)))}return s},zc=new Set(["query","upsert","upsertMany"]),Uc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(zc.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Bc=(e,t)=>{const s=Uc(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const o=A(n,"namespace");if(!(!o||!T(o)||k(o)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s}},qc=(e,t)=>b(e,t,Bc),$c=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"},jc=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Vc=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression)){if(!$c(a))continue;const c=ys(a);c!==""&&s.push({exportName:c,file:r,line:a.getStartLineNumber(),workflow:jc(a)})}}return s},Wc=".lunora-schema.json",I=(e,t)=>{y(e)&&vt(e,"utf8")===t||Zt(e,t,"utf8")},w=(e,t)=>{if(t===""){Jt(e,{force:!0});return}I(e,t)},Hc=e=>{const t=f(e,"package.json");if(y(t))try{const s=JSON.parse(vt(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},Gc=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Yc=e=>{let t=y(e)?e:ue(e);for(;t&&t!==ue(t);){const s=f(t,"tsconfig.json");if(y(s))return s;t=ue(t)}},xt=e=>e.replaceAll("\\","/"),Qc=(e,t,s)=>{if(s&&e.length>0){const r=e.map(a=>`"${a.exportName}"`).join(", ");throw new D("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${r}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const r of t.columns){const a=n.get(r.table)??[];a.push(r.column),n.set(r.table,a)}const o=t.columns.length>0;for(const r of e){if(r.table===void 0){if(o)throw new D("MASK_UNSUPPORTED",`defineShape "${r.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${r.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(r.table);if(a===void 0)continue;const c=a.map(u=>`"${u}"`).join(", ");throw new D("MASK_UNSUPPORTED",`defineShape "${r.exportName}" replicates table "${r.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},J=(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)},Et=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,Xc=8,Zc=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:o,migrations:r,project:a,shapes:c,usesSandbox:u,useUmbrella:d,workflows:E}=e;let N=Qe(a,o),p=Ze(a,o),S=Xe(a,o);for(let C=1;;C+=1){const R=vs({agents:t,functions:N,httpRoutes:S,mutators:p,useUmbrella:d,workflows:E}),O=Ss({agents:t,functions:N,migrations:r,mutators:p,shapes:c,useUmbrella:d,usesSandbox:u});if(C>=Xc||Et(a,s,R)&&Et(a,n,O))return{apiContent:R,functions:N,functionsContent:O,httpRoutes:S,mutators:p};J(a,s,R),J(a,n,O),N=Qe(a,o),p=Ze(a,o),S=Xe(a,o)}},Jc=e=>{const t=Yc(e);return t?new Ye({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Ye({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},ql=(e,t)=>{const s=m(t),n=f(t,"schema.ts");y(n)&&s.push(n);for(const c of s){const u=e.getSourceFile(c);u===void 0?e.addSourceFileAtPath(c):u.refreshFromFileSystemSync()}const o=new Set(s.map(c=>xt(c))),r=xt(t),a=`${r}/`;for(const c of e.getSourceFiles()){const u=c.getFilePath();(u===r||u.startsWith(a))&&!o.has(u)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const u=c.getFilePath();if(!(u===r||u.startsWith(a)||u.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},$l=e=>{const t=Gc(),s=t?de.now():0,n=f(e.projectRoot,e.lunoraDirectory??"lunora"),o=f(n,"schema.ts");if(!y(o))throw new D("INTERNAL",`schema.ts not found at ${o}`);const r=e.project??Jc(n);gn(_s);const a=sn(r,o,e.projectRoot),{agents:c,containers:u,dataModelContent:d,dependencies:E,env:N,featureUsage:p,hasBrowser:S,hasFlags:C,hasNotify:R,identity:O,platformGate:j,queues:F,serverContent:K,storageRulesMetadata:z,usesSandbox:re,useUmbrella:U,workflows:L}=Mn({lunoraDirectory:n,project:r,projectRoot:e.projectRoot,schema:a,target:e.target}),g=f(n,"_generated"),be=f(g,"dataModel.ts"),Ie=f(g,"server.ts"),Bt=f(g,"api.ts"),qt=f(g,"functions.ts");J(r,be,d),J(r,Ie,K);const Pe=Hs(r,n),B=cn(r,n),{apiContent:we,functions:q,functionsContent:Te,httpRoutes:$t,mutators:jt}=Zc({agents:c,apiPath:Bt,generatedFunctionsPath:qt,lunoraDirectory:n,migrations:Pe,project:r,shapes:B,useUmbrella:U,usesSandbox:re,workflows:L}),ie=Us(r,n,L,c),V=e.lint===!1?void 0:ss({adminRoutes:jn(r,n),aiRawRuns:Hn(r,n),aiToolSideEffects:nr(r,n),argumentDerivedFetches:or(r,n),argumentValidators:Er(r,n),authApiCalls:zs(r,n),authConfigs:Tr(r,n),browserUrlAccesses:Lr(r,n),configCalls:Br(r,n),containerKeyAccesses:$r(r,n),containerOverrides:Yr(r,n),containers:u,exportSinks:Jr(r,n),staleMigrationImports:ac(r,n),failOpenGuards:ri(r,n),flagReads:li(r,n),flagSecurityDefaults:pi(r,n),geoIndexUsages:hi(r,n),httpActionGuards:yi(r,n),httpHeaderWrites:Li(r,n),identityClaimReads:Ui(r,n),imageDeliveryUrlAccesses:qi(r,n),inserts:qs(r,n),kvKeyAccesses:ji(r,n),mailRecipientAccesses:Yi(r,n),maskProcedures:$s(r,n),maskStrategies:js(r,n),mutatorWrites:to(r,n),nondeterministicCalls:Qs(r,n),normalizeIdAuthorizations:Eo(r,n),notifyCalls:Zs(r,n),notifyConfig:Xs(r,n),ownerFieldWrites:Po(r,n,q),unrestrictedWhereBranches:_c(r,n),paymentWebhooks:Oo(r,n),privilegedDispatches:jo(r,n),procedureProtections:Ta(r,n),queries:ks(r,n),queues:F,r2sqlCalls:Js(r,n),ratelimitKeySelectors:Fa(r,n),rawRowReturns:za(r,n),relationLoads:qa(r,n),rlsProcedures:en(r,n),schema:a,secretLiterals:Qa(r,n),shapes:B,softDeleteReads:Za(r,n),sqlInterpolations:rc(r,n),storageKeyAccesses:lc(r,n,q),storageUploads:mc(r,n),vectorNamespaceAccesses:qc(r,n),workflowCalls:Vc(r,n),workflows:L,wranglerVariables:e.wranglerVariables}),Ce=V===void 0?[]:[...es(V,{source:"static"}),...Nc(r,n,q)],Vt=tn(r,n),Re=Vs(r,n);Qc(B,Re,Ws(r,n));const Wt=C?Bs(r,n):[],W=Cn(p,{containerCount:u.length,cronCount:ie.length,dependencies:E,hasPaymentTables:Tn(a.tables),queueCount:F.length,storageColumnCount:Object.keys(as(a)).length,storageRuleCount:z.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:L.length}),Oe=t?de.now():0,oe=mn(a,Pe.map(h=>h.id)),Fe=cs({advisories:Ce,advisorProcedures:V?.procedureProtections??[],agents:c,containers:u,env:N,flagKeys:Wt,hasAccessFacade:p.access,hasAi:p.ai,hasAnalytics:p.analytics,hasBrowser:S,hasFlags:C,hasHyperdrive:p.hyperdrive,hasImages:p.images,hasKv:p.kv,hasNotify:R,hasPayments:p.payments,hasPipelines:p.pipelines,hasR2sql:p.r2sql,hasX402:p.x402,maskMetadata:Re,mutators:jt,queues:F,rlsMetadata:Vt,schema:a,schemaSnapshot:oe,shapes:B,storageRules:z,studioFeatures:W,useUmbrella:U,workflows:L}),Le=ls(B,E.has("@lunora/db"),U),De=us(u,a.jurisdiction),ke=ds(L),Me=fs(c),Ke=ps(F),_e=gs(ie),ze=ms(a.vectorIndexes),H=hs(a,U),Ue=xs(E.has("@lunora/seed")),G=e.apiSpec??"openapi",ae=G==="openapi"||G==="both",ce=G==="openrpc"||G==="both",Be=ln({emailAgents:c.filter(h=>h.onEmail===!0).map(h=>({bindingName:h.bindingName,exportName:h.exportName})),hasAccess:E.has("@lunora/cloudflare-access"),hasAi:p.ai,hasAnalytics:p.analytics,hasAuth:E.has("@lunora/auth"),hasBrowser:S,hasFramework:E.has("@lunora/astro")||E.has("@lunora/svelte")||E.has("@lunora/vue"),hasGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend!=="hyperdrive"),hasHyperdrive:p.hyperdrive,hasHyperdriveGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend==="hyperdrive"),hasImages:p.images,hasKv:W.kv,hasNotify:R,hasPayments:p.payments,hasR2sql:p.r2sql,hasQueue:F.some(h=>h.mode==="push"),hasScheduler:W.scheduler,hasStorage:W.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:L.length>0,hasX402:p.x402,identity:O,jurisdiction:a.jurisdiction,useUmbrella:U,voiceAgents:c.filter(h=>h.voice===!0&&h.voiceBindingName!==void 0).map(h=>({bindingName:h.voiceBindingName,exportName:h.exportName})),wantsOpenApi:ae,wantsOpenRpc:ce}),qe=Hc(e.projectRoot),$e=un({functions:q,httpRoutes:$t,version:qe}),je=fn({functions:q,version:qe}),Ve=`${JSON.stringify($e,void 0,2)}
|
|
8
|
+
`,We=`${JSON.stringify(je,void 0,2)}
|
|
9
|
+
`,He=dn($e),Ge=pn(je),le=f(n,Wc),Ht=y(le);if(e.dryRun||(y(g)||Xt(g,{recursive:!0}),I(f(g,"app.ts"),Be),I(be,d),I(f(g,"api.ts"),we),I(Ie,K),I(f(g,"functions.ts"),Te),I(f(g,"shard.ts"),Fe),I(f(g,"crons.ts"),_e),I(f(g,"vectors.ts"),ze),I(f(g,"drizzle.global.ts"),H.global),I(f(g,"drizzle.shard.ts"),H.shard),w(f(g,"containers.ts"),De),w(f(g,"workflows.ts"),ke),w(f(g,"agents.ts"),Me),w(f(g,"queues.ts"),Ke),w(f(g,"seed.ts"),Ue),w(f(g,"collections.ts"),Le),w(f(g,"openapi.json"),ae?Ve:""),w(f(g,"openapi.ts"),ae?He:""),w(f(g,"openrpc.json"),ce?We:""),w(f(g,"openrpc.ts"),ce?Ge:""),(!Ht||e.updateSchemaBaseline===!0)&&I(le,ts(oe))),t){const h=de.now(),Gt=Math.round(h-s),Yt=Math.round(Oe-s),Qt=Math.round(h-Oe);console.error(`@lunora/codegen: codegen took ${Gt.toString()}ms (discovery ${Yt.toString()}ms, emit ${Qt.toString()}ms)`)}return{advisories:Ce,advisorContext:V,agents:c,containers:u,cronTriggers:Es(ie),generated:{agents:Me,api:we,app:Be,collections:Le,containers:De,crons:_e,dataModel:d,drizzleGlobal:H.global,drizzleShard:H.shard,functions:Te,openApi:Ve,openApiModule:He,openRpc:We,openRpcModule:Ge,queues:Ke,seed:Ue,server:K,shard:Fe,vectors:ze,workflows:ke},outputDirectory:g,platformDiagnostics:j.diagnostics,queues:F,schemaSnapshot:oe,schemaSnapshotPath:le,workflows:L}};export{Wc as SCHEMA_SNAPSHOT_FILENAME,Jc as createCodegenProject,Yc as findTsconfig,ql as refreshCodegenProject,$l as runCodegen};
|
package/dist/packem_shared/{buildOpenApiDocument-DBUr_qe5.mjs → buildOpenApiDocument-B3l1QPs9.mjs}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{G as S}from"./emit-
|
|
1
|
+
import{G as S}from"./emit-khv5P1pH.mjs";import{s as p}from"./paths-C-9fwEgQ.mjs";import{LUNORA_ERROR_CODES as O,objectSchema as h,validatorIrToJsonSchema as u}from"./LUNORA_ERROR_CODES-BYg8Lpgb.mjs";const E="/_lunora/rest",A=["authorization","cf-access-jwt-assertion","cookie","x-payment"],f=["x-d1-bookmark","x-lunora-shard-key"],P=e=>[...A,...(e.credentialHeaders??[]).map(t=>t.toLowerCase())],g=e=>Number.isFinite(e)?Math.max(0,Math.floor(e)):0,y=(...e)=>{const t=[];for(const r of e)for(const o of r?.split(",")??[]){const s=o.trim().toLowerCase();s!==""&&!t.includes(s)&&t.push(s)}return t.length===0?void 0:t.join(", ")},T=(e,t)=>{const r=[t,`max-age=${String(g(e.maxAge))}`];return e.staleWhileRevalidate!==void 0&&r.push(`stale-while-revalidate=${String(g(e.staleWhileRevalidate))}`),r.join(", ")},b=e=>e.scope==="public"?y(e.vary,...P(e),...f):y(e.vary,...f),x=e=>{const t=e.indexOf(":");if(!(t<=0||t>=e.length-1||e.indexOf(":",t+1)!==-1))return{name:e.slice(t+1),namespace:e.slice(0,t)}},N=e=>{const t=x(e);if(t!==void 0)return`${E}/${t.namespace}/${t.name}`},k=e=>e==="query"?"GET":"POST",m="#/components/responses/LunoraError",v=/:([A-Za-z_$][\w$]*)/gu,q=e=>[...e.matchAll(v)].map(t=>t[1]),_=e=>e.replaceAll(v,"{$1}"),l=e=>e.kind==="optional"?e.inner??e:e,j=e=>{const t=new Set(q(e.path)),r=[];for(const[o,s]of Object.entries(e.searchParams)){const c=l(s);r.push({description:`Query parameter \`${o}\``,in:"query",name:o,required:s.kind!=="optional",schema:u(c)})}for(const[o,s]of Object.entries(e.params)){const c=l(s);r.push({description:`Path parameter \`${o}\``,in:t.has(o)?"path":"query",name:o,required:t.has(o)?!0:s.kind!=="optional",schema:u(c)})}return r},$=e=>e?{content:{"application/json":{schema:u(e)}},description:"Successful response."}:{content:{"application/json":{schema:{description:"Return shape is TS-inferred (no `.output()` declared); best-effort — any JSON."}}},description:"Successful response. The return shape is TypeScript-inferred and not declared via `.output()`, so it is documented best-effort."},C=e=>{const t=p(e.filePath),r=j(e),o={description:`${e.stream?"Streaming (SSE) ":""}HTTP route handler \`${e.exportName}\` (${e.method} ${e.path}).`,operationId:`${e.method.toLowerCase()}_${p(e.path)}`,responses:{200:$(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:m}},summary:`${e.method} ${e.path}`,tags:[t]};return r.length>0&&(o.parameters=r),Object.keys(e.body).length>0&&(o.requestBody={content:{"application/json":{schema:h(e.body)}},required:!0}),e.stream&&(o["x-lunora-stream"]="text/event-stream"),o},w=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o={additionalProperties:!1,properties:{args:h(e.args),functionPath:{const:r,type:"string"},shardKey:{description:"Optional shard key; omitted routes to the default shard.",type:"string"}},required:["functionPath"],type:"object"};return{operation:{description:`Invoke the \`${e.kind}\` \`${r}\` over the Lunora RPC envelope (POST /_lunora/rpc).`,operationId:r,requestBody:{content:{"application/json":{schema:o}},required:!0},responses:{200:$(e.output),default:{$ref:m}},summary:`${e.kind}: ${r}`,tags:[t],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${r}`}},D=(e,t)=>{if(e===void 0||t!=="get"||e.scope===void 0||e.maxAge===void 0)return{};const r={maxAge:e.maxAge,scope:e.scope,...e.staleWhileRevalidate===void 0?{}:{staleWhileRevalidate:e.staleWhileRevalidate},...e.tag===void 0?{}:{tag:e.tag},...e.vary===void 0?{}:{vary:e.vary}},o={"Cache-Control":{description:r.scope==="public"?"Caching policy. `public` applies only to an uncredentialed request — a request carrying `Authorization` or `Cookie` is always answered `private`.":"Caching policy. Restricted to the caller's own cache; never stored by a shared/edge cache.",schema:{example:T(r,r.scope),type:"string"}}};r.tag!==void 0&&(o["Cache-Tag"]={description:"Purge tag for `ctx.cache.purge({ tags: [...] })`.",schema:{example:r.tag,type:"string"}});const s=b(r);return s!==void 0&&(o.Vary={description:"Request headers this response varies by. The endpoint's own negotiated headers are merged in at runtime.",schema:{example:s,type:"string"}}),{headers:o}},L=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o=N(r);if(o===void 0)return;const s=k(e.kind),c=s==="GET",d={description:`Public REST endpoint for the \`${e.kind}\` \`${r}\` (opt-in via \`.expose({ rest: true })\`). Routed through the procedure, so auth / RLS / validators are enforced.`,operationId:`rest_${p(o)}`,responses:{200:{content:{"application/json":{schema:{description:"Procedure result. The shape is TS-inferred from the return type; best-effort — any JSON."}}},description:"Successful result (TypeScript-inferred return shape, documented best-effort).",...D(e.expose?.cache,c?"get":"post")},default:{$ref:m}},summary:`${s} ${o}`,tags:[t],"x-lunora-function-kind":e.kind};if(c){const n=Object.entries(e.args).map(([a,i])=>{const R=l(i);return{description:`Argument \`${a}\` (JSON-encoded for non-string values).`,in:"query",name:a,required:i.kind!=="optional",schema:u(R)}});return n.length>0&&(d.parameters=n),{method:"get",operation:d,path:o}}return d.requestBody={content:{"application/json":{schema:h(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:d,path:o}},I=e=>{const t=e.version??"0.0.0",r={},o=new Set;for(const n of e.httpRoutes){const a=_(n.path),i=r[a]??{};i[n.method.toLowerCase()]=C(n),r[a]=i,o.add(p(n.filePath))}const s=e.functions.filter(n=>n.visibility!=="internal"&&n.kind!=="stream");for(const n of s){const{operation:a,pathKey:i}=w(n);r[i]={post:a},o.add(p(n.filePath))}for(const n of s){if(n.expose?.rest!==!0)continue;const a=L(n);if(a===void 0)continue;const i=r[a.path]??{};i[a.method]=a.operation,r[a.path]=i}const c=[...o].toSorted((n,a)=>n.localeCompare(a)).map(n=>({description:`Operations declared in \`lunora/${n}\`.`,name:n}));return{components:{responses:{LunoraError:{content:{"application/json":{schema:{additionalProperties:!1,description:"Standard Lunora error envelope.",properties:{error:{additionalProperties:!1,properties:{code:{description:"Machine-readable error code. Clients switch on this value.",enum:O,type:"string"},message:{description:"Human-readable error message (never echoes internal details).",type:"string"}},required:["code","message"],type:"object"}},required:["error"],type:"object"}}},description:"A Lunora error response. The HTTP status reflects the error code (e.g. BAD_REQUEST→400, UNAUTHORIZED→401, FORBIDDEN→403, NOT_FOUND→404)."}}},info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora API",version:t},openapi:"3.1.0",paths:r,tags:c}},J=e=>`${JSON.stringify(I(e),void 0,2)}
|
|
2
2
|
`,U=e=>`${S}export const openApiSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
|
|
3
3
|
`;export{I as buildOpenApiDocument,J as emitOpenApi,U as emitOpenApiModule};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{posix as N}from"node:path";import{SyntaxKind as u,Node as o}from"ts-morph";import{l as q,a as K}from"./discover-ast-D33zP-NZ.mjs";import{a as H}from"./module-specifiers-WF8iAydP.mjs";import{p as W,a as D}from"./parse-validator-BFTp87yz.mjs";import{s as X}from"./paths-C-9fwEgQ.mjs";const x=new Set(["action","mutation","query","stream"]),C=/\bany\b(?!\s*(?:\?\s*)?:)/u,k=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,G=/^[A-Za-z_$][\w$]*$/u,J=e=>G.test(e)?e:JSON.stringify(e),L={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},Q={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init"},Y=H,O=e=>{const t=e.getSymbol();if(!t)return e.getText();const i=t.getDeclarations();for(const r of i){if(!o.isImportSpecifier(r))continue;const s=r.getImportDeclaration().getModuleSpecifierValue();return Y(s)?r.getNameNode().getText():void 0}},w=(e,t=!1)=>{let i=e;for(;o.isCallExpression(i);){const n=i.getExpression();if(!o.isPropertyAccessExpression(n))return;i=n.getExpression()}if(!o.isIdentifier(i))return;const r=O(i);if(r===void 0){if(t)return;const n=i.getSymbol()?.getValueDeclaration();if(n&&o.isVariableDeclaration(n)){const s=n.getInitializer();return s?w(s,!0):void 0}return}return x.has(r)?"public":L[r]?"internal":void 0},b=(e,t)=>{const i=e.getProperty(t);if(i===void 0||!o.isPropertyAssignment(i))return;const r=i.getInitializer();return r!==void 0&&o.isStringLiteral(r)?r.getLiteralValue():void 0},P=(e,t)=>{const i=e.getProperty(t);if(i===void 0||!o.isPropertyAssignment(i))return;const r=i.getInitializer();return r!==void 0&&o.isNumericLiteral(r)?r.getLiteralValue():void 0},Z=e=>{const t=e.getProperty("cache");if(t===void 0||!o.isPropertyAssignment(t))return;const i=t.getInitializer();if(i===void 0||!o.isObjectLiteralExpression(i))return;const r=b(i,"scope"),n=P(i,"maxAge"),s=P(i,"staleWhileRevalidate"),a=b(i,"tag"),c=b(i,"vary"),l={...n===void 0?{}:{maxAge:n},...r==="private"||r==="public"?{scope:r}:{},...s===void 0?{}:{staleWhileRevalidate:s},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},ee=e=>{if(e===void 0||!o.isObjectLiteralExpression(e))return{};const t=Z(e),i=e.getProperty("rest");return i!==void 0&&o.isPropertyAssignment(i)?{...t===void 0?{}:{cache:t},rest:i.getInitializer()?.getText()==="true"}:t===void 0?{}:{cache:t}},te=e=>{let t=e;for(;o.isCallExpression(t);){const i=t.getExpression();if(!o.isPropertyAccessExpression(i))return;if(i.getName()==="expose")return ee(t.getArguments()[0]);t=i.getExpression()}},ie=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return{};const i=t.getProperty("args");if(!i||!o.isPropertyAssignment(i))return{};const r=i.getInitializer();return!r||!o.isObjectLiteralExpression(r)?{}:D(r)},re="/_generated/",ne=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(i=>i?.getDeclarations()??[]);return t.length>0&&t.every(i=>i.getSourceFile().getSymbol()===void 0)},se=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,F=e=>{for(const t of e.getAncestors())if(o.isModuleDeclaration(t)){const i=se.exec(t.getName());if(i?.groups?.specifier!==void 0)return i.groups.specifier}},h=new WeakMap,oe=(e,t)=>{const i=e.getSymbol();if(i===void 0)return;let r=h.get(i.compilerSymbol);return r===void 0&&(r=new Map,h.set(i.compilerSymbol,r)),r.has(t)||r.set(t,i.getExport(t)??e.getExportSymbols().find(n=>n.getName()===t)),r.get(t)},M=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(i=>i.getName()===t),ae=(e,t,i)=>e.getModuleSpecifierValue()===t&&M(e,i)?i:void 0,ce=(e,t)=>{const i=e.getDefaultImport();if(i===void 0)return;const r=i.getSymbol();return(r?.getAliasedSymbol()??r)?.getDeclarations().includes(t)===!0?"default":void 0},le=(e,t,i)=>{if(!M(e,i))return;const r=e.getModuleSpecifierSourceFile(),n=r===void 0?void 0:oe(r,i);return(n?.getAliasedSymbol()??n)?.getDeclarations().includes(t)===!0?i:void 0},ue=/^\.\.?(?:$|\/)/u,ge=new Map([[".cjs",".cjs"],[".cts",".cjs"],[".d.ts",".js"],[".js",".js"],[".jsx",".jsx"],[".mjs",".mjs"],[".mts",".mjs"],[".ts",".js"],[".tsx",".js"]]),fe=(e,t)=>{const i=t.getModuleSpecifierValue();if(!ue.test(i))return;const r=t.getModuleSpecifierSourceFile(),n=r===void 0?void 0:ge.get(r.getExtension());if(r===void 0||n===void 0)return;const s=`${N.join(r.getDirectoryPath(),r.getBaseNameWithoutExtension())}${n}`,a=N.relative(e.getDirectoryPath(),s);return a.startsWith(".")?a:`./${a}`},de=(e,t,i)=>{const r=F(t);for(const n of e.getImportDeclarations()){const s=r===void 0?ce(n,t)??le(n,t,i):ae(n,r,i);if(s!==void 0)return{exportName:s,specifier:fe(e,n)??n.getModuleSpecifierValue()}}},pe=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(i=>{const r=i.indexOf("*");return r===-1?e===i:e.startsWith(i.slice(0,r))&&e.endsWith(i.slice(r+1))}),g={kind:"verbatim"},m={kind:"expand"},me=new Set([u.ClassDeclaration,u.EnumDeclaration,u.EnumMember,u.InterfaceDeclaration,u.TypeAliasDeclaration]),R=(e,t,i)=>{const r=e.getSourceFile();if(r.getSymbol()===void 0&&F(e)===void 0||!me.has(e.getKind()))return g;const n=r.getFilePath();if(n.includes(re))return g;if(n===i)return m;const s=o.isEnumMember(e)?e.getParent():e;if(!o.hasName(s))return m;const a=de(t.getSourceFile(),s,s.getName());return a===void 0?g:pe(a.specifier,t)?m:{kind:"qualify",qualified:a}},j=(e,t,i)=>{const r=e.getAliasSymbol(),n=e.getSymbol(),s=new Set((r??n)?.getDeclarations());let a=!1;for(const c of[n,r].flatMap(l=>l?.getDeclarations()??[])){const l=R(c,t,i);if(l.kind==="qualify"&&s.has(c))return l;a||=l.kind!=="verbatim"}return a?m:g},ve=(e,t,i)=>{const r=o.isPropertySignature(e)||o.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(r===void 0)return g;let n=!1;for(const s of[r,...r.getDescendantsOfKind(u.TypeReference)].filter(a=>o.isTypeReference(a))){const a=s.getTypeName().getSymbol();for(const c of(a?.getAliasedSymbol()??a)?.getDeclarations()??[]){const l=R(c,t,i);if(l.kind==="qualify")return l;n||=l.kind!=="verbatim"}}return n?m:g},_=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},S=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0,v=(e,t,i,r=new Set)=>r.has(e)?!1:(r.add(e),j(e,t,i).kind!=="verbatim"||_(e).some(n=>v(n,t,i,r))?!0:S(e)?e.getProperties().some(n=>n.getDeclarations().some(s=>ve(s,t,i).kind!=="verbatim")?!0:v(n.getTypeAtLocation(t),t,i,r)):!1),ye=(e,t)=>{const i=e.getValueDeclaration()??e.getDeclarations()[0];return i&&(o.isPropertySignature(i)||o.isPropertyDeclaration(i))&&i.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},$=8,Ee=(e,t,i,r,n,s)=>{const a=e.getArrayElementType(),c=a?s(a,t,i,r,n):void 0;if(c!==void 0)return a?.isUnion()?`(${c})[]`:`${c}[]`},be=(e,t,i,r,n,s)=>{const a=[];for(const c of e.getUnionTypes()){const l=s(c,t,i,r,n);if(l===void 0)return;a.push(l)}return a.join(" | ")},xe=(e,t,i,r,n,s)=>{if(!S(e))return;const a=[];for(const c of e.getProperties()){const l=c.getTypeAtLocation(t),p=ye(c,l),B=p&&l.isUnion()?l.getUnionTypes().filter(E=>!E.isUndefined()):[l],A=[];for(const E of B){const T=s(E,t,i,r+1,n);if(T===void 0)return;A.push(T)}a.push(`${J(c.getName())}${p?"?":""}: ${A.join(" | ")}`)}return a.length>0?`{ ${a.join("; ")} }`:"{}"},Se=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},Ae=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>o.isClassDeclaration(t)||o.isClassExpression(t)),y=(e,t,i,r)=>{if(i>$||r.has(e))return!1;const n=new Set(r).add(e);if(_(e).some(c=>y(c,t,i+1,n)))return!0;const s=e.getArrayElementType();return s!==void 0?y(s,t,i+1,n):ne(e)?!1:e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(c=>c?.getDeclarations()??[]).some(c=>o.isClassDeclaration(c)||o.isClassExpression(c))?!0:S(e)&&e.getProperties().some(c=>y(c.getTypeAtLocation(t),t,i+1,n))},Te=(e,t,i,r,n,s,a)=>{const c=[];for(const l of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const p=a(l,i,r,n+1,s);if(p===void 0)return;c.push(p)}return`import("${e.specifier}").${e.exportName}${c.length>0?`<${c.join(", ")}>`:""}`},Ne=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>o.isEnumDeclaration(t)||o.isEnumMember(t)),f=(e,t,i,r,n)=>{if(r>$||n.has(e))return;const s=j(e,t,i);if(s.kind==="verbatim"&&!v(e,t,i))return e.getText(t);const a=new Set(n).add(e);if(!Ae(e)){if(e.isEnumLiteral())return Se(e);if(s.kind==="qualify"&&!Ne(e)){const c=Te(s.qualified,e,t,i,r,a,f);if(c!==void 0)return c}return e.isArray()?Ee(e,t,i,r,a,f):e.isUnion()?be(e,t,i,r,a,f):xe(e,t,i,r,a,f)}},z=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let i=t.getReturnType();const n=(i.getSymbol()??i.getAliasSymbol())?.getName();if(n==="Promise"||n==="AsyncIterable"||n==="AsyncIterableIterator"||n==="AsyncGenerator"){const c=i.getTypeArguments()[0];c&&(i=c)}const s=i.getText(e);if(!s||s==="any"||s==="never"||C.test(s.replaceAll(k,""))||y(i,e,0,new Set))return"unknown";const a=e.getSourceFile().getFilePath();return v(i,e,a)?f(i,e,a,0,new Set)??"unknown":s},Be=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const i=t.getTypeAtLocation(e).getProperty("types");if(!i)return;const r=i.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!r)return;const n=r.getTypeAtLocation(e),s=n.getText(e);if(!s||s==="any"||s==="never"||C.test(s.replaceAll(k,"")))return;const a=e.getSourceFile().getFilePath();return v(n,e,a)?f(n,e,a,0,new Set):s},Pe=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return"unknown";const i=t.getProperty("handler");if(!i||!o.isPropertyAssignment(i))return"unknown";const r=i.getInitializer();return!r||!(o.isArrowFunction(r)||o.isFunctionExpression(r))?"unknown":z(r)},he=e=>{const t=e.getArguments()[0];return!t||!(o.isArrowFunction(t)||o.isFunctionExpression(t))?"unknown":z(t)},Ie=e=>{let t={},i=e;for(;o.isCallExpression(i);){const r=i.getExpression();if(!o.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const n=i.getArguments()[0];n&&o.isObjectLiteralExpression(n)&&(t={...D(n),...t})}i=r.getExpression()}return t},De=e=>{let t=e;for(;o.isCallExpression(t);){const i=t.getExpression();if(!o.isPropertyAccessExpression(i))return;if(i.getName()==="output"){const r=t.getArguments()[0];return r&&o.isExpression(r)?W(r):void 0}t=i.getExpression()}},Ce=e=>{const t=e.getExpression();if(o.isPropertyAccessExpression(t)){const s=t.getName();if(!x.has(s))return;const a=t.getExpression();if(a.getType().getProperty("__lunoraProcedure"))return{kind:s,receiver:a,visibility:a.getType().getProperty("__lunoraVisibility")?"internal":"public"};const c=w(a);return c?{kind:s,receiver:a,visibility:c}:void 0}if(!o.isIdentifier(t))return;const i=O(t);if(!i)return;if(x.has(i))return{kind:i,visibility:"public"};const r=L[i];if(r)return{kind:r,visibility:"internal"};const n=Q[i];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}},I=e=>e!==void 0&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,qe=e=>o.isPropertyAccessExpression(e)&&e.getName()==="db"||o.isIdentifier(e)&&e.getText()==="db",Ke=e=>{const t=e.getArguments()[0],i=I(t);if(i!==void 0)return i;if(t===void 0||!o.isObjectLiteralExpression(t))return;const r=t.getProperty("handler");return r!==void 0&&o.isPropertyAssignment(r)?I(r.getInitializer()):void 0},ke=e=>o.isIdentifier(e)?e.getText():o.isPropertyAccessExpression(e)?e.getName():"",He=(e,t)=>{let i=e;for(;o.isCallExpression(i);){const r=i.getExpression();if(!o.isPropertyAccessExpression(r))break;if(r.getName()===t)return!0;i=r.getExpression()}return!1},We=(e,t,i)=>{let r=e;for(;o.isCallExpression(r);){const n=r.getExpression();if(!o.isPropertyAccessExpression(n))break;const s=r.getArguments()[0];if(n.getName()===t&&s!==void 0&&o.isCallExpression(s)&&ke(s.getExpression())===i)return!0;r=n.getExpression()}return!1},Le=e=>{const t=Ce(e);if(t){if(t.receiver){const i=te(t.receiver),r=De(t.receiver);return{args:Ie(t.receiver),...i?{expose:i}:{},kind:t.kind,...r?{output:r}:{},returnType:he(e),visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:ie(e),kind:t.kind,returnType:Pe(e),visibility:t.visibility}}},Oe=8,d=(e,t=0)=>{if(t>Oe)return;if(o.isCallExpression(e))return e;if(o.isParenthesizedExpression(e)||o.isAsExpression(e)||o.isSatisfiesExpression(e)||o.isNonNullExpression(e))return d(e.getExpression(),t+1);if(!o.isIdentifier(e)&&!o.isPropertyAccessExpression(e))return;const i=e.getSymbol()?.getValueDeclaration();return i?U(i,t+1):void 0},U=(e,t)=>{if(o.isVariableDeclaration(e)||o.isPropertyAssignment(e)){const i=e.getInitializer();return i?d(i,t):void 0}if(o.isShorthandPropertyAssignment(e))return d(e.getNameNode(),t);if(o.isBindingElement(e)){const i=e.getPropertyNameNode()?.getText()??e.getName(),s=e.getFirstAncestorByKind(u.VariableDeclaration)?.getInitializer()?.getType().getProperty(i)?.getValueDeclaration();return s?U(s,t+1):void 0}},we=e=>{const t=e.getNameNode();if(o.isObjectBindingPattern(t)){const n=[];for(const s of t.getElements()){const a=d(s.getNameNode());a&&n.push([s.getName(),a])}return n}const i=e.getInitializer(),r=i&&(o.isCallExpression(i)?i:d(i));return r?[[e.getName(),r]]:[]},V=(e,t,i)=>{const r=Le(e);if(r)return{args:r.args,exportName:t,filePath:i,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},Fe=(e,t)=>{const i=[];for(const r of e.getExportAssignments()){if(r.isExportEquals())continue;const n=d(r.getExpression()),s=n?V(n,"default",t):void 0;s&&i.push(s)}return i},Me=(e,t)=>{const i=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations())for(const[s,a]of we(n)){const c=V(a,s,t);c&&i.push(c)}return i.push(...Fe(e,t)),i},Re=e=>{const t=new Map;for(const i of e){const r=X(i.filePath),n=t.get(r);if(n&&n!==i.filePath)throw Object.assign(new Error(`Namespace collision: "${n}" and "${i.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:[n,i.filePath],status:500});t.set(r,i.filePath)}},Xe=(e,t)=>{const i=q(t),r=[];for(const n of i){const s=e.getSourceFile(n)??e.addSourceFileAtPath(n),a=K(t,n);r.push(...Me(s,a))}return r.sort((n,s)=>`${n.filePath}:${n.exportName}`.localeCompare(`${s.filePath}:${s.exportName}`)),Re(r),r};export{He as chainHasStep,We as chainUsesWrappedCall,Ce as classifyProcedureCall,Xe as discoverFunctions,I as inlineHandler,qe as isDatabaseAccessor,q as listLunoraSourceFiles,K as lunoraRelativePath,Ke as procedureHandler,Be as resolveStandardSchemaType,z as unwrapHandlerReturn};
|
package/dist/packem_shared/{discoverHttpRoutes-oVY4IQQz.mjs → discoverHttpRoutes-DDhmUyVN.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as a}from"ts-morph";import{l,a as m}from"./discover-ast-D33zP-NZ.mjs";import{unwrapHandlerReturn as d}from"./discoverFunctions-
|
|
1
|
+
import{Node as a}from"ts-morph";import{l,a as m}from"./discover-ast-D33zP-NZ.mjs";import{unwrapHandlerReturn as d}from"./discoverFunctions-2ajN70Q9.mjs";import{p as h,a as f}from"./parse-validator-BFTp87yz.mjs";const u=new Set(["delete","get","head","options","patch","post","put"]),g=new Set(["body","params","searchParams"]),E=new Set(["handler","stream"]),v=r=>{const e=r.getArguments()[0];if(e&&a.isStringLiteral(e))return e.getLiteralValue()},x=r=>{const e=r.getArguments()[0];return e&&a.isObjectLiteralExpression(e)?f(e):{}},P=r=>{if(!a.isCallExpression(r))return;const e=r.getExpression();if(!a.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const n=e.getExpression();if(!a.isIdentifier(n)||n.getText()!=="httpRoute")return;const s=v(r);return s===void 0?void 0:{method:o.toUpperCase(),path:s}},S=(r,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},n=r.getExpression();if(!a.isPropertyAccessExpression(n))return;let s=n.getExpression();for(;a.isCallExpression(s);){const i=s.getExpression();if(!a.isPropertyAccessExpression(i))break;const c=i.getName();if(u.has(c))break;if(g.has(c)){const p=x(s);o[c]={...p,...o[c]}}else if(c==="output"&&o.output===void 0){const p=s.getArguments()[0];p&&a.isExpression(p)&&(o.output=h(p))}s=i.getExpression()}const t=P(s);if(t)return o.method=t.method,o.path=t.path,o},A=r=>{const e=r.getArguments()[0];return!e||!(a.isArrowFunction(e)||a.isFunctionExpression(e))?"unknown":d(e)},T=(r,e,o,n)=>{const s=e.getName();if(!E.has(s))return;const t=S(r,s);if(!(t?.method===void 0||t.path===void 0))return{body:t.body,exportName:o,filePath:n,method:t.method,params:t.params,path:t.path,searchParams:t.searchParams,stream:t.stream,...t.stream?{chunkType:A(r)}:{},...t.output?{output:t.output}:{}}},b=(r,e)=>{const o=[];for(const n of r.getVariableStatements())if(n.isExported())for(const s of n.getDeclarations()){const t=s.getInitializer();if(!t||!a.isCallExpression(t))continue;const i=t.getExpression();if(!a.isPropertyAccessExpression(i))continue;const c=T(t,i,s.getName(),e);c&&o.push(c)}return o},F=(r,e)=>{const o=l(e),n=[];for(const s of o){const t=r.getSourceFile(s)??r.addSourceFileAtPath(s),i=m(e,s);n.push(...b(t,i))}return n.sort((s,t)=>`${s.method} ${s.path}`.localeCompare(`${t.method} ${t.path}`)||s.filePath.localeCompare(t.filePath)),n};export{F as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i}from"ts-morph";import{l as f,a as P,t as x}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as p}from"./discoverFunctions-
|
|
1
|
+
import{Node as i}from"ts-morph";import{l as f,a as P,t as x}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as p}from"./discoverFunctions-2ajN70Q9.mjs";const A=e=>{if(!i.isCallExpression(e))return!1;const s=e.getExpression();return i.isIdentifier(s)?s.getText()==="mask":i.isPropertyAccessExpression(s)?s.getName()==="mask":!1},u=e=>{if(i.isPropertyAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e))return e.getName()},k=e=>{const s=e.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return[];const t=[];for(const r of s.getProperties()){const o=u(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=u(a);c!==void 0&&t.push({column:c,table:o})}}return t},g=e=>{const s=[];let t=e;for(;i.isCallExpression(t);){const r=t.getExpression();if(!i.isPropertyAccessExpression(r))break;if(r.getName()==="use"){const o=t.getArguments()[0];o&&A(o)&&s.push(o)}t=r.getExpression()}return s},E=e=>{const s=g(e);return{maskColumns:s.flatMap(t=>k(t)),usesMask:s.length>0}},M=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),S=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=p(t);if(!r)return;const o=r.receiver?E(r.receiver):{maskColumns:[],usesMask:!1},{tablesRead:n,tablesWritten:a}=x(e,M,S);return{exportName:e.getName(),file:s,maskColumns:o.maskColumns,tablesRead:n,tablesWritten:a,usesMask:o.usesMask,visibility:r.visibility}},w=(e,s)=>{const t=[];for(const r of f(s)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=P(s,r);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations()){const l=b(c,n);l&&t.push(l)}}return t},h=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"},C=e=>{const s=e.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return[];const t=[];for(const r of s.getProperties()){const o=u(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=u(a);c!==void 0&&t.push({column:c,strategy:h(a),table:o})}}return t},v=e=>{const s=[];for(const t of e.getVariableStatements())if(t.isExported())for(const r of t.getDeclarations()){const o=r.getInitializer(),n=o&&i.isCallExpression(o)?p(o):void 0;n?.receiver&&s.push(n.receiver)}return s},R=(e,s)=>{const t=new Map;for(const r of f(s)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r);for(const n of v(o))for(const a of g(n))for(const c of C(a)){const l=`${c.table}\0${c.column}`;t.has(l)||t.set(l,c)}}return{columns:[...t.values()]}},F=(e,s,t)=>{const r=e.getArguments()[0];if(!r||!i.isObjectLiteralExpression(r))return[];const o=[];for(const n of r.getProperties()){const a=u(n);if(a===void 0||!i.isPropertyAssignment(n))continue;const c=n.getInitializer();if(!(!c||!i.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const m=u(l);if(m===void 0)continue;const d=h(l);d!=="custom"&&o.push({column:m,exportName:s,file:t,line:l.getStartLineNumber(),strategy:d,table:a})}}return o},z=(e,s)=>{if(!i.isVariableDeclaration(e))return[];const t=e.getInitializer(),r=t&&i.isCallExpression(t)?p(t):void 0;return r?.receiver?g(r.receiver).flatMap(o=>F(o,e.getName(),s)):[]},T=(e,s)=>{const t=[];for(const r of f(s)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=P(s,r);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())t.push(...z(c,n))}return t},D=e=>i.isPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?i.isComputedPropertyName(e.getNameNode()):!1,L=e=>i.isPropertyAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?D(e):!0,y=(e,s=!1)=>{for(const t of e.getProperties()){if(L(t))return!0;if(s)continue;if(!i.isPropertyAssignment(t))return!0;const r=t.getInitializer();if(!r||!i.isObjectLiteralExpression(r)||y(r,!0))return!0}return!1},j=(e,s)=>{for(const t of f(s)){const r=e.getSourceFile(t)??e.addSourceFileAtPath(t);for(const o of v(r))for(const n of g(o)){const a=n.getArguments()[0];if(a!==void 0&&(!i.isObjectLiteralExpression(a)||y(a)))return!0}}return!1};export{w as default,j as discoverMaskHasNonLiteralPolicy,R as discoverMaskMetadata,T as discoverMaskStrategies};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as s,SyntaxKind as a}from"ts-morph";import{l,a as c,h as d}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as f}from"./discoverFunctions-
|
|
1
|
+
import{Node as s,SyntaxKind as a}from"ts-morph";import{l,a as c,h as d}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as f}from"./discoverFunctions-2ajN70Q9.mjs";const u={"crypto.getRandomValues":"crypto.getRandomValues","crypto.randomUUID":"crypto.randomUUID","Date.now":"Date.now","Math.random":"Math.random"},m=new Set(["globalThis","self"]),g=new Set(["globalThis","self","window"]),p=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e)){const t=e.getExpression();if(s.isIdentifier(t)&&g.has(t.getText()))return e.getName()}},h=e=>{const t=e.getExpression();if(s.isIdentifier(t)){const o=t.getText();return o==="fetch"||o==="Date"?o:void 0}if(!s.isPropertyAccessExpression(t))return;const n=t.getName(),i=p(t.getExpression());if(i!==void 0)return n==="fetch"&&m.has(i)?"fetch":u[`${i}.${n}`]},x=e=>{const t=e.getExpression();if(!s.isIdentifier(t)||t.getText()!=="Date")return;const n=e.getArguments(),i=n.every(o=>s.isNumericLiteral(o)||s.isStringLiteral(o)||s.isNoSubstitutionTemplateLiteral(o));return n.length>0&&i?void 0:"new Date"},N=e=>{const t=e.getInitializer();if(!t||!s.isCallExpression(t))return;const n=f(t);if(!n||n.kind!=="query"&&n.kind!=="mutation")return;const i=d(t,n.receiver);return i?{exportName:e.getName(),handler:i,kind:n.kind}:void 0},E=(e,t)=>{const n=[];for(const i of e.handler.getDescendantsOfKind(a.CallExpression)){const o=h(i);o!==void 0&&n.push({callee:o,exportName:e.exportName,file:t,kind:e.kind,line:i.getStartLineNumber()})}for(const i of e.handler.getDescendantsOfKind(a.NewExpression)){const o=x(i);o!==void 0&&n.push({callee:o,exportName:e.exportName,file:t,kind:e.kind,line:i.getStartLineNumber()})}return n},S=(e,t)=>{const n=[];for(const i of e.getVariableStatements())if(i.isExported())for(const o of i.getDeclarations()){const r=N(o);r&&n.push(...E(r,t))}return n},w=(e,t)=>{const n=[];for(const i of l(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...S(o,c(t,i)))}return n};export{w as default};
|
package/dist/packem_shared/{discoverR2sqlCalls-Dy7i757M.mjs → discoverR2sqlCalls-NtUJIKqo.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as o,SyntaxKind as a}from"ts-morph";import{l as c,a as l,h as d}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as f}from"./discoverFunctions-
|
|
1
|
+
import{Node as o,SyntaxKind as a}from"ts-morph";import{l as c,a as l,h as d}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as f}from"./discoverFunctions-2ajN70Q9.mjs";const u=t=>{const r=t.getInitializer();if(!r||!o.isCallExpression(r))return;const e=f(r);if(!e||e.kind!=="query"&&e.kind!=="mutation")return;const n=d(r,e.receiver);return n?{exportName:t.getName(),handler:n,kind:e.kind}:void 0},p=t=>{if(!o.isPropertyAccessExpression(t)||t.getName()!=="r2sql")return;const r=t.getExpression();if(!o.isIdentifier(r)||r.getText()!=="ctx")return;const e=t.getParent();return e&&o.isPropertyAccessExpression(e)&&e.getExpression()===t?`ctx.r2sql.${e.getName()}`:"ctx.r2sql"},x=(t,r)=>{const e=[];for(const n of t.handler.getDescendantsOfKind(a.PropertyAccessExpression)){const s=p(n);s!==void 0&&e.push({callee:s,exportName:t.exportName,file:r,kind:t.kind,line:n.getStartLineNumber()})}return e},m=(t,r)=>{const e=[];for(const n of t.getVariableStatements())if(n.isExported())for(const s of n.getDeclarations()){const i=u(s);i&&e.push(...x(i,r))}return e},P=(t,r)=>{const e=[];for(const n of c(r)){const s=t.getSourceFile(n)??t.addSourceFileAtPath(n);e.push(...m(s,l(r,n)))}return e};export{P as default};
|
package/dist/packem_shared/{discoverRlsMetadata-BqCbCx8m.mjs → discoverRlsMetadata-BA9lVt-Q.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as n}from"ts-morph";import{l as d,a as x,t as P,b as l}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as E}from"./discoverFunctions-
|
|
1
|
+
import{Node as n}from"ts-morph";import{l as d,a as x,t as P,b as l}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as E}from"./discoverFunctions-2ajN70Q9.mjs";const b=t=>{if(!n.isCallExpression(t))return!1;const e=t.getExpression();return n.isIdentifier(e)?e.getText()==="rls":n.isPropertyAccessExpression(e)?e.getName()==="rls":!1},v=t=>{const e=t.getArguments()[0];if(!e||!n.isArrayLiteralExpression(e))return[];const s=[];for(const r of e.getElements()){if(!n.isObjectLiteralExpression(r))continue;const i=r.getProperty("table");if(!i||!n.isPropertyAssignment(i))continue;const o=i.getInitializer();o&&n.isStringLiteral(o)&&s.push(o.getLiteralText())}return s},h=t=>{const e=[];let s=t;for(;n.isCallExpression(s);){const r=s.getExpression();if(!n.isPropertyAccessExpression(r))break;if(r.getName()==="use"){const i=s.getArguments()[0];i&&b(i)&&e.push(i)}s=r.getExpression()}return e},y=t=>{const e=h(t);return{rlsTables:e.flatMap(s=>v(s)),usesRls:e.length>0}},A=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),L=new Set(["delete","deleteMany","insert","insertMany","patch","patchMany","replace"]),S=(t,e)=>{if(!n.isVariableDeclaration(t))return;const s=t.getInitializer();if(!s||!n.isCallExpression(s))return;const r=E(s);if(!r)return;const i=r.receiver?y(r.receiver):{rlsTables:[],usesRls:!1},{tablesRead:o,tablesWritten:a}=P(t,A,L);return{exportName:t.getName(),file:e,rlsTables:i.rlsTables,tablesRead:o,tablesWritten:a,usesRls:i.usesRls,visibility:r.visibility}},w=(t,e)=>{const s=[];for(const r of d(e)){const i=t.getSourceFile(r)??t.addSourceFileAtPath(r),o=x(e,r);for(const a of i.getVariableStatements())if(a.isExported())for(const u of a.getDeclarations()){const c=S(u,o);c&&s.push(c)}}return s},C=new Set(["delete","insert","read","update"]),T=(t,e,s)=>{const r=t.getArguments()[0];if(!r||!n.isArrayLiteralExpression(r))return[];const i=[];for(const o of r.getElements()){if(!n.isObjectLiteralExpression(o))continue;const a=l(o,"on");a===void 0||!C.has(a)||i.push({file:e,on:a,procedure:s,table:l(o,"table")??""})}return i},g=t=>{if(!n.isObjectLiteralExpression(t))return[];const e=t.getProperty("permissions");if(!e||!n.isPropertyAssignment(e))return[];const s=e.getInitializer();if(!s||!n.isArrayLiteralExpression(s))return[];const r=[];for(const i of s.getElements()){if(n.isStringLiteral(i)){r.push(i.getLiteralText());continue}if(n.isCallExpression(i)){const o=i.getArguments()[0];o&&n.isStringLiteral(o)&&r.push(o.getLiteralText())}}return r},m=(t,e)=>e===void 0?t:{...t,description:e},R=t=>{if(n.isCallExpression(t)){const e=t.getArguments()[0];if(!e||!n.isStringLiteral(e))return;const s=t.getArguments()[1],r=s?l(s,"description"):void 0,i=s?g(s):[];return m({name:e.getLiteralText(),permissions:i},r)}if(n.isObjectLiteralExpression(t)){const e=l(t,"name");return e===void 0?void 0:m({name:e,permissions:g(t)},l(t,"description"))}},F=t=>{const e=t.getArguments()[1];if(!e||!n.isObjectLiteralExpression(e))return[];const s=e.getProperty("roles");if(!s||!n.isPropertyAssignment(s))return[];const r=s.getInitializer();if(!r||!n.isArrayLiteralExpression(r))return[];const i=[];for(const o of r.getElements()){const a=R(o);a&&i.push(a)}return i},I=(t,e,s)=>{const r=h(t);return{policies:r.flatMap(i=>T(i,e,s)),roles:r.flatMap(i=>F(i))}},M=t=>{const e=[];for(const s of t.getVariableStatements())if(s.isExported())for(const r of s.getDeclarations()){const i=r.getInitializer(),o=i&&n.isCallExpression(i)?E(i):void 0;o?.receiver&&e.push({name:r.getName(),receiver:o.receiver})}return e},D=(t,e)=>{const s=[],r=new Map;for(const i of d(e)){const o=t.getSourceFile(i)??t.addSourceFileAtPath(i),a=x(e,i);for(const{name:u,receiver:c}of M(o)){const p=I(c,a,u);s.push(...p.policies);for(const f of p.roles)r.has(f.name)||r.set(f.name,f)}}return{policies:s,roles:[...r.values()]}};export{w as default,D as discoverRlsMetadata};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as n}from"ts-morph";import{l as f,a as p,b as u}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as g}from"./discoverFunctions-
|
|
1
|
+
import{Node as n}from"ts-morph";import{l as f,a as p,b as u}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as g}from"./discoverFunctions-2ajN70Q9.mjs";const m=new Set(["delete","list","read","write"]),d=o=>{if(!n.isCallExpression(o))return!1;const e=o.getExpression();return n.isIdentifier(e)?e.getText()==="storageRules":n.isPropertyAccessExpression(e)&&e.getName()==="storageRules"},x=o=>{const e=[];let s=o;for(;n.isCallExpression(s);){const t=s.getExpression();if(!n.isPropertyAccessExpression(t))break;if(t.getName()==="use"){const r=s.getArguments()[0];r&&d(r)&&e.push(r)}s=t.getExpression()}return e},h=(o,e,s)=>{const t=o.getArguments()[0];if(!t||!n.isArrayLiteralExpression(t))return[];const r=[];for(const i of t.getElements()){if(!n.isObjectLiteralExpression(i))continue;const a=u(i,"on");if(a===void 0||!m.has(a))continue;const c=u(i,"prefix"),l={bucket:u(i,"bucket")??"",file:e,on:a,procedure:s};c!==void 0&&(l.prefix=c),r.push(l)}return r},E=o=>{const e=[];for(const s of o.getVariableStatements())if(s.isExported())for(const t of s.getDeclarations()){const r=t.getInitializer(),i=r&&n.isCallExpression(r)?g(r):void 0;i?.receiver&&e.push({name:t.getName(),receiver:i.receiver})}return e},R=(o,e)=>{const s=[];for(const t of f(e)){const r=o.getSourceFile(t)??o.addSourceFileAtPath(t),i=p(e,t);for(const{name:a,receiver:c}of E(r))for(const l of x(c))s.push(...h(l,i,a))}return{rules:s}};export{R as default};
|
|
@@ -160,7 +160,7 @@ export interface Relations {
|
|
|
160
160
|
${y}
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
`,Qe)},Dn=/import\("(?<spec>(?:\.\.?\/)*_generated\/[^"]+)"\)/gu,ft=/^(?:\.\.?\/)*_generated\//u,bt=/\.[A-Za-z]\w*$/u,Pn=e=>e.replaceAll(Dn,(t,n)=>{const r=n.replace(ft,"./");return`import("${bt.test(r)?r:`${r}.js`}")`}),Fn=/import\("(?<spec>[^"]+)"\)/gu,ot="node_modules/",Mn=/^@types\//u,Bn=e=>e.replaceAll(Fn,(t,n)=>{const r=n.lastIndexOf(ot);if(r===-1||r>0&&n[r-1]!=="/")return t;const o=n.slice(r+ot.length);return o===""||Mn.test(o)?t:`import("${o}")`}),jn=/import\("(?<spec>\.\.?\/[^"]+)"\)/gu,qn=/^(?:\.\.?\/)+/u,Wn=e=>{const t=[];for(const n of e.split("/"))if(!(n===""||n===".")){if(n===".."&&t.length>0&&t.at(-1)!==".."){t.pop();continue}t.push(n)}return t.join("/")},Un=(e,t)=>e.replaceAll(jn,(n,r)=>{if(ft.test(r.replace(qn,"")))return n;const o=t.includes("/")?t.slice(0,t.lastIndexOf("/")):"",i=`../${Wn(`${o}/${r}`)}`;return`import("${bt.test(i)?i:`${i}.js`}")`}),D=(e,t)=>Pn(Un(Bn(e),t)),Kn=["client","do","errors","flags","observability","platform","ratelimit","runtime","server","values"],Qn=new RegExp(String.raw`import\("@lunora/(?<pkg>${Kn.join("|")})(?<subpath>/[^"]*)?"\)`,"gu"),Vn={flags:new Set(["/web"]),platform:new Set},yt=(e,t)=>t?e.replaceAll(Qn,(n,r,o)=>{const s=Vn[r];return o&&s&&!s.has(o)?n:`import("lunorash/${r}${o??""}")`}):e,Ve=e=>["Doc","Id"].filter(t=>new RegExp(String.raw
|
|
163
|
+
`,Qe)},Dn=/import\("(?<spec>(?:\.\.?\/)*_generated\/[^"]+)"\)/gu,ft=/^(?:\.\.?\/)*_generated\//u,bt=/\.[A-Za-z]\w*$/u,Pn=e=>e.replaceAll(Dn,(t,n)=>{const r=n.replace(ft,"./");return`import("${bt.test(r)?r:`${r}.js`}")`}),Fn=/import\("(?<spec>[^"]+)"\)/gu,ot="node_modules/",Mn=/^@types\//u,Bn=e=>e.replaceAll(Fn,(t,n)=>{const r=n.lastIndexOf(ot);if(r===-1||r>0&&n[r-1]!=="/")return t;const o=n.slice(r+ot.length);return o===""||Mn.test(o)?t:`import("${o}")`}),jn=/import\("(?<spec>\.\.?\/[^"]+)"\)/gu,qn=/^(?:\.\.?\/)+/u,Wn=e=>{const t=[];for(const n of e.split("/"))if(!(n===""||n===".")){if(n===".."&&t.length>0&&t.at(-1)!==".."){t.pop();continue}t.push(n)}return t.join("/")},Un=(e,t)=>e.replaceAll(jn,(n,r)=>{if(ft.test(r.replace(qn,"")))return n;const o=t.includes("/")?t.slice(0,t.lastIndexOf("/")):"",i=`../${Wn(`${o}/${r}`)}`;return`import("${bt.test(i)?i:`${i}.js`}")`}),D=(e,t)=>Pn(Un(Bn(e),t)),Kn=["client","do","errors","flags","observability","platform","ratelimit","runtime","server","values"],Qn=new RegExp(String.raw`import\("@lunora/(?<pkg>${Kn.join("|")})(?<subpath>/[^"]*)?"\)`,"gu"),Vn={flags:new Set(["/web"]),platform:new Set},yt=(e,t)=>t?e.replaceAll(Qn,(n,r,o)=>{const s=Vn[r];return o&&s&&!s.has(o)?n:`import("lunorash/${r}${o??""}")`}):e,Ve=e=>["Doc","Id"].filter(t=>new RegExp(String.raw`(?<![.$\w])${t}<`,"u").test(e)),wt=e=>e.output===void 0||e.output.kind==="any"||e.kind==="stream"?e.returnType:A(e.output),He=e=>{const t=new Map;for(const n of e){const r=t.get(n.filePath)??[];r.push(n),t.set(n.filePath,r)}return[...t.entries()].toSorted(([n],[r])=>n.localeCompare(r))},at=e=>{const t=([n,r])=>{const o=r.toSorted((s,i)=>s.exportName.localeCompare(i.exportName)).map(s=>{const i=D(we(s.args),s.filePath),a=D(wt(s),s.filePath);return` ${s.exportName}: FunctionReference<"${s.kind}", ${i}, ${a}>;`}).join(`
|
|
164
164
|
`);return` ${E(N(n))}: {
|
|
165
165
|
${o}
|
|
166
166
|
};`};return He(e).map(n=>t(n)).join(`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{A as S,G as D}from"./emit-
|
|
1
|
+
import{A as S,G as D}from"./emit-khv5P1pH.mjs";const E=e=>`has${e.charAt(0).toUpperCase()}${e.slice(1)}`,v=S.map(({appMethod:e,key:t})=>[E(t),e.method,e.configKey,e.doc]),m=e=>v.some(([t])=>e[t]),A=e=>e?['import * as lunoraIdentityContract from "../identity.js";']:[],R=(e,t)=>e?['import type { CreateAccessResolverOptions } from "@lunora/cloudflare-access";',`import { createAccessResolver${t?", composeResolvers":""} } from "@lunora/cloudflare-access";`]:[],x=e=>e?['import { createKvIntrospectorFromEnv } from "@lunora/bindings/kv";']:[],C=e=>e?['import notifyConfig from "../notify.js";']:[],k=e=>(e.emailAgents?.length??0)>0,O=e=>k(e)?['import { dispatchAgentEmail } from "@lunora/agent/inbound";']:[],T=e=>k(e)?['import * as lunoraAgentDefinitions from "../agents.js";']:[],L=e=>{const{hasAccess:t,hasAuth:a,hasFramework:r,hasGlobal:n,hasHyperdriveGlobal:o,hasKv:c,hasQueue:s,hasScheduler:d,hasStorage:h,hasWorkflow:u,useUmbrella:l,wantsOpenApi:p,wantsOpenRpc:b}=e,i=l?"lunorash/runtime":"@lunora/runtime",g=["ExecutionContextLike","HttpRouterLike","LunoraWorker","Route","ScheduledControllerLike","ShardNamespaceLike","WorkerOptions"];n&&g.push("GlobalIntrospector","AdminTableResolver"),r&&g.push("FrameworkHostHandler");const w=[...n||o?["createCrossShardRelationCapabilities"]:[],"createWorker","resolveLogArchiveFromEnv",...r?["withFrameworkWorker"]:[]].join(", ");return[...a?['import type { AuthNamespaceLike, LunoraAuth, LunoraAuthOptions } from "@lunora/auth";','import { createAuth, createAuthAdmin, createAuthAuditReader, createDoAuthWiring, d1Executor, ensureMigrated, handleAuthRequest, lunoraD1Adapter } from "@lunora/auth";']:[],...R(t,a),...n?['import type { D1CtxDbOptions, D1DatabaseLike, D1Exec } from "@lunora/d1";','import { applyCdcChanges, createD1CtxDb, exportGlobalRows, facetGlobalColumn, importGlobalRows, listGlobalTables, readD1CdcChanges, readGlobalTablePage, retryingExec } from "@lunora/d1";']:[],...o?['import type { HyperdriveEngine } from "@lunora/hyperdrive/global";','import { createHyperdriveGlobalCtxDb } from "@lunora/hyperdrive/global";','import type { SqlCtxDbOptions, SqlExec } from "@lunora/sql-store";']:[],...x(c),...d?['import type { DurableObjectNamespaceLike } from "@lunora/scheduler";','import { createScheduler } from "@lunora/scheduler";']:[],...h?['import type { R2BucketLike, Storage } from "@lunora/storage";','import { createBucketStorage, createStorage } from "@lunora/storage";']:[],...u?['import { createWorkflowsRestClient } from "@lunora/workflow";']:[],...O(e),`import type { ${[...g].toSorted((f,y)=>f.localeCompare(y)).join(", ")} } from "${i}";`,`import { ${w} } from "${i}";`,"",...A(e.identity),...T(e),...n||o?['import schema from "../schema.js";']:[],...C(e.hasNotify),'import { LUNORA_CRONS } from "./crons.js";','import { LUNORA_FUNCTIONS } from "./functions.js";',...s?['import { createQueueCaptureSink, dispatchQueueBatch, shouldCaptureQueue } from "@lunora/queue";','import { LUNORA_QUEUE_REGISTRY } from "./queues.js";']:[],...p?['import { openApiSpec } from "./openapi.js";']:[],...b?['import { openRpcSpec } from "./openrpc.js";']:[],'import { createShardDO } from "./shard.js";']},q=e=>[...e.hasStorage?[`/** \`.storage(...)\` declaration — one bucket (required) plus optional extra named buckets and signed-URL config. Backs \`ctx.storage\` AND the studio file browser. */
|
|
2
2
|
interface StorageDeclaration<Env> {
|
|
3
3
|
/** The default R2 bucket binding (the bare \`ctx.storage\`). */
|
|
4
4
|
bucket: Selector<Env, R2BucketLike>;
|
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import{existsSync as N,mkdirSync as jt,readFileSync as xt,writeFileSync as Wt,rmSync as Ht}from"node:fs";import{join as f,dirname as ue}from"node:path";import{performance as de}from"node:perf_hooks";import{runAdvisor as Gt}from"@lunora/advisor";import{LunoraError as R}from"@lunora/errors";import{SyntaxKind as l,Node as i,Project as Qe}from"ts-morph";import{serializeSchemaSnapshot as Yt}from"./SCHEMA_SNAPSHOT_VERSION-CftvRWB8.mjs";import{toAdvisorContext as Qt}from"./formatAdvisories-CkEu1eye.mjs";import{discoverAgents as Xt}from"./AGENTS_FILENAME-CPHo8Se5.mjs";import{discoverContainers as Zt}from"./CONTAINERS_FILENAME-Bvn6LZP6.mjs";import{diagnosticAt as J}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as ee}from"./module-specifiers-WF8iAydP.mjs";import{C as fe,i as Jt,f as es,n as ts,a as ss,h as ns,j as rs,b as is,c as os,l as as,e as cs,o as ls,d as us,k as ds,g as fs,p as ps,m as gs}from"./emit-DBZKVUBi.mjs";import{l as g,a as x,c as y,p as S,f as Et,h as ms,i as hs,r as vt,e as xs}from"./discover-ast-D33zP-NZ.mjs";import Es from"./readPackageDependencies-C6h6FZuP.mjs";import{discoverQueues as vs}from"./QUEUES_FILENAME-BnGLtAIu.mjs";import{discoverSandboxUsage as Ss}from"./discoverSandboxUsage-L0lV17de.mjs";import As from"./discoverStorageRulesMetadata-Demj7Q4c.mjs";import{discoverWorkflows as Ns}from"./WORKFLOWS_FILENAME-B8y51Frf.mjs";import{gatePlatformFeatures as ys,resolveCodegenTarget as bs}from"./DEFAULT_TARGET-CrhWLUK7.mjs";import{i as T,a as F,e as E,c as I,r as Is,b as Ps,s as te,f as ws,g as Ts,d as Cs}from"./discover-queries-Dfj_0WJG.mjs";import{classifyProcedureCall as D,inlineHandler as Os,procedureHandler as St,chainUsesWrappedCall as At,isDatabaseAccessor as _,chainHasStep as Rs,discoverFunctions as Fs,resolveStandardSchemaType as Ls}from"./discoverFunctions-5SwUVBO6.mjs";import Ds from"./discoverAuthApiCalls-DUjcl0SB.mjs";import ks from"./discoverCrons-BUJO2ipU.mjs";import{discoverFlagKeys as Ms}from"./FLAGS_FILENAME-DtBWyUKq.mjs";import Ks from"./discoverHttpRoutes-oVY4IQQz.mjs";import _s from"./discoverInserts-YX8AmrzL.mjs";import zs,{discoverMaskStrategies as Us,discoverMaskMetadata as Bs,discoverMaskHasNonLiteralPolicy as qs}from"./discoverMaskProcedures-BbiYrDLQ.mjs";import $s from"./discoverMigrations-4Jjf5DJE.mjs";import{MUTATORS_FILENAME as Vs,isDefineMutatorCallee as js,discoverMutators as Ws}from"./MUTATORS_FILENAME-cczs0N_f.mjs";import Hs from"./discoverNondeterministicCalls-BcWKCkrg.mjs";import{discoverNotifyConfig as Gs,discoverNotifyCalls as Ys}from"./NOTIFY_FILENAME-3hraPVOT.mjs";import Qs from"./discoverR2sqlCalls-Dy7i757M.mjs";import Xs,{discoverRlsMetadata as Zs}from"./discoverRlsMetadata-BqCbCx8m.mjs";import Js from"./discoverSchema-Hsu_1xIc.mjs";import{secretKindOf as en,redact as tn,isHeuristicSecretKind as sn,isSecretishName as nn}from"./redact-Cy14LEnc.mjs";import{discoverShapes as rn}from"./SHAPES_FILENAME-BTdasTq2.mjs";import{emitApp as on}from"./emitApp-wqZEBJxy.mjs";import{buildOpenApiDocument as an,emitOpenApiModule as cn}from"./buildOpenApiDocument-DBUr_qe5.mjs";import{buildOpenRpcDocument as ln,emitOpenRpcModule as un}from"./OPENRPC_VERSION-l-E_pTg8.mjs";import{s as dn}from"./parse-validator-BFTp87yz.mjs";import{buildSchemaSnapshot as fn}from"./SchemaSnapshotParseError-D2h88OHU.mjs";const pn=e=>{const t=[],s=e.tables.filter(n=>n.shardMode==="global");return s.some(n=>n.globalBackend!=="hyperdrive")&&t.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),s.some(n=>n.globalBackend==="hyperdrive")&&t.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'}),e.vectorIndexes.length>0&&t.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/vectors.ts` import `@lunora/bindings/vectors`"}),t},gn=(e,t)=>{if(t===void 0)return;const s=pn(e).filter(o=>!t.has(o.name));if(s.length===0)return;const n=s.map(o=>` - ${o.name} — ${o.reason}`).join(`
|
|
2
|
-
`);throw new R("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
|
|
3
|
-
${n}
|
|
4
|
-
|
|
5
|
-
Install them with your package manager, then re-run codegen.`)},mn="env.ts",hn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return ee(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},xn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&ee(n.getModuleSpecifierValue())}return!1},En=e=>{if(i.isIdentifier(e))return hn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&xn(t)}return!1},vn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!En(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw J(r,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},Sn=(e,t)=>{const s=f(t,mn);if(!N(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=vn(n);if(o.length!==0){if(o.length>1)throw J(n,`lunora/env.ts declares ${o.length.toString()} defineEnv() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},An=e=>{const t=n=>i.isIdentifier(n)&&n.getText()==="ctx",s=new Set;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression))t(n.getExpression())&&s.add(n.getName());for(const n of e.getDescendantsOfKind(l.VariableDeclaration)){const o=n.getInitializer(),r=n.getNameNode();if(!(o===void 0||!t(o)||!i.isObjectBindingPattern(r)))for(const a of r.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},Nn=(e,t)=>{const s=Object.fromEntries(fe.map(n=>[n.key,!1]));for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=new Set(o.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=An(o);for(const c of fe)if(!s[c.key]){if(r.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(fe.every(c=>s[c.key]))break}return s},yn=["providerSubscriptionId","state"],bn=["providerEventId","processedAt"],Xe=(e,t)=>t.every(s=>s in e.shape),In=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&Xe(t,yn)&&Xe(s,bn)},Pn=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings/kv"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),Nt="identity.ts",wn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return ee(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Tn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&ee(n.getModuleSpecifierValue())}return!1},Cn=e=>{if(i.isIdentifier(e))return wn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&Tn(t)}return!1},On=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!Cn(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw J(r,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},Rn=(e,t)=>{const s=f(t,Nt);if(!N(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=On(n);if(o.length!==0){if(o.length>1)throw J(n,`lunora/identity.ts declares ${o.length.toString()} defineIdentity() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},Fn=(e,t)=>{const s=new Map,n=new Map,o=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.bindingName,`workflow "${r.exportName}"`),o.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const a=s.get(r.name);if(a!==void 0)throw new R("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${a} and agent "${r.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=n.get(r.bindingName);if(c!==void 0)throw new R("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${r.bindingName}": produced by both ${c} and agent "${r.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const u=o.get(r.className);if(u!==void 0)throw new R("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${u} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},Ln=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:o}=e,r=Rn(s,t),a=Sn(s,t),c=Ns(s,t),u=vs(s,t),d=Xt(s,t);Fn(c,d);const v=Zt(s,t),P=As(s,t),p=ys(Nn(s,t),bs(n,e.target)),A=p.usage,k=Ss(s,t),z=A.browser||k.usesSandboxBrowser,U=Es(n),V=U??new Set,C=V.has("lunorash");gn(o,U);const M=N(f(t,"flags.ts")),B=N(f(t,"notify.ts"));return{agents:d,containers:v,dataModelContent:es(o),declaredDependencies:U,dependencies:V,env:a,featureUsage:A,hasBrowser:z,hasFlags:M,hasNotify:B,identity:r,platformGate:p,queues:u,serverContent:Jt({agents:d,containers:v,env:a,hasAccessFacade:A.access,hasAi:A.ai,hasAnalytics:A.analytics,hasBrowser:z,hasFlags:M,hasHyperdrive:A.hyperdrive,hasImages:A.images,hasKv:A.kv,hasNotify:B,hasPayments:A.payments,hasPipelines:A.pipelines,hasR2sql:A.r2sql,hasX402:A.x402,identity:r,queues:u,schema:o,storageRuleBuckets:P.rules.map(ne=>ne.bucket),useUmbrella:C,workflows:c}),storageRulesMetadata:P,usesSandbox:k.usesSandboxBrowser||k.usesSandboxContainer,useUmbrella:C,workflows:c}},yt=new Set(["delete","get","head","options","patch","post","put"]),Dn=new Set(["handler","stream"]),kn=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,Ze=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Mn=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!yt.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()}},Kn=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)||yt.has(n.getName()))break;s=n.getExpression()}return Mn(s)},_n=e=>{for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression))if(Ze.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&Ze.has(s.getText()))return!0}return!1},zn=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||!Dn.has(n.getName()))return;const o=Kn(s);if(!o||!kn.test(o.path))return;const r=s.getArguments()[0],a=r!==void 0&&(i.isArrowFunction(r)||i.isFunctionExpression(r))&&_n(r);return{exportName:e.getName(),file:t,method:o.method,path:o.path,usesGuard:a}},Un=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=zn(o,t);r&&s.push(r)}return s},Bn=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Un(o,x(t,n)))}return s},qn=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",$n=(e,t)=>{if(!qn(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!T(s)||F(s)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},Vn=(e,t)=>y(e,t,$n),jn=new Set(["generateText","streamText"]),Wn=new Set(["messages","prompt","system"]),Hn=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],Gn=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const o of Hn)if(o.methods.has(s)&&o.prefixes.some(r=>n===r||n.startsWith(`${r}.`)))return`${n}.${s}`},Yn=e=>{for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=Gn(t);if(s!==void 0)return s}},Qn=e=>{const t=new Set,s=e.getFirstAncestor(r=>i.isArrowFunction(r)||i.isFunctionExpression(r)||i.isFunctionDeclaration(r)),[n]=s?.getParameters()??[],o=n?.getNameNode();if(o===void 0||!i.isObjectBindingPattern(o))return t;for(const r of o.getElements()){const a=r.getPropertyNameNode()?.getText()??r.getName(),c=r.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const u of c.getElements())t.add(u.getName())}return t},Xn=e=>{if(Is(e))return!0;const t=Qn(e);return t.size===0?!1:e.getDescendantsOfKind(l.Identifier).some(s=>t.has(s.getText()))},Zn=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!Wn.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&Xn(s))return!0}return!1},Jn=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=I(n.getExpression());if(o===void 0||!jn.has(o))continue;const[r]=n.getArguments();if(r===void 0||!i.isObjectLiteralExpression(r))continue;let a;for(const c of r.getDescendantsOfKind(l.CallExpression))if(I(c.getExpression())==="tool"&&(a=Yn(c),a!==void 0))break;a!==void 0&&s.push({exportName:E(n),file:t,line:n.getStartLineNumber(),method:o,sideEffect:a,userInputDerived:Zn(r)})}return s},er=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Jn(o,x(t,n)))}return s},tr=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},sr=(e,t)=>{if(!tr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!T(s)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},nr=(e,t)=>y(e,t,sr),bt=e=>e.getProperties().some(t=>i.isSpreadAssignment(t)),rr=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer();return!n||!i.isObjectLiteralExpression(n)?{objects:[],opaque:!0}:{objects:[n],opaque:bt(n)}},ir=e=>{const t=[];let s=!1,n=e;for(;i.isCallExpression(n);){const o=n.getExpression();if(!i.isPropertyAccessExpression(o))break;if(o.getName()==="input"){const r=n.getArguments()[0];r&&i.isObjectLiteralExpression(r)?(t.push(r),s||=bt(r)):s=!0}n=o.getExpression()}return{objects:t,opaque:s}},It=(e,t)=>t?ir(t):rr(e),or=e=>e.flatMap(t=>t.getProperties().filter(s=>i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)).map(s=>s.getName())),ar=/\.check\(|\.meta\(|length|max/iu,cr=/\bv\.any\s*\(/u,lr=/\bv\.string\s*\(/u,ur=e=>cr.test(e),dr=e=>lr.test(e)&&!ar.test(e),fr=e=>{const t=[],s=[];for(const n of e)for(const o of n.getProperties()){if(!i.isPropertyAssignment(o))continue;const r=o.getInitializer();if(!r)continue;const a=r.getText(),c=o.getName();ur(a)?t.push(c):dr(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},pr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=D(s);if(n?.visibility!=="public")return;const{objects:o}=It(s,n.receiver),{anyArgs:r,unboundedStringArgs:a}=fr(o);if(!(r.length===0&&a.length===0))return{anyArgs:r,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},gr=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=pr(o,t);r&&s.push(r)}return s},mr=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...gr(o,x(t,n)))}return s},pe=e=>e?.getKind()===l.TrueKeyword,hr=e=>e?.getKind()===l.FalseKeyword,xr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Er=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),vr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&I(t.getExpression())==="scim"),Sr=e=>e!==void 0&&i.isCallExpression(e)&&Er.has(I(e.getExpression())??""),Ar=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),Nr=e=>{const t=S(e,"advanced"),s=S(e,"emailAndPassword"),n=S(e,"session");return{analyzable:!0,disableCsrfCheck:pe(S(t,"disableCSRFCheck")),emailPasswordEnabled:pe(S(s,"enabled")),requireEmailVerification:pe(S(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:vr(S(e,"plugins"))&&Sr(S(e,"database")),secureCookiesDisabled:hr(S(t,"useSecureCookies")),sessionFreshAgeZero:xr(S(n,"freshAge")),trustedOriginsWildcard:Ar(S(e,"trustedOrigins"))}},yr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),br=(e,t)=>{if(I(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(r=>i.isSpreadAssignment(r)),o=s!==void 0&&i.isObjectLiteralExpression(s)&&!n?Nr(s):yr();return{exportName:E(e),file:t,line:e.getStartLineNumber(),...o}},Ir=(e,t)=>y(e,t,br),Pr=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},wr=(e,t,s)=>{const n=Pr(e.getExpression(),s);if(n===void 0)return;const o=e.getArguments()[s.argIndex];if(!(!o||!T(o)||F(o))&&!(s.requireUnmodifiedReach===!0&&!Ps(o)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:n}},Tr=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression)){const r=wr(o,t,s);r&&n.push(r)}return n},se=(e,t,s)=>{const n=[];for(const o of g(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...Tr(r,x(t,o),s))}return n},Cr=new Set(["content","pdf","scrape","screenshot"]),Or=(e,t)=>se(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Cr}),Rr=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Fr=new Set(["RateLimiter"]),Lr=new Set(["extend"]),Pt=e=>{const t=[],s=[];let n=!1;for(const o of e.getProperties()){if(i.isSpreadAssignment(o)){n=!0;continue}if(i.isPropertyAssignment(o)){const r=o.getName();t.push(r),o.getInitializer()?.getKind()===l.TrueKeyword&&s.push(r);continue}(i.isShorthandPropertyAssignment(o)||i.isMethodDeclaration(o))&&t.push(o.getName())}return{analyzable:!n,presentKeys:t,trueKeys:s}},Je=e=>e&&i.isObjectLiteralExpression(e)?Pt(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Dr=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!i.isReturnStatement(s))return;const n=s.getExpression();return n!==void 0&&i.isObjectLiteralExpression(n)?n:void 0},kr=e=>{if(i.isObjectLiteralExpression(e))return e;if(i.isParenthesizedExpression(e)){const t=e.getExpression();return i.isObjectLiteralExpression(t)?t:void 0}return i.isBlock(e)?Dr(e):void 0},Mr=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&kr(t.getBody());return s?Pt(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Kr=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=I(n.getExpression());o!==void 0&&(Rr.has(o)?s.push({callee:o,file:t,line:n.getStartLineNumber(),...Je(n.getArguments()[0])}):Lr.has(o)&&s.push({callee:o,file:t,line:n.getStartLineNumber(),...Mr(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(l.NewExpression)){const o=I(n.getExpression());o===void 0||!Fr.has(o)||s.push({callee:o,file:t,line:n.getStartLineNumber(),...Je(n.getArguments()[0])})}return s},_r=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Kr(o,x(t,n)))}return s},et="ctx.containers.",zr=e=>{if(!e.startsWith(et))return!1;const t=e.slice(et.length);return t.length>0&&!t.includes(".")},Ur=(e,t)=>se(e,t,{argIndex:0,matchReceiver:zr,methods:new Set(["get"])}),Br=new Set(["allow","deny","setAllowed"]),qr=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},$r=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!qr(e)))return{detail:"enableInternet: true",exportName:E(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},Vr=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!Br.has(s.getName()))return;const n=s.getExpression();if(!(!i.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),exportName:E(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},jr=(e,t)=>$r(e,t)??Vr(e,t),Wr=(e,t)=>y(e,t,jr),Hr=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Gr=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return Hr.has(s)?s:void 0},Yr=e=>{const t=[],s=[];for(const n of e.getProperties()){if(i.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o);const r=n.getInitializer();r&&i.isStringLiteral(r)&&r.getLiteralText()===""&&s.push(o);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n)||i.isGetAccessorDeclaration(n))&&t.push(n.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Qr=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression)){const c=Gr(a);if(c===void 0)continue;const u=a.getArguments()[0],d=u&&i.isObjectLiteralExpression(u)?Yr(u):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:d.analyzable,emptyKeys:d.emptyKeys,factory:c,file:r,line:a.getStartLineNumber(),presentKeys:d.presentKeys})}}return s},Xr=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Zr=new Set(["dbRateLimit","rateLimit"]),Jr=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&i.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===l.TrueKeyword},ei=(e,t)=>{const s=I(e.getExpression());if(s===void 0)return;const n=Xr.get(s);if(n!==void 0)return{callee:s,exportName:E(e),failOpen:Jr(e.getArguments()[n]),file:t,limitName:Zr.has(s)?Et(e):"",line:e.getStartLineNumber()}},ti=(e,t)=>y(e,t,ei),si=e=>{const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const s=D(t);if(s?.kind!=="query")return;const n=ms(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},tt=e=>{const t=e.getParent();return t&&i.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},ni=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!i.isIdentifier(t)||t.getText()!=="ctx")return;const s=tt(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=tt(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},ri=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const o=ni(n);o!==void 0&&s.push({callee:o,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},ii=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=si(o);r&&s.push(...ri(r,t))}return s},oi=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ii(o,x(t,n)))}return s},ai=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&hs(t.getExpression())},ci=e=>{if(e?.getKind()===l.TrueKeyword)return!0;if(e?.getKind()===l.FalseKeyword)return!1},li=(e,t)=>{if(!ai(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const o=s.getLiteralValue(),r=ci(n);if(!(o.length===0||r===void 0))return{defaultValue:r,exportName:E(e),file:t,key:o,line:e.getStartLineNumber()}},ui=(e,t)=>y(e,t,li),di=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},fi=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},pi=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression))di(a)&&s.push({file:r,indexName:fi(a),line:a.getStartLineNumber()})}return s},gi=new Set(["delete","get","head","options","patch","post","put"]),mi=new Set(["handler","stream"]),hi=new Set(["runAction","runMutation"]),xi=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),Q=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,st=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,nt=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const n=s.getNameNode();if(t)return i.isIdentifier(n)?n.getText():void 0;if(i.isObjectBindingPattern(n)){for(const o of n.getElements())if((o.getPropertyNameNode()?.getText()??o.getNameNode().getText())==="ctx"){const a=o.getNameNode();return i.isIdentifier(a)?a.getText():void 0}}},rt=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);i.isCallExpression(s)&&n.unshift(s);for(const o of n){const r=o.getExpression();if(!i.isPropertyAccessExpression(r))continue;const a=r.getName(),c=r.getExpression();if(hi.has(a)&&Q(c,t))return a;if(xi.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&Q(c.getExpression(),t))return`db.${a}`}},it=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(l.PropertyAccessExpression))if(n.getName()==="auth"&&Q(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(l.VariableDeclaration)){const o=n.getNameNode();if(!(!i.isObjectBindingPattern(o)||!Q(n.getInitializer(),t))){for(const r of o.getElements())if((r.getPropertyNameNode()?.getText()??r.getNameNode().getText())==="auth")return!0}}return!1},Ei=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!mi.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))return;const o=n.getName();if(gi.has(o)){const r=n.getExpression();return i.isIdentifier(r)&&r.getText()==="httpRoute"?o.toUpperCase():void 0}s=n.getExpression()}},vi=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=st(e.getArguments()[0]),u=c&&nt(c,!0);if(!c||u===void 0)return;const d=rt(c,u);return d===void 0?void 0:{exportName:E(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:it(c,u),sideEffect:d}}const n=Ei(e);if(n===void 0)return;const o=st(e.getArguments()[0]),r=o&&nt(o,!1);if(!o||r===void 0)return;const a=rt(o,r);return a===void 0?void 0:{exportName:E(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:it(o,r),sideEffect:a}},Si=(e,t)=>y(e,t,vi),Ai=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),Ni=new Set(["append","set"]),Ee=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",wt=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",ot=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(l.CallExpression)]:e.getDescendantsOfKind(l.CallExpression)).some(n=>Ai.has(Ee(n.getExpression()))&&Ts(n,t)),yi=(e,t)=>{if(ot(e,t))return!0;const s=te(e);return s!==void 0&&ot(s,t)},he=(e,t)=>ws(e,t)&&!yi(e,t),bi=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=te(e);return t!==void 0&&i.isNewExpression(t)&&Ee(t.getExpression())==="Headers"},X=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=te(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},ve=(e,t,s)=>{for(const n of e.getProperties())if(i.isPropertyAssignment(n)){const o=n.getInitializer();o!==void 0&&he(o,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:wt(n.getNameNode()),line:o.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(n)){const o=n.getNameNode();he(o,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:n.getName(),line:o.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(n)){const o=X(n.getExpression());o!==void 0&&ve(o,t,s)}},Tt=(e,t)=>{const s=X(e);if(s===void 0)return;const n=s.getProperty("headers");if(n===void 0||!i.isPropertyAssignment(n))return;const o=X(n.getInitializer());o!==void 0&&ve(o,"response-init",t)},Ii=(e,t)=>{const s=Ee(e.getExpression());if(s==="Response")Tt(e.getArguments()[1],t);else if(s==="Headers"){const n=X(e.getArguments()[0]);n!==void 0&&ve(n,"headers-ctor",t)}},Pi=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName(),o=s.getExpression();if(n==="json"&&i.isIdentifier(o)&&o.getText()==="Response"){Tt(e.getArguments()[1],t);return}if(Ni.has(n)&&bi(o)){const r=e.getArguments()[1];r!==void 0&&he(r,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:wt(e.getArguments()[0]),line:r.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},wi=(e,t)=>{for(const s of e.getDescendantsOfKind(l.NewExpression))Ii(s,t);for(const s of e.getDescendantsOfKind(l.CallExpression))Pi(s,t)},Ti=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=Os(e.getArguments()[0]);if(n===void 0)return[];const o=n.getParameters()[1];if(o===void 0)return[];const r=o.getNameNode();if(!i.isIdentifier(r))return[];const a=[];return wi(n,{exportName:E(e),relativePath:t,requestName:r.getText(),rows:a}),a},Ci=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression))s.push(...Ti(n,t));return s},Oi=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ci(o,x(t,n)))}return s},Ri=new Set(["auth","context.auth","ctx.auth"]),Fi="userId",Li=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.getName())}return t},Di=(e,t)=>{const s=f(t,Nt);if(!N(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const o of n.getDescendantsOfKind(l.CallExpression)){if(I(o.getExpression())!=="defineIdentity")continue;const[r]=o.getArguments();return r&&i.isObjectLiteralExpression(r)?Li(r):void 0}},at=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Ri.has(e.getExpression().getText())?e:void 0},ki=e=>{if(i.isPropertyAccessExpression(e)&&at(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&at(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},Mi=(e,t,s)=>{const n=[];for(const o of e.getDescendants()){const r=ki(o);r!==void 0&&n.push({declared:r===Fi||s.has(r),exportName:E(o),file:t,key:r,line:o.getStartLineNumber()})}return n},Ki=(e,t)=>{const s=Di(e,t);if(s===void 0)return[];const n=[];for(const o of g(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...Mi(r,x(t,o),s))}return n},_i=(e,t)=>{if(I(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=S(s,"key");if(!(!n||!T(n)||F(n)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},zi=(e,t)=>y(e,t,_i),Ui=new Set(["delete","get","getRaw","getWithMetadata","put"]),Bi=(e,t)=>se(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:Ui}),qi=new Set(["queue","send"]),ct=new Set(["bcc","cc","to"]),$i=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!qi.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},Vi=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return ct.has(t.getName())&&T(n)&&!F(n)}if(!i.isPropertyAssignment(t)||!ct.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&T(s)&&!F(s)}):!1,ji=(e,t)=>{const s=$i(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!Vi(n)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s}},Wi=(e,t)=>y(e,t,ji),Hi=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},Gi=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},Yi=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==l.CallExpression)return;const s=t;return js(s.getExpression())?s:void 0},Qi=e=>{const t=Yi(e),s=t===void 0?void 0:Gi(t);if(s===void 0)return[];const n=e.getNameNode(),o=i.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(l.CallExpression).filter(r=>Hi(r)).map(r=>({exportName:o,file:"lunora/mutators.ts",line:r.getStartLineNumber()}))},Xi=e=>e.getVariableDeclarations().flatMap(t=>Qi(t)),Zi=(e,t)=>{const s=f(t,Vs);if(!N(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Xi(n)},Ji=new Set(["delete","get","patch"]),eo=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),to=new Set(["auth","identity","session","user"]),so=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),no=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():""},ro=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},io=(e,t)=>e.getDescendantsOfKind(l.Identifier).some(s=>s.getText()===t),oo=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(l.ThrowStatement).length>0||e.getDescendantsOfKind(l.ReturnStatement).length>0,ao=(e,t)=>e.getDescendantsOfKind(l.IfStatement).some(s=>io(s.getExpression(),t)&&oo(s.getThenStatement())),co=(e,t)=>{for(const s of e.getDescendantsOfKind(l.CallExpression)){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))continue;const o=n.getName();if(!Ji.has(o))continue;const r=n.getExpression();if(!(_(r)||i.isPropertyAccessExpression(r)&&_(r.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&i.isIdentifier(c)&&c.getText()===t)return o}},lo=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t)||i.isParenthesizedExpression(t)||i.isAsExpression(t)||i.isAwaitExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t.getText():void 0},uo=e=>e.getDescendantsOfKind(l.CallExpression).some(t=>t.getArguments().some(s=>lo(s)==="ctx")),fo=e=>e.getDescendantsOfKind(l.BinaryExpression).some(t=>so.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),po=e=>{for(const t of e.getDescendantsOfKind(l.Identifier))if(eo.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&to.has(t.getName()))return!0}return uo(e)||fo(e)},go=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=D(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const o=St(s);if(o===void 0)return[];const r=n.receiver!==void 0&&At(n.receiver,"use","rls"),a=po(o),c=new Set,u=[];for(const d of o.getDescendantsOfKind(l.CallExpression)){const v=no(d);if(v===void 0)continue;const P=ro(d);if(P===void 0||c.has(P)||!ao(o,P))continue;const p=co(o,P);p!==void 0&&(c.add(P),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:p,table:v,usesRls:r,visibility:n.visibility}))}return u},mo=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...go(c,r))}return s},ho=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),xo=new Set(["insert","insertManyUnsafe","patch","replace"]),Eo=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!xo.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="db")return;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="ctx"?t:void 0},vo=(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},So=(e,t,s,n)=>{const o=[];for(const r of e.getProperties()){let a,c;i.isPropertyAssignment(r)?(a=r.getName(),c=r.getInitializer()):i.isShorthandPropertyAssignment(r)&&(a=r.getName(),c=r.getNameNode()),!(a===void 0||c===void 0||!ho.has(a))&&T(c)&&!F(c)&&o.push({exportName:E(s),field:a,file:n,line:s.getStartLineNumber(),method:t})}return o},Ao=(e,t)=>{const s=Eo(e.getExpression());if(s===void 0)return[];const n=e.getArguments()[1];return n?vo(n,s).flatMap(o=>So(o,s,e,t)):[]},No=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression))for(const r of Ao(o,t)){const a=s(r.exportName);n.push(a===void 0?r:{...r,visibility:a})}return n},yo=(e,t,s=[])=>{const n=[],o=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));for(const r of g(t)){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=x(t,r);n.push(...No(a,c,u=>o.get(`${c}:${u}`)))}return n},bo=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Io=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Po=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?Io(t.getInitializer()):void 0},wo=(e,t)=>{const s=I(e.getExpression());if(s===void 0||!bo.has(s))return;const[n]=e.getArguments(),o=n&&i.isObjectLiteralExpression(n)?Po(n):void 0;return{callee:s,exportName:E(e),file:t,line:e.getStartLineNumber(),...o===void 0?{}:{toleranceSeconds:o}}},To=(e,t)=>y(e,t,wo),Co=new Set(["defineQueue","defineWorkflow"]),Oo=new Set(["run","runAction","runMutation","runQuery"]),Ro=new Set(["api","internal"]),Fo=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},Lo=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!i.isPropertyAssignment(s))return;const n=s.getInitializer();if(n&&(i.isArrowFunction(n)||i.isFunctionExpression(n)))return n},Ct=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},Ot=(e,t)=>e===t||e.startsWith(`${t}.`),Rt=e=>{const t=e.getDescendantsOfKind(l.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},lt=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)},Ft=e=>{const t=e.getDescendantsOfKind(l.Identifier).filter(s=>lt(s));return i.isIdentifier(e)&<(e)&&t.push(e),t},Do=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(l.BindingElement).map(s=>s.getName())},ko=e=>{const t=Ct(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(l.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const o=n.getInitializer(),r=i.isVariableDeclarationList(o)?o.getDeclarations()[0]?.getNameNode():void 0;r&&i.isIdentifier(r)&&s.push(`${r.getText()}.body`)}return s},Mo=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:ko(e),o=new Set,r=a=>Rt(a).some(c=>n.some(u=>Ot(c.getText(),u)))?!0:Ft(a).some(c=>o.has(c.getText()));for(const a of e.getDescendantsOfKind(l.VariableDeclaration)){const c=a.getInitializer();if(c&&r(c))for(const u of Do(a))o.add(u)}return{names:o,prefixes:n}},Ko=(e,t)=>Rt(e).some(s=>t.prefixes.some(n=>Ot(s.getText(),n)))?!0:Ft(e).some(s=>t.names.has(s.getText())),_o=e=>{if(e===void 0||!i.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;i.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const n=t.at(-1);if(!(n===void 0||!i.isIdentifier(s)||!Ro.has(s.getText())||t.length<2))return{exportName:n,file:t.slice(0,-1).join("/")}},zo=(e,t,s)=>{const n=Ct(e,0);if(n===void 0)return[];const o=Mo(e,t,n),r=[];for(const a of e.getDescendantsOfKind(l.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!Oo.has(c.getName())||c.getExpression().getText()!==n)continue;const u=a.getArguments()[1];if(!u||!Ko(u,o))continue;const d=_o(a.getArguments()[0]);d!==void 0&&r.push({dispatchKind:t,file:s,handlerExport:E(a),line:a.getStartLineNumber(),targetExport:d.exportName,targetFile:d.file})}return r},Uo=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=Fo(n);if(o===void 0||!Co.has(o))continue;const r=Lo(n);r!==void 0&&s.push(...zo(r,o==="defineQueue"?"queue":"workflow",t))}return s},Bo=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Uo(o,x(t,n)))}return s},ut={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},dt=new Set(["account","credential","member","passkey","session","user"]),qo=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),$o=e=>{const s=qo(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return dt.has(s)||dt.has(n)},Vo=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},jo=(e,t)=>{const{objects:s,opaque:n}=It(e,t);return or(s).some(o=>Vo(o))?!0:n?void 0:!1},Se=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},Wo=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Ho=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},Y={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Go=e=>{const t=Ho(e),s=t?Se(t):void 0;if(t&&s==="protectPublic"){const n=Wo(t);return{...Y,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in ut?{...Y,[ut[s]]:!0}:Y},Yo=e=>{const t={...Y};let s=e;for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))break;const o=n.getName()==="use"?s.getArguments()[0]:void 0;if(o){const r=Go(o);t.usesCaptcha||=r.usesCaptcha,t.usesEmailGate||=r.usesEmailGate,t.usesMask||=r.usesMask,t.usesRateLimit||=r.usesRateLimit,t.usesRls||=r.usesRls}s=n.getExpression()}return t},Qo=new Set(["insert","insertMany","insertManyUnsafe","replace"]),Xo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Qo.has(t.getName()))return!1;const s=t.getExpression();if(!(i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"))return!1;const o=e.getArguments()[0];return!o||!(i.isStringLiteral(o)||i.isNoSubstitutionTemplateLiteral(o))?!1:$o(o.getLiteralText())},Zo=new Set(["create","runAfter","runAt","send","sendBatch"]),Jo=new Set(["queues","scheduler","workflows"]),ea=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Zo.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&Jo.has(s.getName())){const n=s.getExpression();if(i.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},ta=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},Lt=new Set(["generateObject","generateText","streamObject","streamText"]),sa=e=>{const t=Se(e);return t!==void 0&&Lt.has(t)},na=e=>{const t=Se(e);if(t===void 0||!Lt.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(n=>i.isSpreadAssignment(n))?!1:!s.getProperty("maxOutputTokens")},ra=new Set(["log","span","trace"]),ia=new Set(["ai"]),oa=new Set(["email","mail"]),aa=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),ge=(e,t)=>e.getDescendantsOfKind(l.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="ctx"}),ca=new Set([l.ArrowFunction,l.FunctionDeclaration,l.FunctionExpression,l.GetAccessor,l.MethodDeclaration,l.SetAccessor]),la=new Set(["every","filter","flatMap","forEach","map","some"]),ua=new Set(["all","allSettled","race"]),da=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(la.has(n))return t;const o=s.getExpression();if(i.isIdentifier(o)&&o.getText()==="Promise"&&ua.has(n))return t},fa=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(ca.has(t.getKind())){const s=da(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},pa=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}},ga=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}},ma=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression)){if(!aa.has(n.getName()))continue;const o=n.getExpression();if(!i.isIdentifier(o)||o.getText()!=="ctx")continue;const r=ga(n);r&&(t=!0,!fa(r)&&!pa(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},ha=e=>e.getDescendantsOfKind(l.ThrowStatement).some(t=>{const s=t.getExpression();if(!i.isNewExpression(s))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="Error"}),ft="lunora-advisor-exempt",xa=/^[\s*/]+/u,Ea=/[\w-]/u,va=e=>{const s=(e.getFirstAncestorByKind(l.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
|
|
6
|
-
`);for(const n of s.split(`
|
|
7
|
-
`)){const o=n.replace(xa,"");if(!o.startsWith(ft))continue;const r=o.slice(ft.length);if(Ea.test(r.charAt(0)))continue;const a=r.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":r.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},Sa=e=>{const[t]=e.getArguments();if(t){if(i.isObjectLiteralExpression(t)){const s=t.getProperty("handler");return s?i.isPropertyAssignment(s)?s.getInitializer():i.isShorthandPropertyAssignment(s)?s.getNameNode():i.isMethodDeclaration(s)?s:void 0:void 0}return t}},Aa=(e,t)=>{const s=Sa(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(),o=s.getText(),r=n.getVariableDeclaration(o)?.getInitializer();return r&&(i.isArrowFunction(r)||i.isFunctionExpression(r))?r:n.getFunction(o)},Na=e=>{let t=!1,s=!1,n=!1,o=!1,r=!1;for(const u of e.getDescendantsOfKind(l.CallExpression))if(Xo(u)&&(r=!0),ea(u)&&(t=!0),ta(u)&&(o=!0),sa(u)&&(s=!0),na(u)&&(n=!0),r&&t&&o&&n)break;const{handlesErrors:a,reachesOutbound:c}=ma(e);return{callsMail:ge(e,oa),emitsEvent:ge(e,ra),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||ge(e,ia),throwsBareError:ha(e),unboundedAiGeneration:n,usesInsertManyUnsafe:o,writesUserTable:r}},ya=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=D(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const o=n.receiver?Yo(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},r=Aa(e,s);return{...r?Na(r):{},...va(e),...o,analyzableBody:r!==void 0,exportName:e.getName(),file:t,hasEmailArg:jo(s,n.receiver),kind:n.kind,visibility:n.visibility}},ba=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=ya(o,t);r&&s.push(r)}return s},Ia=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ba(o,x(t,n)))}return s},Pa=new Set(["dbRateLimit","rateLimit"]),wa=e=>i.isArrowFunction(e)?e.getBody():e,Ta=(e,t)=>{const s=I(e.getExpression());if(s===void 0||!Pa.has(s))return;const n=e.getArguments()[2];if(!n)return;const o=S(n,"key");if(!o)return;const r=wa(o);if(!(!T(r)||F(r)))return{callee:s,exportName:E(e),file:t,limitName:Et(e),line:e.getStartLineNumber()}},Ca=(e,t)=>y(e,t,Ta),Oa=new Set(["findFirst","findFirstOrThrow","findMany","get"]),Ra=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Oa.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()},Fa=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()}},La=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},Dt=(e,t=!1)=>{const s=La(e);if(i.isIdentifier(s)){if(t)return;const n=te(s);return n===void 0?void 0:Dt(n,!0)}if(i.isCallExpression(s))return Ra(s)??Fa(s)},Da=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(l.ReturnStatement)){const o=n.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),r=n.getExpression();o===e&&r!==void 0&&s.push(r)}return s},ka=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=D(s);if(n?.kind!=="query")return[];const o=St(s);if(o===void 0)return[];const r=n.receiver!==void 0&&Rs(n.receiver,"output"),a=n.receiver!==void 0&&At(n.receiver,"use","mask"),c=new Set,u=[];for(const d of Da(o)){const v=Dt(d);v===void 0||c.has(v)||(c.add(v),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:v,usesMask:a,usesOutput:r,visibility:n.visibility}))}return u},Ma=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...ka(c,r))}return s},Ka=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.getName());return t},_a=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?D(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=vt(r);if(a===void 0)continue;const c=Ka(S(a.options,"with"));c.length!==0&&o.push({exportName:e.getName(),file:t,line:r.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return o},za=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(..._a(c,r))}return s},Z=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===l.PlusToken){const t=Z(e.getLeft()),s=Z(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},Ua=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===l.PlusToken;)t=s,s=t.getParent();return t!==e&&Z(t)!==void 0},Ba=/(?:^|\/)__tests__\//u,qa=/\.(?:spec|test)$/u,$a=e=>Ba.test(e)||qa.test(e),Va=e=>{const t=e.getParent();if(t!==void 0){if(i.isVariableDeclaration(t)||i.isPropertyAssignment(t)||i.isPropertySignature(t))return t.getName();if(i.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.EqualsToken)return t.getLeft().getText()}},ja=(e,t,s)=>sn(e)?!$a(s)&&nn(Va(t)):!0,Wa=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(l.BinaryExpression),...e.getDescendantsOfKind(l.StringLiteral),...e.getDescendantsOfKind(l.NoSubstitutionTemplateLiteral)],o=new Set;for(const r of n){if(Ua(r))continue;const a=Z(r);if(a===void 0)continue;const c=en(a);if(c===void 0||!ja(c,r,t))continue;const u=r.getStartLineNumber(),d=`${String(u)}:${c}`;o.has(d)||(o.add(d),s.push({file:t,kind:c,line:u,preview:tn(a)}))}return s},Ha=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Wa(o,x(t,n)))}return s},Ga=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?D(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=vt(r);if(a===void 0)continue;const c=S(a.options,"includeDeleted");if(c===void 0)continue;const u=i.isTrueLiteral(c),d=!u&&T(c);!u&&!d||o.push({exportName:e.getName(),file:t,fromArgs:d,hardcodedTrue:u,line:r.getStartLineNumber(),table:a.table,visibility:n.visibility})}return o},Ya=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Ga(c,r))}return s},Qa=new Set(["query","unsafe"]),Xa=e=>{if(!i.isPropertyAccessExpression(e)||!Qa.has(e.getName()))return!1;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return i.isIdentifier(s)&&s.getText()==="ctx"},Za=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),Ja=e=>e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()??"<module>",ec=(e,t)=>{if(!Xa(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Za(s)))return{exportName:Ja(e),file:t,line:s.getStartLineNumber()}},tc=(e,t)=>y(e,t,ec),sc=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],nc=e=>{for(const[t,s]of sc)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},rc=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getImportDeclarations()){const a=r.getModuleSpecifierValue(),c=nc(a);c!==void 0&&s.push({file:x(t,n),line:r.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},ic=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),oc=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return se(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:ic,requireUnmodifiedReach:!0}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},ac=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),cc=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,lc=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 o of e.getProperties()){if(i.isSpreadAssignment(o)){n=!0;continue}if(i.isPropertyAssignment(o)){const r=o.getName();t.push(r),r==="expiresInSeconds"&&(s=cc(o.getInitializer()));continue}(i.isShorthandPropertyAssignment(o)||i.isMethodDeclaration(o))&&t.push(o.getName())}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},uc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=ac.get(t);if(s===void 0)return;const n=e.getExpression().getText();return n==="ctx.storage"||n.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},dc=(e,t)=>{const s=uc(e.getExpression());if(s!==void 0)return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s.method,...lc(e.getArguments()[s.optionsIndex])}},fc=(e,t)=>y(e,t,dc),pc=new Set(["RegisteredAction","RegisteredMutation","RegisteredQuery"]),Ae=e=>{const t=e.getType(),s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName();return s!==void 0&&pc.has(s)?s:void 0},kt=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},Mt={cause:"codegen recognises a procedure only when the initializer is a builder chain, and this one is produced by a call or an alias",remediation:"A factory that returns a procedure cannot be read statically — inline it, or export the chain the factory builds."},gc={cause:"the binding is exported by a separate `export { … }` statement, and codegen reads the `export` keyword on the declaration itself",remediation:"Move the keyword onto the declaration and drop the separate export statement."},Ne=(e,t,s,n,o)=>({cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally a builder chain. A procedure written any other way exists at runtime but never reaches `_generated/api.ts`, so no caller can address it.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${s}\` but was not registered — ${o.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:s},name:"procedure_not_registered",remediation:`Assign the builder chain directly: \`export const ${t} = query.input({ … }).query(handler);\`. ${o.remediation}`,title:"Procedure exists at runtime but is missing from the generated API"}),mc=(e,t,s)=>{const n=[];for(const o of e.getVariableStatements().filter(r=>r.isExported()))for(const r of o.getDeclarations()){const a=r.getName();if(s.has(`${t}:${a}`)||!kt(r))continue;const c=Ae(r);c!==void 0&&n.push(Ne(t,a,c,r.getStartLineNumber(),Mt))}return n},hc=(e,t,s)=>{if(s.has(`${t}:default`))return[];const n=[];for(const o of e.getExportAssignments().filter(r=>!r.isExportEquals())){const r=Ae(o.getExpression());r!==void 0&&n.push(Ne(t,"default",r,o.getStartLineNumber(),Mt))}return n},xc=(e,t,s)=>{const n=[];for(const o of e.getExportDeclarations().filter(r=>r.getModuleSpecifier()===void 0))for(const r of o.getNamedExports()){const a=r.getAliasNode()?.getText()??r.getName();if(s.has(`${t}:${a}`))continue;const c=r.getLocalTargetDeclarations().find(d=>i.isVariableDeclaration(d));if(c===void 0||!kt(c))continue;const u=Ae(c);u!==void 0&&n.push(Ne(t,a,u,r.getStartLineNumber(),gc))}return n},Ec=(e,t,s)=>[...mc(e,t,s),...hc(e,t,s),...xc(e,t,s)],vc=(e,t,s)=>{const n=new Set(s.map(r=>`${r.filePath}:${r.exportName}`)),o=[];for(const r of g(t)){const a=e.getSourceFile(r);a!==void 0&&o.push(...Ec(a,x(t,r),n))}return o.toSorted((r,a)=>r.cacheKey.localeCompare(a.cacheKey))},Sc=new Set(["when","where"]),me=new Set(["definePolicy","defineShape"]),Ac=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const n=t.getName();return me.has(n)?n:void 0}if(!i.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(n)){const o=n.getNameNode().getText();return me.has(o)?o:void 0}const s=t.getText();return me.has(s)?s:void 0},Nc=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,Kt=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===l.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Nc(e))return"empty-object";if(i.isParenthesizedExpression(e))return Kt(e.getExpression())}},ye=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),yc=e=>e.getDescendantsOfKind(l.ReturnStatement).filter(t=>ye(t)===e),_t=e=>e.getDescendantsOfKind(l.ConditionalExpression).filter(t=>ye(t)===e),bc=e=>{const t=yc(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(l.IfStatement)!==void 0)||_t(e).length>0},Ic=e=>e.getDescendantsOfKind(l.IfStatement).filter(t=>ye(t)===e),xe=e=>e.getKind()===l.NullKeyword||e.getKind()===l.FalseKeyword||i.isIdentifier(e)&&e.getText()==="undefined"?!0:i.isNumericLiteral(e)?e.getLiteralValue()===0:i.isStringLiteral(e)&&e.getLiteralValue()==="",Pc=(e,t)=>xe(e)||xe(t),wc=new Map([[l.EqualsEqualsEqualsToken,"positive"],[l.EqualsEqualsToken,"positive"],[l.ExclamationEqualsEqualsToken,"negative"],[l.ExclamationEqualsToken,"negative"]]),pt=e=>!xe(e)&&(i.isLiteralExpression(e)||e.getKind()===l.TrueKeyword),Tc=(e,t,s)=>{const n=wc.get(e);if(n!==void 0)return Pc(t,s)?n==="positive"?"negative":"positive":pt(t)||pt(s)?void 0:n},$=e=>{if(i.isParenthesizedExpression(e))return $(e.getExpression());if(i.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken)return"negative";if(i.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=Tc(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===l.AmpersandAmpersandToken||t===l.BarBarToken){const n=$(e.getLeft()),o=$(e.getRight());return n===o?n:"indeterminate"}}return i.isIdentifier(e)||i.isPropertyAccessExpression(e)||i.isElementAccessExpression(e)||i.isCallExpression(e)?"positive":"indeterminate"},gt=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}}},Cc=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(l.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Oc=e=>i.isReturnStatement(e)?e.getExpression()??e:e,Rc=e=>{const t=[];for(const s of _t(e)){const n=$(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of Ic(e)){const n=$(s.getExpression());if(n==="indeterminate")continue;const o=n==="negative"?gt(s.getThenStatement()):gt(s.getElseStatement())??Cc(s);o!==void 0&&t.push(Oc(o))}return t},Fc=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},Lc=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!i.isObjectLiteralExpression(n))return[];const o=[];for(const r of n.getProperties()){if(!i.isPropertyAssignment(r)||!Sc.has(r.getName()))continue;const a=r.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&bc(a))for(const c of Rc(a)){const u=Kt(c);u!==void 0&&o.push({exportName:Fc(e),file:s,form:u,key:r.getName(),line:c.getStartLineNumber(),owner:t})}}return o},Dc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=Ac(n);o!==void 0&&s.push(...Lc(n,o,t))}return s},kc=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Dc(o,x(t,n)))}return s},Mc=new Set(["query","upsert","upsertMany"]),Kc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(Mc.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},_c=(e,t)=>{const s=Kc(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const o=S(n,"namespace");if(!(!o||!T(o)||F(o)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s}},zc=(e,t)=>y(e,t,_c),Uc=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"},Bc=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},qc=(e,t)=>{const s=[];for(const n of g(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression)){if(!Uc(a))continue;const c=xs(a);c!==""&&s.push({exportName:c,file:r,line:a.getStartLineNumber(),workflow:Bc(a)})}}return s},$c=".lunora-schema.json",b=(e,t)=>{N(e)&&xt(e,"utf8")===t||Wt(e,t,"utf8")},w=(e,t)=>{if(t===""){Ht(e,{force:!0});return}b(e,t)},Vc=e=>{const t=f(e,"package.json");if(N(t))try{const s=JSON.parse(xt(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},jc=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Wc=e=>{let t=N(e)?e:ue(e);for(;t&&t!==ue(t);){const s=f(t,"tsconfig.json");if(N(s))return s;t=ue(t)}},mt=e=>e.replaceAll("\\","/"),Hc=(e,t,s)=>{if(s&&e.length>0){const r=e.map(a=>`"${a.exportName}"`).join(", ");throw new R("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${r}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const r of t.columns){const a=n.get(r.table)??[];a.push(r.column),n.set(r.table,a)}const o=t.columns.length>0;for(const r of e){if(r.table===void 0){if(o)throw new R("MASK_UNSUPPORTED",`defineShape "${r.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${r.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(r.table);if(a===void 0)continue;const c=a.map(u=>`"${u}"`).join(", ");throw new R("MASK_UNSUPPORTED",`defineShape "${r.exportName}" replicates table "${r.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},ht=(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)},Gc=e=>{const t=Wc(e);return t?new Qe({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Qe({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Kl=(e,t)=>{const s=g(t),n=f(t,"schema.ts");N(n)&&s.push(n);for(const c of s){const u=e.getSourceFile(c);u===void 0?e.addSourceFileAtPath(c):u.refreshFromFileSystemSync()}const o=new Set(s.map(c=>mt(c))),r=mt(t),a=`${r}/`;for(const c of e.getSourceFiles()){const u=c.getFilePath();(u===r||u.startsWith(a))&&!o.has(u)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const u=c.getFilePath();if(!(u===r||u.startsWith(a)||u.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},_l=e=>{const t=jc(),s=t?de.now():0,n=f(e.projectRoot,e.lunoraDirectory??"lunora"),o=f(n,"schema.ts");if(!N(o))throw new R("INTERNAL",`schema.ts not found at ${o}`);const r=e.project??Gc(n);dn(Ls);const a=Js(r,o,e.projectRoot),{agents:c,containers:u,dataModelContent:d,dependencies:v,env:P,featureUsage:p,hasBrowser:A,hasFlags:k,hasNotify:z,identity:U,platformGate:V,queues:C,serverContent:M,storageRulesMetadata:B,usesSandbox:ne,useUmbrella:K,workflows:O}=Ln({lunoraDirectory:n,project:r,projectRoot:e.projectRoot,schema:a,target:e.target}),m=f(n,"_generated"),be=f(m,"dataModel.ts"),Ie=f(m,"server.ts");ht(r,be,d),ht(r,Ie,M);const L=Fs(r,n),Pe=Ks(r,n),we=$s(r,n),q=rn(r,n),re=Ws(r,n),ie=ks(r,n,O,c),j=e.lint===!1?void 0:Qt({adminRoutes:Bn(r,n),aiRawRuns:Vn(r,n),aiToolSideEffects:er(r,n),argumentDerivedFetches:nr(r,n),argumentValidators:mr(r,n),authApiCalls:Ds(r,n),authConfigs:Ir(r,n),browserUrlAccesses:Or(r,n),configCalls:_r(r,n),containerKeyAccesses:Ur(r,n),containerOverrides:Wr(r,n),containers:u,exportSinks:Qr(r,n),staleMigrationImports:rc(r,n),failOpenGuards:ti(r,n),flagReads:oi(r,n),flagSecurityDefaults:ui(r,n),geoIndexUsages:pi(r,n),httpActionGuards:Si(r,n),httpHeaderWrites:Oi(r,n),identityClaimReads:Ki(r,n),imageDeliveryUrlAccesses:zi(r,n),inserts:_s(r,n),kvKeyAccesses:Bi(r,n),mailRecipientAccesses:Wi(r,n),maskProcedures:zs(r,n),maskStrategies:Us(r,n),mutatorWrites:Zi(r,n),nondeterministicCalls:Hs(r,n),normalizeIdAuthorizations:mo(r,n),notifyCalls:Ys(r,n),notifyConfig:Gs(r,n),ownerFieldWrites:yo(r,n,L),unrestrictedWhereBranches:kc(r,n),paymentWebhooks:To(r,n),privilegedDispatches:Bo(r,n),procedureProtections:Ia(r,n),queries:Cs(r,n),queues:C,r2sqlCalls:Qs(r,n),ratelimitKeySelectors:Ca(r,n),rawRowReturns:Ma(r,n),relationLoads:za(r,n),rlsProcedures:Xs(r,n),schema:a,secretLiterals:Ha(r,n),shapes:q,softDeleteReads:Ya(r,n),sqlInterpolations:tc(r,n),storageKeyAccesses:oc(r,n,L),storageUploads:fc(r,n),vectorNamespaceAccesses:zc(r,n),workflowCalls:qc(r,n),workflows:O,wranglerVariables:e.wranglerVariables}),Te=j===void 0?[]:[...Gt(j,{source:"static"}),...vc(r,n,L)],zt=Zs(r,n),Ce=Bs(r,n);Hc(q,Ce,qs(r,n));const Ut=k?Ms(r,n):[],W=Pn(p,{containerCount:u.length,cronCount:ie.length,dependencies:v,hasPaymentTables:In(a.tables),queueCount:C.length,storageColumnCount:Object.keys(ts(a)).length,storageRuleCount:B.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:O.length}),Oe=t?de.now():0,Re=ss({agents:c,functions:L,httpRoutes:Pe,mutators:re,useUmbrella:K,workflows:O}),Fe=ns({agents:c,functions:L,migrations:we,mutators:re,shapes:q,useUmbrella:K,usesSandbox:ne}),oe=fn(a,we.map(h=>h.id)),Le=rs({advisories:Te,advisorProcedures:j?.procedureProtections??[],agents:c,containers:u,env:P,flagKeys:Ut,hasAccessFacade:p.access,hasAi:p.ai,hasAnalytics:p.analytics,hasBrowser:A,hasFlags:k,hasHyperdrive:p.hyperdrive,hasImages:p.images,hasKv:p.kv,hasNotify:z,hasPayments:p.payments,hasPipelines:p.pipelines,hasR2sql:p.r2sql,hasX402:p.x402,maskMetadata:Ce,mutators:re,queues:C,rlsMetadata:zt,schema:a,schemaSnapshot:oe,shapes:q,storageRules:B,studioFeatures:W,useUmbrella:K,workflows:O}),De=is(q,v.has("@lunora/db"),K),ke=os(u,a.jurisdiction),Me=as(O),Ke=cs(c),_e=ls(C),ze=us(ie),Ue=ds(a.vectorIndexes),H=fs(a,K),Be=ps(v.has("@lunora/seed")),G=e.apiSpec??"openapi",ae=G==="openapi"||G==="both",ce=G==="openrpc"||G==="both",qe=on({emailAgents:c.filter(h=>h.onEmail===!0).map(h=>({bindingName:h.bindingName,exportName:h.exportName})),hasAccess:v.has("@lunora/cloudflare-access"),hasAi:p.ai,hasAnalytics:p.analytics,hasAuth:v.has("@lunora/auth"),hasBrowser:A,hasFramework:v.has("@lunora/astro")||v.has("@lunora/svelte")||v.has("@lunora/vue"),hasGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend!=="hyperdrive"),hasHyperdrive:p.hyperdrive,hasHyperdriveGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend==="hyperdrive"),hasImages:p.images,hasKv:W.kv,hasNotify:z,hasPayments:p.payments,hasR2sql:p.r2sql,hasQueue:C.some(h=>h.mode==="push"),hasScheduler:W.scheduler,hasStorage:W.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:O.length>0,hasX402:p.x402,identity:U,jurisdiction:a.jurisdiction,useUmbrella:K,voiceAgents:c.filter(h=>h.voice===!0&&h.voiceBindingName!==void 0).map(h=>({bindingName:h.voiceBindingName,exportName:h.exportName})),wantsOpenApi:ae,wantsOpenRpc:ce}),$e=Vc(e.projectRoot),Ve=an({functions:L,httpRoutes:Pe,version:$e}),je=ln({functions:L,version:$e}),We=`${JSON.stringify(Ve,void 0,2)}
|
|
8
|
-
`,He=`${JSON.stringify(je,void 0,2)}
|
|
9
|
-
`,Ge=cn(Ve),Ye=un(je),le=f(n,$c),Bt=N(le);if(e.dryRun||(N(m)||jt(m,{recursive:!0}),b(f(m,"app.ts"),qe),b(be,d),b(f(m,"api.ts"),Re),b(Ie,M),b(f(m,"functions.ts"),Fe),b(f(m,"shard.ts"),Le),b(f(m,"crons.ts"),ze),b(f(m,"vectors.ts"),Ue),b(f(m,"drizzle.global.ts"),H.global),b(f(m,"drizzle.shard.ts"),H.shard),w(f(m,"containers.ts"),ke),w(f(m,"workflows.ts"),Me),w(f(m,"agents.ts"),Ke),w(f(m,"queues.ts"),_e),w(f(m,"seed.ts"),Be),w(f(m,"collections.ts"),De),w(f(m,"openapi.json"),ae?We:""),w(f(m,"openapi.ts"),ae?Ge:""),w(f(m,"openrpc.json"),ce?He:""),w(f(m,"openrpc.ts"),ce?Ye:""),(!Bt||e.updateSchemaBaseline===!0)&&b(le,Yt(oe))),t){const h=de.now(),qt=Math.round(h-s),$t=Math.round(Oe-s),Vt=Math.round(h-Oe);console.error(`@lunora/codegen: codegen took ${qt.toString()}ms (discovery ${$t.toString()}ms, emit ${Vt.toString()}ms)`)}return{advisories:Te,advisorContext:j,agents:c,containers:u,cronTriggers:gs(ie),generated:{agents:Ke,api:Re,app:qe,collections:De,containers:ke,crons:ze,dataModel:d,drizzleGlobal:H.global,drizzleShard:H.shard,functions:Fe,openApi:We,openApiModule:Ge,openRpc:He,openRpcModule:Ye,queues:_e,seed:Be,server:M,shard:Le,vectors:Ue,workflows:Me},outputDirectory:m,platformDiagnostics:V.diagnostics,queues:C,schemaSnapshot:oe,schemaSnapshotPath:le,workflows:O}};export{$c as SCHEMA_SNAPSHOT_FILENAME,Gc as createCodegenProject,Wc as findTsconfig,Kl as refreshCodegenProject,_l as runCodegen};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{SyntaxKind as u,Node as s}from"ts-morph";import{l as R,a as _}from"./discover-ast-D33zP-NZ.mjs";import{a as z}from"./module-specifiers-WF8iAydP.mjs";import{p as M,a as T}from"./parse-validator-BFTp87yz.mjs";import{s as U}from"./paths-C-9fwEgQ.mjs";const y=new Set(["action","mutation","query","stream"]),P=/\bany\b(?!\s*(?:\?\s*)?:)/u,S=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,j=/^[A-Za-z_$][\w$]*$/u,$=e=>j.test(e)?e:JSON.stringify(e),h={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},V={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init"},K=z,I=e=>{const t=e.getSymbol();if(!t)return e.getText();const r=t.getDeclarations();for(const i of r){if(!s.isImportSpecifier(i))continue;const o=i.getImportDeclaration().getModuleSpecifierValue();return K(o)?i.getNameNode().getText():void 0}},C=(e,t=!1)=>{let r=e;for(;s.isCallExpression(r);){const n=r.getExpression();if(!s.isPropertyAccessExpression(n))return;r=n.getExpression()}if(!s.isIdentifier(r))return;const i=I(r);if(i===void 0){if(t)return;const n=r.getSymbol()?.getValueDeclaration();if(n&&s.isVariableDeclaration(n)){const o=n.getInitializer();return o?C(o,!0):void 0}return}return y.has(i)?"public":h[i]?"internal":void 0},m=(e,t)=>{const r=e.getProperty(t);if(r===void 0||!s.isPropertyAssignment(r))return;const i=r.getInitializer();return i!==void 0&&s.isStringLiteral(i)?i.getLiteralValue():void 0},A=(e,t)=>{const r=e.getProperty(t);if(r===void 0||!s.isPropertyAssignment(r))return;const i=r.getInitializer();return i!==void 0&&s.isNumericLiteral(i)?i.getLiteralValue():void 0},B=e=>{const t=e.getProperty("cache");if(t===void 0||!s.isPropertyAssignment(t))return;const r=t.getInitializer();if(r===void 0||!s.isObjectLiteralExpression(r))return;const i=m(r,"scope"),n=A(r,"maxAge"),o=A(r,"staleWhileRevalidate"),a=m(r,"tag"),c=m(r,"vary"),l={...n===void 0?{}:{maxAge:n},...i==="private"||i==="public"?{scope:i}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},H=e=>{if(e===void 0||!s.isObjectLiteralExpression(e))return{};const t=B(e),r=e.getProperty("rest");return r!==void 0&&s.isPropertyAssignment(r)?{...t===void 0?{}:{cache:t},rest:r.getInitializer()?.getText()==="true"}:t===void 0?{}:{cache:t}},G=e=>{let t=e;for(;s.isCallExpression(t);){const r=t.getExpression();if(!s.isPropertyAccessExpression(r))return;if(r.getName()==="expose")return H(t.getArguments()[0]);t=r.getExpression()}},q=e=>{const t=e.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))return{};const r=t.getProperty("args");if(!r||!s.isPropertyAssignment(r))return{};const i=r.getInitializer();return!i||!s.isObjectLiteralExpression(i)?{}:T(i)},J="/_generated/",b=(e,t,r)=>e.getImportDeclarations().some(i=>i.getModuleSpecifierSourceFile()!==t?!1:i.getNamespaceImport()!==void 0||i.getNamedImports().some(n=>n.getName()===r)),Q=new Set([u.ClassDeclaration,u.EnumDeclaration,u.EnumMember,u.InterfaceDeclaration,u.TypeAliasDeclaration]),D=(e,t,r)=>{const i=e.getSourceFile();if(i.isInNodeModules()||i.isDeclarationFile()||!Q.has(e.getKind()))return!1;const n=i.getFilePath();return n.includes(J)?!1:n===r?!0:s.isEnumMember(e)?b(t.getSourceFile(),i,e.getParent().getName()):s.hasName(e)&&b(t.getSourceFile(),i,e.getName())},W=(e,t,r)=>[e.getSymbol(),e.getAliasSymbol()].flatMap(i=>i?.getDeclarations()??[]).some(i=>D(i,t,r)),X=(e,t,r)=>{const i=s.isPropertySignature(e)||s.isPropertyDeclaration(e)?e.getTypeNode():void 0;return i===void 0?!1:[i,...i.getDescendantsOfKind(u.TypeReference)].filter(n=>s.isTypeReference(n)).flatMap(n=>{const o=n.getTypeName().getSymbol();return(o?.getAliasedSymbol()??o)?.getDeclarations()??[]}).some(n=>D(n,t,r))},Y=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},F=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0,f=(e,t,r,i=new Set)=>i.has(e)?!1:(i.add(e),W(e,t,r)||Y(e).some(n=>f(n,t,r,i))?!0:F(e)?e.getProperties().some(n=>n.getDeclarations().some(o=>X(o,t,r))?!0:f(n.getTypeAtLocation(t),t,r,i)):!1),Z=(e,t)=>{const r=e.getValueDeclaration()??e.getDeclarations()[0];return r&&(s.isPropertySignature(r)||s.isPropertyDeclaration(r))&&r.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(i=>i.isUndefined())},ee=8,te=(e,t,r,i,n,o)=>{const a=e.getArrayElementType(),c=a?o(a,t,r,i,n):void 0;if(c!==void 0)return a?.isUnion()?`(${c})[]`:`${c}[]`},re=(e,t,r,i,n,o)=>{const a=[];for(const c of e.getUnionTypes()){const l=o(c,t,r,i,n);if(l===void 0)return;a.push(l)}return a.join(" | ")},ie=(e,t,r,i,n,o)=>{if(!F(e))return;const a=[];for(const c of e.getProperties()){const l=c.getTypeAtLocation(t),v=Z(c,l),k=v&&l.isUnion()?l.getUnionTypes().filter(d=>!d.isUndefined()):[l],E=[];for(const d of k){const x=o(d,t,r,i+1,n);if(x===void 0)return;E.push(x)}a.push(`${$(c.getName())}${v?"?":""}: ${E.join(" | ")}`)}return a.length>0?`{ ${a.join("; ")} }`:"{}"},ne=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},se=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>s.isClassDeclaration(t)||s.isClassExpression(t)),g=(e,t,r,i,n)=>{if(i>ee||n.has(e))return;if(!f(e,t,r))return e.getText(t);const o=new Set(n).add(e);if(e.isArray())return te(e,t,r,i,o,g);if(e.isUnion())return re(e,t,r,i,o,g);if(e.isEnumLiteral())return ne(e);if(!se(e))return ie(e,t,r,i,o,g)},L=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let r=t.getReturnType();const n=(r.getSymbol()??r.getAliasSymbol())?.getName();if(n==="Promise"||n==="AsyncIterable"||n==="AsyncIterableIterator"||n==="AsyncGenerator"){const c=r.getTypeArguments()[0];c&&(r=c)}const o=r.getText(e);if(!o||o==="any"||o==="never"||P.test(o.replaceAll(S,"")))return"unknown";const a=e.getSourceFile().getFilePath();return f(r,e,a)?g(r,e,a,0,new Set)??"unknown":o},Te=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const r=t.getTypeAtLocation(e).getProperty("types");if(!r)return;const i=r.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!i)return;const n=i.getTypeAtLocation(e),o=n.getText(e);if(!o||o==="any"||o==="never"||P.test(o.replaceAll(S,"")))return;const a=e.getSourceFile().getFilePath();return f(n,e,a)?g(n,e,a,0,new Set):o},oe=e=>{const t=e.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))return"unknown";const r=t.getProperty("handler");if(!r||!s.isPropertyAssignment(r))return"unknown";const i=r.getInitializer();return!i||!(s.isArrowFunction(i)||s.isFunctionExpression(i))?"unknown":L(i)},ae=e=>{const t=e.getArguments()[0];return!t||!(s.isArrowFunction(t)||s.isFunctionExpression(t))?"unknown":L(t)},ce=e=>{let t={},r=e;for(;s.isCallExpression(r);){const i=r.getExpression();if(!s.isPropertyAccessExpression(i))break;if(i.getName()==="input"){const n=r.getArguments()[0];n&&s.isObjectLiteralExpression(n)&&(t={...T(n),...t})}r=i.getExpression()}return t},le=e=>{let t=e;for(;s.isCallExpression(t);){const r=t.getExpression();if(!s.isPropertyAccessExpression(r))return;if(r.getName()==="output"){const i=t.getArguments()[0];return i&&s.isExpression(i)?M(i):void 0}t=r.getExpression()}},ue=e=>{const t=e.getExpression();if(s.isPropertyAccessExpression(t)){const o=t.getName();if(!y.has(o))return;const a=t.getExpression();if(a.getType().getProperty("__lunoraProcedure"))return{kind:o,receiver:a,visibility:a.getType().getProperty("__lunoraVisibility")?"internal":"public"};const c=C(a);return c?{kind:o,receiver:a,visibility:c}:void 0}if(!s.isIdentifier(t))return;const r=I(t);if(!r)return;if(y.has(r))return{kind:r,visibility:"public"};const i=h[r];if(i)return{kind:i,visibility:"internal"};const n=V[r];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}},N=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,Pe=e=>s.isPropertyAccessExpression(e)&&e.getName()==="db"||s.isIdentifier(e)&&e.getText()==="db",Se=e=>{const t=e.getArguments()[0],r=N(t);if(r!==void 0)return r;if(t===void 0||!s.isObjectLiteralExpression(t))return;const i=t.getProperty("handler");return i!==void 0&&s.isPropertyAssignment(i)?N(i.getInitializer()):void 0},pe=e=>s.isIdentifier(e)?e.getText():s.isPropertyAccessExpression(e)?e.getName():"",he=(e,t)=>{let r=e;for(;s.isCallExpression(r);){const i=r.getExpression();if(!s.isPropertyAccessExpression(i))break;if(i.getName()===t)return!0;r=i.getExpression()}return!1},Ie=(e,t,r)=>{let i=e;for(;s.isCallExpression(i);){const n=i.getExpression();if(!s.isPropertyAccessExpression(n))break;const o=i.getArguments()[0];if(n.getName()===t&&o!==void 0&&s.isCallExpression(o)&&pe(o.getExpression())===r)return!0;i=n.getExpression()}return!1},ge=e=>{const t=ue(e);if(t){if(t.receiver){const r=G(t.receiver),i=le(t.receiver);return{args:ce(t.receiver),...r?{expose:r}:{},kind:t.kind,...i?{output:i}:{},returnType:ae(e),visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:q(e),kind:t.kind,returnType:oe(e),visibility:t.visibility}}},fe=8,p=(e,t=0)=>{if(t>fe)return;if(s.isCallExpression(e))return e;if(s.isParenthesizedExpression(e)||s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isNonNullExpression(e))return p(e.getExpression(),t+1);if(!s.isIdentifier(e)&&!s.isPropertyAccessExpression(e))return;const r=e.getSymbol()?.getValueDeclaration();return r?O(r,t+1):void 0},O=(e,t)=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e)){const r=e.getInitializer();return r?p(r,t):void 0}if(s.isShorthandPropertyAssignment(e))return p(e.getNameNode(),t);if(s.isBindingElement(e)){const r=e.getPropertyNameNode()?.getText()??e.getName(),o=e.getFirstAncestorByKind(u.VariableDeclaration)?.getInitializer()?.getType().getProperty(r)?.getValueDeclaration();return o?O(o,t+1):void 0}},de=e=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t)){const n=[];for(const o of t.getElements()){const a=p(o.getNameNode());a&&n.push([o.getName(),a])}return n}const r=e.getInitializer(),i=r&&(s.isCallExpression(r)?r:p(r));return i?[[e.getName(),i]]:[]},w=(e,t,r)=>{const i=ge(e);if(i)return{args:i.args,exportName:t,filePath:r,kind:i.kind,returnType:i.returnType,...i.output?{output:i.output}:{},visibility:i.visibility,...i.expose?{expose:i.expose}:{},...i.lifecycle?{lifecycle:i.lifecycle}:{}}},me=(e,t)=>{const r=[];for(const i of e.getExportAssignments()){if(i.isExportEquals())continue;const n=p(i.getExpression()),o=n?w(n,"default",t):void 0;o&&r.push(o)}return r},ye=(e,t)=>{const r=[];for(const i of e.getVariableStatements())if(i.isExported())for(const n of i.getDeclarations())for(const[o,a]of de(n)){const c=w(a,o,t);c&&r.push(c)}return r.push(...me(e,t)),r},ve=e=>{const t=new Map;for(const r of e){const i=U(r.filePath),n=t.get(i);if(n&&n!==r.filePath)throw Object.assign(new Error(`Namespace collision: "${n}" and "${r.filePath}" both resolve to "${i}". 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:[n,r.filePath],status:500});t.set(i,r.filePath)}},Ce=(e,t)=>{const r=R(t),i=[];for(const n of r){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),a=_(t,n);i.push(...ye(o,a))}return i.sort((n,o)=>`${n.filePath}:${n.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),ve(i),i};export{he as chainHasStep,Ie as chainUsesWrappedCall,ue as classifyProcedureCall,Ce as discoverFunctions,N as inlineHandler,Pe as isDatabaseAccessor,R as listLunoraSourceFiles,_ as lunoraRelativePath,Se as procedureHandler,Te as resolveStandardSchemaType,L as unwrapHandlerReturn};
|