@lunora/codegen 1.0.0-alpha.135 → 1.0.0-alpha.137

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 (58) hide show
  1. package/dist/index.d.mts +1 -1
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/AGENTS_FILENAME-D1qA0h5m.mjs +1 -0
  5. package/dist/packem_shared/CONTAINERS_FILENAME-oKaARMoA.mjs +1 -0
  6. package/dist/packem_shared/FLAGS_FILENAME-BasxlnVS.mjs +1 -0
  7. package/dist/packem_shared/MUTATORS_FILENAME-DJvAhDlD.mjs +1 -0
  8. package/dist/packem_shared/NOTIFY_FILENAME-B-eIjru_.mjs +1 -0
  9. package/dist/packem_shared/QUEUES_FILENAME-D229WtRm.mjs +1 -0
  10. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CR8wI4jY.mjs +9 -0
  11. package/dist/packem_shared/WORKFLOWS_FILENAME-DRaiCNa6.mjs +1 -0
  12. package/dist/packem_shared/ast-CjWtsS6S.mjs +1 -0
  13. package/dist/packem_shared/chain-CtC3-wwZ.mjs +1 -0
  14. package/dist/packem_shared/classify-procedure-call-AKeIK05y.mjs +1 -0
  15. package/dist/packem_shared/discoverAuthApiCalls-C35kkayg.mjs +1 -0
  16. package/dist/packem_shared/discoverCrons-wXBfQcfn.mjs +1 -0
  17. package/dist/packem_shared/discoverFunctions-BBDziFXy.mjs +1 -0
  18. package/dist/packem_shared/discoverHttpRoutes-Dmow2gql.mjs +1 -0
  19. package/dist/packem_shared/discoverInserts-C5l2INmE.mjs +1 -0
  20. package/dist/packem_shared/discoverMaskProcedures-Df4JQp_2.mjs +1 -0
  21. package/dist/packem_shared/discoverMigrations-CWH7T6qz.mjs +1 -0
  22. package/dist/packem_shared/discoverNondeterministicCalls-JsO91i57.mjs +1 -0
  23. package/dist/packem_shared/discoverQueries-iypfwfdZ.mjs +1 -0
  24. package/dist/packem_shared/discoverR2sqlCalls-BbfOpwE4.mjs +1 -0
  25. package/dist/packem_shared/discoverRlsMetadata-DGUGYgWs.mjs +1 -0
  26. package/dist/packem_shared/discoverRlsProcedures-CRshfYZE.mjs +1 -0
  27. package/dist/packem_shared/discoverSandboxUsage-DdewAOuj.mjs +1 -0
  28. package/dist/packem_shared/discoverSchema-Bp8DcNq7.mjs +1 -0
  29. package/dist/packem_shared/discoverStorageRulesMetadata-gyO60A5S.mjs +1 -0
  30. package/dist/packem_shared/exported-procedure-chains-MlZRKqSD.mjs +1 -0
  31. package/dist/packem_shared/index-CCDlo9L7.mjs +1 -0
  32. package/dist/packem_shared/queries-B_xEHIeL.mjs +1 -0
  33. package/dist/packem_shared/unwrap-handler-return-CmIWbykC.mjs +1 -0
  34. package/package.json +4 -4
  35. package/dist/packem_shared/AGENTS_FILENAME-CPHo8Se5.mjs +0 -1
  36. package/dist/packem_shared/CONTAINERS_FILENAME-Bvn6LZP6.mjs +0 -1
  37. package/dist/packem_shared/FLAGS_FILENAME-DtBWyUKq.mjs +0 -1
  38. package/dist/packem_shared/MUTATORS_FILENAME-D1a0-wNV.mjs +0 -1
  39. package/dist/packem_shared/NOTIFY_FILENAME-B0p73Gm8.mjs +0 -1
  40. package/dist/packem_shared/QUEUES_FILENAME-BnGLtAIu.mjs +0 -1
  41. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DxQyv2mO.mjs +0 -9
  42. package/dist/packem_shared/WORKFLOWS_FILENAME-B8y51Frf.mjs +0 -1
  43. package/dist/packem_shared/discover-ast-D33zP-NZ.mjs +0 -1
  44. package/dist/packem_shared/discover-queries-Dfj_0WJG.mjs +0 -1
  45. package/dist/packem_shared/discoverAuthApiCalls-DUjcl0SB.mjs +0 -1
  46. package/dist/packem_shared/discoverCrons-BUJO2ipU.mjs +0 -1
  47. package/dist/packem_shared/discoverFunctions-CKff5HG0.mjs +0 -1
  48. package/dist/packem_shared/discoverHttpRoutes-DpWRI--A.mjs +0 -1
  49. package/dist/packem_shared/discoverInserts-YX8AmrzL.mjs +0 -1
  50. package/dist/packem_shared/discoverMaskProcedures-DYtwf257.mjs +0 -1
  51. package/dist/packem_shared/discoverMigrations-4Jjf5DJE.mjs +0 -1
  52. package/dist/packem_shared/discoverNondeterministicCalls-CwvKy5-r.mjs +0 -1
  53. package/dist/packem_shared/discoverQueries-C5S9tFoD.mjs +0 -1
  54. package/dist/packem_shared/discoverR2sqlCalls-_bVEyLb8.mjs +0 -1
  55. package/dist/packem_shared/discoverRlsMetadata-BV_yswEJ.mjs +0 -1
  56. package/dist/packem_shared/discoverSandboxUsage-L0lV17de.mjs +0 -1
  57. package/dist/packem_shared/discoverSchema-Hsu_1xIc.mjs +0 -1
  58. package/dist/packem_shared/discoverStorageRulesMetadata-DbDybCNX.mjs +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.135",
3
+ "version": "1.0.0-alpha.137",
4
4
  "description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -46,13 +46,13 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@lunora/advisor": "1.0.0-alpha.96",
50
- "@lunora/agent": "1.0.0-alpha.71",
49
+ "@lunora/advisor": "1.0.0-alpha.97",
50
+ "@lunora/agent": "1.0.0-alpha.72",
51
51
  "@lunora/container": "1.0.0-alpha.35",
52
52
  "@lunora/errors": "1.0.0-alpha.24",
53
53
  "@lunora/platform": "1.0.0-alpha.19",
54
54
  "@lunora/queue": "1.0.0-alpha.36",
55
- "@lunora/scheduler": "1.0.0-alpha.41",
55
+ "@lunora/scheduler": "1.0.0-alpha.42",
56
56
  "@lunora/values": "1.0.0-alpha.31",
57
57
  "@lunora/workflow": "1.0.0-alpha.35",
58
58
  "jsonc-parser": "^3.3.1",
