@lunora/codegen 1.0.0-alpha.259 → 1.0.0-alpha.260

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 (90) hide show
  1. package/dist/index.mjs +1 -1
  2. package/dist/packem_shared/AGENTS_FILENAME-UhIaG4BZ.mjs +1 -0
  3. package/dist/packem_shared/CONTAINERS_FILENAME-DhUL5rDc.mjs +1 -0
  4. package/dist/packem_shared/{DEFAULT_TARGET-Dy9KAvjZ.mjs → DEFAULT_TARGET-7sHexLjO.mjs} +1 -1
  5. package/dist/packem_shared/{FLAGS_FILENAME-DuEbVfug.mjs → FLAGS_FILENAME-BINQ51Zq.mjs} +1 -1
  6. package/dist/packem_shared/GENERATED_HEADER-dFyrHgQ0.mjs +1 -0
  7. package/dist/packem_shared/MUTATORS_FILENAME-D1Q6EUII.mjs +1 -0
  8. package/dist/packem_shared/NOTIFY_FILENAME-bbHHFQ_t.mjs +1 -0
  9. package/dist/packem_shared/{OPENRPC_VERSION-C8htLv5J.mjs → OPENRPC_VERSION-CGu1_YK7.mjs} +1 -1
  10. package/dist/packem_shared/QUEUES_FILENAME-CSLmXUQA.mjs +1 -0
  11. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BVhRHIbS.mjs +11 -0
  12. package/dist/packem_shared/SHAPES_FILENAME-DuR5hLW1.mjs +1 -0
  13. package/dist/packem_shared/WORKFLOWS_FILENAME-IqUyMQgM.mjs +1 -0
  14. package/dist/packem_shared/attribution-sW_DHmLO.mjs +1 -0
  15. package/dist/packem_shared/{buildOpenApiDocument-BG_b1qiR.mjs → buildOpenApiDocument-DOsv1HEF.mjs} +1 -1
  16. package/dist/packem_shared/{capabilitiesUsedBy-D5TtIE8p.mjs → capabilitiesUsedBy-CzqyN9dX.mjs} +1 -1
  17. package/dist/packem_shared/chain-BTbLDrrU.mjs +1 -0
  18. package/dist/packem_shared/{classify-procedure-call-VzDQHiLB.mjs → classify-procedure-call-OnJoKgqu.mjs} +1 -1
  19. package/dist/packem_shared/context-property-calls-BEBjylgc.mjs +1 -0
  20. package/dist/packem_shared/context-root-KWXRWlv6.mjs +1 -0
  21. package/dist/packem_shared/database-calls-rLPCL3-U.mjs +1 -0
  22. package/dist/packem_shared/{discoverAuthApiCalls-D6s0QBwd.mjs → discoverAuthApiCalls-CNj9-Jch.mjs} +1 -1
  23. package/dist/packem_shared/{discoverCrons-D2jGNq6i.mjs → discoverCrons-BqTY53L5.mjs} +1 -1
  24. package/dist/packem_shared/discoverFunctions-DPH4drkg.mjs +1 -0
  25. package/dist/packem_shared/discoverHttpRoutes-MRFziTCb.mjs +1 -0
  26. package/dist/packem_shared/discoverHyperdriveCalls-BcVkR6nw.mjs +1 -0
  27. package/dist/packem_shared/discoverInserts-Duz40u-s.mjs +1 -0
  28. package/dist/packem_shared/discoverMaskProcedures-DYJhbHF3.mjs +1 -0
  29. package/dist/packem_shared/discoverMigrations-D2P2n7JE.mjs +1 -0
  30. package/dist/packem_shared/discoverNondeterministicCalls-Cxf6T2Oi.mjs +1 -0
  31. package/dist/packem_shared/discoverQueries-CWmNPVHm.mjs +1 -0
  32. package/dist/packem_shared/discoverR2sqlCalls-DnKwop5c.mjs +1 -0
  33. package/dist/packem_shared/{discoverRlsMetadata-CVqVMNnz.mjs → discoverRlsMetadata-BXXEFXjf.mjs} +1 -1
  34. package/dist/packem_shared/discoverRlsProcedures-Des596JU.mjs +1 -0
  35. package/dist/packem_shared/{discoverSandboxUsage-DhE6sfq2.mjs → discoverSandboxUsage-Bjl8A_hj.mjs} +1 -1
  36. package/dist/packem_shared/discoverSchema-Cd3iH6q5.mjs +1 -0
  37. package/dist/packem_shared/{discoverStorageRulesMetadata-BdZT9H9j.mjs → discoverStorageRulesMetadata-DGFonj0I.mjs} +1 -1
  38. package/dist/packem_shared/{emitAgents-BD_IUs4I.mjs → emitAgents-Dotqck8w.mjs} +1 -1
  39. package/dist/packem_shared/{emitApi-DdW9RyGG.mjs → emitApi-xDIHPRPH.mjs} +1 -1
  40. package/dist/packem_shared/{emitApp-0rC4g46B.mjs → emitApp-RNU41dtm.mjs} +1 -1
  41. package/dist/packem_shared/{emitCrons-BRKXFGFu.mjs → emitCrons-DsXsg1uG.mjs} +1 -1
  42. package/dist/packem_shared/{emitDataModel-D3WuEZ4b.mjs → emitDataModel-DSk9AkJe.mjs} +1 -1
  43. package/dist/packem_shared/emitDrizzleSchema-DohtnI8c.mjs +15 -0
  44. package/dist/packem_shared/{emitFunctions-BgNeOZt_.mjs → emitFunctions-evl8Mx1a.mjs} +1 -1
  45. package/dist/packem_shared/{emitServer-mdlKhXYb.mjs → emitServer-DymRagL2.mjs} +1 -1
  46. package/dist/packem_shared/{emitShard-CLFR7-_j.mjs → emitShard-DHMYSP4m.mjs} +1 -1
  47. package/dist/packem_shared/exported-procedure-chains-58yS9zc8.mjs +1 -0
  48. package/dist/packem_shared/{fingerprintSchemaSources-DA9sYQDZ.mjs → fingerprintSchemaSources-BzFVnBfa.mjs} +1 -1
  49. package/dist/packem_shared/{handler-reference-BjE6kvyl.mjs → handler-reference-C1oBljnl.mjs} +1 -1
  50. package/dist/packem_shared/index-BusOvbeQ.mjs +1 -0
  51. package/dist/packem_shared/listLunoraSourceFiles-DRes9d5p.mjs +1 -0
  52. package/dist/packem_shared/{loadProjectConfig-CWtWqN3X.mjs → loadProjectConfig-CuGQsqYS.mjs} +1 -1
  53. package/dist/packem_shared/{modules-Dcalu27_.mjs → modules-CsA-QVJ6.mjs} +1 -1
  54. package/dist/packem_shared/{parse-validator-Cs6F8SYG.mjs → parse-validator-B4mFs19C.mjs} +1 -1
  55. package/dist/packem_shared/{qualifiers-BhOL15WZ.mjs → qualifiers-Cw8dEDbh.mjs} +1 -1
  56. package/dist/packem_shared/{readServiceBindings-V1rcBYrK.mjs → readServiceBindings-CnvEGOir.mjs} +1 -1
  57. package/dist/packem_shared/reserved-words-CW1QFbTd.mjs +1 -0
  58. package/dist/packem_shared/{shard-B2AqdAuz.mjs → shard-WXSIZRpD.mjs} +1 -1
  59. package/dist/packem_shared/{shard-runtime-B8rucwkF.mjs → shard-runtime-B1nU9CRa.mjs} +1 -1
  60. package/dist/packem_shared/shared-BXUKWh7t.mjs +9 -0
  61. package/dist/packem_shared/{unwrap-handler-return-Bnx99voQ.mjs → unwrap-handler-return-D7E2TKkS.mjs} +1 -1
  62. package/package.json +3 -3
  63. package/dist/packem_shared/AGENTS_FILENAME-pKCBP6Us.mjs +0 -1
  64. package/dist/packem_shared/CONTAINERS_FILENAME-C0nEQjXL.mjs +0 -1
  65. package/dist/packem_shared/GENERATED_HEADER-DSXl0YM2.mjs +0 -1
  66. package/dist/packem_shared/MUTATORS_FILENAME-Cm-LVbo0.mjs +0 -1
  67. package/dist/packem_shared/NOTIFY_FILENAME-BRewD55T.mjs +0 -1
  68. package/dist/packem_shared/QUEUES_FILENAME-BUC4MU94.mjs +0 -1
  69. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DOe1K6eL.mjs +0 -11
  70. package/dist/packem_shared/SHAPES_FILENAME-BMT5EVQI.mjs +0 -1
  71. package/dist/packem_shared/WORKFLOWS_FILENAME-BIjSK96U.mjs +0 -1
  72. package/dist/packem_shared/attribution-CTEeAmtS.mjs +0 -1
  73. package/dist/packem_shared/chain-ChloHMQt.mjs +0 -1
  74. package/dist/packem_shared/context-property-calls-CtIWno5c.mjs +0 -1
  75. package/dist/packem_shared/discoverFunctions-AcXUQuyo.mjs +0 -1
  76. package/dist/packem_shared/discoverHttpRoutes-C7qeDpp3.mjs +0 -1
  77. package/dist/packem_shared/discoverHyperdriveCalls-CeyhQdv3.mjs +0 -1
  78. package/dist/packem_shared/discoverInserts-Db4we2Lt.mjs +0 -1
  79. package/dist/packem_shared/discoverMaskProcedures-DKS6xOnB.mjs +0 -1
  80. package/dist/packem_shared/discoverMigrations-CyySAw7Z.mjs +0 -1
  81. package/dist/packem_shared/discoverNondeterministicCalls-Bl_vaQUi.mjs +0 -1
  82. package/dist/packem_shared/discoverQueries-DHtbg9iS.mjs +0 -1
  83. package/dist/packem_shared/discoverR2sqlCalls-BNKRNkrB.mjs +0 -1
  84. package/dist/packem_shared/discoverRlsProcedures-zDOYuzjt.mjs +0 -1
  85. package/dist/packem_shared/discoverSchema-DPghAnQv.mjs +0 -1
  86. package/dist/packem_shared/emitDrizzleSchema-Cv0HtLR3.mjs +0 -15
  87. package/dist/packem_shared/exported-procedure-chains-gbM1pign.mjs +0 -1
  88. package/dist/packem_shared/index-Bq-b_-7H.mjs +0 -1
  89. package/dist/packem_shared/listLunoraSourceFiles-DmOftuU4.mjs +0 -1
  90. package/dist/packem_shared/shared-DjUziztz.mjs +0 -9
