@lunora/codegen 1.0.0-alpha.136 → 1.0.0-alpha.138

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 (63) hide show
  1. package/dist/index.d.mts +1 -1
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/AGENTS_FILENAME-D1qA0h5m.mjs +1 -0
  5. package/dist/packem_shared/CONTAINERS_FILENAME-oKaARMoA.mjs +1 -0
  6. package/dist/packem_shared/FLAGS_FILENAME-BasxlnVS.mjs +1 -0
  7. package/dist/packem_shared/{GENERATED_HEADER-Juc2KRT1.mjs → GENERATED_HEADER-Gajqa19J.mjs} +1 -1
  8. package/dist/packem_shared/MUTATORS_FILENAME-DJvAhDlD.mjs +1 -0
  9. package/dist/packem_shared/NOTIFY_FILENAME-B-eIjru_.mjs +1 -0
  10. package/dist/packem_shared/{OPENRPC_VERSION-CtO1oRu-.mjs → OPENRPC_VERSION-X4hs2-hb.mjs} +1 -1
  11. package/dist/packem_shared/QUEUES_FILENAME-D229WtRm.mjs +1 -0
  12. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-D1R4OORJ.mjs +9 -0
  13. package/dist/packem_shared/WORKFLOWS_FILENAME-DRaiCNa6.mjs +1 -0
  14. package/dist/packem_shared/ast-CjWtsS6S.mjs +1 -0
  15. package/dist/packem_shared/{buildOpenApiDocument-B3l1QPs9.mjs → buildOpenApiDocument-CGl09_Pi.mjs} +1 -1
  16. package/dist/packem_shared/chain-CtC3-wwZ.mjs +1 -0
  17. package/dist/packem_shared/classify-procedure-call-AKeIK05y.mjs +1 -0
  18. package/dist/packem_shared/discoverAuthApiCalls-C35kkayg.mjs +1 -0
  19. package/dist/packem_shared/discoverCrons-wXBfQcfn.mjs +1 -0
  20. package/dist/packem_shared/discoverFunctions-BBDziFXy.mjs +1 -0
  21. package/dist/packem_shared/discoverHttpRoutes-Dmow2gql.mjs +1 -0
  22. package/dist/packem_shared/discoverInserts-C5l2INmE.mjs +1 -0
  23. package/dist/packem_shared/discoverMaskProcedures-Df4JQp_2.mjs +1 -0
  24. package/dist/packem_shared/discoverMigrations-CWH7T6qz.mjs +1 -0
  25. package/dist/packem_shared/discoverNondeterministicCalls-JsO91i57.mjs +1 -0
  26. package/dist/packem_shared/discoverQueries-iypfwfdZ.mjs +1 -0
  27. package/dist/packem_shared/discoverR2sqlCalls-BbfOpwE4.mjs +1 -0
  28. package/dist/packem_shared/discoverRlsMetadata-DGUGYgWs.mjs +1 -0
  29. package/dist/packem_shared/discoverRlsProcedures-CRshfYZE.mjs +1 -0
  30. package/dist/packem_shared/discoverSandboxUsage-DdewAOuj.mjs +1 -0
  31. package/dist/packem_shared/discoverSchema-Bp8DcNq7.mjs +1 -0
  32. package/dist/packem_shared/discoverStorageRulesMetadata-gyO60A5S.mjs +1 -0
  33. package/dist/packem_shared/{emit-khv5P1pH.mjs → emit-BQNGQnaS.mjs} +186 -186
  34. package/dist/packem_shared/{emitApp-CZ_yiNNO.mjs → emitApp-BQcIWzkh.mjs} +1 -1
  35. package/dist/packem_shared/exported-procedure-chains-MlZRKqSD.mjs +1 -0
  36. package/dist/packem_shared/index-CCDlo9L7.mjs +1 -0
  37. package/dist/packem_shared/queries-B_xEHIeL.mjs +1 -0
  38. package/dist/packem_shared/unwrap-handler-return-CmIWbykC.mjs +1 -0
  39. package/package.json +10 -10
  40. package/dist/packem_shared/AGENTS_FILENAME-CPHo8Se5.mjs +0 -1
  41. package/dist/packem_shared/CONTAINERS_FILENAME-Bvn6LZP6.mjs +0 -1
  42. package/dist/packem_shared/FLAGS_FILENAME-DtBWyUKq.mjs +0 -1
  43. package/dist/packem_shared/MUTATORS_FILENAME-VnV3vpJh.mjs +0 -1
  44. package/dist/packem_shared/NOTIFY_FILENAME-3xSHPaVK.mjs +0 -1
  45. package/dist/packem_shared/QUEUES_FILENAME-BnGLtAIu.mjs +0 -1
  46. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DIVmMUEJ.mjs +0 -9
  47. package/dist/packem_shared/WORKFLOWS_FILENAME-B8y51Frf.mjs +0 -1
  48. package/dist/packem_shared/discover-ast-D33zP-NZ.mjs +0 -1
  49. package/dist/packem_shared/discover-queries-Dfj_0WJG.mjs +0 -1
  50. package/dist/packem_shared/discoverAuthApiCalls-DUjcl0SB.mjs +0 -1
  51. package/dist/packem_shared/discoverCrons-BUJO2ipU.mjs +0 -1
  52. package/dist/packem_shared/discoverFunctions-2ajN70Q9.mjs +0 -1
  53. package/dist/packem_shared/discoverHttpRoutes-DDhmUyVN.mjs +0 -1
  54. package/dist/packem_shared/discoverInserts-YX8AmrzL.mjs +0 -1
  55. package/dist/packem_shared/discoverMaskProcedures-CjfyneNc.mjs +0 -1
  56. package/dist/packem_shared/discoverMigrations-4Jjf5DJE.mjs +0 -1
  57. package/dist/packem_shared/discoverNondeterministicCalls-CSI5ir3L.mjs +0 -1
  58. package/dist/packem_shared/discoverQueries-C5S9tFoD.mjs +0 -1
  59. package/dist/packem_shared/discoverR2sqlCalls-NtUJIKqo.mjs +0 -1
  60. package/dist/packem_shared/discoverRlsMetadata-BA9lVt-Q.mjs +0 -1
  61. package/dist/packem_shared/discoverSandboxUsage-L0lV17de.mjs +0 -1
  62. package/dist/packem_shared/discoverSchema-Hsu_1xIc.mjs +0 -1
  63. package/dist/packem_shared/discoverStorageRulesMetadata-DudvC-VM.mjs +0 -1
package/dist/index.d.mts CHANGED
@@ -2803,7 +2803,7 @@ declare const discoverRlsProcedures: (project: Project, lunoraDirectory: string)
2803
2803
  * Aggregate the schema-wide RLS metadata the studio's read-only inspector reads:
2804
2804
  * every statically-discovered `(table, on, procedure)` policy entry plus every
2805
2805
  * role declared via `rls(policies, { roles })`. Walks the same builder chains as
2806
- * {@link discoverRlsProcedures} but extracts the richer `{ on }` operation +
2806
+ * `discoverRlsProcedures` but extracts the richer `{ on }` operation +
2807
2807
  * role/permission shape rather than the lint's table-name set.
2808
2808
  *
2809
2809
  * Only the **builder** form (`c.use(rls(...)).query(...)`) can declare policies,
package/dist/index.d.ts CHANGED
@@ -2803,7 +2803,7 @@ declare const discoverRlsProcedures: (project: Project, lunoraDirectory: string)
2803
2803
  * Aggregate the schema-wide RLS metadata the studio's read-only inspector reads:
2804
2804
  * every statically-discovered `(table, on, procedure)` policy entry plus every
2805
2805
  * role declared via `rls(policies, { roles })`. Walks the same builder chains as
2806
- * {@link discoverRlsProcedures} but extracts the richer `{ on }` operation +
2806
+ * `discoverRlsProcedures` but extracts the richer `{ on }` operation +
2807
2807
  * role/permission shape rather than the lint's table-name set.
2808
2808
  *
