@geekmidas/cache 0.0.4 → 0.0.6
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 +32 -32
- package/dist/__tests__/cache.spec.mjs +19 -18
- package/dist/__tests__/integration.spec.cjs +46 -46
- package/dist/__tests__/integration.spec.mjs +27 -26
- package/dist/__tests__/memory.spec.cjs +46 -46
- package/dist/__tests__/memory.spec.mjs +24 -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-BPnJ3lrS.d.mts → index-B6eF5Yxi.d.cts} +9 -1
- package/dist/{index-q3xYn8_0.d.cts → index-Bv61mxVT.d.mts} +9 -1
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +3 -0
- package/dist/magic-string.es-CBih0MJw.mjs +1014 -0
- package/dist/magic-string.es-KiPEzMtt.cjs +1015 -0
- package/dist/memory-Csy6J-Ak.cjs +39 -0
- package/dist/memory-QDTnSEX5.mjs +33 -0
- package/dist/memory.cjs +2 -1
- package/dist/memory.d.cts +4 -2
- package/dist/memory.d.mts +4 -2
- package/dist/memory.mjs +2 -1
- package/dist/src-C7d6HaTp.cjs +19 -0
- package/dist/src-DVpoP03o.mjs +13 -0
- package/dist/{upstash-CTY-M8vR.mjs → upstash-CXy_duOa.mjs} +5 -0
- package/dist/{upstash-0RolGx7m.cjs → upstash-u8Hs4sZG.cjs} +6 -1
- package/dist/upstash.cjs +1 -1
- package/dist/upstash.d.cts +2 -1
- package/dist/upstash.d.mts +2 -1
- package/dist/upstash.mjs +1 -1
- package/dist/vi.bdSIJ99Y-B-qkABPq.cjs +14955 -0
- package/dist/vi.bdSIJ99Y-CB5havZF.mjs +14951 -0
- package/package.json +11 -3
- package/src/expo.ts +51 -0
- package/src/index.ts +25 -0
- package/src/memory.ts +22 -2
- package/src/upstash.ts +10 -0
- package/tsdown.config.ts +5 -0
- package/dist/memory-NQi0XmZ2.mjs +0 -16
- package/dist/memory-n6Iosq6J.cjs +0 -22
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-DWy1uDak.cjs');
|
|
2
|
+
const require_src = require('./src-C7d6HaTp.cjs');
|
|
3
|
+
const date_fns = require_chunk.__toESM(require("date-fns"));
|
|
4
|
+
|
|
5
|
+
//#region src/memory.ts
|
|
6
|
+
var InMemoryCache = class {
|
|
7
|
+
store = /* @__PURE__ */ new Map();
|
|
8
|
+
expirations = /* @__PURE__ */ new Map();
|
|
9
|
+
async get(key) {
|
|
10
|
+
const expiration = await this.ttl(key);
|
|
11
|
+
if (!expiration) {
|
|
12
|
+
await this.delete(key);
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
return this.store.get(key);
|
|
16
|
+
}
|
|
17
|
+
async ttl(key) {
|
|
18
|
+
const expiration = this.expirations.get(key);
|
|
19
|
+
if (!expiration) return 0;
|
|
20
|
+
return require_src.getExpirationInSeconds(expiration);
|
|
21
|
+
}
|
|
22
|
+
async set(key, value, ttl = 600) {
|
|
23
|
+
this.store.set(key, value);
|
|
24
|
+
const now = /* @__PURE__ */ new Date();
|
|
25
|
+
const expiresAt = (0, date_fns.addSeconds)(now, ttl);
|
|
26
|
+
this.expirations.set(key, expiresAt);
|
|
27
|
+
}
|
|
28
|
+
async delete(key) {
|
|
29
|
+
this.store.delete(key);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
Object.defineProperty(exports, 'InMemoryCache', {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () {
|
|
37
|
+
return InMemoryCache;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getExpirationInSeconds } from "./src-DVpoP03o.mjs";
|
|
2
|
+
import { addSeconds } from "date-fns";
|
|
3
|
+
|
|
4
|
+
//#region src/memory.ts
|
|
5
|
+
var InMemoryCache = class {
|
|
6
|
+
store = /* @__PURE__ */ new Map();
|
|
7
|
+
expirations = /* @__PURE__ */ new Map();
|
|
8
|
+
async get(key) {
|
|
9
|
+
const expiration = await this.ttl(key);
|
|
10
|
+
if (!expiration) {
|
|
11
|
+
await this.delete(key);
|
|
12
|
+
return void 0;
|
|
13
|
+
}
|
|
14
|
+
return this.store.get(key);
|
|
15
|
+
}
|
|
16
|
+
async ttl(key) {
|
|
17
|
+
const expiration = this.expirations.get(key);
|
|
18
|
+
if (!expiration) return 0;
|
|
19
|
+
return getExpirationInSeconds(expiration);
|
|
20
|
+
}
|
|
21
|
+
async set(key, value, ttl = 600) {
|
|
22
|
+
this.store.set(key, value);
|
|
23
|
+
const now = /* @__PURE__ */ new Date();
|
|
24
|
+
const expiresAt = addSeconds(now, ttl);
|
|
25
|
+
this.expirations.set(key, expiresAt);
|
|
26
|
+
}
|
|
27
|
+
async delete(key) {
|
|
28
|
+
this.store.delete(key);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { InMemoryCache };
|
package/dist/memory.cjs
CHANGED
package/dist/memory.d.cts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-B6eF5Yxi.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/memory.d.ts
|
|
4
4
|
declare class InMemoryCache<T> implements Cache<T> {
|
|
5
5
|
private store;
|
|
6
|
+
private expirations;
|
|
6
7
|
get(key: string): Promise<T | undefined>;
|
|
7
|
-
|
|
8
|
+
ttl(key: string): Promise<number>;
|
|
9
|
+
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
8
10
|
delete(key: string): Promise<void>;
|
|
9
11
|
}
|
|
10
12
|
//#endregion
|
package/dist/memory.d.mts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-Bv61mxVT.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/memory.d.ts
|
|
4
4
|
declare class InMemoryCache<T> implements Cache<T> {
|
|
5
5
|
private store;
|
|
6
|
+
private expirations;
|
|
6
7
|
get(key: string): Promise<T | undefined>;
|
|
7
|
-
|
|
8
|
+
ttl(key: string): Promise<number>;
|
|
9
|
+
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
8
10
|
delete(key: string): Promise<void>;
|
|
9
11
|
}
|
|
10
12
|
//#endregion
|
package/dist/memory.mjs
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-DWy1uDak.cjs');
|
|
2
|
+
const date_fns = require_chunk.__toESM(require("date-fns"));
|
|
3
|
+
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
const getExpirationInSeconds = (expiresAt) => {
|
|
6
|
+
if (!expiresAt) return 0;
|
|
7
|
+
const expirationDate = new Date(expiresAt);
|
|
8
|
+
const now = /* @__PURE__ */ new Date();
|
|
9
|
+
const secondsLeft = (0, date_fns.differenceInSeconds)(expirationDate, now);
|
|
10
|
+
return Math.max(secondsLeft, 0);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
Object.defineProperty(exports, 'getExpirationInSeconds', {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () {
|
|
17
|
+
return getExpirationInSeconds;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { differenceInSeconds } from "date-fns";
|
|
2
|
+
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
const getExpirationInSeconds = (expiresAt) => {
|
|
5
|
+
if (!expiresAt) return 0;
|
|
6
|
+
const expirationDate = new Date(expiresAt);
|
|
7
|
+
const now = /* @__PURE__ */ new Date();
|
|
8
|
+
const secondsLeft = differenceInSeconds(expirationDate, now);
|
|
9
|
+
return Math.max(secondsLeft, 0);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { getExpirationInSeconds };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-
|
|
1
|
+
const require_chunk = require('./chunk-DWy1uDak.cjs');
|
|
2
2
|
const __upstash_redis = require_chunk.__toESM(require("@upstash/redis"));
|
|
3
3
|
|
|
4
4
|
//#region src/upstash.ts
|
|
@@ -10,6 +10,11 @@ var UpstashCache = class {
|
|
|
10
10
|
token
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
+
async ttl(key) {
|
|
14
|
+
const ttl = await this.client.ttl(key);
|
|
15
|
+
if (ttl === -2) return 0;
|
|
16
|
+
return ttl;
|
|
17
|
+
}
|
|
13
18
|
async get(key) {
|
|
14
19
|
const v = await this.client.get(key);
|
|
15
20
|
if (v === null) return void 0;
|
package/dist/upstash.cjs
CHANGED
package/dist/upstash.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-B6eF5Yxi.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/upstash.d.ts
|
|
4
4
|
declare class UpstashCache<T> implements Cache<T> {
|
|
5
5
|
private client;
|
|
6
6
|
constructor(url: string, token: string);
|
|
7
|
+
ttl(key: string): Promise<number>;
|
|
7
8
|
get(key: string): Promise<T | undefined>;
|
|
8
9
|
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
9
10
|
delete(key: string): Promise<void>;
|
package/dist/upstash.d.mts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
1
|
+
import { Cache } from "./index-Bv61mxVT.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/upstash.d.ts
|
|
4
4
|
declare class UpstashCache<T> implements Cache<T> {
|
|
5
5
|
private client;
|
|
6
6
|
constructor(url: string, token: string);
|
|
7
|
+
ttl(key: string): Promise<number>;
|
|
7
8
|
get(key: string): Promise<T | undefined>;
|
|
8
9
|
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
9
10
|
delete(key: string): Promise<void>;
|
package/dist/upstash.mjs
CHANGED