@lunora/codegen 1.0.0-alpha.259 → 1.0.0-alpha.260

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 (90) hide show
  1. package/dist/index.mjs +1 -1
  2. package/dist/packem_shared/AGENTS_FILENAME-UhIaG4BZ.mjs +1 -0
  3. package/dist/packem_shared/CONTAINERS_FILENAME-DhUL5rDc.mjs +1 -0
  4. package/dist/packem_shared/{DEFAULT_TARGET-Dy9KAvjZ.mjs → DEFAULT_TARGET-7sHexLjO.mjs} +1 -1
  5. package/dist/packem_shared/{FLAGS_FILENAME-DuEbVfug.mjs → FLAGS_FILENAME-BINQ51Zq.mjs} +1 -1
  6. package/dist/packem_shared/GENERATED_HEADER-dFyrHgQ0.mjs +1 -0
  7. package/dist/packem_shared/MUTATORS_FILENAME-D1Q6EUII.mjs +1 -0
  8. package/dist/packem_shared/NOTIFY_FILENAME-bbHHFQ_t.mjs +1 -0
  9. package/dist/packem_shared/{OPENRPC_VERSION-C8htLv5J.mjs → OPENRPC_VERSION-CGu1_YK7.mjs} +1 -1
  10. package/dist/packem_shared/QUEUES_FILENAME-CSLmXUQA.mjs +1 -0
  11. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BVhRHIbS.mjs +11 -0
  12. package/dist/packem_shared/SHAPES_FILENAME-DuR5hLW1.mjs +1 -0
  13. package/dist/packem_shared/WORKFLOWS_FILENAME-IqUyMQgM.mjs +1 -0
  14. package/dist/packem_shared/attribution-sW_DHmLO.mjs +1 -0
  15. package/dist/packem_shared/{buildOpenApiDocument-BG_b1qiR.mjs → buildOpenApiDocument-DOsv1HEF.mjs} +1 -1
  16. package/dist/packem_shared/{capabilitiesUsedBy-D5TtIE8p.mjs → capabilitiesUsedBy-CzqyN9dX.mjs} +1 -1
  17. package/dist/packem_shared/chain-BTbLDrrU.mjs +1 -0
  18. package/dist/packem_shared/{classify-procedure-call-VzDQHiLB.mjs → classify-procedure-call-OnJoKgqu.mjs} +1 -1
  19. package/dist/packem_shared/context-property-calls-BEBjylgc.mjs +1 -0
  20. package/dist/packem_shared/context-root-KWXRWlv6.mjs +1 -0
  21. package/dist/packem_shared/database-calls-rLPCL3-U.mjs +1 -0
  22. package/dist/packem_shared/{discoverAuthApiCalls-D6s0QBwd.mjs → discoverAuthApiCalls-CNj9-Jch.mjs} +1 -1
  23. package/dist/packem_shared/{discoverCrons-D2jGNq6i.mjs → discoverCrons-BqTY53L5.mjs} +1 -1
  24. package/dist/packem_shared/discoverFunctions-DPH4drkg.mjs +1 -0
  25. package/dist/packem_shared/discoverHttpRoutes-MRFziTCb.mjs +1 -0
  26. package/dist/packem_shared/discoverHyperdriveCalls-BcVkR6nw.mjs +1 -0
  27. package/dist/packem_shared/discoverInserts-Duz40u-s.mjs +1 -0
  28. package/dist/packem_shared/discoverMaskProcedures-DYJhbHF3.mjs +1 -0
  29. package/dist/packem_shared/discoverMigrations-D2P2n7JE.mjs +1 -0
  30. package/dist/packem_shared/discoverNondeterministicCalls-Cxf6T2Oi.mjs +1 -0
  31. package/dist/packem_shared/discoverQueries-CWmNPVHm.mjs +1 -0
  32. package/dist/packem_shared/discoverR2sqlCalls-DnKwop5c.mjs +1 -0
  33. package/dist/packem_shared/{discoverRlsMetadata-CVqVMNnz.mjs → discoverRlsMetadata-BXXEFXjf.mjs} +1 -1
  34. package/dist/packem_shared/discoverRlsProcedures-Des596JU.mjs +1 -0
  35. package/dist/packem_shared/{discoverSandboxUsage-DhE6sfq2.mjs → discoverSandboxUsage-Bjl8A_hj.mjs} +1 -1
  36. package/dist/packem_shared/discoverSchema-Cd3iH6q5.mjs +1 -0
  37. package/dist/packem_shared/{discoverStorageRulesMetadata-BdZT9H9j.mjs → discoverStorageRulesMetadata-DGFonj0I.mjs} +1 -1
  38. package/dist/packem_shared/{emitAgents-BD_IUs4I.mjs → emitAgents-Dotqck8w.mjs} +1 -1
  39. package/dist/packem_shared/{emitApi-DdW9RyGG.mjs → emitApi-xDIHPRPH.mjs} +1 -1
  40. package/dist/packem_shared/{emitApp-0rC4g46B.mjs → emitApp-RNU41dtm.mjs} +1 -1
  41. package/dist/packem_shared/{emitCrons-BRKXFGFu.mjs → emitCrons-DsXsg1uG.mjs} +1 -1
  42. package/dist/packem_shared/{emitDataModel-D3WuEZ4b.mjs → emitDataModel-DSk9AkJe.mjs} +1 -1
  43. package/dist/packem_shared/emitDrizzleSchema-DohtnI8c.mjs +15 -0
  44. package/dist/packem_shared/{emitFunctions-BgNeOZt_.mjs → emitFunctions-evl8Mx1a.mjs} +1 -1
  45. package/dist/packem_shared/{emitServer-mdlKhXYb.mjs → emitServer-DymRagL2.mjs} +1 -1
  46. package/dist/packem_shared/{emitShard-CLFR7-_j.mjs → emitShard-DHMYSP4m.mjs} +1 -1
  47. package/dist/packem_shared/exported-procedure-chains-58yS9zc8.mjs +1 -0
  48. package/dist/packem_shared/{fingerprintSchemaSources-DA9sYQDZ.mjs → fingerprintSchemaSources-BzFVnBfa.mjs} +1 -1
  49. package/dist/packem_shared/{handler-reference-BjE6kvyl.mjs → handler-reference-C1oBljnl.mjs} +1 -1
  50. package/dist/packem_shared/index-BusOvbeQ.mjs +1 -0
  51. package/dist/packem_shared/listLunoraSourceFiles-DRes9d5p.mjs +1 -0
  52. package/dist/packem_shared/{loadProjectConfig-CWtWqN3X.mjs → loadProjectConfig-CuGQsqYS.mjs} +1 -1
  53. package/dist/packem_shared/{modules-Dcalu27_.mjs → modules-CsA-QVJ6.mjs} +1 -1
  54. package/dist/packem_shared/{parse-validator-Cs6F8SYG.mjs → parse-validator-B4mFs19C.mjs} +1 -1
  55. package/dist/packem_shared/{qualifiers-BhOL15WZ.mjs → qualifiers-Cw8dEDbh.mjs} +1 -1
  56. package/dist/packem_shared/{readServiceBindings-V1rcBYrK.mjs → readServiceBindings-CnvEGOir.mjs} +1 -1
  57. package/dist/packem_shared/reserved-words-CW1QFbTd.mjs +1 -0
  58. package/dist/packem_shared/{shard-B2AqdAuz.mjs → shard-WXSIZRpD.mjs} +1 -1
  59. package/dist/packem_shared/{shard-runtime-B8rucwkF.mjs → shard-runtime-B1nU9CRa.mjs} +1 -1
  60. package/dist/packem_shared/shared-BXUKWh7t.mjs +9 -0
  61. package/dist/packem_shared/{unwrap-handler-return-Bnx99voQ.mjs → unwrap-handler-return-D7E2TKkS.mjs} +1 -1
  62. package/package.json +3 -3
  63. package/dist/packem_shared/AGENTS_FILENAME-pKCBP6Us.mjs +0 -1
  64. package/dist/packem_shared/CONTAINERS_FILENAME-C0nEQjXL.mjs +0 -1
  65. package/dist/packem_shared/GENERATED_HEADER-DSXl0YM2.mjs +0 -1
  66. package/dist/packem_shared/MUTATORS_FILENAME-Cm-LVbo0.mjs +0 -1
  67. package/dist/packem_shared/NOTIFY_FILENAME-BRewD55T.mjs +0 -1
  68. package/dist/packem_shared/QUEUES_FILENAME-BUC4MU94.mjs +0 -1
  69. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DOe1K6eL.mjs +0 -11
  70. package/dist/packem_shared/SHAPES_FILENAME-BMT5EVQI.mjs +0 -1
  71. package/dist/packem_shared/WORKFLOWS_FILENAME-BIjSK96U.mjs +0 -1
  72. package/dist/packem_shared/attribution-CTEeAmtS.mjs +0 -1
  73. package/dist/packem_shared/chain-ChloHMQt.mjs +0 -1
  74. package/dist/packem_shared/context-property-calls-CtIWno5c.mjs +0 -1
  75. package/dist/packem_shared/discoverFunctions-AcXUQuyo.mjs +0 -1
  76. package/dist/packem_shared/discoverHttpRoutes-C7qeDpp3.mjs +0 -1
  77. package/dist/packem_shared/discoverHyperdriveCalls-CeyhQdv3.mjs +0 -1
  78. package/dist/packem_shared/discoverInserts-Db4we2Lt.mjs +0 -1
  79. package/dist/packem_shared/discoverMaskProcedures-DKS6xOnB.mjs +0 -1
  80. package/dist/packem_shared/discoverMigrations-CyySAw7Z.mjs +0 -1
  81. package/dist/packem_shared/discoverNondeterministicCalls-Bl_vaQUi.mjs +0 -1
  82. package/dist/packem_shared/discoverQueries-DHtbg9iS.mjs +0 -1
  83. package/dist/packem_shared/discoverR2sqlCalls-BNKRNkrB.mjs +0 -1
  84. package/dist/packem_shared/discoverRlsProcedures-zDOYuzjt.mjs +0 -1
  85. package/dist/packem_shared/discoverSchema-DPghAnQv.mjs +0 -1
  86. package/dist/packem_shared/emitDrizzleSchema-Cv0HtLR3.mjs +0 -15
  87. package/dist/packem_shared/exported-procedure-chains-gbM1pign.mjs +0 -1
  88. package/dist/packem_shared/index-Bq-b_-7H.mjs +0 -1
  89. package/dist/packem_shared/listLunoraSourceFiles-DmOftuU4.mjs +0 -1
  90. package/dist/packem_shared/shared-DjUziztz.mjs +0 -9