2809
2809
  * Only the **builder** form (`c.use(rls(...)).query(...)`) can declare policies,
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CftvRWB8.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as S}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as E,diagnosticAt as x}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-CPHo8Se5.mjs";import{default as g}from"./packem_shared/discoverAuthApiCalls-DUjcl0SB.mjs";import{CONTAINERS_FILENAME as R,discoverContainers as M}from"./packem_shared/CONTAINERS_FILENAME-Bvn6LZP6.mjs";import{default as C}from"./packem_shared/discoverCrons-BUJO2ipU.mjs";import{FLAGS_FILENAME as T,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-DtBWyUKq.mjs";import{discoverFunctions as F}from"./packem_shared/discoverFunctions-2ajN70Q9.mjs";import{default as P}from"./packem_shared/discoverHttpRoutes-DDhmUyVN.mjs";import{default as G}from"./packem_shared/discoverInserts-YX8AmrzL.mjs";import{default as b}from"./packem_shared/discoverMaskProcedures-CjfyneNc.mjs";import{default as y}from"./packem_shared/discoverMigrations-4Jjf5DJE.mjs";import{MUTATORS_FILENAME as j,discoverMutators as K}from"./packem_shared/MUTATORS_FILENAME-VnV3vpJh.mjs";import{default as z}from"./packem_shared/discoverNondeterministicCalls-CSI5ir3L.mjs";import{NOTIFY_FILENAME as w,discoverNotifyCalls as q,discoverNotifyConfig as B}from"./packem_shared/NOTIFY_FILENAME-3xSHPaVK.mjs";import{default as Y}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as Z}from"./packem_shared/discover-queries-Dfj_0WJG.mjs";import{QUEUES_FILENAME as ee,discoverQueues as re}from"./packem_shared/QUEUES_FILENAME-BnGLtAIu.mjs";import{default as te}from"./packem_shared/discoverR2sqlCalls-NtUJIKqo.mjs";import{discoverRlsMetadata as ae,default as ie}from"./packem_shared/discoverRlsMetadata-BA9lVt-Q.mjs";import{discoverSandboxUsage as de}from"./packem_shared/discoverSandboxUsage-L0lV17de.mjs";import{default as pe}from"./packem_shared/discoverSchema-Hsu_1xIc.mjs";import{SHAPES_FILENAME as ne,discoverShapes as Se}from"./packem_shared/SHAPES_FILENAME-BTdasTq2.mjs";import{default as Ee}from"./packem_shared/discoverStorageRulesMetadata-DudvC-VM.mjs";import{WORKFLOWS_FILENAME as Ae,discoverWorkflows as ue}from"./packem_shared/WORKFLOWS_FILENAME-B8y51Frf.mjs";import{G as Ne,e as ge,a as Oe,b as Re,c as Me,d as he,f as Ce,g as _e,h as Te,i as Ie,j as Le,k as Fe,l as De,m as Pe}from"./packem_shared/emit-khv5P1pH.mjs";import{emitApp as Ge}from"./packem_shared/emitApp-CZ_yiNNO.mjs";import{buildOpenApiDocument as be,emitOpenApi as ke,emitOpenApiModule as ye}from"./packem_shared/buildOpenApiDocument-B3l1QPs9.mjs";import{OPENRPC_VERSION as je,buildOpenRpcDocument as Ke,emitOpenRpc as Ve,emitOpenRpcModule as ze}from"./packem_shared/OPENRPC_VERSION-CtO1oRu-.mjs";import{DEFAULT_TARGET as we,platformMatrixIds as qe,readProjectTarget as Be,resolveCodegenTarget as Je}from"./packem_shared/DEFAULT_TARGET-CrhWLUK7.mjs";import{SCHEMA_SNAPSHOT_FILENAME as Xe,createCodegenProject as Ze,findTsconfig as $e,refreshCodegenProject as er,runCodegen as rr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-DIVmMUEJ.mjs";import{SchemaSnapshotParseError as tr,buildSchemaSnapshot as sr,evaluateSchemaDrift as ar,parseSchemaSnapshot as ir}from"./packem_shared/SchemaSnapshotParseError-D2h88OHU.mjs";import{schemaFromIr as dr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as pr,validatorIrToJsonSchema as cr}from"./packem_shared/LUNORA_ERROR_CODES-BYg8Lpgb.mjs";import{SDK_LANGUAGES as Sr,SDK_TARGETS as lr,generateSdk as Er}from"./packem_shared/SDK_LANGUAGES-CFyux-74.mjs";import{redact as Ar,secretKindOf as ur}from"./packem_shared/redact-Cy14LEnc.mjs";import{MESSAGE_SOLUTIONS as Nr,findSolutionByMessage as gr}from"@lunora/errors";import{isTypedSchema as Rr}from"./packem_shared/isTypedSchema-B_qlBbE-.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,R as CONTAINERS_FILENAME,E as CodegenDiagnosticError,we as DEFAULT_TARGET,T as FLAGS_FILENAME,Ne as GENERATED_HEADER,pr as LUNORA_ERROR_CODES,Nr as LUNORA_SOLUTION_RULES,j as MUTATORS_FILENAME,w as NOTIFY_FILENAME,je as OPENRPC_VERSION,ee as QUEUES_FILENAME,Xe as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,Sr as SDK_LANGUAGES,lr as SDK_TARGETS,ne as SHAPES_FILENAME,tr as SchemaSnapshotParseError,e as VERSION,Ae as WORKFLOWS_FILENAME,be as buildOpenApiDocument,Ke as buildOpenRpcDocument,sr as buildSchemaSnapshot,Ze as createCodegenProject,c as describeErrorLevelFindings,x as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,g as discoverAuthApiCalls,M as discoverContainers,C as discoverCrons,I as discoverFlags,F as discoverFunctions,P as discoverHttpRoutes,G as discoverInserts,b as discoverMaskProcedures,y as discoverMigrations,K as discoverMutators,z as discoverNondeterministicCalls,q as discoverNotifyCalls,B as discoverNotifyConfig,Z as discoverQueries,re as discoverQueues,te as discoverR2sqlCalls,ae as discoverRlsMetadata,ie as discoverRlsProcedures,de as discoverSandboxUsage,pe as discoverSchema,Se as discoverShapes,Ee as discoverStorageRulesMetadata,ue as discoverWorkflows,ge as emitAgents,Oe as emitApi,Ge as emitApp,Re as emitCollections,Me as emitContainers,he as emitCrons,Ce as emitDataModel,_e as emitDrizzleSchema,Te as emitFunctions,ke as emitOpenApi,ye as emitOpenApiModule,Ve as emitOpenRpc,ze as emitOpenRpcModule,Ie as emitServer,Le as emitShard,Fe as emitVectors,De as emitWorkflows,Pe as emitWranglerCronTriggers,n as errorAdvisoryNames,S as errorPlatformDiagnosticNames,ar as evaluateSchemaDrift,gr as findLunoraSolution,$e as findTsconfig,m as formatAdvisories,Er as generateSdk,Rr as isTypedSchema,d as lintSchema,ir as parseSchemaSnapshot,qe as platformMatrixIds,Y as readPackageDependencies,Be as readProjectTarget,Ar as redact,er as refreshCodegenProject,Je as resolveCodegenTarget,rr as runCodegen,dr as schemaFromIr,ur as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,cr as validatorIrToJsonSchema};
1
+ import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CftvRWB8.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as S}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as E,diagnosticAt as x}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-D1qA0h5m.mjs";import{default as g}from"./packem_shared/discoverAuthApiCalls-C35kkayg.mjs";import{CONTAINERS_FILENAME as R,discoverContainers as M}from"./packem_shared/CONTAINERS_FILENAME-oKaARMoA.mjs";import{default as C}from"./packem_shared/discoverCrons-wXBfQcfn.mjs";import{FLAGS_FILENAME as T,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-BasxlnVS.mjs";import{default as F}from"./packem_shared/discoverFunctions-BBDziFXy.mjs";import{default as P}from"./packem_shared/discoverHttpRoutes-Dmow2gql.mjs";import{default as G}from"./packem_shared/discoverInserts-C5l2INmE.mjs";import{d as b}from"./packem_shared/index-CCDlo9L7.mjs";import{default as y}from"./packem_shared/discoverMigrations-CWH7T6qz.mjs";import{MUTATORS_FILENAME as j,discoverMutators as K}from"./packem_shared/MUTATORS_FILENAME-DJvAhDlD.mjs";import{default as z}from"./packem_shared/discoverNondeterministicCalls-JsO91i57.mjs";import{NOTIFY_FILENAME as w,discoverNotifyCalls as q,discoverNotifyConfig as B}from"./packem_shared/NOTIFY_FILENAME-B-eIjru_.mjs";import{default as Y}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as Z}from"./packem_shared/queries-B_xEHIeL.mjs";import{QUEUES_FILENAME as ee,discoverQueues as re}from"./packem_shared/QUEUES_FILENAME-D229WtRm.mjs";import{default as te}from"./packem_shared/discoverR2sqlCalls-BbfOpwE4.mjs";import{default as ae}from"./packem_shared/discoverRlsProcedures-CRshfYZE.mjs";import{default as me}from"./packem_shared/discoverRlsMetadata-DGUGYgWs.mjs";import{discoverSandboxUsage as fe}from"./packem_shared/discoverSandboxUsage-DdewAOuj.mjs";import{default as ce}from"./packem_shared/discoverSchema-Bp8DcNq7.mjs";import{SHAPES_FILENAME as Se,discoverShapes as le}from"./packem_shared/SHAPES_FILENAME-BTdasTq2.mjs";import{default as xe}from"./packem_shared/discoverStorageRulesMetadata-gyO60A5S.mjs";import{WORKFLOWS_FILENAME as ue,discoverWorkflows as ve}from"./packem_shared/WORKFLOWS_FILENAME-DRaiCNa6.mjs";import{G as ge,e as Oe,a as Re,b as Me,c as he,d as Ce,f as _e,g as Te,h as Ie,i as Le,j as Fe,k as De,l as Pe,m as Ue}from"./packem_shared/emit-BQNGQnaS.mjs";import{emitApp as He}from"./packem_shared/emitApp-BQcIWzkh.mjs";import{buildOpenApiDocument as ke,emitOpenApi as ye,emitOpenApiModule as We}from"./packem_shared/buildOpenApiDocument-CGl09_Pi.mjs";import{OPENRPC_VERSION as Ke,buildOpenRpcDocument as Ve,emitOpenRpc as ze,emitOpenRpcModule as Qe}from"./packem_shared/OPENRPC_VERSION-X4hs2-hb.mjs";import{DEFAULT_TARGET as qe,platformMatrixIds as Be,readProjectTarget as Je,resolveCodegenTarget as Ye}from"./packem_shared/DEFAULT_TARGET-CrhWLUK7.mjs";import{SCHEMA_SNAPSHOT_FILENAME as Ze,createCodegenProject as $e,findTsconfig as er,refreshCodegenProject as rr,runCodegen as or}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-D1R4OORJ.mjs";import{SchemaSnapshotParseError as sr,buildSchemaSnapshot as ar,evaluateSchemaDrift as ir,parseSchemaSnapshot as mr}from"./packem_shared/SchemaSnapshotParseError-D2h88OHU.mjs";import{schemaFromIr as fr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as cr,validatorIrToJsonSchema as nr}from"./packem_shared/LUNORA_ERROR_CODES-BYg8Lpgb.mjs";import{SDK_LANGUAGES as lr,SDK_TARGETS as Er,generateSdk as xr}from"./packem_shared/SDK_LANGUAGES-CFyux-74.mjs";import{redact as ur,secretKindOf as vr}from"./packem_shared/redact-Cy14LEnc.mjs";import{MESSAGE_SOLUTIONS as gr,findSolutionByMessage as Or}from"@lunora/errors";import{isTypedSchema as Mr}from"./packem_shared/isTypedSchema-B_qlBbE-.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,R as CONTAINERS_FILENAME,E as CodegenDiagnosticError,qe as DEFAULT_TARGET,T as FLAGS_FILENAME,ge as GENERATED_HEADER,cr as LUNORA_ERROR_CODES,gr as LUNORA_SOLUTION_RULES,j as MUTATORS_FILENAME,w as NOTIFY_FILENAME,Ke as OPENRPC_VERSION,ee as QUEUES_FILENAME,Ze as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,lr as SDK_LANGUAGES,Er as SDK_TARGETS,Se as SHAPES_FILENAME,sr as SchemaSnapshotParseError,e as VERSION,ue as WORKFLOWS_FILENAME,ke as buildOpenApiDocument,Ve as buildOpenRpcDocument,ar as buildSchemaSnapshot,$e as createCodegenProject,c as describeErrorLevelFindings,x as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,g as discoverAuthApiCalls,M as discoverContainers,C as discoverCrons,I as discoverFlags,F as discoverFunctions,P as discoverHttpRoutes,G as discoverInserts,b as discoverMaskProcedures,y as discoverMigrations,K as discoverMutators,z as discoverNondeterministicCalls,q as discoverNotifyCalls,B as discoverNotifyConfig,Z as discoverQueries,re as discoverQueues,te as discoverR2sqlCalls,me as discoverRlsMetadata,ae as discoverRlsProcedures,fe as discoverSandboxUsage,ce as discoverSchema,le as discoverShapes,xe as discoverStorageRulesMetadata,ve as discoverWorkflows,Oe as emitAgents,Re as emitApi,He as emitApp,Me as emitCollections,he as emitContainers,Ce as emitCrons,_e as emitDataModel,Te as emitDrizzleSchema,Ie as emitFunctions,ye as emitOpenApi,We as emitOpenApiModule,ze as emitOpenRpc,Qe as emitOpenRpcModule,Le as emitServer,Fe as emitShard,De as emitVectors,Pe as emitWorkflows,Ue as emitWranglerCronTriggers,n as errorAdvisoryNames,S as errorPlatformDiagnosticNames,ir as evaluateSchemaDrift,Or as findLunoraSolution,er as findTsconfig,m as formatAdvisories,xr as generateSdk,Mr as isTypedSchema,d as lintSchema,mr as parseSchemaSnapshot,Be as platformMatrixIds,Y as readPackageDependencies,Je as readProjectTarget,ur as redact,rr as refreshCodegenProject,Ye as resolveCodegenTarget,or as runCodegen,fr as schemaFromIr,vr as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,nr as validatorIrToJsonSchema};
@@ -0,0 +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{u as A,s as w}from"./ast-CjWtsS6S.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};
@@ -0,0 +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{s as L}from"./ast-CjWtsS6S.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};
@@ -0,0 +1 @@
1
+ import{existsSync as l}from"node:fs";import{join as p}from"node:path";import{Node as i}from"ts-morph";import{d as g,p as d}from"./ast-CjWtsS6S.mjs";const c="flags.ts",f="@lunora/flags/providers/flagship",u=e=>{const t=e.getSymbol();if(!t)return e.getText()==="flagshipProvider";for(const r of t.getDeclarations())if(i.isImportSpecifier(r))return r.getImportDeclaration().getModuleSpecifierValue()!==f?!1:r.getNameNode().getText()==="flagshipProvider";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=>d(e.getArguments()[0],"provider"),S=(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,S as discoverFlags};
@@ -1 +1 @@
1
- import"./SCHEMA_SNAPSHOT_VERSION-CftvRWB8.mjs";import{G as t,U as m,n as r,e as o,a as n,b as l,c as A,d as E,f as S,g,h as C,o as c,p as d,i as p,j as u,k as D,l as f,m as h}from"./emit-khv5P1pH.mjs";import"./paths-C-9fwEgQ.mjs";export{t as GENERATED_HEADER,m as UMBRELLA_BASE_PACKAGES,r as buildStorageColumns,o as emitAgents,n as emitApi,l as emitCollections,A as emitContainers,E as emitCrons,S as emitDataModel,g as emitDrizzleSchema,C as emitFunctions,c as emitQueues,d as emitSeed,p as emitServer,u as emitShard,D as emitVectors,f as emitWorkflows,h as emitWranglerCronTriggers};
1
+ import"./SCHEMA_SNAPSHOT_VERSION-CftvRWB8.mjs";import{G as t,U as m,n as r,e as o,a as n,b as l,c as A,d as E,f as S,g,h as C,o as c,p as d,i as p,j as u,k as D,l as f,m as h}from"./emit-BQNGQnaS.mjs";import"./paths-C-9fwEgQ.mjs";export{t as GENERATED_HEADER,m as UMBRELLA_BASE_PACKAGES,r as buildStorageColumns,o as emitAgents,n as emitApi,l as emitCollections,A as emitContainers,E as emitCrons,S as emitDataModel,g as emitDrizzleSchema,C as emitFunctions,c as emitQueues,d as emitSeed,p as emitServer,u as emitShard,D as emitVectors,f as emitWorkflows,h as emitWranglerCronTriggers};
@@ -0,0 +1 @@
1
+ import{existsSync as f}from"node:fs";import{join as p}from"node:path";import{Node as o,SyntaxKind as c}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as g}from"./module-specifiers-WF8iAydP.mjs";import{a as d}from"./parse-validator-BFTp87yz.mjs";import{u as x}from"./unwrap-handler-return-CmIWbykC.mjs";const M="mutators.ts",m=g,y=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineMutator";for(const e of t.getDeclarations())if(o.isImportSpecifier(e))return m(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineMutator":!1;return!1},S=r=>{const t=r.getSymbol();if(!t)return!1;for(const e of t.getDeclarations()){if(!o.isNamespaceImport(e))continue;const i=e.getFirstAncestorByKind(c.ImportDeclaration);return i!==void 0&&m(i.getModuleSpecifierValue())}return!1},N=r=>{if(o.isIdentifier(r))return y(r);if(o.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(t)&&S(t)}return!1},I=r=>{const t=r.getArguments()[0];return t&&o.isObjectLiteralExpression(t)?t:void 0},b=r=>{const t=r?.getProperty("args");if(!t||!o.isPropertyAssignment(t))return{};const e=t.getInitializer();return e&&o.isObjectLiteralExpression(e)?d(e):{}},A=r=>{const t=r?.getProperty("server");if(!t||!o.isPropertyAssignment(t))return"unknown";const e=t.getInitializer();return!e||!(o.isArrowFunction(e)||o.isFunctionExpression(e))?"unknown":x(e)},E=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const i=e.getInitializer();if(i?.getKind()!==c.CallExpression)continue;const n=i,a=n.getExpression();if(!N(a))continue;const s=e.getNameNode();if(!o.isIdentifier(s))throw l(s,"defineMutator exports must be plain named exports (no destructuring)");const u=I(n);t.push({args:b(u),exportName:s.getText(),filePath:"mutators",returnType:A(u)})}return t},w=(r,t)=>{const e=p(t,M);if(!f(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),n=E(i);return n.sort((a,s)=>a.exportName.localeCompare(s.exportName)),n};export{M as MUTATORS_FILENAME,w as discoverMutators,N as isDefineMutatorCallee};
@@ -0,0 +1 @@
1
+ import{existsSync as m}from"node:fs";import{join as x}from"node:path";import{SyntaxKind as d,Node as c}from"ts-morph";import{l,a as g,d as P,h as E}from"./ast-CjWtsS6S.mjs";import{c as S}from"./classify-procedure-call-AKeIK05y.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 s=S(t);if(!s)return;const o=E(t,s.receiver);return o?{exportName:e.getName(),handler:o,kind:s.kind}:void 0},h=e=>{const t=[];for(const s of e.getVariableStatements())if(s.isExported())for(const o of s.getDeclarations()){const r=N(o);r&&t.push(r)}return t},f=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),s=e.getExpression();if((t==="notify"||t==="push")&&c.isIdentifier(s)&&s.getText()==="ctx")return t;if(t==="push"&&f(s)==="notify")return"push"},F=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),s=f(e.getExpression());if(s==="notify"&&v.has(t))return`ctx.notify.${t}`;if(s==="push"&&p.has(t))return`ctx.push.${t}`},A=e=>c.isPropertyAccessExpression(e)?f(e.getExpression())==="push"&&p.has(e.getName()):!1,T=(e,t)=>{const s=[];for(const o of l(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o),a=g(t,o);for(const n of h(r))if(!(n.kind!=="query"&&n.kind!=="mutation"))for(const i of n.handler.getDescendantsOfKind(d.PropertyAccessExpression)){const u=F(i);u!==void 0&&s.push({callee:u,exportName:n.exportName,file:a,kind:n.kind,line:i.getStartLineNumber()})}}return s},O=(e,t)=>{for(const s of l(t)){const o=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const r of h(o))for(const a of r.handler.getDescendantsOfKind(d.PropertyAccessExpression))if(A(a))return!0}return!1},_=(e,t)=>{const s=x(t,y);if(!m(s))return;const o=e.getSourceFile(s)??e.addSourceFileAtPath(s),r=P(o);let a=!1,n=!1;if(r&&c.isCallExpression(r)){const i=r.getArguments()[0];i&&c.isObjectLiteralExpression(i)&&(a=i.getProperty("webPush")!==void 0,n=i.getProperty("fcm")!==void 0)}return{hasFcm:n,hasWebPush:a,usesPush:O(e,t)}};export{y as NOTIFY_FILENAME,T as discoverNotifyCalls,_ as discoverNotifyConfig};
@@ -1,3 +1,3 @@
1
- import{G as c}from"./emit-khv5P1pH.mjs";import{s as u}from"./paths-C-9fwEgQ.mjs";import{validatorIrToJsonSchema as m,objectSchema as p,LUNORA_ERROR_CODES as i}from"./LUNORA_ERROR_CODES-BYg8Lpgb.mjs";const l="1.3.2",d={description:"Result is TS-inferred from the function's return type (no `.output()` declared); best-effort — any JSON."},R=e=>{const n=u(e.filePath),o=`${n}:${e.exportName}`;return{description:`Invoke the \`${e.kind}\` \`${o}\` over the Lunora RPC envelope (POST /_lunora/rpc, body \`{ "functionPath": "${o}", "args": { … } }\`).`,errors:i.map((r,s)=>({code:-32e3-s,data:{code:r},message:r})),name:o,params:[{description:"The function's argument object (the RPC envelope's `args`).",name:"args",required:Object.keys(e.args).length>0,schema:p(e.args)}],result:{name:"result",schema:e.output?m(e.output):d},summary:`${e.kind}: ${o}`,"x-lunora-function-kind":e.kind,"x-tags":[{name:n}]}},g=e=>{const n=e.version??"0.0.0",r=e.functions.filter(t=>t.visibility!=="internal"&&t.kind!=="stream").map(t=>R(t)).toSorted((t,a)=>t.name.localeCompare(a.name));return{info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora RPC",version:n},methods:r,openrpc:l}},S=e=>`${JSON.stringify(g(e),void 0,2)}
1
+ import{G as c}from"./emit-BQNGQnaS.mjs";import{s as u}from"./paths-C-9fwEgQ.mjs";import{validatorIrToJsonSchema as m,objectSchema as p,LUNORA_ERROR_CODES as i}from"./LUNORA_ERROR_CODES-BYg8Lpgb.mjs";const l="1.3.2",d={description:"Result is TS-inferred from the function's return type (no `.output()` declared); best-effort — any JSON."},R=e=>{const n=u(e.filePath),o=`${n}:${e.exportName}`;return{description:`Invoke the \`${e.kind}\` \`${o}\` over the Lunora RPC envelope (POST /_lunora/rpc, body \`{ "functionPath": "${o}", "args": { … } }\`).`,errors:i.map((r,s)=>({code:-32e3-s,data:{code:r},message:r})),name:o,params:[{description:"The function's argument object (the RPC envelope's `args`).",name:"args",required:Object.keys(e.args).length>0,schema:p(e.args)}],result:{name:"result",schema:e.output?m(e.output):d},summary:`${e.kind}: ${o}`,"x-lunora-function-kind":e.kind,"x-tags":[{name:n}]}},g=e=>{const n=e.version??"0.0.0",r=e.functions.filter(t=>t.visibility!=="internal"&&t.kind!=="stream").map(t=>R(t)).toSorted((t,a)=>t.name.localeCompare(a.name));return{info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora RPC",version:n},methods:r,openrpc:l}},S=e=>`${JSON.stringify(g(e),void 0,2)}
2
2
  `,v=e=>`${c}export const openRpcSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
3
3
  `;export{l as OPENRPC_VERSION,g as buildOpenRpcDocument,S as emitOpenRpc,v as emitOpenRpcModule};
@@ -0,0 +1 @@
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 u}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{s as h}from"./ast-CjWtsS6S.mjs";const q="queues.ts",b=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineQueue";for(const e of t.getDeclarations())if(u.isImportSpecifier(e))return e.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/queue"?!1:e.getNameNode().getText()==="defineQueue";return!1},c=h("queue"),N=(r,t,e)=>{if(u.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||!u.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||!u.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&&u.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 s=e.getProperty("deadLetterQueue");s&&u.isPropertyAssignment(s)&&(n.tuning.deadLetterQueue=c(s.getInitializerOrThrow(),t,"deadLetterQueue"));for(const i of["maxBatchSize","maxBatchTimeout","maxRetries","retryDelay"]){const m=e.getProperty(i);m&&u.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,s=o.getExpression();if(!u.isIdentifier(s)||!b(s))continue;const i=e.getNameNode();if(!u.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 s=e.get(n.bindingName);if(s!==void 0)throw new d("DUPLICATE_QUEUE_BINDING",`Duplicate queue binding "${n.bindingName}": produced by both "${s}" 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((s,i)=>s.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 ss,readFileSync as At,writeFileSync as ns,rmSync as rs}from"node:fs";import{join as f,dirname as fe}from"node:path";import{performance as pe}from"node:perf_hooks";import{runAdvisor as is}from"@lunora/advisor";import{LunoraError as k}from"@lunora/errors";import{SyntaxKind as l,Node as o,Project as Xe}from"ts-morph";import{serializeSchemaSnapshot as os}from"./SCHEMA_SNAPSHOT_VERSION-CftvRWB8.mjs";import{toAdvisorContext as as}from"./formatAdvisories-CkEu1eye.mjs";import{discoverAgents as cs}from"./AGENTS_FILENAME-D1qA0h5m.mjs";import{discoverContainers as ls}from"./CONTAINERS_FILENAME-oKaARMoA.mjs";import{diagnosticAt as se}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as ne}from"./module-specifiers-WF8iAydP.mjs";import{C as ge,i as us,f as ds,n as fs,j as ps,b as gs,c as ms,l as hs,e as xs,o as Es,d as vs,k as Ss,g as As,p as ys,m as Ns,a as bs,h as Ps}from"./emit-BQNGQnaS.mjs";import{l as g,a as E,f as P,p as y,g as yt,j as Ee,h as Is,i as L,b as Ze,r as Nt,e as ws}from"./ast-CjWtsS6S.mjs";import Ts from"./readPackageDependencies-C6h6FZuP.mjs";import{discoverQueues as Cs}from"./QUEUES_FILENAME-D229WtRm.mjs";import{discoverSandboxUsage as Fs}from"./discoverSandboxUsage-DdewAOuj.mjs";import Os from"./discoverStorageRulesMetadata-gyO60A5S.mjs";import{discoverWorkflows as Rs}from"./WORKFLOWS_FILENAME-DRaiCNa6.mjs";import{gatePlatformFeatures as Ls,resolveCodegenTarget as Ds}from"./DEFAULT_TARGET-CrhWLUK7.mjs";import{i as T,a as M,e as v,r as ks,b as Ms,s as re,c as Ks,f as _s,d as zs}from"./queries-B_xEHIeL.mjs";import{a as A,c as K,d as bt,e as Us}from"./classify-procedure-call-AKeIK05y.mjs";import Bs from"./discoverAuthApiCalls-C35kkayg.mjs";import qs from"./discoverCrons-wXBfQcfn.mjs";import Je from"./discoverFunctions-BBDziFXy.mjs";import{i as $s,r as js,e as Vs}from"./unwrap-handler-return-CmIWbykC.mjs";import et from"./discoverHttpRoutes-Dmow2gql.mjs";import Ws from"./discoverInserts-C5l2INmE.mjs";import{m as Ae,a as X,s as Pt,d as Hs}from"./index-CCDlo9L7.mjs";import{e as It}from"./exported-procedure-chains-MlZRKqSD.mjs";import Gs from"./discoverMigrations-CWH7T6qz.mjs";import{MUTATORS_FILENAME as Ys,isDefineMutatorCallee as Qs,discoverMutators as tt}from"./MUTATORS_FILENAME-DJvAhDlD.mjs";import Xs from"./discoverNondeterministicCalls-JsO91i57.mjs";import{discoverNotifyConfig as Zs,discoverNotifyCalls as Js}from"./NOTIFY_FILENAME-B-eIjru_.mjs";import en from"./discoverR2sqlCalls-BbfOpwE4.mjs";import tn from"./discoverRlsProcedures-CRshfYZE.mjs";import sn from"./discoverRlsMetadata-DGUGYgWs.mjs";import nn from"./discoverSchema-Bp8DcNq7.mjs";import{secretKindOf as rn,redact as on,isHeuristicSecretKind as an,isSecretishName as cn}from"./redact-Cy14LEnc.mjs";import{discoverShapes as ln}from"./SHAPES_FILENAME-BTdasTq2.mjs";import{emitApp as un}from"./emitApp-BQcIWzkh.mjs";import{buildOpenApiDocument as dn,emitOpenApiModule as fn}from"./buildOpenApiDocument-CGl09_Pi.mjs";import{buildOpenRpcDocument as pn,emitOpenRpcModule as gn}from"./OPENRPC_VERSION-X4hs2-hb.mjs";import{s as mn}from"./parse-validator-BFTp87yz.mjs";import{buildSchemaSnapshot as hn}from"./SchemaSnapshotParseError-D2h88OHU.mjs";const xn=e=>{const t=[],s=e.tables.filter(n=>n.shardMode==="global");return s.some(n=>n.globalBackend!=="hyperdrive")&&t.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),s.some(n=>n.globalBackend==="hyperdrive")&&t.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'}),e.vectorIndexes.length>0&&t.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/vectors.ts` import `@lunora/bindings/vectors`"}),t},En=(e,t)=>{if(t===void 0)return;const s=xn(e).filter(i=>!t.has(i.name));if(s.length===0)return;const n=s.map(i=>` - ${i.name} — ${i.reason}`).join(`
2
+ `);throw new k("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
3
+ ${n}
4
+
5
+ Install them with your package manager, then re-run codegen.`)},vn="env.ts",Sn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return ne(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},An=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&ne(n.getModuleSpecifierValue())}return!1},yn=e=>{if(o.isIdentifier(e))return Sn(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&o.isIdentifier(t)&&An(t)}return!1},Nn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!yn(n.getExpression()))continue;const r=s.getNameNode();if(!o.isIdentifier(r))throw se(r,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},bn=(e,t)=>{const s=f(t,vn);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=Nn(n);if(i.length!==0){if(i.length>1)throw se(n,`lunora/env.ts declares ${i.length.toString()} defineEnv() contracts (${i.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Pn=e=>{const t=n=>o.isIdentifier(n)&&n.getText()==="ctx",s=new Set;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression))t(n.getExpression())&&s.add(n.getName());for(const n of e.getDescendantsOfKind(l.VariableDeclaration)){const i=n.getInitializer(),r=n.getNameNode();if(!(i===void 0||!t(i)||!o.isObjectBindingPattern(r)))for(const a of r.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},In=(e,t)=>{const s=Object.fromEntries(ge.map(n=>[n.key,!1]));for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=new Set(i.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=Pn(i);for(const c of ge)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(ge.every(c=>s[c.key]))break}return s},wt="identity.ts",wn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return ne(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Tn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&ne(n.getModuleSpecifierValue())}return!1},Cn=e=>{if(o.isIdentifier(e))return wn(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&o.isIdentifier(t)&&Tn(t)}return!1},Fn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!Cn(n.getExpression()))continue;const r=s.getNameNode();if(!o.isIdentifier(r))throw se(r,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},On=(e,t)=>{const s=f(t,wt);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=Fn(n);if(i.length!==0){if(i.length>1)throw se(n,`lunora/identity.ts declares ${i.length.toString()} defineIdentity() contracts (${i.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Rn=(e,t)=>{const s=new Map,n=new Map,i=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.bindingName,`workflow "${r.exportName}"`),i.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const a=s.get(r.name);if(a!==void 0)throw new 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=i.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})}},Ln=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:i}=e,r=On(s,t),a=bn(s,t),c=Rs(s,t),u=Cs(s,t),d=cs(s,t);Rn(c,d);const h=ls(s,t),N=Os(s,t),p=Ls(In(s,t),Ds(n,e.target)),S=p.usage,C=Fs(s,t),F=S.browser||C.usesSandboxBrowser,O=Ts(n),V=O??new Set,R=V.has("lunorash");En(i,O);const _=b(f(t,"flags.ts")),z=b(f(t,"notify.ts"));return{agents:d,containers:h,dataModelContent:ds(i),declaredDependencies:O,dependencies:V,env:a,featureUsage:S,hasBrowser:F,hasFlags:_,hasNotify:z,identity:r,platformGate:p,queues:u,serverContent:us({agents:d,containers:h,env:a,hasAccessFacade:S.access,hasAi:S.ai,hasAnalytics:S.analytics,hasBrowser:F,hasFlags:_,hasHyperdrive:S.hyperdrive,hasImages:S.images,hasKv:S.kv,hasNotify:z,hasPayments:S.payments,hasPipelines:S.pipelines,hasR2sql:S.r2sql,hasX402:S.x402,identity:r,queues:u,schema:i,storageRuleBuckets:N.rules.map(oe=>oe.bucket),useUmbrella:R,workflows:c}),storageRulesMetadata:N,usesSandbox:C.usesSandboxBrowser||C.usesSandboxContainer,useUmbrella:R,workflows:c}},Tt=new Set(["delete","get","head","options","patch","post","put"]),Dn=new Set(["handler","stream"]),kn=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,st=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Mn=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Tt.has(t.getName()))return;const s=t.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!o.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},Kn=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||Tt.has(n.getName()))break;s=n.getExpression()}return Mn(s)},_n=e=>{for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression))if(st.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&st.has(s.getText()))return!0}return!1},zn=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||!Dn.has(n.getName()))return;const i=Kn(s);if(!i||!kn.test(i.path))return;const r=s.getArguments()[0],a=r!==void 0&&(o.isArrowFunction(r)||o.isFunctionExpression(r))&&_n(r);return{exportName:e.getName(),file:t,method:i.method,path:i.path,usesGuard:a}},Un=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=zn(i,t);r&&s.push(r)}return s},Bn=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Un(i,E(t,n)))}return s},qn=e=>!o.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",$n=(e,t)=>{if(!qn(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!T(s)||M(s)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},jn=(e,t)=>P(e,t,$n),Vn=new Set(["generateText","streamText"]),Wn=new Set(["messages","prompt","system"]),Hn=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],Gn=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const i of Hn)if(i.methods.has(s)&&i.prefixes.some(r=>n===r||n.startsWith(`${r}.`)))return`${n}.${s}`},Yn=e=>{for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=Gn(t);if(s!==void 0)return s}},Qn=e=>{const t=new Set,s=e.getFirstAncestor(r=>o.isArrowFunction(r)||o.isFunctionExpression(r)||o.isFunctionDeclaration(r)),[n]=s?.getParameters()??[],i=n?.getNameNode();if(i===void 0||!o.isObjectBindingPattern(i))return t;for(const r of i.getElements()){const a=r.getPropertyNameNode()?.getText()??r.getName(),c=r.getNameNode();if(a==="args"&&o.isObjectBindingPattern(c))for(const u of c.getElements())t.add(u.getName())}return t},Xn=e=>{if(ks(e))return!0;const t=Qn(e);return t.size===0?!1:e.getDescendantsOfKind(l.Identifier).some(s=>t.has(s.getText()))},Zn=e=>{for(const t of e.getProperties()){if(!o.isPropertyAssignment(t)||!Wn.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&Xn(s))return!0}return!1},Jn=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=A(n.getExpression());if(i===void 0||!Vn.has(i))continue;const[r]=n.getArguments();if(r===void 0||!o.isObjectLiteralExpression(r))continue;let a;for(const c of r.getDescendantsOfKind(l.CallExpression))if(A(c.getExpression())==="tool"&&(a=Yn(c),a!==void 0))break;a!==void 0&&s.push({exportName:v(n),file:t,line:n.getStartLineNumber(),method:i,sideEffect:a,userInputDerived:Zn(r)})}return s},er=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Jn(i,E(t,n)))}return s},tr=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return o.isIdentifier(t)&&t.getText()==="ctx"},sr=(e,t)=>{if(!tr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!T(s)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},nr=(e,t)=>P(e,t,sr),Ct=e=>e.getProperties().some(t=>o.isSpreadAssignment(t)),rr=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!o.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer();return!n||!o.isObjectLiteralExpression(n)?{objects:[],opaque:!0}:{objects:[n],opaque:Ct(n)}},ir=e=>{const t=[];let s=!1,n=e;for(;o.isCallExpression(n);){const i=n.getExpression();if(!o.isPropertyAccessExpression(i))break;if(i.getName()==="input"){const r=n.getArguments()[0];r&&o.isObjectLiteralExpression(r)?(t.push(r),s||=Ct(r)):s=!0}n=i.getExpression()}return{objects:t,opaque:s}},Ft=(e,t)=>t?ir(t):rr(e),or=e=>e.flatMap(t=>t.getProperties().filter(s=>o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)).map(s=>s.getName())),ar=/\.check\(|\.meta\(|length|max/iu,cr=/\bv\.any\s*\(/u,lr=/\bv\.string\s*\(/u,ur=e=>cr.test(e),dr=e=>lr.test(e)&&!ar.test(e),fr=e=>{const t=[],s=[];for(const n of e)for(const i of n.getProperties()){if(!o.isPropertyAssignment(i))continue;const r=i.getInitializer();if(!r)continue;const a=r.getText(),c=i.getName();ur(a)?t.push(c):dr(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},pr=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=K(s);if(n?.visibility!=="public")return;const{objects:i}=Ft(s,n.receiver),{anyArgs:r,unboundedStringArgs:a}=fr(i);if(!(r.length===0&&a.length===0))return{anyArgs:r,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},gr=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=pr(i,t);r&&s.push(r)}return s},mr=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...gr(i,E(t,n)))}return s},me=e=>e?.getKind()===l.TrueKeyword,hr=e=>e?.getKind()===l.FalseKeyword,xr=e=>e!==void 0&&o.isNumericLiteral(e)&&e.getLiteralValue()===0,Er=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),vr=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isCallExpression(t)&&A(t.getExpression())==="scim"),Sr=e=>e!==void 0&&o.isCallExpression(e)&&Er.has(A(e.getExpression())??""),Ar=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isStringLiteral(t)&&t.getLiteralText()==="*"),yr=e=>{const t=y(e,"advanced"),s=y(e,"emailAndPassword"),n=y(e,"session");return{analyzable:!0,disableCsrfCheck:me(y(t,"disableCSRFCheck")),emailPasswordEnabled:me(y(s,"enabled")),requireEmailVerification:me(y(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:vr(y(e,"plugins"))&&Sr(y(e,"database")),secureCookiesDisabled:hr(y(t,"useSecureCookies")),sessionFreshAgeZero:xr(y(n,"freshAge")),trustedOriginsWildcard:Ar(y(e,"trustedOrigins"))}},Nr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),br=(e,t)=>{if(A(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&o.isObjectLiteralExpression(s)&&s.getProperties().some(r=>o.isSpreadAssignment(r)),i=s!==void 0&&o.isObjectLiteralExpression(s)&&!n?yr(s):Nr();return{exportName:v(e),file:t,line:e.getStartLineNumber(),...i}},Pr=(e,t)=>P(e,t,br),Ir=(e,t)=>{if(!o.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},wr=(e,t,s)=>{const n=Ir(e.getExpression(),s);if(n===void 0)return;const i=e.getArguments()[s.argIndex];if(!(!i||!T(i)||M(i))&&!(s.requireUnmodifiedReach===!0&&!Ms(i)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:n}},Tr=(e,t,s)=>{const n=[];for(const i of e.getDescendantsOfKind(l.CallExpression)){const r=wr(i,t,s);r&&n.push(r)}return n},ie=(e,t,s)=>{const n=[];for(const i of g(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...Tr(r,E(t,i),s))}return n},Cr=new Set(["content","pdf","scrape","screenshot"]),Fr=(e,t)=>ie(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Cr}),Or=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Rr=new Set(["RateLimiter"]),Lr=new Set(["extend"]),Ot=e=>{const t=[],s=[];let n=!1;for(const i of e.getProperties()){if(o.isSpreadAssignment(i)){n=!0;continue}if(o.isPropertyAssignment(i)){const r=i.getName();t.push(r),i.getInitializer()?.getKind()===l.TrueKeyword&&s.push(r);continue}(o.isShorthandPropertyAssignment(i)||o.isMethodDeclaration(i))&&t.push(i.getName())}return{analyzable:!n,presentKeys:t,trueKeys:s}},nt=e=>e&&o.isObjectLiteralExpression(e)?Ot(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Dr=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!o.isReturnStatement(s))return;const n=s.getExpression();return n!==void 0&&o.isObjectLiteralExpression(n)?n:void 0},kr=e=>{if(o.isObjectLiteralExpression(e))return e;if(o.isParenthesizedExpression(e)){const t=e.getExpression();return o.isObjectLiteralExpression(t)?t:void 0}return o.isBlock(e)?Dr(e):void 0},Mr=e=>{const t=e&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,s=t&&kr(t.getBody());return s?Ot(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Kr=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=A(n.getExpression());i!==void 0&&(Or.has(i)?s.push({callee:i,file:t,line:n.getStartLineNumber(),...nt(n.getArguments()[0])}):Lr.has(i)&&s.push({callee:i,file:t,line:n.getStartLineNumber(),...Mr(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(l.NewExpression)){const i=A(n.getExpression());i===void 0||!Rr.has(i)||s.push({callee:i,file:t,line:n.getStartLineNumber(),...nt(n.getArguments()[0])})}return s},_r=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Kr(i,E(t,n)))}return s},rt="ctx.containers.",zr=e=>{if(!e.startsWith(rt))return!1;const t=e.slice(rt.length);return t.length>0&&!t.includes(".")},Ur=(e,t)=>ie(e,t,{argIndex:0,matchReceiver:zr,methods:new Set(["get"])}),Br=new Set(["allow","deny","setAllowed"]),qr=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&o.isPropertyAssignment(s)&&o.isTrueLiteral(s.getInitializerOrThrow())},$r=(e,t)=>{const s=e.getExpression();if(!(!o.isPropertyAccessExpression(s)||s.getName()!=="start"||!qr(e)))return{detail:"enableInternet: true",exportName:v(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},jr=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||!Br.has(s.getName()))return;const n=s.getExpression();if(!(!o.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),exportName:v(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},Vr=(e,t)=>$r(e,t)??jr(e,t),Wr=(e,t)=>P(e,t,Vr),Hr=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Gr=e=>{const t=e.getExpression();if(!o.isIdentifier(t))return;const s=t.getText();return Hr.has(s)?s:void 0},Yr=e=>{const t=[],s=[];for(const n of e.getProperties()){if(o.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(o.isPropertyAssignment(n)){const i=n.getName();t.push(i);const r=n.getInitializer();r&&o.isStringLiteral(r)&&r.getLiteralText()===""&&s.push(i);continue}(o.isShorthandPropertyAssignment(n)||o.isMethodDeclaration(n)||o.isGetAccessorDeclaration(n))&&t.push(n.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Qr=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getDescendantsOfKind(l.CallExpression)){const c=Gr(a);if(c===void 0)continue;const u=a.getArguments()[0],d=u&&o.isObjectLiteralExpression(u)?Yr(u):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:d.analyzable,emptyKeys:d.emptyKeys,factory:c,file:r,line:a.getStartLineNumber(),presentKeys:d.presentKeys})}}return s},Xr=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Zr=new Set(["dbRateLimit","rateLimit"]),Jr=e=>{if(!e||!o.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&o.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===l.TrueKeyword},ei=(e,t)=>{const s=A(e.getExpression());if(s===void 0)return;const n=Xr.get(s);if(n!==void 0)return{callee:s,exportName:v(e),failOpen:Jr(e.getArguments()[n]),file:t,limitName:Zr.has(s)?yt(e):"",line:e.getStartLineNumber()}},ti=(e,t)=>P(e,t,ei),si=new Set(["boolean","number","object","string"]),ni=e=>{const t=e.getName();if(!si.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="flags"&&Ee(s.getExpression()))return t;const n=s.getExpression();if(s.getName()==="details"&&o.isPropertyAccessExpression(n)&&n.getName()==="flags"&&Ee(n.getExpression()))return t},ri=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=ni(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(o.isStringLiteral(n)||o.isNoSubstitutionTemplateLiteral(n)))return;const i=n.getLiteralValue();return i.length>0?{key:i,type:s}:void 0},ii=(e,t)=>{const s=new Map;for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of i.getDescendantsOfKind(l.CallExpression)){const a=ri(r);a&&!s.has(a.key)&&s.set(a.key,a.type)}}return[...s.entries()].map(([n,i])=>({key:n,type:i})).toSorted((n,i)=>n.key.localeCompare(i.key))},oi=e=>{const t=e.getInitializer();if(!t||!o.isCallExpression(t))return;const s=K(t);if(s?.kind!=="query")return;const n=Is(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},it=e=>{const t=e.getParent();return t&&o.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},ai=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!o.isIdentifier(t)||t.getText()!=="ctx")return;const s=it(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=it(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},ci=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const i=ai(n);i!==void 0&&s.push({callee:i,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},li=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=oi(i);r&&s.push(...ci(r,t))}return s},ui=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...li(i,E(t,n)))}return s},di=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Ee(t.getExpression())},fi=e=>{if(e?.getKind()===l.TrueKeyword)return!0;if(e?.getKind()===l.FalseKeyword)return!1},pi=(e,t)=>{if(!di(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(o.isStringLiteral(s)||o.isNoSubstitutionTemplateLiteral(s)))return;const i=s.getLiteralValue(),r=fi(n);if(!(i.length===0||r===void 0))return{defaultValue:r,exportName:v(e),file:t,key:i,line:e.getStartLineNumber()}},gi=(e,t)=>P(e,t,pi),mi=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const s=t.getTypeAtLocation(e).getProperty("types");if(!s)return;const n=s.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!n)return;const i=n.getTypeAtLocation(e),r=i.getText(e);if(!r||r==="any"||r==="never"||$s(r))return;const a=e.getSourceFile().getFilePath();return js(i,e,a)?Vs(i,e,a,0,new Set):r},hi=e=>{const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},xi=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},Ei=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getDescendantsOfKind(l.CallExpression))hi(a)&&s.push({file:r,indexName:xi(a),line:a.getStartLineNumber()})}return s},j=e=>e!==void 0&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,Rt=e=>{const t=e.getArguments()[0],s=j(t);if(s!==void 0)return s;if(t===void 0||!o.isObjectLiteralExpression(t))return;const n=t.getProperty("handler");return n!==void 0&&o.isPropertyAssignment(n)?j(n.getInitializer()):void 0},vi=new Set(["delete","get","head","options","patch","post","put"]),Si=new Set(["handler","stream"]),Ai=new Set(["runAction","runMutation"]),yi=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),Z=(e,t)=>e!==void 0&&o.isIdentifier(e)&&e.getText()===t,ot=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const n=s.getNameNode();if(t)return o.isIdentifier(n)?n.getText():void 0;if(o.isObjectBindingPattern(n)){for(const i of n.getElements())if((i.getPropertyNameNode()?.getText()??i.getNameNode().getText())==="ctx"){const a=i.getNameNode();return o.isIdentifier(a)?a.getText():void 0}}},at=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);o.isCallExpression(s)&&n.unshift(s);for(const i of n){const r=i.getExpression();if(!o.isPropertyAccessExpression(r))continue;const a=r.getName(),c=r.getExpression();if(Ai.has(a)&&Z(c,t))return a;if(yi.has(a)&&o.isPropertyAccessExpression(c)&&c.getName()==="db"&&Z(c.getExpression(),t))return`db.${a}`}},ct=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(l.PropertyAccessExpression))if(n.getName()==="auth"&&Z(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(l.VariableDeclaration)){const i=n.getNameNode();if(!(!o.isObjectBindingPattern(i)||!Z(n.getInitializer(),t))){for(const r of i.getElements())if((r.getPropertyNameNode()?.getText()??r.getNameNode().getText())==="auth")return!0}}return!1},Ni=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Si.has(t.getName()))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))return;const i=n.getName();if(vi.has(i)){const r=n.getExpression();return o.isIdentifier(r)&&r.getText()==="httpRoute"?i.toUpperCase():void 0}s=n.getExpression()}},bi=(e,t)=>{const s=e.getExpression();if(o.isIdentifier(s)&&s.getText()==="httpAction"){const c=j(e.getArguments()[0]),u=c&&ot(c,!0);if(!c||u===void 0)return;const d=at(c,u);return d===void 0?void 0:{exportName:v(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ct(c,u),sideEffect:d}}const n=Ni(e);if(n===void 0)return;const i=j(e.getArguments()[0]),r=i&&ot(i,!1);if(!i||r===void 0)return;const a=at(i,r);return a===void 0?void 0:{exportName:v(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:ct(i,r),sideEffect:a}},Pi=(e,t)=>P(e,t,bi),Ii=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),wi=new Set(["append","set"]),Lt=e=>e!==void 0&&(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",lt=(e,t)=>(o.isCallExpression(e)?[e,...e.getDescendantsOfKind(l.CallExpression)]:e.getDescendantsOfKind(l.CallExpression)).some(n=>Ii.has(A(n.getExpression())??"")&&_s(n,t)),Ti=(e,t)=>{if(lt(e,t))return!0;const s=re(e);return s!==void 0&&lt(s,t)},ve=(e,t)=>Ks(e,t)&&!Ti(e,t),Ci=e=>{if(o.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=re(e);return t!==void 0&&o.isNewExpression(t)&&A(t.getExpression())==="Headers"},J=e=>{if(e===void 0)return;if(o.isObjectLiteralExpression(e))return e;const t=re(e);return t!==void 0&&o.isObjectLiteralExpression(t)?t:void 0},ye=(e,t,s)=>{for(const n of e.getProperties())if(o.isPropertyAssignment(n)){const i=n.getInitializer();i!==void 0&&ve(i,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:Lt(n.getNameNode()),line:i.getStartLineNumber(),via:t})}else if(o.isShorthandPropertyAssignment(n)){const i=n.getNameNode();ve(i,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:n.getName(),line:i.getStartLineNumber(),via:t})}else if(o.isSpreadAssignment(n)){const i=J(n.getExpression());i!==void 0&&ye(i,t,s)}},Dt=(e,t)=>{const s=J(e);if(s===void 0)return;const n=s.getProperty("headers");if(n===void 0||!o.isPropertyAssignment(n))return;const i=J(n.getInitializer());i!==void 0&&ye(i,"response-init",t)},Fi=(e,t)=>{const s=A(e.getExpression());if(s==="Response")Dt(e.getArguments()[1],t);else if(s==="Headers"){const n=J(e.getArguments()[0]);n!==void 0&&ye(n,"headers-ctor",t)}},Oi=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName(),i=s.getExpression();if(n==="json"&&o.isIdentifier(i)&&i.getText()==="Response"){Dt(e.getArguments()[1],t);return}if(wi.has(n)&&Ci(i)){const r=e.getArguments()[1];r!==void 0&&ve(r,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:Lt(e.getArguments()[0]),line:r.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},Ri=(e,t)=>{for(const s of e.getDescendantsOfKind(l.NewExpression))Fi(s,t);for(const s of e.getDescendantsOfKind(l.CallExpression))Oi(s,t)},Li=(e,t)=>{const s=e.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=j(e.getArguments()[0]);if(n===void 0)return[];const i=n.getParameters()[1];if(i===void 0)return[];const r=i.getNameNode();if(!o.isIdentifier(r))return[];const a=[];return Ri(n,{exportName:v(e),relativePath:t,requestName:r.getText(),rows:a}),a},Di=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression))s.push(...Li(n,t));return s},ki=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Di(i,E(t,n)))}return s},Mi=new Set(["auth","context.auth","ctx.auth"]),Ki="userId",_i=e=>{const t=new Set;for(const s of e.getProperties()){if(o.isSpreadAssignment(s))return;(o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)||o.isMethodDeclaration(s))&&t.add(s.getName())}return t},zi=(e,t)=>{const s=f(t,wt);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const i of n.getDescendantsOfKind(l.CallExpression)){if(A(i.getExpression())!=="defineIdentity")continue;const[r]=i.getArguments();return r&&o.isObjectLiteralExpression(r)?_i(r):void 0}},ut=e=>{if(!(e===void 0||!o.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Mi.has(e.getExpression().getText())?e:void 0},Ui=e=>{if(o.isPropertyAccessExpression(e)&&ut(e.getExpression())!==void 0)return e.getName();if(o.isElementAccessExpression(e)&&ut(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&o.isStringLiteral(t)?t.getLiteralValue():void 0}},Bi=(e,t,s)=>{const n=[];for(const i of e.getDescendants()){const r=Ui(i);r!==void 0&&n.push({declared:r===Ki||s.has(r),exportName:v(i),file:t,key:r,line:i.getStartLineNumber()})}return n},qi=(e,t)=>{const s=zi(e,t);if(s===void 0)return[];const n=[];for(const i of g(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...Bi(r,E(t,i),s))}return n},$i=(e,t)=>{if(A(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=y(s,"key");if(!(!n||!T(n)||M(n)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},ji=(e,t)=>P(e,t,$i),Vi=new Set(["delete","get","getRaw","getWithMetadata","put"]),Wi=(e,t)=>ie(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:Vi}),Hi=new Set(["queue","send"]),dt=new Set(["bcc","cc","to"]),Gi=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!Hi.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},Yi=e=>o.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(o.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return dt.has(t.getName())&&T(n)&&!M(n)}if(!o.isPropertyAssignment(t)||!dt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&T(s)&&!M(s)}):!1,Qi=(e,t)=>{const s=Gi(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!Yi(n)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s}},Xi=(e,t)=>P(e,t,Qi),Zi=e=>o.isPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?o.isComputedPropertyName(e.getNameNode()):!1,Ji=e=>o.isPropertyAssignment(e)||o.isShorthandPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?Zi(e):!0,kt=(e,t=!1)=>{for(const s of e.getProperties()){if(Ji(s))return!0;if(t)continue;if(!o.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!o.isObjectLiteralExpression(n)||kt(n,!0))return!0}return!1},eo=(e,t)=>{for(const s of g(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:i}of It(n))for(const r of Ae(i)){const a=r.getArguments()[0];if(a!==void 0&&(!o.isObjectLiteralExpression(a)||kt(a)))return!0}}return!1},to=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const i=X(n);if(i===void 0||!o.isPropertyAssignment(n))continue;const r=n.getInitializer();if(!(!r||!o.isObjectLiteralExpression(r)))for(const a of r.getProperties()){const c=X(a);c!==void 0&&s.push({column:c,strategy:Pt(a),table:i})}}return s},so=(e,t)=>{const s=new Map;for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:r}of It(i))for(const a of Ae(r))for(const c of to(a)){const u=`${c.table}\0${c.column}`;s.has(u)||s.set(u,c)}}return{columns:[...s.values()]}},no=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!o.isObjectLiteralExpression(n))return[];const i=[];for(const r of n.getProperties()){const a=X(r);if(a===void 0||!o.isPropertyAssignment(r))continue;const c=r.getInitializer();if(!(!c||!o.isObjectLiteralExpression(c)))for(const u of c.getProperties()){const d=X(u);if(d===void 0)continue;const h=Pt(u);h!=="custom"&&i.push({column:d,exportName:t,file:s,line:u.getStartLineNumber(),strategy:h,table:a})}}return i},ro=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?K(s):void 0;return n?.receiver?Ae(n.receiver).flatMap(i=>no(i,e.getName(),t)):[]},io=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...ro(c,r))}return s},oo=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return L(s)},ao=e=>{const t=e.getArguments()[0];if(t===void 0||!o.isObjectLiteralExpression(t))return;const s=t.getProperty("server");if(s!==void 0)return o.isPropertyAssignment(s)?s.getInitializer():s},co=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==l.CallExpression)return;const s=t;return Qs(s.getExpression())?s:void 0},lo=e=>{const t=co(e),s=t===void 0?void 0:ao(t);if(s===void 0)return[];const n=e.getNameNode(),i=o.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(l.CallExpression).filter(r=>oo(r)).map(r=>({exportName:i,file:"lunora/mutators.ts",line:r.getStartLineNumber()}))},uo=e=>e.getVariableDeclarations().flatMap(t=>lo(t)),fo=(e,t)=>{const s=f(t,Ys);if(!b(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return uo(n)},po=new Set(["delete","get","patch"]),go=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),mo=new Set(["auth","identity","session","user"]),ho=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),xo=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!L(t.getExpression()))return;const s=e.getArguments()[0];return s&&o.isStringLiteral(s)?s.getLiteralText():""},Eo=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(o.isAsExpression(s)||o.isParenthesizedExpression(s)||o.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!o.isVariableDeclaration(s))return;const n=s.getNameNode();return o.isIdentifier(n)?n.getText():void 0},vo=(e,t)=>e.getDescendantsOfKind(l.Identifier).some(s=>s.getText()===t),So=e=>o.isThrowStatement(e)||o.isReturnStatement(e)||e.getDescendantsOfKind(l.ThrowStatement).length>0||e.getDescendantsOfKind(l.ReturnStatement).length>0,Ao=(e,t)=>e.getDescendantsOfKind(l.IfStatement).some(s=>vo(s.getExpression(),t)&&So(s.getThenStatement())),yo=(e,t)=>{for(const s of e.getDescendantsOfKind(l.CallExpression)){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))continue;const i=n.getName();if(!po.has(i))continue;const r=n.getExpression();if(!(L(r)||o.isPropertyAccessExpression(r)&&L(r.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&o.isIdentifier(c)&&c.getText()===t)return i}},No=e=>{let t=e;for(;o.isPropertyAccessExpression(t)||o.isElementAccessExpression(t)||o.isNonNullExpression(t)||o.isParenthesizedExpression(t)||o.isAsExpression(t)||o.isAwaitExpression(t);)t=t.getExpression();return o.isIdentifier(t)?t.getText():void 0},bo=e=>e.getDescendantsOfKind(l.CallExpression).some(t=>t.getArguments().some(s=>No(s)==="ctx")),Po=e=>e.getDescendantsOfKind(l.BinaryExpression).some(t=>ho.has(t.getOperatorToken().getKind())?o.isPropertyAccessExpression(t.getLeft())||o.isPropertyAccessExpression(t.getRight()):!1),Io=e=>{for(const t of e.getDescendantsOfKind(l.Identifier))if(go.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&s.getText()==="ctx"&&mo.has(t.getName()))return!0}return bo(e)||Po(e)},wo=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=K(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const i=Rt(s);if(i===void 0)return[];const r=n.receiver!==void 0&&bt(n.receiver,"use","rls"),a=Io(i),c=new Set,u=[];for(const d of i.getDescendantsOfKind(l.CallExpression)){const h=xo(d);if(h===void 0)continue;const N=Eo(d);if(N===void 0||c.has(N)||!Ao(i,N))continue;const p=yo(i,N);p!==void 0&&(c.add(N),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:p,table:h,usesRls:r,visibility:n.visibility}))}return u},To=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...wo(c,r))}return s},Co=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Fo=new Set(["insert","insertManyUnsafe","patch","replace"]),Oo=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!Fo.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||s.getName()!=="db")return;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"?t:void 0},Ro=(e,t)=>{if(t!=="insertManyUnsafe")return o.isObjectLiteralExpression(e)?[e]:[];if(!o.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())o.isObjectLiteralExpression(n)&&s.push(n);return s},Lo=(e,t,s,n)=>{const i=[];for(const r of e.getProperties()){let a,c;o.isPropertyAssignment(r)?(a=r.getName(),c=r.getInitializer()):o.isShorthandPropertyAssignment(r)&&(a=r.getName(),c=r.getNameNode()),!(a===void 0||c===void 0||!Co.has(a))&&T(c)&&!M(c)&&i.push({exportName:v(s),field:a,file:n,line:s.getStartLineNumber(),method:t})}return i},Do=(e,t)=>{const s=Oo(e.getExpression());if(s===void 0)return[];const n=e.getArguments()[1];return n?Ro(n,s).flatMap(i=>Lo(i,s,e,t)):[]},ko=(e,t,s)=>{const n=[];for(const i of e.getDescendantsOfKind(l.CallExpression))for(const r of Do(i,t)){const a=s(r.exportName);n.push(a===void 0?r:{...r,visibility:a})}return n},Mo=(e,t,s=[])=>{const n=[],i=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));for(const r of g(t)){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=E(t,r);n.push(...ko(a,c,u=>i.get(`${c}:${u}`)))}return n},Ko=["providerSubscriptionId","state"],_o=["providerEventId","processedAt"],ft=(e,t)=>t.every(s=>s in e.shape),zo=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&ft(t,Ko)&&ft(s,_o)},Uo=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Bo=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,qo=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&o.isPropertyAssignment(t)?Bo(t.getInitializer()):void 0},$o=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!Uo.has(s))return;const[n]=e.getArguments(),i=n&&o.isObjectLiteralExpression(n)?qo(n):void 0;return{callee:s,exportName:v(e),file:t,line:e.getStartLineNumber(),...i===void 0?{}:{toleranceSeconds:i}}},jo=(e,t)=>P(e,t,$o),Vo=new Set(["defineQueue","defineWorkflow"]),Wo=new Set(["run","runAction","runMutation","runQuery"]),Ho=new Set(["api","internal"]),Go=e=>{const t=e.getExpression();return o.isIdentifier(t)?t.getText():void 0},Yo=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!o.isPropertyAssignment(s))return;const n=s.getInitializer();if(n&&(o.isArrowFunction(n)||o.isFunctionExpression(n)))return n},Mt=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&o.isIdentifier(s)?s.getText():void 0},Kt=(e,t)=>e===t||e.startsWith(`${t}.`),_t=e=>{const t=e.getDescendantsOfKind(l.PropertyAccessExpression);return o.isPropertyAccessExpression(e)&&t.push(e),t},pt=e=>{const t=e.getParent();return o.isPropertyAccessExpression(t)&&t.getNameNode()===e||o.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(o.isBindingElement(t)&&t.getNameNode()===e)},zt=e=>{const t=e.getDescendantsOfKind(l.Identifier).filter(s=>pt(s));return o.isIdentifier(e)&&pt(e)&&t.push(e),t},Qo=e=>{if(!o.isVariableDeclaration(e))return[];const t=e.getNameNode();return o.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(l.BindingElement).map(s=>s.getName())},Xo=e=>{const t=Mt(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(l.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const i=n.getInitializer(),r=o.isVariableDeclarationList(i)?i.getDeclarations()[0]?.getNameNode():void 0;r&&o.isIdentifier(r)&&s.push(`${r.getText()}.body`)}return s},Zo=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:Xo(e),i=new Set,r=a=>_t(a).some(c=>n.some(u=>Kt(c.getText(),u)))?!0:zt(a).some(c=>i.has(c.getText()));for(const a of e.getDescendantsOfKind(l.VariableDeclaration)){const c=a.getInitializer();if(c&&r(c))for(const u of Qo(a))i.add(u)}return{names:i,prefixes:n}},Jo=(e,t)=>_t(e).some(s=>t.prefixes.some(n=>Kt(s.getText(),n)))?!0:zt(e).some(s=>t.names.has(s.getText())),ea=e=>{if(e===void 0||!o.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;o.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const n=t.at(-1);if(!(n===void 0||!o.isIdentifier(s)||!Ho.has(s.getText())||t.length<2))return{exportName:n,file:t.slice(0,-1).join("/")}},ta=(e,t,s)=>{const n=Mt(e,0);if(n===void 0)return[];const i=Zo(e,t,n),r=[];for(const a of e.getDescendantsOfKind(l.CallExpression)){const c=a.getExpression();if(!o.isPropertyAccessExpression(c)||!Wo.has(c.getName())||c.getExpression().getText()!==n)continue;const u=a.getArguments()[1];if(!u||!Jo(u,i))continue;const d=ea(a.getArguments()[0]);d!==void 0&&r.push({dispatchKind:t,file:s,handlerExport:v(a),line:a.getStartLineNumber(),targetExport:d.exportName,targetFile:d.file})}return r},sa=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=Go(n);if(i===void 0||!Vo.has(i))continue;const r=Yo(n);r!==void 0&&s.push(...ta(r,i==="defineQueue"?"queue":"workflow",t))}return s},na=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...sa(i,E(t,n)))}return s},gt={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},mt=new Set(["account","credential","member","passkey","session","user"]),ra=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),ia=e=>{const s=ra(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return mt.has(s)||mt.has(n)},oa=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},aa=(e,t)=>{const{objects:s,opaque:n}=Ft(e,t);return or(s).some(i=>oa(i))?!0:n?void 0:!1},ca=e=>{const t=e.getArguments()[0];return!t||!o.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},la=e=>{if(o.isCallExpression(e))return e;if(!o.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&o.isCallExpression(s)?s:void 0},Q={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},ua=e=>{const t=la(e),s=t?A(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=ca(t);return{...Q,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in gt?{...Q,[gt[s]]:!0}:Q},da=e=>{const t={...Q};let s=e;for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))break;const i=n.getName()==="use"?s.getArguments()[0]:void 0;if(i){const r=ua(i);t.usesCaptcha||=r.usesCaptcha,t.usesEmailGate||=r.usesEmailGate,t.usesMask||=r.usesMask,t.usesRateLimit||=r.usesRateLimit,t.usesRls||=r.usesRls}s=n.getExpression()}return t},fa=new Set(["insert","insertMany","insertManyUnsafe","replace"]),pa=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!fa.has(t.getName()))return!1;const s=t.getExpression();if(!L(s))return!1;const i=e.getArguments()[0];return!i||!(o.isStringLiteral(i)||o.isNoSubstitutionTemplateLiteral(i))?!1:ia(i.getLiteralText())},ga=new Set(["create","runAfter","runAt","send","sendBatch"]),ma=new Set(["queues","scheduler","workflows"]),ha=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!ga.has(t.getName()))return!1;let s=t.getExpression();for(;o.isCallExpression(s)||o.isElementAccessExpression(s)||o.isPropertyAccessExpression(s);){if(o.isPropertyAccessExpression(s)&&ma.has(s.getName())){const n=s.getExpression();if(o.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},xa=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return L(s)},Ut=new Set(["generateObject","generateText","streamObject","streamText"]),Ea=e=>{const t=A(e.getExpression());return t!==void 0&&Ut.has(t)},va=e=>{const t=A(e.getExpression());if(t===void 0||!Ut.has(t))return!1;const s=e.getArguments()[0];return!s||!o.isObjectLiteralExpression(s)||s.getProperties().some(n=>o.isSpreadAssignment(n))?!1:!s.getProperty("maxOutputTokens")},Sa=new Set(["log","span","trace"]),Aa=new Set(["ai"]),ya=new Set(["email","mail"]),Na=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),he=(e,t)=>e.getDescendantsOfKind(l.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"}),ba=new Set([l.ArrowFunction,l.FunctionDeclaration,l.FunctionExpression,l.GetAccessor,l.MethodDeclaration,l.SetAccessor]),Pa=new Set(["every","filter","flatMap","forEach","map","some"]),Ia=new Set(["all","allSettled","race"]),wa=e=>{const t=e.getParent();if(!t||!o.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName();if(Pa.has(n))return t;const i=s.getExpression();if(o.isIdentifier(i)&&i.getText()==="Promise"&&Ia.has(n))return t},Ta=e=>{let t=e.getParent();for(;t;){if(o.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(ba.has(t.getKind())){const s=wa(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},Ca=e=>{let t=e;for(;;){const s=t.getParent();if(!o.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;if(s.getName()==="catch")return!0;if(s.getName()!=="then"&&s.getName()!=="finally")return!1;const n=s.getParent();if(!o.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},Fa=e=>{let t=e;for(;;){const s=t.getParent();if(o.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return o.isCallExpression(s)&&s.getExpression()===t?s:void 0}},Oa=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression)){if(!Na.has(n.getName()))continue;const i=n.getExpression();if(!o.isIdentifier(i)||i.getText()!=="ctx")continue;const r=Fa(n);r&&(t=!0,!Ta(r)&&!Ca(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},Ra=e=>e.getDescendantsOfKind(l.ThrowStatement).some(t=>{const s=t.getExpression();if(!o.isNewExpression(s))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="Error"}),ht="lunora-advisor-exempt",La=/^[\s*/]+/u,Da=/[\w-]/u,ka=e=>{const s=(e.getFirstAncestorByKind(l.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
6
+ `);for(const n of s.split(`
7
+ `)){const i=n.replace(La,"");if(!i.startsWith(ht))continue;const r=i.slice(ht.length);if(Da.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:""}},Ma=e=>{const[t]=e.getArguments();if(t){if(o.isObjectLiteralExpression(t)){const s=t.getProperty("handler");return s?o.isPropertyAssignment(s)?s.getInitializer():o.isShorthandPropertyAssignment(s)?s.getNameNode():o.isMethodDeclaration(s)?s:void 0:void 0}return t}},Ka=(e,t)=>{const s=Ma(t);if(!s)return;if(o.isArrowFunction(s)||o.isFunctionExpression(s)||o.isMethodDeclaration(s))return e;if(!o.isIdentifier(s))return;const n=s.getSourceFile(),i=s.getText(),r=n.getVariableDeclaration(i)?.getInitializer();return r&&(o.isArrowFunction(r)||o.isFunctionExpression(r))?r:n.getFunction(i)},_a=e=>{let t=!1,s=!1,n=!1,i=!1,r=!1;for(const u of e.getDescendantsOfKind(l.CallExpression))if(pa(u)&&(r=!0),ha(u)&&(t=!0),xa(u)&&(i=!0),Ea(u)&&(s=!0),va(u)&&(n=!0),r&&t&&i&&n)break;const{handlesErrors:a,reachesOutbound:c}=Oa(e);return{callsMail:he(e,ya),emitsEvent:he(e,Sa),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||he(e,Aa),throwsBareError:Ra(e),unboundedAiGeneration:n,usesInsertManyUnsafe:i,writesUserTable:r}},za=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=K(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const i=n.receiver?da(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},r=Ka(e,s);return{...r?_a(r):{},...ka(e),...i,analyzableBody:r!==void 0,exportName:e.getName(),file:t,hasEmailArg:aa(s,n.receiver),kind:n.kind,visibility:n.visibility}},Ua=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=za(i,t);r&&s.push(r)}return s},Ba=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ua(i,E(t,n)))}return s},qa=new Set(["dbRateLimit","rateLimit"]),$a=e=>o.isArrowFunction(e)?e.getBody():e,ja=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!qa.has(s))return;const n=e.getArguments()[2];if(!n)return;const i=y(n,"key");if(!i)return;const r=$a(i);if(!(!T(r)||M(r)))return{callee:s,exportName:v(e),file:t,limitName:yt(e),line:e.getStartLineNumber()}},Va=(e,t)=>P(e,t,ja),Wa=new Set(["findFirst","findFirstOrThrow","findMany","get"]),Ha=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Wa.has(t.getName()))return;const s=t.getExpression();if(L(s)){const n=e.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}if(o.isPropertyAccessExpression(s)&&L(s.getExpression()))return s.getName()},Ga=e=>{let t=e;for(;o.isCallExpression(t);){const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&L(s.getExpression())){const n=t.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},Ya=e=>{let t=Ze(e)??e;for(;o.isAwaitExpression(t);)t=Ze(t.getExpression())??t.getExpression();return t},Bt=(e,t=!1)=>{const s=Ya(e);if(o.isIdentifier(s)){if(t)return;const n=re(s);return n===void 0?void 0:Bt(n,!0)}if(o.isCallExpression(s))return Ha(s)??Ga(s)},Qa=e=>{const t=e.getBody();if(!o.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(l.ReturnStatement)){const i=n.getFirstAncestor(a=>o.isArrowFunction(a)||o.isFunctionExpression(a)||o.isFunctionDeclaration(a)),r=n.getExpression();i===e&&r!==void 0&&s.push(r)}return s},Xa=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=K(s);if(n?.kind!=="query")return[];const i=Rt(s);if(i===void 0)return[];const r=n.receiver!==void 0&&Us(n.receiver,"output"),a=n.receiver!==void 0&&bt(n.receiver,"use","mask"),c=new Set,u=[];for(const d of Qa(i)){const h=Bt(d);h===void 0||c.has(h)||(c.add(h),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:h,usesMask:a,usesOutput:r,visibility:n.visibility}))}return u},Za=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Xa(c,r))}return s},Ja=e=>{if(!e||!o.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)||o.isMethodDeclaration(s)||o.isGetAccessorDeclaration(s))&&t.push(s.getName());return t},ec=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?K(s):void 0;if(!n)return[];const i=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Nt(r);if(a===void 0)continue;const c=Ja(y(a.options,"with"));c.length!==0&&i.push({exportName:e.getName(),file:t,line:r.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return i},tc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...ec(c,r))}return s},ee=e=>{if(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(o.isBinaryExpression(e)&&e.getOperatorToken().getKind()===l.PlusToken){const t=ee(e.getLeft()),s=ee(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},sc=e=>{let t=e,s=t.getParent();for(;s!==void 0&&o.isBinaryExpression(s)&&s.getOperatorToken().getKind()===l.PlusToken;)t=s,s=t.getParent();return t!==e&&ee(t)!==void 0},nc=/(?:^|\/)__tests__\//u,rc=/\.(?:spec|test)$/u,ic=e=>nc.test(e)||rc.test(e),oc=e=>{const t=e.getParent();if(t!==void 0){if(o.isVariableDeclaration(t)||o.isPropertyAssignment(t)||o.isPropertySignature(t))return t.getName();if(o.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.EqualsToken)return t.getLeft().getText()}},ac=(e,t,s)=>an(e)?!ic(s)&&cn(oc(t)):!0,cc=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(l.BinaryExpression),...e.getDescendantsOfKind(l.StringLiteral),...e.getDescendantsOfKind(l.NoSubstitutionTemplateLiteral)],i=new Set;for(const r of n){if(sc(r))continue;const a=ee(r);if(a===void 0)continue;const c=rn(a);if(c===void 0||!ac(c,r,t))continue;const u=r.getStartLineNumber(),d=`${String(u)}:${c}`;i.has(d)||(i.add(d),s.push({file:t,kind:c,line:u,preview:on(a)}))}return s},lc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...cc(i,E(t,n)))}return s},uc=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?K(s):void 0;if(!n)return[];const i=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Nt(r);if(a===void 0)continue;const c=y(a.options,"includeDeleted");if(c===void 0)continue;const u=o.isTrueLiteral(c),d=!u&&T(c);!u&&!d||i.push({exportName:e.getName(),file:t,fromArgs:d,hardcodedTrue:u,line:r.getStartLineNumber(),table:a.table,visibility:n.visibility})}return i},dc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...uc(c,r))}return s},fc=new Set(["query","unsafe"]),pc=e=>{if(!o.isPropertyAccessExpression(e)||!fc.has(e.getName()))return!1;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return o.isIdentifier(s)&&s.getText()==="ctx"},gc=e=>o.isBinaryExpression(e)||o.isTemplateExpression(e),mc=e=>e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()??"<module>",hc=(e,t)=>{if(!pc(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!gc(s)))return{exportName:mc(e),file:t,line:s.getStartLineNumber()}},xc=(e,t)=>P(e,t,hc),Ec=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],vc=e=>{for(const[t,s]of Ec)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},Sc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of i.getImportDeclarations()){const a=r.getModuleSpecifierValue(),c=vc(a);c!==void 0&&s.push({file:E(t,n),line:r.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},Ac=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),yc=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return ie(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:Ac,requireUnmodifiedReach:!0}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},Nc=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),bc=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,Pc=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!o.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const i of e.getProperties()){if(o.isSpreadAssignment(i)){n=!0;continue}if(o.isPropertyAssignment(i)){const r=i.getName();t.push(r),r==="expiresInSeconds"&&(s=bc(i.getInitializer()));continue}(o.isShorthandPropertyAssignment(i)||o.isMethodDeclaration(i))&&t.push(i.getName())}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},Ic=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName(),s=Nc.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},wc=(e,t)=>{const s=Ic(e.getExpression());if(s!==void 0)return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s.method,...Pc(e.getArguments()[s.optionsIndex])}},Tc=(e,t)=>P(e,t,wc),Cc=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings/kv"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),Fc=new Set(["RegisteredAction","RegisteredMutation","RegisteredQuery"]),Ne=e=>{const t=e.getType(),s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName();return s!==void 0&&Fc.has(s)?s:void 0},qt=e=>{const t=e.getInitializer();return t===void 0?!1:o.isCallExpression(t)||o.isIdentifier(t)||o.isPropertyAccessExpression(t)},$t={cause:"codegen recognises a procedure only when the initializer is a builder chain, and this one is produced by a call or an alias",remediation:"A factory that returns a procedure cannot be read statically — inline it, or export the chain the factory builds."},Oc={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."},be=(e,t,s,n,i)=>({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 — ${i.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);\`. ${i.remediation}`,title:"Procedure exists at runtime but is missing from the generated API"}),Rc=(e,t,s)=>{const n=[];for(const i of e.getVariableStatements().filter(r=>r.isExported()))for(const r of i.getDeclarations()){const a=r.getName();if(s.has(`${t}:${a}`)||!qt(r))continue;const c=Ne(r);c!==void 0&&n.push(be(t,a,c,r.getStartLineNumber(),$t))}return n},Lc=(e,t,s)=>{if(s.has(`${t}:default`))return[];const n=[];for(const i of e.getExportAssignments().filter(r=>!r.isExportEquals())){const r=Ne(i.getExpression());r!==void 0&&n.push(be(t,"default",r,i.getStartLineNumber(),$t))}return n},Dc=(e,t,s)=>{const n=[];for(const i of e.getExportDeclarations().filter(r=>r.getModuleSpecifier()===void 0))for(const r of i.getNamedExports()){const a=r.getAliasNode()?.getText()??r.getName();if(s.has(`${t}:${a}`))continue;const c=r.getLocalTargetDeclarations().find(d=>o.isVariableDeclaration(d));if(c===void 0||!qt(c))continue;const u=Ne(c);u!==void 0&&n.push(be(t,a,u,r.getStartLineNumber(),Oc))}return n},kc=(e,t,s)=>[...Rc(e,t,s),...Lc(e,t,s),...Dc(e,t,s)],Mc=(e,t,s)=>{const n=new Set(s.map(r=>`${r.filePath}:${r.exportName}`)),i=[];for(const r of g(t)){const a=e.getSourceFile(r);a!==void 0&&i.push(...kc(a,E(t,r),n))}return i.toSorted((r,a)=>r.cacheKey.localeCompare(a.cacheKey))},Kc=new Set(["when","where"]),xe=new Set(["definePolicy","defineShape"]),_c=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(o.isPropertyAccessExpression(t)){const n=t.getName();return xe.has(n)?n:void 0}if(!o.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(o.isImportSpecifier(n)){const i=n.getNameNode().getText();return xe.has(i)?i:void 0}const s=t.getText();return xe.has(s)?s:void 0},zc=e=>o.isObjectLiteralExpression(e)&&e.getProperties().length===0,jt=e=>{if(e!==void 0){if(o.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===l.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(zc(e))return"empty-object";if(o.isParenthesizedExpression(e))return jt(e.getExpression())}},Pe=e=>e.getAncestors().find(t=>o.isArrowFunction(t)||o.isFunctionExpression(t)||o.isFunctionDeclaration(t)),Uc=e=>e.getDescendantsOfKind(l.ReturnStatement).filter(t=>Pe(t)===e),Vt=e=>e.getDescendantsOfKind(l.ConditionalExpression).filter(t=>Pe(t)===e),Bc=e=>{const t=Uc(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(l.IfStatement)!==void 0)||Vt(e).length>0},qc=e=>e.getDescendantsOfKind(l.IfStatement).filter(t=>Pe(t)===e),Se=e=>e.getKind()===l.NullKeyword||e.getKind()===l.FalseKeyword||o.isIdentifier(e)&&e.getText()==="undefined"?!0:o.isNumericLiteral(e)?e.getLiteralValue()===0:o.isStringLiteral(e)&&e.getLiteralValue()==="",$c=(e,t)=>Se(e)||Se(t),jc=new Map([[l.EqualsEqualsEqualsToken,"positive"],[l.EqualsEqualsToken,"positive"],[l.ExclamationEqualsEqualsToken,"negative"],[l.ExclamationEqualsToken,"negative"]]),xt=e=>!Se(e)&&(o.isLiteralExpression(e)||e.getKind()===l.TrueKeyword),Vc=(e,t,s)=>{const n=jc.get(e);if(n!==void 0)return $c(t,s)?n==="positive"?"negative":"positive":xt(t)||xt(s)?void 0:n},$=e=>{if(o.isParenthesizedExpression(e))return $(e.getExpression());if(o.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken)return"negative";if(o.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=Vc(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===l.AmpersandAmpersandToken||t===l.BarBarToken){const n=$(e.getLeft()),i=$(e.getRight());return n===i?n:"indeterminate"}}return o.isIdentifier(e)||o.isPropertyAccessExpression(e)||o.isElementAccessExpression(e)||o.isCallExpression(e)?"positive":"indeterminate"},Et=e=>{if(e!==void 0){if(o.isReturnStatement(e))return e;if(o.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&o.isReturnStatement(t)?t:void 0}}},Wc=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(l.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Hc=e=>o.isReturnStatement(e)?e.getExpression()??e:e,Gc=e=>{const t=[];for(const s of Vt(e)){const n=$(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of qc(e)){const n=$(s.getExpression());if(n==="indeterminate")continue;const i=n==="negative"?Et(s.getThenStatement()):Et(s.getElseStatement())??Wc(s);i!==void 0&&t.push(Hc(i))}return t},Yc=e=>{for(const t of e.getAncestors())if(o.isVariableDeclaration(t)){const s=t.getNameNode();if(o.isIdentifier(s))return s.getText()}return"<anonymous>"},Qc=(e,t,s)=>{if(!o.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!o.isObjectLiteralExpression(n))return[];const i=[];for(const r of n.getProperties()){if(!o.isPropertyAssignment(r)||!Kc.has(r.getName()))continue;const a=r.getInitializer();if(!(!a||!(o.isArrowFunction(a)||o.isFunctionExpression(a)))&&Bc(a))for(const c of Gc(a)){const u=jt(c);u!==void 0&&i.push({exportName:Yc(e),file:s,form:u,key:r.getName(),line:c.getStartLineNumber(),owner:t})}}return i},Xc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=_c(n);i!==void 0&&s.push(...Qc(n,i,t))}return s},Zc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Xc(i,E(t,n)))}return s},Jc=new Set(["query","upsert","upsertMany"]),el=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(Jc.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},tl=(e,t)=>{const s=el(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const i=y(n,"namespace");if(!(!i||!T(i)||M(i)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s}},sl=(e,t)=>P(e,t,tl),nl=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return o.isPropertyAccessExpression(s)?s.getName()==="workflows":o.isIdentifier(s)&&s.getText()==="workflows"},rl=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},il=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=E(t,n);for(const a of i.getDescendantsOfKind(l.CallExpression)){if(!nl(a))continue;const c=ws(a);c!==""&&s.push({exportName:c,file:r,line:a.getStartLineNumber(),workflow:rl(a)})}}return s},ol=".lunora-schema.json",I=(e,t)=>{b(e)&&At(e,"utf8")===t||ns(e,t,"utf8")},w=(e,t)=>{if(t===""){rs(e,{force:!0});return}I(e,t)},al=e=>{const t=f(e,"package.json");if(b(t))try{const s=JSON.parse(At(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},cl=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},ll=e=>{let t=b(e)?e:fe(e);for(;t&&t!==fe(t);){const s=f(t,"tsconfig.json");if(b(s))return s;t=fe(t)}},vt=e=>e.replaceAll("\\","/"),ul=(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 i=t.columns.length>0;for(const r of e){if(r.table===void 0){if(i)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})}},te=(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)},St=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,dl=8,fl=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:i,migrations:r,project:a,shapes:c,usesSandbox:u,useUmbrella:d,workflows:h}=e;let N=Je(a,i),p=tt(a,i),S=et(a,i);for(let C=1;;C+=1){const F=bs({agents:t,functions:N,httpRoutes:S,mutators:p,useUmbrella:d,workflows:h}),O=Ps({agents:t,functions:N,migrations:r,mutators:p,shapes:c,useUmbrella:d,usesSandbox:u});if(C>=dl||St(a,s,F)&&St(a,n,O))return{apiContent:F,functions:N,functionsContent:O,httpRoutes:S,mutators:p};te(a,s,F),te(a,n,O),N=Je(a,i),p=tt(a,i),S=et(a,i)}},pl=e=>{const t=ll(e);return t?new Xe({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Xe({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},iu=(e,t)=>{const s=g(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 i=new Set(s.map(c=>vt(c))),r=vt(t),a=`${r}/`;for(const c of e.getSourceFiles()){const u=c.getFilePath();(u===r||u.startsWith(a))&&!i.has(u)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const u=c.getFilePath();if(!(u===r||u.startsWith(a)||u.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},ou=e=>{const t=cl(),s=t?pe.now():0,n=f(e.projectRoot,e.lunoraDirectory??"lunora"),i=f(n,"schema.ts");if(!b(i))throw new k("INTERNAL",`schema.ts not found at ${i}`);const r=e.project??pl(n);mn(mi);const a=nn(r,i,e.projectRoot),{agents:c,containers:u,dataModelContent:d,dependencies:h,env:N,featureUsage:p,hasBrowser:S,hasFlags:C,hasNotify:F,identity:O,platformGate:V,queues:R,serverContent:_,storageRulesMetadata:z,usesSandbox:oe,useUmbrella:U,workflows:D}=Ln({lunoraDirectory:n,project:r,projectRoot:e.projectRoot,schema:a,target:e.target}),m=f(n,"_generated"),Ie=f(m,"dataModel.ts"),we=f(m,"server.ts"),Wt=f(m,"api.ts"),Ht=f(m,"functions.ts");te(r,Ie,d),te(r,we,_);const Te=Gs(r,n),B=ln(r,n),{apiContent:Ce,functions:q,functionsContent:Fe,httpRoutes:Gt,mutators:Yt}=fl({agents:c,apiPath:Wt,generatedFunctionsPath:Ht,lunoraDirectory:n,migrations:Te,project:r,shapes:B,useUmbrella:U,usesSandbox:oe,workflows:D}),ae=qs(r,n,D,c),W=e.lint===!1?void 0:as({adminRoutes:Bn(r,n),aiRawRuns:jn(r,n),aiToolSideEffects:er(r,n),argumentDerivedFetches:nr(r,n),argumentValidators:mr(r,n),authApiCalls:Bs(r,n),authConfigs:Pr(r,n),browserUrlAccesses:Fr(r,n),configCalls:_r(r,n),containerKeyAccesses:Ur(r,n),containerOverrides:Wr(r,n),containers:u,exportSinks:Qr(r,n),staleMigrationImports:Sc(r,n),failOpenGuards:ti(r,n),flagReads:ui(r,n),flagSecurityDefaults:gi(r,n),geoIndexUsages:Ei(r,n),httpActionGuards:Pi(r,n),httpHeaderWrites:ki(r,n),identityClaimReads:qi(r,n),imageDeliveryUrlAccesses:ji(r,n),inserts:Ws(r,n),kvKeyAccesses:Wi(r,n),mailRecipientAccesses:Xi(r,n),maskProcedures:Hs(r,n),maskStrategies:io(r,n),mutatorWrites:fo(r,n),nondeterministicCalls:Xs(r,n),normalizeIdAuthorizations:To(r,n),notifyCalls:Js(r,n),notifyConfig:Zs(r,n),ownerFieldWrites:Mo(r,n,q),unrestrictedWhereBranches:Zc(r,n),paymentWebhooks:jo(r,n),privilegedDispatches:na(r,n),procedureProtections:Ba(r,n),queries:zs(r,n),queues:R,r2sqlCalls:en(r,n),ratelimitKeySelectors:Va(r,n),rawRowReturns:Za(r,n),relationLoads:tc(r,n),rlsProcedures:tn(r,n),schema:a,secretLiterals:lc(r,n),shapes:B,softDeleteReads:dc(r,n),sqlInterpolations:xc(r,n),storageKeyAccesses:yc(r,n,q),storageUploads:Tc(r,n),vectorNamespaceAccesses:sl(r,n),workflowCalls:il(r,n),workflows:D,wranglerVariables:e.wranglerVariables}),Oe=W===void 0?[]:[...is(W,{source:"static"}),...Mc(r,n,q)],Qt=sn(r,n),Re=so(r,n);ul(B,Re,eo(r,n));const Xt=C?ii(r,n):[],H=Cc(p,{containerCount:u.length,cronCount:ae.length,dependencies:h,hasPaymentTables:zo(a.tables),queueCount:R.length,storageColumnCount:Object.keys(fs(a)).length,storageRuleCount:z.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:D.length}),Le=t?pe.now():0,ce=hn(a,Te.map(x=>x.id)),De=ps({advisories:Oe,advisorProcedures:W?.procedureProtections??[],agents:c,containers:u,env:N,flagKeys:Xt,hasAccessFacade:p.access,hasAi:p.ai,hasAnalytics:p.analytics,hasBrowser:S,hasFlags:C,hasHyperdrive:p.hyperdrive,hasImages:p.images,hasKv:p.kv,hasNotify:F,hasPayments:p.payments,hasPipelines:p.pipelines,hasR2sql:p.r2sql,hasX402:p.x402,maskMetadata:Re,mutators:Yt,queues:R,rlsMetadata:Qt,schema:a,schemaSnapshot:ce,shapes:B,storageRules:z,studioFeatures:H,useUmbrella:U,workflows:D}),ke=gs(B,h.has("@lunora/db"),U),Me=ms(u,a.jurisdiction),Ke=hs(D),_e=xs(c),ze=Es(R),Ue=vs(ae),Be=Ss(a.vectorIndexes),G=As(a,U),qe=ys(h.has("@lunora/seed")),Y=e.apiSpec??"openapi",le=Y==="openapi"||Y==="both",ue=Y==="openrpc"||Y==="both",$e=un({emailAgents:c.filter(x=>x.onEmail===!0).map(x=>({bindingName:x.bindingName,exportName:x.exportName})),hasAccess:h.has("@lunora/cloudflare-access"),hasAi:p.ai,hasAnalytics:p.analytics,hasAuth:h.has("@lunora/auth"),hasBrowser:S,hasFramework:h.has("@lunora/astro")||h.has("@lunora/svelte")||h.has("@lunora/vue"),hasGlobal:a.tables.some(x=>x.shardMode==="global"&&x.globalBackend!=="hyperdrive"),hasHyperdrive:p.hyperdrive,hasHyperdriveGlobal:a.tables.some(x=>x.shardMode==="global"&&x.globalBackend==="hyperdrive"),hasImages:p.images,hasKv:H.kv,hasNotify:F,hasPayments:p.payments,hasR2sql:p.r2sql,hasQueue:R.some(x=>x.mode==="push"),hasScheduler:H.scheduler,hasStorage:H.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:D.length>0,hasX402:p.x402,identity:O,jurisdiction:a.jurisdiction,useUmbrella:U,voiceAgents:c.filter(x=>x.voice===!0&&x.voiceBindingName!==void 0).map(x=>({bindingName:x.voiceBindingName,exportName:x.exportName})),wantsOpenApi:le,wantsOpenRpc:ue}),je=al(e.projectRoot),Ve=dn({functions:q,httpRoutes:Gt,version:je}),We=pn({functions:q,version:je}),He=`${JSON.stringify(Ve,void 0,2)}
8
+ `,Ge=`${JSON.stringify(We,void 0,2)}
9
+ `,Ye=fn(Ve),Qe=gn(We),de=f(n,ol),Zt=b(de);if(e.dryRun||(b(m)||ss(m,{recursive:!0}),I(f(m,"app.ts"),$e),I(Ie,d),I(f(m,"api.ts"),Ce),I(we,_),I(f(m,"functions.ts"),Fe),I(f(m,"shard.ts"),De),I(f(m,"crons.ts"),Ue),I(f(m,"vectors.ts"),Be),I(f(m,"drizzle.global.ts"),G.global),I(f(m,"drizzle.shard.ts"),G.shard),w(f(m,"containers.ts"),Me),w(f(m,"workflows.ts"),Ke),w(f(m,"agents.ts"),_e),w(f(m,"queues.ts"),ze),w(f(m,"seed.ts"),qe),w(f(m,"collections.ts"),ke),w(f(m,"openapi.json"),le?He:""),w(f(m,"openapi.ts"),le?Ye:""),w(f(m,"openrpc.json"),ue?Ge:""),w(f(m,"openrpc.ts"),ue?Qe:""),(!Zt||e.updateSchemaBaseline===!0)&&I(de,os(ce))),t){const x=pe.now(),Jt=Math.round(x-s),es=Math.round(Le-s),ts=Math.round(x-Le);console.error(`@lunora/codegen: codegen took ${Jt.toString()}ms (discovery ${es.toString()}ms, emit ${ts.toString()}ms)`)}return{advisories:Oe,advisorContext:W,agents:c,containers:u,cronTriggers:Ns(ae),generated:{agents:_e,api:Ce,app:$e,collections:ke,containers:Me,crons:Ue,dataModel:d,drizzleGlobal:G.global,drizzleShard:G.shard,functions:Fe,openApi:He,openApiModule:Ye,openRpc:Ge,openRpcModule:Qe,queues:ze,seed:qe,server:_,shard:De,vectors:Be,workflows:Ke},outputDirectory:m,platformDiagnostics:V.diagnostics,queues:R,schemaSnapshot:ce,schemaSnapshotPath:de,workflows:D}};export{ol as SCHEMA_SNAPSHOT_FILENAME,pl as createCodegenProject,ll as findTsconfig,iu as refreshCodegenProject,ou as runCodegen};
@@ -0,0 +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{u as b,s as h}from"./ast-CjWtsS6S.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{readdirSync as x,lstatSync as E}from"node:fs";import{join as m,extname as A,relative as b,sep as y}from"node:path";import{Node as r,SyntaxKind as p}from"ts-morph";import{diagnosticAt as S}from"./CodegenDiagnosticError-BUXlG3P-.mjs";const h=/\.ts$/u,P=(e,t)=>b(e,t).split(y).join("/").replace(h,""),f=(e,t=[],s=e)=>{let n;try{n=x(e)}catch{return t}for(const i of n){const o=m(e,i),a=E(o);if(a.isDirectory()){if(i==="_generated"||i==="node_modules")continue;f(o,t,s)}else if(a.isFile()&&A(i)===".ts"){if(i==="schema.ts"&&e===s)continue;t.push(o)}}return t},T=(e,t,s)=>{const n=[];for(const i of f(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i),a=P(t,i);for(const d of o.getDescendantsOfKind(p.CallExpression)){const c=s(d,a);c!==void 0&&n.push(c)}}return n},D=e=>{for(const t of e.getAncestors())if(r.isVariableDeclaration(t)&&t.getVariableStatement()?.hasExportKeyword()===!0)return t.getName();return""},I=(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},z=(e,t)=>{if(!e||!r.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&r.isPropertyAssignment(s)?s.getInitializer():void 0},l=e=>r.isPropertyAccessExpression(e)&&e.getName()==="db"||r.isIdentifier(e)&&e.getText()==="db",w=new Set(["findFirst","findFirstOrThrow","findMany"]),C=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!w.has(t.getName()))return;const s=t.getExpression();if(l(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(l(n))return{options:e.getArguments()[0],table:s.getName()}}},g=(e,t)=>{const s=e.getExpression();return!r.isPropertyAccessExpression(s)||!t.has(s.getName())?!1:l(s.getExpression())},u=e=>{const t=e.getArguments()[0];return t&&r.isStringLiteral(t)?t.getLiteralText():""},R=(e,t,s)=>{const n=new Set,i=new Set;for(const o of e.getDescendantsOfKind(p.CallExpression))if(g(o,t)){const a=u(o);a!==""&&n.add(a)}else if(g(o,s)){const a=u(o);a!==""&&i.add(a)}return{tablesRead:[...n],tablesWritten:[...i]}},v=e=>{let t=e;for(;t&&(r.isAsExpression(t)||r.isSatisfiesExpression(t)||r.isParenthesizedExpression(t)||r.isNonNullExpression(t));)t=t.getExpression();return t},V=e=>{const t=v(e);return t&&r.isCallExpression(t)?t:void 0},_=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},K=e=>{const t=e.getArguments()[1];return t&&r.isStringLiteral(t)?t.getLiteralValue():""},$=(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},j=e=>r.isIdentifier(e)&&e.getText()==="ctx",M=e=>(t,s,n)=>{if(r.isStringLiteral(t)||r.isNoSubstitutionTemplateLiteral(t))return t.getLiteralValue();throw S(t,`${e} "${s}": \`${n}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)};export{P as a,v as b,$ as c,_ as d,D as e,T as f,K as g,I as h,l as i,j,f as l,z as p,C as r,M as s,R as t,V as u};
@@ -1,3 +1,3 @@
1
- import{G as S}from"./emit-khv5P1pH.mjs";import{s as p}from"./paths-C-9fwEgQ.mjs";import{LUNORA_ERROR_CODES as O,objectSchema as h,validatorIrToJsonSchema as u}from"./LUNORA_ERROR_CODES-BYg8Lpgb.mjs";const E="/_lunora/rest",A=["authorization","cf-access-jwt-assertion","cookie","x-payment"],f=["x-d1-bookmark","x-lunora-shard-key"],P=e=>[...A,...(e.credentialHeaders??[]).map(t=>t.toLowerCase())],g=e=>Number.isFinite(e)?Math.max(0,Math.floor(e)):0,y=(...e)=>{const t=[];for(const r of e)for(const o of r?.split(",")??[]){const s=o.trim().toLowerCase();s!==""&&!t.includes(s)&&t.push(s)}return t.length===0?void 0:t.join(", ")},T=(e,t)=>{const r=[t,`max-age=${String(g(e.maxAge))}`];return e.staleWhileRevalidate!==void 0&&r.push(`stale-while-revalidate=${String(g(e.staleWhileRevalidate))}`),r.join(", ")},b=e=>e.scope==="public"?y(e.vary,...P(e),...f):y(e.vary,...f),x=e=>{const t=e.indexOf(":");if(!(t<=0||t>=e.length-1||e.indexOf(":",t+1)!==-1))return{name:e.slice(t+1),namespace:e.slice(0,t)}},N=e=>{const t=x(e);if(t!==void 0)return`${E}/${t.namespace}/${t.name}`},k=e=>e==="query"?"GET":"POST",m="#/components/responses/LunoraError",v=/:([A-Za-z_$][\w$]*)/gu,q=e=>[...e.matchAll(v)].map(t=>t[1]),_=e=>e.replaceAll(v,"{$1}"),l=e=>e.kind==="optional"?e.inner??e:e,j=e=>{const t=new Set(q(e.path)),r=[];for(const[o,s]of Object.entries(e.searchParams)){const c=l(s);r.push({description:`Query parameter \`${o}\``,in:"query",name:o,required:s.kind!=="optional",schema:u(c)})}for(const[o,s]of Object.entries(e.params)){const c=l(s);r.push({description:`Path parameter \`${o}\``,in:t.has(o)?"path":"query",name:o,required:t.has(o)?!0:s.kind!=="optional",schema:u(c)})}return r},$=e=>e?{content:{"application/json":{schema:u(e)}},description:"Successful response."}:{content:{"application/json":{schema:{description:"Return shape is TS-inferred (no `.output()` declared); best-effort — any JSON."}}},description:"Successful response. The return shape is TypeScript-inferred and not declared via `.output()`, so it is documented best-effort."},C=e=>{const t=p(e.filePath),r=j(e),o={description:`${e.stream?"Streaming (SSE) ":""}HTTP route handler \`${e.exportName}\` (${e.method} ${e.path}).`,operationId:`${e.method.toLowerCase()}_${p(e.path)}`,responses:{200:$(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:m}},summary:`${e.method} ${e.path}`,tags:[t]};return r.length>0&&(o.parameters=r),Object.keys(e.body).length>0&&(o.requestBody={content:{"application/json":{schema:h(e.body)}},required:!0}),e.stream&&(o["x-lunora-stream"]="text/event-stream"),o},w=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o={additionalProperties:!1,properties:{args:h(e.args),functionPath:{const:r,type:"string"},shardKey:{description:"Optional shard key; omitted routes to the default shard.",type:"string"}},required:["functionPath"],type:"object"};return{operation:{description:`Invoke the \`${e.kind}\` \`${r}\` over the Lunora RPC envelope (POST /_lunora/rpc).`,operationId:r,requestBody:{content:{"application/json":{schema:o}},required:!0},responses:{200:$(e.output),default:{$ref:m}},summary:`${e.kind}: ${r}`,tags:[t],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${r}`}},D=(e,t)=>{if(e===void 0||t!=="get"||e.scope===void 0||e.maxAge===void 0)return{};const r={maxAge:e.maxAge,scope:e.scope,...e.staleWhileRevalidate===void 0?{}:{staleWhileRevalidate:e.staleWhileRevalidate},...e.tag===void 0?{}:{tag:e.tag},...e.vary===void 0?{}:{vary:e.vary}},o={"Cache-Control":{description:r.scope==="public"?"Caching policy. `public` applies only to an uncredentialed request — a request carrying `Authorization` or `Cookie` is always answered `private`.":"Caching policy. Restricted to the caller's own cache; never stored by a shared/edge cache.",schema:{example:T(r,r.scope),type:"string"}}};r.tag!==void 0&&(o["Cache-Tag"]={description:"Purge tag for `ctx.cache.purge({ tags: [...] })`.",schema:{example:r.tag,type:"string"}});const s=b(r);return s!==void 0&&(o.Vary={description:"Request headers this response varies by. The endpoint's own negotiated headers are merged in at runtime.",schema:{example:s,type:"string"}}),{headers:o}},L=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o=N(r);if(o===void 0)return;const s=k(e.kind),c=s==="GET",d={description:`Public REST endpoint for the \`${e.kind}\` \`${r}\` (opt-in via \`.expose({ rest: true })\`). Routed through the procedure, so auth / RLS / validators are enforced.`,operationId:`rest_${p(o)}`,responses:{200:{content:{"application/json":{schema:{description:"Procedure result. The shape is TS-inferred from the return type; best-effort — any JSON."}}},description:"Successful result (TypeScript-inferred return shape, documented best-effort).",...D(e.expose?.cache,c?"get":"post")},default:{$ref:m}},summary:`${s} ${o}`,tags:[t],"x-lunora-function-kind":e.kind};if(c){const n=Object.entries(e.args).map(([a,i])=>{const R=l(i);return{description:`Argument \`${a}\` (JSON-encoded for non-string values).`,in:"query",name:a,required:i.kind!=="optional",schema:u(R)}});return n.length>0&&(d.parameters=n),{method:"get",operation:d,path:o}}return d.requestBody={content:{"application/json":{schema:h(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:d,path:o}},I=e=>{const t=e.version??"0.0.0",r={},o=new Set;for(const n of e.httpRoutes){const a=_(n.path),i=r[a]??{};i[n.method.toLowerCase()]=C(n),r[a]=i,o.add(p(n.filePath))}const s=e.functions.filter(n=>n.visibility!=="internal"&&n.kind!=="stream");for(const n of s){const{operation:a,pathKey:i}=w(n);r[i]={post:a},o.add(p(n.filePath))}for(const n of s){if(n.expose?.rest!==!0)continue;const a=L(n);if(a===void 0)continue;const i=r[a.path]??{};i[a.method]=a.operation,r[a.path]=i}const c=[...o].toSorted((n,a)=>n.localeCompare(a)).map(n=>({description:`Operations declared in \`lunora/${n}\`.`,name:n}));return{components:{responses:{LunoraError:{content:{"application/json":{schema:{additionalProperties:!1,description:"Standard Lunora error envelope.",properties:{error:{additionalProperties:!1,properties:{code:{description:"Machine-readable error code. Clients switch on this value.",enum:O,type:"string"},message:{description:"Human-readable error message (never echoes internal details).",type:"string"}},required:["code","message"],type:"object"}},required:["error"],type:"object"}}},description:"A Lunora error response. The HTTP status reflects the error code (e.g. BAD_REQUEST→400, UNAUTHORIZED→401, FORBIDDEN→403, NOT_FOUND→404)."}}},info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora API",version:t},openapi:"3.1.0",paths:r,tags:c}},J=e=>`${JSON.stringify(I(e),void 0,2)}
1
+ import{G as S}from"./emit-BQNGQnaS.mjs";import{s as p}from"./paths-C-9fwEgQ.mjs";import{LUNORA_ERROR_CODES as O,objectSchema as h,validatorIrToJsonSchema as u}from"./LUNORA_ERROR_CODES-BYg8Lpgb.mjs";const E="/_lunora/rest",A=["authorization","cf-access-jwt-assertion","cookie","x-payment"],f=["x-d1-bookmark","x-lunora-shard-key"],P=e=>[...A,...(e.credentialHeaders??[]).map(t=>t.toLowerCase())],g=e=>Number.isFinite(e)?Math.max(0,Math.floor(e)):0,y=(...e)=>{const t=[];for(const r of e)for(const o of r?.split(",")??[]){const s=o.trim().toLowerCase();s!==""&&!t.includes(s)&&t.push(s)}return t.length===0?void 0:t.join(", ")},T=(e,t)=>{const r=[t,`max-age=${String(g(e.maxAge))}`];return e.staleWhileRevalidate!==void 0&&r.push(`stale-while-revalidate=${String(g(e.staleWhileRevalidate))}`),r.join(", ")},b=e=>e.scope==="public"?y(e.vary,...P(e),...f):y(e.vary,...f),x=e=>{const t=e.indexOf(":");if(!(t<=0||t>=e.length-1||e.indexOf(":",t+1)!==-1))return{name:e.slice(t+1),namespace:e.slice(0,t)}},N=e=>{const t=x(e);if(t!==void 0)return`${E}/${t.namespace}/${t.name}`},k=e=>e==="query"?"GET":"POST",m="#/components/responses/LunoraError",v=/:([A-Za-z_$][\w$]*)/gu,q=e=>[...e.matchAll(v)].map(t=>t[1]),_=e=>e.replaceAll(v,"{$1}"),l=e=>e.kind==="optional"?e.inner??e:e,j=e=>{const t=new Set(q(e.path)),r=[];for(const[o,s]of Object.entries(e.searchParams)){const c=l(s);r.push({description:`Query parameter \`${o}\``,in:"query",name:o,required:s.kind!=="optional",schema:u(c)})}for(const[o,s]of Object.entries(e.params)){const c=l(s);r.push({description:`Path parameter \`${o}\``,in:t.has(o)?"path":"query",name:o,required:t.has(o)?!0:s.kind!=="optional",schema:u(c)})}return r},$=e=>e?{content:{"application/json":{schema:u(e)}},description:"Successful response."}:{content:{"application/json":{schema:{description:"Return shape is TS-inferred (no `.output()` declared); best-effort — any JSON."}}},description:"Successful response. The return shape is TypeScript-inferred and not declared via `.output()`, so it is documented best-effort."},C=e=>{const t=p(e.filePath),r=j(e),o={description:`${e.stream?"Streaming (SSE) ":""}HTTP route handler \`${e.exportName}\` (${e.method} ${e.path}).`,operationId:`${e.method.toLowerCase()}_${p(e.path)}`,responses:{200:$(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:m}},summary:`${e.method} ${e.path}`,tags:[t]};return r.length>0&&(o.parameters=r),Object.keys(e.body).length>0&&(o.requestBody={content:{"application/json":{schema:h(e.body)}},required:!0}),e.stream&&(o["x-lunora-stream"]="text/event-stream"),o},w=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o={additionalProperties:!1,properties:{args:h(e.args),functionPath:{const:r,type:"string"},shardKey:{description:"Optional shard key; omitted routes to the default shard.",type:"string"}},required:["functionPath"],type:"object"};return{operation:{description:`Invoke the \`${e.kind}\` \`${r}\` over the Lunora RPC envelope (POST /_lunora/rpc).`,operationId:r,requestBody:{content:{"application/json":{schema:o}},required:!0},responses:{200:$(e.output),default:{$ref:m}},summary:`${e.kind}: ${r}`,tags:[t],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${r}`}},D=(e,t)=>{if(e===void 0||t!=="get"||e.scope===void 0||e.maxAge===void 0)return{};const r={maxAge:e.maxAge,scope:e.scope,...e.staleWhileRevalidate===void 0?{}:{staleWhileRevalidate:e.staleWhileRevalidate},...e.tag===void 0?{}:{tag:e.tag},...e.vary===void 0?{}:{vary:e.vary}},o={"Cache-Control":{description:r.scope==="public"?"Caching policy. `public` applies only to an uncredentialed request — a request carrying `Authorization` or `Cookie` is always answered `private`.":"Caching policy. Restricted to the caller's own cache; never stored by a shared/edge cache.",schema:{example:T(r,r.scope),type:"string"}}};r.tag!==void 0&&(o["Cache-Tag"]={description:"Purge tag for `ctx.cache.purge({ tags: [...] })`.",schema:{example:r.tag,type:"string"}});const s=b(r);return s!==void 0&&(o.Vary={description:"Request headers this response varies by. The endpoint's own negotiated headers are merged in at runtime.",schema:{example:s,type:"string"}}),{headers:o}},L=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o=N(r);if(o===void 0)return;const s=k(e.kind),c=s==="GET",d={description:`Public REST endpoint for the \`${e.kind}\` \`${r}\` (opt-in via \`.expose({ rest: true })\`). Routed through the procedure, so auth / RLS / validators are enforced.`,operationId:`rest_${p(o)}`,responses:{200:{content:{"application/json":{schema:{description:"Procedure result. The shape is TS-inferred from the return type; best-effort — any JSON."}}},description:"Successful result (TypeScript-inferred return shape, documented best-effort).",...D(e.expose?.cache,c?"get":"post")},default:{$ref:m}},summary:`${s} ${o}`,tags:[t],"x-lunora-function-kind":e.kind};if(c){const n=Object.entries(e.args).map(([a,i])=>{const R=l(i);return{description:`Argument \`${a}\` (JSON-encoded for non-string values).`,in:"query",name:a,required:i.kind!=="optional",schema:u(R)}});return n.length>0&&(d.parameters=n),{method:"get",operation:d,path:o}}return d.requestBody={content:{"application/json":{schema:h(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:d,path:o}},I=e=>{const t=e.version??"0.0.0",r={},o=new Set;for(const n of e.httpRoutes){const a=_(n.path),i=r[a]??{};i[n.method.toLowerCase()]=C(n),r[a]=i,o.add(p(n.filePath))}const s=e.functions.filter(n=>n.visibility!=="internal"&&n.kind!=="stream");for(const n of s){const{operation:a,pathKey:i}=w(n);r[i]={post:a},o.add(p(n.filePath))}for(const n of s){if(n.expose?.rest!==!0)continue;const a=L(n);if(a===void 0)continue;const i=r[a.path]??{};i[a.method]=a.operation,r[a.path]=i}const c=[...o].toSorted((n,a)=>n.localeCompare(a)).map(n=>({description:`Operations declared in \`lunora/${n}\`.`,name:n}));return{components:{responses:{LunoraError:{content:{"application/json":{schema:{additionalProperties:!1,description:"Standard Lunora error envelope.",properties:{error:{additionalProperties:!1,properties:{code:{description:"Machine-readable error code. Clients switch on this value.",enum:O,type:"string"},message:{description:"Human-readable error message (never echoes internal details).",type:"string"}},required:["code","message"],type:"object"}},required:["error"],type:"object"}}},description:"A Lunora error response. The HTTP status reflects the error code (e.g. BAD_REQUEST→400, UNAUTHORIZED→401, FORBIDDEN→403, NOT_FOUND→404)."}}},info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora API",version:t},openapi:"3.1.0",paths:r,tags:c}},J=e=>`${JSON.stringify(I(e),void 0,2)}
2
2
  `,U=e=>`${S}export const openApiSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
3
3
  `;export{I as buildOpenApiDocument,J as emitOpenApi,U as emitOpenApiModule};
@@ -0,0 +1 @@
1
+ import{w as a}from"./classify-procedure-call-AKeIK05y.mjs";const l=s=>a(s,"use","rls");export{l as r};
@@ -0,0 +1 @@
1
+ import{Node as o}from"ts-morph";import{b as a}from"./ast-CjWtsS6S.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"},b=t=>{const{root:i}=p(t);return i&&o.isIdentifier(i)?i:void 0},g=(t,i=!1)=>{const e=b(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},C=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 C(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};
@@ -0,0 +1 @@
1
+ import{SyntaxKind as p,Node as s}from"ts-morph";import{l as f,a as g,e as d}from"./ast-CjWtsS6S.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};
@@ -0,0 +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{l as y}from"./ast-CjWtsS6S.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};
@@ -0,0 +1 @@
1
+ import{s as x}from"./paths-C-9fwEgQ.mjs";import{l as h,a as P}from"./ast-CjWtsS6S.mjs";import{b as f,c as E}from"./classify-procedure-call-AKeIK05y.mjs";import{Node as s,SyntaxKind as b}from"ts-morph";import{p as A,a as d}from"./parse-validator-BFTp87yz.mjs";import{u as v}from"./unwrap-handler-return-CmIWbykC.mjs";const N=i=>{const e=i.getArguments()[0];if(!e||!s.isObjectLiteralExpression(e))return"unknown";const t=e.getProperty("handler");if(!t||!s.isPropertyAssignment(t))return"unknown";const r=t.getInitializer();return!r||!(s.isArrowFunction(r)||s.isFunctionExpression(r))?"unknown":v(r)},F=i=>{const e=i.getArguments()[0];return!e||!(s.isArrowFunction(e)||s.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&&s.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&&s.isExpression(t)?A(t):void 0},u=(i,e)=>{const t=i.getProperty(e);if(t===void 0||!s.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&s.isStringLiteral(r)?r.getLiteralValue():void 0},m=(i,e)=>{const t=i.getProperty(e);if(t===void 0||!s.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&s.isNumericLiteral(r)?r.getLiteralValue():void 0},O=i=>{const e=i.getProperty("cache");if(e===void 0||!s.isPropertyAssignment(e))return;const t=e.getInitializer();if(t===void 0||!s.isObjectLiteralExpression(t))return;const r=u(t,"scope"),n=m(t,"maxAge"),o=m(t,"staleWhileRevalidate"),a=u(t,"tag"),c=u(t,"vary"),g={...n===void 0?{}:{maxAge:n},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(g).length===0?void 0:g},S=i=>{if(i===void 0||!s.isObjectLiteralExpression(i))return{};const e=O(i),t=i.getProperty("rest");return t!==void 0&&s.isPropertyAssignment(t)?{...e===void 0?{}:{cache:e},rest:t.getInitializer()?.getText()==="true"}:e===void 0?{}:{cache:e}},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||!s.isObjectLiteralExpression(e))return{};const t=e.getProperty("args");if(!t||!s.isPropertyAssignment(t))return{};const r=t.getInitializer();return!r||!s.isObjectLiteralExpression(r)?{}:d(r)},T=8,l=(i,e=0)=>{if(e>T)return;if(s.isCallExpression(i))return i;if(s.isParenthesizedExpression(i)||s.isAsExpression(i)||s.isSatisfiesExpression(i)||s.isNonNullExpression(i))return l(i.getExpression(),e+1);if(!s.isIdentifier(i)&&!s.isPropertyAccessExpression(i))return;const t=i.getSymbol()?.getValueDeclaration();return t?p(t,e+1):void 0},p=(i,e)=>{if(s.isVariableDeclaration(i)||s.isPropertyAssignment(i)){const t=i.getInitializer();return t?l(t,e):void 0}if(s.isShorthandPropertyAssignment(i)){const t=i.getValueSymbol()?.getValueDeclaration();return t?p(t,e+1):void 0}if(s.isBindingElement(i)){const t=i.getPropertyNameNode()?.getText()??i.getName(),o=i.getFirstAncestorByKind(b.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return o?p(o,e+1):void 0}},k=i=>{const e=i.getNameNode();if(s.isObjectBindingPattern(e)){const n=[];for(const o of e.getElements()){const a=l(o.getNameNode());a&&n.push([o.getName(),a])}return n}const t=i.getInitializer(),r=t&&(s.isCallExpression(t)?t:l(t));return r?[[i.getName(),r]]:[]},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 n=l(r.getExpression()),o=n?y(n,"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 n of r.getDeclarations())for(const[o,a]of k(n)){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),n=e.get(r);if(n&&n!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${n}" and "${t.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[n,t.filePath],status:500});e.set(r,t.filePath)}},K=(i,e)=>{const t=h(e),r=[];for(const n of t){const o=i.getSourceFile(n)??i.addSourceFileAtPath(n),a=P(e,n);r.push(...D(o,a))}return r.sort((n,o)=>`${n.filePath}:${n.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),j(r),r};export{K as default};
@@ -0,0 +1 @@
1
+ import{Node as a}from"ts-morph";import{p as l,a as m}from"./parse-validator-BFTp87yz.mjs";import{l as d,a as h}from"./ast-CjWtsS6S.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&&a.isStringLiteral(e))return e.getLiteralValue()},x=r=>{const e=r.getArguments()[0];return e&&a.isObjectLiteralExpression(e)?m(e):{}},P=r=>{if(!a.isCallExpression(r))return;const e=r.getExpression();if(!a.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const n=e.getExpression();if(!a.isIdentifier(n)||n.getText()!=="httpRoute")return;const s=v(r);return s===void 0?void 0:{method:o.toUpperCase(),path:s}},S=(r,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},n=r.getExpression();if(!a.isPropertyAccessExpression(n))return;let s=n.getExpression();for(;a.isCallExpression(s);){const i=s.getExpression();if(!a.isPropertyAccessExpression(i))break;const c=i.getName();if(u.has(c))break;if(g.has(c)){const p=x(s);o[c]={...p,...o[c]}}else if(c==="output"&&o.output===void 0){const p=s.getArguments()[0];p&&a.isExpression(p)&&(o.output=l(p))}s=i.getExpression()}const t=P(s);if(t)return o.method=t.method,o.path=t.path,o},A=r=>{const e=r.getArguments()[0];return!e||!(a.isArrowFunction(e)||a.isFunctionExpression(e))?"unknown":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||!a.isCallExpression(t))continue;const i=t.getExpression();if(!a.isPropertyAccessExpression(i))continue;const c=T(t,i,s.getName(),e);c&&o.push(c)}return o},F=(r,e)=>{const o=d(e),n=[];for(const s of o){const t=r.getSourceFile(s)??r.addSourceFileAtPath(s),i=h(e,s);n.push(...b(t,i))}return n.sort((s,t)=>`${s.method} ${s.path}`.localeCompare(`${t.method} ${t.path}`)||s.filePath.localeCompare(t.filePath)),n};export{F as default};
@@ -0,0 +1 @@
1
+ import{SyntaxKind as c,Node as n}from"ts-morph";import{l as f,a as u,e as g,i as d}from"./ast-CjWtsS6S.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 s of r)if(n.isVariableDeclaration(s)){const i=s.getInitializer();if(i&&n.isStringLiteral(i))return i.getLiteralText()}},x=t=>{const e=t.getArguments()[0];return e?n.isStringLiteral(e)?e.getLiteralText():p(e)??"":""},v=(t,e)=>{const r=[];for(const s of f(e)){const i=t.getSourceFile(s)??t.addSourceFileAtPath(s),l=u(e,s);for(const o of i.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"./ast-CjWtsS6S.mjs";import"./classify-procedure-call-AKeIK05y.mjs";import{d as p}from"./index-CCDlo9L7.mjs";export{p as default};
@@ -0,0 +1 @@
1
+ import{SyntaxKind as f,Node as a}from"ts-morph";import{diagnosticAt as u}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as m}from"./module-specifiers-WF8iAydP.mjs";import{l as p,a as h}from"./ast-CjWtsS6S.mjs";const I=r=>{const i=r.getSymbol();if(!i)return r.getText()==="defineMigration";for(const t of i.getDeclarations())if(a.isImportSpecifier(t))return m(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMigration":!1;return!1},d=(r,i)=>{const t=r.getProperty(i);if(!t||!a.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&a.isStringLiteral(e)?e.getLiteralValue():void 0},P=(r,i)=>{const t=r.getInitializer();if(t?.getKind()!==f.CallExpression)return;const e=t.getExpression();if(!a.isIdentifier(e)||!I(e))return;const o=t.getArguments()[0];if(!o||!a.isObjectLiteralExpression(o))return;const n=d(o,"id"),s=r.getName();if(n===void 0||n.trim()==="")throw u(o,`Migration "${s}" 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:s,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),s=h(i,o);for(const c of n.getVariableStatements())if(c.isExported())for(const g of c.getDeclarations()){const l=P(g,s);l&&e.push(l)}}return e.sort((o,n)=>o.id.localeCompare(n.id)),M(e),e};export{y as default};
@@ -0,0 +1 @@
1
+ import{Node as s,SyntaxKind as a}from"ts-morph";import{l,a as c,h as d}from"./ast-CjWtsS6S.mjs";import{c as f}from"./classify-procedure-call-AKeIK05y.mjs";const u={"crypto.getRandomValues":"crypto.getRandomValues","crypto.randomUUID":"crypto.randomUUID","Date.now":"Date.now","Math.random":"Math.random"},m=new Set(["globalThis","self"]),g=new Set(["globalThis","self","window"]),p=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e)){const t=e.getExpression();if(s.isIdentifier(t)&&g.has(t.getText()))return e.getName()}},h=e=>{const t=e.getExpression();if(s.isIdentifier(t)){const o=t.getText();return o==="fetch"||o==="Date"?o:void 0}if(!s.isPropertyAccessExpression(t))return;const n=t.getName(),i=p(t.getExpression());if(i!==void 0)return n==="fetch"&&m.has(i)?"fetch":u[`${i}.${n}`]},x=e=>{const t=e.getExpression();if(!s.isIdentifier(t)||t.getText()!=="Date")return;const n=e.getArguments(),i=n.every(o=>s.isNumericLiteral(o)||s.isStringLiteral(o)||s.isNoSubstitutionTemplateLiteral(o));return n.length>0&&i?void 0:"new Date"},N=e=>{const t=e.getInitializer();if(!t||!s.isCallExpression(t))return;const n=f(t);if(!n||n.kind!=="query"&&n.kind!=="mutation")return;const i=d(t,n.receiver);return i?{exportName:e.getName(),handler:i,kind:n.kind}:void 0},E=(e,t)=>{const n=[];for(const i of e.handler.getDescendantsOfKind(a.CallExpression)){const o=h(i);o!==void 0&&n.push({callee:o,exportName:e.exportName,file:t,kind:e.kind,line:i.getStartLineNumber()})}for(const i of e.handler.getDescendantsOfKind(a.NewExpression)){const o=x(i);o!==void 0&&n.push({callee:o,exportName:e.exportName,file:t,kind:e.kind,line:i.getStartLineNumber()})}return n},S=(e,t)=>{const n=[];for(const i of e.getVariableStatements())if(i.isExported())for(const o of i.getDeclarations()){const r=N(o);r&&n.push(...E(r,t))}return n},w=(e,t)=>{const n=[];for(const i of l(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...S(o,c(t,i)))}return n};export{w as default};
@@ -0,0 +1 @@
1
+ import{d as a}from"./queries-B_xEHIeL.mjs";import"./ast-CjWtsS6S.mjs";export{a as default};
@@ -0,0 +1 @@
1
+ import{Node as o,SyntaxKind as a}from"ts-morph";import{l as c,a as l,h as d}from"./ast-CjWtsS6S.mjs";import{c as f}from"./classify-procedure-call-AKeIK05y.mjs";const u=t=>{const r=t.getInitializer();if(!r||!o.isCallExpression(r))return;const e=f(r);if(!e||e.kind!=="query"&&e.kind!=="mutation")return;const s=d(r,e.receiver);return s?{exportName:t.getName(),handler:s,kind:e.kind}:void 0},p=t=>{if(!o.isPropertyAccessExpression(t)||t.getName()!=="r2sql")return;const r=t.getExpression();if(!o.isIdentifier(r)||r.getText()!=="ctx")return;const e=t.getParent();return e&&o.isPropertyAccessExpression(e)&&e.getExpression()===t?`ctx.r2sql.${e.getName()}`:"ctx.r2sql"},x=(t,r)=>{const e=[];for(const s of t.handler.getDescendantsOfKind(a.PropertyAccessExpression)){const n=p(s);n!==void 0&&e.push({callee:n,exportName:t.exportName,file:r,kind:t.kind,line:s.getStartLineNumber()})}return e},m=(t,r)=>{const e=[];for(const s of t.getVariableStatements())if(s.isExported())for(const n of s.getDeclarations()){const i=u(n);i&&e.push(...x(i,r))}return e},P=(t,r)=>{const e=[];for(const s of c(r)){const n=t.getSourceFile(s)??t.addSourceFileAtPath(s);e.push(...m(n,l(r,s)))}return e};export{P as default};
@@ -0,0 +1 @@
1
+ import{Node as o}from"ts-morph";import{l as d,a as x,c}from"./ast-CjWtsS6S.mjs";import{e as h}from"./exported-procedure-chains-MlZRKqSD.mjs";import{r as A}from"./chain-CtC3-wwZ.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};
@@ -0,0 +1 @@
1
+ import{Node as a}from"ts-morph";import{l as f,a as u,t as d}from"./ast-CjWtsS6S.mjs";import{c as p}from"./classify-procedure-call-AKeIK05y.mjs";import{r as m}from"./chain-CtC3-wwZ.mjs";const b=e=>{const t=e.getArguments()[0];if(!t||!a.isArrayLiteralExpression(t))return[];const s=[];for(const r of t.getElements()){if(!a.isObjectLiteralExpression(r))continue;const i=r.getProperty("table");if(!i||!a.isPropertyAssignment(i))continue;const n=i.getInitializer();n&&a.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(!a.isVariableDeclaration(e))return;const s=e.getInitializer();if(!s||!a.isCallExpression(s))return;const r=p(s);if(!r)return;const i=r.receiver?g(r.receiver):{rlsTables:[],usesRls:!1},{tablesRead:n,tablesWritten:o}=d(e,h,y);return{exportName:e.getName(),file:t,rlsTables:i.rlsTables,tablesRead:n,tablesWritten:o,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 o of i.getVariableStatements())if(o.isExported())for(const c of o.getDeclarations()){const l=v(c,n);l&&s.push(l)}}return s};export{S as default};
@@ -0,0 +1 @@
1
+ import{l as u}from"./ast-CjWtsS6S.mjs";const i=new Set(["@lunora/agent","@lunora/agent/sandbox"]),d=o=>{const s={usesSandboxBrowser:!1,usesSandboxContainer:!1};if(!i.has(o.getModuleSpecifierValue())||o.isTypeOnly())return s;for(const e of o.getNamedImports()){if(e.isTypeOnly())continue;const n=e.getNameNode().getText();n==="browserTool"?s.usesSandboxBrowser=!0:n==="containerTool"&&(s.usesSandboxContainer=!0)}return s},S=(o,s)=>{const e={usesSandboxBrowser:!1,usesSandboxContainer:!1};for(const n of u(s)){const a=o.getSourceFile(n)??o.addSourceFileAtPath(n);for(const t of a.getImportDeclarations()){const r=d(t);e.usesSandboxBrowser||=r.usesSandboxBrowser,e.usesSandboxContainer||=r.usesSandboxContainer}if(e.usesSandboxBrowser&&e.usesSandboxContainer)break}return e};export{S as discoverSandboxUsage};