@lunora/codegen 1.0.0-alpha.150 → 1.0.0-alpha.151

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 (69) hide show
  1. package/dist/index.d.mts +9 -1
  2. package/dist/index.d.ts +9 -1
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/AGENTS_FILENAME-CRdh_pOr.mjs +1 -0
  5. package/dist/packem_shared/CONTAINERS_FILENAME-BssQL6eI.mjs +1 -0
  6. package/dist/packem_shared/FLAGS_FILENAME-Bn_wWM4d.mjs +1 -0
  7. package/dist/packem_shared/{GENERATED_HEADER--PCtJMQc.mjs → GENERATED_HEADER-w7DB5GZI.mjs} +1 -1
  8. package/dist/packem_shared/NOTIFY_FILENAME-BH0djo6F.mjs +1 -0
  9. package/dist/packem_shared/{OPENRPC_VERSION-C4UXIUyy.mjs → OPENRPC_VERSION-BAgBIsQM.mjs} +1 -1
  10. package/dist/packem_shared/QUEUES_FILENAME-CIfuMMG3.mjs +1 -0
  11. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-S3Ey8df4.mjs +9 -0
  12. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-CWESEYLi.mjs +2 -0
  13. package/dist/packem_shared/{SchemaSnapshotParseError-yZc-1mxR.mjs → SchemaSnapshotParseError-yrVM8bTa.mjs} +1 -1
  14. package/dist/packem_shared/WORKFLOWS_FILENAME-CSqONfHS.mjs +1 -0
  15. package/dist/packem_shared/{buildOpenApiDocument-D5xOB07T.mjs → buildOpenApiDocument-ZdoDQXmt.mjs} +1 -1
  16. package/dist/packem_shared/chain-DboeOxBl.mjs +1 -0
  17. package/dist/packem_shared/classify-procedure-call-CRm5Etni.mjs +1 -0
  18. package/dist/packem_shared/context-property-calls-CBUh7oAY.mjs +1 -0
  19. package/dist/packem_shared/discoverAuthApiCalls-B5Qmjmyk.mjs +1 -0
  20. package/dist/packem_shared/discoverCrons-c0ig327z.mjs +1 -0
  21. package/dist/packem_shared/discoverFunctions-DeuEs6Ce.mjs +1 -0
  22. package/dist/packem_shared/discoverHttpRoutes-zWSSyyOj.mjs +1 -0
  23. package/dist/packem_shared/discoverHyperdriveCalls-C6kV2CPz.mjs +1 -0
  24. package/dist/packem_shared/discoverInserts-BB7o_8pU.mjs +1 -0
  25. package/dist/packem_shared/discoverMaskProcedures-CNqwOwXv.mjs +1 -0
  26. package/dist/packem_shared/discoverMigrations-CQjGLKW-.mjs +1 -0
  27. package/dist/packem_shared/discoverNondeterministicCalls-B07wjsd2.mjs +1 -0
  28. package/dist/packem_shared/discoverQueries-Dz2vDpE9.mjs +1 -0
  29. package/dist/packem_shared/discoverR2sqlCalls-CuHe5smg.mjs +1 -0
  30. package/dist/packem_shared/discoverRlsMetadata-CXWVNLk4.mjs +1 -0
  31. package/dist/packem_shared/discoverRlsProcedures-DXdr9YHi.mjs +1 -0
  32. package/dist/packem_shared/discoverSandboxUsage-BJHLHZR_.mjs +1 -0
  33. package/dist/packem_shared/discoverStorageRulesMetadata-CUa2Dtb4.mjs +1 -0
  34. package/dist/packem_shared/{emit-CXfWb_pY.mjs → emit-Dsr5DNpc.mjs} +291 -129
  35. package/dist/packem_shared/{emitApp-DcrQNgaz.mjs → emitApp-kFg_xYlc.mjs} +10 -2
  36. package/dist/packem_shared/{exported-procedure-chains-M40rbSYM.mjs → exported-procedure-chains-Cmt3Pr92.mjs} +1 -1
  37. package/dist/packem_shared/index-BsVoa-4F.mjs +1 -0
  38. package/dist/packem_shared/listLunoraSourceFiles-BvqYMy81.mjs +1 -0
  39. package/dist/packem_shared/queries-D8DheHbi.mjs +1 -0
  40. package/package.json +10 -10
  41. package/dist/packem_shared/AGENTS_FILENAME-B1Abt3Gl.mjs +0 -1
  42. package/dist/packem_shared/CONTAINERS_FILENAME-CtcysaKS.mjs +0 -1
  43. package/dist/packem_shared/FLAGS_FILENAME-B3VZ6vTw.mjs +0 -1
  44. package/dist/packem_shared/NOTIFY_FILENAME-CKO5gtGe.mjs +0 -1
  45. package/dist/packem_shared/QUEUES_FILENAME-C-pzLGy4.mjs +0 -1
  46. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DazENDSB.mjs +0 -9
  47. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-B1BUjuG5.mjs +0 -2
  48. package/dist/packem_shared/WORKFLOWS_FILENAME-BfvqsG9Z.mjs +0 -1
  49. package/dist/packem_shared/ast-BYoSZlae.mjs +0 -1
  50. package/dist/packem_shared/chain-Dygm2apY.mjs +0 -1
  51. package/dist/packem_shared/classify-procedure-call-Ib2EMtFH.mjs +0 -1
  52. package/dist/packem_shared/context-property-calls-Br0sVv8E.mjs +0 -1
  53. package/dist/packem_shared/discoverAuthApiCalls-DoNQSgso.mjs +0 -1
  54. package/dist/packem_shared/discoverCrons-DCxl4hty.mjs +0 -1
  55. package/dist/packem_shared/discoverFunctions-CXURzTDU.mjs +0 -1
  56. package/dist/packem_shared/discoverHttpRoutes-2XhMbeh5.mjs +0 -1
  57. package/dist/packem_shared/discoverHyperdriveCalls-DTq4PKT5.mjs +0 -1
  58. package/dist/packem_shared/discoverInserts-qU5F4W4g.mjs +0 -1
  59. package/dist/packem_shared/discoverMaskProcedures-BZsC5dHd.mjs +0 -1
  60. package/dist/packem_shared/discoverMigrations-BFkJQ8Sy.mjs +0 -1
  61. package/dist/packem_shared/discoverNondeterministicCalls-B-NNzzPW.mjs +0 -1
  62. package/dist/packem_shared/discoverQueries-B4emAFn5.mjs +0 -1
  63. package/dist/packem_shared/discoverR2sqlCalls-C2GtrFnl.mjs +0 -1
  64. package/dist/packem_shared/discoverRlsMetadata-BKcUnSNr.mjs +0 -1
  65. package/dist/packem_shared/discoverRlsProcedures-fAhxiIyD.mjs +0 -1
  66. package/dist/packem_shared/discoverSandboxUsage-CJhnKA0_.mjs +0 -1
  67. package/dist/packem_shared/discoverStorageRulesMetadata-C7XmORWp.mjs +0 -1
  68. package/dist/packem_shared/index-xGhyK9J_.mjs +0 -1
  69. package/dist/packem_shared/queries-Ddvo5dCs.mjs +0 -1
