@tekir/cache 0.1.6 → 0.1.7

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/cache.d.ts CHANGED
@@ -41,7 +41,7 @@ export declare class Cache {
41
41
  * @param key - The cache key.
42
42
  * @returns The cached value, or `null` if not found or expired.
43
43
  */
44
- get<T = unknown>(key: string): Promise<T | null>;
44
+ get<T = any>(key: string): Promise<T | null>;
45
45
  /**
46
46
  * Set a value in the default store.
47
47
  *
@@ -28,7 +28,7 @@ export declare class DatabaseCacheStore implements CacheStore {
28
28
  * @param key - The cache key.
29
29
  * @returns The stored value parsed from JSON, or `null`.
30
30
  */
31
- get<T = unknown>(key: string): Promise<T | null>;
31
+ get<T = any>(key: string): Promise<T | null>;
32
32
  /**
33
33
  * Store a value under the given key, reptekirg any existing entry.
34
34
  *
@@ -19,7 +19,7 @@ export declare class MemoryCacheStore implements CacheStore {
19
19
  * @param key - The cache key.
20
20
  * @returns The stored value cast to `T`, or `null`.
21
21
  */
22
- get<T = unknown>(key: string): Promise<T | null>;
22
+ get<T = any>(key: string): Promise<T | null>;
23
23
  /**
24
24
  * Store a value under the given key with an optional TTL.
25
25
  *
@@ -39,7 +39,7 @@ export declare class RedisCacheStore implements CacheStore {
39
39
  * const value = await store.get<string>('greeting') // 'hello' or null
40
40
  * ```
41
41
  */
42
- get<T = unknown>(key: string): Promise<T | null>;
42
+ get<T = any>(key: string): Promise<T | null>;
43
43
  /**
44
44
  * Store a value under the given key with an optional TTL.
45
45
  * The value is serialized to JSON before being sent to Redis.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tekir/cache",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "In-memory, Redis, and database caching abstraction",
5
5
  "author": "dev@tekir.io",
6
6
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  }
40
40
  },
41
41
  "dependencies": {
42
- "@tekir/core": "^0.1.3"
42
+ "@tekir/core": "^0.1.27"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@tekir/redis": "^0.1.0"
package/src/cache.ts CHANGED
@@ -56,7 +56,7 @@ export class Cache {
56
56
  * @param key - The cache key.
57
57
  * @returns The cached value, or `null` if not found or expired.
58
58
  */
59
- async get<T = unknown>(key: string): Promise<T | null> { return this.store().get<T>(key) }
59
+ async get<T = any>(key: string): Promise<T | null> { return this.store().get<T>(key) }
60
60
 
61
61
  /**
62
62
  * Set a value in the default store.
@@ -44,7 +44,7 @@ export class DatabaseCacheStore implements CacheStore {
44
44
  * @param key - The cache key.
45
45
  * @returns The stored value parsed from JSON, or `null`.
46
46
  */
47
- async get<T = unknown>(key: string): Promise<T | null> {
47
+ async get<T = any>(key: string): Promise<T | null> {
48
48
  await this._ensureTable()
49
49
  const row = await this.db.queryOne(`SELECT value, expires_at FROM "${this.table}" WHERE key = ?`, [key]) as CacheDbRow | null
50
50
  if (!row) return null
@@ -21,7 +21,7 @@ export class MemoryCacheStore implements CacheStore {
21
21
  * @param key - The cache key.
22
22
  * @returns The stored value cast to `T`, or `null`.
23
23
  */
24
- async get<T = unknown>(key: string): Promise<T | null> {
24
+ async get<T = any>(key: string): Promise<T | null> {
25
25
  const entry = this.data.get(key)
26
26
  if (!entry) return null
27
27
  if (entry.expiresAt && Date.now() > entry.expiresAt) {
@@ -56,7 +56,7 @@ export class RedisCacheStore implements CacheStore {
56
56
  * const value = await store.get<string>('greeting') // 'hello' or null
57
57
  * ```
58
58
  */
59
- async get<T = unknown>(key: string): Promise<T | null> {
59
+ async get<T = any>(key: string): Promise<T | null> {
60
60
  const val = await this.redis.get(this.prefix + key)
61
61
  if (val === null) return null
62
62
  try { return JSON.parse(val) as T } catch { return val as unknown as T }