@lunora/codegen 1.0.0-alpha.73 → 1.0.0-alpha.74
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 +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{FLAGS_FILENAME-C1GWerCB.mjs → FLAGS_FILENAME-CQDN7BKc.mjs} +1 -1
- package/dist/packem_shared/{MUTATORS_FILENAME-BWPAtQ2T.mjs → MUTATORS_FILENAME-3Akvs4aT.mjs} +1 -1
- package/dist/packem_shared/{NOTIFY_FILENAME-DP6qvFBX.mjs → NOTIFY_FILENAME-B2lXWa7r.mjs} +1 -1
- package/dist/packem_shared/{SCHEMA_SNAPSHOT_FILENAME-WQ1drzwI.mjs → SCHEMA_SNAPSHOT_FILENAME-Bj7EusPY.mjs} +2 -2
- package/dist/packem_shared/buildOpenApiDocument-xYxqrlj1.mjs +3 -0
- package/dist/packem_shared/{discoverAuthApiCalls-Ba6W92HB.mjs → discoverAuthApiCalls-CEk3J0kc.mjs} +1 -1
- package/dist/packem_shared/{discoverCrons-2nUpw6do.mjs → discoverCrons-kIgM9ZJC.mjs} +1 -1
- package/dist/packem_shared/discoverFunctions-DnqHgv0t.mjs +1 -0
- package/dist/packem_shared/{discoverHttpRoutes-Bf_T_03b.mjs → discoverHttpRoutes-CLn3VDRI.mjs} +1 -1
- package/dist/packem_shared/{discoverInserts-DveVeP5h.mjs → discoverInserts-Cn-CLKET.mjs} +1 -1
- package/dist/packem_shared/{discoverMaskProcedures-BkBquCFR.mjs → discoverMaskProcedures-fZtvsy8v.mjs} +1 -1
- package/dist/packem_shared/{discoverMigrations-T2xb-1rn.mjs → discoverMigrations-BH_IKdFk.mjs} +1 -1
- package/dist/packem_shared/{discoverNondeterministicCalls-BymnOR9k.mjs → discoverNondeterministicCalls-Cl7qNL0J.mjs} +1 -1
- package/dist/packem_shared/{discoverQueries-DNRA-G2a.mjs → discoverQueries-DENx_T6c.mjs} +1 -1
- package/dist/packem_shared/{discoverR2sqlCalls-YEjvGcEq.mjs → discoverR2sqlCalls-CMNfDWlq.mjs} +1 -1
- package/dist/packem_shared/{discoverRlsMetadata-DO3qlLXX.mjs → discoverRlsMetadata-Bf4_2S0t.mjs} +1 -1
- package/dist/packem_shared/{discoverSandboxUsage-JwrmSN9l.mjs → discoverSandboxUsage-Bn1X9COt.mjs} +1 -1
- package/dist/packem_shared/{discoverStorageRulesMetadata-CCztRKjw.mjs → discoverStorageRulesMetadata-CL8J41rX.mjs} +1 -1
- package/package.json +3 -3
- package/dist/packem_shared/buildOpenApiDocument-CXFC-wzM.mjs +0 -3
- package/dist/packem_shared/discoverFunctions-zrIQk7J8.mjs +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -246,6 +246,18 @@ interface SchemaIR {
|
|
|
246
246
|
/** All vector indexes (inline Shape A hoisted + standalone Shape B), flattened. */
|
|
247
247
|
vectorIndexes: ReadonlyArray<VectorIndexIR>;
|
|
248
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Statically-read mirror of `@lunora/server`'s `RestCacheConfig`. Every field is
|
|
251
|
+
* optional because discovery only records literals it could actually read off the
|
|
252
|
+
* `.expose({ cache: … })` object.
|
|
253
|
+
*/
|
|
254
|
+
interface ExposeCacheIR {
|
|
255
|
+
maxAge?: number;
|
|
256
|
+
scope?: "private" | "public";
|
|
257
|
+
staleWhileRevalidate?: number;
|
|
258
|
+
tag?: string;
|
|
259
|
+
vary?: string;
|
|
260
|
+
}
|
|
249
261
|
interface FunctionIR {
|
|
250
262
|
args: Record<string, ValidatorIR>;
|
|
251
263
|
exportName: string;
|
|
@@ -255,8 +267,14 @@ interface FunctionIR {
|
|
|
255
267
|
* OpenAPI emitter describes it as a real `/_lunora/rest/<namespace>/<fn>` path
|
|
256
268
|
* (the single source of truth the runtime router also derives from). Absent →
|
|
257
269
|
* RPC-only (the default; not on the REST surface).
|
|
270
|
+
*
|
|
271
|
+
* `cache` mirrors the `RestCacheConfig` the runtime turns into response
|
|
272
|
+
* headers, so the emitted spec can document the `Cache-Control` a caller will
|
|
273
|
+
* actually observe. Only statically-readable literal fields are carried; a
|
|
274
|
+
* computed value is simply absent (the spec under-documents rather than lies).
|
|
258
275
|
*/
|
|
259
276
|
expose?: {
|
|
277
|
+
cache?: ExposeCacheIR;
|
|
260
278
|
rest?: boolean;
|
|
261
279
|
};
|
|
262
280
|
/** Path relative to `<projectRoot>/lunora/` without extension, e.g. "messages". */
|
package/dist/index.d.ts
CHANGED
|
@@ -246,6 +246,18 @@ interface SchemaIR {
|
|
|
246
246
|
/** All vector indexes (inline Shape A hoisted + standalone Shape B), flattened. */
|
|
247
247
|
vectorIndexes: ReadonlyArray<VectorIndexIR>;
|
|
248
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Statically-read mirror of `@lunora/server`'s `RestCacheConfig`. Every field is
|
|
251
|
+
* optional because discovery only records literals it could actually read off the
|
|
252
|
+
* `.expose({ cache: … })` object.
|
|
253
|
+
*/
|
|
254
|
+
interface ExposeCacheIR {
|
|
255
|
+
maxAge?: number;
|
|
256
|
+
scope?: "private" | "public";
|
|
257
|
+
staleWhileRevalidate?: number;
|
|
258
|
+
tag?: string;
|
|
259
|
+
vary?: string;
|
|
260
|
+
}
|
|
249
261
|
interface FunctionIR {
|
|
250
262
|
args: Record<string, ValidatorIR>;
|
|
251
263
|
exportName: string;
|
|
@@ -255,8 +267,14 @@ interface FunctionIR {
|
|
|
255
267
|
* OpenAPI emitter describes it as a real `/_lunora/rest/<namespace>/<fn>` path
|
|
256
268
|
* (the single source of truth the runtime router also derives from). Absent →
|
|
257
269
|
* RPC-only (the default; not on the REST surface).
|
|
270
|
+
*
|
|
271
|
+
* `cache` mirrors the `RestCacheConfig` the runtime turns into response
|
|
272
|
+
* headers, so the emitted spec can document the `Cache-Control` a caller will
|
|
273
|
+
* actually observe. Only statically-readable literal fields are carried; a
|
|
274
|
+
* computed value is simply absent (the spec under-documents rather than lies).
|
|
258
275
|
*/
|
|
259
276
|
expose?: {
|
|
277
|
+
cache?: ExposeCacheIR;
|
|
260
278
|
rest?: boolean;
|
|
261
279
|
};
|
|
262
280
|
/** Path relative to `<projectRoot>/lunora/` without extension, e.g. "messages". */
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{formatAdvisories as t,lintSchema as s}from"./packem_shared/formatAdvisories-DZvv-0MG.mjs";import{CodegenDiagnosticError as i,diagnosticAt as m}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as f,discoverAgents as p}from"./packem_shared/AGENTS_FILENAME-BesaDYkL.mjs";import{default as n}from"./packem_shared/discoverAuthApiCalls-
|
|
1
|
+
import{formatAdvisories as t,lintSchema as s}from"./packem_shared/formatAdvisories-DZvv-0MG.mjs";import{CodegenDiagnosticError as i,diagnosticAt as m}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as f,discoverAgents as p}from"./packem_shared/AGENTS_FILENAME-BesaDYkL.mjs";import{default as n}from"./packem_shared/discoverAuthApiCalls-CEk3J0kc.mjs";import{CONTAINERS_FILENAME as l,discoverContainers as E}from"./packem_shared/CONTAINERS_FILENAME-CFwdyaCI.mjs";import{default as u}from"./packem_shared/discoverCrons-kIgM9ZJC.mjs";import{FLAGS_FILENAME as v,discoverFlags as N}from"./packem_shared/FLAGS_FILENAME-CQDN7BKc.mjs";import{discoverFunctions as M}from"./packem_shared/discoverFunctions-DnqHgv0t.mjs";import{default as h}from"./packem_shared/discoverHttpRoutes-CLn3VDRI.mjs";import{default as _}from"./packem_shared/discoverInserts-Cn-CLKET.mjs";import{default as g}from"./packem_shared/discoverMaskProcedures-fZtvsy8v.mjs";import{default as F}from"./packem_shared/discoverMigrations-BH_IKdFk.mjs";import{MUTATORS_FILENAME as P,discoverMutators as D}from"./packem_shared/MUTATORS_FILENAME-3Akvs4aT.mjs";import{default as H}from"./packem_shared/discoverNondeterministicCalls-Cl7qNL0J.mjs";import{NOTIFY_FILENAME as G,discoverNotifyCalls as W,discoverNotifyConfig as V}from"./packem_shared/NOTIFY_FILENAME-B2lXWa7r.mjs";import{default as w}from"./packem_shared/discoverQueries-DENx_T6c.mjs";import{QUEUES_FILENAME as z,discoverQueues as Q}from"./packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs";import{default as B}from"./packem_shared/discoverR2sqlCalls-CMNfDWlq.mjs";import{discoverRlsMetadata as K,default as q}from"./packem_shared/discoverRlsMetadata-Bf4_2S0t.mjs";import{discoverSandboxUsage as X}from"./packem_shared/discoverSandboxUsage-Bn1X9COt.mjs";import{default as $}from"./packem_shared/discoverSchema-Cy4OQ0Cu.mjs";import{SHAPES_FILENAME as oe,discoverShapes as re}from"./packem_shared/SHAPES_FILENAME-maut3z1K.mjs";import{default as se}from"./packem_shared/discoverStorageRulesMetadata-CL8J41rX.mjs";import{WORKFLOWS_FILENAME as ie,discoverWorkflows as me}from"./packem_shared/WORKFLOWS_FILENAME-Bk5upkGM.mjs";import{w as fe,B as pe,s as ce,c as ne,_ as Se,t as le,G as Ee,e as xe,b as ue,h as Ae,J as ve,n as Ne,M as Oe,r as Me}from"./packem_shared/emit-D7VIjvlm.mjs";import{emitApp as he}from"./packem_shared/emitApp-CAeIj6e_.mjs";import{buildOpenApiDocument as _e,emitOpenApi as Ie,emitOpenApiModule as ge}from"./packem_shared/buildOpenApiDocument-xYxqrlj1.mjs";import{OPENRPC_VERSION as Fe,buildOpenRpcDocument as Te,emitOpenRpc as Pe,emitOpenRpcModule as De}from"./packem_shared/OPENRPC_VERSION-CvVFqUlq.mjs";import{SCHEMA_SNAPSHOT_FILENAME as He,createCodegenProject as be,refreshCodegenProject as Ge,runCodegen as We}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-Bj7EusPY.mjs";import{SCHEMA_SNAPSHOT_VERSION as ke,SchemaSnapshotParseError as we,buildSchemaSnapshot as ye,diffSchemaSnapshots as ze,evaluateSchemaDrift as Qe,parseSchemaSnapshot as je,serializeSchemaSnapshot as Be}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-Bpf1FGMG.mjs";import{schemaFromIr as Ke}from"./packem_shared/schemaFromIr-R1ZFzVyy.mjs";import{LUNORA_ERROR_CODES as Ye,validatorIrToJsonSchema as Xe}from"./packem_shared/LUNORA_ERROR_CODES-Um9hC1gr.mjs";import{redact as $e,secretKindOf as eo}from"./packem_shared/redact-CQ8-to6l.mjs";import{MESSAGE_SOLUTIONS as ro,findSolutionByMessage as to}from"@lunora/errors";const e="0.0.0";export{f as AGENTS_FILENAME,l as CONTAINERS_FILENAME,i as CodegenDiagnosticError,v as FLAGS_FILENAME,fe as GENERATED_HEADER,Ye as LUNORA_ERROR_CODES,ro as LUNORA_SOLUTION_RULES,P as MUTATORS_FILENAME,G as NOTIFY_FILENAME,Fe as OPENRPC_VERSION,z as QUEUES_FILENAME,He as SCHEMA_SNAPSHOT_FILENAME,ke as SCHEMA_SNAPSHOT_VERSION,oe as SHAPES_FILENAME,we as SchemaSnapshotParseError,e as VERSION,ie as WORKFLOWS_FILENAME,_e as buildOpenApiDocument,Te as buildOpenRpcDocument,ye as buildSchemaSnapshot,be as createCodegenProject,m as diagnosticAt,ze as diffSchemaSnapshots,p as discoverAgents,n as discoverAuthApiCalls,E as discoverContainers,u as discoverCrons,N as discoverFlags,M as discoverFunctions,h as discoverHttpRoutes,_ as discoverInserts,g as discoverMaskProcedures,F as discoverMigrations,D as discoverMutators,H as discoverNondeterministicCalls,W as discoverNotifyCalls,V as discoverNotifyConfig,w as discoverQueries,Q as discoverQueues,B as discoverR2sqlCalls,K as discoverRlsMetadata,q as discoverRlsProcedures,X as discoverSandboxUsage,$ as discoverSchema,re as discoverShapes,se as discoverStorageRulesMetadata,me as discoverWorkflows,pe as emitAgents,ce as emitApi,he as emitApp,ne as emitCollections,Se as emitContainers,le as emitCrons,Ee as emitDataModel,xe as emitDrizzleSchema,ue as emitFunctions,Ie as emitOpenApi,ge as emitOpenApiModule,Pe as emitOpenRpc,De as emitOpenRpcModule,Ae as emitServer,ve as emitShard,Ne as emitVectors,Oe as emitWorkflows,Me as emitWranglerCronTriggers,Qe as evaluateSchemaDrift,to as findLunoraSolution,t as formatAdvisories,s as lintSchema,je as parseSchemaSnapshot,$e as redact,Ge as refreshCodegenProject,We as runCodegen,Ke as schemaFromIr,eo as secretKindOf,Be as serializeSchemaSnapshot,Xe as validatorIrToJsonSchema};
|
|
@@ -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-DnqHgv0t.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};
|
package/dist/packem_shared/{MUTATORS_FILENAME-BWPAtQ2T.mjs → MUTATORS_FILENAME-3Akvs4aT.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-DnqHgv0t.mjs";import{t as d}from"./module-specifiers-8FEEiUcv.mjs";import{d as x}from"./parse-validator-CSDlMEvE.mjs";const y="mutators.ts",f=d,N=r=>{const e=r.getSymbol();if(!e)return r.getText()==="defineMutator";for(const t of e.getDeclarations())if(o.isImportSpecifier(t))return f(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMutator":!1;return!1},E=r=>{const e=r.getSymbol();if(!e)return!1;for(const t of e.getDeclarations()){if(!o.isNamespaceImport(t))continue;const i=t.getFirstAncestorByKind(c.ImportDeclaration);return i!==void 0&&f(i.getModuleSpecifierValue())}return!1},I=r=>{if(o.isIdentifier(r))return N(r);if(o.isPropertyAccessExpression(r)){const e=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(e)&&E(e)}return!1},S=r=>{const e=r.getArguments()[0];return e&&o.isObjectLiteralExpression(e)?e:void 0},A=r=>{const e=r?.getProperty("args");if(!e||!o.isPropertyAssignment(e))return{};const t=e.getInitializer();return t&&o.isObjectLiteralExpression(t)?x(t):{}},M=r=>{const e=r?.getProperty("server");if(!e||!o.isPropertyAssignment(e))return"unknown";const t=e.getInitializer();return!t||!(o.isArrowFunction(t)||o.isFunctionExpression(t))?"unknown":g(t)},P=r=>{const e=[];for(const t of r.getVariableDeclarations()){if(!t.isExported())continue;const i=t.getInitializer();if(i?.getKind()!==c.CallExpression)continue;const n=i,a=n.getExpression();if(!I(a))continue;const s=t.getNameNode();if(!o.isIdentifier(s))throw l(s,"defineMutator exports must be plain named exports (no destructuring)");const u=S(n);e.push({args:A(u),exportName:s.getText(),filePath:"mutators",returnType:M(u)})}return e},j=(r,e)=>{const t=m(e,y);if(!p(t))return[];const i=r.getSourceFile(t)??r.addSourceFileAtPath(t),n=P(i);return n.sort((a,s)=>a.exportName.localeCompare(s.exportName)),n};export{y as MUTATORS_FILENAME,j as discoverMutators,I as isDefineMutatorCallee};
|
|
@@ -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-DnqHgv0t.mjs";const E="notify.ts",A=new Set(["chat","inApp","send","webhook"]),d=new Set(["broadcast","send"]),P=(t,r)=>{if(r){const n=t.getArguments()[0];return n&&(o.isArrowFunction(n)||o.isFunctionExpression(n))?n:void 0}const e=t.getArguments()[0];if(!e||!o.isObjectLiteralExpression(e))return;const s=e.getProperty("handler");if(!s||!o.isPropertyAssignment(s))return;const i=s.getInitializer();return i&&(o.isArrowFunction(i)||o.isFunctionExpression(i))?i:void 0},F=t=>{const r=t.getInitializer();if(!r||!o.isCallExpression(r))return;const e=y(r);if(!e)return;const s=P(r,e.receiver);return s?{exportName:t.getName(),handler:s,kind:e.kind}:void 0},g=t=>{const r=[];for(const e of t.getVariableStatements())if(e.isExported())for(const s of e.getDeclarations()){const i=F(s);i&&r.push(i)}return r},f=t=>{if(!o.isPropertyAccessExpression(t))return;const r=t.getName(),e=t.getExpression();if((r==="notify"||r==="push")&&o.isIdentifier(e)&&e.getText()==="ctx")return r;if(r==="push"&&f(e)==="notify")return"push"},S=t=>{if(!o.isPropertyAccessExpression(t))return;const r=t.getName(),e=f(t.getExpression());if(e==="notify"&&A.has(r))return`ctx.notify.${r}`;if(e==="push"&&d.has(r))return`ctx.push.${r}`},N=t=>o.isPropertyAccessExpression(t)?f(t.getExpression())==="push"&&d.has(t.getName()):!1,D=(t,r)=>{const e=[];for(const s of l(r)){const i=t.getSourceFile(s)??t.addSourceFileAtPath(s),n=m(r,s);for(const c of g(i))if(!(c.kind!=="query"&&c.kind!=="mutation"))for(const a of c.handler.getDescendantsOfKind(p.PropertyAccessExpression)){const u=S(a);u!==void 0&&e.push({callee:u,exportName:c.exportName,file:n,kind:c.kind,line:a.getStartLineNumber()})}}return e},b=(t,r)=>{for(const e of l(r)){const s=t.getSourceFile(e)??t.addSourceFileAtPath(e);for(const i of g(s))for(const n of i.handler.getDescendantsOfKind(p.PropertyAccessExpression))if(N(n))return!0}return!1},v=t=>{const r=t.getExportAssignment(i=>!i.isExportEquals());if(!r)return;const e=r.getExpression();if(!o.isIdentifier(e))return e;const s=e.getSymbol()?.getValueDeclaration();return s&&o.isVariableDeclaration(s)?s.getInitializer():e},L=(t,r)=>{const e=h(r,E);if(!x(e))return;const s=t.getSourceFile(e)??t.addSourceFileAtPath(e),i=v(s);let n=!1,c=!1;if(i&&o.isCallExpression(i)){const a=i.getArguments()[0];a&&o.isObjectLiteralExpression(a)&&(n=a.getProperty("webPush")!==void 0,c=a.getProperty("fcm")!==void 0)}return{hasFcm:c,hasWebPush:n,usesPush:b(t,r)}};export{E as NOTIFY_FILENAME,D as discoverNotifyCalls,L as discoverNotifyConfig};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{existsSync as E,readFileSync as Ae,mkdirSync as Bt,writeFileSync as Vt,rmSync as Ut}from"node:fs";import{join as g,dirname as ge}from"node:path";import{performance as fe}from"node:perf_hooks";import{LunoraError as q}from"@lunora/errors";import{Node as i,SyntaxKind as u,Project as Xe}from"ts-morph";import{lintSchema as Wt}from"./formatAdvisories-DZvv-0MG.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as f,classifyProcedureCall as K,inlineHandler as Gt,procedureHandler as mt,chainUsesWrappedCall as xt,isDatabaseAccessor as k,chainHasStep as _t,discoverFunctions as Ht}from"./discoverFunctions-zrIQk7J8.mjs";import{discoverAgents as Jt}from"./AGENTS_FILENAME-BesaDYkL.mjs";import Qt from"./discoverAuthApiCalls-Ba6W92HB.mjs";import{discoverContainers as Xt}from"./CONTAINERS_FILENAME-CFwdyaCI.mjs";import Zt from"./discoverCrons-2nUpw6do.mjs";import{diagnosticAt as _}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{o as H}from"./module-specifiers-8FEEiUcv.mjs";import{a as pe,d as Yt,G as es,s as ts,h as ss,b as rs,J as ns,c as is,_ as os,M as as,B as cs,j as us,t as ls,n as ds,e as gs,l as fs,r as ps}from"./emit-D7VIjvlm.mjs";import{discoverFlagKeys as ms}from"./FLAGS_FILENAME-C1GWerCB.mjs";import xs from"./discoverHttpRoutes-Bf_T_03b.mjs";import hs from"./discoverInserts-DveVeP5h.mjs";import Es,{discoverMaskStrategies as ys,discoverMaskMetadata as As}from"./discoverMaskProcedures-BkBquCFR.mjs";import $s from"./discoverMigrations-T2xb-1rn.mjs";import{MUTATORS_FILENAME as Ss,isDefineMutatorCallee as Ns,discoverMutators as vs}from"./MUTATORS_FILENAME-BWPAtQ2T.mjs";import bs from"./discoverNondeterministicCalls-BymnOR9k.mjs";import{discoverNotifyConfig as Ps,discoverNotifyCalls as ws}from"./NOTIFY_FILENAME-DP6qvFBX.mjs";import Is from"./discoverQueries-DNRA-G2a.mjs";import{discoverQueues as Os}from"./QUEUES_FILENAME-CSE6i-ld.mjs";import Ls from"./discoverR2sqlCalls-YEjvGcEq.mjs";import Fs,{discoverRlsMetadata as Ts}from"./discoverRlsMetadata-DO3qlLXX.mjs";import{discoverSandboxUsage as Ds}from"./discoverSandboxUsage-JwrmSN9l.mjs";import Cs from"./discoverSchema-Cy4OQ0Cu.mjs";import{secretKindOf as ks,redact as Ks}from"./redact-CQ8-to6l.mjs";import{discoverShapes as Rs}from"./SHAPES_FILENAME-maut3z1K.mjs";import Ms from"./discoverStorageRulesMetadata-CCztRKjw.mjs";import{e as js}from"./discover-ast-CezKqEhE.mjs";import{discoverWorkflows as zs}from"./WORKFLOWS_FILENAME-Bk5upkGM.mjs";import{emitApp as qs}from"./emitApp-CAeIj6e_.mjs";import{buildOpenApiDocument as Bs,emitOpenApiModule as Vs}from"./buildOpenApiDocument-CXFC-wzM.mjs";import{buildOpenRpcDocument as Us,emitOpenRpcModule as Ws}from"./OPENRPC_VERSION-CvVFqUlq.mjs";import{buildSchemaSnapshot as Gs,serializeSchemaSnapshot as _s}from"./SCHEMA_SNAPSHOT_VERSION-Bpf1FGMG.mjs";const ht=new Set(["delete","get","head","options","patch","post","put"]),Hs=new Set(["handler","stream"]),Js=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,Ze=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Qs=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ht.has(t.getName()))return;const s=t.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpRoute")return;const r=e.getArguments()[0];if(!(!r||!i.isStringLiteral(r)))return{method:t.getName().toUpperCase(),path:r.getLiteralValue()}},Xs=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||ht.has(r.getName()))break;s=r.getExpression()}return Qs(s)},Zs=e=>{for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression))if(Ze.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&Ze.has(s.getText()))return!0}return!1},Ys=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||!Hs.has(r.getName()))return;const n=Xs(s);if(!n||!Js.test(n.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&Zs(o);return{exportName:e.getName(),file:t,method:n.method,path:n.path,usesGuard:a}},er=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Ys(n,t);o&&s.push(o)}return s},tr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...er(n,f(t,r)))}return s},Ye=e=>{if(e.getText()!=="args")return!1;const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(i.isPropertyAssignment(t)&&t.getNameNode()===e)},et=e=>{if(e.getText()!=="ctx")return!1;const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(i.isPropertyAssignment(t)&&t.getNameNode()===e)},me=e=>i.isIdentifier(e)?et(e):e.getDescendantsOfKind(u.Identifier).some(t=>et(t)),tt=(e,t)=>{if(e.getText()!==t)return!1;const s=e.getParent();return i.isPropertyAccessExpression(s)&&s.getNameNode()===e?!1:!(i.isPropertyAssignment(s)&&s.getNameNode()===e)},sr=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t:void 0},S=e=>{if(i.isIdentifier(e))return e.getText();if(i.isPropertyAccessExpression(e))return e.getName()},Ee=e=>i.isIdentifier(e)?Ye(e):e.getDescendantsOfKind(u.Identifier).some(t=>Ye(t)),L=e=>{if(!i.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a));if(s===void 0)return;const r=e.getStart();let n,o=-1;for(const a of s.getDescendantsOfKind(u.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<r&&l>o&&(n=c,o=l)}return n},w=e=>{if(Ee(e))return!0;const t=L(e);return t!==void 0&&Ee(t)},T=e=>{if(me(e))return!0;const t=L(e);if(t!==void 0&&me(t))return!0;const s=t??e;return(i.isIdentifier(s)?[s]:s.getDescendantsOfKind(u.Identifier)).some(r=>{const n=L(r);return n!==void 0&&me(n)})},B=(e,t)=>i.isIdentifier(e)?tt(e,t):e.getDescendantsOfKind(u.Identifier).some(s=>tt(s,t)),rr=(e,t)=>{if(B(e,t))return!0;const s=L(e);if(s!==void 0&&B(s,t))return!0;const r=sr(e);if(r!==void 0){const n=L(r);return n!==void 0&&B(n,t)}return!1},h=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)&&t.getVariableStatement()?.hasExportKeyword()===!0)return t.getName();return"<module>"},nr=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",ir=(e,t)=>{if(!nr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)||T(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},or=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ir(r,t);n&&s.push(n)}return s},ar=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...or(n,f(t,r)))}return s},cr=new Set(["generateText","streamText"]),ur=new Set(["messages","prompt","system"]),lr=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],dr=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),r=t.getExpression().getText();for(const n of lr)if(n.methods.has(s)&&n.prefixes.some(o=>r===o||r.startsWith(`${o}.`)))return`${r}.${s}`},gr=e=>{for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=dr(t);if(s!==void 0)return s}},fr=e=>{const t=new Set,s=e.getFirstAncestor(o=>i.isArrowFunction(o)||i.isFunctionExpression(o)||i.isFunctionDeclaration(o)),[r]=s?.getParameters()??[],n=r?.getNameNode();if(n===void 0||!i.isObjectBindingPattern(n))return t;for(const o of n.getElements()){const a=o.getPropertyNameNode()?.getText()??o.getName(),c=o.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},pr=e=>{if(Ee(e))return!0;const t=fr(e);return t.size===0?!1:e.getDescendantsOfKind(u.Identifier).some(s=>t.has(s.getText()))},mr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!ur.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&pr(s))return!0}return!1},xr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());if(n===void 0||!cr.has(n))continue;const[o]=r.getArguments();if(o===void 0||!i.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(u.CallExpression))if(S(c.getExpression())==="tool"&&(a=gr(c),a!==void 0))break;a!==void 0&&s.push({exportName:h(r),file:t,line:r.getStartLineNumber(),method:n,sideEffect:a,userInputDerived:mr(o)})}return s},hr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...xr(n,f(t,r)))}return s},Er=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},yr=(e,t)=>{if(!Er(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},Ar=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=yr(r,t);n&&s.push(n)}return s},$r=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ar(n,f(t,r)))}return s},Et=e=>e.getProperties().some(t=>i.isSpreadAssignment(t)),Sr=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const r=s.getInitializer();return!r||!i.isObjectLiteralExpression(r)?{objects:[],opaque:!0}:{objects:[r],opaque:Et(r)}},Nr=e=>{const t=[];let s=!1,r=e;for(;i.isCallExpression(r);){const n=r.getExpression();if(!i.isPropertyAccessExpression(n))break;if(n.getName()==="input"){const o=r.getArguments()[0];o&&i.isObjectLiteralExpression(o)?(t.push(o),s||=Et(o)):s=!0}r=n.getExpression()}return{objects:t,opaque:s}},yt=(e,t)=>t?Nr(t):Sr(e),vr=e=>e.flatMap(t=>t.getProperties().filter(s=>i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)).map(s=>s.getName())),br=/\.check\(|\.meta\(|length|max/iu,Pr=/\bv\.any\s*\(/u,wr=/\bv\.string\s*\(/u,Ir=e=>Pr.test(e),Or=e=>wr.test(e)&&!br.test(e),Lr=e=>{const t=[],s=[];for(const r of e)for(const n of r.getProperties()){if(!i.isPropertyAssignment(n))continue;const o=n.getInitializer();if(!o)continue;const a=o.getText(),c=n.getName();Ir(a)?t.push(c):Or(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Fr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=K(s);if(r?.visibility!=="public")return;const{objects:n}=yt(s,r.receiver),{anyArgs:o,unboundedStringArgs:a}=Lr(n);if(!(o.length===0&&a.length===0))return{anyArgs:o,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Tr=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Fr(n,t);o&&s.push(o)}return s},Dr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Tr(n,f(t,r)))}return s},N=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},xe=e=>e?.getKind()===u.TrueKeyword,Cr=e=>e?.getKind()===u.FalseKeyword,kr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Kr=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Rr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&S(t.getExpression())==="scim"),Mr=e=>e!==void 0&&i.isCallExpression(e)&&Kr.has(S(e.getExpression())??""),jr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),zr=e=>{const t=N(e,"advanced"),s=N(e,"emailAndPassword"),r=N(e,"session");return{analyzable:!0,disableCsrfCheck:xe(N(t,"disableCSRFCheck")),emailPasswordEnabled:xe(N(s,"enabled")),requireEmailVerification:xe(N(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Rr(N(e,"plugins"))&&Mr(N(e,"database")),secureCookiesDisabled:Cr(N(t,"useSecureCookies")),sessionFreshAgeZero:kr(N(r,"freshAge")),trustedOriginsWildcard:jr(N(e,"trustedOrigins"))}},qr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Br=(e,t)=>{if(S(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],r=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(o=>i.isSpreadAssignment(o)),n=s!==void 0&&i.isObjectLiteralExpression(s)&&!r?zr(s):qr();return{exportName:h(e),file:t,line:e.getStartLineNumber(),...n}},Vr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Br(r,t);n&&s.push(n)}return s},Ur=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Vr(n,f(t,r)))}return s},Wr=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},Gr=(e,t,s)=>{const r=Wr(e.getExpression(),s);if(r===void 0)return;const n=e.getArguments()[s.argIndex];if(!(!n||!w(n)||T(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:r}},_r=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const o=Gr(n,t,s);o&&r.push(o)}return r},J=(e,t,s)=>{const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(..._r(o,f(t,n),s))}return r},Hr=new Set(["content","pdf","scrape","screenshot"]),Jr=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Hr}),Qr=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Xr=new Set(["RateLimiter"]),Zr=new Set(["extend"]),At=e=>{const t=[],s=[];let r=!1;for(const n of e.getProperties()){if(i.isSpreadAssignment(n)){r=!0;continue}if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o),n.getInitializer()?.getKind()===u.TrueKeyword&&s.push(o);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,presentKeys:t,trueKeys:s}},st=e=>e&&i.isObjectLiteralExpression(e)?At(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Yr=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!i.isReturnStatement(s))return;const r=s.getExpression();return r!==void 0&&i.isObjectLiteralExpression(r)?r:void 0},en=e=>{if(i.isObjectLiteralExpression(e))return e;if(i.isParenthesizedExpression(e)){const t=e.getExpression();return i.isObjectLiteralExpression(t)?t:void 0}return i.isBlock(e)?Yr(e):void 0},tn=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&en(t.getBody());return s?At(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},sn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());n!==void 0&&(Qr.has(n)?s.push({callee:n,file:t,line:r.getStartLineNumber(),...st(r.getArguments()[0])}):Zr.has(n)&&s.push({callee:n,file:t,line:r.getStartLineNumber(),...tn(r.getArguments()[0])}))}for(const r of e.getDescendantsOfKind(u.NewExpression)){const n=S(r.getExpression());n===void 0||!Xr.has(n)||s.push({callee:n,file:t,line:r.getStartLineNumber(),...st(r.getArguments()[0])})}return s},rn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...sn(n,f(t,r)))}return s},rt="ctx.containers.",nn=e=>{if(!e.startsWith(rt))return!1;const t=e.slice(rt.length);return t.length>0&&!t.includes(".")},on=(e,t)=>J(e,t,{argIndex:0,matchReceiver:nn,methods:new Set(["get"])}),an=new Set(["allow","deny","setAllowed"]),cn=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},un=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!cn(e)))return{detail:"enableInternet: true",exportName:h(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},ln=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!an.has(s.getName()))return;const r=s.getExpression();if(!(!i.isPropertyAccessExpression(r)||r.getName()!=="egress"))return{detail:s.getName(),exportName:h(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},dn=(e,t)=>un(e,t)??ln(e,t),gn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=dn(r,t);n&&s.push(n)}return s},fn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...gn(n,f(t,r)))}return s},pn="env.ts",mn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return H(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},xn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const r=s.getFirstAncestorByKind(u.ImportDeclaration);return r!==void 0&&H(r.getModuleSpecifierValue())}return!1},hn=e=>{if(i.isIdentifier(e))return mn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&xn(t)}return!1},En=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!hn(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw _(n,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},yn=(e,t)=>{const s=g(t,pn);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=En(r);if(n.length!==0){if(n.length>1)throw _(r,`lunora/env.ts declares ${n.length.toString()} defineEnv() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},An=new Set(["defineExportSink","r2Sink","webhookExportSink"]),$n=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return An.has(s)?s:void 0},Sn=e=>{const t=[],s=[];for(const r of e.getProperties()){if(i.isSpreadAssignment(r))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(i.isPropertyAssignment(r)){const n=r.getName();t.push(n);const o=r.getInitializer();o&&i.isStringLiteral(o)&&o.getLiteralText()===""&&s.push(n);continue}(i.isShorthandPropertyAssignment(r)||i.isMethodDeclaration(r)||i.isGetAccessorDeclaration(r))&&t.push(r.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Nn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){const c=$n(a);if(c===void 0)continue;const l=a.getArguments()[0],p=l&&i.isObjectLiteralExpression(l)?Sn(l):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:p.analyzable,emptyKeys:p.emptyKeys,factory:c,file:o,line:a.getStartLineNumber(),presentKeys:p.presentKeys})}}return s},vn=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),bn=new Set(["dbRateLimit","rateLimit"]),Pn=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&i.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===u.TrueKeyword},wn=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},In=(e,t)=>{const s=S(e.getExpression());if(s===void 0)return;const r=vn.get(s);if(r!==void 0)return{callee:s,exportName:h(e),failOpen:Pn(e.getArguments()[r]),file:t,limitName:bn.has(s)?wn(e):"",line:e.getStartLineNumber()}},On=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=In(r,t);n&&s.push(n)}return s},Ln=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...On(n,f(t,r)))}return s},Fn=e=>{const t=r=>i.isIdentifier(r)&&r.getText()==="ctx",s=new Set;for(const r of e.getDescendantsOfKind(u.PropertyAccessExpression))t(r.getExpression())&&s.add(r.getName());for(const r of e.getDescendantsOfKind(u.VariableDeclaration)){const n=r.getInitializer(),o=r.getNameNode();if(!(n===void 0||!t(n)||!i.isObjectBindingPattern(o)))for(const a of o.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},Tn=(e,t)=>{const s=Object.fromEntries(pe.map(r=>[r.key,!1]));for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=new Set(n.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=Fn(n);for(const c of pe)if(!s[c.key]){if(o.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(pe.every(c=>s[c.key]))break}return s},Dn=["providerSubscriptionId","state"],Cn=["providerEventId","processedAt"],nt=(e,t)=>t.every(s=>s in e.shape),kn=e=>{const t=e.find(r=>r.name==="subscriptions"),s=e.find(r=>r.name==="events");return t!==void 0&&s!==void 0&&nt(t,Dn)&&nt(s,Cn)},Kn=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings/kv"),mail:e.mail||t.dependencies.has("@lunora/mail"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),Rn=e=>i.isIdentifier(e)&&e.getText()==="ctx",Mn=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Rn(t.getExpression())},jn=e=>{if(e?.getKind()===u.TrueKeyword)return!0;if(e?.getKind()===u.FalseKeyword)return!1},zn=(e,t)=>{if(!Mn(e.getExpression()))return;const[s,r]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const n=s.getLiteralValue(),o=jn(r);if(!(n.length===0||o===void 0))return{defaultValue:o,exportName:h(e),file:t,key:n,line:e.getStartLineNumber()}},qn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=zn(r,t);n&&s.push(n)}return s},Bn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...qn(n,f(t,r)))}return s},Vn=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Un=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Wn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression))Vn(a)&&s.push({file:o,indexName:Un(a),line:a.getStartLineNumber()})}return s},Gn=new Set(["delete","get","head","options","patch","post","put"]),_n=new Set(["handler","stream"]),Hn=new Set(["runAction","runMutation"]),Jn=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),U=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,it=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,ot=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const r=s.getNameNode();if(t)return i.isIdentifier(r)?r.getText():void 0;if(i.isObjectBindingPattern(r)){for(const n of r.getElements())if((n.getPropertyNameNode()?.getText()??n.getNameNode().getText())==="ctx"){const o=n.getNameNode();return i.isIdentifier(o)?o.getText():void 0}}},at=(e,t)=>{const s=e.getBody(),r=s.getDescendantsOfKind(u.CallExpression);i.isCallExpression(s)&&r.unshift(s);for(const n of r){const o=n.getExpression();if(!i.isPropertyAccessExpression(o))continue;const a=o.getName(),c=o.getExpression();if(Hn.has(a)&&U(c,t))return a;if(Jn.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&U(c.getExpression(),t))return`db.${a}`}},ct=(e,t)=>{const s=e.getBody();for(const r of s.getDescendantsOfKind(u.PropertyAccessExpression))if(r.getName()==="auth"&&U(r.getExpression(),t))return!0;for(const r of s.getDescendantsOfKind(u.VariableDeclaration)){const n=r.getNameNode();if(!(!i.isObjectBindingPattern(n)||!U(r.getInitializer(),t))){for(const o of n.getElements())if((o.getPropertyNameNode()?.getText()??o.getNameNode().getText())==="auth")return!0}}return!1},Qn=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!_n.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))return;const n=r.getName();if(Gn.has(n)){const o=r.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?n.toUpperCase():void 0}s=r.getExpression()}},Xn=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=it(e.getArguments()[0]),l=c&&ot(c,!0);if(!c||l===void 0)return;const p=at(c,l);return p===void 0?void 0:{exportName:h(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ct(c,l),sideEffect:p}}const r=Qn(e);if(r===void 0)return;const n=it(e.getArguments()[0]),o=n&&ot(n,!1);if(!n||o===void 0)return;const a=at(n,o);return a===void 0?void 0:{exportName:h(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:r,readsAuth:ct(n,o),sideEffect:a}},Zn=(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(...Zn(n,f(t,r)))}return s},ei=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),ti=new Set(["append","set"]),$e=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",$t=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",ut=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(u.CallExpression)]:e.getDescendantsOfKind(u.CallExpression)).some(s=>ei.has($e(s.getExpression()))&&B(s,t)),si=(e,t)=>{if(ut(e,t))return!0;const s=L(e);return s!==void 0&&ut(s,t)},ye=(e,t)=>rr(e,t)&&!si(e,t),ri=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=L(e);return t!==void 0&&i.isNewExpression(t)&&$e(t.getExpression())==="Headers"},W=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=L(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},Se=(e,t,s)=>{for(const r of e.getProperties())if(i.isPropertyAssignment(r)){const n=r.getInitializer();n!==void 0&&ye(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:$t(r.getNameNode()),line:n.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(r)){const n=r.getNameNode();ye(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:r.getName(),line:n.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(r)){const n=W(r.getExpression());n!==void 0&&Se(n,t,s)}},St=(e,t)=>{const s=W(e);if(s===void 0)return;const r=s.getProperty("headers");if(r===void 0||!i.isPropertyAssignment(r))return;const n=W(r.getInitializer());n!==void 0&&Se(n,"response-init",t)},ni=(e,t)=>{const s=$e(e.getExpression());if(s==="Response")St(e.getArguments()[1],t);else if(s==="Headers"){const r=W(e.getArguments()[0]);r!==void 0&&Se(r,"headers-ctor",t)}},ii=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const r=s.getName(),n=s.getExpression();if(r==="json"&&i.isIdentifier(n)&&n.getText()==="Response"){St(e.getArguments()[1],t);return}if(ti.has(r)&&ri(n)){const o=e.getArguments()[1];o!==void 0&&ye(o,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:$t(e.getArguments()[0]),line:o.getStartLineNumber(),via:r==="set"?"headers-set":"headers-append"})}},oi=(e,t)=>{for(const s of e.getDescendantsOfKind(u.NewExpression))ni(s,t);for(const s of e.getDescendantsOfKind(u.CallExpression))ii(s,t)},ai=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const r=Gt(e.getArguments()[0]);if(r===void 0)return[];const n=r.getParameters()[1];if(n===void 0)return[];const o=n.getNameNode();if(!i.isIdentifier(o))return[];const a=[];return oi(r,{exportName:h(e),relativePath:t,requestName:o.getText(),rows:a}),a},ci=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...ai(r,t));return s},ui=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ci(n,f(t,r)))}return s},Nt="identity.ts",li=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return H(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},di=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const r=s.getFirstAncestorByKind(u.ImportDeclaration);return r!==void 0&&H(r.getModuleSpecifierValue())}return!1},gi=e=>{if(i.isIdentifier(e))return li(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&di(t)}return!1},fi=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!gi(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw _(n,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},pi=(e,t)=>{const s=g(t,Nt);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=fi(r);if(n.length!==0){if(n.length>1)throw _(r,`lunora/identity.ts declares ${n.length.toString()} defineIdentity() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},mi=new Set(["auth","context.auth","ctx.auth"]),xi="userId",hi=e=>{const t=new Set;for(const s of e.getProperties()){if(i.isSpreadAssignment(s))return;(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s))&&t.add(s.getName())}return t},Ei=(e,t)=>{const s=g(t,Nt);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const n of r.getDescendantsOfKind(u.CallExpression)){if(S(n.getExpression())!=="defineIdentity")continue;const[o]=n.getArguments();return o&&i.isObjectLiteralExpression(o)?hi(o):void 0}},lt=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return mi.has(e.getExpression().getText())?e:void 0},yi=e=>{if(i.isPropertyAccessExpression(e)&<(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&<(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},Ai=(e,t,s)=>{const r=[];for(const n of e.getDescendants()){const o=yi(n);o!==void 0&&r.push({declared:o===xi||s.has(o),exportName:h(n),file:t,key:o,line:n.getStartLineNumber()})}return r},$i=(e,t)=>{const s=Ei(e,t);if(s===void 0)return[];const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(...Ai(o,f(t,n),s))}return r},Si=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Ni=(e,t)=>{if(S(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const r=Si(s);if(!(!r||!w(r)||T(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},vi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ni(r,t);n&&s.push(n)}return s},bi=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...vi(n,f(t,r)))}return s},Pi=new Set(["delete","get","getRaw","getWithMetadata","put"]),wi=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:Pi}),Ii=new Set(["queue","send"]),dt=new Set(["bcc","cc","to"]),Oi=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Ii.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},Li=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const r=t.getNameNode();return dt.has(t.getName())&&w(r)&&!T(r)}if(!i.isPropertyAssignment(t)||!dt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&w(s)&&!T(s)}):!1,Fi=(e,t)=>{const s=Oi(e.getExpression());if(s===void 0)return;const r=e.getArguments()[0];if(!(!r||!Li(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Ti=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Fi(r,t);n&&s.push(n)}return s},Di=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ti(n,f(t,r)))}return s},Ci=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},ki=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},Ki=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==u.CallExpression)return;const s=t;return Ns(s.getExpression())?s:void 0},Ri=e=>{const t=Ki(e),s=t===void 0?void 0:ki(t);if(s===void 0)return[];const r=e.getNameNode(),n=i.isIdentifier(r)?r.getText():"";return s.getDescendantsOfKind(u.CallExpression).filter(o=>Ci(o)).map(o=>({exportName:n,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},Mi=e=>e.getVariableDeclarations().flatMap(t=>Ri(t)),ji=(e,t)=>{const s=g(t,Ss);if(!E(s))return[];const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Mi(r)},zi=new Set(["delete","get","patch"]),qi=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Bi=new Set(["auth","identity","session","user"]),Vi=new Set([u.EqualsEqualsEqualsToken,u.EqualsEqualsToken,u.ExclamationEqualsEqualsToken,u.ExclamationEqualsToken]),Ui=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!k(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},Wi=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(i.isAsExpression(s)||i.isParenthesizedExpression(s)||i.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!i.isVariableDeclaration(s))return;const r=s.getNameNode();return i.isIdentifier(r)?r.getText():void 0},Gi=(e,t)=>e.getDescendantsOfKind(u.Identifier).some(s=>s.getText()===t),_i=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(u.ThrowStatement).length>0||e.getDescendantsOfKind(u.ReturnStatement).length>0,Hi=(e,t)=>e.getDescendantsOfKind(u.IfStatement).some(s=>Gi(s.getExpression(),t)&&_i(s.getThenStatement())),Ji=(e,t)=>{for(const s of e.getDescendantsOfKind(u.CallExpression)){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))continue;const n=r.getName();if(!zi.has(n))continue;const o=r.getExpression();if(!(k(o)||i.isPropertyAccessExpression(o)&&k(o.getExpression())))continue;const a=s.getArguments()[0];if(a!==void 0&&i.isIdentifier(a)&&a.getText()===t)return n}},Qi=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},Xi=e=>e.getDescendantsOfKind(u.CallExpression).some(t=>t.getArguments().some(s=>Qi(s)==="ctx")),Zi=e=>e.getDescendantsOfKind(u.BinaryExpression).some(t=>Vi.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),Yi=e=>{for(const t of e.getDescendantsOfKind(u.Identifier))if(qi.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&Bi.has(t.getName()))return!0}return Xi(e)||Zi(e)},eo=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const r=K(s);if(r?.kind!=="query"&&r?.kind!=="mutation")return[];const n=mt(s);if(n===void 0)return[];const o=r.receiver!==void 0&&xt(r.receiver,"use","rls"),a=Yi(n),c=new Set,l=[];for(const p of n.getDescendantsOfKind(u.CallExpression)){const y=Ui(p);if(y===void 0)continue;const I=Wi(p);if(I===void 0||c.has(I)||!Hi(n,I))continue;const R=Ji(n,I);R!==void 0&&(c.add(I),l.push({exportName:e.getName(),file:t,line:p.getStartLineNumber(),mentionsOwnership:a,sinkMethod:R,table:y,usesRls:o,visibility:r.visibility}))}return l},to=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...eo(c,o))}return s},so=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),ro=new Set(["insert","insertManyUnsafe","patch","replace"]),no=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!ro.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="db")return;const r=s.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"?t:void 0},io=(e,t)=>{if(t!=="insertManyUnsafe")return i.isObjectLiteralExpression(e)?[e]:[];if(!i.isArrayLiteralExpression(e))return[];const s=[];for(const r of e.getElements())i.isObjectLiteralExpression(r)&&s.push(r);return s},oo=(e,t,s,r)=>{const n=[];for(const o of e.getProperties()){let a,c;i.isPropertyAssignment(o)?(a=o.getName(),c=o.getInitializer()):i.isShorthandPropertyAssignment(o)&&(a=o.getName(),c=o.getNameNode()),!(a===void 0||c===void 0||!so.has(a))&&w(c)&&!T(c)&&n.push({exportName:h(s),field:a,file:r,line:s.getStartLineNumber(),method:t})}return n},ao=(e,t)=>{const s=no(e.getExpression());if(s===void 0)return[];const r=e.getArguments()[1];return r?io(r,s).flatMap(n=>oo(n,s,e,t)):[]},co=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...ao(r,t));return s},uo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...co(n,f(t,r)))}return s},lo=e=>{const t=g(e,"package.json");if(!E(t))return new Set;try{const s=JSON.parse(Ae(t,"utf8")),r=new Set;for(const n of["dependencies","devDependencies","peerDependencies","optionalDependencies"]){const o=s[n];if(o!==null&&typeof o=="object")for(const a of Object.keys(o))r.add(a)}return r}catch{return new Set}},go=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),fo=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,po=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?fo(t.getInitializer()):void 0},mo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=S(r.getExpression());if(n===void 0||!go.has(n))continue;const[o]=r.getArguments(),a=o&&i.isObjectLiteralExpression(o)?po(o):void 0;s.push({callee:n,exportName:h(r),file:t,line:r.getStartLineNumber(),...a===void 0?{}:{toleranceSeconds:a}})}return s},xo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...mo(n,f(t,r)))}return s},ho=new Set(["defineQueue","defineWorkflow"]),Eo=new Set(["run","runAction","runMutation","runQuery"]),yo=new Set(["api","internal"]),Ao=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},$o=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!i.isPropertyAssignment(s))return;const r=s.getInitializer();if(r&&(i.isArrowFunction(r)||i.isFunctionExpression(r)))return r},vt=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},bt=(e,t)=>e===t||e.startsWith(`${t}.`),Pt=e=>{const t=e.getDescendantsOfKind(u.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},gt=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e||i.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(i.isBindingElement(t)&&t.getNameNode()===e)},wt=e=>{const t=e.getDescendantsOfKind(u.Identifier).filter(s=>gt(s));return i.isIdentifier(e)&>(e)&&t.push(e),t},So=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(u.BindingElement).map(s=>s.getName())},No=e=>{const t=vt(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const r of e.getDescendantsOfKind(u.ForOfStatement)){if(r.getExpression().getText()!==`${t}.messages`)continue;const n=r.getInitializer(),o=i.isVariableDeclarationList(n)?n.getDeclarations()[0]?.getNameNode():void 0;o&&i.isIdentifier(o)&&s.push(`${o.getText()}.body`)}return s},vo=(e,t,s)=>{const r=t==="workflow"?[`${s}.params`]:No(e),n=new Set,o=a=>Pt(a).some(c=>r.some(l=>bt(c.getText(),l)))?!0:wt(a).some(c=>n.has(c.getText()));for(const a of e.getDescendantsOfKind(u.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of So(a))n.add(l)}return{names:n,prefixes:r}},bo=(e,t)=>Pt(e).some(s=>t.prefixes.some(r=>bt(s.getText(),r)))?!0:wt(e).some(s=>t.names.has(s.getText())),Po=e=>{if(e===void 0||!i.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;i.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const r=t.at(-1);if(!(r===void 0||!i.isIdentifier(s)||!yo.has(s.getText())||t.length<2))return{exportName:r,file:t.slice(0,-1).join("/")}},wo=(e,t,s)=>{const r=vt(e,0);if(r===void 0)return[];const n=vo(e,t,r),o=[];for(const a of e.getDescendantsOfKind(u.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!Eo.has(c.getName())||c.getExpression().getText()!==r)continue;const l=a.getArguments()[1];if(!l||!bo(l,n))continue;const p=Po(a.getArguments()[0]);p!==void 0&&o.push({dispatchKind:t,file:s,handlerExport:h(a),line:a.getStartLineNumber(),targetExport:p.exportName,targetFile:p.file})}return o},Io=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ao(r);if(n===void 0||!ho.has(n))continue;const o=$o(r);o!==void 0&&s.push(...wo(o,n==="defineQueue"?"queue":"workflow",t))}return s},Oo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Io(n,f(t,r)))}return s},ft={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},Lo=/account|credential|member|passkey|session|user/iu,Fo=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},To=(e,t)=>{const{objects:s,opaque:r}=yt(e,t);return vr(s).some(n=>Fo(n))?!0:r?void 0:!1},It=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},Do=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Co=e=>{if(i.isCallExpression(e))return e;if(!i.isIdentifier(e))return;const t=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return t&&i.isCallExpression(t)?t:void 0},V={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},ko=e=>{const t=Co(e),s=t?It(t):void 0;if(t&&s==="protectPublic"){const r=Do(t);return{...V,usesCaptcha:r.usesCaptcha,usesRateLimit:r.usesRateLimit}}return s!==void 0&&s in ft?{...V,[ft[s]]:!0}:V},Ko=e=>{const t={...V};let s=e;for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))break;const n=r.getName()==="use"?s.getArguments()[0]:void 0;if(n){const o=ko(n);t.usesCaptcha||=o.usesCaptcha,t.usesEmailGate||=o.usesEmailGate,t.usesMask||=o.usesMask,t.usesRateLimit||=o.usesRateLimit,t.usesRls||=o.usesRls}s=r.getExpression()}return t},Ro=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insert")return!1;const s=t.getExpression();if(!(i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"))return!1;const r=e.getArguments()[0];return!!(r&&i.isStringLiteral(r)&&Lo.test(r.getLiteralText()))},Mo=new Set(["create","runAfter","runAt","send","sendBatch"]),jo=new Set(["queues","scheduler","workflows"]),zo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Mo.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&jo.has(s.getName())){const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="ctx")return!0}s=s.getExpression()}return!1},qo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},Bo=new Set(["generateObject","generateText","streamObject","streamText"]),Vo=e=>{const t=It(e);if(t===void 0||!Bo.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(r=>i.isSpreadAssignment(r))?!1:!s.getProperty("maxOutputTokens")},Uo=e=>e.getDescendantsOfKind(u.PropertyAccessExpression).some(t=>{const s=t.getName();if(s!=="mail"&&s!=="email")return!1;const r=t.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"}),Wo=e=>{let t=!1,s=!1,r=!1,n=!1;for(const o of e.getDescendantsOfKind(u.CallExpression))if(Ro(o)&&(n=!0),zo(o)&&(t=!0),qo(o)&&(r=!0),Vo(o)&&(s=!0),n&&t&&r&&s)break;return{callsMail:Uo(e),fanOut:t,unboundedAiGeneration:s,usesInsertManyUnsafe:r,writesUserTable:n}},Go=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=K(s);if(!r||r.kind!=="query"&&r.kind!=="mutation"&&r.kind!=="action")return;const n=r.receiver?Ko(r.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},{callsMail:o,fanOut:a,unboundedAiGeneration:c,usesInsertManyUnsafe:l,writesUserTable:p}=Wo(e);return{callsMail:o,exportName:e.getName(),fanOut:a,file:t,hasEmailArg:To(s,r.receiver),kind:r.kind,unboundedAiGeneration:c,usesCaptcha:n.usesCaptcha,usesEmailGate:n.usesEmailGate,usesInsertManyUnsafe:l,usesMask:n.usesMask,usesRateLimit:n.usesRateLimit,usesRls:n.usesRls,visibility:r.visibility,writesUserTable:p}},_o=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Go(n,t);o&&s.push(o)}return s},Ho=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(..._o(n,f(t,r)))}return s},Jo=new Set(["dbRateLimit","rateLimit"]),Qo=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Xo=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},Zo=e=>i.isArrowFunction(e)?e.getBody():e,Yo=(e,t)=>{const s=S(e.getExpression());if(s===void 0||!Jo.has(s))return;const r=e.getArguments()[2];if(!r)return;const n=Qo(r);if(!n)return;const o=Zo(n);if(!(!w(o)||T(o)))return{callee:s,exportName:h(e),file:t,limitName:Xo(e),line:e.getStartLineNumber()}},ea=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Yo(r,t);n&&s.push(n)}return s},ta=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ea(n,f(t,r)))}return s},sa=new Set(["findFirst","findFirstOrThrow","findMany","get"]),ra=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!sa.has(t.getName()))return;const s=t.getExpression();if(k(s)){const r=e.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&k(s.getExpression()))return s.getName()},na=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&k(s.getExpression())){const r=t.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}t=s.getExpression()}},ia=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},Ot=(e,t=!1)=>{const s=ia(e);if(i.isIdentifier(s)){if(t)return;const r=L(s);return r===void 0?void 0:Ot(r,!0)}if(i.isCallExpression(s))return ra(s)??na(s)},oa=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const r of e.getDescendantsOfKind(u.ReturnStatement)){const n=r.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),o=r.getExpression();n===e&&o!==void 0&&s.push(o)}return s},aa=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const r=K(s);if(r?.kind!=="query")return[];const n=mt(s);if(n===void 0)return[];const o=r.receiver!==void 0&&_t(r.receiver,"output"),a=r.receiver!==void 0&&xt(r.receiver,"use","mask"),c=new Set,l=[];for(const p of oa(n)){const y=Ot(p);y===void 0||c.has(y)||(c.add(y),l.push({exportName:e.getName(),file:t,line:p.getStartLineNumber(),table:y,usesMask:a,usesOutput:o,visibility:r.visibility}))}return l},ca=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...aa(c,o))}return s},ua=new Set(["findFirst","findFirstOrThrow","findMany"]),la=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ua.has(t.getName()))return;const s=t.getExpression();if(i.isPropertyAccessExpression(s)&&s.getName()==="db"||i.isIdentifier(s)&&s.getText()==="db"){const r=e.getArguments()[0];return{options:e.getArguments()[1],table:r&&i.isStringLiteral(r)?r.getLiteralText():""}}if(i.isPropertyAccessExpression(s)){const r=s.getExpression();if(i.isPropertyAccessExpression(r)&&r.getName()==="db"||i.isIdentifier(r)&&r.getText()==="db")return{options:e.getArguments()[0],table:s.getName()}}},da=e=>{if(!e||!i.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s)||i.isGetAccessorDeclaration(s))&&t.push(s.getName());return t},ga=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},fa=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&i.isCallExpression(s)?K(s):void 0;if(!r)return[];const n=[];for(const o of e.getDescendantsOfKind(u.CallExpression)){const a=la(o);if(a===void 0)continue;const c=da(ga(a.options,"with"));c.length!==0&&n.push({exportName:e.getName(),file:t,line:o.getStartLineNumber(),parentTable:a.table,relations:c,visibility:r.visibility})}return n},pa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...fa(c,o))}return s},G=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===u.PlusToken){const t=G(e.getLeft()),s=G(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},ma=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===u.PlusToken;)t=s,s=t.getParent();return t!==e&&G(t)!==void 0},xa=(e,t)=>{const s=[],r=[...e.getDescendantsOfKind(u.BinaryExpression),...e.getDescendantsOfKind(u.StringLiteral),...e.getDescendantsOfKind(u.NoSubstitutionTemplateLiteral)],n=new Set;for(const o of r){if(ma(o))continue;const a=G(o);if(a===void 0)continue;const c=ks(a);if(c===void 0)continue;const l=o.getStartLineNumber(),p=`${String(l)}:${c}`;n.has(p)||(n.add(p),s.push({file:t,kind:c,line:l,preview:Ks(a)}))}return s},ha=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...xa(n,f(t,r)))}return s},Ea=new Set(["findFirst","findFirstOrThrow","findMany"]),ya=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Ea.has(t.getName()))return;const s=t.getExpression();if(i.isPropertyAccessExpression(s)&&s.getName()==="db"||i.isIdentifier(s)&&s.getText()==="db"){const r=e.getArguments()[0];return{options:e.getArguments()[1],table:r&&i.isStringLiteral(r)?r.getLiteralText():""}}if(i.isPropertyAccessExpression(s)){const r=s.getExpression();if(i.isPropertyAccessExpression(r)&&r.getName()==="db"||i.isIdentifier(r)&&r.getText()==="db")return{options:e.getArguments()[0],table:s.getName()}}},Aa=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},$a=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&i.isCallExpression(s)?K(s):void 0;if(!r)return[];const n=[];for(const o of e.getDescendantsOfKind(u.CallExpression)){const a=ya(o);if(a===void 0)continue;const c=Aa(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),p=!l&&w(c);!l&&!p||n.push({exportName:e.getName(),file:t,fromArgs:p,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:r.visibility})}return n},Sa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...$a(c,o))}return s},Na=new Set(["query","unsafe"]),va=e=>{if(!i.isPropertyAccessExpression(e)||!Na.has(e.getName()))return!1;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return i.isIdentifier(s)&&s.getText()==="ctx"},ba=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),Pa=e=>e.getFirstAncestorByKind(u.VariableDeclaration)?.getName()??"<module>",wa=(e,t)=>{if(!va(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!ba(s)))return{exportName:Pa(e),file:t,line:s.getStartLineNumber()}},Ia=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=wa(r,t);n&&s.push(n)}return s},Oa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ia(n,f(t,r)))}return s},La=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Fa=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.storage"||s.startsWith("ctx.storage."),methods:La}),Ta=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Da=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Ca=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!i.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,r=!1;for(const n of e.getProperties()){if(i.isSpreadAssignment(n)){r=!0;continue}if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o),o==="expiresInSeconds"&&(s=Da(n.getInitializer()));continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,expiresInSeconds:s,presentKeys:t}},ka=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=Ta.get(t);if(s===void 0)return;const r=e.getExpression().getText();return r==="ctx.storage"||r.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},Ka=(e,t)=>{const s=ka(e.getExpression());if(s!==void 0)return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s.method,...Ca(e.getArguments()[s.optionsIndex])}},Ra=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ka(r,t);n&&s.push(n)}return s},Ma=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ra(n,f(t,r)))}return s},ja=new Set(["when","where"]),he=new Set(["definePolicy","defineShape"]),za=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const r=t.getName();return he.has(r)?r:void 0}if(!i.isIdentifier(t))return;for(const r of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(r)){const n=r.getNameNode().getText();return he.has(n)?n:void 0}const s=t.getText();return he.has(s)?s:void 0},qa=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,Lt=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===u.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(qa(e))return"empty-object";if(i.isParenthesizedExpression(e))return Lt(e.getExpression())}},Ft=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Tt=e=>e.getDescendantsOfKind(u.ReturnStatement).filter(t=>Ft(t)===e),Dt=e=>e.getDescendantsOfKind(u.ConditionalExpression).filter(t=>Ft(t)===e),Ba=e=>{const t=Tt(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(u.IfStatement)!==void 0)||Dt(e).length>0},Va=e=>{const t=[],s=e.getBody();i.isBlock(s)||t.push(s);for(const r of Tt(e)){const n=i.isReturnStatement(r)?r.getExpression():void 0;t.push(n??r)}for(const r of Dt(e))t.push(r.getWhenTrue(),r.getWhenFalse());return t},Ua=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},Wa=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[r]=e.getArguments();if(!r||!i.isObjectLiteralExpression(r))return[];const n=[];for(const o of r.getProperties()){if(!i.isPropertyAssignment(o)||!ja.has(o.getName()))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Ba(a))for(const c of Va(a)){const l=Lt(c);l!==void 0&&n.push({exportName:Ua(e),file:s,form:l,key:o.getName(),line:c.getStartLineNumber(),owner:t})}}return n},Ga=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=za(r);n!==void 0&&s.push(...Wa(r,n,t))}return s},_a=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ga(n,f(t,r)))}return s},Ha=new Set(["query","upsert","upsertMany"]),Ja=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(Ha.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Qa=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("namespace");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Xa=(e,t)=>{const s=Ja(e.getExpression());if(s===void 0)return;const r=e.getArguments()[1];if(!r)return;const n=Qa(r);if(!(!n||!w(n)||T(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Za=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Xa(r,t);n&&s.push(n)}return s},Ya=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Za(n,f(t,r)))}return s},ec=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="workflows":i.isIdentifier(s)&&s.getText()==="workflows"},tc=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},sc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){if(!ec(a))continue;const c=js(a);c!==""&&s.push({exportName:c,file:o,line:a.getStartLineNumber(),workflow:tc(a)})}}return s},rc=".lunora-schema.json",$=(e,t)=>{E(e)&&Ae(e,"utf8")===t||Vt(e,t,"utf8")},P=(e,t)=>{if(t===""){Ut(e,{force:!0});return}$(e,t)},nc=e=>{const t=g(e,"package.json");if(E(t))try{const s=JSON.parse(Ae(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},ic=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},oc=e=>{let t=E(e)?e:ge(e);for(;t&&t!==ge(t);){const s=g(t,"tsconfig.json");if(E(s))return s;t=ge(t)}},pt=e=>e.replaceAll("\\","/"),ac=(e,t)=>{const s=new Map,r=new Map,n=new Map;for(const o of e)s.set(o.name,`workflow "${o.exportName}"`),r.set(o.bindingName,`workflow "${o.exportName}"`),n.set(o.className,`workflow "${o.exportName}"`);for(const o of t){const a=s.get(o.name);if(a!==void 0)throw new q("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${o.name}": produced by both ${a} and agent "${o.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=r.get(o.bindingName);if(c!==void 0)throw new q("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${o.bindingName}": produced by both ${c} and agent "${o.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const l=n.get(o.className);if(l!==void 0)throw new q("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${o.className}": produced by both ${l} and agent "${o.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},cc=e=>{const t=oc(e);return t?new Xe({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Xe({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Gc=(e,t)=>{const s=d(t),r=g(t,"schema.ts");E(r)&&s.push(r);for(const c of s){const l=e.getSourceFile(c);l===void 0?e.addSourceFileAtPath(c):l.refreshFromFileSystemSync()}const n=new Set(s.map(c=>pt(c))),o=pt(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!n.has(l)&&e.removeSourceFile(c)}},_c=e=>{const t=ic(),s=t?fe.now():0,r=g(e.projectRoot,e.lunoraDirectory??"lunora"),n=g(r,"schema.ts");if(!E(n))throw new q("INTERNAL",`schema.ts not found at ${n}`);const o=e.project??cc(r),a=Cs(o,n,e.projectRoot),c=Ht(o,r),l=xs(o,r),p=$s(o,r),y=Rs(o,r),I=vs(o,r),R=pi(o,r),Ne=yn(o,r),v=zs(o,r),D=Os(o,r),b=Jt(o,r);ac(v,b);const Q=Zt(o,r,v,b),C=Xt(o,r),ve=e.lint===!1?[]:Wt({adminRoutes:tr(o,r),aiRawRuns:ar(o,r),aiToolSideEffects:hr(o,r),argumentDerivedFetches:$r(o,r),argumentValidators:Dr(o,r),authApiCalls:Qt(o,r),authConfigs:Ur(o,r),browserUrlAccesses:Jr(o,r),configCalls:rn(o,r),containerKeyAccesses:on(o,r),containerOverrides:fn(o,r),containers:C,exportSinks:Nn(o,r),failOpenGuards:Ln(o,r),flagSecurityDefaults:Bn(o,r),geoIndexUsages:Wn(o,r),httpActionGuards:Yn(o,r),httpHeaderWrites:ui(o,r),identityClaimReads:$i(o,r),imageDeliveryUrlAccesses:bi(o,r),inserts:hs(o,r),kvKeyAccesses:wi(o,r),mailRecipientAccesses:Di(o,r),maskProcedures:Es(o,r),maskStrategies:ys(o,r),mutatorWrites:ji(o,r),nondeterministicCalls:bs(o,r),normalizeIdAuthorizations:to(o,r),notifyCalls:ws(o,r),notifyConfig:Ps(o,r),ownerFieldWrites:uo(o,r),unrestrictedWhereBranches:_a(o,r),paymentWebhooks:xo(o,r),privilegedDispatches:Oo(o,r),procedureProtections:Ho(o,r),queries:Is(o,r),queues:D,r2sqlCalls:Ls(o,r),ratelimitKeySelectors:ta(o,r),rawRowReturns:ca(o,r),relationLoads:pa(o,r),rlsProcedures:Fs(o,r),schema:a,secretLiterals:ha(o,r),shapes:y,softDeleteReads:Sa(o,r),sqlInterpolations:Oa(o,r),storageKeyAccesses:Fa(o,r),storageUploads:Ma(o,r),vectorNamespaceAccesses:Ya(o,r),workflowCalls:sc(o,r),workflows:v,wranglerVariables:e.wranglerVariables}),Ct=Ts(o,r),kt=As(o,r),X=Ms(o,r),A=Tn(o,r),Z=A.ai,Y=A.payments,be=A.kv,Pe=A.access,ee=E(g(r,"flags.ts")),Kt=ee?ms(o,r):[],te=E(g(r,"notify.ts")),se=A.hyperdrive,re=Ds(o,r),Rt=re.usesSandboxBrowser||re.usesSandboxContainer,ne=A.browser||re.usesSandboxBrowser,ie=A.images,oe=A.analytics,we=A.pipelines,ae=A.r2sql,ce=A.x402,O=lo(e.projectRoot),M=Kn(A,{containerCount:C.length,cronCount:Q.length,dependencies:O,hasPaymentTables:kn(a.tables),queueCount:D.length,storageColumnCount:Object.keys(Yt(a)).length,storageRuleCount:X.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:v.length}),F=O.has("lunorash"),Ie=t?fe.now():0,Oe=es(a,F),Le=ts({agents:b,functions:c,httpRoutes:l,mutators:I,useUmbrella:F,workflows:v}),Fe=ss({agents:b,containers:C,env:Ne,hasAccessFacade:Pe,hasAi:Z,hasAnalytics:oe,hasBrowser:ne,hasFlags:ee,hasHyperdrive:se,hasImages:ie,hasKv:be,hasNotify:te,hasPayments:Y,hasPipelines:we,hasR2sql:ae,hasX402:ce,identity:R,queues:D,schema:a,storageRuleBuckets:X.rules.map(m=>m.bucket),useUmbrella:F,workflows:v}),Te=rs({agents:b,functions:c,migrations:p,mutators:I,shapes:y,useUmbrella:F,usesSandbox:Rt}),De=ns({advisories:ve,agents:b,containers:C,env:Ne,flagKeys:Kt,hasAccessFacade:Pe,hasAi:Z,hasAnalytics:oe,hasBrowser:ne,hasFlags:ee,hasHyperdrive:se,hasImages:ie,hasKv:be,hasNotify:te,hasPayments:Y,hasPipelines:we,hasR2sql:ae,hasX402:ce,maskMetadata:kt,mutators:I,queues:D,rlsMetadata:Ct,schema:a,shapes:y,storageRules:X,studioFeatures:M,useUmbrella:F,workflows:v}),Ce=is(y,O.has("@lunora/db"),F),ke=os(C,a.jurisdiction),Ke=as(v),Re=cs(b),Me=us(D),je=ls(Q),ze=ds(a.vectorIndexes),j=gs(a,F),qe=fs(O.has("@lunora/seed")),z=e.apiSpec??"openapi",ue=z==="openapi"||z==="both",le=z==="openrpc"||z==="both",Be=qs({emailAgents:b.filter(m=>m.onEmail===!0).map(m=>({bindingName:m.bindingName,exportName:m.exportName})),hasAccess:O.has("@lunora/cloudflare-access"),hasAi:Z,hasAnalytics:oe,hasAuth:O.has("@lunora/auth"),hasBrowser:ne,hasFramework:O.has("@lunora/astro")||O.has("@lunora/svelte")||O.has("@lunora/vue"),hasGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend!=="hyperdrive"),hasHyperdrive:se,hasHyperdriveGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend==="hyperdrive"),hasImages:ie,hasKv:M.kv,hasNotify:te,hasPayments:Y,hasR2sql:ae,hasQueue:D.some(m=>m.mode==="push"),hasScheduler:M.scheduler,hasStorage:M.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:v.length>0,hasX402:ce,identity:R,jurisdiction:a.jurisdiction,useUmbrella:F,voiceAgents:b.filter(m=>m.voice===!0&&m.voiceBindingName!==void 0).map(m=>({bindingName:m.voiceBindingName,exportName:m.exportName})),wantsOpenApi:ue,wantsOpenRpc:le}),Ve=nc(e.projectRoot),Ue=Bs({functions:c,httpRoutes:l,version:Ve}),We=Us({functions:c,version:Ve}),Ge=`${JSON.stringify(Ue,void 0,2)}
|
|
1
|
+
import{existsSync as E,readFileSync as Ae,mkdirSync as Bt,writeFileSync as Vt,rmSync as Ut}from"node:fs";import{join as g,dirname as ge}from"node:path";import{performance as fe}from"node:perf_hooks";import{LunoraError as q}from"@lunora/errors";import{Node as i,SyntaxKind as u,Project as Xe}from"ts-morph";import{lintSchema as Wt}from"./formatAdvisories-DZvv-0MG.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as f,classifyProcedureCall as K,inlineHandler as Gt,procedureHandler as mt,chainUsesWrappedCall as xt,isDatabaseAccessor as k,chainHasStep as _t,discoverFunctions as Ht}from"./discoverFunctions-DnqHgv0t.mjs";import{discoverAgents as Jt}from"./AGENTS_FILENAME-BesaDYkL.mjs";import Qt from"./discoverAuthApiCalls-CEk3J0kc.mjs";import{discoverContainers as Xt}from"./CONTAINERS_FILENAME-CFwdyaCI.mjs";import Zt from"./discoverCrons-kIgM9ZJC.mjs";import{diagnosticAt as _}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{o as H}from"./module-specifiers-8FEEiUcv.mjs";import{a as pe,d as Yt,G as es,s as ts,h as ss,b as rs,J as ns,c as is,_ as os,M as as,B as cs,j as us,t as ls,n as ds,e as gs,l as fs,r as ps}from"./emit-D7VIjvlm.mjs";import{discoverFlagKeys as ms}from"./FLAGS_FILENAME-CQDN7BKc.mjs";import xs from"./discoverHttpRoutes-CLn3VDRI.mjs";import hs from"./discoverInserts-Cn-CLKET.mjs";import Es,{discoverMaskStrategies as ys,discoverMaskMetadata as As}from"./discoverMaskProcedures-fZtvsy8v.mjs";import $s from"./discoverMigrations-BH_IKdFk.mjs";import{MUTATORS_FILENAME as Ns,isDefineMutatorCallee as Ss,discoverMutators as bs}from"./MUTATORS_FILENAME-3Akvs4aT.mjs";import vs from"./discoverNondeterministicCalls-Cl7qNL0J.mjs";import{discoverNotifyConfig as Ps,discoverNotifyCalls as ws}from"./NOTIFY_FILENAME-B2lXWa7r.mjs";import Is from"./discoverQueries-DENx_T6c.mjs";import{discoverQueues as Os}from"./QUEUES_FILENAME-CSE6i-ld.mjs";import Ls from"./discoverR2sqlCalls-CMNfDWlq.mjs";import Fs,{discoverRlsMetadata as Ts}from"./discoverRlsMetadata-Bf4_2S0t.mjs";import{discoverSandboxUsage as Ds}from"./discoverSandboxUsage-Bn1X9COt.mjs";import Cs from"./discoverSchema-Cy4OQ0Cu.mjs";import{secretKindOf as ks,redact as Ks}from"./redact-CQ8-to6l.mjs";import{discoverShapes as Rs}from"./SHAPES_FILENAME-maut3z1K.mjs";import Ms from"./discoverStorageRulesMetadata-CL8J41rX.mjs";import{e as js}from"./discover-ast-CezKqEhE.mjs";import{discoverWorkflows as zs}from"./WORKFLOWS_FILENAME-Bk5upkGM.mjs";import{emitApp as qs}from"./emitApp-CAeIj6e_.mjs";import{buildOpenApiDocument as Bs,emitOpenApiModule as Vs}from"./buildOpenApiDocument-xYxqrlj1.mjs";import{buildOpenRpcDocument as Us,emitOpenRpcModule as Ws}from"./OPENRPC_VERSION-CvVFqUlq.mjs";import{buildSchemaSnapshot as Gs,serializeSchemaSnapshot as _s}from"./SCHEMA_SNAPSHOT_VERSION-Bpf1FGMG.mjs";const ht=new Set(["delete","get","head","options","patch","post","put"]),Hs=new Set(["handler","stream"]),Js=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,Ze=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Qs=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ht.has(t.getName()))return;const s=t.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpRoute")return;const r=e.getArguments()[0];if(!(!r||!i.isStringLiteral(r)))return{method:t.getName().toUpperCase(),path:r.getLiteralValue()}},Xs=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||ht.has(r.getName()))break;s=r.getExpression()}return Qs(s)},Zs=e=>{for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression))if(Ze.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&Ze.has(s.getText()))return!0}return!1},Ys=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=s.getExpression();if(!i.isPropertyAccessExpression(r)||!Hs.has(r.getName()))return;const n=Xs(s);if(!n||!Js.test(n.path))return;const o=s.getArguments()[0],a=o!==void 0&&(i.isArrowFunction(o)||i.isFunctionExpression(o))&&Zs(o);return{exportName:e.getName(),file:t,method:n.method,path:n.path,usesGuard:a}},er=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Ys(n,t);o&&s.push(o)}return s},tr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...er(n,f(t,r)))}return s},Ye=e=>{if(e.getText()!=="args")return!1;const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(i.isPropertyAssignment(t)&&t.getNameNode()===e)},et=e=>{if(e.getText()!=="ctx")return!1;const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e?!1:!(i.isPropertyAssignment(t)&&t.getNameNode()===e)},me=e=>i.isIdentifier(e)?et(e):e.getDescendantsOfKind(u.Identifier).some(t=>et(t)),tt=(e,t)=>{if(e.getText()!==t)return!1;const s=e.getParent();return i.isPropertyAccessExpression(s)&&s.getNameNode()===e?!1:!(i.isPropertyAssignment(s)&&s.getNameNode()===e)},sr=e=>{let t=e;for(;i.isPropertyAccessExpression(t)||i.isElementAccessExpression(t)||i.isNonNullExpression(t);)t=t.getExpression();return i.isIdentifier(t)?t:void 0},N=e=>{if(i.isIdentifier(e))return e.getText();if(i.isPropertyAccessExpression(e))return e.getName()},Ee=e=>i.isIdentifier(e)?Ye(e):e.getDescendantsOfKind(u.Identifier).some(t=>Ye(t)),L=e=>{if(!i.isIdentifier(e))return;const t=e.getText(),s=e.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a));if(s===void 0)return;const r=e.getStart();let n,o=-1;for(const a of s.getDescendantsOfKind(u.VariableDeclaration)){if(a.getName()!==t)continue;const c=a.getInitializer(),l=a.getStart();c!==void 0&&l<r&&l>o&&(n=c,o=l)}return n},w=e=>{if(Ee(e))return!0;const t=L(e);return t!==void 0&&Ee(t)},T=e=>{if(me(e))return!0;const t=L(e);if(t!==void 0&&me(t))return!0;const s=t??e;return(i.isIdentifier(s)?[s]:s.getDescendantsOfKind(u.Identifier)).some(r=>{const n=L(r);return n!==void 0&&me(n)})},B=(e,t)=>i.isIdentifier(e)?tt(e,t):e.getDescendantsOfKind(u.Identifier).some(s=>tt(s,t)),rr=(e,t)=>{if(B(e,t))return!0;const s=L(e);if(s!==void 0&&B(s,t))return!0;const r=sr(e);if(r!==void 0){const n=L(r);return n!==void 0&&B(n,t)}return!1},h=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)&&t.getVariableStatement()?.hasExportKeyword()===!0)return t.getName();return"<module>"},nr=e=>!i.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",ir=(e,t)=>{if(!nr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)||T(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},or=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=ir(r,t);n&&s.push(n)}return s},ar=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...or(n,f(t,r)))}return s},cr=new Set(["generateText","streamText"]),ur=new Set(["messages","prompt","system"]),lr=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],dr=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return;const s=t.getName(),r=t.getExpression().getText();for(const n of lr)if(n.methods.has(s)&&n.prefixes.some(o=>r===o||r.startsWith(`${o}.`)))return`${r}.${s}`},gr=e=>{for(const t of e.getDescendantsOfKind(u.CallExpression)){const s=dr(t);if(s!==void 0)return s}},fr=e=>{const t=new Set,s=e.getFirstAncestor(o=>i.isArrowFunction(o)||i.isFunctionExpression(o)||i.isFunctionDeclaration(o)),[r]=s?.getParameters()??[],n=r?.getNameNode();if(n===void 0||!i.isObjectBindingPattern(n))return t;for(const o of n.getElements()){const a=o.getPropertyNameNode()?.getText()??o.getName(),c=o.getNameNode();if(a==="args"&&i.isObjectBindingPattern(c))for(const l of c.getElements())t.add(l.getName())}return t},pr=e=>{if(Ee(e))return!0;const t=fr(e);return t.size===0?!1:e.getDescendantsOfKind(u.Identifier).some(s=>t.has(s.getText()))},mr=e=>{for(const t of e.getProperties()){if(!i.isPropertyAssignment(t)||!ur.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&pr(s))return!0}return!1},xr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=N(r.getExpression());if(n===void 0||!cr.has(n))continue;const[o]=r.getArguments();if(o===void 0||!i.isObjectLiteralExpression(o))continue;let a;for(const c of o.getDescendantsOfKind(u.CallExpression))if(N(c.getExpression())==="tool"&&(a=gr(c),a!==void 0))break;a!==void 0&&s.push({exportName:h(r),file:t,line:r.getStartLineNumber(),method:n,sideEffect:a,userInputDerived:mr(o)})}return s},hr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...xr(n,f(t,r)))}return s},Er=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return i.isIdentifier(t)&&t.getText()==="ctx"},yr=(e,t)=>{if(!Er(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!w(s)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},Ar=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=yr(r,t);n&&s.push(n)}return s},$r=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ar(n,f(t,r)))}return s},Et=e=>e.getProperties().some(t=>i.isSpreadAssignment(t)),Nr=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!i.isPropertyAssignment(s))return{objects:[],opaque:!0};const r=s.getInitializer();return!r||!i.isObjectLiteralExpression(r)?{objects:[],opaque:!0}:{objects:[r],opaque:Et(r)}},Sr=e=>{const t=[];let s=!1,r=e;for(;i.isCallExpression(r);){const n=r.getExpression();if(!i.isPropertyAccessExpression(n))break;if(n.getName()==="input"){const o=r.getArguments()[0];o&&i.isObjectLiteralExpression(o)?(t.push(o),s||=Et(o)):s=!0}r=n.getExpression()}return{objects:t,opaque:s}},yt=(e,t)=>t?Sr(t):Nr(e),br=e=>e.flatMap(t=>t.getProperties().filter(s=>i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)).map(s=>s.getName())),vr=/\.check\(|\.meta\(|length|max/iu,Pr=/\bv\.any\s*\(/u,wr=/\bv\.string\s*\(/u,Ir=e=>Pr.test(e),Or=e=>wr.test(e)&&!vr.test(e),Lr=e=>{const t=[],s=[];for(const r of e)for(const n of r.getProperties()){if(!i.isPropertyAssignment(n))continue;const o=n.getInitializer();if(!o)continue;const a=o.getText(),c=n.getName();Ir(a)?t.push(c):Or(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Fr=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=K(s);if(r?.visibility!=="public")return;const{objects:n}=yt(s,r.receiver),{anyArgs:o,unboundedStringArgs:a}=Lr(n);if(!(o.length===0&&a.length===0))return{anyArgs:o,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Tr=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Fr(n,t);o&&s.push(o)}return s},Dr=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Tr(n,f(t,r)))}return s},S=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},xe=e=>e?.getKind()===u.TrueKeyword,Cr=e=>e?.getKind()===u.FalseKeyword,kr=e=>e!==void 0&&i.isNumericLiteral(e)&&e.getLiteralValue()===0,Kr=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Rr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isCallExpression(t)&&N(t.getExpression())==="scim"),Mr=e=>e!==void 0&&i.isCallExpression(e)&&Kr.has(N(e.getExpression())??""),jr=e=>!e||!i.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>i.isStringLiteral(t)&&t.getLiteralText()==="*"),zr=e=>{const t=S(e,"advanced"),s=S(e,"emailAndPassword"),r=S(e,"session");return{analyzable:!0,disableCsrfCheck:xe(S(t,"disableCSRFCheck")),emailPasswordEnabled:xe(S(s,"enabled")),requireEmailVerification:xe(S(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Rr(S(e,"plugins"))&&Mr(S(e,"database")),secureCookiesDisabled:Cr(S(t,"useSecureCookies")),sessionFreshAgeZero:kr(S(r,"freshAge")),trustedOriginsWildcard:jr(S(e,"trustedOrigins"))}},qr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Br=(e,t)=>{if(N(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],r=s!==void 0&&i.isObjectLiteralExpression(s)&&s.getProperties().some(o=>i.isSpreadAssignment(o)),n=s!==void 0&&i.isObjectLiteralExpression(s)&&!r?zr(s):qr();return{exportName:h(e),file:t,line:e.getStartLineNumber(),...n}},Vr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Br(r,t);n&&s.push(n)}return s},Ur=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Vr(n,f(t,r)))}return s},Wr=(e,t)=>{if(!i.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},Gr=(e,t,s)=>{const r=Wr(e.getExpression(),s);if(r===void 0)return;const n=e.getArguments()[s.argIndex];if(!(!n||!w(n)||T(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:r}},_r=(e,t,s)=>{const r=[];for(const n of e.getDescendantsOfKind(u.CallExpression)){const o=Gr(n,t,s);o&&r.push(o)}return r},J=(e,t,s)=>{const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(..._r(o,f(t,n),s))}return r},Hr=new Set(["content","pdf","scrape","screenshot"]),Jr=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Hr}),Qr=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Xr=new Set(["RateLimiter"]),Zr=new Set(["extend"]),At=e=>{const t=[],s=[];let r=!1;for(const n of e.getProperties()){if(i.isSpreadAssignment(n)){r=!0;continue}if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o),n.getInitializer()?.getKind()===u.TrueKeyword&&s.push(o);continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,presentKeys:t,trueKeys:s}},st=e=>e&&i.isObjectLiteralExpression(e)?At(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Yr=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!i.isReturnStatement(s))return;const r=s.getExpression();return r!==void 0&&i.isObjectLiteralExpression(r)?r:void 0},en=e=>{if(i.isObjectLiteralExpression(e))return e;if(i.isParenthesizedExpression(e)){const t=e.getExpression();return i.isObjectLiteralExpression(t)?t:void 0}return i.isBlock(e)?Yr(e):void 0},tn=e=>{const t=e&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,s=t&&en(t.getBody());return s?At(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},sn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=N(r.getExpression());n!==void 0&&(Qr.has(n)?s.push({callee:n,file:t,line:r.getStartLineNumber(),...st(r.getArguments()[0])}):Zr.has(n)&&s.push({callee:n,file:t,line:r.getStartLineNumber(),...tn(r.getArguments()[0])}))}for(const r of e.getDescendantsOfKind(u.NewExpression)){const n=N(r.getExpression());n===void 0||!Xr.has(n)||s.push({callee:n,file:t,line:r.getStartLineNumber(),...st(r.getArguments()[0])})}return s},rn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...sn(n,f(t,r)))}return s},rt="ctx.containers.",nn=e=>{if(!e.startsWith(rt))return!1;const t=e.slice(rt.length);return t.length>0&&!t.includes(".")},on=(e,t)=>J(e,t,{argIndex:0,matchReceiver:nn,methods:new Set(["get"])}),an=new Set(["allow","deny","setAllowed"]),cn=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&i.isPropertyAssignment(s)&&i.isTrueLiteral(s.getInitializerOrThrow())},un=(e,t)=>{const s=e.getExpression();if(!(!i.isPropertyAccessExpression(s)||s.getName()!=="start"||!cn(e)))return{detail:"enableInternet: true",exportName:h(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},ln=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||!an.has(s.getName()))return;const r=s.getExpression();if(!(!i.isPropertyAccessExpression(r)||r.getName()!=="egress"))return{detail:s.getName(),exportName:h(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},dn=(e,t)=>un(e,t)??ln(e,t),gn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=dn(r,t);n&&s.push(n)}return s},fn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...gn(n,f(t,r)))}return s},pn="env.ts",mn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return H(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},xn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const r=s.getFirstAncestorByKind(u.ImportDeclaration);return r!==void 0&&H(r.getModuleSpecifierValue())}return!1},hn=e=>{if(i.isIdentifier(e))return mn(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(t)&&xn(t)}return!1},En=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!hn(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw _(n,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},yn=(e,t)=>{const s=g(t,pn);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=En(r);if(n.length!==0){if(n.length>1)throw _(r,`lunora/env.ts declares ${n.length.toString()} defineEnv() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},An=new Set(["defineExportSink","r2Sink","webhookExportSink"]),$n=e=>{const t=e.getExpression();if(!i.isIdentifier(t))return;const s=t.getText();return An.has(s)?s:void 0},Nn=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}},Sn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){const c=$n(a);if(c===void 0)continue;const l=a.getArguments()[0],p=l&&i.isObjectLiteralExpression(l)?Nn(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},bn=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),vn=new Set(["dbRateLimit","rateLimit"]),Pn=e=>{if(!e||!i.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&i.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===u.TrueKeyword},wn=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},In=(e,t)=>{const s=N(e.getExpression());if(s===void 0)return;const r=bn.get(s);if(r!==void 0)return{callee:s,exportName:h(e),failOpen:Pn(e.getArguments()[r]),file:t,limitName:vn.has(s)?wn(e):"",line:e.getStartLineNumber()}},On=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=In(r,t);n&&s.push(n)}return s},Ln=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...On(n,f(t,r)))}return s},Fn=e=>{const t=r=>i.isIdentifier(r)&&r.getText()==="ctx",s=new Set;for(const r of e.getDescendantsOfKind(u.PropertyAccessExpression))t(r.getExpression())&&s.add(r.getName());for(const r of e.getDescendantsOfKind(u.VariableDeclaration)){const n=r.getInitializer(),o=r.getNameNode();if(!(n===void 0||!t(n)||!i.isObjectBindingPattern(o)))for(const a of o.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},Tn=(e,t)=>{const s=Object.fromEntries(pe.map(r=>[r.key,!1]));for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=new Set(n.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=Fn(n);for(const c of pe)if(!s[c.key]){if(o.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(pe.every(c=>s[c.key]))break}return s},Dn=["providerSubscriptionId","state"],Cn=["providerEventId","processedAt"],nt=(e,t)=>t.every(s=>s in e.shape),kn=e=>{const t=e.find(r=>r.name==="subscriptions"),s=e.find(r=>r.name==="events");return t!==void 0&&s!==void 0&&nt(t,Dn)&&nt(s,Cn)},Kn=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings/kv"),mail:e.mail||t.dependencies.has("@lunora/mail"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),Rn=e=>i.isIdentifier(e)&&e.getText()==="ctx",Mn=e=>{if(!i.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Rn(t.getExpression())},jn=e=>{if(e?.getKind()===u.TrueKeyword)return!0;if(e?.getKind()===u.FalseKeyword)return!1},zn=(e,t)=>{if(!Mn(e.getExpression()))return;const[s,r]=e.getArguments();if(!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s)))return;const n=s.getLiteralValue(),o=jn(r);if(!(n.length===0||o===void 0))return{defaultValue:o,exportName:h(e),file:t,key:n,line:e.getStartLineNumber()}},qn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=zn(r,t);n&&s.push(n)}return s},Bn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...qn(n,f(t,r)))}return s},Vn=e=>{const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Un=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},Wn=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression))Vn(a)&&s.push({file:o,indexName:Un(a),line:a.getStartLineNumber()})}return s},Gn=new Set(["delete","get","head","options","patch","post","put"]),_n=new Set(["handler","stream"]),Hn=new Set(["runAction","runMutation"]),Jn=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),U=(e,t)=>e!==void 0&&i.isIdentifier(e)&&e.getText()===t,it=e=>e!==void 0&&(i.isArrowFunction(e)||i.isFunctionExpression(e))?e:void 0,ot=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const r=s.getNameNode();if(t)return i.isIdentifier(r)?r.getText():void 0;if(i.isObjectBindingPattern(r)){for(const n of r.getElements())if((n.getPropertyNameNode()?.getText()??n.getNameNode().getText())==="ctx"){const o=n.getNameNode();return i.isIdentifier(o)?o.getText():void 0}}},at=(e,t)=>{const s=e.getBody(),r=s.getDescendantsOfKind(u.CallExpression);i.isCallExpression(s)&&r.unshift(s);for(const n of r){const o=n.getExpression();if(!i.isPropertyAccessExpression(o))continue;const a=o.getName(),c=o.getExpression();if(Hn.has(a)&&U(c,t))return a;if(Jn.has(a)&&i.isPropertyAccessExpression(c)&&c.getName()==="db"&&U(c.getExpression(),t))return`db.${a}`}},ct=(e,t)=>{const s=e.getBody();for(const r of s.getDescendantsOfKind(u.PropertyAccessExpression))if(r.getName()==="auth"&&U(r.getExpression(),t))return!0;for(const r of s.getDescendantsOfKind(u.VariableDeclaration)){const n=r.getNameNode();if(!(!i.isObjectBindingPattern(n)||!U(r.getInitializer(),t))){for(const o of n.getElements())if((o.getPropertyNameNode()?.getText()??o.getNameNode().getText())==="auth")return!0}}return!1},Qn=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!_n.has(t.getName()))return;let s=t.getExpression();for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))return;const n=r.getName();if(Gn.has(n)){const o=r.getExpression();return i.isIdentifier(o)&&o.getText()==="httpRoute"?n.toUpperCase():void 0}s=r.getExpression()}},Xn=(e,t)=>{const s=e.getExpression();if(i.isIdentifier(s)&&s.getText()==="httpAction"){const c=it(e.getArguments()[0]),l=c&&ot(c,!0);if(!c||l===void 0)return;const p=at(c,l);return p===void 0?void 0:{exportName:h(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ct(c,l),sideEffect:p}}const r=Qn(e);if(r===void 0)return;const n=it(e.getArguments()[0]),o=n&&ot(n,!1);if(!n||o===void 0)return;const a=at(n,o);return a===void 0?void 0:{exportName:h(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:r,readsAuth:ct(n,o),sideEffect:a}},Zn=(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(...Zn(n,f(t,r)))}return s},ei=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),ti=new Set(["append","set"]),$e=e=>i.isIdentifier(e)?e.getText():i.isPropertyAccessExpression(e)?e.getName():"",$t=e=>e!==void 0&&(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",ut=(e,t)=>(i.isCallExpression(e)?[e,...e.getDescendantsOfKind(u.CallExpression)]:e.getDescendantsOfKind(u.CallExpression)).some(s=>ei.has($e(s.getExpression()))&&B(s,t)),si=(e,t)=>{if(ut(e,t))return!0;const s=L(e);return s!==void 0&&ut(s,t)},ye=(e,t)=>rr(e,t)&&!si(e,t),ri=e=>{if(i.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=L(e);return t!==void 0&&i.isNewExpression(t)&&$e(t.getExpression())==="Headers"},W=e=>{if(e===void 0)return;if(i.isObjectLiteralExpression(e))return e;const t=L(e);return t!==void 0&&i.isObjectLiteralExpression(t)?t:void 0},Ne=(e,t,s)=>{for(const r of e.getProperties())if(i.isPropertyAssignment(r)){const n=r.getInitializer();n!==void 0&&ye(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:$t(r.getNameNode()),line:n.getStartLineNumber(),via:t})}else if(i.isShorthandPropertyAssignment(r)){const n=r.getNameNode();ye(n,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:r.getName(),line:n.getStartLineNumber(),via:t})}else if(i.isSpreadAssignment(r)){const n=W(r.getExpression());n!==void 0&&Ne(n,t,s)}},Nt=(e,t)=>{const s=W(e);if(s===void 0)return;const r=s.getProperty("headers");if(r===void 0||!i.isPropertyAssignment(r))return;const n=W(r.getInitializer());n!==void 0&&Ne(n,"response-init",t)},ni=(e,t)=>{const s=$e(e.getExpression());if(s==="Response")Nt(e.getArguments()[1],t);else if(s==="Headers"){const r=W(e.getArguments()[0]);r!==void 0&&Ne(r,"headers-ctor",t)}},ii=(e,t)=>{const s=e.getExpression();if(!i.isPropertyAccessExpression(s))return;const r=s.getName(),n=s.getExpression();if(r==="json"&&i.isIdentifier(n)&&n.getText()==="Response"){Nt(e.getArguments()[1],t);return}if(ti.has(r)&&ri(n)){const o=e.getArguments()[1];o!==void 0&&ye(o,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:$t(e.getArguments()[0]),line:o.getStartLineNumber(),via:r==="set"?"headers-set":"headers-append"})}},oi=(e,t)=>{for(const s of e.getDescendantsOfKind(u.NewExpression))ni(s,t);for(const s of e.getDescendantsOfKind(u.CallExpression))ii(s,t)},ai=(e,t)=>{const s=e.getExpression();if(!i.isIdentifier(s)||s.getText()!=="httpAction")return[];const r=Gt(e.getArguments()[0]);if(r===void 0)return[];const n=r.getParameters()[1];if(n===void 0)return[];const o=n.getNameNode();if(!i.isIdentifier(o))return[];const a=[];return oi(r,{exportName:h(e),relativePath:t,requestName:o.getText(),rows:a}),a},ci=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...ai(r,t));return s},ui=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ci(n,f(t,r)))}return s},St="identity.ts",li=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(i.isImportSpecifier(s))return H(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},di=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!i.isNamespaceImport(s))continue;const r=s.getFirstAncestorByKind(u.ImportDeclaration);return r!==void 0&&H(r.getModuleSpecifierValue())}return!1},gi=e=>{if(i.isIdentifier(e))return li(e);if(i.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&i.isIdentifier(t)&&di(t)}return!1},fi=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==u.CallExpression||!gi(r.getExpression()))continue;const n=s.getNameNode();if(!i.isIdentifier(n))throw _(n,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:n.getText()})}return t},pi=(e,t)=>{const s=g(t,St);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),n=fi(r);if(n.length!==0){if(n.length>1)throw _(r,`lunora/identity.ts declares ${n.length.toString()} defineIdentity() contracts (${n.map(o=>o.exportName).join(", ")}); exactly one is allowed`);return n[0]}},mi=new Set(["auth","context.auth","ctx.auth"]),xi="userId",hi=e=>{const t=new Set;for(const s of e.getProperties()){if(i.isSpreadAssignment(s))return;(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s))&&t.add(s.getName())}return t},Ei=(e,t)=>{const s=g(t,St);if(!E(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const n of r.getDescendantsOfKind(u.CallExpression)){if(N(n.getExpression())!=="defineIdentity")continue;const[o]=n.getArguments();return o&&i.isObjectLiteralExpression(o)?hi(o):void 0}},lt=e=>{if(!(e===void 0||!i.isPropertyAccessExpression(e)||e.getName()!=="identity"))return mi.has(e.getExpression().getText())?e:void 0},yi=e=>{if(i.isPropertyAccessExpression(e)&<(e.getExpression())!==void 0)return e.getName();if(i.isElementAccessExpression(e)&<(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&i.isStringLiteral(t)?t.getLiteralValue():void 0}},Ai=(e,t,s)=>{const r=[];for(const n of e.getDescendants()){const o=yi(n);o!==void 0&&r.push({declared:o===xi||s.has(o),exportName:h(n),file:t,key:o,line:n.getStartLineNumber()})}return r},$i=(e,t)=>{const s=Ei(e,t);if(s===void 0)return[];const r=[];for(const n of d(t)){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(...Ai(o,f(t,n),s))}return r},Ni=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Si=(e,t)=>{if(N(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const r=Ni(s);if(!(!r||!w(r)||T(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber()}},bi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Si(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(...bi(n,f(t,r)))}return s},Pi=new Set(["delete","get","getRaw","getWithMetadata","put"]),wi=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:Pi}),Ii=new Set(["queue","send"]),dt=new Set(["bcc","cc","to"]),Oi=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!Ii.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},Li=e=>i.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(i.isShorthandPropertyAssignment(t)){const r=t.getNameNode();return dt.has(t.getName())&&w(r)&&!T(r)}if(!i.isPropertyAssignment(t)||!dt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&w(s)&&!T(s)}):!1,Fi=(e,t)=>{const s=Oi(e.getExpression());if(s===void 0)return;const r=e.getArguments()[0];if(!(!r||!Li(r)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Ti=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Fi(r,t);n&&s.push(n)}return s},Di=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ti(n,f(t,r)))}return s},Ci=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},ki=e=>{const t=e.getArguments()[0];if(t===void 0||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("server");if(s!==void 0)return i.isPropertyAssignment(s)?s.getInitializer():s},Ki=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==u.CallExpression)return;const s=t;return Ss(s.getExpression())?s:void 0},Ri=e=>{const t=Ki(e),s=t===void 0?void 0:ki(t);if(s===void 0)return[];const r=e.getNameNode(),n=i.isIdentifier(r)?r.getText():"";return s.getDescendantsOfKind(u.CallExpression).filter(o=>Ci(o)).map(o=>({exportName:n,file:"lunora/mutators.ts",line:o.getStartLineNumber()}))},Mi=e=>e.getVariableDeclarations().flatMap(t=>Ri(t)),ji=(e,t)=>{const s=g(t,Ns);if(!E(s))return[];const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);return Mi(r)},zi=new Set(["delete","get","patch"]),qi=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Bi=new Set(["auth","identity","session","user"]),Vi=new Set([u.EqualsEqualsEqualsToken,u.EqualsEqualsToken,u.ExclamationEqualsEqualsToken,u.ExclamationEqualsToken]),Ui=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!k(t.getExpression()))return;const s=e.getArguments()[0];return s&&i.isStringLiteral(s)?s.getLiteralText():""},Wi=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(i.isAsExpression(s)||i.isParenthesizedExpression(s)||i.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!i.isVariableDeclaration(s))return;const r=s.getNameNode();return i.isIdentifier(r)?r.getText():void 0},Gi=(e,t)=>e.getDescendantsOfKind(u.Identifier).some(s=>s.getText()===t),_i=e=>i.isThrowStatement(e)||i.isReturnStatement(e)||e.getDescendantsOfKind(u.ThrowStatement).length>0||e.getDescendantsOfKind(u.ReturnStatement).length>0,Hi=(e,t)=>e.getDescendantsOfKind(u.IfStatement).some(s=>Gi(s.getExpression(),t)&&_i(s.getThenStatement())),Ji=(e,t)=>{for(const s of e.getDescendantsOfKind(u.CallExpression)){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))continue;const n=r.getName();if(!zi.has(n))continue;const o=r.getExpression();if(!(k(o)||i.isPropertyAccessExpression(o)&&k(o.getExpression())))continue;const a=s.getArguments()[0];if(a!==void 0&&i.isIdentifier(a)&&a.getText()===t)return n}},Qi=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},Xi=e=>e.getDescendantsOfKind(u.CallExpression).some(t=>t.getArguments().some(s=>Qi(s)==="ctx")),Zi=e=>e.getDescendantsOfKind(u.BinaryExpression).some(t=>Vi.has(t.getOperatorToken().getKind())?i.isPropertyAccessExpression(t.getLeft())||i.isPropertyAccessExpression(t.getRight()):!1),Yi=e=>{for(const t of e.getDescendantsOfKind(u.Identifier))if(qi.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(u.PropertyAccessExpression)){const s=t.getExpression();if(i.isIdentifier(s)&&s.getText()==="ctx"&&Bi.has(t.getName()))return!0}return Xi(e)||Zi(e)},eo=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const r=K(s);if(r?.kind!=="query"&&r?.kind!=="mutation")return[];const n=mt(s);if(n===void 0)return[];const o=r.receiver!==void 0&&xt(r.receiver,"use","rls"),a=Yi(n),c=new Set,l=[];for(const p of n.getDescendantsOfKind(u.CallExpression)){const y=Ui(p);if(y===void 0)continue;const I=Wi(p);if(I===void 0||c.has(I)||!Hi(n,I))continue;const R=Ji(n,I);R!==void 0&&(c.add(I),l.push({exportName:e.getName(),file:t,line:p.getStartLineNumber(),mentionsOwnership:a,sinkMethod:R,table:y,usesRls:o,visibility:r.visibility}))}return l},to=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...eo(c,o))}return s},so=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),ro=new Set(["insert","insertManyUnsafe","patch","replace"]),no=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(!ro.has(t))return;const s=e.getExpression();if(!i.isPropertyAccessExpression(s)||s.getName()!=="db")return;const r=s.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"?t:void 0},io=(e,t)=>{if(t!=="insertManyUnsafe")return i.isObjectLiteralExpression(e)?[e]:[];if(!i.isArrayLiteralExpression(e))return[];const s=[];for(const r of e.getElements())i.isObjectLiteralExpression(r)&&s.push(r);return s},oo=(e,t,s,r)=>{const n=[];for(const o of e.getProperties()){let a,c;i.isPropertyAssignment(o)?(a=o.getName(),c=o.getInitializer()):i.isShorthandPropertyAssignment(o)&&(a=o.getName(),c=o.getNameNode()),!(a===void 0||c===void 0||!so.has(a))&&w(c)&&!T(c)&&n.push({exportName:h(s),field:a,file:r,line:s.getStartLineNumber(),method:t})}return n},ao=(e,t)=>{const s=no(e.getExpression());if(s===void 0)return[];const r=e.getArguments()[1];return r?io(r,s).flatMap(n=>oo(n,s,e,t)):[]},co=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression))s.push(...ao(r,t));return s},uo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...co(n,f(t,r)))}return s},lo=e=>{const t=g(e,"package.json");if(!E(t))return new Set;try{const s=JSON.parse(Ae(t,"utf8")),r=new Set;for(const n of["dependencies","devDependencies","peerDependencies","optionalDependencies"]){const o=s[n];if(o!==null&&typeof o=="object")for(const a of Object.keys(o))r.add(a)}return r}catch{return new Set}},go=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),fo=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,po=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&i.isPropertyAssignment(t)?fo(t.getInitializer()):void 0},mo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=N(r.getExpression());if(n===void 0||!go.has(n))continue;const[o]=r.getArguments(),a=o&&i.isObjectLiteralExpression(o)?po(o):void 0;s.push({callee:n,exportName:h(r),file:t,line:r.getStartLineNumber(),...a===void 0?{}:{toleranceSeconds:a}})}return s},xo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...mo(n,f(t,r)))}return s},ho=new Set(["defineQueue","defineWorkflow"]),Eo=new Set(["run","runAction","runMutation","runQuery"]),yo=new Set(["api","internal"]),Ao=e=>{const t=e.getExpression();return i.isIdentifier(t)?t.getText():void 0},$o=e=>{const t=e.getArguments()[0];if(!t||!i.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!i.isPropertyAssignment(s))return;const r=s.getInitializer();if(r&&(i.isArrowFunction(r)||i.isFunctionExpression(r)))return r},bt=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&i.isIdentifier(s)?s.getText():void 0},vt=(e,t)=>e===t||e.startsWith(`${t}.`),Pt=e=>{const t=e.getDescendantsOfKind(u.PropertyAccessExpression);return i.isPropertyAccessExpression(e)&&t.push(e),t},gt=e=>{const t=e.getParent();return i.isPropertyAccessExpression(t)&&t.getNameNode()===e||i.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(i.isBindingElement(t)&&t.getNameNode()===e)},wt=e=>{const t=e.getDescendantsOfKind(u.Identifier).filter(s=>gt(s));return i.isIdentifier(e)&>(e)&&t.push(e),t},No=e=>{if(!i.isVariableDeclaration(e))return[];const t=e.getNameNode();return i.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(u.BindingElement).map(s=>s.getName())},So=e=>{const t=bt(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},bo=(e,t,s)=>{const r=t==="workflow"?[`${s}.params`]:So(e),n=new Set,o=a=>Pt(a).some(c=>r.some(l=>vt(c.getText(),l)))?!0:wt(a).some(c=>n.has(c.getText()));for(const a of e.getDescendantsOfKind(u.VariableDeclaration)){const c=a.getInitializer();if(c&&o(c))for(const l of No(a))n.add(l)}return{names:n,prefixes:r}},vo=(e,t)=>Pt(e).some(s=>t.prefixes.some(r=>vt(s.getText(),r)))?!0:wt(e).some(s=>t.names.has(s.getText())),Po=e=>{if(e===void 0||!i.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;i.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const r=t.at(-1);if(!(r===void 0||!i.isIdentifier(s)||!yo.has(s.getText())||t.length<2))return{exportName:r,file:t.slice(0,-1).join("/")}},wo=(e,t,s)=>{const r=bt(e,0);if(r===void 0)return[];const n=bo(e,t,r),o=[];for(const a of e.getDescendantsOfKind(u.CallExpression)){const c=a.getExpression();if(!i.isPropertyAccessExpression(c)||!Eo.has(c.getName())||c.getExpression().getText()!==r)continue;const l=a.getArguments()[1];if(!l||!vo(l,n))continue;const p=Po(a.getArguments()[0]);p!==void 0&&o.push({dispatchKind:t,file:s,handlerExport:h(a),line:a.getStartLineNumber(),targetExport:p.exportName,targetFile:p.file})}return o},Io=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ao(r);if(n===void 0||!ho.has(n))continue;const o=$o(r);o!==void 0&&s.push(...wo(o,n==="defineQueue"?"queue":"workflow",t))}return s},Oo=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Io(n,f(t,r)))}return s},ft={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},Lo=/account|credential|member|passkey|session|user/iu,Fo=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},To=(e,t)=>{const{objects:s,opaque:r}=yt(e,t);return br(s).some(n=>Fo(n))?!0:r?void 0:!1},It=e=>{const t=e.getExpression();if(i.isIdentifier(t))return t.getText();if(i.isPropertyAccessExpression(t))return t.getName()},Do=e=>{const t=e.getArguments()[0];return!t||!i.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Co=e=>{if(i.isCallExpression(e))return e;if(!i.isIdentifier(e))return;const t=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return t&&i.isCallExpression(t)?t:void 0},V={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},ko=e=>{const t=Co(e),s=t?It(t):void 0;if(t&&s==="protectPublic"){const r=Do(t);return{...V,usesCaptcha:r.usesCaptcha,usesRateLimit:r.usesRateLimit}}return s!==void 0&&s in ft?{...V,[ft[s]]:!0}:V},Ko=e=>{const t={...V};let s=e;for(;i.isCallExpression(s);){const r=s.getExpression();if(!i.isPropertyAccessExpression(r))break;const n=r.getName()==="use"?s.getArguments()[0]:void 0;if(n){const o=ko(n);t.usesCaptcha||=o.usesCaptcha,t.usesEmailGate||=o.usesEmailGate,t.usesMask||=o.usesMask,t.usesRateLimit||=o.usesRateLimit,t.usesRls||=o.usesRls}s=r.getExpression()}return t},Ro=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insert")return!1;const s=t.getExpression();if(!(i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"))return!1;const r=e.getArguments()[0];return!!(r&&i.isStringLiteral(r)&&Lo.test(r.getLiteralText()))},Mo=new Set(["create","runAfter","runAt","send","sendBatch"]),jo=new Set(["queues","scheduler","workflows"]),zo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Mo.has(t.getName()))return!1;let s=t.getExpression();for(;i.isCallExpression(s)||i.isElementAccessExpression(s)||i.isPropertyAccessExpression(s);){if(i.isPropertyAccessExpression(s)&&jo.has(s.getName())){const r=s.getExpression();if(i.isIdentifier(r)&&r.getText()==="ctx")return!0}s=s.getExpression()}return!1},qo=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="db":i.isIdentifier(s)&&s.getText()==="db"},Bo=new Set(["generateObject","generateText","streamObject","streamText"]),Vo=e=>{const t=It(e);if(t===void 0||!Bo.has(t))return!1;const s=e.getArguments()[0];return!s||!i.isObjectLiteralExpression(s)||s.getProperties().some(r=>i.isSpreadAssignment(r))?!1:!s.getProperty("maxOutputTokens")},Uo=e=>e.getDescendantsOfKind(u.PropertyAccessExpression).some(t=>{const s=t.getName();if(s!=="mail"&&s!=="email")return!1;const r=t.getExpression();return i.isIdentifier(r)&&r.getText()==="ctx"}),Wo=e=>{let t=!1,s=!1,r=!1,n=!1;for(const o of e.getDescendantsOfKind(u.CallExpression))if(Ro(o)&&(n=!0),zo(o)&&(t=!0),qo(o)&&(r=!0),Vo(o)&&(s=!0),n&&t&&r&&s)break;return{callsMail:Uo(e),fanOut:t,unboundedAiGeneration:s,usesInsertManyUnsafe:r,writesUserTable:n}},Go=(e,t)=>{const s=e.getInitializer();if(!s||!i.isCallExpression(s))return;const r=K(s);if(!r||r.kind!=="query"&&r.kind!=="mutation"&&r.kind!=="action")return;const n=r.receiver?Ko(r.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},{callsMail:o,fanOut:a,unboundedAiGeneration:c,usesInsertManyUnsafe:l,writesUserTable:p}=Wo(e);return{callsMail:o,exportName:e.getName(),fanOut:a,file:t,hasEmailArg:To(s,r.receiver),kind:r.kind,unboundedAiGeneration:c,usesCaptcha:n.usesCaptcha,usesEmailGate:n.usesEmailGate,usesInsertManyUnsafe:l,usesMask:n.usesMask,usesRateLimit:n.usesRateLimit,usesRls:n.usesRls,visibility:r.visibility,writesUserTable:p}},_o=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations()){const o=Go(n,t);o&&s.push(o)}return s},Ho=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(..._o(n,f(t,r)))}return s},Jo=new Set(["dbRateLimit","rateLimit"]),Qo=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("key");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Xo=e=>{const t=e.getArguments()[1];return t&&i.isStringLiteral(t)?t.getLiteralValue():""},Zo=e=>i.isArrowFunction(e)?e.getBody():e,Yo=(e,t)=>{const s=N(e.getExpression());if(s===void 0||!Jo.has(s))return;const r=e.getArguments()[2];if(!r)return;const n=Qo(r);if(!n)return;const o=Zo(n);if(!(!w(o)||T(o)))return{callee:s,exportName:h(e),file:t,limitName:Xo(e),line:e.getStartLineNumber()}},ea=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Yo(r,t);n&&s.push(n)}return s},ta=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ea(n,f(t,r)))}return s},sa=new Set(["findFirst","findFirstOrThrow","findMany","get"]),ra=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!sa.has(t.getName()))return;const s=t.getExpression();if(k(s)){const r=e.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}if(i.isPropertyAccessExpression(s)&&k(s.getExpression()))return s.getName()},na=e=>{let t=e;for(;i.isCallExpression(t);){const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&k(s.getExpression())){const r=t.getArguments()[0];return r&&i.isStringLiteral(r)?r.getLiteralText():""}t=s.getExpression()}},ia=e=>{let t=e;for(;i.isAwaitExpression(t)||i.isParenthesizedExpression(t)||i.isNonNullExpression(t)||i.isAsExpression(t);)t=t.getExpression();return t},Ot=(e,t=!1)=>{const s=ia(e);if(i.isIdentifier(s)){if(t)return;const r=L(s);return r===void 0?void 0:Ot(r,!0)}if(i.isCallExpression(s))return ra(s)??na(s)},oa=e=>{const t=e.getBody();if(!i.isBlock(t))return[t];const s=[];for(const r of e.getDescendantsOfKind(u.ReturnStatement)){const n=r.getFirstAncestor(a=>i.isArrowFunction(a)||i.isFunctionExpression(a)||i.isFunctionDeclaration(a)),o=r.getExpression();n===e&&o!==void 0&&s.push(o)}return s},aa=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!i.isCallExpression(s))return[];const r=K(s);if(r?.kind!=="query")return[];const n=mt(s);if(n===void 0)return[];const o=r.receiver!==void 0&&_t(r.receiver,"output"),a=r.receiver!==void 0&&xt(r.receiver,"use","mask"),c=new Set,l=[];for(const p of oa(n)){const y=Ot(p);y===void 0||c.has(y)||(c.add(y),l.push({exportName:e.getName(),file:t,line:p.getStartLineNumber(),table:y,usesMask:a,usesOutput:o,visibility:r.visibility}))}return l},ca=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...aa(c,o))}return s},ua=new Set(["findFirst","findFirstOrThrow","findMany"]),la=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!ua.has(t.getName()))return;const s=t.getExpression();if(i.isPropertyAccessExpression(s)&&s.getName()==="db"||i.isIdentifier(s)&&s.getText()==="db"){const r=e.getArguments()[0];return{options:e.getArguments()[1],table:r&&i.isStringLiteral(r)?r.getLiteralText():""}}if(i.isPropertyAccessExpression(s)){const r=s.getExpression();if(i.isPropertyAccessExpression(r)&&r.getName()==="db"||i.isIdentifier(r)&&r.getText()==="db")return{options:e.getArguments()[0],table:s.getName()}}},da=e=>{if(!e||!i.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(i.isPropertyAssignment(s)||i.isShorthandPropertyAssignment(s)||i.isMethodDeclaration(s)||i.isGetAccessorDeclaration(s))&&t.push(s.getName());return t},ga=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},fa=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&i.isCallExpression(s)?K(s):void 0;if(!r)return[];const n=[];for(const o of e.getDescendantsOfKind(u.CallExpression)){const a=la(o);if(a===void 0)continue;const c=da(ga(a.options,"with"));c.length!==0&&n.push({exportName:e.getName(),file:t,line:o.getStartLineNumber(),parentTable:a.table,relations:c,visibility:r.visibility})}return n},pa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...fa(c,o))}return s},G=e=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(i.isBinaryExpression(e)&&e.getOperatorToken().getKind()===u.PlusToken){const t=G(e.getLeft()),s=G(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},ma=e=>{let t=e,s=t.getParent();for(;s!==void 0&&i.isBinaryExpression(s)&&s.getOperatorToken().getKind()===u.PlusToken;)t=s,s=t.getParent();return t!==e&&G(t)!==void 0},xa=(e,t)=>{const s=[],r=[...e.getDescendantsOfKind(u.BinaryExpression),...e.getDescendantsOfKind(u.StringLiteral),...e.getDescendantsOfKind(u.NoSubstitutionTemplateLiteral)],n=new Set;for(const o of r){if(ma(o))continue;const a=G(o);if(a===void 0)continue;const c=ks(a);if(c===void 0)continue;const l=o.getStartLineNumber(),p=`${String(l)}:${c}`;n.has(p)||(n.add(p),s.push({file:t,kind:c,line:l,preview:Ks(a)}))}return s},ha=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...xa(n,f(t,r)))}return s},Ea=new Set(["findFirst","findFirstOrThrow","findMany"]),ya=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||!Ea.has(t.getName()))return;const s=t.getExpression();if(i.isPropertyAccessExpression(s)&&s.getName()==="db"||i.isIdentifier(s)&&s.getText()==="db"){const r=e.getArguments()[0];return{options:e.getArguments()[1],table:r&&i.isStringLiteral(r)?r.getLiteralText():""}}if(i.isPropertyAccessExpression(s)){const r=s.getExpression();if(i.isPropertyAccessExpression(r)&&r.getName()==="db"||i.isIdentifier(r)&&r.getText()==="db")return{options:e.getArguments()[0],table:s.getName()}}},Aa=(e,t)=>{if(!e||!i.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},$a=(e,t)=>{if(!i.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&i.isCallExpression(s)?K(s):void 0;if(!r)return[];const n=[];for(const o of e.getDescendantsOfKind(u.CallExpression)){const a=ya(o);if(a===void 0)continue;const c=Aa(a.options,"includeDeleted");if(c===void 0)continue;const l=i.isTrueLiteral(c),p=!l&&w(c);!l&&!p||n.push({exportName:e.getName(),file:t,fromArgs:p,hardcodedTrue:l,line:o.getStartLineNumber(),table:a.table,visibility:r.visibility})}return n},Na=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...$a(c,o))}return s},Sa=new Set(["query","unsafe"]),ba=e=>{if(!i.isPropertyAccessExpression(e)||!Sa.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"},va=e=>i.isBinaryExpression(e)||i.isTemplateExpression(e),Pa=e=>e.getFirstAncestorByKind(u.VariableDeclaration)?.getName()??"<module>",wa=(e,t)=>{if(!ba(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!va(s)))return{exportName:Pa(e),file:t,line:s.getStartLineNumber()}},Ia=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=wa(r,t);n&&s.push(n)}return s},Oa=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ia(n,f(t,r)))}return s},La=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Fa=(e,t)=>J(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.storage"||s.startsWith("ctx.storage."),methods:La}),Ta=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Da=e=>e&&i.isNumericLiteral(e)?Number(e.getText()):void 0,Ca=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!i.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,r=!1;for(const n of e.getProperties()){if(i.isSpreadAssignment(n)){r=!0;continue}if(i.isPropertyAssignment(n)){const o=n.getName();t.push(o),o==="expiresInSeconds"&&(s=Da(n.getInitializer()));continue}(i.isShorthandPropertyAssignment(n)||i.isMethodDeclaration(n))&&t.push(n.getName())}return{analyzable:!r,expiresInSeconds:s,presentKeys:t}},ka=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName(),s=Ta.get(t);if(s===void 0)return;const r=e.getExpression().getText();return r==="ctx.storage"||r.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},Ka=(e,t)=>{const s=ka(e.getExpression());if(s!==void 0)return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s.method,...Ca(e.getArguments()[s.optionsIndex])}},Ra=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Ka(r,t);n&&s.push(n)}return s},Ma=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ra(n,f(t,r)))}return s},ja=new Set(["when","where"]),he=new Set(["definePolicy","defineShape"]),za=e=>{if(!i.isCallExpression(e))return;const t=e.getExpression();if(i.isPropertyAccessExpression(t)){const r=t.getName();return he.has(r)?r:void 0}if(!i.isIdentifier(t))return;for(const r of t.getSymbol()?.getDeclarations()??[])if(i.isImportSpecifier(r)){const n=r.getNameNode().getText();return he.has(n)?n:void 0}const s=t.getText();return he.has(s)?s:void 0},qa=e=>i.isObjectLiteralExpression(e)&&e.getProperties().length===0,Lt=e=>{if(e!==void 0){if(i.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===u.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(qa(e))return"empty-object";if(i.isParenthesizedExpression(e))return Lt(e.getExpression())}},Ft=e=>e.getAncestors().find(t=>i.isArrowFunction(t)||i.isFunctionExpression(t)||i.isFunctionDeclaration(t)),Tt=e=>e.getDescendantsOfKind(u.ReturnStatement).filter(t=>Ft(t)===e),Dt=e=>e.getDescendantsOfKind(u.ConditionalExpression).filter(t=>Ft(t)===e),Ba=e=>{const t=Tt(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(u.IfStatement)!==void 0)||Dt(e).length>0},Va=e=>{const t=[],s=e.getBody();i.isBlock(s)||t.push(s);for(const r of Tt(e)){const n=i.isReturnStatement(r)?r.getExpression():void 0;t.push(n??r)}for(const r of Dt(e))t.push(r.getWhenTrue(),r.getWhenFalse());return t},Ua=e=>{for(const t of e.getAncestors())if(i.isVariableDeclaration(t)){const s=t.getNameNode();if(i.isIdentifier(s))return s.getText()}return"<anonymous>"},Wa=(e,t,s)=>{if(!i.isCallExpression(e))return[];const[r]=e.getArguments();if(!r||!i.isObjectLiteralExpression(r))return[];const n=[];for(const o of r.getProperties()){if(!i.isPropertyAssignment(o)||!ja.has(o.getName()))continue;const a=o.getInitializer();if(!(!a||!(i.isArrowFunction(a)||i.isFunctionExpression(a)))&&Ba(a))for(const c of Va(a)){const l=Lt(c);l!==void 0&&n.push({exportName:Ua(e),file:s,form:l,key:o.getName(),line:c.getStartLineNumber(),owner:t})}}return n},Ga=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=za(r);n!==void 0&&s.push(...Wa(r,n,t))}return s},_a=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ga(n,f(t,r)))}return s},Ha=new Set(["query","upsert","upsertMany"]),Ja=e=>{if(!i.isPropertyAccessExpression(e))return;const t=e.getName();if(Ha.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},Qa=e=>{if(!i.isObjectLiteralExpression(e))return;const t=e.getProperty("namespace");return t&&i.isPropertyAssignment(t)?t.getInitializer():void 0},Xa=(e,t)=>{const s=Ja(e.getExpression());if(s===void 0)return;const r=e.getArguments()[1];if(!r)return;const n=Qa(r);if(!(!n||!w(n)||T(n)))return{exportName:h(e),file:t,line:e.getStartLineNumber(),method:s}},Za=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(u.CallExpression)){const n=Xa(r,t);n&&s.push(n)}return s},Ya=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Za(n,f(t,r)))}return s},ec=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return i.isPropertyAccessExpression(s)?s.getName()==="workflows":i.isIdentifier(s)&&s.getText()==="workflows"},tc=e=>{const t=e.getArguments()[0];return t&&i.isStringLiteral(t)?t.getLiteralText():""},sc=(e,t)=>{const s=[];for(const r of d(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),o=f(t,r);for(const a of n.getDescendantsOfKind(u.CallExpression)){if(!ec(a))continue;const c=js(a);c!==""&&s.push({exportName:c,file:o,line:a.getStartLineNumber(),workflow:tc(a)})}}return s},rc=".lunora-schema.json",$=(e,t)=>{E(e)&&Ae(e,"utf8")===t||Vt(e,t,"utf8")},P=(e,t)=>{if(t===""){Ut(e,{force:!0});return}$(e,t)},nc=e=>{const t=g(e,"package.json");if(E(t))try{const s=JSON.parse(Ae(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},ic=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},oc=e=>{let t=E(e)?e:ge(e);for(;t&&t!==ge(t);){const s=g(t,"tsconfig.json");if(E(s))return s;t=ge(t)}},pt=e=>e.replaceAll("\\","/"),ac=(e,t)=>{const s=new Map,r=new Map,n=new Map;for(const o of e)s.set(o.name,`workflow "${o.exportName}"`),r.set(o.bindingName,`workflow "${o.exportName}"`),n.set(o.className,`workflow "${o.exportName}"`);for(const o of t){const a=s.get(o.name);if(a!==void 0)throw new q("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${o.name}": produced by both ${a} and agent "${o.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=r.get(o.bindingName);if(c!==void 0)throw new q("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${o.bindingName}": produced by both ${c} and agent "${o.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const l=n.get(o.className);if(l!==void 0)throw new q("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${o.className}": produced by both ${l} and agent "${o.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},cc=e=>{const t=oc(e);return t?new Xe({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Xe({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},Gc=(e,t)=>{const s=d(t),r=g(t,"schema.ts");E(r)&&s.push(r);for(const c of s){const l=e.getSourceFile(c);l===void 0?e.addSourceFileAtPath(c):l.refreshFromFileSystemSync()}const n=new Set(s.map(c=>pt(c))),o=pt(t),a=`${o}/`;for(const c of e.getSourceFiles()){const l=c.getFilePath();(l===o||l.startsWith(a))&&!n.has(l)&&e.removeSourceFile(c)}},_c=e=>{const t=ic(),s=t?fe.now():0,r=g(e.projectRoot,e.lunoraDirectory??"lunora"),n=g(r,"schema.ts");if(!E(n))throw new q("INTERNAL",`schema.ts not found at ${n}`);const o=e.project??cc(r),a=Cs(o,n,e.projectRoot),c=Ht(o,r),l=xs(o,r),p=$s(o,r),y=Rs(o,r),I=bs(o,r),R=pi(o,r),Se=yn(o,r),b=zs(o,r),D=Os(o,r),v=Jt(o,r);ac(b,v);const Q=Zt(o,r,b,v),C=Xt(o,r),be=e.lint===!1?[]:Wt({adminRoutes:tr(o,r),aiRawRuns:ar(o,r),aiToolSideEffects:hr(o,r),argumentDerivedFetches:$r(o,r),argumentValidators:Dr(o,r),authApiCalls:Qt(o,r),authConfigs:Ur(o,r),browserUrlAccesses:Jr(o,r),configCalls:rn(o,r),containerKeyAccesses:on(o,r),containerOverrides:fn(o,r),containers:C,exportSinks:Sn(o,r),failOpenGuards:Ln(o,r),flagSecurityDefaults:Bn(o,r),geoIndexUsages:Wn(o,r),httpActionGuards:Yn(o,r),httpHeaderWrites:ui(o,r),identityClaimReads:$i(o,r),imageDeliveryUrlAccesses:vi(o,r),inserts:hs(o,r),kvKeyAccesses:wi(o,r),mailRecipientAccesses:Di(o,r),maskProcedures:Es(o,r),maskStrategies:ys(o,r),mutatorWrites:ji(o,r),nondeterministicCalls:vs(o,r),normalizeIdAuthorizations:to(o,r),notifyCalls:ws(o,r),notifyConfig:Ps(o,r),ownerFieldWrites:uo(o,r),unrestrictedWhereBranches:_a(o,r),paymentWebhooks:xo(o,r),privilegedDispatches:Oo(o,r),procedureProtections:Ho(o,r),queries:Is(o,r),queues:D,r2sqlCalls:Ls(o,r),ratelimitKeySelectors:ta(o,r),rawRowReturns:ca(o,r),relationLoads:pa(o,r),rlsProcedures:Fs(o,r),schema:a,secretLiterals:ha(o,r),shapes:y,softDeleteReads:Na(o,r),sqlInterpolations:Oa(o,r),storageKeyAccesses:Fa(o,r),storageUploads:Ma(o,r),vectorNamespaceAccesses:Ya(o,r),workflowCalls:sc(o,r),workflows:b,wranglerVariables:e.wranglerVariables}),Ct=Ts(o,r),kt=As(o,r),X=Ms(o,r),A=Tn(o,r),Z=A.ai,Y=A.payments,ve=A.kv,Pe=A.access,ee=E(g(r,"flags.ts")),Kt=ee?ms(o,r):[],te=E(g(r,"notify.ts")),se=A.hyperdrive,re=Ds(o,r),Rt=re.usesSandboxBrowser||re.usesSandboxContainer,ne=A.browser||re.usesSandboxBrowser,ie=A.images,oe=A.analytics,we=A.pipelines,ae=A.r2sql,ce=A.x402,O=lo(e.projectRoot),M=Kn(A,{containerCount:C.length,cronCount:Q.length,dependencies:O,hasPaymentTables:kn(a.tables),queueCount:D.length,storageColumnCount:Object.keys(Yt(a)).length,storageRuleCount:X.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:b.length}),F=O.has("lunorash"),Ie=t?fe.now():0,Oe=es(a,F),Le=ts({agents:v,functions:c,httpRoutes:l,mutators:I,useUmbrella:F,workflows:b}),Fe=ss({agents:v,containers:C,env:Se,hasAccessFacade:Pe,hasAi:Z,hasAnalytics:oe,hasBrowser:ne,hasFlags:ee,hasHyperdrive:se,hasImages:ie,hasKv:ve,hasNotify:te,hasPayments:Y,hasPipelines:we,hasR2sql:ae,hasX402:ce,identity:R,queues:D,schema:a,storageRuleBuckets:X.rules.map(m=>m.bucket),useUmbrella:F,workflows:b}),Te=rs({agents:v,functions:c,migrations:p,mutators:I,shapes:y,useUmbrella:F,usesSandbox:Rt}),De=ns({advisories:be,agents:v,containers:C,env:Se,flagKeys:Kt,hasAccessFacade:Pe,hasAi:Z,hasAnalytics:oe,hasBrowser:ne,hasFlags:ee,hasHyperdrive:se,hasImages:ie,hasKv:ve,hasNotify:te,hasPayments:Y,hasPipelines:we,hasR2sql:ae,hasX402:ce,maskMetadata:kt,mutators:I,queues:D,rlsMetadata:Ct,schema:a,shapes:y,storageRules:X,studioFeatures:M,useUmbrella:F,workflows:b}),Ce=is(y,O.has("@lunora/db"),F),ke=os(C,a.jurisdiction),Ke=as(b),Re=cs(v),Me=us(D),je=ls(Q),ze=ds(a.vectorIndexes),j=gs(a,F),qe=fs(O.has("@lunora/seed")),z=e.apiSpec??"openapi",ue=z==="openapi"||z==="both",le=z==="openrpc"||z==="both",Be=qs({emailAgents:v.filter(m=>m.onEmail===!0).map(m=>({bindingName:m.bindingName,exportName:m.exportName})),hasAccess:O.has("@lunora/cloudflare-access"),hasAi:Z,hasAnalytics:oe,hasAuth:O.has("@lunora/auth"),hasBrowser:ne,hasFramework:O.has("@lunora/astro")||O.has("@lunora/svelte")||O.has("@lunora/vue"),hasGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend!=="hyperdrive"),hasHyperdrive:se,hasHyperdriveGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend==="hyperdrive"),hasImages:ie,hasKv:M.kv,hasNotify:te,hasPayments:Y,hasR2sql:ae,hasQueue:D.some(m=>m.mode==="push"),hasScheduler:M.scheduler,hasStorage:M.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:b.length>0,hasX402:ce,identity:R,jurisdiction:a.jurisdiction,useUmbrella:F,voiceAgents:v.filter(m=>m.voice===!0&&m.voiceBindingName!==void 0).map(m=>({bindingName:m.voiceBindingName,exportName:m.exportName})),wantsOpenApi:ue,wantsOpenRpc:le}),Ve=nc(e.projectRoot),Ue=Bs({functions:c,httpRoutes:l,version:Ve}),We=Us({functions:c,version:Ve}),Ge=`${JSON.stringify(Ue,void 0,2)}
|
|
2
2
|
`,_e=`${JSON.stringify(We,void 0,2)}
|
|
3
|
-
`,He=Vs(Ue),Je=Ws(We),Qe=Gs(a,p.map(m=>m.id)),de=g(r,rc),Mt=E(de),x=g(r,"_generated");if(e.dryRun||(E(x)||Bt(x,{recursive:!0}),$(g(x,"app.ts"),Be),$(g(x,"dataModel.ts"),Oe),$(g(x,"api.ts"),Le),$(g(x,"server.ts"),Fe),$(g(x,"functions.ts"),Te),$(g(x,"shard.ts"),De),$(g(x,"crons.ts"),je),$(g(x,"vectors.ts"),ze),$(g(x,"drizzle.global.ts"),j.global),$(g(x,"drizzle.shard.ts"),j.shard),P(g(x,"containers.ts"),ke),P(g(x,"workflows.ts"),Ke),P(g(x,"agents.ts"),Re),P(g(x,"queues.ts"),Me),P(g(x,"seed.ts"),qe),P(g(x,"collections.ts"),Ce),P(g(x,"openapi.json"),ue?Ge:""),P(g(x,"openapi.ts"),ue?He:""),P(g(x,"openrpc.json"),le?_e:""),P(g(x,"openrpc.ts"),le?Je:""),(!Mt||e.updateSchemaBaseline===!0)&&$(de,_s(Qe))),t){const m=fe.now(),jt=Math.round(m-s),zt=Math.round(Ie-s),qt=Math.round(m-Ie);console.error(`@lunora/codegen: codegen took ${jt.toString()}ms (discovery ${zt.toString()}ms, emit ${qt.toString()}ms)`)}return{advisories:
|
|
3
|
+
`,He=Vs(Ue),Je=Ws(We),Qe=Gs(a,p.map(m=>m.id)),de=g(r,rc),Mt=E(de),x=g(r,"_generated");if(e.dryRun||(E(x)||Bt(x,{recursive:!0}),$(g(x,"app.ts"),Be),$(g(x,"dataModel.ts"),Oe),$(g(x,"api.ts"),Le),$(g(x,"server.ts"),Fe),$(g(x,"functions.ts"),Te),$(g(x,"shard.ts"),De),$(g(x,"crons.ts"),je),$(g(x,"vectors.ts"),ze),$(g(x,"drizzle.global.ts"),j.global),$(g(x,"drizzle.shard.ts"),j.shard),P(g(x,"containers.ts"),ke),P(g(x,"workflows.ts"),Ke),P(g(x,"agents.ts"),Re),P(g(x,"queues.ts"),Me),P(g(x,"seed.ts"),qe),P(g(x,"collections.ts"),Ce),P(g(x,"openapi.json"),ue?Ge:""),P(g(x,"openapi.ts"),ue?He:""),P(g(x,"openrpc.json"),le?_e:""),P(g(x,"openrpc.ts"),le?Je:""),(!Mt||e.updateSchemaBaseline===!0)&&$(de,_s(Qe))),t){const m=fe.now(),jt=Math.round(m-s),zt=Math.round(Ie-s),qt=Math.round(m-Ie);console.error(`@lunora/codegen: codegen took ${jt.toString()}ms (discovery ${zt.toString()}ms, emit ${qt.toString()}ms)`)}return{advisories:be,agents:v,containers:C,cronTriggers:ps(Q),generated:{agents:Re,api:Le,app:Be,collections:Ce,containers:ke,crons:je,dataModel:Oe,drizzleGlobal:j.global,drizzleShard:j.shard,functions:Te,openApi:Ge,openApiModule:He,openRpc:_e,openRpcModule:Je,queues:Me,seed:qe,server:Fe,shard:De,vectors:ze,workflows:Ke},outputDirectory:x,queues:D,schemaSnapshot:Qe,schemaSnapshotPath:de,workflows:b}};export{rc as SCHEMA_SNAPSHOT_FILENAME,cc as createCodegenProject,Gc as refreshCodegenProject,_c as runCodegen};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{w as v}from"./emit-D7VIjvlm.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]),w=e=>e.replaceAll(y,"{$1}"),N=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=N(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=w(a.path),i=r[s]??{};i[a.method.toLowerCase()]=E(a),r[s]=i,o.add(c(a.filePath))}const n=e.functions.filter(a=>a.visibility!=="internal"&&a.kind!=="stream");for(const a of n){const{operation:s,pathKey:i}=L(a);r[i]={post:s},o.add(c(a.filePath))}for(const a of n){if(a.expose?.rest!==!0)continue;const s=I(a);if(s===void 0)continue;const i=r[s.path]??{};i[s.method]=s.operation,r[s.path]=i,o.add(c(a.filePath))}const p=[...o].toSorted((a,s)=>a.localeCompare(s)).map(a=>({description:`Operations declared in \`lunora/${a}\`.`,name:a}));return{components:{responses:{LunoraError:{content:{"application/json":{schema:{additionalProperties:!1,description:"Standard Lunora error envelope.",properties:{error:{additionalProperties:!1,properties:{code:{description:"Machine-readable error code. Clients switch on this value.",enum:S,type:"string"},message:{description:"Human-readable error message (never echoes internal details).",type:"string"}},required:["code","message"],type:"object"}},required:["error"],type:"object"}}},description:"A Lunora error response. The HTTP status reflects the error code (e.g. BAD_REQUEST→400, UNAUTHORIZED→401, FORBIDDEN→403, NOT_FOUND→404)."}}},info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora API",version:t},openapi:"3.1.0",paths:r,tags:p}},U=e=>`${JSON.stringify(D(e),void 0,2)}
|
|
2
|
+
`,W=e=>`${v}export const openApiSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
|
|
3
|
+
`;export{D as buildOpenApiDocument,U as emitOpenApi,W as emitOpenApiModule};
|
package/dist/packem_shared/{discoverAuthApiCalls-Ba6W92HB.mjs → discoverAuthApiCalls-CEk3J0kc.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-DnqHgv0t.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 L}from"@lunora/errors";import{isValidCronExpression as A,compileCronSchedule as b,CRON_SCHEDULE_KINDS as O}from"@lunora/scheduler";import{SyntaxKind as p,Node as n}from"ts-morph";import{diagnosticAt as f}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{listLunoraSourceFiles as S}from"./discoverFunctions-
|
|
1
|
+
import{LunoraError as L}from"@lunora/errors";import{isValidCronExpression as A,compileCronSchedule as b,CRON_SCHEDULE_KINDS as O}from"@lunora/scheduler";import{SyntaxKind as p,Node as n}from"ts-morph";import{diagnosticAt as f}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{listLunoraSourceFiles as S}from"./discoverFunctions-DnqHgv0t.mjs";import{E as $}from"./module-specifiers-8FEEiUcv.mjs";import{n as I}from"./paths-BmX5O1sG.mjs";const j=new Set([...O,"cron"]),y=e=>{const t=e.getSymbol();if(!t)return e.getText()==="cronJobs";for(const r of t.getDeclarations())if(n.isImportSpecifier(r))return $(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="cronJobs":!1;return!1},R=e=>{const t=new Set;for(const r of e.getVariableDeclarations()){const i=r.getInitializer();if(i?.getKind()!==p.CallExpression)continue;const a=i.getExpression();n.isIdentifier(a)&&y(a)&&t.add(r.getName())}return t},P=e=>{let t=e;for(;n.isCallExpression(t)||n.isPropertyAccessExpression(t);)t=t.getExpression();return n.isIdentifier(t)?t.getText():void 0},C=(e,t)=>{const r=e.getArguments()[t];return r&&(n.isStringLiteral(r)||n.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},_=(e,t)=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)||n.isNumericLiteral(e))return e.getLiteralValue();if(n.isTrueLiteral(e))return!0;if(n.isFalseLiteral(e))return!1;if(n.isPrefixUnaryExpression(e)&&e.getOperatorToken()===p.MinusToken){const r=e.getOperand();if(n.isNumericLiteral(r))return-r.getLiteralValue()}if(n.isObjectLiteralExpression(e))return g(e,t);if(n.isArrayLiteralExpression(e))return e.getElements().map(r=>_(r,t));throw f(e,`Cron job "${t}" passes a non-static value where a literal is required; codegen can only read literals.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500})},g=(e,t)=>{const r={};for(const i of e.getProperties()){if(!n.isPropertyAssignment(i))throw f(i,`Cron job "${t}" uses an unsupported object property (shorthand/spread/method) where a static literal is required.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500});const a=i.getInitializer();a&&(r[i.getName()]=_(a,t))}return r},x=(e,t,r)=>{const i=e.getArguments()[t];if(!i||!n.isPropertyAccessExpression(i))throw f(e,`Cron job "${r}" must reference a function statically (e.g. internal.email.digest); codegen cannot resolve a dynamic reference.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const a=i.getName(),o=i.getExpression();if(!n.isPropertyAccessExpression(o))throw f(i,`Cron job "${r}" function reference must be of the form internal.file.fn (two property accesses).`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const s=o.getName();return`${I(s)}:${a}`},w=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),h=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),T=(e,t,r,i,a,o)=>{const s=e.getExpression();if(!n.isIdentifier(s)||s.getText()!==t)return;const c=r.get(e.getName());if(c)return o(c);throw f(e,`Cron job "${i}" targets ${t}.${e.getName()}, but no such ${a} is declared in lunora/${a}s.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})},D=(e,t,r,i,a)=>{const o=e.getArguments()[t];if(o&&n.isPropertyAccessExpression(o)){const s=T(o,"workflows",i,r,"workflow",w);return s||T(o,"agents",a,r,"agent",h)||{functionPath:x(e,t,r)}}if(o&&n.isIdentifier(o)){const s=i.get(o.getText()),c=a.get(o.getText());if(s&&c)throw f(o,`Cron job "${r}" references "${o.getText()}", which is ambiguous: a workflow and an agent are both declared under that name.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});if(s)return w(s);if(c)return h(c);throw f(o,`Cron job "${r}" references "${o.getText()}", which is neither a function (internal.file.fn / api.file.fn) nor a declared workflow in lunora/workflows.ts nor a declared agent in lunora/agents.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})}return{functionPath:x(e,t,r)}},k=(e,t,r,i,a)=>{const o=t.getName();if(!j.has(o)||!r.has(P(t.getExpression())??""))return;const s=C(e,0);if(s===void 0||s.trim()==="")throw f(e,`A cron ".${o}(...)" registration must pass a non-empty string-literal name as its first argument.`,{code:"CRON_NAME_NOT_STATIC",name:"LunoraError",status:500});let c;if(o==="cron"){const l=C(e,1);if(l===void 0)throw f(e,`Cron job "${s}" must pass a string-literal cron expression to ".cron(...)".`,{code:"CRON_EXPR_NOT_STATIC",name:"LunoraError",status:500});if(!A(l))throw f(e,`Cron job "${s}" has an invalid cron expression "${l}" — expected 5 or 6 space-separated fields.`,{code:"CRON_EXPR_INVALID",name:"LunoraError",status:500});c=l}else{const l=e.getArguments()[1];if(!l||!n.isObjectLiteralExpression(l))throw f(e,`Cron job "${s}" must pass an object-literal schedule to ".${o}(...)".`,{code:"CRON_SCHEDULE_NOT_STATIC",name:"LunoraError",status:500});c=b(o,g(l,s))}const u=D(e,2,s,i,a),m=e.getArguments()[3];return{args:m&&n.isObjectLiteralExpression(m)?g(m,s):{},cron:c,name:s,...u}},F=e=>{const t=new Set;for(const r of e){if(t.has(r.name))throw new L("DUPLICATE_CRON_NAME",`Duplicate cron job name "${r.name}": cron names must be unique across the project.`,{status:500});t.add(r.name)}},J=(e,t,r=[],i=[])=>{const a=S(t),o=[],s=new Map(r.map(u=>[u.exportName,u])),c=new Map(i.map(u=>[u.exportName,u]));for(const u of a){const m=e.getSourceFile(u)??e.addSourceFileAtPath(u),l=R(m);if(l.size!==0)for(const d of m.getDescendantsOfKind(p.CallExpression)){const N=d.getExpression();if(!n.isPropertyAccessExpression(N))continue;const E=k(d,N,l,s,c);E&&o.push(E)}}return o.sort((u,m)=>u.name.localeCompare(m.name)),F(o),o};export{J as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readdirSync as w,lstatSync as D}from"node:fs";import{join as F,extname as C,relative as L,sep as O}from"node:path";import{Node as s,SyntaxKind as j}from"ts-morph";import{t as z}from"./module-specifiers-8FEEiUcv.mjs";import{d as A}from"./parse-validator-CSDlMEvE.mjs";import{n as U}from"./paths-BmX5O1sG.mjs";const y=new Set(["action","mutation","query","stream"]),V=/\bany\b(?!\s*(?:\?\s*)?:)/u,_=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,R=/^[A-Za-z_$][\w$]*$/u,M=e=>R.test(e)?e:JSON.stringify(e),H=/\.ts$/u,B=(e,t)=>L(e,t).split(O).join("/").replace(H,""),h={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},W={onConnect:"connect",onDisconnect:"disconnect"},q=z,P=e=>{const t=e.getSymbol();if(!t)return e.getText();const i=t.getDeclarations();for(const r of i){if(!s.isImportSpecifier(r))continue;const n=r.getImportDeclaration().getModuleSpecifierValue();return q(n)?r.getNameNode().getText():void 0}},N=(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=P(i);if(r===void 0){if(t)return;const n=i.getSymbol()?.getValueDeclaration();if(n&&s.isVariableDeclaration(n)){const o=n.getInitializer();return o?N(o,!0):void 0}return}return y.has(r)?"public":h[r]?"internal":void 0},d=(e,t)=>{const i=e.getProperty(t);if(i===void 0||!s.isPropertyAssignment(i))return;const r=i.getInitializer();return r!==void 0&&s.isStringLiteral(r)?r.getLiteralValue():void 0},E=(e,t)=>{const i=e.getProperty(t);if(i===void 0||!s.isPropertyAssignment(i))return;const r=i.getInitializer();return r!==void 0&&s.isNumericLiteral(r)?r.getLiteralValue():void 0},J=e=>{const t=e.getProperty("cache");if(t===void 0||!s.isPropertyAssignment(t))return;const i=t.getInitializer();if(i===void 0||!s.isObjectLiteralExpression(i))return;const r=d(i,"scope"),n=E(i,"maxAge"),o=E(i,"staleWhileRevalidate"),a=d(i,"tag"),c=d(i,"vary"),l={...n===void 0?{}:{maxAge:n},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},K=e=>{if(e===void 0||!s.isObjectLiteralExpression(e))return{};const t=J(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}},Q=e=>{let t=e;for(;s.isCallExpression(t);){const i=t.getExpression();if(!s.isPropertyAccessExpression(i))return;if(i.getName()==="expose")return K(t.getArguments()[0]);t=i.getExpression()}},G=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)?{}:A(r)},Z=(e,t)=>{for(const i of[e.getSymbol(),e.getAliasSymbol()])if(i)for(const r of i.getDeclarations()){const n=r.getSourceFile();if(!(n.isInNodeModules()||n.isDeclarationFile())&&n.getFilePath()===t&&(s.isInterfaceDeclaration(r)||s.isTypeAliasDeclaration(r))&&!r.isExported())return!0}return!1},X=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},S=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),Z(e,i)||X(e).some(n=>p(n,t,i,r))?!0:S(e)?e.getProperties().some(n=>p(n.getTypeAtLocation(t),t,i,r)):!1),Y=(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())},ee=8,te=(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}[]`},ie=(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(" | ")},re=(e,t,i,r,n,o)=>{if(!S(e))return;const a=[];for(const c of e.getProperties()){const l=c.getTypeAtLocation(t),m=Y(c,l),$=m&&l.isUnion()?l.getUnionTypes().filter(f=>!f.isUndefined()):[l],x=[];for(const f of $){const v=o(f,t,i,r+1,n);if(v===void 0)return;x.push(v)}a.push(`${M(c.getName())}${m?"?":""}: ${x.join(" | ")}`)}return a.length>0?`{ ${a.join("; ")} }`:"{}"},g=(e,t,i,r,n)=>{if(r>ee||n.has(e))return;if(!p(e,t,i))return e.getText(t);const o=new Set(n).add(e);return e.isArray()?te(e,t,i,r,o,g):e.isUnion()?ie(e,t,i,r,o,g):re(e,t,i,r,o,g)},T=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"||V.test(n.replaceAll(_,"")))return"unknown";const o=e.getSourceFile().getFilePath();return p(i,e,o)?g(i,e,o,0,new Set)??"unknown":n},ne=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":T(r)},se=e=>{const t=e.getArguments()[0];return!t||!(s.isArrowFunction(t)||s.isFunctionExpression(t))?"unknown":T(t)},oe=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={...A(n),...t})}i=r.getExpression()}return t},ae=e=>{const t=e.getExpression();if(s.isPropertyAccessExpression(t)){const o=t.getName();if(!y.has(o))return;const a=t.getExpression();if(a.getType().getProperty("__lunoraProcedure"))return{kind:o,receiver:a,visibility:a.getType().getProperty("__lunoraVisibility")?"internal":"public"};const c=N(a);return c?{kind:o,receiver:a,visibility:c}:void 0}if(!s.isIdentifier(t))return;const i=P(t);if(!i)return;if(y.has(i))return{kind:i,visibility:"public"};const r=h[i];if(r)return{kind:r,visibility:"internal"};const n=W[i];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}},b=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,Ae=e=>s.isPropertyAccessExpression(e)&&e.getName()==="db"||s.isIdentifier(e)&&e.getText()==="db",he=e=>{const t=e.getArguments()[0],i=b(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)?b(r.getInitializer()):void 0},ce=e=>s.isIdentifier(e)?e.getText():s.isPropertyAccessExpression(e)?e.getName():"",Pe=(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},Ne=(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)&&ce(o.getExpression())===i)return!0;r=n.getExpression()}return!1},I=(e,t=[],i=e)=>{let r;try{r=w(e)}catch{return t}for(const n of r){const o=F(e,n),a=D(o);if(a.isDirectory()){if(n==="_generated"||n==="node_modules")continue;I(o,t,i)}else if(a.isFile()&&C(n)===".ts"){if(n==="schema.ts"&&e===i)continue;t.push(o)}}return t},le=e=>{const t=ae(e);if(t){if(t.receiver){const i=Q(t.receiver);return{args:oe(t.receiver),...i?{expose:i}:{},kind:t.kind,returnType:se(e),visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:G(e),kind:t.kind,returnType:ne(e),visibility:t.visibility}}},ue=8,u=(e,t=0)=>{if(t>ue)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?k(i,t+1):void 0},k=(e,t)=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e)){const i=e.getInitializer();return i?u(i,t):void 0}if(s.isShorthandPropertyAssignment(e))return u(e.getNameNode(),t);if(s.isBindingElement(e)){const i=e.getPropertyNameNode()?.getText()??e.getName(),r=e.getFirstAncestorByKind(j.VariableDeclaration)?.getInitializer()?.getType().getProperty(i)?.getValueDeclaration();return r?k(r,t+1):void 0}},ge=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]]:[]},pe=(e,t,i)=>{const r=le(e);if(r)return{args:r.args,exportName:t,filePath:i,kind:r.kind,returnType:r.returnType,visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},fe=(e,t)=>{const i=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations())for(const[o,a]of ge(n)){const c=pe(a,o,t);c&&i.push(c)}return i},de=e=>{const t=new Map;for(const i of e){const r=U(i.filePath),n=t.get(r);if(n&&n!==i.filePath)throw Object.assign(new Error(`Namespace collision: "${n}" and "${i.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[n,i.filePath],status:500});t.set(r,i.filePath)}},Se=(e,t)=>{const i=I(t),r=[];for(const n of i){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),a=B(t,n);r.push(...fe(o,a))}return r.sort((n,o)=>`${n.filePath}:${n.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),de(r),r};export{Pe as chainHasStep,Ne as chainUsesWrappedCall,ae as classifyProcedureCall,Se as discoverFunctions,b as inlineHandler,Ae as isDatabaseAccessor,I as listLunoraSourceFiles,B as lunoraRelativePath,he as procedureHandler,T as unwrapHandlerReturn};
|
package/dist/packem_shared/{discoverHttpRoutes-Bf_T_03b.mjs → discoverHttpRoutes-CLn3VDRI.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 l,unwrapHandlerReturn as f}from"./discoverFunctions-
|
|
1
|
+
import{relative as m,sep as h}from"node:path";import{Node as a}from"ts-morph";import{listLunoraSourceFiles as l,unwrapHandlerReturn as f}from"./discoverFunctions-DnqHgv0t.mjs";import{s as d,d as g}from"./parse-validator-CSDlMEvE.mjs";const x=/\.ts$/u,u=new Set(["delete","get","head","options","patch","post","put"]),E=new Set(["body","params","searchParams"]),P=new Set(["handler","stream"]),A=r=>{const e=r.getArguments()[0];if(e&&a.isStringLiteral(e))return e.getLiteralValue()},y=r=>{const e=r.getArguments()[0];return e&&a.isObjectLiteralExpression(e)?g(e):{}},b=r=>{if(!a.isCallExpression(r))return;const e=r.getExpression();if(!a.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const n=e.getExpression();if(!a.isIdentifier(n)||n.getText()!=="httpRoute")return;const s=A(r);return s===void 0?void 0:{method:o.toUpperCase(),path:s}},S=(r,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},n=r.getExpression();if(!a.isPropertyAccessExpression(n))return;let s=n.getExpression();for(;a.isCallExpression(s);){const i=s.getExpression();if(!a.isPropertyAccessExpression(i))break;const p=i.getName();if(u.has(p))break;if(E.has(p)){const c=y(s);o[p]={...c,...o[p]}}else if(p==="output"&&o.output===void 0){const c=s.getArguments()[0];c&&a.isExpression(c)&&(o.output=d(c))}s=i.getExpression()}const t=b(s);if(t)return o.method=t.method,o.path=t.path,o},C=r=>{const e=r.getArguments()[0];return!e||!(a.isArrowFunction(e)||a.isFunctionExpression(e))?"unknown":f(e)},$=(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=l(e),n=[];for(const s of o){const t=r.getSourceFile(s)??r.addSourceFileAtPath(s),i=m(e,s).split(h).join("/").replace(x,"");n.push(...v(t,i))}return n.sort((s,t)=>`${s.method} ${s.path}`.localeCompare(`${t.method} ${t.path}`)||s.filePath.localeCompare(t.filePath)),n};export{L as default};
|
|
@@ -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-DnqHgv0t.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 n,SyntaxKind as
|
|
1
|
+
import{Node as n,SyntaxKind as h}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as E,classifyProcedureCall as g}from"./discoverFunctions-DnqHgv0t.mjs";const v=t=>{if(!n.isCallExpression(t))return!1;const e=t.getExpression();return n.isIdentifier(e)?e.getText()==="mask":n.isPropertyAccessExpression(e)?e.getName()==="mask":!1},f=t=>{if(n.isPropertyAssignment(t)||n.isShorthandPropertyAssignment(t)||n.isMethodDeclaration(t)||n.isGetAccessorDeclaration(t))return t.getName()},S=t=>{const e=t.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return[];const s=[];for(const r of e.getProperties()){const o=f(r);if(o===void 0||!n.isPropertyAssignment(r))continue;const i=r.getInitializer();if(!(!i||!n.isObjectLiteralExpression(i)))for(const a of i.getProperties()){const c=f(a);c!==void 0&&s.push({column:c,table:o})}}return s},p=t=>{const e=[];let s=t;for(;n.isCallExpression(s);){const r=s.getExpression();if(!n.isPropertyAccessExpression(r))break;if(r.getName()==="use"){const o=s.getArguments()[0];o&&v(o)&&e.push(o)}s=r.getExpression()}return e},A=t=>{const e=p(t);return{maskColumns:e.flatMap(s=>S(s)),usesMask:e.length>0}},y=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),k=new Set(["delete","insert","patch","replace"]),x=(t,e)=>{const s=t.getExpression();if(!n.isPropertyAccessExpression(s)||!e.has(s.getName()))return!1;const r=s.getExpression();return n.isPropertyAccessExpression(r)?r.getName()==="db":n.isIdentifier(r)&&r.getText()==="db"},b=t=>{const e=t.getArguments()[0];return e&&n.isStringLiteral(e)?e.getLiteralText():""},M=t=>{const e=new Set,s=new Set;for(const r of t.getDescendantsOfKind(h.CallExpression))if(x(r,y)){const o=b(r);o!==""&&e.add(o)}else if(x(r,k)){const o=b(r);o!==""&&s.add(o)}return{tablesRead:[...e],tablesWritten:[...s]}},C=(t,e)=>{if(!n.isVariableDeclaration(t))return;const s=t.getInitializer();if(!s||!n.isCallExpression(s))return;const r=g(s);if(!r)return;const o=r.receiver?A(r.receiver):{maskColumns:[],usesMask:!1},{tablesRead:i,tablesWritten:a}=M(t);return{exportName:t.getName(),file:e,maskColumns:o.maskColumns,tablesRead:i,tablesWritten:a,usesMask:o.usesMask,visibility:r.visibility}},O=(t,e)=>{const s=[];for(const r of u(e)){const o=t.getSourceFile(r)??t.addSourceFileAtPath(r),i=E(e,r);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations()){const l=C(c,i);l&&s.push(l)}}return s},P=t=>{if(n.isPropertyAssignment(t)){const e=t.getInitializer();if(e&&n.isStringLiteral(e)){const s=e.getLiteralText();if(s==="redact"||s==="hash")return s}}return"custom"},L=t=>{const e=t.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return[];const s=[];for(const r of e.getProperties()){const o=f(r);if(o===void 0||!n.isPropertyAssignment(r))continue;const i=r.getInitializer();if(!(!i||!n.isObjectLiteralExpression(i)))for(const a of i.getProperties()){const c=f(a);c!==void 0&&s.push({column:c,strategy:P(a),table:o})}}return s},N=t=>{const e=[];for(const s of t.getVariableStatements())if(s.isExported())for(const r of s.getDeclarations()){const o=r.getInitializer(),i=o&&n.isCallExpression(o)?g(o):void 0;i?.receiver&&e.push(i.receiver)}return e},j=(t,e)=>{const s=new Map;for(const r of u(e)){const o=t.getSourceFile(r)??t.addSourceFileAtPath(r);for(const i of N(o))for(const a of p(i))for(const c of L(a)){const l=`${c.table}\0${c.column}`;s.has(l)||s.set(l,c)}}return{columns:[...s.values()]}},F=(t,e,s)=>{const r=t.getArguments()[0];if(!r||!n.isObjectLiteralExpression(r))return[];const o=[];for(const i of r.getProperties()){const a=f(i);if(a===void 0||!n.isPropertyAssignment(i))continue;const c=i.getInitializer();if(!(!c||!n.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const m=f(l);if(m===void 0)continue;const d=P(l);d!=="custom"&&o.push({column:m,exportName:e,file:s,line:l.getStartLineNumber(),strategy:d,table:a})}}return o},I=(t,e)=>{if(!n.isVariableDeclaration(t))return[];const s=t.getInitializer(),r=s&&n.isCallExpression(s)?g(s):void 0;return r?.receiver?p(r.receiver).flatMap(o=>F(o,t.getName(),e)):[]},w=(t,e)=>{const s=[];for(const r of u(e)){const o=t.getSourceFile(r)??t.addSourceFileAtPath(r),i=E(e,r);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...I(c,i))}return s};export{O as default,j as discoverMaskMetadata,w as discoverMaskStrategies};
|
package/dist/packem_shared/{discoverMigrations-T2xb-1rn.mjs → discoverMigrations-BH_IKdFk.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-DnqHgv0t.mjs";import{o as I}from"./module-specifiers-8FEEiUcv.mjs";const S=/\.ts$/u,x=r=>{const i=r.getSymbol();if(!i)return r.getText()==="defineMigration";for(const t of i.getDeclarations())if(a.isImportSpecifier(t))return I(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMigration":!1;return!1},f=(r,i)=>{const t=r.getProperty(i);if(!t||!a.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&a.isStringLiteral(e)?e.getLiteralValue():void 0},b=(r,i)=>{const t=r.getInitializer();if(t?.getKind()!==m.CallExpression)return;const e=t.getExpression();if(!a.isIdentifier(e)||!x(e))return;const o=t.getArguments()[0];if(!o||!a.isObjectLiteralExpression(o))return;const n=f(o,"id"),s=r.getName();if(n===void 0||n.trim()==="")throw p(o,`Migration "${s}" in "${i}" must declare \`id\` as a non-empty string literal so codegen can key the registry.`,{code:"MIGRATION_ID_NOT_STATIC",name:"LunoraError",status:500});return{exportName:s,filePath:i,id:n,table:f(o,"table")??""}},E=r=>{const i=new Map;for(const t of r){const e=i.get(t.id);if(e!==void 0)throw Object.assign(new Error(`Duplicate migration id "${t.id}": declared in both "${e}" and "${t.filePath}". Migration ids must be unique across the project.`),{code:"DUPLICATE_MIGRATION_ID",id:t.id,name:"LunoraError",paths:[e,t.filePath],status:500});i.set(t.id,t.filePath)}},y=(r,i)=>{const t=h(i),e=[];for(const o of t){const n=r.getSourceFile(o)??r.addSourceFileAtPath(o),s=g(i,o).split(u).join("/").replace(S,"");for(const c of n.getVariableStatements())if(c.isExported())for(const d of c.getDeclarations()){const l=b(d,s);l&&e.push(l)}}return e.sort((o,n)=>o.id.localeCompare(n.id)),E(e),e};export{y as default};
|
|
@@ -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-DnqHgv0t.mjs";const d={"crypto.getRandomValues":"crypto.getRandomValues","crypto.randomUUID":"crypto.randomUUID","Date.now":"Date.now","Math.random":"Math.random"},f=new Set(["globalThis","self"]),g=new Set(["globalThis","self","window"]),p=t=>{if(o.isIdentifier(t))return t.getText();if(o.isPropertyAccessExpression(t)){const e=t.getExpression();if(o.isIdentifier(e)&&g.has(e.getText()))return t.getName()}},m=t=>{const e=t.getExpression();if(o.isIdentifier(e)){const i=e.getText();return i==="fetch"||i==="Date"?i:void 0}if(!o.isPropertyAccessExpression(e))return;const r=e.getName(),n=p(e.getExpression());if(n!==void 0)return r==="fetch"&&f.has(n)?"fetch":d[`${n}.${r}`]},x=t=>{const e=t.getExpression();if(!o.isIdentifier(e)||e.getText()!=="Date")return;const r=t.getArguments(),n=r.every(i=>o.isNumericLiteral(i)||o.isStringLiteral(i)||o.isNoSubstitutionTemplateLiteral(i));return r.length>0&&n?void 0:"new Date"},h=(t,e)=>{if(e){const s=t.getArguments()[0];return s&&(o.isArrowFunction(s)||o.isFunctionExpression(s))?s:void 0}const r=t.getArguments()[0];if(!r||!o.isObjectLiteralExpression(r))return;const n=r.getProperty("handler");if(!n||!o.isPropertyAssignment(n))return;const i=n.getInitializer();return i&&(o.isArrowFunction(i)||o.isFunctionExpression(i))?i:void 0},E=t=>{const e=t.getInitializer();if(!e||!o.isCallExpression(e))return;const r=l(e);if(!r||r.kind!=="query"&&r.kind!=="mutation")return;const n=h(e,r.receiver);return n?{exportName:t.getName(),handler:n,kind:r.kind}:void 0},N=(t,e)=>{const r=[];for(const n of t.handler.getDescendantsOfKind(a.CallExpression)){const i=m(n);i!==void 0&&r.push({callee:i,exportName:t.exportName,file:e,kind:t.kind,line:n.getStartLineNumber()})}for(const n of t.handler.getDescendantsOfKind(a.NewExpression)){const i=x(n);i!==void 0&&r.push({callee:i,exportName:t.exportName,file:e,kind:t.kind,line:n.getStartLineNumber()})}return r},y=(t,e)=>{const r=[];for(const n of t.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const s=E(i);s&&r.push(...N(s,e))}return r},w=(t,e)=>{const r=[];for(const n of c(e)){const i=t.getSourceFile(n)??t.addSourceFileAtPath(n);r.push(...y(i,u(e,n)))}return r};export{w as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SyntaxKind as u,Node as n}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as g}from"./discoverFunctions-
|
|
1
|
+
import{SyntaxKind as u,Node as n}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as g}from"./discoverFunctions-DnqHgv0t.mjs";const p=new Set(["withIndex","withSearchIndex"]),x=r=>{const e=r.getExpression();if(!n.isPropertyAccessExpression(e)||e.getName()!=="query")return!1;const t=e.getExpression();return n.isPropertyAccessExpression(t)?t.getName()==="db":n.isIdentifier(t)&&t.getText()==="db"},d=r=>{const e=[];let t=r;for(;;){const s=t.getParent();if(!s||!n.isPropertyAccessExpression(s))break;const o=s.getParent();if(!o||!n.isCallExpression(o))break;e.push(s.getName()),t=o}return e},h=r=>{const e=r.getArguments()[0];return e&&n.isStringLiteral(e)?e.getLiteralText():""},P=(r,e)=>{const t=[];for(const s of f(e)){const o=r.getSourceFile(s)??r.addSourceFileAtPath(s),c=g(e,s);for(const i of o.getDescendantsOfKind(u.CallExpression)){if(!x(i))continue;const a=d(i);a.includes("filter")&&t.push({file:c,hasFilter:!0,hasIndex:a.some(l=>p.has(l)),line:i.getStartLineNumber(),table:h(i)})}}return t};export{P as default};
|
package/dist/packem_shared/{discoverR2sqlCalls-YEjvGcEq.mjs → discoverR2sqlCalls-CMNfDWlq.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as o,SyntaxKind as c}from"ts-morph";import{listLunoraSourceFiles as a,lunoraRelativePath as u,classifyProcedureCall as l}from"./discoverFunctions-
|
|
1
|
+
import{Node as o,SyntaxKind as c}from"ts-morph";import{listLunoraSourceFiles as a,lunoraRelativePath as u,classifyProcedureCall as l}from"./discoverFunctions-DnqHgv0t.mjs";const p=(t,r)=>{if(r){const n=t.getArguments()[0];return n&&(o.isArrowFunction(n)||o.isFunctionExpression(n))?n:void 0}const e=t.getArguments()[0];if(!e||!o.isObjectLiteralExpression(e))return;const s=e.getProperty("handler");if(!s||!o.isPropertyAssignment(s))return;const i=s.getInitializer();return i&&(o.isArrowFunction(i)||o.isFunctionExpression(i))?i:void 0},f=t=>{const r=t.getInitializer();if(!r||!o.isCallExpression(r))return;const e=l(r);if(!e||e.kind!=="query"&&e.kind!=="mutation")return;const s=p(r,e.receiver);return s?{exportName:t.getName(),handler:s,kind:e.kind}:void 0},d=t=>{if(!o.isPropertyAccessExpression(t)||t.getName()!=="r2sql")return;const r=t.getExpression();if(!o.isIdentifier(r)||r.getText()!=="ctx")return;const e=t.getParent();return e&&o.isPropertyAccessExpression(e)&&e.getExpression()===t?`ctx.r2sql.${e.getName()}`:"ctx.r2sql"},g=(t,r)=>{const e=[];for(const s of t.handler.getDescendantsOfKind(c.PropertyAccessExpression)){const i=d(s);i!==void 0&&e.push({callee:i,exportName:t.exportName,file:r,kind:t.kind,line:s.getStartLineNumber()})}return e},x=(t,r)=>{const e=[];for(const s of t.getVariableStatements())if(s.isExported())for(const i of s.getDeclarations()){const n=f(i);n&&e.push(...g(n,r))}return e},P=(t,r)=>{const e=[];for(const s of a(r)){const i=t.getSourceFile(s)??t.addSourceFileAtPath(s);e.push(...x(i,u(r,s)))}return e};export{P as default};
|
package/dist/packem_shared/{discoverRlsMetadata-DO3qlLXX.mjs → discoverRlsMetadata-Bf4_2S0t.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as n,SyntaxKind as A}from"ts-morph";import{listLunoraSourceFiles as E,lunoraRelativePath as b,classifyProcedureCall as y}from"./discoverFunctions-
|
|
1
|
+
import{Node as n,SyntaxKind as A}from"ts-morph";import{listLunoraSourceFiles as E,lunoraRelativePath as b,classifyProcedureCall as y}from"./discoverFunctions-DnqHgv0t.mjs";const h=t=>{if(!n.isCallExpression(t))return!1;const e=t.getExpression();return n.isIdentifier(e)?e.getText()==="rls":n.isPropertyAccessExpression(e)?e.getName()==="rls":!1},S=t=>{const e=t.getArguments()[0];if(!e||!n.isArrayLiteralExpression(e))return[];const r=[];for(const s of e.getElements()){if(!n.isObjectLiteralExpression(s))continue;const i=s.getProperty("table");if(!i||!n.isPropertyAssignment(i))continue;const o=i.getInitializer();o&&n.isStringLiteral(o)&&r.push(o.getLiteralText())}return r},L=t=>{const e=[];let r=t;for(;n.isCallExpression(r);){const s=r.getExpression();if(!n.isPropertyAccessExpression(s))break;if(s.getName()==="use"){const i=r.getArguments()[0];i&&h(i)&&e.push(i)}r=s.getExpression()}return e},v=t=>{const e=L(t);return{rlsTables:e.flatMap(r=>S(r)),usesRls:e.length>0}},P=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),T=new Set(["delete","deleteMany","insert","insertMany","patch","patchMany","replace"]),g=(t,e)=>{const r=t.getExpression();if(!n.isPropertyAccessExpression(r)||!e.has(r.getName()))return!1;const s=r.getExpression();return n.isPropertyAccessExpression(s)?s.getName()==="db":n.isIdentifier(s)&&s.getText()==="db"},d=t=>{const e=t.getArguments()[0];return e&&n.isStringLiteral(e)?e.getLiteralText():""},R=t=>{const e=new Set,r=new Set;for(const s of t.getDescendantsOfKind(A.CallExpression))if(g(s,P)){const i=d(s);i!==""&&e.add(i)}else if(g(s,T)){const i=d(s);i!==""&&r.add(i)}return{tablesRead:[...e],tablesWritten:[...r]}},M=(t,e)=>{if(!n.isVariableDeclaration(t))return;const r=t.getInitializer();if(!r||!n.isCallExpression(r))return;const s=y(r);if(!s)return;const i=s.receiver?v(s.receiver):{rlsTables:[],usesRls:!1},{tablesRead:o,tablesWritten:a}=R(t);return{exportName:t.getName(),file:e,rlsTables:i.rlsTables,tablesRead:o,tablesWritten:a,usesRls:i.usesRls,visibility:s.visibility}},D=(t,e)=>{const r=[];for(const s of E(e)){const i=t.getSourceFile(s)??t.addSourceFileAtPath(s),o=b(e,s);for(const a of i.getVariableStatements())if(a.isExported())for(const f of a.getDeclarations()){const c=M(f,o);c&&r.push(c)}}return r},C=new Set(["delete","insert","read","update"]),l=(t,e)=>{if(!n.isObjectLiteralExpression(t))return;const r=t.getProperty(e);if(!r||!n.isPropertyAssignment(r))return;const s=r.getInitializer();return s&&n.isStringLiteral(s)?s.getLiteralText():void 0},I=(t,e,r)=>{const s=t.getArguments()[0];if(!s||!n.isArrayLiteralExpression(s))return[];const i=[];for(const o of s.getElements()){if(!n.isObjectLiteralExpression(o))continue;const a=l(o,"on");a===void 0||!C.has(a)||i.push({file:e,on:a,procedure:r,table:l(o,"table")??""})}return i},m=t=>{if(!n.isObjectLiteralExpression(t))return[];const e=t.getProperty("permissions");if(!e||!n.isPropertyAssignment(e))return[];const r=e.getInitializer();if(!r||!n.isArrayLiteralExpression(r))return[];const s=[];for(const i of r.getElements()){if(n.isStringLiteral(i)){s.push(i.getLiteralText());continue}if(n.isCallExpression(i)){const o=i.getArguments()[0];o&&n.isStringLiteral(o)&&s.push(o.getLiteralText())}}return s},x=(t,e)=>e===void 0?t:{...t,description:e},N=t=>{if(n.isCallExpression(t)){const e=t.getArguments()[0];if(!e||!n.isStringLiteral(e))return;const r=t.getArguments()[1],s=r?l(r,"description"):void 0,i=r?m(r):[];return x({name:e.getLiteralText(),permissions:i},s)}if(n.isObjectLiteralExpression(t)){const e=l(t,"name");return e===void 0?void 0:x({name:e,permissions:m(t)},l(t,"description"))}},O=t=>{const e=t.getArguments()[1];if(!e||!n.isObjectLiteralExpression(e))return[];const r=e.getProperty("roles");if(!r||!n.isPropertyAssignment(r))return[];const s=r.getInitializer();if(!s||!n.isArrayLiteralExpression(s))return[];const i=[];for(const o of s.getElements()){const a=N(o);a&&i.push(a)}return i},w=(t,e,r)=>{const s=L(t);return{policies:s.flatMap(i=>I(i,e,r)),roles:s.flatMap(i=>O(i))}},F=t=>{const e=[];for(const r of t.getVariableStatements())if(r.isExported())for(const s of r.getDeclarations()){const i=s.getInitializer(),o=i&&n.isCallExpression(i)?y(i):void 0;o?.receiver&&e.push({name:s.getName(),receiver:o.receiver})}return e},V=(t,e)=>{const r=[],s=new Map;for(const i of E(e)){const o=t.getSourceFile(i)??t.addSourceFileAtPath(i),a=b(e,i);for(const{name:f,receiver:c}of F(o)){const p=w(c,a,f);r.push(...p.policies);for(const u of p.roles)s.has(u.name)||s.set(u.name,u)}}return{policies:r,roles:[...s.values()]}};export{D as default,V as discoverRlsMetadata};
|
package/dist/packem_shared/{discoverSandboxUsage-JwrmSN9l.mjs → discoverSandboxUsage-Bn1X9COt.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{listLunoraSourceFiles as u}from"./discoverFunctions-
|
|
1
|
+
import{listLunoraSourceFiles as u}from"./discoverFunctions-DnqHgv0t.mjs";const i=new Set(["@lunora/agent","@lunora/agent/sandbox"]),d=o=>{const s={usesSandboxBrowser:!1,usesSandboxContainer:!1};if(!i.has(o.getModuleSpecifierValue())||o.isTypeOnly())return s;for(const e of o.getNamedImports()){if(e.isTypeOnly())continue;const n=e.getNameNode().getText();n==="browserTool"?s.usesSandboxBrowser=!0:n==="containerTool"&&(s.usesSandboxContainer=!0)}return s},c=(o,s)=>{const e={usesSandboxBrowser:!1,usesSandboxContainer:!1};for(const n of u(s)){const a=o.getSourceFile(n)??o.addSourceFileAtPath(n);for(const t of a.getImportDeclarations()){const r=d(t);e.usesSandboxBrowser||=r.usesSandboxBrowser,e.usesSandboxContainer||=r.usesSandboxContainer}if(e.usesSandboxBrowser&&e.usesSandboxContainer)break}return e};export{c as discoverSandboxUsage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as p,classifyProcedureCall as g}from"./discoverFunctions-
|
|
1
|
+
import{Node as i}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as p,classifyProcedureCall as g}from"./discoverFunctions-DnqHgv0t.mjs";const x=new Set(["delete","list","read","write"]),m=s=>{if(!i.isCallExpression(s))return!1;const r=s.getExpression();return i.isIdentifier(r)?r.getText()==="storageRules":i.isPropertyAccessExpression(r)&&r.getName()==="storageRules"},E=s=>{const r=[];let t=s;for(;i.isCallExpression(t);){const e=t.getExpression();if(!i.isPropertyAccessExpression(e))break;if(e.getName()==="use"){const o=t.getArguments()[0];o&&m(o)&&r.push(o)}t=e.getExpression()}return r},u=(s,r)=>{if(!i.isObjectLiteralExpression(s))return;const t=s.getProperty(r);if(!t||!i.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&i.isStringLiteral(e)?e.getLiteralText():void 0},d=(s,r,t)=>{const e=s.getArguments()[0];if(!e||!i.isArrayLiteralExpression(e))return[];const o=[];for(const n of e.getElements()){if(!i.isObjectLiteralExpression(n))continue;const c=u(n,"on");if(c===void 0||!x.has(c))continue;const a=u(n,"prefix"),l={bucket:u(n,"bucket")??"",file:r,on:c,procedure:t};a!==void 0&&(l.prefix=a),o.push(l)}return o},v=s=>{const r=[];for(const t of s.getVariableStatements())if(t.isExported())for(const e of t.getDeclarations()){const o=e.getInitializer(),n=o&&i.isCallExpression(o)?g(o):void 0;n?.receiver&&r.push({name:e.getName(),receiver:n.receiver})}return r},A=(s,r)=>{const t=[];for(const e of f(r)){const o=s.getSourceFile(e)??s.addSourceFileAtPath(e),n=p(r,e);for(const{name:c,receiver:a}of v(o))for(const l of E(a))t.push(...d(l,n,c))}return{rules:t}};export{A as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/codegen",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.74",
|
|
4
4
|
"description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@lunora/advisor": "1.0.0-alpha.
|
|
50
|
-
"@lunora/agent": "1.0.0-alpha.
|
|
49
|
+
"@lunora/advisor": "1.0.0-alpha.53",
|
|
50
|
+
"@lunora/agent": "1.0.0-alpha.29",
|
|
51
51
|
"@lunora/container": "1.0.0-alpha.16",
|
|
52
52
|
"@lunora/errors": "1.0.0-alpha.8",
|
|
53
53
|
"@lunora/queue": "1.0.0-alpha.10",
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{w as $}from"./emit-D7VIjvlm.mjs";import{n as p}from"./paths-BmX5O1sG.mjs";import{LUNORA_ERROR_CODES as y,objectSchema as g,argsObjectSchema as h,validatorIrToJsonSchema as u}from"./LUNORA_ERROR_CODES-Um9hC1gr.mjs";const S="/_lunora/rest",O=e=>{const t=e.indexOf(":");if(!(t<=0||t>=e.length-1||e.indexOf(":",t+1)!==-1))return{name:e.slice(t+1),namespace:e.slice(0,t)}},b=e=>{const t=O(e);if(t!==void 0)return`${S}/${t.namespace}/${t.name}`},P=e=>e==="query"?"GET":"POST",l="#/components/responses/LunoraError",f=/:([A-Za-z_$][\w$]*)/gu,T=e=>[...e.matchAll(f)].map(t=>t[1]),k=e=>e.replaceAll(f,"{$1}"),v=e=>{const t=new Set(T(e.path)),n=[];for(const[o,s]of Object.entries(e.searchParams)){const c=s.kind==="optional"?s.inner??s:s;n.push({description:`Query parameter \`${o}\``,in:"query",name:o,required:s.kind!=="optional",schema:u(c)})}for(const[o,s]of Object.entries(e.params)){const c=s.kind==="optional"?s.inner??s:s;n.push({description:`Path parameter \`${o}\``,in:t.has(o)?"path":"query",name:o,required:t.has(o)?!0:s.kind!=="optional",schema:u(c)})}return n},j=e=>e?{content:{"application/json":{schema:u(e)}},description:"Successful response."}:{content:{"application/json":{schema:{description:"Return shape is TS-inferred (no `.output()` declared); best-effort — any JSON."}}},description:"Successful response. The return shape is TypeScript-inferred and not declared via `.output()`, so it is documented best-effort."},N=e=>{const t=p(e.filePath),n=v(e),o={description:`${e.stream?"Streaming (SSE) ":""}HTTP route handler \`${e.exportName}\` (${e.method} ${e.path}).`,operationId:`${e.method.toLowerCase()}_${p(e.path)}`,responses:{200:j(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:l}},summary:`${e.method} ${e.path}`,tags:[t]};return n.length>0&&(o.parameters=n),Object.keys(e.body).length>0&&(o.requestBody={content:{"application/json":{schema:g(e.body)}},required:!0}),e.stream&&(o["x-lunora-stream"]="text/event-stream"),o},q=e=>{const t=`${p(e.filePath)}:${e.exportName}`,n=p(e.filePath),o={additionalProperties:!1,properties:{args:h(e.args),functionPath:{const:t,type:"string"},shardKey:{description:"Optional shard key; omitted routes to the default shard.",type:"string"}},required:["functionPath"],type:"object"};return{operation:{description:`Invoke the \`${e.kind}\` \`${t}\` over the Lunora RPC envelope (POST /_lunora/rpc).`,operationId:t,requestBody:{content:{"application/json":{schema:o}},required:!0},responses:{200:{content:{"application/json":{schema:{description:"RPC result. The shape is TS-inferred from the function's return type; best-effort — any JSON."}}},description:"Successful RPC result (TypeScript-inferred return shape, documented best-effort)."},default:{$ref:l}},summary:`${e.kind}: ${t}`,tags:[n],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${t}`}},R=e=>{const t=`${p(e.filePath)}:${e.exportName}`,n=b(t);if(n===void 0)return;const o=p(e.filePath),s=P(e.kind),c=s==="GET",r={description:`Public REST endpoint for the \`${e.kind}\` \`${t}\` (opt-in via \`.expose({ rest: true })\`). Routed through the procedure, so auth / RLS / validators are enforced.`,operationId:`rest_${p(n)}`,responses:{200:{content:{"application/json":{schema:{description:"Procedure result. The shape is TS-inferred from the return type; best-effort — any JSON."}}},description:"Successful result (TypeScript-inferred return shape, documented best-effort)."},default:{$ref:l}},summary:`${s} ${n}`,tags:[o],"x-lunora-function-kind":e.kind};if(c){const a=Object.entries(e.args).map(([i,d])=>{const m=d.kind==="optional"?d.inner??d:d;return{description:`Argument \`${i}\` (JSON-encoded for non-string values).`,in:"query",name:i,required:d.kind!=="optional",schema:u(m)}});return a.length>0&&(r.parameters=a),{method:"get",operation:r,path:n}}return r.requestBody={content:{"application/json":{schema:h(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:r,path:n}},A=e=>{const t=e.version??"0.0.0",n={},o=new Set;for(const r of e.httpRoutes){const a=k(r.path),i=n[a]??{};i[r.method.toLowerCase()]=N(r),n[a]=i,o.add(p(r.filePath))}const s=e.functions.filter(r=>r.visibility!=="internal"&&r.kind!=="stream");for(const r of s){const{operation:a,pathKey:i}=q(r);n[i]={post:a},o.add(p(r.filePath))}for(const r of s){if(r.expose?.rest!==!0)continue;const a=R(r);if(a===void 0)continue;const i=n[a.path]??{};i[a.method]=a.operation,n[a.path]=i,o.add(p(r.filePath))}const c=[...o].toSorted((r,a)=>r.localeCompare(a)).map(r=>({description:`Operations declared in \`lunora/${r}\`.`,name:r}));return{components:{responses:{LunoraError:{content:{"application/json":{schema:{additionalProperties:!1,description:"Standard Lunora error envelope.",properties:{error:{additionalProperties:!1,properties:{code:{description:"Machine-readable error code. Clients switch on this value.",enum:y,type:"string"},message:{description:"Human-readable error message (never echoes internal details).",type:"string"}},required:["code","message"],type:"object"}},required:["error"],type:"object"}}},description:"A Lunora error response. The HTTP status reflects the error code (e.g. BAD_REQUEST→400, UNAUTHORIZED→401, FORBIDDEN→403, NOT_FOUND→404)."}}},info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora API",version:t},openapi:"3.1.0",paths:n,tags:c}},_=e=>`${JSON.stringify(A(e),void 0,2)}
|
|
2
|
-
`,I=e=>`${$}export const openApiSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
|
|
3
|
-
`;export{A as buildOpenApiDocument,_ as emitOpenApi,I as emitOpenApiModule};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{readdirSync as k,lstatSync as $}from"node:fs";import{join as w,extname as D,relative as F,sep as C}from"node:path";import{Node as s,SyntaxKind as j}from"ts-morph";import{t as O}from"./module-specifiers-8FEEiUcv.mjs";import{d as b}from"./parse-validator-CSDlMEvE.mjs";import{n as U}from"./paths-BmX5O1sG.mjs";const d=new Set(["action","mutation","query","stream"]),L=/\bany\b(?!\s*(?:\?\s*)?:)/u,z=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,V=/^[A-Za-z_$][\w$]*$/u,_=e=>V.test(e)?e:JSON.stringify(e),M=/\.ts$/u,H=(e,t)=>F(e,t).split(C).join("/").replace(M,""),v={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},B={onConnect:"connect",onDisconnect:"disconnect"},R=O,A=e=>{const t=e.getSymbol();if(!t)return e.getText();const i=t.getDeclarations();for(const r of i){if(!s.isImportSpecifier(r))continue;const n=r.getImportDeclaration().getModuleSpecifierValue();return R(n)?r.getNameNode().getText():void 0}},h=(e,t=!1)=>{let i=e;for(;s.isCallExpression(i);){const n=i.getExpression();if(!s.isPropertyAccessExpression(n))return;i=n.getExpression()}if(!s.isIdentifier(i))return;const r=A(i);if(r===void 0){if(t)return;const n=i.getSymbol()?.getValueDeclaration();if(n&&s.isVariableDeclaration(n)){const o=n.getInitializer();return o?h(o,!0):void 0}return}return d.has(r)?"public":v[r]?"internal":void 0},q=e=>{let t=e;for(;s.isCallExpression(t);){const i=t.getExpression();if(!s.isPropertyAccessExpression(i))return;if(i.getName()==="expose"){const r=t.getArguments()[0];if(r!==void 0&&s.isObjectLiteralExpression(r)){const n=r.getProperty("rest");if(n!==void 0&&s.isPropertyAssignment(n))return{rest:n.getInitializer()?.getText()==="true"}}return{}}t=i.getExpression()}},J=e=>{const t=e.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))return{};const i=t.getProperty("args");if(!i||!s.isPropertyAssignment(i))return{};const r=i.getInitializer();return!r||!s.isObjectLiteralExpression(r)?{}:b(r)},K=(e,t)=>{for(const i of[e.getSymbol(),e.getAliasSymbol()])if(i)for(const r of i.getDeclarations()){const n=r.getSourceFile();if(!(n.isInNodeModules()||n.isDeclarationFile())&&n.getFilePath()===t&&(s.isInterfaceDeclaration(r)||s.isTypeAliasDeclaration(r))&&!r.isExported())return!0}return!1},Q=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},P=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0,p=(e,t,i,r=new Set)=>r.has(e)?!1:(r.add(e),K(e,i)||Q(e).some(n=>p(n,t,i,r))?!0:P(e)?e.getProperties().some(n=>p(n.getTypeAtLocation(t),t,i,r)):!1),G=(e,t)=>{const i=e.getValueDeclaration()??e.getDeclarations()[0];return i&&(s.isPropertySignature(i)||s.isPropertyDeclaration(i))&&i.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},W=8,Z=(e,t,i,r,n,o)=>{const a=e.getArrayElementType(),c=a?o(a,t,i,r,n):void 0;if(c!==void 0)return a?.isUnion()?`(${c})[]`:`${c}[]`},X=(e,t,i,r,n,o)=>{const a=[];for(const c of e.getUnionTypes()){const l=o(c,t,i,r,n);if(l===void 0)return;a.push(l)}return a.join(" | ")},Y=(e,t,i,r,n,o)=>{if(!P(e))return;const a=[];for(const c of e.getProperties()){const l=c.getTypeAtLocation(t),y=G(c,l),I=y&&l.isUnion()?l.getUnionTypes().filter(f=>!f.isUndefined()):[l],m=[];for(const f of I){const x=o(f,t,i,r+1,n);if(x===void 0)return;m.push(x)}a.push(`${_(c.getName())}${y?"?":""}: ${m.join(" | ")}`)}return a.length>0?`{ ${a.join("; ")} }`:"{}"},g=(e,t,i,r,n)=>{if(r>W||n.has(e))return;if(!p(e,t,i))return e.getText(t);const o=new Set(n).add(e);return e.isArray()?Z(e,t,i,r,o,g):e.isUnion()?X(e,t,i,r,o,g):Y(e,t,i,r,o,g)},S=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let i=t.getReturnType();const r=(i.getSymbol()??i.getAliasSymbol())?.getName();if(r==="Promise"||r==="AsyncIterable"||r==="AsyncIterableIterator"||r==="AsyncGenerator"){const a=i.getTypeArguments()[0];a&&(i=a)}const n=i.getText(e);if(!n||n==="any"||n==="never"||L.test(n.replaceAll(z,"")))return"unknown";const o=e.getSourceFile().getFilePath();return p(i,e,o)?g(i,e,o,0,new Set)??"unknown":n},ee=e=>{const t=e.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))return"unknown";const i=t.getProperty("handler");if(!i||!s.isPropertyAssignment(i))return"unknown";const r=i.getInitializer();return!r||!(s.isArrowFunction(r)||s.isFunctionExpression(r))?"unknown":S(r)},te=e=>{const t=e.getArguments()[0];return!t||!(s.isArrowFunction(t)||s.isFunctionExpression(t))?"unknown":S(t)},ie=e=>{let t={},i=e;for(;s.isCallExpression(i);){const r=i.getExpression();if(!s.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const n=i.getArguments()[0];n&&s.isObjectLiteralExpression(n)&&(t={...b(n),...t})}i=r.getExpression()}return t},re=e=>{const t=e.getExpression();if(s.isPropertyAccessExpression(t)){const o=t.getName();if(!d.has(o))return;const a=t.getExpression();if(a.getType().getProperty("__lunoraProcedure"))return{kind:o,receiver:a,visibility:a.getType().getProperty("__lunoraVisibility")?"internal":"public"};const c=h(a);return c?{kind:o,receiver:a,visibility:c}:void 0}if(!s.isIdentifier(t))return;const i=A(t);if(!i)return;if(d.has(i))return{kind:i,visibility:"public"};const r=v[i];if(r)return{kind:r,visibility:"internal"};const n=B[i];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}},E=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,xe=e=>s.isPropertyAccessExpression(e)&&e.getName()==="db"||s.isIdentifier(e)&&e.getText()==="db",Ee=e=>{const t=e.getArguments()[0],i=E(t);if(i!==void 0)return i;if(t===void 0||!s.isObjectLiteralExpression(t))return;const r=t.getProperty("handler");return r!==void 0&&s.isPropertyAssignment(r)?E(r.getInitializer()):void 0},ne=e=>s.isIdentifier(e)?e.getText():s.isPropertyAccessExpression(e)?e.getName():"",be=(e,t)=>{let i=e;for(;s.isCallExpression(i);){const r=i.getExpression();if(!s.isPropertyAccessExpression(r))break;if(r.getName()===t)return!0;i=r.getExpression()}return!1},ve=(e,t,i)=>{let r=e;for(;s.isCallExpression(r);){const n=r.getExpression();if(!s.isPropertyAccessExpression(n))break;const o=r.getArguments()[0];if(n.getName()===t&&o!==void 0&&s.isCallExpression(o)&&ne(o.getExpression())===i)return!0;r=n.getExpression()}return!1},N=(e,t=[],i=e)=>{let r;try{r=k(e)}catch{return t}for(const n of r){const o=w(e,n),a=$(o);if(a.isDirectory()){if(n==="_generated"||n==="node_modules")continue;N(o,t,i)}else if(a.isFile()&&D(n)===".ts"){if(n==="schema.ts"&&e===i)continue;t.push(o)}}return t},se=e=>{const t=re(e);if(t){if(t.receiver){const i=q(t.receiver);return{args:ie(t.receiver),...i?{expose:i}:{},kind:t.kind,returnType:te(e),visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:J(e),kind:t.kind,returnType:ee(e),visibility:t.visibility}}},oe=8,u=(e,t=0)=>{if(t>oe)return;if(s.isCallExpression(e))return e;if(s.isParenthesizedExpression(e)||s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isNonNullExpression(e))return u(e.getExpression(),t+1);if(!s.isIdentifier(e)&&!s.isPropertyAccessExpression(e))return;const i=e.getSymbol()?.getValueDeclaration();return i?T(i,t+1):void 0},T=(e,t)=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e)){const i=e.getInitializer();return i?u(i,t):void 0}if(s.isShorthandPropertyAssignment(e))return u(e.getNameNode(),t);if(s.isBindingElement(e)){const i=e.getPropertyNameNode()?.getText()??e.getName(),r=e.getFirstAncestorByKind(j.VariableDeclaration)?.getInitializer()?.getType().getProperty(i)?.getValueDeclaration();return r?T(r,t+1):void 0}},ae=e=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t)){const n=[];for(const o of t.getElements()){const a=u(o.getNameNode());a&&n.push([o.getName(),a])}return n}const i=e.getInitializer(),r=i&&(s.isCallExpression(i)?i:u(i));return r?[[e.getName(),r]]:[]},ce=(e,t,i)=>{const r=se(e);if(r)return{args:r.args,exportName:t,filePath:i,kind:r.kind,returnType:r.returnType,visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},le=(e,t)=>{const i=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations())for(const[o,a]of ae(n)){const c=ce(a,o,t);c&&i.push(c)}return i},ue=e=>{const t=new Map;for(const i of e){const r=U(i.filePath),n=t.get(r);if(n&&n!==i.filePath)throw Object.assign(new Error(`Namespace collision: "${n}" and "${i.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[n,i.filePath],status:500});t.set(r,i.filePath)}},Ae=(e,t)=>{const i=N(t),r=[];for(const n of i){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),a=H(t,n);r.push(...le(o,a))}return r.sort((n,o)=>`${n.filePath}:${n.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),ue(r),r};export{be as chainHasStep,ve as chainUsesWrappedCall,re as classifyProcedureCall,Ae as discoverFunctions,E as inlineHandler,xe as isDatabaseAccessor,N as listLunoraSourceFiles,H as lunoraRelativePath,Ee as procedureHandler,S as unwrapHandlerReturn};
|