@geekmidas/cache 0.0.3 → 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/README.md +512 -0
- package/dist/__tests__/cache.spec.cjs +30 -30
- package/dist/__tests__/cache.spec.d.cts +1 -0
- package/dist/__tests__/cache.spec.d.mts +1 -0
- package/dist/__tests__/cache.spec.mjs +1 -1
- package/dist/__tests__/integration.spec.cjs +44 -44
- package/dist/__tests__/integration.spec.d.cts +1 -0
- package/dist/__tests__/integration.spec.d.mts +1 -0
- package/dist/__tests__/integration.spec.mjs +1 -1
- package/dist/__tests__/memory.spec.cjs +44 -44
- package/dist/__tests__/memory.spec.d.cts +1 -0
- package/dist/__tests__/memory.spec.d.mts +1 -0
- package/dist/__tests__/memory.spec.mjs +1 -1
- package/dist/__tests__/upstash.spec.cjs +50 -50
- package/dist/__tests__/upstash.spec.d.cts +1 -0
- package/dist/__tests__/upstash.spec.d.mts +1 -0
- package/dist/__tests__/upstash.spec.mjs +1 -1
- 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-CVen_7Cc.d.mts +25 -0
- package/dist/index-q3xYn8_0.d.cts +25 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/memory.d.cts +11 -0
- package/dist/memory.d.mts +11 -0
- package/dist/{upstash-0RolGx7m.cjs → upstash-DiFDpOHy.cjs} +1 -1
- package/dist/upstash.cjs +1 -1
- package/dist/upstash.d.cts +12 -0
- package/dist/upstash.d.mts +12 -0
- package/dist/{vi.DgezovHB-McgltIC5.mjs → vi.bdSIJ99Y-CKSnd2bq.cjs} +3294 -1418
- package/dist/{vi.DgezovHB-NqP74KGR.cjs → vi.bdSIJ99Y-DffpE2Zw.mjs} +3255 -1408
- package/package.json +17 -9
- package/src/expo.ts +53 -0
- package/tsdown.config.ts +5 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, globalExpect, it } from "../vi.
|
|
1
|
+
import { afterEach, beforeEach, describe, globalExpect, it } from "../vi.bdSIJ99Y-DffpE2Zw.mjs";
|
|
2
2
|
import { UpstashCache } from "../upstash-_05vyc5o.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/__tests__/upstash.spec.ts
|
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
8
11
|
var __copyProps = (to, from, except, desc) => {
|
|
9
12
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
13
|
key = keys[i];
|
|
@@ -22,6 +25,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
25
|
|
|
23
26
|
//#endregion
|
|
24
27
|
|
|
28
|
+
Object.defineProperty(exports, '__commonJS', {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return __commonJS;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
25
34
|
Object.defineProperty(exports, '__toESM', {
|
|
26
35
|
enumerable: true,
|
|
27
36
|
get: function () {
|
package/dist/expo.cjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-DWy1uDak.cjs');
|
|
2
|
+
const date_fns = require_chunk.__toESM(require("date-fns"));
|
|
3
|
+
const expo_secure_store = require_chunk.__toESM(require("expo-secure-store"));
|
|
4
|
+
|
|
5
|
+
//#region src/expo.ts
|
|
6
|
+
var ExpoSecureCache = class ExpoSecureCache {
|
|
7
|
+
static getExpiryKey(key) {
|
|
8
|
+
return `${key}:expiresAt`;
|
|
9
|
+
}
|
|
10
|
+
async getExpiration(key) {
|
|
11
|
+
const result = await expo_secure_store.getItemAsync(ExpoSecureCache.getExpiryKey(key));
|
|
12
|
+
if (!result) return 0;
|
|
13
|
+
const date = new Date(JSON.parse(result));
|
|
14
|
+
const secondsLeft = (0, date_fns.differenceInSeconds)(date, /* @__PURE__ */ new Date());
|
|
15
|
+
return Math.max(secondsLeft, 0);
|
|
16
|
+
}
|
|
17
|
+
async get(key) {
|
|
18
|
+
const result = await expo_secure_store.getItemAsync(key);
|
|
19
|
+
if (!result) return void 0;
|
|
20
|
+
const expiresAt = await this.getExpiration(key);
|
|
21
|
+
if (expiresAt === 0) return void 0;
|
|
22
|
+
return JSON.parse(result);
|
|
23
|
+
}
|
|
24
|
+
async set(key, value, ttl) {
|
|
25
|
+
const expiresAt = ttl ? Date.now() + ttl * 1e3 : 0;
|
|
26
|
+
await expo_secure_store.setItemAsync(key, JSON.stringify(value));
|
|
27
|
+
await expo_secure_store.setItemAsync(ExpoSecureCache.getExpiryKey(key), JSON.stringify(expiresAt));
|
|
28
|
+
}
|
|
29
|
+
async delete(key) {
|
|
30
|
+
await expo_secure_store.deleteItemAsync(key);
|
|
31
|
+
await expo_secure_store.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.ExpoSecureCache = ExpoSecureCache;
|
package/dist/expo.d.cts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Cache } from "./index-q3xYn8_0.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/expo.d.ts
|
|
4
|
+
declare class ExpoSecureCache<T> implements Cache<T> {
|
|
5
|
+
static getExpiryKey(key: string): string;
|
|
6
|
+
private getExpiration;
|
|
7
|
+
get(key: string): Promise<T | undefined>;
|
|
8
|
+
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
9
|
+
delete(key: string): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ExpoSecureCache };
|
package/dist/expo.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Cache } from "./index-CVen_7Cc.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/expo.d.ts
|
|
4
|
+
declare class ExpoSecureCache<T> implements Cache<T> {
|
|
5
|
+
static getExpiryKey(key: string): string;
|
|
6
|
+
private getExpiration;
|
|
7
|
+
get(key: string): Promise<T | undefined>;
|
|
8
|
+
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
9
|
+
delete(key: string): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ExpoSecureCache };
|
package/dist/expo.mjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { differenceInSeconds } from "date-fns";
|
|
2
|
+
import * as SecureStore from "expo-secure-store";
|
|
3
|
+
|
|
4
|
+
//#region src/expo.ts
|
|
5
|
+
var ExpoSecureCache = class ExpoSecureCache {
|
|
6
|
+
static getExpiryKey(key) {
|
|
7
|
+
return `${key}:expiresAt`;
|
|
8
|
+
}
|
|
9
|
+
async getExpiration(key) {
|
|
10
|
+
const result = await SecureStore.getItemAsync(ExpoSecureCache.getExpiryKey(key));
|
|
11
|
+
if (!result) return 0;
|
|
12
|
+
const date = new Date(JSON.parse(result));
|
|
13
|
+
const secondsLeft = differenceInSeconds(date, /* @__PURE__ */ new Date());
|
|
14
|
+
return Math.max(secondsLeft, 0);
|
|
15
|
+
}
|
|
16
|
+
async get(key) {
|
|
17
|
+
const result = await SecureStore.getItemAsync(key);
|
|
18
|
+
if (!result) return void 0;
|
|
19
|
+
const expiresAt = await this.getExpiration(key);
|
|
20
|
+
if (expiresAt === 0) return void 0;
|
|
21
|
+
return JSON.parse(result);
|
|
22
|
+
}
|
|
23
|
+
async set(key, value, ttl) {
|
|
24
|
+
const expiresAt = ttl ? Date.now() + ttl * 1e3 : 0;
|
|
25
|
+
await SecureStore.setItemAsync(key, JSON.stringify(value));
|
|
26
|
+
await SecureStore.setItemAsync(ExpoSecureCache.getExpiryKey(key), JSON.stringify(expiresAt));
|
|
27
|
+
}
|
|
28
|
+
async delete(key) {
|
|
29
|
+
await SecureStore.deleteItemAsync(key);
|
|
30
|
+
await SecureStore.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { ExpoSecureCache };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
interface Cache<T> {
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves a value from the cache.
|
|
5
|
+
*
|
|
6
|
+
* @param key The key to retrieve the value for.
|
|
7
|
+
*/
|
|
8
|
+
get(key: string): Promise<T | undefined>;
|
|
9
|
+
/**
|
|
10
|
+
* Sets a value in the cache.
|
|
11
|
+
*
|
|
12
|
+
* @param key The key to set the value for.
|
|
13
|
+
* @param value The value to cache.
|
|
14
|
+
* @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.
|
|
15
|
+
*/
|
|
16
|
+
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Deletes a value from the cache.
|
|
19
|
+
*
|
|
20
|
+
* @param key The key to delete from the cache.
|
|
21
|
+
*/
|
|
22
|
+
delete(key: string): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { Cache };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
interface Cache<T> {
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves a value from the cache.
|
|
5
|
+
*
|
|
6
|
+
* @param key The key to retrieve the value for.
|
|
7
|
+
*/
|
|
8
|
+
get(key: string): Promise<T | undefined>;
|
|
9
|
+
/**
|
|
10
|
+
* Sets a value in the cache.
|
|
11
|
+
*
|
|
12
|
+
* @param key The key to set the value for.
|
|
13
|
+
* @param value The value to cache.
|
|
14
|
+
* @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.
|
|
15
|
+
*/
|
|
16
|
+
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Deletes a value from the cache.
|
|
19
|
+
*
|
|
20
|
+
* @param key The key to delete from the cache.
|
|
21
|
+
*/
|
|
22
|
+
delete(key: string): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { Cache };
|
package/dist/index.d.cts
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Cache } from "./index-q3xYn8_0.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/memory.d.ts
|
|
4
|
+
declare class InMemoryCache<T> implements Cache<T> {
|
|
5
|
+
private store;
|
|
6
|
+
get(key: string): Promise<T | undefined>;
|
|
7
|
+
set(key: string, value: T): Promise<void>;
|
|
8
|
+
delete(key: string): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { InMemoryCache };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Cache } from "./index-CVen_7Cc.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/memory.d.ts
|
|
4
|
+
declare class InMemoryCache<T> implements Cache<T> {
|
|
5
|
+
private store;
|
|
6
|
+
get(key: string): Promise<T | undefined>;
|
|
7
|
+
set(key: string, value: T): Promise<void>;
|
|
8
|
+
delete(key: string): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { InMemoryCache };
|
package/dist/upstash.cjs
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Cache } from "./index-q3xYn8_0.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/upstash.d.ts
|
|
4
|
+
declare class UpstashCache<T> implements Cache<T> {
|
|
5
|
+
private client;
|
|
6
|
+
constructor(url: string, token: string);
|
|
7
|
+
get(key: string): Promise<T | undefined>;
|
|
8
|
+
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
9
|
+
delete(key: string): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { UpstashCache };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Cache } from "./index-CVen_7Cc.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/upstash.d.ts
|
|
4
|
+
declare class UpstashCache<T> implements Cache<T> {
|
|
5
|
+
private client;
|
|
6
|
+
constructor(url: string, token: string);
|
|
7
|
+
get(key: string): Promise<T | undefined>;
|
|
8
|
+
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
9
|
+
delete(key: string): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { UpstashCache };
|