@lunora/codegen 1.0.0-alpha.162 → 1.0.0-alpha.164

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.
Files changed (38) hide show
  1. package/dist/index.mjs +1 -1
  2. package/dist/packem_shared/{AGENTS_FILENAME-CRdh_pOr.mjs → AGENTS_FILENAME-DHk9gO3E.mjs} +1 -1
  3. package/dist/packem_shared/{CONTAINERS_FILENAME-BssQL6eI.mjs → CONTAINERS_FILENAME-CqSjcb1-.mjs} +1 -1
  4. package/dist/packem_shared/{FLAGS_FILENAME-Bn_wWM4d.mjs → FLAGS_FILENAME-Uzu2mD86.mjs} +1 -1
  5. package/dist/packem_shared/{NOTIFY_FILENAME-BH0djo6F.mjs → NOTIFY_FILENAME-a3lg_dJ9.mjs} +1 -1
  6. package/dist/packem_shared/{QUEUES_FILENAME-CIfuMMG3.mjs → QUEUES_FILENAME-BZ6Ak3QY.mjs} +1 -1
  7. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-C9nFNiHX.mjs +9 -0
  8. package/dist/packem_shared/{WORKFLOWS_FILENAME-CSqONfHS.mjs → WORKFLOWS_FILENAME-CXgbWxbT.mjs} +1 -1
  9. package/dist/packem_shared/chain-B1V7k_Eb.mjs +1 -0
  10. package/dist/packem_shared/{classify-procedure-call-CRm5Etni.mjs → classify-procedure-call-C5BOBVM7.mjs} +1 -1
  11. package/dist/packem_shared/{context-property-calls-CBUh7oAY.mjs → context-property-calls-C34F31Vm.mjs} +1 -1
  12. package/dist/packem_shared/{discoverAuthApiCalls-B5Qmjmyk.mjs → discoverAuthApiCalls-mYYZYULR.mjs} +1 -1
  13. package/dist/packem_shared/{discoverCrons-c0ig327z.mjs → discoverCrons-C-GrcmEj.mjs} +1 -1
  14. package/dist/packem_shared/{discoverFunctions-DeuEs6Ce.mjs → discoverFunctions-BJQ_rvqv.mjs} +1 -1
  15. package/dist/packem_shared/{discoverHttpRoutes-zWSSyyOj.mjs → discoverHttpRoutes-Bsu4ctdh.mjs} +1 -1
  16. package/dist/packem_shared/discoverHyperdriveCalls-jqn--Zkc.mjs +1 -0
  17. package/dist/packem_shared/{discoverInserts-BB7o_8pU.mjs → discoverInserts-Bbw_Fkid.mjs} +1 -1
  18. package/dist/packem_shared/discoverMaskProcedures-DM53VCwn.mjs +1 -0
  19. package/dist/packem_shared/{discoverMigrations-CQjGLKW-.mjs → discoverMigrations-ChOwLUzQ.mjs} +1 -1
  20. package/dist/packem_shared/{discoverNondeterministicCalls-B07wjsd2.mjs → discoverNondeterministicCalls-Cesk1Srg.mjs} +1 -1
  21. package/dist/packem_shared/discoverQueries-lcXgO27p.mjs +1 -0
  22. package/dist/packem_shared/discoverR2sqlCalls-DW4RO223.mjs +1 -0
  23. package/dist/packem_shared/{discoverRlsMetadata-CXWVNLk4.mjs → discoverRlsMetadata-pjWjG15I.mjs} +1 -1
  24. package/dist/packem_shared/{discoverRlsProcedures-DXdr9YHi.mjs → discoverRlsProcedures-iPEyaH0Q.mjs} +1 -1
  25. package/dist/packem_shared/{discoverSandboxUsage-BJHLHZR_.mjs → discoverSandboxUsage-zLtQHdkg.mjs} +1 -1
  26. package/dist/packem_shared/{discoverStorageRulesMetadata-CUa2Dtb4.mjs → discoverStorageRulesMetadata-B1gekVBr.mjs} +1 -1
  27. package/dist/packem_shared/{exported-procedure-chains-Cmt3Pr92.mjs → exported-procedure-chains-CH_Ce-wL.mjs} +1 -1
  28. package/dist/packem_shared/{index-BsVoa-4F.mjs → index-D322boXY.mjs} +1 -1
  29. package/dist/packem_shared/listLunoraSourceFiles-lHrzFhbX.mjs +1 -0
  30. package/dist/packem_shared/{queries-D8DheHbi.mjs → queries-C3PDsG0y.mjs} +1 -1
  31. package/package.json +3 -3
  32. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-B9S14dpw.mjs +0 -9
  33. package/dist/packem_shared/chain-DboeOxBl.mjs +0 -1
  34. package/dist/packem_shared/discoverHyperdriveCalls-C6kV2CPz.mjs +0 -1
  35. package/dist/packem_shared/discoverMaskProcedures-CNqwOwXv.mjs +0 -1
  36. package/dist/packem_shared/discoverQueries-Dz2vDpE9.mjs +0 -1
  37. package/dist/packem_shared/discoverR2sqlCalls-CuHe5smg.mjs +0 -1
  38. package/dist/packem_shared/listLunoraSourceFiles-BvqYMy81.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-CWESEYLi.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as 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-CRdh_pOr.mjs";import{listLunoraSourceFiles as g}from"./packem_shared/listLunoraSourceFiles-BvqYMy81.mjs";import{default as R}from"./packem_shared/discoverAuthApiCalls-B5Qmjmyk.mjs";import{CONTAINERS_FILENAME as M,discoverContainers as h}from"./packem_shared/CONTAINERS_FILENAME-BssQL6eI.mjs";import{default as L}from"./packem_shared/discoverCrons-c0ig327z.mjs";import{FLAGS_FILENAME as I,discoverFlags as F}from"./packem_shared/FLAGS_FILENAME-Bn_wWM4d.mjs";import{default as P}from"./packem_shared/discoverFunctions-DeuEs6Ce.mjs";import{default as G}from"./packem_shared/discoverHttpRoutes-zWSSyyOj.mjs";import{default as b}from"./packem_shared/discoverHyperdriveCalls-C6kV2CPz.mjs";import{default as y}from"./packem_shared/discoverInserts-BB7o_8pU.mjs";import{d as j}from"./packem_shared/index-BsVoa-4F.mjs";import{default as V}from"./packem_shared/discoverMigrations-CQjGLKW-.mjs";import{MUTATORS_FILENAME as Q,discoverMutators as w}from"./packem_shared/MUTATORS_FILENAME-DHX1qUP5.mjs";import{default as B}from"./packem_shared/discoverNondeterministicCalls-B07wjsd2.mjs";import{NOTIFY_FILENAME as Y,discoverNotifyCalls as X,discoverNotifyConfig as Z}from"./packem_shared/NOTIFY_FILENAME-BH0djo6F.mjs";import{default as ee}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as oe}from"./packem_shared/queries-D8DheHbi.mjs";import{QUEUES_FILENAME as se,discoverQueues as ae}from"./packem_shared/QUEUES_FILENAME-CIfuMMG3.mjs";import{default as me}from"./packem_shared/discoverR2sqlCalls-CuHe5smg.mjs";import{default as fe}from"./packem_shared/discoverRlsProcedures-DXdr9YHi.mjs";import{default as ce}from"./packem_shared/discoverRlsMetadata-CXWVNLk4.mjs";import{discoverSandboxUsage as le}from"./packem_shared/discoverSandboxUsage-BJHLHZR_.mjs";import{default as xe}from"./packem_shared/discoverSchema-C4znXEB-.mjs";import{SHAPES_FILENAME as Ae,discoverShapes as ue}from"./packem_shared/SHAPES_FILENAME-DhZ3JkkH.mjs";import{default as Ne}from"./packem_shared/discoverStorageRulesMetadata-CUa2Dtb4.mjs";import{WORKFLOWS_FILENAME as Oe,discoverWorkflows as Re}from"./packem_shared/WORKFLOWS_FILENAME-CSqONfHS.mjs";import{G as Me,e as he,a as _e,b as Le,c as Te,d as Ie,f as Fe,g as De,h as Pe,i as Ue,j as Ge,k as He,l as be,m as ke}from"./packem_shared/emit-BNdsZPcd.mjs";import{emitApp as We}from"./packem_shared/emitApp-CxmA4W3C.mjs";import{buildOpenApiDocument as Ke,emitOpenApi as Ve,emitOpenApiModule as ze}from"./packem_shared/buildOpenApiDocument-qYjkmRTX.mjs";import{OPENRPC_VERSION as we,buildOpenRpcDocument as qe,emitOpenRpc as Be,emitOpenRpcModule as Je}from"./packem_shared/OPENRPC_VERSION-BgLkvCYK.mjs";import{DEFAULT_TARGET as Xe,platformMatrixIds as Ze,readProjectTarget as $e,resolveCodegenTarget as er}from"./packem_shared/DEFAULT_TARGET-lPq34YeN.mjs";import{SCHEMA_SNAPSHOT_FILENAME as or,createCodegenProject as tr,findTsconfig as sr,refreshCodegenProject as ar,runCodegen as ir}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-B9S14dpw.mjs";import{SchemaSnapshotParseError as dr,buildSchemaSnapshot as fr,evaluateSchemaDrift as pr,parseSchemaSnapshot as cr}from"./packem_shared/SchemaSnapshotParseError-yrVM8bTa.mjs";import{schemaFromIr as lr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as xr,validatorIrToJsonSchema as Er}from"./packem_shared/LUNORA_ERROR_CODES-CW7-uASH.mjs";import{SDK_LANGUAGES as ur,SDK_TARGETS as vr,generateSdk as Nr}from"./packem_shared/SDK_LANGUAGES-CFyux-74.mjs";import{redact as Or,secretKindOf as Rr}from"./packem_shared/redact-Cy14LEnc.mjs";import{MESSAGE_SOLUTIONS as Mr,findSolutionByMessage as hr}from"@lunora/errors";import{isTypedSchema as Lr}from"./packem_shared/isTypedSchema-B_qlBbE-.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,M as CONTAINERS_FILENAME,x as CodegenDiagnosticError,Xe as DEFAULT_TARGET,I as FLAGS_FILENAME,Me as GENERATED_HEADER,xr as LUNORA_ERROR_CODES,Mr as LUNORA_SOLUTION_RULES,Q as MUTATORS_FILENAME,Y as NOTIFY_FILENAME,we as OPENRPC_VERSION,se as QUEUES_FILENAME,or as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,ur as SDK_LANGUAGES,vr as SDK_TARGETS,Ae as SHAPES_FILENAME,dr as SchemaSnapshotParseError,e as VERSION,Oe as WORKFLOWS_FILENAME,Ke as buildOpenApiDocument,qe as buildOpenRpcDocument,fr as buildSchemaSnapshot,tr as createCodegenProject,c as describeErrorLevelFindings,E as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,R as discoverAuthApiCalls,h as discoverContainers,L as discoverCrons,F as discoverFlags,P as discoverFunctions,G as discoverHttpRoutes,b as discoverHyperdriveCalls,y as discoverInserts,j as discoverMaskProcedures,V as discoverMigrations,w as discoverMutators,B 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,Re as discoverWorkflows,he as emitAgents,_e as emitApi,We as emitApp,Le as emitCollections,Te as emitContainers,Ie as emitCrons,Fe as emitDataModel,De as emitDrizzleSchema,Pe as emitFunctions,Ve as emitOpenApi,ze as emitOpenApiModule,Be as emitOpenRpc,Je as emitOpenRpcModule,Ue as emitServer,Ge as emitShard,He as emitVectors,be as emitWorkflows,ke as emitWranglerCronTriggers,n as errorAdvisoryNames,l as errorPlatformDiagnosticNames,pr as evaluateSchemaDrift,hr as findLunoraSolution,sr as findTsconfig,m as formatAdvisories,Nr as generateSdk,Lr as isTypedSchema,d as lintSchema,g as listLunoraSourceFiles,cr as parseSchemaSnapshot,Ze as platformMatrixIds,ee as readPackageDependencies,$e as readProjectTarget,Or as redact,ar as refreshCodegenProject,er as resolveCodegenTarget,ir as runCodegen,lr as schemaFromIr,Rr as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,Er as validatorIrToJsonSchema};
