@lunora/codegen 1.0.0-alpha.220 → 1.0.0-alpha.221

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/index.d.mts +19 -3
  2. package/dist/index.d.ts +19 -3
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/{AGENTS_FILENAME-CXktfidB.mjs → AGENTS_FILENAME-DoPI92Wu.mjs} +1 -1
  5. package/dist/packem_shared/{CONTAINERS_FILENAME-CtYUTuyn.mjs → CONTAINERS_FILENAME-B6TFs82W.mjs} +1 -1
  6. package/dist/packem_shared/DEFAULT_TARGET-CkKqxaOb.mjs +1 -0
  7. package/dist/packem_shared/{FLAGS_FILENAME-qQuylR_O.mjs → FLAGS_FILENAME-BedPDCsR.mjs} +1 -1
  8. package/dist/packem_shared/{MUTATORS_FILENAME-DCsa5Ma-.mjs → MUTATORS_FILENAME-B6cKrN_m.mjs} +1 -1
  9. package/dist/packem_shared/{NOTIFY_FILENAME-D67sEwVX.mjs → NOTIFY_FILENAME-Cri3NT5U.mjs} +1 -1
  10. package/dist/packem_shared/PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs +1 -0
  11. package/dist/packem_shared/{QUEUES_FILENAME-BdgYKMU9.mjs → QUEUES_FILENAME-CxkPcMH1.mjs} +1 -1
  12. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CoCRXlsC.mjs +9 -0
  13. package/dist/packem_shared/{SHAPES_FILENAME-DTGoT04E.mjs → SHAPES_FILENAME-zJgzynXR.mjs} +1 -1
  14. package/dist/packem_shared/{WORKFLOWS_FILENAME-B6GW6JVZ.mjs → WORKFLOWS_FILENAME-B_ZJxRSx.mjs} +1 -1
  15. package/dist/packem_shared/chain-H2N_uKgj.mjs +1 -0
  16. package/dist/packem_shared/{classify-procedure-call-CZU6n3yF.mjs → classify-procedure-call-BztLe76A.mjs} +1 -1
  17. package/dist/packem_shared/{context-property-calls-ClziPULs.mjs → context-property-calls-CjDzLU8p.mjs} +1 -1
  18. package/dist/packem_shared/{discoverAuthApiCalls-GNVuIrUo.mjs → discoverAuthApiCalls-FxrdBeVt.mjs} +1 -1
  19. package/dist/packem_shared/{discoverCrons-CV2EZ_vn.mjs → discoverCrons-MfKw7IFf.mjs} +1 -1
  20. package/dist/packem_shared/{discoverFunctions-Bk10Q2Zl.mjs → discoverFunctions-BsmX-sEq.mjs} +1 -1
  21. package/dist/packem_shared/{discoverHttpRoutes-DJ-y2q50.mjs → discoverHttpRoutes-BcXI9CNt.mjs} +1 -1
  22. package/dist/packem_shared/discoverHyperdriveCalls-D9qXqTq3.mjs +1 -0
  23. package/dist/packem_shared/{discoverInserts-gOn4B3o0.mjs → discoverInserts-CFJ3IVeI.mjs} +1 -1
  24. package/dist/packem_shared/discoverMaskProcedures-CV_Cc2_g.mjs +1 -0
  25. package/dist/packem_shared/{discoverMigrations-DTv9qRcf.mjs → discoverMigrations-DbrHwcGE.mjs} +1 -1
  26. package/dist/packem_shared/{discoverNondeterministicCalls-CWAlKa4g.mjs → discoverNondeterministicCalls-CSQ_GDcA.mjs} +1 -1
  27. package/dist/packem_shared/discoverQueries-C7y8i_Ga.mjs +1 -0
  28. package/dist/packem_shared/discoverR2sqlCalls-fu7fC0i_.mjs +1 -0
  29. package/dist/packem_shared/{discoverRlsMetadata-Cc-eoo9M.mjs → discoverRlsMetadata-CPmAGL0W.mjs} +1 -1
  30. package/dist/packem_shared/{discoverRlsProcedures-CsbCosUT.mjs → discoverRlsProcedures-BO4qC77y.mjs} +1 -1
  31. package/dist/packem_shared/{discoverSandboxUsage-5WJ5s2sM.mjs → discoverSandboxUsage-CgmfgDTS.mjs} +1 -1
  32. package/dist/packem_shared/discoverSchema-Buzj8y8m.mjs +1 -0
  33. package/dist/packem_shared/{discoverStorageRulesMetadata-Bj6gg_lr.mjs → discoverStorageRulesMetadata-D8VYflWt.mjs} +1 -1
  34. package/dist/packem_shared/{emitApp-BewH-Jfe.mjs → emitApp-DCNd7kfS.mjs} +11 -9
  35. package/dist/packem_shared/{exported-procedure-chains-DhKcj-hK.mjs → exported-procedure-chains-CmCDiPBV.mjs} +1 -1
  36. package/dist/packem_shared/{index-BGHtJQPU.mjs → index-BoaHhVtM.mjs} +1 -1
  37. package/dist/packem_shared/listLunoraSourceFiles-DP-5e-RE.mjs +1 -0
  38. package/dist/packem_shared/loadProjectConfig-CKsFNgn3.mjs +1 -0
  39. package/dist/packem_shared/{parse-validator-2u-Io0i5.mjs → parse-validator-C94Yiabo.mjs} +1 -1
  40. package/dist/packem_shared/{queries-C8MF4jMB.mjs → queries-B-f4jO-x.mjs} +1 -1
  41. package/dist/packem_shared/{unwrap-handler-return-C1OS0xP8.mjs → unwrap-handler-return-CoV_GK33.mjs} +1 -1
  42. package/package.json +9 -9
  43. package/dist/packem_shared/DEFAULT_TARGET-CwlCMxUf.mjs +0 -1
  44. package/dist/packem_shared/PROJECT_CONFIG_FILENAMES-DfD2MHzr.mjs +0 -1
  45. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DPe7MX0x.mjs +0 -9
  46. package/dist/packem_shared/chain-CjJF9d9k.mjs +0 -1
  47. package/dist/packem_shared/discoverHyperdriveCalls-C5he04zb.mjs +0 -1
  48. package/dist/packem_shared/discoverMaskProcedures-GgXYEuuB.mjs +0 -1
  49. package/dist/packem_shared/discoverQueries-CjxhCGm8.mjs +0 -1
  50. package/dist/packem_shared/discoverR2sqlCalls-BkoDbcXj.mjs +0 -1
  51. package/dist/packem_shared/discoverSchema-DvQyqT4W.mjs +0 -1
  52. package/dist/packem_shared/listLunoraSourceFiles-vjwjgpjd.mjs +0 -1
