@lunora/codegen 1.0.0-alpha.218 → 1.0.0-alpha.219

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.mjs +1 -1
  2. package/dist/packem_shared/AGENTS_FILENAME-CXktfidB.mjs +1 -0
  3. package/dist/packem_shared/CONTAINERS_FILENAME-CtYUTuyn.mjs +1 -0
  4. package/dist/packem_shared/{DEFAULT_TARGET-lXUZWR6a.mjs → DEFAULT_TARGET-CwlCMxUf.mjs} +1 -1
  5. package/dist/packem_shared/FLAGS_FILENAME-qQuylR_O.mjs +1 -0
  6. package/dist/packem_shared/{GENERATED_HEADER-CHaKsSSS.mjs → GENERATED_HEADER-Dxg5tOEa.mjs} +1 -1
  7. package/dist/packem_shared/MUTATORS_FILENAME-DCsa5Ma-.mjs +1 -0
  8. package/dist/packem_shared/NOTIFY_FILENAME-D67sEwVX.mjs +1 -0
  9. package/dist/packem_shared/{OPENRPC_VERSION-CJU-lqTu.mjs → OPENRPC_VERSION-DAxS0CaZ.mjs} +1 -1
  10. package/dist/packem_shared/PROJECT_CONFIG_FILENAMES-DfD2MHzr.mjs +1 -0
  11. package/dist/packem_shared/QUEUES_FILENAME-BdgYKMU9.mjs +1 -0
  12. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DPe7MX0x.mjs +9 -0
  13. package/dist/packem_shared/SHAPES_FILENAME-DTGoT04E.mjs +1 -0
  14. package/dist/packem_shared/WORKFLOWS_FILENAME-B6GW6JVZ.mjs +1 -0
  15. package/dist/packem_shared/{buildOpenApiDocument-DGps0I-b.mjs → buildOpenApiDocument-D1dd4rBh.mjs} +1 -1
  16. package/dist/packem_shared/chain-CjJF9d9k.mjs +1 -0
  17. package/dist/packem_shared/{classify-procedure-call-RjsZg8AH.mjs → classify-procedure-call-CZU6n3yF.mjs} +1 -1
  18. package/dist/packem_shared/{context-property-calls-DV-Pt4KS.mjs → context-property-calls-ClziPULs.mjs} +1 -1
  19. package/dist/packem_shared/discoverAuthApiCalls-GNVuIrUo.mjs +1 -0
  20. package/dist/packem_shared/discoverCrons-CV2EZ_vn.mjs +1 -0
  21. package/dist/packem_shared/discoverFunctions-Bk10Q2Zl.mjs +1 -0
  22. package/dist/packem_shared/{discoverHttpRoutes-HeBP7vhK.mjs → discoverHttpRoutes-DJ-y2q50.mjs} +1 -1
  23. package/dist/packem_shared/discoverHyperdriveCalls-C5he04zb.mjs +1 -0
  24. package/dist/packem_shared/{discoverInserts-BP0Gl37o.mjs → discoverInserts-gOn4B3o0.mjs} +1 -1
  25. package/dist/packem_shared/discoverMaskProcedures-GgXYEuuB.mjs +1 -0
  26. package/dist/packem_shared/discoverMigrations-DTv9qRcf.mjs +1 -0
  27. package/dist/packem_shared/{discoverNondeterministicCalls-CJYIXWPw.mjs → discoverNondeterministicCalls-CWAlKa4g.mjs} +1 -1
  28. package/dist/packem_shared/discoverQueries-CjxhCGm8.mjs +1 -0
  29. package/dist/packem_shared/discoverR2sqlCalls-BkoDbcXj.mjs +1 -0
  30. package/dist/packem_shared/discoverRlsMetadata-Cc-eoo9M.mjs +1 -0
  31. package/dist/packem_shared/discoverRlsProcedures-CsbCosUT.mjs +1 -0
  32. package/dist/packem_shared/{discoverSandboxUsage-pJ42YuvL.mjs → discoverSandboxUsage-5WJ5s2sM.mjs} +1 -1
  33. package/dist/packem_shared/discoverSchema-DvQyqT4W.mjs +1 -0
  34. package/dist/packem_shared/{discoverStorageRulesMetadata-BFiKUo5m.mjs → discoverStorageRulesMetadata-Bj6gg_lr.mjs} +1 -1
  35. package/dist/packem_shared/{emit-CBX_NHUL.mjs → emit-6YJU3YbV.mjs} +124 -124
  36. package/dist/packem_shared/{emitApp-Dd-mGXqR.mjs → emitApp-BewH-Jfe.mjs} +1 -1
  37. package/dist/packem_shared/{exported-procedure-chains-CjlBrFjo.mjs → exported-procedure-chains-DhKcj-hK.mjs} +1 -1
  38. package/dist/packem_shared/index-BGHtJQPU.mjs +1 -0
  39. package/dist/packem_shared/listLunoraSourceFiles-vjwjgpjd.mjs +1 -0
  40. package/dist/packem_shared/parse-validator-2u-Io0i5.mjs +1 -0
  41. package/dist/packem_shared/queries-C8MF4jMB.mjs +1 -0
  42. package/dist/packem_shared/{unwrap-handler-return-BEdusskg.mjs → unwrap-handler-return-C1OS0xP8.mjs} +1 -1
  43. package/package.json +5 -5
  44. package/dist/packem_shared/AGENTS_FILENAME-DPIMTD_h.mjs +0 -1
  45. package/dist/packem_shared/CONTAINERS_FILENAME-wDZs0S4p.mjs +0 -1
  46. package/dist/packem_shared/FLAGS_FILENAME-CQofXgIf.mjs +0 -1
  47. package/dist/packem_shared/MUTATORS_FILENAME-CE7K7DfT.mjs +0 -1
  48. package/dist/packem_shared/NOTIFY_FILENAME-DbuOgja2.mjs +0 -1
  49. package/dist/packem_shared/PROJECT_CONFIG_FILENAMES-BkkKjazl.mjs +0 -1
  50. package/dist/packem_shared/QUEUES_FILENAME-Dd781zOQ.mjs +0 -1
  51. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BByCXJyw.mjs +0 -9
  52. package/dist/packem_shared/SHAPES_FILENAME-BtuI2r7-.mjs +0 -1
  53. package/dist/packem_shared/WORKFLOWS_FILENAME-v3AJcUjy.mjs +0 -1
  54. package/dist/packem_shared/chain-u-8_P10m.mjs +0 -1
  55. package/dist/packem_shared/discoverAuthApiCalls-EHm1O8uG.mjs +0 -1
  56. package/dist/packem_shared/discoverCrons-B2GXsB-m.mjs +0 -1
  57. package/dist/packem_shared/discoverFunctions-7IsdPbJJ.mjs +0 -1
  58. package/dist/packem_shared/discoverHyperdriveCalls-CzRlqv_N.mjs +0 -1
  59. package/dist/packem_shared/discoverMaskProcedures-Cl2I3ycl.mjs +0 -1
  60. package/dist/packem_shared/discoverMigrations-BX86Fv9G.mjs +0 -1
  61. package/dist/packem_shared/discoverQueries-COGaQPE5.mjs +0 -1
  62. package/dist/packem_shared/discoverR2sqlCalls-emIgm3TF.mjs +0 -1
  63. package/dist/packem_shared/discoverRlsMetadata-3Gs8U3ng.mjs +0 -1
  64. package/dist/packem_shared/discoverRlsProcedures-CU7YMR3P.mjs +0 -1
  65. package/dist/packem_shared/discoverSchema-ClYGs0dx.mjs +0 -1
  66. package/dist/packem_shared/index-D6xfnMEE.mjs +0 -1
  67. package/dist/packem_shared/listLunoraSourceFiles-DsxeRYvh.mjs +0 -1
  68. package/dist/packem_shared/parse-validator-DW5RNi_6.mjs +0 -1
  69. package/dist/packem_shared/queries-TZaLWhWq.mjs +0 -1
