@lunora/codegen 1.0.0-alpha.77 → 1.0.0-alpha.79

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{a as S,w as D}from"./emit-sQzv_a8t.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{e as S,w as D}from"./emit-BtiV37rG.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>;
@@ -0,0 +1,2 @@
1
+ import{runAdvisor as i}from"@lunora/advisor";const n=e=>[...e.indexes.map(s=>({fields:s.fields,kind:"index",name:s.name,unique:s.unique})),...e.searchIndexes.map(s=>({fields:[s.field,...s.filterFields??[]],kind:"search",name:s.name})),...e.rankIndexes.map(s=>({fields:[...s.sortBy.map(a=>a.field),...s.partitionBy??[]],kind:"rank",name:s.name})),...e.vectorIndexes.filter(s=>s.field!==void 0).map(s=>({fields:[s.field],kind:"vector",name:s.name})),...(e.geoIndexes??[]).map(s=>({fields:[s.field],kind:"geo",name:s.name}))],r=e=>{const s={};for(const[a,t]of Object.entries(e.shape))s[a]=t.kind==="optional"?t.inner?.kind??"optional":t.kind;return s},o=e=>({rlsMode:e.rlsMode,tables:e.tables.map(s=>({externallyManaged:s.externallyManaged??!1,externalSource:s.externalSource?{hasReconcile:s.externalSource.hasReconcile??!1,hasSoftDelete:s.externalSource.hasSoftDelete??!1,hasTenantBy:s.externalSource.hasTenantBy,mode:s.externalSource.mode,unanalyzable:s.externalSource.unanalyzable}:void 0,columnKinds:r(s),fields:Object.keys(s.shape),indexes:n(s),isPublic:s.isPublic??!1,name:s.name,relations:s.relations.map(a=>({field:a.field,kind:a.kind,name:a.name,onDelete:a.onDelete,references:a.references,table:a.table})),shardKind:typeof s.shardMode=="string"?s.shardMode:"shardBy",softDelete:s.softDelete,ttl:s.ttl}))}),l=e=>e.map(s=>({exportName:s.exportName,file:`lunora/${s.filePath}.ts`,table:s.table})),c=e=>({adminRoutes:e.adminRoutes,aiRawRuns:e.aiRawRuns,aiToolSideEffects:e.aiToolSideEffects,argumentDerivedFetches:e.argumentDerivedFetches,argValidators:e.argumentValidators,authApiCalls:e.authApiCalls,authConfigs:e.authConfigs,browserUrlAccesses:e.browserUrlAccesses,configCalls:e.configCalls,containerKeyAccesses:e.containerKeyAccesses,containerOverrides:e.containerOverrides,containers:e.containers,exportSinks:e.exportSinks,failOpenGuards:e.failOpenGuards,flagSecurityDefaults:e.flagSecurityDefaults,geoIndexUsages:e.geoIndexUsages,httpActionGuards:e.httpActionGuards,httpHeaderWrites:e.httpHeaderWrites,identityClaimReads:e.identityClaimReads,imageDeliveryUrlAccesses:e.imageDeliveryUrlAccesses,inserts:e.inserts,kvKeyAccesses:e.kvKeyAccesses,mailRecipientAccesses:e.mailRecipientAccesses,maskProcedures:e.maskProcedures,maskStrategies:e.maskStrategies,mutatorWrites:e.mutatorWrites,nondeterministicCalls:e.nondeterministicCalls,normalizeIdAuthorizations:e.normalizeIdAuthorizations,notifyCalls:e.notifyCalls,notifyConfig:e.notifyConfig,ownerFieldWrites:e.ownerFieldWrites,paymentWebhooks:e.paymentWebhooks,privilegedDispatches:e.privilegedDispatches,procedureProtections:e.procedureProtections,queries:e.queries??[],queues:e.queues,r2sqlCalls:e.r2sqlCalls,ratelimitKeySelectors:e.ratelimitKeySelectors,rawRowReturns:e.rawRowReturns,relationLoads:e.relationLoads,rlsProcedures:e.rlsProcedures,schema:o(e.schema),secretLiterals:e.secretLiterals,shapes:e.shapes===void 0?void 0:l(e.shapes),softDeleteReads:e.softDeleteReads,sqlInterpolations:e.sqlInterpolations,storageKeyAccesses:e.storageKeyAccesses,storageUploads:e.storageUploads,unrestrictedWhereBranches:e.unrestrictedWhereBranches,vectorNamespaceAccesses:e.vectorNamespaceAccesses,workflowCalls:e.workflowCalls,workflows:e.workflows,wranglerVariables:e.wranglerVariables}),m=e=>i(c(e),{source:"static"}),u=e=>{if(e.length===0)return"";const s=`@lunora/codegen: ${String(e.length)} schema advisor finding${e.length===1?"":"s"}`,a=e.map(t=>` [${t.level}] ${t.name}: ${t.detail}`);return[s,...a].join(`
2
+ `)};export{u as formatAdvisories,m as lintSchema,c as toAdvisorContext};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.77",
3
+ "version": "1.0.0-alpha.79",
4
4
  "description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -46,14 +46,16 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@lunora/advisor": "1.0.0-alpha.55",
50
- "@lunora/agent": "1.0.0-alpha.31",
49
+ "@lunora/advisor": "1.0.0-alpha.57",
50
+ "@lunora/agent": "1.0.0-alpha.32",
51
51
  "@lunora/container": "1.0.0-alpha.17",
52
52
  "@lunora/errors": "1.0.0-alpha.9",
53
- "@lunora/queue": "1.0.0-alpha.11",
54
- "@lunora/scheduler": "1.0.0-alpha.13",
53
+ "@lunora/platform": "1.0.0-alpha.1",
54
+ "@lunora/queue": "1.0.0-alpha.12",
55
+ "@lunora/scheduler": "1.0.0-alpha.14",
55
56
  "@lunora/values": "1.0.0-alpha.12",
56
57
  "@lunora/workflow": "1.0.0-alpha.14",
58
+ "jsonc-parser": "^3.3.1",
57
59
  "ts-morph": "^28.0.0"
58
60
  },
