@lunora/codegen 1.0.0-alpha.384 → 1.0.0-alpha.386

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/index.d.mts +32 -6
  2. package/dist/index.d.ts +32 -6
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/{GENERATED_HEADER-Bzf6ZJ9r.mjs → GENERATED_HEADER-B-tYRlRG.mjs} +1 -1
  5. package/dist/packem_shared/{MUTATORS_FILENAME-DlSftsvY.mjs → MUTATORS_FILENAME-D9WbOFm7.mjs} +1 -1
  6. package/dist/packem_shared/{NOTIFY_FILENAME-SKk8x0VM.mjs → NOTIFY_FILENAME-CRU_TEKs.mjs} +1 -1
  7. package/dist/packem_shared/{OPENRPC_VERSION-CSjT8wJW.mjs → OPENRPC_VERSION-CT_E2DcI.mjs} +1 -1
  8. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DqUXDvki.mjs +31 -0
  9. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs +2 -0
  10. package/dist/packem_shared/{SHAPES_FILENAME-rSSihffV.mjs → SHAPES_FILENAME-D9beIrs1.mjs} +1 -1
  11. package/dist/packem_shared/{SchemaSnapshotParseError-ycDz8gOB.mjs → SchemaSnapshotParseError-DnAuFdpl.mjs} +8 -8
  12. package/dist/packem_shared/{buildOpenApiDocument-afHH7rN5.mjs → buildOpenApiDocument-67-fasdW.mjs} +1 -1
  13. package/dist/packem_shared/{context-property-calls-CYaejv5r.mjs → context-property-calls-ZK1UcTQR.mjs} +1 -1
  14. package/dist/packem_shared/{context-root-TiLodrRO.mjs → context-root-DtpwprsY.mjs} +1 -1
  15. package/dist/packem_shared/{database-calls-QqsrkDMs.mjs → database-calls-Cn47SfSU.mjs} +1 -1
  16. package/dist/packem_shared/{discoverFunctions-DdHysjy1.mjs → discoverFunctions-DU5ylqVC.mjs} +1 -1
  17. package/dist/packem_shared/{discoverHttpRoutes-5iA7gI_Q.mjs → discoverHttpRoutes-D9Q0lBBb.mjs} +1 -1
  18. package/dist/packem_shared/discoverHyperdriveCalls-DlyCZKX3.mjs +1 -0
  19. package/dist/packem_shared/{discoverInserts-Dw7fvL7s.mjs → discoverInserts-7Xdawmuk.mjs} +1 -1
  20. package/dist/packem_shared/discoverMaskProcedures-D6kAKDZG.mjs +1 -0
  21. package/dist/packem_shared/{discoverQueries-DVFZJER7.mjs → discoverQueries-C75OdGHl.mjs} +1 -1
  22. package/dist/packem_shared/discoverR2sqlCalls-BrDIti5c.mjs +1 -0
  23. package/dist/packem_shared/{discoverRlsProcedures-C2lkSLPn.mjs → discoverRlsProcedures-BiyDg2ej.mjs} +1 -1
  24. package/dist/packem_shared/discoverSchema-Bs5JUiOE.mjs +1 -0
  25. package/dist/packem_shared/{emitAgents-BeM6PZv4.mjs → emitAgents-iTKWSKan.mjs} +1 -1
  26. package/dist/packem_shared/{emitApi-GFmStqmq.mjs → emitApi-DWJW8Vu9.mjs} +1 -1
  27. package/dist/packem_shared/{emitApp-D-6FIpYb.mjs → emitApp-L7PnfjJK.mjs} +1 -1
  28. package/dist/packem_shared/{emitCrons-Drdn8Mjn.mjs → emitCrons-BvqxeNRr.mjs} +1 -1
  29. package/dist/packem_shared/{emitDataModel-LTnwnhV6.mjs → emitDataModel-MjAOi3KM.mjs} +1 -1
  30. package/dist/packem_shared/{emitDrizzleSchema-CM9jh_F0.mjs → emitDrizzleSchema-Dszoyymv.mjs} +1 -1
  31. package/dist/packem_shared/{emitFunctions-DRAuiKPv.mjs → emitFunctions-C4PzKb4H.mjs} +84 -80
  32. package/dist/packem_shared/{emitServer-4l7MPmK0.mjs → emitServer-BgI9yXW1.mjs} +1 -1
  33. package/dist/packem_shared/emitShard-D4sAFu7Z.mjs +1 -0
  34. package/dist/packem_shared/{index-iw3axJ5Y.mjs → index-CNI4vSyc.mjs} +1 -1
  35. package/dist/packem_shared/index-o449rQLQ.mjs +1 -0
  36. package/dist/packem_shared/{ip-reads-BVXbFgzV.mjs → ip-reads-Dotjify6.mjs} +1 -1
  37. package/dist/packem_shared/{qualifiers-D1Q_3wo2.mjs → qualifiers-ClaCHu0X.mjs} +1 -1
  38. package/dist/packem_shared/{server-D69SOfX8.mjs → server-qWq5nN-R.mjs} +1 -1
  39. package/dist/packem_shared/{shard-L3gYZnC9.mjs → shard-BqfSKnmG.mjs} +1 -1
  40. package/dist/packem_shared/{shard-runtime-lkQU8trx.mjs → shard-runtime-C1P_uVye.mjs} +1 -1
  41. package/dist/packem_shared/{shared-A1XHcT4t.mjs → shared-DhqnD5R3.mjs} +6 -6
  42. package/dist/packem_shared/static-literal-BwDHHjEJ.mjs +1 -0
  43. package/dist/packem_shared/{unwrap-handler-return-eQRIZSOX.mjs → unwrap-handler-return-c2s2-nk9.mjs} +1 -1
  44. package/package.json +8 -8
  45. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-Dle_pfr9.mjs +0 -31
  46. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-BdxZuSxk.mjs +0 -2
  47. package/dist/packem_shared/discoverHyperdriveCalls-BJRaIvLx.mjs +0 -1
  48. package/dist/packem_shared/discoverMaskProcedures-BLKjuD-A.mjs +0 -1
  49. package/dist/packem_shared/discoverR2sqlCalls-BEBdqXi_.mjs +0 -1
  50. package/dist/packem_shared/discoverSchema-Cycd1-H0.mjs +0 -1
  51. package/dist/packem_shared/emitShard-DqEvyZPZ.mjs +0 -1
  52. package/dist/packem_shared/index-BhsJzv9r.mjs +0 -1