@@ -0,0 +1 @@
1
+ import{SyntaxKind as f,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}from"./listLunoraSourceFiles-BvqYMy81.mjs";const I=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=r.getProperty(i);if(!t||!s.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&s.isStringLiteral(e)?e.getLiteralValue():void 0},P=(r,i)=>{const t=r.getInitializer();if(t?.getKind()!==f.CallExpression)return;const e=t.getExpression();if(!s.isIdentifier(e)||!I(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)}},y=(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 g of c.getDeclarations()){const l=P(g,a);l&&e.push(l)}}return e.sort((o,n)=>o.id.localeCompare(n.id)),M(e),e};export{y as default};
@@ -0,0 +1 @@
1
+ import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as l,handlerOf as d}from"./listLunoraSourceFiles-BvqYMy81.mjs";import{c as f}from"./classify-procedure-call-CRm5Etni.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-D8DheHbi.mjs";import"./listLunoraSourceFiles-BvqYMy81.mjs";export{a as default};
@@ -0,0 +1 @@
1
+ import{d as r}from"./context-property-calls-CBUh7oAY.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
@@ -0,0 +1 @@
1
+ import{Node as o}from"ts-morph";import{listLunoraSourceFiles as d,lunoraRelativePath as x,stringPropertyOf as c}from"./listLunoraSourceFiles-BvqYMy81.mjs";import{e as h}from"./exported-procedure-chains-Cmt3Pr92.mjs";import{r as A}from"./chain-DboeOxBl.mjs";const L=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||!L.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=e.getProperty("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},E=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"))}},v=e=>{const t=e.getArguments()[1];if(!t||!o.isObjectLiteralExpression(t))return[];const i=t.getProperty("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=E(n);a&&s.push(a)}return s},y=(e,t,i)=>{const r=A(e);return{policies:r.flatMap(s=>P(s,t,i)),roles:r.flatMap(s=>v(s))}},F=(e,t)=>{const i=[],r=new Map;for(const s of d(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),a=x(t,s);for(const{name:m,receiver:g}of h(n)){const p=y(g,a,m);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{F as default};
@@ -0,0 +1 @@
1
+ import{Node as o}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as u,tablesAccessedIn as d}from"./listLunoraSourceFiles-BvqYMy81.mjs";import{c as p}from"./classify-procedure-call-CRm5Etni.mjs";import{r as m}from"./chain-DboeOxBl.mjs";const b=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=r.getProperty("table");if(!i||!o.isPropertyAssignment(i))continue;const n=i.getInitializer();n&&o.isStringLiteral(n)&&s.push(n.getLiteralText())}return s},g=e=>{const t=m(e);return{rlsTables:t.flatMap(s=>b(s)),usesRls:t.length>0}},h=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),y=new Set(["delete","deleteMany","insert","insertMany","patch","patchMany","replace"]),v=(e,t)=>{if(!o.isVariableDeclaration(e))return;const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const r=p(s);if(!r)return;const i=r.receiver?g(r.receiver):{rlsTables:[],usesRls:!1},{tablesRead:n,tablesWritten:l}=d(e,h,y);return{exportName:e.getName(),file:t,rlsTables:i.rlsTables,tablesRead:n,tablesWritten:l,usesRls:i.usesRls,visibility:r.visibility}},S=(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=v(c,n);a&&s.push(a)}}return s};export{S as default};
@@ -0,0 +1 @@
1
+ import{listLunoraSourceFiles as l}from"./listLunoraSourceFiles-BvqYMy81.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{Node as u}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as p,stringPropertyOf as l}from"./listLunoraSourceFiles-BvqYMy81.mjs";import{w as d}from"./classify-procedure-call-CRm5Etni.mjs";import{e as m}from"./exported-procedure-chains-Cmt3Pr92.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};