@@ -1 +0,0 @@
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-DmOftuU4.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 +0,0 @@
1
- import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as l,handlerOf as d}from"./listLunoraSourceFiles-DmOftuU4.mjs";import{c as f}from"./classify-procedure-call-VzDQHiLB.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 +0,0 @@
1
- import{Node as i}from"ts-morph";import{collectCallRows as c,isDatabaseAccessor as l}from"./listLunoraSourceFiles-DmOftuU4.mjs";import{c as f}from"./attribution-CTEeAmtS.mjs";const u=new Set(["withGeoIndex","withIndex","withSearchIndex"]),p=new Set(["collect","collectWithScores","first","paginate","take","unique"]),g=n=>{const t=n.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="query")return!1;const e=t.getExpression();return l(e)},m=n=>{const t=[];let e=n;for(;;){const r=e.getParent();if(!r||!i.isPropertyAccessExpression(r))break;const s=r.getParent();if(!s||!i.isCallExpression(s))break;t.push(r.getName()),e=s}return t},d=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,E=n=>{let t=n;for(;;){const e=t.getParent();if(!e||!i.isPropertyAccessExpression(e))return!1;const r=e.getParent();if(!r||!i.isCallExpression(r))return!1;if(e.getName()==="filter"){const s=r.getArguments()[0];if(s&&d.test(s.getText()))return!0}t=r}},h=n=>{const t=n.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},S=(n,t)=>c(n,t,(e,r)=>{if(!g(e))return;const s=m(e),a=s.includes("filter");return{file:r,filtersPrimaryKey:a&&E(e),hasFilter:a,hasIndex:s.some(o=>u.has(o)),line:e.getStartLineNumber(),scope:f(e),table:h(e),terminal:s.findLast(o=>p.has(o))}});export{S as default};
@@ -1 +0,0 @@
1
- import{d as r}from"./context-property-calls-CtIWno5c.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 f,lunoraRelativePath as u,tablesAccessedIn as d,findObjectProperty as p}from"./listLunoraSourceFiles-DmOftuU4.mjs";import{c as m}from"./classify-procedure-call-VzDQHiLB.mjs";import{r as b}from"./chain-ChloHMQt.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 +0,0 @@
1
- import{LunoraError as M}from"@lunora/errors";import{Node as i,SyntaxKind as R}from"ts-morph";import{diagnosticAt as d}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{createRequire as F}from"node:module";import{join as C}from"node:path";import{findObjectProperty as u,propertyKeyName as I}from"./listLunoraSourceFiles-DmOftuU4.mjs";import{r as B,p as V}from"./parse-validator-Cs6F8SYG.mjs";const q=(e,t)=>`table "${e}" is .global() and declares vector index "${t}". 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 t=e?._meta??{},n=e?.kind??"unknown",s={column:U(t.column),kind:n};switch(n){case"array":case"optional":{s.inner=m(t.inner);break}case"from":break;case"id":{s.tableName=t.tableName;break}case"literal":{s.literalValue=J(t.value);break}case"object":{const r=t.shape??{};s.shape=Object.fromEntries(Object.entries(r).map(([o,a])=>[o,m(a)]));break}case"record":{s.valueType=m(t.valueValidator),t.keyValidator!==void 0&&(s.keyType=m(t.keyValidator));break}case"storage":{typeof t.bucket=="string"&&(s.bucket=t.bucket);break}case"union":{const r=t.members??[];s.members=r.map(o=>m(o));break}}return s},K=e=>e?.kind==="global"?"global":e?.kind==="shardBy"&&typeof e.field=="string"?{field:e.field,kind:"shardBy"}:"root",Z=(e,t)=>{const n=[];e.relationMap&&Object.keys(e.relationMap).length>0&&n.push("relations"),e.rankIndexes&&e.rankIndexes.length>0&&n.push("rank indexes"),e.vectorIndexes&&e.vectorIndexes.length>0&&n.push("vector indexes"),n.length>0&&console.warn(`@lunora/codegen: package schema-extension table "${t}" declares ${n.join(" + ")}, which are not yet introspected from a node_modules extension — they will be absent from the generated types.`)},G=(e,t)=>{const n=e.shape??{},s=(e.indexes??[]).map(r=>({fields:r.fields,name:r.name,...r.unique?{unique:!0}:{}}));return Z(e,t),{...e.isExternallyManaged?{externallyManaged:!0}:{},geoIndexes:[],indexes:s,name:t,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(n).map(([r,o])=>[r,m(o)])),shardMode:K(e.shardMode),vectorIndexes:[]}},W=e=>{const{key:t,tables:n}=e;if(typeof t!="string"||typeof n!="object"||n===null)return;const s=Object.entries(n).map(([a,l])=>G(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:t}},X=e=>{if(i.isIdentifier(e))return e.getText();if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0}},H=e=>{const t=X(e);if(t===void 0)return;const n=i.isPropertyAccessExpression(e)?e.getName():void 0,s=n===void 0?[]:[n];for(const r of e.getSourceFile().getImportDeclarations()){const o=r.getModuleSpecifierValue();for(const a of r.getNamedImports())if((a.getAliasNode()?.getText()??a.getName())===t)return{importedName:a.getName(),moduleSpecifier:o,propertyPath:s};if(r.getDefaultImport()?.getText()===t)return{importedName:"default",moduleSpecifier:o,propertyPath:s};if(r.getNamespaceImport()?.getText()===t&&n!==void 0)return{importedName:n,moduleSpecifier:o,propertyPath:[]}}},Q=(e,t)=>{let n=e[t.importedName];for(const s of t.propertyPath){if(typeof n!="object"||n===null)return;n=n[s]}return n},Y=(e,t)=>{const n=H(e);if(n)try{const s=F(C(t,"noop.cjs")),r=s.resolve(n.moduleSpecifier),o=s(r),a=Q(o,n);return typeof a!="object"||a===null?void 0:W(a)}catch{return}},ee=new Set(["cosine","dot-product","euclidean"]),b=(e,t)=>{const n=u(e,t);if(n&&i.isPropertyAssignment(n))return n.getInitializer()},f=(e,t)=>{const n=b(e,t);if(n&&i.isStringLiteral(n))return n.getLiteralText()},x=(e,t)=>{const n=b(e,t);if(n&&i.isNumericLiteral(n))return Number(n.getLiteralText())},L=(e,t)=>{const n=b(e,t);if(n&&(i.isTrueLiteral(n)||i.isFalseLiteral(n)))return n.getLiteralValue()},h=(e,t)=>{const n=b(e,t);if(n&&i.isArrayLiteralExpression(n))return n.getElements().filter(s=>i.isStringLiteral(s)).map(s=>s.getLiteralText())},O=e=>e&&ee.has(e)?e:void 0,y=e=>e&&i.isStringLiteral(e)?e.getLiteralText():"_unnamed_",te=(e,t)=>{const n=h(e,t);return n!==void 0&&n.length>0?n:void 0},A=(e,t,n,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()===t){const c=l.getArguments()[0];if(!c||!i.isStringLiteral(c))throw d(l,`\`.${t}(...)\` expects a string literal (${r})`);const g=c.getLiteralText();if(!s.has(g))throw d(c,`unknown ${n} ${JSON.stringify(g)} — expected ${r}`);return g}o=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=/^(?:sqlite_|_cf_|__)/u,se=/__(?:agg|rank|geo|fts)_/u,ie=e=>re.test(e)||se.test(e),oe=new Set(["cascade","restrict","set null"]),ae=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"]),le=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"]),N=/^[A-Za-z_$][\w$]*$/u,w=(e,t)=>{if(ae.has(e))throw d(t,`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(le.has(e))throw d(t,`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(!N.test(e))throw d(t,`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.`);if(ie(e))throw d(t,`table name ${JSON.stringify(e)} is reserved for framework tables — a leading \`__\` and the \`__agg_\`/\`__rank_\`/\`__geo_\`/\`__fts_\` infixes name Lunora's own bookkeeping and index companions, so the Studio and the admin API hide and refuse such a table. Rename the table.`)},ce=e=>e&&oe.has(e)?e:void 0,de=e=>{if(!i.isArrowFunction(e))return;let t=e.getBody();if(i.isParenthesizedExpression(t))t=t.getExpression();else if(i.isBlock(t)){const n=t.getStatements().find(s=>i.isReturnStatement(s));t=n&&i.isReturnStatement(n)?n.getExpression()??t:t}return i.isObjectLiteralExpression(t)?t:void 0},fe=e=>{if(!i.isPropertyAssignment(e))return;const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const n=t.getExpression();if(!i.isPropertyAccessExpression(n))return;const s=n.getName();if(s!=="one"&&s!=="many")return;const[r,o]=t.getArguments();if(!r||!i.isStringLiteral(r))throw d(r??t,`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",g;return o&&i.isObjectLiteralExpression(o)&&(l=f(o,"field")??l,c=f(o,"references")??c,g=s==="one"?ce(f(o,"onDelete")):void 0),{field:l,kind:s,name:I(e),onDelete:g,references:c,table:a}},ue=e=>{const t=de(e);if(!t)return[];const n=[];for(const s of t.getProperties()){const r=fe(s);r&&n.push(r)}return n},pe=(e,t,n)=>{if(!t.includes("."))return;const[s="",...r]=t.split("."),o=`${s}${r.map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join("")}`;throw d(e,`index "${n}" indexes the nested path ${JSON.stringify(t)} — 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.`)},ge=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const t=u(e,"unique");if(!t||!i.isPropertyAssignment(t))return!1;const n=t.getInitializer();if(n===void 0)return!1;if(!i.isTrueLiteral(n)&&!i.isFalseLiteral(n))throw d(n,`\`unique\` must be a literal \`true\` or \`false\`, got ${JSON.stringify(n.getText())}`);return i.isTrueLiteral(n)},me=e=>{const[t,n,s]=e,r=ge(s),o=y(t),a=n&&i.isArrayLiteralExpression(n)?n.getElements():[];for(const c of a)if(!i.isStringLiteral(c))throw d(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)pe(c,c.getLiteralText(),o);return{fields:l.map(c=>c.getLiteralText()),name:o,unique:r}},be=e=>{const[t,n]=e;let s="_unknown_",r,o,a,l;return n&&i.isObjectLiteralExpression(n)&&(s=f(n,"field")??s,r=h(n,"filterFields"),o=f(n,"language"),a=L(n,"staged"),l=f(n,"strategy")),{field:s,filterFields:r,language:o,name:y(t),staged:a,strategy:l}},xe=e=>{const[t,n]=e;let s="_unknown_",r;return n&&i.isObjectLiteralExpression(n)&&(s=f(n,"field")??s,r=x(n,"precision")),{field:s,name:y(t),precision:r}},he=e=>{const[t,n]=e,s=t&&i.isStringLiteral(t)?t.getLiteralText():"_unknown_";let r;return n&&i.isObjectLiteralExpression(n)&&(r=x(n,"after")),{after:r,field:s}},ye=e=>{if(!i.isObjectLiteralExpression(e))return;const t=f(e,"field");return t===void 0?void 0:{direction:f(e,"direction")==="desc"?"desc":"asc",field:t}},ve=e=>{const[t,n]=e;let s=[],r;if(n&&i.isObjectLiteralExpression(n)){const o=u(n,"sortBy");if(o&&i.isPropertyAssignment(o)){const a=o.getInitializer();a&&i.isArrayLiteralExpression(a)&&(s=a.getElements().map(l=>ye(l)).filter(l=>l!==void 0))}r=h(n,"partitionBy")}return{name:y(t),partitionBy:r,sortBy:s}},Ee=(e,t)=>{const[n,s]=e,r=n&&i.isStringLiteral(n)?n.getLiteralText():"_unknown_";if(!(!s||!i.isObjectLiteralExpression(s)))return{dimensions:x(s,"dimensions"),field:r,metadata:h(s,"metadata"),metric:O(f(s,"metric")),name:f(s,"index")??"_unnamed_",table:t}},Ie=e=>{const t=e[0];return t&&i.isObjectLiteralExpression(t)&&f(t,"backend")==="hyperdrive"?"hyperdrive":"d1"},we=e=>{if(e&&i.isObjectLiteralExpression(e)){const t=u(e,"field");if(t&&i.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&i.isStringLiteral(n))return n.getLiteralText()}}return"deletedAt"},Se=e=>{const t=e[0];return!t||!i.isObjectLiteralExpression(t)?{binding:"",hasTenantBy:!1,unanalyzable:!0}:{binding:f(t,"binding")??"",columns:te(t,"columns"),hasReconcile:u(t,"reconcileEveryMs")!==void 0,hasSoftDelete:u(t,"softDeleteColumn")!==void 0,hasTenantBy:u(t,"tenantBy")!==void 0,idColumn:f(t,"idColumn"),mode:f(t,"mode"),query:f(t,"query")}},ke=(e,t,n,s)=>{switch(t){case"commitOrdered":{e.commitOrdered=!0;break}case"externallyManaged":{e.externallyManaged=!0;break}case"geoIndex":{e.geoIndexes.push(xe(n));break}case"global":{e.shardMode="global",e.globalBackend=Ie(n);break}case"index":{e.indexes.push(me(n));break}case"memory":{e.memory=!0;break}case"public":{e.isPublic=!0;break}case"rankIndex":{e.rankIndexes.push(ve(n));break}case"relations":{const r=n[0];r&&e.relations.push(...ue(r));break}case"searchIndex":{e.searchIndexes.push(be(n));break}case"shardBy":{const r=n[0];e.shardMode={field:r&&i.isStringLiteral(r)?r.getLiteralText():"_unknown_",kind:"shardBy"};break}case"softDelete":{e.softDelete={field:we(n[0])};break}case"source":{e.externalSource=Se(n),e.externallyManaged=!0;break}case"ttl":{e.ttl=he(n);break}case"vectorize":{const r=Ee(n,s);r&&e.vectorIndexes.push(r);break}}},_=["__vocab","_config","_content","_data","_docsize","_idx"],Te=(e,t,n)=>{const s=new Set(n.map(r=>r.name));for(const r of n)for(const o of _){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 d(e,`table "${t}" declares search indexes "${r.name}" and "${a}", whose generated FTS5 tables collide: "${r.name}" already owns "${t}__fts_${a}" as its "${o}" companion, so ${l}. Rename one of them so neither ends with another's name plus ${_.join(", ")}.`)}},_e=(e,t,n)=>{if(n.ttl!==void 0&&n.shardMode==="global")throw d(e,ne(t))},P=(e,t)=>{const n={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))ke(n,o.getName(),a,t),r=o.getExpression();else if(i.isIdentifier(o)&&o.getText()==="defineTable"){const l=a[0];if(l&&i.isObjectLiteralExpression(l))s=V(l);else if(l)throw d(l,`table "${t}" 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_${t}\` / \`Insert_${t}\` type instead of sharing the runtime value.`);break}else break}return n.softDelete&&!(n.softDelete.field in s)&&(s={...s,[n.softDelete.field]:{inner:{column:{notNull:!1},kind:"number"},kind:"optional"}}),Te(e,t,n.searchIndexes),_e(e,t,n),{commitOrdered:n.commitOrdered,externallyManaged:n.externallyManaged,externalSource:n.externalSource,geoIndexes:n.geoIndexes,globalBackend:n.shardMode==="global"?n.globalBackend??"d1":void 0,indexes:n.indexes,isPublic:n.isPublic,memory:n.memory,name:t,rankIndexes:n.rankIndexes,relations:n.relations,searchIndexes:n.searchIndexes,shape:s,shardMode:n.shardMode,softDelete:n.softDelete,ttl:n.ttl,vectorIndexes:n.vectorIndexes}},j=(e,t=[],n=new Set,s=new Set)=>{s.add(e);for(const r of e.getProperties()){if(i.isSpreadAssignment(r)){const a=B(r.getExpression());a!==void 0&&!s.has(a)&&j(a,t,n,s);continue}if(!i.isPropertyAssignment(r))continue;const o=r.getInitializer();if(o){const a=I(r);if(w(a,r.getNameNode()),n.has(a))throw d(r.getNameNode(),`defineSchema({...}): table "${a}" is declared more than once — the earlier declaration would be silently discarded. Remove the duplicate.`);n.add(a),t.push(P(o,a))}}return t},Le=e=>{const t=u(e,"source");if(t&&i.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&i.isObjectLiteralExpression(n))return f(n,"table")??"_unknown_"}return"_unknown_"},Oe=e=>{if(!i.isPropertyAssignment(e))return;const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const n=t.getExpression();if(!i.isIdentifier(n)||n.getText()!=="defineVectorIndex")return;const s=t.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:O(f(s,"metric")),name:o,table:Le(s)}},$=e=>{const t=[];for(const n of e.getProperties()){const s=Oe(n);s&&t.push(s)}return t},S=(e,t)=>`${e}_${t}`,Ae=(e,t)=>{if(!N.test(e))throw d(t,`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,t,n)=>n.has(e)?S(t,e):e,Ne=(e,t,n,s)=>{const r=S(t,e.name);return{...e,extensionKey:t,...s?{extensionFromPackage:!0}:{},name:r,relations:e.relations.map(o=>({...o,table:E(o.table,t,n)})),vectorIndexes:e.vectorIndexes.map(o=>({...o,table:E(o.table,t,n)}))}},Pe=e=>{if(i.isVariableDeclaration(e)||i.isPropertyAssignment(e))return e.getInitializer();if(i.isShorthandPropertyAssignment(e))return e.getNameNode()},je=e=>{if(!i.isCallExpression(e))return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="defineSchemaExtension"},$e=e=>{if(i.isIdentifier(e))return e;if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return i.isIdentifier(t)?t:void 0}},De=e=>{if(i.isObjectLiteralExpression(e))return e;if(i.isCallExpression(e)){const t=e.getExpression();let n;if(i.isIdentifier(t)?n=t.getText():i.isPropertyAccessExpression(t)&&(n=t.getName()),n==="definePlugin"){const s=e.getArguments()[1];return s&&i.isObjectLiteralExpression(s)?s:void 0}}},ze=(e,t)=>{const n=Pe(e);if(n){if(i.isPropertyAccessExpression(t)){const s=De(n);return s?b(s,t.getName()):void 0}return n}},Me=e=>{let t=e,n=0;for(;t&&n<32;){if(n+=1,je(t))return t;const s=$e(t),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;t=ze(a,t)}},Re=e=>{const[t,n]=e.getArguments();if(!(!t||!i.isStringLiteral(t))&&!(!n||!i.isObjectLiteralExpression(n)))return{key:t.getLiteralText(),keyNode:t,options:n}},Fe=e=>{const t=u(e,"tables");if(!t||!i.isPropertyAssignment(t))return[];const n=t.getInitializer();if(!n||!i.isObjectLiteralExpression(n))return[];const s=[];for(const r of n.getProperties()){if(!i.isPropertyAssignment(r))continue;const o=r.getInitializer();if(!o)continue;const a=I(r);w(a,r.getNameNode()),s.push(P(o,a))}return s},Ce=e=>{const t=u(e,"vectorIndexes");if(!t||!i.isPropertyAssignment(t))return[];const n=t.getInitializer();return!n||!i.isObjectLiteralExpression(n)?[]:$(n)},D=(e,t,n,s,r)=>{Ae(e,s);const o=new Set(t.map(c=>c.name)),a=t.map(c=>Ne(c,e,o,r)),l=n.map(c=>({...c,name:S(e,c.name),table:E(c.table,e,o)}));return{tables:a,vectorIndexes:l}},Be=(e,t,n)=>D(e,Fe(n),Ce(n),t,t.getSourceFile().getFilePath().includes("/node_modules/")),Ve=(e,t)=>{const n=e.getArguments()[0];if(!n)return;const s=Me(n);if(!s){if(t!==void 0){const o=Y(n,t);if(o){for(const a of o.bareTables)w(a.name,n);return D(o.key,o.bareTables,o.bareVectorIndexes,n,!0)}}console.warn(`@lunora/codegen: skipping \`.extend(${n.getText()})\` — its \`defineSchemaExtension(...)\` could not be resolved from local sources, and ${t===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=Re(s);if(!r){console.warn("@lunora/codegen: skipping `.extend(...)` — `defineSchemaExtension` requires a string `key` and an options object literal.");return}return Be(r.key,r.keyNode,r.options)},qe=e=>{const t=[];let n=e;for(;;){const s=n.getParent();if(!s||!i.isPropertyAccessExpression(s))break;const r=s.getParent();if(!r||!i.isCallExpression(r))break;s.getName()==="extend"&&t.push(r),n=r}return t},Je=(e,t,n)=>{const s=new Set(t.map(o=>o.name)),r=[];for(const o of qe(e)){const a=Ve(o,n);if(a){for(const l of a.tables){if(s.has(l.name))throw d(o,`defineSchema(...).extend(...): table "${l.name}" already exists — another extension with the same key already contributed it.`);s.add(l.name),t.push(l)}r.push(...a.vectorIndexes)}}return r},Ue=new Set(["eu","fedramp","us"]),Ke=e=>A(e,"jurisdiction","jurisdiction",Ue,'"eu", "us", or "fedramp"'),Ze=e=>{let t=e;for(;;){const n=t.getParent(),s=n?.getParent();if(!n||!i.isPropertyAccessExpression(n)||!s||!i.isCallExpression(s))return!1;if(n.getName()==="jurisdiction"){const r=s.getArguments()[1];return r!==void 0&&i.isObjectLiteralExpression(r)&&L(r,"pinAuth")===!0}t=s}},Ge=new Set(["required"]),We=e=>A(e,"rls","rls mode",Ge,'"required"'),rt=(e,t,n)=>{const r=e.addSourceFileAtPath(t).getDescendantsOfKind(R.CallExpression).find(p=>{const T=p.getExpression();return i.isIdentifier(T)&&T.getText()==="defineSchema"});if(!r)throw new M("INTERNAL",`defineSchema() not found in ${t}`);const o=r.getArguments()[0];if(!o||!i.isObjectLiteralExpression(o))throw d(r,"defineSchema() expects an object literal");const a=j(o),l=r.getArguments()[1],c=l&&i.isObjectLiteralExpression(l)?$(l):[],g=Je(r,a,n),k=[...a.flatMap(p=>p.vectorIndexes),...c,...g],z=new Set(a.filter(p=>p.shardMode==="global").map(p=>p.name)),v=k.find(p=>z.has(p.table));if(v)throw d(r,q(v.table,v.name));return{jurisdiction:Ke(r),...Ze(r)?{jurisdictionPinsAuth:!0}:{},rlsMode:We(r),tables:a,vectorIndexes:k}};export{rt as default};
@@ -1,15 +0,0 @@
1
- import{SCHEMA_MODULE_PATH as m}from"./emitDataModel-D3WuEZ4b.mjs";import{b}from"./qualifiers-BhOL15WZ.mjs";import{G as f,a as d,d as g,v as p,u as T,c as A}from"./shared-DjUziztz.mjs";const c=e=>{switch(e.kind){case"array":case"object":case"record":case"union":return{builder:"text",mode:"json",notNull:!0,typeAnnotation:p(e)};case"bigint":return{builder:"blob",mode:"bigint",notNull:!0};case"boolean":return{builder:"integer",mode:"boolean",notNull:!0};case"bytes":return{builder:"blob",mode:"buffer",notNull:!0};case"date":case"timestamp":return{builder:"integer",notNull:!0};case"from":return{builder:"text",notNull:!0,typeAnnotation:p(e)};case"id":return{builder:"text",notNull:!0};case"literal":{const t=e.literalValue??"";return t.startsWith('"')||t.startsWith("'")?{builder:"text",notNull:!0}:t==="true"||t==="false"?{builder:"integer",mode:"boolean",notNull:!0}:t==="null"?{builder:"text",notNull:!0}:{builder:"real",notNull:!0}}case"null":return{builder:"text",notNull:!0};case"number":return{builder:"real",notNull:!0};case"optional":return{...e.inner?c(e.inner):{builder:"text",notNull:!1},notNull:!1};case"storage":case"string":return{builder:"text",notNull:!0};default:return{builder:"text",notNull:!0}}},N=(e,t)=>{const r=T(e);return r.kind==="id"&&r.tableName!==void 0&&t.has(r.tableName)?r.tableName:void 0},h=(e,t,r)=>{d(e,"drizzle column name");const n=c(t),o=n.mode?`, { mode: "${n.mode}" }`:"";let l=`${n.builder}("${e}"${o})`;n.typeAnnotation&&(l+=`.$type<${n.typeAnnotation}>()`);const s=N(t,r);return s!==void 0&&(l+=`.references((): AnySQLiteColumn => ${s}._id)`),n.notNull&&t.column?.notNull!==!1&&(l+=".notNull()"),l},j=e=>{const t=e.unique?"uniqueIndex":"index",r=e.fields.map(n=>(d(n,"drizzle index field"),`t.${n}`)).join(", ");return` ${A(e.name)}: ${t}(${JSON.stringify(e.name)}).on(${r}),`},S=(e,t)=>{d(e.name,"table name");const r=[' _id: text("_id").primaryKey(),',' _creationTime: integer("_creationTime").notNull(),',...Object.entries(e.shape).map(([o,l])=>` ${o}: ${h(o,l,t)},`)].join(`
2
- `),n=e.indexes.length>0?`, (t) => ({
3
- ${e.indexes.map(o=>j(o)).join(`
4
- `)}
5
- })`:"";return`export const ${e.name} = sqliteTable("${e.name}", {
6
- ${r}
7
- }${n});`},I=e=>e.typeAnnotation?.includes('Id<"')??!1,C=(e,t)=>{const r=new Set(["integer","sqliteTable","text"]),n=new Set;let o=!1,l=!1;for(const s of e){for(const i of Object.values(s.shape)){const a=c(i);r.add(a.builder),l=l||I(a),o=o||N(i,t)!==void 0}for(const i of s.indexes)n.add(i.unique?"uniqueIndex":"index")}return{columns:[...r].toSorted((s,i)=>s.localeCompare(i)),indexes:[...n].toSorted((s,i)=>s.localeCompare(i)),needsAnyColumn:o,needsId:l}},x=(e,t=!1)=>{if(e.length===0)return`${f}export {};
8
- `;const r=g(t),n=new Set(e.map(u=>u.name)),{columns:o,indexes:l,needsAnyColumn:s,needsId:i}=C(e,n),a=[...l,...o].toSorted((u,z)=>u.localeCompare(z)),$=e.map(u=>S(u,n)).join(`
9
-
10
- `),y=[s?`import type { AnySQLiteColumn } from "${r.serverDrizzle}";
11
- `:"",i?`import type { Id } from "./dataModel.js";
12
- `:""].join("");return`${f}import { ${a.join(", ")} } from "${r.serverDrizzle}";
13
- ${y}
14
- ${$}
15
- `},q=(e,t=!1)=>{const r=e.tables.filter(o=>o.shardMode==="global"),n=e.tables.filter(o=>o.shardMode!=="global");return{global:b(x(r,t),m),shard:b(x(n,t),m)}};export{q as default};
@@ -1 +0,0 @@
1
- import{Node as a}from"ts-morph";import{c as n}from"./classify-procedure-call-VzDQHiLB.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 +0,0 @@
1
- import{Node as r}from"ts-morph";import{propertyKeyName as f,listLunoraSourceFiles as m,lunoraRelativePath as p,tablesAccessedIn as d}from"./listLunoraSourceFiles-DmOftuU4.mjs";import{w as g,c as h}from"./classify-procedure-call-VzDQHiLB.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 +0,0 @@
1
- import{readdirSync as y,realpathSync as O,lstatSync as T,statSync as N}from"node:fs";import{dirname as w,join as d,relative as F,sep as R,extname as P}from"node:path";import{SyntaxKind as c,Node as s,VariableDeclarationKind as I}from"ts-morph";import{diagnosticAt as D}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{findProjectConfigFile as C}from"./PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";const z=/\.ts$/u,g=(t,e)=>F(t,e).split(R).join("/").replace(z,""),j=new Set(["_generated","node_modules"]),_=(t,e,i)=>t==="schema.ts"&&e===i,k=t=>{try{return N(t)}catch{console.warn(`@lunora/codegen: skipping ${t} — it is a symlink that does not resolve (or vanished mid-scan).`);return}},h=(t,e,i,r)=>{let n,o;try{n=y(t),o=O(t)}catch{return e}if(r.has(o))return e;r.add(o);for(const a of n){const l=d(t,a),u=k(l);u!==void 0&&(u.isDirectory()?j.has(a)||h(l,e,i,r):u.isFile()&&P(a)===".ts"&&!_(a,t,i)&&e.push(l))}return e},A=t=>h(t,[],t,new Set),K=["src/server","src/index.ts","src/worker.ts"],V=new Set([".ts",".tsx"]),L=(t,e=[])=>{let i;try{i=T(t)}catch{return e}if(i.isFile())return V.has(P(t))&&e.push(t),e;if(!i.isDirectory())return e;for(const r of y(t))r==="_generated"||r==="node_modules"||L(d(t,r),e);return e},M=t=>{const e=w(t),i=A(t).map(o=>({displayPath:g(t,o),filePath:o})),r=new Set(i.map(o=>o.filePath)),n=C(e);for(const o of[...K.flatMap(a=>L(d(e,a))),...n===void 0?[]:[n]])r.has(o)||(r.add(o),i.push({displayPath:g(e,o),filePath:o}));return i},U=t=>Array.isArray(t),b=(t,e,i,r)=>{const n=[];for(const{displayPath:o,filePath:a}of e){const l=t.getSourceFile(a)??t.addSourceFileAtPath(a);for(const u of l.getDescendantsOfKind(i)){const p=r(u,o);U(p)?n.push(...p):p!==void 0&&n.push(p)}}return n},W=t=>A(t).map(e=>({displayPath:g(t,e),filePath:e})),$=(t,e,i,r)=>b(t,W(e),i,r),nt=(t,e,i)=>$(t,e,c.CallExpression,i),ot=(t,e,i)=>b(t,M(e),c.CallExpression,i),v=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()},B=t=>v(t.getNameNode()),at=t=>v(t.getPropertyNameNode()??t.getNameNode()),E=(t,e)=>t?.getProperties().find(i=>!s.isSpreadAssignment(i)&&B(i)===e),ct=(t,e)=>{if(e){const o=t.getArguments()[0];return o&&(s.isArrowFunction(o)||s.isFunctionExpression(o))?o:void 0}const i=t.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return;const r=E(i,"handler");if(!r||!s.isPropertyAssignment(r))return;const n=r.getInitializer();return n&&(s.isArrowFunction(n)||s.isFunctionExpression(n))?n:void 0},lt=(t,e)=>{if(!t||!s.isObjectLiteralExpression(t))return;const i=E(t,e);return i&&s.isPropertyAssignment(i)?i.getInitializer():void 0},q=t=>{const e=t?.getParent();return s.isVariableDeclaration(t)&&s.isVariableDeclarationList(e)&&e.getDeclarationKind()===I.Const},H=t=>{let e=t,i=e.getParent();for(;i!==void 0&&(s.isParenthesizedExpression(i)||s.isAsExpression(i)||s.isSatisfiesExpression(i)||s.isTypeAssertion(i)||s.isNonNullExpression(i));)e=i,i=e.getParent();return e},x=t=>{const e=H(t),i=e.getParent();if(i===void 0)return!1;if(s.isBinaryExpression(i)){const n=i.getOperatorToken().getKind();return i.getLeft()===e&&n>=c.FirstAssignment&&n<=c.LastAssignment}if(s.isPrefixUnaryExpression(i)||s.isPostfixUnaryExpression(i)){const n=i.getOperatorToken();return n===c.PlusPlusToken||n===c.MinusMinusToken}return s.isDeleteExpression(i)?!0:s.isForOfStatement(i)||s.isForInStatement(i)?i.getInitializer()===e:s.isPropertyAssignment(i)?i.getInitializer()===e&&x(i):(s.isShorthandPropertyAssignment(i)||s.isSpreadAssignment(i)||s.isSpreadElement(i)||s.isObjectLiteralExpression(i)||s.isArrayLiteralExpression(i))&&x(i)},X=t=>{const e=t?.getDeclarations().find(r=>s.isVariableDeclaration(r));if(!q(e))return;const i=e.getParent().getParent();return s.isVariableStatement(i)&&s.isSourceFile(i.getParent())?e.getInitializer():void 0},Y=t=>X(t.getSymbol()),ut=t=>{if(!t)return;if(s.isObjectLiteralExpression(t))return t;if(!s.isIdentifier(t))return;const e=Y(t);return e!==void 0&&s.isObjectLiteralExpression(e)?e:void 0},f=t=>s.isPropertyAccessExpression(t)&&t.getName()==="db"||s.isIdentifier(t)&&t.getText()==="db",Q=new Set(["findFirst","findFirstOrThrow","findMany","findUnique"]),pt=t=>{const e=t.getExpression();if(!s.isPropertyAccessExpression(e)||!Q.has(e.getName()))return;const i=e.getExpression();if(f(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(f(r))return{options:t.getArguments()[0],table:i.getName()}}},m=(t,e)=>{const i=t.getExpression();return!s.isPropertyAccessExpression(i)||!e.has(i.getName())?!1:f(i.getExpression())},S=t=>{const e=t.getArguments()[0];return e&&s.isStringLiteral(e)?e.getLiteralText():""},gt=(t,e,i)=>{const r=new Set,n=new Set;for(const o of t.getDescendantsOfKind(c.CallExpression))if(m(o,e)){const a=S(o);a!==""&&r.add(a)}else if(m(o,i)){const a=S(o);a!==""&&n.add(a)}return{tablesRead:[...r],tablesWritten:[...n]}},G=t=>{let e=t;for(;e&&(s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isParenthesizedExpression(e)||s.isNonNullExpression(e));)e=e.getExpression();return e},ft=t=>{const e=G(t);return e&&s.isCallExpression(e)?e:void 0},dt=t=>{const e=t.getExportAssignment(n=>!n.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},Et=t=>{const e=t.getArguments()[1];return e&&s.isStringLiteral(e)?e.getLiteralValue():""},xt=(t,e)=>{if(!s.isObjectLiteralExpression(t))return;const i=E(t,e);if(!i||!s.isPropertyAssignment(i))return;const r=i.getInitializer();return r&&s.isStringLiteral(r)?r.getLiteralText():void 0},J=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},mt=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)?J(t):void 0},St=t=>s.isIdentifier(t)&&t.getText()==="ctx",yt=t=>(e,i,r)=>{if(s.isStringLiteral(e)||s.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw D(e,`${t} "${i}": \`${r}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)},Z=new Set(["api","internal"]),Pt=new Set(["run","runAction","runMutation","runQuery"]),ht=t=>{if(t===void 0||!s.isPropertyAccessExpression(t))return;const e=[];let i=t;for(;s.isPropertyAccessExpression(i);)e.unshift(i.getName()),i=i.getExpression();return s.isIdentifier(i)&&Z.has(i.getText())&&e.length>=2?e:void 0};export{Pt as RUN_METHODS,z as TS_EXTENSION_RE,at as bindingKeyName,nt as collectCallRows,$ as collectNodeRows,ot as collectSecurityCallRows,dt as defaultExportExpression,E as findObjectProperty,ht as functionReferenceSegments,ct as handlerOf,q as isConstDeclaration,St as isContextIdentifier,f as isDatabaseAccessor,x as isWriteTarget,Et as limitNameOf,A as listLunoraSourceFiles,M as listSecurityScanFiles,g as lunoraRelativePath,mt as objectLiteralFromCallbackBody,ut as optionsObjectLiteral,H as outermostValueWrapper,lt as propertyInitializer,B as propertyKeyName,v as propertyNameText,pt as readTargetOf,yt as stringPropertyFor,xt as stringPropertyOf,X as symbolConstInitializer,S as tableArgumentOf,gt as tablesAccessedIn,G as unwrapExpression,ft as unwrapToCallExpression};
@@ -1,9 +0,0 @@
1
- import{LunoraError as l}from"@lunora/errors";import{acceptsAbsentIr as $}from"./LUNORA_ERROR_CODES-C2s0xWQD.mjs";const b=/^(?:"(?:[^"\\]|\\(?:["\\/bfnrt]|u[0-9A-Fa-f]{4}))*"|'[^'\\]*'|-?\d+(?:\.\d+)?|true|false|null)$/u,_=`// GENERATED by @lunora/codegen — do not edit.
2
- // Run \`lunora codegen\` to regenerate.
3
-
4
- `,w=(e=!1)=>e?{client:"lunorash/client",do:"lunorash/do",flags:"lunorash/flags",server:"lunorash/server",serverDataModel:"lunorash/server/data-model",serverDrizzle:"lunorash/server/drizzle",serverTypes:"lunorash/server/types",values:"lunorash/values"}:{client:"@lunora/client",do:"@lunora/do",flags:"@lunora/flags",server:"@lunora/server",serverDataModel:"@lunora/server/data-model",serverDrizzle:"@lunora/server/drizzle",serverTypes:"@lunora/server/types",values:"@lunora/values"},p=/^[A-Za-z_$][\w$]*$/u,A=/^[\w./-]+$/u,y=(e,n)=>{if(!p.test(e))throw new l("INTERNAL",`@lunora/codegen: ${n} is not a valid JS identifier: ${JSON.stringify(e)}`)},I=e=>e.charAt(0).toUpperCase()+e.slice(1),u=e=>p.test(e)?e:JSON.stringify(e),R=e=>e==="__proto__"?`[${JSON.stringify(e)}]`:u(e),g={any:"unknown",bigint:"bigint",boolean:"boolean",bytes:"ArrayBuffer",date:"number",geoPoint:"{ lat: number; lng: number }",null:"null",number:"number",storage:"string",string:"string",timestamp:"number"},T=e=>{if(e===void 0)return"unknown";if(!b.test(e))throw new l("INTERNAL",`@lunora/codegen: v.literal() argument is not a parseable string/number/boolean/null literal: ${JSON.stringify(e)}`);return e},t=e=>e.column?.notNull===!1?`${a(e)} | null`:a(e),a=e=>{const n=g[e.kind];if(n!==void 0)return n;switch(e.kind){case"array":return`Array<${e.inner?t(e.inner):"unknown"}>`;case"from":return e.tsType??"unknown";case"id":{const r=e.tableName??"_unknown_";return y(r,"v.id() table name"),`Id<"${r}">`}case"literal":return T(e.literalValue);case"object":return e.shape?`{ ${Object.entries(e.shape).map(([s,o])=>m(s,o)).join("; ")} }`:"Record<string, unknown>";case"optional":return`${e.inner?t(e.inner):"unknown"} | undefined`;case"record":{const r=e.keyType?t(e.keyType):"string",s=e.valueType?t(e.valueType):"unknown";return`Record<${r}, ${s}>`}case"union":return e.members&&e.members.length>0?e.members.map(r=>t(r)).join(" | "):"never";default:return"unknown"}},m=(e,n)=>{const r=u(e);if(n.kind==="optional"){const s=n.inner?t(n.inner):"unknown";return`${r}?: ${s}`}return $(n)?`${r}?: ${t(n)}`:`${r}: ${t(n)}`},O=e=>{const n=Object.entries(e);return n.length===0?"{}":`{ ${n.map(([r,s])=>m(r,s)).join("; ")} }`},d=e=>e.kind==="optional"||!!e.column?.hasDefault,E=e=>e.kind==="optional"&&e.inner?e.inner:e,N=e=>{y(e.name,"table name");const n=Object.entries(e.shape).map(([s,o])=>{const f=E(o),c=t(f),i=u(s);return d(o)?` ${i}?: ${c};`:` ${i}: ${c};`}).join(`
5
- `),r=n?`
6
- ${n}
7
- `:"";return`export interface Insert_${e.name} {
8
- _id?: Id<"${e.name}">;
9
- _creationTime?: number;${r}}`};export{_ as G,A as I,b as L,y as a,u as b,R as c,w as d,N as e,d as i,I as p,O as r,E as u,t as v};