@@ -0,0 +1 @@
1
+ import{w as a}from"./classify-procedure-call-BztLe76A.mjs";const l=s=>a(s,"use","rls");export{l as r};
@@ -1 +1 @@
1
- import{Node as o}from"ts-morph";import{unwrapExpression as a}from"./listLunoraSourceFiles-vjwjgpjd.mjs";import{a as u}from"./module-specifiers-WF8iAydP.mjs";const A=t=>o.isIdentifier(t)?t.getText():o.isPropertyAccessExpression(t)?t.getName():void 0,y=(t,i)=>{const e=new Set;for(const r of t.getImportDeclarations())if(u(r.getModuleSpecifierValue()))for(const n of r.getNamedImports())n.getNameNode().getText()===i&&e.add(n.getAliasNode()?.getText()??n.getName());return e},h=(t,i)=>{if(o.isPropertyAccessExpression(t))return t.getName()===i;if(!o.isIdentifier(t))return!1;const e=t.getText();return e===i||y(t.getSourceFile(),i).has(e)},d=t=>{const i=t.getSymbol();if(!i)return t.getText();for(const e of i.getDeclarations())if(o.isImportSpecifier(e))return u(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText():void 0},p=t=>{const i=[];let e=a(t);for(;e&&o.isCallExpression(e);){const r=a(e.getExpression());if(!r||!o.isPropertyAccessExpression(r))return{root:void 0,steps:i};i.push({call:e,name:r.getName()}),e=a(r.getExpression())}return{root:e,steps:i}},f=t=>p(t).steps,x=(t,i,e)=>f(t).filter(r=>r.name===i).map(r=>r.call.getArguments()[0]).filter(r=>r!==void 0&&o.isCallExpression(r)&&h(r.getExpression(),e)),w=(t,i)=>f(t).some(e=>e.name===i),P=(t,i,e)=>x(t,i,e).length>0,l=new Set(["action","mutation","query","stream"]),m={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},N={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init",onWhisper:"whisper"},I=t=>t==="whisper"?"query":"mutation",C=t=>{const{root:i}=p(t);return i&&o.isIdentifier(i)?i:void 0},g=(t,i=!1)=>{const e=C(t);if(!e)return;const r=d(e);if(r===void 0){if(i)return;const n=e.getSymbol()?.getValueDeclaration();if(n&&o.isVariableDeclaration(n)){const s=n.getInitializer();return s?g(s,!0):void 0}return}return l.has(r)?"public":m[r]?"internal":void 0},E=t=>{const i=t.getName();if(!l.has(i))return;const e=t.getExpression(),r=a(e)??e,n=e===r?[r]:[e,r];if(n.some(c=>c.getType().getProperty("__lunoraProcedure"))){const c=n.some(v=>v.getType().getProperty("__lunoraVisibility"));return{kind:i,receiver:r,visibility:c?"internal":"public"}}const s=g(r);if(s)return{kind:i,receiver:r,visibility:s}},D=t=>{const i=t.getExpression();if(o.isPropertyAccessExpression(i))return E(i);if(!o.isIdentifier(i))return;const e=d(i);if(!e)return;if(l.has(e))return{kind:e,visibility:"public"};const r=m[e];if(r)return{kind:r,visibility:"internal"};const n=N[e];if(n)return{kind:I(n),lifecycle:n,visibility:"internal"}};export{A as a,f as b,D as c,P as d,w as e,x as w};
1
+ import{Node as o}from"ts-morph";import{unwrapExpression as a}from"./listLunoraSourceFiles-DP-5e-RE.mjs";import{a as u}from"./module-specifiers-WF8iAydP.mjs";const A=t=>o.isIdentifier(t)?t.getText():o.isPropertyAccessExpression(t)?t.getName():void 0,y=(t,i)=>{const e=new Set;for(const r of t.getImportDeclarations())if(u(r.getModuleSpecifierValue()))for(const n of r.getNamedImports())n.getNameNode().getText()===i&&e.add(n.getAliasNode()?.getText()??n.getName());return e},h=(t,i)=>{if(o.isPropertyAccessExpression(t))return t.getName()===i;if(!o.isIdentifier(t))return!1;const e=t.getText();return e===i||y(t.getSourceFile(),i).has(e)},d=t=>{const i=t.getSymbol();if(!i)return t.getText();for(const e of i.getDeclarations())if(o.isImportSpecifier(e))return u(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText():void 0},p=t=>{const i=[];let e=a(t);for(;e&&o.isCallExpression(e);){const r=a(e.getExpression());if(!r||!o.isPropertyAccessExpression(r))return{root:void 0,steps:i};i.push({call:e,name:r.getName()}),e=a(r.getExpression())}return{root:e,steps:i}},f=t=>p(t).steps,x=(t,i,e)=>f(t).filter(r=>r.name===i).map(r=>r.call.getArguments()[0]).filter(r=>r!==void 0&&o.isCallExpression(r)&&h(r.getExpression(),e)),w=(t,i)=>f(t).some(e=>e.name===i),P=(t,i,e)=>x(t,i,e).length>0,l=new Set(["action","mutation","query","stream"]),m={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},N={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init",onWhisper:"whisper"},I=t=>t==="whisper"?"query":"mutation",C=t=>{const{root:i}=p(t);return i&&o.isIdentifier(i)?i:void 0},g=(t,i=!1)=>{const e=C(t);if(!e)return;const r=d(e);if(r===void 0){if(i)return;const n=e.getSymbol()?.getValueDeclaration();if(n&&o.isVariableDeclaration(n)){const s=n.getInitializer();return s?g(s,!0):void 0}return}return l.has(r)?"public":m[r]?"internal":void 0},E=t=>{const i=t.getName();if(!l.has(i))return;const e=t.getExpression(),r=a(e)??e,n=e===r?[r]:[e,r];if(n.some(c=>c.getType().getProperty("__lunoraProcedure"))){const c=n.some(v=>v.getType().getProperty("__lunoraVisibility"));return{kind:i,receiver:r,visibility:c?"internal":"public"}}const s=g(r);if(s)return{kind:i,receiver:r,visibility:s}},D=t=>{const i=t.getExpression();if(o.isPropertyAccessExpression(i))return E(i);if(!o.isIdentifier(i))return;const e=d(i);if(!e)return;if(l.has(e))return{kind:e,visibility:"public"};const r=m[e];if(r)return{kind:r,visibility:"internal"};const n=N[e];if(n)return{kind:I(n),lifecycle:n,visibility:"internal"}};export{A as a,f as b,D as c,P as d,w as e,x as w};
@@ -1 +1 @@
1
- import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as d,lunoraRelativePath as l,handlerOf as f}from"./listLunoraSourceFiles-vjwjgpjd.mjs";import{c as u}from"./classify-procedure-call-CZU6n3yF.mjs";const x=e=>{const n=e.getInitializer();if(!n||!s.isCallExpression(n))return;const r=u(n);if(!r||r.kind!=="query"&&r.kind!=="mutation")return;const t=f(n,r.receiver);return t?{exportName:e.getName(),handler:t,kind:r.kind}:void 0},p=(e,n)=>{if(!s.isPropertyAccessExpression(e)||e.getName()!==n)return;const r=e.getExpression();if(!s.isIdentifier(r)||r.getText()!=="ctx")return;const t=e.getParent();return t&&s.isPropertyAccessExpression(t)&&t.getExpression()===e?`ctx.${n}.${t.getName()}`:`ctx.${n}`},m=(e,n,r)=>{const t=[];for(const o of e.handler.getDescendantsOfKind(a.PropertyAccessExpression)){const i=p(o,r);i!==void 0&&t.push({callee:i,exportName:e.exportName,file:n,kind:e.kind,line:o.getStartLineNumber()})}return t},g=(e,n,r)=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const i of o.getDeclarations()){const c=x(i);c&&t.push(...m(c,n,r))}return t},N=(e,n,r)=>{const t=[];for(const o of d(n)){const i=e.getSourceFile(o)??e.addSourceFileAtPath(o);t.push(...g(i,l(n,o),r))}return t};export{N as d};
1
+ import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as d,lunoraRelativePath as l,handlerOf as f}from"./listLunoraSourceFiles-DP-5e-RE.mjs";import{c as u}from"./classify-procedure-call-BztLe76A.mjs";const x=e=>{const n=e.getInitializer();if(!n||!s.isCallExpression(n))return;const r=u(n);if(!r||r.kind!=="query"&&r.kind!=="mutation")return;const t=f(n,r.receiver);return t?{exportName:e.getName(),handler:t,kind:r.kind}:void 0},p=(e,n)=>{if(!s.isPropertyAccessExpression(e)||e.getName()!==n)return;const r=e.getExpression();if(!s.isIdentifier(r)||r.getText()!=="ctx")return;const t=e.getParent();return t&&s.isPropertyAccessExpression(t)&&t.getExpression()===e?`ctx.${n}.${t.getName()}`:`ctx.${n}`},m=(e,n,r)=>{const t=[];for(const o of e.handler.getDescendantsOfKind(a.PropertyAccessExpression)){const i=p(o,r);i!==void 0&&t.push({callee:i,exportName:e.exportName,file:n,kind:e.kind,line:o.getStartLineNumber()})}return t},g=(e,n,r)=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const i of o.getDeclarations()){const c=x(i);c&&t.push(...m(c,n,r))}return t},N=(e,n,r)=>{const t=[];for(const o of d(n)){const i=e.getSourceFile(o)??e.addSourceFileAtPath(o);t.push(...g(i,l(n,o),r))}return t};export{N as d};
@@ -1 +1 @@
1
- import{SyntaxKind as u,Node as r}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as g,enclosingExportName as d,propertyKeyName as m}from"./listLunoraSourceFiles-vjwjgpjd.mjs";const h=s=>{const t=s.getExpression();if(!r.isPropertyAccessExpression(t))return!1;const e=t.getExpression();return r.isPropertyAccessExpression(e)?e.getName()==="authApi":r.isIdentifier(e)&&e.getText()==="authApi"},A=s=>{const t=s.getArguments()[0];if(t===void 0)return!1;if(!r.isObjectLiteralExpression(t))return!0;for(const e of t.getProperties())if((r.isPropertyAssignment(e)||r.isShorthandPropertyAssignment(e))&&m(e)==="headers"||r.isSpreadAssignment(e))return!0;return!1},E=(s,t)=>{const e=[];for(const n of f(t)){const c=s.getSourceFile(n)??s.addSourceFileAtPath(n),l=g(t,n);for(const i of c.getDescendantsOfKind(u.CallExpression)){if(!h(i))continue;const o=d(i);if(o==="")continue;const a=i.getExpression(),p=r.isPropertyAccessExpression(a)?a.getName():"";e.push({exportName:o,file:l,hasHeaders:A(i),line:i.getStartLineNumber(),method:p})}}return e};export{E as default};
1
+ import{SyntaxKind as u,Node as r}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as g,enclosingExportName as d,propertyKeyName as m}from"./listLunoraSourceFiles-DP-5e-RE.mjs";const h=s=>{const t=s.getExpression();if(!r.isPropertyAccessExpression(t))return!1;const e=t.getExpression();return r.isPropertyAccessExpression(e)?e.getName()==="authApi":r.isIdentifier(e)&&e.getText()==="authApi"},A=s=>{const t=s.getArguments()[0];if(t===void 0)return!1;if(!r.isObjectLiteralExpression(t))return!0;for(const e of t.getProperties())if((r.isPropertyAssignment(e)||r.isShorthandPropertyAssignment(e))&&m(e)==="headers"||r.isSpreadAssignment(e))return!0;return!1},E=(s,t)=>{const e=[];for(const n of f(t)){const c=s.getSourceFile(n)??s.addSourceFileAtPath(n),l=g(t,n);for(const i of c.getDescendantsOfKind(u.CallExpression)){if(!h(i))continue;const o=d(i);if(o==="")continue;const a=i.getExpression(),p=r.isPropertyAccessExpression(a)?a.getName():"";e.push({exportName:o,file:l,hasHeaders:A(i),line:i.getStartLineNumber(),method:p})}}return e};export{E as default};
@@ -1 +1 @@
1
- import{LunoraError as L}from"@lunora/errors";import{CRON_SCHEDULE_KINDS as A,isValidCronExpression as O,warnIfSecondsLeading as S,compileCronSchedule as b}from"@lunora/scheduler";import{SyntaxKind as p,Node as s}from"ts-morph";import{diagnosticAt as f,CodegenDiagnosticError as I}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{i as R}from"./module-specifiers-WF8iAydP.mjs";import{s as $}from"./paths-C-9fwEgQ.mjs";import{listLunoraSourceFiles as y,propertyKeyName as P}from"./listLunoraSourceFiles-vjwjgpjd.mjs";const D=new Set([...A,"cron"]),v=e=>{const t=e.getSymbol();if(!t)return e.getText()==="cronJobs";for(const r of t.getDeclarations())if(s.isImportSpecifier(r))return R(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="cronJobs":!1;return!1},F=e=>{const t=new Set;for(const r of e.getVariableDeclarations()){const n=r.getInitializer();if(n?.getKind()!==p.CallExpression)continue;const i=n.getExpression();s.isIdentifier(i)&&v(i)&&t.add(r.getName())}return t},V=e=>{let t=e;for(;s.isCallExpression(t)||s.isPropertyAccessExpression(t);)t=t.getExpression();return s.isIdentifier(t)?t.getText():void 0},x=(e,t)=>{const r=e.getArguments()[t];return r&&(s.isStringLiteral(r)||s.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},_=(e,t)=>{if(s.isStringLiteral(e)||s.isNoSubstitutionTemplateLiteral(e)||s.isNumericLiteral(e))return e.getLiteralValue();if(s.isTrueLiteral(e))return!0;if(s.isFalseLiteral(e))return!1;if(s.isPrefixUnaryExpression(e)&&e.getOperatorToken()===p.MinusToken){const r=e.getOperand();if(s.isNumericLiteral(r))return-r.getLiteralValue()}if(s.isObjectLiteralExpression(e))return m(e,t);if(s.isArrayLiteralExpression(e))return e.getElements().map(r=>_(r,t));throw f(e,`Cron job "${t}" passes a non-static value where a literal is required; codegen can only read literals.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500})},m=(e,t)=>{const r={};for(const n of e.getProperties()){if(!s.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 i=n.getInitializer();i&&(r[P(n)]=_(i,t))}return r},C=(e,t,r)=>{const n=e.getArguments()[t];if(!n||!s.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 i=n.getName(),o=n.getExpression();if(!s.isPropertyAccessExpression(o))throw f(n,`Cron job "${r}" function reference must be of the form internal.file.fn (two property accesses).`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const a=o.getName();return`${$(a)}:${i}`},h=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),w=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),T=(e,t,r,n,i,o)=>{const a=e.getExpression();if(!s.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 ${i} is declared in lunora/${i}s.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})},j=(e,t,r,n,i)=>{const o=e.getArguments()[t];if(o&&s.isPropertyAccessExpression(o)){const a=T(o,"workflows",n,r,"workflow",h);if(a)return a;const c=T(o,"agents",i,r,"agent",w);return c||{functionPath:C(e,t,r)}}if(o&&s.isIdentifier(o)){const a=n.get(o.getText()),c=i.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)}},k=/^@lunora\/scheduler:\s*/u,U=(e,t)=>{const r=x(e,1);if(r===void 0)throw f(e,`Cron job "${t}" must pass a string-literal cron expression to ".cron(...)".`,{code:"CRON_EXPR_NOT_STATIC",name:"LunoraError",status:500});if(!O(r))throw f(e,`Cron job "${t}" has an invalid cron expression "${r}" — expected 5 or 6 space-separated fields.`,{code:"CRON_EXPR_INVALID",name:"LunoraError",status:500});return S(r,`cron expression for job "${t}"`),r},M=(e,t,r)=>{const n=e.getArguments()[1];if(!n||!s.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 b(t,m(n,r),r)}catch(i){if(i instanceof I)throw i;const o=i instanceof Error?i.message.replace(k,""):String(i);throw f(e,o,{code:"CRON_SCHEDULE_INVALID",name:"LunoraError",status:500})}},z=(e,t,r,n,i)=>{const o=t.getName();if(!D.has(o)||!r.has(V(t.getExpression())??""))return;const a=x(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"?U(e,a):M(e,o,a),u=j(e,2,a,n,i),l=e.getArguments()[3];return{args:l&&s.isObjectLiteralExpression(l)?m(l,a):{},cron:c,name:a,...u}},H=e=>{const t=new Set;for(const r of e){if(t.has(r.name))throw new L("DUPLICATE_CRON_NAME",`Duplicate cron job name "${r.name}": cron names must be unique across the project.`,{status:500});t.add(r.name)}},W=(e,t,r=[],n=[])=>{const i=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 i){const l=e.getSourceFile(u)??e.addSourceFileAtPath(u),g=F(l);if(g.size!==0)for(const d of l.getDescendantsOfKind(p.CallExpression)){const N=d.getExpression();if(!s.isPropertyAccessExpression(N))continue;const E=z(d,N,g,a,c);E&&o.push(E)}}return o.sort((u,l)=>u.name.localeCompare(l.name)),H(o),o};export{W as default};
1
+ import{LunoraError as L}from"@lunora/errors";import{CRON_SCHEDULE_KINDS as A,isValidCronExpression as O,warnIfSecondsLeading as S,compileCronSchedule as b}from"@lunora/scheduler";import{SyntaxKind as p,Node as s}from"ts-morph";import{diagnosticAt as f,CodegenDiagnosticError as I}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{i as R}from"./module-specifiers-WF8iAydP.mjs";import{s as $}from"./paths-C-9fwEgQ.mjs";import{listLunoraSourceFiles as y,propertyKeyName as P}from"./listLunoraSourceFiles-DP-5e-RE.mjs";const D=new Set([...A,"cron"]),v=e=>{const t=e.getSymbol();if(!t)return e.getText()==="cronJobs";for(const r of t.getDeclarations())if(s.isImportSpecifier(r))return R(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="cronJobs":!1;return!1},F=e=>{const t=new Set;for(const r of e.getVariableDeclarations()){const n=r.getInitializer();if(n?.getKind()!==p.CallExpression)continue;const i=n.getExpression();s.isIdentifier(i)&&v(i)&&t.add(r.getName())}return t},V=e=>{let t=e;for(;s.isCallExpression(t)||s.isPropertyAccessExpression(t);)t=t.getExpression();return s.isIdentifier(t)?t.getText():void 0},x=(e,t)=>{const r=e.getArguments()[t];return r&&(s.isStringLiteral(r)||s.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},_=(e,t)=>{if(s.isStringLiteral(e)||s.isNoSubstitutionTemplateLiteral(e)||s.isNumericLiteral(e))return e.getLiteralValue();if(s.isTrueLiteral(e))return!0;if(s.isFalseLiteral(e))return!1;if(s.isPrefixUnaryExpression(e)&&e.getOperatorToken()===p.MinusToken){const r=e.getOperand();if(s.isNumericLiteral(r))return-r.getLiteralValue()}if(s.isObjectLiteralExpression(e))return m(e,t);if(s.isArrayLiteralExpression(e))return e.getElements().map(r=>_(r,t));throw f(e,`Cron job "${t}" passes a non-static value where a literal is required; codegen can only read literals.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500})},m=(e,t)=>{const r={};for(const n of e.getProperties()){if(!s.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 i=n.getInitializer();i&&(r[P(n)]=_(i,t))}return r},C=(e,t,r)=>{const n=e.getArguments()[t];if(!n||!s.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 i=n.getName(),o=n.getExpression();if(!s.isPropertyAccessExpression(o))throw f(n,`Cron job "${r}" function reference must be of the form internal.file.fn (two property accesses).`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const a=o.getName();return`${$(a)}:${i}`},h=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),w=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),T=(e,t,r,n,i,o)=>{const a=e.getExpression();if(!s.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 ${i} is declared in lunora/${i}s.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})},j=(e,t,r,n,i)=>{const o=e.getArguments()[t];if(o&&s.isPropertyAccessExpression(o)){const a=T(o,"workflows",n,r,"workflow",h);if(a)return a;const c=T(o,"agents",i,r,"agent",w);return c||{functionPath:C(e,t,r)}}if(o&&s.isIdentifier(o)){const a=n.get(o.getText()),c=i.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)}},k=/^@lunora\/scheduler:\s*/u,U=(e,t)=>{const r=x(e,1);if(r===void 0)throw f(e,`Cron job "${t}" must pass a string-literal cron expression to ".cron(...)".`,{code:"CRON_EXPR_NOT_STATIC",name:"LunoraError",status:500});if(!O(r))throw f(e,`Cron job "${t}" has an invalid cron expression "${r}" — expected 5 or 6 space-separated fields.`,{code:"CRON_EXPR_INVALID",name:"LunoraError",status:500});return S(r,`cron expression for job "${t}"`),r},M=(e,t,r)=>{const n=e.getArguments()[1];if(!n||!s.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 b(t,m(n,r),r)}catch(i){if(i instanceof I)throw i;const o=i instanceof Error?i.message.replace(k,""):String(i);throw f(e,o,{code:"CRON_SCHEDULE_INVALID",name:"LunoraError",status:500})}},z=(e,t,r,n,i)=>{const o=t.getName();if(!D.has(o)||!r.has(V(t.getExpression())??""))return;const a=x(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"?U(e,a):M(e,o,a),u=j(e,2,a,n,i),l=e.getArguments()[3];return{args:l&&s.isObjectLiteralExpression(l)?m(l,a):{},cron:c,name:a,...u}},H=e=>{const t=new Set;for(const r of e){if(t.has(r.name))throw new L("DUPLICATE_CRON_NAME",`Duplicate cron job name "${r.name}": cron names must be unique across the project.`,{status:500});t.add(r.name)}},W=(e,t,r=[],n=[])=>{const i=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 i){const l=e.getSourceFile(u)??e.addSourceFileAtPath(u),g=F(l);if(g.size!==0)for(const d of l.getDescendantsOfKind(p.CallExpression)){const N=d.getExpression();if(!s.isPropertyAccessExpression(N))continue;const E=z(d,N,g,a,c);E&&o.push(E)}}return o.sort((u,l)=>u.name.localeCompare(l.name)),H(o),o};export{W as default};
@@ -1 +1 @@
1
- import{d as P}from"./declared-output-Iaar469J.mjs";import{s as b}from"./paths-C-9fwEgQ.mjs";import{findObjectProperty as c,bindingKeyName as A,listLunoraSourceFiles as F,lunoraRelativePath as N}from"./listLunoraSourceFiles-vjwjgpjd.mjs";import{u as y,p as O,c as m,r as z}from"./unwrap-handler-return-C1OS0xP8.mjs";import{b as d,c as C}from"./classify-procedure-call-CZU6n3yF.mjs";import{Node as n,SyntaxKind as S}from"ts-morph";import{r as h,p as x,a as L}from"./parse-validator-2u-Io0i5.mjs";const k=i=>{const t=i.getArguments()[0];if(!t||!n.isObjectLiteralExpression(t))return"unknown";const e=c(t,"handler");if(!e||!n.isPropertyAssignment(e))return"unknown";const r=e.getInitializer();return!r||!(n.isArrowFunction(r)||n.isFunctionExpression(r))?"unknown":y(r)},I=i=>{const t=i.getArguments()[0];return!t||!(n.isArrowFunction(t)||n.isFunctionExpression(t))?"unknown":y(t)},T=i=>{let t={};for(const e of d(i)){if(e.name!=="input")continue;const r=e.call.getArguments()[0],s=r!==void 0&&n.isExpression(r)?h(r):void 0;s!==void 0&&(t={...x(s),...t})}return t},V=i=>{const t=d(i).find(r=>r.name==="output");if(!t)return;const e=t.call.getArguments()[0];return e&&n.isExpression(e)?O(t.call,()=>L(e)):void 0},p=(i,t)=>{const e=c(i,t);if(e===void 0||!n.isPropertyAssignment(e))return;const r=e.getInitializer();return r!==void 0&&n.isStringLiteral(r)?r.getLiteralValue():void 0},v=(i,t)=>{const e=c(i,t);if(e===void 0||!n.isPropertyAssignment(e))return;const r=e.getInitializer();return r!==void 0&&n.isNumericLiteral(r)?r.getLiteralValue():void 0},w=i=>{const t=c(i,"cache");if(t===void 0||!n.isPropertyAssignment(t))return;const e=t.getInitializer();if(e===void 0||!n.isObjectLiteralExpression(e))return;const r=p(e,"scope"),s=v(e,"maxAge"),o=v(e,"staleWhileRevalidate"),a=p(e,"tag"),l=p(e,"vary"),g={...s===void 0?{}:{maxAge:s},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...l===void 0?{}:{vary:l}};return Object.keys(g).length===0?void 0:g},D=i=>{if(i===void 0||!n.isObjectLiteralExpression(i))return{};const t=w(i),e=c(i,"rest");return e!==void 0&&n.isPropertyAssignment(e)?{...t===void 0?{}:{cache:t},rest:e.getInitializer()?.getText()==="true"}:t===void 0?{}:{cache:t}},j=i=>{const t=d(i).find(e=>e.name==="expose");return t?D(t.call.getArguments()[0]):void 0},R=i=>{const t=i.getArguments()[0];if(!t||!n.isObjectLiteralExpression(t))return{};const e=c(t,"args");if(!e||!n.isPropertyAssignment(e))return{};const r=e.getInitializer(),s=r===void 0?void 0:h(r);return s===void 0?{}:x(s)},B=8,u=(i,t=0)=>{if(t>B)return;if(n.isCallExpression(i))return i;if(n.isParenthesizedExpression(i)||n.isAsExpression(i)||n.isSatisfiesExpression(i)||n.isNonNullExpression(i))return u(i.getExpression(),t+1);if(!n.isIdentifier(i)&&!n.isPropertyAccessExpression(i))return;const e=i.getSymbol()?.getValueDeclaration();return e?f(e,t+1):void 0},f=(i,t)=>{if(n.isVariableDeclaration(i)||n.isPropertyAssignment(i)){const e=i.getInitializer();return e?u(e,t):void 0}if(n.isShorthandPropertyAssignment(i)){const e=i.getValueSymbol()?.getValueDeclaration();return e?f(e,t+1):void 0}if(n.isBindingElement(i)){const e=A(i),o=i.getFirstAncestorByKind(S.VariableDeclaration)?.getInitializer()?.getType().getProperty(e)?.getValueDeclaration();return o?f(o,t+1):void 0}},$=i=>{const t=i.getNameNode();if(n.isObjectBindingPattern(t)){const s=[];for(const o of t.getElements()){const a=u(o.getNameNode());a&&s.push([o.getName(),a])}return s}const e=i.getInitializer(),r=e&&(n.isCallExpression(e)?e:u(e));return r?[[i.getName(),r]]:[]},W=i=>{const t=C(i);if(!t)return;const{receiver:e}=t;if(e){const r=j(e),s=m(()=>V(e)),o=m(()=>I(i)),a=P({kind:t.kind,output:s.value});return z(a?s.erased:o.erased),{args:T(e),...r?{expose:r}:{},kind:t.kind,...s.value?{output:s.value}:{},returnType:o.value,visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:R(i),kind:t.kind,returnType:k(i),visibility:t.visibility}},E=(i,t,e)=>{const r=W(i);if(r)return{args:r.args,exportName:t,filePath:e,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},_=(i,t)=>{const e=[];for(const r of i.getExportAssignments()){if(r.isExportEquals())continue;const s=u(r.getExpression()),o=s?E(s,"default",t):void 0;o&&e.push(o)}return e},H=(i,t)=>{const e=[];for(const r of i.getVariableStatements())if(r.isExported())for(const s of r.getDeclarations())for(const[o,a]of $(s)){const l=E(a,o,t);l&&e.push(l)}return e.push(..._(i,t)),e},K=i=>{const t=new Map;for(const e of i){const r=b(e.filePath),s=t.get(r);if(s&&s!==e.filePath)throw Object.assign(new Error(`Namespace collision: "${s}" and "${e.filePath}" both resolve to "${r}". 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:[s,e.filePath],status:500});t.set(r,e.filePath)}},Y=(i,t)=>{const e=F(t),r=[];for(const s of e){const o=i.getSourceFile(s)??i.addSourceFileAtPath(s),a=N(t,s);r.push(...H(o,a))}return r.sort((s,o)=>`${s.filePath}:${s.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),K(r),r};export{Y as default};
1
+ import{d as P}from"./declared-output-Iaar469J.mjs";import{s as b}from"./paths-C-9fwEgQ.mjs";import{findObjectProperty as c,bindingKeyName as A,listLunoraSourceFiles as F,lunoraRelativePath as N}from"./listLunoraSourceFiles-DP-5e-RE.mjs";import{u as y,p as O,c as m,r as z}from"./unwrap-handler-return-CoV_GK33.mjs";import{b as d,c as C}from"./classify-procedure-call-BztLe76A.mjs";import{Node as n,SyntaxKind as S}from"ts-morph";import{r as h,p as x,a as L}from"./parse-validator-C94Yiabo.mjs";const k=i=>{const t=i.getArguments()[0];if(!t||!n.isObjectLiteralExpression(t))return"unknown";const e=c(t,"handler");if(!e||!n.isPropertyAssignment(e))return"unknown";const r=e.getInitializer();return!r||!(n.isArrowFunction(r)||n.isFunctionExpression(r))?"unknown":y(r)},I=i=>{const t=i.getArguments()[0];return!t||!(n.isArrowFunction(t)||n.isFunctionExpression(t))?"unknown":y(t)},T=i=>{let t={};for(const e of d(i)){if(e.name!=="input")continue;const r=e.call.getArguments()[0],s=r!==void 0&&n.isExpression(r)?h(r):void 0;s!==void 0&&(t={...x(s),...t})}return t},V=i=>{const t=d(i).find(r=>r.name==="output");if(!t)return;const e=t.call.getArguments()[0];return e&&n.isExpression(e)?O(t.call,()=>L(e)):void 0},p=(i,t)=>{const e=c(i,t);if(e===void 0||!n.isPropertyAssignment(e))return;const r=e.getInitializer();return r!==void 0&&n.isStringLiteral(r)?r.getLiteralValue():void 0},v=(i,t)=>{const e=c(i,t);if(e===void 0||!n.isPropertyAssignment(e))return;const r=e.getInitializer();return r!==void 0&&n.isNumericLiteral(r)?r.getLiteralValue():void 0},w=i=>{const t=c(i,"cache");if(t===void 0||!n.isPropertyAssignment(t))return;const e=t.getInitializer();if(e===void 0||!n.isObjectLiteralExpression(e))return;const r=p(e,"scope"),s=v(e,"maxAge"),o=v(e,"staleWhileRevalidate"),a=p(e,"tag"),l=p(e,"vary"),g={...s===void 0?{}:{maxAge:s},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...l===void 0?{}:{vary:l}};return Object.keys(g).length===0?void 0:g},D=i=>{if(i===void 0||!n.isObjectLiteralExpression(i))return{};const t=w(i),e=c(i,"rest");return e!==void 0&&n.isPropertyAssignment(e)?{...t===void 0?{}:{cache:t},rest:e.getInitializer()?.getText()==="true"}:t===void 0?{}:{cache:t}},j=i=>{const t=d(i).find(e=>e.name==="expose");return t?D(t.call.getArguments()[0]):void 0},R=i=>{const t=i.getArguments()[0];if(!t||!n.isObjectLiteralExpression(t))return{};const e=c(t,"args");if(!e||!n.isPropertyAssignment(e))return{};const r=e.getInitializer(),s=r===void 0?void 0:h(r);return s===void 0?{}:x(s)},B=8,u=(i,t=0)=>{if(t>B)return;if(n.isCallExpression(i))return i;if(n.isParenthesizedExpression(i)||n.isAsExpression(i)||n.isSatisfiesExpression(i)||n.isNonNullExpression(i))return u(i.getExpression(),t+1);if(!n.isIdentifier(i)&&!n.isPropertyAccessExpression(i))return;const e=i.getSymbol()?.getValueDeclaration();return e?f(e,t+1):void 0},f=(i,t)=>{if(n.isVariableDeclaration(i)||n.isPropertyAssignment(i)){const e=i.getInitializer();return e?u(e,t):void 0}if(n.isShorthandPropertyAssignment(i)){const e=i.getValueSymbol()?.getValueDeclaration();return e?f(e,t+1):void 0}if(n.isBindingElement(i)){const e=A(i),o=i.getFirstAncestorByKind(S.VariableDeclaration)?.getInitializer()?.getType().getProperty(e)?.getValueDeclaration();return o?f(o,t+1):void 0}},$=i=>{const t=i.getNameNode();if(n.isObjectBindingPattern(t)){const s=[];for(const o of t.getElements()){const a=u(o.getNameNode());a&&s.push([o.getName(),a])}return s}const e=i.getInitializer(),r=e&&(n.isCallExpression(e)?e:u(e));return r?[[i.getName(),r]]:[]},W=i=>{const t=C(i);if(!t)return;const{receiver:e}=t;if(e){const r=j(e),s=m(()=>V(e)),o=m(()=>I(i)),a=P({kind:t.kind,output:s.value});return z(a?s.erased:o.erased),{args:T(e),...r?{expose:r}:{},kind:t.kind,...s.value?{output:s.value}:{},returnType:o.value,visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:R(i),kind:t.kind,returnType:k(i),visibility:t.visibility}},E=(i,t,e)=>{const r=W(i);if(r)return{args:r.args,exportName:t,filePath:e,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},_=(i,t)=>{const e=[];for(const r of i.getExportAssignments()){if(r.isExportEquals())continue;const s=u(r.getExpression()),o=s?E(s,"default",t):void 0;o&&e.push(o)}return e},H=(i,t)=>{const e=[];for(const r of i.getVariableStatements())if(r.isExported())for(const s of r.getDeclarations())for(const[o,a]of $(s)){const l=E(a,o,t);l&&e.push(l)}return e.push(..._(i,t)),e},K=i=>{const t=new Map;for(const e of i){const r=b(e.filePath),s=t.get(r);if(s&&s!==e.filePath)throw Object.assign(new Error(`Namespace collision: "${s}" and "${e.filePath}" both resolve to "${r}". 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:[s,e.filePath],status:500});t.set(r,e.filePath)}},Y=(i,t)=>{const e=F(t),r=[];for(const s of e){const o=i.getSourceFile(s)??i.addSourceFileAtPath(s),a=N(t,s);r.push(...H(o,a))}return r.sort((s,o)=>`${s.filePath}:${s.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),K(r),r};export{Y as default};
@@ -1 +1 @@
1
- import{Node as i}from"ts-morph";import{a as m,p as l}from"./parse-validator-2u-Io0i5.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./listLunoraSourceFiles-vjwjgpjd.mjs";import{u as f}from"./unwrap-handler-return-C1OS0xP8.mjs";const u=new Set(["delete","get","head","options","patch","post","put"]),g=new Set(["body","params","searchParams"]),E=new Set(["handler","stream"]),v=r=>{const e=r.getArguments()[0];if(e&&i.isStringLiteral(e))return e.getLiteralValue()},x=r=>{const e=r.getArguments()[0];return e&&i.isObjectLiteralExpression(e)?l(e):{}},P=r=>{if(!i.isCallExpression(r))return;const e=r.getExpression();if(!i.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const n=e.getExpression();if(!i.isIdentifier(n)||n.getText()!=="httpRoute")return;const s=v(r);return s===void 0?void 0:{method:o.toUpperCase(),path:s}},S=(r,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},n=r.getExpression();if(!i.isPropertyAccessExpression(n))return;let s=n.getExpression();for(;i.isCallExpression(s);){const a=s.getExpression();if(!i.isPropertyAccessExpression(a))break;const c=a.getName();if(u.has(c))break;if(g.has(c)){const p=x(s);o[c]={...p,...o[c]}}else if(c==="output"&&o.output===void 0){const p=s.getArguments()[0];p&&i.isExpression(p)&&(o.output=m(p))}s=a.getExpression()}const t=P(s);if(t)return o.method=t.method,o.path=t.path,o},A=r=>{const e=r.getArguments()[0];return!e||!(i.isArrowFunction(e)||i.isFunctionExpression(e))?"unknown":f(e)},T=(r,e,o,n)=>{const s=e.getName();if(!E.has(s))return;const t=S(r,s);if(!(t?.method===void 0||t.path===void 0))return{body:t.body,exportName:o,filePath:n,method:t.method,params:t.params,path:t.path,searchParams:t.searchParams,stream:t.stream,...t.stream?{chunkType:A(r)}:{},...t.output?{output:t.output}:{}}},b=(r,e)=>{const o=[];for(const n of r.getVariableStatements())if(n.isExported())for(const s of n.getDeclarations()){const t=s.getInitializer();if(!t||!i.isCallExpression(t))continue;const a=t.getExpression();if(!i.isPropertyAccessExpression(a))continue;const c=T(t,a,s.getName(),e);c&&o.push(c)}return o},F=(r,e)=>{const o=d(e),n=[];for(const s of o){const t=r.getSourceFile(s)??r.addSourceFileAtPath(s),a=h(e,s);n.push(...b(t,a))}return n.sort((s,t)=>`${s.method} ${s.path}`.localeCompare(`${t.method} ${t.path}`)||s.filePath.localeCompare(t.filePath)),n};export{F as default};
1
+ import{Node as i}from"ts-morph";import{a as m,p as l}from"./parse-validator-C94Yiabo.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./listLunoraSourceFiles-DP-5e-RE.mjs";import{u as f}from"./unwrap-handler-return-CoV_GK33.mjs";const u=new Set(["delete","get","head","options","patch","post","put"]),g=new Set(["body","params","searchParams"]),E=new Set(["handler","stream"]),v=r=>{const e=r.getArguments()[0];if(e&&i.isStringLiteral(e))return e.getLiteralValue()},x=r=>{const e=r.getArguments()[0];return e&&i.isObjectLiteralExpression(e)?l(e):{}},P=r=>{if(!i.isCallExpression(r))return;const e=r.getExpression();if(!i.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const n=e.getExpression();if(!i.isIdentifier(n)||n.getText()!=="httpRoute")return;const s=v(r);return s===void 0?void 0:{method:o.toUpperCase(),path:s}},S=(r,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},n=r.getExpression();if(!i.isPropertyAccessExpression(n))return;let s=n.getExpression();for(;i.isCallExpression(s);){const a=s.getExpression();if(!i.isPropertyAccessExpression(a))break;const c=a.getName();if(u.has(c))break;if(g.has(c)){const p=x(s);o[c]={...p,...o[c]}}else if(c==="output"&&o.output===void 0){const p=s.getArguments()[0];p&&i.isExpression(p)&&(o.output=m(p))}s=a.getExpression()}const t=P(s);if(t)return o.method=t.method,o.path=t.path,o},A=r=>{const e=r.getArguments()[0];return!e||!(i.isArrowFunction(e)||i.isFunctionExpression(e))?"unknown":f(e)},T=(r,e,o,n)=>{const s=e.getName();if(!E.has(s))return;const t=S(r,s);if(!(t?.method===void 0||t.path===void 0))return{body:t.body,exportName:o,filePath:n,method:t.method,params:t.params,path:t.path,searchParams:t.searchParams,stream:t.stream,...t.stream?{chunkType:A(r)}:{},...t.output?{output:t.output}:{}}},b=(r,e)=>{const o=[];for(const n of r.getVariableStatements())if(n.isExported())for(const s of n.getDeclarations()){const t=s.getInitializer();if(!t||!i.isCallExpression(t))continue;const a=t.getExpression();if(!i.isPropertyAccessExpression(a))continue;const c=T(t,a,s.getName(),e);c&&o.push(c)}return o},F=(r,e)=>{const o=d(e),n=[];for(const s of o){const t=r.getSourceFile(s)??r.addSourceFileAtPath(s),a=h(e,s);n.push(...b(t,a))}return n.sort((s,t)=>`${s.method} ${s.path}`.localeCompare(`${t.method} ${t.path}`)||s.filePath.localeCompare(t.filePath)),n};export{F as default};
@@ -0,0 +1 @@
1
+ import{d as o}from"./context-property-calls-CjDzLU8p.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
@@ -1 +1 @@
1
- import{SyntaxKind as c,Node as n}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as u,enclosingExportName as g,isDatabaseAccessor as d}from"./listLunoraSourceFiles-vjwjgpjd.mjs";const m=t=>{const e=t.getExpression();if(!n.isPropertyAccessExpression(e)||e.getName()!=="insert")return!1;const r=e.getExpression();return d(r)},p=t=>{if(!n.isIdentifier(t))return;const e=t.getSymbol(),r=e?.getAliasedSymbol()?.getDeclarations()??e?.getDeclarations()??[];for(const i of r)if(n.isVariableDeclaration(i)){const s=i.getInitializer();if(s&&n.isStringLiteral(s))return s.getLiteralText()}},x=t=>{const e=t.getArguments()[0];return e?n.isStringLiteral(e)?e.getLiteralText():p(e)??"":""},v=(t,e)=>{const r=[];for(const i of f(e)){const s=t.getSourceFile(i)??t.addSourceFileAtPath(i),l=u(e,i);for(const o of s.getDescendantsOfKind(c.CallExpression)){if(!m(o))continue;const a=g(o);a!==""&&r.push({exportName:a,file:l,line:o.getStartLineNumber(),table:x(o)})}}return r};export{v as default};
1
+ import{SyntaxKind as c,Node as n}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as u,enclosingExportName as g,isDatabaseAccessor as d}from"./listLunoraSourceFiles-DP-5e-RE.mjs";const m=t=>{const e=t.getExpression();if(!n.isPropertyAccessExpression(e)||e.getName()!=="insert")return!1;const r=e.getExpression();return d(r)},p=t=>{if(!n.isIdentifier(t))return;const e=t.getSymbol(),r=e?.getAliasedSymbol()?.getDeclarations()??e?.getDeclarations()??[];for(const i of r)if(n.isVariableDeclaration(i)){const s=i.getInitializer();if(s&&n.isStringLiteral(s))return s.getLiteralText()}},x=t=>{const e=t.getArguments()[0];return e?n.isStringLiteral(e)?e.getLiteralText():p(e)??"":""},v=(t,e)=>{const r=[];for(const i of f(e)){const s=t.getSourceFile(i)??t.addSourceFileAtPath(i),l=u(e,i);for(const o of s.getDescendantsOfKind(c.CallExpression)){if(!m(o))continue;const a=g(o);a!==""&&r.push({exportName:a,file:l,line:o.getStartLineNumber(),table:x(o)})}}return r};export{v as default};
@@ -0,0 +1 @@
1
+ import"./listLunoraSourceFiles-DP-5e-RE.mjs";import"./classify-procedure-call-BztLe76A.mjs";import{d as p}from"./index-BoaHhVtM.mjs";export{p as default};
@@ -1 +1 @@
1
- import{SyntaxKind as g,Node as s}from"ts-morph";import{diagnosticAt as u}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as m}from"./module-specifiers-WF8iAydP.mjs";import{listLunoraSourceFiles as p,lunoraRelativePath as h,findObjectProperty as I}from"./listLunoraSourceFiles-vjwjgpjd.mjs";const P=r=>{const i=r.getSymbol();if(!i)return r.getText()==="defineMigration";for(const t of i.getDeclarations())if(s.isImportSpecifier(t))return m(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMigration":!1;return!1},d=(r,i)=>{const t=I(r,i);if(!t||!s.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&s.isStringLiteral(e)?e.getLiteralValue():void 0},b=(r,i)=>{const t=r.getInitializer();if(t?.getKind()!==g.CallExpression)return;const e=t.getExpression();if(!s.isIdentifier(e)||!P(e))return;const o=t.getArguments()[0];if(!o||!s.isObjectLiteralExpression(o))return;const n=d(o,"id"),a=r.getName();if(n===void 0||n.trim()==="")throw u(o,`Migration "${a}" in "${i}" must declare \`id\` as a non-empty string literal so codegen can key the registry.`,{code:"MIGRATION_ID_NOT_STATIC",name:"LunoraError",status:500});return{exportName:a,filePath:i,id:n,table:d(o,"table")??""}},M=r=>{const i=new Map;for(const t of r){const e=i.get(t.id);if(e!==void 0)throw Object.assign(new Error(`Duplicate migration id "${t.id}": declared in both "${e}" and "${t.filePath}". Migration ids must be unique across the project.`),{code:"DUPLICATE_MIGRATION_ID",id:t.id,name:"LunoraError",paths:[e,t.filePath],status:500});i.set(t.id,t.filePath)}},A=(r,i)=>{const t=p(i),e=[];for(const o of t){const n=r.getSourceFile(o)??r.addSourceFileAtPath(o),a=h(i,o);for(const c of n.getVariableStatements())if(c.isExported())for(const f of c.getDeclarations()){const l=b(f,a);l&&e.push(l)}}return e.sort((o,n)=>o.id.localeCompare(n.id)),M(e),e};export{A as default};
1
+ import{SyntaxKind as g,Node as s}from"ts-morph";import{diagnosticAt as u}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as m}from"./module-specifiers-WF8iAydP.mjs";import{listLunoraSourceFiles as p,lunoraRelativePath as h,findObjectProperty as I}from"./listLunoraSourceFiles-DP-5e-RE.mjs";const P=r=>{const i=r.getSymbol();if(!i)return r.getText()==="defineMigration";for(const t of i.getDeclarations())if(s.isImportSpecifier(t))return m(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMigration":!1;return!1},d=(r,i)=>{const t=I(r,i);if(!t||!s.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&s.isStringLiteral(e)?e.getLiteralValue():void 0},b=(r,i)=>{const t=r.getInitializer();if(t?.getKind()!==g.CallExpression)return;const e=t.getExpression();if(!s.isIdentifier(e)||!P(e))return;const o=t.getArguments()[0];if(!o||!s.isObjectLiteralExpression(o))return;const n=d(o,"id"),a=r.getName();if(n===void 0||n.trim()==="")throw u(o,`Migration "${a}" in "${i}" must declare \`id\` as a non-empty string literal so codegen can key the registry.`,{code:"MIGRATION_ID_NOT_STATIC",name:"LunoraError",status:500});return{exportName:a,filePath:i,id:n,table:d(o,"table")??""}},M=r=>{const i=new Map;for(const t of r){const e=i.get(t.id);if(e!==void 0)throw Object.assign(new Error(`Duplicate migration id "${t.id}": declared in both "${e}" and "${t.filePath}". Migration ids must be unique across the project.`),{code:"DUPLICATE_MIGRATION_ID",id:t.id,name:"LunoraError",paths:[e,t.filePath],status:500});i.set(t.id,t.filePath)}},A=(r,i)=>{const t=p(i),e=[];for(const o of t){const n=r.getSourceFile(o)??r.addSourceFileAtPath(o),a=h(i,o);for(const c of n.getVariableStatements())if(c.isExported())for(const f of c.getDeclarations()){const l=b(f,a);l&&e.push(l)}}return e.sort((o,n)=>o.id.localeCompare(n.id)),M(e),e};export{A as default};
@@ -1 +1 @@
1
- import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as l,handlerOf as d}from"./listLunoraSourceFiles-vjwjgpjd.mjs";import{c as f}from"./classify-procedure-call-CZU6n3yF.mjs";const u={"crypto.getRandomValues":"crypto.getRandomValues","crypto.randomUUID":"crypto.randomUUID","Date.now":"Date.now","Math.random":"Math.random"},m=new Set(["globalThis","self"]),g=new Set(["globalThis","self","window"]),p=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e)){const t=e.getExpression();if(s.isIdentifier(t)&&g.has(t.getText()))return e.getName()}},h=e=>{const t=e.getExpression();if(s.isIdentifier(t)){const o=t.getText();return o==="fetch"||o==="Date"?o:void 0}if(!s.isPropertyAccessExpression(t))return;const n=t.getName(),i=p(t.getExpression());if(i!==void 0)return n==="fetch"&&m.has(i)?"fetch":u[`${i}.${n}`]},x=e=>{const t=e.getExpression();if(!s.isIdentifier(t)||t.getText()!=="Date")return;const n=e.getArguments(),i=n.every(o=>s.isNumericLiteral(o)||s.isStringLiteral(o)||s.isNoSubstitutionTemplateLiteral(o));return n.length>0&&i?void 0:"new Date"},N=e=>{const t=e.getInitializer();if(!t||!s.isCallExpression(t))return;const n=f(t);if(!n||n.kind!=="query"&&n.kind!=="mutation")return;const i=d(t,n.receiver);return i?{exportName:e.getName(),handler:i,kind:n.kind}:void 0},E=(e,t)=>{const n=[];for(const i of e.handler.getDescendantsOfKind(a.CallExpression)){const o=h(i);o!==void 0&&n.push({callee:o,exportName:e.exportName,file:t,kind:e.kind,line:i.getStartLineNumber()})}for(const i of e.handler.getDescendantsOfKind(a.NewExpression)){const o=x(i);o!==void 0&&n.push({callee:o,exportName:e.exportName,file:t,kind:e.kind,line:i.getStartLineNumber()})}return n},S=(e,t)=>{const n=[];for(const i of e.getVariableStatements())if(i.isExported())for(const o of i.getDeclarations()){const r=N(o);r&&n.push(...E(r,t))}return n},w=(e,t)=>{const n=[];for(const i of c(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...S(o,l(t,i)))}return n};export{w as default};
1
+ import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as l,handlerOf as d}from"./listLunoraSourceFiles-DP-5e-RE.mjs";import{c as f}from"./classify-procedure-call-BztLe76A.mjs";const u={"crypto.getRandomValues":"crypto.getRandomValues","crypto.randomUUID":"crypto.randomUUID","Date.now":"Date.now","Math.random":"Math.random"},m=new Set(["globalThis","self"]),g=new Set(["globalThis","self","window"]),p=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e)){const t=e.getExpression();if(s.isIdentifier(t)&&g.has(t.getText()))return e.getName()}},h=e=>{const t=e.getExpression();if(s.isIdentifier(t)){const o=t.getText();return o==="fetch"||o==="Date"?o:void 0}if(!s.isPropertyAccessExpression(t))return;const n=t.getName(),i=p(t.getExpression());if(i!==void 0)return n==="fetch"&&m.has(i)?"fetch":u[`${i}.${n}`]},x=e=>{const t=e.getExpression();if(!s.isIdentifier(t)||t.getText()!=="Date")return;const n=e.getArguments(),i=n.every(o=>s.isNumericLiteral(o)||s.isStringLiteral(o)||s.isNoSubstitutionTemplateLiteral(o));return n.length>0&&i?void 0:"new Date"},N=e=>{const t=e.getInitializer();if(!t||!s.isCallExpression(t))return;const n=f(t);if(!n||n.kind!=="query"&&n.kind!=="mutation")return;const i=d(t,n.receiver);return i?{exportName:e.getName(),handler:i,kind:n.kind}:void 0},E=(e,t)=>{const n=[];for(const i of e.handler.getDescendantsOfKind(a.CallExpression)){const o=h(i);o!==void 0&&n.push({callee:o,exportName:e.exportName,file:t,kind:e.kind,line:i.getStartLineNumber()})}for(const i of e.handler.getDescendantsOfKind(a.NewExpression)){const o=x(i);o!==void 0&&n.push({callee:o,exportName:e.exportName,file:t,kind:e.kind,line:i.getStartLineNumber()})}return n},S=(e,t)=>{const n=[];for(const i of e.getVariableStatements())if(i.isExported())for(const o of i.getDeclarations()){const r=N(o);r&&n.push(...E(r,t))}return n},w=(e,t)=>{const n=[];for(const i of c(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...S(o,l(t,i)))}return n};export{w as default};
@@ -0,0 +1 @@
1
+ import{d as a}from"./queries-B-f4jO-x.mjs";import"./listLunoraSourceFiles-DP-5e-RE.mjs";export{a as default};
@@ -0,0 +1 @@
1
+ import{d as r}from"./context-property-calls-CjDzLU8p.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
@@ -1 +1 @@
1
- import{Node as o}from"ts-morph";import{listLunoraSourceFiles as x,lunoraRelativePath as h,findObjectProperty as m,stringPropertyOf as c}from"./listLunoraSourceFiles-vjwjgpjd.mjs";import{e as A}from"./exported-procedure-chains-DhKcj-hK.mjs";import{r as L}from"./chain-CjJF9d9k.mjs";const E=new Set(["delete","insert","read","update"]),P=(e,t,i)=>{const r=e.getArguments()[0];if(!r||!o.isArrayLiteralExpression(r))return[];const s=[];for(const n of r.getElements()){if(!o.isObjectLiteralExpression(n))continue;const a=c(n,"on");a===void 0||!E.has(a)||s.push({file:t,on:a,procedure:i,table:c(n,"table")??""})}return s},u=e=>{if(!o.isObjectLiteralExpression(e))return[];const t=m(e,"permissions");if(!t||!o.isPropertyAssignment(t))return[];const i=t.getInitializer();if(!i||!o.isArrayLiteralExpression(i))return[];const r=[];for(const s of i.getElements()){if(o.isStringLiteral(s)){r.push(s.getLiteralText());continue}if(o.isCallExpression(s)){const n=s.getArguments()[0];n&&o.isStringLiteral(n)&&r.push(n.getLiteralText())}}return r},f=(e,t)=>t===void 0?e:{...e,description:t},v=e=>{if(o.isCallExpression(e)){const t=e.getArguments()[0];if(!t||!o.isStringLiteral(t))return;const i=e.getArguments()[1],r=i?c(i,"description"):void 0,s=i?u(i):[];return f({name:t.getLiteralText(),permissions:s},r)}if(o.isObjectLiteralExpression(e)){const t=c(e,"name");return t===void 0?void 0:f({name:t,permissions:u(e)},c(e,"description"))}},y=e=>{const t=e.getArguments()[1];if(!t||!o.isObjectLiteralExpression(t))return[];const i=m(t,"roles");if(!i||!o.isPropertyAssignment(i))return[];const r=i.getInitializer();if(!r||!o.isArrayLiteralExpression(r))return[];const s=[];for(const n of r.getElements()){const a=v(n);a&&s.push(a)}return s},O=(e,t,i)=>{const r=L(e);return{policies:r.flatMap(s=>P(s,t,i)),roles:r.flatMap(s=>y(s))}},I=(e,t)=>{const i=[],r=new Map;for(const s of x(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),a=h(t,s);for(const{name:g,receiver:d}of A(n)){const p=O(d,a,g);i.push(...p.policies);for(const l of p.roles)r.has(l.name)||r.set(l.name,l)}}return{policies:i,roles:[...r.values()]}};export{I as default};
1
+ import{Node as o}from"ts-morph";import{listLunoraSourceFiles as x,lunoraRelativePath as h,findObjectProperty as m,stringPropertyOf as c}from"./listLunoraSourceFiles-DP-5e-RE.mjs";import{e as A}from"./exported-procedure-chains-CmCDiPBV.mjs";import{r as L}from"./chain-H2N_uKgj.mjs";const E=new Set(["delete","insert","read","update"]),P=(e,t,i)=>{const r=e.getArguments()[0];if(!r||!o.isArrayLiteralExpression(r))return[];const s=[];for(const n of r.getElements()){if(!o.isObjectLiteralExpression(n))continue;const a=c(n,"on");a===void 0||!E.has(a)||s.push({file:t,on:a,procedure:i,table:c(n,"table")??""})}return s},u=e=>{if(!o.isObjectLiteralExpression(e))return[];const t=m(e,"permissions");if(!t||!o.isPropertyAssignment(t))return[];const i=t.getInitializer();if(!i||!o.isArrayLiteralExpression(i))return[];const r=[];for(const s of i.getElements()){if(o.isStringLiteral(s)){r.push(s.getLiteralText());continue}if(o.isCallExpression(s)){const n=s.getArguments()[0];n&&o.isStringLiteral(n)&&r.push(n.getLiteralText())}}return r},f=(e,t)=>t===void 0?e:{...e,description:t},v=e=>{if(o.isCallExpression(e)){const t=e.getArguments()[0];if(!t||!o.isStringLiteral(t))return;const i=e.getArguments()[1],r=i?c(i,"description"):void 0,s=i?u(i):[];return f({name:t.getLiteralText(),permissions:s},r)}if(o.isObjectLiteralExpression(e)){const t=c(e,"name");return t===void 0?void 0:f({name:t,permissions:u(e)},c(e,"description"))}},y=e=>{const t=e.getArguments()[1];if(!t||!o.isObjectLiteralExpression(t))return[];const i=m(t,"roles");if(!i||!o.isPropertyAssignment(i))return[];const r=i.getInitializer();if(!r||!o.isArrayLiteralExpression(r))return[];const s=[];for(const n of r.getElements()){const a=v(n);a&&s.push(a)}return s},O=(e,t,i)=>{const r=L(e);return{policies:r.flatMap(s=>P(s,t,i)),roles:r.flatMap(s=>y(s))}},I=(e,t)=>{const i=[],r=new Map;for(const s of x(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),a=h(t,s);for(const{name:g,receiver:d}of A(n)){const p=O(d,a,g);i.push(...p.policies);for(const l of p.roles)r.has(l.name)||r.set(l.name,l)}}return{policies:i,roles:[...r.values()]}};export{I as default};
@@ -1 +1 @@
1
- import{Node as o}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as u,tablesAccessedIn as d,findObjectProperty as p}from"./listLunoraSourceFiles-vjwjgpjd.mjs";import{c as m}from"./classify-procedure-call-CZU6n3yF.mjs";import{r as b}from"./chain-CjJF9d9k.mjs";const g=e=>{const t=e.getArguments()[0];if(!t||!o.isArrayLiteralExpression(t))return[];const s=[];for(const r of t.getElements()){if(!o.isObjectLiteralExpression(r))continue;const i=p(r,"table");if(!i||!o.isPropertyAssignment(i))continue;const n=i.getInitializer();n&&o.isStringLiteral(n)&&s.push(n.getLiteralText())}return s},h=e=>{const t=b(e);return{rlsTables:t.flatMap(s=>g(s)),usesRls:t.length>0}},y=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),v=new Set(["delete","deleteMany","insert","insertMany","patch","patchMany","replace"]),P=(e,t)=>{if(!o.isVariableDeclaration(e))return;const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const r=m(s);if(!r)return;const i=r.receiver?h(r.receiver):{rlsTables:[],usesRls:!1},{tablesRead:n,tablesWritten:l}=d(e,y,v);return{exportName:e.getName(),file:t,rlsTables:i.rlsTables,tablesRead:n,tablesWritten:l,usesRls:i.usesRls,visibility:r.visibility}},x=(e,t)=>{const s=[];for(const r of f(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=u(t,r);for(const l of i.getVariableStatements())if(l.isExported())for(const c of l.getDeclarations()){const a=P(c,n);a&&s.push(a)}}return s};export{x as default};
1
+ import{Node as o}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as u,tablesAccessedIn as d,findObjectProperty as p}from"./listLunoraSourceFiles-DP-5e-RE.mjs";import{c as m}from"./classify-procedure-call-BztLe76A.mjs";import{r as b}from"./chain-H2N_uKgj.mjs";const g=e=>{const t=e.getArguments()[0];if(!t||!o.isArrayLiteralExpression(t))return[];const s=[];for(const r of t.getElements()){if(!o.isObjectLiteralExpression(r))continue;const i=p(r,"table");if(!i||!o.isPropertyAssignment(i))continue;const n=i.getInitializer();n&&o.isStringLiteral(n)&&s.push(n.getLiteralText())}return s},h=e=>{const t=b(e);return{rlsTables:t.flatMap(s=>g(s)),usesRls:t.length>0}},y=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),v=new Set(["delete","deleteMany","insert","insertMany","patch","patchMany","replace"]),P=(e,t)=>{if(!o.isVariableDeclaration(e))return;const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const r=m(s);if(!r)return;const i=r.receiver?h(r.receiver):{rlsTables:[],usesRls:!1},{tablesRead:n,tablesWritten:l}=d(e,y,v);return{exportName:e.getName(),file:t,rlsTables:i.rlsTables,tablesRead:n,tablesWritten:l,usesRls:i.usesRls,visibility:r.visibility}},x=(e,t)=>{const s=[];for(const r of f(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=u(t,r);for(const l of i.getVariableStatements())if(l.isExported())for(const c of l.getDeclarations()){const a=P(c,n);a&&s.push(a)}}return s};export{x as default};
@@ -1 +1 @@
1
- import{listLunoraSourceFiles as l}from"./listLunoraSourceFiles-vjwjgpjd.mjs";const i=new Set(["@lunora/agent","@lunora/agent/sandbox"]),a={browserTool:"usesSandboxBrowser",containerTool:"usesSandboxContainer",fsTool:"usesSandboxFs"},u=()=>({usesSandboxBrowser:!1,usesSandboxContainer:!1,usesSandboxFs:!1}),d=o=>{const s=u();if(!i.has(o.getModuleSpecifierValue())||o.isTypeOnly())return s;for(const e of o.getNamedImports()){if(e.isTypeOnly())continue;const n=a[e.getNameNode().getText()];n!==void 0&&(s[n]=!0)}return s},b=(o,s)=>{const e=u();for(const n of l(s)){const c=o.getSourceFile(n)??o.addSourceFileAtPath(n);for(const t of c.getImportDeclarations()){const f=d(t);for(const r of Object.values(a))e[r]||=f[r]}if(Object.values(a).every(t=>e[t]))break}return e};export{b as discoverSandboxUsage};
1
+ import{listLunoraSourceFiles as l}from"./listLunoraSourceFiles-DP-5e-RE.mjs";const i=new Set(["@lunora/agent","@lunora/agent/sandbox"]),a={browserTool:"usesSandboxBrowser",containerTool:"usesSandboxContainer",fsTool:"usesSandboxFs"},u=()=>({usesSandboxBrowser:!1,usesSandboxContainer:!1,usesSandboxFs:!1}),d=o=>{const s=u();if(!i.has(o.getModuleSpecifierValue())||o.isTypeOnly())return s;for(const e of o.getNamedImports()){if(e.isTypeOnly())continue;const n=a[e.getNameNode().getText()];n!==void 0&&(s[n]=!0)}return s},b=(o,s)=>{const e=u();for(const n of l(s)){const c=o.getSourceFile(n)??o.addSourceFileAtPath(n);for(const t of c.getImportDeclarations()){const f=d(t);for(const r of Object.values(a))e[r]||=f[r]}if(Object.values(a).every(t=>e[t]))break}return e};export{b as discoverSandboxUsage};
@@ -0,0 +1 @@
1
+ import{LunoraError as M}from"@lunora/errors";import{Node as i,SyntaxKind as C}from"ts-morph";import{diagnosticAt as f}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{createRequire as R}from"node:module";import{join as F}from"node:path";import{findObjectProperty as u,propertyKeyName as I}from"./listLunoraSourceFiles-DP-5e-RE.mjs";import{r as V,p as B}from"./parse-validator-C94Yiabo.mjs";const q=(e,n)=>`table "${e}" is .global() and declares vector index "${n}". Vector sync runs on the shard write path, which a global (D1/Hyperdrive) table's writes never take — the index would stay empty. Drop .global(), or keep the index yourself with ctx.vectors.upsert/deleteByIds.`,J=e=>{switch(typeof e){case"bigint":return e.toString();case"boolean":case"number":return String(e);case"string":return JSON.stringify(e);default:return e===null?"null":void 0}},U=e=>({...e?.defaultValue!==void 0||e?.defaultFn!==void 0||e?.serverDefault!==void 0?{hasDefault:!0}:{},...e?.onUpdateFn===void 0?{}:{hasOnUpdate:!0},notNull:e?.notNull??!0,...e?.unique===!0?{unique:!0}:{}}),m=e=>{const n=e?._meta??{},t=e?.kind??"unknown",s={column:U(n.column),kind:t};switch(t){case"array":case"optional":{s.inner=m(n.inner);break}case"from":break;case"id":{s.tableName=n.tableName;break}case"literal":{s.literalValue=J(n.value);break}case"object":{const r=n.shape??{};s.shape=Object.fromEntries(Object.entries(r).map(([a,o])=>[a,m(o)]));break}case"record":{s.valueType=m(n.valueValidator),n.keyValidator!==void 0&&(s.keyType=m(n.keyValidator));break}case"storage":{typeof n.bucket=="string"&&(s.bucket=n.bucket);break}case"union":{const r=n.members??[];s.members=r.map(a=>m(a));break}}return s},K=e=>e?.kind==="global"?"global":e?.kind==="shardBy"&&typeof e.field=="string"?{field:e.field,kind:"shardBy"}:"root",Z=(e,n)=>{const t=[];e.relationMap&&Object.keys(e.relationMap).length>0&&t.push("relations"),e.rankIndexes&&e.rankIndexes.length>0&&t.push("rank indexes"),e.vectorIndexes&&e.vectorIndexes.length>0&&t.push("vector indexes"),t.length>0&&console.warn(`@lunora/codegen: package schema-extension table "${n}" declares ${t.join(" + ")}, which are not yet introspected from a node_modules extension — they will be absent from the generated types.`)},G=(e,n)=>{const t=e.shape??{},s=(e.indexes??[]).map(r=>({fields:r.fields,name:r.name,...r.unique?{unique:!0}:{}}));return Z(e,n),{...e.isExternallyManaged?{externallyManaged:!0}:{},geoIndexes:[],indexes:s,name:n,rankIndexes:[],relations:[],searchIndexes:(e.searchIndexes??[]).map(r=>({field:r.field,...r.filterFields?{filterFields:r.filterFields}:{},...r.language===void 0?{}:{language:r.language},...r.staged===void 0?{}:{staged:r.staged},...r.strategy===void 0?{}:{strategy:r.strategy},name:r.name})),shape:Object.fromEntries(Object.entries(t).map(([r,a])=>[r,m(a)])),shardMode:K(e.shardMode),vectorIndexes:[]}},W=e=>{const{key:n,tables:t}=e;if(typeof n!="string"||typeof t!="object"||t===null)return;const s=Object.entries(t).map(([o,l])=>G(l,o)),r=e.vectorIndexes??{},a=Object.entries(r??{}).map(([o,l])=>({...l.dimensions===void 0?{}:{dimensions:l.dimensions},...l.field===void 0?{}:{field:l.field},...l.metadata===void 0?{}:{metadata:l.metadata},...l.metric===void 0?{}:{metric:l.metric},name:o,table:l.table??""}));return{bareTables:s,bareVectorIndexes:a,key:n}},H=e=>{if(i.isIdentifier(e))return e.getText();if(i.isPropertyAccessExpression(e)){const n=e.getExpression();return i.isIdentifier(n)?n.getText():void 0}},Q=e=>{const n=H(e);if(n===void 0)return;const t=i.isPropertyAccessExpression(e)?e.getName():void 0,s=t===void 0?[]:[t];for(const r of e.getSourceFile().getImportDeclarations()){const a=r.getModuleSpecifierValue();for(const o of r.getNamedImports())if((o.getAliasNode()?.getText()??o.getName())===n)return{importedName:o.getName(),moduleSpecifier:a,propertyPath:s};if(r.getDefaultImport()?.getText()===n)return{importedName:"default",moduleSpecifier:a,propertyPath:s};if(r.getNamespaceImport()?.getText()===n&&t!==void 0)return{importedName:t,moduleSpecifier:a,propertyPath:[]}}},X=(e,n)=>{let t=e[n.importedName];for(const s of n.propertyPath){if(typeof t!="object"||t===null)return;t=t[s]}return t},Y=(e,n)=>{const t=Q(e);if(t)try{const s=R(F(n,"noop.cjs")),r=s.resolve(t.moduleSpecifier),a=s(r),o=X(a,t);return typeof o!="object"||o===null?void 0:W(o)}catch{return}},ee=new Set(["cosine","dot-product","euclidean"]),b=(e,n)=>{const t=u(e,n);if(t&&i.isPropertyAssignment(t))return t.getInitializer()},d=(e,n)=>{const t=b(e,n);if(t&&i.isStringLiteral(t))return t.getLiteralText()},x=(e,n)=>{const t=b(e,n);if(t&&i.isNumericLiteral(t))return Number(t.getLiteralText())},O=(e,n)=>{const t=b(e,n);if(t&&(i.isTrueLiteral(t)||i.isFalseLiteral(t)))return t.getLiteralValue()},h=(e,n)=>{const t=b(e,n);if(t&&i.isArrayLiteralExpression(t))return t.getElements().filter(s=>i.isStringLiteral(s)).map(s=>s.getLiteralText())},A=e=>e&&ee.has(e)?e:void 0,y=e=>e&&i.isStringLiteral(e)?e.getLiteralText():"_unnamed_",te=(e,n)=>{const t=h(e,n);return t!==void 0&&t.length>0?t:void 0},N=(e,n,t,s,r)=>{let a=e;for(;;){const o=a.getParent();if(!o||!i.isPropertyAccessExpression(o))break;const l=o.getParent();if(!l||!i.isCallExpression(l))break;if(o.getName()===n){const c=l.getArguments()[0];if(!c||!i.isStringLiteral(c))throw f(l,`\`.${n}(...)\` expects a string literal (${r})`);const g=c.getLiteralText();if(!s.has(g))throw f(c,`unknown ${t} ${JSON.stringify(g)} — expected ${r}`);return g}a=l}},ne=e=>`table "${e}" is both .global() and .ttl(). The TTL sweep is a shard's alarm deleting from that shard's own SQLite, and a global (D1/Hyperdrive) table's rows live outside every shard — so expired rows would never be deleted. Drop .ttl() and expire the rows from a cron, or keep the table shard-local.`,re=new Set(["cascade","restrict","set null"]),se=new Set(["aggregate","asId","cdcChangedTables","count","delete","deleteAll","deleteMany","deleteWhere","findFirst","findFirstOrThrow","findMany","get","groupBy","insert","insertMany","insertManyUnsafe","lookupById","normalizeId","patch","patchMany","patchWhere","query","rank","rankBefore","rankPage","rankPageRows","related","relationEdges","replace","restore","system","wipeShard"]),ie=new Set(["arguments","await","break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","eval","export","extends","false","finally","for","function","if","implements","import","in","instanceof","interface","let","new","null","package","private","protected","public","return","static","super","switch","this","throw","true","try","typeof","var","void","while","with","yield"]),P=/^[A-Za-z_$][\w$]*$/u,w=(e,n)=>{if(se.has(e))throw f(n,`table name "${e}" is reserved — the generated shard binds each table's facade onto the same object that carries \`ctx.db\`'s own members, so this table would overwrite \`ctx.db.${e}\` and every use of it would break. Rename the table.`);if(ie.has(e))throw f(n,`table name "${e}" is a reserved JavaScript word — codegen interpolates table names into a bare \`const ${e} = sqliteTable(...)\` binding in the generated Drizzle module, which is a syntax error for a keyword. Rename the table.`);if(!P.test(e))throw f(n,`table name ${JSON.stringify(e)} is not a valid JS identifier — table names are used in generated type names (Doc_<name>) and must match [A-Za-z_$][A-Za-z0-9_$]*. Rename the table.`)},oe=e=>e&&re.has(e)?e:void 0,ae=e=>{if(!i.isArrowFunction(e))return;let n=e.getBody();if(i.isParenthesizedExpression(n))n=n.getExpression();else if(i.isBlock(n)){const t=n.getStatements().find(s=>i.isReturnStatement(s));n=t&&i.isReturnStatement(t)?t.getExpression()??n:n}return i.isObjectLiteralExpression(n)?n:void 0},le=e=>{if(!i.isPropertyAssignment(e))return;const n=e.getInitializer();if(!n||!i.isCallExpression(n))return;const t=n.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName();if(s!=="one"&&s!=="many")return;const[r,a]=n.getArguments();if(!r||!i.isStringLiteral(r))throw f(r??n,`relation target table must be a string literal — codegen resolves relation targets statically. Got ${r?r.getText():"no argument"}.`);const o=r.getLiteralText();let l="_unknown_",c="_id",g;return a&&i.isObjectLiteralExpression(a)&&(l=d(a,"field")??l,c=d(a,"references")??c,g=s==="one"?oe(d(a,"onDelete")):void 0),{field:l,kind:s,name:I(e),onDelete:g,references:c,table:o}},ce=e=>{const n=ae(e);if(!n)return[];const t=[];for(const s of n.getProperties()){const r=le(s);r&&t.push(r)}return t},de=(e,n,t)=>{if(!n.includes("."))return;const[s="",...r]=n.split("."),a=`${s}${r.map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join("")}`;throw f(e,`index "${t}" indexes the nested path ${JSON.stringify(n)} — Lunora indexes only top-level columns. Denormalise the value into its own column (e.g. \`${a}\`), index that instead, and keep it in sync with a table \`.triggers()\` beforeInsert/beforeUpdate.`)},fe=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const n=u(e,"unique");if(!n||!i.isPropertyAssignment(n))return!1;const t=n.getInitializer();if(t===void 0)return!1;if(!i.isTrueLiteral(t)&&!i.isFalseLiteral(t))throw f(t,`\`unique\` must be a literal \`true\` or \`false\`, got ${JSON.stringify(t.getText())}`);return i.isTrueLiteral(t)},ue=e=>{const[n,t,s]=e,r=fe(s),a=y(n),o=t&&i.isArrayLiteralExpression(t)?t.getElements():[];for(const c of o)if(!i.isStringLiteral(c))throw f(c,`index "${a}" lists a non-literal field (${JSON.stringify(c.getText())}); codegen reads index fields statically, so every entry must be a string literal.`);const l=o.filter(c=>i.isStringLiteral(c));for(const c of l)de(c,c.getLiteralText(),a);return{fields:l.map(c=>c.getLiteralText()),name:a,unique:r}},pe=e=>{const[n,t]=e;let s="_unknown_",r,a,o,l;return t&&i.isObjectLiteralExpression(t)&&(s=d(t,"field")??s,r=h(t,"filterFields"),a=d(t,"language"),o=O(t,"staged"),l=d(t,"strategy")),{field:s,filterFields:r,language:a,name:y(n),staged:o,strategy:l}},ge=e=>{const[n,t]=e;let s="_unknown_",r;return t&&i.isObjectLiteralExpression(t)&&(s=d(t,"field")??s,r=x(t,"precision")),{field:s,name:y(n),precision:r}},me=e=>{const[n,t]=e,s=n&&i.isStringLiteral(n)?n.getLiteralText():"_unknown_";let r;return t&&i.isObjectLiteralExpression(t)&&(r=x(t,"after")),{after:r,field:s}},be=e=>{if(!i.isObjectLiteralExpression(e))return;const n=d(e,"field");return n===void 0?void 0:{direction:d(e,"direction")==="desc"?"desc":"asc",field:n}},xe=e=>{const[n,t]=e;let s=[],r;if(t&&i.isObjectLiteralExpression(t)){const a=u(t,"sortBy");if(a&&i.isPropertyAssignment(a)){const o=a.getInitializer();o&&i.isArrayLiteralExpression(o)&&(s=o.getElements().map(l=>be(l)).filter(l=>l!==void 0))}r=h(t,"partitionBy")}return{name:y(n),partitionBy:r,sortBy:s}},he=(e,n)=>{const[t,s]=e,r=t&&i.isStringLiteral(t)?t.getLiteralText():"_unknown_";if(!(!s||!i.isObjectLiteralExpression(s)))return{dimensions:x(s,"dimensions"),field:r,metadata:h(s,"metadata"),metric:A(d(s,"metric")),name:d(s,"index")??"_unnamed_",table:n}},ye=e=>{const n=e[0];return n&&i.isObjectLiteralExpression(n)&&d(n,"backend")==="hyperdrive"?"hyperdrive":"d1"},ve=e=>{if(e&&i.isObjectLiteralExpression(e)){const n=u(e,"field");if(n&&i.isPropertyAssignment(n)){const t=n.getInitializer();if(t&&i.isStringLiteral(t))return t.getLiteralText()}}return"deletedAt"},Ee=e=>{const n=e[0];return!n||!i.isObjectLiteralExpression(n)?{binding:"",hasTenantBy:!1,unanalyzable:!0}:{binding:d(n,"binding")??"",columns:te(n,"columns"),hasReconcile:u(n,"reconcileEveryMs")!==void 0,hasSoftDelete:u(n,"softDeleteColumn")!==void 0,hasTenantBy:u(n,"tenantBy")!==void 0,idColumn:d(n,"idColumn"),mode:d(n,"mode"),query:d(n,"query")}},Ie=(e,n,t,s)=>{switch(n){case"commitOrdered":{e.commitOrdered=!0;break}case"externallyManaged":{e.externallyManaged=!0;break}case"geoIndex":{e.geoIndexes.push(ge(t));break}case"global":{e.shardMode="global",e.globalBackend=ye(t);break}case"index":{e.indexes.push(ue(t));break}case"memory":{e.memory=!0;break}case"public":{e.isPublic=!0;break}case"rankIndex":{e.rankIndexes.push(xe(t));break}case"relations":{const r=t[0];r&&e.relations.push(...ce(r));break}case"searchIndex":{e.searchIndexes.push(pe(t));break}case"shardBy":{const r=t[0];e.shardMode={field:r&&i.isStringLiteral(r)?r.getLiteralText():"_unknown_",kind:"shardBy"};break}case"softDelete":{e.softDelete={field:ve(t[0])};break}case"source":{e.externalSource=Ee(t),e.externallyManaged=!0;break}case"ttl":{e.ttl=me(t);break}case"vectorize":{const r=he(t,s);r&&e.vectorIndexes.push(r);break}}},L=["__vocab","_config","_content","_data","_docsize","_idx"],we=(e,n,t)=>{const s=new Set(t.map(r=>r.name));for(const r of t)for(const a of L){const o=`${r.name}${a}`;if(!s.has(o))continue;const l=a==="__vocab"?`the \`fts5vocab\` companion for "${o}" is created \`IF NOT EXISTS\`, so it silently resolves to "${r.name}"'s — the second index then reads the wrong vocabulary and returns wrong results, with no error`:`creating "${o}" is rejected (\`object name reserved for internal use: SQLITE_ERROR\`), which aborts the shard migration and leaves every sharded table unreadable`;throw f(e,`table "${n}" declares search indexes "${r.name}" and "${o}", whose generated FTS5 tables collide: "${r.name}" already owns "${n}__fts_${o}" as its "${a}" companion, so ${l}. Rename one of them so neither ends with another's name plus ${L.join(", ")}.`)}},Se=(e,n,t)=>{if(t.ttl!==void 0&&t.shardMode==="global")throw f(e,ne(n))},_=(e,n)=>{const t={commitOrdered:!1,externallyManaged:!1,geoIndexes:[],indexes:[],isPublic:!1,memory:!1,rankIndexes:[],relations:[],searchIndexes:[],shardMode:"root",vectorIndexes:[]};let s={},r=e;for(;i.isCallExpression(r);){const a=r.getExpression(),o=r.getArguments();if(i.isPropertyAccessExpression(a))Ie(t,a.getName(),o,n),r=a.getExpression();else if(i.isIdentifier(a)&&a.getText()==="defineTable"){const l=o[0];if(l&&i.isObjectLiteralExpression(l))s=B(l);else if(l)throw f(l,`table "${n}" calls defineTable(${JSON.stringify(l.getText())}), but codegen reads the field map syntactically and can only read an object literal. Inline the fields into the defineTable(...) call. To reuse them in an \`.input()\`, derive from the generated \`Doc_${n}\` / \`Insert_${n}\` type instead of sharing the runtime value.`);break}else break}return t.softDelete&&!(t.softDelete.field in s)&&(s={...s,[t.softDelete.field]:{inner:{column:{notNull:!1},kind:"number"},kind:"optional"}}),we(e,n,t.searchIndexes),Se(e,n,t),{commitOrdered:t.commitOrdered,externallyManaged:t.externallyManaged,externalSource:t.externalSource,geoIndexes:t.geoIndexes,globalBackend:t.shardMode==="global"?t.globalBackend??"d1":void 0,indexes:t.indexes,isPublic:t.isPublic,memory:t.memory,name:n,rankIndexes:t.rankIndexes,relations:t.relations,searchIndexes:t.searchIndexes,shape:s,shardMode:t.shardMode,softDelete:t.softDelete,ttl:t.ttl,vectorIndexes:t.vectorIndexes}},j=(e,n=[],t=new Set,s=new Set)=>{s.add(e);for(const r of e.getProperties()){if(i.isSpreadAssignment(r)){const o=V(r.getExpression());o!==void 0&&!s.has(o)&&j(o,n,t,s);continue}if(!i.isPropertyAssignment(r))continue;const a=r.getInitializer();if(a){const o=I(r);if(w(o,r.getNameNode()),t.has(o))throw f(r.getNameNode(),`defineSchema({...}): table "${o}" is declared more than once — the earlier declaration would be silently discarded. Remove the duplicate.`);t.add(o),n.push(_(a,o))}}return n},ke=e=>{const n=u(e,"source");if(n&&i.isPropertyAssignment(n)){const t=n.getInitializer();if(t&&i.isObjectLiteralExpression(t))return d(t,"table")??"_unknown_"}return"_unknown_"},Te=e=>{if(!i.isPropertyAssignment(e))return;const n=e.getInitializer();if(!n||!i.isCallExpression(n))return;const t=n.getExpression();if(!i.isIdentifier(t)||t.getText()!=="defineVectorIndex")return;const s=n.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return;const r=e.getNameNode(),a=i.isStringLiteral(r)?r.getLiteralText():r.getText();return{dimensions:x(s,"dimensions"),metric:A(d(s,"metric")),name:a,table:ke(s)}},$=e=>{const n=[];for(const t of e.getProperties()){const s=Te(t);s&&n.push(s)}return n},S=(e,n)=>`${e}_${n}`,Le=(e,n)=>{if(!P.test(e))throw f(n,`defineSchemaExtension key ${JSON.stringify(e)} is not a valid JS identifier — it is prefixed onto every table the extension contributes (\`${e}_<table>\`), and table names are used in generated type names (Doc_<name>) and must match [A-Za-z_$][A-Za-z0-9_$]*. Rename the extension key.`)},E=(e,n,t)=>t.has(e)?S(n,e):e,Oe=(e,n,t)=>{const s=S(n,e.name);return{...e,extensionKey:n,name:s,relations:e.relations.map(r=>({...r,table:E(r.table,n,t)})),vectorIndexes:e.vectorIndexes.map(r=>({...r,table:E(r.table,n,t)}))}},Ae=e=>{if(i.isVariableDeclaration(e)||i.isPropertyAssignment(e))return e.getInitializer();if(i.isShorthandPropertyAssignment(e))return e.getNameNode()},Ne=e=>{if(!i.isCallExpression(e))return!1;const n=e.getExpression();return i.isIdentifier(n)&&n.getText()==="defineSchemaExtension"},Pe=e=>{if(i.isIdentifier(e))return e;if(i.isPropertyAccessExpression(e)){const n=e.getExpression();return i.isIdentifier(n)?n:void 0}},_e=e=>{if(i.isObjectLiteralExpression(e))return e;if(i.isCallExpression(e)){const n=e.getExpression();let t;if(i.isIdentifier(n)?t=n.getText():i.isPropertyAccessExpression(n)&&(t=n.getName()),t==="definePlugin"){const s=e.getArguments()[1];return s&&i.isObjectLiteralExpression(s)?s:void 0}}},je=(e,n)=>{const t=Ae(e);if(t){if(i.isPropertyAccessExpression(n)){const s=_e(t);return s?b(s,n.getName()):void 0}return t}},$e=e=>{let n=e,t=0;for(;n&&t<32;){if(t+=1,Ne(n))return n;const s=Pe(n),r=s&&i.isIdentifier(s)?s.getSymbol():void 0,o=(r?.getAliasedSymbol()?.getDeclarations()??r?.getDeclarations()??[])[0];if(!o)return;const l=o.getSourceFile();if(l.isInNodeModules()||l.isDeclarationFile())return;n=je(o,n)}},De=e=>{const[n,t]=e.getArguments();if(!(!n||!i.isStringLiteral(n))&&!(!t||!i.isObjectLiteralExpression(t)))return{key:n.getLiteralText(),keyNode:n,options:t}},ze=e=>{const n=u(e,"tables");if(!n||!i.isPropertyAssignment(n))return[];const t=n.getInitializer();if(!t||!i.isObjectLiteralExpression(t))return[];const s=[];for(const r of t.getProperties()){if(!i.isPropertyAssignment(r))continue;const a=r.getInitializer();if(!a)continue;const o=I(r);w(o,r.getNameNode()),s.push(_(a,o))}return s},Me=e=>{const n=u(e,"vectorIndexes");if(!n||!i.isPropertyAssignment(n))return[];const t=n.getInitializer();return!t||!i.isObjectLiteralExpression(t)?[]:$(t)},D=(e,n,t,s)=>{Le(e,s);const r=new Set(n.map(l=>l.name)),a=n.map(l=>Oe(l,e,r)),o=t.map(l=>({...l,name:S(e,l.name),table:E(l.table,e,r)}));return{tables:a,vectorIndexes:o}},Ce=(e,n,t)=>D(e,ze(t),Me(t),n),Re=(e,n)=>{const t=e.getArguments()[0];if(!t)return;const s=$e(t);if(!s){if(n!==void 0){const a=Y(t,n);if(a){for(const o of a.bareTables)w(o.name,t);return D(a.key,a.bareTables,a.bareVectorIndexes,t)}}console.warn(`@lunora/codegen: skipping \`.extend(${t.getText()})\` — its \`defineSchemaExtension(...)\` could not be resolved from local sources, and ${n===void 0?"no project root was available to resolve the package":"the package could not be imported/introspected"}. Extension tables will be absent from the generated types.`);return}const r=De(s);if(!r){console.warn("@lunora/codegen: skipping `.extend(...)` — `defineSchemaExtension` requires a string `key` and an options object literal.");return}return Ce(r.key,r.keyNode,r.options)},Fe=e=>{const n=[];let t=e;for(;;){const s=t.getParent();if(!s||!i.isPropertyAccessExpression(s))break;const r=s.getParent();if(!r||!i.isCallExpression(r))break;s.getName()==="extend"&&n.push(r),t=r}return n},Ve=(e,n,t)=>{const s=new Set(n.map(a=>a.name)),r=[];for(const a of Fe(e)){const o=Re(a,t);if(o){for(const l of o.tables){if(s.has(l.name))throw f(a,`defineSchema(...).extend(...): table "${l.name}" already exists — another extension with the same key already contributed it.`);s.add(l.name),n.push(l)}r.push(...o.vectorIndexes)}}return r},Be=new Set(["eu","fedramp","us"]),qe=e=>N(e,"jurisdiction","jurisdiction",Be,'"eu", "us", or "fedramp"'),Je=e=>{let n=e;for(;;){const t=n.getParent(),s=t?.getParent();if(!t||!i.isPropertyAccessExpression(t)||!s||!i.isCallExpression(s))return!1;if(t.getName()==="jurisdiction"){const r=s.getArguments()[1];return r!==void 0&&i.isObjectLiteralExpression(r)&&O(r,"pinAuthAndVoice")===!0}n=s}},Ue=new Set(["required"]),Ke=e=>N(e,"rls","rls mode",Ue,'"required"'),et=(e,n,t)=>{const r=e.addSourceFileAtPath(n).getDescendantsOfKind(C.CallExpression).find(p=>{const T=p.getExpression();return i.isIdentifier(T)&&T.getText()==="defineSchema"});if(!r)throw new M("INTERNAL",`defineSchema() not found in ${n}`);const a=r.getArguments()[0];if(!a||!i.isObjectLiteralExpression(a))throw f(r,"defineSchema() expects an object literal");const o=j(a),l=r.getArguments()[1],c=l&&i.isObjectLiteralExpression(l)?$(l):[],g=Ve(r,o,t),k=[...o.flatMap(p=>p.vectorIndexes),...c,...g],z=new Set(o.filter(p=>p.shardMode==="global").map(p=>p.name)),v=k.find(p=>z.has(p.table));if(v)throw f(r,q(v.table,v.name));return{jurisdiction:qe(r),...Je(r)?{jurisdictionPinsAuthAndVoice:!0}:{},rlsMode:Ke(r),tables:o,vectorIndexes:k}};export{et as default};
@@ -1 +1 @@
1
- import{Node as u}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as p,stringPropertyOf as l}from"./listLunoraSourceFiles-vjwjgpjd.mjs";import{w as d}from"./classify-procedure-call-CZU6n3yF.mjs";import{e as m}from"./exported-procedure-chains-DhKcj-hK.mjs";const h=new Set(["delete","list","read","write"]),g=t=>d(t,"use","storageRules"),x=(t,s,n)=>{const e=t.getArguments()[0];if(!e||!u.isArrayLiteralExpression(e))return[];const i=[];for(const o of e.getElements()){if(!u.isObjectLiteralExpression(o))continue;const r=l(o,"on");if(r===void 0||!h.has(r))continue;const a=l(o,"prefix"),c={bucket:l(o,"bucket")??"",file:s,on:r,procedure:n};a!==void 0&&(c.prefix=a),i.push(c)}return i},A=(t,s)=>{const n=[];for(const e of f(s)){const i=t.getSourceFile(e)??t.addSourceFileAtPath(e),o=p(s,e);for(const{name:r,receiver:a}of m(i))for(const c of g(a))n.push(...x(c,o,r))}return{rules:n}};export{A as default};
1
+ import{Node as u}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as p,stringPropertyOf as l}from"./listLunoraSourceFiles-DP-5e-RE.mjs";import{w as d}from"./classify-procedure-call-BztLe76A.mjs";import{e as m}from"./exported-procedure-chains-CmCDiPBV.mjs";const h=new Set(["delete","list","read","write"]),g=t=>d(t,"use","storageRules"),x=(t,s,n)=>{const e=t.getArguments()[0];if(!e||!u.isArrayLiteralExpression(e))return[];const i=[];for(const o of e.getElements()){if(!u.isObjectLiteralExpression(o))continue;const r=l(o,"on");if(r===void 0||!h.has(r))continue;const a=l(o,"prefix"),c={bucket:l(o,"bucket")??"",file:s,on:r,procedure:n};a!==void 0&&(c.prefix=a),i.push(c)}return i},A=(t,s)=>{const n=[];for(const e of f(s)){const i=t.getSourceFile(e)??t.addSourceFileAtPath(e),o=p(s,e);for(const{name:r,receiver:a}of m(i))for(const c of g(a))n.push(...x(c,o,r))}return{rules:n}};export{A as default};
@@ -137,7 +137,9 @@ import{A as w,G as y}from"./emit-6YJU3YbV.mjs";const k=e=>`has${e.charAt(0).toUp
137
137
  : {}),`]:[],...e.hasSourcedTables?[" ...(this.sourceClientFactory === undefined ? {} : { sourceClient: this.sourceClientFactory }),"]:[],...e.hasStorage?[" ...(this.storageDeclaration ? { storage: (rawEnv: Record<string, unknown>) => this.resolveStorage(rawEnv as Env) } : {}),"]:[],...m(e)?[" ...this.shardExtras,"]:[]];return a.length>0?`
138
138
  ${a.join(`
