@lunora/codegen 1.0.0-alpha.200 → 1.0.0-alpha.201
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{AGENTS_FILENAME-B78F7DuQ.mjs → AGENTS_FILENAME-DPIMTD_h.mjs} +1 -1
- package/dist/packem_shared/{CONTAINERS_FILENAME-CQoUu7n7.mjs → CONTAINERS_FILENAME-wDZs0S4p.mjs} +1 -1
- package/dist/packem_shared/{FLAGS_FILENAME-CoTJH0-7.mjs → FLAGS_FILENAME-CQofXgIf.mjs} +1 -1
- package/dist/packem_shared/{NOTIFY_FILENAME-Bgq52CnU.mjs → NOTIFY_FILENAME-DbuOgja2.mjs} +1 -1
- package/dist/packem_shared/{QUEUES_FILENAME-Q3CF3uYr.mjs → QUEUES_FILENAME-Dd781zOQ.mjs} +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CuZkv079.mjs +9 -0
- package/dist/packem_shared/{WORKFLOWS_FILENAME-BaSbufF2.mjs → WORKFLOWS_FILENAME-v3AJcUjy.mjs} +1 -1
- package/dist/packem_shared/chain-u-8_P10m.mjs +1 -0
- package/dist/packem_shared/{classify-procedure-call-BIlyTUBD.mjs → classify-procedure-call-RjsZg8AH.mjs} +1 -1
- package/dist/packem_shared/{context-property-calls-H37QsE0Q.mjs → context-property-calls-DV-Pt4KS.mjs} +1 -1
- package/dist/packem_shared/{discoverAuthApiCalls-DoblmzUW.mjs → discoverAuthApiCalls-EHm1O8uG.mjs} +1 -1
- package/dist/packem_shared/{discoverCrons-CMu0sA8k.mjs → discoverCrons-B2GXsB-m.mjs} +1 -1
- package/dist/packem_shared/{discoverFunctions-DRf4ucil.mjs → discoverFunctions-BwB7RhZd.mjs} +1 -1
- package/dist/packem_shared/{discoverHttpRoutes-_ME7hLcW.mjs → discoverHttpRoutes-B0EVnVgb.mjs} +1 -1
- package/dist/packem_shared/discoverHyperdriveCalls-CzRlqv_N.mjs +1 -0
- package/dist/packem_shared/{discoverInserts-COk-Sm_n.mjs → discoverInserts-BP0Gl37o.mjs} +1 -1
- package/dist/packem_shared/discoverMaskProcedures-Cl2I3ycl.mjs +1 -0
- package/dist/packem_shared/{discoverMigrations-B_sYrTyE.mjs → discoverMigrations-BX86Fv9G.mjs} +1 -1
- package/dist/packem_shared/{discoverNondeterministicCalls-Dy6k2aPS.mjs → discoverNondeterministicCalls-CJYIXWPw.mjs} +1 -1
- package/dist/packem_shared/discoverQueries-COGaQPE5.mjs +1 -0
- package/dist/packem_shared/discoverR2sqlCalls-emIgm3TF.mjs +1 -0
- package/dist/packem_shared/{discoverRlsMetadata-DwULXx5T.mjs → discoverRlsMetadata-3Gs8U3ng.mjs} +1 -1
- package/dist/packem_shared/{discoverRlsProcedures-D_J8cH-m.mjs → discoverRlsProcedures-CU7YMR3P.mjs} +1 -1
- package/dist/packem_shared/{discoverSandboxUsage-DskdDbkM.mjs → discoverSandboxUsage-pJ42YuvL.mjs} +1 -1
- package/dist/packem_shared/{discoverStorageRulesMetadata-C3ywuLJd.mjs → discoverStorageRulesMetadata-BFiKUo5m.mjs} +1 -1
- package/dist/packem_shared/{exported-procedure-chains-Bqdp4ywr.mjs → exported-procedure-chains-CjlBrFjo.mjs} +1 -1
- package/dist/packem_shared/{index-C4eKBBMk.mjs → index-D6xfnMEE.mjs} +1 -1
- package/dist/packem_shared/listLunoraSourceFiles-DsxeRYvh.mjs +1 -0
- package/dist/packem_shared/queries-TZaLWhWq.mjs +1 -0
- package/package.json +3 -3
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BpSBAMAb.mjs +0 -9
- package/dist/packem_shared/chain-BWtZ1NER.mjs +0 -1
- package/dist/packem_shared/discoverHyperdriveCalls-DP3Vb0HC.mjs +0 -1
- package/dist/packem_shared/discoverMaskProcedures-CNkhbP5z.mjs +0 -1
- package/dist/packem_shared/discoverQueries-BQXP4BZ0.mjs +0 -1
- package/dist/packem_shared/discoverR2sqlCalls-FaK1-wbV.mjs +0 -1
- package/dist/packem_shared/listLunoraSourceFiles-D4xthUf-.mjs +0 -1
- package/dist/packem_shared/queries-CPlxXagL.mjs +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-DwmUKYuc.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as l}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as x,diagnosticAt as E}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-
|
|
1
|
+
import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-DwmUKYuc.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as l}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as x,diagnosticAt as E}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-DPIMTD_h.mjs";import{listLunoraSourceFiles as g}from"./packem_shared/listLunoraSourceFiles-DsxeRYvh.mjs";import{default as O}from"./packem_shared/discoverAuthApiCalls-EHm1O8uG.mjs";import{CONTAINERS_FILENAME as M,discoverContainers as T}from"./packem_shared/CONTAINERS_FILENAME-wDZs0S4p.mjs";import{default as h}from"./packem_shared/discoverCrons-B2GXsB-m.mjs";import{FLAGS_FILENAME as F,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-CQofXgIf.mjs";import{default as D}from"./packem_shared/discoverFunctions-BwB7RhZd.mjs";import{default as U}from"./packem_shared/discoverHttpRoutes-B0EVnVgb.mjs";import{default as H}from"./packem_shared/discoverHyperdriveCalls-CzRlqv_N.mjs";import{default as y}from"./packem_shared/discoverInserts-BP0Gl37o.mjs";import{d as W}from"./packem_shared/index-D6xfnMEE.mjs";import{default as V}from"./packem_shared/discoverMigrations-BX86Fv9G.mjs";import{MUTATORS_FILENAME as Q,discoverMutators as w}from"./packem_shared/MUTATORS_FILENAME-B7EXNAFK.mjs";import{default as q}from"./packem_shared/discoverNondeterministicCalls-CJYIXWPw.mjs";import{NOTIFY_FILENAME as Y,discoverNotifyCalls as X,discoverNotifyConfig as Z}from"./packem_shared/NOTIFY_FILENAME-DbuOgja2.mjs";import{default as ee}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as oe}from"./packem_shared/queries-TZaLWhWq.mjs";import{QUEUES_FILENAME as se,discoverQueues as ae}from"./packem_shared/QUEUES_FILENAME-Dd781zOQ.mjs";import{default as me}from"./packem_shared/discoverR2sqlCalls-emIgm3TF.mjs";import{default as fe}from"./packem_shared/discoverRlsProcedures-CU7YMR3P.mjs";import{default as ce}from"./packem_shared/discoverRlsMetadata-3Gs8U3ng.mjs";import{discoverSandboxUsage as le}from"./packem_shared/discoverSandboxUsage-pJ42YuvL.mjs";import{default as xe}from"./packem_shared/discoverSchema-DoZtXwLg.mjs";import{SHAPES_FILENAME as Ae,discoverShapes as ue}from"./packem_shared/SHAPES_FILENAME-Bvd5kgsF.mjs";import{default as Ne}from"./packem_shared/discoverStorageRulesMetadata-BFiKUo5m.mjs";import{WORKFLOWS_FILENAME as Ce,discoverWorkflows as Oe}from"./packem_shared/WORKFLOWS_FILENAME-v3AJcUjy.mjs";import{G as Me,e as Te,a as _e,b as he,c as Le,d as Fe,f as Ie,g as Pe,h as De,i as Ge,j as Ue,k as be,l as He,m as je,n as ye}from"./packem_shared/emit-BuaY_1hY.mjs";import{emitApp as We}from"./packem_shared/emitApp-nInCbDo8.mjs";import{isD1GlobalTable as Ve,isHyperdriveGlobalTable as ze}from"./packem_shared/isD1GlobalTable-udvHAAzD.mjs";import{buildOpenApiDocument as we,emitOpenApi as Je,emitOpenApiModule as qe}from"./packem_shared/buildOpenApiDocument-DCGde3iO.mjs";import{OPENRPC_VERSION as Ye,buildOpenRpcDocument as Xe,emitOpenRpc as Ze,emitOpenRpcModule as $e}from"./packem_shared/OPENRPC_VERSION-D6-0Hn3B.mjs";import{DEFAULT_TARGET as rr,platformMatrixIds as or,readProjectTarget as tr,resolveCodegenTarget as sr}from"./packem_shared/DEFAULT_TARGET-DtzlGawL.mjs";import{PROJECT_CONFIG_FILENAMES as ir,findProjectConfigFile as mr,loadProjectConfig as dr,readProjectConfigLiterals as fr}from"./packem_shared/PROJECT_CONFIG_FILENAMES-D29yBg5X.mjs";import{SCHEMA_SNAPSHOT_FILENAME as cr,createCodegenProject as nr,findTsconfig as lr,refreshCodegenProject as Sr,runCodegen as xr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-CuZkv079.mjs";import{SchemaSnapshotParseError as Ar,buildSchemaSnapshot as ur,evaluateSchemaDrift as vr,parseSchemaSnapshot as Nr}from"./packem_shared/SchemaSnapshotParseError-lUWe6lPo.mjs";import{schemaFromIr as Cr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as Rr,validatorIrToJsonSchema as Mr}from"./packem_shared/LUNORA_ERROR_CODES-C2s0xWQD.mjs";import{SDK_LANGUAGES as _r,SDK_TARGETS as hr,generateSdk as Lr}from"./packem_shared/SDK_LANGUAGES-CFyux-74.mjs";import{redact as Ir,secretKindOf as Pr}from"./packem_shared/redact-Cy14LEnc.mjs";import{MESSAGE_SOLUTIONS as Gr,findSolutionByMessage as Ur}from"@lunora/errors";import{isTypedSchema as Hr}from"./packem_shared/isTypedSchema-B_qlBbE-.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,M as CONTAINERS_FILENAME,x as CodegenDiagnosticError,rr as DEFAULT_TARGET,F as FLAGS_FILENAME,Me as GENERATED_HEADER,Rr as LUNORA_ERROR_CODES,Gr as LUNORA_SOLUTION_RULES,Q as MUTATORS_FILENAME,Y as NOTIFY_FILENAME,Ye as OPENRPC_VERSION,ir as PROJECT_CONFIG_FILENAMES,se as QUEUES_FILENAME,cr as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,_r as SDK_LANGUAGES,hr as SDK_TARGETS,Ae as SHAPES_FILENAME,Ar as SchemaSnapshotParseError,e as VERSION,Ce as WORKFLOWS_FILENAME,we as buildOpenApiDocument,Xe as buildOpenRpcDocument,ur as buildSchemaSnapshot,nr as createCodegenProject,c as describeErrorLevelFindings,E as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,O as discoverAuthApiCalls,T as discoverContainers,h as discoverCrons,I as discoverFlags,D as discoverFunctions,U as discoverHttpRoutes,H as discoverHyperdriveCalls,y as discoverInserts,W as discoverMaskProcedures,V as discoverMigrations,w as discoverMutators,q as discoverNondeterministicCalls,X as discoverNotifyCalls,Z as discoverNotifyConfig,oe as discoverQueries,ae as discoverQueues,me as discoverR2sqlCalls,ce as discoverRlsMetadata,fe as discoverRlsProcedures,le as discoverSandboxUsage,xe as discoverSchema,ue as discoverShapes,Ne as discoverStorageRulesMetadata,Oe as discoverWorkflows,Te as emitAgents,_e as emitApi,We as emitApp,he as emitCollections,Le as emitContainers,Fe as emitCrons,Ie as emitDataModel,Pe as emitDrizzleSchema,De as emitFunctions,Je as emitOpenApi,qe as emitOpenApiModule,Ze as emitOpenRpc,$e as emitOpenRpcModule,Ge as emitScheduler,Ue as emitServer,be as emitShard,He as emitVectors,je as emitWorkflows,ye as emitWranglerCronTriggers,n as errorAdvisoryNames,l as errorPlatformDiagnosticNames,vr as evaluateSchemaDrift,Ur as findLunoraSolution,mr as findProjectConfigFile,lr as findTsconfig,m as formatAdvisories,Lr as generateSdk,Ve as isD1GlobalTable,ze as isHyperdriveGlobalTable,Hr as isTypedSchema,d as lintSchema,g as listLunoraSourceFiles,dr as loadProjectConfig,Nr as parseSchemaSnapshot,or as platformMatrixIds,ee as readPackageDependencies,fr as readProjectConfigLiterals,tr as readProjectTarget,Ir as redact,Sr as refreshCodegenProject,sr as resolveCodegenTarget,xr as runCodegen,Cr as schemaFromIr,Pr as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,Mr as validatorIrToJsonSchema};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as u}from"node:fs";import{join as p}from"node:path";import{agentDefaultName as d,agentClassName as f,agentBindingName as b,voiceBindingName as N,voiceClassName as y}from"@lunora/agent/naming";import{LunoraError as l}from"@lunora/errors";import{Node as a,SyntaxKind as m}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapToCallExpression as A,stringPropertyFor as w}from"./listLunoraSourceFiles-
|
|
1
|
+
import{existsSync as u}from"node:fs";import{join as p}from"node:path";import{agentDefaultName as d,agentClassName as f,agentBindingName as b,voiceBindingName as N,voiceClassName as y}from"@lunora/agent/naming";import{LunoraError as l}from"@lunora/errors";import{Node as a,SyntaxKind as m}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapToCallExpression as A,stringPropertyFor as w}from"./listLunoraSourceFiles-DsxeRYvh.mjs";const h="agents.ts",E=i=>{const t=i.getSymbol();if(!t)return i.getText()==="defineAgent";for(const n of t.getDeclarations())if(a.isImportSpecifier(n))return n.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/agent"?!1:n.getNameNode().getText()==="defineAgent";return!1},P=w("agent"),I=(i,t,n)=>{if(i.getKind()===m.TrueKeyword)return!0;if(i.getKind()===m.FalseKeyword)return!1;throw g(i,`agent "${t}": \`${n}\` must be a static boolean literal — it is deploy configuration codegen writes into the ctx.agents wiring spec`)},T=(i,t)=>{const n=i.getArguments()[0];if(!n||!a.isObjectLiteralExpression(n))throw g(i,`agent "${t}": defineAgent must be passed an inline object literal`);const o={bindingName:b(t),className:f(t),exportName:t,name:d(t)},e=n.getProperty("name");e&&a.isPropertyAssignment(e)&&(o.name=P(e.getInitializerOrThrow(),t,"name"));const r=n.getProperty("publicRun");r&&a.isPropertyAssignment(r)&&I(r.getInitializerOrThrow(),t,"publicRun")&&(o.publicRun=!0);const s=n.getProperty("voice");if(s&&a.isPropertyAssignment(s)){const c=s.getInitializerOrThrow();if(!a.isObjectLiteralExpression(c))throw g(c,`agent "${t}": \`voice\` must be an inline object literal — its presence tells codegen to emit the voice-session Durable Object`);o.voice=!0,o.voiceBindingName=N(t),o.voiceClassName=y(t)}return n.getProperty("onEmail")&&(o.onEmail=!0),o},v=i=>{const t=[];for(const n of i.getVariableDeclarations()){if(!n.isExported())continue;const o=A(n.getInitializer());if(!o)continue;const e=o.getExpression();if(!a.isIdentifier(e)||!E(e))continue;const r=n.getNameNode();if(!a.isIdentifier(r))throw g(r,"defineAgent exports must be plain named exports (no destructuring)");t.push(T(o,r.getText()))}return t},D=i=>{const t=new Map,n=new Map,o=new Map;for(const e of i){const r=t.get(e.name);if(r!==void 0)throw new l("DUPLICATE_AGENT_NAME",`Duplicate agent name "${e.name}": produced by both "${r}" and "${e.exportName}". Deployed agent names must be unique across the project.`,{status:500});t.set(e.name,e.exportName);const s=n.get(e.bindingName);if(s!==void 0)throw new l("DUPLICATE_AGENT_BINDING",`Duplicate agent binding "${e.bindingName}": produced by both "${s}" and "${e.exportName}". Agent export names must yield unique binding names.`,{status:500});n.set(e.bindingName,e.exportName);const c=o.get(e.className);if(c!==void 0)throw new l("DUPLICATE_AGENT_CLASS",`Duplicate agent class "${e.className}": produced by both "${c}" and "${e.exportName}". Agent export names must yield unique generated class names.`,{status:500});o.set(e.className,e.exportName)}},j=(i,t)=>{const n=p(t,h);if(!u(n))return[];const o=i.getSourceFile(n)??i.addSourceFileAtPath(n),e=v(o);return e.sort((r,s)=>r.exportName.localeCompare(s.exportName)),D(e),e};export{h as AGENTS_FILENAME,j as discoverAgents};
|
package/dist/packem_shared/{CONTAINERS_FILENAME-CQoUu7n7.mjs → CONTAINERS_FILENAME-wDZs0S4p.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as f}from"node:fs";import{join as d}from"node:path";import{containerClassName as b,containerBindingName as p,normalizeContainerImage as u}from"@lunora/container";import{SyntaxKind as y,Node as n}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{stringPropertyFor as L}from"./listLunoraSourceFiles-
|
|
1
|
+
import{existsSync as f}from"node:fs";import{join as d}from"node:path";import{containerClassName as b,containerBindingName as p,normalizeContainerImage as u}from"@lunora/container";import{SyntaxKind as y,Node as n}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{stringPropertyFor as L}from"./listLunoraSourceFiles-DsxeRYvh.mjs";const P="containers.ts",h=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineContainer";for(const i of t.getDeclarations())if(n.isImportSpecifier(i))return i.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/container"?!1:i.getNameNode().getText()==="defineContainer";return!1},g=L("container"),m=(e,t,i)=>{if(n.isNumericLiteral(e))return e.getLiteralValue();throw c(e,`container "${t}": \`${i}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},T=(e,t)=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e))return u(e.getLiteralValue());if(n.isObjectLiteralExpression(e)){const i=e.getProperty("registry");if(i&&n.isPropertyAssignment(i)){const o=i.getInitializerOrThrow();return u({registry:g(o,t,"image.registry")})}const r=e.getProperty("build");if(r&&n.isPropertyAssignment(r)){const o=r.getInitializerOrThrow();return u({build:g(o,t,"image.build")})}}throw c(e,`container "${t}": \`image\` must be a static string path, { registry: "…" }, or { build: "…" } literal`)},k=e=>{if(!n.isObjectLiteralExpression(e))return;const t={};for(const i of e.getProperties()){if(!n.isPropertyAssignment(i))continue;const r=i.getInitializerOrThrow();(n.isStringLiteral(r)||n.isNoSubstitutionTemplateLiteral(r))&&(t[i.getName()]=r.getLiteralValue())}return Object.keys(t).length>0?t:void 0},I=e=>{if(!n.isObjectLiteralExpression(e))return;const t={};for(const i of e.getProperties()){if(!n.isPropertyAssignment(i))continue;const r=i.getName(),o=i.getInitializerOrThrow();n.isNumericLiteral(o)&&(r==="gracePeriodSeconds"||r==="stepPercentage")&&(t[r]=o.getLiteralValue())}return t.gracePeriodSeconds===void 0&&t.stepPercentage===void 0?void 0:t},w=e=>{if(n.isTrueLiteral(e))return!0;if(n.isFalseLiteral(e))return!1},S=e=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)||n.isNumericLiteral(e))return e.getLiteralValue()},A=(e,t)=>{if(n.isStringLiteral(e))return e.getLiteralValue();if(n.isObjectLiteralExpression(e)){const i={};for(const r of e.getProperties()){if(!n.isPropertyAssignment(r))throw c(r,`container "${t}": \`instanceType\` must be an object of static number literals`);const o=r.getName();if(o!=="diskMb"&&o!=="memoryMib"&&o!=="vcpu")throw c(r,`container "${t}": unknown \`instanceType\` field "${o}" — expected vcpu, memoryMib, or diskMb`);i[o]=m(r.getInitializerOrThrow(),t,`instanceType.${o}`)}return i}throw c(e,`container "${t}": \`instanceType\` must be a static string or { vcpu, memoryMib, diskMb } literal`)},v=(e,t)=>{const i=e.getArguments()[0];if(!i||!n.isObjectLiteralExpression(i))throw c(e,`container "${t}": defineContainer must be passed an inline object literal`);const r={bindingName:p(t),className:b(t),exportName:t,image:{buildContext:".",dockerfilePath:"./Dockerfile",kind:"dockerfile"}};let o=!1;for(const a of i.getProperties()){if(!n.isPropertyAssignment(a))continue;const l=a.getName(),s=a.getInitializerOrThrow();switch(l){case"buildArgs":{r.buildArgs=k(s);break}case"enableInternet":{r.enableInternet=w(s);break}case"image":{r.image=T(s,t),o=!0;break}case"instanceType":{r.instanceType=A(s,t);break}case"maxInstances":{r.maxInstances=m(s,t,"maxInstances");break}case"name":{r.name=g(s,t,"name");break}case"rollout":{r.rollout=I(s);break}case"sleepAfter":{r.sleepAfter=S(s);break}}}if(!o)throw c(i,`container "${t}": defineContainer requires a static \`image\` property`);return r},C=e=>{const t=[];for(const i of e.getVariableDeclarations()){if(!i.isExported())continue;const r=i.getInitializer();if(r?.getKind()!==y.CallExpression)continue;const o=r,a=o.getExpression();if(!n.isIdentifier(a)||!h(a))continue;const l=i.getNameNode();if(!n.isIdentifier(l))throw c(l,"defineContainer exports must be plain named exports (no destructuring)");t.push(v(o,l.getText()))}return t},F=(e,t)=>{const i=d(t,P);if(!f(i))return[];const r=e.getSourceFile(i)??e.addSourceFileAtPath(i),o=C(r);return o.sort((a,l)=>a.exportName.localeCompare(l.exportName)),o};export{P as CONTAINERS_FILENAME,F as discoverContainers};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as l}from"node:fs";import{join as p}from"node:path";import{Node as i}from"ts-morph";import{defaultExportExpression as g,propertyInitializer as f}from"./listLunoraSourceFiles-
|
|
1
|
+
import{existsSync as l}from"node:fs";import{join as p}from"node:path";import{Node as i}from"ts-morph";import{defaultExportExpression as g,propertyInitializer as f}from"./listLunoraSourceFiles-DsxeRYvh.mjs";const c="flags.ts",d=new Set(["@lunora/flags/providers/flagship","lunorash/flags/flagship"]),u=e=>{const t=e.getSymbol();if(!t)return e.getText()==="flagshipProvider";for(const r of t.getDeclarations())if(i.isImportSpecifier(r))return d.has(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="flagshipProvider":!1;return!1},m=(e,t)=>{const r=e.getProperty(t);if(!r||!i.isPropertyAssignment(r))return;const o=r.getInitializerOrThrow();if(i.isStringLiteral(o)||i.isNoSubstitutionTemplateLiteral(o))return o.getLiteralValue()},v=e=>{const t=e.getArguments()[0];if(t&&i.isObjectLiteralExpression(t)){const r=m(t,"binding");if(r!==void 0&&r.length>0)return{bindingName:r,mode:"binding",provider:"flagship"}}return{mode:"http",provider:"flagship"}},h=e=>f(e.getArguments()[0],"provider"),P=(e,t)=>{const r=p(t,c);if(!l(r))return;const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=g(o);if(!n||!i.isCallExpression(n))return{provider:"custom"};const s=h(n);if(s&&i.isCallExpression(s)){const a=s.getExpression();if(i.isIdentifier(a)&&u(a))return v(s)}return{provider:"custom"}};export{c as FLAGS_FILENAME,P as discoverFlags};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as m}from"node:fs";import{join as x}from"node:path";import{SyntaxKind as d,Node as c}from"ts-morph";import{listLunoraSourceFiles as l,lunoraRelativePath as g,defaultExportExpression as P,handlerOf as E}from"./listLunoraSourceFiles-
|
|
1
|
+
import{existsSync as m}from"node:fs";import{join as x}from"node:path";import{SyntaxKind as d,Node as c}from"ts-morph";import{listLunoraSourceFiles as l,lunoraRelativePath as g,defaultExportExpression as P,handlerOf as E}from"./listLunoraSourceFiles-DsxeRYvh.mjs";import{c as S}from"./classify-procedure-call-RjsZg8AH.mjs";const y="notify.ts",v=new Set(["chat","inApp","send","webhook"]),p=new Set(["broadcast","send"]),N=e=>{const t=e.getInitializer();if(!t||!c.isCallExpression(t))return;const o=S(t);if(!o)return;const r=E(t,o.receiver);return r?{exportName:e.getName(),handler:r,kind:o.kind}:void 0},h=e=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const r of o.getDeclarations()){const s=N(r);s&&t.push(s)}return t},a=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=e.getExpression();if((t==="notify"||t==="push")&&c.isIdentifier(o)&&o.getText()==="ctx")return t;if(t==="push"&&a(o)==="notify")return"push"},F=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=a(e.getExpression());if(o==="notify"&&v.has(t))return`ctx.notify.${t}`;if(o==="push"&&p.has(t))return`ctx.push.${t}`},A=e=>c.isPropertyAccessExpression(e)?a(e.getExpression())==="push"&&p.has(e.getName()):!1,T=(e,t)=>{const o=[];for(const r of l(t)){const s=e.getSourceFile(r)??e.addSourceFileAtPath(r),f=g(t,r);for(const n of h(s))if(!(n.kind!=="query"&&n.kind!=="mutation"))for(const i of n.handler.getDescendantsOfKind(d.PropertyAccessExpression)){const u=F(i);u!==void 0&&o.push({callee:u,exportName:n.exportName,file:f,kind:n.kind,line:i.getStartLineNumber()})}}return o},O=(e,t)=>{for(const o of l(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);for(const s of h(r))for(const f of s.handler.getDescendantsOfKind(d.PropertyAccessExpression))if(A(f))return!0}return!1},_=(e,t)=>{const o=x(t,y);if(!m(o))return;const r=e.getSourceFile(o)??e.addSourceFileAtPath(o),s=P(r);let f=!1,n=!1;if(s&&c.isCallExpression(s)){const i=s.getArguments()[0];i&&c.isObjectLiteralExpression(i)&&(f=i.getProperty("webPush")!==void 0,n=i.getProperty("fcm")!==void 0)}return{hasFcm:n,hasWebPush:f,usesPush:O(e,t)}};export{y as NOTIFY_FILENAME,T as discoverNotifyCalls,_ as discoverNotifyConfig};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as g}from"node:fs";import{join as l}from"node:path";import{LunoraError as d}from"@lunora/errors";import{queueDefaultName as p,queueBindingName as f}from"@lunora/queue";import{SyntaxKind as y,Node as s}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{stringPropertyFor as h}from"./listLunoraSourceFiles-
|
|
1
|
+
import{existsSync as g}from"node:fs";import{join as l}from"node:path";import{LunoraError as d}from"@lunora/errors";import{queueDefaultName as p,queueBindingName as f}from"@lunora/queue";import{SyntaxKind as y,Node as s}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{stringPropertyFor as h}from"./listLunoraSourceFiles-DsxeRYvh.mjs";const q="queues.ts",b=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineQueue";for(const e of t.getDeclarations())if(s.isImportSpecifier(e))return e.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/queue"?!1:e.getNameNode().getText()==="defineQueue";return!1},c=h("queue"),N=(r,t,e)=>{if(s.isNumericLiteral(r))return r.getLiteralValue();throw a(r,`queue "${t}": \`${e}\` must be a static numeric literal — it is deploy configuration codegen writes into wrangler.jsonc`)},w=(r,t)=>{const e=r.getProperty("name");if(!e||!s.isPropertyAssignment(e))return;const n=c(e.getInitializerOrThrow(),t,"name");if(n.length===0)throw a(e,`queue "${t}": \`name\` must be a non-empty string when provided`);return n},P=(r,t)=>{const e=r.getArguments()[0];if(!e||!s.isObjectLiteralExpression(e))throw a(r,`queue "${t}": defineQueue must be passed an inline object literal`);const n={bindingName:f(t),exportName:t,mode:"push",name:w(e,t)??p(t),tuning:{}},o=e.getProperty("mode");if(o&&s.isPropertyAssignment(o)){const i=c(o.getInitializerOrThrow(),t,"mode");if(i!=="push"&&i!=="pull")throw a(o,`queue "${t}": \`mode\` must be "push" or "pull" (got ${JSON.stringify(i)})`);n.mode=i}const u=e.getProperty("deadLetterQueue");u&&s.isPropertyAssignment(u)&&(n.tuning.deadLetterQueue=c(u.getInitializerOrThrow(),t,"deadLetterQueue"));for(const i of["maxBatchSize","maxBatchTimeout","maxRetries","retryDelay"]){const m=e.getProperty(i);m&&s.isPropertyAssignment(m)&&(n.tuning[i]=N(m.getInitializerOrThrow(),t,i))}return n},E=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const n=e.getInitializer();if(n?.getKind()!==y.CallExpression)continue;const o=n,u=o.getExpression();if(!s.isIdentifier(u)||!b(u))continue;const i=e.getNameNode();if(!s.isIdentifier(i))throw a(i,"defineQueue exports must be plain named exports (no destructuring)");t.push(P(o,i.getText()))}return t},I=r=>{const t=new Map,e=new Map;for(const n of r){const o=t.get(n.name);if(o!==void 0)throw new d("DUPLICATE_QUEUE_NAME",`Duplicate queue name "${n.name}": produced by both "${o}" and "${n.exportName}". Deployed queue names must be unique across the project.`,{status:500});t.set(n.name,n.exportName);const u=e.get(n.bindingName);if(u!==void 0)throw new d("DUPLICATE_QUEUE_BINDING",`Duplicate queue binding "${n.bindingName}": produced by both "${u}" and "${n.exportName}". Queue export names must yield unique binding names.`,{status:500});e.set(n.bindingName,n.exportName)}},T=(r,t)=>{const e=l(t,q);if(!g(e))return[];const n=r.getSourceFile(e)??r.addSourceFileAtPath(e),o=E(n);return o.sort((u,i)=>u.exportName.localeCompare(i.exportName)),I(o),o};export{q as QUEUES_FILENAME,T as discoverQueues};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import{existsSync as b,mkdirSync as Cs,readFileSync as _t,writeFileSync as Fs,rmSync as Os}from"node:fs";import{join as E,dirname as ne}from"node:path";import{performance as Ae}from"node:perf_hooks";import{runAdvisor as Rs}from"@lunora/advisor";import{LunoraError as L}from"@lunora/errors";import{SyntaxKind as l,Node as i,VariableDeclarationKind as Ls,Project as ct}from"ts-morph";import{serializeSchemaSnapshot as Ds}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{toAdvisorContext as ks}from"./formatAdvisories-DwmUKYuc.mjs";import{s as Ms}from"./paths-C-9fwEgQ.mjs";import{C as re,o as zt,j as Ks,f as _s,k as zs,b as $s,c as Us,m as qs,e as Bs,p as Vs,d as Ws,i as js,l as Hs,g as Gs,q as Ys,n as Qs,a as Xs,h as Zs}from"./emit-BuaY_1hY.mjs";import{isD1GlobalTable as $t,isHyperdriveGlobalTable as Ut}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as Js}from"./AGENTS_FILENAME-DPIMTD_h.mjs";import{discoverContainers as en}from"./CONTAINERS_FILENAME-wDZs0S4p.mjs";import tn from"./discoverCrons-B2GXsB-m.mjs";import{diagnosticAt as ue}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as de}from"./module-specifiers-WF8iAydP.mjs";import{listLunoraSourceFiles as p,unwrapExpression as G,listSecurityScanFiles as Re,objectLiteralFromCallbackBody as qt,propertyInitializer as A,lunoraRelativePath as x,collectCallRows as w,collectSecurityCallRows as sn,limitNameOf as Bt,optionsObjectLiteral as Vt,isContextIdentifier as Ie,handlerOf as nn,isDatabaseAccessor as D,readTargetOf as Wt,enclosingExportName as rn}from"./listLunoraSourceFiles-DsxeRYvh.mjs";import on from"./readPackageDependencies-C6h6FZuP.mjs";import{discoverQueues as an}from"./QUEUES_FILENAME-Dd781zOQ.mjs";import{discoverSandboxUsage as cn}from"./discoverSandboxUsage-pJ42YuvL.mjs";import ln from"./discoverStorageRulesMetadata-BFiKUo5m.mjs";import{a as S,c as k,d as jt,e as un}from"./classify-procedure-call-RjsZg8AH.mjs";import{discoverWorkflows as dn}from"./WORKFLOWS_FILENAME-v3AJcUjy.mjs";import{gatePlatformFeatures as fn,resolveCodegenTarget as gn,readTargetDiagnostics as pn}from"./DEFAULT_TARGET-DtzlGawL.mjs";import{i as R,a as _,e as v,r as mn,b as hn,s as fe,c as xn,f as vn,d as En}from"./queries-TZaLWhWq.mjs";import{r as ge,s as Sn}from"./parse-validator-tdRHHDzh.mjs";import yn from"./discoverAuthApiCalls-EHm1O8uG.mjs";import lt from"./discoverFunctions-BwB7RhZd.mjs";import{i as An,r as Nn,e as bn}from"./unwrap-handler-return-Da99uRXX.mjs";import ut from"./discoverHttpRoutes-B0EVnVgb.mjs";import Pn from"./discoverHyperdriveCalls-CzRlqv_N.mjs";import In from"./discoverInserts-BP0Gl37o.mjs";import{m as Le,a as ie,s as Ht,d as wn}from"./index-D6xfnMEE.mjs";import{e as Gt}from"./exported-procedure-chains-CjlBrFjo.mjs";import Tn from"./discoverMigrations-BX86Fv9G.mjs";import{MUTATORS_FILENAME as Cn,isDefineMutatorCallee as Fn,discoverMutators as dt}from"./MUTATORS_FILENAME-B7EXNAFK.mjs";import On from"./discoverNondeterministicCalls-CJYIXWPw.mjs";import{discoverNotifyConfig as Rn,discoverNotifyCalls as Ln}from"./NOTIFY_FILENAME-DbuOgja2.mjs";import Dn from"./discoverR2sqlCalls-emIgm3TF.mjs";import kn from"./discoverRlsProcedures-CU7YMR3P.mjs";import Mn from"./discoverRlsMetadata-3Gs8U3ng.mjs";import Kn from"./discoverSchema-DoZtXwLg.mjs";import{secretKindOf as _n,redact as zn,isHeuristicSecretKind as $n,isSecretishName as Un}from"./redact-Cy14LEnc.mjs";import{discoverShapes as qn}from"./SHAPES_FILENAME-Bvd5kgsF.mjs";import{emitApp as Bn}from"./emitApp-nInCbDo8.mjs";import{buildOpenApiDocument as Vn,emitOpenApiModule as Wn}from"./buildOpenApiDocument-DCGde3iO.mjs";import{buildOpenRpcDocument as jn,emitOpenRpcModule as Hn}from"./OPENRPC_VERSION-D6-0Hn3B.mjs";import{buildSchemaSnapshot as Gn}from"./SchemaSnapshotParseError-lUWe6lPo.mjs";const ft=(e,t="api")=>{const s=new Map;for(const n of e){const o=Ms(n),r=s.get(o);if(r===void 0){s.set(o,n);continue}if(r!==n){const a=t==="api"?`the generated api.ts would declare "${o}" twice and the dispatch key "${o}:<fn>" would be ambiguous`:`the generated api.ts would declare "${o}" twice in HttpStreamsRef and again in the httpStreams object literal`;throw new L("INTERNAL",`@lunora/codegen: "${r}" and "${n}" both map to the ${t} namespace "${o}" — ${a}. Rename one file so the two differ by more than a non-identifier character (\`-\`, \`.\`, \`/\` and \`_\` all sanitize to \`_\`).`,{status:500})}}},Yn=(e,t={})=>{const{hasVectors:s=!0,scheduler:n=!1,storage:o=!1,usage:r}=t,a=[];e.tables.some(c=>$t(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=>Ut(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`"}),o&&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 r===void 0?[]:re)c.requiredPackage!==void 0&&r?.[c.key]===!0&&a.push({name:c.requiredPackage,reason:`\`ctx.${c.contextProperty??c.key}\` usage makes \`_generated/\` import \`${c.moduleSpecifier}\``});return a.filter((c,u)=>a.findIndex(d=>d.name===c.name)===u)},Qn=(e,t,s={})=>{if(t===void 0)return;const n=Yn(e,s).filter(r=>!t.has(r.name));if(n.length===0)return;const o=n.map(r=>` - ${r.name} — ${r.reason}`).join(`
|
|
2
|
+
`);throw new L("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
|
|
3
|
+
${o}
|
|
4
|
+
|
|
5
|
+
Install them with your package manager, then re-run codegen.`)},Xn="env.ts",Zn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return de(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},Jn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&de(n.getModuleSpecifierValue())}return!1},er=e=>{if(i.isIdentifier(e))return Zn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&Jn(t)}return!1},tr=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!er(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw ue(r,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},sr=(e,t)=>{const s=E(t,Xn);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=tr(n);if(o.length!==0){if(o.length>1)throw ue(n,`lunora/env.ts declares ${o.length.toString()} defineEnv() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},gt="ctx",Yt=e=>{const t=new Set,s=new Set([gt]),n=r=>{if(i.isObjectBindingPattern(r))for(const a of r.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&t.add(c)}};for(const r of e.getDescendantsOfKind(l.BindingElement)){if((r.getPropertyNameNode()?.getText()??r.getName())!==gt)continue;const a=r.getNameNode();i.isIdentifier(a)?s.add(a.getText()):n(a)}const o=r=>i.isIdentifier(r)&&s.has(r.getText());for(const r of e.getDescendantsOfKind(l.PropertyAccessExpression))o(r.getExpression())&&t.add(r.getName());for(const r of e.getDescendantsOfKind(l.VariableDeclaration)){const a=r.getInitializer();a!==void 0&&o(a)&&n(r.getNameNode())}return t},nr=(e,t)=>{const s=Object.fromEntries(re.map(n=>[n.key,!1]));for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=new Set(o.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=Yt(o);for(const c of re)if(!s[c.key]){if(r.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(re.every(c=>s[c.key]))break}return s},Qt="identity.ts",rr=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return de(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},or=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&de(n.getModuleSpecifierValue())}return!1},ir=e=>{if(i.isIdentifier(e))return rr(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&or(t)}return!1},ar=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!ir(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw ue(r,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},cr=(e,t)=>{const s=E(t,Qt);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=ar(n);if(o.length!==0){if(o.length>1)throw ue(n,`lunora/identity.ts declares ${o.length.toString()} defineIdentity() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},lr=(e,t)=>{const s=G(t);if(s===void 0||!i.isIdentifier(s))return s;const n=s.getText();return G(e.getDescendantsOfKind(l.VariableDeclaration).find(o=>o.getName()===n)?.getInitializer())},ur=e=>e!==void 0&&i.isObjectLiteralExpression(e)&&e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t))return t.getName()==="durable";if(!i.isPropertyAssignment(t)||t.getName()!=="durable")return!1;const s=t.getInitializer();return s===void 0||G(s)?.getText()!=="false"}),dr=(e,t)=>{const s={durableStreams:!1,secrets:!1};for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);if(s.secrets||(s.secrets=Yt(o).has("secrets")),s.durableStreams||(s.durableStreams=o.getDescendantsOfKind(l.CallExpression).some(r=>{const a=r.getExpression();return(i.isPropertyAccessExpression(a)?a.getName():a.getText())==="stream"&&r.getArguments().some(u=>ur(lr(o,u)))})),s.durableStreams&&s.secrets)break}return s},fr="createWorker",gr="extend",pt=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralValue():void 0,mt=e=>{const t=[],s=pt(A(e,"backupCron"));s!==void 0&&t.push(s);const n=A(e,"crons");if(n===void 0||!i.isObjectLiteralExpression(n))return t;for(const o of n.getProperties()){if(!i.isPropertyAssignment(o)&&!i.isMethodDeclaration(o))continue;const r=pt(o.getNameNode());r!==void 0&&t.push(r)}return t},pr=e=>{const t=S(e.getExpression()),[s]=e.getArguments();if(s===void 0)return[];if(t===fr)return i.isObjectLiteralExpression(s)?mt(s):[];if(t!==gr||!(i.isArrowFunction(s)||i.isFunctionExpression(s)))return[];const n=qt(s.getBody());return n===void 0?[]:mt(n)},mr=(e,t)=>{const s=[];for(const{filePath:n}of Re(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getDescendantsOfKind(l.CallExpression))s.push(...pr(r))}return[...new Set(s)]},Xt=e=>{if(e.kind==="id")return e.tableName;if(!(e.kind!=="array"&&e.kind!=="optional"))return e.inner===void 0?void 0:Xt(e.inner)},hr=e=>{const t=new Set(e.tables.map(s=>s.name));return e.tables.some(s=>Object.values(s.shape).some(n=>{const o=Xt(n);return o!==void 0&&t.has(o)}))},xr=(e,t)=>{const s=new Map,n=new Map,o=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.bindingName,`workflow "${r.exportName}"`),o.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const a=s.get(r.name);if(a!==void 0)throw new L("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${a} and agent "${r.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=n.get(r.bindingName);if(c!==void 0)throw new L("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${r.bindingName}": produced by both ${c} and agent "${r.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const u=o.get(r.className);if(u!==void 0)throw new L("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${u} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},vr=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:o}=e,r=cr(s,t),a=sr(s,t),c=dn(s,t),u=an(s,t),d=Js(s,t);xr(c,d);const h=en(s,t),m=ln(s,t),P=tn(s,t,c,d),M=mr(s,t),g=dr(s,t),T=cn(s,t),F=nr(s,t);F.browser=F.browser||T.usesSandboxBrowser;const U=fn(F,gn(n,e.target),{agents:d.length>0,commitOrderedTables:o.tables.some(N=>N.commitOrdered===!0),cronTriggers:P.length>0,crossShardFanout:o.tables.some(N=>typeof N.shardMode=="object"),durableStreams:g.durableStreams,globalTables:o.tables.some(N=>N.shardMode==="global"),queues:u.length>0,relationGraph:hr(o),secrets:g.secrets,vectorStore:o.vectorIndexes.length>0}),y=U.usage,O=U.signals.vectorStore!==!1,z=on(n),W=z??new Set,X=W.has("lunorash");Qn(o,z,{hasVectors:O,scheduler:y.scheduler||P.length>0,storage:y.storage||m.rules.length>0||Object.keys(zt(o)).length>0,usage:y});const K=b(E(t,"flags.ts")),C=b(E(t,"notify.ts"));return{agents:d,containers:h,crons:P,dataModelContent:_s(o),declaredDependencies:z,dependencies:W,entryCronTriggers:M,env:a,featureUsage:y,hasFlags:K,hasNotify:C,identity:r,platformGate:{...U,diagnostics:[...pn(n,e.target),...U.diagnostics]},queues:u,serverContent:Ks({agents:d,containers:h,env:a,hasAccessFacade:y.access,hasAi:y.ai,hasAnalytics:y.analytics,hasBrowser:y.browser,hasVectors:O,hasFlags:K,hasHyperdrive:y.hyperdrive,hasImages:y.images,hasKv:y.kv,hasNotify:C,hasPayments:y.payments,hasPipelines:y.pipelines,hasR2sql:y.r2sql,hasX402:y.x402,identity:r,queues:u,schema:o,storageRuleBuckets:m.rules.map(N=>N.bucket),useUmbrella:X,workflows:c}),storageRulesMetadata:m,usesSandbox:T.usesSandboxBrowser||T.usesSandboxContainer||T.usesSandboxFs,useUmbrella:X,workflows:c}},Zt=new Set(["delete","get","head","options","patch","post","put"]),Er=new Set(["handler","stream"]),Sr=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,ht=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),yr=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Zt.has(t.getName()))return;const s=t.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!i.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},Ar=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||Zt.has(n.getName()))break;s=n.getExpression()}return yr(s)},Nr=e=>{for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression))if(ht.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&ht.has(s.getText()))return!0}return!1},br=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||!Er.has(n.getName()))return;const o=Ar(s);if(!o||!Sr.test(o.path))return;const r=s.getArguments()[0],a=r!==void 0&&(i.isArrowFunction(r)||i.isFunctionExpression(r))&&Nr(r);return{exportName:e.getName(),file:t,method:o.method,path:o.path,usesGuard:a}},Pr=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=br(o,t);r&&s.push(r)}return s},Ir=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Pr(o,x(t,n)))}return s},wr=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",Tr=(e,t)=>{if(!wr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!R(s)||_(s)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},Cr=(e,t)=>w(e,t,Tr),Fr=new Set(["generateText","streamText"]),Or=new Set(["messages","prompt","system"]),Rr=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],Lr=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const o of Rr)if(o.methods.has(s)&&o.prefixes.some(r=>n===r||n.startsWith(`${r}.`)))return`${n}.${s}`},Dr=e=>{for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=Lr(t);if(s!==void 0)return s}},kr=e=>{const t=new Set,s=e.getFirstAncestor(r=>i.isArrowFunction(r)||i.isFunctionExpression(r)||i.isFunctionDeclaration(r)),[n]=s?.getParameters()??[],o=n?.getNameNode();if(o===void 0||!i.isObjectBindingPattern(o))return t;for(const r of o.getElements()){const a=r.getPropertyNameNode()?.getText()??r.getName(),c=r.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const u of c.getElements())t.add(u.getName())}return t},Mr=e=>{if(mn(e))return!0;const t=kr(e);return t.size===0?!1:e.getDescendantsOfKind(l.Identifier).some(s=>t.has(s.getText()))},Kr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!Or.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&Mr(s))return!0}return!1},_r=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=S(n.getExpression());if(o===void 0||!Fr.has(o))continue;const[r]=n.getArguments();if(r===void 0||!i.isObjectLiteralExpression(r))continue;let a;for(const c of r.getDescendantsOfKind(l.CallExpression))if(S(c.getExpression())==="tool"&&(a=Dr(c),a!==void 0))break;a!==void 0&&s.push({exportName:v(n),file:t,line:n.getStartLineNumber(),method:o,sideEffect:a,userInputDerived:Kr(r)})}return s},zr=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(..._r(o,x(t,n)))}return s},$r=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},Ur=(e,t)=>{if(!$r(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!R(s)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},qr=(e,t)=>w(e,t,Ur),De=(e,t=new Set)=>{if(t.has(e))return!0;t.add(e);try{return e.getProperties().some(s=>{if(!i.isSpreadAssignment(s))return!1;const n=ge(s.getExpression());return n===void 0||De(n,t)})}finally{t.delete(e)}},Br=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer(),o=n===void 0?void 0:ge(n);return o===void 0?{objects:[],opaque:!0}:{objects:[o],opaque:De(o)}},Vr=e=>{const t=[];let s=!1,n=e;for(;i.isCallExpression(n);){const o=n.getExpression();if(!i.isPropertyAccessExpression(o))break;if(o.getName()==="input"){const r=n.getArguments()[0],a=r!==void 0&&i.isExpression(r)?ge(r):void 0;a===void 0?s=!0:(t.push(a),s||=De(a))}n=o.getExpression()}return{objects:t,opaque:s}},ke=(e,t)=>t?Vr(t):Br(e),Jt=(e,t)=>{if(t.has(e))return[];t.add(e);try{return e.getProperties().flatMap(s=>{if(i.isSpreadAssignment(s)){const n=ge(s.getExpression());return n===void 0?[]:Jt(n,t)}return i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)?[s.getName()]:[]})}finally{t.delete(e)}},Wr=e=>e.flatMap(t=>Jt(t,new Set)),jr=new Set(["check","length","max"]),we=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!(!i.isPropertyAccessExpression(t)||t.getExpression().getText()!=="v"))return t.getName()},Hr=e=>[e,...e.getDescendants()].filter(t=>we(t)!==void 0),Gr=e=>{let t=e;for(;;){const s=t.getParent();if(!s||!i.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;const n=s.getParent();if(!n||!i.isCallExpression(n)||n.getExpression()!==s)return!1;if(jr.has(s.getName()))return!0;t=n}},Yr=e=>{const t=[],s=[];for(const n of e)for(const o of n.getProperties()){if(!i.isPropertyAssignment(o))continue;const r=o.getInitializer();if(!r)continue;const a=Hr(r),c=o.getName();a.some(u=>we(u)==="any")?t.push(c):a.some(u=>we(u)==="string"&&!Gr(u))&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Qr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=k(s);if(n?.visibility!=="public")return;const{objects:o}=ke(s,n.receiver),{anyArgs:r,unboundedStringArgs:a}=Yr(o);if(!(r.length===0&&a.length===0))return{anyArgs:r,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Xr=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=Qr(o,t);r&&s.push(r)}return s},Zr=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Xr(o,x(t,n)))}return s},Ne=e=>e?.getKind()===l.TrueKeyword,Jr=e=>e?.getKind()===l.FalseKeyword,eo=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,to=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),so=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&S(t.getExpression())==="scim"),no=e=>e!==void 0&&i.isCallExpression(e)&&to.has(S(e.getExpression())??""),ro=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),oo=e=>{const t=A(e,"advanced"),s=A(e,"emailAndPassword"),n=A(e,"session");return{analyzable:!0,disableCsrfCheck:Ne(A(t,"disableCSRFCheck")),emailPasswordEnabled:Ne(A(s,"enabled")),requireEmailVerification:Ne(A(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:so(A(e,"plugins"))&&no(A(e,"database")),secureCookiesDisabled:Jr(A(t,"useSecureCookies")),sessionFreshAgeZero:eo(A(n,"freshAge")),trustedOriginsWildcard:ro(A(e,"trustedOrigins"))}},io=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),ao=(e,t)=>{if(S(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(r=>i.isSpreadAssignment(r)),o=s!==void 0&&i.isObjectLiteralExpression(s)&&!n?oo(s):io();return{exportName:v(e),file:t,line:e.getStartLineNumber(),...o}},co=(e,t)=>sn(e,t,ao),lo=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},uo=(e,t,s)=>{const n=lo(e.getExpression(),s);if(n===void 0)return;const o=e.getArguments()[s.argIndex];if(!(!o||!R(o)||_(o))&&!(s.requireUnmodifiedReach===!0&&!hn(o)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:n}},fo=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression)){const r=uo(o,t,s);r&&n.push(r)}return n},pe=(e,t,s)=>{const n=[];for(const o of p(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...fo(r,x(t,o),s))}return n},go=new Set(["content","pdf","scrape","screenshot"]),po=(e,t)=>pe(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:go}),mo=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),ho=new Set(["RateLimiter"]),xo=new Set(["extend"]),xt="lunora",vo=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],es=e=>{const t=[],s=[];let n=!1;for(const o of e.getProperties()){if(i.isSpreadAssignment(o)){n=!0;continue}if(i.isPropertyAssignment(o)){const r=o.getName();t.push(r),o.getInitializer()?.getKind()===l.TrueKeyword&&s.push(r);continue}(i.isShorthandPropertyAssignment(o)||i.isMethodDeclaration(o))&&t.push(o.getName())}return{analyzable:!n,presentKeys:t,trueKeys:s}},Te=e=>e&&i.isObjectLiteralExpression(e)?es(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Eo=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&qt(t.getBody());return s?es(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},So=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=S(n.getExpression());o!==void 0&&(mo.has(o)?s.push({callee:o,file:t,line:n.getStartLineNumber(),...Te(n.getArguments()[0])}):xo.has(o)&&s.push({callee:o,file:t,line:n.getStartLineNumber(),...Eo(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(l.NewExpression)){const o=S(n.getExpression());o===void 0||!ho.has(o)||s.push({callee:o,file:t,line:n.getStartLineNumber(),...Te(n.getArguments()[0])})}return s},yo=(e,t)=>{for(const s of vo){const n=E(t,s);if(!b(n))continue;const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=[];for(const a of o.getDescendantsOfKind(l.CallExpression))S(a.getExpression())===xt&&r.push({callee:xt,file:s,line:a.getStartLineNumber(),...Te(a.getArguments()[0])});return r}return[]},Ao=(e,t)=>{const s=[];for(const{displayPath:n,filePath:o}of Re(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);s.push(...So(r,n))}return s.push(...yo(e,ne(t))),s},vt="ctx.containers.",No=e=>{if(!e.startsWith(vt))return!1;const t=e.slice(vt.length);return t.length>0&&!t.includes(".")},bo=(e,t)=>pe(e,t,{argIndex:0,matchReceiver:No,methods:new Set(["get"])}),Po=new Set(["allow","deny","setAllowed"]),Io=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},wo=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!Io(e)))return{detail:"enableInternet: true",exportName:v(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},To=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!Po.has(s.getName()))return;const n=s.getExpression();if(!(!i.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),exportName:v(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},Co=(e,t)=>wo(e,t)??To(e,t),Fo=(e,t)=>w(e,t,Co),Oo=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Ro=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return Oo.has(s)?s:void 0},Lo=e=>{const t=[],s=[];for(const n of e.getProperties()){if(i.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o);const r=n.getInitializer();r&&i.isStringLiteral(r)&&r.getLiteralText()===""&&s.push(o);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n)||i.isGetAccessorDeclaration(n))&&t.push(n.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Do=(e,t)=>{const s=[];for(const{displayPath:n,filePath:o}of Re(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);for(const a of r.getDescendantsOfKind(l.CallExpression)){const c=Ro(a);if(c===void 0)continue;const u=a.getArguments()[0],d=u&&i.isObjectLiteralExpression(u)?Lo(u):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:d.analyzable,emptyKeys:d.emptyKeys,factory:c,file:n,line:a.getStartLineNumber(),presentKeys:d.presentKeys})}}return s},ko=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Mo=new Set(["dbRateLimit","rateLimit"]),Ko=e=>{const t=Vt(e);if(!t)return!1;const s=t.getProperty("failOpen");return s!==void 0&&i.isPropertyAssignment(s)&&s.getInitializer()?.getKind()===l.TrueKeyword},_o=(e,t)=>{const s=S(e.getExpression());if(s===void 0)return;const n=ko.get(s);if(n!==void 0)return{callee:s,exportName:v(e),failOpen:Ko(e.getArguments()[n]),file:t,limitName:Mo.has(s)?Bt(e):"",line:e.getStartLineNumber()}},zo=(e,t)=>w(e,t,_o),$o=new Set(["boolean","number","object","string"]),Uo=e=>{const t=e.getName();if(!$o.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="flags"&&Ie(s.getExpression()))return t;const n=s.getExpression();if(s.getName()==="details"&&i.isPropertyAccessExpression(n)&&n.getName()==="flags"&&Ie(n.getExpression()))return t},qo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=Uo(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(i.isStringLiteral(n)||i.isNoSubstitutionTemplateLiteral(n)))return;const o=n.getLiteralValue();return o.length>0?{key:o,type:s}:void 0},Bo=(e,t)=>{const s=new Map;for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getDescendantsOfKind(l.CallExpression)){const a=qo(r);a&&!s.has(a.key)&&s.set(a.key,a.type)}}return[...s.entries()].map(([n,o])=>({key:n,type:o})).toSorted((n,o)=>n.key.localeCompare(o.key))},Vo=e=>{const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const s=k(t);if(s?.kind!=="query")return;const n=nn(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},Et=e=>{const t=e.getParent();return t&&i.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},Wo=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!i.isIdentifier(t)||t.getText()!=="ctx")return;const s=Et(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=Et(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},jo=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const o=Wo(n);o!==void 0&&s.push({callee:o,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},Ho=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=Vo(o);r&&s.push(...jo(r,t))}return s},Go=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ho(o,x(t,n)))}return s},Yo=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Ie(t.getExpression())},Qo=e=>{if(e?.getKind()===l.TrueKeyword)return!0;if(e?.getKind()===l.FalseKeyword)return!1},Xo=(e,t)=>{if(!Yo(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const o=s.getLiteralValue(),r=Qo(n);if(!(o.length===0||r===void 0))return{defaultValue:r,exportName:v(e),file:t,key:o,line:e.getStartLineNumber()}},Zo=(e,t)=>w(e,t,Xo),Jo=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 o=n.getTypeAtLocation(e),r=o.getText(e);if(!r||r==="any"||r==="never"||An(r))return;const a=e.getSourceFile().getFilePath();return Nn(o,e,a)?bn(o,e,a,0,new Set):r},ei=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},ti=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},si=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression))ei(a)&&s.push({file:r,indexName:ti(a),line:a.getStartLineNumber()})}return s},Y=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,ts=e=>{const t=e.getArguments()[0],s=Y(t);if(s!==void 0)return s;if(t===void 0||!i.isObjectLiteralExpression(t))return;const n=t.getProperty("handler");return n!==void 0&&i.isPropertyAssignment(n)?Y(n.getInitializer()):void 0},ni=new Set(["delete","get","head","options","patch","post","put"]),ri=new Set(["handler","stream"]),oi=new Set(["runAction","runMutation"]),ii=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),Q=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,ss=(e,t)=>{if(!(e===void 0||!i.isObjectBindingPattern(e))){for(const s of e.getElements())if((s.getPropertyNameNode()?.getText()??s.getNameNode().getText())===t){const o=s.getNameNode();return i.isIdentifier(o)?o.getText():void 0}}},St=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?i.isIdentifier(s)?s.getText():void 0:ss(s,"ctx")},yt=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&i.isIdentifier(s)?s.getText():void 0:ss(s,"request")},At=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);i.isCallExpression(s)&&n.unshift(s);for(const o of n){const r=o.getExpression();if(!i.isPropertyAccessExpression(r))continue;const a=r.getName(),c=r.getExpression();if(oi.has(a)&&Q(c,t))return a;if(ii.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&Q(c.getExpression(),t))return`db.${a}`}},Nt=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(l.PropertyAccessExpression))if(n.getName()==="auth"&&Q(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(l.VariableDeclaration)){const o=n.getNameNode();if(!(!i.isObjectBindingPattern(o)||!Q(n.getInitializer(),t))){for(const r of o.getElements())if((r.getPropertyNameNode()?.getText()??r.getNameNode().getText())==="auth")return!0}}return!1},ai=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,ci=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="get"&&s.getName()!=="has")return!1;const n=s.getExpression();return i.isPropertyAccessExpression(n)&&n.getName()==="headers"&&Q(n.getExpression(),t)},li=e=>[...i.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(l.StringLiteral).map(t=>t.getLiteralText())],ns=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:li(s)},ui=(e,t)=>{const s=e.getText();for(let n=e.getParent();n!==void 0;n=n.getParent()){if(!i.isArrowFunction(n)&&!i.isFunctionExpression(n)||!n.getParameters().some(c=>c.getName()===s))continue;const o=n.getParent();if(!i.isCallExpression(o))return[];const r=o.getExpression();if(!i.isPropertyAccessExpression(r))return[];const a=r.getExpression();return i.isIdentifier(a)?ns(t,a.getText()):[]}return[]},di=e=>{const t=e.getArguments()[0];if(t===void 0)return[];if(i.isStringLiteral(t))return[t.getLiteralText()];if(!i.isIdentifier(t))return[];const s=e.getSourceFile(),n=ns(s,t.getText());return n.length>0?n:ui(t,s)},bt=(e,t)=>{if(t===void 0)return!1;const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);return i.isCallExpression(s)&&n.unshift(s),n.some(o=>ci(o,t)&&di(o).some(r=>ai.test(r)))},fi=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ri.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))return;const o=n.getName();if(ni.has(o)){const r=n.getExpression();return i.isIdentifier(r)&&r.getText()==="httpRoute"?o.toUpperCase():void 0}s=n.getExpression()}},gi=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=Y(e.getArguments()[0]),u=c&&St(c,!0);if(!c||u===void 0||bt(c,yt(c,!0)))return;const d=At(c,u);return d===void 0?void 0:{exportName:v(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:Nt(c,u),sideEffect:d}}const n=fi(e);if(n===void 0)return;const o=Y(e.getArguments()[0]),r=o&&St(o,!1);if(!o||r===void 0||bt(o,yt(o,!1)))return;const a=At(o,r);return a===void 0?void 0:{exportName:v(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:Nt(o,r),sideEffect:a}},pi=(e,t)=>w(e,t,gi),mi=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),hi=new Set(["append","set"]),rs=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",Pt=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(l.CallExpression)]:e.getDescendantsOfKind(l.CallExpression)).some(n=>mi.has(S(n.getExpression())??"")&&vn(n,t)),xi=(e,t)=>{if(Pt(e,t))return!0;const s=fe(e);return s!==void 0&&Pt(s,t)},Ce=(e,t)=>xn(e,t)&&!xi(e,t),vi=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=fe(e);return t!==void 0&&i.isNewExpression(t)&&S(t.getExpression())==="Headers"},ae=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=fe(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},Me=(e,t,s)=>{for(const n of e.getProperties())if(i.isPropertyAssignment(n)){const o=n.getInitializer();o!==void 0&&Ce(o,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:rs(n.getNameNode()),line:o.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(n)){const o=n.getNameNode();Ce(o,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:n.getName(),line:o.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(n)){const o=ae(n.getExpression());o!==void 0&&Me(o,t,s)}},os=(e,t)=>{const s=ae(e);if(s===void 0)return;const n=s.getProperty("headers");if(n===void 0||!i.isPropertyAssignment(n))return;const o=ae(n.getInitializer());o!==void 0&&Me(o,"response-init",t)},Ei=(e,t)=>{const s=S(e.getExpression());if(s==="Response")os(e.getArguments()[1],t);else if(s==="Headers"){const n=ae(e.getArguments()[0]);n!==void 0&&Me(n,"headers-ctor",t)}},Si=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName(),o=s.getExpression();if(n==="json"&&i.isIdentifier(o)&&o.getText()==="Response"){os(e.getArguments()[1],t);return}if(hi.has(n)&&vi(o)){const r=e.getArguments()[1];r!==void 0&&Ce(r,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:rs(e.getArguments()[0]),line:r.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},yi=(e,t)=>{for(const s of e.getDescendantsOfKind(l.NewExpression))Ei(s,t);for(const s of e.getDescendantsOfKind(l.CallExpression))Si(s,t)},Ai=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=Y(e.getArguments()[0]);if(n===void 0)return[];const o=n.getParameters()[1];if(o===void 0)return[];const r=o.getNameNode();if(!i.isIdentifier(r))return[];const a=[];return yi(n,{exportName:v(e),relativePath:t,requestName:r.getText(),rows:a}),a},Ni=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression))s.push(...Ai(n,t));return s},bi=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ni(o,x(t,n)))}return s},Pi=new Set(["auth","context.auth","ctx.auth"]),Ii="userId",wi=e=>{const t=new Set;for(const s of e.getProperties()){if(i.isSpreadAssignment(s))return;(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s))&&t.add(s.getName())}return t},Ti=(e,t)=>{const s=E(t,Qt);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const o of n.getDescendantsOfKind(l.CallExpression)){if(S(o.getExpression())!=="defineIdentity")continue;const[r]=o.getArguments();return r&&i.isObjectLiteralExpression(r)?wi(r):void 0}},It=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Pi.has(e.getExpression().getText())?e:void 0},Ci=e=>{if(i.isPropertyAccessExpression(e)&&It(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&It(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},Fi=(e,t,s)=>{const n=[];for(const o of e.getDescendants()){const r=Ci(o);r!==void 0&&n.push({declared:r===Ii||s.has(r),exportName:v(o),file:t,key:r,line:o.getStartLineNumber()})}return n},Oi=(e,t)=>{const s=Ti(e,t);if(s===void 0)return[];const n=[];for(const o of p(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...Fi(r,x(t,o),s))}return n},Ri=(e,t)=>{if(S(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=A(s,"key");if(!(!n||!R(n)||_(n)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},Li=(e,t)=>w(e,t,Ri),Di=new Set(["delete","get","getRaw","getWithMetadata","put"]),ki=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return pe(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.kv"||r.startsWith("ctx.kv."),methods:Di}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},Mi=new Set(["queue","send"]),wt=new Set(["bcc","cc","to"]),Ki=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Mi.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},_i=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return wt.has(t.getName())&&R(n)&&!_(n)}if(!i.isPropertyAssignment(t)||!wt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&R(s)&&!_(s)}):!1,zi=(e,t)=>{const s=Ki(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!_i(n)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s}},$i=(e,t)=>w(e,t,zi),Ui=e=>i.isPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?i.isComputedPropertyName(e.getNameNode()):!1,qi=e=>i.isPropertyAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?Ui(e):!0,is=(e,t=!1)=>{for(const s of e.getProperties()){if(qi(s))return!0;if(t)continue;if(!i.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!i.isObjectLiteralExpression(n)||is(n,!0))return!0}return!1},Bi=(e,t)=>{for(const s of p(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:o}of Gt(n))for(const r of Le(o)){const a=r.getArguments()[0];if(a!==void 0&&(!i.isObjectLiteralExpression(a)||is(a)))return!0}}return!1},Vi=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const o=ie(n);if(o===void 0||!i.isPropertyAssignment(n))continue;const r=n.getInitializer();if(!(!r||!i.isObjectLiteralExpression(r)))for(const a of r.getProperties()){const c=ie(a);c!==void 0&&s.push({column:c,strategy:Ht(a),table:o})}}return s},Wi=(e,t)=>{const s=new Map;for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:r}of Gt(o))for(const a of Le(r))for(const c of Vi(a)){const u=`${c.table}\0${c.column}`;s.has(u)||s.set(u,c)}}return{columns:[...s.values()]}},ji=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!i.isObjectLiteralExpression(n))return[];const o=[];for(const r of n.getProperties()){const a=ie(r);if(a===void 0||!i.isPropertyAssignment(r))continue;const c=r.getInitializer();if(!(!c||!i.isObjectLiteralExpression(c)))for(const u of c.getProperties()){const d=ie(u);if(d===void 0)continue;const h=Ht(u);h!=="custom"&&o.push({column:d,exportName:t,file:s,line:u.getStartLineNumber(),strategy:h,table:a})}}return o},Hi=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?k(s):void 0;return n?.receiver?Le(n.receiver).flatMap(o=>ji(o,e.getName(),t)):[]},Gi=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Hi(c,r))}return s},Yi=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return D(s)},Qi=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},Xi=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==l.CallExpression)return;const s=t;return Fn(s.getExpression())?s:void 0},Zi=e=>{const t=Xi(e),s=t===void 0?void 0:Qi(t);if(s===void 0)return[];const n=e.getNameNode(),o=i.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(l.CallExpression).filter(r=>Yi(r)).map(r=>({exportName:o,file:"lunora/mutators.ts",line:r.getStartLineNumber()}))},Ji=e=>e.getVariableDeclarations().flatMap(t=>Zi(t)),ea=(e,t)=>{const s=E(t,Cn);if(!b(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Ji(n)},ta=new Set(["delete","get","patch"]),sa=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),na=new Set(["auth","identity","session","user"]),ra=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),oa=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!D(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},ia=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(i.isAsExpression(s)||i.isParenthesizedExpression(s)||i.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!i.isVariableDeclaration(s))return;const n=s.getNameNode();return i.isIdentifier(n)?n.getText():void 0},aa=(e,t)=>e.getDescendantsOfKind(l.Identifier).some(s=>s.getText()===t),ca=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(l.ThrowStatement).length>0||e.getDescendantsOfKind(l.ReturnStatement).length>0,la=(e,t)=>e.getDescendantsOfKind(l.IfStatement).some(s=>aa(s.getExpression(),t)&&ca(s.getThenStatement())),ua=(e,t)=>{for(const s of e.getDescendantsOfKind(l.CallExpression)){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))continue;const o=n.getName();if(!ta.has(o))continue;const r=n.getExpression();if(!(D(r)||i.isPropertyAccessExpression(r)&&D(r.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&i.isIdentifier(c)&&c.getText()===t)return o}},da=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t)||i.isParenthesizedExpression(t)||i.isAsExpression(t)||i.isAwaitExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t.getText():void 0},fa=e=>e.getDescendantsOfKind(l.CallExpression).some(t=>t.getArguments().some(s=>da(s)==="ctx")),ga=e=>e.getDescendantsOfKind(l.BinaryExpression).some(t=>ra.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),pa=e=>{for(const t of e.getDescendantsOfKind(l.Identifier))if(sa.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&na.has(t.getName()))return!0}return fa(e)||ga(e)},ma=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=k(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const o=ts(s);if(o===void 0)return[];const r=n.receiver!==void 0&&jt(n.receiver,"use","rls"),a=pa(o),c=new Set,u=[];for(const d of o.getDescendantsOfKind(l.CallExpression)){const h=oa(d);if(h===void 0)continue;const m=ia(d);if(m===void 0||c.has(m)||!la(o,m))continue;const P=ua(o,m);P!==void 0&&(c.add(m),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:P,table:h,usesRls:r,visibility:n.visibility}))}return u},ha=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...ma(c,r))}return s},xa=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),va=new Set(["insert","insertManyUnsafe","patch","replace"]),Ea=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!va.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="db")return;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="ctx"?t:void 0},Sa=(e,t)=>{if(t!=="insertManyUnsafe")return i.isObjectLiteralExpression(e)?[e]:[];if(!i.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())i.isObjectLiteralExpression(n)&&s.push(n);return s},Tt=(e,t)=>{if(i.isPropertyAccessExpression(e)){const s=e.getExpression();return i.isIdentifier(s)&&s.getText()==="args"&&e.getName()===t}if(i.isElementAccessExpression(e)){const s=e.getExpression(),n=e.getArgumentExpression();return i.isIdentifier(s)&&s.getText()==="args"&&n!==void 0&&i.isStringLiteral(n)&&n.getLiteralValue()===t}return!1},ya=e=>{if(!i.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a));if(s===void 0)return;for(const a of s.getDescendantsOfKind(l.BinaryExpression)){const c=a.getLeft();if(i.isIdentifier(c)&&c.getText()===t&&a.getOperatorToken().getText().endsWith("="))return}const n=e.getStart();let o,r=-1;for(const a of s.getDescendantsOfKind(l.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getParent();if(!i.isVariableDeclarationList(c)||c.getDeclarationKind()!==Ls.Const)continue;const u=a.getInitializer(),d=a.getStart();u!==void 0&&d<n&&d>r&&(o=u,r=d)}return o},Aa=(e,t)=>{if(Tt(e,t))return!0;const s=ya(e);return s!==void 0&&Tt(s,t)},Na=(e,t,s,n,o)=>{const r=[];for(const a of e.getProperties()){let c,u;if(i.isPropertyAssignment(a)?(c=a.getName(),u=a.getInitializer()):i.isShorthandPropertyAssignment(a)&&(c=a.getName(),u=a.getNameNode()),!(c===void 0||u===void 0||!xa.has(c))&&R(u)&&!_(u)){const d=v(s),h=o(d)===c&&Aa(u,c);r.push({exportName:d,field:c,file:n,line:s.getStartLineNumber(),method:t,...h&&{ownerScoped:!0}})}}return r},ba=(e,t,s)=>{const n=Ea(e.getExpression());if(n===void 0)return[];const o=e.getArguments()[1];return o?Sa(o,n).flatMap(r=>Na(r,n,e,t,s)):[]},Pa=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression))for(const r of ba(o,t,a=>s(a).owner)){const{visibility:a}=s(r.exportName);n.push(a===void 0?r:{...r,visibility:a})}return n},Ia=(e,t,s=[],n=[])=>{const o=[],r=new Map;for(const a of s)r.set(`${a.filePath}:${a.exportName}`,{visibility:a.visibility});for(const a of n){const c=`${a.filePath}:${a.exportName}`;r.set(c,{...r.get(c),owner:a.owner})}for(const a of p(t)){const c=e.getSourceFile(a)??e.addSourceFileAtPath(a),u=x(t,a);o.push(...Pa(c,u,d=>r.get(`${u}:${d}`)??{}))}return o},wa=["providerSubscriptionId","state"],Ta=["providerEventId","processedAt"],Ct=(e,t)=>t.every(s=>s in e.shape),Ca=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&Ct(t,wa)&&Ct(s,Ta)},Fa=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Oa=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Ra=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?Oa(t.getInitializer()):void 0},La=(e,t)=>{const s=S(e.getExpression());if(s===void 0||!Fa.has(s))return;const[n]=e.getArguments(),o=n&&i.isObjectLiteralExpression(n)?Ra(n):void 0;return{callee:s,exportName:v(e),file:t,line:e.getStartLineNumber(),...o===void 0?{}:{toleranceSeconds:o}}},Da=(e,t)=>w(e,t,La),ka=new Set(["defineQueue","defineWorkflow"]),Ma=new Set(["run","runAction","runMutation","runQuery"]),Ka=new Set(["api","internal"]),_a=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},za=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!i.isPropertyAssignment(s))return;const n=s.getInitializer();if(n&&(i.isArrowFunction(n)||i.isFunctionExpression(n)))return n},as=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},cs=(e,t)=>e===t||e.startsWith(`${t}.`),ls=e=>{const t=e.getDescendantsOfKind(l.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},Ft=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e||i.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(i.isBindingElement(t)&&t.getNameNode()===e)},us=e=>{const t=e.getDescendantsOfKind(l.Identifier).filter(s=>Ft(s));return i.isIdentifier(e)&&Ft(e)&&t.push(e),t},$a=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(l.BindingElement).map(s=>s.getName())},Ua=e=>{const t=as(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(l.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const o=n.getInitializer(),r=i.isVariableDeclarationList(o)?o.getDeclarations()[0]?.getNameNode():void 0;r&&i.isIdentifier(r)&&s.push(`${r.getText()}.body`)}return s},qa=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:Ua(e),o=new Set,r=a=>ls(a).some(c=>n.some(u=>cs(c.getText(),u)))?!0:us(a).some(c=>o.has(c.getText()));for(const a of e.getDescendantsOfKind(l.VariableDeclaration)){const c=a.getInitializer();if(c&&r(c))for(const u of $a(a))o.add(u)}return{names:o,prefixes:n}},Ba=(e,t)=>ls(e).some(s=>t.prefixes.some(n=>cs(s.getText(),n)))?!0:us(e).some(s=>t.names.has(s.getText())),Va=e=>{if(e===void 0||!i.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;i.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const n=t.at(-1);if(!(n===void 0||!i.isIdentifier(s)||!Ka.has(s.getText())||t.length<2))return{exportName:n,file:t.slice(0,-1).join("/")}},Wa=(e,t,s)=>{const n=as(e,0);if(n===void 0)return[];const o=qa(e,t,n),r=[];for(const a of e.getDescendantsOfKind(l.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!Ma.has(c.getName())||c.getExpression().getText()!==n)continue;const u=a.getArguments()[1];if(!u||!Ba(u,o))continue;const d=Va(a.getArguments()[0]);d!==void 0&&r.push({dispatchKind:t,file:s,handlerExport:v(a),line:a.getStartLineNumber(),targetExport:d.exportName,targetFile:d.file})}return r},ja=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=_a(n);if(o===void 0||!ka.has(o))continue;const r=za(n);r!==void 0&&s.push(...Wa(r,o==="defineQueue"?"queue":"workflow",t))}return s},Ha=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ja(o,x(t,n)))}return s},Ot={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},Rt=new Set(["account","credential","member","passkey","session","user"]),Ga=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),Ya=e=>{const s=Ga(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return Rt.has(s)||Rt.has(n)},Qa=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Xa=(e,t)=>{const{objects:s,opaque:n}=ke(e,t);return Wr(s).some(o=>Qa(o))?!0:n?void 0:!1},Za=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Ja=e=>{if(i.isCallExpression(e))return e;if(!i.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&i.isCallExpression(s)?s:void 0},oe={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},ec=e=>{const t=Ja(e),s=t?S(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=Za(t);return{...oe,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in Ot?{...oe,[Ot[s]]:!0}:oe},tc=e=>{const t={...oe};let s=e;for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))break;const o=n.getName()==="use"?s.getArguments()[0]:void 0;if(o){const r=ec(o);t.usesCaptcha||=r.usesCaptcha,t.usesEmailGate||=r.usesEmailGate,t.usesMask||=r.usesMask,t.usesRateLimit||=r.usesRateLimit,t.usesRls||=r.usesRls}s=n.getExpression()}return t},sc=new Set(["insert","insertMany","insertManyUnsafe","replace"]),nc=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!sc.has(t.getName()))return!1;const s=t.getExpression();if(!D(s))return!1;const o=e.getArguments()[0];return!o||!(i.isStringLiteral(o)||i.isNoSubstitutionTemplateLiteral(o))?!1:Ya(o.getLiteralText())},rc=new Set(["create","runAfter","runAt","send","sendBatch"]),oc=new Set(["queues","scheduler","workflows"]),ic=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!rc.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&oc.has(s.getName())){const n=s.getExpression();if(i.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},ac=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return D(s)},ds=new Set(["generateObject","generateText","streamObject","streamText"]),cc=e=>{const t=S(e.getExpression());return t!==void 0&&ds.has(t)},lc=e=>{const t=S(e.getExpression());if(t===void 0||!ds.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(n=>i.isSpreadAssignment(n))?!1:!s.getProperty("maxOutputTokens")},uc=new Set(["log","span","trace"]),dc=new Set(["ai"]),fc=new Set(["email","mail"]),gc=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),be=(e,t)=>e.getDescendantsOfKind(l.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="ctx"}),pc=new Set([l.ArrowFunction,l.FunctionDeclaration,l.FunctionExpression,l.GetAccessor,l.MethodDeclaration,l.SetAccessor]),mc=new Set(["every","filter","flatMap","forEach","map","some"]),hc=new Set(["all","allSettled","race"]),xc=e=>{const t=e.getParent();if(!t||!i.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName();if(mc.has(n))return t;const o=s.getExpression();if(i.isIdentifier(o)&&o.getText()==="Promise"&&hc.has(n))return t},vc=e=>{let t=e.getParent();for(;t;){if(i.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(pc.has(t.getKind())){const s=xc(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},Ec=e=>{let t=e;for(;;){const s=t.getParent();if(!i.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;if(s.getName()==="catch")return!0;if(s.getName()!=="then"&&s.getName()!=="finally")return!1;const n=s.getParent();if(!i.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},Sc=e=>{let t=e;for(;;){const s=t.getParent();if(i.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return i.isCallExpression(s)&&s.getExpression()===t?s:void 0}},yc=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression)){if(!gc.has(n.getName()))continue;const o=n.getExpression();if(!i.isIdentifier(o)||o.getText()!=="ctx")continue;const r=Sc(n);r&&(t=!0,!vc(r)&&!Ec(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},Ac=e=>e.getDescendantsOfKind(l.ThrowStatement).some(t=>{const s=t.getExpression();if(!i.isNewExpression(s))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="Error"}),Lt="lunora-advisor-exempt",Nc=/^[\s*/]+/u,bc=/[\w-]/u,Pc=e=>{const s=(e.getFirstAncestorByKind(l.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
|
|
6
|
+
`);for(const n of s.split(`
|
|
7
|
+
`)){const o=n.replace(Nc,"");if(!o.startsWith(Lt))continue;const r=o.slice(Lt.length);if(bc.test(r.charAt(0)))continue;const a=r.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":r.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},Ic=e=>{const[t]=e.getArguments();if(t){if(i.isObjectLiteralExpression(t)){const s=t.getProperty("handler");return s?i.isPropertyAssignment(s)?s.getInitializer():i.isShorthandPropertyAssignment(s)?s.getNameNode():i.isMethodDeclaration(s)?s:void 0:void 0}return t}},wc=(e,t)=>{const s=Ic(t);if(!s)return;if(i.isArrowFunction(s)||i.isFunctionExpression(s)||i.isMethodDeclaration(s))return e;if(!i.isIdentifier(s))return;const n=s.getSourceFile(),o=s.getText(),r=n.getVariableDeclaration(o)?.getInitializer();return r&&(i.isArrowFunction(r)||i.isFunctionExpression(r))?r:n.getFunction(o)},Tc=e=>{let t=!1,s=!1,n=!1,o=!1,r=!1;for(const u of e.getDescendantsOfKind(l.CallExpression))if(nc(u)&&(r=!0),ic(u)&&(t=!0),ac(u)&&(o=!0),cc(u)&&(s=!0),lc(u)&&(n=!0),r&&t&&o&&n)break;const{handlesErrors:a,reachesOutbound:c}=yc(e);return{callsMail:be(e,fc),emitsEvent:be(e,uc),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||be(e,dc),throwsBareError:Ac(e),unboundedAiGeneration:n,usesInsertManyUnsafe:o,writesUserTable:r}},Cc=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=k(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const o=n.receiver?tc(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},r=wc(e,s);return{...r?Tc(r):{},...Pc(e),...o,analyzableBody:r!==void 0,exportName:e.getName(),file:t,hasEmailArg:Xa(s,n.receiver),kind:n.kind,visibility:n.visibility}},Fc=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=Cc(o,t);r&&s.push(r)}return s},Oc=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Fc(o,x(t,n)))}return s},Rc=new Set(["dbRateLimit","rateLimit"]),Lc=e=>i.isArrowFunction(e)?e.getBody():e,Dc=e=>{if(!i.isArrowFunction(e))return;const t=e.getParameters()[0]?.getNameNode();return t!==void 0&&i.isIdentifier(t)?t:void 0},fs=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getExpression()===e&&t.getName()==="args"},gs=(e,t)=>{const s=t.getSymbol();return s===void 0?[]:e.getDescendantsOfKind(l.Identifier).filter(n=>{if(n.getSymbol()!==s)return!1;const o=n.getParent();return!(i.isPropertyAccessExpression(o)&&o.getNameNode()===n)})},kc=(e,t)=>R(e)||t!==void 0&&gs(e,t).some(s=>fs(s)),Mc=(e,t)=>t===void 0?_(e):gs(e,t).some(s=>!fs(s)),Kc=(e,t)=>{const s=S(e.getExpression());if(s===void 0||!Rc.has(s))return;const n=A(Vt(e.getArguments()[2]),"key");if(!n)return;const o=Lc(n),r=Dc(n);if(!(!kc(o,r)||Mc(o,r)))return{callee:s,exportName:v(e),file:t,limitName:Bt(e),line:e.getStartLineNumber()}},_c=(e,t)=>w(e,t,Kc),zc=new Set(["findFirst","findFirstOrThrow","findMany","findUnique","get"]),$c=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!zc.has(t.getName()))return;const s=t.getExpression();if(D(s)){const n=e.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&D(s.getExpression()))return s.getName()},Uc=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&D(s.getExpression())){const n=t.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},qc=e=>{let t=G(e)??e;for(;i.isAwaitExpression(t);)t=G(t.getExpression())??t.getExpression();return t},ps=(e,t=!1)=>{const s=qc(e);if(i.isIdentifier(s)){if(t)return;const n=fe(s);return n===void 0?void 0:ps(n,!0)}if(i.isCallExpression(s))return $c(s)??Uc(s)},Bc=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(l.ReturnStatement)){const o=n.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),r=n.getExpression();o===e&&r!==void 0&&s.push(r)}return s},Vc=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=k(s);if(n?.kind!=="query")return[];const o=ts(s);if(o===void 0)return[];const r=n.receiver!==void 0&&un(n.receiver,"output"),a=n.receiver!==void 0&&jt(n.receiver,"use","mask"),c=new Set,u=[];for(const d of Bc(o)){const h=ps(d);h===void 0||c.has(h)||(c.add(h),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:h,usesMask:a,usesOutput:r,visibility:n.visibility}))}return u},Wc=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Vc(c,r))}return s},jc=e=>{if(!e||!i.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s)||i.isGetAccessorDeclaration(s))&&t.push(s.getName());return t},Hc=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?k(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Wt(r);if(a===void 0)continue;const c=jc(A(a.options,"with"));c.length!==0&&o.push({exportName:e.getName(),file:t,line:r.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return o},Gc=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Hc(c,r))}return s},ce=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===l.PlusToken){const t=ce(e.getLeft()),s=ce(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},Yc=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===l.PlusToken;)t=s,s=t.getParent();return t!==e&&ce(t)!==void 0},Qc=/(?:^|\/)__tests__\//u,Xc=/\.(?:spec|test)$/u,Zc=e=>Qc.test(e)||Xc.test(e),Jc=e=>{const t=e.getParent();if(t!==void 0){if(i.isVariableDeclaration(t)||i.isPropertyAssignment(t)||i.isPropertySignature(t))return t.getName();if(i.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.EqualsToken)return t.getLeft().getText()}},el=(e,t,s)=>$n(e)?!Zc(s)&&Un(Jc(t)):!0,tl=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(l.BinaryExpression),...e.getDescendantsOfKind(l.StringLiteral),...e.getDescendantsOfKind(l.NoSubstitutionTemplateLiteral)],o=new Set;for(const r of n){if(Yc(r))continue;const a=ce(r);if(a===void 0)continue;const c=_n(a);if(c===void 0||!el(c,r,t))continue;const u=r.getStartLineNumber(),d=`${String(u)}:${c}`;o.has(d)||(o.add(d),s.push({file:t,kind:c,line:u,preview:zn(a)}))}return s},sl=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...tl(o,x(t,n)))}return s},nl=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?k(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Wt(r);if(a===void 0)continue;const c=A(a.options,"includeDeleted");if(c===void 0)continue;const u=i.isTrueLiteral(c),d=!u&&R(c);!u&&!d||o.push({exportName:e.getName(),file:t,fromArgs:d,hardcodedTrue:u,line:r.getStartLineNumber(),table:a.table,visibility:n.visibility})}return o},rl=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...nl(c,r))}return s},ol=new Set(["query","unsafe"]),il=e=>{if(!i.isPropertyAccessExpression(e)||!ol.has(e.getName()))return!1;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return i.isIdentifier(s)&&s.getText()==="ctx"},al=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),cl=e=>e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()??"<module>",ll=(e,t)=>{if(!il(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!al(s)))return{exportName:cl(e),file:t,line:s.getStartLineNumber()}},ul=(e,t)=>w(e,t,ll),dl=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],fl=e=>{for(const[t,s]of dl)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},gl=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getImportDeclarations()){const a=r.getModuleSpecifierValue(),c=fl(a);c!==void 0&&s.push({file:x(t,n),line:r.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},pl=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),ml=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return pe(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:pl,requireUnmodifiedReach:!0}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},hl=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),xl=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,vl=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!i.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const o of e.getProperties()){if(i.isSpreadAssignment(o)){n=!0;continue}if(i.isPropertyAssignment(o)){const r=o.getName();t.push(r),r==="expiresInSeconds"&&(s=xl(o.getInitializer()));continue}(i.isShorthandPropertyAssignment(o)||i.isMethodDeclaration(o))&&t.push(o.getName())}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},El=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=hl.get(t);if(s===void 0)return;const n=e.getExpression().getText();return n==="ctx.storage"||n.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},Sl=(e,t)=>{const s=El(e.getExpression());if(s!==void 0)return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s.method,...vl(e.getArguments()[s.optionsIndex])}},yl=(e,t)=>w(e,t,Sl),Al=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:t.vectorStoreSupported&&t.vectorIndexCount>0,workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),Nl=(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"}),bl=(e,t)=>{if(t===void 0){const s=e.getArguments()[0];if(s===void 0||!i.isObjectLiteralExpression(s)||s.getProperty("args")===void 0)return!1}return ke(e,t).opaque},Pl=(e,t)=>{const s=[],n=(o,r)=>{const a=o.getInitializer();if(a===void 0||!i.isCallExpression(a))return;const c=k(a);c!==void 0&&bl(a,c.receiver)&&s.push(Nl(t,r,a.getStartLineNumber()))};for(const o of e.getVariableStatements().filter(r=>r.isExported()))for(const r of o.getDeclarations())n(r,r.getName());return s},Il=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n);o!==void 0&&s.push(...Pl(o,x(t,n)))}return s.toSorted((n,o)=>n.cacheKey.localeCompare(o.cacheKey))},wl=new Map([["AgentDefinition",{call:"defineAgent({ … })",file:"agents"}],["ContainerDefinition",{call:"defineContainer({ … })",file:"containers"}],["QueueDefinition",{call:"defineQueue({ … })",file:"queues",note:"A dropped queue has no caller to fail — its consumer is simply never wired."}],["RegisteredAction",{call:"action.input({ … }).action(handler)"}],["RegisteredLifecycleHook",{call:"onConnect(handler)",note:"Substitute the hook you called: `onConnect`, `onDisconnect` and `onShardInit` share one type, so codegen cannot tell which you wrote. A dropped hook has no caller to fail — it silently never fires."}],["RegisteredMigration",{call:"defineMigration({ … })",note:"A dropped migration never runs, so `lunora migrate up` reports nothing to do."}],["RegisteredMutation",{call:"mutation.input({ … }).mutation(handler)"}],["RegisteredMutator",{call:"defineMutator({ … })",file:"mutators"}],["RegisteredQuery",{call:"query.input({ … }).query(handler)"}],["RegisteredReactor",{call:"onQueryChange(select, handler)",note:"A dropped reactor has no caller to fail — it silently never runs."}],["RegisteredShape",{call:"defineShape({ … })",file:"shapes"}],["RegisteredStream",{call:"query.input({ … }).stream(handler)"}],["RegisteredWhisperAuthorizer",{call:"onWhisper(handler)",note:"A dropped authorizer has no caller to fail — the whisper topics it was meant to gate silently stay open to every socket on the shard."}],["WorkflowDefinition",{call:"defineWorkflow({ … })",file:"workflows"}]]),me=({byName:e,byPath:t},s,n)=>t.has(`${s}:${n}`)||e.has(n),ms=e=>!e.isAny(),Ke=e=>{const t=e.getType();if(!ms(t))return;const s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName(),n=s===void 0?void 0:wl.get(s);return n===void 0||s===void 0?void 0:{...n,typeName:s}},hs=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},xs={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."},Tl=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.`}),Cl={cause:"the binding is exported by a separate `export { … }` statement, and codegen reads the `export` keyword on the declaration itself",remediation:"Move the keyword onto the declaration and drop the separate export statement."},_e=(e,t,s,n,o)=>{const{call:r,file:a,note:c,typeName:u}=s,d=a!==void 0&&e!==a?a:void 0,h=d===void 0?o:Tl(d),m=c===void 0?h.remediation:`${c} ${h.remediation}`;return{cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally the registering call. 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 \`${u}\` but was not registered — ${h.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:u},name:"procedure_not_registered",remediation:d===void 0?`Assign the registration directly: \`export const ${t} = ${r};\`. ${m}`:m,title:"Procedure exists at runtime but is missing from the generated API"}},Fl=(e,t,s)=>{const n=[];for(const o of e.getVariableStatements().filter(r=>r.isExported()))for(const r of o.getDeclarations()){const a=r.getName();if(me(s,t,a)||!hs(r))continue;const c=Ke(r);c!==void 0&&n.push(_e(t,a,c,r.getStartLineNumber(),xs))}return n},Ol=(e,t,s)=>{if(me(s,t,"default"))return[];const n=[];for(const o of e.getExportAssignments().filter(r=>!r.isExportEquals())){const r=Ke(o.getExpression());r!==void 0&&n.push(_e(t,"default",r,o.getStartLineNumber(),xs))}return n},Rl=(e,t,s)=>{const n=[];for(const o of e.getExportDeclarations().filter(r=>r.getModuleSpecifier()===void 0))for(const r of o.getNamedExports()){const a=r.getAliasNode()?.getText()??r.getName();if(me(s,t,a))continue;const c=r.getLocalTargetDeclarations().find(d=>i.isVariableDeclaration(d));if(c===void 0||!hs(c))continue;const u=Ke(c);u!==void 0&&n.push(_e(t,a,u,r.getStartLineNumber(),Cl))}return n},Ll=(e,t,s)=>[...Fl(e,t,s),...Ol(e,t,s),...Rl(e,t,s)],Dl=(e,t,s)=>e.getVariableStatements().filter(n=>n.isExported()).flatMap(n=>n.getDeclarations()).filter(n=>me(s,t,n.getName())).filter(n=>{const o=n.getInitializer();return o!==void 0&&i.isCallExpression(o)&&i.isPropertyAccessExpression(o.getExpression())}).map(n=>({declaration:n,exportName:n.getName(),relativePath:t})),kl=({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"}),Ml=(e,t,s)=>{const n=[],o=[];for(const a of p(t)){const c=e.getSourceFile(a);if(c===void 0)continue;const u=x(t,a);n.push(...Ll(c,u,s)),o.push(...Dl(c,u,s))}const[r]=o;return r!==void 0&&o.every(({declaration:a})=>!ms(a.getType()))&&n.push(kl(r)),n.toSorted((a,c)=>a.cacheKey.localeCompare(c.cacheKey))},Kl=new Set(["when","where"]),Pe=new Set(["definePolicy","defineShape"]),_l=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const n=t.getName();return Pe.has(n)?n:void 0}if(!i.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(n)){const o=n.getNameNode().getText();return Pe.has(o)?o:void 0}const s=t.getText();return Pe.has(s)?s:void 0},zl=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,vs=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===l.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(zl(e))return"empty-object";if(i.isParenthesizedExpression(e))return vs(e.getExpression())}},ze=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),$l=e=>e.getDescendantsOfKind(l.ReturnStatement).filter(t=>ze(t)===e),Es=e=>e.getDescendantsOfKind(l.ConditionalExpression).filter(t=>ze(t)===e),Ul=e=>{const t=$l(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(l.IfStatement)!==void 0)||Es(e).length>0},ql=e=>e.getDescendantsOfKind(l.IfStatement).filter(t=>ze(t)===e),Fe=e=>e.getKind()===l.NullKeyword||e.getKind()===l.FalseKeyword||i.isIdentifier(e)&&e.getText()==="undefined"?!0:i.isNumericLiteral(e)?e.getLiteralValue()===0:i.isStringLiteral(e)&&e.getLiteralValue()==="",Bl=(e,t)=>Fe(e)||Fe(t),Vl=new Map([[l.EqualsEqualsEqualsToken,"positive"],[l.EqualsEqualsToken,"positive"],[l.ExclamationEqualsEqualsToken,"negative"],[l.ExclamationEqualsToken,"negative"]]),Dt=e=>!Fe(e)&&(i.isLiteralExpression(e)||e.getKind()===l.TrueKeyword),Wl=(e,t,s)=>{const n=Vl.get(e);if(n!==void 0)return Bl(t,s)?n==="positive"?"negative":"positive":Dt(t)||Dt(s)?void 0:n},H=e=>{if(i.isParenthesizedExpression(e))return H(e.getExpression());if(i.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken)return"negative";if(i.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=Wl(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===l.AmpersandAmpersandToken||t===l.BarBarToken){const n=H(e.getLeft()),o=H(e.getRight());return n===o?n:"indeterminate"}}return i.isIdentifier(e)||i.isPropertyAccessExpression(e)||i.isElementAccessExpression(e)||i.isCallExpression(e)?"positive":"indeterminate"},kt=e=>{if(e!==void 0){if(i.isReturnStatement(e))return e;if(i.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&i.isReturnStatement(t)?t:void 0}}},jl=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(l.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Hl=e=>i.isReturnStatement(e)?e.getExpression()??e:e,Gl=e=>{const t=[];for(const s of Es(e)){const n=H(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of ql(e)){const n=H(s.getExpression());if(n==="indeterminate")continue;const o=n==="negative"?kt(s.getThenStatement()):kt(s.getElseStatement())??jl(s);o!==void 0&&t.push(Hl(o))}return t},Yl=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},Ql=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!i.isObjectLiteralExpression(n))return[];const o=[];for(const r of n.getProperties()){if(!i.isPropertyAssignment(r)||!Kl.has(r.getName()))continue;const a=r.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Ul(a))for(const c of Gl(a)){const u=vs(c);u!==void 0&&o.push({exportName:Yl(e),file:s,form:u,key:r.getName(),line:c.getStartLineNumber(),owner:t})}}return o},Xl=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=_l(n);o!==void 0&&s.push(...Ql(n,o,t))}return s},Zl=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Xl(o,x(t,n)))}return s},Jl=new Set(["query","upsert","upsertMany"]),eu=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(Jl.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},tu=(e,t)=>{const s=eu(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const o=A(n,"namespace");if(!(!o||!R(o)||_(o)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s}},su=(e,t)=>w(e,t,tu),nu=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="workflows":i.isIdentifier(s)&&s.getText()==="workflows"},ru=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},ou=(e,t)=>{const s=[];for(const n of p(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression)){if(!nu(a))continue;const c=rn(a);c!==""&&s.push({exportName:c,file:r,line:a.getStartLineNumber(),workflow:ru(a)})}}return s},iu=".lunora-schema.json",Oe=(e,t)=>{b(e)&&_t(e,"utf8")===t||Fs(e,t,"utf8")},au=(e,t)=>{if(t===""){Os(e,{force:!0});return}Oe(e,t)},cu=e=>{const t=E(e,"package.json");if(b(t))try{const s=JSON.parse(_t(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},lu=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},uu=e=>{let t=b(e)?e:ne(e);for(;t&&t!==ne(t);){const s=E(t,"tsconfig.json");if(b(s))return s;t=ne(t)}},Mt=e=>e.replaceAll("\\","/"),du=(e,t,s)=>{if(s&&e.length>0){const r=e.map(a=>`"${a.exportName}"`).join(", ");throw new L("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${r}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const r of t.columns){const a=n.get(r.table)??[];a.push(r.column),n.set(r.table,a)}const o=t.columns.length>0;for(const r of e){if(r.table===void 0){if(o)throw new L("MASK_UNSUPPORTED",`defineShape "${r.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${r.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(r.table);if(a===void 0)continue;const c=a.map(u=>`"${u}"`).join(", ");throw new L("MASK_UNSUPPORTED",`defineShape "${r.exportName}" replicates table "${r.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},le=(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)},Kt=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,fu=8,gu=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:o,migrations:r,project:a,shapes:c,usesSandbox:u,useUmbrella:d,workflows:h}=e;let m=lt(a,o),P=dt(a,o),M=ut(a,o);ft([...m,...P].map(g=>g.filePath)),ft(M.filter(g=>g.stream).map(g=>g.filePath),"http-stream");for(let g=1;;g+=1){const T=Xs({agents:t,functions:m,httpRoutes:M,mutators:P,useUmbrella:d,workflows:h}),F=Zs({agents:t,functions:m,migrations:r,mutators:P,shapes:c,useUmbrella:d,usesSandbox:u});if(g>=fu||Kt(a,s,T)&&Kt(a,n,F))return{apiContent:T,functions:m,functionsContent:F,httpRoutes:M,mutators:P};le(a,s,T),le(a,n,F),m=lt(a,o),P=dt(a,o),M=ut(a,o)}},pu=e=>{const t=uu(e);return t?new ct({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new ct({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},ld=(e,t)=>{const s=p(t),n=E(t,"schema.ts");b(n)&&s.push(n);for(const c of s){const u=e.getSourceFile(c);u===void 0?e.addSourceFileAtPath(c):u.refreshFromFileSystemSync()}const o=new Set(s.map(c=>Mt(c))),r=Mt(t),a=`${r}/`;for(const c of e.getSourceFiles()){const u=c.getFilePath();(u===r||u.startsWith(a))&&!o.has(u)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const u=c.getFilePath();if(!(u===r||u.startsWith(a)||u.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},ud=e=>{const t=lu(),s=t?Ae.now():0,n=E(e.projectRoot,e.lunoraDirectory??"lunora"),o=E(n,"schema.ts");if(!b(o))throw new L("INTERNAL",`schema.ts not found at ${o}`);const r=e.project??pu(n);Sn(Jo);const a=Kn(r,o,e.projectRoot),{agents:c,containers:u,crons:d,dataModelContent:h,dependencies:m,entryCronTriggers:P,env:M,featureUsage:g,hasFlags:T,hasNotify:F,identity:U,platformGate:y,queues:O,serverContent:z,storageRulesMetadata:W,usesSandbox:X,useUmbrella:K,workflows:C}=vr({lunoraDirectory:n,project:r,projectRoot:e.projectRoot,schema:a,target:e.target}),N=E(n,"_generated"),Ss=E(N,"dataModel.ts"),ys=E(N,"server.ts"),As=E(N,"api.ts"),Ns=E(N,"functions.ts");le(r,Ss,h),le(r,ys,z);const Z=Tn(r,n),q=qn(r,n),{apiContent:$e,functions:B,functionsContent:Ue,httpRoutes:bs,mutators:J}=gu({agents:c,apiPath:As,generatedFunctionsPath:Ns,lunoraDirectory:n,migrations:Z,project:r,shapes:q,useUmbrella:K,usesSandbox:X,workflows:C}),ee=e.lint===!1?void 0:ks({adminRoutes:Ir(r,n),aiRawRuns:Cr(r,n),aiToolSideEffects:zr(r,n),argumentDerivedFetches:qr(r,n),argumentValidators:Zr(r,n),authApiCalls:yn(r,n),authConfigs:co(r,n),browserUrlAccesses:po(r,n),configCalls:Ao(r,n),containerKeyAccesses:bo(r,n),containerOverrides:Fo(r,n),containers:u,exportSinks:Do(r,n),staleMigrationImports:gl(r,n),failOpenGuards:zo(r,n),flagReads:Go(r,n),flagSecurityDefaults:Zo(r,n),geoIndexUsages:si(r,n),httpActionGuards:pi(r,n),httpHeaderWrites:bi(r,n),hyperdriveCalls:Pn(r,n),identityClaimReads:Oi(r,n),imageDeliveryUrlAccesses:Li(r,n),inserts:In(r,n),kvKeyAccesses:ki(r,n,B),mailRecipientAccesses:$i(r,n),maskProcedures:wn(r,n),maskStrategies:Gi(r,n),mutatorWrites:ea(r,n),nondeterministicCalls:On(r,n),normalizeIdAuthorizations:ha(r,n),notifyCalls:Ln(r,n),notifyConfig:Rn(r,n),mutators:J,ownerFieldWrites:Ia(r,n,B,J),unrestrictedWhereBranches:Zl(r,n),paymentWebhooks:Da(r,n),privilegedDispatches:Ha(r,n),procedureProtections:Oc(r,n),queries:En(r,n),queues:O,r2sqlCalls:Dn(r,n),ratelimitKeySelectors:_c(r,n),rawRowReturns:Wc(r,n),relationLoads:Gc(r,n),rlsProcedures:kn(r,n),schema:a,secretLiterals:sl(r,n),shapes:q,softDeleteReads:rl(r,n),sqlInterpolations:ul(r,n),storageKeyAccesses:ml(r,n,B),storageUploads:yl(r,n),vectorNamespaceAccesses:su(r,n),workflowCalls:ou(r,n),workflows:C,wranglerVariables:e.wranglerVariables}),qe=ee===void 0?[]:[...Rs(ee,{source:"static"}),...Ml(r,n,{byName:new Set([...C,...O,...c,...u].map(f=>f.exportName)),byPath:new Set([...B,...J,...q,...Z].map(f=>`${f.filePath}:${f.exportName}`))}),...Il(r,n)],Ps=Mn(r,n),Be=Wi(r,n);du(q,Be,Bi(r,n));const Is=T?Bo(r,n):[],he=y.signals.vectorStore!==!1,j=Al(g,{containerCount:u.length,cronCount:d.length,dependencies:m,hasPaymentTables:Ca(a.tables),queueCount:O.length,storageColumnCount:Object.keys(zt(a)).length,storageRuleCount:W.rules.length,vectorIndexCount:a.vectorIndexes.length,vectorStoreSupported:he,workflowCount:C.length}),Ve=t?Ae.now():0,xe=Gn(a,Z.map(f=>f.id)),We=zs({advisories:qe.filter(f=>f.name!=="procedure_type_check_unavailable"),advisorProcedures:ee?.procedureProtections??[],agents:c,containers:u,env:M,flagKeys:Is,hasAccessFacade:g.access,hasAi:g.ai,hasAnalytics:g.analytics,hasBrowser:g.browser,hasFlags:T,hasHyperdrive:g.hyperdrive,hasImages:g.images,hasKv:g.kv,hasNotify:F,hasPayments:g.payments,hasPipelines:g.pipelines,hasR2sql:g.r2sql,hasVectors:he,hasX402:g.x402,maskMetadata:Be,mutators:J,queues:O,rlsMetadata:Ps,schema:a,schemaSnapshot:xe,shapes:q,storageRules:W,studioFeatures:j,useUmbrella:K,workflows:C}),je=$s(q,m.has("@lunora/db"),K),He=Us(u,a.jurisdiction),Ge=qs(C),Ye=Bs(c),Qe=Vs(O),Xe=Ws(d),ws=js(j.scheduler),Ze=Hs(a.vectorIndexes),te=Gs(a,K),Je=Ys(m.has("@lunora/seed")),se=e.apiSpec??"openapi",ve=se==="openapi"||se==="both",Ee=se==="openrpc"||se==="both",et=Bn({emailAgents:c.filter(f=>f.onEmail===!0).map(f=>({bindingName:f.bindingName,exportName:f.exportName})),hasAccess:m.has("@lunora/cloudflare-access"),hasAi:g.ai,hasAnalytics:g.analytics,hasAuth:m.has("@lunora/auth"),hasBrowser:g.browser,hasFramework:m.has("@lunora/astro")||m.has("@lunora/svelte")||m.has("@lunora/vue"),hasGlobal:a.tables.some(f=>$t(f)),hasHyperdrive:g.hyperdrive,hasHyperdriveGlobal:a.tables.some(f=>Ut(f)),hasImages:g.images,hasKv:g.kv,hasKvIntrospector:j.kv,hasNotify:F,hasPayments:g.payments,hasR2sql:g.r2sql,hasQueue:O.some(f=>f.mode==="push"),hasScheduler:j.scheduler,hasSourcedTables:a.tables.some(f=>f.externalSource!==void 0),hasStorage:j.storage,hasVectors:he,hasWorkflow:C.length>0,hasX402:g.x402,identity:U,jurisdiction:a.jurisdiction,tableNames:a.tables.map(f=>f.name),useUmbrella:K,vectorIndexCount:a.vectorIndexes.length,voiceAgents:c.filter(f=>f.voice===!0&&f.voiceBindingName!==void 0).map(f=>({bindingName:f.voiceBindingName,exportName:f.exportName})),wantsOpenApi:ve,wantsOpenRpc:Ee}),tt=cu(e.projectRoot),st=Vn({functions:B,httpRoutes:bs,version:tt}),nt=jn({functions:B,version:tt}),rt=`${JSON.stringify(st,void 0,2)}
|
|
8
|
+
`,ot=`${JSON.stringify(nt,void 0,2)}
|
|
9
|
+
`,it=Wn(st),at=Hn(nt),Se=E(n,iu),Ts=b(Se),ye=[];if(!e.dryRun){b(N)||Cs(N,{recursive:!0});const f=($,V)=>{Oe(E(N,$),V),ye.push($)},I=($,V)=>{au(E(N,$),V),V!==""&&ye.push($)};f("app.ts",et),f("dataModel.ts",h),f("api.ts",$e),f("server.ts",z),f("functions.ts",Ue),f("shard.ts",We),f("crons.ts",Xe),f("vectors.ts",Ze),f("drizzle.global.ts",te.global),f("drizzle.shard.ts",te.shard),I("containers.ts",He),I("workflows.ts",Ge),I("agents.ts",Ye),I("queues.ts",Qe),I("scheduler.ts",ws),I("seed.ts",Je),I("collections.ts",je),I("openapi.json",ve?rt:""),I("openapi.ts",ve?it:""),I("openrpc.json",Ee?ot:""),I("openrpc.ts",Ee?at:""),(!Ts||e.updateSchemaBaseline===!0)&&Oe(Se,Ds(xe))}if(t){const f=Ae.now(),I=Math.round(f-s),$=Math.round(Ve-s),V=Math.round(f-Ve);console.error(`@lunora/codegen: codegen took ${I.toString()}ms (discovery ${$.toString()}ms, emit ${V.toString()}ms)`)}return{advisories:qe,advisorContext:ee,agents:c,containers:u,cronTriggers:[...new Set([...Qs(d),...P])],generated:{agents:Ye,api:$e,app:et,collections:je,containers:He,crons:Xe,dataModel:h,drizzleGlobal:te.global,drizzleShard:te.shard,functions:Ue,openApi:rt,openApiModule:it,openRpc:ot,openRpcModule:at,queues:Qe,seed:Je,server:z,shard:We,vectors:Ze,workflows:Ge},migrations:Z,outputDirectory:N,platformDiagnostics:y.diagnostics,queues:O,schemaSnapshot:xe,schemaSnapshotPath:Se,workflows:C,writtenFiles:ye}};export{iu as SCHEMA_SNAPSHOT_FILENAME,pu as createCodegenProject,uu as findTsconfig,ld as refreshCodegenProject,ud as runCodegen};
|
package/dist/packem_shared/{WORKFLOWS_FILENAME-BaSbufF2.mjs → WORKFLOWS_FILENAME-v3AJcUjy.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as p}from"node:fs";import{join as m}from"node:path";import{LunoraError as a}from"@lunora/errors";import{workflowDefaultName as u,workflowClassName as d,workflowBindingName as g}from"@lunora/workflow";import{Node as i,VariableDeclarationKind as w,SyntaxKind as x}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapToCallExpression as b,stringPropertyFor as h}from"./listLunoraSourceFiles-
|
|
1
|
+
import{existsSync as p}from"node:fs";import{join as m}from"node:path";import{LunoraError as a}from"@lunora/errors";import{workflowDefaultName as u,workflowClassName as d,workflowBindingName as g}from"@lunora/workflow";import{Node as i,VariableDeclarationKind as w,SyntaxKind as x}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapToCallExpression as b,stringPropertyFor as h}from"./listLunoraSourceFiles-DsxeRYvh.mjs";const k="workflows.ts",N=new Set(["do","sleep","sleepUntil","waitForEvent"]),y=n=>{const e=n.getSymbol();if(!e)return n.getText()==="defineWorkflow";for(const t of e.getDeclarations())if(i.isImportSpecifier(t))return t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/workflow"?!1:t.getNameNode().getText()==="defineWorkflow";return!1},E=h("workflow"),S=n=>{const e=n.getExpression();if(!i.isPropertyAccessExpression(e)||!N.has(e.getName()))return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="step"?!0:i.isIdentifier(t)&&t.getText()==="step"},D=n=>{const e=n.getProperty("handler");if(!e)return[];const t=i.isPropertyAssignment(e)?e.getInitializer():e;if(!t)return[];const o=[];for(const r of t.getDescendantsOfKind(x.CallExpression)){if(!S(r))continue;const s=r.getArguments()[0];!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s))||o.push({line:r.getStartLineNumber(),method:r.getExpression().getName(),name:s.getLiteralValue()})}return o},l=n=>{let e=n;for(;e&&(i.isAsExpression(e)||i.isSatisfiesExpression(e)||i.isParenthesizedExpression(e));)e=e.getExpression();return e},P=n=>{const e=l(n);if(e&&i.isObjectLiteralExpression(e))return e;if(!(!e||!i.isIdentifier(e)))for(const t of e.getSymbol()?.getDeclarations()??[]){const r=i.isVariableDeclaration(t)&&t.getVariableStatement()?.getDeclarationKind()===w.Const?l(t.getInitializer()):void 0;if(r&&i.isObjectLiteralExpression(r))return r}},W=(n,e)=>{const t=P(n.getArguments()[0]);if(!t)throw c(n,`workflow "${e}": defineWorkflow's argument must be an object literal, or a local \`const\` holding one — codegen reads \`name\` and the \`ctx.step.*\` calls out of it statically. Keep the handler wherever you like and pass it through: \`const config = { handler: myHandler }; export const ${e} = defineWorkflow(config);\`.`);const o={bindingName:g(e),className:d(e),exportName:e,name:u(e),steps:D(t)},r=t.getProperty("name");return r&&i.isPropertyAssignment(r)&&(o.name=E(r.getInitializerOrThrow(),e,"name")),o},I=n=>{const e=[];for(const t of n.getVariableDeclarations()){if(!t.isExported())continue;const o=b(t.getInitializer());if(!o)continue;const r=o.getExpression();if(!i.isIdentifier(r)||!y(r))continue;const s=t.getNameNode();if(!i.isIdentifier(s))throw c(s,"defineWorkflow exports must be plain named exports (no destructuring)");e.push(W(o,s.getText()))}return e},A=n=>{const e=new Map,t=new Map;for(const o of n){const r=e.get(o.name);if(r!==void 0)throw new a("DUPLICATE_WORKFLOW_NAME",`Duplicate workflow name "${o.name}": produced by both "${r}" and "${o.exportName}". Deployed workflow names must be unique across the project.`,{status:500});e.set(o.name,o.exportName);const s=t.get(o.bindingName);if(s!==void 0)throw new a("DUPLICATE_WORKFLOW_BINDING",`Duplicate workflow binding "${o.bindingName}": produced by both "${s}" and "${o.exportName}". Workflow export names must yield unique binding names.`,{status:500});t.set(o.bindingName,o.exportName)}},$=(n,e)=>{const t=m(e,k);if(!p(t))return[];const o=n.getSourceFile(t)??n.addSourceFileAtPath(t),r=I(o);return r.sort((s,f)=>s.exportName.localeCompare(f.exportName)),A(r),r};export{k as WORKFLOWS_FILENAME,$ as discoverWorkflows};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{w as a}from"./classify-procedure-call-RjsZg8AH.mjs";const l=s=>a(s,"use","rls");export{l as r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as o}from"ts-morph";import{unwrapExpression as a}from"./listLunoraSourceFiles-
|
|
1
|
+
import{Node as o}from"ts-morph";import{unwrapExpression as a}from"./listLunoraSourceFiles-DsxeRYvh.mjs";import{a as u}from"./module-specifiers-WF8iAydP.mjs";const A=t=>o.isIdentifier(t)?t.getText():o.isPropertyAccessExpression(t)?t.getName():void 0,y=(t,i)=>{const e=new Set;for(const r of t.getImportDeclarations())if(u(r.getModuleSpecifierValue()))for(const n of r.getNamedImports())n.getNameNode().getText()===i&&e.add(n.getAliasNode()?.getText()??n.getName());return e},h=(t,i)=>{if(o.isPropertyAccessExpression(t))return t.getName()===i;if(!o.isIdentifier(t))return!1;const e=t.getText();return e===i||y(t.getSourceFile(),i).has(e)},d=t=>{const i=t.getSymbol();if(!i)return t.getText();for(const e of i.getDeclarations())if(o.isImportSpecifier(e))return u(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText():void 0},p=t=>{const i=[];let e=a(t);for(;e&&o.isCallExpression(e);){const r=a(e.getExpression());if(!r||!o.isPropertyAccessExpression(r))return{root:void 0,steps:i};i.push({call:e,name:r.getName()}),e=a(r.getExpression())}return{root:e,steps:i}},f=t=>p(t).steps,x=(t,i,e)=>f(t).filter(r=>r.name===i).map(r=>r.call.getArguments()[0]).filter(r=>r!==void 0&&o.isCallExpression(r)&&h(r.getExpression(),e)),w=(t,i)=>f(t).some(e=>e.name===i),P=(t,i,e)=>x(t,i,e).length>0,l=new Set(["action","mutation","query","stream"]),m={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},N={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init",onWhisper:"whisper"},I=t=>t==="whisper"?"query":"mutation",C=t=>{const{root:i}=p(t);return i&&o.isIdentifier(i)?i:void 0},g=(t,i=!1)=>{const e=C(t);if(!e)return;const r=d(e);if(r===void 0){if(i)return;const n=e.getSymbol()?.getValueDeclaration();if(n&&o.isVariableDeclaration(n)){const s=n.getInitializer();return s?g(s,!0):void 0}return}return l.has(r)?"public":m[r]?"internal":void 0},E=t=>{const i=t.getName();if(!l.has(i))return;const e=t.getExpression(),r=a(e)??e,n=e===r?[r]:[e,r];if(n.some(c=>c.getType().getProperty("__lunoraProcedure"))){const c=n.some(v=>v.getType().getProperty("__lunoraVisibility"));return{kind:i,receiver:r,visibility:c?"internal":"public"}}const s=g(r);if(s)return{kind:i,receiver:r,visibility:s}},D=t=>{const i=t.getExpression();if(o.isPropertyAccessExpression(i))return E(i);if(!o.isIdentifier(i))return;const e=d(i);if(!e)return;if(l.has(e))return{kind:e,visibility:"public"};const r=m[e];if(r)return{kind:r,visibility:"internal"};const n=N[e];if(n)return{kind:I(n),lifecycle:n,visibility:"internal"}};export{A as a,f as b,D as c,P as d,w as e,x as w};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as d,lunoraRelativePath as l,handlerOf as f}from"./listLunoraSourceFiles-
|
|
1
|
+
import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as d,lunoraRelativePath as l,handlerOf as f}from"./listLunoraSourceFiles-DsxeRYvh.mjs";import{c as u}from"./classify-procedure-call-RjsZg8AH.mjs";const x=e=>{const n=e.getInitializer();if(!n||!s.isCallExpression(n))return;const r=u(n);if(!r||r.kind!=="query"&&r.kind!=="mutation")return;const t=f(n,r.receiver);return t?{exportName:e.getName(),handler:t,kind:r.kind}:void 0},p=(e,n)=>{if(!s.isPropertyAccessExpression(e)||e.getName()!==n)return;const r=e.getExpression();if(!s.isIdentifier(r)||r.getText()!=="ctx")return;const t=e.getParent();return t&&s.isPropertyAccessExpression(t)&&t.getExpression()===e?`ctx.${n}.${t.getName()}`:`ctx.${n}`},m=(e,n,r)=>{const t=[];for(const o of e.handler.getDescendantsOfKind(a.PropertyAccessExpression)){const i=p(o,r);i!==void 0&&t.push({callee:i,exportName:e.exportName,file:n,kind:e.kind,line:o.getStartLineNumber()})}return t},g=(e,n,r)=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const i of o.getDeclarations()){const c=x(i);c&&t.push(...m(c,n,r))}return t},N=(e,n,r)=>{const t=[];for(const o of d(n)){const i=e.getSourceFile(o)??e.addSourceFileAtPath(o);t.push(...g(i,l(n,o),r))}return t};export{N as d};
|
package/dist/packem_shared/{discoverAuthApiCalls-DoblmzUW.mjs → discoverAuthApiCalls-EHm1O8uG.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SyntaxKind as p,Node as s}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as g,enclosingExportName as d}from"./listLunoraSourceFiles-
|
|
1
|
+
import{SyntaxKind as p,Node as s}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as g,enclosingExportName as d}from"./listLunoraSourceFiles-DsxeRYvh.mjs";const m=r=>{const t=r.getExpression();if(!s.isPropertyAccessExpression(t))return!1;const e=t.getExpression();return s.isPropertyAccessExpression(e)?e.getName()==="authApi":s.isIdentifier(e)&&e.getText()==="authApi"},h=r=>{const t=r.getArguments()[0];if(t===void 0)return!1;if(!s.isObjectLiteralExpression(t))return!0;for(const e of t.getProperties())if((s.isPropertyAssignment(e)||s.isShorthandPropertyAssignment(e))&&e.getName()==="headers"||s.isSpreadAssignment(e))return!0;return!1},P=(r,t)=>{const e=[];for(const n of f(t)){const c=r.getSourceFile(n)??r.addSourceFileAtPath(n),l=g(t,n);for(const i of c.getDescendantsOfKind(p.CallExpression)){if(!m(i))continue;const o=d(i);if(o==="")continue;const a=i.getExpression(),u=s.isPropertyAccessExpression(a)?a.getName():"";e.push({exportName:o,file:l,hasHeaders:h(i),line:i.getStartLineNumber(),method:u})}}return e};export{P as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as L}from"@lunora/errors";import{CRON_SCHEDULE_KINDS as A,isValidCronExpression as O,warnIfSecondsLeading as S,compileCronSchedule as b}from"@lunora/scheduler";import{SyntaxKind as m,Node as s}from"ts-morph";import{diagnosticAt as f,CodegenDiagnosticError as I}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{i as R}from"./module-specifiers-WF8iAydP.mjs";import{s as $}from"./paths-C-9fwEgQ.mjs";import{listLunoraSourceFiles as y}from"./listLunoraSourceFiles-
|
|
1
|
+
import{LunoraError as L}from"@lunora/errors";import{CRON_SCHEDULE_KINDS as A,isValidCronExpression as O,warnIfSecondsLeading as S,compileCronSchedule as b}from"@lunora/scheduler";import{SyntaxKind as m,Node as s}from"ts-morph";import{diagnosticAt as f,CodegenDiagnosticError as I}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{i as R}from"./module-specifiers-WF8iAydP.mjs";import{s as $}from"./paths-C-9fwEgQ.mjs";import{listLunoraSourceFiles as y}from"./listLunoraSourceFiles-DsxeRYvh.mjs";const P=new Set([...A,"cron"]),D=e=>{const t=e.getSymbol();if(!t)return e.getText()==="cronJobs";for(const r of t.getDeclarations())if(s.isImportSpecifier(r))return R(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="cronJobs":!1;return!1},v=e=>{const t=new Set;for(const r of e.getVariableDeclarations()){const o=r.getInitializer();if(o?.getKind()!==m.CallExpression)continue;const i=o.getExpression();s.isIdentifier(i)&&D(i)&&t.add(r.getName())}return t},F=e=>{let t=e;for(;s.isCallExpression(t)||s.isPropertyAccessExpression(t);)t=t.getExpression();return s.isIdentifier(t)?t.getText():void 0},x=(e,t)=>{const r=e.getArguments()[t];return r&&(s.isStringLiteral(r)||s.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},_=(e,t)=>{if(s.isStringLiteral(e)||s.isNoSubstitutionTemplateLiteral(e)||s.isNumericLiteral(e))return e.getLiteralValue();if(s.isTrueLiteral(e))return!0;if(s.isFalseLiteral(e))return!1;if(s.isPrefixUnaryExpression(e)&&e.getOperatorToken()===m.MinusToken){const r=e.getOperand();if(s.isNumericLiteral(r))return-r.getLiteralValue()}if(s.isObjectLiteralExpression(e))return p(e,t);if(s.isArrayLiteralExpression(e))return e.getElements().map(r=>_(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 o of e.getProperties()){if(!s.isPropertyAssignment(o))throw f(o,`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 i=o.getInitializer();i&&(r[o.getName()]=_(i,t))}return r},C=(e,t,r)=>{const o=e.getArguments()[t];if(!o||!s.isPropertyAccessExpression(o))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 i=o.getName(),n=o.getExpression();if(!s.isPropertyAccessExpression(n))throw f(o,`Cron job "${r}" function reference must be of the form internal.file.fn (two property accesses).`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const a=n.getName();return`${$(a)}:${i}`},h=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),w=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),T=(e,t,r,o,i,n)=>{const a=e.getExpression();if(!s.isIdentifier(a)||a.getText()!==t)return;const c=r.get(e.getName());if(c)return n(c);throw f(e,`Cron job "${o}" targets ${t}.${e.getName()}, but no such ${i} is declared in lunora/${i}s.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})},V=(e,t,r,o,i)=>{const n=e.getArguments()[t];if(n&&s.isPropertyAccessExpression(n)){const a=T(n,"workflows",o,r,"workflow",h);if(a)return a;const c=T(n,"agents",i,r,"agent",w);return c||{functionPath:C(e,t,r)}}if(n&&s.isIdentifier(n)){const a=o.get(n.getText()),c=i.get(n.getText());if(a&&c)throw f(n,`Cron job "${r}" references "${n.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(n,`Cron job "${r}" references "${n.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,k=(e,t)=>{const r=x(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(!O(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 S(r,`cron expression for job "${t}"`),r},U=(e,t,r)=>{const o=e.getArguments()[1];if(!o||!s.isObjectLiteralExpression(o))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 b(t,p(o,r),r)}catch(i){if(i instanceof I)throw i;const n=i instanceof Error?i.message.replace(j,""):String(i);throw f(e,n,{code:"CRON_SCHEDULE_INVALID",name:"LunoraError",status:500})}},M=(e,t,r,o,i)=>{const n=t.getName();if(!P.has(n)||!r.has(F(t.getExpression())??""))return;const a=x(e,0);if(a===void 0||a.trim()==="")throw f(e,`A cron ".${n}(...)" registration must pass a non-empty string-literal name as its first argument.`,{code:"CRON_NAME_NOT_STATIC",name:"LunoraError",status:500});const c=n==="cron"?k(e,a):U(e,n,a),u=V(e,2,a,o,i),l=e.getArguments()[3];return{args:l&&s.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 L("DUPLICATE_CRON_NAME",`Duplicate cron job name "${r.name}": cron names must be unique across the project.`,{status:500});t.add(r.name)}},Q=(e,t,r=[],o=[])=>{const i=y(t),n=[],a=new Map(r.map(u=>[u.exportName,u])),c=new Map(o.map(u=>[u.exportName,u]));for(const u of i){const l=e.getSourceFile(u)??e.addSourceFileAtPath(u),g=v(l);if(g.size!==0)for(const d of l.getDescendantsOfKind(m.CallExpression)){const N=d.getExpression();if(!s.isPropertyAccessExpression(N))continue;const E=M(d,N,g,a,c);E&&n.push(E)}}return n.sort((u,l)=>u.name.localeCompare(l.name)),z(n),n};export{Q as default};
|
package/dist/packem_shared/{discoverFunctions-DRf4ucil.mjs → discoverFunctions-BwB7RhZd.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{s as x}from"./paths-C-9fwEgQ.mjs";import{listLunoraSourceFiles as P,lunoraRelativePath as E}from"./listLunoraSourceFiles-
|
|
1
|
+
import{s as x}from"./paths-C-9fwEgQ.mjs";import{listLunoraSourceFiles as P,lunoraRelativePath as E}from"./listLunoraSourceFiles-DsxeRYvh.mjs";import{b as f,c as b}from"./classify-procedure-call-RjsZg8AH.mjs";import{Node as s,SyntaxKind as A}from"ts-morph";import{p as N,r as m,a as v}from"./parse-validator-tdRHHDzh.mjs";import{u as y}from"./unwrap-handler-return-Da99uRXX.mjs";const F=i=>{const e=i.getArguments()[0];if(!e||!s.isObjectLiteralExpression(e))return"unknown";const t=e.getProperty("handler");if(!t||!s.isPropertyAssignment(t))return"unknown";const r=t.getInitializer();return!r||!(s.isArrowFunction(r)||s.isFunctionExpression(r))?"unknown":y(r)},z=i=>{const e=i.getArguments()[0];return!e||!(s.isArrowFunction(e)||s.isFunctionExpression(e))?"unknown":y(e)},C=i=>{let e={};for(const t of f(i)){if(t.name!=="input")continue;const r=t.call.getArguments()[0],n=r!==void 0&&s.isExpression(r)?m(r):void 0;n!==void 0&&(e={...v(n),...e})}return e},S=i=>{const e=f(i).find(r=>r.name==="output");if(!e)return;const t=e.call.getArguments()[0];return t&&s.isExpression(t)?N(t):void 0},u=(i,e)=>{const t=i.getProperty(e);if(t===void 0||!s.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&s.isStringLiteral(r)?r.getLiteralValue():void 0},d=(i,e)=>{const t=i.getProperty(e);if(t===void 0||!s.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&s.isNumericLiteral(r)?r.getLiteralValue():void 0},O=i=>{const e=i.getProperty("cache");if(e===void 0||!s.isPropertyAssignment(e))return;const t=e.getInitializer();if(t===void 0||!s.isObjectLiteralExpression(t))return;const r=u(t,"scope"),n=d(t,"maxAge"),o=d(t,"staleWhileRevalidate"),a=u(t,"tag"),c=u(t,"vary"),g={...n===void 0?{}:{maxAge:n},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(g).length===0?void 0:g},L=i=>{if(i===void 0||!s.isObjectLiteralExpression(i))return{};const e=O(i),t=i.getProperty("rest");return t!==void 0&&s.isPropertyAssignment(t)?{...e===void 0?{}:{cache:e},rest:t.getInitializer()?.getText()==="true"}:e===void 0?{}:{cache:e}},I=i=>{const e=f(i).find(t=>t.name==="expose");return e?L(e.call.getArguments()[0]):void 0},T=i=>{const e=i.getArguments()[0];if(!e||!s.isObjectLiteralExpression(e))return{};const t=e.getProperty("args");if(!t||!s.isPropertyAssignment(t))return{};const r=t.getInitializer(),n=r===void 0?void 0:m(r);return n===void 0?{}:v(n)},k=8,l=(i,e=0)=>{if(e>k)return;if(s.isCallExpression(i))return i;if(s.isParenthesizedExpression(i)||s.isAsExpression(i)||s.isSatisfiesExpression(i)||s.isNonNullExpression(i))return l(i.getExpression(),e+1);if(!s.isIdentifier(i)&&!s.isPropertyAccessExpression(i))return;const t=i.getSymbol()?.getValueDeclaration();return t?p(t,e+1):void 0},p=(i,e)=>{if(s.isVariableDeclaration(i)||s.isPropertyAssignment(i)){const t=i.getInitializer();return t?l(t,e):void 0}if(s.isShorthandPropertyAssignment(i)){const t=i.getValueSymbol()?.getValueDeclaration();return t?p(t,e+1):void 0}if(s.isBindingElement(i)){const t=i.getPropertyNameNode()?.getText()??i.getName(),o=i.getFirstAncestorByKind(A.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return o?p(o,e+1):void 0}},V=i=>{const e=i.getNameNode();if(s.isObjectBindingPattern(e)){const n=[];for(const o of e.getElements()){const a=l(o.getNameNode());a&&n.push([o.getName(),a])}return n}const t=i.getInitializer(),r=t&&(s.isCallExpression(t)?t:l(t));return r?[[i.getName(),r]]:[]},w=i=>{const e=b(i);if(e){if(e.receiver){const t=I(e.receiver),r=S(e.receiver);return{args:C(e.receiver),...t?{expose:t}:{},kind:e.kind,...r?{output:r}:{},returnType:z(i),visibility:e.visibility}}return e.lifecycle?{args:{},kind:e.kind,lifecycle:e.lifecycle,returnType:"void",visibility:e.visibility}:{args:T(i),kind:e.kind,returnType:F(i),visibility:e.visibility}}},h=(i,e,t)=>{const r=w(i);if(r)return{args:r.args,exportName:e,filePath:t,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},D=(i,e)=>{const t=[];for(const r of i.getExportAssignments()){if(r.isExportEquals())continue;const n=l(r.getExpression()),o=n?h(n,"default",e):void 0;o&&t.push(o)}return t},j=(i,e)=>{const t=[];for(const r of i.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations())for(const[o,a]of V(n)){const c=h(a,o,e);c&&t.push(c)}return t.push(...D(i,e)),t},R=i=>{const e=new Map;for(const t of i){const r=x(t.filePath),n=e.get(r);if(n&&n!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${n}" and "${t.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[n,t.filePath],status:500});e.set(r,t.filePath)}},W=(i,e)=>{const t=P(e),r=[];for(const n of t){const o=i.getSourceFile(n)??i.addSourceFileAtPath(n),a=E(e,n);r.push(...j(o,a))}return r.sort((n,o)=>`${n.filePath}:${n.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),R(r),r};export{W as default};
|
package/dist/packem_shared/{discoverHttpRoutes-_ME7hLcW.mjs → discoverHttpRoutes-B0EVnVgb.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i}from"ts-morph";import{p as m,a as l}from"./parse-validator-tdRHHDzh.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./listLunoraSourceFiles-
|
|
1
|
+
import{Node as i}from"ts-morph";import{p as m,a as l}from"./parse-validator-tdRHHDzh.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./listLunoraSourceFiles-DsxeRYvh.mjs";import{u as f}from"./unwrap-handler-return-Da99uRXX.mjs";const u=new Set(["delete","get","head","options","patch","post","put"]),g=new Set(["body","params","searchParams"]),E=new Set(["handler","stream"]),v=r=>{const e=r.getArguments()[0];if(e&&i.isStringLiteral(e))return e.getLiteralValue()},x=r=>{const e=r.getArguments()[0];return e&&i.isObjectLiteralExpression(e)?l(e):{}},P=r=>{if(!i.isCallExpression(r))return;const e=r.getExpression();if(!i.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const n=e.getExpression();if(!i.isIdentifier(n)||n.getText()!=="httpRoute")return;const s=v(r);return s===void 0?void 0:{method:o.toUpperCase(),path:s}},S=(r,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},n=r.getExpression();if(!i.isPropertyAccessExpression(n))return;let s=n.getExpression();for(;i.isCallExpression(s);){const a=s.getExpression();if(!i.isPropertyAccessExpression(a))break;const c=a.getName();if(u.has(c))break;if(g.has(c)){const p=x(s);o[c]={...p,...o[c]}}else if(c==="output"&&o.output===void 0){const p=s.getArguments()[0];p&&i.isExpression(p)&&(o.output=m(p))}s=a.getExpression()}const t=P(s);if(t)return o.method=t.method,o.path=t.path,o},A=r=>{const e=r.getArguments()[0];return!e||!(i.isArrowFunction(e)||i.isFunctionExpression(e))?"unknown":f(e)},T=(r,e,o,n)=>{const s=e.getName();if(!E.has(s))return;const t=S(r,s);if(!(t?.method===void 0||t.path===void 0))return{body:t.body,exportName:o,filePath:n,method:t.method,params:t.params,path:t.path,searchParams:t.searchParams,stream:t.stream,...t.stream?{chunkType:A(r)}:{},...t.output?{output:t.output}:{}}},b=(r,e)=>{const o=[];for(const n of r.getVariableStatements())if(n.isExported())for(const s of n.getDeclarations()){const t=s.getInitializer();if(!t||!i.isCallExpression(t))continue;const a=t.getExpression();if(!i.isPropertyAccessExpression(a))continue;const c=T(t,a,s.getName(),e);c&&o.push(c)}return o},F=(r,e)=>{const o=d(e),n=[];for(const s of o){const t=r.getSourceFile(s)??r.addSourceFileAtPath(s),a=h(e,s);n.push(...b(t,a))}return n.sort((s,t)=>`${s.method} ${s.path}`.localeCompare(`${t.method} ${t.path}`)||s.filePath.localeCompare(t.filePath)),n};export{F as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as o}from"./context-property-calls-DV-Pt4KS.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SyntaxKind as c,Node as n}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as u,enclosingExportName as g,isDatabaseAccessor as d}from"./listLunoraSourceFiles-
|
|
1
|
+
import{SyntaxKind as c,Node as n}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as u,enclosingExportName as g,isDatabaseAccessor as d}from"./listLunoraSourceFiles-DsxeRYvh.mjs";const m=t=>{const e=t.getExpression();if(!n.isPropertyAccessExpression(e)||e.getName()!=="insert")return!1;const r=e.getExpression();return d(r)},p=t=>{if(!n.isIdentifier(t))return;const e=t.getSymbol(),r=e?.getAliasedSymbol()?.getDeclarations()??e?.getDeclarations()??[];for(const i of r)if(n.isVariableDeclaration(i)){const s=i.getInitializer();if(s&&n.isStringLiteral(s))return s.getLiteralText()}},x=t=>{const e=t.getArguments()[0];return e?n.isStringLiteral(e)?e.getLiteralText():p(e)??"":""},v=(t,e)=>{const r=[];for(const i of f(e)){const s=t.getSourceFile(i)??t.addSourceFileAtPath(i),l=u(e,i);for(const o of s.getDescendantsOfKind(c.CallExpression)){if(!m(o))continue;const a=g(o);a!==""&&r.push({exportName:a,file:l,line:o.getStartLineNumber(),table:x(o)})}}return r};export{v as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./listLunoraSourceFiles-DsxeRYvh.mjs";import"./classify-procedure-call-RjsZg8AH.mjs";import{d as p}from"./index-D6xfnMEE.mjs";export{p as default};
|
package/dist/packem_shared/{discoverMigrations-B_sYrTyE.mjs → discoverMigrations-BX86Fv9G.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SyntaxKind as f,Node as s}from"ts-morph";import{diagnosticAt as u}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as m}from"./module-specifiers-WF8iAydP.mjs";import{listLunoraSourceFiles as p,lunoraRelativePath as h}from"./listLunoraSourceFiles-
|
|
1
|
+
import{SyntaxKind as f,Node as s}from"ts-morph";import{diagnosticAt as u}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as m}from"./module-specifiers-WF8iAydP.mjs";import{listLunoraSourceFiles as p,lunoraRelativePath as h}from"./listLunoraSourceFiles-DsxeRYvh.mjs";const I=r=>{const i=r.getSymbol();if(!i)return r.getText()==="defineMigration";for(const t of i.getDeclarations())if(s.isImportSpecifier(t))return m(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMigration":!1;return!1},d=(r,i)=>{const t=r.getProperty(i);if(!t||!s.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&s.isStringLiteral(e)?e.getLiteralValue():void 0},P=(r,i)=>{const t=r.getInitializer();if(t?.getKind()!==f.CallExpression)return;const e=t.getExpression();if(!s.isIdentifier(e)||!I(e))return;const o=t.getArguments()[0];if(!o||!s.isObjectLiteralExpression(o))return;const n=d(o,"id"),a=r.getName();if(n===void 0||n.trim()==="")throw u(o,`Migration "${a}" in "${i}" must declare \`id\` as a non-empty string literal so codegen can key the registry.`,{code:"MIGRATION_ID_NOT_STATIC",name:"LunoraError",status:500});return{exportName:a,filePath:i,id:n,table:d(o,"table")??""}},M=r=>{const i=new Map;for(const t of r){const e=i.get(t.id);if(e!==void 0)throw Object.assign(new Error(`Duplicate migration id "${t.id}": declared in both "${e}" and "${t.filePath}". Migration ids must be unique across the project.`),{code:"DUPLICATE_MIGRATION_ID",id:t.id,name:"LunoraError",paths:[e,t.filePath],status:500});i.set(t.id,t.filePath)}},y=(r,i)=>{const t=p(i),e=[];for(const o of t){const n=r.getSourceFile(o)??r.addSourceFileAtPath(o),a=h(i,o);for(const c of n.getVariableStatements())if(c.isExported())for(const g of c.getDeclarations()){const l=P(g,a);l&&e.push(l)}}return e.sort((o,n)=>o.id.localeCompare(n.id)),M(e),e};export{y as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as l,handlerOf as d}from"./listLunoraSourceFiles-
|
|
1
|
+
import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as l,handlerOf as d}from"./listLunoraSourceFiles-DsxeRYvh.mjs";import{c as f}from"./classify-procedure-call-RjsZg8AH.mjs";const u={"crypto.getRandomValues":"crypto.getRandomValues","crypto.randomUUID":"crypto.randomUUID","Date.now":"Date.now","Math.random":"Math.random"},m=new Set(["globalThis","self"]),g=new Set(["globalThis","self","window"]),p=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e)){const t=e.getExpression();if(s.isIdentifier(t)&&g.has(t.getText()))return e.getName()}},h=e=>{const t=e.getExpression();if(s.isIdentifier(t)){const o=t.getText();return o==="fetch"||o==="Date"?o:void 0}if(!s.isPropertyAccessExpression(t))return;const n=t.getName(),i=p(t.getExpression());if(i!==void 0)return n==="fetch"&&m.has(i)?"fetch":u[`${i}.${n}`]},x=e=>{const t=e.getExpression();if(!s.isIdentifier(t)||t.getText()!=="Date")return;const n=e.getArguments(),i=n.every(o=>s.isNumericLiteral(o)||s.isStringLiteral(o)||s.isNoSubstitutionTemplateLiteral(o));return n.length>0&&i?void 0:"new Date"},N=e=>{const t=e.getInitializer();if(!t||!s.isCallExpression(t))return;const n=f(t);if(!n||n.kind!=="query"&&n.kind!=="mutation")return;const i=d(t,n.receiver);return i?{exportName:e.getName(),handler:i,kind:n.kind}:void 0},E=(e,t)=>{const n=[];for(const i of e.handler.getDescendantsOfKind(a.CallExpression)){const o=h(i);o!==void 0&&n.push({callee:o,exportName:e.exportName,file:t,kind:e.kind,line:i.getStartLineNumber()})}for(const i of e.handler.getDescendantsOfKind(a.NewExpression)){const o=x(i);o!==void 0&&n.push({callee:o,exportName:e.exportName,file:t,kind:e.kind,line:i.getStartLineNumber()})}return n},S=(e,t)=>{const n=[];for(const i of e.getVariableStatements())if(i.isExported())for(const o of i.getDeclarations()){const r=N(o);r&&n.push(...E(r,t))}return n},w=(e,t)=>{const n=[];for(const i of c(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...S(o,l(t,i)))}return n};export{w as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as a}from"./queries-TZaLWhWq.mjs";import"./listLunoraSourceFiles-DsxeRYvh.mjs";export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as r}from"./context-property-calls-DV-Pt4KS.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
|
package/dist/packem_shared/{discoverRlsMetadata-DwULXx5T.mjs → discoverRlsMetadata-3Gs8U3ng.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as o}from"ts-morph";import{listLunoraSourceFiles as d,lunoraRelativePath as x,stringPropertyOf as c}from"./listLunoraSourceFiles-
|
|
1
|
+
import{Node as o}from"ts-morph";import{listLunoraSourceFiles as d,lunoraRelativePath as x,stringPropertyOf as c}from"./listLunoraSourceFiles-DsxeRYvh.mjs";import{e as h}from"./exported-procedure-chains-CjlBrFjo.mjs";import{r as A}from"./chain-u-8_P10m.mjs";const L=new Set(["delete","insert","read","update"]),P=(e,t,i)=>{const r=e.getArguments()[0];if(!r||!o.isArrayLiteralExpression(r))return[];const s=[];for(const n of r.getElements()){if(!o.isObjectLiteralExpression(n))continue;const a=c(n,"on");a===void 0||!L.has(a)||s.push({file:t,on:a,procedure:i,table:c(n,"table")??""})}return s},u=e=>{if(!o.isObjectLiteralExpression(e))return[];const t=e.getProperty("permissions");if(!t||!o.isPropertyAssignment(t))return[];const i=t.getInitializer();if(!i||!o.isArrayLiteralExpression(i))return[];const r=[];for(const s of i.getElements()){if(o.isStringLiteral(s)){r.push(s.getLiteralText());continue}if(o.isCallExpression(s)){const n=s.getArguments()[0];n&&o.isStringLiteral(n)&&r.push(n.getLiteralText())}}return r},f=(e,t)=>t===void 0?e:{...e,description:t},E=e=>{if(o.isCallExpression(e)){const t=e.getArguments()[0];if(!t||!o.isStringLiteral(t))return;const i=e.getArguments()[1],r=i?c(i,"description"):void 0,s=i?u(i):[];return f({name:t.getLiteralText(),permissions:s},r)}if(o.isObjectLiteralExpression(e)){const t=c(e,"name");return t===void 0?void 0:f({name:t,permissions:u(e)},c(e,"description"))}},v=e=>{const t=e.getArguments()[1];if(!t||!o.isObjectLiteralExpression(t))return[];const i=t.getProperty("roles");if(!i||!o.isPropertyAssignment(i))return[];const r=i.getInitializer();if(!r||!o.isArrayLiteralExpression(r))return[];const s=[];for(const n of r.getElements()){const a=E(n);a&&s.push(a)}return s},y=(e,t,i)=>{const r=A(e);return{policies:r.flatMap(s=>P(s,t,i)),roles:r.flatMap(s=>v(s))}},F=(e,t)=>{const i=[],r=new Map;for(const s of d(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),a=x(t,s);for(const{name:m,receiver:g}of h(n)){const p=y(g,a,m);i.push(...p.policies);for(const l of p.roles)r.has(l.name)||r.set(l.name,l)}}return{policies:i,roles:[...r.values()]}};export{F as default};
|
package/dist/packem_shared/{discoverRlsProcedures-D_J8cH-m.mjs → discoverRlsProcedures-CU7YMR3P.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as o}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as u,tablesAccessedIn as d}from"./listLunoraSourceFiles-
|
|
1
|
+
import{Node as o}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as u,tablesAccessedIn as d}from"./listLunoraSourceFiles-DsxeRYvh.mjs";import{c as p}from"./classify-procedure-call-RjsZg8AH.mjs";import{r as m}from"./chain-u-8_P10m.mjs";const b=e=>{const t=e.getArguments()[0];if(!t||!o.isArrayLiteralExpression(t))return[];const s=[];for(const r of t.getElements()){if(!o.isObjectLiteralExpression(r))continue;const i=r.getProperty("table");if(!i||!o.isPropertyAssignment(i))continue;const n=i.getInitializer();n&&o.isStringLiteral(n)&&s.push(n.getLiteralText())}return s},g=e=>{const t=m(e);return{rlsTables:t.flatMap(s=>b(s)),usesRls:t.length>0}},h=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),y=new Set(["delete","deleteMany","insert","insertMany","patch","patchMany","replace"]),v=(e,t)=>{if(!o.isVariableDeclaration(e))return;const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const r=p(s);if(!r)return;const i=r.receiver?g(r.receiver):{rlsTables:[],usesRls:!1},{tablesRead:n,tablesWritten:l}=d(e,h,y);return{exportName:e.getName(),file:t,rlsTables:i.rlsTables,tablesRead:n,tablesWritten:l,usesRls:i.usesRls,visibility:r.visibility}},S=(e,t)=>{const s=[];for(const r of f(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=u(t,r);for(const l of i.getVariableStatements())if(l.isExported())for(const c of l.getDeclarations()){const a=v(c,n);a&&s.push(a)}}return s};export{S as default};
|
package/dist/packem_shared/{discoverSandboxUsage-DskdDbkM.mjs → discoverSandboxUsage-pJ42YuvL.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{listLunoraSourceFiles as l}from"./listLunoraSourceFiles-
|
|
1
|
+
import{listLunoraSourceFiles as l}from"./listLunoraSourceFiles-DsxeRYvh.mjs";const i=new Set(["@lunora/agent","@lunora/agent/sandbox"]),a={browserTool:"usesSandboxBrowser",containerTool:"usesSandboxContainer",fsTool:"usesSandboxFs"},u=()=>({usesSandboxBrowser:!1,usesSandboxContainer:!1,usesSandboxFs:!1}),d=o=>{const s=u();if(!i.has(o.getModuleSpecifierValue())||o.isTypeOnly())return s;for(const e of o.getNamedImports()){if(e.isTypeOnly())continue;const n=a[e.getNameNode().getText()];n!==void 0&&(s[n]=!0)}return s},b=(o,s)=>{const e=u();for(const n of l(s)){const c=o.getSourceFile(n)??o.addSourceFileAtPath(n);for(const t of c.getImportDeclarations()){const f=d(t);for(const r of Object.values(a))e[r]||=f[r]}if(Object.values(a).every(t=>e[t]))break}return e};export{b as discoverSandboxUsage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as u}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as p,stringPropertyOf as l}from"./listLunoraSourceFiles-
|
|
1
|
+
import{Node as u}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as p,stringPropertyOf as l}from"./listLunoraSourceFiles-DsxeRYvh.mjs";import{w as d}from"./classify-procedure-call-RjsZg8AH.mjs";import{e as m}from"./exported-procedure-chains-CjlBrFjo.mjs";const h=new Set(["delete","list","read","write"]),g=t=>d(t,"use","storageRules"),x=(t,s,n)=>{const e=t.getArguments()[0];if(!e||!u.isArrayLiteralExpression(e))return[];const i=[];for(const o of e.getElements()){if(!u.isObjectLiteralExpression(o))continue;const r=l(o,"on");if(r===void 0||!h.has(r))continue;const a=l(o,"prefix"),c={bucket:l(o,"bucket")??"",file:s,on:r,procedure:n};a!==void 0&&(c.prefix=a),i.push(c)}return i},A=(t,s)=>{const n=[];for(const e of f(s)){const i=t.getSourceFile(e)??t.addSourceFileAtPath(e),o=p(s,e);for(const{name:r,receiver:a}of m(i))for(const c of g(a))n.push(...x(c,o,r))}return{rules:n}};export{A as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as a}from"ts-morph";import{c as n}from"./classify-procedure-call-
|
|
1
|
+
import{Node as a}from"ts-morph";import{c as n}from"./classify-procedure-call-RjsZg8AH.mjs";const f=s=>{const i=[];for(const r of s.getVariableStatements())if(r.isExported())for(const t of r.getDeclarations()){const e=t.getInitializer(),o=e&&a.isCallExpression(e)?n(e):void 0;o?.receiver&&i.push({name:t.getName(),receiver:o.receiver})}return i};export{f as e};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as r}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as m,tablesAccessedIn as d}from"./listLunoraSourceFiles-
|
|
1
|
+
import{Node as r}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as m,tablesAccessedIn as d}from"./listLunoraSourceFiles-DsxeRYvh.mjs";import{w as g,c as p}from"./classify-procedure-call-RjsZg8AH.mjs";const u=e=>{if(!r.isPropertyAssignment(e)&&!r.isShorthandPropertyAssignment(e)&&!r.isMethodDeclaration(e)&&!r.isGetAccessorDeclaration(e))return;const t=e.getNameNode();return r.isStringLiteral(t)?t.getLiteralValue():e.getName()},h=e=>g(e,"use","mask"),x=e=>{if(r.isPropertyAssignment(e)){const t=e.getInitializer();if(t&&r.isStringLiteral(t)){const s=t.getLiteralText();if(s==="redact"||s==="hash")return s}}return"custom"},k=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return[];const s=[];for(const i of t.getProperties()){const n=u(i);if(n===void 0||!r.isPropertyAssignment(i))continue;const o=i.getInitializer();if(!(!o||!r.isObjectLiteralExpression(o)))for(const a of o.getProperties()){const c=u(a);c!==void 0&&s.push({column:c,table:n})}}return s},v=e=>{const t=h(e);return{maskColumns:t.flatMap(s=>k(s)),usesMask:t.length>0}},P=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),C=new Set(["delete","insert","patch","replace"]),M=(e,t)=>{if(!r.isVariableDeclaration(e))return;const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const i=p(s);if(!i)return;const n=i.receiver?v(i.receiver):{maskColumns:[],usesMask:!1},{tablesRead:o,tablesWritten:a}=d(e,P,C);return{exportName:e.getName(),file:t,maskColumns:n.maskColumns,tablesRead:o,tablesWritten:a,usesMask:n.usesMask,visibility:i.visibility}},E=(e,t)=>{const s=[];for(const i of f(t)){const n=e.getSourceFile(i)??e.addSourceFileAtPath(i),o=m(t,i);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations()){const l=M(c,o);l&&s.push(l)}}return s};export{u as a,E as d,h as m,x as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readdirSync as E,realpathSync as y,lstatSync as P,statSync as w}from"node:fs";import{dirname as A,join as g,relative as L,sep as O,extname as x}from"node:path";import{Node as n,SyntaxKind as m,VariableDeclarationKind as F}from"ts-morph";import{diagnosticAt as R}from"./CodegenDiagnosticError-BUXlG3P-.mjs";const D=/\.ts$/u,u=(t,e)=>L(t,e).split(O).join("/").replace(D,""),I=new Set(["_generated","node_modules"]),N=(t,e,i)=>t==="schema.ts"&&e===i,T=t=>{try{return w(t)}catch{console.warn(`@lunora/codegen: skipping ${t} — it is a symlink that does not resolve (or vanished mid-scan).`);return}},S=(t,e,i,s)=>{let r,o;try{r=E(t),o=y(t)}catch{return e}if(s.has(o))return e;s.add(o);for(const a of r){const l=g(t,a),c=T(l);c!==void 0&&(c.isDirectory()?I.has(a)||S(l,e,i,s):c.isFile()&&x(a)===".ts"&&!N(a,t,i)&&e.push(l))}return e},b=t=>S(t,[],t,new Set),z=["src/server","src/index.ts","src/worker.ts"],C=new Set([".ts",".tsx"]),h=(t,e=[])=>{let i;try{i=P(t)}catch{return e}if(i.isFile())return C.has(x(t))&&e.push(t),e;if(!i.isDirectory())return e;for(const s of E(t))s==="_generated"||s==="node_modules"||h(g(t,s),e);return e},j=t=>{const e=A(t),i=b(t).map(r=>({displayPath:u(t,r),filePath:r})),s=new Set(i.map(r=>r.filePath));for(const r of z)for(const o of h(g(e,r)))s.has(o)||(s.add(o),i.push({displayPath:u(e,o),filePath:o}));return i},v=(t,e,i)=>{const s=[];for(const{displayPath:r,filePath:o}of e){const a=t.getSourceFile(o)??t.addSourceFileAtPath(o);for(const l of a.getDescendantsOfKind(m.CallExpression)){const c=i(l,r);c!==void 0&&s.push(c)}}return s},M=(t,e,i)=>v(t,b(e).map(s=>({displayPath:u(e,s),filePath:s})),i),X=(t,e,i)=>v(t,j(e),i),Y=t=>{for(const e of t.getAncestors())if(n.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0)return e.getName();return""},H=(t,e)=>{if(e){const o=t.getArguments()[0];return o&&(n.isArrowFunction(o)||n.isFunctionExpression(o))?o:void 0}const i=t.getArguments()[0];if(!i||!n.isObjectLiteralExpression(i))return;const s=i.getProperty("handler");if(!s||!n.isPropertyAssignment(s))return;const r=s.getInitializer();return r&&(n.isArrowFunction(r)||n.isFunctionExpression(r))?r:void 0},U=(t,e)=>{if(!t||!n.isObjectLiteralExpression(t))return;const i=t.getProperty(e);return i&&n.isPropertyAssignment(i)?i.getInitializer():void 0},V=t=>{const e=t.getSymbol()?.getDeclarations().find(r=>n.isVariableDeclaration(r));if(e===void 0||!n.isVariableDeclaration(e))return;const i=e.getParent();if(!n.isVariableDeclarationList(i)||i.getDeclarationKind()!==F.Const)return;const s=i.getParent();return n.isVariableStatement(s)&&n.isSourceFile(s.getParent())?e.getInitializer():void 0},G=t=>{if(!t)return;if(n.isObjectLiteralExpression(t))return t;if(!n.isIdentifier(t))return;const e=V(t);return e!==void 0&&n.isObjectLiteralExpression(e)?e:void 0},f=t=>n.isPropertyAccessExpression(t)&&t.getName()==="db"||n.isIdentifier(t)&&t.getText()==="db",_=new Set(["findFirst","findFirstOrThrow","findMany","findUnique"]),J=t=>{const e=t.getExpression();if(!n.isPropertyAccessExpression(e)||!_.has(e.getName()))return;const i=e.getExpression();if(f(i)){const s=t.getArguments()[0];return{options:t.getArguments()[1],table:s&&n.isStringLiteral(s)?s.getLiteralText():""}}if(n.isPropertyAccessExpression(i)){const s=i.getExpression();if(f(s))return{options:t.getArguments()[0],table:i.getName()}}},p=(t,e)=>{const i=t.getExpression();return!n.isPropertyAccessExpression(i)||!e.has(i.getName())?!1:f(i.getExpression())},d=t=>{const e=t.getArguments()[0];return e&&n.isStringLiteral(e)?e.getLiteralText():""},Q=(t,e,i)=>{const s=new Set,r=new Set;for(const o of t.getDescendantsOfKind(m.CallExpression))if(p(o,e)){const a=d(o);a!==""&&s.add(a)}else if(p(o,i)){const a=d(o);a!==""&&r.add(a)}return{tablesRead:[...s],tablesWritten:[...r]}},K=t=>{let e=t;for(;e&&(n.isAsExpression(e)||n.isSatisfiesExpression(e)||n.isParenthesizedExpression(e)||n.isNonNullExpression(e));)e=e.getExpression();return e},Z=t=>{const e=K(t);return e&&n.isCallExpression(e)?e:void 0},tt=t=>{const e=t.getExportAssignment(r=>!r.isExportEquals());if(!e)return;const i=e.getExpression();if(!n.isIdentifier(i))return i;const s=i.getSymbol()?.getValueDeclaration();return s&&n.isVariableDeclaration(s)?s.getInitializer():i},et=t=>{const e=t.getArguments()[1];return e&&n.isStringLiteral(e)?e.getLiteralValue():""},it=(t,e)=>{if(!n.isObjectLiteralExpression(t))return;const i=t.getProperty(e);if(!i||!n.isPropertyAssignment(i))return;const s=i.getInitializer();return s&&n.isStringLiteral(s)?s.getLiteralText():void 0},k=t=>{const e=t.getStatements(),[i]=e;if(e.length!==1||i===void 0||!n.isReturnStatement(i))return;const s=i.getExpression();return s!==void 0&&n.isObjectLiteralExpression(s)?s:void 0},st=t=>{if(n.isObjectLiteralExpression(t))return t;if(n.isParenthesizedExpression(t)){const e=t.getExpression();return n.isObjectLiteralExpression(e)?e:void 0}return n.isBlock(t)?k(t):void 0},nt=t=>n.isIdentifier(t)&&t.getText()==="ctx",rt=t=>(e,i,s)=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw R(e,`${t} "${i}": \`${s}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)};export{D as TS_EXTENSION_RE,M as collectCallRows,X as collectSecurityCallRows,tt as defaultExportExpression,Y as enclosingExportName,H as handlerOf,nt as isContextIdentifier,f as isDatabaseAccessor,et as limitNameOf,b as listLunoraSourceFiles,j as listSecurityScanFiles,u as lunoraRelativePath,st as objectLiteralFromCallbackBody,G as optionsObjectLiteral,U as propertyInitializer,J as readTargetOf,rt as stringPropertyFor,it as stringPropertyOf,d as tableArgumentOf,Q as tablesAccessedIn,K as unwrapExpression,Z as unwrapToCallExpression};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as s,SyntaxKind as f}from"ts-morph";import{listLunoraSourceFiles as P,lunoraRelativePath as N,isDatabaseAccessor as v}from"./listLunoraSourceFiles-DsxeRYvh.mjs";const A=t=>{const e=t.getText(),n=r=>{const i=r.getNameNode();return s.isIdentifier(i)&&i.getText()===e};for(const r of t.getAncestors())if(!(!s.isArrowFunction(r)&&!s.isFunctionExpression(r)&&!s.isFunctionDeclaration(r)))for(const i of r.getParameters()){const a=i.getDescendantsOfKind(f.BindingElement).find(o=>n(o));if(a!==void 0)return a}},h=t=>{let e=t;for(;;){const n=e.getParent();if(!s.isObjectBindingPattern(n))return;const r=n.getParent();if(s.isBindingElement(r)){e=r;continue}return s.isParameterDeclaration(r)?(e.getPropertyNameNode()??e.getNameNode()).getText():void 0}},x=(t,e)=>{const n=t.getParent();if(s.isPropertyAccessExpression(n)&&n.getNameNode()===t||s.isPropertyAssignment(n)&&n.getNameNode()===t)return!1;if(t.getText()===e)return!0;const r=A(t);return r!==void 0&&h(r)===e},p=(t,e)=>s.isIdentifier(t)?x(t,e):t.getDescendantsOfKind(f.Identifier).some(n=>x(n,e)),g=t=>p(t,"ctx"),I=t=>{let e=t;for(;s.isPropertyAccessExpression(e)||s.isElementAccessExpression(e)||s.isNonNullExpression(e);)e=e.getExpression();return s.isIdentifier(e)?e:void 0},E=t=>p(t,"args"),u=t=>{if(!s.isIdentifier(t))return;const e=t.getText(),n=t.getFirstAncestor(o=>s.isArrowFunction(o)||s.isFunctionExpression(o)||s.isFunctionDeclaration(o));if(n===void 0)return;const r=t.getStart();let i,a=-1;for(const o of n.getDescendantsOfKind(f.VariableDeclaration)){if(o.getName()!==e)continue;const c=o.getInitializer(),l=o.getStart();c!==void 0&&l<r&&l>a&&(i=c,a=l)}return i},O=t=>{if(E(t))return!0;const e=u(t);return e!==void 0&&E(e)},C=t=>{if(s.isCallExpression(t)||s.isNewExpression(t))return!1;const e=u(t);return e===void 0||!(s.isCallExpression(e)||s.isNewExpression(e))},_=t=>{if(g(t))return!0;const e=u(t);if(e!==void 0&&g(e))return!0;const n=e??t;return(s.isIdentifier(n)?[n]:n.getDescendantsOfKind(f.Identifier)).some(i=>{const a=u(i);return a!==void 0&&g(a)})},m=(t,e)=>p(t,e),B=(t,e)=>{if(m(t,e))return!0;const n=u(t);if(n!==void 0&&m(n,e))return!0;const r=I(t);if(r!==void 0){const i=u(r);return i!==void 0&&m(i,e)}return!1},D=t=>{for(const e of t.getAncestors())if(s.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0)return e.getName();return"<module>"},b=new Set(["withGeoIndex","withIndex","withSearchIndex"]),y=new Set(["collect","collectWithScores","first","paginate","take","unique"]),S=t=>{const e=t.getExpression();if(!s.isPropertyAccessExpression(e)||e.getName()!=="query")return!1;const n=e.getExpression();return v(n)},F=t=>{const e=[];let n=t;for(;;){const r=n.getParent();if(!r||!s.isPropertyAccessExpression(r))break;const i=r.getParent();if(!i||!s.isCallExpression(i))break;e.push(r.getName()),n=i}return e},w=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,R=t=>{let e=t;for(;;){const n=e.getParent();if(!n||!s.isPropertyAccessExpression(n))return!1;const r=n.getParent();if(!r||!s.isCallExpression(r))return!1;if(n.getName()==="filter"){const i=r.getArguments()[0];if(i&&w.test(i.getText()))return!0}e=r}},T=t=>{const e=t.getArguments()[0];return e&&s.isStringLiteral(e)?e.getLiteralText():""},L=(t,e)=>{const n=[];for(const r of P(e)){const i=t.getSourceFile(r)??t.addSourceFileAtPath(r),a=N(e,r);for(const o of i.getDescendantsOfKind(f.CallExpression)){if(!S(o))continue;const c=F(o),l=c.includes("filter");n.push({exportName:D(o),file:a,filtersPrimaryKey:l&&R(o),hasFilter:l,hasIndex:c.some(d=>b.has(d)),line:o.getStartLineNumber(),table:T(o),terminal:c.findLast(d=>y.has(d))})}}return n};export{_ as a,C as b,B as c,L as d,D as e,m as f,O as i,E as r,u as s};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/codegen",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.201",
|
|
4
4
|
"description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@lunora/advisor": "1.0.0-alpha.145",
|
|
50
|
-
"@lunora/agent": "1.0.0-alpha.
|
|
50
|
+
"@lunora/agent": "1.0.0-alpha.125",
|
|
51
51
|
"@lunora/container": "1.0.0-alpha.52",
|
|
52
52
|
"@lunora/errors": "1.0.0-alpha.39",
|
|
53
53
|
"@lunora/platform": "1.0.0-alpha.32",
|
|
54
54
|
"@lunora/queue": "1.0.0-alpha.59",
|
|
55
55
|
"@lunora/scheduler": "1.0.0-alpha.76",
|
|
56
56
|
"@lunora/values": "1.0.0-alpha.49",
|
|
57
|
-
"@lunora/workflow": "1.0.0-alpha.
|
|
57
|
+
"@lunora/workflow": "1.0.0-alpha.58",
|
|
58
58
|
"jiti": "^2.7.0",
|
|
59
59
|
"quicktype-core": "^26.0.0",
|
|
60
60
|
"ts-morph": "^28.0.0"
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import{existsSync as b,mkdirSync as Is,readFileSync as _t,writeFileSync as ws,rmSync as Ts}from"node:fs";import{join as E,dirname as ne}from"node:path";import{performance as Ae}from"node:perf_hooks";import{runAdvisor as Cs}from"@lunora/advisor";import{LunoraError as L}from"@lunora/errors";import{SyntaxKind as l,Node as o,VariableDeclarationKind as Fs,Project as ct}from"ts-morph";import{serializeSchemaSnapshot as Os}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{toAdvisorContext as Rs}from"./formatAdvisories-DwmUKYuc.mjs";import{s as Ls}from"./paths-C-9fwEgQ.mjs";import{C as re,o as zt,j as Ds,f as ks,k as Ms,b as Ks,c as _s,m as zs,e as $s,p as Us,d as qs,i as Bs,l as Vs,g as Ws,q as js,n as Hs,a as Gs,h as Ys}from"./emit-BuaY_1hY.mjs";import{isD1GlobalTable as $t,isHyperdriveGlobalTable as Ut}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as Qs}from"./AGENTS_FILENAME-B78F7DuQ.mjs";import{discoverContainers as Xs}from"./CONTAINERS_FILENAME-CQoUu7n7.mjs";import Zs from"./discoverCrons-CMu0sA8k.mjs";import{diagnosticAt as ue}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as de}from"./module-specifiers-WF8iAydP.mjs";import{listLunoraSourceFiles as p,unwrapExpression as G,listSecurityScanFiles as Re,objectLiteralFromCallbackBody as qt,propertyInitializer as A,lunoraRelativePath as x,collectCallRows as w,collectSecurityCallRows as Js,limitNameOf as Bt,isContextIdentifier as Ie,handlerOf as en,isDatabaseAccessor as D,readTargetOf as Vt,enclosingExportName as tn}from"./listLunoraSourceFiles-D4xthUf-.mjs";import sn from"./readPackageDependencies-C6h6FZuP.mjs";import{discoverQueues as nn}from"./QUEUES_FILENAME-Q3CF3uYr.mjs";import{discoverSandboxUsage as rn}from"./discoverSandboxUsage-DskdDbkM.mjs";import on from"./discoverStorageRulesMetadata-C3ywuLJd.mjs";import{a as S,c as k,d as Wt,e as an}from"./classify-procedure-call-BIlyTUBD.mjs";import{discoverWorkflows as cn}from"./WORKFLOWS_FILENAME-BaSbufF2.mjs";import{gatePlatformFeatures as ln,resolveCodegenTarget as un,readTargetDiagnostics as dn}from"./DEFAULT_TARGET-DtzlGawL.mjs";import{i as R,a as _,e as v,r as fn,b as gn,s as fe,c as pn,f as mn,d as hn}from"./queries-CPlxXagL.mjs";import{r as ge,s as xn}from"./parse-validator-tdRHHDzh.mjs";import vn from"./discoverAuthApiCalls-DoblmzUW.mjs";import lt from"./discoverFunctions-DRf4ucil.mjs";import{i as En,r as Sn,e as yn}from"./unwrap-handler-return-Da99uRXX.mjs";import ut from"./discoverHttpRoutes-_ME7hLcW.mjs";import An from"./discoverHyperdriveCalls-DP3Vb0HC.mjs";import Nn from"./discoverInserts-COk-Sm_n.mjs";import{m as Le,a as oe,s as jt,d as bn}from"./index-C4eKBBMk.mjs";import{e as Ht}from"./exported-procedure-chains-Bqdp4ywr.mjs";import Pn from"./discoverMigrations-B_sYrTyE.mjs";import{MUTATORS_FILENAME as In,isDefineMutatorCallee as wn,discoverMutators as dt}from"./MUTATORS_FILENAME-B7EXNAFK.mjs";import Tn from"./discoverNondeterministicCalls-Dy6k2aPS.mjs";import{discoverNotifyConfig as Cn,discoverNotifyCalls as Fn}from"./NOTIFY_FILENAME-Bgq52CnU.mjs";import On from"./discoverR2sqlCalls-FaK1-wbV.mjs";import Rn from"./discoverRlsProcedures-D_J8cH-m.mjs";import Ln from"./discoverRlsMetadata-DwULXx5T.mjs";import Dn from"./discoverSchema-DoZtXwLg.mjs";import{secretKindOf as kn,redact as Mn,isHeuristicSecretKind as Kn,isSecretishName as _n}from"./redact-Cy14LEnc.mjs";import{discoverShapes as zn}from"./SHAPES_FILENAME-Bvd5kgsF.mjs";import{emitApp as $n}from"./emitApp-nInCbDo8.mjs";import{buildOpenApiDocument as Un,emitOpenApiModule as qn}from"./buildOpenApiDocument-DCGde3iO.mjs";import{buildOpenRpcDocument as Bn,emitOpenRpcModule as Vn}from"./OPENRPC_VERSION-D6-0Hn3B.mjs";import{buildSchemaSnapshot as Wn}from"./SchemaSnapshotParseError-lUWe6lPo.mjs";const ft=(e,t="api")=>{const s=new Map;for(const n of e){const i=Ls(n),r=s.get(i);if(r===void 0){s.set(i,n);continue}if(r!==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 L("INTERNAL",`@lunora/codegen: "${r}" 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})}}},jn=(e,t={})=>{const{hasVectors:s=!0,scheduler:n=!1,storage:i=!1,usage:r}=t,a=[];e.tables.some(c=>$t(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=>Ut(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 r===void 0?[]:re)c.requiredPackage!==void 0&&r?.[c.key]===!0&&a.push({name:c.requiredPackage,reason:`\`ctx.${c.contextProperty??c.key}\` usage makes \`_generated/\` import \`${c.moduleSpecifier}\``});return a.filter((c,u)=>a.findIndex(d=>d.name===c.name)===u)},Hn=(e,t,s={})=>{if(t===void 0)return;const n=jn(e,s).filter(r=>!t.has(r.name));if(n.length===0)return;const i=n.map(r=>` - ${r.name} — ${r.reason}`).join(`
|
|
2
|
-
`);throw new L("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
|
|
3
|
-
${i}
|
|
4
|
-
|
|
5
|
-
Install them with your package manager, then re-run codegen.`)},Gn="env.ts",Yn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return de(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},Qn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&de(n.getModuleSpecifierValue())}return!1},Xn=e=>{if(o.isIdentifier(e))return Yn(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&o.isIdentifier(t)&&Qn(t)}return!1},Zn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!Xn(n.getExpression()))continue;const r=s.getNameNode();if(!o.isIdentifier(r))throw ue(r,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},Jn=(e,t)=>{const s=E(t,Gn);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=Zn(n);if(i.length!==0){if(i.length>1)throw ue(n,`lunora/env.ts declares ${i.length.toString()} defineEnv() contracts (${i.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return i[0]}},gt="ctx",Gt=e=>{const t=new Set,s=new Set([gt]),n=r=>{if(o.isObjectBindingPattern(r))for(const a of r.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&t.add(c)}};for(const r of e.getDescendantsOfKind(l.BindingElement)){if((r.getPropertyNameNode()?.getText()??r.getName())!==gt)continue;const a=r.getNameNode();o.isIdentifier(a)?s.add(a.getText()):n(a)}const i=r=>o.isIdentifier(r)&&s.has(r.getText());for(const r of e.getDescendantsOfKind(l.PropertyAccessExpression))i(r.getExpression())&&t.add(r.getName());for(const r of e.getDescendantsOfKind(l.VariableDeclaration)){const a=r.getInitializer();a!==void 0&&i(a)&&n(r.getNameNode())}return t},er=(e,t)=>{const s=Object.fromEntries(re.map(n=>[n.key,!1]));for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=new Set(i.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=Gt(i);for(const c of re)if(!s[c.key]){if(r.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(re.every(c=>s[c.key]))break}return s},Yt="identity.ts",tr=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return de(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},sr=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&de(n.getModuleSpecifierValue())}return!1},nr=e=>{if(o.isIdentifier(e))return tr(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&o.isIdentifier(t)&&sr(t)}return!1},rr=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!nr(n.getExpression()))continue;const r=s.getNameNode();if(!o.isIdentifier(r))throw ue(r,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},ir=(e,t)=>{const s=E(t,Yt);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=rr(n);if(i.length!==0){if(i.length>1)throw ue(n,`lunora/identity.ts declares ${i.length.toString()} defineIdentity() contracts (${i.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return i[0]}},or=(e,t)=>{const s=G(t);if(s===void 0||!o.isIdentifier(s))return s;const n=s.getText();return G(e.getDescendantsOfKind(l.VariableDeclaration).find(i=>i.getName()===n)?.getInitializer())},ar=e=>e!==void 0&&o.isObjectLiteralExpression(e)&&e.getProperties().some(t=>{if(o.isShorthandPropertyAssignment(t))return t.getName()==="durable";if(!o.isPropertyAssignment(t)||t.getName()!=="durable")return!1;const s=t.getInitializer();return s===void 0||G(s)?.getText()!=="false"}),cr=(e,t)=>{const s={durableStreams:!1,secrets:!1};for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);if(s.secrets||(s.secrets=Gt(i).has("secrets")),s.durableStreams||(s.durableStreams=i.getDescendantsOfKind(l.CallExpression).some(r=>{const a=r.getExpression();return(o.isPropertyAccessExpression(a)?a.getName():a.getText())==="stream"&&r.getArguments().some(u=>ar(or(i,u)))})),s.durableStreams&&s.secrets)break}return s},lr="createWorker",ur="extend",pt=e=>e!==void 0&&(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))?e.getLiteralValue():void 0,mt=e=>{const t=[],s=pt(A(e,"backupCron"));s!==void 0&&t.push(s);const n=A(e,"crons");if(n===void 0||!o.isObjectLiteralExpression(n))return t;for(const i of n.getProperties()){if(!o.isPropertyAssignment(i)&&!o.isMethodDeclaration(i))continue;const r=pt(i.getNameNode());r!==void 0&&t.push(r)}return t},dr=e=>{const t=S(e.getExpression()),[s]=e.getArguments();if(s===void 0)return[];if(t===lr)return o.isObjectLiteralExpression(s)?mt(s):[];if(t!==ur||!(o.isArrowFunction(s)||o.isFunctionExpression(s)))return[];const n=qt(s.getBody());return n===void 0?[]:mt(n)},fr=(e,t)=>{const s=[];for(const{filePath:n}of Re(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of i.getDescendantsOfKind(l.CallExpression))s.push(...dr(r))}return[...new Set(s)]},Qt=e=>{if(e.kind==="id")return e.tableName;if(!(e.kind!=="array"&&e.kind!=="optional"))return e.inner===void 0?void 0:Qt(e.inner)},gr=e=>{const t=new Set(e.tables.map(s=>s.name));return e.tables.some(s=>Object.values(s.shape).some(n=>{const i=Qt(n);return i!==void 0&&t.has(i)}))},pr=(e,t)=>{const s=new Map,n=new Map,i=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.bindingName,`workflow "${r.exportName}"`),i.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const a=s.get(r.name);if(a!==void 0)throw new L("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${a} and agent "${r.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=n.get(r.bindingName);if(c!==void 0)throw new L("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${r.bindingName}": produced by both ${c} and agent "${r.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const u=i.get(r.className);if(u!==void 0)throw new L("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${u} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},mr=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:i}=e,r=ir(s,t),a=Jn(s,t),c=cn(s,t),u=nn(s,t),d=Qs(s,t);pr(c,d);const h=Xs(s,t),m=on(s,t),P=Zs(s,t,c,d),M=fr(s,t),g=cr(s,t),T=rn(s,t),F=er(s,t);F.browser=F.browser||T.usesSandboxBrowser;const U=ln(F,un(n,e.target),{agents:d.length>0,commitOrderedTables:i.tables.some(N=>N.commitOrdered===!0),cronTriggers:P.length>0,crossShardFanout:i.tables.some(N=>typeof N.shardMode=="object"),durableStreams:g.durableStreams,globalTables:i.tables.some(N=>N.shardMode==="global"),queues:u.length>0,relationGraph:gr(i),secrets:g.secrets,vectorStore:i.vectorIndexes.length>0}),y=U.usage,O=U.signals.vectorStore!==!1,z=sn(n),W=z??new Set,X=W.has("lunorash");Hn(i,z,{hasVectors:O,scheduler:y.scheduler||P.length>0,storage:y.storage||m.rules.length>0||Object.keys(zt(i)).length>0,usage:y});const K=b(E(t,"flags.ts")),C=b(E(t,"notify.ts"));return{agents:d,containers:h,crons:P,dataModelContent:ks(i),declaredDependencies:z,dependencies:W,entryCronTriggers:M,env:a,featureUsage:y,hasFlags:K,hasNotify:C,identity:r,platformGate:{...U,diagnostics:[...dn(n,e.target),...U.diagnostics]},queues:u,serverContent:Ds({agents:d,containers:h,env:a,hasAccessFacade:y.access,hasAi:y.ai,hasAnalytics:y.analytics,hasBrowser:y.browser,hasVectors:O,hasFlags:K,hasHyperdrive:y.hyperdrive,hasImages:y.images,hasKv:y.kv,hasNotify:C,hasPayments:y.payments,hasPipelines:y.pipelines,hasR2sql:y.r2sql,hasX402:y.x402,identity:r,queues:u,schema:i,storageRuleBuckets:m.rules.map(N=>N.bucket),useUmbrella:X,workflows:c}),storageRulesMetadata:m,usesSandbox:T.usesSandboxBrowser||T.usesSandboxContainer||T.usesSandboxFs,useUmbrella:X,workflows:c}},Xt=new Set(["delete","get","head","options","patch","post","put"]),hr=new Set(["handler","stream"]),xr=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,ht=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),vr=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Xt.has(t.getName()))return;const s=t.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!o.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},Er=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||Xt.has(n.getName()))break;s=n.getExpression()}return vr(s)},Sr=e=>{for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression))if(ht.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&ht.has(s.getText()))return!0}return!1},yr=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||!hr.has(n.getName()))return;const i=Er(s);if(!i||!xr.test(i.path))return;const r=s.getArguments()[0],a=r!==void 0&&(o.isArrowFunction(r)||o.isFunctionExpression(r))&&Sr(r);return{exportName:e.getName(),file:t,method:i.method,path:i.path,usesGuard:a}},Ar=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=yr(i,t);r&&s.push(r)}return s},Nr=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ar(i,x(t,n)))}return s},br=e=>!o.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",Pr=(e,t)=>{if(!br(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!R(s)||_(s)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},Ir=(e,t)=>w(e,t,Pr),wr=new Set(["generateText","streamText"]),Tr=new Set(["messages","prompt","system"]),Cr=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],Fr=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const i of Cr)if(i.methods.has(s)&&i.prefixes.some(r=>n===r||n.startsWith(`${r}.`)))return`${n}.${s}`},Or=e=>{for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=Fr(t);if(s!==void 0)return s}},Rr=e=>{const t=new Set,s=e.getFirstAncestor(r=>o.isArrowFunction(r)||o.isFunctionExpression(r)||o.isFunctionDeclaration(r)),[n]=s?.getParameters()??[],i=n?.getNameNode();if(i===void 0||!o.isObjectBindingPattern(i))return t;for(const r of i.getElements()){const a=r.getPropertyNameNode()?.getText()??r.getName(),c=r.getNameNode();if(a==="args"&&o.isObjectBindingPattern(c))for(const u of c.getElements())t.add(u.getName())}return t},Lr=e=>{if(fn(e))return!0;const t=Rr(e);return t.size===0?!1:e.getDescendantsOfKind(l.Identifier).some(s=>t.has(s.getText()))},Dr=e=>{for(const t of e.getProperties()){if(!o.isPropertyAssignment(t)||!Tr.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&Lr(s))return!0}return!1},kr=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=S(n.getExpression());if(i===void 0||!wr.has(i))continue;const[r]=n.getArguments();if(r===void 0||!o.isObjectLiteralExpression(r))continue;let a;for(const c of r.getDescendantsOfKind(l.CallExpression))if(S(c.getExpression())==="tool"&&(a=Or(c),a!==void 0))break;a!==void 0&&s.push({exportName:v(n),file:t,line:n.getStartLineNumber(),method:i,sideEffect:a,userInputDerived:Dr(r)})}return s},Mr=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...kr(i,x(t,n)))}return s},Kr=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return o.isIdentifier(t)&&t.getText()==="ctx"},_r=(e,t)=>{if(!Kr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!R(s)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},zr=(e,t)=>w(e,t,_r),De=(e,t=new Set)=>{if(t.has(e))return!0;t.add(e);try{return e.getProperties().some(s=>{if(!o.isSpreadAssignment(s))return!1;const n=ge(s.getExpression());return n===void 0||De(n,t)})}finally{t.delete(e)}},$r=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!o.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer(),i=n===void 0?void 0:ge(n);return i===void 0?{objects:[],opaque:!0}:{objects:[i],opaque:De(i)}},Ur=e=>{const t=[];let s=!1,n=e;for(;o.isCallExpression(n);){const i=n.getExpression();if(!o.isPropertyAccessExpression(i))break;if(i.getName()==="input"){const r=n.getArguments()[0],a=r!==void 0&&o.isExpression(r)?ge(r):void 0;a===void 0?s=!0:(t.push(a),s||=De(a))}n=i.getExpression()}return{objects:t,opaque:s}},ke=(e,t)=>t?Ur(t):$r(e),Zt=(e,t)=>{if(t.has(e))return[];t.add(e);try{return e.getProperties().flatMap(s=>{if(o.isSpreadAssignment(s)){const n=ge(s.getExpression());return n===void 0?[]:Zt(n,t)}return o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)?[s.getName()]:[]})}finally{t.delete(e)}},qr=e=>e.flatMap(t=>Zt(t,new Set)),Br=new Set(["check","length","max"]),we=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(!(!o.isPropertyAccessExpression(t)||t.getExpression().getText()!=="v"))return t.getName()},Vr=e=>[e,...e.getDescendants()].filter(t=>we(t)!==void 0),Wr=e=>{let t=e;for(;;){const s=t.getParent();if(!s||!o.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;const n=s.getParent();if(!n||!o.isCallExpression(n)||n.getExpression()!==s)return!1;if(Br.has(s.getName()))return!0;t=n}},jr=e=>{const t=[],s=[];for(const n of e)for(const i of n.getProperties()){if(!o.isPropertyAssignment(i))continue;const r=i.getInitializer();if(!r)continue;const a=Vr(r),c=i.getName();a.some(u=>we(u)==="any")?t.push(c):a.some(u=>we(u)==="string"&&!Wr(u))&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Hr=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=k(s);if(n?.visibility!=="public")return;const{objects:i}=ke(s,n.receiver),{anyArgs:r,unboundedStringArgs:a}=jr(i);if(!(r.length===0&&a.length===0))return{anyArgs:r,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Gr=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=Hr(i,t);r&&s.push(r)}return s},Yr=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Gr(i,x(t,n)))}return s},Ne=e=>e?.getKind()===l.TrueKeyword,Qr=e=>e?.getKind()===l.FalseKeyword,Xr=e=>e!==void 0&&o.isNumericLiteral(e)&&e.getLiteralValue()===0,Zr=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Jr=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isCallExpression(t)&&S(t.getExpression())==="scim"),ei=e=>e!==void 0&&o.isCallExpression(e)&&Zr.has(S(e.getExpression())??""),ti=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isStringLiteral(t)&&t.getLiteralText()==="*"),si=e=>{const t=A(e,"advanced"),s=A(e,"emailAndPassword"),n=A(e,"session");return{analyzable:!0,disableCsrfCheck:Ne(A(t,"disableCSRFCheck")),emailPasswordEnabled:Ne(A(s,"enabled")),requireEmailVerification:Ne(A(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Jr(A(e,"plugins"))&&ei(A(e,"database")),secureCookiesDisabled:Qr(A(t,"useSecureCookies")),sessionFreshAgeZero:Xr(A(n,"freshAge")),trustedOriginsWildcard:ti(A(e,"trustedOrigins"))}},ni=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),ri=(e,t)=>{if(S(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&o.isObjectLiteralExpression(s)&&s.getProperties().some(r=>o.isSpreadAssignment(r)),i=s!==void 0&&o.isObjectLiteralExpression(s)&&!n?si(s):ni();return{exportName:v(e),file:t,line:e.getStartLineNumber(),...i}},ii=(e,t)=>Js(e,t,ri),oi=(e,t)=>{if(!o.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},ai=(e,t,s)=>{const n=oi(e.getExpression(),s);if(n===void 0)return;const i=e.getArguments()[s.argIndex];if(!(!i||!R(i)||_(i))&&!(s.requireUnmodifiedReach===!0&&!gn(i)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:n}},ci=(e,t,s)=>{const n=[];for(const i of e.getDescendantsOfKind(l.CallExpression)){const r=ai(i,t,s);r&&n.push(r)}return n},pe=(e,t,s)=>{const n=[];for(const i of p(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...ci(r,x(t,i),s))}return n},li=new Set(["content","pdf","scrape","screenshot"]),ui=(e,t)=>pe(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:li}),di=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),fi=new Set(["RateLimiter"]),gi=new Set(["extend"]),xt="lunora",pi=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],Jt=e=>{const t=[],s=[];let n=!1;for(const i of e.getProperties()){if(o.isSpreadAssignment(i)){n=!0;continue}if(o.isPropertyAssignment(i)){const r=i.getName();t.push(r),i.getInitializer()?.getKind()===l.TrueKeyword&&s.push(r);continue}(o.isShorthandPropertyAssignment(i)||o.isMethodDeclaration(i))&&t.push(i.getName())}return{analyzable:!n,presentKeys:t,trueKeys:s}},Te=e=>e&&o.isObjectLiteralExpression(e)?Jt(e):{analyzable:!1,presentKeys:[],trueKeys:[]},mi=e=>{const t=e&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,s=t&&qt(t.getBody());return s?Jt(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},hi=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=S(n.getExpression());i!==void 0&&(di.has(i)?s.push({callee:i,file:t,line:n.getStartLineNumber(),...Te(n.getArguments()[0])}):gi.has(i)&&s.push({callee:i,file:t,line:n.getStartLineNumber(),...mi(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(l.NewExpression)){const i=S(n.getExpression());i===void 0||!fi.has(i)||s.push({callee:i,file:t,line:n.getStartLineNumber(),...Te(n.getArguments()[0])})}return s},xi=(e,t)=>{for(const s of pi){const n=E(t,s);if(!b(n))continue;const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=[];for(const a of i.getDescendantsOfKind(l.CallExpression))S(a.getExpression())===xt&&r.push({callee:xt,file:s,line:a.getStartLineNumber(),...Te(a.getArguments()[0])});return r}return[]},vi=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of Re(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);s.push(...hi(r,n))}return s.push(...xi(e,ne(t))),s},vt="ctx.containers.",Ei=e=>{if(!e.startsWith(vt))return!1;const t=e.slice(vt.length);return t.length>0&&!t.includes(".")},Si=(e,t)=>pe(e,t,{argIndex:0,matchReceiver:Ei,methods:new Set(["get"])}),yi=new Set(["allow","deny","setAllowed"]),Ai=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&o.isPropertyAssignment(s)&&o.isTrueLiteral(s.getInitializerOrThrow())},Ni=(e,t)=>{const s=e.getExpression();if(!(!o.isPropertyAccessExpression(s)||s.getName()!=="start"||!Ai(e)))return{detail:"enableInternet: true",exportName:v(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},bi=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||!yi.has(s.getName()))return;const n=s.getExpression();if(!(!o.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),exportName:v(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},Pi=(e,t)=>Ni(e,t)??bi(e,t),Ii=(e,t)=>w(e,t,Pi),wi=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Ti=e=>{const t=e.getExpression();if(!o.isIdentifier(t))return;const s=t.getText();return wi.has(s)?s:void 0},Ci=e=>{const t=[],s=[];for(const n of e.getProperties()){if(o.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(o.isPropertyAssignment(n)){const i=n.getName();t.push(i);const r=n.getInitializer();r&&o.isStringLiteral(r)&&r.getLiteralText()===""&&s.push(i);continue}(o.isShorthandPropertyAssignment(n)||o.isMethodDeclaration(n)||o.isGetAccessorDeclaration(n))&&t.push(n.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Fi=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of Re(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);for(const a of r.getDescendantsOfKind(l.CallExpression)){const c=Ti(a);if(c===void 0)continue;const u=a.getArguments()[0],d=u&&o.isObjectLiteralExpression(u)?Ci(u):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:d.analyzable,emptyKeys:d.emptyKeys,factory:c,file:n,line:a.getStartLineNumber(),presentKeys:d.presentKeys})}}return s},Oi=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Ri=new Set(["dbRateLimit","rateLimit"]),Li=e=>{if(!e||!o.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&o.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===l.TrueKeyword},Di=(e,t)=>{const s=S(e.getExpression());if(s===void 0)return;const n=Oi.get(s);if(n!==void 0)return{callee:s,exportName:v(e),failOpen:Li(e.getArguments()[n]),file:t,limitName:Ri.has(s)?Bt(e):"",line:e.getStartLineNumber()}},ki=(e,t)=>w(e,t,Di),Mi=new Set(["boolean","number","object","string"]),Ki=e=>{const t=e.getName();if(!Mi.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="flags"&&Ie(s.getExpression()))return t;const n=s.getExpression();if(s.getName()==="details"&&o.isPropertyAccessExpression(n)&&n.getName()==="flags"&&Ie(n.getExpression()))return t},_i=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=Ki(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(o.isStringLiteral(n)||o.isNoSubstitutionTemplateLiteral(n)))return;const i=n.getLiteralValue();return i.length>0?{key:i,type:s}:void 0},zi=(e,t)=>{const s=new Map;for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of i.getDescendantsOfKind(l.CallExpression)){const a=_i(r);a&&!s.has(a.key)&&s.set(a.key,a.type)}}return[...s.entries()].map(([n,i])=>({key:n,type:i})).toSorted((n,i)=>n.key.localeCompare(i.key))},$i=e=>{const t=e.getInitializer();if(!t||!o.isCallExpression(t))return;const s=k(t);if(s?.kind!=="query")return;const n=en(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},Et=e=>{const t=e.getParent();return t&&o.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},Ui=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!o.isIdentifier(t)||t.getText()!=="ctx")return;const s=Et(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=Et(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},qi=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const i=Ui(n);i!==void 0&&s.push({callee:i,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},Bi=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=$i(i);r&&s.push(...qi(r,t))}return s},Vi=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Bi(i,x(t,n)))}return s},Wi=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Ie(t.getExpression())},ji=e=>{if(e?.getKind()===l.TrueKeyword)return!0;if(e?.getKind()===l.FalseKeyword)return!1},Hi=(e,t)=>{if(!Wi(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(o.isStringLiteral(s)||o.isNoSubstitutionTemplateLiteral(s)))return;const i=s.getLiteralValue(),r=ji(n);if(!(i.length===0||r===void 0))return{defaultValue:r,exportName:v(e),file:t,key:i,line:e.getStartLineNumber()}},Gi=(e,t)=>w(e,t,Hi),Yi=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const s=t.getTypeAtLocation(e).getProperty("types");if(!s)return;const n=s.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!n)return;const i=n.getTypeAtLocation(e),r=i.getText(e);if(!r||r==="any"||r==="never"||En(r))return;const a=e.getSourceFile().getFilePath();return Sn(i,e,a)?yn(i,e,a,0,new Set):r},Qi=e=>{const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Xi=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},Zi=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of i.getDescendantsOfKind(l.CallExpression))Qi(a)&&s.push({file:r,indexName:Xi(a),line:a.getStartLineNumber()})}return s},Y=e=>e!==void 0&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,es=e=>{const t=e.getArguments()[0],s=Y(t);if(s!==void 0)return s;if(t===void 0||!o.isObjectLiteralExpression(t))return;const n=t.getProperty("handler");return n!==void 0&&o.isPropertyAssignment(n)?Y(n.getInitializer()):void 0},Ji=new Set(["delete","get","head","options","patch","post","put"]),eo=new Set(["handler","stream"]),to=new Set(["runAction","runMutation"]),so=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),Q=(e,t)=>e!==void 0&&o.isIdentifier(e)&&e.getText()===t,ts=(e,t)=>{if(!(e===void 0||!o.isObjectBindingPattern(e))){for(const s of e.getElements())if((s.getPropertyNameNode()?.getText()??s.getNameNode().getText())===t){const i=s.getNameNode();return o.isIdentifier(i)?i.getText():void 0}}},St=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?o.isIdentifier(s)?s.getText():void 0:ts(s,"ctx")},yt=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&o.isIdentifier(s)?s.getText():void 0:ts(s,"request")},At=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);o.isCallExpression(s)&&n.unshift(s);for(const i of n){const r=i.getExpression();if(!o.isPropertyAccessExpression(r))continue;const a=r.getName(),c=r.getExpression();if(to.has(a)&&Q(c,t))return a;if(so.has(a)&&o.isPropertyAccessExpression(c)&&c.getName()==="db"&&Q(c.getExpression(),t))return`db.${a}`}},Nt=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(l.PropertyAccessExpression))if(n.getName()==="auth"&&Q(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(l.VariableDeclaration)){const i=n.getNameNode();if(!(!o.isObjectBindingPattern(i)||!Q(n.getInitializer(),t))){for(const r of i.getElements())if((r.getPropertyNameNode()?.getText()??r.getNameNode().getText())==="auth")return!0}}return!1},no=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,ro=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||s.getName()!=="get"&&s.getName()!=="has")return!1;const n=s.getExpression();return o.isPropertyAccessExpression(n)&&n.getName()==="headers"&&Q(n.getExpression(),t)},io=e=>[...o.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(l.StringLiteral).map(t=>t.getLiteralText())],ss=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:io(s)},oo=(e,t)=>{const s=e.getText();for(let n=e.getParent();n!==void 0;n=n.getParent()){if(!o.isArrowFunction(n)&&!o.isFunctionExpression(n)||!n.getParameters().some(c=>c.getName()===s))continue;const i=n.getParent();if(!o.isCallExpression(i))return[];const r=i.getExpression();if(!o.isPropertyAccessExpression(r))return[];const a=r.getExpression();return o.isIdentifier(a)?ss(t,a.getText()):[]}return[]},ao=e=>{const t=e.getArguments()[0];if(t===void 0)return[];if(o.isStringLiteral(t))return[t.getLiteralText()];if(!o.isIdentifier(t))return[];const s=e.getSourceFile(),n=ss(s,t.getText());return n.length>0?n:oo(t,s)},bt=(e,t)=>{if(t===void 0)return!1;const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);return o.isCallExpression(s)&&n.unshift(s),n.some(i=>ro(i,t)&&ao(i).some(r=>no.test(r)))},co=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!eo.has(t.getName()))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))return;const i=n.getName();if(Ji.has(i)){const r=n.getExpression();return o.isIdentifier(r)&&r.getText()==="httpRoute"?i.toUpperCase():void 0}s=n.getExpression()}},lo=(e,t)=>{const s=e.getExpression();if(o.isIdentifier(s)&&s.getText()==="httpAction"){const c=Y(e.getArguments()[0]),u=c&&St(c,!0);if(!c||u===void 0||bt(c,yt(c,!0)))return;const d=At(c,u);return d===void 0?void 0:{exportName:v(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:Nt(c,u),sideEffect:d}}const n=co(e);if(n===void 0)return;const i=Y(e.getArguments()[0]),r=i&&St(i,!1);if(!i||r===void 0||bt(i,yt(i,!1)))return;const a=At(i,r);return a===void 0?void 0:{exportName:v(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:Nt(i,r),sideEffect:a}},uo=(e,t)=>w(e,t,lo),fo=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),go=new Set(["append","set"]),ns=e=>e!==void 0&&(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",Pt=(e,t)=>(o.isCallExpression(e)?[e,...e.getDescendantsOfKind(l.CallExpression)]:e.getDescendantsOfKind(l.CallExpression)).some(n=>fo.has(S(n.getExpression())??"")&&mn(n,t)),po=(e,t)=>{if(Pt(e,t))return!0;const s=fe(e);return s!==void 0&&Pt(s,t)},Ce=(e,t)=>pn(e,t)&&!po(e,t),mo=e=>{if(o.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=fe(e);return t!==void 0&&o.isNewExpression(t)&&S(t.getExpression())==="Headers"},ae=e=>{if(e===void 0)return;if(o.isObjectLiteralExpression(e))return e;const t=fe(e);return t!==void 0&&o.isObjectLiteralExpression(t)?t:void 0},Me=(e,t,s)=>{for(const n of e.getProperties())if(o.isPropertyAssignment(n)){const i=n.getInitializer();i!==void 0&&Ce(i,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:ns(n.getNameNode()),line:i.getStartLineNumber(),via:t})}else if(o.isShorthandPropertyAssignment(n)){const i=n.getNameNode();Ce(i,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:n.getName(),line:i.getStartLineNumber(),via:t})}else if(o.isSpreadAssignment(n)){const i=ae(n.getExpression());i!==void 0&&Me(i,t,s)}},rs=(e,t)=>{const s=ae(e);if(s===void 0)return;const n=s.getProperty("headers");if(n===void 0||!o.isPropertyAssignment(n))return;const i=ae(n.getInitializer());i!==void 0&&Me(i,"response-init",t)},ho=(e,t)=>{const s=S(e.getExpression());if(s==="Response")rs(e.getArguments()[1],t);else if(s==="Headers"){const n=ae(e.getArguments()[0]);n!==void 0&&Me(n,"headers-ctor",t)}},xo=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName(),i=s.getExpression();if(n==="json"&&o.isIdentifier(i)&&i.getText()==="Response"){rs(e.getArguments()[1],t);return}if(go.has(n)&&mo(i)){const r=e.getArguments()[1];r!==void 0&&Ce(r,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:ns(e.getArguments()[0]),line:r.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},vo=(e,t)=>{for(const s of e.getDescendantsOfKind(l.NewExpression))ho(s,t);for(const s of e.getDescendantsOfKind(l.CallExpression))xo(s,t)},Eo=(e,t)=>{const s=e.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=Y(e.getArguments()[0]);if(n===void 0)return[];const i=n.getParameters()[1];if(i===void 0)return[];const r=i.getNameNode();if(!o.isIdentifier(r))return[];const a=[];return vo(n,{exportName:v(e),relativePath:t,requestName:r.getText(),rows:a}),a},So=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression))s.push(...Eo(n,t));return s},yo=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...So(i,x(t,n)))}return s},Ao=new Set(["auth","context.auth","ctx.auth"]),No="userId",bo=e=>{const t=new Set;for(const s of e.getProperties()){if(o.isSpreadAssignment(s))return;(o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)||o.isMethodDeclaration(s))&&t.add(s.getName())}return t},Po=(e,t)=>{const s=E(t,Yt);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const i of n.getDescendantsOfKind(l.CallExpression)){if(S(i.getExpression())!=="defineIdentity")continue;const[r]=i.getArguments();return r&&o.isObjectLiteralExpression(r)?bo(r):void 0}},It=e=>{if(!(e===void 0||!o.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Ao.has(e.getExpression().getText())?e:void 0},Io=e=>{if(o.isPropertyAccessExpression(e)&&It(e.getExpression())!==void 0)return e.getName();if(o.isElementAccessExpression(e)&&It(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&o.isStringLiteral(t)?t.getLiteralValue():void 0}},wo=(e,t,s)=>{const n=[];for(const i of e.getDescendants()){const r=Io(i);r!==void 0&&n.push({declared:r===No||s.has(r),exportName:v(i),file:t,key:r,line:i.getStartLineNumber()})}return n},To=(e,t)=>{const s=Po(e,t);if(s===void 0)return[];const n=[];for(const i of p(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...wo(r,x(t,i),s))}return n},Co=(e,t)=>{if(S(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=A(s,"key");if(!(!n||!R(n)||_(n)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},Fo=(e,t)=>w(e,t,Co),Oo=new Set(["delete","get","getRaw","getWithMetadata","put"]),Ro=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return pe(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.kv"||r.startsWith("ctx.kv."),methods:Oo}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},Lo=new Set(["queue","send"]),wt=new Set(["bcc","cc","to"]),Do=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!Lo.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},ko=e=>o.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(o.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return wt.has(t.getName())&&R(n)&&!_(n)}if(!o.isPropertyAssignment(t)||!wt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&R(s)&&!_(s)}):!1,Mo=(e,t)=>{const s=Do(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!ko(n)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s}},Ko=(e,t)=>w(e,t,Mo),_o=e=>o.isPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?o.isComputedPropertyName(e.getNameNode()):!1,zo=e=>o.isPropertyAssignment(e)||o.isShorthandPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?_o(e):!0,is=(e,t=!1)=>{for(const s of e.getProperties()){if(zo(s))return!0;if(t)continue;if(!o.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!o.isObjectLiteralExpression(n)||is(n,!0))return!0}return!1},$o=(e,t)=>{for(const s of p(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:i}of Ht(n))for(const r of Le(i)){const a=r.getArguments()[0];if(a!==void 0&&(!o.isObjectLiteralExpression(a)||is(a)))return!0}}return!1},Uo=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const i=oe(n);if(i===void 0||!o.isPropertyAssignment(n))continue;const r=n.getInitializer();if(!(!r||!o.isObjectLiteralExpression(r)))for(const a of r.getProperties()){const c=oe(a);c!==void 0&&s.push({column:c,strategy:jt(a),table:i})}}return s},qo=(e,t)=>{const s=new Map;for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:r}of Ht(i))for(const a of Le(r))for(const c of Uo(a)){const u=`${c.table}\0${c.column}`;s.has(u)||s.set(u,c)}}return{columns:[...s.values()]}},Bo=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!o.isObjectLiteralExpression(n))return[];const i=[];for(const r of n.getProperties()){const a=oe(r);if(a===void 0||!o.isPropertyAssignment(r))continue;const c=r.getInitializer();if(!(!c||!o.isObjectLiteralExpression(c)))for(const u of c.getProperties()){const d=oe(u);if(d===void 0)continue;const h=jt(u);h!=="custom"&&i.push({column:d,exportName:t,file:s,line:u.getStartLineNumber(),strategy:h,table:a})}}return i},Vo=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?k(s):void 0;return n?.receiver?Le(n.receiver).flatMap(i=>Bo(i,e.getName(),t)):[]},Wo=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Vo(c,r))}return s},jo=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return D(s)},Ho=e=>{const t=e.getArguments()[0];if(t===void 0||!o.isObjectLiteralExpression(t))return;const s=t.getProperty("server");if(s!==void 0)return o.isPropertyAssignment(s)?s.getInitializer():s},Go=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==l.CallExpression)return;const s=t;return wn(s.getExpression())?s:void 0},Yo=e=>{const t=Go(e),s=t===void 0?void 0:Ho(t);if(s===void 0)return[];const n=e.getNameNode(),i=o.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(l.CallExpression).filter(r=>jo(r)).map(r=>({exportName:i,file:"lunora/mutators.ts",line:r.getStartLineNumber()}))},Qo=e=>e.getVariableDeclarations().flatMap(t=>Yo(t)),Xo=(e,t)=>{const s=E(t,In);if(!b(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Qo(n)},Zo=new Set(["delete","get","patch"]),Jo=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),ea=new Set(["auth","identity","session","user"]),ta=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),sa=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!D(t.getExpression()))return;const s=e.getArguments()[0];return s&&o.isStringLiteral(s)?s.getLiteralText():""},na=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(o.isAsExpression(s)||o.isParenthesizedExpression(s)||o.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!o.isVariableDeclaration(s))return;const n=s.getNameNode();return o.isIdentifier(n)?n.getText():void 0},ra=(e,t)=>e.getDescendantsOfKind(l.Identifier).some(s=>s.getText()===t),ia=e=>o.isThrowStatement(e)||o.isReturnStatement(e)||e.getDescendantsOfKind(l.ThrowStatement).length>0||e.getDescendantsOfKind(l.ReturnStatement).length>0,oa=(e,t)=>e.getDescendantsOfKind(l.IfStatement).some(s=>ra(s.getExpression(),t)&&ia(s.getThenStatement())),aa=(e,t)=>{for(const s of e.getDescendantsOfKind(l.CallExpression)){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))continue;const i=n.getName();if(!Zo.has(i))continue;const r=n.getExpression();if(!(D(r)||o.isPropertyAccessExpression(r)&&D(r.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&o.isIdentifier(c)&&c.getText()===t)return i}},ca=e=>{let t=e;for(;o.isPropertyAccessExpression(t)||o.isElementAccessExpression(t)||o.isNonNullExpression(t)||o.isParenthesizedExpression(t)||o.isAsExpression(t)||o.isAwaitExpression(t);)t=t.getExpression();return o.isIdentifier(t)?t.getText():void 0},la=e=>e.getDescendantsOfKind(l.CallExpression).some(t=>t.getArguments().some(s=>ca(s)==="ctx")),ua=e=>e.getDescendantsOfKind(l.BinaryExpression).some(t=>ta.has(t.getOperatorToken().getKind())?o.isPropertyAccessExpression(t.getLeft())||o.isPropertyAccessExpression(t.getRight()):!1),da=e=>{for(const t of e.getDescendantsOfKind(l.Identifier))if(Jo.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&s.getText()==="ctx"&&ea.has(t.getName()))return!0}return la(e)||ua(e)},fa=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=k(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const i=es(s);if(i===void 0)return[];const r=n.receiver!==void 0&&Wt(n.receiver,"use","rls"),a=da(i),c=new Set,u=[];for(const d of i.getDescendantsOfKind(l.CallExpression)){const h=sa(d);if(h===void 0)continue;const m=na(d);if(m===void 0||c.has(m)||!oa(i,m))continue;const P=aa(i,m);P!==void 0&&(c.add(m),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:P,table:h,usesRls:r,visibility:n.visibility}))}return u},ga=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...fa(c,r))}return s},pa=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),ma=new Set(["insert","insertManyUnsafe","patch","replace"]),ha=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!ma.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||s.getName()!=="db")return;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"?t:void 0},xa=(e,t)=>{if(t!=="insertManyUnsafe")return o.isObjectLiteralExpression(e)?[e]:[];if(!o.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())o.isObjectLiteralExpression(n)&&s.push(n);return s},Tt=(e,t)=>{if(o.isPropertyAccessExpression(e)){const s=e.getExpression();return o.isIdentifier(s)&&s.getText()==="args"&&e.getName()===t}if(o.isElementAccessExpression(e)){const s=e.getExpression(),n=e.getArgumentExpression();return o.isIdentifier(s)&&s.getText()==="args"&&n!==void 0&&o.isStringLiteral(n)&&n.getLiteralValue()===t}return!1},va=e=>{if(!o.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>o.isArrowFunction(a)||o.isFunctionExpression(a)||o.isFunctionDeclaration(a));if(s===void 0)return;for(const a of s.getDescendantsOfKind(l.BinaryExpression)){const c=a.getLeft();if(o.isIdentifier(c)&&c.getText()===t&&a.getOperatorToken().getText().endsWith("="))return}const n=e.getStart();let i,r=-1;for(const a of s.getDescendantsOfKind(l.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getParent();if(!o.isVariableDeclarationList(c)||c.getDeclarationKind()!==Fs.Const)continue;const u=a.getInitializer(),d=a.getStart();u!==void 0&&d<n&&d>r&&(i=u,r=d)}return i},Ea=(e,t)=>{if(Tt(e,t))return!0;const s=va(e);return s!==void 0&&Tt(s,t)},Sa=(e,t,s,n,i)=>{const r=[];for(const a of e.getProperties()){let c,u;if(o.isPropertyAssignment(a)?(c=a.getName(),u=a.getInitializer()):o.isShorthandPropertyAssignment(a)&&(c=a.getName(),u=a.getNameNode()),!(c===void 0||u===void 0||!pa.has(c))&&R(u)&&!_(u)){const d=v(s),h=i(d)===c&&Ea(u,c);r.push({exportName:d,field:c,file:n,line:s.getStartLineNumber(),method:t,...h&&{ownerScoped:!0}})}}return r},ya=(e,t,s)=>{const n=ha(e.getExpression());if(n===void 0)return[];const i=e.getArguments()[1];return i?xa(i,n).flatMap(r=>Sa(r,n,e,t,s)):[]},Aa=(e,t,s)=>{const n=[];for(const i of e.getDescendantsOfKind(l.CallExpression))for(const r of ya(i,t,a=>s(a).owner)){const{visibility:a}=s(r.exportName);n.push(a===void 0?r:{...r,visibility:a})}return n},Na=(e,t,s=[],n=[])=>{const i=[],r=new Map;for(const a of s)r.set(`${a.filePath}:${a.exportName}`,{visibility:a.visibility});for(const a of n){const c=`${a.filePath}:${a.exportName}`;r.set(c,{...r.get(c),owner:a.owner})}for(const a of p(t)){const c=e.getSourceFile(a)??e.addSourceFileAtPath(a),u=x(t,a);i.push(...Aa(c,u,d=>r.get(`${u}:${d}`)??{}))}return i},ba=["providerSubscriptionId","state"],Pa=["providerEventId","processedAt"],Ct=(e,t)=>t.every(s=>s in e.shape),Ia=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&Ct(t,ba)&&Ct(s,Pa)},wa=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Ta=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,Ca=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&o.isPropertyAssignment(t)?Ta(t.getInitializer()):void 0},Fa=(e,t)=>{const s=S(e.getExpression());if(s===void 0||!wa.has(s))return;const[n]=e.getArguments(),i=n&&o.isObjectLiteralExpression(n)?Ca(n):void 0;return{callee:s,exportName:v(e),file:t,line:e.getStartLineNumber(),...i===void 0?{}:{toleranceSeconds:i}}},Oa=(e,t)=>w(e,t,Fa),Ra=new Set(["defineQueue","defineWorkflow"]),La=new Set(["run","runAction","runMutation","runQuery"]),Da=new Set(["api","internal"]),ka=e=>{const t=e.getExpression();return o.isIdentifier(t)?t.getText():void 0},Ma=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!o.isPropertyAssignment(s))return;const n=s.getInitializer();if(n&&(o.isArrowFunction(n)||o.isFunctionExpression(n)))return n},os=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&o.isIdentifier(s)?s.getText():void 0},as=(e,t)=>e===t||e.startsWith(`${t}.`),cs=e=>{const t=e.getDescendantsOfKind(l.PropertyAccessExpression);return o.isPropertyAccessExpression(e)&&t.push(e),t},Ft=e=>{const t=e.getParent();return o.isPropertyAccessExpression(t)&&t.getNameNode()===e||o.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(o.isBindingElement(t)&&t.getNameNode()===e)},ls=e=>{const t=e.getDescendantsOfKind(l.Identifier).filter(s=>Ft(s));return o.isIdentifier(e)&&Ft(e)&&t.push(e),t},Ka=e=>{if(!o.isVariableDeclaration(e))return[];const t=e.getNameNode();return o.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(l.BindingElement).map(s=>s.getName())},_a=e=>{const t=os(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(l.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const i=n.getInitializer(),r=o.isVariableDeclarationList(i)?i.getDeclarations()[0]?.getNameNode():void 0;r&&o.isIdentifier(r)&&s.push(`${r.getText()}.body`)}return s},za=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:_a(e),i=new Set,r=a=>cs(a).some(c=>n.some(u=>as(c.getText(),u)))?!0:ls(a).some(c=>i.has(c.getText()));for(const a of e.getDescendantsOfKind(l.VariableDeclaration)){const c=a.getInitializer();if(c&&r(c))for(const u of Ka(a))i.add(u)}return{names:i,prefixes:n}},$a=(e,t)=>cs(e).some(s=>t.prefixes.some(n=>as(s.getText(),n)))?!0:ls(e).some(s=>t.names.has(s.getText())),Ua=e=>{if(e===void 0||!o.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;o.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const n=t.at(-1);if(!(n===void 0||!o.isIdentifier(s)||!Da.has(s.getText())||t.length<2))return{exportName:n,file:t.slice(0,-1).join("/")}},qa=(e,t,s)=>{const n=os(e,0);if(n===void 0)return[];const i=za(e,t,n),r=[];for(const a of e.getDescendantsOfKind(l.CallExpression)){const c=a.getExpression();if(!o.isPropertyAccessExpression(c)||!La.has(c.getName())||c.getExpression().getText()!==n)continue;const u=a.getArguments()[1];if(!u||!$a(u,i))continue;const d=Ua(a.getArguments()[0]);d!==void 0&&r.push({dispatchKind:t,file:s,handlerExport:v(a),line:a.getStartLineNumber(),targetExport:d.exportName,targetFile:d.file})}return r},Ba=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=ka(n);if(i===void 0||!Ra.has(i))continue;const r=Ma(n);r!==void 0&&s.push(...qa(r,i==="defineQueue"?"queue":"workflow",t))}return s},Va=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ba(i,x(t,n)))}return s},Ot={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},Rt=new Set(["account","credential","member","passkey","session","user"]),Wa=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),ja=e=>{const s=Wa(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return Rt.has(s)||Rt.has(n)},Ha=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Ga=(e,t)=>{const{objects:s,opaque:n}=ke(e,t);return qr(s).some(i=>Ha(i))?!0:n?void 0:!1},Ya=e=>{const t=e.getArguments()[0];return!t||!o.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Qa=e=>{if(o.isCallExpression(e))return e;if(!o.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&o.isCallExpression(s)?s:void 0},ie={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Xa=e=>{const t=Qa(e),s=t?S(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=Ya(t);return{...ie,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in Ot?{...ie,[Ot[s]]:!0}:ie},Za=e=>{const t={...ie};let s=e;for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))break;const i=n.getName()==="use"?s.getArguments()[0]:void 0;if(i){const r=Xa(i);t.usesCaptcha||=r.usesCaptcha,t.usesEmailGate||=r.usesEmailGate,t.usesMask||=r.usesMask,t.usesRateLimit||=r.usesRateLimit,t.usesRls||=r.usesRls}s=n.getExpression()}return t},Ja=new Set(["insert","insertMany","insertManyUnsafe","replace"]),ec=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Ja.has(t.getName()))return!1;const s=t.getExpression();if(!D(s))return!1;const i=e.getArguments()[0];return!i||!(o.isStringLiteral(i)||o.isNoSubstitutionTemplateLiteral(i))?!1:ja(i.getLiteralText())},tc=new Set(["create","runAfter","runAt","send","sendBatch"]),sc=new Set(["queues","scheduler","workflows"]),nc=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!tc.has(t.getName()))return!1;let s=t.getExpression();for(;o.isCallExpression(s)||o.isElementAccessExpression(s)||o.isPropertyAccessExpression(s);){if(o.isPropertyAccessExpression(s)&&sc.has(s.getName())){const n=s.getExpression();if(o.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},rc=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return D(s)},us=new Set(["generateObject","generateText","streamObject","streamText"]),ic=e=>{const t=S(e.getExpression());return t!==void 0&&us.has(t)},oc=e=>{const t=S(e.getExpression());if(t===void 0||!us.has(t))return!1;const s=e.getArguments()[0];return!s||!o.isObjectLiteralExpression(s)||s.getProperties().some(n=>o.isSpreadAssignment(n))?!1:!s.getProperty("maxOutputTokens")},ac=new Set(["log","span","trace"]),cc=new Set(["ai"]),lc=new Set(["email","mail"]),uc=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),be=(e,t)=>e.getDescendantsOfKind(l.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"}),dc=new Set([l.ArrowFunction,l.FunctionDeclaration,l.FunctionExpression,l.GetAccessor,l.MethodDeclaration,l.SetAccessor]),fc=new Set(["every","filter","flatMap","forEach","map","some"]),gc=new Set(["all","allSettled","race"]),pc=e=>{const t=e.getParent();if(!t||!o.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName();if(fc.has(n))return t;const i=s.getExpression();if(o.isIdentifier(i)&&i.getText()==="Promise"&&gc.has(n))return t},mc=e=>{let t=e.getParent();for(;t;){if(o.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(dc.has(t.getKind())){const s=pc(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},hc=e=>{let t=e;for(;;){const s=t.getParent();if(!o.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;if(s.getName()==="catch")return!0;if(s.getName()!=="then"&&s.getName()!=="finally")return!1;const n=s.getParent();if(!o.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},xc=e=>{let t=e;for(;;){const s=t.getParent();if(o.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return o.isCallExpression(s)&&s.getExpression()===t?s:void 0}},vc=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression)){if(!uc.has(n.getName()))continue;const i=n.getExpression();if(!o.isIdentifier(i)||i.getText()!=="ctx")continue;const r=xc(n);r&&(t=!0,!mc(r)&&!hc(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},Ec=e=>e.getDescendantsOfKind(l.ThrowStatement).some(t=>{const s=t.getExpression();if(!o.isNewExpression(s))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="Error"}),Lt="lunora-advisor-exempt",Sc=/^[\s*/]+/u,yc=/[\w-]/u,Ac=e=>{const s=(e.getFirstAncestorByKind(l.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
|
|
6
|
-
`);for(const n of s.split(`
|
|
7
|
-
`)){const i=n.replace(Sc,"");if(!i.startsWith(Lt))continue;const r=i.slice(Lt.length);if(yc.test(r.charAt(0)))continue;const a=r.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":r.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},Nc=e=>{const[t]=e.getArguments();if(t){if(o.isObjectLiteralExpression(t)){const s=t.getProperty("handler");return s?o.isPropertyAssignment(s)?s.getInitializer():o.isShorthandPropertyAssignment(s)?s.getNameNode():o.isMethodDeclaration(s)?s:void 0:void 0}return t}},bc=(e,t)=>{const s=Nc(t);if(!s)return;if(o.isArrowFunction(s)||o.isFunctionExpression(s)||o.isMethodDeclaration(s))return e;if(!o.isIdentifier(s))return;const n=s.getSourceFile(),i=s.getText(),r=n.getVariableDeclaration(i)?.getInitializer();return r&&(o.isArrowFunction(r)||o.isFunctionExpression(r))?r:n.getFunction(i)},Pc=e=>{let t=!1,s=!1,n=!1,i=!1,r=!1;for(const u of e.getDescendantsOfKind(l.CallExpression))if(ec(u)&&(r=!0),nc(u)&&(t=!0),rc(u)&&(i=!0),ic(u)&&(s=!0),oc(u)&&(n=!0),r&&t&&i&&n)break;const{handlesErrors:a,reachesOutbound:c}=vc(e);return{callsMail:be(e,lc),emitsEvent:be(e,ac),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||be(e,cc),throwsBareError:Ec(e),unboundedAiGeneration:n,usesInsertManyUnsafe:i,writesUserTable:r}},Ic=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=k(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const i=n.receiver?Za(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},r=bc(e,s);return{...r?Pc(r):{},...Ac(e),...i,analyzableBody:r!==void 0,exportName:e.getName(),file:t,hasEmailArg:Ga(s,n.receiver),kind:n.kind,visibility:n.visibility}},wc=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=Ic(i,t);r&&s.push(r)}return s},Tc=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...wc(i,x(t,n)))}return s},Cc=new Set(["dbRateLimit","rateLimit"]),Fc=e=>o.isArrowFunction(e)?e.getBody():e,Oc=(e,t)=>{const s=S(e.getExpression());if(s===void 0||!Cc.has(s))return;const n=e.getArguments()[2];if(!n)return;const i=A(n,"key");if(!i)return;const r=Fc(i);if(!(!R(r)||_(r)))return{callee:s,exportName:v(e),file:t,limitName:Bt(e),line:e.getStartLineNumber()}},Rc=(e,t)=>w(e,t,Oc),Lc=new Set(["findFirst","findFirstOrThrow","findMany","findUnique","get"]),Dc=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Lc.has(t.getName()))return;const s=t.getExpression();if(D(s)){const n=e.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}if(o.isPropertyAccessExpression(s)&&D(s.getExpression()))return s.getName()},kc=e=>{let t=e;for(;o.isCallExpression(t);){const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&D(s.getExpression())){const n=t.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},Mc=e=>{let t=G(e)??e;for(;o.isAwaitExpression(t);)t=G(t.getExpression())??t.getExpression();return t},ds=(e,t=!1)=>{const s=Mc(e);if(o.isIdentifier(s)){if(t)return;const n=fe(s);return n===void 0?void 0:ds(n,!0)}if(o.isCallExpression(s))return Dc(s)??kc(s)},Kc=e=>{const t=e.getBody();if(!o.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(l.ReturnStatement)){const i=n.getFirstAncestor(a=>o.isArrowFunction(a)||o.isFunctionExpression(a)||o.isFunctionDeclaration(a)),r=n.getExpression();i===e&&r!==void 0&&s.push(r)}return s},_c=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=k(s);if(n?.kind!=="query")return[];const i=es(s);if(i===void 0)return[];const r=n.receiver!==void 0&&an(n.receiver,"output"),a=n.receiver!==void 0&&Wt(n.receiver,"use","mask"),c=new Set,u=[];for(const d of Kc(i)){const h=ds(d);h===void 0||c.has(h)||(c.add(h),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:h,usesMask:a,usesOutput:r,visibility:n.visibility}))}return u},zc=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(..._c(c,r))}return s},$c=e=>{if(!e||!o.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)||o.isMethodDeclaration(s)||o.isGetAccessorDeclaration(s))&&t.push(s.getName());return t},Uc=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?k(s):void 0;if(!n)return[];const i=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Vt(r);if(a===void 0)continue;const c=$c(A(a.options,"with"));c.length!==0&&i.push({exportName:e.getName(),file:t,line:r.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return i},qc=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Uc(c,r))}return s},ce=e=>{if(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(o.isBinaryExpression(e)&&e.getOperatorToken().getKind()===l.PlusToken){const t=ce(e.getLeft()),s=ce(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},Bc=e=>{let t=e,s=t.getParent();for(;s!==void 0&&o.isBinaryExpression(s)&&s.getOperatorToken().getKind()===l.PlusToken;)t=s,s=t.getParent();return t!==e&&ce(t)!==void 0},Vc=/(?:^|\/)__tests__\//u,Wc=/\.(?:spec|test)$/u,jc=e=>Vc.test(e)||Wc.test(e),Hc=e=>{const t=e.getParent();if(t!==void 0){if(o.isVariableDeclaration(t)||o.isPropertyAssignment(t)||o.isPropertySignature(t))return t.getName();if(o.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.EqualsToken)return t.getLeft().getText()}},Gc=(e,t,s)=>Kn(e)?!jc(s)&&_n(Hc(t)):!0,Yc=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(l.BinaryExpression),...e.getDescendantsOfKind(l.StringLiteral),...e.getDescendantsOfKind(l.NoSubstitutionTemplateLiteral)],i=new Set;for(const r of n){if(Bc(r))continue;const a=ce(r);if(a===void 0)continue;const c=kn(a);if(c===void 0||!Gc(c,r,t))continue;const u=r.getStartLineNumber(),d=`${String(u)}:${c}`;i.has(d)||(i.add(d),s.push({file:t,kind:c,line:u,preview:Mn(a)}))}return s},Qc=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Yc(i,x(t,n)))}return s},Xc=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?k(s):void 0;if(!n)return[];const i=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Vt(r);if(a===void 0)continue;const c=A(a.options,"includeDeleted");if(c===void 0)continue;const u=o.isTrueLiteral(c),d=!u&&R(c);!u&&!d||i.push({exportName:e.getName(),file:t,fromArgs:d,hardcodedTrue:u,line:r.getStartLineNumber(),table:a.table,visibility:n.visibility})}return i},Zc=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Xc(c,r))}return s},Jc=new Set(["query","unsafe"]),el=e=>{if(!o.isPropertyAccessExpression(e)||!Jc.has(e.getName()))return!1;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return o.isIdentifier(s)&&s.getText()==="ctx"},tl=e=>o.isBinaryExpression(e)||o.isTemplateExpression(e),sl=e=>e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()??"<module>",nl=(e,t)=>{if(!el(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!tl(s)))return{exportName:sl(e),file:t,line:s.getStartLineNumber()}},rl=(e,t)=>w(e,t,nl),il=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],ol=e=>{for(const[t,s]of il)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},al=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of i.getImportDeclarations()){const a=r.getModuleSpecifierValue(),c=ol(a);c!==void 0&&s.push({file:x(t,n),line:r.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},cl=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),ll=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return pe(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:cl,requireUnmodifiedReach:!0}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},ul=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),dl=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,fl=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!o.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const i of e.getProperties()){if(o.isSpreadAssignment(i)){n=!0;continue}if(o.isPropertyAssignment(i)){const r=i.getName();t.push(r),r==="expiresInSeconds"&&(s=dl(i.getInitializer()));continue}(o.isShorthandPropertyAssignment(i)||o.isMethodDeclaration(i))&&t.push(i.getName())}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},gl=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName(),s=ul.get(t);if(s===void 0)return;const n=e.getExpression().getText();return n==="ctx.storage"||n.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},pl=(e,t)=>{const s=gl(e.getExpression());if(s!==void 0)return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s.method,...fl(e.getArguments()[s.optionsIndex])}},ml=(e,t)=>w(e,t,pl),hl=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:t.vectorStoreSupported&&t.vectorIndexCount>0,workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),xl=(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"}),vl=(e,t)=>{if(t===void 0){const s=e.getArguments()[0];if(s===void 0||!o.isObjectLiteralExpression(s)||s.getProperty("args")===void 0)return!1}return ke(e,t).opaque},El=(e,t)=>{const s=[],n=(i,r)=>{const a=i.getInitializer();if(a===void 0||!o.isCallExpression(a))return;const c=k(a);c!==void 0&&vl(a,c.receiver)&&s.push(xl(t,r,a.getStartLineNumber()))};for(const i of e.getVariableStatements().filter(r=>r.isExported()))for(const r of i.getDeclarations())n(r,r.getName());return s},Sl=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n);i!==void 0&&s.push(...El(i,x(t,n)))}return s.toSorted((n,i)=>n.cacheKey.localeCompare(i.cacheKey))},yl=new Map([["AgentDefinition",{call:"defineAgent({ … })",file:"agents"}],["ContainerDefinition",{call:"defineContainer({ … })",file:"containers"}],["QueueDefinition",{call:"defineQueue({ … })",file:"queues",note:"A dropped queue has no caller to fail — its consumer is simply never wired."}],["RegisteredAction",{call:"action.input({ … }).action(handler)"}],["RegisteredLifecycleHook",{call:"onConnect(handler)",note:"Substitute the hook you called: `onConnect`, `onDisconnect` and `onShardInit` share one type, so codegen cannot tell which you wrote. A dropped hook has no caller to fail — it silently never fires."}],["RegisteredMigration",{call:"defineMigration({ … })",note:"A dropped migration never runs, so `lunora migrate up` reports nothing to do."}],["RegisteredMutation",{call:"mutation.input({ … }).mutation(handler)"}],["RegisteredMutator",{call:"defineMutator({ … })",file:"mutators"}],["RegisteredQuery",{call:"query.input({ … }).query(handler)"}],["RegisteredReactor",{call:"onQueryChange(select, handler)",note:"A dropped reactor has no caller to fail — it silently never runs."}],["RegisteredShape",{call:"defineShape({ … })",file:"shapes"}],["RegisteredStream",{call:"query.input({ … }).stream(handler)"}],["RegisteredWhisperAuthorizer",{call:"onWhisper(handler)",note:"A dropped authorizer has no caller to fail — the whisper topics it was meant to gate silently stay open to every socket on the shard."}],["WorkflowDefinition",{call:"defineWorkflow({ … })",file:"workflows"}]]),me=({byName:e,byPath:t},s,n)=>t.has(`${s}:${n}`)||e.has(n),fs=e=>!e.isAny(),Ke=e=>{const t=e.getType();if(!fs(t))return;const s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName(),n=s===void 0?void 0:yl.get(s);return n===void 0||s===void 0?void 0:{...n,typeName:s}},gs=e=>{const t=e.getInitializer();return t===void 0?!1:o.isCallExpression(t)||o.isIdentifier(t)||o.isPropertyAccessExpression(t)},ps={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."},Al=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.`}),Nl={cause:"the binding is exported by a separate `export { … }` statement, and codegen reads the `export` keyword on the declaration itself",remediation:"Move the keyword onto the declaration and drop the separate export statement."},_e=(e,t,s,n,i)=>{const{call:r,file:a,note:c,typeName:u}=s,d=a!==void 0&&e!==a?a:void 0,h=d===void 0?i:Al(d),m=c===void 0?h.remediation:`${c} ${h.remediation}`;return{cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally the registering call. 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 \`${u}\` but was not registered — ${h.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:u},name:"procedure_not_registered",remediation:d===void 0?`Assign the registration directly: \`export const ${t} = ${r};\`. ${m}`:m,title:"Procedure exists at runtime but is missing from the generated API"}},bl=(e,t,s)=>{const n=[];for(const i of e.getVariableStatements().filter(r=>r.isExported()))for(const r of i.getDeclarations()){const a=r.getName();if(me(s,t,a)||!gs(r))continue;const c=Ke(r);c!==void 0&&n.push(_e(t,a,c,r.getStartLineNumber(),ps))}return n},Pl=(e,t,s)=>{if(me(s,t,"default"))return[];const n=[];for(const i of e.getExportAssignments().filter(r=>!r.isExportEquals())){const r=Ke(i.getExpression());r!==void 0&&n.push(_e(t,"default",r,i.getStartLineNumber(),ps))}return n},Il=(e,t,s)=>{const n=[];for(const i of e.getExportDeclarations().filter(r=>r.getModuleSpecifier()===void 0))for(const r of i.getNamedExports()){const a=r.getAliasNode()?.getText()??r.getName();if(me(s,t,a))continue;const c=r.getLocalTargetDeclarations().find(d=>o.isVariableDeclaration(d));if(c===void 0||!gs(c))continue;const u=Ke(c);u!==void 0&&n.push(_e(t,a,u,r.getStartLineNumber(),Nl))}return n},wl=(e,t,s)=>[...bl(e,t,s),...Pl(e,t,s),...Il(e,t,s)],Tl=(e,t,s)=>e.getVariableStatements().filter(n=>n.isExported()).flatMap(n=>n.getDeclarations()).filter(n=>me(s,t,n.getName())).filter(n=>{const i=n.getInitializer();return i!==void 0&&o.isCallExpression(i)&&o.isPropertyAccessExpression(i.getExpression())}).map(n=>({declaration:n,exportName:n.getName(),relativePath:t})),Cl=({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"}),Fl=(e,t,s)=>{const n=[],i=[];for(const a of p(t)){const c=e.getSourceFile(a);if(c===void 0)continue;const u=x(t,a);n.push(...wl(c,u,s)),i.push(...Tl(c,u,s))}const[r]=i;return r!==void 0&&i.every(({declaration:a})=>!fs(a.getType()))&&n.push(Cl(r)),n.toSorted((a,c)=>a.cacheKey.localeCompare(c.cacheKey))},Ol=new Set(["when","where"]),Pe=new Set(["definePolicy","defineShape"]),Rl=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(o.isPropertyAccessExpression(t)){const n=t.getName();return Pe.has(n)?n:void 0}if(!o.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(o.isImportSpecifier(n)){const i=n.getNameNode().getText();return Pe.has(i)?i:void 0}const s=t.getText();return Pe.has(s)?s:void 0},Ll=e=>o.isObjectLiteralExpression(e)&&e.getProperties().length===0,ms=e=>{if(e!==void 0){if(o.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===l.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Ll(e))return"empty-object";if(o.isParenthesizedExpression(e))return ms(e.getExpression())}},ze=e=>e.getAncestors().find(t=>o.isArrowFunction(t)||o.isFunctionExpression(t)||o.isFunctionDeclaration(t)),Dl=e=>e.getDescendantsOfKind(l.ReturnStatement).filter(t=>ze(t)===e),hs=e=>e.getDescendantsOfKind(l.ConditionalExpression).filter(t=>ze(t)===e),kl=e=>{const t=Dl(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(l.IfStatement)!==void 0)||hs(e).length>0},Ml=e=>e.getDescendantsOfKind(l.IfStatement).filter(t=>ze(t)===e),Fe=e=>e.getKind()===l.NullKeyword||e.getKind()===l.FalseKeyword||o.isIdentifier(e)&&e.getText()==="undefined"?!0:o.isNumericLiteral(e)?e.getLiteralValue()===0:o.isStringLiteral(e)&&e.getLiteralValue()==="",Kl=(e,t)=>Fe(e)||Fe(t),_l=new Map([[l.EqualsEqualsEqualsToken,"positive"],[l.EqualsEqualsToken,"positive"],[l.ExclamationEqualsEqualsToken,"negative"],[l.ExclamationEqualsToken,"negative"]]),Dt=e=>!Fe(e)&&(o.isLiteralExpression(e)||e.getKind()===l.TrueKeyword),zl=(e,t,s)=>{const n=_l.get(e);if(n!==void 0)return Kl(t,s)?n==="positive"?"negative":"positive":Dt(t)||Dt(s)?void 0:n},H=e=>{if(o.isParenthesizedExpression(e))return H(e.getExpression());if(o.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken)return"negative";if(o.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=zl(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===l.AmpersandAmpersandToken||t===l.BarBarToken){const n=H(e.getLeft()),i=H(e.getRight());return n===i?n:"indeterminate"}}return o.isIdentifier(e)||o.isPropertyAccessExpression(e)||o.isElementAccessExpression(e)||o.isCallExpression(e)?"positive":"indeterminate"},kt=e=>{if(e!==void 0){if(o.isReturnStatement(e))return e;if(o.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&o.isReturnStatement(t)?t:void 0}}},$l=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(l.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Ul=e=>o.isReturnStatement(e)?e.getExpression()??e:e,ql=e=>{const t=[];for(const s of hs(e)){const n=H(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of Ml(e)){const n=H(s.getExpression());if(n==="indeterminate")continue;const i=n==="negative"?kt(s.getThenStatement()):kt(s.getElseStatement())??$l(s);i!==void 0&&t.push(Ul(i))}return t},Bl=e=>{for(const t of e.getAncestors())if(o.isVariableDeclaration(t)){const s=t.getNameNode();if(o.isIdentifier(s))return s.getText()}return"<anonymous>"},Vl=(e,t,s)=>{if(!o.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!o.isObjectLiteralExpression(n))return[];const i=[];for(const r of n.getProperties()){if(!o.isPropertyAssignment(r)||!Ol.has(r.getName()))continue;const a=r.getInitializer();if(!(!a||!(o.isArrowFunction(a)||o.isFunctionExpression(a)))&&kl(a))for(const c of ql(a)){const u=ms(c);u!==void 0&&i.push({exportName:Bl(e),file:s,form:u,key:r.getName(),line:c.getStartLineNumber(),owner:t})}}return i},Wl=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=Rl(n);i!==void 0&&s.push(...Vl(n,i,t))}return s},jl=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Wl(i,x(t,n)))}return s},Hl=new Set(["query","upsert","upsertMany"]),Gl=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(Hl.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Yl=(e,t)=>{const s=Gl(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const i=A(n,"namespace");if(!(!i||!R(i)||_(i)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s}},Ql=(e,t)=>w(e,t,Yl),Xl=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return o.isPropertyAccessExpression(s)?s.getName()==="workflows":o.isIdentifier(s)&&s.getText()==="workflows"},Zl=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},Jl=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of i.getDescendantsOfKind(l.CallExpression)){if(!Xl(a))continue;const c=tn(a);c!==""&&s.push({exportName:c,file:r,line:a.getStartLineNumber(),workflow:Zl(a)})}}return s},eu=".lunora-schema.json",Oe=(e,t)=>{b(e)&&_t(e,"utf8")===t||ws(e,t,"utf8")},tu=(e,t)=>{if(t===""){Ts(e,{force:!0});return}Oe(e,t)},su=e=>{const t=E(e,"package.json");if(b(t))try{const s=JSON.parse(_t(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},nu=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},ru=e=>{let t=b(e)?e:ne(e);for(;t&&t!==ne(t);){const s=E(t,"tsconfig.json");if(b(s))return s;t=ne(t)}},Mt=e=>e.replaceAll("\\","/"),iu=(e,t,s)=>{if(s&&e.length>0){const r=e.map(a=>`"${a.exportName}"`).join(", ");throw new L("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${r}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const r of t.columns){const a=n.get(r.table)??[];a.push(r.column),n.set(r.table,a)}const i=t.columns.length>0;for(const r of e){if(r.table===void 0){if(i)throw new L("MASK_UNSUPPORTED",`defineShape "${r.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${r.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(r.table);if(a===void 0)continue;const c=a.map(u=>`"${u}"`).join(", ");throw new L("MASK_UNSUPPORTED",`defineShape "${r.exportName}" replicates table "${r.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},le=(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)},Kt=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,ou=8,au=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:i,migrations:r,project:a,shapes:c,usesSandbox:u,useUmbrella:d,workflows:h}=e;let m=lt(a,i),P=dt(a,i),M=ut(a,i);ft([...m,...P].map(g=>g.filePath)),ft(M.filter(g=>g.stream).map(g=>g.filePath),"http-stream");for(let g=1;;g+=1){const T=Gs({agents:t,functions:m,httpRoutes:M,mutators:P,useUmbrella:d,workflows:h}),F=Ys({agents:t,functions:m,migrations:r,mutators:P,shapes:c,useUmbrella:d,usesSandbox:u});if(g>=ou||Kt(a,s,T)&&Kt(a,n,F))return{apiContent:T,functions:m,functionsContent:F,httpRoutes:M,mutators:P};le(a,s,T),le(a,n,F),m=lt(a,i),P=dt(a,i),M=ut(a,i)}},cu=e=>{const t=ru(e);return t?new ct({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new ct({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},nd=(e,t)=>{const s=p(t),n=E(t,"schema.ts");b(n)&&s.push(n);for(const c of s){const u=e.getSourceFile(c);u===void 0?e.addSourceFileAtPath(c):u.refreshFromFileSystemSync()}const i=new Set(s.map(c=>Mt(c))),r=Mt(t),a=`${r}/`;for(const c of e.getSourceFiles()){const u=c.getFilePath();(u===r||u.startsWith(a))&&!i.has(u)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const u=c.getFilePath();if(!(u===r||u.startsWith(a)||u.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},rd=e=>{const t=nu(),s=t?Ae.now():0,n=E(e.projectRoot,e.lunoraDirectory??"lunora"),i=E(n,"schema.ts");if(!b(i))throw new L("INTERNAL",`schema.ts not found at ${i}`);const r=e.project??cu(n);xn(Yi);const a=Dn(r,i,e.projectRoot),{agents:c,containers:u,crons:d,dataModelContent:h,dependencies:m,entryCronTriggers:P,env:M,featureUsage:g,hasFlags:T,hasNotify:F,identity:U,platformGate:y,queues:O,serverContent:z,storageRulesMetadata:W,usesSandbox:X,useUmbrella:K,workflows:C}=mr({lunoraDirectory:n,project:r,projectRoot:e.projectRoot,schema:a,target:e.target}),N=E(n,"_generated"),xs=E(N,"dataModel.ts"),vs=E(N,"server.ts"),Es=E(N,"api.ts"),Ss=E(N,"functions.ts");le(r,xs,h),le(r,vs,z);const Z=Pn(r,n),q=zn(r,n),{apiContent:$e,functions:B,functionsContent:Ue,httpRoutes:ys,mutators:J}=au({agents:c,apiPath:Es,generatedFunctionsPath:Ss,lunoraDirectory:n,migrations:Z,project:r,shapes:q,useUmbrella:K,usesSandbox:X,workflows:C}),ee=e.lint===!1?void 0:Rs({adminRoutes:Nr(r,n),aiRawRuns:Ir(r,n),aiToolSideEffects:Mr(r,n),argumentDerivedFetches:zr(r,n),argumentValidators:Yr(r,n),authApiCalls:vn(r,n),authConfigs:ii(r,n),browserUrlAccesses:ui(r,n),configCalls:vi(r,n),containerKeyAccesses:Si(r,n),containerOverrides:Ii(r,n),containers:u,exportSinks:Fi(r,n),staleMigrationImports:al(r,n),failOpenGuards:ki(r,n),flagReads:Vi(r,n),flagSecurityDefaults:Gi(r,n),geoIndexUsages:Zi(r,n),httpActionGuards:uo(r,n),httpHeaderWrites:yo(r,n),hyperdriveCalls:An(r,n),identityClaimReads:To(r,n),imageDeliveryUrlAccesses:Fo(r,n),inserts:Nn(r,n),kvKeyAccesses:Ro(r,n,B),mailRecipientAccesses:Ko(r,n),maskProcedures:bn(r,n),maskStrategies:Wo(r,n),mutatorWrites:Xo(r,n),nondeterministicCalls:Tn(r,n),normalizeIdAuthorizations:ga(r,n),notifyCalls:Fn(r,n),notifyConfig:Cn(r,n),mutators:J,ownerFieldWrites:Na(r,n,B,J),unrestrictedWhereBranches:jl(r,n),paymentWebhooks:Oa(r,n),privilegedDispatches:Va(r,n),procedureProtections:Tc(r,n),queries:hn(r,n),queues:O,r2sqlCalls:On(r,n),ratelimitKeySelectors:Rc(r,n),rawRowReturns:zc(r,n),relationLoads:qc(r,n),rlsProcedures:Rn(r,n),schema:a,secretLiterals:Qc(r,n),shapes:q,softDeleteReads:Zc(r,n),sqlInterpolations:rl(r,n),storageKeyAccesses:ll(r,n,B),storageUploads:ml(r,n),vectorNamespaceAccesses:Ql(r,n),workflowCalls:Jl(r,n),workflows:C,wranglerVariables:e.wranglerVariables}),qe=ee===void 0?[]:[...Cs(ee,{source:"static"}),...Fl(r,n,{byName:new Set([...C,...O,...c,...u].map(f=>f.exportName)),byPath:new Set([...B,...J,...q,...Z].map(f=>`${f.filePath}:${f.exportName}`))}),...Sl(r,n)],As=Ln(r,n),Be=qo(r,n);iu(q,Be,$o(r,n));const Ns=T?zi(r,n):[],he=y.signals.vectorStore!==!1,j=hl(g,{containerCount:u.length,cronCount:d.length,dependencies:m,hasPaymentTables:Ia(a.tables),queueCount:O.length,storageColumnCount:Object.keys(zt(a)).length,storageRuleCount:W.rules.length,vectorIndexCount:a.vectorIndexes.length,vectorStoreSupported:he,workflowCount:C.length}),Ve=t?Ae.now():0,xe=Wn(a,Z.map(f=>f.id)),We=Ms({advisories:qe.filter(f=>f.name!=="procedure_type_check_unavailable"),advisorProcedures:ee?.procedureProtections??[],agents:c,containers:u,env:M,flagKeys:Ns,hasAccessFacade:g.access,hasAi:g.ai,hasAnalytics:g.analytics,hasBrowser:g.browser,hasFlags:T,hasHyperdrive:g.hyperdrive,hasImages:g.images,hasKv:g.kv,hasNotify:F,hasPayments:g.payments,hasPipelines:g.pipelines,hasR2sql:g.r2sql,hasVectors:he,hasX402:g.x402,maskMetadata:Be,mutators:J,queues:O,rlsMetadata:As,schema:a,schemaSnapshot:xe,shapes:q,storageRules:W,studioFeatures:j,useUmbrella:K,workflows:C}),je=Ks(q,m.has("@lunora/db"),K),He=_s(u,a.jurisdiction),Ge=zs(C),Ye=$s(c),Qe=Us(O),Xe=qs(d),bs=Bs(j.scheduler),Ze=Vs(a.vectorIndexes),te=Ws(a,K),Je=js(m.has("@lunora/seed")),se=e.apiSpec??"openapi",ve=se==="openapi"||se==="both",Ee=se==="openrpc"||se==="both",et=$n({emailAgents:c.filter(f=>f.onEmail===!0).map(f=>({bindingName:f.bindingName,exportName:f.exportName})),hasAccess:m.has("@lunora/cloudflare-access"),hasAi:g.ai,hasAnalytics:g.analytics,hasAuth:m.has("@lunora/auth"),hasBrowser:g.browser,hasFramework:m.has("@lunora/astro")||m.has("@lunora/svelte")||m.has("@lunora/vue"),hasGlobal:a.tables.some(f=>$t(f)),hasHyperdrive:g.hyperdrive,hasHyperdriveGlobal:a.tables.some(f=>Ut(f)),hasImages:g.images,hasKv:g.kv,hasKvIntrospector:j.kv,hasNotify:F,hasPayments:g.payments,hasR2sql:g.r2sql,hasQueue:O.some(f=>f.mode==="push"),hasScheduler:j.scheduler,hasSourcedTables:a.tables.some(f=>f.externalSource!==void 0),hasStorage:j.storage,hasVectors:he,hasWorkflow:C.length>0,hasX402:g.x402,identity:U,jurisdiction:a.jurisdiction,tableNames:a.tables.map(f=>f.name),useUmbrella:K,vectorIndexCount:a.vectorIndexes.length,voiceAgents:c.filter(f=>f.voice===!0&&f.voiceBindingName!==void 0).map(f=>({bindingName:f.voiceBindingName,exportName:f.exportName})),wantsOpenApi:ve,wantsOpenRpc:Ee}),tt=su(e.projectRoot),st=Un({functions:B,httpRoutes:ys,version:tt}),nt=Bn({functions:B,version:tt}),rt=`${JSON.stringify(st,void 0,2)}
|
|
8
|
-
`,it=`${JSON.stringify(nt,void 0,2)}
|
|
9
|
-
`,ot=qn(st),at=Vn(nt),Se=E(n,eu),Ps=b(Se),ye=[];if(!e.dryRun){b(N)||Is(N,{recursive:!0});const f=($,V)=>{Oe(E(N,$),V),ye.push($)},I=($,V)=>{tu(E(N,$),V),V!==""&&ye.push($)};f("app.ts",et),f("dataModel.ts",h),f("api.ts",$e),f("server.ts",z),f("functions.ts",Ue),f("shard.ts",We),f("crons.ts",Xe),f("vectors.ts",Ze),f("drizzle.global.ts",te.global),f("drizzle.shard.ts",te.shard),I("containers.ts",He),I("workflows.ts",Ge),I("agents.ts",Ye),I("queues.ts",Qe),I("scheduler.ts",bs),I("seed.ts",Je),I("collections.ts",je),I("openapi.json",ve?rt:""),I("openapi.ts",ve?ot:""),I("openrpc.json",Ee?it:""),I("openrpc.ts",Ee?at:""),(!Ps||e.updateSchemaBaseline===!0)&&Oe(Se,Os(xe))}if(t){const f=Ae.now(),I=Math.round(f-s),$=Math.round(Ve-s),V=Math.round(f-Ve);console.error(`@lunora/codegen: codegen took ${I.toString()}ms (discovery ${$.toString()}ms, emit ${V.toString()}ms)`)}return{advisories:qe,advisorContext:ee,agents:c,containers:u,cronTriggers:[...new Set([...Hs(d),...P])],generated:{agents:Ye,api:$e,app:et,collections:je,containers:He,crons:Xe,dataModel:h,drizzleGlobal:te.global,drizzleShard:te.shard,functions:Ue,openApi:rt,openApiModule:ot,openRpc:it,openRpcModule:at,queues:Qe,seed:Je,server:z,shard:We,vectors:Ze,workflows:Ge},migrations:Z,outputDirectory:N,platformDiagnostics:y.diagnostics,queues:O,schemaSnapshot:xe,schemaSnapshotPath:Se,workflows:C,writtenFiles:ye}};export{eu as SCHEMA_SNAPSHOT_FILENAME,cu as createCodegenProject,ru as findTsconfig,nd as refreshCodegenProject,rd as runCodegen};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{w as a}from"./classify-procedure-call-BIlyTUBD.mjs";const l=s=>a(s,"use","rls");export{l as r};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as o}from"./context-property-calls-H37QsE0Q.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./listLunoraSourceFiles-D4xthUf-.mjs";import"./classify-procedure-call-BIlyTUBD.mjs";import{d as p}from"./index-C4eKBBMk.mjs";export{p as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as a}from"./queries-CPlxXagL.mjs";import"./listLunoraSourceFiles-D4xthUf-.mjs";export{a as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as r}from"./context-property-calls-H37QsE0Q.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{readdirSync as E,realpathSync as A,lstatSync as P,statSync as b}from"node:fs";import{dirname as v,join as u,relative as O,sep as L,extname as x}from"node:path";import{Node as r,SyntaxKind as m}from"ts-morph";import{diagnosticAt as F}from"./CodegenDiagnosticError-BUXlG3P-.mjs";const R=/\.ts$/u,f=(t,e)=>O(t,e).split(L).join("/").replace(R,""),N=new Set(["_generated","node_modules"]),T=(t,e,s)=>t==="schema.ts"&&e===s,I=t=>{try{return b(t)}catch{console.warn(`@lunora/codegen: skipping ${t} — it is a symlink that does not resolve (or vanished mid-scan).`);return}},S=(t,e,s,n)=>{let i,o;try{i=E(t),o=A(t)}catch{return e}if(n.has(o))return e;n.add(o);for(const a of i){const l=u(t,a),c=I(l);c!==void 0&&(c.isDirectory()?N.has(a)||S(l,e,s,n):c.isFile()&&x(a)===".ts"&&!T(a,t,s)&&e.push(l))}return e},h=t=>S(t,[],t,new Set),D=["src/server","src/index.ts","src/worker.ts"],_=new Set([".ts",".tsx"]),y=(t,e=[])=>{let s;try{s=P(t)}catch{return e}if(s.isFile())return _.has(x(t))&&e.push(t),e;if(!s.isDirectory())return e;for(const n of E(t))n==="_generated"||n==="node_modules"||y(u(t,n),e);return e},C=t=>{const e=v(t),s=h(t).map(i=>({displayPath:f(t,i),filePath:i})),n=new Set(s.map(i=>i.filePath));for(const i of D)for(const o of y(u(e,i)))n.has(o)||(n.add(o),s.push({displayPath:f(e,o),filePath:o}));return s},w=(t,e,s)=>{const n=[];for(const{displayPath:i,filePath:o}of e){const a=t.getSourceFile(o)??t.addSourceFileAtPath(o);for(const l of a.getDescendantsOfKind(m.CallExpression)){const c=s(l,i);c!==void 0&&n.push(c)}}return n},W=(t,e,s)=>w(t,h(e).map(n=>({displayPath:f(e,n),filePath:n})),s),q=(t,e,s)=>w(t,C(e),s),M=t=>{for(const e of t.getAncestors())if(r.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0)return e.getName();return""},X=(t,e)=>{if(e){const o=t.getArguments()[0];return o&&(r.isArrowFunction(o)||r.isFunctionExpression(o))?o:void 0}const s=t.getArguments()[0];if(!s||!r.isObjectLiteralExpression(s))return;const n=s.getProperty("handler");if(!n||!r.isPropertyAssignment(n))return;const i=n.getInitializer();return i&&(r.isArrowFunction(i)||r.isFunctionExpression(i))?i:void 0},Y=(t,e)=>{if(!t||!r.isObjectLiteralExpression(t))return;const s=t.getProperty(e);return s&&r.isPropertyAssignment(s)?s.getInitializer():void 0},p=t=>r.isPropertyAccessExpression(t)&&t.getName()==="db"||r.isIdentifier(t)&&t.getText()==="db",z=new Set(["findFirst","findFirstOrThrow","findMany","findUnique"]),H=t=>{const e=t.getExpression();if(!r.isPropertyAccessExpression(e)||!z.has(e.getName()))return;const s=e.getExpression();if(p(s)){const n=t.getArguments()[0];return{options:t.getArguments()[1],table:n&&r.isStringLiteral(n)?n.getLiteralText():""}}if(r.isPropertyAccessExpression(s)){const n=s.getExpression();if(p(n))return{options:t.getArguments()[0],table:s.getName()}}},g=(t,e)=>{const s=t.getExpression();return!r.isPropertyAccessExpression(s)||!e.has(s.getName())?!1:p(s.getExpression())},d=t=>{const e=t.getArguments()[0];return e&&r.isStringLiteral(e)?e.getLiteralText():""},U=(t,e,s)=>{const n=new Set,i=new Set;for(const o of t.getDescendantsOfKind(m.CallExpression))if(g(o,e)){const a=d(o);a!==""&&n.add(a)}else if(g(o,s)){const a=d(o);a!==""&&i.add(a)}return{tablesRead:[...n],tablesWritten:[...i]}},j=t=>{let e=t;for(;e&&(r.isAsExpression(e)||r.isSatisfiesExpression(e)||r.isParenthesizedExpression(e)||r.isNonNullExpression(e));)e=e.getExpression();return e},G=t=>{const e=j(t);return e&&r.isCallExpression(e)?e:void 0},J=t=>{const e=t.getExportAssignment(i=>!i.isExportEquals());if(!e)return;const s=e.getExpression();if(!r.isIdentifier(s))return s;const n=s.getSymbol()?.getValueDeclaration();return n&&r.isVariableDeclaration(n)?n.getInitializer():s},Q=t=>{const e=t.getArguments()[1];return e&&r.isStringLiteral(e)?e.getLiteralValue():""},Z=(t,e)=>{if(!r.isObjectLiteralExpression(t))return;const s=t.getProperty(e);if(!s||!r.isPropertyAssignment(s))return;const n=s.getInitializer();return n&&r.isStringLiteral(n)?n.getLiteralText():void 0},k=t=>{const e=t.getStatements(),[s]=e;if(e.length!==1||s===void 0||!r.isReturnStatement(s))return;const n=s.getExpression();return n!==void 0&&r.isObjectLiteralExpression(n)?n:void 0},tt=t=>{if(r.isObjectLiteralExpression(t))return t;if(r.isParenthesizedExpression(t)){const e=t.getExpression();return r.isObjectLiteralExpression(e)?e:void 0}return r.isBlock(t)?k(t):void 0},et=t=>r.isIdentifier(t)&&t.getText()==="ctx",st=t=>(e,s,n)=>{if(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw F(e,`${t} "${s}": \`${n}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)};export{R as TS_EXTENSION_RE,W as collectCallRows,q as collectSecurityCallRows,J as defaultExportExpression,M as enclosingExportName,X as handlerOf,et as isContextIdentifier,p as isDatabaseAccessor,Q as limitNameOf,h as listLunoraSourceFiles,C as listSecurityScanFiles,f as lunoraRelativePath,tt as objectLiteralFromCallbackBody,Y as propertyInitializer,H as readTargetOf,st as stringPropertyFor,Z as stringPropertyOf,d as tableArgumentOf,U as tablesAccessedIn,j as unwrapExpression,G as unwrapToCallExpression};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Node as r,SyntaxKind as f}from"ts-morph";import{listLunoraSourceFiles as P,lunoraRelativePath as h,isDatabaseAccessor as A}from"./listLunoraSourceFiles-D4xthUf-.mjs";const m=(t,e)=>{if(t.getText()!==e)return!1;const s=t.getParent();return r.isPropertyAccessExpression(s)&&s.getNameNode()===t?!1:!(r.isPropertyAssignment(s)&&s.getNameNode()===t)},x=(t,e)=>r.isIdentifier(t)?m(t,e):t.getDescendantsOfKind(f.Identifier).some(s=>m(s,e)),g=t=>x(t,"ctx"),I=t=>{let e=t;for(;r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e)||r.isNonNullExpression(e);)e=e.getExpression();return r.isIdentifier(e)?e:void 0},E=t=>x(t,"args"),u=t=>{if(!r.isIdentifier(t))return;const e=t.getText(),s=t.getFirstAncestor(o=>r.isArrowFunction(o)||r.isFunctionExpression(o)||r.isFunctionDeclaration(o));if(s===void 0)return;const i=t.getStart();let n,a=-1;for(const o of s.getDescendantsOfKind(f.VariableDeclaration)){if(o.getName()!==e)continue;const c=o.getInitializer(),l=o.getStart();c!==void 0&&l<i&&l>a&&(n=c,a=l)}return n},C=t=>{if(E(t))return!0;const e=u(t);return e!==void 0&&E(e)},K=t=>{if(r.isCallExpression(t)||r.isNewExpression(t))return!1;const e=u(t);return e===void 0||!(r.isCallExpression(e)||r.isNewExpression(e))},O=t=>{if(g(t))return!0;const e=u(t);if(e!==void 0&&g(e))return!0;const s=e??t;return(r.isIdentifier(s)?[s]:s.getDescendantsOfKind(f.Identifier)).some(n=>{const a=u(n);return a!==void 0&&g(a)})},p=(t,e)=>x(t,e),T=(t,e)=>{if(p(t,e))return!0;const s=u(t);if(s!==void 0&&p(s,e))return!0;const i=I(t);if(i!==void 0){const n=u(i);return n!==void 0&&p(n,e)}return!1},v=t=>{for(const e of t.getAncestors())if(r.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0)return e.getName();return"<module>"},N=new Set(["withGeoIndex","withIndex","withSearchIndex"]),S=new Set(["collect","collectWithScores","first","paginate","take","unique"]),b=t=>{const e=t.getExpression();if(!r.isPropertyAccessExpression(e)||e.getName()!=="query")return!1;const s=e.getExpression();return A(s)},y=t=>{const e=[];let s=t;for(;;){const i=s.getParent();if(!i||!r.isPropertyAccessExpression(i))break;const n=i.getParent();if(!n||!r.isCallExpression(n))break;e.push(i.getName()),s=n}return e},D=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,w=t=>{let e=t;for(;;){const s=e.getParent();if(!s||!r.isPropertyAccessExpression(s))return!1;const i=s.getParent();if(!i||!r.isCallExpression(i))return!1;if(s.getName()==="filter"){const n=i.getArguments()[0];if(n&&D.test(n.getText()))return!0}e=i}},R=t=>{const e=t.getArguments()[0];return e&&r.isStringLiteral(e)?e.getLiteralText():""},_=(t,e)=>{const s=[];for(const i of P(e)){const n=t.getSourceFile(i)??t.addSourceFileAtPath(i),a=h(e,i);for(const o of n.getDescendantsOfKind(f.CallExpression)){if(!b(o))continue;const c=y(o),l=c.includes("filter");s.push({exportName:v(o),file:a,filtersPrimaryKey:l&&w(o),hasFilter:l,hasIndex:c.some(d=>N.has(d)),line:o.getStartLineNumber(),table:R(o),terminal:c.findLast(d=>S.has(d))})}}return s};export{O as a,K as b,T as c,_ as d,v as e,p as f,C as i,E as r,u as s};
|