@lunora/codegen 1.0.0-alpha.70 → 1.0.0-alpha.71

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.
@@ -1,4 +1,4 @@
1
- import{d as S,w as D}from"./emit-Bp0nOR_O.mjs";const E=e=>`has${e.charAt(0).toUpperCase()}${e.slice(1)}`,m=S.map(({appMethod:e,key:t})=>[E(t),e.method,e.configKey,e.doc]),v=e=>m.some(([t])=>e[t]),A=e=>e?['import * as lunoraIdentityContract from "../identity.js";']:[],x=(e,t)=>e?['import type { CreateAccessResolverOptions } from "@lunora/cloudflare-access";',`import { createAccessResolver${t?", composeResolvers":""} } from "@lunora/cloudflare-access";`]:[],R=e=>e?['import { createKvIntrospectorFromEnv } from "@lunora/bindings/kv";']:[],O=e=>e?['import notifyConfig from "../notify.js";']:[],k=e=>(e.emailAgents?.length??0)>0,C=e=>k(e)?['import { dispatchAgentEmail } from "@lunora/agent/inbound";']:[],j=e=>k(e)?['import * as lunoraAgentDefinitions from "../agents.js";']:[],L=e=>{const{hasAccess:t,hasAuth:r,hasFramework:a,hasGlobal:n,hasHyperdriveGlobal:o,hasKv:l,hasQueue:s,hasScheduler:u,hasStorage:d,hasWorkflow:h,useUmbrella:c,wantsOpenApi:p,wantsOpenRpc:b}=e,i=c?"lunorash/runtime":"@lunora/runtime",g=["ExecutionContextLike","LunoraWorker","Route","ScheduledControllerLike","ShardNamespaceLike","WorkerOptions"];n&&g.push("GlobalIntrospector"),a&&g.push("FrameworkHostHandler");const f=[...n||o?["createCrossShardRelationCapabilities"]:[],"createWorker","resolveLogArchiveFromEnv",...a?["withFrameworkWorker"]:[]].join(", ");return[...r?['import type { LunoraAuth, LunoraAuthOptions } from "@lunora/auth";','import { createAuth, createAuthAdmin, createAuthAuditReader, createDoAuthWiring, d1Executor, ensureMigrated, handleAuthRequest, lunoraD1Adapter } from "@lunora/auth";']:[],...x(t,r),...n?['import type { D1CtxDbOptions, D1DatabaseLike, D1Exec } from "@lunora/d1";','import { createD1CtxDb, facetGlobalColumn, listGlobalTables, readGlobalTablePage } from "@lunora/d1";']:[],...o?['import type { HyperdriveEngine } from "@lunora/hyperdrive/global";','import { createHyperdriveGlobalCtxDb } from "@lunora/hyperdrive/global";','import type { SqlCtxDbOptions, SqlExec } from "@lunora/sql-store";']:[],...R(l),...u?['import type { DurableObjectNamespaceLike } from "@lunora/scheduler";','import { createScheduler } from "@lunora/scheduler";']:[],...d?['import type { R2BucketLike, Storage } from "@lunora/storage";','import { createBucketStorage, createStorage } from "@lunora/storage";']:[],...h?['import { createWorkflowsRestClient } from "@lunora/workflow";']:[],...C(e),`import type { ${[...g].toSorted((w,y)=>w.localeCompare(y)).join(", ")} } from "${i}";`,`import { ${f} } from "${i}";`,"",...A(e.identity),...j(e),...n||o?['import schema from "../schema.js";']:[],...O(e.hasNotify),'import { LUNORA_CRONS } from "./crons.js";','import { LUNORA_FUNCTIONS } from "./functions.js";',...s?['import { createQueueCaptureSink, dispatchQueueBatch, shouldCaptureQueue } from "@lunora/queue";','import { LUNORA_QUEUE_REGISTRY } from "./queues.js";']:[],...p?['import { openApiSpec } from "./openapi.js";']:[],...b?['import { openRpcSpec } from "./openrpc.js";']:[],'import { createShardDO } from "./shard.js";']},q=e=>[...e.hasStorage?[`/** \`.storage(...)\` declaration — one bucket (required) plus optional extra named buckets and signed-URL config. Backs \`ctx.storage\` AND the studio file browser. */
1
+ import{f as S,w as D}from"./emit-D7VIjvlm.mjs";const E=e=>`has${e.charAt(0).toUpperCase()}${e.slice(1)}`,m=S.map(({appMethod:e,key:t})=>[E(t),e.method,e.configKey,e.doc]),v=e=>m.some(([t])=>e[t]),A=e=>e?['import * as lunoraIdentityContract from "../identity.js";']:[],x=(e,t)=>e?['import type { CreateAccessResolverOptions } from "@lunora/cloudflare-access";',`import { createAccessResolver${t?", composeResolvers":""} } from "@lunora/cloudflare-access";`]:[],R=e=>e?['import { createKvIntrospectorFromEnv } from "@lunora/bindings/kv";']:[],O=e=>e?['import notifyConfig from "../notify.js";']:[],k=e=>(e.emailAgents?.length??0)>0,C=e=>k(e)?['import { dispatchAgentEmail } from "@lunora/agent/inbound";']:[],j=e=>k(e)?['import * as lunoraAgentDefinitions from "../agents.js";']:[],L=e=>{const{hasAccess:t,hasAuth:r,hasFramework:a,hasGlobal:n,hasHyperdriveGlobal:o,hasKv:l,hasQueue:s,hasScheduler:u,hasStorage:d,hasWorkflow:h,useUmbrella:c,wantsOpenApi:p,wantsOpenRpc:b}=e,i=c?"lunorash/runtime":"@lunora/runtime",g=["ExecutionContextLike","LunoraWorker","Route","ScheduledControllerLike","ShardNamespaceLike","WorkerOptions"];n&&g.push("GlobalIntrospector"),a&&g.push("FrameworkHostHandler");const f=[...n||o?["createCrossShardRelationCapabilities"]:[],"createWorker","resolveLogArchiveFromEnv",...a?["withFrameworkWorker"]:[]].join(", ");return[...r?['import type { LunoraAuth, LunoraAuthOptions } from "@lunora/auth";','import { createAuth, createAuthAdmin, createAuthAuditReader, createDoAuthWiring, d1Executor, ensureMigrated, handleAuthRequest, lunoraD1Adapter } from "@lunora/auth";']:[],...x(t,r),...n?['import type { D1CtxDbOptions, D1DatabaseLike, D1Exec } from "@lunora/d1";','import { createD1CtxDb, facetGlobalColumn, listGlobalTables, readGlobalTablePage } from "@lunora/d1";']:[],...o?['import type { HyperdriveEngine } from "@lunora/hyperdrive/global";','import { createHyperdriveGlobalCtxDb } from "@lunora/hyperdrive/global";','import type { SqlCtxDbOptions, SqlExec } from "@lunora/sql-store";']:[],...R(l),...u?['import type { DurableObjectNamespaceLike } from "@lunora/scheduler";','import { createScheduler } from "@lunora/scheduler";']:[],...d?['import type { R2BucketLike, Storage } from "@lunora/storage";','import { createBucketStorage, createStorage } from "@lunora/storage";']:[],...h?['import { createWorkflowsRestClient } from "@lunora/workflow";']:[],...C(e),`import type { ${[...g].toSorted((w,y)=>w.localeCompare(y)).join(", ")} } from "${i}";`,`import { ${f} } from "${i}";`,"",...A(e.identity),...j(e),...n||o?['import schema from "../schema.js";']:[],...O(e.hasNotify),'import { LUNORA_CRONS } from "./crons.js";','import { LUNORA_FUNCTIONS } from "./functions.js";',...s?['import { createQueueCaptureSink, dispatchQueueBatch, shouldCaptureQueue } from "@lunora/queue";','import { LUNORA_QUEUE_REGISTRY } from "./queues.js";']:[],...p?['import { openApiSpec } from "./openapi.js";']:[],...b?['import { openRpcSpec } from "./openrpc.js";']:[],'import { createShardDO } from "./shard.js";']},q=e=>[...e.hasStorage?[`/** \`.storage(...)\` declaration — one bucket (required) plus optional extra named buckets and signed-URL config. Backs \`ctx.storage\` AND the studio file browser. */
2
2
  interface StorageDeclaration<Env> {
3
3
  /** The default R2 bucket binding (the bare \`ctx.storage\`). */
4
4
  bucket: Selector<Env, R2BucketLike>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.70",
3
+ "version": "1.0.0-alpha.71",
4
4
  "description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -46,8 +46,8 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@lunora/advisor": "1.0.0-alpha.49",
50
- "@lunora/agent": "1.0.0-alpha.25",
49
+ "@lunora/advisor": "1.0.0-alpha.50",
50
+ "@lunora/agent": "1.0.0-alpha.26",
51
51
  "@lunora/container": "1.0.0-alpha.16",
52
52
  "@lunora/errors": "1.0.0-alpha.8",
53
53
  "@lunora/queue": "1.0.0-alpha.10",
@@ -1 +0,0 @@
1
- import"@lunora/agent/component";import"@lunora/errors";import{w as m,X as r,B as o,s as n,c as l,_ as c,t as g,H as p,e as u,b as C,j as E,l as S,h as d,J as A,n as D,M as h,r as b}from"./emit-Bp0nOR_O.mjs";import"./paths-BmX5O1sG.mjs";export{m as GENERATED_HEADER,r as buildStorageColumns,o as emitAgents,n as emitApi,l as emitCollections,c as emitContainers,g as emitCrons,p as emitDataModel,u as emitDrizzleSchema,C as emitFunctions,E as emitQueues,S as emitSeed,d as emitServer,A as emitShard,D as emitVectors,h as emitWorkflows,b as emitWranglerCronTriggers};
@@ -1 +0,0 @@
1
- import{LunoraError as j}from"@lunora/errors";import{Node as s,SyntaxKind as w}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{d as N}from"./parse-validator-CSDlMEvE.mjs";import{createRequire as T}from"node:module";import{join as O}from"node:path";const _=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}},$=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}:{}}),f=e=>{const t=e?._meta??{},r=e?.kind??"unknown",n={column:$(t.column),kind:r};switch(r){case"array":case"optional":{n.inner=f(t.inner);break}case"id":{n.tableName=t.tableName;break}case"literal":{n.literalValue=_(t.value);break}case"object":{const i=t.shape??{};n.shape=Object.fromEntries(Object.entries(i).map(([o,a])=>[o,f(a)]));break}case"record":{n.valueType=f(t.valueValidator),t.keyValidator!==void 0&&(n.keyType=f(t.keyValidator));break}case"storage":{typeof t.bucket=="string"&&(n.bucket=t.bucket);break}case"union":{const i=t.members??[];n.members=i.map(o=>f(o));break}}return n},M=e=>e?.kind==="global"?"global":e?.kind==="shardBy"&&typeof e.field=="string"?{field:e.field,kind:"shardBy"}:"root",z=(e,t)=>{const r=[];e.relationMap&&Object.keys(e.relationMap).length>0&&r.push("relations"),e.rankIndexes&&e.rankIndexes.length>0&&r.push("rank indexes"),e.vectorIndexes&&e.vectorIndexes.length>0&&r.push("vector indexes"),r.length>0&&console.warn(`@lunora/codegen: package schema-extension table "${t}" declares ${r.join(" + ")}, which are not yet introspected from a node_modules extension — they will be absent from the generated types.`)},D=(e,t)=>{const r=e.shape??{},n=(e.indexes??[]).map(i=>({fields:i.fields,name:i.name,...i.unique?{unique:!0}:{}}));return z(e,t),{...e.isExternallyManaged?{externallyManaged:!0}:{},geoIndexes:[],indexes:n,name:t,rankIndexes:[],relations:[],searchIndexes:(e.searchIndexes??[]).map(i=>({field:i.field,...i.filterFields?{filterFields:i.filterFields}:{},name:i.name})),shape:Object.fromEntries(Object.entries(r).map(([i,o])=>[i,f(o)])),shardMode:M(e.shardMode),vectorIndexes:[]}},B=e=>{const{key:t,tables:r}=e;if(typeof t!="string"||typeof r!="object"||r===null)return;const n=Object.entries(r).map(([a,l])=>D(l,a)),i=e.vectorIndexes??{},o=Object.entries(i??{}).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:n,bareVectorIndexes:o,key:t}},q=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e)){const t=e.getExpression();return s.isIdentifier(t)?t.getText():void 0}},F=e=>{const t=q(e);if(t===void 0)return;const r=s.isPropertyAccessExpression(e)?e.getName():void 0,n=r===void 0?[]:[r];for(const i of e.getSourceFile().getImportDeclarations()){const o=i.getModuleSpecifierValue();for(const a of i.getNamedImports())if((a.getAliasNode()?.getText()??a.getName())===t)return{importedName:a.getName(),moduleSpecifier:o,propertyPath:n};if(i.getDefaultImport()?.getText()===t)return{importedName:"default",moduleSpecifier:o,propertyPath:n};if(i.getNamespaceImport()?.getText()===t&&r!==void 0)return{importedName:r,moduleSpecifier:o,propertyPath:[]}}},C=(e,t)=>{let r=e[t.importedName];for(const n of t.propertyPath){if(typeof r!="object"||r===null)return;r=r[n]}return r},V=(e,t)=>{const r=F(e);if(r)try{const n=T(O(t,"noop.cjs")),i=n.resolve(r.moduleSpecifier),o=n(i),a=C(o,r);return typeof a!="object"||a===null?void 0:B(a)}catch{return}},R=new Set(["cosine","dot-product","euclidean"]),J=new Set(["cascade","restrict","set null"]),E=new Set(["delete","get","insert","normalizeId","patch","query","replace","system"]),K=(e,t)=>{if(E.has(e))throw g(t,`table name "${e}" is reserved — it collides with a \`ctx.db\` member (one of ${[...E].map(r=>`"${r}"`).join(", ")}). Rename the table.`)},c=(e,t)=>{const r=e.getProperty(t);if(r&&s.isPropertyAssignment(r)){const n=r.getInitializer();if(n&&s.isStringLiteral(n))return n.getLiteralText()}},m=(e,t)=>{const r=e.getProperty(t);if(r&&s.isPropertyAssignment(r)){const n=r.getInitializer();if(n&&s.isNumericLiteral(n))return Number(n.getLiteralText())}},h=(e,t)=>{const r=e.getProperty(t);if(r&&s.isPropertyAssignment(r)){const n=r.getInitializer();if(n&&s.isArrayLiteralExpression(n))return n.getElements().filter(i=>s.isStringLiteral(i)).map(i=>i.getLiteralText())}},v=e=>e&&R.has(e)?e:void 0,U=e=>e&&J.has(e)?e:void 0,G=e=>{if(!s.isArrowFunction(e))return;let t=e.getBody();if(s.isParenthesizedExpression(t))t=t.getExpression();else if(s.isBlock(t)){const r=t.getStatements().find(n=>s.isReturnStatement(n));t=r&&s.isReturnStatement(r)?r.getExpression()??t:t}return s.isObjectLiteralExpression(t)?t:void 0},H=e=>{if(!s.isPropertyAssignment(e))return;const t=e.getInitializer();if(!t||!s.isCallExpression(t))return;const r=t.getExpression();if(!s.isPropertyAccessExpression(r))return;const n=r.getName();if(n!=="one"&&n!=="many")return;const[i,o]=t.getArguments(),a=i&&s.isStringLiteral(i)?i.getLiteralText():"_unknown_";let l="_unknown_",d="_id",u;return o&&s.isObjectLiteralExpression(o)&&(l=c(o,"field")??l,d=c(o,"references")??d,u=n==="one"?U(c(o,"onDelete")):void 0),{field:l,kind:n,name:e.getName(),onDelete:u,references:d,table:a}},Q=e=>{const t=G(e);if(!t)return[];const r=[];for(const n of t.getProperties()){const i=H(n);i&&r.push(i)}return r},x=e=>e&&s.isStringLiteral(e)?e.getLiteralText():"_unnamed_",W=e=>{const[t,r,n]=e;let i=!1;if(n&&s.isObjectLiteralExpression(n)){const o=n.getProperty("unique");if(o&&s.isPropertyAssignment(o)){const a=o.getInitializer();if(a&&!s.isTrueLiteral(a)&&!s.isFalseLiteral(a))throw g(a,`\`unique\` must be a literal \`true\` or \`false\`, got ${JSON.stringify(a.getText())}`);i=a?s.isTrueLiteral(a):!1}}return{fields:r&&s.isArrayLiteralExpression(r)?r.getElements().filter(o=>s.isStringLiteral(o)).map(o=>o.getLiteralText()):[],name:x(t),unique:i}},X=e=>{const[t,r]=e;let n="_unknown_",i;return r&&s.isObjectLiteralExpression(r)&&(n=c(r,"field")??n,i=h(r,"filterFields")),{field:n,filterFields:i,name:x(t)}},Y=e=>{const[t,r]=e;let n="_unknown_",i;return r&&s.isObjectLiteralExpression(r)&&(n=c(r,"field")??n,i=m(r,"precision")),{field:n,name:x(t),precision:i}},Z=e=>{const[t,r]=e,n=t&&s.isStringLiteral(t)?t.getLiteralText():"_unknown_";let i;return r&&s.isObjectLiteralExpression(r)&&(i=m(r,"after")),{after:i,field:n}},ee=e=>{if(!s.isObjectLiteralExpression(e))return;const t=c(e,"field");return t===void 0?void 0:{direction:c(e,"direction")==="desc"?"desc":"asc",field:t}},te=e=>{const[t,r]=e;let n=[],i;if(r&&s.isObjectLiteralExpression(r)){const o=r.getProperty("sortBy");if(o&&s.isPropertyAssignment(o)){const a=o.getInitializer();a&&s.isArrayLiteralExpression(a)&&(n=a.getElements().map(l=>ee(l)).filter(l=>l!==void 0))}i=h(r,"partitionBy")}return{name:x(t),partitionBy:i,sortBy:n}},re=(e,t)=>{const[r,n]=e,i=r&&s.isStringLiteral(r)?r.getLiteralText():"_unknown_";if(!(!n||!s.isObjectLiteralExpression(n)))return{dimensions:m(n,"dimensions"),field:i,metadata:h(n,"metadata"),metric:v(c(n,"metric")),name:c(n,"index")??"_unnamed_",table:t}},ne=e=>{const t=e[0];return t&&s.isObjectLiteralExpression(t)&&c(t,"backend")==="hyperdrive"?"hyperdrive":"d1"},ie=e=>{if(e&&s.isObjectLiteralExpression(e)){const t=e.getProperty("field");if(t&&s.isPropertyAssignment(t)){const r=t.getInitializer();if(r&&s.isStringLiteral(r))return r.getLiteralText()}}return"deletedAt"},p=(e,t)=>{const r=e.getProperty(t);if(r&&s.isPropertyAssignment(r)){const n=r.getInitializer();if(n&&s.isStringLiteral(n))return n.getLiteralText()}},se=(e,t)=>{const r=e.getProperty(t);if(r&&s.isPropertyAssignment(r)){const n=r.getInitializer();if(n&&s.isArrayLiteralExpression(n)){const i=n.getElements().filter(o=>s.isStringLiteral(o)).map(o=>o.getLiteralText());return i.length>0?i:void 0}}},oe=e=>{const t=e[0];return!t||!s.isObjectLiteralExpression(t)?{binding:"",hasTenantBy:!1,unanalyzable:!0}:{binding:p(t,"binding")??"",columns:se(t,"columns"),hasReconcile:t.getProperty("reconcileEveryMs")!==void 0,hasSoftDelete:t.getProperty("softDeleteColumn")!==void 0,hasTenantBy:t.getProperty("tenantBy")!==void 0,idColumn:p(t,"idColumn"),mode:p(t,"mode"),query:p(t,"query")}},ae=(e,t,r,n)=>{switch(t){case"externallyManaged":{e.externallyManaged=!0;break}case"geoIndex":{e.geoIndexes.push(Y(r));break}case"global":{e.shardMode="global",e.globalBackend=ne(r);break}case"index":{e.indexes.push(W(r));break}case"public":{e.isPublic=!0;break}case"rankIndex":{e.rankIndexes.push(te(r));break}case"relations":{const i=r[0];i&&e.relations.push(...Q(i));break}case"searchIndex":{e.searchIndexes.push(X(r));break}case"shardBy":{const i=r[0];e.shardMode={field:i&&s.isStringLiteral(i)?i.getLiteralText():"_unknown_",kind:"shardBy"};break}case"softDelete":{e.softDelete={field:ie(r[0])};break}case"source":{e.externalSource=oe(r),e.externallyManaged=!0;break}case"ttl":{e.ttl=Z(r);break}case"vectorize":{const i=re(r,n);i&&e.vectorIndexes.push(i);break}}},L=(e,t)=>{const r={externallyManaged:!1,geoIndexes:[],indexes:[],isPublic:!1,rankIndexes:[],relations:[],searchIndexes:[],shardMode:"root",vectorIndexes:[]};let n={},i=e;for(;s.isCallExpression(i);){const o=i.getExpression(),a=i.getArguments();if(s.isPropertyAccessExpression(o))ae(r,o.getName(),a,t),i=o.getExpression();else if(s.isIdentifier(o)&&o.getText()==="defineTable"){const l=a[0];l&&s.isObjectLiteralExpression(l)&&(n=N(l));break}else break}return r.softDelete&&!(r.softDelete.field in n)&&(n={...n,[r.softDelete.field]:{inner:{kind:"number"},kind:"optional"}}),{externallyManaged:r.externallyManaged,externalSource:r.externalSource,geoIndexes:r.geoIndexes,globalBackend:r.shardMode==="global"?r.globalBackend??"d1":void 0,indexes:r.indexes,isPublic:r.isPublic,name:t,rankIndexes:r.rankIndexes,relations:r.relations,searchIndexes:r.searchIndexes,shape:n,shardMode:r.shardMode,softDelete:r.softDelete,ttl:r.ttl,vectorIndexes:r.vectorIndexes}},le=e=>{const t=e.getProperty("source");if(t&&s.isPropertyAssignment(t)){const r=t.getInitializer();if(r&&s.isObjectLiteralExpression(r))return c(r,"table")??"_unknown_"}return"_unknown_"},ce=e=>{if(!s.isPropertyAssignment(e))return;const t=e.getInitializer();if(!t||!s.isCallExpression(t))return;const r=t.getExpression();if(!s.isIdentifier(r)||r.getText()!=="defineVectorIndex")return;const n=t.getArguments()[0];if(!n||!s.isObjectLiteralExpression(n))return;const i=e.getNameNode(),o=s.isStringLiteral(i)?i.getLiteralText():i.getText();return{dimensions:m(n,"dimensions"),metric:v(c(n,"metric")),name:o,table:le(n)}},P=e=>{const t=[];for(const r of e.getProperties()){const n=ce(r);n&&t.push(n)}return t},k=(e,t)=>`${e}_${t}`,y=(e,t,r)=>r.has(e)?k(t,e):e,de=(e,t,r)=>{const n=k(t,e.name);return{...e,extensionKey:t,name:n,relations:e.relations.map(i=>({...i,table:y(i.table,t,r)})),vectorIndexes:e.vectorIndexes.map(i=>({...i,table:y(i.table,t,r)}))}},ue=e=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e))return e.getInitializer();if(s.isShorthandPropertyAssignment(e))return e.getNameNode()},fe=(e,t)=>{const r=e.getProperty(t);if(r&&s.isPropertyAssignment(r))return r.getInitializer()},ge=e=>{if(!s.isCallExpression(e))return!1;const t=e.getExpression();return s.isIdentifier(t)&&t.getText()==="defineSchemaExtension"},pe=e=>{if(s.isIdentifier(e))return e;if(s.isPropertyAccessExpression(e)){const t=e.getExpression();return s.isIdentifier(t)?t:void 0}},me=e=>{if(s.isObjectLiteralExpression(e))return e;if(s.isCallExpression(e)){const t=e.getExpression();let r;if(s.isIdentifier(t)?r=t.getText():s.isPropertyAccessExpression(t)&&(r=t.getName()),r==="definePlugin"){const n=e.getArguments()[1];return n&&s.isObjectLiteralExpression(n)?n:void 0}}},xe=(e,t)=>{const r=ue(e);if(r){if(s.isPropertyAccessExpression(t)){const n=me(r);return n?fe(n,t.getName()):void 0}return r}},be=e=>{let t=e,r=0;for(;t&&r<32;){if(r+=1,ge(t))return t;const n=pe(t),i=n&&s.isIdentifier(n)?n.getSymbol():void 0,o=(i?.getAliasedSymbol()?.getDeclarations()??i?.getDeclarations()??[])[0];if(!o)return;const a=o.getSourceFile();if(a.isInNodeModules()||a.isDeclarationFile())return;t=xe(o,t)}},ye=e=>{const[t,r]=e.getArguments();if(!(!t||!s.isStringLiteral(t))&&!(!r||!s.isObjectLiteralExpression(r)))return{key:t.getLiteralText(),options:r}},he=e=>{const t=e.getProperty("tables");if(!t||!s.isPropertyAssignment(t))return[];const r=t.getInitializer();if(!r||!s.isObjectLiteralExpression(r))return[];const n=[];for(const i of r.getProperties()){if(!s.isPropertyAssignment(i))continue;const o=i.getInitializer();o&&n.push(L(o,i.getName()))}return n},ke=e=>{const t=e.getProperty("vectorIndexes");if(!t||!s.isPropertyAssignment(t))return[];const r=t.getInitializer();return!r||!s.isObjectLiteralExpression(r)?[]:P(r)},S=(e,t,r)=>{const n=new Set(t.map(a=>a.name)),i=t.map(a=>de(a,e,n)),o=r.map(a=>({...a,name:k(e,a.name),table:y(a.table,e,n)}));return{tables:i,vectorIndexes:o}},Ie=(e,t)=>S(e,he(t),ke(t)),Ee=(e,t)=>{const r=e.getArguments()[0];if(!r)return;const n=be(r);if(!n){if(t!==void 0){const o=V(r,t);if(o)return S(o.key,o.bareTables,o.bareVectorIndexes)}console.warn(`@lunora/codegen: skipping \`.extend(${r.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 i=ye(n);if(!i){console.warn("@lunora/codegen: skipping `.extend(...)` — `defineSchemaExtension` requires a string `key` and an options object literal.");return}return Ie(i.key,i.options)},ve=e=>{const t=[];let r=e;for(;;){const n=r.getParent();if(!n||!s.isPropertyAccessExpression(n))break;const i=n.getParent();if(!i||!s.isCallExpression(i))break;n.getName()==="extend"&&t.push(i),r=i}return t},A=(e,t,r,n,i)=>{let o=e;for(;;){const a=o.getParent();if(!a||!s.isPropertyAccessExpression(a))break;const l=a.getParent();if(!l||!s.isCallExpression(l))break;if(a.getName()===t){const d=l.getArguments()[0];if(!d||!s.isStringLiteral(d))throw g(l,`\`.${t}(...)\` expects a string literal (${i})`);const u=d.getLiteralText();if(!n.has(u))throw g(d,`unknown ${r} ${JSON.stringify(u)} — expected ${i}`);return u}o=l}},Le=new Set(["eu","fedramp","us"]),Pe=e=>A(e,"jurisdiction","jurisdiction",Le,'"eu", "us", or "fedramp"'),Se=new Set(["required"]),Ae=e=>A(e,"rls","rls mode",Se,'"required"'),je=e=>{const t=[];for(const r of e.getProperties()){if(!s.isPropertyAssignment(r))continue;const n=r.getInitializer();if(n){const i=r.getName();K(i,r.getNameNode()),t.push(L(n,i))}}return t},we=(e,t,r)=>{const n=new Set(t.map(o=>o.name)),i=[];for(const o of ve(e)){const a=Ee(o,r);if(a){for(const l of a.tables){if(n.has(l.name))throw g(o,`defineSchema(...).extend(...): table "${l.name}" already exists — another extension with the same key already contributed it.`);n.add(l.name),t.push(l)}i.push(...a.vectorIndexes)}}return i},ze=(e,t,r)=>{const n=e.addSourceFileAtPath(t).getDescendantsOfKind(w.CallExpression).find(b=>{const I=b.getExpression();return s.isIdentifier(I)&&I.getText()==="defineSchema"});if(!n)throw new j("INTERNAL",`defineSchema() not found in ${t}`);const i=n.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))throw g(n,"defineSchema() expects an object literal");const o=je(i),a=n.getArguments()[1],l=a&&s.isObjectLiteralExpression(a)?P(a):[],d=we(n,o,r),u=[...o.flatMap(b=>b.vectorIndexes),...l,...d];return{jurisdiction:Pe(n),rlsMode:Ae(n),tables:o,vectorIndexes:u}};export{ze as default};