1
+ import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CWESEYLi.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as 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-DHk9gO3E.mjs";import{listLunoraSourceFiles as g}from"./packem_shared/listLunoraSourceFiles-lHrzFhbX.mjs";import{default as R}from"./packem_shared/discoverAuthApiCalls-mYYZYULR.mjs";import{CONTAINERS_FILENAME as M,discoverContainers as h}from"./packem_shared/CONTAINERS_FILENAME-CqSjcb1-.mjs";import{default as L}from"./packem_shared/discoverCrons-C-GrcmEj.mjs";import{FLAGS_FILENAME as I,discoverFlags as F}from"./packem_shared/FLAGS_FILENAME-Uzu2mD86.mjs";import{default as P}from"./packem_shared/discoverFunctions-BJQ_rvqv.mjs";import{default as G}from"./packem_shared/discoverHttpRoutes-Bsu4ctdh.mjs";import{default as b}from"./packem_shared/discoverHyperdriveCalls-jqn--Zkc.mjs";import{default as y}from"./packem_shared/discoverInserts-Bbw_Fkid.mjs";import{d as j}from"./packem_shared/index-D322boXY.mjs";import{default as V}from"./packem_shared/discoverMigrations-ChOwLUzQ.mjs";import{MUTATORS_FILENAME as Q,discoverMutators as w}from"./packem_shared/MUTATORS_FILENAME-DHX1qUP5.mjs";import{default as B}from"./packem_shared/discoverNondeterministicCalls-Cesk1Srg.mjs";import{NOTIFY_FILENAME as Y,discoverNotifyCalls as X,discoverNotifyConfig as Z}from"./packem_shared/NOTIFY_FILENAME-a3lg_dJ9.mjs";import{default as ee}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as oe}from"./packem_shared/queries-C3PDsG0y.mjs";import{QUEUES_FILENAME as se,discoverQueues as ae}from"./packem_shared/QUEUES_FILENAME-BZ6Ak3QY.mjs";import{default as me}from"./packem_shared/discoverR2sqlCalls-DW4RO223.mjs";import{default as fe}from"./packem_shared/discoverRlsProcedures-iPEyaH0Q.mjs";import{default as ce}from"./packem_shared/discoverRlsMetadata-pjWjG15I.mjs";import{discoverSandboxUsage as le}from"./packem_shared/discoverSandboxUsage-zLtQHdkg.mjs";import{default as xe}from"./packem_shared/discoverSchema-C4znXEB-.mjs";import{SHAPES_FILENAME as Ae,discoverShapes as ue}from"./packem_shared/SHAPES_FILENAME-DhZ3JkkH.mjs";import{default as Ne}from"./packem_shared/discoverStorageRulesMetadata-B1gekVBr.mjs";import{WORKFLOWS_FILENAME as Oe,discoverWorkflows as Re}from"./packem_shared/WORKFLOWS_FILENAME-CXgbWxbT.mjs";import{G as Me,e as he,a as _e,b as Le,c as Te,d as Ie,f as Fe,g as De,h as Pe,i as Ue,j as Ge,k as He,l as be,m as ke}from"./packem_shared/emit-BNdsZPcd.mjs";import{emitApp as We}from"./packem_shared/emitApp-CxmA4W3C.mjs";import{buildOpenApiDocument as Ke,emitOpenApi as Ve,emitOpenApiModule as ze}from"./packem_shared/buildOpenApiDocument-qYjkmRTX.mjs";import{OPENRPC_VERSION as we,buildOpenRpcDocument as qe,emitOpenRpc as Be,emitOpenRpcModule as Je}from"./packem_shared/OPENRPC_VERSION-BgLkvCYK.mjs";import{DEFAULT_TARGET as Xe,platformMatrixIds as Ze,readProjectTarget as $e,resolveCodegenTarget as er}from"./packem_shared/DEFAULT_TARGET-lPq34YeN.mjs";import{SCHEMA_SNAPSHOT_FILENAME as or,createCodegenProject as tr,findTsconfig as sr,refreshCodegenProject as ar,runCodegen as ir}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-C9nFNiHX.mjs";import{SchemaSnapshotParseError as dr,buildSchemaSnapshot as fr,evaluateSchemaDrift as pr,parseSchemaSnapshot as cr}from"./packem_shared/SchemaSnapshotParseError-yrVM8bTa.mjs";import{schemaFromIr as lr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as xr,validatorIrToJsonSchema as Er}from"./packem_shared/LUNORA_ERROR_CODES-CW7-uASH.mjs";import{SDK_LANGUAGES as ur,SDK_TARGETS as vr,generateSdk as Nr}from"./packem_shared/SDK_LANGUAGES-CFyux-74.mjs";import{redact as Or,secretKindOf as Rr}from"./packem_shared/redact-Cy14LEnc.mjs";import{MESSAGE_SOLUTIONS as Mr,findSolutionByMessage as hr}from"@lunora/errors";import{isTypedSchema as Lr}from"./packem_shared/isTypedSchema-B_qlBbE-.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,M as CONTAINERS_FILENAME,x as CodegenDiagnosticError,Xe as DEFAULT_TARGET,I as FLAGS_FILENAME,Me as GENERATED_HEADER,xr as LUNORA_ERROR_CODES,Mr as LUNORA_SOLUTION_RULES,Q as MUTATORS_FILENAME,Y as NOTIFY_FILENAME,we as OPENRPC_VERSION,se as QUEUES_FILENAME,or as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,ur as SDK_LANGUAGES,vr as SDK_TARGETS,Ae as SHAPES_FILENAME,dr as SchemaSnapshotParseError,e as VERSION,Oe as WORKFLOWS_FILENAME,Ke as buildOpenApiDocument,qe as buildOpenRpcDocument,fr as buildSchemaSnapshot,tr as createCodegenProject,c as describeErrorLevelFindings,E as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,R as discoverAuthApiCalls,h as discoverContainers,L as discoverCrons,F as discoverFlags,P as discoverFunctions,G as discoverHttpRoutes,b as discoverHyperdriveCalls,y as discoverInserts,j as discoverMaskProcedures,V as discoverMigrations,w as discoverMutators,B 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,Re as discoverWorkflows,he as emitAgents,_e as emitApi,We as emitApp,Le as emitCollections,Te as emitContainers,Ie as emitCrons,Fe as emitDataModel,De as emitDrizzleSchema,Pe as emitFunctions,Ve as emitOpenApi,ze as emitOpenApiModule,Be as emitOpenRpc,Je as emitOpenRpcModule,Ue as emitServer,Ge as emitShard,He as emitVectors,be as emitWorkflows,ke as emitWranglerCronTriggers,n as errorAdvisoryNames,l as errorPlatformDiagnosticNames,pr as evaluateSchemaDrift,hr as findLunoraSolution,sr as findTsconfig,m as formatAdvisories,Nr as generateSdk,Lr as isTypedSchema,d as lintSchema,g as listLunoraSourceFiles,cr as parseSchemaSnapshot,Ze as platformMatrixIds,ee as readPackageDependencies,$e as readProjectTarget,Or as redact,ar as refreshCodegenProject,er as resolveCodegenTarget,ir as runCodegen,lr as schemaFromIr,Rr as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,Er 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-BvqYMy81.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};
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-lHrzFhbX.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};
@@ -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-BvqYMy81.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
+ 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-lHrzFhbX.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-BvqYMy81.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
+ 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-lHrzFhbX.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-BvqYMy81.mjs";import{c as S}from"./classify-procedure-call-CRm5Etni.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
+ 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-lHrzFhbX.mjs";import{c as S}from"./classify-procedure-call-C5BOBVM7.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-BvqYMy81.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};
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-lHrzFhbX.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 gs,readFileSync as Ct,writeFileSync as ps,rmSync as ms}from"node:fs";import{join as f,dirname as J}from"node:path";import{performance as he}from"node:perf_hooks";import{runAdvisor as hs}from"@lunora/advisor";import{LunoraError as D}from"@lunora/errors";import{SyntaxKind as l,Node as i,Project as st}from"ts-morph";import{serializeSchemaSnapshot as xs}from"./SCHEMA_SNAPSHOT_VERSION-CWESEYLi.mjs";import{toAdvisorContext as Es}from"./formatAdvisories-CkEu1eye.mjs";import{s as vs}from"./paths-C-9fwEgQ.mjs";import{discoverAgents as Ss}from"./AGENTS_FILENAME-DHk9gO3E.mjs";import{discoverContainers as ys}from"./CONTAINERS_FILENAME-CqSjcb1-.mjs";import As from"./discoverCrons-C-GrcmEj.mjs";import{diagnosticAt as ie}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as ae}from"./module-specifiers-WF8iAydP.mjs";import{C as xe,n as Ft,i as Ns,f as bs,j as Ps,b as Is,c as ws,l as Ts,e as Cs,o as Fs,d as Os,k as Rs,g as Ls,p as Ds,m as ks,a as Ms,h as Ks}from"./emit-BNdsZPcd.mjs";import{listLunoraSourceFiles as m,unwrapExpression as W,listSecurityScanFiles as Ie,objectLiteralFromCallbackBody as Ot,propertyInitializer as A,lunoraRelativePath as v,collectCallRows as I,collectSecurityCallRows as _s,limitNameOf as Rt,isContextIdentifier as ye,handlerOf as zs,isDatabaseAccessor as k,readTargetOf as Lt,enclosingExportName as Us}from"./listLunoraSourceFiles-lHrzFhbX.mjs";import Bs from"./readPackageDependencies-C6h6FZuP.mjs";import{discoverQueues as $s}from"./QUEUES_FILENAME-BZ6Ak3QY.mjs";import{discoverSandboxUsage as qs}from"./discoverSandboxUsage-zLtQHdkg.mjs";import Vs from"./discoverStorageRulesMetadata-B1gekVBr.mjs";import{a as S,c as z,d as Dt,e as js}from"./classify-procedure-call-C5BOBVM7.mjs";import{discoverWorkflows as Ws}from"./WORKFLOWS_FILENAME-CXgbWxbT.mjs";import{gatePlatformFeatures as Hs,resolveCodegenTarget as Gs}from"./DEFAULT_TARGET-lPq34YeN.mjs";import{i as R,a as _,e as E,r as Ys,b as Xs,s as ce,c as Qs,f as Zs,d as Js}from"./queries-C3PDsG0y.mjs";import en from"./discoverAuthApiCalls-mYYZYULR.mjs";import nt from"./discoverFunctions-BJQ_rvqv.mjs";import{i as tn,r as sn,e as nn}from"./unwrap-handler-return-CmIWbykC.mjs";import rt from"./discoverHttpRoutes-Bsu4ctdh.mjs";import rn from"./discoverHyperdriveCalls-jqn--Zkc.mjs";import on from"./discoverInserts-Bbw_Fkid.mjs";import{m as we,a as te,s as kt,d as an}from"./index-D322boXY.mjs";import{e as Mt}from"./exported-procedure-chains-CH_Ce-wL.mjs";import cn from"./discoverMigrations-ChOwLUzQ.mjs";import{MUTATORS_FILENAME as ln,isDefineMutatorCallee as un,discoverMutators as ot}from"./MUTATORS_FILENAME-DHX1qUP5.mjs";import dn from"./discoverNondeterministicCalls-Cesk1Srg.mjs";import{discoverNotifyConfig as fn,discoverNotifyCalls as gn}from"./NOTIFY_FILENAME-a3lg_dJ9.mjs";import pn from"./discoverR2sqlCalls-DW4RO223.mjs";import mn from"./discoverRlsProcedures-iPEyaH0Q.mjs";import hn from"./discoverRlsMetadata-pjWjG15I.mjs";import xn from"./discoverSchema-C4znXEB-.mjs";import{secretKindOf as En,redact as vn,isHeuristicSecretKind as Sn,isSecretishName as yn}from"./redact-Cy14LEnc.mjs";import{discoverShapes as An}from"./SHAPES_FILENAME-DhZ3JkkH.mjs";import{emitApp as Nn}from"./emitApp-CxmA4W3C.mjs";import{buildOpenApiDocument as bn,emitOpenApiModule as Pn}from"./buildOpenApiDocument-qYjkmRTX.mjs";import{buildOpenRpcDocument as In,emitOpenRpcModule as wn}from"./OPENRPC_VERSION-BgLkvCYK.mjs";import{s as Tn}from"./parse-validator-CMV0eq2a.mjs";import{buildSchemaSnapshot as Cn}from"./SchemaSnapshotParseError-yrVM8bTa.mjs";const it=(e,t="api")=>{const s=new Map;for(const n of e){const o=vs(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 D("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})}}},Fn=(e,t={})=>{const{hasVectors:s=!0,scheduler:n=!1,storage:o=!1}=t,r=[],a=e.tables.filter(c=>c.shardMode==="global");return a.some(c=>c.globalBackend!=="hyperdrive")&&r.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),a.some(c=>c.globalBackend==="hyperdrive")&&r.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&&r.push({name:"@lunora/scheduler",reason:"a declared cron (or `ctx.scheduler` use) makes `_generated/app.ts` import `createScheduler`"}),o&&r.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&&r.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/shard.ts` import `@lunora/bindings/vectors`"}),r},On=(e,t,s={})=>{if(t===void 0)return;const n=Fn(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 D("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.`)},Rn="env.ts",Ln=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return ae(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},Dn=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&&ae(n.getModuleSpecifierValue())}return!1},kn=e=>{if(i.isIdentifier(e))return Ln(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&Dn(t)}return!1},Mn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!kn(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw ie(r,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},Kn=(e,t)=>{const s=f(t,Rn);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=Mn(n);if(o.length!==0){if(o.length>1)throw ie(n,`lunora/env.ts declares ${o.length.toString()} defineEnv() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},at="ctx",Kt=e=>{const t=new Set,s=new Set([at]),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())!==at)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},_n=(e,t)=>{const s=Object.fromEntries(xe.map(n=>[n.key,!1]));for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=new Set(o.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=Kt(o);for(const c of xe)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(xe.every(c=>s[c.key]))break}return s},_t="identity.ts",zn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return ae(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Un=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&&ae(n.getModuleSpecifierValue())}return!1},Bn=e=>{if(i.isIdentifier(e))return zn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&Un(t)}return!1},$n=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!Bn(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw ie(r,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},qn=(e,t)=>{const s=f(t,_t);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=$n(n);if(o.length!==0){if(o.length>1)throw ie(n,`lunora/identity.ts declares ${o.length.toString()} defineIdentity() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},Vn=(e,t)=>{const s=W(t);if(s===void 0||!i.isIdentifier(s))return s;const n=s.getText();return W(e.getDescendantsOfKind(l.VariableDeclaration).find(o=>o.getName()===n)?.getInitializer())},jn=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||W(s)?.getText()!=="false"}),Wn=(e,t)=>{const s={durableStreams:!1,secrets:!1};for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);if(s.secrets||(s.secrets=Kt(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=>jn(Vn(o,u)))})),s.durableStreams&&s.secrets)break}return s},Hn="createWorker",Gn="extend",ct=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralValue():void 0,lt=e=>{const t=[],s=ct(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=ct(o.getNameNode());r!==void 0&&t.push(r)}return t},Yn=e=>{const t=S(e.getExpression()),[s]=e.getArguments();if(s===void 0)return[];if(t===Hn)return i.isObjectLiteralExpression(s)?lt(s):[];if(t!==Gn||!(i.isArrowFunction(s)||i.isFunctionExpression(s)))return[];const n=Ot(s.getBody());return n===void 0?[]:lt(n)},Xn=(e,t)=>{const s=[];for(const{filePath:n}of Ie(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getDescendantsOfKind(l.CallExpression))s.push(...Yn(r))}return[...new Set(s)]},Qn=(e,t)=>{const s=new Map,n=new Map,o=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.bindingName,`workflow "${r.exportName}"`),o.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const a=s.get(r.name);if(a!==void 0)throw new D("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${a} and agent "${r.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=n.get(r.bindingName);if(c!==void 0)throw new D("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${r.bindingName}": produced by both ${c} and agent "${r.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const u=o.get(r.className);if(u!==void 0)throw new D("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${u} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},Zn=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:o}=e,r=qn(s,t),a=Kn(s,t),c=Ws(s,t),u=$s(s,t),d=Ss(s,t);Qn(c,d);const y=ys(s,t),x=Vs(s,t),P=As(s,t,c,d),M=Xn(s,t),g=Wn(s,t),T=qs(s,t),C=_n(s,t);C.browser=C.browser||T.usesSandboxBrowser;const $=Hs(C,Gs(n,e.target),{agents:d.length>0,commitOrderedTables:o.tables.some(p=>p.commitOrdered===!0),cronTriggers:P.length>0,crossShardFanout:o.tables.some(p=>typeof p.shardMode=="object"),durableStreams:g.durableStreams,globalTables:o.tables.some(p=>p.shardMode==="global"),queues:u.length>0,secrets:g.secrets,vectorStore:o.vectorIndexes.length>0}),N=$.usage,L=$.signals.vectorStore!==!1,U=Bs(n),q=U??new Set,G=q.has("lunorash");On(o,U,{hasVectors:L,scheduler:N.scheduler||P.length>0,storage:N.storage||x.rules.length>0||Object.keys(Ft(o)).length>0});const K=b(f(t,"flags.ts")),F=b(f(t,"notify.ts"));return{agents:d,containers:y,crons:P,dataModelContent:bs(o),declaredDependencies:U,dependencies:q,entryCronTriggers:M,env:a,featureUsage:N,hasFlags:K,hasNotify:F,identity:r,platformGate:$,queues:u,serverContent:Ns({agents:d,containers:y,env:a,hasAccessFacade:N.access,hasAi:N.ai,hasAnalytics:N.analytics,hasBrowser:N.browser,hasVectors:L,hasFlags:K,hasHyperdrive:N.hyperdrive,hasImages:N.images,hasKv:N.kv,hasNotify:F,hasPayments:N.payments,hasPipelines:N.pipelines,hasR2sql:N.r2sql,hasX402:N.x402,identity:r,queues:u,schema:o,storageRuleBuckets:x.rules.map(p=>p.bucket),useUmbrella:G,workflows:c}),storageRulesMetadata:x,usesSandbox:T.usesSandboxBrowser||T.usesSandboxContainer||T.usesSandboxFs,useUmbrella:G,workflows:c}},zt=new Set(["delete","get","head","options","patch","post","put"]),Jn=new Set(["handler","stream"]),er=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,ut=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),tr=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()}},sr=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 tr(s)},nr=e=>{for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression))if(ut.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&ut.has(s.getText()))return!0}return!1},rr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||!Jn.has(n.getName()))return;const o=sr(s);if(!o||!er.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}},or=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=rr(o,t);r&&s.push(r)}return s},ir=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...or(o,v(t,n)))}return s},ar=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",cr=(e,t)=>{if(!ar(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!R(s)||_(s)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},lr=(e,t)=>I(e,t,cr),ur=new Set(["generateText","streamText"]),dr=new Set(["messages","prompt","system"]),fr=[{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"]}],gr=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const o of fr)if(o.methods.has(s)&&o.prefixes.some(r=>n===r||n.startsWith(`${r}.`)))return`${n}.${s}`},pr=e=>{for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=gr(t);if(s!==void 0)return s}},mr=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},hr=e=>{if(Ys(e))return!0;const t=mr(e);return t.size===0?!1:e.getDescendantsOfKind(l.Identifier).some(s=>t.has(s.getText()))},xr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!dr.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&hr(s))return!0}return!1},Er=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=S(n.getExpression());if(o===void 0||!ur.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=pr(c),a!==void 0))break;a!==void 0&&s.push({exportName:E(n),file:t,line:n.getStartLineNumber(),method:o,sideEffect:a,userInputDerived:xr(r)})}return s},vr=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Er(o,v(t,n)))}return s},Sr=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},yr=(e,t)=>{if(!Sr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!R(s)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},Ar=(e,t)=>I(e,t,yr),Ut=e=>e.getProperties().some(t=>i.isSpreadAssignment(t)),Nr=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer();return!n||!i.isObjectLiteralExpression(n)?{objects:[],opaque:!0}:{objects:[n],opaque:Ut(n)}},br=e=>{const t=[];let s=!1,n=e;for(;i.isCallExpression(n);){const o=n.getExpression();if(!i.isPropertyAccessExpression(o))break;if(o.getName()==="input"){const r=n.getArguments()[0];r&&i.isObjectLiteralExpression(r)?(t.push(r),s||=Ut(r)):s=!0}n=o.getExpression()}return{objects:t,opaque:s}},Bt=(e,t)=>t?br(t):Nr(e),Pr=e=>e.flatMap(t=>t.getProperties().filter(s=>i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)).map(s=>s.getName())),Ir=new Set(["check","length","max"]),Ae=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!(!i.isPropertyAccessExpression(t)||t.getExpression().getText()!=="v"))return t.getName()},wr=e=>[e,...e.getDescendants()].filter(t=>Ae(t)!==void 0),Tr=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(Ir.has(s.getName()))return!0;t=n}},Cr=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=wr(r),c=o.getName();a.some(u=>Ae(u)==="any")?t.push(c):a.some(u=>Ae(u)==="string"&&!Tr(u))&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Fr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=z(s);if(n?.visibility!=="public")return;const{objects:o}=Bt(s,n.receiver),{anyArgs:r,unboundedStringArgs:a}=Cr(o);if(!(r.length===0&&a.length===0))return{anyArgs:r,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Or=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=Fr(o,t);r&&s.push(r)}return s},Rr=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Or(o,v(t,n)))}return s},Ee=e=>e?.getKind()===l.TrueKeyword,Lr=e=>e?.getKind()===l.FalseKeyword,Dr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,kr=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Mr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&S(t.getExpression())==="scim"),Kr=e=>e!==void 0&&i.isCallExpression(e)&&kr.has(S(e.getExpression())??""),_r=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),zr=e=>{const t=A(e,"advanced"),s=A(e,"emailAndPassword"),n=A(e,"session");return{analyzable:!0,disableCsrfCheck:Ee(A(t,"disableCSRFCheck")),emailPasswordEnabled:Ee(A(s,"enabled")),requireEmailVerification:Ee(A(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Mr(A(e,"plugins"))&&Kr(A(e,"database")),secureCookiesDisabled:Lr(A(t,"useSecureCookies")),sessionFreshAgeZero:Dr(A(n,"freshAge")),trustedOriginsWildcard:_r(A(e,"trustedOrigins"))}},Ur=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Br=(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?zr(s):Ur();return{exportName:E(e),file:t,line:e.getStartLineNumber(),...o}},$r=(e,t)=>_s(e,t,Br),qr=(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},Vr=(e,t,s)=>{const n=qr(e.getExpression(),s);if(n===void 0)return;const o=e.getArguments()[s.argIndex];if(!(!o||!R(o)||_(o))&&!(s.requireUnmodifiedReach===!0&&!Xs(o)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:n}},jr=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression)){const r=Vr(o,t,s);r&&n.push(r)}return n},le=(e,t,s)=>{const n=[];for(const o of m(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...jr(r,v(t,o),s))}return n},Wr=new Set(["content","pdf","scrape","screenshot"]),Hr=(e,t)=>le(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Wr}),Gr=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Yr=new Set(["RateLimiter"]),Xr=new Set(["extend"]),dt="lunora",Qr=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],$t=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}},Ne=e=>e&&i.isObjectLiteralExpression(e)?$t(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Zr=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&Ot(t.getBody());return s?$t(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Jr=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=S(n.getExpression());o!==void 0&&(Gr.has(o)?s.push({callee:o,file:t,line:n.getStartLineNumber(),...Ne(n.getArguments()[0])}):Xr.has(o)&&s.push({callee:o,file:t,line:n.getStartLineNumber(),...Zr(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(l.NewExpression)){const o=S(n.getExpression());o===void 0||!Yr.has(o)||s.push({callee:o,file:t,line:n.getStartLineNumber(),...Ne(n.getArguments()[0])})}return s},eo=(e,t)=>{for(const s of Qr){const n=f(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())===dt&&r.push({callee:dt,file:s,line:a.getStartLineNumber(),...Ne(a.getArguments()[0])});return r}return[]},to=(e,t)=>{const s=[];for(const{displayPath:n,filePath:o}of Ie(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);s.push(...Jr(r,n))}return s.push(...eo(e,J(t))),s},ft="ctx.containers.",so=e=>{if(!e.startsWith(ft))return!1;const t=e.slice(ft.length);return t.length>0&&!t.includes(".")},no=(e,t)=>le(e,t,{argIndex:0,matchReceiver:so,methods:new Set(["get"])}),ro=new Set(["allow","deny","setAllowed"]),oo=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())},io=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!oo(e)))return{detail:"enableInternet: true",exportName:E(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},ao=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!ro.has(s.getName()))return;const n=s.getExpression();if(!(!i.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),exportName:E(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},co=(e,t)=>io(e,t)??ao(e,t),lo=(e,t)=>I(e,t,co),uo=new Set(["defineExportSink","r2Sink","webhookExportSink"]),fo=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return uo.has(s)?s:void 0},go=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}},po=(e,t)=>{const s=[];for(const{displayPath:n,filePath:o}of Ie(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);for(const a of r.getDescendantsOfKind(l.CallExpression)){const c=fo(a);if(c===void 0)continue;const u=a.getArguments()[0],d=u&&i.isObjectLiteralExpression(u)?go(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},mo=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),ho=new Set(["dbRateLimit","rateLimit"]),xo=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&i.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===l.TrueKeyword},Eo=(e,t)=>{const s=S(e.getExpression());if(s===void 0)return;const n=mo.get(s);if(n!==void 0)return{callee:s,exportName:E(e),failOpen:xo(e.getArguments()[n]),file:t,limitName:ho.has(s)?Rt(e):"",line:e.getStartLineNumber()}},vo=(e,t)=>I(e,t,Eo),So=new Set(["boolean","number","object","string"]),yo=e=>{const t=e.getName();if(!So.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="flags"&&ye(s.getExpression()))return t;const n=s.getExpression();if(s.getName()==="details"&&i.isPropertyAccessExpression(n)&&n.getName()==="flags"&&ye(n.getExpression()))return t},Ao=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=yo(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},No=(e,t)=>{const s=new Map;for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getDescendantsOfKind(l.CallExpression)){const a=Ao(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))},bo=e=>{const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const s=z(t);if(s?.kind!=="query")return;const n=zs(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},gt=e=>{const t=e.getParent();return t&&i.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},Po=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!i.isIdentifier(t)||t.getText()!=="ctx")return;const s=gt(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=gt(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},Io=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const o=Po(n);o!==void 0&&s.push({callee:o,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},wo=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=bo(o);r&&s.push(...Io(r,t))}return s},To=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...wo(o,v(t,n)))}return s},Co=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&ye(t.getExpression())},Fo=e=>{if(e?.getKind()===l.TrueKeyword)return!0;if(e?.getKind()===l.FalseKeyword)return!1},Oo=(e,t)=>{if(!Co(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const o=s.getLiteralValue(),r=Fo(n);if(!(o.length===0||r===void 0))return{defaultValue:r,exportName:E(e),file:t,key:o,line:e.getStartLineNumber()}},Ro=(e,t)=>I(e,t,Oo),Lo=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"||tn(r))return;const a=e.getSourceFile().getFilePath();return sn(o,e,a)?nn(o,e,a,0,new Set):r},Do=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},ko=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Mo=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression))Do(a)&&s.push({file:r,indexName:ko(a),line:a.getStartLineNumber()})}return s},H=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,qt=e=>{const t=e.getArguments()[0],s=H(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)?H(n.getInitializer()):void 0},Ko=new Set(["delete","get","head","options","patch","post","put"]),_o=new Set(["handler","stream"]),zo=new Set(["runAction","runMutation"]),Uo=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),se=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,pt=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const n=s.getNameNode();if(t)return i.isIdentifier(n)?n.getText():void 0;if(i.isObjectBindingPattern(n)){for(const o of n.getElements())if((o.getPropertyNameNode()?.getText()??o.getNameNode().getText())==="ctx"){const a=o.getNameNode();return i.isIdentifier(a)?a.getText():void 0}}},mt=(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(zo.has(a)&&se(c,t))return a;if(Uo.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&se(c.getExpression(),t))return`db.${a}`}},ht=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(l.PropertyAccessExpression))if(n.getName()==="auth"&&se(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(l.VariableDeclaration)){const o=n.getNameNode();if(!(!i.isObjectBindingPattern(o)||!se(n.getInitializer(),t))){for(const r of o.getElements())if((r.getPropertyNameNode()?.getText()??r.getNameNode().getText())==="auth")return!0}}return!1},Bo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!_o.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(Ko.has(o)){const r=n.getExpression();return i.isIdentifier(r)&&r.getText()==="httpRoute"?o.toUpperCase():void 0}s=n.getExpression()}},$o=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=H(e.getArguments()[0]),u=c&&pt(c,!0);if(!c||u===void 0)return;const d=mt(c,u);return d===void 0?void 0:{exportName:E(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ht(c,u),sideEffect:d}}const n=Bo(e);if(n===void 0)return;const o=H(e.getArguments()[0]),r=o&&pt(o,!1);if(!o||r===void 0)return;const a=mt(o,r);return a===void 0?void 0:{exportName:E(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:ht(o,r),sideEffect:a}},qo=(e,t)=>I(e,t,$o),Vo=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),jo=new Set(["append","set"]),Vt=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",xt=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(l.CallExpression)]:e.getDescendantsOfKind(l.CallExpression)).some(n=>Vo.has(S(n.getExpression())??"")&&Zs(n,t)),Wo=(e,t)=>{if(xt(e,t))return!0;const s=ce(e);return s!==void 0&&xt(s,t)},be=(e,t)=>Qs(e,t)&&!Wo(e,t),Ho=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=ce(e);return t!==void 0&&i.isNewExpression(t)&&S(t.getExpression())==="Headers"},ne=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=ce(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},Te=(e,t,s)=>{for(const n of e.getProperties())if(i.isPropertyAssignment(n)){const o=n.getInitializer();o!==void 0&&be(o,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:Vt(n.getNameNode()),line:o.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(n)){const o=n.getNameNode();be(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=ne(n.getExpression());o!==void 0&&Te(o,t,s)}},jt=(e,t)=>{const s=ne(e);if(s===void 0)return;const n=s.getProperty("headers");if(n===void 0||!i.isPropertyAssignment(n))return;const o=ne(n.getInitializer());o!==void 0&&Te(o,"response-init",t)},Go=(e,t)=>{const s=S(e.getExpression());if(s==="Response")jt(e.getArguments()[1],t);else if(s==="Headers"){const n=ne(e.getArguments()[0]);n!==void 0&&Te(n,"headers-ctor",t)}},Yo=(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"){jt(e.getArguments()[1],t);return}if(jo.has(n)&&Ho(o)){const r=e.getArguments()[1];r!==void 0&&be(r,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:Vt(e.getArguments()[0]),line:r.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},Xo=(e,t)=>{for(const s of e.getDescendantsOfKind(l.NewExpression))Go(s,t);for(const s of e.getDescendantsOfKind(l.CallExpression))Yo(s,t)},Qo=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=H(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 Xo(n,{exportName:E(e),relativePath:t,requestName:r.getText(),rows:a}),a},Zo=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression))s.push(...Qo(n,t));return s},Jo=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Zo(o,v(t,n)))}return s},ei=new Set(["auth","context.auth","ctx.auth"]),ti="userId",si=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},ni=(e,t)=>{const s=f(t,_t);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)?si(r):void 0}},Et=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return ei.has(e.getExpression().getText())?e:void 0},ri=e=>{if(i.isPropertyAccessExpression(e)&&Et(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&Et(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},oi=(e,t,s)=>{const n=[];for(const o of e.getDescendants()){const r=ri(o);r!==void 0&&n.push({declared:r===ti||s.has(r),exportName:E(o),file:t,key:r,line:o.getStartLineNumber()})}return n},ii=(e,t)=>{const s=ni(e,t);if(s===void 0)return[];const n=[];for(const o of m(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...oi(r,v(t,o),s))}return n},ai=(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:E(e),file:t,line:e.getStartLineNumber()}},ci=(e,t)=>I(e,t,ai),li=new Set(["delete","get","getRaw","getWithMetadata","put"]),ui=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return le(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.kv"||r.startsWith("ctx.kv."),methods:li}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},di=new Set(["queue","send"]),vt=new Set(["bcc","cc","to"]),fi=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!di.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},gi=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return vt.has(t.getName())&&R(n)&&!_(n)}if(!i.isPropertyAssignment(t)||!vt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&R(s)&&!_(s)}):!1,pi=(e,t)=>{const s=fi(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!gi(n)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s}},mi=(e,t)=>I(e,t,pi),hi=e=>i.isPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?i.isComputedPropertyName(e.getNameNode()):!1,xi=e=>i.isPropertyAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?hi(e):!0,Wt=(e,t=!1)=>{for(const s of e.getProperties()){if(xi(s))return!0;if(t)continue;if(!i.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!i.isObjectLiteralExpression(n)||Wt(n,!0))return!0}return!1},Ei=(e,t)=>{for(const s of m(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:o}of Mt(n))for(const r of we(o)){const a=r.getArguments()[0];if(a!==void 0&&(!i.isObjectLiteralExpression(a)||Wt(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=te(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=te(a);c!==void 0&&s.push({column:c,strategy:kt(a),table:o})}}return s},Si=(e,t)=>{const s=new Map;for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:r}of Mt(o))for(const a of we(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()]}},yi=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!i.isObjectLiteralExpression(n))return[];const o=[];for(const r of n.getProperties()){const a=te(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=te(u);if(d===void 0)continue;const y=kt(u);y!=="custom"&&o.push({column:d,exportName:t,file:s,line:u.getStartLineNumber(),strategy:y,table:a})}}return o},Ai=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?z(s):void 0;return n?.receiver?we(n.receiver).flatMap(o=>yi(o,e.getName(),t)):[]},Ni=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Ai(c,r))}return s},bi=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return k(s)},Pi=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},Ii=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==l.CallExpression)return;const s=t;return un(s.getExpression())?s:void 0},wi=e=>{const t=Ii(e),s=t===void 0?void 0:Pi(t);if(s===void 0)return[];const n=e.getNameNode(),o=i.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(l.CallExpression).filter(r=>bi(r)).map(r=>({exportName:o,file:"lunora/mutators.ts",line:r.getStartLineNumber()}))},Ti=e=>e.getVariableDeclarations().flatMap(t=>wi(t)),Ci=(e,t)=>{const s=f(t,ln);if(!b(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Ti(n)},Fi=new Set(["delete","get","patch"]),Oi=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Ri=new Set(["auth","identity","session","user"]),Li=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),Di=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!k(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},ki=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},Mi=(e,t)=>e.getDescendantsOfKind(l.Identifier).some(s=>s.getText()===t),Ki=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(l.ThrowStatement).length>0||e.getDescendantsOfKind(l.ReturnStatement).length>0,_i=(e,t)=>e.getDescendantsOfKind(l.IfStatement).some(s=>Mi(s.getExpression(),t)&&Ki(s.getThenStatement())),zi=(e,t)=>{for(const s of e.getDescendantsOfKind(l.CallExpression)){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))continue;const o=n.getName();if(!Fi.has(o))continue;const r=n.getExpression();if(!(k(r)||i.isPropertyAccessExpression(r)&&k(r.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&i.isIdentifier(c)&&c.getText()===t)return o}},Ui=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},Bi=e=>e.getDescendantsOfKind(l.CallExpression).some(t=>t.getArguments().some(s=>Ui(s)==="ctx")),$i=e=>e.getDescendantsOfKind(l.BinaryExpression).some(t=>Li.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),qi=e=>{for(const t of e.getDescendantsOfKind(l.Identifier))if(Oi.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&Ri.has(t.getName()))return!0}return Bi(e)||$i(e)},Vi=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=z(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const o=qt(s);if(o===void 0)return[];const r=n.receiver!==void 0&&Dt(n.receiver,"use","rls"),a=qi(o),c=new Set,u=[];for(const d of o.getDescendantsOfKind(l.CallExpression)){const y=Di(d);if(y===void 0)continue;const x=ki(d);if(x===void 0||c.has(x)||!_i(o,x))continue;const P=zi(o,x);P!==void 0&&(c.add(x),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:P,table:y,usesRls:r,visibility:n.visibility}))}return u},ji=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Vi(c,r))}return s},Wi=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Hi=new Set(["insert","insertManyUnsafe","patch","replace"]),Gi=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Hi.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},Yi=(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},Xi=(e,t,s,n)=>{const o=[];for(const r of e.getProperties()){let a,c;i.isPropertyAssignment(r)?(a=r.getName(),c=r.getInitializer()):i.isShorthandPropertyAssignment(r)&&(a=r.getName(),c=r.getNameNode()),!(a===void 0||c===void 0||!Wi.has(a))&&R(c)&&!_(c)&&o.push({exportName:E(s),field:a,file:n,line:s.getStartLineNumber(),method:t})}return o},Qi=(e,t)=>{const s=Gi(e.getExpression());if(s===void 0)return[];const n=e.getArguments()[1];return n?Yi(n,s).flatMap(o=>Xi(o,s,e,t)):[]},Zi=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression))for(const r of Qi(o,t)){const a=s(r.exportName);n.push(a===void 0?r:{...r,visibility:a})}return n},Ji=(e,t,s=[])=>{const n=[],o=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));for(const r of m(t)){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=v(t,r);n.push(...Zi(a,c,u=>o.get(`${c}:${u}`)))}return n},ea=["providerSubscriptionId","state"],ta=["providerEventId","processedAt"],St=(e,t)=>t.every(s=>s in e.shape),sa=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&St(t,ea)&&St(s,ta)},na=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),ra=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,oa=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?ra(t.getInitializer()):void 0},ia=(e,t)=>{const s=S(e.getExpression());if(s===void 0||!na.has(s))return;const[n]=e.getArguments(),o=n&&i.isObjectLiteralExpression(n)?oa(n):void 0;return{callee:s,exportName:E(e),file:t,line:e.getStartLineNumber(),...o===void 0?{}:{toleranceSeconds:o}}},aa=(e,t)=>I(e,t,ia),ca=new Set(["defineQueue","defineWorkflow"]),la=new Set(["run","runAction","runMutation","runQuery"]),ua=new Set(["api","internal"]),da=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},fa=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},Ht=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},Gt=(e,t)=>e===t||e.startsWith(`${t}.`),Yt=e=>{const t=e.getDescendantsOfKind(l.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},yt=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)},Xt=e=>{const t=e.getDescendantsOfKind(l.Identifier).filter(s=>yt(s));return i.isIdentifier(e)&&yt(e)&&t.push(e),t},ga=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(l.BindingElement).map(s=>s.getName())},pa=e=>{const t=Ht(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},ma=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:pa(e),o=new Set,r=a=>Yt(a).some(c=>n.some(u=>Gt(c.getText(),u)))?!0:Xt(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 ga(a))o.add(u)}return{names:o,prefixes:n}},ha=(e,t)=>Yt(e).some(s=>t.prefixes.some(n=>Gt(s.getText(),n)))?!0:Xt(e).some(s=>t.names.has(s.getText())),xa=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)||!ua.has(s.getText())||t.length<2))return{exportName:n,file:t.slice(0,-1).join("/")}},Ea=(e,t,s)=>{const n=Ht(e,0);if(n===void 0)return[];const o=ma(e,t,n),r=[];for(const a of e.getDescendantsOfKind(l.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!la.has(c.getName())||c.getExpression().getText()!==n)continue;const u=a.getArguments()[1];if(!u||!ha(u,o))continue;const d=xa(a.getArguments()[0]);d!==void 0&&r.push({dispatchKind:t,file:s,handlerExport:E(a),line:a.getStartLineNumber(),targetExport:d.exportName,targetFile:d.file})}return r},va=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=da(n);if(o===void 0||!ca.has(o))continue;const r=fa(n);r!==void 0&&s.push(...Ea(r,o==="defineQueue"?"queue":"workflow",t))}return s},Sa=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...va(o,v(t,n)))}return s},At={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},Nt=new Set(["account","credential","member","passkey","session","user"]),ya=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),Aa=e=>{const s=ya(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return Nt.has(s)||Nt.has(n)},Na=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},ba=(e,t)=>{const{objects:s,opaque:n}=Bt(e,t);return Pr(s).some(o=>Na(o))?!0:n?void 0:!1},Pa=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Ia=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},ee={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},wa=e=>{const t=Ia(e),s=t?S(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=Pa(t);return{...ee,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in At?{...ee,[At[s]]:!0}:ee},Ta=e=>{const t={...ee};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=wa(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},Ca=new Set(["insert","insertMany","insertManyUnsafe","replace"]),Fa=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Ca.has(t.getName()))return!1;const s=t.getExpression();if(!k(s))return!1;const o=e.getArguments()[0];return!o||!(i.isStringLiteral(o)||i.isNoSubstitutionTemplateLiteral(o))?!1:Aa(o.getLiteralText())},Oa=new Set(["create","runAfter","runAt","send","sendBatch"]),Ra=new Set(["queues","scheduler","workflows"]),La=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Oa.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&Ra.has(s.getName())){const n=s.getExpression();if(i.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},Da=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return k(s)},Qt=new Set(["generateObject","generateText","streamObject","streamText"]),ka=e=>{const t=S(e.getExpression());return t!==void 0&&Qt.has(t)},Ma=e=>{const t=S(e.getExpression());if(t===void 0||!Qt.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")},Ka=new Set(["log","span","trace"]),_a=new Set(["ai"]),za=new Set(["email","mail"]),Ua=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),ve=(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"}),Ba=new Set([l.ArrowFunction,l.FunctionDeclaration,l.FunctionExpression,l.GetAccessor,l.MethodDeclaration,l.SetAccessor]),$a=new Set(["every","filter","flatMap","forEach","map","some"]),qa=new Set(["all","allSettled","race"]),Va=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($a.has(n))return t;const o=s.getExpression();if(i.isIdentifier(o)&&o.getText()==="Promise"&&qa.has(n))return t},ja=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(Ba.has(t.getKind())){const s=Va(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},Wa=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}},Ha=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}},Ga=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression)){if(!Ua.has(n.getName()))continue;const o=n.getExpression();if(!i.isIdentifier(o)||o.getText()!=="ctx")continue;const r=Ha(n);r&&(t=!0,!ja(r)&&!Wa(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},Ya=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"}),bt="lunora-advisor-exempt",Xa=/^[\s*/]+/u,Qa=/[\w-]/u,Za=e=>{const s=(e.getFirstAncestorByKind(l.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
6
+ `);for(const n of s.split(`
7
+ `)){const o=n.replace(Xa,"");if(!o.startsWith(bt))continue;const r=o.slice(bt.length);if(Qa.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:""}},Ja=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}},ec=(e,t)=>{const s=Ja(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(Fa(u)&&(r=!0),La(u)&&(t=!0),Da(u)&&(o=!0),ka(u)&&(s=!0),Ma(u)&&(n=!0),r&&t&&o&&n)break;const{handlesErrors:a,reachesOutbound:c}=Ga(e);return{callsMail:ve(e,za),emitsEvent:ve(e,Ka),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||ve(e,_a),throwsBareError:Ya(e),unboundedAiGeneration:n,usesInsertManyUnsafe:o,writesUserTable:r}},sc=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=z(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const o=n.receiver?Ta(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},r=ec(e,s);return{...r?tc(r):{},...Za(e),...o,analyzableBody:r!==void 0,exportName:e.getName(),file:t,hasEmailArg:ba(s,n.receiver),kind:n.kind,visibility:n.visibility}},nc=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=sc(o,t);r&&s.push(r)}return s},rc=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...nc(o,v(t,n)))}return s},oc=new Set(["dbRateLimit","rateLimit"]),ic=e=>i.isArrowFunction(e)?e.getBody():e,ac=(e,t)=>{const s=S(e.getExpression());if(s===void 0||!oc.has(s))return;const n=e.getArguments()[2];if(!n)return;const o=A(n,"key");if(!o)return;const r=ic(o);if(!(!R(r)||_(r)))return{callee:s,exportName:E(e),file:t,limitName:Rt(e),line:e.getStartLineNumber()}},cc=(e,t)=>I(e,t,ac),lc=new Set(["findFirst","findFirstOrThrow","findMany","get"]),uc=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!lc.has(t.getName()))return;const s=t.getExpression();if(k(s)){const n=e.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&k(s.getExpression()))return s.getName()},dc=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&k(s.getExpression())){const n=t.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},fc=e=>{let t=W(e)??e;for(;i.isAwaitExpression(t);)t=W(t.getExpression())??t.getExpression();return t},Zt=(e,t=!1)=>{const s=fc(e);if(i.isIdentifier(s)){if(t)return;const n=ce(s);return n===void 0?void 0:Zt(n,!0)}if(i.isCallExpression(s))return uc(s)??dc(s)},gc=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},pc=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=z(s);if(n?.kind!=="query")return[];const o=qt(s);if(o===void 0)return[];const r=n.receiver!==void 0&&js(n.receiver,"output"),a=n.receiver!==void 0&&Dt(n.receiver,"use","mask"),c=new Set,u=[];for(const d of gc(o)){const y=Zt(d);y===void 0||c.has(y)||(c.add(y),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:y,usesMask:a,usesOutput:r,visibility:n.visibility}))}return u},mc=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...pc(c,r))}return s},hc=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},xc=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?z(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Lt(r);if(a===void 0)continue;const c=hc(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},Ec=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...xc(c,r))}return s},re=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===l.PlusToken){const t=re(e.getLeft()),s=re(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},vc=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&&re(t)!==void 0},Sc=/(?:^|\/)__tests__\//u,yc=/\.(?:spec|test)$/u,Ac=e=>Sc.test(e)||yc.test(e),Nc=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()}},bc=(e,t,s)=>Sn(e)?!Ac(s)&&yn(Nc(t)):!0,Pc=(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(vc(r))continue;const a=re(r);if(a===void 0)continue;const c=En(a);if(c===void 0||!bc(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:vn(a)}))}return s},Ic=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Pc(o,v(t,n)))}return s},wc=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?z(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Lt(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},Tc=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...wc(c,r))}return s},Cc=new Set(["query","unsafe"]),Fc=e=>{if(!i.isPropertyAccessExpression(e)||!Cc.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"},Oc=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),Rc=e=>e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()??"<module>",Lc=(e,t)=>{if(!Fc(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Oc(s)))return{exportName:Rc(e),file:t,line:s.getStartLineNumber()}},Dc=(e,t)=>I(e,t,Lc),kc=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],Mc=e=>{for(const[t,s]of kc)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},Kc=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getImportDeclarations()){const a=r.getModuleSpecifierValue(),c=Mc(a);c!==void 0&&s.push({file:v(t,n),line:r.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},_c=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),zc=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return le(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:_c,requireUnmodifiedReach:!0}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},Uc=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Bc=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,$c=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=Bc(o.getInitializer()));continue}(i.isShorthandPropertyAssignment(o)||i.isMethodDeclaration(o))&&t.push(o.getName())}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},qc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=Uc.get(t);if(s===void 0)return;const n=e.getExpression().getText();return n==="ctx.storage"||n.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},Vc=(e,t)=>{const s=qc(e.getExpression());if(s!==void 0)return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s.method,...$c(e.getArguments()[s.optionsIndex])}},jc=(e,t)=>I(e,t,Vc),Wc=(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")}),Hc=new Set(["RegisteredAction","RegisteredMutation","RegisteredQuery"]),Ce=e=>{const t=e.getType(),s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName();return s!==void 0&&Hc.has(s)?s:void 0},Jt=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},es={cause:"codegen recognises a procedure only when the initializer is a builder chain, and this one is produced by a call or an alias",remediation:"A factory that returns a procedure cannot be read statically — inline it, or export the chain the factory builds."},Gc={cause:"the binding is exported by a separate `export { … }` statement, and codegen reads the `export` keyword on the declaration itself",remediation:"Move the keyword onto the declaration and drop the separate export statement."},Fe=(e,t,s,n,o)=>({cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally a builder chain. A procedure written any other way exists at runtime but never reaches `_generated/api.ts`, so no caller can address it.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${s}\` but was not registered — ${o.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:s},name:"procedure_not_registered",remediation:`Assign the builder chain directly: \`export const ${t} = query.input({ … }).query(handler);\`. ${o.remediation}`,title:"Procedure exists at runtime but is missing from the generated API"}),Yc=(e,t,s)=>{const n=[];for(const o of e.getVariableStatements().filter(r=>r.isExported()))for(const r of o.getDeclarations()){const a=r.getName();if(s.has(`${t}:${a}`)||!Jt(r))continue;const c=Ce(r);c!==void 0&&n.push(Fe(t,a,c,r.getStartLineNumber(),es))}return n},Xc=(e,t,s)=>{if(s.has(`${t}:default`))return[];const n=[];for(const o of e.getExportAssignments().filter(r=>!r.isExportEquals())){const r=Ce(o.getExpression());r!==void 0&&n.push(Fe(t,"default",r,o.getStartLineNumber(),es))}return n},Qc=(e,t,s)=>{const n=[];for(const o of e.getExportDeclarations().filter(r=>r.getModuleSpecifier()===void 0))for(const r of o.getNamedExports()){const a=r.getAliasNode()?.getText()??r.getName();if(s.has(`${t}:${a}`))continue;const c=r.getLocalTargetDeclarations().find(d=>i.isVariableDeclaration(d));if(c===void 0||!Jt(c))continue;const u=Ce(c);u!==void 0&&n.push(Fe(t,a,u,r.getStartLineNumber(),Gc))}return n},Zc=(e,t,s)=>[...Yc(e,t,s),...Xc(e,t,s),...Qc(e,t,s)],Jc=(e,t,s)=>{const n=new Set(s.map(r=>`${r.filePath}:${r.exportName}`)),o=[];for(const r of m(t)){const a=e.getSourceFile(r);a!==void 0&&o.push(...Zc(a,v(t,r),n))}return o.toSorted((r,a)=>r.cacheKey.localeCompare(a.cacheKey))},el=new Set(["when","where"]),Se=new Set(["definePolicy","defineShape"]),tl=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const n=t.getName();return Se.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 Se.has(o)?o:void 0}const s=t.getText();return Se.has(s)?s:void 0},sl=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,ts=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===l.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(sl(e))return"empty-object";if(i.isParenthesizedExpression(e))return ts(e.getExpression())}},Oe=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),nl=e=>e.getDescendantsOfKind(l.ReturnStatement).filter(t=>Oe(t)===e),ss=e=>e.getDescendantsOfKind(l.ConditionalExpression).filter(t=>Oe(t)===e),rl=e=>{const t=nl(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(l.IfStatement)!==void 0)||ss(e).length>0},ol=e=>e.getDescendantsOfKind(l.IfStatement).filter(t=>Oe(t)===e),Pe=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()==="",il=(e,t)=>Pe(e)||Pe(t),al=new Map([[l.EqualsEqualsEqualsToken,"positive"],[l.EqualsEqualsToken,"positive"],[l.ExclamationEqualsEqualsToken,"negative"],[l.ExclamationEqualsToken,"negative"]]),Pt=e=>!Pe(e)&&(i.isLiteralExpression(e)||e.getKind()===l.TrueKeyword),cl=(e,t,s)=>{const n=al.get(e);if(n!==void 0)return il(t,s)?n==="positive"?"negative":"positive":Pt(t)||Pt(s)?void 0:n},j=e=>{if(i.isParenthesizedExpression(e))return j(e.getExpression());if(i.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken)return"negative";if(i.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=cl(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===l.AmpersandAmpersandToken||t===l.BarBarToken){const n=j(e.getLeft()),o=j(e.getRight());return n===o?n:"indeterminate"}}return i.isIdentifier(e)||i.isPropertyAccessExpression(e)||i.isElementAccessExpression(e)||i.isCallExpression(e)?"positive":"indeterminate"},It=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}}},ll=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=>i.isReturnStatement(e)?e.getExpression()??e:e,dl=e=>{const t=[];for(const s of ss(e)){const n=j(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of ol(e)){const n=j(s.getExpression());if(n==="indeterminate")continue;const o=n==="negative"?It(s.getThenStatement()):It(s.getElseStatement())??ll(s);o!==void 0&&t.push(ul(o))}return t},fl=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},gl=(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)||!el.has(r.getName()))continue;const a=r.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&rl(a))for(const c of dl(a)){const u=ts(c);u!==void 0&&o.push({exportName:fl(e),file:s,form:u,key:r.getName(),line:c.getStartLineNumber(),owner:t})}}return o},pl=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=tl(n);o!==void 0&&s.push(...gl(n,o,t))}return s},ml=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...pl(o,v(t,n)))}return s},hl=new Set(["query","upsert","upsertMany"]),xl=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(hl.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},El=(e,t)=>{const s=xl(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:E(e),file:t,line:e.getStartLineNumber(),method:s}},vl=(e,t)=>I(e,t,El),Sl=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"},yl=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Al=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression)){if(!Sl(a))continue;const c=Us(a);c!==""&&s.push({exportName:c,file:r,line:a.getStartLineNumber(),workflow:yl(a)})}}return s},Nl=".lunora-schema.json",w=(e,t)=>{b(e)&&Ct(e,"utf8")===t||ps(e,t,"utf8")},O=(e,t)=>{if(t===""){ms(e,{force:!0});return}w(e,t)},bl=e=>{const t=f(e,"package.json");if(b(t))try{const s=JSON.parse(Ct(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},Pl=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Il=e=>{let t=b(e)?e:J(e);for(;t&&t!==J(t);){const s=f(t,"tsconfig.json");if(b(s))return s;t=J(t)}},wt=e=>e.replaceAll("\\","/"),wl=(e,t,s)=>{if(s&&e.length>0){const r=e.map(a=>`"${a.exportName}"`).join(", ");throw new D("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${r}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const r of t.columns){const a=n.get(r.table)??[];a.push(r.column),n.set(r.table,a)}const o=t.columns.length>0;for(const r of e){if(r.table===void 0){if(o)throw new D("MASK_UNSUPPORTED",`defineShape "${r.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${r.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(r.table);if(a===void 0)continue;const c=a.map(u=>`"${u}"`).join(", ");throw new D("MASK_UNSUPPORTED",`defineShape "${r.exportName}" replicates table "${r.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},oe=(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)},Tt=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,Tl=8,Cl=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:o,migrations:r,project:a,shapes:c,usesSandbox:u,useUmbrella:d,workflows:y}=e;let x=nt(a,o),P=ot(a,o),M=rt(a,o);it([...x,...P].map(g=>g.filePath)),it(M.filter(g=>g.stream).map(g=>g.filePath),"http-stream");for(let g=1;;g+=1){const T=Ms({agents:t,functions:x,httpRoutes:M,mutators:P,useUmbrella:d,workflows:y}),C=Ks({agents:t,functions:x,migrations:r,mutators:P,shapes:c,useUmbrella:d,usesSandbox:u});if(g>=Tl||Tt(a,s,T)&&Tt(a,n,C))return{apiContent:T,functions:x,functionsContent:C,httpRoutes:M,mutators:P};oe(a,s,T),oe(a,n,C),x=nt(a,o),P=ot(a,o),M=rt(a,o)}},Fl=e=>{const t=Il(e);return t?new st({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new st({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},bu=(e,t)=>{const s=m(t),n=f(t,"schema.ts");b(n)&&s.push(n);for(const c of s){const u=e.getSourceFile(c);u===void 0?e.addSourceFileAtPath(c):u.refreshFromFileSystemSync()}const o=new Set(s.map(c=>wt(c))),r=wt(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)}}},Pu=e=>{const t=Pl(),s=t?he.now():0,n=f(e.projectRoot,e.lunoraDirectory??"lunora"),o=f(n,"schema.ts");if(!b(o))throw new D("INTERNAL",`schema.ts not found at ${o}`);const r=e.project??Fl(n);Tn(Lo);const a=xn(r,o,e.projectRoot),{agents:c,containers:u,crons:d,dataModelContent:y,dependencies:x,entryCronTriggers:P,env:M,featureUsage:g,hasFlags:T,hasNotify:C,identity:$,platformGate:N,queues:L,serverContent:U,storageRulesMetadata:q,usesSandbox:G,useUmbrella:K,workflows:F}=Zn({lunoraDirectory:n,project:r,projectRoot:e.projectRoot,schema:a,target:e.target}),p=f(n,"_generated"),Re=f(p,"dataModel.ts"),Le=f(p,"server.ts"),ns=f(p,"api.ts"),rs=f(p,"functions.ts");oe(r,Re,y),oe(r,Le,U);const ue=cn(r,n),V=An(r,n),{apiContent:De,functions:B,functionsContent:ke,httpRoutes:os,mutators:is}=Cl({agents:c,apiPath:ns,generatedFunctionsPath:rs,lunoraDirectory:n,migrations:ue,project:r,shapes:V,useUmbrella:K,usesSandbox:G,workflows:F}),Y=e.lint===!1?void 0:Es({adminRoutes:ir(r,n),aiRawRuns:lr(r,n),aiToolSideEffects:vr(r,n),argumentDerivedFetches:Ar(r,n),argumentValidators:Rr(r,n),authApiCalls:en(r,n),authConfigs:$r(r,n),browserUrlAccesses:Hr(r,n),configCalls:to(r,n),containerKeyAccesses:no(r,n),containerOverrides:lo(r,n),containers:u,exportSinks:po(r,n),staleMigrationImports:Kc(r,n),failOpenGuards:vo(r,n),flagReads:To(r,n),flagSecurityDefaults:Ro(r,n),geoIndexUsages:Mo(r,n),httpActionGuards:qo(r,n),httpHeaderWrites:Jo(r,n),hyperdriveCalls:rn(r,n),identityClaimReads:ii(r,n),imageDeliveryUrlAccesses:ci(r,n),inserts:on(r,n),kvKeyAccesses:ui(r,n,B),mailRecipientAccesses:mi(r,n),maskProcedures:an(r,n),maskStrategies:Ni(r,n),mutatorWrites:Ci(r,n),nondeterministicCalls:dn(r,n),normalizeIdAuthorizations:ji(r,n),notifyCalls:gn(r,n),notifyConfig:fn(r,n),ownerFieldWrites:Ji(r,n,B),unrestrictedWhereBranches:ml(r,n),paymentWebhooks:aa(r,n),privilegedDispatches:Sa(r,n),procedureProtections:rc(r,n),queries:Js(r,n),queues:L,r2sqlCalls:pn(r,n),ratelimitKeySelectors:cc(r,n),rawRowReturns:mc(r,n),relationLoads:Ec(r,n),rlsProcedures:mn(r,n),schema:a,secretLiterals:Ic(r,n),shapes:V,softDeleteReads:Tc(r,n),sqlInterpolations:Dc(r,n),storageKeyAccesses:zc(r,n,B),storageUploads:jc(r,n),vectorNamespaceAccesses:vl(r,n),workflowCalls:Al(r,n),workflows:F,wranglerVariables:e.wranglerVariables}),Me=Y===void 0?[]:[...hs(Y,{source:"static"}),...Jc(r,n,B)],as=hn(r,n),Ke=Si(r,n);wl(V,Ke,Ei(r,n));const cs=T?No(r,n):[],de=N.signals.vectorStore!==!1,X=Wc(g,{containerCount:u.length,cronCount:d.length,dependencies:x,hasPaymentTables:sa(a.tables),queueCount:L.length,storageColumnCount:Object.keys(Ft(a)).length,storageRuleCount:q.rules.length,vectorIndexCount:a.vectorIndexes.length,vectorStoreSupported:de,workflowCount:F.length}),_e=t?he.now():0,fe=Cn(a,ue.map(h=>h.id)),ze=Ps({advisories:Me,advisorProcedures:Y?.procedureProtections??[],agents:c,containers:u,env:M,flagKeys:cs,hasAccessFacade:g.access,hasAi:g.ai,hasAnalytics:g.analytics,hasBrowser:g.browser,hasFlags:T,hasHyperdrive:g.hyperdrive,hasImages:g.images,hasKv:g.kv,hasNotify:C,hasPayments:g.payments,hasPipelines:g.pipelines,hasR2sql:g.r2sql,hasVectors:de,hasX402:g.x402,maskMetadata:Ke,mutators:is,queues:L,rlsMetadata:as,schema:a,schemaSnapshot:fe,shapes:V,storageRules:q,studioFeatures:X,useUmbrella:K,workflows:F}),Ue=Is(V,x.has("@lunora/db"),K),Be=ws(u,a.jurisdiction),$e=Ts(F),qe=Cs(c),Ve=Fs(L),je=Os(d),We=Rs(a.vectorIndexes),Q=Ls(a,K),He=Ds(x.has("@lunora/seed")),Z=e.apiSpec??"openapi",ge=Z==="openapi"||Z==="both",pe=Z==="openrpc"||Z==="both",Ge=Nn({emailAgents:c.filter(h=>h.onEmail===!0).map(h=>({bindingName:h.bindingName,exportName:h.exportName})),hasAccess:x.has("@lunora/cloudflare-access"),hasAi:g.ai,hasAnalytics:g.analytics,hasAuth:x.has("@lunora/auth"),hasBrowser:g.browser,hasFramework:x.has("@lunora/astro")||x.has("@lunora/svelte")||x.has("@lunora/vue"),hasGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend!=="hyperdrive"),hasHyperdrive:g.hyperdrive,hasHyperdriveGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend==="hyperdrive"),hasImages:g.images,hasKv:g.kv,hasKvIntrospector:X.kv,hasNotify:C,hasPayments:g.payments,hasR2sql:g.r2sql,hasQueue:L.some(h=>h.mode==="push"),hasScheduler:X.scheduler,hasStorage:X.storage,hasVectors:de,hasWorkflow:F.length>0,hasX402:g.x402,identity:$,jurisdiction:a.jurisdiction,tableNames:a.tables.map(h=>h.name),useUmbrella:K,vectorIndexCount:a.vectorIndexes.length,voiceAgents:c.filter(h=>h.voice===!0&&h.voiceBindingName!==void 0).map(h=>({bindingName:h.voiceBindingName,exportName:h.exportName})),wantsOpenApi:ge,wantsOpenRpc:pe}),Ye=bl(e.projectRoot),Xe=bn({functions:B,httpRoutes:os,version:Ye}),Qe=In({functions:B,version:Ye}),Ze=`${JSON.stringify(Xe,void 0,2)}
8
+ `,Je=`${JSON.stringify(Qe,void 0,2)}
9
+ `,et=Pn(Xe),tt=wn(Qe),me=f(n,Nl),ls=b(me);if(e.dryRun||(b(p)||gs(p,{recursive:!0}),w(f(p,"app.ts"),Ge),w(Re,y),w(f(p,"api.ts"),De),w(Le,U),w(f(p,"functions.ts"),ke),w(f(p,"shard.ts"),ze),w(f(p,"crons.ts"),je),w(f(p,"vectors.ts"),We),w(f(p,"drizzle.global.ts"),Q.global),w(f(p,"drizzle.shard.ts"),Q.shard),O(f(p,"containers.ts"),Be),O(f(p,"workflows.ts"),$e),O(f(p,"agents.ts"),qe),O(f(p,"queues.ts"),Ve),O(f(p,"seed.ts"),He),O(f(p,"collections.ts"),Ue),O(f(p,"openapi.json"),ge?Ze:""),O(f(p,"openapi.ts"),ge?et:""),O(f(p,"openrpc.json"),pe?Je:""),O(f(p,"openrpc.ts"),pe?tt:""),(!ls||e.updateSchemaBaseline===!0)&&w(me,xs(fe))),t){const h=he.now(),us=Math.round(h-s),ds=Math.round(_e-s),fs=Math.round(h-_e);console.error(`@lunora/codegen: codegen took ${us.toString()}ms (discovery ${ds.toString()}ms, emit ${fs.toString()}ms)`)}return{advisories:Me,advisorContext:Y,agents:c,containers:u,cronTriggers:[...new Set([...ks(d),...P])],generated:{agents:qe,api:De,app:Ge,collections:Ue,containers:Be,crons:je,dataModel:y,drizzleGlobal:Q.global,drizzleShard:Q.shard,functions:ke,openApi:Ze,openApiModule:et,openRpc:Je,openRpcModule:tt,queues:Ve,seed:He,server:U,shard:ze,vectors:We,workflows:$e},migrations:ue,outputDirectory:p,platformDiagnostics:N.diagnostics,queues:L,schemaSnapshot:fe,schemaSnapshotPath:me,workflows:F}};export{Nl as SCHEMA_SNAPSHOT_FILENAME,Fl as createCodegenProject,Il as findTsconfig,bu as refreshCodegenProject,Pu as runCodegen};
@@ -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-BvqYMy81.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};
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-lHrzFhbX.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-C5BOBVM7.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-BvqYMy81.mjs";import{a as u}from"./module-specifiers-WF8iAydP.mjs";const T=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},x=(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,N=(t,i,e)=>f(t).filter(r=>r.name===i).map(r=>r.call.getArguments()[0]).filter(r=>r!==void 0&&o.isCallExpression(r)&&x(r.getExpression(),e)),A=(t,i)=>f(t).some(e=>e.name===i),w=(t,i,e)=>N(t,i,e).length>0,l=new Set(["action","mutation","query","stream"]),m={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},I={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init"},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}},P=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=I[e];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}};export{T as a,f as b,P as c,w as d,A as e,N as w};
1
+ import{Node as o}from"ts-morph";import{unwrapExpression as a}from"./listLunoraSourceFiles-lHrzFhbX.mjs";import{a as u}from"./module-specifiers-WF8iAydP.mjs";const T=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},x=(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,N=(t,i,e)=>f(t).filter(r=>r.name===i).map(r=>r.call.getArguments()[0]).filter(r=>r!==void 0&&o.isCallExpression(r)&&x(r.getExpression(),e)),A=(t,i)=>f(t).some(e=>e.name===i),w=(t,i,e)=>N(t,i,e).length>0,l=new Set(["action","mutation","query","stream"]),m={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},I={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init"},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}},P=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=I[e];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}};export{T as a,f as b,P as c,w as d,A as e,N 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-BvqYMy81.mjs";import{c as u}from"./classify-procedure-call-CRm5Etni.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};
1
+ import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as d,lunoraRelativePath as l,handlerOf as f}from"./listLunoraSourceFiles-lHrzFhbX.mjs";import{c as u}from"./classify-procedure-call-C5BOBVM7.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};
@@ -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-BvqYMy81.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
+ import{SyntaxKind as p,Node as s}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as g,enclosingExportName as d}from"./listLunoraSourceFiles-lHrzFhbX.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-BvqYMy81.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};
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-lHrzFhbX.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};
@@ -1 +1 @@
1
- import{s as x}from"./paths-C-9fwEgQ.mjs";import{listLunoraSourceFiles as h,lunoraRelativePath as P}from"./listLunoraSourceFiles-BvqYMy81.mjs";import{b as f,c as E}from"./classify-procedure-call-CRm5Etni.mjs";import{Node as n,SyntaxKind as b}from"ts-morph";import{p as A,a as d}from"./parse-validator-CMV0eq2a.mjs";import{u as v}from"./unwrap-handler-return-CmIWbykC.mjs";const N=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return"unknown";const t=e.getProperty("handler");if(!t||!n.isPropertyAssignment(t))return"unknown";const r=t.getInitializer();return!r||!(n.isArrowFunction(r)||n.isFunctionExpression(r))?"unknown":v(r)},F=i=>{const e=i.getArguments()[0];return!e||!(n.isArrowFunction(e)||n.isFunctionExpression(e))?"unknown":v(e)},z=i=>{let e={};for(const t of f(i)){if(t.name!=="input")continue;const r=t.call.getArguments()[0];r&&n.isObjectLiteralExpression(r)&&(e={...d(r),...e})}return e},C=i=>{const e=f(i).find(r=>r.name==="output");if(!e)return;const t=e.call.getArguments()[0];return t&&n.isExpression(t)?A(t):void 0},u=(i,e)=>{const t=i.getProperty(e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isStringLiteral(r)?r.getLiteralValue():void 0},m=(i,e)=>{const t=i.getProperty(e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isNumericLiteral(r)?r.getLiteralValue():void 0},O=i=>{const e=i.getProperty("cache");if(e===void 0||!n.isPropertyAssignment(e))return;const t=e.getInitializer();if(t===void 0||!n.isObjectLiteralExpression(t))return;const r=u(t,"scope"),s=m(t,"maxAge"),o=m(t,"staleWhileRevalidate"),a=u(t,"tag"),c=u(t,"vary"),g={...s===void 0?{}:{maxAge:s},...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},S=i=>{if(i===void 0||!n.isObjectLiteralExpression(i))return{};const e=O(i),t=i.getProperty("rest");return t!==void 0&&n.isPropertyAssignment(t)?{...e===void 0?{}:{cache:e},rest:t.getInitializer()?.getText()==="true"}:e===void 0?{}:{cache:e}},L=i=>{const e=f(i).find(t=>t.name==="expose");return e?S(e.call.getArguments()[0]):void 0},I=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return{};const t=e.getProperty("args");if(!t||!n.isPropertyAssignment(t))return{};const r=t.getInitializer();return!r||!n.isObjectLiteralExpression(r)?{}:d(r)},T=8,l=(i,e=0)=>{if(e>T)return;if(n.isCallExpression(i))return i;if(n.isParenthesizedExpression(i)||n.isAsExpression(i)||n.isSatisfiesExpression(i)||n.isNonNullExpression(i))return l(i.getExpression(),e+1);if(!n.isIdentifier(i)&&!n.isPropertyAccessExpression(i))return;const t=i.getSymbol()?.getValueDeclaration();return t?p(t,e+1):void 0},p=(i,e)=>{if(n.isVariableDeclaration(i)||n.isPropertyAssignment(i)){const t=i.getInitializer();return t?l(t,e):void 0}if(n.isShorthandPropertyAssignment(i)){const t=i.getValueSymbol()?.getValueDeclaration();return t?p(t,e+1):void 0}if(n.isBindingElement(i)){const t=i.getPropertyNameNode()?.getText()??i.getName(),o=i.getFirstAncestorByKind(b.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return o?p(o,e+1):void 0}},k=i=>{const e=i.getNameNode();if(n.isObjectBindingPattern(e)){const s=[];for(const o of e.getElements()){const a=l(o.getNameNode());a&&s.push([o.getName(),a])}return s}const t=i.getInitializer(),r=t&&(n.isCallExpression(t)?t:l(t));return r?[[i.getName(),r]]:[]},V=i=>{const e=E(i);if(e){if(e.receiver){const t=L(e.receiver),r=C(e.receiver);return{args:z(e.receiver),...t?{expose:t}:{},kind:e.kind,...r?{output:r}:{},returnType:F(i),visibility:e.visibility}}return e.lifecycle?{args:{},kind:e.kind,lifecycle:e.lifecycle,returnType:"void",visibility:e.visibility}:{args:I(i),kind:e.kind,returnType:N(i),visibility:e.visibility}}},y=(i,e,t)=>{const r=V(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}:{}}},w=(i,e)=>{const t=[];for(const r of i.getExportAssignments()){if(r.isExportEquals())continue;const s=l(r.getExpression()),o=s?y(s,"default",e):void 0;o&&t.push(o)}return t},D=(i,e)=>{const t=[];for(const r of i.getVariableStatements())if(r.isExported())for(const s of r.getDeclarations())for(const[o,a]of k(s)){const c=y(a,o,e);c&&t.push(c)}return t.push(...w(i,e)),t},j=i=>{const e=new Map;for(const t of i){const r=x(t.filePath),s=e.get(r);if(s&&s!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${s}" and "${t.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[s,t.filePath],status:500});e.set(r,t.filePath)}},K=(i,e)=>{const t=h(e),r=[];for(const s of t){const o=i.getSourceFile(s)??i.addSourceFileAtPath(s),a=P(e,s);r.push(...D(o,a))}return r.sort((s,o)=>`${s.filePath}:${s.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),j(r),r};export{K as default};
1
+ import{s as x}from"./paths-C-9fwEgQ.mjs";import{listLunoraSourceFiles as h,lunoraRelativePath as P}from"./listLunoraSourceFiles-lHrzFhbX.mjs";import{b as f,c as E}from"./classify-procedure-call-C5BOBVM7.mjs";import{Node as n,SyntaxKind as b}from"ts-morph";import{p as A,a as d}from"./parse-validator-CMV0eq2a.mjs";import{u as v}from"./unwrap-handler-return-CmIWbykC.mjs";const N=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return"unknown";const t=e.getProperty("handler");if(!t||!n.isPropertyAssignment(t))return"unknown";const r=t.getInitializer();return!r||!(n.isArrowFunction(r)||n.isFunctionExpression(r))?"unknown":v(r)},F=i=>{const e=i.getArguments()[0];return!e||!(n.isArrowFunction(e)||n.isFunctionExpression(e))?"unknown":v(e)},z=i=>{let e={};for(const t of f(i)){if(t.name!=="input")continue;const r=t.call.getArguments()[0];r&&n.isObjectLiteralExpression(r)&&(e={...d(r),...e})}return e},C=i=>{const e=f(i).find(r=>r.name==="output");if(!e)return;const t=e.call.getArguments()[0];return t&&n.isExpression(t)?A(t):void 0},u=(i,e)=>{const t=i.getProperty(e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isStringLiteral(r)?r.getLiteralValue():void 0},m=(i,e)=>{const t=i.getProperty(e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isNumericLiteral(r)?r.getLiteralValue():void 0},O=i=>{const e=i.getProperty("cache");if(e===void 0||!n.isPropertyAssignment(e))return;const t=e.getInitializer();if(t===void 0||!n.isObjectLiteralExpression(t))return;const r=u(t,"scope"),s=m(t,"maxAge"),o=m(t,"staleWhileRevalidate"),a=u(t,"tag"),c=u(t,"vary"),g={...s===void 0?{}:{maxAge:s},...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},S=i=>{if(i===void 0||!n.isObjectLiteralExpression(i))return{};const e=O(i),t=i.getProperty("rest");return t!==void 0&&n.isPropertyAssignment(t)?{...e===void 0?{}:{cache:e},rest:t.getInitializer()?.getText()==="true"}:e===void 0?{}:{cache:e}},L=i=>{const e=f(i).find(t=>t.name==="expose");return e?S(e.call.getArguments()[0]):void 0},I=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return{};const t=e.getProperty("args");if(!t||!n.isPropertyAssignment(t))return{};const r=t.getInitializer();return!r||!n.isObjectLiteralExpression(r)?{}:d(r)},T=8,l=(i,e=0)=>{if(e>T)return;if(n.isCallExpression(i))return i;if(n.isParenthesizedExpression(i)||n.isAsExpression(i)||n.isSatisfiesExpression(i)||n.isNonNullExpression(i))return l(i.getExpression(),e+1);if(!n.isIdentifier(i)&&!n.isPropertyAccessExpression(i))return;const t=i.getSymbol()?.getValueDeclaration();return t?p(t,e+1):void 0},p=(i,e)=>{if(n.isVariableDeclaration(i)||n.isPropertyAssignment(i)){const t=i.getInitializer();return t?l(t,e):void 0}if(n.isShorthandPropertyAssignment(i)){const t=i.getValueSymbol()?.getValueDeclaration();return t?p(t,e+1):void 0}if(n.isBindingElement(i)){const t=i.getPropertyNameNode()?.getText()??i.getName(),o=i.getFirstAncestorByKind(b.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return o?p(o,e+1):void 0}},k=i=>{const e=i.getNameNode();if(n.isObjectBindingPattern(e)){const s=[];for(const o of e.getElements()){const a=l(o.getNameNode());a&&s.push([o.getName(),a])}return s}const t=i.getInitializer(),r=t&&(n.isCallExpression(t)?t:l(t));return r?[[i.getName(),r]]:[]},V=i=>{const e=E(i);if(e){if(e.receiver){const t=L(e.receiver),r=C(e.receiver);return{args:z(e.receiver),...t?{expose:t}:{},kind:e.kind,...r?{output:r}:{},returnType:F(i),visibility:e.visibility}}return e.lifecycle?{args:{},kind:e.kind,lifecycle:e.lifecycle,returnType:"void",visibility:e.visibility}:{args:I(i),kind:e.kind,returnType:N(i),visibility:e.visibility}}},y=(i,e,t)=>{const r=V(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}:{}}},w=(i,e)=>{const t=[];for(const r of i.getExportAssignments()){if(r.isExportEquals())continue;const s=l(r.getExpression()),o=s?y(s,"default",e):void 0;o&&t.push(o)}return t},D=(i,e)=>{const t=[];for(const r of i.getVariableStatements())if(r.isExported())for(const s of r.getDeclarations())for(const[o,a]of k(s)){const c=y(a,o,e);c&&t.push(c)}return t.push(...w(i,e)),t},j=i=>{const e=new Map;for(const t of i){const r=x(t.filePath),s=e.get(r);if(s&&s!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${s}" and "${t.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[s,t.filePath],status:500});e.set(r,t.filePath)}},K=(i,e)=>{const t=h(e),r=[];for(const s of t){const o=i.getSourceFile(s)??i.addSourceFileAtPath(s),a=P(e,s);r.push(...D(o,a))}return r.sort((s,o)=>`${s.filePath}:${s.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),j(r),r};export{K as default};
@@ -1 +1 @@
1
- import{Node as i}from"ts-morph";import{p as m,a as l}from"./parse-validator-CMV0eq2a.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./listLunoraSourceFiles-BvqYMy81.mjs";import{u as f}from"./unwrap-handler-return-CmIWbykC.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};
1
+ import{Node as i}from"ts-morph";import{p as m,a as l}from"./parse-validator-CMV0eq2a.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./listLunoraSourceFiles-lHrzFhbX.mjs";import{u as f}from"./unwrap-handler-return-CmIWbykC.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-C34F31Vm.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-BvqYMy81.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};
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-lHrzFhbX.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-lHrzFhbX.mjs";import"./classify-procedure-call-C5BOBVM7.mjs";import{d as p}from"./index-D322boXY.mjs";export{p as default};
@@ -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-BvqYMy81.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
+ 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-lHrzFhbX.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-BvqYMy81.mjs";import{c as f}from"./classify-procedure-call-CRm5Etni.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};
1
+ import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as l,handlerOf as d}from"./listLunoraSourceFiles-lHrzFhbX.mjs";import{c as f}from"./classify-procedure-call-C5BOBVM7.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-C3PDsG0y.mjs";import"./listLunoraSourceFiles-lHrzFhbX.mjs";export{a as default};
@@ -0,0 +1 @@
1
+ import{d as r}from"./context-property-calls-C34F31Vm.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
@@ -1 +1 @@
1
- import{Node as o}from"ts-morph";import{listLunoraSourceFiles as d,lunoraRelativePath as x,stringPropertyOf as c}from"./listLunoraSourceFiles-BvqYMy81.mjs";import{e as h}from"./exported-procedure-chains-Cmt3Pr92.mjs";import{r as A}from"./chain-DboeOxBl.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};
1
+ import{Node as o}from"ts-morph";import{listLunoraSourceFiles as d,lunoraRelativePath as x,stringPropertyOf as c}from"./listLunoraSourceFiles-lHrzFhbX.mjs";import{e as h}from"./exported-procedure-chains-CH_Ce-wL.mjs";import{r as A}from"./chain-B1V7k_Eb.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};
@@ -1 +1 @@
1
- import{Node as o}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as u,tablesAccessedIn as d}from"./listLunoraSourceFiles-BvqYMy81.mjs";import{c as p}from"./classify-procedure-call-CRm5Etni.mjs";import{r as m}from"./chain-DboeOxBl.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};
1
+ import{Node as o}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as u,tablesAccessedIn as d}from"./listLunoraSourceFiles-lHrzFhbX.mjs";import{c as p}from"./classify-procedure-call-C5BOBVM7.mjs";import{r as m}from"./chain-B1V7k_Eb.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};
@@ -1 +1 @@
1
- import{listLunoraSourceFiles as l}from"./listLunoraSourceFiles-BvqYMy81.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
+ import{listLunoraSourceFiles as l}from"./listLunoraSourceFiles-lHrzFhbX.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-BvqYMy81.mjs";import{w as d}from"./classify-procedure-call-CRm5Etni.mjs";import{e as m}from"./exported-procedure-chains-Cmt3Pr92.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
+ import{Node as u}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as p,stringPropertyOf as l}from"./listLunoraSourceFiles-lHrzFhbX.mjs";import{w as d}from"./classify-procedure-call-C5BOBVM7.mjs";import{e as m}from"./exported-procedure-chains-CH_Ce-wL.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-CRm5Etni.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
+ import{Node as a}from"ts-morph";import{c as n}from"./classify-procedure-call-C5BOBVM7.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-BvqYMy81.mjs";import{w as g,c as p}from"./classify-procedure-call-CRm5Etni.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};
1
+ import{Node as r}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as m,tablesAccessedIn as d}from"./listLunoraSourceFiles-lHrzFhbX.mjs";import{w as g,c as p}from"./classify-procedure-call-C5BOBVM7.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 A,lstatSync as P,statSync as b}from"node:fs";import{dirname as v,join as g,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=g(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(g(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(g(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),M=(t,e,s)=>w(t,C(e),s),X=t=>{for(const e of t.getAncestors())if(r.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0)return e.getName();return""},Y=(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},q=(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"]),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()}}},u=(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():""},G=(t,e,s)=>{const n=new Set,i=new Set;for(const o of t.getDescendantsOfKind(m.CallExpression))if(u(o,e)){const a=d(o);a!==""&&n.add(a)}else if(u(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},J=t=>{const e=j(t);return e&&r.isCallExpression(e)?e:void 0},Q=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},U=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,M as collectSecurityCallRows,Q as defaultExportExpression,X as enclosingExportName,Y as handlerOf,et as isContextIdentifier,p as isDatabaseAccessor,U as limitNameOf,h as listLunoraSourceFiles,C as listSecurityScanFiles,f as lunoraRelativePath,tt as objectLiteralFromCallbackBody,q as propertyInitializer,H as readTargetOf,st as stringPropertyFor,Z as stringPropertyOf,d as tableArgumentOf,G as tablesAccessedIn,j as unwrapExpression,J as unwrapToCallExpression};
@@ -1 +1 @@
1
- import{Node as r,SyntaxKind as f}from"ts-morph";import{listLunoraSourceFiles as P,lunoraRelativePath as h,isDatabaseAccessor as A}from"./listLunoraSourceFiles-BvqYMy81.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};
1
+ import{Node as r,SyntaxKind as f}from"ts-morph";import{listLunoraSourceFiles as P,lunoraRelativePath as h,isDatabaseAccessor as A}from"./listLunoraSourceFiles-lHrzFhbX.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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.162",
3
+ "version": "1.0.0-alpha.164",
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.114",
50
- "@lunora/agent": "1.0.0-alpha.93",
50
+ "@lunora/agent": "1.0.0-alpha.94",
51
51
  "@lunora/container": "1.0.0-alpha.47",
52
52
  "@lunora/errors": "1.0.0-alpha.34",
53
53
  "@lunora/platform": "1.0.0-alpha.27",
54
54
  "@lunora/queue": "1.0.0-alpha.50",
55
55
  "@lunora/scheduler": "1.0.0-alpha.57",
56
56
  "@lunora/values": "1.0.0-alpha.42",
57
- "@lunora/workflow": "1.0.0-alpha.47",
57
+ "@lunora/workflow": "1.0.0-alpha.48",
58
58
  "jsonc-parser": "^3.3.1",
59
59
  "quicktype-core": "^26.0.0",
60
60
  "ts-morph": "^28.0.0"
@@ -1,9 +0,0 @@
1
- import{existsSync as P,mkdirSync as ls,readFileSync as Pt,writeFileSync as us,rmSync as ds}from"node:fs";import{join as f,dirname as Z}from"node:path";import{performance as me}from"node:perf_hooks";import{runAdvisor as fs}from"@lunora/advisor";import{LunoraError as k}from"@lunora/errors";import{SyntaxKind as l,Node as i,Project as et}from"ts-morph";import{serializeSchemaSnapshot as gs}from"./SCHEMA_SNAPSHOT_VERSION-CWESEYLi.mjs";import{toAdvisorContext as ps}from"./formatAdvisories-CkEu1eye.mjs";import{s as ms}from"./paths-C-9fwEgQ.mjs";import{discoverAgents as hs}from"./AGENTS_FILENAME-CRdh_pOr.mjs";import{discoverContainers as xs}from"./CONTAINERS_FILENAME-BssQL6eI.mjs";import Es from"./discoverCrons-c0ig327z.mjs";import{diagnosticAt as oe}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as ie}from"./module-specifiers-WF8iAydP.mjs";import{C as he,n as It,i as vs,f as Ss,j as ys,b as As,c as Ns,l as bs,e as Ps,o as Is,d as ws,k as Ts,g as Cs,p as Fs,m as Os,a as Rs,h as Ls}from"./emit-BNdsZPcd.mjs";import{listLunoraSourceFiles as m,unwrapExpression as V,lunoraRelativePath as v,collectCallRows as w,collectSecurityCallRows as Ds,propertyInitializer as b,listSecurityScanFiles as wt,limitNameOf as Tt,isContextIdentifier as Se,handlerOf as ks,isDatabaseAccessor as M,readTargetOf as Ct,enclosingExportName as Ms}from"./listLunoraSourceFiles-BvqYMy81.mjs";import Ks from"./readPackageDependencies-C6h6FZuP.mjs";import{discoverQueues as _s}from"./QUEUES_FILENAME-CIfuMMG3.mjs";import{discoverSandboxUsage as zs}from"./discoverSandboxUsage-BJHLHZR_.mjs";import Us from"./discoverStorageRulesMetadata-CUa2Dtb4.mjs";import{discoverWorkflows as Bs}from"./WORKFLOWS_FILENAME-CSqONfHS.mjs";import{gatePlatformFeatures as $s,resolveCodegenTarget as qs}from"./DEFAULT_TARGET-lPq34YeN.mjs";import{i as R,a as _,e as E,r as js,b as Vs,s as ae,c as Ws,f as Hs,d as Gs}from"./queries-D8DheHbi.mjs";import{a as y,c as z,d as Ft,e as Ys}from"./classify-procedure-call-CRm5Etni.mjs";import Xs from"./discoverAuthApiCalls-B5Qmjmyk.mjs";import tt from"./discoverFunctions-DeuEs6Ce.mjs";import{i as Qs,r as Zs,e as Js}from"./unwrap-handler-return-CmIWbykC.mjs";import st from"./discoverHttpRoutes-zWSSyyOj.mjs";import en from"./discoverHyperdriveCalls-C6kV2CPz.mjs";import tn from"./discoverInserts-BB7o_8pU.mjs";import{m as Pe,a as ee,s as Ot,d as sn}from"./index-BsVoa-4F.mjs";import{e as Rt}from"./exported-procedure-chains-Cmt3Pr92.mjs";import nn from"./discoverMigrations-CQjGLKW-.mjs";import{MUTATORS_FILENAME as rn,isDefineMutatorCallee as on,discoverMutators as nt}from"./MUTATORS_FILENAME-DHX1qUP5.mjs";import an from"./discoverNondeterministicCalls-B07wjsd2.mjs";import{discoverNotifyConfig as cn,discoverNotifyCalls as ln}from"./NOTIFY_FILENAME-BH0djo6F.mjs";import un from"./discoverR2sqlCalls-CuHe5smg.mjs";import dn from"./discoverRlsProcedures-DXdr9YHi.mjs";import fn from"./discoverRlsMetadata-CXWVNLk4.mjs";import gn from"./discoverSchema-C4znXEB-.mjs";import{secretKindOf as pn,redact as mn,isHeuristicSecretKind as hn,isSecretishName as xn}from"./redact-Cy14LEnc.mjs";import{discoverShapes as En}from"./SHAPES_FILENAME-DhZ3JkkH.mjs";import{emitApp as vn}from"./emitApp-CxmA4W3C.mjs";import{buildOpenApiDocument as Sn,emitOpenApiModule as yn}from"./buildOpenApiDocument-qYjkmRTX.mjs";import{buildOpenRpcDocument as An,emitOpenRpcModule as Nn}from"./OPENRPC_VERSION-BgLkvCYK.mjs";import{s as bn}from"./parse-validator-CMV0eq2a.mjs";import{buildSchemaSnapshot as Pn}from"./SchemaSnapshotParseError-yrVM8bTa.mjs";const rt=(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 k("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})}}},In=(e,t={})=>{const{hasVectors:s=!0,scheduler:n=!1,storage:o=!1}=t,r=[],a=e.tables.filter(c=>c.shardMode==="global");return a.some(c=>c.globalBackend!=="hyperdrive")&&r.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),a.some(c=>c.globalBackend==="hyperdrive")&&r.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&&r.push({name:"@lunora/scheduler",reason:"a declared cron (or `ctx.scheduler` use) makes `_generated/app.ts` import `createScheduler`"}),o&&r.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&&r.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/shard.ts` import `@lunora/bindings/vectors`"}),r},wn=(e,t,s={})=>{if(t===void 0)return;const n=In(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 k("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.`)},Tn="env.ts",Cn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return ie(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},Fn=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&&ie(n.getModuleSpecifierValue())}return!1},On=e=>{if(i.isIdentifier(e))return Cn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&Fn(t)}return!1},Rn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!On(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw oe(r,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},Ln=(e,t)=>{const s=f(t,Tn);if(!P(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=Rn(n);if(o.length!==0){if(o.length>1)throw oe(n,`lunora/env.ts declares ${o.length.toString()} defineEnv() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},ot="ctx",Lt=e=>{const t=new Set,s=new Set([ot]),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())!==ot)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},Dn=(e,t)=>{const s=Object.fromEntries(he.map(n=>[n.key,!1]));for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=new Set(o.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=Lt(o);for(const c of he)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(he.every(c=>s[c.key]))break}return s},Dt="identity.ts",kn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return ie(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Mn=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&&ie(n.getModuleSpecifierValue())}return!1},Kn=e=>{if(i.isIdentifier(e))return kn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&Mn(t)}return!1},_n=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!Kn(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw oe(r,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},zn=(e,t)=>{const s=f(t,Dt);if(!P(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=_n(n);if(o.length!==0){if(o.length>1)throw oe(n,`lunora/identity.ts declares ${o.length.toString()} defineIdentity() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},Un=(e,t)=>{const s=V(t);if(s===void 0||!i.isIdentifier(s))return s;const n=s.getText();return V(e.getDescendantsOfKind(l.VariableDeclaration).find(o=>o.getName()===n)?.getInitializer())},Bn=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||V(s)?.getText()!=="false"}),$n=(e,t)=>{const s={durableStreams:!1,secrets:!1};for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);if(s.secrets||(s.secrets=Lt(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=>Bn(Un(o,u)))})),s.durableStreams&&s.secrets)break}return s},qn=(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 k("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${a} and agent "${r.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=n.get(r.bindingName);if(c!==void 0)throw new k("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${r.bindingName}": produced by both ${c} and agent "${r.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const u=o.get(r.className);if(u!==void 0)throw new k("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${u} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},jn=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:o}=e,r=zn(s,t),a=Ln(s,t),c=Bs(s,t),u=_s(s,t),d=hs(s,t);qn(c,d);const S=xs(s,t),x=Us(s,t),I=Es(s,t,c,d),p=$n(s,t),N=zs(s,t),C=Dn(s,t);C.browser=C.browser||N.usesSandboxBrowser;const L=$s(C,qs(n,e.target),{agents:d.length>0,commitOrderedTables:o.tables.some(g=>g.commitOrdered===!0),cronTriggers:I.length>0,crossShardFanout:o.tables.some(g=>typeof g.shardMode=="object"),durableStreams:p.durableStreams,globalTables:o.tables.some(g=>g.shardMode==="global"),queues:u.length>0,secrets:p.secrets,vectorStore:o.vectorIndexes.length>0}),A=L.usage,D=L.signals.vectorStore!==!1,U=Ks(n),$=U??new Set,H=$.has("lunorash");wn(o,U,{hasVectors:D,scheduler:A.scheduler||I.length>0,storage:A.storage||x.rules.length>0||Object.keys(It(o)).length>0});const K=P(f(t,"flags.ts")),F=P(f(t,"notify.ts"));return{agents:d,containers:S,crons:I,dataModelContent:Ss(o),declaredDependencies:U,dependencies:$,env:a,featureUsage:A,hasFlags:K,hasNotify:F,identity:r,platformGate:L,queues:u,serverContent:vs({agents:d,containers:S,env:a,hasAccessFacade:A.access,hasAi:A.ai,hasAnalytics:A.analytics,hasBrowser:A.browser,hasVectors:D,hasFlags:K,hasHyperdrive:A.hyperdrive,hasImages:A.images,hasKv:A.kv,hasNotify:F,hasPayments:A.payments,hasPipelines:A.pipelines,hasR2sql:A.r2sql,hasX402:A.x402,identity:r,queues:u,schema:o,storageRuleBuckets:x.rules.map(g=>g.bucket),useUmbrella:H,workflows:c}),storageRulesMetadata:x,usesSandbox:N.usesSandboxBrowser||N.usesSandboxContainer||N.usesSandboxFs,useUmbrella:H,workflows:c}},kt=new Set(["delete","get","head","options","patch","post","put"]),Vn=new Set(["handler","stream"]),Wn=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,it=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Hn=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!kt.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()}},Gn=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)||kt.has(n.getName()))break;s=n.getExpression()}return Hn(s)},Yn=e=>{for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression))if(it.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&it.has(s.getText()))return!0}return!1},Xn=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||!Vn.has(n.getName()))return;const o=Gn(s);if(!o||!Wn.test(o.path))return;const r=s.getArguments()[0],a=r!==void 0&&(i.isArrowFunction(r)||i.isFunctionExpression(r))&&Yn(r);return{exportName:e.getName(),file:t,method:o.method,path:o.path,usesGuard:a}},Qn=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=Xn(o,t);r&&s.push(r)}return s},Zn=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Qn(o,v(t,n)))}return s},Jn=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",er=(e,t)=>{if(!Jn(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!R(s)||_(s)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},tr=(e,t)=>w(e,t,er),sr=new Set(["generateText","streamText"]),nr=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"]}],or=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}`},ir=e=>{for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=or(t);if(s!==void 0)return s}},ar=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},cr=e=>{if(js(e))return!0;const t=ar(e);return t.size===0?!1:e.getDescendantsOfKind(l.Identifier).some(s=>t.has(s.getText()))},lr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!nr.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&cr(s))return!0}return!1},ur=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=y(n.getExpression());if(o===void 0||!sr.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(y(c.getExpression())==="tool"&&(a=ir(c),a!==void 0))break;a!==void 0&&s.push({exportName:E(n),file:t,line:n.getStartLineNumber(),method:o,sideEffect:a,userInputDerived:lr(r)})}return s},dr=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ur(o,v(t,n)))}return s},fr=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},gr=(e,t)=>{if(!fr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!R(s)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},pr=(e,t)=>w(e,t,gr),Mt=e=>e.getProperties().some(t=>i.isSpreadAssignment(t)),mr=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer();return!n||!i.isObjectLiteralExpression(n)?{objects:[],opaque:!0}:{objects:[n],opaque:Mt(n)}},hr=e=>{const t=[];let s=!1,n=e;for(;i.isCallExpression(n);){const o=n.getExpression();if(!i.isPropertyAccessExpression(o))break;if(o.getName()==="input"){const r=n.getArguments()[0];r&&i.isObjectLiteralExpression(r)?(t.push(r),s||=Mt(r)):s=!0}n=o.getExpression()}return{objects:t,opaque:s}},Kt=(e,t)=>t?hr(t):mr(e),xr=e=>e.flatMap(t=>t.getProperties().filter(s=>i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)).map(s=>s.getName())),Er=new Set(["check","length","max"]),ye=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!(!i.isPropertyAccessExpression(t)||t.getExpression().getText()!=="v"))return t.getName()},vr=e=>[e,...e.getDescendants()].filter(t=>ye(t)!==void 0),Sr=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(Er.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=vr(r),c=o.getName();a.some(u=>ye(u)==="any")?t.push(c):a.some(u=>ye(u)==="string"&&!Sr(u))&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Ar=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=z(s);if(n?.visibility!=="public")return;const{objects:o}=Kt(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}},Nr=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=Ar(o,t);r&&s.push(r)}return s},br=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Nr(o,v(t,n)))}return s},xe=e=>e?.getKind()===l.TrueKeyword,Pr=e=>e?.getKind()===l.FalseKeyword,Ir=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,wr=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Tr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&y(t.getExpression())==="scim"),Cr=e=>e!==void 0&&i.isCallExpression(e)&&wr.has(y(e.getExpression())??""),Fr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),Or=e=>{const t=b(e,"advanced"),s=b(e,"emailAndPassword"),n=b(e,"session");return{analyzable:!0,disableCsrfCheck:xe(b(t,"disableCSRFCheck")),emailPasswordEnabled:xe(b(s,"enabled")),requireEmailVerification:xe(b(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Tr(b(e,"plugins"))&&Cr(b(e,"database")),secureCookiesDisabled:Pr(b(t,"useSecureCookies")),sessionFreshAgeZero:Ir(b(n,"freshAge")),trustedOriginsWildcard:Fr(b(e,"trustedOrigins"))}},Rr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Lr=(e,t)=>{if(y(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?Or(s):Rr();return{exportName:E(e),file:t,line:e.getStartLineNumber(),...o}},Dr=(e,t)=>Ds(e,t,Lr),kr=(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},Mr=(e,t,s)=>{const n=kr(e.getExpression(),s);if(n===void 0)return;const o=e.getArguments()[s.argIndex];if(!(!o||!R(o)||_(o))&&!(s.requireUnmodifiedReach===!0&&!Vs(o)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:n}},Kr=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression)){const r=Mr(o,t,s);r&&n.push(r)}return n},ce=(e,t,s)=>{const n=[];for(const o of m(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...Kr(r,v(t,o),s))}return n},_r=new Set(["content","pdf","scrape","screenshot"]),zr=(e,t)=>ce(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:_r}),Ur=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Br=new Set(["RateLimiter"]),$r=new Set(["extend"]),at="lunora",qr=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],_t=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}},Ae=e=>e&&i.isObjectLiteralExpression(e)?_t(e):{analyzable:!1,presentKeys:[],trueKeys:[]},jr=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!i.isReturnStatement(s))return;const n=s.getExpression();return n!==void 0&&i.isObjectLiteralExpression(n)?n:void 0},Vr=e=>{if(i.isObjectLiteralExpression(e))return e;if(i.isParenthesizedExpression(e)){const t=e.getExpression();return i.isObjectLiteralExpression(t)?t:void 0}return i.isBlock(e)?jr(e):void 0},Wr=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&Vr(t.getBody());return s?_t(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Hr=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=y(n.getExpression());o!==void 0&&(Ur.has(o)?s.push({callee:o,file:t,line:n.getStartLineNumber(),...Ae(n.getArguments()[0])}):$r.has(o)&&s.push({callee:o,file:t,line:n.getStartLineNumber(),...Wr(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(l.NewExpression)){const o=y(n.getExpression());o===void 0||!Br.has(o)||s.push({callee:o,file:t,line:n.getStartLineNumber(),...Ae(n.getArguments()[0])})}return s},Gr=(e,t)=>{for(const s of qr){const n=f(t,s);if(!P(n))continue;const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=[];for(const a of o.getDescendantsOfKind(l.CallExpression))y(a.getExpression())===at&&r.push({callee:at,file:s,line:a.getStartLineNumber(),...Ae(a.getArguments()[0])});return r}return[]},Yr=(e,t)=>{const s=[];for(const{displayPath:n,filePath:o}of wt(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);s.push(...Hr(r,n))}return s.push(...Gr(e,Z(t))),s},ct="ctx.containers.",Xr=e=>{if(!e.startsWith(ct))return!1;const t=e.slice(ct.length);return t.length>0&&!t.includes(".")},Qr=(e,t)=>ce(e,t,{argIndex:0,matchReceiver:Xr,methods:new Set(["get"])}),Zr=new Set(["allow","deny","setAllowed"]),Jr=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())},eo=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!Jr(e)))return{detail:"enableInternet: true",exportName:E(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},to=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!Zr.has(s.getName()))return;const n=s.getExpression();if(!(!i.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),exportName:E(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},so=(e,t)=>eo(e,t)??to(e,t),no=(e,t)=>w(e,t,so),ro=new Set(["defineExportSink","r2Sink","webhookExportSink"]),oo=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return ro.has(s)?s:void 0},io=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}},ao=(e,t)=>{const s=[];for(const{displayPath:n,filePath:o}of wt(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);for(const a of r.getDescendantsOfKind(l.CallExpression)){const c=oo(a);if(c===void 0)continue;const u=a.getArguments()[0],d=u&&i.isObjectLiteralExpression(u)?io(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},co=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),lo=new Set(["dbRateLimit","rateLimit"]),uo=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&i.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===l.TrueKeyword},fo=(e,t)=>{const s=y(e.getExpression());if(s===void 0)return;const n=co.get(s);if(n!==void 0)return{callee:s,exportName:E(e),failOpen:uo(e.getArguments()[n]),file:t,limitName:lo.has(s)?Tt(e):"",line:e.getStartLineNumber()}},go=(e,t)=>w(e,t,fo),po=new Set(["boolean","number","object","string"]),mo=e=>{const t=e.getName();if(!po.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="flags"&&Se(s.getExpression()))return t;const n=s.getExpression();if(s.getName()==="details"&&i.isPropertyAccessExpression(n)&&n.getName()==="flags"&&Se(n.getExpression()))return t},ho=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=mo(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},xo=(e,t)=>{const s=new Map;for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getDescendantsOfKind(l.CallExpression)){const a=ho(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))},Eo=e=>{const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const s=z(t);if(s?.kind!=="query")return;const n=ks(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},lt=e=>{const t=e.getParent();return t&&i.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},vo=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!i.isIdentifier(t)||t.getText()!=="ctx")return;const s=lt(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=lt(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},So=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const o=vo(n);o!==void 0&&s.push({callee:o,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},yo=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=Eo(o);r&&s.push(...So(r,t))}return s},Ao=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...yo(o,v(t,n)))}return s},No=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Se(t.getExpression())},bo=e=>{if(e?.getKind()===l.TrueKeyword)return!0;if(e?.getKind()===l.FalseKeyword)return!1},Po=(e,t)=>{if(!No(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const o=s.getLiteralValue(),r=bo(n);if(!(o.length===0||r===void 0))return{defaultValue:r,exportName:E(e),file:t,key:o,line:e.getStartLineNumber()}},Io=(e,t)=>w(e,t,Po),wo=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"||Qs(r))return;const a=e.getSourceFile().getFilePath();return Zs(o,e,a)?Js(o,e,a,0,new Set):r},To=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Co=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Fo=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression))To(a)&&s.push({file:r,indexName:Co(a),line:a.getStartLineNumber()})}return s},W=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,zt=e=>{const t=e.getArguments()[0],s=W(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)?W(n.getInitializer()):void 0},Oo=new Set(["delete","get","head","options","patch","post","put"]),Ro=new Set(["handler","stream"]),Lo=new Set(["runAction","runMutation"]),Do=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),te=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,ut=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const n=s.getNameNode();if(t)return i.isIdentifier(n)?n.getText():void 0;if(i.isObjectBindingPattern(n)){for(const o of n.getElements())if((o.getPropertyNameNode()?.getText()??o.getNameNode().getText())==="ctx"){const a=o.getNameNode();return i.isIdentifier(a)?a.getText():void 0}}},dt=(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(Lo.has(a)&&te(c,t))return a;if(Do.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&te(c.getExpression(),t))return`db.${a}`}},ft=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(l.PropertyAccessExpression))if(n.getName()==="auth"&&te(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(l.VariableDeclaration)){const o=n.getNameNode();if(!(!i.isObjectBindingPattern(o)||!te(n.getInitializer(),t))){for(const r of o.getElements())if((r.getPropertyNameNode()?.getText()??r.getNameNode().getText())==="auth")return!0}}return!1},ko=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Ro.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(Oo.has(o)){const r=n.getExpression();return i.isIdentifier(r)&&r.getText()==="httpRoute"?o.toUpperCase():void 0}s=n.getExpression()}},Mo=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=W(e.getArguments()[0]),u=c&&ut(c,!0);if(!c||u===void 0)return;const d=dt(c,u);return d===void 0?void 0:{exportName:E(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ft(c,u),sideEffect:d}}const n=ko(e);if(n===void 0)return;const o=W(e.getArguments()[0]),r=o&&ut(o,!1);if(!o||r===void 0)return;const a=dt(o,r);return a===void 0?void 0:{exportName:E(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:ft(o,r),sideEffect:a}},Ko=(e,t)=>w(e,t,Mo),_o=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),zo=new Set(["append","set"]),Ut=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",gt=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(l.CallExpression)]:e.getDescendantsOfKind(l.CallExpression)).some(n=>_o.has(y(n.getExpression())??"")&&Hs(n,t)),Uo=(e,t)=>{if(gt(e,t))return!0;const s=ae(e);return s!==void 0&&gt(s,t)},Ne=(e,t)=>Ws(e,t)&&!Uo(e,t),Bo=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=ae(e);return t!==void 0&&i.isNewExpression(t)&&y(t.getExpression())==="Headers"},se=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=ae(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},Ie=(e,t,s)=>{for(const n of e.getProperties())if(i.isPropertyAssignment(n)){const o=n.getInitializer();o!==void 0&&Ne(o,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:Ut(n.getNameNode()),line:o.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(n)){const o=n.getNameNode();Ne(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=se(n.getExpression());o!==void 0&&Ie(o,t,s)}},Bt=(e,t)=>{const s=se(e);if(s===void 0)return;const n=s.getProperty("headers");if(n===void 0||!i.isPropertyAssignment(n))return;const o=se(n.getInitializer());o!==void 0&&Ie(o,"response-init",t)},$o=(e,t)=>{const s=y(e.getExpression());if(s==="Response")Bt(e.getArguments()[1],t);else if(s==="Headers"){const n=se(e.getArguments()[0]);n!==void 0&&Ie(n,"headers-ctor",t)}},qo=(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"){Bt(e.getArguments()[1],t);return}if(zo.has(n)&&Bo(o)){const r=e.getArguments()[1];r!==void 0&&Ne(r,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:Ut(e.getArguments()[0]),line:r.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},jo=(e,t)=>{for(const s of e.getDescendantsOfKind(l.NewExpression))$o(s,t);for(const s of e.getDescendantsOfKind(l.CallExpression))qo(s,t)},Vo=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=W(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 jo(n,{exportName:E(e),relativePath:t,requestName:r.getText(),rows:a}),a},Wo=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression))s.push(...Vo(n,t));return s},Ho=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Wo(o,v(t,n)))}return s},Go=new Set(["auth","context.auth","ctx.auth"]),Yo="userId",Xo=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},Qo=(e,t)=>{const s=f(t,Dt);if(!P(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const o of n.getDescendantsOfKind(l.CallExpression)){if(y(o.getExpression())!=="defineIdentity")continue;const[r]=o.getArguments();return r&&i.isObjectLiteralExpression(r)?Xo(r):void 0}},pt=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Go.has(e.getExpression().getText())?e:void 0},Zo=e=>{if(i.isPropertyAccessExpression(e)&&pt(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&pt(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},Jo=(e,t,s)=>{const n=[];for(const o of e.getDescendants()){const r=Zo(o);r!==void 0&&n.push({declared:r===Yo||s.has(r),exportName:E(o),file:t,key:r,line:o.getStartLineNumber()})}return n},ei=(e,t)=>{const s=Qo(e,t);if(s===void 0)return[];const n=[];for(const o of m(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...Jo(r,v(t,o),s))}return n},ti=(e,t)=>{if(y(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=b(s,"key");if(!(!n||!R(n)||_(n)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},si=(e,t)=>w(e,t,ti),ni=new Set(["delete","get","getRaw","getWithMetadata","put"]),ri=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return ce(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.kv"||r.startsWith("ctx.kv."),methods:ni}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},oi=new Set(["queue","send"]),mt=new Set(["bcc","cc","to"]),ii=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!oi.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},ai=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return mt.has(t.getName())&&R(n)&&!_(n)}if(!i.isPropertyAssignment(t)||!mt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&R(s)&&!_(s)}):!1,ci=(e,t)=>{const s=ii(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!ai(n)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s}},li=(e,t)=>w(e,t,ci),ui=e=>i.isPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?i.isComputedPropertyName(e.getNameNode()):!1,di=e=>i.isPropertyAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?ui(e):!0,$t=(e,t=!1)=>{for(const s of e.getProperties()){if(di(s))return!0;if(t)continue;if(!i.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!i.isObjectLiteralExpression(n)||$t(n,!0))return!0}return!1},fi=(e,t)=>{for(const s of m(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:o}of Rt(n))for(const r of Pe(o)){const a=r.getArguments()[0];if(a!==void 0&&(!i.isObjectLiteralExpression(a)||$t(a)))return!0}}return!1},gi=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const o=ee(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=ee(a);c!==void 0&&s.push({column:c,strategy:Ot(a),table:o})}}return s},pi=(e,t)=>{const s=new Map;for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:r}of Rt(o))for(const a of Pe(r))for(const c of gi(a)){const u=`${c.table}\0${c.column}`;s.has(u)||s.set(u,c)}}return{columns:[...s.values()]}},mi=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!i.isObjectLiteralExpression(n))return[];const o=[];for(const r of n.getProperties()){const a=ee(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=ee(u);if(d===void 0)continue;const S=Ot(u);S!=="custom"&&o.push({column:d,exportName:t,file:s,line:u.getStartLineNumber(),strategy:S,table:a})}}return o},hi=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?z(s):void 0;return n?.receiver?Pe(n.receiver).flatMap(o=>mi(o,e.getName(),t)):[]},xi=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...hi(c,r))}return s},Ei=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return M(s)},vi=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},Si=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==l.CallExpression)return;const s=t;return on(s.getExpression())?s:void 0},yi=e=>{const t=Si(e),s=t===void 0?void 0:vi(t);if(s===void 0)return[];const n=e.getNameNode(),o=i.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(l.CallExpression).filter(r=>Ei(r)).map(r=>({exportName:o,file:"lunora/mutators.ts",line:r.getStartLineNumber()}))},Ai=e=>e.getVariableDeclarations().flatMap(t=>yi(t)),Ni=(e,t)=>{const s=f(t,rn);if(!P(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Ai(n)},bi=new Set(["delete","get","patch"]),Pi=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Ii=new Set(["auth","identity","session","user"]),wi=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),Ti=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!M(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},Ci=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},Fi=(e,t)=>e.getDescendantsOfKind(l.Identifier).some(s=>s.getText()===t),Oi=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(l.ThrowStatement).length>0||e.getDescendantsOfKind(l.ReturnStatement).length>0,Ri=(e,t)=>e.getDescendantsOfKind(l.IfStatement).some(s=>Fi(s.getExpression(),t)&&Oi(s.getThenStatement())),Li=(e,t)=>{for(const s of e.getDescendantsOfKind(l.CallExpression)){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))continue;const o=n.getName();if(!bi.has(o))continue;const r=n.getExpression();if(!(M(r)||i.isPropertyAccessExpression(r)&&M(r.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&i.isIdentifier(c)&&c.getText()===t)return o}},Di=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},ki=e=>e.getDescendantsOfKind(l.CallExpression).some(t=>t.getArguments().some(s=>Di(s)==="ctx")),Mi=e=>e.getDescendantsOfKind(l.BinaryExpression).some(t=>wi.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),Ki=e=>{for(const t of e.getDescendantsOfKind(l.Identifier))if(Pi.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&Ii.has(t.getName()))return!0}return ki(e)||Mi(e)},_i=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=z(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const o=zt(s);if(o===void 0)return[];const r=n.receiver!==void 0&&Ft(n.receiver,"use","rls"),a=Ki(o),c=new Set,u=[];for(const d of o.getDescendantsOfKind(l.CallExpression)){const S=Ti(d);if(S===void 0)continue;const x=Ci(d);if(x===void 0||c.has(x)||!Ri(o,x))continue;const I=Li(o,x);I!==void 0&&(c.add(x),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:I,table:S,usesRls:r,visibility:n.visibility}))}return u},zi=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(..._i(c,r))}return s},Ui=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Bi=new Set(["insert","insertManyUnsafe","patch","replace"]),$i=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Bi.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},qi=(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},ji=(e,t,s,n)=>{const o=[];for(const r of e.getProperties()){let a,c;i.isPropertyAssignment(r)?(a=r.getName(),c=r.getInitializer()):i.isShorthandPropertyAssignment(r)&&(a=r.getName(),c=r.getNameNode()),!(a===void 0||c===void 0||!Ui.has(a))&&R(c)&&!_(c)&&o.push({exportName:E(s),field:a,file:n,line:s.getStartLineNumber(),method:t})}return o},Vi=(e,t)=>{const s=$i(e.getExpression());if(s===void 0)return[];const n=e.getArguments()[1];return n?qi(n,s).flatMap(o=>ji(o,s,e,t)):[]},Wi=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression))for(const r of Vi(o,t)){const a=s(r.exportName);n.push(a===void 0?r:{...r,visibility:a})}return n},Hi=(e,t,s=[])=>{const n=[],o=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));for(const r of m(t)){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=v(t,r);n.push(...Wi(a,c,u=>o.get(`${c}:${u}`)))}return n},Gi=["providerSubscriptionId","state"],Yi=["providerEventId","processedAt"],ht=(e,t)=>t.every(s=>s in e.shape),Xi=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&ht(t,Gi)&&ht(s,Yi)},Qi=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Zi=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Ji=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?Zi(t.getInitializer()):void 0},ea=(e,t)=>{const s=y(e.getExpression());if(s===void 0||!Qi.has(s))return;const[n]=e.getArguments(),o=n&&i.isObjectLiteralExpression(n)?Ji(n):void 0;return{callee:s,exportName:E(e),file:t,line:e.getStartLineNumber(),...o===void 0?{}:{toleranceSeconds:o}}},ta=(e,t)=>w(e,t,ea),sa=new Set(["defineQueue","defineWorkflow"]),na=new Set(["run","runAction","runMutation","runQuery"]),ra=new Set(["api","internal"]),oa=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},ia=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},qt=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},jt=(e,t)=>e===t||e.startsWith(`${t}.`),Vt=e=>{const t=e.getDescendantsOfKind(l.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},xt=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)},Wt=e=>{const t=e.getDescendantsOfKind(l.Identifier).filter(s=>xt(s));return i.isIdentifier(e)&&xt(e)&&t.push(e),t},aa=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(l.BindingElement).map(s=>s.getName())},ca=e=>{const t=qt(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},la=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:ca(e),o=new Set,r=a=>Vt(a).some(c=>n.some(u=>jt(c.getText(),u)))?!0:Wt(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 aa(a))o.add(u)}return{names:o,prefixes:n}},ua=(e,t)=>Vt(e).some(s=>t.prefixes.some(n=>jt(s.getText(),n)))?!0:Wt(e).some(s=>t.names.has(s.getText())),da=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)||!ra.has(s.getText())||t.length<2))return{exportName:n,file:t.slice(0,-1).join("/")}},fa=(e,t,s)=>{const n=qt(e,0);if(n===void 0)return[];const o=la(e,t,n),r=[];for(const a of e.getDescendantsOfKind(l.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!na.has(c.getName())||c.getExpression().getText()!==n)continue;const u=a.getArguments()[1];if(!u||!ua(u,o))continue;const d=da(a.getArguments()[0]);d!==void 0&&r.push({dispatchKind:t,file:s,handlerExport:E(a),line:a.getStartLineNumber(),targetExport:d.exportName,targetFile:d.file})}return r},ga=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=oa(n);if(o===void 0||!sa.has(o))continue;const r=ia(n);r!==void 0&&s.push(...fa(r,o==="defineQueue"?"queue":"workflow",t))}return s},pa=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ga(o,v(t,n)))}return s},Et={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},vt=new Set(["account","credential","member","passkey","session","user"]),ma=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),ha=e=>{const s=ma(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return vt.has(s)||vt.has(n)},xa=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Ea=(e,t)=>{const{objects:s,opaque:n}=Kt(e,t);return xr(s).some(o=>xa(o))?!0:n?void 0:!1},va=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Sa=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},J={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},ya=e=>{const t=Sa(e),s=t?y(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=va(t);return{...J,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in Et?{...J,[Et[s]]:!0}:J},Aa=e=>{const t={...J};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=ya(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},Na=new Set(["insert","insertMany","insertManyUnsafe","replace"]),ba=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Na.has(t.getName()))return!1;const s=t.getExpression();if(!M(s))return!1;const o=e.getArguments()[0];return!o||!(i.isStringLiteral(o)||i.isNoSubstitutionTemplateLiteral(o))?!1:ha(o.getLiteralText())},Pa=new Set(["create","runAfter","runAt","send","sendBatch"]),Ia=new Set(["queues","scheduler","workflows"]),wa=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Pa.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&Ia.has(s.getName())){const n=s.getExpression();if(i.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},Ta=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return M(s)},Ht=new Set(["generateObject","generateText","streamObject","streamText"]),Ca=e=>{const t=y(e.getExpression());return t!==void 0&&Ht.has(t)},Fa=e=>{const t=y(e.getExpression());if(t===void 0||!Ht.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")},Oa=new Set(["log","span","trace"]),Ra=new Set(["ai"]),La=new Set(["email","mail"]),Da=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),Ee=(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"}),ka=new Set([l.ArrowFunction,l.FunctionDeclaration,l.FunctionExpression,l.GetAccessor,l.MethodDeclaration,l.SetAccessor]),Ma=new Set(["every","filter","flatMap","forEach","map","some"]),Ka=new Set(["all","allSettled","race"]),_a=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(Ma.has(n))return t;const o=s.getExpression();if(i.isIdentifier(o)&&o.getText()==="Promise"&&Ka.has(n))return t},za=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(ka.has(t.getKind())){const s=_a(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},Ua=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}},Ba=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}},$a=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression)){if(!Da.has(n.getName()))continue;const o=n.getExpression();if(!i.isIdentifier(o)||o.getText()!=="ctx")continue;const r=Ba(n);r&&(t=!0,!za(r)&&!Ua(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},qa=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"}),St="lunora-advisor-exempt",ja=/^[\s*/]+/u,Va=/[\w-]/u,Wa=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(ja,"");if(!o.startsWith(St))continue;const r=o.slice(St.length);if(Va.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:""}},Ha=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}},Ga=(e,t)=>{const s=Ha(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)},Ya=e=>{let t=!1,s=!1,n=!1,o=!1,r=!1;for(const u of e.getDescendantsOfKind(l.CallExpression))if(ba(u)&&(r=!0),wa(u)&&(t=!0),Ta(u)&&(o=!0),Ca(u)&&(s=!0),Fa(u)&&(n=!0),r&&t&&o&&n)break;const{handlesErrors:a,reachesOutbound:c}=$a(e);return{callsMail:Ee(e,La),emitsEvent:Ee(e,Oa),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||Ee(e,Ra),throwsBareError:qa(e),unboundedAiGeneration:n,usesInsertManyUnsafe:o,writesUserTable:r}},Xa=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=z(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const o=n.receiver?Aa(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},r=Ga(e,s);return{...r?Ya(r):{},...Wa(e),...o,analyzableBody:r!==void 0,exportName:e.getName(),file:t,hasEmailArg:Ea(s,n.receiver),kind:n.kind,visibility:n.visibility}},Qa=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=Xa(o,t);r&&s.push(r)}return s},Za=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Qa(o,v(t,n)))}return s},Ja=new Set(["dbRateLimit","rateLimit"]),ec=e=>i.isArrowFunction(e)?e.getBody():e,tc=(e,t)=>{const s=y(e.getExpression());if(s===void 0||!Ja.has(s))return;const n=e.getArguments()[2];if(!n)return;const o=b(n,"key");if(!o)return;const r=ec(o);if(!(!R(r)||_(r)))return{callee:s,exportName:E(e),file:t,limitName:Tt(e),line:e.getStartLineNumber()}},sc=(e,t)=>w(e,t,tc),nc=new Set(["findFirst","findFirstOrThrow","findMany","get"]),rc=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!nc.has(t.getName()))return;const s=t.getExpression();if(M(s)){const n=e.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&M(s.getExpression()))return s.getName()},oc=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&M(s.getExpression())){const n=t.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},ic=e=>{let t=V(e)??e;for(;i.isAwaitExpression(t);)t=V(t.getExpression())??t.getExpression();return t},Gt=(e,t=!1)=>{const s=ic(e);if(i.isIdentifier(s)){if(t)return;const n=ae(s);return n===void 0?void 0:Gt(n,!0)}if(i.isCallExpression(s))return rc(s)??oc(s)},ac=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},cc=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=z(s);if(n?.kind!=="query")return[];const o=zt(s);if(o===void 0)return[];const r=n.receiver!==void 0&&Ys(n.receiver,"output"),a=n.receiver!==void 0&&Ft(n.receiver,"use","mask"),c=new Set,u=[];for(const d of ac(o)){const S=Gt(d);S===void 0||c.has(S)||(c.add(S),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:S,usesMask:a,usesOutput:r,visibility:n.visibility}))}return u},lc=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...cc(c,r))}return s},uc=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},dc=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?z(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Ct(r);if(a===void 0)continue;const c=uc(b(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},fc=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...dc(c,r))}return s},ne=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===l.PlusToken){const t=ne(e.getLeft()),s=ne(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},gc=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&&ne(t)!==void 0},pc=/(?:^|\/)__tests__\//u,mc=/\.(?:spec|test)$/u,hc=e=>pc.test(e)||mc.test(e),xc=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()}},Ec=(e,t,s)=>hn(e)?!hc(s)&&xn(xc(t)):!0,vc=(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(gc(r))continue;const a=ne(r);if(a===void 0)continue;const c=pn(a);if(c===void 0||!Ec(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:mn(a)}))}return s},Sc=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...vc(o,v(t,n)))}return s},yc=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?z(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Ct(r);if(a===void 0)continue;const c=b(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},Ac=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...yc(c,r))}return s},Nc=new Set(["query","unsafe"]),bc=e=>{if(!i.isPropertyAccessExpression(e)||!Nc.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"},Pc=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),Ic=e=>e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()??"<module>",wc=(e,t)=>{if(!bc(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Pc(s)))return{exportName:Ic(e),file:t,line:s.getStartLineNumber()}},Tc=(e,t)=>w(e,t,wc),Cc=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],Fc=e=>{for(const[t,s]of Cc)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},Oc=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getImportDeclarations()){const a=r.getModuleSpecifierValue(),c=Fc(a);c!==void 0&&s.push({file:v(t,n),line:r.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},Rc=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Lc=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return ce(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:Rc,requireUnmodifiedReach:!0}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},Dc=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),kc=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Mc=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=kc(o.getInitializer()));continue}(i.isShorthandPropertyAssignment(o)||i.isMethodDeclaration(o))&&t.push(o.getName())}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},Kc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=Dc.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},_c=(e,t)=>{const s=Kc(e.getExpression());if(s!==void 0)return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s.method,...Mc(e.getArguments()[s.optionsIndex])}},zc=(e,t)=>w(e,t,_c),Uc=(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")}),Bc=new Set(["RegisteredAction","RegisteredMutation","RegisteredQuery"]),we=e=>{const t=e.getType(),s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName();return s!==void 0&&Bc.has(s)?s:void 0},Yt=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},Xt={cause:"codegen recognises a procedure only when the initializer is a builder chain, and this one is produced by a call or an alias",remediation:"A factory that returns a procedure cannot be read statically — inline it, or export the chain the factory builds."},$c={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."},Te=(e,t,s,n,o)=>({cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally a builder chain. A procedure written any other way exists at runtime but never reaches `_generated/api.ts`, so no caller can address it.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${s}\` but was not registered — ${o.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:s},name:"procedure_not_registered",remediation:`Assign the builder chain directly: \`export const ${t} = query.input({ … }).query(handler);\`. ${o.remediation}`,title:"Procedure exists at runtime but is missing from the generated API"}),qc=(e,t,s)=>{const n=[];for(const o of e.getVariableStatements().filter(r=>r.isExported()))for(const r of o.getDeclarations()){const a=r.getName();if(s.has(`${t}:${a}`)||!Yt(r))continue;const c=we(r);c!==void 0&&n.push(Te(t,a,c,r.getStartLineNumber(),Xt))}return n},jc=(e,t,s)=>{if(s.has(`${t}:default`))return[];const n=[];for(const o of e.getExportAssignments().filter(r=>!r.isExportEquals())){const r=we(o.getExpression());r!==void 0&&n.push(Te(t,"default",r,o.getStartLineNumber(),Xt))}return n},Vc=(e,t,s)=>{const n=[];for(const o of e.getExportDeclarations().filter(r=>r.getModuleSpecifier()===void 0))for(const r of o.getNamedExports()){const a=r.getAliasNode()?.getText()??r.getName();if(s.has(`${t}:${a}`))continue;const c=r.getLocalTargetDeclarations().find(d=>i.isVariableDeclaration(d));if(c===void 0||!Yt(c))continue;const u=we(c);u!==void 0&&n.push(Te(t,a,u,r.getStartLineNumber(),$c))}return n},Wc=(e,t,s)=>[...qc(e,t,s),...jc(e,t,s),...Vc(e,t,s)],Hc=(e,t,s)=>{const n=new Set(s.map(r=>`${r.filePath}:${r.exportName}`)),o=[];for(const r of m(t)){const a=e.getSourceFile(r);a!==void 0&&o.push(...Wc(a,v(t,r),n))}return o.toSorted((r,a)=>r.cacheKey.localeCompare(a.cacheKey))},Gc=new Set(["when","where"]),ve=new Set(["definePolicy","defineShape"]),Yc=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const n=t.getName();return ve.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 ve.has(o)?o:void 0}const s=t.getText();return ve.has(s)?s:void 0},Xc=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,Qt=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===l.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Xc(e))return"empty-object";if(i.isParenthesizedExpression(e))return Qt(e.getExpression())}},Ce=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Qc=e=>e.getDescendantsOfKind(l.ReturnStatement).filter(t=>Ce(t)===e),Zt=e=>e.getDescendantsOfKind(l.ConditionalExpression).filter(t=>Ce(t)===e),Zc=e=>{const t=Qc(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(l.IfStatement)!==void 0)||Zt(e).length>0},Jc=e=>e.getDescendantsOfKind(l.IfStatement).filter(t=>Ce(t)===e),be=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()==="",el=(e,t)=>be(e)||be(t),tl=new Map([[l.EqualsEqualsEqualsToken,"positive"],[l.EqualsEqualsToken,"positive"],[l.ExclamationEqualsEqualsToken,"negative"],[l.ExclamationEqualsToken,"negative"]]),yt=e=>!be(e)&&(i.isLiteralExpression(e)||e.getKind()===l.TrueKeyword),sl=(e,t,s)=>{const n=tl.get(e);if(n!==void 0)return el(t,s)?n==="positive"?"negative":"positive":yt(t)||yt(s)?void 0:n},j=e=>{if(i.isParenthesizedExpression(e))return j(e.getExpression());if(i.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken)return"negative";if(i.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=sl(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===l.AmpersandAmpersandToken||t===l.BarBarToken){const n=j(e.getLeft()),o=j(e.getRight());return n===o?n:"indeterminate"}}return i.isIdentifier(e)||i.isPropertyAccessExpression(e)||i.isElementAccessExpression(e)||i.isCallExpression(e)?"positive":"indeterminate"},At=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}}},nl=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(l.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},rl=e=>i.isReturnStatement(e)?e.getExpression()??e:e,ol=e=>{const t=[];for(const s of Zt(e)){const n=j(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of Jc(e)){const n=j(s.getExpression());if(n==="indeterminate")continue;const o=n==="negative"?At(s.getThenStatement()):At(s.getElseStatement())??nl(s);o!==void 0&&t.push(rl(o))}return t},il=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},al=(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)||!Gc.has(r.getName()))continue;const a=r.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Zc(a))for(const c of ol(a)){const u=Qt(c);u!==void 0&&o.push({exportName:il(e),file:s,form:u,key:r.getName(),line:c.getStartLineNumber(),owner:t})}}return o},cl=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=Yc(n);o!==void 0&&s.push(...al(n,o,t))}return s},ll=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...cl(o,v(t,n)))}return s},ul=new Set(["query","upsert","upsertMany"]),dl=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(ul.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},fl=(e,t)=>{const s=dl(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const o=b(n,"namespace");if(!(!o||!R(o)||_(o)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s}},gl=(e,t)=>w(e,t,fl),pl=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"},ml=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},hl=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression)){if(!pl(a))continue;const c=Ms(a);c!==""&&s.push({exportName:c,file:r,line:a.getStartLineNumber(),workflow:ml(a)})}}return s},xl=".lunora-schema.json",T=(e,t)=>{P(e)&&Pt(e,"utf8")===t||us(e,t,"utf8")},O=(e,t)=>{if(t===""){ds(e,{force:!0});return}T(e,t)},El=e=>{const t=f(e,"package.json");if(P(t))try{const s=JSON.parse(Pt(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},vl=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Sl=e=>{let t=P(e)?e:Z(e);for(;t&&t!==Z(t);){const s=f(t,"tsconfig.json");if(P(s))return s;t=Z(t)}},Nt=e=>e.replaceAll("\\","/"),yl=(e,t,s)=>{if(s&&e.length>0){const r=e.map(a=>`"${a.exportName}"`).join(", ");throw new k("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${r}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const r of t.columns){const a=n.get(r.table)??[];a.push(r.column),n.set(r.table,a)}const o=t.columns.length>0;for(const r of e){if(r.table===void 0){if(o)throw new k("MASK_UNSUPPORTED",`defineShape "${r.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${r.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(r.table);if(a===void 0)continue;const c=a.map(u=>`"${u}"`).join(", ");throw new k("MASK_UNSUPPORTED",`defineShape "${r.exportName}" replicates table "${r.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},re=(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)},bt=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,Al=8,Nl=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:o,migrations:r,project:a,shapes:c,usesSandbox:u,useUmbrella:d,workflows:S}=e;let x=tt(a,o),I=nt(a,o),p=st(a,o);rt([...x,...I].map(N=>N.filePath)),rt(p.filter(N=>N.stream).map(N=>N.filePath),"http-stream");for(let N=1;;N+=1){const C=Rs({agents:t,functions:x,httpRoutes:p,mutators:I,useUmbrella:d,workflows:S}),L=Ls({agents:t,functions:x,migrations:r,mutators:I,shapes:c,useUmbrella:d,usesSandbox:u});if(N>=Al||bt(a,s,C)&&bt(a,n,L))return{apiContent:C,functions:x,functionsContent:L,httpRoutes:p,mutators:I};re(a,s,C),re(a,n,L),x=tt(a,o),I=nt(a,o),p=st(a,o)}},bl=e=>{const t=Sl(e);return t?new et({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new et({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Eu=(e,t)=>{const s=m(t),n=f(t,"schema.ts");P(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=>Nt(c))),r=Nt(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)}}},vu=e=>{const t=vl(),s=t?me.now():0,n=f(e.projectRoot,e.lunoraDirectory??"lunora"),o=f(n,"schema.ts");if(!P(o))throw new k("INTERNAL",`schema.ts not found at ${o}`);const r=e.project??bl(n);bn(wo);const a=gn(r,o,e.projectRoot),{agents:c,containers:u,crons:d,dataModelContent:S,dependencies:x,env:I,featureUsage:p,hasFlags:N,hasNotify:C,identity:L,platformGate:A,queues:D,serverContent:U,storageRulesMetadata:$,usesSandbox:H,useUmbrella:K,workflows:F}=jn({lunoraDirectory:n,project:r,projectRoot:e.projectRoot,schema:a,target:e.target}),g=f(n,"_generated"),Fe=f(g,"dataModel.ts"),Oe=f(g,"server.ts"),Jt=f(g,"api.ts"),es=f(g,"functions.ts");re(r,Fe,S),re(r,Oe,U);const le=nn(r,n),q=En(r,n),{apiContent:Re,functions:B,functionsContent:Le,httpRoutes:ts,mutators:ss}=Nl({agents:c,apiPath:Jt,generatedFunctionsPath:es,lunoraDirectory:n,migrations:le,project:r,shapes:q,useUmbrella:K,usesSandbox:H,workflows:F}),G=e.lint===!1?void 0:ps({adminRoutes:Zn(r,n),aiRawRuns:tr(r,n),aiToolSideEffects:dr(r,n),argumentDerivedFetches:pr(r,n),argumentValidators:br(r,n),authApiCalls:Xs(r,n),authConfigs:Dr(r,n),browserUrlAccesses:zr(r,n),configCalls:Yr(r,n),containerKeyAccesses:Qr(r,n),containerOverrides:no(r,n),containers:u,exportSinks:ao(r,n),staleMigrationImports:Oc(r,n),failOpenGuards:go(r,n),flagReads:Ao(r,n),flagSecurityDefaults:Io(r,n),geoIndexUsages:Fo(r,n),httpActionGuards:Ko(r,n),httpHeaderWrites:Ho(r,n),hyperdriveCalls:en(r,n),identityClaimReads:ei(r,n),imageDeliveryUrlAccesses:si(r,n),inserts:tn(r,n),kvKeyAccesses:ri(r,n,B),mailRecipientAccesses:li(r,n),maskProcedures:sn(r,n),maskStrategies:xi(r,n),mutatorWrites:Ni(r,n),nondeterministicCalls:an(r,n),normalizeIdAuthorizations:zi(r,n),notifyCalls:ln(r,n),notifyConfig:cn(r,n),ownerFieldWrites:Hi(r,n,B),unrestrictedWhereBranches:ll(r,n),paymentWebhooks:ta(r,n),privilegedDispatches:pa(r,n),procedureProtections:Za(r,n),queries:Gs(r,n),queues:D,r2sqlCalls:un(r,n),ratelimitKeySelectors:sc(r,n),rawRowReturns:lc(r,n),relationLoads:fc(r,n),rlsProcedures:dn(r,n),schema:a,secretLiterals:Sc(r,n),shapes:q,softDeleteReads:Ac(r,n),sqlInterpolations:Tc(r,n),storageKeyAccesses:Lc(r,n,B),storageUploads:zc(r,n),vectorNamespaceAccesses:gl(r,n),workflowCalls:hl(r,n),workflows:F,wranglerVariables:e.wranglerVariables}),De=G===void 0?[]:[...fs(G,{source:"static"}),...Hc(r,n,B)],ns=fn(r,n),ke=pi(r,n);yl(q,ke,fi(r,n));const rs=N?xo(r,n):[],ue=A.signals.vectorStore!==!1,Y=Uc(p,{containerCount:u.length,cronCount:d.length,dependencies:x,hasPaymentTables:Xi(a.tables),queueCount:D.length,storageColumnCount:Object.keys(It(a)).length,storageRuleCount:$.rules.length,vectorIndexCount:a.vectorIndexes.length,vectorStoreSupported:ue,workflowCount:F.length}),Me=t?me.now():0,de=Pn(a,le.map(h=>h.id)),Ke=ys({advisories:De,advisorProcedures:G?.procedureProtections??[],agents:c,containers:u,env:I,flagKeys:rs,hasAccessFacade:p.access,hasAi:p.ai,hasAnalytics:p.analytics,hasBrowser:p.browser,hasFlags:N,hasHyperdrive:p.hyperdrive,hasImages:p.images,hasKv:p.kv,hasNotify:C,hasPayments:p.payments,hasPipelines:p.pipelines,hasR2sql:p.r2sql,hasVectors:ue,hasX402:p.x402,maskMetadata:ke,mutators:ss,queues:D,rlsMetadata:ns,schema:a,schemaSnapshot:de,shapes:q,storageRules:$,studioFeatures:Y,useUmbrella:K,workflows:F}),_e=As(q,x.has("@lunora/db"),K),ze=Ns(u,a.jurisdiction),Ue=bs(F),Be=Ps(c),$e=Is(D),qe=ws(d),je=Ts(a.vectorIndexes),X=Cs(a,K),Ve=Fs(x.has("@lunora/seed")),Q=e.apiSpec??"openapi",fe=Q==="openapi"||Q==="both",ge=Q==="openrpc"||Q==="both",We=vn({emailAgents:c.filter(h=>h.onEmail===!0).map(h=>({bindingName:h.bindingName,exportName:h.exportName})),hasAccess:x.has("@lunora/cloudflare-access"),hasAi:p.ai,hasAnalytics:p.analytics,hasAuth:x.has("@lunora/auth"),hasBrowser:p.browser,hasFramework:x.has("@lunora/astro")||x.has("@lunora/svelte")||x.has("@lunora/vue"),hasGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend!=="hyperdrive"),hasHyperdrive:p.hyperdrive,hasHyperdriveGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend==="hyperdrive"),hasImages:p.images,hasKv:p.kv,hasKvIntrospector:Y.kv,hasNotify:C,hasPayments:p.payments,hasR2sql:p.r2sql,hasQueue:D.some(h=>h.mode==="push"),hasScheduler:Y.scheduler,hasStorage:Y.storage,hasVectors:ue,hasWorkflow:F.length>0,hasX402:p.x402,identity:L,jurisdiction:a.jurisdiction,tableNames:a.tables.map(h=>h.name),useUmbrella:K,vectorIndexCount:a.vectorIndexes.length,voiceAgents:c.filter(h=>h.voice===!0&&h.voiceBindingName!==void 0).map(h=>({bindingName:h.voiceBindingName,exportName:h.exportName})),wantsOpenApi:fe,wantsOpenRpc:ge}),He=El(e.projectRoot),Ge=Sn({functions:B,httpRoutes:ts,version:He}),Ye=An({functions:B,version:He}),Xe=`${JSON.stringify(Ge,void 0,2)}
8
- `,Qe=`${JSON.stringify(Ye,void 0,2)}
9
- `,Ze=yn(Ge),Je=Nn(Ye),pe=f(n,xl),os=P(pe);if(e.dryRun||(P(g)||ls(g,{recursive:!0}),T(f(g,"app.ts"),We),T(Fe,S),T(f(g,"api.ts"),Re),T(Oe,U),T(f(g,"functions.ts"),Le),T(f(g,"shard.ts"),Ke),T(f(g,"crons.ts"),qe),T(f(g,"vectors.ts"),je),T(f(g,"drizzle.global.ts"),X.global),T(f(g,"drizzle.shard.ts"),X.shard),O(f(g,"containers.ts"),ze),O(f(g,"workflows.ts"),Ue),O(f(g,"agents.ts"),Be),O(f(g,"queues.ts"),$e),O(f(g,"seed.ts"),Ve),O(f(g,"collections.ts"),_e),O(f(g,"openapi.json"),fe?Xe:""),O(f(g,"openapi.ts"),fe?Ze:""),O(f(g,"openrpc.json"),ge?Qe:""),O(f(g,"openrpc.ts"),ge?Je:""),(!os||e.updateSchemaBaseline===!0)&&T(pe,gs(de))),t){const h=me.now(),is=Math.round(h-s),as=Math.round(Me-s),cs=Math.round(h-Me);console.error(`@lunora/codegen: codegen took ${is.toString()}ms (discovery ${as.toString()}ms, emit ${cs.toString()}ms)`)}return{advisories:De,advisorContext:G,agents:c,containers:u,cronTriggers:Os(d),generated:{agents:Be,api:Re,app:We,collections:_e,containers:ze,crons:qe,dataModel:S,drizzleGlobal:X.global,drizzleShard:X.shard,functions:Le,openApi:Xe,openApiModule:Ze,openRpc:Qe,openRpcModule:Je,queues:$e,seed:Ve,server:U,shard:Ke,vectors:je,workflows:Ue},migrations:le,outputDirectory:g,platformDiagnostics:A.diagnostics,queues:D,schemaSnapshot:de,schemaSnapshotPath:pe,workflows:F}};export{xl as SCHEMA_SNAPSHOT_FILENAME,bl as createCodegenProject,Sl as findTsconfig,Eu as refreshCodegenProject,vu as runCodegen};
@@ -1 +0,0 @@
1
- import{w as a}from"./classify-procedure-call-CRm5Etni.mjs";const l=s=>a(s,"use","rls");export{l as r};
@@ -1 +0,0 @@
1
- import{d as o}from"./context-property-calls-CBUh7oAY.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
@@ -1 +0,0 @@
1
- import"./listLunoraSourceFiles-BvqYMy81.mjs";import"./classify-procedure-call-CRm5Etni.mjs";import{d as p}from"./index-BsVoa-4F.mjs";export{p as default};
@@ -1 +0,0 @@
1
- import{d as a}from"./queries-D8DheHbi.mjs";import"./listLunoraSourceFiles-BvqYMy81.mjs";export{a as default};
@@ -1 +0,0 @@
1
- import{d as r}from"./context-property-calls-CBUh7oAY.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 O,join as p,relative as F,sep as R,extname as x}from"node:path";import{Node as r,SyntaxKind as m}from"ts-morph";import{diagnosticAt as v}from"./CodegenDiagnosticError-BUXlG3P-.mjs";const N=/\.ts$/u,f=(e,t)=>F(e,t).split(R).join("/").replace(N,""),T=new Set(["_generated","node_modules"]),L=(e,t,s)=>e==="schema.ts"&&t===s,I=e=>{try{return b(e)}catch{console.warn(`@lunora/codegen: skipping ${e} — it is a symlink that does not resolve (or vanished mid-scan).`);return}},S=(e,t,s,n)=>{let i,o;try{i=E(e),o=A(e)}catch{return t}if(n.has(o))return t;n.add(o);for(const a of i){const l=p(e,a),c=I(l);c!==void 0&&(c.isDirectory()?T.has(a)||S(l,t,s,n):c.isFile()&&x(a)===".ts"&&!L(a,e,s)&&t.push(l))}return t},y=e=>S(e,[],e,new Set),D=["src/server","src/index.ts","src/worker.ts"],_=new Set([".ts",".tsx"]),h=(e,t=[])=>{let s;try{s=P(e)}catch{return t}if(s.isFile())return _.has(x(e))&&t.push(e),t;if(!s.isDirectory())return t;for(const n of E(e))n==="_generated"||n==="node_modules"||h(p(e,n),t);return t},C=e=>{const t=O(e),s=y(e).map(i=>({displayPath:f(e,i),filePath:i})),n=new Set(s.map(i=>i.filePath));for(const i of D)for(const o of h(p(t,i)))n.has(o)||(n.add(o),s.push({displayPath:f(t,o),filePath:o}));return s},w=(e,t,s)=>{const n=[];for(const{displayPath:i,filePath:o}of t){const a=e.getSourceFile(o)??e.addSourceFileAtPath(o);for(const l of a.getDescendantsOfKind(m.CallExpression)){const c=s(l,i);c!==void 0&&n.push(c)}}return n},W=(e,t,s)=>w(e,y(t).map(n=>({displayPath:f(t,n),filePath:n})),s),M=(e,t,s)=>w(e,C(t),s),X=e=>{for(const t of e.getAncestors())if(r.isVariableDeclaration(t)&&t.getVariableStatement()?.hasExportKeyword()===!0)return t.getName();return""},Y=(e,t)=>{if(t){const o=e.getArguments()[0];return o&&(r.isArrowFunction(o)||r.isFunctionExpression(o))?o:void 0}const s=e.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},q=(e,t)=>{if(!e||!r.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&r.isPropertyAssignment(s)?s.getInitializer():void 0},g=e=>r.isPropertyAccessExpression(e)&&e.getName()==="db"||r.isIdentifier(e)&&e.getText()==="db",z=new Set(["findFirst","findFirstOrThrow","findMany"]),H=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!z.has(t.getName()))return;const s=t.getExpression();if(g(s)){const n=e.getArguments()[0];return{options:e.getArguments()[1],table:n&&r.isStringLiteral(n)?n.getLiteralText():""}}if(r.isPropertyAccessExpression(s)){const n=s.getExpression();if(g(n))return{options:e.getArguments()[0],table:s.getName()}}},u=(e,t)=>{const s=e.getExpression();return!r.isPropertyAccessExpression(s)||!t.has(s.getName())?!1:g(s.getExpression())},d=e=>{const t=e.getArguments()[0];return t&&r.isStringLiteral(t)?t.getLiteralText():""},B=(e,t,s)=>{const n=new Set,i=new Set;for(const o of e.getDescendantsOfKind(m.CallExpression))if(u(o,t)){const a=d(o);a!==""&&n.add(a)}else if(u(o,s)){const a=d(o);a!==""&&i.add(a)}return{tablesRead:[...n],tablesWritten:[...i]}},K=e=>{let t=e;for(;t&&(r.isAsExpression(t)||r.isSatisfiesExpression(t)||r.isParenthesizedExpression(t)||r.isNonNullExpression(t));)t=t.getExpression();return t},G=e=>{const t=K(e);return t&&r.isCallExpression(t)?t:void 0},J=e=>{const t=e.getExportAssignment(i=>!i.isExportEquals());if(!t)return;const s=t.getExpression();if(!r.isIdentifier(s))return s;const n=s.getSymbol()?.getValueDeclaration();return n&&r.isVariableDeclaration(n)?n.getInitializer():s},Q=e=>{const t=e.getArguments()[1];return t&&r.isStringLiteral(t)?t.getLiteralValue():""},U=(e,t)=>{if(!r.isObjectLiteralExpression(e))return;const s=e.getProperty(t);if(!s||!r.isPropertyAssignment(s))return;const n=s.getInitializer();return n&&r.isStringLiteral(n)?n.getLiteralText():void 0},Z=e=>r.isIdentifier(e)&&e.getText()==="ctx",tt=e=>(t,s,n)=>{if(r.isStringLiteral(t)||r.isNoSubstitutionTemplateLiteral(t))return t.getLiteralValue();throw v(t,`${e} "${s}": \`${n}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)};export{N as TS_EXTENSION_RE,W as collectCallRows,M as collectSecurityCallRows,J as defaultExportExpression,X as enclosingExportName,Y as handlerOf,Z as isContextIdentifier,g as isDatabaseAccessor,Q as limitNameOf,y as listLunoraSourceFiles,C as listSecurityScanFiles,f as lunoraRelativePath,q as propertyInitializer,H as readTargetOf,tt as stringPropertyFor,U as stringPropertyOf,d as tableArgumentOf,B as tablesAccessedIn,K as unwrapExpression,G as unwrapToCallExpression};