139
139
  `)}
140
- `:""},B=e=>[...e.tableNames.length>0?[` options.listSchemaTables = () => [${e.tableNames.map(t=>JSON.stringify(t)).join(", ")}];`]:[],...e.hasScheduler?[` if (this.schedulerDeclaration) {
140
+ `:""},B=e=>e.jurisdiction&&e.jurisdictionPinsAuthAndVoice===!0?`
141
+ // The schema's jurisdiction pins the auth object like every other DO.
142
+ jurisdiction: ${JSON.stringify(e.jurisdiction)},`:"",P=e=>[...e.tableNames.length>0?[` options.listSchemaTables = () => [${e.tableNames.map(t=>JSON.stringify(t)).join(", ")}];`]:[],...e.hasScheduler?[` if (this.schedulerDeclaration) {
141
143
  options.schedulerDO = this.schedulerDeclaration.namespace(env);
142
144
  }`]:[],...e.hasWorkflow?[` options.workflowsClient = (workflowEnv) => {
143
145
  const source = workflowEnv as Record<string, unknown>;
@@ -204,7 +206,7 @@ ${a.join(`
204
206
  // than more emitted code: request-path logic in generated output can only be
205
207
  // typechecked, never unit-tested.
206
208
  const authWiring = createDoAuthWiring({
207
- internalSecret: authDeclaration.internalSecret?.(env),
209
+ internalSecret: authDeclaration.internalSecret?.(env),${B(e)}
208
210
  namespace: authNamespace(env),
209
211
  objectName: authDeclaration.objectName?.(env),
210
212
  });
@@ -279,14 +281,14 @@ ${a.join(`
279
281
  }`]:[],...e.voiceAgents&&e.voiceAgents.length>0?[` options.voiceAgents = {
280
282
  ${e.voiceAgents.map(t=>` ${JSON.stringify(t.exportName)}: (env as Record<string, unknown>)[${JSON.stringify(t.bindingName)}] as ShardNamespaceLike,`).join(`
281
283
  `)}
282
- };`]:[]],P=e=>[" cronJobs: LUNORA_CRONS,"," functions: LUNORA_FUNCTIONS,",...e.identity?[` identity: lunoraIdentityContract.${e.identity.exportName},`]:[],...e.jurisdiction?[` jurisdiction: ${JSON.stringify(e.jurisdiction)},`]:[],...e.wantsOpenApi?[" openApiSpec,"]:[],...e.wantsOpenRpc?[" openRpcSpec,"]:[],...e.hasQueue?[" queue: (batch: unknown, queueEnv: unknown, _context: ExecutionContextLike, trigger: TriggerTrace): Promise<void> =>"," dispatchQueueBatch(batch as Parameters<typeof dispatchQueueBatch>[0], LUNORA_QUEUE_REGISTRY, {"," capture: shouldCaptureQueue(queueEnv as Record<string, unknown>)",` ? createQueueCaptureSink(queueEnv as Record<string, unknown>${e.jurisdiction?`, { jurisdiction: ${JSON.stringify(e.jurisdiction)} }`:""})`," : undefined,"," env: queueEnv as Record<string, unknown>,"," traceparent: trigger.traceparent,"," }),"]:[]," ...(this.httpRouterApp ? { httpRouter: this.httpRouterApp } : {}),"," routes: this.routeMap,"," shardDO: this.shardSelector?.(env) ?? (undefined as unknown as ShardNamespaceLike),"],W=e=>e.hasScheduler?`
284
+ };`]:[]],W=e=>[" cronJobs: LUNORA_CRONS,"," functions: LUNORA_FUNCTIONS,",...e.identity?[` identity: lunoraIdentityContract.${e.identity.exportName},`]:[],...e.jurisdiction?[` jurisdiction: ${JSON.stringify(e.jurisdiction)},`]:[],...e.wantsOpenApi?[" openApiSpec,"]:[],...e.wantsOpenRpc?[" openRpcSpec,"]:[],...e.hasQueue?[" queue: (batch: unknown, queueEnv: unknown, _context: ExecutionContextLike, trigger: TriggerTrace): Promise<void> =>"," dispatchQueueBatch(batch as Parameters<typeof dispatchQueueBatch>[0], LUNORA_QUEUE_REGISTRY, {"," capture: shouldCaptureQueue(queueEnv as Record<string, unknown>)",` ? createQueueCaptureSink(queueEnv as Record<string, unknown>${e.jurisdiction?`, { jurisdiction: ${JSON.stringify(e.jurisdiction)} }`:""})`," : undefined,"," env: queueEnv as Record<string, unknown>,"," traceparent: trigger.traceparent,"," }),"]:[]," ...(this.httpRouterApp ? { httpRouter: this.httpRouterApp } : {}),"," routes: this.routeMap,"," shardDO: this.shardSelector?.(env) ?? (undefined as unknown as ShardNamespaceLike),"],_=e=>e.hasScheduler?`
283
285
  /** Resolve the \`SchedulerDO\`-backed scheduler for this env; \`undefined\` until the namespace is wired. */
284
286
  private resolveScheduler(env: Env): ReturnType<typeof createScheduler> | undefined {
285
287
  const namespace = this.schedulerDeclaration?.namespace(env);
286
288
 
287
289
  return namespace ? createScheduler({${e.jurisdiction?` jurisdiction: ${JSON.stringify(e.jurisdiction)},`:""} namespace }) : undefined;
288
290
  }
289
- `:"",_=e=>e?`
291
+ `:"",$=e=>e?`
290
292
  /**
291
293
  * One bucket's \`Storage\`, signing under the name it is registered as.
292
294
  *
@@ -624,7 +626,7 @@ const buildGlobalCdcApplier =
624
626
 
625
627
  return request.changes.length;
626
628
  };
627
- `:"",$=e=>[...e.hasAuth?["AuthDeclaration"]:[],"ComposedApp",...e.hasGlobal?["GlobalDeclaration"]:[],"LunoraConfig",...e.hasScheduler?["SchedulerDeclaration"]:[],"Selector",...e.hasStorage?["StorageDeclaration"]:[]].toSorted((t,a)=>t.localeCompare(a)).join(", "),F=e=>{const t={...e,hasVectors:(e.hasVectors??!0)&&(e.vectorIndexCount??0)>0},{hasAuth:a}=t,r=N(t),n=B(t),i=a?` let auth: LunoraAuth | null = null;
629
+ `:"",U=e=>[...e.hasAuth?["AuthDeclaration"]:[],"ComposedApp",...e.hasGlobal?["GlobalDeclaration"]:[],"LunoraConfig",...e.hasScheduler?["SchedulerDeclaration"]:[],"Selector",...e.hasStorage?["StorageDeclaration"]:[]].toSorted((t,a)=>t.localeCompare(a)).join(", "),M=e=>{const t={...e,hasVectors:(e.hasVectors??!0)&&(e.vectorIndexCount??0)>0},{hasAuth:a}=t,r=N(t),n=P(t),i=a?` let auth: LunoraAuth | null = null;
628
630
  let authInit: Promise<void> | null = null;
629
631
  `:"",o=a?`
630
632
  const initAuth = async (env: Env): Promise<void> => {
@@ -780,11 +782,11 @@ ${t.hasFramework?`
780
782
  `:""}
781
783
  return composed;
782
784
  }
783
- ${W(t)}${_(t.hasStorage)}
785
+ ${_(t)}${$(t.hasStorage)}
784
786
  /** Fan the recorded declarations into the worker-side \`createWorker\` options. */
785
787
  private buildWorkerOptions(env: Env, ${c}): WorkerOptions {
786
788
  const options: WorkerOptions = {
787
- ${P(t).join(`
789
+ ${W(t).join(`
788
790
  `)}
789
791
  };
790
792
 
@@ -836,5 +838,5 @@ interface LunoraConfig<Env extends object = object> {
836
838
  const defineApp = <Env extends object>(): AppBuilder<Env> => new AppBuilder<Env>();
837
839
 
838
840
  export { AppBuilder, defineApp };
839
- export type { ${$(t)} };
840
- `};export{F as emitApp};
841
+ export type { ${U(t)} };
842
+ `};export{M as emitApp};
@@ -1 +1 @@
1
- import{Node as a}from"ts-morph";import{c as n}from"./classify-procedure-call-CZU6n3yF.mjs";const f=s=>{const i=[];for(const r of s.getVariableStatements())if(r.isExported())for(const t of r.getDeclarations()){const e=t.getInitializer(),o=e&&a.isCallExpression(e)?n(e):void 0;o?.receiver&&i.push({name:t.getName(),receiver:o.receiver})}return i};export{f as e};
1
+ import{Node as a}from"ts-morph";import{c as n}from"./classify-procedure-call-BztLe76A.mjs";const f=s=>{const i=[];for(const r of s.getVariableStatements())if(r.isExported())for(const t of r.getDeclarations()){const e=t.getInitializer(),o=e&&a.isCallExpression(e)?n(e):void 0;o?.receiver&&i.push({name:t.getName(),receiver:o.receiver})}return i};export{f as e};
@@ -1 +1 @@
1
- import{Node as r}from"ts-morph";import{propertyKeyName as f,listLunoraSourceFiles as m,lunoraRelativePath as p,tablesAccessedIn as d}from"./listLunoraSourceFiles-vjwjgpjd.mjs";import{w as g,c as h}from"./classify-procedure-call-CZU6n3yF.mjs";const u=e=>{if(!(!r.isPropertyAssignment(e)&&!r.isShorthandPropertyAssignment(e)&&!r.isMethodDeclaration(e)&&!r.isGetAccessorDeclaration(e)))return f(e)},k=e=>g(e,"use","mask"),x=e=>{if(r.isPropertyAssignment(e)){const t=e.getInitializer();if(t&&r.isStringLiteral(t)){const s=t.getLiteralText();if(s==="redact"||s==="hash")return s}}return"custom"},v=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return[];const s=[];for(const i of t.getProperties()){const n=u(i);if(n===void 0||!r.isPropertyAssignment(i))continue;const o=i.getInitializer();if(!(!o||!r.isObjectLiteralExpression(o)))for(const a of o.getProperties()){const c=u(a);c!==void 0&&s.push({column:c,table:n})}}return s},P=e=>{const t=k(e);return{maskColumns:t.flatMap(s=>v(s)),usesMask:t.length>0}},y=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),C=new Set(["delete","insert","patch","replace"]),M=(e,t)=>{if(!r.isVariableDeclaration(e))return;const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const i=h(s);if(!i)return;const n=i.receiver?P(i.receiver):{maskColumns:[],usesMask:!1},{tablesRead:o,tablesWritten:a}=d(e,y,C);return{exportName:e.getName(),file:t,maskColumns:n.maskColumns,tablesRead:o,tablesWritten:a,usesMask:n.usesMask,visibility:i.visibility}},E=(e,t)=>{const s=[];for(const i of m(t)){const n=e.getSourceFile(i)??e.addSourceFileAtPath(i),o=p(t,i);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations()){const l=M(c,o);l&&s.push(l)}}return s};export{u as a,E as d,k as m,x as s};
1
+ import{Node as r}from"ts-morph";import{propertyKeyName as f,listLunoraSourceFiles as m,lunoraRelativePath as p,tablesAccessedIn as d}from"./listLunoraSourceFiles-DP-5e-RE.mjs";import{w as g,c as h}from"./classify-procedure-call-BztLe76A.mjs";const u=e=>{if(!(!r.isPropertyAssignment(e)&&!r.isShorthandPropertyAssignment(e)&&!r.isMethodDeclaration(e)&&!r.isGetAccessorDeclaration(e)))return f(e)},k=e=>g(e,"use","mask"),x=e=>{if(r.isPropertyAssignment(e)){const t=e.getInitializer();if(t&&r.isStringLiteral(t)){const s=t.getLiteralText();if(s==="redact"||s==="hash")return s}}return"custom"},v=e=>{const t=e.getArguments()[0];if(!t||!r.isObjectLiteralExpression(t))return[];const s=[];for(const i of t.getProperties()){const n=u(i);if(n===void 0||!r.isPropertyAssignment(i))continue;const o=i.getInitializer();if(!(!o||!r.isObjectLiteralExpression(o)))for(const a of o.getProperties()){const c=u(a);c!==void 0&&s.push({column:c,table:n})}}return s},P=e=>{const t=k(e);return{maskColumns:t.flatMap(s=>v(s)),usesMask:t.length>0}},y=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),C=new Set(["delete","insert","patch","replace"]),M=(e,t)=>{if(!r.isVariableDeclaration(e))return;const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const i=h(s);if(!i)return;const n=i.receiver?P(i.receiver):{maskColumns:[],usesMask:!1},{tablesRead:o,tablesWritten:a}=d(e,y,C);return{exportName:e.getName(),file:t,maskColumns:n.maskColumns,tablesRead:o,tablesWritten:a,usesMask:n.usesMask,visibility:i.visibility}},E=(e,t)=>{const s=[];for(const i of m(t)){const n=e.getSourceFile(i)??e.addSourceFileAtPath(i),o=p(t,i);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations()){const l=M(c,o);l&&s.push(l)}}return s};export{u as a,E as d,k as m,x as s};
@@ -0,0 +1 @@
1
+ import{readdirSync as x,realpathSync as P,lstatSync as A,statSync as O}from"node:fs";import{dirname as w,join as f,relative as N,sep as F,extname as E}from"node:path";import{Node as s,VariableDeclarationKind as T,SyntaxKind as S}from"ts-morph";import{diagnosticAt as R}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{findProjectConfigFile as D}from"./PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";const I=/\.ts$/u,u=(t,e)=>N(t,e).split(F).join("/").replace(I,""),C=new Set(["_generated","node_modules"]),j=(t,e,i)=>t==="schema.ts"&&e===i,z=t=>{try{return O(t)}catch{console.warn(`@lunora/codegen: skipping ${t} — it is a symlink that does not resolve (or vanished mid-scan).`);return}},b=(t,e,i,r)=>{let o,n;try{o=x(t),n=P(t)}catch{return e}if(r.has(n))return e;r.add(n);for(const a of o){const l=f(t,a),c=z(l);c!==void 0&&(c.isDirectory()?C.has(a)||b(l,e,i,r):c.isFile()&&E(a)===".ts"&&!j(a,t,i)&&e.push(l))}return e},y=t=>b(t,[],t,new Set),V=["src/server","src/index.ts","src/worker.ts"],_=new Set([".ts",".tsx"]),v=(t,e=[])=>{let i;try{i=A(t)}catch{return e}if(i.isFile())return _.has(E(t))&&e.push(t),e;if(!i.isDirectory())return e;for(const r of x(t))r==="_generated"||r==="node_modules"||v(f(t,r),e);return e},K=t=>{const e=w(t),i=y(t).map(n=>({displayPath:u(t,n),filePath:n})),r=new Set(i.map(n=>n.filePath)),o=D(e);for(const n of[...V.flatMap(a=>v(f(e,a))),...o===void 0?[]:[o]])r.has(n)||(r.add(n),i.push({displayPath:u(e,n),filePath:n}));return i},L=(t,e,i)=>{const r=[];for(const{displayPath:o,filePath:n}of e){const a=t.getSourceFile(n)??t.addSourceFileAtPath(n);for(const l of a.getDescendantsOfKind(S.CallExpression)){const c=i(l,o);c!==void 0&&r.push(c)}}return r},J=(t,e,i)=>L(t,y(e).map(r=>({displayPath:u(e,r),filePath:r})),i),Q=(t,e,i)=>L(t,K(e),i),Z=t=>{for(const e of t.getAncestors())if(s.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0)return e.getName();return""},h=t=>{if(s.isStringLiteral(t)||s.isNoSubstitutionTemplateLiteral(t)||s.isNumericLiteral(t))return t.getLiteralText();if(s.isComputedPropertyName(t)){const e=t.getExpression();if(s.isStringLiteral(e)||s.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText()}return t.getText()},k=t=>h(t.getNameNode()),tt=t=>h(t.getPropertyNameNode()??t.getNameNode()),p=(t,e)=>t?.getProperties().find(i=>!s.isSpreadAssignment(i)&&k(i)===e),et=(t,e)=>{if(e){const n=t.getArguments()[0];return n&&(s.isArrowFunction(n)||s.isFunctionExpression(n))?n:void 0}const i=t.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return;const r=p(i,"handler");if(!r||!s.isPropertyAssignment(r))return;const o=r.getInitializer();return o&&(s.isArrowFunction(o)||s.isFunctionExpression(o))?o:void 0},it=(t,e)=>{if(!t||!s.isObjectLiteralExpression(t))return;const i=p(t,e);return i&&s.isPropertyAssignment(i)?i.getInitializer():void 0},$=t=>{const e=t?.getDeclarations().find(o=>s.isVariableDeclaration(o));if(e===void 0||!s.isVariableDeclaration(e))return;const i=e.getParent();if(!s.isVariableDeclarationList(i)||i.getDeclarationKind()!==T.Const)return;const r=i.getParent();return s.isVariableStatement(r)&&s.isSourceFile(r.getParent())?e.getInitializer():void 0},B=t=>$(t.getSymbol()),st=t=>{if(!t)return;if(s.isObjectLiteralExpression(t))return t;if(!s.isIdentifier(t))return;const e=B(t);return e!==void 0&&s.isObjectLiteralExpression(e)?e:void 0},g=t=>s.isPropertyAccessExpression(t)&&t.getName()==="db"||s.isIdentifier(t)&&t.getText()==="db",M=new Set(["findFirst","findFirstOrThrow","findMany","findUnique"]),rt=t=>{const e=t.getExpression();if(!s.isPropertyAccessExpression(e)||!M.has(e.getName()))return;const i=e.getExpression();if(g(i)){const r=t.getArguments()[0];return{options:t.getArguments()[1],table:r&&s.isStringLiteral(r)?r.getLiteralText():""}}if(s.isPropertyAccessExpression(i)){const r=i.getExpression();if(g(r))return{options:t.getArguments()[0],table:i.getName()}}},d=(t,e)=>{const i=t.getExpression();return!s.isPropertyAccessExpression(i)||!e.has(i.getName())?!1:g(i.getExpression())},m=t=>{const e=t.getArguments()[0];return e&&s.isStringLiteral(e)?e.getLiteralText():""},nt=(t,e,i)=>{const r=new Set,o=new Set;for(const n of t.getDescendantsOfKind(S.CallExpression))if(d(n,e)){const a=m(n);a!==""&&r.add(a)}else if(d(n,i)){const a=m(n);a!==""&&o.add(a)}return{tablesRead:[...r],tablesWritten:[...o]}},W=t=>{let e=t;for(;e&&(s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isParenthesizedExpression(e)||s.isNonNullExpression(e));)e=e.getExpression();return e},ot=t=>{const e=W(t);return e&&s.isCallExpression(e)?e:void 0},at=t=>{const e=t.getExportAssignment(o=>!o.isExportEquals());if(!e)return;const i=e.getExpression();if(!s.isIdentifier(i))return i;const r=i.getSymbol()?.getValueDeclaration();return r&&s.isVariableDeclaration(r)?r.getInitializer():i},ct=t=>{const e=t.getArguments()[1];return e&&s.isStringLiteral(e)?e.getLiteralValue():""},lt=(t,e)=>{if(!s.isObjectLiteralExpression(t))return;const i=p(t,e);if(!i||!s.isPropertyAssignment(i))return;const r=i.getInitializer();return r&&s.isStringLiteral(r)?r.getLiteralText():void 0},q=t=>{const e=t.getStatements(),[i]=e;if(e.length!==1||i===void 0||!s.isReturnStatement(i))return;const r=i.getExpression();return r!==void 0&&s.isObjectLiteralExpression(r)?r:void 0},ut=t=>{if(s.isObjectLiteralExpression(t))return t;if(s.isParenthesizedExpression(t)){const e=t.getExpression();return s.isObjectLiteralExpression(e)?e:void 0}return s.isBlock(t)?q(t):void 0},gt=t=>s.isIdentifier(t)&&t.getText()==="ctx",ft=t=>(e,i,r)=>{if(s.isStringLiteral(e)||s.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw R(e,`${t} "${i}": \`${r}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)};export{I as TS_EXTENSION_RE,tt as bindingKeyName,J as collectCallRows,Q as collectSecurityCallRows,at as defaultExportExpression,Z as enclosingExportName,p as findObjectProperty,et as handlerOf,gt as isContextIdentifier,g as isDatabaseAccessor,ct as limitNameOf,y as listLunoraSourceFiles,K as listSecurityScanFiles,u as lunoraRelativePath,ut as objectLiteralFromCallbackBody,st as optionsObjectLiteral,it as propertyInitializer,k as propertyKeyName,h as propertyNameText,rt as readTargetOf,ft as stringPropertyFor,lt as stringPropertyOf,$ as symbolConstInitializer,m as tableArgumentOf,nt as tablesAccessedIn,W as unwrapExpression,ot as unwrapToCallExpression};
@@ -0,0 +1 @@
1
+ import{statSync as p,readFileSync as m}from"node:fs";import{basename as v}from"node:path";import{createJiti as E}from"jiti";import{Project as b,Node as r}from"ts-morph";import{propertyKeyName as u}from"./listLunoraSourceFiles-DP-5e-RE.mjs";import{findProjectConfigFile as f}from"./PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";import{PROJECT_CONFIG_FILENAMES as I}from"./PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";const g=new Map,N=async t=>{const i=f(t);if(i===void 0)return{};let e;try{const n=p(i);e=`${String(n.mtimeMs)}:${String(n.size)}`}catch{return{}}const s=g.get(i);if(s?.key===e)return s.value;const l=(async()=>{try{const o=(await E(i,{interopDefault:!1,moduleCache:!1}).import(i))?.default;return{config:o!==null&&typeof o=="object"?o:void 0}}catch(n){return{error:n instanceof Error?n.message:String(n)}}})();return g.set(i,{key:e,value:l}),l},x=t=>{let e=t.getExportAssignments().find(s=>!s.isExportEquals())?.getExpression();for(;e!==void 0&&(r.isSatisfiesExpression(e)||r.isAsExpression(e)||r.isParenthesizedExpression(e));)e=e.getExpression();if(e!==void 0&&r.isIdentifier(e))for(e=t.getVariableDeclaration(e.getText())?.getInitializer();e!==void 0&&(r.isSatisfiesExpression(e)||r.isAsExpression(e));)e=e.getExpression();return e!==void 0&&r.isObjectLiteralExpression(e)?e:void 0},c=(t,i)=>r.isPropertyAssignment(t)?t.getInitializer():i.getVariableDeclaration(u(t))?.getInitializer(),S=(t,i)=>{let e=t;for(;e!==void 0&&(r.isSatisfiesExpression(e)||r.isAsExpression(e)||r.isParenthesizedExpression(e));)e=e.getExpression();if(e===void 0||!r.isObjectLiteralExpression(e))return{advisor:{unreadable:!0}};const s=e.getProperties(),l=s.filter(a=>r.isPropertyAssignment(a)&&!r.isComputedPropertyName(a.getNameNode())||r.isShorthandPropertyAssignment(a));if(l.length!==s.length)return{advisor:{unreadable:!0}};const n=l.find(a=>u(a)==="minSeverity");if(n===void 0)return{advisor:{}};const o=c(n,i);return o!==void 0&&r.isStringLiteral(o)?{advisor:{minSeverity:o.getLiteralValue()}}:{advisor:{unreadable:!0}}},h=new Map([["advisor",{advisor:{unreadable:!0}}],["remote",{unreadable:!0}],["target",{unreadable:!0}]]),P=(t,i)=>{if(r.isGetAccessorDeclaration(t)||r.isMethodDeclaration(t))return h.get(u(t))??{};if(!r.isPropertyAssignment(t)&&!r.isShorthandPropertyAssignment(t))return{};const e=u(t);if(e==="advisor")return S(c(t,i),i);if(e!=="target"&&e!=="remote")return{};const s=c(t,i);return s===void 0?{unreadable:!0}:e==="target"?r.isStringLiteral(s)?{target:s.getLiteralValue()}:{unreadable:!0}:r.isTrueLiteral(s)||r.isFalseLiteral(s)?{remote:s.getLiteralValue()}:r.isObjectLiteralExpression(s)?{remote:!0}:{unreadable:!0}},O=t=>{const i=f(t);if(i===void 0)return{};let e;try{e=m(i,"utf8")}catch{return{unreadable:!0}}const l=new b({compilerOptions:{allowJs:!0},skipFileDependencyResolution:!0,skipLoadingLibFiles:!0,useInMemoryFileSystem:!0}).createSourceFile(v(i),e,{overwrite:!0}),n=x(l);if(n===void 0)return{unreadable:!0};if(n.getProperties().some(a=>r.isSpreadAssignment(a)))return n.getProperties().some(d=>!r.isSpreadAssignment(d)&&u(d)==="advisor")?{advisor:{unreadable:!0},unreadable:!0}:{unreadable:!0};let o={};for(const a of n.getProperties())o={...o,...P(a,l)};return o};export{I as PROJECT_CONFIG_FILENAMES,f as findProjectConfigFile,N as loadProjectConfig,O as readProjectConfigLiterals};
@@ -1 +1 @@
1
- import{LunoraError as y}from"@lunora/errors";import{Node as n,VariableDeclarationKind as h}from"ts-morph";import{diagnosticAt as v}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{propertyKeyName as E}from"./listLunoraSourceFiles-vjwjgpjd.mjs";let f;const j=e=>{f=e},A=/^[A-Za-z_$][\w$]*$/u,p=new Set(["$defaultFn","$onUpdateFn","$type","default","defaultNow","nullable","serverDefault","unique"]),k=(e,t)=>{const r={notNull:!0,...e.column};switch(t){case"$defaultFn":case"default":case"defaultNow":case"serverDefault":{r.hasDefault=!0;break}case"$onUpdateFn":{r.hasOnUpdate=!0;break}case"$type":break;case"nullable":{r.notNull=!1;break}case"unique":{r.unique=!0;break}}return{...e,column:r}},N=new Set(["any","bigint","boolean","bytes","date","geoPoint","null","number","string","timestamp"]),m=new Set(["check","email","int","length","max","min","pattern","positive","url"]),I=new Set(["meta"]),L=new Set(["strip"]),l=new Set,g=new Set,S=e=>{const t=e.getSymbol();let r=(t?.getAliasedSymbol()??t)?.getValueDeclaration();if(r!==void 0&&n.isShorthandPropertyAssignment(r)){const i=r.getValueSymbol();r=(i?.getAliasedSymbol()??i)?.getValueDeclaration()}if(!(r===void 0||!n.isVariableDeclaration(r)))return r.getInitializer()},T=e=>{const t=e.getParent();return!n.isVariableDeclaration(t)||t.getVariableStatement()?.getDeclarationKind()===h.Const},u=e=>{if(n.isParenthesizedExpression(e)||n.isAsExpression(e)||n.isSatisfiesExpression(e))return u(e.getExpression());if(n.isObjectLiteralExpression(e))return e;if(n.isPropertyAccessExpression(e)){const r=e.getSymbol()?.getValueDeclaration(),i=r!==void 0&&n.isPropertyAssignment(r)?r.getInitializer():void 0;return i===void 0?void 0:u(i)}if(!n.isIdentifier(e)||l.has(e))return;const t=S(e);if(!(t===void 0||!T(t))){l.add(e);try{return u(t)}finally{l.delete(e)}}},w="v",D=e=>{if(n.isIdentifier(e))return!0;let t=e;for(;n.isCallExpression(t);){const r=t.getExpression();if(!n.isPropertyAccessExpression(r))return!1;t=r.getExpression()}return n.isIdentifier(t)&&t.getText()===w},c=e=>{if(n.isIdentifier(e)&&!l.has(e)){const t=S(e);if(t!==void 0&&D(t)){l.add(e);try{return c(t)}finally{l.delete(e)}}}return n.isCallExpression(e)?P(e):{kind:"any",sourceText:e.getText()}},R=e=>{const t=u(e.getExpression());if(t===void 0||g.has(t))return{};g.add(t);try{return b(t)}finally{g.delete(t)}},b=e=>{const t={};for(const r of e.getProperties()){if(n.isSpreadAssignment(r)){Object.assign(t,R(r));continue}const i=n.isShorthandPropertyAssignment(r);if(!i&&!n.isPropertyAssignment(r))continue;const o=r.getNameNode();if(n.isComputedPropertyName(o))continue;const a=i?r.getNameNode():r.getInitializer();if(!a)continue;const s=E(r);if(!A.test(s))throw new y("INTERNAL",`@lunora/codegen: field name is not a valid JS identifier: ${JSON.stringify(s)}`);t[s]=c(a)}return t},d=(e,t)=>e&&n.isExpression(e)?c(e):t,V=e=>e===void 0?"undefined":n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)?JSON.stringify(e.getLiteralValue()):e.getText(),O=e=>{const t=e&&f?f(e):void 0;return t===void 0?{kind:"from"}:{kind:"from",tsType:t}},x=(e,t,r)=>{if(N.has(e))return{kind:e};const[i,o]=t;switch(e){case"array":return{inner:d(i,{kind:"any"}),kind:"array"};case"from":return O(i);case"id":{if(!i||!n.isStringLiteral(i))throw v(i??r,`v.id(...) target table must be a string literal — codegen resolves foreign-key targets statically. Got ${i?i.getText():"no argument"}.`);return{kind:"id",tableName:i.getLiteralText()}}case"literal":return{kind:"literal",literalValue:V(i)};case"object":return i&&n.isObjectLiteralExpression(i)?{kind:"object",shape:b(i)}:{kind:"object",shape:{}};case"optional":return{inner:d(i,{kind:"any"}),kind:"optional"};case"record":return{keyType:d(i,{kind:"string"}),kind:"record",valueType:d(o,{kind:"any"})};case"storage":return i&&n.isStringLiteral(i)?{bucket:i.getLiteralText(),kind:"storage"}:{kind:"storage"};case"union":return{kind:"union",members:t.filter(a=>n.isExpression(a)).map(a=>c(a))};default:throw new y("INTERNAL",`Unsupported validator kind: ${e}`)}},M=e=>{const[t]=e;if(e.length!==1||t===void 0||!n.isNumericLiteral(t))return;const r=Number(t.getText().replaceAll("_",""));return Number.isSafeInteger(r)&&r>=0?r:void 0},P=e=>{const t=e.getExpression();if(!n.isPropertyAccessExpression(t))return{kind:"any",sourceText:e.getText()};const r=t.getName(),i=e.getArguments();if(p.has(r)||m.has(r)||I.has(r)||L.has(r)){const o=t.getExpression(),a=n.isExpression(o)?c(o):{kind:"any"};if(p.has(r))return k(a,r);if(!m.has(r))return a;const s=r==="max"&&a.kind==="string"?M(i):void 0;return s!==void 0?{...a,hasRefinement:!0,stringMaxLength:Math.min(a.stringMaxLength??s,s)}:{...a,hasRefinement:!0,unmodelledRefinement:!0}}return x(r,i,e)};export{c as a,b as p,u as r,j as s};
1
+ import{LunoraError as y}from"@lunora/errors";import{Node as n,VariableDeclarationKind as h}from"ts-morph";import{diagnosticAt as v}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{propertyKeyName as E}from"./listLunoraSourceFiles-DP-5e-RE.mjs";let f;const j=e=>{f=e},A=/^[A-Za-z_$][\w$]*$/u,p=new Set(["$defaultFn","$onUpdateFn","$type","default","defaultNow","nullable","serverDefault","unique"]),k=(e,t)=>{const r={notNull:!0,...e.column};switch(t){case"$defaultFn":case"default":case"defaultNow":case"serverDefault":{r.hasDefault=!0;break}case"$onUpdateFn":{r.hasOnUpdate=!0;break}case"$type":break;case"nullable":{r.notNull=!1;break}case"unique":{r.unique=!0;break}}return{...e,column:r}},N=new Set(["any","bigint","boolean","bytes","date","geoPoint","null","number","string","timestamp"]),m=new Set(["check","email","int","length","max","min","pattern","positive","url"]),I=new Set(["meta"]),L=new Set(["strip"]),l=new Set,g=new Set,S=e=>{const t=e.getSymbol();let r=(t?.getAliasedSymbol()??t)?.getValueDeclaration();if(r!==void 0&&n.isShorthandPropertyAssignment(r)){const i=r.getValueSymbol();r=(i?.getAliasedSymbol()??i)?.getValueDeclaration()}if(!(r===void 0||!n.isVariableDeclaration(r)))return r.getInitializer()},T=e=>{const t=e.getParent();return!n.isVariableDeclaration(t)||t.getVariableStatement()?.getDeclarationKind()===h.Const},u=e=>{if(n.isParenthesizedExpression(e)||n.isAsExpression(e)||n.isSatisfiesExpression(e))return u(e.getExpression());if(n.isObjectLiteralExpression(e))return e;if(n.isPropertyAccessExpression(e)){const r=e.getSymbol()?.getValueDeclaration(),i=r!==void 0&&n.isPropertyAssignment(r)?r.getInitializer():void 0;return i===void 0?void 0:u(i)}if(!n.isIdentifier(e)||l.has(e))return;const t=S(e);if(!(t===void 0||!T(t))){l.add(e);try{return u(t)}finally{l.delete(e)}}},w="v",D=e=>{if(n.isIdentifier(e))return!0;let t=e;for(;n.isCallExpression(t);){const r=t.getExpression();if(!n.isPropertyAccessExpression(r))return!1;t=r.getExpression()}return n.isIdentifier(t)&&t.getText()===w},c=e=>{if(n.isIdentifier(e)&&!l.has(e)){const t=S(e);if(t!==void 0&&D(t)){l.add(e);try{return c(t)}finally{l.delete(e)}}}return n.isCallExpression(e)?P(e):{kind:"any",sourceText:e.getText()}},R=e=>{const t=u(e.getExpression());if(t===void 0||g.has(t))return{};g.add(t);try{return b(t)}finally{g.delete(t)}},b=e=>{const t={};for(const r of e.getProperties()){if(n.isSpreadAssignment(r)){Object.assign(t,R(r));continue}const i=n.isShorthandPropertyAssignment(r);if(!i&&!n.isPropertyAssignment(r))continue;const o=r.getNameNode();if(n.isComputedPropertyName(o))continue;const a=i?r.getNameNode():r.getInitializer();if(!a)continue;const s=E(r);if(!A.test(s))throw new y("INTERNAL",`@lunora/codegen: field name is not a valid JS identifier: ${JSON.stringify(s)}`);t[s]=c(a)}return t},d=(e,t)=>e&&n.isExpression(e)?c(e):t,V=e=>e===void 0?"undefined":n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)?JSON.stringify(e.getLiteralValue()):e.getText(),O=e=>{const t=e&&f?f(e):void 0;return t===void 0?{kind:"from"}:{kind:"from",tsType:t}},x=(e,t,r)=>{if(N.has(e))return{kind:e};const[i,o]=t;switch(e){case"array":return{inner:d(i,{kind:"any"}),kind:"array"};case"from":return O(i);case"id":{if(!i||!n.isStringLiteral(i))throw v(i??r,`v.id(...) target table must be a string literal — codegen resolves foreign-key targets statically. Got ${i?i.getText():"no argument"}.`);return{kind:"id",tableName:i.getLiteralText()}}case"literal":return{kind:"literal",literalValue:V(i)};case"object":return i&&n.isObjectLiteralExpression(i)?{kind:"object",shape:b(i)}:{kind:"object",shape:{}};case"optional":return{inner:d(i,{kind:"any"}),kind:"optional"};case"record":return{keyType:d(i,{kind:"string"}),kind:"record",valueType:d(o,{kind:"any"})};case"storage":return i&&n.isStringLiteral(i)?{bucket:i.getLiteralText(),kind:"storage"}:{kind:"storage"};case"union":return{kind:"union",members:t.filter(a=>n.isExpression(a)).map(a=>c(a))};default:throw new y("INTERNAL",`Unsupported validator kind: ${e}`)}},M=e=>{const[t]=e;if(e.length!==1||t===void 0||!n.isNumericLiteral(t))return;const r=Number(t.getText().replaceAll("_",""));return Number.isSafeInteger(r)&&r>=0?r:void 0},P=e=>{const t=e.getExpression();if(!n.isPropertyAccessExpression(t))return{kind:"any",sourceText:e.getText()};const r=t.getName(),i=e.getArguments();if(p.has(r)||m.has(r)||I.has(r)||L.has(r)){const o=t.getExpression(),a=n.isExpression(o)?c(o):{kind:"any"};if(p.has(r))return k(a,r);if(!m.has(r))return a;const s=r==="max"&&a.kind==="string"?M(i):void 0;return s!==void 0?{...a,hasRefinement:!0,stringMaxLength:Math.min(a.stringMaxLength??s,s)}:{...a,hasRefinement:!0,unmodelledRefinement:!0}}return x(r,i,e)};export{c as a,b as p,u as r,j as s};
@@ -1 +1 @@
1
- import{Node as s,SyntaxKind as f}from"ts-morph";import{bindingKeyName as P,listLunoraSourceFiles as v,lunoraRelativePath as A,isDatabaseAccessor as h}from"./listLunoraSourceFiles-vjwjgpjd.mjs";const I=t=>{const e=t.getText(),n=r=>{const i=r.getNameNode();return s.isIdentifier(i)&&i.getText()===e};for(const r of t.getAncestors())if(!(!s.isArrowFunction(r)&&!s.isFunctionExpression(r)&&!s.isFunctionDeclaration(r)))for(const i of r.getParameters()){const a=i.getDescendantsOfKind(f.BindingElement).find(o=>n(o));if(a!==void 0)return a}},N=t=>{let e=t;for(;;){const n=e.getParent();if(!s.isObjectBindingPattern(n))return;const r=n.getParent();if(s.isBindingElement(r)){e=r;continue}return s.isParameterDeclaration(r)?P(e):void 0}},x=(t,e)=>{const n=t.getParent();if(s.isPropertyAccessExpression(n)&&n.getNameNode()===t||s.isPropertyAssignment(n)&&n.getNameNode()===t)return!1;if(t.getText()===e)return!0;const r=I(t);return r!==void 0&&N(r)===e},p=(t,e)=>s.isIdentifier(t)?x(t,e):t.getDescendantsOfKind(f.Identifier).some(n=>x(n,e)),g=t=>p(t,"ctx"),b=t=>{let e=t;for(;s.isPropertyAccessExpression(e)||s.isElementAccessExpression(e)||s.isNonNullExpression(e);)e=e.getExpression();return s.isIdentifier(e)?e:void 0},E=t=>p(t,"args"),u=t=>{if(!s.isIdentifier(t))return;const e=t.getText(),n=t.getFirstAncestor(o=>s.isArrowFunction(o)||s.isFunctionExpression(o)||s.isFunctionDeclaration(o));if(n===void 0)return;const r=t.getStart();let i,a=-1;for(const o of n.getDescendantsOfKind(f.VariableDeclaration)){if(o.getName()!==e)continue;const c=o.getInitializer(),l=o.getStart();c!==void 0&&l<r&&l>a&&(i=c,a=l)}return i},C=t=>{if(E(t))return!0;const e=u(t);return e!==void 0&&E(e)},_=t=>{if(s.isCallExpression(t)||s.isNewExpression(t))return!1;const e=u(t);return e===void 0||!(s.isCallExpression(e)||s.isNewExpression(e))},B=t=>{if(g(t))return!0;const e=u(t);if(e!==void 0&&g(e))return!0;const n=e??t;return(s.isIdentifier(n)?[n]:n.getDescendantsOfKind(f.Identifier)).some(i=>{const a=u(i);return a!==void 0&&g(a)})},m=(t,e)=>p(t,e),L=(t,e)=>{if(m(t,e))return!0;const n=u(t);if(n!==void 0&&m(n,e))return!0;const r=b(t);if(r!==void 0){const i=u(r);return i!==void 0&&m(i,e)}return!1},D=t=>{for(const e of t.getAncestors())if(s.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0)return e.getName();return"<module>"},y=new Set(["withGeoIndex","withIndex","withSearchIndex"]),S=new Set(["collect","collectWithScores","first","paginate","take","unique"]),F=t=>{const e=t.getExpression();if(!s.isPropertyAccessExpression(e)||e.getName()!=="query")return!1;const n=e.getExpression();return h(n)},w=t=>{const e=[];let n=t;for(;;){const r=n.getParent();if(!r||!s.isPropertyAccessExpression(r))break;const i=r.getParent();if(!i||!s.isCallExpression(i))break;e.push(r.getName()),n=i}return e},R=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,K=t=>{let e=t;for(;;){const n=e.getParent();if(!n||!s.isPropertyAccessExpression(n))return!1;const r=n.getParent();if(!r||!s.isCallExpression(r))return!1;if(n.getName()==="filter"){const i=r.getArguments()[0];if(i&&R.test(i.getText()))return!0}e=r}},z=t=>{const e=t.getArguments()[0];return e&&s.isStringLiteral(e)?e.getLiteralText():""},M=(t,e)=>{const n=[];for(const r of v(e)){const i=t.getSourceFile(r)??t.addSourceFileAtPath(r),a=A(e,r);for(const o of i.getDescendantsOfKind(f.CallExpression)){if(!F(o))continue;const c=w(o),l=c.includes("filter");n.push({exportName:D(o),file:a,filtersPrimaryKey:l&&K(o),hasFilter:l,hasIndex:c.some(d=>y.has(d)),line:o.getStartLineNumber(),table:z(o),terminal:c.findLast(d=>S.has(d))})}}return n};export{B as a,_ as b,L as c,M as d,D as e,m as f,C as i,E as r,u as s};
1
+ import{Node as s,SyntaxKind as f}from"ts-morph";import{bindingKeyName as P,listLunoraSourceFiles as v,lunoraRelativePath as A,isDatabaseAccessor as h}from"./listLunoraSourceFiles-DP-5e-RE.mjs";const I=t=>{const e=t.getText(),n=r=>{const i=r.getNameNode();return s.isIdentifier(i)&&i.getText()===e};for(const r of t.getAncestors())if(!(!s.isArrowFunction(r)&&!s.isFunctionExpression(r)&&!s.isFunctionDeclaration(r)))for(const i of r.getParameters()){const a=i.getDescendantsOfKind(f.BindingElement).find(o=>n(o));if(a!==void 0)return a}},N=t=>{let e=t;for(;;){const n=e.getParent();if(!s.isObjectBindingPattern(n))return;const r=n.getParent();if(s.isBindingElement(r)){e=r;continue}return s.isParameterDeclaration(r)?P(e):void 0}},x=(t,e)=>{const n=t.getParent();if(s.isPropertyAccessExpression(n)&&n.getNameNode()===t||s.isPropertyAssignment(n)&&n.getNameNode()===t)return!1;if(t.getText()===e)return!0;const r=I(t);return r!==void 0&&N(r)===e},p=(t,e)=>s.isIdentifier(t)?x(t,e):t.getDescendantsOfKind(f.Identifier).some(n=>x(n,e)),g=t=>p(t,"ctx"),b=t=>{let e=t;for(;s.isPropertyAccessExpression(e)||s.isElementAccessExpression(e)||s.isNonNullExpression(e);)e=e.getExpression();return s.isIdentifier(e)?e:void 0},E=t=>p(t,"args"),u=t=>{if(!s.isIdentifier(t))return;const e=t.getText(),n=t.getFirstAncestor(o=>s.isArrowFunction(o)||s.isFunctionExpression(o)||s.isFunctionDeclaration(o));if(n===void 0)return;const r=t.getStart();let i,a=-1;for(const o of n.getDescendantsOfKind(f.VariableDeclaration)){if(o.getName()!==e)continue;const c=o.getInitializer(),l=o.getStart();c!==void 0&&l<r&&l>a&&(i=c,a=l)}return i},C=t=>{if(E(t))return!0;const e=u(t);return e!==void 0&&E(e)},_=t=>{if(s.isCallExpression(t)||s.isNewExpression(t))return!1;const e=u(t);return e===void 0||!(s.isCallExpression(e)||s.isNewExpression(e))},B=t=>{if(g(t))return!0;const e=u(t);if(e!==void 0&&g(e))return!0;const n=e??t;return(s.isIdentifier(n)?[n]:n.getDescendantsOfKind(f.Identifier)).some(i=>{const a=u(i);return a!==void 0&&g(a)})},m=(t,e)=>p(t,e),L=(t,e)=>{if(m(t,e))return!0;const n=u(t);if(n!==void 0&&m(n,e))return!0;const r=b(t);if(r!==void 0){const i=u(r);return i!==void 0&&m(i,e)}return!1},D=t=>{for(const e of t.getAncestors())if(s.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0)return e.getName();return"<module>"},y=new Set(["withGeoIndex","withIndex","withSearchIndex"]),S=new Set(["collect","collectWithScores","first","paginate","take","unique"]),F=t=>{const e=t.getExpression();if(!s.isPropertyAccessExpression(e)||e.getName()!=="query")return!1;const n=e.getExpression();return h(n)},w=t=>{const e=[];let n=t;for(;;){const r=n.getParent();if(!r||!s.isPropertyAccessExpression(r))break;const i=r.getParent();if(!i||!s.isCallExpression(i))break;e.push(r.getName()),n=i}return e},R=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,K=t=>{let e=t;for(;;){const n=e.getParent();if(!n||!s.isPropertyAccessExpression(n))return!1;const r=n.getParent();if(!r||!s.isCallExpression(r))return!1;if(n.getName()==="filter"){const i=r.getArguments()[0];if(i&&R.test(i.getText()))return!0}e=r}},z=t=>{const e=t.getArguments()[0];return e&&s.isStringLiteral(e)?e.getLiteralText():""},M=(t,e)=>{const n=[];for(const r of v(e)){const i=t.getSourceFile(r)??t.addSourceFileAtPath(r),a=A(e,r);for(const o of i.getDescendantsOfKind(f.CallExpression)){if(!F(o))continue;const c=w(o),l=c.includes("filter");n.push({exportName:D(o),file:a,filtersPrimaryKey:l&&K(o),hasFilter:l,hasIndex:c.some(d=>y.has(d)),line:o.getStartLineNumber(),table:z(o),terminal:c.findLast(d=>S.has(d))})}}return n};export{B as a,_ as b,L as c,M as d,D as e,m as f,C as i,E as r,u as s};
@@ -1 +1 @@
1
- import{Node as l,SyntaxKind as g}from"ts-morph";import{lunoraRelativePath as L}from"./listLunoraSourceFiles-vjwjgpjd.mjs";import{posix as D}from"node:path";let S,v;const Ae=e=>{const t=S,n=[];S=n;try{return{erased:n,value:e()}}finally{S=t}},Te=e=>{S?.push(...e)},j=e=>{for(const t of e.getAncestors())if(l.isVariableDeclaration(t))return t.getName()},w=(e,t)=>{S?.push({exportName:j(e),filePath:e.getSourceFile().getFilePath(),line:e.getStartLineNumber(),rendered:t})},Ne=e=>{v!==void 0&&w(v,e)},xe=(e,t)=>{const n=v;v=e;try{return t()}finally{v=n}},k=(e,t)=>{const n=e.exportName??`line ${e.line.toString()}`;return{cacheKey:`procedure_return_type_erased:${t}:${n}`,categories:["SCHEMA"],description:"Codegen renders a procedure's return type into `_generated/`, where only names that resolve from that directory may appear. A type it can neither name nor reproduce structurally — a class instance, a call or index signature, a recursive or very deeply nested shape — is emitted as `unknown` instead, so callers lose the shape while the runtime still returns it.",detail:`\`${n}\` in \`${t}\` (line ${e.line.toString()}) returns \`${e.rendered}\`, which codegen could not reproduce — its generated type is \`unknown\`.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e.exportName,filePath:t,line:e.line,rendered:e.rendered},name:"procedure_return_type_erased",remediation:"Declare the shape explicitly with `.output(...)`, or export the type from the module that declares it so codegen can name it. A class instance cannot cross the wire at all — return a plain object.",title:"Procedure return type is missing from the generated type"}},De=(e,t)=>{const n=new Map;for(const r of e){const s=k(r,L(t,r.filePath));n.set(s.cacheKey,s)}return[...n.values()].toSorted((r,s)=>r.cacheKey.localeCompare(s.cacheKey))},P=/\bany\b(?!\s*(?:\?\s*)?:)/u,U=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,O=e=>P.test(e.replaceAll(U,"")),K="/_generated/",B=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(n=>n?.getDeclarations()??[]);return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},F=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,T=e=>{for(const t of e.getAncestors())if(l.isModuleDeclaration(t)){const n=F.exec(t.getName());if(n?.groups?.specifier!==void 0)return n.groups.specifier}},h=new WeakMap,V=(e,t)=>{const n=e.getSymbol();if(n===void 0)return;let r=h.get(n.compilerSymbol);return r===void 0&&(r=new Map,h.set(n.compilerSymbol,r)),r.has(t)||r.set(t,n.getExport(t)??e.getExportSymbols().find(s=>s.getName()===t)),r.get(t)},_=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(n=>n.getName()===t),W=(e,t,n)=>e.getModuleSpecifierValue()===t&&_(e,n)?n:void 0,q=(e,t)=>{const n=e.getDefaultImport();if(n===void 0)return;const r=n.getSymbol();return(r?.getAliasedSymbol()??r)?.getDeclarations().includes(t)===!0?"default":void 0},G=(e,t,n)=>{if(!_(e,n))return;const r=e.getModuleSpecifierSourceFile(),s=r===void 0?void 0:V(r,n);return(s?.getAliasedSymbol()??s)?.getDeclarations().includes(t)===!0?n:void 0},X=/^\.\.?(?:$|\/)/u,H=new Map([[".cjs",".cjs"],[".cts",".cjs"],[".d.ts",".js"],[".js",".js"],[".jsx",".jsx"],[".mjs",".mjs"],[".mts",".mjs"],[".ts",".js"],[".tsx",".js"]]),Y=(e,t)=>{const n=t.getModuleSpecifierValue();if(!X.test(n))return;const r=t.getModuleSpecifierSourceFile(),s=r===void 0?void 0:H.get(r.getExtension());if(r===void 0||s===void 0)return;const i=`${D.join(r.getDirectoryPath(),r.getBaseNameWithoutExtension())}${s}`,o=D.relative(e.getDirectoryPath(),i);return o.startsWith(".")?o:`./${o}`},J=(e,t,n)=>{const r=T(t);for(const s of e.getImportDeclarations()){const i=r===void 0?q(s,t)??G(s,t,n):W(s,r,n);if(i!==void 0)return{exportName:i,specifier:Y(e,s)??s.getModuleSpecifierValue()}}},z=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(n=>{const r=n.indexOf("*");return r===-1?e===n:e.startsWith(n.slice(0,r))&&e.endsWith(n.slice(r+1))}),m={kind:"verbatim"},p={kind:"expand"},Q=new Set([g.ClassDeclaration,g.EnumDeclaration,g.EnumMember,g.InterfaceDeclaration,g.TypeAliasDeclaration]),Z=e=>T(e)!==void 0||l.isExportable(e)&&e.isExported(),ee=(e,t)=>new RegExp(String.raw`(?<![$\w])${t.replaceAll(/[$()*+.?[\\\]^{|}]/gu,String.raw`\$&`)}(?![$\w])`,"u").test(e),M=(e,t,n,r)=>{const s=e.getSourceFile();if(s.getSymbol()===void 0&&T(e)===void 0||!Q.has(e.getKind()))return m;const i=s.getFilePath();if(i.includes(K))return m;if(i===n)return p;const o=l.isEnumMember(e)?e.getParent():e;if(!l.hasName(o))return p;const a=J(t.getSourceFile(),o,o.getName());return a===void 0?Z(o)||!ee(r(),o.getName())?m:p:z(a.specifier,t)?p:{kind:"qualify",qualified:a}},te=new Set([g.ClassDeclaration,g.EnumDeclaration,g.FunctionDeclaration,g.ModuleDeclaration]),I=e=>{const t=e?.getDeclarations()??[];return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},ne=e=>{for(const t of e.getDeclarations()){const n=t.getFirstChildByKind(g.ComputedPropertyName);if(n!==void 0){let r=n.getExpression();for(;l.isPropertyAccessExpression(r);)r=r.getExpression();return r}}},re=(e,t)=>{if(e.getProperties().some(s=>{if(!s.getName().startsWith("__@"))return!1;const i=ne(s);return i===void 0||!I(i.getSymbol())}))return!0;const r=e.getSymbol();return r!==void 0&&r.getDeclarations().some(s=>te.has(s.getKind()))&&!I(r)&&t().startsWith("typeof ")},R=(e,t,n)=>{const r=e.getAliasSymbol(),s=e.getSymbol(),i=new Set((r??s)?.getDeclarations());let o=!1,a;const c=()=>(a??=e.getText(t),a);for(const u of[s,r].flatMap(d=>d?.getDeclarations()??[])){const d=M(u,t,n,c);if(d.kind==="qualify"&&i.has(u))return d;o||=d.kind!=="verbatim"}return o||re(e,c)?p:m},se=(e,t,n)=>{const r=l.isPropertySignature(e)||l.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(r===void 0)return m;let s=!1;for(const i of[r,...r.getDescendantsOfKind(g.TypeReference)].filter(o=>l.isTypeReference(o))){const o=i.getTypeName().getSymbol();for(const a of(o?.getAliasedSymbol()??o)?.getDeclarations()??[]){const c=M(a,t,n,()=>i.getText());if(c.kind==="qualify")return c;s||=c.kind!=="verbatim"}}return s?p:m},oe=/^[A-Za-z_$][\w$]*$/u,ie=e=>oe.test(e)?e:JSON.stringify(e),$=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},y=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0&&!e.getProperties().some(t=>t.getName().startsWith("__@")),E=(e,t,n,r=new Set)=>r.has(e)?!1:(r.add(e),R(e,t,n).kind!=="verbatim"||$(e).some(s=>E(s,t,n,r))?!0:y(e)?e.getProperties().some(s=>s.getDeclarations().some(i=>se(i,t,n).kind!=="verbatim")?!0:E(s.getTypeAtLocation(t),t,n,r)):!1),ae=(e,t)=>{const n=e.getValueDeclaration()??e.getDeclarations()[0];return n&&(l.isPropertySignature(n)||l.isPropertyDeclaration(n))&&n.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},C=(e,t)=>e!==void 0&&(y(e)||e.isString()||e.isNumber()||e.isBigInt()||e.isBoolean()||e.isLiteral()||e.isBooleanLiteral()||e.isEnumLiteral()||e.isTemplateLiteral()||e.isNull()||e.isUndefined()||e.isAny()||e.isUnknown()||e.isNever()||e.isVoid())?t:`(${t})`,ce=32,ue=8,le=(e,t,n,r,s,i)=>{const o=e.getArrayElementType(),a=o?i(o,t,n,r,s):void 0;if(a!==void 0)return`${C(o,a)}[]`},ge=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getUnionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(c)}return o.join(" | ")},de=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getIntersectionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(C(a,c))}return o.join(" & ")},me=(e,t,n,r,s,i)=>{if(!y(e))return;const o=[];for(const a of e.getProperties()){const c=a.getTypeAtLocation(t),u=ae(a,c),d=u&&c.isUnion()?c.getUnionTypes().filter(A=>!A.isUndefined()):[c],N=[];for(const A of d){const x=i(A,t,n,r+1,s);if(x===void 0)return;N.push(x)}o.push(`${ie(a.getName())}${u?"?":""}: ${N.join(" | ")}`)}return o.length>0?`{ ${o.join("; ")} }`:"{}"},fe=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},pe=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isClassDeclaration(t)||l.isClassExpression(t)),b=(e,t,n,r,s=new Set)=>{if(r.has(e)||s.has(e))return!1;if(n>ce)return!0;const i=new Set(r).add(e);if($(e).some(u=>b(u,t,n+1,i,s)))return!0;const o=e.getArrayElementType();if(o!==void 0)return b(o,t,n+1,i,s);if(B(e))return s.add(e),!1;if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(u=>u?.getDeclarations()??[]).some(u=>l.isClassDeclaration(u)||l.isClassExpression(u)))return!0;const c=y(e)&&e.getProperties().some(u=>b(u.getTypeAtLocation(t),t,n+1,i,s));return c||s.add(e),c},Se=(e,t,n,r,s,i,o)=>{const a=[];for(const c of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const u=o(c,n,r,s+1,i);if(u===void 0)return;a.push(u)}return`import("${e.specifier}").${e.exportName}${a.length>0?`<${a.join(", ")}>`:""}`},ve=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isEnumDeclaration(t)||l.isEnumMember(t)),f=(e,t,n,r,s)=>{if(r>ue||s.has(e))return;const i=R(e,t,n);if(i.kind==="verbatim"&&!E(e,t,n))return e.getText(t);const o=new Set(s).add(e);if(!pe(e)){if(e.isEnumLiteral())return fe(e);if(i.kind==="qualify"&&!ve(e)){const a=Se(i.qualified,e,t,n,r,o,f);if(a!==void 0)return a}return e.isArray()?le(e,t,n,r,o,f):e.isUnion()?ge(e,t,n,r,o,f):e.isIntersection()?de(e,t,n,r,o,f):me(e,t,n,r,o,f)}},he=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let n=t.getReturnType();const s=(n.getSymbol()??n.getAliasSymbol())?.getName();if(s==="Promise"||s==="AsyncIterable"||s==="AsyncIterableIterator"||s==="AsyncGenerator"){const a=n.getTypeArguments()[0];a&&(n=a)}const i=n.getText(e);if(!i||i==="any"||i==="never"||O(i)||b(n,e,0,new Set))return"unknown";const o=e.getSourceFile().getFilePath();if(E(n,e,o)){const a=f(n,e,o,0,new Set);return a===void 0&&w(e,i),a??"unknown"}return i};export{E as a,Ne as b,Ae as c,De as d,f as e,O as i,xe as p,Te as r,he as u};
1
+ import{Node as l,SyntaxKind as g}from"ts-morph";import{lunoraRelativePath as L}from"./listLunoraSourceFiles-DP-5e-RE.mjs";import{posix as D}from"node:path";let S,v;const Ae=e=>{const t=S,n=[];S=n;try{return{erased:n,value:e()}}finally{S=t}},Te=e=>{S?.push(...e)},j=e=>{for(const t of e.getAncestors())if(l.isVariableDeclaration(t))return t.getName()},w=(e,t)=>{S?.push({exportName:j(e),filePath:e.getSourceFile().getFilePath(),line:e.getStartLineNumber(),rendered:t})},Ne=e=>{v!==void 0&&w(v,e)},xe=(e,t)=>{const n=v;v=e;try{return t()}finally{v=n}},k=(e,t)=>{const n=e.exportName??`line ${e.line.toString()}`;return{cacheKey:`procedure_return_type_erased:${t}:${n}`,categories:["SCHEMA"],description:"Codegen renders a procedure's return type into `_generated/`, where only names that resolve from that directory may appear. A type it can neither name nor reproduce structurally — a class instance, a call or index signature, a recursive or very deeply nested shape — is emitted as `unknown` instead, so callers lose the shape while the runtime still returns it.",detail:`\`${n}\` in \`${t}\` (line ${e.line.toString()}) returns \`${e.rendered}\`, which codegen could not reproduce — its generated type is \`unknown\`.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e.exportName,filePath:t,line:e.line,rendered:e.rendered},name:"procedure_return_type_erased",remediation:"Declare the shape explicitly with `.output(...)`, or export the type from the module that declares it so codegen can name it. A class instance cannot cross the wire at all — return a plain object.",title:"Procedure return type is missing from the generated type"}},De=(e,t)=>{const n=new Map;for(const r of e){const s=k(r,L(t,r.filePath));n.set(s.cacheKey,s)}return[...n.values()].toSorted((r,s)=>r.cacheKey.localeCompare(s.cacheKey))},P=/\bany\b(?!\s*(?:\?\s*)?:)/u,U=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,O=e=>P.test(e.replaceAll(U,"")),K="/_generated/",B=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(n=>n?.getDeclarations()??[]);return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},F=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,T=e=>{for(const t of e.getAncestors())if(l.isModuleDeclaration(t)){const n=F.exec(t.getName());if(n?.groups?.specifier!==void 0)return n.groups.specifier}},h=new WeakMap,V=(e,t)=>{const n=e.getSymbol();if(n===void 0)return;let r=h.get(n.compilerSymbol);return r===void 0&&(r=new Map,h.set(n.compilerSymbol,r)),r.has(t)||r.set(t,n.getExport(t)??e.getExportSymbols().find(s=>s.getName()===t)),r.get(t)},_=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(n=>n.getName()===t),W=(e,t,n)=>e.getModuleSpecifierValue()===t&&_(e,n)?n:void 0,q=(e,t)=>{const n=e.getDefaultImport();if(n===void 0)return;const r=n.getSymbol();return(r?.getAliasedSymbol()??r)?.getDeclarations().includes(t)===!0?"default":void 0},G=(e,t,n)=>{if(!_(e,n))return;const r=e.getModuleSpecifierSourceFile(),s=r===void 0?void 0:V(r,n);return(s?.getAliasedSymbol()??s)?.getDeclarations().includes(t)===!0?n:void 0},X=/^\.\.?(?:$|\/)/u,H=new Map([[".cjs",".cjs"],[".cts",".cjs"],[".d.ts",".js"],[".js",".js"],[".jsx",".jsx"],[".mjs",".mjs"],[".mts",".mjs"],[".ts",".js"],[".tsx",".js"]]),Y=(e,t)=>{const n=t.getModuleSpecifierValue();if(!X.test(n))return;const r=t.getModuleSpecifierSourceFile(),s=r===void 0?void 0:H.get(r.getExtension());if(r===void 0||s===void 0)return;const i=`${D.join(r.getDirectoryPath(),r.getBaseNameWithoutExtension())}${s}`,o=D.relative(e.getDirectoryPath(),i);return o.startsWith(".")?o:`./${o}`},J=(e,t,n)=>{const r=T(t);for(const s of e.getImportDeclarations()){const i=r===void 0?q(s,t)??G(s,t,n):W(s,r,n);if(i!==void 0)return{exportName:i,specifier:Y(e,s)??s.getModuleSpecifierValue()}}},z=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(n=>{const r=n.indexOf("*");return r===-1?e===n:e.startsWith(n.slice(0,r))&&e.endsWith(n.slice(r+1))}),m={kind:"verbatim"},p={kind:"expand"},Q=new Set([g.ClassDeclaration,g.EnumDeclaration,g.EnumMember,g.InterfaceDeclaration,g.TypeAliasDeclaration]),Z=e=>T(e)!==void 0||l.isExportable(e)&&e.isExported(),ee=(e,t)=>new RegExp(String.raw`(?<![$\w])${t.replaceAll(/[$()*+.?[\\\]^{|}]/gu,String.raw`\$&`)}(?![$\w])`,"u").test(e),M=(e,t,n,r)=>{const s=e.getSourceFile();if(s.getSymbol()===void 0&&T(e)===void 0||!Q.has(e.getKind()))return m;const i=s.getFilePath();if(i.includes(K))return m;if(i===n)return p;const o=l.isEnumMember(e)?e.getParent():e;if(!l.hasName(o))return p;const a=J(t.getSourceFile(),o,o.getName());return a===void 0?Z(o)||!ee(r(),o.getName())?m:p:z(a.specifier,t)?p:{kind:"qualify",qualified:a}},te=new Set([g.ClassDeclaration,g.EnumDeclaration,g.FunctionDeclaration,g.ModuleDeclaration]),I=e=>{const t=e?.getDeclarations()??[];return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},ne=e=>{for(const t of e.getDeclarations()){const n=t.getFirstChildByKind(g.ComputedPropertyName);if(n!==void 0){let r=n.getExpression();for(;l.isPropertyAccessExpression(r);)r=r.getExpression();return r}}},re=(e,t)=>{if(e.getProperties().some(s=>{if(!s.getName().startsWith("__@"))return!1;const i=ne(s);return i===void 0||!I(i.getSymbol())}))return!0;const r=e.getSymbol();return r!==void 0&&r.getDeclarations().some(s=>te.has(s.getKind()))&&!I(r)&&t().startsWith("typeof ")},R=(e,t,n)=>{const r=e.getAliasSymbol(),s=e.getSymbol(),i=new Set((r??s)?.getDeclarations());let o=!1,a;const c=()=>(a??=e.getText(t),a);for(const u of[s,r].flatMap(d=>d?.getDeclarations()??[])){const d=M(u,t,n,c);if(d.kind==="qualify"&&i.has(u))return d;o||=d.kind!=="verbatim"}return o||re(e,c)?p:m},se=(e,t,n)=>{const r=l.isPropertySignature(e)||l.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(r===void 0)return m;let s=!1;for(const i of[r,...r.getDescendantsOfKind(g.TypeReference)].filter(o=>l.isTypeReference(o))){const o=i.getTypeName().getSymbol();for(const a of(o?.getAliasedSymbol()??o)?.getDeclarations()??[]){const c=M(a,t,n,()=>i.getText());if(c.kind==="qualify")return c;s||=c.kind!=="verbatim"}}return s?p:m},oe=/^[A-Za-z_$][\w$]*$/u,ie=e=>oe.test(e)?e:JSON.stringify(e),$=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},y=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0&&!e.getProperties().some(t=>t.getName().startsWith("__@")),E=(e,t,n,r=new Set)=>r.has(e)?!1:(r.add(e),R(e,t,n).kind!=="verbatim"||$(e).some(s=>E(s,t,n,r))?!0:y(e)?e.getProperties().some(s=>s.getDeclarations().some(i=>se(i,t,n).kind!=="verbatim")?!0:E(s.getTypeAtLocation(t),t,n,r)):!1),ae=(e,t)=>{const n=e.getValueDeclaration()??e.getDeclarations()[0];return n&&(l.isPropertySignature(n)||l.isPropertyDeclaration(n))&&n.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},C=(e,t)=>e!==void 0&&(y(e)||e.isString()||e.isNumber()||e.isBigInt()||e.isBoolean()||e.isLiteral()||e.isBooleanLiteral()||e.isEnumLiteral()||e.isTemplateLiteral()||e.isNull()||e.isUndefined()||e.isAny()||e.isUnknown()||e.isNever()||e.isVoid())?t:`(${t})`,ce=32,ue=8,le=(e,t,n,r,s,i)=>{const o=e.getArrayElementType(),a=o?i(o,t,n,r,s):void 0;if(a!==void 0)return`${C(o,a)}[]`},ge=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getUnionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(c)}return o.join(" | ")},de=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getIntersectionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(C(a,c))}return o.join(" & ")},me=(e,t,n,r,s,i)=>{if(!y(e))return;const o=[];for(const a of e.getProperties()){const c=a.getTypeAtLocation(t),u=ae(a,c),d=u&&c.isUnion()?c.getUnionTypes().filter(A=>!A.isUndefined()):[c],N=[];for(const A of d){const x=i(A,t,n,r+1,s);if(x===void 0)return;N.push(x)}o.push(`${ie(a.getName())}${u?"?":""}: ${N.join(" | ")}`)}return o.length>0?`{ ${o.join("; ")} }`:"{}"},fe=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},pe=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isClassDeclaration(t)||l.isClassExpression(t)),b=(e,t,n,r,s=new Set)=>{if(r.has(e)||s.has(e))return!1;if(n>ce)return!0;const i=new Set(r).add(e);if($(e).some(u=>b(u,t,n+1,i,s)))return!0;const o=e.getArrayElementType();if(o!==void 0)return b(o,t,n+1,i,s);if(B(e))return s.add(e),!1;if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(u=>u?.getDeclarations()??[]).some(u=>l.isClassDeclaration(u)||l.isClassExpression(u)))return!0;const c=y(e)&&e.getProperties().some(u=>b(u.getTypeAtLocation(t),t,n+1,i,s));return c||s.add(e),c},Se=(e,t,n,r,s,i,o)=>{const a=[];for(const c of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const u=o(c,n,r,s+1,i);if(u===void 0)return;a.push(u)}return`import("${e.specifier}").${e.exportName}${a.length>0?`<${a.join(", ")}>`:""}`},ve=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isEnumDeclaration(t)||l.isEnumMember(t)),f=(e,t,n,r,s)=>{if(r>ue||s.has(e))return;const i=R(e,t,n);if(i.kind==="verbatim"&&!E(e,t,n))return e.getText(t);const o=new Set(s).add(e);if(!pe(e)){if(e.isEnumLiteral())return fe(e);if(i.kind==="qualify"&&!ve(e)){const a=Se(i.qualified,e,t,n,r,o,f);if(a!==void 0)return a}return e.isArray()?le(e,t,n,r,o,f):e.isUnion()?ge(e,t,n,r,o,f):e.isIntersection()?de(e,t,n,r,o,f):me(e,t,n,r,o,f)}},he=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let n=t.getReturnType();const s=(n.getSymbol()??n.getAliasSymbol())?.getName();if(s==="Promise"||s==="AsyncIterable"||s==="AsyncIterableIterator"||s==="AsyncGenerator"){const a=n.getTypeArguments()[0];a&&(n=a)}const i=n.getText(e);if(!i||i==="any"||i==="never"||O(i)||b(n,e,0,new Set))return"unknown";const o=e.getSourceFile().getFilePath();if(E(n,e,o)){const a=f(n,e,o,0,new Set);return a===void 0&&w(e,i),a??"unknown"}return i};export{E as a,Ne as b,Ae as c,De as d,f as e,O as i,xe as p,Te as r,he as u};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.220",
3
+ "version": "1.0.0-alpha.221",
4
4
  "description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -46,15 +46,15 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@lunora/advisor": "1.0.0-alpha.159",
50
- "@lunora/agent": "1.0.0-alpha.140",
51
- "@lunora/container": "1.0.0-alpha.57",
52
- "@lunora/errors": "1.0.0-alpha.41",
49
+ "@lunora/advisor": "1.0.0-alpha.160",
50
+ "@lunora/agent": "1.0.0-alpha.141",
51
+ "@lunora/container": "1.0.0-alpha.58",
52
+ "@lunora/errors": "1.0.0-alpha.42",
53
53
  "@lunora/platform": "1.0.0-alpha.39",
54
- "@lunora/queue": "1.0.0-alpha.69",
55
- "@lunora/scheduler": "1.0.0-alpha.87",
56
- "@lunora/values": "1.0.0-alpha.52",
57
- "@lunora/workflow": "1.0.0-alpha.63",
54
+ "@lunora/queue": "1.0.0-alpha.70",
55
+ "@lunora/scheduler": "1.0.0-alpha.88",
56
+ "@lunora/values": "1.0.0-alpha.53",
57
+ "@lunora/workflow": "1.0.0-alpha.64",
58
58
  "jiti": "^2.7.0",
59
59
  "quicktype-core": "^26.0.0",
60
60
  "ts-morph": "^28.0.0"
@@ -1 +0,0 @@
1
- import{NODE_CAPABILITIES as f,CLOUDFLARE_CAPABILITIES as h}from"@lunora/platform";import{readProjectConfigLiterals as m}from"./PROJECT_CONFIG_FILENAMES-DfD2MHzr.mjs";const c="cloudflare",v=t=>{const{target:e}=m(t);return e!==void 0&&e.length>0?e:void 0},x=(t,e)=>e??v(t)??c,L=(t,e)=>{if(e!==void 0)return[];const{target:a,unreadable:o}=m(t);return o!==!0||a!==void 0?[]:[{level:"warn",message:`lunora.config declares a \`target\` that codegen cannot read without evaluating it, so the "${c}" 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: "${c}" }\`), or pass \`--target\`.`,target:c}]},u={cloudflare:h,node:f},I=()=>Object.keys(u).toSorted((t,e)=>t.localeCompare(e)),b={access:null,ai:"ai",analytics:"analytics",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:null},y=["agents","commitOrderedTables","cronTriggers","crossShardFanout","durableStreams","globalTables","queues","relationGraph","secrets","vectorStore"],g={agents:"durable agents (`defineAgent`)",commitOrderedTables:"commit-ordered tables (`.commitOrdered()`)",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()`)",queues:"queues (`defineQueue`)",relationGraph:"relation-graph traversal (`ctx.db.related`, derived from `v.id(...)` columns)",secrets:"the secrets store (`ctx.secrets`)",vectorStore:"vector indexes (`.vectorize()`)"},S=(t,e,a)=>({level:"error",message:`${e.name} does not support ${g[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:a}),T=(t,e,a)=>({level:"error",message:`${e.name}'s capability matrix does not declare a support level for ${g[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:a}),_=t=>{const{diagnostics:e,gatedSignals:a,matrix:o,reported:i,signals:d,target:n}=t;for(const s of y){if(d[s]!==!0)continue;const r=o.features[s]?.level;r!=="unsupported"&&r!==void 0||(a[s]=!1,!i.has(s)&&e.push(r==="unsupported"?S(s,o,n):T(s,o,n)))}},$=(t,e,a,o={})=>{const i={...t},d={...o},n=[],s=new Set;for(const[r,l]of Object.entries(b)){if(l===null||!t[r])continue;const p=e.features[l]?.level;p==="unsupported"?(i[r]=!1,s.add(l),n.push({feature:r,level:"error",message:`${e.name} does not support "${r}" (ctx.${r}).`,name:"platform_unsupported_feature",remediation:`Remove the ctx.${r} usage, or deploy to a target whose capability matrix marks "${l}" as native or emulated.`,target:a})):p===void 0&&(i[r]=!1,s.add(l),n.push({feature:r,level:"error",message:`${e.name}'s capability matrix does not declare a support level for "${r}" (ctx.${r}). Treated as unsupported.`,name:"platform_undeclared_feature",remediation:`Rate "${l}" 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:a}))}return _({diagnostics:n,gatedSignals:d,matrix:e,reported:s,signals:o,target:a}),{diagnostics:n,signals:d,usage:i}},O=(t,e,a={})=>{const o=u[e];return o===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}],signals:{...a},usage:{...t}}:$(t,o,e,a)};export{b as CAPABILITY_TO_FEATURE,c as DEFAULT_TARGET,$ as gateAgainstMatrix,O as gatePlatformFeatures,I as platformMatrixIds,v as readProjectTarget,L as readTargetDiagnostics,x as resolveCodegenTarget};
@@ -1 +0,0 @@
1
- import{existsSync as m,statSync as p,readFileSync as v}from"node:fs";import{resolve as E,basename as b}from"node:path";import{createJiti as x}from"jiti";import{Project as S,Node as r}from"ts-morph";import{propertyKeyName as u}from"./listLunoraSourceFiles-vjwjgpjd.mjs";const h=["lunora.config.ts","lunora.config.mts","lunora.config.js","lunora.config.mjs"],f=t=>h.map(i=>E(t,i)).find(i=>m(i)),g=new Map,D=async t=>{const i=f(t);if(i===void 0)return{};let e;try{const n=p(i);e=`${String(n.mtimeMs)}:${String(n.size)}`}catch{return{}}const s=g.get(i);if(s?.key===e)return s.value;const l=(async()=>{try{const o=(await x(i,{interopDefault:!1,moduleCache:!1}).import(i))?.default;return{config:o!==null&&typeof o=="object"?o:void 0}}catch(n){return{error:n instanceof Error?n.message:String(n)}}})();return g.set(i,{key:e,value:l}),l},P=t=>{let e=t.getExportAssignments().find(s=>!s.isExportEquals())?.getExpression();for(;e!==void 0&&(r.isSatisfiesExpression(e)||r.isAsExpression(e)||r.isParenthesizedExpression(e));)e=e.getExpression();if(e!==void 0&&r.isIdentifier(e))for(e=t.getVariableDeclaration(e.getText())?.getInitializer();e!==void 0&&(r.isSatisfiesExpression(e)||r.isAsExpression(e));)e=e.getExpression();return e!==void 0&&r.isObjectLiteralExpression(e)?e:void 0},c=(t,i)=>r.isPropertyAssignment(t)?t.getInitializer():i.getVariableDeclaration(u(t))?.getInitializer(),y=(t,i)=>{let e=t;for(;e!==void 0&&(r.isSatisfiesExpression(e)||r.isAsExpression(e)||r.isParenthesizedExpression(e));)e=e.getExpression();if(e===void 0||!r.isObjectLiteralExpression(e))return{advisor:{unreadable:!0}};const s=e.getProperties(),l=s.filter(a=>r.isPropertyAssignment(a)&&!r.isComputedPropertyName(a.getNameNode())||r.isShorthandPropertyAssignment(a));if(l.length!==s.length)return{advisor:{unreadable:!0}};const n=l.find(a=>u(a)==="minSeverity");if(n===void 0)return{advisor:{}};const o=c(n,i);return o!==void 0&&r.isStringLiteral(o)?{advisor:{minSeverity:o.getLiteralValue()}}:{advisor:{unreadable:!0}}},A=new Map([["advisor",{advisor:{unreadable:!0}}],["remote",{unreadable:!0}],["target",{unreadable:!0}]]),L=(t,i)=>{if(r.isGetAccessorDeclaration(t)||r.isMethodDeclaration(t))return A.get(u(t))??{};if(!r.isPropertyAssignment(t)&&!r.isShorthandPropertyAssignment(t))return{};const e=u(t);if(e==="advisor")return y(c(t,i),i);if(e!=="target"&&e!=="remote")return{};const s=c(t,i);return s===void 0?{unreadable:!0}:e==="target"?r.isStringLiteral(s)?{target:s.getLiteralValue()}:{unreadable:!0}:r.isTrueLiteral(s)||r.isFalseLiteral(s)?{remote:s.getLiteralValue()}:r.isObjectLiteralExpression(s)?{remote:!0}:{unreadable:!0}},F=t=>{const i=f(t);if(i===void 0)return{};let e;try{e=v(i,"utf8")}catch{return{unreadable:!0}}const l=new S({compilerOptions:{allowJs:!0},skipFileDependencyResolution:!0,skipLoadingLibFiles:!0,useInMemoryFileSystem:!0}).createSourceFile(b(i),e,{overwrite:!0}),n=P(l);if(n===void 0)return{unreadable:!0};if(n.getProperties().some(a=>r.isSpreadAssignment(a)))return n.getProperties().some(d=>!r.isSpreadAssignment(d)&&u(d)==="advisor")?{advisor:{unreadable:!0},unreadable:!0}:{unreadable:!0};let o={};for(const a of n.getProperties())o={...o,...L(a,l)};return o};export{h as PROJECT_CONFIG_FILENAMES,f as findProjectConfigFile,D as loadProjectConfig,F as readProjectConfigLiterals};