@lunora/codegen 1.0.0-alpha.416 → 1.0.0-alpha.418

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 (23) hide show
  1. package/dist/index.mjs +1 -1
  2. package/dist/packem_shared/{ALL_NOTIFY_CHANNELS-CoyNtlJg.mjs → ALL_NOTIFY_CHANNELS-BgkkvuUe.mjs} +1 -1
  3. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BDE_7uUb.mjs +56 -0
  4. package/dist/packem_shared/{SHAPES_FILENAME-BT27EjsB.mjs → SHAPES_FILENAME-C-hrGfJ2.mjs} +1 -1
  5. package/dist/packem_shared/{context-property-calls-Deip03CF.mjs → context-property-calls-BT1J7BqY.mjs} +1 -1
  6. package/dist/packem_shared/{context-root-UV6KjmwK.mjs → context-root-BpDEhvNE.mjs} +1 -1
  7. package/dist/packem_shared/{database-calls-CGw4OQvy.mjs → database-calls-d-Sssc-3.mjs} +1 -1
  8. package/dist/packem_shared/{discoverFunctions-MHRdfRso.mjs → discoverFunctions-C9HUlfiV.mjs} +1 -1
  9. package/dist/packem_shared/discoverHyperdriveCalls-BmAoOGGq.mjs +1 -0
  10. package/dist/packem_shared/{discoverInserts-C9-l0aVv.mjs → discoverInserts-DIarYU2P.mjs} +1 -1
  11. package/dist/packem_shared/discoverMaskProcedures-jkRrWS86.mjs +1 -0
  12. package/dist/packem_shared/{discoverQueries-BjyoiPKG.mjs → discoverQueries-DLZHcDzB.mjs} +1 -1
  13. package/dist/packem_shared/discoverR2sqlCalls-D_HWbbky.mjs +1 -0
  14. package/dist/packem_shared/{discoverRlsProcedures-BjN30sc6.mjs → discoverRlsProcedures-BbSdCvmA.mjs} +1 -1
  15. package/dist/packem_shared/{index-C7b1eUg3.mjs → index-CfSmiylg.mjs} +1 -1
  16. package/dist/packem_shared/{index-JMn3mU7I.mjs → index-DtJBMdZ4.mjs} +1 -1
  17. package/dist/packem_shared/ip-reads-D2qhKEb6.mjs +1 -0
  18. package/package.json +2 -2
  19. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BoqKQ7A_.mjs +0 -56
  20. package/dist/packem_shared/discoverHyperdriveCalls-DigrVFGI.mjs +0 -1
  21. package/dist/packem_shared/discoverMaskProcedures-B-59Z4Ua.mjs +0 -1
  22. package/dist/packem_shared/discoverR2sqlCalls-BUgyZ722.mjs +0 -1
  23. package/dist/packem_shared/ip-reads-Dct3s1DB.mjs +0 -1
