@lunora/codegen 1.0.0-alpha.329 → 1.0.0-alpha.330
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{MUTATORS_FILENAME-Jkk8Zgkb.mjs → MUTATORS_FILENAME-B_I0kkvJ.mjs} +1 -1
- package/dist/packem_shared/{NOTIFY_FILENAME-DiYZjYts.mjs → NOTIFY_FILENAME-DOIxn0Qb.mjs} +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DdPW4JCi.mjs +31 -0
- package/dist/packem_shared/{SHAPES_FILENAME-DkBUN9dK.mjs → SHAPES_FILENAME-D7Ifi5Ce.mjs} +1 -1
- package/dist/packem_shared/chain-ZlTHdRo2.mjs +1 -0
- package/dist/packem_shared/classify-procedure-call-Bw5sia-K.mjs +1 -0
- package/dist/packem_shared/{context-property-calls-eO5eiVZG.mjs → context-property-calls-Co_G3ENU.mjs} +1 -1
- package/dist/packem_shared/{context-root-D-pTjHtx.mjs → context-root-BTW5XwVq.mjs} +1 -1
- package/dist/packem_shared/{database-calls-DJgmh0Kv.mjs → database-calls-D-GwIhWO.mjs} +1 -1
- package/dist/packem_shared/{discoverCrons-DBnCama4.mjs → discoverCrons-B2SdRjRO.mjs} +1 -1
- package/dist/packem_shared/{discoverFunctions-CIJja4zp.mjs → discoverFunctions-C9Ra5XXH.mjs} +1 -1
- package/dist/packem_shared/discoverHyperdriveCalls-DfCAjBgd.mjs +1 -0
- package/dist/packem_shared/{discoverInserts-CednbRCq.mjs → discoverInserts-T5ojinqL.mjs} +1 -1
- package/dist/packem_shared/discoverMaskProcedures-DKd9fVDa.mjs +1 -0
- package/dist/packem_shared/{discoverMigrations-C9mLIhGZ.mjs → discoverMigrations-ClgjUkaG.mjs} +1 -1
- package/dist/packem_shared/{discoverNondeterministicCalls-B6FUSWes.mjs → discoverNondeterministicCalls-UCUCyCox.mjs} +1 -1
- package/dist/packem_shared/{discoverQueries-BezURxvr.mjs → discoverQueries-u2XNpxsn.mjs} +1 -1
- package/dist/packem_shared/discoverR2sqlCalls-jz5KouxF.mjs +1 -0
- package/dist/packem_shared/{discoverRlsMetadata-DCgP2H39.mjs → discoverRlsMetadata-D2G3YAoe.mjs} +1 -1
- package/dist/packem_shared/{discoverRlsProcedures-Os1lrVX_.mjs → discoverRlsProcedures-BD8aG1BU.mjs} +1 -1
- package/dist/packem_shared/{discoverStorageRulesMetadata-BTD9Vs5X.mjs → discoverStorageRulesMetadata-C2ceH0ZO.mjs} +1 -1
- package/dist/packem_shared/{emitShard-Ba8hJ_G8.mjs → emitShard-DtfjUgjj.mjs} +1 -1
- package/dist/packem_shared/{exported-procedure-chains-DOFtzPZn.mjs → exported-procedure-chains-CVzkVdq4.mjs} +1 -1
- package/dist/packem_shared/{index-iWQbulvu.mjs → index-BPUxZYM5.mjs} +1 -1
- package/dist/packem_shared/{module-specifiers-WF8iAydP.mjs → module-specifiers-BctA0m_p.mjs} +1 -1
- package/dist/packem_shared/{shard-BtImwCVL.mjs → shard-CsfiXxV0.mjs} +130 -105
- package/package.json +9 -9
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-GV-_yNKe.mjs +0 -11
- package/dist/packem_shared/chain-DYBhMcDK.mjs +0 -1
- package/dist/packem_shared/classify-procedure-call-DUBO9bqm.mjs +0 -1
- package/dist/packem_shared/discoverHyperdriveCalls-DVIQ0i_e.mjs +0 -1
- package/dist/packem_shared/discoverMaskProcedures-B4k9BS0s.mjs +0 -1
- package/dist/packem_shared/discoverR2sqlCalls-B9Q6xfi6.mjs +0 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import{existsSync as M,mkdirSync as Kt,readFileSync as ur,writeFileSync as fr,rmSync as ye,readdirSync as Pn}from"node:fs";import{dirname as zt,join as E,relative as wn}from"node:path";import{performance as gt}from"node:perf_hooks";import{runAdvisor as gr}from"@lunora/advisor";import{LunoraError as _}from"@lunora/errors";import{serializeSchemaSnapshot as pr}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{toAdvisorContext as mr}from"./formatAdvisories-BCVASH7N.mjs";import{Node as r,SyntaxKind as d,ts as hr,VariableDeclarationKind as vr}from"ts-morph";import{listLunoraSourceFiles as A,lunoraRelativePath as w,bindingKeyName as ae,collectCallRows as C,findObjectProperty as V,collectSecurityCallRows as Er,propertyInitializer as F,listSecurityScanFiles as He,objectLiteralFromCallbackBody as In,limitNameOf as Cn,optionsObjectLiteral as Tn,handlerOf as xr,collectNodeRows as ne,chainRootOf as Ge,outermostValueWrapper as I,isWriteTarget as Ye,isSameNode as y,unwrapExpression as h,isConstDeclaration as ie,memberAccessOf as $t,returningFunctionOf as bt,walkChain as Sr,RUN_METHODS as On,functionReferenceSegments as Ar,isTestPath as yr,isFunctionLike as re,functionKeyOf as kn}from"./isTestPath-B81lOULB.mjs";import{b as Y,d as j,f as L,g as Bt,c as x,a as Vt,w as Ut,k as br,l as Nr,h as Pr,m as wr,j as Nt,i as Ir}from"./attribution-hVBriwzy.mjs";import{a as Os,r as pt,i as H,b as Cr,m as Rn,c as Qe,e as Wt,E as Fn,C as Ln,d as Tr,f as Or,g as kr}from"./context-root-BTW5XwVq.mjs";import{a as P,i as Rr,c as ee,d as Dn,e as Fr,f as Lr,g as Mn}from"./classify-procedure-call-Bw5sia-K.mjs";import{a as S,r as _n,s as Dr,b as Mr}from"./project-config-file-BV7RR-l6.mjs";import{b as _r,a as Xe}from"./module-specifiers-BctA0m_p.mjs";import{r as Je,s as Kr}from"./parse-validator-IDBKIT7M.mjs";import zr from"./discoverAuthApiCalls-xs0ONfI-.mjs";import{i as z,r as Kn}from"./database-calls-D-GwIhWO.mjs";import $r from"./discoverHyperdriveCalls-DfCAjBgd.mjs";import{diagnosticAt as le}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{m as qt,a as $e,s as zn,d as Br}from"./index-BPUxZYM5.mjs";import{MUTATORS_FILENAME as Vr,isDefineMutatorCallee as Ur,mutatorServerImplOf as Wr,discoverMutators as qr}from"./MUTATORS_FILENAME-B_I0kkvJ.mjs";import jr from"./discoverNondeterministicCalls-UCUCyCox.mjs";import{discoverNotifyConfig as Hr,discoverNotifyCalls as Gr}from"./NOTIFY_FILENAME-DOIxn0Qb.mjs";import Yr from"./discoverR2sqlCalls-jz5KouxF.mjs";import Qr from"./discoverRlsProcedures-BD8aG1BU.mjs";import{s as jt,n as Xr}from"./dispatch-namespace-DwTjD7BU.mjs";import{secretKindOf as Jr,redact as Zr,isHeuristicSecretKind as eo,isSecretishName as to}from"./redact-Cy14LEnc.mjs";import{a as Fe,d as so,r as no}from"./modules-CjOcuQnK.mjs";import{WORKFLOWS_FILENAME as io,discoverWorkflows as ro}from"./WORKFLOWS_FILENAME-CdeS224T.mjs";import{r as oo}from"./json-data-Chfs2Cz5.mjs";import{a as ao,I as co,g as lo,G as $n,d as uo}from"./shared-DnCokNcE.mjs";import{createCodegenProject as fo}from"./createCodegenProject-V51_yBw3.mjs";import{findTsconfig as SE,refreshCodegenProject as AE}from"./createCodegenProject-V51_yBw3.mjs";import{CAPABILITIES as go,usedCapabilities as po}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{isD1GlobalTable as Bn,isHyperdriveGlobalTable as Vn}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as mo}from"./AGENTS_FILENAME-B6-kjzM3.mjs";import{discoverContainers as ho}from"./CONTAINERS_FILENAME-dFRtAyIe.mjs";import vo from"./discoverCrons-B2SdRjRO.mjs";import{contextPropertiesRead as Eo,discoverFeatureUsage as xo}from"./capabilitiesUsedBy-CF7sUwa8.mjs";import Un from"./readPackageDependencies-RHhGiz0k.mjs";import{PROJECT_CONFIG_FILENAMES as So,findProjectConfigFile as Ao}from"./PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";import{discoverQueueDeclarations as yo}from"./QUEUES_FILENAME-CsRy4VTF.mjs";import{discoverSandboxUsage as bo}from"./discoverSandboxUsage-w6Q3RvxZ.mjs";import{resolveServiceBindings as No}from"./readServiceBindings-DvqIThzd.mjs";import Po from"./discoverStorageRulesMetadata-C2ceH0ZO.mjs";import{resolveCodegenTarget as Pt,gatePlatformFeatures as wo,readTargetDiagnostics as Io,vectorizeDimensionDiagnostics as Co,liveStreamsDeliveryAuthorizationDiagnostic as To,socketRoutesDeliveryAuthorizationDiagnostic as Oo,studioPlatformFor as ko,platformFeatureAvailable as Ro}from"./DEFAULT_TARGET-BbWiB-rs.mjs";import{i as Fo}from"./schema-BgM8A3XV.mjs";import{b as Wn,e as Lo}from"./shard-CsfiXxV0.mjs";import{e as Do,a as Mo}from"./server-DAvi_bv_.mjs";import{emitDataModel as _o}from"./emitDataModel-BskFt9Wv.mjs";import{i as Ko,a as zo,e as $o,b as Bo,d as Vo,c as Uo}from"./unwrap-handler-return-CeaOifqX.mjs";import Wo from"./discoverFunctions-C9Ra5XXH.mjs";import qo from"./discoverHttpRoutes-WBAqBcfK.mjs";import jo from"./discoverInserts-T5ojinqL.mjs";import{e as qn}from"./exported-procedure-chains-CVzkVdq4.mjs";import Ho from"./discoverMigrations-ClgjUkaG.mjs";import Go from"./discoverQueries-u2XNpxsn.mjs";import Yo from"./discoverRlsMetadata-D2G3YAoe.mjs";import Qo from"./discoverSchema-BtsX-CN9.mjs";import{discoverShapes as Xo}from"./SHAPES_FILENAME-D7Ifi5Ce.mjs";import{i as Jo}from"./reserved-words-CW1QFbTd.mjs";import{emitApp as Zo}from"./emitApp-DuJW6LKD.mjs";import{readJsonSync as ea}from"@visulima/fs";import{buildSchemaSnapshot as ta}from"./SchemaSnapshotParseError-BRJT7c2k.mjs";import{buildOpenApiDocument as sa,emitOpenApiModule as na}from"./buildOpenApiDocument-DFv-RYZU.mjs";import{buildOpenRpcDocument as ia,emitOpenRpcModule as ra}from"./OPENRPC_VERSION-CCY7xqSL.mjs";import{v as oa,t as aa,u as ca,s as la,w as da}from"./shard-runtime-BpoCV-aM.mjs";import{emitCollections as ua,emitSeed as fa,emitApi as ga,emitInternalApi as pa}from"./emitApi-CDgIPAG2.mjs";import{emitCrons as ma,emitScheduler as ha,emitShardRegistry as va,emitDurableObjects as Ea,emitVectors as xa,emitWranglerCronTriggers as Sa}from"./emitCrons-BQW2lviZ.mjs";import Aa from"./emitDrizzleSchema-DitcRZ1a.mjs";import{LAZY_FUNCTION_DIRECTORY as jn,emitFunctions as ya,emitLazyFunctionModules as ba}from"./emitFunctions-Cd0Tuw73.mjs";const Na=(e,t=!1)=>{if(e.length===0)return"";const s=uo(t),n=e.map(c=>{if(ao(c.exportName,"live stream export name"),!co.test(c.filePath))throw new Error(`@lunora/codegen: live stream file path is not safe to import: ${JSON.stringify(c.filePath)}`);return`import type { ${c.exportName} as ${c.exportName}Stream } from "../${c.filePath}.js";`}),i=e.map(c=>{const l=c.topics.map(u=>{lo(u.name,"live topic name");const f=`(typeof ${c.exportName}Stream)["topics"]["${u.name}"]`,g=`LiveTopicRef<LiveTopicPayload<${f}>>`,p=JSON.stringify(c.id);if(u.fields.length===0)return` ${u.name}: (): ${g} => ({ __lunoraLive: ${p}, topic: ${JSON.stringify(u.name)} }),`;const v=u.fields.map($=>`\${encodeURIComponent(key.${$})}`).join(":");return` ${u.name}: (key: LiveTopicKey<${f}>): ${g} => ({
|
|
2
|
+
__lunoraLive: ${p},
|
|
3
|
+
topic: \`${u.name}:${v}\`,
|
|
4
|
+
}),`});return` ${c.exportName}: {
|
|
5
|
+
${l.join(`
|
|
6
|
+
`)}
|
|
7
|
+
},`}),a=e.some(c=>c.topics.some(l=>l.fields.length>0))?"LiveTopicKey, LiveTopicPayload, LiveTopicRef":"LiveTopicPayload, LiveTopicRef";return`${$n}import type { ${a} } from "${s.server}";
|
|
8
|
+
|
|
9
|
+
${n.join(`
|
|
10
|
+
`)}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A typed reference to each declared live topic, grouped by the stream's export name:
|
|
14
|
+
* \`live.posts.post({ postId })\`. Pass one to \`ctx.live.publish(ref, payload)\` on the server, or to a
|
|
15
|
+
* live-topic hook in the browser. A reference is plain data and carries no server code.
|
|
16
|
+
*/
|
|
17
|
+
export const live = {
|
|
18
|
+
${i.join(`
|
|
19
|
+
`)}
|
|
20
|
+
};
|
|
21
|
+
`},Hn=new Set(["delete","get","head","options","patch","post","put"]),Pa=new Set(["handler","stream"]),wa=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,ks=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Ia=e=>{if(!r.isCallExpression(e))return;const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!Hn.has(t.getName()))return;const s=t.getExpression();if(!r.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!r.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},Ca=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;r.isCallExpression(s);){const n=s.getExpression();if(!r.isPropertyAccessExpression(n)||Hn.has(n.getName()))break;s=n.getExpression()}return Ia(s)},Ta=e=>{for(const t of e.getDescendantsOfKind(d.PropertyAccessExpression))if(ks.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=t.getExpression();if(r.isIdentifier(s)&&ks.has(s.getText()))return!0}return!1},Oa=(e,t)=>{const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const n=s.getExpression();if(!r.isPropertyAccessExpression(n)||!Pa.has(n.getName()))return;const i=Ca(s);if(!i||!wa.test(i.path))return;const o=s.getArguments()[0],a=o!==void 0&&(r.isArrowFunction(o)||r.isFunctionExpression(o))&&Ta(o);return{exportName:j(e)??e.getName(),file:t,method:i.method,path:i.path,usesGuard:a}},ka=(e,t)=>{const s=[];for(const n of Y(e)){const i=Oa(n,t);i&&s.push(i)}return s},Ra=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ka(i,w(t,n)))}return s},Fa=e=>{const t=e.getText(),s=n=>{const i=n.getNameNode();return r.isIdentifier(i)&&i.getText()===t};for(const n of e.getAncestors())if(!(!r.isArrowFunction(n)&&!r.isFunctionExpression(n)&&!r.isFunctionDeclaration(n)))for(const i of n.getParameters()){const o=i.getDescendantsOfKind(d.BindingElement).find(a=>s(a));if(o!==void 0)return o}},La=e=>{let t=e;for(;;){const s=t.getParent();if(!r.isObjectBindingPattern(s))return;const n=s.getParent();if(r.isBindingElement(n)){t=n;continue}return r.isParameterDeclaration(n)?ae(t):void 0}},Da=e=>{const t=e.getText();if(!e.getAncestors().some(o=>{const a=r.isFunctionLikeDeclaration(o)||r.isArrowFunction(o)?o.getParameters()[1]:void 0,c=a?.getNameNode();return a!==void 0&&(r.isIdentifier(c)?c.getText()===t:a.getDescendantsOfKind(d.BindingElement).some(l=>l.getName()===t))&&Os(a)}))return!1;const n=L(e),i=r.isParameterDeclaration(n)?n:n?.getFirstAncestorByKind(d.Parameter);return i!==void 0&&(r.isParameterDeclaration(n)||r.isBindingElement(n))&&Os(i)},Rs=(e,t)=>{const s=e.getParent();if(r.isPropertyAccessExpression(s)&&s.getNameNode()===e||r.isPropertyAssignment(s)&&s.getNameNode()===e)return!1;if(e.getText()===t)return!0;const n=Fa(e);return n!==void 0&&La(n)===t?!0:t==="args"&&Da(e)},Gn=(e,t)=>r.isIdentifier(e)?Rs(e,t):e.getDescendantsOfKind(d.Identifier).some(s=>Rs(s,t)),Ma=e=>{let t=e;for(;r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t)||r.isNonNullExpression(t);)t=t.getExpression();return r.isIdentifier(t)?t:void 0},Fs=e=>{const t=r.isIdentifier(e)?L(e):void 0;return r.isVariableDeclaration(t)&&r.isIdentifier(t.getNameNode())&&!Bt(t)?t.getInitializer():void 0},wt=e=>Gn(e,"args"),G=e=>{if(!r.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>r.isArrowFunction(a)||r.isFunctionExpression(a)||r.isFunctionDeclaration(a));if(s===void 0)return;const n=e.getStart();let i,o=-1;for(const a of s.getDescendantsOfKind(d.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<n&&l>o&&(i=c,o=l)}return i},q=e=>{if(wt(e))return!0;const t=G(e);return t!==void 0&&wt(t)},_a=e=>{if(r.isCallExpression(e)||r.isNewExpression(e))return!1;const t=G(e);return t===void 0||!(r.isCallExpression(t)||r.isNewExpression(t))},ce=e=>{if(pt(e))return!0;const t=Fs(e);if(t!==void 0&&pt(t))return!0;const s=t??e;return(r.isIdentifier(s)?[s]:s.getDescendantsOfKind(d.Identifier)).some(i=>{const o=Fs(i);return o!==void 0&&pt(o)})},Le=(e,t)=>Gn(e,t),Ka=(e,t)=>{if(Le(e,t))return!0;const s=G(e);if(s!==void 0&&Le(s,t))return!0;const n=Ma(e);if(n!==void 0){const i=G(n);return i!==void 0&&Le(i,t)}return!1},za=e=>!r.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:H(e.getExpression(),["ai"]),$a=(e,t)=>{if(!za(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!q(s)||ce(s)))return{scope:x(e),file:t,line:e.getStartLineNumber()}},Ba=(e,t)=>C(e,t,$a),Va=new Set(["generateText","streamText"]),Ua=new Set(["messages","prompt","system"]),Wa=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","patchIf","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],qa=(e,t)=>Wa.some(s=>s.methods.has(t)&&s.prefixes.some(n=>e===n||e.startsWith(`${n}.`))),ja=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return;const s=t.getName(),n=[Cr(t.getExpression()),t.getExpression().getText()].find(i=>i!==void 0&&qa(i,s));return n===void 0?void 0:`${n}.${s}`},Ha=e=>{for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=ja(t);if(s!==void 0)return s}},Ga=e=>{const t=new Set,s=e.getFirstAncestor(o=>r.isArrowFunction(o)||r.isFunctionExpression(o)||r.isFunctionDeclaration(o)),[n]=s?.getParameters()??[],i=n?.getNameNode();if(i===void 0||!r.isObjectBindingPattern(i))return t;for(const o of i.getElements()){const a=ae(o),c=o.getNameNode();if(a==="args"&&r.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},Ya=e=>{if(wt(e))return!0;const t=Ga(e);return t.size===0?!1:e.getDescendantsOfKind(d.Identifier).some(s=>t.has(s.getText()))},Qa=e=>{for(const t of e.getProperties()){if(!r.isPropertyAssignment(t)||!Ua.has(S(t)))continue;const s=t.getInitializer();if(s!==void 0&&Ya(s))return!0}return!1},Xa=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=P(n.getExpression());if(i===void 0||!Va.has(i))continue;const[o]=n.getArguments();if(o===void 0||!r.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(d.CallExpression))if(P(c.getExpression())==="tool"&&(a=Ha(c),a!==void 0))break;a!==void 0&&s.push({scope:x(n),file:t,line:n.getStartLineNumber(),method:i,sideEffect:a,userInputDerived:Qa(o)})}return s},Ja=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Xa(i,w(t,n)))}return s},Za=e=>H(e,["fetch"]),ec=(e,t)=>{if(!Za(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!q(s)))return{scope:x(e),file:t,line:e.getStartLineNumber()}},tc=(e,t)=>C(e,t,ec),Ht=(e,t=new Set)=>{if(t.has(e))return!0;t.add(e);try{return e.getProperties().some(s=>{if(!r.isSpreadAssignment(s))return!1;const n=Je(s.getExpression());return n===void 0||Ht(n,t)})}finally{t.delete(e)}},sc=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=V(t,"args");if(!s)return{objects:[],opaque:!1};if(!r.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer(),i=n===void 0?void 0:Je(n);return i===void 0?{objects:[],opaque:!0}:{objects:[i],opaque:Ht(i)}},nc=e=>{const t=[];let s=!1,n=e;for(;r.isCallExpression(n);){const i=n.getExpression();if(!r.isPropertyAccessExpression(i))break;if(i.getName()==="input"){const o=n.getArguments()[0],a=o!==void 0&&r.isExpression(o)?Je(o):void 0;a===void 0?s=!0:(t.push(a),s||=Ht(a))}n=i.getExpression()}return{objects:t,opaque:s}},Gt=(e,t)=>t?nc(t):sc(e),Yn=(e,t)=>{if(t.has(e))return[];t.add(e);try{return e.getProperties().flatMap(s=>{if(r.isSpreadAssignment(s)){const n=Je(s.getExpression());return n===void 0?[]:Yn(n,t)}return r.isPropertyAssignment(s)||r.isShorthandPropertyAssignment(s)?[S(s)]:[]})}finally{t.delete(e)}},ic=e=>e.flatMap(t=>Yn(t,new Set)),rc=new Set(["check","length","max"]),It=e=>{let t=e;for(;;){const s=t.getParent();if(!s||!r.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;const n=s.getParent();if(!n||!r.isCallExpression(n)||n.getExpression()!==s)return!1;if(rc.has(s.getName()))return!0;t=n}},Ct=e=>_r(e)||e==="@lunora/values",oc=e=>{const t=new Set(["v"]);for(const s of Rr(e,"v",Ct))t.add(s);for(const s of e.getImportDeclarations()){const n=s.getNamespaceImport();n&&Ct(s.getModuleSpecifierValue())&&t.add(`${n.getText()}.v`)}return t},ac=(e,t)=>{const s=new Map;for(const n of e.getVariableStatements())for(const i of n.getDeclarations()){const o=i.getNameNode(),a=i.getInitializer();if(!(!r.isObjectBindingPattern(o)||!a||!t.has(a.getText())))for(const c of o.getElements())c.getDotDotDotToken()||s.set(c.getName(),c.getPropertyNameNode()?.getText()??c.getName())}return s},cc=e=>(e.getSymbol()?.getDeclarations()??[]).some(t=>!t.getSourceFile().isDeclarationFile()&&!r.isImportSpecifier(t)&&!r.isNamespaceImport(t)&&!r.isImportClause(t)),lc=e=>(e.getSymbol()?.getDeclarations()??[]).some(t=>r.isNamespaceImport(t)&&Ct(t.getFirstAncestorByKindOrThrow(d.ImportDeclaration).getModuleSpecifierValue())),Yt=(e,t)=>{if(!r.isCallExpression(e))return;const s=e.getExpression();if(r.isPropertyAccessExpression(s)){const n=s.getExpression();if(!t.namespaces.has(n.getText()))return;if(r.isIdentifier(n))return cc(n)?void 0:s.getName();const i=r.isPropertyAccessExpression(n)?n.getExpression():void 0;return r.isIdentifier(i)&&lc(i)?s.getName():void 0}if(r.isIdentifier(s))return t.destructured.get(s.getText())},dc=(e,t)=>{if(!r.isIdentifier(e))return;const s=e.getText(),n=t.getVariableDeclaration(s)?.getInitializer();return n&&(r.isArrowFunction(n)||r.isFunctionExpression(n))?n:t.getFunction(s)},uc=e=>{let t=e.getParent();for(;t&&!r.isFunctionLikeDeclaration(t);)t=t.getParent();return t},fc=e=>r.isReturnStatement(e)?e.getExpression():void 0,gc=e=>r.isArrowFunction(e)&&!r.isBlock(e.getBody())?[e.getBody()]:e.getDescendantsOfKind(d.ReturnStatement).filter(t=>uc(t)?.compilerNode===e.compilerNode).flatMap(t=>{const s=fc(t);return s?[s]:[]}),Qn=(e,t)=>{if(Yt(e,t)!==void 0)return e;if(r.isCallExpression(e)||r.isPropertyAccessExpression(e))return Qn(e.getExpression(),t)},pc=(e,t)=>{const s=dc(e.getExpression(),e.getSourceFile());if(!s)return[];const n=It(e),i=new Set(gc(s).map(o=>Qn(o,t)).filter(o=>o!==void 0));return[s,...s.getDescendants()].flatMap(o=>{const a=Yt(o,t);return a===void 0?[]:[{bounded:It(o)||n&&i.has(o),factory:a}]})},mc=(e,t)=>[e,...e.getDescendants()].flatMap(s=>{const n=Yt(s,t),i=n===void 0?[]:[{bounded:It(s),factory:n}];return r.isCallExpression(s)?[...i,...pc(s,t)]:i}),hc=(e,t)=>{const s=[],n=[];for(const i of e)for(const o of i.getProperties()){if(!r.isPropertyAssignment(o))continue;const a=o.getInitializer();if(!a)continue;const c=mc(a,t),l=S(o);c.some(u=>u.factory==="any")?s.push(l):c.some(u=>u.factory==="string"&&!u.bounded)&&n.push(l)}return{anyArgs:s,unboundedStringArgs:n}},vc=(e,t,s)=>{const n=e.getInitializer();if(!n||!r.isCallExpression(n))return;const i=ee(n);if(i?.visibility!=="public")return;const{objects:o}=Gt(n,i.receiver),{anyArgs:a,unboundedStringArgs:c}=hc(o,s);if(!(a.length===0&&c.length===0))return{anyArgs:a,exportName:j(e)??e.getName(),file:t,line:n.getStartLineNumber(),unboundedStringArgs:c}},Ec=(e,t)=>{const s=[],n=oc(e),i={destructured:ac(e,n),namespaces:n};for(const o of Y(e)){const a=vc(o,t,i);a&&s.push(a)}return s},xc=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ec(i,w(t,n)))}return s},mt=e=>e?.getKind()===d.TrueKeyword,Sc=e=>e?.getKind()===d.FalseKeyword,Ac=e=>e!==void 0&&r.isNumericLiteral(e)&&e.getLiteralValue()===0,yc=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),bc=e=>!e||!r.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>r.isCallExpression(t)&&P(t.getExpression())==="scim"),Nc=e=>e!==void 0&&r.isCallExpression(e)&&yc.has(P(e.getExpression())??""),Pc=e=>!e||!r.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>r.isStringLiteral(t)&&t.getLiteralText()==="*"),wc=e=>{const t=F(e,"advanced"),s=F(e,"emailAndPassword"),n=F(e,"session");return{analyzable:!0,disableCsrfCheck:mt(F(t,"disableCSRFCheck")),emailPasswordEnabled:mt(F(s,"enabled")),requireEmailVerification:mt(F(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:bc(F(e,"plugins"))&&Nc(F(e,"database")),secureCookiesDisabled:Sc(F(t,"useSecureCookies")),sessionFreshAgeZero:Ac(F(n,"freshAge")),trustedOriginsWildcard:Pc(F(e,"trustedOrigins"))}},Ic=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Cc=(e,t)=>{if(P(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&r.isObjectLiteralExpression(s)&&s.getProperties().some(o=>r.isSpreadAssignment(o)),i=s!==void 0&&r.isObjectLiteralExpression(s)&&!n?wc(s):Ic();return{scope:x(e),file:t,line:e.getStartLineNumber(),...i}},Tc=(e,t)=>Er(e,t,Cc),Oc=(e,t)=>{if(!r.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return Rn(e.getExpression(),t.matchReceiver)?s:void 0},kc=(e,t,s)=>{const n=Oc(e.getExpression(),s);if(n===void 0)return;const i=e.getArguments()[s.argIndex];if(!(!i||!q(i)||ce(i))&&!(s.requireUnmodifiedReach===!0&&!_a(i)))return{scope:x(e),file:t,line:e.getStartLineNumber(),method:n}},Ze=(e,t,s)=>C(e,t,(n,i)=>kc(n,i,s)),Rc=new Set(["content","pdf","scrape","screenshot"]),Fc=(e,t)=>Ze(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Rc}),Lc=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Dc=new Set(["RateLimiter"]),Mc=new Set(["extend"]),Ls="lunora",_c=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],Xn=e=>{const t=[],s=[];let n=!1;for(const i of e.getProperties()){if(r.isSpreadAssignment(i)){n=!0;continue}if(r.isPropertyAssignment(i)){const o=S(i);t.push(o),i.getInitializer()?.getKind()===d.TrueKeyword&&s.push(o);continue}(r.isShorthandPropertyAssignment(i)||r.isMethodDeclaration(i))&&t.push(S(i))}return{analyzable:!n,presentKeys:t,trueKeys:s}},Tt=e=>e&&r.isObjectLiteralExpression(e)?Xn(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Kc=e=>{const t=e&&(r.isArrowFunction(e)||r.isFunctionExpression(e))?e:void 0,s=t&&In(t.getBody());return s?Xn(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},zc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=P(n.getExpression());i!==void 0&&(Lc.has(i)?s.push({callee:i,file:t,line:n.getStartLineNumber(),...Tt(n.getArguments()[0])}):Mc.has(i)&&s.push({callee:i,file:t,line:n.getStartLineNumber(),...Kc(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(d.NewExpression)){const i=P(n.getExpression());i===void 0||!Dc.has(i)||s.push({callee:i,file:t,line:n.getStartLineNumber(),...Tt(n.getArguments()[0])})}return s},$c=(e,t)=>{for(const s of _c){const n=E(t,s);if(!M(n))continue;const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=[];for(const a of i.getDescendantsOfKind(d.CallExpression))P(a.getExpression())===Ls&&o.push({callee:Ls,file:s,line:a.getStartLineNumber(),...Tt(a.getArguments()[0])});return o}return[]},Bc=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of He(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);s.push(...zc(o,n))}return s.push(...$c(e,zt(t))),s},Ds="ctx.containers.",Vc=e=>{if(!e.startsWith(Ds))return!1;const t=e.slice(Ds.length);return t.length>0&&!t.includes(".")},Uc=(e,t)=>Ze(e,t,{argIndex:0,matchReceiver:Vc,methods:new Set(["get"])}),Wc=new Set(["allow","deny","setAllowed"]),qc=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return!1;const s=V(t,"enableInternet");return s!==void 0&&r.isPropertyAssignment(s)&&r.isTrueLiteral(s.getInitializerOrThrow())},jc=(e,t)=>{const s=e.getExpression();if(!(!r.isPropertyAccessExpression(s)||s.getName()!=="start"||!qc(e)))return{detail:"enableInternet: true",scope:x(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},Hc=(e,t)=>{const s=e.getExpression();if(!r.isPropertyAccessExpression(s)||!Wc.has(s.getName()))return;const n=s.getExpression();if(!(!r.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),scope:x(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},Gc=(e,t)=>jc(e,t)??Hc(e,t),Yc=(e,t)=>C(e,t,Gc),Qc=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="count")return;const s=t.getExpression();if(z(s)){const n=e.getArguments()[0];return n&&r.isStringLiteral(n)?n.getLiteralText():""}return r.isPropertyAccessExpression(s)&&z(s.getExpression())?s.getName():void 0},Xc=e=>{const t=e.getExpression(),s=r.isPropertyAccessExpression(t)?t.getExpression():void 0;return e.getArguments()[s!==void 0&&z(s)?1:0]},Jc=new Set(["baseWhere","relationBaseWhere","restrictsCounts","where"]),Zc=e=>{if(e===void 0||!r.isObjectLiteralExpression(e))return;const t=[];for(const n of e.getProperties()){if(!r.isPropertyAssignment(n)&&!r.isShorthandPropertyAssignment(n))return;t.push(n.getName())}return t.length>0&&t.every(n=>Jc.has(n))||t.some(n=>n==="AND"||n==="OR"||n==="NOT")?void 0:t},el=(e,t,s)=>{const n=new Map(s.map(i=>[i.name,i.aggregateIndexed===!0]));return C(e,t,(i,o)=>{const a=Qc(i);if(a===void 0)return;const c=Zc(Xc(i));return{file:o,indexed:n.get(a)!==!1,...c===void 0?{}:{filterFields:c},line:i.getStartLineNumber(),scope:x(i),table:a}})},tl=new Set(["defineExportSink","r2Sink","webhookExportSink"]),sl=e=>{const t=e.getExpression();if(!r.isIdentifier(t))return;const s=t.getText();return tl.has(s)?s:void 0},nl=e=>{const t=[],s=[];for(const n of e.getProperties()){if(r.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(r.isPropertyAssignment(n)){const i=S(n);t.push(i);const o=n.getInitializer();o&&r.isStringLiteral(o)&&o.getLiteralText()===""&&s.push(i);continue}(r.isShorthandPropertyAssignment(n)||r.isMethodDeclaration(n)||r.isGetAccessorDeclaration(n))&&t.push(S(n))}return{analyzable:!0,emptyKeys:s,presentKeys:t}},il=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of He(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);for(const a of o.getDescendantsOfKind(d.CallExpression)){const c=sl(a);if(c===void 0)continue;const l=a.getArguments()[0],u=l&&r.isObjectLiteralExpression(l)?nl(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:u.analyzable,emptyKeys:u.emptyKeys,factory:c,file:n,line:a.getStartLineNumber(),presentKeys:u.presentKeys})}}return s},rl=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),ol=new Set(["dbRateLimit","rateLimit"]),al=e=>{const t=Tn(e);if(!t)return!1;const s=V(t,"failOpen");return s!==void 0&&r.isPropertyAssignment(s)&&s.getInitializer()?.getKind()===d.TrueKeyword},cl=(e,t)=>{const s=P(e.getExpression());if(s===void 0)return;const n=rl.get(s);if(n!==void 0)return{callee:s,scope:x(e),failOpen:al(e.getArguments()[n]),file:t,limitName:ol.has(s)?Cn(e):"",line:e.getStartLineNumber()}},ll=(e,t)=>C(e,t,cl),dl=e=>{const t=e.getInitializer();if(!t||!r.isCallExpression(t))return;const s=ee(t);if(s?.kind!=="query")return;const n=xr(t,s.receiver);return n?{exportName:j(e)??e.getName(),handler:n}:void 0},Ms=e=>{const t=e.getParent();return t&&r.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},ul=e=>{const t=Ms(e);if(!t)return"ctx.flags";if(t.getName()==="details"){const s=Ms(t);return s?`ctx.flags.details.${s.getName()}`:"ctx.flags.details"}return`ctx.flags.${t.getName()}`},fl=(e,t)=>{const s=[];for(const n of Qe(e.handler,"flags"))s.push({callee:ul(n),exportName:e.exportName,file:t,line:n.getStartLineNumber()});return s},gl=(e,t)=>{const s=[];for(const n of Y(e)){const i=dl(n);i&&s.push(...fl(i,t))}return s},pl=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...gl(i,w(t,n)))}return s},ml=e=>!r.isPropertyAccessExpression(e)||e.getName()!=="boolean"?!1:H(e.getExpression(),["flags"]),hl=e=>{if(e?.getKind()===d.TrueKeyword)return!0;if(e?.getKind()===d.FalseKeyword)return!1},vl=(e,t)=>{if(!ml(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(r.isStringLiteral(s)||r.isNoSubstitutionTemplateLiteral(s)))return;const i=s.getLiteralValue(),o=hl(n);if(!(i.length===0||o===void 0))return{defaultValue:o,scope:x(e),file:t,key:i,line:e.getStartLineNumber()}},El=(e,t)=>C(e,t,vl),xl=e=>{const t=e.getExpression();return r.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Sl=e=>{const t=e.getArguments()[0];return t&&r.isStringLiteral(t)?t.getLiteralText():""},Al=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=w(t,n);for(const a of i.getDescendantsOfKind(d.CallExpression))xl(a)&&s.push({file:o,indexName:Sl(a),line:a.getStartLineNumber()})}return s},be=e=>e!==void 0&&(r.isArrowFunction(e)||r.isFunctionExpression(e))?e:void 0,Jn=e=>{const t=e.getArguments()[0],s=be(t);if(s!==void 0)return s;if(t===void 0||!r.isObjectLiteralExpression(t))return;const n=V(t,"handler");return n!==void 0&&r.isPropertyAssignment(n)?be(n.getInitializer()):void 0},yl=new Set(["delete","get","head","options","patch","post","put"]),bl=new Set(["handler","stream"]),Nl=new Set(["runAction","runMutation"]),Pl=new Set(["delete","insert","insertManyUnsafe","patch","patchIf","replace"]),Ne=(e,t)=>e!==void 0&&r.isIdentifier(e)&&e.getText()===t,Zn=(e,t)=>{if(!(e===void 0||!r.isObjectBindingPattern(e))){for(const s of e.getElements())if(ae(s)===t){const i=s.getNameNode();return r.isIdentifier(i)?i.getText():void 0}}},_s=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?r.isIdentifier(s)?s.getText():void 0:Zn(s,"ctx")},Ks=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&r.isIdentifier(s)?s.getText():void 0:Zn(s,"request")},zs=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(d.CallExpression);r.isCallExpression(s)&&n.unshift(s);for(const i of n){const o=i.getExpression();if(!r.isPropertyAccessExpression(o))continue;const a=o.getName(),c=o.getExpression();if(Nl.has(a)&&Ne(c,t))return a;if(Pl.has(a)&&r.isPropertyAccessExpression(c)&&c.getName()==="db"&&Ne(c.getExpression(),t))return`db.${a}`}},$s=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(d.PropertyAccessExpression))if(n.getName()==="auth"&&Ne(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(d.VariableDeclaration)){const i=n.getNameNode();if(!(!r.isObjectBindingPattern(i)||!Ne(n.getInitializer(),t))){for(const o of i.getElements())if(ae(o)==="auth")return!0}}return!1},wl=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,Il=(e,t)=>{const s=e.getExpression();if(!r.isPropertyAccessExpression(s)||s.getName()!=="get"&&s.getName()!=="has")return!1;const n=s.getExpression();return r.isPropertyAccessExpression(n)&&n.getName()==="headers"&&Ne(n.getExpression(),t)},Cl=e=>[...r.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(d.StringLiteral).map(t=>t.getLiteralText())],ei=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:Cl(s)},Tl=(e,t)=>{const s=e.getText();for(let n=e.getParent();n!==void 0;n=n.getParent()){if(!r.isArrowFunction(n)&&!r.isFunctionExpression(n)||!n.getParameters().some(c=>c.getName()===s))continue;const i=n.getParent();if(!r.isCallExpression(i))return[];const o=i.getExpression();if(!r.isPropertyAccessExpression(o))return[];const a=o.getExpression();return r.isIdentifier(a)?ei(t,a.getText()):[]}return[]},Ol=e=>{const t=e.getArguments()[0];if(t===void 0)return[];if(r.isStringLiteral(t))return[t.getLiteralText()];if(!r.isIdentifier(t))return[];const s=e.getSourceFile(),n=ei(s,t.getText());return n.length>0?n:Tl(t,s)},Bs=(e,t)=>{if(t===void 0)return!1;const s=e.getBody(),n=s.getDescendantsOfKind(d.CallExpression);return r.isCallExpression(s)&&n.unshift(s),n.some(i=>Il(i,t)&&Ol(i).some(o=>wl.test(o)))},kl=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!bl.has(t.getName()))return;let s=t.getExpression();for(;r.isCallExpression(s);){const n=s.getExpression();if(!r.isPropertyAccessExpression(n))return;const i=n.getName();if(yl.has(i)){const o=n.getExpression();return r.isIdentifier(o)&&o.getText()==="httpRoute"?i.toUpperCase():void 0}s=n.getExpression()}},Rl=(e,t)=>{const s=e.getExpression();if(r.isIdentifier(s)&&s.getText()==="httpAction"){const c=be(e.getArguments()[0]),l=c&&_s(c,!0);if(!c||l===void 0||Bs(c,Ks(c,!0)))return;const u=zs(c,l);return u===void 0?void 0:{scope:x(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:$s(c,l),sideEffect:u}}const n=kl(e);if(n===void 0)return;const i=be(e.getArguments()[0]),o=i&&_s(i,!1);if(!i||o===void 0||Bs(i,Ks(i,!1)))return;const a=zs(i,o);return a===void 0?void 0:{scope:x(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:$s(i,o),sideEffect:a}},Fl=(e,t)=>C(e,t,Rl),Ll=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),Dl=new Set(["append","set"]),ti=e=>e!==void 0&&(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",Vs=(e,t)=>(r.isCallExpression(e)?[e,...e.getDescendantsOfKind(d.CallExpression)]:e.getDescendantsOfKind(d.CallExpression)).some(n=>Ll.has(P(n.getExpression())??"")&&Le(n,t)),Ml=(e,t)=>{if(Vs(e,t))return!0;const s=G(e);return s!==void 0&&Vs(s,t)},Ot=(e,t)=>Ka(e,t)&&!Ml(e,t),_l=e=>{if(r.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=G(e);return t!==void 0&&r.isNewExpression(t)&&P(t.getExpression())==="Headers"},Be=e=>{if(e===void 0)return;if(r.isObjectLiteralExpression(e))return e;const t=G(e);return t!==void 0&&r.isObjectLiteralExpression(t)?t:void 0},Qt=(e,t,s)=>{for(const n of e.getProperties())if(r.isPropertyAssignment(n)){const i=n.getInitializer();i!==void 0&&Ot(i,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:ti(n.getNameNode()),line:i.getStartLineNumber(),via:t})}else if(r.isShorthandPropertyAssignment(n)){const i=n.getNameNode();Ot(i,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:S(n),line:i.getStartLineNumber(),via:t})}else if(r.isSpreadAssignment(n)){const i=Be(n.getExpression());i!==void 0&&Qt(i,t,s)}},si=(e,t)=>{const s=Be(e);if(s===void 0)return;const n=V(s,"headers");if(n===void 0||!r.isPropertyAssignment(n))return;const i=Be(n.getInitializer());i!==void 0&&Qt(i,"response-init",t)},Kl=(e,t)=>{const s=P(e.getExpression());if(s==="Response")si(e.getArguments()[1],t);else if(s==="Headers"){const n=Be(e.getArguments()[0]);n!==void 0&&Qt(n,"headers-ctor",t)}},zl=(e,t)=>{const s=e.getExpression();if(!r.isPropertyAccessExpression(s))return;const n=s.getName(),i=s.getExpression();if(n==="json"&&r.isIdentifier(i)&&i.getText()==="Response"){si(e.getArguments()[1],t);return}if(Dl.has(n)&&_l(i)){const o=e.getArguments()[1];o!==void 0&&Ot(o,t.requestName)&&t.rows.push({scope:t.scope,file:t.relativePath,headerName:ti(e.getArguments()[0]),line:o.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},$l=(e,t)=>{for(const s of e.getDescendantsOfKind(d.NewExpression))Kl(s,t);for(const s of e.getDescendantsOfKind(d.CallExpression))zl(s,t)},Bl=(e,t)=>{const s=e.getExpression();if(!r.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=be(e.getArguments()[0]);if(n===void 0)return[];const i=n.getParameters()[1];if(i===void 0)return[];const o=i.getNameNode();if(!r.isIdentifier(o))return[];const a=[];return $l(n,{scope:x(e),relativePath:t,requestName:o.getText(),rows:a}),a},Vl=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression))s.push(...Bl(n,t));return s},Ul=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Vl(i,w(t,n)))}return s},ni="identity.ts",Wl=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(r.isImportSpecifier(s))return Xe(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},ql=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!r.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(d.ImportDeclaration);return n!==void 0&&Xe(n.getModuleSpecifierValue())}return!1},jl=e=>{if(r.isIdentifier(e))return Wl(e);if(r.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&r.isIdentifier(t)&&ql(t)}return!1},Hl=e=>{const t=[];for(const s of e.getVariableDeclarations()){const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!jl(n.getExpression()))continue;const o=s.getNameNode();if(!r.isIdentifier(o)){if(s.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw le(o,"defineIdentity exports must be plain named exports (no destructuring)")}const a=Vt(s,"member");a!==void 0&&t.push({exportName:a})}return t},Gl=(e,t)=>{const s=E(t,ni);if(!M(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=Hl(n);if(i.length!==0){if(i.length>1)throw le(n,`lunora/identity.ts declares ${i.length.toString()} defineIdentity() contracts (${i.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Yl=new Set(["auth","context.auth"]),Ql="userId",Xl=e=>{const t=new Set;for(const s of e.getProperties()){if(r.isSpreadAssignment(s))return;(r.isPropertyAssignment(s)||r.isShorthandPropertyAssignment(s)||r.isMethodDeclaration(s))&&t.add(S(s))}return t},Jl=(e,t)=>{const s=E(t,ni);if(!M(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const i of n.getDescendantsOfKind(d.CallExpression)){if(P(i.getExpression())!=="defineIdentity")continue;const[o]=i.getArguments();return o&&r.isObjectLiteralExpression(o)?Xl(o):void 0}},Us=e=>{if(e===void 0||!r.isPropertyAccessExpression(e)||e.getName()!=="identity")return;const t=e.getExpression();return Yl.has(t.getText())||H(t,["auth"])?e:void 0},Zl=e=>{if(r.isPropertyAccessExpression(e)&&Us(e.getExpression())!==void 0)return e.getName();if(r.isElementAccessExpression(e)&&Us(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&r.isStringLiteral(t)?t.getLiteralValue():void 0}},Ws=(e,t,s)=>{const n=Zl(e);return n===void 0?void 0:{declared:n===Ql||s.has(n),file:t,key:n,line:e.getStartLineNumber(),scope:x(e)}},ed=(e,t)=>{const s=Jl(e,t);return s===void 0?[]:[...ne(e,t,d.PropertyAccessExpression,(n,i)=>Ws(n,i,s)),...ne(e,t,d.ElementAccessExpression,(n,i)=>Ws(n,i,s))]},td=(e,t)=>{if(P(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=F(s,"key");if(!(!n||!q(n)||ce(n)))return{scope:x(e),file:t,line:e.getStartLineNumber()}},sd=(e,t)=>C(e,t,td),nd=new Set(["delete","get","getRaw","getWithMetadata","put"]),id=(e,t,s=[])=>{const n=Ze(e,t,{argIndex:0,matchReceiver:i=>i==="ctx.kv"||i.startsWith("ctx.kv."),methods:nd});return Ut(n,s)},rd=new Set(["queue","send"]),qs=new Set(["bcc","cc","to"]),od=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();if(!rd.has(t))return;const s=e.getExpression();return H(s,["mail"])||H(s,["email"])?t:void 0},ad=e=>r.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(r.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return qs.has(S(t))&&q(n)&&!ce(n)}if(!r.isPropertyAssignment(t)||!qs.has(S(t)))return!1;const s=t.getInitializer();return s!==void 0&&q(s)&&!ce(s)}):!1,cd=(e,t)=>{const s=od(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!ad(n)))return{scope:x(e),file:t,line:e.getStartLineNumber(),method:s}},ld=(e,t)=>C(e,t,cd),dd=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!r.isObjectLiteralExpression(n))return[];const i=[];for(const o of n.getProperties()){const a=$e(o);if(a===void 0||!r.isPropertyAssignment(o))continue;const c=o.getInitializer();if(!(!c||!r.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const u=$e(l);if(u===void 0)continue;const f=zn(l);f!=="custom"&&i.push({column:u,exportName:t,file:s,line:l.getStartLineNumber(),strategy:f,table:a})}}return i},ud=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&r.isCallExpression(s)?ee(s):void 0;return n?.receiver?qt(n.receiver).flatMap(i=>dd(i,j(e)??e.getName(),t)):[]},fd=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=w(t,n);for(const a of Y(i))s.push(...ud(a,o))}return s},gd=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return z(s)},pd=e=>{const t=e.getArguments()[0];if(t===void 0||!r.isObjectLiteralExpression(t))return;const s=V(t,"server");if(s!==void 0)return r.isPropertyAssignment(s)?s.getInitializer():s},md=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==d.CallExpression)return;const s=t;return Ur(s.getExpression())?s:void 0},hd=e=>{const t=md(e),s=t===void 0?void 0:pd(t);if(s===void 0)return[];const n=e.getNameNode(),i=r.isIdentifier(n)?j(e)??n.getText():"";return s.getDescendantsOfKind(d.CallExpression).filter(o=>gd(o)).map(o=>({exportName:i,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},vd=e=>e.getVariableDeclarations().flatMap(t=>hd(t)),Ed=(e,t)=>{const s=E(t,Vr);if(!M(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return vd(n)},xd=new Set(["delete","get","patch"]),Sd=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Ad=new Set(["auth","identity","session","user"]),yd=new Set([d.EqualsEqualsEqualsToken,d.EqualsEqualsToken,d.ExclamationEqualsEqualsToken,d.ExclamationEqualsToken]),bd=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!z(t.getExpression()))return;const s=e.getArguments()[0];return s&&r.isStringLiteral(s)?s.getLiteralText():""},Nd=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(r.isAsExpression(s)||r.isParenthesizedExpression(s)||r.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!r.isVariableDeclaration(s))return;const n=s.getNameNode();return r.isIdentifier(n)?n.getText():void 0},Pd=(e,t)=>e.getDescendantsOfKind(d.Identifier).some(s=>s.getText()===t),wd=e=>r.isThrowStatement(e)||r.isReturnStatement(e)||e.getDescendantsOfKind(d.ThrowStatement).length>0||e.getDescendantsOfKind(d.ReturnStatement).length>0,Id=(e,t)=>e.getDescendantsOfKind(d.IfStatement).some(s=>Pd(s.getExpression(),t)&&wd(s.getThenStatement())),Cd=(e,t)=>{for(const s of e.getDescendantsOfKind(d.CallExpression)){const n=s.getExpression();if(!r.isPropertyAccessExpression(n))continue;const i=n.getName();if(!xd.has(i))continue;const o=n.getExpression();if(!(z(o)||r.isPropertyAccessExpression(o)&&z(o.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&r.isIdentifier(c)&&c.getText()===t)return i}},Td=e=>e.getDescendantsOfKind(d.CallExpression).some(t=>t.getArguments().some(s=>Wt(Ge(s))!==void 0)),Od=e=>e.getDescendantsOfKind(d.BinaryExpression).some(t=>yd.has(t.getOperatorToken().getKind())?r.isPropertyAccessExpression(t.getLeft())||r.isPropertyAccessExpression(t.getRight()):!1),kd=e=>{for(const t of e.getDescendantsOfKind(d.Identifier))if(Sd.has(t.getText()))return!0;return[...Ad].some(t=>Qe(e,t).length>0)?!0:Td(e)||Od(e)},Rd=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!r.isCallExpression(s))return[];const n=ee(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const i=Jn(s);if(i===void 0)return[];const o=n.receiver!==void 0&&Dn(n.receiver,"use","rls"),a=kd(i),c=new Set,l=[];for(const u of i.getDescendantsOfKind(d.CallExpression)){const f=bd(u);if(f===void 0)continue;const g=Nd(u);if(g===void 0||c.has(g)||!Id(i,g))continue;const p=Cd(i,g);p!==void 0&&(c.add(g),l.push({exportName:j(e)??e.getName(),file:t,line:u.getStartLineNumber(),mentionsOwnership:a,sinkMethod:p,table:f,usesRls:o,visibility:n.visibility}))}return l},Fd=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=w(t,n);for(const a of Y(i))s.push(...Rd(a,o))}return s},ii=(e,t)=>{const s=r.isIdentifier(e)&&t!==void 0?L(e):void 0;return s===void 0||t===void 0?!1:s.compilerNode===t.compilerNode?r.isIdentifier(t.getNameNode()):r.isBindingElement(s)&&s.getFirstAncestorByKind(d.Parameter)?.compilerNode===t.compilerNode},Ld=e=>{const t=I(e),s=t.getParent();return(r.isPropertyAccessExpression(s)||r.isElementAccessExpression(s))&&s.getExpression()===t&&!Ye(s)},Dd=e=>{const t=I(e).getParent();return r.isVariableDeclaration(t)&&r.isObjectBindingPattern(t.getNameNode())},Md=e=>{const s=I(e).getParent();if(r.isSpreadAssignment(s)||r.isSpreadElement(s)){const n=s.getParent();return(r.isObjectLiteralExpression(n)||r.isArrayLiteralExpression(n))&&!Ye(n)}return r.isTemplateSpan(s)&&!r.isTaggedTemplateExpression(s.getParent().getParent())},Ve=e=>{const t=L(e);return t===void 0||Nr(t.getSourceFile())},kt=(e,t)=>{const s=I(e),n=s.getParent();if(!r.isCallExpression(n))return!1;const i=n.getArguments().indexOf(s),o=h(n.getExpression());if(i===-1||o===void 0)return!1;if(r.isIdentifier(o))return o.getText()==="structuredClone"&&Ve(o);if(ii(Ge(o),t))return!(r.isPropertyAccessExpression(o)&&Fn.has(o.getName()))||r.isExpressionStatement(I(r.isAwaitExpression(n.getParent())?n.getParentOrThrow():n).getParent());if(!r.isPropertyAccessExpression(o))return!1;const a=o.getExpression();if(!r.isIdentifier(a)||!Ve(a))return!1;const c=a.getText(),l=o.getName();switch(c){case"console":return!0;case"JSON":return l==="stringify";case"Object":return["entries","freeze","isFrozen","keys","values"].includes(l)||l==="assign"&&i>0;default:return!1}},De={kind:"opaque"},_d={kind:"unreached"},Kd=e=>{const t=e.getSymbol()?.getDeclarations()??[],s=t.filter(o=>r.isFunctionDeclaration(o)&&o.hasBody()),[n]=s;return t.every(o=>r.isFunctionDeclaration(o)&&o.getSourceFile()===e.getSourceFile())&&s.length===1&&r.isFunctionDeclaration(n)?n:void 0},Rt=e=>{const t=h(e);if(r.isArrowFunction(t)||r.isFunctionExpression(t))return t;const s=r.isIdentifier(t)?L(t):void 0;if(s?.getSourceFile()!==e.getSourceFile())return;if(r.isFunctionDeclaration(s)){const i=Kd(s);return i===void 0||Bt(i)?void 0:i}const n=ie(s)?h(s.getInitializer()):void 0;return r.isArrowFunction(n)||r.isFunctionExpression(n)?n:void 0},ri=(e,t,s)=>{const n=t.getArguments(),i=n.indexOf(s),o=i===-1||n.slice(0,i+1).some(l=>r.isSpreadElement(l))||e.getDescendantsOfKind(d.Identifier).some(l=>l.getText()==="arguments"),a=e.getParameters(),c=a[i];return o?De:c===void 0?a.some(l=>l.isRestParameter())?De:_d:c.isRestParameter()?De:{kind:"parameter",parameter:c}},zd=e=>{const t=I(e),s=t.getParent();if(!r.isCallExpression(s)||s.getExpression()===t)return;const n=Rt(s.getExpression());return n===void 0?De:ri(n,s,t)},$d=new Set(["__defineGetter__","__defineSetter__","__proto__"]),Bd=e=>r.isForInStatement(e)?e.getExpression():r.isConditionalExpression(e)?e.getCondition():r.isElementAccessExpression(e)?e.getArgumentExpression():void 0,oi=e=>{const t=I(e),s=t.getParent();if(r.isIfStatement(s)||r.isWhileStatement(s)||r.isDoStatement(s)||r.isSwitchStatement(s)||r.isCaseClause(s)||r.isTypeOfExpression(s)||r.isVoidExpression(s)||r.isComputedPropertyName(s))return!0;if(r.isTemplateSpan(s))return!r.isTaggedTemplateExpression(s.getParent().getParent());const n=Bd(s);if(n!==void 0)return y(n,t);if(r.isPrefixUnaryExpression(s))return s.getOperatorToken()!==d.PlusPlusToken&&s.getOperatorToken()!==d.MinusMinusToken;if(!r.isBinaryExpression(s))return!1;const i=s.getOperatorToken().getKind(),o=i>=d.FirstAssignment&&i<=d.LastAssignment,a=i===d.QuestionQuestionToken||i===d.BarBarToken||i===d.AmpersandAmpersandToken;return!o&&!a},Vd=4,ai=(e,t,s=0)=>{if(br(e))return!0;if(Ld(e)){const i=I(e).getParent(),o=r.isElementAccessExpression(i)?i.getArgumentExpression():void 0,a=r.isStringLiteral(o)?o.getLiteralValue():void 0,c=r.isPropertyAccessExpression(i)?i.getName():a;return c===void 0||!$d.has(c)}if(Dd(e)||Md(e)||oi(e)||kt(e,t))return!0;const n=zd(e);return n?.kind==="unreached"||n?.kind==="parameter"&&Ud(n.parameter,s+1)},js=new WeakMap,Ud=(e,t=0)=>{const s=e.getNameNode();if(!r.isIdentifier(s))return!0;const n=js.get(e.compilerNode);if(n!==void 0)return n;if(t>Vd)return!1;const o=(s.getSymbol()?.getDeclarations().length??0)===1&&e.getParentOrThrow().getDescendantsOfKind(d.Identifier).every(a=>a===s||a.getText()!==s.getText()||L(a)?.compilerNode!==e.compilerNode||ai(a,void 0,t));return(o||t===0)&&js.set(e.compilerNode,o),o},Hs=new WeakMap,Wd=(e,t)=>{const s=r.isFunctionExpression(e)?e.getNameNode():void 0;if(!r.isArrowFunction(e)&&e.getFirstDescendantByKind(d.ThisKeyword)!==void 0)return!0;const n=new Set([t.getName(),...s===void 0?[]:[s.getText()]]);return e.getDescendantsOfKind(d.Identifier).some(i=>{if(i===s||!n.has(i.getText()))return!1;const o=L(i)?.compilerNode;return o!==void 0&&(o===t.compilerNode||s!==void 0&&o===e.compilerNode)})},qd=(e,t,s)=>{const{context:n,impl:i}=e,o=Hs.get(i.compilerNode);if(o!==void 0)return o;const a=t.getNameNode(),c=r.isIdentifier(a)?[a]:a.getDescendantsOfKind(d.BindingElement).flatMap(g=>{const p=g.getNameNode();return r.isIdentifier(p)?[p]:[]}),l=new Map(c.map(g=>[g.getText(),g.getParentOrThrow().compilerNode])),u=g=>r.isIdentifier(a)?ai(g,n):!Ye(g),f=!Wd(i,s)&&c.every(g=>(g.getSymbol()?.getDeclarations().length??0)===1)&&i.getDescendantsOfKind(d.Identifier).every(g=>{const p=g.getText();if(p==="arguments")return!1;const v=l.get(p);return v===void 0||c.includes(g)||L(g)?.compilerNode!==v?!0:u(g)});return Hs.set(i.compilerNode,f),f},Gs=new WeakMap,jd=e=>{let t=Gs.get(e.compilerNode);return t===void 0&&(t=new Map(e.getVariableDeclarations().flatMap(s=>{const n=Wr(s);return n===void 0?[]:[[n.compilerNode,s]]})),Gs.set(e.compilerNode,t)),t},Hd=e=>{const t=jd(e.getSourceFile()),s=e.getAncestors().find(l=>t.has(l.compilerNode)),n=s===void 0?void 0:t.get(s.compilerNode);if(s===void 0||n===void 0)return;const[i,o]=s.getParameters(),a=o===void 0||o.isRestParameter()?void 0:o,c={context:i,impl:s,mutatorName:j(n)??n.getName()};return a!==void 0&&qd(c,a,n)?{...c,parameter:a,pristine:!0}:{...c,parameter:a,pristine:!1}},ht="args",Ee=e=>{const t=$t(e);if(t!==void 0){const c=h(t.object);return r.isIdentifier(c)&&c.getText()===ht?t.member:void 0}if(!r.isIdentifier(e))return;const s=L(e);if(!r.isBindingElement(s)||s.getDotDotDotToken()!==void 0)return;const n=s.getParent();if(!r.isObjectBindingPattern(n))return;const i=n.getParent(),o=ie(i)?h(i.getInitializer()):void 0;return r.isBindingElement(i)&&ae(i)===ht||r.isIdentifier(o)&&o.getText()===ht?ae(s):void 0},Gd=new Set(["auth","identity","user"]),Ft=e=>{const t=i=>{const o=Wt(i);return o!==void 0&&o.length>0&&Gd.has(o[0]??"")},s=h(e)??e;if(t(s))return!0;const n=G(s);return n!==void 0&&t(n)},ci=(e,t=2)=>{const s=new Set;for(const n of[e,...e.getDescendants()]){const i=Ee(n);i!==void 0&&s.add(i);const o=t>0&&r.isIdentifier(n)?G(n):void 0;if(o!==void 0)for(const a of ci(o,t-1))s.add(a)}return s},Me=e=>{const t=h(e)??e;if(!r.isBinaryExpression(t))return[];const s=t.getOperatorToken().getKind(),n=t.getLeft(),i=t.getRight();if(s===d.BarBarToken)return[...Me(n),...Me(i)];if(s===d.AmpersandAmpersandToken){const l=(u,f)=>{const g=Ee(h(u)??u);return g===void 0?[]:Me(f).filter(p=>p===g)};return[...l(n,i),...l(i,n)]}if(s!==d.ExclamationEqualsEqualsToken&&s!==d.ExclamationEqualsToken)return[];const o=[],a=Ee(h(n)??n),c=Ee(h(i)??i);return a!==void 0&&Ft(i)&&o.push(a),c!==void 0&&Ft(n)&&o.push(c),o},Yd=e=>{const t=h(e)??e;if(!r.isIdentifier(t))return!1;const s=t.getSymbol(),n=s?.getAliasedSymbol()?.getValueDeclaration()??s?.getValueDeclaration();if(!r.isVariableDeclaration(n))return!1;const i=h(n.getInitializer());return r.isCallExpression(i)&&Fr(i.getExpression(),"defineIdentityGuard")},Qd=e=>{if(!Yd(e.getExpression()))return[];const t=e.getArguments();return t.flatMap((s,n)=>{const i=Ee(h(s)??s),o=t.some((a,c)=>c!==n&&Ft(a));return i!==void 0&&o?[i]:[]})},Xd=e=>{if(r.isThrowStatement(e))return!0;if(!r.isBlock(e))return!1;const t=e.getStatements().at(-1);return t!==void 0&&r.isThrowStatement(t)},Jd=e=>r.isArrowFunction(e)||r.isFunctionExpression(e)||r.isFunctionDeclaration(e)||r.isMethodDeclaration(e),Ys=(e,t)=>{for(let s=e.getParent();s!==void 0;s=s.getParent()){if(s===t||s.compilerNode===t.compilerNode)return!0;if(!(r.isBlock(s)||r.isExpressionStatement(s)||r.isAwaitExpression(s)||r.isParenthesizedExpression(s)||r.isVariableStatement(s)||r.isVariableDeclarationList(s)||r.isVariableDeclaration(s)))return!1}return!1},Zd=e=>r.isAwaitExpression(e.getParent())||e.getType().isVoid(),eu=(e,t)=>{const s=new Set;for(const n of e.getDescendantsOfKind(d.IfStatement))if(n.getEnd()<=t&&Ys(n,e)&&Xd(n.getThenStatement()))for(const i of Me(n.getExpression()))s.add(i);for(const n of e.getDescendantsOfKind(d.CallExpression))if(n.getEnd()<=t&&Zd(n)&&Ys(n,e))for(const i of Qd(n))s.add(i);return s},tu=(e,t)=>{const s=ci(t);if(s.size===0)return!1;const n=e.getFirstAncestor(Jd);if(n===void 0)return!1;const i=eu(n,e.getStart());return[...s].every(o=>i.has(o))},su=new Set(["at","concat","filter","find","findLast","flat","reverse","slice","sort","toReversed","toSorted"]),nu=new Map([["Array",new Set(["from","of"])],["Object",new Set(["entries","values"])]]),Lt=new Set(["catch","every","filter","finally","find","findIndex","findLast","findLastIndex","flatMap","forEach","map","reduce","reduceRight","some","sort","then"]),li=e=>e.getNameNode().getDescendantsOfKind(d.BindingElement).filter(t=>r.isIdentifier(t.getNameNode())),iu=e=>{const t=I(e),s=t.getParent();if(r.isVariableDeclaration(s))return y(s.getInitializer(),t)?s:void 0;const n=r.isForOfStatement(s)&&s.getExpression()===t?s.getInitializer():void 0;return r.isVariableDeclarationList(n)?n.getDeclarations()[0]:void 0},ru=e=>{const t=iu(e);return t===void 0?void 0:r.isIdentifier(t.getNameNode())?r.isForOfStatement(t.getParent().getParent())||ie(t)?[t]:void 0:li(t)},xe=e=>e.isUnion()?e.getUnionTypes().every(t=>xe(t)):e.isIntersection()?e.getIntersectionTypes().some(t=>xe(t)):!e.isAny()&&!e.isUnknown()&&!e.isObject()&&!e.isTypeParameter(),Ue=(e,t,s)=>{const n=r.isCallExpression(e)?h(e.getExpression()):void 0;return r.isPropertyAccessExpression(n)&&t.has(n.getName())&&(s===void 0||n.getExpression()===s)},_e=e=>{const t=h(e);if(!r.isArrowFunction(t)&&!r.isFunctionExpression(t))return;const s=t.getBody();return r.isBlock(s)?s.getDescendantsOfKind(d.ReturnStatement).filter(n=>n.getFirstAncestor(i=>r.isFunctionLikeDeclaration(i))===t).map(n=>n.getExpression()):[s]},ou=e=>{const t=r.isCallExpression(e)?h(e.getExpression()):void 0,s=r.isPropertyAccessExpression(t)?t.getExpression():void 0;return r.isPropertyAccessExpression(t)&&r.isIdentifier(s)&&nu.get(s.getText())?.has(t.getName())===!0&&Ve(s)},au=e=>{const t=bt(e);if(!r.isArrowFunction(t)&&!r.isFunctionExpression(t))return;const s=I(t),n=s.getParent();return r.isCallExpression(n)&&n.getArguments().includes(s)&&Ue(n,Ln)?n:void 0},cu=(e,t)=>{if(!(r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e))||e.getExpression()!==t)return;const s=I(e),n=s.getParent();return!r.isCallExpression(n)||n.getExpression()!==s?e:Ue(n,su,t)?n:void 0},lu=(e,t)=>{if(r.isAwaitExpression(e))return e;if(r.isConditionalExpression(e))return e.getCondition()===t?void 0:e;const s=r.isBinaryExpression(e)?e.getOperatorToken().getKind():void 0;return s===d.QuestionQuestionToken||s===d.BarBarToken||s===d.AmpersandAmpersandToken?e:void 0},du=(e,t)=>{if(r.isArrayLiteralExpression(e))return e;const n=r.isSpreadElement(e)||r.isSpreadAssignment(e)||r.isShorthandPropertyAssignment(e)||r.isPropertyAssignment(e)&&y(e.getInitializer(),t)?e.getParent():void 0;return r.isArrayLiteralExpression(n)||r.isObjectLiteralExpression(n)?n:void 0},Qs=e=>{const t=I(e),s=t.getParent();if(s===void 0)return;const n=r.isCallExpression(s)&&s.getArguments().includes(t)&&ou(s);return cu(s,t)??lu(s,t)??du(s,t)??(n?s:au(t))},uu=5e4,di=()=>({inProgress:new Set,verdicts:new Map});class fu{cuts=0;work=0;reset(){this.work=0}cut(){return this.cuts+=1,!0}spend(){return this.work+=1,this.work>uu&&this.cut()}memoized(t,s,n){const i=n.verdicts.get(t);if(i!==void 0)return i;if(n.inProgress.has(t))return this.cuts+=1,!1;if(this.spend())return!0;const o=this.cuts;n.inProgress.add(t);let a;try{a=s()}finally{n.inProgress.delete(t)}return this.cuts===o&&n.verdicts.set(t,a),a}}const gu=8,pu=8;class mu{budget;scope;taint;verdicts=di();constructor(t,s,n){this.scope=t,this.budget=s,this.taint=n}isCompromised(t){return this.flowHasCompromisingUse(t)&&!xe(t.getType())}flowHasCompromisingUse(t){return this.budget.memoized(t.compilerNode,()=>{const s=this.budget.cuts,n=[],i=new Set,o=(c,l)=>{i.has(c.compilerNode)||(i.add(c.compilerNode),n.push({binding:c,hops:l}))};let a=!1;o(t,0);for(const c of n)if(a=(c.binding===t?void 0:this.verdicts.verdicts.get(c.binding.compilerNode))??this.visitBinding(c,t,o),a)break;if(!a&&this.budget.cuts===s)for(const c of i)this.verdicts.verdicts.set(c,!1);return a},this.verdicts)}visitBinding({binding:t,hops:s},n,i){const o=t.getNameNode();if(!r.isIdentifier(o)){for(const l of r.isParameterDeclaration(t)?li(t):[])i(l,s);return!1}if(this.budget.spend())return!0;const a=(l,u)=>u&&s>=gu?this.budget.cut():(i(l,u?s+1:s),!1);return this.taint.referencesTo(t,o.getText()).some(l=>this.valueCompromises(I(l),!0,a,0))&&(t===n||!xe(t.getType()))}valueCompromises(t,s,n,i){let o=t;for(let p=Qs(o);p!==void 0;p=Qs(o)){if(r.isCallExpression(p)&&this.callbackCompromises(p,n))return!0;o=I(p)}const a=o.getParent(),c=o===t&&s,l=()=>!c&&xe(o.getType());if(Ye(o))return!c&&(!r.isBinaryExpression(a)||this.taint.isTaintedValue(a.getRight(),!1));const u=ru(o);if(u!==void 0)return u.some(p=>n(p,!0));const f=r.isPropertyAccessExpression(a)&&a.getExpression()===o?a.getParent():void 0;if(r.isCallExpression(f)&&f.getExpression()===a)return this.methodCallCompromises(f,n);const g=this.nestedReturningFunctionOf(o);return g!==void 0?this.resultCompromises(g,n,i)&&!l():this.positionCompromises(o,n)&&!l()}resultCompromises(t,s,n){const i=I(t).getParent();if(n>=pu)return this.budget.cut();if(r.isCallExpression(i))return i.getExpression()===I(t)?this.valueCompromises(i,!1,s,n+1):!Ue(i,Lt);const o=r.isFunctionDeclaration(t)?t:i,a=r.isFunctionDeclaration(o)||ie(o)?o.getNameNode():void 0;return o===void 0||!r.isIdentifier(a)?!0:this.taint.referencesTo(o,a.getText()).some(c=>{const l=I(c),u=l.getParent();return!r.isCallExpression(u)||u.getExpression()!==l||this.valueCompromises(u,!1,s,n+1)})}methodCallCompromises(t,s){return t.getArguments().filter(i=>_e(i)===void 0).some(i=>this.taint.isTaintedValue(i,!1))||this.callbackCompromises(t,s)}callbackCompromises(t,s){const n=Ue(t,Lt)?t.getArguments()[0]:void 0;if(n===void 0)return!1;const i=Rt(n);return i!==void 0&&this.taint.isInImpl(i)?i.getParameters().some(o=>s(o,!1)):this.taint.isTaintedValue(n,!1)}positionCompromises(t,s){const n=t.getParent();if(r.isCallExpression(n)&&n.getArguments().includes(t))return this.argumentCompromises(n,t,s);const i=r.isSpreadElement(n)?n.getParent():void 0;if(n!==void 0&&r.isCallExpression(i))return!kt(n,this.scope.context)&&this.isOpaqueCallTainted(i.getExpression(),i.getArguments(),n);if(r.isNewExpression(n))return this.isOpaqueCallTainted(n.getExpression(),n.getArguments(),t);if(r.isTemplateSpan(n)){const o=n.getParent(),a=o.getParent(),c=o.getTemplateSpans().map(l=>l.getExpression());return r.isTaggedTemplateExpression(a)&&this.isOpaqueCallTainted(a.getTag(),c,t)}return!this.isReadPosition(t)}argumentCompromises(t,s,n){if(kt(s,this.scope.context))return!1;const i=Rt(t.getExpression()),o=i===void 0?void 0:ri(i,t,s);return o?.kind==="unreached"?!1:o?.kind==="parameter"&&i!==void 0&&this.taint.isInImpl(i)?n(o.parameter,!1):this.isOpaqueCallTainted(t.getExpression(),t.getArguments(),s)}isReadPosition(t){const s=t.getParent();return s===void 0||r.isExpressionStatement(s)||r.isForStatement(s)||r.isElementAccessExpression(s)||oi(t)||y(bt(t),this.scope.impl)}isOpaqueCallTainted(t,s,n){const i=!r.isIdentifier(h(n));return this.taint.isTaintedValue(t,!1)||s.some(o=>(o!==n||i)&&this.taint.isTaintedValue(o,!1))}nestedReturningFunctionOf(t){const s=bt(t);return y(s,this.scope.impl)?void 0:s}}const hu=new Set(["at","every","filter","finally","find","findIndex","findLast","findLastIndex","forEach","order","slice","some","sort","withIndex","withSearchIndex"]),vu=e=>{const t=h(e);if(!r.isIdentifier(t))return r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t);const s=L(t),n=r.isVariableDeclaration(s)?h(s.getInitializer()):void 0;return s===void 0||r.isFunctionDeclaration(s)||r.isParameterDeclaration(s)||r.isArrowFunction(n)||r.isFunctionExpression(n)},Eu=new Set(["all","allSettled","any","race"]),Xs=e=>r.isParameterDeclaration(e)?e:r.isBindingElement(e)?e.getFirstAncestorByKind(d.Parameter):void 0,vt=8;class xu{budget=new fu;referencesByDeclaration=new Map;referencesByName=new Map;scope;verdicts=di();walk;variableDepth=0;queryDepth=0;constructor(t){this.scope=t,this.walk=new mu(t,this.budget,this);for(const s of t.impl.getDescendantsOfKind(d.Identifier)){const n=s.getText();this.referencesByName.set(n,[...this.referencesByName.get(n)??[],s])}}isTaintedValue(t,s){this.queryDepth===0&&this.budget.reset(),this.queryDepth+=1;try{return s&&this.isRootedInContext(t,vt)?!1:(r.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(i=>Pr(i)&&this.isIdentifierTainted(i))}finally{this.queryDepth-=1}}isInImpl(t){const{impl:s}=this.scope;return t!==s&&s.getPos()<=t.getPos()&&t.getEnd()<=s.getEnd()}referencesTo(t,s){let n=this.referencesByDeclaration.get(s);if(n===void 0){n=new Map;for(const i of this.referencesByName.get(s)??[]){const o=L(i)?.compilerNode;o!==void 0&&n.set(o,[...n.get(o)??[],i])}this.referencesByDeclaration.set(s,n)}return(n.get(t.compilerNode)??[]).filter(i=>i.getParent()!==t)}flowsIntoTainted(t){if([t.getInitializer(),...t.getDescendantsOfKind(d.BindingElement).map(g=>g.getInitializer())].some(g=>g!==void 0&&this.isTaintedValue(g,!1)))return!0;const n=t.getParentOrThrow(),i=r.isFunctionLikeDeclaration(n)?n.getParameters().findIndex(g=>g.compilerNode===t.compilerNode):-1,o=I(n),a=o.getParent();if(i===-1)return!0;if(r.isCallExpression(a)){if(a.getExpression()===o)return this.isCallSiteTainted(a,i,t.isRestParameter());const g=h(a.getExpression());if(!r.isPropertyAccessExpression(g)||!Lt.has(g.getName()))return!0;const p=a.getArguments().filter(v=>v!==o);return this.isTaintedValue(g.getExpression(),!0)||p.some(v=>this.isTaintedValue(v,!1))}const c=r.isVariableDeclaration(a)&&ie(a)?a:void 0,l=r.isFunctionDeclaration(n)?n:c,u=l?.getNameNode();if(l===void 0||!r.isIdentifier(u))return!0;const f=this.referencesTo(l,u.getText());return f.length===0||f.some(g=>{const p=I(g),v=p.getParent();return!r.isCallExpression(v)||v.getExpression()!==p||this.isCallSiteTainted(v,i,t.isRestParameter())})}isCallSiteTainted(t,s,n){const i=t.getArguments(),o=i.findIndex(c=>r.isSpreadElement(c)),a=c=>c===s||n&&c>s||o!==-1&&o<=s&&c>=o;return i.some((c,l)=>a(l)&&this.isTaintedValue(c,!1))}isContextRootedCombinator(t,s){const n=h(t.getExpression()),i=r.isPropertyAccessExpression(n)?n.getExpression():void 0,a=r.isPropertyAccessExpression(n)&&r.isIdentifier(i)&&i.getText()==="Promise"&&Ve(i)&&Eu.has(n.getName())?h(t.getArguments()[0]):void 0;if(r.isArrayLiteralExpression(a)){const f=a.getElements();return f.length>0&&f.every(g=>!r.isSpreadElement(g)&&this.isRootedInContext(g,s))}const c=r.isCallExpression(a)?h(a.getExpression()):void 0,l=r.isCallExpression(a)&&r.isPropertyAccessExpression(c)&&c.getName()==="map"?h(a.getArguments()[0]):void 0,u=l===void 0?void 0:_e(l);return u!==void 0&&u.length>0&&u.every(f=>f!==void 0&&this.isRootedInContext(f,s))}isIdentifierTainted(t){const s=t.getText();if(s==="arguments")return!0;const n=L(t),i=Xs(n);if(i!==void 0)return this.isSource(i);if(s==="args")return!0;if(n===void 0||!this.isInImpl(n))return!1;if(r.isFunctionDeclaration(n))return this.budget.memoized(n.compilerNode,()=>this.isTaintedValue(n,!1),this.verdicts);if(r.isBindingElement(n)&&this.walk.isCompromised(n))return!0;const o=r.isBindingElement(n)?n.getFirstAncestorByKind(d.VariableDeclaration):n;return r.isVariableDeclaration(o)&&this.isVariableTainted(o)}callChainVerdict(t,s){if(this.isContextRootedCombinator(t,s))return!0;const n=h(t.getExpression()),i=r.isPropertyAccessExpression(n)?n.getName():void 0;return i!==void 0&&Fn.has(i)?!1:i!==void 0&&Ln.has(i)?this.isCallbackResultServerScoped(t,s)?void 0:!1:t.getArguments().some(a=>_e(a)!==void 0)&&(i===void 0||!hu.has(i))?!1:void 0}isCallbackResultServerScoped(t,s){const n=(i,o=[])=>{const a=Ge(i),c=r.isIdentifier(a)?Xs(L(a)):void 0;return c!==void 0&&o.includes(c)?!0:this.isRootedInContext(i,s)||!this.isTaintedValue(i,!1)};return t.getArguments().every(i=>{const o=_e(i);if(o===void 0)return!vu(i)&&n(i);const a=h(i),c=r.isArrowFunction(a)||r.isFunctionExpression(a)?a.getParameters():[];return o.every(l=>l===void 0||n(l,c))})}isRootedInContext(t,s){const n=Sr(t,u=>this.callChainVerdict(u,s)),i=n.root;if(n.verdict!==void 0)return n.verdict;if(ii(i,this.scope.context))return!0;const o=r.isIdentifier(i)?L(i):void 0,a=r.isBindingElement(o)?o.getFirstAncestorByKind(d.VariableDeclaration):o,c=ie(a)&&this.isInImpl(a)?a.getInitializer():void 0,l=r.isBindingElement(o)?o:a;return s>0&&c!==void 0&&(r.isBindingElement(l)||r.isVariableDeclaration(l))&&!this.walk.isCompromised(l)&&this.isRootedInContext(c,s-1)}isSource(t){const{impl:s,parameter:n}=this.scope;return t.compilerNode===n?.compilerNode?!0:t.getParent()!==s&&this.isInImpl(t)&&(this.budget.memoized(t.compilerNode,()=>this.flowsIntoTainted(t),this.verdicts)||this.walk.isCompromised(t))}isVariableTainted(t){return this.budget.memoized(t.compilerNode,()=>{const s=t.getParent().getParent();if(r.isCatchClause(t.getParent())||this.walk.isCompromised(t))return!0;if(r.isForOfStatement(s)||r.isForInStatement(s))return this.isTaintedValue(s.getExpression(),!0);const n=t.getInitializer(),i=Bt(t);if(n===void 0||i)return!0;if(this.isRootedInContext(n,vt))return!1;if(this.variableDepth>=vt)return this.budget.cut();this.variableDepth+=1;try{return this.isTaintedValue(n,!1)}finally{this.variableDepth-=1}},this.verdicts)}}const Js=new WeakMap,Su=e=>{const t=Js.get(e.impl.compilerNode);if(t!==void 0)return t;const s=new xu(e);return Js.set(e.impl.compilerNode,s),s},Au=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),yu=new Set(["insert","insertManyUnsafe","patch","replace"]),bu=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();return yu.has(t)&&Tr(e.getExpression())?t:void 0},Nu=(e,t)=>{if(t!=="insertManyUnsafe")return r.isObjectLiteralExpression(e)?[e]:[];if(!r.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())r.isObjectLiteralExpression(n)&&s.push(n);return s},Pu=(e,t)=>{const s=$t(e);return s?.member===t?h(s.object):void 0},Zs=(e,t)=>r.isIdentifier(e)&&L(e)?.compilerNode===t.compilerNode,ui=(e,t,s,n=1)=>{const i=Pu(e,s);if(i!==void 0)return Zs(i,t);const o=r.isIdentifier(e)?L(e):void 0;if(r.isBindingElement(o)){const c=o.getParent(),l=c.getParent();return o.getDotDotDotToken()===void 0&&ae(o)===s&&r.isObjectBindingPattern(c)&&(l.compilerNode===t.compilerNode||ie(l)&&Zs(h(l.getInitializer()),t))}const a=ie(o)?o.getInitializer():void 0;return n>0&&a!==void 0&&ui(a,t,s,n-1)},Dt=e=>{const t=h(e)??e;return r.isConditionalExpression(t)?[...Dt(t.getWhenTrue()),...Dt(t.getWhenFalse())]:[t]},wu=(e,t,s)=>{const n=[],i=s===void 0?void 0:Su(s);for(const o of e.getProperties()){let a,c;if(r.isPropertyAssignment(o)?(a=S(o),c=o.getInitializer()):r.isShorthandPropertyAssignment(o)&&(a=S(o),c=o.getNameNode()),a===void 0||c===void 0||!Au.has(a))continue;const l=Dt(c).filter(f=>i===void 0?q(f)&&!Or(f):i.isTaintedValue(f,!0));if(l.length>0){const f=t.ownerField===a&&s?.pristine===!0&&ui(c,s.parameter,a),g=l.every(p=>tu(t.call,p));n.push({field:a,file:t.relativePath,line:t.call.getStartLineNumber(),method:t.method,scope:t.scope,...f&&{ownerScoped:!0},...g&&{guarded:!0}})}}return n},Iu=(e,t,s)=>{const n=bu(e.getExpression()),i=n===void 0?void 0:e.getArguments()[1];if(n===void 0||i===void 0)return[];const o=Nu(i,n);if(o.length===0)return[];const a=x(e),c=Hd(e),l={call:e,method:n,ownerField:c===void 0?void 0:s(c.mutatorName),relativePath:t,scope:a};return o.flatMap(u=>wu(u,l,c))},Cu=(e,t,s=[],n=[])=>{const i=new Map(n.map(c=>[`${c.filePath}:${c.exportName}`,c.owner])),o=C(e,t,(c,l)=>Iu(c,l,u=>i.get(`${l}:${u}`))),a=new Map(s.map(c=>[`${c.filePath}:${c.exportName}`,c.adminOnly===!0]));return Ut(o,s).map(c=>wr(c.scope)?.every(f=>a.get(`${c.file}:${f}`)===!0)===!0?{...c,adminOnly:!0}:c)},Tu=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Ou=e=>e&&r.isNumericLiteral(e)?Number(e.getText()):void 0,ku=e=>{const t=V(e,"webhookToleranceSeconds");return t&&r.isPropertyAssignment(t)?Ou(t.getInitializer()):void 0},Ru=(e,t)=>{const s=P(e.getExpression());if(s===void 0||!Tu.has(s))return;const[n]=e.getArguments(),i=n&&r.isObjectLiteralExpression(n)?ku(n):void 0;return{callee:s,scope:x(e),file:t,line:e.getStartLineNumber(),...i===void 0?{}:{toleranceSeconds:i}}},Fu=(e,t)=>C(e,t,Ru),Lu=new Map([["defineQueue",0],["defineSubscription",1],["defineWorkflow",0]]),Du=e=>{const t=e.getExpression();return r.isIdentifier(t)?t.getText():void 0},Mu=(e,t)=>{const s=e.getArguments()[t];if(!s||!r.isObjectLiteralExpression(s))return;const n=V(s,"handler");if(n===void 0||!r.isPropertyAssignment(n))return;const i=n.getInitializer();if(i&&(r.isArrowFunction(i)||r.isFunctionExpression(i)))return i},fi=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&r.isIdentifier(s)?s.getText():void 0},gi=(e,t)=>e===t||e.startsWith(`${t}.`),pi=e=>{const t=e.getDescendantsOfKind(d.PropertyAccessExpression);return r.isPropertyAccessExpression(e)&&t.push(e),t},en=e=>{const t=e.getParent();return r.isPropertyAccessExpression(t)&&t.getNameNode()===e||r.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(r.isBindingElement(t)&&t.getNameNode()===e)},mi=e=>{const t=e.getDescendantsOfKind(d.Identifier).filter(s=>en(s));return r.isIdentifier(e)&&en(e)&&t.push(e),t},_u=e=>{if(!r.isVariableDeclaration(e))return[];const t=e.getNameNode();return r.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(d.BindingElement).map(s=>s.getName())},Ku=e=>{const t=fi(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(d.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const i=n.getInitializer(),o=r.isVariableDeclarationList(i)?i.getDeclarations()[0]?.getNameNode():void 0;o&&r.isIdentifier(o)&&s.push(`${o.getText()}.body`)}return s},zu=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:Ku(e),i=new Set,o=a=>pi(a).some(c=>n.some(l=>gi(c.getText(),l)))?!0:mi(a).some(c=>i.has(c.getText()));for(const a of e.getDescendantsOfKind(d.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of _u(a))i.add(l)}return{names:i,prefixes:n}},$u=(e,t)=>pi(e).some(s=>t.prefixes.some(n=>gi(s.getText(),n)))?!0:mi(e).some(s=>t.names.has(s.getText())),Bu=e=>{const t=Ar(e);return t===void 0?void 0:{exportName:String(t.at(-1)),file:t.slice(0,-1).join("/")}},Vu=(e,t,s)=>{const n=fi(e,0);if(n===void 0)return[];const i=zu(e,t,n),o=new Set([n,...i.prefixes.filter(c=>c.endsWith(".body")).map(c=>c.slice(0,-5))]),a=[];for(const c of e.getDescendantsOfKind(d.CallExpression)){const l=c.getExpression();if(!r.isPropertyAccessExpression(l)||!On.has(l.getName())||!o.has(l.getExpression().getText()))continue;const u=c.getArguments()[1];if(!u||!$u(u,i))continue;const f=Bu(c.getArguments()[0]);f!==void 0&&a.push({dispatchKind:t,file:s,scope:x(c),line:c.getStartLineNumber(),targetExport:f.exportName,targetFile:f.file})}return a},Uu=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=Du(n),o=i===void 0?void 0:Lu.get(i);if(o===void 0)continue;const a=Mu(n,o);a!==void 0&&s.push(...Vu(a,i==="defineWorkflow"?"workflow":"queue",t))}return s},Wu=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Uu(i,w(t,n)))}return s},tn={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},sn=new Set(["account","credential","member","passkey","session","user"]),qu=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),ju=e=>{const s=qu(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return sn.has(s)||sn.has(n)},Hu=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Gu=(e,t)=>{const{objects:s,opaque:n}=Gt(e,t);return ic(s).some(i=>Hu(i))?!0:n?void 0:!1},Yu=e=>{const t=e.getArguments()[0];return!t||!r.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!V(t,"captcha"),usesRateLimit:!!V(t,"rateLimit")}},Qu=e=>{if(r.isCallExpression(e))return e;if(!r.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&r.isCallExpression(s)?s:void 0},Ke={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Xu=e=>{const t=Qu(e),s=t?P(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=Yu(t);return{...Ke,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in tn?{...Ke,[tn[s]]:!0}:Ke},Ju=e=>{const t={...Ke};let s=e;for(;r.isCallExpression(s);){const n=s.getExpression();if(!r.isPropertyAccessExpression(n))break;const i=n.getName()==="use"?s.getArguments()[0]:void 0;if(i){const o=Xu(i);t.usesCaptcha||=o.usesCaptcha,t.usesEmailGate||=o.usesEmailGate,t.usesMask||=o.usesMask,t.usesRateLimit||=o.usesRateLimit,t.usesRls||=o.usesRls}s=n.getExpression()}return t},Zu=new Set(["insert","insertMany","insertManyUnsafe","replace"]),ef=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!Zu.has(t.getName()))return!1;const s=t.getExpression();if(!z(s))return!1;const i=e.getArguments()[0];return!i||!(r.isStringLiteral(i)||r.isNoSubstitutionTemplateLiteral(i))?!1:ju(i.getLiteralText())},tf=new Set(["create","publish","publishBatch","runAfter","runAt","send","sendBatch"]),nn=new Set(["queues","scheduler","topics","workflows"]),sf=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!tf.has(t.getName()))return!1;let s=t.getExpression();for(;r.isCallExpression(s)||r.isElementAccessExpression(s)||r.isPropertyAccessExpression(s);){if(r.isPropertyAccessExpression(s)&&nn.has(s.getName())&&kr(s.getExpression()))return!0;s=s.getExpression()}const n=Wt(s);return n?.length===1&&nn.has(n[0]??"")},nf=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return z(s)},hi=new Set(["generateObject","generateText","streamObject","streamText"]),rf=e=>{const t=P(e.getExpression());return t!==void 0&&hi.has(t)},of=e=>{const t=P(e.getExpression());if(t===void 0||!hi.has(t))return!1;const s=e.getArguments()[0];return!s||!r.isObjectLiteralExpression(s)||s.getProperties().some(n=>r.isSpreadAssignment(n))?!1:!V(s,"maxOutputTokens")},af=new Set(["log","span","trace"]),cf=new Set(["ai"]),lf=new Set(["email","mail"]),df=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","topics","workflows"]),Et=(e,t)=>[...t].some(s=>Qe(e,s).length>0),vi=new Set([d.ArrowFunction,d.FunctionDeclaration,d.FunctionExpression,d.GetAccessor,d.MethodDeclaration,d.SetAccessor]),uf=new Set(["every","filter","flatMap","forEach","map","some"]),ff=new Set(["all","allSettled","race"]),Ei=e=>{const t=e.getParent();if(!t||!r.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!r.isPropertyAccessExpression(s))return;const n=s.getName();if(uf.has(n))return t;const i=s.getExpression();if(r.isIdentifier(i)&&i.getText()==="Promise"&&ff.has(n))return t},gf=e=>{let t=e.getParent();for(;t;){if(r.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(vi.has(t.getKind())){const s=Ei(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},pf=e=>{let t=e.getParent();for(;t!==void 0;){if(r.isCallExpression(t)&&t.getExpression().getText()==="Promise.allSettled")return!0;if(vi.has(t.getKind())){if(t=Ei(t),t===void 0)return!1;continue}t=t.getParent()}return!1},mf=e=>{const t=e.getFirstAncestor(u=>r.isArrowFunction(u)||r.isFunctionExpression(u)),s=t?.getParent();if(!t||!r.isCallExpression(s)||!s.getArguments().includes(t))return!1;const n=s.getExpression();if(!r.isIdentifier(n))return!1;const i=n.getSymbol(),o=i?.getAliasedSymbol()?.getValueDeclaration()??i?.getValueDeclaration(),a=r.isVariableDeclaration(o)?o.getInitializer():o;if(!r.isArrowFunction(a)&&!r.isFunctionExpression(a)&&!r.isFunctionDeclaration(a))return!1;const c=s.getArguments().indexOf(t),l=a.getParameters()[c]?.getName();return l===void 0?!1:a.getDescendantsOfKind(d.TryStatement).some(u=>{const f=u.getTryBlock().getDescendantsOfKind(d.CallExpression).some(p=>{const v=p.getExpression();return r.isIdentifier(v)&&v.getText()===l&&r.isAwaitExpression(p.getParent())}),g=u.getCatchClause();return f&&g!==void 0&&g.getDescendantsOfKind(d.ThrowStatement).length>0})},hf=e=>{let t=e;for(;;){const s=t.getParent();if(!r.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;if(s.getName()==="catch")return!0;if(s.getName()!=="then"&&s.getName()!=="finally")return!1;const n=s.getParent();if(!r.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},vf=e=>{let t=e;for(;;){const s=t.getParent();if(r.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return r.isCallExpression(s)&&s.getExpression()===t?s:void 0}},Ef=e=>{let t=!1,s=!0;for(const n of[...df].flatMap(i=>Qe(e,i))){const i=vf(n);i&&(t=!0,!gf(i)&&!hf(i)&&!mf(i)&&!pf(i)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},xf=e=>e.getDescendantsOfKind(d.ThrowStatement).some(t=>{const s=t.getExpression();if(!r.isNewExpression(s))return!1;const n=s.getExpression();return r.isIdentifier(n)&&n.getText()==="Error"}),rn="lunora-advisor-exempt",Sf=/^[\s*/]+/u,Af=/[\w-]/u,yf=e=>{const s=(e.getFirstAncestorByKind(d.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
|
|
22
|
+
`);for(const n of s.split(`
|
|
23
|
+
`)){const i=n.replace(Sf,"");if(!i.startsWith(rn))continue;const o=i.slice(rn.length);if(Af.test(o.charAt(0)))continue;const a=o.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":o.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},bf=e=>{const[t]=e.getArguments();if(t){if(r.isObjectLiteralExpression(t)){const s=V(t,"handler");return s?r.isPropertyAssignment(s)?s.getInitializer():r.isShorthandPropertyAssignment(s)?s.getNameNode():r.isMethodDeclaration(s)?s:void 0:void 0}return t}},Nf=(e,t)=>{const s=bf(t);if(!s)return;if(r.isArrowFunction(s)||r.isFunctionExpression(s)||r.isMethodDeclaration(s))return e;if(!r.isIdentifier(s))return;const n=s.getSourceFile(),i=s.getText(),o=n.getVariableDeclaration(i)?.getInitializer();return o&&(r.isArrowFunction(o)||r.isFunctionExpression(o))?o:n.getFunction(i)},Pf=e=>{let t=!1,s=!1,n=!1,i=!1,o=!1;for(const l of e.getDescendantsOfKind(d.CallExpression))if(ef(l)&&(o=!0),sf(l)&&(t=!0),nf(l)&&(i=!0),rf(l)&&(s=!0),of(l)&&(n=!0),o&&t&&i&&n)break;const{handlesErrors:a,reachesOutbound:c}=Ef(e);return{callsMail:Et(e,lf),emitsEvent:Et(e,af),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||Et(e,cf),throwsBareError:xf(e),unboundedAiGeneration:n,usesInsertManyUnsafe:i,writesUserTable:o}},wf=(e,t)=>{const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const n=ee(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const i=n.receiver?Ju(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},o=Nf(e,s);return{...o?Pf(o):{},...yf(e),...i,analyzableBody:o!==void 0,exportName:j(e)??e.getName(),file:t,hasEmailArg:Gu(s,n.receiver),kind:n.kind,visibility:n.visibility}},If=(e,t)=>{const s=[];for(const n of Y(e)){const i=wf(n,t);i&&s.push(i)}return s},Cf=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...If(i,w(t,n)))}return s},Tf=new Set(["dbRateLimit","rateLimit"]),Of=e=>r.isArrowFunction(e)?e.getBody():e,kf=e=>{if(!r.isArrowFunction(e))return;const t=e.getParameters()[0]?.getNameNode();return t!==void 0&&r.isIdentifier(t)?t:void 0},xi=e=>{const t=e.getParent();return r.isPropertyAccessExpression(t)&&t.getExpression()===e&&t.getName()==="args"},Si=(e,t)=>{const s=t.getSymbol();return s===void 0?[]:e.getDescendantsOfKind(d.Identifier).filter(n=>{if(n.getSymbol()!==s)return!1;const i=n.getParent();return!(r.isPropertyAccessExpression(i)&&i.getNameNode()===n)})},Rf=(e,t)=>q(e)||t!==void 0&&Si(e,t).some(s=>xi(s)),Ff=(e,t)=>t===void 0?ce(e):Si(e,t).some(s=>!xi(s)),Lf=(e,t)=>{const s=P(e.getExpression());if(s===void 0||!Tf.has(s))return;const n=F(Tn(e.getArguments()[2]),"key");if(!n)return;const i=Of(n),o=kf(n);if(!(!Rf(i,o)||Ff(i,o)))return{callee:s,scope:x(e),file:t,limitName:Cn(e),line:e.getStartLineNumber()}},Df=(e,t)=>C(e,t,Lf),Mf=new Set(["findFirst","findFirstOrThrow","findMany","findUnique","get"]),_f=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!Mf.has(t.getName()))return;const s=t.getExpression();if(z(s)){const n=e.getArguments()[0];return n&&r.isStringLiteral(n)?n.getLiteralText():""}if(r.isPropertyAccessExpression(s)&&z(s.getExpression()))return s.getName()},Kf=e=>{let t=e;for(;r.isCallExpression(t);){const s=t.getExpression();if(!r.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&z(s.getExpression())){const n=t.getArguments()[0];return n&&r.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},zf=e=>{let t=h(e)??e;for(;r.isAwaitExpression(t);)t=h(t.getExpression())??t.getExpression();return t},Ai=(e,t=!1)=>{const s=zf(e);if(r.isIdentifier(s)){if(t)return;const n=G(s);return n===void 0?void 0:Ai(n,!0)}if(r.isCallExpression(s))return _f(s)??Kf(s)},$f=e=>{const t=e.getBody();if(!r.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(d.ReturnStatement)){const i=n.getFirstAncestor(a=>r.isArrowFunction(a)||r.isFunctionExpression(a)||r.isFunctionDeclaration(a)),o=n.getExpression();i===e&&o!==void 0&&s.push(o)}return s},Bf=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!r.isCallExpression(s))return[];const n=ee(s);if(n?.kind!=="query")return[];const i=Jn(s);if(i===void 0)return[];const o=n.receiver!==void 0&&Lr(n.receiver,"output"),a=n.receiver!==void 0&&Dn(n.receiver,"use","mask"),c=new Set,l=[];for(const u of $f(i)){const f=Ai(u);f===void 0||c.has(f)||(c.add(f),l.push({exportName:j(e)??e.getName(),file:t,line:u.getStartLineNumber(),table:f,usesMask:a,usesOutput:o,visibility:n.visibility}))}return l},Vf=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=w(t,n);for(const a of Y(i))s.push(...Bf(a,o))}return s},Uf=e=>{if(!e||!r.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(r.isPropertyAssignment(s)||r.isShorthandPropertyAssignment(s)||r.isMethodDeclaration(s)||r.isGetAccessorDeclaration(s))&&t.push(S(s));return t},Wf=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&r.isCallExpression(s)?ee(s):void 0;if(!n)return[];const i=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=Kn(o);if(a===void 0)continue;const c=Uf(F(a.options,"with"));c.length!==0&&i.push({exportName:j(e)??e.getName(),file:t,line:o.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return i},qf=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=w(t,n);for(const a of Y(i))s.push(...Wf(a,o))}return s},W=(e,t)=>`${e}:${t}`,on=(e,t,s,n)=>s===void 0?void 0:{endLine:e.getEndLineNumber(),exported:n,file:t,name:s,node:e,startLine:e.getStartLineNumber()},jf=(e,t)=>[...ne(e,t,d.FunctionDeclaration,(s,n)=>s.getParent().getKind()===d.SourceFile?on(s,n,s.getName(),s.isExported()):void 0),...ne(e,t,d.VariableDeclaration,(s,n)=>{const i=s.getVariableStatement();return i?.getParent().getKind()===d.SourceFile?on(i,n,s.getName(),i.isExported()):void 0})],Hf=(e,t,s)=>{const n=e.getExpression();if(!r.isIdentifier(n))return;const i=n.getSymbol(),o=(i?.getAliasedSymbol()??i)?.getDeclarations()[0];if(o===void 0||!(r.isFunctionDeclaration(o)||r.isVariableDeclaration(o)))return;const a=o.getName(),c=w(s,o.getSourceFile().getFilePath());return a===void 0?void 0:t.get(W(c,a))},Gf=e=>`${e.table}|${e.method}|${e.fields?.join(",")??"*"}`,Yf=(e,t)=>{const s=new Map(e.map(n=>[W(n.file,n.name),new Map]));for(const n of t){const i=e.find(o=>o.file===n.file&&o.startLine<=n.line&&n.line<=o.endLine);i!==void 0&&n.table!==""&&s.get(W(i.file,i.name))?.set(Gf(n),{fields:n.fields,method:n.method,table:n.table})}return s},Qf=(e,t,s)=>e.node.getDescendantsOfKind(d.CallExpression).map(n=>Hf(n,t,s)).filter(n=>n!==void 0),Xf=(e,t,s,n)=>{for(const i of e){const o=i.scope.kind==="module"?void 0:t.get(W(i.file,i.scope.name)),a=i.target===void 0?void 0:s.get(i.target);i.kind==="call"&&o!==void 0&&a!==void 0&&n.get(W(o.file,o.name))?.push(a)}},Jf=(e,t,s)=>{const n=new Map(e.map(a=>[W(a.file,a.name),a])),i=new Map(e.map(a=>[`${jt(a.file)}:${a.name}`,a])),o=new Map(e.map(a=>[W(a.file,a.name),Qf(a,n,t)]));return Xf(s,n,i,o),o},Zf=(e,t)=>{let s=!1;for(const[n,i]of t??[])e!==void 0&&!e.has(n)&&(e.set(n,i),s=!0);return s},eg=(e,t,s)=>{let n=!0;for(;n;){n=!1;for(const i of e)for(const o of s.get(W(i.file,i.name))??[])Zf(t.get(W(i.file,i.name)),t.get(W(o.file,o.name)))&&(n=!0)}},tg=(e,t,s,n)=>{const i=jf(e,t),o=Yf(i,s);return eg(i,o,Jf(i,t,n)),i.filter(a=>a.exported).flatMap(a=>[...o.get(W(a.file,a.name))?.values()??[]].map(c=>({...c,exportName:a.name,file:a.file})))},We=e=>{if(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(r.isBinaryExpression(e)&&e.getOperatorToken().getKind()===d.PlusToken){const t=We(e.getLeft()),s=We(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},sg=e=>{let t=e,s=t.getParent();for(;s!==void 0&&r.isBinaryExpression(s)&&s.getOperatorToken().getKind()===d.PlusToken;)t=s,s=t.getParent();return t!==e&&We(t)!==void 0},ng=e=>{const t=e.getParent();if(t!==void 0){if(r.isVariableDeclaration(t)||r.isPropertyAssignment(t)||r.isPropertySignature(t))return S(t);if(r.isBinaryExpression(t)&&t.getOperatorToken().getKind()===d.EqualsToken)return t.getLeft().getText()}},ig=(e,t,s)=>eo(e)?!yr(s)&&to(ng(t)):!0,rg=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(d.BinaryExpression),...e.getDescendantsOfKind(d.StringLiteral),...e.getDescendantsOfKind(d.NoSubstitutionTemplateLiteral)],i=new Set;for(const o of n){if(sg(o))continue;const a=We(o);if(a===void 0)continue;const c=Jr(a);if(c===void 0||!ig(c,o,t))continue;const l=o.getStartLineNumber(),u=`${String(l)}:${c}`;i.has(u)||(i.add(u),s.push({file:t,kind:c,line:l,preview:Zr(a)}))}return s},og=(e,t)=>{const s=[];for(const n of A(t,{includeSkipped:!0})){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...rg(i,w(t,n)))}return s},ag=(e,t)=>{if(!r.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&r.isCallExpression(s)?ee(s):void 0;if(!n)return[];const i=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=Kn(o);if(a===void 0)continue;const c=F(a.options,"includeDeleted");if(c===void 0)continue;const l=r.isTrueLiteral(c),u=!l&&q(c);!l&&!u||i.push({exportName:j(e)??e.getName(),file:t,fromArgs:u,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:n.visibility})}return i},cg=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=w(t,n);for(const a of Y(i))s.push(...ag(a,o))}return s},lg=new Set(["query","unsafe"]),dg=e=>!r.isPropertyAccessExpression(e)||!lg.has(e.getName())?!1:H(e.getExpression(),["sql"]),ug=e=>r.isBinaryExpression(e)||r.isTemplateExpression(e),fg=(e,t)=>{if(!dg(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!ug(s)))return{file:t,line:s.getStartLineNumber(),scope:x(e)}},gg=(e,t)=>C(e,t,fg),pg=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],mg=e=>{for(const[t,s]of pg)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},hg=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of i.getImportDeclarations()){const a=o.getModuleSpecifierValue(),c=mg(a);c!==void 0&&s.push({file:w(t,n),line:o.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},vg=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Eg=(e,t,s=[])=>{const n=Ze(e,t,{argIndex:0,matchReceiver:i=>i==="ctx.storage"||i.startsWith("ctx.storage."),methods:vg,requireUnmodifiedReach:!0});return Ut(n,s)},xg=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Sg=e=>e&&r.isNumericLiteral(e)?Number(e.getText()):void 0,Ag=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!r.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const i of e.getProperties()){if(r.isSpreadAssignment(i)){n=!0;continue}if(r.isPropertyAssignment(i)){const o=S(i);t.push(o),o==="expiresInSeconds"&&(s=Sg(i.getInitializer()));continue}(r.isShorthandPropertyAssignment(i)||r.isMethodDeclaration(i))&&t.push(S(i))}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},yg=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName(),s=xg.get(t);return s===void 0?void 0:Rn(e.getExpression(),i=>i==="ctx.storage"||i.startsWith("ctx.storage."))?{method:t,optionsIndex:s}:void 0},bg=(e,t)=>{const s=yg(e.getExpression());if(s!==void 0)return{scope:x(e),file:t,line:e.getStartLineNumber(),method:s.method,...Ag(e.getArguments()[s.optionsIndex])}},Ng=(e,t)=>C(e,t,bg),Pg=e=>r.isDoStatement(e)||r.isForInStatement(e)||r.isForOfStatement(e)||r.isForStatement(e)||r.isWhileStatement(e),yi=e=>{const t=e.getLabel()?.getText(),s=i=>t!==void 0?r.isLabeledStatement(i)&&i.getLabel().getText()===t:Pg(i)||r.isBreakStatement(e)&&r.isSwitchStatement(i);let n=e.getFirstAncestor(i=>re(i)||s(i));if(!(n===void 0||re(n))){for(;r.isContinueStatement(e)&&r.isLabeledStatement(n);)n=n.getStatement();return n}},Xt=(e,t)=>y(e.getFirstAncestor(s=>y(s,t)||re(s)),t),wg=(e,t)=>y(e,t)||e.getFirstAncestor(s=>y(s,t))!==void 0,bi=(e,t)=>{if(r.isReturnStatement(e)||r.isThrowStatement(e))return y(e,t)||Xt(e,t);if(r.isBreakStatement(e)||r.isContinueStatement(e)){const s=yi(e);return s!==void 0&&!wg(s,t)}return!1},Ni=e=>[...r.isBreakStatement(e)||r.isContinueStatement(e)||r.isReturnStatement(e)||r.isThrowStatement(e)?[e]:[],...e.getDescendantsOfKind(d.BreakStatement),...e.getDescendantsOfKind(d.ContinueStatement),...e.getDescendantsOfKind(d.ReturnStatement),...e.getDescendantsOfKind(d.ThrowStatement)],Ig=e=>Ni(e).some(t=>bi(t,e)),Cg=e=>{const t=r.isCallExpression(e)?e.getExpression():void 0;return r.isPropertyAccessExpression(t)&&t.getName()==="throwIfAborted"},Tg=e=>Ni(e).some(t=>bi(t,e)||r.isBreakStatement(t)&&y(yi(t),e))||e.getDescendantsOfKind(d.CallExpression).some(t=>Cg(t)&&Xt(t,e)),Og=e=>e.getDescendantsOfKind(d.YieldExpression).some(t=>Xt(t,e)),kg=e=>r.isDoStatement(e)||r.isWhileStatement(e)?e.getExpression():e.getCondition(),Rg=e=>r.isDoStatement(e)?"do":r.isWhileStatement(e)?"while":"for",xt=(e,t)=>{const s=kg(e);if(!(s===void 0||r.isTrueLiteral(h(s)))||Tg(e)||Og(e))return;const i=x(e);if(!(i.kind==="module"&&e.getFirstAncestor(re)!==void 0))return{file:t,kind:Rg(e),line:e.getStartLineNumber(),scope:i}},Fg=(e,t)=>[...ne(e,t,d.WhileStatement,xt),...ne(e,t,d.ForStatement,xt),...ne(e,t,d.DoStatement,xt)].toSorted((s,n)=>s.file.localeCompare(n.file)||s.line-n.line),Lg=new Set(["when","where"]),St=new Set(["definePolicy","defineShape"]),Dg=e=>{if(!r.isCallExpression(e))return;const t=e.getExpression();if(r.isPropertyAccessExpression(t)){const n=t.getName();return St.has(n)?n:void 0}if(!r.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(r.isImportSpecifier(n)){const i=n.getNameNode().getText();return St.has(i)?i:void 0}const s=t.getText();return St.has(s)?s:void 0},Mg=e=>r.isObjectLiteralExpression(e)&&e.getProperties().length===0,Pi=e=>{if(e!==void 0){if(r.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===d.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Mg(e))return"empty-object";if(r.isParenthesizedExpression(e))return Pi(e.getExpression())}},Jt=e=>e.getAncestors().find(t=>r.isArrowFunction(t)||r.isFunctionExpression(t)||r.isFunctionDeclaration(t)),_g=e=>e.getDescendantsOfKind(d.ReturnStatement).filter(t=>Jt(t)===e),wi=e=>e.getDescendantsOfKind(d.ConditionalExpression).filter(t=>Jt(t)===e),Kg=e=>{const t=_g(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(d.IfStatement)!==void 0)||wi(e).length>0},zg=e=>e.getDescendantsOfKind(d.IfStatement).filter(t=>Jt(t)===e),Mt=e=>e.getKind()===d.NullKeyword||e.getKind()===d.FalseKeyword||r.isIdentifier(e)&&e.getText()==="undefined"?!0:r.isNumericLiteral(e)?e.getLiteralValue()===0:r.isStringLiteral(e)&&e.getLiteralValue()==="",$g=(e,t)=>Mt(e)||Mt(t),Bg=new Map([[d.EqualsEqualsEqualsToken,"positive"],[d.EqualsEqualsToken,"positive"],[d.ExclamationEqualsEqualsToken,"negative"],[d.ExclamationEqualsToken,"negative"]]),an=e=>!Mt(e)&&(r.isLiteralExpression(e)||e.getKind()===d.TrueKeyword),Vg=(e,t,s)=>{const n=Bg.get(e);if(n!==void 0)return $g(t,s)?n==="positive"?"negative":"positive":an(t)||an(s)?void 0:n},Se=e=>{if(r.isParenthesizedExpression(e))return Se(e.getExpression());if(r.isPrefixUnaryExpression(e)&&e.getOperatorToken()===d.ExclamationToken)return"negative";if(r.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=Vg(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===d.AmpersandAmpersandToken||t===d.BarBarToken){const n=Se(e.getLeft()),i=Se(e.getRight());return n===i?n:"indeterminate"}}return r.isIdentifier(e)||r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e)||r.isCallExpression(e)?"positive":"indeterminate"},cn=e=>{if(e!==void 0){if(r.isReturnStatement(e))return e;if(r.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&r.isReturnStatement(t)?t:void 0}}},Ug=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(d.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Wg=e=>r.isReturnStatement(e)?e.getExpression()??e:e,qg=e=>{const t=[];for(const s of wi(e)){const n=Se(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of zg(e)){const n=Se(s.getExpression());if(n==="indeterminate")continue;const i=n==="negative"?cn(s.getThenStatement()):cn(s.getElseStatement())??Ug(s);i!==void 0&&t.push(Wg(i))}return t},jg=e=>{for(const t of e.getAncestors())if(r.isVariableDeclaration(t)){const s=t.getNameNode();if(r.isIdentifier(s))return s.getText()}return"<anonymous>"},Hg=(e,t,s)=>{if(!r.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!r.isObjectLiteralExpression(n))return[];const i=[];for(const o of n.getProperties()){if(!r.isPropertyAssignment(o)||!Lg.has(S(o)))continue;const a=o.getInitializer();if(!(!a||!(r.isArrowFunction(a)||r.isFunctionExpression(a)))&&Kg(a))for(const c of qg(a)){const l=Pi(c);l!==void 0&&i.push({exportName:jg(e),file:s,form:l,key:S(o),line:c.getStartLineNumber(),owner:t})}}return i},Gg=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const i=Dg(n);i!==void 0&&s.push(...Hg(n,i,t))}return s},Yg=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Gg(i,w(t,n)))}return s},Qg=new Set(["query","upsert","upsertMany","upsertNow"]),pe=new Set,Xg=e=>{if(!r.isPropertyAccessExpression(e))return;const t=e.getName();if(Qg.has(t))return H(e.getExpression(),["vectors"])?t:void 0},Zt=e=>{let t=e;for(;r.isParenthesizedExpression(t)||r.isAsExpression(t)||r.isSatisfiesExpression(t)||r.isNonNullExpression(t)||r.isTypeAssertion(t);)t=t.getExpression();return t},Ii=e=>{const t=e.getParent();return r.isShorthandPropertyAssignment(t)&&t.getNameNode()===e?t.getValueSymbol():e.getSymbol()},Ci=e=>Ii(e)?.getDeclarations()[0],Jg=e=>{const t=e.getParent();return r.isBindingElement(t)||(r.isPropertyAccessExpression(t)||r.isPropertyAssignment(t)||r.isVariableDeclaration(t)||r.isParameterDeclaration(t)||r.isMethodDeclaration(t))&&t.getNameNode()===e?!1:!r.isQualifiedName(t)||t.getLeft()===e},Ti=e=>{let t=e;for(;t!==void 0&&(r.isBindingElement(t)||r.isObjectBindingPattern(t)||r.isArrayBindingPattern(t));)t=t.getParent();return t!==void 0&&r.isVariableDeclaration(t)?t:void 0},ln=(e,t,s)=>{const n=Ii(e)?.compilerSymbol;if(n!==void 0&&t.has(n))return!0;if(s>0){const i=Ti(Ci(e)),o=i!==void 0&&r.isVariableDeclaration(i)?i.getInitializer():void 0;if(o!==void 0)return es(o,t,s-1)}return q(e)},es=(e,t,s)=>{const n=Zt(e);return ce(n)?!1:r.isIdentifier(n)?ln(n,t,s):q(n)?!0:n.getDescendantsOfKind(d.Identifier).some(i=>Jg(i)&&ln(i,t,s))},Oi=e=>{const t=Ti(Ci(e));return t!==void 0&&r.isVariableDeclaration(t)?t.getInitializer():void 0},Z=(e,t)=>{const s=Zt(e);if(r.isObjectLiteralExpression(s))return[s];if(r.isConditionalExpression(s))return[...Z(s.getWhenTrue(),t),...Z(s.getWhenFalse(),t)];if(r.isBinaryExpression(s)){const n=s.getOperatorToken().getKind();if(n===d.BarBarToken||n===d.QuestionQuestionToken||n===d.AmpersandAmpersandToken)return[...Z(s.getLeft(),t),...Z(s.getRight(),t)]}if(r.isIdentifier(s)&&t){const n=Oi(s);return n===void 0?[]:Z(n,!1)}return[]},Zg=(e,t)=>{const s=Z(e,t);if(s.length===0)return{replaces:!0,sources:[e]};const n=s.map(o=>qe(o,!1)),i=n.flat();if(i.length!==0)return{replaces:n.every(o=>o.length>0),sources:i}},ep=e=>(r.isPropertyAssignment(e)||r.isShorthandPropertyAssignment(e))&&e.getName()==="namespace",tp=e=>r.isShorthandPropertyAssignment(e)?e.getNameNode():e.getInitializer()??e.getNameNode(),qe=(e,t)=>{let s=[];for(const n of e.getProperties())if(r.isSpreadAssignment(n)){const i=Zg(n.getExpression(),t);i!==void 0&&(s=i.replaces?i.sources:[...s,...i.sources])}else ep(n)&&(s=[tp(n)]);return s},sp=e=>{if(!e||!(r.isArrowFunction(e)||r.isFunctionExpression(e)))return[];const t=e.getBody();return r.isBlock(t)?t.getDescendantsOfKind(d.ReturnStatement).filter(s=>s.getFirstAncestor(n=>r.isFunctionLikeDeclaration(n))===e).flatMap(s=>s.getExpression()??[]):[t]},np=e=>{if(!e||!(r.isArrowFunction(e)||r.isFunctionExpression(e)))return pe;const t=e.getParameters()[0]?.getNameNode();if(t===void 0)return pe;const s=r.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.BindingElement).map(n=>n.getNameNode());return new Set(s.flatMap(n=>r.isIdentifier(n)?n.getSymbol()?.compilerSymbol??[]:[]))},_t=(e,t=!0,s=pe)=>{const n=Zt(e);if(r.isIdentifier(n)){const o=t?Oi(n):void 0;return o===void 0?[{node:n,parameters:s}]:_t(o,!1,s)}if(r.isArrayLiteralExpression(n))return n.getElements().flatMap(o=>r.isSpreadElement(o)?_t(o.getExpression(),t,s):Z(o,!0).flatMap(a=>qe(a,!0).map(c=>({node:c,parameters:s}))));const i=r.isCallExpression(n)?n.getExpression():void 0;if(r.isCallExpression(n)&&r.isPropertyAccessExpression(i)&&i.getName()==="map"){const o=n.getArguments()[0],a=es(i.getExpression(),pe,1)?np(o):pe;return sp(o).flatMap(c=>Z(c,!0).flatMap(l=>qe(l,!0).map(u=>({node:u,parameters:a}))))}return[{node:n,parameters:s}]},ip=(e,t)=>{const s=Xg(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!(!n||!(s==="upsertMany"?_t(n):Z(n,!0).flatMap(o=>qe(o,!0).map(a=>({node:a,parameters:pe})))).some(({node:o,parameters:a})=>es(o,a,1))))return{scope:x(e),file:t,line:e.getStartLineNumber(),method:s}},rp=(e,t)=>C(e,t,ip),op=(e,t,s)=>{const{callSites:n,containers:i,crons:o,functions:a,modules:c,mutators:l,queues:u,schema:f,shapes:g,wranglerVariables:p,workflows:v}=s;return mr({adminRoutes:Ra(e,t),aiRawRuns:Ba(e,t),aiToolSideEffects:Ja(e,t),argumentDerivedFetches:tc(e,t),argumentValidators:xc(e,t),authApiCalls:zr(e,t),authConfigs:Tc(e,t),browserUrlAccesses:Fc(e,t),callEdges:n.callEdges,configCalls:Bc(e,t),containerKeyAccesses:Uc(e,t),containerOverrides:Yc(e,t),containers:i,countReads:el(e,t,f.tables),crons:o,cronTargets:o.flatMap($=>$.functionPath===void 0?[]:[$.functionPath]),exportSinks:il(e,t),staleMigrationImports:hg(e,t),failOpenGuards:ll(e,t),flagReads:pl(e,t),flagSecurityDefaults:El(e,t),geoIndexUsages:Al(e,t),httpActionGuards:Fl(e,t),httpHeaderWrites:Ul(e,t),hyperdriveCalls:$r(e,t),identityClaimReads:ed(e,t),imageDeliveryUrlAccesses:sd(e,t),inserts:n.inserts,kvKeyAccesses:id(e,t,a),mailRecipientAccesses:ld(e,t),maskProcedures:Br(e,t),maskStrategies:fd(e,t),mutatorWrites:Ed(e,t),nondeterministicCalls:jr(e,t),normalizeIdAuthorizations:Fd(e,t),notifyCalls:Gr(e,t),notifyConfig:Hr(e,t),mutators:l,ownerFieldWrites:Cu(e,t,a,l),unrestrictedWhereBranches:Yg(e,t),paymentWebhooks:Fu(e,t),privilegedDispatches:Wu(e,t),procedureProtections:Cf(e,t),queries:n.queries,queues:u,r2sqlCalls:Yr(e,t),ratelimitKeySelectors:Df(e,t),rawRowReturns:Vf(e,t),relationLoads:qf(e,t),rlsProcedures:Qr(e,t),schema:f,secretLiterals:og(e,t),modules:c,shapes:g,softDeleteReads:cg(e,t),sqlInterpolations:gg(e,t),storageKeyAccesses:Eg(e,t,a),storageUploads:Ng(e,t),tableWrites:n.tableWrites,rowEffects:tg(e,t,n.tableWrites,n.callEdges),unboundedLoops:Fg(e,t),vectorNamespaceAccesses:rp(e,t),workflowCalls:n.workflowCalls,workflows:v,wranglerVariables:p})},ap=e=>({cacheKey:`advisor_accept_unused:${e.rule}:${e.file}:${e.exportName}`,categories:["SCHEMA"],description:"`advisor.accept` in `lunora.config.*` accepts a finding the advisor does not report as an error.",detail:`No ERROR \`${e.rule}\` in \`${e.file}\` for \`${e.exportName}\` — the acceptance no longer applies.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e.exportName,file:e.file,rule:e.rule},name:"advisor_accept_unused",remediation:"Remove the entry, or correct the rule, file and export name it names.",title:"An accepted advisor finding matches no error"}),cp=(e,t)=>{const s=new Set;return[...e.map(i=>{if(i.level!=="ERROR")return i;const o=t.find(a=>a.rule===i.name&&a.file===i.metadata.file&&a.exportName===i.metadata.exportName);return o===void 0?i:(s.add(o),{...i,detail:`Accepted: ${o.reason}. ${i.detail}`,level:"INFO",metadata:{...i.metadata,accepted:o.reason}})}),...t.filter(i=>!s.has(i)).map(i=>ap(i))]},lp=()=>({cacheKey:"advisor_accept_invalid",categories:["SCHEMA"],description:"`advisor.accept` in `lunora.config.*` is read by parsing the file, so every entry must be a literal.",detail:"`advisor.accept` is not an array of literal `{ rule, file, exportName, reason }` objects with non-empty strings, so codegen ignored all of it and every ERROR still fails the gate.",facing:"INTERNAL",level:"WARN",metadata:{},name:"advisor_accept_invalid",remediation:'Write `advisor: { accept: [{ rule: "owner_field_from_args_not_auth", file: "lunora/auth/team.ts", exportName: "addTeamMember", reason: "…" }] }` as literals on the config\'s default export.',title:"`advisor.accept` is not a list codegen can read, so no acceptance applies"}),dp=e=>e.metadata.accepted!==void 0||e.name==="advisor_accept_unused"||e.name==="advisor_accept_invalid",dn={error:"ERROR",info:"INFO",warn:"WARN"},un={ERROR:2,INFO:0,WARN:1},up=e=>({cacheKey:"advisor_min_severity_invalid",categories:["SCHEMA"],description:"`advisor.minSeverity` in `lunora.config.*` sets the lowest advisory level codegen reports and writes into `_generated/shard.ts`. Codegen reads it by parsing the file, so it has to be a string literal.",detail:e,facing:"INTERNAL",level:"WARN",metadata:{},name:"advisor_min_severity_invalid",remediation:'Set `advisor: { minSeverity: "info" | "warn" | "error" }` as a literal on the config\'s default export.',title:"`advisor.minSeverity` is not a level codegen can read, so every advisory was reported"}),fp=(e,t)=>{const{advisor:s}=_n(e);if(s===void 0||s.minSeverity===void 0&&s.unreadable!==!0)return[...t];const{minSeverity:n}=s,i=n!==void 0&&Object.hasOwn(dn,n)?dn[n]:void 0;return i===void 0?[...t,up(n===void 0?"`advisor.minSeverity` is not a string literal codegen can read without evaluating the config: a computed value or key, or a spread that could set or override it.":`\`advisor.minSeverity\` is "${n}", which is not one of "info", "warn" or "error".`)]:t.filter(o=>dp(o)||un[o.level]>=un[i])},gp=(e,t)=>{const{advisor:s}=_n(e),n=cp(t,s?.accept??[]);return fp(e,s?.acceptUnreadable===!0?[...n,lp()]:n)},pp={call:"function",enqueue:"queue",invoke:"service",publish:"topic",schedule:"function"},mp="crons",hp=io.replace(/\.ts$/u,""),ge=(e,t)=>`${jt(e)}:${t}`,At=(e,t,s)=>t===""?{reason:`the ${s} is not a string literal`}:{to:`${e}:${t}`},vp=e=>[...e.callEdges.map(t=>{const s=t.target===void 0?{reason:t.reason??"unreadable target"}:{to:`${pp[t.kind]}:${t.target}`};return{file:t.file,kind:t.kind,line:t.line,scope:t.scope,...s}}),...e.queries.map(t=>({file:t.file,kind:"read",line:t.line,scope:t.scope,...At("table",t.table,"table name")})),...[...e.inserts,...e.tableWrites].map(t=>({file:t.file,kind:"write",line:t.line,scope:t.scope,...At("table",t.table,"written table")})),...e.workflowCalls.map(t=>({file:t.file,kind:"start",line:t.line,scope:t.scope,...At("workflow",t.workflow,"workflow name")}))],Ep=e=>e.untracked===!0?"inside a helper only code outside any export calls":"inside a non-exported helper",xp=e=>{const{scope:t}=e;switch(t.kind){case"export":return[{...e,exportName:t.name}];case"helper":return t.callers.length===0?[{...e,unattributed:Ep(t)}]:t.callers.map(s=>({...e,exportName:s}));default:return[{...e,unattributed:"at module scope"}]}},Sp=e=>vp(e).flatMap(t=>xp(t)),Ap=e=>[...e.queues.flatMap(t=>t.topic===void 0?[]:[{file:t.filePath,from:`topic:${t.topic}`,kind:"subscribe",line:0,to:`queue:${t.exportName}`}]),...e.crons.map(t=>{const s=t.workflow===void 0?void 0:`workflow:${t.workflow.exportName}`,n=t.functionPath===void 0?void 0:`function:${t.functionPath}`,i=s??n;return{file:mp,from:`cron:${t.name}`,kind:"trigger",line:0,...i===void 0?{reason:"the cron has no target"}:{to:i}}})],yp=e=>new Map(e.flatMap(t=>t.tables.map(s=>[s,t.name]))),ve=(e,t)=>t===void 0?e:{...e,module:t},bp=e=>{const t=new Map,s=new Map,n=yp(e.modules),i=(c,l)=>{s.set(c,[...s.get(c)??[],l])},o=(c,l)=>{t.set(c.id,c),l!==void 0&&i(l,c.id)},a=(c,l)=>{c!==void 0&&i(ge(c.file,c.exportName),l)};for(const c of e.functions){const l=ge(c.filePath,c.exportName),u=[...Xr(c.filePath),c.exportName].join(".");o(ve({detail:c.kind,id:`function:${l}`,kind:"function",name:u},Fe(e.modules,c.filePath)),l)}for(const c of e.httpRoutes){const l=ge(c.filePath,c.exportName);o(ve({id:`http:${l}`,kind:"http",name:`${c.method} ${c.path}`},Fe(e.modules,c.filePath)),l)}for(const c of e.schema.tables)o(ve({id:`table:${c.name}`,kind:"table",name:c.name},n.get(c.name)));for(const c of e.queues){const l=c.topic===void 0?{}:{detail:"subscription"};o(ve({...l,id:`queue:${c.exportName}`,kind:"queue",name:c.exportName},Fe(e.modules,c.filePath)),ge(c.filePath,c.exportName)),a(c.handlerSite,`queue:${c.exportName}`)}for(const c of e.topics)o(ve({id:`topic:${c.exportName}`,kind:"topic",name:c.exportName},Fe(e.modules,c.filePath)));for(const c of e.workflows)o({id:`workflow:${c.exportName}`,kind:"workflow",name:c.exportName},ge(hp,c.exportName)),a(c.handlerSite,`workflow:${c.exportName}`);for(const c of e.crons)o({detail:c.cron,id:`cron:${c.name}`,kind:"cron",name:c.name});for(const c of e.services){const l=c.rpcEntrypoint===void 0?"fetch":"rpc";o({detail:c.entrypoint===void 0?l:`${l} · ${c.entrypoint}`,id:`service:${c.name}`,kind:"service",name:c.worker})}return{nodes:t,sites:s}},Np=e=>e==="default"?"the default export is not a registered function":`"${e}" is not a registered function`,Pp=(e,t)=>"from"in e?[e.from]:"unattributed"in e?{reason:e.unattributed}:t.get(ge(e.file,e.exportName))??{reason:Np(e.exportName)},wp=(e,t,s)=>{if("reason"in e)return{reason:e.reason};const n=Pp(e,t);if("reason"in n)return n;const{to:i}=e;return s.has(i)?{drawn:n.map(o=>({from:o,kind:e.kind,to:i}))}:{reason:`${i} is not declared`}},yt=e=>`${e.from}|${e.kind}|${e.to}`,Ip=e=>`${e.file}|${String(e.line)}|${e.kind}|${e.reason}`,Cp=e=>{const{nodes:t,sites:s}=bp(e),n=new Map,i=new Map;for(const o of[...Ap(e),...Sp(e)]){const a=wp(o,s,t);if("drawn"in a)for(const c of a.drawn)n.set(yt(c),c);else{const c={file:o.file,kind:o.kind,line:o.line,reason:a.reason};i.set(Ip(c),c)}}return{edges:[...n.values()].toSorted((o,a)=>yt(o).localeCompare(yt(a))),nodes:[...t.values()].toSorted((o,a)=>o.id.localeCompare(a.id)),modules:e.modules.map(o=>({...o.description===void 0?{}:{description:o.description},...o.installed===!0?{installed:!0}:{},...o.ownsFolder===!1?{ownsFolder:!1}:{},name:o.name,tables:[...o.tables]})),unresolved:[...i.values()].toSorted((o,a)=>o.file.localeCompare(a.file)||o.line-a.line),version:1}},Tp=e=>`${$n}export const architecture = ${oo(e,"Record<string, unknown>")};
|
|
24
|
+
`,fn=(e,t="api")=>{const s=new Map;for(const n of e){const i=jt(n),o=s.get(i);if(o===void 0){s.set(i,n);continue}if(o!==n){const a=t==="api"?`the generated api.ts would declare "${i}" twice and the dispatch key "${i}:<fn>" would be ambiguous`:`the generated api.ts would declare "${i}" twice in HttpStreamsRef and again in the httpStreams object literal`;throw new _("INTERNAL",`@lunora/codegen: "${o}" and "${n}" both map to the ${t} namespace "${i}" — ${a}. Rename one file so the two differ by more than a non-identifier character (\`-\`, \`.\`, \`/\` and \`_\` all sanitize to \`_\`).`,{status:500})}}},Op=(e,t={})=>{const{hasVectors:s=!0,scheduler:n=!1,storage:i=!1,usage:o}=t,a=[];e.tables.some(c=>Bn(c))&&a.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),e.tables.some(c=>Vn(c))&&a.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'},{name:"@lunora/sql-store",reason:'`.global({ backend: "hyperdrive" })` makes `_generated/app.ts` import the `SqlCtxDbOptions` / `SqlExec` types'}),n&&a.push({name:"@lunora/scheduler",reason:"a declared cron (or `ctx.scheduler` use) makes `_generated/app.ts` import `createScheduler`"}),i&&a.push({name:"@lunora/storage",reason:"a `v.storage()` column, a storage access rule (or `ctx.storage` use) makes `_generated/app.ts` import `createStorage`"}),e.vectorIndexes.length>0&&s&&a.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/shard.ts` import `@lunora/bindings/vectors`"});for(const c of o===void 0?[]:go)c.requiredPackage!==void 0&&o?.[c.key]===!0&&a.push({name:c.requiredPackage,reason:`\`ctx.${c.contextProperty??c.key}\` usage makes \`_generated/\` import \`${c.moduleSpecifier}\``});return a.filter((c,l)=>a.findIndex(u=>u.name===c.name)===l)},kp=(e,t,s={})=>{if(t===void 0)return;const n=Op(e,s).filter(o=>!t.has(o.name));if(n.length===0)return;const i=n.map(o=>` - ${o.name} — ${o.reason}`).join(`
|
|
25
|
+
`);throw new _("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
|
|
26
|
+
${i}
|
|
27
|
+
|
|
28
|
+
Install them with your package manager, then re-run codegen.`)},Rp="env.ts",Fp=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(r.isImportSpecifier(s))return Xe(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},Lp=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!r.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(d.ImportDeclaration);return n!==void 0&&Xe(n.getModuleSpecifierValue())}return!1},Dp=e=>{if(r.isIdentifier(e))return Fp(e);if(r.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&r.isIdentifier(t)&&Lp(t)}return!1},Mp=e=>{const t=[];for(const s of e.getVariableDeclarations()){const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!Dp(n.getExpression()))continue;const o=s.getNameNode();if(!r.isIdentifier(o)){if(s.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw le(o,"defineEnv exports must be plain named exports (no destructuring)")}const a=Vt(s,"member");a!==void 0&&t.push({exportName:a})}return t},_p=(e,t)=>{const s=E(t,Rp);if(!M(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=Mp(n);if(i.length!==0){if(i.length>1)throw le(n,`lunora/env.ts declares ${i.length.toString()} defineEnv() contracts (${i.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Kp={defineLiveStream:"liveStreams",defineRoom:"typedWebSockets",defineWebSocket:"socketRoutes"},zp=new Set(["allowedHosts","deniedHosts","interceptHttps"]),$p=(e,t)=>{const s=h(t);if(s===void 0||!r.isIdentifier(s))return s;const n=s.getText();return h(e.getDescendantsOfKind(d.VariableDeclaration).find(i=>i.getName()===n)?.getInitializer())},Bp=(e,t)=>e!==void 0&&r.isObjectLiteralExpression(e)&&e.getProperties().some(s=>{if(r.isShorthandPropertyAssignment(s))return t.has(S(s));if(!r.isPropertyAssignment(s)||!t.has(S(s)))return!1;const n=h(s.getInitializer())?.getText();return n!=="false"&&n!=="undefined"}),Vp=new Set(["durable"]),Up=new Set(["rollback"]),ki=e=>{const t=e.getExpression();return r.isPropertyAccessExpression(t)?t.getName():t.getText()},Wp="defineApp",Ae="app",gn=(e,t)=>e.getDescendantsOfKind(d.PropertyAssignment).some(s=>S(s)===Ae&&s.getInitializer()?.getText()===t)||t===Ae&&e.getDescendantsOfKind(d.ShorthandPropertyAssignment).some(s=>S(s)===Ae),qp=e=>{if(e===void 0||!So.includes(e.getSourceFile().getBaseName()))return!1;if(r.isMethodDeclaration(e))return r.isObjectLiteralExpression(e.getParent())&&S(e)===Ae;if(!(r.isArrowFunction(e)||r.isFunctionExpression(e)||r.isFunctionDeclaration(e)))return!1;const t=e.getParent();if(r.isPropertyAssignment(t))return S(t)===Ae;if(r.isVariableDeclaration(t))return gn(e.getSourceFile(),t.getName());const s=r.isFunctionDeclaration(e)?e.getName():void 0;return s!==void 0&&gn(e.getSourceFile(),s)},jp="AppBuilder",Ri=e=>{const t=e.getSourceFile();return t.getBaseNameWithoutExtension()==="app"&&t.getDirectory().getBaseName()==="_generated"},Hp=e=>{const t=e.getType(),s=(t.getConstraint()??t).getSymbol();return s?.getName()===jp&&s.getDeclarations().some(n=>Ri(n))},Gp=e=>e.getText()===Wp&&(e.getSymbol()?.getDeclarations()??[]).every(t=>r.isImportSpecifier(t)||r.isImportClause(t)||Ri(t)),Fi=(e,t,s=new Set)=>{const n=Ge(t);if(n===void 0||!r.isIdentifier(n))return!1;if(Gp(n))return!0;const i=n.getText();if(s.has(i))return!1;s.add(i);for(const o of n.getAncestors()){if(r.isParametered(o)&&o.getParameters().some(a=>a.getName()===i))return qp(o);if(r.isBlock(o)||r.isSourceFile(o)){const a=o.getVariableStatements().flatMap(c=>c.getDeclarations()).find(c=>c.getName()===i);if(a!==void 0)return Fi(e,a.getInitializer(),s)}}return!1},Li=(e,t)=>{const s=$t(t.getExpression());return s?.member==="deliveryAuthorization"&&(Fi(e,s.object)||Hp(s.object))},Yp=new Map([["defineContainer",{keys:zp,signal:"containerEgressPolicy"}],["defineStep",{keys:Up,signal:"workflowRollback"}],["stream",{keys:Vp,signal:"durableStreams"}]]),Qp=(e,t)=>{const s=Yp.get(ki(t));if(s!==void 0)return t.getArguments().some(n=>Bp($p(e,n),s.keys))?s.signal:void 0},Xp=(e,t)=>Kp[ki(t)]??(Li(e,t)?"deliveryAuthorization":void 0),Jp=(e,t,s)=>{const n={containerEgressPolicy:!1,deliveryAuthorization:!1,durableStreams:!1,liveContext:!1,liveStreams:!1,secrets:!1,socketRoutes:!1,typedWebSockets:!1,workflowRollback:!1};for(const i of A(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);if(!n.secrets||!n.liveContext){const c=Eo(o);n.secrets=n.secrets||c.has("secrets"),n.liveContext=n.liveContext||c.has("live")}const a=o.getDescendantsOfKind(d.CallExpression);for(const c of a){const l=Qp(o,c)??Xp(o,c);l!==void 0&&(n[l]=!0)}if(n.liveStreams=n.liveStreams||o.getFullText().includes("defineLiveStream")&&a.some(c=>Mn(c,"defineLiveStream")),Object.values(n).every(Boolean))break}if(n.typedWebSockets=n.typedWebSockets||n.socketRoutes,!n.deliveryAuthorization&&s!==void 0){const i=e.getSourceFile(s)??e.addSourceFileAtPath(s);n.deliveryAuthorization=i.getDescendantsOfKind(d.CallExpression).some(o=>Li(i,o))}return n},Zp="createWorker",em="extend",pn=e=>e!==void 0&&(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))?e.getLiteralValue():void 0,mn=e=>{const t=[],s=pn(F(e,"backupCron"));s!==void 0&&t.push(s);const n=F(e,"crons");if(n===void 0||!r.isObjectLiteralExpression(n))return t;for(const i of n.getProperties()){if(!r.isPropertyAssignment(i)&&!r.isMethodDeclaration(i))continue;const o=pn(i.getNameNode());o!==void 0&&t.push(o)}return t},tm=e=>{const t=P(e.getExpression()),[s]=e.getArguments();if(s===void 0)return[];if(t===Zp)return r.isObjectLiteralExpression(s)?mn(s):[];if(t!==em||!(r.isArrowFunction(s)||r.isFunctionExpression(s)))return[];const n=In(s.getBody());return n===void 0?[]:mn(n)},sm=(e,t)=>{const s=[];for(const{filePath:n}of He(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of i.getDescendantsOfKind(d.CallExpression))s.push(...tm(o))}return[...new Set(s)]},Di=e=>{if(e.kind==="id")return e.tableName;if(!(e.kind!=="array"&&e.kind!=="optional"))return e.inner===void 0?void 0:Di(e.inner)},nm=e=>{const t=new Set(e.tables.map(s=>s.name));return e.tables.some(s=>Object.values(s.shape).some(n=>{const i=Di(n);return i!==void 0&&t.has(i)}))},im=(e,t)=>{const s=new Map,n=new Map;for(const i of e)s.set(i.name,`workflow "${i.exportName}"`),n.set(i.className,`workflow "${i.exportName}"`);for(const i of t){const o=s.get(i.name);if(o!==void 0)throw new _("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${i.name}": produced by both ${o} and agent "${i.exportName}". Workflow and agent names share one account-wide namespace and must be unique together.`,{status:500});const a=n.get(i.className);if(a!==void 0)throw new _("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${i.className}": produced by both ${a} and agent "${i.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},rm=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:i}=e,o=Gl(s,t),a=_p(s,t),c=ro(s,t),{queues:l,topics:u}=yo(s,t),f=No(n),g=mo(s,t);im(c,g);const p=ho(s,t),v=Po(s,t),$=vo(s,t,c,g),de=sm(s,t),b=Jp(s,t,Ao(n)),B=bo(s,t),U=xo(s,t);U.browser=U.browser||B.usesSandboxBrowser;const k=Pt(n,e.target),R=wo(U,k,{agents:g.length>0,commitOrderedTables:i.tables.some(D=>D.commitOrdered===!0),cronTriggers:$.length>0,crossShardFanout:i.tables.some(D=>Fo(D)),containerEgressPolicy:b.containerEgressPolicy,containerRuntimeScheduling:p.some(D=>D.schedulingPolicy==="durable_object"),containerSandboxTools:p.some(D=>D.sandbox===!0),deliveryAuthorization:b.deliveryAuthorization,durableStreams:b.durableStreams,globalTables:i.tables.some(D=>D.shardMode==="global"),liveContext:b.liveContext,liveStreams:b.liveStreams,typedWebSockets:b.typedWebSockets,queues:l.length>0,relationGraph:nm(i),secrets:b.secrets,services:f.length>0,topics:u.length>0,vectorStore:i.vectorIndexes.length>0,workerLoaders:B.usesSandboxLoader,workflowRollback:b.workflowRollback,workflowSchedules:c.some(D=>D.schedules!==void 0)}),T=R.usage,Q=po(T),X=R.signals.vectorStore!==!1,te=R.signals.services===!1?[]:f,J=Un(n),ue=J??new Set,K=ue.has("lunorash");kp(i,J,{hasVectors:X,scheduler:T.scheduler||$.length>0,storage:T.storage||v.rules.length>0||Object.keys(Wn(i)).length>0,usage:T});const N=M(E(t,"flags.ts")),O=M(E(t,"notify.ts"));return{agents:g,capabilities:Q,containers:p,crons:$,dataModelContent:_o(i),declaredDependencies:J,dependencies:ue,entryCronTriggers:de,env:a,featureUsage:T,hasFlags:N,hasNotify:O,identity:o,platformGate:{...R,diagnostics:[...Io(n,e.target),...R.diagnostics,...Co(k,i.vectorIndexes),...b.liveStreams&&b.deliveryAuthorization?[To(k)]:[],...b.socketRoutes&&b.deliveryAuthorization?[Oo(k)]:[]]},queues:l,serverContent:Do({agents:g,capabilities:Q,containers:p,env:a,hasVectors:X,hasFlags:N,hasNotify:O,identity:o,queues:l,schema:i,services:te,storageRuleBuckets:v.rules.map(D=>D.bucket),topics:u,useUmbrella:K,workflows:c}),services:te,storageRulesMetadata:v,topics:u,usesSandbox:B.usesSandboxBrowser||B.usesSandboxContainer||B.usesSandboxFs,useUmbrella:K,workflows:c}},Mi=(e,t)=>{if(!r.isPropertyAccessExpression(e))return;const s=e.getExpression();if(!r.isPropertyAccessExpression(s))return;const n=s.getExpression();return r.isPropertyAccessExpression(n)&&n.getName()===t?s.getName():void 0},om=e=>{if(!r.isPropertyAccessExpression(e))return!1;const t=e.getExpression();return r.isPropertyAccessExpression(t)&&t.getName()==="scheduler"||r.isIdentifier(t)&&t.getText()==="scheduler"},am=new Map([["publish",{kind:"publish",surface:"topics"}],["publishBatch",{kind:"publish",surface:"topics"}],["send",{kind:"enqueue",surface:"queues"}],["sendBatch",{kind:"enqueue",surface:"queues"}]]),cm=/^[\w$]+:[\w$]+$/u,lm=(e,t)=>{const s=kn(t);return s!==void 0?{kind:"call",target:s}:e!=="run"&&t!==void 0?{kind:"call",reason:'the function reference is not a static api.* / internal.* chain or a "namespace:export" key'}:void 0},hn=e=>{const t=[];for(const s of e.getProperties()){if(!r.isPropertyAssignment(s)&&!r.isShorthandPropertyAssignment(s))return;t.push(s.getName())}return t},dm=e=>{if(e===void 0)return[];if(r.isObjectLiteralExpression(e))return hn(e);if(r.isIdentifier(e)){const t=e.getSymbol()?.getDeclarations()[0];if(r.isVariableDeclaration(t)&&t.getVariableStatement()?.getDeclarationKind()===vr.Const){const s=t.getInitializer();return r.isObjectLiteralExpression(s)?hn(s):void 0}}},um=(e,t,s)=>({schedule:{argKeys:dm(s),...e==="runAfter"&&t!==void 0&&r.isNumericLiteral(t)?{delayMs:t.getLiteralValue()}:{}}}),fm=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return;const s=t.getName(),[n,i,o]=e.getArguments();if(On.has(s))return lm(s,n);if((s==="runAfter"||s==="runAt")&&om(t)){const l=kn(i)??(r.isStringLiteral(i)&&cm.test(i.getLiteralText())?i.getLiteralText():void 0);return l===void 0?{kind:"schedule",reason:'the scheduled function is not a static api.* / internal.* chain or a "namespace:export" key'}:{kind:"schedule",target:l,...um(s,n,o)}}const a=am.get(s),c=a===void 0?void 0:Mi(t,a.surface);return a===void 0||c===void 0?void 0:{kind:a.kind,target:c}},gm=new Set([d.AmpersandAmpersandEqualsToken,d.AmpersandAmpersandToken,d.BarBarEqualsToken,d.BarBarToken,d.QuestionQuestionEqualsToken,d.QuestionQuestionToken]),_i=e=>hr.isOptionalChain(e.compilerNode),pm=(e,t)=>r.isIfStatement(t)?!y(e,t.getExpression()):r.isWhileStatement(t)||r.isForInStatement(t)||r.isForOfStatement(t)?y(e,t.getStatement()):r.isForStatement(t)?y(e,t.getStatement())||y(t.getIncrementor(),e):r.isCaseClause(t)||r.isDefaultClause(t)||r.isCatchClause(t)?!0:re(t)?t.getFirstAncestor(re)!==void 0:r.isConditionalExpression(t)?!y(e,t.getCondition()):r.isBinaryExpression(t)?!y(e,t.getLeft())&&gm.has(t.getOperatorToken().getKind()):(r.isCallExpression(t)||r.isElementAccessExpression(t))&&_i(t)?!y(e,t.getExpression()):r.isBlock(t)&&t.getStatements().some(s=>s.getEnd()<=e.getStart()&&Ig(s)),mm=e=>{let t=e,s=e.getParent();for(;s!==void 0&&(r.isAwaitExpression(s)||r.isParenthesizedExpression(s));)t=s,s=s.getParent();const n=r.isVariableDeclaration(s)||r.isBinaryExpression(s)&&y(t,s.getRight())&&s.getOperatorToken().getKind()===d.EqualsToken,i=e.getFirstAncestor(re);return n||i?.getDescendantsOfKind(d.ThrowStatement).some(o=>o.getStart()>=e.getEnd()&&y(o.getFirstAncestor(re),i))===!0},hm=(e,t)=>(r.isWhileStatement(t)||r.isForInStatement(t)||r.isForOfStatement(t))&&y(e,t.getStatement())||r.isForStatement(t)&&(y(e,t.getStatement())||y(t.getIncrementor(),e)),vm=(e,t)=>{if(_i(e)||t==="schedule"&&mm(e))return"guard";let s=e,n=!1;for(let i=s.getParent();i!==void 0&&!r.isSourceFile(i);i=i.getParent()){if(pm(s,i)){if(!hm(s,i))return"guard";n=!0}s=i}return n?"loop":void 0},vn=(e,t,s)=>{if(s===void 0)return;const n=vm(e,s.kind);return{...s,...n===void 0?{}:{conditional:!0},...n==="loop"?{loopOnly:!0}:{},file:t,line:e.getStartLineNumber(),scope:x(e)}},Em=(e,t)=>[...C(e,t,(s,n)=>vn(s,n,fm(s))),...ne(e,t,d.PropertyAccessExpression,(s,n)=>{const i=Mi(s,"services");return vn(s,n,i===void 0?void 0:{kind:"invoke",target:i})})],xm=new Set(["boolean","number","object","string"]),Sm=e=>{const t=e.getName();if(!xm.has(t))return;const s=e.getExpression();return H(s,["flags"])||H(s,["flags","details"])?t:void 0},Am=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return;const s=Sm(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(r.isStringLiteral(n)||r.isNoSubstitutionTemplateLiteral(n)))return;const i=n.getLiteralValue();return i.length>0?{key:i,type:s}:void 0},ym=(e,t)=>{const s=new Map;for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of i.getDescendantsOfKind(d.CallExpression)){const a=Am(o);a&&!s.has(a.key)&&s.set(a.key,a.type)}}return[...s.entries()].map(([n,i])=>({key:n,type:i})).toSorted((n,i)=>n.key.localeCompare(i.key))},bm=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const s=t.getTypeAtLocation(e).getProperty("types");if(!s)return;const n=s.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!n)return;const i=n.getTypeAtLocation(e),o=i.getText(e);if(!o||o==="any"||o==="never"||Ko(o))return;const a=e.getSourceFile().getFilePath();if(zo(i,e,a)){const c=$o(i,e,a,0,new Set);return c===void 0&&Bo(o),c}return o},Nm=e=>e.getProperties().some(t=>{if(r.isSpreadAssignment(t))return!0;const s=Dr(t.getNameNode());return s===void 0||s==="namespace"}),Pm=(e,t)=>{for(const{filePath:s}of He(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const i of n.getDescendantsOfKind(d.CallExpression)){const o=i.getExpression(),[a]=i.getArguments();if(!(!r.isPropertyAccessExpression(o)||o.getName()!=="auth"||a===void 0)&&(!r.isObjectLiteralExpression(a)||Nm(a)))return i}}},wm="https://lunora.sh/docs/concepts/data-residency#pinning-auth-and-voice",Im=(e,t)=>{if(!(e.jurisdiction===void 0||e.jurisdictionPinsAuth===!0||t===void 0))throw le(t,`the schema pins Durable Objects to the "${e.jurisdiction}" jurisdiction, and this project also has DO-backed auth (users, sessions, accounts, credentials). Pinning the auth object resolves it to a NEW, EMPTY object: existing users stay in the unpinned one until you copy them across (${wm}). Acknowledge with \`.jurisdiction("${e.jurisdiction}", { pinAuth: true })\`, deploy, then run the copy. For D1-mode auth the acknowledgement changes nothing.`,{code:"JURISDICTION_MOVE",status:422})},Cm="room:",Tm="__lunora_socket__:",Om=/^[A-Za-z]\w*$/u,En=e=>Om.test(e),km=e=>`${e}:`.startsWith(Cm)||`${e}:`.startsWith(Tm),Ki=e=>e.getProperties().some(t=>r.isSpreadAssignment(t)||r.isComputedPropertyName(t.getNameNode())),zi=e=>Ki(e)||e.getProperties().some(t=>r.isMethodDeclaration(t)||r.isGetAccessorDeclaration(t)||r.isSetAccessorDeclaration(t)),xn=e=>S(e),ts=(e,t)=>e.getProperties().find(s=>(r.isPropertyAssignment(s)||r.isShorthandPropertyAssignment(s))&&S(s)===t),oe=(e,t)=>{const s=le(e,`defineLiveStream ${t}`);return new _("LIVE_STREAM_NOT_LITERAL",s.message)},$i=(e,t,s)=>{const n=ts(e,t),i=r.isPropertyAssignment(n)?n.getInitializer():void 0;if(i===void 0||!r.isObjectLiteralExpression(i))throw oe(n??e,`needs ${s} so codegen can read its topics`);if(zi(i))throw oe(i,`cannot spread into or compute the keys of \`${t}\`: codegen must read every name as a literal`);return i},Rm=(e,t)=>{const s=xn(t),n=r.isPropertyAssignment(t)?t.getInitializer():void 0;if(n===void 0||!r.isObjectLiteralExpression(n))throw oe(t,`needs an object literal for topic "${s}" ({ key?, payload }), not a reference to one`);if(zi(n))throw oe(n,`cannot spread into or compute the keys of topic "${s}"`);if(!En(s)||km(s))throw new _("LIVE_TOPIC_INVALID",`live stream "${e}": topic name "${s}" must be a plain identifier (letters, digits and "_", starting with a letter) that does not encode into the "room:" or socket topic prefix.`);if(ts(n,"key")===void 0)return{fields:[],name:s};const a=$i(n,"key",`an object literal \`key\` for topic "${s}"`).getProperties().map(l=>xn(l)),c=a.find(l=>!En(l));if(c!==void 0)throw new _("LIVE_TOPIC_INVALID",`live stream "${e}": key field "${s}.${c}" must be a plain identifier (letters, digits and "_", starting with a letter).`);return{fields:a,name:s}},Fm=(e,t,s)=>{const n=e.getArguments()[0];if(n===void 0||!r.isObjectLiteralExpression(n))throw oe(e,"needs an object-literal options argument so codegen can read its `id` and `topics`");if(Ki(n))throw oe(n,"cannot spread its options or use a computed key: codegen must read `id` and `topics` as literals");const i=ts(n,"id"),o=r.isPropertyAssignment(i)?i.getInitializer():void 0;if(o===void 0||!r.isStringLiteral(o))throw oe(i??n,'needs a string-literal `id` (e.g. `defineLiveStream({ id: "posts", … })`) so codegen can type its references');const a=o.getLiteralValue(),c=$i(n,"topics","an object-literal `topics` map");return{exportName:t,filePath:w(s,e.getSourceFile().getFilePath()),id:a,topics:c.getProperties().map(l=>Rm(a,l))}},Lm=e=>{const t=new Map;for(const s of e)for(const[n,i]of[["id",s.id],["export",s.exportName]]){const o=`${n}:${i}`,a=t.get(o);if(a!==void 0)throw new _("LIVE_STREAM_DUPLICATE",`live stream ${n} "${i}" is declared by both lunora/${a}.ts and lunora/${s.filePath}.ts; it must be unique across the app.`);t.set(o,s.filePath)}},Dm=e=>{let t=e.getParent();for(;r.isAsExpression(t)||r.isSatisfiesExpression(t)||r.isNonNullExpression(t)||r.isParenthesizedExpression(t);)t=t.getParent();return t},Mm=(e,t)=>e.getDescendantsOfKind(d.CallExpression).filter(s=>Mn(s,"defineLiveStream")).map(s=>{const n=Dm(s),i=r.isVariableDeclaration(n)?Vt(n,"binding"):void 0;if(i===void 0)throw new _("LIVE_STREAM_NOT_EXPORTED",le(s,"defineLiveStream must be assigned to a named export (`export const posts = defineLiveStream({ … })`), not a default export, a local, or an inline call, so codegen can type its references").message);return Fm(s,i,t)}),_m=(e,t)=>{const s=A(t).flatMap(n=>Mm(e.getSourceFile(n)??e.addSourceFileAtPath(n),t));return Lm(s),s},Km=e=>r.isPropertyAssignment(e)||r.isMethodDeclaration(e)||r.isGetAccessorDeclaration(e)?r.isComputedPropertyName(e.getNameNode()):!1,zm=e=>r.isPropertyAssignment(e)||r.isShorthandPropertyAssignment(e)||r.isMethodDeclaration(e)||r.isGetAccessorDeclaration(e)?Km(e):!0,Bi=(e,t=!1)=>{for(const s of e.getProperties()){if(zm(s))return!0;if(t)continue;if(!r.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!r.isObjectLiteralExpression(n)||Bi(n,!0))return!0}return!1},$m=(e,t)=>{for(const s of A(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:i}of qn(n))for(const o of qt(i)){const a=o.getArguments()[0];if(a!==void 0&&(!r.isObjectLiteralExpression(a)||Bi(a)))return!0}}return!1},Bm=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const i=$e(n);if(i===void 0||!r.isPropertyAssignment(n))continue;const o=n.getInitializer();if(!(!o||!r.isObjectLiteralExpression(o)))for(const a of o.getProperties()){const c=$e(a);c!==void 0&&s.push({column:c,strategy:zn(a),table:i})}}return s},Vm=(e,t)=>{const s=new Map;for(const n of A(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:o}of qn(i))for(const a of qt(o))for(const c of Bm(a)){const l=`${c.table}\0${c.column}`;s.has(l)||s.set(l,c)}}return{columns:[...s.values()]}},Um=["providerSubscriptionId","state"],Wm=["providerEventId","processedAt"],Sn=(e,t)=>t.every(s=>s in e.shape),qm=e=>{const t=e.find(n=>n.name==="payment_subscriptions"),s=e.find(n=>n.name==="payment_events");return t!==void 0&&s!==void 0&&Sn(t,Um)&&Sn(s,Wm)},jm=["account","apikey","member","passkey","session","teamMember","twoFactor","user"],Hm=(e,t)=>{const s={};for(const[n,i]of e)s[n]={dataset:i};for(const[n,i]of t)s[n]={excluded:i};return s},Gm=(e,t)=>{const s=[];for(const n of e){const i=t[n];i===void 0?s.push({code:"unclassified",table:n}):"excluded"in i&&i.excluded.trim()===""&&s.push({code:"excluded_without_reason",table:n})}return s},Ym="@lunora/privacy",Vi="userId",Qm=e=>e.replaceAll("\\","/"),Xm="privacy",Jm=new Set(["actionCacheDataset","authDataset","documentHistoryDataset"]),et=e=>e!==void 0&&(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():void 0,tt=e=>r.isPropertyAssignment(e)?e.getName().replaceAll(/^["']|["']$/gu,""):"",ss=e=>e.getProperties().filter(t=>r.isPropertyAssignment(t)),Zm=(e,t)=>{const s=e.getProperty(t),n=r.isPropertyAssignment(s)?s.getInitializer():void 0;return n!==void 0&&r.isObjectLiteralExpression(n)?n:void 0},st=e=>{const t=e.getExpression();return r.isIdentifier(t)?t.getText():void 0},eh=(e,t)=>{const s=e.getArguments()[1];if(s===void 0||!r.isObjectLiteralExpression(s))return;const n=Zm(s,"tables"),i=et(e.getArguments()[0])??"defineDataset";for(const o of n===void 0?[]:ss(n).map(a=>tt(a)))t.datasets.set(o,i)},th=(e,t)=>{const s=e.getArguments()[0],n=s!==void 0&&r.isObjectLiteralExpression(s)?ss(s):[],i=new Set(n.map(o=>tt(o)));for(const o of jm)i.has(o)||t.datasets.set(o,"authDataset");for(const o of n){const a=r.isPropertyAssignment(o)?et(o.getInitializer()):void 0;a!==void 0&&t.datasets.set(a,"authDataset")}},An=(e,t,s)=>{t.datasets.set(et(e.getArguments()[0])??s,s)},ns=8,Pe=(e,t=0)=>{if(t>ns)return;if(r.isAsExpression(e)||r.isSatisfiesExpression(e)||r.isParenthesizedExpression(e))return Pe(e.getExpression(),t+1);if(!r.isIdentifier(e))return e;const s=e.getSymbol(),n=(s?.isAlias()===!0?s.getAliasedSymbol():s)?.getValueDeclaration(),i=r.isVariableDeclaration(n)?n.getInitializer():void 0;return i===void 0?void 0:Pe(i,t+1)},sh=e=>{if(r.isPropertyAssignment(e)){const t=e.getInitializer();return t===void 0?void 0:[tt(e),t]}if(r.isShorthandPropertyAssignment(e)){const t=e.getValueSymbol(),s=(t?.isAlias()===!0?t.getAliasedSymbol():t)?.getValueDeclaration(),n=r.isVariableDeclaration(s)?s.getInitializer():void 0;return[e.getName(),n??e.getNameNode()]}},Ui=(e,t=0)=>{const s=Pe(e,t);if(s===void 0||!r.isObjectLiteralExpression(s)||t>ns)return;const n=new Map;for(const i of s.getProperties()){const o=r.isSpreadAssignment(i)?Ui(i.getExpression(),t+1):[sh(i)];if(o===void 0)return;for(const a of o)a!==void 0&&n.set(a[0],a[1])}return n},nh=e=>{const t=e.getArguments()[0];return t===void 0?void 0:Ui(t)},ih=(e,t)=>{const s=e?.get("exclude"),n=s===void 0?void 0:Pe(s);for(const i of n!==void 0&&r.isObjectLiteralExpression(n)?ss(n):[])t.excluded.set(tt(i),r.isPropertyAssignment(i)?et(i.getInitializer())??"":"")},rh=(e,t)=>{switch(st(e)){case"actionCacheDataset":{An(e,t,"actionCache");break}case"authDataset":{th(e,t);break}case"defineDataset":{eh(e,t);break}case"documentHistoryDataset":{An(e,t,"documentHistory");break}}},is=e=>e!==void 0&&r.isCallExpression(e)&&st(e)==="defineDataset",Wi=e=>e!==void 0&&r.isCallExpression(e)&&Jm.has(st(e)??""),oh=e=>{const t=e.getSymbol(),n=(t?.isAlias()===!0?t.getAliasedSymbol():t)?.getValueDeclaration(),i=r.isVariableDeclaration(n)?n.getInitializer():void 0;return r.isVariableDeclaration(n)&&(is(i)||Wi(i))?n:void 0},qi=(e,t,s=0)=>{const n=Pe(e,s);if(n===void 0||!r.isArrayLiteralExpression(n)||s>ns)return!1;for(const i of n.getElements())if(r.isSpreadElement(i)){if(!qi(i.getExpression(),t,s+1))return!1}else if(!is(i)&&!Wi(i)){const o=r.isIdentifier(i)?oh(i):void 0;if(o===void 0)return!1;t.add(o)}return!0},ah=e=>{if(e===void 0)return;const t=e.get("datasets"),s=new Set;return t===void 0||qi(t,s)?s:void 0},ch=(e,t)=>{const s=[];for(const i of e.getDescendantsOfKind(d.CallExpression))if(rh(i,t),st(i)==="definePrivacy"){const o=nh(i);ih(o,t),s.push({location:`${e.getFilePath()}:${String(i.getStartLineNumber())}`,passed:ah(o)})}return{declared:e.getDescendantsOfKind(d.VariableDeclaration).filter(i=>is(i.getInitializer())).map(i=>({declaration:i,name:i.getName()})),privacyCalls:s}},lh=(e,t)=>{const s=E(t,"schema.ts"),n=[...A(t),...M(s)?[s]:[]];for(const o of n)e.getSourceFile(o)===void 0&&e.addSourceFileAtPath(o);const i=new Set(n.map(o=>Qm(o)));return e.getSourceFiles().filter(o=>i.has(o.getFilePath()))},dh=(e,t,s)=>{if(s?.has(Ym)!==!0)return{classifications:{},enabled:!1,unusedDatasets:[]};const n={datasets:new Map,excluded:new Map},i=[],o=[];for(const f of lh(e,t)){const g=ch(f,n);i.push(...g.declared),o.push(...g.privacyCalls)}const a=new Set;for(const f of o){for(const g of f.passed??[])a.add(g);f.passed===void 0&&console.warn(`@lunora/codegen: privacy_datasets_unresolved: the definePrivacy call at ${f.location} passes datasets codegen cannot read, so a defineDataset it leaves out is not reported. Pass an array of dataset constants, directly or through a spread of a config object literal.`)}const l=o.every(f=>f.passed!==void 0)?i.filter(f=>!a.has(f.declaration)).map(f=>f.name):[];return{classifications:Hm(n.datasets,n.excluded),enabled:o.length>0,unusedDatasets:l}},uh=e=>e.extensionKey!==Xm&&Vi in e.shape,fh=e=>e.code==="excluded_without_reason"?`privacy_exclusion_unexplained: "${e.table}" is excluded without a reason. Give one in definePrivacy({ exclude }).`:`privacy_table_unclassified: "${e.table}" holds user data (it has a "${Vi}" column) but no dataset exports it. Add it to a defineDataset, or exclude it in definePrivacy({ exclude }) with a reason.`,gh=(e,t)=>{if(!t.enabled)return;const s=e.filter(o=>uh(o)).map(o=>o.name),[n]=Gm(s,t.classifications);if(n!==void 0)throw new _("PRIVACY_COVERAGE",fh(n));const[i]=t.unusedDatasets;if(i!==void 0)throw new _("PRIVACY_COVERAGE",`privacy_dataset_unused: "${i}" is declared with defineDataset but never passed to definePrivacy({ datasets }). Pass it, or delete it.`)},ph=(e,t)=>{const s=ko(t.target);return{...s===void 0?{}:{platform:s},analytics:e.analytics||t.dependencies.has("@lunora/bindings"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,privacy:t.dependencies.has("@lunora/privacy"),queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:t.vectorStoreSupported&&t.vectorIndexCount>0,workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}},mh=new Set(["delete","hardDelete","patch","replace","restore"]),hh=new Set(["insertMany","insertManyUnsafe","patchIf","patchWhere"]),vh=new Set(["delete","deleteMany","hardDelete","insert","insertMany","patch","patchMany","replace","restore","upsert","upsertMany"]),yn=(e,t)=>{const s=e.getNonNullableType().getProperty("__table")?.getTypeAtLocation(t);if(s===void 0)return[];const n=s.isUnion()?s.getUnionTypes():[s],i=n.map(o=>o.getLiteralValue()).filter(o=>typeof o=="string");return i.length===n.length?i:[]},Eh=(e,t)=>{const s=e.getType();if(t==="deleteMany"||t==="patchMany"){const n=s.getArrayElementType();if(n===void 0)return[];const i=t==="patchMany"?n.getProperty("id")?.getTypeAtLocation(e):n;return i===void 0?[]:yn(i,e)}return yn(s,e)},bn="",xh=(e,t)=>{if(t!=="patch"&&t!=="patchMany")return;const s=e.getArguments()[1];if(s===void 0||!r.isObjectLiteralExpression(s))return;const n=[];for(const i of s.getProperties()){if(!r.isPropertyAssignment(i)&&!r.isShorthandPropertyAssignment(i))return;n.push(i.getName())}return n},Sh=(e,t)=>{if(hh.has(e))return{method:e,tables:[t!==void 0&&r.isStringLiteral(t)?t.getLiteralText():bn]};if(mh.has(e)||e==="deleteMany"||e==="patchMany"){const s=t===void 0?[]:Eh(t,e);return{method:e,tables:s.length===0?[bn]:s}}},Nn=(e,t)=>e===void 0?void 0:{...e,fields:xh(t,e.method)},Ah=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression();if(z(n))return Nn(Sh(s,e.getArguments()[0]),e);if(vh.has(s)&&r.isPropertyAccessExpression(n)&&z(n.getExpression()))return Nn({method:s,tables:[n.getName()]},e)},yh=(e,t)=>C(e,t,(s,n)=>{const i=Ah(s);if(i===void 0)return;const o=x(s),a=s.getStartLineNumber();return i.tables.map(c=>({...i.fields===void 0?{}:{fields:i.fields},file:n,line:a,method:i.method,scope:o,table:c}))}),bh=(e,t,s)=>({cacheKey:`procedure_arguments_unreadable:${e}:${t}`,categories:["SCHEMA"],description:"Codegen reads an argument record statically. One built at runtime — a factory call, or a property off a value it cannot follow — has no literal to read, so the generated `FunctionReference` carries only the arguments it could see while the runtime validator still enforces all of them.",detail:`\`${t}\` in \`${e}\` (line ${s.toString()}) declares arguments codegen could not read, so its generated type is missing some of them.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:s},name:"procedure_arguments_unreadable",remediation:`Declare the arguments as an object literal, or as a \`const\` object literal the chain names — \`const ${t}Args = { … };\` then \`.input(${t}Args)\`. Both resolve; a record returned by a call does not.`,title:"Procedure arguments are missing from the generated type"}),Nh=(e,t)=>{if(t===void 0){const s=e.getArguments()[0];if(s===void 0||!r.isObjectLiteralExpression(s)||V(s,"args")===void 0)return!1}return Gt(e,t).opaque},Ph=(e,t)=>{const s=[],n=(i,o)=>{const a=i.getInitializer();if(a===void 0||!r.isCallExpression(a))return;const c=ee(a);c!==void 0&&Nh(a,c.receiver)&&s.push(bh(t,o,a.getStartLineNumber()))};for(const i of e.getVariableStatements().filter(o=>o.isExported()))for(const o of i.getDeclarations())n(o,o.getName());return s},wh=(e,t)=>{const s=[];for(const n of A(t)){const i=e.getSourceFile(n);i!==void 0&&s.push(...Ph(i,w(t,n)))}return s.toSorted((n,i)=>n.cacheKey.localeCompare(i.cacheKey))},Ih=new Map([["AgentDefinition",{call:"defineAgent({ … })",file:"agents"}],["ContainerDefinition",{call:"defineContainer({ … })",file:"containers"}],["QueueDefinition",{call:"defineQueue({ … })",file:"queues",note:"A dropped queue has no caller to fail — its consumer is simply never wired."}],["RegisteredAction",{call:"action.input({ … }).action(handler)"}],["RegisteredLifecycleHook",{call:"onConnect(handler)",note:"Substitute the hook you called: `onConnect`, `onDisconnect` and `onShardInit` share one type, so codegen cannot tell which you wrote. A dropped hook has no caller to fail — it silently never fires."}],["RegisteredMigration",{call:"defineMigration({ … })",note:"A dropped migration never runs, so `lunora migrate up` reports nothing to do."}],["RegisteredMutation",{call:"mutation.input({ … }).mutation(handler)"}],["RegisteredMutator",{call:"defineMutator({ … })",file:"mutators"}],["RegisteredQuery",{call:"query.input({ … }).query(handler)"}],["RegisteredReactor",{call:"onQueryChange(select, handler)",note:"A dropped reactor has no caller to fail — it silently never runs."}],["RegisteredRoom",{call:"defineRoom({ … })",note:"A dropped room has no caller to fail — its whisper topic is never wired to a handler, so joins, messages and broadcasts are silently ignored."}],["RegisteredShape",{call:"defineShape({ … })",file:"shapes"}],["RegisteredStream",{call:"query.input({ … }).stream(handler)"}],["RegisteredWebSocket",{call:"defineWebSocket({ … })",note:"A dropped socket route has no caller to fail — its path is never recognised as an upgrade route, so connections fall through to the app router and the handler never runs."}],["RegisteredWhisperAuthorizer",{call:"onWhisper(handler)",note:"A dropped authorizer has no caller to fail — the whisper topics it was meant to gate silently stay open to every socket on the shard."}],["SubscriptionDefinition",{call:"defineSubscription(topic, { … })",file:"queues",note:"A dropped subscription is never published to — its topic's messages simply never reach it."}],["WorkflowDefinition",{call:"defineWorkflow({ … })",file:"workflows"}]]),je=({byName:e,byPath:t},s,n)=>t.has(`${s}:${n}`)||e.has(n),ji=e=>!e.isAny(),Hi=e=>{const t=e.getType();if(!ji(t))return;const s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName(),n=s===void 0?void 0:Ih.get(s);return n===void 0||s===void 0?void 0:{...n,typeName:s}},Ch=e=>{const t=e.getInitializer();return t===void 0?!1:r.isCallExpression(t)||r.isIdentifier(t)||r.isPropertyAccessExpression(t)},Gi={cause:"codegen recognises a registration only when the initializer is the registering call itself, and this one comes from a factory or an alias",remediation:"A factory that returns a registration cannot be read statically — inline it, or export what the factory builds."},Th=e=>({cause:`codegen reads this kind of registration only from \`lunora/${e}.ts\`, and this is a different module`,remediation:`Move it into \`lunora/${e}.ts\` — the declaration itself is fine.`}),Oh={cause:"it is exported only under a string name that is not an identifier, which the generated `api.ts` and dispatch table cannot address as `<module>.<name>`",remediation:"Export it under an identifier name as well (or instead)."},kh=new Set(["AgentDefinition","ContainerDefinition","QueueDefinition","RegisteredShape","SubscriptionDefinition","WorkflowDefinition"]),Rh={cause:"it is exported only as `default` or under a reserved word, and this kind's name becomes an import binding and a generated class / binding name, where that is a syntax error",remediation:"Export it under a plain identifier: `export const <name> = …` (an extra `export default <name>` is fine)."},Fh=(e,t,s)=>{if(!t.some(i=>Ir(i)))return Oh;const n=e.getVariableStatement()?.hasExportKeyword()===!0;return kh.has(s.typeName)&&!n&&!t.some(i=>Jo(i))?Rh:Gi},Yi=(e,t,s,n,i)=>{const{call:o,file:a,note:c,typeName:l}=s,u=a!==void 0&&e!==a?a:void 0,f=u===void 0?i:Th(u),g=c===void 0?f.remediation:`${c} ${f.remediation}`;return{cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when its initializer is literally the registering call and the module exports it under an identifier name — by the `export` keyword, a local `export { … }`, or `export default`. Written any other way it exists at runtime but never reaches the generated output — `_generated/api.ts` for a procedure, the lifecycle manifest for a hook or reactor — so a caller cannot address it and a hook never fires.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${l}\` but was not registered — ${f.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:l},name:"procedure_not_registered",remediation:u===void 0?`Assign the registration directly: \`export const ${t} = ${o};\`. ${g}`:g,title:"Procedure exists at runtime but is missing from the generated API"}},Lh=(e,t,s)=>{const n=[];for(const i of Y(e)){const o=r.isIdentifier(i.getNameNode())?Nt(i):[i.getName()],c=o.some(u=>je(s,t,u))||!Ch(i)?void 0:Hi(i),[l=i.getName()]=o;c!==void 0&&n.push(Yi(t,l,c,i.getStartLineNumber(),Fh(i,o,c)))}return n},Dh=(e,t,s)=>{if(je(s,t,"default"))return[];const n=[];for(const i of e.getExportAssignments().filter(o=>!o.isExportEquals()&&!r.isIdentifier(o.getExpression()))){const o=Hi(i.getExpression());o!==void 0&&n.push(Yi(t,"default",o,i.getStartLineNumber(),Gi))}return n},Mh=(e,t,s)=>[...Lh(e,t,s),...Dh(e,t,s)],_h=(e,t,s)=>e.getVariableStatements().flatMap(n=>n.getDeclarations()).filter(n=>r.isIdentifier(n.getNameNode())).filter(n=>Nt(n).some(i=>je(s,t,i))).filter(n=>{const i=n.getInitializer();return i!==void 0&&r.isCallExpression(i)&&r.isPropertyAccessExpression(i.getExpression())}).map(n=>{const i=Nt(n).find(o=>je(s,t,o))??n.getName();return{declaration:n,exportName:i,relativePath:t}}),Kh=({exportName:e,relativePath:t})=>({cacheKey:"procedure_type_check_unavailable",categories:["SCHEMA"],description:"Codegen cross-checks every export in `lunora/` against its TYPE to catch a procedure the syntactic scan dropped — a factory-assigned export, an alias, a separate `export { … }`. That check needs the type checker to resolve `@lunora/server`; when it cannot, the check reports nothing regardless of what the code does.",detail:`Type resolution for \`lunora/\` is unavailable — the registered procedure \`${e}\` in \`${t}\` types as \`any\`, as does every other one — so codegen cannot tell you when an export is dropped from \`_generated/api.ts\`. A dropped procedure will surface as \`Property '<name>' does not exist\` at its call site instead.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e,filePath:t},name:"procedure_type_check_unavailable",remediation:`Check what codegen sees: \`${e}\` should have a procedure type, not \`any\`. It needs a \`tsconfig.json\` at or above \`lunora/\` — the one codegen finds walking up from there, which is not necessarily the one your editor uses — resolving \`lunorash\` / \`@lunora/server\` to declarations that exist on disk (a workspace dependency has to be built first).`,title:"Codegen cannot type-check `lunora/`, so dropped procedures go unreported"}),zh=(e,t,s)=>{const n=[],i=[];for(const a of A(t)){const c=e.getSourceFile(a);if(c===void 0)continue;const l=w(t,a);n.push(...Mh(c,l,s)),i.push(..._h(c,l,s))}const[o]=i;return o!==void 0&&i.every(({declaration:a})=>!ji(a.getType()))&&n.push(Kh(o)),n.toSorted((a,c)=>a.cacheKey.localeCompare(c.cacheKey))},$h=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return r.isPropertyAccessExpression(s)?s.getName()==="workflows":r.isIdentifier(s)&&s.getText()==="workflows"},Bh=e=>{const t=e.getArguments()[0];return t&&r.isStringLiteral(t)?t.getLiteralText():""},Vh=(e,t)=>C(e,t,(s,n)=>$h(s)?{file:n,line:s.getStartLineNumber(),scope:x(s),workflow:Bh(s)}:void 0),we=(e,t)=>{M(e)&&ur(e,"utf8")===t||fr(e,t,"utf8")},Uh=(e,t)=>{if(t===""){ye(e,{force:!0});return}we(e,t)},Wh=(e,t)=>{const s=E(e,"services");if(Object.keys(t).length===0){ye(s,{force:!0,recursive:!0});return}if(M(s))for(const n of Pn(s,{recursive:!0,withFileTypes:!0})){const i=E(n.parentPath,n.name);n.isFile()&&t[wn(e,i)]===void 0&&ye(i)}for(const[n,i]of Object.entries(t))Kt(zt(E(e,n)),{recursive:!0}),we(E(e,n),i)},qh=(e,t,s)=>{const n=E(e,t);if(Object.keys(s).length===0){ye(n,{force:!0,recursive:!0});return}if(M(n))for(const i of Pn(n,{recursive:!0,withFileTypes:!0})){const o=E(i.parentPath,i.name);i.isFile()&&s[wn(n,o)]===void 0&&ye(o)}for(const[i,o]of Object.entries(s)){const a=E(n,i);Kt(zt(a),{recursive:!0}),we(a,o)}},jh=e=>{try{const t=ea(E(e,"package.json"));return typeof t.version=="string"&&t.version!==""?t.version:void 0}catch{return}},ze=(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)},Hh=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,Gh=(e,t)=>{M(e)||Kt(e,{recursive:!0});const s=[];for(const n of t)switch(n.kind){case"always":{we(E(e,n.name),n.content),s.push(n.name);break}case"directory":{qh(e,n.name,n.files),s.push(...Object.keys(n.files).map(i=>E(n.name,i)));break}case"services":{Wh(e,n.files),s.push(...Object.keys(n.files));break}default:Uh(E(e,n.name),n.content),n.content!==""&&s.push(n.name)}return s},Yh=e=>{const t=jh(e.projectRoot),s=e.wantsArchitecture?e.modules:[],n=sa({functions:e.functions,httpRoutes:e.httpRoutes,modules:s,version:t}),i=ia({functions:e.functions,modules:s,version:t});return{openApiContent:`${JSON.stringify(n,void 0,2)}
|
|
29
|
+
`,openApiModuleContent:na(n),openRpcContent:`${JSON.stringify(i,void 0,2)}
|
|
30
|
+
`,openRpcModuleContent:ra(i)}},Qh=".lunora-schema.json",Xh=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Jh=(e,t,s)=>{if(s&&e.length>0){const o=e.map(a=>`"${a.exportName}"`).join(", ");throw new _("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${o}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const o of t.columns){const a=n.get(o.table)??[];a.push(o.column),n.set(o.table,a)}const i=t.columns.length>0;for(const o of e){if(o.table===void 0){if(i)throw new _("MASK_UNSUPPORTED",`defineShape "${o.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${o.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(o.table);if(a===void 0)continue;const c=a.map(l=>`"${l}"`).join(", ");throw new _("MASK_UNSUPPORTED",`defineShape "${o.exportName}" replicates table "${o.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},Zh=8,ev=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,internalPath:i,lazyFunctions:o,lunoraDirectory:a,migrations:c,project:l,roomsSupported:u,shapes:f,usesSandbox:g,useUmbrella:p,workflows:v}=e,$=()=>Uo(()=>{const k=Wo(l,a,{lazyFunctions:o}),R=qr(l,a);return{functions:k,httpRoutes:qo(l,a),mutators:R}});let{erased:de,value:{functions:b,httpRoutes:B,mutators:U}}=$();fn([...b,...U].map(k=>k.filePath)),fn(B.filter(k=>k.stream).map(k=>k.filePath),"http-stream");for(let k=1;;k+=1){const R=u?b:b.filter(N=>N.channel?.kind!=="room"&&N.lifecycle!=="socket"),T=ga({agents:t,functions:R,httpRoutes:B,mutators:U,useUmbrella:p,workflows:v}),Q={agents:t,functions:R,lazyFunctions:o,migrations:c,mutators:U,shapes:f,useUmbrella:p,usesSandbox:g},X=ya(Q),te=ba(Q),J=pa({functions:b,useUmbrella:p}),ue=E(a,"_generated",jn),K=[[s,T],[i,J],[n,X],...Object.entries(te).map(([N,O])=>[E(ue,N),O])];if(k>=Zh||K.every(([N,O])=>Hh(l,N,O)))return{apiContent:T,erased:de,functions:b,functionModulesContent:te,functionsContent:X,httpRoutes:B,internalContent:J,mutators:U};for(const[N,O]of K)ze(l,N,O);({erased:de,value:{functions:b,httpRoutes:B,mutators:U}}=$())}},vE=e=>{const t=Xh(),s=t?gt.now():0,n=E(e.projectRoot,e.lunoraDirectory??"lunora"),i=e.lazyFunctions===!0,o=E(n,"schema.ts");if(!M(o))throw new _("INTERNAL",`schema.ts not found at ${o}`);const a=e.project??fo(n);Kr(bm);const c=Qo(a,o,e.projectRoot);gh(c.tables,dh(a,n,Un(e.projectRoot)));const{agents:l,capabilities:u,containers:f,crons:g,dataModelContent:p,dependencies:v,entryCronTriggers:$,env:de,featureUsage:b,hasFlags:B,hasNotify:U,identity:k,platformGate:R,queues:T,serverContent:Q,services:X,storageRulesMetadata:te,topics:J,usesSandbox:ue,useUmbrella:K,workflows:N}=rm({lunoraDirectory:n,project:a,projectRoot:e.projectRoot,schema:c,target:e.target});Im(c,c.jurisdiction===void 0?void 0:Pm(a,n));const O=E(n,"_generated"),D=E(O,"dataModel.ts"),Qi=E(O,"server.ts"),Xi=E(O,"api.ts"),Ji=E(O,"internal.ts"),Zi=E(O,"functions.ts");ze(a,D,p),ze(a,Qi,Q);const rs=Object.fromEntries(X.filter(m=>m.rpcEntrypoint!==void 0).flatMap(m=>Object.entries(Mo(m,O))));for(const[m,ft]of Object.entries(rs))ze(a,E(O,m),ft);const Ie=Ho(a,n),fe=Xo(a,n),nt=R.signals.typedWebSockets!==!1,{apiContent:os,erased:er,functions:se,functionModulesContent:as,functionsContent:cs,httpRoutes:it,internalContent:ls,mutators:rt}=ev({agents:l,apiPath:Xi,generatedFunctionsPath:Zi,internalPath:Ji,lazyFunctions:i,roomsSupported:nt,lunoraDirectory:n,migrations:Ie,project:a,shapes:fe,useUmbrella:K,usesSandbox:ue,workflows:N}),ds=so(a,n),ot=no(ds,c,[...se,...it].map(m=>m.filePath)),Ce=ds.length>0,Te=e.lint===!1&&!Ce?void 0:{callEdges:Em(a,n),inserts:jo(a,n),queries:Go(a,n,se),tableWrites:yh(a,n),workflowCalls:Vh(a,n)},Oe=e.lint===!1||Te===void 0?void 0:op(a,n,{callSites:Te,containers:f,crons:g,functions:se,modules:ot,mutators:rt,queues:T,schema:c,shapes:fe,workflows:N,wranglerVariables:e.wranglerVariables}),us=Oe===void 0?[]:gp(e.projectRoot,[...gr(Oe,{source:"static"}),...zh(a,n,{byName:new Set([...N,...T,...l,...f].map(m=>m.exportName)),byPath:new Set([...se,...rt,...fe,...Ie].map(m=>`${m.filePath}:${m.exportName}`))}),...wh(a,n),...Vo(er,n),...oa(T,e.wranglerQueueProducers)]),tr=Yo(a,n),fs=Vm(a,n);Jh(fe,fs,$m(a,n));const sr=B?ym(a,n):[],at=R.signals.vectorStore!==!1,nr=Ro(Pt(e.projectRoot,e.target),"deliveryAuthorization"),me=ph(b,{containerCount:f.length,cronCount:g.length,dependencies:v,hasPaymentTables:qm(c.tables),queueCount:T.length,storageColumnCount:Object.keys(Wn(c)).length,storageRuleCount:te.rules.length,vectorIndexCount:c.vectorIndexes.length,target:Pt(e.projectRoot,e.target),vectorStoreSupported:at,workflowCount:N.length}),gs=t?gt.now():0,ct=ta(c,Ie.map(m=>m.id)),ps=_m(a,n),ms=Lo({advisories:us.filter(m=>m.name!=="procedure_type_check_unavailable"),advisorProcedures:Oe?.procedureProtections??[],agents:l,capabilities:u,containers:f,env:de,flagKeys:sr,hasFlags:B,hasNotify:U,hasRooms:nt&&se.some(m=>m.channel?.kind==="room"),hasSockets:nt&&se.some(m=>m.lifecycle==="socket"),lazyFunctions:i,hasVectors:at,liveStreamDeclarations:ps,liveStreams:R.signals.liveStreams===!0,maskMetadata:fs,mutators:rt,queues:T,rlsMetadata:tr,schema:c,schemaSnapshot:ct,shapes:fe,services:X,storageRules:te,studioFeatures:me,topics:J,useUmbrella:K,workflows:N}),hs=ua(fe,v.has("@lunora/db"),K),vs=aa(f,c.jurisdiction),Es=ca(N),xs=la(l),Ss=da(T,e.wranglerQueueProducers),As=Na(ps,K),ys=ma(g),ir=ha(me.scheduler),rr=va(c.tables,K),or=Mr(e.projectRoot)?Ea(K):"",bs=xa(c.vectorIndexes),ke=Aa(c,K),Ns=fa(v.has("@lunora/seed")),Re=e.apiSpec??"openapi",lt=Re==="openapi"||Re==="both",dt=Re==="openrpc"||Re==="both",Ps=Zo({capabilities:u,emailAgents:l.filter(m=>m.onEmail===!0).map(m=>({className:m.className,exportName:m.exportName})),hasAccess:v.has("@lunora/cloudflare-access"),hasAuth:v.has("@lunora/auth"),hasFramework:v.has("@lunora/astro")||v.has("@lunora/svelte")||v.has("@lunora/vue")||M(E(e.projectRoot,"src","worker.ts")),hasGlobal:c.tables.some(m=>Bn(m)),hasHyperdriveGlobal:c.tables.some(m=>Vn(m)),hasKvIntrospector:me.kv,hasNotify:U,hasQueue:T.some(m=>m.mode==="push"),liveStreams:R.signals.liveStreams===!0,liveStreamsWithheld:R.liveStreamsWithheld,hasScheduler:me.scheduler,hasSourcedTables:c.tables.some(m=>m.externalSource!==void 0),hasStorage:me.storage,hasDeliveryAuthorization:nr,hasVectors:at,hasWorkflow:N.length>0,identity:k,jurisdiction:c.jurisdiction,jurisdictionPinsAuth:c.jurisdictionPinsAuth===!0,tables:c.tables.map(m=>({name:m.name,shardMode:m.shardMode})),useUmbrella:K,vectorIndexCount:c.vectorIndexes.length,voiceAgents:l.filter(m=>m.voice===!0&&m.voiceBindingName!==void 0).map(m=>({bindingName:m.voiceBindingName,exportName:m.exportName})),wantsArchitecture:Ce,wantsOpenApi:lt,wantsOpenRpc:dt}),{openApiContent:ws,openApiModuleContent:Is,openRpcContent:Cs,openRpcModuleContent:Ts}=Yh({functions:se,httpRoutes:it,modules:ot,projectRoot:e.projectRoot,wantsArchitecture:Ce}),he=Ce&&Te!==void 0?Cp({...Te,crons:g,functions:se,httpRoutes:it,modules:ot,queues:T,schema:c,services:X,topics:J,workflows:N}):void 0,ut=E(n,Qh),ar=M(ut),cr=e.dryRun?[]:Gh(O,[{content:Ps,kind:"always",name:"app.ts"},{content:p,kind:"always",name:"dataModel.ts"},{content:os,kind:"always",name:"api.ts"},{content:ls,kind:"always",name:"internal.ts"},{content:Q,kind:"always",name:"server.ts"},{content:cs,kind:"always",name:"functions.ts"},{files:as,kind:"directory",name:jn},{content:ms,kind:"always",name:"shard.ts"},{content:ys,kind:"always",name:"crons.ts"},{content:bs,kind:"always",name:"vectors.ts"},{content:ke.global,kind:"always",name:"drizzle.global.ts"},{content:ke.shard,kind:"always",name:"drizzle.shard.ts"},{content:vs,kind:"optional",name:"containers.ts"},{content:Es,kind:"optional",name:"workflows.ts"},{content:xs,kind:"optional",name:"agents.ts"},{content:Ss,kind:"optional",name:"queues.ts"},{content:As,kind:"optional",name:"live.ts"},{content:ir,kind:"optional",name:"scheduler.ts"},{content:rr,kind:"optional",name:"shardRegistry.ts"},{content:or,kind:"optional",name:"durableObjects.ts"},{content:Ns,kind:"optional",name:"seed.ts"},{content:hs,kind:"optional",name:"collections.ts"},{files:rs,kind:"services"},{content:lt?ws:"",kind:"optional",name:"openapi.json"},{content:lt?Is:"",kind:"optional",name:"openapi.ts"},{content:dt?Cs:"",kind:"optional",name:"openrpc.json"},{content:dt?Ts:"",kind:"optional",name:"openrpc.ts"},{content:he===void 0?"":`${JSON.stringify(he,void 0,2)}
|
|
31
|
+
`,kind:"optional",name:"architecture.json"},{content:he===void 0?"":Tp(he),kind:"optional",name:"architecture.ts"}]);if(!e.dryRun&&(!ar||e.updateSchemaBaseline===!0)&&we(ut,pr(ct)),t){const m=gt.now(),ft=Math.round(m-s),lr=Math.round(gs-s),dr=Math.round(m-gs);console.error(`@lunora/codegen: codegen took ${ft.toString()}ms (discovery ${lr.toString()}ms, emit ${dr.toString()}ms)`)}return{advisories:us,advisorContext:Oe,agents:l,architecture:he,containers:f,cronTriggers:[...new Set([...Sa(g),...$])],generated:{agents:xs,api:os,app:Ps,collections:hs,containers:vs,crons:ys,dataModel:p,drizzleGlobal:ke.global,drizzleShard:ke.shard,functionModules:as,functions:cs,internal:ls,live:As,openApi:ws,openApiModule:Is,openRpc:Cs,openRpcModule:Ts,queues:Ss,seed:Ns,server:Q,shard:ms,vectors:bs,workflows:Es},migrations:Ie,outputDirectory:O,platformDiagnostics:R.diagnostics,queues:T,schemaSnapshot:ct,schemaSnapshotPath:ut,workflows:N,writtenFiles:cr}};export{Qh as SCHEMA_SNAPSHOT_FILENAME,fo as createCodegenProject,SE as findTsconfig,AE as refreshCodegenProject,vE as runCodegen};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as m}from"node:fs";import{join as u}from"node:path";import{SyntaxKind as p,Node as o}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{
|
|
1
|
+
import{existsSync as m}from"node:fs";import{join as u}from"node:path";import{SyntaxKind as p,Node as o}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as f}from"./module-specifiers-BctA0m_p.mjs";import{p as d}from"./parse-validator-IDBKIT7M.mjs";import{findObjectProperty as l}from"./isTestPath-B81lOULB.mjs";import{a as S}from"./attribution-hVBriwzy.mjs";const h="shapes.ts",x=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineShape";for(const e of t.getDeclarations())if(o.isImportSpecifier(e))return f(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineShape":!1;return!1},b=r=>{const t=r.getSymbol();if(!t)return!1;for(const e of t.getDeclarations()){if(!o.isNamespaceImport(e))continue;const i=e.getFirstAncestorByKind(p.ImportDeclaration);return i!==void 0&&f(i.getModuleSpecifierValue())}return!1},y=r=>{if(o.isIdentifier(r))return x(r);if(o.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineShape"&&o.isIdentifier(t)&&b(t)}return!1},N=r=>{const[t]=r.getArguments();if(!t||!o.isObjectLiteralExpression(t))return;const e=l(t,"table");if(!e||!o.isPropertyAssignment(e))return;const i=e.getInitializer();return i&&o.isStringLiteral(i)?i.getLiteralValue():void 0},E=r=>{const[t]=r.getArguments();if(!t||!o.isObjectLiteralExpression(t))return{};const e=l(t,"args");if(!e||!o.isPropertyAssignment(e))return{};const i=e.getInitializer();return!i||!o.isObjectLiteralExpression(i)?{}:d(i)},I=r=>{const t=[];for(const e of r.getVariableDeclarations()){const i=e.getInitializer();if(i?.getKind()!==p.CallExpression)continue;const s=i,a=s.getExpression();if(!y(a))continue;const n=e.getNameNode();if(!o.isIdentifier(n)){if(e.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw g(n,"defineShape exports must be plain named exports (no destructuring)")}const c=S(e,"binding");c!==void 0&&t.push({args:E(s),exportName:c,filePath:"shapes",table:N(s)})}return t},z=(r,t)=>{const e=u(t,h);if(!m(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),s=I(i);return s.sort((a,n)=>a.exportName.localeCompare(n.exportName)),s};export{h as SHAPES_FILENAME,z as discoverShapes};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{w as a}from"./classify-procedure-call-Bw5sia-K.mjs";const l=s=>a(s,"use","rls");export{l as r};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as o,VariableDeclarationKind as S,SyntaxKind as b}from"ts-morph";import{a as y,b as c}from"./module-specifiers-BctA0m_p.mjs";import{unwrapExpression as l}from"./isTestPath-B81lOULB.mjs";const U=e=>o.isIdentifier(e)?e.getText():o.isPropertyAccessExpression(e)?e.getName():void 0,h=(e,t,r=c)=>{const i=new Set;for(const n of e.getImportDeclarations())if(r(n.getModuleSpecifierValue()))for(const s of n.getNamedImports())s.getNameNode().getText()===t&&i.add(s.getAliasNode()?.getText()??s.getName());return i},k=(e,t)=>{if(o.isPropertyAccessExpression(e))return e.getName()===t;if(!o.isIdentifier(e))return!1;const r=e.getText();return r===t||h(e.getSourceFile(),t).has(r)},N=e=>{for(const t of e.getSymbol()?.getDeclarations()??[])if(o.isImportSpecifier(t)&&c(t.getImportDeclaration().getModuleSpecifierValue()))return t.getNameNode().getText()},x=e=>e.getSymbol()?N(e):e.getText(),K=(e,t)=>o.isIdentifier(e)&&N(e)===t,Y=(e,t)=>{const r=e.getExpression(),i=e.getSourceFile();if(o.isIdentifier(r))return h(i,t,y).has(r.getText());if(!o.isPropertyAccessExpression(r)||r.getName()!==t)return!1;const n=r.getExpression().getText();return i.getImportDeclarations().some(s=>s.getNamespaceImport()?.getText()===n&&y(s.getModuleSpecifierValue()))},u=e=>{const t=[];let r=l(e);for(;r&&o.isCallExpression(r);){const i=l(r.getExpression());if(!i||!o.isPropertyAccessExpression(i))return{root:void 0,steps:t};t.push({call:r,name:i.getName()}),r=l(i.getExpression())}return{root:r,steps:t}},E=e=>u(e).steps,A=(e,t,r)=>E(e).filter(i=>i.name===t).map(i=>i.call.getArguments()[0]).filter(i=>i!==void 0&&o.isCallExpression(i)&&r(i.getExpression())),M=(e,t,r)=>A(e,t,i=>k(i,r)),G=(e,t)=>E(e).some(r=>r.name===t),J=(e,t,r)=>M(e,t,r).length>0,D=new Set(["action","internalAction","internalMutation","internalQuery","mutation","query","stream"]),C=e=>{if(o.isIdentifier(e)){for(const t of e.getSymbol()?.getDeclarations()??[])if(o.isImportSpecifier(t)&&c(t.getImportDeclaration().getModuleSpecifierValue()))return t.getName()}if(o.isPropertyAccessExpression(e)){const t=e.getExpression();if(o.isIdentifier(t))return t.getSymbol()?.getDeclarations().some(i=>o.isNamespaceImport(i)&&c(i.getFirstAncestorByKindOrThrow(b.ImportDeclaration).getModuleSpecifierValue()))?e.getName():void 0}},z=e=>{const t=e.getParent(),r=t.getParent(),i=e.getPropertyNameNode()??e.getNameNode();if(!o.isObjectBindingPattern(t)||!o.isVariableDeclaration(r)||r.getVariableStatement()?.getDeclarationKind()!==S.Const||e.getDotDotDotToken()||e.getInitializer()||!o.isIdentifier(i)||!D.has(i.getText())||i.getText()==="stream")return;const n=r.getInitializer();if(!n)return;const{root:s,steps:a}=u(n);return s&&C(s)==="initLunora"&&a.length===2&&a[0]?.name==="create"&&a[1]?.name==="dataModel"?i.getText():void 0},R=e=>{const t=C(e);if(t)return D.has(t)?{factory:t}:{};if(!o.isIdentifier(e))return{};const r=e.getSymbol(),i=(r?.isAlias()?r.getAliasedSymbol():r)?.getValueDeclaration();return i&&o.isBindingElement(i)?{factory:z(i)}:i&&o.isVariableDeclaration(i)&&i.getVariableStatement()?.getDeclarationKind()===S.Const?{initializer:i.getInitializer()}:{}},B=e=>{const t=[],r=new Set;let i=e;for(;i!==void 0&&!r.has(i);){r.add(i);const n=u(i);if(t.push(...n.steps),!n.root)break;const{factory:s,initializer:a}=R(n.root);if(s)return{factory:s,steps:t};i=a}return{steps:t}},m=new Set(["action","mutation","query","stream"]),T={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},f={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init",onWhisper:"whisper",defineWebSocket:"socket"},p={defineRoom:"room"},_=e=>e==="whisper"?"query":"mutation",w=e=>{const{root:t}=u(e);return t&&o.isIdentifier(t)?t:void 0},O=(e,t=!1)=>{const r=w(e);if(!r)return;const i=x(r);if(i===void 0){if(t)return;const n=r.getSymbol()?.getValueDeclaration();if(n&&o.isVariableDeclaration(n)){const s=n.getInitializer();return s?O(s,!0):void 0}return}return m.has(i)?"public":T[i]?"internal":void 0},V=(e,t=!1)=>{if(A(e,"use",s=>K(s,"platformAdmin")).length>0)return!0;if(t)return!1;const r=w(e)?.getSymbol(),i=(r?.isAlias()?r.getAliasedSymbol():r)?.getValueDeclaration(),n=i&&o.isVariableDeclaration(i)?i.getInitializer():void 0;return n!==void 0&&V(n,!0)},v=e=>V(e)?{adminOnly:!0}:{},L=(e,t)=>{const r=e.getName();if(!m.has(r))return;const i=e.getExpression(),n=l(i)??i,s=i===n?[n]:[i,n];if(s.some(d=>d.getType().getProperty("__lunoraProcedure"))){const d=s.some(P=>P.getType().getProperty("__lunoraVisibility"));return{kind:r,receiver:n,visibility:d?"internal":"public",...v(n)}}const a=t?B(n).factory:void 0,F=a?.startsWith("internal")?"internal":"public",g=a?F:O(n);if(g)return{kind:r,receiver:n,visibility:g,...v(n)}},j=e=>(e.getSymbol()?.getDeclarations()??[]).some(t=>o.isNamespaceImport(t)&&c(t.getFirstAncestorByKind(b.ImportDeclaration)?.getModuleSpecifierValue()??"")),W=e=>Object.hasOwn(p,e)||Object.hasOwn(f,e),I=e=>{if(Object.hasOwn(p,e))return{channel:p[e],kind:"mutation",visibility:"internal"};const t=Object.hasOwn(f,e)?f[e]:void 0;return t?{kind:_(t),lifecycle:t,visibility:"internal"}:void 0},X=(e,t=!1)=>{const r=e.getExpression();if(o.isPropertyAccessExpression(r)){const s=r.getExpression(),a=r.getName();return W(a)&&o.isIdentifier(s)&&j(s)?I(a):L(r,t)}if(!o.isIdentifier(r))return;const i=x(r);if(!i)return;if(m.has(i))return{kind:i,visibility:"public"};const n=T[i];return n?{kind:n,visibility:"internal"}:I(i)};export{U as a,E as b,X as c,J as d,K as e,G as f,Y as g,h as i,B as s,M as w};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i}from"ts-morph";import{listLunoraSourceFiles as a,lunoraRelativePath as c,handlerOf as l}from"./isTestPath-B81lOULB.mjs";import{b as d,d as f}from"./attribution-hVBriwzy.mjs";import{c as u}from"./context-root-
|
|
1
|
+
import{Node as i}from"ts-morph";import{listLunoraSourceFiles as a,lunoraRelativePath as c,handlerOf as l}from"./isTestPath-B81lOULB.mjs";import{b as d,d as f}from"./attribution-hVBriwzy.mjs";import{c as u}from"./context-root-BTW5XwVq.mjs";import{c as m}from"./classify-procedure-call-Bw5sia-K.mjs";const p=t=>{const r=t.getInitializer();if(!r||!i.isCallExpression(r))return;const e=m(r);if(!e||e.kind!=="query"&&e.kind!=="mutation")return;const o=l(r,e.receiver);return o?{exportName:f(t)??t.getName(),handler:o,kind:e.kind}:void 0},x=(t,r)=>{const e=t.getParent();return e&&i.isPropertyAccessExpression(e)&&e.getExpression()===t?`ctx.${r}.${e.getName()}`:`ctx.${r}`},h=(t,r,e)=>{const o=[];for(const n of u(t.handler,e))o.push({callee:x(n,e),exportName:t.exportName,file:r,kind:t.kind,line:n.getStartLineNumber()});return o},N=(t,r,e)=>{const o=[];for(const n of d(t)){const s=p(n);s&&o.push(...h(s,r,e))}return o},F=(t,r,e)=>{const o=[];for(const n of a(r)){const s=t.getSourceFile(n)??t.addSourceFileAtPath(n);o.push(...N(s,c(r,n),e))}return o};export{F as d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as s,SyntaxKind as d}from"ts-morph";import{unwrapExpression as l,memberAccessOf as P,bindingKeyName as C,findObjectProperty as p,isConstDeclaration as D,walkChain as A}from"./isTestPath-B81lOULB.mjs";import{f as v,g as I,h as M}from"./attribution-hVBriwzy.mjs";import{c as F}from"./classify-procedure-call-
|
|
1
|
+
import{Node as s,SyntaxKind as d}from"ts-morph";import{unwrapExpression as l,memberAccessOf as P,bindingKeyName as C,findObjectProperty as p,isConstDeclaration as D,walkChain as A}from"./isTestPath-B81lOULB.mjs";import{f as v,g as I,h as M}from"./attribution-hVBriwzy.mjs";import{c as F}from"./classify-procedure-call-Bw5sia-K.mjs";import{isDefineMutatorCallee as b}from"./MUTATORS_FILENAME-B_I0kkvJ.mjs";const x=8,E=t=>{if(s.isMethodDeclaration(t))return t;const e=s.isPropertyAssignment(t)?l(t.getInitializer()):void 0,o=s.isShorthandPropertyAssignment(t)?t.getNameNode():e;if(s.isArrowFunction(o)||s.isFunctionExpression(o))return o;const i=s.isIdentifier(o)?v(o):void 0;if(s.isFunctionDeclaration(i))return i;const n=D(i)?l(i.getInitializer()):void 0;return s.isArrowFunction(n)||s.isFunctionExpression(n)?n:void 0},w=t=>{const e=l(t.getArguments()[0]),o=s.isObjectLiteralExpression(e)?e:void 0,i=p(o,"server"),n=p(o,"handler"),r=i!==void 0&&b(t.getExpression()),a=n===void 0?void 0:F(t),u=a!==void 0&&a.receiver===void 0;return[r?E(i):void 0,u?E(n):void 0].filter(f=>f!==void 0)},h=new WeakMap,O=t=>{const e=t.getSourceFile(),o=h.get(e.compilerNode);if(o!==void 0)return o;const i=new Set(e.getDescendantsOfKind(d.CallExpression).flatMap(n=>w(n)).map(n=>n.compilerNode));return h.set(e.compilerNode,i),i},S=t=>{const e=t.getParent();return(s.isArrowFunction(e)||s.isFunctionExpression(e)||s.isFunctionDeclaration(e)||s.isMethodDeclaration(e))&&e.getParameters()[0]===t&&O(t).has(e.compilerNode)},G=t=>{const e=t.getParent();return(s.isArrowFunction(e)||s.isFunctionExpression(e)||s.isFunctionDeclaration(e)||s.isMethodDeclaration(e))&&e.getParameters()[1]===t&&O(t).has(e.compilerNode)},T=t=>t.getNameNode().getDescendantsOfKind(d.BindingElement).some(e=>e.getParent().getParent()===t&&["args","ctx"].includes(C(e))),g=(t,e,o)=>{const i=t.getParent().getParent(),n=C(t);if(t.getDotDotDotToken()!==void 0||e==="trust"&&I(t))return;let r;if(s.isParameterDeclaration(i)){if(!S(i)||T(i))return n==="ctx"?[]:void 0;r=[]}else s.isBindingElement(i)?r=g(i,e,o):s.isVariableDeclaration(i)&&o>0&&(r=c(i.getInitializer(),e,o-1));return r===void 0?void 0:[...r,n]},c=(t,e="discover",o=x)=>{const i=l(t),n=P(i);if(n!==void 0){const r=c(n.object,e,o);return r===void 0?void 0:[...r,n.member]}return s.isIdentifier(i)?B(i,e,o):void 0},B=(t,e,o)=>{const i=t.getText()==="ctx",n=e==="trust"||!i?v(t):void 0;return i&&!s.isVariableDeclaration(n)?s.isBindingElement(n)?g(n,e,o):[]:s.isParameterDeclaration(n)?s.isIdentifier(n.getNameNode())&&S(n)?[]:void 0:s.isBindingElement(n)?g(n,e,o):!(s.isVariableDeclaration(n)&&s.isIdentifier(n.getNameNode())&&o>0)||e==="trust"&&I(n)?void 0:c(n.getInitializer(),e,o-1)},Q=t=>c(t,"discover"),H=t=>{const e=c(t);return e===void 0?void 0:["ctx",...e].join(".")},q=(t,e)=>{if(e(t.getText()))return!0;const o=H(t);return o!==void 0&&e(o)},J=(t,e)=>{const o=l(t),i=P(o);if(i!==void 0&&i.member!==e.at(-1))return!1;const n=o===void 0?void 0:c(o);return n?.length===e.length&&n.every((r,a)=>r===e[a])},Y=(t,e)=>U(t).get(e)??[],K=t=>{const e=new Map;for(const i of t.getDescendantsOfKind(d.BindingElement)){const n=s.isIdentifier(i.getNameNode())?g(i,"discover",x):void 0;n?.length===1&&n[0]!==void 0&&e.set(i.compilerNode,n[0])}const o=new Set([...e.keys()].map(i=>i.name.getText()));return t.getDescendantsOfKind(d.Identifier).flatMap(i=>{const r=o.has(i.getText())&&!s.isBindingElement(i.getParent())?v(i):void 0,a=r===void 0?void 0:e.get(r.compilerNode);return a===void 0?[]:[[a,i]]})},N=new WeakMap,U=t=>{const e=N.get(t.compilerNode);if(e!==void 0)return e;const o=new Map;for(const[n,r]of[...y(t),...K(t)])o.set(n,[...o.get(n)??[],r]);const i=new Map([...o].map(([n,r])=>[n,r.toSorted((a,u)=>a.getPos()-u.getPos())]));return N.set(t.compilerNode,i),i},y=t=>t.getDescendantsOfKind(d.PropertyAccessExpression).flatMap(e=>z(e.getExpression())?[[e.getName(),e]]:[]),z=t=>s.isIdentifier(t)&&c(t)?.length===0,Z=t=>{const e=c(t);return e?.length===1&&e[0]==="db"},_=new Set(["asId","createMultipartUpload","fetch","generateUploadUrl","getPresignedUrl","getSignedUrl","getUrl","normalizeId","resumeMultipartUpload","runAction","runMutation","runQuery","store","upload"]),R=new Set(["catch","flatMap","map","reduce","reduceRight","then"]),k=(t,e=x)=>{const o=A(t,u=>{const f=l(u.getExpression()),m=s.isPropertyAccessExpression(f)?f.getName():void 0;return m!==void 0&&(_.has(m)||R.has(m))?!1:void 0}),i=o.root;if(o.verdict!==void 0||!s.isIdentifier(i))return o.verdict??!1;if(c(i,"trust")!==void 0)return!0;const n=v(i),r=s.isBindingElement(n)?n.getFirstAncestorByKind(d.VariableDeclaration):n,a=D(r)&&e>0?r.getInitializer():void 0;return a!==void 0&&k(a,e-1)},$=t=>(s.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(o=>M(o)&&c(o,"trust")!==void 0);export{R as C,_ as E,G as a,H as b,Y as c,Z as d,Q as e,k as f,z as g,J as i,q as m,$ as r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SyntaxKind as g,Node as n}from"ts-morph";import{d as p}from"./context-root-
|
|
1
|
+
import{SyntaxKind as g,Node as n}from"ts-morph";import{d as p}from"./context-root-BTW5XwVq.mjs";const c=e=>n.isPropertyAccessExpression(e)&&e.getName()==="db"||n.isIdentifier(e)&&e.getText()==="db"||p(e),l=new Set(["findFirst","findFirstOrThrow","findMany","findUnique"]),u=e=>{const t=e.getExpression();if(!n.isPropertyAccessExpression(t)||!l.has(t.getName()))return;const s=t.getExpression();if(c(s))return{options:e.getArguments()[1],table:d(e)};if(n.isPropertyAccessExpression(s)){const o=s.getExpression();if(c(o))return{options:e.getArguments()[0],table:s.getName()}}},f=(e,t)=>{const s=e.getExpression();return!n.isPropertyAccessExpression(s)||!t.has(s.getName())?!1:c(s.getExpression())},d=e=>{const t=e.getArguments()[0];return t&&n.isStringLiteral(t)?t.getLiteralText():""},m=(e,t,s)=>{const o=new Set,i=new Set;for(const a of e.getDescendantsOfKind(g.CallExpression))if(f(a,t)){const r=d(a);r!==""&&o.add(r)}else if(f(a,s)){const r=d(a);r!==""&&i.add(r)}return{tablesRead:[...o],tablesWritten:[...i]}};export{c as i,u as r,m as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as x}from"@lunora/errors";import{CRON_SCHEDULE_KINDS as A,warnIfSecondsLeading as O,compileCronSchedule as S}from"@lunora/scheduler";import I from"@lunora/scheduler/validate";import{SyntaxKind as m,Node as i}from"ts-morph";import{diagnosticAt as f,CodegenDiagnosticError as R}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{i as b}from"./module-specifiers-
|
|
1
|
+
import{LunoraError as x}from"@lunora/errors";import{CRON_SCHEDULE_KINDS as A,warnIfSecondsLeading as O,compileCronSchedule as S}from"@lunora/scheduler";import I from"@lunora/scheduler/validate";import{SyntaxKind as m,Node as i}from"ts-morph";import{diagnosticAt as f,CodegenDiagnosticError as R}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{i as b}from"./module-specifiers-BctA0m_p.mjs";import{listLunoraSourceFiles as y,functionKeyOf as $}from"./isTestPath-B81lOULB.mjs";import{a as P}from"./project-config-file-BV7RR-l6.mjs";const D=new Set([...A,"cron"]),v=e=>{const t=e.getSymbol();if(!t)return e.getText()==="cronJobs";for(const r of t.getDeclarations())if(i.isImportSpecifier(r))return b(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="cronJobs":!1;return!1},F=e=>{const t=new Set;for(const r of e.getVariableDeclarations()){const n=r.getInitializer();if(n?.getKind()!==m.CallExpression)continue;const s=n.getExpression();i.isIdentifier(s)&&v(s)&&t.add(r.getName())}return t},V=e=>{let t=e;for(;i.isCallExpression(t)||i.isPropertyAccessExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t.getText():void 0},_=(e,t)=>{const r=e.getArguments()[t];return r&&(i.isStringLiteral(r)||i.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},L=(e,t)=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e)||i.isNumericLiteral(e))return e.getLiteralValue();if(i.isTrueLiteral(e))return!0;if(i.isFalseLiteral(e))return!1;if(i.isPrefixUnaryExpression(e)&&e.getOperatorToken()===m.MinusToken){const r=e.getOperand();if(i.isNumericLiteral(r))return-r.getLiteralValue()}if(i.isObjectLiteralExpression(e))return p(e,t);if(i.isArrayLiteralExpression(e))return e.getElements().map(r=>L(r,t));throw f(e,`Cron job "${t}" passes a non-static value where a literal is required; codegen can only read literals.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500})},p=(e,t)=>{const r={};for(const n of e.getProperties()){if(!i.isPropertyAssignment(n))throw f(n,`Cron job "${t}" uses an unsupported object property (shorthand/spread/method) where a static literal is required.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500});const s=n.getInitializer();s&&(r[P(n)]=L(s,t))}return r},C=(e,t,r)=>{const n=e.getArguments()[t];if(!n||!i.isPropertyAccessExpression(n))throw f(e,`Cron job "${r}" must reference a function statically (e.g. internal.email.digest); codegen cannot resolve a dynamic reference.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const s=$(n);if(s===void 0)throw f(n,`Cron job "${r}" function reference must be of the form internal.<…path>.fn (or api.<…path>.fn).`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});return s},h=e=>({workflow:{className:e.className,exportName:e.exportName}}),w=e=>({workflow:{className:e.className,exportName:e.exportName}}),T=(e,t,r,n,s,o)=>{const a=e.getExpression();if(!i.isIdentifier(a)||a.getText()!==t)return;const c=r.get(e.getName());if(c)return o(c);throw f(e,`Cron job "${n}" targets ${t}.${e.getName()}, but no such ${s} is declared in lunora/${s}s.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})},k=(e,t,r,n,s)=>{const o=e.getArguments()[t];if(o&&i.isPropertyAccessExpression(o)){const a=T(o,"workflows",n,r,"workflow",h);if(a)return a;const c=T(o,"agents",s,r,"agent",w);return c||{functionPath:C(e,t,r)}}if(o&&i.isIdentifier(o)){const a=n.get(o.getText()),c=s.get(o.getText());if(a&&c)throw f(o,`Cron job "${r}" references "${o.getText()}", which is ambiguous: a workflow and an agent are both declared under that name.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});if(a)return h(a);if(c)return w(c);throw f(o,`Cron job "${r}" references "${o.getText()}", which is neither a function (internal.file.fn / api.file.fn) nor a declared workflow in lunora/workflows.ts nor a declared agent in lunora/agents.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})}return{functionPath:C(e,t,r)}},j=/^@lunora\/scheduler:\s*/u,U=(e,t)=>{const r=_(e,1);if(r===void 0)throw f(e,`Cron job "${t}" must pass a string-literal cron expression to ".cron(...)".`,{code:"CRON_EXPR_NOT_STATIC",name:"LunoraError",status:500});if(!I(r))throw f(e,`Cron job "${t}" has an invalid cron expression "${r}" — expected 5 or 6 space-separated fields.`,{code:"CRON_EXPR_INVALID",name:"LunoraError",status:500});return O(r,`cron expression for job "${t}"`),r},M=(e,t,r)=>{const n=e.getArguments()[1];if(!n||!i.isObjectLiteralExpression(n))throw f(e,`Cron job "${r}" must pass an object-literal schedule to ".${t}(...)".`,{code:"CRON_SCHEDULE_NOT_STATIC",name:"LunoraError",status:500});try{return S(t,p(n,r),r)}catch(s){if(s instanceof R)throw s;const o=s instanceof Error?s.message.replace(j,""):String(s);throw f(e,o,{code:"CRON_SCHEDULE_INVALID",name:"LunoraError",status:500})}},K=(e,t,r,n,s)=>{const o=t.getName();if(!D.has(o)||!r.has(V(t.getExpression())??""))return;const a=_(e,0);if(a===void 0||a.trim()==="")throw f(e,`A cron ".${o}(...)" registration must pass a non-empty string-literal name as its first argument.`,{code:"CRON_NAME_NOT_STATIC",name:"LunoraError",status:500});const c=o==="cron"?U(e,a):M(e,o,a),u=k(e,2,a,n,s),l=e.getArguments()[3];return{args:l&&i.isObjectLiteralExpression(l)?p(l,a):{},cron:c,name:a,...u}},z=e=>{const t=new Set;for(const r of e){if(t.has(r.name))throw new x("DUPLICATE_CRON_NAME",`Duplicate cron job name "${r.name}": cron names must be unique across the project.`,{status:500});t.add(r.name)}},Y=(e,t,r=[],n=[])=>{const s=y(t),o=[],a=new Map(r.map(u=>[u.exportName,u])),c=new Map(n.map(u=>[u.exportName,u]));for(const u of s){const l=e.getSourceFile(u)??e.addSourceFileAtPath(u),g=F(l);if(g.size!==0)for(const d of l.getDescendantsOfKind(m.CallExpression)){const N=d.getExpression();if(!i.isPropertyAccessExpression(N))continue;const E=K(d,N,g,a,c);E&&o.push(E)}}return o.sort((u,l)=>u.name.localeCompare(l.name)),z(o),o};export{Y as default};
|