@lunora/codegen 1.0.0-alpha.421 → 1.0.0-alpha.423
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.mjs +1 -1
- package/dist/packem_shared/DEFAULT_TARGET-5-_edM-R.mjs +1 -0
- package/dist/packem_shared/{SCHEMA_SNAPSHOT_FILENAME-CvXFQ6RH.mjs → SCHEMA_SNAPSHOT_FILENAME-CdN_q7ja.mjs} +11 -11
- package/dist/packem_shared/{SHAPES_FILENAME-BxRvP1ab.mjs → SHAPES_FILENAME-DTJKanSz.mjs} +1 -1
- package/dist/packem_shared/{discoverCrons-bT8F5GyL.mjs → discoverCrons-BlL_VbIv.mjs} +1 -1
- package/dist/packem_shared/{discoverFunctions-BNqI2S6a.mjs → discoverFunctions-CGrAezsY.mjs} +1 -1
- package/dist/packem_shared/{index-DFMCX2vk.mjs → index-M4HwQ4Jr.mjs} +1 -1
- package/dist/packem_shared/{ip-reads-D4nRZgML.mjs → ip-reads-By7tJdyu.mjs} +1 -1
- package/package.json +1 -1
- package/dist/packem_shared/DEFAULT_TARGET-CVYzxQ0y.mjs +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as d}from"node:fs";import{join as l}from"node:path";import{SyntaxKind as m,Node as n}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as u}from"./module-specifiers-BctA0m_p.mjs";import{p as h}from"./parse-validator-BisfC8bR.mjs";import{declarationLineOf as x,findObjectProperty as c}from"./isTestPath-Uwb5a6Kq.mjs";import{a as S}from"./attribution-Cwt30DDJ.mjs";import{m as f}from"./ip-reads-
|
|
1
|
+
import{existsSync as d}from"node:fs";import{join as l}from"node:path";import{SyntaxKind as m,Node as n}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as u}from"./module-specifiers-BctA0m_p.mjs";import{p as h}from"./parse-validator-BisfC8bR.mjs";import{declarationLineOf as x,findObjectProperty as c}from"./isTestPath-Uwb5a6Kq.mjs";import{a as S}from"./attribution-Cwt30DDJ.mjs";import{m as f}from"./ip-reads-By7tJdyu.mjs";const b="shapes.ts",y=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineShape";for(const e of t.getDeclarations())if(n.isImportSpecifier(e))return u(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineShape":!1;return!1},I=r=>{const t=r.getSymbol();if(!t)return!1;for(const e of t.getDeclarations()){if(!n.isNamespaceImport(e))continue;const i=e.getFirstAncestorByKind(m.ImportDeclaration);return i!==void 0&&u(i.getModuleSpecifierValue())}return!1},N=r=>{if(n.isIdentifier(r))return y(r);if(n.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineShape"&&n.isIdentifier(t)&&I(t)}return!1},A=r=>{const[t]=r.getArguments();if(!t||!n.isObjectLiteralExpression(t))return;const e=c(t,"table");if(!e||!n.isPropertyAssignment(e))return;const i=e.getInitializer();return i&&n.isStringLiteral(i)?i.getLiteralValue():void 0},E=r=>{const[t]=r.getArguments();if(!t||!n.isObjectLiteralExpression(t))return{};const e=c(t,"args");if(!e||!n.isPropertyAssignment(e))return{};const i=e.getInitializer();return!i||!n.isObjectLiteralExpression(i)?{}:h(i)},P=r=>{const[t]=r.getArguments(),e=n.isObjectLiteralExpression(t)?c(t,"where"):void 0,i=n.isPropertyAssignment(e)?e.getInitializer():void 0;if(e===void 0)return f(r);if(!n.isArrowFunction(i)&&!n.isFunctionExpression(i))return!0;const o=i.getParameters()[0]?.getNameNode();return n.isIdentifier(o)&&o.getText()!=="ctx"&&o.findReferencesAsNodes().length>0||f(r)},v=r=>{const t=[];for(const e of r.getVariableDeclarations()){const i=e.getInitializer();if(i?.getKind()!==m.CallExpression)continue;const o=i,s=o.getExpression();if(!N(s))continue;const a=e.getNameNode();if(!n.isIdentifier(a)){if(e.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw g(a,"defineShape exports must be plain named exports (no destructuring)")}const p=S(e,"binding");p!==void 0&&t.push({args:E(o),exportName:p,filePath:"shapes",line:x(e),...P(o)?{readsIp:!0}:{},table:A(o)})}return t},K=(r,t)=>{const e=l(t,b);if(!d(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),o=v(i);return o.sort((s,a)=>s.exportName.localeCompare(a.exportName)),o};export{b as SHAPES_FILENAME,K as discoverShapes};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as x}from"@lunora/errors";import{CRON_SCHEDULE_KINDS as A,warnIfSecondsLeading as O,compileCronSchedule as S}from"@lunora/scheduler";import I from"@lunora/scheduler/validate";import{SyntaxKind as p,Node as i}from"ts-morph";import{diagnosticAt as f,CodegenDiagnosticError as R}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{i as b}from"./module-specifiers-BctA0m_p.mjs";import{listLunoraSourceFiles as y,declarationLineOf as $,lunoraRelativePath as P,functionKeyOf as v}from"./isTestPath-Uwb5a6Kq.mjs";import{a as D}from"./property-name-7cBlgK_O.mjs";const F=new Set([...A,"cron"]),V=e=>{const t=e.getSymbol();if(!t)return e.getText()==="cronJobs";for(const r of t.getDeclarations())if(i.isImportSpecifier(r))return b(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="cronJobs":!1;return!1},k=e=>{const t=new Set;for(const r of e.getVariableDeclarations()){const n=r.getInitializer();if(n?.getKind()!==p.CallExpression)continue;const s=n.getExpression();i.isIdentifier(s)&&V(s)&&t.add(r.getName())}return t},j=e=>{let t=e;for(;i.isCallExpression(t)||i.isPropertyAccessExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t.getText():void 0},L=(e,t)=>{const r=e.getArguments()[t];return r&&(i.isStringLiteral(r)||i.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},_=(e,t)=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e)||i.isNumericLiteral(e))return e.getLiteralValue();if(i.isTrueLiteral(e))return!0;if(i.isFalseLiteral(e))return!1;if(i.isPrefixUnaryExpression(e)&&e.getOperatorToken()===p.MinusToken){const r=e.getOperand();if(i.isNumericLiteral(r))return-r.getLiteralValue()}if(i.isObjectLiteralExpression(e))return d(e,t);if(i.isArrayLiteralExpression(e))return e.getElements().map(r=>_(r,t));throw f(e,`Cron job "${t}" passes a non-static value where a literal is required; codegen can only read literals.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500})},d=(e,t)=>{const r={};for(const n of e.getProperties()){if(!i.isPropertyAssignment(n))throw f(n,`Cron job "${t}" uses an unsupported object property (shorthand/spread/method) where a static literal is required.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500});const s=n.getInitializer();s&&(r[D(n)]=_(s,t))}return r},C=(e,t,r)=>{const n=e.getArguments()[t];if(!n||!i.isPropertyAccessExpression(n))throw f(e,`Cron job "${r}" must reference a function statically (e.g. internal.email.digest); codegen cannot resolve a dynamic reference.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const s=v(n);if(s===void 0)throw f(n,`Cron job "${r}" function reference must be of the form internal.<…path>.fn (or api.<…path>.fn).`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});return s},h=e=>({workflow:{className:e.className,exportName:e.exportName}}),w=e=>({workflow:{className:e.className,exportName:e.exportName}}),T=(e,t,r,n,s,o)=>{const a=e.getExpression();if(!i.isIdentifier(a)||a.getText()!==t)return;const c=r.get(e.getName());if(c)return o(c);throw f(e,`Cron job "${n}" targets ${t}.${e.getName()}, but no such ${s} is declared in lunora/${s}s.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})},U=(e,t,r,n,s)=>{const o=e.getArguments()[t];if(o&&i.isPropertyAccessExpression(o)){const a=T(o,"workflows",n,r,"workflow",h);if(a)return a;const c=T(o,"agents",s,r,"agent",w);return c||{functionPath:C(e,t,r)}}if(o&&i.isIdentifier(o)){const a=n.get(o.getText()),c=s.get(o.getText());if(a&&c)throw f(o,`Cron job "${r}" references "${o.getText()}", which is ambiguous: a workflow and an agent are both declared under that name.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});if(a)return h(a);if(c)return w(c);throw f(o,`Cron job "${r}" references "${o.getText()}", which is neither a function (internal.file.fn / api.file.fn) nor a declared workflow in lunora/workflows.ts nor a declared agent in lunora/agents.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})}return{functionPath:C(e,t,r)}},M=/^@lunora\/scheduler:\s*/u,K=(e,t)=>{const r=L(e,1);if(r===void 0)throw f(e,`Cron job "${t}" must pass a string-literal cron expression to ".cron(...)".`,{code:"CRON_EXPR_NOT_STATIC",name:"LunoraError",status:500});if(!I(r))throw f(e,`Cron job "${t}" has an invalid cron expression "${r}" — expected 5 or 6 space-separated fields.`,{code:"CRON_EXPR_INVALID",name:"LunoraError",status:500});return O(r,`cron expression for job "${t}"`),r},z=(e,t,r)=>{const n=e.getArguments()[1];if(!n||!i.isObjectLiteralExpression(n))throw f(e,`Cron job "${r}" must pass an object-literal schedule to ".${t}(...)".`,{code:"CRON_SCHEDULE_NOT_STATIC",name:"LunoraError",status:500});try{return S(t,d(n,r),r)}catch(s){if(s instanceof R)throw s;const o=s instanceof Error?s.message.replace(M,""):String(s);throw f(e,o,{code:"CRON_SCHEDULE_INVALID",name:"LunoraError",status:500})}},H=(e,t,r,n,s)=>{const o=t.getName();if(!F.has(o)||!r.has(j(t.getExpression())??""))return;const a=L(e,0);if(a===void 0||a.trim()==="")throw f(e,`A cron ".${o}(...)" registration must pass a non-empty string-literal name as its first argument.`,{code:"CRON_NAME_NOT_STATIC",name:"LunoraError",status:500});const c=o==="cron"?K(e,a):z(e,o,a),u=U(e,2,a,n,s),l=e.getArguments()[3];return{args:l&&i.isObjectLiteralExpression(l)?d(l,a):{},cron:c,name:a,...u}},q=e=>{const t=new Set;for(const r of e){if(t.has(r.name))throw new x("DUPLICATE_CRON_NAME",`Duplicate cron job name "${r.name}": cron names must be unique across the project.`,{status:500});t.add(r.name)}},ee=(e,t,r=[],n=[])=>{const s=y(t),o=[],a=new Map(r.map(u=>[u.exportName,u])),c=new Map(n.map(u=>[u.exportName,u]));for(const u of s){const l=e.getSourceFile(u)??e.addSourceFileAtPath(u),g=k(l);if(g.size!==0)for(const m of l.getDescendantsOfKind(p.CallExpression)){const N=m.getExpression();if(!i.isPropertyAccessExpression(N))continue;const E=H(m,N,g,a,c);E&&o.push({...E,file:P(t,u),line:$(m)})}}return o.sort((u,l)=>u.name.localeCompare(l.name)),q(o),o};export{ee as default};
|
|
1
|
+
import{LunoraError as x}from"@lunora/errors";import{CRON_SCHEDULE_KINDS as A,warnIfSecondsLeading as O,compileCronSchedule as S}from"@lunora/scheduler";import I from"@lunora/scheduler/validate";import{SyntaxKind as p,Node as i}from"ts-morph";import{diagnosticAt as f,CodegenDiagnosticError as R}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{i as b}from"./module-specifiers-BctA0m_p.mjs";import{listLunoraSourceFiles as y,declarationLineOf as $,lunoraRelativePath as P,functionKeyOf as v}from"./isTestPath-Uwb5a6Kq.mjs";import{a as D}from"./property-name-7cBlgK_O.mjs";const F=new Set([...A,"cron"]),V=e=>{const t=e.getSymbol();if(!t)return e.getText()==="cronJobs";for(const r of t.getDeclarations())if(i.isImportSpecifier(r))return b(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="cronJobs":!1;return!1},k=e=>{const t=new Set;for(const r of e.getVariableDeclarations()){const n=r.getInitializer();if(n?.getKind()!==p.CallExpression)continue;const s=n.getExpression();i.isIdentifier(s)&&V(s)&&t.add(r.getName())}return t},j=e=>{let t=e;for(;i.isCallExpression(t)||i.isPropertyAccessExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t.getText():void 0},L=(e,t)=>{const r=e.getArguments()[t];return r&&(i.isStringLiteral(r)||i.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},_=(e,t)=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e)||i.isNumericLiteral(e))return e.getLiteralValue();if(i.isTrueLiteral(e))return!0;if(i.isFalseLiteral(e))return!1;if(i.isPrefixUnaryExpression(e)&&e.getOperatorToken()===p.MinusToken){const r=e.getOperand();if(i.isNumericLiteral(r))return-r.getLiteralValue()}if(i.isObjectLiteralExpression(e))return d(e,t);if(i.isArrayLiteralExpression(e))return e.getElements().map(r=>_(r,t));throw f(e,`Cron job "${t}" passes a non-static value where a literal is required; codegen can only read literals.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500})},d=(e,t)=>{const r={};for(const n of e.getProperties()){if(!i.isPropertyAssignment(n))throw f(n,`Cron job "${t}" uses an unsupported object property (shorthand/spread/method) where a static literal is required.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500});const s=n.getInitializer();s&&(r[D(n)]=_(s,t))}return r},C=(e,t,r)=>{const n=e.getArguments()[t];if(!n||!i.isPropertyAccessExpression(n))throw f(e,`Cron job "${r}" must reference a function statically (e.g. internal.email.digest); codegen cannot resolve a dynamic reference.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const s=v(n);if(s===void 0)throw f(n,`Cron job "${r}" function reference must be of the form internal.<…path>.fn (or api.<…path>.fn).`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});return s},h=e=>({workflow:{className:e.className,exportName:e.exportName}}),w=e=>({workflow:{className:e.className,exportName:e.exportName}}),T=(e,t,r,n,s,o)=>{const a=e.getExpression();if(!i.isIdentifier(a)||a.getText()!==t)return;const c=r.get(e.getName());if(c)return o(c);throw f(e,`Cron job "${n}" targets ${t}.${e.getName()}, but no such ${s} is declared in lunora/${s}s.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})},U=(e,t,r,n,s)=>{const o=e.getArguments()[t];if(o&&i.isPropertyAccessExpression(o)){const a=T(o,"workflows",n,r,"workflow",h);if(a)return a;const c=T(o,"agents",s,r,"agent",w);return c||{functionPath:C(e,t,r)}}if(o&&i.isIdentifier(o)){const a=n.get(o.getText()),c=s.get(o.getText());if(a&&c)throw f(o,`Cron job "${r}" references "${o.getText()}", which is ambiguous: a workflow and an agent are both declared under that name.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});if(a)return h(a);if(c)return w(c);throw f(o,`Cron job "${r}" references "${o.getText()}", which is neither a function (internal.file.fn / api.file.fn) nor a declared workflow in lunora/workflows.ts nor a declared agent in lunora/agents.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})}return{functionPath:C(e,t,r)}},M=/^@lunora\/scheduler:\s*/u,K=(e,t)=>{const r=L(e,1);if(r===void 0)throw f(e,`Cron job "${t}" must pass a string-literal cron expression to ".cron(...)".`,{code:"CRON_EXPR_NOT_STATIC",name:"LunoraError",status:500});if(!I(r))throw f(e,`Cron job "${t}" has an invalid cron expression "${r}" — expected 5 or 6 space-separated fields that occur on at least one date.`,{code:"CRON_EXPR_INVALID",name:"LunoraError",status:500});return O(r,`cron expression for job "${t}"`),r},z=(e,t,r)=>{const n=e.getArguments()[1];if(!n||!i.isObjectLiteralExpression(n))throw f(e,`Cron job "${r}" must pass an object-literal schedule to ".${t}(...)".`,{code:"CRON_SCHEDULE_NOT_STATIC",name:"LunoraError",status:500});try{return S(t,d(n,r),r)}catch(s){if(s instanceof R)throw s;const o=s instanceof Error?s.message.replace(M,""):String(s);throw f(e,o,{code:"CRON_SCHEDULE_INVALID",name:"LunoraError",status:500})}},H=(e,t,r,n,s)=>{const o=t.getName();if(!F.has(o)||!r.has(j(t.getExpression())??""))return;const a=L(e,0);if(a===void 0||a.trim()==="")throw f(e,`A cron ".${o}(...)" registration must pass a non-empty string-literal name as its first argument.`,{code:"CRON_NAME_NOT_STATIC",name:"LunoraError",status:500});const c=o==="cron"?K(e,a):z(e,o,a),u=U(e,2,a,n,s),l=e.getArguments()[3];return{args:l&&i.isObjectLiteralExpression(l)?d(l,a):{},cron:c,name:a,...u}},q=e=>{const t=new Set;for(const r of e){if(t.has(r.name))throw new x("DUPLICATE_CRON_NAME",`Duplicate cron job name "${r.name}": cron names must be unique across the project.`,{status:500});t.add(r.name)}},ee=(e,t,r=[],n=[])=>{const s=y(t),o=[],a=new Map(r.map(u=>[u.exportName,u])),c=new Map(n.map(u=>[u.exportName,u]));for(const u of s){const l=e.getSourceFile(u)??e.addSourceFileAtPath(u),g=k(l);if(g.size!==0)for(const m of l.getDescendantsOfKind(p.CallExpression)){const N=m.getExpression();if(!i.isPropertyAccessExpression(N))continue;const E=H(m,N,g,a,c);E&&o.push({...E,file:P(t,u),line:$(m)})}}return o.sort((u,l)=>u.name.localeCompare(l.name)),q(o),o};export{ee as default};
|
package/dist/packem_shared/{discoverFunctions-BNqI2S6a.mjs → discoverFunctions-CGrAezsY.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./declared-output-Iaar469J.mjs";import"./isTestPath-Uwb5a6Kq.mjs";import"./attribution-Cwt30DDJ.mjs";import"./unwrap-handler-return-DvbyiLjc.mjs";import"./ip-reads-
|
|
1
|
+
import"./declared-output-Iaar469J.mjs";import"./isTestPath-Uwb5a6Kq.mjs";import"./attribution-Cwt30DDJ.mjs";import"./unwrap-handler-return-DvbyiLjc.mjs";import"./ip-reads-By7tJdyu.mjs";import"./classify-procedure-call-BmEirzc_.mjs";import{d as f}from"./index-M4HwQ4Jr.mjs";import"./dispatch-namespace-DwTjD7BU.mjs";export{f as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as g}from"@lunora/errors";import{Node as s,SyntaxKind as B}from"ts-morph";import{d as z}from"./declared-output-Iaar469J.mjs";import{findObjectProperty as h,bindingKeyName as H,listLunoraSourceFiles as M,lunoraRelativePath as W}from"./isTestPath-Uwb5a6Kq.mjs";import{e as K,i as O}from"./attribution-Cwt30DDJ.mjs";import{u as R,p as q,r as Y,c as w,a as G}from"./unwrap-handler-return-DvbyiLjc.mjs";import{m as J}from"./ip-reads-D4nRZgML.mjs";import{b as L,s as X,c as Q}from"./classify-procedure-call-BmEirzc_.mjs";import{r as D,p as C,a as Z}from"./parse-validator-BisfC8bR.mjs";import{N as ee,l as te}from"./project-config-file-DR7xrrNB.mjs";import{s as ie}from"./dispatch-namespace-DwTjD7BU.mjs";const I=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,ne=e=>{const i=e.getArguments()[0],t=I(i);if(t!==void 0)return t;if(i===void 0||!s.isObjectLiteralExpression(i))return;const n=h(i,"handler");return n!==void 0&&s.isPropertyAssignment(n)?I(n.getInitializer()):void 0},re=e=>{const i=e.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return"unknown";const t=h(i,"handler");if(!t||!s.isPropertyAssignment(t))return"unknown";const n=t.getInitializer();return!n||!(s.isArrowFunction(n)||s.isFunctionExpression(n))?"unknown":R(n)},oe=e=>{const i=e.getArguments()[0];return!i||!(s.isArrowFunction(i)||s.isFunctionExpression(i))?"unknown":R(i)},se=e=>{let i={};for(const t of L(e)){if(t.name!=="input")continue;const n=t.call.getArguments()[0],o=n!==void 0&&s.isExpression(n)?D(n):void 0;o!==void 0&&(i={...C(o),...i})}return i},ae=e=>{const i=L(e).find(n=>n.name==="output");if(!i)return;const t=i.call.getArguments()[0];return t&&s.isExpression(t)?q(i.call,()=>Z(t)):void 0},E=(e,i)=>{const t=h(e,i);if(t===void 0||!s.isPropertyAssignment(t))return;const n=t.getInitializer();return n!==void 0&&s.isStringLiteral(n)?n.getLiteralValue():void 0},k=(e,i)=>{const t=h(e,i);if(t===void 0||!s.isPropertyAssignment(t))return;const n=t.getInitializer();return n!==void 0&&s.isNumericLiteral(n)?n.getLiteralValue():void 0},ce=e=>{const i=h(e,"cache");if(i===void 0||!s.isPropertyAssignment(i))return;const t=i.getInitializer();if(t===void 0||!s.isObjectLiteralExpression(t))return;const n=E(t,"scope"),o=k(t,"maxAge"),r=k(t,"staleWhileRevalidate"),a=E(t,"tag"),c=E(t,"vary"),l={...o===void 0?{}:{maxAge:o},...n==="private"||n==="public"?{scope:n}:{},...r===void 0?{}:{staleWhileRevalidate:r},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},le=e=>{if(e===void 0||!s.isObjectLiteralExpression(e))return{};const i=ce(e),t=h(e,"rest");return t!==void 0&&s.isPropertyAssignment(t)?{...i===void 0?{}:{cache:i},rest:t.getInitializer()?.getText()==="true"}:i===void 0?{}:{cache:i}},ue=e=>{const i=L(e).find(t=>t.name==="expose");return i?le(i.call.getArguments()[0]):void 0},de=e=>{const i=L(e).find(r=>r.name==="x402");if(!i)return;const t=i.call.getArguments()[0];if(t===void 0||!s.isObjectLiteralExpression(t))return{};const n=h(t,"price");if(n===void 0||!s.isPropertyAssignment(n))return{};const o=n.getInitializer();return o===void 0?{}:s.isStringLiteral(o)?{price:o.getLiteralValue()}:s.isNumericLiteral(o)?{price:o.getLiteralValue()}:{}},ge=e=>{const i=e.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return{};const t=h(i,"args");if(!t||!s.isPropertyAssignment(t))return{};const n=t.getInitializer(),o=n===void 0?void 0:D(n);return o===void 0?{}:C(o)},f=(e,i)=>{throw new g("INTERNAL",`@lunora/codegen: lazy function registry needs literal ${i} in ${e.getSourceFile().getFilePath()}:${String(e.getStartLineNumber())}`)},S=(e,i,t)=>{if(!e||!s.isObjectLiteralExpression(e))return f(i,"metadata objects");const n=new Set;for(const o of e.getProperties()){if(!s.isPropertyAssignment(o))return f(o,"metadata fields without spreads, getters, or shorthand");const r=o.getNameNode(),a=s.isStringLiteral(r)?r.getLiteralValue():r.getText();if(!s.isIdentifier(r)&&!s.isStringLiteral(r)||!t.includes(a)||n.has(a))return f(o,"supported, unique metadata fields");n.add(a)}return e},y=(e,i)=>{const t=e.getProperty(i);return t&&s.isPropertyAssignment(t)?t.getInitializer():void 0},pe=e=>{const i=S(e,e,["credentialHeaders","maxAge","scope","staleWhileRevalidate","tag","vary"]),t={};for(const r of["maxAge","staleWhileRevalidate"]){const a=y(i,r);if(!(a===void 0&&r!=="maxAge")){if(!a||!s.isNumericLiteral(a))return f(e,`cache.${r}`);t[r]=a.getLiteralValue()}}const n=y(i,"scope");if(!n||!s.isStringLiteral(n)||!["private","public"].includes(n.getLiteralValue()))return f(e,"cache.scope");t.scope=n.getLiteralValue();for(const r of["tag","vary"]){const a=y(i,r);if(a!==void 0){if(!s.isStringLiteral(a))return f(a,`cache.${r}`);t[r]=a.getLiteralValue()}}const o=y(i,"credentialHeaders");if(o!==void 0){if(!s.isArrayLiteralExpression(o))return f(o,"cache.credentialHeaders");t.credentialHeaders=o.getElements().map(r=>s.isStringLiteral(r)?r.getLiteralValue():f(r,"cache.credentialHeaders string entries"))}return t},fe=e=>{const i=S(e.getArguments()[0],e,["rest","cache"]),t=y(i,"rest"),n=y(i,"cache");return t!==void 0&&!s.isTrueLiteral(t)&&!s.isFalseLiteral(t)?f(t,".expose({ rest })"):{...t?{rest:s.isTrueLiteral(t)}:{},...n?{cache:pe(n)}:{}}},me=e=>{const i=S(e.getArguments()[0],e,["price"]),t=y(i,"price");return!t||!s.isStringLiteral(t)&&!s.isNumericLiteral(t)?f(e,"`.x402({ price })` value"):{price:t.getLiteralValue()}},he=e=>{const i=e.map(o=>{const r=o.getArguments()[0];return r===void 0?ee:te(r)}),t=i.every(o=>o!==null&&typeof o=="object"&&!Array.isArray(o)),n=i.reduce((o,r)=>({...r,...o}),{});return t?n:"unloaded"},ye=e=>{const{factory:i,steps:t}=X(e);if(!i)return f(e,"metadata from a resolvable Lunora factory root");const n={visibility:i.startsWith("internal")?"internal":"public"};for(const{call:r,name:a}of t){if(!["expose","input","meta","output","use","x402"].includes(a))return f(r,`known builder modifiers, got .${a}()`);a==="expose"&&n.expose===void 0&&(n.expose=fe(r)),a==="x402"&&n.x402===void 0&&(n.x402=me(r))}const o=t.filter(r=>r.name==="meta").map(r=>r.call);return o.length===0?n:{...n,meta:he(o)}},ve=new Set(["action","mutation","query","stream"]),N=(e,i,t)=>{const n=e.getProperty(i)?.getTypeAtLocation(t);if(n===void 0)return;const o=n.isUnion()?n.getUnionTypes().filter(a=>!a.isUndefined()):[n],r=o.length===1?o[0]?.getLiteralValue():void 0;return typeof r=="string"?r:void 0},U=(e,i)=>{const t=N(e,"kind",i);return t!==void 0&&ve.has(t)&&e.getProperty("handler")!==void 0?t:void 0},be=e=>{const i=e.getParent();if(s.isPropertyAccessExpression(i)&&i.getExpression()===e)return i.getName()==="functions";if(s.isElementAccessExpression(i)&&i.getExpression()===e){const n=i.getArgumentExpression();return n!==void 0&&s.isStringLiteral(n)&&n.getLiteralValue()==="functions"}const t=s.isVariableDeclaration(i)&&i.getNameNode()!==e?i.getNameNode():void 0;return t!==void 0&&s.isObjectBindingPattern(t)&&t.getElements().some(n=>(n.getPropertyNameNode()?.getText()??n.getName())==="functions")},it=(e,i)=>{for(const t of e)for(const n of t.getVariableDeclarations()){const o=n.getNameNode();if(!n.isExported()||!s.isIdentifier(o))continue;const a=(n.getType().getProperty("functions")?.getTypeAtLocation(n)?.getProperties()??[]).filter(u=>U(u.getTypeAtLocation(n),n)!==void 0);if(a.length===0||o.findReferencesAsNodes().some(u=>be(u)))continue;const l=n.getName(),d=a.map(u=>u.getName()).join(", ");console.warn(`@lunora/codegen: ${i(t)}:${l} ships functions (${d}) that nothing re-exports, so none is in the generated api. Add \`export const { ${d} } = ${l}.functions;\` (or export your own wrappers of them).`)}},Ne=new Set(["connect","disconnect","init","reactor","whisper"]),Le={ArrayBuffer:"bytes",GeoPoint:"geoPoint"},Ae=8,P=(e,i)=>{const t=e.getText(i);return t===""?{kind:"from"}:{kind:"from",tsType:t}},Ee=new Set(["false","true"]),Pe=[[e=>e.isAny()||e.isUnknown(),"any"],[e=>e.isString(),"string"],[e=>e.isNumber(),"number"],[e=>e.isBoolean(),"boolean"],[e=>e.isNull(),"null"],[e=>e.isBigInt(),"bigint"]],Te=(e,i,t)=>{if(!e.isObject()||e.isIntersection()||e.getCallSignatures().length>0||e.isClass())return;const n=e.getProperties();if(n.some(r=>r.getTypeAtLocation(i).getCallSignatures().length>0))return;const o=e.getStringIndexType();if(o!==void 0&&n.length===0)return{keyType:{kind:"string"},kind:"record",valueType:b(o,i,t+1)};if(!(o!==void 0||n.length===0))return{kind:"object",shape:Object.fromEntries(n.map(r=>[r.getName(),$(r.getTypeAtLocation(i),r.isOptional(),i,t+1)]))}},b=(e,i,t)=>{if(t>Ae)return P(e,i);const n=Pe.find(([a])=>a(e));if(n!==void 0)return{kind:n[1]};const o=Le[(e.getSymbol()??e.getAliasSymbol())?.getName()??""];if(o!==void 0)return{kind:o};if(e.isStringLiteral()||e.isNumberLiteral()||e.isBooleanLiteral()||e.isBigIntLiteral())return{kind:"literal",literalValue:e.getText(i),sensitive:!0};const r=e.isIntersection()?N(e,"__table",i):void 0;if(r!==void 0)return{kind:"id",tableName:r};if(e.isUnion())return F(e.getUnionTypes(),i,t);if(e.isArray()){const a=e.getArrayElementType();return a===void 0?P(e,i):{inner:b(a,i,t+1),kind:"array"}}return Te(e,i,t)??P(e,i)},F=(e,i,t)=>{const o=new Set(e.filter(l=>l.isBooleanLiteral()).map(l=>l.getText(i))).size===Ee.size,r=e.filter(l=>!(o&&l.isBooleanLiteral())).map(l=>b(l,i,t+1)),a=o?[...r,{kind:"boolean"}]:r,[c]=a;return a.length===1&&c!==void 0?c:{kind:"union",members:a}},$=(e,i,t,n)=>{const o=e.isUnion()?e.getUnionTypes():[e],r=o.filter(l=>!l.isUndefined());if(!i&&r.length===o.length)return b(e,t,n);if(r.length===0)return{inner:{kind:"any"},kind:"optional"};const[a]=r;return{inner:r.length===1&&a!==void 0?b(a,t,n):F(r,t,n),kind:"optional"}},xe=(e,i)=>{const t=e.getProperty("__type")?.getTypeAtLocation(i);if(t===void 0)return{kind:"from"};const n=(e.getSymbol()??e.getAliasSymbol())?.getName();return n==="TimestampColumnValidator"?{kind:"timestamp"}:n==="ObjectColumnValidator"&&t.getProperties().length===0?{kind:"object",shape:{}}:$(t,!1,i,0)},Se=new Set(["AsyncGenerator","AsyncIterable","AsyncIterableIterator"]),Oe=(e,i)=>{const t=e.getProperty("handler")?.getTypeAtLocation(i).getCallSignatures()[0]?.getReturnType();if(t===void 0)return[];if(Se.has((t.getSymbol()??t.getAliasSymbol())?.getName()??"")){const[n]=t.getTypeArguments();return n===void 0?[]:[n]}return(t.isUnion()?t.getUnionTypes():[t]).map(n=>n.getSymbol()?.getName()==="Promise"?n.getTypeArguments()[0]??n:n)},we=(e,i)=>{const t=[...new Set(e.map(n=>Y(n,i)))];return t.length===0||t.includes("unknown")?"unknown":t.join(" | ")},Ie=(e,i,t,n)=>{const o=e.getType(),r=U(o,e);if(r===void 0)return;const a={...n?{description:n}:{},exportName:i,filePath:t,kind:r};if(o.getProperty("channel")?.isOptional()===!1)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a room from a published package; its name is not in the declared type, so codegen cannot route it. Declare the room with \`defineRoom\` in this file instead.`);const c=N(o,"lifecycle",e),l=o.getProperty("lifecycle");if(c===void 0&&l!==void 0&&!l.isOptional())throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a lifecycle hook from a published package whose type does not say which moment it runs at. Declare it with its moment, e.g. \`RegisteredLifecycleHook & { readonly lifecycle: "disconnect" }\` (what \`onDisconnect\` returns).`);if(c!==void 0){if(!Ne.has(c))throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a "${c}" lifecycle hook from a published package; only a locally declared hook can carry its route. Declare it in this file instead.`);return{...a,args:{},lifecycle:c,returnType:"void",visibility:"internal"}}const d=N(o,"visibility",e);if(d!=="internal"&&d!=="public")throw new g("PUBLISHED_FUNCTION_VISIBILITY_UNKNOWN",`${t}:${i} re-exports a function from a published package whose type does not say whether it is internal or public. Declare it in that package as \`RegisteredQuery\` / \`RegisteredMutation\` / \`RegisteredAction\` (public) or their \`RegisteredInternal*\` counterparts, not the bare \`RegisteredFunction\`, so codegen does not list an internal function in the client \`api\`.`);if(d==="internal"&&o.getProperty("visibility")?.isOptional()!==!1)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports an internal function from a published package whose type makes \`visibility\` optional, so the value may not carry it. Declare it with a \`RegisteredInternal*\` type, which requires \`visibility: "internal"\`.`);const u=o.getProperty("args")?.getTypeAtLocation(e);if(u===void 0||u.isAny()||u.isUnknown()||u.getStringIndexType()!==void 0||u.getNumberIndexType()!==void 0)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a function from a published package whose type does not list its arguments. Declare its validator map with one key per argument (an empty \`{}\` for none) so codegen can type the client call.`);const m=Object.fromEntries(u.getProperties().map(p=>[p.getName(),xe(p.getTypeAtLocation(e),e)]));return{...a,args:m,...r==="query"?{readsIp:!0}:{},returnType:we(Oe(o,e),e),typeDerivedArgs:!0,visibility:d}},ke=8,A=(e,i=0)=>{if(i>ke)return;if(s.isCallExpression(e))return{call:e};if(s.isParenthesizedExpression(e)||s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isNonNullExpression(e))return A(e.getExpression(),i+1);if(!s.isIdentifier(e)&&!s.isPropertyAccessExpression(e))return;const t=e.getSymbol()?.getValueDeclaration();return t?T(t,i+1):void 0},T=(e,i)=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e)){const t=e.getInitializer();return t?A(t,i):{deadEnd:e}}if(s.isShorthandPropertyAssignment(e)){const t=e.getValueSymbol()?.getValueDeclaration();return t?T(t,i+1):void 0}if(s.isBindingElement(e)){const t=H(e),r=e.getFirstAncestorByKind(B.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return r?T(r,i+1):void 0}return{deadEnd:e}},x=e=>{const i=A(e);return i!==void 0&&"call"in i?i.call:void 0},_=e=>{const i=A(e);return i!==void 0&&"deadEnd"in i&&i.deadEnd.getSourceFile().isDeclarationFile()},_e=(e,i=()=>!0)=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t)){const r=[];for(const a of t.getElements().filter(c=>i(c.getName()))){const c=x(a.getNameNode());c&&r.push([a.getName(),c])}return r}if(!i(e.getName()))return[];const n=e.getInitializer(),o=n&&(s.isCallExpression(n)?n:x(n));return o?[[e.getName(),o]]:[]},Re=(e,i)=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t))return t.getElements().filter(o=>i(o.getName())&&_(o.getNameNode())).map(o=>[o.getName(),o.getNameNode()]);const n=e.getInitializer();return i(e.getName())&&n!==void 0&&_(n)?[[e.getName(),t]]:[]},De=e=>{const i=e.getArguments()[0],t=s.isObjectLiteralExpression(i)?i.getProperty("name"):void 0,n=s.isPropertyAssignment(t)?t.getInitializer():void 0;if(!n||!s.isStringLiteral(n))throw new g("ROOM_NAME_NOT_LITERAL",'defineRoom needs a string-literal `name` (e.g. `defineRoom({ name: "chat", … })`) so codegen can type its reference.');return n.getLiteralValue()},Ce=e=>e.startsWith("/")&&new URL(e,"https://lunora.invalid").pathname===e&&e!=="/_lunora"&&!e.startsWith("/_lunora/"),Ue=e=>{const i=e.getArguments()[0];if(!s.isObjectLiteralExpression(i))throw new g("SOCKET_PATH_NOT_LITERAL","defineWebSocket needs an object-literal options argument so codegen can read its `path` and `auth`.");const t=i.getProperty("path"),n=s.isPropertyAssignment(t)?t.getInitializer():void 0;if(!n||!s.isStringLiteral(n))throw new g("SOCKET_PATH_NOT_LITERAL",'defineWebSocket needs a string-literal `path` (e.g. `defineWebSocket({ path: "/chat", … })`) so codegen can route its upgrade.');const o=n.getLiteralValue();if(!Ce(o))throw new g("SOCKET_PATH_INVALID",`defineWebSocket path "${o}" must be a plain URL path starting with "/" (no "?", "#", ".." or unencoded characters) and not under "/_lunora".`);if(i.getProperties().some(l=>s.isSpreadAssignment(l)||s.isPropertyAssignment(l)&&s.isComputedPropertyName(l.getNameNode())))throw new g("SOCKET_AUTH_NOT_LITERAL","defineWebSocket cannot spread its options or use a computed key: codegen must read `auth` as a literal `auth: true` or `auth: false`.");const a=i.getProperty("auth");if(a===void 0)return{auth:!1,path:o};const c=s.isPropertyAssignment(a)?a.getInitializer():void 0;if(c===void 0||!(s.isTrueLiteral(c)||s.isFalseLiteral(c)))throw new g("SOCKET_AUTH_NOT_LITERAL","defineWebSocket needs a literal `auth: true` or `auth: false`, so codegen can read whether the route requires a session. A shorthand or a variable is not read.");return{auth:s.isTrueLiteral(c),path:o}},Fe=(e,i,t,n)=>{const o=n?ye(i):void 0,r=n?o?.expose:ue(i),a=n?o?.x402:de(i),c=w(()=>ae(i)),l=w(()=>oe(e)),d=z({kind:t.kind,output:c.value});return G(d?c.erased:l.erased),{args:se(i),...r?{expose:r}:{},...a?{x402:a}:{},...o?.meta===void 0?{}:{meta:o.meta},...t.adminOnly?{adminOnly:!0}:{},kind:t.kind,...c.value?{output:c.value}:{},returnType:l.value,visibility:o?.visibility==="internal"||t.visibility==="internal"?"internal":"public"}},$e=(e,i)=>{const t=Q(e,i);if(!t)return;if(t.channel)return{args:{},channel:{kind:t.channel,name:De(e)},kind:t.kind,returnType:"void",visibility:t.visibility};const{receiver:n}=t;return n?Fe(e,n,t,i):t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",...t.lifecycle==="socket"?{socket:{...Ue(e),origin:`${e.getSourceFile().getFilePath()}@${String(e.getStart())}`}}:{},visibility:t.visibility}:{args:ge(e),kind:t.kind,returnType:re(e),visibility:t.visibility}},V=e=>{const i=e?.getJsDocs().at(-1)?.getDescription().trim();return i===""?void 0:i},Ve=e=>V(e.getFirstAncestor(i=>s.isVariableStatement(i))),je=e=>{const i=new Map;for(const t of e.getVariableStatements())if(t.isExported())for(const n of t.getDeclarations())i.has(n.getName())||i.set(n.getName(),t);return t=>V(i.get(t))},j=(e,i,t,n,o)=>{const r=$e(e,n);if(!r)return;const a=o??Ve(e);return{args:r.args,...a?{description:a}:{},exportName:i,filePath:t,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},...r.meta===void 0?{}:{meta:r.meta},visibility:r.visibility,...r.adminOnly?{adminOnly:!0}:{},...r.kind==="query"&&(ne(e)===void 0||J(e))?{readsIp:!0}:{},...r.expose?{expose:r.expose}:{},...r.x402?{x402:r.x402}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{},...r.channel?{channel:r.channel}:{},...r.socket?{socket:r.socket}:{}}},Be=(e,i,t)=>{const n=[];for(const o of e.getExportAssignments()){if(o.isExportEquals())continue;const r=x(o.getExpression()),a=r?j(r,"default",i,t):void 0;r&&a&&n.push({call:r,entry:a})}return n},ze=(e,i,t)=>{const n=K(e),o=je(e),r=new Map,a=(d,u)=>{if(d?.channel?.kind!=="room")return;const m=r.get(d.channel.name);if(m!==void 0&&m!==u)throw new g("DUPLICATE_ROOM_NAME",`Duplicate room name "${d.channel.name}" in ${i}: two defineRoom calls share it. Room names must be unique.`);r.set(d.channel.name,u)},c=e.getVariableStatements().flatMap(d=>d.getDeclarations()).flatMap(d=>_e(d,u=>n.has(u))).flatMap(([d,u])=>(n.get(d)??[]).filter(m=>O(m)).flatMap(m=>{const p=j(u,m,i,t,o(m));return a(p,u),p?[p]:[]})),l=new Set(c.map(d=>d.exportName));for(const d of e.getVariableStatements().flatMap(u=>u.getDeclarations()))for(const[u,m]of Re(d,p=>n.has(p)))for(const p of(n.get(u)??[]).filter(v=>O(v)&&!l.has(v))){const v=Ie(m,p,i,o(p));v&&(c.push(v),l.add(p))}for(const{call:d,entry:u}of Be(e,i,t))l.has(u.exportName)||(a(u,d),c.push(u));return c},He=e=>{const i=new Map;for(const t of e){if(t.channel?.kind!=="room")continue;const n=i.get(t.channel.name);if(n!==void 0&&n.file!==t.filePath)throw new g("DUPLICATE_ROOM_NAME",`Duplicate room name "${t.channel.name}": defined in ${n.origin} and ${t.filePath}:${t.exportName}. Room names must be unique across the project.`);n===void 0&&i.set(t.channel.name,{file:t.filePath,origin:`${t.filePath}:${t.exportName}`})}},Me=e=>{const i=new Map;for(const t of e){const n=ie(t.filePath),o=i.get(n);if(o&&o!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${o}" and "${t.filePath}" both resolve to "${n}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[o,t.filePath],status:500});i.set(n,t.filePath)}},nt=(e,i,t={})=>{const n=M(i),o=[];for(const r of n){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=W(i,r);o.push(...ze(a,c,t.lazyFunctions===!0))}return o.sort((r,a)=>`${r.filePath}:${r.exportName}`.localeCompare(`${a.filePath}:${a.exportName}`)),Me(o),He(o),o};export{nt as d,I as i,ne as p,it as w};
|
|
1
|
+
import{LunoraError as g}from"@lunora/errors";import{Node as s,SyntaxKind as B}from"ts-morph";import{d as z}from"./declared-output-Iaar469J.mjs";import{findObjectProperty as h,bindingKeyName as H,listLunoraSourceFiles as M,lunoraRelativePath as W}from"./isTestPath-Uwb5a6Kq.mjs";import{e as K,i as O}from"./attribution-Cwt30DDJ.mjs";import{u as R,p as q,r as Y,c as w,a as G}from"./unwrap-handler-return-DvbyiLjc.mjs";import{m as J}from"./ip-reads-By7tJdyu.mjs";import{b as L,s as X,c as Q}from"./classify-procedure-call-BmEirzc_.mjs";import{r as D,p as C,a as Z}from"./parse-validator-BisfC8bR.mjs";import{N as ee,l as te}from"./project-config-file-DR7xrrNB.mjs";import{s as ie}from"./dispatch-namespace-DwTjD7BU.mjs";const I=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,ne=e=>{const i=e.getArguments()[0],t=I(i);if(t!==void 0)return t;if(i===void 0||!s.isObjectLiteralExpression(i))return;const n=h(i,"handler");return n!==void 0&&s.isPropertyAssignment(n)?I(n.getInitializer()):void 0},re=e=>{const i=e.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return"unknown";const t=h(i,"handler");if(!t||!s.isPropertyAssignment(t))return"unknown";const n=t.getInitializer();return!n||!(s.isArrowFunction(n)||s.isFunctionExpression(n))?"unknown":R(n)},oe=e=>{const i=e.getArguments()[0];return!i||!(s.isArrowFunction(i)||s.isFunctionExpression(i))?"unknown":R(i)},se=e=>{let i={};for(const t of L(e)){if(t.name!=="input")continue;const n=t.call.getArguments()[0],o=n!==void 0&&s.isExpression(n)?D(n):void 0;o!==void 0&&(i={...C(o),...i})}return i},ae=e=>{const i=L(e).find(n=>n.name==="output");if(!i)return;const t=i.call.getArguments()[0];return t&&s.isExpression(t)?q(i.call,()=>Z(t)):void 0},E=(e,i)=>{const t=h(e,i);if(t===void 0||!s.isPropertyAssignment(t))return;const n=t.getInitializer();return n!==void 0&&s.isStringLiteral(n)?n.getLiteralValue():void 0},k=(e,i)=>{const t=h(e,i);if(t===void 0||!s.isPropertyAssignment(t))return;const n=t.getInitializer();return n!==void 0&&s.isNumericLiteral(n)?n.getLiteralValue():void 0},ce=e=>{const i=h(e,"cache");if(i===void 0||!s.isPropertyAssignment(i))return;const t=i.getInitializer();if(t===void 0||!s.isObjectLiteralExpression(t))return;const n=E(t,"scope"),o=k(t,"maxAge"),r=k(t,"staleWhileRevalidate"),a=E(t,"tag"),c=E(t,"vary"),l={...o===void 0?{}:{maxAge:o},...n==="private"||n==="public"?{scope:n}:{},...r===void 0?{}:{staleWhileRevalidate:r},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},le=e=>{if(e===void 0||!s.isObjectLiteralExpression(e))return{};const i=ce(e),t=h(e,"rest");return t!==void 0&&s.isPropertyAssignment(t)?{...i===void 0?{}:{cache:i},rest:t.getInitializer()?.getText()==="true"}:i===void 0?{}:{cache:i}},ue=e=>{const i=L(e).find(t=>t.name==="expose");return i?le(i.call.getArguments()[0]):void 0},de=e=>{const i=L(e).find(r=>r.name==="x402");if(!i)return;const t=i.call.getArguments()[0];if(t===void 0||!s.isObjectLiteralExpression(t))return{};const n=h(t,"price");if(n===void 0||!s.isPropertyAssignment(n))return{};const o=n.getInitializer();return o===void 0?{}:s.isStringLiteral(o)?{price:o.getLiteralValue()}:s.isNumericLiteral(o)?{price:o.getLiteralValue()}:{}},ge=e=>{const i=e.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return{};const t=h(i,"args");if(!t||!s.isPropertyAssignment(t))return{};const n=t.getInitializer(),o=n===void 0?void 0:D(n);return o===void 0?{}:C(o)},f=(e,i)=>{throw new g("INTERNAL",`@lunora/codegen: lazy function registry needs literal ${i} in ${e.getSourceFile().getFilePath()}:${String(e.getStartLineNumber())}`)},S=(e,i,t)=>{if(!e||!s.isObjectLiteralExpression(e))return f(i,"metadata objects");const n=new Set;for(const o of e.getProperties()){if(!s.isPropertyAssignment(o))return f(o,"metadata fields without spreads, getters, or shorthand");const r=o.getNameNode(),a=s.isStringLiteral(r)?r.getLiteralValue():r.getText();if(!s.isIdentifier(r)&&!s.isStringLiteral(r)||!t.includes(a)||n.has(a))return f(o,"supported, unique metadata fields");n.add(a)}return e},y=(e,i)=>{const t=e.getProperty(i);return t&&s.isPropertyAssignment(t)?t.getInitializer():void 0},pe=e=>{const i=S(e,e,["credentialHeaders","maxAge","scope","staleWhileRevalidate","tag","vary"]),t={};for(const r of["maxAge","staleWhileRevalidate"]){const a=y(i,r);if(!(a===void 0&&r!=="maxAge")){if(!a||!s.isNumericLiteral(a))return f(e,`cache.${r}`);t[r]=a.getLiteralValue()}}const n=y(i,"scope");if(!n||!s.isStringLiteral(n)||!["private","public"].includes(n.getLiteralValue()))return f(e,"cache.scope");t.scope=n.getLiteralValue();for(const r of["tag","vary"]){const a=y(i,r);if(a!==void 0){if(!s.isStringLiteral(a))return f(a,`cache.${r}`);t[r]=a.getLiteralValue()}}const o=y(i,"credentialHeaders");if(o!==void 0){if(!s.isArrayLiteralExpression(o))return f(o,"cache.credentialHeaders");t.credentialHeaders=o.getElements().map(r=>s.isStringLiteral(r)?r.getLiteralValue():f(r,"cache.credentialHeaders string entries"))}return t},fe=e=>{const i=S(e.getArguments()[0],e,["rest","cache"]),t=y(i,"rest"),n=y(i,"cache");return t!==void 0&&!s.isTrueLiteral(t)&&!s.isFalseLiteral(t)?f(t,".expose({ rest })"):{...t?{rest:s.isTrueLiteral(t)}:{},...n?{cache:pe(n)}:{}}},me=e=>{const i=S(e.getArguments()[0],e,["price"]),t=y(i,"price");return!t||!s.isStringLiteral(t)&&!s.isNumericLiteral(t)?f(e,"`.x402({ price })` value"):{price:t.getLiteralValue()}},he=e=>{const i=e.map(o=>{const r=o.getArguments()[0];return r===void 0?ee:te(r)}),t=i.every(o=>o!==null&&typeof o=="object"&&!Array.isArray(o)),n=i.reduce((o,r)=>({...r,...o}),{});return t?n:"unloaded"},ye=e=>{const{factory:i,steps:t}=X(e);if(!i)return f(e,"metadata from a resolvable Lunora factory root");const n={visibility:i.startsWith("internal")?"internal":"public"};for(const{call:r,name:a}of t){if(!["expose","input","meta","output","use","x402"].includes(a))return f(r,`known builder modifiers, got .${a}()`);a==="expose"&&n.expose===void 0&&(n.expose=fe(r)),a==="x402"&&n.x402===void 0&&(n.x402=me(r))}const o=t.filter(r=>r.name==="meta").map(r=>r.call);return o.length===0?n:{...n,meta:he(o)}},ve=new Set(["action","mutation","query","stream"]),N=(e,i,t)=>{const n=e.getProperty(i)?.getTypeAtLocation(t);if(n===void 0)return;const o=n.isUnion()?n.getUnionTypes().filter(a=>!a.isUndefined()):[n],r=o.length===1?o[0]?.getLiteralValue():void 0;return typeof r=="string"?r:void 0},U=(e,i)=>{const t=N(e,"kind",i);return t!==void 0&&ve.has(t)&&e.getProperty("handler")!==void 0?t:void 0},be=e=>{const i=e.getParent();if(s.isPropertyAccessExpression(i)&&i.getExpression()===e)return i.getName()==="functions";if(s.isElementAccessExpression(i)&&i.getExpression()===e){const n=i.getArgumentExpression();return n!==void 0&&s.isStringLiteral(n)&&n.getLiteralValue()==="functions"}const t=s.isVariableDeclaration(i)&&i.getNameNode()!==e?i.getNameNode():void 0;return t!==void 0&&s.isObjectBindingPattern(t)&&t.getElements().some(n=>(n.getPropertyNameNode()?.getText()??n.getName())==="functions")},it=(e,i)=>{for(const t of e)for(const n of t.getVariableDeclarations()){const o=n.getNameNode();if(!n.isExported()||!s.isIdentifier(o))continue;const a=(n.getType().getProperty("functions")?.getTypeAtLocation(n)?.getProperties()??[]).filter(u=>U(u.getTypeAtLocation(n),n)!==void 0);if(a.length===0||o.findReferencesAsNodes().some(u=>be(u)))continue;const l=n.getName(),d=a.map(u=>u.getName()).join(", ");console.warn(`@lunora/codegen: ${i(t)}:${l} ships functions (${d}) that nothing re-exports, so none is in the generated api. Add \`export const { ${d} } = ${l}.functions;\` (or export your own wrappers of them).`)}},Ne=new Set(["connect","disconnect","init","reactor","whisper"]),Le={ArrayBuffer:"bytes",GeoPoint:"geoPoint"},Ae=8,P=(e,i)=>{const t=e.getText(i);return t===""?{kind:"from"}:{kind:"from",tsType:t}},Ee=new Set(["false","true"]),Pe=[[e=>e.isAny()||e.isUnknown(),"any"],[e=>e.isString(),"string"],[e=>e.isNumber(),"number"],[e=>e.isBoolean(),"boolean"],[e=>e.isNull(),"null"],[e=>e.isBigInt(),"bigint"]],Te=(e,i,t)=>{if(!e.isObject()||e.isIntersection()||e.getCallSignatures().length>0||e.isClass())return;const n=e.getProperties();if(n.some(r=>r.getTypeAtLocation(i).getCallSignatures().length>0))return;const o=e.getStringIndexType();if(o!==void 0&&n.length===0)return{keyType:{kind:"string"},kind:"record",valueType:b(o,i,t+1)};if(!(o!==void 0||n.length===0))return{kind:"object",shape:Object.fromEntries(n.map(r=>[r.getName(),$(r.getTypeAtLocation(i),r.isOptional(),i,t+1)]))}},b=(e,i,t)=>{if(t>Ae)return P(e,i);const n=Pe.find(([a])=>a(e));if(n!==void 0)return{kind:n[1]};const o=Le[(e.getSymbol()??e.getAliasSymbol())?.getName()??""];if(o!==void 0)return{kind:o};if(e.isStringLiteral()||e.isNumberLiteral()||e.isBooleanLiteral()||e.isBigIntLiteral())return{kind:"literal",literalValue:e.getText(i),sensitive:!0};const r=e.isIntersection()?N(e,"__table",i):void 0;if(r!==void 0)return{kind:"id",tableName:r};if(e.isUnion())return F(e.getUnionTypes(),i,t);if(e.isArray()){const a=e.getArrayElementType();return a===void 0?P(e,i):{inner:b(a,i,t+1),kind:"array"}}return Te(e,i,t)??P(e,i)},F=(e,i,t)=>{const o=new Set(e.filter(l=>l.isBooleanLiteral()).map(l=>l.getText(i))).size===Ee.size,r=e.filter(l=>!(o&&l.isBooleanLiteral())).map(l=>b(l,i,t+1)),a=o?[...r,{kind:"boolean"}]:r,[c]=a;return a.length===1&&c!==void 0?c:{kind:"union",members:a}},$=(e,i,t,n)=>{const o=e.isUnion()?e.getUnionTypes():[e],r=o.filter(l=>!l.isUndefined());if(!i&&r.length===o.length)return b(e,t,n);if(r.length===0)return{inner:{kind:"any"},kind:"optional"};const[a]=r;return{inner:r.length===1&&a!==void 0?b(a,t,n):F(r,t,n),kind:"optional"}},xe=(e,i)=>{const t=e.getProperty("__type")?.getTypeAtLocation(i);if(t===void 0)return{kind:"from"};const n=(e.getSymbol()??e.getAliasSymbol())?.getName();return n==="TimestampColumnValidator"?{kind:"timestamp"}:n==="ObjectColumnValidator"&&t.getProperties().length===0?{kind:"object",shape:{}}:$(t,!1,i,0)},Se=new Set(["AsyncGenerator","AsyncIterable","AsyncIterableIterator"]),Oe=(e,i)=>{const t=e.getProperty("handler")?.getTypeAtLocation(i).getCallSignatures()[0]?.getReturnType();if(t===void 0)return[];if(Se.has((t.getSymbol()??t.getAliasSymbol())?.getName()??"")){const[n]=t.getTypeArguments();return n===void 0?[]:[n]}return(t.isUnion()?t.getUnionTypes():[t]).map(n=>n.getSymbol()?.getName()==="Promise"?n.getTypeArguments()[0]??n:n)},we=(e,i)=>{const t=[...new Set(e.map(n=>Y(n,i)))];return t.length===0||t.includes("unknown")?"unknown":t.join(" | ")},Ie=(e,i,t,n)=>{const o=e.getType(),r=U(o,e);if(r===void 0)return;const a={...n?{description:n}:{},exportName:i,filePath:t,kind:r};if(o.getProperty("channel")?.isOptional()===!1)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a room from a published package; its name is not in the declared type, so codegen cannot route it. Declare the room with \`defineRoom\` in this file instead.`);const c=N(o,"lifecycle",e),l=o.getProperty("lifecycle");if(c===void 0&&l!==void 0&&!l.isOptional())throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a lifecycle hook from a published package whose type does not say which moment it runs at. Declare it with its moment, e.g. \`RegisteredLifecycleHook & { readonly lifecycle: "disconnect" }\` (what \`onDisconnect\` returns).`);if(c!==void 0){if(!Ne.has(c))throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a "${c}" lifecycle hook from a published package; only a locally declared hook can carry its route. Declare it in this file instead.`);return{...a,args:{},lifecycle:c,returnType:"void",visibility:"internal"}}const d=N(o,"visibility",e);if(d!=="internal"&&d!=="public")throw new g("PUBLISHED_FUNCTION_VISIBILITY_UNKNOWN",`${t}:${i} re-exports a function from a published package whose type does not say whether it is internal or public. Declare it in that package as \`RegisteredQuery\` / \`RegisteredMutation\` / \`RegisteredAction\` (public) or their \`RegisteredInternal*\` counterparts, not the bare \`RegisteredFunction\`, so codegen does not list an internal function in the client \`api\`.`);if(d==="internal"&&o.getProperty("visibility")?.isOptional()!==!1)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports an internal function from a published package whose type makes \`visibility\` optional, so the value may not carry it. Declare it with a \`RegisteredInternal*\` type, which requires \`visibility: "internal"\`.`);const u=o.getProperty("args")?.getTypeAtLocation(e);if(u===void 0||u.isAny()||u.isUnknown()||u.getStringIndexType()!==void 0||u.getNumberIndexType()!==void 0)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a function from a published package whose type does not list its arguments. Declare its validator map with one key per argument (an empty \`{}\` for none) so codegen can type the client call.`);const m=Object.fromEntries(u.getProperties().map(p=>[p.getName(),xe(p.getTypeAtLocation(e),e)]));return{...a,args:m,...r==="query"?{readsIp:!0}:{},returnType:we(Oe(o,e),e),typeDerivedArgs:!0,visibility:d}},ke=8,A=(e,i=0)=>{if(i>ke)return;if(s.isCallExpression(e))return{call:e};if(s.isParenthesizedExpression(e)||s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isNonNullExpression(e))return A(e.getExpression(),i+1);if(!s.isIdentifier(e)&&!s.isPropertyAccessExpression(e))return;const t=e.getSymbol()?.getValueDeclaration();return t?T(t,i+1):void 0},T=(e,i)=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e)){const t=e.getInitializer();return t?A(t,i):{deadEnd:e}}if(s.isShorthandPropertyAssignment(e)){const t=e.getValueSymbol()?.getValueDeclaration();return t?T(t,i+1):void 0}if(s.isBindingElement(e)){const t=H(e),r=e.getFirstAncestorByKind(B.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return r?T(r,i+1):void 0}return{deadEnd:e}},x=e=>{const i=A(e);return i!==void 0&&"call"in i?i.call:void 0},_=e=>{const i=A(e);return i!==void 0&&"deadEnd"in i&&i.deadEnd.getSourceFile().isDeclarationFile()},_e=(e,i=()=>!0)=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t)){const r=[];for(const a of t.getElements().filter(c=>i(c.getName()))){const c=x(a.getNameNode());c&&r.push([a.getName(),c])}return r}if(!i(e.getName()))return[];const n=e.getInitializer(),o=n&&(s.isCallExpression(n)?n:x(n));return o?[[e.getName(),o]]:[]},Re=(e,i)=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t))return t.getElements().filter(o=>i(o.getName())&&_(o.getNameNode())).map(o=>[o.getName(),o.getNameNode()]);const n=e.getInitializer();return i(e.getName())&&n!==void 0&&_(n)?[[e.getName(),t]]:[]},De=e=>{const i=e.getArguments()[0],t=s.isObjectLiteralExpression(i)?i.getProperty("name"):void 0,n=s.isPropertyAssignment(t)?t.getInitializer():void 0;if(!n||!s.isStringLiteral(n))throw new g("ROOM_NAME_NOT_LITERAL",'defineRoom needs a string-literal `name` (e.g. `defineRoom({ name: "chat", … })`) so codegen can type its reference.');return n.getLiteralValue()},Ce=e=>e.startsWith("/")&&new URL(e,"https://lunora.invalid").pathname===e&&e!=="/_lunora"&&!e.startsWith("/_lunora/"),Ue=e=>{const i=e.getArguments()[0];if(!s.isObjectLiteralExpression(i))throw new g("SOCKET_PATH_NOT_LITERAL","defineWebSocket needs an object-literal options argument so codegen can read its `path` and `auth`.");const t=i.getProperty("path"),n=s.isPropertyAssignment(t)?t.getInitializer():void 0;if(!n||!s.isStringLiteral(n))throw new g("SOCKET_PATH_NOT_LITERAL",'defineWebSocket needs a string-literal `path` (e.g. `defineWebSocket({ path: "/chat", … })`) so codegen can route its upgrade.');const o=n.getLiteralValue();if(!Ce(o))throw new g("SOCKET_PATH_INVALID",`defineWebSocket path "${o}" must be a plain URL path starting with "/" (no "?", "#", ".." or unencoded characters) and not under "/_lunora".`);if(i.getProperties().some(l=>s.isSpreadAssignment(l)||s.isPropertyAssignment(l)&&s.isComputedPropertyName(l.getNameNode())))throw new g("SOCKET_AUTH_NOT_LITERAL","defineWebSocket cannot spread its options or use a computed key: codegen must read `auth` as a literal `auth: true` or `auth: false`.");const a=i.getProperty("auth");if(a===void 0)return{auth:!1,path:o};const c=s.isPropertyAssignment(a)?a.getInitializer():void 0;if(c===void 0||!(s.isTrueLiteral(c)||s.isFalseLiteral(c)))throw new g("SOCKET_AUTH_NOT_LITERAL","defineWebSocket needs a literal `auth: true` or `auth: false`, so codegen can read whether the route requires a session. A shorthand or a variable is not read.");return{auth:s.isTrueLiteral(c),path:o}},Fe=(e,i,t,n)=>{const o=n?ye(i):void 0,r=n?o?.expose:ue(i),a=n?o?.x402:de(i),c=w(()=>ae(i)),l=w(()=>oe(e)),d=z({kind:t.kind,output:c.value});return G(d?c.erased:l.erased),{args:se(i),...r?{expose:r}:{},...a?{x402:a}:{},...o?.meta===void 0?{}:{meta:o.meta},...t.adminOnly?{adminOnly:!0}:{},kind:t.kind,...c.value?{output:c.value}:{},returnType:l.value,visibility:o?.visibility==="internal"||t.visibility==="internal"?"internal":"public"}},$e=(e,i)=>{const t=Q(e,i);if(!t)return;if(t.channel)return{args:{},channel:{kind:t.channel,name:De(e)},kind:t.kind,returnType:"void",visibility:t.visibility};const{receiver:n}=t;return n?Fe(e,n,t,i):t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",...t.lifecycle==="socket"?{socket:{...Ue(e),origin:`${e.getSourceFile().getFilePath()}@${String(e.getStart())}`}}:{},visibility:t.visibility}:{args:ge(e),kind:t.kind,returnType:re(e),visibility:t.visibility}},V=e=>{const i=e?.getJsDocs().at(-1)?.getDescription().trim();return i===""?void 0:i},Ve=e=>V(e.getFirstAncestor(i=>s.isVariableStatement(i))),je=e=>{const i=new Map;for(const t of e.getVariableStatements())if(t.isExported())for(const n of t.getDeclarations())i.has(n.getName())||i.set(n.getName(),t);return t=>V(i.get(t))},j=(e,i,t,n,o)=>{const r=$e(e,n);if(!r)return;const a=o??Ve(e);return{args:r.args,...a?{description:a}:{},exportName:i,filePath:t,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},...r.meta===void 0?{}:{meta:r.meta},visibility:r.visibility,...r.adminOnly?{adminOnly:!0}:{},...r.kind==="query"&&(ne(e)===void 0||J(e))?{readsIp:!0}:{},...r.expose?{expose:r.expose}:{},...r.x402?{x402:r.x402}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{},...r.channel?{channel:r.channel}:{},...r.socket?{socket:r.socket}:{}}},Be=(e,i,t)=>{const n=[];for(const o of e.getExportAssignments()){if(o.isExportEquals())continue;const r=x(o.getExpression()),a=r?j(r,"default",i,t):void 0;r&&a&&n.push({call:r,entry:a})}return n},ze=(e,i,t)=>{const n=K(e),o=je(e),r=new Map,a=(d,u)=>{if(d?.channel?.kind!=="room")return;const m=r.get(d.channel.name);if(m!==void 0&&m!==u)throw new g("DUPLICATE_ROOM_NAME",`Duplicate room name "${d.channel.name}" in ${i}: two defineRoom calls share it. Room names must be unique.`);r.set(d.channel.name,u)},c=e.getVariableStatements().flatMap(d=>d.getDeclarations()).flatMap(d=>_e(d,u=>n.has(u))).flatMap(([d,u])=>(n.get(d)??[]).filter(m=>O(m)).flatMap(m=>{const p=j(u,m,i,t,o(m));return a(p,u),p?[p]:[]})),l=new Set(c.map(d=>d.exportName));for(const d of e.getVariableStatements().flatMap(u=>u.getDeclarations()))for(const[u,m]of Re(d,p=>n.has(p)))for(const p of(n.get(u)??[]).filter(v=>O(v)&&!l.has(v))){const v=Ie(m,p,i,o(p));v&&(c.push(v),l.add(p))}for(const{call:d,entry:u}of Be(e,i,t))l.has(u.exportName)||(a(u,d),c.push(u));return c},He=e=>{const i=new Map;for(const t of e){if(t.channel?.kind!=="room")continue;const n=i.get(t.channel.name);if(n!==void 0&&n.file!==t.filePath)throw new g("DUPLICATE_ROOM_NAME",`Duplicate room name "${t.channel.name}": defined in ${n.origin} and ${t.filePath}:${t.exportName}. Room names must be unique across the project.`);n===void 0&&i.set(t.channel.name,{file:t.filePath,origin:`${t.filePath}:${t.exportName}`})}},Me=e=>{const i=new Map;for(const t of e){const n=ie(t.filePath),o=i.get(n);if(o&&o!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${o}" and "${t.filePath}" both resolve to "${n}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[o,t.filePath],status:500});i.set(n,t.filePath)}},nt=(e,i,t={})=>{const n=M(i),o=[];for(const r of n){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=W(i,r);o.push(...ze(a,c,t.lazyFunctions===!0))}return o.sort((r,a)=>`${r.filePath}:${r.exportName}`.localeCompare(`${a.filePath}:${a.exportName}`)),Me(o),He(o),o};export{nt as d,I as i,ne as p,it as w};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as n,SyntaxKind as d,VariableDeclarationKind as we}from"ts-morph";import{isConstDeclaration as K,unwrapExpression as l,descendantsOfKind as Be,bindingKeyName as ue,findObjectProperty as Fe}from"./isTestPath-Uwb5a6Kq.mjs";import{r as Ce,b as V,d as p}from"./attribution-Cwt30DDJ.mjs";import{i as ae,r as j,c as m,a as Le}from"./context-root-BpDEhvNE.mjs";import{a as M,s as Z}from"./property-name-7cBlgK_O.mjs";const Re=e=>{const t=e.getText(),s=i=>{const r=i.getNameNode();return n.isIdentifier(r)&&r.getText()===t};for(const i of e.getAncestors())if(!(!n.isArrowFunction(i)&&!n.isFunctionExpression(i)&&!n.isFunctionDeclaration(i)))for(const r of i.getParameters()){const o=r.getDescendantsOfKind(d.BindingElement).find(a=>s(a));if(o!==void 0)return o}},ze=e=>{let t=e;for(;;){const s=t.getParent();if(!n.isObjectBindingPattern(s))return;const i=s.getParent();if(n.isBindingElement(i)){t=i;continue}return n.isParameterDeclaration(i)?ue(t):void 0}},ke=e=>{const t=e.getText();if(!e.getAncestors().some(o=>{const a=n.isFunctionLikeDeclaration(o)||n.isArrowFunction(o)?o.getParameters()[1]:void 0,c=a?.getNameNode();return a!==void 0&&(n.isIdentifier(c)?c.getText()===t:a.getDescendantsOfKind(d.BindingElement).some(u=>u.getName()===t))&&ae(a)}))return!1;const i=p(e),r=n.isParameterDeclaration(i)?i:i?.getFirstAncestorByKind(d.Parameter);return r!==void 0&&(n.isParameterDeclaration(i)||n.isBindingElement(i))&&ae(r)},ce=(e,t)=>{const s=e.getParent();if(n.isPropertyAccessExpression(s)&&s.getNameNode()===e||n.isPropertyAssignment(s)&&s.getNameNode()===e)return!1;if(e.getText()===t)return!0;const i=Re(e);return i!==void 0&&ze(i)===t?!0:t==="args"&&ke(e)},L=(e,t)=>n.isIdentifier(e)?ce(e,t):e.getDescendantsOfKind(d.Identifier).some(s=>ce(s,t)),Ke=e=>{let t=e;for(;n.isPropertyAccessExpression(t)||n.isElementAccessExpression(t)||n.isNonNullExpression(t);)t=t.getExpression();return n.isIdentifier(t)?t:void 0},f=e=>{const t=n.isIdentifier(e)?p(e):void 0;return n.isVariableDeclaration(t)&&n.isIdentifier(t.getNameNode())&&!V(t)?t.getInitializer():void 0},Ve=(e,t)=>{const s=e.getParent();if(n.isVariableDeclarationList(s)&&s.getDeclarationKind()===we.Var)return t;const i=s.getParent();return n.isVariableStatement(i)?i.getParent():i},Me=(e,t)=>{const s=e.getNameNode();return n.isIdentifier(s)?s.getText()===t:s.getDescendantsOfKind(d.BindingElement).some(i=>{const r=i.getNameNode();return n.isIdentifier(r)&&r.getText()===t})},J=e=>e.getDescendantsOfKind(d.Identifier).filter(t=>{const s=t.getParent();return!(n.isPropertyAccessExpression(s)&&s.getNameNode()===t)&&!(n.isPropertyAssignment(s)&&s.getNameNode()===t)}),O=e=>n.isIdentifier(e)?[e]:J(e),T=e=>{let t=e;for(;;){const s=t.getParent();if(!((n.isPropertyAccessExpression(s)||n.isElementAccessExpression(s)||n.isNonNullExpression(s))&&s.getExpression()===t))return t;t=s}},We=e=>{const t=e.getParent();return n.isCallExpression(t)&&t.getExpression()===e?t:void 0},_e=new Set(["find","findFirst","findFirstOrThrow","findMany","findUnique","first","get","unique"]),U=new Set(["findFirst","findUnique","first","get","unique"]),W=e=>{const t=e.getExpression();return n.isPropertyAccessExpression(t)&&_e.has(t.getName())&&m(t)?.[0]==="db"},I=(e,t)=>{for(let s=e,i=e.getParent();i!==void 0&&s!==t;s=i,i=i.getParent()){if(n.isConditionalExpression(i))return!0;if(n.isBinaryExpression(i)){const r=i.getOperatorToken().getKind();if(s===i.getRight()&&(r===d.QuestionQuestionToken||r===d.BarBarToken)||s===i.getLeft()&&r===d.AmpersandAmpersandToken)return!0}}return!1},ge=e=>O(e).some(t=>{if(I(t,e))return!1;if(m(T(t))?.[0]==="auth")return!0;const s=f(t);return s!==void 0&&O(s).some(i=>m(T(i))?.[0]==="auth"&&!I(i,s))}),je=e=>W(e)&&e.getArguments().some(t=>ge(t)),fe=(e,t)=>{for(let s=e.getParent();s!==void 0;s=s.getParent()){if(n.isCallExpression(s)&&m(s.getExpression())?.[0]==="db")return!0;if(s===t)return!1}return!1},qe=new Set(["_id","id"]),X=e=>{let t=e;for(let s=t.getParent();;s=t.getParent()){if(n.isAwaitExpression(s)||n.isParenthesizedExpression(s)||n.isNonNullExpression(s)||n.isAsExpression(s)||n.isSatisfiesExpression(s)||n.isTypeAssertion(s)){t=s;continue}if(n.isPropertyAccessExpression(s)&&s.getExpression()===t)return{field:s.getName(),read:s};if(n.isElementAccessExpression(s)&&s.getExpression()===t){const i=l(s.getArgumentExpression());return{field:n.isStringLiteral(i)||n.isNoSubstitutionTemplateLiteral(i)?i.getLiteralValue():void 0,read:s}}return{field:void 0,read:t}}},$="userId",y=e=>{let t=e;for(;;){const s=n.isNonNullExpression(t)||n.isAwaitExpression(t)?t.getExpression():l(t);if(s===void 0||s===t)return t;t=s}},G=e=>{const t=m(y(e));return t?.length===2&&t[0]==="auth"&&t[1]===$},ee=e=>n.isPropertyAssignment(e)?e.getInitializer():n.isShorthandPropertyAssignment(e)?e.getNameNode():void 0,b=e=>{let t=e;for(let s=t.getParent();;s=t.getParent()){if(!(n.isParenthesizedExpression(s)||n.isNonNullExpression(s)||n.isAsExpression(s)||n.isSatisfiesExpression(s)||n.isTypeAssertion(s)))return t;t=s}},pe=e=>{const t=p(e);return e.getSourceFile().getDescendantsOfKind(d.Identifier).filter(s=>s.getText()===e.getText()&&p(s)===t).filter(s=>{const i=s.getParent();return!((n.isVariableDeclaration(i)||n.isBindingElement(i))&&i.getNameNode()===s)})},le=e=>{const t=b(e).getParent();return n.isCallExpression(t)&&W(t)&&t.getArguments().includes(b(e))},Ue=e=>pe(e).every(t=>{if(le(t))return!0;const s=b(t),i=s.getParent(),r=i?.getParent();return(n.isPropertyAssignment(i)&&i.getNameNode()!==s&&M(i)==="where"||n.isShorthandPropertyAssignment(i)&&i.getName()==="where")&&r!==void 0&&le(r)}),R=e=>{const t=l(e);if(n.isObjectLiteralExpression(t))return t;const s=n.isIdentifier(t)&&Ue(t)?l(f(t)):void 0;return n.isObjectLiteralExpression(s)?s:void 0},Ge=e=>{const t=l(e)??e;if(!n.isObjectLiteralExpression(t))return G(e);const[s,...i]=t.getProperties(),r=i.length===0&&n.isPropertyAssignment(s)&&M(s)==="eq"?s.getInitializer():void 0;return r!==void 0&&G(r)},te=(e,t)=>{const s=e.getProperties(),i=n.isSpreadAssignment(t)?void 0:M(t);return s.slice(s.indexOf(t)+1).some(r=>{if(n.isSpreadAssignment(r))return!0;const o=Z(r.getNameNode());return o===void 0||o===i})},se=e=>e.getProperties().some(t=>n.isGetAccessorDeclaration(t)||n.isSetAccessorDeclaration(t)||n.isMethodDeclaration(t)),me=(e,t)=>!se(e)&&e.getProperties().some(s=>{const i=ee(s);if(i===void 0||n.isSpreadAssignment(s)||te(e,s))return!1;const r=Z(s.getNameNode());if(r===void 0)return!1;if(r==="AND"){const o=l(i);return n.isArrayLiteralExpression(o)&&o.getElements().some(a=>{const c=R(a);return c!==void 0&&me(c,t)})}return(t===void 0||r===t)&&Ge(i)}),Ee=(e,t)=>{const s=R(e),i=s===void 0?void 0:Fe(s,"where"),r=s===void 0||i===void 0||se(s)||te(s,i)?void 0:R(ee(i));return r!==void 0&&me(r,t)},ve=e=>e.getArguments().some(t=>G(t)||Ee(t,void 0)),He=(e,t)=>t===void 0?!1:qe.has(t)?ve(e):e.getArguments().some(s=>Ee(s,t)),Qe=new Set(["_creationTime","_id"]),Ye=(e,t)=>Qe.has(t)||e.getArguments().every(s=>{const i=R(s);if(i===void 0)return!0;const r=i.getProperties(),o=r.findLast(c=>!n.isSpreadAssignment(c)&&M(c)==="select");if(se(i))return!1;if(o===void 0)return!r.some(c=>n.isSpreadAssignment(c)||Z(c.getNameNode())===void 0);if(te(i,o))return!1;const a=l(ee(o));return n.isArrayLiteralExpression(a)&&a.getElements().some(c=>(n.isStringLiteral(c)||n.isNoSubstitutionTemplateLiteral(c))&&c.getLiteralValue()===t)}),w=(e,t,s,i)=>{const r=e.getExpression(),o=n.isPropertyAccessExpression(r)&&(U.has(r.getName())||r.getName().endsWith("OrThrow"));return!je(e)||!o||s!==void 0&&!Ye(e,s)?!1:i!==void 0&&l(t)===l(i)&&ve(e)||He(e,s)},ie=(e,t)=>{const s=t.getExpression(),i=n.isPropertyAccessExpression(s)&&s.getName().endsWith("OrThrow");return(n.isPropertyAccessExpression(e)||n.isElementAccessExpression(e))&&e.hasQuestionDotToken()&&!i},xe=(e,t)=>O(e).some(s=>{const i=T(s),r=m(i)?.[0];if(r==="auth")return!I(s,e)&&!fe(s,e);const o=r==="db"&&!I(s,e)?We(i):void 0;if(o===void 0)return!1;const{field:a,read:c}=X(o);return!ie(c,o)&&w(o,c,a,t)}),H=e=>n.isArrowFunction(e)||n.isFunctionExpression(e)||n.isFunctionDeclaration(e)||n.isMethodDeclaration(e),Q=e=>{const t=e.getFirstAncestor(s=>H(s));return H(t)?t:void 0},Ze=e=>{const t=l(e);return n.isAwaitExpression(t)?l(t.getExpression()):t},D=e=>{const t=[];let s=l(e);for(;s!==void 0;)if(n.isPropertyAccessExpression(s))t.unshift(s.getName()),s=l(s.getExpression());else if(n.isElementAccessExpression(s)){const i=s.getArgumentExpression();if(!n.isStringLiteral(i))return;t.unshift(i.getLiteralValue()),s=l(s.getExpression())}else return n.isIdentifier(s)?{path:t,root:s}:void 0},E=(e,t)=>p(e)?.compilerNode===t.compilerNode,Ae=e=>{if(!n.isIdentifier(e))return;const t=Ce(e),s=t?.isAlias()===!0?t.getAliasedSymbol():t,i=s?.getValueDeclaration()??s?.getDeclarations()[0];if(i===void 0)return;const r=i.getSourceFile();if(r.isDeclarationFile()||r.isInNodeModules())return;if(n.isFunctionDeclaration(i))return i.getBody()===void 0||i.isGenerator()||V(i)?void 0:i;if(!K(i))return;const o=l(i.getInitializer());return n.isArrowFunction(o)||n.isFunctionExpression(o)&&!o.isGenerator()?o:void 0},Je=e=>e>=d.FirstAssignment&&e<=d.LastAssignment,ne=e=>{const t=[],s=[];let i=l(e);for(;i!==void 0;)if(n.isCallExpression(i))t.push(i),i=l(i.getExpression());else if(n.isPropertyAccessExpression(i))s.unshift(i.getName()),i=l(i.getExpression());else if(n.isElementAccessExpression(i)){const r=i.getArgumentExpression();if(!n.isStringLiteral(r))return;s.unshift(r.getLiteralValue()),i=l(i.getExpression())}else return n.isIdentifier(i)&&t.length>0&&s.length>0?{calls:t,names:s,root:i}:void 0},re=e=>{const t=e.names[e.names.length-1]??"";if(U.has(t))return{selfEnforcing:!1};const s=t.endsWith("OrThrow")?t.slice(0,-7):void 0;return s!==void 0&&U.has(s)?{selfEnforcing:!0}:void 0},Xe=e=>{const t=l(e),s=n.isIdentifier(t)?l(f(t))??t:t,i=D(s);if(i===void 0||i.path.length===0)return;const r=p(i.root);if(!K(r)||!n.isIdentifier(r.getNameNode()))return;const o=Ze(r.getInitializer()),a=n.isCallExpression(o)&&m(o.getExpression())?.[0]==="db"?ne(o):void 0;return a!==void 0&&re(a)!==void 0?r:void 0},Ne=e=>e.calls.flatMap(t=>t.getArguments().flatMap(s=>[s,...s.getDescendants()])),$e=(e,t)=>{const s=n.isIdentifier(e)?p(e):void 0;if(!n.isBindingElement(s)||s.getDotDotDotToken()!==void 0||s.getInitializer()!==void 0)return!1;const i=s.getParent(),r=n.isObjectBindingPattern(i)?i.getParent():void 0;if(!K(r))return!1;const o=D(r.getInitializer());return o?.path[0]==="auth"&&E(o.root,t)},et=(e,t)=>{const s=D(e);if(s!==void 0&&s.path.length>0)return s.path[0]==="auth"&&E(s.root,t);const i=D(f(e));return i?.path[0]==="auth"&&E(i.root,t)?!0:$e(e,t)},Pe=e=>{if(!n.isVariableStatement(e))return;const t=e.getDeclarations(),s=t.length===1?t[0]:void 0;return s!==void 0&&K(s)&&n.isIdentifier(s.getNameNode())?s:void 0},tt=(e,t)=>{const s=l(e),i=a=>n.isIdentifier(a)&&E(a,t);if(n.isPrefixUnaryExpression(s))return s.getOperatorToken()===d.ExclamationToken&&i(l(s.getOperand()));if(!n.isBinaryExpression(s)||s.getOperatorToken().getKind()!==d.EqualsEqualsToken)return!1;const r=l(s.getLeft()),o=l(s.getRight());return i(r)&&n.isNullLiteral(o)||i(o)&&n.isNullLiteral(r)},st=(e,t)=>{const s=n.isBlock(e)?e.getStatements():void 0,i=s===void 0?e:s[s.length-1];return n.isThrowStatement(i)||!t&&n.isReturnStatement(i)},he=(e,t,s)=>n.isIfStatement(e)&&e.getElseStatement()===void 0&&tt(e.getExpression(),t)&&st(e.getThenStatement(),s),it=(e,t,s)=>{const i=e.getBody();if(!n.isBlock(i))return!1;const r=i.getStatements();return r.some((o,a)=>{const c=Pe(o),u=l(c?.getInitializer()),g=n.isAwaitExpression(u)?ne(u.getExpression()):void 0,A=g===void 0?void 0:re(g);if(c===void 0||g===void 0||A===void 0||g.names[0]!=="db"||!E(g.root,t))return!1;const v=Ne(g),P=v.some(x=>et(x,t)),F=s.some(x=>v.some(oe=>n.isIdentifier(oe)&&E(oe,x)));if(!P||!F)return!1;const h=A.selfEnforcing?o:r.slice(a+1).find(x=>he(x,c,!0));return h!==void 0&&!e.getDescendantsOfKind(d.ReturnStatement).some(x=>Q(x)?.compilerNode===e.compilerNode&&x.getStart()<h.getEnd())})},nt=(e,t,s)=>{const i=Ae(e.getExpression()),r=e.getArguments();if(i===void 0||r.some(v=>n.isSpreadElement(v)))return!1;const o=r.flatMap((v,P)=>m(v)?.length===0?[P]:[]),a=o.length===1?o[0]:void 0,c=a===void 0?void 0:i.getParameters()[a];if(a===void 0||c===void 0||c.isRestParameter()||!n.isIdentifier(c.getNameNode()))return!1;const u=[];r.forEach((v,P)=>{const F=D(l(v)),h=P===a||F===void 0||!E(F.root,t)?void 0:i.getParameters()[P];h!==void 0&&n.isIdentifier(h.getNameNode())&&u.push(h)});const g=i.getReturnType(),A=i.isAsync()||g.isAny()||g.isUnknown()||g.getText().includes("Promise");return u.length===0||!s&&A?!1:it(i,c,u)},rt=(e,t)=>{const s=Pe(e),i=l(s?.getInitializer()),r=n.isAwaitExpression(i)?ne(i.getExpression()):void 0,o=r===void 0?void 0:re(r);if(s===void 0||r===void 0||o===void 0||r.names[0]!=="db"||m(r.root)?.length!==0)return;const a=r.calls.some(u=>u.getArguments().some(g=>ge(g))),c=Ne(r).some(u=>n.isIdentifier(u)&&E(u,t));return a&&c?{declaration:s,selfEnforcing:o.selfEnforcing}:void 0},ot=(e,t,s)=>{const i=(r,o)=>o.getStart()<=r.getStart()&&r.getEnd()<=o.getEnd();for(let r=e.getParent();r!==void 0&&r.compilerNode!==t.compilerNode;r=r.getParent()){if(H(r)||n.isIfStatement(r)||n.isIterationStatement(r)||n.isCaseClause(r)||n.isDefaultClause(r)||n.isCatchClause(r))return!1;if(n.isTryStatement(r)&&r.getCatchClause()!==void 0){const o=r.getTryBlock();if(!i(e,o)||!i(s,o))return!1}}return!0},at=(e,t,s,i,r)=>e.slice(0,t).some((o,a)=>{if(!ot(o,i,r))return!1;if(n.isExpressionStatement(o)){const u=l(o.getExpression()),g=n.isAwaitExpression(u),A=g?l(u.getExpression()):u;if(n.isCallExpression(A)&&nt(A,s,g))return!0}const c=rt(o,s);return c!==void 0&&(c.selfEnforcing||a+1<t&&he(e[a+1],c.declaration,!1))}),_=e=>{let t=l(e)??e;for(;n.isAwaitExpression(t);)t=l(t.getExpression())??t.getExpression();return t},C=e=>{const t=_(e);return n.isCallExpression(t)||n.isNewExpression(t)},ct=e=>{const t=_(e);return n.isCallExpression(t)&&m(t.getExpression())?.[0]==="db"},Ie=e=>{const t=_(e);return n.isCallExpression(t)&&W(t)},ye=e=>L(e,"args")||O(e).some(t=>{const s=f(t);return s!==void 0&&L(s,"args")}),z=(e,t)=>{const s=e?.getNameNode().getDescendantsOfKind(d.BindingElement).find(i=>n.isIdentifier(i.getNameNode())&&i.getNameNode().getText()===t);return s===void 0?[]:[s,...s.getAncestors().filter(i=>n.isBindingElement(i))].map(i=>n.isBindingElement(i)?i.getInitializer():void 0).filter(i=>i!==void 0)},De=e=>{const t=n.isIdentifier(e)?p(e):void 0;if(!n.isBindingElement(t)||V(t))return;const s=t.getFirstAncestorByKind(d.VariableDeclaration),i=s?.getInitializer();if(!z(s,e.getText()).some(r=>ye(r)))return i!==void 0&&Ie(i)?i:void 0},B=e=>{const t=_(e);return n.isCallExpression(t)&&W(t)?t:void 0},Se=e=>{if(!(!n.isBindingElement(e)||!n.isObjectBindingPattern(e.getParent())||e.getDotDotDotToken()!==void 0||n.isBindingElement(e.getParent().getParent())))return ue(e)},lt=e=>{let t=e,s=t.getParent();for(;n.isParenthesizedExpression(s)||n.isArrayLiteralExpression(s)||n.isObjectLiteralExpression(s)||n.isSpreadElement(s)||n.isSpreadAssignment(s)||n.isShorthandPropertyAssignment(s)||n.isPropertyAssignment(s)&&s.getNameNode()!==t;)t=s,s=t.getParent();if(n.isBinaryExpression(s)){const i=s.getOperatorToken().getKind();return s.getLeft()===t&&i>=d.FirstAssignment&&i<=d.LastAssignment}if(n.isForOfStatement(s)||n.isForInStatement(s))return s.getInitializer()===t;if(n.isPrefixUnaryExpression(s)||n.isPostfixUnaryExpression(s)){const i=s.getOperatorToken();return i===d.PlusPlusToken||i===d.MinusMinusToken}return n.isDeleteExpression(s)},Oe=e=>pe(e).every(t=>{const s=b(t),i=s.getParent();return n.isVariableDeclaration(i)&&n.isObjectBindingPattern(i.getNameNode())||n.isSpreadAssignment(i)?!0:(n.isPropertyAccessExpression(i)||n.isElementAccessExpression(i))&&i.getExpression()===s&&!lt(b(T(i)))}),de=(e,t)=>{const s=t!==void 0&&l(e)===l(t),i=f(e);if(i!==void 0){const a=B(i);if(a===void 0)return xe(i,s?i:void 0);if(n.isIdentifier(e)&&!Oe(e))return!1;const{field:c,read:u}=X(e);return ie(u,a)?!1:w(a,u,c,t)}const r=De(e),o=r===void 0?void 0:B(r);return o!==void 0&&n.isIdentifier(e)&&w(o,e,Se(p(e)),t)},S=(e,t=!0)=>{const s=y(e);if(n.isTemplateExpression(s))return s.getTemplateSpans().flatMap(o=>S(o.getExpression(),t));if(n.isBinaryExpression(s)&&s.getOperatorToken().getKind()===d.PlusToken)return[...S(s.getLeft(),t),...S(s.getRight(),t)];const i=t&&n.isIdentifier(s)?f(s):void 0,r=i===void 0?void 0:y(i);return r!==void 0&&(n.isTemplateExpression(r)||n.isBinaryExpression(r)&&r.getOperatorToken().getKind()===d.PlusToken)?S(r,!1):[s]},dt=e=>n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)||n.isNumericLiteral(e),ut=e=>{const t=y(e.getExpression()),s=n.isIdentifier(t)?f(t):void 0;if(n.isIdentifier(t)&&s!==void 0&&!Oe(t))return!1;const i=B(t)??(s===void 0?void 0:B(s));return i!==void 0&&!ie(e,i)&&w(i,e,X(e.getExpression()).field,void 0)},gt=e=>{const t=p(e),s=Se(t),i=n.isBindingElement(t)?t.getFirstAncestorByKind(d.VariableDeclaration)?.getInitializer():void 0,r=i===void 0?void 0:m(y(i));if(r!==void 0)return r.length===1&&r[0]==="auth"&&s===$;const o=De(e),a=o===void 0?void 0:B(o);return a!==void 0&&w(a,e,s,void 0)},Te=(e,t=!0)=>{const s=y(e),i=n.isIdentifier(s)?p(s):void 0;if((n.isVariableDeclaration(i)||n.isBindingElement(i))&&V(i))return!1;const r=m(s);if(r!==void 0)return r.length===2&&r[0]==="auth"&&r[1]===$;if(n.isPropertyAccessExpression(s)||n.isElementAccessExpression(s))return ut(s);if(!n.isIdentifier(s))return!1;const o=f(s);return o===void 0?gt(s):t&&Te(o,!1)},ft=(e,t)=>{const s=S(t),i=s.findIndex(a=>!dt(a)),r=s.findIndex(a=>a.getPos()<=e.getPos()&&e.getEnd()<=a.getEnd()),o=s[i];return o!==void 0&&i<r&&Te(o)},N=e=>L(e,"args"),k=e=>{if(!n.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>n.isArrowFunction(a)||n.isFunctionExpression(a)||n.isFunctionDeclaration(a));if(s===void 0)return;const i=e.getStart();let r,o=-1;for(const a of Be(s,d.VariableDeclaration)){if(!Me(a,t))continue;const c=Ve(a,s);if(c===void 0||i<c.getStart()||i>=c.getEnd())continue;const u=a.getInitializer(),g=a.getStart();u!==void 0&&g<i&&g>o&&(r=a,o=g)}return r},Y=e=>k(e)?.getInitializer(),wt=e=>{if(N(e))return!0;const t=s=>{const i=k(s),r=i?.getInitializer();return r!==void 0&&N(r)||z(i,s.getText()).some(o=>N(o))};return t(e)||J(e).some(s=>t(s))},Bt=e=>{if(C(e))return!1;if(z(k(e),e.getText()).some(i=>N(i)&&!C(i)))return!0;const t=Y(e);if(t!==void 0&&C(t)&&!(Ie(t)&&N(t)))return!1;const s=t??e;return N(s)?!0:J(s).some(i=>{if(i.getFirstAncestor(c=>c===s||n.isCallExpression(c)||n.isNewExpression(c))!==s)return!1;const o=k(i),a=c=>c!==void 0&&N(c)&&(!C(c)||ct(c));return a(o?.getInitializer())||z(o,i.getText()).some(c=>a(c))})},Ft=e=>{if(j(e))return!0;const t=f(e);if(t!==void 0&&j(t))return!0;const s=t??e;return(n.isIdentifier(s)?[s]:s.getDescendantsOfKind(d.Identifier)).some(r=>{const o=f(r);return o!==void 0&&j(o)})},Ct=e=>{const t=f(e)??e;if(O(t).some(r=>I(r,t)&&ye(T(r))&&!ft(r,t)))return!1;if(xe(e,e)||de(e,e))return!0;const s=f(e)??e;return(n.isIdentifier(s)?[s]:s.getDescendantsOfKind(d.Identifier)).some(r=>!I(r,s)&&!fe(r,s)&&de(r,s))},q=(e,t)=>L(e,t),Lt=(e,t)=>{if(q(e,t))return!0;const s=Y(e);if(s!==void 0&&q(s,t))return!0;const i=Ke(e);if(i!==void 0){const r=Y(i);return r!==void 0&&q(r,t)}return!1},Rt=(e,t)=>{const s=Q(e),i=Xe(t);if(s===void 0||i===void 0||Q(i)?.compilerNode!==s.compilerNode||s.getDescendantsOfKind(d.BinaryExpression).some(c=>{const u=D(c.getLeft());return Je(c.getOperatorToken().getKind())&&u!==void 0&&E(u.root,i)}))return!1;let o=e,a=e.getParent();for(;a!==void 0&&a.compilerNode!==s.compilerNode;){if(n.isBlock(a)){const c=a.getStatements(),u=c.findIndex(g=>g.compilerNode===o.compilerNode);if(u>0&&at(c,u,i,s,e))return!0}o=a,a=a.getParent()}return!1},pt=/rate|limit|\bip\b|geo|throttle/iu,mt=/^run[A-Z]/u,Et=e=>n.isIdentifier(e)?(e.getSymbol()?.getDeclarations()??[]).some(s=>s.getFirstAncestorByKind(d.ImportDeclaration)?.getModuleSpecifierValue().startsWith("@lunora/")===!0):!1,vt=e=>{const t=n.isCallExpression(e)?e.getExpression():e;let s;return n.isIdentifier(t)?s=t:n.isPropertyAccessExpression(t)&&(s=t.getNameNode()),s!==void 0&&Et(n.isPropertyAccessExpression(t)?t.getExpression():s)&&!pt.test(s.getText())},xt=e=>{const t=n.isCallExpression(e)?e.getExpression():void 0;if(n.isElementAccessExpression(t)){const s=t.getArgumentExpression();return(n.isStringLiteral(s)||n.isNoSubstitutionTemplateLiteral(s))&&s.getLiteralText()==="use"}return n.isPropertyAccessExpression(t)&&t.getName()==="use"},At=e=>{const t=e.getParent();return n.isPropertyAccessExpression(t)&&t.getExpression()===e?!mt.test(t.getName()):n.isElementAccessExpression(t)&&t.getExpression()===e?n.isStringLiteral(t.getArgumentExpression())||n.isNoSubstitutionTemplateLiteral(t.getArgumentExpression()):n.isVariableDeclaration(t)&&t.getInitializer()?.getText()===e.getText()},Nt=e=>{if(n.isPropertyAccessExpression(e))return e.getName()==="ip";if(n.isElementAccessExpression(e)){const t=e.getArgumentExpression();return(n.isStringLiteral(t)||n.isNoSubstitutionTemplateLiteral(t))&&t.getLiteralText()==="ip"}return n.isBindingElement(e)?e.getDotDotDotToken()!==void 0||(e.getPropertyNameNode()?.getText()??e.getName())==="ip":n.isShorthandPropertyAssignment(e)&&e.getName()==="ip"},Pt=(e,t)=>{const s=e.getParent();if(!n.isCallExpression(s)||s.getExpression()===e)return!1;const i=s.getArguments().indexOf(e),r=Ae(s.getExpression()),o=i===-1||r===void 0?void 0:r.getParameters()[i];return r===void 0||o===void 0||o.isRestParameter()||!n.isIdentifier(o.getNameNode())?!1:t.has(r.compilerNode)?!0:(t.add(r.compilerNode),!be(r,o,t))},ht=(e,t)=>t!==void 0&&n.isIdentifier(e)&&p(e)?.compilerNode===t.compilerNode,It=e=>n.isArrowFunction(e)||n.isFunctionExpression(e)||n.isFunctionDeclaration(e)||n.isMethodDeclaration(e),yt=(e,t)=>!n.isBindingElement(e)||e.getDotDotDotToken()===void 0?!1:e.getFirstAncestorByKind(d.Parameter)?.getParent()?.getAncestors().some(r=>r!==t&&It(r)&&r.getAncestors().includes(t))===!0,be=(e,t,s)=>{for(const i of e.getDescendants()){if(Nt(i)&&!yt(i,e)||xt(i)&&!vt(i.getArguments()[0]))return!0;if(n.isIdentifier(i)&&(Le(i)||ht(i,t))&&!At(i)){const r=i.getParent();if(!(n.isParameterDeclaration(r)||n.isBindingElement(r)||n.isVariableDeclaration(r))&&!Pt(i,s))return!0}}return!1},zt=e=>be(e,void 0,new Set);export{Ft as a,Bt as b,Ct as c,Rt as d,Lt as e,q as f,k as g,wt as i,zt as m,N as r,Y as s};
|
|
1
|
+
import{Node as n,SyntaxKind as d,VariableDeclarationKind as Be}from"ts-morph";import{isConstDeclaration as K,unwrapExpression as l,descendantsOfKind as Fe,bindingKeyName as ue,findObjectProperty as Ce}from"./isTestPath-Uwb5a6Kq.mjs";import{r as Le,b as V,d as p}from"./attribution-Cwt30DDJ.mjs";import{i as ae,r as j,c as m,a as ze}from"./context-root-BpDEhvNE.mjs";import{a as M,s as Z}from"./property-name-7cBlgK_O.mjs";const Re=e=>{const t=e.getText(),s=i=>{const r=i.getNameNode();return n.isIdentifier(r)&&r.getText()===t};for(const i of e.getAncestors())if(!(!n.isArrowFunction(i)&&!n.isFunctionExpression(i)&&!n.isFunctionDeclaration(i)))for(const r of i.getParameters()){const o=r.getDescendantsOfKind(d.BindingElement).find(a=>s(a));if(o!==void 0)return o}},ke=e=>{let t=e;for(;;){const s=t.getParent();if(!n.isObjectBindingPattern(s))return;const i=s.getParent();if(n.isBindingElement(i)){t=i;continue}return n.isParameterDeclaration(i)?ue(t):void 0}},Ke=e=>{const t=e.getText();if(!e.getAncestors().some(o=>{const a=n.isFunctionLikeDeclaration(o)||n.isArrowFunction(o)?o.getParameters()[1]:void 0,c=a?.getNameNode();return a!==void 0&&(n.isIdentifier(c)?c.getText()===t:a.getDescendantsOfKind(d.BindingElement).some(u=>u.getName()===t))&&ae(a)}))return!1;const i=p(e),r=n.isParameterDeclaration(i)?i:i?.getFirstAncestorByKind(d.Parameter);return r!==void 0&&(n.isParameterDeclaration(i)||n.isBindingElement(i))&&ae(r)},ce=(e,t)=>{const s=e.getParent();if(n.isPropertyAccessExpression(s)&&s.getNameNode()===e||n.isPropertyAssignment(s)&&s.getNameNode()===e)return!1;if(e.getText()===t)return!0;const i=Re(e);return i!==void 0&&ke(i)===t?!0:t==="args"&&Ke(e)},L=(e,t)=>n.isIdentifier(e)?ce(e,t):e.getDescendantsOfKind(d.Identifier).some(s=>ce(s,t)),Ve=e=>{let t=e;for(;n.isPropertyAccessExpression(t)||n.isElementAccessExpression(t)||n.isNonNullExpression(t);)t=t.getExpression();return n.isIdentifier(t)?t:void 0},f=e=>{const t=n.isIdentifier(e)?p(e):void 0;return n.isVariableDeclaration(t)&&n.isIdentifier(t.getNameNode())&&!V(t)?t.getInitializer():void 0},Me=(e,t)=>{const s=e.getParent();if(n.isVariableDeclarationList(s)&&s.getDeclarationKind()===Be.Var)return t;const i=s.getParent();return n.isVariableStatement(i)?i.getParent():i},We=(e,t)=>{const s=e.getNameNode();return n.isIdentifier(s)?s.getText()===t:s.getDescendantsOfKind(d.BindingElement).some(i=>{const r=i.getNameNode();return n.isIdentifier(r)&&r.getText()===t})},J=e=>e.getDescendantsOfKind(d.Identifier).filter(t=>{const s=t.getParent();return!(n.isPropertyAccessExpression(s)&&s.getNameNode()===t)&&!(n.isPropertyAssignment(s)&&s.getNameNode()===t)}),O=e=>n.isIdentifier(e)?[e]:J(e),T=e=>{let t=e;for(;;){const s=t.getParent();if(!((n.isPropertyAccessExpression(s)||n.isElementAccessExpression(s)||n.isNonNullExpression(s))&&s.getExpression()===t))return t;t=s}},_e=e=>{const t=e.getParent();return n.isCallExpression(t)&&t.getExpression()===e?t:void 0},je=new Set(["find","findFirst","findFirstOrThrow","findMany","findUnique","first","get","unique"]),U=new Set(["findFirst","findUnique","first","get","unique"]),W=e=>{const t=e.getExpression();return n.isPropertyAccessExpression(t)&&je.has(t.getName())&&m(t)?.[0]==="db"},I=(e,t)=>{for(let s=e,i=e.getParent();i!==void 0&&s!==t;s=i,i=i.getParent()){if(n.isConditionalExpression(i))return!0;if(n.isBinaryExpression(i)){const r=i.getOperatorToken().getKind();if(s===i.getRight()&&(r===d.QuestionQuestionToken||r===d.BarBarToken)||s===i.getLeft()&&r===d.AmpersandAmpersandToken)return!0}}return!1},ge=e=>O(e).some(t=>{if(I(t,e))return!1;if(m(T(t))?.[0]==="auth")return!0;const s=f(t);return s!==void 0&&O(s).some(i=>m(T(i))?.[0]==="auth"&&!I(i,s))}),qe=e=>W(e)&&e.getArguments().some(t=>ge(t)),fe=(e,t)=>{for(let s=e.getParent();s!==void 0;s=s.getParent()){if(n.isCallExpression(s)&&m(s.getExpression())?.[0]==="db")return!0;if(s===t)return!1}return!1},Ue=new Set(["_id","id"]),X=e=>{let t=e;for(let s=t.getParent();;s=t.getParent()){if(n.isAwaitExpression(s)||n.isParenthesizedExpression(s)||n.isNonNullExpression(s)||n.isAsExpression(s)||n.isSatisfiesExpression(s)||n.isTypeAssertion(s)){t=s;continue}if(n.isPropertyAccessExpression(s)&&s.getExpression()===t)return{field:s.getName(),read:s};if(n.isElementAccessExpression(s)&&s.getExpression()===t){const i=l(s.getArgumentExpression());return{field:n.isStringLiteral(i)||n.isNoSubstitutionTemplateLiteral(i)?i.getLiteralValue():void 0,read:s}}return{field:void 0,read:t}}},$="userId",y=e=>{let t=e;for(;;){const s=n.isNonNullExpression(t)||n.isAwaitExpression(t)?t.getExpression():l(t);if(s===void 0||s===t)return t;t=s}},G=e=>{const t=m(y(e));return t?.length===2&&t[0]==="auth"&&t[1]===$},ee=e=>n.isPropertyAssignment(e)?e.getInitializer():n.isShorthandPropertyAssignment(e)?e.getNameNode():void 0,b=e=>{let t=e;for(let s=t.getParent();;s=t.getParent()){if(!(n.isParenthesizedExpression(s)||n.isNonNullExpression(s)||n.isAsExpression(s)||n.isSatisfiesExpression(s)||n.isTypeAssertion(s)))return t;t=s}},pe=e=>{const t=p(e);return e.getSourceFile().getDescendantsOfKind(d.Identifier).filter(s=>s.getText()===e.getText()&&p(s)===t).filter(s=>{const i=s.getParent();return!((n.isVariableDeclaration(i)||n.isBindingElement(i))&&i.getNameNode()===s)})},le=e=>{const t=b(e).getParent();return n.isCallExpression(t)&&W(t)&&t.getArguments().includes(b(e))},Ge=e=>pe(e).every(t=>{if(le(t))return!0;const s=b(t),i=s.getParent(),r=i?.getParent();return(n.isPropertyAssignment(i)&&i.getNameNode()!==s&&M(i)==="where"||n.isShorthandPropertyAssignment(i)&&i.getName()==="where")&&r!==void 0&&le(r)}),z=e=>{const t=l(e);if(n.isObjectLiteralExpression(t))return t;const s=n.isIdentifier(t)&&Ge(t)?l(f(t)):void 0;return n.isObjectLiteralExpression(s)?s:void 0},He=e=>{const t=l(e)??e;if(!n.isObjectLiteralExpression(t))return G(e);const[s,...i]=t.getProperties(),r=i.length===0&&n.isPropertyAssignment(s)&&M(s)==="eq"?s.getInitializer():void 0;return r!==void 0&&G(r)},te=(e,t)=>{const s=e.getProperties(),i=n.isSpreadAssignment(t)?void 0:M(t);return s.slice(s.indexOf(t)+1).some(r=>{if(n.isSpreadAssignment(r))return!0;const o=Z(r.getNameNode());return o===void 0||o===i})},se=e=>e.getProperties().some(t=>n.isGetAccessorDeclaration(t)||n.isSetAccessorDeclaration(t)||n.isMethodDeclaration(t)),me=(e,t)=>!se(e)&&e.getProperties().some(s=>{const i=ee(s);if(i===void 0||n.isSpreadAssignment(s)||te(e,s))return!1;const r=Z(s.getNameNode());if(r===void 0)return!1;if(r==="AND"){const o=l(i);return n.isArrayLiteralExpression(o)&&o.getElements().some(a=>{const c=z(a);return c!==void 0&&me(c,t)})}return(t===void 0||r===t)&&He(i)}),Ee=(e,t)=>{const s=z(e),i=s===void 0?void 0:Ce(s,"where"),r=s===void 0||i===void 0||se(s)||te(s,i)?void 0:z(ee(i));return r!==void 0&&me(r,t)},ve=e=>e.getArguments().some(t=>G(t)||Ee(t,void 0)),Qe=(e,t)=>t===void 0?!1:Ue.has(t)?ve(e):e.getArguments().some(s=>Ee(s,t)),Ye=new Set(["_creationTime","_id"]),Ze=(e,t)=>Ye.has(t)||e.getArguments().every(s=>{const i=z(s);if(i===void 0)return!0;const r=i.getProperties(),o=r.findLast(c=>!n.isSpreadAssignment(c)&&M(c)==="select");if(se(i))return!1;if(o===void 0)return!r.some(c=>n.isSpreadAssignment(c)||Z(c.getNameNode())===void 0);if(te(i,o))return!1;const a=l(ee(o));return n.isArrayLiteralExpression(a)&&a.getElements().some(c=>(n.isStringLiteral(c)||n.isNoSubstitutionTemplateLiteral(c))&&c.getLiteralValue()===t)}),w=(e,t,s,i)=>{const r=e.getExpression(),o=n.isPropertyAccessExpression(r)&&(U.has(r.getName())||r.getName().endsWith("OrThrow"));return!qe(e)||!o||s!==void 0&&!Ze(e,s)?!1:i!==void 0&&l(t)===l(i)&&ve(e)||Qe(e,s)},ie=(e,t)=>{const s=t.getExpression(),i=n.isPropertyAccessExpression(s)&&s.getName().endsWith("OrThrow");return(n.isPropertyAccessExpression(e)||n.isElementAccessExpression(e))&&e.hasQuestionDotToken()&&!i},xe=(e,t)=>O(e).some(s=>{const i=T(s),r=m(i)?.[0];if(r==="auth")return!I(s,e)&&!fe(s,e);const o=r==="db"&&!I(s,e)?_e(i):void 0;if(o===void 0)return!1;const{field:a,read:c}=X(o);return!ie(c,o)&&w(o,c,a,t)}),H=e=>n.isArrowFunction(e)||n.isFunctionExpression(e)||n.isFunctionDeclaration(e)||n.isMethodDeclaration(e),Q=e=>{const t=e.getFirstAncestor(s=>H(s));return H(t)?t:void 0},Je=e=>{const t=l(e);return n.isAwaitExpression(t)?l(t.getExpression()):t},D=e=>{const t=[];let s=l(e);for(;s!==void 0;)if(n.isPropertyAccessExpression(s))t.unshift(s.getName()),s=l(s.getExpression());else if(n.isElementAccessExpression(s)){const i=s.getArgumentExpression();if(!n.isStringLiteral(i))return;t.unshift(i.getLiteralValue()),s=l(s.getExpression())}else return n.isIdentifier(s)?{path:t,root:s}:void 0},E=(e,t)=>p(e)?.compilerNode===t.compilerNode,Ae=e=>{if(!n.isIdentifier(e))return;const t=Le(e),s=t?.isAlias()===!0?t.getAliasedSymbol():t,i=s?.getValueDeclaration()??s?.getDeclarations()[0];if(i===void 0)return;const r=i.getSourceFile();if(r.isDeclarationFile()||r.isInNodeModules())return;if(n.isFunctionDeclaration(i))return i.getBody()===void 0||i.isGenerator()||V(i)?void 0:i;if(!K(i))return;const o=l(i.getInitializer());return n.isArrowFunction(o)||n.isFunctionExpression(o)&&!o.isGenerator()?o:void 0},Xe=e=>e>=d.FirstAssignment&&e<=d.LastAssignment,ne=e=>{const t=[],s=[];let i=l(e);for(;i!==void 0;)if(n.isCallExpression(i))t.push(i),i=l(i.getExpression());else if(n.isPropertyAccessExpression(i))s.unshift(i.getName()),i=l(i.getExpression());else if(n.isElementAccessExpression(i)){const r=i.getArgumentExpression();if(!n.isStringLiteral(r))return;s.unshift(r.getLiteralValue()),i=l(i.getExpression())}else return n.isIdentifier(i)&&t.length>0&&s.length>0?{calls:t,names:s,root:i}:void 0},re=e=>{const t=e.names[e.names.length-1]??"";if(U.has(t))return{selfEnforcing:!1};const s=t.endsWith("OrThrow")?t.slice(0,-7):void 0;return s!==void 0&&U.has(s)?{selfEnforcing:!0}:void 0},$e=e=>{const t=l(e),s=n.isIdentifier(t)?l(f(t))??t:t,i=D(s);if(i===void 0||i.path.length===0)return;const r=p(i.root);if(!K(r)||!n.isIdentifier(r.getNameNode()))return;const o=Je(r.getInitializer()),a=n.isCallExpression(o)&&m(o.getExpression())?.[0]==="db"?ne(o):void 0;return a!==void 0&&re(a)!==void 0?r:void 0},Ne=e=>e.calls.flatMap(t=>t.getArguments().flatMap(s=>[s,...s.getDescendants()])),et=(e,t)=>{const s=n.isIdentifier(e)?p(e):void 0;if(!n.isBindingElement(s)||s.getDotDotDotToken()!==void 0||s.getInitializer()!==void 0)return!1;const i=s.getParent(),r=n.isObjectBindingPattern(i)?i.getParent():void 0;if(!K(r))return!1;const o=D(r.getInitializer());return o?.path[0]==="auth"&&E(o.root,t)},tt=(e,t)=>{const s=D(e);if(s!==void 0&&s.path.length>0)return s.path[0]==="auth"&&E(s.root,t);const i=D(f(e));return i?.path[0]==="auth"&&E(i.root,t)?!0:et(e,t)},he=e=>{if(!n.isVariableStatement(e))return;const t=e.getDeclarations(),s=t.length===1?t[0]:void 0;return s!==void 0&&K(s)&&n.isIdentifier(s.getNameNode())?s:void 0},st=(e,t)=>{const s=l(e),i=a=>n.isIdentifier(a)&&E(a,t);if(n.isPrefixUnaryExpression(s))return s.getOperatorToken()===d.ExclamationToken&&i(l(s.getOperand()));if(!n.isBinaryExpression(s)||s.getOperatorToken().getKind()!==d.EqualsEqualsToken)return!1;const r=l(s.getLeft()),o=l(s.getRight());return i(r)&&n.isNullLiteral(o)||i(o)&&n.isNullLiteral(r)},it=(e,t)=>{const s=n.isBlock(e)?e.getStatements():void 0,i=s===void 0?e:s[s.length-1];return n.isThrowStatement(i)||!t&&n.isReturnStatement(i)},Pe=(e,t,s)=>n.isIfStatement(e)&&e.getElseStatement()===void 0&&st(e.getExpression(),t)&&it(e.getThenStatement(),s),nt=(e,t,s)=>{const i=e.getBody();if(!n.isBlock(i))return!1;const r=i.getStatements();return r.some((o,a)=>{const c=he(o),u=l(c?.getInitializer()),g=n.isAwaitExpression(u)?ne(u.getExpression()):void 0,A=g===void 0?void 0:re(g);if(c===void 0||g===void 0||A===void 0||g.names[0]!=="db"||!E(g.root,t))return!1;const v=Ne(g),h=v.some(x=>tt(x,t)),F=s.some(x=>v.some(oe=>n.isIdentifier(oe)&&E(oe,x)));if(!h||!F)return!1;const P=A.selfEnforcing?o:r.slice(a+1).find(x=>Pe(x,c,!0));return P!==void 0&&!e.getDescendantsOfKind(d.ReturnStatement).some(x=>Q(x)?.compilerNode===e.compilerNode&&x.getStart()<P.getEnd())})},rt=(e,t,s)=>{const i=Ae(e.getExpression()),r=e.getArguments();if(i===void 0||r.some(v=>n.isSpreadElement(v)))return!1;const o=r.flatMap((v,h)=>m(v)?.length===0?[h]:[]),a=o.length===1?o[0]:void 0,c=a===void 0?void 0:i.getParameters()[a];if(a===void 0||c===void 0||c.isRestParameter()||!n.isIdentifier(c.getNameNode()))return!1;const u=[];r.forEach((v,h)=>{const F=D(l(v)),P=h===a||F===void 0||!E(F.root,t)?void 0:i.getParameters()[h];P!==void 0&&n.isIdentifier(P.getNameNode())&&u.push(P)});const g=i.getReturnType(),A=i.isAsync()||g.isAny()||g.isUnknown()||g.getText().includes("Promise");return u.length===0||!s&&A?!1:nt(i,c,u)},ot=(e,t)=>{const s=he(e),i=l(s?.getInitializer()),r=n.isAwaitExpression(i)?ne(i.getExpression()):void 0,o=r===void 0?void 0:re(r);if(s===void 0||r===void 0||o===void 0||r.names[0]!=="db"||m(r.root)?.length!==0)return;const a=r.calls.some(u=>u.getArguments().some(g=>ge(g))),c=Ne(r).some(u=>n.isIdentifier(u)&&E(u,t));return a&&c?{declaration:s,selfEnforcing:o.selfEnforcing}:void 0},at=(e,t,s)=>{const i=(r,o)=>o.getStart()<=r.getStart()&&r.getEnd()<=o.getEnd();for(let r=e.getParent();r!==void 0&&r.compilerNode!==t.compilerNode;r=r.getParent()){if(H(r)||n.isIfStatement(r)||n.isIterationStatement(r)||n.isCaseClause(r)||n.isDefaultClause(r)||n.isCatchClause(r))return!1;if(n.isTryStatement(r)&&r.getCatchClause()!==void 0){const o=r.getTryBlock();if(!i(e,o)||!i(s,o))return!1}}return!0},ct=(e,t,s,i,r)=>e.slice(0,t).some((o,a)=>{if(!at(o,i,r))return!1;if(n.isExpressionStatement(o)){const u=l(o.getExpression()),g=n.isAwaitExpression(u),A=g?l(u.getExpression()):u;if(n.isCallExpression(A)&&rt(A,s,g))return!0}const c=ot(o,s);return c!==void 0&&(c.selfEnforcing||a+1<t&&Pe(e[a+1],c.declaration,!1))}),_=e=>{let t=l(e)??e;for(;n.isAwaitExpression(t);)t=l(t.getExpression())??t.getExpression();return t},C=e=>{const t=_(e);return n.isCallExpression(t)||n.isNewExpression(t)},lt=e=>{const t=_(e);return n.isCallExpression(t)&&m(t.getExpression())?.[0]==="db"},Ie=e=>{const t=_(e);return n.isCallExpression(t)&&W(t)},ye=e=>L(e,"args")||O(e).some(t=>{const s=f(t);return s!==void 0&&L(s,"args")}),R=(e,t)=>{const s=e?.getNameNode().getDescendantsOfKind(d.BindingElement).find(i=>n.isIdentifier(i.getNameNode())&&i.getNameNode().getText()===t);return s===void 0?[]:[s,...s.getAncestors().filter(i=>n.isBindingElement(i))].map(i=>n.isBindingElement(i)?i.getInitializer():void 0).filter(i=>i!==void 0)},De=e=>{const t=n.isIdentifier(e)?p(e):void 0;if(!n.isBindingElement(t)||V(t))return;const s=t.getFirstAncestorByKind(d.VariableDeclaration),i=s?.getInitializer();if(!R(s,e.getText()).some(r=>ye(r)))return i!==void 0&&Ie(i)?i:void 0},B=e=>{const t=_(e);return n.isCallExpression(t)&&W(t)?t:void 0},Se=e=>{if(!(!n.isBindingElement(e)||!n.isObjectBindingPattern(e.getParent())||e.getDotDotDotToken()!==void 0||n.isBindingElement(e.getParent().getParent())))return ue(e)},dt=e=>{let t=e,s=t.getParent();for(;n.isParenthesizedExpression(s)||n.isArrayLiteralExpression(s)||n.isObjectLiteralExpression(s)||n.isSpreadElement(s)||n.isSpreadAssignment(s)||n.isShorthandPropertyAssignment(s)||n.isPropertyAssignment(s)&&s.getNameNode()!==t;)t=s,s=t.getParent();if(n.isBinaryExpression(s)){const i=s.getOperatorToken().getKind();return s.getLeft()===t&&i>=d.FirstAssignment&&i<=d.LastAssignment}if(n.isForOfStatement(s)||n.isForInStatement(s))return s.getInitializer()===t;if(n.isPrefixUnaryExpression(s)||n.isPostfixUnaryExpression(s)){const i=s.getOperatorToken();return i===d.PlusPlusToken||i===d.MinusMinusToken}return n.isDeleteExpression(s)},Oe=e=>pe(e).every(t=>{const s=b(t),i=s.getParent();return n.isVariableDeclaration(i)&&n.isObjectBindingPattern(i.getNameNode())||n.isSpreadAssignment(i)?!0:(n.isPropertyAccessExpression(i)||n.isElementAccessExpression(i))&&i.getExpression()===s&&!dt(b(T(i)))}),de=(e,t)=>{const s=t!==void 0&&l(e)===l(t),i=f(e);if(i!==void 0){const a=B(i);if(a===void 0)return xe(i,s?i:void 0);if(n.isIdentifier(e)&&!Oe(e))return!1;const{field:c,read:u}=X(e);return ie(u,a)?!1:w(a,u,c,t)}const r=De(e),o=r===void 0?void 0:B(r);return o!==void 0&&n.isIdentifier(e)&&w(o,e,Se(p(e)),t)},S=(e,t=!0)=>{const s=y(e);if(n.isTemplateExpression(s))return s.getTemplateSpans().flatMap(o=>S(o.getExpression(),t));if(n.isBinaryExpression(s)&&s.getOperatorToken().getKind()===d.PlusToken)return[...S(s.getLeft(),t),...S(s.getRight(),t)];const i=t&&n.isIdentifier(s)?f(s):void 0,r=i===void 0?void 0:y(i);return r!==void 0&&(n.isTemplateExpression(r)||n.isBinaryExpression(r)&&r.getOperatorToken().getKind()===d.PlusToken)?S(r,!1):[s]},ut=e=>n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)||n.isNumericLiteral(e),gt=e=>{const t=y(e.getExpression()),s=n.isIdentifier(t)?f(t):void 0;if(n.isIdentifier(t)&&s!==void 0&&!Oe(t))return!1;const i=B(t)??(s===void 0?void 0:B(s));return i!==void 0&&!ie(e,i)&&w(i,e,X(e.getExpression()).field,void 0)},ft=e=>{const t=p(e),s=Se(t),i=n.isBindingElement(t)?t.getFirstAncestorByKind(d.VariableDeclaration)?.getInitializer():void 0,r=i===void 0?void 0:m(y(i));if(r!==void 0)return r.length===1&&r[0]==="auth"&&s===$;const o=De(e),a=o===void 0?void 0:B(o);return a!==void 0&&w(a,e,s,void 0)},Te=(e,t=!0)=>{const s=y(e),i=n.isIdentifier(s)?p(s):void 0;if((n.isVariableDeclaration(i)||n.isBindingElement(i))&&V(i))return!1;const r=m(s);if(r!==void 0)return r.length===2&&r[0]==="auth"&&r[1]===$;if(n.isPropertyAccessExpression(s)||n.isElementAccessExpression(s))return gt(s);if(!n.isIdentifier(s))return!1;const o=f(s);return o===void 0?ft(s):t&&Te(o,!1)},pt=(e,t)=>{const s=S(t),i=s.findIndex(a=>!ut(a)),r=s.findIndex(a=>a.getPos()<=e.getPos()&&e.getEnd()<=a.getEnd()),o=s[i];return o!==void 0&&i<r&&Te(o)},N=e=>L(e,"args"),k=e=>{if(!n.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>n.isArrowFunction(a)||n.isFunctionExpression(a)||n.isFunctionDeclaration(a));if(s===void 0)return;const i=e.getStart();let r,o=-1;for(const a of Fe(s,d.VariableDeclaration)){if(!We(a,t))continue;const c=Me(a,s);if(c===void 0||i<c.getStart()||i>=c.getEnd())continue;const u=a.getInitializer(),g=a.getStart();u!==void 0&&g<i&&g>o&&(r=a,o=g)}return r},Y=e=>k(e)?.getInitializer(),Bt=e=>{if(N(e))return!0;const t=s=>{const i=k(s),r=i?.getInitializer();return r!==void 0&&N(r)||R(i,s.getText()).some(o=>N(o))};return t(e)||J(e).some(s=>t(s))},Ft=e=>{if(C(e))return!1;if(R(k(e),e.getText()).some(i=>N(i)&&!C(i)))return!0;const t=Y(e);if(t!==void 0&&C(t)&&!(Ie(t)&&N(t)))return!1;const s=t??e;return N(s)?!0:J(s).some(i=>{if(i.getFirstAncestor(c=>c===s||n.isCallExpression(c)||n.isNewExpression(c))!==s)return!1;const o=k(i),a=c=>c!==void 0&&N(c)&&(!C(c)||lt(c));return a(o?.getInitializer())||R(o,i.getText()).some(c=>a(c))})},Ct=e=>{if(j(e))return!0;const t=f(e);if(t!==void 0&&j(t))return!0;const s=t??e;return(n.isIdentifier(s)?[s]:s.getDescendantsOfKind(d.Identifier)).some(r=>{const o=f(r);return o!==void 0&&j(o)})},Lt=e=>{const t=f(e)??e;if(O(t).some(r=>I(r,t)&&ye(T(r))&&!pt(r,t)))return!1;if(xe(e,e)||de(e,e))return!0;const s=f(e)??e;return(n.isIdentifier(s)?[s]:s.getDescendantsOfKind(d.Identifier)).some(r=>!I(r,s)&&!fe(r,s)&&de(r,s))},q=(e,t)=>L(e,t),zt=(e,t)=>{if(q(e,t))return!0;const s=Y(e);if(s!==void 0&&q(s,t))return!0;const i=Ve(e);if(i!==void 0){const r=Y(i);return r!==void 0&&q(r,t)}return!1},Rt=(e,t)=>{const s=Q(e),i=$e(t);if(s===void 0||i===void 0||Q(i)?.compilerNode!==s.compilerNode||s.getDescendantsOfKind(d.BinaryExpression).some(c=>{const u=D(c.getLeft());return Xe(c.getOperatorToken().getKind())&&u!==void 0&&E(u.root,i)}))return!1;let o=e,a=e.getParent();for(;a!==void 0&&a.compilerNode!==s.compilerNode;){if(n.isBlock(a)){const c=a.getStatements(),u=c.findIndex(g=>g.compilerNode===o.compilerNode);if(u>0&&ct(c,u,i,s,e))return!0}o=a,a=a.getParent()}return!1},mt=/rate|limit|\bip\b|geo|throttle/iu,Et=/^run[A-Z]/u,vt=e=>n.isIdentifier(e)?(e.getSymbol()?.getDeclarations()??[]).some(s=>s.getFirstAncestorByKind(d.ImportDeclaration)?.getModuleSpecifierValue().startsWith("@lunora/")===!0):!1,xt=e=>{const t=n.isCallExpression(e)?e.getExpression():e;let s;return n.isIdentifier(t)?s=t:n.isPropertyAccessExpression(t)&&(s=t.getNameNode()),s!==void 0&&vt(n.isPropertyAccessExpression(t)?t.getExpression():s)&&!mt.test(s.getText())},At=e=>{const t=n.isCallExpression(e)?e.getExpression():void 0;if(n.isElementAccessExpression(t)){const s=t.getArgumentExpression();return(n.isStringLiteral(s)||n.isNoSubstitutionTemplateLiteral(s))&&s.getLiteralText()==="use"}return n.isPropertyAccessExpression(t)&&t.getName()==="use"},Nt=e=>{const t=e.getParent();return n.isPropertyAccessExpression(t)&&t.getExpression()===e?!Et.test(t.getName()):n.isElementAccessExpression(t)&&t.getExpression()===e?n.isStringLiteral(t.getArgumentExpression())||n.isNoSubstitutionTemplateLiteral(t.getArgumentExpression()):n.isVariableDeclaration(t)&&t.getInitializer()?.getText()===e.getText()},ht=e=>{if(n.isPropertyAccessExpression(e))return e.getName()==="ip";if(n.isElementAccessExpression(e)){const t=e.getArgumentExpression();return(n.isStringLiteral(t)||n.isNoSubstitutionTemplateLiteral(t))&&t.getLiteralText()==="ip"}return n.isBindingElement(e)?e.getDotDotDotToken()!==void 0||(e.getPropertyNameNode()?.getText()??e.getName())==="ip":n.isShorthandPropertyAssignment(e)&&e.getName()==="ip"},Pt=(e,t)=>{const s=e.getParent();if(!n.isCallExpression(s)||s.getExpression()===e)return!1;const i=s.getArguments(),r=i.indexOf(e);if(i.slice(0,Math.max(r,0)).some(c=>n.isSpreadElement(c)))return!1;const o=Ae(s.getExpression()),a=r===-1||o===void 0?void 0:o.getParameters()[r];return o===void 0||a===void 0||a.isRestParameter()||!n.isIdentifier(a.getNameNode())?!1:t.has(a.compilerNode)?!0:(t.add(a.compilerNode),!we(o,a,t))},be=(e,t,s=new Set)=>{if(t===void 0||!n.isIdentifier(e))return!1;const i=p(e);if(i?.compilerNode===t.compilerNode)return!0;if(i===void 0||s.has(i.compilerNode))return!1;s.add(i.compilerNode);const r=n.isVariableDeclaration(i)&&n.isIdentifier(i.getNameNode())?i.getInitializer():void 0;return r!==void 0&&be(r,t,s)},It=e=>{const t=e.getParent();return n.isParameterDeclaration(t)||n.isBindingElement(t)||n.isVariableDeclaration(t)?t.getInitializer()!==e:!1},yt=e=>n.isArrowFunction(e)||n.isFunctionExpression(e)||n.isFunctionDeclaration(e)||n.isMethodDeclaration(e),Dt=(e,t)=>!n.isBindingElement(e)||e.getDotDotDotToken()===void 0?!1:e.getFirstAncestorByKind(d.Parameter)?.getParent()?.getAncestors().some(r=>r!==t&&yt(r)&&r.getAncestors().includes(t))===!0,we=(e,t,s)=>{for(const i of e.getDescendants())if(ht(i)&&!Dt(i,e)||At(i)&&!xt(i.getArguments()[0])||n.isIdentifier(i)&&(ze(i)||be(i,t))&&!Nt(i)&&!It(i)&&!Pt(i,s))return!0;return!1},kt=e=>we(e,void 0,new Set);export{Ct as a,Ft as b,Lt as c,Rt as d,zt as e,q as f,k as g,Bt as i,kt as m,N as r,Y as s};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{NODE_CAPABILITIES as g,CLOUDFLARE_CAPABILITIES as b,CELLD_CAPABILITIES as y}from"@lunora/platform";import{r as f}from"./project-config-file-DR7xrrNB.mjs";const m="cloudflare",S=t=>{const{target:e}=f(t);return e!==void 0&&e.length>0?e:void 0},I=(t,e)=>e??S(t)??m,z=(t,e)=>{if(e!==void 0)return[];const{target:r,unreadable:a}=f(t);return a!==!0||r!==void 0?[]:[{level:"warn",message:`lunora.config declares a \`target\` that codegen cannot read without evaluating it, so the "${m}" surface was emitted. \`runCodegen\` resolves the target synchronously, which means it reads literals only.`,name:"platform_unreadable_target",remediation:`Write \`target\` as a string literal on the config's default export (\`export default { target: "${m}" }\`), or pass \`--target\`.`,target:m}]},_={max:1536,min:32},E=(t,e)=>{if(t!=="cloudflare")return[];const{max:r,min:a}=_,i=`${String(a)}-${String(r)}`;return e.filter(({dimensions:o})=>o!==void 0&&(!Number.isInteger(o)||o<a||o>r)).map(({dimensions:o,name:s})=>({level:"warn",message:`Vector index "${s}" declares ${String(o)} dimensions; Cloudflare Vectorize accepts ${i}, so creating a Vectorize index for it fails at deploy.`,name:"platform_vector_dimensions_out_of_range",remediation:`If a Vectorize index backs "${s}", use ${i} dimensions (many embedding models can truncate output to fit). Ignore this if another store, such as pgvector, backs it.`,target:t}))},u={celld:y,cloudflare:b,node:g},O=(t,e)=>{const r=u[t];if(r===void 0)return!0;const a=r.features[e]?.level;return a==="native"||a==="emulated"},D=()=>Object.keys(u).toSorted((t,e)=>t.localeCompare(e)),k={access:null,ai:"ai",aiSearch:"aiSearch",analytics:"analytics",analyticsSql:"analyticsSql",artifacts:"artifacts",browser:"browser",container:"containers",flags:null,hyperdrive:"hyperdrive",images:"images",kv:"keyValueStore",mail:"mail",notify:null,payments:null,pipelines:"pipelines",r2sql:null,scheduler:"scheduler",storage:"objectStorage",vectors:"vectorStore",workflows:"workflows",x402:"secrets"},w=["agents","commitOrderedTables","containerEgressPolicy","containerRuntimeScheduling","containerSandboxTools","cronTriggers","crossShardFanout","deliveryAuthorization","durableStreams","globalTables","liveStreams","queues","relationGraph","secrets","secretValues","services","topics","typedWebSockets","vectorStore","workerLoaders","workflowRollback","workflowSchedules"],h={agents:"durable agents (`defineAgent`)",commitOrderedTables:"commit-ordered tables (`.commitOrdered()`)",containerEgressPolicy:"container egress policies (`defineContainer({ allowedHosts | deniedHosts | interceptHttps })`)",containerRuntimeScheduling:'per-instance container images and snapshots (`defineContainer({ schedulingPolicy: "durable_object" })`)',containerSandboxTools:"container sandbox helpers — files, directory backups, bucket mounts (`defineContainer({ sandbox: true })`)",deliveryAuthorization:"delivery authorization (`.deliveryAuthorization(...)` on the app builder)",cronTriggers:"declared cron triggers (`cronJobs()`)",crossShardFanout:"cross-shard fan-out queries (a `.shardBy(...)` schema)",durableStreams:"durable streams (`.stream(handler, { durable: true })`)",globalTables:"global tables (`.global()`)",liveContext:"the live publisher (`ctx.live`)",liveStreams:"live topic streams (`defineLiveStream`)",queues:"queues (`defineQueue`)",relationGraph:"relation-graph traversal (`ctx.db.related`, derived from `v.id(...)` columns)",secrets:"the secrets store (`ctx.secrets`)",secretValues:"human-supplied secret values (`requestSecretTool`, held for one agent step)",services:"service bindings to sibling Workers (`lunora.config` `services`)",topics:"pub/sub topics (`defineTopic` / `defineSubscription`)",typedWebSockets:"typed WebSocket routes and rooms (`defineWebSocket` / `defineRoom`)",vectorStore:"vector indexes (`.vectorize()`)",workerLoaders:"sandboxed agent scripts (`jsCodeTool`, on Worker Loaders)",workflowRollback:"workflow step rollback (`defineStep({ rollback })`)",workflowSchedules:"scheduled workflow instances (`defineWorkflow({ schedules })`)"},T=(t,e,r)=>({level:"error",message:`${e.name} does not support ${h[t]}, which this app declares.`,name:"platform_unsupported_feature",remediation:`Remove the declaration, or deploy to a target whose capability matrix marks "${t}" as native or emulated.`,target:r}),x=(t,e)=>({level:"error",message:`${t.name} withholds live streams, so ctx.live is not available on the "${e}" target, but this app reads ctx.live.`,name:"platform_unsupported_feature",remediation:'Remove the ctx.live usage, or deploy to a target whose capability matrix marks "liveStreams" as native or emulated.',target:e}),P=t=>({level:"error",message:"This app declares defineLiveStream topics and enables delivery authorization. With delivery authorization on, the shard answers every /_lunora/live/* request with 501, so the live streams cannot be served.",name:"platform_live_stream_delivery_authorization",remediation:"Remove the defineLiveStream declarations, or remove the .deliveryAuthorization(...) call. Live streams and delivery authorization cannot be combined.",target:t}),W=t=>({level:"error",message:"This app declares defineWebSocket routes and enables delivery authorization. With delivery authorization on, the shard answers every route upgrade with 501, so the routes cannot be served.",name:"platform_socket_delivery_authorization",remediation:"Remove the defineWebSocket declarations, or remove the .deliveryAuthorization(...) call. Socket routes and delivery authorization cannot be combined.",target:t}),A=(t,e,r)=>({level:"error",message:`${e.name}'s capability matrix does not declare a support level for ${h[t]}, which this app declares. Treated as unsupported.`,name:"platform_undeclared_feature",remediation:`Rate "${t}" in the ${e.name} capability matrix as "native", "emulated", or "unsupported" — an undeclared feature fails closed rather than letting the app deploy onto a primitive the host may not provide.`,target:r}),$=t=>{const{diagnostics:e,gatedSignals:r,matrix:a,reported:i,signals:o,target:s}=t;for(const n of w){if(o[n]!==!0)continue;const d=a.features[n]?.level;d!=="unsupported"&&d!==void 0||(r[n]=!1,!i.has(n)&&e.push(d==="unsupported"?T(n,a,s):A(n,a,s)))}},R=(t,e,r,a={})=>{const i={...t},o={...a},s=[],n=new Set;for(const[l,c]of Object.entries(k)){if(c===null||!t[l])continue;const v=e.features[c]?.level;v==="unsupported"?(i[l]=!1,n.add(c),s.push({feature:l,level:"error",message:`${e.name} does not support "${l}" (ctx.${l}).`,name:"platform_unsupported_feature",remediation:`Remove the ctx.${l} usage, or deploy to a target whose capability matrix marks "${c}" as native or emulated.`,target:r})):v===void 0&&(i[l]=!1,n.add(c),s.push({feature:l,level:"error",message:`${e.name}'s capability matrix does not declare a support level for "${l}" (ctx.${l}). Treated as unsupported.`,name:"platform_undeclared_feature",remediation:`Rate "${c}" in the ${e.name} capability matrix as "native", "emulated", or "unsupported" — an undeclared feature fails closed rather than shipping a surface the host may not provide.`,target:r}))}$({diagnostics:s,gatedSignals:o,matrix:e,reported:n,signals:a,target:r});const d=e.features.liveStreams?.level,p=d===void 0||d==="unsupported";return a.liveContext===!0&&p&&s.push(x(e,r)),{diagnostics:s,liveStreamsWithheld:p,signals:o,usage:i}},F=(t,e,r={})=>{const a=u[e];return a===void 0?{diagnostics:[{level:"error",message:`Unknown deploy target "${e}" — no capability matrix is registered for it. Codegen emitted the full Cloudflare surface un-gated.`,name:"platform_unknown_target",remediation:`Use a registered target (${Object.keys(u).join(", ")}) or install the target's @lunora/platform-${e} package.`,target:e}],liveStreamsWithheld:!1,signals:{...r},usage:{...t}}:R(t,a,e,r)},j=t=>{const e=u[t];if(e===void 0)return{supported:!0};const r=e.features.adminTokenRevocation?.level;return r!==void 0&&r!=="unsupported"?{supported:!0}:{diagnostic:{level:"warn",message:`${e.name} ${r===void 0?"does not declare a support level for":"does not support"} named admin tokens, so codegen omits the admin revocation store (\`_generated/adminRevocations.ts\` and the builder's \`.adminRevocations()\`). The root LUNORA_ADMIN_TOKEN is the only admin credential here.`,name:r===void 0?"platform_undeclared_feature":"platform_unsupported_feature",remediation:'Use the root admin token, or deploy to a target whose capability matrix marks "adminTokenRevocation" as native or emulated.',target:t},supported:!1}},N=t=>{const e=u[t];if(e===void 0)return;const r=Object.entries(e.features).filter(([,a])=>a.level==="unsupported").map(([a])=>a).toSorted((a,i)=>a.localeCompare(i));return{id:e.id,name:e.name,unsupported:r}};export{k as CAPABILITY_TO_FEATURE,m as DEFAULT_TARGET,j as gateAdminTokenRevocation,R as gateAgainstMatrix,F as gatePlatformFeatures,P as liveStreamsDeliveryAuthorizationDiagnostic,O as platformFeatureAvailable,D as platformMatrixIds,S as readProjectTarget,z as readTargetDiagnostics,I as resolveCodegenTarget,W as socketRoutesDeliveryAuthorizationDiagnostic,N as studioPlatformFor,E as vectorizeDimensionDiagnostics};
|