@@ -0,0 +1 @@
1
+ import"./isTestPath-Uwb5a6Kq.mjs";import"./attribution-Cwt30DDJ.mjs";import"./database-calls-d-Sssc-3.mjs";import"./classify-procedure-call-BmEirzc_.mjs";import{d as a}from"./index-CfSmiylg.mjs";export{a as default};
@@ -1 +1 @@
1
- import{Node as i,SyntaxKind as u}from"ts-morph";import{collectCallRows as x}from"./isTestPath-Uwb5a6Kq.mjs";import{w as E,c as h}from"./attribution-Cwt30DDJ.mjs";import{i as v}from"./database-calls-CGw4OQvy.mjs";const A=new Set(["withGeoIndex","withIndex","withSearchIndex"]),S=new Set(["collect","collectWithScores","first","paginate","take","unique"]),w=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="query")return!1;const n=e.getExpression();return v(n)},y=t=>{const e=[];let n=t;for(;;){const s=n.getParent();if(!s||!i.isPropertyAccessExpression(s))break;const r=s.getParent();if(!r||!i.isCallExpression(r))break;e.push(r),n=r}return e},l=t=>{const e=t.getExpression();return i.isPropertyAccessExpression(e)?e.getName():""},m=t=>{if(t===void 0||!(i.isArrowFunction(t)||i.isFunctionExpression(t)))return;const e=t.getParameters()[0]?.getNameNode();return e!==void 0&&i.isIdentifier(e)?e.getText():void 0},O=t=>{let e=t;for(;i.isCallExpression(e)||i.isPropertyAccessExpression(e);)e=e.getExpression();return e},P=(t,e)=>{const n=new Set,s=[t,...t.getDescendantsOfKind(u.CallExpression)].filter(r=>i.isCallExpression(r));for(const r of s){const c=r.getExpression();if(i.isPropertyAccessExpression(c)){const o=O(c);i.isIdentifier(o)&&o.getText()===e&&n.add(c.getName())}}return n},f=(t,e)=>{if(i.isParenthesizedExpression(t))return f(t.getExpression(),e);if(i.isConditionalExpression(t)){const n=f(t.getWhenFalse(),e);return new Set([...f(t.getWhenTrue(),e)].filter(s=>n.has(s)))}return P(t,e)},C=t=>{if(!(i.isArrowFunction(t)||i.isFunctionExpression(t)))return;const e=t.getBody();if(!i.isBlock(e))return i.isExpression(e)?[e]:void 0;const n=e.getDescendantsOfKind(u.ReturnStatement).filter(s=>s.getFirstAncestor(r=>i.isArrowFunction(r)||i.isFunctionExpression(r))?.compilerNode===t.compilerNode).map(s=>s.getExpression()).filter(s=>s!==void 0);return n.length===0?void 0:n},F=(t,e)=>{const n=C(t);if(n===void 0)return;const[s,...r]=n.map(o=>f(o,e));return[...s??new Set].filter(o=>r.every(d=>d.has(o))).toSorted((o,d)=>o.localeCompare(d))},I=(t,e)=>{const n=new Set;for(const s of t.getDescendantsOfKind(u.PropertyAccessExpression)){const r=s.getExpression();i.isIdentifier(r)&&r.getText()===e&&n.add(s.getName())}for(const s of t.getDescendantsOfKind(u.ElementAccessExpression)){const r=s.getExpression(),c=s.getArgumentExpression();i.isIdentifier(r)&&r.getText()===e&&c!==void 0&&i.isStringLiteral(c)&&n.add(c.getLiteralText())}return[...n]},N=t=>{if(t===void 0)return;const[e,n]=t.getArguments(),s=m(n),r=e!==void 0&&i.isStringLiteral(e)?e.getLiteralText():void 0;return n===void 0?{bounds:[],name:r}:{bounds:s===void 0?void 0:F(n,s),name:r}},T=t=>{const e=t.flatMap(n=>{const s=n.getArguments()[0],r=m(s);return s===void 0||r===void 0?[]:I(s,r)});if(e.length!==0)return[...new Set(e)].toSorted((n,s)=>n.localeCompare(s))},b=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,D=t=>t.some(e=>l(e)==="filter"&&b.test(e.getArguments()[0]?.getText()??"")),L=t=>{const e=t.getArguments()[0];return e&&i.isStringLiteral(e)?e.getLiteralText():""},k=(t,e,n=[])=>{const s=x(t,e,(r,c)=>{if(!w(r))return;const o=y(r),d=o.map(a=>l(a)),p=o.filter(a=>l(a)==="filter"),g=p.length>0;return{file:c,filterFields:g?T(p):void 0,filtersPrimaryKey:g&&D(o),hasFilter:g,hasIndex:d.some(a=>A.has(a)),index:N(o.find(a=>l(a)==="withIndex")),line:r.getStartLineNumber(),scope:h(r),table:L(r),terminal:d.findLast(a=>S.has(a))}});return E(s,n)};export{k as default};
1
+ import{Node as i,SyntaxKind as u}from"ts-morph";import{collectCallRows as x}from"./isTestPath-Uwb5a6Kq.mjs";import{w as E,c as h}from"./attribution-Cwt30DDJ.mjs";import{i as v}from"./database-calls-d-Sssc-3.mjs";const A=new Set(["withGeoIndex","withIndex","withSearchIndex"]),S=new Set(["collect","collectWithScores","first","paginate","take","unique"]),w=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="query")return!1;const n=e.getExpression();return v(n)},y=t=>{const e=[];let n=t;for(;;){const s=n.getParent();if(!s||!i.isPropertyAccessExpression(s))break;const r=s.getParent();if(!r||!i.isCallExpression(r))break;e.push(r),n=r}return e},l=t=>{const e=t.getExpression();return i.isPropertyAccessExpression(e)?e.getName():""},m=t=>{if(t===void 0||!(i.isArrowFunction(t)||i.isFunctionExpression(t)))return;const e=t.getParameters()[0]?.getNameNode();return e!==void 0&&i.isIdentifier(e)?e.getText():void 0},O=t=>{let e=t;for(;i.isCallExpression(e)||i.isPropertyAccessExpression(e);)e=e.getExpression();return e},P=(t,e)=>{const n=new Set,s=[t,...t.getDescendantsOfKind(u.CallExpression)].filter(r=>i.isCallExpression(r));for(const r of s){const c=r.getExpression();if(i.isPropertyAccessExpression(c)){const o=O(c);i.isIdentifier(o)&&o.getText()===e&&n.add(c.getName())}}return n},f=(t,e)=>{if(i.isParenthesizedExpression(t))return f(t.getExpression(),e);if(i.isConditionalExpression(t)){const n=f(t.getWhenFalse(),e);return new Set([...f(t.getWhenTrue(),e)].filter(s=>n.has(s)))}return P(t,e)},C=t=>{if(!(i.isArrowFunction(t)||i.isFunctionExpression(t)))return;const e=t.getBody();if(!i.isBlock(e))return i.isExpression(e)?[e]:void 0;const n=e.getDescendantsOfKind(u.ReturnStatement).filter(s=>s.getFirstAncestor(r=>i.isArrowFunction(r)||i.isFunctionExpression(r))?.compilerNode===t.compilerNode).map(s=>s.getExpression()).filter(s=>s!==void 0);return n.length===0?void 0:n},F=(t,e)=>{const n=C(t);if(n===void 0)return;const[s,...r]=n.map(o=>f(o,e));return[...s??new Set].filter(o=>r.every(d=>d.has(o))).toSorted((o,d)=>o.localeCompare(d))},I=(t,e)=>{const n=new Set;for(const s of t.getDescendantsOfKind(u.PropertyAccessExpression)){const r=s.getExpression();i.isIdentifier(r)&&r.getText()===e&&n.add(s.getName())}for(const s of t.getDescendantsOfKind(u.ElementAccessExpression)){const r=s.getExpression(),c=s.getArgumentExpression();i.isIdentifier(r)&&r.getText()===e&&c!==void 0&&i.isStringLiteral(c)&&n.add(c.getLiteralText())}return[...n]},N=t=>{if(t===void 0)return;const[e,n]=t.getArguments(),s=m(n),r=e!==void 0&&i.isStringLiteral(e)?e.getLiteralText():void 0;return n===void 0?{bounds:[],name:r}:{bounds:s===void 0?void 0:F(n,s),name:r}},T=t=>{const e=t.flatMap(n=>{const s=n.getArguments()[0],r=m(s);return s===void 0||r===void 0?[]:I(s,r)});if(e.length!==0)return[...new Set(e)].toSorted((n,s)=>n.localeCompare(s))},b=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,D=t=>t.some(e=>l(e)==="filter"&&b.test(e.getArguments()[0]?.getText()??"")),L=t=>{const e=t.getArguments()[0];return e&&i.isStringLiteral(e)?e.getLiteralText():""},k=(t,e,n=[])=>{const s=x(t,e,(r,c)=>{if(!w(r))return;const o=y(r),d=o.map(a=>l(a)),p=o.filter(a=>l(a)==="filter"),g=p.length>0;return{file:c,filterFields:g?T(p):void 0,filtersPrimaryKey:g&&D(o),hasFilter:g,hasIndex:d.some(a=>A.has(a)),index:N(o.find(a=>l(a)==="withIndex")),line:r.getStartLineNumber(),scope:h(r),table:L(r),terminal:d.findLast(a=>S.has(a))}});return E(s,n)};export{k as default};
@@ -0,0 +1 @@
1
+ import{d as r}from"./context-property-calls-BT1J7BqY.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
@@ -1 +1 @@
1
- import{Node as l}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as f,declarationLineOf as u,findObjectProperty as p}from"./isTestPath-Uwb5a6Kq.mjs";import{j as d,h as m}from"./attribution-Cwt30DDJ.mjs";import{t as b}from"./database-calls-CGw4OQvy.mjs";import{c as h}from"./classify-procedure-call-BmEirzc_.mjs";import{r as y,p as v}from"./policies-Dn_tuTZd.mjs";const P=e=>{const s=[];for(const r of v(e)){const t=p(r,"table");if(!t||!l.isPropertyAssignment(t))continue;const i=t.getInitializer();i&&l.isStringLiteral(i)&&s.push(i.getLiteralText())}return s},T=e=>{const s=y(e);return{rlsTables:s.flatMap(r=>P(r)),usesRls:s.length>0}},g=new Set(["explain","findFirst","findFirstOrThrow","findMany","get","query"]),R=new Set(["delete","deleteMany","insert","insertMany","patch","patchIf","patchMany","replace"]),x=(e,s)=>{if(!l.isVariableDeclaration(e))return;const r=e.getInitializer();if(!r||!l.isCallExpression(r))return;const t=h(r);if(!t)return;const i=t.receiver?T(t.receiver):{rlsTables:[],usesRls:!1},{tablesRead:o,tablesWritten:a}=b(e,g,R);return{exportName:m(e)??e.getName(),file:s,line:u(e),rlsTables:i.rlsTables,tablesRead:o,tablesWritten:a,usesRls:i.usesRls,visibility:t.visibility}},D=(e,s)=>{const r=[];for(const t of c(s)){const i=e.getSourceFile(t)??e.addSourceFileAtPath(t),o=f(s,t);for(const a of d(i)){const n=x(a,o);n&&r.push(n)}}return r};export{D as default};
1
+ import{Node as l}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as f,declarationLineOf as u,findObjectProperty as p}from"./isTestPath-Uwb5a6Kq.mjs";import{j as d,h as m}from"./attribution-Cwt30DDJ.mjs";import{t as b}from"./database-calls-d-Sssc-3.mjs";import{c as h}from"./classify-procedure-call-BmEirzc_.mjs";import{r as y,p as v}from"./policies-Dn_tuTZd.mjs";const P=e=>{const s=[];for(const r of v(e)){const t=p(r,"table");if(!t||!l.isPropertyAssignment(t))continue;const i=t.getInitializer();i&&l.isStringLiteral(i)&&s.push(i.getLiteralText())}return s},T=e=>{const s=y(e);return{rlsTables:s.flatMap(r=>P(r)),usesRls:s.length>0}},g=new Set(["explain","findFirst","findFirstOrThrow","findMany","get","query"]),R=new Set(["delete","deleteMany","insert","insertMany","patch","patchIf","patchMany","replace"]),x=(e,s)=>{if(!l.isVariableDeclaration(e))return;const r=e.getInitializer();if(!r||!l.isCallExpression(r))return;const t=h(r);if(!t)return;const i=t.receiver?T(t.receiver):{rlsTables:[],usesRls:!1},{tablesRead:o,tablesWritten:a}=b(e,g,R);return{exportName:m(e)??e.getName(),file:s,line:u(e),rlsTables:i.rlsTables,tablesRead:o,tablesWritten:a,usesRls:i.usesRls,visibility:t.visibility}},D=(e,s)=>{const r=[];for(const t of c(s)){const i=e.getSourceFile(t)??e.addSourceFileAtPath(t),o=f(s,t);for(const a of d(i)){const n=x(a,o);n&&r.push(n)}}return r};export{D as default};
@@ -1 +1 @@
1
- import{Node as r}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as f,declarationLineOf as m}from"./isTestPath-Uwb5a6Kq.mjs";import{j as p,h as d}from"./attribution-Cwt30DDJ.mjs";import{t as g}from"./database-calls-CGw4OQvy.mjs";import{w as h,c as k}from"./classify-procedure-call-BmEirzc_.mjs";import{a as v}from"./property-name-7cBlgK_O.mjs";const l=e=>{if(!(!r.isPropertyAssignment(e)&&!r.isShorthandPropertyAssignment(e)&&!r.isMethodDeclaration(e)&&!r.isGetAccessorDeclaration(e)))return v(e)},P=e=>h(e,"use","mask"),E=e=>{if(r.isPropertyAssignment(e)){const s=e.getInitializer();if(s&&r.isStringLiteral(s)){const t=s.getLiteralText();if(t==="redact"||t==="hash")return t}}return"custom"},y=e=>{const s=e.getArguments()[0];if(!s||!r.isObjectLiteralExpression(s))return[];const t=[];for(const i of s.getProperties()){const o=l(i);if(o===void 0||!r.isPropertyAssignment(i))continue;const n=i.getInitializer();if(!(!n||!r.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=l(a);c!==void 0&&t.push({column:c,table:o})}}return t},C=e=>{const s=P(e);return{maskColumns:s.flatMap(t=>y(t)),usesMask:s.length>0}},M=new Set(["explain","findFirst","findFirstOrThrow","findMany","get","query"]),x=new Set(["delete","insert","patch","replace"]),A=(e,s)=>{if(!r.isVariableDeclaration(e))return;const t=e.getInitializer();if(!t||!r.isCallExpression(t))return;const i=k(t);if(!i)return;const o=i.receiver?C(i.receiver):{maskColumns:[],usesMask:!1},{tablesRead:n,tablesWritten:a}=g(e,M,x);return{exportName:d(e)??e.getName(),file:s,line:m(e),maskColumns:o.maskColumns,tablesRead:n,tablesWritten:a,usesMask:o.usesMask,visibility:i.visibility}},z=(e,s)=>{const t=[];for(const i of u(s)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i),n=f(s,i);for(const a of p(o)){const c=A(a,n);c&&t.push(c)}}return t};export{l as a,z as d,P as m,E as s};
1
+ import{Node as r}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as f,declarationLineOf as m}from"./isTestPath-Uwb5a6Kq.mjs";import{j as p,h as d}from"./attribution-Cwt30DDJ.mjs";import{t as g}from"./database-calls-d-Sssc-3.mjs";import{w as h,c as k}from"./classify-procedure-call-BmEirzc_.mjs";import{a as v}from"./property-name-7cBlgK_O.mjs";const l=e=>{if(!(!r.isPropertyAssignment(e)&&!r.isShorthandPropertyAssignment(e)&&!r.isMethodDeclaration(e)&&!r.isGetAccessorDeclaration(e)))return v(e)},P=e=>h(e,"use","mask"),E=e=>{if(r.isPropertyAssignment(e)){const s=e.getInitializer();if(s&&r.isStringLiteral(s)){const t=s.getLiteralText();if(t==="redact"||t==="hash")return t}}return"custom"},y=e=>{const s=e.getArguments()[0];if(!s||!r.isObjectLiteralExpression(s))return[];const t=[];for(const i of s.getProperties()){const o=l(i);if(o===void 0||!r.isPropertyAssignment(i))continue;const n=i.getInitializer();if(!(!n||!r.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=l(a);c!==void 0&&t.push({column:c,table:o})}}return t},C=e=>{const s=P(e);return{maskColumns:s.flatMap(t=>y(t)),usesMask:s.length>0}},M=new Set(["explain","findFirst","findFirstOrThrow","findMany","get","query"]),x=new Set(["delete","insert","patch","replace"]),A=(e,s)=>{if(!r.isVariableDeclaration(e))return;const t=e.getInitializer();if(!t||!r.isCallExpression(t))return;const i=k(t);if(!i)return;const o=i.receiver?C(i.receiver):{maskColumns:[],usesMask:!1},{tablesRead:n,tablesWritten:a}=g(e,M,x);return{exportName:d(e)??e.getName(),file:s,line:m(e),maskColumns:o.maskColumns,tablesRead:n,tablesWritten:a,usesMask:o.usesMask,visibility:i.visibility}},z=(e,s)=>{const t=[];for(const i of u(s)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i),n=f(s,i);for(const a of p(o)){const c=A(a,n);c&&t.push(c)}}return t};export{l as a,z as d,P as m,E as s};
@@ -1 +1 @@
1
- import{LunoraError as g}from"@lunora/errors";import{Node as s,SyntaxKind as B}from"ts-morph";import{d as z}from"./declared-output-Iaar469J.mjs";import{findObjectProperty as h,bindingKeyName as H,listLunoraSourceFiles as M,lunoraRelativePath as W}from"./isTestPath-Uwb5a6Kq.mjs";import{e as K,i as O}from"./attribution-Cwt30DDJ.mjs";import{u as R,p as q,r as Y,c as w,a as G}from"./unwrap-handler-return-DvbyiLjc.mjs";import{m as J}from"./ip-reads-Dct3s1DB.mjs";import{b as L,s as X,c as Q}from"./classify-procedure-call-BmEirzc_.mjs";import{r as D,p as C,a as Z}from"./parse-validator-BisfC8bR.mjs";import{N as ee,l as te}from"./project-config-file-DR7xrrNB.mjs";import{s as ie}from"./dispatch-namespace-DwTjD7BU.mjs";const I=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,ne=e=>{const i=e.getArguments()[0],t=I(i);if(t!==void 0)return t;if(i===void 0||!s.isObjectLiteralExpression(i))return;const n=h(i,"handler");return n!==void 0&&s.isPropertyAssignment(n)?I(n.getInitializer()):void 0},re=e=>{const i=e.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return"unknown";const t=h(i,"handler");if(!t||!s.isPropertyAssignment(t))return"unknown";const n=t.getInitializer();return!n||!(s.isArrowFunction(n)||s.isFunctionExpression(n))?"unknown":R(n)},oe=e=>{const i=e.getArguments()[0];return!i||!(s.isArrowFunction(i)||s.isFunctionExpression(i))?"unknown":R(i)},se=e=>{let i={};for(const t of L(e)){if(t.name!=="input")continue;const n=t.call.getArguments()[0],o=n!==void 0&&s.isExpression(n)?D(n):void 0;o!==void 0&&(i={...C(o),...i})}return i},ae=e=>{const i=L(e).find(n=>n.name==="output");if(!i)return;const t=i.call.getArguments()[0];return t&&s.isExpression(t)?q(i.call,()=>Z(t)):void 0},E=(e,i)=>{const t=h(e,i);if(t===void 0||!s.isPropertyAssignment(t))return;const n=t.getInitializer();return n!==void 0&&s.isStringLiteral(n)?n.getLiteralValue():void 0},k=(e,i)=>{const t=h(e,i);if(t===void 0||!s.isPropertyAssignment(t))return;const n=t.getInitializer();return n!==void 0&&s.isNumericLiteral(n)?n.getLiteralValue():void 0},ce=e=>{const i=h(e,"cache");if(i===void 0||!s.isPropertyAssignment(i))return;const t=i.getInitializer();if(t===void 0||!s.isObjectLiteralExpression(t))return;const n=E(t,"scope"),o=k(t,"maxAge"),r=k(t,"staleWhileRevalidate"),a=E(t,"tag"),c=E(t,"vary"),l={...o===void 0?{}:{maxAge:o},...n==="private"||n==="public"?{scope:n}:{},...r===void 0?{}:{staleWhileRevalidate:r},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},le=e=>{if(e===void 0||!s.isObjectLiteralExpression(e))return{};const i=ce(e),t=h(e,"rest");return t!==void 0&&s.isPropertyAssignment(t)?{...i===void 0?{}:{cache:i},rest:t.getInitializer()?.getText()==="true"}:i===void 0?{}:{cache:i}},ue=e=>{const i=L(e).find(t=>t.name==="expose");return i?le(i.call.getArguments()[0]):void 0},de=e=>{const i=L(e).find(r=>r.name==="x402");if(!i)return;const t=i.call.getArguments()[0];if(t===void 0||!s.isObjectLiteralExpression(t))return{};const n=h(t,"price");if(n===void 0||!s.isPropertyAssignment(n))return{};const o=n.getInitializer();return o===void 0?{}:s.isStringLiteral(o)?{price:o.getLiteralValue()}:s.isNumericLiteral(o)?{price:o.getLiteralValue()}:{}},ge=e=>{const i=e.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return{};const t=h(i,"args");if(!t||!s.isPropertyAssignment(t))return{};const n=t.getInitializer(),o=n===void 0?void 0:D(n);return o===void 0?{}:C(o)},f=(e,i)=>{throw new g("INTERNAL",`@lunora/codegen: lazy function registry needs literal ${i} in ${e.getSourceFile().getFilePath()}:${String(e.getStartLineNumber())}`)},S=(e,i,t)=>{if(!e||!s.isObjectLiteralExpression(e))return f(i,"metadata objects");const n=new Set;for(const o of e.getProperties()){if(!s.isPropertyAssignment(o))return f(o,"metadata fields without spreads, getters, or shorthand");const r=o.getNameNode(),a=s.isStringLiteral(r)?r.getLiteralValue():r.getText();if(!s.isIdentifier(r)&&!s.isStringLiteral(r)||!t.includes(a)||n.has(a))return f(o,"supported, unique metadata fields");n.add(a)}return e},y=(e,i)=>{const t=e.getProperty(i);return t&&s.isPropertyAssignment(t)?t.getInitializer():void 0},pe=e=>{const i=S(e,e,["credentialHeaders","maxAge","scope","staleWhileRevalidate","tag","vary"]),t={};for(const r of["maxAge","staleWhileRevalidate"]){const a=y(i,r);if(!(a===void 0&&r!=="maxAge")){if(!a||!s.isNumericLiteral(a))return f(e,`cache.${r}`);t[r]=a.getLiteralValue()}}const n=y(i,"scope");if(!n||!s.isStringLiteral(n)||!["private","public"].includes(n.getLiteralValue()))return f(e,"cache.scope");t.scope=n.getLiteralValue();for(const r of["tag","vary"]){const a=y(i,r);if(a!==void 0){if(!s.isStringLiteral(a))return f(a,`cache.${r}`);t[r]=a.getLiteralValue()}}const o=y(i,"credentialHeaders");if(o!==void 0){if(!s.isArrayLiteralExpression(o))return f(o,"cache.credentialHeaders");t.credentialHeaders=o.getElements().map(r=>s.isStringLiteral(r)?r.getLiteralValue():f(r,"cache.credentialHeaders string entries"))}return t},fe=e=>{const i=S(e.getArguments()[0],e,["rest","cache"]),t=y(i,"rest"),n=y(i,"cache");return t!==void 0&&!s.isTrueLiteral(t)&&!s.isFalseLiteral(t)?f(t,".expose({ rest })"):{...t?{rest:s.isTrueLiteral(t)}:{},...n?{cache:pe(n)}:{}}},me=e=>{const i=S(e.getArguments()[0],e,["price"]),t=y(i,"price");return!t||!s.isStringLiteral(t)&&!s.isNumericLiteral(t)?f(e,"`.x402({ price })` value"):{price:t.getLiteralValue()}},he=e=>{const i=e.map(o=>{const r=o.getArguments()[0];return r===void 0?ee:te(r)}),t=i.every(o=>o!==null&&typeof o=="object"&&!Array.isArray(o)),n=i.reduce((o,r)=>({...r,...o}),{});return t?n:"unloaded"},ye=e=>{const{factory:i,steps:t}=X(e);if(!i)return f(e,"metadata from a resolvable Lunora factory root");const n={visibility:i.startsWith("internal")?"internal":"public"};for(const{call:r,name:a}of t){if(!["expose","input","meta","output","use","x402"].includes(a))return f(r,`known builder modifiers, got .${a}()`);a==="expose"&&n.expose===void 0&&(n.expose=fe(r)),a==="x402"&&n.x402===void 0&&(n.x402=me(r))}const o=t.filter(r=>r.name==="meta").map(r=>r.call);return o.length===0?n:{...n,meta:he(o)}},ve=new Set(["action","mutation","query","stream"]),N=(e,i,t)=>{const n=e.getProperty(i)?.getTypeAtLocation(t);if(n===void 0)return;const o=n.isUnion()?n.getUnionTypes().filter(a=>!a.isUndefined()):[n],r=o.length===1?o[0]?.getLiteralValue():void 0;return typeof r=="string"?r:void 0},U=(e,i)=>{const t=N(e,"kind",i);return t!==void 0&&ve.has(t)&&e.getProperty("handler")!==void 0?t:void 0},be=e=>{const i=e.getParent();if(s.isPropertyAccessExpression(i)&&i.getExpression()===e)return i.getName()==="functions";if(s.isElementAccessExpression(i)&&i.getExpression()===e){const n=i.getArgumentExpression();return n!==void 0&&s.isStringLiteral(n)&&n.getLiteralValue()==="functions"}const t=s.isVariableDeclaration(i)&&i.getNameNode()!==e?i.getNameNode():void 0;return t!==void 0&&s.isObjectBindingPattern(t)&&t.getElements().some(n=>(n.getPropertyNameNode()?.getText()??n.getName())==="functions")},it=(e,i)=>{for(const t of e)for(const n of t.getVariableDeclarations()){const o=n.getNameNode();if(!n.isExported()||!s.isIdentifier(o))continue;const a=(n.getType().getProperty("functions")?.getTypeAtLocation(n)?.getProperties()??[]).filter(u=>U(u.getTypeAtLocation(n),n)!==void 0);if(a.length===0||o.findReferencesAsNodes().some(u=>be(u)))continue;const l=n.getName(),d=a.map(u=>u.getName()).join(", ");console.warn(`@lunora/codegen: ${i(t)}:${l} ships functions (${d}) that nothing re-exports, so none is in the generated api. Add \`export const { ${d} } = ${l}.functions;\` (or export your own wrappers of them).`)}},Ne=new Set(["connect","disconnect","init","reactor","whisper"]),Le={ArrayBuffer:"bytes",GeoPoint:"geoPoint"},Ae=8,P=(e,i)=>{const t=e.getText(i);return t===""?{kind:"from"}:{kind:"from",tsType:t}},Ee=new Set(["false","true"]),Pe=[[e=>e.isAny()||e.isUnknown(),"any"],[e=>e.isString(),"string"],[e=>e.isNumber(),"number"],[e=>e.isBoolean(),"boolean"],[e=>e.isNull(),"null"],[e=>e.isBigInt(),"bigint"]],Te=(e,i,t)=>{if(!e.isObject()||e.isIntersection()||e.getCallSignatures().length>0||e.isClass())return;const n=e.getProperties();if(n.some(r=>r.getTypeAtLocation(i).getCallSignatures().length>0))return;const o=e.getStringIndexType();if(o!==void 0&&n.length===0)return{keyType:{kind:"string"},kind:"record",valueType:b(o,i,t+1)};if(!(o!==void 0||n.length===0))return{kind:"object",shape:Object.fromEntries(n.map(r=>[r.getName(),$(r.getTypeAtLocation(i),r.isOptional(),i,t+1)]))}},b=(e,i,t)=>{if(t>Ae)return P(e,i);const n=Pe.find(([a])=>a(e));if(n!==void 0)return{kind:n[1]};const o=Le[(e.getSymbol()??e.getAliasSymbol())?.getName()??""];if(o!==void 0)return{kind:o};if(e.isStringLiteral()||e.isNumberLiteral()||e.isBooleanLiteral()||e.isBigIntLiteral())return{kind:"literal",literalValue:e.getText(i),sensitive:!0};const r=e.isIntersection()?N(e,"__table",i):void 0;if(r!==void 0)return{kind:"id",tableName:r};if(e.isUnion())return F(e.getUnionTypes(),i,t);if(e.isArray()){const a=e.getArrayElementType();return a===void 0?P(e,i):{inner:b(a,i,t+1),kind:"array"}}return Te(e,i,t)??P(e,i)},F=(e,i,t)=>{const o=new Set(e.filter(l=>l.isBooleanLiteral()).map(l=>l.getText(i))).size===Ee.size,r=e.filter(l=>!(o&&l.isBooleanLiteral())).map(l=>b(l,i,t+1)),a=o?[...r,{kind:"boolean"}]:r,[c]=a;return a.length===1&&c!==void 0?c:{kind:"union",members:a}},$=(e,i,t,n)=>{const o=e.isUnion()?e.getUnionTypes():[e],r=o.filter(l=>!l.isUndefined());if(!i&&r.length===o.length)return b(e,t,n);if(r.length===0)return{inner:{kind:"any"},kind:"optional"};const[a]=r;return{inner:r.length===1&&a!==void 0?b(a,t,n):F(r,t,n),kind:"optional"}},xe=(e,i)=>{const t=e.getProperty("__type")?.getTypeAtLocation(i);if(t===void 0)return{kind:"from"};const n=(e.getSymbol()??e.getAliasSymbol())?.getName();return n==="TimestampColumnValidator"?{kind:"timestamp"}:n==="ObjectColumnValidator"&&t.getProperties().length===0?{kind:"object",shape:{}}:$(t,!1,i,0)},Se=new Set(["AsyncGenerator","AsyncIterable","AsyncIterableIterator"]),Oe=(e,i)=>{const t=e.getProperty("handler")?.getTypeAtLocation(i).getCallSignatures()[0]?.getReturnType();if(t===void 0)return[];if(Se.has((t.getSymbol()??t.getAliasSymbol())?.getName()??"")){const[n]=t.getTypeArguments();return n===void 0?[]:[n]}return(t.isUnion()?t.getUnionTypes():[t]).map(n=>n.getSymbol()?.getName()==="Promise"?n.getTypeArguments()[0]??n:n)},we=(e,i)=>{const t=[...new Set(e.map(n=>Y(n,i)))];return t.length===0||t.includes("unknown")?"unknown":t.join(" | ")},Ie=(e,i,t,n)=>{const o=e.getType(),r=U(o,e);if(r===void 0)return;const a={...n?{description:n}:{},exportName:i,filePath:t,kind:r};if(o.getProperty("channel")?.isOptional()===!1)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a room from a published package; its name is not in the declared type, so codegen cannot route it. Declare the room with \`defineRoom\` in this file instead.`);const c=N(o,"lifecycle",e),l=o.getProperty("lifecycle");if(c===void 0&&l!==void 0&&!l.isOptional())throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a lifecycle hook from a published package whose type does not say which moment it runs at. Declare it with its moment, e.g. \`RegisteredLifecycleHook & { readonly lifecycle: "disconnect" }\` (what \`onDisconnect\` returns).`);if(c!==void 0){if(!Ne.has(c))throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a "${c}" lifecycle hook from a published package; only a locally declared hook can carry its route. Declare it in this file instead.`);return{...a,args:{},lifecycle:c,returnType:"void",visibility:"internal"}}const d=N(o,"visibility",e);if(d!=="internal"&&d!=="public")throw new g("PUBLISHED_FUNCTION_VISIBILITY_UNKNOWN",`${t}:${i} re-exports a function from a published package whose type does not say whether it is internal or public. Declare it in that package as \`RegisteredQuery\` / \`RegisteredMutation\` / \`RegisteredAction\` (public) or their \`RegisteredInternal*\` counterparts, not the bare \`RegisteredFunction\`, so codegen does not list an internal function in the client \`api\`.`);if(d==="internal"&&o.getProperty("visibility")?.isOptional()!==!1)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports an internal function from a published package whose type makes \`visibility\` optional, so the value may not carry it. Declare it with a \`RegisteredInternal*\` type, which requires \`visibility: "internal"\`.`);const u=o.getProperty("args")?.getTypeAtLocation(e);if(u===void 0||u.isAny()||u.isUnknown()||u.getStringIndexType()!==void 0||u.getNumberIndexType()!==void 0)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a function from a published package whose type does not list its arguments. Declare its validator map with one key per argument (an empty \`{}\` for none) so codegen can type the client call.`);const m=Object.fromEntries(u.getProperties().map(p=>[p.getName(),xe(p.getTypeAtLocation(e),e)]));return{...a,args:m,...r==="query"?{readsIp:!0}:{},returnType:we(Oe(o,e),e),typeDerivedArgs:!0,visibility:d}},ke=8,A=(e,i=0)=>{if(i>ke)return;if(s.isCallExpression(e))return{call:e};if(s.isParenthesizedExpression(e)||s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isNonNullExpression(e))return A(e.getExpression(),i+1);if(!s.isIdentifier(e)&&!s.isPropertyAccessExpression(e))return;const t=e.getSymbol()?.getValueDeclaration();return t?T(t,i+1):void 0},T=(e,i)=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e)){const t=e.getInitializer();return t?A(t,i):{deadEnd:e}}if(s.isShorthandPropertyAssignment(e)){const t=e.getValueSymbol()?.getValueDeclaration();return t?T(t,i+1):void 0}if(s.isBindingElement(e)){const t=H(e),r=e.getFirstAncestorByKind(B.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return r?T(r,i+1):void 0}return{deadEnd:e}},x=e=>{const i=A(e);return i!==void 0&&"call"in i?i.call:void 0},_=e=>{const i=A(e);return i!==void 0&&"deadEnd"in i&&i.deadEnd.getSourceFile().isDeclarationFile()},_e=(e,i=()=>!0)=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t)){const r=[];for(const a of t.getElements().filter(c=>i(c.getName()))){const c=x(a.getNameNode());c&&r.push([a.getName(),c])}return r}if(!i(e.getName()))return[];const n=e.getInitializer(),o=n&&(s.isCallExpression(n)?n:x(n));return o?[[e.getName(),o]]:[]},Re=(e,i)=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t))return t.getElements().filter(o=>i(o.getName())&&_(o.getNameNode())).map(o=>[o.getName(),o.getNameNode()]);const n=e.getInitializer();return i(e.getName())&&n!==void 0&&_(n)?[[e.getName(),t]]:[]},De=e=>{const i=e.getArguments()[0],t=s.isObjectLiteralExpression(i)?i.getProperty("name"):void 0,n=s.isPropertyAssignment(t)?t.getInitializer():void 0;if(!n||!s.isStringLiteral(n))throw new g("ROOM_NAME_NOT_LITERAL",'defineRoom needs a string-literal `name` (e.g. `defineRoom({ name: "chat", … })`) so codegen can type its reference.');return n.getLiteralValue()},Ce=e=>e.startsWith("/")&&new URL(e,"https://lunora.invalid").pathname===e&&e!=="/_lunora"&&!e.startsWith("/_lunora/"),Ue=e=>{const i=e.getArguments()[0];if(!s.isObjectLiteralExpression(i))throw new g("SOCKET_PATH_NOT_LITERAL","defineWebSocket needs an object-literal options argument so codegen can read its `path` and `auth`.");const t=i.getProperty("path"),n=s.isPropertyAssignment(t)?t.getInitializer():void 0;if(!n||!s.isStringLiteral(n))throw new g("SOCKET_PATH_NOT_LITERAL",'defineWebSocket needs a string-literal `path` (e.g. `defineWebSocket({ path: "/chat", … })`) so codegen can route its upgrade.');const o=n.getLiteralValue();if(!Ce(o))throw new g("SOCKET_PATH_INVALID",`defineWebSocket path "${o}" must be a plain URL path starting with "/" (no "?", "#", ".." or unencoded characters) and not under "/_lunora".`);if(i.getProperties().some(l=>s.isSpreadAssignment(l)||s.isPropertyAssignment(l)&&s.isComputedPropertyName(l.getNameNode())))throw new g("SOCKET_AUTH_NOT_LITERAL","defineWebSocket cannot spread its options or use a computed key: codegen must read `auth` as a literal `auth: true` or `auth: false`.");const a=i.getProperty("auth");if(a===void 0)return{auth:!1,path:o};const c=s.isPropertyAssignment(a)?a.getInitializer():void 0;if(c===void 0||!(s.isTrueLiteral(c)||s.isFalseLiteral(c)))throw new g("SOCKET_AUTH_NOT_LITERAL","defineWebSocket needs a literal `auth: true` or `auth: false`, so codegen can read whether the route requires a session. A shorthand or a variable is not read.");return{auth:s.isTrueLiteral(c),path:o}},Fe=(e,i,t,n)=>{const o=n?ye(i):void 0,r=n?o?.expose:ue(i),a=n?o?.x402:de(i),c=w(()=>ae(i)),l=w(()=>oe(e)),d=z({kind:t.kind,output:c.value});return G(d?c.erased:l.erased),{args:se(i),...r?{expose:r}:{},...a?{x402:a}:{},...o?.meta===void 0?{}:{meta:o.meta},...t.adminOnly?{adminOnly:!0}:{},kind:t.kind,...c.value?{output:c.value}:{},returnType:l.value,visibility:o?.visibility==="internal"||t.visibility==="internal"?"internal":"public"}},$e=(e,i)=>{const t=Q(e,i);if(!t)return;if(t.channel)return{args:{},channel:{kind:t.channel,name:De(e)},kind:t.kind,returnType:"void",visibility:t.visibility};const{receiver:n}=t;return n?Fe(e,n,t,i):t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",...t.lifecycle==="socket"?{socket:{...Ue(e),origin:`${e.getSourceFile().getFilePath()}@${String(e.getStart())}`}}:{},visibility:t.visibility}:{args:ge(e),kind:t.kind,returnType:re(e),visibility:t.visibility}},V=e=>{const i=e?.getJsDocs().at(-1)?.getDescription().trim();return i===""?void 0:i},Ve=e=>V(e.getFirstAncestor(i=>s.isVariableStatement(i))),je=e=>{const i=new Map;for(const t of e.getVariableStatements())if(t.isExported())for(const n of t.getDeclarations())i.has(n.getName())||i.set(n.getName(),t);return t=>V(i.get(t))},j=(e,i,t,n,o)=>{const r=$e(e,n);if(!r)return;const a=o??Ve(e);return{args:r.args,...a?{description:a}:{},exportName:i,filePath:t,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},...r.meta===void 0?{}:{meta:r.meta},visibility:r.visibility,...r.adminOnly?{adminOnly:!0}:{},...r.kind==="query"&&(ne(e)===void 0||J(e))?{readsIp:!0}:{},...r.expose?{expose:r.expose}:{},...r.x402?{x402:r.x402}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{},...r.channel?{channel:r.channel}:{},...r.socket?{socket:r.socket}:{}}},Be=(e,i,t)=>{const n=[];for(const o of e.getExportAssignments()){if(o.isExportEquals())continue;const r=x(o.getExpression()),a=r?j(r,"default",i,t):void 0;r&&a&&n.push({call:r,entry:a})}return n},ze=(e,i,t)=>{const n=K(e),o=je(e),r=new Map,a=(d,u)=>{if(d?.channel?.kind!=="room")return;const m=r.get(d.channel.name);if(m!==void 0&&m!==u)throw new g("DUPLICATE_ROOM_NAME",`Duplicate room name "${d.channel.name}" in ${i}: two defineRoom calls share it. Room names must be unique.`);r.set(d.channel.name,u)},c=e.getVariableStatements().flatMap(d=>d.getDeclarations()).flatMap(d=>_e(d,u=>n.has(u))).flatMap(([d,u])=>(n.get(d)??[]).filter(m=>O(m)).flatMap(m=>{const p=j(u,m,i,t,o(m));return a(p,u),p?[p]:[]})),l=new Set(c.map(d=>d.exportName));for(const d of e.getVariableStatements().flatMap(u=>u.getDeclarations()))for(const[u,m]of Re(d,p=>n.has(p)))for(const p of(n.get(u)??[]).filter(v=>O(v)&&!l.has(v))){const v=Ie(m,p,i,o(p));v&&(c.push(v),l.add(p))}for(const{call:d,entry:u}of Be(e,i,t))l.has(u.exportName)||(a(u,d),c.push(u));return c},He=e=>{const i=new Map;for(const t of e){if(t.channel?.kind!=="room")continue;const n=i.get(t.channel.name);if(n!==void 0&&n.file!==t.filePath)throw new g("DUPLICATE_ROOM_NAME",`Duplicate room name "${t.channel.name}": defined in ${n.origin} and ${t.filePath}:${t.exportName}. Room names must be unique across the project.`);n===void 0&&i.set(t.channel.name,{file:t.filePath,origin:`${t.filePath}:${t.exportName}`})}},Me=e=>{const i=new Map;for(const t of e){const n=ie(t.filePath),o=i.get(n);if(o&&o!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${o}" and "${t.filePath}" both resolve to "${n}". 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:[o,t.filePath],status:500});i.set(n,t.filePath)}},nt=(e,i,t={})=>{const n=M(i),o=[];for(const r of n){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=W(i,r);o.push(...ze(a,c,t.lazyFunctions===!0))}return o.sort((r,a)=>`${r.filePath}:${r.exportName}`.localeCompare(`${a.filePath}:${a.exportName}`)),Me(o),He(o),o};export{nt as d,I as i,ne as p,it as w};
1
+ import{LunoraError as g}from"@lunora/errors";import{Node as s,SyntaxKind as B}from"ts-morph";import{d as z}from"./declared-output-Iaar469J.mjs";import{findObjectProperty as h,bindingKeyName as H,listLunoraSourceFiles as M,lunoraRelativePath as W}from"./isTestPath-Uwb5a6Kq.mjs";import{e as K,i as O}from"./attribution-Cwt30DDJ.mjs";import{u as R,p as q,r as Y,c as w,a as G}from"./unwrap-handler-return-DvbyiLjc.mjs";import{m as J}from"./ip-reads-D2qhKEb6.mjs";import{b as L,s as X,c as Q}from"./classify-procedure-call-BmEirzc_.mjs";import{r as D,p as C,a as Z}from"./parse-validator-BisfC8bR.mjs";import{N as ee,l as te}from"./project-config-file-DR7xrrNB.mjs";import{s as ie}from"./dispatch-namespace-DwTjD7BU.mjs";const I=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,ne=e=>{const i=e.getArguments()[0],t=I(i);if(t!==void 0)return t;if(i===void 0||!s.isObjectLiteralExpression(i))return;const n=h(i,"handler");return n!==void 0&&s.isPropertyAssignment(n)?I(n.getInitializer()):void 0},re=e=>{const i=e.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return"unknown";const t=h(i,"handler");if(!t||!s.isPropertyAssignment(t))return"unknown";const n=t.getInitializer();return!n||!(s.isArrowFunction(n)||s.isFunctionExpression(n))?"unknown":R(n)},oe=e=>{const i=e.getArguments()[0];return!i||!(s.isArrowFunction(i)||s.isFunctionExpression(i))?"unknown":R(i)},se=e=>{let i={};for(const t of L(e)){if(t.name!=="input")continue;const n=t.call.getArguments()[0],o=n!==void 0&&s.isExpression(n)?D(n):void 0;o!==void 0&&(i={...C(o),...i})}return i},ae=e=>{const i=L(e).find(n=>n.name==="output");if(!i)return;const t=i.call.getArguments()[0];return t&&s.isExpression(t)?q(i.call,()=>Z(t)):void 0},E=(e,i)=>{const t=h(e,i);if(t===void 0||!s.isPropertyAssignment(t))return;const n=t.getInitializer();return n!==void 0&&s.isStringLiteral(n)?n.getLiteralValue():void 0},k=(e,i)=>{const t=h(e,i);if(t===void 0||!s.isPropertyAssignment(t))return;const n=t.getInitializer();return n!==void 0&&s.isNumericLiteral(n)?n.getLiteralValue():void 0},ce=e=>{const i=h(e,"cache");if(i===void 0||!s.isPropertyAssignment(i))return;const t=i.getInitializer();if(t===void 0||!s.isObjectLiteralExpression(t))return;const n=E(t,"scope"),o=k(t,"maxAge"),r=k(t,"staleWhileRevalidate"),a=E(t,"tag"),c=E(t,"vary"),l={...o===void 0?{}:{maxAge:o},...n==="private"||n==="public"?{scope:n}:{},...r===void 0?{}:{staleWhileRevalidate:r},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},le=e=>{if(e===void 0||!s.isObjectLiteralExpression(e))return{};const i=ce(e),t=h(e,"rest");return t!==void 0&&s.isPropertyAssignment(t)?{...i===void 0?{}:{cache:i},rest:t.getInitializer()?.getText()==="true"}:i===void 0?{}:{cache:i}},ue=e=>{const i=L(e).find(t=>t.name==="expose");return i?le(i.call.getArguments()[0]):void 0},de=e=>{const i=L(e).find(r=>r.name==="x402");if(!i)return;const t=i.call.getArguments()[0];if(t===void 0||!s.isObjectLiteralExpression(t))return{};const n=h(t,"price");if(n===void 0||!s.isPropertyAssignment(n))return{};const o=n.getInitializer();return o===void 0?{}:s.isStringLiteral(o)?{price:o.getLiteralValue()}:s.isNumericLiteral(o)?{price:o.getLiteralValue()}:{}},ge=e=>{const i=e.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return{};const t=h(i,"args");if(!t||!s.isPropertyAssignment(t))return{};const n=t.getInitializer(),o=n===void 0?void 0:D(n);return o===void 0?{}:C(o)},f=(e,i)=>{throw new g("INTERNAL",`@lunora/codegen: lazy function registry needs literal ${i} in ${e.getSourceFile().getFilePath()}:${String(e.getStartLineNumber())}`)},S=(e,i,t)=>{if(!e||!s.isObjectLiteralExpression(e))return f(i,"metadata objects");const n=new Set;for(const o of e.getProperties()){if(!s.isPropertyAssignment(o))return f(o,"metadata fields without spreads, getters, or shorthand");const r=o.getNameNode(),a=s.isStringLiteral(r)?r.getLiteralValue():r.getText();if(!s.isIdentifier(r)&&!s.isStringLiteral(r)||!t.includes(a)||n.has(a))return f(o,"supported, unique metadata fields");n.add(a)}return e},y=(e,i)=>{const t=e.getProperty(i);return t&&s.isPropertyAssignment(t)?t.getInitializer():void 0},pe=e=>{const i=S(e,e,["credentialHeaders","maxAge","scope","staleWhileRevalidate","tag","vary"]),t={};for(const r of["maxAge","staleWhileRevalidate"]){const a=y(i,r);if(!(a===void 0&&r!=="maxAge")){if(!a||!s.isNumericLiteral(a))return f(e,`cache.${r}`);t[r]=a.getLiteralValue()}}const n=y(i,"scope");if(!n||!s.isStringLiteral(n)||!["private","public"].includes(n.getLiteralValue()))return f(e,"cache.scope");t.scope=n.getLiteralValue();for(const r of["tag","vary"]){const a=y(i,r);if(a!==void 0){if(!s.isStringLiteral(a))return f(a,`cache.${r}`);t[r]=a.getLiteralValue()}}const o=y(i,"credentialHeaders");if(o!==void 0){if(!s.isArrayLiteralExpression(o))return f(o,"cache.credentialHeaders");t.credentialHeaders=o.getElements().map(r=>s.isStringLiteral(r)?r.getLiteralValue():f(r,"cache.credentialHeaders string entries"))}return t},fe=e=>{const i=S(e.getArguments()[0],e,["rest","cache"]),t=y(i,"rest"),n=y(i,"cache");return t!==void 0&&!s.isTrueLiteral(t)&&!s.isFalseLiteral(t)?f(t,".expose({ rest })"):{...t?{rest:s.isTrueLiteral(t)}:{},...n?{cache:pe(n)}:{}}},me=e=>{const i=S(e.getArguments()[0],e,["price"]),t=y(i,"price");return!t||!s.isStringLiteral(t)&&!s.isNumericLiteral(t)?f(e,"`.x402({ price })` value"):{price:t.getLiteralValue()}},he=e=>{const i=e.map(o=>{const r=o.getArguments()[0];return r===void 0?ee:te(r)}),t=i.every(o=>o!==null&&typeof o=="object"&&!Array.isArray(o)),n=i.reduce((o,r)=>({...r,...o}),{});return t?n:"unloaded"},ye=e=>{const{factory:i,steps:t}=X(e);if(!i)return f(e,"metadata from a resolvable Lunora factory root");const n={visibility:i.startsWith("internal")?"internal":"public"};for(const{call:r,name:a}of t){if(!["expose","input","meta","output","use","x402"].includes(a))return f(r,`known builder modifiers, got .${a}()`);a==="expose"&&n.expose===void 0&&(n.expose=fe(r)),a==="x402"&&n.x402===void 0&&(n.x402=me(r))}const o=t.filter(r=>r.name==="meta").map(r=>r.call);return o.length===0?n:{...n,meta:he(o)}},ve=new Set(["action","mutation","query","stream"]),N=(e,i,t)=>{const n=e.getProperty(i)?.getTypeAtLocation(t);if(n===void 0)return;const o=n.isUnion()?n.getUnionTypes().filter(a=>!a.isUndefined()):[n],r=o.length===1?o[0]?.getLiteralValue():void 0;return typeof r=="string"?r:void 0},U=(e,i)=>{const t=N(e,"kind",i);return t!==void 0&&ve.has(t)&&e.getProperty("handler")!==void 0?t:void 0},be=e=>{const i=e.getParent();if(s.isPropertyAccessExpression(i)&&i.getExpression()===e)return i.getName()==="functions";if(s.isElementAccessExpression(i)&&i.getExpression()===e){const n=i.getArgumentExpression();return n!==void 0&&s.isStringLiteral(n)&&n.getLiteralValue()==="functions"}const t=s.isVariableDeclaration(i)&&i.getNameNode()!==e?i.getNameNode():void 0;return t!==void 0&&s.isObjectBindingPattern(t)&&t.getElements().some(n=>(n.getPropertyNameNode()?.getText()??n.getName())==="functions")},it=(e,i)=>{for(const t of e)for(const n of t.getVariableDeclarations()){const o=n.getNameNode();if(!n.isExported()||!s.isIdentifier(o))continue;const a=(n.getType().getProperty("functions")?.getTypeAtLocation(n)?.getProperties()??[]).filter(u=>U(u.getTypeAtLocation(n),n)!==void 0);if(a.length===0||o.findReferencesAsNodes().some(u=>be(u)))continue;const l=n.getName(),d=a.map(u=>u.getName()).join(", ");console.warn(`@lunora/codegen: ${i(t)}:${l} ships functions (${d}) that nothing re-exports, so none is in the generated api. Add \`export const { ${d} } = ${l}.functions;\` (or export your own wrappers of them).`)}},Ne=new Set(["connect","disconnect","init","reactor","whisper"]),Le={ArrayBuffer:"bytes",GeoPoint:"geoPoint"},Ae=8,P=(e,i)=>{const t=e.getText(i);return t===""?{kind:"from"}:{kind:"from",tsType:t}},Ee=new Set(["false","true"]),Pe=[[e=>e.isAny()||e.isUnknown(),"any"],[e=>e.isString(),"string"],[e=>e.isNumber(),"number"],[e=>e.isBoolean(),"boolean"],[e=>e.isNull(),"null"],[e=>e.isBigInt(),"bigint"]],Te=(e,i,t)=>{if(!e.isObject()||e.isIntersection()||e.getCallSignatures().length>0||e.isClass())return;const n=e.getProperties();if(n.some(r=>r.getTypeAtLocation(i).getCallSignatures().length>0))return;const o=e.getStringIndexType();if(o!==void 0&&n.length===0)return{keyType:{kind:"string"},kind:"record",valueType:b(o,i,t+1)};if(!(o!==void 0||n.length===0))return{kind:"object",shape:Object.fromEntries(n.map(r=>[r.getName(),$(r.getTypeAtLocation(i),r.isOptional(),i,t+1)]))}},b=(e,i,t)=>{if(t>Ae)return P(e,i);const n=Pe.find(([a])=>a(e));if(n!==void 0)return{kind:n[1]};const o=Le[(e.getSymbol()??e.getAliasSymbol())?.getName()??""];if(o!==void 0)return{kind:o};if(e.isStringLiteral()||e.isNumberLiteral()||e.isBooleanLiteral()||e.isBigIntLiteral())return{kind:"literal",literalValue:e.getText(i),sensitive:!0};const r=e.isIntersection()?N(e,"__table",i):void 0;if(r!==void 0)return{kind:"id",tableName:r};if(e.isUnion())return F(e.getUnionTypes(),i,t);if(e.isArray()){const a=e.getArrayElementType();return a===void 0?P(e,i):{inner:b(a,i,t+1),kind:"array"}}return Te(e,i,t)??P(e,i)},F=(e,i,t)=>{const o=new Set(e.filter(l=>l.isBooleanLiteral()).map(l=>l.getText(i))).size===Ee.size,r=e.filter(l=>!(o&&l.isBooleanLiteral())).map(l=>b(l,i,t+1)),a=o?[...r,{kind:"boolean"}]:r,[c]=a;return a.length===1&&c!==void 0?c:{kind:"union",members:a}},$=(e,i,t,n)=>{const o=e.isUnion()?e.getUnionTypes():[e],r=o.filter(l=>!l.isUndefined());if(!i&&r.length===o.length)return b(e,t,n);if(r.length===0)return{inner:{kind:"any"},kind:"optional"};const[a]=r;return{inner:r.length===1&&a!==void 0?b(a,t,n):F(r,t,n),kind:"optional"}},xe=(e,i)=>{const t=e.getProperty("__type")?.getTypeAtLocation(i);if(t===void 0)return{kind:"from"};const n=(e.getSymbol()??e.getAliasSymbol())?.getName();return n==="TimestampColumnValidator"?{kind:"timestamp"}:n==="ObjectColumnValidator"&&t.getProperties().length===0?{kind:"object",shape:{}}:$(t,!1,i,0)},Se=new Set(["AsyncGenerator","AsyncIterable","AsyncIterableIterator"]),Oe=(e,i)=>{const t=e.getProperty("handler")?.getTypeAtLocation(i).getCallSignatures()[0]?.getReturnType();if(t===void 0)return[];if(Se.has((t.getSymbol()??t.getAliasSymbol())?.getName()??"")){const[n]=t.getTypeArguments();return n===void 0?[]:[n]}return(t.isUnion()?t.getUnionTypes():[t]).map(n=>n.getSymbol()?.getName()==="Promise"?n.getTypeArguments()[0]??n:n)},we=(e,i)=>{const t=[...new Set(e.map(n=>Y(n,i)))];return t.length===0||t.includes("unknown")?"unknown":t.join(" | ")},Ie=(e,i,t,n)=>{const o=e.getType(),r=U(o,e);if(r===void 0)return;const a={...n?{description:n}:{},exportName:i,filePath:t,kind:r};if(o.getProperty("channel")?.isOptional()===!1)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a room from a published package; its name is not in the declared type, so codegen cannot route it. Declare the room with \`defineRoom\` in this file instead.`);const c=N(o,"lifecycle",e),l=o.getProperty("lifecycle");if(c===void 0&&l!==void 0&&!l.isOptional())throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a lifecycle hook from a published package whose type does not say which moment it runs at. Declare it with its moment, e.g. \`RegisteredLifecycleHook & { readonly lifecycle: "disconnect" }\` (what \`onDisconnect\` returns).`);if(c!==void 0){if(!Ne.has(c))throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a "${c}" lifecycle hook from a published package; only a locally declared hook can carry its route. Declare it in this file instead.`);return{...a,args:{},lifecycle:c,returnType:"void",visibility:"internal"}}const d=N(o,"visibility",e);if(d!=="internal"&&d!=="public")throw new g("PUBLISHED_FUNCTION_VISIBILITY_UNKNOWN",`${t}:${i} re-exports a function from a published package whose type does not say whether it is internal or public. Declare it in that package as \`RegisteredQuery\` / \`RegisteredMutation\` / \`RegisteredAction\` (public) or their \`RegisteredInternal*\` counterparts, not the bare \`RegisteredFunction\`, so codegen does not list an internal function in the client \`api\`.`);if(d==="internal"&&o.getProperty("visibility")?.isOptional()!==!1)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports an internal function from a published package whose type makes \`visibility\` optional, so the value may not carry it. Declare it with a \`RegisteredInternal*\` type, which requires \`visibility: "internal"\`.`);const u=o.getProperty("args")?.getTypeAtLocation(e);if(u===void 0||u.isAny()||u.isUnknown()||u.getStringIndexType()!==void 0||u.getNumberIndexType()!==void 0)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a function from a published package whose type does not list its arguments. Declare its validator map with one key per argument (an empty \`{}\` for none) so codegen can type the client call.`);const m=Object.fromEntries(u.getProperties().map(p=>[p.getName(),xe(p.getTypeAtLocation(e),e)]));return{...a,args:m,...r==="query"?{readsIp:!0}:{},returnType:we(Oe(o,e),e),typeDerivedArgs:!0,visibility:d}},ke=8,A=(e,i=0)=>{if(i>ke)return;if(s.isCallExpression(e))return{call:e};if(s.isParenthesizedExpression(e)||s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isNonNullExpression(e))return A(e.getExpression(),i+1);if(!s.isIdentifier(e)&&!s.isPropertyAccessExpression(e))return;const t=e.getSymbol()?.getValueDeclaration();return t?T(t,i+1):void 0},T=(e,i)=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e)){const t=e.getInitializer();return t?A(t,i):{deadEnd:e}}if(s.isShorthandPropertyAssignment(e)){const t=e.getValueSymbol()?.getValueDeclaration();return t?T(t,i+1):void 0}if(s.isBindingElement(e)){const t=H(e),r=e.getFirstAncestorByKind(B.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return r?T(r,i+1):void 0}return{deadEnd:e}},x=e=>{const i=A(e);return i!==void 0&&"call"in i?i.call:void 0},_=e=>{const i=A(e);return i!==void 0&&"deadEnd"in i&&i.deadEnd.getSourceFile().isDeclarationFile()},_e=(e,i=()=>!0)=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t)){const r=[];for(const a of t.getElements().filter(c=>i(c.getName()))){const c=x(a.getNameNode());c&&r.push([a.getName(),c])}return r}if(!i(e.getName()))return[];const n=e.getInitializer(),o=n&&(s.isCallExpression(n)?n:x(n));return o?[[e.getName(),o]]:[]},Re=(e,i)=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t))return t.getElements().filter(o=>i(o.getName())&&_(o.getNameNode())).map(o=>[o.getName(),o.getNameNode()]);const n=e.getInitializer();return i(e.getName())&&n!==void 0&&_(n)?[[e.getName(),t]]:[]},De=e=>{const i=e.getArguments()[0],t=s.isObjectLiteralExpression(i)?i.getProperty("name"):void 0,n=s.isPropertyAssignment(t)?t.getInitializer():void 0;if(!n||!s.isStringLiteral(n))throw new g("ROOM_NAME_NOT_LITERAL",'defineRoom needs a string-literal `name` (e.g. `defineRoom({ name: "chat", … })`) so codegen can type its reference.');return n.getLiteralValue()},Ce=e=>e.startsWith("/")&&new URL(e,"https://lunora.invalid").pathname===e&&e!=="/_lunora"&&!e.startsWith("/_lunora/"),Ue=e=>{const i=e.getArguments()[0];if(!s.isObjectLiteralExpression(i))throw new g("SOCKET_PATH_NOT_LITERAL","defineWebSocket needs an object-literal options argument so codegen can read its `path` and `auth`.");const t=i.getProperty("path"),n=s.isPropertyAssignment(t)?t.getInitializer():void 0;if(!n||!s.isStringLiteral(n))throw new g("SOCKET_PATH_NOT_LITERAL",'defineWebSocket needs a string-literal `path` (e.g. `defineWebSocket({ path: "/chat", … })`) so codegen can route its upgrade.');const o=n.getLiteralValue();if(!Ce(o))throw new g("SOCKET_PATH_INVALID",`defineWebSocket path "${o}" must be a plain URL path starting with "/" (no "?", "#", ".." or unencoded characters) and not under "/_lunora".`);if(i.getProperties().some(l=>s.isSpreadAssignment(l)||s.isPropertyAssignment(l)&&s.isComputedPropertyName(l.getNameNode())))throw new g("SOCKET_AUTH_NOT_LITERAL","defineWebSocket cannot spread its options or use a computed key: codegen must read `auth` as a literal `auth: true` or `auth: false`.");const a=i.getProperty("auth");if(a===void 0)return{auth:!1,path:o};const c=s.isPropertyAssignment(a)?a.getInitializer():void 0;if(c===void 0||!(s.isTrueLiteral(c)||s.isFalseLiteral(c)))throw new g("SOCKET_AUTH_NOT_LITERAL","defineWebSocket needs a literal `auth: true` or `auth: false`, so codegen can read whether the route requires a session. A shorthand or a variable is not read.");return{auth:s.isTrueLiteral(c),path:o}},Fe=(e,i,t,n)=>{const o=n?ye(i):void 0,r=n?o?.expose:ue(i),a=n?o?.x402:de(i),c=w(()=>ae(i)),l=w(()=>oe(e)),d=z({kind:t.kind,output:c.value});return G(d?c.erased:l.erased),{args:se(i),...r?{expose:r}:{},...a?{x402:a}:{},...o?.meta===void 0?{}:{meta:o.meta},...t.adminOnly?{adminOnly:!0}:{},kind:t.kind,...c.value?{output:c.value}:{},returnType:l.value,visibility:o?.visibility==="internal"||t.visibility==="internal"?"internal":"public"}},$e=(e,i)=>{const t=Q(e,i);if(!t)return;if(t.channel)return{args:{},channel:{kind:t.channel,name:De(e)},kind:t.kind,returnType:"void",visibility:t.visibility};const{receiver:n}=t;return n?Fe(e,n,t,i):t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",...t.lifecycle==="socket"?{socket:{...Ue(e),origin:`${e.getSourceFile().getFilePath()}@${String(e.getStart())}`}}:{},visibility:t.visibility}:{args:ge(e),kind:t.kind,returnType:re(e),visibility:t.visibility}},V=e=>{const i=e?.getJsDocs().at(-1)?.getDescription().trim();return i===""?void 0:i},Ve=e=>V(e.getFirstAncestor(i=>s.isVariableStatement(i))),je=e=>{const i=new Map;for(const t of e.getVariableStatements())if(t.isExported())for(const n of t.getDeclarations())i.has(n.getName())||i.set(n.getName(),t);return t=>V(i.get(t))},j=(e,i,t,n,o)=>{const r=$e(e,n);if(!r)return;const a=o??Ve(e);return{args:r.args,...a?{description:a}:{},exportName:i,filePath:t,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},...r.meta===void 0?{}:{meta:r.meta},visibility:r.visibility,...r.adminOnly?{adminOnly:!0}:{},...r.kind==="query"&&(ne(e)===void 0||J(e))?{readsIp:!0}:{},...r.expose?{expose:r.expose}:{},...r.x402?{x402:r.x402}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{},...r.channel?{channel:r.channel}:{},...r.socket?{socket:r.socket}:{}}},Be=(e,i,t)=>{const n=[];for(const o of e.getExportAssignments()){if(o.isExportEquals())continue;const r=x(o.getExpression()),a=r?j(r,"default",i,t):void 0;r&&a&&n.push({call:r,entry:a})}return n},ze=(e,i,t)=>{const n=K(e),o=je(e),r=new Map,a=(d,u)=>{if(d?.channel?.kind!=="room")return;const m=r.get(d.channel.name);if(m!==void 0&&m!==u)throw new g("DUPLICATE_ROOM_NAME",`Duplicate room name "${d.channel.name}" in ${i}: two defineRoom calls share it. Room names must be unique.`);r.set(d.channel.name,u)},c=e.getVariableStatements().flatMap(d=>d.getDeclarations()).flatMap(d=>_e(d,u=>n.has(u))).flatMap(([d,u])=>(n.get(d)??[]).filter(m=>O(m)).flatMap(m=>{const p=j(u,m,i,t,o(m));return a(p,u),p?[p]:[]})),l=new Set(c.map(d=>d.exportName));for(const d of e.getVariableStatements().flatMap(u=>u.getDeclarations()))for(const[u,m]of Re(d,p=>n.has(p)))for(const p of(n.get(u)??[]).filter(v=>O(v)&&!l.has(v))){const v=Ie(m,p,i,o(p));v&&(c.push(v),l.add(p))}for(const{call:d,entry:u}of Be(e,i,t))l.has(u.exportName)||(a(u,d),c.push(u));return c},He=e=>{const i=new Map;for(const t of e){if(t.channel?.kind!=="room")continue;const n=i.get(t.channel.name);if(n!==void 0&&n.file!==t.filePath)throw new g("DUPLICATE_ROOM_NAME",`Duplicate room name "${t.channel.name}": defined in ${n.origin} and ${t.filePath}:${t.exportName}. Room names must be unique across the project.`);n===void 0&&i.set(t.channel.name,{file:t.filePath,origin:`${t.filePath}:${t.exportName}`})}},Me=e=>{const i=new Map;for(const t of e){const n=ie(t.filePath),o=i.get(n);if(o&&o!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${o}" and "${t.filePath}" both resolve to "${n}". 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:[o,t.filePath],status:500});i.set(n,t.filePath)}},nt=(e,i,t={})=>{const n=M(i),o=[];for(const r of n){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=W(i,r);o.push(...ze(a,c,t.lazyFunctions===!0))}return o.sort((r,a)=>`${r.filePath}:${r.exportName}`.localeCompare(`${a.filePath}:${a.exportName}`)),Me(o),He(o),o};export{nt as d,I as i,ne as p,it as w};
@@ -0,0 +1 @@
1
+ import{Node as s,SyntaxKind as u,VariableDeclarationKind as re}from"ts-morph";import{isConstDeclaration as F,unwrapExpression as d,descendantsOfKind as oe,bindingKeyName as ae}from"./isTestPath-Uwb5a6Kq.mjs";import{r as ce,b as V,d as N}from"./attribution-Cwt30DDJ.mjs";import{i as _,r as C,c as m,a as le}from"./context-root-BpDEhvNE.mjs";const de=e=>{const t=e.getText(),i=n=>{const r=n.getNameNode();return s.isIdentifier(r)&&r.getText()===t};for(const n of e.getAncestors())if(!(!s.isArrowFunction(n)&&!s.isFunctionExpression(n)&&!s.isFunctionDeclaration(n)))for(const r of n.getParameters()){const o=r.getDescendantsOfKind(u.BindingElement).find(a=>i(a));if(o!==void 0)return o}},ue=e=>{let t=e;for(;;){const i=t.getParent();if(!s.isObjectBindingPattern(i))return;const n=i.getParent();if(s.isBindingElement(n)){t=n;continue}return s.isParameterDeclaration(n)?ae(t):void 0}},ge=e=>{const t=e.getText();if(!e.getAncestors().some(o=>{const a=s.isFunctionLikeDeclaration(o)||s.isArrowFunction(o)?o.getParameters()[1]:void 0,c=a?.getNameNode();return a!==void 0&&(s.isIdentifier(c)?c.getText()===t:a.getDescendantsOfKind(u.BindingElement).some(l=>l.getName()===t))&&_(a)}))return!1;const n=N(e),r=s.isParameterDeclaration(n)?n:n?.getFirstAncestorByKind(u.Parameter);return r!==void 0&&(s.isParameterDeclaration(n)||s.isBindingElement(n))&&_(r)},q=(e,t)=>{const i=e.getParent();if(s.isPropertyAccessExpression(i)&&i.getNameNode()===e||s.isPropertyAssignment(i)&&i.getNameNode()===e)return!1;if(e.getText()===t)return!0;const n=de(e);return n!==void 0&&ue(n)===t?!0:t==="args"&&ge(e)},T=(e,t)=>s.isIdentifier(e)?q(e,t):e.getDescendantsOfKind(u.Identifier).some(i=>q(i,t)),fe=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=>{const t=s.isIdentifier(e)?N(e):void 0;return s.isVariableDeclaration(t)&&s.isIdentifier(t.getNameNode())&&!V(t)?t.getInitializer():void 0},me=(e,t)=>{const i=e.getParent();if(s.isVariableDeclarationList(i)&&i.getDeclarationKind()===re.Var)return t;const n=i.getParent();return s.isVariableStatement(n)?n.getParent():n},pe=(e,t)=>{const i=e.getNameNode();return s.isIdentifier(i)?i.getText()===t:i.getDescendantsOfKind(u.BindingElement).some(n=>{const r=n.getNameNode();return s.isIdentifier(r)&&r.getText()===t})},M=e=>e.getDescendantsOfKind(u.Identifier).filter(t=>{const i=t.getParent();return!(s.isPropertyAccessExpression(i)&&i.getNameNode()===t)&&!(s.isPropertyAssignment(i)&&i.getNameNode()===t)}),y=e=>s.isIdentifier(e)?[e]:M(e),b=e=>{let t=e;for(;;){const i=t.getParent();if(!((s.isPropertyAccessExpression(i)||s.isElementAccessExpression(i)||s.isNonNullExpression(i))&&i.getExpression()===t))return t;t=i}},Ee=e=>{const t=e.getParent();return s.isCallExpression(t)&&t.getExpression()===e?t:void 0},ve=new Set(["find","findFirst","findFirstOrThrow","findMany","findUnique","first","get","unique"]),Z=e=>{const t=e.getExpression();return s.isPropertyAccessExpression(t)&&ve.has(t.getName())&&m(t)?.[0]==="db"},D=(e,t)=>{for(let i=e,n=e.getParent();n!==void 0&&i!==t;i=n,n=n.getParent()){if(s.isConditionalExpression(n))return!0;if(s.isBinaryExpression(n)){const r=n.getOperatorToken().getKind();if(i===n.getRight()&&(r===u.QuestionQuestionToken||r===u.BarBarToken)||i===n.getLeft()&&r===u.AmpersandAmpersandToken)return!0}}return!1},J=e=>y(e).some(t=>{if(D(t,e))return!1;if(m(b(t))?.[0]==="auth")return!0;const i=f(t);return i!==void 0&&y(i).some(n=>m(b(n))?.[0]==="auth"&&!D(n,i))}),xe=e=>Z(e)&&e.getArguments().some(t=>J(t)),X=(e,t)=>{for(let i=e.getParent();i!==void 0;i=i.getParent()){if(s.isCallExpression(i)&&m(i.getExpression())?.[0]==="db")return!0;if(i===t)return!1}return!1},R=e=>y(e).some(t=>{const i=b(t),n=m(i)?.[0];if(n==="auth")return!D(t,e)&&!X(t,e);const r=n==="db"&&!D(t,e)?Ee(i):void 0;return r!==void 0&&xe(r)}),k=e=>s.isArrowFunction(e)||s.isFunctionExpression(e)||s.isFunctionDeclaration(e)||s.isMethodDeclaration(e),K=e=>{const t=e.getFirstAncestor(i=>k(i));return k(t)?t:void 0},Ae=e=>{const t=d(e);return s.isAwaitExpression(t)?d(t.getExpression()):t},P=e=>{const t=[];let i=d(e);for(;i!==void 0;)if(s.isPropertyAccessExpression(i))t.unshift(i.getName()),i=d(i.getExpression());else if(s.isElementAccessExpression(i)){const n=i.getArgumentExpression();if(!s.isStringLiteral(n))return;t.unshift(n.getLiteralValue()),i=d(i.getExpression())}else return s.isIdentifier(i)?{path:t,root:i}:void 0},p=(e,t)=>N(e)?.compilerNode===t.compilerNode,Y=e=>{if(!s.isIdentifier(e))return;const t=ce(e),i=t?.isAlias()===!0?t.getAliasedSymbol():t,n=i?.getValueDeclaration()??i?.getDeclarations()[0];if(n===void 0)return;const r=n.getSourceFile();if(r.isDeclarationFile()||r.isInNodeModules())return;if(s.isFunctionDeclaration(n))return n.getBody()===void 0||n.isGenerator()||V(n)?void 0:n;if(!F(n))return;const o=d(n.getInitializer());return s.isArrowFunction(o)||s.isFunctionExpression(o)&&!o.isGenerator()?o:void 0},Ne=e=>e>=u.FirstAssignment&&e<=u.LastAssignment,H=e=>{const t=[],i=[];let n=d(e);for(;n!==void 0;)if(s.isCallExpression(n))t.push(n),n=d(n.getExpression());else if(s.isPropertyAccessExpression(n))i.unshift(n.getName()),n=d(n.getExpression());else if(s.isElementAccessExpression(n)){const r=n.getArgumentExpression();if(!s.isStringLiteral(r))return;i.unshift(r.getLiteralValue()),n=d(n.getExpression())}else return s.isIdentifier(n)&&t.length>0&&i.length>0?{calls:t,names:i,root:n}:void 0},j=new Set(["findFirst","findUnique","first","get","unique"]),U=e=>{const t=e.names[e.names.length-1]??"";if(j.has(t))return{selfEnforcing:!1};const i=t.endsWith("OrThrow")?t.slice(0,-7):void 0;return i!==void 0&&j.has(i)?{selfEnforcing:!0}:void 0},Ie=e=>{const t=d(e),i=s.isIdentifier(t)?d(f(t))??t:t,n=P(i);if(n===void 0||n.path.length===0)return;const r=N(n.root);if(!F(r)||!s.isIdentifier(r.getNameNode()))return;const o=Ae(r.getInitializer()),a=s.isCallExpression(o)&&m(o.getExpression())?.[0]==="db"?H(o):void 0;return a!==void 0&&U(a)!==void 0?r:void 0},$=e=>e.calls.flatMap(t=>t.getArguments().flatMap(i=>[i,...i.getDescendants()])),he=(e,t)=>{const i=s.isIdentifier(e)?N(e):void 0;if(!s.isBindingElement(i)||i.getDotDotDotToken()!==void 0||i.getInitializer()!==void 0)return!1;const n=i.getParent(),r=s.isObjectBindingPattern(n)?n.getParent():void 0;if(!F(r))return!1;const o=P(r.getInitializer());return o?.path[0]==="auth"&&p(o.root,t)},De=(e,t)=>{const i=P(e);if(i!==void 0&&i.path.length>0)return i.path[0]==="auth"&&p(i.root,t);const n=P(f(e));return n?.path[0]==="auth"&&p(n.root,t)?!0:he(e,t)},ee=e=>{if(!s.isVariableStatement(e))return;const t=e.getDeclarations(),i=t.length===1?t[0]:void 0;return i!==void 0&&F(i)&&s.isIdentifier(i.getNameNode())?i:void 0},Pe=(e,t)=>{const i=d(e),n=a=>s.isIdentifier(a)&&p(a,t);if(s.isPrefixUnaryExpression(i))return i.getOperatorToken()===u.ExclamationToken&&n(d(i.getOperand()));if(!s.isBinaryExpression(i)||i.getOperatorToken().getKind()!==u.EqualsEqualsToken)return!1;const r=d(i.getLeft()),o=d(i.getRight());return n(r)&&s.isNullLiteral(o)||n(o)&&s.isNullLiteral(r)},ye=(e,t)=>{const i=s.isBlock(e)?e.getStatements():void 0,n=i===void 0?e:i[i.length-1];return s.isThrowStatement(n)||!t&&s.isReturnStatement(n)},te=(e,t,i)=>s.isIfStatement(e)&&e.getElseStatement()===void 0&&Pe(e.getExpression(),t)&&ye(e.getThenStatement(),i),Se=(e,t,i)=>{const n=e.getBody();if(!s.isBlock(n))return!1;const r=n.getStatements();return r.some((o,a)=>{const c=ee(o),l=d(c?.getInitializer()),g=s.isAwaitExpression(l)?H(l.getExpression()):void 0,x=g===void 0?void 0:U(g);if(c===void 0||g===void 0||x===void 0||g.names[0]!=="db"||!p(g.root,t))return!1;const E=$(g),I=E.some(v=>De(v,t)),S=i.some(v=>E.some(W=>s.isIdentifier(W)&&p(W,v)));if(!I||!S)return!1;const h=x.selfEnforcing?o:r.slice(a+1).find(v=>te(v,c,!0));return h!==void 0&&!e.getDescendantsOfKind(u.ReturnStatement).some(v=>K(v)?.compilerNode===e.compilerNode&&v.getStart()<h.getEnd())})},Oe=(e,t,i)=>{const n=Y(e.getExpression()),r=e.getArguments();if(n===void 0||r.some(E=>s.isSpreadElement(E)))return!1;const o=r.flatMap((E,I)=>m(E)?.length===0?[I]:[]),a=o.length===1?o[0]:void 0,c=a===void 0?void 0:n.getParameters()[a];if(a===void 0||c===void 0||c.isRestParameter()||!s.isIdentifier(c.getNameNode()))return!1;const l=[];r.forEach((E,I)=>{const S=P(d(E)),h=I===a||S===void 0||!p(S.root,t)?void 0:n.getParameters()[I];h!==void 0&&s.isIdentifier(h.getNameNode())&&l.push(h)});const g=n.getReturnType(),x=n.isAsync()||g.isAny()||g.isUnknown()||g.getText().includes("Promise");return l.length===0||!i&&x?!1:Se(n,c,l)},Te=(e,t)=>{const i=ee(e),n=d(i?.getInitializer()),r=s.isAwaitExpression(n)?H(n.getExpression()):void 0,o=r===void 0?void 0:U(r);if(i===void 0||r===void 0||o===void 0||r.names[0]!=="db"||m(r.root)?.length!==0)return;const a=r.calls.some(l=>l.getArguments().some(g=>J(g))),c=$(r).some(l=>s.isIdentifier(l)&&p(l,t));return a&&c?{declaration:i,selfEnforcing:o.selfEnforcing}:void 0},be=(e,t,i)=>{const n=(r,o)=>o.getStart()<=r.getStart()&&r.getEnd()<=o.getEnd();for(let r=e.getParent();r!==void 0&&r.compilerNode!==t.compilerNode;r=r.getParent()){if(k(r)||s.isIfStatement(r)||s.isIterationStatement(r)||s.isCaseClause(r)||s.isDefaultClause(r)||s.isCatchClause(r))return!1;if(s.isTryStatement(r)&&r.getCatchClause()!==void 0){const o=r.getTryBlock();if(!n(e,o)||!n(i,o))return!1}}return!0},Be=(e,t,i,n,r)=>e.slice(0,t).some((o,a)=>{if(!be(o,n,r))return!1;if(s.isExpressionStatement(o)){const l=d(o.getExpression()),g=s.isAwaitExpression(l),x=g?d(l.getExpression()):l;if(s.isCallExpression(x)&&Oe(x,i,g))return!0}const c=Te(o,i);return c!==void 0&&(c.selfEnforcing||a+1<t&&te(e[a+1],c.declaration,!1))}),G=e=>{let t=d(e)??e;for(;s.isAwaitExpression(t);)t=d(t.getExpression())??t.getExpression();return t},O=e=>{const t=G(e);return s.isCallExpression(t)||s.isNewExpression(t)},we=e=>{const t=G(e);return s.isCallExpression(t)&&m(t.getExpression())?.[0]==="db"},ie=e=>{const t=G(e);return s.isCallExpression(t)&&Z(t)},ne=e=>T(e,"args")||y(e).some(t=>{const i=f(t);return i!==void 0&&T(i,"args")}),B=(e,t)=>{const i=e?.getNameNode().getDescendantsOfKind(u.BindingElement).find(n=>s.isIdentifier(n.getNameNode())&&n.getNameNode().getText()===t);return i===void 0?[]:[i,...i.getAncestors().filter(n=>s.isBindingElement(n))].map(n=>s.isBindingElement(n)?n.getInitializer():void 0).filter(n=>n!==void 0)},Q=e=>{const t=s.isIdentifier(e)?N(e):void 0;if(!s.isBindingElement(t)||V(t))return;const i=t.getFirstAncestorByKind(u.VariableDeclaration),n=i?.getInitializer();if(!B(i,e.getText()).some(r=>ne(r)))return n!==void 0&&ie(n)?n:void 0},A=e=>T(e,"args"),w=e=>{if(!s.isIdentifier(e))return;const t=e.getText(),i=e.getFirstAncestor(a=>s.isArrowFunction(a)||s.isFunctionExpression(a)||s.isFunctionDeclaration(a));if(i===void 0)return;const n=e.getStart();let r,o=-1;for(const a of oe(i,u.VariableDeclaration)){if(!pe(a,t))continue;const c=me(a,i);if(c===void 0||n<c.getStart()||n>=c.getEnd())continue;const l=a.getInitializer(),g=a.getStart();l!==void 0&&g<n&&g>o&&(r=a,o=g)}return r},L=e=>w(e)?.getInitializer(),je=e=>{if(A(e))return!0;const t=i=>{const n=w(i),r=n?.getInitializer();return r!==void 0&&A(r)||B(n,i.getText()).some(o=>A(o))};return t(e)||M(e).some(i=>t(i))},Qe=e=>{if(O(e))return!1;if(B(w(e),e.getText()).some(n=>A(n)&&!O(n)))return!0;const t=L(e);if(t!==void 0&&O(t)&&!(ie(t)&&A(t)))return!1;const i=t??e;return A(i)?!0:M(i).some(n=>{if(n.getFirstAncestor(c=>c===i||s.isCallExpression(c)||s.isNewExpression(c))!==i)return!1;const o=w(n),a=c=>c!==void 0&&A(c)&&(!O(c)||we(c));return a(o?.getInitializer())||B(o,n.getText()).some(c=>a(c))})},Ze=e=>{if(C(e))return!0;const t=f(e);if(t!==void 0&&C(t))return!0;const i=t??e;return(s.isIdentifier(i)?[i]:i.getDescendantsOfKind(u.Identifier)).some(r=>{const o=f(r);return o!==void 0&&C(o)})},Je=e=>{const t=f(e)??e;if(y(t).some(o=>D(o,t)&&ne(b(o))))return!1;if(R(e))return!0;const i=f(e)??Q(e);if(i!==void 0&&R(i))return!0;const n=i??e;return(s.isIdentifier(n)?[n]:n.getDescendantsOfKind(u.Identifier)).some(o=>{if(D(o,n)||X(o,n))return!1;const a=f(o)??Q(o);return a!==void 0&&R(a)})},z=(e,t)=>T(e,t),Xe=(e,t)=>{if(z(e,t))return!0;const i=L(e);if(i!==void 0&&z(i,t))return!0;const n=fe(e);if(n!==void 0){const r=L(n);return r!==void 0&&z(r,t)}return!1},Ye=(e,t)=>{const i=K(e),n=Ie(t);if(i===void 0||n===void 0||K(n)?.compilerNode!==i.compilerNode||i.getDescendantsOfKind(u.BinaryExpression).some(c=>{const l=P(c.getLeft());return Ne(c.getOperatorToken().getKind())&&l!==void 0&&p(l.root,n)}))return!1;let o=e,a=e.getParent();for(;a!==void 0&&a.compilerNode!==i.compilerNode;){if(s.isBlock(a)){const c=a.getStatements(),l=c.findIndex(g=>g.compilerNode===o.compilerNode);if(l>0&&Be(c,l,n,i,e))return!0}o=a,a=a.getParent()}return!1},Fe=/rate|limit|\bip\b|geo|throttle/iu,Ce=/^run[A-Z]/u,Re=e=>s.isIdentifier(e)?(e.getSymbol()?.getDeclarations()??[]).some(i=>i.getFirstAncestorByKind(u.ImportDeclaration)?.getModuleSpecifierValue().startsWith("@lunora/")===!0):!1,ze=e=>{const t=s.isCallExpression(e)?e.getExpression():e;let i;return s.isIdentifier(t)?i=t:s.isPropertyAccessExpression(t)&&(i=t.getNameNode()),i!==void 0&&Re(s.isPropertyAccessExpression(t)?t.getExpression():i)&&!Fe.test(i.getText())},ke=e=>{const t=s.isCallExpression(e)?e.getExpression():void 0;if(s.isElementAccessExpression(t)){const i=t.getArgumentExpression();return(s.isStringLiteral(i)||s.isNoSubstitutionTemplateLiteral(i))&&i.getLiteralText()==="use"}return s.isPropertyAccessExpression(t)&&t.getName()==="use"},Ke=e=>{const t=e.getParent();return s.isPropertyAccessExpression(t)&&t.getExpression()===e?!Ce.test(t.getName()):s.isElementAccessExpression(t)&&t.getExpression()===e?s.isStringLiteral(t.getArgumentExpression())||s.isNoSubstitutionTemplateLiteral(t.getArgumentExpression()):s.isVariableDeclaration(t)&&t.getInitializer()?.getText()===e.getText()},Le=e=>{if(s.isPropertyAccessExpression(e))return e.getName()==="ip";if(s.isElementAccessExpression(e)){const t=e.getArgumentExpression();return(s.isStringLiteral(t)||s.isNoSubstitutionTemplateLiteral(t))&&t.getLiteralText()==="ip"}return s.isBindingElement(e)?e.getDotDotDotToken()!==void 0||(e.getPropertyNameNode()?.getText()??e.getName())==="ip":s.isShorthandPropertyAssignment(e)&&e.getName()==="ip"},Ve=(e,t)=>{const i=e.getParent();if(!s.isCallExpression(i)||i.getExpression()===e)return!1;const n=i.getArguments().indexOf(e),r=Y(i.getExpression()),o=n===-1||r===void 0?void 0:r.getParameters()[n];return r===void 0||o===void 0||o.isRestParameter()||!s.isIdentifier(o.getNameNode())?!1:t.has(r.compilerNode)?!0:(t.add(r.compilerNode),!se(r,o,t))},Me=(e,t)=>t!==void 0&&s.isIdentifier(e)&&N(e)?.compilerNode===t.compilerNode,He=e=>s.isArrowFunction(e)||s.isFunctionExpression(e)||s.isFunctionDeclaration(e)||s.isMethodDeclaration(e),Ue=(e,t)=>!s.isBindingElement(e)||e.getDotDotDotToken()===void 0?!1:e.getFirstAncestorByKind(u.Parameter)?.getParent()?.getAncestors().some(r=>r!==t&&He(r)&&r.getAncestors().includes(t))===!0,se=(e,t,i)=>{for(const n of e.getDescendants()){if(Le(n)&&!Ue(n,e)||ke(n)&&!ze(n.getArguments()[0]))return!0;if(s.isIdentifier(n)&&(le(n)||Me(n,t))&&!Ke(n)){const r=n.getParent();if(!(s.isParameterDeclaration(r)||s.isBindingElement(r)||s.isVariableDeclaration(r))&&!Ve(n,i))return!0}}return!1},$e=e=>se(e,void 0,new Set);export{Ze as a,Qe as b,Je as c,Ye as d,Xe as e,z as f,w as g,je as i,$e as m,A as r,L as s};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.416",
3
+ "version": "1.0.0-alpha.418",
4
4
  "description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -50,7 +50,7 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@lunora/advisor": "^1.0.0-alpha.294",
53
+ "@lunora/advisor": "^1.0.0-alpha.295",
54
54
  "@lunora/agent": "^1.0.0-alpha.283",
55
55
  "@lunora/container": "1.0.0-alpha.108",
56
56
  "@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",