@@ -1 +0,0 @@
1
- import{d as P}from"./declared-output-Iaar469J.mjs";import{s as E}from"./paths-C-9fwEgQ.mjs";import{listLunoraSourceFiles as b,lunoraRelativePath as A}from"./listLunoraSourceFiles-DsxeRYvh.mjs";import{u as v,p as N,c as g,r as F}from"./unwrap-handler-return-BEdusskg.mjs";import{b as f,c as z}from"./classify-procedure-call-RjsZg8AH.mjs";import{Node as n,SyntaxKind as C}from"ts-morph";import{r as y,p as h,a as O}from"./parse-validator-DW5RNi_6.mjs";const S=i=>{const t=i.getArguments()[0];if(!t||!n.isObjectLiteralExpression(t))return"unknown";const e=t.getProperty("handler");if(!e||!n.isPropertyAssignment(e))return"unknown";const r=e.getInitializer();return!r||!(n.isArrowFunction(r)||n.isFunctionExpression(r))?"unknown":v(r)},L=i=>{const t=i.getArguments()[0];return!t||!(n.isArrowFunction(t)||n.isFunctionExpression(t))?"unknown":v(t)},k=i=>{let t={};for(const e of f(i)){if(e.name!=="input")continue;const r=e.call.getArguments()[0],s=r!==void 0&&n.isExpression(r)?y(r):void 0;s!==void 0&&(t={...h(s),...t})}return t},I=i=>{const t=f(i).find(r=>r.name==="output");if(!t)return;const e=t.call.getArguments()[0];return e&&n.isExpression(e)?N(t.call,()=>O(e)):void 0},u=(i,t)=>{const e=i.getProperty(t);if(e===void 0||!n.isPropertyAssignment(e))return;const r=e.getInitializer();return r!==void 0&&n.isStringLiteral(r)?r.getLiteralValue():void 0},m=(i,t)=>{const e=i.getProperty(t);if(e===void 0||!n.isPropertyAssignment(e))return;const r=e.getInitializer();return r!==void 0&&n.isNumericLiteral(r)?r.getLiteralValue():void 0},T=i=>{const t=i.getProperty("cache");if(t===void 0||!n.isPropertyAssignment(t))return;const e=t.getInitializer();if(e===void 0||!n.isObjectLiteralExpression(e))return;const r=u(e,"scope"),s=m(e,"maxAge"),o=m(e,"staleWhileRevalidate"),a=u(e,"tag"),c=u(e,"vary"),d={...s===void 0?{}:{maxAge:s},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(d).length===0?void 0:d},V=i=>{if(i===void 0||!n.isObjectLiteralExpression(i))return{};const t=T(i),e=i.getProperty("rest");return e!==void 0&&n.isPropertyAssignment(e)?{...t===void 0?{}:{cache:t},rest:e.getInitializer()?.getText()==="true"}:t===void 0?{}:{cache:t}},w=i=>{const t=f(i).find(e=>e.name==="expose");return t?V(t.call.getArguments()[0]):void 0},D=i=>{const t=i.getArguments()[0];if(!t||!n.isObjectLiteralExpression(t))return{};const e=t.getProperty("args");if(!e||!n.isPropertyAssignment(e))return{};const r=e.getInitializer(),s=r===void 0?void 0:y(r);return s===void 0?{}:h(s)},j=8,l=(i,t=0)=>{if(t>j)return;if(n.isCallExpression(i))return i;if(n.isParenthesizedExpression(i)||n.isAsExpression(i)||n.isSatisfiesExpression(i)||n.isNonNullExpression(i))return l(i.getExpression(),t+1);if(!n.isIdentifier(i)&&!n.isPropertyAccessExpression(i))return;const e=i.getSymbol()?.getValueDeclaration();return e?p(e,t+1):void 0},p=(i,t)=>{if(n.isVariableDeclaration(i)||n.isPropertyAssignment(i)){const e=i.getInitializer();return e?l(e,t):void 0}if(n.isShorthandPropertyAssignment(i)){const e=i.getValueSymbol()?.getValueDeclaration();return e?p(e,t+1):void 0}if(n.isBindingElement(i)){const e=i.getPropertyNameNode()?.getText()??i.getName(),o=i.getFirstAncestorByKind(C.VariableDeclaration)?.getInitializer()?.getType().getProperty(e)?.getValueDeclaration();return o?p(o,t+1):void 0}},R=i=>{const t=i.getNameNode();if(n.isObjectBindingPattern(t)){const s=[];for(const o of t.getElements()){const a=l(o.getNameNode());a&&s.push([o.getName(),a])}return s}const e=i.getInitializer(),r=e&&(n.isCallExpression(e)?e:l(e));return r?[[i.getName(),r]]:[]},B=i=>{const t=z(i);if(!t)return;const{receiver:e}=t;if(e){const r=w(e),s=g(()=>I(e)),o=g(()=>L(i)),a=P({kind:t.kind,output:s.value});return F(a?s.erased:o.erased),{args:k(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:D(i),kind:t.kind,returnType:S(i),visibility:t.visibility}},x=(i,t,e)=>{const r=B(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=l(r.getExpression()),o=s?x(s,"default",t):void 0;o&&e.push(o)}return e},W=(i,t)=>{const e=[];for(const r of i.getVariableStatements())if(r.isExported())for(const s of r.getDeclarations())for(const[o,a]of R(s)){const c=x(a,o,t);c&&e.push(c)}return e.push(...$(i,t)),e},_=i=>{const t=new Map;for(const e of i){const r=E(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)}},Q=(i,t)=>{const e=b(t),r=[];for(const s of e){const o=i.getSourceFile(s)??i.addSourceFileAtPath(s),a=A(t,s);r.push(...W(o,a))}return r.sort((s,o)=>`${s.filePath}:${s.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),_(r),r};export{Q as default};
@@ -1 +0,0 @@
1
- import{d as o}from"./context-property-calls-DV-Pt4KS.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
@@ -1 +0,0 @@
1
- import"./listLunoraSourceFiles-DsxeRYvh.mjs";import"./classify-procedure-call-RjsZg8AH.mjs";import{d as p}from"./index-D6xfnMEE.mjs";export{p as default};
@@ -1 +0,0 @@
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-DsxeRYvh.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};
@@ -1 +0,0 @@
1
- import{d as a}from"./queries-TZaLWhWq.mjs";import"./listLunoraSourceFiles-DsxeRYvh.mjs";export{a as default};
@@ -1 +0,0 @@
1
- import{d as r}from"./context-property-calls-DV-Pt4KS.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
@@ -1 +0,0 @@
1
- import{Node as o}from"ts-morph";import{listLunoraSourceFiles as d,lunoraRelativePath as x,stringPropertyOf as c}from"./listLunoraSourceFiles-DsxeRYvh.mjs";import{e as h}from"./exported-procedure-chains-CjlBrFjo.mjs";import{r as A}from"./chain-u-8_P10m.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};
@@ -1 +0,0 @@
1
- import{Node as o}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as u,tablesAccessedIn as d}from"./listLunoraSourceFiles-DsxeRYvh.mjs";import{c as p}from"./classify-procedure-call-RjsZg8AH.mjs";import{r as m}from"./chain-u-8_P10m.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};
@@ -1 +0,0 @@
1
- import{LunoraError as D}from"@lunora/errors";import{Node as i,SyntaxKind as z}from"ts-morph";import{diagnosticAt as f}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{createRequire as M}from"node:module";import{join as R}from"node:path";import{r as C,p as F}from"./parse-validator-DW5RNi_6.mjs";const B=(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.`,V=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}},q=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}:{}}),g=e=>{const n=e?._meta??{},t=e?.kind??"unknown",s={column:q(n.column),kind:t};switch(t){case"array":case"optional":{s.inner=g(n.inner);break}case"from":break;case"id":{s.tableName=n.tableName;break}case"literal":{s.literalValue=V(n.value);break}case"object":{const r=n.shape??{};s.shape=Object.fromEntries(Object.entries(r).map(([o,a])=>[o,g(a)]));break}case"record":{s.valueType=g(n.valueValidator),n.keyValidator!==void 0&&(s.keyType=g(n.keyValidator));break}case"storage":{typeof n.bucket=="string"&&(s.bucket=n.bucket);break}case"union":{const r=n.members??[];s.members=r.map(o=>g(o));break}}return s},J=e=>e?.kind==="global"?"global":e?.kind==="shardBy"&&typeof e.field=="string"?{field:e.field,kind:"shardBy"}:"root",U=(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.`)},K=(e,n)=>{const t=e.shape??{},s=(e.indexes??[]).map(r=>({fields:r.fields,name:r.name,...r.unique?{unique:!0}:{}}));return U(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,o])=>[r,g(o)])),shardMode:J(e.shardMode),vectorIndexes:[]}},Z=e=>{const{key:n,tables:t}=e;if(typeof n!="string"||typeof t!="object"||t===null)return;const s=Object.entries(t).map(([a,l])=>K(l,a)),r=e.vectorIndexes??{},o=Object.entries(r??{}).map(([a,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:a,table:l.table??""}));return{bareTables:s,bareVectorIndexes:o,key:n}},W=e=>{if(i.isIdentifier(e))return e.getText();if(i.isPropertyAccessExpression(e)){const n=e.getExpression();return i.isIdentifier(n)?n.getText():void 0}},G=e=>{const n=W(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 o=r.getModuleSpecifierValue();for(const a of r.getNamedImports())if((a.getAliasNode()?.getText()??a.getName())===n)return{importedName:a.getName(),moduleSpecifier:o,propertyPath:s};if(r.getDefaultImport()?.getText()===n)return{importedName:"default",moduleSpecifier:o,propertyPath:s};if(r.getNamespaceImport()?.getText()===n&&t!==void 0)return{importedName:t,moduleSpecifier:o,propertyPath:[]}}},H=(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},Q=(e,n)=>{const t=G(e);if(t)try{const s=M(R(n,"noop.cjs")),r=s.resolve(t.moduleSpecifier),o=s(r),a=H(o,t);return typeof a!="object"||a===null?void 0:Z(a)}catch{return}},X=new Set(["cosine","dot-product","euclidean"]),T=e=>e.replaceAll(/^["']|["']$/gu,""),m=(e,n)=>{const t=e.getProperty(n);if(t&&i.isPropertyAssignment(t))return t.getInitializer()},d=(e,n)=>{const t=m(e,n);if(t&&i.isStringLiteral(t))return t.getLiteralText()},x=(e,n)=>{const t=m(e,n);if(t&&i.isNumericLiteral(t))return Number(t.getLiteralText())},Y=(e,n)=>{const t=m(e,n);if(t&&(i.isTrueLiteral(t)||i.isFalseLiteral(t)))return t.getLiteralValue()},b=(e,n)=>{const t=m(e,n);if(t&&i.isArrayLiteralExpression(t))return t.getElements().filter(s=>i.isStringLiteral(s)).map(s=>s.getLiteralText())},L=e=>e&&X.has(e)?e:void 0,h=e=>e&&i.isStringLiteral(e)?e.getLiteralText():"_unnamed_",ee=(e,n)=>{const t=b(e,n);return t!==void 0&&t.length>0?t:void 0},O=(e,n,t,s,r)=>{let o=e;for(;;){const a=o.getParent();if(!a||!i.isPropertyAccessExpression(a))break;const l=a.getParent();if(!l||!i.isCallExpression(l))break;if(a.getName()===n){const c=l.getArguments()[0];if(!c||!i.isStringLiteral(c))throw f(l,`\`.${n}(...)\` expects a string literal (${r})`);const p=c.getLiteralText();if(!s.has(p))throw f(c,`unknown ${t} ${JSON.stringify(p)} — expected ${r}`);return p}o=l}},te=new Set(["cascade","restrict","set null"]),ne=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"]),re=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,E=(e,n)=>{const t=T(e);if(ne.has(t))throw f(n,`table name "${t}" 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.${t}\` and every use of it would break. Rename the table.`);if(re.has(t))throw f(n,`table name "${t}" is a reserved JavaScript word — codegen interpolates table names into a bare \`const ${t} = sqliteTable(...)\` binding in the generated Drizzle module, which is a syntax error for a keyword. Rename the table.`);if(!P.test(t))throw f(n,`table name ${JSON.stringify(t)} 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.`)},se=e=>e&&te.has(e)?e:void 0,ie=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},oe=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,o]=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 a=r.getLiteralText();let l="_unknown_",c="_id",p;return o&&i.isObjectLiteralExpression(o)&&(l=d(o,"field")??l,c=d(o,"references")??c,p=s==="one"?se(d(o,"onDelete")):void 0),{field:l,kind:s,name:e.getName(),onDelete:p,references:c,table:a}},ae=e=>{const n=ie(e);if(!n)return[];const t=[];for(const s of n.getProperties()){const r=oe(s);r&&t.push(r)}return t},le=(e,n,t)=>{if(!n.includes("."))return;const[s="",...r]=n.split("."),o=`${s}${r.map(a=>a.charAt(0).toUpperCase()+a.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. \`${o}\`), index that instead, and keep it in sync with a table \`.triggers()\` beforeInsert/beforeUpdate.`)},ce=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const n=e.getProperty("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)},de=e=>{const[n,t,s]=e,r=ce(s),o=h(n),a=t&&i.isArrayLiteralExpression(t)?t.getElements():[];for(const c of a)if(!i.isStringLiteral(c))throw f(c,`index "${o}" lists a non-literal field (${JSON.stringify(c.getText())}); codegen reads index fields statically, so every entry must be a string literal.`);const l=a.filter(c=>i.isStringLiteral(c));for(const c of l)le(c,c.getLiteralText(),o);return{fields:l.map(c=>c.getLiteralText()),name:o,unique:r}},fe=e=>{const[n,t]=e;let s="_unknown_",r,o,a,l;return t&&i.isObjectLiteralExpression(t)&&(s=d(t,"field")??s,r=b(t,"filterFields"),o=d(t,"language"),a=Y(t,"staged"),l=d(t,"strategy")),{field:s,filterFields:r,language:o,name:h(n),staged:a,strategy:l}},ue=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:h(n),precision:r}},pe=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}},ge=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}},me=e=>{const[n,t]=e;let s=[],r;if(t&&i.isObjectLiteralExpression(t)){const o=t.getProperty("sortBy");if(o&&i.isPropertyAssignment(o)){const a=o.getInitializer();a&&i.isArrayLiteralExpression(a)&&(s=a.getElements().map(l=>ge(l)).filter(l=>l!==void 0))}r=b(t,"partitionBy")}return{name:h(n),partitionBy:r,sortBy:s}},xe=(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:b(s,"metadata"),metric:L(d(s,"metric")),name:d(s,"index")??"_unnamed_",table:n}},be=e=>{const n=e[0];return n&&i.isObjectLiteralExpression(n)&&d(n,"backend")==="hyperdrive"?"hyperdrive":"d1"},he=e=>{if(e&&i.isObjectLiteralExpression(e)){const n=e.getProperty("field");if(n&&i.isPropertyAssignment(n)){const t=n.getInitializer();if(t&&i.isStringLiteral(t))return t.getLiteralText()}}return"deletedAt"},ye=e=>{const n=e[0];return!n||!i.isObjectLiteralExpression(n)?{binding:"",hasTenantBy:!1,unanalyzable:!0}:{binding:d(n,"binding")??"",columns:ee(n,"columns"),hasReconcile:n.getProperty("reconcileEveryMs")!==void 0,hasSoftDelete:n.getProperty("softDeleteColumn")!==void 0,hasTenantBy:n.getProperty("tenantBy")!==void 0,idColumn:d(n,"idColumn"),mode:d(n,"mode"),query:d(n,"query")}},ve=(e,n,t,s)=>{switch(n){case"commitOrdered":{e.commitOrdered=!0;break}case"externallyManaged":{e.externallyManaged=!0;break}case"geoIndex":{e.geoIndexes.push(ue(t));break}case"global":{e.shardMode="global",e.globalBackend=be(t);break}case"index":{e.indexes.push(de(t));break}case"memory":{e.memory=!0;break}case"public":{e.isPublic=!0;break}case"rankIndex":{e.rankIndexes.push(me(t));break}case"relations":{const r=t[0];r&&e.relations.push(...ae(r));break}case"searchIndex":{e.searchIndexes.push(fe(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:he(t[0])};break}case"source":{e.externalSource=ye(t),e.externallyManaged=!0;break}case"ttl":{e.ttl=pe(t);break}case"vectorize":{const r=xe(t,s);r&&e.vectorIndexes.push(r);break}}},w=["__vocab","_config","_content","_data","_docsize","_idx"],Ee=(e,n,t)=>{const s=new Set(t.map(r=>r.name));for(const r of t)for(const o of w){const a=`${r.name}${o}`;if(!s.has(a))continue;const l=o==="__vocab"?`the \`fts5vocab\` companion for "${a}" 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 "${a}" 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 "${a}", whose generated FTS5 tables collide: "${r.name}" already owns "${n}__fts_${a}" as its "${o}" companion, so ${l}. Rename one of them so neither ends with another's name plus ${w.join(", ")}.`)}},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 o=r.getExpression(),a=r.getArguments();if(i.isPropertyAccessExpression(o))ve(t,o.getName(),a,n),r=o.getExpression();else if(i.isIdentifier(o)&&o.getText()==="defineTable"){const l=a[0];if(l&&i.isObjectLiteralExpression(l))s=F(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:{kind:"number"},kind:"optional"}}),Ee(e,n,t.searchIndexes),{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}},A=(e,n=[],t=new Set,s=new Set)=>{s.add(e);for(const r of e.getProperties()){if(i.isSpreadAssignment(r)){const a=C(r.getExpression());a!==void 0&&!s.has(a)&&A(a,n,t,s);continue}if(!i.isPropertyAssignment(r))continue;const o=r.getInitializer();if(o){const a=r.getName();E(a,r.getNameNode());const l=T(a);if(t.has(l))throw f(r.getNameNode(),`defineSchema({...}): table "${l}" is declared more than once — the earlier declaration would be silently discarded. Remove the duplicate.`);t.add(l),n.push(N(o,a))}}return n},Ie=e=>{const n=e.getProperty("source");if(n&&i.isPropertyAssignment(n)){const t=n.getInitializer();if(t&&i.isObjectLiteralExpression(t))return d(t,"table")??"_unknown_"}return"_unknown_"},Se=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(),o=i.isStringLiteral(r)?r.getLiteralText():r.getText();return{dimensions:x(s,"dimensions"),metric:L(d(s,"metric")),name:o,table:Ie(s)}},_=e=>{const n=[];for(const t of e.getProperties()){const s=Se(t);s&&n.push(s)}return n},I=(e,n)=>`${e}_${n}`,ke=(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.`)},v=(e,n,t)=>t.has(e)?I(n,e):e,we=(e,n,t)=>{const s=I(n,e.name);return{...e,extensionKey:n,name:s,relations:e.relations.map(r=>({...r,table:v(r.table,n,t)})),vectorIndexes:e.vectorIndexes.map(r=>({...r,table:v(r.table,n,t)}))}},Te=e=>{if(i.isVariableDeclaration(e)||i.isPropertyAssignment(e))return e.getInitializer();if(i.isShorthandPropertyAssignment(e))return e.getNameNode()},Le=e=>{if(!i.isCallExpression(e))return!1;const n=e.getExpression();return i.isIdentifier(n)&&n.getText()==="defineSchemaExtension"},Oe=e=>{if(i.isIdentifier(e))return e;if(i.isPropertyAccessExpression(e)){const n=e.getExpression();return i.isIdentifier(n)?n:void 0}},Pe=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}}},Ne=(e,n)=>{const t=Te(e);if(t){if(i.isPropertyAccessExpression(n)){const s=Pe(t);return s?m(s,n.getName()):void 0}return t}},Ae=e=>{let n=e,t=0;for(;n&&t<32;){if(t+=1,Le(n))return n;const s=Oe(n),r=s&&i.isIdentifier(s)?s.getSymbol():void 0,a=(r?.getAliasedSymbol()?.getDeclarations()??r?.getDeclarations()??[])[0];if(!a)return;const l=a.getSourceFile();if(l.isInNodeModules()||l.isDeclarationFile())return;n=Ne(a,n)}},_e=e=>{const[n,t]=e.getArguments();if(!(!n||!i.isStringLiteral(n))&&!(!t||!i.isObjectLiteralExpression(t)))return{key:n.getLiteralText(),keyNode:n,options:t}},$e=e=>{const n=e.getProperty("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 o=r.getInitializer();if(!o)continue;const a=r.getName();E(a,r.getNameNode()),s.push(N(o,a))}return s},je=e=>{const n=e.getProperty("vectorIndexes");if(!n||!i.isPropertyAssignment(n))return[];const t=n.getInitializer();return!t||!i.isObjectLiteralExpression(t)?[]:_(t)},$=(e,n,t,s)=>{ke(e,s);const r=new Set(n.map(l=>l.name)),o=n.map(l=>we(l,e,r)),a=t.map(l=>({...l,name:I(e,l.name),table:v(l.table,e,r)}));return{tables:o,vectorIndexes:a}},De=(e,n,t)=>$(e,$e(t),je(t),n),ze=(e,n)=>{const t=e.getArguments()[0];if(!t)return;const s=Ae(t);if(!s){if(n!==void 0){const o=Q(t,n);if(o){for(const a of o.bareTables)E(a.name,t);return $(o.key,o.bareTables,o.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=_e(s);if(!r){console.warn("@lunora/codegen: skipping `.extend(...)` — `defineSchemaExtension` requires a string `key` and an options object literal.");return}return De(r.key,r.keyNode,r.options)},Me=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},Re=(e,n,t)=>{const s=new Set(n.map(o=>o.name)),r=[];for(const o of Me(e)){const a=ze(o,t);if(a){for(const l of a.tables){if(s.has(l.name))throw f(o,`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(...a.vectorIndexes)}}return r},Ce=new Set(["eu","fedramp","us"]),Fe=e=>O(e,"jurisdiction","jurisdiction",Ce,'"eu", "us", or "fedramp"'),Be=new Set(["required"]),Ve=e=>O(e,"rls","rls mode",Be,'"required"'),Ge=(e,n,t)=>{const r=e.addSourceFileAtPath(n).getDescendantsOfKind(z.CallExpression).find(u=>{const k=u.getExpression();return i.isIdentifier(k)&&k.getText()==="defineSchema"});if(!r)throw new D("INTERNAL",`defineSchema() not found in ${n}`);const o=r.getArguments()[0];if(!o||!i.isObjectLiteralExpression(o))throw f(r,"defineSchema() expects an object literal");const a=A(o),l=r.getArguments()[1],c=l&&i.isObjectLiteralExpression(l)?_(l):[],p=Re(r,a,t),S=[...a.flatMap(u=>u.vectorIndexes),...c,...p],j=new Set(a.filter(u=>u.shardMode==="global").map(u=>u.name)),y=S.find(u=>j.has(u.table));if(y)throw f(r,B(y.table,y.name));return{jurisdiction:Fe(r),rlsMode:Ve(r),tables:a,vectorIndexes:S}};export{Ge as default};
@@ -1 +0,0 @@
1
- import{Node as r}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as m,tablesAccessedIn as d}from"./listLunoraSourceFiles-DsxeRYvh.mjs";import{w as g,c as p}from"./classify-procedure-call-RjsZg8AH.mjs";const u=e=>{if(!r.isPropertyAssignment(e)&&!r.isShorthandPropertyAssignment(e)&&!r.isMethodDeclaration(e)&&!r.isGetAccessorDeclaration(e))return;const t=e.getNameNode();return r.isStringLiteral(t)?t.getLiteralValue():e.getName()},h=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"},k=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},v=e=>{const t=h(e);return{maskColumns:t.flatMap(s=>k(s)),usesMask:t.length>0}},P=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=p(s);if(!i)return;const n=i.receiver?v(i.receiver):{maskColumns:[],usesMask:!1},{tablesRead:o,tablesWritten:a}=d(e,P,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 f(t)){const n=e.getSourceFile(i)??e.addSourceFileAtPath(i),o=m(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,h as m,x as s};
@@ -1 +0,0 @@
1
- import{readdirSync as E,realpathSync as y,lstatSync as P,statSync as w}from"node:fs";import{dirname as A,join as g,relative as L,sep as O,extname as x}from"node:path";import{Node as n,SyntaxKind as m,VariableDeclarationKind as F}from"ts-morph";import{diagnosticAt as R}from"./CodegenDiagnosticError-BUXlG3P-.mjs";const D=/\.ts$/u,u=(t,e)=>L(t,e).split(O).join("/").replace(D,""),I=new Set(["_generated","node_modules"]),N=(t,e,i)=>t==="schema.ts"&&e===i,T=t=>{try{return w(t)}catch{console.warn(`@lunora/codegen: skipping ${t} — it is a symlink that does not resolve (or vanished mid-scan).`);return}},S=(t,e,i,s)=>{let r,o;try{r=E(t),o=y(t)}catch{return e}if(s.has(o))return e;s.add(o);for(const a of r){const l=g(t,a),c=T(l);c!==void 0&&(c.isDirectory()?I.has(a)||S(l,e,i,s):c.isFile()&&x(a)===".ts"&&!N(a,t,i)&&e.push(l))}return e},b=t=>S(t,[],t,new Set),z=["src/server","src/index.ts","src/worker.ts"],C=new Set([".ts",".tsx"]),h=(t,e=[])=>{let i;try{i=P(t)}catch{return e}if(i.isFile())return C.has(x(t))&&e.push(t),e;if(!i.isDirectory())return e;for(const s of E(t))s==="_generated"||s==="node_modules"||h(g(t,s),e);return e},j=t=>{const e=A(t),i=b(t).map(r=>({displayPath:u(t,r),filePath:r})),s=new Set(i.map(r=>r.filePath));for(const r of z)for(const o of h(g(e,r)))s.has(o)||(s.add(o),i.push({displayPath:u(e,o),filePath:o}));return i},v=(t,e,i)=>{const s=[];for(const{displayPath:r,filePath:o}of e){const a=t.getSourceFile(o)??t.addSourceFileAtPath(o);for(const l of a.getDescendantsOfKind(m.CallExpression)){const c=i(l,r);c!==void 0&&s.push(c)}}return s},M=(t,e,i)=>v(t,b(e).map(s=>({displayPath:u(e,s),filePath:s})),i),X=(t,e,i)=>v(t,j(e),i),Y=t=>{for(const e of t.getAncestors())if(n.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0)return e.getName();return""},H=(t,e)=>{if(e){const o=t.getArguments()[0];return o&&(n.isArrowFunction(o)||n.isFunctionExpression(o))?o:void 0}const i=t.getArguments()[0];if(!i||!n.isObjectLiteralExpression(i))return;const s=i.getProperty("handler");if(!s||!n.isPropertyAssignment(s))return;const r=s.getInitializer();return r&&(n.isArrowFunction(r)||n.isFunctionExpression(r))?r:void 0},U=(t,e)=>{if(!t||!n.isObjectLiteralExpression(t))return;const i=t.getProperty(e);return i&&n.isPropertyAssignment(i)?i.getInitializer():void 0},V=t=>{const e=t.getSymbol()?.getDeclarations().find(r=>n.isVariableDeclaration(r));if(e===void 0||!n.isVariableDeclaration(e))return;const i=e.getParent();if(!n.isVariableDeclarationList(i)||i.getDeclarationKind()!==F.Const)return;const s=i.getParent();return n.isVariableStatement(s)&&n.isSourceFile(s.getParent())?e.getInitializer():void 0},G=t=>{if(!t)return;if(n.isObjectLiteralExpression(t))return t;if(!n.isIdentifier(t))return;const e=V(t);return e!==void 0&&n.isObjectLiteralExpression(e)?e:void 0},f=t=>n.isPropertyAccessExpression(t)&&t.getName()==="db"||n.isIdentifier(t)&&t.getText()==="db",_=new Set(["findFirst","findFirstOrThrow","findMany","findUnique"]),J=t=>{const e=t.getExpression();if(!n.isPropertyAccessExpression(e)||!_.has(e.getName()))return;const i=e.getExpression();if(f(i)){const s=t.getArguments()[0];return{options:t.getArguments()[1],table:s&&n.isStringLiteral(s)?s.getLiteralText():""}}if(n.isPropertyAccessExpression(i)){const s=i.getExpression();if(f(s))return{options:t.getArguments()[0],table:i.getName()}}},p=(t,e)=>{const i=t.getExpression();return!n.isPropertyAccessExpression(i)||!e.has(i.getName())?!1:f(i.getExpression())},d=t=>{const e=t.getArguments()[0];return e&&n.isStringLiteral(e)?e.getLiteralText():""},Q=(t,e,i)=>{const s=new Set,r=new Set;for(const o of t.getDescendantsOfKind(m.CallExpression))if(p(o,e)){const a=d(o);a!==""&&s.add(a)}else if(p(o,i)){const a=d(o);a!==""&&r.add(a)}return{tablesRead:[...s],tablesWritten:[...r]}},K=t=>{let e=t;for(;e&&(n.isAsExpression(e)||n.isSatisfiesExpression(e)||n.isParenthesizedExpression(e)||n.isNonNullExpression(e));)e=e.getExpression();return e},Z=t=>{const e=K(t);return e&&n.isCallExpression(e)?e:void 0},tt=t=>{const e=t.getExportAssignment(r=>!r.isExportEquals());if(!e)return;const i=e.getExpression();if(!n.isIdentifier(i))return i;const s=i.getSymbol()?.getValueDeclaration();return s&&n.isVariableDeclaration(s)?s.getInitializer():i},et=t=>{const e=t.getArguments()[1];return e&&n.isStringLiteral(e)?e.getLiteralValue():""},it=(t,e)=>{if(!n.isObjectLiteralExpression(t))return;const i=t.getProperty(e);if(!i||!n.isPropertyAssignment(i))return;const s=i.getInitializer();return s&&n.isStringLiteral(s)?s.getLiteralText():void 0},k=t=>{const e=t.getStatements(),[i]=e;if(e.length!==1||i===void 0||!n.isReturnStatement(i))return;const s=i.getExpression();return s!==void 0&&n.isObjectLiteralExpression(s)?s:void 0},st=t=>{if(n.isObjectLiteralExpression(t))return t;if(n.isParenthesizedExpression(t)){const e=t.getExpression();return n.isObjectLiteralExpression(e)?e:void 0}return n.isBlock(t)?k(t):void 0},nt=t=>n.isIdentifier(t)&&t.getText()==="ctx",rt=t=>(e,i,s)=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw R(e,`${t} "${i}": \`${s}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)};export{D as TS_EXTENSION_RE,M as collectCallRows,X as collectSecurityCallRows,tt as defaultExportExpression,Y as enclosingExportName,H as handlerOf,nt as isContextIdentifier,f as isDatabaseAccessor,et as limitNameOf,b as listLunoraSourceFiles,j as listSecurityScanFiles,u as lunoraRelativePath,st as objectLiteralFromCallbackBody,G as optionsObjectLiteral,U as propertyInitializer,J as readTargetOf,rt as stringPropertyFor,it as stringPropertyOf,d as tableArgumentOf,Q as tablesAccessedIn,K as unwrapExpression,Z as unwrapToCallExpression};
@@ -1 +0,0 @@
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";let f;const _=e=>{f=e},E=/^[A-Za-z_$][\w$]*$/u,m=new Set(["$defaultFn","$onUpdateFn","$type","default","defaultNow","nullable","serverDefault","unique"]),A=(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}},k=new Set(["any","bigint","boolean","bytes","date","geoPoint","null","number","string","timestamp"]),p=new Set(["check","email","int","length","max","min","pattern","positive","url"]),N=new Set(["meta"]),I=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()},L=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||!L(t))){l.add(e);try{return u(t)}finally{l.delete(e)}}},T="v",w=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()===T},c=e=>{if(n.isIdentifier(e)&&!l.has(e)){const t=S(e);if(t!==void 0&&w(t)){l.add(e);try{return c(t)}finally{l.delete(e)}}}return n.isCallExpression(e)?M(e):{kind:"any",sourceText:e.getText()}},D=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,D(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=r.getName();if(!E.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,R=e=>e===void 0?"undefined":n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)?JSON.stringify(e.getLiteralValue()):e.getText(),V=e=>{const t=e&&f?f(e):void 0;return t===void 0?{kind:"from"}:{kind:"from",tsType:t}},O=(e,t,r)=>{if(k.has(e))return{kind:e};const[i,o]=t;switch(e){case"array":return{inner:d(i,{kind:"any"}),kind:"array"};case"from":return V(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:R(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}`)}},x=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},M=e=>{const t=e.getExpression();if(!n.isPropertyAccessExpression(t))return{kind:"any",sourceText:e.getText()};const r=t.getName(),i=e.getArguments();if(m.has(r)||p.has(r)||N.has(r)||I.has(r)){const o=t.getExpression(),a=n.isExpression(o)?c(o):{kind:"any"};if(m.has(r))return A(a,r);if(!p.has(r))return a;const s=r==="max"&&a.kind==="string"?x(i):void 0;return s!==void 0?{...a,hasRefinement:!0,stringMaxLength:Math.min(a.stringMaxLength??s,s)}:{...a,hasRefinement:!0,unmodelledRefinement:!0}}return O(r,i,e)};export{c as a,b as p,u as r,_ as s};
@@ -1 +0,0 @@
1
- import{Node as s,SyntaxKind as f}from"ts-morph";import{listLunoraSourceFiles as P,lunoraRelativePath as N,isDatabaseAccessor as v}from"./listLunoraSourceFiles-DsxeRYvh.mjs";const A=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}},h=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)?(e.getPropertyNameNode()??e.getNameNode()).getText():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=A(t);return r!==void 0&&h(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"),I=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},O=t=>{if(E(t))return!0;const e=u(t);return e!==void 0&&E(e)},C=t=>{if(s.isCallExpression(t)||s.isNewExpression(t))return!1;const e=u(t);return e===void 0||!(s.isCallExpression(e)||s.isNewExpression(e))},_=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),B=(t,e)=>{if(m(t,e))return!0;const n=u(t);if(n!==void 0&&m(n,e))return!0;const r=I(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>"},b=new Set(["withGeoIndex","withIndex","withSearchIndex"]),y=new Set(["collect","collectWithScores","first","paginate","take","unique"]),S=t=>{const e=t.getExpression();if(!s.isPropertyAccessExpression(e)||e.getName()!=="query")return!1;const n=e.getExpression();return v(n)},F=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},w=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,R=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&&w.test(i.getText()))return!0}e=r}},T=t=>{const e=t.getArguments()[0];return e&&s.isStringLiteral(e)?e.getLiteralText():""},L=(t,e)=>{const n=[];for(const r of P(e)){const i=t.getSourceFile(r)??t.addSourceFileAtPath(r),a=N(e,r);for(const o of i.getDescendantsOfKind(f.CallExpression)){if(!S(o))continue;const c=F(o),l=c.includes("filter");n.push({exportName:D(o),file:a,filtersPrimaryKey:l&&R(o),hasFilter:l,hasIndex:c.some(d=>b.has(d)),line:o.getStartLineNumber(),table:T(o),terminal:c.findLast(d=>y.has(d))})}}return n};export{_ as a,C as b,B as c,L as d,D as e,m as f,O as i,E as r,u as s};