@lunora/codegen 1.0.0-alpha.424 → 1.0.0-alpha.425
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/{AGENTS_FILENAME-C-QzrY0q.mjs → AGENTS_FILENAME-BSW65Q9R.mjs} +1 -1
- package/dist/packem_shared/{ALL_NOTIFY_CHANNELS-DE_qq1fJ.mjs → ALL_NOTIFY_CHANNELS-DI0zmZGs.mjs} +1 -1
- package/dist/packem_shared/{CONTAINERS_FILENAME-7_HMXUYy.mjs → CONTAINERS_FILENAME-Dy3qWGfI.mjs} +1 -1
- package/dist/packem_shared/{ENV_FILENAME-DmUUtjIW.mjs → ENV_FILENAME-DFx_jlpa.mjs} +1 -1
- package/dist/packem_shared/{MUTATORS_FILENAME-DdW3wZa_.mjs → MUTATORS_FILENAME-SLAN2VXq.mjs} +1 -1
- package/dist/packem_shared/{QUEUES_FILENAME-BovqRXD2.mjs → QUEUES_FILENAME-CVkpGqoY.mjs} +1 -1
- package/dist/packem_shared/{SCHEMA_SNAPSHOT_FILENAME-m_oKXr4Q.mjs → SCHEMA_SNAPSHOT_FILENAME-DamKv-D7.mjs} +1 -1
- package/dist/packem_shared/{SHAPES_FILENAME-Bd57JHv9.mjs → SHAPES_FILENAME-Cf4sum4C.mjs} +1 -1
- package/dist/packem_shared/{WORKFLOWS_FILENAME-DXusn4DF.mjs → WORKFLOWS_FILENAME-Dtxo_XBw.mjs} +1 -1
- package/dist/packem_shared/attribution-B8xa6AeK.mjs +1 -0
- package/dist/packem_shared/{context-property-calls-CxYu8Rfs.mjs → context-property-calls-As5I0QR6.mjs} +1 -1
- package/dist/packem_shared/{context-root-DbKRPl4u.mjs → context-root-CO8PbZi5.mjs} +1 -1
- package/dist/packem_shared/{database-calls-DtZbfTbe.mjs → database-calls-Cug60vT9.mjs} +1 -1
- package/dist/packem_shared/{discoverAuthApiCalls-BFou6Thm.mjs → discoverAuthApiCalls-DcvsgL5u.mjs} +1 -1
- package/dist/packem_shared/discoverFunctions-CGwHnz_a.mjs +1 -0
- package/dist/packem_shared/{discoverHttpRoutes-zVW8BZNx.mjs → discoverHttpRoutes-BtMgsfzG.mjs} +1 -1
- package/dist/packem_shared/discoverHyperdriveCalls-B--Nvx36.mjs +1 -0
- package/dist/packem_shared/{discoverInserts-D4fHoFon.mjs → discoverInserts-Dx7Lxey3.mjs} +1 -1
- package/dist/packem_shared/discoverMaskProcedures-Dj_hkZz2.mjs +1 -0
- package/dist/packem_shared/{discoverMigrations-D6OuJs3t.mjs → discoverMigrations-DaBdK1Bv.mjs} +1 -1
- package/dist/packem_shared/{discoverNondeterministicCalls-D7wKI8GM.mjs → discoverNondeterministicCalls-MeKjo_UX.mjs} +1 -1
- package/dist/packem_shared/{discoverQueries-DXVXWVrp.mjs → discoverQueries-BlhMsXuk.mjs} +1 -1
- package/dist/packem_shared/discoverR2sqlCalls-DHvclvkv.mjs +1 -0
- package/dist/packem_shared/{discoverRlsMetadata-CFOKezvx.mjs → discoverRlsMetadata-CO-pRHOx.mjs} +1 -1
- package/dist/packem_shared/{discoverRlsProcedures-Dz6GjF-3.mjs → discoverRlsProcedures-CUfhUqfY.mjs} +1 -1
- package/dist/packem_shared/{discoverStorageRulesMetadata-BWfevd6T.mjs → discoverStorageRulesMetadata-D_pYyr1i.mjs} +1 -1
- package/dist/packem_shared/{exported-procedure-chains-CAkR82w2.mjs → exported-procedure-chains-ej9ozyZB.mjs} +1 -1
- package/dist/packem_shared/{handler-reference-T5OJcVXW.mjs → handler-reference-_zhtPddp.mjs} +1 -1
- package/dist/packem_shared/{index-pzfYD4Dg.mjs → index-BwLaIVqA.mjs} +1 -1
- package/dist/packem_shared/{index-CmF_PUd_.mjs → index-CQuAXbal.mjs} +1 -1
- package/dist/packem_shared/ip-reads-D8rPYtZ6.mjs +1 -0
- package/package.json +1 -1
- package/dist/packem_shared/attribution-CbD9hCjb.mjs +0 -1
- package/dist/packem_shared/discoverFunctions-BkY2frX0.mjs +0 -1
- package/dist/packem_shared/discoverHyperdriveCalls-TfL8wEi8.mjs +0 -1
- package/dist/packem_shared/discoverMaskProcedures-BQWCpO-4.mjs +0 -1
- package/dist/packem_shared/discoverR2sqlCalls-CK-UpwgM.mjs +0 -1
- package/dist/packem_shared/ip-reads-Du9jIYHJ.mjs +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as i,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs";import{formatAdvisories as d,lintSchema as f,toAdvisorContext as m}from"./packem_shared/formatAdvisories-Bue5tbp6.mjs";import{describeErrorLevelFindings as n,errorAdvisoryNames as c,errorPlatformDiagnosticNames as l,sortedUniqueNames as S}from"./packem_shared/describeErrorLevelFindings-DlkgCw8a.mjs";import{CAPABILITY_PROBES as E}from"./packem_shared/CAPABILITY_PROBES-DCzOjTN7.mjs";import{COMPANION_BINDING as u,COMPANION_SERVICE_NAME as N}from"./packem_shared/COMPANION_BINDING-Da_v9XpC.mjs";import{CodegenDiagnosticError as g,diagnosticAt as C}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as I,discoverAgents as _}from"./packem_shared/AGENTS_FILENAME-
|
|
1
|
+
import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as i,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs";import{formatAdvisories as d,lintSchema as f,toAdvisorContext as m}from"./packem_shared/formatAdvisories-Bue5tbp6.mjs";import{describeErrorLevelFindings as n,errorAdvisoryNames as c,errorPlatformDiagnosticNames as l,sortedUniqueNames as S}from"./packem_shared/describeErrorLevelFindings-DlkgCw8a.mjs";import{CAPABILITY_PROBES as E}from"./packem_shared/CAPABILITY_PROBES-DCzOjTN7.mjs";import{COMPANION_BINDING as u,COMPANION_SERVICE_NAME as N}from"./packem_shared/COMPANION_BINDING-Da_v9XpC.mjs";import{CodegenDiagnosticError as g,diagnosticAt as C}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as I,discoverAgents as _}from"./packem_shared/AGENTS_FILENAME-BSW65Q9R.mjs";import{isTestPath as L,listLunoraSourceFiles as M}from"./packem_shared/isTestPath-DJeZ18i9.mjs";import{default as F}from"./packem_shared/discoverAuthApiCalls-DcvsgL5u.mjs";import{CONTAINERS_FILENAME as P,discoverContainers as D}from"./packem_shared/CONTAINERS_FILENAME-Dy3qWGfI.mjs";import{default as b}from"./packem_shared/discoverCrons-MpIC14pg.mjs";import{ENV_FILENAME as U}from"./packem_shared/ENV_FILENAME-DFx_jlpa.mjs";import{capabilitiesUsedBy as H,createTargetScope as j,foldCapabilitySignals as V,mayReadCapabilityContext as k,sourceCapabilitySignals as W}from"./packem_shared/capabilitiesUsedBy-BcDkRoOu.mjs";import{FLAGS_FILENAME as K,discoverFlags as Q}from"./packem_shared/FLAGS_FILENAME-CDaIBL6L.mjs";import{d as q}from"./packem_shared/index-BwLaIVqA.mjs";import{default as J}from"./packem_shared/discoverHttpRoutes-BtMgsfzG.mjs";import{default as Z}from"./packem_shared/discoverHyperdriveCalls-B--Nvx36.mjs";import{default as ee}from"./packem_shared/discoverInserts-Dx7Lxey3.mjs";import{d as oe}from"./packem_shared/index-CQuAXbal.mjs";import{default as ie}from"./packem_shared/discoverMigrations-DaBdK1Bv.mjs";import{MUTATORS_FILENAME as se,discoverMutators as de}from"./packem_shared/MUTATORS_FILENAME-SLAN2VXq.mjs";import{default as me}from"./packem_shared/discoverNondeterministicCalls-MeKjo_UX.mjs";import{ALL_NOTIFY_CHANNELS as ne,NOTIFY_FILENAME as ce,discoverNotifyCalls as le,discoverNotifyChannels as Se,discoverNotifyConfig as xe}from"./packem_shared/ALL_NOTIFY_CHANNELS-DI0zmZGs.mjs";import{default as Ae}from"./packem_shared/readPackageDependencies-RHhGiz0k.mjs";import{default as Ne}from"./packem_shared/discoverQueries-BlhMsXuk.mjs";import{QUEUES_FILENAME as ge,discoverQueues as Ce}from"./packem_shared/QUEUES_FILENAME-CVkpGqoY.mjs";import{default as Ie}from"./packem_shared/discoverR2sqlCalls-DHvclvkv.mjs";import{default as Re}from"./packem_shared/discoverRlsProcedures-CUfhUqfY.mjs";import{default as Me}from"./packem_shared/discoverRlsMetadata-CO-pRHOx.mjs";import{discoverSandboxUsage as Fe}from"./packem_shared/discoverSandboxUsage-CdrJNRFd.mjs";import{default as Pe}from"./packem_shared/discoverSchema-CL9PLdOu.mjs";import{companionServiceBinding as ye,readBoundServiceBindings as be,readDevServiceBindings as Ge,readServiceBindings as Ue,resolveServiceBindings as Be}from"./packem_shared/companionServiceBinding-BZjm486n.mjs";import{SHAPES_FILENAME as je,discoverShapes as Ve}from"./packem_shared/SHAPES_FILENAME-Cf4sum4C.mjs";import{default as We}from"./packem_shared/discoverStorageRulesMetadata-D_pYyr1i.mjs";import{WORKFLOWS_FILENAME as Ke,discoverWorkflows as Qe}from"./packem_shared/WORKFLOWS_FILENAME-Dtxo_XBw.mjs";import{emitApp as qe}from"./packem_shared/emitApp-LFKtDRYu.mjs";import{isD1GlobalTable as Je,isHyperdriveGlobalTable as Xe}from"./packem_shared/isD1GlobalTable-udvHAAzD.mjs";import{buildOpenApiDocument as $e,emitOpenApi as er,emitOpenApiModule as rr}from"./packem_shared/buildOpenApiDocument-C3zlve6K.mjs";import{OPENRPC_VERSION as tr,buildOpenRpcDocument as ir,emitOpenRpc as ar,emitOpenRpcModule as sr}from"./packem_shared/OPENRPC_VERSION-DkWde9eh.mjs";import{DEFAULT_TARGET as fr,platformMatrixIds as mr,readProjectTarget as pr,resolveCodegenTarget as nr}from"./packem_shared/DEFAULT_TARGET-5-_edM-R.mjs";import{b as lr,r as Sr,c as xr,d as Er}from"./packem_shared/project-config-file-DR7xrrNB.mjs";import{PROJECT_CONFIG_FILENAMES as ur,findCodegenConfigFile as Nr,findProjectConfigFile as vr,projectConfigCandidatePaths as gr}from"./packem_shared/PROJECT_CONFIG_FILENAMES-CLfsyvjA.mjs";import{SCHEMA_SNAPSHOT_FILENAME as Or,runCodegen as Ir}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-DamKv-D7.mjs";import{SchemaSnapshotParseError as Rr,buildSchemaSnapshot as Lr,evaluateSchemaDrift as Mr,indexReferencesOf as Tr,parseSchemaSnapshot as Fr}from"./packem_shared/SchemaSnapshotParseError-CV7mmuPi.mjs";import{default as Pr}from"./packem_shared/fingerprintSchemaSources-BqPD3mw0.mjs";import{schemaFromIr as yr}from"./packem_shared/schemaFromIr-CByOxuZb.mjs";import{LUNORA_ERROR_CODES as Gr,validatorIrToJsonSchema as Ur}from"./packem_shared/LUNORA_ERROR_CODES-D7AVT7qF.mjs";import{SDK_LANGUAGES as Hr,SDK_TARGETS as jr,generateSdk as Vr}from"./sdk/index.mjs";import{redact as Wr,secretKindOf as zr}from"./packem_shared/redact-Cy14LEnc.mjs";import{default as Qr}from"./packem_shared/emitDrizzleSchema-BzOChEYW.mjs";import{e as qr}from"./packem_shared/server-Dfxmm5Zw.mjs";import{e as Jr}from"./packem_shared/shard-CWAD5mYy.mjs";import{G as Zr}from"./packem_shared/shared-Cn7dMQ_u.mjs";import{MESSAGE_SOLUTIONS as eo,findSolutionByMessage as ro}from"@lunora/errors";import{createCodegenProject as to,findTsconfig as io,refreshCodegenProject as ao,tsconfigFingerprint as so}from"./packem_shared/createCodegenProject-C4XuJSap.mjs";import{t as mo,u as po,v as no}from"./packem_shared/shard-runtime-G5mZQjY0.mjs";import{emitApi as lo,emitCollections as So,emitInternalApi as xo}from"./packem_shared/emitApi-lwadq5G7.mjs";import{emitCrons as Ao,emitScheduler as uo,emitVectors as No,emitWranglerCronTriggers as vo}from"./packem_shared/emitCrons-CCRKs482.mjs";import{emitDataModel as Co}from"./packem_shared/emitDataModel-BvCZS4Yq.mjs";import{emitFunctions as Io}from"./packem_shared/emitFunctions-ppMX7E3X.mjs";import{isTypedSchema as Ro}from"./packem_shared/isTypedSchema-CDv3pJB6.mjs";const e="0.0.0";export{I as AGENTS_FILENAME,ne as ALL_NOTIFY_CHANNELS,E as CAPABILITY_PROBES,u as COMPANION_BINDING,N as COMPANION_SERVICE_NAME,P as CONTAINERS_FILENAME,g as CodegenDiagnosticError,fr as DEFAULT_TARGET,U as ENV_FILENAME,K as FLAGS_FILENAME,Zr as GENERATED_HEADER,Gr as LUNORA_ERROR_CODES,eo as LUNORA_SOLUTION_RULES,se as MUTATORS_FILENAME,ce as NOTIFY_FILENAME,tr as OPENRPC_VERSION,ur as PROJECT_CONFIG_FILENAMES,ge as QUEUES_FILENAME,Or as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,Hr as SDK_LANGUAGES,jr as SDK_TARGETS,je as SHAPES_FILENAME,Rr as SchemaSnapshotParseError,e as VERSION,Ke as WORKFLOWS_FILENAME,$e as buildOpenApiDocument,ir as buildOpenRpcDocument,Lr as buildSchemaSnapshot,H as capabilitiesUsedBy,ye as companionServiceBinding,to as createCodegenProject,j as createTargetScope,n as describeErrorLevelFindings,C as diagnosticAt,i as diffSchemaSnapshots,_ as discoverAgents,F as discoverAuthApiCalls,D as discoverContainers,b as discoverCrons,Q as discoverFlags,q as discoverFunctions,J as discoverHttpRoutes,Z as discoverHyperdriveCalls,ee as discoverInserts,oe as discoverMaskProcedures,ie as discoverMigrations,de as discoverMutators,me as discoverNondeterministicCalls,le as discoverNotifyCalls,Se as discoverNotifyChannels,xe as discoverNotifyConfig,Ne as discoverQueries,Ce as discoverQueues,Ie as discoverR2sqlCalls,Me as discoverRlsMetadata,Re as discoverRlsProcedures,Fe as discoverSandboxUsage,Pe as discoverSchema,Ve as discoverShapes,We as discoverStorageRulesMetadata,Qe as discoverWorkflows,mo as emitAgents,lo as emitApi,qe as emitApp,So as emitCollections,po as emitContainers,Ao as emitCrons,Co as emitDataModel,Qr as emitDrizzleSchema,Io as emitFunctions,xo as emitInternalApi,er as emitOpenApi,rr as emitOpenApiModule,ar as emitOpenRpc,sr as emitOpenRpcModule,uo as emitScheduler,qr as emitServer,Jr as emitShard,No as emitVectors,no as emitWorkflows,vo as emitWranglerCronTriggers,c as errorAdvisoryNames,l as errorPlatformDiagnosticNames,Mr as evaluateSchemaDrift,Nr as findCodegenConfigFile,ro as findLunoraSolution,vr as findProjectConfigFile,io as findTsconfig,Pr as fingerprintSchemaSources,V as foldCapabilitySignals,d as formatAdvisories,Vr as generateSdk,Tr as indexReferencesOf,Je as isD1GlobalTable,Xe as isHyperdriveGlobalTable,L as isTestPath,Ro as isTypedSchema,f as lintSchema,M as listLunoraSourceFiles,lr as loadProjectConfig,k as mayReadCapabilityContext,Fr as parseSchemaSnapshot,mr as platformMatrixIds,gr as projectConfigCandidatePaths,be as readBoundServiceBindings,Ge as readDevServiceBindings,Ae as readPackageDependencies,Sr as readProjectConfigLiterals,xr as readProjectLazyFunctions,Er as readProjectSecurityHeaders,pr as readProjectTarget,Ue as readServiceBindings,Wr as redact,ao as refreshCodegenProject,nr as resolveCodegenTarget,Be as resolveServiceBindings,Ir as runCodegen,yr as schemaFromIr,zr as secretKindOf,a as serializeSchemaSnapshot,S as sortedUniqueNames,W as sourceCapabilitySignals,m as toAdvisorContext,so as tsconfigFingerprint,Ur as validatorIrToJsonSchema};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as p}from"node:fs";import{join as f}from"node:path";import{agentDefaultName as d,agentClassName as b,voiceBindingName as N,voiceClassName as y}from"@lunora/agent/naming";import{LunoraError as g}from"@lunora/errors";import{Node as a,SyntaxKind as u}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapToCallExpression as A,findObjectProperty as c,stringPropertyFor as E}from"./isTestPath-DJeZ18i9.mjs";import{a as w}from"./attribution-
|
|
1
|
+
import{existsSync as p}from"node:fs";import{join as f}from"node:path";import{agentDefaultName as d,agentClassName as b,voiceBindingName as N,voiceClassName as y}from"@lunora/agent/naming";import{LunoraError as g}from"@lunora/errors";import{Node as a,SyntaxKind as u}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapToCallExpression as A,findObjectProperty as c,stringPropertyFor as E}from"./isTestPath-DJeZ18i9.mjs";import{a as w}from"./attribution-B8xa6AeK.mjs";const h=new Set(["@lunora/agent","@lunora/agent/core"]),v="agents.ts",P=o=>{const n=o.getSymbol();if(!n)return o.getText()==="defineAgent";for(const e of n.getDeclarations())if(a.isImportSpecifier(e))return h.has(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineAgent":!1;return!1},S=E("agent"),D=(o,n,e)=>{if(o.getKind()===u.TrueKeyword)return!0;if(o.getKind()===u.FalseKeyword)return!1;throw l(o,`agent "${n}": \`${e}\` must be a static boolean literal — it is deploy configuration codegen writes into the ctx.agents wiring spec`)},I=(o,n)=>{const e=o.getArguments()[0];if(!e||!a.isObjectLiteralExpression(e))throw l(o,`agent "${n}": defineAgent must be passed an inline object literal`);const t={className:b(n),exportName:n,name:d(n)},r=c(e,"name");r&&a.isPropertyAssignment(r)&&(t.name=S(r.getInitializerOrThrow(),n,"name"));const i=c(e,"publicRun");i&&a.isPropertyAssignment(i)&&D(i.getInitializerOrThrow(),n,"publicRun")&&(t.publicRun=!0);const s=c(e,"voice");if(s&&a.isPropertyAssignment(s)){const m=s.getInitializerOrThrow();if(!a.isObjectLiteralExpression(m))throw l(m,`agent "${n}": \`voice\` must be an inline object literal — its presence tells codegen to emit the voice-session Durable Object`);t.voice=!0,t.voiceBindingName=N(n),t.voiceClassName=y(n)}return c(e,"onEmail")&&(t.onEmail=!0),t},T=o=>{const n=[];for(const e of o.getVariableDeclarations()){const t=A(e.getInitializer());if(!t)continue;const r=t.getExpression();if(!a.isIdentifier(r)||!P(r))continue;const i=e.getNameNode();if(!a.isIdentifier(i)){if(e.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw l(i,"defineAgent exports must be plain named exports (no destructuring)")}const s=w(e,"binding");s!==void 0&&n.push(I(t,s))}return n},x=o=>{const n=new Map,e=new Map;for(const t of o){const r=n.get(t.name);if(r!==void 0)throw new g("DUPLICATE_AGENT_NAME",`Duplicate agent name "${t.name}": produced by both "${r}" and "${t.exportName}". Deployed agent names must be unique across the project.`,{status:500});n.set(t.name,t.exportName);const i=e.get(t.className);if(i!==void 0)throw new g("DUPLICATE_AGENT_CLASS",`Duplicate agent class "${t.className}": produced by both "${i}" and "${t.exportName}". Agent export names must yield unique generated class names.`,{status:500});e.set(t.className,t.exportName)}},M=(o,n)=>{const e=f(n,v);if(!p(e))return[];const t=o.getSourceFile(e)??o.addSourceFileAtPath(e),r=T(t);return r.sort((i,s)=>i.exportName.localeCompare(s.exportName)),x(r),r};export{v as AGENTS_FILENAME,M as discoverAgents};
|
package/dist/packem_shared/{ALL_NOTIFY_CHANNELS-DE_qq1fJ.mjs → ALL_NOTIFY_CHANNELS-DI0zmZGs.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as I}from"node:fs";import{join as D}from"node:path";import{SyntaxKind as l,Node as r,VariableDeclarationKind as L}from"ts-morph";import{listLunoraSourceFiles as E,lunoraRelativePath as C,descendantsOfKind as v,findObjectProperty as d,defaultExportExpression as k,propertyInitializer as m,handlerOf as w,unwrapExpression as u}from"./isTestPath-DJeZ18i9.mjs";import{j as M,h as _}from"./attribution-
|
|
1
|
+
import{existsSync as I}from"node:fs";import{join as D}from"node:path";import{SyntaxKind as l,Node as r,VariableDeclarationKind as L}from"ts-morph";import{listLunoraSourceFiles as E,lunoraRelativePath as C,descendantsOfKind as v,findObjectProperty as d,defaultExportExpression as k,propertyInitializer as m,handlerOf as w,unwrapExpression as u}from"./isTestPath-DJeZ18i9.mjs";import{j as M,h as _}from"./attribution-B8xa6AeK.mjs";import{e as p}from"./context-root-CO8PbZi5.mjs";import{c as j}from"./classify-procedure-call-BK_MMoue.mjs";import{s as R}from"./property-name-7cBlgK_O.mjs";const z="notify.ts",W=new Set(["chat","inApp","send","webhook"]),S=new Set(["broadcast","send","sendToCondition","sendToTopic"]),H=e=>{const s=e.getInitializer();if(!s||!r.isCallExpression(s))return;const t=j(s);if(!t)return;const i=w(s,t.receiver);return i?{exportName:_(e)??e.getName(),handler:i,kind:t.kind}:void 0},P=e=>{const s=[];for(const t of M(e)){const i=H(t);i&&s.push(i)}return s},b=e=>p(e,["notify"])?"notify":p(e,["push"])||p(e,["notify","push"])?"push":void 0,U=e=>{if(!r.isPropertyAccessExpression(e))return;const s=e.getName(),t=b(e.getExpression());if(t==="notify"&&W.has(s))return`ctx.notify.${s}`;if(t==="push"&&S.has(s))return`ctx.push.${s}`},V=e=>r.isPropertyAccessExpression(e)?b(e.getExpression())==="push"&&S.has(e.getName()):!1,de=(e,s)=>{const t=[];for(const i of E(s)){const n=e.getSourceFile(i)??e.addSourceFileAtPath(i),c=C(s,i);for(const o of P(n))if(!(o.kind!=="query"&&o.kind!=="mutation"))for(const a of v(o.handler,l.PropertyAccessExpression)){const f=U(a);f!==void 0&&t.push({callee:f,exportName:o.exportName,file:c,kind:o.kind,line:a.getStartLineNumber()})}}return t},B=(e,s)=>{const t=new Set;for(const i of E(s)){const n=e.getSourceFile(i)??e.addSourceFileAtPath(i);for(const c of P(n))for(const o of v(c.handler,l.PropertyAccessExpression))V(o)&&t.add(o.getName())}return t},y={fcm:"env",hasWebPush:!0},K=new Set(["@lunora/notify"]),O=(e,s)=>{const t=e.getSymbol();if(!t)return e.getText()===s;for(const i of t.getDeclarations())if(r.isImportSpecifier(i))return K.has(i.getImportDeclaration().getModuleSpecifierValue())?i.getNameNode().getText()===s:!1;return!1},A=(e,s=new Set)=>{const t=k(e);if(!t)return;if(!r.isIdentifier(t))return t;const i=t.getSymbol();if(!i?.isAlias())return t;const n=i.getAliasedSymbol();if(!n)return t;const c=n.getDeclarations().find(a=>r.isExportAssignment(a));if(!c)return t;const o=c.getSourceFile();if(!s.has(o.getFilePath()))return A(o,s.add(o.getFilePath()))},Y=new Set(["%=","&&=","&=","**=","+=","-=","/=","<<=","=",">>=",">>>=","??=","^=","|=","||="]),x=e=>{const s=e.getSymbol();return s?.getAliasedSymbol()?.getDeclarations()[0]??s?.getDeclarations()[0]},N=e=>{if(r.isIdentifier(e))return e;if(r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e))return N(e.getExpression())},g=(e,s)=>{const t=N(e);return t!==void 0&&x(t)===s},$=(e,s)=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t))return!1;const i=t.getName(),n=t.getExpression(),c=r.isIdentifier(n)?n.getText():"";if(!((i==="assign"||i==="defineProperty"||i==="defineProperties")&&c==="Object"||i==="set"&&c==="Reflect"))return!1;const a=e.getArguments()[0];return a!==void 0&&r.isIdentifier(a)&&x(a)===s},q=(e,s)=>{if(r.isBinaryExpression(e))return Y.has(e.getOperatorToken().getText())&&g(e.getLeft(),s);if(r.isDeleteExpression(e))return g(e.getExpression(),s);if(r.isPrefixUnaryExpression(e)||r.isPostfixUnaryExpression(e)){const t=e.getOperatorToken();return(t===l.PlusPlusToken||t===l.MinusMinusToken)&&g(e.getOperand(),s)}return r.isCallExpression(e)?$(e,s):!1},G=(e,s)=>{const t=x(e);return t===void 0?!0:s.some(i=>i.getDescendants().some(n=>q(n,t)))},J=e=>{if(r.isObjectLiteralExpression(e))return e;if(!r.isIdentifier(e))return;const s=e.getSymbol(),t=s?.getAliasedSymbol()?.getDeclarations()??s?.getDeclarations()??[];for(const i of t){if(!r.isVariableDeclaration(i))continue;const n=i.getInitializer();if(!n||!r.isObjectLiteralExpression(n))continue;const c=i.getParent();if(!r.isVariableDeclarationList(c)||c.getDeclarationKind()!==L.Const)continue;const o=[i.getSourceFile(),e.getSourceFile()].filter((a,f,T)=>T.findIndex(F=>F.getFilePath()===a.getFilePath())===f);if(!G(e,o))return n}},Q=e=>r.isArrowFunction(e)||r.isFunctionExpression(e)||r.isMethodDeclaration(e),X=e=>{const s=e.getBody();if(!r.isBlock(s))return s;const[t,...i]=s.getStatements();return i.length===0&&r.isReturnStatement(t)?t.getExpression():void 0},Z=e=>{const s=u(e),t=u(s!==void 0&&Q(s)?X(s):s);if(t!==void 0&&r.isCallExpression(t)){const i=t.getExpression(),n=u(t.getArguments()[1]);return r.isIdentifier(i)&&O(i,"fcmFromEnv")&&n!==void 0&&r.isObjectLiteralExpression(n)?n:void 0}return t!==void 0&&r.isObjectLiteralExpression(t)?t:void 0},h=(e,s)=>{const t=d(e,s),i=e.getProperties();return t!==void 0&&!i.slice(i.indexOf(t)+1).some(n=>{if(r.isSpreadAssignment(n))return!0;const c=R(n.getNameNode());return c===void 0||c===s})},ee=e=>{const s=d(e,"getAccessToken");if(s===void 0||!h(e,"getAccessToken"))return!1;if(r.isShorthandPropertyAssignment(s)||r.isMethodDeclaration(s))return!0;const t=u(m(e,"getAccessToken"));return t!==void 0&&(r.isArrowFunction(t)||r.isFunctionExpression(t)||r.isCallExpression(t)||r.isPropertyAccessExpression(t)||r.isIdentifier(t)&&t.getText()!=="undefined")},te=e=>{const s=u(m(e,"projectId"));return h(e,"projectId")&&s!==void 0&&(r.isStringLiteral(s)||r.isNoSubstitutionTemplateLiteral(s))&&s.getLiteralText()!==""},se=(e,s)=>{const t=d(e,"fcm");if(t===void 0)return"absent";if(!s||!h(e,"fcm"))return"env";const i=r.isMethodDeclaration(t)?t:m(e,"fcm"),n=i===void 0?void 0:Z(i);return n===void 0||!ee(n)?"env":te(n)?"ownCredentials":"ownToken"},ie=(e,s)=>{const t=D(s,z);if(!I(t))return;const i=e.getSourceFile(t)??e.addSourceFileAtPath(t),n=A(i);if(!n||!r.isCallExpression(n))return y;const c=n.getExpression(),o=r.isIdentifier(c)&&O(c,"defineNotify")?n.getArguments()[0]:void 0,a=o===void 0?void 0:J(o);return!a||a.getProperties().some(f=>r.isSpreadAssignment(f))?y:{fcm:se(a,r.isObjectLiteralExpression(o)),hasWebPush:d(a,"webPush")!==void 0}},pe=(e,s)=>{const t=ie(e,s);if(t===void 0)return;const i=B(e,s);return{hasFcm:t.fcm!=="absent",hasWebPush:t.hasWebPush,usesFcmOnlySend:i.has("sendToTopic")||i.has("sendToCondition"),usesPush:i.size>0}};export{y as ALL_NOTIFY_CHANNELS,z as NOTIFY_FILENAME,de as discoverNotifyCalls,ie as discoverNotifyChannels,pe as discoverNotifyConfig};
|
package/dist/packem_shared/{CONTAINERS_FILENAME-7_HMXUYy.mjs → CONTAINERS_FILENAME-Dy3qWGfI.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as O}from"node:fs";import{join as j}from"node:path";import{containerClassName as A,containerBindingName as k,DURABLE_OBJECT_POLICY_FORBIDDEN_KEYS as C,isManagedImage as _,isCloudflareRegistryDigest as D,normalizeContainerImage as f}from"@lunora/container";import{SyntaxKind as $,Node as s}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{declarationLineOf as M,stringPropertyFor as F,findObjectProperty as p,symbolConstInitializer as V,descendantsOfKind as K,outermostValueWrapper as w,isWriteTarget as R}from"./isTestPath-DJeZ18i9.mjs";import{a as B}from"./attribution-
|
|
1
|
+
import{existsSync as O}from"node:fs";import{join as j}from"node:path";import{containerClassName as A,containerBindingName as k,DURABLE_OBJECT_POLICY_FORBIDDEN_KEYS as C,isManagedImage as _,isCloudflareRegistryDigest as D,normalizeContainerImage as f}from"@lunora/container";import{SyntaxKind as $,Node as s}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{declarationLineOf as M,stringPropertyFor as F,findObjectProperty as p,symbolConstInitializer as V,descendantsOfKind as K,outermostValueWrapper as w,isWriteTarget as R}from"./isTestPath-DJeZ18i9.mjs";import{a as B}from"./attribution-B8xa6AeK.mjs";import{a as b}from"./property-name-7cBlgK_O.mjs";const E="containers.ts",N=E.replace(/\.ts$/u,""),U=t=>{const e=t.getSymbol();if(!e)return t.getText()==="defineContainer";for(const r of e.getDeclarations())if(s.isImportSpecifier(r))return r.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/container"?!1:r.getNameNode().getText()==="defineContainer";return!1},d=F("container"),y=(t,e,r)=>{if(s.isNumericLiteral(t))return t.getLiteralValue();throw a(t,`container "${e}": \`${r}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},L=(t,e)=>{if(s.isStringLiteral(t)||s.isNoSubstitutionTemplateLiteral(t))return f(t.getLiteralValue());if(s.isObjectLiteralExpression(t)){const r=p(t,"registry");if(r&&s.isPropertyAssignment(r)){const i=r.getInitializerOrThrow();return f({registry:d(i,e,"image.registry")})}const n=p(t,"build");if(n&&s.isPropertyAssignment(n)){const i=n.getInitializerOrThrow();return f({build:d(i,e,"image.build")})}}throw a(t,`container "${e}": \`image\` must be a static string path, { registry: "…" }, or { build: "…" } literal`)},Y=new Set(["buildArgs","image","images","instanceType","maxInstances","name","rollout","sandbox","schedulingPolicy"]),z=new Set(["gracePeriodSeconds","stepPercentage"]),T=t=>{let e=t;for(;s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isTypeAssertion(e)||s.isParenthesizedExpression(e);)e=e.getExpression();return e},W=(t,e)=>K(e,$.Identifier).some(r=>{if(r.getSymbol()!==t)return!1;let n=w(r),i=n.getParent();if(s.isCallExpression(i)&&i.getExpression().getText()==="Object.assign")return i.getArguments()[0]===n;for(;(s.isPropertyAccessExpression(i)||s.isElementAccessExpression(i))&&i.getExpression()===n;){if(R(i))return!0;n=w(i),i=n.getParent()}return!1}),q=16,P=(t,e,r,n)=>{let i={name:r,symbol:t},o;for(let c=0;c<q;c+=1){const l=V(i.symbol);if(l===void 0||!s.isExpression(l))return o;if(o=T(l),s.isObjectLiteralExpression(o)&&i.symbol!==void 0&&W(i.symbol,e.getSourceFile()))throw a(e,`${n}: \`${i.name}\` is a const object that is written to elsewhere in this file, so its initializer is not the value the container runs with. Declare the settings where they are final.`);if(!s.isIdentifier(o))return o;i={name:o.getText(),symbol:o.getSymbol()}}return o},I=(t,e)=>{const r=T(t);return s.isIdentifier(r)?P(r.getSymbol(),r,r.getText(),e)??r:r},x=t=>{const e=t.getNonNullableType();return(e.isUnion()?e.getUnionTypes():[e]).flatMap(n=>n.getApparentType().getProperties().map(i=>i.getName()))},H=(t,e,r)=>{const n=t.getExpression().getType(),i=e==="every"||n.isAny()||n.isUnknown()?["its keys"]:[...new Set(x(n))].filter(o=>e.has(o)).map(o=>`\`${o}\``);if(i.length>0)throw a(t,`${r}: this spread can set ${i.join(", ")}, which codegen writes into wrangler.jsonc and so must read statically. Spread a module-scope \`const\` object literal, or write the keys inline.`)},J=(t,e,r)=>{const n=b(t),i=s.isShorthandPropertyAssignment(t)?P(t.getValueSymbol(),t,n,r):void 0;if(i!==void 0)return[n,i];if(e==="every"||e.has(n))throw a(t,`${r}: \`${n}\` is deploy configuration codegen writes into wrangler.jsonc, so it must be a static literal — inline it, or name a module-scope \`const\` initialized with one.`)},m=(t,e,r,n=new Set)=>{const i=[],o=new Set(n).add(t);for(const c of t.getProperties())if(s.isPropertyAssignment(c))i.push([b(c),I(c.getInitializerOrThrow(),r)]);else if(s.isSpreadAssignment(c))i.push(...X(c,e,r,o));else{const l=J(c,e,r);l!==void 0&&i.push(l)}return i},X=(t,e,r,n)=>{const i=I(t.getExpression(),r);if(!s.isObjectLiteralExpression(i))return H(t,e,r),[];if(n.has(i))throw a(t,`${r}: this spread refers back to an object it is part of, so it has no static value.`);return m(i,e,r,n)},G=(t,e)=>{if(!s.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`buildArgs\` must be a static object literal — it is deploy configuration codegen writes into wrangler.jsonc`);const r={};for(const[n,i]of m(t,"every",`container "${e}" buildArgs`))r[n]=d(i,e,`buildArgs.${n}`);return Object.keys(r).length>0?r:void 0},Q=(t,e)=>{if(!s.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`rollout\` must be a static object literal — it is deploy configuration codegen writes into wrangler.jsonc`);const r={};for(const[n,i]of m(t,z,`container "${e}" rollout`))(n==="gracePeriodSeconds"||n==="stepPercentage")&&(r[n]=y(i,e,`rollout.${n}`));return r.gracePeriodSeconds===void 0&&r.stepPercentage===void 0?void 0:r},v=t=>{if(s.isTrueLiteral(t))return!0;if(s.isFalseLiteral(t))return!1},S=t=>{if(s.isStringLiteral(t)||s.isNoSubstitutionTemplateLiteral(t)||s.isNumericLiteral(t))return t.getLiteralValue()},Z=(t,e)=>{if(s.isStringLiteral(t))return t.getLiteralValue();if(s.isObjectLiteralExpression(t)){const r={};for(const n of t.getProperties()){if(!s.isPropertyAssignment(n))throw a(n,`container "${e}": \`instanceType\` must be an object of static number literals`);const i=b(n);if(i!=="diskMb"&&i!=="memoryMib"&&i!=="vcpu")throw a(n,`container "${e}": unknown \`instanceType\` field "${i}" — expected vcpu, memoryMib, or diskMb`);r[i]=y(n.getInitializerOrThrow(),e,`instanceType.${i}`)}return r}throw a(t,`container "${e}": \`instanceType\` must be a static string or { vcpu, memoryMib, diskMb } literal`)},ee=(t,e)=>{if(!s.isObjectLiteralExpression(t))throw a(t,`container "${e}": \`images\` must be a static object literal — codegen writes it into wrangler.jsonc`);const r={};for(const[n,i]of m(t,"every",`container "${e}" images`)){const o=L(i,e);if(o.kind==="build")throw a(i,`container "${e}": \`images["${n}"]\` cannot be a Railpack { build } source — use a Dockerfile path or a { registry } reference`);if(o.kind==="registry"&&!D(o.reference))throw a(i,`container "${e}": \`images["${n}"].registry\` must be a digest-pinned (@sha256) reference under registry.cloudflare.com — push other registries' images there first`);r[n]=o}return r},te=(t,e)=>{const r=t.findLast(([i])=>i==="schedulingPolicy");if(r===void 0)return;const n=d(r[1],e,"schedulingPolicy");if(n!=="default"&&n!=="durable_object")throw a(r[1],`container "${e}": unknown \`schedulingPolicy\` "${n}" — use "default" or "durable_object"`);return n==="durable_object"?n:void 0},ne=(t,e,r,n)=>{if(r!==void 0&&C.includes(t))throw a(e,`container "${n}": \`${t}\` is not supported with schedulingPolicy "durable_object"`);if(r===void 0&&t==="images")throw a(e,`container "${n}": \`images\` needs schedulingPolicy "durable_object"`)},ie=(t,e,r,n)=>{const{base:i,policy:o}=r;switch(t){case"buildArgs":{i.buildArgs=G(e,n);break}case"enableInternet":{i.enableInternet=v(e);break}case"hardTimeout":{i.hardTimeout=S(e);break}case"image":{r.scheduled||(o.image=L(e,n));break}case"images":{o.images=ee(e,n);break}case"instanceType":{i.instanceType=Z(e,n);break}case"maxInstances":{o.maxInstances=y(e,n,"maxInstances");break}case"name":{i.name=d(e,n,"name");break}case"rollout":{o.rollout=Q(e,n);break}case"sandbox":{const c=v(e);if(c===void 0)throw a(e,`container "${n}": \`sandbox\` must be a static true/false literal`);i.sandbox=c;break}case"sleepAfter":{i.sleepAfter=S(e);break}}},re=(t,e,r)=>{const n=t.findLast(([o])=>o==="image")?.[1];if(n===void 0||!(s.isStringLiteral(n)||s.isNoSubstitutionTemplateLiteral(n)))return;const i=n.getLiteralValue();if(!Object.hasOwn(e??{},i)&&!_(i))throw a(n,`container "${r}": \`image\` "${i}" must name an entry of \`images\` or a Cloudflare-managed "cloudflare/…" image`)},se=(t,e)=>{const r=t.getArguments()[0];if(!r||!s.isObjectLiteralExpression(r))throw a(t,`container "${e}": defineContainer must be passed an inline object literal`);const n=m(r,Y,`container "${e}"`),i=te(n,e),o={base:{bindingName:k(e),className:A(e),exportName:e,file:N,line:M(t)},policy:{},scheduled:i!==void 0};for(const[g,u]of n)ne(g,u,i,e),ie(g,u,o,e);const{base:c,policy:l}=o;if(i==="durable_object")return re(n,l.images,e),{...c,...l.images===void 0?{}:{images:l.images},schedulingPolicy:i};if(l.image===void 0)throw a(r,`container "${e}": defineContainer requires a static \`image\` property`);return{...c,image:l.image,...l.maxInstances===void 0?{}:{maxInstances:l.maxInstances},...l.rollout===void 0?{}:{rollout:l.rollout}}},oe=t=>{const e=[],r=new Map;for(const n of t.getVariableDeclarations()){const i=n.getInitializer();if(i?.getKind()!==$.CallExpression)continue;const o=i,c=o.getExpression();if(!s.isIdentifier(c)||!U(c))continue;const l=n.getNameNode();if(!s.isIdentifier(l)){if(n.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw a(l,"defineContainer exports must be plain named exports (no destructuring)")}const g=B(n,"binding");if(g===void 0)continue;const u=se(o,g),h=r.get(u.bindingName);if(h!==void 0)throw a(l,`containers "${h}" and "${u.exportName}" both map to the binding ${u.bindingName} — rename one so each container gets its own Durable Object binding`);r.set(u.bindingName,u.exportName),e.push(u)}return e},be=(t,e)=>{const r=j(e,E);if(!O(r))return[];const n=t.getSourceFile(r)??t.addSourceFileAtPath(r),i=oe(n);return i.sort((o,c)=>o.exportName.localeCompare(c.exportName)),i};export{E as CONTAINERS_FILENAME,be as discoverContainers};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as l}from"node:fs";import{join as d}from"node:path";import{SyntaxKind as c,Node as i}from"ts-morph";import{diagnosticAt as f}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as m}from"./module-specifiers-BctA0m_p.mjs";import{a as u}from"./attribution-
|
|
1
|
+
import{existsSync as l}from"node:fs";import{join as d}from"node:path";import{SyntaxKind as c,Node as i}from"ts-morph";import{diagnosticAt as f}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as m}from"./module-specifiers-BctA0m_p.mjs";import{a as u}from"./attribution-B8xa6AeK.mjs";const p="env.ts",g=e=>{const n=e.getSymbol();if(!n)return e.getText()==="defineEnv";for(const t of n.getDeclarations())if(i.isImportSpecifier(t))return m(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineEnv":!1;return!1},v=e=>{const n=e.getSymbol();if(!n)return!1;for(const t of n.getDeclarations()){if(!i.isNamespaceImport(t))continue;const o=t.getFirstAncestorByKind(c.ImportDeclaration);return o!==void 0&&m(o.getModuleSpecifierValue())}return!1},E=e=>{if(i.isIdentifier(e))return g(e);if(i.isPropertyAccessExpression(e)){const n=e.getExpression();return e.getName()==="defineEnv"&&i.isIdentifier(n)&&v(n)}return!1},x=e=>{const n=[];for(const t of e.getVariableDeclarations()){const o=t.getInitializer();if(o?.getKind()!==c.CallExpression||!E(o.getExpression()))continue;const s=t.getNameNode();if(!i.isIdentifier(s)){if(t.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw f(s,"defineEnv exports must be plain named exports (no destructuring)")}const a=u(t,"member");a!==void 0&&n.push({exportName:a})}return n},D=(e,n)=>{const t=d(n,p);if(!l(t))return;const o=e.getSourceFile(t)??e.addSourceFileAtPath(t),r=x(o);if(r.length!==0){if(r.length>1)throw f(o,`lunora/env.ts declares ${r.length.toString()} defineEnv() contracts (${r.map(s=>s.exportName).join(", ")}); exactly one is allowed`);return r[0]}};export{p as ENV_FILENAME,D as discoverEnv};
|
package/dist/packem_shared/{MUTATORS_FILENAME-DdW3wZa_.mjs → MUTATORS_FILENAME-SLAN2VXq.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as E}from"node:fs";import{join as y}from"node:path";import{Node as o,SyntaxKind as l}from"ts-morph";import{diagnosticAt as I}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as M}from"./module-specifiers-BctA0m_p.mjs";import{p as A}from"./parse-validator-BisfC8bR.mjs";import{findObjectProperty as c,unwrapExpression as d,isConstDeclaration as P}from"./isTestPath-DJeZ18i9.mjs";import{g as b,i as D,d as g,h as O}from"./attribution-
|
|
1
|
+
import{existsSync as E}from"node:fs";import{join as y}from"node:path";import{Node as o,SyntaxKind as l}from"ts-morph";import{diagnosticAt as I}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as M}from"./module-specifiers-BctA0m_p.mjs";import{p as A}from"./parse-validator-BisfC8bR.mjs";import{findObjectProperty as c,unwrapExpression as d,isConstDeclaration as P}from"./isTestPath-DJeZ18i9.mjs";import{g as b,i as D,d as g,h as O}from"./attribution-B8xa6AeK.mjs";import{u as h}from"./unwrap-handler-return-BnsKyz9W.mjs";const w="mutators.ts",x=M,z=r=>{const e=r.getSymbol();if(!e)return r.getText()==="defineMutator";for(const t of e.getDeclarations())if(o.isImportSpecifier(t))return x(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMutator":!1;return!1},C=r=>{const e=r.getSymbol();if(!e)return!1;for(const t of e.getDeclarations()){if(!o.isNamespaceImport(t))continue;const i=t.getFirstAncestorByKind(l.ImportDeclaration);return i!==void 0&&x(i.getModuleSpecifierValue())}return!1},N=r=>{if(o.isIdentifier(r))return z(r);if(o.isPropertyAccessExpression(r)){const e=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(e)&&C(e)}return!1},S=r=>{const e=r.getArguments()[0];return e&&o.isObjectLiteralExpression(e)?e:void 0},m=new WeakMap,p=r=>{let e=m.get(r.compilerNode);if(e===void 0){const t=r.getNameNode(),i=t?.getText();e=r.getSourceFile().getDescendantsOfKind(l.Identifier).filter(s=>s!==t&&s.getText()===i&&g(s)?.compilerNode===r.compilerNode).length===1&&O(r)===void 0,m.set(r.compilerNode,e)}return e},f=r=>{const e=o.isIdentifier(r)?g(r):void 0,t=o.isSourceFile(e?.getParent())||o.isSourceFile(e?.getParent()?.getParent()?.getParent());if(e===void 0||e.getSourceFile()!==r?.getSourceFile()||!t)return;if(o.isFunctionDeclaration(e))return e.hasBody()&&p(e)?e:void 0;const i=P(e)?d(e.getInitializer()):void 0;return(o.isArrowFunction(i)||o.isFunctionExpression(i))&&o.isVariableDeclaration(e)&&p(e)?i:void 0},G=r=>{const e=r.getInitializer();if(!o.isCallExpression(e)||!N(e.getExpression()))return;const t=c(S(e),"server");if(o.isMethodDeclaration(t))return t;if(o.isShorthandPropertyAssignment(t))return f(t.getNameNode());const i=o.isPropertyAssignment(t)?d(t.getInitializer()):void 0;return o.isArrowFunction(i)||o.isFunctionExpression(i)?i:f(i)},T=r=>{const e=c(r,"args");if(!e||!o.isPropertyAssignment(e))return{};const t=e.getInitializer();return t&&o.isObjectLiteralExpression(t)?A(t):{}},L=r=>{const e=c(r,"server");if(!e||!o.isPropertyAssignment(e))return"unknown";const t=e.getInitializer();return!t||!(o.isArrowFunction(t)||o.isFunctionExpression(t))?"unknown":h(t)},j=r=>{const e=c(r,"owner");if(!e||!o.isPropertyAssignment(e))return;const t=e.getInitializer();return t&&o.isStringLiteral(t)?t.getLiteralValue():void 0},R=r=>{const e=[];for(const t of r.getVariableDeclarations()){if(!t.isExported())continue;const i=t.getInitializer();if(i?.getKind()!==l.CallExpression)continue;const n=i,s=n.getExpression();if(!N(s))continue;const a=t.getNameNode();if(!o.isIdentifier(a))throw I(a,"defineMutator exports must be plain named exports (no destructuring)");const u=S(n);for(const v of b(t).filter(F=>D(F)))e.push({args:T(u),exportName:v,filePath:"mutators",line:n.getStartLineNumber(),owner:j(u),returnType:L(u)})}return e},J=(r,e)=>{const t=y(e,w);if(!E(t))return[];const i=r.getSourceFile(t)??r.addSourceFileAtPath(t),n=R(i);return n.sort((s,a)=>s.exportName.localeCompare(a.exportName)),n};export{w as MUTATORS_FILENAME,J as discoverMutators,N as isDefineMutatorCallee,S as mutatorLiteral,G as mutatorServerImplOf};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as q}from"node:fs";import{join as f}from"node:path";import{LunoraError as b}from"@lunora/errors";import{queueDefaultName as y,queueBindingName as S}from"@lunora/queue";import{SyntaxKind as w,Node as u}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{declarationLineOf as N,lunoraRelativePath as g,findObjectProperty as l,stringPropertyFor as v}from"./isTestPath-DJeZ18i9.mjs";import{a as $}from"./attribution-
|
|
1
|
+
import{existsSync as q}from"node:fs";import{join as f}from"node:path";import{LunoraError as b}from"@lunora/errors";import{queueDefaultName as y,queueBindingName as S}from"@lunora/queue";import{SyntaxKind as w,Node as u}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{declarationLineOf as N,lunoraRelativePath as g,findObjectProperty as l,stringPropertyFor as v}from"./isTestPath-DJeZ18i9.mjs";import{a as $}from"./attribution-B8xa6AeK.mjs";import{r as F}from"./handler-reference-_zhtPddp.mjs";import{d as P}from"./modules-isOWiSYI.mjs";const h="queues.ts",E=o=>{const e=t=>t==="defineQueue"||t==="defineSubscription"||t==="defineTopic",i=o.getSymbol();if(!i){const t=o.getText();return e(t)?t:void 0}for(const t of i.getDeclarations()){if(!u.isImportSpecifier(t))continue;if(t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/queue")return;const n=t.getNameNode().getText();return e(n)?n:void 0}},d=v("queue"),I=(o,e,i)=>{if(u.isNumericLiteral(o))return o.getLiteralValue();throw c(o,`queue "${e}": \`${i}\` must be a static numeric literal — it is deploy configuration codegen writes into wrangler.jsonc`)},A={maxBatchSize:{integer:!0,max:100,min:1},maxBatchTimeout:{integer:!1,max:60,min:0},maxConcurrency:{integer:!0,max:250,min:1},maxRetries:{integer:!0,max:100,min:0},retryDelay:{integer:!0,max:86400,min:0}},T=(o,e)=>{const i={};for(const[t,n]of Object.entries(A)){const s=l(o,t);if(s&&u.isPropertyAssignment(s)){const a=I(s.getInitializerOrThrow(),e,t);if(a<n.min||a>n.max||n.integer&&!Number.isInteger(a))throw c(s,`queue "${e}": \`${t}\` must be ${n.integer?"an integer":"a number"} from ${n.min.toString()} to ${n.max.toString()} (got ${a.toString()})`);i[t]=a}}return i},O=(o,e)=>{const i=l(o,"name");if(!i||!u.isPropertyAssignment(i))return;const t=d(i.getInitializerOrThrow(),e,"name");if(t.length===0)throw c(i,`queue "${e}": \`name\` must be a non-empty string when provided`);return t},x=(o,e,i,t)=>{const n=F(l(o,"handler"),t)?.site,s={bindingName:S(e),exportName:e,filePath:g(t,o.getSourceFile().getFilePath()),line:N(o),mode:"push",name:O(o,e)??y(e),...i===void 0?{}:{topic:i},...n===void 0?{}:{handlerSite:n},tuning:{}},a=l(o,"mode");if(a&&u.isPropertyAssignment(a)){if(i!==void 0)throw c(a,`subscription "${e}": \`mode\` is not allowed — a subscription is always a push consumer`);const m=d(a.getInitializerOrThrow(),e,"mode");if(m!=="push"&&m!=="pull")throw c(a,`queue "${e}": \`mode\` must be "push" or "pull" (got ${JSON.stringify(m)})`);s.mode=m}const r=l(o,"deadLetterQueue");return r&&u.isPropertyAssignment(r)&&(s.tuning.deadLetterQueue=d(r.getInitializerOrThrow(),e,"deadLetterQueue")),Object.assign(s.tuning,T(o,e)),s},Q=(o,e,i)=>{const t=o.getArguments()[0];if(!t||!u.isObjectLiteralExpression(t))throw c(o,`queue "${e}": defineQueue must be passed an inline object literal`);return x(t,e,void 0,i)},p=(o,e)=>`${o}:${e}`,L=o=>{const e=o.getSymbol(),i=(e?.isAlias()===!0?e.getAliasedSymbol():e)?.getDeclarations()[0];return i!==void 0&&u.isVariableDeclaration(i)?p(i.getSourceFile().getFilePath(),i.getName()):p(o.getSourceFile().getFilePath(),o.getText())},U=(o,e,i,t)=>{const[n,s]=o.getArguments(),a=n!==void 0&&u.isIdentifier(n)?i.get(L(n)):void 0;if(a===void 0)throw c(n??o,`subscription "${e}": the first argument must name a \`defineTopic()\` export of lunora/queues.ts or a module's queues.ts`);if(!s||!u.isObjectLiteralExpression(s))throw c(o,`subscription "${e}": defineSubscription must be passed an inline object literal`);return x(s,e,a,t)},C=o=>{const e=[];for(const i of o.getVariableDeclarations()){const t=i.getInitializer();if(t?.getKind()!==w.CallExpression)continue;const n=t,s=n.getExpression(),a=u.isIdentifier(s)?E(s):void 0;if(a===void 0)continue;const r=i.getNameNode();if(!u.isIdentifier(r)){if(i.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw c(r,`${a} exports must be plain named exports (no destructuring)`)}const m=$(i,"binding");m!==void 0&&e.push({call:n,exportName:m,factory:a,localName:r.getText()})}return e},M=(o,e)=>{const i=new Map;for(const t of o){const n=g(e,t.call.getSourceFile().getFilePath()),s=i.get(t.exportName);if(s!==void 0)throw c(t.call,`"${t.exportName}" is exported by both lunora/${s}.ts and lunora/${n}.ts — queue and topic export names must be unique across the app`);i.set(t.exportName,n)}},j=(o,e)=>{const i=o.flatMap(r=>C(r));M(i,e);const t=i.filter(r=>r.factory==="defineTopic"),n=new Map(t.map(r=>[p(r.call.getSourceFile().getFilePath(),r.localName),r.exportName])),s=[];for(const r of i)r.factory==="defineQueue"?s.push(Q(r.call,r.exportName,e)):r.factory==="defineSubscription"&&s.push(U(r.call,r.exportName,n,e));const a=t.map(r=>({exportName:r.exportName,filePath:g(e,r.call.getSourceFile().getFilePath()),line:N(r.call)}));return{queues:s,topics:a}},z=(o,e)=>[f(e,h),...P(o,e).map(i=>f(e,i.name,h))].filter(i=>q(i)),D=o=>{const e=new Map,i=new Map;for(const t of o){const n=e.get(t.name);if(n!==void 0)throw new b("DUPLICATE_QUEUE_NAME",`Duplicate queue name "${t.name}": produced by both "${n}" and "${t.exportName}". Deployed queue names must be unique across the project.`,{status:500});e.set(t.name,t.exportName);const s=i.get(t.bindingName);if(s!==void 0)throw new b("DUPLICATE_QUEUE_BINDING",`Duplicate queue binding "${t.bindingName}": produced by both "${s}" and "${t.exportName}". Queue export names must yield unique binding names.`,{status:500});i.set(t.bindingName,t.exportName)}},B=(o,e)=>{const i=z(o,e).map(a=>o.getSourceFile(a)??o.addSourceFileAtPath(a)),{queues:t,topics:n}=j(i,e),s=t.toSorted((a,r)=>a.exportName.localeCompare(r.exportName));return D(s),{queues:s,topics:n.toSorted((a,r)=>a.exportName.localeCompare(r.exportName))}},Y=(o,e)=>B(o,e).queues;export{h as QUEUES_FILENAME,B as discoverQueueDeclarations,Y as discoverQueues};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{existsSync as z,readFileSync as ze,mkdirSync as pt,writeFileSync as mo,rmSync as ve,readdirSync as ls}from"node:fs";import{dirname as gt,join as E,relative as Be,sep as ti,basename as ho}from"node:path";import{performance as _t}from"node:perf_hooks";import{RUNTIME_LINTS as vo,STATIC_LINTS as Eo,runAdvisor as xo}from"@lunora/advisor";import{LunoraError as D}from"@lunora/errors";import{serializeSchemaSnapshot as So}from"./SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs";import{toAdvisorContext as yo}from"./formatAdvisories-Bue5tbp6.mjs";import{Node as r,SyntaxKind as d,Project as ds,VariableDeclarationKind as us,ts as C}from"ts-morph";import{listLunoraSourceFiles as b,lunoraRelativePath as I,declarationLineOf as si,collectCallRows as L,descendantsOfKind as S,bindingKeyName as Ee,findObjectProperty as U,collectSecurityCallRows as Ao,propertyInitializer as $,listSecurityScanFiles as Ve,objectLiteralFromCallbackBody as ni,limitNameOf as ii,optionsObjectLiteral as ri,handlerOf as bo,memberAccessOf as fs,chainRootOf as mt,unwrapExpression as v,collectNodeRows as ce,isConstDeclaration as X,outermostValueWrapper as O,isWriteTarget as we,isSameNode as w,returningFunctionOf as qt,walkChain as No,staticNumberValue as oi,RUN_METHODS as ps,functionReferenceSegments as wo,isTestPath as Po,isFunctionLike as pe,functionKeyOf as ai,withSourceListMemo as Io}from"./isTestPath-DJeZ18i9.mjs";import{j as te,h as Z,c as A,a as gs,w as ms,k as To,d as V,l as Co,b as ci,f as Oo,m as ko,g as Ht,i as Ro}from"./attribution-
|
|
1
|
+
import{existsSync as z,readFileSync as ze,mkdirSync as pt,writeFileSync as mo,rmSync as ve,readdirSync as ls}from"node:fs";import{dirname as gt,join as E,relative as Be,sep as ti,basename as ho}from"node:path";import{performance as _t}from"node:perf_hooks";import{RUNTIME_LINTS as vo,STATIC_LINTS as Eo,runAdvisor as xo}from"@lunora/advisor";import{LunoraError as D}from"@lunora/errors";import{serializeSchemaSnapshot as So}from"./SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs";import{toAdvisorContext as yo}from"./formatAdvisories-Bue5tbp6.mjs";import{Node as r,SyntaxKind as d,Project as ds,VariableDeclarationKind as us,ts as C}from"ts-morph";import{listLunoraSourceFiles as b,lunoraRelativePath as I,declarationLineOf as si,collectCallRows as L,descendantsOfKind as S,bindingKeyName as Ee,findObjectProperty as U,collectSecurityCallRows as Ao,propertyInitializer as $,listSecurityScanFiles as Ve,objectLiteralFromCallbackBody as ni,limitNameOf as ii,optionsObjectLiteral as ri,handlerOf as bo,memberAccessOf as fs,chainRootOf as mt,unwrapExpression as v,collectNodeRows as ce,isConstDeclaration as X,outermostValueWrapper as O,isWriteTarget as we,isSameNode as w,returningFunctionOf as qt,walkChain as No,staticNumberValue as oi,RUN_METHODS as ps,functionReferenceSegments as wo,isTestPath as Po,isFunctionLike as pe,functionKeyOf as ai,withSourceListMemo as Io}from"./isTestPath-DJeZ18i9.mjs";import{j as te,h as Z,c as A,a as gs,w as ms,k as To,d as V,l as Co,b as ci,f as Oo,m as ko,g as Ht,i as Ro}from"./attribution-B8xa6AeK.mjs";import{i as H,a as Ae,r as Lo,b as Fo,c as li,d as Do,s as Ue,e as _o,f as Mo,g as $o}from"./ip-reads-D8rPYtZ6.mjs";import{e as J,f as Ko,m as di,b as ht,g as hs,E as ui,C as fi,d as pi,h as zo,j as Bo,a as Vo}from"./context-root-CO8PbZi5.mjs";import{a as k,i as gi,c as le,d as mi,e as hi,f as Uo,b as Wo,g as jo,h as qo}from"./classify-procedure-call-BK_MMoue.mjs";import{a as y,s as vs}from"./property-name-7cBlgK_O.mjs";import{b as Ho,a as vi}from"./module-specifiers-BctA0m_p.mjs";import{r as vt,s as Go}from"./parse-validator-BisfC8bR.mjs";import Yo from"./discoverAuthApiCalls-DcvsgL5u.mjs";import{i as B,r as Ei}from"./database-calls-Cug60vT9.mjs";import{i as Gt,p as xi,w as Qo,d as Xo}from"./index-BwLaIVqA.mjs";import Jo from"./discoverHyperdriveCalls-B--Nvx36.mjs";import{PROJECT_CONFIG_FILENAMES as Zo,findProjectConfigFile as Si,findCodegenConfigFile as ea}from"./PROJECT_CONFIG_FILENAMES-CLfsyvjA.mjs";import{contextPropertiesRead as ta,createTargetScope as sa,fileWiresRequestSecretTool as na,discoverFeatureUsage as ia}from"./capabilitiesUsedBy-BcDkRoOu.mjs";import{diagnosticAt as Pe}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{m as Es,a as ot,s as yi,d as ra}from"./index-CQuAXbal.mjs";import{MUTATORS_FILENAME as oa,isDefineMutatorCallee as aa,mutatorServerImplOf as ca,discoverMutators as la}from"./MUTATORS_FILENAME-SLAN2VXq.mjs";import da from"./discoverNondeterministicCalls-MeKjo_UX.mjs";import{discoverNotifyConfig as ua,discoverNotifyCalls as fa}from"./ALL_NOTIFY_CHANNELS-DI0zmZGs.mjs";import pa from"./discoverR2sqlCalls-DHvclvkv.mjs";import ga from"./discoverRlsProcedures-CUfhUqfY.mjs";import{s as xs,n as ma}from"./dispatch-namespace-DwTjD7BU.mjs";import{secretKindOf as ha,redact as va,isHeuristicSecretKind as Ea,isSecretishName as xa}from"./redact-Cy14LEnc.mjs";import{r as Ai,p as Sa,c as ya,a as Aa,e as ba,d as Na}from"./project-config-file-DR7xrrNB.mjs";import{a as Je,d as wa,r as Pa}from"./modules-isOWiSYI.mjs";import{WORKFLOWS_FILENAME as Ia,discoverWorkflows as Ta}from"./WORKFLOWS_FILENAME-Dtxo_XBw.mjs";import{r as Ca}from"./json-data-Chfs2Cz5.mjs";import{a as Oa,I as ka,g as Ra,G as bi,d as La,i as Fa}from"./shared-Cn7dMQ_u.mjs";import{createCodegenProject as Da}from"./createCodegenProject-C4XuJSap.mjs";import{findTsconfig as MS,refreshCodegenProject as $S,tsconfigFingerprint as KS}from"./createCodegenProject-C4XuJSap.mjs";import{wranglerString as _a,wranglerValue as Ma,companionName as $a,COMPANION_FILES as Ka}from"./COMPANION_BINDING-Da_v9XpC.mjs";import{CAPABILITIES as za,usedCapabilities as Ba}from"./CAPABILITY_PROBES-DCzOjTN7.mjs";import{isD1GlobalTable as Ni,isHyperdriveGlobalTable as wi}from"./isD1GlobalTable-udvHAAzD.mjs";import{discoverAgents as Va}from"./AGENTS_FILENAME-BSW65Q9R.mjs";import{discoverContainers as Ua}from"./CONTAINERS_FILENAME-Dy3qWGfI.mjs";import Wa from"./discoverCrons-MpIC14pg.mjs";import{discoverEnv as ja}from"./ENV_FILENAME-DFx_jlpa.mjs";import Pi from"./readPackageDependencies-RHhGiz0k.mjs";import{discoverQueueDeclarations as qa}from"./QUEUES_FILENAME-CVkpGqoY.mjs";import{discoverSandboxUsage as Ha}from"./discoverSandboxUsage-CdrJNRFd.mjs";import{resolveServiceBindings as Ga}from"./companionServiceBinding-BZjm486n.mjs";import Ya from"./discoverStorageRulesMetadata-D_pYyr1i.mjs";import{resolveCodegenTarget as ke,gatePlatformFeatures as Qa,readTargetDiagnostics as Xa,vectorizeDimensionDiagnostics as Ja,liveStreamsDeliveryAuthorizationDiagnostic as Za,socketRoutesDeliveryAuthorizationDiagnostic as ec,studioPlatformFor as tc,platformFeatureAvailable as sc,gateAdminTokenRevocation as nc}from"./DEFAULT_TARGET-5-_edM-R.mjs";import{i as ic}from"./schema-BgM8A3XV.mjs";import{b as Ii,e as rc}from"./shard-CWAD5mYy.mjs";import{e as oc,a as ac}from"./server-Dfxmm5Zw.mjs";import{emitDataModel as cc}from"./emitDataModel-BvCZS4Yq.mjs";import{i as lc,b as dc,e as uc,d as fc,f as pc,c as gc}from"./unwrap-handler-return-BnsKyz9W.mjs";import mc from"./discoverHttpRoutes-BtMgsfzG.mjs";import hc from"./discoverInserts-Dx7Lxey3.mjs";import{e as Ti}from"./exported-procedure-chains-ej9ozyZB.mjs";import vc from"./discoverMigrations-DaBdK1Bv.mjs";import rn from"./discoverQueries-BlhMsXuk.mjs";import Ec from"./discoverRlsMetadata-CO-pRHOx.mjs";import xc from"./discoverSchema-CL9PLdOu.mjs";import{discoverShapes as Sc}from"./SHAPES_FILENAME-Cf4sum4C.mjs";import{i as yc}from"./reserved-words-CW1QFbTd.mjs";import{emitAuthModule as Ac,emitApp as bc}from"./emitApp-LFKtDRYu.mjs";import{readJsonSync as Nc}from"@visulima/fs";import{indexReferencesOf as wc,buildSchemaSnapshot as Pc}from"./SchemaSnapshotParseError-CV7mmuPi.mjs";import{buildOpenApiDocument as Ic,emitOpenApiModule as Tc}from"./buildOpenApiDocument-C3zlve6K.mjs";import{buildOpenRpcDocument as Cc,emitOpenRpcModule as Oc}from"./OPENRPC_VERSION-DkWde9eh.mjs";import{w as kc,u as Rc,v as Lc,t as Fc,x as Dc}from"./shard-runtime-G5mZQjY0.mjs";import{emitCollections as _c,emitSeed as Mc,emitApi as $c,emitInternalApi as Kc}from"./emitApi-lwadq5G7.mjs";import{emitCrons as zc,emitScheduler as Bc,emitAdminRevocations as Vc,emitShardRegistry as Uc,emitDurableObjects as Wc,emitVectors as jc,emitWranglerCronTriggers as qc}from"./emitCrons-CCRKs482.mjs";import Hc from"./emitDrizzleSchema-BzOChEYW.mjs";import{LAZY_FUNCTION_DIRECTORY as Ci,emitFunctions as Gc,emitLazyFunctionModules as Yc}from"./emitFunctions-ppMX7E3X.mjs";const Qc=(e,t=!1)=>{if(e.length===0)return"";const s=La(t),n=e.map(c=>{if(Oa(c.exportName,"live stream export name"),!ka.test(c.filePath))throw new Error(`@lunora/codegen: live stream file path is not safe to import: ${JSON.stringify(c.filePath)}`);return`import type { ${c.exportName} as ${c.exportName}Stream } from "../${c.filePath}.js";`}),i=e.map(c=>{const l=c.topics.map(u=>{Ra(u.name,"live topic name");const f=`(typeof ${c.exportName}Stream)["topics"]["${u.name}"]`,p=`LiveTopicRef<LiveTopicPayload<${f}>>`,g=JSON.stringify(c.id);if(u.fields.length===0)return` ${u.name}: (): ${p} => ({ __lunoraLive: ${g}, topic: ${JSON.stringify(u.name)} }),`;const h=u.fields.map(x=>`\${encodeURIComponent(key.${x})}`).join(":");return` ${u.name}: (key: LiveTopicKey<${f}>): ${p} => ({
|
|
2
2
|
__lunoraLive: ${g},
|
|
3
3
|
topic: \`${u.name}:${h}\`,
|
|
4
4
|
}),`});return` ${c.exportName}: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as d}from"node:fs";import{join as l}from"node:path";import{SyntaxKind as m,Node as n}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as u}from"./module-specifiers-BctA0m_p.mjs";import{p as h}from"./parse-validator-BisfC8bR.mjs";import{declarationLineOf as x,findObjectProperty as c}from"./isTestPath-DJeZ18i9.mjs";import{a as S}from"./attribution-
|
|
1
|
+
import{existsSync as d}from"node:fs";import{join as l}from"node:path";import{SyntaxKind as m,Node as n}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as u}from"./module-specifiers-BctA0m_p.mjs";import{p as h}from"./parse-validator-BisfC8bR.mjs";import{declarationLineOf as x,findObjectProperty as c}from"./isTestPath-DJeZ18i9.mjs";import{a as S}from"./attribution-B8xa6AeK.mjs";import{m as f}from"./ip-reads-D8rPYtZ6.mjs";const b="shapes.ts",y=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineShape";for(const e of t.getDeclarations())if(n.isImportSpecifier(e))return u(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineShape":!1;return!1},I=r=>{const t=r.getSymbol();if(!t)return!1;for(const e of t.getDeclarations()){if(!n.isNamespaceImport(e))continue;const i=e.getFirstAncestorByKind(m.ImportDeclaration);return i!==void 0&&u(i.getModuleSpecifierValue())}return!1},N=r=>{if(n.isIdentifier(r))return y(r);if(n.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineShape"&&n.isIdentifier(t)&&I(t)}return!1},A=r=>{const[t]=r.getArguments();if(!t||!n.isObjectLiteralExpression(t))return;const e=c(t,"table");if(!e||!n.isPropertyAssignment(e))return;const i=e.getInitializer();return i&&n.isStringLiteral(i)?i.getLiteralValue():void 0},E=r=>{const[t]=r.getArguments();if(!t||!n.isObjectLiteralExpression(t))return{};const e=c(t,"args");if(!e||!n.isPropertyAssignment(e))return{};const i=e.getInitializer();return!i||!n.isObjectLiteralExpression(i)?{}:h(i)},P=r=>{const[t]=r.getArguments(),e=n.isObjectLiteralExpression(t)?c(t,"where"):void 0,i=n.isPropertyAssignment(e)?e.getInitializer():void 0;if(e===void 0)return f(r);if(!n.isArrowFunction(i)&&!n.isFunctionExpression(i))return!0;const o=i.getParameters()[0]?.getNameNode();return n.isIdentifier(o)&&o.getText()!=="ctx"&&o.findReferencesAsNodes().length>0||f(r)},v=r=>{const t=[];for(const e of r.getVariableDeclarations()){const i=e.getInitializer();if(i?.getKind()!==m.CallExpression)continue;const o=i,s=o.getExpression();if(!N(s))continue;const a=e.getNameNode();if(!n.isIdentifier(a)){if(e.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw g(a,"defineShape exports must be plain named exports (no destructuring)")}const p=S(e,"binding");p!==void 0&&t.push({args:E(o),exportName:p,filePath:"shapes",line:x(e),...P(o)?{readsIp:!0}:{},table:A(o)})}return t},K=(r,t)=>{const e=l(t,b);if(!d(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),o=v(i);return o.sort((s,a)=>s.exportName.localeCompare(a.exportName)),o};export{b as SHAPES_FILENAME,K as discoverShapes};
|
package/dist/packem_shared/{WORKFLOWS_FILENAME-DXusn4DF.mjs → WORKFLOWS_FILENAME-Dtxo_XBw.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as b}from"node:fs";import{join as k}from"node:path";import{LunoraError as w}from"@lunora/errors";import y from"@lunora/scheduler/validate";import{workflowDefaultName as E,workflowClassName as v}from"@lunora/workflow";import{Node as n,VariableDeclarationKind as S,SyntaxKind as P}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapToCallExpression as x,declarationLineOf as L,lunoraRelativePath as N,findObjectProperty as d,stringPropertyFor as $}from"./isTestPath-DJeZ18i9.mjs";import{a as A}from"./attribution-
|
|
1
|
+
import{existsSync as b}from"node:fs";import{join as k}from"node:path";import{LunoraError as w}from"@lunora/errors";import y from"@lunora/scheduler/validate";import{workflowDefaultName as E,workflowClassName as v}from"@lunora/workflow";import{Node as n,VariableDeclarationKind as S,SyntaxKind as P}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapToCallExpression as x,declarationLineOf as L,lunoraRelativePath as N,findObjectProperty as d,stringPropertyFor as $}from"./isTestPath-DJeZ18i9.mjs";import{a as A}from"./attribution-B8xa6AeK.mjs";import{r as O}from"./handler-reference-_zhtPddp.mjs";const W="workflows.ts",C=new Set(["do","sleep","sleepUntil","waitForEvent"]),F=o=>{const e=o.getSymbol();if(!e)return o.getText()==="defineWorkflow";for(const t of e.getDeclarations())if(n.isImportSpecifier(t))return t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/workflow"?!1:t.getNameNode().getText()==="defineWorkflow";return!1},m=$("workflow"),I=(o,e,t)=>{if(n.isNumericLiteral(o))return o.getLiteralValue();throw c(o,`workflow "${e}": \`${t}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},f=(o,e)=>{const t=d(o,e);return t&&n.isPropertyAssignment(t)?t.getInitializerOrThrow():void 0},g=(o,e,t)=>{if(n.isObjectLiteralExpression(o))return o;throw c(o,`workflow "${e}": \`${t}\` must be an inline object literal — it is deploy configuration codegen writes into wrangler.jsonc`)},D=(o,e)=>{if(!n.isArrayLiteralExpression(o)||o.getElements().length===0)throw c(o,`workflow "${e}": \`schedules\` must be a non-empty inline array of cron expression string literals`);return o.getElements().map(t=>{const r=m(t,e,"schedules[]");if(!y(r))throw c(t,`workflow "${e}": schedule "${r}" is not a valid cron expression`);return r})},R=(o,e)=>{const t={},r=f(o,"schedules");r!==void 0&&(t.schedules=D(r,e));const s=f(o,"limits");if(s!==void 0){const i=f(g(s,e,"limits"),"steps");if(i===void 0)t.limits={};else{const l=I(i,e,"limits.steps");if(!Number.isInteger(l)||l<=0)throw c(i,`workflow "${e}": \`limits.steps\` must be a positive integer (got ${String(l)})`);t.limits={steps:l}}}const a=f(o,"defaultRetention");if(a!==void 0){const i=g(a,e,"defaultRetention"),l={};for(const u of["errorRetention","successRetention"]){const p=f(i,u);p!==void 0&&(l[u]=m(p,e,`defaultRetention.${u}`))}t.defaultRetention=l}return t},T=o=>{const e=o.getExpression();if(!n.isPropertyAccessExpression(e)||!C.has(e.getName()))return!1;const t=e.getExpression();return n.isPropertyAccessExpression(t)&&t.getName()==="step"?!0:n.isIdentifier(t)&&t.getText()==="step"},j=o=>{if(!o)return[];const e=[];for(const t of o.getDescendantsOfKind(P.CallExpression)){if(!T(t))continue;const r=t.getArguments()[0];!r||!(n.isStringLiteral(r)||n.isNoSubstitutionTemplateLiteral(r))||e.push({line:t.getStartLineNumber(),method:t.getExpression().getName(),name:r.getLiteralValue()})}return e},h=o=>{let e=o;for(;e&&(n.isAsExpression(e)||n.isSatisfiesExpression(e)||n.isParenthesizedExpression(e));)e=e.getExpression();return e},K=o=>{const e=h(o);if(e&&n.isObjectLiteralExpression(e))return e;if(!(!e||!n.isIdentifier(e)))for(const t of e.getSymbol()?.getDeclarations()??[]){const s=n.isVariableDeclaration(t)&&t.getVariableStatement()?.getDeclarationKind()===S.Const?h(t.getInitializer()):void 0;if(s&&n.isObjectLiteralExpression(s))return s}},V=(o,e)=>{const t=d(o,"handler"),r=O(t,e);return r!==void 0?r:{body:t!==void 0&&n.isPropertyAssignment(t)?t.getInitializer():t}},z=(o,e,t)=>{const r=K(o.getArguments()[0]);if(!r)throw c(o,`workflow "${e}": defineWorkflow's argument must be an object literal, or a local \`const\` holding one — codegen reads \`name\` and the \`ctx.step.*\` calls out of it statically. Keep the handler wherever you like and pass it through: \`const config = { handler: myHandler }; export const ${e} = defineWorkflow(config);\`.`);const s=V(r,t),a={className:v(e),exportName:e,file:N(t,o.getSourceFile().getFilePath()),line:L(o),name:E(e),steps:j(s.body),...s.file===void 0?{}:{handlerFile:s.file},...s.site===void 0?{}:{handlerSite:s.site}},i=d(r,"name");return i&&n.isPropertyAssignment(i)&&(a.name=m(i.getInitializerOrThrow(),e,"name")),{...a,...R(r,e)}},M=(o,e)=>{const t=[];for(const r of o.getVariableDeclarations()){const s=x(r.getInitializer());if(!s)continue;const a=s.getExpression();if(!n.isIdentifier(a)||!F(a))continue;const i=r.getNameNode();if(!n.isIdentifier(i)){if(r.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw c(i,"defineWorkflow exports must be plain named exports (no destructuring)")}const l=A(r,"binding");l!==void 0&&t.push(z(s,l,e))}return t},_=o=>{const e=new Map,t=new Map;for(const r of o){const s=e.get(r.name);if(s!==void 0)throw new w("DUPLICATE_WORKFLOW_NAME",`Duplicate workflow name "${r.name}": produced by both "${s}" and "${r.exportName}". Deployed workflow names must be unique across the project.`,{status:500});e.set(r.name,r.exportName);const a=t.get(r.className);if(a!==void 0)throw new w("DUPLICATE_WORKFLOW_CLASS",`Duplicate workflow class "${r.className}": produced by both "${a}" and "${r.exportName}". Workflow export names must yield unique generated class names.`,{status:500});t.set(r.className,r.exportName)}},ee=(o,e)=>{const t=k(e,W);if(!b(t))return[];const r=o.getSourceFile(t)??o.addSourceFileAtPath(t),s=M(r,e);return s.sort((a,i)=>a.exportName.localeCompare(i.exportName)),_(s),s};export{W as WORKFLOWS_FILENAME,ee as discoverWorkflows};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{callSiteCallers as b,byCodepoint as k}from"@lunora/advisor";import{Node as n,SyntaxKind as p,VariableDeclarationKind as O,ts as F}from"ts-morph";import{i as T}from"./reserved-words-CW1QFbTd.mjs";import{isWriteTarget as M,descendantsOfKind as V,unwrapExpression as P}from"./isTestPath-DJeZ18i9.mjs";const N=new WeakMap,A=e=>e.getStatements().flatMap(t=>n.isFunctionDeclaration(t)?[t]:n.isVariableStatement(t)?t.getDeclarations().filter(o=>n.isIdentifier(o.getNameNode())):[]),x=e=>n.isStringLiteral(e)?e.getLiteralValue():e.getText(),C=e=>{if(n.isFunctionDeclaration(e)||n.isClassDeclaration(e)){const t=e.getName();return e.hasExportKeyword()?[[t??"default",e.hasDefaultKeyword()?"default":t??"default"]]:[]}return!n.isVariableStatement(e)||!e.hasExportKeyword()?[]:e.getDeclarations().flatMap(t=>{const o=t.getNameNode();return n.isIdentifier(o)?[[o.getText(),o.getText()]]:o.getDescendantsOfKind(p.BindingElement).flatMap(r=>n.isIdentifier(r.getNameNode())?[[r.getName(),r.getName()]]:[])})},I=e=>{if(n.isExportDeclaration(e))return e.hasModuleSpecifier()||e.isTypeOnly()?[]:e.getNamedExports().filter(o=>!o.isTypeOnly()).map(o=>{const r=x(o.getNameNode()),s=o.getAliasNode();return[r,s===void 0?r:x(s)]});const t=n.isExportAssignment(e)&&!e.isExportEquals()?e.getExpression():void 0;return n.isIdentifier(t)?[[t.getText(),"default"]]:C(e)},h=new WeakMap,K=e=>{const t=h.get(e.compilerNode);if(t!==void 0)return t;const o=new Map;for(const[s,i]of e.getStatements().flatMap(c=>I(c)))o.set(s,(o.get(s)??new Set).add(i));const r=new Map([...o].map(([s,i])=>[s,[...i].toSorted(Z)]));return h.set(e.compilerNode,r),r},g=e=>{const t=n.isBindingElement(e)?e.getFirstAncestorByKind(p.VariableStatement):void 0,o=n.isVariableDeclaration(e)?e.getVariableStatement():void 0,r=n.isFunctionDeclaration(e)?e:t??o;if(r===void 0||!n.isSourceFile(r.getParent()))return[];const s=n.isFunctionDeclaration(e)?e.getName()??"default":e.getName();return K(e.getSourceFile()).get(s)??[]},L=e=>new Map(e.flatMap(t=>{const o=g(t);return o.length===0?[]:[[t.compilerNode,o]]})),B=e=>{const t=P(e);return t!==void 0&&(n.isArrowFunction(t)||n.isFunctionExpression(t))},y=(e,t)=>{for(const o of e.getAncestors()){if(n.isExportAssignment(o)&&!o.isExportEquals())return{kind:"export",name:"default"};if((n.isFunctionDeclaration(o)&&n.isSourceFile(o.getParent())||n.isVariableDeclaration(o)&&n.isSourceFile(o.getVariableStatement()?.getParent())&&n.isIdentifier(o.getNameNode()))&&(n.isFunctionDeclaration(o)||n.isVariableDeclaration(o))){const s=t.get(o.compilerNode)?.[0];return s!==void 0?{kind:"export",name:s}:n.isFunctionDeclaration(o)||B(o.getInitializer())?{declaration:o,kind:"helper"}:{kind:"untracked"}}}return{kind:"untracked"}},E=e=>{for(const t of e.getAncestors()){if(n.isExpressionWithTypeArguments(t)){const o=t.getParent();return!(n.isHeritageClause(o)&&o.getToken()===p.ExtendsKeyword&&(n.isClassDeclaration(o.getParent())||n.isClassExpression(o.getParent())))}if(F.isTypeNode(t.compilerNode))return!0}return!1},te=e=>{const t=e.getParent(),o=n.isPropertyAccessExpression(t)&&t.getNameNode()===e,r=(n.isPropertyAssignment(t)||n.isMethodDeclaration(t))&&t.getNameNode()===e;return!o&&!r&&!E(e)},v=e=>{const t=e.getParent();return n.isShorthandPropertyAssignment(t)&&t.getNameNode()===e?t.getValueSymbol():e.getSymbol()},R=e=>{const t=v(e);return t?.getValueDeclaration()??t?.getDeclarations()[0]},S=new WeakMap,$=/\/typescript\/lib\/lib\.[^/]+\.d\.ts$/u,_=e=>{const t=e.getFilePath();return e.isDeclarationFile()&&($.test(t)||t.includes("/@types/node/"))},W=e=>{let t=e;for(;n.isBindingElement(t);)t=t.getParentOrThrow().getParentOrThrow();const o=n.isVariableDeclaration(t)?t.getParent():void 0;return n.isVariableDeclarationList(o)?o:void 0},oe=e=>{const t=e.getNameNode();if(!n.isIdentifier(t)||W(e)?.getDeclarationKind()===O.Const||_(e.getSourceFile()))return!1;let o=S.get(e.compilerNode);if(o===void 0){const r=n.isFunctionDeclaration(e)?e.getSourceFile():e.getFirstAncestor(i=>n.isFunctionLikeDeclaration(i)||n.isArrowFunction(i))??e.getSourceFile(),s=t.getText();o=r.getDescendantsOfKind(p.Identifier).some(i=>i!==t&&i.getText()===s&&M(i)&&R(i)?.compilerNode===e.compilerNode),S.set(e.compilerNode,o)}return o},z=e=>{const t=new Map,o=new Set,r=new Set;for(const s of e){const i=s.getNameNode(),c=i?.getSymbol()?.compilerSymbol;i!==void 0&&c!==void 0&&(t.set(c,s.compilerNode),o.add(i.compilerNode),r.add(i.getText()))}return{bySymbol:t,nameNodes:o,spellings:r}},H=(e,t,o)=>{const{bySymbol:r,nameNodes:s,spellings:i}=z(t),c=new Map;for(const a of V(e,p.Identifier)){if(!i.has(a.getText())||s.has(a.compilerNode)||E(a))continue;const l=v(a)?.compilerSymbol,d=l===void 0?void 0:r.get(l);d!==void 0&&c.set(d,[...c.get(d)??[],y(a,o)])}return c},q=(e,t)=>{const o=new Map(e.map(a=>[a.compilerNode,new Set])),r=new Set,s=a=>(o.get(a)?.size??0)+(r.has(a)?1:0),i=(a,l)=>{const d=s(a),u=o.get(a),m=l.kind==="helper"?l.declaration.compilerNode:void 0;l.kind==="export"&&u?.add(l.name);for(const w of m===void 0?[]:o.get(m)??[])u?.add(w);return(l.kind==="untracked"||m!==void 0&&r.has(m))&&r.add(a),s(a)!==d};let c=!0;for(;c;){c=!1;for(const[a,l]of t)for(const d of l)c=i(a,d)||c}return new Map([...o].map(([a,l])=>[a,{callers:[...l].toSorted((d,u)=>d.localeCompare(u)),untracked:r.has(a)}]))},X=e=>{const t=N.get(e.compilerNode);if(t!==void 0)return t;const o=A(e),r=L(o),s=o.filter(c=>!r.has(c.compilerNode)),i={exportNames:r,helperReach:s.length===0?new Map:q(s,H(e,s,r))};return N.set(e.compilerNode,i),i},re=e=>{const t=X(e.getSourceFile()),o=y(e,t.exportNames);switch(o.kind){case"export":return{kind:"export",name:o.name};case"helper":{const r=o.declaration.getName(),s=t.helperReach.get(o.declaration.compilerNode);if(r===void 0||s===void 0)throw new Error(`call-site attribution: helper at ${o.declaration.getSourceFile().getFilePath()} is not indexed`);return{callers:s.callers,kind:"helper",name:r,...s.untracked?{untracked:!0}:{}}}default:return{kind:"module"}}},j=e=>{if(e.kind==="helper"&&e.untracked===!0)return;const t=b(e);return t.length===0?void 0:t},G=(e,t)=>{const o=new Set(b(e).map(r=>t(r)));return o.has("public")?"public":j(e)===void 0||o.has(void 0)?void 0:"internal"},ne=(e,t)=>{const o=new Map(t.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return e.map(r=>{const s=G(r.scope,i=>o.get(`${r.file}:${i}`));return s===void 0?r:{...r,visibility:s}})},f=/^[$A-Z_a-z][\w$]*$/u,D=e=>f.test(e),Y=e=>{const t=g(e);return t.length===0?n.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0?e.getName():void 0:t.find(o=>D(o))??e.getName()},se=e=>e.getVariableStatements().flatMap(t=>t.getDeclarations()).filter(t=>Y(t)!==void 0),ie=(e,t)=>{if(n.isIdentifier(e.getNameNode()))return e.getVariableStatement()?.hasExportKeyword()===!0?e.getName():g(e).find(o=>t==="binding"?T(o):D(o))},Z=(e,t)=>Number(f.test(t))-Number(f.test(e))||k(e,t);export{ie as a,oe as b,re as c,R as d,K as e,te as f,g,Y as h,D as i,se as j,E as k,_ as l,j as m,v as r,ne as w};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i}from"ts-morph";import{listLunoraSourceFiles as a,lunoraRelativePath as c,handlerOf as l}from"./isTestPath-DJeZ18i9.mjs";import{j as d,h as f}from"./attribution-
|
|
1
|
+
import{Node as i}from"ts-morph";import{listLunoraSourceFiles as a,lunoraRelativePath as c,handlerOf as l}from"./isTestPath-DJeZ18i9.mjs";import{j as d,h as f}from"./attribution-B8xa6AeK.mjs";import{b as u}from"./context-root-CO8PbZi5.mjs";import{c as m}from"./classify-procedure-call-BK_MMoue.mjs";const p=t=>{const r=t.getInitializer();if(!r||!i.isCallExpression(r))return;const e=m(r);if(!e||e.kind!=="query"&&e.kind!=="mutation")return;const o=l(r,e.receiver);return o?{exportName:f(t)??t.getName(),handler:o,kind:e.kind}:void 0},x=(t,r)=>{const e=t.getParent();return e&&i.isPropertyAccessExpression(e)&&e.getExpression()===t?`ctx.${r}.${e.getName()}`:`ctx.${r}`},h=(t,r,e)=>{const o=[];for(const n of u(t.handler,e))o.push({callee:x(n,e),exportName:t.exportName,file:r,kind:t.kind,line:n.getStartLineNumber()});return o},N=(t,r,e)=>{const o=[];for(const n of d(t)){const s=p(n);s&&o.push(...h(s,r,e))}return o},F=(t,r,e)=>{const o=[];for(const n of a(r)){const s=t.getSourceFile(n)??t.addSourceFileAtPath(n);o.push(...N(s,c(r,n),e))}return o};export{F as d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as o,SyntaxKind as d}from"ts-morph";import{unwrapExpression as l,memberAccessOf as C,descendantsOfKind as P,bindingKeyName as I,isConstDeclaration as D,findObjectProperty as E,walkChain as M}from"./isTestPath-DJeZ18i9.mjs";import{d as v,b as O,f as F}from"./attribution-
|
|
1
|
+
import{Node as o,SyntaxKind as d}from"ts-morph";import{unwrapExpression as l,memberAccessOf as C,descendantsOfKind as P,bindingKeyName as I,isConstDeclaration as D,findObjectProperty as E,walkChain as M}from"./isTestPath-DJeZ18i9.mjs";import{d as v,b as O,f as F}from"./attribution-B8xa6AeK.mjs";import{c as w}from"./classify-procedure-call-BK_MMoue.mjs";import{isDefineMutatorCallee as B}from"./MUTATORS_FILENAME-SLAN2VXq.mjs";const x=8,h=t=>{if(o.isMethodDeclaration(t))return t;const e=o.isPropertyAssignment(t)?l(t.getInitializer()):void 0,r=o.isShorthandPropertyAssignment(t)?t.getNameNode():e;if(o.isArrowFunction(r)||o.isFunctionExpression(r))return r;const i=o.isIdentifier(r)?v(r):void 0;if(o.isFunctionDeclaration(i))return i;const n=D(i)?l(i.getInitializer()):void 0;return o.isArrowFunction(n)||o.isFunctionExpression(n)?n:void 0},T=t=>{const e=l(t.getArguments()[0]),r=o.isObjectLiteralExpression(e)?e:void 0,i=E(r,"server"),n=E(r,"handler"),s=i!==void 0&&B(t.getExpression()),a=n===void 0?void 0:w(t),u=a!==void 0&&a.receiver===void 0;return[s?h(i):void 0,u?h(n):void 0].filter(f=>f!==void 0)},p=new WeakMap,S=t=>{const e=t.getSourceFile(),r=p.get(e.compilerNode);if(r!==void 0)return r;const i=new Set(e.getDescendantsOfKind(d.CallExpression).flatMap(n=>T(n)).map(n=>n.compilerNode));return p.set(e.compilerNode,i),i},A=t=>{const e=t.getParent();return(o.isArrowFunction(e)||o.isFunctionExpression(e)||o.isFunctionDeclaration(e)||o.isMethodDeclaration(e))&&e.getParameters()[0]===t&&S(t).has(e.compilerNode)},Y=t=>{const e=t.getParent();return(o.isArrowFunction(e)||o.isFunctionExpression(e)||o.isFunctionDeclaration(e)||o.isMethodDeclaration(e))&&e.getParameters()[1]===t&&S(t).has(e.compilerNode)},z=t=>t.getNameNode().getDescendantsOfKind(d.BindingElement).some(e=>e.getParent().getParent()===t&&["args","ctx"].includes(I(e))),b=(t,e,r)=>{const i=t.getInitializer();if(i===void 0)return e;const n=r>0?c(i,"trust",r-1):void 0;return n?.length===e.length&&n.every((s,a)=>s===e[a])?e:void 0},H=(t,e,r,i)=>{if(e==="ctx")return r==="trust"?b(t,[],i):[]},g=(t,e,r)=>{const i=t.getParent().getParent(),n=I(t);if(t.getDotDotDotToken()!==void 0||e==="trust"&&O(t))return;let s;if(o.isParameterDeclaration(i)){if(!A(i)||z(i))return H(t,n,e,r);s=[]}else o.isBindingElement(i)?s=g(i,e,r):o.isVariableDeclaration(i)&&r>0&&(s=c(i.getInitializer(),e,r-1));const a=s===void 0?void 0:[...s,n];return e==="trust"&&a!==void 0?b(t,a,r):a},c=(t,e="discover",r=x)=>{const i=l(t),n=C(i);if(n!==void 0){const s=c(n.object,e,r);return s===void 0?void 0:[...s,n.member]}return o.isIdentifier(i)?K(i,e,r):void 0},K=(t,e,r)=>{const i=t.getText()==="ctx",n=e==="trust"||!i?v(t):void 0;return i&&!o.isVariableDeclaration(n)?o.isBindingElement(n)?g(n,e,r):[]:o.isParameterDeclaration(n)?o.isIdentifier(n.getNameNode())&&A(n)?[]:void 0:o.isBindingElement(n)?g(n,e,r):!(o.isVariableDeclaration(n)&&o.isIdentifier(n.getNameNode())&&r>0)||e==="trust"&&O(n)?void 0:c(n.getInitializer(),e,r-1)},Z=t=>c(t,"discover"),$=t=>c(t,"trust"),U=t=>{const e=c(t);return e===void 0?void 0:["ctx",...e].join(".")},ee=(t,e)=>{if(e(t.getText()))return!0;const r=U(t);return r!==void 0&&e(r)},te=(t,e)=>{const r=l(t),i=C(r);if(i!==void 0&&i.member!==e.at(-1))return!1;const n=r===void 0?void 0:c(r);return n?.length===e.length&&n.every((s,a)=>s===e[a])},ne=(t,e)=>y(t).get(e)??[],k=t=>{const e=new Map;for(const i of P(t,d.BindingElement)){const n=o.isIdentifier(i.getNameNode())?g(i,"discover",x):void 0;n?.length===1&&n[0]!==void 0&&e.set(i.compilerNode,n[0])}const r=new Set([...e.keys()].map(i=>i.name.getText()));return P(t,d.Identifier).flatMap(i=>{const s=r.has(i.getText())&&!o.isBindingElement(i.getParent())?v(i):void 0,a=s===void 0?void 0:e.get(s.compilerNode);return a===void 0?[]:[[a,i]]})},N=new WeakMap,y=t=>{const e=N.get(t.compilerNode);if(e!==void 0)return e;const r=new Map;for(const[n,s]of[..._(t),...k(t)])r.set(n,[...r.get(n)??[],s]);const i=new Map([...r].map(([n,s])=>[n,s.toSorted((a,u)=>a.getPos()-u.getPos())]));return N.set(t.compilerNode,i),i},_=t=>t.getDescendantsOfKind(d.PropertyAccessExpression).flatMap(e=>R(e.getExpression())?[[e.getName(),e]]:[]),R=t=>o.isIdentifier(t)&&c(t)?.length===0,ie=t=>{const e=c(t);return e?.length===1&&e[0]==="db"},j=new Set(["asId","createMultipartUpload","fetch","generateUploadUrl","getPresignedUrl","getSignedUrl","getUrl","normalizeId","resumeMultipartUpload","runAction","runMutation","runQuery","store","upload"]),L=new Set(["catch","flatMap","map","reduce","reduceRight","then"]),V=t=>{for(let e=t;o.isBindingElement(e)||o.isObjectBindingPattern(e)||o.isArrayBindingPattern(e);e=e.getParent())if(o.isBindingElement(e)&&e.getInitializer()!==void 0)return!0;return!1},X=(t,e=x)=>{const r=M(t,u=>{const f=l(u.getExpression()),m=o.isPropertyAccessExpression(f)?f.getName():void 0;return m!==void 0&&(j.has(m)||L.has(m))?!1:void 0}),i=r.root;if(r.verdict!==void 0||!o.isIdentifier(i))return r.verdict??!1;if(c(i,"trust")!==void 0)return!0;const n=v(i),s=o.isBindingElement(n)?n.getFirstAncestorByKind(d.VariableDeclaration):n;if(o.isBindingElement(n)&&V(n))return!1;const a=D(s)&&e>0?s.getInitializer():void 0;return a!==void 0&&X(a,e-1)},re=t=>(o.isIdentifier(t)?[t]:t.getDescendantsOfKind(d.Identifier)).some(r=>F(r)&&c(r,"trust")!==void 0);export{L as C,j as E,R as a,ne as b,$ as c,ie as d,te as e,U as f,Z as g,X as h,Y as i,h as j,ee as m,re as r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SyntaxKind as g,Node as n}from"ts-morph";import{descendantsOfKind as p}from"./isTestPath-DJeZ18i9.mjs";import{d as l}from"./context-root-
|
|
1
|
+
import{SyntaxKind as g,Node as n}from"ts-morph";import{descendantsOfKind as p}from"./isTestPath-DJeZ18i9.mjs";import{d as l}from"./context-root-CO8PbZi5.mjs";const c=e=>n.isPropertyAccessExpression(e)&&e.getName()==="db"||n.isIdentifier(e)&&e.getText()==="db"||l(e),b=new Set(["findFirst","findFirstOrThrow","findMany","findUnique"]),E=e=>{const t=e.getExpression();if(!n.isPropertyAccessExpression(t)||!b.has(t.getName()))return;const s=t.getExpression();if(c(s))return{options:e.getArguments()[1],table:d(e)};if(n.isPropertyAccessExpression(s)){const o=s.getExpression();if(c(o))return{options:e.getArguments()[0],table:s.getName()}}},f=(e,t)=>{const s=e.getExpression();return!n.isPropertyAccessExpression(s)||!t.has(s.getName())?!1:c(s.getExpression())},d=e=>{const t=e.getArguments()[0];return t&&n.isStringLiteral(t)?t.getLiteralText():""},A=(e,t,s)=>{const o=new Set,i=new Set;for(const a of p(e,g.CallExpression))if(f(a,t)){const r=d(a);r!==""&&o.add(r)}else if(f(a,s)){const r=d(a);r!==""&&i.add(r)}return{tablesRead:[...o],tablesWritten:[...i]}};export{c as i,E as r,A as t};
|
package/dist/packem_shared/{discoverAuthApiCalls-BFou6Thm.mjs → discoverAuthApiCalls-DcvsgL5u.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as t}from"ts-morph";import{collectCallRows as n}from"./isTestPath-DJeZ18i9.mjs";import{c as p}from"./attribution-
|
|
1
|
+
import{Node as t}from"ts-morph";import{collectCallRows as n}from"./isTestPath-DJeZ18i9.mjs";import{c as p}from"./attribution-B8xa6AeK.mjs";import{a}from"./property-name-7cBlgK_O.mjs";const c=s=>{const r=s.getExpression();if(!t.isPropertyAccessExpression(r))return!1;const e=r.getExpression();return t.isPropertyAccessExpression(e)?e.getName()==="authApi":t.isIdentifier(e)&&e.getText()==="authApi"},u=s=>{const r=s.getArguments()[0];if(r===void 0)return!1;if(!t.isObjectLiteralExpression(r))return!0;for(const e of r.getProperties())if((t.isPropertyAssignment(e)||t.isShorthandPropertyAssignment(e))&&a(e)==="headers"||t.isSpreadAssignment(e))return!0;return!1},d=(s,r)=>n(s,r,(e,o)=>{if(!c(e))return;const i=e.getExpression();return{file:o,hasHeaders:u(e),line:e.getStartLineNumber(),method:t.isPropertyAccessExpression(i)?i.getName():"",scope:p(e)}});export{d as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./declared-output-Iaar469J.mjs";import"./isTestPath-DJeZ18i9.mjs";import"./attribution-B8xa6AeK.mjs";import"./unwrap-handler-return-BnsKyz9W.mjs";import"./ip-reads-D8rPYtZ6.mjs";import"./classify-procedure-call-BK_MMoue.mjs";import{d as f}from"./index-BwLaIVqA.mjs";import"./dispatch-namespace-DwTjD7BU.mjs";export{f as default};
|
package/dist/packem_shared/{discoverHttpRoutes-zVW8BZNx.mjs → discoverHttpRoutes-BtMgsfzG.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as n}from"ts-morph";import{a as m,p as l}from"./parse-validator-BisfC8bR.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./isTestPath-DJeZ18i9.mjs";import{j as f,h as g}from"./attribution-
|
|
1
|
+
import{Node as n}from"ts-morph";import{a as m,p as l}from"./parse-validator-BisfC8bR.mjs";import{listLunoraSourceFiles as d,lunoraRelativePath as h}from"./isTestPath-DJeZ18i9.mjs";import{j as f,h as g}from"./attribution-B8xa6AeK.mjs";import{u as x}from"./unwrap-handler-return-BnsKyz9W.mjs";const u=new Set(["delete","get","head","options","patch","post","put"]),E=new Set(["body","params","searchParams"]),v=new Set(["handler","stream"]),P=s=>{const e=s.getArguments()[0];if(e&&n.isStringLiteral(e))return e.getLiteralValue()},S=s=>{const e=s.getArguments()[0];return e&&n.isObjectLiteralExpression(e)?l(e):{}},A=s=>{if(!n.isCallExpression(s))return;const e=s.getExpression();if(!n.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const a=e.getExpression();if(!n.isIdentifier(a)||a.getText()!=="httpRoute")return;const t=P(s);return t===void 0?void 0:{method:o.toUpperCase(),path:t}},T=(s,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},a=s.getExpression();if(!n.isPropertyAccessExpression(a))return;let t=a.getExpression();for(;n.isCallExpression(t);){const i=t.getExpression();if(!n.isPropertyAccessExpression(i))break;const c=i.getName();if(u.has(c))break;if(E.has(c)){const p=S(t);o[c]={...p,...o[c]}}else if(c==="output"&&o.output===void 0){const p=t.getArguments()[0];p&&n.isExpression(p)&&(o.output=m(p))}t=i.getExpression()}const r=A(t);if(r)return o.method=r.method,o.path=r.path,o},b=s=>{const e=s.getArguments()[0];return!e||!(n.isArrowFunction(e)||n.isFunctionExpression(e))?"unknown":x(e,!0)},y=(s,e,o,a)=>{const t=e.getName();if(!v.has(t))return;const r=T(s,t);if(!(r?.method===void 0||r.path===void 0))return{body:r.body,exportName:o,filePath:a,method:r.method,params:r.params,path:r.path,searchParams:r.searchParams,stream:r.stream,...r.stream?{chunkType:b(s)}:{},...r.output?{output:r.output}:{}}},R=(s,e)=>{const o=[];for(const a of f(s)){const t=a.getInitializer();if(!t||!n.isCallExpression(t))continue;const r=t.getExpression();if(!n.isPropertyAccessExpression(r))continue;const i=y(t,r,g(a)??a.getName(),e);i&&o.push(i)}return o},L=(s,e)=>{const o=d(e),a=[];for(const t of o){const r=s.getSourceFile(t)??s.addSourceFileAtPath(t),i=h(e,t);a.push(...R(r,i))}return a.sort((t,r)=>`${t.method} ${t.path}`.localeCompare(`${r.method} ${r.path}`)||t.filePath.localeCompare(r.filePath)),a};export{L as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as o}from"./context-property-calls-As5I0QR6.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i}from"ts-morph";import{collectCallRows as n}from"./isTestPath-DJeZ18i9.mjs";import{c as a}from"./attribution-
|
|
1
|
+
import{Node as i}from"ts-morph";import{collectCallRows as n}from"./isTestPath-DJeZ18i9.mjs";import{c as a}from"./attribution-B8xa6AeK.mjs";import{i as c}from"./database-calls-Cug60vT9.mjs";const l=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="insert")return!1;const r=e.getExpression();return c(r)},g=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 o=s.getInitializer();if(o&&i.isStringLiteral(o))return o.getLiteralText()}},f=t=>{const e=t.getArguments()[0];return e?i.isStringLiteral(e)?e.getLiteralText():g(e)??"":""},d=(t,e)=>n(t,e,(r,s)=>l(r)?{file:s,line:r.getStartLineNumber(),scope:a(r),table:f(r)}:void 0);export{d as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./isTestPath-DJeZ18i9.mjs";import"./attribution-B8xa6AeK.mjs";import"./database-calls-Cug60vT9.mjs";import"./classify-procedure-call-BK_MMoue.mjs";import{d as a}from"./index-CQuAXbal.mjs";export{a as default};
|
package/dist/packem_shared/{discoverMigrations-D6OuJs3t.mjs → discoverMigrations-DaBdK1Bv.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SyntaxKind as p,Node as n}from"ts-morph";import{diagnosticAt as h}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as I}from"./module-specifiers-BctA0m_p.mjs";import{listLunoraSourceFiles as P,lunoraRelativePath as b,findObjectProperty as d}from"./isTestPath-DJeZ18i9.mjs";import{j as x,a as A}from"./attribution-
|
|
1
|
+
import{SyntaxKind as p,Node as n}from"ts-morph";import{diagnosticAt as h}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as I}from"./module-specifiers-BctA0m_p.mjs";import{listLunoraSourceFiles as P,lunoraRelativePath as b,findObjectProperty as d}from"./isTestPath-DJeZ18i9.mjs";import{j as x,a as A}from"./attribution-B8xa6AeK.mjs";const S=i=>{const r=i.getSymbol();if(!r)return i.getText()==="defineMigration";for(const t of r.getDeclarations())if(n.isImportSpecifier(t))return I(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMigration":!1;return!1},u=(i,r)=>{const t=d(i,r);if(!t||!n.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&n.isStringLiteral(e)?e.getLiteralValue():void 0},z=i=>{const r=n.isPropertyAssignment(i)?i.getInitializer():void 0;if(r===void 0||!n.isObjectLiteralExpression(r))return;const t=u(r,"field"),e=d(r,"after"),o=n.isPropertyAssignment(e)?e.getInitializer():void 0;if(!(t===void 0||e!==void 0&&!(o!==void 0&&n.isNumericLiteral(o))))return{...o!==void 0&&n.isNumericLiteral(o)?{after:o.getLiteralValue()}:{},field:t}},E=i=>{const r=d(i,"covers"),t=n.isPropertyAssignment(r)?r.getInitializer():void 0;if(t===void 0||!n.isObjectLiteralExpression(t))return;const e={};for(const s of["jurisdiction","shardMode","table"]){const c=u(t,s);c!==void 0&&(e[s]=c)}const o=z(d(t,"ttl"));o!==void 0&&(e.ttl=o);const a=d(t,"memory");return n.isPropertyAssignment(a)&&a.getInitializer()?.getKind()===p.TrueKeyword&&(e.memory=!0),Object.keys(e).length===0?void 0:e},g=i=>n.isParenthesizedExpression(i)?g(i.getExpression()):i,v=i=>n.isArrowFunction(i)||n.isFunctionExpression(i)||n.isMethodDeclaration(i)||n.isFunctionDeclaration(i),y=(i,r=4)=>{const t=g(i);if(v(t))return t;if(r===0||!n.isIdentifier(t))return;const e=t.getParent(),o=n.isShorthandPropertyAssignment(e)?e.getValueSymbol():t.getSymbol(),a=o?.getAliasedSymbol()??o,s=a?.getValueDeclaration()??a?.getDeclarations()[0];if(s!==void 0){if(n.isVariableDeclaration(s)){const c=s.getInitializer();return c===void 0?void 0:y(c,r-1)}return v(s)?s:void 0}},N=i=>{const r=d(i,"up");let t=r;n.isPropertyAssignment(r)?t=r.getInitializer():n.isShorthandPropertyAssignment(r)&&(t=r.getNameNode());const e=t===void 0?void 0:y(t);if(e===void 0)return!1;const o=e.getParameters()[0]?.getNameNode();if(o===void 0||!n.isIdentifier(o))return!1;const a=m=>{const f=m===void 0?void 0:g(m);return f!==void 0&&n.isIdentifier(f)&&f.getText()===o.getText()},s=e.getBody();if(s===void 0)return!1;if(!n.isBlock(s))return a(s);const[c,...l]=s.getStatements();return l.length===0&&c!==void 0&&n.isReturnStatement(c)&&a(c.getExpression())},D=(i,r)=>{const t=i.getInitializer();if(t?.getKind()!==p.CallExpression)return;const e=t.getExpression();if(!n.isIdentifier(e)||!S(e))return;const o=t.getArguments()[0];if(!o||!n.isObjectLiteralExpression(o))return;const a=u(o,"id"),s=A(i,"member");if(s===void 0)return;if(a===void 0||a.trim()==="")throw h(o,`Migration "${s}" in "${r}" must declare \`id\` as a non-empty string literal so codegen can key the registry.`,{code:"MIGRATION_ID_NOT_STATIC",name:"LunoraError",status:500});const c=E(o);return{...c===void 0?{}:{covers:c},exportName:s,filePath:r,id:a,...N(o)?{identity:!0}:{},table:u(o,"table")??""}},M=i=>{const r=new Map;for(const t of i){const e=r.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});r.set(t.id,t.filePath)}},V=(i,r)=>{const t=P(r),e=[];for(const o of t){const a=i.getSourceFile(o)??i.addSourceFileAtPath(o),s=b(r,o);for(const c of x(a)){const l=D(c,s);l&&e.push(l)}}return e.sort((o,a)=>o.id.localeCompare(a.id)),M(e),e};export{V as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as s,SyntaxKind as d}from"ts-morph";import{listLunoraSourceFiles as m,lunoraRelativePath as g,handlerOf as u,descendantsOfKind as l}from"./isTestPath-DJeZ18i9.mjs";import{j as N,h as x}from"./attribution-
|
|
1
|
+
import{Node as s,SyntaxKind as d}from"ts-morph";import{listLunoraSourceFiles as m,lunoraRelativePath as g,handlerOf as u,descendantsOfKind as l}from"./isTestPath-DJeZ18i9.mjs";import{j as N,h as x}from"./attribution-B8xa6AeK.mjs";import{c as p}from"./classify-procedure-call-BK_MMoue.mjs";const h={"crypto.getRandomValues":"crypto.getRandomValues","crypto.randomUUID":"crypto.randomUUID","Date.now":"Date.now","Math.random":"Math.random"},E=new Set(["globalThis","self"]),v=new Set(["globalThis","self","window"]),I=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e)){const t=e.getExpression();if(s.isIdentifier(t)&&v.has(t.getText()))return e.getName()}},S=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=I(t.getExpression());if(i!==void 0)return n==="fetch"&&E.has(i)?"fetch":h[`${i}.${n}`]},T=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"},y=e=>{const t=e.getInitializer();if(!t||!s.isCallExpression(t))return;const n=p(t);if(!n||n.kind!=="query"&&n.kind!=="mutation")return;const i=u(t,n.receiver);return i?{exportName:x(e)??e.getName(),handler:i,kind:n.kind}:void 0},L=e=>{const t=new Set(["ctx"]),n=r=>{if(s.isObjectBindingPattern(r))for(const a of r.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getNameNode().getText(),f=a.getNameNode();c==="ctx"&&s.isIdentifier(f)&&t.add(f.getText())}},[i]=s.isParametered(e)?e.getParameters():[],o=i!==void 0&&s.isIdentifier(i.getNameNode())?i.getNameNode().getText():void 0;if(i!==void 0){const r=i.getNameNode();s.isIdentifier(r)?t.add(r.getText()):n(r)}for(const r of l(e,d.VariableDeclaration)){const a=r.getInitializer();o!==void 0&&a!==void 0&&s.isIdentifier(a)&&a.getText()===o&&n(r.getNameNode())}return t},P=(e,t,n)=>{const i=e.getExpression();if(!s.isPropertyAccessExpression(i)||i.getName()!=="random")return!1;const o=i.getExpression();return!s.isIdentifier(o)||!t.has(o.getText())?!1:o.getSymbol()?.getDeclarations()[0]?.getFirstAncestor(c=>s.isFunctionLikeDeclaration(c))===n},w=(e,t)=>{const n=[],i=L(e.handler);for(const o of l(e.handler,d.CallExpression)){const r=e.kind==="query"&&P(o,i,e.handler)?"ctx.random":S(o);r!==void 0&&n.push({callee:r,exportName:e.exportName,file:t,kind:e.kind,line:o.getStartLineNumber()})}for(const o of l(e.handler,d.NewExpression)){const r=T(o);r!==void 0&&n.push({callee:r,exportName:e.exportName,file:t,kind:e.kind,line:o.getStartLineNumber()})}return n},O=(e,t)=>{const n=[];for(const i of N(e)){const o=y(i);o&&n.push(...w(o,t))}return n},A=(e,t)=>{const n=[];for(const i of m(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...O(o,g(t,i)))}return n};export{A as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i,SyntaxKind as u}from"ts-morph";import{collectCallRows as x}from"./isTestPath-DJeZ18i9.mjs";import{w as E,c as h}from"./attribution-
|
|
1
|
+
import{Node as i,SyntaxKind as u}from"ts-morph";import{collectCallRows as x}from"./isTestPath-DJeZ18i9.mjs";import{w as E,c as h}from"./attribution-B8xa6AeK.mjs";import{i as v}from"./database-calls-Cug60vT9.mjs";const A=new Set(["withGeoIndex","withIndex","withSearchIndex"]),S=new Set(["collect","collectWithScores","first","paginate","take","unique"]),w=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="query")return!1;const n=e.getExpression();return v(n)},y=t=>{const e=[];let n=t;for(;;){const s=n.getParent();if(!s||!i.isPropertyAccessExpression(s))break;const r=s.getParent();if(!r||!i.isCallExpression(r))break;e.push(r),n=r}return e},l=t=>{const e=t.getExpression();return i.isPropertyAccessExpression(e)?e.getName():""},m=t=>{if(t===void 0||!(i.isArrowFunction(t)||i.isFunctionExpression(t)))return;const e=t.getParameters()[0]?.getNameNode();return e!==void 0&&i.isIdentifier(e)?e.getText():void 0},O=t=>{let e=t;for(;i.isCallExpression(e)||i.isPropertyAccessExpression(e);)e=e.getExpression();return e},P=(t,e)=>{const n=new Set,s=[t,...t.getDescendantsOfKind(u.CallExpression)].filter(r=>i.isCallExpression(r));for(const r of s){const c=r.getExpression();if(i.isPropertyAccessExpression(c)){const o=O(c);i.isIdentifier(o)&&o.getText()===e&&n.add(c.getName())}}return n},f=(t,e)=>{if(i.isParenthesizedExpression(t))return f(t.getExpression(),e);if(i.isConditionalExpression(t)){const n=f(t.getWhenFalse(),e);return new Set([...f(t.getWhenTrue(),e)].filter(s=>n.has(s)))}return P(t,e)},C=t=>{if(!(i.isArrowFunction(t)||i.isFunctionExpression(t)))return;const e=t.getBody();if(!i.isBlock(e))return i.isExpression(e)?[e]:void 0;const n=e.getDescendantsOfKind(u.ReturnStatement).filter(s=>s.getFirstAncestor(r=>i.isArrowFunction(r)||i.isFunctionExpression(r))?.compilerNode===t.compilerNode).map(s=>s.getExpression()).filter(s=>s!==void 0);return n.length===0?void 0:n},F=(t,e)=>{const n=C(t);if(n===void 0)return;const[s,...r]=n.map(o=>f(o,e));return[...s??new Set].filter(o=>r.every(d=>d.has(o))).toSorted((o,d)=>o.localeCompare(d))},I=(t,e)=>{const n=new Set;for(const s of t.getDescendantsOfKind(u.PropertyAccessExpression)){const r=s.getExpression();i.isIdentifier(r)&&r.getText()===e&&n.add(s.getName())}for(const s of t.getDescendantsOfKind(u.ElementAccessExpression)){const r=s.getExpression(),c=s.getArgumentExpression();i.isIdentifier(r)&&r.getText()===e&&c!==void 0&&i.isStringLiteral(c)&&n.add(c.getLiteralText())}return[...n]},N=t=>{if(t===void 0)return;const[e,n]=t.getArguments(),s=m(n),r=e!==void 0&&i.isStringLiteral(e)?e.getLiteralText():void 0;return n===void 0?{bounds:[],name:r}:{bounds:s===void 0?void 0:F(n,s),name:r}},T=t=>{const e=t.flatMap(n=>{const s=n.getArguments()[0],r=m(s);return s===void 0||r===void 0?[]:I(s,r)});if(e.length!==0)return[...new Set(e)].toSorted((n,s)=>n.localeCompare(s))},b=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,D=t=>t.some(e=>l(e)==="filter"&&b.test(e.getArguments()[0]?.getText()??"")),L=t=>{const e=t.getArguments()[0];return e&&i.isStringLiteral(e)?e.getLiteralText():""},k=(t,e,n=[])=>{const s=x(t,e,(r,c)=>{if(!w(r))return;const o=y(r),d=o.map(a=>l(a)),p=o.filter(a=>l(a)==="filter"),g=p.length>0;return{file:c,filterFields:g?T(p):void 0,filtersPrimaryKey:g&&D(o),hasFilter:g,hasIndex:d.some(a=>A.has(a)),index:N(o.find(a=>l(a)==="withIndex")),line:r.getStartLineNumber(),scope:h(r),table:L(r),terminal:d.findLast(a=>S.has(a))}});return E(s,n)};export{k as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as r}from"./context-property-calls-As5I0QR6.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
|
package/dist/packem_shared/{discoverRlsMetadata-CFOKezvx.mjs → discoverRlsMetadata-CO-pRHOx.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as o}from"ts-morph";import{listLunoraSourceFiles as h,lunoraRelativePath as x,findObjectProperty as m,stringPropertyOf as a}from"./isTestPath-DJeZ18i9.mjs";import{e as L}from"./exported-procedure-chains-
|
|
1
|
+
import{Node as o}from"ts-morph";import{listLunoraSourceFiles as h,lunoraRelativePath as x,findObjectProperty as m,stringPropertyOf as a}from"./isTestPath-DJeZ18i9.mjs";import{e as L}from"./exported-procedure-chains-ej9ozyZB.mjs";import{r as P,p as A}from"./policies-CrNWTJQi.mjs";const v=new Set(["delete","insert","read","update"]),E=(e,t,s)=>{const i=[];for(const r of A(e)){const n=a(r,"on");n===void 0||!v.has(n)||i.push({file:t,on:n,procedure:s,table:a(r,"table")??""})}return i},f=e=>{if(!o.isObjectLiteralExpression(e))return[];const t=m(e,"permissions");if(!t||!o.isPropertyAssignment(t))return[];const s=t.getInitializer();if(!s||!o.isArrayLiteralExpression(s))return[];const i=[];for(const r of s.getElements()){if(o.isStringLiteral(r)){i.push(r.getLiteralText());continue}if(o.isCallExpression(r)){const n=r.getArguments()[0];n&&o.isStringLiteral(n)&&i.push(n.getLiteralText())}}return i},u=(e,t)=>t===void 0?e:{...e,description:t},y=e=>{if(o.isCallExpression(e)){const t=e.getArguments()[0];if(!t||!o.isStringLiteral(t))return;const s=e.getArguments()[1],i=s?a(s,"description"):void 0,r=s?f(s):[];return u({name:t.getLiteralText(),permissions:r},i)}if(o.isObjectLiteralExpression(e)){const t=a(e,"name");return t===void 0?void 0:u({name:t,permissions:f(e)},a(e,"description"))}},O=e=>{const t=e.getArguments()[1];if(!t||!o.isObjectLiteralExpression(t))return[];const s=m(t,"roles");if(!s||!o.isPropertyAssignment(s))return[];const i=s.getInitializer();if(!i||!o.isArrayLiteralExpression(i))return[];const r=[];for(const n of i.getElements()){const c=y(n);c&&r.push(c)}return r},S=(e,t,s)=>{const i=P(e);return{policies:i.flatMap(r=>E(r,t,s)),roles:i.flatMap(r=>O(r))}},M=(e,t)=>{const s=[],i=new Map;for(const r of h(t)){const n=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=x(t,r);for(const{name:g,receiver:d}of L(n)){const p=S(d,c,g);s.push(...p.policies);for(const l of p.roles)i.has(l.name)||i.set(l.name,l)}}return{policies:s,roles:[...i.values()]}};export{M as default};
|
package/dist/packem_shared/{discoverRlsProcedures-Dz6GjF-3.mjs → discoverRlsProcedures-CUfhUqfY.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as l}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as f,declarationLineOf as u,findObjectProperty as p}from"./isTestPath-DJeZ18i9.mjs";import{j as d,h as m}from"./attribution-
|
|
1
|
+
import{Node as l}from"ts-morph";import{listLunoraSourceFiles as c,lunoraRelativePath as f,declarationLineOf as u,findObjectProperty as p}from"./isTestPath-DJeZ18i9.mjs";import{j as d,h as m}from"./attribution-B8xa6AeK.mjs";import{t as b}from"./database-calls-Cug60vT9.mjs";import{c as h}from"./classify-procedure-call-BK_MMoue.mjs";import{r as y,p as v}from"./policies-CrNWTJQi.mjs";const P=e=>{const s=[];for(const r of v(e)){const t=p(r,"table");if(!t||!l.isPropertyAssignment(t))continue;const i=t.getInitializer();i&&l.isStringLiteral(i)&&s.push(i.getLiteralText())}return s},T=e=>{const s=y(e);return{rlsTables:s.flatMap(r=>P(r)),usesRls:s.length>0}},g=new Set(["explain","findFirst","findFirstOrThrow","findMany","get","query"]),R=new Set(["delete","deleteMany","insert","insertMany","patch","patchIf","patchMany","replace"]),x=(e,s)=>{if(!l.isVariableDeclaration(e))return;const r=e.getInitializer();if(!r||!l.isCallExpression(r))return;const t=h(r);if(!t)return;const i=t.receiver?T(t.receiver):{rlsTables:[],usesRls:!1},{tablesRead:o,tablesWritten:a}=b(e,g,R);return{exportName:m(e)??e.getName(),file:s,line:u(e),rlsTables:i.rlsTables,tablesRead:o,tablesWritten:a,usesRls:i.usesRls,visibility:t.visibility}},D=(e,s)=>{const r=[];for(const t of c(s)){const i=e.getSourceFile(t)??e.addSourceFileAtPath(t),o=f(s,t);for(const a of d(i)){const n=x(a,o);n&&r.push(n)}}return r};export{D as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as u}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as p,stringPropertyOf as l}from"./isTestPath-DJeZ18i9.mjs";import{w as d}from"./classify-procedure-call-BK_MMoue.mjs";import{e as m}from"./exported-procedure-chains-
|
|
1
|
+
import{Node as u}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as p,stringPropertyOf as l}from"./isTestPath-DJeZ18i9.mjs";import{w as d}from"./classify-procedure-call-BK_MMoue.mjs";import{e as m}from"./exported-procedure-chains-ej9ozyZB.mjs";const h=new Set(["delete","list","read","write"]),g=t=>d(t,"use","storageRules"),x=(t,s,n)=>{const e=t.getArguments()[0];if(!e||!u.isArrayLiteralExpression(e))return[];const i=[];for(const o of e.getElements()){if(!u.isObjectLiteralExpression(o))continue;const r=l(o,"on");if(r===void 0||!h.has(r))continue;const a=l(o,"prefix"),c={bucket:l(o,"bucket")??"",file:s,on:r,procedure:n};a!==void 0&&(c.prefix=a),i.push(c)}return i},A=(t,s)=>{const n=[];for(const e of f(s)){const i=t.getSourceFile(e)??t.addSourceFileAtPath(e),o=p(s,e);for(const{name:r,receiver:a}of m(i))for(const c of g(a))n.push(...x(c,o,r))}return{rules:n}};export{A as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as s}from"ts-morph";import{j as t,h as c}from"./attribution-
|
|
1
|
+
import{Node as s}from"ts-morph";import{j as t,h as c}from"./attribution-B8xa6AeK.mjs";import{c as n}from"./classify-procedure-call-BK_MMoue.mjs";const m=a=>{const i=[];for(const e of t(a)){const r=e.getInitializer(),o=r&&s.isCallExpression(r)?n(r):void 0;o?.receiver&&i.push({name:c(e)??e.getName(),receiver:o.receiver})}return i};export{m as e};
|
package/dist/packem_shared/{handler-reference-T5OJcVXW.mjs → handler-reference-_zhtPddp.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{dirname as F}from"node:path";import{Node as e}from"ts-morph";import{unwrapExpression as m,lunoraRelativePath as u}from"./isTestPath-DJeZ18i9.mjs";import{r as v,h}from"./attribution-
|
|
1
|
+
import{dirname as F}from"node:path";import{Node as e}from"ts-morph";import{unwrapExpression as m,lunoraRelativePath as u}from"./isTestPath-DJeZ18i9.mjs";import{r as v,h}from"./attribution-B8xa6AeK.mjs";const b=i=>e.isPropertyAssignment(i)?m(i.getInitializer()):e.isShorthandPropertyAssignment(i)?i.getNameNode():void 0,A=(i,s)=>{const o=i===void 0?void 0:b(i);if(o===void 0||!e.isIdentifier(o))return;const a=v(o),g=a?.getAliasedSymbol()??a;for(const t of g?.getDeclarations()??[]){const n=e.isVariableDeclaration(t)?m(t.getInitializer()):t;if(!(e.isFunctionDeclaration(n)||e.isArrowFunction(n)||e.isFunctionExpression(n))||!(e.isFunctionDeclaration(t)||e.isVariableDeclaration(t)))continue;const r=t.getSourceFile(),c=u(s,r.getFilePath()),l=!c.startsWith("../"),d=l?c:u(F(s),r.getFilePath()),f=h(t);return{body:n,...r===o.getSourceFile()?{}:{file:d},...l&&f!==void 0?{site:{exportName:f,file:d}}:{}}}};export{A as r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as g}from"@lunora/errors";import{Node as s,SyntaxKind as B}from"ts-morph";import{d as z}from"./declared-output-Iaar469J.mjs";import{findObjectProperty as h,bindingKeyName as H,listLunoraSourceFiles as M,lunoraRelativePath as W}from"./isTestPath-DJeZ18i9.mjs";import{e as K,i as O}from"./attribution-CbD9hCjb.mjs";import{u as R,p as q,r as Y,c as w,a as G}from"./unwrap-handler-return-BnsKyz9W.mjs";import{m as J}from"./ip-reads-Du9jIYHJ.mjs";import{b as L,s as X,c as Q}from"./classify-procedure-call-BK_MMoue.mjs";import{r as D,p as C,a as Z}from"./parse-validator-BisfC8bR.mjs";import{N as ee,l as te}from"./project-config-file-DR7xrrNB.mjs";import{s as ie}from"./dispatch-namespace-DwTjD7BU.mjs";const I=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,ne=e=>{const i=e.getArguments()[0],t=I(i);if(t!==void 0)return t;if(i===void 0||!s.isObjectLiteralExpression(i))return;const n=h(i,"handler");return n!==void 0&&s.isPropertyAssignment(n)?I(n.getInitializer()):void 0},re=e=>{const i=e.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return"unknown";const t=h(i,"handler");if(!t||!s.isPropertyAssignment(t))return"unknown";const n=t.getInitializer();return!n||!(s.isArrowFunction(n)||s.isFunctionExpression(n))?"unknown":R(n)},oe=e=>{const i=e.getArguments()[0];return!i||!(s.isArrowFunction(i)||s.isFunctionExpression(i))?"unknown":R(i)},se=e=>{let i={};for(const t of L(e)){if(t.name!=="input")continue;const n=t.call.getArguments()[0],o=n!==void 0&&s.isExpression(n)?D(n):void 0;o!==void 0&&(i={...C(o),...i})}return i},ae=e=>{const i=L(e).find(n=>n.name==="output");if(!i)return;const t=i.call.getArguments()[0];return t&&s.isExpression(t)?q(i.call,()=>Z(t)):void 0},E=(e,i)=>{const t=h(e,i);if(t===void 0||!s.isPropertyAssignment(t))return;const n=t.getInitializer();return n!==void 0&&s.isStringLiteral(n)?n.getLiteralValue():void 0},k=(e,i)=>{const t=h(e,i);if(t===void 0||!s.isPropertyAssignment(t))return;const n=t.getInitializer();return n!==void 0&&s.isNumericLiteral(n)?n.getLiteralValue():void 0},ce=e=>{const i=h(e,"cache");if(i===void 0||!s.isPropertyAssignment(i))return;const t=i.getInitializer();if(t===void 0||!s.isObjectLiteralExpression(t))return;const n=E(t,"scope"),o=k(t,"maxAge"),r=k(t,"staleWhileRevalidate"),a=E(t,"tag"),c=E(t,"vary"),l={...o===void 0?{}:{maxAge:o},...n==="private"||n==="public"?{scope:n}:{},...r===void 0?{}:{staleWhileRevalidate:r},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},le=e=>{if(e===void 0||!s.isObjectLiteralExpression(e))return{};const i=ce(e),t=h(e,"rest");return t!==void 0&&s.isPropertyAssignment(t)?{...i===void 0?{}:{cache:i},rest:t.getInitializer()?.getText()==="true"}:i===void 0?{}:{cache:i}},ue=e=>{const i=L(e).find(t=>t.name==="expose");return i?le(i.call.getArguments()[0]):void 0},de=e=>{const i=L(e).find(r=>r.name==="x402");if(!i)return;const t=i.call.getArguments()[0];if(t===void 0||!s.isObjectLiteralExpression(t))return{};const n=h(t,"price");if(n===void 0||!s.isPropertyAssignment(n))return{};const o=n.getInitializer();return o===void 0?{}:s.isStringLiteral(o)?{price:o.getLiteralValue()}:s.isNumericLiteral(o)?{price:o.getLiteralValue()}:{}},ge=e=>{const i=e.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return{};const t=h(i,"args");if(!t||!s.isPropertyAssignment(t))return{};const n=t.getInitializer(),o=n===void 0?void 0:D(n);return o===void 0?{}:C(o)},f=(e,i)=>{throw new g("INTERNAL",`@lunora/codegen: lazy function registry needs literal ${i} in ${e.getSourceFile().getFilePath()}:${String(e.getStartLineNumber())}`)},S=(e,i,t)=>{if(!e||!s.isObjectLiteralExpression(e))return f(i,"metadata objects");const n=new Set;for(const o of e.getProperties()){if(!s.isPropertyAssignment(o))return f(o,"metadata fields without spreads, getters, or shorthand");const r=o.getNameNode(),a=s.isStringLiteral(r)?r.getLiteralValue():r.getText();if(!s.isIdentifier(r)&&!s.isStringLiteral(r)||!t.includes(a)||n.has(a))return f(o,"supported, unique metadata fields");n.add(a)}return e},y=(e,i)=>{const t=e.getProperty(i);return t&&s.isPropertyAssignment(t)?t.getInitializer():void 0},pe=e=>{const i=S(e,e,["credentialHeaders","maxAge","scope","staleWhileRevalidate","tag","vary"]),t={};for(const r of["maxAge","staleWhileRevalidate"]){const a=y(i,r);if(!(a===void 0&&r!=="maxAge")){if(!a||!s.isNumericLiteral(a))return f(e,`cache.${r}`);t[r]=a.getLiteralValue()}}const n=y(i,"scope");if(!n||!s.isStringLiteral(n)||!["private","public"].includes(n.getLiteralValue()))return f(e,"cache.scope");t.scope=n.getLiteralValue();for(const r of["tag","vary"]){const a=y(i,r);if(a!==void 0){if(!s.isStringLiteral(a))return f(a,`cache.${r}`);t[r]=a.getLiteralValue()}}const o=y(i,"credentialHeaders");if(o!==void 0){if(!s.isArrayLiteralExpression(o))return f(o,"cache.credentialHeaders");t.credentialHeaders=o.getElements().map(r=>s.isStringLiteral(r)?r.getLiteralValue():f(r,"cache.credentialHeaders string entries"))}return t},fe=e=>{const i=S(e.getArguments()[0],e,["rest","cache"]),t=y(i,"rest"),n=y(i,"cache");return t!==void 0&&!s.isTrueLiteral(t)&&!s.isFalseLiteral(t)?f(t,".expose({ rest })"):{...t?{rest:s.isTrueLiteral(t)}:{},...n?{cache:pe(n)}:{}}},me=e=>{const i=S(e.getArguments()[0],e,["price"]),t=y(i,"price");return!t||!s.isStringLiteral(t)&&!s.isNumericLiteral(t)?f(e,"`.x402({ price })` value"):{price:t.getLiteralValue()}},he=e=>{const i=e.map(o=>{const r=o.getArguments()[0];return r===void 0?ee:te(r)}),t=i.every(o=>o!==null&&typeof o=="object"&&!Array.isArray(o)),n=i.reduce((o,r)=>({...r,...o}),{});return t?n:"unloaded"},ye=e=>{const{factory:i,steps:t}=X(e);if(!i)return f(e,"metadata from a resolvable Lunora factory root");const n={visibility:i.startsWith("internal")?"internal":"public"};for(const{call:r,name:a}of t){if(!["expose","input","meta","output","use","x402"].includes(a))return f(r,`known builder modifiers, got .${a}()`);a==="expose"&&n.expose===void 0&&(n.expose=fe(r)),a==="x402"&&n.x402===void 0&&(n.x402=me(r))}const o=t.filter(r=>r.name==="meta").map(r=>r.call);return o.length===0?n:{...n,meta:he(o)}},ve=new Set(["action","mutation","query","stream"]),N=(e,i,t)=>{const n=e.getProperty(i)?.getTypeAtLocation(t);if(n===void 0)return;const o=n.isUnion()?n.getUnionTypes().filter(a=>!a.isUndefined()):[n],r=o.length===1?o[0]?.getLiteralValue():void 0;return typeof r=="string"?r:void 0},U=(e,i)=>{const t=N(e,"kind",i);return t!==void 0&&ve.has(t)&&e.getProperty("handler")!==void 0?t:void 0},be=e=>{const i=e.getParent();if(s.isPropertyAccessExpression(i)&&i.getExpression()===e)return i.getName()==="functions";if(s.isElementAccessExpression(i)&&i.getExpression()===e){const n=i.getArgumentExpression();return n!==void 0&&s.isStringLiteral(n)&&n.getLiteralValue()==="functions"}const t=s.isVariableDeclaration(i)&&i.getNameNode()!==e?i.getNameNode():void 0;return t!==void 0&&s.isObjectBindingPattern(t)&&t.getElements().some(n=>(n.getPropertyNameNode()?.getText()??n.getName())==="functions")},it=(e,i)=>{for(const t of e)for(const n of t.getVariableDeclarations()){const o=n.getNameNode();if(!n.isExported()||!s.isIdentifier(o))continue;const a=(n.getType().getProperty("functions")?.getTypeAtLocation(n)?.getProperties()??[]).filter(u=>U(u.getTypeAtLocation(n),n)!==void 0);if(a.length===0||o.findReferencesAsNodes().some(u=>be(u)))continue;const l=n.getName(),d=a.map(u=>u.getName()).join(", ");console.warn(`@lunora/codegen: ${i(t)}:${l} ships functions (${d}) that nothing re-exports, so none is in the generated api. Add \`export const { ${d} } = ${l}.functions;\` (or export your own wrappers of them).`)}},Ne=new Set(["connect","disconnect","init","reactor","whisper"]),Le={ArrayBuffer:"bytes",GeoPoint:"geoPoint"},Ae=8,P=(e,i)=>{const t=e.getText(i);return t===""?{kind:"from"}:{kind:"from",tsType:t}},Ee=new Set(["false","true"]),Pe=[[e=>e.isAny()||e.isUnknown(),"any"],[e=>e.isString(),"string"],[e=>e.isNumber(),"number"],[e=>e.isBoolean(),"boolean"],[e=>e.isNull(),"null"],[e=>e.isBigInt(),"bigint"]],Te=(e,i,t)=>{if(!e.isObject()||e.isIntersection()||e.getCallSignatures().length>0||e.isClass())return;const n=e.getProperties();if(n.some(r=>r.getTypeAtLocation(i).getCallSignatures().length>0))return;const o=e.getStringIndexType();if(o!==void 0&&n.length===0)return{keyType:{kind:"string"},kind:"record",valueType:b(o,i,t+1)};if(!(o!==void 0||n.length===0))return{kind:"object",shape:Object.fromEntries(n.map(r=>[r.getName(),$(r.getTypeAtLocation(i),r.isOptional(),i,t+1)]))}},b=(e,i,t)=>{if(t>Ae)return P(e,i);const n=Pe.find(([a])=>a(e));if(n!==void 0)return{kind:n[1]};const o=Le[(e.getSymbol()??e.getAliasSymbol())?.getName()??""];if(o!==void 0)return{kind:o};if(e.isStringLiteral()||e.isNumberLiteral()||e.isBooleanLiteral()||e.isBigIntLiteral())return{kind:"literal",literalValue:e.getText(i),sensitive:!0};const r=e.isIntersection()?N(e,"__table",i):void 0;if(r!==void 0)return{kind:"id",tableName:r};if(e.isUnion())return F(e.getUnionTypes(),i,t);if(e.isArray()){const a=e.getArrayElementType();return a===void 0?P(e,i):{inner:b(a,i,t+1),kind:"array"}}return Te(e,i,t)??P(e,i)},F=(e,i,t)=>{const o=new Set(e.filter(l=>l.isBooleanLiteral()).map(l=>l.getText(i))).size===Ee.size,r=e.filter(l=>!(o&&l.isBooleanLiteral())).map(l=>b(l,i,t+1)),a=o?[...r,{kind:"boolean"}]:r,[c]=a;return a.length===1&&c!==void 0?c:{kind:"union",members:a}},$=(e,i,t,n)=>{const o=e.isUnion()?e.getUnionTypes():[e],r=o.filter(l=>!l.isUndefined());if(!i&&r.length===o.length)return b(e,t,n);if(r.length===0)return{inner:{kind:"any"},kind:"optional"};const[a]=r;return{inner:r.length===1&&a!==void 0?b(a,t,n):F(r,t,n),kind:"optional"}},xe=(e,i)=>{const t=e.getProperty("__type")?.getTypeAtLocation(i);if(t===void 0)return{kind:"from"};const n=(e.getSymbol()??e.getAliasSymbol())?.getName();return n==="TimestampColumnValidator"?{kind:"timestamp"}:n==="ObjectColumnValidator"&&t.getProperties().length===0?{kind:"object",shape:{}}:$(t,!1,i,0)},Se=new Set(["AsyncGenerator","AsyncIterable","AsyncIterableIterator"]),Oe=(e,i)=>{const t=e.getProperty("handler")?.getTypeAtLocation(i).getCallSignatures()[0]?.getReturnType();if(t===void 0)return[];if(Se.has((t.getSymbol()??t.getAliasSymbol())?.getName()??"")){const[n]=t.getTypeArguments();return n===void 0?[]:[n]}return(t.isUnion()?t.getUnionTypes():[t]).map(n=>n.getSymbol()?.getName()==="Promise"?n.getTypeArguments()[0]??n:n)},we=(e,i)=>{const t=[...new Set(e.map(n=>Y(n,i)))];return t.length===0||t.includes("unknown")?"unknown":t.join(" | ")},Ie=(e,i,t,n)=>{const o=e.getType(),r=U(o,e);if(r===void 0)return;const a={...n?{description:n}:{},exportName:i,filePath:t,kind:r};if(o.getProperty("channel")?.isOptional()===!1)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a room from a published package; its name is not in the declared type, so codegen cannot route it. Declare the room with \`defineRoom\` in this file instead.`);const c=N(o,"lifecycle",e),l=o.getProperty("lifecycle");if(c===void 0&&l!==void 0&&!l.isOptional())throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a lifecycle hook from a published package whose type does not say which moment it runs at. Declare it with its moment, e.g. \`RegisteredLifecycleHook & { readonly lifecycle: "disconnect" }\` (what \`onDisconnect\` returns).`);if(c!==void 0){if(!Ne.has(c))throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a "${c}" lifecycle hook from a published package; only a locally declared hook can carry its route. Declare it in this file instead.`);return{...a,args:{},lifecycle:c,returnType:"void",visibility:"internal"}}const d=N(o,"visibility",e);if(d!=="internal"&&d!=="public")throw new g("PUBLISHED_FUNCTION_VISIBILITY_UNKNOWN",`${t}:${i} re-exports a function from a published package whose type does not say whether it is internal or public. Declare it in that package as \`RegisteredQuery\` / \`RegisteredMutation\` / \`RegisteredAction\` (public) or their \`RegisteredInternal*\` counterparts, not the bare \`RegisteredFunction\`, so codegen does not list an internal function in the client \`api\`.`);if(d==="internal"&&o.getProperty("visibility")?.isOptional()!==!1)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports an internal function from a published package whose type makes \`visibility\` optional, so the value may not carry it. Declare it with a \`RegisteredInternal*\` type, which requires \`visibility: "internal"\`.`);const u=o.getProperty("args")?.getTypeAtLocation(e);if(u===void 0||u.isAny()||u.isUnknown()||u.getStringIndexType()!==void 0||u.getNumberIndexType()!==void 0)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a function from a published package whose type does not list its arguments. Declare its validator map with one key per argument (an empty \`{}\` for none) so codegen can type the client call.`);const m=Object.fromEntries(u.getProperties().map(p=>[p.getName(),xe(p.getTypeAtLocation(e),e)]));return{...a,args:m,...r==="query"?{readsIp:!0}:{},returnType:we(Oe(o,e),e),typeDerivedArgs:!0,visibility:d}},ke=8,A=(e,i=0)=>{if(i>ke)return;if(s.isCallExpression(e))return{call:e};if(s.isParenthesizedExpression(e)||s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isNonNullExpression(e))return A(e.getExpression(),i+1);if(!s.isIdentifier(e)&&!s.isPropertyAccessExpression(e))return;const t=e.getSymbol()?.getValueDeclaration();return t?T(t,i+1):void 0},T=(e,i)=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e)){const t=e.getInitializer();return t?A(t,i):{deadEnd:e}}if(s.isShorthandPropertyAssignment(e)){const t=e.getValueSymbol()?.getValueDeclaration();return t?T(t,i+1):void 0}if(s.isBindingElement(e)){const t=H(e),r=e.getFirstAncestorByKind(B.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return r?T(r,i+1):void 0}return{deadEnd:e}},x=e=>{const i=A(e);return i!==void 0&&"call"in i?i.call:void 0},_=e=>{const i=A(e);return i!==void 0&&"deadEnd"in i&&i.deadEnd.getSourceFile().isDeclarationFile()},_e=(e,i=()=>!0)=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t)){const r=[];for(const a of t.getElements().filter(c=>i(c.getName()))){const c=x(a.getNameNode());c&&r.push([a.getName(),c])}return r}if(!i(e.getName()))return[];const n=e.getInitializer(),o=n&&(s.isCallExpression(n)?n:x(n));return o?[[e.getName(),o]]:[]},Re=(e,i)=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t))return t.getElements().filter(o=>i(o.getName())&&_(o.getNameNode())).map(o=>[o.getName(),o.getNameNode()]);const n=e.getInitializer();return i(e.getName())&&n!==void 0&&_(n)?[[e.getName(),t]]:[]},De=e=>{const i=e.getArguments()[0],t=s.isObjectLiteralExpression(i)?i.getProperty("name"):void 0,n=s.isPropertyAssignment(t)?t.getInitializer():void 0;if(!n||!s.isStringLiteral(n))throw new g("ROOM_NAME_NOT_LITERAL",'defineRoom needs a string-literal `name` (e.g. `defineRoom({ name: "chat", … })`) so codegen can type its reference.');return n.getLiteralValue()},Ce=e=>e.startsWith("/")&&new URL(e,"https://lunora.invalid").pathname===e&&e!=="/_lunora"&&!e.startsWith("/_lunora/"),Ue=e=>{const i=e.getArguments()[0];if(!s.isObjectLiteralExpression(i))throw new g("SOCKET_PATH_NOT_LITERAL","defineWebSocket needs an object-literal options argument so codegen can read its `path` and `auth`.");const t=i.getProperty("path"),n=s.isPropertyAssignment(t)?t.getInitializer():void 0;if(!n||!s.isStringLiteral(n))throw new g("SOCKET_PATH_NOT_LITERAL",'defineWebSocket needs a string-literal `path` (e.g. `defineWebSocket({ path: "/chat", … })`) so codegen can route its upgrade.');const o=n.getLiteralValue();if(!Ce(o))throw new g("SOCKET_PATH_INVALID",`defineWebSocket path "${o}" must be a plain URL path starting with "/" (no "?", "#", ".." or unencoded characters) and not under "/_lunora".`);if(i.getProperties().some(l=>s.isSpreadAssignment(l)||s.isPropertyAssignment(l)&&s.isComputedPropertyName(l.getNameNode())))throw new g("SOCKET_AUTH_NOT_LITERAL","defineWebSocket cannot spread its options or use a computed key: codegen must read `auth` as a literal `auth: true` or `auth: false`.");const a=i.getProperty("auth");if(a===void 0)return{auth:!1,path:o};const c=s.isPropertyAssignment(a)?a.getInitializer():void 0;if(c===void 0||!(s.isTrueLiteral(c)||s.isFalseLiteral(c)))throw new g("SOCKET_AUTH_NOT_LITERAL","defineWebSocket needs a literal `auth: true` or `auth: false`, so codegen can read whether the route requires a session. A shorthand or a variable is not read.");return{auth:s.isTrueLiteral(c),path:o}},Fe=(e,i,t,n)=>{const o=n?ye(i):void 0,r=n?o?.expose:ue(i),a=n?o?.x402:de(i),c=w(()=>ae(i)),l=w(()=>oe(e)),d=z({kind:t.kind,output:c.value});return G(d?c.erased:l.erased),{args:se(i),...r?{expose:r}:{},...a?{x402:a}:{},...o?.meta===void 0?{}:{meta:o.meta},...t.adminOnly?{adminOnly:!0}:{},kind:t.kind,...c.value?{output:c.value}:{},returnType:l.value,visibility:o?.visibility==="internal"||t.visibility==="internal"?"internal":"public"}},$e=(e,i)=>{const t=Q(e,i);if(!t)return;if(t.channel)return{args:{},channel:{kind:t.channel,name:De(e)},kind:t.kind,returnType:"void",visibility:t.visibility};const{receiver:n}=t;return n?Fe(e,n,t,i):t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",...t.lifecycle==="socket"?{socket:{...Ue(e),origin:`${e.getSourceFile().getFilePath()}@${String(e.getStart())}`}}:{},visibility:t.visibility}:{args:ge(e),kind:t.kind,returnType:re(e),visibility:t.visibility}},V=e=>{const i=e?.getJsDocs().at(-1)?.getDescription().trim();return i===""?void 0:i},Ve=e=>V(e.getFirstAncestor(i=>s.isVariableStatement(i))),je=e=>{const i=new Map;for(const t of e.getVariableStatements())if(t.isExported())for(const n of t.getDeclarations())i.has(n.getName())||i.set(n.getName(),t);return t=>V(i.get(t))},j=(e,i,t,n,o)=>{const r=$e(e,n);if(!r)return;const a=o??Ve(e);return{args:r.args,...a?{description:a}:{},exportName:i,filePath:t,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},...r.meta===void 0?{}:{meta:r.meta},visibility:r.visibility,...r.adminOnly?{adminOnly:!0}:{},...r.kind==="query"&&(ne(e)===void 0||J(e))?{readsIp:!0}:{},...r.expose?{expose:r.expose}:{},...r.x402?{x402:r.x402}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{},...r.channel?{channel:r.channel}:{},...r.socket?{socket:r.socket}:{}}},Be=(e,i,t)=>{const n=[];for(const o of e.getExportAssignments()){if(o.isExportEquals())continue;const r=x(o.getExpression()),a=r?j(r,"default",i,t):void 0;r&&a&&n.push({call:r,entry:a})}return n},ze=(e,i,t)=>{const n=K(e),o=je(e),r=new Map,a=(d,u)=>{if(d?.channel?.kind!=="room")return;const m=r.get(d.channel.name);if(m!==void 0&&m!==u)throw new g("DUPLICATE_ROOM_NAME",`Duplicate room name "${d.channel.name}" in ${i}: two defineRoom calls share it. Room names must be unique.`);r.set(d.channel.name,u)},c=e.getVariableStatements().flatMap(d=>d.getDeclarations()).flatMap(d=>_e(d,u=>n.has(u))).flatMap(([d,u])=>(n.get(d)??[]).filter(m=>O(m)).flatMap(m=>{const p=j(u,m,i,t,o(m));return a(p,u),p?[p]:[]})),l=new Set(c.map(d=>d.exportName));for(const d of e.getVariableStatements().flatMap(u=>u.getDeclarations()))for(const[u,m]of Re(d,p=>n.has(p)))for(const p of(n.get(u)??[]).filter(v=>O(v)&&!l.has(v))){const v=Ie(m,p,i,o(p));v&&(c.push(v),l.add(p))}for(const{call:d,entry:u}of Be(e,i,t))l.has(u.exportName)||(a(u,d),c.push(u));return c},He=e=>{const i=new Map;for(const t of e){if(t.channel?.kind!=="room")continue;const n=i.get(t.channel.name);if(n!==void 0&&n.file!==t.filePath)throw new g("DUPLICATE_ROOM_NAME",`Duplicate room name "${t.channel.name}": defined in ${n.origin} and ${t.filePath}:${t.exportName}. Room names must be unique across the project.`);n===void 0&&i.set(t.channel.name,{file:t.filePath,origin:`${t.filePath}:${t.exportName}`})}},Me=e=>{const i=new Map;for(const t of e){const n=ie(t.filePath),o=i.get(n);if(o&&o!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${o}" and "${t.filePath}" both resolve to "${n}". 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:[o,t.filePath],status:500});i.set(n,t.filePath)}},nt=(e,i,t={})=>{const n=M(i),o=[];for(const r of n){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=W(i,r);o.push(...ze(a,c,t.lazyFunctions===!0))}return o.sort((r,a)=>`${r.filePath}:${r.exportName}`.localeCompare(`${a.filePath}:${a.exportName}`)),Me(o),He(o),o};export{nt as d,I as i,ne as p,it as w};
|
|
1
|
+
import{LunoraError as g}from"@lunora/errors";import{Node as s,SyntaxKind as B}from"ts-morph";import{d as z}from"./declared-output-Iaar469J.mjs";import{findObjectProperty as h,bindingKeyName as H,listLunoraSourceFiles as M,lunoraRelativePath as W}from"./isTestPath-DJeZ18i9.mjs";import{e as K,i as O}from"./attribution-B8xa6AeK.mjs";import{u as R,p as q,r as Y,c as w,a as G}from"./unwrap-handler-return-BnsKyz9W.mjs";import{m as J}from"./ip-reads-D8rPYtZ6.mjs";import{b as L,s as X,c as Q}from"./classify-procedure-call-BK_MMoue.mjs";import{r as D,p as C,a as Z}from"./parse-validator-BisfC8bR.mjs";import{N as ee,l as te}from"./project-config-file-DR7xrrNB.mjs";import{s as ie}from"./dispatch-namespace-DwTjD7BU.mjs";const I=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,ne=e=>{const i=e.getArguments()[0],t=I(i);if(t!==void 0)return t;if(i===void 0||!s.isObjectLiteralExpression(i))return;const n=h(i,"handler");return n!==void 0&&s.isPropertyAssignment(n)?I(n.getInitializer()):void 0},re=e=>{const i=e.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return"unknown";const t=h(i,"handler");if(!t||!s.isPropertyAssignment(t))return"unknown";const n=t.getInitializer();return!n||!(s.isArrowFunction(n)||s.isFunctionExpression(n))?"unknown":R(n)},oe=e=>{const i=e.getArguments()[0];return!i||!(s.isArrowFunction(i)||s.isFunctionExpression(i))?"unknown":R(i)},se=e=>{let i={};for(const t of L(e)){if(t.name!=="input")continue;const n=t.call.getArguments()[0],o=n!==void 0&&s.isExpression(n)?D(n):void 0;o!==void 0&&(i={...C(o),...i})}return i},ae=e=>{const i=L(e).find(n=>n.name==="output");if(!i)return;const t=i.call.getArguments()[0];return t&&s.isExpression(t)?q(i.call,()=>Z(t)):void 0},E=(e,i)=>{const t=h(e,i);if(t===void 0||!s.isPropertyAssignment(t))return;const n=t.getInitializer();return n!==void 0&&s.isStringLiteral(n)?n.getLiteralValue():void 0},k=(e,i)=>{const t=h(e,i);if(t===void 0||!s.isPropertyAssignment(t))return;const n=t.getInitializer();return n!==void 0&&s.isNumericLiteral(n)?n.getLiteralValue():void 0},ce=e=>{const i=h(e,"cache");if(i===void 0||!s.isPropertyAssignment(i))return;const t=i.getInitializer();if(t===void 0||!s.isObjectLiteralExpression(t))return;const n=E(t,"scope"),o=k(t,"maxAge"),r=k(t,"staleWhileRevalidate"),a=E(t,"tag"),c=E(t,"vary"),l={...o===void 0?{}:{maxAge:o},...n==="private"||n==="public"?{scope:n}:{},...r===void 0?{}:{staleWhileRevalidate:r},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},le=e=>{if(e===void 0||!s.isObjectLiteralExpression(e))return{};const i=ce(e),t=h(e,"rest");return t!==void 0&&s.isPropertyAssignment(t)?{...i===void 0?{}:{cache:i},rest:t.getInitializer()?.getText()==="true"}:i===void 0?{}:{cache:i}},ue=e=>{const i=L(e).find(t=>t.name==="expose");return i?le(i.call.getArguments()[0]):void 0},de=e=>{const i=L(e).find(r=>r.name==="x402");if(!i)return;const t=i.call.getArguments()[0];if(t===void 0||!s.isObjectLiteralExpression(t))return{};const n=h(t,"price");if(n===void 0||!s.isPropertyAssignment(n))return{};const o=n.getInitializer();return o===void 0?{}:s.isStringLiteral(o)?{price:o.getLiteralValue()}:s.isNumericLiteral(o)?{price:o.getLiteralValue()}:{}},ge=e=>{const i=e.getArguments()[0];if(!i||!s.isObjectLiteralExpression(i))return{};const t=h(i,"args");if(!t||!s.isPropertyAssignment(t))return{};const n=t.getInitializer(),o=n===void 0?void 0:D(n);return o===void 0?{}:C(o)},f=(e,i)=>{throw new g("INTERNAL",`@lunora/codegen: lazy function registry needs literal ${i} in ${e.getSourceFile().getFilePath()}:${String(e.getStartLineNumber())}`)},S=(e,i,t)=>{if(!e||!s.isObjectLiteralExpression(e))return f(i,"metadata objects");const n=new Set;for(const o of e.getProperties()){if(!s.isPropertyAssignment(o))return f(o,"metadata fields without spreads, getters, or shorthand");const r=o.getNameNode(),a=s.isStringLiteral(r)?r.getLiteralValue():r.getText();if(!s.isIdentifier(r)&&!s.isStringLiteral(r)||!t.includes(a)||n.has(a))return f(o,"supported, unique metadata fields");n.add(a)}return e},y=(e,i)=>{const t=e.getProperty(i);return t&&s.isPropertyAssignment(t)?t.getInitializer():void 0},pe=e=>{const i=S(e,e,["credentialHeaders","maxAge","scope","staleWhileRevalidate","tag","vary"]),t={};for(const r of["maxAge","staleWhileRevalidate"]){const a=y(i,r);if(!(a===void 0&&r!=="maxAge")){if(!a||!s.isNumericLiteral(a))return f(e,`cache.${r}`);t[r]=a.getLiteralValue()}}const n=y(i,"scope");if(!n||!s.isStringLiteral(n)||!["private","public"].includes(n.getLiteralValue()))return f(e,"cache.scope");t.scope=n.getLiteralValue();for(const r of["tag","vary"]){const a=y(i,r);if(a!==void 0){if(!s.isStringLiteral(a))return f(a,`cache.${r}`);t[r]=a.getLiteralValue()}}const o=y(i,"credentialHeaders");if(o!==void 0){if(!s.isArrayLiteralExpression(o))return f(o,"cache.credentialHeaders");t.credentialHeaders=o.getElements().map(r=>s.isStringLiteral(r)?r.getLiteralValue():f(r,"cache.credentialHeaders string entries"))}return t},fe=e=>{const i=S(e.getArguments()[0],e,["rest","cache"]),t=y(i,"rest"),n=y(i,"cache");return t!==void 0&&!s.isTrueLiteral(t)&&!s.isFalseLiteral(t)?f(t,".expose({ rest })"):{...t?{rest:s.isTrueLiteral(t)}:{},...n?{cache:pe(n)}:{}}},me=e=>{const i=S(e.getArguments()[0],e,["price"]),t=y(i,"price");return!t||!s.isStringLiteral(t)&&!s.isNumericLiteral(t)?f(e,"`.x402({ price })` value"):{price:t.getLiteralValue()}},he=e=>{const i=e.map(o=>{const r=o.getArguments()[0];return r===void 0?ee:te(r)}),t=i.every(o=>o!==null&&typeof o=="object"&&!Array.isArray(o)),n=i.reduce((o,r)=>({...r,...o}),{});return t?n:"unloaded"},ye=e=>{const{factory:i,steps:t}=X(e);if(!i)return f(e,"metadata from a resolvable Lunora factory root");const n={visibility:i.startsWith("internal")?"internal":"public"};for(const{call:r,name:a}of t){if(!["expose","input","meta","output","use","x402"].includes(a))return f(r,`known builder modifiers, got .${a}()`);a==="expose"&&n.expose===void 0&&(n.expose=fe(r)),a==="x402"&&n.x402===void 0&&(n.x402=me(r))}const o=t.filter(r=>r.name==="meta").map(r=>r.call);return o.length===0?n:{...n,meta:he(o)}},ve=new Set(["action","mutation","query","stream"]),N=(e,i,t)=>{const n=e.getProperty(i)?.getTypeAtLocation(t);if(n===void 0)return;const o=n.isUnion()?n.getUnionTypes().filter(a=>!a.isUndefined()):[n],r=o.length===1?o[0]?.getLiteralValue():void 0;return typeof r=="string"?r:void 0},U=(e,i)=>{const t=N(e,"kind",i);return t!==void 0&&ve.has(t)&&e.getProperty("handler")!==void 0?t:void 0},be=e=>{const i=e.getParent();if(s.isPropertyAccessExpression(i)&&i.getExpression()===e)return i.getName()==="functions";if(s.isElementAccessExpression(i)&&i.getExpression()===e){const n=i.getArgumentExpression();return n!==void 0&&s.isStringLiteral(n)&&n.getLiteralValue()==="functions"}const t=s.isVariableDeclaration(i)&&i.getNameNode()!==e?i.getNameNode():void 0;return t!==void 0&&s.isObjectBindingPattern(t)&&t.getElements().some(n=>(n.getPropertyNameNode()?.getText()??n.getName())==="functions")},it=(e,i)=>{for(const t of e)for(const n of t.getVariableDeclarations()){const o=n.getNameNode();if(!n.isExported()||!s.isIdentifier(o))continue;const a=(n.getType().getProperty("functions")?.getTypeAtLocation(n)?.getProperties()??[]).filter(u=>U(u.getTypeAtLocation(n),n)!==void 0);if(a.length===0||o.findReferencesAsNodes().some(u=>be(u)))continue;const l=n.getName(),d=a.map(u=>u.getName()).join(", ");console.warn(`@lunora/codegen: ${i(t)}:${l} ships functions (${d}) that nothing re-exports, so none is in the generated api. Add \`export const { ${d} } = ${l}.functions;\` (or export your own wrappers of them).`)}},Ne=new Set(["connect","disconnect","init","reactor","whisper"]),Le={ArrayBuffer:"bytes",GeoPoint:"geoPoint"},Ae=8,P=(e,i)=>{const t=e.getText(i);return t===""?{kind:"from"}:{kind:"from",tsType:t}},Ee=new Set(["false","true"]),Pe=[[e=>e.isAny()||e.isUnknown(),"any"],[e=>e.isString(),"string"],[e=>e.isNumber(),"number"],[e=>e.isBoolean(),"boolean"],[e=>e.isNull(),"null"],[e=>e.isBigInt(),"bigint"]],Te=(e,i,t)=>{if(!e.isObject()||e.isIntersection()||e.getCallSignatures().length>0||e.isClass())return;const n=e.getProperties();if(n.some(r=>r.getTypeAtLocation(i).getCallSignatures().length>0))return;const o=e.getStringIndexType();if(o!==void 0&&n.length===0)return{keyType:{kind:"string"},kind:"record",valueType:b(o,i,t+1)};if(!(o!==void 0||n.length===0))return{kind:"object",shape:Object.fromEntries(n.map(r=>[r.getName(),$(r.getTypeAtLocation(i),r.isOptional(),i,t+1)]))}},b=(e,i,t)=>{if(t>Ae)return P(e,i);const n=Pe.find(([a])=>a(e));if(n!==void 0)return{kind:n[1]};const o=Le[(e.getSymbol()??e.getAliasSymbol())?.getName()??""];if(o!==void 0)return{kind:o};if(e.isStringLiteral()||e.isNumberLiteral()||e.isBooleanLiteral()||e.isBigIntLiteral())return{kind:"literal",literalValue:e.getText(i),sensitive:!0};const r=e.isIntersection()?N(e,"__table",i):void 0;if(r!==void 0)return{kind:"id",tableName:r};if(e.isUnion())return F(e.getUnionTypes(),i,t);if(e.isArray()){const a=e.getArrayElementType();return a===void 0?P(e,i):{inner:b(a,i,t+1),kind:"array"}}return Te(e,i,t)??P(e,i)},F=(e,i,t)=>{const o=new Set(e.filter(l=>l.isBooleanLiteral()).map(l=>l.getText(i))).size===Ee.size,r=e.filter(l=>!(o&&l.isBooleanLiteral())).map(l=>b(l,i,t+1)),a=o?[...r,{kind:"boolean"}]:r,[c]=a;return a.length===1&&c!==void 0?c:{kind:"union",members:a}},$=(e,i,t,n)=>{const o=e.isUnion()?e.getUnionTypes():[e],r=o.filter(l=>!l.isUndefined());if(!i&&r.length===o.length)return b(e,t,n);if(r.length===0)return{inner:{kind:"any"},kind:"optional"};const[a]=r;return{inner:r.length===1&&a!==void 0?b(a,t,n):F(r,t,n),kind:"optional"}},xe=(e,i)=>{const t=e.getProperty("__type")?.getTypeAtLocation(i);if(t===void 0)return{kind:"from"};const n=(e.getSymbol()??e.getAliasSymbol())?.getName();return n==="TimestampColumnValidator"?{kind:"timestamp"}:n==="ObjectColumnValidator"&&t.getProperties().length===0?{kind:"object",shape:{}}:$(t,!1,i,0)},Se=new Set(["AsyncGenerator","AsyncIterable","AsyncIterableIterator"]),Oe=(e,i)=>{const t=e.getProperty("handler")?.getTypeAtLocation(i).getCallSignatures()[0]?.getReturnType();if(t===void 0)return[];if(Se.has((t.getSymbol()??t.getAliasSymbol())?.getName()??"")){const[n]=t.getTypeArguments();return n===void 0?[]:[n]}return(t.isUnion()?t.getUnionTypes():[t]).map(n=>n.getSymbol()?.getName()==="Promise"?n.getTypeArguments()[0]??n:n)},we=(e,i)=>{const t=[...new Set(e.map(n=>Y(n,i)))];return t.length===0||t.includes("unknown")?"unknown":t.join(" | ")},Ie=(e,i,t,n)=>{const o=e.getType(),r=U(o,e);if(r===void 0)return;const a={...n?{description:n}:{},exportName:i,filePath:t,kind:r};if(o.getProperty("channel")?.isOptional()===!1)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a room from a published package; its name is not in the declared type, so codegen cannot route it. Declare the room with \`defineRoom\` in this file instead.`);const c=N(o,"lifecycle",e),l=o.getProperty("lifecycle");if(c===void 0&&l!==void 0&&!l.isOptional())throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a lifecycle hook from a published package whose type does not say which moment it runs at. Declare it with its moment, e.g. \`RegisteredLifecycleHook & { readonly lifecycle: "disconnect" }\` (what \`onDisconnect\` returns).`);if(c!==void 0){if(!Ne.has(c))throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a "${c}" lifecycle hook from a published package; only a locally declared hook can carry its route. Declare it in this file instead.`);return{...a,args:{},lifecycle:c,returnType:"void",visibility:"internal"}}const d=N(o,"visibility",e);if(d!=="internal"&&d!=="public")throw new g("PUBLISHED_FUNCTION_VISIBILITY_UNKNOWN",`${t}:${i} re-exports a function from a published package whose type does not say whether it is internal or public. Declare it in that package as \`RegisteredQuery\` / \`RegisteredMutation\` / \`RegisteredAction\` (public) or their \`RegisteredInternal*\` counterparts, not the bare \`RegisteredFunction\`, so codegen does not list an internal function in the client \`api\`.`);if(d==="internal"&&o.getProperty("visibility")?.isOptional()!==!1)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports an internal function from a published package whose type makes \`visibility\` optional, so the value may not carry it. Declare it with a \`RegisteredInternal*\` type, which requires \`visibility: "internal"\`.`);const u=o.getProperty("args")?.getTypeAtLocation(e);if(u===void 0||u.isAny()||u.isUnknown()||u.getStringIndexType()!==void 0||u.getNumberIndexType()!==void 0)throw new g("PUBLISHED_FUNCTION_UNSUPPORTED",`${t}:${i} re-exports a function from a published package whose type does not list its arguments. Declare its validator map with one key per argument (an empty \`{}\` for none) so codegen can type the client call.`);const m=Object.fromEntries(u.getProperties().map(p=>[p.getName(),xe(p.getTypeAtLocation(e),e)]));return{...a,args:m,...r==="query"?{readsIp:!0}:{},returnType:we(Oe(o,e),e),typeDerivedArgs:!0,visibility:d}},ke=8,A=(e,i=0)=>{if(i>ke)return;if(s.isCallExpression(e))return{call:e};if(s.isParenthesizedExpression(e)||s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isNonNullExpression(e))return A(e.getExpression(),i+1);if(!s.isIdentifier(e)&&!s.isPropertyAccessExpression(e))return;const t=e.getSymbol()?.getValueDeclaration();return t?T(t,i+1):void 0},T=(e,i)=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e)){const t=e.getInitializer();return t?A(t,i):{deadEnd:e}}if(s.isShorthandPropertyAssignment(e)){const t=e.getValueSymbol()?.getValueDeclaration();return t?T(t,i+1):void 0}if(s.isBindingElement(e)){const t=H(e),r=e.getFirstAncestorByKind(B.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return r?T(r,i+1):void 0}return{deadEnd:e}},x=e=>{const i=A(e);return i!==void 0&&"call"in i?i.call:void 0},_=e=>{const i=A(e);return i!==void 0&&"deadEnd"in i&&i.deadEnd.getSourceFile().isDeclarationFile()},_e=(e,i=()=>!0)=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t)){const r=[];for(const a of t.getElements().filter(c=>i(c.getName()))){const c=x(a.getNameNode());c&&r.push([a.getName(),c])}return r}if(!i(e.getName()))return[];const n=e.getInitializer(),o=n&&(s.isCallExpression(n)?n:x(n));return o?[[e.getName(),o]]:[]},Re=(e,i)=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t))return t.getElements().filter(o=>i(o.getName())&&_(o.getNameNode())).map(o=>[o.getName(),o.getNameNode()]);const n=e.getInitializer();return i(e.getName())&&n!==void 0&&_(n)?[[e.getName(),t]]:[]},De=e=>{const i=e.getArguments()[0],t=s.isObjectLiteralExpression(i)?i.getProperty("name"):void 0,n=s.isPropertyAssignment(t)?t.getInitializer():void 0;if(!n||!s.isStringLiteral(n))throw new g("ROOM_NAME_NOT_LITERAL",'defineRoom needs a string-literal `name` (e.g. `defineRoom({ name: "chat", … })`) so codegen can type its reference.');return n.getLiteralValue()},Ce=e=>e.startsWith("/")&&new URL(e,"https://lunora.invalid").pathname===e&&e!=="/_lunora"&&!e.startsWith("/_lunora/"),Ue=e=>{const i=e.getArguments()[0];if(!s.isObjectLiteralExpression(i))throw new g("SOCKET_PATH_NOT_LITERAL","defineWebSocket needs an object-literal options argument so codegen can read its `path` and `auth`.");const t=i.getProperty("path"),n=s.isPropertyAssignment(t)?t.getInitializer():void 0;if(!n||!s.isStringLiteral(n))throw new g("SOCKET_PATH_NOT_LITERAL",'defineWebSocket needs a string-literal `path` (e.g. `defineWebSocket({ path: "/chat", … })`) so codegen can route its upgrade.');const o=n.getLiteralValue();if(!Ce(o))throw new g("SOCKET_PATH_INVALID",`defineWebSocket path "${o}" must be a plain URL path starting with "/" (no "?", "#", ".." or unencoded characters) and not under "/_lunora".`);if(i.getProperties().some(l=>s.isSpreadAssignment(l)||s.isPropertyAssignment(l)&&s.isComputedPropertyName(l.getNameNode())))throw new g("SOCKET_AUTH_NOT_LITERAL","defineWebSocket cannot spread its options or use a computed key: codegen must read `auth` as a literal `auth: true` or `auth: false`.");const a=i.getProperty("auth");if(a===void 0)return{auth:!1,path:o};const c=s.isPropertyAssignment(a)?a.getInitializer():void 0;if(c===void 0||!(s.isTrueLiteral(c)||s.isFalseLiteral(c)))throw new g("SOCKET_AUTH_NOT_LITERAL","defineWebSocket needs a literal `auth: true` or `auth: false`, so codegen can read whether the route requires a session. A shorthand or a variable is not read.");return{auth:s.isTrueLiteral(c),path:o}},Fe=(e,i,t,n)=>{const o=n?ye(i):void 0,r=n?o?.expose:ue(i),a=n?o?.x402:de(i),c=w(()=>ae(i)),l=w(()=>oe(e)),d=z({kind:t.kind,output:c.value});return G(d?c.erased:l.erased),{args:se(i),...r?{expose:r}:{},...a?{x402:a}:{},...o?.meta===void 0?{}:{meta:o.meta},...t.adminOnly?{adminOnly:!0}:{},kind:t.kind,...c.value?{output:c.value}:{},returnType:l.value,visibility:o?.visibility==="internal"||t.visibility==="internal"?"internal":"public"}},$e=(e,i)=>{const t=Q(e,i);if(!t)return;if(t.channel)return{args:{},channel:{kind:t.channel,name:De(e)},kind:t.kind,returnType:"void",visibility:t.visibility};const{receiver:n}=t;return n?Fe(e,n,t,i):t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",...t.lifecycle==="socket"?{socket:{...Ue(e),origin:`${e.getSourceFile().getFilePath()}@${String(e.getStart())}`}}:{},visibility:t.visibility}:{args:ge(e),kind:t.kind,returnType:re(e),visibility:t.visibility}},V=e=>{const i=e?.getJsDocs().at(-1)?.getDescription().trim();return i===""?void 0:i},Ve=e=>V(e.getFirstAncestor(i=>s.isVariableStatement(i))),je=e=>{const i=new Map;for(const t of e.getVariableStatements())if(t.isExported())for(const n of t.getDeclarations())i.has(n.getName())||i.set(n.getName(),t);return t=>V(i.get(t))},j=(e,i,t,n,o)=>{const r=$e(e,n);if(!r)return;const a=o??Ve(e);return{args:r.args,...a?{description:a}:{},exportName:i,filePath:t,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},...r.meta===void 0?{}:{meta:r.meta},visibility:r.visibility,...r.adminOnly?{adminOnly:!0}:{},...r.kind==="query"&&(ne(e)===void 0||J(e))?{readsIp:!0}:{},...r.expose?{expose:r.expose}:{},...r.x402?{x402:r.x402}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{},...r.channel?{channel:r.channel}:{},...r.socket?{socket:r.socket}:{}}},Be=(e,i,t)=>{const n=[];for(const o of e.getExportAssignments()){if(o.isExportEquals())continue;const r=x(o.getExpression()),a=r?j(r,"default",i,t):void 0;r&&a&&n.push({call:r,entry:a})}return n},ze=(e,i,t)=>{const n=K(e),o=je(e),r=new Map,a=(d,u)=>{if(d?.channel?.kind!=="room")return;const m=r.get(d.channel.name);if(m!==void 0&&m!==u)throw new g("DUPLICATE_ROOM_NAME",`Duplicate room name "${d.channel.name}" in ${i}: two defineRoom calls share it. Room names must be unique.`);r.set(d.channel.name,u)},c=e.getVariableStatements().flatMap(d=>d.getDeclarations()).flatMap(d=>_e(d,u=>n.has(u))).flatMap(([d,u])=>(n.get(d)??[]).filter(m=>O(m)).flatMap(m=>{const p=j(u,m,i,t,o(m));return a(p,u),p?[p]:[]})),l=new Set(c.map(d=>d.exportName));for(const d of e.getVariableStatements().flatMap(u=>u.getDeclarations()))for(const[u,m]of Re(d,p=>n.has(p)))for(const p of(n.get(u)??[]).filter(v=>O(v)&&!l.has(v))){const v=Ie(m,p,i,o(p));v&&(c.push(v),l.add(p))}for(const{call:d,entry:u}of Be(e,i,t))l.has(u.exportName)||(a(u,d),c.push(u));return c},He=e=>{const i=new Map;for(const t of e){if(t.channel?.kind!=="room")continue;const n=i.get(t.channel.name);if(n!==void 0&&n.file!==t.filePath)throw new g("DUPLICATE_ROOM_NAME",`Duplicate room name "${t.channel.name}": defined in ${n.origin} and ${t.filePath}:${t.exportName}. Room names must be unique across the project.`);n===void 0&&i.set(t.channel.name,{file:t.filePath,origin:`${t.filePath}:${t.exportName}`})}},Me=e=>{const i=new Map;for(const t of e){const n=ie(t.filePath),o=i.get(n);if(o&&o!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${o}" and "${t.filePath}" both resolve to "${n}". 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:[o,t.filePath],status:500});i.set(n,t.filePath)}},nt=(e,i,t={})=>{const n=M(i),o=[];for(const r of n){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=W(i,r);o.push(...ze(a,c,t.lazyFunctions===!0))}return o.sort((r,a)=>`${r.filePath}:${r.exportName}`.localeCompare(`${a.filePath}:${a.exportName}`)),Me(o),He(o),o};export{nt as d,I as i,ne as p,it as w};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as r}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as f,declarationLineOf as m}from"./isTestPath-DJeZ18i9.mjs";import{j as p,h as d}from"./attribution-
|
|
1
|
+
import{Node as r}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as f,declarationLineOf as m}from"./isTestPath-DJeZ18i9.mjs";import{j as p,h as d}from"./attribution-B8xa6AeK.mjs";import{t as g}from"./database-calls-Cug60vT9.mjs";import{w as h,c as k}from"./classify-procedure-call-BK_MMoue.mjs";import{a as v}from"./property-name-7cBlgK_O.mjs";const l=e=>{if(!(!r.isPropertyAssignment(e)&&!r.isShorthandPropertyAssignment(e)&&!r.isMethodDeclaration(e)&&!r.isGetAccessorDeclaration(e)))return v(e)},P=e=>h(e,"use","mask"),E=e=>{if(r.isPropertyAssignment(e)){const s=e.getInitializer();if(s&&r.isStringLiteral(s)){const t=s.getLiteralText();if(t==="redact"||t==="hash")return t}}return"custom"},y=e=>{const s=e.getArguments()[0];if(!s||!r.isObjectLiteralExpression(s))return[];const t=[];for(const i of s.getProperties()){const o=l(i);if(o===void 0||!r.isPropertyAssignment(i))continue;const n=i.getInitializer();if(!(!n||!r.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=l(a);c!==void 0&&t.push({column:c,table:o})}}return t},C=e=>{const s=P(e);return{maskColumns:s.flatMap(t=>y(t)),usesMask:s.length>0}},M=new Set(["explain","findFirst","findFirstOrThrow","findMany","get","query"]),x=new Set(["delete","insert","patch","replace"]),A=(e,s)=>{if(!r.isVariableDeclaration(e))return;const t=e.getInitializer();if(!t||!r.isCallExpression(t))return;const i=k(t);if(!i)return;const o=i.receiver?C(i.receiver):{maskColumns:[],usesMask:!1},{tablesRead:n,tablesWritten:a}=g(e,M,x);return{exportName:d(e)??e.getName(),file:s,line:m(e),maskColumns:o.maskColumns,tablesRead:n,tablesWritten:a,usesMask:o.usesMask,visibility:i.visibility}},z=(e,s)=>{const t=[];for(const i of u(s)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i),n=f(s,i);for(const a of p(o)){const c=A(a,n);c&&t.push(c)}}return t};export{l as a,z as d,P as m,E as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Node as r,SyntaxKind as l,VariableDeclarationKind as at}from"ts-morph";import{isConstDeclaration as B,unwrapExpression as u,descendantsOfKind as ct,bindingKeyName as Ee,findObjectProperty as lt}from"./isTestPath-DJeZ18i9.mjs";import{r as dt,b as F,d as m}from"./attribution-B8xa6AeK.mjs";import{i as Oe,r as ce,c as N,a as ut}from"./context-root-CO8PbZi5.mjs";import{a as ne,s as h}from"./property-name-7cBlgK_O.mjs";const gt=s=>{const e=s.getText(),t=n=>{const i=n.getNameNode();return r.isIdentifier(i)&&i.getText()===e};for(const n of s.getAncestors())if(!(!r.isArrowFunction(n)&&!r.isFunctionExpression(n)&&!r.isFunctionDeclaration(n)))for(const i of n.getParameters()){const o=i.getDescendantsOfKind(l.BindingElement).find(a=>t(a));if(o!==void 0)return o}},pt=s=>{let e=s;for(;;){const t=e.getParent();if(!r.isObjectBindingPattern(t))return;const n=t.getParent();if(r.isBindingElement(n)){e=n;continue}return r.isParameterDeclaration(n)?Ee(e):void 0}},ft=s=>{const e=s.getText();if(!s.getAncestors().some(o=>{const a=r.isFunctionLikeDeclaration(o)||r.isArrowFunction(o)?o.getParameters()[1]:void 0,c=a?.getNameNode();return a!==void 0&&(r.isIdentifier(c)?c.getText()===e:a.getDescendantsOfKind(l.BindingElement).some(d=>d.getName()===e))&&Oe(a)}))return!1;const n=m(s),i=r.isParameterDeclaration(n)?n:n?.getFirstAncestorByKind(l.Parameter);return i!==void 0&&(r.isParameterDeclaration(n)||r.isBindingElement(n))&&Oe(i)},Se=(s,e)=>{const t=s.getParent();if(r.isPropertyAccessExpression(t)&&t.getNameNode()===s||r.isPropertyAssignment(t)&&t.getNameNode()===s)return!1;if(s.getText()===e)return!0;const n=gt(s);return n!==void 0&&pt(n)===e?!0:e==="args"&&ft(s)},K=(s,e)=>r.isIdentifier(s)?Se(s,e):s.getDescendantsOfKind(l.Identifier).some(t=>Se(t,e)),Le=s=>{let e=s;for(;r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e)||r.isNonNullExpression(e);)e=e.getExpression();return r.isIdentifier(e)?e:void 0},v=s=>{const e=r.isIdentifier(s)?m(s):void 0;return r.isVariableDeclaration(e)&&r.isIdentifier(e.getNameNode())&&!F(e)?e.getInitializer():void 0},mt=(s,e)=>{const t=s.getParent();if(r.isVariableDeclarationList(t)&&t.getDeclarationKind()===at.Var)return e;const n=t.getParent();return r.isVariableStatement(n)?n.getParent():n},Et=(s,e)=>{const t=s.getNameNode();return r.isIdentifier(t)?t.getText()===e:t.getDescendantsOfKind(l.BindingElement).some(n=>{const i=n.getNameNode();return r.isIdentifier(i)&&i.getText()===e})},re=s=>s.getDescendantsOfKind(l.Identifier).filter(e=>{const t=e.getParent();return!(r.isPropertyAccessExpression(t)&&t.getNameNode()===e)&&!(r.isPropertyAssignment(t)&&t.getNameNode()===e)}),D=s=>r.isIdentifier(s)?[s]:re(s),w=s=>{let e=s;for(;;){const t=e.getParent();if(!((r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t)||r.isNonNullExpression(t))&&t.getExpression()===e))return e;e=t}},vt=s=>{const e=s.getParent();return r.isCallExpression(e)&&e.getExpression()===s?e:void 0},Re=new Set(["find","findFirst","findFirstOrThrow","findMany","findUnique","first","get","unique"]),de=new Set(["findFirst","findUnique","first","get","unique"]),P=s=>{const e=s.getExpression();return r.isPropertyAccessExpression(e)&&Re.has(e.getName())&&N(e)?.[0]==="db"},z=(s,e)=>{for(let t=s,n=s.getParent();n!==void 0&&t!==e;t=n,n=n.getParent()){if(r.isConditionalExpression(n))return!0;if(r.isBinaryExpression(n)){const i=n.getOperatorToken().getKind();if(t===n.getRight()&&(i===l.QuestionQuestionToken||i===l.BarBarToken)||t===n.getLeft()&&i===l.AmpersandAmpersandToken)return!0}}return!1},ve=s=>{if(!r.isIdentifier(s)||s.getText()!=="undefined")return!1;const e=m(s);return e===void 0||e.getSourceFile().isDeclarationFile()},Fe=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),W=s=>{const e=u(s)??s;if(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e)||r.isNumericLiteral(e)||r.isNullLiteral(e)||r.isTrueLiteral(e)||r.isFalseLiteral(e)||ve(e))return!0;const t=r.isIdentifier(e)?m(e):void 0,n=B(t)&&r.isSourceFile(t.getVariableStatement()?.getParent())?t.getInitializer():void 0;return n!==void 0&&!r.isIdentifier(u(n))&&W(n)},f=s=>{let e=s;for(let t=e.getParent();;t=e.getParent()){if(!(r.isParenthesizedExpression(t)||r.isNonNullExpression(t)||r.isAsExpression(t)||r.isSatisfiesExpression(t)||r.isTypeAssertion(t)))return e;e=t}},q=s=>r.isArrowFunction(s)||r.isFunctionExpression(s)||r.isFunctionDeclaration(s)||r.isMethodDeclaration(s),O=s=>{const e=s.getFirstAncestor(t=>q(t));return q(e)?e:void 0},Ce=new Set([l.GreaterThanEqualsToken,l.GreaterThanToken,l.InKeyword,l.InstanceOfKeyword,l.LessThanEqualsToken,l.LessThanToken]),xt=(s,e)=>{if(N(s)!==void 0||W(s))return!0;const t=m(s);if(t===void 0)return!1;if(t.getSourceFile().isDeclarationFile())return!0;const n=r.isParameterDeclaration(t)?t:t.getFirstAncestorByKind(l.Parameter);return e!==void 0&&n?.getParent().compilerNode===e.compilerNode},Q=(s,e)=>{const t=u(s)??s;if(r.isPrefixUnaryExpression(t)&&t.getOperatorToken()===l.ExclamationToken)return Q(t.getOperand(),e);if(r.isBinaryExpression(t)){const n=t.getOperatorToken().getKind();if(Fe.has(n)||Ce.has(n))return!0;if(n===l.AmpersandAmpersandToken)return Q(t.getLeft(),e)&&Q(t.getRight(),e)}return r.isTrueLiteral(t)||r.isFalseLiteral(t)?!0:!K(t,"args")&&D(t).every(n=>xt(n,e))},L=s=>{const e=m(s);return s.getSourceFile().getDescendantsOfKind(l.Identifier).filter(t=>t.getText()===s.getText()&&m(t)===e).filter(t=>{const n=t.getParent();return!((r.isVariableDeclaration(n)||r.isBindingElement(n))&&n.getNameNode()===t)})},Y=s=>{const e=O(s);if(e===void 0)return;const t=f(e).getParent();if(r.isCallExpression(t))return t.getArguments().includes(f(e))?e:void 0;const n=r.isVariableDeclaration(t)&&B(t)?t.getNameNode():void 0,i=r.isIdentifier(n)?L(n):[];return i.length>0&&i.every(o=>{const a=f(o),c=a.getParent();return r.isCallExpression(c)&&c.getArguments().includes(a)})?e:void 0},At=s=>{const e=f(s),t=e.getParent();return r.isArrowFunction(t)?t.getBody()===e&&Y(e)!==void 0:r.isReturnStatement(t)?Y(t)!==void 0:r.isIfStatement(t)||r.isWhileStatement(t)||r.isDoStatement(t)?t.getExpression()===e:r.isForStatement(t)||r.isConditionalExpression(t)?t.getCondition()===e:r.isPrefixUnaryExpression(t)?t.getOperatorToken()===l.ExclamationToken:r.isBinaryExpression(t)&&(Fe.has(t.getOperatorToken().getKind())||Ce.has(t.getOperatorToken().getKind()))},Pt=s=>{let e=s;for(let t=f(e).getParent();r.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.AmpersandAmpersandToken;t=f(e).getParent())e=t;return At(e)&&Q(e,Y(e))},ue=(s,e)=>{for(let t=s,n=s.getParent();n!==void 0&&t!==e;t=n,n=n.getParent()){if(r.isConditionalExpression(n))return!0;const i=r.isBinaryExpression(n)?n.getOperatorToken().getKind():void 0;if(r.isBinaryExpression(n)&&(i===l.QuestionQuestionToken||i===l.BarBarToken)){if(t!==n.getLeft()||!W(n.getRight()))return!0}else if(r.isBinaryExpression(n)&&i===l.AmpersandAmpersandToken&&!Pt(n))return!0}return!1},ht=s=>{const e=O(s),t=e?.getBody();return e===void 0||!r.isBlock(t)||s.getParent()!==t?!1:e.getDescendantsOfKind(l.ReturnStatement).every(n=>n===s||O(n)!==e)},Nt=s=>{let e=f(s);for(let n=e.getParent();r.isBinaryExpression(n)&&n.getOperatorToken().getKind()===l.AmpersandAmpersandToken;n=e.getParent())e=f(n);const t=e.getParent();return r.isArrowFunction(t)&&t.getBody()===e||r.isReturnStatement(t)&&ht(t)},xe="userId",Z=s=>s?.length===2&&s[0]==="auth"&&s[1]===xe,I=s=>{let e=s;for(;;){const t=r.isNonNullExpression(e)||r.isAwaitExpression(e)?e.getExpression():u(e);if(t===void 0||t===e)return e;e=t}},T=s=>Z(N(I(s))),yt=new Set(["contains","gt","gte","isNull","lt","lte","ne","neq","not","notIn"]),ze=new Set(["NOT","not","OR"]),J=s=>{for(let e=s.getParent();e!==void 0&&!r.isCallExpression(e);e=e.getParent()){const t=r.isPropertyAssignment(e)?h(e.getNameNode()):void 0;if(t!==void 0&&ze.has(t))return!0}return!1},It=s=>s>=l.FirstAssignment&&s<=l.LastAssignment,ie=s=>{let e=s,t=e.getParent();for(;r.isParenthesizedExpression(t)||r.isAsExpression(t)||r.isSatisfiesExpression(t)||r.isNonNullExpression(t)||r.isTypeAssertion(t)||r.isArrayLiteralExpression(t)||r.isObjectLiteralExpression(t)||r.isSpreadElement(t)||r.isSpreadAssignment(t)||r.isShorthandPropertyAssignment(t)||r.isPropertyAssignment(t)&&t.getNameNode()!==e;)e=t,t=e.getParent();if(r.isBinaryExpression(t))return t.getLeft()===e&&It(t.getOperatorToken().getKind());if(r.isForOfStatement(t)||r.isForInStatement(t))return t.getInitializer()===e;if(r.isPrefixUnaryExpression(t)||r.isPostfixUnaryExpression(t)){const n=t.getOperatorToken();return n===l.PlusPlusToken||n===l.MinusMinusToken}return r.isDeleteExpression(t)},Ke=(s,e)=>s.every((t,n)=>n>=e.length||t===void 0||e[n]===void 0||t===e[n]),ge=(s,e)=>s.length<e.length&&Ke(s,e),_=s=>{const e=[];let t=f(s);for(let n=t.getParent();;n=t.getParent()){if(r.isPropertyAccessExpression(n)&&n.getExpression()===t)e.push(n.getName());else if(r.isElementAccessExpression(n)&&n.getExpression()===t){const i=u(n.getArgumentExpression());e.push(r.isStringLiteral(i)||r.isNoSubstitutionTemplateLiteral(i)?i.getLiteralValue():void 0)}else return{node:t,path:e};t=f(n)}},Ae=s=>{const e=s.getParent();return r.isCallExpression(e)&&e.getExpression()===s},qe=s=>{const e=s.getParent();if(r.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),n=u(e.getLeft()===s?e.getRight():e.getLeft());return t===l.EqualsEqualsEqualsToken||t===l.ExclamationEqualsEqualsToken||(t===l.EqualsEqualsToken||t===l.ExclamationEqualsToken)&&(r.isNullLiteral(n)||ve(n))}return r.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken||r.isTypeOfExpression(e)},Ve=(s,e)=>e.length===0&&qe(s),Tt=(s,e,t,n)=>{const i=s.getParent();if(r.isSpreadAssignment(i)||r.isVariableDeclaration(i)&&r.isObjectBindingPattern(i.getNameNode()))return t.every(c=>c.length===e.length+1);const a=r.isReturnStatement(i)&&n!==void 0&&O(i)?.compilerNode===n.compilerNode;return qe(s)||a},pe=(s,e,t=[])=>{const{node:n,path:i}=_(s),o=[...t,...i];if(ie(n))return i.length===0||!e.some(d=>Ke(o,d));if(Ae(n)){const d=o.slice(0,-1);return i.length===0||!e.some(g=>ge(d,g))}const a=e.filter(d=>ge(o,d)),c=m(s);return a.length===0||Tt(n,o,a,c===void 0?void 0:O(c))},oe=(s,e)=>{const t=s.getProperties(),n=r.isSpreadAssignment(e)?void 0:ne(e);return t.slice(t.indexOf(e)+1).some(i=>{if(r.isSpreadAssignment(i))return!0;const o=h(i.getNameNode());return o===void 0||o===n})},X=s=>{for(let e=s;e!==void 0&&!r.isCallExpression(e)&&!r.isVariableDeclaration(e)&&!q(e);e=e.getParent()){const t=e.getParent();if((r.isPropertyAssignment(e)||r.isShorthandPropertyAssignment(e))&&r.isObjectLiteralExpression(t)&&oe(t,e))return!0}return!1},De=(s,e)=>{const t=f(s),n=t.getParent();return r.isCallExpression(n)&&n.getArguments().includes(t)&&e(n)},Me=(s,e=P)=>{const t=f(s),n=t.getParent();if(r.isVariableDeclaration(n)&&B(n)){const i=n.getInitializer(),o=n.getNameNode(),a=r.isIdentifier(o)&&i===t?L(o):[];return a.length>0&&a.every(c=>De(c,e))}return De(t,e)},$=(s,e=P)=>{const t=f(s),n=t.getParent();if(r.isPropertyAssignment(n))return h(n.getNameNode())==="where"&&Me(n.getParent(),e);if(r.isArrayLiteralExpression(n)){const i=f(n).getParent();return r.isPropertyAssignment(i)&&h(i.getNameNode())==="AND"&&$(i.getParent(),e)}return r.isVariableDeclaration(n)?n.getInitializer()===t:!1},Ue=(s,e=P)=>{const t=s.getParent();if(!r.isObjectLiteralExpression(t)||!(r.isPropertyAssignment(s)||r.isShorthandPropertyAssignment(s)))return!1;const n=h(s.getNameNode());if(n==="eq"||n==="in"){const i=f(t).getParent();return r.isPropertyAssignment(i)&&$(i.getParent(),e)}return $(t,e)},Ot=(s,e)=>{if(!r.isArrayLiteralExpression(s)||!s.getElements().every(a=>e.isCaller(a)))return!1;const t=f(s).getParent(),n=r.isVariableDeclaration(t)?t.getNameNode():void 0,o=r.isIdentifier(n)&&v(n)!==void 0?L(n):[s];return o.length>0&&o.every(a=>{const c=f(a).getParent();return r.isPropertyAssignment(c)&&h(c.getNameNode())==="in"&&!J(c)&&Ue(c,e.isRead)&&!X(c)})},St=s=>{const e=s.getPropertyNameNode();return!r.isComputedPropertyName(e)||W(e.getExpression())},Dt=s=>!F(s)&&[s,...s.getAncestors().filter(e=>r.isBindingElement(e))].every(e=>r.isBindingElement(e)&&e.getInitializer()===void 0&&e.getDotDotDotToken()===void 0&&St(e)),bt=(s,e,t)=>{const n=_(s).path;return t.getDescendantsOfKind(l.Identifier).filter(i=>i.getParent()!==e&&m(i)?.compilerNode===e?.compilerNode).every(i=>pe(i,[n]))},kt=(s,e)=>{const t=e===void 0?void 0:I(e);if(t===void 0)return!1;if(t===s)return!0;const n=r.isIdentifier(t)?v(t):void 0;return n!==void 0&&I(n)===s},wt=(s,e,t)=>{const n=u(s)??s,i=r.isPropertyAccessExpression(n)||r.isElementAccessExpression(n),o=i?Le(n):n,a=r.isIdentifier(o)?m(o):void 0,c=Y(e),d=c!==void 0&&kt(c,t)?c:void 0;let g;return r.isParameterDeclaration(a)&&i&&!F(a)?g=a.getParent():r.isBindingElement(a)&&Dt(a)&&(g=a.getFirstAncestorByKind(l.Parameter)?.getParent()),g!==void 0&&g===d&&r.isIdentifier(o)&&bt(o,a,g)},Bt=(s,e)=>{const{isRead:t,predicate:n}=e,i=s.getParent();if(r.isArrayLiteralExpression(i))return Ot(i,e);if(r.isPropertyAssignment(i)||r.isShorthandPropertyAssignment(i)){const c=h(i.getNameNode());return(r.isPropertyAssignment(i)?i.getInitializer():s)===s&&c!==void 0&&!yt.has(c)&&!ze.has(c)&&!J(i)&&Ue(i,t)&&!X(i)}if(r.isCallExpression(i)){const c=i.getExpression(),g=(r.isPropertyAccessExpression(c)?c.getName():void 0)==="eq"||t(i);return i.getArguments().includes(s)&&g}if(!r.isBinaryExpression(i))return!1;const o=i.getOperatorToken().getKind(),a=i.getLeft()===s?i.getRight():i.getLeft();return(o===l.EqualsEqualsEqualsToken||o===l.EqualsEqualsToken)&&Nt(i)&&wt(a,i,n)},Lt=(s,e)=>{if(!r.isCallExpression(s))return!1;const t=s.getExpression(),[n,...i]=s.getArguments(),o=r.isIdentifier(t)&&t.getText()==="String"?m(t):void 0;return n===e&&i.length===0&&o?.getSourceFile().isDeclarationFile()===!0},H=(s,e)=>{let t=w(s);for(let n=t.getParent();n!==void 0;n=t.getParent()){const i=r.isParenthesizedExpression(n)||r.isNonNullExpression(n)||r.isAsExpression(n)||r.isSatisfiesExpression(n)||r.isTypeAssertion(n)||r.isAwaitExpression(n),o=r.isBinaryExpression(n)?n.getOperatorToken().getKind():void 0,a=r.isBinaryExpression(n)&&(o===l.QuestionQuestionToken||o===l.BarBarToken)&&n.getLeft()===t&&W(n.getRight());if(!i&&!a&&!Lt(n,t))break;t=n}return Bt(t,e)},Rt=s=>{const e=f(s),t=e.getParent();if(r.isPropertyAssignment(t)||r.isShorthandPropertyAssignment(t))return h(t.getNameNode())==="where"&&!J(t)&&Me(t.getParent())&&!X(t);if(r.isArrayLiteralExpression(t)){const n=f(t).getParent();return r.isPropertyAssignment(n)&&h(n.getNameNode())==="AND"&&!J(n)&&$(n.getParent())&&!X(n)}return r.isCallExpression(t)&&t.getArguments().includes(e)&&P(t)},R=s=>{const e=I(s);if(r.isConditionalExpression(e))return[...R(e.getWhenTrue()),...R(e.getWhenFalse())];if(!r.isBinaryExpression(e))return[e];const t=e.getOperatorToken().getKind();return t===l.CommaToken?R(e.getRight()):t===l.QuestionQuestionToken||t===l.BarBarToken||t===l.AmpersandAmpersandToken?[...R(e.getLeft()),...R(e.getRight())]:[e]},We=s=>D(s).some(e=>{if(ue(e,s))return!1;if(T(w(e)))return H(e,{isCaller:T,isRead:P,predicate:s});const t=v(e),n=t===void 0?[]:R(t);if(n.length>0&&n.every(c=>T(c)))return H(e,{isCaller:T,isRead:P,predicate:s});const[i]=n,o=r.isObjectLiteralExpression(i),a=o||r.isArrayLiteralExpression(i)||r.isArrowFunction(i)||r.isFunctionExpression(i);return n.length!==1||i===void 0||!a||o&&!(r.isIdentifier(e)&&L(e).every(c=>Rt(c)))?!1:D(i).some(c=>T(w(c))&&!ue(c,i)&&H(c,{isCaller:T,isRead:P,predicate:s}))}),Ft=s=>P(s)&&s.getArguments().some(e=>We(e)),_e=(s,e)=>{for(let t=s.getParent();t!==void 0;t=t.getParent()){if(r.isCallExpression(t)&&N(t.getExpression())?.[0]==="db")return!0;if(t===e)return!1}return!1},Ct=new Set(["_id","id"]),Pe=s=>{let e=s;for(let t=e.getParent();;t=e.getParent()){if(r.isAwaitExpression(t)||r.isParenthesizedExpression(t)||r.isNonNullExpression(t)||r.isAsExpression(t)||r.isSatisfiesExpression(t)||r.isTypeAssertion(t)){e=t;continue}if(r.isPropertyAccessExpression(t)&&t.getExpression()===e)return{field:t.getName(),read:t};if(r.isElementAccessExpression(t)&&t.getExpression()===e){const n=u(t.getArgumentExpression());return{field:r.isStringLiteral(n)||r.isNoSubstitutionTemplateLiteral(n)?n.getLiteralValue():void 0,read:t}}return{field:void 0,read:e}}},he=s=>r.isPropertyAssignment(s)?s.getInitializer():r.isShorthandPropertyAssignment(s)?s.getNameNode():void 0,be=s=>{const e=f(s).getParent();return r.isCallExpression(e)&&P(e)&&e.getArguments().includes(f(s))},zt=s=>L(s).every(e=>{if(be(e))return!0;const t=f(e),n=t.getParent(),i=n?.getParent();return(r.isPropertyAssignment(n)&&n.getNameNode()!==t&&ne(n)==="where"||r.isShorthandPropertyAssignment(n)&&n.getName()==="where")&&i!==void 0&&be(i)}),ee=s=>{const e=u(s);if(r.isObjectLiteralExpression(e))return e;const t=r.isIdentifier(e)&&zt(e)?u(v(e)):void 0;return r.isObjectLiteralExpression(t)?t:void 0},Kt=s=>{const e=u(s)??s;if(!r.isObjectLiteralExpression(e))return T(s);const[t,...n]=e.getProperties(),i=n.length===0&&r.isPropertyAssignment(t)&&ne(t)==="eq"?t.getInitializer():void 0;return i!==void 0&&T(i)},Ne=s=>s.getProperties().some(e=>r.isGetAccessorDeclaration(e)||r.isSetAccessorDeclaration(e)||r.isMethodDeclaration(e)),Ge=(s,e)=>!Ne(s)&&s.getProperties().some(t=>{const n=he(t);if(n===void 0||r.isSpreadAssignment(t)||oe(s,t))return!1;const i=h(t.getNameNode());if(i===void 0)return!1;if(i==="AND"){const o=u(n);return r.isArrayLiteralExpression(o)&&o.getElements().some(a=>{const c=ee(a);return c!==void 0&&Ge(c,e)})}return(e===void 0||i===e)&&Kt(n)}),je=(s,e)=>{const t=ee(s),n=t===void 0?void 0:lt(t,"where"),i=t===void 0||n===void 0||Ne(t)||oe(t,n)?void 0:ee(he(n));return i!==void 0&&Ge(i,e)},Qe=s=>s.getArguments().some(e=>T(e)||je(e,void 0)),qt=(s,e)=>e===void 0?!1:Ct.has(e)?Qe(s):s.getArguments().some(t=>je(t,e)),Vt=new Set(["_creationTime","_id"]),Mt=(s,e)=>Vt.has(e)||s.getArguments().every(t=>{const n=ee(t);if(n===void 0)return!0;const i=n.getProperties(),o=i.findLast(c=>!r.isSpreadAssignment(c)&&ne(c)==="select");if(Ne(n))return!1;if(o===void 0)return!i.some(c=>r.isSpreadAssignment(c)||h(c.getNameNode())===void 0);if(oe(n,o))return!1;const a=u(he(o));return r.isArrayLiteralExpression(a)&&a.getElements().some(c=>(r.isStringLiteral(c)||r.isNoSubstitutionTemplateLiteral(c))&&c.getLiteralValue()===e)}),V=(s,e,t,n)=>{const i=s.getExpression(),o=r.isPropertyAccessExpression(i)&&(de.has(i.getName())||i.getName().endsWith("OrThrow"));return!Ft(s)||!o||t!==void 0&&!Mt(s,t)?!1:n!==void 0&&u(e)===u(n)&&Qe(s)||qt(s,t)},ye=(s,e)=>{const t=e.getExpression(),n=r.isPropertyAccessExpression(t)&&t.getName().endsWith("OrThrow");return(r.isPropertyAccessExpression(s)||r.isElementAccessExpression(s))&&s.hasQuestionDotToken()&&!n},He=(s,e)=>D(s).some(t=>{const n=w(t),i=N(n)?.[0];if(i==="auth")return!z(t,s)&&!_e(t,s);const o=i==="db"&&!z(t,s)?vt(n):void 0;if(o===void 0)return!1;const{field:a,read:c}=Pe(o);return!ye(c,o)&&V(o,c,a,e)}),Ut=s=>{const e=u(s);return r.isAwaitExpression(e)?u(e.getExpression()):e},M=s=>{const e=[];let t=u(s);for(;t!==void 0;)if(r.isPropertyAccessExpression(t))e.unshift(t.getName()),t=u(t.getExpression());else if(r.isElementAccessExpression(t)){const n=t.getArgumentExpression();if(!r.isStringLiteral(n))return;e.unshift(n.getLiteralValue()),t=u(t.getExpression())}else return r.isIdentifier(t)?{path:e,root:t}:void 0},S=(s,e)=>m(s)?.compilerNode===e.compilerNode,Ye=s=>{if(!r.isIdentifier(s))return;const e=dt(s),t=e?.isAlias()===!0?e.getAliasedSymbol():e,n=t?.getValueDeclaration()??t?.getDeclarations()[0];if(n===void 0)return;const i=n.getSourceFile();if(i.isDeclarationFile()||i.isInNodeModules())return;if(r.isFunctionDeclaration(n))return n.getBody()===void 0||n.isGenerator()||F(n)?void 0:n;if(!B(n))return;const o=u(n.getInitializer());return r.isArrowFunction(o)||r.isFunctionExpression(o)&&!o.isGenerator()?o:void 0},Ze=(s,e,t)=>s.getStart()<e.getEnd()||O(s)?.compilerNode!==t.compilerNode?!0:e.getAncestors().some(n=>r.isIterationStatement(n)&&n.getStart()<=s.getStart()&&s.getEnd()<=n.getEnd()),Wt=(s,e,t)=>e.getDescendantsOfKind(l.Identifier).some(n=>n.getText()===s.getName()&&ie(n)&&m(n)?.compilerNode===s.compilerNode&&Ze(n,t,e)),Ie=s=>{const e=[],t=[];let n=u(s);for(;n!==void 0;)if(r.isCallExpression(n))e.push(n),n=u(n.getExpression());else if(r.isPropertyAccessExpression(n))t.unshift(n.getName()),n=u(n.getExpression());else if(r.isElementAccessExpression(n)){const i=n.getArgumentExpression();if(!r.isStringLiteral(i))return;t.unshift(i.getLiteralValue()),n=u(n.getExpression())}else return r.isIdentifier(n)&&e.length>0&&t.length>0?{calls:e,names:t,root:n}:void 0},Te=s=>{const e=s.names[s.names.length-1]??"";if(de.has(e))return{selfEnforcing:!1};const t=e.endsWith("OrThrow")?e.slice(0,-7):void 0;return t!==void 0&&de.has(t)?{selfEnforcing:!0}:void 0},_t=s=>{const e=u(s),t=r.isIdentifier(e)?u(v(e))??e:e,n=M(t);if(n===void 0||n.path.length===0)return;const i=m(n.root);if(!B(i)||!r.isIdentifier(i.getNameNode()))return;const o=Ut(i.getInitializer()),a=r.isCallExpression(o)&&N(o.getExpression())?.[0]==="db"?Ie(o):void 0;return a!==void 0&&Te(a)!==void 0?{keyPath:n.path,row:i}:void 0},Gt=(s,e,t)=>{const n=s.getDescendantsOfKind(l.Identifier).filter(o=>o!==e.getNameNode()&&m(o)?.compilerNode===e.compilerNode);return{reads:n.flatMap(o=>{const{node:a,path:c}=_(o),d=[...t,...Ae(a)?c.slice(0,-1):c];return Ve(a,d)||ie(a)?[]:[d]}),uses:n.map(o=>({prefix:t,use:o}))}},Je=s=>s.calls.flatMap(e=>e.getArguments().flatMap(t=>[t,...t.getDescendants()])),jt=(s,e)=>{const t=r.isIdentifier(s)?m(s):void 0;if(!r.isBindingElement(t)||t.getDotDotDotToken()!==void 0||t.getInitializer()!==void 0)return!1;const n=t.getParent(),i=r.isObjectBindingPattern(n)?n.getParent():void 0;if(!B(i))return!1;const o=M(i.getInitializer());return o!==void 0&&Z([...o.path,Ee(t)])&&S(o.root,e)},ke=(s,e)=>{const t=M(s);if(t!==void 0&&t.path.length>0)return Z(t.path)&&S(t.root,e);const n=M(v(s));return n!==void 0&&Z(n.path)&&S(n.root,e)?!0:jt(s,e)},Qt=(s,e)=>{const t=s.getExpression();if(!r.isPropertyAccessExpression(t)||!Re.has(t.getName()))return!1;let n=t;for(;(r.isPropertyAccessExpression(n)||r.isElementAccessExpression(n))&&!r.isIdentifier(n.getExpression());)n=n.getExpression();const i=r.isPropertyAccessExpression(n)?n.getExpression():void 0;return r.isPropertyAccessExpression(n)&&n.getName()==="db"&&r.isIdentifier(i)&&m(i)?.compilerNode===e.compilerNode},Ht=(s,e)=>[s,...s.getDescendants()].some(t=>ke(t,e)&&!ue(t,s)&&H(t,{isCaller:n=>ke(I(n),e),isRead:n=>Qt(n,e),predicate:s})),Xe=s=>{if(!r.isVariableStatement(s))return;const e=s.getDeclarations(),t=e.length===1?e[0]:void 0;return t!==void 0&&B(t)&&r.isIdentifier(t.getNameNode())?t:void 0},Yt=(s,e)=>{const t=u(s),n=d=>r.isIdentifier(d)&&S(d,e);if(r.isPrefixUnaryExpression(t))return t.getOperatorToken()===l.ExclamationToken&&n(u(t.getOperand()));if(!r.isBinaryExpression(t))return!1;const i=t.getOperatorToken().getKind(),o=d=>i===l.EqualsEqualsEqualsToken?r.isNullLiteral(d):i===l.EqualsEqualsToken&&(r.isNullLiteral(d)||ve(d)),a=u(t.getLeft()),c=u(t.getRight());return n(a)&&o(c)||n(c)&&o(a)},Zt=(s,e)=>{const t=r.isBlock(s)?s.getStatements():void 0,n=t===void 0?s:t[t.length-1];return r.isThrowStatement(n)||!e&&r.isReturnStatement(n)},$e=(s,e,t)=>r.isIfStatement(s)&&s.getElseStatement()===void 0&&Yt(s.getExpression(),e)&&Zt(s.getThenStatement(),t),Jt=(s,e,t)=>{const n=s.getBody();if(!r.isBlock(n))return;const i=n.getStatements();return i.find((o,a)=>{const c=Xe(o),d=u(c?.getInitializer()),g=r.isAwaitExpression(d)?Ie(d.getExpression()):void 0,A=g===void 0?void 0:Te(g);if(c===void 0||g===void 0||A===void 0||g.names[0]!=="db"||!S(g.root,e))return!1;const b=Je(g),E=g.calls.some(x=>x.getArguments().some(G=>Ht(G,e))),y=t.some(x=>b.some(G=>r.isIdentifier(G)&&S(G,x)));if(!E||!y)return!1;const p=A.selfEnforcing?o:i.slice(a+1).find(x=>$e(x,c,!0));return p!==void 0&&!s.getDescendantsOfKind(l.ReturnStatement).some(x=>O(x)?.compilerNode===s.compilerNode&&x.getStart()<p.getEnd())})},Xt=(s,e,t,n)=>{const i=[];for(const[o,a]of e.entries()){const c=M(u(a));if(o!==t&&c!==void 0&&S(c.root,n)){const d=s.getParameters()[o];if(d===void 0||d.isRestParameter()||!r.isIdentifier(d.getNameNode()))return;i.push({argument:a,tied:d,...Gt(s,d,c.path)})}}return i},$t=s=>!r.isArrowFunction(s)&&re(s).some(e=>e.getText()==="arguments"&&e.getFirstAncestor(t=>q(t)&&!r.isArrowFunction(t))?.compilerNode===s.compilerNode),es=(s,e,t)=>{const n=Ye(s.getExpression()),i=s.getArguments();if(n===void 0||i.some(p=>r.isSpreadElement(p)))return;const o=i.flatMap((p,x)=>N(p)?.length===0?[x]:[]),a=o.length===1?o[0]:void 0,c=a===void 0?void 0:n.getParameters()[a];if(a===void 0||c===void 0||c.isRestParameter()||!r.isIdentifier(c.getNameNode()))return;const d=Xt(n,i,a,e);if(d===void 0)return;const g=d.map(({tied:p})=>p),A=d.flatMap(({reads:p})=>p),b=n.getReturnType(),E=n.isAsync()||b.isAny()||b.isUnknown()||b.getText().includes("Promise");if(g.length===0||!t&&E||$t(n))return;const y=Jt(n,c,g);if(y!==void 0)return[c,...g].some(p=>p.hasInitializer()||Wt(p,n,y))?void 0:{guardedPaths:A,helperArguments:d.map(({argument:p})=>p),helperUses:d.flatMap(({uses:p})=>p)}},ts=(s,e)=>{const t=Xe(s),n=u(t?.getInitializer()),i=r.isAwaitExpression(n)?Ie(n.getExpression()):void 0,o=i===void 0?void 0:Te(i);if(t===void 0||i===void 0||o===void 0||i.names[0]!=="db"||N(i.root)?.length!==0)return;const a=i.calls.some(d=>d.getArguments().some(g=>We(g))),c=Je(i).some(d=>r.isIdentifier(d)&&S(d,e));return a&&c?{declaration:t,selfEnforcing:o.selfEnforcing}:void 0},ss=(s,e,t)=>{const n=(i,o)=>o.getStart()<=i.getStart()&&i.getEnd()<=o.getEnd();for(let i=s.getParent();i!==void 0&&i.compilerNode!==e.compilerNode;i=i.getParent()){if(q(i)||r.isIfStatement(i)||r.isIterationStatement(i)||r.isCaseClause(i)||r.isDefaultClause(i)||r.isCatchClause(i))return!1;if(r.isTryStatement(i)&&i.getCatchClause()!==void 0){const o=i.getTryBlock();if(!n(s,o)||!n(t,o))return!1}}return!0},ns=(s,e)=>[s,...e.filter(t=>!ge(s,t))],rs=(s,e)=>s.getDescendantsOfKind(l.Identifier).flatMap(t=>{if(!S(t,e))return[];const{node:n,path:i}=_(t),o=Ae(n)?i.slice(0,-1):i;return Ve(n,o)?[]:[o]}),is=(s,e)=>{if(!r.isExpressionStatement(s))return;const t=u(s.getExpression()),n=r.isAwaitExpression(t),i=n?u(t.getExpression()):t;return r.isCallExpression(i)?es(i,e,n):void 0},os=(s,e,t,n,i)=>s.slice(0,e).flatMap((o,a)=>{if(!ss(o,n,i))return[];const c=is(o,t);if(c!==void 0)return[c];const d=ts(o,t);return d!==void 0&&(d.selfEnforcing||a+1<e&&$e(s[a+1],d.declaration,!1))?[{guardedPaths:rs(d.declaration,t)}]:[]}),ae=s=>{let e=u(s)??s;for(;r.isAwaitExpression(e);)e=u(e.getExpression())??e.getExpression();return e},j=s=>{const e=ae(s);return r.isCallExpression(e)||r.isNewExpression(e)},as=s=>{const e=ae(s);return r.isCallExpression(e)&&N(e.getExpression())?.[0]==="db"},et=s=>{const e=ae(s);return r.isCallExpression(e)&&P(e)},fe=s=>K(s,"args")||D(s).some(e=>{const t=v(e);return t!==void 0&&K(t,"args")}),te=(s,e)=>{const t=s?.getNameNode().getDescendantsOfKind(l.BindingElement).find(n=>r.isIdentifier(n.getNameNode())&&n.getNameNode().getText()===e);return t===void 0?[]:[t,...t.getAncestors().filter(n=>r.isBindingElement(n))].map(n=>r.isBindingElement(n)?n.getInitializer():void 0).filter(n=>n!==void 0)},tt=s=>{const e=r.isIdentifier(s)?m(s):void 0;if(!r.isBindingElement(e)||F(e))return;const t=e.getFirstAncestorByKind(l.VariableDeclaration),n=t?.getInitializer();if(!te(t,s.getText()).some(i=>fe(i)))return n!==void 0&&et(n)?n:void 0},U=s=>{const e=ae(s);return r.isCallExpression(e)&&P(e)?e:void 0},st=s=>{if(!(!r.isBindingElement(s)||!r.isObjectBindingPattern(s.getParent())||s.getDotDotDotToken()!==void 0||r.isBindingElement(s.getParent().getParent())))return Ee(s)},nt=s=>L(s).every(e=>{const t=f(e),n=t.getParent();return r.isVariableDeclaration(n)&&r.isObjectBindingPattern(n.getNameNode())||r.isSpreadAssignment(n)?!0:(r.isPropertyAccessExpression(n)||r.isElementAccessExpression(n))&&n.getExpression()===t&&!ie(f(w(n)))}),we=(s,e)=>{const t=e!==void 0&&u(s)===u(e),n=v(s);if(n!==void 0){const a=U(n);if(a===void 0)return He(n,t?n:void 0);if(r.isIdentifier(s)&&!nt(s))return!1;const{field:c,read:d}=Pe(s);return ye(d,a)?!1:V(a,d,c,e)}const i=tt(s),o=i===void 0?void 0:U(i);return o!==void 0&&r.isIdentifier(s)&&V(o,s,st(m(s)),e)},C=(s,e=!0)=>{const t=I(s);if(r.isTemplateExpression(t))return t.getTemplateSpans().flatMap(o=>C(o.getExpression(),e));if(r.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.PlusToken)return[...C(t.getLeft(),e),...C(t.getRight(),e)];const n=e&&r.isIdentifier(t)?v(t):void 0,i=n===void 0?void 0:I(n);return i!==void 0&&(r.isTemplateExpression(i)||r.isBinaryExpression(i)&&i.getOperatorToken().getKind()===l.PlusToken)?C(i,!1).map(({part:o})=>({anchor:t,part:o})):[{anchor:t,part:t}]},cs=s=>r.isStringLiteral(s)||r.isNoSubstitutionTemplateLiteral(s)||r.isNumericLiteral(s),ls=s=>{const e=I(s.getExpression()),t=r.isIdentifier(e)?v(e):void 0;if(r.isIdentifier(e)&&t!==void 0&&!nt(e))return!1;const n=U(e)??(t===void 0?void 0:U(t));return n!==void 0&&!ye(s,n)&&V(n,s,Pe(s.getExpression()).field,void 0)},ds=s=>{const e=m(s),t=st(e),n=r.isBindingElement(e)?e.getFirstAncestorByKind(l.VariableDeclaration)?.getInitializer():void 0,i=n===void 0?void 0:N(I(n));if(i!==void 0)return i.length===1&&i[0]==="auth"&&t===xe;const o=tt(s),a=o===void 0?void 0:U(o);return a!==void 0&&V(a,s,t,void 0)},rt=(s,e=!0)=>{const t=I(s),n=r.isIdentifier(t)?m(t):void 0;if((r.isVariableDeclaration(n)||r.isBindingElement(n))&&F(n))return!1;const i=N(t);if(i!==void 0)return i.length===2&&i[0]==="auth"&&i[1]===xe;if(r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t))return ls(t);if(!r.isIdentifier(t))return!1;const o=v(t);return o===void 0?ds(t):e&&rt(o,!1)},Be=(s,e,t=s)=>{const n=C(e),i=(g,A)=>g.getPos()<=A.getPos()&&A.getEnd()<=g.getEnd(),o=n.findIndex(({part:g})=>!cs(g)),a=n.findIndex(({part:g})=>i(g,s)),c=a===-1?n.findIndex(({anchor:g,part:A})=>i(A,t)||i(g,t)):a,d=n[o];return d!==void 0&&o<c&&rt(d.part)},k=s=>K(s,"args"),se=s=>{if(!r.isIdentifier(s))return;const e=s.getText(),t=s.getFirstAncestor(a=>r.isArrowFunction(a)||r.isFunctionExpression(a)||r.isFunctionDeclaration(a));if(t===void 0)return;const n=s.getStart();let i,o=-1;for(const a of ct(t,l.VariableDeclaration)){if(!Et(a,e))continue;const c=mt(a,t);if(c===void 0||n<c.getStart()||n>=c.getEnd())continue;const d=a.getInitializer(),g=a.getStart();d!==void 0&&g<n&&g>o&&(i=a,o=g)}return i},me=s=>se(s)?.getInitializer(),Ss=s=>{if(k(s))return!0;const e=t=>{const n=se(t),i=n?.getInitializer();return i!==void 0&&k(i)||te(n,t.getText()).some(o=>k(o))};return e(s)||re(s).some(t=>e(t))},Ds=s=>{if(j(s))return!1;if(te(se(s),s.getText()).some(n=>k(n)&&!j(n)))return!0;const e=me(s);if(e!==void 0&&j(e)&&!(et(e)&&k(e)))return!1;const t=e??s;return k(t)?!0:re(t).some(n=>{if(n.getFirstAncestor(c=>c===t||r.isCallExpression(c)||r.isNewExpression(c))!==t)return!1;const o=se(n),a=c=>c!==void 0&&k(c)&&(!j(c)||as(c));return a(o?.getInitializer())||te(o,n.getText()).some(c=>a(c))})},bs=s=>{if(ce(s))return!0;const e=v(s);if(e!==void 0&&ce(e))return!0;const t=e??s;return(r.isIdentifier(t)?[t]:t.getDescendantsOfKind(l.Identifier)).some(i=>{const o=v(i);return o!==void 0&&ce(o)})},ks=s=>{const e=v(s)??s,t=a=>D(a).some(c=>z(c,a)&&fe(w(c))&&!Be(c,a)),n=D(e).some(a=>{const c=v(a);return c!==void 0&&D(c).some(d=>z(d,c)&&fe(w(d))&&!Be(d,e,a))});if(t(e)||n)return!1;if(He(s,s)||we(s,s))return!0;const i=v(s)??s;return(r.isIdentifier(i)?[i]:i.getDescendantsOfKind(l.Identifier)).some(a=>!z(a,i)&&!_e(a,i)&&we(a,i))},le=(s,e)=>K(s,e),ws=(s,e)=>{if(le(s,e))return!0;const t=me(s);if(t!==void 0&&le(t,e))return!0;const n=Le(s);if(n!==void 0){const i=me(n);return i!==void 0&&le(i,e)}return!1},Bs=(s,e)=>{const t=O(s),n=_t(e);if(t===void 0||n===void 0||O(n.row)?.compilerNode!==t.compilerNode)return!1;const{keyPath:i,row:o}=n,a=o.getNameNode(),c=[];let d=s;for(let E=s.getParent();E!==void 0&&E.compilerNode!==t.compilerNode;E=E.getParent()){if(r.isBlock(E)){const y=E.getStatements(),p=y.findIndex(x=>x.compilerNode===d.compilerNode);c.push(...p>0?os(y,p,o,t,s):[])}d=E}if(!r.isIdentifier(a))return!1;const g=L(a).filter(E=>Ze(E,s,t)),A=new Set(c.flatMap(E=>E.helperArguments??[])),b=c.flatMap(E=>E.helperUses??[]);return c.some(E=>{const y=ns(i,E.guardedPaths);return g.every(p=>A.has(_(p).node)||pe(p,y))&&b.every(({prefix:p,use:x})=>pe(x,y,p))})},us=/rate|limit|\bip\b|geo|throttle/iu,gs=/^run[A-Z]/u,ps=s=>r.isIdentifier(s)?(s.getSymbol()?.getDeclarations()??[]).some(t=>t.getFirstAncestorByKind(l.ImportDeclaration)?.getModuleSpecifierValue().startsWith("@lunora/")===!0):!1,fs=s=>{const e=r.isCallExpression(s)?s.getExpression():s;let t;return r.isIdentifier(e)?t=e:r.isPropertyAccessExpression(e)&&(t=e.getNameNode()),t!==void 0&&ps(r.isPropertyAccessExpression(e)?e.getExpression():t)&&!us.test(t.getText())},ms=s=>{const e=r.isCallExpression(s)?s.getExpression():void 0;if(r.isElementAccessExpression(e)){const t=e.getArgumentExpression();return(r.isStringLiteral(t)||r.isNoSubstitutionTemplateLiteral(t))&&t.getLiteralText()==="use"}return r.isPropertyAccessExpression(e)&&e.getName()==="use"},Es=s=>{const e=s.getParent();return r.isPropertyAccessExpression(e)&&e.getExpression()===s?!gs.test(e.getName()):r.isElementAccessExpression(e)&&e.getExpression()===s?r.isStringLiteral(e.getArgumentExpression())||r.isNoSubstitutionTemplateLiteral(e.getArgumentExpression()):r.isVariableDeclaration(e)&&e.getInitializer()?.getText()===s.getText()},vs=s=>{if(r.isPropertyAccessExpression(s))return s.getName()==="ip";if(r.isElementAccessExpression(s)){const e=s.getArgumentExpression();return(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))&&e.getLiteralText()==="ip"}return r.isBindingElement(s)?s.getDotDotDotToken()!==void 0||(s.getPropertyNameNode()?.getText()??s.getName())==="ip":r.isShorthandPropertyAssignment(s)&&s.getName()==="ip"},xs=(s,e)=>{const t=s.getParent();if(!r.isCallExpression(t)||t.getExpression()===s)return!1;const n=t.getArguments(),i=n.indexOf(s);if(n.slice(0,Math.max(i,0)).some(c=>r.isSpreadElement(c)))return!1;const o=Ye(t.getExpression()),a=i===-1||o===void 0?void 0:o.getParameters()[i];return o===void 0||a===void 0||a.isRestParameter()||!r.isIdentifier(a.getNameNode())?!1:e.has(a.compilerNode)?!0:(e.add(a.compilerNode),!ot(o,a,e))},it=(s,e,t=new Set)=>{if(e===void 0||!r.isIdentifier(s))return!1;const n=m(s);if(n?.compilerNode===e.compilerNode)return!0;if(n===void 0||t.has(n.compilerNode))return!1;t.add(n.compilerNode);const i=r.isVariableDeclaration(n)&&r.isIdentifier(n.getNameNode())?n.getInitializer():void 0;return i!==void 0&&it(i,e,t)},As=s=>{const e=s.getParent();return r.isParameterDeclaration(e)||r.isBindingElement(e)||r.isVariableDeclaration(e)?e.getInitializer()!==s:!1},Ps=s=>r.isArrowFunction(s)||r.isFunctionExpression(s)||r.isFunctionDeclaration(s)||r.isMethodDeclaration(s),hs=(s,e)=>!r.isBindingElement(s)||s.getDotDotDotToken()===void 0?!1:s.getFirstAncestorByKind(l.Parameter)?.getParent()?.getAncestors().some(i=>i!==e&&Ps(i)&&i.getAncestors().includes(e))===!0,ot=(s,e,t)=>{for(const n of s.getDescendants())if(vs(n)&&!hs(n,s)||ms(n)&&!fs(n.getArguments()[0])||r.isIdentifier(n)&&(ut(n)||it(n,e))&&!Es(n)&&!As(n)&&!xs(n,t))return!0;return!1},Ls=s=>ot(s,void 0,new Set);export{bs as a,Ds as b,ks as c,Bs as d,ws as e,le as f,se as g,Ss as i,Ls as m,k as r,me as s};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{callSiteCallers as y,byCodepoint as k}from"@lunora/advisor";import{Node as r,SyntaxKind as p,VariableDeclarationKind as F,ts as O}from"ts-morph";import{i as M}from"./reserved-words-CW1QFbTd.mjs";import{isWriteTarget as A,descendantsOfKind as T,unwrapExpression as V}from"./isTestPath-DJeZ18i9.mjs";const N=new WeakMap,C=e=>e.getStatements().flatMap(t=>r.isFunctionDeclaration(t)?[t]:r.isVariableStatement(t)?t.getDeclarations().filter(o=>r.isIdentifier(o.getNameNode())):[]),x=e=>r.isStringLiteral(e)?e.getLiteralValue():e.getText(),I=e=>{if(r.isFunctionDeclaration(e)||r.isClassDeclaration(e)){const t=e.getName();return e.hasExportKeyword()?[[t??"default",e.hasDefaultKeyword()?"default":t??"default"]]:[]}return!r.isVariableStatement(e)||!e.hasExportKeyword()?[]:e.getDeclarations().flatMap(t=>{const o=t.getNameNode();return r.isIdentifier(o)?[[o.getText(),o.getText()]]:o.getDescendantsOfKind(p.BindingElement).flatMap(n=>r.isIdentifier(n.getNameNode())?[[n.getName(),n.getName()]]:[])})},P=e=>{if(r.isExportDeclaration(e))return e.hasModuleSpecifier()||e.isTypeOnly()?[]:e.getNamedExports().filter(o=>!o.isTypeOnly()).map(o=>{const n=x(o.getNameNode()),s=o.getAliasNode();return[n,s===void 0?n:x(s)]});const t=r.isExportAssignment(e)&&!e.isExportEquals()?e.getExpression():void 0;return r.isIdentifier(t)?[[t.getText(),"default"]]:I(e)},h=new WeakMap,K=e=>{const t=h.get(e.compilerNode);if(t!==void 0)return t;const o=new Map;for(const[s,c]of e.getStatements().flatMap(i=>P(i)))o.set(s,(o.get(s)??new Set).add(c));const n=new Map([...o].map(([s,c])=>[s,[...c].toSorted(Y)]));return h.set(e.compilerNode,n),n},g=e=>{const t=r.isBindingElement(e)?e.getFirstAncestorByKind(p.VariableStatement):void 0,o=r.isVariableDeclaration(e)?e.getVariableStatement():void 0,n=r.isFunctionDeclaration(e)?e:t??o;if(n===void 0||!r.isSourceFile(n.getParent()))return[];const s=r.isFunctionDeclaration(e)?e.getName()??"default":e.getName();return K(e.getSourceFile()).get(s)??[]},L=e=>new Map(e.flatMap(t=>{const o=g(t);return o.length===0?[]:[[t.compilerNode,o]]})),B=e=>{const t=V(e);return t!==void 0&&(r.isArrowFunction(t)||r.isFunctionExpression(t))},b=(e,t)=>{for(const o of e.getAncestors()){if(r.isExportAssignment(o)&&!o.isExportEquals())return{kind:"export",name:"default"};if((r.isFunctionDeclaration(o)&&r.isSourceFile(o.getParent())||r.isVariableDeclaration(o)&&r.isSourceFile(o.getVariableStatement()?.getParent())&&r.isIdentifier(o.getNameNode()))&&(r.isFunctionDeclaration(o)||r.isVariableDeclaration(o))){const s=t.get(o.compilerNode)?.[0];return s!==void 0?{kind:"export",name:s}:r.isFunctionDeclaration(o)||B(o.getInitializer())?{declaration:o,kind:"helper"}:{kind:"untracked"}}}return{kind:"untracked"}},E=e=>{for(const t of e.getAncestors()){if(r.isExpressionWithTypeArguments(t)){const o=t.getParent();return!(r.isHeritageClause(o)&&o.getToken()===p.ExtendsKeyword&&(r.isClassDeclaration(o.getParent())||r.isClassExpression(o.getParent())))}if(O.isTypeNode(t.compilerNode))return!0}return!1},ee=e=>{const t=e.getParent(),o=r.isPropertyAccessExpression(t)&&t.getNameNode()===e,n=(r.isPropertyAssignment(t)||r.isMethodDeclaration(t))&&t.getNameNode()===e;return!o&&!n&&!E(e)},v=e=>{const t=e.getParent();return r.isShorthandPropertyAssignment(t)&&t.getNameNode()===e?t.getValueSymbol():e.getSymbol()},R=e=>{const t=v(e);return t?.getValueDeclaration()??t?.getDeclarations()[0]},S=new WeakMap,$=/\/typescript\/lib\/lib\.[^/]+\.d\.ts$/u,_=e=>{const t=e.getFilePath();return e.isDeclarationFile()&&($.test(t)||t.includes("/@types/node/"))},te=e=>{const t=e.getNameNode(),o=r.isFunctionDeclaration(e)?void 0:e.getFirstAncestorByKind(p.VariableDeclarationList);if(!r.isIdentifier(t)||o?.getDeclarationKind()===F.Const||_(e.getSourceFile()))return!1;let n=S.get(e.compilerNode);if(n===void 0){const s=r.isFunctionDeclaration(e)?e.getSourceFile():e.getFirstAncestor(i=>r.isFunctionLikeDeclaration(i)||r.isArrowFunction(i))??e.getSourceFile(),c=t.getText();n=s.getDescendantsOfKind(p.Identifier).some(i=>i!==t&&i.getText()===c&&A(i)&&R(i)?.compilerNode===e.compilerNode),S.set(e.compilerNode,n)}return n},W=e=>{const t=new Map,o=new Set,n=new Set;for(const s of e){const c=s.getNameNode(),i=c?.getSymbol()?.compilerSymbol;c!==void 0&&i!==void 0&&(t.set(i,s.compilerNode),o.add(c.compilerNode),n.add(c.getText()))}return{bySymbol:t,nameNodes:o,spellings:n}},z=(e,t,o)=>{const{bySymbol:n,nameNodes:s,spellings:c}=W(t),i=new Map;for(const a of T(e,p.Identifier)){if(!c.has(a.getText())||s.has(a.compilerNode)||E(a))continue;const l=v(a)?.compilerSymbol,d=l===void 0?void 0:n.get(l);d!==void 0&&i.set(d,[...i.get(d)??[],b(a,o)])}return i},H=(e,t)=>{const o=new Map(e.map(a=>[a.compilerNode,new Set])),n=new Set,s=a=>(o.get(a)?.size??0)+(n.has(a)?1:0),c=(a,l)=>{const d=s(a),u=o.get(a),m=l.kind==="helper"?l.declaration.compilerNode:void 0;l.kind==="export"&&u?.add(l.name);for(const w of m===void 0?[]:o.get(m)??[])u?.add(w);return(l.kind==="untracked"||m!==void 0&&n.has(m))&&n.add(a),s(a)!==d};let i=!0;for(;i;){i=!1;for(const[a,l]of t)for(const d of l)i=c(a,d)||i}return new Map([...o].map(([a,l])=>[a,{callers:[...l].toSorted((d,u)=>d.localeCompare(u)),untracked:n.has(a)}]))},q=e=>{const t=N.get(e.compilerNode);if(t!==void 0)return t;const o=C(e),n=L(o),s=o.filter(i=>!n.has(i.compilerNode)),c={exportNames:n,helperReach:s.length===0?new Map:H(s,z(e,s,n))};return N.set(e.compilerNode,c),c},oe=e=>{const t=q(e.getSourceFile()),o=b(e,t.exportNames);switch(o.kind){case"export":return{kind:"export",name:o.name};case"helper":{const n=o.declaration.getName(),s=t.helperReach.get(o.declaration.compilerNode);if(n===void 0||s===void 0)throw new Error(`call-site attribution: helper at ${o.declaration.getSourceFile().getFilePath()} is not indexed`);return{callers:s.callers,kind:"helper",name:n,...s.untracked?{untracked:!0}:{}}}default:return{kind:"module"}}},X=e=>{if(e.kind==="helper"&&e.untracked===!0)return;const t=y(e);return t.length===0?void 0:t},j=(e,t)=>{const o=new Set(y(e).map(n=>t(n)));return o.has("public")?"public":X(e)===void 0||o.has(void 0)?void 0:"internal"},ne=(e,t)=>{const o=new Map(t.map(n=>[`${n.filePath}:${n.exportName}`,n.visibility]));return e.map(n=>{const s=j(n.scope,c=>o.get(`${n.file}:${c}`));return s===void 0?n:{...n,visibility:s}})},f=/^[$A-Z_a-z][\w$]*$/u,D=e=>f.test(e),G=e=>{const t=g(e);return t.length===0?r.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0?e.getName():void 0:t.find(o=>D(o))??e.getName()},re=e=>e.getVariableStatements().flatMap(t=>t.getDeclarations()).filter(t=>G(t)!==void 0),se=(e,t)=>{if(r.isIdentifier(e.getNameNode()))return e.getVariableStatement()?.hasExportKeyword()===!0?e.getName():g(e).find(o=>t==="binding"?M(o):D(o))},Y=(e,t)=>Number(f.test(t))-Number(f.test(e))||k(e,t);export{se as a,te as b,oe as c,R as d,K as e,ee as f,g,G as h,D as i,re as j,E as k,_ as l,X as m,v as r,ne as w};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./declared-output-Iaar469J.mjs";import"./isTestPath-DJeZ18i9.mjs";import"./attribution-CbD9hCjb.mjs";import"./unwrap-handler-return-BnsKyz9W.mjs";import"./ip-reads-Du9jIYHJ.mjs";import"./classify-procedure-call-BK_MMoue.mjs";import{d as f}from"./index-pzfYD4Dg.mjs";import"./dispatch-namespace-DwTjD7BU.mjs";export{f as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as o}from"./context-property-calls-CxYu8Rfs.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./isTestPath-DJeZ18i9.mjs";import"./attribution-CbD9hCjb.mjs";import"./database-calls-DtZbfTbe.mjs";import"./classify-procedure-call-BK_MMoue.mjs";import{d as a}from"./index-CmF_PUd_.mjs";export{a as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as r}from"./context-property-calls-CxYu8Rfs.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Node as r,SyntaxKind as l,VariableDeclarationKind as ct}from"ts-morph";import{isConstDeclaration as w,unwrapExpression as u,descendantsOfKind as lt,bindingKeyName as Ee,findObjectProperty as dt}from"./isTestPath-DJeZ18i9.mjs";import{r as ut,b as ne,d as m}from"./attribution-CbD9hCjb.mjs";import{i as Oe,r as ce,c as N,a as gt}from"./context-root-DbKRPl4u.mjs";import{a as re,s as h}from"./property-name-7cBlgK_O.mjs";const pt=s=>{const e=s.getText(),t=n=>{const i=n.getNameNode();return r.isIdentifier(i)&&i.getText()===e};for(const n of s.getAncestors())if(!(!r.isArrowFunction(n)&&!r.isFunctionExpression(n)&&!r.isFunctionDeclaration(n)))for(const i of n.getParameters()){const o=i.getDescendantsOfKind(l.BindingElement).find(a=>t(a));if(o!==void 0)return o}},ft=s=>{let e=s;for(;;){const t=e.getParent();if(!r.isObjectBindingPattern(t))return;const n=t.getParent();if(r.isBindingElement(n)){e=n;continue}return r.isParameterDeclaration(n)?Ee(e):void 0}},mt=s=>{const e=s.getText();if(!s.getAncestors().some(o=>{const a=r.isFunctionLikeDeclaration(o)||r.isArrowFunction(o)?o.getParameters()[1]:void 0,c=a?.getNameNode();return a!==void 0&&(r.isIdentifier(c)?c.getText()===e:a.getDescendantsOfKind(l.BindingElement).some(d=>d.getName()===e))&&Oe(a)}))return!1;const n=m(s),i=r.isParameterDeclaration(n)?n:n?.getFirstAncestorByKind(l.Parameter);return i!==void 0&&(r.isParameterDeclaration(n)||r.isBindingElement(n))&&Oe(i)},Se=(s,e)=>{const t=s.getParent();if(r.isPropertyAccessExpression(t)&&t.getNameNode()===s||r.isPropertyAssignment(t)&&t.getNameNode()===s)return!1;if(s.getText()===e)return!0;const n=pt(s);return n!==void 0&&ft(n)===e?!0:e==="args"&&mt(s)},z=(s,e)=>r.isIdentifier(s)?Se(s,e):s.getDescendantsOfKind(l.Identifier).some(t=>Se(t,e)),Le=s=>{let e=s;for(;r.isPropertyAccessExpression(e)||r.isElementAccessExpression(e)||r.isNonNullExpression(e);)e=e.getExpression();return r.isIdentifier(e)?e:void 0},v=s=>{const e=r.isIdentifier(s)?m(s):void 0;return r.isVariableDeclaration(e)&&r.isIdentifier(e.getNameNode())&&!ne(e)?e.getInitializer():void 0},Et=(s,e)=>{const t=s.getParent();if(r.isVariableDeclarationList(t)&&t.getDeclarationKind()===ct.Var)return e;const n=t.getParent();return r.isVariableStatement(n)?n.getParent():n},vt=(s,e)=>{const t=s.getNameNode();return r.isIdentifier(t)?t.getText()===e:t.getDescendantsOfKind(l.BindingElement).some(n=>{const i=n.getNameNode();return r.isIdentifier(i)&&i.getText()===e})},ie=s=>s.getDescendantsOfKind(l.Identifier).filter(e=>{const t=e.getParent();return!(r.isPropertyAccessExpression(t)&&t.getNameNode()===e)&&!(r.isPropertyAssignment(t)&&t.getNameNode()===e)}),D=s=>r.isIdentifier(s)?[s]:ie(s),B=s=>{let e=s;for(;;){const t=e.getParent();if(!((r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t)||r.isNonNullExpression(t))&&t.getExpression()===e))return e;e=t}},xt=s=>{const e=s.getParent();return r.isCallExpression(e)&&e.getExpression()===s?e:void 0},Re=new Set(["find","findFirst","findFirstOrThrow","findMany","findUnique","first","get","unique"]),de=new Set(["findFirst","findUnique","first","get","unique"]),A=s=>{const e=s.getExpression();return r.isPropertyAccessExpression(e)&&Re.has(e.getName())&&N(e)?.[0]==="db"},C=(s,e)=>{for(let t=s,n=s.getParent();n!==void 0&&t!==e;t=n,n=n.getParent()){if(r.isConditionalExpression(n))return!0;if(r.isBinaryExpression(n)){const i=n.getOperatorToken().getKind();if(t===n.getRight()&&(i===l.QuestionQuestionToken||i===l.BarBarToken)||t===n.getLeft()&&i===l.AmpersandAmpersandToken)return!0}}return!1},ve=s=>{if(!r.isIdentifier(s)||s.getText()!=="undefined")return!1;const e=m(s);return e===void 0||e.getSourceFile().isDeclarationFile()},Fe=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),U=s=>{const e=u(s)??s;if(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e)||r.isNumericLiteral(e)||r.isNullLiteral(e)||r.isTrueLiteral(e)||r.isFalseLiteral(e)||ve(e))return!0;const t=r.isIdentifier(e)?m(e):void 0,n=w(t)&&r.isSourceFile(t.getVariableStatement()?.getParent())?t.getInitializer():void 0;return n!==void 0&&!r.isIdentifier(u(n))&&U(n)},f=s=>{let e=s;for(let t=e.getParent();;t=e.getParent()){if(!(r.isParenthesizedExpression(t)||r.isNonNullExpression(t)||r.isAsExpression(t)||r.isSatisfiesExpression(t)||r.isTypeAssertion(t)))return e;e=t}},K=s=>r.isArrowFunction(s)||r.isFunctionExpression(s)||r.isFunctionDeclaration(s)||r.isMethodDeclaration(s),O=s=>{const e=s.getFirstAncestor(t=>K(t));return K(e)?e:void 0},Ce=new Set([l.GreaterThanEqualsToken,l.GreaterThanToken,l.InKeyword,l.InstanceOfKeyword,l.LessThanEqualsToken,l.LessThanToken]),Pt=(s,e)=>{if(N(s)!==void 0||U(s))return!0;const t=m(s);if(t===void 0)return!1;if(t.getSourceFile().isDeclarationFile())return!0;const n=r.isParameterDeclaration(t)?t:t.getFirstAncestorByKind(l.Parameter);return e!==void 0&&n?.getParent().compilerNode===e.compilerNode},Q=(s,e)=>{const t=u(s)??s;if(r.isPrefixUnaryExpression(t)&&t.getOperatorToken()===l.ExclamationToken)return Q(t.getOperand(),e);if(r.isBinaryExpression(t)){const n=t.getOperatorToken().getKind();if(Fe.has(n)||Ce.has(n))return!0;if(n===l.AmpersandAmpersandToken)return Q(t.getLeft(),e)&&Q(t.getRight(),e)}return r.isTrueLiteral(t)||r.isFalseLiteral(t)?!0:!z(t,"args")&&D(t).every(n=>Pt(n,e))},L=s=>{const e=m(s);return s.getSourceFile().getDescendantsOfKind(l.Identifier).filter(t=>t.getText()===s.getText()&&m(t)===e).filter(t=>{const n=t.getParent();return!((r.isVariableDeclaration(n)||r.isBindingElement(n))&&n.getNameNode()===t)})},Y=s=>{const e=O(s);if(e===void 0)return;const t=f(e).getParent();if(r.isCallExpression(t))return t.getArguments().includes(f(e))?e:void 0;const n=r.isVariableDeclaration(t)&&w(t)?t.getNameNode():void 0,i=r.isIdentifier(n)?L(n):[];return i.length>0&&i.every(o=>{const a=f(o),c=a.getParent();return r.isCallExpression(c)&&c.getArguments().includes(a)})?e:void 0},At=s=>{const e=f(s),t=e.getParent();return r.isArrowFunction(t)?t.getBody()===e&&Y(e)!==void 0:r.isReturnStatement(t)?Y(t)!==void 0:r.isIfStatement(t)||r.isWhileStatement(t)||r.isDoStatement(t)?t.getExpression()===e:r.isForStatement(t)||r.isConditionalExpression(t)?t.getCondition()===e:r.isPrefixUnaryExpression(t)?t.getOperatorToken()===l.ExclamationToken:r.isBinaryExpression(t)&&(Fe.has(t.getOperatorToken().getKind())||Ce.has(t.getOperatorToken().getKind()))},ht=s=>{let e=s;for(let t=f(e).getParent();r.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.AmpersandAmpersandToken;t=f(e).getParent())e=t;return At(e)&&Q(e,Y(e))},ue=(s,e)=>{for(let t=s,n=s.getParent();n!==void 0&&t!==e;t=n,n=n.getParent()){if(r.isConditionalExpression(n))return!0;const i=r.isBinaryExpression(n)?n.getOperatorToken().getKind():void 0;if(r.isBinaryExpression(n)&&(i===l.QuestionQuestionToken||i===l.BarBarToken)){if(t!==n.getLeft()||!U(n.getRight()))return!0}else if(r.isBinaryExpression(n)&&i===l.AmpersandAmpersandToken&&!ht(n))return!0}return!1},Nt=s=>{const e=O(s),t=e?.getBody();return e===void 0||!r.isBlock(t)||s.getParent()!==t?!1:e.getDescendantsOfKind(l.ReturnStatement).every(n=>n===s||O(n)!==e)},yt=s=>{let e=f(s);for(let n=e.getParent();r.isBinaryExpression(n)&&n.getOperatorToken().getKind()===l.AmpersandAmpersandToken;n=e.getParent())e=f(n);const t=e.getParent();return r.isArrowFunction(t)&&t.getBody()===e||r.isReturnStatement(t)&&Nt(t)},xe="userId",Z=s=>s?.length===2&&s[0]==="auth"&&s[1]===xe,I=s=>{let e=s;for(;;){const t=r.isNonNullExpression(e)||r.isAwaitExpression(e)?e.getExpression():u(e);if(t===void 0||t===e)return e;e=t}},T=s=>Z(N(I(s))),It=new Set(["contains","gt","gte","isNull","lt","lte","ne","neq","not","notIn"]),ze=new Set(["NOT","not","OR"]),J=s=>{for(let e=s.getParent();e!==void 0&&!r.isCallExpression(e);e=e.getParent()){const t=r.isPropertyAssignment(e)?h(e.getNameNode()):void 0;if(t!==void 0&&ze.has(t))return!0}return!1},Tt=s=>s>=l.FirstAssignment&&s<=l.LastAssignment,W=s=>{let e=s,t=e.getParent();for(;r.isParenthesizedExpression(t)||r.isAsExpression(t)||r.isSatisfiesExpression(t)||r.isNonNullExpression(t)||r.isTypeAssertion(t)||r.isArrayLiteralExpression(t)||r.isObjectLiteralExpression(t)||r.isSpreadElement(t)||r.isSpreadAssignment(t)||r.isShorthandPropertyAssignment(t)||r.isPropertyAssignment(t)&&t.getNameNode()!==e;)e=t,t=e.getParent();if(r.isBinaryExpression(t))return t.getLeft()===e&&Tt(t.getOperatorToken().getKind());if(r.isForOfStatement(t)||r.isForInStatement(t))return t.getInitializer()===e;if(r.isPrefixUnaryExpression(t)||r.isPostfixUnaryExpression(t)){const n=t.getOperatorToken();return n===l.PlusPlusToken||n===l.MinusMinusToken}return r.isDeleteExpression(t)},Ke=(s,e)=>s.every((t,n)=>n>=e.length||t===void 0||e[n]===void 0||t===e[n]),ge=(s,e)=>s.length<e.length&&Ke(s,e),_=s=>{const e=[];let t=f(s);for(let n=t.getParent();;n=t.getParent()){if(r.isPropertyAccessExpression(n)&&n.getExpression()===t)e.push(n.getName());else if(r.isElementAccessExpression(n)&&n.getExpression()===t){const i=u(n.getArgumentExpression());e.push(r.isStringLiteral(i)||r.isNoSubstitutionTemplateLiteral(i)?i.getLiteralValue():void 0)}else return{node:t,path:e};t=f(n)}},Pe=s=>{const e=s.getParent();return r.isCallExpression(e)&&e.getExpression()===s},qe=s=>{const e=s.getParent();if(r.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),n=u(e.getLeft()===s?e.getRight():e.getLeft());return t===l.EqualsEqualsEqualsToken||t===l.ExclamationEqualsEqualsToken||(t===l.EqualsEqualsToken||t===l.ExclamationEqualsToken)&&(r.isNullLiteral(n)||ve(n))}return r.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken||r.isTypeOfExpression(e)},Ve=(s,e)=>e.length===0&&qe(s),Ot=(s,e,t,n)=>{const i=s.getParent();if(r.isSpreadAssignment(i)||r.isVariableDeclaration(i)&&r.isObjectBindingPattern(i.getNameNode()))return t.every(c=>c.length===e.length+1);const a=r.isReturnStatement(i)&&n!==void 0&&O(i)?.compilerNode===n.compilerNode;return qe(s)||a},pe=(s,e,t=[])=>{const{node:n,path:i}=_(s),o=[...t,...i];if(W(n))return i.length===0||!e.some(d=>Ke(o,d));if(Pe(n)){const d=o.slice(0,-1);return i.length===0||!e.some(g=>ge(d,g))}const a=e.filter(d=>ge(o,d)),c=m(s);return a.length===0||Ot(n,o,a,c===void 0?void 0:O(c))},oe=(s,e)=>{const t=s.getProperties(),n=r.isSpreadAssignment(e)?void 0:re(e);return t.slice(t.indexOf(e)+1).some(i=>{if(r.isSpreadAssignment(i))return!0;const o=h(i.getNameNode());return o===void 0||o===n})},X=s=>{for(let e=s;e!==void 0&&!r.isCallExpression(e)&&!r.isVariableDeclaration(e)&&!K(e);e=e.getParent()){const t=e.getParent();if((r.isPropertyAssignment(e)||r.isShorthandPropertyAssignment(e))&&r.isObjectLiteralExpression(t)&&oe(t,e))return!0}return!1},De=(s,e)=>{const t=f(s),n=t.getParent();return r.isCallExpression(n)&&n.getArguments().includes(t)&&e(n)},Me=(s,e=A)=>{const t=f(s),n=t.getParent();if(r.isVariableDeclaration(n)&&w(n)){const i=n.getInitializer(),o=n.getNameNode(),a=r.isIdentifier(o)&&i===t?L(o):[];return a.length>0&&a.every(c=>De(c,e))}return De(t,e)},$=(s,e=A)=>{const t=f(s),n=t.getParent();if(r.isPropertyAssignment(n))return h(n.getNameNode())==="where"&&Me(n.getParent(),e);if(r.isArrayLiteralExpression(n)){const i=f(n).getParent();return r.isPropertyAssignment(i)&&h(i.getNameNode())==="AND"&&$(i.getParent(),e)}return r.isVariableDeclaration(n)?n.getInitializer()===t:!1},Ue=(s,e=A)=>{const t=s.getParent();if(!r.isObjectLiteralExpression(t)||!(r.isPropertyAssignment(s)||r.isShorthandPropertyAssignment(s)))return!1;const n=h(s.getNameNode());if(n==="eq"||n==="in"){const i=f(t).getParent();return r.isPropertyAssignment(i)&&$(i.getParent(),e)}return $(t,e)},St=(s,e)=>{if(!r.isArrayLiteralExpression(s)||!s.getElements().every(a=>e.isCaller(a)))return!1;const t=f(s).getParent(),n=r.isVariableDeclaration(t)?t.getNameNode():void 0,o=r.isIdentifier(n)&&v(n)!==void 0?L(n):[s];return o.length>0&&o.every(a=>{const c=f(a).getParent();return r.isPropertyAssignment(c)&&h(c.getNameNode())==="in"&&!J(c)&&Ue(c,e.isRead)&&!X(c)})},We=(s,e)=>s.getDescendantsOfKind(l.Identifier).some(t=>W(t)&&m(t)?.compilerNode===e.compilerNode),Dt=s=>{const e=s.getPropertyNameNode();return!r.isComputedPropertyName(e)||U(e.getExpression())},bt=s=>!We(s.getFirstAncestorByKind(l.Parameter)?.getParent()??s,s)&&[s,...s.getAncestors().filter(e=>r.isBindingElement(e))].every(e=>r.isBindingElement(e)&&e.getInitializer()===void 0&&e.getDotDotDotToken()===void 0&&Dt(e)),kt=(s,e,t)=>{const n=_(s).path;return t.getDescendantsOfKind(l.Identifier).filter(i=>i.getParent()!==e&&m(i)?.compilerNode===e?.compilerNode).every(i=>pe(i,[n]))},Bt=(s,e)=>{const t=e===void 0?void 0:I(e);if(t===void 0)return!1;if(t===s)return!0;const n=r.isIdentifier(t)?v(t):void 0;return n!==void 0&&I(n)===s},wt=(s,e,t)=>{const n=u(s)??s,i=r.isPropertyAccessExpression(n)||r.isElementAccessExpression(n),o=i?Le(n):n,a=r.isIdentifier(o)?m(o):void 0,c=Y(e),d=c!==void 0&&Bt(c,t)?c:void 0;let g;return r.isParameterDeclaration(a)&&i&&!We(a.getParent(),a)?g=a.getParent():r.isBindingElement(a)&&bt(a)&&(g=a.getFirstAncestorByKind(l.Parameter)?.getParent()),g!==void 0&&g===d&&r.isIdentifier(o)&&kt(o,a,g)},Lt=(s,e)=>{const{isRead:t,predicate:n}=e,i=s.getParent();if(r.isArrayLiteralExpression(i))return St(i,e);if(r.isPropertyAssignment(i)||r.isShorthandPropertyAssignment(i)){const c=h(i.getNameNode());return(r.isPropertyAssignment(i)?i.getInitializer():s)===s&&c!==void 0&&!It.has(c)&&!ze.has(c)&&!J(i)&&Ue(i,t)&&!X(i)}if(r.isCallExpression(i)){const c=i.getExpression(),g=(r.isPropertyAccessExpression(c)?c.getName():void 0)==="eq"||t(i);return i.getArguments().includes(s)&&g}if(!r.isBinaryExpression(i))return!1;const o=i.getOperatorToken().getKind(),a=i.getLeft()===s?i.getRight():i.getLeft();return(o===l.EqualsEqualsEqualsToken||o===l.EqualsEqualsToken)&&yt(i)&&wt(a,i,n)},Rt=(s,e)=>{if(!r.isCallExpression(s))return!1;const t=s.getExpression(),[n,...i]=s.getArguments(),o=r.isIdentifier(t)&&t.getText()==="String"?m(t):void 0;return n===e&&i.length===0&&o?.getSourceFile().isDeclarationFile()===!0},H=(s,e)=>{let t=B(s);for(let n=t.getParent();n!==void 0;n=t.getParent()){const i=r.isParenthesizedExpression(n)||r.isNonNullExpression(n)||r.isAsExpression(n)||r.isSatisfiesExpression(n)||r.isTypeAssertion(n)||r.isAwaitExpression(n),o=r.isBinaryExpression(n)?n.getOperatorToken().getKind():void 0,a=r.isBinaryExpression(n)&&(o===l.QuestionQuestionToken||o===l.BarBarToken)&&n.getLeft()===t&&U(n.getRight());if(!i&&!a&&!Rt(n,t))break;t=n}return Lt(t,e)},Ft=s=>{const e=f(s),t=e.getParent();if(r.isPropertyAssignment(t)||r.isShorthandPropertyAssignment(t))return h(t.getNameNode())==="where"&&!J(t)&&Me(t.getParent())&&!X(t);if(r.isArrayLiteralExpression(t)){const n=f(t).getParent();return r.isPropertyAssignment(n)&&h(n.getNameNode())==="AND"&&!J(n)&&$(n.getParent())&&!X(n)}return r.isCallExpression(t)&&t.getArguments().includes(e)&&A(t)},R=s=>{const e=I(s);if(r.isConditionalExpression(e))return[...R(e.getWhenTrue()),...R(e.getWhenFalse())];if(!r.isBinaryExpression(e))return[e];const t=e.getOperatorToken().getKind();return t===l.CommaToken?R(e.getRight()):t===l.QuestionQuestionToken||t===l.BarBarToken||t===l.AmpersandAmpersandToken?[...R(e.getLeft()),...R(e.getRight())]:[e]},_e=s=>D(s).some(e=>{if(ue(e,s))return!1;if(T(B(e)))return H(e,{isCaller:T,isRead:A,predicate:s});const t=v(e),n=t===void 0?[]:R(t);if(n.length>0&&n.every(c=>T(c)))return H(e,{isCaller:T,isRead:A,predicate:s});const[i]=n,o=r.isObjectLiteralExpression(i),a=o||r.isArrayLiteralExpression(i)||r.isArrowFunction(i)||r.isFunctionExpression(i);return n.length!==1||i===void 0||!a||o&&!(r.isIdentifier(e)&&L(e).every(c=>Ft(c)))?!1:D(i).some(c=>T(B(c))&&!ue(c,i)&&H(c,{isCaller:T,isRead:A,predicate:s}))}),Ct=s=>A(s)&&s.getArguments().some(e=>_e(e)),Ge=(s,e)=>{for(let t=s.getParent();t!==void 0;t=t.getParent()){if(r.isCallExpression(t)&&N(t.getExpression())?.[0]==="db")return!0;if(t===e)return!1}return!1},zt=new Set(["_id","id"]),Ae=s=>{let e=s;for(let t=e.getParent();;t=e.getParent()){if(r.isAwaitExpression(t)||r.isParenthesizedExpression(t)||r.isNonNullExpression(t)||r.isAsExpression(t)||r.isSatisfiesExpression(t)||r.isTypeAssertion(t)){e=t;continue}if(r.isPropertyAccessExpression(t)&&t.getExpression()===e)return{field:t.getName(),read:t};if(r.isElementAccessExpression(t)&&t.getExpression()===e){const n=u(t.getArgumentExpression());return{field:r.isStringLiteral(n)||r.isNoSubstitutionTemplateLiteral(n)?n.getLiteralValue():void 0,read:t}}return{field:void 0,read:e}}},he=s=>r.isPropertyAssignment(s)?s.getInitializer():r.isShorthandPropertyAssignment(s)?s.getNameNode():void 0,be=s=>{const e=f(s).getParent();return r.isCallExpression(e)&&A(e)&&e.getArguments().includes(f(s))},Kt=s=>L(s).every(e=>{if(be(e))return!0;const t=f(e),n=t.getParent(),i=n?.getParent();return(r.isPropertyAssignment(n)&&n.getNameNode()!==t&&re(n)==="where"||r.isShorthandPropertyAssignment(n)&&n.getName()==="where")&&i!==void 0&&be(i)}),ee=s=>{const e=u(s);if(r.isObjectLiteralExpression(e))return e;const t=r.isIdentifier(e)&&Kt(e)?u(v(e)):void 0;return r.isObjectLiteralExpression(t)?t:void 0},qt=s=>{const e=u(s)??s;if(!r.isObjectLiteralExpression(e))return T(s);const[t,...n]=e.getProperties(),i=n.length===0&&r.isPropertyAssignment(t)&&re(t)==="eq"?t.getInitializer():void 0;return i!==void 0&&T(i)},Ne=s=>s.getProperties().some(e=>r.isGetAccessorDeclaration(e)||r.isSetAccessorDeclaration(e)||r.isMethodDeclaration(e)),je=(s,e)=>!Ne(s)&&s.getProperties().some(t=>{const n=he(t);if(n===void 0||r.isSpreadAssignment(t)||oe(s,t))return!1;const i=h(t.getNameNode());if(i===void 0)return!1;if(i==="AND"){const o=u(n);return r.isArrayLiteralExpression(o)&&o.getElements().some(a=>{const c=ee(a);return c!==void 0&&je(c,e)})}return(e===void 0||i===e)&&qt(n)}),Qe=(s,e)=>{const t=ee(s),n=t===void 0?void 0:dt(t,"where"),i=t===void 0||n===void 0||Ne(t)||oe(t,n)?void 0:ee(he(n));return i!==void 0&&je(i,e)},He=s=>s.getArguments().some(e=>T(e)||Qe(e,void 0)),Vt=(s,e)=>e===void 0?!1:zt.has(e)?He(s):s.getArguments().some(t=>Qe(t,e)),Mt=new Set(["_creationTime","_id"]),Ut=(s,e)=>Mt.has(e)||s.getArguments().every(t=>{const n=ee(t);if(n===void 0)return!0;const i=n.getProperties(),o=i.findLast(c=>!r.isSpreadAssignment(c)&&re(c)==="select");if(Ne(n))return!1;if(o===void 0)return!i.some(c=>r.isSpreadAssignment(c)||h(c.getNameNode())===void 0);if(oe(n,o))return!1;const a=u(he(o));return r.isArrayLiteralExpression(a)&&a.getElements().some(c=>(r.isStringLiteral(c)||r.isNoSubstitutionTemplateLiteral(c))&&c.getLiteralValue()===e)}),q=(s,e,t,n)=>{const i=s.getExpression(),o=r.isPropertyAccessExpression(i)&&(de.has(i.getName())||i.getName().endsWith("OrThrow"));return!Ct(s)||!o||t!==void 0&&!Ut(s,t)?!1:n!==void 0&&u(e)===u(n)&&He(s)||Vt(s,t)},ye=(s,e)=>{const t=e.getExpression(),n=r.isPropertyAccessExpression(t)&&t.getName().endsWith("OrThrow");return(r.isPropertyAccessExpression(s)||r.isElementAccessExpression(s))&&s.hasQuestionDotToken()&&!n},Ye=(s,e)=>D(s).some(t=>{const n=B(t),i=N(n)?.[0];if(i==="auth")return!C(t,s)&&!Ge(t,s);const o=i==="db"&&!C(t,s)?xt(n):void 0;if(o===void 0)return!1;const{field:a,read:c}=Ae(o);return!ye(c,o)&&q(o,c,a,e)}),Wt=s=>{const e=u(s);return r.isAwaitExpression(e)?u(e.getExpression()):e},V=s=>{const e=[];let t=u(s);for(;t!==void 0;)if(r.isPropertyAccessExpression(t))e.unshift(t.getName()),t=u(t.getExpression());else if(r.isElementAccessExpression(t)){const n=t.getArgumentExpression();if(!r.isStringLiteral(n))return;e.unshift(n.getLiteralValue()),t=u(t.getExpression())}else return r.isIdentifier(t)?{path:e,root:t}:void 0},S=(s,e)=>m(s)?.compilerNode===e.compilerNode,Ze=s=>{if(!r.isIdentifier(s))return;const e=ut(s),t=e?.isAlias()===!0?e.getAliasedSymbol():e,n=t?.getValueDeclaration()??t?.getDeclarations()[0];if(n===void 0)return;const i=n.getSourceFile();if(i.isDeclarationFile()||i.isInNodeModules())return;if(r.isFunctionDeclaration(n))return n.getBody()===void 0||n.isGenerator()||ne(n)?void 0:n;if(!w(n))return;const o=u(n.getInitializer());return r.isArrowFunction(o)||r.isFunctionExpression(o)&&!o.isGenerator()?o:void 0},Je=(s,e,t)=>s.getStart()<e.getEnd()||O(s)?.compilerNode!==t.compilerNode?!0:e.getAncestors().some(n=>r.isIterationStatement(n)&&n.getStart()<=s.getStart()&&s.getEnd()<=n.getEnd()),_t=(s,e,t)=>e.getDescendantsOfKind(l.Identifier).some(n=>n.getText()===s.getName()&&W(n)&&m(n)?.compilerNode===s.compilerNode&&Je(n,t,e)),Ie=s=>{const e=[],t=[];let n=u(s);for(;n!==void 0;)if(r.isCallExpression(n))e.push(n),n=u(n.getExpression());else if(r.isPropertyAccessExpression(n))t.unshift(n.getName()),n=u(n.getExpression());else if(r.isElementAccessExpression(n)){const i=n.getArgumentExpression();if(!r.isStringLiteral(i))return;t.unshift(i.getLiteralValue()),n=u(n.getExpression())}else return r.isIdentifier(n)&&e.length>0&&t.length>0?{calls:e,names:t,root:n}:void 0},Te=s=>{const e=s.names[s.names.length-1]??"";if(de.has(e))return{selfEnforcing:!1};const t=e.endsWith("OrThrow")?e.slice(0,-7):void 0;return t!==void 0&&de.has(t)?{selfEnforcing:!0}:void 0},Gt=s=>{const e=u(s),t=r.isIdentifier(e)?u(v(e))??e:e,n=V(t);if(n===void 0||n.path.length===0)return;const i=m(n.root);if(!w(i)||!r.isIdentifier(i.getNameNode()))return;const o=Wt(i.getInitializer()),a=r.isCallExpression(o)&&N(o.getExpression())?.[0]==="db"?Ie(o):void 0;return a!==void 0&&Te(a)!==void 0?{keyPath:n.path,row:i}:void 0},jt=(s,e,t)=>{const n=s.getDescendantsOfKind(l.Identifier).filter(o=>o!==e.getNameNode()&&m(o)?.compilerNode===e.compilerNode);return{reads:n.flatMap(o=>{const{node:a,path:c}=_(o),d=[...t,...Pe(a)?c.slice(0,-1):c];return Ve(a,d)||W(a)?[]:[d]}),uses:n.map(o=>({prefix:t,use:o}))}},Xe=s=>s.calls.flatMap(e=>e.getArguments().flatMap(t=>[t,...t.getDescendants()])),Qt=(s,e)=>{const t=r.isIdentifier(s)?m(s):void 0;if(!r.isBindingElement(t)||t.getDotDotDotToken()!==void 0||t.getInitializer()!==void 0)return!1;const n=t.getParent(),i=r.isObjectBindingPattern(n)?n.getParent():void 0;if(!w(i))return!1;const o=V(i.getInitializer());return o!==void 0&&Z([...o.path,Ee(t)])&&S(o.root,e)},ke=(s,e)=>{const t=V(s);if(t!==void 0&&t.path.length>0)return Z(t.path)&&S(t.root,e);const n=V(v(s));return n!==void 0&&Z(n.path)&&S(n.root,e)?!0:Qt(s,e)},Ht=(s,e)=>{const t=s.getExpression();if(!r.isPropertyAccessExpression(t)||!Re.has(t.getName()))return!1;let n=t;for(;(r.isPropertyAccessExpression(n)||r.isElementAccessExpression(n))&&!r.isIdentifier(n.getExpression());)n=n.getExpression();const i=r.isPropertyAccessExpression(n)?n.getExpression():void 0;return r.isPropertyAccessExpression(n)&&n.getName()==="db"&&r.isIdentifier(i)&&m(i)?.compilerNode===e.compilerNode},Yt=(s,e)=>[s,...s.getDescendants()].some(t=>ke(t,e)&&!ue(t,s)&&H(t,{isCaller:n=>ke(I(n),e),isRead:n=>Ht(n,e),predicate:s})),$e=s=>{if(!r.isVariableStatement(s))return;const e=s.getDeclarations(),t=e.length===1?e[0]:void 0;return t!==void 0&&w(t)&&r.isIdentifier(t.getNameNode())?t:void 0},Zt=(s,e)=>{const t=u(s),n=d=>r.isIdentifier(d)&&S(d,e);if(r.isPrefixUnaryExpression(t))return t.getOperatorToken()===l.ExclamationToken&&n(u(t.getOperand()));if(!r.isBinaryExpression(t))return!1;const i=t.getOperatorToken().getKind(),o=d=>i===l.EqualsEqualsEqualsToken?r.isNullLiteral(d):i===l.EqualsEqualsToken&&(r.isNullLiteral(d)||ve(d)),a=u(t.getLeft()),c=u(t.getRight());return n(a)&&o(c)||n(c)&&o(a)},Jt=(s,e)=>{const t=r.isBlock(s)?s.getStatements():void 0,n=t===void 0?s:t[t.length-1];return r.isThrowStatement(n)||!e&&r.isReturnStatement(n)},et=(s,e,t)=>r.isIfStatement(s)&&s.getElseStatement()===void 0&&Zt(s.getExpression(),e)&&Jt(s.getThenStatement(),t),Xt=(s,e,t)=>{const n=s.getBody();if(!r.isBlock(n))return;const i=n.getStatements();return i.find((o,a)=>{const c=$e(o),d=u(c?.getInitializer()),g=r.isAwaitExpression(d)?Ie(d.getExpression()):void 0,P=g===void 0?void 0:Te(g);if(c===void 0||g===void 0||P===void 0||g.names[0]!=="db"||!S(g.root,e))return!1;const b=Xe(g),E=g.calls.some(x=>x.getArguments().some(G=>Yt(G,e))),y=t.some(x=>b.some(G=>r.isIdentifier(G)&&S(G,x)));if(!E||!y)return!1;const p=P.selfEnforcing?o:i.slice(a+1).find(x=>et(x,c,!0));return p!==void 0&&!s.getDescendantsOfKind(l.ReturnStatement).some(x=>O(x)?.compilerNode===s.compilerNode&&x.getStart()<p.getEnd())})},$t=(s,e,t,n)=>{const i=[];for(const[o,a]of e.entries()){const c=V(u(a));if(o!==t&&c!==void 0&&S(c.root,n)){const d=s.getParameters()[o];if(d===void 0||d.isRestParameter()||!r.isIdentifier(d.getNameNode()))return;i.push({argument:a,tied:d,...jt(s,d,c.path)})}}return i},es=s=>!r.isArrowFunction(s)&&ie(s).some(e=>e.getText()==="arguments"&&e.getFirstAncestor(t=>K(t)&&!r.isArrowFunction(t))?.compilerNode===s.compilerNode),ts=(s,e,t)=>{const n=Ze(s.getExpression()),i=s.getArguments();if(n===void 0||i.some(p=>r.isSpreadElement(p)))return;const o=i.flatMap((p,x)=>N(p)?.length===0?[x]:[]),a=o.length===1?o[0]:void 0,c=a===void 0?void 0:n.getParameters()[a];if(a===void 0||c===void 0||c.isRestParameter()||!r.isIdentifier(c.getNameNode()))return;const d=$t(n,i,a,e);if(d===void 0)return;const g=d.map(({tied:p})=>p),P=d.flatMap(({reads:p})=>p),b=n.getReturnType(),E=n.isAsync()||b.isAny()||b.isUnknown()||b.getText().includes("Promise");if(g.length===0||!t&&E||es(n))return;const y=Xt(n,c,g);if(y!==void 0)return[c,...g].some(p=>p.hasInitializer()||_t(p,n,y))?void 0:{guardedPaths:P,helperArguments:d.map(({argument:p})=>p),helperUses:d.flatMap(({uses:p})=>p)}},ss=(s,e)=>{const t=$e(s),n=u(t?.getInitializer()),i=r.isAwaitExpression(n)?Ie(n.getExpression()):void 0,o=i===void 0?void 0:Te(i);if(t===void 0||i===void 0||o===void 0||i.names[0]!=="db"||N(i.root)?.length!==0)return;const a=i.calls.some(d=>d.getArguments().some(g=>_e(g))),c=Xe(i).some(d=>r.isIdentifier(d)&&S(d,e));return a&&c?{declaration:t,selfEnforcing:o.selfEnforcing}:void 0},ns=(s,e,t)=>{const n=(i,o)=>o.getStart()<=i.getStart()&&i.getEnd()<=o.getEnd();for(let i=s.getParent();i!==void 0&&i.compilerNode!==e.compilerNode;i=i.getParent()){if(K(i)||r.isIfStatement(i)||r.isIterationStatement(i)||r.isCaseClause(i)||r.isDefaultClause(i)||r.isCatchClause(i))return!1;if(r.isTryStatement(i)&&i.getCatchClause()!==void 0){const o=i.getTryBlock();if(!n(s,o)||!n(t,o))return!1}}return!0},rs=(s,e)=>[s,...e.filter(t=>!ge(s,t))],is=(s,e)=>s.getDescendantsOfKind(l.Identifier).flatMap(t=>{if(!S(t,e))return[];const{node:n,path:i}=_(t),o=Pe(n)?i.slice(0,-1):i;return Ve(n,o)?[]:[o]}),os=(s,e)=>{if(!r.isExpressionStatement(s))return;const t=u(s.getExpression()),n=r.isAwaitExpression(t),i=n?u(t.getExpression()):t;return r.isCallExpression(i)?ts(i,e,n):void 0},as=(s,e,t,n,i)=>s.slice(0,e).flatMap((o,a)=>{if(!ns(o,n,i))return[];const c=os(o,t);if(c!==void 0)return[c];const d=ss(o,t);return d!==void 0&&(d.selfEnforcing||a+1<e&&et(s[a+1],d.declaration,!1))?[{guardedPaths:is(d.declaration,t)}]:[]}),ae=s=>{let e=u(s)??s;for(;r.isAwaitExpression(e);)e=u(e.getExpression())??e.getExpression();return e},j=s=>{const e=ae(s);return r.isCallExpression(e)||r.isNewExpression(e)},cs=s=>{const e=ae(s);return r.isCallExpression(e)&&N(e.getExpression())?.[0]==="db"},tt=s=>{const e=ae(s);return r.isCallExpression(e)&&A(e)},fe=s=>z(s,"args")||D(s).some(e=>{const t=v(e);return t!==void 0&&z(t,"args")}),te=(s,e)=>{const t=s?.getNameNode().getDescendantsOfKind(l.BindingElement).find(n=>r.isIdentifier(n.getNameNode())&&n.getNameNode().getText()===e);return t===void 0?[]:[t,...t.getAncestors().filter(n=>r.isBindingElement(n))].map(n=>r.isBindingElement(n)?n.getInitializer():void 0).filter(n=>n!==void 0)},st=s=>{const e=r.isIdentifier(s)?m(s):void 0;if(!r.isBindingElement(e)||ne(e))return;const t=e.getFirstAncestorByKind(l.VariableDeclaration),n=t?.getInitializer();if(!te(t,s.getText()).some(i=>fe(i)))return n!==void 0&&tt(n)?n:void 0},M=s=>{const e=ae(s);return r.isCallExpression(e)&&A(e)?e:void 0},nt=s=>{if(!(!r.isBindingElement(s)||!r.isObjectBindingPattern(s.getParent())||s.getDotDotDotToken()!==void 0||r.isBindingElement(s.getParent().getParent())))return Ee(s)},rt=s=>L(s).every(e=>{const t=f(e),n=t.getParent();return r.isVariableDeclaration(n)&&r.isObjectBindingPattern(n.getNameNode())||r.isSpreadAssignment(n)?!0:(r.isPropertyAccessExpression(n)||r.isElementAccessExpression(n))&&n.getExpression()===t&&!W(f(B(n)))}),Be=(s,e)=>{const t=e!==void 0&&u(s)===u(e),n=v(s);if(n!==void 0){const a=M(n);if(a===void 0)return Ye(n,t?n:void 0);if(r.isIdentifier(s)&&!rt(s))return!1;const{field:c,read:d}=Ae(s);return ye(d,a)?!1:q(a,d,c,e)}const i=st(s),o=i===void 0?void 0:M(i);return o!==void 0&&r.isIdentifier(s)&&q(o,s,nt(m(s)),e)},F=(s,e=!0)=>{const t=I(s);if(r.isTemplateExpression(t))return t.getTemplateSpans().flatMap(o=>F(o.getExpression(),e));if(r.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.PlusToken)return[...F(t.getLeft(),e),...F(t.getRight(),e)];const n=e&&r.isIdentifier(t)?v(t):void 0,i=n===void 0?void 0:I(n);return i!==void 0&&(r.isTemplateExpression(i)||r.isBinaryExpression(i)&&i.getOperatorToken().getKind()===l.PlusToken)?F(i,!1).map(({part:o})=>({anchor:t,part:o})):[{anchor:t,part:t}]},ls=s=>r.isStringLiteral(s)||r.isNoSubstitutionTemplateLiteral(s)||r.isNumericLiteral(s),ds=s=>{const e=I(s.getExpression()),t=r.isIdentifier(e)?v(e):void 0;if(r.isIdentifier(e)&&t!==void 0&&!rt(e))return!1;const n=M(e)??(t===void 0?void 0:M(t));return n!==void 0&&!ye(s,n)&&q(n,s,Ae(s.getExpression()).field,void 0)},us=s=>{const e=m(s),t=nt(e),n=r.isBindingElement(e)?e.getFirstAncestorByKind(l.VariableDeclaration)?.getInitializer():void 0,i=n===void 0?void 0:N(I(n));if(i!==void 0)return i.length===1&&i[0]==="auth"&&t===xe;const o=st(s),a=o===void 0?void 0:M(o);return a!==void 0&&q(a,s,t,void 0)},it=(s,e=!0)=>{const t=I(s),n=r.isIdentifier(t)?m(t):void 0;if((r.isVariableDeclaration(n)||r.isBindingElement(n))&&ne(n))return!1;const i=N(t);if(i!==void 0)return i.length===2&&i[0]==="auth"&&i[1]===xe;if(r.isPropertyAccessExpression(t)||r.isElementAccessExpression(t))return ds(t);if(!r.isIdentifier(t))return!1;const o=v(t);return o===void 0?us(t):e&&it(o,!1)},we=(s,e,t=s)=>{const n=F(e),i=(g,P)=>g.getPos()<=P.getPos()&&P.getEnd()<=g.getEnd(),o=n.findIndex(({part:g})=>!ls(g)),a=n.findIndex(({part:g})=>i(g,s)),c=a===-1?n.findIndex(({anchor:g,part:P})=>i(P,t)||i(g,t)):a,d=n[o];return d!==void 0&&o<c&&it(d.part)},k=s=>z(s,"args"),se=s=>{if(!r.isIdentifier(s))return;const e=s.getText(),t=s.getFirstAncestor(a=>r.isArrowFunction(a)||r.isFunctionExpression(a)||r.isFunctionDeclaration(a));if(t===void 0)return;const n=s.getStart();let i,o=-1;for(const a of lt(t,l.VariableDeclaration)){if(!vt(a,e))continue;const c=Et(a,t);if(c===void 0||n<c.getStart()||n>=c.getEnd())continue;const d=a.getInitializer(),g=a.getStart();d!==void 0&&g<n&&g>o&&(i=a,o=g)}return i},me=s=>se(s)?.getInitializer(),Ds=s=>{if(k(s))return!0;const e=t=>{const n=se(t),i=n?.getInitializer();return i!==void 0&&k(i)||te(n,t.getText()).some(o=>k(o))};return e(s)||ie(s).some(t=>e(t))},bs=s=>{if(j(s))return!1;if(te(se(s),s.getText()).some(n=>k(n)&&!j(n)))return!0;const e=me(s);if(e!==void 0&&j(e)&&!(tt(e)&&k(e)))return!1;const t=e??s;return k(t)?!0:ie(t).some(n=>{if(n.getFirstAncestor(c=>c===t||r.isCallExpression(c)||r.isNewExpression(c))!==t)return!1;const o=se(n),a=c=>c!==void 0&&k(c)&&(!j(c)||cs(c));return a(o?.getInitializer())||te(o,n.getText()).some(c=>a(c))})},ks=s=>{if(ce(s))return!0;const e=v(s);if(e!==void 0&&ce(e))return!0;const t=e??s;return(r.isIdentifier(t)?[t]:t.getDescendantsOfKind(l.Identifier)).some(i=>{const o=v(i);return o!==void 0&&ce(o)})},Bs=s=>{const e=v(s)??s,t=a=>D(a).some(c=>C(c,a)&&fe(B(c))&&!we(c,a)),n=D(e).some(a=>{const c=v(a);return c!==void 0&&D(c).some(d=>C(d,c)&&fe(B(d))&&!we(d,e,a))});if(t(e)||n)return!1;if(Ye(s,s)||Be(s,s))return!0;const i=v(s)??s;return(r.isIdentifier(i)?[i]:i.getDescendantsOfKind(l.Identifier)).some(a=>!C(a,i)&&!Ge(a,i)&&Be(a,i))},le=(s,e)=>z(s,e),ws=(s,e)=>{if(le(s,e))return!0;const t=me(s);if(t!==void 0&&le(t,e))return!0;const n=Le(s);if(n!==void 0){const i=me(n);return i!==void 0&&le(i,e)}return!1},Ls=(s,e)=>{const t=O(s),n=Gt(e);if(t===void 0||n===void 0||O(n.row)?.compilerNode!==t.compilerNode)return!1;const{keyPath:i,row:o}=n,a=o.getNameNode(),c=[];let d=s;for(let E=s.getParent();E!==void 0&&E.compilerNode!==t.compilerNode;E=E.getParent()){if(r.isBlock(E)){const y=E.getStatements(),p=y.findIndex(x=>x.compilerNode===d.compilerNode);c.push(...p>0?as(y,p,o,t,s):[])}d=E}if(!r.isIdentifier(a))return!1;const g=L(a).filter(E=>Je(E,s,t)),P=new Set(c.flatMap(E=>E.helperArguments??[])),b=c.flatMap(E=>E.helperUses??[]);return c.some(E=>{const y=rs(i,E.guardedPaths);return g.every(p=>P.has(_(p).node)||pe(p,y))&&b.every(({prefix:p,use:x})=>pe(x,y,p))})},gs=/rate|limit|\bip\b|geo|throttle/iu,ps=/^run[A-Z]/u,fs=s=>r.isIdentifier(s)?(s.getSymbol()?.getDeclarations()??[]).some(t=>t.getFirstAncestorByKind(l.ImportDeclaration)?.getModuleSpecifierValue().startsWith("@lunora/")===!0):!1,ms=s=>{const e=r.isCallExpression(s)?s.getExpression():s;let t;return r.isIdentifier(e)?t=e:r.isPropertyAccessExpression(e)&&(t=e.getNameNode()),t!==void 0&&fs(r.isPropertyAccessExpression(e)?e.getExpression():t)&&!gs.test(t.getText())},Es=s=>{const e=r.isCallExpression(s)?s.getExpression():void 0;if(r.isElementAccessExpression(e)){const t=e.getArgumentExpression();return(r.isStringLiteral(t)||r.isNoSubstitutionTemplateLiteral(t))&&t.getLiteralText()==="use"}return r.isPropertyAccessExpression(e)&&e.getName()==="use"},vs=s=>{const e=s.getParent();return r.isPropertyAccessExpression(e)&&e.getExpression()===s?!ps.test(e.getName()):r.isElementAccessExpression(e)&&e.getExpression()===s?r.isStringLiteral(e.getArgumentExpression())||r.isNoSubstitutionTemplateLiteral(e.getArgumentExpression()):r.isVariableDeclaration(e)&&e.getInitializer()?.getText()===s.getText()},xs=s=>{if(r.isPropertyAccessExpression(s))return s.getName()==="ip";if(r.isElementAccessExpression(s)){const e=s.getArgumentExpression();return(r.isStringLiteral(e)||r.isNoSubstitutionTemplateLiteral(e))&&e.getLiteralText()==="ip"}return r.isBindingElement(s)?s.getDotDotDotToken()!==void 0||(s.getPropertyNameNode()?.getText()??s.getName())==="ip":r.isShorthandPropertyAssignment(s)&&s.getName()==="ip"},Ps=(s,e)=>{const t=s.getParent();if(!r.isCallExpression(t)||t.getExpression()===s)return!1;const n=t.getArguments(),i=n.indexOf(s);if(n.slice(0,Math.max(i,0)).some(c=>r.isSpreadElement(c)))return!1;const o=Ze(t.getExpression()),a=i===-1||o===void 0?void 0:o.getParameters()[i];return o===void 0||a===void 0||a.isRestParameter()||!r.isIdentifier(a.getNameNode())?!1:e.has(a.compilerNode)?!0:(e.add(a.compilerNode),!at(o,a,e))},ot=(s,e,t=new Set)=>{if(e===void 0||!r.isIdentifier(s))return!1;const n=m(s);if(n?.compilerNode===e.compilerNode)return!0;if(n===void 0||t.has(n.compilerNode))return!1;t.add(n.compilerNode);const i=r.isVariableDeclaration(n)&&r.isIdentifier(n.getNameNode())?n.getInitializer():void 0;return i!==void 0&&ot(i,e,t)},As=s=>{const e=s.getParent();return r.isParameterDeclaration(e)||r.isBindingElement(e)||r.isVariableDeclaration(e)?e.getInitializer()!==s:!1},hs=s=>r.isArrowFunction(s)||r.isFunctionExpression(s)||r.isFunctionDeclaration(s)||r.isMethodDeclaration(s),Ns=(s,e)=>!r.isBindingElement(s)||s.getDotDotDotToken()===void 0?!1:s.getFirstAncestorByKind(l.Parameter)?.getParent()?.getAncestors().some(i=>i!==e&&hs(i)&&i.getAncestors().includes(e))===!0,at=(s,e,t)=>{for(const n of s.getDescendants())if(xs(n)&&!Ns(n,s)||Es(n)&&!ms(n.getArguments()[0])||r.isIdentifier(n)&&(gt(n)||ot(n,e))&&!vs(n)&&!As(n)&&!Ps(n,t))return!0;return!1},Rs=s=>at(s,void 0,new Set);export{ks as a,bs as b,Bs as c,Ls as d,ws as e,le as f,se as g,Ds as i,Rs as m,k as r,me as s};
|