@@ -1 +0,0 @@
1
- import{existsSync as u}from"node:fs";import{join as p}from"node:path";import{agentDefaultName as d,agentClassName as f,agentBindingName as b,voiceBindingName as N,voiceClassName as y}from"@lunora/agent/naming";import{LunoraError as l}from"@lunora/errors";import{Node as a,SyntaxKind as m}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{u as A,s as w}from"./discover-ast-D33zP-NZ.mjs";const h="agents.ts",E=i=>{const t=i.getSymbol();if(!t)return i.getText()==="defineAgent";for(const n of t.getDeclarations())if(a.isImportSpecifier(n))return n.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/agent"?!1:n.getNameNode().getText()==="defineAgent";return!1},P=w("agent"),I=(i,t,n)=>{if(i.getKind()===m.TrueKeyword)return!0;if(i.getKind()===m.FalseKeyword)return!1;throw g(i,`agent "${t}": \`${n}\` must be a static boolean literal — it is deploy configuration codegen writes into the ctx.agents wiring spec`)},T=(i,t)=>{const n=i.getArguments()[0];if(!n||!a.isObjectLiteralExpression(n))throw g(i,`agent "${t}": defineAgent must be passed an inline object literal`);const o={bindingName:b(t),className:f(t),exportName:t,name:d(t)},e=n.getProperty("name");e&&a.isPropertyAssignment(e)&&(o.name=P(e.getInitializerOrThrow(),t,"name"));const r=n.getProperty("publicRun");r&&a.isPropertyAssignment(r)&&I(r.getInitializerOrThrow(),t,"publicRun")&&(o.publicRun=!0);const s=n.getProperty("voice");if(s&&a.isPropertyAssignment(s)){const c=s.getInitializerOrThrow();if(!a.isObjectLiteralExpression(c))throw g(c,`agent "${t}": \`voice\` must be an inline object literal — its presence tells codegen to emit the voice-session Durable Object`);o.voice=!0,o.voiceBindingName=N(t),o.voiceClassName=y(t)}return n.getProperty("onEmail")&&(o.onEmail=!0),o},v=i=>{const t=[];for(const n of i.getVariableDeclarations()){if(!n.isExported())continue;const o=A(n.getInitializer());if(!o)continue;const e=o.getExpression();if(!a.isIdentifier(e)||!E(e))continue;const r=n.getNameNode();if(!a.isIdentifier(r))throw g(r,"defineAgent exports must be plain named exports (no destructuring)");t.push(T(o,r.getText()))}return t},D=i=>{const t=new Map,n=new Map,o=new Map;for(const e of i){const r=t.get(e.name);if(r!==void 0)throw new l("DUPLICATE_AGENT_NAME",`Duplicate agent name "${e.name}": produced by both "${r}" and "${e.exportName}". Deployed agent names must be unique across the project.`,{status:500});t.set(e.name,e.exportName);const s=n.get(e.bindingName);if(s!==void 0)throw new l("DUPLICATE_AGENT_BINDING",`Duplicate agent binding "${e.bindingName}": produced by both "${s}" and "${e.exportName}". Agent export names must yield unique binding names.`,{status:500});n.set(e.bindingName,e.exportName);const c=o.get(e.className);if(c!==void 0)throw new l("DUPLICATE_AGENT_CLASS",`Duplicate agent class "${e.className}": produced by both "${c}" and "${e.exportName}". Agent export names must yield unique generated class names.`,{status:500});o.set(e.className,e.exportName)}},j=(i,t)=>{const n=p(t,h);if(!u(n))return[];const o=i.getSourceFile(n)??i.addSourceFileAtPath(n),e=v(o);return e.sort((r,s)=>r.exportName.localeCompare(s.exportName)),D(e),e};export{h as AGENTS_FILENAME,j as discoverAgents};
@@ -1 +0,0 @@
1
- import{existsSync as f}from"node:fs";import{join as d}from"node:path";import{containerClassName as b,containerBindingName as p,normalizeContainerImage as u}from"@lunora/container";import{SyntaxKind as y,Node as n}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{s as L}from"./discover-ast-D33zP-NZ.mjs";const P="containers.ts",h=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineContainer";for(const i of t.getDeclarations())if(n.isImportSpecifier(i))return i.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/container"?!1:i.getNameNode().getText()==="defineContainer";return!1},g=L("container"),m=(e,t,i)=>{if(n.isNumericLiteral(e))return e.getLiteralValue();throw c(e,`container "${t}": \`${i}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},T=(e,t)=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e))return u(e.getLiteralValue());if(n.isObjectLiteralExpression(e)){const i=e.getProperty("registry");if(i&&n.isPropertyAssignment(i)){const o=i.getInitializerOrThrow();return u({registry:g(o,t,"image.registry")})}const r=e.getProperty("build");if(r&&n.isPropertyAssignment(r)){const o=r.getInitializerOrThrow();return u({build:g(o,t,"image.build")})}}throw c(e,`container "${t}": \`image\` must be a static string path, { registry: "…" }, or { build: "…" } literal`)},k=e=>{if(!n.isObjectLiteralExpression(e))return;const t={};for(const i of e.getProperties()){if(!n.isPropertyAssignment(i))continue;const r=i.getInitializerOrThrow();(n.isStringLiteral(r)||n.isNoSubstitutionTemplateLiteral(r))&&(t[i.getName()]=r.getLiteralValue())}return Object.keys(t).length>0?t:void 0},I=e=>{if(!n.isObjectLiteralExpression(e))return;const t={};for(const i of e.getProperties()){if(!n.isPropertyAssignment(i))continue;const r=i.getName(),o=i.getInitializerOrThrow();n.isNumericLiteral(o)&&(r==="gracePeriodSeconds"||r==="stepPercentage")&&(t[r]=o.getLiteralValue())}return t.gracePeriodSeconds===void 0&&t.stepPercentage===void 0?void 0:t},w=e=>{if(n.isTrueLiteral(e))return!0;if(n.isFalseLiteral(e))return!1},S=e=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)||n.isNumericLiteral(e))return e.getLiteralValue()},A=(e,t)=>{if(n.isStringLiteral(e))return e.getLiteralValue();if(n.isObjectLiteralExpression(e)){const i={};for(const r of e.getProperties()){if(!n.isPropertyAssignment(r))throw c(r,`container "${t}": \`instanceType\` must be an object of static number literals`);const o=r.getName();if(o!=="diskMb"&&o!=="memoryMib"&&o!=="vcpu")throw c(r,`container "${t}": unknown \`instanceType\` field "${o}" — expected vcpu, memoryMib, or diskMb`);i[o]=m(r.getInitializerOrThrow(),t,`instanceType.${o}`)}return i}throw c(e,`container "${t}": \`instanceType\` must be a static string or { vcpu, memoryMib, diskMb } literal`)},v=(e,t)=>{const i=e.getArguments()[0];if(!i||!n.isObjectLiteralExpression(i))throw c(e,`container "${t}": defineContainer must be passed an inline object literal`);const r={bindingName:p(t),className:b(t),exportName:t,image:{buildContext:".",dockerfilePath:"./Dockerfile",kind:"dockerfile"}};let o=!1;for(const a of i.getProperties()){if(!n.isPropertyAssignment(a))continue;const l=a.getName(),s=a.getInitializerOrThrow();switch(l){case"buildArgs":{r.buildArgs=k(s);break}case"enableInternet":{r.enableInternet=w(s);break}case"image":{r.image=T(s,t),o=!0;break}case"instanceType":{r.instanceType=A(s,t);break}case"maxInstances":{r.maxInstances=m(s,t,"maxInstances");break}case"name":{r.name=g(s,t,"name");break}case"rollout":{r.rollout=I(s);break}case"sleepAfter":{r.sleepAfter=S(s);break}}}if(!o)throw c(i,`container "${t}": defineContainer requires a static \`image\` property`);return r},C=e=>{const t=[];for(const i of e.getVariableDeclarations()){if(!i.isExported())continue;const r=i.getInitializer();if(r?.getKind()!==y.CallExpression)continue;const o=r,a=o.getExpression();if(!n.isIdentifier(a)||!h(a))continue;const l=i.getNameNode();if(!n.isIdentifier(l))throw c(l,"defineContainer exports must be plain named exports (no destructuring)");t.push(v(o,l.getText()))}return t},F=(e,t)=>{const i=d(t,P);if(!f(i))return[];const r=e.getSourceFile(i)??e.addSourceFileAtPath(i),o=C(r);return o.sort((a,l)=>a.exportName.localeCompare(l.exportName)),o};export{P as CONTAINERS_FILENAME,F as discoverContainers};
@@ -1 +0,0 @@
1
- import{existsSync as c}from"node:fs";import{join as g}from"node:path";import{SyntaxKind as p,Node as o}from"ts-morph";import{l as d,d as f,p as u,i as l}from"./discover-ast-D33zP-NZ.mjs";const m="flags.ts",v=new Set(["boolean","number","object","string"]),x="@lunora/flags/providers/flagship",y=r=>{const i=r.getSymbol();if(!i)return r.getText()==="flagshipProvider";for(const e of i.getDeclarations())if(o.isImportSpecifier(e))return e.getImportDeclaration().getModuleSpecifierValue()!==x?!1:e.getNameNode().getText()==="flagshipProvider";return!1},E=(r,i)=>{const e=r.getProperty(i);if(!e||!o.isPropertyAssignment(e))return;const t=e.getInitializerOrThrow();if(o.isStringLiteral(t)||o.isNoSubstitutionTemplateLiteral(t))return t.getLiteralValue()},S=r=>{const i=r.getArguments()[0];if(i&&o.isObjectLiteralExpression(i)){const e=E(i,"binding");if(e!==void 0&&e.length>0)return{bindingName:e,mode:"binding",provider:"flagship"}}return{mode:"http",provider:"flagship"}},h=r=>u(r.getArguments()[0],"provider"),N=(r,i)=>{const e=g(i,m);if(!c(e))return;const t=r.getSourceFile(e)??r.addSourceFileAtPath(e),s=f(t);if(!s||!o.isCallExpression(s))return{provider:"custom"};const a=h(s);if(a&&o.isCallExpression(a)){const n=a.getExpression();if(o.isIdentifier(n)&&y(n))return S(a)}return{provider:"custom"}},F=r=>{const i=r.getName();if(!v.has(i))return;const e=r.getExpression();if(!o.isPropertyAccessExpression(e))return;if(e.getName()==="flags"&&l(e.getExpression()))return i;const t=e.getExpression();if(e.getName()==="details"&&o.isPropertyAccessExpression(t)&&t.getName()==="flags"&&l(t.getExpression()))return i},P=r=>{const i=r.getExpression();if(!o.isPropertyAccessExpression(i))return;const e=F(i);if(e===void 0)return;const t=r.getArguments()[0];if(!t||!(o.isStringLiteral(t)||o.isNoSubstitutionTemplateLiteral(t)))return;const s=t.getLiteralValue();return s.length>0?{key:s,type:e}:void 0},C=(r,i)=>{const e=new Map;for(const t of d(i)){const s=r.getSourceFile(t)??r.addSourceFileAtPath(t);for(const a of s.getDescendantsOfKind(p.CallExpression)){const n=P(a);n&&!e.has(n.key)&&e.set(n.key,n.type)}}return[...e.entries()].map(([t,s])=>({key:t,type:s})).toSorted((t,s)=>t.key.localeCompare(s.key))};export{m as FLAGS_FILENAME,C as discoverFlagKeys,N as discoverFlags};
@@ -1 +0,0 @@
1
- import{existsSync as f}from"node:fs";import{join as p}from"node:path";import{Node as o,SyntaxKind as u}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapHandlerReturn as g}from"./discoverFunctions-CKff5HG0.mjs";import{a as d}from"./module-specifiers-WF8iAydP.mjs";import{a as x}from"./parse-validator-BFTp87yz.mjs";const M="mutators.ts",m=d,y=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineMutator";for(const e of t.getDeclarations())if(o.isImportSpecifier(e))return m(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineMutator":!1;return!1},S=r=>{const t=r.getSymbol();if(!t)return!1;for(const e of t.getDeclarations()){if(!o.isNamespaceImport(e))continue;const i=e.getFirstAncestorByKind(u.ImportDeclaration);return i!==void 0&&m(i.getModuleSpecifierValue())}return!1},N=r=>{if(o.isIdentifier(r))return y(r);if(o.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(t)&&S(t)}return!1},I=r=>{const t=r.getArguments()[0];return t&&o.isObjectLiteralExpression(t)?t:void 0},b=r=>{const t=r?.getProperty("args");if(!t||!o.isPropertyAssignment(t))return{};const e=t.getInitializer();return e&&o.isObjectLiteralExpression(e)?x(e):{}},A=r=>{const t=r?.getProperty("server");if(!t||!o.isPropertyAssignment(t))return"unknown";const e=t.getInitializer();return!e||!(o.isArrowFunction(e)||o.isFunctionExpression(e))?"unknown":g(e)},E=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const i=e.getInitializer();if(i?.getKind()!==u.CallExpression)continue;const n=i,a=n.getExpression();if(!N(a))continue;const s=e.getNameNode();if(!o.isIdentifier(s))throw l(s,"defineMutator exports must be plain named exports (no destructuring)");const c=I(n);t.push({args:b(c),exportName:s.getText(),filePath:"mutators",returnType:A(c)})}return t},w=(r,t)=>{const e=p(t,M);if(!f(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),n=E(i);return n.sort((a,s)=>a.exportName.localeCompare(s.exportName)),n};export{M as MUTATORS_FILENAME,w as discoverMutators,N as isDefineMutatorCallee};
@@ -1 +0,0 @@
1
- import{existsSync as m}from"node:fs";import{join as x}from"node:path";import{SyntaxKind as d,Node as c}from"ts-morph";import{l,a as g,d as P,h as E}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as S}from"./discoverFunctions-CKff5HG0.mjs";const y="notify.ts",v=new Set(["chat","inApp","send","webhook"]),p=new Set(["broadcast","send"]),N=e=>{const t=e.getInitializer();if(!t||!c.isCallExpression(t))return;const o=S(t);if(!o)return;const s=E(t,o.receiver);return s?{exportName:e.getName(),handler:s,kind:o.kind}:void 0},h=e=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const s of o.getDeclarations()){const r=N(s);r&&t.push(r)}return t},f=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=e.getExpression();if((t==="notify"||t==="push")&&c.isIdentifier(o)&&o.getText()==="ctx")return t;if(t==="push"&&f(o)==="notify")return"push"},F=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=f(e.getExpression());if(o==="notify"&&v.has(t))return`ctx.notify.${t}`;if(o==="push"&&p.has(t))return`ctx.push.${t}`},A=e=>c.isPropertyAccessExpression(e)?f(e.getExpression())==="push"&&p.has(e.getName()):!1,T=(e,t)=>{const o=[];for(const s of l(t)){const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),a=g(t,s);for(const n of h(r))if(!(n.kind!=="query"&&n.kind!=="mutation"))for(const i of n.handler.getDescendantsOfKind(d.PropertyAccessExpression)){const u=F(i);u!==void 0&&o.push({callee:u,exportName:n.exportName,file:a,kind:n.kind,line:i.getStartLineNumber()})}}return o},O=(e,t)=>{for(const o of l(t)){const s=e.getSourceFile(o)??e.addSourceFileAtPath(o);for(const r of h(s))for(const a of r.handler.getDescendantsOfKind(d.PropertyAccessExpression))if(A(a))return!0}return!1},_=(e,t)=>{const o=x(t,y);if(!m(o))return;const s=e.getSourceFile(o)??e.addSourceFileAtPath(o),r=P(s);let a=!1,n=!1;if(r&&c.isCallExpression(r)){const i=r.getArguments()[0];i&&c.isObjectLiteralExpression(i)&&(a=i.getProperty("webPush")!==void 0,n=i.getProperty("fcm")!==void 0)}return{hasFcm:n,hasWebPush:a,usesPush:O(e,t)}};export{y as NOTIFY_FILENAME,T as discoverNotifyCalls,_ as discoverNotifyConfig};
@@ -1 +0,0 @@
1
- import{existsSync as g}from"node:fs";import{join as l}from"node:path";import{LunoraError as d}from"@lunora/errors";import{queueDefaultName as p,queueBindingName as f}from"@lunora/queue";import{SyntaxKind as y,Node as u}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{s as h}from"./discover-ast-D33zP-NZ.mjs";const q="queues.ts",b=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineQueue";for(const e of t.getDeclarations())if(u.isImportSpecifier(e))return e.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/queue"?!1:e.getNameNode().getText()==="defineQueue";return!1},c=h("queue"),N=(r,t,e)=>{if(u.isNumericLiteral(r))return r.getLiteralValue();throw a(r,`queue "${t}": \`${e}\` must be a static numeric literal — it is deploy configuration codegen writes into wrangler.jsonc`)},w=(r,t)=>{const e=r.getProperty("name");if(!e||!u.isPropertyAssignment(e))return;const n=c(e.getInitializerOrThrow(),t,"name");if(n.length===0)throw a(e,`queue "${t}": \`name\` must be a non-empty string when provided`);return n},P=(r,t)=>{const e=r.getArguments()[0];if(!e||!u.isObjectLiteralExpression(e))throw a(r,`queue "${t}": defineQueue must be passed an inline object literal`);const n={bindingName:f(t),exportName:t,mode:"push",name:w(e,t)??p(t),tuning:{}},o=e.getProperty("mode");if(o&&u.isPropertyAssignment(o)){const i=c(o.getInitializerOrThrow(),t,"mode");if(i!=="push"&&i!=="pull")throw a(o,`queue "${t}": \`mode\` must be "push" or "pull" (got ${JSON.stringify(i)})`);n.mode=i}const s=e.getProperty("deadLetterQueue");s&&u.isPropertyAssignment(s)&&(n.tuning.deadLetterQueue=c(s.getInitializerOrThrow(),t,"deadLetterQueue"));for(const i of["maxBatchSize","maxBatchTimeout","maxRetries","retryDelay"]){const m=e.getProperty(i);m&&u.isPropertyAssignment(m)&&(n.tuning[i]=N(m.getInitializerOrThrow(),t,i))}return n},E=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const n=e.getInitializer();if(n?.getKind()!==y.CallExpression)continue;const o=n,s=o.getExpression();if(!u.isIdentifier(s)||!b(s))continue;const i=e.getNameNode();if(!u.isIdentifier(i))throw a(i,"defineQueue exports must be plain named exports (no destructuring)");t.push(P(o,i.getText()))}return t},I=r=>{const t=new Map,e=new Map;for(const n of r){const o=t.get(n.name);if(o!==void 0)throw new d("DUPLICATE_QUEUE_NAME",`Duplicate queue name "${n.name}": produced by both "${o}" and "${n.exportName}". Deployed queue names must be unique across the project.`,{status:500});t.set(n.name,n.exportName);const s=e.get(n.bindingName);if(s!==void 0)throw new d("DUPLICATE_QUEUE_BINDING",`Duplicate queue binding "${n.bindingName}": produced by both "${s}" and "${n.exportName}". Queue export names must yield unique binding names.`,{status:500});e.set(n.bindingName,n.exportName)}},T=(r,t)=>{const e=l(t,q);if(!g(e))return[];const n=r.getSourceFile(e)??r.addSourceFileAtPath(e),o=E(n);return o.sort((s,i)=>s.exportName.localeCompare(i.exportName)),I(o),o};export{q as QUEUES_FILENAME,T as discoverQueues};
@@ -1,9 +0,0 @@
1
- import{existsSync as y,mkdirSync as Xt,readFileSync as vt,writeFileSync as Zt,rmSync as Jt}from"node:fs";import{join as f,dirname as ue}from"node:path";import{performance as de}from"node:perf_hooks";import{runAdvisor as es}from"@lunora/advisor";import{LunoraError as D}from"@lunora/errors";import{SyntaxKind as l,Node as i,Project as Ye}from"ts-morph";import{serializeSchemaSnapshot as ts}from"./SCHEMA_SNAPSHOT_VERSION-CftvRWB8.mjs";import{toAdvisorContext as ss}from"./formatAdvisories-CkEu1eye.mjs";import{discoverAgents as ns}from"./AGENTS_FILENAME-CPHo8Se5.mjs";import{discoverContainers as rs}from"./CONTAINERS_FILENAME-Bvn6LZP6.mjs";import{diagnosticAt as ee}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as te}from"./module-specifiers-WF8iAydP.mjs";import{C as fe,i as is,f as os,n as as,j as cs,b as ls,c as us,l as ds,e as fs,o as ps,d as gs,k as ms,g as hs,p as xs,m as Es,a as vs,h as Ss}from"./emit-khv5P1pH.mjs";import{l as m,a as x,c as b,p as A,f as St,h as As,i as Ns,r as At,e as ys}from"./discover-ast-D33zP-NZ.mjs";import bs from"./readPackageDependencies-C6h6FZuP.mjs";import{discoverQueues as Is}from"./QUEUES_FILENAME-BnGLtAIu.mjs";import{discoverSandboxUsage as Ps}from"./discoverSandboxUsage-L0lV17de.mjs";import ws from"./discoverStorageRulesMetadata-DbDybCNX.mjs";import{discoverWorkflows as Ts}from"./WORKFLOWS_FILENAME-B8y51Frf.mjs";import{gatePlatformFeatures as Cs,resolveCodegenTarget as Rs}from"./DEFAULT_TARGET-CrhWLUK7.mjs";import{i as T,a as k,e as v,c as P,r as Os,b as Fs,s as se,f as Ls,g as Ds,d as ks}from"./discover-queries-Dfj_0WJG.mjs";import{classifyProcedureCall as M,inlineHandler as Ms,procedureHandler as Nt,chainUsesWrappedCall as yt,isDatabaseAccessor as _,chainHasStep as Ks,discoverFunctions as Qe,resolveStandardSchemaType as _s}from"./discoverFunctions-CKff5HG0.mjs";import zs from"./discoverAuthApiCalls-DUjcl0SB.mjs";import Us from"./discoverCrons-BUJO2ipU.mjs";import{discoverFlagKeys as Bs}from"./FLAGS_FILENAME-DtBWyUKq.mjs";import Xe from"./discoverHttpRoutes-DpWRI--A.mjs";import qs from"./discoverInserts-YX8AmrzL.mjs";import $s,{discoverMaskStrategies as js,discoverMaskMetadata as Vs,discoverMaskHasNonLiteralPolicy as Ws}from"./discoverMaskProcedures-DYtwf257.mjs";import Hs from"./discoverMigrations-4Jjf5DJE.mjs";import{MUTATORS_FILENAME as Gs,isDefineMutatorCallee as Ys,discoverMutators as Ze}from"./MUTATORS_FILENAME-D1a0-wNV.mjs";import Qs from"./discoverNondeterministicCalls-CwvKy5-r.mjs";import{discoverNotifyConfig as Xs,discoverNotifyCalls as Zs}from"./NOTIFY_FILENAME-B0p73Gm8.mjs";import Js from"./discoverR2sqlCalls-_bVEyLb8.mjs";import en,{discoverRlsMetadata as tn}from"./discoverRlsMetadata-BV_yswEJ.mjs";import sn from"./discoverSchema-Hsu_1xIc.mjs";import{secretKindOf as nn,redact as rn,isHeuristicSecretKind as on,isSecretishName as an}from"./redact-Cy14LEnc.mjs";import{discoverShapes as cn}from"./SHAPES_FILENAME-BTdasTq2.mjs";import{emitApp as ln}from"./emitApp-CZ_yiNNO.mjs";import{buildOpenApiDocument as un,emitOpenApiModule as dn}from"./buildOpenApiDocument-B3l1QPs9.mjs";import{buildOpenRpcDocument as fn,emitOpenRpcModule as pn}from"./OPENRPC_VERSION-CtO1oRu-.mjs";import{s as gn}from"./parse-validator-BFTp87yz.mjs";import{buildSchemaSnapshot as mn}from"./SchemaSnapshotParseError-D2h88OHU.mjs";const hn=e=>{const t=[],s=e.tables.filter(n=>n.shardMode==="global");return s.some(n=>n.globalBackend!=="hyperdrive")&&t.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),s.some(n=>n.globalBackend==="hyperdrive")&&t.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'}),e.vectorIndexes.length>0&&t.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/vectors.ts` import `@lunora/bindings/vectors`"}),t},xn=(e,t)=>{if(t===void 0)return;const s=hn(e).filter(o=>!t.has(o.name));if(s.length===0)return;const n=s.map(o=>` - ${o.name} — ${o.reason}`).join(`
2
- `);throw new D("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
3
- ${n}
4
-
5
- Install them with your package manager, then re-run codegen.`)},En="env.ts",vn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return te(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},Sn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&te(n.getModuleSpecifierValue())}return!1},An=e=>{if(i.isIdentifier(e))return vn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&Sn(t)}return!1},Nn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!An(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw ee(r,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},yn=(e,t)=>{const s=f(t,En);if(!y(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=Nn(n);if(o.length!==0){if(o.length>1)throw ee(n,`lunora/env.ts declares ${o.length.toString()} defineEnv() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},bn=e=>{const t=n=>i.isIdentifier(n)&&n.getText()==="ctx",s=new Set;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression))t(n.getExpression())&&s.add(n.getName());for(const n of e.getDescendantsOfKind(l.VariableDeclaration)){const o=n.getInitializer(),r=n.getNameNode();if(!(o===void 0||!t(o)||!i.isObjectBindingPattern(r)))for(const a of r.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},In=(e,t)=>{const s=Object.fromEntries(fe.map(n=>[n.key,!1]));for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=new Set(o.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=bn(o);for(const c of fe)if(!s[c.key]){if(r.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(fe.every(c=>s[c.key]))break}return s},Pn=["providerSubscriptionId","state"],wn=["providerEventId","processedAt"],Je=(e,t)=>t.every(s=>s in e.shape),Tn=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&Je(t,Pn)&&Je(s,wn)},Cn=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings/kv"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),bt="identity.ts",Rn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return te(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},On=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&te(n.getModuleSpecifierValue())}return!1},Fn=e=>{if(i.isIdentifier(e))return Rn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&On(t)}return!1},Ln=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!Fn(n.getExpression()))continue;const r=s.getNameNode();if(!i.isIdentifier(r))throw ee(r,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},Dn=(e,t)=>{const s=f(t,bt);if(!y(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=Ln(n);if(o.length!==0){if(o.length>1)throw ee(n,`lunora/identity.ts declares ${o.length.toString()} defineIdentity() contracts (${o.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return o[0]}},kn=(e,t)=>{const s=new Map,n=new Map,o=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.bindingName,`workflow "${r.exportName}"`),o.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const a=s.get(r.name);if(a!==void 0)throw new D("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${a} and agent "${r.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=n.get(r.bindingName);if(c!==void 0)throw new D("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${r.bindingName}": produced by both ${c} and agent "${r.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const u=o.get(r.className);if(u!==void 0)throw new D("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${u} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},Mn=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:o}=e,r=Dn(s,t),a=yn(s,t),c=Ts(s,t),u=Is(s,t),d=ns(s,t);kn(c,d);const E=rs(s,t),N=ws(s,t),p=Cs(In(s,t),Rs(n,e.target)),S=p.usage,C=Ps(s,t),R=S.browser||C.usesSandboxBrowser,O=bs(n),j=O??new Set,F=j.has("lunorash");xn(o,O);const K=y(f(t,"flags.ts")),z=y(f(t,"notify.ts"));return{agents:d,containers:E,dataModelContent:os(o),declaredDependencies:O,dependencies:j,env:a,featureUsage:S,hasBrowser:R,hasFlags:K,hasNotify:z,identity:r,platformGate:p,queues:u,serverContent:is({agents:d,containers:E,env:a,hasAccessFacade:S.access,hasAi:S.ai,hasAnalytics:S.analytics,hasBrowser:R,hasFlags:K,hasHyperdrive:S.hyperdrive,hasImages:S.images,hasKv:S.kv,hasNotify:z,hasPayments:S.payments,hasPipelines:S.pipelines,hasR2sql:S.r2sql,hasX402:S.x402,identity:r,queues:u,schema:o,storageRuleBuckets:N.rules.map(re=>re.bucket),useUmbrella:F,workflows:c}),storageRulesMetadata:N,usesSandbox:C.usesSandboxBrowser||C.usesSandboxContainer,useUmbrella:F,workflows:c}},It=new Set(["delete","get","head","options","patch","post","put"]),Kn=new Set(["handler","stream"]),_n=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,et=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),zn=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!It.has(t.getName()))return;const s=t.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!i.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},Un=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||It.has(n.getName()))break;s=n.getExpression()}return zn(s)},Bn=e=>{for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression))if(et.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&et.has(s.getText()))return!0}return!1},qn=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=s.getExpression();if(!i.isPropertyAccessExpression(n)||!Kn.has(n.getName()))return;const o=Un(s);if(!o||!_n.test(o.path))return;const r=s.getArguments()[0],a=r!==void 0&&(i.isArrowFunction(r)||i.isFunctionExpression(r))&&Bn(r);return{exportName:e.getName(),file:t,method:o.method,path:o.path,usesGuard:a}},$n=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=qn(o,t);r&&s.push(r)}return s},jn=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...$n(o,x(t,n)))}return s},Vn=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",Wn=(e,t)=>{if(!Vn(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!T(s)||k(s)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},Hn=(e,t)=>b(e,t,Wn),Gn=new Set(["generateText","streamText"]),Yn=new Set(["messages","prompt","system"]),Qn=[{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"]}],Xn=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const o of Qn)if(o.methods.has(s)&&o.prefixes.some(r=>n===r||n.startsWith(`${r}.`)))return`${n}.${s}`},Zn=e=>{for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=Xn(t);if(s!==void 0)return s}},Jn=e=>{const t=new Set,s=e.getFirstAncestor(r=>i.isArrowFunction(r)||i.isFunctionExpression(r)||i.isFunctionDeclaration(r)),[n]=s?.getParameters()??[],o=n?.getNameNode();if(o===void 0||!i.isObjectBindingPattern(o))return t;for(const r of o.getElements()){const a=r.getPropertyNameNode()?.getText()??r.getName(),c=r.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const u of c.getElements())t.add(u.getName())}return t},er=e=>{if(Os(e))return!0;const t=Jn(e);return t.size===0?!1:e.getDescendantsOfKind(l.Identifier).some(s=>t.has(s.getText()))},tr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!Yn.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&er(s))return!0}return!1},sr=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=P(n.getExpression());if(o===void 0||!Gn.has(o))continue;const[r]=n.getArguments();if(r===void 0||!i.isObjectLiteralExpression(r))continue;let a;for(const c of r.getDescendantsOfKind(l.CallExpression))if(P(c.getExpression())==="tool"&&(a=Zn(c),a!==void 0))break;a!==void 0&&s.push({exportName:v(n),file:t,line:n.getStartLineNumber(),method:o,sideEffect:a,userInputDerived:tr(r)})}return s},nr=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...sr(o,x(t,n)))}return s},rr=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},ir=(e,t)=>{if(!rr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!T(s)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},or=(e,t)=>b(e,t,ir),Pt=e=>e.getProperties().some(t=>i.isSpreadAssignment(t)),ar=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer();return!n||!i.isObjectLiteralExpression(n)?{objects:[],opaque:!0}:{objects:[n],opaque:Pt(n)}},cr=e=>{const t=[];let s=!1,n=e;for(;i.isCallExpression(n);){const o=n.getExpression();if(!i.isPropertyAccessExpression(o))break;if(o.getName()==="input"){const r=n.getArguments()[0];r&&i.isObjectLiteralExpression(r)?(t.push(r),s||=Pt(r)):s=!0}n=o.getExpression()}return{objects:t,opaque:s}},wt=(e,t)=>t?cr(t):ar(e),lr=e=>e.flatMap(t=>t.getProperties().filter(s=>i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)).map(s=>s.getName())),ur=/\.check\(|\.meta\(|length|max/iu,dr=/\bv\.any\s*\(/u,fr=/\bv\.string\s*\(/u,pr=e=>dr.test(e),gr=e=>fr.test(e)&&!ur.test(e),mr=e=>{const t=[],s=[];for(const n of e)for(const o of n.getProperties()){if(!i.isPropertyAssignment(o))continue;const r=o.getInitializer();if(!r)continue;const a=r.getText(),c=o.getName();pr(a)?t.push(c):gr(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},hr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=M(s);if(n?.visibility!=="public")return;const{objects:o}=wt(s,n.receiver),{anyArgs:r,unboundedStringArgs:a}=mr(o);if(!(r.length===0&&a.length===0))return{anyArgs:r,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},xr=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=hr(o,t);r&&s.push(r)}return s},Er=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...xr(o,x(t,n)))}return s},pe=e=>e?.getKind()===l.TrueKeyword,vr=e=>e?.getKind()===l.FalseKeyword,Sr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Ar=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Nr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&P(t.getExpression())==="scim"),yr=e=>e!==void 0&&i.isCallExpression(e)&&Ar.has(P(e.getExpression())??""),br=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),Ir=e=>{const t=A(e,"advanced"),s=A(e,"emailAndPassword"),n=A(e,"session");return{analyzable:!0,disableCsrfCheck:pe(A(t,"disableCSRFCheck")),emailPasswordEnabled:pe(A(s,"enabled")),requireEmailVerification:pe(A(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Nr(A(e,"plugins"))&&yr(A(e,"database")),secureCookiesDisabled:vr(A(t,"useSecureCookies")),sessionFreshAgeZero:Sr(A(n,"freshAge")),trustedOriginsWildcard:br(A(e,"trustedOrigins"))}},Pr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),wr=(e,t)=>{if(P(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(r=>i.isSpreadAssignment(r)),o=s!==void 0&&i.isObjectLiteralExpression(s)&&!n?Ir(s):Pr();return{exportName:v(e),file:t,line:e.getStartLineNumber(),...o}},Tr=(e,t)=>b(e,t,wr),Cr=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},Rr=(e,t,s)=>{const n=Cr(e.getExpression(),s);if(n===void 0)return;const o=e.getArguments()[s.argIndex];if(!(!o||!T(o)||k(o))&&!(s.requireUnmodifiedReach===!0&&!Fs(o)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:n}},Or=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression)){const r=Rr(o,t,s);r&&n.push(r)}return n},ne=(e,t,s)=>{const n=[];for(const o of m(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...Or(r,x(t,o),s))}return n},Fr=new Set(["content","pdf","scrape","screenshot"]),Lr=(e,t)=>ne(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Fr}),Dr=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),kr=new Set(["RateLimiter"]),Mr=new Set(["extend"]),Tt=e=>{const t=[],s=[];let n=!1;for(const o of e.getProperties()){if(i.isSpreadAssignment(o)){n=!0;continue}if(i.isPropertyAssignment(o)){const r=o.getName();t.push(r),o.getInitializer()?.getKind()===l.TrueKeyword&&s.push(r);continue}(i.isShorthandPropertyAssignment(o)||i.isMethodDeclaration(o))&&t.push(o.getName())}return{analyzable:!n,presentKeys:t,trueKeys:s}},tt=e=>e&&i.isObjectLiteralExpression(e)?Tt(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Kr=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!i.isReturnStatement(s))return;const n=s.getExpression();return n!==void 0&&i.isObjectLiteralExpression(n)?n:void 0},_r=e=>{if(i.isObjectLiteralExpression(e))return e;if(i.isParenthesizedExpression(e)){const t=e.getExpression();return i.isObjectLiteralExpression(t)?t:void 0}return i.isBlock(e)?Kr(e):void 0},zr=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&_r(t.getBody());return s?Tt(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Ur=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=P(n.getExpression());o!==void 0&&(Dr.has(o)?s.push({callee:o,file:t,line:n.getStartLineNumber(),...tt(n.getArguments()[0])}):Mr.has(o)&&s.push({callee:o,file:t,line:n.getStartLineNumber(),...zr(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(l.NewExpression)){const o=P(n.getExpression());o===void 0||!kr.has(o)||s.push({callee:o,file:t,line:n.getStartLineNumber(),...tt(n.getArguments()[0])})}return s},Br=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ur(o,x(t,n)))}return s},st="ctx.containers.",qr=e=>{if(!e.startsWith(st))return!1;const t=e.slice(st.length);return t.length>0&&!t.includes(".")},$r=(e,t)=>ne(e,t,{argIndex:0,matchReceiver:qr,methods:new Set(["get"])}),jr=new Set(["allow","deny","setAllowed"]),Vr=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},Wr=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!Vr(e)))return{detail:"enableInternet: true",exportName:v(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},Hr=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!jr.has(s.getName()))return;const n=s.getExpression();if(!(!i.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),exportName:v(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},Gr=(e,t)=>Wr(e,t)??Hr(e,t),Yr=(e,t)=>b(e,t,Gr),Qr=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Xr=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return Qr.has(s)?s:void 0},Zr=e=>{const t=[],s=[];for(const n of e.getProperties()){if(i.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o);const r=n.getInitializer();r&&i.isStringLiteral(r)&&r.getLiteralText()===""&&s.push(o);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n)||i.isGetAccessorDeclaration(n))&&t.push(n.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Jr=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression)){const c=Xr(a);if(c===void 0)continue;const u=a.getArguments()[0],d=u&&i.isObjectLiteralExpression(u)?Zr(u):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:d.analyzable,emptyKeys:d.emptyKeys,factory:c,file:r,line:a.getStartLineNumber(),presentKeys:d.presentKeys})}}return s},ei=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),ti=new Set(["dbRateLimit","rateLimit"]),si=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&i.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===l.TrueKeyword},ni=(e,t)=>{const s=P(e.getExpression());if(s===void 0)return;const n=ei.get(s);if(n!==void 0)return{callee:s,exportName:v(e),failOpen:si(e.getArguments()[n]),file:t,limitName:ti.has(s)?St(e):"",line:e.getStartLineNumber()}},ri=(e,t)=>b(e,t,ni),ii=e=>{const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const s=M(t);if(s?.kind!=="query")return;const n=As(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},nt=e=>{const t=e.getParent();return t&&i.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},oi=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!i.isIdentifier(t)||t.getText()!=="ctx")return;const s=nt(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=nt(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},ai=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const o=oi(n);o!==void 0&&s.push({callee:o,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},ci=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=ii(o);r&&s.push(...ai(r,t))}return s},li=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ci(o,x(t,n)))}return s},ui=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Ns(t.getExpression())},di=e=>{if(e?.getKind()===l.TrueKeyword)return!0;if(e?.getKind()===l.FalseKeyword)return!1},fi=(e,t)=>{if(!ui(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const o=s.getLiteralValue(),r=di(n);if(!(o.length===0||r===void 0))return{defaultValue:r,exportName:v(e),file:t,key:o,line:e.getStartLineNumber()}},pi=(e,t)=>b(e,t,fi),gi=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},mi=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},hi=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression))gi(a)&&s.push({file:r,indexName:mi(a),line:a.getStartLineNumber()})}return s},xi=new Set(["delete","get","head","options","patch","post","put"]),Ei=new Set(["handler","stream"]),vi=new Set(["runAction","runMutation"]),Si=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),Q=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,rt=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,it=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const n=s.getNameNode();if(t)return i.isIdentifier(n)?n.getText():void 0;if(i.isObjectBindingPattern(n)){for(const o of n.getElements())if((o.getPropertyNameNode()?.getText()??o.getNameNode().getText())==="ctx"){const a=o.getNameNode();return i.isIdentifier(a)?a.getText():void 0}}},ot=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);i.isCallExpression(s)&&n.unshift(s);for(const o of n){const r=o.getExpression();if(!i.isPropertyAccessExpression(r))continue;const a=r.getName(),c=r.getExpression();if(vi.has(a)&&Q(c,t))return a;if(Si.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&Q(c.getExpression(),t))return`db.${a}`}},at=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(l.PropertyAccessExpression))if(n.getName()==="auth"&&Q(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(l.VariableDeclaration)){const o=n.getNameNode();if(!(!i.isObjectBindingPattern(o)||!Q(n.getInitializer(),t))){for(const r of o.getElements())if((r.getPropertyNameNode()?.getText()??r.getNameNode().getText())==="auth")return!0}}return!1},Ai=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Ei.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))return;const o=n.getName();if(xi.has(o)){const r=n.getExpression();return i.isIdentifier(r)&&r.getText()==="httpRoute"?o.toUpperCase():void 0}s=n.getExpression()}},Ni=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=rt(e.getArguments()[0]),u=c&&it(c,!0);if(!c||u===void 0)return;const d=ot(c,u);return d===void 0?void 0:{exportName:v(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:at(c,u),sideEffect:d}}const n=Ai(e);if(n===void 0)return;const o=rt(e.getArguments()[0]),r=o&&it(o,!1);if(!o||r===void 0)return;const a=ot(o,r);return a===void 0?void 0:{exportName:v(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:at(o,r),sideEffect:a}},yi=(e,t)=>b(e,t,Ni),bi=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),Ii=new Set(["append","set"]),Ee=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",Ct=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",ct=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(l.CallExpression)]:e.getDescendantsOfKind(l.CallExpression)).some(n=>bi.has(Ee(n.getExpression()))&&Ds(n,t)),Pi=(e,t)=>{if(ct(e,t))return!0;const s=se(e);return s!==void 0&&ct(s,t)},he=(e,t)=>Ls(e,t)&&!Pi(e,t),wi=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=se(e);return t!==void 0&&i.isNewExpression(t)&&Ee(t.getExpression())==="Headers"},X=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=se(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},ve=(e,t,s)=>{for(const n of e.getProperties())if(i.isPropertyAssignment(n)){const o=n.getInitializer();o!==void 0&&he(o,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:Ct(n.getNameNode()),line:o.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(n)){const o=n.getNameNode();he(o,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:n.getName(),line:o.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(n)){const o=X(n.getExpression());o!==void 0&&ve(o,t,s)}},Rt=(e,t)=>{const s=X(e);if(s===void 0)return;const n=s.getProperty("headers");if(n===void 0||!i.isPropertyAssignment(n))return;const o=X(n.getInitializer());o!==void 0&&ve(o,"response-init",t)},Ti=(e,t)=>{const s=Ee(e.getExpression());if(s==="Response")Rt(e.getArguments()[1],t);else if(s==="Headers"){const n=X(e.getArguments()[0]);n!==void 0&&ve(n,"headers-ctor",t)}},Ci=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName(),o=s.getExpression();if(n==="json"&&i.isIdentifier(o)&&o.getText()==="Response"){Rt(e.getArguments()[1],t);return}if(Ii.has(n)&&wi(o)){const r=e.getArguments()[1];r!==void 0&&he(r,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:Ct(e.getArguments()[0]),line:r.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},Ri=(e,t)=>{for(const s of e.getDescendantsOfKind(l.NewExpression))Ti(s,t);for(const s of e.getDescendantsOfKind(l.CallExpression))Ci(s,t)},Oi=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=Ms(e.getArguments()[0]);if(n===void 0)return[];const o=n.getParameters()[1];if(o===void 0)return[];const r=o.getNameNode();if(!i.isIdentifier(r))return[];const a=[];return Ri(n,{exportName:v(e),relativePath:t,requestName:r.getText(),rows:a}),a},Fi=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression))s.push(...Oi(n,t));return s},Li=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Fi(o,x(t,n)))}return s},Di=new Set(["auth","context.auth","ctx.auth"]),ki="userId",Mi=e=>{const t=new Set;for(const s of e.getProperties()){if(i.isSpreadAssignment(s))return;(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s))&&t.add(s.getName())}return t},Ki=(e,t)=>{const s=f(t,bt);if(!y(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const o of n.getDescendantsOfKind(l.CallExpression)){if(P(o.getExpression())!=="defineIdentity")continue;const[r]=o.getArguments();return r&&i.isObjectLiteralExpression(r)?Mi(r):void 0}},lt=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Di.has(e.getExpression().getText())?e:void 0},_i=e=>{if(i.isPropertyAccessExpression(e)&&lt(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&lt(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},zi=(e,t,s)=>{const n=[];for(const o of e.getDescendants()){const r=_i(o);r!==void 0&&n.push({declared:r===ki||s.has(r),exportName:v(o),file:t,key:r,line:o.getStartLineNumber()})}return n},Ui=(e,t)=>{const s=Ki(e,t);if(s===void 0)return[];const n=[];for(const o of m(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);n.push(...zi(r,x(t,o),s))}return n},Bi=(e,t)=>{if(P(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=A(s,"key");if(!(!n||!T(n)||k(n)))return{exportName:v(e),file:t,line:e.getStartLineNumber()}},qi=(e,t)=>b(e,t,Bi),$i=new Set(["delete","get","getRaw","getWithMetadata","put"]),ji=(e,t)=>ne(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:$i}),Vi=new Set(["queue","send"]),ut=new Set(["bcc","cc","to"]),Wi=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Vi.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},Hi=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return ut.has(t.getName())&&T(n)&&!k(n)}if(!i.isPropertyAssignment(t)||!ut.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&T(s)&&!k(s)}):!1,Gi=(e,t)=>{const s=Wi(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!Hi(n)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s}},Yi=(e,t)=>b(e,t,Gi),Qi=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},Xi=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},Zi=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==l.CallExpression)return;const s=t;return Ys(s.getExpression())?s:void 0},Ji=e=>{const t=Zi(e),s=t===void 0?void 0:Xi(t);if(s===void 0)return[];const n=e.getNameNode(),o=i.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(l.CallExpression).filter(r=>Qi(r)).map(r=>({exportName:o,file:"lunora/mutators.ts",line:r.getStartLineNumber()}))},eo=e=>e.getVariableDeclarations().flatMap(t=>Ji(t)),to=(e,t)=>{const s=f(t,Gs);if(!y(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return eo(n)},so=new Set(["delete","get","patch"]),no=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),ro=new Set(["auth","identity","session","user"]),io=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),oo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!_(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},ao=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(i.isAsExpression(s)||i.isParenthesizedExpression(s)||i.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!i.isVariableDeclaration(s))return;const n=s.getNameNode();return i.isIdentifier(n)?n.getText():void 0},co=(e,t)=>e.getDescendantsOfKind(l.Identifier).some(s=>s.getText()===t),lo=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(l.ThrowStatement).length>0||e.getDescendantsOfKind(l.ReturnStatement).length>0,uo=(e,t)=>e.getDescendantsOfKind(l.IfStatement).some(s=>co(s.getExpression(),t)&&lo(s.getThenStatement())),fo=(e,t)=>{for(const s of e.getDescendantsOfKind(l.CallExpression)){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))continue;const o=n.getName();if(!so.has(o))continue;const r=n.getExpression();if(!(_(r)||i.isPropertyAccessExpression(r)&&_(r.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&i.isIdentifier(c)&&c.getText()===t)return o}},po=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t)||i.isParenthesizedExpression(t)||i.isAsExpression(t)||i.isAwaitExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t.getText():void 0},go=e=>e.getDescendantsOfKind(l.CallExpression).some(t=>t.getArguments().some(s=>po(s)==="ctx")),mo=e=>e.getDescendantsOfKind(l.BinaryExpression).some(t=>io.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),ho=e=>{for(const t of e.getDescendantsOfKind(l.Identifier))if(no.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&ro.has(t.getName()))return!0}return go(e)||mo(e)},xo=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=M(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const o=Nt(s);if(o===void 0)return[];const r=n.receiver!==void 0&&yt(n.receiver,"use","rls"),a=ho(o),c=new Set,u=[];for(const d of o.getDescendantsOfKind(l.CallExpression)){const E=oo(d);if(E===void 0)continue;const N=ao(d);if(N===void 0||c.has(N)||!uo(o,N))continue;const p=fo(o,N);p!==void 0&&(c.add(N),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:p,table:E,usesRls:r,visibility:n.visibility}))}return u},Eo=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...xo(c,r))}return s},vo=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),So=new Set(["insert","insertManyUnsafe","patch","replace"]),Ao=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!So.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="db")return;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="ctx"?t:void 0},No=(e,t)=>{if(t!=="insertManyUnsafe")return i.isObjectLiteralExpression(e)?[e]:[];if(!i.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())i.isObjectLiteralExpression(n)&&s.push(n);return s},yo=(e,t,s,n)=>{const o=[];for(const r of e.getProperties()){let a,c;i.isPropertyAssignment(r)?(a=r.getName(),c=r.getInitializer()):i.isShorthandPropertyAssignment(r)&&(a=r.getName(),c=r.getNameNode()),!(a===void 0||c===void 0||!vo.has(a))&&T(c)&&!k(c)&&o.push({exportName:v(s),field:a,file:n,line:s.getStartLineNumber(),method:t})}return o},bo=(e,t)=>{const s=Ao(e.getExpression());if(s===void 0)return[];const n=e.getArguments()[1];return n?No(n,s).flatMap(o=>yo(o,s,e,t)):[]},Io=(e,t,s)=>{const n=[];for(const o of e.getDescendantsOfKind(l.CallExpression))for(const r of bo(o,t)){const a=s(r.exportName);n.push(a===void 0?r:{...r,visibility:a})}return n},Po=(e,t,s=[])=>{const n=[],o=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));for(const r of m(t)){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=x(t,r);n.push(...Io(a,c,u=>o.get(`${c}:${u}`)))}return n},wo=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),To=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Co=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?To(t.getInitializer()):void 0},Ro=(e,t)=>{const s=P(e.getExpression());if(s===void 0||!wo.has(s))return;const[n]=e.getArguments(),o=n&&i.isObjectLiteralExpression(n)?Co(n):void 0;return{callee:s,exportName:v(e),file:t,line:e.getStartLineNumber(),...o===void 0?{}:{toleranceSeconds:o}}},Oo=(e,t)=>b(e,t,Ro),Fo=new Set(["defineQueue","defineWorkflow"]),Lo=new Set(["run","runAction","runMutation","runQuery"]),Do=new Set(["api","internal"]),ko=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},Mo=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!i.isPropertyAssignment(s))return;const n=s.getInitializer();if(n&&(i.isArrowFunction(n)||i.isFunctionExpression(n)))return n},Ot=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},Ft=(e,t)=>e===t||e.startsWith(`${t}.`),Lt=e=>{const t=e.getDescendantsOfKind(l.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},dt=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e||i.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(i.isBindingElement(t)&&t.getNameNode()===e)},Dt=e=>{const t=e.getDescendantsOfKind(l.Identifier).filter(s=>dt(s));return i.isIdentifier(e)&&dt(e)&&t.push(e),t},Ko=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(l.BindingElement).map(s=>s.getName())},_o=e=>{const t=Ot(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(l.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const o=n.getInitializer(),r=i.isVariableDeclarationList(o)?o.getDeclarations()[0]?.getNameNode():void 0;r&&i.isIdentifier(r)&&s.push(`${r.getText()}.body`)}return s},zo=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:_o(e),o=new Set,r=a=>Lt(a).some(c=>n.some(u=>Ft(c.getText(),u)))?!0:Dt(a).some(c=>o.has(c.getText()));for(const a of e.getDescendantsOfKind(l.VariableDeclaration)){const c=a.getInitializer();if(c&&r(c))for(const u of Ko(a))o.add(u)}return{names:o,prefixes:n}},Uo=(e,t)=>Lt(e).some(s=>t.prefixes.some(n=>Ft(s.getText(),n)))?!0:Dt(e).some(s=>t.names.has(s.getText())),Bo=e=>{if(e===void 0||!i.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;i.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const n=t.at(-1);if(!(n===void 0||!i.isIdentifier(s)||!Do.has(s.getText())||t.length<2))return{exportName:n,file:t.slice(0,-1).join("/")}},qo=(e,t,s)=>{const n=Ot(e,0);if(n===void 0)return[];const o=zo(e,t,n),r=[];for(const a of e.getDescendantsOfKind(l.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!Lo.has(c.getName())||c.getExpression().getText()!==n)continue;const u=a.getArguments()[1];if(!u||!Uo(u,o))continue;const d=Bo(a.getArguments()[0]);d!==void 0&&r.push({dispatchKind:t,file:s,handlerExport:v(a),line:a.getStartLineNumber(),targetExport:d.exportName,targetFile:d.file})}return r},$o=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=ko(n);if(o===void 0||!Fo.has(o))continue;const r=Mo(n);r!==void 0&&s.push(...qo(r,o==="defineQueue"?"queue":"workflow",t))}return s},jo=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...$o(o,x(t,n)))}return s},ft={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},pt=new Set(["account","credential","member","passkey","session","user"]),Vo=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),Wo=e=>{const s=Vo(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return pt.has(s)||pt.has(n)},Ho=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Go=(e,t)=>{const{objects:s,opaque:n}=wt(e,t);return lr(s).some(o=>Ho(o))?!0:n?void 0:!1},Se=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},Yo=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Qo=e=>{if(i.isCallExpression(e))return e;if(!i.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&i.isCallExpression(s)?s:void 0},Y={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Xo=e=>{const t=Qo(e),s=t?Se(t):void 0;if(t&&s==="protectPublic"){const n=Yo(t);return{...Y,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in ft?{...Y,[ft[s]]:!0}:Y},Zo=e=>{const t={...Y};let s=e;for(;i.isCallExpression(s);){const n=s.getExpression();if(!i.isPropertyAccessExpression(n))break;const o=n.getName()==="use"?s.getArguments()[0]:void 0;if(o){const r=Xo(o);t.usesCaptcha||=r.usesCaptcha,t.usesEmailGate||=r.usesEmailGate,t.usesMask||=r.usesMask,t.usesRateLimit||=r.usesRateLimit,t.usesRls||=r.usesRls}s=n.getExpression()}return t},Jo=new Set(["insert","insertMany","insertManyUnsafe","replace"]),ea=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Jo.has(t.getName()))return!1;const s=t.getExpression();if(!(i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"))return!1;const o=e.getArguments()[0];return!o||!(i.isStringLiteral(o)||i.isNoSubstitutionTemplateLiteral(o))?!1:Wo(o.getLiteralText())},ta=new Set(["create","runAfter","runAt","send","sendBatch"]),sa=new Set(["queues","scheduler","workflows"]),na=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ta.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&sa.has(s.getName())){const n=s.getExpression();if(i.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},ra=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},kt=new Set(["generateObject","generateText","streamObject","streamText"]),ia=e=>{const t=Se(e);return t!==void 0&&kt.has(t)},oa=e=>{const t=Se(e);if(t===void 0||!kt.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(n=>i.isSpreadAssignment(n))?!1:!s.getProperty("maxOutputTokens")},aa=new Set(["log","span","trace"]),ca=new Set(["ai"]),la=new Set(["email","mail"]),ua=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),ge=(e,t)=>e.getDescendantsOfKind(l.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="ctx"}),da=new Set([l.ArrowFunction,l.FunctionDeclaration,l.FunctionExpression,l.GetAccessor,l.MethodDeclaration,l.SetAccessor]),fa=new Set(["every","filter","flatMap","forEach","map","some"]),pa=new Set(["all","allSettled","race"]),ga=e=>{const t=e.getParent();if(!t||!i.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;const n=s.getName();if(fa.has(n))return t;const o=s.getExpression();if(i.isIdentifier(o)&&o.getText()==="Promise"&&pa.has(n))return t},ma=e=>{let t=e.getParent();for(;t;){if(i.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(da.has(t.getKind())){const s=ga(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},ha=e=>{let t=e;for(;;){const s=t.getParent();if(!i.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;if(s.getName()==="catch")return!0;if(s.getName()!=="then"&&s.getName()!=="finally")return!1;const n=s.getParent();if(!i.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},xa=e=>{let t=e;for(;;){const s=t.getParent();if(i.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return i.isCallExpression(s)&&s.getExpression()===t?s:void 0}},Ea=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression)){if(!ua.has(n.getName()))continue;const o=n.getExpression();if(!i.isIdentifier(o)||o.getText()!=="ctx")continue;const r=xa(n);r&&(t=!0,!ma(r)&&!ha(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},va=e=>e.getDescendantsOfKind(l.ThrowStatement).some(t=>{const s=t.getExpression();if(!i.isNewExpression(s))return!1;const n=s.getExpression();return i.isIdentifier(n)&&n.getText()==="Error"}),gt="lunora-advisor-exempt",Sa=/^[\s*/]+/u,Aa=/[\w-]/u,Na=e=>{const s=(e.getFirstAncestorByKind(l.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
6
- `);for(const n of s.split(`
7
- `)){const o=n.replace(Sa,"");if(!o.startsWith(gt))continue;const r=o.slice(gt.length);if(Aa.test(r.charAt(0)))continue;const a=r.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":r.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},ya=e=>{const[t]=e.getArguments();if(t){if(i.isObjectLiteralExpression(t)){const s=t.getProperty("handler");return s?i.isPropertyAssignment(s)?s.getInitializer():i.isShorthandPropertyAssignment(s)?s.getNameNode():i.isMethodDeclaration(s)?s:void 0:void 0}return t}},ba=(e,t)=>{const s=ya(t);if(!s)return;if(i.isArrowFunction(s)||i.isFunctionExpression(s)||i.isMethodDeclaration(s))return e;if(!i.isIdentifier(s))return;const n=s.getSourceFile(),o=s.getText(),r=n.getVariableDeclaration(o)?.getInitializer();return r&&(i.isArrowFunction(r)||i.isFunctionExpression(r))?r:n.getFunction(o)},Ia=e=>{let t=!1,s=!1,n=!1,o=!1,r=!1;for(const u of e.getDescendantsOfKind(l.CallExpression))if(ea(u)&&(r=!0),na(u)&&(t=!0),ra(u)&&(o=!0),ia(u)&&(s=!0),oa(u)&&(n=!0),r&&t&&o&&n)break;const{handlesErrors:a,reachesOutbound:c}=Ea(e);return{callsMail:ge(e,la),emitsEvent:ge(e,aa),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||ge(e,ca),throwsBareError:va(e),unboundedAiGeneration:n,usesInsertManyUnsafe:o,writesUserTable:r}},Pa=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const n=M(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const o=n.receiver?Zo(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},r=ba(e,s);return{...r?Ia(r):{},...Na(e),...o,analyzableBody:r!==void 0,exportName:e.getName(),file:t,hasEmailArg:Go(s,n.receiver),kind:n.kind,visibility:n.visibility}},wa=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const o of n.getDeclarations()){const r=Pa(o,t);r&&s.push(r)}return s},Ta=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...wa(o,x(t,n)))}return s},Ca=new Set(["dbRateLimit","rateLimit"]),Ra=e=>i.isArrowFunction(e)?e.getBody():e,Oa=(e,t)=>{const s=P(e.getExpression());if(s===void 0||!Ca.has(s))return;const n=e.getArguments()[2];if(!n)return;const o=A(n,"key");if(!o)return;const r=Ra(o);if(!(!T(r)||k(r)))return{callee:s,exportName:v(e),file:t,limitName:St(e),line:e.getStartLineNumber()}},Fa=(e,t)=>b(e,t,Oa),La=new Set(["findFirst","findFirstOrThrow","findMany","get"]),Da=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!La.has(t.getName()))return;const s=t.getExpression();if(_(s)){const n=e.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&_(s.getExpression()))return s.getName()},ka=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&_(s.getExpression())){const n=t.getArguments()[0];return n&&i.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},Ma=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},Mt=(e,t=!1)=>{const s=Ma(e);if(i.isIdentifier(s)){if(t)return;const n=se(s);return n===void 0?void 0:Mt(n,!0)}if(i.isCallExpression(s))return Da(s)??ka(s)},Ka=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(l.ReturnStatement)){const o=n.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),r=n.getExpression();o===e&&r!==void 0&&s.push(r)}return s},_a=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const n=M(s);if(n?.kind!=="query")return[];const o=Nt(s);if(o===void 0)return[];const r=n.receiver!==void 0&&Ks(n.receiver,"output"),a=n.receiver!==void 0&&yt(n.receiver,"use","mask"),c=new Set,u=[];for(const d of Ka(o)){const E=Mt(d);E===void 0||c.has(E)||(c.add(E),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:E,usesMask:a,usesOutput:r,visibility:n.visibility}))}return u},za=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(..._a(c,r))}return s},Ua=e=>{if(!e||!i.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s)||i.isGetAccessorDeclaration(s))&&t.push(s.getName());return t},Ba=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?M(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=At(r);if(a===void 0)continue;const c=Ua(A(a.options,"with"));c.length!==0&&o.push({exportName:e.getName(),file:t,line:r.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return o},qa=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Ba(c,r))}return s},Z=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===l.PlusToken){const t=Z(e.getLeft()),s=Z(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},$a=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===l.PlusToken;)t=s,s=t.getParent();return t!==e&&Z(t)!==void 0},ja=/(?:^|\/)__tests__\//u,Va=/\.(?:spec|test)$/u,Wa=e=>ja.test(e)||Va.test(e),Ha=e=>{const t=e.getParent();if(t!==void 0){if(i.isVariableDeclaration(t)||i.isPropertyAssignment(t)||i.isPropertySignature(t))return t.getName();if(i.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.EqualsToken)return t.getLeft().getText()}},Ga=(e,t,s)=>on(e)?!Wa(s)&&an(Ha(t)):!0,Ya=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(l.BinaryExpression),...e.getDescendantsOfKind(l.StringLiteral),...e.getDescendantsOfKind(l.NoSubstitutionTemplateLiteral)],o=new Set;for(const r of n){if($a(r))continue;const a=Z(r);if(a===void 0)continue;const c=nn(a);if(c===void 0||!Ga(c,r,t))continue;const u=r.getStartLineNumber(),d=`${String(u)}:${c}`;o.has(d)||(o.add(d),s.push({file:t,kind:c,line:u,preview:rn(a)}))}return s},Qa=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ya(o,x(t,n)))}return s},Xa=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&i.isCallExpression(s)?M(s):void 0;if(!n)return[];const o=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=At(r);if(a===void 0)continue;const c=A(a.options,"includeDeleted");if(c===void 0)continue;const u=i.isTrueLiteral(c),d=!u&&T(c);!u&&!d||o.push({exportName:e.getName(),file:t,fromArgs:d,hardcodedTrue:u,line:r.getStartLineNumber(),table:a.table,visibility:n.visibility})}return o},Za=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Xa(c,r))}return s},Ja=new Set(["query","unsafe"]),ec=e=>{if(!i.isPropertyAccessExpression(e)||!Ja.has(e.getName()))return!1;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return i.isIdentifier(s)&&s.getText()==="ctx"},tc=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),sc=e=>e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()??"<module>",nc=(e,t)=>{if(!ec(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!tc(s)))return{exportName:sc(e),file:t,line:s.getStartLineNumber()}},rc=(e,t)=>b(e,t,nc),ic=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],oc=e=>{for(const[t,s]of ic)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},ac=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of o.getImportDeclarations()){const a=r.getModuleSpecifierValue(),c=oc(a);c!==void 0&&s.push({file:x(t,n),line:r.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},cc=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),lc=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return ne(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:cc,requireUnmodifiedReach:!0}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},uc=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),dc=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,fc=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!i.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const o of e.getProperties()){if(i.isSpreadAssignment(o)){n=!0;continue}if(i.isPropertyAssignment(o)){const r=o.getName();t.push(r),r==="expiresInSeconds"&&(s=dc(o.getInitializer()));continue}(i.isShorthandPropertyAssignment(o)||i.isMethodDeclaration(o))&&t.push(o.getName())}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},pc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=uc.get(t);if(s===void 0)return;const n=e.getExpression().getText();return n==="ctx.storage"||n.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},gc=(e,t)=>{const s=pc(e.getExpression());if(s!==void 0)return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s.method,...fc(e.getArguments()[s.optionsIndex])}},mc=(e,t)=>b(e,t,gc),hc=new Set(["RegisteredAction","RegisteredMutation","RegisteredQuery"]),Ae=e=>{const t=e.getType(),s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName();return s!==void 0&&hc.has(s)?s:void 0},Kt=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},_t={cause:"codegen recognises a procedure only when the initializer is a builder chain, and this one is produced by a call or an alias",remediation:"A factory that returns a procedure cannot be read statically — inline it, or export the chain the factory builds."},xc={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."},Ne=(e,t,s,n,o)=>({cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally a builder chain. A procedure written any other way exists at runtime but never reaches `_generated/api.ts`, so no caller can address it.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${s}\` but was not registered — ${o.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:s},name:"procedure_not_registered",remediation:`Assign the builder chain directly: \`export const ${t} = query.input({ … }).query(handler);\`. ${o.remediation}`,title:"Procedure exists at runtime but is missing from the generated API"}),Ec=(e,t,s)=>{const n=[];for(const o of e.getVariableStatements().filter(r=>r.isExported()))for(const r of o.getDeclarations()){const a=r.getName();if(s.has(`${t}:${a}`)||!Kt(r))continue;const c=Ae(r);c!==void 0&&n.push(Ne(t,a,c,r.getStartLineNumber(),_t))}return n},vc=(e,t,s)=>{if(s.has(`${t}:default`))return[];const n=[];for(const o of e.getExportAssignments().filter(r=>!r.isExportEquals())){const r=Ae(o.getExpression());r!==void 0&&n.push(Ne(t,"default",r,o.getStartLineNumber(),_t))}return n},Sc=(e,t,s)=>{const n=[];for(const o of e.getExportDeclarations().filter(r=>r.getModuleSpecifier()===void 0))for(const r of o.getNamedExports()){const a=r.getAliasNode()?.getText()??r.getName();if(s.has(`${t}:${a}`))continue;const c=r.getLocalTargetDeclarations().find(d=>i.isVariableDeclaration(d));if(c===void 0||!Kt(c))continue;const u=Ae(c);u!==void 0&&n.push(Ne(t,a,u,r.getStartLineNumber(),xc))}return n},Ac=(e,t,s)=>[...Ec(e,t,s),...vc(e,t,s),...Sc(e,t,s)],Nc=(e,t,s)=>{const n=new Set(s.map(r=>`${r.filePath}:${r.exportName}`)),o=[];for(const r of m(t)){const a=e.getSourceFile(r);a!==void 0&&o.push(...Ac(a,x(t,r),n))}return o.toSorted((r,a)=>r.cacheKey.localeCompare(a.cacheKey))},yc=new Set(["when","where"]),me=new Set(["definePolicy","defineShape"]),bc=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const n=t.getName();return me.has(n)?n:void 0}if(!i.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(n)){const o=n.getNameNode().getText();return me.has(o)?o:void 0}const s=t.getText();return me.has(s)?s:void 0},Ic=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,zt=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===l.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Ic(e))return"empty-object";if(i.isParenthesizedExpression(e))return zt(e.getExpression())}},ye=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Pc=e=>e.getDescendantsOfKind(l.ReturnStatement).filter(t=>ye(t)===e),Ut=e=>e.getDescendantsOfKind(l.ConditionalExpression).filter(t=>ye(t)===e),wc=e=>{const t=Pc(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(l.IfStatement)!==void 0)||Ut(e).length>0},Tc=e=>e.getDescendantsOfKind(l.IfStatement).filter(t=>ye(t)===e),xe=e=>e.getKind()===l.NullKeyword||e.getKind()===l.FalseKeyword||i.isIdentifier(e)&&e.getText()==="undefined"?!0:i.isNumericLiteral(e)?e.getLiteralValue()===0:i.isStringLiteral(e)&&e.getLiteralValue()==="",Cc=(e,t)=>xe(e)||xe(t),Rc=new Map([[l.EqualsEqualsEqualsToken,"positive"],[l.EqualsEqualsToken,"positive"],[l.ExclamationEqualsEqualsToken,"negative"],[l.ExclamationEqualsToken,"negative"]]),mt=e=>!xe(e)&&(i.isLiteralExpression(e)||e.getKind()===l.TrueKeyword),Oc=(e,t,s)=>{const n=Rc.get(e);if(n!==void 0)return Cc(t,s)?n==="positive"?"negative":"positive":mt(t)||mt(s)?void 0:n},$=e=>{if(i.isParenthesizedExpression(e))return $(e.getExpression());if(i.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken)return"negative";if(i.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=Oc(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===l.AmpersandAmpersandToken||t===l.BarBarToken){const n=$(e.getLeft()),o=$(e.getRight());return n===o?n:"indeterminate"}}return i.isIdentifier(e)||i.isPropertyAccessExpression(e)||i.isElementAccessExpression(e)||i.isCallExpression(e)?"positive":"indeterminate"},ht=e=>{if(e!==void 0){if(i.isReturnStatement(e))return e;if(i.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&i.isReturnStatement(t)?t:void 0}}},Fc=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(l.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Lc=e=>i.isReturnStatement(e)?e.getExpression()??e:e,Dc=e=>{const t=[];for(const s of Ut(e)){const n=$(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of Tc(e)){const n=$(s.getExpression());if(n==="indeterminate")continue;const o=n==="negative"?ht(s.getThenStatement()):ht(s.getElseStatement())??Fc(s);o!==void 0&&t.push(Lc(o))}return t},kc=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},Mc=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!i.isObjectLiteralExpression(n))return[];const o=[];for(const r of n.getProperties()){if(!i.isPropertyAssignment(r)||!yc.has(r.getName()))continue;const a=r.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&wc(a))for(const c of Dc(a)){const u=zt(c);u!==void 0&&o.push({exportName:kc(e),file:s,form:u,key:r.getName(),line:c.getStartLineNumber(),owner:t})}}return o},Kc=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const o=bc(n);o!==void 0&&s.push(...Mc(n,o,t))}return s},_c=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Kc(o,x(t,n)))}return s},zc=new Set(["query","upsert","upsertMany"]),Uc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(zc.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Bc=(e,t)=>{const s=Uc(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const o=A(n,"namespace");if(!(!o||!T(o)||k(o)))return{exportName:v(e),file:t,line:e.getStartLineNumber(),method:s}},qc=(e,t)=>b(e,t,Bc),$c=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="workflows":i.isIdentifier(s)&&s.getText()==="workflows"},jc=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Vc=(e,t)=>{const s=[];for(const n of m(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=x(t,n);for(const a of o.getDescendantsOfKind(l.CallExpression)){if(!$c(a))continue;const c=ys(a);c!==""&&s.push({exportName:c,file:r,line:a.getStartLineNumber(),workflow:jc(a)})}}return s},Wc=".lunora-schema.json",I=(e,t)=>{y(e)&&vt(e,"utf8")===t||Zt(e,t,"utf8")},w=(e,t)=>{if(t===""){Jt(e,{force:!0});return}I(e,t)},Hc=e=>{const t=f(e,"package.json");if(y(t))try{const s=JSON.parse(vt(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},Gc=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Yc=e=>{let t=y(e)?e:ue(e);for(;t&&t!==ue(t);){const s=f(t,"tsconfig.json");if(y(s))return s;t=ue(t)}},xt=e=>e.replaceAll("\\","/"),Qc=(e,t,s)=>{if(s&&e.length>0){const r=e.map(a=>`"${a.exportName}"`).join(", ");throw new D("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${r}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const r of t.columns){const a=n.get(r.table)??[];a.push(r.column),n.set(r.table,a)}const o=t.columns.length>0;for(const r of e){if(r.table===void 0){if(o)throw new D("MASK_UNSUPPORTED",`defineShape "${r.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${r.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(r.table);if(a===void 0)continue;const c=a.map(u=>`"${u}"`).join(", ");throw new D("MASK_UNSUPPORTED",`defineShape "${r.exportName}" replicates table "${r.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},J=(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)},Et=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,Xc=8,Zc=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:o,migrations:r,project:a,shapes:c,usesSandbox:u,useUmbrella:d,workflows:E}=e;let N=Qe(a,o),p=Ze(a,o),S=Xe(a,o);for(let C=1;;C+=1){const R=vs({agents:t,functions:N,httpRoutes:S,mutators:p,useUmbrella:d,workflows:E}),O=Ss({agents:t,functions:N,migrations:r,mutators:p,shapes:c,useUmbrella:d,usesSandbox:u});if(C>=Xc||Et(a,s,R)&&Et(a,n,O))return{apiContent:R,functions:N,functionsContent:O,httpRoutes:S,mutators:p};J(a,s,R),J(a,n,O),N=Qe(a,o),p=Ze(a,o),S=Xe(a,o)}},Jc=e=>{const t=Yc(e);return t?new Ye({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Ye({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},ql=(e,t)=>{const s=m(t),n=f(t,"schema.ts");y(n)&&s.push(n);for(const c of s){const u=e.getSourceFile(c);u===void 0?e.addSourceFileAtPath(c):u.refreshFromFileSystemSync()}const o=new Set(s.map(c=>xt(c))),r=xt(t),a=`${r}/`;for(const c of e.getSourceFiles()){const u=c.getFilePath();(u===r||u.startsWith(a))&&!o.has(u)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const u=c.getFilePath();if(!(u===r||u.startsWith(a)||u.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},$l=e=>{const t=Gc(),s=t?de.now():0,n=f(e.projectRoot,e.lunoraDirectory??"lunora"),o=f(n,"schema.ts");if(!y(o))throw new D("INTERNAL",`schema.ts not found at ${o}`);const r=e.project??Jc(n);gn(_s);const a=sn(r,o,e.projectRoot),{agents:c,containers:u,dataModelContent:d,dependencies:E,env:N,featureUsage:p,hasBrowser:S,hasFlags:C,hasNotify:R,identity:O,platformGate:j,queues:F,serverContent:K,storageRulesMetadata:z,usesSandbox:re,useUmbrella:U,workflows:L}=Mn({lunoraDirectory:n,project:r,projectRoot:e.projectRoot,schema:a,target:e.target}),g=f(n,"_generated"),be=f(g,"dataModel.ts"),Ie=f(g,"server.ts"),Bt=f(g,"api.ts"),qt=f(g,"functions.ts");J(r,be,d),J(r,Ie,K);const Pe=Hs(r,n),B=cn(r,n),{apiContent:we,functions:q,functionsContent:Te,httpRoutes:$t,mutators:jt}=Zc({agents:c,apiPath:Bt,generatedFunctionsPath:qt,lunoraDirectory:n,migrations:Pe,project:r,shapes:B,useUmbrella:U,usesSandbox:re,workflows:L}),ie=Us(r,n,L,c),V=e.lint===!1?void 0:ss({adminRoutes:jn(r,n),aiRawRuns:Hn(r,n),aiToolSideEffects:nr(r,n),argumentDerivedFetches:or(r,n),argumentValidators:Er(r,n),authApiCalls:zs(r,n),authConfigs:Tr(r,n),browserUrlAccesses:Lr(r,n),configCalls:Br(r,n),containerKeyAccesses:$r(r,n),containerOverrides:Yr(r,n),containers:u,exportSinks:Jr(r,n),staleMigrationImports:ac(r,n),failOpenGuards:ri(r,n),flagReads:li(r,n),flagSecurityDefaults:pi(r,n),geoIndexUsages:hi(r,n),httpActionGuards:yi(r,n),httpHeaderWrites:Li(r,n),identityClaimReads:Ui(r,n),imageDeliveryUrlAccesses:qi(r,n),inserts:qs(r,n),kvKeyAccesses:ji(r,n),mailRecipientAccesses:Yi(r,n),maskProcedures:$s(r,n),maskStrategies:js(r,n),mutatorWrites:to(r,n),nondeterministicCalls:Qs(r,n),normalizeIdAuthorizations:Eo(r,n),notifyCalls:Zs(r,n),notifyConfig:Xs(r,n),ownerFieldWrites:Po(r,n,q),unrestrictedWhereBranches:_c(r,n),paymentWebhooks:Oo(r,n),privilegedDispatches:jo(r,n),procedureProtections:Ta(r,n),queries:ks(r,n),queues:F,r2sqlCalls:Js(r,n),ratelimitKeySelectors:Fa(r,n),rawRowReturns:za(r,n),relationLoads:qa(r,n),rlsProcedures:en(r,n),schema:a,secretLiterals:Qa(r,n),shapes:B,softDeleteReads:Za(r,n),sqlInterpolations:rc(r,n),storageKeyAccesses:lc(r,n,q),storageUploads:mc(r,n),vectorNamespaceAccesses:qc(r,n),workflowCalls:Vc(r,n),workflows:L,wranglerVariables:e.wranglerVariables}),Ce=V===void 0?[]:[...es(V,{source:"static"}),...Nc(r,n,q)],Vt=tn(r,n),Re=Vs(r,n);Qc(B,Re,Ws(r,n));const Wt=C?Bs(r,n):[],W=Cn(p,{containerCount:u.length,cronCount:ie.length,dependencies:E,hasPaymentTables:Tn(a.tables),queueCount:F.length,storageColumnCount:Object.keys(as(a)).length,storageRuleCount:z.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:L.length}),Oe=t?de.now():0,oe=mn(a,Pe.map(h=>h.id)),Fe=cs({advisories:Ce,advisorProcedures:V?.procedureProtections??[],agents:c,containers:u,env:N,flagKeys:Wt,hasAccessFacade:p.access,hasAi:p.ai,hasAnalytics:p.analytics,hasBrowser:S,hasFlags:C,hasHyperdrive:p.hyperdrive,hasImages:p.images,hasKv:p.kv,hasNotify:R,hasPayments:p.payments,hasPipelines:p.pipelines,hasR2sql:p.r2sql,hasX402:p.x402,maskMetadata:Re,mutators:jt,queues:F,rlsMetadata:Vt,schema:a,schemaSnapshot:oe,shapes:B,storageRules:z,studioFeatures:W,useUmbrella:U,workflows:L}),Le=ls(B,E.has("@lunora/db"),U),De=us(u,a.jurisdiction),ke=ds(L),Me=fs(c),Ke=ps(F),_e=gs(ie),ze=ms(a.vectorIndexes),H=hs(a,U),Ue=xs(E.has("@lunora/seed")),G=e.apiSpec??"openapi",ae=G==="openapi"||G==="both",ce=G==="openrpc"||G==="both",Be=ln({emailAgents:c.filter(h=>h.onEmail===!0).map(h=>({bindingName:h.bindingName,exportName:h.exportName})),hasAccess:E.has("@lunora/cloudflare-access"),hasAi:p.ai,hasAnalytics:p.analytics,hasAuth:E.has("@lunora/auth"),hasBrowser:S,hasFramework:E.has("@lunora/astro")||E.has("@lunora/svelte")||E.has("@lunora/vue"),hasGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend!=="hyperdrive"),hasHyperdrive:p.hyperdrive,hasHyperdriveGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend==="hyperdrive"),hasImages:p.images,hasKv:W.kv,hasNotify:R,hasPayments:p.payments,hasR2sql:p.r2sql,hasQueue:F.some(h=>h.mode==="push"),hasScheduler:W.scheduler,hasStorage:W.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:L.length>0,hasX402:p.x402,identity:O,jurisdiction:a.jurisdiction,useUmbrella:U,voiceAgents:c.filter(h=>h.voice===!0&&h.voiceBindingName!==void 0).map(h=>({bindingName:h.voiceBindingName,exportName:h.exportName})),wantsOpenApi:ae,wantsOpenRpc:ce}),qe=Hc(e.projectRoot),$e=un({functions:q,httpRoutes:$t,version:qe}),je=fn({functions:q,version:qe}),Ve=`${JSON.stringify($e,void 0,2)}
8
- `,We=`${JSON.stringify(je,void 0,2)}
9
- `,He=dn($e),Ge=pn(je),le=f(n,Wc),Ht=y(le);if(e.dryRun||(y(g)||Xt(g,{recursive:!0}),I(f(g,"app.ts"),Be),I(be,d),I(f(g,"api.ts"),we),I(Ie,K),I(f(g,"functions.ts"),Te),I(f(g,"shard.ts"),Fe),I(f(g,"crons.ts"),_e),I(f(g,"vectors.ts"),ze),I(f(g,"drizzle.global.ts"),H.global),I(f(g,"drizzle.shard.ts"),H.shard),w(f(g,"containers.ts"),De),w(f(g,"workflows.ts"),ke),w(f(g,"agents.ts"),Me),w(f(g,"queues.ts"),Ke),w(f(g,"seed.ts"),Ue),w(f(g,"collections.ts"),Le),w(f(g,"openapi.json"),ae?Ve:""),w(f(g,"openapi.ts"),ae?He:""),w(f(g,"openrpc.json"),ce?We:""),w(f(g,"openrpc.ts"),ce?Ge:""),(!Ht||e.updateSchemaBaseline===!0)&&I(le,ts(oe))),t){const h=de.now(),Gt=Math.round(h-s),Yt=Math.round(Oe-s),Qt=Math.round(h-Oe);console.error(`@lunora/codegen: codegen took ${Gt.toString()}ms (discovery ${Yt.toString()}ms, emit ${Qt.toString()}ms)`)}return{advisories:Ce,advisorContext:V,agents:c,containers:u,cronTriggers:Es(ie),generated:{agents:Me,api:we,app:Be,collections:Le,containers:De,crons:_e,dataModel:d,drizzleGlobal:H.global,drizzleShard:H.shard,functions:Te,openApi:Ve,openApiModule:He,openRpc:We,openRpcModule:Ge,queues:Ke,seed:Ue,server:K,shard:Fe,vectors:ze,workflows:ke},outputDirectory:g,platformDiagnostics:j.diagnostics,queues:F,schemaSnapshot:oe,schemaSnapshotPath:le,workflows:L}};export{Wc as SCHEMA_SNAPSHOT_FILENAME,Jc as createCodegenProject,Yc as findTsconfig,ql as refreshCodegenProject,$l as runCodegen};
@@ -1 +0,0 @@
1
- import{existsSync as p}from"node:fs";import{join as m}from"node:path";import{LunoraError as a}from"@lunora/errors";import{workflowDefaultName as u,workflowClassName as d,workflowBindingName as g}from"@lunora/workflow";import{Node as i,VariableDeclarationKind as w,SyntaxKind as x}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{u as b,s as h}from"./discover-ast-D33zP-NZ.mjs";const k="workflows.ts",N=new Set(["do","sleep","sleepUntil","waitForEvent"]),y=n=>{const e=n.getSymbol();if(!e)return n.getText()==="defineWorkflow";for(const t of e.getDeclarations())if(i.isImportSpecifier(t))return t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/workflow"?!1:t.getNameNode().getText()==="defineWorkflow";return!1},E=h("workflow"),S=n=>{const e=n.getExpression();if(!i.isPropertyAccessExpression(e)||!N.has(e.getName()))return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="step"?!0:i.isIdentifier(t)&&t.getText()==="step"},D=n=>{const e=n.getProperty("handler");if(!e)return[];const t=i.isPropertyAssignment(e)?e.getInitializer():e;if(!t)return[];const o=[];for(const r of t.getDescendantsOfKind(x.CallExpression)){if(!S(r))continue;const s=r.getArguments()[0];!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s))||o.push({line:r.getStartLineNumber(),method:r.getExpression().getName(),name:s.getLiteralValue()})}return o},l=n=>{let e=n;for(;e&&(i.isAsExpression(e)||i.isSatisfiesExpression(e)||i.isParenthesizedExpression(e));)e=e.getExpression();return e},P=n=>{const e=l(n);if(e&&i.isObjectLiteralExpression(e))return e;if(!(!e||!i.isIdentifier(e)))for(const t of e.getSymbol()?.getDeclarations()??[]){const r=i.isVariableDeclaration(t)&&t.getVariableStatement()?.getDeclarationKind()===w.Const?l(t.getInitializer()):void 0;if(r&&i.isObjectLiteralExpression(r))return r}},W=(n,e)=>{const t=P(n.getArguments()[0]);if(!t)throw c(n,`workflow "${e}": defineWorkflow's argument must be an object literal, or a local \`const\` holding one — codegen reads \`name\` and the \`ctx.step.*\` calls out of it statically. Keep the handler wherever you like and pass it through: \`const config = { handler: myHandler }; export const ${e} = defineWorkflow(config);\`.`);const o={bindingName:g(e),className:d(e),exportName:e,name:u(e),steps:D(t)},r=t.getProperty("name");return r&&i.isPropertyAssignment(r)&&(o.name=E(r.getInitializerOrThrow(),e,"name")),o},I=n=>{const e=[];for(const t of n.getVariableDeclarations()){if(!t.isExported())continue;const o=b(t.getInitializer());if(!o)continue;const r=o.getExpression();if(!i.isIdentifier(r)||!y(r))continue;const s=t.getNameNode();if(!i.isIdentifier(s))throw c(s,"defineWorkflow exports must be plain named exports (no destructuring)");e.push(W(o,s.getText()))}return e},A=n=>{const e=new Map,t=new Map;for(const o of n){const r=e.get(o.name);if(r!==void 0)throw new a("DUPLICATE_WORKFLOW_NAME",`Duplicate workflow name "${o.name}": produced by both "${r}" and "${o.exportName}". Deployed workflow names must be unique across the project.`,{status:500});e.set(o.name,o.exportName);const s=t.get(o.bindingName);if(s!==void 0)throw new a("DUPLICATE_WORKFLOW_BINDING",`Duplicate workflow binding "${o.bindingName}": produced by both "${s}" and "${o.exportName}". Workflow export names must yield unique binding names.`,{status:500});t.set(o.bindingName,o.exportName)}},$=(n,e)=>{const t=m(e,k);if(!p(t))return[];const o=n.getSourceFile(t)??n.addSourceFileAtPath(t),r=I(o);return r.sort((s,f)=>s.exportName.localeCompare(f.exportName)),A(r),r};export{k as WORKFLOWS_FILENAME,$ as discoverWorkflows};
@@ -1 +0,0 @@
1
- import{readdirSync as d,lstatSync as x}from"node:fs";import{join as m,extname as E,relative as b,sep as A}from"node:path";import{Node as i,SyntaxKind as f}from"ts-morph";import{diagnosticAt as y}from"./CodegenDiagnosticError-BUXlG3P-.mjs";const S=/\.ts$/u,h=(t,e)=>b(t,e).split(A).join("/").replace(S,""),p=(t,e=[],s=t)=>{let r;try{r=d(t)}catch{return e}for(const n of r){const o=m(t,n),a=x(o);if(a.isDirectory()){if(n==="_generated"||n==="node_modules")continue;p(o,e,s)}else if(a.isFile()&&E(n)===".ts"){if(n==="schema.ts"&&t===s)continue;e.push(o)}}return e},I=(t,e,s)=>{const r=[];for(const n of p(e)){const o=t.getSourceFile(n)??t.addSourceFileAtPath(n),a=h(e,n);for(const u of o.getDescendantsOfKind(f.CallExpression)){const c=s(u,a);c!==void 0&&r.push(c)}}return r},N=t=>{for(const e of t.getAncestors())if(i.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0)return e.getName();return""},O=(t,e)=>{if(e){const o=t.getArguments()[0];return o&&(i.isArrowFunction(o)||i.isFunctionExpression(o))?o:void 0}const s=t.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return;const r=s.getProperty("handler");if(!r||!i.isPropertyAssignment(r))return;const n=r.getInitializer();return n&&(i.isArrowFunction(n)||i.isFunctionExpression(n))?n:void 0},F=(t,e)=>{if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty(e);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},P=new Set(["findFirst","findFirstOrThrow","findMany"]),D=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||!P.has(e.getName()))return;const s=e.getExpression();if(i.isPropertyAccessExpression(s)&&s.getName()==="db"||i.isIdentifier(s)&&s.getText()==="db"){const r=t.getArguments()[0];return{options:t.getArguments()[1],table:r&&i.isStringLiteral(r)?r.getLiteralText():""}}if(i.isPropertyAccessExpression(s)){const r=s.getExpression();if(i.isPropertyAccessExpression(r)&&r.getName()==="db"||i.isIdentifier(r)&&r.getText()==="db")return{options:t.getArguments()[0],table:s.getName()}}},l=(t,e)=>{const s=t.getExpression();if(!i.isPropertyAccessExpression(s)||!e.has(s.getName()))return!1;const r=s.getExpression();return i.isPropertyAccessExpression(r)?r.getName()==="db":i.isIdentifier(r)&&r.getText()==="db"},g=t=>{const e=t.getArguments()[0];return e&&i.isStringLiteral(e)?e.getLiteralText():""},z=(t,e,s)=>{const r=new Set,n=new Set;for(const o of t.getDescendantsOfKind(f.CallExpression))if(l(o,e)){const a=g(o);a!==""&&r.add(a)}else if(l(o,s)){const a=g(o);a!==""&&n.add(a)}return{tablesRead:[...r],tablesWritten:[...n]}},C=t=>{let e=t;for(;e&&(i.isAsExpression(e)||i.isSatisfiesExpression(e)||i.isParenthesizedExpression(e));)e=e.getExpression();return e&&i.isCallExpression(e)?e:void 0},R=t=>{const e=t.getExportAssignment(n=>!n.isExportEquals());if(!e)return;const s=e.getExpression();if(!i.isIdentifier(s))return s;const r=s.getSymbol()?.getValueDeclaration();return r&&i.isVariableDeclaration(r)?r.getInitializer():s},V=t=>{const e=t.getArguments()[1];return e&&i.isStringLiteral(e)?e.getLiteralValue():""},_=(t,e)=>{if(!i.isObjectLiteralExpression(t))return;const s=t.getProperty(e);if(!s||!i.isPropertyAssignment(s))return;const r=s.getInitializer();return r&&i.isStringLiteral(r)?r.getLiteralText():void 0},K=t=>i.isIdentifier(t)&&t.getText()==="ctx",$=t=>(e,s,r)=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw y(e,`${t} "${s}": \`${r}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)};export{h as a,_ as b,I as c,R as d,N as e,V as f,O as h,K as i,p as l,F as p,D as r,$ as s,z as t,C as u};
@@ -1 +0,0 @@
1
- import{Node as s,SyntaxKind as f}from"ts-morph";import{l as P,a as h}from"./discover-ast-D33zP-NZ.mjs";const x=(e,t)=>{if(e.getText()!==t)return!1;const r=e.getParent();return s.isPropertyAccessExpression(r)&&r.getNameNode()===e?!1:!(s.isPropertyAssignment(r)&&r.getNameNode()===e)},m=(e,t)=>s.isIdentifier(e)?x(e,t):e.getDescendantsOfKind(f.Identifier).some(r=>x(r,t)),g=e=>m(e,"ctx"),A=e=>{let t=e;for(;s.isPropertyAccessExpression(t)||s.isElementAccessExpression(t)||s.isNonNullExpression(t);)t=t.getExpression();return s.isIdentifier(t)?t:void 0},F=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e))return e.getName()},E=e=>m(e,"args"),u=e=>{if(!s.isIdentifier(e))return;const t=e.getText(),r=e.getFirstAncestor(o=>s.isArrowFunction(o)||s.isFunctionExpression(o)||s.isFunctionDeclaration(o));if(r===void 0)return;const i=e.getStart();let n,a=-1;for(const o of r.getDescendantsOfKind(f.VariableDeclaration)){if(o.getName()!==t)continue;const c=o.getInitializer(),l=o.getStart();c!==void 0&&l<i&&l>a&&(n=c,a=l)}return n},T=e=>{if(E(e))return!0;const t=u(e);return t!==void 0&&E(t)},C=e=>{if(s.isCallExpression(e)||s.isNewExpression(e))return!1;const t=u(e);return t===void 0||!(s.isCallExpression(t)||s.isNewExpression(t))},K=e=>{if(g(e))return!0;const t=u(e);if(t!==void 0&&g(t))return!0;const r=t??e;return(s.isIdentifier(r)?[r]:r.getDescendantsOfKind(f.Identifier)).some(n=>{const a=u(n);return a!==void 0&&g(a)})},p=(e,t)=>m(e,t),O=(e,t)=>{if(p(e,t))return!0;const r=u(e);if(r!==void 0&&p(r,t))return!0;const i=A(e);if(i!==void 0){const n=u(i);return n!==void 0&&p(n,t)}return!1},I=e=>{for(const t of e.getAncestors())if(s.isVariableDeclaration(t)&&t.getVariableStatement()?.hasExportKeyword()===!0)return t.getName();return"<module>"},v=new Set(["withGeoIndex","withIndex","withSearchIndex"]),N=new Set(["collect","collectWithScores","first","paginate","take","unique"]),y=e=>{const t=e.getExpression();if(!s.isPropertyAccessExpression(t)||t.getName()!=="query")return!1;const r=t.getExpression();return s.isPropertyAccessExpression(r)?r.getName()==="db":s.isIdentifier(r)&&r.getText()==="db"},b=e=>{const t=[];let r=e;for(;;){const i=r.getParent();if(!i||!s.isPropertyAccessExpression(i))break;const n=i.getParent();if(!n||!s.isCallExpression(n))break;t.push(i.getName()),r=n}return t},S=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,D=e=>{let t=e;for(;;){const r=t.getParent();if(!r||!s.isPropertyAccessExpression(r))return!1;const i=r.getParent();if(!i||!s.isCallExpression(i))return!1;if(r.getName()==="filter"){const n=i.getArguments()[0];if(n&&S.test(n.getText()))return!0}t=i}},w=e=>{const t=e.getArguments()[0];return t&&s.isStringLiteral(t)?t.getLiteralText():""},_=(e,t)=>{const r=[];for(const i of P(t)){const n=e.getSourceFile(i)??e.addSourceFileAtPath(i),a=h(t,i);for(const o of n.getDescendantsOfKind(f.CallExpression)){if(!y(o))continue;const c=b(o),l=c.includes("filter");r.push({exportName:I(o),file:a,filtersPrimaryKey:l&&D(o),hasFilter:l,hasIndex:c.some(d=>v.has(d)),line:o.getStartLineNumber(),table:w(o),terminal:c.findLast(d=>N.has(d))})}}return r};export{K as a,C as b,F as c,_ as d,I as e,O as f,p as g,T as i,E as r,u as s};
@@ -1 +0,0 @@
1
- import{SyntaxKind as p,Node as s}from"ts-morph";import{l as f,a as g,e as d}from"./discover-ast-D33zP-NZ.mjs";const m=r=>{const t=r.getExpression();if(!s.isPropertyAccessExpression(t))return!1;const e=t.getExpression();return s.isPropertyAccessExpression(e)?e.getName()==="authApi":s.isIdentifier(e)&&e.getText()==="authApi"},h=r=>{const t=r.getArguments()[0];if(t===void 0)return!1;if(!s.isObjectLiteralExpression(t))return!0;for(const e of t.getProperties())if((s.isPropertyAssignment(e)||s.isShorthandPropertyAssignment(e))&&e.getName()==="headers"||s.isSpreadAssignment(e))return!0;return!1},P=(r,t)=>{const e=[];for(const n of f(t)){const c=r.getSourceFile(n)??r.addSourceFileAtPath(n),l=g(t,n);for(const i of c.getDescendantsOfKind(p.CallExpression)){if(!m(i))continue;const o=d(i);if(o==="")continue;const a=i.getExpression(),u=s.isPropertyAccessExpression(a)?a.getName():"";e.push({exportName:o,file:l,hasHeaders:h(i),line:i.getStartLineNumber(),method:u})}}return e};export{P as default};
@@ -1 +0,0 @@
1
- import{LunoraError as L}from"@lunora/errors";import{CRON_SCHEDULE_KINDS as A,isValidCronExpression as O,warnIfSecondsLeading as S,compileCronSchedule as b}from"@lunora/scheduler";import{SyntaxKind as m,Node as s}from"ts-morph";import{diagnosticAt as f,CodegenDiagnosticError as I}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{i as R}from"./module-specifiers-WF8iAydP.mjs";import{s as $}from"./paths-C-9fwEgQ.mjs";import{l as y}from"./discover-ast-D33zP-NZ.mjs";const P=new Set([...A,"cron"]),D=e=>{const t=e.getSymbol();if(!t)return e.getText()==="cronJobs";for(const r of t.getDeclarations())if(s.isImportSpecifier(r))return R(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="cronJobs":!1;return!1},v=e=>{const t=new Set;for(const r of e.getVariableDeclarations()){const o=r.getInitializer();if(o?.getKind()!==m.CallExpression)continue;const i=o.getExpression();s.isIdentifier(i)&&D(i)&&t.add(r.getName())}return t},F=e=>{let t=e;for(;s.isCallExpression(t)||s.isPropertyAccessExpression(t);)t=t.getExpression();return s.isIdentifier(t)?t.getText():void 0},x=(e,t)=>{const r=e.getArguments()[t];return r&&(s.isStringLiteral(r)||s.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},_=(e,t)=>{if(s.isStringLiteral(e)||s.isNoSubstitutionTemplateLiteral(e)||s.isNumericLiteral(e))return e.getLiteralValue();if(s.isTrueLiteral(e))return!0;if(s.isFalseLiteral(e))return!1;if(s.isPrefixUnaryExpression(e)&&e.getOperatorToken()===m.MinusToken){const r=e.getOperand();if(s.isNumericLiteral(r))return-r.getLiteralValue()}if(s.isObjectLiteralExpression(e))return p(e,t);if(s.isArrayLiteralExpression(e))return e.getElements().map(r=>_(r,t));throw f(e,`Cron job "${t}" passes a non-static value where a literal is required; codegen can only read literals.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500})},p=(e,t)=>{const r={};for(const o of e.getProperties()){if(!s.isPropertyAssignment(o))throw f(o,`Cron job "${t}" uses an unsupported object property (shorthand/spread/method) where a static literal is required.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500});const i=o.getInitializer();i&&(r[o.getName()]=_(i,t))}return r},C=(e,t,r)=>{const o=e.getArguments()[t];if(!o||!s.isPropertyAccessExpression(o))throw f(e,`Cron job "${r}" must reference a function statically (e.g. internal.email.digest); codegen cannot resolve a dynamic reference.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const i=o.getName(),n=o.getExpression();if(!s.isPropertyAccessExpression(n))throw f(o,`Cron job "${r}" function reference must be of the form internal.file.fn (two property accesses).`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const a=n.getName();return`${$(a)}:${i}`},h=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),w=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),T=(e,t,r,o,i,n)=>{const a=e.getExpression();if(!s.isIdentifier(a)||a.getText()!==t)return;const c=r.get(e.getName());if(c)return n(c);throw f(e,`Cron job "${o}" targets ${t}.${e.getName()}, but no such ${i} is declared in lunora/${i}s.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})},V=(e,t,r,o,i)=>{const n=e.getArguments()[t];if(n&&s.isPropertyAccessExpression(n)){const a=T(n,"workflows",o,r,"workflow",h);if(a)return a;const c=T(n,"agents",i,r,"agent",w);return c||{functionPath:C(e,t,r)}}if(n&&s.isIdentifier(n)){const a=o.get(n.getText()),c=i.get(n.getText());if(a&&c)throw f(n,`Cron job "${r}" references "${n.getText()}", which is ambiguous: a workflow and an agent are both declared under that name.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});if(a)return h(a);if(c)return w(c);throw f(n,`Cron job "${r}" references "${n.getText()}", which is neither a function (internal.file.fn / api.file.fn) nor a declared workflow in lunora/workflows.ts nor a declared agent in lunora/agents.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})}return{functionPath:C(e,t,r)}},j=/^@lunora\/scheduler:\s*/u,k=(e,t)=>{const r=x(e,1);if(r===void 0)throw f(e,`Cron job "${t}" must pass a string-literal cron expression to ".cron(...)".`,{code:"CRON_EXPR_NOT_STATIC",name:"LunoraError",status:500});if(!O(r))throw f(e,`Cron job "${t}" has an invalid cron expression "${r}" — expected 5 or 6 space-separated fields.`,{code:"CRON_EXPR_INVALID",name:"LunoraError",status:500});return S(r,`cron expression for job "${t}"`),r},U=(e,t,r)=>{const o=e.getArguments()[1];if(!o||!s.isObjectLiteralExpression(o))throw f(e,`Cron job "${r}" must pass an object-literal schedule to ".${t}(...)".`,{code:"CRON_SCHEDULE_NOT_STATIC",name:"LunoraError",status:500});try{return b(t,p(o,r),r)}catch(i){if(i instanceof I)throw i;const n=i instanceof Error?i.message.replace(j,""):String(i);throw f(e,n,{code:"CRON_SCHEDULE_INVALID",name:"LunoraError",status:500})}},M=(e,t,r,o,i)=>{const n=t.getName();if(!P.has(n)||!r.has(F(t.getExpression())??""))return;const a=x(e,0);if(a===void 0||a.trim()==="")throw f(e,`A cron ".${n}(...)" registration must pass a non-empty string-literal name as its first argument.`,{code:"CRON_NAME_NOT_STATIC",name:"LunoraError",status:500});const c=n==="cron"?k(e,a):U(e,n,a),u=V(e,2,a,o,i),l=e.getArguments()[3];return{args:l&&s.isObjectLiteralExpression(l)?p(l,a):{},cron:c,name:a,...u}},z=e=>{const t=new Set;for(const r of e){if(t.has(r.name))throw new L("DUPLICATE_CRON_NAME",`Duplicate cron job name "${r.name}": cron names must be unique across the project.`,{status:500});t.add(r.name)}},Q=(e,t,r=[],o=[])=>{const i=y(t),n=[],a=new Map(r.map(u=>[u.exportName,u])),c=new Map(o.map(u=>[u.exportName,u]));for(const u of i){const l=e.getSourceFile(u)??e.addSourceFileAtPath(u),g=v(l);if(g.size!==0)for(const d of l.getDescendantsOfKind(m.CallExpression)){const N=d.getExpression();if(!s.isPropertyAccessExpression(N))continue;const E=M(d,N,g,a,c);E&&n.push(E)}}return n.sort((u,l)=>u.name.localeCompare(l.name)),z(n),n};export{Q as default};
@@ -1 +0,0 @@
1
- import{SyntaxKind as u,Node as o}from"ts-morph";import{l as B,a as q}from"./discover-ast-D33zP-NZ.mjs";import{a as K}from"./module-specifiers-WF8iAydP.mjs";import{p as H,a as I}from"./parse-validator-BFTp87yz.mjs";import{s as W}from"./paths-C-9fwEgQ.mjs";const x=new Set(["action","mutation","query","stream"]),C=/\bany\b(?!\s*(?:\?\s*)?:)/u,D=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,G=/^[A-Za-z_$][\w$]*$/u,X=e=>G.test(e)?e:JSON.stringify(e),k={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},J={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init"},Q=K,L=e=>{const t=e.getSymbol();if(!t)return e.getText();const r=t.getDeclarations();for(const i of r){if(!o.isImportSpecifier(i))continue;const s=i.getImportDeclaration().getModuleSpecifierValue();return Q(s)?i.getNameNode().getText():void 0}},O=(e,t=!1)=>{let r=e;for(;o.isCallExpression(r);){const n=r.getExpression();if(!o.isPropertyAccessExpression(n))return;r=n.getExpression()}if(!o.isIdentifier(r))return;const i=L(r);if(i===void 0){if(t)return;const n=r.getSymbol()?.getValueDeclaration();if(n&&o.isVariableDeclaration(n)){const s=n.getInitializer();return s?O(s,!0):void 0}return}return x.has(i)?"public":k[i]?"internal":void 0},b=(e,t)=>{const r=e.getProperty(t);if(r===void 0||!o.isPropertyAssignment(r))return;const i=r.getInitializer();return i!==void 0&&o.isStringLiteral(i)?i.getLiteralValue():void 0},N=(e,t)=>{const r=e.getProperty(t);if(r===void 0||!o.isPropertyAssignment(r))return;const i=r.getInitializer();return i!==void 0&&o.isNumericLiteral(i)?i.getLiteralValue():void 0},Y=e=>{const t=e.getProperty("cache");if(t===void 0||!o.isPropertyAssignment(t))return;const r=t.getInitializer();if(r===void 0||!o.isObjectLiteralExpression(r))return;const i=b(r,"scope"),n=N(r,"maxAge"),s=N(r,"staleWhileRevalidate"),a=b(r,"tag"),c=b(r,"vary"),l={...n===void 0?{}:{maxAge:n},...i==="private"||i==="public"?{scope:i}:{},...s===void 0?{}:{staleWhileRevalidate:s},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},Z=e=>{if(e===void 0||!o.isObjectLiteralExpression(e))return{};const t=Y(e),r=e.getProperty("rest");return r!==void 0&&o.isPropertyAssignment(r)?{...t===void 0?{}:{cache:t},rest:r.getInitializer()?.getText()==="true"}:t===void 0?{}:{cache:t}},ee=e=>{let t=e;for(;o.isCallExpression(t);){const r=t.getExpression();if(!o.isPropertyAccessExpression(r))return;if(r.getName()==="expose")return Z(t.getArguments()[0]);t=r.getExpression()}},te=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return{};const r=t.getProperty("args");if(!r||!o.isPropertyAssignment(r))return{};const i=r.getInitializer();return!i||!o.isObjectLiteralExpression(i)?{}:I(i)},re="/_generated/",ie=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(r=>r?.getDeclarations()??[]);return t.length>0&&t.every(r=>r.getSourceFile().getSymbol()===void 0)},ne=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,w=e=>{for(const t of e.getAncestors())if(o.isModuleDeclaration(t)){const r=ne.exec(t.getName());if(r?.groups?.specifier!==void 0)return r.groups.specifier}},P=new WeakMap,se=(e,t)=>{const r=e.getSymbol();if(r===void 0)return;let i=P.get(r.compilerSymbol);return i===void 0&&(i=new Map,P.set(r.compilerSymbol,i)),i.has(t)||i.set(t,r.getExport(t)??e.getExportSymbols().find(n=>n.getName()===t)),i.get(t)},F=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(r=>r.getName()===t),oe=(e,t,r)=>{const i=e.getModuleSpecifierValue();return i===t&&F(e,r)?{exportName:r,specifier:i}:void 0},ae=(e,t)=>{const r=e.getDefaultImport();if(r===void 0)return;const i=r.getSymbol();return(i?.getAliasedSymbol()??i)?.getDeclarations().includes(t)===!0?{exportName:"default",specifier:e.getModuleSpecifierValue()}:void 0},ce=(e,t,r)=>{if(!F(e,r))return;const i=e.getModuleSpecifierSourceFile(),n=i===void 0?void 0:se(i,r);return(n?.getAliasedSymbol()??n)?.getDeclarations().includes(t)===!0?{exportName:r,specifier:e.getModuleSpecifierValue()}:void 0},le=(e,t,r)=>{const i=w(t);for(const n of e.getImportDeclarations()){const s=i===void 0?ae(n,t)??ce(n,t,r):oe(n,i,r);if(s!==void 0)return s}},ue=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(r=>{const i=r.indexOf("*");return i===-1?e===r:e.startsWith(r.slice(0,i))&&e.endsWith(r.slice(i+1))}),g={kind:"verbatim"},m={kind:"expand"},ge=new Set([u.ClassDeclaration,u.EnumDeclaration,u.EnumMember,u.InterfaceDeclaration,u.TypeAliasDeclaration]),M=(e,t,r)=>{const i=e.getSourceFile();if(i.getSymbol()===void 0&&w(e)===void 0||!ge.has(e.getKind()))return g;const n=i.getFilePath();if(n.includes(re))return g;if(n===r)return m;const s=o.isEnumMember(e)?e.getParent():e;if(!o.hasName(s))return m;const a=le(t.getSourceFile(),s,s.getName());return a===void 0?g:ue(a.specifier,t)?m:{kind:"qualify",qualified:a}},R=(e,t,r)=>{const i=e.getAliasSymbol(),n=e.getSymbol(),s=new Set((i??n)?.getDeclarations());let a=!1;for(const c of[n,i].flatMap(l=>l?.getDeclarations()??[])){const l=M(c,t,r);if(l.kind==="qualify"&&s.has(c))return l;a||=l.kind!=="verbatim"}return a?m:g},fe=(e,t,r)=>{const i=o.isPropertySignature(e)||o.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(i===void 0)return g;let n=!1;for(const s of[i,...i.getDescendantsOfKind(u.TypeReference)].filter(a=>o.isTypeReference(a))){const a=s.getTypeName().getSymbol();for(const c of(a?.getAliasedSymbol()??a)?.getDeclarations()??[]){const l=M(c,t,r);if(l.kind==="qualify")return l;n||=l.kind!=="verbatim"}}return n?m:g},_=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},S=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0,v=(e,t,r,i=new Set)=>i.has(e)?!1:(i.add(e),R(e,t,r).kind!=="verbatim"||_(e).some(n=>v(n,t,r,i))?!0:S(e)?e.getProperties().some(n=>n.getDeclarations().some(s=>fe(s,t,r).kind!=="verbatim")?!0:v(n.getTypeAtLocation(t),t,r,i)):!1),pe=(e,t)=>{const r=e.getValueDeclaration()??e.getDeclarations()[0];return r&&(o.isPropertySignature(r)||o.isPropertyDeclaration(r))&&r.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(i=>i.isUndefined())},z=8,de=(e,t,r,i,n,s)=>{const a=e.getArrayElementType(),c=a?s(a,t,r,i,n):void 0;if(c!==void 0)return a?.isUnion()?`(${c})[]`:`${c}[]`},me=(e,t,r,i,n,s)=>{const a=[];for(const c of e.getUnionTypes()){const l=s(c,t,r,i,n);if(l===void 0)return;a.push(l)}return a.join(" | ")},ve=(e,t,r,i,n,s)=>{if(!S(e))return;const a=[];for(const c of e.getProperties()){const l=c.getTypeAtLocation(t),d=pe(c,l),V=d&&l.isUnion()?l.getUnionTypes().filter(E=>!E.isUndefined()):[l],A=[];for(const E of V){const T=s(E,t,r,i+1,n);if(T===void 0)return;A.push(T)}a.push(`${X(c.getName())}${d?"?":""}: ${A.join(" | ")}`)}return a.length>0?`{ ${a.join("; ")} }`:"{}"},ye=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},Ee=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>o.isClassDeclaration(t)||o.isClassExpression(t)),y=(e,t,r,i)=>{if(r>z||i.has(e))return!1;const n=new Set(i).add(e);if(_(e).some(c=>y(c,t,r+1,n)))return!0;const s=e.getArrayElementType();return s!==void 0?y(s,t,r+1,n):ie(e)?!1:e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(c=>c?.getDeclarations()??[]).some(c=>o.isClassDeclaration(c)||o.isClassExpression(c))?!0:S(e)&&e.getProperties().some(c=>y(c.getTypeAtLocation(t),t,r+1,n))},be=(e,t,r,i,n,s,a)=>{const c=[];for(const l of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const d=a(l,r,i,n+1,s);if(d===void 0)return;c.push(d)}return`import("${e.specifier}").${e.exportName}${c.length>0?`<${c.join(", ")}>`:""}`},xe=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>o.isEnumDeclaration(t)||o.isEnumMember(t)),f=(e,t,r,i,n)=>{if(i>z||n.has(e))return;const s=R(e,t,r);if(s.kind==="verbatim"&&!v(e,t,r))return e.getText(t);const a=new Set(n).add(e);if(!Ee(e)){if(e.isEnumLiteral())return ye(e);if(s.kind==="qualify"&&!xe(e)){const c=be(s.qualified,e,t,r,i,a,f);if(c!==void 0)return c}return e.isArray()?de(e,t,r,i,a,f):e.isUnion()?me(e,t,r,i,a,f):ve(e,t,r,i,a,f)}},U=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let r=t.getReturnType();const n=(r.getSymbol()??r.getAliasSymbol())?.getName();if(n==="Promise"||n==="AsyncIterable"||n==="AsyncIterableIterator"||n==="AsyncGenerator"){const c=r.getTypeArguments()[0];c&&(r=c)}const s=r.getText(e);if(!s||s==="any"||s==="never"||C.test(s.replaceAll(D,""))||y(r,e,0,new Set))return"unknown";const a=e.getSourceFile().getFilePath();return v(r,e,a)?f(r,e,a,0,new Set)??"unknown":s},ze=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const r=t.getTypeAtLocation(e).getProperty("types");if(!r)return;const i=r.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!i)return;const n=i.getTypeAtLocation(e),s=n.getText(e);if(!s||s==="any"||s==="never"||C.test(s.replaceAll(D,"")))return;const a=e.getSourceFile().getFilePath();return v(n,e,a)?f(n,e,a,0,new Set):s},Se=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return"unknown";const r=t.getProperty("handler");if(!r||!o.isPropertyAssignment(r))return"unknown";const i=r.getInitializer();return!i||!(o.isArrowFunction(i)||o.isFunctionExpression(i))?"unknown":U(i)},Ae=e=>{const t=e.getArguments()[0];return!t||!(o.isArrowFunction(t)||o.isFunctionExpression(t))?"unknown":U(t)},Te=e=>{let t={},r=e;for(;o.isCallExpression(r);){const i=r.getExpression();if(!o.isPropertyAccessExpression(i))break;if(i.getName()==="input"){const n=r.getArguments()[0];n&&o.isObjectLiteralExpression(n)&&(t={...I(n),...t})}r=i.getExpression()}return t},Ne=e=>{let t=e;for(;o.isCallExpression(t);){const r=t.getExpression();if(!o.isPropertyAccessExpression(r))return;if(r.getName()==="output"){const i=t.getArguments()[0];return i&&o.isExpression(i)?H(i):void 0}t=r.getExpression()}},Pe=e=>{const t=e.getExpression();if(o.isPropertyAccessExpression(t)){const s=t.getName();if(!x.has(s))return;const a=t.getExpression();if(a.getType().getProperty("__lunoraProcedure"))return{kind:s,receiver:a,visibility:a.getType().getProperty("__lunoraVisibility")?"internal":"public"};const c=O(a);return c?{kind:s,receiver:a,visibility:c}:void 0}if(!o.isIdentifier(t))return;const r=L(t);if(!r)return;if(x.has(r))return{kind:r,visibility:"public"};const i=k[r];if(i)return{kind:i,visibility:"internal"};const n=J[r];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}},h=e=>e!==void 0&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,Ue=e=>o.isPropertyAccessExpression(e)&&e.getName()==="db"||o.isIdentifier(e)&&e.getText()==="db",$e=e=>{const t=e.getArguments()[0],r=h(t);if(r!==void 0)return r;if(t===void 0||!o.isObjectLiteralExpression(t))return;const i=t.getProperty("handler");return i!==void 0&&o.isPropertyAssignment(i)?h(i.getInitializer()):void 0},he=e=>o.isIdentifier(e)?e.getText():o.isPropertyAccessExpression(e)?e.getName():"",je=(e,t)=>{let r=e;for(;o.isCallExpression(r);){const i=r.getExpression();if(!o.isPropertyAccessExpression(i))break;if(i.getName()===t)return!0;r=i.getExpression()}return!1},Ve=(e,t,r)=>{let i=e;for(;o.isCallExpression(i);){const n=i.getExpression();if(!o.isPropertyAccessExpression(n))break;const s=i.getArguments()[0];if(n.getName()===t&&s!==void 0&&o.isCallExpression(s)&&he(s.getExpression())===r)return!0;i=n.getExpression()}return!1},Ie=e=>{const t=Pe(e);if(t){if(t.receiver){const r=ee(t.receiver),i=Ne(t.receiver);return{args:Te(t.receiver),...r?{expose:r}:{},kind:t.kind,...i?{output:i}:{},returnType:Ae(e),visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:te(e),kind:t.kind,returnType:Se(e),visibility:t.visibility}}},Ce=8,p=(e,t=0)=>{if(t>Ce)return;if(o.isCallExpression(e))return e;if(o.isParenthesizedExpression(e)||o.isAsExpression(e)||o.isSatisfiesExpression(e)||o.isNonNullExpression(e))return p(e.getExpression(),t+1);if(!o.isIdentifier(e)&&!o.isPropertyAccessExpression(e))return;const r=e.getSymbol()?.getValueDeclaration();return r?$(r,t+1):void 0},$=(e,t)=>{if(o.isVariableDeclaration(e)||o.isPropertyAssignment(e)){const r=e.getInitializer();return r?p(r,t):void 0}if(o.isShorthandPropertyAssignment(e))return p(e.getNameNode(),t);if(o.isBindingElement(e)){const r=e.getPropertyNameNode()?.getText()??e.getName(),s=e.getFirstAncestorByKind(u.VariableDeclaration)?.getInitializer()?.getType().getProperty(r)?.getValueDeclaration();return s?$(s,t+1):void 0}},De=e=>{const t=e.getNameNode();if(o.isObjectBindingPattern(t)){const n=[];for(const s of t.getElements()){const a=p(s.getNameNode());a&&n.push([s.getName(),a])}return n}const r=e.getInitializer(),i=r&&(o.isCallExpression(r)?r:p(r));return i?[[e.getName(),i]]:[]},j=(e,t,r)=>{const i=Ie(e);if(i)return{args:i.args,exportName:t,filePath:r,kind:i.kind,returnType:i.returnType,...i.output?{output:i.output}:{},visibility:i.visibility,...i.expose?{expose:i.expose}:{},...i.lifecycle?{lifecycle:i.lifecycle}:{}}},ke=(e,t)=>{const r=[];for(const i of e.getExportAssignments()){if(i.isExportEquals())continue;const n=p(i.getExpression()),s=n?j(n,"default",t):void 0;s&&r.push(s)}return r},Le=(e,t)=>{const r=[];for(const i of e.getVariableStatements())if(i.isExported())for(const n of i.getDeclarations())for(const[s,a]of De(n)){const c=j(a,s,t);c&&r.push(c)}return r.push(...ke(e,t)),r},Oe=e=>{const t=new Map;for(const r of e){const i=W(r.filePath),n=t.get(i);if(n&&n!==r.filePath)throw Object.assign(new Error(`Namespace collision: "${n}" and "${r.filePath}" both resolve to "${i}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[n,r.filePath],status:500});t.set(i,r.filePath)}},Be=(e,t)=>{const r=B(t),i=[];for(const n of r){const s=e.getSourceFile(n)??e.addSourceFileAtPath(n),a=q(t,n);i.push(...Le(s,a))}return i.sort((n,s)=>`${n.filePath}:${n.exportName}`.localeCompare(`${s.filePath}:${s.exportName}`)),Oe(i),i};export{je as chainHasStep,Ve as chainUsesWrappedCall,Pe as classifyProcedureCall,Be as discoverFunctions,h as inlineHandler,Ue as isDatabaseAccessor,B as listLunoraSourceFiles,q as lunoraRelativePath,$e as procedureHandler,ze as resolveStandardSchemaType,U as unwrapHandlerReturn};
@@ -1 +0,0 @@
1
- import{Node as a}from"ts-morph";import{l,a as m}from"./discover-ast-D33zP-NZ.mjs";import{unwrapHandlerReturn as d}from"./discoverFunctions-CKff5HG0.mjs";import{p as h,a as f}from"./parse-validator-BFTp87yz.mjs";const u=new Set(["delete","get","head","options","patch","post","put"]),g=new Set(["body","params","searchParams"]),E=new Set(["handler","stream"]),v=r=>{const e=r.getArguments()[0];if(e&&a.isStringLiteral(e))return e.getLiteralValue()},x=r=>{const e=r.getArguments()[0];return e&&a.isObjectLiteralExpression(e)?f(e):{}},P=r=>{if(!a.isCallExpression(r))return;const e=r.getExpression();if(!a.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const n=e.getExpression();if(!a.isIdentifier(n)||n.getText()!=="httpRoute")return;const s=v(r);return s===void 0?void 0:{method:o.toUpperCase(),path:s}},S=(r,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},n=r.getExpression();if(!a.isPropertyAccessExpression(n))return;let s=n.getExpression();for(;a.isCallExpression(s);){const i=s.getExpression();if(!a.isPropertyAccessExpression(i))break;const c=i.getName();if(u.has(c))break;if(g.has(c)){const p=x(s);o[c]={...p,...o[c]}}else if(c==="output"&&o.output===void 0){const p=s.getArguments()[0];p&&a.isExpression(p)&&(o.output=h(p))}s=i.getExpression()}const t=P(s);if(t)return o.method=t.method,o.path=t.path,o},A=r=>{const e=r.getArguments()[0];return!e||!(a.isArrowFunction(e)||a.isFunctionExpression(e))?"unknown":d(e)},T=(r,e,o,n)=>{const s=e.getName();if(!E.has(s))return;const t=S(r,s);if(!(t?.method===void 0||t.path===void 0))return{body:t.body,exportName:o,filePath:n,method:t.method,params:t.params,path:t.path,searchParams:t.searchParams,stream:t.stream,...t.stream?{chunkType:A(r)}:{},...t.output?{output:t.output}:{}}},b=(r,e)=>{const o=[];for(const n of r.getVariableStatements())if(n.isExported())for(const s of n.getDeclarations()){const t=s.getInitializer();if(!t||!a.isCallExpression(t))continue;const i=t.getExpression();if(!a.isPropertyAccessExpression(i))continue;const c=T(t,i,s.getName(),e);c&&o.push(c)}return o},F=(r,e)=>{const o=l(e),n=[];for(const s of o){const t=r.getSourceFile(s)??r.addSourceFileAtPath(s),i=m(e,s);n.push(...b(t,i))}return n.sort((s,t)=>`${s.method} ${s.path}`.localeCompare(`${t.method} ${t.path}`)||s.filePath.localeCompare(t.filePath)),n};export{F as default};
@@ -1 +0,0 @@
1
- import{SyntaxKind as c,Node as i}from"ts-morph";import{l as f,a as g,e as u}from"./discover-ast-D33zP-NZ.mjs";const d=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="insert")return!1;const r=e.getExpression();return i.isPropertyAccessExpression(r)?r.getName()==="db":i.isIdentifier(r)&&r.getText()==="db"},m=t=>{if(!i.isIdentifier(t))return;const e=t.getSymbol(),r=e?.getAliasedSymbol()?.getDeclarations()??e?.getDeclarations()??[];for(const s of r)if(i.isVariableDeclaration(s)){const n=s.getInitializer();if(n&&i.isStringLiteral(n))return n.getLiteralText()}},p=t=>{const e=t.getArguments()[0];return e?i.isStringLiteral(e)?e.getLiteralText():m(e)??"":""},S=(t,e)=>{const r=[];for(const s of f(e)){const n=t.getSourceFile(s)??t.addSourceFileAtPath(s),l=g(e,s);for(const o of n.getDescendantsOfKind(c.CallExpression)){if(!d(o))continue;const a=u(o);a!==""&&r.push({exportName:a,file:l,line:o.getStartLineNumber(),table:p(o)})}}return r};export{S as default};
@@ -1 +0,0 @@
1
- import{Node as i}from"ts-morph";import{l as f,a as P,t as x}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as p}from"./discoverFunctions-CKff5HG0.mjs";const A=e=>{if(!i.isCallExpression(e))return!1;const s=e.getExpression();return i.isIdentifier(s)?s.getText()==="mask":i.isPropertyAccessExpression(s)?s.getName()==="mask":!1},u=e=>{if(i.isPropertyAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e))return e.getName()},k=e=>{const s=e.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return[];const t=[];for(const r of s.getProperties()){const o=u(r);if(o===void 0||!i.isPropertyAssignment(r))continue;const n=r.getInitializer();if(!(!n||!i.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=u(a);c!==void 0&&t.push({column:c,table:o})}}return t},g=e=>{const s=[];let t=e;for(;i.isCallExpression(t);){const r=t.getExpression();if(!i.isPropertyAccessExpression(r))break;if(r.getName()==="use"){const o=t.getArguments()[0];o&&A(o)&&s.push(o)}t=r.getExpression()}return s},E=e=>{const s=g(e);return{maskColumns:s.flatMap(t=>k(t)),usesMask:s.length>0}},M=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),S=new Set(["delete","insert","patch","replace"]),b=(e,s)=>{if(!i.isVariableDeclaration(e))return;const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const r=p(t);if(!r)return;const o=r.receiver?E(r.receiver):{maskColumns:[],usesMask:!1},{tablesRead:n,tablesWritten:a}=x(e,M,S);return{exportName:e.getName(),file:s,maskColumns:o.maskColumns,tablesRead:n,tablesWritten:a,usesMask:o.usesMask,visibility:r.visibility}},w=(e,s)=>{const t=[];for(const r of f(s)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=P(s,r);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations()){const l=b(c,n);l&&t.push(l)}}return t},h=e=>{if(i.isPropertyAssignment(e)){const s=e.getInitializer();if(s&&i.isStringLiteral(s)){const t=s.getLiteralText();if(t==="redact"||t==="hash")return t}}return"custom"},C=e=>{const s=e.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return[];const t=[];for(const r of s.getProperties()){const o=u(r);if(o===void 0||!i.isPropertyAssignment(r))continue;const n=r.getInitializer();if(!(!n||!i.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=u(a);c!==void 0&&t.push({column:c,strategy:h(a),table:o})}}return t},v=e=>{const s=[];for(const t of e.getVariableStatements())if(t.isExported())for(const r of t.getDeclarations()){const o=r.getInitializer(),n=o&&i.isCallExpression(o)?p(o):void 0;n?.receiver&&s.push(n.receiver)}return s},R=(e,s)=>{const t=new Map;for(const r of f(s)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r);for(const n of v(o))for(const a of g(n))for(const c of C(a)){const l=`${c.table}\0${c.column}`;t.has(l)||t.set(l,c)}}return{columns:[...t.values()]}},F=(e,s,t)=>{const r=e.getArguments()[0];if(!r||!i.isObjectLiteralExpression(r))return[];const o=[];for(const n of r.getProperties()){const a=u(n);if(a===void 0||!i.isPropertyAssignment(n))continue;const c=n.getInitializer();if(!(!c||!i.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const m=u(l);if(m===void 0)continue;const d=h(l);d!=="custom"&&o.push({column:m,exportName:s,file:t,line:l.getStartLineNumber(),strategy:d,table:a})}}return o},z=(e,s)=>{if(!i.isVariableDeclaration(e))return[];const t=e.getInitializer(),r=t&&i.isCallExpression(t)?p(t):void 0;return r?.receiver?g(r.receiver).flatMap(o=>F(o,e.getName(),s)):[]},T=(e,s)=>{const t=[];for(const r of f(s)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=P(s,r);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())t.push(...z(c,n))}return t},D=e=>i.isPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?i.isComputedPropertyName(e.getNameNode()):!1,L=e=>i.isPropertyAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?D(e):!0,y=(e,s=!1)=>{for(const t of e.getProperties()){if(L(t))return!0;if(s)continue;if(!i.isPropertyAssignment(t))return!0;const r=t.getInitializer();if(!r||!i.isObjectLiteralExpression(r)||y(r,!0))return!0}return!1},j=(e,s)=>{for(const t of f(s)){const r=e.getSourceFile(t)??e.addSourceFileAtPath(t);for(const o of v(r))for(const n of g(o)){const a=n.getArguments()[0];if(a!==void 0&&(!i.isObjectLiteralExpression(a)||y(a)))return!0}}return!1};export{w as default,j as discoverMaskHasNonLiteralPolicy,R as discoverMaskMetadata,T as discoverMaskStrategies};
@@ -1 +0,0 @@
1
- import{SyntaxKind as f,Node as a}from"ts-morph";import{diagnosticAt as u}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{l as m,a as p}from"./discover-ast-D33zP-NZ.mjs";import{b as h}from"./module-specifiers-WF8iAydP.mjs";const I=r=>{const i=r.getSymbol();if(!i)return r.getText()==="defineMigration";for(const t of i.getDeclarations())if(a.isImportSpecifier(t))return h(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMigration":!1;return!1},d=(r,i)=>{const t=r.getProperty(i);if(!t||!a.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&a.isStringLiteral(e)?e.getLiteralValue():void 0},P=(r,i)=>{const t=r.getInitializer();if(t?.getKind()!==f.CallExpression)return;const e=t.getExpression();if(!a.isIdentifier(e)||!I(e))return;const o=t.getArguments()[0];if(!o||!a.isObjectLiteralExpression(o))return;const n=d(o,"id"),s=r.getName();if(n===void 0||n.trim()==="")throw u(o,`Migration "${s}" in "${i}" must declare \`id\` as a non-empty string literal so codegen can key the registry.`,{code:"MIGRATION_ID_NOT_STATIC",name:"LunoraError",status:500});return{exportName:s,filePath:i,id:n,table:d(o,"table")??""}},M=r=>{const i=new Map;for(const t of r){const e=i.get(t.id);if(e!==void 0)throw Object.assign(new Error(`Duplicate migration id "${t.id}": declared in both "${e}" and "${t.filePath}". Migration ids must be unique across the project.`),{code:"DUPLICATE_MIGRATION_ID",id:t.id,name:"LunoraError",paths:[e,t.filePath],status:500});i.set(t.id,t.filePath)}},y=(r,i)=>{const t=m(i),e=[];for(const o of t){const n=r.getSourceFile(o)??r.addSourceFileAtPath(o),s=p(i,o);for(const c of n.getVariableStatements())if(c.isExported())for(const g of c.getDeclarations()){const l=P(g,s);l&&e.push(l)}}return e.sort((o,n)=>o.id.localeCompare(n.id)),M(e),e};export{y as default};
@@ -1 +0,0 @@
1
- import{Node as s,SyntaxKind as a}from"ts-morph";import{l,a as c,h as d}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as f}from"./discoverFunctions-CKff5HG0.mjs";const u={"crypto.getRandomValues":"crypto.getRandomValues","crypto.randomUUID":"crypto.randomUUID","Date.now":"Date.now","Math.random":"Math.random"},m=new Set(["globalThis","self"]),g=new Set(["globalThis","self","window"]),p=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e)){const t=e.getExpression();if(s.isIdentifier(t)&&g.has(t.getText()))return e.getName()}},h=e=>{const t=e.getExpression();if(s.isIdentifier(t)){const o=t.getText();return o==="fetch"||o==="Date"?o:void 0}if(!s.isPropertyAccessExpression(t))return;const n=t.getName(),i=p(t.getExpression());if(i!==void 0)return n==="fetch"&&m.has(i)?"fetch":u[`${i}.${n}`]},x=e=>{const t=e.getExpression();if(!s.isIdentifier(t)||t.getText()!=="Date")return;const n=e.getArguments(),i=n.every(o=>s.isNumericLiteral(o)||s.isStringLiteral(o)||s.isNoSubstitutionTemplateLiteral(o));return n.length>0&&i?void 0:"new Date"},N=e=>{const t=e.getInitializer();if(!t||!s.isCallExpression(t))return;const n=f(t);if(!n||n.kind!=="query"&&n.kind!=="mutation")return;const i=d(t,n.receiver);return i?{exportName:e.getName(),handler:i,kind:n.kind}:void 0},E=(e,t)=>{const n=[];for(const i of e.handler.getDescendantsOfKind(a.CallExpression)){const o=h(i);o!==void 0&&n.push({callee:o,exportName:e.exportName,file:t,kind:e.kind,line:i.getStartLineNumber()})}for(const i of e.handler.getDescendantsOfKind(a.NewExpression)){const o=x(i);o!==void 0&&n.push({callee:o,exportName:e.exportName,file:t,kind:e.kind,line:i.getStartLineNumber()})}return n},S=(e,t)=>{const n=[];for(const i of e.getVariableStatements())if(i.isExported())for(const o of i.getDeclarations()){const r=N(o);r&&n.push(...E(r,t))}return n},w=(e,t)=>{const n=[];for(const i of l(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...S(o,c(t,i)))}return n};export{w as default};
@@ -1 +0,0 @@
1
- import{d as a}from"./discover-queries-Dfj_0WJG.mjs";import"./discover-ast-D33zP-NZ.mjs";export{a as default};
@@ -1 +0,0 @@
1
- import{Node as o,SyntaxKind as a}from"ts-morph";import{l as c,a as l,h as d}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as f}from"./discoverFunctions-CKff5HG0.mjs";const u=t=>{const r=t.getInitializer();if(!r||!o.isCallExpression(r))return;const e=f(r);if(!e||e.kind!=="query"&&e.kind!=="mutation")return;const n=d(r,e.receiver);return n?{exportName:t.getName(),handler:n,kind:e.kind}:void 0},p=t=>{if(!o.isPropertyAccessExpression(t)||t.getName()!=="r2sql")return;const r=t.getExpression();if(!o.isIdentifier(r)||r.getText()!=="ctx")return;const e=t.getParent();return e&&o.isPropertyAccessExpression(e)&&e.getExpression()===t?`ctx.r2sql.${e.getName()}`:"ctx.r2sql"},x=(t,r)=>{const e=[];for(const n of t.handler.getDescendantsOfKind(a.PropertyAccessExpression)){const s=p(n);s!==void 0&&e.push({callee:s,exportName:t.exportName,file:r,kind:t.kind,line:n.getStartLineNumber()})}return e},m=(t,r)=>{const e=[];for(const n of t.getVariableStatements())if(n.isExported())for(const s of n.getDeclarations()){const i=u(s);i&&e.push(...x(i,r))}return e},P=(t,r)=>{const e=[];for(const n of c(r)){const s=t.getSourceFile(n)??t.addSourceFileAtPath(n);e.push(...m(s,l(r,n)))}return e};export{P as default};
@@ -1 +0,0 @@
1
- import{Node as n}from"ts-morph";import{l as d,a as x,t as P,b as l}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as E}from"./discoverFunctions-CKff5HG0.mjs";const b=t=>{if(!n.isCallExpression(t))return!1;const e=t.getExpression();return n.isIdentifier(e)?e.getText()==="rls":n.isPropertyAccessExpression(e)?e.getName()==="rls":!1},v=t=>{const e=t.getArguments()[0];if(!e||!n.isArrayLiteralExpression(e))return[];const s=[];for(const r of e.getElements()){if(!n.isObjectLiteralExpression(r))continue;const i=r.getProperty("table");if(!i||!n.isPropertyAssignment(i))continue;const o=i.getInitializer();o&&n.isStringLiteral(o)&&s.push(o.getLiteralText())}return s},h=t=>{const e=[];let s=t;for(;n.isCallExpression(s);){const r=s.getExpression();if(!n.isPropertyAccessExpression(r))break;if(r.getName()==="use"){const i=s.getArguments()[0];i&&b(i)&&e.push(i)}s=r.getExpression()}return e},y=t=>{const e=h(t);return{rlsTables:e.flatMap(s=>v(s)),usesRls:e.length>0}},A=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),L=new Set(["delete","deleteMany","insert","insertMany","patch","patchMany","replace"]),S=(t,e)=>{if(!n.isVariableDeclaration(t))return;const s=t.getInitializer();if(!s||!n.isCallExpression(s))return;const r=E(s);if(!r)return;const i=r.receiver?y(r.receiver):{rlsTables:[],usesRls:!1},{tablesRead:o,tablesWritten:a}=P(t,A,L);return{exportName:t.getName(),file:e,rlsTables:i.rlsTables,tablesRead:o,tablesWritten:a,usesRls:i.usesRls,visibility:r.visibility}},w=(t,e)=>{const s=[];for(const r of d(e)){const i=t.getSourceFile(r)??t.addSourceFileAtPath(r),o=x(e,r);for(const a of i.getVariableStatements())if(a.isExported())for(const u of a.getDeclarations()){const c=S(u,o);c&&s.push(c)}}return s},C=new Set(["delete","insert","read","update"]),T=(t,e,s)=>{const r=t.getArguments()[0];if(!r||!n.isArrayLiteralExpression(r))return[];const i=[];for(const o of r.getElements()){if(!n.isObjectLiteralExpression(o))continue;const a=l(o,"on");a===void 0||!C.has(a)||i.push({file:e,on:a,procedure:s,table:l(o,"table")??""})}return i},g=t=>{if(!n.isObjectLiteralExpression(t))return[];const e=t.getProperty("permissions");if(!e||!n.isPropertyAssignment(e))return[];const s=e.getInitializer();if(!s||!n.isArrayLiteralExpression(s))return[];const r=[];for(const i of s.getElements()){if(n.isStringLiteral(i)){r.push(i.getLiteralText());continue}if(n.isCallExpression(i)){const o=i.getArguments()[0];o&&n.isStringLiteral(o)&&r.push(o.getLiteralText())}}return r},m=(t,e)=>e===void 0?t:{...t,description:e},R=t=>{if(n.isCallExpression(t)){const e=t.getArguments()[0];if(!e||!n.isStringLiteral(e))return;const s=t.getArguments()[1],r=s?l(s,"description"):void 0,i=s?g(s):[];return m({name:e.getLiteralText(),permissions:i},r)}if(n.isObjectLiteralExpression(t)){const e=l(t,"name");return e===void 0?void 0:m({name:e,permissions:g(t)},l(t,"description"))}},F=t=>{const e=t.getArguments()[1];if(!e||!n.isObjectLiteralExpression(e))return[];const s=e.getProperty("roles");if(!s||!n.isPropertyAssignment(s))return[];const r=s.getInitializer();if(!r||!n.isArrayLiteralExpression(r))return[];const i=[];for(const o of r.getElements()){const a=R(o);a&&i.push(a)}return i},I=(t,e,s)=>{const r=h(t);return{policies:r.flatMap(i=>T(i,e,s)),roles:r.flatMap(i=>F(i))}},M=t=>{const e=[];for(const s of t.getVariableStatements())if(s.isExported())for(const r of s.getDeclarations()){const i=r.getInitializer(),o=i&&n.isCallExpression(i)?E(i):void 0;o?.receiver&&e.push({name:r.getName(),receiver:o.receiver})}return e},D=(t,e)=>{const s=[],r=new Map;for(const i of d(e)){const o=t.getSourceFile(i)??t.addSourceFileAtPath(i),a=x(e,i);for(const{name:u,receiver:c}of M(o)){const p=I(c,a,u);s.push(...p.policies);for(const f of p.roles)r.has(f.name)||r.set(f.name,f)}}return{policies:s,roles:[...r.values()]}};export{w as default,D as discoverRlsMetadata};
@@ -1 +0,0 @@
1
- import{l as u}from"./discover-ast-D33zP-NZ.mjs";const i=new Set(["@lunora/agent","@lunora/agent/sandbox"]),d=o=>{const s={usesSandboxBrowser:!1,usesSandboxContainer:!1};if(!i.has(o.getModuleSpecifierValue())||o.isTypeOnly())return s;for(const e of o.getNamedImports()){if(e.isTypeOnly())continue;const n=e.getNameNode().getText();n==="browserTool"?s.usesSandboxBrowser=!0:n==="containerTool"&&(s.usesSandboxContainer=!0)}return s},S=(o,s)=>{const e={usesSandboxBrowser:!1,usesSandboxContainer:!1};for(const n of u(s)){const a=o.getSourceFile(n)??o.addSourceFileAtPath(n);for(const t of a.getImportDeclarations()){const r=d(t);e.usesSandboxBrowser||=r.usesSandboxBrowser,e.usesSandboxContainer||=r.usesSandboxContainer}if(e.usesSandboxBrowser&&e.usesSandboxContainer)break}return e};export{S as discoverSandboxUsage};
@@ -1 +0,0 @@
1
- import{LunoraError as _}from"@lunora/errors";import{Node as i,SyntaxKind as j}from"ts-morph";import{diagnosticAt as f}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as $}from"./parse-validator-BFTp87yz.mjs";import{createRequire as z}from"node:module";import{join as D}from"node:path";const C=e=>{switch(typeof e){case"bigint":return e.toString();case"boolean":case"number":return String(e);case"string":return JSON.stringify(e);default:return e===null?"null":void 0}},R=e=>({...e?.defaultValue!==void 0||e?.defaultFn!==void 0||e?.serverDefault!==void 0?{hasDefault:!0}:{},...e?.onUpdateFn===void 0?{}:{hasOnUpdate:!0},notNull:e?.notNull??!0,...e?.unique===!0?{unique:!0}:{}}),p=e=>{const n=e?._meta??{},t=e?.kind??"unknown",s={column:R(n.column),kind:t};switch(t){case"array":case"optional":{s.inner=p(n.inner);break}case"from":break;case"id":{s.tableName=n.tableName;break}case"literal":{s.literalValue=C(n.value);break}case"object":{const r=n.shape??{};s.shape=Object.fromEntries(Object.entries(r).map(([o,a])=>[o,p(a)]));break}case"record":{s.valueType=p(n.valueValidator),n.keyValidator!==void 0&&(s.keyType=p(n.keyValidator));break}case"storage":{typeof n.bucket=="string"&&(s.bucket=n.bucket);break}case"union":{const r=n.members??[];s.members=r.map(o=>p(o));break}}return s},M=e=>e?.kind==="global"?"global":e?.kind==="shardBy"&&typeof e.field=="string"?{field:e.field,kind:"shardBy"}:"root",F=(e,n)=>{const t=[];e.relationMap&&Object.keys(e.relationMap).length>0&&t.push("relations"),e.rankIndexes&&e.rankIndexes.length>0&&t.push("rank indexes"),e.vectorIndexes&&e.vectorIndexes.length>0&&t.push("vector indexes"),t.length>0&&console.warn(`@lunora/codegen: package schema-extension table "${n}" declares ${t.join(" + ")}, which are not yet introspected from a node_modules extension — they will be absent from the generated types.`)},B=(e,n)=>{const t=e.shape??{},s=(e.indexes??[]).map(r=>({fields:r.fields,name:r.name,...r.unique?{unique:!0}:{}}));return F(e,n),{...e.isExternallyManaged?{externallyManaged:!0}:{},geoIndexes:[],indexes:s,name:n,rankIndexes:[],relations:[],searchIndexes:(e.searchIndexes??[]).map(r=>({field:r.field,...r.filterFields?{filterFields:r.filterFields}:{},...r.language===void 0?{}:{language:r.language},...r.staged===void 0?{}:{staged:r.staged},...r.strategy===void 0?{}:{strategy:r.strategy},name:r.name})),shape:Object.fromEntries(Object.entries(t).map(([r,o])=>[r,p(o)])),shardMode:M(e.shardMode),vectorIndexes:[]}},V=e=>{const{key:n,tables:t}=e;if(typeof n!="string"||typeof t!="object"||t===null)return;const s=Object.entries(t).map(([a,l])=>B(l,a)),r=e.vectorIndexes??{},o=Object.entries(r??{}).map(([a,l])=>({...l.dimensions===void 0?{}:{dimensions:l.dimensions},...l.field===void 0?{}:{field:l.field},...l.metadata===void 0?{}:{metadata:l.metadata},...l.metric===void 0?{}:{metric:l.metric},name:a,table:l.table??""}));return{bareTables:s,bareVectorIndexes:o,key:n}},q=e=>{if(i.isIdentifier(e))return e.getText();if(i.isPropertyAccessExpression(e)){const n=e.getExpression();return i.isIdentifier(n)?n.getText():void 0}},J=e=>{const n=q(e);if(n===void 0)return;const t=i.isPropertyAccessExpression(e)?e.getName():void 0,s=t===void 0?[]:[t];for(const r of e.getSourceFile().getImportDeclarations()){const o=r.getModuleSpecifierValue();for(const a of r.getNamedImports())if((a.getAliasNode()?.getText()??a.getName())===n)return{importedName:a.getName(),moduleSpecifier:o,propertyPath:s};if(r.getDefaultImport()?.getText()===n)return{importedName:"default",moduleSpecifier:o,propertyPath:s};if(r.getNamespaceImport()?.getText()===n&&t!==void 0)return{importedName:t,moduleSpecifier:o,propertyPath:[]}}},U=(e,n)=>{let t=e[n.importedName];for(const s of n.propertyPath){if(typeof t!="object"||t===null)return;t=t[s]}return t},K=(e,n)=>{const t=J(e);if(t)try{const s=z(D(n,"noop.cjs")),r=s.resolve(t.moduleSpecifier),o=s(r),a=U(o,t);return typeof a!="object"||a===null?void 0:V(a)}catch{return}},G=new Set(["cosine","dot-product","euclidean"]),Z=new Set(["cascade","restrict","set null"]),I=new Set(["delete","get","insert","normalizeId","patch","query","replace","system"]),Q=new Set(["arguments","await","break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","eval","export","extends","false","finally","for","function","if","implements","import","in","instanceof","interface","let","new","null","package","private","protected","public","return","static","super","switch","this","throw","true","try","typeof","var","void","while","with","yield"]),W=/^[A-Za-z_$][\w$]*$/u,k=e=>e.replaceAll(/^["']|["']$/gu,""),w=(e,n)=>{const t=k(e);if(I.has(t))throw f(n,`table name "${t}" is reserved — it collides with a \`ctx.db\` member (one of ${[...I].map(s=>`"${s}"`).join(", ")}). Rename the table.`);if(Q.has(t))throw f(n,`table name "${t}" is a reserved JavaScript word — codegen interpolates table names into a bare \`const ${t} = sqliteTable(...)\` binding in the generated Drizzle module, which is a syntax error for a keyword. Rename the table.`);if(!W.test(t))throw f(n,`table name ${JSON.stringify(t)} is not a valid JS identifier — table names are used in generated type names (Doc_<name>) and must match [A-Za-z_$][A-Za-z0-9_$]*. Rename the table.`)},g=(e,n)=>{const t=e.getProperty(n);if(t&&i.isPropertyAssignment(t))return t.getInitializer()},d=(e,n)=>{const t=g(e,n);if(t&&i.isStringLiteral(t))return t.getLiteralText()},m=(e,n)=>{const t=g(e,n);if(t&&i.isNumericLiteral(t))return Number(t.getLiteralText())},X=(e,n)=>{const t=g(e,n);if(t&&(i.isTrueLiteral(t)||i.isFalseLiteral(t)))return t.getLiteralValue()},x=(e,n)=>{const t=g(e,n);if(t&&i.isArrayLiteralExpression(t))return t.getElements().filter(s=>i.isStringLiteral(s)).map(s=>s.getLiteralText())},T=e=>e&&G.has(e)?e:void 0,H=e=>e&&Z.has(e)?e:void 0,Y=e=>{if(!i.isArrowFunction(e))return;let n=e.getBody();if(i.isParenthesizedExpression(n))n=n.getExpression();else if(i.isBlock(n)){const t=n.getStatements().find(s=>i.isReturnStatement(s));n=t&&i.isReturnStatement(t)?t.getExpression()??n:n}return i.isObjectLiteralExpression(n)?n:void 0},ee=e=>{if(!i.isPropertyAssignment(e))return;const n=e.getInitializer();if(!n||!i.isCallExpression(n))return;const t=n.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName();if(s!=="one"&&s!=="many")return;const[r,o]=n.getArguments();if(!r||!i.isStringLiteral(r))throw f(r??n,`relation target table must be a string literal — codegen resolves relation targets statically. Got ${r?r.getText():"no argument"}.`);const a=r.getLiteralText();let l="_unknown_",c="_id",u;return o&&i.isObjectLiteralExpression(o)&&(l=d(o,"field")??l,c=d(o,"references")??c,u=s==="one"?H(d(o,"onDelete")):void 0),{field:l,kind:s,name:e.getName(),onDelete:u,references:c,table:a}},te=e=>{const n=Y(e);if(!n)return[];const t=[];for(const s of n.getProperties()){const r=ee(s);r&&t.push(r)}return t},b=e=>e&&i.isStringLiteral(e)?e.getLiteralText():"_unnamed_",ne=(e,n,t)=>{if(!n.includes("."))return;const[s="",...r]=n.split("."),o=`${s}${r.map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join("")}`;throw f(e,`index "${t}" indexes the nested path ${JSON.stringify(n)} — Lunora indexes only top-level columns. Denormalise the value into its own column (e.g. \`${o}\`), index that instead, and keep it in sync with a table \`.triggers()\` beforeInsert/beforeUpdate.`)},re=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const n=e.getProperty("unique");if(!n||!i.isPropertyAssignment(n))return!1;const t=n.getInitializer();if(t===void 0)return!1;if(!i.isTrueLiteral(t)&&!i.isFalseLiteral(t))throw f(t,`\`unique\` must be a literal \`true\` or \`false\`, got ${JSON.stringify(t.getText())}`);return i.isTrueLiteral(t)},se=e=>{const[n,t,s]=e,r=re(s),o=b(n),a=t&&i.isArrayLiteralExpression(t)?t.getElements():[];for(const c of a)if(!i.isStringLiteral(c))throw f(c,`index "${o}" lists a non-literal field (${JSON.stringify(c.getText())}); codegen reads index fields statically, so every entry must be a string literal.`);const l=a.filter(c=>i.isStringLiteral(c));for(const c of l)ne(c,c.getLiteralText(),o);return{fields:l.map(c=>c.getLiteralText()),name:o,unique:r}},ie=e=>{const[n,t]=e;let s="_unknown_",r,o,a,l;return t&&i.isObjectLiteralExpression(t)&&(s=d(t,"field")??s,r=x(t,"filterFields"),o=d(t,"language"),a=X(t,"staged"),l=d(t,"strategy")),{field:s,filterFields:r,language:o,name:b(n),staged:a,strategy:l}},oe=e=>{const[n,t]=e;let s="_unknown_",r;return t&&i.isObjectLiteralExpression(t)&&(s=d(t,"field")??s,r=m(t,"precision")),{field:s,name:b(n),precision:r}},ae=e=>{const[n,t]=e,s=n&&i.isStringLiteral(n)?n.getLiteralText():"_unknown_";let r;return t&&i.isObjectLiteralExpression(t)&&(r=m(t,"after")),{after:r,field:s}},le=e=>{if(!i.isObjectLiteralExpression(e))return;const n=d(e,"field");return n===void 0?void 0:{direction:d(e,"direction")==="desc"?"desc":"asc",field:n}},ce=e=>{const[n,t]=e;let s=[],r;if(t&&i.isObjectLiteralExpression(t)){const o=t.getProperty("sortBy");if(o&&i.isPropertyAssignment(o)){const a=o.getInitializer();a&&i.isArrayLiteralExpression(a)&&(s=a.getElements().map(l=>le(l)).filter(l=>l!==void 0))}r=x(t,"partitionBy")}return{name:b(n),partitionBy:r,sortBy:s}},de=(e,n)=>{const[t,s]=e,r=t&&i.isStringLiteral(t)?t.getLiteralText():"_unknown_";if(!(!s||!i.isObjectLiteralExpression(s)))return{dimensions:m(s,"dimensions"),field:r,metadata:x(s,"metadata"),metric:T(d(s,"metric")),name:d(s,"index")??"_unnamed_",table:n}},fe=e=>{const n=e[0];return n&&i.isObjectLiteralExpression(n)&&d(n,"backend")==="hyperdrive"?"hyperdrive":"d1"},ue=e=>{if(e&&i.isObjectLiteralExpression(e)){const n=e.getProperty("field");if(n&&i.isPropertyAssignment(n)){const t=n.getInitializer();if(t&&i.isStringLiteral(t))return t.getLiteralText()}}return"deletedAt"},pe=(e,n)=>{const t=x(e,n);return t!==void 0&&t.length>0?t:void 0},ge=e=>{const n=e[0];return!n||!i.isObjectLiteralExpression(n)?{binding:"",hasTenantBy:!1,unanalyzable:!0}:{binding:d(n,"binding")??"",columns:pe(n,"columns"),hasReconcile:n.getProperty("reconcileEveryMs")!==void 0,hasSoftDelete:n.getProperty("softDeleteColumn")!==void 0,hasTenantBy:n.getProperty("tenantBy")!==void 0,idColumn:d(n,"idColumn"),mode:d(n,"mode"),query:d(n,"query")}},me=(e,n,t,s)=>{switch(n){case"commitOrdered":{e.commitOrdered=!0;break}case"externallyManaged":{e.externallyManaged=!0;break}case"geoIndex":{e.geoIndexes.push(oe(t));break}case"global":{e.shardMode="global",e.globalBackend=fe(t);break}case"index":{e.indexes.push(se(t));break}case"memory":{e.memory=!0;break}case"public":{e.isPublic=!0;break}case"rankIndex":{e.rankIndexes.push(ce(t));break}case"relations":{const r=t[0];r&&e.relations.push(...te(r));break}case"searchIndex":{e.searchIndexes.push(ie(t));break}case"shardBy":{const r=t[0];e.shardMode={field:r&&i.isStringLiteral(r)?r.getLiteralText():"_unknown_",kind:"shardBy"};break}case"softDelete":{e.softDelete={field:ue(t[0])};break}case"source":{e.externalSource=ge(t),e.externallyManaged=!0;break}case"ttl":{e.ttl=ae(t);break}case"vectorize":{const r=de(t,s);r&&e.vectorIndexes.push(r);break}}},S=["__vocab","_config","_content","_data","_docsize","_idx"],xe=(e,n,t)=>{const s=new Set(t.map(r=>r.name));for(const r of t)for(const o of S){const a=`${r.name}${o}`;if(!s.has(a))continue;const l=o==="__vocab"?`the \`fts5vocab\` companion for "${a}" is created \`IF NOT EXISTS\`, so it silently resolves to "${r.name}"'s — the second index then reads the wrong vocabulary and returns wrong results, with no error`:`creating "${a}" is rejected (\`object name reserved for internal use: SQLITE_ERROR\`), which aborts the shard migration and leaves every sharded table unreadable`;throw f(e,`table "${n}" declares search indexes "${r.name}" and "${a}", whose generated FTS5 tables collide: "${r.name}" already owns "${n}__fts_${a}" as its "${o}" companion, so ${l}. Rename one of them so neither ends with another's name plus ${S.join(", ")}.`)}},L=(e,n)=>{const t={commitOrdered:!1,externallyManaged:!1,geoIndexes:[],indexes:[],isPublic:!1,memory:!1,rankIndexes:[],relations:[],searchIndexes:[],shardMode:"root",vectorIndexes:[]};let s={},r=e;for(;i.isCallExpression(r);){const o=r.getExpression(),a=r.getArguments();if(i.isPropertyAccessExpression(o))me(t,o.getName(),a,n),r=o.getExpression();else if(i.isIdentifier(o)&&o.getText()==="defineTable"){const l=a[0];if(l&&i.isObjectLiteralExpression(l))s=$(l);else if(l)throw f(l,`table "${n}" calls defineTable(${JSON.stringify(l.getText())}), but codegen reads the field map syntactically and can only read an object literal. Inline the fields into the defineTable(...) call. To reuse them in an \`.input()\`, derive from the generated \`Doc_${n}\` / \`Insert_${n}\` type instead of sharing the runtime value.`);break}else break}return t.softDelete&&!(t.softDelete.field in s)&&(s={...s,[t.softDelete.field]:{inner:{kind:"number"},kind:"optional"}}),xe(e,n,t.searchIndexes),{commitOrdered:t.commitOrdered,externallyManaged:t.externallyManaged,externalSource:t.externalSource,geoIndexes:t.geoIndexes,globalBackend:t.shardMode==="global"?t.globalBackend??"d1":void 0,indexes:t.indexes,isPublic:t.isPublic,memory:t.memory,name:n,rankIndexes:t.rankIndexes,relations:t.relations,searchIndexes:t.searchIndexes,shape:s,shardMode:t.shardMode,softDelete:t.softDelete,ttl:t.ttl,vectorIndexes:t.vectorIndexes}},be=e=>{const n=e.getProperty("source");if(n&&i.isPropertyAssignment(n)){const t=n.getInitializer();if(t&&i.isObjectLiteralExpression(t))return d(t,"table")??"_unknown_"}return"_unknown_"},he=e=>{if(!i.isPropertyAssignment(e))return;const n=e.getInitializer();if(!n||!i.isCallExpression(n))return;const t=n.getExpression();if(!i.isIdentifier(t)||t.getText()!=="defineVectorIndex")return;const s=n.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return;const r=e.getNameNode(),o=i.isStringLiteral(r)?r.getLiteralText():r.getText();return{dimensions:m(s,"dimensions"),metric:T(d(s,"metric")),name:o,table:be(s)}},O=e=>{const n=[];for(const t of e.getProperties()){const s=he(t);s&&n.push(s)}return n},v=(e,n)=>`${e}_${n}`,y=(e,n,t)=>t.has(e)?v(n,e):e,ye=(e,n,t)=>{const s=v(n,e.name);return{...e,extensionKey:n,name:s,relations:e.relations.map(r=>({...r,table:y(r.table,n,t)})),vectorIndexes:e.vectorIndexes.map(r=>({...r,table:y(r.table,n,t)}))}},ve=e=>{if(i.isVariableDeclaration(e)||i.isPropertyAssignment(e))return e.getInitializer();if(i.isShorthandPropertyAssignment(e))return e.getNameNode()},Ee=e=>{if(!i.isCallExpression(e))return!1;const n=e.getExpression();return i.isIdentifier(n)&&n.getText()==="defineSchemaExtension"},Ie=e=>{if(i.isIdentifier(e))return e;if(i.isPropertyAccessExpression(e)){const n=e.getExpression();return i.isIdentifier(n)?n:void 0}},Se=e=>{if(i.isObjectLiteralExpression(e))return e;if(i.isCallExpression(e)){const n=e.getExpression();let t;if(i.isIdentifier(n)?t=n.getText():i.isPropertyAccessExpression(n)&&(t=n.getName()),t==="definePlugin"){const s=e.getArguments()[1];return s&&i.isObjectLiteralExpression(s)?s:void 0}}},ke=(e,n)=>{const t=ve(e);if(t){if(i.isPropertyAccessExpression(n)){const s=Se(t);return s?g(s,n.getName()):void 0}return t}},we=e=>{let n=e,t=0;for(;n&&t<32;){if(t+=1,Ee(n))return n;const s=Ie(n),r=s&&i.isIdentifier(s)?s.getSymbol():void 0,a=(r?.getAliasedSymbol()?.getDeclarations()??r?.getDeclarations()??[])[0];if(!a)return;const l=a.getSourceFile();if(l.isInNodeModules()||l.isDeclarationFile())return;n=ke(a,n)}},Te=e=>{const[n,t]=e.getArguments();if(!(!n||!i.isStringLiteral(n))&&!(!t||!i.isObjectLiteralExpression(t)))return{key:n.getLiteralText(),options:t}},Le=e=>{const n=e.getProperty("tables");if(!n||!i.isPropertyAssignment(n))return[];const t=n.getInitializer();if(!t||!i.isObjectLiteralExpression(t))return[];const s=[];for(const r of t.getProperties()){if(!i.isPropertyAssignment(r))continue;const o=r.getInitializer();if(!o)continue;const a=r.getName();w(a,r.getNameNode()),s.push(L(o,a))}return s},Oe=e=>{const n=e.getProperty("vectorIndexes");if(!n||!i.isPropertyAssignment(n))return[];const t=n.getInitializer();return!t||!i.isObjectLiteralExpression(t)?[]:O(t)},P=(e,n,t)=>{const s=new Set(n.map(a=>a.name)),r=n.map(a=>ye(a,e,s)),o=t.map(a=>({...a,name:v(e,a.name),table:y(a.table,e,s)}));return{tables:r,vectorIndexes:o}},Pe=(e,n)=>P(e,Le(n),Oe(n)),Ne=(e,n)=>{const t=e.getArguments()[0];if(!t)return;const s=we(t);if(!s){if(n!==void 0){const o=K(t,n);if(o)return P(o.key,o.bareTables,o.bareVectorIndexes)}console.warn(`@lunora/codegen: skipping \`.extend(${t.getText()})\` — its \`defineSchemaExtension(...)\` could not be resolved from local sources, and ${n===void 0?"no project root was available to resolve the package":"the package could not be imported/introspected"}. Extension tables will be absent from the generated types.`);return}const r=Te(s);if(!r){console.warn("@lunora/codegen: skipping `.extend(...)` — `defineSchemaExtension` requires a string `key` and an options object literal.");return}return Pe(r.key,r.options)},Ae=e=>{const n=[];let t=e;for(;;){const s=t.getParent();if(!s||!i.isPropertyAccessExpression(s))break;const r=s.getParent();if(!r||!i.isCallExpression(r))break;s.getName()==="extend"&&n.push(r),t=r}return n},N=(e,n,t,s,r)=>{let o=e;for(;;){const a=o.getParent();if(!a||!i.isPropertyAccessExpression(a))break;const l=a.getParent();if(!l||!i.isCallExpression(l))break;if(a.getName()===n){const c=l.getArguments()[0];if(!c||!i.isStringLiteral(c))throw f(l,`\`.${n}(...)\` expects a string literal (${r})`);const u=c.getLiteralText();if(!s.has(u))throw f(c,`unknown ${t} ${JSON.stringify(u)} — expected ${r}`);return u}o=l}},_e=new Set(["eu","fedramp","us"]),je=e=>N(e,"jurisdiction","jurisdiction",_e,'"eu", "us", or "fedramp"'),$e=new Set(["required"]),ze=e=>N(e,"rls","rls mode",$e,'"required"'),De=e=>{const n=[],t=new Set;for(const s of e.getProperties()){if(!i.isPropertyAssignment(s))continue;const r=s.getInitializer();if(r){const o=s.getName();w(o,s.getNameNode());const a=k(o);if(t.has(a))throw f(s.getNameNode(),`defineSchema({...}): table "${a}" is declared more than once — the earlier declaration would be silently discarded. Remove the duplicate.`);t.add(a),n.push(L(r,o))}}return n},Ce=(e,n,t)=>{const s=new Set(n.map(o=>o.name)),r=[];for(const o of Ae(e)){const a=Ne(o,t);if(a){for(const l of a.tables){if(s.has(l.name))throw f(o,`defineSchema(...).extend(...): table "${l.name}" already exists — another extension with the same key already contributed it.`);s.add(l.name),n.push(l)}r.push(...a.vectorIndexes)}}return r},Je=(e,n,t)=>{const r=e.addSourceFileAtPath(n).getDescendantsOfKind(j.CallExpression).find(h=>{const E=h.getExpression();return i.isIdentifier(E)&&E.getText()==="defineSchema"});if(!r)throw new _("INTERNAL",`defineSchema() not found in ${n}`);const o=r.getArguments()[0];if(!o||!i.isObjectLiteralExpression(o))throw f(r,"defineSchema() expects an object literal");const a=De(o),l=r.getArguments()[1],c=l&&i.isObjectLiteralExpression(l)?O(l):[],u=Ce(r,a,t),A=[...a.flatMap(h=>h.vectorIndexes),...c,...u];return{jurisdiction:je(r),rlsMode:ze(r),tables:a,vectorIndexes:A}};export{Je as default};
@@ -1 +0,0 @@
1
- import{Node as n}from"ts-morph";import{l as f,a as p,b as u}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as g}from"./discoverFunctions-CKff5HG0.mjs";const m=new Set(["delete","list","read","write"]),d=o=>{if(!n.isCallExpression(o))return!1;const e=o.getExpression();return n.isIdentifier(e)?e.getText()==="storageRules":n.isPropertyAccessExpression(e)&&e.getName()==="storageRules"},x=o=>{const e=[];let s=o;for(;n.isCallExpression(s);){const t=s.getExpression();if(!n.isPropertyAccessExpression(t))break;if(t.getName()==="use"){const r=s.getArguments()[0];r&&d(r)&&e.push(r)}s=t.getExpression()}return e},h=(o,e,s)=>{const t=o.getArguments()[0];if(!t||!n.isArrayLiteralExpression(t))return[];const r=[];for(const i of t.getElements()){if(!n.isObjectLiteralExpression(i))continue;const a=u(i,"on");if(a===void 0||!m.has(a))continue;const c=u(i,"prefix"),l={bucket:u(i,"bucket")??"",file:e,on:a,procedure:s};c!==void 0&&(l.prefix=c),r.push(l)}return r},E=o=>{const e=[];for(const s of o.getVariableStatements())if(s.isExported())for(const t of s.getDeclarations()){const r=t.getInitializer(),i=r&&n.isCallExpression(r)?g(r):void 0;i?.receiver&&e.push({name:t.getName(),receiver:i.receiver})}return e},R=(o,e)=>{const s=[];for(const t of f(e)){const r=o.getSourceFile(t)??o.addSourceFileAtPath(t),i=p(e,t);for(const{name:a,receiver:c}of E(r))for(const l of x(c))s.push(...h(l,i,a))}return{rules:s}};export{R as default};