@lunora/codegen 1.0.0-alpha.135 → 1.0.0-alpha.136
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.mjs +1 -1
- package/dist/packem_shared/{MUTATORS_FILENAME-D1a0-wNV.mjs → MUTATORS_FILENAME-VnV3vpJh.mjs} +1 -1
- package/dist/packem_shared/{NOTIFY_FILENAME-B0p73Gm8.mjs → NOTIFY_FILENAME-3xSHPaVK.mjs} +1 -1
- package/dist/packem_shared/{SCHEMA_SNAPSHOT_FILENAME-DxQyv2mO.mjs → SCHEMA_SNAPSHOT_FILENAME-DIVmMUEJ.mjs} +1 -1
- package/dist/packem_shared/discoverFunctions-2ajN70Q9.mjs +1 -0
- package/dist/packem_shared/{discoverHttpRoutes-DpWRI--A.mjs → discoverHttpRoutes-DDhmUyVN.mjs} +1 -1
- package/dist/packem_shared/{discoverMaskProcedures-DYtwf257.mjs → discoverMaskProcedures-CjfyneNc.mjs} +1 -1
- package/dist/packem_shared/{discoverNondeterministicCalls-CwvKy5-r.mjs → discoverNondeterministicCalls-CSI5ir3L.mjs} +1 -1
- package/dist/packem_shared/{discoverR2sqlCalls-_bVEyLb8.mjs → discoverR2sqlCalls-NtUJIKqo.mjs} +1 -1
- package/dist/packem_shared/{discoverRlsMetadata-BV_yswEJ.mjs → discoverRlsMetadata-BA9lVt-Q.mjs} +1 -1
- package/dist/packem_shared/{discoverStorageRulesMetadata-DbDybCNX.mjs → discoverStorageRulesMetadata-DudvC-VM.mjs} +1 -1
- package/package.json +1 -1
- package/dist/packem_shared/discoverFunctions-CKff5HG0.mjs +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CftvRWB8.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as S}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as E,diagnosticAt as x}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-CPHo8Se5.mjs";import{default as g}from"./packem_shared/discoverAuthApiCalls-DUjcl0SB.mjs";import{CONTAINERS_FILENAME as R,discoverContainers as M}from"./packem_shared/CONTAINERS_FILENAME-Bvn6LZP6.mjs";import{default as C}from"./packem_shared/discoverCrons-BUJO2ipU.mjs";import{FLAGS_FILENAME as T,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-DtBWyUKq.mjs";import{discoverFunctions as F}from"./packem_shared/discoverFunctions-
|
|
1
|
+
import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CftvRWB8.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as S}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as E,diagnosticAt as x}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-CPHo8Se5.mjs";import{default as g}from"./packem_shared/discoverAuthApiCalls-DUjcl0SB.mjs";import{CONTAINERS_FILENAME as R,discoverContainers as M}from"./packem_shared/CONTAINERS_FILENAME-Bvn6LZP6.mjs";import{default as C}from"./packem_shared/discoverCrons-BUJO2ipU.mjs";import{FLAGS_FILENAME as T,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-DtBWyUKq.mjs";import{discoverFunctions as F}from"./packem_shared/discoverFunctions-2ajN70Q9.mjs";import{default as P}from"./packem_shared/discoverHttpRoutes-DDhmUyVN.mjs";import{default as G}from"./packem_shared/discoverInserts-YX8AmrzL.mjs";import{default as b}from"./packem_shared/discoverMaskProcedures-CjfyneNc.mjs";import{default as y}from"./packem_shared/discoverMigrations-4Jjf5DJE.mjs";import{MUTATORS_FILENAME as j,discoverMutators as K}from"./packem_shared/MUTATORS_FILENAME-VnV3vpJh.mjs";import{default as z}from"./packem_shared/discoverNondeterministicCalls-CSI5ir3L.mjs";import{NOTIFY_FILENAME as w,discoverNotifyCalls as q,discoverNotifyConfig as B}from"./packem_shared/NOTIFY_FILENAME-3xSHPaVK.mjs";import{default as Y}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as Z}from"./packem_shared/discover-queries-Dfj_0WJG.mjs";import{QUEUES_FILENAME as ee,discoverQueues as re}from"./packem_shared/QUEUES_FILENAME-BnGLtAIu.mjs";import{default as te}from"./packem_shared/discoverR2sqlCalls-NtUJIKqo.mjs";import{discoverRlsMetadata as ae,default as ie}from"./packem_shared/discoverRlsMetadata-BA9lVt-Q.mjs";import{discoverSandboxUsage as de}from"./packem_shared/discoverSandboxUsage-L0lV17de.mjs";import{default as pe}from"./packem_shared/discoverSchema-Hsu_1xIc.mjs";import{SHAPES_FILENAME as ne,discoverShapes as Se}from"./packem_shared/SHAPES_FILENAME-BTdasTq2.mjs";import{default as Ee}from"./packem_shared/discoverStorageRulesMetadata-DudvC-VM.mjs";import{WORKFLOWS_FILENAME as Ae,discoverWorkflows as ue}from"./packem_shared/WORKFLOWS_FILENAME-B8y51Frf.mjs";import{G as Ne,e as ge,a as Oe,b as Re,c as Me,d as he,f as Ce,g as _e,h as Te,i as Ie,j as Le,k as Fe,l as De,m as Pe}from"./packem_shared/emit-khv5P1pH.mjs";import{emitApp as Ge}from"./packem_shared/emitApp-CZ_yiNNO.mjs";import{buildOpenApiDocument as be,emitOpenApi as ke,emitOpenApiModule as ye}from"./packem_shared/buildOpenApiDocument-B3l1QPs9.mjs";import{OPENRPC_VERSION as je,buildOpenRpcDocument as Ke,emitOpenRpc as Ve,emitOpenRpcModule as ze}from"./packem_shared/OPENRPC_VERSION-CtO1oRu-.mjs";import{DEFAULT_TARGET as we,platformMatrixIds as qe,readProjectTarget as Be,resolveCodegenTarget as Je}from"./packem_shared/DEFAULT_TARGET-CrhWLUK7.mjs";import{SCHEMA_SNAPSHOT_FILENAME as Xe,createCodegenProject as Ze,findTsconfig as $e,refreshCodegenProject as er,runCodegen as rr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-DIVmMUEJ.mjs";import{SchemaSnapshotParseError as tr,buildSchemaSnapshot as sr,evaluateSchemaDrift as ar,parseSchemaSnapshot as ir}from"./packem_shared/SchemaSnapshotParseError-D2h88OHU.mjs";import{schemaFromIr as dr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as pr,validatorIrToJsonSchema as cr}from"./packem_shared/LUNORA_ERROR_CODES-BYg8Lpgb.mjs";import{SDK_LANGUAGES as Sr,SDK_TARGETS as lr,generateSdk as Er}from"./packem_shared/SDK_LANGUAGES-CFyux-74.mjs";import{redact as Ar,secretKindOf as ur}from"./packem_shared/redact-Cy14LEnc.mjs";import{MESSAGE_SOLUTIONS as Nr,findSolutionByMessage as gr}from"@lunora/errors";import{isTypedSchema as Rr}from"./packem_shared/isTypedSchema-B_qlBbE-.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,R as CONTAINERS_FILENAME,E as CodegenDiagnosticError,we as DEFAULT_TARGET,T as FLAGS_FILENAME,Ne as GENERATED_HEADER,pr as LUNORA_ERROR_CODES,Nr as LUNORA_SOLUTION_RULES,j as MUTATORS_FILENAME,w as NOTIFY_FILENAME,je as OPENRPC_VERSION,ee as QUEUES_FILENAME,Xe as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,Sr as SDK_LANGUAGES,lr as SDK_TARGETS,ne as SHAPES_FILENAME,tr as SchemaSnapshotParseError,e as VERSION,Ae as WORKFLOWS_FILENAME,be as buildOpenApiDocument,Ke as buildOpenRpcDocument,sr as buildSchemaSnapshot,Ze as createCodegenProject,c as describeErrorLevelFindings,x as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,g as discoverAuthApiCalls,M as discoverContainers,C as discoverCrons,I as discoverFlags,F as discoverFunctions,P as discoverHttpRoutes,G as discoverInserts,b as discoverMaskProcedures,y as discoverMigrations,K as discoverMutators,z as discoverNondeterministicCalls,q as discoverNotifyCalls,B as discoverNotifyConfig,Z as discoverQueries,re as discoverQueues,te as discoverR2sqlCalls,ae as discoverRlsMetadata,ie as discoverRlsProcedures,de as discoverSandboxUsage,pe as discoverSchema,Se as discoverShapes,Ee as discoverStorageRulesMetadata,ue as discoverWorkflows,ge as emitAgents,Oe as emitApi,Ge as emitApp,Re as emitCollections,Me as emitContainers,he as emitCrons,Ce as emitDataModel,_e as emitDrizzleSchema,Te as emitFunctions,ke as emitOpenApi,ye as emitOpenApiModule,Ve as emitOpenRpc,ze as emitOpenRpcModule,Ie as emitServer,Le as emitShard,Fe as emitVectors,De as emitWorkflows,Pe as emitWranglerCronTriggers,n as errorAdvisoryNames,S as errorPlatformDiagnosticNames,ar as evaluateSchemaDrift,gr as findLunoraSolution,$e as findTsconfig,m as formatAdvisories,Er as generateSdk,Rr as isTypedSchema,d as lintSchema,ir as parseSchemaSnapshot,qe as platformMatrixIds,Y as readPackageDependencies,Be as readProjectTarget,Ar as redact,er as refreshCodegenProject,Je as resolveCodegenTarget,rr as runCodegen,dr as schemaFromIr,ur as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,cr as validatorIrToJsonSchema};
|
package/dist/packem_shared/{MUTATORS_FILENAME-D1a0-wNV.mjs → MUTATORS_FILENAME-VnV3vpJh.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as f}from"node:fs";import{join as p}from"node:path";import{Node as o,SyntaxKind as u}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapHandlerReturn as g}from"./discoverFunctions-
|
|
1
|
+
import{existsSync as f}from"node:fs";import{join as p}from"node:path";import{Node as o,SyntaxKind as u}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapHandlerReturn as g}from"./discoverFunctions-2ajN70Q9.mjs";import{a as d}from"./module-specifiers-WF8iAydP.mjs";import{a as x}from"./parse-validator-BFTp87yz.mjs";const M="mutators.ts",m=d,y=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineMutator";for(const e of t.getDeclarations())if(o.isImportSpecifier(e))return m(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineMutator":!1;return!1},S=r=>{const t=r.getSymbol();if(!t)return!1;for(const e of t.getDeclarations()){if(!o.isNamespaceImport(e))continue;const i=e.getFirstAncestorByKind(u.ImportDeclaration);return i!==void 0&&m(i.getModuleSpecifierValue())}return!1},N=r=>{if(o.isIdentifier(r))return y(r);if(o.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(t)&&S(t)}return!1},I=r=>{const t=r.getArguments()[0];return t&&o.isObjectLiteralExpression(t)?t:void 0},b=r=>{const t=r?.getProperty("args");if(!t||!o.isPropertyAssignment(t))return{};const e=t.getInitializer();return e&&o.isObjectLiteralExpression(e)?x(e):{}},A=r=>{const t=r?.getProperty("server");if(!t||!o.isPropertyAssignment(t))return"unknown";const e=t.getInitializer();return!e||!(o.isArrowFunction(e)||o.isFunctionExpression(e))?"unknown":g(e)},E=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const i=e.getInitializer();if(i?.getKind()!==u.CallExpression)continue;const n=i,a=n.getExpression();if(!N(a))continue;const s=e.getNameNode();if(!o.isIdentifier(s))throw l(s,"defineMutator exports must be plain named exports (no destructuring)");const c=I(n);t.push({args:b(c),exportName:s.getText(),filePath:"mutators",returnType:A(c)})}return t},w=(r,t)=>{const e=p(t,M);if(!f(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),n=E(i);return n.sort((a,s)=>a.exportName.localeCompare(s.exportName)),n};export{M as MUTATORS_FILENAME,w as discoverMutators,N as isDefineMutatorCallee};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as m}from"node:fs";import{join as x}from"node:path";import{SyntaxKind as d,Node as c}from"ts-morph";import{l,a as g,d as P,h as E}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as S}from"./discoverFunctions-
|
|
1
|
+
import{existsSync as m}from"node:fs";import{join as x}from"node:path";import{SyntaxKind as d,Node as c}from"ts-morph";import{l,a as g,d as P,h as E}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as S}from"./discoverFunctions-2ajN70Q9.mjs";const y="notify.ts",v=new Set(["chat","inApp","send","webhook"]),p=new Set(["broadcast","send"]),N=e=>{const t=e.getInitializer();if(!t||!c.isCallExpression(t))return;const o=S(t);if(!o)return;const s=E(t,o.receiver);return s?{exportName:e.getName(),handler:s,kind:o.kind}:void 0},h=e=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const s of o.getDeclarations()){const r=N(s);r&&t.push(r)}return t},f=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=e.getExpression();if((t==="notify"||t==="push")&&c.isIdentifier(o)&&o.getText()==="ctx")return t;if(t==="push"&&f(o)==="notify")return"push"},F=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=f(e.getExpression());if(o==="notify"&&v.has(t))return`ctx.notify.${t}`;if(o==="push"&&p.has(t))return`ctx.push.${t}`},A=e=>c.isPropertyAccessExpression(e)?f(e.getExpression())==="push"&&p.has(e.getName()):!1,T=(e,t)=>{const o=[];for(const s of l(t)){const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),a=g(t,s);for(const n of h(r))if(!(n.kind!=="query"&&n.kind!=="mutation"))for(const i of n.handler.getDescendantsOfKind(d.PropertyAccessExpression)){const u=F(i);u!==void 0&&o.push({callee:u,exportName:n.exportName,file:a,kind:n.kind,line:i.getStartLineNumber()})}}return o},O=(e,t)=>{for(const o of l(t)){const s=e.getSourceFile(o)??e.addSourceFileAtPath(o);for(const r of h(s))for(const a of r.handler.getDescendantsOfKind(d.PropertyAccessExpression))if(A(a))return!0}return!1},_=(e,t)=>{const o=x(t,y);if(!m(o))return;const s=e.getSourceFile(o)??e.addSourceFileAtPath(o),r=P(s);let a=!1,n=!1;if(r&&c.isCallExpression(r)){const i=r.getArguments()[0];i&&c.isObjectLiteralExpression(i)&&(a=i.getProperty("webPush")!==void 0,n=i.getProperty("fcm")!==void 0)}return{hasFcm:n,hasWebPush:a,usesPush:O(e,t)}};export{y as NOTIFY_FILENAME,T as discoverNotifyCalls,_ as discoverNotifyConfig};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{existsSync as y,mkdirSync as Xt,readFileSync as vt,writeFileSync as Zt,rmSync as Jt}from"node:fs";import{join as f,dirname as ue}from"node:path";import{performance as de}from"node:perf_hooks";import{runAdvisor as es}from"@lunora/advisor";import{LunoraError as D}from"@lunora/errors";import{SyntaxKind as l,Node as i,Project as Ye}from"ts-morph";import{serializeSchemaSnapshot as ts}from"./SCHEMA_SNAPSHOT_VERSION-CftvRWB8.mjs";import{toAdvisorContext as ss}from"./formatAdvisories-CkEu1eye.mjs";import{discoverAgents as ns}from"./AGENTS_FILENAME-CPHo8Se5.mjs";import{discoverContainers as rs}from"./CONTAINERS_FILENAME-Bvn6LZP6.mjs";import{diagnosticAt as ee}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as te}from"./module-specifiers-WF8iAydP.mjs";import{C as fe,i as is,f as os,n as as,j as cs,b as ls,c as us,l as ds,e as fs,o as ps,d as gs,k as ms,g as hs,p as xs,m as Es,a as vs,h as Ss}from"./emit-khv5P1pH.mjs";import{l as m,a as x,c as b,p as A,f as St,h as As,i as Ns,r as At,e as ys}from"./discover-ast-D33zP-NZ.mjs";import bs from"./readPackageDependencies-C6h6FZuP.mjs";import{discoverQueues as Is}from"./QUEUES_FILENAME-BnGLtAIu.mjs";import{discoverSandboxUsage as Ps}from"./discoverSandboxUsage-L0lV17de.mjs";import ws from"./discoverStorageRulesMetadata-
|
|
1
|
+
import{existsSync as y,mkdirSync as Xt,readFileSync as vt,writeFileSync as Zt,rmSync as Jt}from"node:fs";import{join as f,dirname as ue}from"node:path";import{performance as de}from"node:perf_hooks";import{runAdvisor as es}from"@lunora/advisor";import{LunoraError as D}from"@lunora/errors";import{SyntaxKind as l,Node as i,Project as Ye}from"ts-morph";import{serializeSchemaSnapshot as ts}from"./SCHEMA_SNAPSHOT_VERSION-CftvRWB8.mjs";import{toAdvisorContext as ss}from"./formatAdvisories-CkEu1eye.mjs";import{discoverAgents as ns}from"./AGENTS_FILENAME-CPHo8Se5.mjs";import{discoverContainers as rs}from"./CONTAINERS_FILENAME-Bvn6LZP6.mjs";import{diagnosticAt as ee}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as te}from"./module-specifiers-WF8iAydP.mjs";import{C as fe,i as is,f as os,n as as,j as cs,b as ls,c as us,l as ds,e as fs,o as ps,d as gs,k as ms,g as hs,p as xs,m as Es,a as vs,h as Ss}from"./emit-khv5P1pH.mjs";import{l as m,a as x,c as b,p as A,f as St,h as As,i as Ns,r as At,e as ys}from"./discover-ast-D33zP-NZ.mjs";import bs from"./readPackageDependencies-C6h6FZuP.mjs";import{discoverQueues as Is}from"./QUEUES_FILENAME-BnGLtAIu.mjs";import{discoverSandboxUsage as Ps}from"./discoverSandboxUsage-L0lV17de.mjs";import ws from"./discoverStorageRulesMetadata-DudvC-VM.mjs";import{discoverWorkflows as Ts}from"./WORKFLOWS_FILENAME-B8y51Frf.mjs";import{gatePlatformFeatures as Cs,resolveCodegenTarget as Rs}from"./DEFAULT_TARGET-CrhWLUK7.mjs";import{i as T,a as k,e as v,c as P,r as Os,b as Fs,s as se,f as Ls,g as Ds,d as ks}from"./discover-queries-Dfj_0WJG.mjs";import{classifyProcedureCall as M,inlineHandler as Ms,procedureHandler as Nt,chainUsesWrappedCall as yt,isDatabaseAccessor as _,chainHasStep as Ks,discoverFunctions as Qe,resolveStandardSchemaType as _s}from"./discoverFunctions-2ajN70Q9.mjs";import zs from"./discoverAuthApiCalls-DUjcl0SB.mjs";import Us from"./discoverCrons-BUJO2ipU.mjs";import{discoverFlagKeys as Bs}from"./FLAGS_FILENAME-DtBWyUKq.mjs";import Xe from"./discoverHttpRoutes-DDhmUyVN.mjs";import qs from"./discoverInserts-YX8AmrzL.mjs";import $s,{discoverMaskStrategies as js,discoverMaskMetadata as Vs,discoverMaskHasNonLiteralPolicy as Ws}from"./discoverMaskProcedures-CjfyneNc.mjs";import Hs from"./discoverMigrations-4Jjf5DJE.mjs";import{MUTATORS_FILENAME as Gs,isDefineMutatorCallee as Ys,discoverMutators as Ze}from"./MUTATORS_FILENAME-VnV3vpJh.mjs";import Qs from"./discoverNondeterministicCalls-CSI5ir3L.mjs";import{discoverNotifyConfig as Xs,discoverNotifyCalls as Zs}from"./NOTIFY_FILENAME-3xSHPaVK.mjs";import Js from"./discoverR2sqlCalls-NtUJIKqo.mjs";import en,{discoverRlsMetadata as tn}from"./discoverRlsMetadata-BA9lVt-Q.mjs";import sn from"./discoverSchema-Hsu_1xIc.mjs";import{secretKindOf as nn,redact as rn,isHeuristicSecretKind as on,isSecretishName as an}from"./redact-Cy14LEnc.mjs";import{discoverShapes as cn}from"./SHAPES_FILENAME-BTdasTq2.mjs";import{emitApp as ln}from"./emitApp-CZ_yiNNO.mjs";import{buildOpenApiDocument as un,emitOpenApiModule as dn}from"./buildOpenApiDocument-B3l1QPs9.mjs";import{buildOpenRpcDocument as fn,emitOpenRpcModule as pn}from"./OPENRPC_VERSION-CtO1oRu-.mjs";import{s as gn}from"./parse-validator-BFTp87yz.mjs";import{buildSchemaSnapshot as mn}from"./SchemaSnapshotParseError-D2h88OHU.mjs";const hn=e=>{const t=[],s=e.tables.filter(n=>n.shardMode==="global");return s.some(n=>n.globalBackend!=="hyperdrive")&&t.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),s.some(n=>n.globalBackend==="hyperdrive")&&t.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'}),e.vectorIndexes.length>0&&t.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/vectors.ts` import `@lunora/bindings/vectors`"}),t},xn=(e,t)=>{if(t===void 0)return;const s=hn(e).filter(o=>!t.has(o.name));if(s.length===0)return;const n=s.map(o=>` - ${o.name} — ${o.reason}`).join(`
|
|
2
2
|
`);throw new D("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
|
|
3
3
|
${n}
|
|
4
4
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{posix as N}from"node:path";import{SyntaxKind as u,Node as o}from"ts-morph";import{l as q,a as K}from"./discover-ast-D33zP-NZ.mjs";import{a as H}from"./module-specifiers-WF8iAydP.mjs";import{p as W,a as D}from"./parse-validator-BFTp87yz.mjs";import{s as X}from"./paths-C-9fwEgQ.mjs";const x=new Set(["action","mutation","query","stream"]),C=/\bany\b(?!\s*(?:\?\s*)?:)/u,k=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,G=/^[A-Za-z_$][\w$]*$/u,J=e=>G.test(e)?e:JSON.stringify(e),L={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},Q={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init"},Y=H,O=e=>{const t=e.getSymbol();if(!t)return e.getText();const i=t.getDeclarations();for(const r of i){if(!o.isImportSpecifier(r))continue;const s=r.getImportDeclaration().getModuleSpecifierValue();return Y(s)?r.getNameNode().getText():void 0}},w=(e,t=!1)=>{let i=e;for(;o.isCallExpression(i);){const n=i.getExpression();if(!o.isPropertyAccessExpression(n))return;i=n.getExpression()}if(!o.isIdentifier(i))return;const r=O(i);if(r===void 0){if(t)return;const n=i.getSymbol()?.getValueDeclaration();if(n&&o.isVariableDeclaration(n)){const s=n.getInitializer();return s?w(s,!0):void 0}return}return x.has(r)?"public":L[r]?"internal":void 0},b=(e,t)=>{const i=e.getProperty(t);if(i===void 0||!o.isPropertyAssignment(i))return;const r=i.getInitializer();return r!==void 0&&o.isStringLiteral(r)?r.getLiteralValue():void 0},P=(e,t)=>{const i=e.getProperty(t);if(i===void 0||!o.isPropertyAssignment(i))return;const r=i.getInitializer();return r!==void 0&&o.isNumericLiteral(r)?r.getLiteralValue():void 0},Z=e=>{const t=e.getProperty("cache");if(t===void 0||!o.isPropertyAssignment(t))return;const i=t.getInitializer();if(i===void 0||!o.isObjectLiteralExpression(i))return;const r=b(i,"scope"),n=P(i,"maxAge"),s=P(i,"staleWhileRevalidate"),a=b(i,"tag"),c=b(i,"vary"),l={...n===void 0?{}:{maxAge:n},...r==="private"||r==="public"?{scope:r}:{},...s===void 0?{}:{staleWhileRevalidate:s},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},ee=e=>{if(e===void 0||!o.isObjectLiteralExpression(e))return{};const t=Z(e),i=e.getProperty("rest");return i!==void 0&&o.isPropertyAssignment(i)?{...t===void 0?{}:{cache:t},rest:i.getInitializer()?.getText()==="true"}:t===void 0?{}:{cache:t}},te=e=>{let t=e;for(;o.isCallExpression(t);){const i=t.getExpression();if(!o.isPropertyAccessExpression(i))return;if(i.getName()==="expose")return ee(t.getArguments()[0]);t=i.getExpression()}},ie=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return{};const i=t.getProperty("args");if(!i||!o.isPropertyAssignment(i))return{};const r=i.getInitializer();return!r||!o.isObjectLiteralExpression(r)?{}:D(r)},re="/_generated/",ne=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(i=>i?.getDeclarations()??[]);return t.length>0&&t.every(i=>i.getSourceFile().getSymbol()===void 0)},se=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,F=e=>{for(const t of e.getAncestors())if(o.isModuleDeclaration(t)){const i=se.exec(t.getName());if(i?.groups?.specifier!==void 0)return i.groups.specifier}},h=new WeakMap,oe=(e,t)=>{const i=e.getSymbol();if(i===void 0)return;let r=h.get(i.compilerSymbol);return r===void 0&&(r=new Map,h.set(i.compilerSymbol,r)),r.has(t)||r.set(t,i.getExport(t)??e.getExportSymbols().find(n=>n.getName()===t)),r.get(t)},M=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(i=>i.getName()===t),ae=(e,t,i)=>e.getModuleSpecifierValue()===t&&M(e,i)?i:void 0,ce=(e,t)=>{const i=e.getDefaultImport();if(i===void 0)return;const r=i.getSymbol();return(r?.getAliasedSymbol()??r)?.getDeclarations().includes(t)===!0?"default":void 0},le=(e,t,i)=>{if(!M(e,i))return;const r=e.getModuleSpecifierSourceFile(),n=r===void 0?void 0:oe(r,i);return(n?.getAliasedSymbol()??n)?.getDeclarations().includes(t)===!0?i:void 0},ue=/^\.\.?(?:$|\/)/u,ge=new Map([[".cjs",".cjs"],[".cts",".cjs"],[".d.ts",".js"],[".js",".js"],[".jsx",".jsx"],[".mjs",".mjs"],[".mts",".mjs"],[".ts",".js"],[".tsx",".js"]]),fe=(e,t)=>{const i=t.getModuleSpecifierValue();if(!ue.test(i))return;const r=t.getModuleSpecifierSourceFile(),n=r===void 0?void 0:ge.get(r.getExtension());if(r===void 0||n===void 0)return;const s=`${N.join(r.getDirectoryPath(),r.getBaseNameWithoutExtension())}${n}`,a=N.relative(e.getDirectoryPath(),s);return a.startsWith(".")?a:`./${a}`},de=(e,t,i)=>{const r=F(t);for(const n of e.getImportDeclarations()){const s=r===void 0?ce(n,t)??le(n,t,i):ae(n,r,i);if(s!==void 0)return{exportName:s,specifier:fe(e,n)??n.getModuleSpecifierValue()}}},pe=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(i=>{const r=i.indexOf("*");return r===-1?e===i:e.startsWith(i.slice(0,r))&&e.endsWith(i.slice(r+1))}),g={kind:"verbatim"},m={kind:"expand"},me=new Set([u.ClassDeclaration,u.EnumDeclaration,u.EnumMember,u.InterfaceDeclaration,u.TypeAliasDeclaration]),R=(e,t,i)=>{const r=e.getSourceFile();if(r.getSymbol()===void 0&&F(e)===void 0||!me.has(e.getKind()))return g;const n=r.getFilePath();if(n.includes(re))return g;if(n===i)return m;const s=o.isEnumMember(e)?e.getParent():e;if(!o.hasName(s))return m;const a=de(t.getSourceFile(),s,s.getName());return a===void 0?g:pe(a.specifier,t)?m:{kind:"qualify",qualified:a}},j=(e,t,i)=>{const r=e.getAliasSymbol(),n=e.getSymbol(),s=new Set((r??n)?.getDeclarations());let a=!1;for(const c of[n,r].flatMap(l=>l?.getDeclarations()??[])){const l=R(c,t,i);if(l.kind==="qualify"&&s.has(c))return l;a||=l.kind!=="verbatim"}return a?m:g},ve=(e,t,i)=>{const r=o.isPropertySignature(e)||o.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(r===void 0)return g;let n=!1;for(const s of[r,...r.getDescendantsOfKind(u.TypeReference)].filter(a=>o.isTypeReference(a))){const a=s.getTypeName().getSymbol();for(const c of(a?.getAliasedSymbol()??a)?.getDeclarations()??[]){const l=R(c,t,i);if(l.kind==="qualify")return l;n||=l.kind!=="verbatim"}}return n?m:g},_=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,v=(e,t,i,r=new Set)=>r.has(e)?!1:(r.add(e),j(e,t,i).kind!=="verbatim"||_(e).some(n=>v(n,t,i,r))?!0:S(e)?e.getProperties().some(n=>n.getDeclarations().some(s=>ve(s,t,i).kind!=="verbatim")?!0:v(n.getTypeAtLocation(t),t,i,r)):!1),ye=(e,t)=>{const i=e.getValueDeclaration()??e.getDeclarations()[0];return i&&(o.isPropertySignature(i)||o.isPropertyDeclaration(i))&&i.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},$=8,Ee=(e,t,i,r,n,s)=>{const a=e.getArrayElementType(),c=a?s(a,t,i,r,n):void 0;if(c!==void 0)return a?.isUnion()?`(${c})[]`:`${c}[]`},be=(e,t,i,r,n,s)=>{const a=[];for(const c of e.getUnionTypes()){const l=s(c,t,i,r,n);if(l===void 0)return;a.push(l)}return a.join(" | ")},xe=(e,t,i,r,n,s)=>{if(!S(e))return;const a=[];for(const c of e.getProperties()){const l=c.getTypeAtLocation(t),p=ye(c,l),B=p&&l.isUnion()?l.getUnionTypes().filter(E=>!E.isUndefined()):[l],A=[];for(const E of B){const T=s(E,t,i,r+1,n);if(T===void 0)return;A.push(T)}a.push(`${J(c.getName())}${p?"?":""}: ${A.join(" | ")}`)}return a.length>0?`{ ${a.join("; ")} }`:"{}"},Se=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},Ae=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>o.isClassDeclaration(t)||o.isClassExpression(t)),y=(e,t,i,r)=>{if(i>$||r.has(e))return!1;const n=new Set(r).add(e);if(_(e).some(c=>y(c,t,i+1,n)))return!0;const s=e.getArrayElementType();return s!==void 0?y(s,t,i+1,n):ne(e)?!1:e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(c=>c?.getDeclarations()??[]).some(c=>o.isClassDeclaration(c)||o.isClassExpression(c))?!0:S(e)&&e.getProperties().some(c=>y(c.getTypeAtLocation(t),t,i+1,n))},Te=(e,t,i,r,n,s,a)=>{const c=[];for(const l of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const p=a(l,i,r,n+1,s);if(p===void 0)return;c.push(p)}return`import("${e.specifier}").${e.exportName}${c.length>0?`<${c.join(", ")}>`:""}`},Ne=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>o.isEnumDeclaration(t)||o.isEnumMember(t)),f=(e,t,i,r,n)=>{if(r>$||n.has(e))return;const s=j(e,t,i);if(s.kind==="verbatim"&&!v(e,t,i))return e.getText(t);const a=new Set(n).add(e);if(!Ae(e)){if(e.isEnumLiteral())return Se(e);if(s.kind==="qualify"&&!Ne(e)){const c=Te(s.qualified,e,t,i,r,a,f);if(c!==void 0)return c}return e.isArray()?Ee(e,t,i,r,a,f):e.isUnion()?be(e,t,i,r,a,f):xe(e,t,i,r,a,f)}},z=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let i=t.getReturnType();const n=(i.getSymbol()??i.getAliasSymbol())?.getName();if(n==="Promise"||n==="AsyncIterable"||n==="AsyncIterableIterator"||n==="AsyncGenerator"){const c=i.getTypeArguments()[0];c&&(i=c)}const s=i.getText(e);if(!s||s==="any"||s==="never"||C.test(s.replaceAll(k,""))||y(i,e,0,new Set))return"unknown";const a=e.getSourceFile().getFilePath();return v(i,e,a)?f(i,e,a,0,new Set)??"unknown":s},Be=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const i=t.getTypeAtLocation(e).getProperty("types");if(!i)return;const r=i.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!r)return;const n=r.getTypeAtLocation(e),s=n.getText(e);if(!s||s==="any"||s==="never"||C.test(s.replaceAll(k,"")))return;const a=e.getSourceFile().getFilePath();return v(n,e,a)?f(n,e,a,0,new Set):s},Pe=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return"unknown";const i=t.getProperty("handler");if(!i||!o.isPropertyAssignment(i))return"unknown";const r=i.getInitializer();return!r||!(o.isArrowFunction(r)||o.isFunctionExpression(r))?"unknown":z(r)},he=e=>{const t=e.getArguments()[0];return!t||!(o.isArrowFunction(t)||o.isFunctionExpression(t))?"unknown":z(t)},Ie=e=>{let t={},i=e;for(;o.isCallExpression(i);){const r=i.getExpression();if(!o.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const n=i.getArguments()[0];n&&o.isObjectLiteralExpression(n)&&(t={...D(n),...t})}i=r.getExpression()}return t},De=e=>{let t=e;for(;o.isCallExpression(t);){const i=t.getExpression();if(!o.isPropertyAccessExpression(i))return;if(i.getName()==="output"){const r=t.getArguments()[0];return r&&o.isExpression(r)?W(r):void 0}t=i.getExpression()}},Ce=e=>{const t=e.getExpression();if(o.isPropertyAccessExpression(t)){const s=t.getName();if(!x.has(s))return;const a=t.getExpression();if(a.getType().getProperty("__lunoraProcedure"))return{kind:s,receiver:a,visibility:a.getType().getProperty("__lunoraVisibility")?"internal":"public"};const c=w(a);return c?{kind:s,receiver:a,visibility:c}:void 0}if(!o.isIdentifier(t))return;const i=O(t);if(!i)return;if(x.has(i))return{kind:i,visibility:"public"};const r=L[i];if(r)return{kind:r,visibility:"internal"};const n=Q[i];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}},I=e=>e!==void 0&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,qe=e=>o.isPropertyAccessExpression(e)&&e.getName()==="db"||o.isIdentifier(e)&&e.getText()==="db",Ke=e=>{const t=e.getArguments()[0],i=I(t);if(i!==void 0)return i;if(t===void 0||!o.isObjectLiteralExpression(t))return;const r=t.getProperty("handler");return r!==void 0&&o.isPropertyAssignment(r)?I(r.getInitializer()):void 0},ke=e=>o.isIdentifier(e)?e.getText():o.isPropertyAccessExpression(e)?e.getName():"",He=(e,t)=>{let i=e;for(;o.isCallExpression(i);){const r=i.getExpression();if(!o.isPropertyAccessExpression(r))break;if(r.getName()===t)return!0;i=r.getExpression()}return!1},We=(e,t,i)=>{let r=e;for(;o.isCallExpression(r);){const n=r.getExpression();if(!o.isPropertyAccessExpression(n))break;const s=r.getArguments()[0];if(n.getName()===t&&s!==void 0&&o.isCallExpression(s)&&ke(s.getExpression())===i)return!0;r=n.getExpression()}return!1},Le=e=>{const t=Ce(e);if(t){if(t.receiver){const i=te(t.receiver),r=De(t.receiver);return{args:Ie(t.receiver),...i?{expose:i}:{},kind:t.kind,...r?{output:r}:{},returnType:he(e),visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:ie(e),kind:t.kind,returnType:Pe(e),visibility:t.visibility}}},Oe=8,d=(e,t=0)=>{if(t>Oe)return;if(o.isCallExpression(e))return e;if(o.isParenthesizedExpression(e)||o.isAsExpression(e)||o.isSatisfiesExpression(e)||o.isNonNullExpression(e))return d(e.getExpression(),t+1);if(!o.isIdentifier(e)&&!o.isPropertyAccessExpression(e))return;const i=e.getSymbol()?.getValueDeclaration();return i?U(i,t+1):void 0},U=(e,t)=>{if(o.isVariableDeclaration(e)||o.isPropertyAssignment(e)){const i=e.getInitializer();return i?d(i,t):void 0}if(o.isShorthandPropertyAssignment(e))return d(e.getNameNode(),t);if(o.isBindingElement(e)){const i=e.getPropertyNameNode()?.getText()??e.getName(),s=e.getFirstAncestorByKind(u.VariableDeclaration)?.getInitializer()?.getType().getProperty(i)?.getValueDeclaration();return s?U(s,t+1):void 0}},we=e=>{const t=e.getNameNode();if(o.isObjectBindingPattern(t)){const n=[];for(const s of t.getElements()){const a=d(s.getNameNode());a&&n.push([s.getName(),a])}return n}const i=e.getInitializer(),r=i&&(o.isCallExpression(i)?i:d(i));return r?[[e.getName(),r]]:[]},V=(e,t,i)=>{const r=Le(e);if(r)return{args:r.args,exportName:t,filePath:i,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},Fe=(e,t)=>{const i=[];for(const r of e.getExportAssignments()){if(r.isExportEquals())continue;const n=d(r.getExpression()),s=n?V(n,"default",t):void 0;s&&i.push(s)}return i},Me=(e,t)=>{const i=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations())for(const[s,a]of we(n)){const c=V(a,s,t);c&&i.push(c)}return i.push(...Fe(e,t)),i},Re=e=>{const t=new Map;for(const i of e){const r=X(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)}},Xe=(e,t)=>{const i=q(t),r=[];for(const n of i){const s=e.getSourceFile(n)??e.addSourceFileAtPath(n),a=K(t,n);r.push(...Me(s,a))}return r.sort((n,s)=>`${n.filePath}:${n.exportName}`.localeCompare(`${s.filePath}:${s.exportName}`)),Re(r),r};export{He as chainHasStep,We as chainUsesWrappedCall,Ce as classifyProcedureCall,Xe as discoverFunctions,I as inlineHandler,qe as isDatabaseAccessor,q as listLunoraSourceFiles,K as lunoraRelativePath,Ke as procedureHandler,Be as resolveStandardSchemaType,z as unwrapHandlerReturn};
|
package/dist/packem_shared/{discoverHttpRoutes-DpWRI--A.mjs → discoverHttpRoutes-DDhmUyVN.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as a}from"ts-morph";import{l,a as m}from"./discover-ast-D33zP-NZ.mjs";import{unwrapHandlerReturn as d}from"./discoverFunctions-
|
|
1
|
+
import{Node as a}from"ts-morph";import{l,a as m}from"./discover-ast-D33zP-NZ.mjs";import{unwrapHandlerReturn as d}from"./discoverFunctions-2ajN70Q9.mjs";import{p as h,a as f}from"./parse-validator-BFTp87yz.mjs";const u=new Set(["delete","get","head","options","patch","post","put"]),g=new Set(["body","params","searchParams"]),E=new Set(["handler","stream"]),v=r=>{const e=r.getArguments()[0];if(e&&a.isStringLiteral(e))return e.getLiteralValue()},x=r=>{const e=r.getArguments()[0];return e&&a.isObjectLiteralExpression(e)?f(e):{}},P=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=v(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 c=i.getName();if(u.has(c))break;if(g.has(c)){const p=x(s);o[c]={...p,...o[c]}}else if(c==="output"&&o.output===void 0){const p=s.getArguments()[0];p&&a.isExpression(p)&&(o.output=h(p))}s=i.getExpression()}const t=P(s);if(t)return o.method=t.method,o.path=t.path,o},A=r=>{const e=r.getArguments()[0];return!e||!(a.isArrowFunction(e)||a.isFunctionExpression(e))?"unknown":d(e)},T=(r,e,o,n)=>{const s=e.getName();if(!E.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:A(r)}:{},...t.output?{output:t.output}:{}}},b=(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 c=T(t,i,s.getName(),e);c&&o.push(c)}return o},F=(r,e)=>{const o=l(e),n=[];for(const s of o){const t=r.getSourceFile(s)??r.addSourceFileAtPath(s),i=m(e,s);n.push(...b(t,i))}return n.sort((s,t)=>`${s.method} ${s.path}`.localeCompare(`${t.method} ${t.path}`)||s.filePath.localeCompare(t.filePath)),n};export{F as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i}from"ts-morph";import{l as f,a as P,t as x}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as p}from"./discoverFunctions-
|
|
1
|
+
import{Node as i}from"ts-morph";import{l as f,a as P,t as x}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as p}from"./discoverFunctions-2ajN70Q9.mjs";const A=e=>{if(!i.isCallExpression(e))return!1;const s=e.getExpression();return i.isIdentifier(s)?s.getText()==="mask":i.isPropertyAccessExpression(s)?s.getName()==="mask":!1},u=e=>{if(i.isPropertyAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e))return e.getName()},k=e=>{const s=e.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return[];const t=[];for(const r of s.getProperties()){const o=u(r);if(o===void 0||!i.isPropertyAssignment(r))continue;const n=r.getInitializer();if(!(!n||!i.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=u(a);c!==void 0&&t.push({column:c,table:o})}}return t},g=e=>{const s=[];let t=e;for(;i.isCallExpression(t);){const r=t.getExpression();if(!i.isPropertyAccessExpression(r))break;if(r.getName()==="use"){const o=t.getArguments()[0];o&&A(o)&&s.push(o)}t=r.getExpression()}return s},E=e=>{const s=g(e);return{maskColumns:s.flatMap(t=>k(t)),usesMask:s.length>0}},M=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),S=new Set(["delete","insert","patch","replace"]),b=(e,s)=>{if(!i.isVariableDeclaration(e))return;const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const r=p(t);if(!r)return;const o=r.receiver?E(r.receiver):{maskColumns:[],usesMask:!1},{tablesRead:n,tablesWritten:a}=x(e,M,S);return{exportName:e.getName(),file:s,maskColumns:o.maskColumns,tablesRead:n,tablesWritten:a,usesMask:o.usesMask,visibility:r.visibility}},w=(e,s)=>{const t=[];for(const r of f(s)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=P(s,r);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations()){const l=b(c,n);l&&t.push(l)}}return t},h=e=>{if(i.isPropertyAssignment(e)){const s=e.getInitializer();if(s&&i.isStringLiteral(s)){const t=s.getLiteralText();if(t==="redact"||t==="hash")return t}}return"custom"},C=e=>{const s=e.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return[];const t=[];for(const r of s.getProperties()){const o=u(r);if(o===void 0||!i.isPropertyAssignment(r))continue;const n=r.getInitializer();if(!(!n||!i.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=u(a);c!==void 0&&t.push({column:c,strategy:h(a),table:o})}}return t},v=e=>{const s=[];for(const t of e.getVariableStatements())if(t.isExported())for(const r of t.getDeclarations()){const o=r.getInitializer(),n=o&&i.isCallExpression(o)?p(o):void 0;n?.receiver&&s.push(n.receiver)}return s},R=(e,s)=>{const t=new Map;for(const r of f(s)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r);for(const n of v(o))for(const a of g(n))for(const c of C(a)){const l=`${c.table}\0${c.column}`;t.has(l)||t.set(l,c)}}return{columns:[...t.values()]}},F=(e,s,t)=>{const r=e.getArguments()[0];if(!r||!i.isObjectLiteralExpression(r))return[];const o=[];for(const n of r.getProperties()){const a=u(n);if(a===void 0||!i.isPropertyAssignment(n))continue;const c=n.getInitializer();if(!(!c||!i.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const m=u(l);if(m===void 0)continue;const d=h(l);d!=="custom"&&o.push({column:m,exportName:s,file:t,line:l.getStartLineNumber(),strategy:d,table:a})}}return o},z=(e,s)=>{if(!i.isVariableDeclaration(e))return[];const t=e.getInitializer(),r=t&&i.isCallExpression(t)?p(t):void 0;return r?.receiver?g(r.receiver).flatMap(o=>F(o,e.getName(),s)):[]},T=(e,s)=>{const t=[];for(const r of f(s)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=P(s,r);for(const a of o.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())t.push(...z(c,n))}return t},D=e=>i.isPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?i.isComputedPropertyName(e.getNameNode()):!1,L=e=>i.isPropertyAssignment(e)||i.isShorthandPropertyAssignment(e)||i.isMethodDeclaration(e)||i.isGetAccessorDeclaration(e)?D(e):!0,y=(e,s=!1)=>{for(const t of e.getProperties()){if(L(t))return!0;if(s)continue;if(!i.isPropertyAssignment(t))return!0;const r=t.getInitializer();if(!r||!i.isObjectLiteralExpression(r)||y(r,!0))return!0}return!1},j=(e,s)=>{for(const t of f(s)){const r=e.getSourceFile(t)??e.addSourceFileAtPath(t);for(const o of v(r))for(const n of g(o)){const a=n.getArguments()[0];if(a!==void 0&&(!i.isObjectLiteralExpression(a)||y(a)))return!0}}return!1};export{w as default,j as discoverMaskHasNonLiteralPolicy,R as discoverMaskMetadata,T as discoverMaskStrategies};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as s,SyntaxKind as a}from"ts-morph";import{l,a as c,h as d}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as f}from"./discoverFunctions-
|
|
1
|
+
import{Node as s,SyntaxKind as a}from"ts-morph";import{l,a as c,h as d}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as f}from"./discoverFunctions-2ajN70Q9.mjs";const u={"crypto.getRandomValues":"crypto.getRandomValues","crypto.randomUUID":"crypto.randomUUID","Date.now":"Date.now","Math.random":"Math.random"},m=new Set(["globalThis","self"]),g=new Set(["globalThis","self","window"]),p=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e)){const t=e.getExpression();if(s.isIdentifier(t)&&g.has(t.getText()))return e.getName()}},h=e=>{const t=e.getExpression();if(s.isIdentifier(t)){const o=t.getText();return o==="fetch"||o==="Date"?o:void 0}if(!s.isPropertyAccessExpression(t))return;const n=t.getName(),i=p(t.getExpression());if(i!==void 0)return n==="fetch"&&m.has(i)?"fetch":u[`${i}.${n}`]},x=e=>{const t=e.getExpression();if(!s.isIdentifier(t)||t.getText()!=="Date")return;const n=e.getArguments(),i=n.every(o=>s.isNumericLiteral(o)||s.isStringLiteral(o)||s.isNoSubstitutionTemplateLiteral(o));return n.length>0&&i?void 0:"new Date"},N=e=>{const t=e.getInitializer();if(!t||!s.isCallExpression(t))return;const n=f(t);if(!n||n.kind!=="query"&&n.kind!=="mutation")return;const i=d(t,n.receiver);return i?{exportName:e.getName(),handler:i,kind:n.kind}:void 0},E=(e,t)=>{const n=[];for(const i of e.handler.getDescendantsOfKind(a.CallExpression)){const o=h(i);o!==void 0&&n.push({callee:o,exportName:e.exportName,file:t,kind:e.kind,line:i.getStartLineNumber()})}for(const i of e.handler.getDescendantsOfKind(a.NewExpression)){const o=x(i);o!==void 0&&n.push({callee:o,exportName:e.exportName,file:t,kind:e.kind,line:i.getStartLineNumber()})}return n},S=(e,t)=>{const n=[];for(const i of e.getVariableStatements())if(i.isExported())for(const o of i.getDeclarations()){const r=N(o);r&&n.push(...E(r,t))}return n},w=(e,t)=>{const n=[];for(const i of l(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...S(o,c(t,i)))}return n};export{w as default};
|
package/dist/packem_shared/{discoverR2sqlCalls-_bVEyLb8.mjs → discoverR2sqlCalls-NtUJIKqo.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as o,SyntaxKind as a}from"ts-morph";import{l as c,a as l,h as d}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as f}from"./discoverFunctions-
|
|
1
|
+
import{Node as o,SyntaxKind as a}from"ts-morph";import{l as c,a as l,h as d}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as f}from"./discoverFunctions-2ajN70Q9.mjs";const u=t=>{const r=t.getInitializer();if(!r||!o.isCallExpression(r))return;const e=f(r);if(!e||e.kind!=="query"&&e.kind!=="mutation")return;const n=d(r,e.receiver);return n?{exportName:t.getName(),handler:n,kind:e.kind}:void 0},p=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"},x=(t,r)=>{const e=[];for(const n of t.handler.getDescendantsOfKind(a.PropertyAccessExpression)){const s=p(n);s!==void 0&&e.push({callee:s,exportName:t.exportName,file:r,kind:t.kind,line:n.getStartLineNumber()})}return e},m=(t,r)=>{const e=[];for(const n of t.getVariableStatements())if(n.isExported())for(const s of n.getDeclarations()){const i=u(s);i&&e.push(...x(i,r))}return e},P=(t,r)=>{const e=[];for(const n of c(r)){const s=t.getSourceFile(n)??t.addSourceFileAtPath(n);e.push(...m(s,l(r,n)))}return e};export{P as default};
|
package/dist/packem_shared/{discoverRlsMetadata-BV_yswEJ.mjs → discoverRlsMetadata-BA9lVt-Q.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as n}from"ts-morph";import{l as d,a as x,t as P,b as l}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as E}from"./discoverFunctions-
|
|
1
|
+
import{Node as n}from"ts-morph";import{l as d,a as x,t as P,b as l}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as E}from"./discoverFunctions-2ajN70Q9.mjs";const b=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},v=t=>{const e=t.getArguments()[0];if(!e||!n.isArrayLiteralExpression(e))return[];const s=[];for(const r of e.getElements()){if(!n.isObjectLiteralExpression(r))continue;const i=r.getProperty("table");if(!i||!n.isPropertyAssignment(i))continue;const o=i.getInitializer();o&&n.isStringLiteral(o)&&s.push(o.getLiteralText())}return s},h=t=>{const e=[];let s=t;for(;n.isCallExpression(s);){const r=s.getExpression();if(!n.isPropertyAccessExpression(r))break;if(r.getName()==="use"){const i=s.getArguments()[0];i&&b(i)&&e.push(i)}s=r.getExpression()}return e},y=t=>{const e=h(t);return{rlsTables:e.flatMap(s=>v(s)),usesRls:e.length>0}},A=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),L=new Set(["delete","deleteMany","insert","insertMany","patch","patchMany","replace"]),S=(t,e)=>{if(!n.isVariableDeclaration(t))return;const s=t.getInitializer();if(!s||!n.isCallExpression(s))return;const r=E(s);if(!r)return;const i=r.receiver?y(r.receiver):{rlsTables:[],usesRls:!1},{tablesRead:o,tablesWritten:a}=P(t,A,L);return{exportName:t.getName(),file:e,rlsTables:i.rlsTables,tablesRead:o,tablesWritten:a,usesRls:i.usesRls,visibility:r.visibility}},w=(t,e)=>{const s=[];for(const r of d(e)){const i=t.getSourceFile(r)??t.addSourceFileAtPath(r),o=x(e,r);for(const a of i.getVariableStatements())if(a.isExported())for(const u of a.getDeclarations()){const c=S(u,o);c&&s.push(c)}}return s},C=new Set(["delete","insert","read","update"]),T=(t,e,s)=>{const r=t.getArguments()[0];if(!r||!n.isArrayLiteralExpression(r))return[];const i=[];for(const o of r.getElements()){if(!n.isObjectLiteralExpression(o))continue;const a=l(o,"on");a===void 0||!C.has(a)||i.push({file:e,on:a,procedure:s,table:l(o,"table")??""})}return i},g=t=>{if(!n.isObjectLiteralExpression(t))return[];const e=t.getProperty("permissions");if(!e||!n.isPropertyAssignment(e))return[];const s=e.getInitializer();if(!s||!n.isArrayLiteralExpression(s))return[];const r=[];for(const i of s.getElements()){if(n.isStringLiteral(i)){r.push(i.getLiteralText());continue}if(n.isCallExpression(i)){const o=i.getArguments()[0];o&&n.isStringLiteral(o)&&r.push(o.getLiteralText())}}return r},m=(t,e)=>e===void 0?t:{...t,description:e},R=t=>{if(n.isCallExpression(t)){const e=t.getArguments()[0];if(!e||!n.isStringLiteral(e))return;const s=t.getArguments()[1],r=s?l(s,"description"):void 0,i=s?g(s):[];return m({name:e.getLiteralText(),permissions:i},r)}if(n.isObjectLiteralExpression(t)){const e=l(t,"name");return e===void 0?void 0:m({name:e,permissions:g(t)},l(t,"description"))}},F=t=>{const e=t.getArguments()[1];if(!e||!n.isObjectLiteralExpression(e))return[];const s=e.getProperty("roles");if(!s||!n.isPropertyAssignment(s))return[];const r=s.getInitializer();if(!r||!n.isArrayLiteralExpression(r))return[];const i=[];for(const o of r.getElements()){const a=R(o);a&&i.push(a)}return i},I=(t,e,s)=>{const r=h(t);return{policies:r.flatMap(i=>T(i,e,s)),roles:r.flatMap(i=>F(i))}},M=t=>{const e=[];for(const s of t.getVariableStatements())if(s.isExported())for(const r of s.getDeclarations()){const i=r.getInitializer(),o=i&&n.isCallExpression(i)?E(i):void 0;o?.receiver&&e.push({name:r.getName(),receiver:o.receiver})}return e},D=(t,e)=>{const s=[],r=new Map;for(const i of d(e)){const o=t.getSourceFile(i)??t.addSourceFileAtPath(i),a=x(e,i);for(const{name:u,receiver:c}of M(o)){const p=I(c,a,u);s.push(...p.policies);for(const f of p.roles)r.has(f.name)||r.set(f.name,f)}}return{policies:s,roles:[...r.values()]}};export{w as default,D as discoverRlsMetadata};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as n}from"ts-morph";import{l as f,a as p,b as u}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as g}from"./discoverFunctions-
|
|
1
|
+
import{Node as n}from"ts-morph";import{l as f,a as p,b as u}from"./discover-ast-D33zP-NZ.mjs";import{classifyProcedureCall as g}from"./discoverFunctions-2ajN70Q9.mjs";const m=new Set(["delete","list","read","write"]),d=o=>{if(!n.isCallExpression(o))return!1;const e=o.getExpression();return n.isIdentifier(e)?e.getText()==="storageRules":n.isPropertyAccessExpression(e)&&e.getName()==="storageRules"},x=o=>{const e=[];let s=o;for(;n.isCallExpression(s);){const t=s.getExpression();if(!n.isPropertyAccessExpression(t))break;if(t.getName()==="use"){const r=s.getArguments()[0];r&&d(r)&&e.push(r)}s=t.getExpression()}return e},h=(o,e,s)=>{const t=o.getArguments()[0];if(!t||!n.isArrayLiteralExpression(t))return[];const r=[];for(const i of t.getElements()){if(!n.isObjectLiteralExpression(i))continue;const a=u(i,"on");if(a===void 0||!m.has(a))continue;const c=u(i,"prefix"),l={bucket:u(i,"bucket")??"",file:e,on:a,procedure:s};c!==void 0&&(l.prefix=c),r.push(l)}return r},E=o=>{const e=[];for(const s of o.getVariableStatements())if(s.isExported())for(const t of s.getDeclarations()){const r=t.getInitializer(),i=r&&n.isCallExpression(r)?g(r):void 0;i?.receiver&&e.push({name:t.getName(),receiver:i.receiver})}return e},R=(o,e)=>{const s=[];for(const t of f(e)){const r=o.getSourceFile(t)??o.addSourceFileAtPath(t),i=p(e,t);for(const{name:a,receiver:c}of E(r))for(const l of x(c))s.push(...h(l,i,a))}return{rules:s}};export{R as default};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{SyntaxKind as u,Node as o}from"ts-morph";import{l as B,a as q}from"./discover-ast-D33zP-NZ.mjs";import{a as K}from"./module-specifiers-WF8iAydP.mjs";import{p as H,a as I}from"./parse-validator-BFTp87yz.mjs";import{s as W}from"./paths-C-9fwEgQ.mjs";const x=new Set(["action","mutation","query","stream"]),C=/\bany\b(?!\s*(?:\?\s*)?:)/u,D=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,G=/^[A-Za-z_$][\w$]*$/u,X=e=>G.test(e)?e:JSON.stringify(e),k={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},J={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init"},Q=K,L=e=>{const t=e.getSymbol();if(!t)return e.getText();const r=t.getDeclarations();for(const i of r){if(!o.isImportSpecifier(i))continue;const s=i.getImportDeclaration().getModuleSpecifierValue();return Q(s)?i.getNameNode().getText():void 0}},O=(e,t=!1)=>{let r=e;for(;o.isCallExpression(r);){const n=r.getExpression();if(!o.isPropertyAccessExpression(n))return;r=n.getExpression()}if(!o.isIdentifier(r))return;const i=L(r);if(i===void 0){if(t)return;const n=r.getSymbol()?.getValueDeclaration();if(n&&o.isVariableDeclaration(n)){const s=n.getInitializer();return s?O(s,!0):void 0}return}return x.has(i)?"public":k[i]?"internal":void 0},b=(e,t)=>{const r=e.getProperty(t);if(r===void 0||!o.isPropertyAssignment(r))return;const i=r.getInitializer();return i!==void 0&&o.isStringLiteral(i)?i.getLiteralValue():void 0},N=(e,t)=>{const r=e.getProperty(t);if(r===void 0||!o.isPropertyAssignment(r))return;const i=r.getInitializer();return i!==void 0&&o.isNumericLiteral(i)?i.getLiteralValue():void 0},Y=e=>{const t=e.getProperty("cache");if(t===void 0||!o.isPropertyAssignment(t))return;const r=t.getInitializer();if(r===void 0||!o.isObjectLiteralExpression(r))return;const i=b(r,"scope"),n=N(r,"maxAge"),s=N(r,"staleWhileRevalidate"),a=b(r,"tag"),c=b(r,"vary"),l={...n===void 0?{}:{maxAge:n},...i==="private"||i==="public"?{scope:i}:{},...s===void 0?{}:{staleWhileRevalidate:s},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},Z=e=>{if(e===void 0||!o.isObjectLiteralExpression(e))return{};const t=Y(e),r=e.getProperty("rest");return r!==void 0&&o.isPropertyAssignment(r)?{...t===void 0?{}:{cache:t},rest:r.getInitializer()?.getText()==="true"}:t===void 0?{}:{cache:t}},ee=e=>{let t=e;for(;o.isCallExpression(t);){const r=t.getExpression();if(!o.isPropertyAccessExpression(r))return;if(r.getName()==="expose")return Z(t.getArguments()[0]);t=r.getExpression()}},te=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return{};const r=t.getProperty("args");if(!r||!o.isPropertyAssignment(r))return{};const i=r.getInitializer();return!i||!o.isObjectLiteralExpression(i)?{}:I(i)},re="/_generated/",ie=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(r=>r?.getDeclarations()??[]);return t.length>0&&t.every(r=>r.getSourceFile().getSymbol()===void 0)},ne=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,w=e=>{for(const t of e.getAncestors())if(o.isModuleDeclaration(t)){const r=ne.exec(t.getName());if(r?.groups?.specifier!==void 0)return r.groups.specifier}},P=new WeakMap,se=(e,t)=>{const r=e.getSymbol();if(r===void 0)return;let i=P.get(r.compilerSymbol);return i===void 0&&(i=new Map,P.set(r.compilerSymbol,i)),i.has(t)||i.set(t,r.getExport(t)??e.getExportSymbols().find(n=>n.getName()===t)),i.get(t)},F=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(r=>r.getName()===t),oe=(e,t,r)=>{const i=e.getModuleSpecifierValue();return i===t&&F(e,r)?{exportName:r,specifier:i}:void 0},ae=(e,t)=>{const r=e.getDefaultImport();if(r===void 0)return;const i=r.getSymbol();return(i?.getAliasedSymbol()??i)?.getDeclarations().includes(t)===!0?{exportName:"default",specifier:e.getModuleSpecifierValue()}:void 0},ce=(e,t,r)=>{if(!F(e,r))return;const i=e.getModuleSpecifierSourceFile(),n=i===void 0?void 0:se(i,r);return(n?.getAliasedSymbol()??n)?.getDeclarations().includes(t)===!0?{exportName:r,specifier:e.getModuleSpecifierValue()}:void 0},le=(e,t,r)=>{const i=w(t);for(const n of e.getImportDeclarations()){const s=i===void 0?ae(n,t)??ce(n,t,r):oe(n,i,r);if(s!==void 0)return s}},ue=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(r=>{const i=r.indexOf("*");return i===-1?e===r:e.startsWith(r.slice(0,i))&&e.endsWith(r.slice(i+1))}),g={kind:"verbatim"},m={kind:"expand"},ge=new Set([u.ClassDeclaration,u.EnumDeclaration,u.EnumMember,u.InterfaceDeclaration,u.TypeAliasDeclaration]),M=(e,t,r)=>{const i=e.getSourceFile();if(i.getSymbol()===void 0&&w(e)===void 0||!ge.has(e.getKind()))return g;const n=i.getFilePath();if(n.includes(re))return g;if(n===r)return m;const s=o.isEnumMember(e)?e.getParent():e;if(!o.hasName(s))return m;const a=le(t.getSourceFile(),s,s.getName());return a===void 0?g:ue(a.specifier,t)?m:{kind:"qualify",qualified:a}},R=(e,t,r)=>{const i=e.getAliasSymbol(),n=e.getSymbol(),s=new Set((i??n)?.getDeclarations());let a=!1;for(const c of[n,i].flatMap(l=>l?.getDeclarations()??[])){const l=M(c,t,r);if(l.kind==="qualify"&&s.has(c))return l;a||=l.kind!=="verbatim"}return a?m:g},fe=(e,t,r)=>{const i=o.isPropertySignature(e)||o.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(i===void 0)return g;let n=!1;for(const s of[i,...i.getDescendantsOfKind(u.TypeReference)].filter(a=>o.isTypeReference(a))){const a=s.getTypeName().getSymbol();for(const c of(a?.getAliasedSymbol()??a)?.getDeclarations()??[]){const l=M(c,t,r);if(l.kind==="qualify")return l;n||=l.kind!=="verbatim"}}return n?m:g},_=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,v=(e,t,r,i=new Set)=>i.has(e)?!1:(i.add(e),R(e,t,r).kind!=="verbatim"||_(e).some(n=>v(n,t,r,i))?!0:S(e)?e.getProperties().some(n=>n.getDeclarations().some(s=>fe(s,t,r).kind!=="verbatim")?!0:v(n.getTypeAtLocation(t),t,r,i)):!1),pe=(e,t)=>{const r=e.getValueDeclaration()??e.getDeclarations()[0];return r&&(o.isPropertySignature(r)||o.isPropertyDeclaration(r))&&r.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(i=>i.isUndefined())},z=8,de=(e,t,r,i,n,s)=>{const a=e.getArrayElementType(),c=a?s(a,t,r,i,n):void 0;if(c!==void 0)return a?.isUnion()?`(${c})[]`:`${c}[]`},me=(e,t,r,i,n,s)=>{const a=[];for(const c of e.getUnionTypes()){const l=s(c,t,r,i,n);if(l===void 0)return;a.push(l)}return a.join(" | ")},ve=(e,t,r,i,n,s)=>{if(!S(e))return;const a=[];for(const c of e.getProperties()){const l=c.getTypeAtLocation(t),d=pe(c,l),V=d&&l.isUnion()?l.getUnionTypes().filter(E=>!E.isUndefined()):[l],A=[];for(const E of V){const T=s(E,t,r,i+1,n);if(T===void 0)return;A.push(T)}a.push(`${X(c.getName())}${d?"?":""}: ${A.join(" | ")}`)}return a.length>0?`{ ${a.join("; ")} }`:"{}"},ye=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},Ee=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>o.isClassDeclaration(t)||o.isClassExpression(t)),y=(e,t,r,i)=>{if(r>z||i.has(e))return!1;const n=new Set(i).add(e);if(_(e).some(c=>y(c,t,r+1,n)))return!0;const s=e.getArrayElementType();return s!==void 0?y(s,t,r+1,n):ie(e)?!1:e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(c=>c?.getDeclarations()??[]).some(c=>o.isClassDeclaration(c)||o.isClassExpression(c))?!0:S(e)&&e.getProperties().some(c=>y(c.getTypeAtLocation(t),t,r+1,n))},be=(e,t,r,i,n,s,a)=>{const c=[];for(const l of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const d=a(l,r,i,n+1,s);if(d===void 0)return;c.push(d)}return`import("${e.specifier}").${e.exportName}${c.length>0?`<${c.join(", ")}>`:""}`},xe=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>o.isEnumDeclaration(t)||o.isEnumMember(t)),f=(e,t,r,i,n)=>{if(i>z||n.has(e))return;const s=R(e,t,r);if(s.kind==="verbatim"&&!v(e,t,r))return e.getText(t);const a=new Set(n).add(e);if(!Ee(e)){if(e.isEnumLiteral())return ye(e);if(s.kind==="qualify"&&!xe(e)){const c=be(s.qualified,e,t,r,i,a,f);if(c!==void 0)return c}return e.isArray()?de(e,t,r,i,a,f):e.isUnion()?me(e,t,r,i,a,f):ve(e,t,r,i,a,f)}},U=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let r=t.getReturnType();const n=(r.getSymbol()??r.getAliasSymbol())?.getName();if(n==="Promise"||n==="AsyncIterable"||n==="AsyncIterableIterator"||n==="AsyncGenerator"){const c=r.getTypeArguments()[0];c&&(r=c)}const s=r.getText(e);if(!s||s==="any"||s==="never"||C.test(s.replaceAll(D,""))||y(r,e,0,new Set))return"unknown";const a=e.getSourceFile().getFilePath();return v(r,e,a)?f(r,e,a,0,new Set)??"unknown":s},ze=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const r=t.getTypeAtLocation(e).getProperty("types");if(!r)return;const i=r.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!i)return;const n=i.getTypeAtLocation(e),s=n.getText(e);if(!s||s==="any"||s==="never"||C.test(s.replaceAll(D,"")))return;const a=e.getSourceFile().getFilePath();return v(n,e,a)?f(n,e,a,0,new Set):s},Se=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return"unknown";const r=t.getProperty("handler");if(!r||!o.isPropertyAssignment(r))return"unknown";const i=r.getInitializer();return!i||!(o.isArrowFunction(i)||o.isFunctionExpression(i))?"unknown":U(i)},Ae=e=>{const t=e.getArguments()[0];return!t||!(o.isArrowFunction(t)||o.isFunctionExpression(t))?"unknown":U(t)},Te=e=>{let t={},r=e;for(;o.isCallExpression(r);){const i=r.getExpression();if(!o.isPropertyAccessExpression(i))break;if(i.getName()==="input"){const n=r.getArguments()[0];n&&o.isObjectLiteralExpression(n)&&(t={...I(n),...t})}r=i.getExpression()}return t},Ne=e=>{let t=e;for(;o.isCallExpression(t);){const r=t.getExpression();if(!o.isPropertyAccessExpression(r))return;if(r.getName()==="output"){const i=t.getArguments()[0];return i&&o.isExpression(i)?H(i):void 0}t=r.getExpression()}},Pe=e=>{const t=e.getExpression();if(o.isPropertyAccessExpression(t)){const s=t.getName();if(!x.has(s))return;const a=t.getExpression();if(a.getType().getProperty("__lunoraProcedure"))return{kind:s,receiver:a,visibility:a.getType().getProperty("__lunoraVisibility")?"internal":"public"};const c=O(a);return c?{kind:s,receiver:a,visibility:c}:void 0}if(!o.isIdentifier(t))return;const r=L(t);if(!r)return;if(x.has(r))return{kind:r,visibility:"public"};const i=k[r];if(i)return{kind:i,visibility:"internal"};const n=J[r];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}},h=e=>e!==void 0&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,Ue=e=>o.isPropertyAccessExpression(e)&&e.getName()==="db"||o.isIdentifier(e)&&e.getText()==="db",$e=e=>{const t=e.getArguments()[0],r=h(t);if(r!==void 0)return r;if(t===void 0||!o.isObjectLiteralExpression(t))return;const i=t.getProperty("handler");return i!==void 0&&o.isPropertyAssignment(i)?h(i.getInitializer()):void 0},he=e=>o.isIdentifier(e)?e.getText():o.isPropertyAccessExpression(e)?e.getName():"",je=(e,t)=>{let r=e;for(;o.isCallExpression(r);){const i=r.getExpression();if(!o.isPropertyAccessExpression(i))break;if(i.getName()===t)return!0;r=i.getExpression()}return!1},Ve=(e,t,r)=>{let i=e;for(;o.isCallExpression(i);){const n=i.getExpression();if(!o.isPropertyAccessExpression(n))break;const s=i.getArguments()[0];if(n.getName()===t&&s!==void 0&&o.isCallExpression(s)&&he(s.getExpression())===r)return!0;i=n.getExpression()}return!1},Ie=e=>{const t=Pe(e);if(t){if(t.receiver){const r=ee(t.receiver),i=Ne(t.receiver);return{args:Te(t.receiver),...r?{expose:r}:{},kind:t.kind,...i?{output:i}:{},returnType:Ae(e),visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:te(e),kind:t.kind,returnType:Se(e),visibility:t.visibility}}},Ce=8,p=(e,t=0)=>{if(t>Ce)return;if(o.isCallExpression(e))return e;if(o.isParenthesizedExpression(e)||o.isAsExpression(e)||o.isSatisfiesExpression(e)||o.isNonNullExpression(e))return p(e.getExpression(),t+1);if(!o.isIdentifier(e)&&!o.isPropertyAccessExpression(e))return;const r=e.getSymbol()?.getValueDeclaration();return r?$(r,t+1):void 0},$=(e,t)=>{if(o.isVariableDeclaration(e)||o.isPropertyAssignment(e)){const r=e.getInitializer();return r?p(r,t):void 0}if(o.isShorthandPropertyAssignment(e))return p(e.getNameNode(),t);if(o.isBindingElement(e)){const r=e.getPropertyNameNode()?.getText()??e.getName(),s=e.getFirstAncestorByKind(u.VariableDeclaration)?.getInitializer()?.getType().getProperty(r)?.getValueDeclaration();return s?$(s,t+1):void 0}},De=e=>{const t=e.getNameNode();if(o.isObjectBindingPattern(t)){const n=[];for(const s of t.getElements()){const a=p(s.getNameNode());a&&n.push([s.getName(),a])}return n}const r=e.getInitializer(),i=r&&(o.isCallExpression(r)?r:p(r));return i?[[e.getName(),i]]:[]},j=(e,t,r)=>{const i=Ie(e);if(i)return{args:i.args,exportName:t,filePath:r,kind:i.kind,returnType:i.returnType,...i.output?{output:i.output}:{},visibility:i.visibility,...i.expose?{expose:i.expose}:{},...i.lifecycle?{lifecycle:i.lifecycle}:{}}},ke=(e,t)=>{const r=[];for(const i of e.getExportAssignments()){if(i.isExportEquals())continue;const n=p(i.getExpression()),s=n?j(n,"default",t):void 0;s&&r.push(s)}return r},Le=(e,t)=>{const r=[];for(const i of e.getVariableStatements())if(i.isExported())for(const n of i.getDeclarations())for(const[s,a]of De(n)){const c=j(a,s,t);c&&r.push(c)}return r.push(...ke(e,t)),r},Oe=e=>{const t=new Map;for(const r of e){const i=W(r.filePath),n=t.get(i);if(n&&n!==r.filePath)throw Object.assign(new Error(`Namespace collision: "${n}" and "${r.filePath}" both resolve to "${i}". 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,r.filePath],status:500});t.set(i,r.filePath)}},Be=(e,t)=>{const r=B(t),i=[];for(const n of r){const s=e.getSourceFile(n)??e.addSourceFileAtPath(n),a=q(t,n);i.push(...Le(s,a))}return i.sort((n,s)=>`${n.filePath}:${n.exportName}`.localeCompare(`${s.filePath}:${s.exportName}`)),Oe(i),i};export{je as chainHasStep,Ve as chainUsesWrappedCall,Pe as classifyProcedureCall,Be as discoverFunctions,h as inlineHandler,Ue as isDatabaseAccessor,B as listLunoraSourceFiles,q as lunoraRelativePath,$e as procedureHandler,ze as resolveStandardSchemaType,U as unwrapHandlerReturn};
|