@gvnrdao/dh-sdk 0.0.217 → 0.0.219

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.
@@ -184,11 +184,19 @@ export declare class BitcoinOperations {
184
184
  /**
185
185
  * Get balance cache statistics
186
186
  */
187
- getBalanceCacheStats(): import("../cache/cache-manager.module").CacheStats | null;
187
+ getBalanceCacheStats(): {
188
+ size: number;
189
+ maxSize: number;
190
+ ttlMs: number;
191
+ } | null;
188
192
  /**
189
193
  * Get address cache statistics
190
194
  */
191
- getAddressCacheStats(): import("../cache/cache-manager.module").CacheStats | null;
195
+ getAddressCacheStats(): {
196
+ size: number;
197
+ maxSize: number;
198
+ ttlMs: number;
199
+ } | null;
192
200
  /**
193
201
  * Get current network configuration
194
202
  */
@@ -1,228 +1,74 @@
1
1
  /**
2
- * Generic Cache Manager Module
2
+ * Cache Manager Module
3
3
  *
4
- * Provides a type-safe, generic LRU cache with TTL support.
5
- * Can be used for any data type (Bitcoin balances, addresses, query results, etc.)
6
- *
7
- * Features:
8
- * - Generic type support
9
- * - TTL-based expiration
10
- * - LRU eviction policy
11
- * - Hit/miss statistics
12
- * - Memory-efficient
13
- * - Thread-safe operations
14
- */
15
- import { Result } from '../../types/result';
16
- import { SDKError } from '../../utils/error-handler';
17
- /**
18
- * Cache entry with metadata
4
+ * Provides a simple cache factory for SDK modules.
5
+ * Each cache is an independent LRU cache with TTL support.
19
6
  */
20
- interface CacheEntry<T> {
21
- /** Cached value */
22
- value: T;
23
- /** Unix timestamp when entry was created (ms) */
24
- timestamp: number;
25
- /** Number of times this entry was accessed */
26
- hits: number;
27
- /** Unix timestamp of last access (ms) */
28
- lastAccessed: number;
7
+ export interface CacheConfig {
8
+ maxSize: number;
9
+ ttlMs: number;
29
10
  }
30
- /**
31
- * Cache statistics
32
- */
33
11
  export interface CacheStats {
34
- /** Current number of entries in cache */
35
12
  size: number;
36
- /** Total cache hits */
37
- hits: number;
38
- /** Total cache misses */
39
- misses: number;
40
- /** Total evictions performed */
41
- evictions: number;
42
- /** Timestamp of oldest entry (ms) */
43
- oldestEntry: number;
44
- /** Timestamp of newest entry (ms) */
45
- newestEntry: number;
46
- /** Hit rate as percentage (0-100) */
47
- hitRate: number;
48
- }
49
- /**
50
- * Cache configuration
51
- */
52
- export interface CacheConfig {
53
- /** Maximum number of entries (default: 1000) */
54
- maxSize?: number;
55
- /** Time-to-live in milliseconds (default: 60000 = 1 minute) */
56
- ttlMs?: number;
57
- /** Enable debug logging (default: false) */
58
- debug?: boolean;
59
- /** Cache name for logging (default: 'Cache') */
60
- name?: string;
13
+ maxSize: number;
14
+ ttlMs: number;
61
15
  }
62
16
  /**
63
- * Generic LRU Cache with TTL support
64
- *
65
- * @template K - Key type (usually string)
66
- * @template V - Value type
67
- *
68
- * @example
69
- * ```typescript
70
- * // Create a cache for Bitcoin balances
71
- * const balanceCache = new LRUCache<string, BitcoinBalance>({
72
- * maxSize: 500,
73
- * ttlMs: 60000,
74
- * name: 'BitcoinBalance'
75
- * });
76
- *
77
- * // Set value
78
- * balanceCache.set('bc1q...', { balance: Satoshis(50000000n) });
79
- *
80
- * // Get value
81
- * const balance = balanceCache.get('bc1q...');
82
- * if (balance) {
83
- * console.log('Cached balance:', balance.balance);
84
- * }
85
- * ```
17
+ * Simple LRU Cache with TTL support
86
18
  */
87
- export declare class LRUCache<K, V> {
19
+ export declare class Cache<T = any> {
88
20
  private cache;
89
21
  private readonly maxSize;
90
22
  private readonly ttlMs;
91
- private readonly debug;
92
- private readonly name;
93
- private stats;
94
- constructor(config?: CacheConfig);
23
+ constructor(config: CacheConfig);
95
24
  /**
96
25
  * Get value from cache
97
- *
98
- * Returns null if:
99
- * - Key not found
100
- * - Entry has expired
101
- *
102
- * @param key - Cache key
103
- * @returns Cached value or null
104
- */
105
- get(key: K): V | null;
106
- /**
107
- * Get value from cache with Result wrapper
108
- *
109
- * Useful when you want to distinguish between "not found" and "expired"
110
26
  */
111
- getResult(key: K): Result<V, SDKError>;
27
+ get(key: string): T | undefined;
112
28
  /**
113
29
  * Set value in cache
114
- *
115
- * If cache is full, evicts the least recently used entry
116
- *
117
- * @param key - Cache key
118
- * @param value - Value to cache
119
- * @param ttl - Optional custom TTL for this entry (ms)
120
30
  */
121
- set(key: K, value: V, ttl?: number): void;
31
+ set(key: string, value: T, ttl?: number): void;
122
32
  /**
123
- * Set value in cache with Result wrapper
33
+ * Check if key exists in cache
124
34
  */
125
- setResult(key: K, value: V, ttl?: number): Result<void, SDKError>;
126
- /**
127
- * Check if key exists in cache (without affecting stats)
128
- */
129
- has(key: K): boolean;
35
+ has(key: string): boolean;
130
36
  /**
131
- * Delete specific key from cache
37
+ * Delete key from cache
132
38
  */
133
- delete(key: K): boolean;
39
+ delete(key: string): boolean;
134
40
  /**
135
- * Clear entire cache
41
+ * Clear all cache entries
136
42
  */
137
43
  clear(): void;
138
44
  /**
139
- * Get current cache size
140
- */
141
- size(): number;
142
- /**
143
- * Get cache statistics
144
- */
145
- getStats(): CacheStats;
146
- /**
147
- * Get hit rate percentage
148
- */
149
- getHitRate(): number;
150
- /**
151
- * Get all cached keys (for debugging)
152
- */
153
- getKeys(): K[];
154
- /**
155
- * Get all cached values (for debugging)
156
- */
157
- getValues(): V[];
158
- /**
159
- * Get all cache entries with metadata (for debugging)
160
- */
161
- getEntries(): Array<{
162
- key: K;
163
- value: V;
164
- metadata: Omit<CacheEntry<V>, 'value'>;
165
- }>;
166
- /**
167
- * Clean up expired entries
168
- *
169
- * Useful for periodic maintenance
170
- *
171
- * @returns Number of entries cleaned
45
+ * Clean expired entries
172
46
  */
173
47
  cleanExpired(): number;
174
48
  /**
175
- * Check if cache entry is expired
176
- */
177
- private isExpired;
178
- /**
179
- * Evict least recently used entry
180
- */
181
- private evictLRU;
182
- /**
183
- * Get or compute value
184
- *
185
- * If key exists in cache, returns cached value.
186
- * Otherwise, computes value using provided function and caches it.
187
- *
188
- * @param key - Cache key
189
- * @param compute - Function to compute value if not in cache
190
- * @param ttl - Optional custom TTL for this entry
191
- * @returns Cached or computed value
192
- */
193
- getOrCompute(key: K, compute: () => Promise<V>, ttl?: number): Promise<V>;
194
- /**
195
- * Get or compute value with Result wrapper
49
+ * Get cache statistics
196
50
  */
197
- getOrComputeResult(key: K, compute: () => Promise<Result<V, SDKError>>, ttl?: number): Promise<Result<V, SDKError>>;
51
+ getStats(): {
52
+ size: number;
53
+ maxSize: number;
54
+ ttlMs: number;
55
+ };
198
56
  }
199
57
  /**
200
- * Generic cache interface for type safety
201
- */
202
- export interface Cache<T> {
203
- get(key: string): T | null | undefined;
204
- set(key: string, value: T): void;
205
- delete(key: string): boolean;
206
- clear(): void;
207
- has(key: string): boolean;
208
- size(): number;
209
- getStats(): CacheStats;
210
- }
211
- /**
212
- * Cache Manager - Factory for creating specialized caches
58
+ * Cache Manager
59
+ *
60
+ * Factory for creating named caches with specific configurations
213
61
  */
214
62
  export declare class CacheManager {
215
63
  private caches;
216
- private readonly globalConfig;
217
- constructor(globalConfig?: CacheConfig);
64
+ private readonly debug;
65
+ constructor(config?: {
66
+ debug?: boolean;
67
+ });
218
68
  /**
219
- * Create or get a named cache
220
- *
221
- * @param name - Unique cache name
222
- * @param config - Optional cache-specific configuration
223
- * @returns LRU cache instance
69
+ * Get or create a cache instance
224
70
  */
225
- getCache<K, V>(name: string, config?: CacheConfig): LRUCache<K, V>;
71
+ getCache<T = any>(name: string, config: CacheConfig): Cache<T>;
226
72
  /**
227
73
  * Clear all caches
228
74
  */
@@ -234,18 +80,13 @@ export declare class CacheManager {
234
80
  /**
235
81
  * Get statistics for all caches
236
82
  */
237
- getAllStats(): Record<string, CacheStats>;
238
- /**
239
- * Get list of all cache names
240
- */
241
- getCacheNames(): string[];
83
+ getAllStats(): Record<string, ReturnType<Cache["getStats"]>>;
242
84
  /**
243
- * Delete a named cache
85
+ * Destroy cache manager
244
86
  */
245
- deleteCache(name: string): boolean;
87
+ destroy(): void;
246
88
  }
247
- /**
248
- * Factory function to create a CacheManager instance
249
- */
250
- export declare function createCacheManager(config?: CacheConfig): CacheManager;
251
- export {};
89
+ export { Cache as LRUCache };
90
+ export declare function createCacheManager(config?: {
91
+ debug?: boolean;
92
+ }): CacheManager;
@@ -563,7 +563,11 @@ export declare class DiamondHandsSDK {
563
563
  /**
564
564
  * Get cache statistics
565
565
  */
566
- getCacheStats(): Record<string, import("./cache/cache-manager.module").CacheStats>;
566
+ getCacheStats(): Record<string, {
567
+ size: number;
568
+ maxSize: number;
569
+ ttlMs: number;
570
+ }>;
567
571
  /**
568
572
  * Get contract manager (for advanced usage)
569
573
  */
@@ -196,7 +196,11 @@ export declare class LoanQuery {
196
196
  /**
197
197
  * Get cache statistics
198
198
  */
199
- getCacheStats(): import("../cache/cache-manager.module").CacheStats | null;
199
+ getCacheStats(): {
200
+ size: number;
201
+ maxSize: number;
202
+ ttlMs: number;
203
+ } | null;
200
204
  }
201
205
  /**
202
206
  * Factory function to create a LoanQuery instance
@@ -124,7 +124,11 @@ export declare class PKPManager {
124
124
  /**
125
125
  * Get cache statistics
126
126
  */
127
- getCacheStats(): import("../cache/cache-manager.module").CacheStats | null;
127
+ getCacheStats(): {
128
+ size: number;
129
+ maxSize: number;
130
+ ttlMs: number;
131
+ } | null;
128
132
  }
129
133
  /**
130
134
  * Factory function to create a PKPManager instance
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@gvnrdao/dh-sdk",
3
- "version": "0.0.217",
3
+ "version": "0.0.219",
4
4
  "description": "TypeScript SDK for Diamond Hands Protocol - Bitcoin-backed lending with LIT Protocol PKPs",
5
5
  "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
6
+ "types": "dist/sdk/src/index.d.ts",
7
7
  "module": "dist/index.mjs",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/index.d.ts",
10
+ "types": "./dist/sdk/src/index.d.ts",
11
11
  "browser": "./dist/index.mjs",
12
12
  "import": "./dist/index.mjs",
13
13
  "require": "./dist/index.js"
14
14
  },
15
15
  "./server": {
16
- "types": "./dist/server.d.ts",
16
+ "types": "./dist/sdk/src/server.d.ts",
17
17
  "import": "./dist/server.mjs",
18
18
  "require": "./dist/server.js"
19
19
  }
@@ -70,8 +70,8 @@
70
70
  },
71
71
  "sideEffects": false,
72
72
  "dependencies": {
73
- "@gvnrdao/dh-lit-actions": "^0.0.281",
74
- "@gvnrdao/dh-lit-ops": "^0.0.254",
73
+ "@gvnrdao/dh-lit-actions": "^0.0.283",
74
+ "@gvnrdao/dh-lit-ops": "^0.0.256",
75
75
  "@noble/hashes": "^1.5.0",
76
76
  "axios": "^1.15.2",
77
77
  "bech32": "^2.0.0",