@@ -1,4 +1,4 @@
1
- import{LunoraError as vt}from"@lunora/errors";import{serializeSchemaSnapshot as kt,hashSchemaSnapshot as St}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{isHyperdriveGlobalTable as Rt,isD1GlobalTable as xt}from"./isD1GlobalTable-udvHAAzD.mjs";import{p as At,i as Dt}from"./ir-DBSvhNa-.mjs";import{r as h}from"./json-data-Chfs2Cz5.mjs";import{r as C,e as Tt,a as Ot,b as Et,c as Ct,d as Lt,f as It,g as _t,h as Mt,i as Pt,j as qt,k as Nt,l as $t,m as Ft,n as Ut,o as Bt,p as Wt,q as jt}from"./shard-runtime-B8rucwkF.mjs";import{u as K,i as Ht,G as Vt,d as Kt}from"./shared-DjUziztz.mjs";const Gt=` /**
1
+ import{LunoraError as vt}from"@lunora/errors";import{serializeSchemaSnapshot as kt,hashSchemaSnapshot as St}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{isHyperdriveGlobalTable as Rt,isD1GlobalTable as xt}from"./isD1GlobalTable-udvHAAzD.mjs";import{p as At,i as Dt}from"./ir-DBSvhNa-.mjs";import{r as h}from"./json-data-Chfs2Cz5.mjs";import{r as C,e as Tt,a as Ot,b as Et,c as Ct,d as Lt,f as It,g as _t,h as Mt,i as Pt,j as qt,k as Nt,l as $t,m as Ft,n as Ut,o as Bt,p as Wt,q as jt}from"./shard-runtime-B1nU9CRa.mjs";import{u as K,i as Ht,G as Vt,d as Kt}from"./shared-BXUKWh7t.mjs";const Gt=` /**
2
2
  * The bare writer every admin/maintenance entry point writes through.
3
3
  *
4
4
  * Admin and maintenance writes go through the SAME reactive-cache hooks as a
@@ -1,4 +1,4 @@
1
- import{s as b}from"./ir-DBSvhNa-.mjs";import{r as y}from"./json-data-Chfs2Cz5.mjs";import{CAPABILITIES as $}from"./CAPABILITY_PROBES-DFsutD7g.mjs";import{a as c,G as p}from"./shared-DjUziztz.mjs";const W=e=>e?{importFragment:"serveRelationFanout, ",override:`
1
+ import{s as b}from"./ir-DBSvhNa-.mjs";import{r as y}from"./json-data-Chfs2Cz5.mjs";import{CAPABILITIES as $}from"./CAPABILITY_PROBES-DFsutD7g.mjs";import{a as c,G as p}from"./shared-BXUKWh7t.mjs";const W=e=>e?{importFragment:"serveRelationFanout, ",override:`
2
2
  protected override async runRelationFanoutRead(functionPath: string, args: Record<string, unknown>): Promise<unknown> {
3
3
  this.ensureMigrated();
4
4
 
@@ -0,0 +1,9 @@
1
+ import{LunoraError as u}from"@lunora/errors";import{R as $}from"./reserved-words-CW1QFbTd.mjs";import{acceptsAbsentIr as b}from"./LUNORA_ERROR_CODES-C2s0xWQD.mjs";const g=/^(?:"(?:[^"\\]|\\(?:["\\/bfnrt]|u[0-9A-Fa-f]{4}))*"|'[^'\\]*'|-?\d+(?:\.\d+)?|true|false|null)$/u,k=`// GENERATED by @lunora/codegen — do not edit.
2
+ // Run \`lunora codegen\` to regenerate.
3
+
4
+ `,I=(e=!1)=>e?{client:"lunorash/client",do:"lunorash/do",flags:"lunorash/flags",server:"lunorash/server",serverDataModel:"lunorash/server/data-model",serverDrizzle:"lunorash/server/drizzle",serverTypes:"lunorash/server/types",values:"lunorash/values"}:{client:"@lunora/client",do:"@lunora/do",flags:"@lunora/flags",server:"@lunora/server",serverDataModel:"@lunora/server/data-model",serverDrizzle:"@lunora/server/drizzle",serverTypes:"@lunora/server/types",values:"@lunora/values"},i=/^[A-Za-z_$][\w$]*$/u,A=/^[\w./-]+$/u,f=(e,n)=>{if(!i.test(e)||$.has(e))throw new u("INTERNAL",`@lunora/codegen: ${n} is not a valid JS identifier: ${JSON.stringify(e)}`)},N=(e,n)=>{if(!i.test(e))throw new u("INTERNAL",`@lunora/codegen: ${n} is not a valid JS identifier: ${JSON.stringify(e)}`)},O=e=>e.charAt(0).toUpperCase()+e.slice(1),a=e=>i.test(e)?e:JSON.stringify(e),S=e=>e==="__proto__"?`[${JSON.stringify(e)}]`:a(e),d={any:"unknown",bigint:"bigint",boolean:"boolean",bytes:"ArrayBuffer",date:"number",geoPoint:"{ lat: number; lng: number }",null:"null",number:"number",storage:"string",string:"string",timestamp:"number"},T=e=>{if(e===void 0)return"unknown";if(!g.test(e))throw new u("INTERNAL",`@lunora/codegen: v.literal() argument is not a parseable string/number/boolean/null literal: ${JSON.stringify(e)}`);return e},t=e=>e.column?.notNull===!1?`${p(e)} | null`:p(e),p=e=>{const n=d[e.kind];if(n!==void 0)return n;switch(e.kind){case"array":return`Array<${e.inner?t(e.inner):"unknown"}>`;case"from":return e.tsType??"unknown";case"id":{const r=e.tableName??"_unknown_";return f(r,"v.id() table name"),`Id<"${r}">`}case"literal":return T(e.literalValue);case"object":return e.shape?`{ ${Object.entries(e.shape).map(([s,o])=>y(s,o)).join("; ")} }`:"Record<string, unknown>";case"optional":return`${e.inner?t(e.inner):"unknown"} | undefined`;case"record":{const r=e.keyType?t(e.keyType):"string",s=e.valueType?t(e.valueType):"unknown";return`Record<${r}, ${s}>`}case"union":return e.members&&e.members.length>0?e.members.map(r=>t(r)).join(" | "):"never";default:return"unknown"}},y=(e,n)=>{const r=a(e);if(n.kind==="optional"){const s=n.inner?t(n.inner):"unknown";return`${r}?: ${s}`}return b(n)?`${r}?: ${t(n)}`:`${r}: ${t(n)}`},D=e=>{const n=Object.entries(e);return n.length===0?"{}":`{ ${n.map(([r,s])=>y(r,s)).join("; ")} }`},E=e=>e.kind==="optional"||!!e.column?.hasDefault,h=e=>e.kind==="optional"&&e.inner?e.inner:e,j=e=>{f(e.name,"table name");const n=Object.entries(e.shape).map(([s,o])=>{const m=h(o),c=t(m),l=a(s);return E(o)?` ${l}?: ${c};`:` ${l}: ${c};`}).join(`
5
+ `),r=n?`
6
+ ${n}
7
+ `:"";return`export interface Insert_${e.name} {
8
+ _id?: Id<"${e.name}">;
9
+ _creationTime?: number;${r}}`};export{k as G,A as I,g as L,f as a,a as b,S as c,I as d,j as e,N as f,E as i,O as p,D as r,h as u,t as v};
@@ -1 +1 @@
1
- import{Node as l,SyntaxKind as g}from"ts-morph";import{lunoraRelativePath as L}from"./listLunoraSourceFiles-DmOftuU4.mjs";import{posix as D}from"node:path";let S,v;const Ae=e=>{const t=S,n=[];S=n;try{return{erased:n,value:e()}}finally{S=t}},Te=e=>{S?.push(...e)},j=e=>{for(const t of e.getAncestors())if(l.isVariableDeclaration(t))return t.getName()},w=(e,t)=>{S?.push({exportName:j(e),filePath:e.getSourceFile().getFilePath(),line:e.getStartLineNumber(),rendered:t})},Ne=e=>{v!==void 0&&w(v,e)},xe=(e,t)=>{const n=v;v=e;try{return t()}finally{v=n}},k=(e,t)=>{const n=e.exportName??`line ${e.line.toString()}`;return{cacheKey:`procedure_return_type_erased:${t}:${n}`,categories:["SCHEMA"],description:"Codegen renders a procedure's return type into `_generated/`, where only names that resolve from that directory may appear. A type it can neither name nor reproduce structurally — a class instance, a call or index signature, a recursive or very deeply nested shape — is emitted as `unknown` instead, so callers lose the shape while the runtime still returns it.",detail:`\`${n}\` in \`${t}\` (line ${e.line.toString()}) returns \`${e.rendered}\`, which codegen could not reproduce — its generated type is \`unknown\`.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e.exportName,filePath:t,line:e.line,rendered:e.rendered},name:"procedure_return_type_erased",remediation:"Declare the shape explicitly with `.output(...)`, or export the type from the module that declares it so codegen can name it. A class instance cannot cross the wire at all — return a plain object.",title:"Procedure return type is missing from the generated type"}},De=(e,t)=>{const n=new Map;for(const r of e){const s=k(r,L(t,r.filePath));n.set(s.cacheKey,s)}return[...n.values()].toSorted((r,s)=>r.cacheKey.localeCompare(s.cacheKey))},P=/\bany\b(?!\s*(?:\?\s*)?:)/u,U=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,O=e=>P.test(e.replaceAll(U,"")),K="/_generated/",B=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(n=>n?.getDeclarations()??[]);return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},F=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,T=e=>{for(const t of e.getAncestors())if(l.isModuleDeclaration(t)){const n=F.exec(t.getName());if(n?.groups?.specifier!==void 0)return n.groups.specifier}},h=new WeakMap,V=(e,t)=>{const n=e.getSymbol();if(n===void 0)return;let r=h.get(n.compilerSymbol);return r===void 0&&(r=new Map,h.set(n.compilerSymbol,r)),r.has(t)||r.set(t,n.getExport(t)??e.getExportSymbols().find(s=>s.getName()===t)),r.get(t)},_=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(n=>n.getName()===t),W=(e,t,n)=>e.getModuleSpecifierValue()===t&&_(e,n)?n:void 0,q=(e,t)=>{const n=e.getDefaultImport();if(n===void 0)return;const r=n.getSymbol();return(r?.getAliasedSymbol()??r)?.getDeclarations().includes(t)===!0?"default":void 0},G=(e,t,n)=>{if(!_(e,n))return;const r=e.getModuleSpecifierSourceFile(),s=r===void 0?void 0:V(r,n);return(s?.getAliasedSymbol()??s)?.getDeclarations().includes(t)===!0?n:void 0},X=/^\.\.?(?:$|\/)/u,H=new Map([[".cjs",".cjs"],[".cts",".cjs"],[".d.ts",".js"],[".js",".js"],[".jsx",".jsx"],[".mjs",".mjs"],[".mts",".mjs"],[".ts",".js"],[".tsx",".js"]]),Y=(e,t)=>{const n=t.getModuleSpecifierValue();if(!X.test(n))return;const r=t.getModuleSpecifierSourceFile(),s=r===void 0?void 0:H.get(r.getExtension());if(r===void 0||s===void 0)return;const i=`${D.join(r.getDirectoryPath(),r.getBaseNameWithoutExtension())}${s}`,o=D.relative(e.getDirectoryPath(),i);return o.startsWith(".")?o:`./${o}`},J=(e,t,n)=>{const r=T(t);for(const s of e.getImportDeclarations()){const i=r===void 0?q(s,t)??G(s,t,n):W(s,r,n);if(i!==void 0)return{exportName:i,specifier:Y(e,s)??s.getModuleSpecifierValue()}}},z=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(n=>{const r=n.indexOf("*");return r===-1?e===n:e.startsWith(n.slice(0,r))&&e.endsWith(n.slice(r+1))}),m={kind:"verbatim"},p={kind:"expand"},Q=new Set([g.ClassDeclaration,g.EnumDeclaration,g.EnumMember,g.InterfaceDeclaration,g.TypeAliasDeclaration]),Z=e=>T(e)!==void 0||l.isExportable(e)&&e.isExported(),ee=(e,t)=>new RegExp(String.raw`(?<![$\w])${t.replaceAll(/[$()*+.?[\\\]^{|}]/gu,String.raw`\$&`)}(?![$\w])`,"u").test(e),M=(e,t,n,r)=>{const s=e.getSourceFile();if(s.getSymbol()===void 0&&T(e)===void 0||!Q.has(e.getKind()))return m;const i=s.getFilePath();if(i.includes(K))return m;if(i===n)return p;const o=l.isEnumMember(e)?e.getParent():e;if(!l.hasName(o))return p;const a=J(t.getSourceFile(),o,o.getName());return a===void 0?Z(o)||!ee(r(),o.getName())?m:p:z(a.specifier,t)?p:{kind:"qualify",qualified:a}},te=new Set([g.ClassDeclaration,g.EnumDeclaration,g.FunctionDeclaration,g.ModuleDeclaration]),I=e=>{const t=e?.getDeclarations()??[];return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},ne=e=>{for(const t of e.getDeclarations()){const n=t.getFirstChildByKind(g.ComputedPropertyName);if(n!==void 0){let r=n.getExpression();for(;l.isPropertyAccessExpression(r);)r=r.getExpression();return r}}},re=(e,t)=>{if(e.getProperties().some(s=>{if(!s.getName().startsWith("__@"))return!1;const i=ne(s);return i===void 0||!I(i.getSymbol())}))return!0;const r=e.getSymbol();return r!==void 0&&r.getDeclarations().some(s=>te.has(s.getKind()))&&!I(r)&&t().startsWith("typeof ")},R=(e,t,n)=>{const r=e.getAliasSymbol(),s=e.getSymbol(),i=new Set((r??s)?.getDeclarations());let o=!1,a;const c=()=>(a??=e.getText(t),a);for(const u of[s,r].flatMap(d=>d?.getDeclarations()??[])){const d=M(u,t,n,c);if(d.kind==="qualify"&&i.has(u))return d;o||=d.kind!=="verbatim"}return o||re(e,c)?p:m},se=(e,t,n)=>{const r=l.isPropertySignature(e)||l.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(r===void 0)return m;let s=!1;for(const i of[r,...r.getDescendantsOfKind(g.TypeReference)].filter(o=>l.isTypeReference(o))){const o=i.getTypeName().getSymbol();for(const a of(o?.getAliasedSymbol()??o)?.getDeclarations()??[]){const c=M(a,t,n,()=>i.getText());if(c.kind==="qualify")return c;s||=c.kind!=="verbatim"}}return s?p:m},oe=/^[A-Za-z_$][\w$]*$/u,ie=e=>oe.test(e)?e:JSON.stringify(e),$=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},y=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0&&!e.getProperties().some(t=>t.getName().startsWith("__@")),E=(e,t,n,r=new Set)=>r.has(e)?!1:(r.add(e),R(e,t,n).kind!=="verbatim"||$(e).some(s=>E(s,t,n,r))?!0:y(e)?e.getProperties().some(s=>s.getDeclarations().some(i=>se(i,t,n).kind!=="verbatim")?!0:E(s.getTypeAtLocation(t),t,n,r)):!1),ae=(e,t)=>{const n=e.getValueDeclaration()??e.getDeclarations()[0];return n&&(l.isPropertySignature(n)||l.isPropertyDeclaration(n))&&n.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},C=(e,t)=>e!==void 0&&(y(e)||e.isString()||e.isNumber()||e.isBigInt()||e.isBoolean()||e.isLiteral()||e.isBooleanLiteral()||e.isEnumLiteral()||e.isTemplateLiteral()||e.isNull()||e.isUndefined()||e.isAny()||e.isUnknown()||e.isNever()||e.isVoid())?t:`(${t})`,ce=32,ue=8,le=(e,t,n,r,s,i)=>{const o=e.getArrayElementType(),a=o?i(o,t,n,r,s):void 0;if(a!==void 0)return`${C(o,a)}[]`},ge=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getUnionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(c)}return o.join(" | ")},de=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getIntersectionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(C(a,c))}return o.join(" & ")},me=(e,t,n,r,s,i)=>{if(!y(e))return;const o=[];for(const a of e.getProperties()){const c=a.getTypeAtLocation(t),u=ae(a,c),d=u&&c.isUnion()?c.getUnionTypes().filter(A=>!A.isUndefined()):[c],N=[];for(const A of d){const x=i(A,t,n,r+1,s);if(x===void 0)return;N.push(x)}o.push(`${ie(a.getName())}${u?"?":""}: ${N.join(" | ")}`)}return o.length>0?`{ ${o.join("; ")} }`:"{}"},fe=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},pe=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isClassDeclaration(t)||l.isClassExpression(t)),b=(e,t,n,r,s=new Set)=>{if(r.has(e)||s.has(e))return!1;if(n>ce)return!0;const i=new Set(r).add(e);if($(e).some(u=>b(u,t,n+1,i,s)))return!0;const o=e.getArrayElementType();if(o!==void 0)return b(o,t,n+1,i,s);if(B(e))return s.add(e),!1;if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(u=>u?.getDeclarations()??[]).some(u=>l.isClassDeclaration(u)||l.isClassExpression(u)))return!0;const c=y(e)&&e.getProperties().some(u=>b(u.getTypeAtLocation(t),t,n+1,i,s));return c||s.add(e),c},Se=(e,t,n,r,s,i,o)=>{const a=[];for(const c of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const u=o(c,n,r,s+1,i);if(u===void 0)return;a.push(u)}return`import("${e.specifier}").${e.exportName}${a.length>0?`<${a.join(", ")}>`:""}`},ve=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isEnumDeclaration(t)||l.isEnumMember(t)),f=(e,t,n,r,s)=>{if(r>ue||s.has(e))return;const i=R(e,t,n);if(i.kind==="verbatim"&&!E(e,t,n))return e.getText(t);const o=new Set(s).add(e);if(!pe(e)){if(e.isEnumLiteral())return fe(e);if(i.kind==="qualify"&&!ve(e)){const a=Se(i.qualified,e,t,n,r,o,f);if(a!==void 0)return a}return e.isArray()?le(e,t,n,r,o,f):e.isUnion()?ge(e,t,n,r,o,f):e.isIntersection()?de(e,t,n,r,o,f):me(e,t,n,r,o,f)}},he=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let n=t.getReturnType();const s=(n.getSymbol()??n.getAliasSymbol())?.getName();if(s==="Promise"||s==="AsyncIterable"||s==="AsyncIterableIterator"||s==="AsyncGenerator"){const a=n.getTypeArguments()[0];a&&(n=a)}const i=n.getText(e);if(!i||i==="any"||i==="never"||O(i)||b(n,e,0,new Set))return"unknown";const o=e.getSourceFile().getFilePath();if(E(n,e,o)){const a=f(n,e,o,0,new Set);return a===void 0&&w(e,i),a??"unknown"}return i};export{E as a,Ne as b,Ae as c,De as d,f as e,O as i,xe as p,Te as r,he as u};
1
+ import{Node as l,SyntaxKind as g}from"ts-morph";import{lunoraRelativePath as L}from"./listLunoraSourceFiles-DRes9d5p.mjs";import{posix as D}from"node:path";let S,v;const Ae=e=>{const t=S,n=[];S=n;try{return{erased:n,value:e()}}finally{S=t}},Te=e=>{S?.push(...e)},j=e=>{for(const t of e.getAncestors())if(l.isVariableDeclaration(t))return t.getName()},w=(e,t)=>{S?.push({exportName:j(e),filePath:e.getSourceFile().getFilePath(),line:e.getStartLineNumber(),rendered:t})},Ne=e=>{v!==void 0&&w(v,e)},xe=(e,t)=>{const n=v;v=e;try{return t()}finally{v=n}},k=(e,t)=>{const n=e.exportName??`line ${e.line.toString()}`;return{cacheKey:`procedure_return_type_erased:${t}:${n}`,categories:["SCHEMA"],description:"Codegen renders a procedure's return type into `_generated/`, where only names that resolve from that directory may appear. A type it can neither name nor reproduce structurally — a class instance, a call or index signature, a recursive or very deeply nested shape — is emitted as `unknown` instead, so callers lose the shape while the runtime still returns it.",detail:`\`${n}\` in \`${t}\` (line ${e.line.toString()}) returns \`${e.rendered}\`, which codegen could not reproduce — its generated type is \`unknown\`.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e.exportName,filePath:t,line:e.line,rendered:e.rendered},name:"procedure_return_type_erased",remediation:"Declare the shape explicitly with `.output(...)`, or export the type from the module that declares it so codegen can name it. A class instance cannot cross the wire at all — return a plain object.",title:"Procedure return type is missing from the generated type"}},De=(e,t)=>{const n=new Map;for(const r of e){const s=k(r,L(t,r.filePath));n.set(s.cacheKey,s)}return[...n.values()].toSorted((r,s)=>r.cacheKey.localeCompare(s.cacheKey))},P=/\bany\b(?!\s*(?:\?\s*)?:)/u,U=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,O=e=>P.test(e.replaceAll(U,"")),K="/_generated/",B=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(n=>n?.getDeclarations()??[]);return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},F=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,T=e=>{for(const t of e.getAncestors())if(l.isModuleDeclaration(t)){const n=F.exec(t.getName());if(n?.groups?.specifier!==void 0)return n.groups.specifier}},h=new WeakMap,V=(e,t)=>{const n=e.getSymbol();if(n===void 0)return;let r=h.get(n.compilerSymbol);return r===void 0&&(r=new Map,h.set(n.compilerSymbol,r)),r.has(t)||r.set(t,n.getExport(t)??e.getExportSymbols().find(s=>s.getName()===t)),r.get(t)},_=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(n=>n.getName()===t),W=(e,t,n)=>e.getModuleSpecifierValue()===t&&_(e,n)?n:void 0,q=(e,t)=>{const n=e.getDefaultImport();if(n===void 0)return;const r=n.getSymbol();return(r?.getAliasedSymbol()??r)?.getDeclarations().includes(t)===!0?"default":void 0},G=(e,t,n)=>{if(!_(e,n))return;const r=e.getModuleSpecifierSourceFile(),s=r===void 0?void 0:V(r,n);return(s?.getAliasedSymbol()??s)?.getDeclarations().includes(t)===!0?n:void 0},X=/^\.\.?(?:$|\/)/u,H=new Map([[".cjs",".cjs"],[".cts",".cjs"],[".d.ts",".js"],[".js",".js"],[".jsx",".jsx"],[".mjs",".mjs"],[".mts",".mjs"],[".ts",".js"],[".tsx",".js"]]),Y=(e,t)=>{const n=t.getModuleSpecifierValue();if(!X.test(n))return;const r=t.getModuleSpecifierSourceFile(),s=r===void 0?void 0:H.get(r.getExtension());if(r===void 0||s===void 0)return;const i=`${D.join(r.getDirectoryPath(),r.getBaseNameWithoutExtension())}${s}`,o=D.relative(e.getDirectoryPath(),i);return o.startsWith(".")?o:`./${o}`},J=(e,t,n)=>{const r=T(t);for(const s of e.getImportDeclarations()){const i=r===void 0?q(s,t)??G(s,t,n):W(s,r,n);if(i!==void 0)return{exportName:i,specifier:Y(e,s)??s.getModuleSpecifierValue()}}},z=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(n=>{const r=n.indexOf("*");return r===-1?e===n:e.startsWith(n.slice(0,r))&&e.endsWith(n.slice(r+1))}),m={kind:"verbatim"},p={kind:"expand"},Q=new Set([g.ClassDeclaration,g.EnumDeclaration,g.EnumMember,g.InterfaceDeclaration,g.TypeAliasDeclaration]),Z=e=>T(e)!==void 0||l.isExportable(e)&&e.isExported(),ee=(e,t)=>new RegExp(String.raw`(?<![$\w])${t.replaceAll(/[$()*+.?[\\\]^{|}]/gu,String.raw`\$&`)}(?![$\w])`,"u").test(e),M=(e,t,n,r)=>{const s=e.getSourceFile();if(s.getSymbol()===void 0&&T(e)===void 0||!Q.has(e.getKind()))return m;const i=s.getFilePath();if(i.includes(K))return m;if(i===n)return p;const o=l.isEnumMember(e)?e.getParent():e;if(!l.hasName(o))return p;const a=J(t.getSourceFile(),o,o.getName());return a===void 0?Z(o)||!ee(r(),o.getName())?m:p:z(a.specifier,t)?p:{kind:"qualify",qualified:a}},te=new Set([g.ClassDeclaration,g.EnumDeclaration,g.FunctionDeclaration,g.ModuleDeclaration]),I=e=>{const t=e?.getDeclarations()??[];return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},ne=e=>{for(const t of e.getDeclarations()){const n=t.getFirstChildByKind(g.ComputedPropertyName);if(n!==void 0){let r=n.getExpression();for(;l.isPropertyAccessExpression(r);)r=r.getExpression();return r}}},re=(e,t)=>{if(e.getProperties().some(s=>{if(!s.getName().startsWith("__@"))return!1;const i=ne(s);return i===void 0||!I(i.getSymbol())}))return!0;const r=e.getSymbol();return r!==void 0&&r.getDeclarations().some(s=>te.has(s.getKind()))&&!I(r)&&t().startsWith("typeof ")},R=(e,t,n)=>{const r=e.getAliasSymbol(),s=e.getSymbol(),i=new Set((r??s)?.getDeclarations());let o=!1,a;const c=()=>(a??=e.getText(t),a);for(const u of[s,r].flatMap(d=>d?.getDeclarations()??[])){const d=M(u,t,n,c);if(d.kind==="qualify"&&i.has(u))return d;o||=d.kind!=="verbatim"}return o||re(e,c)?p:m},se=(e,t,n)=>{const r=l.isPropertySignature(e)||l.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(r===void 0)return m;let s=!1;for(const i of[r,...r.getDescendantsOfKind(g.TypeReference)].filter(o=>l.isTypeReference(o))){const o=i.getTypeName().getSymbol();for(const a of(o?.getAliasedSymbol()??o)?.getDeclarations()??[]){const c=M(a,t,n,()=>i.getText());if(c.kind==="qualify")return c;s||=c.kind!=="verbatim"}}return s?p:m},oe=/^[A-Za-z_$][\w$]*$/u,ie=e=>oe.test(e)?e:JSON.stringify(e),$=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},y=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0&&!e.getProperties().some(t=>t.getName().startsWith("__@")),E=(e,t,n,r=new Set)=>r.has(e)?!1:(r.add(e),R(e,t,n).kind!=="verbatim"||$(e).some(s=>E(s,t,n,r))?!0:y(e)?e.getProperties().some(s=>s.getDeclarations().some(i=>se(i,t,n).kind!=="verbatim")?!0:E(s.getTypeAtLocation(t),t,n,r)):!1),ae=(e,t)=>{const n=e.getValueDeclaration()??e.getDeclarations()[0];return n&&(l.isPropertySignature(n)||l.isPropertyDeclaration(n))&&n.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},C=(e,t)=>e!==void 0&&(y(e)||e.isString()||e.isNumber()||e.isBigInt()||e.isBoolean()||e.isLiteral()||e.isBooleanLiteral()||e.isEnumLiteral()||e.isTemplateLiteral()||e.isNull()||e.isUndefined()||e.isAny()||e.isUnknown()||e.isNever()||e.isVoid())?t:`(${t})`,ce=32,ue=8,le=(e,t,n,r,s,i)=>{const o=e.getArrayElementType(),a=o?i(o,t,n,r,s):void 0;if(a!==void 0)return`${C(o,a)}[]`},ge=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getUnionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(c)}return o.join(" | ")},de=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getIntersectionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(C(a,c))}return o.join(" & ")},me=(e,t,n,r,s,i)=>{if(!y(e))return;const o=[];for(const a of e.getProperties()){const c=a.getTypeAtLocation(t),u=ae(a,c),d=u&&c.isUnion()?c.getUnionTypes().filter(A=>!A.isUndefined()):[c],N=[];for(const A of d){const x=i(A,t,n,r+1,s);if(x===void 0)return;N.push(x)}o.push(`${ie(a.getName())}${u?"?":""}: ${N.join(" | ")}`)}return o.length>0?`{ ${o.join("; ")} }`:"{}"},fe=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},pe=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isClassDeclaration(t)||l.isClassExpression(t)),b=(e,t,n,r,s=new Set)=>{if(r.has(e)||s.has(e))return!1;if(n>ce)return!0;const i=new Set(r).add(e);if($(e).some(u=>b(u,t,n+1,i,s)))return!0;const o=e.getArrayElementType();if(o!==void 0)return b(o,t,n+1,i,s);if(B(e))return s.add(e),!1;if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(u=>u?.getDeclarations()??[]).some(u=>l.isClassDeclaration(u)||l.isClassExpression(u)))return!0;const c=y(e)&&e.getProperties().some(u=>b(u.getTypeAtLocation(t),t,n+1,i,s));return c||s.add(e),c},Se=(e,t,n,r,s,i,o)=>{const a=[];for(const c of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const u=o(c,n,r,s+1,i);if(u===void 0)return;a.push(u)}return`import("${e.specifier}").${e.exportName}${a.length>0?`<${a.join(", ")}>`:""}`},ve=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isEnumDeclaration(t)||l.isEnumMember(t)),f=(e,t,n,r,s)=>{if(r>ue||s.has(e))return;const i=R(e,t,n);if(i.kind==="verbatim"&&!E(e,t,n))return e.getText(t);const o=new Set(s).add(e);if(!pe(e)){if(e.isEnumLiteral())return fe(e);if(i.kind==="qualify"&&!ve(e)){const a=Se(i.qualified,e,t,n,r,o,f);if(a!==void 0)return a}return e.isArray()?le(e,t,n,r,o,f):e.isUnion()?ge(e,t,n,r,o,f):e.isIntersection()?de(e,t,n,r,o,f):me(e,t,n,r,o,f)}},he=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let n=t.getReturnType();const s=(n.getSymbol()??n.getAliasSymbol())?.getName();if(s==="Promise"||s==="AsyncIterable"||s==="AsyncIterableIterator"||s==="AsyncGenerator"){const a=n.getTypeArguments()[0];a&&(n=a)}const i=n.getText(e);if(!i||i==="any"||i==="never"||O(i)||b(n,e,0,new Set))return"unknown";const o=e.getSourceFile().getFilePath();if(E(n,e,o)){const a=f(n,e,o,0,new Set);return a===void 0&&w(e,i),a??"unknown"}return i};export{E as a,Ne as b,Ae as c,De as d,f as e,O as i,xe as p,Te as r,he as u};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.259",
3
+ "version": "1.0.0-alpha.260",
4
4
  "description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -46,8 +46,8 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@lunora/advisor": "1.0.0-alpha.188",
50
- "@lunora/agent": "1.0.0-alpha.172",
49
+ "@lunora/advisor": "1.0.0-alpha.189",
50
+ "@lunora/agent": "1.0.0-alpha.174",
51
51
  "@lunora/container": "1.0.0-alpha.69",
52
52
  "@lunora/errors": "1.0.0-alpha.50",
53
53
  "@lunora/platform": "1.0.0-alpha.55",
@@ -1 +0,0 @@
1
- import{existsSync as p}from"node:fs";import{join as f}from"node:path";import{agentDefaultName as d,agentClassName as b,voiceBindingName as N,voiceClassName as y}from"@lunora/agent/naming";import{LunoraError as m}from"@lunora/errors";import{Node as s,SyntaxKind as u}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapToCallExpression as A,findObjectProperty as c,stringPropertyFor as w}from"./listLunoraSourceFiles-DmOftuU4.mjs";const h="agents.ts",E=o=>{const n=o.getSymbol();if(!n)return o.getText()==="defineAgent";for(const t of n.getDeclarations())if(s.isImportSpecifier(t))return t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/agent"?!1:t.getNameNode().getText()==="defineAgent";return!1},P=w("agent"),v=(o,n,t)=>{if(o.getKind()===u.TrueKeyword)return!0;if(o.getKind()===u.FalseKeyword)return!1;throw l(o,`agent "${n}": \`${t}\` must be a static boolean literal — it is deploy configuration codegen writes into the ctx.agents wiring spec`)},T=(o,n)=>{const t=o.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))throw l(o,`agent "${n}": defineAgent must be passed an inline object literal`);const e={className:b(n),exportName:n,name:d(n)},i=c(t,"name");i&&s.isPropertyAssignment(i)&&(e.name=P(i.getInitializerOrThrow(),n,"name"));const r=c(t,"publicRun");r&&s.isPropertyAssignment(r)&&v(r.getInitializerOrThrow(),n,"publicRun")&&(e.publicRun=!0);const a=c(t,"voice");if(a&&s.isPropertyAssignment(a)){const g=a.getInitializerOrThrow();if(!s.isObjectLiteralExpression(g))throw l(g,`agent "${n}": \`voice\` must be an inline object literal — its presence tells codegen to emit the voice-session Durable Object`);e.voice=!0,e.voiceBindingName=N(n),e.voiceClassName=y(n)}return c(t,"onEmail")&&(e.onEmail=!0),e},I=o=>{const n=[];for(const t of o.getVariableDeclarations()){if(!t.isExported())continue;const e=A(t.getInitializer());if(!e)continue;const i=e.getExpression();if(!s.isIdentifier(i)||!E(i))continue;const r=t.getNameNode();if(!s.isIdentifier(r))throw l(r,"defineAgent exports must be plain named exports (no destructuring)");n.push(T(e,r.getText()))}return n},x=o=>{const n=new Map,t=new Map;for(const e of o){const i=n.get(e.name);if(i!==void 0)throw new m("DUPLICATE_AGENT_NAME",`Duplicate agent name "${e.name}": produced by both "${i}" and "${e.exportName}". Deployed agent names must be unique across the project.`,{status:500});n.set(e.name,e.exportName);const r=t.get(e.className);if(r!==void 0)throw new m("DUPLICATE_AGENT_CLASS",`Duplicate agent class "${e.className}": produced by both "${r}" and "${e.exportName}". Agent export names must yield unique generated class names.`,{status:500});t.set(e.className,e.exportName)}},O=(o,n)=>{const t=f(n,h);if(!p(t))return[];const e=o.getSourceFile(t)??o.addSourceFileAtPath(t),i=I(e);return i.sort((r,a)=>r.exportName.localeCompare(a.exportName)),x(i),i};export{h as AGENTS_FILENAME,O as discoverAgents};
@@ -1 +0,0 @@
1
- import{existsSync as P}from"node:fs";import{join as T}from"node:path";import{containerClassName as j,containerBindingName as I,DURABLE_OBJECT_POLICY_FORBIDDEN_KEYS as A,isManagedImage as O,isCloudflareRegistryDigest as k,normalizeContainerImage as m}from"@lunora/container";import{SyntaxKind as v,Node as s}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{propertyKeyName as b,stringPropertyFor as C,findObjectProperty as h,symbolConstInitializer as _,outermostValueWrapper as p,isWriteTarget as D}from"./listLunoraSourceFiles-DmOftuU4.mjs";const M="containers.ts",F=t=>{const e=t.getSymbol();if(!e)return t.getText()==="defineContainer";for(const i of e.getDeclarations())if(s.isImportSpecifier(i))return i.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/container"?!1:i.getNameNode().getText()==="defineContainer";return!1},d=C("container"),y=(t,e,i)=>{if(s.isNumericLiteral(t))return t.getLiteralValue();throw a(t,`container "${e}": \`${i}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},$=(t,e)=>{if(s.isStringLiteral(t)||s.isNoSubstitutionTemplateLiteral(t))return m(t.getLiteralValue());if(s.isObjectLiteralExpression(t)){const i=h(t,"registry");if(i&&s.isPropertyAssignment(i)){const r=i.getInitializerOrThrow();return m({registry:d(r,e,"image.registry")})}const n=h(t,"build");if(n&&s.isPropertyAssignment(n)){const r=n.getInitializerOrThrow();return m({build:d(r,e,"image.build")})}}throw a(t,`container "${e}": \`image\` must be a static string path, { registry: "…" }, or { build: "…" } literal`)},V=new Set(["buildArgs","image","images","instanceType","maxInstances","name","rollout","sandbox","schedulingPolicy"]),B=new Set(["gracePeriodSeconds","stepPercentage"]),S=t=>{let e=t;for(;s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isTypeAssertion(e)||s.isParenthesizedExpression(e);)e=e.getExpression();return e},K=(t,e)=>e.getDescendantsOfKind(v.Identifier).some(i=>{if(i.getSymbol()!==t)return!1;let n=p(i),r=n.getParent();if(s.isCallExpression(r)&&r.getExpression().getText()==="Object.assign")return r.getArguments()[0]===n;for(;(s.isPropertyAccessExpression(r)||s.isElementAccessExpression(r))&&r.getExpression()===n;){if(D(r))return!0;n=p(r),r=n.getParent()}return!1}),R=16,E=(t,e,i,n)=>{let r={name:i,symbol:t},o;for(let l=0;l<R;l+=1){const c=_(r.symbol);if(c===void 0||!s.isExpression(c))return o;if(o=S(c),s.isObjectLiteralExpression(o)&&r.symbol!==void 0&&K(r.symbol,e.getSourceFile()))throw a(e,`${n}: \`${r.name}\` is a const object that is written to elsewhere in this file, so its initializer is not the value the container runs with. Declare the settings where they are final.`);if(!s.isIdentifier(o))return o;r={name:o.getText(),symbol:o.getSymbol()}}return o},L=(t,e)=>{const i=S(t);return s.isIdentifier(i)?E(i.getSymbol(),i,i.getText(),e)??i:i},U=t=>{const e=t.getNonNullableType();return(e.isUnion()?e.getUnionTypes():[e]).flatMap(n=>n.getApparentType().getProperties().map(r=>r.getName()))},z=(t,e,i)=>{const n=t.getExpression().getType(),r=e==="every"||n.isAny()||n.isUnknown()?["its keys"]:[...new Set(U(n))].filter(o=>e.has(o)).map(o=>`\`${o}\``);if(r.length>0)throw a(t,`${i}: this spread can set ${r.join(", ")}, which codegen writes into wrangler.jsonc and so must read statically. Spread a module-scope \`const\` object literal, or write the keys inline.`)},Y=(t,e,i)=>{const n=b(t),r=s.isShorthandPropertyAssignment(t)?E(t.getValueSymbol(),t,n,i):void 0;if(r!==void 0)return[n,r];if(e==="every"||e.has(n))throw a(t,`${i}: \`${n}\` is deploy configuration codegen writes into wrangler.jsonc, so it must be a static literal — inline it, or name a module-scope \`const\` initialized with one.`)},f=(t,e,i,n=new Set)=>{const r=[],o=new Set(n).add(t);for(const l of t.getProperties())if(s.isPropertyAssignment(l))r.push([b(l),L(l.getInitializerOrThrow(),i)]);else if(s.isSpreadAssignment(l))r.push(...W(l,e,i,o));else{const c=Y(l,e,i);c!==void 0&&r.push(c)}return r},W=(t,e,i,n)=>{const r=L(t.getExpression(),i);if(!s.isObjectLiteralExpression(r))return z(t,e,i),[];if(n.has(r))throw a(t,`${i}: this spread refers back to an object it is part of, so it has no static value.`);return f(r,e,i,n)},q=(t,e)=>{if(!s.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`buildArgs\` must be a static object literal — it is deploy configuration codegen writes into wrangler.jsonc`);const i={};for(const[n,r]of f(t,"every",`container "${e}" buildArgs`))i[n]=d(r,e,`buildArgs.${n}`);return Object.keys(i).length>0?i:void 0},N=(t,e)=>{if(!s.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`rollout\` must be a static object literal — it is deploy configuration codegen writes into wrangler.jsonc`);const i={};for(const[n,r]of f(t,B,`container "${e}" rollout`))(n==="gracePeriodSeconds"||n==="stepPercentage")&&(i[n]=y(r,e,`rollout.${n}`));return i.gracePeriodSeconds===void 0&&i.stepPercentage===void 0?void 0:i},w=t=>{if(s.isTrueLiteral(t))return!0;if(s.isFalseLiteral(t))return!1},H=t=>{if(s.isStringLiteral(t)||s.isNoSubstitutionTemplateLiteral(t)||s.isNumericLiteral(t))return t.getLiteralValue()},J=(t,e)=>{if(s.isStringLiteral(t))return t.getLiteralValue();if(s.isObjectLiteralExpression(t)){const i={};for(const n of t.getProperties()){if(!s.isPropertyAssignment(n))throw a(n,`container "${e}": \`instanceType\` must be an object of static number literals`);const r=b(n);if(r!=="diskMb"&&r!=="memoryMib"&&r!=="vcpu")throw a(n,`container "${e}": unknown \`instanceType\` field "${r}" — expected vcpu, memoryMib, or diskMb`);i[r]=y(n.getInitializerOrThrow(),e,`instanceType.${r}`)}return i}throw a(t,`container "${e}": \`instanceType\` must be a static string or { vcpu, memoryMib, diskMb } literal`)},X=(t,e)=>{if(!s.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`images\` must be a static object literal — codegen writes it into wrangler.jsonc`);const i={};for(const[n,r]of f(t,"every",`container "${e}" images`)){const o=$(r,e);if(o.kind==="build")throw a(r,`container "${e}": \`images["${n}"]\` cannot be a Railpack { build } source — use a Dockerfile path or a { registry } reference`);if(o.kind==="registry"&&!k(o.reference))throw a(r,`container "${e}": \`images["${n}"].registry\` must be a digest-pinned (@sha256) reference under registry.cloudflare.com — push other registries' images there first`);i[n]=o}return i},x=(t,e)=>{const i=t.findLast(([r])=>r==="schedulingPolicy");if(i===void 0)return;const n=d(i[1],e,"schedulingPolicy");if(n!=="default"&&n!=="durable_object")throw a(i[1],`container "${e}": unknown \`schedulingPolicy\` "${n}" — use "default" or "durable_object"`);return n==="durable_object"?n:void 0},G=(t,e,i,n)=>{if(i!==void 0&&A.includes(t))throw a(e,`container "${n}": \`${t}\` is not supported with schedulingPolicy "durable_object"`);if(i===void 0&&t==="images")throw a(e,`container "${n}": \`images\` needs schedulingPolicy "durable_object"`)},Q=(t,e,i,n)=>{const{base:r,policy:o}=i;switch(t){case"buildArgs":{r.buildArgs=q(e,n);break}case"enableInternet":{r.enableInternet=w(e);break}case"image":{i.scheduled||(o.image=$(e,n));break}case"images":{o.images=X(e,n);break}case"instanceType":{r.instanceType=J(e,n);break}case"maxInstances":{o.maxInstances=y(e,n,"maxInstances");break}case"name":{r.name=d(e,n,"name");break}case"rollout":{o.rollout=N(e,n);break}case"sandbox":{const l=w(e);if(l===void 0)throw a(e,`container "${n}": \`sandbox\` must be a static true/false literal`);r.sandbox=l;break}case"sleepAfter":{r.sleepAfter=H(e);break}}},Z=(t,e,i)=>{const n=t.findLast(([o])=>o==="image")?.[1];if(n===void 0||!(s.isStringLiteral(n)||s.isNoSubstitutionTemplateLiteral(n)))return;const r=n.getLiteralValue();if(!Object.hasOwn(e??{},r)&&!O(r))throw a(n,`container "${i}": \`image\` "${r}" must name an entry of \`images\` or a Cloudflare-managed "cloudflare/…" image`)},ee=(t,e)=>{const i=t.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))throw a(t,`container "${e}": defineContainer must be passed an inline object literal`);const n=f(i,V,`container "${e}"`),r=x(n,e),o={base:{bindingName:I(e),className:j(e),exportName:e},policy:{},scheduled:r!==void 0};for(const[u,g]of n)G(u,g,r,e),Q(u,g,o,e);const{base:l,policy:c}=o;if(r==="durable_object")return Z(n,c.images,e),{...l,...c.images===void 0?{}:{images:c.images},schedulingPolicy:r};if(c.image===void 0)throw a(i,`container "${e}": defineContainer requires a static \`image\` property`);return{...l,image:c.image,...c.maxInstances===void 0?{}:{maxInstances:c.maxInstances},...c.rollout===void 0?{}:{rollout:c.rollout}}},te=t=>{const e=[],i=new Map;for(const n of t.getVariableDeclarations()){if(!n.isExported())continue;const r=n.getInitializer();if(r?.getKind()!==v.CallExpression)continue;const o=r,l=o.getExpression();if(!s.isIdentifier(l)||!F(l))continue;const c=n.getNameNode();if(!s.isIdentifier(c))throw a(c,"defineContainer exports must be plain named exports (no destructuring)");const u=ee(o,c.getText()),g=i.get(u.bindingName);if(g!==void 0)throw a(c,`containers "${g}" and "${u.exportName}" both map to the binding ${u.bindingName} — rename one so each container gets its own Durable Object binding`);i.set(u.bindingName,u.exportName),e.push(u)}return e},ce=(t,e)=>{const i=T(e,M);if(!P(i))return[];const n=t.getSourceFile(i)??t.addSourceFileAtPath(i),r=te(n);return r.sort((o,l)=>o.exportName.localeCompare(l.exportName)),r};export{M as CONTAINERS_FILENAME,ce as discoverContainers};
@@ -1 +0,0 @@
1
- import{G as s,I as n,a as t,d as p,i,p as o,r as d,e as E,c as I,b as T,u as c,v as y}from"./shared-DjUziztz.mjs";import"./LUNORA_ERROR_CODES-C2s0xWQD.mjs";export{s as GENERATED_HEADER,n as IMPORT_PATH_RE,t as assertIdentifier,p as baseSpecifiers,i as isOptionalOnInsert,o as pascalCase,d as renderArgsType,E as renderInsertInterface,I as renderObjectKey,T as renderPropertyKey,c as unwrapOptional,y as validatorToType};
@@ -1 +0,0 @@
1
- import{existsSync as g}from"node:fs";import{join as d}from"node:path";import{Node as o,SyntaxKind as p}from"ts-morph";import{diagnosticAt as x}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as y}from"./module-specifiers-WF8iAydP.mjs";import{p as M}from"./parse-validator-Cs6F8SYG.mjs";import{findObjectProperty as a,unwrapExpression as S}from"./listLunoraSourceFiles-DmOftuU4.mjs";import{u as I}from"./unwrap-handler-return-Bnx99voQ.mjs";const E="mutators.ts",l=y,N=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineMutator";for(const r of t.getDeclarations())if(o.isImportSpecifier(r))return l(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="defineMutator":!1;return!1},v=e=>{const t=e.getSymbol();if(!t)return!1;for(const r of t.getDeclarations()){if(!o.isNamespaceImport(r))continue;const i=r.getFirstAncestorByKind(p.ImportDeclaration);return i!==void 0&&l(i.getModuleSpecifierValue())}return!1},m=e=>{if(o.isIdentifier(e))return N(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineMutator"&&o.isIdentifier(t)&&v(t)}return!1},f=e=>{const t=e.getArguments()[0];return t&&o.isObjectLiteralExpression(t)?t:void 0},C=e=>{const t=e.getInitializer();if(!o.isCallExpression(t)||!m(t.getExpression()))return;const r=a(f(t),"server");if(o.isMethodDeclaration(r))return r;const i=o.isPropertyAssignment(r)?S(r.getInitializer()):void 0;return o.isArrowFunction(i)||o.isFunctionExpression(i)?i:void 0},A=e=>{const t=a(e,"args");if(!t||!o.isPropertyAssignment(t))return{};const r=t.getInitializer();return r&&o.isObjectLiteralExpression(r)?M(r):{}},b=e=>{const t=a(e,"server");if(!t||!o.isPropertyAssignment(t))return"unknown";const r=t.getInitializer();return!r||!(o.isArrowFunction(r)||o.isFunctionExpression(r))?"unknown":I(r)},F=e=>{const t=a(e,"owner");if(!t||!o.isPropertyAssignment(t))return;const r=t.getInitializer();return r&&o.isStringLiteral(r)?r.getLiteralValue():void 0},P=e=>{const t=[];for(const r of e.getVariableDeclarations()){if(!r.isExported())continue;const i=r.getInitializer();if(i?.getKind()!==p.CallExpression)continue;const n=i,u=n.getExpression();if(!m(u))continue;const s=r.getNameNode();if(!o.isIdentifier(s))throw x(s,"defineMutator exports must be plain named exports (no destructuring)");const c=f(n);t.push({args:A(c),exportName:s.getText(),filePath:"mutators",line:n.getStartLineNumber(),owner:F(c),returnType:b(c)})}return t},V=(e,t)=>{const r=d(t,E);if(!g(r))return[];const i=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=P(i);return n.sort((u,s)=>u.exportName.localeCompare(s.exportName)),n};export{E as MUTATORS_FILENAME,V as discoverMutators,m as isDefineMutatorCallee,f as mutatorLiteral,C as mutatorServerImplOf};
@@ -1 +0,0 @@
1
- import{existsSync as x}from"node:fs";import{join as P}from"node:path";import{SyntaxKind as l,Node as c}from"ts-morph";import{listLunoraSourceFiles as p,lunoraRelativePath as g,defaultExportExpression as E,findObjectProperty as d,handlerOf as S}from"./listLunoraSourceFiles-DmOftuU4.mjs";import{c as v}from"./classify-procedure-call-VzDQHiLB.mjs";const y="notify.ts",N=new Set(["chat","inApp","send","webhook"]),h=new Set(["broadcast","send"]),F=e=>{const t=e.getInitializer();if(!t||!c.isCallExpression(t))return;const o=v(t);if(!o)return;const s=S(t,o.receiver);return s?{exportName:e.getName(),handler:s,kind:o.kind}:void 0},m=e=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const s of o.getDeclarations()){const r=F(s);r&&t.push(r)}return t},a=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=e.getExpression();if((t==="notify"||t==="push")&&c.isIdentifier(o)&&o.getText()==="ctx")return t;if(t==="push"&&a(o)==="notify")return"push"},A=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=a(e.getExpression());if(o==="notify"&&N.has(t))return`ctx.notify.${t}`;if(o==="push"&&h.has(t))return`ctx.push.${t}`},O=e=>c.isPropertyAccessExpression(e)?a(e.getExpression())==="push"&&h.has(e.getName()):!1,_=(e,t)=>{const o=[];for(const s of p(t)){const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),f=g(t,s);for(const n of m(r))if(!(n.kind!=="query"&&n.kind!=="mutation"))for(const i of n.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const u=A(i);u!==void 0&&o.push({callee:u,exportName:n.exportName,file:f,kind:n.kind,line:i.getStartLineNumber()})}}return o},b=(e,t)=>{for(const o of p(t)){const s=e.getSourceFile(o)??e.addSourceFileAtPath(o);for(const r of m(s))for(const f of r.handler.getDescendantsOfKind(l.PropertyAccessExpression))if(O(f))return!0}return!1},w=(e,t)=>{const o=P(t,y);if(!x(o))return;const s=e.getSourceFile(o)??e.addSourceFileAtPath(o),r=E(s);let f=!1,n=!1;if(r&&c.isCallExpression(r)){const i=r.getArguments()[0];i&&c.isObjectLiteralExpression(i)&&(f=d(i,"webPush")!==void 0,n=d(i,"fcm")!==void 0)}return{hasFcm:n,hasWebPush:f,usesPush:b(e,t)}};export{y as NOTIFY_FILENAME,_ as discoverNotifyCalls,w as discoverNotifyConfig};
@@ -1 +0,0 @@
1
- import{existsSync as b}from"node:fs";import{join as h}from"node:path";import{LunoraError as l}from"@lunora/errors";import{queueDefaultName as y,queueBindingName as q}from"@lunora/queue";import{SyntaxKind as w,Node as c}from"ts-morph";import{diagnosticAt as d}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{findObjectProperty as m,stringPropertyFor as N}from"./listLunoraSourceFiles-DmOftuU4.mjs";import{r as x}from"./handler-reference-BjE6kvyl.mjs";const v="queues.ts",E=o=>{const t=e=>e==="defineQueue"||e==="defineSubscription"||e==="defineTopic",i=o.getSymbol();if(!i){const e=o.getText();return t(e)?e:void 0}for(const e of i.getDeclarations()){if(!c.isImportSpecifier(e))continue;if(e.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/queue")return;const r=e.getNameNode().getText();return t(r)?r:void 0}},f=N("queue"),S=(o,t,i)=>{if(c.isNumericLiteral(o))return o.getLiteralValue();throw d(o,`queue "${t}": \`${i}\` must be a static numeric literal — it is deploy configuration codegen writes into wrangler.jsonc`)},$=(o,t)=>{const i=m(o,"name");if(!i||!c.isPropertyAssignment(i))return;const e=f(i.getInitializerOrThrow(),t,"name");if(e.length===0)throw d(i,`queue "${t}": \`name\` must be a non-empty string when provided`);return e},g=(o,t,i,e)=>{const r=x(m(o,"handler"),e)?.site,s={bindingName:q(t),exportName:t,mode:"push",name:$(o,t)??y(t),...i===void 0?{}:{topic:i},...r===void 0?{}:{handlerSite:r},tuning:{}},n=m(o,"mode");if(n&&c.isPropertyAssignment(n)){if(i!==void 0)throw d(n,`subscription "${t}": \`mode\` is not allowed — a subscription is always a push consumer`);const u=f(n.getInitializerOrThrow(),t,"mode");if(u!=="push"&&u!=="pull")throw d(n,`queue "${t}": \`mode\` must be "push" or "pull" (got ${JSON.stringify(u)})`);s.mode=u}const a=m(o,"deadLetterQueue");a&&c.isPropertyAssignment(a)&&(s.tuning.deadLetterQueue=f(a.getInitializerOrThrow(),t,"deadLetterQueue"));for(const u of["maxBatchSize","maxBatchTimeout","maxRetries","retryDelay"]){const p=m(o,u);p&&c.isPropertyAssignment(p)&&(s.tuning[u]=S(p.getInitializerOrThrow(),t,u))}return s},I=(o,t,i)=>{const e=o.getArguments()[0];if(!e||!c.isObjectLiteralExpression(e))throw d(o,`queue "${t}": defineQueue must be passed an inline object literal`);return g(e,t,void 0,i)},P=(o,t,i,e)=>{const[r,s]=o.getArguments();if(!r||!c.isIdentifier(r)||!i.has(r.getText()))throw d(r??o,`subscription "${t}": the first argument must name a \`defineTopic()\` export of lunora/queues.ts`);if(!s||!c.isObjectLiteralExpression(s))throw d(o,`subscription "${t}": defineSubscription must be passed an inline object literal`);return g(s,t,r.getText(),e)},T=o=>{const t=[];for(const i of o.getVariableDeclarations()){if(!i.isExported())continue;const e=i.getInitializer();if(e?.getKind()!==w.CallExpression)continue;const r=e,s=r.getExpression(),n=c.isIdentifier(s)?E(s):void 0;if(n===void 0)continue;const a=i.getNameNode();if(!c.isIdentifier(a))throw d(a,`${n} exports must be plain named exports (no destructuring)`);t.push({call:r,exportName:a.getText(),factory:n})}return t},A=(o,t)=>{const i=T(o),e=new Set(i.filter(n=>n.factory==="defineTopic").map(n=>n.exportName)),r=[];for(const n of i)n.factory==="defineQueue"?r.push(I(n.call,n.exportName,t)):n.factory==="defineSubscription"&&r.push(P(n.call,n.exportName,e,t));const s=[...e].map(n=>({exportName:n}));return{queues:r,topics:s}},Q=o=>{const t=new Map,i=new Map;for(const e of o){const r=t.get(e.name);if(r!==void 0)throw new l("DUPLICATE_QUEUE_NAME",`Duplicate queue name "${e.name}": produced by both "${r}" and "${e.exportName}". Deployed queue names must be unique across the project.`,{status:500});t.set(e.name,e.exportName);const s=i.get(e.bindingName);if(s!==void 0)throw new l("DUPLICATE_QUEUE_BINDING",`Duplicate queue binding "${e.bindingName}": produced by both "${s}" and "${e.exportName}". Queue export names must yield unique binding names.`,{status:500});i.set(e.bindingName,e.exportName)}},L=(o,t)=>{const i=h(t,v);if(!b(i))return{queues:[],topics:[]};const e=o.getSourceFile(i)??o.addSourceFileAtPath(i),{queues:r,topics:s}=A(e,t),n=r.toSorted((a,u)=>a.exportName.localeCompare(u.exportName));return Q(n),{queues:n,topics:s.toSorted((a,u)=>a.exportName.localeCompare(u.exportName))}},M=(o,t)=>L(o,t).queues;export{v as QUEUES_FILENAME,L as discoverQueueDeclarations,M as discoverQueues};
@@ -1,11 +0,0 @@
1
- import{existsSync as T,mkdirSync as bn,readFileSync as As,writeFileSync as Nn,rmSync as Pn}from"node:fs";import{join as S,dirname as Se}from"node:path";import{performance as Be}from"node:perf_hooks";import{runAdvisor as wn}from"@lunora/advisor";import{LunoraError as j}from"@lunora/errors";import{SyntaxKind as d,Node as i,Project as Kt}from"ts-morph";import{serializeSchemaSnapshot as In}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{toAdvisorContext as Tn}from"./formatAdvisories-DwmUKYuc.mjs";import{readProjectConfigLiterals as Cn}from"./loadProjectConfig-CWtWqN3X.mjs";import{a as zt,d as On,r as Rn}from"./modules-Dcalu27_.mjs";import{QUEUES_FILENAME as Fn,discoverQueueDeclarations as kn}from"./QUEUES_FILENAME-BUC4MU94.mjs";import{WORKFLOWS_FILENAME as Ln,discoverWorkflows as Dn}from"./WORKFLOWS_FILENAME-BIjSK96U.mjs";import{r as Mn}from"./json-data-Chfs2Cz5.mjs";import{s as Ie}from"./paths-C-9fwEgQ.mjs";import{G as _n}from"./shared-DjUziztz.mjs";import{CAPABILITIES as Kn,usedCapabilities as zn}from"./CAPABILITY_PROBES-DFsutD7g.mjs";import{isD1GlobalTable as bs,isHyperdriveGlobalTable as Ns}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as $n}from"./AGENTS_FILENAME-pKCBP6Us.mjs";import{discoverContainers as Bn}from"./CONTAINERS_FILENAME-C0nEQjXL.mjs";import Un from"./discoverCrons-D2jGNq6i.mjs";import{diagnosticAt as de}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as Te}from"./module-specifiers-WF8iAydP.mjs";import{contextPropertiesRead as Vn,discoverFeatureUsage as jn}from"./capabilitiesUsedBy-D5TtIE8p.mjs";import qn from"./readPackageDependencies-C6h6FZuP.mjs";import{listLunoraSourceFiles as E,propertyKeyName as y,unwrapExpression as v,listSecurityScanFiles as Ce,objectLiteralFromCallbackBody as Ps,propertyInitializer as N,lunoraRelativePath as P,bindingKeyName as ue,collectCallRows as w,findObjectProperty as F,collectSecurityCallRows as Wn,collectNodeRows as Xe,RUN_METHODS as ws,functionReferenceSegments as Is,limitNameOf as Ts,optionsObjectLiteral as Cs,isContextIdentifier as Je,handlerOf as Hn,isDatabaseAccessor as M,isConstDeclaration as ie,isWriteTarget as ae,outermostValueWrapper as z,readTargetOf as Os}from"./listLunoraSourceFiles-DmOftuU4.mjs";import{discoverSandboxUsage as Gn}from"./discoverSandboxUsage-DhE6sfq2.mjs";import{resolveServiceBindings as Yn}from"./readServiceBindings-V1rcBYrK.mjs";import Qn from"./discoverStorageRulesMetadata-BdZT9H9j.mjs";import{a as A,c as q,d as Rs,e as Xn}from"./classify-procedure-call-VzDQHiLB.mjs";import{i as Jn}from"./ir-DBSvhNa-.mjs";import{gatePlatformFeatures as Zn,resolveCodegenTarget as Fs,readTargetDiagnostics as er,studioPlatformFor as tr}from"./DEFAULT_TARGET-Dy9KAvjZ.mjs";import{b as ks,e as sr}from"./shard-B2AqdAuz.mjs";import nr from"./emitServer-mdlKhXYb.mjs";import{emitDataModel as rr}from"./emitDataModel-D3WuEZ4b.mjs";import{c as h,w as it,d as D}from"./attribution-CTEeAmtS.mjs";import{r as Oe,s as ir}from"./parse-validator-Cs6F8SYG.mjs";import or from"./discoverAuthApiCalls-D6s0QBwd.mjs";import{i as ar,a as cr,e as lr,b as dr,d as ur,c as fr}from"./unwrap-handler-return-Bnx99voQ.mjs";import pr from"./discoverFunctions-AcXUQuyo.mjs";import gr from"./discoverHttpRoutes-C7qeDpp3.mjs";import mr from"./discoverHyperdriveCalls-CeyhQdv3.mjs";import hr from"./discoverInserts-Db4we2Lt.mjs";import{m as ot,a as be,s as Ls,d as vr}from"./index-Bq-b_-7H.mjs";import{e as Ds}from"./exported-procedure-chains-gbM1pign.mjs";import Er from"./discoverMigrations-CyySAw7Z.mjs";import{MUTATORS_FILENAME as xr,isDefineMutatorCallee as Sr,mutatorServerImplOf as yr,discoverMutators as Ar}from"./MUTATORS_FILENAME-Cm-LVbo0.mjs";import br from"./discoverNondeterministicCalls-Bl_vaQUi.mjs";import{discoverNotifyConfig as Nr,discoverNotifyCalls as Pr}from"./NOTIFY_FILENAME-BRewD55T.mjs";import wr from"./discoverQueries-DHtbg9iS.mjs";import Ir from"./discoverR2sqlCalls-BNKRNkrB.mjs";import Tr from"./discoverRlsProcedures-zDOYuzjt.mjs";import Cr from"./discoverRlsMetadata-CVqVMNnz.mjs";import Or from"./discoverSchema-DPghAnQv.mjs";import{secretKindOf as Rr,redact as Fr,isHeuristicSecretKind as kr,isSecretishName as Lr}from"./redact-Cy14LEnc.mjs";import{discoverShapes as Dr}from"./SHAPES_FILENAME-BMT5EVQI.mjs";import{emitApp as Mr}from"./emitApp-0rC4g46B.mjs";import{buildOpenApiDocument as _r,emitOpenApiModule as Kr}from"./buildOpenApiDocument-BG_b1qiR.mjs";import{buildOpenRpcDocument as zr,emitOpenRpcModule as $r}from"./OPENRPC_VERSION-C8htLv5J.mjs";import{buildSchemaSnapshot as Br}from"./SchemaSnapshotParseError-CPOXlFhI.mjs";import{emitCollections as Ur,emitSeed as Vr,emitApi as jr}from"./emitApi-DdW9RyGG.mjs";import{t as qr,u as Wr,s as Hr,v as Gr}from"./shard-runtime-B8rucwkF.mjs";import{emitCrons as Yr,emitScheduler as Qr,emitShardRegistry as Xr,emitVectors as Jr,emitWranglerCronTriggers as Zr}from"./emitCrons-BRKXFGFu.mjs";import ei from"./emitDrizzleSchema-Cv0HtLR3.mjs";import ti from"./emitFunctions-BgNeOZt_.mjs";const $t={error:"ERROR",info:"INFO",warn:"WARN"},Bt={ERROR:2,INFO:0,WARN:1},si=e=>({cacheKey:"advisor_min_severity_invalid",categories:["SCHEMA"],description:"`advisor.minSeverity` in `lunora.config.*` sets the lowest advisory level codegen reports and writes into `_generated/shard.ts`. Codegen reads it by parsing the file, so it has to be a string literal.",detail:e,facing:"INTERNAL",level:"WARN",metadata:{},name:"advisor_min_severity_invalid",remediation:'Set `advisor: { minSeverity: "info" | "warn" | "error" }` as a literal on the config\'s default export.',title:"`advisor.minSeverity` is not a level codegen can read, so every advisory was reported"}),ni=(e,t)=>{const{advisor:s}=Cn(e);if(s===void 0||s.minSeverity===void 0&&s.unreadable!==!0)return[...t];const{minSeverity:n}=s,r=n!==void 0&&Object.hasOwn($t,n)?$t[n]:void 0;return r===void 0?[...t,si(n===void 0?"`advisor.minSeverity` is not a string literal codegen can read without evaluating the config: a computed value or key, or a spread that could set or override it.":`\`advisor.minSeverity\` is "${n}", which is not one of "info", "warn" or "error".`)]:t.filter(o=>Bt[o.level]>=Bt[r])},ri={call:"function",enqueue:"queue",invoke:"service",publish:"topic",schedule:"function"},Ms=Fn.replace(/\.ts$/u,""),ii="crons",oi=Ln.replace(/\.ts$/u,""),te=(e,t)=>`${Ie(e)}:${t}`,Ue=(e,t,s)=>t===""?{reason:`the ${s} is not a string literal`}:{to:`${e}:${t}`},ai=e=>[...e.callEdges.map(t=>{const s=t.target===void 0?{reason:t.reason??"unreadable target"}:{to:`${ri[t.kind]}:${t.target}`};return{file:t.file,kind:t.kind,line:t.line,scope:t.scope,...s}}),...e.queries.map(t=>({file:t.file,kind:"read",line:t.line,scope:t.scope,...Ue("table",t.table,"table name")})),...[...e.inserts,...e.tableWrites].map(t=>({file:t.file,kind:"write",line:t.line,scope:t.scope,...Ue("table",t.table,"written table")})),...e.workflowCalls.map(t=>({file:t.file,kind:"start",line:t.line,scope:t.scope,...Ue("workflow",t.workflow,"workflow name")}))],ci=e=>e.untracked===!0?"inside a helper only code outside any export calls":"inside a non-exported helper",li=e=>{const{scope:t}=e;switch(t.kind){case"export":return[{...e,exportName:t.name}];case"helper":return t.callers.length===0?[{...e,unattributed:ci(t)}]:t.callers.map(s=>({...e,exportName:s}));default:return[{...e,unattributed:"at module scope"}]}},di=e=>ai(e).flatMap(t=>li(t)),ui=e=>[...e.queues.flatMap(t=>t.topic===void 0?[]:[{file:Ms,from:`topic:${t.topic}`,kind:"subscribe",line:0,to:`queue:${t.exportName}`}]),...e.crons.map(t=>{const s=t.workflow===void 0?void 0:`workflow:${t.workflow.exportName}`,n=t.functionPath===void 0?void 0:`function:${t.functionPath}`,r=s??n;return{file:ii,from:`cron:${t.name}`,kind:"trigger",line:0,...r===void 0?{reason:"the cron has no target"}:{to:r}}})],fi=e=>new Map(e.flatMap(t=>t.tables.map(s=>[s,t.name]))),Ve=(e,t)=>t===void 0?e:{...e,module:t},pi=e=>{const t=new Map,s=new Map,n=fi(e.modules),r=(c,l)=>{s.set(c,[...s.get(c)??[],l])},o=(c,l)=>{t.set(c.id,c),l!==void 0&&r(l,c.id)},a=(c,l)=>{c!==void 0&&r(te(c.file,c.exportName),l)};for(const c of e.functions){const l=te(c.filePath,c.exportName),u=`${Ie(c.filePath)}.${c.exportName}`;o(Ve({detail:c.kind,id:`function:${l}`,kind:"function",name:u},zt(e.modules,c.filePath)),l)}for(const c of e.httpRoutes){const l=te(c.filePath,c.exportName);o(Ve({id:`http:${l}`,kind:"http",name:`${c.method} ${c.path}`},zt(e.modules,c.filePath)),l)}for(const c of e.schema.tables)o(Ve({id:`table:${c.name}`,kind:"table",name:c.name},n.get(c.name)));for(const c of e.queues){const l=c.topic===void 0?{}:{detail:"subscription"};o({...l,id:`queue:${c.exportName}`,kind:"queue",name:c.exportName},te(Ms,c.exportName)),a(c.handlerSite,`queue:${c.exportName}`)}for(const c of e.topics)o({id:`topic:${c.exportName}`,kind:"topic",name:c.exportName});for(const c of e.workflows)o({id:`workflow:${c.exportName}`,kind:"workflow",name:c.exportName},te(oi,c.exportName)),a(c.handlerSite,`workflow:${c.exportName}`);for(const c of e.crons)o({detail:c.cron,id:`cron:${c.name}`,kind:"cron",name:c.name});for(const c of e.services){const l=c.rpcEntrypoint===void 0?"fetch":"rpc";o({detail:c.entrypoint===void 0?l:`${l} · ${c.entrypoint}`,id:`service:${c.name}`,kind:"service",name:c.worker})}return{nodes:t,sites:s}},gi=e=>e==="default"?"the default export is not a registered function":`"${e}" is not a registered function`,mi=(e,t)=>"from"in e?[e.from]:"unattributed"in e?{reason:e.unattributed}:t.get(te(e.file,e.exportName))??{reason:gi(e.exportName)},hi=(e,t,s)=>{if("reason"in e)return{reason:e.reason};const n=mi(e,t);if("reason"in n)return n;const{to:r}=e;return s.has(r)?{drawn:n.map(o=>({from:o,kind:e.kind,to:r}))}:{reason:`${r} is not declared`}},je=e=>`${e.from}|${e.kind}|${e.to}`,vi=e=>`${e.file}|${String(e.line)}|${e.kind}|${e.reason}`,Ei=e=>{const{nodes:t,sites:s}=pi(e),n=new Map,r=new Map;for(const o of[...ui(e),...di(e)]){const a=hi(o,s,t);if("drawn"in a)for(const c of a.drawn)n.set(je(c),c);else{const c={file:o.file,kind:o.kind,line:o.line,reason:a.reason};r.set(vi(c),c)}}return{edges:[...n.values()].toSorted((o,a)=>je(o).localeCompare(je(a))),nodes:[...t.values()].toSorted((o,a)=>o.id.localeCompare(a.id)),modules:e.modules.map(o=>({...o.description===void 0?{}:{description:o.description},...o.installed===!0?{installed:!0}:{},...o.ownsFolder===!1?{ownsFolder:!1}:{},name:o.name,tables:[...o.tables]})),unresolved:[...r.values()].toSorted((o,a)=>o.file.localeCompare(a.file)||o.line-a.line),version:1}},xi=e=>`${_n}export const architecture = ${Mn(e,"Record<string, unknown>")};
2
- `,Si=(e,t)=>{if(!(!t||e.jurisdiction!=="fedramp"))throw new j("CODEGEN_DIAGNOSTIC",'@lunora/codegen: the schema pins data to the "fedramp" jurisdiction, but this app uses Cloudflare Artifacts (`ctx.artifacts`), which supports only the "eu" and "us" jurisdictions. Repo data would be stored outside the declared residency. Remove the `ctx.artifacts` usage, or pin the schema to a jurisdiction Artifacts supports.')},Ut=(e,t="api")=>{const s=new Map;for(const n of e){const r=Ie(n),o=s.get(r);if(o===void 0){s.set(r,n);continue}if(o!==n){const a=t==="api"?`the generated api.ts would declare "${r}" twice and the dispatch key "${r}:<fn>" would be ambiguous`:`the generated api.ts would declare "${r}" twice in HttpStreamsRef and again in the httpStreams object literal`;throw new j("INTERNAL",`@lunora/codegen: "${o}" and "${n}" both map to the ${t} namespace "${r}" — ${a}. Rename one file so the two differ by more than a non-identifier character (\`-\`, \`.\`, \`/\` and \`_\` all sanitize to \`_\`).`,{status:500})}}},yi=(e,t={})=>{const{hasVectors:s=!0,scheduler:n=!1,storage:r=!1,usage:o}=t,a=[];e.tables.some(c=>bs(c))&&a.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),e.tables.some(c=>Ns(c))&&a.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'},{name:"@lunora/sql-store",reason:'`.global({ backend: "hyperdrive" })` makes `_generated/app.ts` import the `SqlCtxDbOptions` / `SqlExec` types'}),n&&a.push({name:"@lunora/scheduler",reason:"a declared cron (or `ctx.scheduler` use) makes `_generated/app.ts` import `createScheduler`"}),r&&a.push({name:"@lunora/storage",reason:"a `v.storage()` column, a storage access rule (or `ctx.storage` use) makes `_generated/app.ts` import `createStorage`"}),e.vectorIndexes.length>0&&s&&a.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/shard.ts` import `@lunora/bindings/vectors`"});for(const c of o===void 0?[]:Kn)c.requiredPackage!==void 0&&o?.[c.key]===!0&&a.push({name:c.requiredPackage,reason:`\`ctx.${c.contextProperty??c.key}\` usage makes \`_generated/\` import \`${c.moduleSpecifier}\``});return a.filter((c,l)=>a.findIndex(u=>u.name===c.name)===l)},Ai=(e,t,s={})=>{if(t===void 0)return;const n=yi(e,s).filter(o=>!t.has(o.name));if(n.length===0)return;const r=n.map(o=>` - ${o.name} — ${o.reason}`).join(`
3
- `);throw new j("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
4
- ${r}
5
-
6
- Install them with your package manager, then re-run codegen.`)},bi="env.ts",Ni=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return Te(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},Pi=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(d.ImportDeclaration);return n!==void 0&&Te(n.getModuleSpecifierValue())}return!1},wi=e=>{if(i.isIdentifier(e))return Ni(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&Pi(t)}return!1},Ii=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!wi(n.getExpression()))continue;const o=s.getNameNode();if(!i.isIdentifier(o))throw de(o,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:o.getText()})}return t},Ti=(e,t)=>{const s=S(t,bi);if(!T(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),r=Ii(n);if(r.length!==0){if(r.length>1)throw de(n,`lunora/env.ts declares ${r.length.toString()} defineEnv() contracts (${r.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return r[0]}},_s="identity.ts",Ci=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return Te(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Oi=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(d.ImportDeclaration);return n!==void 0&&Te(n.getModuleSpecifierValue())}return!1},Ri=e=>{if(i.isIdentifier(e))return Ci(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&Oi(t)}return!1},Fi=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==d.CallExpression||!Ri(n.getExpression()))continue;const o=s.getNameNode();if(!i.isIdentifier(o))throw de(o,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:o.getText()})}return t},ki=(e,t)=>{const s=S(t,_s);if(!T(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),r=Fi(n);if(r.length!==0){if(r.length>1)throw de(n,`lunora/identity.ts declares ${r.length.toString()} defineIdentity() contracts (${r.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return r[0]}},Li=new Set(["allowedHosts","deniedHosts","interceptHttps"]),Di=(e,t)=>{const s=v(t);if(s===void 0||!i.isIdentifier(s))return s;const n=s.getText();return v(e.getDescendantsOfKind(d.VariableDeclaration).find(r=>r.getName()===n)?.getInitializer())},Mi=(e,t)=>e!==void 0&&i.isObjectLiteralExpression(e)&&e.getProperties().some(s=>{if(i.isShorthandPropertyAssignment(s))return t.has(y(s));if(!i.isPropertyAssignment(s)||!t.has(y(s)))return!1;const n=v(s.getInitializer())?.getText();return n!=="false"&&n!=="undefined"}),_i=new Set(["durable"]),Ki=new Set(["rollback"]),zi=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)?t.getName():t.getText()},$i=new Map([["defineContainer",{keys:Li,signal:"containerEgressPolicy"}],["defineStep",{keys:Ki,signal:"workflowRollback"}],["stream",{keys:_i,signal:"durableStreams"}]]),Bi=(e,t)=>{const s=$i.get(zi(t));if(s!==void 0)return t.getArguments().some(n=>Mi(Di(e,n),s.keys))?s.signal:void 0},Ui=(e,t)=>{const s={containerEgressPolicy:!1,durableStreams:!1,secrets:!1,workflowRollback:!1};for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.secrets||(s.secrets=Vn(r).has("secrets"));for(const o of r.getDescendantsOfKind(d.CallExpression)){const a=Bi(r,o);a!==void 0&&(s[a]=!0)}if(Object.values(s).every(Boolean))break}return s},Vi="createWorker",ji="extend",Vt=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralValue():void 0,jt=e=>{const t=[],s=Vt(N(e,"backupCron"));s!==void 0&&t.push(s);const n=N(e,"crons");if(n===void 0||!i.isObjectLiteralExpression(n))return t;for(const r of n.getProperties()){if(!i.isPropertyAssignment(r)&&!i.isMethodDeclaration(r))continue;const o=Vt(r.getNameNode());o!==void 0&&t.push(o)}return t},qi=e=>{const t=A(e.getExpression()),[s]=e.getArguments();if(s===void 0)return[];if(t===Vi)return i.isObjectLiteralExpression(s)?jt(s):[];if(t!==ji||!(i.isArrowFunction(s)||i.isFunctionExpression(s)))return[];const n=Ps(s.getBody());return n===void 0?[]:jt(n)},Wi=(e,t)=>{const s=[];for(const{filePath:n}of Ce(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of r.getDescendantsOfKind(d.CallExpression))s.push(...qi(o))}return[...new Set(s)]},Ks=e=>{if(e.kind==="id")return e.tableName;if(!(e.kind!=="array"&&e.kind!=="optional"))return e.inner===void 0?void 0:Ks(e.inner)},Hi=e=>{const t=new Set(e.tables.map(s=>s.name));return e.tables.some(s=>Object.values(s.shape).some(n=>{const r=Ks(n);return r!==void 0&&t.has(r)}))},Gi=(e,t)=>{const s=new Map,n=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const o=s.get(r.name);if(o!==void 0)throw new j("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${o} and agent "${r.exportName}". Workflow and agent names share one account-wide namespace and must be unique together.`,{status:500});const a=n.get(r.className);if(a!==void 0)throw new j("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${a} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},Yi=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:r}=e,o=ki(s,t),a=Ti(s,t),c=Dn(s,t),{queues:l,topics:u}=kn(s,t),g=Yn(n),f=$n(s,t);Gi(c,f);const m=Bn(s,t),x=Qn(s,t),_=Un(s,t,c,f),K=Wi(s,t),b=Ui(s,t),O=Gn(s,t),U=jn(s,t);U.browser=U.browser||O.usesSandboxBrowser;const W=Zn(U,Fs(n,e.target),{agents:f.length>0,commitOrderedTables:r.tables.some(C=>C.commitOrdered===!0),cronTriggers:_.length>0,crossShardFanout:r.tables.some(C=>Jn(C)),containerEgressPolicy:b.containerEgressPolicy,containerRuntimeScheduling:m.some(C=>C.schedulingPolicy==="durable_object"),containerSandboxTools:m.some(C=>C.sandbox===!0),durableStreams:b.durableStreams,globalTables:r.tables.some(C=>C.shardMode==="global"),queues:l.length>0,relationGraph:Hi(r),secrets:b.secrets,services:g.length>0,topics:u.length>0,vectorStore:r.vectorIndexes.length>0,workerLoaders:O.usesSandboxLoader,workflowRollback:b.workflowRollback,workflowSchedules:c.some(C=>C.schedules!==void 0)}),R=W.usage,X=zn(R),se=W.signals.vectorStore!==!1,ne=W.signals.services===!1?[]:g,J=qn(n),fe=J??new Set,V=fe.has("lunorash");Ai(r,J,{hasVectors:se,scheduler:R.scheduler||_.length>0,storage:R.storage||x.rules.length>0||Object.keys(ks(r)).length>0,usage:R});const k=T(S(t,"flags.ts")),L=T(S(t,"notify.ts"));return{agents:f,capabilities:X,containers:m,crons:_,dataModelContent:rr(r),declaredDependencies:J,dependencies:fe,entryCronTriggers:K,env:a,featureUsage:R,hasFlags:k,hasNotify:L,identity:o,platformGate:{...W,diagnostics:[...er(n,e.target),...W.diagnostics]},queues:l,serverContent:nr({agents:f,capabilities:X,containers:m,env:a,hasVectors:se,hasFlags:k,hasNotify:L,identity:o,queues:l,schema:r,generatedDirectory:S(t,"_generated"),services:ne,storageRuleBuckets:x.rules.map(C=>C.bucket),topics:u,useUmbrella:V,workflows:c}),services:ne,storageRulesMetadata:x,topics:u,usesSandbox:O.usesSandboxBrowser||O.usesSandboxContainer||O.usesSandboxFs,useUmbrella:V,workflows:c}},zs=new Set(["delete","get","head","options","patch","post","put"]),Qi=new Set(["handler","stream"]),Xi=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,qt=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Ji=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!zs.has(t.getName()))return;const s=t.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!i.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},Zi=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||zs.has(n.getName()))break;s=n.getExpression()}return Ji(s)},eo=e=>{for(const t of e.getDescendantsOfKind(d.PropertyAccessExpression))if(qt.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&qt.has(s.getText()))return!0}return!1},to=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||!Qi.has(n.getName()))return;const r=Zi(s);if(!r||!Xi.test(r.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&eo(o);return{exportName:e.getName(),file:t,method:r.method,path:r.path,usesGuard:a}},so=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const r of n.getDeclarations()){const o=to(r,t);o&&s.push(o)}return s},no=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...so(r,P(t,n)))}return s},ro=e=>{const t=e.getText(),s=n=>{const r=n.getNameNode();return i.isIdentifier(r)&&r.getText()===t};for(const n of e.getAncestors())if(!(!i.isArrowFunction(n)&&!i.isFunctionExpression(n)&&!i.isFunctionDeclaration(n)))for(const r of n.getParameters()){const o=r.getDescendantsOfKind(d.BindingElement).find(a=>s(a));if(o!==void 0)return o}},io=e=>{let t=e;for(;;){const s=t.getParent();if(!i.isObjectBindingPattern(s))return;const n=s.getParent();if(i.isBindingElement(n)){t=n;continue}return i.isParameterDeclaration(n)?ue(t):void 0}},Wt=(e,t)=>{const s=e.getParent();if(i.isPropertyAccessExpression(s)&&s.getNameNode()===e||i.isPropertyAssignment(s)&&s.getNameNode()===e)return!1;if(e.getText()===t)return!0;const n=ro(e);return n!==void 0&&io(n)===t},at=(e,t)=>i.isIdentifier(e)?Wt(e,t):e.getDescendantsOfKind(d.Identifier).some(s=>Wt(s,t)),qe=e=>at(e,"ctx"),oo=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t:void 0},Ze=e=>at(e,"args"),$=e=>{if(!i.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a));if(s===void 0)return;const n=e.getStart();let r,o=-1;for(const a of s.getDescendantsOfKind(d.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<n&&l>o&&(r=c,o=l)}return r},B=e=>{if(Ze(e))return!0;const t=$(e);return t!==void 0&&Ze(t)},ao=e=>{if(i.isCallExpression(e)||i.isNewExpression(e))return!1;const t=$(e);return t===void 0||!(i.isCallExpression(t)||i.isNewExpression(t))},G=e=>{if(qe(e))return!0;const t=$(e);if(t!==void 0&&qe(t))return!0;const s=t??e;return(i.isIdentifier(s)?[s]:s.getDescendantsOfKind(d.Identifier)).some(r=>{const o=$(r);return o!==void 0&&qe(o)})},ye=(e,t)=>at(e,t),co=(e,t)=>{if(ye(e,t))return!0;const s=$(e);if(s!==void 0&&ye(s,t))return!0;const n=oo(e);if(n!==void 0){const r=$(n);return r!==void 0&&ye(r,t)}return!1},lo=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",uo=(e,t)=>{if(!lo(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!B(s)||G(s)))return{scope:h(e),file:t,line:e.getStartLineNumber()}},fo=(e,t)=>w(e,t,uo),po=new Set(["generateText","streamText"]),go=new Set(["messages","prompt","system"]),mo=[{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"]}],ho=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const r of mo)if(r.methods.has(s)&&r.prefixes.some(o=>n===o||n.startsWith(`${o}.`)))return`${n}.${s}`},vo=e=>{for(const t of e.getDescendantsOfKind(d.CallExpression)){const s=ho(t);if(s!==void 0)return s}},Eo=e=>{const t=new Set,s=e.getFirstAncestor(o=>i.isArrowFunction(o)||i.isFunctionExpression(o)||i.isFunctionDeclaration(o)),[n]=s?.getParameters()??[],r=n?.getNameNode();if(r===void 0||!i.isObjectBindingPattern(r))return t;for(const o of r.getElements()){const a=ue(o),c=o.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},xo=e=>{if(Ze(e))return!0;const t=Eo(e);return t.size===0?!1:e.getDescendantsOfKind(d.Identifier).some(s=>t.has(s.getText()))},So=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!go.has(y(t)))continue;const s=t.getInitializer();if(s!==void 0&&xo(s))return!0}return!1},yo=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=A(n.getExpression());if(r===void 0||!po.has(r))continue;const[o]=n.getArguments();if(o===void 0||!i.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(d.CallExpression))if(A(c.getExpression())==="tool"&&(a=vo(c),a!==void 0))break;a!==void 0&&s.push({scope:h(n),file:t,line:n.getStartLineNumber(),method:r,sideEffect:a,userInputDerived:So(o)})}return s},Ao=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...yo(r,P(t,n)))}return s},bo=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},No=(e,t)=>{if(!bo(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!B(s)))return{scope:h(e),file:t,line:e.getStartLineNumber()}},Po=(e,t)=>w(e,t,No),ct=(e,t=new Set)=>{if(t.has(e))return!0;t.add(e);try{return e.getProperties().some(s=>{if(!i.isSpreadAssignment(s))return!1;const n=Oe(s.getExpression());return n===void 0||ct(n,t)})}finally{t.delete(e)}},wo=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=F(t,"args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer(),r=n===void 0?void 0:Oe(n);return r===void 0?{objects:[],opaque:!0}:{objects:[r],opaque:ct(r)}},Io=e=>{const t=[];let s=!1,n=e;for(;i.isCallExpression(n);){const r=n.getExpression();if(!i.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const o=n.getArguments()[0],a=o!==void 0&&i.isExpression(o)?Oe(o):void 0;a===void 0?s=!0:(t.push(a),s||=ct(a))}n=r.getExpression()}return{objects:t,opaque:s}},lt=(e,t)=>t?Io(t):wo(e),$s=(e,t)=>{if(t.has(e))return[];t.add(e);try{return e.getProperties().flatMap(s=>{if(i.isSpreadAssignment(s)){const n=Oe(s.getExpression());return n===void 0?[]:$s(n,t)}return i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)?[y(s)]:[]})}finally{t.delete(e)}},To=e=>e.flatMap(t=>$s(t,new Set)),Co=new Set(["check","length","max"]),et=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!(!i.isPropertyAccessExpression(t)||t.getExpression().getText()!=="v"))return t.getName()},Oo=e=>[e,...e.getDescendants()].filter(t=>et(t)!==void 0),Ro=e=>{let t=e;for(;;){const s=t.getParent();if(!s||!i.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;const n=s.getParent();if(!n||!i.isCallExpression(n)||n.getExpression()!==s)return!1;if(Co.has(s.getName()))return!0;t=n}},Fo=e=>{const t=[],s=[];for(const n of e)for(const r of n.getProperties()){if(!i.isPropertyAssignment(r))continue;const o=r.getInitializer();if(!o)continue;const a=Oo(o),c=y(r);a.some(l=>et(l)==="any")?t.push(c):a.some(l=>et(l)==="string"&&!Ro(l))&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},ko=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=q(s);if(n?.visibility!=="public")return;const{objects:r}=lt(s,n.receiver),{anyArgs:o,unboundedStringArgs:a}=Fo(r);if(!(o.length===0&&a.length===0))return{anyArgs:o,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Lo=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const r of n.getDeclarations()){const o=ko(r,t);o&&s.push(o)}return s},Do=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Lo(r,P(t,n)))}return s},We=e=>e?.getKind()===d.TrueKeyword,Mo=e=>e?.getKind()===d.FalseKeyword,_o=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Ko=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),zo=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&A(t.getExpression())==="scim"),$o=e=>e!==void 0&&i.isCallExpression(e)&&Ko.has(A(e.getExpression())??""),Bo=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),Uo=e=>{const t=N(e,"advanced"),s=N(e,"emailAndPassword"),n=N(e,"session");return{analyzable:!0,disableCsrfCheck:We(N(t,"disableCSRFCheck")),emailPasswordEnabled:We(N(s,"enabled")),requireEmailVerification:We(N(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:zo(N(e,"plugins"))&&$o(N(e,"database")),secureCookiesDisabled:Mo(N(t,"useSecureCookies")),sessionFreshAgeZero:_o(N(n,"freshAge")),trustedOriginsWildcard:Bo(N(e,"trustedOrigins"))}},Vo=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),jo=(e,t)=>{if(A(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(o=>i.isSpreadAssignment(o)),r=s!==void 0&&i.isObjectLiteralExpression(s)&&!n?Uo(s):Vo();return{scope:h(e),file:t,line:e.getStartLineNumber(),...r}},qo=(e,t)=>Wn(e,t,jo),Wo=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},Ho=(e,t,s)=>{const n=Wo(e.getExpression(),s);if(n===void 0)return;const r=e.getArguments()[s.argIndex];if(!(!r||!B(r)||G(r))&&!(s.requireUnmodifiedReach===!0&&!ao(r)))return{scope:h(e),file:t,line:e.getStartLineNumber(),method:n}},Re=(e,t,s)=>w(e,t,(n,r)=>Ho(n,r,s)),Go=new Set(["content","pdf","scrape","screenshot"]),Yo=(e,t)=>Re(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Go}),Bs=e=>{const t=Is(e);return t===void 0?void 0:`${Ie(t.slice(0,-1).join("/"))}:${String(t.at(-1))}`},Us=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getExpression();return i.isPropertyAccessExpression(n)&&n.getName()===t?s.getName():void 0},Qo=e=>{if(!i.isPropertyAccessExpression(e))return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="scheduler"||i.isIdentifier(t)&&t.getText()==="scheduler"},Xo=new Map([["publish",{kind:"publish",surface:"topics"}],["publishBatch",{kind:"publish",surface:"topics"}],["send",{kind:"enqueue",surface:"queues"}],["sendBatch",{kind:"enqueue",surface:"queues"}]]),Jo=(e,t)=>{const s=Bs(t);return s!==void 0?{kind:"call",target:s}:e!=="run"&&t!==void 0?{kind:"call",reason:"the function reference is not a static api.* / internal.* chain"}:void 0},Zo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),[n,r]=e.getArguments();if(ws.has(s))return Jo(s,n);if((s==="runAfter"||s==="runAt")&&Qo(t)){const c=Bs(r);return c===void 0?{kind:"schedule",reason:"the scheduled function is not a static api.* / internal.* chain"}:{kind:"schedule",target:c}}const o=Xo.get(s),a=o===void 0?void 0:Us(t,o.surface);return o===void 0||a===void 0?void 0:{kind:o.kind,target:a}},Ht=(e,t,s)=>s===void 0?void 0:{...s,file:t,line:e.getStartLineNumber(),scope:h(e)},ea=(e,t)=>[...w(e,t,(s,n)=>Ht(s,n,Zo(s))),...Xe(e,t,d.PropertyAccessExpression,(s,n)=>{const r=Us(s,"services");return Ht(s,n,r===void 0?void 0:{kind:"invoke",target:r})})],ta=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),sa=new Set(["RateLimiter"]),na=new Set(["extend"]),Gt="lunora",ra=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],Vs=e=>{const t=[],s=[];let n=!1;for(const r of e.getProperties()){if(i.isSpreadAssignment(r)){n=!0;continue}if(i.isPropertyAssignment(r)){const o=y(r);t.push(o),r.getInitializer()?.getKind()===d.TrueKeyword&&s.push(o);continue}(i.isShorthandPropertyAssignment(r)||i.isMethodDeclaration(r))&&t.push(y(r))}return{analyzable:!n,presentKeys:t,trueKeys:s}},tt=e=>e&&i.isObjectLiteralExpression(e)?Vs(e):{analyzable:!1,presentKeys:[],trueKeys:[]},ia=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&Ps(t.getBody());return s?Vs(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},oa=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=A(n.getExpression());r!==void 0&&(ta.has(r)?s.push({callee:r,file:t,line:n.getStartLineNumber(),...tt(n.getArguments()[0])}):na.has(r)&&s.push({callee:r,file:t,line:n.getStartLineNumber(),...ia(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(d.NewExpression)){const r=A(n.getExpression());r===void 0||!sa.has(r)||s.push({callee:r,file:t,line:n.getStartLineNumber(),...tt(n.getArguments()[0])})}return s},aa=(e,t)=>{for(const s of ra){const n=S(t,s);if(!T(n))continue;const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=[];for(const a of r.getDescendantsOfKind(d.CallExpression))A(a.getExpression())===Gt&&o.push({callee:Gt,file:s,line:a.getStartLineNumber(),...tt(a.getArguments()[0])});return o}return[]},ca=(e,t)=>{const s=[];for(const{displayPath:n,filePath:r}of Ce(t)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...oa(o,n))}return s.push(...aa(e,Se(t))),s},Yt="ctx.containers.",la=e=>{if(!e.startsWith(Yt))return!1;const t=e.slice(Yt.length);return t.length>0&&!t.includes(".")},da=(e,t)=>Re(e,t,{argIndex:0,matchReceiver:la,methods:new Set(["get"])}),ua=new Set(["allow","deny","setAllowed"]),fa=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=F(t,"enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},pa=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!fa(e)))return{detail:"enableInternet: true",scope:h(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},ga=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!ua.has(s.getName()))return;const n=s.getExpression();if(!(!i.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),scope:h(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},ma=(e,t)=>pa(e,t)??ga(e,t),ha=(e,t)=>w(e,t,ma),va=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Ea=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return va.has(s)?s:void 0},xa=e=>{const t=[],s=[];for(const n of e.getProperties()){if(i.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(n)){const r=y(n);t.push(r);const o=n.getInitializer();o&&i.isStringLiteral(o)&&o.getLiteralText()===""&&s.push(r);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n)||i.isGetAccessorDeclaration(n))&&t.push(y(n))}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Sa=(e,t)=>{const s=[];for(const{displayPath:n,filePath:r}of Ce(t)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r);for(const a of o.getDescendantsOfKind(d.CallExpression)){const c=Ea(a);if(c===void 0)continue;const l=a.getArguments()[0],u=l&&i.isObjectLiteralExpression(l)?xa(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:u.analyzable,emptyKeys:u.emptyKeys,factory:c,file:n,line:a.getStartLineNumber(),presentKeys:u.presentKeys})}}return s},ya=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Aa=new Set(["dbRateLimit","rateLimit"]),ba=e=>{const t=Cs(e);if(!t)return!1;const s=F(t,"failOpen");return s!==void 0&&i.isPropertyAssignment(s)&&s.getInitializer()?.getKind()===d.TrueKeyword},Na=(e,t)=>{const s=A(e.getExpression());if(s===void 0)return;const n=ya.get(s);if(n!==void 0)return{callee:s,scope:h(e),failOpen:ba(e.getArguments()[n]),file:t,limitName:Aa.has(s)?Ts(e):"",line:e.getStartLineNumber()}},Pa=(e,t)=>w(e,t,Na),wa=new Set(["boolean","number","object","string"]),Ia=e=>{const t=e.getName();if(!wa.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="flags"&&Je(s.getExpression()))return t;const n=s.getExpression();if(s.getName()==="details"&&i.isPropertyAccessExpression(n)&&n.getName()==="flags"&&Je(n.getExpression()))return t},Ta=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=Ia(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(i.isStringLiteral(n)||i.isNoSubstitutionTemplateLiteral(n)))return;const r=n.getLiteralValue();return r.length>0?{key:r,type:s}:void 0},Ca=(e,t)=>{const s=new Map;for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of r.getDescendantsOfKind(d.CallExpression)){const a=Ta(o);a&&!s.has(a.key)&&s.set(a.key,a.type)}}return[...s.entries()].map(([n,r])=>({key:n,type:r})).toSorted((n,r)=>n.key.localeCompare(r.key))},Oa=e=>{const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const s=q(t);if(s?.kind!=="query")return;const n=Hn(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},Qt=e=>{const t=e.getParent();return t&&i.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},Ra=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!i.isIdentifier(t)||t.getText()!=="ctx")return;const s=Qt(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=Qt(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},Fa=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(d.PropertyAccessExpression)){const r=Ra(n);r!==void 0&&s.push({callee:r,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},ka=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const r of n.getDeclarations()){const o=Oa(r);o&&s.push(...Fa(o,t))}return s},La=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ka(r,P(t,n)))}return s},Da=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Je(t.getExpression())},Ma=e=>{if(e?.getKind()===d.TrueKeyword)return!0;if(e?.getKind()===d.FalseKeyword)return!1},_a=(e,t)=>{if(!Da(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const r=s.getLiteralValue(),o=Ma(n);if(!(r.length===0||o===void 0))return{defaultValue:o,scope:h(e),file:t,key:r,line:e.getStartLineNumber()}},Ka=(e,t)=>w(e,t,_a),za=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 r=n.getTypeAtLocation(e),o=r.getText(e);if(!o||o==="any"||o==="never"||ar(o))return;const a=e.getSourceFile().getFilePath();if(cr(r,e,a)){const c=lr(r,e,a,0,new Set);return c===void 0&&dr(o),c}return o},$a=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Ba=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Ua=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=P(t,n);for(const a of r.getDescendantsOfKind(d.CallExpression))$a(a)&&s.push({file:o,indexName:Ba(a),line:a.getStartLineNumber()})}return s},ce=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,js=e=>{const t=e.getArguments()[0],s=ce(t);if(s!==void 0)return s;if(t===void 0||!i.isObjectLiteralExpression(t))return;const n=F(t,"handler");return n!==void 0&&i.isPropertyAssignment(n)?ce(n.getInitializer()):void 0},Va=new Set(["delete","get","head","options","patch","post","put"]),ja=new Set(["handler","stream"]),qa=new Set(["runAction","runMutation"]),Wa=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),le=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,qs=(e,t)=>{if(!(e===void 0||!i.isObjectBindingPattern(e))){for(const s of e.getElements())if(ue(s)===t){const r=s.getNameNode();return i.isIdentifier(r)?r.getText():void 0}}},Xt=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?i.isIdentifier(s)?s.getText():void 0:qs(s,"ctx")},Jt=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&i.isIdentifier(s)?s.getText():void 0:qs(s,"request")},Zt=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(d.CallExpression);i.isCallExpression(s)&&n.unshift(s);for(const r of n){const o=r.getExpression();if(!i.isPropertyAccessExpression(o))continue;const a=o.getName(),c=o.getExpression();if(qa.has(a)&&le(c,t))return a;if(Wa.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&le(c.getExpression(),t))return`db.${a}`}},es=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(d.PropertyAccessExpression))if(n.getName()==="auth"&&le(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(d.VariableDeclaration)){const r=n.getNameNode();if(!(!i.isObjectBindingPattern(r)||!le(n.getInitializer(),t))){for(const o of r.getElements())if(ue(o)==="auth")return!0}}return!1},Ha=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,Ga=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="get"&&s.getName()!=="has")return!1;const n=s.getExpression();return i.isPropertyAccessExpression(n)&&n.getName()==="headers"&&le(n.getExpression(),t)},Ya=e=>[...i.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(d.StringLiteral).map(t=>t.getLiteralText())],Ws=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:Ya(s)},Qa=(e,t)=>{const s=e.getText();for(let n=e.getParent();n!==void 0;n=n.getParent()){if(!i.isArrowFunction(n)&&!i.isFunctionExpression(n)||!n.getParameters().some(c=>c.getName()===s))continue;const r=n.getParent();if(!i.isCallExpression(r))return[];const o=r.getExpression();if(!i.isPropertyAccessExpression(o))return[];const a=o.getExpression();return i.isIdentifier(a)?Ws(t,a.getText()):[]}return[]},Xa=e=>{const t=e.getArguments()[0];if(t===void 0)return[];if(i.isStringLiteral(t))return[t.getLiteralText()];if(!i.isIdentifier(t))return[];const s=e.getSourceFile(),n=Ws(s,t.getText());return n.length>0?n:Qa(t,s)},ts=(e,t)=>{if(t===void 0)return!1;const s=e.getBody(),n=s.getDescendantsOfKind(d.CallExpression);return i.isCallExpression(s)&&n.unshift(s),n.some(r=>Ga(r,t)&&Xa(r).some(o=>Ha.test(o)))},Ja=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ja.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))return;const r=n.getName();if(Va.has(r)){const o=n.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?r.toUpperCase():void 0}s=n.getExpression()}},Za=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=ce(e.getArguments()[0]),l=c&&Xt(c,!0);if(!c||l===void 0||ts(c,Jt(c,!0)))return;const u=Zt(c,l);return u===void 0?void 0:{scope:h(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:es(c,l),sideEffect:u}}const n=Ja(e);if(n===void 0)return;const r=ce(e.getArguments()[0]),o=r&&Xt(r,!1);if(!r||o===void 0||ts(r,Jt(r,!1)))return;const a=Zt(r,o);return a===void 0?void 0:{scope:h(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:es(r,o),sideEffect:a}},ec=(e,t)=>w(e,t,Za),tc=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),sc=new Set(["append","set"]),Hs=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",ss=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(d.CallExpression)]:e.getDescendantsOfKind(d.CallExpression)).some(n=>tc.has(A(n.getExpression())??"")&&ye(n,t)),nc=(e,t)=>{if(ss(e,t))return!0;const s=$(e);return s!==void 0&&ss(s,t)},st=(e,t)=>co(e,t)&&!nc(e,t),rc=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=$(e);return t!==void 0&&i.isNewExpression(t)&&A(t.getExpression())==="Headers"},Ne=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=$(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},dt=(e,t,s)=>{for(const n of e.getProperties())if(i.isPropertyAssignment(n)){const r=n.getInitializer();r!==void 0&&st(r,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:Hs(n.getNameNode()),line:r.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(n)){const r=n.getNameNode();st(r,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:y(n),line:r.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(n)){const r=Ne(n.getExpression());r!==void 0&&dt(r,t,s)}},Gs=(e,t)=>{const s=Ne(e);if(s===void 0)return;const n=F(s,"headers");if(n===void 0||!i.isPropertyAssignment(n))return;const r=Ne(n.getInitializer());r!==void 0&&dt(r,"response-init",t)},ic=(e,t)=>{const s=A(e.getExpression());if(s==="Response")Gs(e.getArguments()[1],t);else if(s==="Headers"){const n=Ne(e.getArguments()[0]);n!==void 0&&dt(n,"headers-ctor",t)}},oc=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName(),r=s.getExpression();if(n==="json"&&i.isIdentifier(r)&&r.getText()==="Response"){Gs(e.getArguments()[1],t);return}if(sc.has(n)&&rc(r)){const o=e.getArguments()[1];o!==void 0&&st(o,t.requestName)&&t.rows.push({scope:t.scope,file:t.relativePath,headerName:Hs(e.getArguments()[0]),line:o.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},ac=(e,t)=>{for(const s of e.getDescendantsOfKind(d.NewExpression))ic(s,t);for(const s of e.getDescendantsOfKind(d.CallExpression))oc(s,t)},cc=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=ce(e.getArguments()[0]);if(n===void 0)return[];const r=n.getParameters()[1];if(r===void 0)return[];const o=r.getNameNode();if(!i.isIdentifier(o))return[];const a=[];return ac(n,{scope:h(e),relativePath:t,requestName:o.getText(),rows:a}),a},lc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression))s.push(...cc(n,t));return s},dc=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...lc(r,P(t,n)))}return s},uc=new Set(["auth","context.auth","ctx.auth"]),fc="userId",pc=e=>{const t=new Set;for(const s of e.getProperties()){if(i.isSpreadAssignment(s))return;(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s))&&t.add(y(s))}return t},gc=(e,t)=>{const s=S(t,_s);if(!T(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const r of n.getDescendantsOfKind(d.CallExpression)){if(A(r.getExpression())!=="defineIdentity")continue;const[o]=r.getArguments();return o&&i.isObjectLiteralExpression(o)?pc(o):void 0}},ns=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return uc.has(e.getExpression().getText())?e:void 0},mc=e=>{if(i.isPropertyAccessExpression(e)&&ns(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&ns(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},rs=(e,t,s)=>{const n=mc(e);return n===void 0?void 0:{declared:n===fc||s.has(n),file:t,key:n,line:e.getStartLineNumber(),scope:h(e)}},hc=(e,t)=>{const s=gc(e,t);return s===void 0?[]:[...Xe(e,t,d.PropertyAccessExpression,(n,r)=>rs(n,r,s)),...Xe(e,t,d.ElementAccessExpression,(n,r)=>rs(n,r,s))]},vc=(e,t)=>{if(A(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=N(s,"key");if(!(!n||!B(n)||G(n)))return{scope:h(e),file:t,line:e.getStartLineNumber()}},Ec=(e,t)=>w(e,t,vc),xc=e=>{if(i.isComputedPropertyName(e)){const t=e.getExpression();return i.isStringLiteral(t)||i.isNoSubstitutionTemplateLiteral(t)?t.getLiteralValue():void 0}return i.isStringLiteral(e)?e.getLiteralValue():e.getText()},Sc=e=>e.getProperties().some(t=>{if(i.isSpreadAssignment(t))return!0;const s=xc(t.getNameNode());return s===void 0||s==="namespace"}),yc=(e,t)=>{for(const{filePath:s}of Ce(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const r of n.getDescendantsOfKind(d.CallExpression)){const o=r.getExpression(),[a]=r.getArguments();if(!(!i.isPropertyAccessExpression(o)||o.getName()!=="auth"||a===void 0)&&(!i.isObjectLiteralExpression(a)||Sc(a)))return r}}},Ac="https://lunora.sh/docs/concepts/data-residency#pinning-auth-and-voice",bc=(e,t)=>{if(!(e.jurisdiction===void 0||e.jurisdictionPinsAuth===!0||t===void 0))throw de(t,`the schema pins Durable Objects to the "${e.jurisdiction}" jurisdiction, and this project also has DO-backed auth (users, sessions, accounts, credentials). Pinning the auth object resolves it to a NEW, EMPTY object: existing users stay in the unpinned one until you copy them across (${Ac}). Acknowledge with \`.jurisdiction("${e.jurisdiction}", { pinAuth: true })\`, deploy, then run the copy. For D1-mode auth the acknowledgement changes nothing.`,{code:"JURISDICTION_MOVE",status:422})},Nc=new Set(["delete","get","getRaw","getWithMetadata","put"]),Pc=(e,t,s=[])=>{const n=Re(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.kv"||r.startsWith("ctx.kv."),methods:Nc});return it(n,s)},wc=new Set(["queue","send"]),is=new Set(["bcc","cc","to"]),Ic=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!wc.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},Tc=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return is.has(y(t))&&B(n)&&!G(n)}if(!i.isPropertyAssignment(t)||!is.has(y(t)))return!1;const s=t.getInitializer();return s!==void 0&&B(s)&&!G(s)}):!1,Cc=(e,t)=>{const s=Ic(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!Tc(n)))return{scope:h(e),file:t,line:e.getStartLineNumber(),method:s}},Oc=(e,t)=>w(e,t,Cc),Rc=e=>i.isPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?i.isComputedPropertyName(e.getNameNode()):!1,Fc=e=>i.isPropertyAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?Rc(e):!0,Ys=(e,t=!1)=>{for(const s of e.getProperties()){if(Fc(s))return!0;if(t)continue;if(!i.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!i.isObjectLiteralExpression(n)||Ys(n,!0))return!0}return!1},kc=(e,t)=>{for(const s of E(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:r}of Ds(n))for(const o of ot(r)){const a=o.getArguments()[0];if(a!==void 0&&(!i.isObjectLiteralExpression(a)||Ys(a)))return!0}}return!1},Lc=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const r=be(n);if(r===void 0||!i.isPropertyAssignment(n))continue;const o=n.getInitializer();if(!(!o||!i.isObjectLiteralExpression(o)))for(const a of o.getProperties()){const c=be(a);c!==void 0&&s.push({column:c,strategy:Ls(a),table:r})}}return s},Dc=(e,t)=>{const s=new Map;for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:o}of Ds(r))for(const a of ot(o))for(const c of Lc(a)){const l=`${c.table}\0${c.column}`;s.has(l)||s.set(l,c)}}return{columns:[...s.values()]}},Mc=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!i.isObjectLiteralExpression(n))return[];const r=[];for(const o of n.getProperties()){const a=be(o);if(a===void 0||!i.isPropertyAssignment(o))continue;const c=o.getInitializer();if(!(!c||!i.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const u=be(l);if(u===void 0)continue;const g=Ls(l);g!=="custom"&&r.push({column:u,exportName:t,file:s,line:l.getStartLineNumber(),strategy:g,table:a})}}return r},_c=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?q(s):void 0;return n?.receiver?ot(n.receiver).flatMap(r=>Mc(r,e.getName(),t)):[]},Kc=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=P(t,n);for(const a of r.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(..._c(c,o))}return s},zc=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return M(s)},$c=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=F(t,"server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},Bc=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==d.CallExpression)return;const s=t;return Sr(s.getExpression())?s:void 0},Uc=e=>{const t=Bc(e),s=t===void 0?void 0:$c(t);if(s===void 0)return[];const n=e.getNameNode(),r=i.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(d.CallExpression).filter(o=>zc(o)).map(o=>({exportName:r,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},Vc=e=>e.getVariableDeclarations().flatMap(t=>Uc(t)),jc=(e,t)=>{const s=S(t,xr);if(!T(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Vc(n)},qc=new Set(["delete","get","patch"]),Wc=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Hc=new Set(["auth","identity","session","user"]),Gc=new Set([d.EqualsEqualsEqualsToken,d.EqualsEqualsToken,d.ExclamationEqualsEqualsToken,d.ExclamationEqualsToken]),Yc=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!M(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},Qc=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(i.isAsExpression(s)||i.isParenthesizedExpression(s)||i.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!i.isVariableDeclaration(s))return;const n=s.getNameNode();return i.isIdentifier(n)?n.getText():void 0},Xc=(e,t)=>e.getDescendantsOfKind(d.Identifier).some(s=>s.getText()===t),Jc=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(d.ThrowStatement).length>0||e.getDescendantsOfKind(d.ReturnStatement).length>0,Zc=(e,t)=>e.getDescendantsOfKind(d.IfStatement).some(s=>Xc(s.getExpression(),t)&&Jc(s.getThenStatement())),el=(e,t)=>{for(const s of e.getDescendantsOfKind(d.CallExpression)){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))continue;const r=n.getName();if(!qc.has(r))continue;const o=n.getExpression();if(!(M(o)||i.isPropertyAccessExpression(o)&&M(o.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&i.isIdentifier(c)&&c.getText()===t)return r}},tl=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t)||i.isParenthesizedExpression(t)||i.isAsExpression(t)||i.isAwaitExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t.getText():void 0},sl=e=>e.getDescendantsOfKind(d.CallExpression).some(t=>t.getArguments().some(s=>tl(s)==="ctx")),nl=e=>e.getDescendantsOfKind(d.BinaryExpression).some(t=>Gc.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),rl=e=>{for(const t of e.getDescendantsOfKind(d.Identifier))if(Wc.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(d.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&Hc.has(t.getName()))return!0}return sl(e)||nl(e)},il=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=q(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const r=js(s);if(r===void 0)return[];const o=n.receiver!==void 0&&Rs(n.receiver,"use","rls"),a=rl(r),c=new Set,l=[];for(const u of r.getDescendantsOfKind(d.CallExpression)){const g=Yc(u);if(g===void 0)continue;const f=Qc(u);if(f===void 0||c.has(f)||!Zc(r,f))continue;const m=el(r,f);m!==void 0&&(c.add(f),l.push({exportName:e.getName(),file:t,line:u.getStartLineNumber(),mentionsOwnership:a,sinkMethod:m,table:g,usesRls:o,visibility:n.visibility}))}return l},ol=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=P(t,n);for(const a of r.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...il(c,o))}return s},al=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),cl=new Set(["insert","insertManyUnsafe","patch","replace"]),ll=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!cl.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="db")return;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="ctx"?t:void 0},dl=(e,t)=>{if(t!=="insertManyUnsafe")return i.isObjectLiteralExpression(e)?[e]:[];if(!i.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())i.isObjectLiteralExpression(n)&&s.push(n);return s},os=new WeakMap,Qs=new Set(["asId","runAction","runMutation","runQuery"]),ul=new Set(["catch","flatMap","map","reduce","reduceRight","then"]),fl=new Set(["at","every","filter","finally","find","findIndex","findLast","findLastIndex","forEach","order","slice","some","sort","withIndex","withSearchIndex"]),He=e=>{const t=v(e);if(!i.isArrowFunction(t)&&!i.isFunctionExpression(t))return;const s=t.getBody();return i.isBlock(s)?s.getDescendantsOfKind(d.ReturnStatement).filter(n=>n.getFirstAncestor(r=>i.isFunctionLikeDeclaration(r))===t).map(n=>n.getExpression()):[s]},pl=e=>{const t=v(e);if(!i.isIdentifier(t))return i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t);const s=D(t),n=i.isVariableDeclaration(s)?v(s.getInitializer()):void 0;return s===void 0||i.isFunctionDeclaration(s)||i.isParameterDeclaration(s)||i.isArrowFunction(n)||i.isFunctionExpression(n)},gl=new Set(["all","allSettled","any","race"]),Xs=e=>{let t=v(e);for(;i.isAwaitExpression(t)||i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isCallExpression(t);)t=v(t.getExpression());return t},Js=(e,t)=>{const s=i.isIdentifier(e)&&t!==void 0?D(e):void 0;return s===void 0||t===void 0?!1:s.compilerNode===t.compilerNode?i.isIdentifier(t.getNameNode()):i.isBindingElement(s)&&s.getFirstAncestorByKind(d.Parameter)?.compilerNode===t.compilerNode},ml=e=>{const t=z(e),s=t.getParent();return(i.isPropertyAccessExpression(s)||i.isElementAccessExpression(s))&&s.getExpression()===t&&!ae(s)},hl=e=>{const t=z(e).getParent();return i.isVariableDeclaration(t)&&i.isObjectBindingPattern(t.getNameNode())},vl=e=>{const s=z(e).getParent();if(i.isSpreadAssignment(s)||i.isSpreadElement(s)){const n=s.getParent();return(i.isObjectLiteralExpression(n)||i.isArrayLiteralExpression(n))&&!ae(n)}return i.isTemplateSpan(s)&&!i.isTaggedTemplateExpression(s.getParent().getParent())},El=/\/typescript\/lib\/lib\.[^/]+\.d\.ts$/u,as=e=>{const t=D(e);if(t===void 0)return!0;const s=t.getSourceFile(),n=s.getFilePath();return s.isDeclarationFile()&&(El.test(n)||n.includes("/@types/node/"))},xl=(e,t)=>{const s=z(e),n=s.getParent();if(!i.isCallExpression(n))return!1;const r=n.getArguments().indexOf(s),o=v(n.getExpression());if(r===-1||o===void 0)return!1;if(i.isIdentifier(o))return o.getText()==="structuredClone"&&as(o);if(Js(Xs(o),t))return!(i.isPropertyAccessExpression(o)&&Qs.has(o.getName()))||i.isExpressionStatement(z(i.isAwaitExpression(n.getParent())?n.getParentOrThrow():n).getParent());if(!i.isPropertyAccessExpression(o))return!1;const a=o.getExpression();if(!i.isIdentifier(a)||!as(a))return!1;const c=a.getText(),l=o.getName();switch(c){case"console":return!0;case"JSON":return l==="stringify";case"Object":return["entries","keys","values"].includes(l)||["assign","freeze","isFrozen"].includes(l)&&r>0;default:return!1}},Sl=(e,t)=>{const s=i.isFunctionExpression(e)?e.getNameNode():void 0;if(!i.isArrowFunction(e)&&e.getFirstDescendantByKind(d.ThisKeyword)!==void 0)return!0;const n=new Set([t.getName(),...s===void 0?[]:[s.getText()]]);return e.getDescendantsOfKind(d.Identifier).some(r=>{if(r===s||!n.has(r.getText()))return!1;const o=D(r)?.compilerNode;return o!==void 0&&(o===t.compilerNode||s!==void 0&&o===e.compilerNode)})},yl=(e,t,s)=>{const{context:n,impl:r}=e,o=os.get(r.compilerNode);if(o!==void 0)return o;const a=t.getNameNode(),c=i.isIdentifier(a)?[a]:a.getDescendantsOfKind(d.BindingElement).flatMap(f=>{const m=f.getNameNode();return i.isIdentifier(m)?[m]:[]}),l=new Map(c.map(f=>[f.getText(),f.getParentOrThrow().compilerNode])),u=f=>i.isIdentifier(a)?ml(f)||hl(f)||vl(f)||xl(f,n):!ae(f),g=!Sl(r,s)&&c.every(f=>(f.getSymbol()?.getDeclarations().length??0)===1)&&r.getDescendantsOfKind(d.Identifier).every(f=>{const m=f.getText();if(m==="arguments")return!1;const x=l.get(m);return x===void 0||c.includes(f)||D(f)?.compilerNode!==x?!0:u(f)});return os.set(r.compilerNode,g),g},Al=e=>{const t=e.getAncestors().at(-2),s=i.isVariableStatement(t)?t.getDeclarations().find(l=>l.getPos()<=e.getPos()&&e.getEnd()<=l.getEnd()):void 0,n=s===void 0?void 0:yr(s);if(s===void 0||n===void 0||e.getPos()<n.getPos()||n.getEnd()<e.getEnd())return;const[r,o]=n.getParameters(),a=o===void 0||o.isRestParameter()?void 0:o,c={context:r,impl:n,parameter:a};return{...c,pristine:a!==void 0&&yl(c,a,s)}},cs=e=>i.isParameterDeclaration(e)?e:i.isBindingElement(e)?e.getFirstAncestorByKind(d.Parameter):void 0,bl=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!((i.isPropertyAssignment(t)||i.isMethodDeclaration(t))&&t.getNameNode()===e)},Nl=new Set(["catch","every","filter","finally","find","findIndex","findLast","findLastIndex","flatMap","forEach","map","reduce","reduceRight","some","sort","then"]),Ge=8,Pl=5e4;class wl{cuts=0;inProgress=new Set;referencesByName=new Map;scope;variableDepth=0;verdicts=new Map;queryDepth=0;work=0;constructor(t){this.scope=t;for(const s of t.impl.getDescendantsOfKind(d.Identifier)){const n=s.getText();this.referencesByName.set(n,[...this.referencesByName.get(n)??[],s])}}isTaintedValue(t,s){this.queryDepth===0&&(this.work=0),this.queryDepth+=1;try{return s&&this.isRootedInContext(t,Ge)?!1:(i.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(r=>bl(r)&&this.isIdentifierTainted(r))}finally{this.queryDepth-=1}}flowsIntoTainted(t){if([t.getInitializer(),...t.getDescendantsOfKind(d.BindingElement).map(f=>f.getInitializer())].some(f=>f!==void 0&&this.isTaintedValue(f,!1)))return!0;const n=t.getParentOrThrow(),r=i.isFunctionLikeDeclaration(n)?n.getParameters().findIndex(f=>f.compilerNode===t.compilerNode):-1,o=z(n),a=o.getParent();if(r===-1)return!0;if(i.isCallExpression(a)){if(a.getExpression()===o)return this.isCallSiteTainted(a,r,t.isRestParameter());const f=v(a.getExpression());if(!i.isPropertyAccessExpression(f)||!Nl.has(f.getName()))return!0;const m=a.getArguments().filter(x=>x!==o);return this.isTaintedValue(f.getExpression(),!0)||m.some(x=>this.isTaintedValue(x,!1))}const c=i.isVariableDeclaration(a)&&ie(a)?a:void 0,l=i.isFunctionDeclaration(n)?n:c,u=l?.getNameNode();if(l===void 0||!i.isIdentifier(u))return!0;const g=this.referencesTo(l,u.getText());return g.length===0||g.some(f=>{const m=z(f),x=m.getParent();return!i.isCallExpression(x)||x.getExpression()!==m||this.isCallSiteTainted(x,r,t.isRestParameter())})}isCallSiteTainted(t,s,n){const r=t.getArguments(),o=r.findIndex(c=>i.isSpreadElement(c)),a=c=>c===s||n&&c>s||o!==-1&&o<=s&&c>=o;return r.some((c,l)=>a(l)&&this.isTaintedValue(c,!1))}isContextRootedCombinator(t,s){const n=v(t.getExpression()),o=i.isPropertyAccessExpression(n)&&n.getExpression().getText()==="Promise"&&gl.has(n.getName())?v(t.getArguments()[0]):void 0;if(i.isArrayLiteralExpression(o)){const u=o.getElements();return u.length>0&&u.every(g=>!i.isSpreadElement(g)&&this.isRootedInContext(g,s))}const a=i.isCallExpression(o)?v(o.getExpression()):void 0,c=i.isCallExpression(o)&&i.isPropertyAccessExpression(a)&&a.getName()==="map"?v(o.getArguments()[0]):void 0,l=c===void 0?void 0:He(c);return l!==void 0&&l.length>0&&l.every(u=>u!==void 0&&this.isRootedInContext(u,s))}isIdentifierTainted(t){const s=t.getText();if(s==="arguments")return!0;const n=D(t),r=cs(n);if(r!==void 0)return this.isSource(r);if(s==="args")return!0;if(n===void 0||!this.isInImpl(n))return!1;if(i.isFunctionDeclaration(n))return this.memoized(n.compilerNode,()=>this.isTaintedValue(n,!1));const o=i.isBindingElement(n)?n.getFirstAncestorByKind(d.VariableDeclaration):n;return i.isVariableDeclaration(o)&&this.isVariableTainted(o,s)}isInImpl(t){const{impl:s}=this.scope;return t!==s&&s.getPos()<=t.getPos()&&t.getEnd()<=s.getEnd()}isMutatedWithTaint(t){const s=t.getNameNode();return i.isIdentifier(s)?this.memoized(s.compilerNode,()=>this.referencesTo(t,s.getText()).some(n=>{let r=z(n),o=r.getParent();for(;(i.isPropertyAccessExpression(o)||i.isElementAccessExpression(o))&&o.getExpression()===r;)r=z(o),o=r.getParent();if(r!==z(n)&&ae(r))return!i.isBinaryExpression(o)||this.isTaintedValue(o.getRight(),!1);if(!i.isCallExpression(o))return!1;const a=o.getArguments().filter(c=>{const l=v(c);return c!==r&&!i.isArrowFunction(l)&&!i.isFunctionExpression(l)});return(o.getExpression()===r||o.getArguments().includes(r))&&a.some(c=>this.isTaintedValue(c,!1))})):!1}callChainVerdict(t,s){if(this.isContextRootedCombinator(t,s))return!0;const n=v(t.getExpression()),r=i.isPropertyAccessExpression(n)?n.getName():void 0;return r!==void 0&&Qs.has(r)?!1:r!==void 0&&ul.has(r)?this.isCallbackResultServerScoped(t,s)?void 0:!1:t.getArguments().some(a=>He(a)!==void 0)&&(r===void 0||!fl.has(r))?!1:void 0}isCallbackResultServerScoped(t,s){const n=(r,o=[])=>{const a=Xs(r),c=i.isIdentifier(a)?cs(D(a)):void 0;return c!==void 0&&o.includes(c)?!0:this.isRootedInContext(r,s)||!this.isTaintedValue(r,!1)};return t.getArguments().every(r=>{const o=He(r);if(o===void 0)return!pl(r)&&n(r);const a=v(r),c=i.isArrowFunction(a)||i.isFunctionExpression(a)?a.getParameters():[];return o.every(l=>l===void 0||n(l,c))})}isRootedInContext(t,s){let n=v(t);for(;i.isAwaitExpression(n)||i.isPropertyAccessExpression(n)||i.isElementAccessExpression(n)||i.isCallExpression(n);){const c=i.isCallExpression(n)?this.callChainVerdict(n,s):void 0;if(c!==void 0)return c;n=v(n.getExpression())}if(Js(n,this.scope.context))return!0;const r=i.isIdentifier(n)?D(n):void 0,o=i.isBindingElement(r)?r.getFirstAncestorByKind(d.VariableDeclaration):r,a=ie(o)&&this.isInImpl(o)?o.getInitializer():void 0;return s>0&&a!==void 0&&i.isVariableDeclaration(o)&&!this.isMutatedWithTaint(o)&&this.isRootedInContext(a,s-1)}isSource(t){const{impl:s,parameter:n}=this.scope;return t.compilerNode===n?.compilerNode?!0:t.getParent()!==s&&this.isInImpl(t)&&this.memoized(t.compilerNode,()=>this.flowsIntoTainted(t))}isVariableTainted(t,s){return this.memoized(t.compilerNode,()=>{const n=t.getParent().getParent();if(i.isCatchClause(t.getParent()))return!0;if(i.isForOfStatement(n)||i.isForInStatement(n))return this.isTaintedValue(n.getExpression(),!0);const r=t.getInitializer(),o=!ie(t)&&this.referencesTo(t,s).some(a=>ae(a));if(r===void 0||o||this.isMutatedWithTaint(t))return!0;if(this.isRootedInContext(r,Ge))return!1;if(this.variableDepth>=Ge)return this.cuts+=1,!0;this.variableDepth+=1;try{return this.isTaintedValue(r,!1)}finally{this.variableDepth-=1}})}memoized(t,s){const n=this.verdicts.get(t);if(n!==void 0)return n;if(this.inProgress.has(t))return this.cuts+=1,!1;if(this.work+=1,this.work>Pl)return this.cuts+=1,!0;const r=this.cuts;this.inProgress.add(t);let o;try{o=s()}finally{this.inProgress.delete(t)}return this.cuts===r&&this.verdicts.set(t,o),o}referencesTo(t,s){return(this.referencesByName.get(s)??[]).filter(n=>n.getParent()!==t&&D(n)?.compilerNode===t.compilerNode)}}const ls=new WeakMap,Il=e=>{const t=ls.get(e.impl.compilerNode);if(t!==void 0)return t;const s=new wl(e);return ls.set(e.impl.compilerNode,s),s},Tl=(e,t)=>{if(i.isPropertyAccessExpression(e))return e.getName()===t?v(e.getExpression()):void 0;if(i.isElementAccessExpression(e)){const s=e.getArgumentExpression();return s!==void 0&&i.isStringLiteral(s)&&s.getLiteralValue()===t?v(e.getExpression()):void 0}},ds=(e,t)=>i.isIdentifier(e)&&D(e)?.compilerNode===t.compilerNode,Zs=(e,t,s,n=1)=>{const r=Tl(e,s);if(r!==void 0)return ds(r,t);const o=i.isIdentifier(e)?D(e):void 0;if(i.isBindingElement(o)){const c=o.getParent(),l=c.getParent();return o.getDotDotDotToken()===void 0&&ue(o)===s&&i.isObjectBindingPattern(c)&&(l.compilerNode===t.compilerNode||ie(l)&&ds(v(l.getInitializer()),t))}const a=ie(o)?o.getInitializer():void 0;return n>0&&a!==void 0&&Zs(a,t,s,n-1)},Cl=(e,t,s)=>{const n=[],r=s===void 0?void 0:Il(s);for(const o of e.getProperties()){let a,c;if(i.isPropertyAssignment(o)?(a=y(o),c=o.getInitializer()):i.isShorthandPropertyAssignment(o)&&(a=y(o),c=o.getNameNode()),a===void 0||c===void 0||!al.has(a))continue;if(r===void 0?B(c)&&!G(c):r.isTaintedValue(c,!0)){const u=t.ownerField===a&&s?.parameter!==void 0&&s.pristine&&Zs(c,s.parameter,a);n.push({field:a,file:t.relativePath,line:t.call.getStartLineNumber(),method:t.method,scope:t.scope,...u&&{ownerScoped:!0}})}}return n},Ol=(e,t,s)=>{const n=ll(e.getExpression()),r=n===void 0?void 0:e.getArguments()[1];if(n===void 0||r===void 0)return[];const o=dl(r,n);if(o.length===0)return[];const a=h(e),c=a.kind==="export",l={call:e,method:n,ownerField:c?s(a.name):void 0,relativePath:t,scope:a},u=c?Al(e):void 0;return o.flatMap(g=>Cl(g,l,u))},Rl=(e,t,s=[],n=[])=>{const r=new Map(n.map(a=>[`${a.filePath}:${a.exportName}`,a.owner])),o=w(e,t,(a,c)=>Ol(a,c,l=>r.get(`${c}:${l}`)));return it(o,s)},Fl=["providerSubscriptionId","state"],kl=["providerEventId","processedAt"],us=(e,t)=>t.every(s=>s in e.shape),Ll=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&us(t,Fl)&&us(s,kl)},Dl=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Ml=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,_l=e=>{const t=F(e,"webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?Ml(t.getInitializer()):void 0},Kl=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!Dl.has(s))return;const[n]=e.getArguments(),r=n&&i.isObjectLiteralExpression(n)?_l(n):void 0;return{callee:s,scope:h(e),file:t,line:e.getStartLineNumber(),...r===void 0?{}:{toleranceSeconds:r}}},zl=(e,t)=>w(e,t,Kl),$l=new Map([["defineQueue",0],["defineSubscription",1],["defineWorkflow",0]]),Bl=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},Ul=(e,t)=>{const s=e.getArguments()[t];if(!s||!i.isObjectLiteralExpression(s))return;const n=F(s,"handler");if(n===void 0||!i.isPropertyAssignment(n))return;const r=n.getInitializer();if(r&&(i.isArrowFunction(r)||i.isFunctionExpression(r)))return r},en=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},tn=(e,t)=>e===t||e.startsWith(`${t}.`),sn=e=>{const t=e.getDescendantsOfKind(d.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},fs=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e||i.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(i.isBindingElement(t)&&t.getNameNode()===e)},nn=e=>{const t=e.getDescendantsOfKind(d.Identifier).filter(s=>fs(s));return i.isIdentifier(e)&&fs(e)&&t.push(e),t},Vl=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(d.BindingElement).map(s=>s.getName())},jl=e=>{const t=en(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(d.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const r=n.getInitializer(),o=i.isVariableDeclarationList(r)?r.getDeclarations()[0]?.getNameNode():void 0;o&&i.isIdentifier(o)&&s.push(`${o.getText()}.body`)}return s},ql=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:jl(e),r=new Set,o=a=>sn(a).some(c=>n.some(l=>tn(c.getText(),l)))?!0:nn(a).some(c=>r.has(c.getText()));for(const a of e.getDescendantsOfKind(d.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of Vl(a))r.add(l)}return{names:r,prefixes:n}},Wl=(e,t)=>sn(e).some(s=>t.prefixes.some(n=>tn(s.getText(),n)))?!0:nn(e).some(s=>t.names.has(s.getText())),Hl=e=>{const t=Is(e);return t===void 0?void 0:{exportName:String(t.at(-1)),file:t.slice(0,-1).join("/")}},Gl=(e,t,s)=>{const n=en(e,0);if(n===void 0)return[];const r=ql(e,t,n),o=new Set([n,...r.prefixes.filter(c=>c.endsWith(".body")).map(c=>c.slice(0,-5))]),a=[];for(const c of e.getDescendantsOfKind(d.CallExpression)){const l=c.getExpression();if(!i.isPropertyAccessExpression(l)||!ws.has(l.getName())||!o.has(l.getExpression().getText()))continue;const u=c.getArguments()[1];if(!u||!Wl(u,r))continue;const g=Hl(c.getArguments()[0]);g!==void 0&&a.push({dispatchKind:t,file:s,scope:h(c),line:c.getStartLineNumber(),targetExport:g.exportName,targetFile:g.file})}return a},Yl=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=Bl(n),o=r===void 0?void 0:$l.get(r);if(o===void 0)continue;const a=Ul(n,o);a!==void 0&&s.push(...Gl(a,r==="defineWorkflow"?"workflow":"queue",t))}return s},Ql=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Yl(r,P(t,n)))}return s},ps={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},gs=new Set(["account","credential","member","passkey","session","user"]),Xl=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),Jl=e=>{const s=Xl(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return gs.has(s)||gs.has(n)},Zl=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},ed=(e,t)=>{const{objects:s,opaque:n}=lt(e,t);return To(s).some(r=>Zl(r))?!0:n?void 0:!1},td=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!F(t,"captcha"),usesRateLimit:!!F(t,"rateLimit")}},sd=e=>{if(i.isCallExpression(e))return e;if(!i.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&i.isCallExpression(s)?s:void 0},Ae={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},nd=e=>{const t=sd(e),s=t?A(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=td(t);return{...Ae,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in ps?{...Ae,[ps[s]]:!0}:Ae},rd=e=>{const t={...Ae};let s=e;for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))break;const r=n.getName()==="use"?s.getArguments()[0]:void 0;if(r){const o=nd(r);t.usesCaptcha||=o.usesCaptcha,t.usesEmailGate||=o.usesEmailGate,t.usesMask||=o.usesMask,t.usesRateLimit||=o.usesRateLimit,t.usesRls||=o.usesRls}s=n.getExpression()}return t},id=new Set(["insert","insertMany","insertManyUnsafe","replace"]),od=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!id.has(t.getName()))return!1;const s=t.getExpression();if(!M(s))return!1;const r=e.getArguments()[0];return!r||!(i.isStringLiteral(r)||i.isNoSubstitutionTemplateLiteral(r))?!1:Jl(r.getLiteralText())},ad=new Set(["create","publish","publishBatch","runAfter","runAt","send","sendBatch"]),cd=new Set(["queues","scheduler","topics","workflows"]),ld=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ad.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&cd.has(s.getName())){const n=s.getExpression();if(i.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},dd=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return M(s)},rn=new Set(["generateObject","generateText","streamObject","streamText"]),ud=e=>{const t=A(e.getExpression());return t!==void 0&&rn.has(t)},fd=e=>{const t=A(e.getExpression());if(t===void 0||!rn.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(n=>i.isSpreadAssignment(n))?!1:!F(s,"maxOutputTokens")},pd=new Set(["log","span","trace"]),gd=new Set(["ai"]),md=new Set(["email","mail"]),hd=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","topics","workflows"]),Ye=(e,t)=>e.getDescendantsOfKind(d.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="ctx"}),vd=new Set([d.ArrowFunction,d.FunctionDeclaration,d.FunctionExpression,d.GetAccessor,d.MethodDeclaration,d.SetAccessor]),Ed=new Set(["every","filter","flatMap","forEach","map","some"]),xd=new Set(["all","allSettled","race"]),Sd=e=>{const t=e.getParent();if(!t||!i.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName();if(Ed.has(n))return t;const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="Promise"&&xd.has(n))return t},yd=e=>{let t=e.getParent();for(;t;){if(i.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(vd.has(t.getKind())){const s=Sd(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},Ad=e=>{let t=e;for(;;){const s=t.getParent();if(!i.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;if(s.getName()==="catch")return!0;if(s.getName()!=="then"&&s.getName()!=="finally")return!1;const n=s.getParent();if(!i.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},bd=e=>{let t=e;for(;;){const s=t.getParent();if(i.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return i.isCallExpression(s)&&s.getExpression()===t?s:void 0}},Nd=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(d.PropertyAccessExpression)){if(!hd.has(n.getName()))continue;const r=n.getExpression();if(!i.isIdentifier(r)||r.getText()!=="ctx")continue;const o=bd(n);o&&(t=!0,!yd(o)&&!Ad(o)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},Pd=e=>e.getDescendantsOfKind(d.ThrowStatement).some(t=>{const s=t.getExpression();if(!i.isNewExpression(s))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="Error"}),ms="lunora-advisor-exempt",wd=/^[\s*/]+/u,Id=/[\w-]/u,Td=e=>{const s=(e.getFirstAncestorByKind(d.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
7
- `);for(const n of s.split(`
8
- `)){const r=n.replace(wd,"");if(!r.startsWith(ms))continue;const o=r.slice(ms.length);if(Id.test(o.charAt(0)))continue;const a=o.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":o.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},Cd=e=>{const[t]=e.getArguments();if(t){if(i.isObjectLiteralExpression(t)){const s=F(t,"handler");return s?i.isPropertyAssignment(s)?s.getInitializer():i.isShorthandPropertyAssignment(s)?s.getNameNode():i.isMethodDeclaration(s)?s:void 0:void 0}return t}},Od=(e,t)=>{const s=Cd(t);if(!s)return;if(i.isArrowFunction(s)||i.isFunctionExpression(s)||i.isMethodDeclaration(s))return e;if(!i.isIdentifier(s))return;const n=s.getSourceFile(),r=s.getText(),o=n.getVariableDeclaration(r)?.getInitializer();return o&&(i.isArrowFunction(o)||i.isFunctionExpression(o))?o:n.getFunction(r)},Rd=e=>{let t=!1,s=!1,n=!1,r=!1,o=!1;for(const l of e.getDescendantsOfKind(d.CallExpression))if(od(l)&&(o=!0),ld(l)&&(t=!0),dd(l)&&(r=!0),ud(l)&&(s=!0),fd(l)&&(n=!0),o&&t&&r&&n)break;const{handlesErrors:a,reachesOutbound:c}=Nd(e);return{callsMail:Ye(e,md),emitsEvent:Ye(e,pd),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||Ye(e,gd),throwsBareError:Pd(e),unboundedAiGeneration:n,usesInsertManyUnsafe:r,writesUserTable:o}},Fd=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=q(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const r=n.receiver?rd(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},o=Od(e,s);return{...o?Rd(o):{},...Td(e),...r,analyzableBody:o!==void 0,exportName:e.getName(),file:t,hasEmailArg:ed(s,n.receiver),kind:n.kind,visibility:n.visibility}},kd=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const r of n.getDeclarations()){const o=Fd(r,t);o&&s.push(o)}return s},Ld=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...kd(r,P(t,n)))}return s},Dd=new Set(["dbRateLimit","rateLimit"]),Md=e=>i.isArrowFunction(e)?e.getBody():e,_d=e=>{if(!i.isArrowFunction(e))return;const t=e.getParameters()[0]?.getNameNode();return t!==void 0&&i.isIdentifier(t)?t:void 0},on=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getExpression()===e&&t.getName()==="args"},an=(e,t)=>{const s=t.getSymbol();return s===void 0?[]:e.getDescendantsOfKind(d.Identifier).filter(n=>{if(n.getSymbol()!==s)return!1;const r=n.getParent();return!(i.isPropertyAccessExpression(r)&&r.getNameNode()===n)})},Kd=(e,t)=>B(e)||t!==void 0&&an(e,t).some(s=>on(s)),zd=(e,t)=>t===void 0?G(e):an(e,t).some(s=>!on(s)),$d=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!Dd.has(s))return;const n=N(Cs(e.getArguments()[2]),"key");if(!n)return;const r=Md(n),o=_d(n);if(!(!Kd(r,o)||zd(r,o)))return{callee:s,scope:h(e),file:t,limitName:Ts(e),line:e.getStartLineNumber()}},Bd=(e,t)=>w(e,t,$d),Ud=new Set(["findFirst","findFirstOrThrow","findMany","findUnique","get"]),Vd=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Ud.has(t.getName()))return;const s=t.getExpression();if(M(s)){const n=e.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&M(s.getExpression()))return s.getName()},jd=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&M(s.getExpression())){const n=t.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},qd=e=>{let t=v(e)??e;for(;i.isAwaitExpression(t);)t=v(t.getExpression())??t.getExpression();return t},cn=(e,t=!1)=>{const s=qd(e);if(i.isIdentifier(s)){if(t)return;const n=$(s);return n===void 0?void 0:cn(n,!0)}if(i.isCallExpression(s))return Vd(s)??jd(s)},Wd=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(d.ReturnStatement)){const r=n.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),o=n.getExpression();r===e&&o!==void 0&&s.push(o)}return s},Hd=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=q(s);if(n?.kind!=="query")return[];const r=js(s);if(r===void 0)return[];const o=n.receiver!==void 0&&Xn(n.receiver,"output"),a=n.receiver!==void 0&&Rs(n.receiver,"use","mask"),c=new Set,l=[];for(const u of Wd(r)){const g=cn(u);g===void 0||c.has(g)||(c.add(g),l.push({exportName:e.getName(),file:t,line:u.getStartLineNumber(),table:g,usesMask:a,usesOutput:o,visibility:n.visibility}))}return l},Gd=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=P(t,n);for(const a of r.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Hd(c,o))}return s},Yd=e=>{if(!e||!i.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s)||i.isGetAccessorDeclaration(s))&&t.push(y(s));return t},Qd=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?q(s):void 0;if(!n)return[];const r=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=Os(o);if(a===void 0)continue;const c=Yd(N(a.options,"with"));c.length!==0&&r.push({exportName:e.getName(),file:t,line:o.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return r},Xd=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=P(t,n);for(const a of r.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Qd(c,o))}return s},Pe=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===d.PlusToken){const t=Pe(e.getLeft()),s=Pe(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},Jd=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===d.PlusToken;)t=s,s=t.getParent();return t!==e&&Pe(t)!==void 0},Zd=/(?:^|\/)__tests__\//u,eu=/\.(?:spec|test)$/u,tu=e=>Zd.test(e)||eu.test(e),su=e=>{const t=e.getParent();if(t!==void 0){if(i.isVariableDeclaration(t)||i.isPropertyAssignment(t)||i.isPropertySignature(t))return y(t);if(i.isBinaryExpression(t)&&t.getOperatorToken().getKind()===d.EqualsToken)return t.getLeft().getText()}},nu=(e,t,s)=>kr(e)?!tu(s)&&Lr(su(t)):!0,ru=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(d.BinaryExpression),...e.getDescendantsOfKind(d.StringLiteral),...e.getDescendantsOfKind(d.NoSubstitutionTemplateLiteral)],r=new Set;for(const o of n){if(Jd(o))continue;const a=Pe(o);if(a===void 0)continue;const c=Rr(a);if(c===void 0||!nu(c,o,t))continue;const l=o.getStartLineNumber(),u=`${String(l)}:${c}`;r.has(u)||(r.add(u),s.push({file:t,kind:c,line:l,preview:Fr(a)}))}return s},iu=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ru(r,P(t,n)))}return s},ou=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?q(s):void 0;if(!n)return[];const r=[];for(const o of e.getDescendantsOfKind(d.CallExpression)){const a=Os(o);if(a===void 0)continue;const c=N(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),u=!l&&B(c);!l&&!u||r.push({exportName:e.getName(),file:t,fromArgs:u,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:n.visibility})}return r},au=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),o=P(t,n);for(const a of r.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...ou(c,o))}return s},cu=new Set(["query","unsafe"]),lu=e=>{if(!i.isPropertyAccessExpression(e)||!cu.has(e.getName()))return!1;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return i.isIdentifier(s)&&s.getText()==="ctx"},du=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),uu=(e,t)=>{if(!lu(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!du(s)))return{file:t,line:s.getStartLineNumber(),scope:h(e)}},fu=(e,t)=>w(e,t,uu),pu=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],gu=e=>{for(const[t,s]of pu)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},mu=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const o of r.getImportDeclarations()){const a=o.getModuleSpecifierValue(),c=gu(a);c!==void 0&&s.push({file:P(t,n),line:o.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},hu=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),vu=(e,t,s=[])=>{const n=Re(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:hu,requireUnmodifiedReach:!0});return it(n,s)},Eu=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),xu=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Su=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!i.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const r of e.getProperties()){if(i.isSpreadAssignment(r)){n=!0;continue}if(i.isPropertyAssignment(r)){const o=y(r);t.push(o),o==="expiresInSeconds"&&(s=xu(r.getInitializer()));continue}(i.isShorthandPropertyAssignment(r)||i.isMethodDeclaration(r))&&t.push(y(r))}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},yu=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=Eu.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},Au=(e,t)=>{const s=yu(e.getExpression());if(s!==void 0)return{scope:h(e),file:t,line:e.getStartLineNumber(),method:s.method,...Su(e.getArguments()[s.optionsIndex])}},bu=(e,t)=>w(e,t,Au),Nu=(e,t)=>{const s=tr(t.target);return{...s===void 0?{}:{platform:s},analytics:e.analytics||t.dependencies.has("@lunora/bindings"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:t.vectorStoreSupported&&t.vectorIndexCount>0,workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}},Pu=new Set(["delete","hardDelete","patch","replace","restore"]),wu=new Set(["insertMany","insertManyUnsafe","patchWhere"]),Iu=new Set(["delete","deleteMany","hardDelete","insert","insertMany","patch","patchMany","replace","restore","upsert","upsertMany"]),hs=(e,t)=>{const s=e.getNonNullableType().getProperty("__table")?.getTypeAtLocation(t);if(s===void 0)return[];const n=s.isUnion()?s.getUnionTypes():[s],r=n.map(o=>o.getLiteralValue()).filter(o=>typeof o=="string");return r.length===n.length?r:[]},Tu=(e,t)=>{const s=e.getType();if(t==="deleteMany"||t==="patchMany"){const n=s.getArrayElementType();if(n===void 0)return[];const r=t==="patchMany"?n.getProperty("id")?.getTypeAtLocation(e):n;return r===void 0?[]:hs(r,e)}return hs(s,e)},vs="",Cu=(e,t)=>{if(wu.has(e))return{method:e,tables:[t!==void 0&&i.isStringLiteral(t)?t.getLiteralText():vs]};if(Pu.has(e)||e==="deleteMany"||e==="patchMany"){const s=t===void 0?[]:Tu(t,e);return{method:e,tables:s.length===0?[vs]:s}}},Ou=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression();if(M(n))return Cu(s,e.getArguments()[0]);if(Iu.has(s)&&i.isPropertyAccessExpression(n)&&M(n.getExpression()))return{method:s,tables:[n.getName()]}},Ru=(e,t)=>w(e,t,(s,n)=>{const r=Ou(s);if(r===void 0)return;const o=h(s),a=s.getStartLineNumber();return r.tables.map(c=>({file:n,line:a,method:r.method,scope:o,table:c}))}),Fu=(e,t,s)=>({cacheKey:`procedure_arguments_unreadable:${e}:${t}`,categories:["SCHEMA"],description:"Codegen reads an argument record statically. One built at runtime — a factory call, or a property off a value it cannot follow — has no literal to read, so the generated `FunctionReference` carries only the arguments it could see while the runtime validator still enforces all of them.",detail:`\`${t}\` in \`${e}\` (line ${s.toString()}) declares arguments codegen could not read, so its generated type is missing some of them.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:s},name:"procedure_arguments_unreadable",remediation:`Declare the arguments as an object literal, or as a \`const\` object literal the chain names — \`const ${t}Args = { … };\` then \`.input(${t}Args)\`. Both resolve; a record returned by a call does not.`,title:"Procedure arguments are missing from the generated type"}),ku=(e,t)=>{if(t===void 0){const s=e.getArguments()[0];if(s===void 0||!i.isObjectLiteralExpression(s)||F(s,"args")===void 0)return!1}return lt(e,t).opaque},Lu=(e,t)=>{const s=[],n=(r,o)=>{const a=r.getInitializer();if(a===void 0||!i.isCallExpression(a))return;const c=q(a);c!==void 0&&ku(a,c.receiver)&&s.push(Fu(t,o,a.getStartLineNumber()))};for(const r of e.getVariableStatements().filter(o=>o.isExported()))for(const o of r.getDeclarations())n(o,o.getName());return s},Du=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n);r!==void 0&&s.push(...Lu(r,P(t,n)))}return s.toSorted((n,r)=>n.cacheKey.localeCompare(r.cacheKey))},Mu=new Map([["AgentDefinition",{call:"defineAgent({ … })",file:"agents"}],["ContainerDefinition",{call:"defineContainer({ … })",file:"containers"}],["QueueDefinition",{call:"defineQueue({ … })",file:"queues",note:"A dropped queue has no caller to fail — its consumer is simply never wired."}],["RegisteredAction",{call:"action.input({ … }).action(handler)"}],["RegisteredLifecycleHook",{call:"onConnect(handler)",note:"Substitute the hook you called: `onConnect`, `onDisconnect` and `onShardInit` share one type, so codegen cannot tell which you wrote. A dropped hook has no caller to fail — it silently never fires."}],["RegisteredMigration",{call:"defineMigration({ … })",note:"A dropped migration never runs, so `lunora migrate up` reports nothing to do."}],["RegisteredMutation",{call:"mutation.input({ … }).mutation(handler)"}],["RegisteredMutator",{call:"defineMutator({ … })",file:"mutators"}],["RegisteredQuery",{call:"query.input({ … }).query(handler)"}],["RegisteredReactor",{call:"onQueryChange(select, handler)",note:"A dropped reactor has no caller to fail — it silently never runs."}],["RegisteredShape",{call:"defineShape({ … })",file:"shapes"}],["RegisteredStream",{call:"query.input({ … }).stream(handler)"}],["RegisteredWhisperAuthorizer",{call:"onWhisper(handler)",note:"A dropped authorizer has no caller to fail — the whisper topics it was meant to gate silently stay open to every socket on the shard."}],["SubscriptionDefinition",{call:"defineSubscription(topic, { … })",file:"queues",note:"A dropped subscription is never published to — its topic's messages simply never reach it."}],["WorkflowDefinition",{call:"defineWorkflow({ … })",file:"workflows"}]]),Fe=({byName:e,byPath:t},s,n)=>t.has(`${s}:${n}`)||e.has(n),ln=e=>!e.isAny(),ut=e=>{const t=e.getType();if(!ln(t))return;const s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName(),n=s===void 0?void 0:Mu.get(s);return n===void 0||s===void 0?void 0:{...n,typeName:s}},dn=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},un={cause:"codegen recognises a registration only when the initializer is the registering call itself, and this one comes from a factory or an alias",remediation:"A factory that returns a registration cannot be read statically — inline it, or export what the factory builds."},_u=e=>({cause:`codegen reads this kind of registration only from \`lunora/${e}.ts\`, and this is a different module`,remediation:`Move it into \`lunora/${e}.ts\` — the declaration itself is fine.`}),Ku={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."},ft=(e,t,s,n,r)=>{const{call:o,file:a,note:c,typeName:l}=s,u=a!==void 0&&e!==a?a:void 0,g=u===void 0?r:_u(u),f=c===void 0?g.remediation:`${c} ${g.remediation}`;return{cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally the registering call. Written any other way it exists at runtime but never reaches the generated output — `_generated/api.ts` for a procedure, the lifecycle manifest for a hook or reactor — so a caller cannot address it and a hook never fires.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${l}\` but was not registered — ${g.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:l},name:"procedure_not_registered",remediation:u===void 0?`Assign the registration directly: \`export const ${t} = ${o};\`. ${f}`:f,title:"Procedure exists at runtime but is missing from the generated API"}},zu=(e,t,s)=>{const n=[];for(const r of e.getVariableStatements().filter(o=>o.isExported()))for(const o of r.getDeclarations()){const a=o.getName();if(Fe(s,t,a)||!dn(o))continue;const c=ut(o);c!==void 0&&n.push(ft(t,a,c,o.getStartLineNumber(),un))}return n},$u=(e,t,s)=>{if(Fe(s,t,"default"))return[];const n=[];for(const r of e.getExportAssignments().filter(o=>!o.isExportEquals())){const o=ut(r.getExpression());o!==void 0&&n.push(ft(t,"default",o,r.getStartLineNumber(),un))}return n},Bu=(e,t,s)=>{const n=[];for(const r of e.getExportDeclarations().filter(o=>o.getModuleSpecifier()===void 0))for(const o of r.getNamedExports()){const a=o.getAliasNode()?.getText()??o.getName();if(Fe(s,t,a))continue;const c=o.getLocalTargetDeclarations().find(u=>i.isVariableDeclaration(u));if(c===void 0||!dn(c))continue;const l=ut(c);l!==void 0&&n.push(ft(t,a,l,o.getStartLineNumber(),Ku))}return n},Uu=(e,t,s)=>[...zu(e,t,s),...$u(e,t,s),...Bu(e,t,s)],Vu=(e,t,s)=>e.getVariableStatements().filter(n=>n.isExported()).flatMap(n=>n.getDeclarations()).filter(n=>Fe(s,t,n.getName())).filter(n=>{const r=n.getInitializer();return r!==void 0&&i.isCallExpression(r)&&i.isPropertyAccessExpression(r.getExpression())}).map(n=>({declaration:n,exportName:n.getName(),relativePath:t})),ju=({exportName:e,relativePath:t})=>({cacheKey:"procedure_type_check_unavailable",categories:["SCHEMA"],description:"Codegen cross-checks every export in `lunora/` against its TYPE to catch a procedure the syntactic scan dropped — a factory-assigned export, an alias, a separate `export { … }`. That check needs the type checker to resolve `@lunora/server`; when it cannot, the check reports nothing regardless of what the code does.",detail:`Type resolution for \`lunora/\` is unavailable — the registered procedure \`${e}\` in \`${t}\` types as \`any\`, as does every other one — so codegen cannot tell you when an export is dropped from \`_generated/api.ts\`. A dropped procedure will surface as \`Property '<name>' does not exist\` at its call site instead.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e,filePath:t},name:"procedure_type_check_unavailable",remediation:`Check what codegen sees: \`${e}\` should have a procedure type, not \`any\`. It needs a \`tsconfig.json\` at or above \`lunora/\` — the one codegen finds walking up from there, which is not necessarily the one your editor uses — resolving \`lunorash\` / \`@lunora/server\` to declarations that exist on disk (a workspace dependency has to be built first).`,title:"Codegen cannot type-check `lunora/`, so dropped procedures go unreported"}),qu=(e,t,s)=>{const n=[],r=[];for(const a of E(t)){const c=e.getSourceFile(a);if(c===void 0)continue;const l=P(t,a);n.push(...Uu(c,l,s)),r.push(...Vu(c,l,s))}const[o]=r;return o!==void 0&&r.every(({declaration:a})=>!ln(a.getType()))&&n.push(ju(o)),n.toSorted((a,c)=>a.cacheKey.localeCompare(c.cacheKey))},Wu=new Set(["when","where"]),Qe=new Set(["definePolicy","defineShape"]),Hu=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const n=t.getName();return Qe.has(n)?n:void 0}if(!i.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(n)){const r=n.getNameNode().getText();return Qe.has(r)?r:void 0}const s=t.getText();return Qe.has(s)?s:void 0},Gu=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,fn=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===d.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Gu(e))return"empty-object";if(i.isParenthesizedExpression(e))return fn(e.getExpression())}},pt=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Yu=e=>e.getDescendantsOfKind(d.ReturnStatement).filter(t=>pt(t)===e),pn=e=>e.getDescendantsOfKind(d.ConditionalExpression).filter(t=>pt(t)===e),Qu=e=>{const t=Yu(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(d.IfStatement)!==void 0)||pn(e).length>0},Xu=e=>e.getDescendantsOfKind(d.IfStatement).filter(t=>pt(t)===e),nt=e=>e.getKind()===d.NullKeyword||e.getKind()===d.FalseKeyword||i.isIdentifier(e)&&e.getText()==="undefined"?!0:i.isNumericLiteral(e)?e.getLiteralValue()===0:i.isStringLiteral(e)&&e.getLiteralValue()==="",Ju=(e,t)=>nt(e)||nt(t),Zu=new Map([[d.EqualsEqualsEqualsToken,"positive"],[d.EqualsEqualsToken,"positive"],[d.ExclamationEqualsEqualsToken,"negative"],[d.ExclamationEqualsToken,"negative"]]),Es=e=>!nt(e)&&(i.isLiteralExpression(e)||e.getKind()===d.TrueKeyword),ef=(e,t,s)=>{const n=Zu.get(e);if(n!==void 0)return Ju(t,s)?n==="positive"?"negative":"positive":Es(t)||Es(s)?void 0:n},oe=e=>{if(i.isParenthesizedExpression(e))return oe(e.getExpression());if(i.isPrefixUnaryExpression(e)&&e.getOperatorToken()===d.ExclamationToken)return"negative";if(i.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=ef(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===d.AmpersandAmpersandToken||t===d.BarBarToken){const n=oe(e.getLeft()),r=oe(e.getRight());return n===r?n:"indeterminate"}}return i.isIdentifier(e)||i.isPropertyAccessExpression(e)||i.isElementAccessExpression(e)||i.isCallExpression(e)?"positive":"indeterminate"},xs=e=>{if(e!==void 0){if(i.isReturnStatement(e))return e;if(i.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&i.isReturnStatement(t)?t:void 0}}},tf=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(d.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},sf=e=>i.isReturnStatement(e)?e.getExpression()??e:e,nf=e=>{const t=[];for(const s of pn(e)){const n=oe(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of Xu(e)){const n=oe(s.getExpression());if(n==="indeterminate")continue;const r=n==="negative"?xs(s.getThenStatement()):xs(s.getElseStatement())??tf(s);r!==void 0&&t.push(sf(r))}return t},rf=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},of=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!i.isObjectLiteralExpression(n))return[];const r=[];for(const o of n.getProperties()){if(!i.isPropertyAssignment(o)||!Wu.has(y(o)))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Qu(a))for(const c of nf(a)){const l=fn(c);l!==void 0&&r.push({exportName:rf(e),file:s,form:l,key:y(o),line:c.getStartLineNumber(),owner:t})}}return r},af=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(d.CallExpression)){const r=Hu(n);r!==void 0&&s.push(...of(n,r,t))}return s},cf=(e,t)=>{const s=[];for(const n of E(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...af(r,P(t,n)))}return s},lf=new Set(["query","upsert","upsertNow"]),df=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(lf.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},uf=(e,t)=>{const s=df(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const r=N(n,"namespace");if(!(!r||!B(r)||G(r)))return{scope:h(e),file:t,line:e.getStartLineNumber(),method:s}},ff=(e,t)=>w(e,t,uf),pf=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="workflows":i.isIdentifier(s)&&s.getText()==="workflows"},gf=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},mf=(e,t)=>w(e,t,(s,n)=>pf(s)?{file:n,line:s.getStartLineNumber(),scope:h(s),workflow:gf(s)}:void 0),hf=".lunora-schema.json",rt=(e,t)=>{T(e)&&As(e,"utf8")===t||Nn(e,t,"utf8")},vf=(e,t)=>{if(t===""){Pn(e,{force:!0});return}rt(e,t)},Ef=e=>{const t=S(e,"package.json");if(T(t))try{const s=JSON.parse(As(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},xf=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Sf=e=>{let t=T(e)?e:Se(e);for(;t&&t!==Se(t);){const s=S(t,"tsconfig.json");if(T(s))return s;t=Se(t)}},Ss=e=>e.replaceAll("\\","/"),yf=(e,t,s)=>{if(s&&e.length>0){const o=e.map(a=>`"${a.exportName}"`).join(", ");throw new j("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${o}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const o of t.columns){const a=n.get(o.table)??[];a.push(o.column),n.set(o.table,a)}const r=t.columns.length>0;for(const o of e){if(o.table===void 0){if(r)throw new j("MASK_UNSUPPORTED",`defineShape "${o.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${o.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(o.table);if(a===void 0)continue;const c=a.map(l=>`"${l}"`).join(", ");throw new j("MASK_UNSUPPORTED",`defineShape "${o.exportName}" replicates table "${o.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},we=(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)},ys=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,Af=8,bf=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:r,migrations:o,project:a,shapes:c,usesSandbox:l,useUmbrella:u,workflows:g}=e,f=()=>fr(()=>{const b=pr(a,r),O=Ar(a,r);return{functions:b,httpRoutes:gr(a,r),mutators:O}});let{erased:m,value:{functions:x,httpRoutes:_,mutators:K}}=f();Ut([...x,...K].map(b=>b.filePath)),Ut(_.filter(b=>b.stream).map(b=>b.filePath),"http-stream");for(let b=1;;b+=1){const O=jr({agents:t,functions:x,httpRoutes:_,mutators:K,useUmbrella:u,workflows:g}),U=ti({agents:t,functions:x,migrations:o,mutators:K,shapes:c,useUmbrella:u,usesSandbox:l});if(b>=Af||ys(a,s,O)&&ys(a,n,U))return{apiContent:O,erased:m,functions:x,functionsContent:U,httpRoutes:_,mutators:K};we(a,s,O),we(a,n,U),{erased:m,value:{functions:x,httpRoutes:_,mutators:K}}=f()}},Nf=e=>{const t=Sf(e);return t?new Kt({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Kt({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Dp=(e,t)=>{const s=E(t),n=S(t,"schema.ts");T(n)&&s.push(n);for(const c of s){const l=e.getSourceFile(c);l===void 0?e.addSourceFileAtPath(c):l.refreshFromFileSystemSync()}const r=new Set(s.map(c=>Ss(c))),o=Ss(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!r.has(l)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const l=c.getFilePath();if(!(l===o||l.startsWith(a)||l.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},Mp=e=>{const t=xf(),s=t?Be.now():0,n=S(e.projectRoot,e.lunoraDirectory??"lunora"),r=S(n,"schema.ts");if(!T(r))throw new j("INTERNAL",`schema.ts not found at ${r}`);const o=e.project??Nf(n);ir(za);const a=Or(o,r,e.projectRoot),{agents:c,capabilities:l,containers:u,crons:g,dataModelContent:f,dependencies:m,entryCronTriggers:x,env:_,featureUsage:K,hasFlags:b,hasNotify:O,identity:U,platformGate:W,queues:R,serverContent:X,services:se,storageRulesMetadata:ne,topics:J,usesSandbox:fe,useUmbrella:V,workflows:k}=Yi({lunoraDirectory:n,project:o,projectRoot:e.projectRoot,schema:a,target:e.target});bc(a,a.jurisdiction===void 0?void 0:yc(o,n)),Si(a,K.artifacts);const L=S(n,"_generated"),C=S(L,"dataModel.ts"),gn=S(L,"server.ts"),mn=S(L,"api.ts"),hn=S(L,"functions.ts");we(o,C,f),we(o,gn,X);const pe=Er(o,n),Z=Dr(o,n),{apiContent:gt,erased:vn,functions:H,functionsContent:mt,httpRoutes:ke,mutators:ge}=bf({agents:c,apiPath:mn,generatedFunctionsPath:hn,lunoraDirectory:n,migrations:pe,project:o,shapes:Z,useUmbrella:V,usesSandbox:fe,workflows:k}),ht=On(o,n),Le=Rn(ht,a,[...H,...ke].map(p=>p.filePath)),me=ht.length>0,Y=e.lint===!1&&!me?void 0:{inserts:hr(o,n),queries:wr(o,n),tableWrites:Ru(o,n),workflowCalls:mf(o,n)},he=e.lint===!1||Y===void 0?void 0:Tn({adminRoutes:no(o,n),aiRawRuns:fo(o,n),aiToolSideEffects:Ao(o,n),argumentDerivedFetches:Po(o,n),argumentValidators:Do(o,n),authApiCalls:or(o,n),authConfigs:qo(o,n),browserUrlAccesses:Yo(o,n),configCalls:ca(o,n),containerKeyAccesses:da(o,n),containerOverrides:ha(o,n),containers:u,exportSinks:Sa(o,n),staleMigrationImports:mu(o,n),failOpenGuards:Pa(o,n),flagReads:La(o,n),flagSecurityDefaults:Ka(o,n),geoIndexUsages:Ua(o,n),httpActionGuards:ec(o,n),httpHeaderWrites:dc(o,n),hyperdriveCalls:mr(o,n),identityClaimReads:hc(o,n),imageDeliveryUrlAccesses:Ec(o,n),inserts:Y.inserts,kvKeyAccesses:Pc(o,n,H),mailRecipientAccesses:Oc(o,n),maskProcedures:vr(o,n),maskStrategies:Kc(o,n),mutatorWrites:jc(o,n),nondeterministicCalls:br(o,n),normalizeIdAuthorizations:ol(o,n),notifyCalls:Pr(o,n),notifyConfig:Nr(o,n),mutators:ge,ownerFieldWrites:Rl(o,n,H,ge),unrestrictedWhereBranches:cf(o,n),paymentWebhooks:zl(o,n),privilegedDispatches:Ql(o,n),procedureProtections:Ld(o,n),queries:Y.queries,queues:R,r2sqlCalls:Ir(o,n),ratelimitKeySelectors:Bd(o,n),rawRowReturns:Gd(o,n),relationLoads:Xd(o,n),rlsProcedures:Tr(o,n),schema:a,secretLiterals:iu(o,n),modules:Le,shapes:Z,softDeleteReads:au(o,n),sqlInterpolations:fu(o,n),storageKeyAccesses:vu(o,n,H),storageUploads:bu(o,n),tableWrites:Y.tableWrites,vectorNamespaceAccesses:ff(o,n),workflowCalls:Y.workflowCalls,workflows:k,wranglerVariables:e.wranglerVariables}),vt=he===void 0?[]:ni(e.projectRoot,[...wn(he,{source:"static"}),...qu(o,n,{byName:new Set([...k,...R,...c,...u].map(p=>p.exportName)),byPath:new Set([...H,...ge,...Z,...pe].map(p=>`${p.filePath}:${p.exportName}`))}),...Du(o,n),...ur(vn,n)]),En=Cr(o,n),Et=Dc(o,n);yf(Z,Et,kc(o,n));const xn=b?Ca(o,n):[],De=W.signals.vectorStore!==!1,re=Nu(K,{containerCount:u.length,cronCount:g.length,dependencies:m,hasPaymentTables:Ll(a.tables),queueCount:R.length,storageColumnCount:Object.keys(ks(a)).length,storageRuleCount:ne.rules.length,vectorIndexCount:a.vectorIndexes.length,target:Fs(e.projectRoot,e.target),vectorStoreSupported:De,workflowCount:k.length}),xt=t?Be.now():0,Me=Br(a,pe.map(p=>p.id)),St=sr({advisories:vt.filter(p=>p.name!=="procedure_type_check_unavailable"),advisorProcedures:he?.procedureProtections??[],agents:c,capabilities:l,containers:u,env:_,flagKeys:xn,hasFlags:b,hasNotify:O,hasVectors:De,maskMetadata:Et,mutators:ge,queues:R,rlsMetadata:En,schema:a,schemaSnapshot:Me,shapes:Z,services:se,storageRules:ne,studioFeatures:re,topics:J,useUmbrella:V,workflows:k}),yt=Ur(Z,m.has("@lunora/db"),V),At=qr(u,a.jurisdiction),bt=Wr(k),Nt=Hr(c),Pt=Gr(R),wt=Yr(g),Sn=Qr(re.scheduler),yn=Xr(a.tables,V),It=Jr(a.vectorIndexes),ve=ei(a,V),Tt=Vr(m.has("@lunora/seed")),Ee=e.apiSpec??"openapi",_e=Ee==="openapi"||Ee==="both",Ke=Ee==="openrpc"||Ee==="both",Ct=Mr({capabilities:l,emailAgents:c.filter(p=>p.onEmail===!0).map(p=>({className:p.className,exportName:p.exportName})),hasAccess:m.has("@lunora/cloudflare-access"),hasAuth:m.has("@lunora/auth"),hasFramework:m.has("@lunora/astro")||m.has("@lunora/svelte")||m.has("@lunora/vue")||T(S(e.projectRoot,"src","worker.ts")),hasGlobal:a.tables.some(p=>bs(p)),hasHyperdriveGlobal:a.tables.some(p=>Ns(p)),hasKvIntrospector:re.kv,hasNotify:O,hasQueue:R.some(p=>p.mode==="push"),hasScheduler:re.scheduler,hasSourcedTables:a.tables.some(p=>p.externalSource!==void 0),hasStorage:re.storage,hasVectors:De,hasWorkflow:k.length>0,identity:U,jurisdiction:a.jurisdiction,jurisdictionPinsAuth:a.jurisdictionPinsAuth===!0,tables:a.tables.map(p=>({name:p.name,shardMode:p.shardMode})),useUmbrella:V,vectorIndexCount:a.vectorIndexes.length,voiceAgents:c.filter(p=>p.voice===!0&&p.voiceBindingName!==void 0).map(p=>({bindingName:p.voiceBindingName,exportName:p.exportName})),wantsArchitecture:me,wantsOpenApi:_e,wantsOpenRpc:Ke}),Ot=Ef(e.projectRoot),Rt=me?Le:[],Ft=_r({functions:H,httpRoutes:ke,modules:Rt,version:Ot}),kt=zr({functions:H,modules:Rt,version:Ot}),Lt=`${JSON.stringify(Ft,void 0,2)}
9
- `,Dt=`${JSON.stringify(kt,void 0,2)}
10
- `,xe=me&&Y!==void 0?Ei({...Y,callEdges:ea(o,n),crons:g,functions:H,httpRoutes:ke,modules:Le,queues:R,schema:a,services:se,topics:J,workflows:k}):void 0,Mt=Kr(Ft),_t=$r(kt),ze=S(n,hf),An=T(ze),$e=[];if(!e.dryRun){T(L)||bn(L,{recursive:!0});const p=(Q,ee)=>{rt(S(L,Q),ee),$e.push(Q)},I=(Q,ee)=>{vf(S(L,Q),ee),ee!==""&&$e.push(Q)};p("app.ts",Ct),p("dataModel.ts",f),p("api.ts",gt),p("server.ts",X),p("functions.ts",mt),p("shard.ts",St),p("crons.ts",wt),p("vectors.ts",It),p("drizzle.global.ts",ve.global),p("drizzle.shard.ts",ve.shard),I("containers.ts",At),I("workflows.ts",bt),I("agents.ts",Nt),I("queues.ts",Pt),I("scheduler.ts",Sn),I("shardRegistry.ts",yn),I("seed.ts",Tt),I("collections.ts",yt),I("openapi.json",_e?Lt:""),I("openapi.ts",_e?Mt:""),I("openrpc.json",Ke?Dt:""),I("openrpc.ts",Ke?_t:""),I("architecture.json",xe===void 0?"":`${JSON.stringify(xe,void 0,2)}
11
- `),I("architecture.ts",xe===void 0?"":xi(xe)),(!An||e.updateSchemaBaseline===!0)&&rt(ze,In(Me))}if(t){const p=Be.now(),I=Math.round(p-s),Q=Math.round(xt-s),ee=Math.round(p-xt);console.error(`@lunora/codegen: codegen took ${I.toString()}ms (discovery ${Q.toString()}ms, emit ${ee.toString()}ms)`)}return{advisories:vt,advisorContext:he,agents:c,containers:u,cronTriggers:[...new Set([...Zr(g),...x])],generated:{agents:Nt,api:gt,app:Ct,collections:yt,containers:At,crons:wt,dataModel:f,drizzleGlobal:ve.global,drizzleShard:ve.shard,functions:mt,openApi:Lt,openApiModule:Mt,openRpc:Dt,openRpcModule:_t,queues:Pt,seed:Tt,server:X,shard:St,vectors:It,workflows:bt},migrations:pe,outputDirectory:L,platformDiagnostics:W.diagnostics,queues:R,schemaSnapshot:Me,schemaSnapshotPath:ze,workflows:k,writtenFiles:$e}};export{hf as SCHEMA_SNAPSHOT_FILENAME,Nf as createCodegenProject,Sf as findTsconfig,Dp as refreshCodegenProject,Mp as runCodegen};
@@ -1 +0,0 @@
1
- import{existsSync as l}from"node:fs";import{join as m}from"node:path";import{SyntaxKind as c,Node as o}from"ts-morph";import{diagnosticAt as u}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as p}from"./module-specifiers-WF8iAydP.mjs";import{p as g}from"./parse-validator-Cs6F8SYG.mjs";import{findObjectProperty as f}from"./listLunoraSourceFiles-DmOftuU4.mjs";const d="shapes.ts",S=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineShape";for(const e of t.getDeclarations())if(o.isImportSpecifier(e))return p(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineShape":!1;return!1},h=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&&p(i.getModuleSpecifierValue())}return!1},x=r=>{if(o.isIdentifier(r))return S(r);if(o.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineShape"&&o.isIdentifier(t)&&h(t)}return!1},b=r=>{const[t]=r.getArguments();if(!t||!o.isObjectLiteralExpression(t))return;const e=f(t,"table");if(!e||!o.isPropertyAssignment(e))return;const i=e.getInitializer();return i&&o.isStringLiteral(i)?i.getLiteralValue():void 0},y=r=>{const[t]=r.getArguments();if(!t||!o.isObjectLiteralExpression(t))return{};const e=f(t,"args");if(!e||!o.isPropertyAssignment(e))return{};const i=e.getInitializer();return!i||!o.isObjectLiteralExpression(i)?{}:g(i)},N=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const i=e.getInitializer();if(i?.getKind()!==c.CallExpression)continue;const s=i,a=s.getExpression();if(!x(a))continue;const n=e.getNameNode();if(!o.isIdentifier(n))throw u(n,"defineShape exports must be plain named exports (no destructuring)");t.push({args:y(s),exportName:n.getText(),filePath:"shapes",table:b(s)})}return t},L=(r,t)=>{const e=m(t,d);if(!l(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),s=N(i);return s.sort((a,n)=>a.exportName.localeCompare(n.exportName)),s};export{d as SHAPES_FILENAME,L as discoverShapes};
@@ -1 +0,0 @@
1
- import{existsSync as k}from"node:fs";import{join as y}from"node:path";import{LunoraError as w}from"@lunora/errors";import{isValidCronExpression as b}from"@lunora/scheduler";import{workflowDefaultName as E,workflowClassName as v}from"@lunora/workflow";import{Node as n,VariableDeclarationKind as S,SyntaxKind as x}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapToCallExpression as L,findObjectProperty as d,stringPropertyFor as P}from"./listLunoraSourceFiles-DmOftuU4.mjs";import{r as $}from"./handler-reference-BjE6kvyl.mjs";const A="workflows.ts",N=new Set(["do","sleep","sleepUntil","waitForEvent"]),W=o=>{const e=o.getSymbol();if(!e)return o.getText()==="defineWorkflow";for(const t of e.getDeclarations())if(n.isImportSpecifier(t))return t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/workflow"?!1:t.getNameNode().getText()==="defineWorkflow";return!1},m=P("workflow"),C=(o,e,t)=>{if(n.isNumericLiteral(o))return o.getLiteralValue();throw c(o,`workflow "${e}": \`${t}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},f=(o,e)=>{const t=d(o,e);return t&&n.isPropertyAssignment(t)?t.getInitializerOrThrow():void 0},g=(o,e,t)=>{if(n.isObjectLiteralExpression(o))return o;throw c(o,`workflow "${e}": \`${t}\` must be an inline object literal — it is deploy configuration codegen writes into wrangler.jsonc`)},D=(o,e)=>{if(!n.isArrayLiteralExpression(o)||o.getElements().length===0)throw c(o,`workflow "${e}": \`schedules\` must be a non-empty inline array of cron expression string literals`);return o.getElements().map(t=>{const r=m(t,e,"schedules[]");if(!b(r))throw c(t,`workflow "${e}": schedule "${r}" is not a valid cron expression`);return r})},I=(o,e)=>{const t={},r=f(o,"schedules");r!==void 0&&(t.schedules=D(r,e));const s=f(o,"limits");if(s!==void 0){const i=f(g(s,e,"limits"),"steps");if(i===void 0)t.limits={};else{const a=C(i,e,"limits.steps");if(!Number.isInteger(a)||a<=0)throw c(i,`workflow "${e}": \`limits.steps\` must be a positive integer (got ${String(a)})`);t.limits={steps:a}}}const l=f(o,"defaultRetention");if(l!==void 0){const i=g(l,e,"defaultRetention"),a={};for(const u of["errorRetention","successRetention"]){const p=f(i,u);p!==void 0&&(a[u]=m(p,e,`defaultRetention.${u}`))}t.defaultRetention=a}return t},O=o=>{const e=o.getExpression();if(!n.isPropertyAccessExpression(e)||!N.has(e.getName()))return!1;const t=e.getExpression();return n.isPropertyAccessExpression(t)&&t.getName()==="step"?!0:n.isIdentifier(t)&&t.getText()==="step"},F=o=>{if(!o)return[];const e=[];for(const t of o.getDescendantsOfKind(x.CallExpression)){if(!O(t))continue;const r=t.getArguments()[0];!r||!(n.isStringLiteral(r)||n.isNoSubstitutionTemplateLiteral(r))||e.push({line:t.getStartLineNumber(),method:t.getExpression().getName(),name:r.getLiteralValue()})}return e},h=o=>{let e=o;for(;e&&(n.isAsExpression(e)||n.isSatisfiesExpression(e)||n.isParenthesizedExpression(e));)e=e.getExpression();return e},T=o=>{const e=h(o);if(e&&n.isObjectLiteralExpression(e))return e;if(!(!e||!n.isIdentifier(e)))for(const t of e.getSymbol()?.getDeclarations()??[]){const s=n.isVariableDeclaration(t)&&t.getVariableStatement()?.getDeclarationKind()===S.Const?h(t.getInitializer()):void 0;if(s&&n.isObjectLiteralExpression(s))return s}},R=(o,e)=>{const t=d(o,"handler"),r=$(t,e);return r!==void 0?r:{body:t!==void 0&&n.isPropertyAssignment(t)?t.getInitializer():t}},j=(o,e,t)=>{const r=T(o.getArguments()[0]);if(!r)throw c(o,`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 s=R(r,t),l={className:v(e),exportName:e,name:E(e),steps:F(s.body),...s.file===void 0?{}:{handlerFile:s.file},...s.site===void 0?{}:{handlerSite:s.site}},i=d(r,"name");return i&&n.isPropertyAssignment(i)&&(l.name=m(i.getInitializerOrThrow(),e,"name")),{...l,...I(r,e)}},K=(o,e)=>{const t=[];for(const r of o.getVariableDeclarations()){if(!r.isExported())continue;const s=L(r.getInitializer());if(!s)continue;const l=s.getExpression();if(!n.isIdentifier(l)||!W(l))continue;const i=r.getNameNode();if(!n.isIdentifier(i))throw c(i,"defineWorkflow exports must be plain named exports (no destructuring)");t.push(j(s,i.getText(),e))}return t},V=o=>{const e=new Map,t=new Map;for(const r of o){const s=e.get(r.name);if(s!==void 0)throw new w("DUPLICATE_WORKFLOW_NAME",`Duplicate workflow name "${r.name}": produced by both "${s}" and "${r.exportName}". Deployed workflow names must be unique across the project.`,{status:500});e.set(r.name,r.exportName);const l=t.get(r.className);if(l!==void 0)throw new w("DUPLICATE_WORKFLOW_CLASS",`Duplicate workflow class "${r.className}": produced by both "${l}" and "${r.exportName}". Workflow export names must yield unique generated class names.`,{status:500});t.set(r.className,r.exportName)}},Q=(o,e)=>{const t=y(e,A);if(!k(t))return[];const r=o.getSourceFile(t)??o.addSourceFileAtPath(t),s=K(r,e);return s.sort((l,i)=>l.exportName.localeCompare(i.exportName)),V(s),s};export{A as WORKFLOWS_FILENAME,Q as discoverWorkflows};
@@ -1 +0,0 @@
1
- import{callSiteCallers as b}from"@lunora/advisor";import{Node as a,SyntaxKind as u,ts as y}from"ts-morph";const m=new WeakMap,S=t=>t.getStatements().flatMap(o=>a.isFunctionDeclaration(o)?[o]:a.isVariableStatement(o)?o.getDeclarations().filter(e=>a.isIdentifier(e.getNameNode())):[]),v=t=>a.isFunctionDeclaration(t)?t.hasExportKeyword()?t.hasDefaultKeyword()?"default":t.getName()??"default":void 0:t.getVariableStatement()?.hasExportKeyword()===!0?t.getName():void 0,k=t=>t.getStatements().flatMap(o=>{if(a.isExportDeclaration(o)&&!o.hasModuleSpecifier()&&!o.isTypeOnly())return o.getNamedExports().map(n=>[n.getNameNode().getText(),n.getAliasNode()?.getText()??n.getName()]);const e=a.isExportAssignment(o)&&!o.isExportEquals()?o.getExpression():void 0;return e!==void 0&&a.isIdentifier(e)?[[e.getText(),"default"]]:[]}),w=(t,o)=>{const e=new Map(o.map(i=>[i.getName(),i])),n=new Map,r=(i,c)=>{if(i===void 0||c===void 0)return;const s=n.get(i.compilerNode);(s===void 0||c<s)&&n.set(i.compilerNode,c)};for(const i of o)r(i,v(i));for(const[i,c]of k(t))r(e.get(i),c);return n},g=(t,o)=>{for(const e of t.getAncestors()){if(a.isExportAssignment(e)&&!e.isExportEquals())return{kind:"export",name:"default"};if((a.isFunctionDeclaration(e)&&a.isSourceFile(e.getParent())||a.isVariableDeclaration(e)&&a.isSourceFile(e.getVariableStatement()?.getParent())&&a.isIdentifier(e.getNameNode()))&&(a.isFunctionDeclaration(e)||a.isVariableDeclaration(e))){const r=o.get(e.compilerNode);return r===void 0?{declaration:e,kind:"helper"}:{kind:"export",name:r}}}return{kind:"untracked"}},E=t=>{for(const o of t.getAncestors()){if(a.isExpressionWithTypeArguments(o)){const e=o.getParent();return!(a.isHeritageClause(e)&&e.getToken()===u.ExtendsKeyword&&(a.isClassDeclaration(e.getParent())||a.isClassExpression(e.getParent())))}if(y.isTypeNode(o.compilerNode))return!0}return!1},N=t=>{const o=t.getParent();return a.isShorthandPropertyAssignment(o)&&o.getNameNode()===t?o.getValueSymbol():t.getSymbol()},V=t=>{const o=N(t);return o?.getValueDeclaration()??o?.getDeclarations()[0]},D=t=>{const o=new Map,e=new Set,n=new Set;for(const r of t){const i=r.getNameNode(),c=i?.getSymbol()?.compilerSymbol;i!==void 0&&c!==void 0&&(o.set(c,r.compilerNode),e.add(i.compilerNode),n.add(i.getText()))}return{bySymbol:o,nameNodes:e,spellings:n}},O=(t,o,e)=>{const{bySymbol:n,nameNodes:r,spellings:i}=D(o),c=new Map;for(const s of t.getDescendantsOfKind(u.Identifier)){if(!i.has(s.getText())||r.has(s.compilerNode)||E(s))continue;const l=N(s)?.compilerSymbol,d=l===void 0?void 0:n.get(l);d!==void 0&&c.set(d,[...c.get(d)??[],g(s,e)])}return c},M=(t,o)=>{const e=new Map(t.map(s=>[s.compilerNode,new Set])),n=new Set,r=s=>(e.get(s)?.size??0)+(n.has(s)?1:0),i=(s,l)=>{const d=r(s),p=e.get(s),f=l.kind==="helper"?l.declaration.compilerNode:void 0;l.kind==="export"&&p?.add(l.name);for(const x of f===void 0?[]:e.get(f)??[])p?.add(x);return(l.kind==="untracked"||f!==void 0&&n.has(f))&&n.add(s),r(s)!==d};let c=!0;for(;c;){c=!1;for(const[s,l]of o)for(const d of l)c=i(s,d)||c}return new Map([...e].map(([s,l])=>[s,{callers:[...l].toSorted((d,p)=>d.localeCompare(p)),untracked:n.has(s)}]))},h=t=>{const o=m.get(t.compilerNode);if(o!==void 0)return o;const e=S(t),n=w(t,e),r=e.filter(c=>!n.has(c.compilerNode)),i={exportNames:n,helperReach:r.length===0?new Map:M(r,O(t,r,n))};return m.set(t.compilerNode,i),i},A=t=>{const o=h(t.getSourceFile()),e=g(t,o.exportNames);switch(e.kind){case"export":return{kind:"export",name:e.name};case"helper":{const n=e.declaration.getName(),r=o.helperReach.get(e.declaration.compilerNode);if(n===void 0||r===void 0)throw new Error(`call-site attribution: helper at ${e.declaration.getSourceFile().getFilePath()} is not indexed`);return{callers:r.callers,kind:"helper",name:n,...r.untracked?{untracked:!0}:{}}}default:return{kind:"module"}}},T=(t,o)=>{const e=b(t).map(r=>o(r));return e.includes("public")?"public":e.length===0||e.includes(void 0)||t.kind==="helper"&&t.untracked===!0?void 0:"internal"},K=(t,o)=>{const e=new Map(o.map(n=>[`${n.filePath}:${n.exportName}`,n.visibility]));return t.map(n=>{const r=T(n.scope,i=>e.get(`${n.file}:${i}`));return r===void 0?n:{...n,visibility:r}})},F=t=>h(t.getSourceFile()).exportNames.get(t.compilerNode);export{A as c,V as d,F as e,N as r,K as w};
@@ -1 +0,0 @@
1
- import{w as a}from"./classify-procedure-call-VzDQHiLB.mjs";const l=s=>a(s,"use","rls");export{l as r};
@@ -1 +0,0 @@
1
- import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as d,lunoraRelativePath as l,handlerOf as f}from"./listLunoraSourceFiles-DmOftuU4.mjs";import{c as u}from"./classify-procedure-call-VzDQHiLB.mjs";const x=e=>{const n=e.getInitializer();if(!n||!s.isCallExpression(n))return;const r=u(n);if(!r||r.kind!=="query"&&r.kind!=="mutation")return;const t=f(n,r.receiver);return t?{exportName:e.getName(),handler:t,kind:r.kind}:void 0},p=(e,n)=>{if(!s.isPropertyAccessExpression(e)||e.getName()!==n)return;const r=e.getExpression();if(!s.isIdentifier(r)||r.getText()!=="ctx")return;const t=e.getParent();return t&&s.isPropertyAccessExpression(t)&&t.getExpression()===e?`ctx.${n}.${t.getName()}`:`ctx.${n}`},m=(e,n,r)=>{const t=[];for(const o of e.handler.getDescendantsOfKind(a.PropertyAccessExpression)){const i=p(o,r);i!==void 0&&t.push({callee:i,exportName:e.exportName,file:n,kind:e.kind,line:o.getStartLineNumber()})}return t},g=(e,n,r)=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const i of o.getDeclarations()){const c=x(i);c&&t.push(...m(c,n,r))}return t},N=(e,n,r)=>{const t=[];for(const o of d(n)){const i=e.getSourceFile(o)??e.addSourceFileAtPath(o);t.push(...g(i,l(n,o),r))}return t};export{N as d};
@@ -1 +0,0 @@
1
- import{d as P}from"./declared-output-Iaar469J.mjs";import{s as b}from"./paths-C-9fwEgQ.mjs";import{findObjectProperty as c,bindingKeyName as A,listLunoraSourceFiles as F,lunoraRelativePath as N}from"./listLunoraSourceFiles-DmOftuU4.mjs";import{u as y,p as O,c as m,r as z}from"./unwrap-handler-return-Bnx99voQ.mjs";import{b as d,c as C}from"./classify-procedure-call-VzDQHiLB.mjs";import{Node as n,SyntaxKind as S}from"ts-morph";import{r as h,p as x,a as L}from"./parse-validator-Cs6F8SYG.mjs";const k=i=>{const t=i.getArguments()[0];if(!t||!n.isObjectLiteralExpression(t))return"unknown";const e=c(t,"handler");if(!e||!n.isPropertyAssignment(e))return"unknown";const r=e.getInitializer();return!r||!(n.isArrowFunction(r)||n.isFunctionExpression(r))?"unknown":y(r)},I=i=>{const t=i.getArguments()[0];return!t||!(n.isArrowFunction(t)||n.isFunctionExpression(t))?"unknown":y(t)},T=i=>{let t={};for(const e of d(i)){if(e.name!=="input")continue;const r=e.call.getArguments()[0],s=r!==void 0&&n.isExpression(r)?h(r):void 0;s!==void 0&&(t={...x(s),...t})}return t},V=i=>{const t=d(i).find(r=>r.name==="output");if(!t)return;const e=t.call.getArguments()[0];return e&&n.isExpression(e)?O(t.call,()=>L(e)):void 0},p=(i,t)=>{const e=c(i,t);if(e===void 0||!n.isPropertyAssignment(e))return;const r=e.getInitializer();return r!==void 0&&n.isStringLiteral(r)?r.getLiteralValue():void 0},v=(i,t)=>{const e=c(i,t);if(e===void 0||!n.isPropertyAssignment(e))return;const r=e.getInitializer();return r!==void 0&&n.isNumericLiteral(r)?r.getLiteralValue():void 0},w=i=>{const t=c(i,"cache");if(t===void 0||!n.isPropertyAssignment(t))return;const e=t.getInitializer();if(e===void 0||!n.isObjectLiteralExpression(e))return;const r=p(e,"scope"),s=v(e,"maxAge"),o=v(e,"staleWhileRevalidate"),a=p(e,"tag"),l=p(e,"vary"),g={...s===void 0?{}:{maxAge:s},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...l===void 0?{}:{vary:l}};return Object.keys(g).length===0?void 0:g},D=i=>{if(i===void 0||!n.isObjectLiteralExpression(i))return{};const t=w(i),e=c(i,"rest");return e!==void 0&&n.isPropertyAssignment(e)?{...t===void 0?{}:{cache:t},rest:e.getInitializer()?.getText()==="true"}:t===void 0?{}:{cache:t}},j=i=>{const t=d(i).find(e=>e.name==="expose");return t?D(t.call.getArguments()[0]):void 0},R=i=>{const t=i.getArguments()[0];if(!t||!n.isObjectLiteralExpression(t))return{};const e=c(t,"args");if(!e||!n.isPropertyAssignment(e))return{};const r=e.getInitializer(),s=r===void 0?void 0:h(r);return s===void 0?{}:x(s)},B=8,u=(i,t=0)=>{if(t>B)return;if(n.isCallExpression(i))return i;if(n.isParenthesizedExpression(i)||n.isAsExpression(i)||n.isSatisfiesExpression(i)||n.isNonNullExpression(i))return u(i.getExpression(),t+1);if(!n.isIdentifier(i)&&!n.isPropertyAccessExpression(i))return;const e=i.getSymbol()?.getValueDeclaration();return e?f(e,t+1):void 0},f=(i,t)=>{if(n.isVariableDeclaration(i)||n.isPropertyAssignment(i)){const e=i.getInitializer();return e?u(e,t):void 0}if(n.isShorthandPropertyAssignment(i)){const e=i.getValueSymbol()?.getValueDeclaration();return e?f(e,t+1):void 0}if(n.isBindingElement(i)){const e=A(i),o=i.getFirstAncestorByKind(S.VariableDeclaration)?.getInitializer()?.getType().getProperty(e)?.getValueDeclaration();return o?f(o,t+1):void 0}},$=i=>{const t=i.getNameNode();if(n.isObjectBindingPattern(t)){const s=[];for(const o of t.getElements()){const a=u(o.getNameNode());a&&s.push([o.getName(),a])}return s}const e=i.getInitializer(),r=e&&(n.isCallExpression(e)?e:u(e));return r?[[i.getName(),r]]:[]},W=i=>{const t=C(i);if(!t)return;const{receiver:e}=t;if(e){const r=j(e),s=m(()=>V(e)),o=m(()=>I(i)),a=P({kind:t.kind,output:s.value});return z(a?s.erased:o.erased),{args:T(e),...r?{expose:r}:{},kind:t.kind,...s.value?{output:s.value}:{},returnType:o.value,visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:R(i),kind:t.kind,returnType:k(i),visibility:t.visibility}},E=(i,t,e)=>{const r=W(i);if(r)return{args:r.args,exportName:t,filePath:e,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},_=(i,t)=>{const e=[];for(const r of i.getExportAssignments()){if(r.isExportEquals())continue;const s=u(r.getExpression()),o=s?E(s,"default",t):void 0;o&&e.push(o)}return e},H=(i,t)=>{const e=[];for(const r of i.getVariableStatements())if(r.isExported())for(const s of r.getDeclarations())for(const[o,a]of $(s)){const l=E(a,o,t);l&&e.push(l)}return e.push(..._(i,t)),e},K=i=>{const t=new Map;for(const e of i){const r=b(e.filePath),s=t.get(r);if(s&&s!==e.filePath)throw Object.assign(new Error(`Namespace collision: "${s}" and "${e.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[s,e.filePath],status:500});t.set(r,e.filePath)}},Y=(i,t)=>{const e=F(t),r=[];for(const s of e){const o=i.getSourceFile(s)??i.addSourceFileAtPath(s),a=N(t,s);r.push(...H(o,a))}return r.sort((s,o)=>`${s.filePath}:${s.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),K(r),r};export{Y as default};
@@ -1 +0,0 @@
1
- import{Node as i}from"ts-morph";import{a as m,p as l}from"./parse-validator-Cs6F8SYG.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./listLunoraSourceFiles-DmOftuU4.mjs";import{u as f}from"./unwrap-handler-return-Bnx99voQ.mjs";const u=new Set(["delete","get","head","options","patch","post","put"]),g=new Set(["body","params","searchParams"]),E=new Set(["handler","stream"]),v=r=>{const e=r.getArguments()[0];if(e&&i.isStringLiteral(e))return e.getLiteralValue()},x=r=>{const e=r.getArguments()[0];return e&&i.isObjectLiteralExpression(e)?l(e):{}},P=r=>{if(!i.isCallExpression(r))return;const e=r.getExpression();if(!i.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const n=e.getExpression();if(!i.isIdentifier(n)||n.getText()!=="httpRoute")return;const s=v(r);return s===void 0?void 0:{method:o.toUpperCase(),path:s}},S=(r,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},n=r.getExpression();if(!i.isPropertyAccessExpression(n))return;let s=n.getExpression();for(;i.isCallExpression(s);){const a=s.getExpression();if(!i.isPropertyAccessExpression(a))break;const c=a.getName();if(u.has(c))break;if(g.has(c)){const p=x(s);o[c]={...p,...o[c]}}else if(c==="output"&&o.output===void 0){const p=s.getArguments()[0];p&&i.isExpression(p)&&(o.output=m(p))}s=a.getExpression()}const t=P(s);if(t)return o.method=t.method,o.path=t.path,o},A=r=>{const e=r.getArguments()[0];return!e||!(i.isArrowFunction(e)||i.isFunctionExpression(e))?"unknown":f(e)},T=(r,e,o,n)=>{const s=e.getName();if(!E.has(s))return;const t=S(r,s);if(!(t?.method===void 0||t.path===void 0))return{body:t.body,exportName:o,filePath:n,method:t.method,params:t.params,path:t.path,searchParams:t.searchParams,stream:t.stream,...t.stream?{chunkType:A(r)}:{},...t.output?{output:t.output}:{}}},b=(r,e)=>{const o=[];for(const n of r.getVariableStatements())if(n.isExported())for(const s of n.getDeclarations()){const t=s.getInitializer();if(!t||!i.isCallExpression(t))continue;const a=t.getExpression();if(!i.isPropertyAccessExpression(a))continue;const c=T(t,a,s.getName(),e);c&&o.push(c)}return o},F=(r,e)=>{const o=d(e),n=[];for(const s of o){const t=r.getSourceFile(s)??r.addSourceFileAtPath(s),a=h(e,s);n.push(...b(t,a))}return n.sort((s,t)=>`${s.method} ${s.path}`.localeCompare(`${t.method} ${t.path}`)||s.filePath.localeCompare(t.filePath)),n};export{F as default};
@@ -1 +0,0 @@
1
- import{d as o}from"./context-property-calls-CtIWno5c.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
@@ -1 +0,0 @@
1
- import{Node as i}from"ts-morph";import{collectCallRows as n,isDatabaseAccessor as a}from"./listLunoraSourceFiles-DmOftuU4.mjs";import{c}from"./attribution-CTEeAmtS.mjs";const l=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="insert")return!1;const r=e.getExpression();return a(r)},g=t=>{if(!i.isIdentifier(t))return;const e=t.getSymbol(),r=e?.getAliasedSymbol()?.getDeclarations()??e?.getDeclarations()??[];for(const s of r)if(i.isVariableDeclaration(s)){const o=s.getInitializer();if(o&&i.isStringLiteral(o))return o.getLiteralText()}},f=t=>{const e=t.getArguments()[0];return e?i.isStringLiteral(e)?e.getLiteralText():g(e)??"":""},b=(t,e)=>n(t,e,(r,s)=>l(r)?{file:s,line:r.getStartLineNumber(),scope:c(r),table:f(r)}:void 0);export{b as default};
@@ -1 +0,0 @@
1
- import"./listLunoraSourceFiles-DmOftuU4.mjs";import"./classify-procedure-call-VzDQHiLB.mjs";import{d as p}from"./index-Bq-b_-7H.mjs";export{p as default};