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

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 (56) hide show
  1. package/dist/index.d.mts +3 -1
  2. package/dist/index.d.ts +3 -1
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/{AGENTS_FILENAME-D0fmyQlq.mjs → AGENTS_FILENAME-pKCBP6Us.mjs} +1 -1
  5. package/dist/packem_shared/CONTAINERS_FILENAME-C0nEQjXL.mjs +1 -0
  6. package/dist/packem_shared/{DEFAULT_TARGET-D5J5j3CW.mjs → DEFAULT_TARGET-Dy9KAvjZ.mjs} +1 -1
  7. package/dist/packem_shared/{FLAGS_FILENAME-C1tAv68t.mjs → FLAGS_FILENAME-DuEbVfug.mjs} +1 -1
  8. package/dist/packem_shared/MUTATORS_FILENAME-Cm-LVbo0.mjs +1 -0
  9. package/dist/packem_shared/{NOTIFY_FILENAME-Dmylk3YO.mjs → NOTIFY_FILENAME-BRewD55T.mjs} +1 -1
  10. package/dist/packem_shared/{OPENRPC_VERSION-LZowDAOS.mjs → OPENRPC_VERSION-C8htLv5J.mjs} +1 -1
  11. package/dist/packem_shared/{QUEUES_FILENAME-CQXsARur.mjs → QUEUES_FILENAME-BUC4MU94.mjs} +1 -1
  12. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DOe1K6eL.mjs +11 -0
  13. package/dist/packem_shared/{SHAPES_FILENAME-CNUAxXo3.mjs → SHAPES_FILENAME-BMT5EVQI.mjs} +1 -1
  14. package/dist/packem_shared/{WORKFLOWS_FILENAME-DrRu8060.mjs → WORKFLOWS_FILENAME-BIjSK96U.mjs} +1 -1
  15. package/dist/packem_shared/attribution-CTEeAmtS.mjs +1 -0
  16. package/dist/packem_shared/{buildOpenApiDocument-DZMRzaEx.mjs → buildOpenApiDocument-BG_b1qiR.mjs} +1 -1
  17. package/dist/packem_shared/{capabilitiesUsedBy-DLv5b8Ss.mjs → capabilitiesUsedBy-D5TtIE8p.mjs} +1 -1
  18. package/dist/packem_shared/chain-ChloHMQt.mjs +1 -0
  19. package/dist/packem_shared/{classify-procedure-call-DcsbRyEV.mjs → classify-procedure-call-VzDQHiLB.mjs} +1 -1
  20. package/dist/packem_shared/{context-property-calls-BClPebao.mjs → context-property-calls-CtIWno5c.mjs} +1 -1
  21. package/dist/packem_shared/{discoverAuthApiCalls-CEL1n0I0.mjs → discoverAuthApiCalls-D6s0QBwd.mjs} +1 -1
  22. package/dist/packem_shared/{discoverCrons-BcrneOpi.mjs → discoverCrons-D2jGNq6i.mjs} +1 -1
  23. package/dist/packem_shared/{discoverFunctions-TvTtRhvv.mjs → discoverFunctions-AcXUQuyo.mjs} +1 -1
  24. package/dist/packem_shared/{discoverHttpRoutes-BdaGy42T.mjs → discoverHttpRoutes-C7qeDpp3.mjs} +1 -1
  25. package/dist/packem_shared/discoverHyperdriveCalls-CeyhQdv3.mjs +1 -0
  26. package/dist/packem_shared/{discoverInserts-B2MLcH9M.mjs → discoverInserts-Db4we2Lt.mjs} +1 -1
  27. package/dist/packem_shared/discoverMaskProcedures-DKS6xOnB.mjs +1 -0
  28. package/dist/packem_shared/{discoverMigrations-jUmsOO70.mjs → discoverMigrations-CyySAw7Z.mjs} +1 -1
  29. package/dist/packem_shared/{discoverNondeterministicCalls-BJzH9mEn.mjs → discoverNondeterministicCalls-Bl_vaQUi.mjs} +1 -1
  30. package/dist/packem_shared/{discoverQueries-B4enrT1h.mjs → discoverQueries-DHtbg9iS.mjs} +1 -1
  31. package/dist/packem_shared/discoverR2sqlCalls-BNKRNkrB.mjs +1 -0
  32. package/dist/packem_shared/{discoverRlsMetadata-DewerjgN.mjs → discoverRlsMetadata-CVqVMNnz.mjs} +1 -1
  33. package/dist/packem_shared/{discoverRlsProcedures-DY5xYy7C.mjs → discoverRlsProcedures-zDOYuzjt.mjs} +1 -1
  34. package/dist/packem_shared/{discoverSandboxUsage-CJPFsjOS.mjs → discoverSandboxUsage-DhE6sfq2.mjs} +1 -1
  35. package/dist/packem_shared/{discoverSchema-DPRQni-9.mjs → discoverSchema-DPghAnQv.mjs} +1 -1
  36. package/dist/packem_shared/{discoverStorageRulesMetadata-DnVGPbZl.mjs → discoverStorageRulesMetadata-BdZT9H9j.mjs} +1 -1
  37. package/dist/packem_shared/{exported-procedure-chains-BVawk4h7.mjs → exported-procedure-chains-gbM1pign.mjs} +1 -1
  38. package/dist/packem_shared/{fingerprintSchemaSources-D5z-pfpY.mjs → fingerprintSchemaSources-DA9sYQDZ.mjs} +1 -1
  39. package/dist/packem_shared/{handler-reference-DLDPO906.mjs → handler-reference-BjE6kvyl.mjs} +1 -1
  40. package/dist/packem_shared/{index-CpnWNNMK.mjs → index-Bq-b_-7H.mjs} +1 -1
  41. package/dist/packem_shared/listLunoraSourceFiles-DmOftuU4.mjs +1 -0
  42. package/dist/packem_shared/{loadProjectConfig-D_pUUrhQ.mjs → loadProjectConfig-CWtWqN3X.mjs} +1 -1
  43. package/dist/packem_shared/{modules-B7lb5-dN.mjs → modules-Dcalu27_.mjs} +1 -1
  44. package/dist/packem_shared/{parse-validator-0q0Uz-Cx.mjs → parse-validator-Cs6F8SYG.mjs} +1 -1
  45. package/dist/packem_shared/{readServiceBindings-B_M_ZvhO.mjs → readServiceBindings-V1rcBYrK.mjs} +1 -1
  46. package/dist/packem_shared/{unwrap-handler-return-DFT18rnR.mjs → unwrap-handler-return-Bnx99voQ.mjs} +1 -1
  47. package/package.json +3 -3
  48. package/dist/packem_shared/CONTAINERS_FILENAME-C2wrJ9hF.mjs +0 -1
  49. package/dist/packem_shared/MUTATORS_FILENAME-CDYDr1iG.mjs +0 -1
  50. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CYrLeST3.mjs +0 -11
  51. package/dist/packem_shared/attribution-DpIyvmtn.mjs +0 -1
  52. package/dist/packem_shared/chain-Bah-gxpx.mjs +0 -1
  53. package/dist/packem_shared/discoverHyperdriveCalls-CDm53WpH.mjs +0 -1
  54. package/dist/packem_shared/discoverMaskProcedures-Cj-dvv0H.mjs +0 -1
  55. package/dist/packem_shared/discoverR2sqlCalls-BgbXtbva.mjs +0 -1
  56. package/dist/packem_shared/listLunoraSourceFiles-jTik1QWu.mjs +0 -1
