UNPKG

wisdom-sdk

Version:

Core business logic and data access layer for prediction markets

109 lines (107 loc) 4.38 kB
declare const KV_PREFIXES: { readonly MARKET: "market"; readonly MARKET_IDS: "market_ids"; readonly USER_MARKETS: "user_markets"; readonly MARKET_PARTICIPANTS: "market_participants"; readonly MARKET_CATEGORY: "market_category"; readonly MARKET_STATUS: "market_status"; readonly PREDICTION: "prediction"; readonly USER_PREDICTIONS: "user_predictions"; readonly MARKET_PREDICTIONS: "market_predictions"; readonly PREDICTION_NFT: "prediction_nft"; readonly USER_BALANCE: "user_balance"; readonly USER_STATS: "user_stats"; readonly LEADERBOARD: "leaderboard"; readonly LEADERBOARD_EARNINGS: "leaderboard_earnings"; readonly LEADERBOARD_ACCURACY: "leaderboard_accuracy"; readonly BUG_REPORT: "bug_report"; readonly BUG_REPORT_IDS: "bug_report_ids"; readonly USER_BUG_REPORTS: "user_bug_reports"; readonly CUSTODY_TRANSACTION: "custody_transaction"; readonly CUSTODY_TRANSACTION_IDS: "custody_transaction_ids"; readonly USER_TRANSACTIONS: "user_transactions"; readonly SIGNER_TRANSACTIONS: "signer_transactions"; readonly MARKET_TRANSACTIONS: "market_transactions"; readonly CUSTODY_NFT_RECEIPT: "custody_nft_receipt"; readonly CLAIM_REWARD_TRANSACTION: "claim_reward_transaction"; readonly USER_CLAIM_REWARDS: "user_claim_rewards"; }; type EntityType = keyof typeof KV_PREFIXES; /** * Get a formatted key for a specific entity */ declare function getKey(entityType: EntityType, id?: string): string; /** * Store an entity in KV */ declare function storeEntity<T>(entityType: EntityType, id: string, data: T): Promise<T>; /** * Get an entity from KV - with backward compatibility */ declare function getEntity<T>(entityType: EntityType, id: string): Promise<T | null>; /** * Delete an entity from KV */ declare function deleteEntity(entityType: EntityType, id: string): Promise<boolean>; /** * Add an ID to a set - with backward compatibility */ declare function addToSet(setType: EntityType, id: string, memberId: string): Promise<boolean>; /** * Remove an ID from a set */ declare function removeFromSet(setType: EntityType, id: string, memberId: string): Promise<boolean>; /** * Get all members of a set - with backward compatibility */ declare function getSetMembers(setType: EntityType, id: string): Promise<string[]>; /** * Check if a member is in a set */ declare function isSetMember(setType: EntityType, id: string, memberId: string): Promise<boolean>; /** * Add a member to a sorted set with score */ declare function addToSortedSet(setType: EntityType, memberId: string, score: number): Promise<boolean>; /** * Get top members from a sorted set */ declare function getTopFromSortedSet(setType: EntityType, limit?: number, reverse?: boolean): Promise<string[]>; /** * Get scores for specific members from a sorted set * Returns a map of memberId -> score */ declare function getScoresFromSortedSet(setType: EntityType, memberIds: string[]): Promise<Record<string, number>>; /** * Get all keys matching a pattern */ declare function getKeys(pattern: string): Promise<string[]>; /** * Check if a key exists */ declare function keyExists(entityType: EntityType, id: string): Promise<boolean>; /** * Debug function to get information about KV store */ declare function getDebugInfo(): Promise<Record<string, unknown>>; /** * Transaction interface for atomic operations */ interface KvTransaction { operations: Array<{ type: 'entity' | 'set' | 'sortedSet'; entityType: EntityType; id: string; data?: unknown; }>; addEntity<T>(entityType: EntityType, id: string, data: T): Promise<void>; addToSetInTransaction(setType: EntityType, id: string, memberId: string): Promise<void>; addToSortedSetInTransaction(setType: EntityType, memberId: string, score: number): Promise<void>; execute(): Promise<boolean>; } /** * Start a Redis transaction for atomic operations * @returns A transaction object with methods that queue commands to be executed atomically */ declare function startTransaction(): Promise<KvTransaction>; export { type EntityType, KV_PREFIXES, type KvTransaction, addToSet, addToSortedSet, deleteEntity, getDebugInfo, getEntity, getKey, getKeys, getScoresFromSortedSet, getSetMembers, getTopFromSortedSet, isSetMember, keyExists, removeFromSet, startTransaction, storeEntity };