11import { v } from "convex/values" ;
22import { query , mutation , internalMutation , internalAction } from "./_generated/server" ;
3- import { internal } from "./_generated/api" ;
3+ import { internal , api } from "./_generated/api" ;
44
55// Get analytics for a specific coin
66export const getCoinAnalytics = query ( {
@@ -110,22 +110,23 @@ export const fetchRealTimeAnalytics = internalAction({
110110 args : {
111111 coinId : v . id ( "memeCoins" ) ,
112112 } ,
113- handler : async ( ctx , args ) => {
113+ handler : async ( ctx , args ) : Promise < { success : boolean ; data ?: any ; error ?: string ; cachedData ?: any } > => {
114114 // Get coin details
115- const coin = await ctx . runQuery ( internal . memeCoins . getById , { coinId : args . coinId } ) ;
115+ // @ts -ignore - Type instantiation depth issue
116+ const coin = await ctx . runQuery ( api . memeCoins . getById , { coinId : args . coinId } ) ;
116117 if ( ! coin ) {
117118 throw new Error ( "Coin not found" ) ;
118119 }
119120
120121 // Get deployment details
121- const deployment = await ctx . runQuery ( internal . memeCoins . getDeployment , { coinId : args . coinId } ) ;
122+ const deployment : any = await ctx . runQuery ( api . memeCoins . getDeployment , { coinId : args . coinId } ) ;
122123 if ( ! deployment || ! deployment . contractAddress ) {
123124 throw new Error ( "Coin not deployed" ) ;
124125 }
125126
126127 try {
127128 // Fetch data from multiple sources in parallel
128- const [ priceData , dexData , blockchainData ] = await Promise . all ( [
129+ const [ priceData , dexData , blockchainData ] : [ any , any , any ] = await Promise . all ( [
129130 // Fetch price data from CoinGecko
130131 ctx . runAction ( internal . analytics . coingecko . fetchTokenPriceData , {
131132 contractAddress : deployment . contractAddress ,
@@ -178,14 +179,14 @@ export const fetchRealTimeAnalytics = internalAction({
178179 console . error ( "Failed to fetch real-time analytics:" , error ) ;
179180
180181 // In case of API failures, try to use cached data
181- const latestAnalytics = await ctx . runQuery ( internal . analytics . getLatestAnalytics , {
182+ const latestAnalytics : any = await ctx . runQuery ( api . analytics . getLatestAnalytics , {
182183 coinId : args . coinId
183184 } ) ;
184185
185186 if ( latestAnalytics ) {
186187 return {
187188 success : false ,
188- error : error . message ,
189+ error : ( error as Error ) . message ,
189190 cachedData : latestAnalytics
190191 } ;
191192 }
@@ -198,9 +199,9 @@ export const fetchRealTimeAnalytics = internalAction({
198199// Batch update analytics for all deployed coins
199200export const batchUpdateAnalytics = internalAction ( {
200201 args : { } ,
201- handler : async ( ctx ) => {
202+ handler : async ( ctx ) : Promise < { total : number ; successful : number ; failed : number ; results : any [ ] } > => {
202203 // Get all deployed coins
203- const deployedCoins = await ctx . runQuery ( internal . memeCoins . getAllDeployedCoins , { } ) ;
204+ const deployedCoins : any [ ] = await ctx . runQuery ( api . memeCoins . getAllDeployedCoins , { } ) ;
204205
205206 const results = [ ] ;
206207
@@ -210,7 +211,7 @@ export const batchUpdateAnalytics = internalAction({
210211 const batch = deployedCoins . slice ( i , i + batchSize ) ;
211212
212213 const batchResults = await Promise . allSettled (
213- batch . map ( coin =>
214+ batch . map ( ( coin : any ) =>
214215 ctx . runAction ( internal . analytics . fetchRealTimeAnalytics , {
215216 coinId : coin . _id
216217 } )
@@ -261,19 +262,19 @@ export const getHistoricalPrices = internalAction({
261262 coinId : v . id ( "memeCoins" ) ,
262263 days : v . optional ( v . number ( ) )
263264 } ,
264- handler : async ( ctx , args ) => {
265- const coin = await ctx . runQuery ( internal . memeCoins . getById , { coinId : args . coinId } ) ;
265+ handler : async ( ctx , args ) : Promise < any > => {
266+ const coin = await ctx . runQuery ( api . memeCoins . getById , { coinId : args . coinId } ) ;
266267 if ( ! coin ) {
267268 throw new Error ( "Coin not found" ) ;
268269 }
269270
270- const deployment = await ctx . runQuery ( internal . memeCoins . getDeployment , { coinId : args . coinId } ) ;
271+ const deployment : any = await ctx . runQuery ( api . memeCoins . getDeployment , { coinId : args . coinId } ) ;
271272 if ( ! deployment || ! deployment . contractAddress ) {
272273 throw new Error ( "Coin not deployed" ) ;
273274 }
274275
275276 try {
276- const historicalData = await ctx . runAction ( internal . analytics . coingecko . fetchHistoricalPrices , {
277+ const historicalData : any = await ctx . runAction ( internal . analytics . coingecko . fetchHistoricalPrices , {
277278 contractAddress : deployment . contractAddress ,
278279 blockchain : deployment . blockchain ,
279280 days : args . days || 7
@@ -292,19 +293,19 @@ export const getDEXPools = internalAction({
292293 args : {
293294 coinId : v . id ( "memeCoins" )
294295 } ,
295- handler : async ( ctx , args ) => {
296- const coin = await ctx . runQuery ( internal . memeCoins . getById , { coinId : args . coinId } ) ;
296+ handler : async ( ctx , args ) : Promise < any > => {
297+ const coin = await ctx . runQuery ( api . memeCoins . getById , { coinId : args . coinId } ) ;
297298 if ( ! coin ) {
298299 throw new Error ( "Coin not found" ) ;
299300 }
300301
301- const deployment = await ctx . runQuery ( internal . memeCoins . getDeployment , { coinId : args . coinId } ) ;
302+ const deployment : any = await ctx . runQuery ( api . memeCoins . getDeployment , { coinId : args . coinId } ) ;
302303 if ( ! deployment || ! deployment . contractAddress ) {
303304 throw new Error ( "Coin not deployed" ) ;
304305 }
305306
306307 try {
307- const poolsData = await ctx . runAction ( internal . analytics . geckoterminal . fetchTokenPools , {
308+ const poolsData : any = await ctx . runAction ( internal . analytics . geckoterminal . fetchTokenPools , {
308309 contractAddress : deployment . contractAddress ,
309310 blockchain : deployment . blockchain
310311 } ) ;
@@ -320,14 +321,14 @@ export const getDEXPools = internalAction({
320321// Clear expired cache entries (to be called periodically)
321322export const clearAnalyticsCache = internalAction ( {
322323 args : { } ,
323- handler : async ( ctx ) => {
324- const results = await Promise . all ( [
324+ handler : async ( ctx ) : Promise < { totalCleared : number ; services : { coingecko : number ; geckoterminal : number ; blockchainExplorers : number } } > => {
325+ const results : any [ ] = await Promise . all ( [
325326 ctx . runAction ( internal . analytics . coingecko . clearExpiredCache , { } ) ,
326327 ctx . runAction ( internal . analytics . geckoterminal . clearExpiredCache , { } ) ,
327328 ctx . runAction ( internal . analytics . blockchainExplorers . clearExpiredCache , { } )
328329 ] ) ;
329330
330- const totalCleared = results . reduce ( ( sum , result ) => sum + result . cleared , 0 ) ;
331+ const totalCleared = results . reduce ( ( sum : number , result : any ) => sum + result . cleared , 0 ) ;
331332
332333 return {
333334 totalCleared,
0 commit comments