@lunora/codegen 1.0.0-alpha.7 → 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.
- package/LICENSE.md +6 -0
- package/__assets__/package-og.svg +1 -1
- package/dist/index.d.mts +2098 -736
- package/dist/index.d.ts +2098 -736
- package/dist/index.mjs +1 -29
- package/dist/packem_shared/AGENTS_FILENAME-BesaDYkL.mjs +1 -0
- package/dist/packem_shared/CONTAINERS_FILENAME-CFwdyaCI.mjs +1 -0
- package/dist/packem_shared/CodegenDiagnosticError-DPezpZTz.mjs +1 -0
- package/dist/packem_shared/FLAGS_FILENAME-C1GWerCB.mjs +1 -0
- package/dist/packem_shared/GENERATED_HEADER-DV-sQj-R.mjs +1 -0
- package/dist/packem_shared/LUNORA_ERROR_CODES-Um9hC1gr.mjs +1 -0
- package/dist/packem_shared/MUTATORS_FILENAME-BWPAtQ2T.mjs +1 -0
- package/dist/packem_shared/NOTIFY_FILENAME-DP6qvFBX.mjs +1 -0
- package/dist/packem_shared/OPENRPC_VERSION-CvVFqUlq.mjs +3 -0
- package/dist/packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs +1 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CDCj-7wp.mjs +3 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-Bpf1FGMG.mjs +15 -0
- package/dist/packem_shared/SHAPES_FILENAME-maut3z1K.mjs +1 -0
- package/dist/packem_shared/WORKFLOWS_FILENAME-Bk5upkGM.mjs +1 -0
- package/dist/packem_shared/buildOpenApiDocument-CXFC-wzM.mjs +3 -0
- package/dist/packem_shared/discover-ast-CezKqEhE.mjs +1 -0
- package/dist/packem_shared/discoverAuthApiCalls-Ba6W92HB.mjs +1 -0
- package/dist/packem_shared/discoverCrons-2nUpw6do.mjs +1 -0
- package/dist/packem_shared/discoverFunctions-zrIQk7J8.mjs +1 -0
- package/dist/packem_shared/discoverHttpRoutes-Bf_T_03b.mjs +1 -0
- package/dist/packem_shared/discoverInserts-DveVeP5h.mjs +1 -0
- package/dist/packem_shared/discoverMaskProcedures-BkBquCFR.mjs +1 -0
- package/dist/packem_shared/discoverMigrations-T2xb-1rn.mjs +1 -0
- package/dist/packem_shared/discoverNondeterministicCalls-BymnOR9k.mjs +1 -0
- package/dist/packem_shared/discoverQueries-DNRA-G2a.mjs +1 -0
- package/dist/packem_shared/discoverR2sqlCalls-YEjvGcEq.mjs +1 -0
- package/dist/packem_shared/discoverRlsMetadata-DO3qlLXX.mjs +1 -0
- package/dist/packem_shared/discoverSandboxUsage-JwrmSN9l.mjs +1 -0
- package/dist/packem_shared/discoverSchema-Cy4OQ0Cu.mjs +1 -0
- package/dist/packem_shared/discoverStorageRulesMetadata-CCztRKjw.mjs +1 -0
- package/dist/packem_shared/emit-D7VIjvlm.mjs +2152 -0
- package/dist/packem_shared/emitApp-CAeIj6e_.mjs +444 -0
- package/dist/packem_shared/formatAdvisories-DZvv-0MG.mjs +2 -0
- package/dist/packem_shared/module-specifiers-8FEEiUcv.mjs +1 -0
- package/dist/packem_shared/parse-validator-CSDlMEvE.mjs +1 -0
- package/dist/packem_shared/paths-BmX5O1sG.mjs +1 -0
- package/dist/packem_shared/redact-CQ8-to6l.mjs +1 -0
- package/dist/packem_shared/schemaFromIr-R1ZFzVyy.mjs +1 -0
- package/package.json +10 -7
- package/dist/packem_shared/CONTAINERS_FILENAME-0K-pjNb8.mjs +0 -224
- package/dist/packem_shared/CodegenDiagnosticError-54jWDxA9.mjs +0 -22
- package/dist/packem_shared/GENERATED_HEADER-DF1hQcix.mjs +0 -2495
- package/dist/packem_shared/LUNORA_ERROR_CODES-CySpQPD3.mjs +0 -61
- package/dist/packem_shared/OPENRPC_VERSION-C7zKVeKi.mjs +0 -60
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-g7kpX8hu.mjs +0 -922
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-DzLDbWk3.mjs +0 -233
- package/dist/packem_shared/WORKFLOWS_FILENAME-DRDQdhfq.mjs +0 -84
- package/dist/packem_shared/buildOpenApiDocument-Cns1EkCQ.mjs +0 -183
- package/dist/packem_shared/discover-ast-CT6BgBr4.mjs +0 -13
- package/dist/packem_shared/discoverAuthApiCalls-C35R6z0T.mjs +0 -62
- package/dist/packem_shared/discoverCrons-BL6iGuJ3.mjs +0 -254
- package/dist/packem_shared/discoverFunctions-DEgAcRuD.mjs +0 -460
- package/dist/packem_shared/discoverHttpRoutes-C978pBiG.mjs +0 -131
- package/dist/packem_shared/discoverInserts-pLBFsSAV.mjs +0 -61
- package/dist/packem_shared/discoverMaskProcedures-B64zA740.mjs +0 -217
- package/dist/packem_shared/discoverMigrations-Doj_-BAA.mjs +0 -91
- package/dist/packem_shared/discoverNondeterministicCalls-4KiPQxQU.mjs +0 -122
- package/dist/packem_shared/discoverQueries-BkIi0dBD.mjs +0 -62
- package/dist/packem_shared/discoverR2sqlCalls-BpDqvcUn.mjs +0 -80
- package/dist/packem_shared/discoverRlsMetadata-DpRB1HMe.mjs +0 -280
- package/dist/packem_shared/discoverSchema-DYl0QfDH.mjs +0 -775
- package/dist/packem_shared/discoverStorageRulesMetadata-DAqJUxUv.mjs +0 -97
- package/dist/packem_shared/emitApp-Ci_hcJNO.mjs +0 -599
- package/dist/packem_shared/formatAdvisories-8NIv1k0I.mjs +0 -69
- package/dist/packem_shared/parse-validator-tuQtHrsr.mjs +0 -132
- package/dist/packem_shared/paths-BRd6JHuF.mjs +0 -11
- package/dist/packem_shared/schemaFromIr-DTYsLBaA.mjs +0 -57
package/dist/index.mjs
CHANGED
|
@@ -1,29 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { CodegenDiagnosticError, diagnosticAt } from './packem_shared/CodegenDiagnosticError-54jWDxA9.mjs';
|
|
3
|
-
export { default as discoverAuthApiCalls } from './packem_shared/discoverAuthApiCalls-C35R6z0T.mjs';
|
|
4
|
-
export { CONTAINERS_FILENAME, discoverContainers } from './packem_shared/CONTAINERS_FILENAME-0K-pjNb8.mjs';
|
|
5
|
-
export { default as discoverCrons } from './packem_shared/discoverCrons-BL6iGuJ3.mjs';
|
|
6
|
-
export { discoverFunctions } from './packem_shared/discoverFunctions-DEgAcRuD.mjs';
|
|
7
|
-
export { default as discoverHttpRoutes } from './packem_shared/discoverHttpRoutes-C978pBiG.mjs';
|
|
8
|
-
export { default as discoverInserts } from './packem_shared/discoverInserts-pLBFsSAV.mjs';
|
|
9
|
-
export { default as discoverMaskProcedures } from './packem_shared/discoverMaskProcedures-B64zA740.mjs';
|
|
10
|
-
export { default as discoverMigrations } from './packem_shared/discoverMigrations-Doj_-BAA.mjs';
|
|
11
|
-
export { default as discoverNondeterministicCalls } from './packem_shared/discoverNondeterministicCalls-4KiPQxQU.mjs';
|
|
12
|
-
export { default as discoverQueries } from './packem_shared/discoverQueries-BkIi0dBD.mjs';
|
|
13
|
-
export { default as discoverR2sqlCalls } from './packem_shared/discoverR2sqlCalls-BpDqvcUn.mjs';
|
|
14
|
-
export { discoverRlsMetadata, default as discoverRlsProcedures } from './packem_shared/discoverRlsMetadata-DpRB1HMe.mjs';
|
|
15
|
-
export { default as discoverSchema } from './packem_shared/discoverSchema-DYl0QfDH.mjs';
|
|
16
|
-
export { default as discoverStorageRulesMetadata } from './packem_shared/discoverStorageRulesMetadata-DAqJUxUv.mjs';
|
|
17
|
-
export { WORKFLOWS_FILENAME, discoverWorkflows } from './packem_shared/WORKFLOWS_FILENAME-DRDQdhfq.mjs';
|
|
18
|
-
export { GENERATED_HEADER, emitApi, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers } from './packem_shared/GENERATED_HEADER-DF1hQcix.mjs';
|
|
19
|
-
export { emitApp } from './packem_shared/emitApp-Ci_hcJNO.mjs';
|
|
20
|
-
export { buildOpenApiDocument, emitOpenApi, emitOpenApiModule } from './packem_shared/buildOpenApiDocument-Cns1EkCQ.mjs';
|
|
21
|
-
export { OPENRPC_VERSION, buildOpenRpcDocument, emitOpenRpc, emitOpenRpcModule } from './packem_shared/OPENRPC_VERSION-C7zKVeKi.mjs';
|
|
22
|
-
export { SCHEMA_SNAPSHOT_FILENAME, createCodegenProject, refreshCodegenProject, runCodegen } from './packem_shared/SCHEMA_SNAPSHOT_FILENAME-g7kpX8hu.mjs';
|
|
23
|
-
export { SCHEMA_SNAPSHOT_VERSION, SchemaSnapshotParseError, buildSchemaSnapshot, diffSchemaSnapshots, evaluateSchemaDrift, parseSchemaSnapshot, serializeSchemaSnapshot } from './packem_shared/SCHEMA_SNAPSHOT_VERSION-DzLDbWk3.mjs';
|
|
24
|
-
export { schemaFromIr } from './packem_shared/schemaFromIr-DTYsLBaA.mjs';
|
|
25
|
-
export { LUNORA_ERROR_CODES, validatorIrToJsonSchema } from './packem_shared/LUNORA_ERROR_CODES-CySpQPD3.mjs';
|
|
26
|
-
|
|
27
|
-
const VERSION = "0.0.0";
|
|
28
|
-
|
|
29
|
-
export { VERSION };
|
|
1
|
+
import{formatAdvisories as t,lintSchema as s}from"./packem_shared/formatAdvisories-DZvv-0MG.mjs";import{CodegenDiagnosticError as i,diagnosticAt as m}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as f,discoverAgents as p}from"./packem_shared/AGENTS_FILENAME-BesaDYkL.mjs";import{default as n}from"./packem_shared/discoverAuthApiCalls-Ba6W92HB.mjs";import{CONTAINERS_FILENAME as l,discoverContainers as E}from"./packem_shared/CONTAINERS_FILENAME-CFwdyaCI.mjs";import{default as u}from"./packem_shared/discoverCrons-2nUpw6do.mjs";import{FLAGS_FILENAME as v,discoverFlags as N}from"./packem_shared/FLAGS_FILENAME-C1GWerCB.mjs";import{discoverFunctions as M}from"./packem_shared/discoverFunctions-zrIQk7J8.mjs";import{default as h}from"./packem_shared/discoverHttpRoutes-Bf_T_03b.mjs";import{default as _}from"./packem_shared/discoverInserts-DveVeP5h.mjs";import{default as g}from"./packem_shared/discoverMaskProcedures-BkBquCFR.mjs";import{default as F}from"./packem_shared/discoverMigrations-T2xb-1rn.mjs";import{MUTATORS_FILENAME as P,discoverMutators as D}from"./packem_shared/MUTATORS_FILENAME-BWPAtQ2T.mjs";import{default as H}from"./packem_shared/discoverNondeterministicCalls-BymnOR9k.mjs";import{NOTIFY_FILENAME as G,discoverNotifyCalls as W,discoverNotifyConfig as V}from"./packem_shared/NOTIFY_FILENAME-DP6qvFBX.mjs";import{default as w}from"./packem_shared/discoverQueries-DNRA-G2a.mjs";import{QUEUES_FILENAME as z,discoverQueues as Q}from"./packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs";import{default as B}from"./packem_shared/discoverR2sqlCalls-YEjvGcEq.mjs";import{discoverRlsMetadata as K,default as q}from"./packem_shared/discoverRlsMetadata-DO3qlLXX.mjs";import{discoverSandboxUsage as X}from"./packem_shared/discoverSandboxUsage-JwrmSN9l.mjs";import{default as $}from"./packem_shared/discoverSchema-Cy4OQ0Cu.mjs";import{SHAPES_FILENAME as oe,discoverShapes as re}from"./packem_shared/SHAPES_FILENAME-maut3z1K.mjs";import{default as se}from"./packem_shared/discoverStorageRulesMetadata-CCztRKjw.mjs";import{WORKFLOWS_FILENAME as ie,discoverWorkflows as me}from"./packem_shared/WORKFLOWS_FILENAME-Bk5upkGM.mjs";import{w as fe,B as pe,s as ce,c as ne,_ as Se,t as le,G as Ee,e as xe,b as ue,h as Ae,J as ve,n as Ne,M as Oe,r as Me}from"./packem_shared/emit-D7VIjvlm.mjs";import{emitApp as he}from"./packem_shared/emitApp-CAeIj6e_.mjs";import{buildOpenApiDocument as _e,emitOpenApi as Ie,emitOpenApiModule as ge}from"./packem_shared/buildOpenApiDocument-CXFC-wzM.mjs";import{OPENRPC_VERSION as Fe,buildOpenRpcDocument as Te,emitOpenRpc as Pe,emitOpenRpcModule as De}from"./packem_shared/OPENRPC_VERSION-CvVFqUlq.mjs";import{SCHEMA_SNAPSHOT_FILENAME as He,createCodegenProject as be,refreshCodegenProject as Ge,runCodegen as We}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-CDCj-7wp.mjs";import{SCHEMA_SNAPSHOT_VERSION as ke,SchemaSnapshotParseError as we,buildSchemaSnapshot as ye,diffSchemaSnapshots as ze,evaluateSchemaDrift as Qe,parseSchemaSnapshot as je,serializeSchemaSnapshot as Be}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-Bpf1FGMG.mjs";import{schemaFromIr as Ke}from"./packem_shared/schemaFromIr-R1ZFzVyy.mjs";import{LUNORA_ERROR_CODES as Ye,validatorIrToJsonSchema as Xe}from"./packem_shared/LUNORA_ERROR_CODES-Um9hC1gr.mjs";import{redact as $e,secretKindOf as eo}from"./packem_shared/redact-CQ8-to6l.mjs";import{MESSAGE_SOLUTIONS as ro,findSolutionByMessage as to}from"@lunora/errors";const e="0.0.0";export{f as AGENTS_FILENAME,l as CONTAINERS_FILENAME,i as CodegenDiagnosticError,v as FLAGS_FILENAME,fe as GENERATED_HEADER,Ye as LUNORA_ERROR_CODES,ro as LUNORA_SOLUTION_RULES,P as MUTATORS_FILENAME,G as NOTIFY_FILENAME,Fe as OPENRPC_VERSION,z as QUEUES_FILENAME,He as SCHEMA_SNAPSHOT_FILENAME,ke as SCHEMA_SNAPSHOT_VERSION,oe as SHAPES_FILENAME,we as SchemaSnapshotParseError,e as VERSION,ie as WORKFLOWS_FILENAME,_e as buildOpenApiDocument,Te as buildOpenRpcDocument,ye as buildSchemaSnapshot,be as createCodegenProject,m as diagnosticAt,ze as diffSchemaSnapshots,p as discoverAgents,n as discoverAuthApiCalls,E as discoverContainers,u as discoverCrons,N as discoverFlags,M as discoverFunctions,h as discoverHttpRoutes,_ as discoverInserts,g as discoverMaskProcedures,F as discoverMigrations,D as discoverMutators,H as discoverNondeterministicCalls,W as discoverNotifyCalls,V as discoverNotifyConfig,w as discoverQueries,Q as discoverQueues,B as discoverR2sqlCalls,K as discoverRlsMetadata,q as discoverRlsProcedures,X as discoverSandboxUsage,$ as discoverSchema,re as discoverShapes,se as discoverStorageRulesMetadata,me as discoverWorkflows,pe as emitAgents,ce as emitApi,he as emitApp,ne as emitCollections,Se as emitContainers,le as emitCrons,Ee as emitDataModel,xe as emitDrizzleSchema,ue as emitFunctions,Ie as emitOpenApi,ge as emitOpenApiModule,Pe as emitOpenRpc,De as emitOpenRpcModule,Ae as emitServer,ve as emitShard,Ne as emitVectors,Oe as emitWorkflows,Me as emitWranglerCronTriggers,Qe as evaluateSchemaDrift,to as findLunoraSolution,t as formatAdvisories,s as lintSchema,je as parseSchemaSnapshot,$e as redact,Ge as refreshCodegenProject,We as runCodegen,Ke as schemaFromIr,eo as secretKindOf,Be as serializeSchemaSnapshot,Xe as validatorIrToJsonSchema};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync as u}from"node:fs";import{join as p}from"node:path";import{agentDefaultName as d,agentClassName as f,agentBindingName as N,voiceBindingName as b,voiceClassName as x}from"@lunora/agent/naming";import{LunoraError as m}from"@lunora/errors";import{Node as o,SyntaxKind as l}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-DPezpZTz.mjs";const w="agents.ts",A=i=>{const e=i.getSymbol();if(!e)return i.getText()==="defineAgent";for(const n of e.getDeclarations())if(o.isImportSpecifier(n))return n.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/agent"?!1:n.getNameNode().getText()==="defineAgent";return!1},E=(i,e,n)=>{if(o.isStringLiteral(i)||o.isNoSubstitutionTemplateLiteral(i))return i.getLiteralValue();throw g(i,`agent "${e}": \`${n}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)},h=(i,e,n)=>{if(i.getKind()===l.TrueKeyword)return!0;if(i.getKind()===l.FalseKeyword)return!1;throw g(i,`agent "${e}": \`${n}\` must be a static boolean literal — it is deploy configuration codegen writes into the ctx.agents wiring spec`)},y=(i,e)=>{const n=i.getArguments()[0];if(!n||!o.isObjectLiteralExpression(n))throw g(i,`agent "${e}": defineAgent must be passed an inline object literal`);const r={bindingName:N(e),className:f(e),exportName:e,name:d(e)},t=n.getProperty("name");t&&o.isPropertyAssignment(t)&&(r.name=E(t.getInitializerOrThrow(),e,"name"));const s=n.getProperty("publicRun");s&&o.isPropertyAssignment(s)&&h(s.getInitializerOrThrow(),e,"publicRun")&&(r.publicRun=!0);const a=n.getProperty("voice");if(a&&o.isPropertyAssignment(a)){const c=a.getInitializerOrThrow();if(!o.isObjectLiteralExpression(c))throw g(c,`agent "${e}": \`voice\` must be an inline object literal — its presence tells codegen to emit the voice-session Durable Object`);r.voice=!0,r.voiceBindingName=b(e),r.voiceClassName=x(e)}return n.getProperty("onEmail")&&(r.onEmail=!0),r},I=i=>{let e=i;for(;e&&(o.isAsExpression(e)||o.isSatisfiesExpression(e)||o.isParenthesizedExpression(e));)e=e.getExpression();return e&&o.isCallExpression(e)?e:void 0},T=i=>{const e=[];for(const n of i.getVariableDeclarations()){if(!n.isExported())continue;const r=I(n.getInitializer());if(!r)continue;const t=r.getExpression();if(!o.isIdentifier(t)||!A(t))continue;const s=n.getNameNode();if(!o.isIdentifier(s))throw g(s,"defineAgent exports must be plain named exports (no destructuring)");e.push(y(r,s.getText()))}return e},$=i=>{const e=new Map,n=new Map,r=new Map;for(const t of i){const s=e.get(t.name);if(s!==void 0)throw new m("DUPLICATE_AGENT_NAME",`Duplicate agent name "${t.name}": produced by both "${s}" and "${t.exportName}". Deployed agent names must be unique across the project.`,{status:500});e.set(t.name,t.exportName);const a=n.get(t.bindingName);if(a!==void 0)throw new m("DUPLICATE_AGENT_BINDING",`Duplicate agent binding "${t.bindingName}": produced by both "${a}" and "${t.exportName}". Agent export names must yield unique binding names.`,{status:500});n.set(t.bindingName,t.exportName);const c=r.get(t.className);if(c!==void 0)throw new m("DUPLICATE_AGENT_CLASS",`Duplicate agent class "${t.className}": produced by both "${c}" and "${t.exportName}". Agent export names must yield unique generated class names.`,{status:500});r.set(t.className,t.exportName)}},j=(i,e)=>{const n=p(e,w);if(!u(n))return[];const r=i.getSourceFile(n)??i.addSourceFileAtPath(n),t=T(r);return t.sort((s,a)=>s.exportName.localeCompare(a.exportName)),$(t),t};export{w as AGENTS_FILENAME,j as discoverAgents};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync as f}from"node:fs";import{join as p}from"node:path";import{containerClassName as d,containerBindingName as b,normalizeContainerImage as g}from"@lunora/container";import{SyntaxKind as y,Node as n}from"ts-morph";import{diagnosticAt as s}from"./CodegenDiagnosticError-DPezpZTz.mjs";const L="containers.ts",N=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineContainer";for(const i of t.getDeclarations())if(n.isImportSpecifier(i))return i.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/container"?!1:i.getNameNode().getText()==="defineContainer";return!1},u=(e,t,i)=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw s(e,`container "${t}": \`${i}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)},m=(e,t,i)=>{if(n.isNumericLiteral(e))return e.getLiteralValue();throw s(e,`container "${t}": \`${i}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},x=(e,t)=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e))return g(e.getLiteralValue());if(n.isObjectLiteralExpression(e)){const i=e.getProperty("registry");if(i&&n.isPropertyAssignment(i)){const o=i.getInitializerOrThrow();return g({registry:u(o,t,"image.registry")})}const r=e.getProperty("build");if(r&&n.isPropertyAssignment(r)){const o=r.getInitializerOrThrow();return g({build:u(o,t,"image.build")})}}throw s(e,`container "${t}": \`image\` must be a static string path, { registry: "…" }, or { build: "…" } literal`)},h=e=>{if(!n.isObjectLiteralExpression(e))return;const t={};for(const i of e.getProperties()){if(!n.isPropertyAssignment(i))continue;const r=i.getInitializerOrThrow();(n.isStringLiteral(r)||n.isNoSubstitutionTemplateLiteral(r))&&(t[i.getName()]=r.getLiteralValue())}return Object.keys(t).length>0?t:void 0},w=e=>{if(!n.isObjectLiteralExpression(e))return;const t={};for(const i of e.getProperties()){if(!n.isPropertyAssignment(i))continue;const r=i.getName(),o=i.getInitializerOrThrow();n.isNumericLiteral(o)&&(r==="gracePeriodSeconds"||r==="stepPercentage")&&(t[r]=o.getLiteralValue())}return t.gracePeriodSeconds===void 0&&t.stepPercentage===void 0?void 0:t},T=e=>{if(n.isTrueLiteral(e))return!0;if(n.isFalseLiteral(e))return!1},I=e=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)||n.isNumericLiteral(e))return e.getLiteralValue()},S=(e,t)=>{if(n.isStringLiteral(e))return e.getLiteralValue();if(n.isObjectLiteralExpression(e)){const i={};for(const r of e.getProperties()){if(!n.isPropertyAssignment(r))throw s(r,`container "${t}": \`instanceType\` must be an object of static number literals`);const o=r.getName();if(o!=="diskMb"&&o!=="memoryMib"&&o!=="vcpu")throw s(r,`container "${t}": unknown \`instanceType\` field "${o}" — expected vcpu, memoryMib, or diskMb`);i[o]=m(r.getInitializerOrThrow(),t,`instanceType.${o}`)}return i}throw s(e,`container "${t}": \`instanceType\` must be a static string or { vcpu, memoryMib, diskMb } literal`)},P=(e,t)=>{const i=e.getArguments()[0];if(!i||!n.isObjectLiteralExpression(i))throw s(e,`container "${t}": defineContainer must be passed an inline object literal`);const r={bindingName:b(t),className:d(t),exportName:t,image:{buildContext:".",dockerfilePath:"./Dockerfile",kind:"dockerfile"}};let o=!1;for(const a of i.getProperties()){if(!n.isPropertyAssignment(a))continue;const l=a.getName(),c=a.getInitializerOrThrow();switch(l){case"buildArgs":{r.buildArgs=h(c);break}case"enableInternet":{r.enableInternet=T(c);break}case"image":{r.image=x(c,t),o=!0;break}case"instanceType":{r.instanceType=S(c,t);break}case"maxInstances":{r.maxInstances=m(c,t,"maxInstances");break}case"name":{r.name=u(c,t,"name");break}case"rollout":{r.rollout=w(c);break}case"sleepAfter":{r.sleepAfter=I(c);break}}}if(!o)throw s(i,`container "${t}": defineContainer requires a static \`image\` property`);return r},k=e=>{const t=[];for(const i of e.getVariableDeclarations()){if(!i.isExported())continue;const r=i.getInitializer();if(r?.getKind()!==y.CallExpression)continue;const o=r,a=o.getExpression();if(!n.isIdentifier(a)||!N(a))continue;const l=i.getNameNode();if(!n.isIdentifier(l))throw s(l,"defineContainer exports must be plain named exports (no destructuring)");t.push(P(o,l.getText()))}return t},j=(e,t)=>{const i=p(t,L);if(!f(i))return[];const r=e.getSourceFile(i)??e.addSourceFileAtPath(i),o=k(r);return o.sort((a,l)=>a.exportName.localeCompare(l.exportName)),o};export{L as CONTAINERS_FILENAME,j as discoverContainers};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as g}from"@lunora/errors";class a extends g{column;file;line;constructor(i,e,n,t){super("CODEGEN_DIAGNOSTIC",i,{location:{column:t,file:e,line:n},name:"CodegenDiagnosticError"}),this.file=e,this.line=n,this.column=t}}const m=(o,i,e)=>{const n=o.getSourceFile(),t=n.getFilePath(),r=o.getStartLineNumber(),{column:c}=n.getLineAndColumnAtPos(o.getStart()),l=`@lunora/codegen: ${i} (${t}:${r.toString()}:${c.toString()})`,s=new a(l,t,r,c);return e?Object.assign(s,e):s};export{a as CodegenDiagnosticError,m as diagnosticAt};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync as l}from"node:fs";import{join as c}from"node:path";import{SyntaxKind as p,Node as s}from"ts-morph";import{listLunoraSourceFiles as f}from"./discoverFunctions-zrIQk7J8.mjs";const u="flags.ts",d=new Set(["boolean","number","object","string"]),m="@lunora/flags/providers/flagship",x=r=>{const t=r.getSymbol();if(!t)return r.getText()==="flagshipProvider";for(const e of t.getDeclarations())if(s.isImportSpecifier(e))return e.getImportDeclaration().getModuleSpecifierValue()!==m?!1:e.getNameNode().getText()==="flagshipProvider";return!1},y=(r,t)=>{const e=r.getProperty(t);if(!e||!s.isPropertyAssignment(e))return;const i=e.getInitializerOrThrow();if(s.isStringLiteral(i)||s.isNoSubstitutionTemplateLiteral(i))return i.getLiteralValue()},E=r=>{const t=r.getArguments()[0];if(t&&s.isObjectLiteralExpression(t)){const e=y(t,"binding");if(e!==void 0&&e.length>0)return{bindingName:e,mode:"binding",provider:"flagship"}}return{mode:"http",provider:"flagship"}},S=r=>{const t=r.getExportAssignment(n=>!n.isExportEquals());if(!t)return;const e=t.getExpression();if(!s.isIdentifier(e))return e;const i=e.getSymbol()?.getValueDeclaration();return i&&s.isVariableDeclaration(i)?i.getInitializer():e},b=r=>{const t=r.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))return;const e=t.getProperty("provider");return e&&s.isPropertyAssignment(e)?e.getInitializer():void 0},F=(r,t)=>{const e=c(t,u);if(!l(e))return;const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),n=S(i);if(!n||!s.isCallExpression(n))return{provider:"custom"};const a=b(n);if(a&&s.isCallExpression(a)){const o=a.getExpression();if(s.isIdentifier(o)&&x(o))return E(a)}return{provider:"custom"}},g=r=>s.isIdentifier(r)&&r.getText()==="ctx",h=r=>{const t=r.getName();if(!d.has(t))return;const e=r.getExpression();if(!s.isPropertyAccessExpression(e))return;if(e.getName()==="flags"&&g(e.getExpression()))return t;const i=e.getExpression();if(e.getName()==="details"&&s.isPropertyAccessExpression(i)&&i.getName()==="flags"&&g(i.getExpression()))return t},v=r=>{const t=r.getExpression();if(!s.isPropertyAccessExpression(t))return;const e=h(t);if(e===void 0)return;const i=r.getArguments()[0];if(!i||!(s.isStringLiteral(i)||s.isNoSubstitutionTemplateLiteral(i)))return;const n=i.getLiteralValue();return n.length>0?{key:n,type:e}:void 0},I=(r,t)=>{const e=new Map;for(const i of f(t)){const n=r.getSourceFile(i)??r.addSourceFileAtPath(i);for(const a of n.getDescendantsOfKind(p.CallExpression)){const o=v(a);o&&!e.has(o.key)&&e.set(o.key,o.type)}}return[...e.entries()].map(([i,n])=>({key:i,type:n})).toSorted((i,n)=>i.key.localeCompare(n.key))};export{u as FLAGS_FILENAME,I as discoverFlagKeys,F as discoverFlags};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"@lunora/agent/component";import"@lunora/errors";import{w as m,d as r,B as o,s as n,c as l,_ as c,t as d,G as g,e as p,b as u,j as C,l as E,h as S,J as A,n as D,M as h,r as b}from"./emit-D7VIjvlm.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,d as emitCrons,g as emitDataModel,p as emitDrizzleSchema,u as emitFunctions,C as emitQueues,E as emitSeed,S as emitServer,A as emitShard,D as emitVectors,h as emitWorkflows,b as emitWranglerCronTriggers};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsonSchemaFromNode as n,objectSchemaFromNodes as a}from"@lunora/values";const N=e=>{if(e===void 0)return{};const t=e.trim();if(t==="true")return{const:!0};if(t==="false")return{const:!1};if(t==="null")return{const:null,type:"null"};if(t.startsWith('"')&&t.endsWith('"'))try{return{const:JSON.parse(t),type:"string"}}catch{return{const:t.slice(1,-1),type:"string"}}if(t.startsWith("'")&&t.endsWith("'"))return{const:t.slice(1,-1),type:"string"};const r=Number(t);return Number.isNaN(r)?{const:t}:{const:r}},s={constraints:()=>{},inner:e=>e.inner,isNullable:e=>e.column?.notNull===!1,kind:e=>e.kind,literalSchema:e=>N(e.literalValue),members:e=>e.members??[],shape:e=>e.shape??{},tableName:e=>e.tableName,valueChild:e=>e.valueType},o=e=>n(e,s),l=e=>a(e,s),O=e=>l(e),c=["BAD_REQUEST","CONFLICT","COUNT_RLS_UNSUPPORTED","FORBIDDEN","FUNCTION_NOT_FOUND","INTERNAL","INTERNAL_SERVER_ERROR","METHOD_NOT_ALLOWED","NOT_FOUND","NOT_IMPLEMENTED","PAYLOAD_TOO_LARGE","TOO_MANY_REQUESTS","UNAUTHORIZED","UNPROCESSABLE","VALIDATION_ERROR"];export{c as LUNORA_ERROR_CODES,O as argsObjectSchema,N as literalConst,l as objectSchema,o as validatorIrToJsonSchema};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync as p}from"node:fs";import{join as m}from"node:path";import{Node as o,SyntaxKind as c}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{unwrapHandlerReturn as g}from"./discoverFunctions-zrIQk7J8.mjs";import{t as d}from"./module-specifiers-8FEEiUcv.mjs";import{d as x}from"./parse-validator-CSDlMEvE.mjs";const y="mutators.ts",f=d,N=r=>{const e=r.getSymbol();if(!e)return r.getText()==="defineMutator";for(const t of e.getDeclarations())if(o.isImportSpecifier(t))return f(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMutator":!1;return!1},E=r=>{const e=r.getSymbol();if(!e)return!1;for(const t of e.getDeclarations()){if(!o.isNamespaceImport(t))continue;const i=t.getFirstAncestorByKind(c.ImportDeclaration);return i!==void 0&&f(i.getModuleSpecifierValue())}return!1},I=r=>{if(o.isIdentifier(r))return N(r);if(o.isPropertyAccessExpression(r)){const e=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(e)&&E(e)}return!1},S=r=>{const e=r.getArguments()[0];return e&&o.isObjectLiteralExpression(e)?e:void 0},A=r=>{const e=r?.getProperty("args");if(!e||!o.isPropertyAssignment(e))return{};const t=e.getInitializer();return t&&o.isObjectLiteralExpression(t)?x(t):{}},M=r=>{const e=r?.getProperty("server");if(!e||!o.isPropertyAssignment(e))return"unknown";const t=e.getInitializer();return!t||!(o.isArrowFunction(t)||o.isFunctionExpression(t))?"unknown":g(t)},P=r=>{const e=[];for(const t of r.getVariableDeclarations()){if(!t.isExported())continue;const i=t.getInitializer();if(i?.getKind()!==c.CallExpression)continue;const n=i,a=n.getExpression();if(!I(a))continue;const s=t.getNameNode();if(!o.isIdentifier(s))throw l(s,"defineMutator exports must be plain named exports (no destructuring)");const u=S(n);e.push({args:A(u),exportName:s.getText(),filePath:"mutators",returnType:M(u)})}return e},j=(r,e)=>{const t=m(e,y);if(!p(t))return[];const i=r.getSourceFile(t)??r.addSourceFileAtPath(t),n=P(i);return n.sort((a,s)=>a.exportName.localeCompare(s.exportName)),n};export{y as MUTATORS_FILENAME,j as discoverMutators,I as isDefineMutatorCallee};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync as x}from"node:fs";import{join as h}from"node:path";import{SyntaxKind as p,Node as o}from"ts-morph";import{listLunoraSourceFiles as l,lunoraRelativePath as m,classifyProcedureCall as y}from"./discoverFunctions-zrIQk7J8.mjs";const E="notify.ts",A=new Set(["chat","inApp","send","webhook"]),d=new Set(["broadcast","send"]),P=(t,r)=>{if(r){const n=t.getArguments()[0];return n&&(o.isArrowFunction(n)||o.isFunctionExpression(n))?n:void 0}const e=t.getArguments()[0];if(!e||!o.isObjectLiteralExpression(e))return;const s=e.getProperty("handler");if(!s||!o.isPropertyAssignment(s))return;const i=s.getInitializer();return i&&(o.isArrowFunction(i)||o.isFunctionExpression(i))?i:void 0},F=t=>{const r=t.getInitializer();if(!r||!o.isCallExpression(r))return;const e=y(r);if(!e)return;const s=P(r,e.receiver);return s?{exportName:t.getName(),handler:s,kind:e.kind}:void 0},g=t=>{const r=[];for(const e of t.getVariableStatements())if(e.isExported())for(const s of e.getDeclarations()){const i=F(s);i&&r.push(i)}return r},f=t=>{if(!o.isPropertyAccessExpression(t))return;const r=t.getName(),e=t.getExpression();if((r==="notify"||r==="push")&&o.isIdentifier(e)&&e.getText()==="ctx")return r;if(r==="push"&&f(e)==="notify")return"push"},S=t=>{if(!o.isPropertyAccessExpression(t))return;const r=t.getName(),e=f(t.getExpression());if(e==="notify"&&A.has(r))return`ctx.notify.${r}`;if(e==="push"&&d.has(r))return`ctx.push.${r}`},N=t=>o.isPropertyAccessExpression(t)?f(t.getExpression())==="push"&&d.has(t.getName()):!1,D=(t,r)=>{const e=[];for(const s of l(r)){const i=t.getSourceFile(s)??t.addSourceFileAtPath(s),n=m(r,s);for(const c of g(i))if(!(c.kind!=="query"&&c.kind!=="mutation"))for(const a of c.handler.getDescendantsOfKind(p.PropertyAccessExpression)){const u=S(a);u!==void 0&&e.push({callee:u,exportName:c.exportName,file:n,kind:c.kind,line:a.getStartLineNumber()})}}return e},b=(t,r)=>{for(const e of l(r)){const s=t.getSourceFile(e)??t.addSourceFileAtPath(e);for(const i of g(s))for(const n of i.handler.getDescendantsOfKind(p.PropertyAccessExpression))if(N(n))return!0}return!1},v=t=>{const r=t.getExportAssignment(i=>!i.isExportEquals());if(!r)return;const e=r.getExpression();if(!o.isIdentifier(e))return e;const s=e.getSymbol()?.getValueDeclaration();return s&&o.isVariableDeclaration(s)?s.getInitializer():e},L=(t,r)=>{const e=h(r,E);if(!x(e))return;const s=t.getSourceFile(e)??t.addSourceFileAtPath(e),i=v(s);let n=!1,c=!1;if(i&&o.isCallExpression(i)){const a=i.getArguments()[0];a&&o.isObjectLiteralExpression(a)&&(n=a.getProperty("webPush")!==void 0,c=a.getProperty("fcm")!==void 0)}return{hasFcm:c,hasWebPush:n,usesPush:b(t,r)}};export{E as NOTIFY_FILENAME,D as discoverNotifyCalls,L as discoverNotifyConfig};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{w as a}from"./emit-D7VIjvlm.mjs";import{n as s}from"./paths-BmX5O1sG.mjs";import{argsObjectSchema as i,LUNORA_ERROR_CODES as c}from"./LUNORA_ERROR_CODES-Um9hC1gr.mjs";const m="1.3.2",p=()=>({description:"Result is TS-inferred from the function's return type (no `.output()` declared); best-effort — any JSON."}),u=e=>{const n=s(e.filePath),t=`${n}:${e.exportName}`;return{description:`Invoke the \`${e.kind}\` \`${t}\` over the Lunora RPC envelope (POST /_lunora/rpc, body \`{ "functionPath": "${t}", "args": { … } }\`).`,errors:c.map((r,o)=>({code:-32e3-o,data:{code:r},message:r})),name:t,params:[{description:"The function's argument object (the RPC envelope's `args`).",name:"args",required:Object.keys(e.args).length>0,schema:i(e.args)}],result:{name:"result",schema:p()},summary:`${e.kind}: ${t}`,"x-lunora-function-kind":e.kind,"x-tags":[{name:n}]}},d=e=>{const n=e.version??"0.0.0",t=e.functions.filter(r=>r.visibility!=="internal"&&r.kind!=="stream").map(r=>u(r)).toSorted((r,o)=>r.name.localeCompare(o.name));return{info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora RPC",version:n},methods:t,openrpc:m}},R=e=>`${JSON.stringify(d(e),void 0,2)}
|
|
2
|
+
`,O=e=>`${a}export const openRpcSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
|
|
3
|
+
`;export{m as OPENRPC_VERSION,d as buildOpenRpcDocument,R as emitOpenRpc,O as emitOpenRpcModule};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync as d}from"node:fs";import{join as p}from"node:path";import{LunoraError as g}from"@lunora/errors";import{queueDefaultName as l,queueBindingName as f}from"@lunora/queue";import{SyntaxKind as N,Node as u}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-DPezpZTz.mjs";const h="queues.ts",x=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineQueue";for(const e of t.getDeclarations())if(u.isImportSpecifier(e))return e.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/queue"?!1:e.getNameNode().getText()==="defineQueue";return!1},c=(r,t,e)=>{if(u.isStringLiteral(r)||u.isNoSubstitutionTemplateLiteral(r))return r.getLiteralValue();throw a(r,`queue "${t}": \`${e}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)},b=(r,t,e)=>{if(u.isNumericLiteral(r))return r.getLiteralValue();throw a(r,`queue "${t}": \`${e}\` must be a static numeric literal — it is deploy configuration codegen writes into wrangler.jsonc`)},w=(r,t)=>{const e=r.getProperty("name");if(!e||!u.isPropertyAssignment(e))return;const i=c(e.getInitializerOrThrow(),t,"name");if(i.length===0)throw a(e,`queue "${t}": \`name\` must be a non-empty string when provided`);return i},y=(r,t)=>{const e=r.getArguments()[0];if(!e||!u.isObjectLiteralExpression(e))throw a(r,`queue "${t}": defineQueue must be passed an inline object literal`);const i={bindingName:f(t),exportName:t,mode:"push",name:w(e,t)??l(t),tuning:{}},o=e.getProperty("mode");if(o&&u.isPropertyAssignment(o)){const n=c(o.getInitializerOrThrow(),t,"mode");if(n!=="push"&&n!=="pull")throw a(o,`queue "${t}": \`mode\` must be "push" or "pull" (got ${JSON.stringify(n)})`);i.mode=n}const s=e.getProperty("deadLetterQueue");s&&u.isPropertyAssignment(s)&&(i.tuning.deadLetterQueue=c(s.getInitializerOrThrow(),t,"deadLetterQueue"));for(const n of["maxBatchSize","maxBatchTimeout","maxRetries","retryDelay"]){const m=e.getProperty(n);m&&u.isPropertyAssignment(m)&&(i.tuning[n]=b(m.getInitializerOrThrow(),t,n))}return i},E=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const i=e.getInitializer();if(i?.getKind()!==N.CallExpression)continue;const o=i,s=o.getExpression();if(!u.isIdentifier(s)||!x(s))continue;const n=e.getNameNode();if(!u.isIdentifier(n))throw a(n,"defineQueue exports must be plain named exports (no destructuring)");t.push(y(o,n.getText()))}return t},q=r=>{const t=new Map,e=new Map;for(const i of r){const o=t.get(i.name);if(o!==void 0)throw new g("DUPLICATE_QUEUE_NAME",`Duplicate queue name "${i.name}": produced by both "${o}" and "${i.exportName}". Deployed queue names must be unique across the project.`,{status:500});t.set(i.name,i.exportName);const s=e.get(i.bindingName);if(s!==void 0)throw new g("DUPLICATE_QUEUE_BINDING",`Duplicate queue binding "${i.bindingName}": produced by both "${s}" and "${i.exportName}". Queue export names must yield unique binding names.`,{status:500});e.set(i.bindingName,i.exportName)}},D=(r,t)=>{const e=p(t,h);if(!d(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),o=E(i);return o.sort((s,n)=>s.exportName.localeCompare(n.exportName)),q(o),o};export{h as QUEUES_FILENAME,D as discoverQueues};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{existsSync as E,readFileSync as Ae,mkdirSync as zt,writeFileSync as qt,rmSync as Bt}from"node:fs";import{join as g,dirname as ge}from"node:path";import{performance as fe}from"node:perf_hooks";import{LunoraError as q}from"@lunora/errors";import{Node as i,SyntaxKind as u,Project as Xe}from"ts-morph";import{lintSchema as Vt}from"./formatAdvisories-DZvv-0MG.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as f,classifyProcedureCall as K,inlineHandler as Ut,procedureHandler as mt,chainUsesWrappedCall as xt,isDatabaseAccessor as k,chainHasStep as Wt,discoverFunctions as Gt}from"./discoverFunctions-zrIQk7J8.mjs";import{discoverAgents as _t}from"./AGENTS_FILENAME-BesaDYkL.mjs";import Ht from"./discoverAuthApiCalls-Ba6W92HB.mjs";import{discoverContainers as Jt}from"./CONTAINERS_FILENAME-CFwdyaCI.mjs";import Qt from"./discoverCrons-2nUpw6do.mjs";import{diagnosticAt as _}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{o as H}from"./module-specifiers-8FEEiUcv.mjs";import{a as pe,d as Xt,G as Zt,s as Yt,h as es,b as ts,J as ss,c as rs,_ as ns,M as is,B as os,j as as,t as cs,n as us,e as ls,l as ds,r as gs}from"./emit-D7VIjvlm.mjs";import{discoverFlagKeys as fs}from"./FLAGS_FILENAME-C1GWerCB.mjs";import ps from"./discoverHttpRoutes-Bf_T_03b.mjs";import ms from"./discoverInserts-DveVeP5h.mjs";import xs,{discoverMaskStrategies as hs,discoverMaskMetadata as Es}from"./discoverMaskProcedures-BkBquCFR.mjs";import ys from"./discoverMigrations-T2xb-1rn.mjs";import{MUTATORS_FILENAME as As,isDefineMutatorCallee as $s,discoverMutators as Ns}from"./MUTATORS_FILENAME-BWPAtQ2T.mjs";import Ss from"./discoverNondeterministicCalls-BymnOR9k.mjs";import{discoverNotifyConfig as vs,discoverNotifyCalls as bs}from"./NOTIFY_FILENAME-DP6qvFBX.mjs";import Ps from"./discoverQueries-DNRA-G2a.mjs";import{discoverQueues as ws}from"./QUEUES_FILENAME-CSE6i-ld.mjs";import Is from"./discoverR2sqlCalls-YEjvGcEq.mjs";import Os,{discoverRlsMetadata as Ls}from"./discoverRlsMetadata-DO3qlLXX.mjs";import{discoverSandboxUsage as Fs}from"./discoverSandboxUsage-JwrmSN9l.mjs";import Ts from"./discoverSchema-Cy4OQ0Cu.mjs";import{secretKindOf as Ds,redact as Cs}from"./redact-CQ8-to6l.mjs";import{discoverShapes as ks}from"./SHAPES_FILENAME-maut3z1K.mjs";import Ks from"./discoverStorageRulesMetadata-CCztRKjw.mjs";import{e as Rs}from"./discover-ast-CezKqEhE.mjs";import{discoverWorkflows as Ms}from"./WORKFLOWS_FILENAME-Bk5upkGM.mjs";import{emitApp as js}from"./emitApp-CAeIj6e_.mjs";import{buildOpenApiDocument as zs,emitOpenApiModule as qs}from"./buildOpenApiDocument-CXFC-wzM.mjs";import{buildOpenRpcDocument as Bs,emitOpenRpcModule as Vs}from"./OPENRPC_VERSION-CvVFqUlq.mjs";import{buildSchemaSnapshot as Us,serializeSchemaSnapshot as Ws}from"./SCHEMA_SNAPSHOT_VERSION-Bpf1FGMG.mjs";const ht=new Set(["delete","get","head","options","patch","post","put"]),Gs=new Set(["handler","stream"]),_s=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,Ze=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Hs=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()}},Js=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 Hs(s)},Qs=e=>{for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression))if(Ze.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&Ze.has(s.getText()))return!0}return!1},Xs=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||!Gs.has(r.getName()))return;const n=Js(s);if(!n||!_s.test(n.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&Qs(o);return{exportName:e.getName(),file:t,method:n.method,path:n.path,usesGuard:a}},Zs=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Xs(n,t);o&&s.push(o)}return s},Ys=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Zs(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)},me=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)},er=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t:void 0},N=e=>{if(i.isIdentifier(e))return e.getText();if(i.isPropertyAccessExpression(e))return e.getName()},Ee=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(Ee(e))return!0;const t=L(e);return t!==void 0&&Ee(t)},T=e=>{if(me(e))return!0;const t=L(e);if(t!==void 0&&me(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&&me(n)})},B=(e,t)=>i.isIdentifier(e)?tt(e,t):e.getDescendantsOfKind(u.Identifier).some(s=>tt(s,t)),tr=(e,t)=>{if(B(e,t))return!0;const s=L(e);if(s!==void 0&&B(s,t))return!0;const r=er(e);if(r!==void 0){const n=L(r);return n!==void 0&&B(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>"},sr=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",rr=(e,t)=>{if(!sr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)||T(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},nr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=rr(r,t);n&&s.push(n)}return s},ir=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...nr(n,f(t,r)))}return s},or=new Set(["generateText","streamText"]),ar=new Set(["messages","prompt","system"]),cr=[{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"]}],ur=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),r=t.getExpression().getText();for(const n of cr)if(n.methods.has(s)&&n.prefixes.some(o=>r===o||r.startsWith(`${o}.`)))return`${r}.${s}`},lr=e=>{for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=ur(t);if(s!==void 0)return s}},dr=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},gr=e=>{if(Ee(e))return!0;const t=dr(e);return t.size===0?!1:e.getDescendantsOfKind(u.Identifier).some(s=>t.has(s.getText()))},fr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!ar.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&gr(s))return!0}return!1},pr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=N(r.getExpression());if(n===void 0||!or.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(N(c.getExpression())==="tool"&&(a=lr(c),a!==void 0))break;a!==void 0&&s.push({exportName:h(r),file:t,line:r.getStartLineNumber(),method:n,sideEffect:a,userInputDerived:fr(o)})}return s},mr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...pr(n,f(t,r)))}return s},xr=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},hr=(e,t)=>{if(!xr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},Er=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=hr(r,t);n&&s.push(n)}return s},yr=(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},Ar=/\.check\(|\.meta\(|length|max/iu,$r=/\bv\.any\s*\(/u,Nr=/\bv\.string\s*\(/u,Sr=e=>$r.test(e),vr=e=>Nr.test(e)&&!Ar.test(e),br=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("args");if(!s||!i.isPropertyAssignment(s))return;const r=s.getInitializer();return r&&i.isObjectLiteralExpression(r)?r:void 0},Pr=e=>{const t=[];let s=e;for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const n=s.getArguments()[0];n&&i.isObjectLiteralExpression(n)&&t.push(n)}s=r.getExpression()}return t},wr=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();Sr(a)?t.push(c):vr(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Ir=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=K(s);if(r?.visibility!=="public")return;const n=r.receiver?Pr(r.receiver):[br(s)].filter(c=>c!==void 0),{anyArgs:o,unboundedStringArgs:a}=wr(n);if(!(o.length===0&&a.length===0))return{anyArgs:o,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Or=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Ir(n,t);o&&s.push(o)}return s},Lr=(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},S=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},xe=e=>e?.getKind()===u.TrueKeyword,Fr=e=>e?.getKind()===u.FalseKeyword,Tr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Dr=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Cr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&N(t.getExpression())==="scim"),kr=e=>e!==void 0&&i.isCallExpression(e)&&Dr.has(N(e.getExpression())??""),Kr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),Rr=e=>{const t=S(e,"advanced"),s=S(e,"emailAndPassword"),r=S(e,"session");return{analyzable:!0,disableCsrfCheck:xe(S(t,"disableCSRFCheck")),emailPasswordEnabled:xe(S(s,"enabled")),requireEmailVerification:xe(S(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Cr(S(e,"plugins"))&&kr(S(e,"database")),secureCookiesDisabled:Fr(S(t,"useSecureCookies")),sessionFreshAgeZero:Tr(S(r,"freshAge")),trustedOriginsWildcard:Kr(S(e,"trustedOrigins"))}},Mr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),jr=(e,t)=>{if(N(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?Rr(s):Mr();return{exportName:h(e),file:t,line:e.getStartLineNumber(),...n}},zr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=jr(r,t);n&&s.push(n)}return s},qr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...zr(n,f(t,r)))}return s},Br=(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},Vr=(e,t,s)=>{const r=Br(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}},Ur=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const o=Vr(n,t,s);o&&r.push(o)}return r},J=(e,t,s)=>{const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(...Ur(o,f(t,n),s))}return r},Wr=new Set(["content","pdf","scrape","screenshot"]),Gr=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Wr}),_r=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Hr=new Set(["RateLimiter"]),Jr=new Set(["extend"]),Et=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)?Et(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Qr=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},Xr=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)?Qr(e):void 0},Zr=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&Xr(t.getBody());return s?Et(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Yr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=N(r.getExpression());n!==void 0&&(_r.has(n)?s.push({callee:n,file:t,line:r.getStartLineNumber(),...st(r.getArguments()[0])}):Jr.has(n)&&s.push({callee:n,file:t,line:r.getStartLineNumber(),...Zr(r.getArguments()[0])}))}for(const r of e.getDescendantsOfKind(u.NewExpression)){const n=N(r.getExpression());n===void 0||!Hr.has(n)||s.push({callee:n,file:t,line:r.getStartLineNumber(),...st(r.getArguments()[0])})}return s},en=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Yr(n,f(t,r)))}return s},rt="ctx.containers.",tn=e=>{if(!e.startsWith(rt))return!1;const t=e.slice(rt.length);return t.length>0&&!t.includes(".")},sn=(e,t)=>J(e,t,{argIndex:0,matchReceiver:tn,methods:new Set(["get"])}),rn=new Set(["allow","deny","setAllowed"]),nn=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())},on=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!nn(e)))return{detail:"enableInternet: true",exportName:h(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},an=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!rn.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()}},cn=(e,t)=>on(e,t)??an(e,t),un=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=cn(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(...un(n,f(t,r)))}return s},dn="env.ts",gn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return H(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},fn=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&&H(r.getModuleSpecifierValue())}return!1},pn=e=>{if(i.isIdentifier(e))return gn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&fn(t)}return!1},mn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!pn(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw _(n,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},xn=(e,t)=>{const s=g(t,dn);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=mn(r);if(n.length!==0){if(n.length>1)throw _(r,`lunora/env.ts declares ${n.length.toString()} defineEnv() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},hn=new Set(["defineExportSink","r2Sink","webhookExportSink"]),En=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return hn.has(s)?s:void 0},yn=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}},An=(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=En(a);if(c===void 0)continue;const l=a.getArguments()[0],p=l&&i.isObjectLiteralExpression(l)?yn(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},$n=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Nn=new Set(["dbRateLimit","rateLimit"]),Sn=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},vn=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},bn=(e,t)=>{const s=N(e.getExpression());if(s===void 0)return;const r=$n.get(s);if(r!==void 0)return{callee:s,exportName:h(e),failOpen:Sn(e.getArguments()[r]),file:t,limitName:Nn.has(s)?vn(e):"",line:e.getStartLineNumber()}},Pn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=bn(r,t);n&&s.push(n)}return s},wn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Pn(n,f(t,r)))}return s},In=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},On=(e,t)=>{const s=Object.fromEntries(pe.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=In(n);for(const c of pe)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(pe.every(c=>s[c.key]))break}return s},Ln=["providerSubscriptionId","state"],Fn=["providerEventId","processedAt"],nt=(e,t)=>t.every(s=>s in e.shape),Tn=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,Ln)&&nt(s,Fn)},Dn=(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"),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")}),Cn=e=>i.isIdentifier(e)&&e.getText()==="ctx",kn=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Cn(t.getExpression())},Kn=e=>{if(e?.getKind()===u.TrueKeyword)return!0;if(e?.getKind()===u.FalseKeyword)return!1},Rn=(e,t)=>{if(!kn(e.getExpression()))return;const[s,r]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const n=s.getLiteralValue(),o=Kn(r);if(!(n.length===0||o===void 0))return{defaultValue:o,exportName:h(e),file:t,key:n,line:e.getStartLineNumber()}},Mn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Rn(r,t);n&&s.push(n)}return s},jn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Mn(n,f(t,r)))}return s},zn=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},qn=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Bn=(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))zn(a)&&s.push({file:o,indexName:qn(a),line:a.getStartLineNumber()})}return s},Vn=new Set(["delete","get","head","options","patch","post","put"]),Un=new Set(["handler","stream"]),Wn=new Set(["runAction","runMutation"]),Gn=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(Wn.has(a)&&U(c,t))return a;if(Gn.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},_n=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Un.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(Vn.has(n)){const o=r.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?n.toUpperCase():void 0}s=r.getExpression()}},Hn=(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=_n(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}},Jn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Hn(r,t);n&&s.push(n)}return s},Qn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Jn(n,f(t,r)))}return s},Xn=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),Zn=new Set(["append","set"]),$e=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",yt=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=>Xn.has($e(s.getExpression()))&&B(s,t)),Yn=(e,t)=>{if(ut(e,t))return!0;const s=L(e);return s!==void 0&&ut(s,t)},ye=(e,t)=>tr(e,t)&&!Yn(e,t),ei=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=L(e);return t!==void 0&&i.isNewExpression(t)&&$e(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&&ye(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:yt(r.getNameNode()),line:n.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(r)){const n=r.getNameNode();ye(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)}},At=(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)},ti=(e,t)=>{const s=$e(e.getExpression());if(s==="Response")At(e.getArguments()[1],t);else if(s==="Headers"){const r=W(e.getArguments()[0]);r!==void 0&&Ne(r,"headers-ctor",t)}},si=(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"){At(e.getArguments()[1],t);return}if(Zn.has(r)&&ei(n)){const o=e.getArguments()[1];o!==void 0&&ye(o,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:yt(e.getArguments()[0]),line:o.getStartLineNumber(),via:r==="set"?"headers-set":"headers-append"})}},ri=(e,t)=>{for(const s of e.getDescendantsOfKind(u.NewExpression))ti(s,t);for(const s of e.getDescendantsOfKind(u.CallExpression))si(s,t)},ni=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const r=Ut(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 ri(r,{exportName:h(e),relativePath:t,requestName:o.getText(),rows:a}),a},ii=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...ni(r,t));return s},oi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ii(n,f(t,r)))}return s},$t="identity.ts",ai=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return H(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},ci=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&&H(r.getModuleSpecifierValue())}return!1},ui=e=>{if(i.isIdentifier(e))return ai(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&ci(t)}return!1},li=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!ui(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw _(n,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},di=(e,t)=>{const s=g(t,$t);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=li(r);if(n.length!==0){if(n.length>1)throw _(r,`lunora/identity.ts declares ${n.length.toString()} defineIdentity() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},gi=new Set(["auth","context.auth","ctx.auth"]),fi="userId",pi=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},mi=(e,t)=>{const s=g(t,$t);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const n of r.getDescendantsOfKind(u.CallExpression)){if(N(n.getExpression())!=="defineIdentity")continue;const[o]=n.getArguments();return o&&i.isObjectLiteralExpression(o)?pi(o):void 0}},lt=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return gi.has(e.getExpression().getText())?e:void 0},xi=e=>{if(i.isPropertyAccessExpression(e)&<(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&<(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},hi=(e,t,s)=>{const r=[];for(const n of e.getDescendants()){const o=xi(n);o!==void 0&&r.push({declared:o===fi||s.has(o),exportName:h(n),file:t,key:o,line:n.getStartLineNumber()})}return r},Ei=(e,t)=>{const s=mi(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(...hi(o,f(t,n),s))}return r},yi=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Ai=(e,t)=>{if(N(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const r=yi(s);if(!(!r||!w(r)||T(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},$i=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ai(r,t);n&&s.push(n)}return s},Ni=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...$i(n,f(t,r)))}return s},Si=new Set(["delete","get","getRaw","getWithMetadata","put"]),vi=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:Si}),bi=new Set(["queue","send"]),dt=new Set(["bcc","cc","to"]),Pi=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!bi.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},wi=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,Ii=(e,t)=>{const s=Pi(e.getExpression());if(s===void 0)return;const r=e.getArguments()[0];if(!(!r||!wi(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Oi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ii(r,t);n&&s.push(n)}return s},Li=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Oi(n,f(t,r)))}return s},Fi=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"},Ti=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},Di=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==u.CallExpression)return;const s=t;return $s(s.getExpression())?s:void 0},Ci=e=>{const t=Di(e),s=t===void 0?void 0:Ti(t);if(s===void 0)return[];const r=e.getNameNode(),n=i.isIdentifier(r)?r.getText():"";return s.getDescendantsOfKind(u.CallExpression).filter(o=>Fi(o)).map(o=>({exportName:n,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},ki=e=>e.getVariableDeclarations().flatMap(t=>Ci(t)),Ki=(e,t)=>{const s=g(t,As);if(!E(s))return[];const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);return ki(r)},Ri=new Set(["delete","get","patch"]),Mi=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),ji=new Set(["auth","identity","session","user"]),zi=new Set([u.EqualsEqualsEqualsToken,u.EqualsEqualsToken,u.ExclamationEqualsEqualsToken,u.ExclamationEqualsToken]),qi=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():""},Bi=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},Vi=(e,t)=>e.getDescendantsOfKind(u.Identifier).some(s=>s.getText()===t),Ui=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(u.ThrowStatement).length>0||e.getDescendantsOfKind(u.ReturnStatement).length>0,Wi=(e,t)=>e.getDescendantsOfKind(u.IfStatement).some(s=>Vi(s.getExpression(),t)&&Ui(s.getThenStatement())),Gi=(e,t)=>{for(const s of e.getDescendantsOfKind(u.CallExpression)){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))continue;const n=r.getName();if(!Ri.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}},_i=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},Hi=e=>e.getDescendantsOfKind(u.CallExpression).some(t=>t.getArguments().some(s=>_i(s)==="ctx")),Ji=e=>e.getDescendantsOfKind(u.BinaryExpression).some(t=>zi.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),Qi=e=>{for(const t of e.getDescendantsOfKind(u.Identifier))if(Mi.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&ji.has(t.getName()))return!0}return Hi(e)||Ji(e)},Xi=(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=Qi(n),c=new Set,l=[];for(const p of n.getDescendantsOfKind(u.CallExpression)){const y=qi(p);if(y===void 0)continue;const I=Bi(p);if(I===void 0||c.has(I)||!Wi(n,I))continue;const R=Gi(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},Zi=(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(...Xi(c,o))}return s},Yi=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),eo=new Set(["insert","insertManyUnsafe","patch","replace"]),to=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!eo.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},so=(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},ro=(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||!Yi.has(a))&&w(c)&&!T(c)&&n.push({exportName:h(s),field:a,file:r,line:s.getStartLineNumber(),method:t})}return n},no=(e,t)=>{const s=to(e.getExpression());if(s===void 0)return[];const r=e.getArguments()[1];return r?so(r,s).flatMap(n=>ro(n,s,e,t)):[]},io=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...no(r,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},ao=e=>{const t=g(e,"package.json");if(!E(t))return new Set;try{const s=JSON.parse(Ae(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}},co=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),uo=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,lo=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?uo(t.getInitializer()):void 0},go=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=N(r.getExpression());if(n===void 0||!co.has(n))continue;const[o]=r.getArguments(),a=o&&i.isObjectLiteralExpression(o)?lo(o):void 0;s.push({callee:n,exportName:h(r),file:t,line:r.getStartLineNumber(),...a===void 0?{}:{toleranceSeconds:a}})}return s},fo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...go(n,f(t,r)))}return s},po=new Set(["defineQueue","defineWorkflow"]),mo=new Set(["run","runAction","runMutation","runQuery"]),xo=new Set(["api","internal"]),ho=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},Eo=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},Nt=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},St=(e,t)=>e===t||e.startsWith(`${t}.`),vt=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)},bt=e=>{const t=e.getDescendantsOfKind(u.Identifier).filter(s=>gt(s));return i.isIdentifier(e)&>(e)&&t.push(e),t},yo=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(u.BindingElement).map(s=>s.getName())},Ao=e=>{const t=Nt(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},$o=(e,t,s)=>{const r=t==="workflow"?[`${s}.params`]:Ao(e),n=new Set,o=a=>vt(a).some(c=>r.some(l=>St(c.getText(),l)))?!0:bt(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 yo(a))n.add(l)}return{names:n,prefixes:r}},No=(e,t)=>vt(e).some(s=>t.prefixes.some(r=>St(s.getText(),r)))?!0:bt(e).some(s=>t.names.has(s.getText())),So=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)||!xo.has(s.getText())||t.length<2))return{exportName:r,file:t.slice(0,-1).join("/")}},vo=(e,t,s)=>{const r=Nt(e,0);if(r===void 0)return[];const n=$o(e,t,r),o=[];for(const a of e.getDescendantsOfKind(u.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!mo.has(c.getName())||c.getExpression().getText()!==r)continue;const l=a.getArguments()[1];if(!l||!No(l,n))continue;const p=So(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},bo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ho(r);if(n===void 0||!po.has(n))continue;const o=Eo(r);o!==void 0&&s.push(...vo(o,n==="defineQueue"?"queue":"workflow",t))}return s},Po=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...bo(n,f(t,r)))}return s},ft={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},wo=/account|credential|member|passkey|session|user/iu,Pt=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},Io=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Oo=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},V={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Lo=e=>{const t=Oo(e),s=t?Pt(t):void 0;if(t&&s==="protectPublic"){const r=Io(t);return{...V,usesCaptcha:r.usesCaptcha,usesRateLimit:r.usesRateLimit}}return s!==void 0&&s in ft?{...V,[ft[s]]:!0}:V},Fo=e=>{const t={...V};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=Lo(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},To=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)&&wo.test(r.getLiteralText()))},Do=new Set(["create","runAfter","runAt","send","sendBatch"]),Co=new Set(["queues","scheduler","workflows"]),ko=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Do.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&Co.has(s.getName())){const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="ctx")return!0}s=s.getExpression()}return!1},Ko=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"},Ro=new Set(["generateObject","generateText","streamObject","streamText"]),Mo=e=>{const t=Pt(e);if(t===void 0||!Ro.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")},jo=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"}),zo=e=>{let t=!1,s=!1,r=!1,n=!1;for(const o of e.getDescendantsOfKind(u.CallExpression))if(To(o)&&(n=!0),ko(o)&&(t=!0),Ko(o)&&(r=!0),Mo(o)&&(s=!0),n&&t&&r&&s)break;return{callsMail:jo(e),fanOut:t,unboundedAiGeneration:s,usesInsertManyUnsafe:r,writesUserTable:n}},qo=(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?Fo(r.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},{callsMail:o,fanOut:a,unboundedAiGeneration:c,usesInsertManyUnsafe:l,writesUserTable:p}=zo(e);return{callsMail:o,exportName:e.getName(),fanOut:a,file:t,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}},Bo=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=qo(n,t);o&&s.push(o)}return s},Vo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Bo(n,f(t,r)))}return s},Uo=new Set(["dbRateLimit","rateLimit"]),Wo=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Go=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},_o=e=>i.isArrowFunction(e)?e.getBody():e,Ho=(e,t)=>{const s=N(e.getExpression());if(s===void 0||!Uo.has(s))return;const r=e.getArguments()[2];if(!r)return;const n=Wo(r);if(!n)return;const o=_o(n);if(!(!w(o)||T(o)))return{callee:s,exportName:h(e),file:t,limitName:Go(e),line:e.getStartLineNumber()}},Jo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ho(r,t);n&&s.push(n)}return s},Qo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Jo(n,f(t,r)))}return s},Xo=new Set(["findFirst","findFirstOrThrow","findMany","get"]),Zo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Xo.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()},Yo=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()}},ea=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},wt=(e,t=!1)=>{const s=ea(e);if(i.isIdentifier(s)){if(t)return;const r=L(s);return r===void 0?void 0:wt(r,!0)}if(i.isCallExpression(s))return Zo(s)??Yo(s)},ta=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},sa=(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&&Wt(r.receiver,"output"),a=r.receiver!==void 0&&xt(r.receiver,"use","mask"),c=new Set,l=[];for(const p of ta(n)){const y=wt(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},ra=(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(...sa(c,o))}return s},na=new Set(["findFirst","findFirstOrThrow","findMany"]),ia=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!na.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()}}},oa=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},aa=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},ca=(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=ia(o);if(a===void 0)continue;const c=oa(aa(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},ua=(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(...ca(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}},la=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},da=(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(la(o))continue;const a=G(o);if(a===void 0)continue;const c=Ds(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:Cs(a)}))}return s},ga=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...da(n,f(t,r)))}return s},fa=new Set(["findFirst","findFirstOrThrow","findMany"]),pa=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!fa.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()}}},ma=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},xa=(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=pa(o);if(a===void 0)continue;const c=ma(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},ha=(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(...xa(c,o))}return s},Ea=new Set(["query","unsafe"]),ya=e=>{if(!i.isPropertyAccessExpression(e)||!Ea.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"},Aa=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),$a=e=>e.getFirstAncestorByKind(u.VariableDeclaration)?.getName()??"<module>",Na=(e,t)=>{if(!ya(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Aa(s)))return{exportName:$a(e),file:t,line:s.getStartLineNumber()}},Sa=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Na(r,t);n&&s.push(n)}return s},va=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Sa(n,f(t,r)))}return s},ba=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Pa=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.storage"||s.startsWith("ctx.storage."),methods:ba}),wa=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Ia=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Oa=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=Ia(n.getInitializer()));continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,expiresInSeconds:s,presentKeys:t}},La=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=wa.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},Fa=(e,t)=>{const s=La(e.getExpression());if(s!==void 0)return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s.method,...Oa(e.getArguments()[s.optionsIndex])}},Ta=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Fa(r,t);n&&s.push(n)}return s},Da=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ta(n,f(t,r)))}return s},Ca=new Set(["when","where"]),he=new Set(["definePolicy","defineShape"]),ka=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const r=t.getName();return he.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 he.has(n)?n:void 0}const s=t.getText();return he.has(s)?s:void 0},Ka=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,It=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===u.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Ka(e))return"empty-object";if(i.isParenthesizedExpression(e))return It(e.getExpression())}},Ot=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Lt=e=>e.getDescendantsOfKind(u.ReturnStatement).filter(t=>Ot(t)===e),Ft=e=>e.getDescendantsOfKind(u.ConditionalExpression).filter(t=>Ot(t)===e),Ra=e=>{const t=Lt(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(u.IfStatement)!==void 0)||Ft(e).length>0},Ma=e=>{const t=[],s=e.getBody();i.isBlock(s)||t.push(s);for(const r of Lt(e)){const n=i.isReturnStatement(r)?r.getExpression():void 0;t.push(n??r)}for(const r of Ft(e))t.push(r.getWhenTrue(),r.getWhenFalse());return t},ja=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},za=(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)||!Ca.has(o.getName()))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Ra(a))for(const c of Ma(a)){const l=It(c);l!==void 0&&n.push({exportName:ja(e),file:s,form:l,key:o.getName(),line:c.getStartLineNumber(),owner:t})}}return n},qa=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ka(r);n!==void 0&&s.push(...za(r,n,t))}return s},Ba=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...qa(n,f(t,r)))}return s},Va=new Set(["query","upsert","upsertMany"]),Ua=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(Va.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Wa=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("namespace");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Ga=(e,t)=>{const s=Ua(e.getExpression());if(s===void 0)return;const r=e.getArguments()[1];if(!r)return;const n=Wa(r);if(!(!n||!w(n)||T(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},_a=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ga(r,t);n&&s.push(n)}return s},Ha=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(..._a(n,f(t,r)))}return s},Ja=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"},Qa=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Xa=(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(!Ja(a))continue;const c=Rs(a);c!==""&&s.push({exportName:c,file:o,line:a.getStartLineNumber(),workflow:Qa(a)})}}return s},Za=".lunora-schema.json",$=(e,t)=>{E(e)&&Ae(e,"utf8")===t||qt(e,t,"utf8")},P=(e,t)=>{if(t===""){Bt(e,{force:!0});return}$(e,t)},Ya=e=>{const t=g(e,"package.json");if(E(t))try{const s=JSON.parse(Ae(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},ec=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},tc=e=>{let t=E(e)?e:ge(e);for(;t&&t!==ge(t);){const s=g(t,"tsconfig.json");if(E(s))return s;t=ge(t)}},pt=e=>e.replaceAll("\\","/"),sc=(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})}},rc=e=>{const t=tc(e);return t?new Xe({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Xe({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},qc=(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)}},Bc=e=>{const t=ec(),s=t?fe.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??rc(r),a=Ts(o,n,e.projectRoot),c=Gt(o,r),l=ps(o,r),p=ys(o,r),y=ks(o,r),I=Ns(o,r),R=di(o,r),Se=xn(o,r),v=Ms(o,r),D=ws(o,r),b=_t(o,r);sc(v,b);const Q=Qt(o,r,v,b),C=Jt(o,r),ve=e.lint===!1?[]:Vt({adminRoutes:Ys(o,r),aiRawRuns:ir(o,r),aiToolSideEffects:mr(o,r),argumentDerivedFetches:yr(o,r),argumentValidators:Lr(o,r),authApiCalls:Ht(o,r),authConfigs:qr(o,r),browserUrlAccesses:Gr(o,r),configCalls:en(o,r),containerKeyAccesses:sn(o,r),containerOverrides:ln(o,r),containers:C,exportSinks:An(o,r),failOpenGuards:wn(o,r),flagSecurityDefaults:jn(o,r),geoIndexUsages:Bn(o,r),httpActionGuards:Qn(o,r),httpHeaderWrites:oi(o,r),identityClaimReads:Ei(o,r),imageDeliveryUrlAccesses:Ni(o,r),inserts:ms(o,r),kvKeyAccesses:vi(o,r),mailRecipientAccesses:Li(o,r),maskProcedures:xs(o,r),maskStrategies:hs(o,r),mutatorWrites:Ki(o,r),nondeterministicCalls:Ss(o,r),normalizeIdAuthorizations:Zi(o,r),notifyCalls:bs(o,r),notifyConfig:vs(o,r),ownerFieldWrites:oo(o,r),unrestrictedWhereBranches:Ba(o,r),paymentWebhooks:fo(o,r),privilegedDispatches:Po(o,r),procedureProtections:Vo(o,r),queries:Ps(o,r),queues:D,r2sqlCalls:Is(o,r),ratelimitKeySelectors:Qo(o,r),rawRowReturns:ra(o,r),relationLoads:ua(o,r),rlsProcedures:Os(o,r),schema:a,secretLiterals:ga(o,r),shapes:y,softDeleteReads:ha(o,r),sqlInterpolations:va(o,r),storageKeyAccesses:Pa(o,r),storageUploads:Da(o,r),vectorNamespaceAccesses:Ha(o,r),workflowCalls:Xa(o,r),workflows:v,wranglerVariables:e.wranglerVariables}),Tt=Ls(o,r),Dt=Es(o,r),X=Ks(o,r),A=On(o,r),Z=A.ai,Y=A.payments,be=A.kv,Pe=A.access,ee=E(g(r,"flags.ts")),Ct=ee?fs(o,r):[],te=E(g(r,"notify.ts")),se=A.hyperdrive,re=Fs(o,r),kt=re.usesSandboxBrowser||re.usesSandboxContainer,ne=A.browser||re.usesSandboxBrowser,ie=A.images,oe=A.analytics,we=A.pipelines,ae=A.r2sql,ce=A.x402,O=ao(e.projectRoot),M=Dn(A,{containerCount:C.length,cronCount:Q.length,dependencies:O,hasPaymentTables:Tn(a.tables),queueCount:D.length,storageColumnCount:Object.keys(Xt(a)).length,storageRuleCount:X.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:v.length}),F=O.has("lunorash"),Ie=t?fe.now():0,Oe=Zt(a,F),Le=Yt({agents:b,functions:c,httpRoutes:l,mutators:I,useUmbrella:F,workflows:v}),Fe=es({agents:b,containers:C,env:Se,hasAccessFacade:Pe,hasAi:Z,hasAnalytics:oe,hasBrowser:ne,hasFlags:ee,hasHyperdrive:se,hasImages:ie,hasKv:be,hasNotify:te,hasPayments:Y,hasPipelines:we,hasR2sql:ae,hasX402:ce,identity:R,queues:D,schema:a,storageRuleBuckets:X.rules.map(m=>m.bucket),useUmbrella:F,workflows:v}),Te=ts({agents:b,functions:c,migrations:p,mutators:I,shapes:y,useUmbrella:F,usesSandbox:kt}),De=ss({advisories:ve,agents:b,containers:C,env:Se,flagKeys:Ct,hasAccessFacade:Pe,hasAi:Z,hasAnalytics:oe,hasBrowser:ne,hasFlags:ee,hasHyperdrive:se,hasImages:ie,hasKv:be,hasNotify:te,hasPayments:Y,hasPipelines:we,hasR2sql:ae,hasX402:ce,maskMetadata:Dt,mutators:I,queues:D,rlsMetadata:Tt,schema:a,shapes:y,storageRules:X,studioFeatures:M,useUmbrella:F,workflows:v}),Ce=rs(y,O.has("@lunora/db"),F),ke=ns(C,a.jurisdiction),Ke=is(v),Re=os(b),Me=as(D),je=cs(Q),ze=us(a.vectorIndexes),j=ls(a,F),qe=ds(O.has("@lunora/seed")),z=e.apiSpec??"openapi",ue=z==="openapi"||z==="both",le=z==="openrpc"||z==="both",Be=js({emailAgents:b.filter(m=>m.onEmail===!0).map(m=>({bindingName:m.bindingName,exportName:m.exportName})),hasAccess:O.has("@lunora/cloudflare-access"),hasAi:Z,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:ue,wantsOpenRpc:le}),Ve=Ya(e.projectRoot),Ue=zs({functions:c,httpRoutes:l,version:Ve}),We=Bs({functions:c,version:Ve}),Ge=`${JSON.stringify(Ue,void 0,2)}
|
|
2
|
+
`,_e=`${JSON.stringify(We,void 0,2)}
|
|
3
|
+
`,He=qs(Ue),Je=Vs(We),Qe=Us(a,p.map(m=>m.id)),de=g(r,Za),Kt=E(de),x=g(r,"_generated");if(e.dryRun||(E(x)||zt(x,{recursive:!0}),$(g(x,"app.ts"),Be),$(g(x,"dataModel.ts"),Oe),$(g(x,"api.ts"),Le),$(g(x,"server.ts"),Fe),$(g(x,"functions.ts"),Te),$(g(x,"shard.ts"),De),$(g(x,"crons.ts"),je),$(g(x,"vectors.ts"),ze),$(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"),Ke),P(g(x,"agents.ts"),Re),P(g(x,"queues.ts"),Me),P(g(x,"seed.ts"),qe),P(g(x,"collections.ts"),Ce),P(g(x,"openapi.json"),ue?Ge:""),P(g(x,"openapi.ts"),ue?He:""),P(g(x,"openrpc.json"),le?_e:""),P(g(x,"openrpc.ts"),le?Je:""),(!Kt||e.updateSchemaBaseline===!0)&&$(de,Ws(Qe))),t){const m=fe.now(),Rt=Math.round(m-s),Mt=Math.round(Ie-s),jt=Math.round(m-Ie);console.error(`@lunora/codegen: codegen took ${Rt.toString()}ms (discovery ${Mt.toString()}ms, emit ${jt.toString()}ms)`)}return{advisories:ve,agents:b,containers:C,cronTriggers:gs(Q),generated:{agents:Re,api:Le,app:Be,collections:Ce,containers:ke,crons:je,dataModel:Oe,drizzleGlobal:j.global,drizzleShard:j.shard,functions:Te,openApi:Ge,openApiModule:He,openRpc:_e,openRpcModule:Je,queues:Me,seed:qe,server:Fe,shard:De,vectors:ze,workflows:Ke},outputDirectory:x,queues:D,schemaSnapshot:Qe,schemaSnapshotPath:de,workflows:v}};export{Za as SCHEMA_SNAPSHOT_FILENAME,rc as createCodegenProject,qc as refreshCodegenProject,Bc as runCodegen};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import{LunoraError as f}from"@lunora/errors";const l=1,g=e=>e==="global"||e==="root"?e:`shardBy:${e.field}`,p=e=>e.kind==="optional"?{kind:e.inner?.kind??"unknown",optional:!0}:{kind:e.kind,optional:!1},b=e=>{const n={};for(const[a,o]of Object.entries(e.shape))n[a]=p(o);const i={};for(const a of e.indexes)i[a.name]={fields:[...a.fields],unique:a.unique??!1};const t={};for(const a of e.relations)t[a.name]={field:a.field,kind:a.kind,table:a.table};return{fields:n,indexes:i,relations:t,shardMode:g(e.shardMode)}},y=e=>{const n={},i=Object.keys(e);i.sort();for(const t of i)n[t]=e[t];return n},q=(e,n)=>{const i={};for(const a of e.tables)i[a.name]=b(a);const t=[...n].sort();return{jurisdiction:e.jurisdiction,migrationIds:t,tables:y(i),version:l}},R=e=>`${JSON.stringify(e,void 0,2)}
|
|
2
|
+
`;class c extends f{constructor(n){super("SCHEMA_SNAPSHOT_PARSE",n,{name:"SchemaSnapshotParseError"})}}const d=e=>typeof e=="object"&&e!==null,v=e=>d(e)&&d(e.fields)&&d(e.indexes)&&d(e.relations)&&typeof e.shardMode=="string",T=e=>{if(e===void 0||e.trim()==="")return;let n;try{n=JSON.parse(e)}catch(i){throw new c(`baseline is not valid JSON: ${i instanceof Error?i.message:String(i)}`)}if(!d(n)||n.version!==l||!d(n.tables))throw new c(`baseline is malformed or written by an incompatible version (expected version ${String(l)})`);for(const[i,t]of Object.entries(n.tables))if(!v(t))throw new c(`baseline table "${i}" has an invalid structure`);return{jurisdiction:typeof n.jurisdiction=="string"?n.jurisdiction:void 0,migrationIds:Array.isArray(n.migrationIds)?n.migrationIds:[],tables:n.tables,version:l}},$=(e,n)=>e.unique===n.unique&&e.fields.length===n.fields.length&&e.fields.every((i,t)=>i===n.fields[t]),k=(e,n,i,t)=>{const a=[];return i.kind!==t.kind&&a.push({severity:"breaking",summary:`field ${e}.${n} changed type: ${i.kind} → ${t.kind} — add a data migration to convert existing values`,type:"changedFieldKind"}),i.optional&&!t.optional?a.push({severity:"breaking",summary:`field ${e}.${n} became required — rows missing it would be invalid; add a data migration to backfill it`,type:"fieldOptionalToRequired"}):!i.optional&&t.optional&&a.push({severity:"safe",summary:`field ${e}.${n} became optional`,type:"fieldRequiredToOptional"}),a},w=(e,n,i)=>i.optional?{severity:"safe",summary:`added optional field ${e}.${n}`,type:"addedOptionalField"}:{severity:"breaking",summary:`added required field ${e}.${n} — existing rows have no value; add a data migration to backfill it`,type:"addedRequiredField"},S=(e,n,i,t)=>{for(const[a,o]of Object.entries(i.fields)){const s=n.fields[a];s===void 0?t.push(w(e,a,o)):t.push(...k(e,a,s,o))}for(const a of Object.keys(n.fields))i.fields[a]===void 0&&t.push({severity:"breaking",summary:`removed field ${e}.${a} — add a data migration if stored data must be cleaned up`,type:"removedField"})},j=(e,n,i,t)=>{for(const[a,o]of Object.entries(i.indexes)){const s=n.indexes[a];if(s===void 0){t.push({severity:"safe",summary:`added index ${a} on ${e}`,type:"addedIndex"});continue}$(s,o)||t.push({severity:"breaking",summary:`index ${a} on ${e} changed shape — a query may have relied on the old index`,type:"changedIndex"})}for(const a of Object.keys(n.indexes))i.indexes[a]===void 0&&t.push({severity:"breaking",summary:`removed index ${a} on ${e} — a query that used \`.withIndex("${a}")\` would break`,type:"removedIndex"})},x=(e,n,i,t)=>{for(const a of Object.keys(i.relations))n.relations[a]===void 0&&t.push({severity:"safe",summary:`added relation ${e}.${a}`,type:"addedRelation"});for(const a of Object.keys(n.relations))i.relations[a]===void 0&&t.push({severity:"breaking",summary:`removed relation ${e}.${a}`,type:"removedRelation"})},O=(e,n,i,t)=>{n.shardMode!==i.shardMode&&t.push({severity:"breaking",summary:`table ${e} changed shard mode: ${n.shardMode} → ${i.shardMode} — its physical storage moves; add a data migration / re-shard plan`,type:"changedShardMode"}),S(e,n,i,t),j(e,n,i,t),x(e,n,i,t)},I=(e,n)=>{const i=[],t=e?.tables??{};for(const[a,o]of Object.entries(n.tables)){const s=t[a];if(s===void 0){i.push({severity:"safe",summary:`added table ${a}`,type:"addedTable"});continue}O(a,s,o,i)}for(const a of Object.keys(t))n.tables[a]===void 0&&i.push({severity:"breaking",summary:`removed table ${a} — add a data migration if its data must be archived/cleaned up`,type:"removedTable"});if(e!==void 0&&e.jurisdiction!==n.jurisdiction){const a=e.jurisdiction??"(none)",o=n.jurisdiction??"(none)";i.push({severity:"breaking",summary:`Durable Object jurisdiction changed from ${a} to ${o} — this re-homes every DO and strands all existing shard, scheduler, and session-DO data in the old region (no in-place migration; export then import to move it). Revert the change, or override the gate to proceed intentionally.`,type:"changedJurisdiction"})}return{changes:i}},E=e=>{const{allowDrift:n=!1,baseline:i,current:t}=e,a=I(i,t),o=a.changes.filter(r=>r.severity==="breaking"),s=t.migrationIds.filter(r=>!(i?.migrationIds??[]).includes(r));if(a.changes.length===0||i===void 0)return{blocked:!1,changes:a.changes,newMigrationIds:s,reason:""};if(o.length===0){const r=a.changes.map(m=>` - ${m.summary}`).join(`
|
|
3
|
+
`);return{blocked:!1,changes:a.changes,newMigrationIds:s,reason:`schema drift detected (all additive/safe):
|
|
4
|
+
${r}`}}const h=o.map(r=>` - ${r.summary}`).join(`
|
|
5
|
+
`);if(s.length>0)return{blocked:!1,changes:a.changes,newMigrationIds:s,reason:`breaking schema drift detected, but ${String(s.length)} new migration(s) were added (${s.join(", ")}):
|
|
6
|
+
${h}`};const u=`deploy blocked: ${String(o.length)} breaking schema change(s) detected since the last blessed schema baseline — these changes are incompatible with existing data without a migration:
|
|
7
|
+
${h}
|
|
8
|
+
|
|
9
|
+
To fix:
|
|
10
|
+
• For breaking changes: add a \`defineMigration({ id, table, up })\` in lunora/ for each affected table, then run \`lunora migrate\` (or \`lunora codegen\`) to apply and re-bless the baseline.
|
|
11
|
+
• For backward-compatible changes (e.g. adding an optional field): pass \`--allow-schema-drift\` to skip the block.
|
|
12
|
+
• To accept the new shape without a migration (you know data is compatible): pass \`--update-schema-baseline\`.
|
|
13
|
+
Docs: https://lunora.dev/docs/migrations`;return n?{blocked:!1,changes:a.changes,newMigrationIds:s,reason:`${u}
|
|
14
|
+
|
|
15
|
+
(overridden by --allow-schema-drift)`}:{blocked:!0,changes:a.changes,newMigrationIds:s,reason:u}};export{l as SCHEMA_SNAPSHOT_VERSION,c as SchemaSnapshotParseError,q as buildSchemaSnapshot,I as diffSchemaSnapshots,E as evaluateSchemaDrift,T as parseSchemaSnapshot,R as serializeSchemaSnapshot};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync as p}from"node:fs";import{join as g}from"node:path";import{SyntaxKind as c,Node as o}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{o as f}from"./module-specifiers-8FEEiUcv.mjs";import{d as u}from"./parse-validator-CSDlMEvE.mjs";const m="shapes.ts",d=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineShape";for(const e of t.getDeclarations())if(o.isImportSpecifier(e))return f(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineShape":!1;return!1},x=r=>{const t=r.getSymbol();if(!t)return!1;for(const e of t.getDeclarations()){if(!o.isNamespaceImport(e))continue;const i=e.getFirstAncestorByKind(c.ImportDeclaration);return i!==void 0&&f(i.getModuleSpecifierValue())}return!1},S=r=>{if(o.isIdentifier(r))return d(r);if(o.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineShape"&&o.isIdentifier(t)&&x(t)}return!1},h=r=>{const[t]=r.getArguments();if(!t||!o.isObjectLiteralExpression(t))return;const e=t.getProperty("table");if(!e||!o.isPropertyAssignment(e))return;const i=e.getInitializer();return i&&o.isStringLiteral(i)?i.getLiteralValue():void 0},I=r=>{const[t]=r.getArguments();if(!t||!o.isObjectLiteralExpression(t))return{};const e=t.getProperty("args");if(!e||!o.isPropertyAssignment(e))return{};const i=e.getInitializer();return!i||!o.isObjectLiteralExpression(i)?{}:u(i)},y=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const i=e.getInitializer();if(i?.getKind()!==c.CallExpression)continue;const n=i,a=n.getExpression();if(!S(a))continue;const s=e.getNameNode();if(!o.isIdentifier(s))throw l(s,"defineShape exports must be plain named exports (no destructuring)");t.push({args:I(n),exportName:s.getText(),filePath:"shapes",table:h(n)})}return t},D=(r,t)=>{const e=g(t,m);if(!p(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),n=y(i);return n.sort((a,s)=>a.exportName.localeCompare(s.exportName)),n};export{m as SHAPES_FILENAME,D as discoverShapes};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync as m}from"node:fs";import{join as p}from"node:path";import{LunoraError as l}from"@lunora/errors";import{workflowDefaultName as c,workflowClassName as u,workflowBindingName as g}from"@lunora/workflow";import{Node as i,SyntaxKind as d}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-DPezpZTz.mjs";const w="workflows.ts",x=new Set(["do","sleep","sleepUntil","waitForEvent"]),N=o=>{const e=o.getSymbol();if(!e)return o.getText()==="defineWorkflow";for(const t of e.getDeclarations())if(i.isImportSpecifier(t))return t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/workflow"?!1:t.getNameNode().getText()==="defineWorkflow";return!1},b=(o,e,t)=>{if(i.isStringLiteral(o)||i.isNoSubstitutionTemplateLiteral(o))return o.getLiteralValue();throw a(o,`workflow "${e}": \`${t}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)},E=o=>{const e=o.getExpression();if(!i.isPropertyAccessExpression(e)||!x.has(e.getName()))return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="step"?!0:i.isIdentifier(t)&&t.getText()==="step"},h=o=>{const e=o.getProperty("handler");if(!e)return[];const t=i.isPropertyAssignment(e)?e.getInitializer():e;if(!t)return[];const r=[];for(const n of t.getDescendantsOfKind(d.CallExpression)){if(!E(n))continue;const s=n.getArguments()[0];!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s))||r.push({line:n.getStartLineNumber(),method:n.getExpression().getName(),name:s.getLiteralValue()})}return r},k=(o,e)=>{const t=o.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))throw a(o,`workflow "${e}": defineWorkflow must be passed an inline object literal`);const r={bindingName:g(e),className:u(e),exportName:e,name:c(e),steps:h(t)},n=t.getProperty("name");return n&&i.isPropertyAssignment(n)&&(r.name=b(n.getInitializerOrThrow(),e,"name")),r},S=o=>{let e=o;for(;e&&(i.isAsExpression(e)||i.isSatisfiesExpression(e)||i.isParenthesizedExpression(e));)e=e.getExpression();return e&&i.isCallExpression(e)?e:void 0},y=o=>{const e=[];for(const t of o.getVariableDeclarations()){if(!t.isExported())continue;const r=S(t.getInitializer());if(!r)continue;const n=r.getExpression();if(!i.isIdentifier(n)||!N(n))continue;const s=t.getNameNode();if(!i.isIdentifier(s))throw a(s,"defineWorkflow exports must be plain named exports (no destructuring)");e.push(k(r,s.getText()))}return e},L=o=>{const e=new Map,t=new Map;for(const r of o){const n=e.get(r.name);if(n!==void 0)throw new l("DUPLICATE_WORKFLOW_NAME",`Duplicate workflow name "${r.name}": produced by both "${n}" and "${r.exportName}". Deployed workflow names must be unique across the project.`,{status:500});e.set(r.name,r.exportName);const s=t.get(r.bindingName);if(s!==void 0)throw new l("DUPLICATE_WORKFLOW_BINDING",`Duplicate workflow binding "${r.bindingName}": produced by both "${s}" and "${r.exportName}". Workflow export names must yield unique binding names.`,{status:500});t.set(r.bindingName,r.exportName)}},T=(o,e)=>{const t=p(e,w);if(!m(t))return[];const r=o.getSourceFile(t)??o.addSourceFileAtPath(t),n=y(r);return n.sort((s,f)=>s.exportName.localeCompare(f.exportName)),L(n),n};export{w as WORKFLOWS_FILENAME,T as discoverWorkflows};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{w as $}from"./emit-D7VIjvlm.mjs";import{n as p}from"./paths-BmX5O1sG.mjs";import{LUNORA_ERROR_CODES as y,objectSchema as g,argsObjectSchema as h,validatorIrToJsonSchema as u}from"./LUNORA_ERROR_CODES-Um9hC1gr.mjs";const S="/_lunora/rest",O=e=>{const t=e.indexOf(":");if(!(t<=0||t>=e.length-1||e.indexOf(":",t+1)!==-1))return{name:e.slice(t+1),namespace:e.slice(0,t)}},b=e=>{const t=O(e);if(t!==void 0)return`${S}/${t.namespace}/${t.name}`},P=e=>e==="query"?"GET":"POST",l="#/components/responses/LunoraError",f=/:([A-Za-z_$][\w$]*)/gu,T=e=>[...e.matchAll(f)].map(t=>t[1]),k=e=>e.replaceAll(f,"{$1}"),v=e=>{const t=new Set(T(e.path)),n=[];for(const[o,s]of Object.entries(e.searchParams)){const c=s.kind==="optional"?s.inner??s:s;n.push({description:`Query parameter \`${o}\``,in:"query",name:o,required:s.kind!=="optional",schema:u(c)})}for(const[o,s]of Object.entries(e.params)){const c=s.kind==="optional"?s.inner??s:s;n.push({description:`Path parameter \`${o}\``,in:t.has(o)?"path":"query",name:o,required:t.has(o)?!0:s.kind!=="optional",schema:u(c)})}return n},j=e=>e?{content:{"application/json":{schema:u(e)}},description:"Successful response."}:{content:{"application/json":{schema:{description:"Return shape is TS-inferred (no `.output()` declared); best-effort — any JSON."}}},description:"Successful response. The return shape is TypeScript-inferred and not declared via `.output()`, so it is documented best-effort."},N=e=>{const t=p(e.filePath),n=v(e),o={description:`${e.stream?"Streaming (SSE) ":""}HTTP route handler \`${e.exportName}\` (${e.method} ${e.path}).`,operationId:`${e.method.toLowerCase()}_${p(e.path)}`,responses:{200:j(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:l}},summary:`${e.method} ${e.path}`,tags:[t]};return n.length>0&&(o.parameters=n),Object.keys(e.body).length>0&&(o.requestBody={content:{"application/json":{schema:g(e.body)}},required:!0}),e.stream&&(o["x-lunora-stream"]="text/event-stream"),o},q=e=>{const t=`${p(e.filePath)}:${e.exportName}`,n=p(e.filePath),o={additionalProperties:!1,properties:{args:h(e.args),functionPath:{const:t,type:"string"},shardKey:{description:"Optional shard key; omitted routes to the default shard.",type:"string"}},required:["functionPath"],type:"object"};return{operation:{description:`Invoke the \`${e.kind}\` \`${t}\` over the Lunora RPC envelope (POST /_lunora/rpc).`,operationId:t,requestBody:{content:{"application/json":{schema:o}},required:!0},responses:{200:{content:{"application/json":{schema:{description:"RPC result. The shape is TS-inferred from the function's return type; best-effort — any JSON."}}},description:"Successful RPC result (TypeScript-inferred return shape, documented best-effort)."},default:{$ref:l}},summary:`${e.kind}: ${t}`,tags:[n],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${t}`}},R=e=>{const t=`${p(e.filePath)}:${e.exportName}`,n=b(t);if(n===void 0)return;const o=p(e.filePath),s=P(e.kind),c=s==="GET",r={description:`Public REST endpoint for the \`${e.kind}\` \`${t}\` (opt-in via \`.expose({ rest: true })\`). Routed through the procedure, so auth / RLS / validators are enforced.`,operationId:`rest_${p(n)}`,responses:{200:{content:{"application/json":{schema:{description:"Procedure result. The shape is TS-inferred from the return type; best-effort — any JSON."}}},description:"Successful result (TypeScript-inferred return shape, documented best-effort)."},default:{$ref:l}},summary:`${s} ${n}`,tags:[o],"x-lunora-function-kind":e.kind};if(c){const a=Object.entries(e.args).map(([i,d])=>{const m=d.kind==="optional"?d.inner??d:d;return{description:`Argument \`${i}\` (JSON-encoded for non-string values).`,in:"query",name:i,required:d.kind!=="optional",schema:u(m)}});return a.length>0&&(r.parameters=a),{method:"get",operation:r,path:n}}return r.requestBody={content:{"application/json":{schema:h(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:r,path:n}},A=e=>{const t=e.version??"0.0.0",n={},o=new Set;for(const r of e.httpRoutes){const a=k(r.path),i=n[a]??{};i[r.method.toLowerCase()]=N(r),n[a]=i,o.add(p(r.filePath))}const s=e.functions.filter(r=>r.visibility!=="internal"&&r.kind!=="stream");for(const r of s){const{operation:a,pathKey:i}=q(r);n[i]={post:a},o.add(p(r.filePath))}for(const r of s){if(r.expose?.rest!==!0)continue;const a=R(r);if(a===void 0)continue;const i=n[a.path]??{};i[a.method]=a.operation,n[a.path]=i,o.add(p(r.filePath))}const c=[...o].toSorted((r,a)=>r.localeCompare(a)).map(r=>({description:`Operations declared in \`lunora/${r}\`.`,name:r}));return{components:{responses:{LunoraError:{content:{"application/json":{schema:{additionalProperties:!1,description:"Standard Lunora error envelope.",properties:{error:{additionalProperties:!1,properties:{code:{description:"Machine-readable error code. Clients switch on this value.",enum:y,type:"string"},message:{description:"Human-readable error message (never echoes internal details).",type:"string"}},required:["code","message"],type:"object"}},required:["error"],type:"object"}}},description:"A Lunora error response. The HTTP status reflects the error code (e.g. BAD_REQUEST→400, UNAUTHORIZED→401, FORBIDDEN→403, NOT_FOUND→404)."}}},info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora API",version:t},openapi:"3.1.0",paths:n,tags:c}},_=e=>`${JSON.stringify(A(e),void 0,2)}
|
|
2
|
+
`,I=e=>`${$}export const openApiSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
|
|
3
|
+
`;export{A as buildOpenApiDocument,_ as emitOpenApi,I as emitOpenApiModule};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as r}from"ts-morph";const a=/\.ts$/u,s=t=>{for(const e of t.getAncestors())if(r.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0)return e.getName();return""};export{a as T,s as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{relative as u,sep as m}from"node:path";import{SyntaxKind as l,Node as s}from"ts-morph";import{T as g,e as d}from"./discover-ast-CezKqEhE.mjs";import{listLunoraSourceFiles as x}from"./discoverFunctions-zrIQk7J8.mjs";const E=r=>{const t=r.getExpression();if(!s.isPropertyAccessExpression(t))return!1;const e=t.getExpression();return s.isPropertyAccessExpression(e)?e.getName()==="authApi":s.isIdentifier(e)&&e.getText()==="authApi"},A=r=>{const t=r.getArguments()[0];if(t===void 0)return!1;if(!s.isObjectLiteralExpression(t))return!0;for(const e of t.getProperties())if((s.isPropertyAssignment(e)||s.isShorthandPropertyAssignment(e))&&e.getName()==="headers"||s.isSpreadAssignment(e))return!0;return!1},y=(r,t)=>{const e=[];for(const i of x(t)){const p=r.getSourceFile(i)??r.addSourceFileAtPath(i),c=u(t,i).replace(g,"").split(m).join("/");for(const o of p.getDescendantsOfKind(l.CallExpression)){if(!E(o))continue;const n=d(o);if(n==="")continue;const a=o.getExpression(),f=s.isPropertyAccessExpression(a)?a.getName():"";e.push({exportName:n,file:c,hasHeaders:A(o),line:o.getStartLineNumber(),method:f})}}return e};export{y as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as L}from"@lunora/errors";import{isValidCronExpression as A,compileCronSchedule as b,CRON_SCHEDULE_KINDS as O}from"@lunora/scheduler";import{SyntaxKind as p,Node as n}from"ts-morph";import{diagnosticAt as f}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{listLunoraSourceFiles as S}from"./discoverFunctions-zrIQk7J8.mjs";import{E as $}from"./module-specifiers-8FEEiUcv.mjs";import{n as I}from"./paths-BmX5O1sG.mjs";const j=new Set([...O,"cron"]),y=e=>{const t=e.getSymbol();if(!t)return e.getText()==="cronJobs";for(const r of t.getDeclarations())if(n.isImportSpecifier(r))return $(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="cronJobs":!1;return!1},R=e=>{const t=new Set;for(const r of e.getVariableDeclarations()){const i=r.getInitializer();if(i?.getKind()!==p.CallExpression)continue;const a=i.getExpression();n.isIdentifier(a)&&y(a)&&t.add(r.getName())}return t},P=e=>{let t=e;for(;n.isCallExpression(t)||n.isPropertyAccessExpression(t);)t=t.getExpression();return n.isIdentifier(t)?t.getText():void 0},C=(e,t)=>{const r=e.getArguments()[t];return r&&(n.isStringLiteral(r)||n.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},_=(e,t)=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)||n.isNumericLiteral(e))return e.getLiteralValue();if(n.isTrueLiteral(e))return!0;if(n.isFalseLiteral(e))return!1;if(n.isPrefixUnaryExpression(e)&&e.getOperatorToken()===p.MinusToken){const r=e.getOperand();if(n.isNumericLiteral(r))return-r.getLiteralValue()}if(n.isObjectLiteralExpression(e))return g(e,t);if(n.isArrayLiteralExpression(e))return e.getElements().map(r=>_(r,t));throw f(e,`Cron job "${t}" passes a non-static value where a literal is required; codegen can only read literals.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500})},g=(e,t)=>{const r={};for(const i of e.getProperties()){if(!n.isPropertyAssignment(i))throw f(i,`Cron job "${t}" uses an unsupported object property (shorthand/spread/method) where a static literal is required.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500});const a=i.getInitializer();a&&(r[i.getName()]=_(a,t))}return r},x=(e,t,r)=>{const i=e.getArguments()[t];if(!i||!n.isPropertyAccessExpression(i))throw f(e,`Cron job "${r}" must reference a function statically (e.g. internal.email.digest); codegen cannot resolve a dynamic reference.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const a=i.getName(),o=i.getExpression();if(!n.isPropertyAccessExpression(o))throw f(i,`Cron job "${r}" function reference must be of the form internal.file.fn (two property accesses).`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const s=o.getName();return`${I(s)}:${a}`},w=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),h=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),T=(e,t,r,i,a,o)=>{const s=e.getExpression();if(!n.isIdentifier(s)||s.getText()!==t)return;const c=r.get(e.getName());if(c)return o(c);throw f(e,`Cron job "${i}" targets ${t}.${e.getName()}, but no such ${a} is declared in lunora/${a}s.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})},D=(e,t,r,i,a)=>{const o=e.getArguments()[t];if(o&&n.isPropertyAccessExpression(o)){const s=T(o,"workflows",i,r,"workflow",w);return s||T(o,"agents",a,r,"agent",h)||{functionPath:x(e,t,r)}}if(o&&n.isIdentifier(o)){const s=i.get(o.getText()),c=a.get(o.getText());if(s&&c)throw f(o,`Cron job "${r}" references "${o.getText()}", which is ambiguous: a workflow and an agent are both declared under that name.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});if(s)return w(s);if(c)return h(c);throw f(o,`Cron job "${r}" references "${o.getText()}", which is neither a function (internal.file.fn / api.file.fn) nor a declared workflow in lunora/workflows.ts nor a declared agent in lunora/agents.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})}return{functionPath:x(e,t,r)}},k=(e,t,r,i,a)=>{const o=t.getName();if(!j.has(o)||!r.has(P(t.getExpression())??""))return;const s=C(e,0);if(s===void 0||s.trim()==="")throw f(e,`A cron ".${o}(...)" registration must pass a non-empty string-literal name as its first argument.`,{code:"CRON_NAME_NOT_STATIC",name:"LunoraError",status:500});let c;if(o==="cron"){const l=C(e,1);if(l===void 0)throw f(e,`Cron job "${s}" must pass a string-literal cron expression to ".cron(...)".`,{code:"CRON_EXPR_NOT_STATIC",name:"LunoraError",status:500});if(!A(l))throw f(e,`Cron job "${s}" has an invalid cron expression "${l}" — expected 5 or 6 space-separated fields.`,{code:"CRON_EXPR_INVALID",name:"LunoraError",status:500});c=l}else{const l=e.getArguments()[1];if(!l||!n.isObjectLiteralExpression(l))throw f(e,`Cron job "${s}" must pass an object-literal schedule to ".${o}(...)".`,{code:"CRON_SCHEDULE_NOT_STATIC",name:"LunoraError",status:500});c=b(o,g(l,s))}const u=D(e,2,s,i,a),m=e.getArguments()[3];return{args:m&&n.isObjectLiteralExpression(m)?g(m,s):{},cron:c,name:s,...u}},F=e=>{const t=new Set;for(const r of e){if(t.has(r.name))throw new L("DUPLICATE_CRON_NAME",`Duplicate cron job name "${r.name}": cron names must be unique across the project.`,{status:500});t.add(r.name)}},J=(e,t,r=[],i=[])=>{const a=S(t),o=[],s=new Map(r.map(u=>[u.exportName,u])),c=new Map(i.map(u=>[u.exportName,u]));for(const u of a){const m=e.getSourceFile(u)??e.addSourceFileAtPath(u),l=R(m);if(l.size!==0)for(const d of m.getDescendantsOfKind(p.CallExpression)){const N=d.getExpression();if(!n.isPropertyAccessExpression(N))continue;const E=k(d,N,l,s,c);E&&o.push(E)}}return o.sort((u,m)=>u.name.localeCompare(m.name)),F(o),o};export{J as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readdirSync as k,lstatSync as $}from"node:fs";import{join as w,extname as D,relative as F,sep as C}from"node:path";import{Node as s,SyntaxKind as j}from"ts-morph";import{t as O}from"./module-specifiers-8FEEiUcv.mjs";import{d as b}from"./parse-validator-CSDlMEvE.mjs";import{n as U}from"./paths-BmX5O1sG.mjs";const d=new Set(["action","mutation","query","stream"]),L=/\bany\b(?!\s*(?:\?\s*)?:)/u,z=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,V=/^[A-Za-z_$][\w$]*$/u,_=e=>V.test(e)?e:JSON.stringify(e),M=/\.ts$/u,H=(e,t)=>F(e,t).split(C).join("/").replace(M,""),v={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},B={onConnect:"connect",onDisconnect:"disconnect"},R=O,A=e=>{const t=e.getSymbol();if(!t)return e.getText();const i=t.getDeclarations();for(const r of i){if(!s.isImportSpecifier(r))continue;const n=r.getImportDeclaration().getModuleSpecifierValue();return R(n)?r.getNameNode().getText():void 0}},h=(e,t=!1)=>{let i=e;for(;s.isCallExpression(i);){const n=i.getExpression();if(!s.isPropertyAccessExpression(n))return;i=n.getExpression()}if(!s.isIdentifier(i))return;const r=A(i);if(r===void 0){if(t)return;const n=i.getSymbol()?.getValueDeclaration();if(n&&s.isVariableDeclaration(n)){const o=n.getInitializer();return o?h(o,!0):void 0}return}return d.has(r)?"public":v[r]?"internal":void 0},q=e=>{let t=e;for(;s.isCallExpression(t);){const i=t.getExpression();if(!s.isPropertyAccessExpression(i))return;if(i.getName()==="expose"){const r=t.getArguments()[0];if(r!==void 0&&s.isObjectLiteralExpression(r)){const n=r.getProperty("rest");if(n!==void 0&&s.isPropertyAssignment(n))return{rest:n.getInitializer()?.getText()==="true"}}return{}}t=i.getExpression()}},J=e=>{const t=e.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))return{};const i=t.getProperty("args");if(!i||!s.isPropertyAssignment(i))return{};const r=i.getInitializer();return!r||!s.isObjectLiteralExpression(r)?{}:b(r)},K=(e,t)=>{for(const i of[e.getSymbol(),e.getAliasSymbol()])if(i)for(const r of i.getDeclarations()){const n=r.getSourceFile();if(!(n.isInNodeModules()||n.isDeclarationFile())&&n.getFilePath()===t&&(s.isInterfaceDeclaration(r)||s.isTypeAliasDeclaration(r))&&!r.isExported())return!0}return!1},Q=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},P=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0,p=(e,t,i,r=new Set)=>r.has(e)?!1:(r.add(e),K(e,i)||Q(e).some(n=>p(n,t,i,r))?!0:P(e)?e.getProperties().some(n=>p(n.getTypeAtLocation(t),t,i,r)):!1),G=(e,t)=>{const i=e.getValueDeclaration()??e.getDeclarations()[0];return i&&(s.isPropertySignature(i)||s.isPropertyDeclaration(i))&&i.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},W=8,Z=(e,t,i,r,n,o)=>{const a=e.getArrayElementType(),c=a?o(a,t,i,r,n):void 0;if(c!==void 0)return a?.isUnion()?`(${c})[]`:`${c}[]`},X=(e,t,i,r,n,o)=>{const a=[];for(const c of e.getUnionTypes()){const l=o(c,t,i,r,n);if(l===void 0)return;a.push(l)}return a.join(" | ")},Y=(e,t,i,r,n,o)=>{if(!P(e))return;const a=[];for(const c of e.getProperties()){const l=c.getTypeAtLocation(t),y=G(c,l),I=y&&l.isUnion()?l.getUnionTypes().filter(f=>!f.isUndefined()):[l],m=[];for(const f of I){const x=o(f,t,i,r+1,n);if(x===void 0)return;m.push(x)}a.push(`${_(c.getName())}${y?"?":""}: ${m.join(" | ")}`)}return a.length>0?`{ ${a.join("; ")} }`:"{}"},g=(e,t,i,r,n)=>{if(r>W||n.has(e))return;if(!p(e,t,i))return e.getText(t);const o=new Set(n).add(e);return e.isArray()?Z(e,t,i,r,o,g):e.isUnion()?X(e,t,i,r,o,g):Y(e,t,i,r,o,g)},S=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let i=t.getReturnType();const r=(i.getSymbol()??i.getAliasSymbol())?.getName();if(r==="Promise"||r==="AsyncIterable"||r==="AsyncIterableIterator"||r==="AsyncGenerator"){const a=i.getTypeArguments()[0];a&&(i=a)}const n=i.getText(e);if(!n||n==="any"||n==="never"||L.test(n.replaceAll(z,"")))return"unknown";const o=e.getSourceFile().getFilePath();return p(i,e,o)?g(i,e,o,0,new Set)??"unknown":n},ee=e=>{const t=e.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))return"unknown";const i=t.getProperty("handler");if(!i||!s.isPropertyAssignment(i))return"unknown";const r=i.getInitializer();return!r||!(s.isArrowFunction(r)||s.isFunctionExpression(r))?"unknown":S(r)},te=e=>{const t=e.getArguments()[0];return!t||!(s.isArrowFunction(t)||s.isFunctionExpression(t))?"unknown":S(t)},ie=e=>{let t={},i=e;for(;s.isCallExpression(i);){const r=i.getExpression();if(!s.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const n=i.getArguments()[0];n&&s.isObjectLiteralExpression(n)&&(t={...b(n),...t})}i=r.getExpression()}return t},re=e=>{const t=e.getExpression();if(s.isPropertyAccessExpression(t)){const o=t.getName();if(!d.has(o))return;const a=t.getExpression();if(a.getType().getProperty("__lunoraProcedure"))return{kind:o,receiver:a,visibility:a.getType().getProperty("__lunoraVisibility")?"internal":"public"};const c=h(a);return c?{kind:o,receiver:a,visibility:c}:void 0}if(!s.isIdentifier(t))return;const i=A(t);if(!i)return;if(d.has(i))return{kind:i,visibility:"public"};const r=v[i];if(r)return{kind:r,visibility:"internal"};const n=B[i];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}},E=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,xe=e=>s.isPropertyAccessExpression(e)&&e.getName()==="db"||s.isIdentifier(e)&&e.getText()==="db",Ee=e=>{const t=e.getArguments()[0],i=E(t);if(i!==void 0)return i;if(t===void 0||!s.isObjectLiteralExpression(t))return;const r=t.getProperty("handler");return r!==void 0&&s.isPropertyAssignment(r)?E(r.getInitializer()):void 0},ne=e=>s.isIdentifier(e)?e.getText():s.isPropertyAccessExpression(e)?e.getName():"",be=(e,t)=>{let i=e;for(;s.isCallExpression(i);){const r=i.getExpression();if(!s.isPropertyAccessExpression(r))break;if(r.getName()===t)return!0;i=r.getExpression()}return!1},ve=(e,t,i)=>{let r=e;for(;s.isCallExpression(r);){const n=r.getExpression();if(!s.isPropertyAccessExpression(n))break;const o=r.getArguments()[0];if(n.getName()===t&&o!==void 0&&s.isCallExpression(o)&&ne(o.getExpression())===i)return!0;r=n.getExpression()}return!1},N=(e,t=[],i=e)=>{let r;try{r=k(e)}catch{return t}for(const n of r){const o=w(e,n),a=$(o);if(a.isDirectory()){if(n==="_generated"||n==="node_modules")continue;N(o,t,i)}else if(a.isFile()&&D(n)===".ts"){if(n==="schema.ts"&&e===i)continue;t.push(o)}}return t},se=e=>{const t=re(e);if(t){if(t.receiver){const i=q(t.receiver);return{args:ie(t.receiver),...i?{expose:i}:{},kind:t.kind,returnType:te(e),visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:J(e),kind:t.kind,returnType:ee(e),visibility:t.visibility}}},oe=8,u=(e,t=0)=>{if(t>oe)return;if(s.isCallExpression(e))return e;if(s.isParenthesizedExpression(e)||s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isNonNullExpression(e))return u(e.getExpression(),t+1);if(!s.isIdentifier(e)&&!s.isPropertyAccessExpression(e))return;const i=e.getSymbol()?.getValueDeclaration();return i?T(i,t+1):void 0},T=(e,t)=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e)){const i=e.getInitializer();return i?u(i,t):void 0}if(s.isShorthandPropertyAssignment(e))return u(e.getNameNode(),t);if(s.isBindingElement(e)){const i=e.getPropertyNameNode()?.getText()??e.getName(),r=e.getFirstAncestorByKind(j.VariableDeclaration)?.getInitializer()?.getType().getProperty(i)?.getValueDeclaration();return r?T(r,t+1):void 0}},ae=e=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t)){const n=[];for(const o of t.getElements()){const a=u(o.getNameNode());a&&n.push([o.getName(),a])}return n}const i=e.getInitializer(),r=i&&(s.isCallExpression(i)?i:u(i));return r?[[e.getName(),r]]:[]},ce=(e,t,i)=>{const r=se(e);if(r)return{args:r.args,exportName:t,filePath:i,kind:r.kind,returnType:r.returnType,visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},le=(e,t)=>{const i=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations())for(const[o,a]of ae(n)){const c=ce(a,o,t);c&&i.push(c)}return i},ue=e=>{const t=new Map;for(const i of e){const r=U(i.filePath),n=t.get(r);if(n&&n!==i.filePath)throw Object.assign(new Error(`Namespace collision: "${n}" and "${i.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[n,i.filePath],status:500});t.set(r,i.filePath)}},Ae=(e,t)=>{const i=N(t),r=[];for(const n of i){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),a=H(t,n);r.push(...le(o,a))}return r.sort((n,o)=>`${n.filePath}:${n.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),ue(r),r};export{be as chainHasStep,ve as chainUsesWrappedCall,re as classifyProcedureCall,Ae as discoverFunctions,E as inlineHandler,xe as isDatabaseAccessor,N as listLunoraSourceFiles,H as lunoraRelativePath,Ee as procedureHandler,S as unwrapHandlerReturn};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{relative as m,sep as h}from"node:path";import{Node as a}from"ts-morph";import{listLunoraSourceFiles as l,unwrapHandlerReturn as f}from"./discoverFunctions-zrIQk7J8.mjs";import{s as d,d as g}from"./parse-validator-CSDlMEvE.mjs";const x=/\.ts$/u,u=new Set(["delete","get","head","options","patch","post","put"]),E=new Set(["body","params","searchParams"]),P=new Set(["handler","stream"]),A=r=>{const e=r.getArguments()[0];if(e&&a.isStringLiteral(e))return e.getLiteralValue()},y=r=>{const e=r.getArguments()[0];return e&&a.isObjectLiteralExpression(e)?g(e):{}},b=r=>{if(!a.isCallExpression(r))return;const e=r.getExpression();if(!a.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const n=e.getExpression();if(!a.isIdentifier(n)||n.getText()!=="httpRoute")return;const s=A(r);return s===void 0?void 0:{method:o.toUpperCase(),path:s}},S=(r,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},n=r.getExpression();if(!a.isPropertyAccessExpression(n))return;let s=n.getExpression();for(;a.isCallExpression(s);){const i=s.getExpression();if(!a.isPropertyAccessExpression(i))break;const p=i.getName();if(u.has(p))break;if(E.has(p)){const c=y(s);o[p]={...c,...o[p]}}else if(p==="output"&&o.output===void 0){const c=s.getArguments()[0];c&&a.isExpression(c)&&(o.output=d(c))}s=i.getExpression()}const t=b(s);if(t)return o.method=t.method,o.path=t.path,o},C=r=>{const e=r.getArguments()[0];return!e||!(a.isArrowFunction(e)||a.isFunctionExpression(e))?"unknown":f(e)},v=(r,e,o,n)=>{const s=e.getName();if(!P.has(s))return;const t=S(r,s);if(!(t?.method===void 0||t.path===void 0))return{body:t.body,exportName:o,filePath:n,method:t.method,params:t.params,path:t.path,searchParams:t.searchParams,stream:t.stream,...t.stream?{chunkType:C(r)}:{},...t.output?{output:t.output}:{}}},w=(r,e)=>{const o=[];for(const n of r.getVariableStatements())if(n.isExported())for(const s of n.getDeclarations()){const t=s.getInitializer();if(!t||!a.isCallExpression(t))continue;const i=t.getExpression();if(!a.isPropertyAccessExpression(i))continue;const p=v(t,i,s.getName(),e);p&&o.push(p)}return o},L=(r,e)=>{const o=l(e),n=[];for(const s of o){const t=r.getSourceFile(s)??r.addSourceFileAtPath(s),i=m(e,s).split(h).join("/").replace(x,"");n.push(...w(t,i))}return n.sort((s,t)=>`${s.method} ${s.path}`.localeCompare(`${t.method} ${t.path}`)||s.filePath.localeCompare(t.filePath)),n};export{L as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SyntaxKind as c,Node as i}from"ts-morph";import{e as f}from"./discover-ast-CezKqEhE.mjs";import{listLunoraSourceFiles as g,lunoraRelativePath as u}from"./discoverFunctions-zrIQk7J8.mjs";const m=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="insert")return!1;const r=e.getExpression();return i.isPropertyAccessExpression(r)?r.getName()==="db":i.isIdentifier(r)&&r.getText()==="db"},p=t=>{if(!i.isIdentifier(t))return;const e=t.getSymbol(),r=e?.getAliasedSymbol()?.getDeclarations()??e?.getDeclarations()??[];for(const s of r)if(i.isVariableDeclaration(s)){const n=s.getInitializer();if(n&&i.isStringLiteral(n))return n.getLiteralText()}},x=t=>{const e=t.getArguments()[0];return e?i.isStringLiteral(e)?e.getLiteralText():p(e)??"":""},E=(t,e)=>{const r=[];for(const s of g(e)){const n=t.getSourceFile(s)??t.addSourceFileAtPath(s),l=u(e,s);for(const o of n.getDescendantsOfKind(c.CallExpression)){if(!m(o))continue;const a=f(o);a!==""&&r.push({exportName:a,file:l,line:o.getStartLineNumber(),table:x(o)})}}return r};export{E as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as n,SyntaxKind as P}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as E,classifyProcedureCall as g}from"./discoverFunctions-zrIQk7J8.mjs";const S=t=>{if(!n.isCallExpression(t))return!1;const e=t.getExpression();return n.isIdentifier(e)?e.getText()==="mask":n.isPropertyAccessExpression(e)?e.getName()==="mask":!1},f=t=>{if(n.isPropertyAssignment(t)||n.isShorthandPropertyAssignment(t)||n.isMethodDeclaration(t)||n.isGetAccessorDeclaration(t))return t.getName()},v=t=>{const e=t.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return[];const s=[];for(const r of e.getProperties()){const o=f(r);if(o===void 0||!n.isPropertyAssignment(r))continue;const i=r.getInitializer();if(!(!i||!n.isObjectLiteralExpression(i)))for(const a of i.getProperties()){const c=f(a);c!==void 0&&s.push({column:c,table:o})}}return s},p=t=>{const e=[];let s=t;for(;n.isCallExpression(s);){const r=s.getExpression();if(!n.isPropertyAccessExpression(r))break;if(r.getName()==="use"){const o=s.getArguments()[0];o&&S(o)&&e.push(o)}s=r.getExpression()}return e},A=t=>{const e=p(t);return{maskColumns:e.flatMap(s=>v(s)),usesMask:e.length>0}},y=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),k=new Set(["delete","insert","patch","replace"]),x=(t,e)=>{const s=t.getExpression();if(!n.isPropertyAccessExpression(s)||!e.has(s.getName()))return!1;const r=s.getExpression();return n.isPropertyAccessExpression(r)?r.getName()==="db":n.isIdentifier(r)&&r.getText()==="db"},b=t=>{const e=t.getArguments()[0];return e&&n.isStringLiteral(e)?e.getLiteralText():""},M=t=>{const e=new Set,s=new Set;for(const r of t.getDescendantsOfKind(P.CallExpression))if(x(r,y)){const o=b(r);o!==""&&e.add(o)}else if(x(r,k)){const o=b(r);o!==""&&s.add(o)}return{tablesRead:[...e],tablesWritten:[...s]}},C=(t,e)=>{if(!n.isVariableDeclaration(t))return;const s=t.getInitializer();if(!s||!n.isCallExpression(s))return;const r=g(s);if(!r)return;const o=r.receiver?A(r.receiver):{maskColumns:[],usesMask:!1},{tablesRead:i,tablesWritten:a}=M(t);return{exportName:t.getName(),file:e,maskColumns:o.maskColumns,tablesRead:i,tablesWritten:a,usesMask:o.usesMask,visibility:r.visibility}},O=(t,e)=>{const s=[];for(const r of u(e)){const o=t.getSourceFile(r)??t.addSourceFileAtPath(r),i=E(e,r);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations()){const l=C(c,i);l&&s.push(l)}}return s},h=t=>{if(n.isPropertyAssignment(t)){const e=t.getInitializer();if(e&&n.isStringLiteral(e)){const s=e.getLiteralText();if(s==="redact"||s==="hash")return s}}return"custom"},L=t=>{const e=t.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return[];const s=[];for(const r of e.getProperties()){const o=f(r);if(o===void 0||!n.isPropertyAssignment(r))continue;const i=r.getInitializer();if(!(!i||!n.isObjectLiteralExpression(i)))for(const a of i.getProperties()){const c=f(a);c!==void 0&&s.push({column:c,strategy:h(a),table:o})}}return s},N=t=>{const e=[];for(const s of t.getVariableStatements())if(s.isExported())for(const r of s.getDeclarations()){const o=r.getInitializer(),i=o&&n.isCallExpression(o)?g(o):void 0;i?.receiver&&e.push(i.receiver)}return e},j=(t,e)=>{const s=new Map;for(const r of u(e)){const o=t.getSourceFile(r)??t.addSourceFileAtPath(r);for(const i of N(o))for(const a of p(i))for(const c of L(a)){const l=`${c.table}\0${c.column}`;s.has(l)||s.set(l,c)}}return{columns:[...s.values()]}},F=(t,e,s)=>{const r=t.getArguments()[0];if(!r||!n.isObjectLiteralExpression(r))return[];const o=[];for(const i of r.getProperties()){const a=f(i);if(a===void 0||!n.isPropertyAssignment(i))continue;const c=i.getInitializer();if(!(!c||!n.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const m=f(l);if(m===void 0)continue;const d=h(l);d!=="custom"&&o.push({column:m,exportName:e,file:s,line:l.getStartLineNumber(),strategy:d,table:a})}}return o},I=(t,e)=>{if(!n.isVariableDeclaration(t))return[];const s=t.getInitializer(),r=s&&n.isCallExpression(s)?g(s):void 0;return r?.receiver?p(r.receiver).flatMap(o=>F(o,t.getName(),e)):[]},w=(t,e)=>{const s=[];for(const r of u(e)){const o=t.getSourceFile(r)??t.addSourceFileAtPath(r),i=E(e,r);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...I(c,i))}return s};export{O as default,j as discoverMaskMetadata,w as discoverMaskStrategies};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{relative as g,sep as u}from"node:path";import{SyntaxKind as m,Node as a}from"ts-morph";import{diagnosticAt as p}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{listLunoraSourceFiles as h}from"./discoverFunctions-zrIQk7J8.mjs";import{o as I}from"./module-specifiers-8FEEiUcv.mjs";const x=/\.ts$/u,S=r=>{const i=r.getSymbol();if(!i)return r.getText()==="defineMigration";for(const t of i.getDeclarations())if(a.isImportSpecifier(t))return I(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMigration":!1;return!1},f=(r,i)=>{const t=r.getProperty(i);if(!t||!a.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&a.isStringLiteral(e)?e.getLiteralValue():void 0},b=(r,i)=>{const t=r.getInitializer();if(t?.getKind()!==m.CallExpression)return;const e=t.getExpression();if(!a.isIdentifier(e)||!S(e))return;const o=t.getArguments()[0];if(!o||!a.isObjectLiteralExpression(o))return;const n=f(o,"id"),s=r.getName();if(n===void 0||n.trim()==="")throw p(o,`Migration "${s}" in "${i}" must declare \`id\` as a non-empty string literal so codegen can key the registry.`,{code:"MIGRATION_ID_NOT_STATIC",name:"LunoraError",status:500});return{exportName:s,filePath:i,id:n,table:f(o,"table")??""}},M=r=>{const i=new Map;for(const t of r){const e=i.get(t.id);if(e!==void 0)throw Object.assign(new Error(`Duplicate migration id "${t.id}": declared in both "${e}" and "${t.filePath}". Migration ids must be unique across the project.`),{code:"DUPLICATE_MIGRATION_ID",id:t.id,name:"LunoraError",paths:[e,t.filePath],status:500});i.set(t.id,t.filePath)}},y=(r,i)=>{const t=h(i),e=[];for(const o of t){const n=r.getSourceFile(o)??r.addSourceFileAtPath(o),s=g(i,o).split(u).join("/").replace(x,"");for(const c of n.getVariableStatements())if(c.isExported())for(const d of c.getDeclarations()){const l=b(d,s);l&&e.push(l)}}return e.sort((o,n)=>o.id.localeCompare(n.id)),M(e),e};export{y as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as o,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as u,classifyProcedureCall as l}from"./discoverFunctions-zrIQk7J8.mjs";const d={"crypto.getRandomValues":"crypto.getRandomValues","crypto.randomUUID":"crypto.randomUUID","Date.now":"Date.now","Math.random":"Math.random"},f=new Set(["globalThis","self"]),g=new Set(["globalThis","self","window"]),p=t=>{if(o.isIdentifier(t))return t.getText();if(o.isPropertyAccessExpression(t)){const e=t.getExpression();if(o.isIdentifier(e)&&g.has(e.getText()))return t.getName()}},m=t=>{const e=t.getExpression();if(o.isIdentifier(e)){const i=e.getText();return i==="fetch"||i==="Date"?i:void 0}if(!o.isPropertyAccessExpression(e))return;const r=e.getName(),n=p(e.getExpression());if(n!==void 0)return r==="fetch"&&f.has(n)?"fetch":d[`${n}.${r}`]},x=t=>{const e=t.getExpression();if(!o.isIdentifier(e)||e.getText()!=="Date")return;const r=t.getArguments(),n=r.every(i=>o.isNumericLiteral(i)||o.isStringLiteral(i)||o.isNoSubstitutionTemplateLiteral(i));return r.length>0&&n?void 0:"new Date"},h=(t,e)=>{if(e){const s=t.getArguments()[0];return s&&(o.isArrowFunction(s)||o.isFunctionExpression(s))?s:void 0}const r=t.getArguments()[0];if(!r||!o.isObjectLiteralExpression(r))return;const n=r.getProperty("handler");if(!n||!o.isPropertyAssignment(n))return;const i=n.getInitializer();return i&&(o.isArrowFunction(i)||o.isFunctionExpression(i))?i:void 0},N=t=>{const e=t.getInitializer();if(!e||!o.isCallExpression(e))return;const r=l(e);if(!r||r.kind!=="query"&&r.kind!=="mutation")return;const n=h(e,r.receiver);return n?{exportName:t.getName(),handler:n,kind:r.kind}:void 0},E=(t,e)=>{const r=[];for(const n of t.handler.getDescendantsOfKind(a.CallExpression)){const i=m(n);i!==void 0&&r.push({callee:i,exportName:t.exportName,file:e,kind:t.kind,line:n.getStartLineNumber()})}for(const n of t.handler.getDescendantsOfKind(a.NewExpression)){const i=x(n);i!==void 0&&r.push({callee:i,exportName:t.exportName,file:e,kind:t.kind,line:n.getStartLineNumber()})}return r},y=(t,e)=>{const r=[];for(const n of t.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const s=N(i);s&&r.push(...E(s,e))}return r},w=(t,e)=>{const r=[];for(const n of c(e)){const i=t.getSourceFile(n)??t.addSourceFileAtPath(n);r.push(...y(i,u(e,n)))}return r};export{w as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SyntaxKind as u,Node as n}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as g}from"./discoverFunctions-zrIQk7J8.mjs";const x=new Set(["withIndex","withSearchIndex"]),p=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():""},E=(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(!p(i))continue;const a=d(i);a.includes("filter")&&t.push({file:c,hasFilter:!0,hasIndex:a.some(l=>x.has(l)),line:i.getStartLineNumber(),table:h(i)})}}return t};export{E as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as o,SyntaxKind as c}from"ts-morph";import{listLunoraSourceFiles as a,lunoraRelativePath as u,classifyProcedureCall as l}from"./discoverFunctions-zrIQk7J8.mjs";const p=(t,r)=>{if(r){const n=t.getArguments()[0];return n&&(o.isArrowFunction(n)||o.isFunctionExpression(n))?n:void 0}const e=t.getArguments()[0];if(!e||!o.isObjectLiteralExpression(e))return;const s=e.getProperty("handler");if(!s||!o.isPropertyAssignment(s))return;const i=s.getInitializer();return i&&(o.isArrowFunction(i)||o.isFunctionExpression(i))?i:void 0},f=t=>{const r=t.getInitializer();if(!r||!o.isCallExpression(r))return;const e=l(r);if(!e||e.kind!=="query"&&e.kind!=="mutation")return;const s=p(r,e.receiver);return s?{exportName:t.getName(),handler:s,kind:e.kind}:void 0},d=t=>{if(!o.isPropertyAccessExpression(t)||t.getName()!=="r2sql")return;const r=t.getExpression();if(!o.isIdentifier(r)||r.getText()!=="ctx")return;const e=t.getParent();return e&&o.isPropertyAccessExpression(e)&&e.getExpression()===t?`ctx.r2sql.${e.getName()}`:"ctx.r2sql"},g=(t,r)=>{const e=[];for(const s of t.handler.getDescendantsOfKind(c.PropertyAccessExpression)){const i=d(s);i!==void 0&&e.push({callee:i,exportName:t.exportName,file:r,kind:t.kind,line:s.getStartLineNumber()})}return e},x=(t,r)=>{const e=[];for(const s of t.getVariableStatements())if(s.isExported())for(const i of s.getDeclarations()){const n=f(i);n&&e.push(...g(n,r))}return e},A=(t,r)=>{const e=[];for(const s of a(r)){const i=t.getSourceFile(s)??t.addSourceFileAtPath(s);e.push(...x(i,u(r,s)))}return e};export{A as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as n,SyntaxKind as A}from"ts-morph";import{listLunoraSourceFiles as E,lunoraRelativePath as b,classifyProcedureCall as y}from"./discoverFunctions-zrIQk7J8.mjs";const S=t=>{if(!n.isCallExpression(t))return!1;const e=t.getExpression();return n.isIdentifier(e)?e.getText()==="rls":n.isPropertyAccessExpression(e)?e.getName()==="rls":!1},h=t=>{const e=t.getArguments()[0];if(!e||!n.isArrayLiteralExpression(e))return[];const r=[];for(const s of e.getElements()){if(!n.isObjectLiteralExpression(s))continue;const i=s.getProperty("table");if(!i||!n.isPropertyAssignment(i))continue;const o=i.getInitializer();o&&n.isStringLiteral(o)&&r.push(o.getLiteralText())}return r},L=t=>{const e=[];let r=t;for(;n.isCallExpression(r);){const s=r.getExpression();if(!n.isPropertyAccessExpression(s))break;if(s.getName()==="use"){const i=r.getArguments()[0];i&&S(i)&&e.push(i)}r=s.getExpression()}return e},v=t=>{const e=L(t);return{rlsTables:e.flatMap(r=>h(r)),usesRls:e.length>0}},P=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),T=new Set(["delete","deleteMany","insert","insertMany","patch","patchMany","replace"]),g=(t,e)=>{const r=t.getExpression();if(!n.isPropertyAccessExpression(r)||!e.has(r.getName()))return!1;const s=r.getExpression();return n.isPropertyAccessExpression(s)?s.getName()==="db":n.isIdentifier(s)&&s.getText()==="db"},d=t=>{const e=t.getArguments()[0];return e&&n.isStringLiteral(e)?e.getLiteralText():""},M=t=>{const e=new Set,r=new Set;for(const s of t.getDescendantsOfKind(A.CallExpression))if(g(s,P)){const i=d(s);i!==""&&e.add(i)}else if(g(s,T)){const i=d(s);i!==""&&r.add(i)}return{tablesRead:[...e],tablesWritten:[...r]}},R=(t,e)=>{if(!n.isVariableDeclaration(t))return;const r=t.getInitializer();if(!r||!n.isCallExpression(r))return;const s=y(r);if(!s)return;const i=s.receiver?v(s.receiver):{rlsTables:[],usesRls:!1},{tablesRead:o,tablesWritten:a}=M(t);return{exportName:t.getName(),file:e,rlsTables:i.rlsTables,tablesRead:o,tablesWritten:a,usesRls:i.usesRls,visibility:s.visibility}},D=(t,e)=>{const r=[];for(const s of E(e)){const i=t.getSourceFile(s)??t.addSourceFileAtPath(s),o=b(e,s);for(const a of i.getVariableStatements())if(a.isExported())for(const f of a.getDeclarations()){const c=R(f,o);c&&r.push(c)}}return r},C=new Set(["delete","insert","read","update"]),l=(t,e)=>{if(!n.isObjectLiteralExpression(t))return;const r=t.getProperty(e);if(!r||!n.isPropertyAssignment(r))return;const s=r.getInitializer();return s&&n.isStringLiteral(s)?s.getLiteralText():void 0},F=(t,e,r)=>{const s=t.getArguments()[0];if(!s||!n.isArrayLiteralExpression(s))return[];const i=[];for(const o of s.getElements()){if(!n.isObjectLiteralExpression(o))continue;const a=l(o,"on");a===void 0||!C.has(a)||i.push({file:e,on:a,procedure:r,table:l(o,"table")??""})}return i},m=t=>{if(!n.isObjectLiteralExpression(t))return[];const e=t.getProperty("permissions");if(!e||!n.isPropertyAssignment(e))return[];const r=e.getInitializer();if(!r||!n.isArrayLiteralExpression(r))return[];const s=[];for(const i of r.getElements()){if(n.isStringLiteral(i)){s.push(i.getLiteralText());continue}if(n.isCallExpression(i)){const o=i.getArguments()[0];o&&n.isStringLiteral(o)&&s.push(o.getLiteralText())}}return s},x=(t,e)=>e===void 0?t:{...t,description:e},I=t=>{if(n.isCallExpression(t)){const e=t.getArguments()[0];if(!e||!n.isStringLiteral(e))return;const r=t.getArguments()[1],s=r?l(r,"description"):void 0,i=r?m(r):[];return x({name:e.getLiteralText(),permissions:i},s)}if(n.isObjectLiteralExpression(t)){const e=l(t,"name");return e===void 0?void 0:x({name:e,permissions:m(t)},l(t,"description"))}},N=t=>{const e=t.getArguments()[1];if(!e||!n.isObjectLiteralExpression(e))return[];const r=e.getProperty("roles");if(!r||!n.isPropertyAssignment(r))return[];const s=r.getInitializer();if(!s||!n.isArrayLiteralExpression(s))return[];const i=[];for(const o of s.getElements()){const a=I(o);a&&i.push(a)}return i},O=(t,e,r)=>{const s=L(t);return{policies:s.flatMap(i=>F(i,e,r)),roles:s.flatMap(i=>N(i))}},w=t=>{const e=[];for(const r of t.getVariableStatements())if(r.isExported())for(const s of r.getDeclarations()){const i=s.getInitializer(),o=i&&n.isCallExpression(i)?y(i):void 0;o?.receiver&&e.push({name:s.getName(),receiver:o.receiver})}return e},V=(t,e)=>{const r=[],s=new Map;for(const i of E(e)){const o=t.getSourceFile(i)??t.addSourceFileAtPath(i),a=b(e,i);for(const{name:f,receiver:c}of w(o)){const p=O(c,a,f);r.push(...p.policies);for(const u of p.roles)s.has(u.name)||s.set(u.name,u)}}return{policies:r,roles:[...s.values()]}};export{D as default,V as discoverRlsMetadata};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{listLunoraSourceFiles as u}from"./discoverFunctions-zrIQk7J8.mjs";const i=new Set(["@lunora/agent","@lunora/agent/sandbox"]),d=o=>{const s={usesSandboxBrowser:!1,usesSandboxContainer:!1};if(!i.has(o.getModuleSpecifierValue())||o.isTypeOnly())return s;for(const e of o.getNamedImports()){if(e.isTypeOnly())continue;const n=e.getNameNode().getText();n==="browserTool"?s.usesSandboxBrowser=!0:n==="containerTool"&&(s.usesSandboxContainer=!0)}return s},c=(o,s)=>{const e={usesSandboxBrowser:!1,usesSandboxContainer:!1};for(const n of u(s)){const a=o.getSourceFile(n)??o.addSourceFileAtPath(n);for(const t of a.getImportDeclarations()){const r=d(t);e.usesSandboxBrowser||=r.usesSandboxBrowser,e.usesSandboxContainer||=r.usesSandboxContainer}if(e.usesSandboxBrowser&&e.usesSandboxContainer)break}return e};export{c as discoverSandboxUsage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as j}from"@lunora/errors";import{Node as s,SyntaxKind as w}from"ts-morph";import{diagnosticAt as f}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{d as T}from"./parse-validator-CSDlMEvE.mjs";import{createRequire as N}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}:{}}),g=e=>{const r=e?._meta??{},t=e?.kind??"unknown",n={column:$(r.column),kind:t};switch(t){case"array":case"optional":{n.inner=g(r.inner);break}case"id":{n.tableName=r.tableName;break}case"literal":{n.literalValue=_(r.value);break}case"object":{const i=r.shape??{};n.shape=Object.fromEntries(Object.entries(i).map(([o,a])=>[o,g(a)]));break}case"record":{n.valueType=g(r.valueValidator),r.keyValidator!==void 0&&(n.keyType=g(r.keyValidator));break}case"storage":{typeof r.bucket=="string"&&(n.bucket=r.bucket);break}case"union":{const i=r.members??[];n.members=i.map(o=>g(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,r)=>{const t=[];e.relationMap&&Object.keys(e.relationMap).length>0&&t.push("relations"),e.rankIndexes&&e.rankIndexes.length>0&&t.push("rank indexes"),e.vectorIndexes&&e.vectorIndexes.length>0&&t.push("vector indexes"),t.length>0&&console.warn(`@lunora/codegen: package schema-extension table "${r}" declares ${t.join(" + ")}, which are not yet introspected from a node_modules extension — they will be absent from the generated types.`)},D=(e,r)=>{const t=e.shape??{},n=(e.indexes??[]).map(i=>({fields:i.fields,name:i.name,...i.unique?{unique:!0}:{}}));return z(e,r),{...e.isExternallyManaged?{externallyManaged:!0}:{},geoIndexes:[],indexes:n,name:r,rankIndexes:[],relations:[],searchIndexes:(e.searchIndexes??[]).map(i=>({field:i.field,...i.filterFields?{filterFields:i.filterFields}:{},...i.language===void 0?{}:{language:i.language},...i.staged===void 0?{}:{staged:i.staged},...i.strategy===void 0?{}:{strategy:i.strategy},name:i.name})),shape:Object.fromEntries(Object.entries(t).map(([i,o])=>[i,g(o)])),shardMode:M(e.shardMode),vectorIndexes:[]}},B=e=>{const{key:r,tables:t}=e;if(typeof r!="string"||typeof t!="object"||t===null)return;const n=Object.entries(t).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:r}},q=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e)){const r=e.getExpression();return s.isIdentifier(r)?r.getText():void 0}},F=e=>{const r=q(e);if(r===void 0)return;const t=s.isPropertyAccessExpression(e)?e.getName():void 0,n=t===void 0?[]:[t];for(const i of e.getSourceFile().getImportDeclarations()){const o=i.getModuleSpecifierValue();for(const a of i.getNamedImports())if((a.getAliasNode()?.getText()??a.getName())===r)return{importedName:a.getName(),moduleSpecifier:o,propertyPath:n};if(i.getDefaultImport()?.getText()===r)return{importedName:"default",moduleSpecifier:o,propertyPath:n};if(i.getNamespaceImport()?.getText()===r&&t!==void 0)return{importedName:t,moduleSpecifier:o,propertyPath:[]}}},C=(e,r)=>{let t=e[r.importedName];for(const n of r.propertyPath){if(typeof t!="object"||t===null)return;t=t[n]}return t},V=(e,r)=>{const t=F(e);if(t)try{const n=N(O(r,"noop.cjs")),i=n.resolve(t.moduleSpecifier),o=n(i),a=C(o,t);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,r)=>{if(E.has(e))throw f(r,`table name "${e}" is reserved — it collides with a \`ctx.db\` member (one of ${[...E].map(t=>`"${t}"`).join(", ")}). Rename the table.`)},c=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&s.isStringLiteral(n))return n.getLiteralText()}},m=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&s.isNumericLiteral(n))return Number(n.getLiteralText())}},U=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&(s.isTrueLiteral(n)||s.isFalseLiteral(n)))return n.getLiteralValue()}},h=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.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,G=e=>e&&J.has(e)?e:void 0,H=e=>{if(!s.isArrowFunction(e))return;let r=e.getBody();if(s.isParenthesizedExpression(r))r=r.getExpression();else if(s.isBlock(r)){const t=r.getStatements().find(n=>s.isReturnStatement(n));r=t&&s.isReturnStatement(t)?t.getExpression()??r:r}return s.isObjectLiteralExpression(r)?r:void 0},Q=e=>{if(!s.isPropertyAssignment(e))return;const r=e.getInitializer();if(!r||!s.isCallExpression(r))return;const t=r.getExpression();if(!s.isPropertyAccessExpression(t))return;const n=t.getName();if(n!=="one"&&n!=="many")return;const[i,o]=r.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"?G(c(o,"onDelete")):void 0),{field:l,kind:n,name:e.getName(),onDelete:u,references:d,table:a}},W=e=>{const r=H(e);if(!r)return[];const t=[];for(const n of r.getProperties()){const i=Q(n);i&&t.push(i)}return t},x=e=>e&&s.isStringLiteral(e)?e.getLiteralText():"_unnamed_",X=e=>{const[r,t,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 f(a,`\`unique\` must be a literal \`true\` or \`false\`, got ${JSON.stringify(a.getText())}`);i=a?s.isTrueLiteral(a):!1}}return{fields:t&&s.isArrayLiteralExpression(t)?t.getElements().filter(o=>s.isStringLiteral(o)).map(o=>o.getLiteralText()):[],name:x(r),unique:i}},Y=e=>{const[r,t]=e;let n="_unknown_",i,o,a,l;return t&&s.isObjectLiteralExpression(t)&&(n=c(t,"field")??n,i=h(t,"filterFields"),o=c(t,"language"),a=U(t,"staged"),l=c(t,"strategy")),{field:n,filterFields:i,language:o,name:x(r),staged:a,strategy:l}},Z=e=>{const[r,t]=e;let n="_unknown_",i;return t&&s.isObjectLiteralExpression(t)&&(n=c(t,"field")??n,i=m(t,"precision")),{field:n,name:x(r),precision:i}},ee=e=>{const[r,t]=e,n=r&&s.isStringLiteral(r)?r.getLiteralText():"_unknown_";let i;return t&&s.isObjectLiteralExpression(t)&&(i=m(t,"after")),{after:i,field:n}},te=e=>{if(!s.isObjectLiteralExpression(e))return;const r=c(e,"field");return r===void 0?void 0:{direction:c(e,"direction")==="desc"?"desc":"asc",field:r}},re=e=>{const[r,t]=e;let n=[],i;if(t&&s.isObjectLiteralExpression(t)){const o=t.getProperty("sortBy");if(o&&s.isPropertyAssignment(o)){const a=o.getInitializer();a&&s.isArrayLiteralExpression(a)&&(n=a.getElements().map(l=>te(l)).filter(l=>l!==void 0))}i=h(t,"partitionBy")}return{name:x(r),partitionBy:i,sortBy:n}},ne=(e,r)=>{const[t,n]=e,i=t&&s.isStringLiteral(t)?t.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:r}},ie=e=>{const r=e[0];return r&&s.isObjectLiteralExpression(r)&&c(r,"backend")==="hyperdrive"?"hyperdrive":"d1"},se=e=>{if(e&&s.isObjectLiteralExpression(e)){const r=e.getProperty("field");if(r&&s.isPropertyAssignment(r)){const t=r.getInitializer();if(t&&s.isStringLiteral(t))return t.getLiteralText()}}return"deletedAt"},p=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.getInitializer();if(n&&s.isStringLiteral(n))return n.getLiteralText()}},oe=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t)){const n=t.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}}},ae=e=>{const r=e[0];return!r||!s.isObjectLiteralExpression(r)?{binding:"",hasTenantBy:!1,unanalyzable:!0}:{binding:p(r,"binding")??"",columns:oe(r,"columns"),hasReconcile:r.getProperty("reconcileEveryMs")!==void 0,hasSoftDelete:r.getProperty("softDeleteColumn")!==void 0,hasTenantBy:r.getProperty("tenantBy")!==void 0,idColumn:p(r,"idColumn"),mode:p(r,"mode"),query:p(r,"query")}},le=(e,r,t,n)=>{switch(r){case"externallyManaged":{e.externallyManaged=!0;break}case"geoIndex":{e.geoIndexes.push(Z(t));break}case"global":{e.shardMode="global",e.globalBackend=ie(t);break}case"index":{e.indexes.push(X(t));break}case"public":{e.isPublic=!0;break}case"rankIndex":{e.rankIndexes.push(re(t));break}case"relations":{const i=t[0];i&&e.relations.push(...W(i));break}case"searchIndex":{e.searchIndexes.push(Y(t));break}case"shardBy":{const i=t[0];e.shardMode={field:i&&s.isStringLiteral(i)?i.getLiteralText():"_unknown_",kind:"shardBy"};break}case"softDelete":{e.softDelete={field:se(t[0])};break}case"source":{e.externalSource=ae(t),e.externallyManaged=!0;break}case"ttl":{e.ttl=ee(t);break}case"vectorize":{const i=ne(t,n);i&&e.vectorIndexes.push(i);break}}},L=(e,r)=>{const t={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))le(t,o.getName(),a,r),i=o.getExpression();else if(s.isIdentifier(o)&&o.getText()==="defineTable"){const l=a[0];l&&s.isObjectLiteralExpression(l)&&(n=T(l));break}else break}return t.softDelete&&!(t.softDelete.field in n)&&(n={...n,[t.softDelete.field]:{inner:{kind:"number"},kind:"optional"}}),{externallyManaged:t.externallyManaged,externalSource:t.externalSource,geoIndexes:t.geoIndexes,globalBackend:t.shardMode==="global"?t.globalBackend??"d1":void 0,indexes:t.indexes,isPublic:t.isPublic,name:r,rankIndexes:t.rankIndexes,relations:t.relations,searchIndexes:t.searchIndexes,shape:n,shardMode:t.shardMode,softDelete:t.softDelete,ttl:t.ttl,vectorIndexes:t.vectorIndexes}},ce=e=>{const r=e.getProperty("source");if(r&&s.isPropertyAssignment(r)){const t=r.getInitializer();if(t&&s.isObjectLiteralExpression(t))return c(t,"table")??"_unknown_"}return"_unknown_"},de=e=>{if(!s.isPropertyAssignment(e))return;const r=e.getInitializer();if(!r||!s.isCallExpression(r))return;const t=r.getExpression();if(!s.isIdentifier(t)||t.getText()!=="defineVectorIndex")return;const n=r.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:ce(n)}},P=e=>{const r=[];for(const t of e.getProperties()){const n=de(t);n&&r.push(n)}return r},k=(e,r)=>`${e}_${r}`,y=(e,r,t)=>t.has(e)?k(r,e):e,ue=(e,r,t)=>{const n=k(r,e.name);return{...e,extensionKey:r,name:n,relations:e.relations.map(i=>({...i,table:y(i.table,r,t)})),vectorIndexes:e.vectorIndexes.map(i=>({...i,table:y(i.table,r,t)}))}},ge=e=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e))return e.getInitializer();if(s.isShorthandPropertyAssignment(e))return e.getNameNode()},fe=(e,r)=>{const t=e.getProperty(r);if(t&&s.isPropertyAssignment(t))return t.getInitializer()},pe=e=>{if(!s.isCallExpression(e))return!1;const r=e.getExpression();return s.isIdentifier(r)&&r.getText()==="defineSchemaExtension"},me=e=>{if(s.isIdentifier(e))return e;if(s.isPropertyAccessExpression(e)){const r=e.getExpression();return s.isIdentifier(r)?r:void 0}},xe=e=>{if(s.isObjectLiteralExpression(e))return e;if(s.isCallExpression(e)){const r=e.getExpression();let t;if(s.isIdentifier(r)?t=r.getText():s.isPropertyAccessExpression(r)&&(t=r.getName()),t==="definePlugin"){const n=e.getArguments()[1];return n&&s.isObjectLiteralExpression(n)?n:void 0}}},be=(e,r)=>{const t=ge(e);if(t){if(s.isPropertyAccessExpression(r)){const n=xe(t);return n?fe(n,r.getName()):void 0}return t}},ye=e=>{let r=e,t=0;for(;r&&t<32;){if(t+=1,pe(r))return r;const n=me(r),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;r=be(o,r)}},he=e=>{const[r,t]=e.getArguments();if(!(!r||!s.isStringLiteral(r))&&!(!t||!s.isObjectLiteralExpression(t)))return{key:r.getLiteralText(),options:t}},ke=e=>{const r=e.getProperty("tables");if(!r||!s.isPropertyAssignment(r))return[];const t=r.getInitializer();if(!t||!s.isObjectLiteralExpression(t))return[];const n=[];for(const i of t.getProperties()){if(!s.isPropertyAssignment(i))continue;const o=i.getInitializer();o&&n.push(L(o,i.getName()))}return n},Ie=e=>{const r=e.getProperty("vectorIndexes");if(!r||!s.isPropertyAssignment(r))return[];const t=r.getInitializer();return!t||!s.isObjectLiteralExpression(t)?[]:P(t)},S=(e,r,t)=>{const n=new Set(r.map(a=>a.name)),i=r.map(a=>ue(a,e,n)),o=t.map(a=>({...a,name:k(e,a.name),table:y(a.table,e,n)}));return{tables:i,vectorIndexes:o}},Ee=(e,r)=>S(e,ke(r),Ie(r)),ve=(e,r)=>{const t=e.getArguments()[0];if(!t)return;const n=ye(t);if(!n){if(r!==void 0){const o=V(t,r);if(o)return S(o.key,o.bareTables,o.bareVectorIndexes)}console.warn(`@lunora/codegen: skipping \`.extend(${t.getText()})\` — its \`defineSchemaExtension(...)\` could not be resolved from local sources, and ${r===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=he(n);if(!i){console.warn("@lunora/codegen: skipping `.extend(...)` — `defineSchemaExtension` requires a string `key` and an options object literal.");return}return Ee(i.key,i.options)},Le=e=>{const r=[];let t=e;for(;;){const n=t.getParent();if(!n||!s.isPropertyAccessExpression(n))break;const i=n.getParent();if(!i||!s.isCallExpression(i))break;n.getName()==="extend"&&r.push(i),t=i}return r},A=(e,r,t,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()===r){const d=l.getArguments()[0];if(!d||!s.isStringLiteral(d))throw f(l,`\`.${r}(...)\` expects a string literal (${i})`);const u=d.getLiteralText();if(!n.has(u))throw f(d,`unknown ${t} ${JSON.stringify(u)} — expected ${i}`);return u}o=l}},Pe=new Set(["eu","fedramp","us"]),Se=e=>A(e,"jurisdiction","jurisdiction",Pe,'"eu", "us", or "fedramp"'),Ae=new Set(["required"]),je=e=>A(e,"rls","rls mode",Ae,'"required"'),we=e=>{const r=[];for(const t of e.getProperties()){if(!s.isPropertyAssignment(t))continue;const n=t.getInitializer();if(n){const i=t.getName();K(i,t.getNameNode()),r.push(L(n,i))}}return r},Te=(e,r,t)=>{const n=new Set(r.map(o=>o.name)),i=[];for(const o of Le(e)){const a=ve(o,t);if(a){for(const l of a.tables){if(n.has(l.name))throw f(o,`defineSchema(...).extend(...): table "${l.name}" already exists — another extension with the same key already contributed it.`);n.add(l.name),r.push(l)}i.push(...a.vectorIndexes)}}return i},De=(e,r,t)=>{const n=e.addSourceFileAtPath(r).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 ${r}`);const i=n.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))throw f(n,"defineSchema() expects an object literal");const o=we(i),a=n.getArguments()[1],l=a&&s.isObjectLiteralExpression(a)?P(a):[],d=Te(n,o,t),u=[...o.flatMap(b=>b.vectorIndexes),...l,...d];return{jurisdiction:Se(n),rlsMode:je(n),tables:o,vectorIndexes:u}};export{De as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as i}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as p,classifyProcedureCall as g}from"./discoverFunctions-zrIQk7J8.mjs";const x=new Set(["delete","list","read","write"]),m=s=>{if(!i.isCallExpression(s))return!1;const r=s.getExpression();return i.isIdentifier(r)?r.getText()==="storageRules":i.isPropertyAccessExpression(r)&&r.getName()==="storageRules"},d=s=>{const r=[];let t=s;for(;i.isCallExpression(t);){const e=t.getExpression();if(!i.isPropertyAccessExpression(e))break;if(e.getName()==="use"){const o=t.getArguments()[0];o&&m(o)&&r.push(o)}t=e.getExpression()}return r},u=(s,r)=>{if(!i.isObjectLiteralExpression(s))return;const t=s.getProperty(r);if(!t||!i.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&i.isStringLiteral(e)?e.getLiteralText():void 0},E=(s,r,t)=>{const e=s.getArguments()[0];if(!e||!i.isArrayLiteralExpression(e))return[];const o=[];for(const n of e.getElements()){if(!i.isObjectLiteralExpression(n))continue;const c=u(n,"on");if(c===void 0||!x.has(c))continue;const a=u(n,"prefix"),l={bucket:u(n,"bucket")??"",file:r,on:c,procedure:t};a!==void 0&&(l.prefix=a),o.push(l)}return o},v=s=>{const r=[];for(const t of s.getVariableStatements())if(t.isExported())for(const e of t.getDeclarations()){const o=e.getInitializer(),n=o&&i.isCallExpression(o)?g(o):void 0;n?.receiver&&r.push({name:e.getName(),receiver:n.receiver})}return r},A=(s,r)=>{const t=[];for(const e of f(r)){const o=s.getSourceFile(e)??s.addSourceFileAtPath(e),n=p(r,e);for(const{name:c,receiver:a}of v(o))for(const l of d(a))t.push(...E(l,n,c))}return{rules:t}};export{A as default};
|