@lunora/codegen 1.0.0-alpha.8 → 1.0.0-alpha.81
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 +2576 -823
- package/dist/index.d.ts +2576 -823
- 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/DEFAULT_TARGET-BYPEwgZu.mjs +1 -0
- package/dist/packem_shared/FLAGS_FILENAME-UPE377GV.mjs +1 -0
- package/dist/packem_shared/GENERATED_HEADER-CR3xA8yO.mjs +1 -0
- package/dist/packem_shared/LUNORA_ERROR_CODES-Um9hC1gr.mjs +1 -0
- package/dist/packem_shared/MUTATORS_FILENAME-CsAoG-d2.mjs +1 -0
- package/dist/packem_shared/NOTIFY_FILENAME-zA5OFFbv.mjs +1 -0
- package/dist/packem_shared/OPENRPC_VERSION-DfKtsdPS.mjs +3 -0
- package/dist/packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs +1 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DjpfF4p7.mjs +12 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs +2 -0
- package/dist/packem_shared/SHAPES_FILENAME-DyVUZzIk.mjs +1 -0
- package/dist/packem_shared/SchemaSnapshotParseError-0KRzSjo4.mjs +14 -0
- package/dist/packem_shared/WORKFLOWS_FILENAME-ClsYRKXp.mjs +1 -0
- package/dist/packem_shared/buildOpenApiDocument-D46nZ7D_.mjs +3 -0
- package/dist/packem_shared/discover-ast-CezKqEhE.mjs +1 -0
- package/dist/packem_shared/discover-queries-Ctpk9SA-.mjs +1 -0
- package/dist/packem_shared/discoverAuthApiCalls-CYdI8pkP.mjs +1 -0
- package/dist/packem_shared/discoverCrons-CwtPaymU.mjs +1 -0
- package/dist/packem_shared/discoverFunctions-CVYkUBTm.mjs +1 -0
- package/dist/packem_shared/discoverHttpRoutes-DmTedJlp.mjs +1 -0
- package/dist/packem_shared/discoverInserts-CssZuKb6.mjs +1 -0
- package/dist/packem_shared/discoverMaskProcedures-DQ-4yUUK.mjs +1 -0
- package/dist/packem_shared/discoverMigrations-qyXaVjw1.mjs +1 -0
- package/dist/packem_shared/discoverNondeterministicCalls-GNP4oKrf.mjs +1 -0
- package/dist/packem_shared/discoverQueries-2A0lbpxV.mjs +1 -0
- package/dist/packem_shared/discoverR2sqlCalls-B7uqLnVS.mjs +1 -0
- package/dist/packem_shared/discoverRlsMetadata-Bt0QK8VM.mjs +1 -0
- package/dist/packem_shared/discoverSandboxUsage-Bb2JzaIW.mjs +1 -0
- package/dist/packem_shared/discoverSchema-DUl8rbP3.mjs +1 -0
- package/dist/packem_shared/discoverStorageRulesMetadata-VJ_uXOFe.mjs +1 -0
- package/dist/packem_shared/emit-CCw5fiXq.mjs +2176 -0
- package/dist/packem_shared/emitApp-DEHN578T.mjs +449 -0
- package/dist/packem_shared/formatAdvisories-BCEfzLT0.mjs +2 -0
- package/dist/packem_shared/module-specifiers-8FEEiUcv.mjs +1 -0
- package/dist/packem_shared/parse-validator-_jDrFxwt.mjs +1 -0
- package/dist/packem_shared/paths-BmX5O1sG.mjs +1 -0
- package/dist/packem_shared/redact-6jD4lAhq.mjs +1 -0
- package/dist/packem_shared/schemaFromIr-R1ZFzVyy.mjs +1 -0
- package/package.json +12 -7
- package/dist/packem_shared/CONTAINERS_FILENAME-DlP6YM_Q.mjs +0 -224
- package/dist/packem_shared/CodegenDiagnosticError-DeblMkzO.mjs +0 -23
- 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-Ic_wUaIc.mjs +0 -937
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-DzLDbWk3.mjs +0 -233
- package/dist/packem_shared/WORKFLOWS_FILENAME-D62dcBGg.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-nHPo3UeE.mjs +0 -257
- 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-Dy24kmeD.mjs +0 -97
- 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-fVmAXacI.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-DeblMkzO.mjs';
|
|
3
|
-
export { default as discoverAuthApiCalls } from './packem_shared/discoverAuthApiCalls-C35R6z0T.mjs';
|
|
4
|
-
export { CONTAINERS_FILENAME, discoverContainers } from './packem_shared/CONTAINERS_FILENAME-DlP6YM_Q.mjs';
|
|
5
|
-
export { default as discoverCrons } from './packem_shared/discoverCrons-nHPo3UeE.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-Dy24kmeD.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-fVmAXacI.mjs';
|
|
16
|
-
export { default as discoverStorageRulesMetadata } from './packem_shared/discoverStorageRulesMetadata-DAqJUxUv.mjs';
|
|
17
|
-
export { WORKFLOWS_FILENAME, discoverWorkflows } from './packem_shared/WORKFLOWS_FILENAME-D62dcBGg.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-Ic_wUaIc.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{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as p}from"./packem_shared/formatAdvisories-BCEfzLT0.mjs";import{CodegenDiagnosticError as c,diagnosticAt as n}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as l,discoverAgents as E}from"./packem_shared/AGENTS_FILENAME-BesaDYkL.mjs";import{default as A}from"./packem_shared/discoverAuthApiCalls-CYdI8pkP.mjs";import{CONTAINERS_FILENAME as v,discoverContainers as N}from"./packem_shared/CONTAINERS_FILENAME-CFwdyaCI.mjs";import{default as R}from"./packem_shared/discoverCrons-CwtPaymU.mjs";import{FLAGS_FILENAME as C,discoverFlags as g}from"./packem_shared/FLAGS_FILENAME-UPE377GV.mjs";import{discoverFunctions as I}from"./packem_shared/discoverFunctions-CVYkUBTm.mjs";import{default as L}from"./packem_shared/discoverHttpRoutes-DmTedJlp.mjs";import{default as T}from"./packem_shared/discoverInserts-CssZuKb6.mjs";import{default as D}from"./packem_shared/discoverMaskProcedures-DQ-4yUUK.mjs";import{default as H}from"./packem_shared/discoverMigrations-qyXaVjw1.mjs";import{MUTATORS_FILENAME as y,discoverMutators as W}from"./packem_shared/MUTATORS_FILENAME-CsAoG-d2.mjs";import{default as V}from"./packem_shared/discoverNondeterministicCalls-GNP4oKrf.mjs";import{NOTIFY_FILENAME as k,discoverNotifyCalls as z,discoverNotifyConfig as Q}from"./packem_shared/NOTIFY_FILENAME-zA5OFFbv.mjs";import{y as J}from"./packem_shared/discover-queries-Ctpk9SA-.mjs";import{QUEUES_FILENAME as q,discoverQueues as B}from"./packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs";import{default as $}from"./packem_shared/discoverR2sqlCalls-B7uqLnVS.mjs";import{discoverRlsMetadata as Z,default as ee}from"./packem_shared/discoverRlsMetadata-Bt0QK8VM.mjs";import{discoverSandboxUsage as re}from"./packem_shared/discoverSandboxUsage-Bb2JzaIW.mjs";import{default as se}from"./packem_shared/discoverSchema-DUl8rbP3.mjs";import{SHAPES_FILENAME as ie,discoverShapes as me}from"./packem_shared/SHAPES_FILENAME-DyVUZzIk.mjs";import{default as pe}from"./packem_shared/discoverStorageRulesMetadata-VJ_uXOFe.mjs";import{WORKFLOWS_FILENAME as ce,discoverWorkflows as ne}from"./packem_shared/WORKFLOWS_FILENAME-ClsYRKXp.mjs";import{R as le,J as Ee,y as xe,x as Ae,H as ue,p as ve,n as Ne,u as Oe,N as Re,$ as Me,a as Ce,g as ge,G as he,m as Ie}from"./packem_shared/emit-CCw5fiXq.mjs";import{emitApp as Le}from"./packem_shared/emitApp-DEHN578T.mjs";import{buildOpenApiDocument as Te,emitOpenApi as Pe,emitOpenApiModule as De}from"./packem_shared/buildOpenApiDocument-D46nZ7D_.mjs";import{OPENRPC_VERSION as He,buildOpenRpcDocument as Ge,emitOpenRpc as ye,emitOpenRpcModule as We}from"./packem_shared/OPENRPC_VERSION-DfKtsdPS.mjs";import{DEFAULT_TARGET as Ve,platformMatrixIds as je,readProjectTarget as ke,resolveCodegenTarget as ze}from"./packem_shared/DEFAULT_TARGET-BYPEwgZu.mjs";import{SCHEMA_SNAPSHOT_FILENAME as we,createCodegenProject as Je,refreshCodegenProject as Ke,runCodegen as qe}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-DjpfF4p7.mjs";import{SchemaSnapshotParseError as Ye,buildSchemaSnapshot as $e,evaluateSchemaDrift as Xe,parseSchemaSnapshot as Ze}from"./packem_shared/SchemaSnapshotParseError-0KRzSjo4.mjs";import{schemaFromIr as oo}from"./packem_shared/schemaFromIr-R1ZFzVyy.mjs";import{LUNORA_ERROR_CODES as to,validatorIrToJsonSchema as so}from"./packem_shared/LUNORA_ERROR_CODES-Um9hC1gr.mjs";import{redact as io,secretKindOf as mo}from"./packem_shared/redact-6jD4lAhq.mjs";import{MESSAGE_SOLUTIONS as fo,findSolutionByMessage as co}from"@lunora/errors";const e="0.0.0";export{l as AGENTS_FILENAME,v as CONTAINERS_FILENAME,c as CodegenDiagnosticError,Ve as DEFAULT_TARGET,C as FLAGS_FILENAME,le as GENERATED_HEADER,to as LUNORA_ERROR_CODES,fo as LUNORA_SOLUTION_RULES,y as MUTATORS_FILENAME,k as NOTIFY_FILENAME,He as OPENRPC_VERSION,q as QUEUES_FILENAME,we as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,ie as SHAPES_FILENAME,Ye as SchemaSnapshotParseError,e as VERSION,ce as WORKFLOWS_FILENAME,Te as buildOpenApiDocument,Ge as buildOpenRpcDocument,$e as buildSchemaSnapshot,Je as createCodegenProject,n as diagnosticAt,s as diffSchemaSnapshots,E as discoverAgents,A as discoverAuthApiCalls,N as discoverContainers,R as discoverCrons,g as discoverFlags,I as discoverFunctions,L as discoverHttpRoutes,T as discoverInserts,D as discoverMaskProcedures,H as discoverMigrations,W as discoverMutators,V as discoverNondeterministicCalls,z as discoverNotifyCalls,Q as discoverNotifyConfig,J as discoverQueries,B as discoverQueues,$ as discoverR2sqlCalls,Z as discoverRlsMetadata,ee as discoverRlsProcedures,re as discoverSandboxUsage,se as discoverSchema,me as discoverShapes,pe as discoverStorageRulesMetadata,ne as discoverWorkflows,Ee as emitAgents,xe as emitApi,Le as emitApp,Ae as emitCollections,ue as emitContainers,ve as emitCrons,Ne as emitDataModel,Oe as emitDrizzleSchema,Re as emitFunctions,Pe as emitOpenApi,De as emitOpenApiModule,ye as emitOpenRpc,We as emitOpenRpcModule,Me as emitServer,Ce as emitShard,ge as emitVectors,he as emitWorkflows,Ie as emitWranglerCronTriggers,Xe as evaluateSchemaDrift,co as findLunoraSolution,m as formatAdvisories,d as lintSchema,Ze as parseSchemaSnapshot,je as platformMatrixIds,ke as readProjectTarget,io as redact,Ke as refreshCodegenProject,ze as resolveCodegenTarget,qe as runCodegen,oo as schemaFromIr,mo as secretKindOf,a as serializeSchemaSnapshot,p as toAdvisorContext,so 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,readFileSync as c}from"node:fs";import{join as u}from"node:path";import{CLOUDFLARE_CAPABILITIES as g}from"@lunora/platform";import{parse as m}from"jsonc-parser";const f="cloudflare",p="lunora.json",d=t=>{const e=u(t,p);if(!l(e))return;let a;try{a=c(e,"utf8")}catch{return}const s=[],o=m(a,s,{allowTrailingComma:!0});if(s.length>0||o===null||typeof o!="object")return;const{target:r}=o;return typeof r=="string"&&r.length>0?r:void 0},C=(t,e)=>e??d(t)??f,n={cloudflare:g},j=()=>Object.keys(n).toSorted((t,e)=>t.localeCompare(e)),y={ai:"ai",analytics:"analytics",browser:"browser",container:"containers",hyperdrive:"hyperdrive",kv:"keyValueStore",mail:"mail",pipelines:"pipelines",scheduler:"scheduler",storage:"objectStorage",vectors:"vectorStore",workflows:"workflows"},h=(t,e,a)=>{const s={...t},o=[];for(const[r,i]of Object.entries(y))t[r]&&e.features[i]?.level==="unsupported"&&(s[r]=!1,o.push({feature:r,level:"error",message:`${e.name} does not support "${r}" (ctx.${r}). Its surface was omitted from the generated types.`,name:"platform_unsupported_feature",remediation:`Remove the ctx.${r} usage, or deploy to a target whose capability matrix marks "${i}" as native or emulated.`,target:a}));return{diagnostics:o,usage:s}},x=(t,e)=>{const a=n[e];return a===void 0?{diagnostics:[{level:"error",message:`Unknown deploy target "${e}" — no capability matrix is registered for it. Codegen emitted the full Cloudflare surface un-gated.`,name:"platform_unknown_target",remediation:`Use a registered target (${Object.keys(n).join(", ")}) or install the target's @lunora/platform-${e} package.`,target:e}],usage:{...t}}:h(t,a,e)};export{f as DEFAULT_TARGET,p as PROJECT_CONFIG_FILE,h as gateAgainstMatrix,x as gatePlatformFeatures,j as platformMatrixIds,d as readProjectTarget,C as resolveCodegenTarget};
|
|
@@ -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-CVYkUBTm.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"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{R as r,b as o,J as n,y as l,x as p,H as g,p as u,n as c,u as C,N as E,z as S,c as d,$ as A,a as D,g as z,G as R,m as b}from"./emit-CCw5fiXq.mjs";import"./paths-BmX5O1sG.mjs";export{r as GENERATED_HEADER,o as buildStorageColumns,n as emitAgents,l as emitApi,p as emitCollections,g as emitContainers,u as emitCrons,c as emitDataModel,C as emitDrizzleSchema,E as emitFunctions,S as emitQueues,d as emitSeed,A as emitServer,D as emitShard,z as emitVectors,R 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 u}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{unwrapHandlerReturn as g}from"./discoverFunctions-CVYkUBTm.mjs";import{t as d}from"./module-specifiers-8FEEiUcv.mjs";import{c as x}from"./parse-validator-_jDrFxwt.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(u.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()!==u.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 c=S(n);e.push({args:A(c),exportName:s.getText(),filePath:"mutators",returnType:M(c)})}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-CVYkUBTm.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},S=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=S(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"},F=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,L=(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=F(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},D=(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,L as discoverNotifyCalls,D as discoverNotifyConfig};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{R as a}from"./emit-CCw5fiXq.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,12 @@
|
|
|
1
|
+
import{existsSync as E,readFileSync as ye,mkdirSync as Gt,writeFileSync as Ht,rmSync as Qt}from"node:fs";import{join as g,dirname as fe}from"node:path";import{performance as me}from"node:perf_hooks";import{runAdvisor as Jt}from"@lunora/advisor";import{LunoraError as R}from"@lunora/errors";import{Node as i,SyntaxKind as u,Project as tt}from"ts-morph";import{serializeSchemaSnapshot as Xt}from"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{toAdvisorContext as Zt}from"./formatAdvisories-BCEfzLT0.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as p,classifyProcedureCall as k,inlineHandler as Yt,procedureHandler as ht,chainUsesWrappedCall as Et,isDatabaseAccessor as C,chainHasStep as es,discoverFunctions as ts,resolveStandardSchemaType as ss}from"./discoverFunctions-CVYkUBTm.mjs";import{discoverAgents as rs}from"./AGENTS_FILENAME-BesaDYkL.mjs";import{i as w,a as O,e as h,c as S,r as ns,s as G,b as is,d as os,y as as}from"./discover-queries-Ctpk9SA-.mjs";import cs from"./discoverAuthApiCalls-CYdI8pkP.mjs";import{discoverContainers as us}from"./CONTAINERS_FILENAME-CFwdyaCI.mjs";import ls from"./discoverCrons-CwtPaymU.mjs";import{diagnosticAt as H}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{o as Q}from"./module-specifiers-8FEEiUcv.mjs";import{r as xe,b as ds,n as gs,y as ps,$ as fs,N as ms,a as xs,x as hs,H as Es,G as $s,J as ys,z as As,p as Ss,g as Ns,u as bs,c as vs,m as Ps}from"./emit-CCw5fiXq.mjs";import{discoverFlagKeys as ws}from"./FLAGS_FILENAME-UPE377GV.mjs";import Is from"./discoverHttpRoutes-DmTedJlp.mjs";import Ls from"./discoverInserts-CssZuKb6.mjs";import Ts,{discoverMaskStrategies as Os,discoverMaskMetadata as Fs}from"./discoverMaskProcedures-DQ-4yUUK.mjs";import Ds from"./discoverMigrations-qyXaVjw1.mjs";import{MUTATORS_FILENAME as Cs,isDefineMutatorCallee as ks,discoverMutators as Ks}from"./MUTATORS_FILENAME-CsAoG-d2.mjs";import Rs from"./discoverNondeterministicCalls-GNP4oKrf.mjs";import{discoverNotifyConfig as js,discoverNotifyCalls as zs}from"./NOTIFY_FILENAME-zA5OFFbv.mjs";import{discoverQueues as Ms}from"./QUEUES_FILENAME-CSE6i-ld.mjs";import qs from"./discoverR2sqlCalls-B7uqLnVS.mjs";import Bs,{discoverRlsMetadata as Vs}from"./discoverRlsMetadata-Bt0QK8VM.mjs";import{discoverSandboxUsage as Us}from"./discoverSandboxUsage-Bb2JzaIW.mjs";import Ws from"./discoverSchema-DUl8rbP3.mjs";import{secretKindOf as _s,redact as Gs,isHeuristicSecretKind as Hs,isSecretishName as Qs}from"./redact-6jD4lAhq.mjs";import{discoverShapes as Js}from"./SHAPES_FILENAME-DyVUZzIk.mjs";import Xs from"./discoverStorageRulesMetadata-VJ_uXOFe.mjs";import{e as Zs}from"./discover-ast-CezKqEhE.mjs";import{discoverWorkflows as Ys}from"./WORKFLOWS_FILENAME-ClsYRKXp.mjs";import{emitApp as er}from"./emitApp-DEHN578T.mjs";import{buildOpenApiDocument as tr,emitOpenApiModule as sr}from"./buildOpenApiDocument-D46nZ7D_.mjs";import{buildOpenRpcDocument as rr,emitOpenRpcModule as nr}from"./OPENRPC_VERSION-DfKtsdPS.mjs";import{p as ir}from"./parse-validator-_jDrFxwt.mjs";import{gatePlatformFeatures as or,resolveCodegenTarget as ar}from"./DEFAULT_TARGET-BYPEwgZu.mjs";import{buildSchemaSnapshot as cr}from"./SchemaSnapshotParseError-0KRzSjo4.mjs";const ur=e=>{const t=[],s=e.tables.filter(r=>r.shardMode==="global");return s.some(r=>r.globalBackend!=="hyperdrive")&&t.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),s.some(r=>r.globalBackend==="hyperdrive")&&t.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'}),e.vectorIndexes.length>0&&t.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/vectors.ts` import `@lunora/bindings/vectors`"}),t},lr=(e,t)=>{if(t===void 0)return;const s=ur(e).filter(o=>!t.has(o.name));if(s.length===0)return;const r=s.map(o=>` - ${o.name} — ${o.reason}`).join(`
|
|
2
|
+
`),n=s.map(o=>o.name).join(" ");throw new R("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
|
|
3
|
+
${r}
|
|
4
|
+
|
|
5
|
+
Install them, then re-run codegen:
|
|
6
|
+
|
|
7
|
+
pnpm add ${n}
|
|
8
|
+
`)},$t=new Set(["delete","get","head","options","patch","post","put"]),dr=new Set(["handler","stream"]),gr=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,st=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),pr=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!$t.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()}},fr=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)||$t.has(r.getName()))break;s=r.getExpression()}return pr(s)},mr=e=>{for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression))if(st.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&st.has(s.getText()))return!0}return!1},xr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||!dr.has(r.getName()))return;const n=fr(s);if(!n||!gr.test(n.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&mr(o);return{exportName:e.getName(),file:t,method:n.method,path:n.path,usesGuard:a}},hr=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=xr(n,t);o&&s.push(o)}return s},Er=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...hr(n,p(t,r)))}return s},$r=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",yr=(e,t)=>{if(!$r(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)||O(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},Ar=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=yr(r,t);n&&s.push(n)}return s},Sr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ar(n,p(t,r)))}return s},Nr=new Set(["generateText","streamText"]),br=new Set(["messages","prompt","system"]),vr=[{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"]}],Pr=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),r=t.getExpression().getText();for(const n of vr)if(n.methods.has(s)&&n.prefixes.some(o=>r===o||r.startsWith(`${o}.`)))return`${r}.${s}`},wr=e=>{for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=Pr(t);if(s!==void 0)return s}},Ir=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},Lr=e=>{if(ns(e))return!0;const t=Ir(e);return t.size===0?!1:e.getDescendantsOfKind(u.Identifier).some(s=>t.has(s.getText()))},Tr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!br.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&Lr(s))return!0}return!1},Or=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());if(n===void 0||!Nr.has(n))continue;const[o]=r.getArguments();if(o===void 0||!i.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(u.CallExpression))if(S(c.getExpression())==="tool"&&(a=wr(c),a!==void 0))break;a!==void 0&&s.push({exportName:h(r),file:t,line:r.getStartLineNumber(),method:n,sideEffect:a,userInputDerived:Tr(o)})}return s},Fr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Or(n,p(t,r)))}return s},Dr=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},Cr=(e,t)=>{if(!Dr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},kr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Cr(r,t);n&&s.push(n)}return s},Kr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...kr(n,p(t,r)))}return s},yt=e=>e.getProperties().some(t=>i.isSpreadAssignment(t)),Rr=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const r=s.getInitializer();return!r||!i.isObjectLiteralExpression(r)?{objects:[],opaque:!0}:{objects:[r],opaque:yt(r)}},jr=e=>{const t=[];let s=!1,r=e;for(;i.isCallExpression(r);){const n=r.getExpression();if(!i.isPropertyAccessExpression(n))break;if(n.getName()==="input"){const o=r.getArguments()[0];o&&i.isObjectLiteralExpression(o)?(t.push(o),s||=yt(o)):s=!0}r=n.getExpression()}return{objects:t,opaque:s}},At=(e,t)=>t?jr(t):Rr(e),zr=e=>e.flatMap(t=>t.getProperties().filter(s=>i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)).map(s=>s.getName())),Mr=/\.check\(|\.meta\(|length|max/iu,qr=/\bv\.any\s*\(/u,Br=/\bv\.string\s*\(/u,Vr=e=>qr.test(e),Ur=e=>Br.test(e)&&!Mr.test(e),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();Vr(a)?t.push(c):Ur(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},_r=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=k(s);if(r?.visibility!=="public")return;const{objects:n}=At(s,r.receiver),{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}},Gr=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=_r(n,t);o&&s.push(o)}return s},Hr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Gr(n,p(t,r)))}return s},N=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},he=e=>e?.getKind()===u.TrueKeyword,Qr=e=>e?.getKind()===u.FalseKeyword,Jr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Xr=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Zr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&S(t.getExpression())==="scim"),Yr=e=>e!==void 0&&i.isCallExpression(e)&&Xr.has(S(e.getExpression())??""),en=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),tn=e=>{const t=N(e,"advanced"),s=N(e,"emailAndPassword"),r=N(e,"session");return{analyzable:!0,disableCsrfCheck:he(N(t,"disableCSRFCheck")),emailPasswordEnabled:he(N(s,"enabled")),requireEmailVerification:he(N(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Zr(N(e,"plugins"))&&Yr(N(e,"database")),secureCookiesDisabled:Qr(N(t,"useSecureCookies")),sessionFreshAgeZero:Jr(N(r,"freshAge")),trustedOriginsWildcard:en(N(e,"trustedOrigins"))}},sn=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),rn=(e,t)=>{if(S(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],r=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(o=>i.isSpreadAssignment(o)),n=s!==void 0&&i.isObjectLiteralExpression(s)&&!r?tn(s):sn();return{exportName:h(e),file:t,line:e.getStartLineNumber(),...n}},nn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=rn(r,t);n&&s.push(n)}return s},on=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...nn(n,p(t,r)))}return s},an=(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},cn=(e,t,s)=>{const r=an(e.getExpression(),s);if(r===void 0)return;const n=e.getArguments()[s.argIndex];if(!(!n||!w(n)||O(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:r}},un=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const o=cn(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(...un(o,p(t,n),s))}return r},ln=new Set(["content","pdf","scrape","screenshot"]),dn=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:ln}),gn=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),pn=new Set(["RateLimiter"]),fn=new Set(["extend"]),St=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}},rt=e=>e&&i.isObjectLiteralExpression(e)?St(e):{analyzable:!1,presentKeys:[],trueKeys:[]},mn=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},xn=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)?mn(e):void 0},hn=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&xn(t.getBody());return s?St(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},En=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());n!==void 0&&(gn.has(n)?s.push({callee:n,file:t,line:r.getStartLineNumber(),...rt(r.getArguments()[0])}):fn.has(n)&&s.push({callee:n,file:t,line:r.getStartLineNumber(),...hn(r.getArguments()[0])}))}for(const r of e.getDescendantsOfKind(u.NewExpression)){const n=S(r.getExpression());n===void 0||!pn.has(n)||s.push({callee:n,file:t,line:r.getStartLineNumber(),...rt(r.getArguments()[0])})}return s},$n=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...En(n,p(t,r)))}return s},nt="ctx.containers.",yn=e=>{if(!e.startsWith(nt))return!1;const t=e.slice(nt.length);return t.length>0&&!t.includes(".")},An=(e,t)=>J(e,t,{argIndex:0,matchReceiver:yn,methods:new Set(["get"])}),Sn=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())},bn=(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()}},vn=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!Sn.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()}},Pn=(e,t)=>bn(e,t)??vn(e,t),wn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Pn(r,t);n&&s.push(n)}return s},In=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...wn(n,p(t,r)))}return s},Ln="env.ts",Tn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return Q(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},On=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&&Q(r.getModuleSpecifierValue())}return!1},Fn=e=>{if(i.isIdentifier(e))return Tn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&On(t)}return!1},Dn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!Fn(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw H(n,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},Cn=(e,t)=>{const s=g(t,Ln);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=Dn(r);if(n.length!==0){if(n.length>1)throw H(r,`lunora/env.ts declares ${n.length.toString()} defineEnv() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},kn=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Kn=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return kn.has(s)?s:void 0},Rn=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}},jn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){const c=Kn(a);if(c===void 0)continue;const l=a.getArguments()[0],f=l&&i.isObjectLiteralExpression(l)?Rn(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:f.analyzable,emptyKeys:f.emptyKeys,factory:c,file:o,line:a.getStartLineNumber(),presentKeys:f.presentKeys})}}return s},zn=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Mn=new Set(["dbRateLimit","rateLimit"]),qn=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},Bn=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},Vn=(e,t)=>{const s=S(e.getExpression());if(s===void 0)return;const r=zn.get(s);if(r!==void 0)return{callee:s,exportName:h(e),failOpen:qn(e.getArguments()[r]),file:t,limitName:Mn.has(s)?Bn(e):"",line:e.getStartLineNumber()}},Un=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Vn(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(...Un(n,p(t,r)))}return s},_n=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},Gn=(e,t)=>{const s=Object.fromEntries(xe.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=_n(n);for(const c of xe)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(xe.every(c=>s[c.key]))break}return s},Hn=["providerSubscriptionId","state"],Qn=["providerEventId","processedAt"],it=(e,t)=>t.every(s=>s in e.shape),Jn=e=>{const t=e.find(r=>r.name==="subscriptions"),s=e.find(r=>r.name==="events");return t!==void 0&&s!==void 0&&it(t,Hn)&&it(s,Qn)},Xn=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings/kv"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),Zn=e=>i.isIdentifier(e)&&e.getText()==="ctx",Yn=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Zn(t.getExpression())},ei=e=>{if(e?.getKind()===u.TrueKeyword)return!0;if(e?.getKind()===u.FalseKeyword)return!1},ti=(e,t)=>{if(!Yn(e.getExpression()))return;const[s,r]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const n=s.getLiteralValue(),o=ei(r);if(!(n.length===0||o===void 0))return{defaultValue:o,exportName:h(e),file:t,key:n,line:e.getStartLineNumber()}},si=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ti(r,t);n&&s.push(n)}return s},ri=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...si(n,p(t,r)))}return s},ni=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},ii=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},oi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression))ni(a)&&s.push({file:o,indexName:ii(a),line:a.getStartLineNumber()})}return s},ai=new Set(["delete","get","head","options","patch","post","put"]),ci=new Set(["handler","stream"]),ui=new Set(["runAction","runMutation"]),li=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),U=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,ot=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,at=(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}}},ct=(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(ui.has(a)&&U(c,t))return a;if(li.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&U(c.getExpression(),t))return`db.${a}`}},ut=(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},di=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ci.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(ai.has(n)){const o=r.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?n.toUpperCase():void 0}s=r.getExpression()}},gi=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=ot(e.getArguments()[0]),l=c&&at(c,!0);if(!c||l===void 0)return;const f=ct(c,l);return f===void 0?void 0:{exportName:h(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ut(c,l),sideEffect:f}}const r=di(e);if(r===void 0)return;const n=ot(e.getArguments()[0]),o=n&&at(n,!1);if(!n||o===void 0)return;const a=ct(n,o);return a===void 0?void 0:{exportName:h(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:r,readsAuth:ut(n,o),sideEffect:a}},pi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=gi(r,t);n&&s.push(n)}return s},fi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...pi(n,p(t,r)))}return s},mi=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),xi=new Set(["append","set"]),Ae=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",Nt=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",lt=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(u.CallExpression)]:e.getDescendantsOfKind(u.CallExpression)).some(s=>mi.has(Ae(s.getExpression()))&&os(s,t)),hi=(e,t)=>{if(lt(e,t))return!0;const s=G(e);return s!==void 0&<(s,t)},$e=(e,t)=>is(e,t)&&!hi(e,t),Ei=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=G(e);return t!==void 0&&i.isNewExpression(t)&&Ae(t.getExpression())==="Headers"},W=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=G(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},Se=(e,t,s)=>{for(const r of e.getProperties())if(i.isPropertyAssignment(r)){const n=r.getInitializer();n!==void 0&&$e(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:Nt(r.getNameNode()),line:n.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(r)){const n=r.getNameNode();$e(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&&Se(n,t,s)}},bt=(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&&Se(n,"response-init",t)},$i=(e,t)=>{const s=Ae(e.getExpression());if(s==="Response")bt(e.getArguments()[1],t);else if(s==="Headers"){const r=W(e.getArguments()[0]);r!==void 0&&Se(r,"headers-ctor",t)}},yi=(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"){bt(e.getArguments()[1],t);return}if(xi.has(r)&&Ei(n)){const o=e.getArguments()[1];o!==void 0&&$e(o,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:Nt(e.getArguments()[0]),line:o.getStartLineNumber(),via:r==="set"?"headers-set":"headers-append"})}},Ai=(e,t)=>{for(const s of e.getDescendantsOfKind(u.NewExpression))$i(s,t);for(const s of e.getDescendantsOfKind(u.CallExpression))yi(s,t)},Si=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const r=Yt(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 Ai(r,{exportName:h(e),relativePath:t,requestName:o.getText(),rows:a}),a},Ni=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...Si(r,t));return s},bi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ni(n,p(t,r)))}return s},vt="identity.ts",vi=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return Q(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Pi=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&&Q(r.getModuleSpecifierValue())}return!1},wi=e=>{if(i.isIdentifier(e))return vi(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&Pi(t)}return!1},Ii=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!wi(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw H(n,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},Li=(e,t)=>{const s=g(t,vt);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=Ii(r);if(n.length!==0){if(n.length>1)throw H(r,`lunora/identity.ts declares ${n.length.toString()} defineIdentity() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},Ti=new Set(["auth","context.auth","ctx.auth"]),Oi="userId",Fi=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},Di=(e,t)=>{const s=g(t,vt);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const n of r.getDescendantsOfKind(u.CallExpression)){if(S(n.getExpression())!=="defineIdentity")continue;const[o]=n.getArguments();return o&&i.isObjectLiteralExpression(o)?Fi(o):void 0}},dt=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Ti.has(e.getExpression().getText())?e:void 0},Ci=e=>{if(i.isPropertyAccessExpression(e)&&dt(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&dt(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},ki=(e,t,s)=>{const r=[];for(const n of e.getDescendants()){const o=Ci(n);o!==void 0&&r.push({declared:o===Oi||s.has(o),exportName:h(n),file:t,key:o,line:n.getStartLineNumber()})}return r},Ki=(e,t)=>{const s=Di(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(...ki(o,p(t,n),s))}return r},Ri=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},ji=(e,t)=>{if(S(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const r=Ri(s);if(!(!r||!w(r)||O(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},zi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ji(r,t);n&&s.push(n)}return s},Mi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...zi(n,p(t,r)))}return s},qi=new Set(["delete","get","getRaw","getWithMetadata","put"]),Bi=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:qi}),Vi=new Set(["queue","send"]),gt=new Set(["bcc","cc","to"]),Ui=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Vi.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 gt.has(t.getName())&&w(r)&&!O(r)}if(!i.isPropertyAssignment(t)||!gt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&w(s)&&!O(s)}):!1,_i=(e,t)=>{const s=Ui(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}},Gi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=_i(r,t);n&&s.push(n)}return s},Hi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Gi(n,p(t,r)))}return s},Qi=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"},Ji=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},Xi=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==u.CallExpression)return;const s=t;return ks(s.getExpression())?s:void 0},Zi=e=>{const t=Xi(e),s=t===void 0?void 0:Ji(t);if(s===void 0)return[];const r=e.getNameNode(),n=i.isIdentifier(r)?r.getText():"";return s.getDescendantsOfKind(u.CallExpression).filter(o=>Qi(o)).map(o=>({exportName:n,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},Yi=e=>e.getVariableDeclarations().flatMap(t=>Zi(t)),eo=(e,t)=>{const s=g(t,Cs);if(!E(s))return[];const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Yi(r)},to=new Set(["delete","get","patch"]),so=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),ro=new Set(["auth","identity","session","user"]),no=new Set([u.EqualsEqualsEqualsToken,u.EqualsEqualsToken,u.ExclamationEqualsEqualsToken,u.ExclamationEqualsToken]),io=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!C(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},oo=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},ao=(e,t)=>e.getDescendantsOfKind(u.Identifier).some(s=>s.getText()===t),co=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(u.ThrowStatement).length>0||e.getDescendantsOfKind(u.ReturnStatement).length>0,uo=(e,t)=>e.getDescendantsOfKind(u.IfStatement).some(s=>ao(s.getExpression(),t)&&co(s.getThenStatement())),lo=(e,t)=>{for(const s of e.getDescendantsOfKind(u.CallExpression)){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))continue;const n=r.getName();if(!to.has(n))continue;const o=r.getExpression();if(!(C(o)||i.isPropertyAccessExpression(o)&&C(o.getExpression())))continue;const a=s.getArguments()[0];if(a!==void 0&&i.isIdentifier(a)&&a.getText()===t)return n}},go=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},po=e=>e.getDescendantsOfKind(u.CallExpression).some(t=>t.getArguments().some(s=>go(s)==="ctx")),fo=e=>e.getDescendantsOfKind(u.BinaryExpression).some(t=>no.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),mo=e=>{for(const t of e.getDescendantsOfKind(u.Identifier))if(so.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&ro.has(t.getName()))return!0}return po(e)||fo(e)},xo=(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=ht(s);if(n===void 0)return[];const o=r.receiver!==void 0&&Et(r.receiver,"use","rls"),a=mo(n),c=new Set,l=[];for(const f of n.getDescendantsOfKind(u.CallExpression)){const $=io(f);if($===void 0)continue;const I=oo(f);if(I===void 0||c.has(I)||!uo(n,I))continue;const K=lo(n,I);K!==void 0&&(c.add(I),l.push({exportName:e.getName(),file:t,line:f.getStartLineNumber(),mentionsOwnership:a,sinkMethod:K,table:$,usesRls:o,visibility:r.visibility}))}return l},ho=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...xo(c,o))}return s},Eo=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),$o=new Set(["insert","insertManyUnsafe","patch","replace"]),yo=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!$o.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},Ao=(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},So=(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||!Eo.has(a))&&w(c)&&!O(c)&&n.push({exportName:h(s),field:a,file:r,line:s.getStartLineNumber(),method:t})}return n},No=(e,t)=>{const s=yo(e.getExpression());if(s===void 0)return[];const r=e.getArguments()[1];return r?Ao(r,s).flatMap(n=>So(n,s,e,t)):[]},bo=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression))for(const o of No(n,t)){const a=s(o.exportName);r.push(a===void 0?o:{...o,visibility:a})}return r},vo=(e,t,s=[])=>{const r=[],n=new Map(s.map(o=>[`${o.filePath}:${o.exportName}`,o.visibility]));for(const o of d(t)){const a=e.getSourceFile(o)??e.addSourceFileAtPath(o),c=p(t,o);r.push(...bo(a,c,l=>n.get(`${c}:${l}`)))}return r},Po=e=>{const t=g(e,"package.json");if(E(t))try{const s=JSON.parse(ye(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}},wo=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Io=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Lo=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?Io(t.getInitializer()):void 0},To=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());if(n===void 0||!wo.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},Oo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...To(n,p(t,r)))}return s},Fo=new Set(["defineQueue","defineWorkflow"]),Do=new Set(["run","runAction","runMutation","runQuery"]),Co=new Set(["api","internal"]),ko=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},Ko=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},Pt=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},wt=(e,t)=>e===t||e.startsWith(`${t}.`),It=e=>{const t=e.getDescendantsOfKind(u.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},pt=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)},Lt=e=>{const t=e.getDescendantsOfKind(u.Identifier).filter(s=>pt(s));return i.isIdentifier(e)&&pt(e)&&t.push(e),t},Ro=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(u.BindingElement).map(s=>s.getName())},jo=e=>{const t=Pt(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},zo=(e,t,s)=>{const r=t==="workflow"?[`${s}.params`]:jo(e),n=new Set,o=a=>It(a).some(c=>r.some(l=>wt(c.getText(),l)))?!0:Lt(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 Ro(a))n.add(l)}return{names:n,prefixes:r}},Mo=(e,t)=>It(e).some(s=>t.prefixes.some(r=>wt(s.getText(),r)))?!0:Lt(e).some(s=>t.names.has(s.getText())),qo=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)||!Co.has(s.getText())||t.length<2))return{exportName:r,file:t.slice(0,-1).join("/")}},Bo=(e,t,s)=>{const r=Pt(e,0);if(r===void 0)return[];const n=zo(e,t,r),o=[];for(const a of e.getDescendantsOfKind(u.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!Do.has(c.getName())||c.getExpression().getText()!==r)continue;const l=a.getArguments()[1];if(!l||!Mo(l,n))continue;const f=qo(a.getArguments()[0]);f!==void 0&&o.push({dispatchKind:t,file:s,handlerExport:h(a),line:a.getStartLineNumber(),targetExport:f.exportName,targetFile:f.file})}return o},Vo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ko(r);if(n===void 0||!Fo.has(n))continue;const o=Ko(r);o!==void 0&&s.push(...Bo(o,n==="defineQueue"?"queue":"workflow",t))}return s},Uo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Vo(n,p(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,_o=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Go=(e,t)=>{const{objects:s,opaque:r}=At(e,t);return zr(s).some(n=>_o(n))?!0:r?void 0:!1},Ne=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},Ho=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Qo=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},Jo=e=>{const t=Qo(e),s=t?Ne(t):void 0;if(t&&s==="protectPublic"){const r=Ho(t);return{...V,usesCaptcha:r.usesCaptcha,usesRateLimit:r.usesRateLimit}}return s!==void 0&&s in ft?{...V,[ft[s]]:!0}:V},Xo=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=Jo(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},Zo=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()))},Yo=new Set(["create","runAfter","runAt","send","sendBatch"]),ea=new Set(["queues","scheduler","workflows"]),ta=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Yo.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&ea.has(s.getName())){const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="ctx")return!0}s=s.getExpression()}return!1},sa=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"},Tt=new Set(["generateObject","generateText","streamObject","streamText"]),ra=e=>{const t=Ne(e);return t!==void 0&&Tt.has(t)},na=e=>{const t=Ne(e);if(t===void 0||!Tt.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")},ia=new Set(["log","span","trace"]),oa=new Set(["ai"]),aa=new Set(["email","mail"]),ca=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),B=(e,t)=>e.getDescendantsOfKind(u.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const r=s.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"}),ua=e=>e.getDescendantsOfKind(u.ThrowStatement).some(t=>{const s=t.getExpression();if(!i.isNewExpression(s))return!1;const r=s.getExpression();return i.isIdentifier(r)&&r.getText()==="Error"}),mt="lunora-advisor-exempt",la=/^[\s*/]+/u,da=/[\w-]/u,ga=e=>{const t=(e.getFirstAncestorByKind(u.VariableStatement)??e).getLeadingCommentRanges().map(s=>s.getText()).join(`
|
|
9
|
+
`);for(const s of t.split(`
|
|
10
|
+
`)){const r=s.replace(la,"");if(!r.startsWith(mt))continue;const n=r.slice(mt.length);if(da.test(n.charAt(0)))continue;const o=n.indexOf("--");return{exempt:!0,exemptReason:(o===-1?"":n.slice(o+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},pa=e=>{let t=!1,s=!1,r=!1,n=!1,o=!1;for(const a of e.getDescendantsOfKind(u.CallExpression))if(Zo(a)&&(o=!0),ta(a)&&(t=!0),sa(a)&&(n=!0),ra(a)&&(s=!0),na(a)&&(r=!0),o&&t&&n&&r)break;return{callsMail:B(e,aa),emitsEvent:B(e,ia),fanOut:t,handlesErrors:e.getDescendantsOfKind(u.TryStatement).length>0,reachesOutbound:B(e,ca),runsAiGeneration:s||B(e,oa),throwsBareError:ua(e),unboundedAiGeneration:r,usesInsertManyUnsafe:n,writesUserTable:o}},fa=(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?Xo(r.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1};return{...pa(e),...ga(e),...n,exportName:e.getName(),file:t,hasEmailArg:Go(s,r.receiver),kind:r.kind,visibility:r.visibility}},ma=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=fa(n,t);o&&s.push(o)}return s},xa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ma(n,p(t,r)))}return s},ha=new Set(["dbRateLimit","rateLimit"]),Ea=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},$a=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},ya=e=>i.isArrowFunction(e)?e.getBody():e,Aa=(e,t)=>{const s=S(e.getExpression());if(s===void 0||!ha.has(s))return;const r=e.getArguments()[2];if(!r)return;const n=Ea(r);if(!n)return;const o=ya(n);if(!(!w(o)||O(o)))return{callee:s,exportName:h(e),file:t,limitName:$a(e),line:e.getStartLineNumber()}},Sa=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Aa(r,t);n&&s.push(n)}return s},Na=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Sa(n,p(t,r)))}return s},ba=new Set(["findFirst","findFirstOrThrow","findMany","get"]),va=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ba.has(t.getName()))return;const s=t.getExpression();if(C(s)){const r=e.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&C(s.getExpression()))return s.getName()},Pa=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&C(s.getExpression())){const r=t.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}t=s.getExpression()}},wa=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},Ot=(e,t=!1)=>{const s=wa(e);if(i.isIdentifier(s)){if(t)return;const r=G(s);return r===void 0?void 0:Ot(r,!0)}if(i.isCallExpression(s))return va(s)??Pa(s)},Ia=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},La=(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=ht(s);if(n===void 0)return[];const o=r.receiver!==void 0&&es(r.receiver,"output"),a=r.receiver!==void 0&&Et(r.receiver,"use","mask"),c=new Set,l=[];for(const f of Ia(n)){const $=Ot(f);$===void 0||c.has($)||(c.add($),l.push({exportName:e.getName(),file:t,line:f.getStartLineNumber(),table:$,usesMask:a,usesOutput:o,visibility:r.visibility}))}return l},Ta=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...La(c,o))}return s},Oa=new Set(["findFirst","findFirstOrThrow","findMany"]),Fa=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Oa.has(t.getName()))return;const s=t.getExpression();if(i.isPropertyAccessExpression(s)&&s.getName()==="db"||i.isIdentifier(s)&&s.getText()==="db"){const r=e.getArguments()[0];return{options:e.getArguments()[1],table:r&&i.isStringLiteral(r)?r.getLiteralText():""}}if(i.isPropertyAccessExpression(s)){const r=s.getExpression();if(i.isPropertyAccessExpression(r)&&r.getName()==="db"||i.isIdentifier(r)&&r.getText()==="db")return{options:e.getArguments()[0],table:s.getName()}}},Da=e=>{if(!e||!i.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s)||i.isGetAccessorDeclaration(s))&&t.push(s.getName());return t},Ca=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},ka=(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=Fa(o);if(a===void 0)continue;const c=Da(Ca(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},Ka=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...ka(c,o))}return s},_=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===u.PlusToken){const t=_(e.getLeft()),s=_(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},Ra=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&&_(t)!==void 0},ja=/(?:^|\/)__tests__\//u,za=/\.(?:spec|test)$/u,Ma=e=>ja.test(e)||za.test(e),qa=e=>{const t=e.getParent();if(t!==void 0){if(i.isVariableDeclaration(t)||i.isPropertyAssignment(t)||i.isPropertySignature(t))return t.getName();if(i.isBinaryExpression(t)&&t.getOperatorToken().getKind()===u.EqualsToken)return t.getLeft().getText()}},Ba=(e,t,s)=>Hs(e)?!Ma(s)&&Qs(qa(t)):!0,Va=(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(Ra(o))continue;const a=_(o);if(a===void 0)continue;const c=_s(a);if(c===void 0||!Ba(c,o,t))continue;const l=o.getStartLineNumber(),f=`${String(l)}:${c}`;n.has(f)||(n.add(f),s.push({file:t,kind:c,line:l,preview:Gs(a)}))}return s},Ua=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Va(n,p(t,r)))}return s},Wa=new Set(["findFirst","findFirstOrThrow","findMany"]),_a=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Wa.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()}}},Ga=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},Ha=(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=_a(o);if(a===void 0)continue;const c=Ga(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),f=!l&&w(c);!l&&!f||n.push({exportName:e.getName(),file:t,fromArgs:f,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:r.visibility})}return n},Qa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Ha(c,o))}return s},Ja=new Set(["query","unsafe"]),Xa=e=>{if(!i.isPropertyAccessExpression(e)||!Ja.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"},Za=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),Ya=e=>e.getFirstAncestorByKind(u.VariableDeclaration)?.getName()??"<module>",ec=(e,t)=>{if(!Xa(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Za(s)))return{exportName:Ya(e),file:t,line:s.getStartLineNumber()}},tc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ec(r,t);n&&s.push(n)}return s},sc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...tc(n,p(t,r)))}return s},rc=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),nc=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.storage"||s.startsWith("ctx.storage."),methods:rc}),ic=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),oc=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,ac=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=oc(n.getInitializer()));continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,expiresInSeconds:s,presentKeys:t}},cc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=ic.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},uc=(e,t)=>{const s=cc(e.getExpression());if(s!==void 0)return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s.method,...ac(e.getArguments()[s.optionsIndex])}},lc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=uc(r,t);n&&s.push(n)}return s},dc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...lc(n,p(t,r)))}return s},gc=new Set(["RegisteredAction","RegisteredMutation","RegisteredQuery"]),be=e=>{const t=e.getType(),s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName();return s!==void 0&&gc.has(s)?s:void 0},Ft=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},Dt={cause:"codegen recognises a procedure only when the initializer is a builder chain, and this one is produced by a call or an alias",remediation:"A factory that returns a procedure cannot be read statically — inline it, or export the chain the factory builds."},pc={cause:"the binding is exported by a separate `export { … }` statement, and codegen reads the `export` keyword on the declaration itself",remediation:"Move the keyword onto the declaration and drop the separate export statement."},ve=(e,t,s,r,n)=>({cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally a builder chain. A procedure written any other way exists at runtime but never reaches `_generated/api.ts`, so no caller can address it.",detail:`\`${t}\` in \`${e}\` (line ${r.toString()}) has type \`${s}\` but was not registered — ${n.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:r,typeName:s},name:"procedure_not_registered",remediation:`Assign the builder chain directly: \`export const ${t} = query.input({ … }).query(handler);\`. ${n.remediation}`,title:"Procedure exists at runtime but is missing from the generated API"}),fc=(e,t,s)=>{const r=[];for(const n of e.getVariableStatements().filter(o=>o.isExported()))for(const o of n.getDeclarations()){const a=o.getName();if(s.has(`${t}:${a}`)||!Ft(o))continue;const c=be(o);c!==void 0&&r.push(ve(t,a,c,o.getStartLineNumber(),Dt))}return r},mc=(e,t,s)=>{if(s.has(`${t}:default`))return[];const r=[];for(const n of e.getExportAssignments().filter(o=>!o.isExportEquals())){const o=be(n.getExpression());o!==void 0&&r.push(ve(t,"default",o,n.getStartLineNumber(),Dt))}return r},xc=(e,t,s)=>{const r=[];for(const n of e.getExportDeclarations().filter(o=>o.getModuleSpecifier()===void 0))for(const o of n.getNamedExports()){const a=o.getAliasNode()?.getText()??o.getName();if(s.has(`${t}:${a}`))continue;const c=o.getLocalTargetDeclarations().find(f=>i.isVariableDeclaration(f));if(c===void 0||!Ft(c))continue;const l=be(c);l!==void 0&&r.push(ve(t,a,l,o.getStartLineNumber(),pc))}return r},hc=(e,t,s)=>[...fc(e,t,s),...mc(e,t,s),...xc(e,t,s)],Ec=(e,t,s)=>{const r=new Set(s.map(o=>`${o.filePath}:${o.exportName}`)),n=[];for(const o of d(t)){const a=e.getSourceFile(o);a!==void 0&&n.push(...hc(a,p(t,o),r))}return n.toSorted((o,a)=>o.cacheKey.localeCompare(a.cacheKey))},$c=new Set(["when","where"]),Ee=new Set(["definePolicy","defineShape"]),yc=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const r=t.getName();return Ee.has(r)?r:void 0}if(!i.isIdentifier(t))return;for(const r of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(r)){const n=r.getNameNode().getText();return Ee.has(n)?n:void 0}const s=t.getText();return Ee.has(s)?s:void 0},Ac=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,Ct=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===u.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Ac(e))return"empty-object";if(i.isParenthesizedExpression(e))return Ct(e.getExpression())}},kt=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Kt=e=>e.getDescendantsOfKind(u.ReturnStatement).filter(t=>kt(t)===e),Rt=e=>e.getDescendantsOfKind(u.ConditionalExpression).filter(t=>kt(t)===e),Sc=e=>{const t=Kt(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(u.IfStatement)!==void 0)||Rt(e).length>0},Nc=e=>{const t=[],s=e.getBody();i.isBlock(s)||t.push(s);for(const r of Kt(e)){const n=i.isReturnStatement(r)?r.getExpression():void 0;t.push(n??r)}for(const r of Rt(e))t.push(r.getWhenTrue(),r.getWhenFalse());return t},bc=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},vc=(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)||!$c.has(o.getName()))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Sc(a))for(const c of Nc(a)){const l=Ct(c);l!==void 0&&n.push({exportName:bc(e),file:s,form:l,key:o.getName(),line:c.getStartLineNumber(),owner:t})}}return n},Pc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=yc(r);n!==void 0&&s.push(...vc(r,n,t))}return s},wc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Pc(n,p(t,r)))}return s},Ic=new Set(["query","upsert","upsertMany"]),Lc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(Ic.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Tc=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("namespace");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Oc=(e,t)=>{const s=Lc(e.getExpression());if(s===void 0)return;const r=e.getArguments()[1];if(!r)return;const n=Tc(r);if(!(!n||!w(n)||O(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Fc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Oc(r,t);n&&s.push(n)}return s},Dc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Fc(n,p(t,r)))}return s},Cc=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"},kc=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Kc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=p(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){if(!Cc(a))continue;const c=Zs(a);c!==""&&s.push({exportName:c,file:o,line:a.getStartLineNumber(),workflow:kc(a)})}}return s},Rc=".lunora-schema.json",A=(e,t)=>{E(e)&&ye(e,"utf8")===t||Ht(e,t,"utf8")},P=(e,t)=>{if(t===""){Qt(e,{force:!0});return}A(e,t)},jc=e=>{const t=g(e,"package.json");if(E(t))try{const s=JSON.parse(ye(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},zc=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Mc=e=>{let t=E(e)?e:fe(e);for(;t&&t!==fe(t);){const s=g(t,"tsconfig.json");if(E(s))return s;t=fe(t)}},xt=e=>e.replaceAll("\\","/"),qc=(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 R("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 R("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 R("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})}},Bc=e=>{const t=Mc(e);return t?new tt({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new tt({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Tu=(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=>xt(c))),o=xt(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!n.has(l)&&e.removeSourceFile(c)}},Ou=e=>{const t=zc(),s=t?me.now():0,r=g(e.projectRoot,e.lunoraDirectory??"lunora"),n=g(r,"schema.ts");if(!E(n))throw new R("INTERNAL",`schema.ts not found at ${n}`);const o=e.project??Bc(r);ir(ss);const a=Ws(o,n,e.projectRoot),c=ts(o,r),l=Is(o,r),f=Ds(o,r),$=Js(o,r),I=Ks(o,r),K=Li(o,r),Pe=Cn(o,r),b=Ys(o,r),F=Ms(o,r),v=rs(o,r);qc(b,v);const X=ls(o,r,b,v),D=us(o,r),j=e.lint===!1?void 0:Zt({adminRoutes:Er(o,r),aiRawRuns:Sr(o,r),aiToolSideEffects:Fr(o,r),argumentDerivedFetches:Kr(o,r),argumentValidators:Hr(o,r),authApiCalls:cs(o,r),authConfigs:on(o,r),browserUrlAccesses:dn(o,r),configCalls:$n(o,r),containerKeyAccesses:An(o,r),containerOverrides:In(o,r),containers:D,exportSinks:jn(o,r),failOpenGuards:Wn(o,r),flagSecurityDefaults:ri(o,r),geoIndexUsages:oi(o,r),httpActionGuards:fi(o,r),httpHeaderWrites:bi(o,r),identityClaimReads:Ki(o,r),imageDeliveryUrlAccesses:Mi(o,r),inserts:Ls(o,r),kvKeyAccesses:Bi(o,r),mailRecipientAccesses:Hi(o,r),maskProcedures:Ts(o,r),maskStrategies:Os(o,r),mutatorWrites:eo(o,r),nondeterministicCalls:Rs(o,r),normalizeIdAuthorizations:ho(o,r),notifyCalls:zs(o,r),notifyConfig:js(o,r),ownerFieldWrites:vo(o,r,c),unrestrictedWhereBranches:wc(o,r),paymentWebhooks:Oo(o,r),privilegedDispatches:Uo(o,r),procedureProtections:xa(o,r),queries:as(o,r),queues:F,r2sqlCalls:qs(o,r),ratelimitKeySelectors:Na(o,r),rawRowReturns:Ta(o,r),relationLoads:Ka(o,r),rlsProcedures:Bs(o,r),schema:a,secretLiterals:Ua(o,r),shapes:$,softDeleteReads:Qa(o,r),sqlInterpolations:sc(o,r),storageKeyAccesses:nc(o,r),storageUploads:dc(o,r),vectorNamespaceAccesses:Dc(o,r),workflowCalls:Kc(o,r),workflows:b,wranglerVariables:e.wranglerVariables}),we=j===void 0?[]:[...Jt(j,{source:"static"}),...Ec(o,r,c)],jt=Vs(o,r),zt=Fs(o,r),Z=Xs(o,r),Mt=Gn(o,r),Ie=or(Mt,ar(e.projectRoot,e.target)),y=Ie.usage,Y=y.ai,ee=y.payments,Le=y.kv,Te=y.access,te=E(g(r,"flags.ts")),qt=te?ws(o,r):[],se=E(g(r,"notify.ts")),re=y.hyperdrive,ne=Us(o,r),Bt=ne.usesSandboxBrowser||ne.usesSandboxContainer,ie=y.browser||ne.usesSandboxBrowser,oe=y.images,ae=y.analytics,Oe=y.pipelines,ce=y.r2sql,ue=y.x402,Fe=Po(e.projectRoot),L=Fe??new Set,z=Xn(y,{containerCount:D.length,cronCount:X.length,dependencies:L,hasPaymentTables:Jn(a.tables),queueCount:F.length,storageColumnCount:Object.keys(ds(a)).length,storageRuleCount:Z.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:b.length}),T=L.has("lunorash");lr(a,Fe);const De=t?me.now():0,Ce=gs(a,T),ke=ps({agents:v,functions:c,httpRoutes:l,mutators:I,useUmbrella:T,workflows:b}),Ke=fs({agents:v,containers:D,env:Pe,hasAccessFacade:Te,hasAi:Y,hasAnalytics:ae,hasBrowser:ie,hasFlags:te,hasHyperdrive:re,hasImages:oe,hasKv:Le,hasNotify:se,hasPayments:ee,hasPipelines:Oe,hasR2sql:ce,hasX402:ue,identity:K,queues:F,schema:a,storageRuleBuckets:Z.rules.map(m=>m.bucket),useUmbrella:T,workflows:b}),Re=ms({agents:v,functions:c,migrations:f,mutators:I,shapes:$,useUmbrella:T,usesSandbox:Bt}),le=cr(a,f.map(m=>m.id)),je=xs({advisories:we,advisorProcedures:j?.procedureProtections??[],agents:v,containers:D,env:Pe,flagKeys:qt,hasAccessFacade:Te,hasAi:Y,hasAnalytics:ae,hasBrowser:ie,hasFlags:te,hasHyperdrive:re,hasImages:oe,hasKv:Le,hasNotify:se,hasPayments:ee,hasPipelines:Oe,hasR2sql:ce,hasX402:ue,maskMetadata:zt,mutators:I,queues:F,rlsMetadata:jt,schema:a,schemaSnapshot:le,shapes:$,storageRules:Z,studioFeatures:z,useUmbrella:T,workflows:b}),ze=hs($,L.has("@lunora/db"),T),Me=Es(D,a.jurisdiction),qe=$s(b),Be=ys(v),Ve=As(F),Ue=Ss(X),We=Ns(a.vectorIndexes),M=bs(a,T),_e=vs(L.has("@lunora/seed")),q=e.apiSpec??"openapi",de=q==="openapi"||q==="both",ge=q==="openrpc"||q==="both",Ge=er({emailAgents:v.filter(m=>m.onEmail===!0).map(m=>({bindingName:m.bindingName,exportName:m.exportName})),hasAccess:L.has("@lunora/cloudflare-access"),hasAi:Y,hasAnalytics:ae,hasAuth:L.has("@lunora/auth"),hasBrowser:ie,hasFramework:L.has("@lunora/astro")||L.has("@lunora/svelte")||L.has("@lunora/vue"),hasGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend!=="hyperdrive"),hasHyperdrive:re,hasHyperdriveGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend==="hyperdrive"),hasImages:oe,hasKv:z.kv,hasNotify:se,hasPayments:ee,hasR2sql:ce,hasQueue:F.some(m=>m.mode==="push"),hasScheduler:z.scheduler,hasStorage:z.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:b.length>0,hasX402:ue,identity:K,jurisdiction:a.jurisdiction,useUmbrella:T,voiceAgents:v.filter(m=>m.voice===!0&&m.voiceBindingName!==void 0).map(m=>({bindingName:m.voiceBindingName,exportName:m.exportName})),wantsOpenApi:de,wantsOpenRpc:ge}),He=jc(e.projectRoot),Qe=tr({functions:c,httpRoutes:l,version:He}),Je=rr({functions:c,version:He}),Xe=`${JSON.stringify(Qe,void 0,2)}
|
|
11
|
+
`,Ze=`${JSON.stringify(Je,void 0,2)}
|
|
12
|
+
`,Ye=sr(Qe),et=nr(Je),pe=g(r,Rc),Vt=E(pe),x=g(r,"_generated");if(e.dryRun||(E(x)||Gt(x,{recursive:!0}),A(g(x,"app.ts"),Ge),A(g(x,"dataModel.ts"),Ce),A(g(x,"api.ts"),ke),A(g(x,"server.ts"),Ke),A(g(x,"functions.ts"),Re),A(g(x,"shard.ts"),je),A(g(x,"crons.ts"),Ue),A(g(x,"vectors.ts"),We),A(g(x,"drizzle.global.ts"),M.global),A(g(x,"drizzle.shard.ts"),M.shard),P(g(x,"containers.ts"),Me),P(g(x,"workflows.ts"),qe),P(g(x,"agents.ts"),Be),P(g(x,"queues.ts"),Ve),P(g(x,"seed.ts"),_e),P(g(x,"collections.ts"),ze),P(g(x,"openapi.json"),de?Xe:""),P(g(x,"openapi.ts"),de?Ye:""),P(g(x,"openrpc.json"),ge?Ze:""),P(g(x,"openrpc.ts"),ge?et:""),(!Vt||e.updateSchemaBaseline===!0)&&A(pe,Xt(le))),t){const m=me.now(),Ut=Math.round(m-s),Wt=Math.round(De-s),_t=Math.round(m-De);console.error(`@lunora/codegen: codegen took ${Ut.toString()}ms (discovery ${Wt.toString()}ms, emit ${_t.toString()}ms)`)}return{advisories:we,advisorContext:j,agents:v,containers:D,cronTriggers:Ps(X),generated:{agents:Be,api:ke,app:Ge,collections:ze,containers:Me,crons:Ue,dataModel:Ce,drizzleGlobal:M.global,drizzleShard:M.shard,functions:Re,openApi:Xe,openApiModule:Ye,openRpc:Ze,openRpcModule:et,queues:Ve,seed:_e,server:Ke,shard:je,vectors:We,workflows:qe},outputDirectory:x,platformDiagnostics:Ie.diagnostics,queues:F,schemaSnapshot:le,schemaSnapshotPath:pe,workflows:b}};export{Rc as SCHEMA_SNAPSHOT_FILENAME,Bc as createCodegenProject,Tu as refreshCodegenProject,Ou as runCodegen};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const f=1;function v(e){const a={},t=Object.keys(e);t.sort();for(const s of t)a[s]=e[s];return a}const d=e=>`${JSON.stringify(e,void 0,2)}
|
|
2
|
+
`,g=e=>{const a=d(e),t=s=>{let i=s;for(let o=0;o<a.length;o+=1)i^=a.codePointAt(o)??0,i=Math.imul(i,16777619)>>>0;return i.toString(16).padStart(8,"0")};return`${t(2166136261)}${t(16777619)}`},r=e=>typeof e=="object"&&e!==null,l=e=>r(e)&&r(e.fields)&&r(e.indexes)&&r(e.relations)&&typeof e.shardMode=="string",$=e=>{if(e===void 0||e.trim()==="")return{status:"absent"};let a;try{a=JSON.parse(e)}catch(t){return{error:`baseline is not valid JSON: ${t instanceof Error?t.message:String(t)}`,status:"invalid"}}if(!r(a)||a.version!==1||!r(a.tables))return{error:`baseline is malformed or written by an incompatible version (expected version ${String(1)})`,status:"invalid"};for(const[t,s]of Object.entries(a.tables))if(!l(s))return{error:`baseline table "${t}" has an invalid structure`,status:"invalid"};return{snapshot:{jurisdiction:typeof a.jurisdiction=="string"?a.jurisdiction:void 0,migrationIds:Array.isArray(a.migrationIds)?a.migrationIds:[],tables:a.tables,version:1},status:"ok"}},c=(e,a)=>e.unique===a.unique&&e.fields.length===a.fields.length&&e.fields.every((t,s)=>t===a.fields[s]),u=(e,a,t,s)=>{const i=[];return t.kind!==s.kind&&i.push({severity:"breaking",summary:`field ${e}.${a} changed type: ${t.kind} → ${s.kind} — add a data migration to convert existing values`,table:e,scope:"table",type:"changedFieldKind"}),t.optional&&!s.optional?i.push({severity:"breaking",summary:`field ${e}.${a} became required — rows missing it would be invalid; add a data migration to backfill it`,table:e,scope:"table",type:"fieldOptionalToRequired"}):!t.optional&&s.optional&&i.push({scope:"table",severity:"safe",summary:`field ${e}.${a} became optional`,table:e,type:"fieldRequiredToOptional"}),i},p=(e,a,t)=>t.optional?{scope:"table",severity:"safe",summary:`added optional field ${e}.${a}`,table:e,type:"addedOptionalField"}:{severity:"breaking",summary:`added required field ${e}.${a} — existing rows have no value; add a data migration to backfill it`,table:e,scope:"table",type:"addedRequiredField"},b=(e,a,t,s)=>{for(const[i,o]of Object.entries(t.fields)){const n=a.fields[i];n===void 0?s.push(p(e,i,o)):s.push(...u(e,i,n,o))}for(const i of Object.keys(a.fields))t.fields[i]===void 0&&s.push({severity:"breaking",summary:`removed field ${e}.${i} — add a data migration if stored data must be cleaned up`,table:e,scope:"table",type:"removedField"})},m=(e,a,t,s)=>{for(const[i,o]of Object.entries(t.indexes)){const n=a.indexes[i];if(n===void 0){s.push({scope:"table",severity:"safe",summary:`added index ${i} on ${e}`,table:e,type:"addedIndex"});continue}c(n,o)||s.push({severity:"breaking",summary:`index ${i} on ${e} changed shape — a query may have relied on the old index`,table:e,scope:"table",type:"changedIndex"})}for(const i of Object.keys(a.indexes))t.indexes[i]===void 0&&s.push({severity:"breaking",summary:`removed index ${i} on ${e} — a query that used \`.withIndex("${i}")\` would break`,table:e,scope:"table",type:"removedIndex"})},h=(e,a,t,s)=>{for(const i of Object.keys(t.relations))a.relations[i]===void 0&&s.push({scope:"schema",severity:"safe",summary:`added relation ${e}.${i}`,table:e,type:"addedRelation"});for(const i of Object.keys(a.relations))t.relations[i]===void 0&&s.push({scope:"schema",severity:"breaking",summary:`removed relation ${e}.${i}`,table:e,type:"removedRelation"})},y=(e,a,t,s)=>{a.shardMode!==t.shardMode&&s.push({severity:"breaking",summary:`table ${e} changed shard mode: ${a.shardMode} → ${t.shardMode} — its physical storage moves; add a data migration / re-shard plan`,table:e,scope:"table",type:"changedShardMode"}),b(e,a,t,s),m(e,a,t,s),h(e,a,t,s)},k=(e,a)=>{const t=[],s=e?.tables??{};for(const[i,o]of Object.entries(a.tables)){const n=s[i];if(n===void 0){t.push({scope:"table",severity:"safe",summary:`added table ${i}`,table:i,type:"addedTable"});continue}y(i,n,o,t)}for(const i of Object.keys(s))a.tables[i]===void 0&&t.push({scope:"table",severity:"breaking",summary:`removed table ${i} — add a data migration if its data must be archived/cleaned up`,table:i,type:"removedTable"});if(e!==void 0&&e.jurisdiction!==a.jurisdiction){const i=e.jurisdiction??"(none)",o=a.jurisdiction??"(none)";t.push({scope:"schema",severity:"breaking",summary:`Durable Object jurisdiction changed from ${i} 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:t}};export{f as SCHEMA_SNAPSHOT_VERSION,k as diffSchemaSnapshots,g as hashSchemaSnapshot,l as isValidTableSnapshot,$ as parseSnapshotJson,d as serializeSchemaSnapshot,v as sortKeys};
|
|
@@ -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{c as u}from"./parse-validator-_jDrFxwt.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,14 @@
|
|
|
1
|
+
import{LunoraError as h}from"@lunora/errors";import{SCHEMA_SNAPSHOT_VERSION as f,sortKeys as g,diffSchemaSnapshots as m,parseSnapshotJson as u}from"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{serializeSchemaSnapshot as x}from"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";const p=a=>a==="global"||a==="root"?a:`shardBy:${a.field}`,b=a=>a.kind==="optional"?{kind:a.inner?.kind??"unknown",optional:!0}:{kind:a.kind,optional:!1},S=a=>{const s={};for(const[e,r]of Object.entries(a.shape))s[e]=b(r);const n={};for(const e of a.indexes)n[e.name]={fields:[...e.fields],unique:e.unique??!1};const o={};for(const e of a.relations)o[e.name]={field:e.field,kind:e.kind,table:e.table};return{fields:s,indexes:n,relations:o,shardMode:p(a.shardMode)}},M=(a,s)=>{const n={};for(const e of a.tables)n[e.name]=S(e);const o=[...s].sort();return{jurisdiction:a.jurisdiction,migrationIds:o,tables:g(n),version:f}};class k extends h{constructor(s){super("SCHEMA_SNAPSHOT_PARSE",s,{name:"SchemaSnapshotParseError"})}}const y=a=>{const s=u(a);if(s.status==="invalid")throw new k(s.error);return s.status==="ok"?s.snapshot:void 0},$=a=>{const{allowDrift:s=!1,baseline:n,current:o}=a,e=m(n,o),r=e.changes.filter(i=>i.severity==="breaking"),t=o.migrationIds.filter(i=>!(n?.migrationIds??[]).includes(i));if(e.changes.length===0||n===void 0)return{blocked:!1,changes:e.changes,newMigrationIds:t,reason:""};if(r.length===0){const i=e.changes.map(l=>` - ${l.summary}`).join(`
|
|
2
|
+
`);return{blocked:!1,changes:e.changes,newMigrationIds:t,reason:`schema drift detected (all additive/safe):
|
|
3
|
+
${i}`}}const c=r.map(i=>` - ${i.summary}`).join(`
|
|
4
|
+
`);if(t.length>0)return{blocked:!1,changes:e.changes,newMigrationIds:t,reason:`breaking schema drift detected, but ${String(t.length)} new migration(s) were added (${t.join(", ")}):
|
|
5
|
+
${c}`};const d=`deploy blocked: ${String(r.length)} breaking schema change(s) detected since the last blessed schema baseline — these changes are incompatible with existing data without a migration:
|
|
6
|
+
${c}
|
|
7
|
+
|
|
8
|
+
To fix:
|
|
9
|
+
• 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.
|
|
10
|
+
• For backward-compatible changes (e.g. adding an optional field): pass \`--allow-schema-drift\` to skip the block.
|
|
11
|
+
• To accept the new shape without a migration (you know data is compatible): pass \`--update-schema-baseline\`.
|
|
12
|
+
Docs: https://lunora.dev/docs/migrations`;return s?{blocked:!1,changes:e.changes,newMigrationIds:t,reason:`${d}
|
|
13
|
+
|
|
14
|
+
(overridden by --allow-schema-drift)`}:{blocked:!0,changes:e.changes,newMigrationIds:t,reason:d}};export{f as SCHEMA_SNAPSHOT_VERSION,k as SchemaSnapshotParseError,M as buildSchemaSnapshot,m as diffSchemaSnapshots,$ as evaluateSchemaDrift,y as parseSchemaSnapshot,x as serializeSchemaSnapshot};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync as p}from"node:fs";import{join as m}from"node:path";import{LunoraError as l}from"@lunora/errors";import{workflowDefaultName as g,workflowClassName as u,workflowBindingName as d}from"@lunora/workflow";import{Node as o,VariableDeclarationKind as w,SyntaxKind as x}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-DPezpZTz.mjs";const N="workflows.ts",b=new Set(["do","sleep","sleepUntil","waitForEvent"]),h=r=>{const e=r.getSymbol();if(!e)return r.getText()==="defineWorkflow";for(const t of e.getDeclarations())if(o.isImportSpecifier(t))return t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/workflow"?!1:t.getNameNode().getText()==="defineWorkflow";return!1},E=(r,e,t)=>{if(o.isStringLiteral(r)||o.isNoSubstitutionTemplateLiteral(r))return r.getLiteralValue();throw a(r,`workflow "${e}": \`${t}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)},k=r=>{const e=r.getExpression();if(!o.isPropertyAccessExpression(e)||!b.has(e.getName()))return!1;const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="step"?!0:o.isIdentifier(t)&&t.getText()==="step"},y=r=>{const e=r.getProperty("handler");if(!e)return[];const t=o.isPropertyAssignment(e)?e.getInitializer():e;if(!t)return[];const i=[];for(const n of t.getDescendantsOfKind(x.CallExpression)){if(!k(n))continue;const s=n.getArguments()[0];!s||!(o.isStringLiteral(s)||o.isNoSubstitutionTemplateLiteral(s))||i.push({line:n.getStartLineNumber(),method:n.getExpression().getName(),name:s.getLiteralValue()})}return i},c=r=>{let e=r;for(;e&&(o.isAsExpression(e)||o.isSatisfiesExpression(e)||o.isParenthesizedExpression(e));)e=e.getExpression();return e},S=r=>{const e=c(r);if(e&&o.isObjectLiteralExpression(e))return e;if(!(!e||!o.isIdentifier(e)))for(const t of e.getSymbol()?.getDeclarations()??[]){const i=o.isVariableDeclaration(t)&&t.getVariableStatement()?.getDeclarationKind()===w.Const?c(t.getInitializer()):void 0;if(i&&o.isObjectLiteralExpression(i))return i}},L=(r,e)=>{const t=S(r.getArguments()[0]);if(!t)throw a(r,`workflow "${e}": defineWorkflow's argument must be an object literal, or a local \`const\` holding one — codegen reads \`name\` and the \`ctx.step.*\` calls out of it statically. Keep the handler wherever you like and pass it through: \`const config = { handler: myHandler }; export const ${e} = defineWorkflow(config);\`.`);const i={bindingName:d(e),className:u(e),exportName:e,name:g(e),steps:y(t)},n=t.getProperty("name");return n&&o.isPropertyAssignment(n)&&(i.name=E(n.getInitializerOrThrow(),e,"name")),i},I=r=>{let e=r;for(;e&&(o.isAsExpression(e)||o.isSatisfiesExpression(e)||o.isParenthesizedExpression(e));)e=e.getExpression();return e&&o.isCallExpression(e)?e:void 0},A=r=>{const e=[];for(const t of r.getVariableDeclarations()){if(!t.isExported())continue;const i=I(t.getInitializer());if(!i)continue;const n=i.getExpression();if(!o.isIdentifier(n)||!h(n))continue;const s=t.getNameNode();if(!o.isIdentifier(s))throw a(s,"defineWorkflow exports must be plain named exports (no destructuring)");e.push(L(i,s.getText()))}return e},D=r=>{const e=new Map,t=new Map;for(const i of r){const n=e.get(i.name);if(n!==void 0)throw new l("DUPLICATE_WORKFLOW_NAME",`Duplicate workflow name "${i.name}": produced by both "${n}" and "${i.exportName}". Deployed workflow names must be unique across the project.`,{status:500});e.set(i.name,i.exportName);const s=t.get(i.bindingName);if(s!==void 0)throw new l("DUPLICATE_WORKFLOW_BINDING",`Duplicate workflow binding "${i.bindingName}": produced by both "${s}" and "${i.exportName}". Workflow export names must yield unique binding names.`,{status:500});t.set(i.bindingName,i.exportName)}},v=(r,e)=>{const t=m(e,N);if(!p(t))return[];const i=r.getSourceFile(t)??r.addSourceFileAtPath(t),n=A(i);return n.sort((s,f)=>s.exportName.localeCompare(f.exportName)),D(n),n};export{N as WORKFLOWS_FILENAME,v as discoverWorkflows};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{R as v}from"./emit-CCw5fiXq.mjs";import{n as c}from"./paths-BmX5O1sG.mjs";import{LUNORA_ERROR_CODES as S,objectSchema as b,argsObjectSchema as g,validatorIrToJsonSchema as u}from"./LUNORA_ERROR_CODES-Um9hC1gr.mjs";const O="/_lunora/rest",x=["authorization","cf-access-jwt-assertion","cookie"],h=["x-d1-bookmark","x-lunora-shard-key"],P=e=>[...x,...(e.credentialHeaders??[]).map(t=>t.toLowerCase())],m=e=>Number.isFinite(e)?Math.max(0,Math.floor(e)):0,f=(...e)=>{const t=[];for(const r of e)for(const o of r?.split(",")??[]){const n=o.trim().toLowerCase();n!==""&&!t.includes(n)&&t.push(n)}return t.length===0?void 0:t.join(", ")},T=(e,t)=>{const r=[t,`max-age=${String(m(e.maxAge))}`];return e.staleWhileRevalidate!==void 0&&r.push(`stale-while-revalidate=${String(m(e.staleWhileRevalidate))}`),r.join(", ")},k=e=>e.scope==="public"?f(e.vary,...P(e),...h):f(e.vary,...h),R=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)}},j=e=>{const t=R(e);if(t!==void 0)return`${O}/${t.namespace}/${t.name}`},q=e=>e==="query"?"GET":"POST",l="#/components/responses/LunoraError",y=/:([A-Za-z_$][\w$]*)/gu,A=e=>[...e.matchAll(y)].map(t=>t[1]),N=e=>e.replaceAll(y,"{$1}"),w=e=>{const t=new Set(A(e.path)),r=[];for(const[o,n]of Object.entries(e.searchParams)){const p=n.kind==="optional"?n.inner??n:n;r.push({description:`Query parameter \`${o}\``,in:"query",name:o,required:n.kind!=="optional",schema:u(p)})}for(const[o,n]of Object.entries(e.params)){const p=n.kind==="optional"?n.inner??n:n;r.push({description:`Path parameter \`${o}\``,in:t.has(o)?"path":"query",name:o,required:t.has(o)?!0:n.kind!=="optional",schema:u(p)})}return r},C=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."},E=e=>{const t=c(e.filePath),r=w(e),o={description:`${e.stream?"Streaming (SSE) ":""}HTTP route handler \`${e.exportName}\` (${e.method} ${e.path}).`,operationId:`${e.method.toLowerCase()}_${c(e.path)}`,responses:{200:C(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:l}},summary:`${e.method} ${e.path}`,tags:[t]};return r.length>0&&(o.parameters=r),Object.keys(e.body).length>0&&(o.requestBody={content:{"application/json":{schema:b(e.body)}},required:!0}),e.stream&&(o["x-lunora-stream"]="text/event-stream"),o},L=e=>{const t=`${c(e.filePath)}:${e.exportName}`,r=c(e.filePath),o={additionalProperties:!1,properties:{args:g(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:[r],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${t}`}},_=(e,t)=>{if(e===void 0||t!=="get"||e.scope===void 0||e.maxAge===void 0)return{};const r={maxAge:e.maxAge,scope:e.scope,...e.staleWhileRevalidate===void 0?{}:{staleWhileRevalidate:e.staleWhileRevalidate},...e.tag===void 0?{}:{tag:e.tag},...e.vary===void 0?{}:{vary:e.vary}},o={"Cache-Control":{description:r.scope==="public"?"Caching policy. `public` applies only to an uncredentialed request — a request carrying `Authorization` or `Cookie` is always answered `private`.":"Caching policy. Restricted to the caller's own cache; never stored by a shared/edge cache.",schema:{example:T(r,r.scope),type:"string"}}};r.tag!==void 0&&(o["Cache-Tag"]={description:"Purge tag for `ctx.cache.purge({ tags: [...] })`.",schema:{example:r.tag,type:"string"}});const n=k(r);return n!==void 0&&(o.Vary={description:"Request headers this response varies by. The endpoint's own negotiated headers are merged in at runtime.",schema:{example:n,type:"string"}}),{headers:o}},I=e=>{const t=`${c(e.filePath)}:${e.exportName}`,r=j(t);if(r===void 0)return;const o=c(e.filePath),n=q(e.kind),p=n==="GET",a={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_${c(r)}`,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).",..._(e.expose?.cache,p?"get":"post")},default:{$ref:l}},summary:`${n} ${r}`,tags:[o],"x-lunora-function-kind":e.kind};if(p){const s=Object.entries(e.args).map(([i,d])=>{const $=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($)}});return s.length>0&&(a.parameters=s),{method:"get",operation:a,path:r}}return a.requestBody={content:{"application/json":{schema:g(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:a,path:r}},D=e=>{const t=e.version??"0.0.0",r={},o=new Set;for(const a of e.httpRoutes){const s=N(a.path),i=r[s]??{};i[a.method.toLowerCase()]=E(a),r[s]=i,o.add(c(a.filePath))}const n=e.functions.filter(a=>a.visibility!=="internal"&&a.kind!=="stream");for(const a of n){const{operation:s,pathKey:i}=L(a);r[i]={post:s},o.add(c(a.filePath))}for(const a of n){if(a.expose?.rest!==!0)continue;const s=I(a);if(s===void 0)continue;const i=r[s.path]??{};i[s.method]=s.operation,r[s.path]=i,o.add(c(a.filePath))}const p=[...o].toSorted((a,s)=>a.localeCompare(s)).map(a=>({description:`Operations declared in \`lunora/${a}\`.`,name:a}));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:S,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:r,tags:p}},U=e=>`${JSON.stringify(D(e),void 0,2)}
|
|
2
|
+
`,W=e=>`${v}export const openApiSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
|
|
3
|
+
`;export{D as buildOpenApiDocument,U as emitOpenApi,W 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{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as E,lunoraRelativePath as P}from"./discoverFunctions-CVYkUBTm.mjs";const p=e=>{if(e.getText()!=="args")return!1;const t=e.getParent();return s.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(s.isPropertyAssignment(t)&&t.getNameNode()===e)},m=e=>{if(e.getText()!=="ctx")return!1;const t=e.getParent();return s.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(s.isPropertyAssignment(t)&&t.getNameNode()===e)},d=e=>s.isIdentifier(e)?m(e):e.getDescendantsOfKind(a.Identifier).some(t=>m(t)),x=(e,t)=>{if(e.getText()!==t)return!1;const r=e.getParent();return s.isPropertyAccessExpression(r)&&r.getNameNode()===e?!1:!(s.isPropertyAssignment(r)&&r.getNameNode()===e)},A=e=>{let t=e;for(;s.isPropertyAccessExpression(t)||s.isElementAccessExpression(t)||s.isNonNullExpression(t);)t=t.getExpression();return s.isIdentifier(t)?t:void 0},T=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e))return e.getName()},N=e=>s.isIdentifier(e)?p(e):e.getDescendantsOfKind(a.Identifier).some(t=>p(t)),u=e=>{if(!s.isIdentifier(e))return;const t=e.getText(),r=e.getFirstAncestor(o=>s.isArrowFunction(o)||s.isFunctionExpression(o)||s.isFunctionDeclaration(o));if(r===void 0)return;const n=e.getStart();let i,g=-1;for(const o of r.getDescendantsOfKind(a.VariableDeclaration)){if(o.getName()!==t)continue;const c=o.getInitializer(),f=o.getStart();c!==void 0&&f<n&&f>g&&(i=c,g=f)}return i},w=e=>{if(N(e))return!0;const t=u(e);return t!==void 0&&N(t)},O=e=>{if(d(e))return!0;const t=u(e);if(t!==void 0&&d(t))return!0;const r=t??e;return(s.isIdentifier(r)?[r]:r.getDescendantsOfKind(a.Identifier)).some(n=>{const i=u(n);return i!==void 0&&d(i)})},l=(e,t)=>s.isIdentifier(e)?x(e,t):e.getDescendantsOfKind(a.Identifier).some(r=>x(r,t)),C=(e,t)=>{if(l(e,t))return!0;const r=u(e);if(r!==void 0&&l(r,t))return!0;const n=A(e);if(n!==void 0){const i=u(n);return i!==void 0&&l(i,t)}return!1},y=e=>{for(const t of e.getAncestors())if(s.isVariableDeclaration(t)&&t.getVariableStatement()?.hasExportKeyword()===!0)return t.getName();return"<module>"},I=new Set(["withIndex","withSearchIndex"]),S=e=>{const t=e.getExpression();if(!s.isPropertyAccessExpression(t)||t.getName()!=="query")return!1;const r=t.getExpression();return s.isPropertyAccessExpression(r)?r.getName()==="db":s.isIdentifier(r)&&r.getText()==="db"},h=e=>{const t=[];let r=e;for(;;){const n=r.getParent();if(!n||!s.isPropertyAccessExpression(n))break;const i=n.getParent();if(!i||!s.isCallExpression(i))break;t.push(n.getName()),r=i}return t},v=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,b=e=>{let t=e;for(;;){const r=t.getParent();if(!r||!s.isPropertyAccessExpression(r))return!1;const n=r.getParent();if(!n||!s.isCallExpression(n))return!1;if(r.getName()==="filter"){const i=n.getArguments()[0];if(i&&v.test(i.getText()))return!0}t=n}},D=e=>{const t=e.getArguments()[0];return t&&s.isStringLiteral(t)?t.getLiteralText():""},L=(e,t)=>{const r=[];for(const n of E(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),g=P(t,n);for(const o of i.getDescendantsOfKind(a.CallExpression)){if(!S(o))continue;const c=h(o);c.includes("filter")&&r.push({exportName:y(o),file:g,filtersPrimaryKey:b(o),hasFilter:!0,hasIndex:c.some(f=>I.has(f)),line:o.getStartLineNumber(),table:D(o)})}}return r};export{O as a,C as b,T as c,l as d,y as e,w as i,N as r,u as s,L as y};
|
|
@@ -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-CVYkUBTm.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-CVYkUBTm.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}`},h=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),w=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",h);return s||T(o,"agents",a,r,"agent",w)||{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 h(s);if(c)return w(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 C,lstatSync as $}from"node:fs";import{join as O,extname as j,relative as z,sep as U}from"node:path";import{Node as s,SyntaxKind as V}from"ts-morph";import{t as _}from"./module-specifiers-8FEEiUcv.mjs";import{s as R,c as h}from"./parse-validator-_jDrFxwt.mjs";import{n as M}from"./paths-BmX5O1sG.mjs";const y=new Set(["action","mutation","query","stream"]),P=/\bany\b(?!\s*(?:\?\s*)?:)/u,b=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,q=/^[A-Za-z_$][\w$]*$/u,B=e=>q.test(e)?e:JSON.stringify(e),H=/\.ts$/u,W=(e,t)=>z(e,t).split(U).join("/").replace(H,""),T={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},J={onConnect:"connect",onDisconnect:"disconnect"},Q=_,N=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 Q(n)?r.getNameNode().getText():void 0}},S=(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=N(i);if(r===void 0){if(t)return;const n=i.getSymbol()?.getValueDeclaration();if(n&&s.isVariableDeclaration(n)){const o=n.getInitializer();return o?S(o,!0):void 0}return}return y.has(r)?"public":T[r]?"internal":void 0},d=(e,t)=>{const i=e.getProperty(t);if(i===void 0||!s.isPropertyAssignment(i))return;const r=i.getInitializer();return r!==void 0&&s.isStringLiteral(r)?r.getLiteralValue():void 0},E=(e,t)=>{const i=e.getProperty(t);if(i===void 0||!s.isPropertyAssignment(i))return;const r=i.getInitializer();return r!==void 0&&s.isNumericLiteral(r)?r.getLiteralValue():void 0},G=e=>{const t=e.getProperty("cache");if(t===void 0||!s.isPropertyAssignment(t))return;const i=t.getInitializer();if(i===void 0||!s.isObjectLiteralExpression(i))return;const r=d(i,"scope"),n=E(i,"maxAge"),o=E(i,"staleWhileRevalidate"),a=d(i,"tag"),c=d(i,"vary"),l={...n===void 0?{}:{maxAge:n},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},K=e=>{if(e===void 0||!s.isObjectLiteralExpression(e))return{};const t=G(e),i=e.getProperty("rest");return i!==void 0&&s.isPropertyAssignment(i)?{...t===void 0?{}:{cache:t},rest:i.getInitializer()?.getText()==="true"}:t===void 0?{}:{cache:t}},Z=e=>{let t=e;for(;s.isCallExpression(t);){const i=t.getExpression();if(!s.isPropertyAccessExpression(i))return;if(i.getName()==="expose")return K(t.getArguments()[0]);t=i.getExpression()}},X=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)?{}:h(r)},Y=(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},ee=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},I=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0,g=(e,t,i,r=new Set)=>r.has(e)?!1:(r.add(e),Y(e,i)||ee(e).some(n=>g(n,t,i,r))?!0:I(e)?e.getProperties().some(n=>g(n.getTypeAtLocation(t),t,i,r)):!1),te=(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())},ie=8,re=(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}[]`},ne=(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(" | ")},se=(e,t,i,r,n,o)=>{if(!I(e))return;const a=[];for(const c of e.getProperties()){const l=c.getTypeAtLocation(t),m=te(c,l),D=m&&l.isUnion()?l.getUnionTypes().filter(f=>!f.isUndefined()):[l],x=[];for(const f of D){const v=o(f,t,i,r+1,n);if(v===void 0)return;x.push(v)}a.push(`${B(c.getName())}${m?"?":""}: ${x.join(" | ")}`)}return a.length>0?`{ ${a.join("; ")} }`:"{}"},p=(e,t,i,r,n)=>{if(r>ie||n.has(e))return;if(!g(e,t,i))return e.getText(t);const o=new Set(n).add(e);return e.isArray()?re(e,t,i,r,o,p):e.isUnion()?ne(e,t,i,r,o,p):se(e,t,i,r,o,p)},k=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"||P.test(n.replaceAll(b,"")))return"unknown";const o=e.getSourceFile().getFilePath();return g(i,e,o)?p(i,e,o,0,new Set)??"unknown":n},Te=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const i=t.getTypeAtLocation(e).getProperty("types");if(!i)return;const r=i.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!r)return;const n=r.getTypeAtLocation(e),o=n.getText(e);if(!o||o==="any"||o==="never"||P.test(o.replaceAll(b,"")))return;const a=e.getSourceFile().getFilePath();return g(n,e,a)?p(n,e,a,0,new Set):o},oe=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":k(r)},ae=e=>{const t=e.getArguments()[0];return!t||!(s.isArrowFunction(t)||s.isFunctionExpression(t))?"unknown":k(t)},ce=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={...h(n),...t})}i=r.getExpression()}return t},le=e=>{let t=e;for(;s.isCallExpression(t);){const i=t.getExpression();if(!s.isPropertyAccessExpression(i))return;if(i.getName()==="output"){const r=t.getArguments()[0];return r&&s.isExpression(r)?R(r):void 0}t=i.getExpression()}},ue=e=>{const t=e.getExpression();if(s.isPropertyAccessExpression(t)){const o=t.getName();if(!y.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=S(a);return c?{kind:o,receiver:a,visibility:c}:void 0}if(!s.isIdentifier(t))return;const i=N(t);if(!i)return;if(y.has(i))return{kind:i,visibility:"public"};const r=T[i];if(r)return{kind:r,visibility:"internal"};const n=J[i];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}},A=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,Ne=e=>s.isPropertyAccessExpression(e)&&e.getName()==="db"||s.isIdentifier(e)&&e.getText()==="db",Se=e=>{const t=e.getArguments()[0],i=A(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)?A(r.getInitializer()):void 0},pe=e=>s.isIdentifier(e)?e.getText():s.isPropertyAccessExpression(e)?e.getName():"",Ie=(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},ke=(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)&&pe(o.getExpression())===i)return!0;r=n.getExpression()}return!1},w=(e,t=[],i=e)=>{let r;try{r=C(e)}catch{return t}for(const n of r){const o=O(e,n),a=$(o);if(a.isDirectory()){if(n==="_generated"||n==="node_modules")continue;w(o,t,i)}else if(a.isFile()&&j(n)===".ts"){if(n==="schema.ts"&&e===i)continue;t.push(o)}}return t},ge=e=>{const t=ue(e);if(t){if(t.receiver){const i=Z(t.receiver),r=le(t.receiver);return{args:ce(t.receiver),...i?{expose:i}:{},kind:t.kind,...r?{output:r}:{},returnType:ae(e),visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:X(e),kind:t.kind,returnType:oe(e),visibility:t.visibility}}},fe=8,u=(e,t=0)=>{if(t>fe)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?F(i,t+1):void 0},F=(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(V.VariableDeclaration)?.getInitializer()?.getType().getProperty(i)?.getValueDeclaration();return r?F(r,t+1):void 0}},de=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]]:[]},L=(e,t,i)=>{const r=ge(e);if(r)return{args:r.args,exportName:t,filePath:i,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},ye=(e,t)=>{const i=[];for(const r of e.getExportAssignments()){if(r.isExportEquals())continue;const n=u(r.getExpression()),o=n?L(n,"default",t):void 0;o&&i.push(o)}return i},me=(e,t)=>{const i=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations())for(const[o,a]of de(n)){const c=L(a,o,t);c&&i.push(c)}return i.push(...ye(e,t)),i},xe=e=>{const t=new Map;for(const i of e){const r=M(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)}},we=(e,t)=>{const i=w(t),r=[];for(const n of i){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),a=W(t,n);r.push(...me(o,a))}return r.sort((n,o)=>`${n.filePath}:${n.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),xe(r),r};export{Ie as chainHasStep,ke as chainUsesWrappedCall,ue as classifyProcedureCall,we as discoverFunctions,A as inlineHandler,Ne as isDatabaseAccessor,w as listLunoraSourceFiles,W as lunoraRelativePath,Se as procedureHandler,Te as resolveStandardSchemaType,k 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-CVYkUBTm.mjs";import{s as d,c as g}from"./parse-validator-_jDrFxwt.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},$=r=>{const e=r.getArguments()[0];return!e||!(a.isArrowFunction(e)||a.isFunctionExpression(e))?"unknown":f(e)},C=(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:$(r)}:{},...t.output?{output:t.output}:{}}},v=(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=C(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(...v(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-CVYkUBTm.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()}},d=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:d(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-CVYkUBTm.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():""},L=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]}},M=(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}=L(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=M(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"},C=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 C(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-CVYkUBTm.mjs";import{o as I}from"./module-specifiers-8FEEiUcv.mjs";const S=/\.ts$/u,x=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)||!x(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")??""}},E=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(S,"");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)),E(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-CVYkUBTm.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},E=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},N=(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=E(i);s&&r.push(...N(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"ts-morph";import{y as p}from"./discover-queries-Ctpk9SA-.mjs";import"./discoverFunctions-CVYkUBTm.mjs";export{p 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-CVYkUBTm.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-CVYkUBTm.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},I=(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},N=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"))}},O=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=N(o);a&&i.push(a)}return i},w=(t,e,r)=>{const s=L(t);return{policies:s.flatMap(i=>I(i,e,r)),roles:s.flatMap(i=>O(i))}},F=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 F(o)){const p=w(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-CVYkUBTm.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};
|