@@ -1 +0,0 @@
1
- import{d as r}from"./context-property-calls-CYaejv5r.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
@@ -1 +0,0 @@
1
- import{LunoraError as C}from"@lunora/errors";import{Node as i,SyntaxKind as B}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{findObjectProperty as u,descendantsOfKind as V}from"./isTestPath-JdN4KXhV.mjs";import{createRequire as q}from"node:module";import{join as O}from"node:path";import{fileURLToPath as J}from"node:url";import{createJiti as U}from"jiti";import{r as K,p as W}from"./parse-validator-BisfC8bR.mjs";import{R as X}from"./reserved-words-CW1QFbTd.mjs";import{a as w}from"./property-name-7cBlgK_O.mjs";const Z=(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.`,G=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}},H=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 t=e?._meta??{},n=e?.kind??"unknown",s={column:H(t.column),kind:n};switch(n){case"array":case"optional":{s.inner=g(t.inner);break}case"from":break;case"id":{s.tableName=t.tableName;break}case"literal":{s.literalValue=G(t.value);break}case"object":{const r=t.shape??{};s.shape=Object.fromEntries(Object.entries(r).map(([o,a])=>[o,g(a)]));break}case"record":{s.valueType=g(t.valueValidator),t.keyValidator!==void 0&&(s.keyType=g(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=>g(o));break}}return s},Q=e=>e?.kind==="global"?"global":e?.kind==="shardBy"&&typeof e.field=="string"?{field:e.field,kind:"shardBy"}:"root",Y=(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.`)},ee=(e,t)=>{const n=e.shape??{},s=(e.indexes??[]).map(r=>({fields:r.fields,name:r.name,...r.unique?{unique:!0}:{}}));return Y(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,g(o)])),shardMode:Q(e.shardMode),vectorIndexes:[]}},te=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])=>ee(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}},ne=e=>{if(i.isIdentifier(e))return e.getText();if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0}},re=e=>{const t=ne(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:[]}}},se=(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},ie=(e,t)=>{const n=re(e);if(n)try{const s=U(O(t,"noop.js")).esmResolve(n.moduleSpecifier),r=q(O(t,"noop.cjs"))(s.startsWith("file:")?J(s):s),o=se(r,n);return typeof o!="object"||o===null?void 0:te(o)}catch{return}},oe=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()},y=(e,t)=>{const n=b(e,t);if(n&&i.isNumericLiteral(n))return Number(n.getLiteralText())},N=(e,t)=>{const n=b(e,t);if(n&&(i.isTrueLiteral(n)||i.isFalseLiteral(n)))return n.getLiteralValue()},v=(e,t)=>{const n=b(e,t);if(n&&i.isArrayLiteralExpression(n))return n.getElements().filter(s=>i.isStringLiteral(s)).map(s=>s.getLiteralText())},P=e=>e&&oe.has(e)?e:void 0,E=e=>e&&i.isStringLiteral(e)?e.getLiteralText():"_unnamed_",ae=(e,t)=>{const n=v(e,t);return n!==void 0&&n.length>0?n:void 0},j=(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 d=l.getArguments()[0];if(!d||!i.isStringLiteral(d))throw c(l,`\`.${t}(...)\` expects a string literal (${r})`);const m=d.getLiteralText();if(!s.has(m))throw c(d,`unknown ${n} ${JSON.stringify(m)} — expected ${r}`);return m}o=l}},le=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.`,ce=/^(?:sqlite_|_cf_|__)/u,de=/__(?:agg|rank|geo|fts)_/u,fe=e=>ce.test(e)||de.test(e),ue=new Set(["cascade","restrict","set null"]),pe=new Set(["aggregate","asId","assertPatchAllowed","cdcChangedTables","count","delete","deleteAll","deleteMany","deleteRereadTables","deleteWhere","explain","findFirst","findFirstOrThrow","findMany","get","groupBy","insert","insertMany","insertManyUnsafe","inTransaction","lookupById","normalizeId","patch","patchIf","patchMany","patchWhere","query","rank","rankBefore","rankPage","rankPageRows","related","relationEdges","relationWrites","replace","restore","softDeleteFields","system","wipeShard"]),$=/^[A-Za-z_$][\w$]*$/u,k=(e,t)=>{if(pe.has(e))throw c(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(X.has(e))throw c(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(!$.test(e))throw c(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(fe(e))throw c(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.`)},ge=e=>e&&ue.has(e)?e:void 0,me=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},he=(e,t,n)=>{const s=i.isPropertyAssignment(e)?e.getInitializer():void 0;if(!s||!i.isObjectLiteralExpression(s))throw c(e,"relation `through` must be an object literal `{ table, from, to }` — codegen resolves it statically.");const[r,o,a]=["table","from","to"].map(l=>f(s,l));if(r===void 0||o===void 0||a===void 0)throw c(s,"relation `through` needs string-literal `table`, `from` and `to` — codegen resolves them statically.");if(o===a)throw c(s,`relation \`through\` has \`from\` and \`to\` both set to "${o}"; a link needs two different columns.`);return{kind:"many",name:t,table:n,through:{from:o,table:r,to:a}}},be=(e,t,n,s)=>{const r=s&&i.isObjectLiteralExpression(s)?s:void 0,o=e==="many"?r?.getProperty("through"):void 0;return o?he(o,t,n):{field:(r&&f(r,"field"))??"_unknown_",kind:e,name:t,onDelete:e==="one"&&r?ge(f(r,"onDelete")):void 0,references:(r&&f(r,"references"))??"_id",table:n}},xe=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 c(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();return be(s,w(e),a,o)},ye=e=>{const t=me(e);if(!t)return[];const n=[];for(const s of t.getProperties()){const r=xe(s);r&&n.push(r)}return n},ve=(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 c(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.`,{code:"INDEX_FIELD_NESTED_PATH",name:"LunoraError",status:500})},Ee=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 c(n,`\`unique\` must be a literal \`true\` or \`false\`, got ${JSON.stringify(n.getText())}`);return i.isTrueLiteral(n)},Ie=e=>{const[t,n,s]=e,r=Ee(s),o=E(t),a=n&&i.isArrayLiteralExpression(n)?n.getElements():[];for(const d of a)if(!i.isStringLiteral(d))throw c(d,`index "${o}" lists a non-literal field (${JSON.stringify(d.getText())}); codegen reads index fields statically, so every entry must be a string literal.`);const l=a.filter(d=>i.isStringLiteral(d));for(const d of l)ve(d,d.getLiteralText(),o);return{fields:l.map(d=>d.getLiteralText()),name:o,unique:r}},we=e=>{const[t,n]=e;let s="_unknown_",r,o,a,l;return n&&i.isObjectLiteralExpression(n)&&(s=f(n,"field")??s,r=v(n,"filterFields"),o=f(n,"language"),a=N(n,"staged"),l=f(n,"strategy")),{field:s,filterFields:r,language:o,name:E(t),staged:a,strategy:l}},ke=e=>{const[t,n]=e;let s="_unknown_",r;return n&&i.isObjectLiteralExpression(n)&&(s=f(n,"field")??s,r=y(n,"precision")),{field:s,name:E(t),precision:r}},Se=e=>{const[t,n]=e,s=t&&i.isStringLiteral(t)?t.getLiteralText():"_unknown_";let r;return n&&i.isObjectLiteralExpression(n)&&(r=y(n,"after")),{after:r,field:s}},Te=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}},_e=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=>Te(l)).filter(l=>l!==void 0))}r=v(n,"partitionBy")}return{name:E(t),partitionBy:r,sortBy:s}},Oe=(e,t)=>{const[n,s]=e,r=n&&i.isStringLiteral(n)?n.getLiteralText():"_unknown_";if(!(!s||!i.isObjectLiteralExpression(s)))return{dimensions:y(s,"dimensions"),field:r,metadata:v(s,"metadata"),metric:P(f(s,"metric")),name:f(s,"index")??"_unnamed_",table:t}},Le=e=>{const t=e[0];return t&&i.isObjectLiteralExpression(t)&&f(t,"backend")==="hyperdrive"?"hyperdrive":"d1"},L=(e,t)=>{if(e===void 0)return t;if(!i.isObjectLiteralExpression(e))throw c(e,"the options must be an object literal — codegen reads the column name from the source and cannot evaluate a variable or an expression here.");const n=u(e,"field");if(n===void 0)return t;const s=i.isPropertyAssignment(n)?n.getInitializer():void 0;if(s&&i.isStringLiteral(s))return s.getLiteralText();throw c(n,"`field` must be a string literal — codegen reads the column name from the source and cannot evaluate a constant or an expression here.")},Ae=e=>{const t=e[0];return!t||!i.isObjectLiteralExpression(t)?{binding:"",hasTenantBy:!1,unanalyzable:!0}:{binding:f(t,"binding")??"",columns:ae(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")}},Ne=(e,t,n,s)=>{switch(t){case"aggregateIndex":{e.aggregateIndexed=!0;break}case"commitOrdered":{e.commitOrdered=!0;break}case"externallyManaged":{e.externallyManaged=!0;break}case"geoIndex":{e.geoIndexes.push(ke(n));break}case"global":{e.shardMode="global",e.globalBackend=Le(n);break}case"index":{e.indexes.unshift(Ie(n));break}case"memory":{e.memory=!0;break}case"public":{e.isPublic=!0;break}case"rankIndex":{e.rankIndexes.push(_e(n));break}case"relations":{const r=n[0];r&&e.relations.push(...ye(r));break}case"searchIndex":{e.searchIndexes.push(we(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:L(n[0],"deletedAt")};break}case"source":{e.externalSource=Ae(n),e.externallyManaged=!0;break}case"timestamps":{e.timestampsFields.push(L(n[0],"updatedAt"));break}case"ttl":{e.ttl=Se(n);break}case"vectorize":{const r=Oe(n,s);r&&e.vectorIndexes.push(r);break}}},A=["__vocab","_config","_content","_data","_docsize","_idx"],Pe=(e,t,n)=>{const s=new Set(n.map(r=>r.name));for(const r of n)for(const o of A){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 c(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 ${A.join(", ")}.`)}},je=(e,t,n)=>{if(n.ttl!==void 0&&n.shardMode==="global")throw c(e,le(t))},$e=(e,t,n)=>{const{softDelete:s,timestampsFields:r}=n,o={};s&&!(s.field in t)&&(o[s.field]={inner:{column:{notNull:!1},kind:"number"},kind:"optional"});const[a]=r;if(a===void 0)return{...t,...o};if(r.length>1)throw c(e,"`.timestamps()` was called more than once; one table tracks one last-change column.");if(a===s?.field)throw c(e,`\`.softDelete()\` and \`.timestamps()\` both use "${a}"; give one of them another field.`);const l=t[a];if(l===void 0)o[a]={column:{hasDefault:!0,hasOnUpdate:!0,notNull:!0},kind:"timestamp"};else if(l.kind!=="timestamp"||l.column?.hasOnUpdate!==!0||l.column.hasDefault!==!0)throw c(e,`\`.timestamps()\` would add "${a}", but the table already declares it as something other than \`v.timestamp().defaultNow().$onUpdateFn(() => Date.now())\`; remove the column or declare it that way.`);return{...t,...o}},D=(e,t)=>{const n={aggregateIndexed:!1,commitOrdered:!1,externallyManaged:!1,geoIndexes:[],indexes:[],isPublic:!1,memory:!1,rankIndexes:[],relations:[],searchIndexes:[],shardMode:"root",timestampsFields:[],vectorIndexes:[]};let s={},r=e;for(;i.isCallExpression(r);){const o=r.getExpression(),a=r.getArguments();if(i.isPropertyAccessExpression(o))Ne(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=W(l);else if(l)throw c(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 s=$e(e,s,n),Pe(e,t,n.searchIndexes),je(e,t,n),{...n.aggregateIndexed?{aggregateIndexed:!0}:{},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}},z=(e,t=[],n=new Set,s=new Set)=>{s.add(e);for(const r of e.getProperties()){if(i.isSpreadAssignment(r)){const a=K(r.getExpression());a!==void 0&&!s.has(a)&&z(a,t,n,s);continue}if(!i.isPropertyAssignment(r))continue;const o=r.getInitializer();if(o){const a=w(r);if(k(a,r.getNameNode()),n.has(a))throw c(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(D(o,a))}}return t},De=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_"},ze=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:y(s,"dimensions"),metric:P(f(s,"metric")),name:o,table:De(s)}},F=e=>{const t=[];for(const n of e.getProperties()){const s=ze(n);s&&t.push(s)}return t},S=(e,t)=>`${e}_${t}`,Fe=(e,t)=>{if(!$.test(e))throw c(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.`)},h=(e,t,n)=>n.has(e)?S(t,e):e,x=(e,t)=>{const n=s=>s===void 0?void 0:x(s,t);return{...e,...e.tableName===void 0?{}:{tableName:t(e.tableName)},...e.inner===void 0?{}:{inner:n(e.inner)},...e.keyType===void 0?{}:{keyType:n(e.keyType)},...e.valueType===void 0?{}:{valueType:n(e.valueType)},...e.members===void 0?{}:{members:e.members.map(s=>x(s,t))},...e.shape===void 0?{}:{shape:Object.fromEntries(Object.entries(e.shape).map(([s,r])=>[s,x(r,t)]))}}},Me=(e,t,n,s)=>{const r=S(t,e.name);return{...e,extensionKey:t,...s?{extensionFromPackage:!0}:{},name:r,shape:Object.fromEntries(Object.entries(e.shape).map(([o,a])=>[o,x(a,l=>h(l,t,n))])),relations:e.relations.map(o=>{const a=h(o.table,t,n);return o.through===void 0?{...o,table:a}:{...o,table:a,through:{...o.through,table:h(o.through.table,t,n)}}}),vectorIndexes:e.vectorIndexes.map(o=>({...o,table:h(o.table,t,n)}))}},Re=e=>{if(i.isVariableDeclaration(e)||i.isPropertyAssignment(e))return e.getInitializer();if(i.isShorthandPropertyAssignment(e))return e.getNameNode()},Ce=e=>{if(!i.isCallExpression(e))return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="defineSchemaExtension"},Be=e=>{if(i.isIdentifier(e))return e;if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return i.isIdentifier(t)?t:void 0}},Ve=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}}},qe=(e,t)=>{const n=Re(e);if(n){if(i.isPropertyAccessExpression(t)){const s=Ve(n);return s?b(s,t.getName()):void 0}return n}},Je=e=>{let t=e,n=0;for(;t&&n<32;){if(n+=1,Ce(t))return t;const s=Be(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=qe(a,t)}},Ue=e=>{const[t,n]=e.getArguments();if(!(!t||!i.isStringLiteral(t))&&!(!n||!i.isObjectLiteralExpression(n)))return{key:t.getLiteralText(),keyNode:t,options:n}},Ke=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=w(r);k(a,r.getNameNode()),s.push(D(o,a))}return s},We=e=>{const t=u(e,"vectorIndexes");if(!t||!i.isPropertyAssignment(t))return[];const n=t.getInitializer();return!n||!i.isObjectLiteralExpression(n)?[]:F(n)},M=(e,t,n,s,r)=>{Fe(e,s);const o=new Set(t.map(d=>d.name)),a=t.map(d=>Me(d,e,o,r)),l=n.map(d=>({...d,name:S(e,d.name),table:h(d.table,e,o)}));return{tables:a,vectorIndexes:l}},Xe=(e,t,n)=>M(e,Ke(n),We(n),t,t.getSourceFile().getFilePath().includes("/node_modules/")),Ze=(e,t)=>{const n=e.getArguments()[0];if(!n)return;const s=Je(n);if(!s){if(t!==void 0){const o=ie(n,t);if(o){for(const a of o.bareTables)k(a.name,n);return M(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=Ue(s);if(!r){console.warn("@lunora/codegen: skipping `.extend(...)` — `defineSchemaExtension` requires a string `key` and an options object literal.");return}return Xe(r.key,r.keyNode,r.options)},Ge=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},He=(e,t,n)=>{const s=new Set(t.map(o=>o.name)),r=[];for(const o of Ge(e)){const a=Ze(o,n);if(a){for(const l of a.tables){if(s.has(l.name))throw c(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},Qe=new Set(["eu","fedramp","us"]),Ye=e=>j(e,"jurisdiction","jurisdiction",Qe,'"eu", "us", or "fedramp"'),et=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)&&N(r,"pinAuth")===!0}t=s}},tt=new Set(["required"]),nt=e=>j(e,"rls","rls mode",tt,'"required"'),rt=e=>{if(!i.isObjectLiteralExpression(e))return;const t=new Set;for(const n of e.getProperties()){const s=i.isPropertyAssignment(n)?n.getInitializer():void 0;if(!s||!i.isCallExpression(s))return;const r=s.getExpression(),o=s.getArguments()[1],a=o&&i.isObjectLiteralExpression(o)?f(o,"on"):void 0;if(!i.isIdentifier(r)||r.getText()!=="defineAggregateIndex"||a===void 0)return;t.add(a)}return t},st=(e,t)=>{if(t===void 0)return;const n=rt(t);for(const s of e)(n===void 0||n.has(s.name))&&(s.aggregateIndexed=!0)},ht=(e,t,n)=>{const s=e.addSourceFileAtPath(t),r=V(s,B.CallExpression).find(p=>{const _=p.getExpression();return i.isIdentifier(_)&&_.getText()==="defineSchema"});if(!r)throw new C("INTERNAL",`defineSchema() not found in ${t}`);const o=r.getArguments()[0];if(!o||!i.isObjectLiteralExpression(o))throw c(r,"defineSchema() expects an object literal");const a=z(o),l=r.getArguments()[1],d=l&&i.isObjectLiteralExpression(l)?F(l):[],m=He(r,a,n);st(a,r.getArguments()[2]);const T=[...a.flatMap(p=>p.vectorIndexes),...d,...m],R=new Set(a.filter(p=>p.shardMode==="global").map(p=>p.name)),I=T.find(p=>R.has(p.table));if(I)throw c(r,Z(I.table,I.name));return{jurisdiction:Ye(r),...et(r)?{jurisdictionPinsAuth:!0}:{},rlsMode:nt(r),tables:a,vectorIndexes:T}};export{ht as default};
@@ -1 +0,0 @@
1
- import"./SCHEMA_SNAPSHOT_VERSION-BdxZuSxk.mjs";import"./isD1GlobalTable-udvHAAzD.mjs";import"./json-data-Chfs2Cz5.mjs";import{e as d}from"./shard-L3gYZnC9.mjs";import"./shard-runtime-lkQU8trx.mjs";import"./shared-A1XHcT4t.mjs";import"./platform-8oj7iXQy.mjs";import"./schema-BgM8A3XV.mjs";export{d as default};
@@ -1 +0,0 @@
1
- import{LunoraError as d}from"@lunora/errors";import{Node as s,SyntaxKind as k}from"ts-morph";import{d as I}from"./declared-output-Iaar469J.mjs";import{findObjectProperty as f,bindingKeyName as C,listLunoraSourceFiles as F,lunoraRelativePath as R}from"./isTestPath-JdN4KXhV.mjs";import{e as _,i as V}from"./attribution-CTMkuBkn.mjs";import{u as N,p as z,c as A,r as $}from"./unwrap-handler-return-eQRIZSOX.mjs";import{m as j}from"./ip-reads-BVXbFgzV.mjs";import{b as v,s as D,c as M}from"./classify-procedure-call-DtqiTjPg.mjs";import{r as O,p as S,a as H}from"./parse-validator-BisfC8bR.mjs";import{s as W}from"./dispatch-namespace-DwTjD7BU.mjs";const P=t=>t!==void 0&&(s.isArrowFunction(t)||s.isFunctionExpression(t))?t:void 0,B=t=>{const i=t.getArguments()[0],e=P(i);if(e!==void 0)return e;if(i===void 0||!s.isObjectLiteralExpression(i))return;const r=f(i,"handler");return r!==void 0&&s.isPropertyAssignment(r)?P(r.getInitializer()):void 0},K=t=>{const i=t.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return"unknown";const e=f(i,"handler");if(!e||!s.isPropertyAssignment(e))return"unknown";const r=e.getInitializer();return!r||!(s.isArrowFunction(r)||s.isFunctionExpression(r))?"unknown":N(r)},q=t=>{const i=t.getArguments()[0];return!i||!(s.isArrowFunction(i)||s.isFunctionExpression(i))?"unknown":N(i)},U=t=>{let i={};for(const e of v(t)){if(e.name!=="input")continue;const r=e.call.getArguments()[0],o=r!==void 0&&s.isExpression(r)?O(r):void 0;o!==void 0&&(i={...S(o),...i})}return i},J=t=>{const i=v(t).find(r=>r.name==="output");if(!i)return;const e=i.call.getArguments()[0];return e&&s.isExpression(e)?z(i.call,()=>H(e)):void 0},x=(t,i)=>{const e=f(t,i);if(e===void 0||!s.isPropertyAssignment(e))return;const r=e.getInitializer();return r!==void 0&&s.isStringLiteral(r)?r.getLiteralValue():void 0},E=(t,i)=>{const e=f(t,i);if(e===void 0||!s.isPropertyAssignment(e))return;const r=e.getInitializer();return r!==void 0&&s.isNumericLiteral(r)?r.getLiteralValue():void 0},X=t=>{const i=f(t,"cache");if(i===void 0||!s.isPropertyAssignment(i))return;const e=i.getInitializer();if(e===void 0||!s.isObjectLiteralExpression(e))return;const r=x(e,"scope"),o=E(e,"maxAge"),n=E(e,"staleWhileRevalidate"),a=x(e,"tag"),l=x(e,"vary"),c={...o===void 0?{}:{maxAge:o},...r==="private"||r==="public"?{scope:r}:{},...n===void 0?{}:{staleWhileRevalidate:n},...a===void 0?{}:{tag:a},...l===void 0?{}:{vary:l}};return Object.keys(c).length===0?void 0:c},G=t=>{if(t===void 0||!s.isObjectLiteralExpression(t))return{};const i=X(t),e=f(t,"rest");return e!==void 0&&s.isPropertyAssignment(e)?{...i===void 0?{}:{cache:i},rest:e.getInitializer()?.getText()==="true"}:i===void 0?{}:{cache:i}},Q=t=>{const i=v(t).find(e=>e.name==="expose");return i?G(i.call.getArguments()[0]):void 0},Y=t=>{const i=v(t).find(n=>n.name==="x402");if(!i)return;const e=i.call.getArguments()[0];if(e===void 0||!s.isObjectLiteralExpression(e))return{};const r=f(e,"price");if(r===void 0||!s.isPropertyAssignment(r))return{};const o=r.getInitializer();return o===void 0?{}:s.isStringLiteral(o)?{price:o.getLiteralValue()}:s.isNumericLiteral(o)?{price:o.getLiteralValue()}:{}},Z=t=>{const i=t.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return{};const e=f(i,"args");if(!e||!s.isPropertyAssignment(e))return{};const r=e.getInitializer(),o=r===void 0?void 0:O(r);return o===void 0?{}:S(o)},p=(t,i)=>{throw new d("INTERNAL",`@lunora/codegen: lazy function registry needs literal ${i} in ${t.getSourceFile().getFilePath()}:${String(t.getStartLineNumber())}`)},b=(t,i,e)=>{if(!t||!s.isObjectLiteralExpression(t))return p(i,"metadata objects");const r=new Set;for(const o of t.getProperties()){if(!s.isPropertyAssignment(o))return p(o,"metadata fields without spreads, getters, or shorthand");const n=o.getNameNode(),a=s.isStringLiteral(n)?n.getLiteralValue():n.getText();if(!s.isIdentifier(n)&&!s.isStringLiteral(n)||!e.includes(a)||r.has(a))return p(o,"supported, unique metadata fields");r.add(a)}return t},g=(t,i)=>{const e=t.getProperty(i);return e&&s.isPropertyAssignment(e)?e.getInitializer():void 0},ee=t=>{const i=b(t,t,["credentialHeaders","maxAge","scope","staleWhileRevalidate","tag","vary"]),e={};for(const n of["maxAge","staleWhileRevalidate"]){const a=g(i,n);if(!(a===void 0&&n!=="maxAge")){if(!a||!s.isNumericLiteral(a))return p(t,`cache.${n}`);e[n]=a.getLiteralValue()}}const r=g(i,"scope");if(!r||!s.isStringLiteral(r)||!["private","public"].includes(r.getLiteralValue()))return p(t,"cache.scope");e.scope=r.getLiteralValue();for(const n of["tag","vary"]){const a=g(i,n);if(a!==void 0){if(!s.isStringLiteral(a))return p(a,`cache.${n}`);e[n]=a.getLiteralValue()}}const o=g(i,"credentialHeaders");if(o!==void 0){if(!s.isArrayLiteralExpression(o))return p(o,"cache.credentialHeaders");e.credentialHeaders=o.getElements().map(n=>s.isStringLiteral(n)?n.getLiteralValue():p(n,"cache.credentialHeaders string entries"))}return e},te=t=>{const i=b(t.getArguments()[0],t,["rest","cache"]),e=g(i,"rest"),r=g(i,"cache");return e!==void 0&&!s.isTrueLiteral(e)&&!s.isFalseLiteral(e)?p(e,".expose({ rest })"):{...e?{rest:s.isTrueLiteral(e)}:{},...r?{cache:ee(r)}:{}}},ie=t=>{const i=b(t.getArguments()[0],t,["price"]),e=g(i,"price");return!e||!s.isStringLiteral(e)&&!s.isNumericLiteral(e)?p(t,"`.x402({ price })` value"):{price:e.getLiteralValue()}},re=t=>{const{factory:i,steps:e}=D(t);if(!i)return p(t,"metadata from a resolvable Lunora factory root");const r={visibility:i.startsWith("internal")?"internal":"public"};for(const{call:o,name:n}of e){if(!["expose","input","meta","output","use","x402"].includes(n))return p(o,`known builder modifiers, got .${n}()`);n==="expose"&&r.expose===void 0&&(r.expose=te(o)),n==="x402"&&r.x402===void 0&&(r.x402=ie(o))}return r},ne=8,h=(t,i=0)=>{if(i>ne)return;if(s.isCallExpression(t))return t;if(s.isParenthesizedExpression(t)||s.isAsExpression(t)||s.isSatisfiesExpression(t)||s.isNonNullExpression(t))return h(t.getExpression(),i+1);if(!s.isIdentifier(t)&&!s.isPropertyAccessExpression(t))return;const e=t.getSymbol()?.getValueDeclaration();return e?L(e,i+1):void 0},L=(t,i)=>{if(s.isVariableDeclaration(t)||s.isPropertyAssignment(t)){const e=t.getInitializer();return e?h(e,i):void 0}if(s.isShorthandPropertyAssignment(t)){const e=t.getValueSymbol()?.getValueDeclaration();return e?L(e,i+1):void 0}if(s.isBindingElement(t)){const e=C(t),n=t.getFirstAncestorByKind(k.VariableDeclaration)?.getInitializer()?.getType().getProperty(e)?.getValueDeclaration();return n?L(n,i+1):void 0}},se=(t,i=()=>!0)=>{const e=t.getNameNode();if(s.isObjectBindingPattern(e)){const n=[];for(const a of e.getElements().filter(l=>i(l.getName()))){const l=h(a.getNameNode());l&&n.push([a.getName(),l])}return n}if(!i(t.getName()))return[];const r=t.getInitializer(),o=r&&(s.isCallExpression(r)?r:h(r));return o?[[t.getName(),o]]:[]},oe=t=>{const i=t.getArguments()[0],e=s.isObjectLiteralExpression(i)?i.getProperty("name"):void 0,r=s.isPropertyAssignment(e)?e.getInitializer():void 0;if(!r||!s.isStringLiteral(r))throw new d("ROOM_NAME_NOT_LITERAL",'defineRoom needs a string-literal `name` (e.g. `defineRoom({ name: "chat", … })`) so codegen can type its reference.');return r.getLiteralValue()},ae=t=>t.startsWith("/")&&new URL(t,"https://lunora.invalid").pathname===t&&t!=="/_lunora"&&!t.startsWith("/_lunora/"),ce=t=>{const i=t.getArguments()[0];if(!s.isObjectLiteralExpression(i))throw new d("SOCKET_PATH_NOT_LITERAL","defineWebSocket needs an object-literal options argument so codegen can read its `path` and `auth`.");const e=i.getProperty("path"),r=s.isPropertyAssignment(e)?e.getInitializer():void 0;if(!r||!s.isStringLiteral(r))throw new d("SOCKET_PATH_NOT_LITERAL",'defineWebSocket needs a string-literal `path` (e.g. `defineWebSocket({ path: "/chat", … })`) so codegen can route its upgrade.');const o=r.getLiteralValue();if(!ae(o))throw new d("SOCKET_PATH_INVALID",`defineWebSocket path "${o}" must be a plain URL path starting with "/" (no "?", "#", ".." or unencoded characters) and not under "/_lunora".`);if(i.getProperties().some(c=>s.isSpreadAssignment(c)||s.isPropertyAssignment(c)&&s.isComputedPropertyName(c.getNameNode())))throw new d("SOCKET_AUTH_NOT_LITERAL","defineWebSocket cannot spread its options or use a computed key: codegen must read `auth` as a literal `auth: true` or `auth: false`.");const a=i.getProperty("auth");if(a===void 0)return{auth:!1,path:o};const l=s.isPropertyAssignment(a)?a.getInitializer():void 0;if(l===void 0||!(s.isTrueLiteral(l)||s.isFalseLiteral(l)))throw new d("SOCKET_AUTH_NOT_LITERAL","defineWebSocket needs a literal `auth: true` or `auth: false`, so codegen can read whether the route requires a session. A shorthand or a variable is not read.");return{auth:s.isTrueLiteral(l),path:o}},le=(t,i,e,r)=>{const o=r?re(i):void 0,n=r?o?.expose:Q(i),a=r?o?.x402:Y(i),l=A(()=>J(i)),c=A(()=>q(t)),u=I({kind:e.kind,output:l.value});return $(u?l.erased:c.erased),{args:U(i),...n?{expose:n}:{},...a?{x402:a}:{},...e.adminOnly?{adminOnly:!0}:{},kind:e.kind,...l.value?{output:l.value}:{},returnType:c.value,visibility:o?.visibility==="internal"||e.visibility==="internal"?"internal":"public"}},ue=(t,i)=>{const e=M(t,i);if(!e)return;if(e.channel)return{args:{},channel:{kind:e.channel,name:oe(t)},kind:e.kind,returnType:"void",visibility:e.visibility};const{receiver:r}=e;return r?le(t,r,e,i):e.lifecycle?{args:{},kind:e.kind,lifecycle:e.lifecycle,returnType:"void",...e.lifecycle==="socket"?{socket:{...ce(t),origin:`${t.getSourceFile().getFilePath()}@${String(t.getStart())}`}}:{},visibility:e.visibility}:{args:Z(t),kind:e.kind,returnType:K(t),visibility:e.visibility}},T=t=>{const i=t?.getJsDocs().at(-1)?.getDescription().trim();return i===""?void 0:i},pe=t=>T(t.getFirstAncestor(i=>s.isVariableStatement(i))),de=(t,i)=>T(t.getVariableStatements().find(e=>e.isExported()&&e.getDeclarations().some(r=>r.getName()===i))),w=(t,i,e,r,o)=>{const n=ue(t,r);if(!n)return;const a=o??pe(t);return{args:n.args,...a?{description:a}:{},exportName:i,filePath:e,kind:n.kind,returnType:n.returnType,...n.output?{output:n.output}:{},visibility:n.visibility,...n.adminOnly?{adminOnly:!0}:{},...n.kind==="query"&&(B(t)===void 0||j(t))?{readsIp:!0}:{},...n.expose?{expose:n.expose}:{},...n.x402?{x402:n.x402}:{},...n.lifecycle?{lifecycle:n.lifecycle}:{},...n.channel?{channel:n.channel}:{},...n.socket?{socket:n.socket}:{}}},fe=(t,i,e)=>{const r=[];for(const o of t.getExportAssignments()){if(o.isExportEquals())continue;const n=h(o.getExpression()),a=n?w(n,"default",i,e):void 0;n&&a&&r.push({call:n,entry:a})}return r},me=(t,i,e)=>{const r=_(t),o=new Map,n=(c,u)=>{if(c?.channel?.kind!=="room")return;const m=o.get(c.channel.name);if(m!==void 0&&m!==u)throw new d("DUPLICATE_ROOM_NAME",`Duplicate room name "${c.channel.name}" in ${i}: two defineRoom calls share it. Room names must be unique.`);o.set(c.channel.name,u)},a=t.getVariableStatements().flatMap(c=>c.getDeclarations()).flatMap(c=>se(c,u=>r.has(u))).flatMap(([c,u])=>(r.get(c)??[]).filter(m=>V(m)).flatMap(m=>{const y=w(u,m,i,e,de(t,m));return n(y,u),y?[y]:[]})),l=new Set(a.map(c=>c.exportName));for(const{call:c,entry:u}of fe(t,i,e))l.has(u.exportName)||(n(u,c),a.push(u));return a},ge=t=>{const i=new Map;for(const e of t){if(e.channel?.kind!=="room")continue;const r=i.get(e.channel.name);if(r!==void 0&&r.file!==e.filePath)throw new d("DUPLICATE_ROOM_NAME",`Duplicate room name "${e.channel.name}": defined in ${r.origin} and ${e.filePath}:${e.exportName}. Room names must be unique across the project.`);r===void 0&&i.set(e.channel.name,{file:e.filePath,origin:`${e.filePath}:${e.exportName}`})}},he=t=>{const i=new Map;for(const e of t){const r=W(e.filePath),o=i.get(r);if(o&&o!==e.filePath)throw Object.assign(new Error(`Namespace collision: "${o}" 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:[o,e.filePath],status:500});i.set(r,e.filePath)}},Se=(t,i,e={})=>{const r=F(i),o=[];for(const n of r){const a=t.getSourceFile(n)??t.addSourceFileAtPath(n),l=R(i,n);o.push(...me(a,l,e.lazyFunctions===!0))}return o.sort((n,a)=>`${n.filePath}:${n.exportName}`.localeCompare(`${a.filePath}:${a.exportName}`)),he(o),ge(o),o};export{Se as d,P as i,B as p};