@@ -1 +1 @@
1
- import{Node as l,SyntaxKind as g}from"ts-morph";import{lunoraRelativePath as L}from"./listLunoraSourceFiles-jTik1QWu.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-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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.257",
3
+ "version": "1.0.0-alpha.259",
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.187",
50
- "@lunora/agent": "1.0.0-alpha.170",
49
+ "@lunora/advisor": "1.0.0-alpha.188",
50
+ "@lunora/agent": "1.0.0-alpha.172",
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 L}from"node:fs";import{join as P}from"node:path";import{containerClassName as T,containerBindingName as A,DURABLE_OBJECT_POLICY_FORBIDDEN_KEYS as j,isManagedImage as I,isCloudflareRegistryDigest as O,normalizeContainerImage as b}from"@lunora/container";import{SyntaxKind as d,Node as o}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{propertyKeyName as y,stringPropertyFor as k,findObjectProperty as p,symbolConstInitializer as C}from"./listLunoraSourceFiles-jTik1QWu.mjs";const D="containers.ts",M=t=>{const e=t.getSymbol();if(!e)return t.getText()==="defineContainer";for(const r of e.getDeclarations())if(o.isImportSpecifier(r))return r.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/container"?!1:r.getNameNode().getText()==="defineContainer";return!1},f=k("container"),h=(t,e,r)=>{if(o.isNumericLiteral(t))return t.getLiteralValue();throw a(t,`container "${e}": \`${r}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},E=(t,e)=>{if(o.isStringLiteral(t)||o.isNoSubstitutionTemplateLiteral(t))return b(t.getLiteralValue());if(o.isObjectLiteralExpression(t)){const r=p(t,"registry");if(r&&o.isPropertyAssignment(r)){const i=r.getInitializerOrThrow();return b({registry:f(i,e,"image.registry")})}const n=p(t,"build");if(n&&o.isPropertyAssignment(n)){const i=n.getInitializerOrThrow();return b({build:f(i,e,"image.build")})}}throw a(t,`container "${e}": \`image\` must be a static string path, { registry: "…" }, or { build: "…" } literal`)},_=new Set(["buildArgs","image","images","instanceType","maxInstances","name","rollout","sandbox","schedulingPolicy"]),F=new Set(["gracePeriodSeconds","stepPercentage"]),v=t=>{let e=t;for(;o.isAsExpression(e)||o.isSatisfiesExpression(e)||o.isTypeAssertion(e)||o.isParenthesizedExpression(e);)e=e.getExpression();return e},B=(t,e)=>{const r=i=>{let s=i;for(;o.isPropertyAccessExpression(s)||o.isElementAccessExpression(s)||o.isParenthesizedExpression(s);)s=s.getExpression();return s===i?void 0:s},n=i=>i!==void 0&&o.isIdentifier(i)&&i.getSymbol()===t;return e.getDescendants().some(i=>{if(o.isBinaryExpression(i)){const s=i.getOperatorToken().getKind();return s>=d.FirstAssignment&&s<=d.LastAssignment&&n(r(i.getLeft()))}if(o.isPrefixUnaryExpression(i)||o.isPostfixUnaryExpression(i)){const s=i.getOperatorToken();return(s===d.PlusPlusToken||s===d.MinusMinusToken)&&n(r(i.getOperand()))}return o.isDeleteExpression(i)?n(r(i.getExpression())):o.isCallExpression(i)&&i.getExpression().getText()==="Object.assign"&&n(i.getArguments()[0])})},V=16,$=(t,e,r,n)=>{let i={name:r,symbol:t},s;for(let l=0;l<V;l+=1){const c=C(i.symbol);if(c===void 0||!o.isExpression(c))return s;if(s=v(c),o.isObjectLiteralExpression(s)&&i.symbol!==void 0&&B(i.symbol,e.getSourceFile()))throw a(e,`${n}: \`${i.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(!o.isIdentifier(s))return s;i={name:s.getText(),symbol:s.getSymbol()}}return s},S=(t,e)=>{const r=v(t);return o.isIdentifier(r)?$(r.getSymbol(),r,r.getText(),e)??r:r},x=t=>{const e=t.getNonNullableType();return(e.isUnion()?e.getUnionTypes():[e]).flatMap(n=>n.getApparentType().getProperties().map(i=>i.getName()))},K=(t,e,r)=>{const n=t.getExpression().getType(),i=e==="every"||n.isAny()||n.isUnknown()?["its keys"]:[...new Set(x(n))].filter(s=>e.has(s)).map(s=>`\`${s}\``);if(i.length>0)throw a(t,`${r}: this spread can set ${i.join(", ")}, which codegen writes into wrangler.jsonc and so must read statically. Spread a module-scope \`const\` object literal, or write the keys inline.`)},R=(t,e,r)=>{const n=y(t),i=o.isShorthandPropertyAssignment(t)?$(t.getValueSymbol(),t,n,r):void 0;if(i!==void 0)return[n,i];if(e==="every"||e.has(n))throw a(t,`${r}: \`${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.`)},m=(t,e,r,n=new Set)=>{const i=[],s=new Set(n).add(t);for(const l of t.getProperties())if(o.isPropertyAssignment(l))i.push([y(l),S(l.getInitializerOrThrow(),r)]);else if(o.isSpreadAssignment(l))i.push(...U(l,e,r,s));else{const c=R(l,e,r);c!==void 0&&i.push(c)}return i},U=(t,e,r,n)=>{const i=S(t.getExpression(),r);if(!o.isObjectLiteralExpression(i))return K(t,e,r),[];if(n.has(i))throw a(t,`${r}: this spread refers back to an object it is part of, so it has no static value.`);return m(i,e,r,n)},z=(t,e)=>{if(!o.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`buildArgs\` must be a static object literal — it is deploy configuration codegen writes into wrangler.jsonc`);const r={};for(const[n,i]of m(t,"every",`container "${e}" buildArgs`))r[n]=f(i,e,`buildArgs.${n}`);return Object.keys(r).length>0?r:void 0},Y=(t,e)=>{if(!o.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`rollout\` must be a static object literal — it is deploy configuration codegen writes into wrangler.jsonc`);const r={};for(const[n,i]of m(t,F,`container "${e}" rollout`))(n==="gracePeriodSeconds"||n==="stepPercentage")&&(r[n]=h(i,e,`rollout.${n}`));return r.gracePeriodSeconds===void 0&&r.stepPercentage===void 0?void 0:r},w=t=>{if(o.isTrueLiteral(t))return!0;if(o.isFalseLiteral(t))return!1},q=t=>{if(o.isStringLiteral(t)||o.isNoSubstitutionTemplateLiteral(t)||o.isNumericLiteral(t))return t.getLiteralValue()},N=(t,e)=>{if(o.isStringLiteral(t))return t.getLiteralValue();if(o.isObjectLiteralExpression(t)){const r={};for(const n of t.getProperties()){if(!o.isPropertyAssignment(n))throw a(n,`container "${e}": \`instanceType\` must be an object of static number literals`);const i=y(n);if(i!=="diskMb"&&i!=="memoryMib"&&i!=="vcpu")throw a(n,`container "${e}": unknown \`instanceType\` field "${i}" — expected vcpu, memoryMib, or diskMb`);r[i]=h(n.getInitializerOrThrow(),e,`instanceType.${i}`)}return r}throw a(t,`container "${e}": \`instanceType\` must be a static string or { vcpu, memoryMib, diskMb } literal`)},H=(t,e)=>{if(!o.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`images\` must be a static object literal — codegen writes it into wrangler.jsonc`);const r={};for(const[n,i]of m(t,"every",`container "${e}" images`)){const s=E(i,e);if(s.kind==="build")throw a(i,`container "${e}": \`images["${n}"]\` cannot be a Railpack { build } source — use a Dockerfile path or a { registry } reference`);if(s.kind==="registry"&&!O(s.reference))throw a(i,`container "${e}": \`images["${n}"].registry\` must be a digest-pinned (@sha256) reference under registry.cloudflare.com — push other registries' images there first`);r[n]=s}return r},J=(t,e)=>{const r=t.findLast(([i])=>i==="schedulingPolicy");if(r===void 0)return;const n=f(r[1],e,"schedulingPolicy");if(n!=="default"&&n!=="durable_object")throw a(r[1],`container "${e}": unknown \`schedulingPolicy\` "${n}" — use "default" or "durable_object"`);return n==="durable_object"?n:void 0},W=(t,e,r,n)=>{if(r!==void 0&&j.includes(t))throw a(e,`container "${n}": \`${t}\` is not supported with schedulingPolicy "durable_object"`);if(r===void 0&&t==="images")throw a(e,`container "${n}": \`images\` needs schedulingPolicy "durable_object"`)},X=(t,e,r,n)=>{const{base:i,policy:s}=r;switch(t){case"buildArgs":{i.buildArgs=z(e,n);break}case"enableInternet":{i.enableInternet=w(e);break}case"image":{r.scheduled||(s.image=E(e,n));break}case"images":{s.images=H(e,n);break}case"instanceType":{i.instanceType=N(e,n);break}case"maxInstances":{s.maxInstances=h(e,n,"maxInstances");break}case"name":{i.name=f(e,n,"name");break}case"rollout":{s.rollout=Y(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`);i.sandbox=l;break}case"sleepAfter":{i.sleepAfter=q(e);break}}},G=(t,e,r)=>{const n=t.findLast(([s])=>s==="image")?.[1];if(n===void 0||!(o.isStringLiteral(n)||o.isNoSubstitutionTemplateLiteral(n)))return;const i=n.getLiteralValue();if(!Object.hasOwn(e??{},i)&&!I(i))throw a(n,`container "${r}": \`image\` "${i}" must name an entry of \`images\` or a Cloudflare-managed "cloudflare/…" image`)},Q=(t,e)=>{const r=t.getArguments()[0];if(!r||!o.isObjectLiteralExpression(r))throw a(t,`container "${e}": defineContainer must be passed an inline object literal`);const n=m(r,_,`container "${e}"`),i=J(n,e),s={base:{bindingName:A(e),className:T(e),exportName:e},policy:{},scheduled:i!==void 0};for(const[u,g]of n)W(u,g,i,e),X(u,g,s,e);const{base:l,policy:c}=s;if(i==="durable_object")return G(n,c.images,e),{...l,...c.images===void 0?{}:{images:c.images},schedulingPolicy:i};if(c.image===void 0)throw a(r,`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}}},Z=t=>{const e=[],r=new Map;for(const n of t.getVariableDeclarations()){if(!n.isExported())continue;const i=n.getInitializer();if(i?.getKind()!==d.CallExpression)continue;const s=i,l=s.getExpression();if(!o.isIdentifier(l)||!M(l))continue;const c=n.getNameNode();if(!o.isIdentifier(c))throw a(c,"defineContainer exports must be plain named exports (no destructuring)");const u=Q(s,c.getText()),g=r.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`);r.set(u.bindingName,u.exportName),e.push(u)}return e},oe=(t,e)=>{const r=P(e,D);if(!L(r))return[];const n=t.getSourceFile(r)??t.addSourceFileAtPath(r),i=Z(n);return i.sort((s,l)=>s.exportName.localeCompare(l.exportName)),i};export{D as CONTAINERS_FILENAME,oe as discoverContainers};
@@ -1 +0,0 @@
1
- import{existsSync as p}from"node:fs";import{join as l}from"node:path";import{Node as o,SyntaxKind as m}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as d}from"./module-specifiers-WF8iAydP.mjs";import{p as x}from"./parse-validator-0q0Uz-Cx.mjs";import{findObjectProperty as c}from"./listLunoraSourceFiles-jTik1QWu.mjs";import{u as M}from"./unwrap-handler-return-DFT18rnR.mjs";const y="mutators.ts",f=d,S=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineMutator";for(const e of t.getDeclarations())if(o.isImportSpecifier(e))return f(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineMutator":!1;return!1},N=r=>{const t=r.getSymbol();if(!t)return!1;for(const e of t.getDeclarations()){if(!o.isNamespaceImport(e))continue;const i=e.getFirstAncestorByKind(m.ImportDeclaration);return i!==void 0&&f(i.getModuleSpecifierValue())}return!1},I=r=>{if(o.isIdentifier(r))return S(r);if(o.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(t)&&N(t)}return!1},b=r=>{const t=r.getArguments()[0];return t&&o.isObjectLiteralExpression(t)?t:void 0},A=r=>{const t=c(r,"args");if(!t||!o.isPropertyAssignment(t))return{};const e=t.getInitializer();return e&&o.isObjectLiteralExpression(e)?x(e):{}},E=r=>{const t=c(r,"server");if(!t||!o.isPropertyAssignment(t))return"unknown";const e=t.getInitializer();return!e||!(o.isArrowFunction(e)||o.isFunctionExpression(e))?"unknown":M(e)},F=r=>{const t=c(r,"owner");if(!t||!o.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&o.isStringLiteral(e)?e.getLiteralValue():void 0},P=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const i=e.getInitializer();if(i?.getKind()!==m.CallExpression)continue;const n=i,a=n.getExpression();if(!I(a))continue;const s=e.getNameNode();if(!o.isIdentifier(s))throw g(s,"defineMutator exports must be plain named exports (no destructuring)");const u=b(n);t.push({args:A(u),exportName:s.getText(),filePath:"mutators",line:n.getStartLineNumber(),owner:F(u),returnType:E(u)})}return t},O=(r,t)=>{const e=l(t,y);if(!p(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),n=P(i);return n.sort((a,s)=>a.exportName.localeCompare(s.exportName)),n};export{y as MUTATORS_FILENAME,O as discoverMutators,I as isDefineMutatorCallee};
@@ -1,11 +0,0 @@
1
- import{existsSync as P,mkdirSync as ln,readFileSync as fs,writeFileSync as un,rmSync as dn}from"node:fs";import{join as h,dirname as me}from"node:path";import{performance as _e}from"node:perf_hooks";import{runAdvisor as fn}from"@lunora/advisor";import{LunoraError as U}from"@lunora/errors";import{SyntaxKind as u,Node as o,VariableDeclarationKind as pn,Project as Ft}from"ts-morph";import{serializeSchemaSnapshot as gn}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{toAdvisorContext as mn}from"./formatAdvisories-DwmUKYuc.mjs";import{readProjectConfigLiterals as hn}from"./loadProjectConfig-D_pUUrhQ.mjs";import{a as kt,d as vn,r as En}from"./modules-B7lb5-dN.mjs";import{QUEUES_FILENAME as xn,discoverQueueDeclarations as Sn}from"./QUEUES_FILENAME-CQXsARur.mjs";import{WORKFLOWS_FILENAME as yn,discoverWorkflows as An}from"./WORKFLOWS_FILENAME-DrRu8060.mjs";import{r as bn}from"./json-data-Chfs2Cz5.mjs";import{s as Ae}from"./paths-C-9fwEgQ.mjs";import{G as Nn}from"./shared-DjUziztz.mjs";import{CAPABILITIES as wn,usedCapabilities as Pn}from"./CAPABILITY_PROBES-DFsutD7g.mjs";import{isD1GlobalTable as ps,isHyperdriveGlobalTable as gs}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as In}from"./AGENTS_FILENAME-D0fmyQlq.mjs";import{discoverContainers as Tn}from"./CONTAINERS_FILENAME-C2wrJ9hF.mjs";import Cn from"./discoverCrons-BcrneOpi.mjs";import{diagnosticAt as ie}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as be}from"./module-specifiers-WF8iAydP.mjs";import{contextPropertiesRead as On,discoverFeatureUsage as Rn}from"./capabilitiesUsedBy-DLv5b8Ss.mjs";import Fn from"./readPackageDependencies-C6h6FZuP.mjs";import{listLunoraSourceFiles as m,propertyKeyName as E,unwrapExpression as ne,listSecurityScanFiles as Ne,objectLiteralFromCallbackBody as ms,propertyInitializer as A,lunoraRelativePath as b,bindingKeyName as we,collectCallRows as N,findObjectProperty as O,collectSecurityCallRows as kn,collectNodeRows as We,RUN_METHODS as hs,functionReferenceSegments as vs,limitNameOf as Es,optionsObjectLiteral as xs,isContextIdentifier as Ve,handlerOf as Ln,isDatabaseAccessor as L,readTargetOf as Ss}from"./listLunoraSourceFiles-jTik1QWu.mjs";import{discoverSandboxUsage as Dn}from"./discoverSandboxUsage-CJPFsjOS.mjs";import{resolveServiceBindings as Mn}from"./readServiceBindings-B_M_ZvhO.mjs";import _n from"./discoverStorageRulesMetadata-DnVGPbZl.mjs";import{a as x,c as j,d as ys,e as Kn}from"./classify-procedure-call-DcsbRyEV.mjs";import{i as $n}from"./ir-DBSvhNa-.mjs";import{gatePlatformFeatures as zn,resolveCodegenTarget as As,readTargetDiagnostics as Un,studioPlatformFor as jn}from"./DEFAULT_TARGET-D5J5j3CW.mjs";import{b as bs,e as Bn}from"./shard-B2AqdAuz.mjs";import qn from"./emitServer-mdlKhXYb.mjs";import{emitDataModel as Wn}from"./emitDataModel-D3WuEZ4b.mjs";import{c as g,w as Ze}from"./attribution-DpIyvmtn.mjs";import{r as Pe,s as Vn}from"./parse-validator-0q0Uz-Cx.mjs";import Hn from"./discoverAuthApiCalls-CEL1n0I0.mjs";import{i as Gn,a as Yn,e as Qn,b as Xn,d as Jn,c as Zn}from"./unwrap-handler-return-DFT18rnR.mjs";import er from"./discoverFunctions-TvTtRhvv.mjs";import tr from"./discoverHttpRoutes-BdaGy42T.mjs";import sr from"./discoverHyperdriveCalls-CDm53WpH.mjs";import nr from"./discoverInserts-B2MLcH9M.mjs";import{m as et,a as Ee,s as Ns,d as rr}from"./index-CpnWNNMK.mjs";import{e as ws}from"./exported-procedure-chains-BVawk4h7.mjs";import or from"./discoverMigrations-jUmsOO70.mjs";import{MUTATORS_FILENAME as ir,isDefineMutatorCallee as ar,discoverMutators as cr}from"./MUTATORS_FILENAME-CDYDr1iG.mjs";import lr from"./discoverNondeterministicCalls-BJzH9mEn.mjs";import{discoverNotifyConfig as ur,discoverNotifyCalls as dr}from"./NOTIFY_FILENAME-Dmylk3YO.mjs";import fr from"./discoverQueries-B4enrT1h.mjs";import pr from"./discoverR2sqlCalls-BgbXtbva.mjs";import gr from"./discoverRlsProcedures-DY5xYy7C.mjs";import mr from"./discoverRlsMetadata-DewerjgN.mjs";import hr from"./discoverSchema-DPRQni-9.mjs";import{secretKindOf as vr,redact as Er,isHeuristicSecretKind as xr,isSecretishName as Sr}from"./redact-Cy14LEnc.mjs";import{discoverShapes as yr}from"./SHAPES_FILENAME-CNUAxXo3.mjs";import{emitApp as Ar}from"./emitApp-0rC4g46B.mjs";import{buildOpenApiDocument as br,emitOpenApiModule as Nr}from"./buildOpenApiDocument-DZMRzaEx.mjs";import{buildOpenRpcDocument as wr,emitOpenRpcModule as Pr}from"./OPENRPC_VERSION-LZowDAOS.mjs";import{buildSchemaSnapshot as Ir}from"./SchemaSnapshotParseError-CPOXlFhI.mjs";import{emitCollections as Tr,emitSeed as Cr,emitApi as Or}from"./emitApi-DdW9RyGG.mjs";import{t as Rr,u as Fr,s as kr,v as Lr}from"./shard-runtime-B8rucwkF.mjs";import{emitCrons as Dr,emitScheduler as Mr,emitShardRegistry as _r,emitVectors as Kr,emitWranglerCronTriggers as $r}from"./emitCrons-BRKXFGFu.mjs";import zr from"./emitDrizzleSchema-Cv0HtLR3.mjs";import Ur from"./emitFunctions-BgNeOZt_.mjs";const Lt={error:"ERROR",info:"INFO",warn:"WARN"},Dt={ERROR:2,INFO:0,WARN:1},jr=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"}),Br=(e,t)=>{const{advisor:s}=hn(e);if(s===void 0||s.minSeverity===void 0&&s.unreadable!==!0)return[...t];const{minSeverity:n}=s,r=n!==void 0&&Object.hasOwn(Lt,n)?Lt[n]:void 0;return r===void 0?[...t,jr(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(i=>Dt[i.level]>=Dt[r])},qr={call:"function",enqueue:"queue",invoke:"service",publish:"topic",schedule:"function"},Ps=xn.replace(/\.ts$/u,""),Wr="crons",Vr=yn.replace(/\.ts$/u,""),J=(e,t)=>`${Ae(e)}:${t}`,Ke=(e,t,s)=>t===""?{reason:`the ${s} is not a string literal`}:{to:`${e}:${t}`},Hr=e=>[...e.callEdges.map(t=>{const s=t.target===void 0?{reason:t.reason??"unreadable target"}:{to:`${qr[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,...Ke("table",t.table,"table name")})),...[...e.inserts,...e.tableWrites].map(t=>({file:t.file,kind:"write",line:t.line,scope:t.scope,...Ke("table",t.table,"written table")})),...e.workflowCalls.map(t=>({file:t.file,kind:"start",line:t.line,scope:t.scope,...Ke("workflow",t.workflow,"workflow name")}))],Gr=e=>e.untracked===!0?"inside a helper only code outside any export calls":"inside a non-exported helper",Yr=e=>{const{scope:t}=e;switch(t.kind){case"export":return[{...e,exportName:t.name}];case"helper":return t.callers.length===0?[{...e,unattributed:Gr(t)}]:t.callers.map(s=>({...e,exportName:s}));default:return[{...e,unattributed:"at module scope"}]}},Qr=e=>Hr(e).flatMap(t=>Yr(t)),Xr=e=>[...e.queues.flatMap(t=>t.topic===void 0?[]:[{file:Ps,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:Wr,from:`cron:${t.name}`,kind:"trigger",line:0,...r===void 0?{reason:"the cron has no target"}:{to:r}}})],Jr=e=>new Map(e.flatMap(t=>t.tables.map(s=>[s,t.name]))),$e=(e,t)=>t===void 0?e:{...e,module:t},Zr=e=>{const t=new Map,s=new Map,n=Jr(e.modules),r=(c,l)=>{s.set(c,[...s.get(c)??[],l])},i=(c,l)=>{t.set(c.id,c),l!==void 0&&r(l,c.id)},a=(c,l)=>{c!==void 0&&r(J(c.file,c.exportName),l)};for(const c of e.functions){const l=J(c.filePath,c.exportName),d=`${Ae(c.filePath)}.${c.exportName}`;i($e({detail:c.kind,id:`function:${l}`,kind:"function",name:d},kt(e.modules,c.filePath)),l)}for(const c of e.httpRoutes){const l=J(c.filePath,c.exportName);i($e({id:`http:${l}`,kind:"http",name:`${c.method} ${c.path}`},kt(e.modules,c.filePath)),l)}for(const c of e.schema.tables)i($e({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"};i({...l,id:`queue:${c.exportName}`,kind:"queue",name:c.exportName},J(Ps,c.exportName)),a(c.handlerSite,`queue:${c.exportName}`)}for(const c of e.topics)i({id:`topic:${c.exportName}`,kind:"topic",name:c.exportName});for(const c of e.workflows)i({id:`workflow:${c.exportName}`,kind:"workflow",name:c.exportName},J(Vr,c.exportName)),a(c.handlerSite,`workflow:${c.exportName}`);for(const c of e.crons)i({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";i({detail:c.entrypoint===void 0?l:`${l} · ${c.entrypoint}`,id:`service:${c.name}`,kind:"service",name:c.worker})}return{nodes:t,sites:s}},eo=e=>e==="default"?"the default export is not a registered function":`"${e}" is not a registered function`,to=(e,t)=>"from"in e?[e.from]:"unattributed"in e?{reason:e.unattributed}:t.get(J(e.file,e.exportName))??{reason:eo(e.exportName)},so=(e,t,s)=>{if("reason"in e)return{reason:e.reason};const n=to(e,t);if("reason"in n)return n;const{to:r}=e;return s.has(r)?{drawn:n.map(i=>({from:i,kind:e.kind,to:r}))}:{reason:`${r} is not declared`}},ze=e=>`${e.from}|${e.kind}|${e.to}`,no=e=>`${e.file}|${String(e.line)}|${e.kind}|${e.reason}`,ro=e=>{const{nodes:t,sites:s}=Zr(e),n=new Map,r=new Map;for(const i of[...Xr(e),...Qr(e)]){const a=so(i,s,t);if("drawn"in a)for(const c of a.drawn)n.set(ze(c),c);else{const c={file:i.file,kind:i.kind,line:i.line,reason:a.reason};r.set(no(c),c)}}return{edges:[...n.values()].toSorted((i,a)=>ze(i).localeCompare(ze(a))),nodes:[...t.values()].toSorted((i,a)=>i.id.localeCompare(a.id)),modules:e.modules.map(i=>({...i.description===void 0?{}:{description:i.description},...i.installed===!0?{installed:!0}:{},...i.ownsFolder===!1?{ownsFolder:!1}:{},name:i.name,tables:[...i.tables]})),unresolved:[...r.values()].toSorted((i,a)=>i.file.localeCompare(a.file)||i.line-a.line),version:1}},oo=e=>`${Nn}export const architecture = ${bn(e,"Record<string, unknown>")};
2
- `,io=(e,t)=>{if(!(!t||e.jurisdiction!=="fedramp"))throw new U("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.')},Mt=(e,t="api")=>{const s=new Map;for(const n of e){const r=Ae(n),i=s.get(r);if(i===void 0){s.set(r,n);continue}if(i!==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 U("INTERNAL",`@lunora/codegen: "${i}" 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})}}},ao=(e,t={})=>{const{hasVectors:s=!0,scheduler:n=!1,storage:r=!1,usage:i}=t,a=[];e.tables.some(c=>ps(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=>gs(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 i===void 0?[]:wn)c.requiredPackage!==void 0&&i?.[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(d=>d.name===c.name)===l)},co=(e,t,s={})=>{if(t===void 0)return;const n=ao(e,s).filter(i=>!t.has(i.name));if(n.length===0)return;const r=n.map(i=>` - ${i.name} — ${i.reason}`).join(`
3
- `);throw new U("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.`)},lo="env.ts",uo=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return be(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},fo=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(u.ImportDeclaration);return n!==void 0&&be(n.getModuleSpecifierValue())}return!1},po=e=>{if(o.isIdentifier(e))return uo(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&o.isIdentifier(t)&&fo(t)}return!1},go=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==u.CallExpression||!po(n.getExpression()))continue;const i=s.getNameNode();if(!o.isIdentifier(i))throw ie(i,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:i.getText()})}return t},mo=(e,t)=>{const s=h(t,lo);if(!P(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),r=go(n);if(r.length!==0){if(r.length>1)throw ie(n,`lunora/env.ts declares ${r.length.toString()} defineEnv() contracts (${r.map(i=>i.exportName).join(", ")}); exactly one is allowed`);return r[0]}},Is="identity.ts",ho=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return be(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},vo=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(u.ImportDeclaration);return n!==void 0&&be(n.getModuleSpecifierValue())}return!1},Eo=e=>{if(o.isIdentifier(e))return ho(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&o.isIdentifier(t)&&vo(t)}return!1},xo=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==u.CallExpression||!Eo(n.getExpression()))continue;const i=s.getNameNode();if(!o.isIdentifier(i))throw ie(i,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:i.getText()})}return t},So=(e,t)=>{const s=h(t,Is);if(!P(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),r=xo(n);if(r.length!==0){if(r.length>1)throw ie(n,`lunora/identity.ts declares ${r.length.toString()} defineIdentity() contracts (${r.map(i=>i.exportName).join(", ")}); exactly one is allowed`);return r[0]}},yo=new Set(["allowedHosts","deniedHosts","interceptHttps"]),Ao=(e,t)=>{const s=ne(t);if(s===void 0||!o.isIdentifier(s))return s;const n=s.getText();return ne(e.getDescendantsOfKind(u.VariableDeclaration).find(r=>r.getName()===n)?.getInitializer())},bo=(e,t)=>e!==void 0&&o.isObjectLiteralExpression(e)&&e.getProperties().some(s=>{if(o.isShorthandPropertyAssignment(s))return t.has(E(s));if(!o.isPropertyAssignment(s)||!t.has(E(s)))return!1;const n=ne(s.getInitializer())?.getText();return n!=="false"&&n!=="undefined"}),No=new Set(["durable"]),wo=new Set(["rollback"]),Po=e=>{const t=e.getExpression();return o.isPropertyAccessExpression(t)?t.getName():t.getText()},Io=new Map([["defineContainer",{keys:yo,signal:"containerEgressPolicy"}],["defineStep",{keys:wo,signal:"workflowRollback"}],["stream",{keys:No,signal:"durableStreams"}]]),To=(e,t)=>{const s=Io.get(Po(t));if(s!==void 0)return t.getArguments().some(n=>bo(Ao(e,n),s.keys))?s.signal:void 0},Co=(e,t)=>{const s={containerEgressPolicy:!1,durableStreams:!1,secrets:!1,workflowRollback:!1};for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.secrets||(s.secrets=On(r).has("secrets"));for(const i of r.getDescendantsOfKind(u.CallExpression)){const a=To(r,i);a!==void 0&&(s[a]=!0)}if(Object.values(s).every(Boolean))break}return s},Oo="createWorker",Ro="extend",_t=e=>e!==void 0&&(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))?e.getLiteralValue():void 0,Kt=e=>{const t=[],s=_t(A(e,"backupCron"));s!==void 0&&t.push(s);const n=A(e,"crons");if(n===void 0||!o.isObjectLiteralExpression(n))return t;for(const r of n.getProperties()){if(!o.isPropertyAssignment(r)&&!o.isMethodDeclaration(r))continue;const i=_t(r.getNameNode());i!==void 0&&t.push(i)}return t},Fo=e=>{const t=x(e.getExpression()),[s]=e.getArguments();if(s===void 0)return[];if(t===Oo)return o.isObjectLiteralExpression(s)?Kt(s):[];if(t!==Ro||!(o.isArrowFunction(s)||o.isFunctionExpression(s)))return[];const n=ms(s.getBody());return n===void 0?[]:Kt(n)},ko=(e,t)=>{const s=[];for(const{filePath:n}of Ne(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const i of r.getDescendantsOfKind(u.CallExpression))s.push(...Fo(i))}return[...new Set(s)]},Ts=e=>{if(e.kind==="id")return e.tableName;if(!(e.kind!=="array"&&e.kind!=="optional"))return e.inner===void 0?void 0:Ts(e.inner)},Lo=e=>{const t=new Set(e.tables.map(s=>s.name));return e.tables.some(s=>Object.values(s.shape).some(n=>{const r=Ts(n);return r!==void 0&&t.has(r)}))},Do=(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 i=s.get(r.name);if(i!==void 0)throw new U("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${i} 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 U("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})}},Mo=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:r}=e,i=So(s,t),a=mo(s,t),c=An(s,t),{queues:l,topics:d}=Sn(s,t),p=Mn(n),v=In(s,t);Do(c,v);const S=Tn(s,t),k=_n(s,t),D=Cn(s,t,c,v),M=ko(s,t),y=Co(s,t),T=Dn(s,t),$=Rn(s,t);$.browser=$.browser||T.usesSandboxBrowser;const B=zn($,As(n,e.target),{agents:v.length>0,commitOrderedTables:r.tables.some(I=>I.commitOrdered===!0),cronTriggers:D.length>0,crossShardFanout:r.tables.some(I=>$n(I)),containerEgressPolicy:y.containerEgressPolicy,containerRuntimeScheduling:S.some(I=>I.schedulingPolicy==="durable_object"),containerSandboxTools:S.some(I=>I.sandbox===!0),durableStreams:y.durableStreams,globalTables:r.tables.some(I=>I.shardMode==="global"),queues:l.length>0,relationGraph:Lo(r),secrets:y.secrets,services:p.length>0,topics:d.length>0,vectorStore:r.vectorIndexes.length>0,workerLoaders:T.usesSandboxLoader,workflowRollback:y.workflowRollback,workflowSchedules:c.some(I=>I.schedules!==void 0)}),C=B.usage,G=Pn(C),Z=B.signals.vectorStore!==!1,ee=B.signals.services===!1?[]:p,Y=Fn(n),ae=Y??new Set,z=ae.has("lunorash");co(r,Y,{hasVectors:Z,scheduler:C.scheduler||D.length>0,storage:C.storage||k.rules.length>0||Object.keys(bs(r)).length>0,usage:C});const R=P(h(t,"flags.ts")),F=P(h(t,"notify.ts"));return{agents:v,capabilities:G,containers:S,crons:D,dataModelContent:Wn(r),declaredDependencies:Y,dependencies:ae,entryCronTriggers:M,env:a,featureUsage:C,hasFlags:R,hasNotify:F,identity:i,platformGate:{...B,diagnostics:[...Un(n,e.target),...B.diagnostics]},queues:l,serverContent:qn({agents:v,capabilities:G,containers:S,env:a,hasVectors:Z,hasFlags:R,hasNotify:F,identity:i,queues:l,schema:r,generatedDirectory:h(t,"_generated"),services:ee,storageRuleBuckets:k.rules.map(I=>I.bucket),topics:d,useUmbrella:z,workflows:c}),services:ee,storageRulesMetadata:k,topics:d,usesSandbox:T.usesSandboxBrowser||T.usesSandboxContainer||T.usesSandboxFs,useUmbrella:z,workflows:c}},Cs=new Set(["delete","get","head","options","patch","post","put"]),_o=new Set(["handler","stream"]),Ko=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,$t=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),$o=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Cs.has(t.getName()))return;const s=t.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!o.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},zo=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||Cs.has(n.getName()))break;s=n.getExpression()}return $o(s)},Uo=e=>{for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression))if($t.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&$t.has(s.getText()))return!0}return!1},jo=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||!_o.has(n.getName()))return;const r=zo(s);if(!r||!Ko.test(r.path))return;const i=s.getArguments()[0],a=i!==void 0&&(o.isArrowFunction(i)||o.isFunctionExpression(i))&&Uo(i);return{exportName:e.getName(),file:t,method:r.method,path:r.path,usesGuard:a}},Bo=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const r of n.getDeclarations()){const i=jo(r,t);i&&s.push(i)}return s},qo=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Bo(r,b(t,n)))}return s},Wo=e=>{const t=e.getText(),s=n=>{const r=n.getNameNode();return o.isIdentifier(r)&&r.getText()===t};for(const n of e.getAncestors())if(!(!o.isArrowFunction(n)&&!o.isFunctionExpression(n)&&!o.isFunctionDeclaration(n)))for(const r of n.getParameters()){const i=r.getDescendantsOfKind(u.BindingElement).find(a=>s(a));if(i!==void 0)return i}},Vo=e=>{let t=e;for(;;){const s=t.getParent();if(!o.isObjectBindingPattern(s))return;const n=s.getParent();if(o.isBindingElement(n)){t=n;continue}return o.isParameterDeclaration(n)?we(t):void 0}},zt=(e,t)=>{const s=e.getParent();if(o.isPropertyAccessExpression(s)&&s.getNameNode()===e||o.isPropertyAssignment(s)&&s.getNameNode()===e)return!1;if(e.getText()===t)return!0;const n=Wo(e);return n!==void 0&&Vo(n)===t},tt=(e,t)=>o.isIdentifier(e)?zt(e,t):e.getDescendantsOfKind(u.Identifier).some(s=>zt(s,t)),Ue=e=>tt(e,"ctx"),Ho=e=>{let t=e;for(;o.isPropertyAccessExpression(t)||o.isElementAccessExpression(t)||o.isNonNullExpression(t);)t=t.getExpression();return o.isIdentifier(t)?t:void 0},He=e=>tt(e,"args"),_=e=>{if(!o.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>o.isArrowFunction(a)||o.isFunctionExpression(a)||o.isFunctionDeclaration(a));if(s===void 0)return;const n=e.getStart();let r,i=-1;for(const a of s.getDescendantsOfKind(u.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<n&&l>i&&(r=c,i=l)}return r},K=e=>{if(He(e))return!0;const t=_(e);return t!==void 0&&He(t)},Go=e=>{if(o.isCallExpression(e)||o.isNewExpression(e))return!1;const t=_(e);return t===void 0||!(o.isCallExpression(t)||o.isNewExpression(t))},W=e=>{if(Ue(e))return!0;const t=_(e);if(t!==void 0&&Ue(t))return!0;const s=t??e;return(o.isIdentifier(s)?[s]:s.getDescendantsOfKind(u.Identifier)).some(r=>{const i=_(r);return i!==void 0&&Ue(i)})},he=(e,t)=>tt(e,t),Yo=(e,t)=>{if(he(e,t))return!0;const s=_(e);if(s!==void 0&&he(s,t))return!0;const n=Ho(e);if(n!==void 0){const r=_(n);return r!==void 0&&he(r,t)}return!1},Qo=e=>!o.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",Xo=(e,t)=>{if(!Qo(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!K(s)||W(s)))return{scope:g(e),file:t,line:e.getStartLineNumber()}},Jo=(e,t)=>N(e,t,Xo),Zo=new Set(["generateText","streamText"]),ei=new Set(["messages","prompt","system"]),ti=[{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"]}],si=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const r of ti)if(r.methods.has(s)&&r.prefixes.some(i=>n===i||n.startsWith(`${i}.`)))return`${n}.${s}`},ni=e=>{for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=si(t);if(s!==void 0)return s}},ri=e=>{const t=new Set,s=e.getFirstAncestor(i=>o.isArrowFunction(i)||o.isFunctionExpression(i)||o.isFunctionDeclaration(i)),[n]=s?.getParameters()??[],r=n?.getNameNode();if(r===void 0||!o.isObjectBindingPattern(r))return t;for(const i of r.getElements()){const a=we(i),c=i.getNameNode();if(a==="args"&&o.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},oi=e=>{if(He(e))return!0;const t=ri(e);return t.size===0?!1:e.getDescendantsOfKind(u.Identifier).some(s=>t.has(s.getText()))},ii=e=>{for(const t of e.getProperties()){if(!o.isPropertyAssignment(t)||!ei.has(E(t)))continue;const s=t.getInitializer();if(s!==void 0&&oi(s))return!0}return!1},ai=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const r=x(n.getExpression());if(r===void 0||!Zo.has(r))continue;const[i]=n.getArguments();if(i===void 0||!o.isObjectLiteralExpression(i))continue;let a;for(const c of i.getDescendantsOfKind(u.CallExpression))if(x(c.getExpression())==="tool"&&(a=ni(c),a!==void 0))break;a!==void 0&&s.push({scope:g(n),file:t,line:n.getStartLineNumber(),method:r,sideEffect:a,userInputDerived:ii(i)})}return s},ci=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ai(r,b(t,n)))}return s},li=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return o.isIdentifier(t)&&t.getText()==="ctx"},ui=(e,t)=>{if(!li(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!K(s)))return{scope:g(e),file:t,line:e.getStartLineNumber()}},di=(e,t)=>N(e,t,ui),st=(e,t=new Set)=>{if(t.has(e))return!0;t.add(e);try{return e.getProperties().some(s=>{if(!o.isSpreadAssignment(s))return!1;const n=Pe(s.getExpression());return n===void 0||st(n,t)})}finally{t.delete(e)}},fi=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=O(t,"args");if(!s)return{objects:[],opaque:!1};if(!o.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer(),r=n===void 0?void 0:Pe(n);return r===void 0?{objects:[],opaque:!0}:{objects:[r],opaque:st(r)}},pi=e=>{const t=[];let s=!1,n=e;for(;o.isCallExpression(n);){const r=n.getExpression();if(!o.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const i=n.getArguments()[0],a=i!==void 0&&o.isExpression(i)?Pe(i):void 0;a===void 0?s=!0:(t.push(a),s||=st(a))}n=r.getExpression()}return{objects:t,opaque:s}},nt=(e,t)=>t?pi(t):fi(e),Os=(e,t)=>{if(t.has(e))return[];t.add(e);try{return e.getProperties().flatMap(s=>{if(o.isSpreadAssignment(s)){const n=Pe(s.getExpression());return n===void 0?[]:Os(n,t)}return o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)?[E(s)]:[]})}finally{t.delete(e)}},gi=e=>e.flatMap(t=>Os(t,new Set)),mi=new Set(["check","length","max"]),Ge=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(!(!o.isPropertyAccessExpression(t)||t.getExpression().getText()!=="v"))return t.getName()},hi=e=>[e,...e.getDescendants()].filter(t=>Ge(t)!==void 0),vi=e=>{let t=e;for(;;){const s=t.getParent();if(!s||!o.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;const n=s.getParent();if(!n||!o.isCallExpression(n)||n.getExpression()!==s)return!1;if(mi.has(s.getName()))return!0;t=n}},Ei=e=>{const t=[],s=[];for(const n of e)for(const r of n.getProperties()){if(!o.isPropertyAssignment(r))continue;const i=r.getInitializer();if(!i)continue;const a=hi(i),c=E(r);a.some(l=>Ge(l)==="any")?t.push(c):a.some(l=>Ge(l)==="string"&&!vi(l))&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},xi=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=j(s);if(n?.visibility!=="public")return;const{objects:r}=nt(s,n.receiver),{anyArgs:i,unboundedStringArgs:a}=Ei(r);if(!(i.length===0&&a.length===0))return{anyArgs:i,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Si=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const r of n.getDeclarations()){const i=xi(r,t);i&&s.push(i)}return s},yi=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Si(r,b(t,n)))}return s},je=e=>e?.getKind()===u.TrueKeyword,Ai=e=>e?.getKind()===u.FalseKeyword,bi=e=>e!==void 0&&o.isNumericLiteral(e)&&e.getLiteralValue()===0,Ni=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),wi=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isCallExpression(t)&&x(t.getExpression())==="scim"),Pi=e=>e!==void 0&&o.isCallExpression(e)&&Ni.has(x(e.getExpression())??""),Ii=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isStringLiteral(t)&&t.getLiteralText()==="*"),Ti=e=>{const t=A(e,"advanced"),s=A(e,"emailAndPassword"),n=A(e,"session");return{analyzable:!0,disableCsrfCheck:je(A(t,"disableCSRFCheck")),emailPasswordEnabled:je(A(s,"enabled")),requireEmailVerification:je(A(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:wi(A(e,"plugins"))&&Pi(A(e,"database")),secureCookiesDisabled:Ai(A(t,"useSecureCookies")),sessionFreshAgeZero:bi(A(n,"freshAge")),trustedOriginsWildcard:Ii(A(e,"trustedOrigins"))}},Ci=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Oi=(e,t)=>{if(x(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&o.isObjectLiteralExpression(s)&&s.getProperties().some(i=>o.isSpreadAssignment(i)),r=s!==void 0&&o.isObjectLiteralExpression(s)&&!n?Ti(s):Ci();return{scope:g(e),file:t,line:e.getStartLineNumber(),...r}},Ri=(e,t)=>kn(e,t,Oi),Fi=(e,t)=>{if(!o.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},ki=(e,t,s)=>{const n=Fi(e.getExpression(),s);if(n===void 0)return;const r=e.getArguments()[s.argIndex];if(!(!r||!K(r)||W(r))&&!(s.requireUnmodifiedReach===!0&&!Go(r)))return{scope:g(e),file:t,line:e.getStartLineNumber(),method:n}},Ie=(e,t,s)=>N(e,t,(n,r)=>ki(n,r,s)),Li=new Set(["content","pdf","scrape","screenshot"]),Di=(e,t)=>Ie(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Li}),Rs=e=>{const t=vs(e);return t===void 0?void 0:`${Ae(t.slice(0,-1).join("/"))}:${String(t.at(-1))}`},Fs=(e,t)=>{if(!o.isPropertyAccessExpression(e))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getExpression();return o.isPropertyAccessExpression(n)&&n.getName()===t?s.getName():void 0},Mi=e=>{if(!o.isPropertyAccessExpression(e))return!1;const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="scheduler"||o.isIdentifier(t)&&t.getText()==="scheduler"},_i=new Map([["publish",{kind:"publish",surface:"topics"}],["publishBatch",{kind:"publish",surface:"topics"}],["send",{kind:"enqueue",surface:"queues"}],["sendBatch",{kind:"enqueue",surface:"queues"}]]),Ki=(e,t)=>{const s=Rs(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},$i=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=t.getName(),[n,r]=e.getArguments();if(hs.has(s))return Ki(s,n);if((s==="runAfter"||s==="runAt")&&Mi(t)){const c=Rs(r);return c===void 0?{kind:"schedule",reason:"the scheduled function is not a static api.* / internal.* chain"}:{kind:"schedule",target:c}}const i=_i.get(s),a=i===void 0?void 0:Fs(t,i.surface);return i===void 0||a===void 0?void 0:{kind:i.kind,target:a}},Ut=(e,t,s)=>s===void 0?void 0:{...s,file:t,line:e.getStartLineNumber(),scope:g(e)},zi=(e,t)=>[...N(e,t,(s,n)=>Ut(s,n,$i(s))),...We(e,t,u.PropertyAccessExpression,(s,n)=>{const r=Fs(s,"services");return Ut(s,n,r===void 0?void 0:{kind:"invoke",target:r})})],Ui=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),ji=new Set(["RateLimiter"]),Bi=new Set(["extend"]),jt="lunora",qi=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],ks=e=>{const t=[],s=[];let n=!1;for(const r of e.getProperties()){if(o.isSpreadAssignment(r)){n=!0;continue}if(o.isPropertyAssignment(r)){const i=E(r);t.push(i),r.getInitializer()?.getKind()===u.TrueKeyword&&s.push(i);continue}(o.isShorthandPropertyAssignment(r)||o.isMethodDeclaration(r))&&t.push(E(r))}return{analyzable:!n,presentKeys:t,trueKeys:s}},Ye=e=>e&&o.isObjectLiteralExpression(e)?ks(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Wi=e=>{const t=e&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,s=t&&ms(t.getBody());return s?ks(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Vi=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const r=x(n.getExpression());r!==void 0&&(Ui.has(r)?s.push({callee:r,file:t,line:n.getStartLineNumber(),...Ye(n.getArguments()[0])}):Bi.has(r)&&s.push({callee:r,file:t,line:n.getStartLineNumber(),...Wi(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(u.NewExpression)){const r=x(n.getExpression());r===void 0||!ji.has(r)||s.push({callee:r,file:t,line:n.getStartLineNumber(),...Ye(n.getArguments()[0])})}return s},Hi=(e,t)=>{for(const s of qi){const n=h(t,s);if(!P(n))continue;const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),i=[];for(const a of r.getDescendantsOfKind(u.CallExpression))x(a.getExpression())===jt&&i.push({callee:jt,file:s,line:a.getStartLineNumber(),...Ye(a.getArguments()[0])});return i}return[]},Gi=(e,t)=>{const s=[];for(const{displayPath:n,filePath:r}of Ne(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Vi(i,n))}return s.push(...Hi(e,me(t))),s},Bt="ctx.containers.",Yi=e=>{if(!e.startsWith(Bt))return!1;const t=e.slice(Bt.length);return t.length>0&&!t.includes(".")},Qi=(e,t)=>Ie(e,t,{argIndex:0,matchReceiver:Yi,methods:new Set(["get"])}),Xi=new Set(["allow","deny","setAllowed"]),Ji=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return!1;const s=O(t,"enableInternet");return s!==void 0&&o.isPropertyAssignment(s)&&o.isTrueLiteral(s.getInitializerOrThrow())},Zi=(e,t)=>{const s=e.getExpression();if(!(!o.isPropertyAccessExpression(s)||s.getName()!=="start"||!Ji(e)))return{detail:"enableInternet: true",scope:g(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},ea=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||!Xi.has(s.getName()))return;const n=s.getExpression();if(!(!o.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),scope:g(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},ta=(e,t)=>Zi(e,t)??ea(e,t),sa=(e,t)=>N(e,t,ta),na=new Set(["defineExportSink","r2Sink","webhookExportSink"]),ra=e=>{const t=e.getExpression();if(!o.isIdentifier(t))return;const s=t.getText();return na.has(s)?s:void 0},oa=e=>{const t=[],s=[];for(const n of e.getProperties()){if(o.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(o.isPropertyAssignment(n)){const r=E(n);t.push(r);const i=n.getInitializer();i&&o.isStringLiteral(i)&&i.getLiteralText()===""&&s.push(r);continue}(o.isShorthandPropertyAssignment(n)||o.isMethodDeclaration(n)||o.isGetAccessorDeclaration(n))&&t.push(E(n))}return{analyzable:!0,emptyKeys:s,presentKeys:t}},ia=(e,t)=>{const s=[];for(const{displayPath:n,filePath:r}of Ne(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r);for(const a of i.getDescendantsOfKind(u.CallExpression)){const c=ra(a);if(c===void 0)continue;const l=a.getArguments()[0],d=l&&o.isObjectLiteralExpression(l)?oa(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:d.analyzable,emptyKeys:d.emptyKeys,factory:c,file:n,line:a.getStartLineNumber(),presentKeys:d.presentKeys})}}return s},aa=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),ca=new Set(["dbRateLimit","rateLimit"]),la=e=>{const t=xs(e);if(!t)return!1;const s=O(t,"failOpen");return s!==void 0&&o.isPropertyAssignment(s)&&s.getInitializer()?.getKind()===u.TrueKeyword},ua=(e,t)=>{const s=x(e.getExpression());if(s===void 0)return;const n=aa.get(s);if(n!==void 0)return{callee:s,scope:g(e),failOpen:la(e.getArguments()[n]),file:t,limitName:ca.has(s)?Es(e):"",line:e.getStartLineNumber()}},da=(e,t)=>N(e,t,ua),fa=new Set(["boolean","number","object","string"]),pa=e=>{const t=e.getName();if(!fa.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="flags"&&Ve(s.getExpression()))return t;const n=s.getExpression();if(s.getName()==="details"&&o.isPropertyAccessExpression(n)&&n.getName()==="flags"&&Ve(n.getExpression()))return t},ga=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=pa(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(o.isStringLiteral(n)||o.isNoSubstitutionTemplateLiteral(n)))return;const r=n.getLiteralValue();return r.length>0?{key:r,type:s}:void 0},ma=(e,t)=>{const s=new Map;for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const i of r.getDescendantsOfKind(u.CallExpression)){const a=ga(i);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))},ha=e=>{const t=e.getInitializer();if(!t||!o.isCallExpression(t))return;const s=j(t);if(s?.kind!=="query")return;const n=Ln(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},qt=e=>{const t=e.getParent();return t&&o.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},va=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!o.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()}`},Ea=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(u.PropertyAccessExpression)){const r=va(n);r!==void 0&&s.push({callee:r,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},xa=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const r of n.getDeclarations()){const i=ha(r);i&&s.push(...Ea(i,t))}return s},Sa=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...xa(r,b(t,n)))}return s},ya=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Ve(t.getExpression())},Aa=e=>{if(e?.getKind()===u.TrueKeyword)return!0;if(e?.getKind()===u.FalseKeyword)return!1},ba=(e,t)=>{if(!ya(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(o.isStringLiteral(s)||o.isNoSubstitutionTemplateLiteral(s)))return;const r=s.getLiteralValue(),i=Aa(n);if(!(r.length===0||i===void 0))return{defaultValue:i,scope:g(e),file:t,key:r,line:e.getStartLineNumber()}},Na=(e,t)=>N(e,t,ba),wa=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),i=r.getText(e);if(!i||i==="any"||i==="never"||Gn(i))return;const a=e.getSourceFile().getFilePath();if(Yn(r,e,a)){const c=Qn(r,e,a,0,new Set);return c===void 0&&Xn(i),c}return i},Pa=e=>{const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Ia=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},Ta=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),i=b(t,n);for(const a of r.getDescendantsOfKind(u.CallExpression))Pa(a)&&s.push({file:i,indexName:Ia(a),line:a.getStartLineNumber()})}return s},re=e=>e!==void 0&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,Ls=e=>{const t=e.getArguments()[0],s=re(t);if(s!==void 0)return s;if(t===void 0||!o.isObjectLiteralExpression(t))return;const n=O(t,"handler");return n!==void 0&&o.isPropertyAssignment(n)?re(n.getInitializer()):void 0},Ca=new Set(["delete","get","head","options","patch","post","put"]),Oa=new Set(["handler","stream"]),Ra=new Set(["runAction","runMutation"]),Fa=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),oe=(e,t)=>e!==void 0&&o.isIdentifier(e)&&e.getText()===t,Ds=(e,t)=>{if(!(e===void 0||!o.isObjectBindingPattern(e))){for(const s of e.getElements())if(we(s)===t){const r=s.getNameNode();return o.isIdentifier(r)?r.getText():void 0}}},Wt=(e,t)=>{const s=e.getParameters()[0]?.getNameNode();if(s!==void 0)return t?o.isIdentifier(s)?s.getText():void 0:Ds(s,"ctx")},Vt=(e,t)=>{const s=e.getParameters()[t?1:0]?.getNameNode();return t?s!==void 0&&o.isIdentifier(s)?s.getText():void 0:Ds(s,"request")},Ht=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(u.CallExpression);o.isCallExpression(s)&&n.unshift(s);for(const r of n){const i=r.getExpression();if(!o.isPropertyAccessExpression(i))continue;const a=i.getName(),c=i.getExpression();if(Ra.has(a)&&oe(c,t))return a;if(Fa.has(a)&&o.isPropertyAccessExpression(c)&&c.getName()==="db"&&oe(c.getExpression(),t))return`db.${a}`}},Gt=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(u.PropertyAccessExpression))if(n.getName()==="auth"&&oe(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(u.VariableDeclaration)){const r=n.getNameNode();if(!(!o.isObjectBindingPattern(r)||!oe(n.getInitializer(),t))){for(const i of r.getElements())if(we(i)==="auth")return!0}}return!1},ka=/signature|hmac|digest|(?:^|[_-])sig(?:[_-]|$)/i,La=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||s.getName()!=="get"&&s.getName()!=="has")return!1;const n=s.getExpression();return o.isPropertyAccessExpression(n)&&n.getName()==="headers"&&oe(n.getExpression(),t)},Da=e=>[...o.isStringLiteral(e)?[e.getLiteralText()]:[],...e.getDescendantsOfKind(u.StringLiteral).map(t=>t.getLiteralText())],Ms=(e,t)=>{const s=e.getVariableDeclaration(t)?.getInitializer();return s===void 0?[]:Da(s)},Ma=(e,t)=>{const s=e.getText();for(let n=e.getParent();n!==void 0;n=n.getParent()){if(!o.isArrowFunction(n)&&!o.isFunctionExpression(n)||!n.getParameters().some(c=>c.getName()===s))continue;const r=n.getParent();if(!o.isCallExpression(r))return[];const i=r.getExpression();if(!o.isPropertyAccessExpression(i))return[];const a=i.getExpression();return o.isIdentifier(a)?Ms(t,a.getText()):[]}return[]},_a=e=>{const t=e.getArguments()[0];if(t===void 0)return[];if(o.isStringLiteral(t))return[t.getLiteralText()];if(!o.isIdentifier(t))return[];const s=e.getSourceFile(),n=Ms(s,t.getText());return n.length>0?n:Ma(t,s)},Yt=(e,t)=>{if(t===void 0)return!1;const s=e.getBody(),n=s.getDescendantsOfKind(u.CallExpression);return o.isCallExpression(s)&&n.unshift(s),n.some(r=>La(r,t)&&_a(r).some(i=>ka.test(i)))},Ka=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Oa.has(t.getName()))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))return;const r=n.getName();if(Ca.has(r)){const i=n.getExpression();return o.isIdentifier(i)&&i.getText()==="httpRoute"?r.toUpperCase():void 0}s=n.getExpression()}},$a=(e,t)=>{const s=e.getExpression();if(o.isIdentifier(s)&&s.getText()==="httpAction"){const c=re(e.getArguments()[0]),l=c&&Wt(c,!0);if(!c||l===void 0||Yt(c,Vt(c,!0)))return;const d=Ht(c,l);return d===void 0?void 0:{scope:g(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:Gt(c,l),sideEffect:d}}const n=Ka(e);if(n===void 0)return;const r=re(e.getArguments()[0]),i=r&&Wt(r,!1);if(!r||i===void 0||Yt(r,Vt(r,!1)))return;const a=Ht(r,i);return a===void 0?void 0:{scope:g(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:Gt(r,i),sideEffect:a}},za=(e,t)=>N(e,t,$a),Ua=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),ja=new Set(["append","set"]),_s=e=>e!==void 0&&(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",Qt=(e,t)=>(o.isCallExpression(e)?[e,...e.getDescendantsOfKind(u.CallExpression)]:e.getDescendantsOfKind(u.CallExpression)).some(n=>Ua.has(x(n.getExpression())??"")&&he(n,t)),Ba=(e,t)=>{if(Qt(e,t))return!0;const s=_(e);return s!==void 0&&Qt(s,t)},Qe=(e,t)=>Yo(e,t)&&!Ba(e,t),qa=e=>{if(o.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=_(e);return t!==void 0&&o.isNewExpression(t)&&x(t.getExpression())==="Headers"},xe=e=>{if(e===void 0)return;if(o.isObjectLiteralExpression(e))return e;const t=_(e);return t!==void 0&&o.isObjectLiteralExpression(t)?t:void 0},rt=(e,t,s)=>{for(const n of e.getProperties())if(o.isPropertyAssignment(n)){const r=n.getInitializer();r!==void 0&&Qe(r,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:_s(n.getNameNode()),line:r.getStartLineNumber(),via:t})}else if(o.isShorthandPropertyAssignment(n)){const r=n.getNameNode();Qe(r,s.requestName)&&s.rows.push({scope:s.scope,file:s.relativePath,headerName:E(n),line:r.getStartLineNumber(),via:t})}else if(o.isSpreadAssignment(n)){const r=xe(n.getExpression());r!==void 0&&rt(r,t,s)}},Ks=(e,t)=>{const s=xe(e);if(s===void 0)return;const n=O(s,"headers");if(n===void 0||!o.isPropertyAssignment(n))return;const r=xe(n.getInitializer());r!==void 0&&rt(r,"response-init",t)},Wa=(e,t)=>{const s=x(e.getExpression());if(s==="Response")Ks(e.getArguments()[1],t);else if(s==="Headers"){const n=xe(e.getArguments()[0]);n!==void 0&&rt(n,"headers-ctor",t)}},Va=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName(),r=s.getExpression();if(n==="json"&&o.isIdentifier(r)&&r.getText()==="Response"){Ks(e.getArguments()[1],t);return}if(ja.has(n)&&qa(r)){const i=e.getArguments()[1];i!==void 0&&Qe(i,t.requestName)&&t.rows.push({scope:t.scope,file:t.relativePath,headerName:_s(e.getArguments()[0]),line:i.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},Ha=(e,t)=>{for(const s of e.getDescendantsOfKind(u.NewExpression))Wa(s,t);for(const s of e.getDescendantsOfKind(u.CallExpression))Va(s,t)},Ga=(e,t)=>{const s=e.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=re(e.getArguments()[0]);if(n===void 0)return[];const r=n.getParameters()[1];if(r===void 0)return[];const i=r.getNameNode();if(!o.isIdentifier(i))return[];const a=[];return Ha(n,{scope:g(e),relativePath:t,requestName:i.getText(),rows:a}),a},Ya=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(u.CallExpression))s.push(...Ga(n,t));return s},Qa=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ya(r,b(t,n)))}return s},Xa=new Set(["auth","context.auth","ctx.auth"]),Ja="userId",Za=e=>{const t=new Set;for(const s of e.getProperties()){if(o.isSpreadAssignment(s))return;(o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)||o.isMethodDeclaration(s))&&t.add(E(s))}return t},ec=(e,t)=>{const s=h(t,Is);if(!P(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const r of n.getDescendantsOfKind(u.CallExpression)){if(x(r.getExpression())!=="defineIdentity")continue;const[i]=r.getArguments();return i&&o.isObjectLiteralExpression(i)?Za(i):void 0}},Xt=e=>{if(!(e===void 0||!o.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Xa.has(e.getExpression().getText())?e:void 0},tc=e=>{if(o.isPropertyAccessExpression(e)&&Xt(e.getExpression())!==void 0)return e.getName();if(o.isElementAccessExpression(e)&&Xt(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&o.isStringLiteral(t)?t.getLiteralValue():void 0}},Jt=(e,t,s)=>{const n=tc(e);return n===void 0?void 0:{declared:n===Ja||s.has(n),file:t,key:n,line:e.getStartLineNumber(),scope:g(e)}},sc=(e,t)=>{const s=ec(e,t);return s===void 0?[]:[...We(e,t,u.PropertyAccessExpression,(n,r)=>Jt(n,r,s)),...We(e,t,u.ElementAccessExpression,(n,r)=>Jt(n,r,s))]},nc=(e,t)=>{if(x(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=A(s,"key");if(!(!n||!K(n)||W(n)))return{scope:g(e),file:t,line:e.getStartLineNumber()}},rc=(e,t)=>N(e,t,nc),oc=e=>{if(o.isComputedPropertyName(e)){const t=e.getExpression();return o.isStringLiteral(t)||o.isNoSubstitutionTemplateLiteral(t)?t.getLiteralValue():void 0}return o.isStringLiteral(e)?e.getLiteralValue():e.getText()},ic=e=>e.getProperties().some(t=>{if(o.isSpreadAssignment(t))return!0;const s=oc(t.getNameNode());return s===void 0||s==="namespace"}),ac=(e,t)=>{for(const{filePath:s}of Ne(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const r of n.getDescendantsOfKind(u.CallExpression)){const i=r.getExpression(),[a]=r.getArguments();if(!(!o.isPropertyAccessExpression(i)||i.getName()!=="auth"||a===void 0)&&(!o.isObjectLiteralExpression(a)||ic(a)))return r}}},cc="https://lunora.sh/docs/concepts/data-residency#pinning-auth-and-voice",lc=(e,t)=>{if(!(e.jurisdiction===void 0||e.jurisdictionPinsAuth===!0||t===void 0))throw ie(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 (${cc}). 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})},uc=new Set(["delete","get","getRaw","getWithMetadata","put"]),dc=(e,t,s=[])=>{const n=Ie(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.kv"||r.startsWith("ctx.kv."),methods:uc});return Ze(n,s)},fc=new Set(["queue","send"]),Zt=new Set(["bcc","cc","to"]),pc=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!fc.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},gc=e=>o.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(o.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return Zt.has(E(t))&&K(n)&&!W(n)}if(!o.isPropertyAssignment(t)||!Zt.has(E(t)))return!1;const s=t.getInitializer();return s!==void 0&&K(s)&&!W(s)}):!1,mc=(e,t)=>{const s=pc(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!gc(n)))return{scope:g(e),file:t,line:e.getStartLineNumber(),method:s}},hc=(e,t)=>N(e,t,mc),vc=e=>o.isPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?o.isComputedPropertyName(e.getNameNode()):!1,Ec=e=>o.isPropertyAssignment(e)||o.isShorthandPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?vc(e):!0,$s=(e,t=!1)=>{for(const s of e.getProperties()){if(Ec(s))return!0;if(t)continue;if(!o.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!o.isObjectLiteralExpression(n)||$s(n,!0))return!0}return!1},xc=(e,t)=>{for(const s of m(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:r}of ws(n))for(const i of et(r)){const a=i.getArguments()[0];if(a!==void 0&&(!o.isObjectLiteralExpression(a)||$s(a)))return!0}}return!1},Sc=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const r=Ee(n);if(r===void 0||!o.isPropertyAssignment(n))continue;const i=n.getInitializer();if(!(!i||!o.isObjectLiteralExpression(i)))for(const a of i.getProperties()){const c=Ee(a);c!==void 0&&s.push({column:c,strategy:Ns(a),table:r})}}return s},yc=(e,t)=>{const s=new Map;for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:i}of ws(r))for(const a of et(i))for(const c of Sc(a)){const l=`${c.table}\0${c.column}`;s.has(l)||s.set(l,c)}}return{columns:[...s.values()]}},Ac=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!o.isObjectLiteralExpression(n))return[];const r=[];for(const i of n.getProperties()){const a=Ee(i);if(a===void 0||!o.isPropertyAssignment(i))continue;const c=i.getInitializer();if(!(!c||!o.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const d=Ee(l);if(d===void 0)continue;const p=Ns(l);p!=="custom"&&r.push({column:d,exportName:t,file:s,line:l.getStartLineNumber(),strategy:p,table:a})}}return r},bc=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?j(s):void 0;return n?.receiver?et(n.receiver).flatMap(r=>Ac(r,e.getName(),t)):[]},Nc=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),i=b(t,n);for(const a of r.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...bc(c,i))}return s},wc=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return L(s)},Pc=e=>{const t=e.getArguments()[0];if(t===void 0||!o.isObjectLiteralExpression(t))return;const s=O(t,"server");if(s!==void 0)return o.isPropertyAssignment(s)?s.getInitializer():s},Ic=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==u.CallExpression)return;const s=t;return ar(s.getExpression())?s:void 0},Tc=e=>{const t=Ic(e),s=t===void 0?void 0:Pc(t);if(s===void 0)return[];const n=e.getNameNode(),r=o.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(u.CallExpression).filter(i=>wc(i)).map(i=>({exportName:r,file:"lunora/mutators.ts",line:i.getStartLineNumber()}))},Cc=e=>e.getVariableDeclarations().flatMap(t=>Tc(t)),Oc=(e,t)=>{const s=h(t,ir);if(!P(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Cc(n)},Rc=new Set(["delete","get","patch"]),Fc=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),kc=new Set(["auth","identity","session","user"]),Lc=new Set([u.EqualsEqualsEqualsToken,u.EqualsEqualsToken,u.ExclamationEqualsEqualsToken,u.ExclamationEqualsToken]),Dc=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!L(t.getExpression()))return;const s=e.getArguments()[0];return s&&o.isStringLiteral(s)?s.getLiteralText():""},Mc=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(o.isAsExpression(s)||o.isParenthesizedExpression(s)||o.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!o.isVariableDeclaration(s))return;const n=s.getNameNode();return o.isIdentifier(n)?n.getText():void 0},_c=(e,t)=>e.getDescendantsOfKind(u.Identifier).some(s=>s.getText()===t),Kc=e=>o.isThrowStatement(e)||o.isReturnStatement(e)||e.getDescendantsOfKind(u.ThrowStatement).length>0||e.getDescendantsOfKind(u.ReturnStatement).length>0,$c=(e,t)=>e.getDescendantsOfKind(u.IfStatement).some(s=>_c(s.getExpression(),t)&&Kc(s.getThenStatement())),zc=(e,t)=>{for(const s of e.getDescendantsOfKind(u.CallExpression)){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))continue;const r=n.getName();if(!Rc.has(r))continue;const i=n.getExpression();if(!(L(i)||o.isPropertyAccessExpression(i)&&L(i.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&o.isIdentifier(c)&&c.getText()===t)return r}},Uc=e=>{let t=e;for(;o.isPropertyAccessExpression(t)||o.isElementAccessExpression(t)||o.isNonNullExpression(t)||o.isParenthesizedExpression(t)||o.isAsExpression(t)||o.isAwaitExpression(t);)t=t.getExpression();return o.isIdentifier(t)?t.getText():void 0},jc=e=>e.getDescendantsOfKind(u.CallExpression).some(t=>t.getArguments().some(s=>Uc(s)==="ctx")),Bc=e=>e.getDescendantsOfKind(u.BinaryExpression).some(t=>Lc.has(t.getOperatorToken().getKind())?o.isPropertyAccessExpression(t.getLeft())||o.isPropertyAccessExpression(t.getRight()):!1),qc=e=>{for(const t of e.getDescendantsOfKind(u.Identifier))if(Fc.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&s.getText()==="ctx"&&kc.has(t.getName()))return!0}return jc(e)||Bc(e)},Wc=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=j(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const r=Ls(s);if(r===void 0)return[];const i=n.receiver!==void 0&&ys(n.receiver,"use","rls"),a=qc(r),c=new Set,l=[];for(const d of r.getDescendantsOfKind(u.CallExpression)){const p=Dc(d);if(p===void 0)continue;const v=Mc(d);if(v===void 0||c.has(v)||!$c(r,v))continue;const S=zc(r,v);S!==void 0&&(c.add(v),l.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:S,table:p,usesRls:i,visibility:n.visibility}))}return l},Vc=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),i=b(t,n);for(const a of r.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Wc(c,i))}return s},Hc=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Gc=new Set(["insert","insertManyUnsafe","patch","replace"]),Yc=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!Gc.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||s.getName()!=="db")return;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"?t:void 0},Qc=(e,t)=>{if(t!=="insertManyUnsafe")return o.isObjectLiteralExpression(e)?[e]:[];if(!o.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())o.isObjectLiteralExpression(n)&&s.push(n);return s},es=(e,t)=>{if(o.isPropertyAccessExpression(e)){const s=e.getExpression();return o.isIdentifier(s)&&s.getText()==="args"&&e.getName()===t}if(o.isElementAccessExpression(e)){const s=e.getExpression(),n=e.getArgumentExpression();return o.isIdentifier(s)&&s.getText()==="args"&&n!==void 0&&o.isStringLiteral(n)&&n.getLiteralValue()===t}return!1},Xc=e=>{if(!o.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>o.isArrowFunction(a)||o.isFunctionExpression(a)||o.isFunctionDeclaration(a));if(s===void 0)return;for(const a of s.getDescendantsOfKind(u.BinaryExpression)){const c=a.getLeft();if(o.isIdentifier(c)&&c.getText()===t&&a.getOperatorToken().getText().endsWith("="))return}const n=e.getStart();let r,i=-1;for(const a of s.getDescendantsOfKind(u.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getParent();if(!o.isVariableDeclarationList(c)||c.getDeclarationKind()!==pn.Const)continue;const l=a.getInitializer(),d=a.getStart();l!==void 0&&d<n&&d>i&&(r=l,i=d)}return r},Jc=(e,t)=>{if(es(e,t))return!0;const s=Xc(e);return s!==void 0&&es(s,t)},Zc=(e,t,s,n,r)=>{const i=[];for(const a of e.getProperties()){let c,l;if(o.isPropertyAssignment(a)?(c=E(a),l=a.getInitializer()):o.isShorthandPropertyAssignment(a)&&(c=E(a),l=a.getNameNode()),!(c===void 0||l===void 0||!Hc.has(c))&&K(l)&&!W(l)){const d=g(s),p=d.kind==="export"&&r(d.name)===c&&Jc(l,c);i.push({field:c,file:n,line:s.getStartLineNumber(),method:t,scope:d,...p&&{ownerScoped:!0}})}}return i},el=(e,t,s)=>{const n=Yc(e.getExpression());if(n===void 0)return[];const r=e.getArguments()[1];return r?Qc(r,n).flatMap(i=>Zc(i,n,e,t,s)):[]},tl=(e,t,s=[],n=[])=>{const r=new Map(n.map(a=>[`${a.filePath}:${a.exportName}`,a.owner])),i=N(e,t,(a,c)=>el(a,c,l=>r.get(`${c}:${l}`)));return Ze(i,s)},sl=["providerSubscriptionId","state"],nl=["providerEventId","processedAt"],ts=(e,t)=>t.every(s=>s in e.shape),rl=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&ts(t,sl)&&ts(s,nl)},ol=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),il=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,al=e=>{const t=O(e,"webhookToleranceSeconds");return t&&o.isPropertyAssignment(t)?il(t.getInitializer()):void 0},cl=(e,t)=>{const s=x(e.getExpression());if(s===void 0||!ol.has(s))return;const[n]=e.getArguments(),r=n&&o.isObjectLiteralExpression(n)?al(n):void 0;return{callee:s,scope:g(e),file:t,line:e.getStartLineNumber(),...r===void 0?{}:{toleranceSeconds:r}}},ll=(e,t)=>N(e,t,cl),ul=new Map([["defineQueue",0],["defineSubscription",1],["defineWorkflow",0]]),dl=e=>{const t=e.getExpression();return o.isIdentifier(t)?t.getText():void 0},fl=(e,t)=>{const s=e.getArguments()[t];if(!s||!o.isObjectLiteralExpression(s))return;const n=O(s,"handler");if(n===void 0||!o.isPropertyAssignment(n))return;const r=n.getInitializer();if(r&&(o.isArrowFunction(r)||o.isFunctionExpression(r)))return r},zs=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&o.isIdentifier(s)?s.getText():void 0},Us=(e,t)=>e===t||e.startsWith(`${t}.`),js=e=>{const t=e.getDescendantsOfKind(u.PropertyAccessExpression);return o.isPropertyAccessExpression(e)&&t.push(e),t},ss=e=>{const t=e.getParent();return o.isPropertyAccessExpression(t)&&t.getNameNode()===e||o.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(o.isBindingElement(t)&&t.getNameNode()===e)},Bs=e=>{const t=e.getDescendantsOfKind(u.Identifier).filter(s=>ss(s));return o.isIdentifier(e)&&ss(e)&&t.push(e),t},pl=e=>{if(!o.isVariableDeclaration(e))return[];const t=e.getNameNode();return o.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(u.BindingElement).map(s=>s.getName())},gl=e=>{const t=zs(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(u.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const r=n.getInitializer(),i=o.isVariableDeclarationList(r)?r.getDeclarations()[0]?.getNameNode():void 0;i&&o.isIdentifier(i)&&s.push(`${i.getText()}.body`)}return s},ml=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:gl(e),r=new Set,i=a=>js(a).some(c=>n.some(l=>Us(c.getText(),l)))?!0:Bs(a).some(c=>r.has(c.getText()));for(const a of e.getDescendantsOfKind(u.VariableDeclaration)){const c=a.getInitializer();if(c&&i(c))for(const l of pl(a))r.add(l)}return{names:r,prefixes:n}},hl=(e,t)=>js(e).some(s=>t.prefixes.some(n=>Us(s.getText(),n)))?!0:Bs(e).some(s=>t.names.has(s.getText())),vl=e=>{const t=vs(e);return t===void 0?void 0:{exportName:String(t.at(-1)),file:t.slice(0,-1).join("/")}},El=(e,t,s)=>{const n=zs(e,0);if(n===void 0)return[];const r=ml(e,t,n),i=new Set([n,...r.prefixes.filter(c=>c.endsWith(".body")).map(c=>c.slice(0,-5))]),a=[];for(const c of e.getDescendantsOfKind(u.CallExpression)){const l=c.getExpression();if(!o.isPropertyAccessExpression(l)||!hs.has(l.getName())||!i.has(l.getExpression().getText()))continue;const d=c.getArguments()[1];if(!d||!hl(d,r))continue;const p=vl(c.getArguments()[0]);p!==void 0&&a.push({dispatchKind:t,file:s,scope:g(c),line:c.getStartLineNumber(),targetExport:p.exportName,targetFile:p.file})}return a},xl=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const r=dl(n),i=r===void 0?void 0:ul.get(r);if(i===void 0)continue;const a=fl(n,i);a!==void 0&&s.push(...El(a,r==="defineWorkflow"?"workflow":"queue",t))}return s},Sl=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...xl(r,b(t,n)))}return s},ns={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},rs=new Set(["account","credential","member","passkey","session","user"]),yl=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),Al=e=>{const s=yl(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return rs.has(s)||rs.has(n)},bl=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Nl=(e,t)=>{const{objects:s,opaque:n}=nt(e,t);return gi(s).some(r=>bl(r))?!0:n?void 0:!1},wl=e=>{const t=e.getArguments()[0];return!t||!o.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!O(t,"captcha"),usesRateLimit:!!O(t,"rateLimit")}},Pl=e=>{if(o.isCallExpression(e))return e;if(!o.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&o.isCallExpression(s)?s:void 0},ve={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Il=e=>{const t=Pl(e),s=t?x(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=wl(t);return{...ve,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in ns?{...ve,[ns[s]]:!0}:ve},Tl=e=>{const t={...ve};let s=e;for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))break;const r=n.getName()==="use"?s.getArguments()[0]:void 0;if(r){const i=Il(r);t.usesCaptcha||=i.usesCaptcha,t.usesEmailGate||=i.usesEmailGate,t.usesMask||=i.usesMask,t.usesRateLimit||=i.usesRateLimit,t.usesRls||=i.usesRls}s=n.getExpression()}return t},Cl=new Set(["insert","insertMany","insertManyUnsafe","replace"]),Ol=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Cl.has(t.getName()))return!1;const s=t.getExpression();if(!L(s))return!1;const r=e.getArguments()[0];return!r||!(o.isStringLiteral(r)||o.isNoSubstitutionTemplateLiteral(r))?!1:Al(r.getLiteralText())},Rl=new Set(["create","publish","publishBatch","runAfter","runAt","send","sendBatch"]),Fl=new Set(["queues","scheduler","topics","workflows"]),kl=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Rl.has(t.getName()))return!1;let s=t.getExpression();for(;o.isCallExpression(s)||o.isElementAccessExpression(s)||o.isPropertyAccessExpression(s);){if(o.isPropertyAccessExpression(s)&&Fl.has(s.getName())){const n=s.getExpression();if(o.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},Ll=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return L(s)},qs=new Set(["generateObject","generateText","streamObject","streamText"]),Dl=e=>{const t=x(e.getExpression());return t!==void 0&&qs.has(t)},Ml=e=>{const t=x(e.getExpression());if(t===void 0||!qs.has(t))return!1;const s=e.getArguments()[0];return!s||!o.isObjectLiteralExpression(s)||s.getProperties().some(n=>o.isSpreadAssignment(n))?!1:!O(s,"maxOutputTokens")},_l=new Set(["log","span","trace"]),Kl=new Set(["ai"]),$l=new Set(["email","mail"]),zl=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","topics","workflows"]),Be=(e,t)=>e.getDescendantsOfKind(u.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"}),Ul=new Set([u.ArrowFunction,u.FunctionDeclaration,u.FunctionExpression,u.GetAccessor,u.MethodDeclaration,u.SetAccessor]),jl=new Set(["every","filter","flatMap","forEach","map","some"]),Bl=new Set(["all","allSettled","race"]),ql=e=>{const t=e.getParent();if(!t||!o.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName();if(jl.has(n))return t;const r=s.getExpression();if(o.isIdentifier(r)&&r.getText()==="Promise"&&Bl.has(n))return t},Wl=e=>{let t=e.getParent();for(;t;){if(o.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(Ul.has(t.getKind())){const s=ql(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},Vl=e=>{let t=e;for(;;){const s=t.getParent();if(!o.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;if(s.getName()==="catch")return!0;if(s.getName()!=="then"&&s.getName()!=="finally")return!1;const n=s.getParent();if(!o.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},Hl=e=>{let t=e;for(;;){const s=t.getParent();if(o.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return o.isCallExpression(s)&&s.getExpression()===t?s:void 0}},Gl=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(u.PropertyAccessExpression)){if(!zl.has(n.getName()))continue;const r=n.getExpression();if(!o.isIdentifier(r)||r.getText()!=="ctx")continue;const i=Hl(n);i&&(t=!0,!Wl(i)&&!Vl(i)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},Yl=e=>e.getDescendantsOfKind(u.ThrowStatement).some(t=>{const s=t.getExpression();if(!o.isNewExpression(s))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="Error"}),os="lunora-advisor-exempt",Ql=/^[\s*/]+/u,Xl=/[\w-]/u,Jl=e=>{const s=(e.getFirstAncestorByKind(u.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
7
- `);for(const n of s.split(`
8
- `)){const r=n.replace(Ql,"");if(!r.startsWith(os))continue;const i=r.slice(os.length);if(Xl.test(i.charAt(0)))continue;const a=i.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":i.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},Zl=e=>{const[t]=e.getArguments();if(t){if(o.isObjectLiteralExpression(t)){const s=O(t,"handler");return s?o.isPropertyAssignment(s)?s.getInitializer():o.isShorthandPropertyAssignment(s)?s.getNameNode():o.isMethodDeclaration(s)?s:void 0:void 0}return t}},eu=(e,t)=>{const s=Zl(t);if(!s)return;if(o.isArrowFunction(s)||o.isFunctionExpression(s)||o.isMethodDeclaration(s))return e;if(!o.isIdentifier(s))return;const n=s.getSourceFile(),r=s.getText(),i=n.getVariableDeclaration(r)?.getInitializer();return i&&(o.isArrowFunction(i)||o.isFunctionExpression(i))?i:n.getFunction(r)},tu=e=>{let t=!1,s=!1,n=!1,r=!1,i=!1;for(const l of e.getDescendantsOfKind(u.CallExpression))if(Ol(l)&&(i=!0),kl(l)&&(t=!0),Ll(l)&&(r=!0),Dl(l)&&(s=!0),Ml(l)&&(n=!0),i&&t&&r&&n)break;const{handlesErrors:a,reachesOutbound:c}=Gl(e);return{callsMail:Be(e,$l),emitsEvent:Be(e,_l),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||Be(e,Kl),throwsBareError:Yl(e),unboundedAiGeneration:n,usesInsertManyUnsafe:r,writesUserTable:i}},su=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=j(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const r=n.receiver?Tl(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},i=eu(e,s);return{...i?tu(i):{},...Jl(e),...r,analyzableBody:i!==void 0,exportName:e.getName(),file:t,hasEmailArg:Nl(s,n.receiver),kind:n.kind,visibility:n.visibility}},nu=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const r of n.getDeclarations()){const i=su(r,t);i&&s.push(i)}return s},ru=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...nu(r,b(t,n)))}return s},ou=new Set(["dbRateLimit","rateLimit"]),iu=e=>o.isArrowFunction(e)?e.getBody():e,au=e=>{if(!o.isArrowFunction(e))return;const t=e.getParameters()[0]?.getNameNode();return t!==void 0&&o.isIdentifier(t)?t:void 0},Ws=e=>{const t=e.getParent();return o.isPropertyAccessExpression(t)&&t.getExpression()===e&&t.getName()==="args"},Vs=(e,t)=>{const s=t.getSymbol();return s===void 0?[]:e.getDescendantsOfKind(u.Identifier).filter(n=>{if(n.getSymbol()!==s)return!1;const r=n.getParent();return!(o.isPropertyAccessExpression(r)&&r.getNameNode()===n)})},cu=(e,t)=>K(e)||t!==void 0&&Vs(e,t).some(s=>Ws(s)),lu=(e,t)=>t===void 0?W(e):Vs(e,t).some(s=>!Ws(s)),uu=(e,t)=>{const s=x(e.getExpression());if(s===void 0||!ou.has(s))return;const n=A(xs(e.getArguments()[2]),"key");if(!n)return;const r=iu(n),i=au(n);if(!(!cu(r,i)||lu(r,i)))return{callee:s,scope:g(e),file:t,limitName:Es(e),line:e.getStartLineNumber()}},du=(e,t)=>N(e,t,uu),fu=new Set(["findFirst","findFirstOrThrow","findMany","findUnique","get"]),pu=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!fu.has(t.getName()))return;const s=t.getExpression();if(L(s)){const n=e.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}if(o.isPropertyAccessExpression(s)&&L(s.getExpression()))return s.getName()},gu=e=>{let t=e;for(;o.isCallExpression(t);){const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&L(s.getExpression())){const n=t.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},mu=e=>{let t=ne(e)??e;for(;o.isAwaitExpression(t);)t=ne(t.getExpression())??t.getExpression();return t},Hs=(e,t=!1)=>{const s=mu(e);if(o.isIdentifier(s)){if(t)return;const n=_(s);return n===void 0?void 0:Hs(n,!0)}if(o.isCallExpression(s))return pu(s)??gu(s)},hu=e=>{const t=e.getBody();if(!o.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(u.ReturnStatement)){const r=n.getFirstAncestor(a=>o.isArrowFunction(a)||o.isFunctionExpression(a)||o.isFunctionDeclaration(a)),i=n.getExpression();r===e&&i!==void 0&&s.push(i)}return s},vu=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=j(s);if(n?.kind!=="query")return[];const r=Ls(s);if(r===void 0)return[];const i=n.receiver!==void 0&&Kn(n.receiver,"output"),a=n.receiver!==void 0&&ys(n.receiver,"use","mask"),c=new Set,l=[];for(const d of hu(r)){const p=Hs(d);p===void 0||c.has(p)||(c.add(p),l.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:p,usesMask:a,usesOutput:i,visibility:n.visibility}))}return l},Eu=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),i=b(t,n);for(const a of r.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...vu(c,i))}return s},xu=e=>{if(!e||!o.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)||o.isMethodDeclaration(s)||o.isGetAccessorDeclaration(s))&&t.push(E(s));return t},Su=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?j(s):void 0;if(!n)return[];const r=[];for(const i of e.getDescendantsOfKind(u.CallExpression)){const a=Ss(i);if(a===void 0)continue;const c=xu(A(a.options,"with"));c.length!==0&&r.push({exportName:e.getName(),file:t,line:i.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return r},yu=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),i=b(t,n);for(const a of r.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Su(c,i))}return s},Se=e=>{if(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(o.isBinaryExpression(e)&&e.getOperatorToken().getKind()===u.PlusToken){const t=Se(e.getLeft()),s=Se(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},Au=e=>{let t=e,s=t.getParent();for(;s!==void 0&&o.isBinaryExpression(s)&&s.getOperatorToken().getKind()===u.PlusToken;)t=s,s=t.getParent();return t!==e&&Se(t)!==void 0},bu=/(?:^|\/)__tests__\//u,Nu=/\.(?:spec|test)$/u,wu=e=>bu.test(e)||Nu.test(e),Pu=e=>{const t=e.getParent();if(t!==void 0){if(o.isVariableDeclaration(t)||o.isPropertyAssignment(t)||o.isPropertySignature(t))return E(t);if(o.isBinaryExpression(t)&&t.getOperatorToken().getKind()===u.EqualsToken)return t.getLeft().getText()}},Iu=(e,t,s)=>xr(e)?!wu(s)&&Sr(Pu(t)):!0,Tu=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(u.BinaryExpression),...e.getDescendantsOfKind(u.StringLiteral),...e.getDescendantsOfKind(u.NoSubstitutionTemplateLiteral)],r=new Set;for(const i of n){if(Au(i))continue;const a=Se(i);if(a===void 0)continue;const c=vr(a);if(c===void 0||!Iu(c,i,t))continue;const l=i.getStartLineNumber(),d=`${String(l)}:${c}`;r.has(d)||(r.add(d),s.push({file:t,kind:c,line:l,preview:Er(a)}))}return s},Cu=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Tu(r,b(t,n)))}return s},Ou=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?j(s):void 0;if(!n)return[];const r=[];for(const i of e.getDescendantsOfKind(u.CallExpression)){const a=Ss(i);if(a===void 0)continue;const c=A(a.options,"includeDeleted");if(c===void 0)continue;const l=o.isTrueLiteral(c),d=!l&&K(c);!l&&!d||r.push({exportName:e.getName(),file:t,fromArgs:d,hardcodedTrue:l,line:i.getStartLineNumber(),table:a.table,visibility:n.visibility})}return r},Ru=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n),i=b(t,n);for(const a of r.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Ou(c,i))}return s},Fu=new Set(["query","unsafe"]),ku=e=>{if(!o.isPropertyAccessExpression(e)||!Fu.has(e.getName()))return!1;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return o.isIdentifier(s)&&s.getText()==="ctx"},Lu=e=>o.isBinaryExpression(e)||o.isTemplateExpression(e),Du=(e,t)=>{if(!ku(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Lu(s)))return{file:t,line:s.getStartLineNumber(),scope:g(e)}},Mu=(e,t)=>N(e,t,Du),_u=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],Ku=e=>{for(const[t,s]of _u)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},$u=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const i of r.getImportDeclarations()){const a=i.getModuleSpecifierValue(),c=Ku(a);c!==void 0&&s.push({file:b(t,n),line:i.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},zu=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Uu=(e,t,s=[])=>{const n=Ie(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:zu,requireUnmodifiedReach:!0});return Ze(n,s)},ju=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Bu=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,qu=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!o.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const r of e.getProperties()){if(o.isSpreadAssignment(r)){n=!0;continue}if(o.isPropertyAssignment(r)){const i=E(r);t.push(i),i==="expiresInSeconds"&&(s=Bu(r.getInitializer()));continue}(o.isShorthandPropertyAssignment(r)||o.isMethodDeclaration(r))&&t.push(E(r))}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},Wu=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName(),s=ju.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},Vu=(e,t)=>{const s=Wu(e.getExpression());if(s!==void 0)return{scope:g(e),file:t,line:e.getStartLineNumber(),method:s.method,...qu(e.getArguments()[s.optionsIndex])}},Hu=(e,t)=>N(e,t,Vu),Gu=(e,t)=>{const s=jn(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")}},Yu=new Set(["delete","hardDelete","patch","replace","restore"]),Qu=new Set(["insertMany","insertManyUnsafe","patchWhere"]),Xu=new Set(["delete","deleteMany","hardDelete","insert","insertMany","patch","patchMany","replace","restore","upsert","upsertMany"]),is=(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(i=>i.getLiteralValue()).filter(i=>typeof i=="string");return r.length===n.length?r:[]},Ju=(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?[]:is(r,e)}return is(s,e)},as="",Zu=(e,t)=>{if(Qu.has(e))return{method:e,tables:[t!==void 0&&o.isStringLiteral(t)?t.getLiteralText():as]};if(Yu.has(e)||e==="deleteMany"||e==="patchMany"){const s=t===void 0?[]:Ju(t,e);return{method:e,tables:s.length===0?[as]:s}}},ed=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression();if(L(n))return Zu(s,e.getArguments()[0]);if(Xu.has(s)&&o.isPropertyAccessExpression(n)&&L(n.getExpression()))return{method:s,tables:[n.getName()]}},td=(e,t)=>N(e,t,(s,n)=>{const r=ed(s);if(r===void 0)return;const i=g(s),a=s.getStartLineNumber();return r.tables.map(c=>({file:n,line:a,method:r.method,scope:i,table:c}))}),sd=(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"}),nd=(e,t)=>{if(t===void 0){const s=e.getArguments()[0];if(s===void 0||!o.isObjectLiteralExpression(s)||O(s,"args")===void 0)return!1}return nt(e,t).opaque},rd=(e,t)=>{const s=[],n=(r,i)=>{const a=r.getInitializer();if(a===void 0||!o.isCallExpression(a))return;const c=j(a);c!==void 0&&nd(a,c.receiver)&&s.push(sd(t,i,a.getStartLineNumber()))};for(const r of e.getVariableStatements().filter(i=>i.isExported()))for(const i of r.getDeclarations())n(i,i.getName());return s},od=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n);r!==void 0&&s.push(...rd(r,b(t,n)))}return s.toSorted((n,r)=>n.cacheKey.localeCompare(r.cacheKey))},id=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"}]]),Te=({byName:e,byPath:t},s,n)=>t.has(`${s}:${n}`)||e.has(n),Gs=e=>!e.isAny(),ot=e=>{const t=e.getType();if(!Gs(t))return;const s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName(),n=s===void 0?void 0:id.get(s);return n===void 0||s===void 0?void 0:{...n,typeName:s}},Ys=e=>{const t=e.getInitializer();return t===void 0?!1:o.isCallExpression(t)||o.isIdentifier(t)||o.isPropertyAccessExpression(t)},Qs={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."},ad=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.`}),cd={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."},it=(e,t,s,n,r)=>{const{call:i,file:a,note:c,typeName:l}=s,d=a!==void 0&&e!==a?a:void 0,p=d===void 0?r:ad(d),v=c===void 0?p.remediation:`${c} ${p.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 — ${p.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:l},name:"procedure_not_registered",remediation:d===void 0?`Assign the registration directly: \`export const ${t} = ${i};\`. ${v}`:v,title:"Procedure exists at runtime but is missing from the generated API"}},ld=(e,t,s)=>{const n=[];for(const r of e.getVariableStatements().filter(i=>i.isExported()))for(const i of r.getDeclarations()){const a=i.getName();if(Te(s,t,a)||!Ys(i))continue;const c=ot(i);c!==void 0&&n.push(it(t,a,c,i.getStartLineNumber(),Qs))}return n},ud=(e,t,s)=>{if(Te(s,t,"default"))return[];const n=[];for(const r of e.getExportAssignments().filter(i=>!i.isExportEquals())){const i=ot(r.getExpression());i!==void 0&&n.push(it(t,"default",i,r.getStartLineNumber(),Qs))}return n},dd=(e,t,s)=>{const n=[];for(const r of e.getExportDeclarations().filter(i=>i.getModuleSpecifier()===void 0))for(const i of r.getNamedExports()){const a=i.getAliasNode()?.getText()??i.getName();if(Te(s,t,a))continue;const c=i.getLocalTargetDeclarations().find(d=>o.isVariableDeclaration(d));if(c===void 0||!Ys(c))continue;const l=ot(c);l!==void 0&&n.push(it(t,a,l,i.getStartLineNumber(),cd))}return n},fd=(e,t,s)=>[...ld(e,t,s),...ud(e,t,s),...dd(e,t,s)],pd=(e,t,s)=>e.getVariableStatements().filter(n=>n.isExported()).flatMap(n=>n.getDeclarations()).filter(n=>Te(s,t,n.getName())).filter(n=>{const r=n.getInitializer();return r!==void 0&&o.isCallExpression(r)&&o.isPropertyAccessExpression(r.getExpression())}).map(n=>({declaration:n,exportName:n.getName(),relativePath:t})),gd=({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"}),md=(e,t,s)=>{const n=[],r=[];for(const a of m(t)){const c=e.getSourceFile(a);if(c===void 0)continue;const l=b(t,a);n.push(...fd(c,l,s)),r.push(...pd(c,l,s))}const[i]=r;return i!==void 0&&r.every(({declaration:a})=>!Gs(a.getType()))&&n.push(gd(i)),n.toSorted((a,c)=>a.cacheKey.localeCompare(c.cacheKey))},hd=new Set(["when","where"]),qe=new Set(["definePolicy","defineShape"]),vd=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(o.isPropertyAccessExpression(t)){const n=t.getName();return qe.has(n)?n:void 0}if(!o.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(o.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},Ed=e=>o.isObjectLiteralExpression(e)&&e.getProperties().length===0,Xs=e=>{if(e!==void 0){if(o.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===u.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Ed(e))return"empty-object";if(o.isParenthesizedExpression(e))return Xs(e.getExpression())}},at=e=>e.getAncestors().find(t=>o.isArrowFunction(t)||o.isFunctionExpression(t)||o.isFunctionDeclaration(t)),xd=e=>e.getDescendantsOfKind(u.ReturnStatement).filter(t=>at(t)===e),Js=e=>e.getDescendantsOfKind(u.ConditionalExpression).filter(t=>at(t)===e),Sd=e=>{const t=xd(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(u.IfStatement)!==void 0)||Js(e).length>0},yd=e=>e.getDescendantsOfKind(u.IfStatement).filter(t=>at(t)===e),Xe=e=>e.getKind()===u.NullKeyword||e.getKind()===u.FalseKeyword||o.isIdentifier(e)&&e.getText()==="undefined"?!0:o.isNumericLiteral(e)?e.getLiteralValue()===0:o.isStringLiteral(e)&&e.getLiteralValue()==="",Ad=(e,t)=>Xe(e)||Xe(t),bd=new Map([[u.EqualsEqualsEqualsToken,"positive"],[u.EqualsEqualsToken,"positive"],[u.ExclamationEqualsEqualsToken,"negative"],[u.ExclamationEqualsToken,"negative"]]),cs=e=>!Xe(e)&&(o.isLiteralExpression(e)||e.getKind()===u.TrueKeyword),Nd=(e,t,s)=>{const n=bd.get(e);if(n!==void 0)return Ad(t,s)?n==="positive"?"negative":"positive":cs(t)||cs(s)?void 0:n},se=e=>{if(o.isParenthesizedExpression(e))return se(e.getExpression());if(o.isPrefixUnaryExpression(e)&&e.getOperatorToken()===u.ExclamationToken)return"negative";if(o.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=Nd(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===u.AmpersandAmpersandToken||t===u.BarBarToken){const n=se(e.getLeft()),r=se(e.getRight());return n===r?n:"indeterminate"}}return o.isIdentifier(e)||o.isPropertyAccessExpression(e)||o.isElementAccessExpression(e)||o.isCallExpression(e)?"positive":"indeterminate"},ls=e=>{if(e!==void 0){if(o.isReturnStatement(e))return e;if(o.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&o.isReturnStatement(t)?t:void 0}}},wd=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(u.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Pd=e=>o.isReturnStatement(e)?e.getExpression()??e:e,Id=e=>{const t=[];for(const s of Js(e)){const n=se(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of yd(e)){const n=se(s.getExpression());if(n==="indeterminate")continue;const r=n==="negative"?ls(s.getThenStatement()):ls(s.getElseStatement())??wd(s);r!==void 0&&t.push(Pd(r))}return t},Td=e=>{for(const t of e.getAncestors())if(o.isVariableDeclaration(t)){const s=t.getNameNode();if(o.isIdentifier(s))return s.getText()}return"<anonymous>"},Cd=(e,t,s)=>{if(!o.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!o.isObjectLiteralExpression(n))return[];const r=[];for(const i of n.getProperties()){if(!o.isPropertyAssignment(i)||!hd.has(E(i)))continue;const a=i.getInitializer();if(!(!a||!(o.isArrowFunction(a)||o.isFunctionExpression(a)))&&Sd(a))for(const c of Id(a)){const l=Xs(c);l!==void 0&&r.push({exportName:Td(e),file:s,form:l,key:E(i),line:c.getStartLineNumber(),owner:t})}}return r},Od=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const r=vd(n);r!==void 0&&s.push(...Cd(n,r,t))}return s},Rd=(e,t)=>{const s=[];for(const n of m(t)){const r=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Od(r,b(t,n)))}return s},Fd=new Set(["query","upsert","upsertNow"]),kd=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(Fd.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Ld=(e,t)=>{const s=kd(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const r=A(n,"namespace");if(!(!r||!K(r)||W(r)))return{scope:g(e),file:t,line:e.getStartLineNumber(),method:s}},Dd=(e,t)=>N(e,t,Ld),Md=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return o.isPropertyAccessExpression(s)?s.getName()==="workflows":o.isIdentifier(s)&&s.getText()==="workflows"},_d=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},Kd=(e,t)=>N(e,t,(s,n)=>Md(s)?{file:n,line:s.getStartLineNumber(),scope:g(s),workflow:_d(s)}:void 0),$d=".lunora-schema.json",Je=(e,t)=>{P(e)&&fs(e,"utf8")===t||un(e,t,"utf8")},zd=(e,t)=>{if(t===""){dn(e,{force:!0});return}Je(e,t)},Ud=e=>{const t=h(e,"package.json");if(P(t))try{const s=JSON.parse(fs(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},jd=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Bd=e=>{let t=P(e)?e:me(e);for(;t&&t!==me(t);){const s=h(t,"tsconfig.json");if(P(s))return s;t=me(t)}},us=e=>e.replaceAll("\\","/"),qd=(e,t,s)=>{if(s&&e.length>0){const i=e.map(a=>`"${a.exportName}"`).join(", ");throw new U("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) (${i}), 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 i of t.columns){const a=n.get(i.table)??[];a.push(i.column),n.set(i.table,a)}const r=t.columns.length>0;for(const i of e){if(i.table===void 0){if(r)throw new U("MASK_UNSUPPORTED",`defineShape "${i.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 "${i.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(i.table);if(a===void 0)continue;const c=a.map(l=>`"${l}"`).join(", ");throw new U("MASK_UNSUPPORTED",`defineShape "${i.exportName}" replicates table "${i.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})}},ye=(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)},ds=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,Wd=8,Vd=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:r,migrations:i,project:a,shapes:c,usesSandbox:l,useUmbrella:d,workflows:p}=e,v=()=>Zn(()=>{const y=er(a,r),T=cr(a,r);return{functions:y,httpRoutes:tr(a,r),mutators:T}});let{erased:S,value:{functions:k,httpRoutes:D,mutators:M}}=v();Mt([...k,...M].map(y=>y.filePath)),Mt(D.filter(y=>y.stream).map(y=>y.filePath),"http-stream");for(let y=1;;y+=1){const T=Or({agents:t,functions:k,httpRoutes:D,mutators:M,useUmbrella:d,workflows:p}),$=Ur({agents:t,functions:k,migrations:i,mutators:M,shapes:c,useUmbrella:d,usesSandbox:l});if(y>=Wd||ds(a,s,T)&&ds(a,n,$))return{apiContent:T,erased:S,functions:k,functionsContent:$,httpRoutes:D,mutators:M};ye(a,s,T),ye(a,n,$),{erased:S,value:{functions:k,httpRoutes:D,mutators:M}}=v()}},Hd=e=>{const t=Bd(e);return t?new Ft({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Ft({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},op=(e,t)=>{const s=m(t),n=h(t,"schema.ts");P(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=>us(c))),i=us(t),a=`${i}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===i||l.startsWith(a))&&!r.has(l)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const l=c.getFilePath();if(!(l===i||l.startsWith(a)||l.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},ip=e=>{const t=jd(),s=t?_e.now():0,n=h(e.projectRoot,e.lunoraDirectory??"lunora"),r=h(n,"schema.ts");if(!P(r))throw new U("INTERNAL",`schema.ts not found at ${r}`);const i=e.project??Hd(n);Vn(wa);const a=hr(i,r,e.projectRoot),{agents:c,capabilities:l,containers:d,crons:p,dataModelContent:v,dependencies:S,entryCronTriggers:k,env:D,featureUsage:M,hasFlags:y,hasNotify:T,identity:$,platformGate:B,queues:C,serverContent:G,services:Z,storageRulesMetadata:ee,topics:Y,usesSandbox:ae,useUmbrella:z,workflows:R}=Mo({lunoraDirectory:n,project:i,projectRoot:e.projectRoot,schema:a,target:e.target});lc(a,a.jurisdiction===void 0?void 0:ac(i,n)),io(a,M.artifacts);const F=h(n,"_generated"),I=h(F,"dataModel.ts"),Zs=h(F,"server.ts"),en=h(F,"api.ts"),tn=h(F,"functions.ts");ye(i,I,v),ye(i,Zs,G);const ce=or(i,n),Q=yr(i,n),{apiContent:ct,erased:sn,functions:q,functionsContent:lt,httpRoutes:Ce,mutators:le}=Vd({agents:c,apiPath:en,generatedFunctionsPath:tn,lunoraDirectory:n,migrations:ce,project:i,shapes:Q,useUmbrella:z,usesSandbox:ae,workflows:R}),ut=vn(i,n),Oe=En(ut,a,[...q,...Ce].map(f=>f.filePath)),ue=ut.length>0,V=e.lint===!1&&!ue?void 0:{inserts:nr(i,n),queries:fr(i,n),tableWrites:td(i,n),workflowCalls:Kd(i,n)},de=e.lint===!1||V===void 0?void 0:mn({adminRoutes:qo(i,n),aiRawRuns:Jo(i,n),aiToolSideEffects:ci(i,n),argumentDerivedFetches:di(i,n),argumentValidators:yi(i,n),authApiCalls:Hn(i,n),authConfigs:Ri(i,n),browserUrlAccesses:Di(i,n),configCalls:Gi(i,n),containerKeyAccesses:Qi(i,n),containerOverrides:sa(i,n),containers:d,exportSinks:ia(i,n),staleMigrationImports:$u(i,n),failOpenGuards:da(i,n),flagReads:Sa(i,n),flagSecurityDefaults:Na(i,n),geoIndexUsages:Ta(i,n),httpActionGuards:za(i,n),httpHeaderWrites:Qa(i,n),hyperdriveCalls:sr(i,n),identityClaimReads:sc(i,n),imageDeliveryUrlAccesses:rc(i,n),inserts:V.inserts,kvKeyAccesses:dc(i,n,q),mailRecipientAccesses:hc(i,n),maskProcedures:rr(i,n),maskStrategies:Nc(i,n),mutatorWrites:Oc(i,n),nondeterministicCalls:lr(i,n),normalizeIdAuthorizations:Vc(i,n),notifyCalls:dr(i,n),notifyConfig:ur(i,n),mutators:le,ownerFieldWrites:tl(i,n,q,le),unrestrictedWhereBranches:Rd(i,n),paymentWebhooks:ll(i,n),privilegedDispatches:Sl(i,n),procedureProtections:ru(i,n),queries:V.queries,queues:C,r2sqlCalls:pr(i,n),ratelimitKeySelectors:du(i,n),rawRowReturns:Eu(i,n),relationLoads:yu(i,n),rlsProcedures:gr(i,n),schema:a,secretLiterals:Cu(i,n),modules:Oe,shapes:Q,softDeleteReads:Ru(i,n),sqlInterpolations:Mu(i,n),storageKeyAccesses:Uu(i,n,q),storageUploads:Hu(i,n),tableWrites:V.tableWrites,vectorNamespaceAccesses:Dd(i,n),workflowCalls:V.workflowCalls,workflows:R,wranglerVariables:e.wranglerVariables}),dt=de===void 0?[]:Br(e.projectRoot,[...fn(de,{source:"static"}),...md(i,n,{byName:new Set([...R,...C,...c,...d].map(f=>f.exportName)),byPath:new Set([...q,...le,...Q,...ce].map(f=>`${f.filePath}:${f.exportName}`))}),...od(i,n),...Jn(sn,n)]),nn=mr(i,n),ft=yc(i,n);qd(Q,ft,xc(i,n));const rn=y?ma(i,n):[],Re=B.signals.vectorStore!==!1,te=Gu(M,{containerCount:d.length,cronCount:p.length,dependencies:S,hasPaymentTables:rl(a.tables),queueCount:C.length,storageColumnCount:Object.keys(bs(a)).length,storageRuleCount:ee.rules.length,vectorIndexCount:a.vectorIndexes.length,target:As(e.projectRoot,e.target),vectorStoreSupported:Re,workflowCount:R.length}),pt=t?_e.now():0,Fe=Ir(a,ce.map(f=>f.id)),gt=Bn({advisories:dt.filter(f=>f.name!=="procedure_type_check_unavailable"),advisorProcedures:de?.procedureProtections??[],agents:c,capabilities:l,containers:d,env:D,flagKeys:rn,hasFlags:y,hasNotify:T,hasVectors:Re,maskMetadata:ft,mutators:le,queues:C,rlsMetadata:nn,schema:a,schemaSnapshot:Fe,shapes:Q,services:Z,storageRules:ee,studioFeatures:te,topics:Y,useUmbrella:z,workflows:R}),mt=Tr(Q,S.has("@lunora/db"),z),ht=Rr(d,a.jurisdiction),vt=Fr(R),Et=kr(c),xt=Lr(C),St=Dr(p),on=Mr(te.scheduler),an=_r(a.tables,z),yt=Kr(a.vectorIndexes),fe=zr(a,z),At=Cr(S.has("@lunora/seed")),pe=e.apiSpec??"openapi",ke=pe==="openapi"||pe==="both",Le=pe==="openrpc"||pe==="both",bt=Ar({capabilities:l,emailAgents:c.filter(f=>f.onEmail===!0).map(f=>({className:f.className,exportName:f.exportName})),hasAccess:S.has("@lunora/cloudflare-access"),hasAuth:S.has("@lunora/auth"),hasFramework:S.has("@lunora/astro")||S.has("@lunora/svelte")||S.has("@lunora/vue")||P(h(e.projectRoot,"src","worker.ts")),hasGlobal:a.tables.some(f=>ps(f)),hasHyperdriveGlobal:a.tables.some(f=>gs(f)),hasKvIntrospector:te.kv,hasNotify:T,hasQueue:C.some(f=>f.mode==="push"),hasScheduler:te.scheduler,hasSourcedTables:a.tables.some(f=>f.externalSource!==void 0),hasStorage:te.storage,hasVectors:Re,hasWorkflow:R.length>0,identity:$,jurisdiction:a.jurisdiction,jurisdictionPinsAuth:a.jurisdictionPinsAuth===!0,tables:a.tables.map(f=>({name:f.name,shardMode:f.shardMode})),useUmbrella:z,vectorIndexCount:a.vectorIndexes.length,voiceAgents:c.filter(f=>f.voice===!0&&f.voiceBindingName!==void 0).map(f=>({bindingName:f.voiceBindingName,exportName:f.exportName})),wantsArchitecture:ue,wantsOpenApi:ke,wantsOpenRpc:Le}),Nt=Ud(e.projectRoot),wt=ue?Oe:[],Pt=br({functions:q,httpRoutes:Ce,modules:wt,version:Nt}),It=wr({functions:q,modules:wt,version:Nt}),Tt=`${JSON.stringify(Pt,void 0,2)}
9
- `,Ct=`${JSON.stringify(It,void 0,2)}
10
- `,ge=ue&&V!==void 0?ro({...V,callEdges:zi(i,n),crons:p,functions:q,httpRoutes:Ce,modules:Oe,queues:C,schema:a,services:Z,topics:Y,workflows:R}):void 0,Ot=Nr(Pt),Rt=Pr(It),De=h(n,$d),cn=P(De),Me=[];if(!e.dryRun){P(F)||ln(F,{recursive:!0});const f=(H,X)=>{Je(h(F,H),X),Me.push(H)},w=(H,X)=>{zd(h(F,H),X),X!==""&&Me.push(H)};f("app.ts",bt),f("dataModel.ts",v),f("api.ts",ct),f("server.ts",G),f("functions.ts",lt),f("shard.ts",gt),f("crons.ts",St),f("vectors.ts",yt),f("drizzle.global.ts",fe.global),f("drizzle.shard.ts",fe.shard),w("containers.ts",ht),w("workflows.ts",vt),w("agents.ts",Et),w("queues.ts",xt),w("scheduler.ts",on),w("shardRegistry.ts",an),w("seed.ts",At),w("collections.ts",mt),w("openapi.json",ke?Tt:""),w("openapi.ts",ke?Ot:""),w("openrpc.json",Le?Ct:""),w("openrpc.ts",Le?Rt:""),w("architecture.json",ge===void 0?"":`${JSON.stringify(ge,void 0,2)}
11
- `),w("architecture.ts",ge===void 0?"":oo(ge)),(!cn||e.updateSchemaBaseline===!0)&&Je(De,gn(Fe))}if(t){const f=_e.now(),w=Math.round(f-s),H=Math.round(pt-s),X=Math.round(f-pt);console.error(`@lunora/codegen: codegen took ${w.toString()}ms (discovery ${H.toString()}ms, emit ${X.toString()}ms)`)}return{advisories:dt,advisorContext:de,agents:c,containers:d,cronTriggers:[...new Set([...$r(p),...k])],generated:{agents:Et,api:ct,app:bt,collections:mt,containers:ht,crons:St,dataModel:v,drizzleGlobal:fe.global,drizzleShard:fe.shard,functions:lt,openApi:Tt,openApiModule:Ot,openRpc:Ct,openRpcModule:Rt,queues:xt,seed:At,server:G,shard:gt,vectors:yt,workflows:vt},migrations:ce,outputDirectory:F,platformDiagnostics:B.diagnostics,queues:C,schemaSnapshot:Fe,schemaSnapshotPath:De,workflows:R,writtenFiles:Me}};export{$d as SCHEMA_SNAPSHOT_FILENAME,Hd as createCodegenProject,Bd as findTsconfig,op as refreshCodegenProject,ip as runCodegen};
@@ -1 +0,0 @@
1
- import{callSiteCallers as x}from"@lunora/advisor";import{Node as a,SyntaxKind as u,ts as b}from"ts-morph";const m=new WeakMap,y=t=>t.getStatements().flatMap(o=>a.isFunctionDeclaration(o)?[o]:a.isVariableStatement(o)?o.getDeclarations().filter(e=>a.isIdentifier(e.getNameNode())):[]),S=t=>a.isFunctionDeclaration(t)?t.hasExportKeyword()?t.hasDefaultKeyword()?"default":t.getName()??"default":void 0:t.getVariableStatement()?.hasExportKeyword()===!0?t.getName():void 0,v=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"]]:[]}),k=(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,S(i));for(const[i,c]of v(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"}},w=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(b.isTypeNode(o.compilerNode))return!0}return!1},E=t=>{const o=t.getParent();return a.isShorthandPropertyAssignment(o)&&o.getNameNode()===t?o.getValueSymbol():t.getSymbol()},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)||w(s))continue;const l=E(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 h of f===void 0?[]:e.get(f)??[])p?.add(h);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)}]))},N=t=>{const o=m.get(t.compilerNode);if(o!==void 0)return o;const e=y(t),n=k(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=N(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=x(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"},V=(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}})},K=t=>N(t.getSourceFile()).exportNames.get(t.compilerNode);export{A as c,K as e,E as r,V as w};
@@ -1 +0,0 @@
1
- import{w as a}from"./classify-procedure-call-DcsbRyEV.mjs";const l=s=>a(s,"use","rls");export{l as r};
@@ -1 +0,0 @@
1
- import{d as o}from"./context-property-calls-BClPebao.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
@@ -1 +0,0 @@
1
- import"./listLunoraSourceFiles-jTik1QWu.mjs";import"./classify-procedure-call-DcsbRyEV.mjs";import{d as p}from"./index-CpnWNNMK.mjs";export{p as default};
@@ -1 +0,0 @@
1
- import{d as r}from"./context-property-calls-BClPebao.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
@@ -1 +0,0 @@
1
- import{readdirSync as S,realpathSync as A,lstatSync as O,statSync as N}from"node:fs";import{dirname as w,join as g,relative as R,sep as T,extname as y}from"node:path";import{SyntaxKind as d,Node as s,VariableDeclarationKind as F}from"ts-morph";import{diagnosticAt as I}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{findProjectConfigFile as D}from"./PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";const C=/\.ts$/u,p=(t,e)=>R(t,e).split(T).join("/").replace(C,""),_=new Set(["_generated","node_modules"]),j=(t,e,i)=>t==="schema.ts"&&e===i,z=t=>{try{return N(t)}catch{console.warn(`@lunora/codegen: skipping ${t} — it is a symlink that does not resolve (or vanished mid-scan).`);return}},b=(t,e,i,n)=>{let o,r;try{o=S(t),r=A(t)}catch{return e}if(n.has(r))return e;n.add(r);for(const a of o){const c=g(t,a),l=z(c);l!==void 0&&(l.isDirectory()?_.has(a)||b(c,e,i,n):l.isFile()&&y(a)===".ts"&&!j(a,t,i)&&e.push(c))}return e},h=t=>b(t,[],t,new Set),K=["src/server","src/index.ts","src/worker.ts"],V=new Set([".ts",".tsx"]),v=(t,e=[])=>{let i;try{i=O(t)}catch{return e}if(i.isFile())return V.has(y(t))&&e.push(t),e;if(!i.isDirectory())return e;for(const n of S(t))n==="_generated"||n==="node_modules"||v(g(t,n),e);return e},k=t=>{const e=w(t),i=h(t).map(r=>({displayPath:p(t,r),filePath:r})),n=new Set(i.map(r=>r.filePath)),o=D(e);for(const r of[...K.flatMap(a=>v(g(e,a))),...o===void 0?[]:[o]])n.has(r)||(n.add(r),i.push({displayPath:p(e,r),filePath:r}));return i},M=t=>Array.isArray(t),L=(t,e,i,n)=>{const o=[];for(const{displayPath:r,filePath:a}of e){const c=t.getSourceFile(a)??t.addSourceFileAtPath(a);for(const l of c.getDescendantsOfKind(i)){const u=n(l,r);M(u)?o.push(...u):u!==void 0&&o.push(u)}}return o},$=t=>h(t).map(e=>({displayPath:p(t,e),filePath:e})),B=(t,e,i,n)=>L(t,$(e),i,n),it=(t,e,i)=>B(t,e,d.CallExpression,i),st=(t,e,i)=>L(t,k(e),d.CallExpression,i),P=t=>{if(s.isStringLiteral(t)||s.isNoSubstitutionTemplateLiteral(t)||s.isNumericLiteral(t))return t.getLiteralText();if(s.isComputedPropertyName(t)){const e=t.getExpression();if(s.isStringLiteral(e)||s.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText()}return t.getText()},U=t=>P(t.getNameNode()),nt=t=>P(t.getPropertyNameNode()??t.getNameNode()),E=(t,e)=>t?.getProperties().find(i=>!s.isSpreadAssignment(i)&&U(i)===e),rt=(t,e)=>{if(e){const r=t.getArguments()[0];return r&&(s.isArrowFunction(r)||s.isFunctionExpression(r))?r:void 0}const i=t.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return;const n=E(i,"handler");if(!n||!s.isPropertyAssignment(n))return;const o=n.getInitializer();return o&&(s.isArrowFunction(o)||s.isFunctionExpression(o))?o:void 0},ot=(t,e)=>{if(!t||!s.isObjectLiteralExpression(t))return;const i=E(t,e);return i&&s.isPropertyAssignment(i)?i.getInitializer():void 0},W=t=>{const e=t?.getDeclarations().find(o=>s.isVariableDeclaration(o));if(e===void 0||!s.isVariableDeclaration(e))return;const i=e.getParent();if(!s.isVariableDeclarationList(i)||i.getDeclarationKind()!==F.Const)return;const n=i.getParent();return s.isVariableStatement(n)&&s.isSourceFile(n.getParent())?e.getInitializer():void 0},q=t=>W(t.getSymbol()),at=t=>{if(!t)return;if(s.isObjectLiteralExpression(t))return t;if(!s.isIdentifier(t))return;const e=q(t);return e!==void 0&&s.isObjectLiteralExpression(e)?e:void 0},f=t=>s.isPropertyAccessExpression(t)&&t.getName()==="db"||s.isIdentifier(t)&&t.getText()==="db",H=new Set(["findFirst","findFirstOrThrow","findMany","findUnique"]),ct=t=>{const e=t.getExpression();if(!s.isPropertyAccessExpression(e)||!H.has(e.getName()))return;const i=e.getExpression();if(f(i)){const n=t.getArguments()[0];return{options:t.getArguments()[1],table:n&&s.isStringLiteral(n)?n.getLiteralText():""}}if(s.isPropertyAccessExpression(i)){const n=i.getExpression();if(f(n))return{options:t.getArguments()[0],table:i.getName()}}},x=(t,e)=>{const i=t.getExpression();return!s.isPropertyAccessExpression(i)||!e.has(i.getName())?!1:f(i.getExpression())},m=t=>{const e=t.getArguments()[0];return e&&s.isStringLiteral(e)?e.getLiteralText():""},lt=(t,e,i)=>{const n=new Set,o=new Set;for(const r of t.getDescendantsOfKind(d.CallExpression))if(x(r,e)){const a=m(r);a!==""&&n.add(a)}else if(x(r,i)){const a=m(r);a!==""&&o.add(a)}return{tablesRead:[...n],tablesWritten:[...o]}},X=t=>{let e=t;for(;e&&(s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isParenthesizedExpression(e)||s.isNonNullExpression(e));)e=e.getExpression();return e},ut=t=>{const e=X(t);return e&&s.isCallExpression(e)?e:void 0},pt=t=>{const e=t.getExportAssignment(o=>!o.isExportEquals());if(!e)return;const i=e.getExpression();if(!s.isIdentifier(i))return i;const n=i.getSymbol()?.getValueDeclaration();return n&&s.isVariableDeclaration(n)?n.getInitializer():i},ft=t=>{const e=t.getArguments()[1];return e&&s.isStringLiteral(e)?e.getLiteralValue():""},gt=(t,e)=>{if(!s.isObjectLiteralExpression(t))return;const i=E(t,e);if(!i||!s.isPropertyAssignment(i))return;const n=i.getInitializer();return n&&s.isStringLiteral(n)?n.getLiteralText():void 0},Y=t=>{const e=t.getStatements(),[i]=e;if(e.length!==1||i===void 0||!s.isReturnStatement(i))return;const n=i.getExpression();return n!==void 0&&s.isObjectLiteralExpression(n)?n:void 0},dt=t=>{if(s.isObjectLiteralExpression(t))return t;if(s.isParenthesizedExpression(t)){const e=t.getExpression();return s.isObjectLiteralExpression(e)?e:void 0}return s.isBlock(t)?Y(t):void 0},Et=t=>s.isIdentifier(t)&&t.getText()==="ctx",xt=t=>(e,i,n)=>{if(s.isStringLiteral(e)||s.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw I(e,`${t} "${i}": \`${n}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)},Q=new Set(["api","internal"]),mt=new Set(["run","runAction","runMutation","runQuery"]),St=t=>{if(t===void 0||!s.isPropertyAccessExpression(t))return;const e=[];let i=t;for(;s.isPropertyAccessExpression(i);)e.unshift(i.getName()),i=i.getExpression();return s.isIdentifier(i)&&Q.has(i.getText())&&e.length>=2?e:void 0};export{mt as RUN_METHODS,C as TS_EXTENSION_RE,nt as bindingKeyName,it as collectCallRows,B as collectNodeRows,st as collectSecurityCallRows,pt as defaultExportExpression,E as findObjectProperty,St as functionReferenceSegments,rt as handlerOf,Et as isContextIdentifier,f as isDatabaseAccessor,ft as limitNameOf,h as listLunoraSourceFiles,k as listSecurityScanFiles,p as lunoraRelativePath,dt as objectLiteralFromCallbackBody,at as optionsObjectLiteral,ot as propertyInitializer,U as propertyKeyName,P as propertyNameText,ct as readTargetOf,xt as stringPropertyFor,gt as stringPropertyOf,W as symbolConstInitializer,m as tableArgumentOf,lt as tablesAccessedIn,X as unwrapExpression,ut as unwrapToCallExpression};