59
61
  "engines": {
@@ -1 +0,0 @@
1
- import"@lunora/agent/component";import"@lunora/errors";import"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{w as r,n as o,K as n,g as l,h as g,W as p,i as c,Z as u,s as C,v as E,V as S,m as d,k as A,t as D,l as h,Q as W,c as f}from"./emit-sQzv_a8t.mjs";import"./paths-BmX5O1sG.mjs";export{r as GENERATED_HEADER,o as buildStorageColumns,n as emitAgents,l as emitApi,g as emitCollections,p as emitContainers,c as emitCrons,u as emitDataModel,C as emitDrizzleSchema,E as emitFunctions,S as emitQueues,d as emitSeed,A as emitServer,D as emitShard,h as emitVectors,W as emitWorkflows,f as emitWranglerCronTriggers};
@@ -1,3 +0,0 @@
1
- import{existsSync as E,readFileSync as $e,mkdirSync as Vt,writeFileSync as Bt,rmSync as Ut}from"node:fs";import{join as g,dirname as fe}from"node:path";import{performance as pe}from"node:perf_hooks";import{LunoraError as q}from"@lunora/errors";import{Node as i,SyntaxKind as u,Project as Ze}from"ts-morph";import{serializeSchemaSnapshot as Wt}from"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{lintSchema as Gt}from"./formatAdvisories-DZvv-0MG.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as f,classifyProcedureCall as K,inlineHandler as Ht,procedureHandler as mt,chainUsesWrappedCall as xt,isDatabaseAccessor as k,chainHasStep as _t,discoverFunctions as Qt}from"./discoverFunctions-DnqHgv0t.mjs";import{discoverAgents as Jt}from"./AGENTS_FILENAME-BesaDYkL.mjs";import Zt from"./discoverAuthApiCalls-CEk3J0kc.mjs";import{discoverContainers as Xt}from"./CONTAINERS_FILENAME-CFwdyaCI.mjs";import Yt from"./discoverCrons-kIgM9ZJC.mjs";import{diagnosticAt as H}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{o as _}from"./module-specifiers-8FEEiUcv.mjs";import{r as me,n as es,Z as ts,g as ss,k as rs,v as ns,t as is,h as os,W as as,Q as cs,K as us,V as ls,i as ds,l as gs,s as fs,m as ps,c as ms}from"./emit-sQzv_a8t.mjs";import{discoverFlagKeys as xs}from"./FLAGS_FILENAME-CQDN7BKc.mjs";import hs from"./discoverHttpRoutes-CLn3VDRI.mjs";import Es from"./discoverInserts-Cn-CLKET.mjs";import ys,{discoverMaskStrategies as As,discoverMaskMetadata as $s}from"./discoverMaskProcedures-fZtvsy8v.mjs";import Ss from"./discoverMigrations-BH_IKdFk.mjs";import{MUTATORS_FILENAME as Ns,isDefineMutatorCallee as vs,discoverMutators as bs}from"./MUTATORS_FILENAME-3Akvs4aT.mjs";import Ps from"./discoverNondeterministicCalls-Cl7qNL0J.mjs";import{discoverNotifyConfig as ws,discoverNotifyCalls as Is}from"./NOTIFY_FILENAME-B2lXWa7r.mjs";import Os from"./discoverQueries-DENx_T6c.mjs";import{discoverQueues as Ls}from"./QUEUES_FILENAME-CSE6i-ld.mjs";import Fs from"./discoverR2sqlCalls-CMNfDWlq.mjs";import Ts,{discoverRlsMetadata as Ds}from"./discoverRlsMetadata-Bf4_2S0t.mjs";import{discoverSandboxUsage as Cs}from"./discoverSandboxUsage-Bn1X9COt.mjs";import ks from"./discoverSchema-Cy4OQ0Cu.mjs";import{secretKindOf as Ks,redact as Rs}from"./redact-CQ8-to6l.mjs";import{discoverShapes as Ms}from"./SHAPES_FILENAME-maut3z1K.mjs";import js from"./discoverStorageRulesMetadata-CL8J41rX.mjs";import{e as zs}from"./discover-ast-CezKqEhE.mjs";import{discoverWorkflows as qs}from"./WORKFLOWS_FILENAME-Bk5upkGM.mjs";import{emitApp as Vs}from"./emitApp-D5X1S54W.mjs";import{buildOpenApiDocument as Bs,emitOpenApiModule as Us}from"./buildOpenApiDocument-DeMEuKaw.mjs";import{buildOpenRpcDocument as Ws,emitOpenRpcModule as Gs}from"./OPENRPC_VERSION-67sJ7JrS.mjs";import{buildSchemaSnapshot as Hs}from"./SchemaSnapshotParseError-0KRzSjo4.mjs";const ht=new Set(["delete","get","head","options","patch","post","put"]),_s=new Set(["handler","stream"]),Qs=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,Xe=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Js=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ht.has(t.getName()))return;const s=t.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpRoute")return;const r=e.getArguments()[0];if(!(!r||!i.isStringLiteral(r)))return{method:t.getName().toUpperCase(),path:r.getLiteralValue()}},Zs=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||ht.has(r.getName()))break;s=r.getExpression()}return Js(s)},Xs=e=>{for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression))if(Xe.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&Xe.has(s.getText()))return!0}return!1},Ys=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||!_s.has(r.getName()))return;const n=Zs(s);if(!n||!Qs.test(n.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&Xs(o);return{exportName:e.getName(),file:t,method:n.method,path:n.path,usesGuard:a}},er=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Ys(n,t);o&&s.push(o)}return s},tr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...er(n,f(t,r)))}return s},Ye=e=>{if(e.getText()!=="args")return!1;const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(i.isPropertyAssignment(t)&&t.getNameNode()===e)},et=e=>{if(e.getText()!=="ctx")return!1;const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(i.isPropertyAssignment(t)&&t.getNameNode()===e)},xe=e=>i.isIdentifier(e)?et(e):e.getDescendantsOfKind(u.Identifier).some(t=>et(t)),tt=(e,t)=>{if(e.getText()!==t)return!1;const s=e.getParent();return i.isPropertyAccessExpression(s)&&s.getNameNode()===e?!1:!(i.isPropertyAssignment(s)&&s.getNameNode()===e)},sr=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t:void 0},S=e=>{if(i.isIdentifier(e))return e.getText();if(i.isPropertyAccessExpression(e))return e.getName()},ye=e=>i.isIdentifier(e)?Ye(e):e.getDescendantsOfKind(u.Identifier).some(t=>Ye(t)),L=e=>{if(!i.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a));if(s===void 0)return;const r=e.getStart();let n,o=-1;for(const a of s.getDescendantsOfKind(u.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<r&&l>o&&(n=c,o=l)}return n},w=e=>{if(ye(e))return!0;const t=L(e);return t!==void 0&&ye(t)},T=e=>{if(xe(e))return!0;const t=L(e);if(t!==void 0&&xe(t))return!0;const s=t??e;return(i.isIdentifier(s)?[s]:s.getDescendantsOfKind(u.Identifier)).some(r=>{const n=L(r);return n!==void 0&&xe(n)})},V=(e,t)=>i.isIdentifier(e)?tt(e,t):e.getDescendantsOfKind(u.Identifier).some(s=>tt(s,t)),rr=(e,t)=>{if(V(e,t))return!0;const s=L(e);if(s!==void 0&&V(s,t))return!0;const r=sr(e);if(r!==void 0){const n=L(r);return n!==void 0&&V(n,t)}return!1},h=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)&&t.getVariableStatement()?.hasExportKeyword()===!0)return t.getName();return"<module>"},nr=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",ir=(e,t)=>{if(!nr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)||T(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},or=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ir(r,t);n&&s.push(n)}return s},ar=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...or(n,f(t,r)))}return s},cr=new Set(["generateText","streamText"]),ur=new Set(["messages","prompt","system"]),lr=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],dr=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),r=t.getExpression().getText();for(const n of lr)if(n.methods.has(s)&&n.prefixes.some(o=>r===o||r.startsWith(`${o}.`)))return`${r}.${s}`},gr=e=>{for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=dr(t);if(s!==void 0)return s}},fr=e=>{const t=new Set,s=e.getFirstAncestor(o=>i.isArrowFunction(o)||i.isFunctionExpression(o)||i.isFunctionDeclaration(o)),[r]=s?.getParameters()??[],n=r?.getNameNode();if(n===void 0||!i.isObjectBindingPattern(n))return t;for(const o of n.getElements()){const a=o.getPropertyNameNode()?.getText()??o.getName(),c=o.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},pr=e=>{if(ye(e))return!0;const t=fr(e);return t.size===0?!1:e.getDescendantsOfKind(u.Identifier).some(s=>t.has(s.getText()))},mr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!ur.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&pr(s))return!0}return!1},xr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());if(n===void 0||!cr.has(n))continue;const[o]=r.getArguments();if(o===void 0||!i.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(u.CallExpression))if(S(c.getExpression())==="tool"&&(a=gr(c),a!==void 0))break;a!==void 0&&s.push({exportName:h(r),file:t,line:r.getStartLineNumber(),method:n,sideEffect:a,userInputDerived:mr(o)})}return s},hr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...xr(n,f(t,r)))}return s},Er=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},yr=(e,t)=>{if(!Er(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},Ar=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=yr(r,t);n&&s.push(n)}return s},$r=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ar(n,f(t,r)))}return s},Et=e=>e.getProperties().some(t=>i.isSpreadAssignment(t)),Sr=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const r=s.getInitializer();return!r||!i.isObjectLiteralExpression(r)?{objects:[],opaque:!0}:{objects:[r],opaque:Et(r)}},Nr=e=>{const t=[];let s=!1,r=e;for(;i.isCallExpression(r);){const n=r.getExpression();if(!i.isPropertyAccessExpression(n))break;if(n.getName()==="input"){const o=r.getArguments()[0];o&&i.isObjectLiteralExpression(o)?(t.push(o),s||=Et(o)):s=!0}r=n.getExpression()}return{objects:t,opaque:s}},yt=(e,t)=>t?Nr(t):Sr(e),vr=e=>e.flatMap(t=>t.getProperties().filter(s=>i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)).map(s=>s.getName())),br=/\.check\(|\.meta\(|length|max/iu,Pr=/\bv\.any\s*\(/u,wr=/\bv\.string\s*\(/u,Ir=e=>Pr.test(e),Or=e=>wr.test(e)&&!br.test(e),Lr=e=>{const t=[],s=[];for(const r of e)for(const n of r.getProperties()){if(!i.isPropertyAssignment(n))continue;const o=n.getInitializer();if(!o)continue;const a=o.getText(),c=n.getName();Ir(a)?t.push(c):Or(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Fr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=K(s);if(r?.visibility!=="public")return;const{objects:n}=yt(s,r.receiver),{anyArgs:o,unboundedStringArgs:a}=Lr(n);if(!(o.length===0&&a.length===0))return{anyArgs:o,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Tr=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Fr(n,t);o&&s.push(o)}return s},Dr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Tr(n,f(t,r)))}return s},N=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},he=e=>e?.getKind()===u.TrueKeyword,Cr=e=>e?.getKind()===u.FalseKeyword,kr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Kr=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Rr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&S(t.getExpression())==="scim"),Mr=e=>e!==void 0&&i.isCallExpression(e)&&Kr.has(S(e.getExpression())??""),jr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),zr=e=>{const t=N(e,"advanced"),s=N(e,"emailAndPassword"),r=N(e,"session");return{analyzable:!0,disableCsrfCheck:he(N(t,"disableCSRFCheck")),emailPasswordEnabled:he(N(s,"enabled")),requireEmailVerification:he(N(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Rr(N(e,"plugins"))&&Mr(N(e,"database")),secureCookiesDisabled:Cr(N(t,"useSecureCookies")),sessionFreshAgeZero:kr(N(r,"freshAge")),trustedOriginsWildcard:jr(N(e,"trustedOrigins"))}},qr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Vr=(e,t)=>{if(S(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],r=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(o=>i.isSpreadAssignment(o)),n=s!==void 0&&i.isObjectLiteralExpression(s)&&!r?zr(s):qr();return{exportName:h(e),file:t,line:e.getStartLineNumber(),...n}},Br=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Vr(r,t);n&&s.push(n)}return s},Ur=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Br(n,f(t,r)))}return s},Wr=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},Gr=(e,t,s)=>{const r=Wr(e.getExpression(),s);if(r===void 0)return;const n=e.getArguments()[s.argIndex];if(!(!n||!w(n)||T(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:r}},Hr=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const o=Gr(n,t,s);o&&r.push(o)}return r},Q=(e,t,s)=>{const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(...Hr(o,f(t,n),s))}return r},_r=new Set(["content","pdf","scrape","screenshot"]),Qr=(e,t)=>Q(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:_r}),Jr=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Zr=new Set(["RateLimiter"]),Xr=new Set(["extend"]),At=e=>{const t=[],s=[];let r=!1;for(const n of e.getProperties()){if(i.isSpreadAssignment(n)){r=!0;continue}if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o),n.getInitializer()?.getKind()===u.TrueKeyword&&s.push(o);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,presentKeys:t,trueKeys:s}},st=e=>e&&i.isObjectLiteralExpression(e)?At(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Yr=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!i.isReturnStatement(s))return;const r=s.getExpression();return r!==void 0&&i.isObjectLiteralExpression(r)?r:void 0},en=e=>{if(i.isObjectLiteralExpression(e))return e;if(i.isParenthesizedExpression(e)){const t=e.getExpression();return i.isObjectLiteralExpression(t)?t:void 0}return i.isBlock(e)?Yr(e):void 0},tn=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&en(t.getBody());return s?At(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},sn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());n!==void 0&&(Jr.has(n)?s.push({callee:n,file:t,line:r.getStartLineNumber(),...st(r.getArguments()[0])}):Xr.has(n)&&s.push({callee:n,file:t,line:r.getStartLineNumber(),...tn(r.getArguments()[0])}))}for(const r of e.getDescendantsOfKind(u.NewExpression)){const n=S(r.getExpression());n===void 0||!Zr.has(n)||s.push({callee:n,file:t,line:r.getStartLineNumber(),...st(r.getArguments()[0])})}return s},rn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...sn(n,f(t,r)))}return s},rt="ctx.containers.",nn=e=>{if(!e.startsWith(rt))return!1;const t=e.slice(rt.length);return t.length>0&&!t.includes(".")},on=(e,t)=>Q(e,t,{argIndex:0,matchReceiver:nn,methods:new Set(["get"])}),an=new Set(["allow","deny","setAllowed"]),cn=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},un=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!cn(e)))return{detail:"enableInternet: true",exportName:h(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},ln=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!an.has(s.getName()))return;const r=s.getExpression();if(!(!i.isPropertyAccessExpression(r)||r.getName()!=="egress"))return{detail:s.getName(),exportName:h(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},dn=(e,t)=>un(e,t)??ln(e,t),gn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=dn(r,t);n&&s.push(n)}return s},fn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...gn(n,f(t,r)))}return s},pn="env.ts",mn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return _(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},xn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const r=s.getFirstAncestorByKind(u.ImportDeclaration);return r!==void 0&&_(r.getModuleSpecifierValue())}return!1},hn=e=>{if(i.isIdentifier(e))return mn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&xn(t)}return!1},En=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!hn(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw H(n,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},yn=(e,t)=>{const s=g(t,pn);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=En(r);if(n.length!==0){if(n.length>1)throw H(r,`lunora/env.ts declares ${n.length.toString()} defineEnv() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},An=new Set(["defineExportSink","r2Sink","webhookExportSink"]),$n=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return An.has(s)?s:void 0},Sn=e=>{const t=[],s=[];for(const r of e.getProperties()){if(i.isSpreadAssignment(r))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(r)){const n=r.getName();t.push(n);const o=r.getInitializer();o&&i.isStringLiteral(o)&&o.getLiteralText()===""&&s.push(n);continue}(i.isShorthandPropertyAssignment(r)||i.isMethodDeclaration(r)||i.isGetAccessorDeclaration(r))&&t.push(r.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Nn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){const c=$n(a);if(c===void 0)continue;const l=a.getArguments()[0],p=l&&i.isObjectLiteralExpression(l)?Sn(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:p.analyzable,emptyKeys:p.emptyKeys,factory:c,file:o,line:a.getStartLineNumber(),presentKeys:p.presentKeys})}}return s},vn=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),bn=new Set(["dbRateLimit","rateLimit"]),Pn=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&i.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===u.TrueKeyword},wn=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},In=(e,t)=>{const s=S(e.getExpression());if(s===void 0)return;const r=vn.get(s);if(r!==void 0)return{callee:s,exportName:h(e),failOpen:Pn(e.getArguments()[r]),file:t,limitName:bn.has(s)?wn(e):"",line:e.getStartLineNumber()}},On=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=In(r,t);n&&s.push(n)}return s},Ln=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...On(n,f(t,r)))}return s},Fn=e=>{const t=r=>i.isIdentifier(r)&&r.getText()==="ctx",s=new Set;for(const r of e.getDescendantsOfKind(u.PropertyAccessExpression))t(r.getExpression())&&s.add(r.getName());for(const r of e.getDescendantsOfKind(u.VariableDeclaration)){const n=r.getInitializer(),o=r.getNameNode();if(!(n===void 0||!t(n)||!i.isObjectBindingPattern(o)))for(const a of o.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},Tn=(e,t)=>{const s=Object.fromEntries(me.map(r=>[r.key,!1]));for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=new Set(n.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=Fn(n);for(const c of me)if(!s[c.key]){if(o.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(me.every(c=>s[c.key]))break}return s},Dn=["providerSubscriptionId","state"],Cn=["providerEventId","processedAt"],nt=(e,t)=>t.every(s=>s in e.shape),kn=e=>{const t=e.find(r=>r.name==="subscriptions"),s=e.find(r=>r.name==="events");return t!==void 0&&s!==void 0&&nt(t,Dn)&&nt(s,Cn)},Kn=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings/kv"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),Rn=e=>i.isIdentifier(e)&&e.getText()==="ctx",Mn=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Rn(t.getExpression())},jn=e=>{if(e?.getKind()===u.TrueKeyword)return!0;if(e?.getKind()===u.FalseKeyword)return!1},zn=(e,t)=>{if(!Mn(e.getExpression()))return;const[s,r]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const n=s.getLiteralValue(),o=jn(r);if(!(n.length===0||o===void 0))return{defaultValue:o,exportName:h(e),file:t,key:n,line:e.getStartLineNumber()}},qn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=zn(r,t);n&&s.push(n)}return s},Vn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...qn(n,f(t,r)))}return s},Bn=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Un=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Wn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression))Bn(a)&&s.push({file:o,indexName:Un(a),line:a.getStartLineNumber()})}return s},Gn=new Set(["delete","get","head","options","patch","post","put"]),Hn=new Set(["handler","stream"]),_n=new Set(["runAction","runMutation"]),Qn=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),U=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,it=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,ot=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const r=s.getNameNode();if(t)return i.isIdentifier(r)?r.getText():void 0;if(i.isObjectBindingPattern(r)){for(const n of r.getElements())if((n.getPropertyNameNode()?.getText()??n.getNameNode().getText())==="ctx"){const o=n.getNameNode();return i.isIdentifier(o)?o.getText():void 0}}},at=(e,t)=>{const s=e.getBody(),r=s.getDescendantsOfKind(u.CallExpression);i.isCallExpression(s)&&r.unshift(s);for(const n of r){const o=n.getExpression();if(!i.isPropertyAccessExpression(o))continue;const a=o.getName(),c=o.getExpression();if(_n.has(a)&&U(c,t))return a;if(Qn.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&U(c.getExpression(),t))return`db.${a}`}},ct=(e,t)=>{const s=e.getBody();for(const r of s.getDescendantsOfKind(u.PropertyAccessExpression))if(r.getName()==="auth"&&U(r.getExpression(),t))return!0;for(const r of s.getDescendantsOfKind(u.VariableDeclaration)){const n=r.getNameNode();if(!(!i.isObjectBindingPattern(n)||!U(r.getInitializer(),t))){for(const o of n.getElements())if((o.getPropertyNameNode()?.getText()??o.getNameNode().getText())==="auth")return!0}}return!1},Jn=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Hn.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))return;const n=r.getName();if(Gn.has(n)){const o=r.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?n.toUpperCase():void 0}s=r.getExpression()}},Zn=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=it(e.getArguments()[0]),l=c&&ot(c,!0);if(!c||l===void 0)return;const p=at(c,l);return p===void 0?void 0:{exportName:h(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ct(c,l),sideEffect:p}}const r=Jn(e);if(r===void 0)return;const n=it(e.getArguments()[0]),o=n&&ot(n,!1);if(!n||o===void 0)return;const a=at(n,o);return a===void 0?void 0:{exportName:h(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:r,readsAuth:ct(n,o),sideEffect:a}},Xn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Zn(r,t);n&&s.push(n)}return s},Yn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Xn(n,f(t,r)))}return s},ei=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),ti=new Set(["append","set"]),Se=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",$t=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",ut=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(u.CallExpression)]:e.getDescendantsOfKind(u.CallExpression)).some(s=>ei.has(Se(s.getExpression()))&&V(s,t)),si=(e,t)=>{if(ut(e,t))return!0;const s=L(e);return s!==void 0&&ut(s,t)},Ae=(e,t)=>rr(e,t)&&!si(e,t),ri=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=L(e);return t!==void 0&&i.isNewExpression(t)&&Se(t.getExpression())==="Headers"},W=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=L(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},Ne=(e,t,s)=>{for(const r of e.getProperties())if(i.isPropertyAssignment(r)){const n=r.getInitializer();n!==void 0&&Ae(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:$t(r.getNameNode()),line:n.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(r)){const n=r.getNameNode();Ae(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:r.getName(),line:n.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(r)){const n=W(r.getExpression());n!==void 0&&Ne(n,t,s)}},St=(e,t)=>{const s=W(e);if(s===void 0)return;const r=s.getProperty("headers");if(r===void 0||!i.isPropertyAssignment(r))return;const n=W(r.getInitializer());n!==void 0&&Ne(n,"response-init",t)},ni=(e,t)=>{const s=Se(e.getExpression());if(s==="Response")St(e.getArguments()[1],t);else if(s==="Headers"){const r=W(e.getArguments()[0]);r!==void 0&&Ne(r,"headers-ctor",t)}},ii=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const r=s.getName(),n=s.getExpression();if(r==="json"&&i.isIdentifier(n)&&n.getText()==="Response"){St(e.getArguments()[1],t);return}if(ti.has(r)&&ri(n)){const o=e.getArguments()[1];o!==void 0&&Ae(o,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:$t(e.getArguments()[0]),line:o.getStartLineNumber(),via:r==="set"?"headers-set":"headers-append"})}},oi=(e,t)=>{for(const s of e.getDescendantsOfKind(u.NewExpression))ni(s,t);for(const s of e.getDescendantsOfKind(u.CallExpression))ii(s,t)},ai=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const r=Ht(e.getArguments()[0]);if(r===void 0)return[];const n=r.getParameters()[1];if(n===void 0)return[];const o=n.getNameNode();if(!i.isIdentifier(o))return[];const a=[];return oi(r,{exportName:h(e),relativePath:t,requestName:o.getText(),rows:a}),a},ci=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...ai(r,t));return s},ui=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ci(n,f(t,r)))}return s},Nt="identity.ts",li=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return _(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},di=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const r=s.getFirstAncestorByKind(u.ImportDeclaration);return r!==void 0&&_(r.getModuleSpecifierValue())}return!1},gi=e=>{if(i.isIdentifier(e))return li(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&di(t)}return!1},fi=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!gi(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw H(n,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},pi=(e,t)=>{const s=g(t,Nt);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=fi(r);if(n.length!==0){if(n.length>1)throw H(r,`lunora/identity.ts declares ${n.length.toString()} defineIdentity() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},mi=new Set(["auth","context.auth","ctx.auth"]),xi="userId",hi=e=>{const t=new Set;for(const s of e.getProperties()){if(i.isSpreadAssignment(s))return;(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s))&&t.add(s.getName())}return t},Ei=(e,t)=>{const s=g(t,Nt);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const n of r.getDescendantsOfKind(u.CallExpression)){if(S(n.getExpression())!=="defineIdentity")continue;const[o]=n.getArguments();return o&&i.isObjectLiteralExpression(o)?hi(o):void 0}},lt=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return mi.has(e.getExpression().getText())?e:void 0},yi=e=>{if(i.isPropertyAccessExpression(e)&&lt(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&lt(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},Ai=(e,t,s)=>{const r=[];for(const n of e.getDescendants()){const o=yi(n);o!==void 0&&r.push({declared:o===xi||s.has(o),exportName:h(n),file:t,key:o,line:n.getStartLineNumber()})}return r},$i=(e,t)=>{const s=Ei(e,t);if(s===void 0)return[];const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(...Ai(o,f(t,n),s))}return r},Si=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Ni=(e,t)=>{if(S(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const r=Si(s);if(!(!r||!w(r)||T(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},vi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ni(r,t);n&&s.push(n)}return s},bi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...vi(n,f(t,r)))}return s},Pi=new Set(["delete","get","getRaw","getWithMetadata","put"]),wi=(e,t)=>Q(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:Pi}),Ii=new Set(["queue","send"]),dt=new Set(["bcc","cc","to"]),Oi=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Ii.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},Li=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const r=t.getNameNode();return dt.has(t.getName())&&w(r)&&!T(r)}if(!i.isPropertyAssignment(t)||!dt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&w(s)&&!T(s)}):!1,Fi=(e,t)=>{const s=Oi(e.getExpression());if(s===void 0)return;const r=e.getArguments()[0];if(!(!r||!Li(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Ti=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Fi(r,t);n&&s.push(n)}return s},Di=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ti(n,f(t,r)))}return s},Ci=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},ki=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},Ki=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==u.CallExpression)return;const s=t;return vs(s.getExpression())?s:void 0},Ri=e=>{const t=Ki(e),s=t===void 0?void 0:ki(t);if(s===void 0)return[];const r=e.getNameNode(),n=i.isIdentifier(r)?r.getText():"";return s.getDescendantsOfKind(u.CallExpression).filter(o=>Ci(o)).map(o=>({exportName:n,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},Mi=e=>e.getVariableDeclarations().flatMap(t=>Ri(t)),ji=(e,t)=>{const s=g(t,Ns);if(!E(s))return[];const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Mi(r)},zi=new Set(["delete","get","patch"]),qi=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Vi=new Set(["auth","identity","session","user"]),Bi=new Set([u.EqualsEqualsEqualsToken,u.EqualsEqualsToken,u.ExclamationEqualsEqualsToken,u.ExclamationEqualsToken]),Ui=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!k(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},Wi=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(i.isAsExpression(s)||i.isParenthesizedExpression(s)||i.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!i.isVariableDeclaration(s))return;const r=s.getNameNode();return i.isIdentifier(r)?r.getText():void 0},Gi=(e,t)=>e.getDescendantsOfKind(u.Identifier).some(s=>s.getText()===t),Hi=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(u.ThrowStatement).length>0||e.getDescendantsOfKind(u.ReturnStatement).length>0,_i=(e,t)=>e.getDescendantsOfKind(u.IfStatement).some(s=>Gi(s.getExpression(),t)&&Hi(s.getThenStatement())),Qi=(e,t)=>{for(const s of e.getDescendantsOfKind(u.CallExpression)){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))continue;const n=r.getName();if(!zi.has(n))continue;const o=r.getExpression();if(!(k(o)||i.isPropertyAccessExpression(o)&&k(o.getExpression())))continue;const a=s.getArguments()[0];if(a!==void 0&&i.isIdentifier(a)&&a.getText()===t)return n}},Ji=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t)||i.isParenthesizedExpression(t)||i.isAsExpression(t)||i.isAwaitExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t.getText():void 0},Zi=e=>e.getDescendantsOfKind(u.CallExpression).some(t=>t.getArguments().some(s=>Ji(s)==="ctx")),Xi=e=>e.getDescendantsOfKind(u.BinaryExpression).some(t=>Bi.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),Yi=e=>{for(const t of e.getDescendantsOfKind(u.Identifier))if(qi.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&Vi.has(t.getName()))return!0}return Zi(e)||Xi(e)},eo=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const r=K(s);if(r?.kind!=="query"&&r?.kind!=="mutation")return[];const n=mt(s);if(n===void 0)return[];const o=r.receiver!==void 0&&xt(r.receiver,"use","rls"),a=Yi(n),c=new Set,l=[];for(const p of n.getDescendantsOfKind(u.CallExpression)){const y=Ui(p);if(y===void 0)continue;const I=Wi(p);if(I===void 0||c.has(I)||!_i(n,I))continue;const R=Qi(n,I);R!==void 0&&(c.add(I),l.push({exportName:e.getName(),file:t,line:p.getStartLineNumber(),mentionsOwnership:a,sinkMethod:R,table:y,usesRls:o,visibility:r.visibility}))}return l},to=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...eo(c,o))}return s},so=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),ro=new Set(["insert","insertManyUnsafe","patch","replace"]),no=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!ro.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="db")return;const r=s.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"?t:void 0},io=(e,t)=>{if(t!=="insertManyUnsafe")return i.isObjectLiteralExpression(e)?[e]:[];if(!i.isArrayLiteralExpression(e))return[];const s=[];for(const r of e.getElements())i.isObjectLiteralExpression(r)&&s.push(r);return s},oo=(e,t,s,r)=>{const n=[];for(const o of e.getProperties()){let a,c;i.isPropertyAssignment(o)?(a=o.getName(),c=o.getInitializer()):i.isShorthandPropertyAssignment(o)&&(a=o.getName(),c=o.getNameNode()),!(a===void 0||c===void 0||!so.has(a))&&w(c)&&!T(c)&&n.push({exportName:h(s),field:a,file:r,line:s.getStartLineNumber(),method:t})}return n},ao=(e,t)=>{const s=no(e.getExpression());if(s===void 0)return[];const r=e.getArguments()[1];return r?io(r,s).flatMap(n=>oo(n,s,e,t)):[]},co=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...ao(r,t));return s},uo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...co(n,f(t,r)))}return s},lo=e=>{const t=g(e,"package.json");if(!E(t))return new Set;try{const s=JSON.parse($e(t,"utf8")),r=new Set;for(const n of["dependencies","devDependencies","peerDependencies","optionalDependencies"]){const o=s[n];if(o!==null&&typeof o=="object")for(const a of Object.keys(o))r.add(a)}return r}catch{return new Set}},go=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),fo=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,po=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?fo(t.getInitializer()):void 0},mo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());if(n===void 0||!go.has(n))continue;const[o]=r.getArguments(),a=o&&i.isObjectLiteralExpression(o)?po(o):void 0;s.push({callee:n,exportName:h(r),file:t,line:r.getStartLineNumber(),...a===void 0?{}:{toleranceSeconds:a}})}return s},xo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...mo(n,f(t,r)))}return s},ho=new Set(["defineQueue","defineWorkflow"]),Eo=new Set(["run","runAction","runMutation","runQuery"]),yo=new Set(["api","internal"]),Ao=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},$o=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!i.isPropertyAssignment(s))return;const r=s.getInitializer();if(r&&(i.isArrowFunction(r)||i.isFunctionExpression(r)))return r},vt=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},bt=(e,t)=>e===t||e.startsWith(`${t}.`),Pt=e=>{const t=e.getDescendantsOfKind(u.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},gt=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e||i.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(i.isBindingElement(t)&&t.getNameNode()===e)},wt=e=>{const t=e.getDescendantsOfKind(u.Identifier).filter(s=>gt(s));return i.isIdentifier(e)&&gt(e)&&t.push(e),t},So=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(u.BindingElement).map(s=>s.getName())},No=e=>{const t=vt(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const r of e.getDescendantsOfKind(u.ForOfStatement)){if(r.getExpression().getText()!==`${t}.messages`)continue;const n=r.getInitializer(),o=i.isVariableDeclarationList(n)?n.getDeclarations()[0]?.getNameNode():void 0;o&&i.isIdentifier(o)&&s.push(`${o.getText()}.body`)}return s},vo=(e,t,s)=>{const r=t==="workflow"?[`${s}.params`]:No(e),n=new Set,o=a=>Pt(a).some(c=>r.some(l=>bt(c.getText(),l)))?!0:wt(a).some(c=>n.has(c.getText()));for(const a of e.getDescendantsOfKind(u.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of So(a))n.add(l)}return{names:n,prefixes:r}},bo=(e,t)=>Pt(e).some(s=>t.prefixes.some(r=>bt(s.getText(),r)))?!0:wt(e).some(s=>t.names.has(s.getText())),Po=e=>{if(e===void 0||!i.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;i.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const r=t.at(-1);if(!(r===void 0||!i.isIdentifier(s)||!yo.has(s.getText())||t.length<2))return{exportName:r,file:t.slice(0,-1).join("/")}},wo=(e,t,s)=>{const r=vt(e,0);if(r===void 0)return[];const n=vo(e,t,r),o=[];for(const a of e.getDescendantsOfKind(u.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!Eo.has(c.getName())||c.getExpression().getText()!==r)continue;const l=a.getArguments()[1];if(!l||!bo(l,n))continue;const p=Po(a.getArguments()[0]);p!==void 0&&o.push({dispatchKind:t,file:s,handlerExport:h(a),line:a.getStartLineNumber(),targetExport:p.exportName,targetFile:p.file})}return o},Io=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ao(r);if(n===void 0||!ho.has(n))continue;const o=$o(r);o!==void 0&&s.push(...wo(o,n==="defineQueue"?"queue":"workflow",t))}return s},Oo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Io(n,f(t,r)))}return s},ft={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},Lo=/account|credential|member|passkey|session|user/iu,Fo=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},To=(e,t)=>{const{objects:s,opaque:r}=yt(e,t);return vr(s).some(n=>Fo(n))?!0:r?void 0:!1},It=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},Do=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Co=e=>{if(i.isCallExpression(e))return e;if(!i.isIdentifier(e))return;const t=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return t&&i.isCallExpression(t)?t:void 0},B={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},ko=e=>{const t=Co(e),s=t?It(t):void 0;if(t&&s==="protectPublic"){const r=Do(t);return{...B,usesCaptcha:r.usesCaptcha,usesRateLimit:r.usesRateLimit}}return s!==void 0&&s in ft?{...B,[ft[s]]:!0}:B},Ko=e=>{const t={...B};let s=e;for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))break;const n=r.getName()==="use"?s.getArguments()[0]:void 0;if(n){const o=ko(n);t.usesCaptcha||=o.usesCaptcha,t.usesEmailGate||=o.usesEmailGate,t.usesMask||=o.usesMask,t.usesRateLimit||=o.usesRateLimit,t.usesRls||=o.usesRls}s=r.getExpression()}return t},Ro=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insert")return!1;const s=t.getExpression();if(!(i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"))return!1;const r=e.getArguments()[0];return!!(r&&i.isStringLiteral(r)&&Lo.test(r.getLiteralText()))},Mo=new Set(["create","runAfter","runAt","send","sendBatch"]),jo=new Set(["queues","scheduler","workflows"]),zo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Mo.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&jo.has(s.getName())){const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="ctx")return!0}s=s.getExpression()}return!1},qo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},Vo=new Set(["generateObject","generateText","streamObject","streamText"]),Bo=e=>{const t=It(e);if(t===void 0||!Vo.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(r=>i.isSpreadAssignment(r))?!1:!s.getProperty("maxOutputTokens")},Uo=e=>e.getDescendantsOfKind(u.PropertyAccessExpression).some(t=>{const s=t.getName();if(s!=="mail"&&s!=="email")return!1;const r=t.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"}),Wo=e=>{let t=!1,s=!1,r=!1,n=!1;for(const o of e.getDescendantsOfKind(u.CallExpression))if(Ro(o)&&(n=!0),zo(o)&&(t=!0),qo(o)&&(r=!0),Bo(o)&&(s=!0),n&&t&&r&&s)break;return{callsMail:Uo(e),fanOut:t,unboundedAiGeneration:s,usesInsertManyUnsafe:r,writesUserTable:n}},Go=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=K(s);if(!r||r.kind!=="query"&&r.kind!=="mutation"&&r.kind!=="action")return;const n=r.receiver?Ko(r.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},{callsMail:o,fanOut:a,unboundedAiGeneration:c,usesInsertManyUnsafe:l,writesUserTable:p}=Wo(e);return{callsMail:o,exportName:e.getName(),fanOut:a,file:t,hasEmailArg:To(s,r.receiver),kind:r.kind,unboundedAiGeneration:c,usesCaptcha:n.usesCaptcha,usesEmailGate:n.usesEmailGate,usesInsertManyUnsafe:l,usesMask:n.usesMask,usesRateLimit:n.usesRateLimit,usesRls:n.usesRls,visibility:r.visibility,writesUserTable:p}},Ho=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Go(n,t);o&&s.push(o)}return s},_o=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ho(n,f(t,r)))}return s},Qo=new Set(["dbRateLimit","rateLimit"]),Jo=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Zo=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},Xo=e=>i.isArrowFunction(e)?e.getBody():e,Yo=(e,t)=>{const s=S(e.getExpression());if(s===void 0||!Qo.has(s))return;const r=e.getArguments()[2];if(!r)return;const n=Jo(r);if(!n)return;const o=Xo(n);if(!(!w(o)||T(o)))return{callee:s,exportName:h(e),file:t,limitName:Zo(e),line:e.getStartLineNumber()}},ea=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Yo(r,t);n&&s.push(n)}return s},ta=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ea(n,f(t,r)))}return s},sa=new Set(["findFirst","findFirstOrThrow","findMany","get"]),ra=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!sa.has(t.getName()))return;const s=t.getExpression();if(k(s)){const r=e.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&k(s.getExpression()))return s.getName()},na=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&k(s.getExpression())){const r=t.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}t=s.getExpression()}},ia=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},Ot=(e,t=!1)=>{const s=ia(e);if(i.isIdentifier(s)){if(t)return;const r=L(s);return r===void 0?void 0:Ot(r,!0)}if(i.isCallExpression(s))return ra(s)??na(s)},oa=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const r of e.getDescendantsOfKind(u.ReturnStatement)){const n=r.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),o=r.getExpression();n===e&&o!==void 0&&s.push(o)}return s},aa=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const r=K(s);if(r?.kind!=="query")return[];const n=mt(s);if(n===void 0)return[];const o=r.receiver!==void 0&&_t(r.receiver,"output"),a=r.receiver!==void 0&&xt(r.receiver,"use","mask"),c=new Set,l=[];for(const p of oa(n)){const y=Ot(p);y===void 0||c.has(y)||(c.add(y),l.push({exportName:e.getName(),file:t,line:p.getStartLineNumber(),table:y,usesMask:a,usesOutput:o,visibility:r.visibility}))}return l},ca=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...aa(c,o))}return s},ua=new Set(["findFirst","findFirstOrThrow","findMany"]),la=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ua.has(t.getName()))return;const s=t.getExpression();if(i.isPropertyAccessExpression(s)&&s.getName()==="db"||i.isIdentifier(s)&&s.getText()==="db"){const r=e.getArguments()[0];return{options:e.getArguments()[1],table:r&&i.isStringLiteral(r)?r.getLiteralText():""}}if(i.isPropertyAccessExpression(s)){const r=s.getExpression();if(i.isPropertyAccessExpression(r)&&r.getName()==="db"||i.isIdentifier(r)&&r.getText()==="db")return{options:e.getArguments()[0],table:s.getName()}}},da=e=>{if(!e||!i.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s)||i.isGetAccessorDeclaration(s))&&t.push(s.getName());return t},ga=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},fa=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&i.isCallExpression(s)?K(s):void 0;if(!r)return[];const n=[];for(const o of e.getDescendantsOfKind(u.CallExpression)){const a=la(o);if(a===void 0)continue;const c=da(ga(a.options,"with"));c.length!==0&&n.push({exportName:e.getName(),file:t,line:o.getStartLineNumber(),parentTable:a.table,relations:c,visibility:r.visibility})}return n},pa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...fa(c,o))}return s},G=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===u.PlusToken){const t=G(e.getLeft()),s=G(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},ma=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===u.PlusToken;)t=s,s=t.getParent();return t!==e&&G(t)!==void 0},xa=(e,t)=>{const s=[],r=[...e.getDescendantsOfKind(u.BinaryExpression),...e.getDescendantsOfKind(u.StringLiteral),...e.getDescendantsOfKind(u.NoSubstitutionTemplateLiteral)],n=new Set;for(const o of r){if(ma(o))continue;const a=G(o);if(a===void 0)continue;const c=Ks(a);if(c===void 0)continue;const l=o.getStartLineNumber(),p=`${String(l)}:${c}`;n.has(p)||(n.add(p),s.push({file:t,kind:c,line:l,preview:Rs(a)}))}return s},ha=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...xa(n,f(t,r)))}return s},Ea=new Set(["findFirst","findFirstOrThrow","findMany"]),ya=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Ea.has(t.getName()))return;const s=t.getExpression();if(i.isPropertyAccessExpression(s)&&s.getName()==="db"||i.isIdentifier(s)&&s.getText()==="db"){const r=e.getArguments()[0];return{options:e.getArguments()[1],table:r&&i.isStringLiteral(r)?r.getLiteralText():""}}if(i.isPropertyAccessExpression(s)){const r=s.getExpression();if(i.isPropertyAccessExpression(r)&&r.getName()==="db"||i.isIdentifier(r)&&r.getText()==="db")return{options:e.getArguments()[0],table:s.getName()}}},Aa=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},$a=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&i.isCallExpression(s)?K(s):void 0;if(!r)return[];const n=[];for(const o of e.getDescendantsOfKind(u.CallExpression)){const a=ya(o);if(a===void 0)continue;const c=Aa(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),p=!l&&w(c);!l&&!p||n.push({exportName:e.getName(),file:t,fromArgs:p,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:r.visibility})}return n},Sa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...$a(c,o))}return s},Na=new Set(["query","unsafe"]),va=e=>{if(!i.isPropertyAccessExpression(e)||!Na.has(e.getName()))return!1;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return i.isIdentifier(s)&&s.getText()==="ctx"},ba=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),Pa=e=>e.getFirstAncestorByKind(u.VariableDeclaration)?.getName()??"<module>",wa=(e,t)=>{if(!va(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!ba(s)))return{exportName:Pa(e),file:t,line:s.getStartLineNumber()}},Ia=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=wa(r,t);n&&s.push(n)}return s},Oa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ia(n,f(t,r)))}return s},La=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Fa=(e,t)=>Q(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.storage"||s.startsWith("ctx.storage."),methods:La}),Ta=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Da=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Ca=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!i.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,r=!1;for(const n of e.getProperties()){if(i.isSpreadAssignment(n)){r=!0;continue}if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o),o==="expiresInSeconds"&&(s=Da(n.getInitializer()));continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,expiresInSeconds:s,presentKeys:t}},ka=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=Ta.get(t);if(s===void 0)return;const r=e.getExpression().getText();return r==="ctx.storage"||r.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},Ka=(e,t)=>{const s=ka(e.getExpression());if(s!==void 0)return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s.method,...Ca(e.getArguments()[s.optionsIndex])}},Ra=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ka(r,t);n&&s.push(n)}return s},Ma=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ra(n,f(t,r)))}return s},ja=new Set(["when","where"]),Ee=new Set(["definePolicy","defineShape"]),za=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const r=t.getName();return Ee.has(r)?r:void 0}if(!i.isIdentifier(t))return;for(const r of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(r)){const n=r.getNameNode().getText();return Ee.has(n)?n:void 0}const s=t.getText();return Ee.has(s)?s:void 0},qa=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,Lt=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===u.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(qa(e))return"empty-object";if(i.isParenthesizedExpression(e))return Lt(e.getExpression())}},Ft=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Tt=e=>e.getDescendantsOfKind(u.ReturnStatement).filter(t=>Ft(t)===e),Dt=e=>e.getDescendantsOfKind(u.ConditionalExpression).filter(t=>Ft(t)===e),Va=e=>{const t=Tt(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(u.IfStatement)!==void 0)||Dt(e).length>0},Ba=e=>{const t=[],s=e.getBody();i.isBlock(s)||t.push(s);for(const r of Tt(e)){const n=i.isReturnStatement(r)?r.getExpression():void 0;t.push(n??r)}for(const r of Dt(e))t.push(r.getWhenTrue(),r.getWhenFalse());return t},Ua=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},Wa=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[r]=e.getArguments();if(!r||!i.isObjectLiteralExpression(r))return[];const n=[];for(const o of r.getProperties()){if(!i.isPropertyAssignment(o)||!ja.has(o.getName()))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Va(a))for(const c of Ba(a)){const l=Lt(c);l!==void 0&&n.push({exportName:Ua(e),file:s,form:l,key:o.getName(),line:c.getStartLineNumber(),owner:t})}}return n},Ga=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=za(r);n!==void 0&&s.push(...Wa(r,n,t))}return s},Ha=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ga(n,f(t,r)))}return s},_a=new Set(["query","upsert","upsertMany"]),Qa=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(_a.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Ja=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("namespace");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Za=(e,t)=>{const s=Qa(e.getExpression());if(s===void 0)return;const r=e.getArguments()[1];if(!r)return;const n=Ja(r);if(!(!n||!w(n)||T(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Xa=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Za(r,t);n&&s.push(n)}return s},Ya=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Xa(n,f(t,r)))}return s},ec=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="workflows":i.isIdentifier(s)&&s.getText()==="workflows"},tc=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},sc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){if(!ec(a))continue;const c=zs(a);c!==""&&s.push({exportName:c,file:o,line:a.getStartLineNumber(),workflow:tc(a)})}}return s},rc=".lunora-schema.json",$=(e,t)=>{E(e)&&$e(e,"utf8")===t||Bt(e,t,"utf8")},P=(e,t)=>{if(t===""){Ut(e,{force:!0});return}$(e,t)},nc=e=>{const t=g(e,"package.json");if(E(t))try{const s=JSON.parse($e(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},ic=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},oc=e=>{let t=E(e)?e:fe(e);for(;t&&t!==fe(t);){const s=g(t,"tsconfig.json");if(E(s))return s;t=fe(t)}},pt=e=>e.replaceAll("\\","/"),ac=(e,t)=>{const s=new Map,r=new Map,n=new Map;for(const o of e)s.set(o.name,`workflow "${o.exportName}"`),r.set(o.bindingName,`workflow "${o.exportName}"`),n.set(o.className,`workflow "${o.exportName}"`);for(const o of t){const a=s.get(o.name);if(a!==void 0)throw new q("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${o.name}": produced by both ${a} and agent "${o.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=r.get(o.bindingName);if(c!==void 0)throw new q("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${o.bindingName}": produced by both ${c} and agent "${o.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const l=n.get(o.className);if(l!==void 0)throw new q("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${o.className}": produced by both ${l} and agent "${o.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},cc=e=>{const t=oc(e);return t?new Ze({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Ze({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Hc=(e,t)=>{const s=d(t),r=g(t,"schema.ts");E(r)&&s.push(r);for(const c of s){const l=e.getSourceFile(c);l===void 0?e.addSourceFileAtPath(c):l.refreshFromFileSystemSync()}const n=new Set(s.map(c=>pt(c))),o=pt(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!n.has(l)&&e.removeSourceFile(c)}},_c=e=>{const t=ic(),s=t?pe.now():0,r=g(e.projectRoot,e.lunoraDirectory??"lunora"),n=g(r,"schema.ts");if(!E(n))throw new q("INTERNAL",`schema.ts not found at ${n}`);const o=e.project??cc(r),a=ks(o,n,e.projectRoot),c=Qt(o,r),l=hs(o,r),p=Ss(o,r),y=Ms(o,r),I=bs(o,r),R=pi(o,r),ve=yn(o,r),v=qs(o,r),D=Ls(o,r),b=Jt(o,r);ac(v,b);const J=Yt(o,r,v,b),C=Xt(o,r),be=e.lint===!1?[]:Gt({adminRoutes:tr(o,r),aiRawRuns:ar(o,r),aiToolSideEffects:hr(o,r),argumentDerivedFetches:$r(o,r),argumentValidators:Dr(o,r),authApiCalls:Zt(o,r),authConfigs:Ur(o,r),browserUrlAccesses:Qr(o,r),configCalls:rn(o,r),containerKeyAccesses:on(o,r),containerOverrides:fn(o,r),containers:C,exportSinks:Nn(o,r),failOpenGuards:Ln(o,r),flagSecurityDefaults:Vn(o,r),geoIndexUsages:Wn(o,r),httpActionGuards:Yn(o,r),httpHeaderWrites:ui(o,r),identityClaimReads:$i(o,r),imageDeliveryUrlAccesses:bi(o,r),inserts:Es(o,r),kvKeyAccesses:wi(o,r),mailRecipientAccesses:Di(o,r),maskProcedures:ys(o,r),maskStrategies:As(o,r),mutatorWrites:ji(o,r),nondeterministicCalls:Ps(o,r),normalizeIdAuthorizations:to(o,r),notifyCalls:Is(o,r),notifyConfig:ws(o,r),ownerFieldWrites:uo(o,r),unrestrictedWhereBranches:Ha(o,r),paymentWebhooks:xo(o,r),privilegedDispatches:Oo(o,r),procedureProtections:_o(o,r),queries:Os(o,r),queues:D,r2sqlCalls:Fs(o,r),ratelimitKeySelectors:ta(o,r),rawRowReturns:ca(o,r),relationLoads:pa(o,r),rlsProcedures:Ts(o,r),schema:a,secretLiterals:ha(o,r),shapes:y,softDeleteReads:Sa(o,r),sqlInterpolations:Oa(o,r),storageKeyAccesses:Fa(o,r),storageUploads:Ma(o,r),vectorNamespaceAccesses:Ya(o,r),workflowCalls:sc(o,r),workflows:v,wranglerVariables:e.wranglerVariables}),Ct=Ds(o,r),kt=$s(o,r),Z=js(o,r),A=Tn(o,r),X=A.ai,Y=A.payments,Pe=A.kv,we=A.access,ee=E(g(r,"flags.ts")),Kt=ee?xs(o,r):[],te=E(g(r,"notify.ts")),se=A.hyperdrive,re=Cs(o,r),Rt=re.usesSandboxBrowser||re.usesSandboxContainer,ne=A.browser||re.usesSandboxBrowser,ie=A.images,oe=A.analytics,Ie=A.pipelines,ae=A.r2sql,ce=A.x402,O=lo(e.projectRoot),M=Kn(A,{containerCount:C.length,cronCount:J.length,dependencies:O,hasPaymentTables:kn(a.tables),queueCount:D.length,storageColumnCount:Object.keys(es(a)).length,storageRuleCount:Z.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:v.length}),F=O.has("lunorash"),Oe=t?pe.now():0,Le=ts(a,F),Fe=ss({agents:b,functions:c,httpRoutes:l,mutators:I,useUmbrella:F,workflows:v}),Te=rs({agents:b,containers:C,env:ve,hasAccessFacade:we,hasAi:X,hasAnalytics:oe,hasBrowser:ne,hasFlags:ee,hasHyperdrive:se,hasImages:ie,hasKv:Pe,hasNotify:te,hasPayments:Y,hasPipelines:Ie,hasR2sql:ae,hasX402:ce,identity:R,queues:D,schema:a,storageRuleBuckets:Z.rules.map(m=>m.bucket),useUmbrella:F,workflows:v}),De=ns({agents:b,functions:c,migrations:p,mutators:I,shapes:y,useUmbrella:F,usesSandbox:Rt}),ue=Hs(a,p.map(m=>m.id)),Ce=is({advisories:be,agents:b,containers:C,env:ve,flagKeys:Kt,hasAccessFacade:we,hasAi:X,hasAnalytics:oe,hasBrowser:ne,hasFlags:ee,hasHyperdrive:se,hasImages:ie,hasKv:Pe,hasNotify:te,hasPayments:Y,hasPipelines:Ie,hasR2sql:ae,hasX402:ce,maskMetadata:kt,mutators:I,queues:D,rlsMetadata:Ct,schema:a,schemaSnapshot:ue,shapes:y,storageRules:Z,studioFeatures:M,useUmbrella:F,workflows:v}),ke=os(y,O.has("@lunora/db"),F),Ke=as(C,a.jurisdiction),Re=cs(v),Me=us(b),je=ls(D),ze=ds(J),qe=gs(a.vectorIndexes),j=fs(a,F),Ve=ps(O.has("@lunora/seed")),z=e.apiSpec??"openapi",le=z==="openapi"||z==="both",de=z==="openrpc"||z==="both",Be=Vs({emailAgents:b.filter(m=>m.onEmail===!0).map(m=>({bindingName:m.bindingName,exportName:m.exportName})),hasAccess:O.has("@lunora/cloudflare-access"),hasAi:X,hasAnalytics:oe,hasAuth:O.has("@lunora/auth"),hasBrowser:ne,hasFramework:O.has("@lunora/astro")||O.has("@lunora/svelte")||O.has("@lunora/vue"),hasGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend!=="hyperdrive"),hasHyperdrive:se,hasHyperdriveGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend==="hyperdrive"),hasImages:ie,hasKv:M.kv,hasNotify:te,hasPayments:Y,hasR2sql:ae,hasQueue:D.some(m=>m.mode==="push"),hasScheduler:M.scheduler,hasStorage:M.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:v.length>0,hasX402:ce,identity:R,jurisdiction:a.jurisdiction,useUmbrella:F,voiceAgents:b.filter(m=>m.voice===!0&&m.voiceBindingName!==void 0).map(m=>({bindingName:m.voiceBindingName,exportName:m.exportName})),wantsOpenApi:le,wantsOpenRpc:de}),Ue=nc(e.projectRoot),We=Bs({functions:c,httpRoutes:l,version:Ue}),Ge=Ws({functions:c,version:Ue}),He=`${JSON.stringify(We,void 0,2)}
2
- `,_e=`${JSON.stringify(Ge,void 0,2)}
3
- `,Qe=Us(We),Je=Gs(Ge),ge=g(r,rc),Mt=E(ge),x=g(r,"_generated");if(e.dryRun||(E(x)||Vt(x,{recursive:!0}),$(g(x,"app.ts"),Be),$(g(x,"dataModel.ts"),Le),$(g(x,"api.ts"),Fe),$(g(x,"server.ts"),Te),$(g(x,"functions.ts"),De),$(g(x,"shard.ts"),Ce),$(g(x,"crons.ts"),ze),$(g(x,"vectors.ts"),qe),$(g(x,"drizzle.global.ts"),j.global),$(g(x,"drizzle.shard.ts"),j.shard),P(g(x,"containers.ts"),Ke),P(g(x,"workflows.ts"),Re),P(g(x,"agents.ts"),Me),P(g(x,"queues.ts"),je),P(g(x,"seed.ts"),Ve),P(g(x,"collections.ts"),ke),P(g(x,"openapi.json"),le?He:""),P(g(x,"openapi.ts"),le?Qe:""),P(g(x,"openrpc.json"),de?_e:""),P(g(x,"openrpc.ts"),de?Je:""),(!Mt||e.updateSchemaBaseline===!0)&&$(ge,Wt(ue))),t){const m=pe.now(),jt=Math.round(m-s),zt=Math.round(Oe-s),qt=Math.round(m-Oe);console.error(`@lunora/codegen: codegen took ${jt.toString()}ms (discovery ${zt.toString()}ms, emit ${qt.toString()}ms)`)}return{advisories:be,agents:b,containers:C,cronTriggers:ms(J),generated:{agents:Me,api:Fe,app:Be,collections:ke,containers:Ke,crons:ze,dataModel:Le,drizzleGlobal:j.global,drizzleShard:j.shard,functions:De,openApi:He,openApiModule:Qe,openRpc:_e,openRpcModule:Je,queues:je,seed:Ve,server:Te,shard:Ce,vectors:qe,workflows:Re},outputDirectory:x,queues:D,schemaSnapshot:ue,schemaSnapshotPath:ge,workflows:v}};export{rc as SCHEMA_SNAPSHOT_FILENAME,cc as createCodegenProject,Hc as refreshCodegenProject,_c as runCodegen};
@@ -1 +0,0 @@
1
- import{SyntaxKind as u,Node as n}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as g}from"./discoverFunctions-DnqHgv0t.mjs";const p=new Set(["withIndex","withSearchIndex"]),x=r=>{const e=r.getExpression();if(!n.isPropertyAccessExpression(e)||e.getName()!=="query")return!1;const t=e.getExpression();return n.isPropertyAccessExpression(t)?t.getName()==="db":n.isIdentifier(t)&&t.getText()==="db"},d=r=>{const e=[];let t=r;for(;;){const s=t.getParent();if(!s||!n.isPropertyAccessExpression(s))break;const o=s.getParent();if(!o||!n.isCallExpression(o))break;e.push(s.getName()),t=o}return e},h=r=>{const e=r.getArguments()[0];return e&&n.isStringLiteral(e)?e.getLiteralText():""},P=(r,e)=>{const t=[];for(const s of f(e)){const o=r.getSourceFile(s)??r.addSourceFileAtPath(s),c=g(e,s);for(const i of o.getDescendantsOfKind(u.CallExpression)){if(!x(i))continue;const a=d(i);a.includes("filter")&&t.push({file:c,hasFilter:!0,hasIndex:a.some(l=>p.has(l)),line:i.getStartLineNumber(),table:h(i)})}}return t};export{P as default};
@@ -1,2 +0,0 @@
1
- import{runAdvisor as i}from"@lunora/advisor";const n=e=>[...e.indexes.map(s=>({fields:s.fields,kind:"index",name:s.name,unique:s.unique})),...e.searchIndexes.map(s=>({fields:[s.field,...s.filterFields??[]],kind:"search",name:s.name})),...e.rankIndexes.map(s=>({fields:[...s.sortBy.map(a=>a.field),...s.partitionBy??[]],kind:"rank",name:s.name})),...e.vectorIndexes.filter(s=>s.field!==void 0).map(s=>({fields:[s.field],kind:"vector",name:s.name})),...(e.geoIndexes??[]).map(s=>({fields:[s.field],kind:"geo",name:s.name}))],r=e=>{const s={};for(const[a,t]of Object.entries(e.shape))s[a]=t.kind==="optional"?t.inner?.kind??"optional":t.kind;return s},l=e=>({rlsMode:e.rlsMode,tables:e.tables.map(s=>({externallyManaged:s.externallyManaged??!1,externalSource:s.externalSource?{hasReconcile:s.externalSource.hasReconcile??!1,hasSoftDelete:s.externalSource.hasSoftDelete??!1,hasTenantBy:s.externalSource.hasTenantBy,mode:s.externalSource.mode,unanalyzable:s.externalSource.unanalyzable}:void 0,columnKinds:r(s),fields:Object.keys(s.shape),indexes:n(s),isPublic:s.isPublic??!1,name:s.name,relations:s.relations.map(a=>({field:a.field,kind:a.kind,name:a.name,onDelete:a.onDelete,references:a.references,table:a.table})),shardKind:typeof s.shardMode=="string"?s.shardMode:"shardBy",softDelete:s.softDelete,ttl:s.ttl}))}),o=e=>e.map(s=>({exportName:s.exportName,file:`lunora/${s.filePath}.ts`,table:s.table})),d=e=>i({adminRoutes:e.adminRoutes,aiRawRuns:e.aiRawRuns,aiToolSideEffects:e.aiToolSideEffects,argumentDerivedFetches:e.argumentDerivedFetches,argValidators:e.argumentValidators,authApiCalls:e.authApiCalls,authConfigs:e.authConfigs,browserUrlAccesses:e.browserUrlAccesses,configCalls:e.configCalls,containerKeyAccesses:e.containerKeyAccesses,containerOverrides:e.containerOverrides,containers:e.containers,exportSinks:e.exportSinks,failOpenGuards:e.failOpenGuards,flagSecurityDefaults:e.flagSecurityDefaults,geoIndexUsages:e.geoIndexUsages,httpActionGuards:e.httpActionGuards,httpHeaderWrites:e.httpHeaderWrites,identityClaimReads:e.identityClaimReads,imageDeliveryUrlAccesses:e.imageDeliveryUrlAccesses,inserts:e.inserts,kvKeyAccesses:e.kvKeyAccesses,mailRecipientAccesses:e.mailRecipientAccesses,maskProcedures:e.maskProcedures,maskStrategies:e.maskStrategies,mutatorWrites:e.mutatorWrites,nondeterministicCalls:e.nondeterministicCalls,normalizeIdAuthorizations:e.normalizeIdAuthorizations,notifyCalls:e.notifyCalls,notifyConfig:e.notifyConfig,ownerFieldWrites:e.ownerFieldWrites,unrestrictedWhereBranches:e.unrestrictedWhereBranches,paymentWebhooks:e.paymentWebhooks,privilegedDispatches:e.privilegedDispatches,procedureProtections:e.procedureProtections,queries:e.queries??[],queues:e.queues,r2sqlCalls:e.r2sqlCalls,ratelimitKeySelectors:e.ratelimitKeySelectors,rawRowReturns:e.rawRowReturns,relationLoads:e.relationLoads,rlsProcedures:e.rlsProcedures,schema:l(e.schema),secretLiterals:e.secretLiterals,shapes:e.shapes===void 0?void 0:o(e.shapes),softDeleteReads:e.softDeleteReads,sqlInterpolations:e.sqlInterpolations,storageKeyAccesses:e.storageKeyAccesses,storageUploads:e.storageUploads,vectorNamespaceAccesses:e.vectorNamespaceAccesses,workflowCalls:e.workflowCalls,workflows:e.workflows,wranglerVariables:e.wranglerVariables},{source:"static"}),m=e=>{if(e.length===0)return"";const s=`@lunora/codegen: ${String(e.length)} schema advisor finding${e.length===1?"":"s"}`,a=e.map(t=>` [${t.level}] ${t.name}: ${t.detail}`);return[s,...a].join(`
2
- `)};export{m as formatAdvisories,d as lintSchema};