@lunora/codegen 1.0.0-alpha.85 → 1.0.0-alpha.87
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/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{FLAGS_FILENAME-BiJh08O0.mjs → FLAGS_FILENAME-CHaH6obH.mjs} +1 -1
- package/dist/packem_shared/GENERATED_HEADER-CUBdTCVk.mjs +1 -0
- package/dist/packem_shared/{MUTATORS_FILENAME-9652koWz.mjs → MUTATORS_FILENAME-DY3rgWGl.mjs} +1 -1
- package/dist/packem_shared/{NOTIFY_FILENAME-DeIlwPBu.mjs → NOTIFY_FILENAME-CDvoTY3Y.mjs} +1 -1
- package/dist/packem_shared/{OPENRPC_VERSION-K3RTK2CP.mjs → OPENRPC_VERSION-aq5eyIkd.mjs} +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-ChA6rpGP.mjs +9 -0
- package/dist/packem_shared/{SHAPES_FILENAME-Cwn4I4UB.mjs → SHAPES_FILENAME-BdLj5-mD.mjs} +1 -1
- package/dist/packem_shared/{buildOpenApiDocument-Blf3mpIz.mjs → buildOpenApiDocument-Bw3MChvT.mjs} +1 -1
- package/dist/packem_shared/{discover-queries-B4Lw0cEr.mjs → discover-queries-BmZeJ--u.mjs} +1 -1
- package/dist/packem_shared/{discoverAuthApiCalls-CVTXSguP.mjs → discoverAuthApiCalls-BgL6nj03.mjs} +1 -1
- package/dist/packem_shared/{discoverCrons-CZ0_RXUc.mjs → discoverCrons-WJscxQFl.mjs} +1 -1
- package/dist/packem_shared/discoverFunctions-BgGmxEqW.mjs +1 -0
- package/dist/packem_shared/{discoverHttpRoutes-VyBQ9CbN.mjs → discoverHttpRoutes-eW8RbVOr.mjs} +1 -1
- package/dist/packem_shared/{discoverInserts-BGlOx2Cg.mjs → discoverInserts-BCz6zpI0.mjs} +1 -1
- package/dist/packem_shared/{discoverMaskProcedures-DpAT4zsu.mjs → discoverMaskProcedures-DLfQRsQc.mjs} +1 -1
- package/dist/packem_shared/{discoverMigrations-CcOvlTA7.mjs → discoverMigrations-Cbc4W765.mjs} +1 -1
- package/dist/packem_shared/{discoverNondeterministicCalls-CVY5_-x1.mjs → discoverNondeterministicCalls-x9IhWxPP.mjs} +1 -1
- package/dist/packem_shared/discoverQueries-Cf0LGoQG.mjs +1 -0
- package/dist/packem_shared/{discoverR2sqlCalls-BKn9ogOI.mjs → discoverR2sqlCalls--MSfSeDm.mjs} +1 -1
- package/dist/packem_shared/{discoverRlsMetadata-B2iTIbm0.mjs → discoverRlsMetadata-DTRS0ROc.mjs} +1 -1
- package/dist/packem_shared/{discoverSandboxUsage-rkLj3ZC0.mjs → discoverSandboxUsage-BDyeyuYo.mjs} +1 -1
- package/dist/packem_shared/discoverSchema-DSJSX4Ss.mjs +1 -0
- package/dist/packem_shared/{discoverStorageRulesMetadata-AD_GPKdF.mjs → discoverStorageRulesMetadata-Cic97L-2.mjs} +1 -1
- package/dist/packem_shared/{emit-B7IUlWwi.mjs → emit-DMvG162j.mjs} +335 -324
- package/dist/packem_shared/{emitApp-jRD2D9kI.mjs → emitApp--dJ6EnFn.mjs} +1 -1
- package/dist/packem_shared/parse-validator-CkLxY-Mr.mjs +1 -0
- package/package.json +10 -10
- package/dist/packem_shared/GENERATED_HEADER-oy7DTIDi.mjs +0 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DHVrsPNK.mjs +0 -9
- package/dist/packem_shared/discoverFunctions-9GMvSwz7.mjs +0 -1
- package/dist/packem_shared/discoverQueries-BFFoJLOQ.mjs +0 -1
- package/dist/packem_shared/discoverSchema-1zm6abY5.mjs +0 -1
- package/dist/packem_shared/parse-validator-DCrBLhq7.mjs +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -2793,7 +2793,7 @@ declare const WORKFLOWS_FILENAME = "workflows.ts";
|
|
|
2793
2793
|
declare const discoverWorkflows: (project: Project, lunoraDirectory: string) => WorkflowIR[];
|
|
2794
2794
|
declare const GENERATED_HEADER = "// GENERATED by @lunora/codegen — do not edit.\n// Run `lunora codegen` to regenerate.\n\n";
|
|
2795
2795
|
/** Emit `_generated/dataModel.ts` — `Doc<"name">` + `Id<"name">` for every table. */
|
|
2796
|
-
declare const emitDataModel: (schema: SchemaIR
|
|
2796
|
+
declare const emitDataModel: (schema: SchemaIR) => string;
|
|
2797
2797
|
/**
|
|
2798
2798
|
* Emit `_generated/api.ts` — the typed `api.*` registry (public functions), the
|
|
2799
2799
|
* `internal.*` registry, and (when the project declares them) the typed
|
package/dist/index.d.ts
CHANGED
|
@@ -2793,7 +2793,7 @@ declare const WORKFLOWS_FILENAME = "workflows.ts";
|
|
|
2793
2793
|
declare const discoverWorkflows: (project: Project, lunoraDirectory: string) => WorkflowIR[];
|
|
2794
2794
|
declare const GENERATED_HEADER = "// GENERATED by @lunora/codegen — do not edit.\n// Run `lunora codegen` to regenerate.\n\n";
|
|
2795
2795
|
/** Emit `_generated/dataModel.ts` — `Doc<"name">` + `Id<"name">` for every table. */
|
|
2796
|
-
declare const emitDataModel: (schema: SchemaIR
|
|
2796
|
+
declare const emitDataModel: (schema: SchemaIR) => string;
|
|
2797
2797
|
/**
|
|
2798
2798
|
* Emit `_generated/api.ts` — the typed `api.*` registry (public functions), the
|
|
2799
2799
|
* `internal.*` registry, and (when the project declares them) the typed
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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 f}from"./packem_shared/formatAdvisories-BCEfzLT0.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as l}from"./packem_shared/describeErrorLevelFindings-IhNx9gPr.mjs";import{CodegenDiagnosticError as E,diagnosticAt as x}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-BesaDYkL.mjs";import{default as O}from"./packem_shared/discoverAuthApiCalls-
|
|
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 f}from"./packem_shared/formatAdvisories-BCEfzLT0.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as l}from"./packem_shared/describeErrorLevelFindings-IhNx9gPr.mjs";import{CodegenDiagnosticError as E,diagnosticAt as x}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-BesaDYkL.mjs";import{default as O}from"./packem_shared/discoverAuthApiCalls-BgL6nj03.mjs";import{CONTAINERS_FILENAME as R,discoverContainers as C}from"./packem_shared/CONTAINERS_FILENAME-CFwdyaCI.mjs";import{default as h}from"./packem_shared/discoverCrons-WJscxQFl.mjs";import{FLAGS_FILENAME as _,discoverFlags as L}from"./packem_shared/FLAGS_FILENAME-CHaH6obH.mjs";import{discoverFunctions as T}from"./packem_shared/discoverFunctions-BgGmxEqW.mjs";import{default as D}from"./packem_shared/discoverHttpRoutes-eW8RbVOr.mjs";import{default as H}from"./packem_shared/discoverInserts-BCz6zpI0.mjs";import{default as y}from"./packem_shared/discoverMaskProcedures-DLfQRsQc.mjs";import{default as W}from"./packem_shared/discoverMigrations-Cbc4W765.mjs";import{MUTATORS_FILENAME as V,discoverMutators as j}from"./packem_shared/MUTATORS_FILENAME-DY3rgWGl.mjs";import{default as Q}from"./packem_shared/discoverNondeterministicCalls-x9IhWxPP.mjs";import{NOTIFY_FILENAME as w,discoverNotifyCalls as B,discoverNotifyConfig as K}from"./packem_shared/NOTIFY_FILENAME-CDvoTY3Y.mjs";import{default as Y}from"./packem_shared/readPackageDependencies-CogJX1Ia.mjs";import{y as X}from"./packem_shared/discover-queries-BmZeJ--u.mjs";import{QUEUES_FILENAME as ee,discoverQueues as re}from"./packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs";import{default as te}from"./packem_shared/discoverR2sqlCalls--MSfSeDm.mjs";import{discoverRlsMetadata as ae,default as ie}from"./packem_shared/discoverRlsMetadata-DTRS0ROc.mjs";import{discoverSandboxUsage as de}from"./packem_shared/discoverSandboxUsage-BDyeyuYo.mjs";import{default as pe}from"./packem_shared/discoverSchema-DSJSX4Ss.mjs";import{SHAPES_FILENAME as ne,discoverShapes as le}from"./packem_shared/SHAPES_FILENAME-BdLj5-mD.mjs";import{default as Ee}from"./packem_shared/discoverStorageRulesMetadata-Cic97L-2.mjs";import{WORKFLOWS_FILENAME as Ae,discoverWorkflows as ue}from"./packem_shared/WORKFLOWS_FILENAME-ClsYRKXp.mjs";import{S as Ne,c as Oe,C as ge,E as Re,s as Ce,A as Me,g as he,$ as Ie,q as _e,B as Le,x as Fe,N as Te,l as Pe,T as De}from"./packem_shared/emit-DMvG162j.mjs";import{emitApp as He}from"./packem_shared/emitApp--dJ6EnFn.mjs";import{buildOpenApiDocument as ye,emitOpenApi as Ge,emitOpenApiModule as We}from"./packem_shared/buildOpenApiDocument-Bw3MChvT.mjs";import{OPENRPC_VERSION as Ve,buildOpenRpcDocument as je,emitOpenRpc as ze,emitOpenRpcModule as Qe}from"./packem_shared/OPENRPC_VERSION-aq5eyIkd.mjs";import{DEFAULT_TARGET as we,platformMatrixIds as Be,readProjectTarget as Ke,resolveCodegenTarget as Je}from"./packem_shared/DEFAULT_TARGET-CH5disA3.mjs";import{SCHEMA_SNAPSHOT_FILENAME as $e,createCodegenProject as Xe,refreshCodegenProject as Ze,runCodegen as er}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-ChA6rpGP.mjs";import{SchemaSnapshotParseError as or,buildSchemaSnapshot as tr,evaluateSchemaDrift as sr,parseSchemaSnapshot as ar}from"./packem_shared/SchemaSnapshotParseError-BJkhTEpi.mjs";import{schemaFromIr as mr}from"./packem_shared/schemaFromIr-R1ZFzVyy.mjs";import{LUNORA_ERROR_CODES as fr,validatorIrToJsonSchema as pr}from"./packem_shared/LUNORA_ERROR_CODES-Um9hC1gr.mjs";import{redact as nr,secretKindOf as lr}from"./packem_shared/redact-6jD4lAhq.mjs";import{MESSAGE_SOLUTIONS as Er,findSolutionByMessage as xr}from"@lunora/errors";const e="0.0.0";export{u as AGENTS_FILENAME,R as CONTAINERS_FILENAME,E as CodegenDiagnosticError,we as DEFAULT_TARGET,_ as FLAGS_FILENAME,Ne as GENERATED_HEADER,fr as LUNORA_ERROR_CODES,Er as LUNORA_SOLUTION_RULES,V as MUTATORS_FILENAME,w as NOTIFY_FILENAME,Ve as OPENRPC_VERSION,ee as QUEUES_FILENAME,$e as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,ne as SHAPES_FILENAME,or as SchemaSnapshotParseError,e as VERSION,Ae as WORKFLOWS_FILENAME,ye as buildOpenApiDocument,je as buildOpenRpcDocument,tr as buildSchemaSnapshot,Xe as createCodegenProject,c as describeErrorLevelFindings,x as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,O as discoverAuthApiCalls,C as discoverContainers,h as discoverCrons,L as discoverFlags,T as discoverFunctions,D as discoverHttpRoutes,H as discoverInserts,y as discoverMaskProcedures,W as discoverMigrations,j as discoverMutators,Q as discoverNondeterministicCalls,B as discoverNotifyCalls,K as discoverNotifyConfig,X as discoverQueries,re as discoverQueues,te as discoverR2sqlCalls,ae as discoverRlsMetadata,ie as discoverRlsProcedures,de as discoverSandboxUsage,pe as discoverSchema,le as discoverShapes,Ee as discoverStorageRulesMetadata,ue as discoverWorkflows,Oe as emitAgents,ge as emitApi,He as emitApp,Re as emitCollections,Ce as emitContainers,Me as emitCrons,he as emitDataModel,Ie as emitDrizzleSchema,_e as emitFunctions,Ge as emitOpenApi,We as emitOpenApiModule,ze as emitOpenRpc,Qe as emitOpenRpcModule,Le as emitServer,Fe as emitShard,Te as emitVectors,Pe as emitWorkflows,De as emitWranglerCronTriggers,n as errorAdvisoryNames,l as errorPlatformDiagnosticNames,sr as evaluateSchemaDrift,xr as findLunoraSolution,m as formatAdvisories,d as lintSchema,ar as parseSchemaSnapshot,Be as platformMatrixIds,Y as readPackageDependencies,Ke as readProjectTarget,nr as redact,Ze as refreshCodegenProject,Je as resolveCodegenTarget,er as runCodegen,mr as schemaFromIr,lr as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,pr as validatorIrToJsonSchema};
|
|
@@ -1 +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-
|
|
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-BgGmxEqW.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{S as r,b as o,a as n,c as l,C as A,E,s as S,A as C,g,$ as p,q as c,d,L as u,B as D,x as B,N as L,l as R,T}from"./emit-DMvG162j.mjs";import"./paths-BmX5O1sG.mjs";export{r as GENERATED_HEADER,o as UMBRELLA_BASE_PACKAGES,n as buildStorageColumns,l as emitAgents,A as emitApi,E as emitCollections,S as emitContainers,C as emitCrons,g as emitDataModel,p as emitDrizzleSchema,c as emitFunctions,d as emitQueues,u as emitSeed,D as emitServer,B as emitShard,L as emitVectors,R as emitWorkflows,T as emitWranglerCronTriggers};
|
package/dist/packem_shared/{MUTATORS_FILENAME-9652koWz.mjs → MUTATORS_FILENAME-DY3rgWGl.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as p}from"node:fs";import{join as m}from"node:path";import{Node as o,SyntaxKind as c}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{unwrapHandlerReturn as g}from"./discoverFunctions-
|
|
1
|
+
import{existsSync as p}from"node:fs";import{join as m}from"node:path";import{Node as o,SyntaxKind as c}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{unwrapHandlerReturn as g}from"./discoverFunctions-BgGmxEqW.mjs";import{t as d}from"./module-specifiers-8FEEiUcv.mjs";import{f as x}from"./parse-validator-CkLxY-Mr.mjs";const y="mutators.ts",f=d,E=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},N=r=>{const e=r.getSymbol();if(!e)return!1;for(const t of e.getDeclarations()){if(!o.isNamespaceImport(t))continue;const i=t.getFirstAncestorByKind(c.ImportDeclaration);return i!==void 0&&f(i.getModuleSpecifierValue())}return!1},I=r=>{if(o.isIdentifier(r))return E(r);if(o.isPropertyAccessExpression(r)){const e=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(e)&&N(e)}return!1},S=r=>{const e=r.getArguments()[0];return e&&o.isObjectLiteralExpression(e)?e:void 0},A=r=>{const e=r?.getProperty("args");if(!e||!o.isPropertyAssignment(e))return{};const t=e.getInitializer();return t&&o.isObjectLiteralExpression(t)?x(t):{}},M=r=>{const e=r?.getProperty("server");if(!e||!o.isPropertyAssignment(e))return"unknown";const t=e.getInitializer();return!t||!(o.isArrowFunction(t)||o.isFunctionExpression(t))?"unknown":g(t)},P=r=>{const e=[];for(const t of r.getVariableDeclarations()){if(!t.isExported())continue;const i=t.getInitializer();if(i?.getKind()!==c.CallExpression)continue;const n=i,a=n.getExpression();if(!I(a))continue;const s=t.getNameNode();if(!o.isIdentifier(s))throw l(s,"defineMutator exports must be plain named exports (no destructuring)");const u=S(n);e.push({args:A(u),exportName:s.getText(),filePath:"mutators",returnType:M(u)})}return e},j=(r,e)=>{const t=m(e,y);if(!p(t))return[];const i=r.getSourceFile(t)??r.addSourceFileAtPath(t),n=P(i);return n.sort((a,s)=>a.exportName.localeCompare(s.exportName)),n};export{y as MUTATORS_FILENAME,j as discoverMutators,I as isDefineMutatorCallee};
|
|
@@ -1 +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-
|
|
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-BgGmxEqW.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,D=(t,r)=>{const e=[];for(const s of l(r)){const i=t.getSourceFile(s)??t.addSourceFileAtPath(s),n=m(r,s);for(const c of g(i))if(!(c.kind!=="query"&&c.kind!=="mutation"))for(const a of c.handler.getDescendantsOfKind(p.PropertyAccessExpression)){const u=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},L=(t,r)=>{const e=h(r,E);if(!x(e))return;const s=t.getSourceFile(e)??t.addSourceFileAtPath(e),i=v(s);let n=!1,c=!1;if(i&&o.isCallExpression(i)){const a=i.getArguments()[0];a&&o.isObjectLiteralExpression(a)&&(n=a.getProperty("webPush")!==void 0,c=a.getProperty("fcm")!==void 0)}return{hasFcm:c,hasWebPush:n,usesPush:b(t,r)}};export{E as NOTIFY_FILENAME,D as discoverNotifyCalls,L as discoverNotifyConfig};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{S as a}from"./emit-DMvG162j.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
2
|
`,O=e=>`${a}export const openRpcSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
|
|
3
3
|
`;export{m as OPENRPC_VERSION,d as buildOpenRpcDocument,R as emitOpenRpc,O as emitOpenRpcModule};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import{existsSync as A,mkdirSync as Mt,readFileSync as lt,writeFileSync as jt,rmSync as zt}from"node:fs";import{join as f,dirname as ce}from"node:path";import{performance as ue}from"node:perf_hooks";import{runAdvisor as qt}from"@lunora/advisor";import{LunoraError as F}from"@lunora/errors";import{SyntaxKind as u,Node as i,Project as _e}from"ts-morph";import{serializeSchemaSnapshot as Bt}from"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{toAdvisorContext as Ut}from"./formatAdvisories-BCEfzLT0.mjs";import{discoverAgents as Vt}from"./AGENTS_FILENAME-BesaDYkL.mjs";import{discoverContainers as Wt}from"./CONTAINERS_FILENAME-CFwdyaCI.mjs";import{diagnosticAt as X}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{o as Z}from"./module-specifiers-8FEEiUcv.mjs";import{r as le,B as _t,g as Gt,a as Ht,C as Qt,q as Jt,x as Xt,E as Zt,s as Yt,l as es,c as ts,d as ss,A as rs,N as ns,$ as is,L as os,T as as}from"./emit-DMvG162j.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as g,classifyProcedureCall as R,inlineHandler as cs,procedureHandler as dt,chainUsesWrappedCall as gt,isDatabaseAccessor as K,chainHasStep as us,discoverFunctions as ls,resolveStandardSchemaType as ds}from"./discoverFunctions-BgGmxEqW.mjs";import gs from"./readPackageDependencies-CogJX1Ia.mjs";import{discoverQueues as ps}from"./QUEUES_FILENAME-CSE6i-ld.mjs";import{discoverSandboxUsage as fs}from"./discoverSandboxUsage-BDyeyuYo.mjs";import ms from"./discoverStorageRulesMetadata-Cic97L-2.mjs";import{discoverWorkflows as hs}from"./WORKFLOWS_FILENAME-ClsYRKXp.mjs";import{gatePlatformFeatures as xs,resolveCodegenTarget as Es}from"./DEFAULT_TARGET-CH5disA3.mjs";import{i as w,a as L,e as E,c as b,r as ys,b as $s,s as Y,d as As,f as Ss,y as bs}from"./discover-queries-BmZeJ--u.mjs";import vs from"./discoverAuthApiCalls-BgL6nj03.mjs";import Ns from"./discoverCrons-WJscxQFl.mjs";import{discoverFlagKeys as Ps}from"./FLAGS_FILENAME-CHaH6obH.mjs";import ws from"./discoverHttpRoutes-eW8RbVOr.mjs";import Is from"./discoverInserts-BCz6zpI0.mjs";import Ts,{discoverMaskStrategies as Fs,discoverMaskMetadata as Ls,discoverMaskHasNonLiteralPolicy as Ds}from"./discoverMaskProcedures-DLfQRsQc.mjs";import Os from"./discoverMigrations-Cbc4W765.mjs";import{MUTATORS_FILENAME as ks,isDefineMutatorCallee as Cs,discoverMutators as Ks}from"./MUTATORS_FILENAME-DY3rgWGl.mjs";import Rs from"./discoverNondeterministicCalls-x9IhWxPP.mjs";import{discoverNotifyConfig as Ms,discoverNotifyCalls as js}from"./NOTIFY_FILENAME-CDvoTY3Y.mjs";import zs from"./discoverR2sqlCalls--MSfSeDm.mjs";import qs,{discoverRlsMetadata as Bs}from"./discoverRlsMetadata-DTRS0ROc.mjs";import Us from"./discoverSchema-DSJSX4Ss.mjs";import{secretKindOf as Vs,redact as Ws,isHeuristicSecretKind as _s,isSecretishName as Gs}from"./redact-6jD4lAhq.mjs";import{discoverShapes as Hs}from"./SHAPES_FILENAME-BdLj5-mD.mjs";import{e as Qs}from"./discover-ast-CezKqEhE.mjs";import{emitApp as Js}from"./emitApp--dJ6EnFn.mjs";import{buildOpenApiDocument as Xs,emitOpenApiModule as Zs}from"./buildOpenApiDocument-Bw3MChvT.mjs";import{buildOpenRpcDocument as Ys,emitOpenRpcModule as er}from"./OPENRPC_VERSION-aq5eyIkd.mjs";import{g as tr}from"./parse-validator-CkLxY-Mr.mjs";import{buildSchemaSnapshot as sr}from"./SchemaSnapshotParseError-BJkhTEpi.mjs";const rr=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},nr=(e,t)=>{if(t===void 0)return;const s=rr(e).filter(n=>!t.has(n.name));if(s.length===0)return;const r=s.map(n=>` - ${n.name} — ${n.reason}`).join(`
|
|
2
|
+
`);throw new F("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
|
|
3
|
+
${r}
|
|
4
|
+
|
|
5
|
+
Install them with your package manager, then re-run codegen.`)},ir="env.ts",or=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return Z(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},ar=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&&Z(r.getModuleSpecifierValue())}return!1},cr=e=>{if(i.isIdentifier(e))return or(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&ar(t)}return!1},ur=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!cr(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw X(n,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},lr=(e,t)=>{const s=f(t,ir);if(!A(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=ur(r);if(n.length!==0){if(n.length>1)throw X(r,`lunora/env.ts declares ${n.length.toString()} defineEnv() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},dr=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},gr=(e,t)=>{const s=Object.fromEntries(le.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=dr(n);for(const c of le)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(le.every(c=>s[c.key]))break}return s},pr=["providerSubscriptionId","state"],fr=["providerEventId","processedAt"],Ge=(e,t)=>t.every(s=>s in e.shape),mr=e=>{const t=e.find(r=>r.name==="subscriptions"),s=e.find(r=>r.name==="events");return t!==void 0&&s!==void 0&&Ge(t,pr)&&Ge(s,fr)},hr=(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")}),pt="identity.ts",xr=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return Z(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Er=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&&Z(r.getModuleSpecifierValue())}return!1},yr=e=>{if(i.isIdentifier(e))return xr(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&Er(t)}return!1},$r=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!yr(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw X(n,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},Ar=(e,t)=>{const s=f(t,pt);if(!A(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=$r(r);if(n.length!==0){if(n.length>1)throw X(r,`lunora/identity.ts declares ${n.length.toString()} defineIdentity() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},Sr=(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 F("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 F("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 F("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})}},br=e=>{const{lunoraDirectory:t,project:s,projectRoot:r,schema:n}=e,o=Ar(s,t),a=lr(s,t),c=hs(s,t),l=ps(s,t),p=Vt(s,t);Sr(c,p);const y=Wt(s,t),N=ms(s,t),m=xs(gr(s,t),Es(r,e.target)),$=m.usage,O=fs(s,t),M=$.browser||O.usesSandboxBrowser,j=gs(r),B=j??new Set,I=B.has("lunorash");nr(n,j);const k=A(f(t,"flags.ts")),z=A(f(t,"notify.ts"));return{agents:p,containers:y,dataModelContent:Gt(n),declaredDependencies:j,dependencies:B,env:a,featureUsage:$,hasBrowser:M,hasFlags:k,hasNotify:z,identity:o,platformGate:m,queues:l,serverContent:_t({agents:p,containers:y,env:a,hasAccessFacade:$.access,hasAi:$.ai,hasAnalytics:$.analytics,hasBrowser:M,hasFlags:k,hasHyperdrive:$.hyperdrive,hasImages:$.images,hasKv:$.kv,hasNotify:z,hasPayments:$.payments,hasPipelines:$.pipelines,hasR2sql:$.r2sql,hasX402:$.x402,identity:o,queues:l,schema:n,storageRuleBuckets:N.rules.map(te=>te.bucket),useUmbrella:I,workflows:c}),storageRulesMetadata:N,usesSandbox:O.usesSandboxBrowser||O.usesSandboxContainer,useUmbrella:I,workflows:c}},ft=new Set(["delete","get","head","options","patch","post","put"]),vr=new Set(["handler","stream"]),Nr=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,He=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)||!ft.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()}},wr=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)||ft.has(r.getName()))break;s=r.getExpression()}return Pr(s)},Ir=e=>{for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression))if(He.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&He.has(s.getText()))return!0}return!1},Tr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||!vr.has(r.getName()))return;const n=wr(s);if(!n||!Nr.test(n.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&Ir(o);return{exportName:e.getName(),file:t,method:n.method,path:n.path,usesGuard:a}},Fr=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Tr(n,t);o&&s.push(o)}return s},Lr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Fr(n,g(t,r)))}return s},Dr=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",Or=(e,t)=>{if(!Dr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)||L(s)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},kr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Or(r,t);n&&s.push(n)}return s},Cr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...kr(n,g(t,r)))}return s},Kr=new Set(["generateText","streamText"]),Rr=new Set(["messages","prompt","system"]),Mr=[{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"]}],jr=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),r=t.getExpression().getText();for(const n of Mr)if(n.methods.has(s)&&n.prefixes.some(o=>r===o||r.startsWith(`${o}.`)))return`${r}.${s}`},zr=e=>{for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=jr(t);if(s!==void 0)return s}},qr=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},Br=e=>{if(ys(e))return!0;const t=qr(e);return t.size===0?!1:e.getDescendantsOfKind(u.Identifier).some(s=>t.has(s.getText()))},Ur=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!Rr.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&Br(s))return!0}return!1},Vr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=b(r.getExpression());if(n===void 0||!Kr.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(b(c.getExpression())==="tool"&&(a=zr(c),a!==void 0))break;a!==void 0&&s.push({exportName:E(r),file:t,line:r.getStartLineNumber(),method:n,sideEffect:a,userInputDerived:Ur(o)})}return s},Wr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Vr(n,g(t,r)))}return s},_r=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},Gr=(e,t)=>{if(!_r(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},Hr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Gr(r,t);n&&s.push(n)}return s},Qr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Hr(n,g(t,r)))}return s},mt=e=>e.getProperties().some(t=>i.isSpreadAssignment(t)),Jr=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:mt(r)}},Xr=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||=mt(o)):s=!0}r=n.getExpression()}return{objects:t,opaque:s}},ht=(e,t)=>t?Xr(t):Jr(e),Zr=e=>e.flatMap(t=>t.getProperties().filter(s=>i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)).map(s=>s.getName())),Yr=/\.check\(|\.meta\(|length|max/iu,en=/\bv\.any\s*\(/u,tn=/\bv\.string\s*\(/u,sn=e=>en.test(e),rn=e=>tn.test(e)&&!Yr.test(e),nn=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();sn(a)?t.push(c):rn(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},on=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=R(s);if(r?.visibility!=="public")return;const{objects:n}=ht(s,r.receiver),{anyArgs:o,unboundedStringArgs:a}=nn(n);if(!(o.length===0&&a.length===0))return{anyArgs:o,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},an=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=on(n,t);o&&s.push(o)}return s},cn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...an(n,g(t,r)))}return s},v=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},de=e=>e?.getKind()===u.TrueKeyword,un=e=>e?.getKind()===u.FalseKeyword,ln=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,dn=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),gn=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&b(t.getExpression())==="scim"),pn=e=>e!==void 0&&i.isCallExpression(e)&&dn.has(b(e.getExpression())??""),fn=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),mn=e=>{const t=v(e,"advanced"),s=v(e,"emailAndPassword"),r=v(e,"session");return{analyzable:!0,disableCsrfCheck:de(v(t,"disableCSRFCheck")),emailPasswordEnabled:de(v(s,"enabled")),requireEmailVerification:de(v(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:gn(v(e,"plugins"))&&pn(v(e,"database")),secureCookiesDisabled:un(v(t,"useSecureCookies")),sessionFreshAgeZero:ln(v(r,"freshAge")),trustedOriginsWildcard:fn(v(e,"trustedOrigins"))}},hn=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),xn=(e,t)=>{if(b(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?mn(s):hn();return{exportName:E(e),file:t,line:e.getStartLineNumber(),...n}},En=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=xn(r,t);n&&s.push(n)}return s},yn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...En(n,g(t,r)))}return s},$n=(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},An=(e,t,s)=>{const r=$n(e.getExpression(),s);if(r===void 0)return;const n=e.getArguments()[s.argIndex];if(!(!n||!w(n)||L(n))&&!(s.requireUnmodifiedReach===!0&&!$s(n)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:r}},Sn=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const o=An(n,t,s);o&&r.push(o)}return r},ee=(e,t,s)=>{const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(...Sn(o,g(t,n),s))}return r},bn=new Set(["content","pdf","scrape","screenshot"]),vn=(e,t)=>ee(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:bn}),Nn=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Pn=new Set(["RateLimiter"]),wn=new Set(["extend"]),xt=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}},Qe=e=>e&&i.isObjectLiteralExpression(e)?xt(e):{analyzable:!1,presentKeys:[],trueKeys:[]},In=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},Tn=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)?In(e):void 0},Fn=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&Tn(t.getBody());return s?xt(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Ln=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=b(r.getExpression());n!==void 0&&(Nn.has(n)?s.push({callee:n,file:t,line:r.getStartLineNumber(),...Qe(r.getArguments()[0])}):wn.has(n)&&s.push({callee:n,file:t,line:r.getStartLineNumber(),...Fn(r.getArguments()[0])}))}for(const r of e.getDescendantsOfKind(u.NewExpression)){const n=b(r.getExpression());n===void 0||!Pn.has(n)||s.push({callee:n,file:t,line:r.getStartLineNumber(),...Qe(r.getArguments()[0])})}return s},Dn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ln(n,g(t,r)))}return s},Je="ctx.containers.",On=e=>{if(!e.startsWith(Je))return!1;const t=e.slice(Je.length);return t.length>0&&!t.includes(".")},kn=(e,t)=>ee(e,t,{argIndex:0,matchReceiver:On,methods:new Set(["get"])}),Cn=new Set(["allow","deny","setAllowed"]),Kn=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())},Rn=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!Kn(e)))return{detail:"enableInternet: true",exportName:E(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},Mn=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!Cn.has(s.getName()))return;const r=s.getExpression();if(!(!i.isPropertyAccessExpression(r)||r.getName()!=="egress"))return{detail:s.getName(),exportName:E(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},jn=(e,t)=>Rn(e,t)??Mn(e,t),zn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=jn(r,t);n&&s.push(n)}return s},qn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...zn(n,g(t,r)))}return s},Bn=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Un=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return Bn.has(s)?s:void 0},Vn=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}},Wn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=g(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){const c=Un(a);if(c===void 0)continue;const l=a.getArguments()[0],p=l&&i.isObjectLiteralExpression(l)?Vn(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:p.analyzable,emptyKeys:p.emptyKeys,factory:c,file:o,line:a.getStartLineNumber(),presentKeys:p.presentKeys})}}return s},_n=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Gn=new Set(["dbRateLimit","rateLimit"]),Hn=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},Qn=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},Jn=(e,t)=>{const s=b(e.getExpression());if(s===void 0)return;const r=_n.get(s);if(r!==void 0)return{callee:s,exportName:E(e),failOpen:Hn(e.getArguments()[r]),file:t,limitName:Gn.has(s)?Qn(e):"",line:e.getStartLineNumber()}},Xn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Jn(r,t);n&&s.push(n)}return s},Zn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Xn(n,g(t,r)))}return s},Yn=e=>i.isIdentifier(e)&&e.getText()==="ctx",ei=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Yn(t.getExpression())},ti=e=>{if(e?.getKind()===u.TrueKeyword)return!0;if(e?.getKind()===u.FalseKeyword)return!1},si=(e,t)=>{if(!ei(e.getExpression()))return;const[s,r]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const n=s.getLiteralValue(),o=ti(r);if(!(n.length===0||o===void 0))return{defaultValue:o,exportName:E(e),file:t,key:n,line:e.getStartLineNumber()}},ri=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=si(r,t);n&&s.push(n)}return s},ni=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ri(n,g(t,r)))}return s},ii=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},oi=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},ai=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=g(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression))ii(a)&&s.push({file:o,indexName:oi(a),line:a.getStartLineNumber()})}return s},ci=new Set(["delete","get","head","options","patch","post","put"]),ui=new Set(["handler","stream"]),li=new Set(["runAction","runMutation"]),di=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),H=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,Xe=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,Ze=(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}}},Ye=(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(li.has(a)&&H(c,t))return a;if(di.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&H(c.getExpression(),t))return`db.${a}`}},et=(e,t)=>{const s=e.getBody();for(const r of s.getDescendantsOfKind(u.PropertyAccessExpression))if(r.getName()==="auth"&&H(r.getExpression(),t))return!0;for(const r of s.getDescendantsOfKind(u.VariableDeclaration)){const n=r.getNameNode();if(!(!i.isObjectBindingPattern(n)||!H(r.getInitializer(),t))){for(const o of n.getElements())if((o.getPropertyNameNode()?.getText()??o.getNameNode().getText())==="auth")return!0}}return!1},gi=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ui.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(ci.has(n)){const o=r.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?n.toUpperCase():void 0}s=r.getExpression()}},pi=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=Xe(e.getArguments()[0]),l=c&&Ze(c,!0);if(!c||l===void 0)return;const p=Ye(c,l);return p===void 0?void 0:{exportName:E(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:et(c,l),sideEffect:p}}const r=gi(e);if(r===void 0)return;const n=Xe(e.getArguments()[0]),o=n&&Ze(n,!1);if(!n||o===void 0)return;const a=Ye(n,o);return a===void 0?void 0:{exportName:E(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:r,readsAuth:et(n,o),sideEffect:a}},fi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=pi(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(...fi(n,g(t,r)))}return s},hi=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),xi=new Set(["append","set"]),me=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",Et=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",tt=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(u.CallExpression)]:e.getDescendantsOfKind(u.CallExpression)).some(s=>hi.has(me(s.getExpression()))&&Ss(s,t)),Ei=(e,t)=>{if(tt(e,t))return!0;const s=Y(e);return s!==void 0&&tt(s,t)},fe=(e,t)=>As(e,t)&&!Ei(e,t),yi=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=Y(e);return t!==void 0&&i.isNewExpression(t)&&me(t.getExpression())==="Headers"},Q=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=Y(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},he=(e,t,s)=>{for(const r of e.getProperties())if(i.isPropertyAssignment(r)){const n=r.getInitializer();n!==void 0&&fe(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:Et(r.getNameNode()),line:n.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(r)){const n=r.getNameNode();fe(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=Q(r.getExpression());n!==void 0&&he(n,t,s)}},yt=(e,t)=>{const s=Q(e);if(s===void 0)return;const r=s.getProperty("headers");if(r===void 0||!i.isPropertyAssignment(r))return;const n=Q(r.getInitializer());n!==void 0&&he(n,"response-init",t)},$i=(e,t)=>{const s=me(e.getExpression());if(s==="Response")yt(e.getArguments()[1],t);else if(s==="Headers"){const r=Q(e.getArguments()[0]);r!==void 0&&he(r,"headers-ctor",t)}},Ai=(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"){yt(e.getArguments()[1],t);return}if(xi.has(r)&&yi(n)){const o=e.getArguments()[1];o!==void 0&&fe(o,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:Et(e.getArguments()[0]),line:o.getStartLineNumber(),via:r==="set"?"headers-set":"headers-append"})}},Si=(e,t)=>{for(const s of e.getDescendantsOfKind(u.NewExpression))$i(s,t);for(const s of e.getDescendantsOfKind(u.CallExpression))Ai(s,t)},bi=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const r=cs(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 Si(r,{exportName:E(e),relativePath:t,requestName:o.getText(),rows:a}),a},vi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...bi(r,t));return s},Ni=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...vi(n,g(t,r)))}return s},Pi=new Set(["auth","context.auth","ctx.auth"]),wi="userId",Ii=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},Ti=(e,t)=>{const s=f(t,pt);if(!A(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const n of r.getDescendantsOfKind(u.CallExpression)){if(b(n.getExpression())!=="defineIdentity")continue;const[o]=n.getArguments();return o&&i.isObjectLiteralExpression(o)?Ii(o):void 0}},st=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Pi.has(e.getExpression().getText())?e:void 0},Fi=e=>{if(i.isPropertyAccessExpression(e)&&st(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&&st(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},Li=(e,t,s)=>{const r=[];for(const n of e.getDescendants()){const o=Fi(n);o!==void 0&&r.push({declared:o===wi||s.has(o),exportName:E(n),file:t,key:o,line:n.getStartLineNumber()})}return r},Di=(e,t)=>{const s=Ti(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(...Li(o,g(t,n),s))}return r},Oi=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},ki=(e,t)=>{if(b(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const r=Oi(s);if(!(!r||!w(r)||L(r)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},Ci=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ki(r,t);n&&s.push(n)}return s},Ki=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ci(n,g(t,r)))}return s},Ri=new Set(["delete","get","getRaw","getWithMetadata","put"]),Mi=(e,t)=>ee(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:Ri}),ji=new Set(["queue","send"]),rt=new Set(["bcc","cc","to"]),zi=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!ji.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},qi=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const r=t.getNameNode();return rt.has(t.getName())&&w(r)&&!L(r)}if(!i.isPropertyAssignment(t)||!rt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&w(s)&&!L(s)}):!1,Bi=(e,t)=>{const s=zi(e.getExpression());if(s===void 0)return;const r=e.getArguments()[0];if(!(!r||!qi(r)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s}},Ui=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Bi(r,t);n&&s.push(n)}return s},Vi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ui(n,g(t,r)))}return s},Wi=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"},_i=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},Gi=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==u.CallExpression)return;const s=t;return Cs(s.getExpression())?s:void 0},Hi=e=>{const t=Gi(e),s=t===void 0?void 0:_i(t);if(s===void 0)return[];const r=e.getNameNode(),n=i.isIdentifier(r)?r.getText():"";return s.getDescendantsOfKind(u.CallExpression).filter(o=>Wi(o)).map(o=>({exportName:n,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},Qi=e=>e.getVariableDeclarations().flatMap(t=>Hi(t)),Ji=(e,t)=>{const s=f(t,ks);if(!A(s))return[];const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Qi(r)},Xi=new Set(["delete","get","patch"]),Zi=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Yi=new Set(["auth","identity","session","user"]),eo=new Set([u.EqualsEqualsEqualsToken,u.EqualsEqualsToken,u.ExclamationEqualsEqualsToken,u.ExclamationEqualsToken]),to=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!K(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},so=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},ro=(e,t)=>e.getDescendantsOfKind(u.Identifier).some(s=>s.getText()===t),no=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(u.ThrowStatement).length>0||e.getDescendantsOfKind(u.ReturnStatement).length>0,io=(e,t)=>e.getDescendantsOfKind(u.IfStatement).some(s=>ro(s.getExpression(),t)&&no(s.getThenStatement())),oo=(e,t)=>{for(const s of e.getDescendantsOfKind(u.CallExpression)){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))continue;const n=r.getName();if(!Xi.has(n))continue;const o=r.getExpression();if(!(K(o)||i.isPropertyAccessExpression(o)&&K(o.getExpression())))continue;const a=s.getArguments()[0];if(a!==void 0&&i.isIdentifier(a)&&a.getText()===t)return n}},ao=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},co=e=>e.getDescendantsOfKind(u.CallExpression).some(t=>t.getArguments().some(s=>ao(s)==="ctx")),uo=e=>e.getDescendantsOfKind(u.BinaryExpression).some(t=>eo.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),lo=e=>{for(const t of e.getDescendantsOfKind(u.Identifier))if(Zi.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&Yi.has(t.getName()))return!0}return co(e)||uo(e)},go=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const r=R(s);if(r?.kind!=="query"&&r?.kind!=="mutation")return[];const n=dt(s);if(n===void 0)return[];const o=r.receiver!==void 0&>(r.receiver,"use","rls"),a=lo(n),c=new Set,l=[];for(const p of n.getDescendantsOfKind(u.CallExpression)){const y=to(p);if(y===void 0)continue;const N=so(p);if(N===void 0||c.has(N)||!io(n,N))continue;const m=oo(n,N);m!==void 0&&(c.add(N),l.push({exportName:e.getName(),file:t,line:p.getStartLineNumber(),mentionsOwnership:a,sinkMethod:m,table:y,usesRls:o,visibility:r.visibility}))}return l},po=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=g(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...go(c,o))}return s},fo=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),mo=new Set(["insert","insertManyUnsafe","patch","replace"]),ho=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!mo.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},xo=(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},Eo=(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||!fo.has(a))&&w(c)&&!L(c)&&n.push({exportName:E(s),field:a,file:r,line:s.getStartLineNumber(),method:t})}return n},yo=(e,t)=>{const s=ho(e.getExpression());if(s===void 0)return[];const r=e.getArguments()[1];return r?xo(r,s).flatMap(n=>Eo(n,s,e,t)):[]},$o=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression))for(const o of yo(n,t)){const a=s(o.exportName);r.push(a===void 0?o:{...o,visibility:a})}return r},Ao=(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=g(t,o);r.push(...$o(a,c,l=>n.get(`${c}:${l}`)))}return r},So=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),bo=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,vo=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?bo(t.getInitializer()):void 0},No=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=b(r.getExpression());if(n===void 0||!So.has(n))continue;const[o]=r.getArguments(),a=o&&i.isObjectLiteralExpression(o)?vo(o):void 0;s.push({callee:n,exportName:E(r),file:t,line:r.getStartLineNumber(),...a===void 0?{}:{toleranceSeconds:a}})}return s},Po=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...No(n,g(t,r)))}return s},wo=new Set(["defineQueue","defineWorkflow"]),Io=new Set(["run","runAction","runMutation","runQuery"]),To=new Set(["api","internal"]),Fo=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},Lo=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},$t=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},At=(e,t)=>e===t||e.startsWith(`${t}.`),St=e=>{const t=e.getDescendantsOfKind(u.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},nt=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e||i.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(i.isBindingElement(t)&&t.getNameNode()===e)},bt=e=>{const t=e.getDescendantsOfKind(u.Identifier).filter(s=>nt(s));return i.isIdentifier(e)&&nt(e)&&t.push(e),t},Do=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(u.BindingElement).map(s=>s.getName())},Oo=e=>{const t=$t(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},ko=(e,t,s)=>{const r=t==="workflow"?[`${s}.params`]:Oo(e),n=new Set,o=a=>St(a).some(c=>r.some(l=>At(c.getText(),l)))?!0:bt(a).some(c=>n.has(c.getText()));for(const a of e.getDescendantsOfKind(u.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of Do(a))n.add(l)}return{names:n,prefixes:r}},Co=(e,t)=>St(e).some(s=>t.prefixes.some(r=>At(s.getText(),r)))?!0:bt(e).some(s=>t.names.has(s.getText())),Ko=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)||!To.has(s.getText())||t.length<2))return{exportName:r,file:t.slice(0,-1).join("/")}},Ro=(e,t,s)=>{const r=$t(e,0);if(r===void 0)return[];const n=ko(e,t,r),o=[];for(const a of e.getDescendantsOfKind(u.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!Io.has(c.getName())||c.getExpression().getText()!==r)continue;const l=a.getArguments()[1];if(!l||!Co(l,n))continue;const p=Ko(a.getArguments()[0]);p!==void 0&&o.push({dispatchKind:t,file:s,handlerExport:E(a),line:a.getStartLineNumber(),targetExport:p.exportName,targetFile:p.file})}return o},Mo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Fo(r);if(n===void 0||!wo.has(n))continue;const o=Lo(r);o!==void 0&&s.push(...Ro(o,n==="defineQueue"?"queue":"workflow",t))}return s},jo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Mo(n,g(t,r)))}return s},it={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},ot=new Set(["account","credential","member","passkey","session","user"]),zo=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),qo=e=>{const t=zo(e).at(-1);if(!t)return!1;const s=t.endsWith("s")?t.slice(0,-1):t;return ot.has(t)||ot.has(s)},Bo=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Uo=(e,t)=>{const{objects:s,opaque:r}=ht(e,t);return Zr(s).some(n=>Bo(n))?!0:r?void 0:!1},xe=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},Vo=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Wo=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},G={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},_o=e=>{const t=Wo(e),s=t?xe(t):void 0;if(t&&s==="protectPublic"){const r=Vo(t);return{...G,usesCaptcha:r.usesCaptcha,usesRateLimit:r.usesRateLimit}}return s!==void 0&&s in it?{...G,[it[s]]:!0}:G},Go=e=>{const t={...G};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=_o(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},Ho=new Set(["insert","insertMany","insertManyUnsafe","replace"]),Qo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Ho.has(t.getName()))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)||i.isNoSubstitutionTemplateLiteral(r))?!1:qo(r.getLiteralText())},Jo=new Set(["create","runAfter","runAt","send","sendBatch"]),Xo=new Set(["queues","scheduler","workflows"]),Zo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Jo.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&Xo.has(s.getName())){const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="ctx")return!0}s=s.getExpression()}return!1},Yo=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"},vt=new Set(["generateObject","generateText","streamObject","streamText"]),ea=e=>{const t=xe(e);return t!==void 0&&vt.has(t)},ta=e=>{const t=xe(e);if(t===void 0||!vt.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")},sa=new Set(["log","span","trace"]),ra=new Set(["ai"]),na=new Set(["email","mail"]),ia=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),ge=(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"}),oa=new Set([u.ArrowFunction,u.FunctionDeclaration,u.FunctionExpression,u.GetAccessor,u.MethodDeclaration,u.SetAccessor]),aa=new Set(["every","filter","flatMap","forEach","map","some"]),ca=new Set(["all","allSettled","race"]),ua=e=>{const t=e.getParent();if(!t||!i.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;const r=s.getName();if(aa.has(r))return t;const n=s.getExpression();if(i.isIdentifier(n)&&n.getText()==="Promise"&&ca.has(r))return t},la=e=>{let t=e.getParent();for(;t;){if(i.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(oa.has(t.getKind())){const s=ua(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},da=e=>{let t=e;for(;;){const s=t.getParent();if(!i.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;if(s.getName()==="catch")return!0;if(s.getName()!=="then"&&s.getName()!=="finally")return!1;const r=s.getParent();if(!i.isCallExpression(r)||r.getExpression()!==s)return!1;t=r}},ga=e=>{let t=e;for(;;){const s=t.getParent();if(i.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return i.isCallExpression(s)&&s.getExpression()===t?s:void 0}},pa=e=>{let t=!1,s=!0;for(const r of e.getDescendantsOfKind(u.PropertyAccessExpression)){if(!ia.has(r.getName()))continue;const n=r.getExpression();if(!i.isIdentifier(n)||n.getText()!=="ctx")continue;const o=ga(r);o&&(t=!0,!la(o)&&!da(o)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},fa=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"}),at="lunora-advisor-exempt",ma=/^[\s*/]+/u,ha=/[\w-]/u,xa=e=>{const t=(e.getFirstAncestorByKind(u.VariableStatement)??e).getLeadingCommentRanges().map(s=>s.getText()).join(`
|
|
6
|
+
`);for(const s of t.split(`
|
|
7
|
+
`)){const r=s.replace(ma,"");if(!r.startsWith(at))continue;const n=r.slice(at.length);if(ha.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:""}},Ea=e=>{const[t]=e.getArguments();if(t){if(i.isObjectLiteralExpression(t)){const s=t.getProperty("handler");return s?i.isPropertyAssignment(s)?s.getInitializer():i.isShorthandPropertyAssignment(s)?s.getNameNode():i.isMethodDeclaration(s)?s:void 0:void 0}return t}},ya=(e,t)=>{const s=Ea(t);if(!s)return;if(i.isArrowFunction(s)||i.isFunctionExpression(s)||i.isMethodDeclaration(s))return e;if(!i.isIdentifier(s))return;const r=s.getSourceFile(),n=s.getText(),o=r.getVariableDeclaration(n)?.getInitializer();return o&&(i.isArrowFunction(o)||i.isFunctionExpression(o))?o:r.getFunction(n)},$a=e=>{let t=!1,s=!1,r=!1,n=!1,o=!1;for(const l of e.getDescendantsOfKind(u.CallExpression))if(Qo(l)&&(o=!0),Zo(l)&&(t=!0),Yo(l)&&(n=!0),ea(l)&&(s=!0),ta(l)&&(r=!0),o&&t&&n&&r)break;const{handlesErrors:a,reachesOutbound:c}=pa(e);return{callsMail:ge(e,na),emitsEvent:ge(e,sa),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||ge(e,ra),throwsBareError:fa(e),unboundedAiGeneration:r,usesInsertManyUnsafe:n,writesUserTable:o}},Aa=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=R(s);if(!r||r.kind!=="query"&&r.kind!=="mutation"&&r.kind!=="action")return;const n=r.receiver?Go(r.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},o=ya(e,s);return{...o?$a(o):{},...xa(e),...n,analyzableBody:o!==void 0,exportName:e.getName(),file:t,hasEmailArg:Uo(s,r.receiver),kind:r.kind,visibility:r.visibility}},Sa=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Aa(n,t);o&&s.push(o)}return s},ba=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Sa(n,g(t,r)))}return s},va=new Set(["dbRateLimit","rateLimit"]),Na=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Pa=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},wa=e=>i.isArrowFunction(e)?e.getBody():e,Ia=(e,t)=>{const s=b(e.getExpression());if(s===void 0||!va.has(s))return;const r=e.getArguments()[2];if(!r)return;const n=Na(r);if(!n)return;const o=wa(n);if(!(!w(o)||L(o)))return{callee:s,exportName:E(e),file:t,limitName:Pa(e),line:e.getStartLineNumber()}},Ta=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ia(r,t);n&&s.push(n)}return s},Fa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ta(n,g(t,r)))}return s},La=new Set(["findFirst","findFirstOrThrow","findMany","get"]),Da=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!La.has(t.getName()))return;const s=t.getExpression();if(K(s)){const r=e.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&K(s.getExpression()))return s.getName()},Oa=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&K(s.getExpression())){const r=t.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}t=s.getExpression()}},ka=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},Nt=(e,t=!1)=>{const s=ka(e);if(i.isIdentifier(s)){if(t)return;const r=Y(s);return r===void 0?void 0:Nt(r,!0)}if(i.isCallExpression(s))return Da(s)??Oa(s)},Ca=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},Ka=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const r=R(s);if(r?.kind!=="query")return[];const n=dt(s);if(n===void 0)return[];const o=r.receiver!==void 0&&us(r.receiver,"output"),a=r.receiver!==void 0&>(r.receiver,"use","mask"),c=new Set,l=[];for(const p of Ca(n)){const y=Nt(p);y===void 0||c.has(y)||(c.add(y),l.push({exportName:e.getName(),file:t,line:p.getStartLineNumber(),table:y,usesMask:a,usesOutput:o,visibility:r.visibility}))}return l},Ra=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=g(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Ka(c,o))}return s},Ma=new Set(["findFirst","findFirstOrThrow","findMany"]),ja=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Ma.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()}}},za=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},qa=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},Ba=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&i.isCallExpression(s)?R(s):void 0;if(!r)return[];const n=[];for(const o of e.getDescendantsOfKind(u.CallExpression)){const a=ja(o);if(a===void 0)continue;const c=za(qa(a.options,"with"));c.length!==0&&n.push({exportName:e.getName(),file:t,line:o.getStartLineNumber(),parentTable:a.table,relations:c,visibility:r.visibility})}return n},Ua=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=g(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Ba(c,o))}return s},J=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===u.PlusToken){const t=J(e.getLeft()),s=J(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},Va=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&&J(t)!==void 0},Wa=/(?:^|\/)__tests__\//u,_a=/\.(?:spec|test)$/u,Ga=e=>Wa.test(e)||_a.test(e),Ha=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()}},Qa=(e,t,s)=>_s(e)?!Ga(s)&&Gs(Ha(t)):!0,Ja=(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(Va(o))continue;const a=J(o);if(a===void 0)continue;const c=Vs(a);if(c===void 0||!Qa(c,o,t))continue;const l=o.getStartLineNumber(),p=`${String(l)}:${c}`;n.has(p)||(n.add(p),s.push({file:t,kind:c,line:l,preview:Ws(a)}))}return s},Xa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ja(n,g(t,r)))}return s},Za=new Set(["findFirst","findFirstOrThrow","findMany"]),Ya=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Za.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()}}},ec=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},tc=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&i.isCallExpression(s)?R(s):void 0;if(!r)return[];const n=[];for(const o of e.getDescendantsOfKind(u.CallExpression)){const a=Ya(o);if(a===void 0)continue;const c=ec(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),p=!l&&w(c);!l&&!p||n.push({exportName:e.getName(),file:t,fromArgs:p,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:r.visibility})}return n},sc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=g(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...tc(c,o))}return s},rc=new Set(["query","unsafe"]),nc=e=>{if(!i.isPropertyAccessExpression(e)||!rc.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"},ic=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),oc=e=>e.getFirstAncestorByKind(u.VariableDeclaration)?.getName()??"<module>",ac=(e,t)=>{if(!nc(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!ic(s)))return{exportName:oc(e),file:t,line:s.getStartLineNumber()}},cc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ac(r,t);n&&s.push(n)}return s},uc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...cc(n,g(t,r)))}return s},lc=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),dc=(e,t,s=[])=>{const r=new Map(s.map(n=>[`${n.filePath}:${n.exportName}`,n.visibility]));return ee(e,t,{argIndex:0,matchReceiver:n=>n==="ctx.storage"||n.startsWith("ctx.storage."),methods:lc,requireUnmodifiedReach:!0}).map(n=>{const o=r.get(`${n.file}:${n.exportName}`);return o===void 0?n:{...n,visibility:o}})},gc=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),pc=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,fc=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=pc(n.getInitializer()));continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,expiresInSeconds:s,presentKeys:t}},mc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=gc.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},hc=(e,t)=>{const s=mc(e.getExpression());if(s!==void 0)return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s.method,...fc(e.getArguments()[s.optionsIndex])}},xc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=hc(r,t);n&&s.push(n)}return s},Ec=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...xc(n,g(t,r)))}return s},yc=new Set(["RegisteredAction","RegisteredMutation","RegisteredQuery"]),Ee=e=>{const t=e.getType(),s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName();return s!==void 0&&yc.has(s)?s:void 0},Pt=e=>{const t=e.getInitializer();return t===void 0?!1:i.isCallExpression(t)||i.isIdentifier(t)||i.isPropertyAccessExpression(t)},wt={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."},$c={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."},ye=(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"}),Ac=(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}`)||!Pt(o))continue;const c=Ee(o);c!==void 0&&r.push(ye(t,a,c,o.getStartLineNumber(),wt))}return r},Sc=(e,t,s)=>{if(s.has(`${t}:default`))return[];const r=[];for(const n of e.getExportAssignments().filter(o=>!o.isExportEquals())){const o=Ee(n.getExpression());o!==void 0&&r.push(ye(t,"default",o,n.getStartLineNumber(),wt))}return r},bc=(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(p=>i.isVariableDeclaration(p));if(c===void 0||!Pt(c))continue;const l=Ee(c);l!==void 0&&r.push(ye(t,a,l,o.getStartLineNumber(),$c))}return r},vc=(e,t,s)=>[...Ac(e,t,s),...Sc(e,t,s),...bc(e,t,s)],Nc=(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(...vc(a,g(t,o),r))}return n.toSorted((o,a)=>o.cacheKey.localeCompare(a.cacheKey))},Pc=new Set(["when","where"]),pe=new Set(["definePolicy","defineShape"]),wc=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const r=t.getName();return pe.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 pe.has(n)?n:void 0}const s=t.getText();return pe.has(s)?s:void 0},Ic=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,It=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===u.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Ic(e))return"empty-object";if(i.isParenthesizedExpression(e))return It(e.getExpression())}},Tt=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Ft=e=>e.getDescendantsOfKind(u.ReturnStatement).filter(t=>Tt(t)===e),Lt=e=>e.getDescendantsOfKind(u.ConditionalExpression).filter(t=>Tt(t)===e),Tc=e=>{const t=Ft(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(u.IfStatement)!==void 0)||Lt(e).length>0},Fc=e=>{const t=[],s=e.getBody();i.isBlock(s)||t.push(s);for(const r of Ft(e)){const n=i.isReturnStatement(r)?r.getExpression():void 0;t.push(n??r)}for(const r of Lt(e))t.push(r.getWhenTrue(),r.getWhenFalse());return t},Lc=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},Dc=(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)||!Pc.has(o.getName()))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Tc(a))for(const c of Fc(a)){const l=It(c);l!==void 0&&n.push({exportName:Lc(e),file:s,form:l,key:o.getName(),line:c.getStartLineNumber(),owner:t})}}return n},Oc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=wc(r);n!==void 0&&s.push(...Dc(r,n,t))}return s},kc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Oc(n,g(t,r)))}return s},Cc=new Set(["query","upsert","upsertMany"]),Kc=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(Cc.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Rc=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("namespace");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Mc=(e,t)=>{const s=Kc(e.getExpression());if(s===void 0)return;const r=e.getArguments()[1];if(!r)return;const n=Rc(r);if(!(!n||!w(n)||L(n)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s}},jc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Mc(r,t);n&&s.push(n)}return s},zc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...jc(n,g(t,r)))}return s},qc=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"},Bc=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Uc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=g(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){if(!qc(a))continue;const c=Qs(a);c!==""&&s.push({exportName:c,file:o,line:a.getStartLineNumber(),workflow:Bc(a)})}}return s},Vc=".lunora-schema.json",S=(e,t)=>{A(e)&<(e,"utf8")===t||jt(e,t,"utf8")},P=(e,t)=>{if(t===""){zt(e,{force:!0});return}S(e,t)},Wc=e=>{const t=f(e,"package.json");if(A(t))try{const s=JSON.parse(lt(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},_c=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Gc=e=>{let t=A(e)?e:ce(e);for(;t&&t!==ce(t);){const s=f(t,"tsconfig.json");if(A(s))return s;t=ce(t)}},ct=e=>e.replaceAll("\\","/"),Hc=(e,t,s)=>{if(s&&e.length>0){const o=e.map(a=>`"${a.exportName}"`).join(", ");throw new F("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${o}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const r=new Map;for(const o of t.columns){const a=r.get(o.table)??[];a.push(o.column),r.set(o.table,a)}const n=t.columns.length>0;for(const o of e){if(o.table===void 0){if(n)throw new F("MASK_UNSUPPORTED",`defineShape "${o.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${o.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=r.get(o.table);if(a===void 0)continue;const c=a.map(l=>`"${l}"`).join(", ");throw new F("MASK_UNSUPPORTED",`defineShape "${o.exportName}" replicates table "${o.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},ut=(e,t,s)=>{const r=e.getSourceFile(t);if(r===void 0){e.createSourceFile(t,s,{overwrite:!0});return}r.getFullText()!==s&&r.replaceWithText(s)},Qc=e=>{const t=Gc(e);return t?new _e({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new _e({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Mu=(e,t)=>{const s=d(t),r=f(t,"schema.ts");A(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=>ct(c))),o=ct(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!n.has(l)&&e.removeSourceFile(c)}},ju=e=>{const t=_c(),s=t?ue.now():0,r=f(e.projectRoot,e.lunoraDirectory??"lunora"),n=f(r,"schema.ts");if(!A(n))throw new F("INTERNAL",`schema.ts not found at ${n}`);const o=e.project??Qc(r);tr(ds);const a=Us(o,n,e.projectRoot),{agents:c,containers:l,dataModelContent:p,dependencies:y,env:N,featureUsage:m,hasBrowser:$,hasFlags:O,hasNotify:M,identity:j,platformGate:B,queues:I,serverContent:k,storageRulesMetadata:z,usesSandbox:te,useUmbrella:C,workflows:T}=br({lunoraDirectory:r,project:o,projectRoot:e.projectRoot,schema:a,target:e.target}),h=f(r,"_generated"),$e=f(h,"dataModel.ts"),Ae=f(h,"server.ts");ut(o,$e,p),ut(o,Ae,k);const D=ls(o,r),Se=ws(o,r),be=Os(o,r),q=Hs(o,r),se=Ks(o,r),re=Ns(o,r,T,c),U=e.lint===!1?void 0:Ut({adminRoutes:Lr(o,r),aiRawRuns:Cr(o,r),aiToolSideEffects:Wr(o,r),argumentDerivedFetches:Qr(o,r),argumentValidators:cn(o,r),authApiCalls:vs(o,r),authConfigs:yn(o,r),browserUrlAccesses:vn(o,r),configCalls:Dn(o,r),containerKeyAccesses:kn(o,r),containerOverrides:qn(o,r),containers:l,exportSinks:Wn(o,r),failOpenGuards:Zn(o,r),flagSecurityDefaults:ni(o,r),geoIndexUsages:ai(o,r),httpActionGuards:mi(o,r),httpHeaderWrites:Ni(o,r),identityClaimReads:Di(o,r),imageDeliveryUrlAccesses:Ki(o,r),inserts:Is(o,r),kvKeyAccesses:Mi(o,r),mailRecipientAccesses:Vi(o,r),maskProcedures:Ts(o,r),maskStrategies:Fs(o,r),mutatorWrites:Ji(o,r),nondeterministicCalls:Rs(o,r),normalizeIdAuthorizations:po(o,r),notifyCalls:js(o,r),notifyConfig:Ms(o,r),ownerFieldWrites:Ao(o,r,D),unrestrictedWhereBranches:kc(o,r),paymentWebhooks:Po(o,r),privilegedDispatches:jo(o,r),procedureProtections:ba(o,r),queries:bs(o,r),queues:I,r2sqlCalls:zs(o,r),ratelimitKeySelectors:Fa(o,r),rawRowReturns:Ra(o,r),relationLoads:Ua(o,r),rlsProcedures:qs(o,r),schema:a,secretLiterals:Xa(o,r),shapes:q,softDeleteReads:sc(o,r),sqlInterpolations:uc(o,r),storageKeyAccesses:dc(o,r,D),storageUploads:Ec(o,r),vectorNamespaceAccesses:zc(o,r),workflowCalls:Uc(o,r),workflows:T,wranglerVariables:e.wranglerVariables}),ve=U===void 0?[]:[...qt(U,{source:"static"}),...Nc(o,r,D)],Dt=Bs(o,r),Ne=Ls(o,r);Hc(q,Ne,Ds(o,r));const Ot=O?Ps(o,r):[],V=hr(m,{containerCount:l.length,cronCount:re.length,dependencies:y,hasPaymentTables:mr(a.tables),queueCount:I.length,storageColumnCount:Object.keys(Ht(a)).length,storageRuleCount:z.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:T.length}),Pe=t?ue.now():0,we=Qt({agents:c,functions:D,httpRoutes:Se,mutators:se,useUmbrella:C,workflows:T}),Ie=Jt({agents:c,functions:D,migrations:be,mutators:se,shapes:q,useUmbrella:C,usesSandbox:te}),ne=sr(a,be.map(x=>x.id)),Te=Xt({advisories:ve,advisorProcedures:U?.procedureProtections??[],agents:c,containers:l,env:N,flagKeys:Ot,hasAccessFacade:m.access,hasAi:m.ai,hasAnalytics:m.analytics,hasBrowser:$,hasFlags:O,hasHyperdrive:m.hyperdrive,hasImages:m.images,hasKv:m.kv,hasNotify:M,hasPayments:m.payments,hasPipelines:m.pipelines,hasR2sql:m.r2sql,hasX402:m.x402,maskMetadata:Ne,mutators:se,queues:I,rlsMetadata:Dt,schema:a,schemaSnapshot:ne,shapes:q,storageRules:z,studioFeatures:V,useUmbrella:C,workflows:T}),Fe=Zt(q,y.has("@lunora/db"),C),Le=Yt(l,a.jurisdiction),De=es(T),Oe=ts(c),ke=ss(I),Ce=rs(re),Ke=ns(a.vectorIndexes),W=is(a,C),Re=os(y.has("@lunora/seed")),_=e.apiSpec??"openapi",ie=_==="openapi"||_==="both",oe=_==="openrpc"||_==="both",Me=Js({emailAgents:c.filter(x=>x.onEmail===!0).map(x=>({bindingName:x.bindingName,exportName:x.exportName})),hasAccess:y.has("@lunora/cloudflare-access"),hasAi:m.ai,hasAnalytics:m.analytics,hasAuth:y.has("@lunora/auth"),hasBrowser:$,hasFramework:y.has("@lunora/astro")||y.has("@lunora/svelte")||y.has("@lunora/vue"),hasGlobal:a.tables.some(x=>x.shardMode==="global"&&x.globalBackend!=="hyperdrive"),hasHyperdrive:m.hyperdrive,hasHyperdriveGlobal:a.tables.some(x=>x.shardMode==="global"&&x.globalBackend==="hyperdrive"),hasImages:m.images,hasKv:V.kv,hasNotify:M,hasPayments:m.payments,hasR2sql:m.r2sql,hasQueue:I.some(x=>x.mode==="push"),hasScheduler:V.scheduler,hasStorage:V.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:T.length>0,hasX402:m.x402,identity:j,jurisdiction:a.jurisdiction,useUmbrella:C,voiceAgents:c.filter(x=>x.voice===!0&&x.voiceBindingName!==void 0).map(x=>({bindingName:x.voiceBindingName,exportName:x.exportName})),wantsOpenApi:ie,wantsOpenRpc:oe}),je=Wc(e.projectRoot),ze=Xs({functions:D,httpRoutes:Se,version:je}),qe=Ys({functions:D,version:je}),Be=`${JSON.stringify(ze,void 0,2)}
|
|
8
|
+
`,Ue=`${JSON.stringify(qe,void 0,2)}
|
|
9
|
+
`,Ve=Zs(ze),We=er(qe),ae=f(r,Vc),kt=A(ae);if(e.dryRun||(A(h)||Mt(h,{recursive:!0}),S(f(h,"app.ts"),Me),S($e,p),S(f(h,"api.ts"),we),S(Ae,k),S(f(h,"functions.ts"),Ie),S(f(h,"shard.ts"),Te),S(f(h,"crons.ts"),Ce),S(f(h,"vectors.ts"),Ke),S(f(h,"drizzle.global.ts"),W.global),S(f(h,"drizzle.shard.ts"),W.shard),P(f(h,"containers.ts"),Le),P(f(h,"workflows.ts"),De),P(f(h,"agents.ts"),Oe),P(f(h,"queues.ts"),ke),P(f(h,"seed.ts"),Re),P(f(h,"collections.ts"),Fe),P(f(h,"openapi.json"),ie?Be:""),P(f(h,"openapi.ts"),ie?Ve:""),P(f(h,"openrpc.json"),oe?Ue:""),P(f(h,"openrpc.ts"),oe?We:""),(!kt||e.updateSchemaBaseline===!0)&&S(ae,Bt(ne))),t){const x=ue.now(),Ct=Math.round(x-s),Kt=Math.round(Pe-s),Rt=Math.round(x-Pe);console.error(`@lunora/codegen: codegen took ${Ct.toString()}ms (discovery ${Kt.toString()}ms, emit ${Rt.toString()}ms)`)}return{advisories:ve,advisorContext:U,agents:c,containers:l,cronTriggers:as(re),generated:{agents:Oe,api:we,app:Me,collections:Fe,containers:Le,crons:Ce,dataModel:p,drizzleGlobal:W.global,drizzleShard:W.shard,functions:Ie,openApi:Be,openApiModule:Ve,openRpc:Ue,openRpcModule:We,queues:ke,seed:Re,server:k,shard:Te,vectors:Ke,workflows:De},outputDirectory:h,platformDiagnostics:B.diagnostics,queues:I,schemaSnapshot:ne,schemaSnapshotPath:ae,workflows:T}};export{Vc as SCHEMA_SNAPSHOT_FILENAME,Qc as createCodegenProject,Mu as refreshCodegenProject,ju as runCodegen};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as
|
|
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{f as u}from"./parse-validator-CkLxY-Mr.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};
|
package/dist/packem_shared/{buildOpenApiDocument-Blf3mpIz.mjs → buildOpenApiDocument-Bw3MChvT.mjs}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{S as v}from"./emit-DMvG162j.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
2
|
`,W=e=>`${v}export const openApiSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
|
|
3
3
|
`;export{D as buildOpenApiDocument,U as emitOpenApi,W as emitOpenApiModule};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as r,SyntaxKind as c}from"ts-morph";import{listLunoraSourceFiles as E,lunoraRelativePath as P}from"./discoverFunctions-
|
|
1
|
+
import{Node as r,SyntaxKind as c}from"ts-morph";import{listLunoraSourceFiles as E,lunoraRelativePath as P}from"./discoverFunctions-BgGmxEqW.mjs";const p=e=>{if(e.getText()!=="args")return!1;const t=e.getParent();return r.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(r.isPropertyAssignment(t)&&t.getNameNode()===e)},x=e=>{if(e.getText()!=="ctx")return!1;const t=e.getParent();return r.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(r.isPropertyAssignment(t)&&t.getNameNode()===e)},d=e=>r.isIdentifier(e)?x(e):e.getDescendantsOfKind(c.Identifier).some(t=>x(t)),m=(e,t)=>{if(e.getText()!==t)return!1;const s=e.getParent();return r.isPropertyAccessExpression(s)&&s.getNameNode()===e?!1:!(r.isPropertyAssignment(s)&&s.getNameNode()===e)},A=e=>{let t=e;for(;r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t)||r.isNonNullExpression(t);)t=t.getExpression();return r.isIdentifier(t)?t:void 0},F=e=>{if(r.isIdentifier(e))return e.getText();if(r.isPropertyAccessExpression(e))return e.getName()},N=e=>r.isIdentifier(e)?p(e):e.getDescendantsOfKind(c.Identifier).some(t=>p(t)),a=e=>{if(!r.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(o=>r.isArrowFunction(o)||r.isFunctionExpression(o)||r.isFunctionDeclaration(o));if(s===void 0)return;const n=e.getStart();let i,g=-1;for(const o of s.getDescendantsOfKind(c.VariableDeclaration)){if(o.getName()!==t)continue;const f=o.getInitializer(),u=o.getStart();f!==void 0&&u<n&&u>g&&(i=f,g=u)}return i},T=e=>{if(N(e))return!0;const t=a(e);return t!==void 0&&N(t)},C=e=>{if(r.isCallExpression(e)||r.isNewExpression(e))return!1;const t=a(e);return t===void 0||!(r.isCallExpression(t)||r.isNewExpression(t))},O=e=>{if(d(e))return!0;const t=a(e);if(t!==void 0&&d(t))return!0;const s=t??e;return(r.isIdentifier(s)?[s]:s.getDescendantsOfKind(c.Identifier)).some(n=>{const i=a(n);return i!==void 0&&d(i)})},l=(e,t)=>r.isIdentifier(e)?m(e,t):e.getDescendantsOfKind(c.Identifier).some(s=>m(s,t)),L=(e,t)=>{if(l(e,t))return!0;const s=a(e);if(s!==void 0&&l(s,t))return!0;const n=A(e);if(n!==void 0){const i=a(n);return i!==void 0&&l(i,t)}return!1},y=e=>{for(const t of e.getAncestors())if(r.isVariableDeclaration(t)&&t.getVariableStatement()?.hasExportKeyword()===!0)return t.getName();return"<module>"},I=new Set(["withIndex","withSearchIndex"]),h=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||t.getName()!=="query")return!1;const s=t.getExpression();return r.isPropertyAccessExpression(s)?s.getName()==="db":r.isIdentifier(s)&&s.getText()==="db"},v=e=>{const t=[];let s=e;for(;;){const n=s.getParent();if(!n||!r.isPropertyAccessExpression(n))break;const i=n.getParent();if(!i||!r.isCallExpression(i))break;t.push(n.getName()),s=i}return t},S=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,b=e=>{let t=e;for(;;){const s=t.getParent();if(!s||!r.isPropertyAccessExpression(s))return!1;const n=s.getParent();if(!n||!r.isCallExpression(n))return!1;if(s.getName()==="filter"){const i=n.getArguments()[0];if(i&&S.test(i.getText()))return!0}t=n}},D=e=>{const t=e.getArguments()[0];return t&&r.isStringLiteral(t)?t.getLiteralText():""},q=(e,t)=>{const s=[];for(const n of E(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),g=P(t,n);for(const o of i.getDescendantsOfKind(c.CallExpression)){if(!h(o))continue;const f=v(o);f.includes("filter")&&s.push({exportName:y(o),file:g,filtersPrimaryKey:b(o),hasFilter:!0,hasIndex:f.some(u=>I.has(u)),line:o.getStartLineNumber(),table:D(o)})}}return s};export{O as a,C as b,F as c,L as d,y as e,l as f,T as i,N as r,a as s,q as y};
|
package/dist/packem_shared/{discoverAuthApiCalls-CVTXSguP.mjs → discoverAuthApiCalls-BgL6nj03.mjs}
RENAMED
|
@@ -1 +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-
|
|
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-BgGmxEqW.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as T}from"@lunora/errors";import{CRON_SCHEDULE_KINDS as b,isValidCronExpression as A,warnIfSecondsLeading as S,compileCronSchedule as O}from"@lunora/scheduler";import{SyntaxKind as m,Node as s}from"ts-morph";import{diagnosticAt as u,CodegenDiagnosticError as I}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{listLunoraSourceFiles as $}from"./discoverFunctions-
|
|
1
|
+
import{LunoraError as T}from"@lunora/errors";import{CRON_SCHEDULE_KINDS as b,isValidCronExpression as A,warnIfSecondsLeading as S,compileCronSchedule as O}from"@lunora/scheduler";import{SyntaxKind as m,Node as s}from"ts-morph";import{diagnosticAt as u,CodegenDiagnosticError as I}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{listLunoraSourceFiles as $}from"./discoverFunctions-BgGmxEqW.mjs";import{E as j}from"./module-specifiers-8FEEiUcv.mjs";import{n as y}from"./paths-BmX5O1sG.mjs";const R=new Set([...b,"cron"]),D=e=>{const t=e.getSymbol();if(!t)return e.getText()==="cronJobs";for(const r of t.getDeclarations())if(s.isImportSpecifier(r))return j(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="cronJobs":!1;return!1},P=e=>{const t=new Set;for(const r of e.getVariableDeclarations()){const n=r.getInitializer();if(n?.getKind()!==m.CallExpression)continue;const i=n.getExpression();s.isIdentifier(i)&&D(i)&&t.add(r.getName())}return t},V=e=>{let t=e;for(;s.isCallExpression(t)||s.isPropertyAccessExpression(t);)t=t.getExpression();return s.isIdentifier(t)?t.getText():void 0},L=(e,t)=>{const r=e.getArguments()[t];return r&&(s.isStringLiteral(r)||s.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},_=(e,t)=>{if(s.isStringLiteral(e)||s.isNoSubstitutionTemplateLiteral(e)||s.isNumericLiteral(e))return e.getLiteralValue();if(s.isTrueLiteral(e))return!0;if(s.isFalseLiteral(e))return!1;if(s.isPrefixUnaryExpression(e)&&e.getOperatorToken()===m.MinusToken){const r=e.getOperand();if(s.isNumericLiteral(r))return-r.getLiteralValue()}if(s.isObjectLiteralExpression(e))return g(e,t);if(s.isArrayLiteralExpression(e))return e.getElements().map(r=>_(r,t));throw u(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 n of e.getProperties()){if(!s.isPropertyAssignment(n))throw u(n,`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 i=n.getInitializer();i&&(r[n.getName()]=_(i,t))}return r},C=(e,t,r)=>{const n=e.getArguments()[t];if(!n||!s.isPropertyAccessExpression(n))throw u(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 i=n.getName(),o=n.getExpression();if(!s.isPropertyAccessExpression(o))throw u(n,`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 a=o.getName();return`${y(a)}:${i}`},h=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),x=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),w=(e,t,r,n,i,o)=>{const a=e.getExpression();if(!s.isIdentifier(a)||a.getText()!==t)return;const l=r.get(e.getName());if(l)return o(l);throw u(e,`Cron job "${n}" targets ${t}.${e.getName()}, but no such ${i} is declared in lunora/${i}s.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})},k=(e,t,r,n,i)=>{const o=e.getArguments()[t];if(o&&s.isPropertyAccessExpression(o)){const a=w(o,"workflows",n,r,"workflow",h);return a||w(o,"agents",i,r,"agent",x)||{functionPath:C(e,t,r)}}if(o&&s.isIdentifier(o)){const a=n.get(o.getText()),l=i.get(o.getText());if(a&&l)throw u(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(a)return h(a);if(l)return x(l);throw u(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:C(e,t,r)}},F=/^@lunora\/scheduler:\s*/u,v=(e,t)=>{const r=L(e,1);if(r===void 0)throw u(e,`Cron job "${t}" must pass a string-literal cron expression to ".cron(...)".`,{code:"CRON_EXPR_NOT_STATIC",name:"LunoraError",status:500});if(!A(r))throw u(e,`Cron job "${t}" has an invalid cron expression "${r}" — expected 5 or 6 space-separated fields.`,{code:"CRON_EXPR_INVALID",name:"LunoraError",status:500});return S(r,`cron expression for job "${t}"`),r},U=(e,t,r)=>{const n=e.getArguments()[1];if(!n||!s.isObjectLiteralExpression(n))throw u(e,`Cron job "${r}" must pass an object-literal schedule to ".${t}(...)".`,{code:"CRON_SCHEDULE_NOT_STATIC",name:"LunoraError",status:500});try{return O(t,g(n,r),r)}catch(i){if(i instanceof I)throw i;const o=i instanceof Error?i.message.replace(F,""):String(i);throw u(e,o,{code:"CRON_SCHEDULE_INVALID",name:"LunoraError",status:500})}},M=(e,t,r,n,i)=>{const o=t.getName();if(!R.has(o)||!r.has(V(t.getExpression())??""))return;const a=L(e,0);if(a===void 0||a.trim()==="")throw u(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});const l=o==="cron"?v(e,a):U(e,o,a),c=k(e,2,a,n,i),f=e.getArguments()[3];return{args:f&&s.isObjectLiteralExpression(f)?g(f,a):{},cron:l,name:a,...c}},z=e=>{const t=new Set;for(const r of e){if(t.has(r.name))throw new T("DUPLICATE_CRON_NAME",`Duplicate cron job name "${r.name}": cron names must be unique across the project.`,{status:500});t.add(r.name)}},Q=(e,t,r=[],n=[])=>{const i=$(t),o=[],a=new Map(r.map(c=>[c.exportName,c])),l=new Map(n.map(c=>[c.exportName,c]));for(const c of i){const f=e.getSourceFile(c)??e.addSourceFileAtPath(c),p=P(f);if(p.size!==0)for(const d of f.getDescendantsOfKind(m.CallExpression)){const N=d.getExpression();if(!s.isPropertyAccessExpression(N))continue;const E=M(d,N,p,a,l);E&&o.push(E)}}return o.sort((c,f)=>c.name.localeCompare(f.name)),z(o),o};export{Q 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 M,f as h}from"./parse-validator-CkLxY-Mr.mjs";import{n as R}from"./paths-BmX5O1sG.mjs";const m=new Set(["action","mutation","query","stream"]),P=/\bany\b(?!\s*(?:\?\s*)?:)/u,b=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,q=/^[A-Za-z_$][\w$]*$/u,H=e=>q.test(e)?e:JSON.stringify(e),W=/\.ts$/u,B=(e,t)=>z(e,t).split(U).join("/").replace(W,""),N={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},J={onConnect:"connect",onDisconnect:"disconnect"},K=_,S=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 K(n)?r.getNameNode().getText():void 0}},T=(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=S(i);if(r===void 0){if(t)return;const n=i.getSymbol()?.getValueDeclaration();if(n&&s.isVariableDeclaration(n)){const o=n.getInitializer();return o?T(o,!0):void 0}return}return m.has(r)?"public":N[r]?"internal":void 0},y=(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},Q=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=y(i,"scope"),n=E(i,"maxAge"),o=E(i,"staleWhileRevalidate"),a=y(i,"tag"),c=y(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},G=e=>{if(e===void 0||!s.isObjectLiteralExpression(e))return{};const t=Q(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 G(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="/_generated/",ee=(e,t,i)=>{const r=t.getSourceFile(),n=(a,c)=>r.getImportDeclarations().some(l=>l.getModuleSpecifierSourceFile()!==a?!1:l.getNamespaceImport()!==void 0||l.getNamedImports().some(f=>f.getName()===c)),o=a=>{const c=a.getSourceFile();if(c.isInNodeModules()||c.isDeclarationFile()||!s.isInterfaceDeclaration(a)&&!s.isTypeAliasDeclaration(a))return!1;const l=c.getFilePath();return l.includes(Y)?!1:l===i||n(c,a.getName())};return[e.getSymbol(),e.getAliasSymbol()].flatMap(a=>a?.getDeclarations()??[]).some(a=>o(a))},te=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,p=(e,t,i,r=new Set)=>r.has(e)?!1:(r.add(e),ee(e,t,i)||te(e).some(n=>p(n,t,i,r))?!0:I(e)?e.getProperties().some(n=>p(n.getTypeAtLocation(t),t,i,r)):!1),ie=(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())},re=8,ne=(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}[]`},se=(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(" | ")},oe=(e,t,i,r,n,o)=>{if(!I(e))return;const a=[];for(const c of e.getProperties()){const l=c.getTypeAtLocation(t),f=ie(c,l),L=f&&l.isUnion()?l.getUnionTypes().filter(d=>!d.isUndefined()):[l],x=[];for(const d of L){const v=o(d,t,i,r+1,n);if(v===void 0)return;x.push(v)}a.push(`${H(c.getName())}${f?"?":""}: ${x.join(" | ")}`)}return a.length>0?`{ ${a.join("; ")} }`:"{}"},g=(e,t,i,r,n)=>{if(r>re||n.has(e))return;if(!p(e,t,i))return e.getText(t);const o=new Set(n).add(e);return e.isArray()?ne(e,t,i,r,o,g):e.isUnion()?se(e,t,i,r,o,g):oe(e,t,i,r,o,g)},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 p(i,e,o)?g(i,e,o,0,new Set)??"unknown":n},Se=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 p(n,e,a)?g(n,e,a,0,new Set):o},ae=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)},ce=e=>{const t=e.getArguments()[0];return!t||!(s.isArrowFunction(t)||s.isFunctionExpression(t))?"unknown":k(t)},le=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},ue=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)?M(r):void 0}t=i.getExpression()}},ge=e=>{const t=e.getExpression();if(s.isPropertyAccessExpression(t)){const o=t.getName();if(!m.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=T(a);return c?{kind:o,receiver:a,visibility:c}:void 0}if(!s.isIdentifier(t))return;const i=S(t);if(!i)return;if(m.has(i))return{kind:i,visibility:"public"};const r=N[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,Te=e=>s.isPropertyAccessExpression(e)&&e.getName()==="db"||s.isIdentifier(e)&&e.getText()==="db",Ie=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():"",ke=(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},Fe=(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},F=(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;F(o,t,i)}else if(a.isFile()&&j(n)===".ts"){if(n==="schema.ts"&&e===i)continue;t.push(o)}}return t},fe=e=>{const t=ge(e);if(t){if(t.receiver){const i=Z(t.receiver),r=ue(t.receiver);return{args:le(t.receiver),...i?{expose:i}:{},kind:t.kind,...r?{output:r}:{},returnType:ce(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:ae(e),visibility:t.visibility}}},de=8,u=(e,t=0)=>{if(t>de)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?w(i,t+1):void 0},w=(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?w(r,t+1):void 0}},ye=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]]:[]},D=(e,t,i)=>{const r=fe(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}:{}}},me=(e,t)=>{const i=[];for(const r of e.getExportAssignments()){if(r.isExportEquals())continue;const n=u(r.getExpression()),o=n?D(n,"default",t):void 0;o&&i.push(o)}return i},xe=(e,t)=>{const i=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations())for(const[o,a]of ye(n)){const c=D(a,o,t);c&&i.push(c)}return i.push(...me(e,t)),i},ve=e=>{const t=new Map;for(const i of e){const r=R(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=F(t),r=[];for(const n of i){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),a=B(t,n);r.push(...xe(o,a))}return r.sort((n,o)=>`${n.filePath}:${n.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),ve(r),r};export{ke as chainHasStep,Fe as chainUsesWrappedCall,ge as classifyProcedureCall,we as discoverFunctions,A as inlineHandler,Te as isDatabaseAccessor,F as listLunoraSourceFiles,B as lunoraRelativePath,Ie as procedureHandler,Se as resolveStandardSchemaType,k as unwrapHandlerReturn};
|
package/dist/packem_shared/{discoverHttpRoutes-VyBQ9CbN.mjs → discoverHttpRoutes-eW8RbVOr.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{relative as m,sep as h}from"node:path";import{Node as a}from"ts-morph";import{listLunoraSourceFiles as
|
|
1
|
+
import{relative as m,sep as h}from"node:path";import{Node as a}from"ts-morph";import{listLunoraSourceFiles as f,unwrapHandlerReturn as l}from"./discoverFunctions-BgGmxEqW.mjs";import{s as d,f as g}from"./parse-validator-CkLxY-Mr.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()},b=r=>{const e=r.getArguments()[0];return e&&a.isObjectLiteralExpression(e)?g(e):{}},y=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=b(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=y(s);if(t)return o.method=t.method,o.path=t.path,o},C=r=>{const e=r.getArguments()[0];return!e||!(a.isArrowFunction(e)||a.isFunctionExpression(e))?"unknown":l(e)},$=(r,e,o,n)=>{const s=e.getName();if(!P.has(s))return;const t=S(r,s);if(!(t?.method===void 0||t.path===void 0))return{body:t.body,exportName:o,filePath:n,method:t.method,params:t.params,path:t.path,searchParams:t.searchParams,stream:t.stream,...t.stream?{chunkType:C(r)}:{},...t.output?{output:t.output}:{}}},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=$(t,i,s.getName(),e);p&&o.push(p)}return o},L=(r,e)=>{const o=f(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};
|
|
@@ -1 +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-
|
|
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-BgGmxEqW.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i,SyntaxKind as y}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as P,classifyProcedureCall as p}from"./discoverFunctions-
|
|
1
|
+
import{Node as i,SyntaxKind as y}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as P,classifyProcedureCall as p}from"./discoverFunctions-BgGmxEqW.mjs";const S=t=>{if(!i.isCallExpression(t))return!1;const s=t.getExpression();return i.isIdentifier(s)?s.getText()==="mask":i.isPropertyAccessExpression(s)?s.getName()==="mask":!1},f=t=>{if(i.isPropertyAssignment(t)||i.isShorthandPropertyAssignment(t)||i.isMethodDeclaration(t)||i.isGetAccessorDeclaration(t))return t.getName()},v=t=>{const s=t.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return[];const e=[];for(const r of s.getProperties()){const o=f(r);if(o===void 0||!i.isPropertyAssignment(r))continue;const n=r.getInitializer();if(!(!n||!i.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=f(a);c!==void 0&&e.push({column:c,table:o})}}return e},g=t=>{const s=[];let e=t;for(;i.isCallExpression(e);){const r=e.getExpression();if(!i.isPropertyAccessExpression(r))break;if(r.getName()==="use"){const o=e.getArguments()[0];o&&S(o)&&s.push(o)}e=r.getExpression()}return s},L=t=>{const s=g(t);return{maskColumns:s.flatMap(e=>v(e)),usesMask:s.length>0}},M=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),N=new Set(["delete","insert","patch","replace"]),x=(t,s)=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||!s.has(e.getName()))return!1;const r=e.getExpression();return i.isPropertyAccessExpression(r)?r.getName()==="db":i.isIdentifier(r)&&r.getText()==="db"},b=t=>{const s=t.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},k=t=>{const s=new Set,e=new Set;for(const r of t.getDescendantsOfKind(y.CallExpression))if(x(r,M)){const o=b(r);o!==""&&s.add(o)}else if(x(r,N)){const o=b(r);o!==""&&e.add(o)}return{tablesRead:[...s],tablesWritten:[...e]}},D=(t,s)=>{if(!i.isVariableDeclaration(t))return;const e=t.getInitializer();if(!e||!i.isCallExpression(e))return;const r=p(e);if(!r)return;const o=r.receiver?L(r.receiver):{maskColumns:[],usesMask:!1},{tablesRead:n,tablesWritten:a}=k(t);return{exportName:t.getName(),file:s,maskColumns:o.maskColumns,tablesRead:n,tablesWritten:a,usesMask:o.usesMask,visibility:r.visibility}},T=(t,s)=>{const e=[];for(const r of u(s)){const o=t.getSourceFile(r)??t.addSourceFileAtPath(r),n=P(s,r);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations()){const l=D(c,n);l&&e.push(l)}}return e},A=t=>{if(i.isPropertyAssignment(t)){const s=t.getInitializer();if(s&&i.isStringLiteral(s)){const e=s.getLiteralText();if(e==="redact"||e==="hash")return e}}return"custom"},C=t=>{const s=t.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return[];const e=[];for(const r of s.getProperties()){const o=f(r);if(o===void 0||!i.isPropertyAssignment(r))continue;const n=r.getInitializer();if(!(!n||!i.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=f(a);c!==void 0&&e.push({column:c,strategy:A(a),table:o})}}return e},h=t=>{const s=[];for(const e of t.getVariableStatements())if(e.isExported())for(const r of e.getDeclarations()){const o=r.getInitializer(),n=o&&i.isCallExpression(o)?p(o):void 0;n?.receiver&&s.push(n.receiver)}return s},R=(t,s)=>{const e=new Map;for(const r of u(s)){const o=t.getSourceFile(r)??t.addSourceFileAtPath(r);for(const n of h(o))for(const a of g(n))for(const c of C(a)){const l=`${c.table}\0${c.column}`;e.has(l)||e.set(l,c)}}return{columns:[...e.values()]}},F=(t,s,e)=>{const r=t.getArguments()[0];if(!r||!i.isObjectLiteralExpression(r))return[];const o=[];for(const n of r.getProperties()){const a=f(n);if(a===void 0||!i.isPropertyAssignment(n))continue;const c=n.getInitializer();if(!(!c||!i.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const d=f(l);if(d===void 0)continue;const m=A(l);m!=="custom"&&o.push({column:d,exportName:s,file:e,line:l.getStartLineNumber(),strategy:m,table:a})}}return o},I=(t,s)=>{if(!i.isVariableDeclaration(t))return[];const e=t.getInitializer(),r=e&&i.isCallExpression(e)?p(e):void 0;return r?.receiver?g(r.receiver).flatMap(o=>F(o,t.getName(),s)):[]},V=(t,s)=>{const e=[];for(const r of u(s)){const o=t.getSourceFile(r)??t.addSourceFileAtPath(r),n=P(s,r);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())e.push(...I(c,n))}return e},O=t=>i.isPropertyAssignment(t)||i.isMethodDeclaration(t)||i.isGetAccessorDeclaration(t)?i.isComputedPropertyName(t.getNameNode()):!1,j=t=>i.isPropertyAssignment(t)||i.isShorthandPropertyAssignment(t)||i.isMethodDeclaration(t)||i.isGetAccessorDeclaration(t)?O(t):!0,E=(t,s=!1)=>{for(const e of t.getProperties()){if(j(e))return!0;if(s)continue;if(!i.isPropertyAssignment(e))return!0;const r=e.getInitializer();if(!r||!i.isObjectLiteralExpression(r)||E(r,!0))return!0}return!1},$=(t,s)=>{for(const e of u(s)){const r=t.getSourceFile(e)??t.addSourceFileAtPath(e);for(const o of h(r))for(const n of g(o)){const a=n.getArguments()[0];if(a!==void 0&&(!i.isObjectLiteralExpression(a)||E(a)))return!0}}return!1};export{T as default,$ as discoverMaskHasNonLiteralPolicy,R as discoverMaskMetadata,V as discoverMaskStrategies};
|
package/dist/packem_shared/{discoverMigrations-CcOvlTA7.mjs → discoverMigrations-Cbc4W765.mjs}
RENAMED
|
@@ -1 +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-
|
|
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-BgGmxEqW.mjs";import{o as I}from"./module-specifiers-8FEEiUcv.mjs";const S=/\.ts$/u,b=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},x=(r,i)=>{const t=r.getInitializer();if(t?.getKind()!==m.CallExpression)return;const e=t.getExpression();if(!a.isIdentifier(e)||!b(e))return;const o=t.getArguments()[0];if(!o||!a.isObjectLiteralExpression(o))return;const n=f(o,"id"),s=r.getName();if(n===void 0||n.trim()==="")throw p(o,`Migration "${s}" in "${i}" must declare \`id\` as a non-empty string literal so codegen can key the registry.`,{code:"MIGRATION_ID_NOT_STATIC",name:"LunoraError",status:500});return{exportName:s,filePath:i,id:n,table:f(o,"table")??""}},M=r=>{const i=new Map;for(const t of r){const e=i.get(t.id);if(e!==void 0)throw Object.assign(new Error(`Duplicate migration id "${t.id}": declared in both "${e}" and "${t.filePath}". Migration ids must be unique across the project.`),{code:"DUPLICATE_MIGRATION_ID",id:t.id,name:"LunoraError",paths:[e,t.filePath],status:500});i.set(t.id,t.filePath)}},y=(r,i)=>{const t=h(i),e=[];for(const o of t){const n=r.getSourceFile(o)??r.addSourceFileAtPath(o),s=g(i,o).split(u).join("/").replace(S,"");for(const c of n.getVariableStatements())if(c.isExported())for(const d of c.getDeclarations()){const l=x(d,s);l&&e.push(l)}}return e.sort((o,n)=>o.id.localeCompare(n.id)),M(e),e};export{y as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as o,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as u,classifyProcedureCall as l}from"./discoverFunctions-
|
|
1
|
+
import{Node as o,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as u,classifyProcedureCall as l}from"./discoverFunctions-BgGmxEqW.mjs";const d={"crypto.getRandomValues":"crypto.getRandomValues","crypto.randomUUID":"crypto.randomUUID","Date.now":"Date.now","Math.random":"Math.random"},f=new Set(["globalThis","self"]),g=new Set(["globalThis","self","window"]),p=t=>{if(o.isIdentifier(t))return t.getText();if(o.isPropertyAccessExpression(t)){const e=t.getExpression();if(o.isIdentifier(e)&&g.has(e.getText()))return t.getName()}},m=t=>{const e=t.getExpression();if(o.isIdentifier(e)){const i=e.getText();return i==="fetch"||i==="Date"?i:void 0}if(!o.isPropertyAccessExpression(e))return;const r=e.getName(),n=p(e.getExpression());if(n!==void 0)return r==="fetch"&&f.has(n)?"fetch":d[`${n}.${r}`]},x=t=>{const e=t.getExpression();if(!o.isIdentifier(e)||e.getText()!=="Date")return;const r=t.getArguments(),n=r.every(i=>o.isNumericLiteral(i)||o.isStringLiteral(i)||o.isNoSubstitutionTemplateLiteral(i));return r.length>0&&n?void 0:"new Date"},h=(t,e)=>{if(e){const s=t.getArguments()[0];return s&&(o.isArrowFunction(s)||o.isFunctionExpression(s))?s:void 0}const r=t.getArguments()[0];if(!r||!o.isObjectLiteralExpression(r))return;const n=r.getProperty("handler");if(!n||!o.isPropertyAssignment(n))return;const i=n.getInitializer();return i&&(o.isArrowFunction(i)||o.isFunctionExpression(i))?i:void 0},N=t=>{const e=t.getInitializer();if(!e||!o.isCallExpression(e))return;const r=l(e);if(!r||r.kind!=="query"&&r.kind!=="mutation")return;const n=h(e,r.receiver);return n?{exportName:t.getName(),handler:n,kind:r.kind}:void 0},E=(t,e)=>{const r=[];for(const n of t.handler.getDescendantsOfKind(a.CallExpression)){const i=m(n);i!==void 0&&r.push({callee:i,exportName:t.exportName,file:e,kind:t.kind,line:n.getStartLineNumber()})}for(const n of t.handler.getDescendantsOfKind(a.NewExpression)){const i=x(n);i!==void 0&&r.push({callee:i,exportName:t.exportName,file:e,kind:t.kind,line:n.getStartLineNumber()})}return r},y=(t,e)=>{const r=[];for(const n of t.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const s=N(i);s&&r.push(...E(s,e))}return r},D=(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{D as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"ts-morph";import{y as p}from"./discover-queries-BmZeJ--u.mjs";import"./discoverFunctions-BgGmxEqW.mjs";export{p as default};
|