@lunora/codegen 1.0.0-alpha.424 → 1.0.0-alpha.426
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.
- package/dist/index.d.mts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{AGENTS_FILENAME-C-QzrY0q.mjs → AGENTS_FILENAME-BSW65Q9R.mjs} +1 -1
- package/dist/packem_shared/{ALL_NOTIFY_CHANNELS-DE_qq1fJ.mjs → ALL_NOTIFY_CHANNELS-DI0zmZGs.mjs} +1 -1
- package/dist/packem_shared/{CONTAINERS_FILENAME-7_HMXUYy.mjs → CONTAINERS_FILENAME-Dy3qWGfI.mjs} +1 -1
- package/dist/packem_shared/{ENV_FILENAME-DmUUtjIW.mjs → ENV_FILENAME-DFx_jlpa.mjs} +1 -1
- package/dist/packem_shared/{MUTATORS_FILENAME-DdW3wZa_.mjs → MUTATORS_FILENAME-SLAN2VXq.mjs} +1 -1
- package/dist/packem_shared/{QUEUES_FILENAME-BovqRXD2.mjs → QUEUES_FILENAME-CVkpGqoY.mjs} +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-B669eYRp.mjs +57 -0
- package/dist/packem_shared/{SHAPES_FILENAME-Bd57JHv9.mjs → SHAPES_FILENAME-Cf4sum4C.mjs} +1 -1
- package/dist/packem_shared/{WORKFLOWS_FILENAME-DXusn4DF.mjs → WORKFLOWS_FILENAME-Dtxo_XBw.mjs} +1 -1
- package/dist/packem_shared/attribution-B8xa6AeK.mjs +1 -0
- package/dist/packem_shared/{context-property-calls-CxYu8Rfs.mjs → context-property-calls-As5I0QR6.mjs} +1 -1
- package/dist/packem_shared/{context-root-DbKRPl4u.mjs → context-root-CO8PbZi5.mjs} +1 -1
- package/dist/packem_shared/{database-calls-DtZbfTbe.mjs → database-calls-Cug60vT9.mjs} +1 -1
- package/dist/packem_shared/{discoverAuthApiCalls-BFou6Thm.mjs → discoverAuthApiCalls-DcvsgL5u.mjs} +1 -1
- package/dist/packem_shared/discoverFunctions-CGwHnz_a.mjs +1 -0
- package/dist/packem_shared/{discoverHttpRoutes-zVW8BZNx.mjs → discoverHttpRoutes-BtMgsfzG.mjs} +1 -1
- package/dist/packem_shared/discoverHyperdriveCalls-B--Nvx36.mjs +1 -0
- package/dist/packem_shared/{discoverInserts-D4fHoFon.mjs → discoverInserts-Dx7Lxey3.mjs} +1 -1
- package/dist/packem_shared/discoverMaskProcedures-Dj_hkZz2.mjs +1 -0
- package/dist/packem_shared/{discoverMigrations-D6OuJs3t.mjs → discoverMigrations-DaBdK1Bv.mjs} +1 -1
- package/dist/packem_shared/{discoverNondeterministicCalls-D7wKI8GM.mjs → discoverNondeterministicCalls-MeKjo_UX.mjs} +1 -1
- package/dist/packem_shared/{discoverQueries-DXVXWVrp.mjs → discoverQueries-BlhMsXuk.mjs} +1 -1
- package/dist/packem_shared/discoverR2sqlCalls-DHvclvkv.mjs +1 -0
- package/dist/packem_shared/{discoverRlsMetadata-CFOKezvx.mjs → discoverRlsMetadata-CO-pRHOx.mjs} +1 -1
- package/dist/packem_shared/{discoverRlsProcedures-Dz6GjF-3.mjs → discoverRlsProcedures-CUfhUqfY.mjs} +1 -1
- package/dist/packem_shared/{discoverStorageRulesMetadata-BWfevd6T.mjs → discoverStorageRulesMetadata-D_pYyr1i.mjs} +1 -1
- package/dist/packem_shared/{exported-procedure-chains-CAkR82w2.mjs → exported-procedure-chains-ej9ozyZB.mjs} +1 -1
- package/dist/packem_shared/{handler-reference-T5OJcVXW.mjs → handler-reference-_zhtPddp.mjs} +1 -1
- package/dist/packem_shared/{index-pzfYD4Dg.mjs → index-BwLaIVqA.mjs} +1 -1
- package/dist/packem_shared/{index-CmF_PUd_.mjs → index-CQuAXbal.mjs} +1 -1
- package/dist/packem_shared/ip-reads-D8rPYtZ6.mjs +1 -0
- package/package.json +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-m_oKXr4Q.mjs +0 -57
- package/dist/packem_shared/attribution-CbD9hCjb.mjs +0 -1
- package/dist/packem_shared/discoverFunctions-BkY2frX0.mjs +0 -1
- package/dist/packem_shared/discoverHyperdriveCalls-TfL8wEi8.mjs +0 -1
- package/dist/packem_shared/discoverMaskProcedures-BQWCpO-4.mjs +0 -1
- package/dist/packem_shared/discoverR2sqlCalls-CK-UpwgM.mjs +0 -1
- package/dist/packem_shared/ip-reads-Du9jIYHJ.mjs +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as o,SyntaxKind as d}from"ts-morph";import{unwrapExpression as l,memberAccessOf as C,descendantsOfKind as P,bindingKeyName as I,isConstDeclaration as D,findObjectProperty as E,walkChain as M}from"./isTestPath-DJeZ18i9.mjs";import{d as v,b as O,f as F}from"./attribution-
|
|
1
|
+
import{Node as o,SyntaxKind as d}from"ts-morph";import{unwrapExpression as l,memberAccessOf as C,descendantsOfKind as P,bindingKeyName as I,isConstDeclaration as D,findObjectProperty as E,walkChain as M}from"./isTestPath-DJeZ18i9.mjs";import{d as v,b as O,f as F}from"./attribution-B8xa6AeK.mjs";import{c as w}from"./classify-procedure-call-BK_MMoue.mjs";import{isDefineMutatorCallee as B}from"./MUTATORS_FILENAME-SLAN2VXq.mjs";const x=8,h=t=>{if(o.isMethodDeclaration(t))return t;const e=o.isPropertyAssignment(t)?l(t.getInitializer()):void 0,r=o.isShorthandPropertyAssignment(t)?t.getNameNode():e;if(o.isArrowFunction(r)||o.isFunctionExpression(r))return r;const i=o.isIdentifier(r)?v(r):void 0;if(o.isFunctionDeclaration(i))return i;const n=D(i)?l(i.getInitializer()):void 0;return o.isArrowFunction(n)||o.isFunctionExpression(n)?n:void 0},T=t=>{const e=l(t.getArguments()[0]),r=o.isObjectLiteralExpression(e)?e:void 0,i=E(r,"server"),n=E(r,"handler"),s=i!==void 0&&B(t.getExpression()),a=n===void 0?void 0:w(t),u=a!==void 0&&a.receiver===void 0;return[s?h(i):void 0,u?h(n):void 0].filter(f=>f!==void 0)},p=new WeakMap,S=t=>{const e=t.getSourceFile(),r=p.get(e.compilerNode);if(r!==void 0)return r;const i=new Set(e.getDescendantsOfKind(d.CallExpression).flatMap(n=>T(n)).map(n=>n.compilerNode));return p.set(e.compilerNode,i),i},A=t=>{const e=t.getParent();return(o.isArrowFunction(e)||o.isFunctionExpression(e)||o.isFunctionDeclaration(e)||o.isMethodDeclaration(e))&&e.getParameters()[0]===t&&S(t).has(e.compilerNode)},Y=t=>{const e=t.getParent();return(o.isArrowFunction(e)||o.isFunctionExpression(e)||o.isFunctionDeclaration(e)||o.isMethodDeclaration(e))&&e.getParameters()[1]===t&&S(t).has(e.compilerNode)},z=t=>t.getNameNode().getDescendantsOfKind(d.BindingElement).some(e=>e.getParent().getParent()===t&&["args","ctx"].includes(I(e))),b=(t,e,r)=>{const i=t.getInitializer();if(i===void 0)return e;const n=r>0?c(i,"trust",r-1):void 0;return n?.length===e.length&&n.every((s,a)=>s===e[a])?e:void 0},H=(t,e,r,i)=>{if(e==="ctx")return r==="trust"?b(t,[],i):[]},g=(t,e,r)=>{const i=t.getParent().getParent(),n=I(t);if(t.getDotDotDotToken()!==void 0||e==="trust"&&O(t))return;let s;if(o.isParameterDeclaration(i)){if(!A(i)||z(i))return H(t,n,e,r);s=[]}else o.isBindingElement(i)?s=g(i,e,r):o.isVariableDeclaration(i)&&r>0&&(s=c(i.getInitializer(),e,r-1));const a=s===void 0?void 0:[...s,n];return e==="trust"&&a!==void 0?b(t,a,r):a},c=(t,e="discover",r=x)=>{const i=l(t),n=C(i);if(n!==void 0){const s=c(n.object,e,r);return s===void 0?void 0:[...s,n.member]}return o.isIdentifier(i)?K(i,e,r):void 0},K=(t,e,r)=>{const i=t.getText()==="ctx",n=e==="trust"||!i?v(t):void 0;return i&&!o.isVariableDeclaration(n)?o.isBindingElement(n)?g(n,e,r):[]:o.isParameterDeclaration(n)?o.isIdentifier(n.getNameNode())&&A(n)?[]:void 0:o.isBindingElement(n)?g(n,e,r):!(o.isVariableDeclaration(n)&&o.isIdentifier(n.getNameNode())&&r>0)||e==="trust"&&O(n)?void 0:c(n.getInitializer(),e,r-1)},Z=t=>c(t,"discover"),$=t=>c(t,"trust"),U=t=>{const e=c(t);return e===void 0?void 0:["ctx",...e].join(".")},ee=(t,e)=>{if(e(t.getText()))return!0;const r=U(t);return r!==void 0&&e(r)},te=(t,e)=>{const r=l(t),i=C(r);if(i!==void 0&&i.member!==e.at(-1))return!1;const n=r===void 0?void 0:c(r);return n?.length===e.length&&n.every((s,a)=>s===e[a])},ne=(t,e)=>y(t).get(e)??[],k=t=>{const e=new Map;for(const i of P(t,d.BindingElement)){const n=o.isIdentifier(i.getNameNode())?g(i,"discover",x):void 0;n?.length===1&&n[0]!==void 0&&e.set(i.compilerNode,n[0])}const r=new Set([...e.keys()].map(i=>i.name.getText()));return P(t,d.Identifier).flatMap(i=>{const s=r.has(i.getText())&&!o.isBindingElement(i.getParent())?v(i):void 0,a=s===void 0?void 0:e.get(s.compilerNode);return a===void 0?[]:[[a,i]]})},N=new WeakMap,y=t=>{const e=N.get(t.compilerNode);if(e!==void 0)return e;const r=new Map;for(const[n,s]of[..._(t),...k(t)])r.set(n,[...r.get(n)??[],s]);const i=new Map([...r].map(([n,s])=>[n,s.toSorted((a,u)=>a.getPos()-u.getPos())]));return N.set(t.compilerNode,i),i},_=t=>t.getDescendantsOfKind(d.PropertyAccessExpression).flatMap(e=>R(e.getExpression())?[[e.getName(),e]]:[]),R=t=>o.isIdentifier(t)&&c(t)?.length===0,ie=t=>{const e=c(t);return e?.length===1&&e[0]==="db"},j=new Set(["asId","createMultipartUpload","fetch","generateUploadUrl","getPresignedUrl","getSignedUrl","getUrl","normalizeId","resumeMultipartUpload","runAction","runMutation","runQuery","store","upload"]),L=new Set(["catch","flatMap","map","reduce","reduceRight","then"]),V=t=>{for(let e=t;o.isBindingElement(e)||o.isObjectBindingPattern(e)||o.isArrayBindingPattern(e);e=e.getParent())if(o.isBindingElement(e)&&e.getInitializer()!==void 0)return!0;return!1},X=(t,e=x)=>{const r=M(t,u=>{const f=l(u.getExpression()),m=o.isPropertyAccessExpression(f)?f.getName():void 0;return m!==void 0&&(j.has(m)||L.has(m))?!1:void 0}),i=r.root;if(r.verdict!==void 0||!o.isIdentifier(i))return r.verdict??!1;if(c(i,"trust")!==void 0)return!0;const n=v(i),s=o.isBindingElement(n)?n.getFirstAncestorByKind(d.VariableDeclaration):n;if(o.isBindingElement(n)&&V(n))return!1;const a=D(s)&&e>0?s.getInitializer():void 0;return a!==void 0&&X(a,e-1)},re=t=>(o.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(r=>F(r)&&c(r,"trust")!==void 0);export{L as C,j as E,R as a,ne as b,$ as c,ie as d,te as e,U as f,Z as g,X as h,Y as i,h as j,ee as m,re as r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SyntaxKind as g,Node as n}from"ts-morph";import{descendantsOfKind as p}from"./isTestPath-DJeZ18i9.mjs";import{d as l}from"./context-root-
|
|
1
|
+
import{SyntaxKind as g,Node as n}from"ts-morph";import{descendantsOfKind as p}from"./isTestPath-DJeZ18i9.mjs";import{d as l}from"./context-root-CO8PbZi5.mjs";const c=e=>n.isPropertyAccessExpression(e)&&e.getName()==="db"||n.isIdentifier(e)&&e.getText()==="db"||l(e),b=new Set(["findFirst","findFirstOrThrow","findMany","findUnique"]),E=e=>{const t=e.getExpression();if(!n.isPropertyAccessExpression(t)||!b.has(t.getName()))return;const s=t.getExpression();if(c(s))return{options:e.getArguments()[1],table:d(e)};if(n.isPropertyAccessExpression(s)){const o=s.getExpression();if(c(o))return{options:e.getArguments()[0],table:s.getName()}}},f=(e,t)=>{const s=e.getExpression();return!n.isPropertyAccessExpression(s)||!t.has(s.getName())?!1:c(s.getExpression())},d=e=>{const t=e.getArguments()[0];return t&&n.isStringLiteral(t)?t.getLiteralText():""},A=(e,t,s)=>{const o=new Set,i=new Set;for(const a of p(e,g.CallExpression))if(f(a,t)){const r=d(a);r!==""&&o.add(r)}else if(f(a,s)){const r=d(a);r!==""&&i.add(r)}return{tablesRead:[...o],tablesWritten:[...i]}};export{c as i,E as r,A as t};
|
package/dist/packem_shared/{discoverAuthApiCalls-BFou6Thm.mjs → discoverAuthApiCalls-DcvsgL5u.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as t}from"ts-morph";import{collectCallRows as n}from"./isTestPath-DJeZ18i9.mjs";import{c as p}from"./attribution-
|
|
1
|
+
import{Node as t}from"ts-morph";import{collectCallRows as n}from"./isTestPath-DJeZ18i9.mjs";import{c as p}from"./attribution-B8xa6AeK.mjs";import{a}from"./property-name-7cBlgK_O.mjs";const c=s=>{const r=s.getExpression();if(!t.isPropertyAccessExpression(r))return!1;const e=r.getExpression();return t.isPropertyAccessExpression(e)?e.getName()==="authApi":t.isIdentifier(e)&&e.getText()==="authApi"},u=s=>{const r=s.getArguments()[0];if(r===void 0)return!1;if(!t.isObjectLiteralExpression(r))return!0;for(const e of r.getProperties())if((t.isPropertyAssignment(e)||t.isShorthandPropertyAssignment(e))&&a(e)==="headers"||t.isSpreadAssignment(e))return!0;return!1},d=(s,r)=>n(s,r,(e,o)=>{if(!c(e))return;const i=e.getExpression();return{file:o,hasHeaders:u(e),line:e.getStartLineNumber(),method:t.isPropertyAccessExpression(i)?i.getName():"",scope:p(e)}});export{d as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./declared-output-Iaar469J.mjs";import"./isTestPath-DJeZ18i9.mjs";import"./attribution-B8xa6AeK.mjs";import"./unwrap-handler-return-BnsKyz9W.mjs";import"./ip-reads-D8rPYtZ6.mjs";import"./classify-procedure-call-BK_MMoue.mjs";import{d as f}from"./index-BwLaIVqA.mjs";import"./dispatch-namespace-DwTjD7BU.mjs";export{f as default};
|
package/dist/packem_shared/{discoverHttpRoutes-zVW8BZNx.mjs → discoverHttpRoutes-BtMgsfzG.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as n}from"ts-morph";import{a as m,p as l}from"./parse-validator-BisfC8bR.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./isTestPath-DJeZ18i9.mjs";import{j as f,h as g}from"./attribution-
|
|
1
|
+
import{Node as n}from"ts-morph";import{a as m,p as l}from"./parse-validator-BisfC8bR.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./isTestPath-DJeZ18i9.mjs";import{j as f,h as g}from"./attribution-B8xa6AeK.mjs";import{u as x}from"./unwrap-handler-return-BnsKyz9W.mjs";const u=new Set(["delete","get","head","options","patch","post","put"]),E=new Set(["body","params","searchParams"]),v=new Set(["handler","stream"]),P=s=>{const e=s.getArguments()[0];if(e&&n.isStringLiteral(e))return e.getLiteralValue()},S=s=>{const e=s.getArguments()[0];return e&&n.isObjectLiteralExpression(e)?l(e):{}},A=s=>{if(!n.isCallExpression(s))return;const e=s.getExpression();if(!n.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const a=e.getExpression();if(!n.isIdentifier(a)||a.getText()!=="httpRoute")return;const t=P(s);return t===void 0?void 0:{method:o.toUpperCase(),path:t}},T=(s,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},a=s.getExpression();if(!n.isPropertyAccessExpression(a))return;let t=a.getExpression();for(;n.isCallExpression(t);){const i=t.getExpression();if(!n.isPropertyAccessExpression(i))break;const c=i.getName();if(u.has(c))break;if(E.has(c)){const p=S(t);o[c]={...p,...o[c]}}else if(c==="output"&&o.output===void 0){const p=t.getArguments()[0];p&&n.isExpression(p)&&(o.output=m(p))}t=i.getExpression()}const r=A(t);if(r)return o.method=r.method,o.path=r.path,o},b=s=>{const e=s.getArguments()[0];return!e||!(n.isArrowFunction(e)||n.isFunctionExpression(e))?"unknown":x(e,!0)},y=(s,e,o,a)=>{const t=e.getName();if(!v.has(t))return;const r=T(s,t);if(!(r?.method===void 0||r.path===void 0))return{body:r.body,exportName:o,filePath:a,method:r.method,params:r.params,path:r.path,searchParams:r.searchParams,stream:r.stream,...r.stream?{chunkType:b(s)}:{},...r.output?{output:r.output}:{}}},R=(s,e)=>{const o=[];for(const a of f(s)){const t=a.getInitializer();if(!t||!n.isCallExpression(t))continue;const r=t.getExpression();if(!n.isPropertyAccessExpression(r))continue;const i=y(t,r,g(a)??a.getName(),e);i&&o.push(i)}return o},L=(s,e)=>{const o=d(e),a=[];for(const t of o){const r=s.getSourceFile(t)??s.addSourceFileAtPath(t),i=h(e,t);a.push(...R(r,i))}return a.sort((t,r)=>`${t.method} ${t.path}`.localeCompare(`${r.method} ${r.path}`)||t.filePath.localeCompare(r.filePath)),a};export{L as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as o}from"./context-property-calls-As5I0QR6.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i}from"ts-morph";import{collectCallRows as n}from"./isTestPath-DJeZ18i9.mjs";import{c as a}from"./attribution-
|
|
1
|
+
import{Node as i}from"ts-morph";import{collectCallRows as n}from"./isTestPath-DJeZ18i9.mjs";import{c as a}from"./attribution-B8xa6AeK.mjs";import{i as c}from"./database-calls-Cug60vT9.mjs";const l=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="insert")return!1;const r=e.getExpression();return c(r)},g=t=>{if(!i.isIdentifier(t))return;const e=t.getSymbol(),r=e?.getAliasedSymbol()?.getDeclarations()??e?.getDeclarations()??[];for(const s of r)if(i.isVariableDeclaration(s)){const o=s.getInitializer();if(o&&i.isStringLiteral(o))return o.getLiteralText()}},f=t=>{const e=t.getArguments()[0];return e?i.isStringLiteral(e)?e.getLiteralText():g(e)??"":""},d=(t,e)=>n(t,e,(r,s)=>l(r)?{file:s,line:r.getStartLineNumber(),scope:a(r),table:f(r)}:void 0);export{d as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./isTestPath-DJeZ18i9.mjs";import"./attribution-B8xa6AeK.mjs";import"./database-calls-Cug60vT9.mjs";import"./classify-procedure-call-BK_MMoue.mjs";import{d as a}from"./index-CQuAXbal.mjs";export{a as default};
|
package/dist/packem_shared/{discoverMigrations-D6OuJs3t.mjs → discoverMigrations-DaBdK1Bv.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SyntaxKind as p,Node as n}from"ts-morph";import{diagnosticAt as h}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as I}from"./module-specifiers-BctA0m_p.mjs";import{listLunoraSourceFiles as P,lunoraRelativePath as b,findObjectProperty as d}from"./isTestPath-DJeZ18i9.mjs";import{j as x,a as A}from"./attribution-
|
|
1
|
+
import{SyntaxKind as p,Node as n}from"ts-morph";import{diagnosticAt as h}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as I}from"./module-specifiers-BctA0m_p.mjs";import{listLunoraSourceFiles as P,lunoraRelativePath as b,findObjectProperty as d}from"./isTestPath-DJeZ18i9.mjs";import{j as x,a as A}from"./attribution-B8xa6AeK.mjs";const S=i=>{const r=i.getSymbol();if(!r)return i.getText()==="defineMigration";for(const t of r.getDeclarations())if(n.isImportSpecifier(t))return I(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMigration":!1;return!1},u=(i,r)=>{const t=d(i,r);if(!t||!n.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&n.isStringLiteral(e)?e.getLiteralValue():void 0},z=i=>{const r=n.isPropertyAssignment(i)?i.getInitializer():void 0;if(r===void 0||!n.isObjectLiteralExpression(r))return;const t=u(r,"field"),e=d(r,"after"),o=n.isPropertyAssignment(e)?e.getInitializer():void 0;if(!(t===void 0||e!==void 0&&!(o!==void 0&&n.isNumericLiteral(o))))return{...o!==void 0&&n.isNumericLiteral(o)?{after:o.getLiteralValue()}:{},field:t}},E=i=>{const r=d(i,"covers"),t=n.isPropertyAssignment(r)?r.getInitializer():void 0;if(t===void 0||!n.isObjectLiteralExpression(t))return;const e={};for(const s of["jurisdiction","shardMode","table"]){const c=u(t,s);c!==void 0&&(e[s]=c)}const o=z(d(t,"ttl"));o!==void 0&&(e.ttl=o);const a=d(t,"memory");return n.isPropertyAssignment(a)&&a.getInitializer()?.getKind()===p.TrueKeyword&&(e.memory=!0),Object.keys(e).length===0?void 0:e},g=i=>n.isParenthesizedExpression(i)?g(i.getExpression()):i,v=i=>n.isArrowFunction(i)||n.isFunctionExpression(i)||n.isMethodDeclaration(i)||n.isFunctionDeclaration(i),y=(i,r=4)=>{const t=g(i);if(v(t))return t;if(r===0||!n.isIdentifier(t))return;const e=t.getParent(),o=n.isShorthandPropertyAssignment(e)?e.getValueSymbol():t.getSymbol(),a=o?.getAliasedSymbol()??o,s=a?.getValueDeclaration()??a?.getDeclarations()[0];if(s!==void 0){if(n.isVariableDeclaration(s)){const c=s.getInitializer();return c===void 0?void 0:y(c,r-1)}return v(s)?s:void 0}},N=i=>{const r=d(i,"up");let t=r;n.isPropertyAssignment(r)?t=r.getInitializer():n.isShorthandPropertyAssignment(r)&&(t=r.getNameNode());const e=t===void 0?void 0:y(t);if(e===void 0)return!1;const o=e.getParameters()[0]?.getNameNode();if(o===void 0||!n.isIdentifier(o))return!1;const a=m=>{const f=m===void 0?void 0:g(m);return f!==void 0&&n.isIdentifier(f)&&f.getText()===o.getText()},s=e.getBody();if(s===void 0)return!1;if(!n.isBlock(s))return a(s);const[c,...l]=s.getStatements();return l.length===0&&c!==void 0&&n.isReturnStatement(c)&&a(c.getExpression())},D=(i,r)=>{const t=i.getInitializer();if(t?.getKind()!==p.CallExpression)return;const e=t.getExpression();if(!n.isIdentifier(e)||!S(e))return;const o=t.getArguments()[0];if(!o||!n.isObjectLiteralExpression(o))return;const a=u(o,"id"),s=A(i,"member");if(s===void 0)return;if(a===void 0||a.trim()==="")throw h(o,`Migration "${s}" in "${r}" must declare \`id\` as a non-empty string literal so codegen can key the registry.`,{code:"MIGRATION_ID_NOT_STATIC",name:"LunoraError",status:500});const c=E(o);return{...c===void 0?{}:{covers:c},exportName:s,filePath:r,id:a,...N(o)?{identity:!0}:{},table:u(o,"table")??""}},M=i=>{const r=new Map;for(const t of i){const e=r.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});r.set(t.id,t.filePath)}},V=(i,r)=>{const t=P(r),e=[];for(const o of t){const a=i.getSourceFile(o)??i.addSourceFileAtPath(o),s=b(r,o);for(const c of x(a)){const l=D(c,s);l&&e.push(l)}}return e.sort((o,a)=>o.id.localeCompare(a.id)),M(e),e};export{V as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as s,SyntaxKind as d}from"ts-morph";import{listLunoraSourceFiles as m,lunoraRelativePath as g,handlerOf as u,descendantsOfKind as l}from"./isTestPath-DJeZ18i9.mjs";import{j as N,h as x}from"./attribution-
|
|
1
|
+
import{Node as s,SyntaxKind as d}from"ts-morph";import{listLunoraSourceFiles as m,lunoraRelativePath as g,handlerOf as u,descendantsOfKind as l}from"./isTestPath-DJeZ18i9.mjs";import{j as N,h as x}from"./attribution-B8xa6AeK.mjs";import{c as p}from"./classify-procedure-call-BK_MMoue.mjs";const h={"crypto.getRandomValues":"crypto.getRandomValues","crypto.randomUUID":"crypto.randomUUID","Date.now":"Date.now","Math.random":"Math.random"},E=new Set(["globalThis","self"]),v=new Set(["globalThis","self","window"]),I=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e)){const t=e.getExpression();if(s.isIdentifier(t)&&v.has(t.getText()))return e.getName()}},S=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=I(t.getExpression());if(i!==void 0)return n==="fetch"&&E.has(i)?"fetch":h[`${i}.${n}`]},T=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"},y=e=>{const t=e.getInitializer();if(!t||!s.isCallExpression(t))return;const n=p(t);if(!n||n.kind!=="query"&&n.kind!=="mutation")return;const i=u(t,n.receiver);return i?{exportName:x(e)??e.getName(),handler:i,kind:n.kind}:void 0},L=e=>{const t=new Set(["ctx"]),n=r=>{if(s.isObjectBindingPattern(r))for(const a of r.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getNameNode().getText(),f=a.getNameNode();c==="ctx"&&s.isIdentifier(f)&&t.add(f.getText())}},[i]=s.isParametered(e)?e.getParameters():[],o=i!==void 0&&s.isIdentifier(i.getNameNode())?i.getNameNode().getText():void 0;if(i!==void 0){const r=i.getNameNode();s.isIdentifier(r)?t.add(r.getText()):n(r)}for(const r of l(e,d.VariableDeclaration)){const a=r.getInitializer();o!==void 0&&a!==void 0&&s.isIdentifier(a)&&a.getText()===o&&n(r.getNameNode())}return t},P=(e,t,n)=>{const i=e.getExpression();if(!s.isPropertyAccessExpression(i)||i.getName()!=="random")return!1;const o=i.getExpression();return!s.isIdentifier(o)||!t.has(o.getText())?!1:o.getSymbol()?.getDeclarations()[0]?.getFirstAncestor(c=>s.isFunctionLikeDeclaration(c))===n},w=(e,t)=>{const n=[],i=L(e.handler);for(const o of l(e.handler,d.CallExpression)){const r=e.kind==="query"&&P(o,i,e.handler)?"ctx.random":S(o);r!==void 0&&n.push({callee:r,exportName:e.exportName,file:t,kind:e.kind,line:o.getStartLineNumber()})}for(const o of l(e.handler,d.NewExpression)){const r=T(o);r!==void 0&&n.push({callee:r,exportName:e.exportName,file:t,kind:e.kind,line:o.getStartLineNumber()})}return n},O=(e,t)=>{const n=[];for(const i of N(e)){const o=y(i);o&&n.push(...w(o,t))}return n},A=(e,t)=>{const n=[];for(const i of m(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...O(o,g(t,i)))}return n};export{A as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i,SyntaxKind as u}from"ts-morph";import{collectCallRows as x}from"./isTestPath-DJeZ18i9.mjs";import{w as E,c as h}from"./attribution-
|
|
1
|
+
import{Node as i,SyntaxKind as u}from"ts-morph";import{collectCallRows as x}from"./isTestPath-DJeZ18i9.mjs";import{w as E,c as h}from"./attribution-B8xa6AeK.mjs";import{i as v}from"./database-calls-Cug60vT9.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-As5I0QR6.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
|
package/dist/packem_shared/{discoverRlsMetadata-CFOKezvx.mjs → discoverRlsMetadata-CO-pRHOx.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as o}from"ts-morph";import{listLunoraSourceFiles as h,lunoraRelativePath as x,findObjectProperty as m,stringPropertyOf as a}from"./isTestPath-DJeZ18i9.mjs";import{e as L}from"./exported-procedure-chains-
|
|
1
|
+
import{Node as o}from"ts-morph";import{listLunoraSourceFiles as h,lunoraRelativePath as x,findObjectProperty as m,stringPropertyOf as a}from"./isTestPath-DJeZ18i9.mjs";import{e as L}from"./exported-procedure-chains-ej9ozyZB.mjs";import{r as P,p as A}from"./policies-CrNWTJQi.mjs";const v=new Set(["delete","insert","read","update"]),E=(e,t,s)=>{const i=[];for(const r of A(e)){const n=a(r,"on");n===void 0||!v.has(n)||i.push({file:t,on:n,procedure:s,table:a(r,"table")??""})}return i},f=e=>{if(!o.isObjectLiteralExpression(e))return[];const t=m(e,"permissions");if(!t||!o.isPropertyAssignment(t))return[];const s=t.getInitializer();if(!s||!o.isArrayLiteralExpression(s))return[];const i=[];for(const r of s.getElements()){if(o.isStringLiteral(r)){i.push(r.getLiteralText());continue}if(o.isCallExpression(r)){const n=r.getArguments()[0];n&&o.isStringLiteral(n)&&i.push(n.getLiteralText())}}return i},u=(e,t)=>t===void 0?e:{...e,description:t},y=e=>{if(o.isCallExpression(e)){const t=e.getArguments()[0];if(!t||!o.isStringLiteral(t))return;const s=e.getArguments()[1],i=s?a(s,"description"):void 0,r=s?f(s):[];return u({name:t.getLiteralText(),permissions:r},i)}if(o.isObjectLiteralExpression(e)){const t=a(e,"name");return t===void 0?void 0:u({name:t,permissions:f(e)},a(e,"description"))}},O=e=>{const t=e.getArguments()[1];if(!t||!o.isObjectLiteralExpression(t))return[];const s=m(t,"roles");if(!s||!o.isPropertyAssignment(s))return[];const i=s.getInitializer();if(!i||!o.isArrayLiteralExpression(i))return[];const r=[];for(const n of i.getElements()){const c=y(n);c&&r.push(c)}return r},S=(e,t,s)=>{const i=P(e);return{policies:i.flatMap(r=>E(r,t,s)),roles:i.flatMap(r=>O(r))}},M=(e,t)=>{const s=[],i=new Map;for(const r of h(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=x(t,r);for(const{name:g,receiver:d}of L(n)){const p=S(d,c,g);s.push(...p.policies);for(const l of p.roles)i.has(l.name)||i.set(l.name,l)}}return{policies:s,roles:[...i.values()]}};export{M as default};
|
package/dist/packem_shared/{discoverRlsProcedures-Dz6GjF-3.mjs → discoverRlsProcedures-CUfhUqfY.mjs}
RENAMED
|
@@ -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-DJeZ18i9.mjs";import{j as d,h as m}from"./attribution-
|
|
1
|
+
import{Node as l}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as f,declarationLineOf as u,findObjectProperty as p}from"./isTestPath-DJeZ18i9.mjs";import{j as d,h as m}from"./attribution-B8xa6AeK.mjs";import{t as b}from"./database-calls-Cug60vT9.mjs";import{c as h}from"./classify-procedure-call-BK_MMoue.mjs";import{r as y,p as v}from"./policies-CrNWTJQi.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 u}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as p,stringPropertyOf as l}from"./isTestPath-DJeZ18i9.mjs";import{w as d}from"./classify-procedure-call-BK_MMoue.mjs";import{e as m}from"./exported-procedure-chains-
|
|
1
|
+
import{Node as u}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as p,stringPropertyOf as l}from"./isTestPath-DJeZ18i9.mjs";import{w as d}from"./classify-procedure-call-BK_MMoue.mjs";import{e as m}from"./exported-procedure-chains-ej9ozyZB.mjs";const h=new Set(["delete","list","read","write"]),g=t=>d(t,"use","storageRules"),x=(t,s,n)=>{const e=t.getArguments()[0];if(!e||!u.isArrayLiteralExpression(e))return[];const i=[];for(const o of e.getElements()){if(!u.isObjectLiteralExpression(o))continue;const r=l(o,"on");if(r===void 0||!h.has(r))continue;const a=l(o,"prefix"),c={bucket:l(o,"bucket")??"",file:s,on:r,procedure:n};a!==void 0&&(c.prefix=a),i.push(c)}return i},A=(t,s)=>{const n=[];for(const e of f(s)){const i=t.getSourceFile(e)??t.addSourceFileAtPath(e),o=p(s,e);for(const{name:r,receiver:a}of m(i))for(const c of g(a))n.push(...x(c,o,r))}return{rules:n}};export{A as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as s}from"ts-morph";import{j as t,h as c}from"./attribution-
|
|
1
|
+
import{Node as s}from"ts-morph";import{j as t,h as c}from"./attribution-B8xa6AeK.mjs";import{c as n}from"./classify-procedure-call-BK_MMoue.mjs";const m=a=>{const i=[];for(const e of t(a)){const r=e.getInitializer(),o=r&&s.isCallExpression(r)?n(r):void 0;o?.receiver&&i.push({name:c(e)??e.getName(),receiver:o.receiver})}return i};export{m as e};
|
package/dist/packem_shared/{handler-reference-T5OJcVXW.mjs → handler-reference-_zhtPddp.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{dirname as F}from"node:path";import{Node as e}from"ts-morph";import{unwrapExpression as m,lunoraRelativePath as u}from"./isTestPath-DJeZ18i9.mjs";import{r as v,h}from"./attribution-
|
|
1
|
+
import{dirname as F}from"node:path";import{Node as e}from"ts-morph";import{unwrapExpression as m,lunoraRelativePath as u}from"./isTestPath-DJeZ18i9.mjs";import{r as v,h}from"./attribution-B8xa6AeK.mjs";const b=i=>e.isPropertyAssignment(i)?m(i.getInitializer()):e.isShorthandPropertyAssignment(i)?i.getNameNode():void 0,A=(i,s)=>{const o=i===void 0?void 0:b(i);if(o===void 0||!e.isIdentifier(o))return;const a=v(o),g=a?.getAliasedSymbol()??a;for(const t of g?.getDeclarations()??[]){const n=e.isVariableDeclaration(t)?m(t.getInitializer()):t;if(!(e.isFunctionDeclaration(n)||e.isArrowFunction(n)||e.isFunctionExpression(n))||!(e.isFunctionDeclaration(t)||e.isVariableDeclaration(t)))continue;const r=t.getSourceFile(),c=u(s,r.getFilePath()),l=!c.startsWith("../"),d=l?c:u(F(s),r.getFilePath()),f=h(t);return{body:n,...r===o.getSourceFile()?{}:{file:d},...l&&f!==void 0?{site:{exportName:f,file:d}}:{}}}};export{A as r};
|
|
@@ -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-DJeZ18i9.mjs";import{e as K,i as O}from"./attribution-CbD9hCjb.mjs";import{u as R,p as q,r as Y,c as w,a as G}from"./unwrap-handler-return-BnsKyz9W.mjs";import{m as J}from"./ip-reads-Du9jIYHJ.mjs";import{b as L,s as X,c as Q}from"./classify-procedure-call-BK_MMoue.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-DJeZ18i9.mjs";import{e as K,i as O}from"./attribution-B8xa6AeK.mjs";import{u as R,p as q,r as Y,c as w,a as G}from"./unwrap-handler-return-BnsKyz9W.mjs";import{m as J}from"./ip-reads-D8rPYtZ6.mjs";import{b as L,s as X,c as Q}from"./classify-procedure-call-BK_MMoue.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 +1 @@
|
|
|
1
|
-
import{Node as r}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as f,declarationLineOf as m}from"./isTestPath-DJeZ18i9.mjs";import{j as p,h as d}from"./attribution-
|
|
1
|
+
import{Node as r}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as f,declarationLineOf as m}from"./isTestPath-DJeZ18i9.mjs";import{j as p,h as d}from"./attribution-B8xa6AeK.mjs";import{t as g}from"./database-calls-Cug60vT9.mjs";import{w as h,c as k}from"./classify-procedure-call-BK_MMoue.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as r,SyntaxKind as l,VariableDeclarationKind as at}from"ts-morph";import{isConstDeclaration as B,unwrapExpression as u,descendantsOfKind as ct,bindingKeyName as Ee,findObjectProperty as lt}from"./isTestPath-DJeZ18i9.mjs";import{r as dt,b as F,d as m}from"./attribution-B8xa6AeK.mjs";import{i as Oe,r as ce,c as N,a as ut}from"./context-root-CO8PbZi5.mjs";import{a as ne,s as h}from"./property-name-7cBlgK_O.mjs";const gt=s=>{const e=s.getText(),t=n=>{const i=n.getNameNode();return r.isIdentifier(i)&&i.getText()===e};for(const n of s.getAncestors())if(!(!r.isArrowFunction(n)&&!r.isFunctionExpression(n)&&!r.isFunctionDeclaration(n)))for(const i of n.getParameters()){const o=i.getDescendantsOfKind(l.BindingElement).find(a=>t(a));if(o!==void 0)return o}},pt=s=>{let e=s;for(;;){const t=e.getParent();if(!r.isObjectBindingPattern(t))return;const n=t.getParent();if(r.isBindingElement(n)){e=n;continue}return r.isParameterDeclaration(n)?Ee(e):void 0}},ft=s=>{const e=s.getText();if(!s.getAncestors().some(o=>{const a=r.isFunctionLikeDeclaration(o)||r.isArrowFunction(o)?o.getParameters()[1]:void 0,c=a?.getNameNode();return a!==void 0&&(r.isIdentifier(c)?c.getText()===e:a.getDescendantsOfKind(l.BindingElement).some(d=>d.getName()===e))&&Oe(a)}))return!1;const n=m(s),i=r.isParameterDeclaration(n)?n:n?.getFirstAncestorByKind(l.Parameter);return i!==void 0&&(r.isParameterDeclaration(n)||r.isBindingElement(n))&&Oe(i)},Se=(s,e)=>{const t=s.getParent();if(r.isPropertyAccessExpression(t)&&t.getNameNode()===s||r.isPropertyAssignment(t)&&t.getNameNode()===s)return!1;if(s.getText()===e)return!0;const n=gt(s);return n!==void 0&&pt(n)===e?!0:e==="args"&&ft(s)},K=(s,e)=>r.isIdentifier(s)?Se(s,e):s.getDescendantsOfKind(l.Identifier).some(t=>Se(t,e)),Le=s=>{let e=s;for(;r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e)||r.isNonNullExpression(e);)e=e.getExpression();return r.isIdentifier(e)?e:void 0},v=s=>{const e=r.isIdentifier(s)?m(s):void 0;return r.isVariableDeclaration(e)&&r.isIdentifier(e.getNameNode())&&!F(e)?e.getInitializer():void 0},mt=(s,e)=>{const t=s.getParent();if(r.isVariableDeclarationList(t)&&t.getDeclarationKind()===at.Var)return e;const n=t.getParent();return r.isVariableStatement(n)?n.getParent():n},Et=(s,e)=>{const t=s.getNameNode();return r.isIdentifier(t)?t.getText()===e:t.getDescendantsOfKind(l.BindingElement).some(n=>{const i=n.getNameNode();return r.isIdentifier(i)&&i.getText()===e})},re=s=>s.getDescendantsOfKind(l.Identifier).filter(e=>{const t=e.getParent();return!(r.isPropertyAccessExpression(t)&&t.getNameNode()===e)&&!(r.isPropertyAssignment(t)&&t.getNameNode()===e)}),D=s=>r.isIdentifier(s)?[s]:re(s),w=s=>{let e=s;for(;;){const t=e.getParent();if(!((r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t)||r.isNonNullExpression(t))&&t.getExpression()===e))return e;e=t}},vt=s=>{const e=s.getParent();return r.isCallExpression(e)&&e.getExpression()===s?e:void 0},Re=new Set(["find","findFirst","findFirstOrThrow","findMany","findUnique","first","get","unique"]),de=new Set(["findFirst","findUnique","first","get","unique"]),P=s=>{const e=s.getExpression();return r.isPropertyAccessExpression(e)&&Re.has(e.getName())&&N(e)?.[0]==="db"},z=(s,e)=>{for(let t=s,n=s.getParent();n!==void 0&&t!==e;t=n,n=n.getParent()){if(r.isConditionalExpression(n))return!0;if(r.isBinaryExpression(n)){const i=n.getOperatorToken().getKind();if(t===n.getRight()&&(i===l.QuestionQuestionToken||i===l.BarBarToken)||t===n.getLeft()&&i===l.AmpersandAmpersandToken)return!0}}return!1},ve=s=>{if(!r.isIdentifier(s)||s.getText()!=="undefined")return!1;const e=m(s);return e===void 0||e.getSourceFile().isDeclarationFile()},Fe=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),W=s=>{const e=u(s)??s;if(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e)||r.isNumericLiteral(e)||r.isNullLiteral(e)||r.isTrueLiteral(e)||r.isFalseLiteral(e)||ve(e))return!0;const t=r.isIdentifier(e)?m(e):void 0,n=B(t)&&r.isSourceFile(t.getVariableStatement()?.getParent())?t.getInitializer():void 0;return n!==void 0&&!r.isIdentifier(u(n))&&W(n)},f=s=>{let e=s;for(let t=e.getParent();;t=e.getParent()){if(!(r.isParenthesizedExpression(t)||r.isNonNullExpression(t)||r.isAsExpression(t)||r.isSatisfiesExpression(t)||r.isTypeAssertion(t)))return e;e=t}},q=s=>r.isArrowFunction(s)||r.isFunctionExpression(s)||r.isFunctionDeclaration(s)||r.isMethodDeclaration(s),O=s=>{const e=s.getFirstAncestor(t=>q(t));return q(e)?e:void 0},Ce=new Set([l.GreaterThanEqualsToken,l.GreaterThanToken,l.InKeyword,l.InstanceOfKeyword,l.LessThanEqualsToken,l.LessThanToken]),xt=(s,e)=>{if(N(s)!==void 0||W(s))return!0;const t=m(s);if(t===void 0)return!1;if(t.getSourceFile().isDeclarationFile())return!0;const n=r.isParameterDeclaration(t)?t:t.getFirstAncestorByKind(l.Parameter);return e!==void 0&&n?.getParent().compilerNode===e.compilerNode},Q=(s,e)=>{const t=u(s)??s;if(r.isPrefixUnaryExpression(t)&&t.getOperatorToken()===l.ExclamationToken)return Q(t.getOperand(),e);if(r.isBinaryExpression(t)){const n=t.getOperatorToken().getKind();if(Fe.has(n)||Ce.has(n))return!0;if(n===l.AmpersandAmpersandToken)return Q(t.getLeft(),e)&&Q(t.getRight(),e)}return r.isTrueLiteral(t)||r.isFalseLiteral(t)?!0:!K(t,"args")&&D(t).every(n=>xt(n,e))},L=s=>{const e=m(s);return s.getSourceFile().getDescendantsOfKind(l.Identifier).filter(t=>t.getText()===s.getText()&&m(t)===e).filter(t=>{const n=t.getParent();return!((r.isVariableDeclaration(n)||r.isBindingElement(n))&&n.getNameNode()===t)})},Y=s=>{const e=O(s);if(e===void 0)return;const t=f(e).getParent();if(r.isCallExpression(t))return t.getArguments().includes(f(e))?e:void 0;const n=r.isVariableDeclaration(t)&&B(t)?t.getNameNode():void 0,i=r.isIdentifier(n)?L(n):[];return i.length>0&&i.every(o=>{const a=f(o),c=a.getParent();return r.isCallExpression(c)&&c.getArguments().includes(a)})?e:void 0},At=s=>{const e=f(s),t=e.getParent();return r.isArrowFunction(t)?t.getBody()===e&&Y(e)!==void 0:r.isReturnStatement(t)?Y(t)!==void 0:r.isIfStatement(t)||r.isWhileStatement(t)||r.isDoStatement(t)?t.getExpression()===e:r.isForStatement(t)||r.isConditionalExpression(t)?t.getCondition()===e:r.isPrefixUnaryExpression(t)?t.getOperatorToken()===l.ExclamationToken:r.isBinaryExpression(t)&&(Fe.has(t.getOperatorToken().getKind())||Ce.has(t.getOperatorToken().getKind()))},Pt=s=>{let e=s;for(let t=f(e).getParent();r.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.AmpersandAmpersandToken;t=f(e).getParent())e=t;return At(e)&&Q(e,Y(e))},ue=(s,e)=>{for(let t=s,n=s.getParent();n!==void 0&&t!==e;t=n,n=n.getParent()){if(r.isConditionalExpression(n))return!0;const i=r.isBinaryExpression(n)?n.getOperatorToken().getKind():void 0;if(r.isBinaryExpression(n)&&(i===l.QuestionQuestionToken||i===l.BarBarToken)){if(t!==n.getLeft()||!W(n.getRight()))return!0}else if(r.isBinaryExpression(n)&&i===l.AmpersandAmpersandToken&&!Pt(n))return!0}return!1},ht=s=>{const e=O(s),t=e?.getBody();return e===void 0||!r.isBlock(t)||s.getParent()!==t?!1:e.getDescendantsOfKind(l.ReturnStatement).every(n=>n===s||O(n)!==e)},Nt=s=>{let e=f(s);for(let n=e.getParent();r.isBinaryExpression(n)&&n.getOperatorToken().getKind()===l.AmpersandAmpersandToken;n=e.getParent())e=f(n);const t=e.getParent();return r.isArrowFunction(t)&&t.getBody()===e||r.isReturnStatement(t)&&ht(t)},xe="userId",Z=s=>s?.length===2&&s[0]==="auth"&&s[1]===xe,I=s=>{let e=s;for(;;){const t=r.isNonNullExpression(e)||r.isAwaitExpression(e)?e.getExpression():u(e);if(t===void 0||t===e)return e;e=t}},T=s=>Z(N(I(s))),yt=new Set(["contains","gt","gte","isNull","lt","lte","ne","neq","not","notIn"]),ze=new Set(["NOT","not","OR"]),J=s=>{for(let e=s.getParent();e!==void 0&&!r.isCallExpression(e);e=e.getParent()){const t=r.isPropertyAssignment(e)?h(e.getNameNode()):void 0;if(t!==void 0&&ze.has(t))return!0}return!1},It=s=>s>=l.FirstAssignment&&s<=l.LastAssignment,ie=s=>{let e=s,t=e.getParent();for(;r.isParenthesizedExpression(t)||r.isAsExpression(t)||r.isSatisfiesExpression(t)||r.isNonNullExpression(t)||r.isTypeAssertion(t)||r.isArrayLiteralExpression(t)||r.isObjectLiteralExpression(t)||r.isSpreadElement(t)||r.isSpreadAssignment(t)||r.isShorthandPropertyAssignment(t)||r.isPropertyAssignment(t)&&t.getNameNode()!==e;)e=t,t=e.getParent();if(r.isBinaryExpression(t))return t.getLeft()===e&&It(t.getOperatorToken().getKind());if(r.isForOfStatement(t)||r.isForInStatement(t))return t.getInitializer()===e;if(r.isPrefixUnaryExpression(t)||r.isPostfixUnaryExpression(t)){const n=t.getOperatorToken();return n===l.PlusPlusToken||n===l.MinusMinusToken}return r.isDeleteExpression(t)},Ke=(s,e)=>s.every((t,n)=>n>=e.length||t===void 0||e[n]===void 0||t===e[n]),ge=(s,e)=>s.length<e.length&&Ke(s,e),_=s=>{const e=[];let t=f(s);for(let n=t.getParent();;n=t.getParent()){if(r.isPropertyAccessExpression(n)&&n.getExpression()===t)e.push(n.getName());else if(r.isElementAccessExpression(n)&&n.getExpression()===t){const i=u(n.getArgumentExpression());e.push(r.isStringLiteral(i)||r.isNoSubstitutionTemplateLiteral(i)?i.getLiteralValue():void 0)}else return{node:t,path:e};t=f(n)}},Ae=s=>{const e=s.getParent();return r.isCallExpression(e)&&e.getExpression()===s},qe=s=>{const e=s.getParent();if(r.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),n=u(e.getLeft()===s?e.getRight():e.getLeft());return t===l.EqualsEqualsEqualsToken||t===l.ExclamationEqualsEqualsToken||(t===l.EqualsEqualsToken||t===l.ExclamationEqualsToken)&&(r.isNullLiteral(n)||ve(n))}return r.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken||r.isTypeOfExpression(e)},Ve=(s,e)=>e.length===0&&qe(s),Tt=(s,e,t,n)=>{const i=s.getParent();if(r.isSpreadAssignment(i)||r.isVariableDeclaration(i)&&r.isObjectBindingPattern(i.getNameNode()))return t.every(c=>c.length===e.length+1);const a=r.isReturnStatement(i)&&n!==void 0&&O(i)?.compilerNode===n.compilerNode;return qe(s)||a},pe=(s,e,t=[])=>{const{node:n,path:i}=_(s),o=[...t,...i];if(ie(n))return i.length===0||!e.some(d=>Ke(o,d));if(Ae(n)){const d=o.slice(0,-1);return i.length===0||!e.some(g=>ge(d,g))}const a=e.filter(d=>ge(o,d)),c=m(s);return a.length===0||Tt(n,o,a,c===void 0?void 0:O(c))},oe=(s,e)=>{const t=s.getProperties(),n=r.isSpreadAssignment(e)?void 0:ne(e);return t.slice(t.indexOf(e)+1).some(i=>{if(r.isSpreadAssignment(i))return!0;const o=h(i.getNameNode());return o===void 0||o===n})},X=s=>{for(let e=s;e!==void 0&&!r.isCallExpression(e)&&!r.isVariableDeclaration(e)&&!q(e);e=e.getParent()){const t=e.getParent();if((r.isPropertyAssignment(e)||r.isShorthandPropertyAssignment(e))&&r.isObjectLiteralExpression(t)&&oe(t,e))return!0}return!1},De=(s,e)=>{const t=f(s),n=t.getParent();return r.isCallExpression(n)&&n.getArguments().includes(t)&&e(n)},Me=(s,e=P)=>{const t=f(s),n=t.getParent();if(r.isVariableDeclaration(n)&&B(n)){const i=n.getInitializer(),o=n.getNameNode(),a=r.isIdentifier(o)&&i===t?L(o):[];return a.length>0&&a.every(c=>De(c,e))}return De(t,e)},$=(s,e=P)=>{const t=f(s),n=t.getParent();if(r.isPropertyAssignment(n))return h(n.getNameNode())==="where"&&Me(n.getParent(),e);if(r.isArrayLiteralExpression(n)){const i=f(n).getParent();return r.isPropertyAssignment(i)&&h(i.getNameNode())==="AND"&&$(i.getParent(),e)}return r.isVariableDeclaration(n)?n.getInitializer()===t:!1},Ue=(s,e=P)=>{const t=s.getParent();if(!r.isObjectLiteralExpression(t)||!(r.isPropertyAssignment(s)||r.isShorthandPropertyAssignment(s)))return!1;const n=h(s.getNameNode());if(n==="eq"||n==="in"){const i=f(t).getParent();return r.isPropertyAssignment(i)&&$(i.getParent(),e)}return $(t,e)},Ot=(s,e)=>{if(!r.isArrayLiteralExpression(s)||!s.getElements().every(a=>e.isCaller(a)))return!1;const t=f(s).getParent(),n=r.isVariableDeclaration(t)?t.getNameNode():void 0,o=r.isIdentifier(n)&&v(n)!==void 0?L(n):[s];return o.length>0&&o.every(a=>{const c=f(a).getParent();return r.isPropertyAssignment(c)&&h(c.getNameNode())==="in"&&!J(c)&&Ue(c,e.isRead)&&!X(c)})},St=s=>{const e=s.getPropertyNameNode();return!r.isComputedPropertyName(e)||W(e.getExpression())},Dt=s=>!F(s)&&[s,...s.getAncestors().filter(e=>r.isBindingElement(e))].every(e=>r.isBindingElement(e)&&e.getInitializer()===void 0&&e.getDotDotDotToken()===void 0&&St(e)),bt=(s,e,t)=>{const n=_(s).path;return t.getDescendantsOfKind(l.Identifier).filter(i=>i.getParent()!==e&&m(i)?.compilerNode===e?.compilerNode).every(i=>pe(i,[n]))},kt=(s,e)=>{const t=e===void 0?void 0:I(e);if(t===void 0)return!1;if(t===s)return!0;const n=r.isIdentifier(t)?v(t):void 0;return n!==void 0&&I(n)===s},wt=(s,e,t)=>{const n=u(s)??s,i=r.isPropertyAccessExpression(n)||r.isElementAccessExpression(n),o=i?Le(n):n,a=r.isIdentifier(o)?m(o):void 0,c=Y(e),d=c!==void 0&&kt(c,t)?c:void 0;let g;return r.isParameterDeclaration(a)&&i&&!F(a)?g=a.getParent():r.isBindingElement(a)&&Dt(a)&&(g=a.getFirstAncestorByKind(l.Parameter)?.getParent()),g!==void 0&&g===d&&r.isIdentifier(o)&&bt(o,a,g)},Bt=(s,e)=>{const{isRead:t,predicate:n}=e,i=s.getParent();if(r.isArrayLiteralExpression(i))return Ot(i,e);if(r.isPropertyAssignment(i)||r.isShorthandPropertyAssignment(i)){const c=h(i.getNameNode());return(r.isPropertyAssignment(i)?i.getInitializer():s)===s&&c!==void 0&&!yt.has(c)&&!ze.has(c)&&!J(i)&&Ue(i,t)&&!X(i)}if(r.isCallExpression(i)){const c=i.getExpression(),g=(r.isPropertyAccessExpression(c)?c.getName():void 0)==="eq"||t(i);return i.getArguments().includes(s)&&g}if(!r.isBinaryExpression(i))return!1;const o=i.getOperatorToken().getKind(),a=i.getLeft()===s?i.getRight():i.getLeft();return(o===l.EqualsEqualsEqualsToken||o===l.EqualsEqualsToken)&&Nt(i)&&wt(a,i,n)},Lt=(s,e)=>{if(!r.isCallExpression(s))return!1;const t=s.getExpression(),[n,...i]=s.getArguments(),o=r.isIdentifier(t)&&t.getText()==="String"?m(t):void 0;return n===e&&i.length===0&&o?.getSourceFile().isDeclarationFile()===!0},H=(s,e)=>{let t=w(s);for(let n=t.getParent();n!==void 0;n=t.getParent()){const i=r.isParenthesizedExpression(n)||r.isNonNullExpression(n)||r.isAsExpression(n)||r.isSatisfiesExpression(n)||r.isTypeAssertion(n)||r.isAwaitExpression(n),o=r.isBinaryExpression(n)?n.getOperatorToken().getKind():void 0,a=r.isBinaryExpression(n)&&(o===l.QuestionQuestionToken||o===l.BarBarToken)&&n.getLeft()===t&&W(n.getRight());if(!i&&!a&&!Lt(n,t))break;t=n}return Bt(t,e)},Rt=s=>{const e=f(s),t=e.getParent();if(r.isPropertyAssignment(t)||r.isShorthandPropertyAssignment(t))return h(t.getNameNode())==="where"&&!J(t)&&Me(t.getParent())&&!X(t);if(r.isArrayLiteralExpression(t)){const n=f(t).getParent();return r.isPropertyAssignment(n)&&h(n.getNameNode())==="AND"&&!J(n)&&$(n.getParent())&&!X(n)}return r.isCallExpression(t)&&t.getArguments().includes(e)&&P(t)},R=s=>{const e=I(s);if(r.isConditionalExpression(e))return[...R(e.getWhenTrue()),...R(e.getWhenFalse())];if(!r.isBinaryExpression(e))return[e];const t=e.getOperatorToken().getKind();return t===l.CommaToken?R(e.getRight()):t===l.QuestionQuestionToken||t===l.BarBarToken||t===l.AmpersandAmpersandToken?[...R(e.getLeft()),...R(e.getRight())]:[e]},We=s=>D(s).some(e=>{if(ue(e,s))return!1;if(T(w(e)))return H(e,{isCaller:T,isRead:P,predicate:s});const t=v(e),n=t===void 0?[]:R(t);if(n.length>0&&n.every(c=>T(c)))return H(e,{isCaller:T,isRead:P,predicate:s});const[i]=n,o=r.isObjectLiteralExpression(i),a=o||r.isArrayLiteralExpression(i)||r.isArrowFunction(i)||r.isFunctionExpression(i);return n.length!==1||i===void 0||!a||o&&!(r.isIdentifier(e)&&L(e).every(c=>Rt(c)))?!1:D(i).some(c=>T(w(c))&&!ue(c,i)&&H(c,{isCaller:T,isRead:P,predicate:s}))}),Ft=s=>P(s)&&s.getArguments().some(e=>We(e)),_e=(s,e)=>{for(let t=s.getParent();t!==void 0;t=t.getParent()){if(r.isCallExpression(t)&&N(t.getExpression())?.[0]==="db")return!0;if(t===e)return!1}return!1},Ct=new Set(["_id","id"]),Pe=s=>{let e=s;for(let t=e.getParent();;t=e.getParent()){if(r.isAwaitExpression(t)||r.isParenthesizedExpression(t)||r.isNonNullExpression(t)||r.isAsExpression(t)||r.isSatisfiesExpression(t)||r.isTypeAssertion(t)){e=t;continue}if(r.isPropertyAccessExpression(t)&&t.getExpression()===e)return{field:t.getName(),read:t};if(r.isElementAccessExpression(t)&&t.getExpression()===e){const n=u(t.getArgumentExpression());return{field:r.isStringLiteral(n)||r.isNoSubstitutionTemplateLiteral(n)?n.getLiteralValue():void 0,read:t}}return{field:void 0,read:e}}},he=s=>r.isPropertyAssignment(s)?s.getInitializer():r.isShorthandPropertyAssignment(s)?s.getNameNode():void 0,be=s=>{const e=f(s).getParent();return r.isCallExpression(e)&&P(e)&&e.getArguments().includes(f(s))},zt=s=>L(s).every(e=>{if(be(e))return!0;const t=f(e),n=t.getParent(),i=n?.getParent();return(r.isPropertyAssignment(n)&&n.getNameNode()!==t&&ne(n)==="where"||r.isShorthandPropertyAssignment(n)&&n.getName()==="where")&&i!==void 0&&be(i)}),ee=s=>{const e=u(s);if(r.isObjectLiteralExpression(e))return e;const t=r.isIdentifier(e)&&zt(e)?u(v(e)):void 0;return r.isObjectLiteralExpression(t)?t:void 0},Kt=s=>{const e=u(s)??s;if(!r.isObjectLiteralExpression(e))return T(s);const[t,...n]=e.getProperties(),i=n.length===0&&r.isPropertyAssignment(t)&&ne(t)==="eq"?t.getInitializer():void 0;return i!==void 0&&T(i)},Ne=s=>s.getProperties().some(e=>r.isGetAccessorDeclaration(e)||r.isSetAccessorDeclaration(e)||r.isMethodDeclaration(e)),Ge=(s,e)=>!Ne(s)&&s.getProperties().some(t=>{const n=he(t);if(n===void 0||r.isSpreadAssignment(t)||oe(s,t))return!1;const i=h(t.getNameNode());if(i===void 0)return!1;if(i==="AND"){const o=u(n);return r.isArrayLiteralExpression(o)&&o.getElements().some(a=>{const c=ee(a);return c!==void 0&&Ge(c,e)})}return(e===void 0||i===e)&&Kt(n)}),je=(s,e)=>{const t=ee(s),n=t===void 0?void 0:lt(t,"where"),i=t===void 0||n===void 0||Ne(t)||oe(t,n)?void 0:ee(he(n));return i!==void 0&&Ge(i,e)},Qe=s=>s.getArguments().some(e=>T(e)||je(e,void 0)),qt=(s,e)=>e===void 0?!1:Ct.has(e)?Qe(s):s.getArguments().some(t=>je(t,e)),Vt=new Set(["_creationTime","_id"]),Mt=(s,e)=>Vt.has(e)||s.getArguments().every(t=>{const n=ee(t);if(n===void 0)return!0;const i=n.getProperties(),o=i.findLast(c=>!r.isSpreadAssignment(c)&&ne(c)==="select");if(Ne(n))return!1;if(o===void 0)return!i.some(c=>r.isSpreadAssignment(c)||h(c.getNameNode())===void 0);if(oe(n,o))return!1;const a=u(he(o));return r.isArrayLiteralExpression(a)&&a.getElements().some(c=>(r.isStringLiteral(c)||r.isNoSubstitutionTemplateLiteral(c))&&c.getLiteralValue()===e)}),V=(s,e,t,n)=>{const i=s.getExpression(),o=r.isPropertyAccessExpression(i)&&(de.has(i.getName())||i.getName().endsWith("OrThrow"));return!Ft(s)||!o||t!==void 0&&!Mt(s,t)?!1:n!==void 0&&u(e)===u(n)&&Qe(s)||qt(s,t)},ye=(s,e)=>{const t=e.getExpression(),n=r.isPropertyAccessExpression(t)&&t.getName().endsWith("OrThrow");return(r.isPropertyAccessExpression(s)||r.isElementAccessExpression(s))&&s.hasQuestionDotToken()&&!n},He=(s,e)=>D(s).some(t=>{const n=w(t),i=N(n)?.[0];if(i==="auth")return!z(t,s)&&!_e(t,s);const o=i==="db"&&!z(t,s)?vt(n):void 0;if(o===void 0)return!1;const{field:a,read:c}=Pe(o);return!ye(c,o)&&V(o,c,a,e)}),Ut=s=>{const e=u(s);return r.isAwaitExpression(e)?u(e.getExpression()):e},M=s=>{const e=[];let t=u(s);for(;t!==void 0;)if(r.isPropertyAccessExpression(t))e.unshift(t.getName()),t=u(t.getExpression());else if(r.isElementAccessExpression(t)){const n=t.getArgumentExpression();if(!r.isStringLiteral(n))return;e.unshift(n.getLiteralValue()),t=u(t.getExpression())}else return r.isIdentifier(t)?{path:e,root:t}:void 0},S=(s,e)=>m(s)?.compilerNode===e.compilerNode,Ye=s=>{if(!r.isIdentifier(s))return;const e=dt(s),t=e?.isAlias()===!0?e.getAliasedSymbol():e,n=t?.getValueDeclaration()??t?.getDeclarations()[0];if(n===void 0)return;const i=n.getSourceFile();if(i.isDeclarationFile()||i.isInNodeModules())return;if(r.isFunctionDeclaration(n))return n.getBody()===void 0||n.isGenerator()||F(n)?void 0:n;if(!B(n))return;const o=u(n.getInitializer());return r.isArrowFunction(o)||r.isFunctionExpression(o)&&!o.isGenerator()?o:void 0},Ze=(s,e,t)=>s.getStart()<e.getEnd()||O(s)?.compilerNode!==t.compilerNode?!0:e.getAncestors().some(n=>r.isIterationStatement(n)&&n.getStart()<=s.getStart()&&s.getEnd()<=n.getEnd()),Wt=(s,e,t)=>e.getDescendantsOfKind(l.Identifier).some(n=>n.getText()===s.getName()&&ie(n)&&m(n)?.compilerNode===s.compilerNode&&Ze(n,t,e)),Ie=s=>{const e=[],t=[];let n=u(s);for(;n!==void 0;)if(r.isCallExpression(n))e.push(n),n=u(n.getExpression());else if(r.isPropertyAccessExpression(n))t.unshift(n.getName()),n=u(n.getExpression());else if(r.isElementAccessExpression(n)){const i=n.getArgumentExpression();if(!r.isStringLiteral(i))return;t.unshift(i.getLiteralValue()),n=u(n.getExpression())}else return r.isIdentifier(n)&&e.length>0&&t.length>0?{calls:e,names:t,root:n}:void 0},Te=s=>{const e=s.names[s.names.length-1]??"";if(de.has(e))return{selfEnforcing:!1};const t=e.endsWith("OrThrow")?e.slice(0,-7):void 0;return t!==void 0&&de.has(t)?{selfEnforcing:!0}:void 0},_t=s=>{const e=u(s),t=r.isIdentifier(e)?u(v(e))??e:e,n=M(t);if(n===void 0||n.path.length===0)return;const i=m(n.root);if(!B(i)||!r.isIdentifier(i.getNameNode()))return;const o=Ut(i.getInitializer()),a=r.isCallExpression(o)&&N(o.getExpression())?.[0]==="db"?Ie(o):void 0;return a!==void 0&&Te(a)!==void 0?{keyPath:n.path,row:i}:void 0},Gt=(s,e,t)=>{const n=s.getDescendantsOfKind(l.Identifier).filter(o=>o!==e.getNameNode()&&m(o)?.compilerNode===e.compilerNode);return{reads:n.flatMap(o=>{const{node:a,path:c}=_(o),d=[...t,...Ae(a)?c.slice(0,-1):c];return Ve(a,d)||ie(a)?[]:[d]}),uses:n.map(o=>({prefix:t,use:o}))}},Je=s=>s.calls.flatMap(e=>e.getArguments().flatMap(t=>[t,...t.getDescendants()])),jt=(s,e)=>{const t=r.isIdentifier(s)?m(s):void 0;if(!r.isBindingElement(t)||t.getDotDotDotToken()!==void 0||t.getInitializer()!==void 0)return!1;const n=t.getParent(),i=r.isObjectBindingPattern(n)?n.getParent():void 0;if(!B(i))return!1;const o=M(i.getInitializer());return o!==void 0&&Z([...o.path,Ee(t)])&&S(o.root,e)},ke=(s,e)=>{const t=M(s);if(t!==void 0&&t.path.length>0)return Z(t.path)&&S(t.root,e);const n=M(v(s));return n!==void 0&&Z(n.path)&&S(n.root,e)?!0:jt(s,e)},Qt=(s,e)=>{const t=s.getExpression();if(!r.isPropertyAccessExpression(t)||!Re.has(t.getName()))return!1;let n=t;for(;(r.isPropertyAccessExpression(n)||r.isElementAccessExpression(n))&&!r.isIdentifier(n.getExpression());)n=n.getExpression();const i=r.isPropertyAccessExpression(n)?n.getExpression():void 0;return r.isPropertyAccessExpression(n)&&n.getName()==="db"&&r.isIdentifier(i)&&m(i)?.compilerNode===e.compilerNode},Ht=(s,e)=>[s,...s.getDescendants()].some(t=>ke(t,e)&&!ue(t,s)&&H(t,{isCaller:n=>ke(I(n),e),isRead:n=>Qt(n,e),predicate:s})),Xe=s=>{if(!r.isVariableStatement(s))return;const e=s.getDeclarations(),t=e.length===1?e[0]:void 0;return t!==void 0&&B(t)&&r.isIdentifier(t.getNameNode())?t:void 0},Yt=(s,e)=>{const t=u(s),n=d=>r.isIdentifier(d)&&S(d,e);if(r.isPrefixUnaryExpression(t))return t.getOperatorToken()===l.ExclamationToken&&n(u(t.getOperand()));if(!r.isBinaryExpression(t))return!1;const i=t.getOperatorToken().getKind(),o=d=>i===l.EqualsEqualsEqualsToken?r.isNullLiteral(d):i===l.EqualsEqualsToken&&(r.isNullLiteral(d)||ve(d)),a=u(t.getLeft()),c=u(t.getRight());return n(a)&&o(c)||n(c)&&o(a)},Zt=(s,e)=>{const t=r.isBlock(s)?s.getStatements():void 0,n=t===void 0?s:t[t.length-1];return r.isThrowStatement(n)||!e&&r.isReturnStatement(n)},$e=(s,e,t)=>r.isIfStatement(s)&&s.getElseStatement()===void 0&&Yt(s.getExpression(),e)&&Zt(s.getThenStatement(),t),Jt=(s,e,t)=>{const n=s.getBody();if(!r.isBlock(n))return;const i=n.getStatements();return i.find((o,a)=>{const c=Xe(o),d=u(c?.getInitializer()),g=r.isAwaitExpression(d)?Ie(d.getExpression()):void 0,A=g===void 0?void 0:Te(g);if(c===void 0||g===void 0||A===void 0||g.names[0]!=="db"||!S(g.root,e))return!1;const b=Je(g),E=g.calls.some(x=>x.getArguments().some(G=>Ht(G,e))),y=t.some(x=>b.some(G=>r.isIdentifier(G)&&S(G,x)));if(!E||!y)return!1;const p=A.selfEnforcing?o:i.slice(a+1).find(x=>$e(x,c,!0));return p!==void 0&&!s.getDescendantsOfKind(l.ReturnStatement).some(x=>O(x)?.compilerNode===s.compilerNode&&x.getStart()<p.getEnd())})},Xt=(s,e,t,n)=>{const i=[];for(const[o,a]of e.entries()){const c=M(u(a));if(o!==t&&c!==void 0&&S(c.root,n)){const d=s.getParameters()[o];if(d===void 0||d.isRestParameter()||!r.isIdentifier(d.getNameNode()))return;i.push({argument:a,tied:d,...Gt(s,d,c.path)})}}return i},$t=s=>!r.isArrowFunction(s)&&re(s).some(e=>e.getText()==="arguments"&&e.getFirstAncestor(t=>q(t)&&!r.isArrowFunction(t))?.compilerNode===s.compilerNode),es=(s,e,t)=>{const n=Ye(s.getExpression()),i=s.getArguments();if(n===void 0||i.some(p=>r.isSpreadElement(p)))return;const o=i.flatMap((p,x)=>N(p)?.length===0?[x]:[]),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()||!r.isIdentifier(c.getNameNode()))return;const d=Xt(n,i,a,e);if(d===void 0)return;const g=d.map(({tied:p})=>p),A=d.flatMap(({reads:p})=>p),b=n.getReturnType(),E=n.isAsync()||b.isAny()||b.isUnknown()||b.getText().includes("Promise");if(g.length===0||!t&&E||$t(n))return;const y=Jt(n,c,g);if(y!==void 0)return[c,...g].some(p=>p.hasInitializer()||Wt(p,n,y))?void 0:{guardedPaths:A,helperArguments:d.map(({argument:p})=>p),helperUses:d.flatMap(({uses:p})=>p)}},ts=(s,e)=>{const t=Xe(s),n=u(t?.getInitializer()),i=r.isAwaitExpression(n)?Ie(n.getExpression()):void 0,o=i===void 0?void 0:Te(i);if(t===void 0||i===void 0||o===void 0||i.names[0]!=="db"||N(i.root)?.length!==0)return;const a=i.calls.some(d=>d.getArguments().some(g=>We(g))),c=Je(i).some(d=>r.isIdentifier(d)&&S(d,e));return a&&c?{declaration:t,selfEnforcing:o.selfEnforcing}:void 0},ss=(s,e,t)=>{const n=(i,o)=>o.getStart()<=i.getStart()&&i.getEnd()<=o.getEnd();for(let i=s.getParent();i!==void 0&&i.compilerNode!==e.compilerNode;i=i.getParent()){if(q(i)||r.isIfStatement(i)||r.isIterationStatement(i)||r.isCaseClause(i)||r.isDefaultClause(i)||r.isCatchClause(i))return!1;if(r.isTryStatement(i)&&i.getCatchClause()!==void 0){const o=i.getTryBlock();if(!n(s,o)||!n(t,o))return!1}}return!0},ns=(s,e)=>[s,...e.filter(t=>!ge(s,t))],rs=(s,e)=>s.getDescendantsOfKind(l.Identifier).flatMap(t=>{if(!S(t,e))return[];const{node:n,path:i}=_(t),o=Ae(n)?i.slice(0,-1):i;return Ve(n,o)?[]:[o]}),is=(s,e)=>{if(!r.isExpressionStatement(s))return;const t=u(s.getExpression()),n=r.isAwaitExpression(t),i=n?u(t.getExpression()):t;return r.isCallExpression(i)?es(i,e,n):void 0},os=(s,e,t,n,i)=>s.slice(0,e).flatMap((o,a)=>{if(!ss(o,n,i))return[];const c=is(o,t);if(c!==void 0)return[c];const d=ts(o,t);return d!==void 0&&(d.selfEnforcing||a+1<e&&$e(s[a+1],d.declaration,!1))?[{guardedPaths:rs(d.declaration,t)}]:[]}),ae=s=>{let e=u(s)??s;for(;r.isAwaitExpression(e);)e=u(e.getExpression())??e.getExpression();return e},j=s=>{const e=ae(s);return r.isCallExpression(e)||r.isNewExpression(e)},as=s=>{const e=ae(s);return r.isCallExpression(e)&&N(e.getExpression())?.[0]==="db"},et=s=>{const e=ae(s);return r.isCallExpression(e)&&P(e)},fe=s=>K(s,"args")||D(s).some(e=>{const t=v(e);return t!==void 0&&K(t,"args")}),te=(s,e)=>{const t=s?.getNameNode().getDescendantsOfKind(l.BindingElement).find(n=>r.isIdentifier(n.getNameNode())&&n.getNameNode().getText()===e);return t===void 0?[]:[t,...t.getAncestors().filter(n=>r.isBindingElement(n))].map(n=>r.isBindingElement(n)?n.getInitializer():void 0).filter(n=>n!==void 0)},tt=s=>{const e=r.isIdentifier(s)?m(s):void 0;if(!r.isBindingElement(e)||F(e))return;const t=e.getFirstAncestorByKind(l.VariableDeclaration),n=t?.getInitializer();if(!te(t,s.getText()).some(i=>fe(i)))return n!==void 0&&et(n)?n:void 0},U=s=>{const e=ae(s);return r.isCallExpression(e)&&P(e)?e:void 0},st=s=>{if(!(!r.isBindingElement(s)||!r.isObjectBindingPattern(s.getParent())||s.getDotDotDotToken()!==void 0||r.isBindingElement(s.getParent().getParent())))return Ee(s)},nt=s=>L(s).every(e=>{const t=f(e),n=t.getParent();return r.isVariableDeclaration(n)&&r.isObjectBindingPattern(n.getNameNode())||r.isSpreadAssignment(n)?!0:(r.isPropertyAccessExpression(n)||r.isElementAccessExpression(n))&&n.getExpression()===t&&!ie(f(w(n)))}),we=(s,e)=>{const t=e!==void 0&&u(s)===u(e),n=v(s);if(n!==void 0){const a=U(n);if(a===void 0)return He(n,t?n:void 0);if(r.isIdentifier(s)&&!nt(s))return!1;const{field:c,read:d}=Pe(s);return ye(d,a)?!1:V(a,d,c,e)}const i=tt(s),o=i===void 0?void 0:U(i);return o!==void 0&&r.isIdentifier(s)&&V(o,s,st(m(s)),e)},C=(s,e=!0)=>{const t=I(s);if(r.isTemplateExpression(t))return t.getTemplateSpans().flatMap(o=>C(o.getExpression(),e));if(r.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.PlusToken)return[...C(t.getLeft(),e),...C(t.getRight(),e)];const n=e&&r.isIdentifier(t)?v(t):void 0,i=n===void 0?void 0:I(n);return i!==void 0&&(r.isTemplateExpression(i)||r.isBinaryExpression(i)&&i.getOperatorToken().getKind()===l.PlusToken)?C(i,!1).map(({part:o})=>({anchor:t,part:o})):[{anchor:t,part:t}]},cs=s=>r.isStringLiteral(s)||r.isNoSubstitutionTemplateLiteral(s)||r.isNumericLiteral(s),ls=s=>{const e=I(s.getExpression()),t=r.isIdentifier(e)?v(e):void 0;if(r.isIdentifier(e)&&t!==void 0&&!nt(e))return!1;const n=U(e)??(t===void 0?void 0:U(t));return n!==void 0&&!ye(s,n)&&V(n,s,Pe(s.getExpression()).field,void 0)},ds=s=>{const e=m(s),t=st(e),n=r.isBindingElement(e)?e.getFirstAncestorByKind(l.VariableDeclaration)?.getInitializer():void 0,i=n===void 0?void 0:N(I(n));if(i!==void 0)return i.length===1&&i[0]==="auth"&&t===xe;const o=tt(s),a=o===void 0?void 0:U(o);return a!==void 0&&V(a,s,t,void 0)},rt=(s,e=!0)=>{const t=I(s),n=r.isIdentifier(t)?m(t):void 0;if((r.isVariableDeclaration(n)||r.isBindingElement(n))&&F(n))return!1;const i=N(t);if(i!==void 0)return i.length===2&&i[0]==="auth"&&i[1]===xe;if(r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t))return ls(t);if(!r.isIdentifier(t))return!1;const o=v(t);return o===void 0?ds(t):e&&rt(o,!1)},Be=(s,e,t=s)=>{const n=C(e),i=(g,A)=>g.getPos()<=A.getPos()&&A.getEnd()<=g.getEnd(),o=n.findIndex(({part:g})=>!cs(g)),a=n.findIndex(({part:g})=>i(g,s)),c=a===-1?n.findIndex(({anchor:g,part:A})=>i(A,t)||i(g,t)):a,d=n[o];return d!==void 0&&o<c&&rt(d.part)},k=s=>K(s,"args"),se=s=>{if(!r.isIdentifier(s))return;const e=s.getText(),t=s.getFirstAncestor(a=>r.isArrowFunction(a)||r.isFunctionExpression(a)||r.isFunctionDeclaration(a));if(t===void 0)return;const n=s.getStart();let i,o=-1;for(const a of ct(t,l.VariableDeclaration)){if(!Et(a,e))continue;const c=mt(a,t);if(c===void 0||n<c.getStart()||n>=c.getEnd())continue;const d=a.getInitializer(),g=a.getStart();d!==void 0&&g<n&&g>o&&(i=a,o=g)}return i},me=s=>se(s)?.getInitializer(),Ss=s=>{if(k(s))return!0;const e=t=>{const n=se(t),i=n?.getInitializer();return i!==void 0&&k(i)||te(n,t.getText()).some(o=>k(o))};return e(s)||re(s).some(t=>e(t))},Ds=s=>{if(j(s))return!1;if(te(se(s),s.getText()).some(n=>k(n)&&!j(n)))return!0;const e=me(s);if(e!==void 0&&j(e)&&!(et(e)&&k(e)))return!1;const t=e??s;return k(t)?!0:re(t).some(n=>{if(n.getFirstAncestor(c=>c===t||r.isCallExpression(c)||r.isNewExpression(c))!==t)return!1;const o=se(n),a=c=>c!==void 0&&k(c)&&(!j(c)||as(c));return a(o?.getInitializer())||te(o,n.getText()).some(c=>a(c))})},bs=s=>{if(ce(s))return!0;const e=v(s);if(e!==void 0&&ce(e))return!0;const t=e??s;return(r.isIdentifier(t)?[t]:t.getDescendantsOfKind(l.Identifier)).some(i=>{const o=v(i);return o!==void 0&&ce(o)})},ks=s=>{const e=v(s)??s,t=a=>D(a).some(c=>z(c,a)&&fe(w(c))&&!Be(c,a)),n=D(e).some(a=>{const c=v(a);return c!==void 0&&D(c).some(d=>z(d,c)&&fe(w(d))&&!Be(d,e,a))});if(t(e)||n)return!1;if(He(s,s)||we(s,s))return!0;const i=v(s)??s;return(r.isIdentifier(i)?[i]:i.getDescendantsOfKind(l.Identifier)).some(a=>!z(a,i)&&!_e(a,i)&&we(a,i))},le=(s,e)=>K(s,e),ws=(s,e)=>{if(le(s,e))return!0;const t=me(s);if(t!==void 0&&le(t,e))return!0;const n=Le(s);if(n!==void 0){const i=me(n);return i!==void 0&&le(i,e)}return!1},Bs=(s,e)=>{const t=O(s),n=_t(e);if(t===void 0||n===void 0||O(n.row)?.compilerNode!==t.compilerNode)return!1;const{keyPath:i,row:o}=n,a=o.getNameNode(),c=[];let d=s;for(let E=s.getParent();E!==void 0&&E.compilerNode!==t.compilerNode;E=E.getParent()){if(r.isBlock(E)){const y=E.getStatements(),p=y.findIndex(x=>x.compilerNode===d.compilerNode);c.push(...p>0?os(y,p,o,t,s):[])}d=E}if(!r.isIdentifier(a))return!1;const g=L(a).filter(E=>Ze(E,s,t)),A=new Set(c.flatMap(E=>E.helperArguments??[])),b=c.flatMap(E=>E.helperUses??[]);return c.some(E=>{const y=ns(i,E.guardedPaths);return g.every(p=>A.has(_(p).node)||pe(p,y))&&b.every(({prefix:p,use:x})=>pe(x,y,p))})},us=/rate|limit|\bip\b|geo|throttle/iu,gs=/^run[A-Z]/u,ps=s=>r.isIdentifier(s)?(s.getSymbol()?.getDeclarations()??[]).some(t=>t.getFirstAncestorByKind(l.ImportDeclaration)?.getModuleSpecifierValue().startsWith("@lunora/")===!0):!1,fs=s=>{const e=r.isCallExpression(s)?s.getExpression():s;let t;return r.isIdentifier(e)?t=e:r.isPropertyAccessExpression(e)&&(t=e.getNameNode()),t!==void 0&&ps(r.isPropertyAccessExpression(e)?e.getExpression():t)&&!us.test(t.getText())},ms=s=>{const e=r.isCallExpression(s)?s.getExpression():void 0;if(r.isElementAccessExpression(e)){const t=e.getArgumentExpression();return(r.isStringLiteral(t)||r.isNoSubstitutionTemplateLiteral(t))&&t.getLiteralText()==="use"}return r.isPropertyAccessExpression(e)&&e.getName()==="use"},Es=s=>{const e=s.getParent();return r.isPropertyAccessExpression(e)&&e.getExpression()===s?!gs.test(e.getName()):r.isElementAccessExpression(e)&&e.getExpression()===s?r.isStringLiteral(e.getArgumentExpression())||r.isNoSubstitutionTemplateLiteral(e.getArgumentExpression()):r.isVariableDeclaration(e)&&e.getInitializer()?.getText()===s.getText()},vs=s=>{if(r.isPropertyAccessExpression(s))return s.getName()==="ip";if(r.isElementAccessExpression(s)){const e=s.getArgumentExpression();return(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))&&e.getLiteralText()==="ip"}return r.isBindingElement(s)?s.getDotDotDotToken()!==void 0||(s.getPropertyNameNode()?.getText()??s.getName())==="ip":r.isShorthandPropertyAssignment(s)&&s.getName()==="ip"},xs=(s,e)=>{const t=s.getParent();if(!r.isCallExpression(t)||t.getExpression()===s)return!1;const n=t.getArguments(),i=n.indexOf(s);if(n.slice(0,Math.max(i,0)).some(c=>r.isSpreadElement(c)))return!1;const o=Ye(t.getExpression()),a=i===-1||o===void 0?void 0:o.getParameters()[i];return o===void 0||a===void 0||a.isRestParameter()||!r.isIdentifier(a.getNameNode())?!1:e.has(a.compilerNode)?!0:(e.add(a.compilerNode),!ot(o,a,e))},it=(s,e,t=new Set)=>{if(e===void 0||!r.isIdentifier(s))return!1;const n=m(s);if(n?.compilerNode===e.compilerNode)return!0;if(n===void 0||t.has(n.compilerNode))return!1;t.add(n.compilerNode);const i=r.isVariableDeclaration(n)&&r.isIdentifier(n.getNameNode())?n.getInitializer():void 0;return i!==void 0&&it(i,e,t)},As=s=>{const e=s.getParent();return r.isParameterDeclaration(e)||r.isBindingElement(e)||r.isVariableDeclaration(e)?e.getInitializer()!==s:!1},Ps=s=>r.isArrowFunction(s)||r.isFunctionExpression(s)||r.isFunctionDeclaration(s)||r.isMethodDeclaration(s),hs=(s,e)=>!r.isBindingElement(s)||s.getDotDotDotToken()===void 0?!1:s.getFirstAncestorByKind(l.Parameter)?.getParent()?.getAncestors().some(i=>i!==e&&Ps(i)&&i.getAncestors().includes(e))===!0,ot=(s,e,t)=>{for(const n of s.getDescendants())if(vs(n)&&!hs(n,s)||ms(n)&&!fs(n.getArguments()[0])||r.isIdentifier(n)&&(ut(n)||it(n,e))&&!Es(n)&&!As(n)&&!xs(n,t))return!0;return!1},Ls=s=>ot(s,void 0,new Set);export{bs as a,Ds as b,ks as c,Bs as d,ws as e,le as f,se as g,Ss as i,Ls as m,k as r,me as s};
|