@geekmidas/cache 0.0.4 → 0.0.5
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/__tests__/cache.spec.cjs +30 -31
- package/dist/__tests__/cache.spec.mjs +18 -18
- package/dist/__tests__/integration.spec.cjs +44 -45
- package/dist/__tests__/integration.spec.mjs +26 -26
- package/dist/__tests__/memory.spec.cjs +44 -45
- package/dist/__tests__/memory.spec.mjs +23 -23
- package/dist/__tests__/upstash.spec.cjs +50 -51
- package/dist/__tests__/upstash.spec.mjs +23 -23
- package/dist/{chunk-CUT6urMc.cjs → chunk-DWy1uDak.cjs} +9 -0
- package/dist/expo.cjs +36 -0
- package/dist/expo.d.cts +12 -0
- package/dist/expo.d.mts +12 -0
- package/dist/expo.mjs +35 -0
- package/dist/index.d.mts +1 -1
- package/dist/magic-string.es-BvJNBYzY.mjs +1014 -0
- package/dist/magic-string.es-CKiDiYoS.cjs +1015 -0
- package/dist/memory.d.mts +1 -1
- package/dist/memory.mjs +1 -1
- package/dist/{upstash-0RolGx7m.cjs → upstash-DiFDpOHy.cjs} +1 -1
- package/dist/upstash.cjs +1 -1
- package/dist/upstash.d.mts +1 -1
- package/dist/upstash.mjs +1 -1
- package/dist/vi.bdSIJ99Y-CKSnd2bq.cjs +14955 -0
- package/dist/vi.bdSIJ99Y-DffpE2Zw.mjs +14951 -0
- package/package.json +11 -3
- package/src/expo.ts +53 -0
- package/tsdown.config.ts +5 -0
- /package/dist/{index-BPnJ3lrS.d.mts → index-CVen_7Cc.d.mts} +0 -0
- /package/dist/{memory-NQi0XmZ2.mjs → memory-YteQXj7m.mjs} +0 -0
- /package/dist/{upstash-CTY-M8vR.mjs → upstash-_05vyc5o.mjs} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/cache",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Type-safe email client with SMTP support and React templates",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -19,15 +19,23 @@
|
|
|
19
19
|
"types": "./dist/upstash.d.ts",
|
|
20
20
|
"import": "./dist/upstash.mjs",
|
|
21
21
|
"require": "./dist/upstash.cjs"
|
|
22
|
+
},
|
|
23
|
+
"./expo": {
|
|
24
|
+
"types": "./dist/expo.d.ts",
|
|
25
|
+
"import": "./dist/expo.mjs",
|
|
26
|
+
"require": "./dist/expo.cjs"
|
|
22
27
|
}
|
|
23
28
|
},
|
|
24
29
|
"publishConfig": {
|
|
25
30
|
"registry": "https://registry.npmjs.org/",
|
|
26
31
|
"access": "public"
|
|
27
32
|
},
|
|
28
|
-
"dependencies": {
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"date-fns": "~4.1.0"
|
|
35
|
+
},
|
|
29
36
|
"devDependencies": {},
|
|
30
37
|
"peerDependencies": {
|
|
31
|
-
"@upstash/redis": "~1.35.1"
|
|
38
|
+
"@upstash/redis": "~1.35.1",
|
|
39
|
+
"expo-secure-store": "^14.2.3"
|
|
32
40
|
}
|
|
33
41
|
}
|
package/src/expo.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { differenceInSeconds } from 'date-fns';
|
|
2
|
+
import * as SecureStore from 'expo-secure-store';
|
|
3
|
+
import type { Cache } from './index';
|
|
4
|
+
|
|
5
|
+
export class ExpoSecureCache<T> implements Cache<T> {
|
|
6
|
+
static getExpiryKey(key: string): string {
|
|
7
|
+
return `${key}:expiresAt`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
private async getExpiration(key: string): Promise<number> {
|
|
11
|
+
const result = await SecureStore.getItemAsync(
|
|
12
|
+
ExpoSecureCache.getExpiryKey(key),
|
|
13
|
+
);
|
|
14
|
+
if (!result) {
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const date = new Date(JSON.parse(result));
|
|
19
|
+
|
|
20
|
+
const secondsLeft = differenceInSeconds(date, new Date());
|
|
21
|
+
|
|
22
|
+
return Math.max(secondsLeft, 0);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Implementation details
|
|
26
|
+
async get(key: string): Promise<T | undefined> {
|
|
27
|
+
const result = await SecureStore.getItemAsync(key);
|
|
28
|
+
if (!result) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const expiresAt = await this.getExpiration(key);
|
|
33
|
+
if (expiresAt === 0) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return JSON.parse(result) as T;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async set(key: string, value: T, ttl?: number): Promise<void> {
|
|
41
|
+
const expiresAt = ttl ? Date.now() + ttl * 1000 : 0;
|
|
42
|
+
await SecureStore.setItemAsync(key, JSON.stringify(value));
|
|
43
|
+
await SecureStore.setItemAsync(
|
|
44
|
+
ExpoSecureCache.getExpiryKey(key),
|
|
45
|
+
JSON.stringify(expiresAt),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async delete(key: string): Promise<void> {
|
|
50
|
+
await SecureStore.deleteItemAsync(key);
|
|
51
|
+
await SecureStore.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));
|
|
52
|
+
}
|
|
53
|
+
}
|
package/tsdown.config.ts
ADDED
|
File without changes
|
|
File without changes
|
|
File without changes
|