@geekmidas/cache 10.0.0-alpha.4 → 10.0.0-alpha.40
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/expo.cjs +10 -11
- package/dist/expo.cjs.map +1 -1
- package/dist/expo.d.cts +2 -6
- package/dist/expo.d.cts.map +1 -1
- package/dist/expo.d.mts +2 -6
- package/dist/expo.d.mts.map +1 -1
- package/dist/expo.mjs +4 -7
- package/dist/expo.mjs.map +1 -1
- package/dist/file.cjs +16 -20
- package/dist/file.cjs.map +1 -1
- package/dist/file.d.cts +3 -6
- package/dist/file.d.cts.map +1 -1
- package/dist/file.d.mts +3 -6
- package/dist/file.d.mts.map +1 -1
- package/dist/file.mjs +7 -13
- package/dist/file.mjs.map +1 -1
- package/dist/{index-1sNRIo6N.d.mts → index-BbdGhmWP.d.cts} +2 -4
- package/dist/index-BbdGhmWP.d.cts.map +1 -0
- package/dist/{index-CNQ50bVk.d.cts → index-BbdGhmWP.d.mts} +2 -4
- package/dist/index-BbdGhmWP.d.mts.map +1 -0
- package/dist/index.cjs +15 -5
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +12 -3
- package/dist/index.mjs.map +1 -0
- package/dist/memory.cjs +8 -12
- package/dist/memory.cjs.map +1 -1
- package/dist/memory.d.cts +2 -6
- package/dist/memory.d.cts.map +1 -1
- package/dist/memory.d.mts +2 -6
- package/dist/memory.d.mts.map +1 -1
- package/dist/memory.mjs +5 -9
- package/dist/memory.mjs.map +1 -1
- package/dist/postgres.cjs +27 -4
- package/dist/postgres.cjs.map +1 -1
- package/dist/postgres.d.cts +5 -9
- package/dist/postgres.d.cts.map +1 -1
- package/dist/postgres.d.mts +5 -9
- package/dist/postgres.d.mts.map +1 -1
- package/dist/postgres.mjs +23 -2
- package/dist/postgres.mjs.map +1 -1
- package/dist/redis.cjs +19 -8
- package/dist/redis.cjs.map +1 -1
- package/dist/redis.d.cts +4 -8
- package/dist/redis.d.cts.map +1 -1
- package/dist/redis.d.mts +4 -8
- package/dist/redis.d.mts.map +1 -1
- package/dist/redis.mjs +17 -6
- package/dist/redis.mjs.map +1 -1
- package/dist/registry.cjs +47 -5
- package/dist/registry.cjs.map +1 -0
- package/dist/registry.d.cts +1 -1
- package/dist/registry.d.mts +1 -1
- package/dist/registry.mjs +43 -2
- package/dist/registry.mjs.map +1 -0
- package/dist/{chunk-CUT6urMc.cjs → rolldown-runtime-VH7oDXx4.cjs} +8 -10
- package/dist/upstash.cjs +5 -6
- package/dist/upstash.cjs.map +1 -1
- package/dist/upstash.d.cts +6 -9
- package/dist/upstash.d.cts.map +1 -1
- package/dist/upstash.d.mts +6 -9
- package/dist/upstash.d.mts.map +1 -1
- package/dist/upstash.mjs +2 -3
- package/dist/upstash.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/index-1sNRIo6N.d.mts.map +0 -1
- package/dist/index-CNQ50bVk.d.cts.map +0 -1
- package/dist/registry-CITg73zW.cjs +0 -65
- package/dist/registry-CITg73zW.cjs.map +0 -1
- package/dist/registry-CT0b-rjB.mjs +0 -41
- package/dist/registry-CT0b-rjB.mjs.map +0 -1
- package/dist/src-DVpoP03o.mjs +0 -14
- package/dist/src-DVpoP03o.mjs.map +0 -1
- package/dist/src-ysNIqjnr.cjs +0 -20
- package/dist/src-ysNIqjnr.cjs.map +0 -1
package/dist/expo.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
require(
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.cjs");
|
|
3
|
+
const require_index = require("./index.cjs");
|
|
4
|
+
let date_fns = require("date-fns");
|
|
5
|
+
let expo_secure_store = require("expo-secure-store");
|
|
6
|
+
expo_secure_store = require_rolldown_runtime.__toESM(expo_secure_store, 1);
|
|
7
7
|
//#region src/expo.ts
|
|
8
8
|
var ExpoSecureCache = class ExpoSecureCache {
|
|
9
9
|
static getExpiryKey(key) {
|
|
@@ -12,14 +12,13 @@ var ExpoSecureCache = class ExpoSecureCache {
|
|
|
12
12
|
async ttl(key) {
|
|
13
13
|
const result = await expo_secure_store.getItemAsync(ExpoSecureCache.getExpiryKey(key));
|
|
14
14
|
if (!result) return 0;
|
|
15
|
-
const secondsLeft =
|
|
15
|
+
const secondsLeft = require_index.getExpirationInSeconds(result);
|
|
16
16
|
return Math.max(secondsLeft, 0);
|
|
17
17
|
}
|
|
18
18
|
async get(key) {
|
|
19
19
|
const result = await expo_secure_store.getItemAsync(key);
|
|
20
|
-
if (!result) return
|
|
21
|
-
|
|
22
|
-
if (expiresAt === 0) return void 0;
|
|
20
|
+
if (!result) return;
|
|
21
|
+
if (await this.ttl(key) === 0) return;
|
|
23
22
|
return JSON.parse(result);
|
|
24
23
|
}
|
|
25
24
|
async set(key, value, ttl = 600) {
|
|
@@ -32,7 +31,7 @@ var ExpoSecureCache = class ExpoSecureCache {
|
|
|
32
31
|
await expo_secure_store.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));
|
|
33
32
|
}
|
|
34
33
|
};
|
|
35
|
-
|
|
36
34
|
//#endregion
|
|
37
35
|
exports.ExpoSecureCache = ExpoSecureCache;
|
|
36
|
+
|
|
38
37
|
//# sourceMappingURL=expo.cjs.map
|
package/dist/expo.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expo.cjs","names":["
|
|
1
|
+
{"version":3,"file":"expo.cjs","names":["SecureStore","getExpirationInSeconds","addSeconds"],"sources":["../src/expo.ts"],"sourcesContent":["import { addSeconds } from 'date-fns';\nimport * as SecureStore from 'expo-secure-store';\nimport { type Cache, getExpirationInSeconds } from './index';\n\nexport class ExpoSecureCache implements Cache {\n\tstatic getExpiryKey(key: string): string {\n\t\treturn `${key}:expiresAt`;\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst result = await SecureStore.getItemAsync(\n\t\t\tExpoSecureCache.getExpiryKey(key),\n\t\t);\n\t\tif (!result) {\n\t\t\treturn 0;\n\t\t}\n\n\t\tconst secondsLeft = getExpirationInSeconds(result);\n\n\t\treturn Math.max(secondsLeft, 0);\n\t}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst result = await SecureStore.getItemAsync(key);\n\t\tif (!result) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst expiresAt = await this.ttl(key);\n\t\tif (expiresAt === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn JSON.parse(result) as T;\n\t}\n\n\tasync set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n\t\tconst expiresAt = addSeconds(new Date(), ttl).toISOString();\n\t\tawait SecureStore.setItemAsync(key, JSON.stringify(value));\n\t\tawait SecureStore.setItemAsync(\n\t\t\tExpoSecureCache.getExpiryKey(key),\n\t\t\texpiresAt,\n\t\t);\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tawait SecureStore.deleteItemAsync(key);\n\t\tawait SecureStore.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));\n\t}\n}\n"],"mappings":";;;;;;;AAIA,IAAa,kBAAb,MAAa,gBAAiC;CAC7C,OAAO,aAAa,KAAqB;EACxC,OAAO,GAAG,IAAI;CACf;CAEA,MAAM,IAAI,KAA8B;EACvC,MAAM,SAAS,MAAMA,kBAAY,aAChC,gBAAgB,aAAa,GAAG,CACjC;EACA,IAAI,CAAC,QACJ,OAAO;EAGR,MAAM,cAAcC,cAAAA,uBAAuB,MAAM;EAEjD,OAAO,KAAK,IAAI,aAAa,CAAC;CAC/B;CAEA,MAAM,IAAO,KAAqC;EACjD,MAAM,SAAS,MAAMD,kBAAY,aAAa,GAAG;EACjD,IAAI,CAAC,QACJ;EAID,IAAI,MADoB,KAAK,IAAI,GAAG,MAClB,GACjB;EAGD,OAAO,KAAK,MAAM,MAAM;CACzB;CAEA,MAAM,IAAO,KAAa,OAAU,MAAc,KAAoB;EACrE,MAAM,aAAA,GAAYE,SAAAA,WAAAA,iBAAW,IAAI,KAAK,GAAG,GAAG,CAAC,CAAC,YAAY;EAC1D,MAAMF,kBAAY,aAAa,KAAK,KAAK,UAAU,KAAK,CAAC;EACzD,MAAMA,kBAAY,aACjB,gBAAgB,aAAa,GAAG,GAChC,SACD;CACD;CAEA,MAAM,OAAO,KAA4B;EACxC,MAAMA,kBAAY,gBAAgB,GAAG;EACrC,MAAMA,kBAAY,gBAAgB,gBAAgB,aAAa,GAAG,CAAC;CACpE;AACD"}
|
package/dist/expo.d.cts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
2
|
-
|
|
1
|
+
import { t as Cache } from "./index-BbdGhmWP.cjs";
|
|
3
2
|
//#region src/expo.d.ts
|
|
4
|
-
declare class ExpoSecureCache implements Cache {
|
|
3
|
+
export declare class ExpoSecureCache implements Cache {
|
|
5
4
|
static getExpiryKey(key: string): string;
|
|
6
5
|
ttl(key: string): Promise<number>;
|
|
7
6
|
get<T>(key: string): Promise<T | undefined>;
|
|
8
7
|
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
9
8
|
delete(key: string): Promise<void>;
|
|
10
9
|
}
|
|
11
|
-
//# sourceMappingURL=expo.d.ts.map
|
|
12
|
-
|
|
13
10
|
//#endregion
|
|
14
|
-
export { ExpoSecureCache };
|
|
15
11
|
//# sourceMappingURL=expo.d.cts.map
|
package/dist/expo.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expo.d.cts","names":[],"sources":["../src/expo.ts"],"
|
|
1
|
+
{"version":3,"file":"expo.d.cts","names":[],"sources":["../src/expo.ts"],"mappings":";;qBAIa,2BAA2B;SAChC,aAAa;EAId,IAAI,cAAc;EAalB,IAAI,GAAG,cAAc,QAAQ;EAc7B,IAAI,GAAG,aAAa,OAAO,GAAG,eAAoB;EASlD,OAAO,cAAc"}
|
package/dist/expo.d.mts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
2
|
-
|
|
1
|
+
import { t as Cache } from "./index-BbdGhmWP.mjs";
|
|
3
2
|
//#region src/expo.d.ts
|
|
4
|
-
declare class ExpoSecureCache implements Cache {
|
|
3
|
+
export declare class ExpoSecureCache implements Cache {
|
|
5
4
|
static getExpiryKey(key: string): string;
|
|
6
5
|
ttl(key: string): Promise<number>;
|
|
7
6
|
get<T>(key: string): Promise<T | undefined>;
|
|
8
7
|
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
9
8
|
delete(key: string): Promise<void>;
|
|
10
9
|
}
|
|
11
|
-
//# sourceMappingURL=expo.d.ts.map
|
|
12
|
-
|
|
13
10
|
//#endregion
|
|
14
|
-
export { ExpoSecureCache };
|
|
15
11
|
//# sourceMappingURL=expo.d.mts.map
|
package/dist/expo.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expo.d.mts","names":[],"sources":["../src/expo.ts"],"
|
|
1
|
+
{"version":3,"file":"expo.d.mts","names":[],"sources":["../src/expo.ts"],"mappings":";;qBAIa,2BAA2B;SAChC,aAAa;EAId,IAAI,cAAc;EAalB,IAAI,GAAG,cAAc,QAAQ;EAc7B,IAAI,GAAG,aAAa,OAAO,GAAG,eAAoB;EASlD,OAAO,cAAc"}
|
package/dist/expo.mjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import { getExpirationInSeconds } from "./src-DVpoP03o.mjs";
|
|
1
|
+
import { getExpirationInSeconds } from "./index.mjs";
|
|
3
2
|
import { addSeconds } from "date-fns";
|
|
4
3
|
import * as SecureStore from "expo-secure-store";
|
|
5
|
-
|
|
6
4
|
//#region src/expo.ts
|
|
7
5
|
var ExpoSecureCache = class ExpoSecureCache {
|
|
8
6
|
static getExpiryKey(key) {
|
|
@@ -16,9 +14,8 @@ var ExpoSecureCache = class ExpoSecureCache {
|
|
|
16
14
|
}
|
|
17
15
|
async get(key) {
|
|
18
16
|
const result = await SecureStore.getItemAsync(key);
|
|
19
|
-
if (!result) return
|
|
20
|
-
|
|
21
|
-
if (expiresAt === 0) return void 0;
|
|
17
|
+
if (!result) return;
|
|
18
|
+
if (await this.ttl(key) === 0) return;
|
|
22
19
|
return JSON.parse(result);
|
|
23
20
|
}
|
|
24
21
|
async set(key, value, ttl = 600) {
|
|
@@ -31,7 +28,7 @@ var ExpoSecureCache = class ExpoSecureCache {
|
|
|
31
28
|
await SecureStore.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));
|
|
32
29
|
}
|
|
33
30
|
};
|
|
34
|
-
|
|
35
31
|
//#endregion
|
|
36
32
|
export { ExpoSecureCache };
|
|
33
|
+
|
|
37
34
|
//# sourceMappingURL=expo.mjs.map
|
package/dist/expo.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expo.mjs","names":[
|
|
1
|
+
{"version":3,"file":"expo.mjs","names":[],"sources":["../src/expo.ts"],"sourcesContent":["import { addSeconds } from 'date-fns';\nimport * as SecureStore from 'expo-secure-store';\nimport { type Cache, getExpirationInSeconds } from './index';\n\nexport class ExpoSecureCache implements Cache {\n\tstatic getExpiryKey(key: string): string {\n\t\treturn `${key}:expiresAt`;\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst result = await SecureStore.getItemAsync(\n\t\t\tExpoSecureCache.getExpiryKey(key),\n\t\t);\n\t\tif (!result) {\n\t\t\treturn 0;\n\t\t}\n\n\t\tconst secondsLeft = getExpirationInSeconds(result);\n\n\t\treturn Math.max(secondsLeft, 0);\n\t}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst result = await SecureStore.getItemAsync(key);\n\t\tif (!result) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst expiresAt = await this.ttl(key);\n\t\tif (expiresAt === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn JSON.parse(result) as T;\n\t}\n\n\tasync set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n\t\tconst expiresAt = addSeconds(new Date(), ttl).toISOString();\n\t\tawait SecureStore.setItemAsync(key, JSON.stringify(value));\n\t\tawait SecureStore.setItemAsync(\n\t\t\tExpoSecureCache.getExpiryKey(key),\n\t\t\texpiresAt,\n\t\t);\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tawait SecureStore.deleteItemAsync(key);\n\t\tawait SecureStore.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));\n\t}\n}\n"],"mappings":";;;;AAIA,IAAa,kBAAb,MAAa,gBAAiC;CAC7C,OAAO,aAAa,KAAqB;EACxC,OAAO,GAAG,IAAI;CACf;CAEA,MAAM,IAAI,KAA8B;EACvC,MAAM,SAAS,MAAM,YAAY,aAChC,gBAAgB,aAAa,GAAG,CACjC;EACA,IAAI,CAAC,QACJ,OAAO;EAGR,MAAM,cAAc,uBAAuB,MAAM;EAEjD,OAAO,KAAK,IAAI,aAAa,CAAC;CAC/B;CAEA,MAAM,IAAO,KAAqC;EACjD,MAAM,SAAS,MAAM,YAAY,aAAa,GAAG;EACjD,IAAI,CAAC,QACJ;EAID,IAAI,MADoB,KAAK,IAAI,GAAG,MAClB,GACjB;EAGD,OAAO,KAAK,MAAM,MAAM;CACzB;CAEA,MAAM,IAAO,KAAa,OAAU,MAAc,KAAoB;EACrE,MAAM,YAAY,2BAAW,IAAI,KAAK,GAAG,GAAG,CAAC,CAAC,YAAY;EAC1D,MAAM,YAAY,aAAa,KAAK,KAAK,UAAU,KAAK,CAAC;EACzD,MAAM,YAAY,aACjB,gBAAgB,aAAa,GAAG,GAChC,SACD;CACD;CAEA,MAAM,OAAO,KAA4B;EACxC,MAAM,YAAY,gBAAgB,GAAG;EACrC,MAAM,YAAY,gBAAgB,gBAAgB,aAAa,GAAG,CAAC;CACpE;AACD"}
|
package/dist/file.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
require(
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.cjs");
|
|
3
|
+
const require_index = require("./index.cjs");
|
|
4
|
+
let date_fns = require("date-fns");
|
|
5
|
+
let node_fs = require("node:fs");
|
|
6
|
+
let node_fs_promises = require("node:fs/promises");
|
|
7
|
+
let node_path = require("node:path");
|
|
8
|
+
let proper_lockfile = require("proper-lockfile");
|
|
9
|
+
proper_lockfile = require_rolldown_runtime.__toESM(proper_lockfile, 1);
|
|
10
10
|
//#region src/file.ts
|
|
11
11
|
var FileCache = class {
|
|
12
12
|
path;
|
|
@@ -18,16 +18,14 @@ var FileCache = class {
|
|
|
18
18
|
this.defaultTtl = options.ttl ?? 600;
|
|
19
19
|
}
|
|
20
20
|
async get(key) {
|
|
21
|
-
const
|
|
22
|
-
const entry = data[key];
|
|
21
|
+
const entry = (await this.readData())[key];
|
|
23
22
|
if (!entry) return void 0;
|
|
24
|
-
|
|
25
|
-
if (remaining <= 0) {
|
|
23
|
+
if (require_index.getExpirationInSeconds(entry.expiresAt) <= 0) {
|
|
26
24
|
await this.withLock(async (current) => {
|
|
27
25
|
delete current[key];
|
|
28
26
|
return current;
|
|
29
27
|
});
|
|
30
|
-
return
|
|
28
|
+
return;
|
|
31
29
|
}
|
|
32
30
|
return entry.value;
|
|
33
31
|
}
|
|
@@ -49,10 +47,9 @@ var FileCache = class {
|
|
|
49
47
|
});
|
|
50
48
|
}
|
|
51
49
|
async ttl(key) {
|
|
52
|
-
const
|
|
53
|
-
const entry = data[key];
|
|
50
|
+
const entry = (await this.readData())[key];
|
|
54
51
|
if (!entry) return 0;
|
|
55
|
-
return
|
|
52
|
+
return require_index.getExpirationInSeconds(entry.expiresAt);
|
|
56
53
|
}
|
|
57
54
|
async readData() {
|
|
58
55
|
try {
|
|
@@ -85,8 +82,7 @@ var FileCache = class {
|
|
|
85
82
|
stale: 1e4
|
|
86
83
|
});
|
|
87
84
|
try {
|
|
88
|
-
const
|
|
89
|
-
const updated = await fn(data);
|
|
85
|
+
const updated = await fn(await this.readData());
|
|
90
86
|
await (0, node_fs_promises.writeFile)(this.path, JSON.stringify(updated, null, 2));
|
|
91
87
|
} finally {
|
|
92
88
|
await release();
|
|
@@ -96,7 +92,7 @@ var FileCache = class {
|
|
|
96
92
|
}
|
|
97
93
|
}
|
|
98
94
|
};
|
|
99
|
-
|
|
100
95
|
//#endregion
|
|
101
96
|
exports.FileCache = FileCache;
|
|
97
|
+
|
|
102
98
|
//# sourceMappingURL=file.cjs.map
|
package/dist/file.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.cjs","names":["
|
|
1
|
+
{"version":3,"file":"file.cjs","names":["join","getExpirationInSeconds","addSeconds","readFile","dirname","existsSync","mkdir","writeFile","lockfile"],"sources":["../src/file.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport { addSeconds } from 'date-fns';\nimport lockfile from 'proper-lockfile';\nimport { type Cache, getExpirationInSeconds } from './';\n\ninterface FileCacheEntry {\n\tvalue: unknown;\n\texpiresAt: string;\n}\n\ntype FileCacheData = Record<string, FileCacheEntry>;\n\nexport interface FileCacheOptions {\n\t/** Path to the cache JSON file. Default: `process.cwd()/.gkm/cache.json` */\n\tpath?: string;\n\t/** Default TTL in seconds. Default: 600 */\n\tttl?: number;\n}\n\nexport class FileCache implements Cache {\n\tprivate readonly path: string;\n\tprivate readonly defaultTtl: number;\n\t/** In-process mutex to serialize concurrent writes within the same process. */\n\tprivate mutex: Promise<void> = Promise.resolve();\n\n\tconstructor(options: FileCacheOptions = {}) {\n\t\tthis.path = options.path ?? join(process.cwd(), '.gkm', 'cache.json');\n\t\tthis.defaultTtl = options.ttl ?? 600;\n\t}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst data = await this.readData();\n\t\tconst entry = data[key];\n\t\tif (!entry) return undefined;\n\n\t\tconst remaining = getExpirationInSeconds(entry.expiresAt);\n\t\tif (remaining <= 0) {\n\t\t\tawait this.withLock(async (current) => {\n\t\t\t\tdelete current[key];\n\t\t\t\treturn current;\n\t\t\t});\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn entry.value as T;\n\t}\n\n\tasync set<T>(key: string, value: T, ttl?: number): Promise<void> {\n\t\tconst seconds = ttl ?? this.defaultTtl;\n\t\tconst expiresAt = addSeconds(new Date(), seconds).toISOString();\n\n\t\tawait this.withLock(async (data) => {\n\t\t\tdata[key] = { value, expiresAt };\n\t\t\treturn data;\n\t\t});\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tawait this.withLock(async (data) => {\n\t\t\tdelete data[key];\n\t\t\treturn data;\n\t\t});\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst data = await this.readData();\n\t\tconst entry = data[key];\n\t\tif (!entry) return 0;\n\n\t\treturn getExpirationInSeconds(entry.expiresAt);\n\t}\n\n\tprivate async readData(): Promise<FileCacheData> {\n\t\ttry {\n\t\t\tconst content = await readFile(this.path, 'utf-8');\n\t\t\treturn JSON.parse(content) as FileCacheData;\n\t\t} catch {\n\t\t\treturn {};\n\t\t}\n\t}\n\n\tprivate async ensureDir(): Promise<void> {\n\t\tconst dir = dirname(this.path);\n\t\tif (!existsSync(dir)) {\n\t\t\tawait mkdir(dir, { recursive: true });\n\t\t}\n\t}\n\n\tprivate async withLock(\n\t\tfn: (data: FileCacheData) => Promise<FileCacheData>,\n\t): Promise<void> {\n\t\t// Queue behind any pending in-process operations\n\t\tconst prev = this.mutex;\n\t\tlet resolve: () => void;\n\t\tthis.mutex = new Promise<void>((r) => {\n\t\t\tresolve = r;\n\t\t});\n\n\t\ttry {\n\t\t\tawait prev;\n\t\t\tawait this.ensureDir();\n\n\t\t\t// Ensure file exists before locking (proper-lockfile requires it)\n\t\t\tif (!existsSync(this.path)) {\n\t\t\t\tawait writeFile(this.path, '{}');\n\t\t\t}\n\n\t\t\tconst release = await lockfile.lock(this.path, {\n\t\t\t\tretries: { retries: 3, minTimeout: 100, maxTimeout: 1000 },\n\t\t\t\tstale: 10000,\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tconst data = await this.readData();\n\t\t\t\tconst updated = await fn(data);\n\t\t\t\tawait writeFile(this.path, JSON.stringify(updated, null, 2));\n\t\t\t} finally {\n\t\t\t\tawait release();\n\t\t\t}\n\t\t} finally {\n\t\t\tresolve!();\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;AAqBA,IAAa,YAAb,MAAwC;CACvC;CACA;;CAEA,QAA+B,QAAQ,QAAQ;CAE/C,YAAY,UAA4B,CAAC,GAAG;EAC3C,KAAK,OAAO,QAAQ,SAAA,GAAQA,UAAAA,KAAAA,CAAK,QAAQ,IAAI,GAAG,QAAQ,YAAY;EACpE,KAAK,aAAa,QAAQ,OAAO;CAClC;CAEA,MAAM,IAAO,KAAqC;EAEjD,MAAM,SAAQ,MADK,KAAK,SAAS,EAAA,CACd;EACnB,IAAI,CAAC,OAAO,OAAO,KAAA;EAGnB,IADkBC,cAAAA,uBAAuB,MAAM,SACnC,KAAK,GAAG;GACnB,MAAM,KAAK,SAAS,OAAO,YAAY;IACtC,OAAO,QAAQ;IACf,OAAO;GACR,CAAC;GACD;EACD;EAEA,OAAO,MAAM;CACd;CAEA,MAAM,IAAO,KAAa,OAAU,KAA6B;EAChE,MAAM,UAAU,OAAO,KAAK;EAC5B,MAAM,aAAA,GAAYC,SAAAA,WAAAA,iBAAW,IAAI,KAAK,GAAG,OAAO,CAAC,CAAC,YAAY;EAE9D,MAAM,KAAK,SAAS,OAAO,SAAS;GACnC,KAAK,OAAO;IAAE;IAAO;GAAU;GAC/B,OAAO;EACR,CAAC;CACF;CAEA,MAAM,OAAO,KAA4B;EACxC,MAAM,KAAK,SAAS,OAAO,SAAS;GACnC,OAAO,KAAK;GACZ,OAAO;EACR,CAAC;CACF;CAEA,MAAM,IAAI,KAA8B;EAEvC,MAAM,SAAQ,MADK,KAAK,SAAS,EAAA,CACd;EACnB,IAAI,CAAC,OAAO,OAAO;EAEnB,OAAOD,cAAAA,uBAAuB,MAAM,SAAS;CAC9C;CAEA,MAAc,WAAmC;EAChD,IAAI;GACH,MAAM,UAAU,OAAA,GAAME,iBAAAA,SAAAA,CAAS,KAAK,MAAM,OAAO;GACjD,OAAO,KAAK,MAAM,OAAO;EAC1B,QAAQ;GACP,OAAO,CAAC;EACT;CACD;CAEA,MAAc,YAA2B;EACxC,MAAM,OAAA,GAAMC,UAAAA,QAAAA,CAAQ,KAAK,IAAI;EAC7B,IAAI,EAAA,GAACC,QAAAA,WAAAA,CAAW,GAAG,GAClB,OAAA,GAAMC,iBAAAA,MAAAA,CAAM,KAAK,EAAE,WAAW,KAAK,CAAC;CAEtC;CAEA,MAAc,SACb,IACgB;EAEhB,MAAM,OAAO,KAAK;EAClB,IAAI;EACJ,KAAK,QAAQ,IAAI,SAAe,MAAM;GACrC,UAAU;EACX,CAAC;EAED,IAAI;GACH,MAAM;GACN,MAAM,KAAK,UAAU;GAGrB,IAAI,EAAA,GAACD,QAAAA,WAAAA,CAAW,KAAK,IAAI,GACxB,OAAA,GAAME,iBAAAA,UAAAA,CAAU,KAAK,MAAM,IAAI;GAGhC,MAAM,UAAU,MAAMC,gBAAAA,QAAS,KAAK,KAAK,MAAM;IAC9C,SAAS;KAAE,SAAS;KAAG,YAAY;KAAK,YAAY;IAAK;IACzD,OAAO;GACR,CAAC;GAED,IAAI;IAEH,MAAM,UAAU,MAAM,GAAG,MADN,KAAK,SAAS,CACJ;IAC7B,OAAA,GAAMD,iBAAAA,UAAAA,CAAU,KAAK,MAAM,KAAK,UAAU,SAAS,MAAM,CAAC,CAAC;GAC5D,UAAU;IACT,MAAM,QAAQ;GACf;EACD,UAAU;GACT,QAAS;EACV;CACD;AACD"}
|
package/dist/file.d.cts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
2
|
-
|
|
1
|
+
import { t as Cache } from "./index-BbdGhmWP.cjs";
|
|
3
2
|
//#region src/file.d.ts
|
|
4
|
-
interface FileCacheOptions {
|
|
3
|
+
export interface FileCacheOptions {
|
|
5
4
|
/** Path to the cache JSON file. Default: `process.cwd()/.gkm/cache.json` */
|
|
6
5
|
path?: string;
|
|
7
6
|
/** Default TTL in seconds. Default: 600 */
|
|
8
7
|
ttl?: number;
|
|
9
8
|
}
|
|
10
|
-
declare class FileCache implements Cache {
|
|
9
|
+
export declare class FileCache implements Cache {
|
|
11
10
|
private readonly path;
|
|
12
11
|
private readonly defaultTtl;
|
|
13
12
|
/** In-process mutex to serialize concurrent writes within the same process. */
|
|
@@ -21,7 +20,5 @@ declare class FileCache implements Cache {
|
|
|
21
20
|
private ensureDir;
|
|
22
21
|
private withLock;
|
|
23
22
|
}
|
|
24
|
-
//# sourceMappingURL=file.d.ts.map
|
|
25
23
|
//#endregion
|
|
26
|
-
export { FileCache, FileCacheOptions };
|
|
27
24
|
//# sourceMappingURL=file.d.cts.map
|
package/dist/file.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.cts","names":[],"sources":["../src/file.ts"],"
|
|
1
|
+
{"version":3,"file":"file.d.cts","names":[],"sources":["../src/file.ts"],"mappings":";;iBAciB;;EAEhB;;EAEA;;qBAGY,qBAAqB;mBAChB;mBACA;;UAET;EAER,YAAY,UAAS;EAKf,IAAI,GAAG,cAAc,QAAQ;EAiB7B,IAAI,GAAG,aAAa,OAAO,GAAG,eAAe;EAU7C,OAAO,cAAc;EAOrB,IAAI,cAAc;UAQV;UASA;UAOA"}
|
package/dist/file.d.mts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { Cache } from "./index-
|
|
2
|
-
|
|
1
|
+
import { t as Cache } from "./index-BbdGhmWP.mjs";
|
|
3
2
|
//#region src/file.d.ts
|
|
4
|
-
interface FileCacheOptions {
|
|
3
|
+
export interface FileCacheOptions {
|
|
5
4
|
/** Path to the cache JSON file. Default: `process.cwd()/.gkm/cache.json` */
|
|
6
5
|
path?: string;
|
|
7
6
|
/** Default TTL in seconds. Default: 600 */
|
|
8
7
|
ttl?: number;
|
|
9
8
|
}
|
|
10
|
-
declare class FileCache implements Cache {
|
|
9
|
+
export declare class FileCache implements Cache {
|
|
11
10
|
private readonly path;
|
|
12
11
|
private readonly defaultTtl;
|
|
13
12
|
/** In-process mutex to serialize concurrent writes within the same process. */
|
|
@@ -21,7 +20,5 @@ declare class FileCache implements Cache {
|
|
|
21
20
|
private ensureDir;
|
|
22
21
|
private withLock;
|
|
23
22
|
}
|
|
24
|
-
//# sourceMappingURL=file.d.ts.map
|
|
25
23
|
//#endregion
|
|
26
|
-
export { FileCache, FileCacheOptions };
|
|
27
24
|
//# sourceMappingURL=file.d.mts.map
|
package/dist/file.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.mts","names":[],"sources":["../src/file.ts"],"
|
|
1
|
+
{"version":3,"file":"file.d.mts","names":[],"sources":["../src/file.ts"],"mappings":";;iBAciB;;EAEhB;;EAEA;;qBAGY,qBAAqB;mBAChB;mBACA;;UAET;EAER,YAAY,UAAS;EAKf,IAAI,GAAG,cAAc,QAAQ;EAiB7B,IAAI,GAAG,aAAa,OAAO,GAAG,eAAe;EAU7C,OAAO,cAAc;EAOrB,IAAI,cAAc;UAQV;UASA;UAOA"}
|
package/dist/file.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import { getExpirationInSeconds } from "./src-DVpoP03o.mjs";
|
|
1
|
+
import { getExpirationInSeconds } from "./index.mjs";
|
|
3
2
|
import { addSeconds } from "date-fns";
|
|
4
3
|
import { existsSync } from "node:fs";
|
|
5
4
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
6
5
|
import { dirname, join } from "node:path";
|
|
7
6
|
import lockfile from "proper-lockfile";
|
|
8
|
-
|
|
9
7
|
//#region src/file.ts
|
|
10
8
|
var FileCache = class {
|
|
11
9
|
path;
|
|
@@ -17,16 +15,14 @@ var FileCache = class {
|
|
|
17
15
|
this.defaultTtl = options.ttl ?? 600;
|
|
18
16
|
}
|
|
19
17
|
async get(key) {
|
|
20
|
-
const
|
|
21
|
-
const entry = data[key];
|
|
18
|
+
const entry = (await this.readData())[key];
|
|
22
19
|
if (!entry) return void 0;
|
|
23
|
-
|
|
24
|
-
if (remaining <= 0) {
|
|
20
|
+
if (getExpirationInSeconds(entry.expiresAt) <= 0) {
|
|
25
21
|
await this.withLock(async (current) => {
|
|
26
22
|
delete current[key];
|
|
27
23
|
return current;
|
|
28
24
|
});
|
|
29
|
-
return
|
|
25
|
+
return;
|
|
30
26
|
}
|
|
31
27
|
return entry.value;
|
|
32
28
|
}
|
|
@@ -48,8 +44,7 @@ var FileCache = class {
|
|
|
48
44
|
});
|
|
49
45
|
}
|
|
50
46
|
async ttl(key) {
|
|
51
|
-
const
|
|
52
|
-
const entry = data[key];
|
|
47
|
+
const entry = (await this.readData())[key];
|
|
53
48
|
if (!entry) return 0;
|
|
54
49
|
return getExpirationInSeconds(entry.expiresAt);
|
|
55
50
|
}
|
|
@@ -84,8 +79,7 @@ var FileCache = class {
|
|
|
84
79
|
stale: 1e4
|
|
85
80
|
});
|
|
86
81
|
try {
|
|
87
|
-
const
|
|
88
|
-
const updated = await fn(data);
|
|
82
|
+
const updated = await fn(await this.readData());
|
|
89
83
|
await writeFile(this.path, JSON.stringify(updated, null, 2));
|
|
90
84
|
} finally {
|
|
91
85
|
await release();
|
|
@@ -95,7 +89,7 @@ var FileCache = class {
|
|
|
95
89
|
}
|
|
96
90
|
}
|
|
97
91
|
};
|
|
98
|
-
|
|
99
92
|
//#endregion
|
|
100
93
|
export { FileCache };
|
|
94
|
+
|
|
101
95
|
//# sourceMappingURL=file.mjs.map
|
package/dist/file.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.mjs","names":[
|
|
1
|
+
{"version":3,"file":"file.mjs","names":[],"sources":["../src/file.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport { addSeconds } from 'date-fns';\nimport lockfile from 'proper-lockfile';\nimport { type Cache, getExpirationInSeconds } from './';\n\ninterface FileCacheEntry {\n\tvalue: unknown;\n\texpiresAt: string;\n}\n\ntype FileCacheData = Record<string, FileCacheEntry>;\n\nexport interface FileCacheOptions {\n\t/** Path to the cache JSON file. Default: `process.cwd()/.gkm/cache.json` */\n\tpath?: string;\n\t/** Default TTL in seconds. Default: 600 */\n\tttl?: number;\n}\n\nexport class FileCache implements Cache {\n\tprivate readonly path: string;\n\tprivate readonly defaultTtl: number;\n\t/** In-process mutex to serialize concurrent writes within the same process. */\n\tprivate mutex: Promise<void> = Promise.resolve();\n\n\tconstructor(options: FileCacheOptions = {}) {\n\t\tthis.path = options.path ?? join(process.cwd(), '.gkm', 'cache.json');\n\t\tthis.defaultTtl = options.ttl ?? 600;\n\t}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst data = await this.readData();\n\t\tconst entry = data[key];\n\t\tif (!entry) return undefined;\n\n\t\tconst remaining = getExpirationInSeconds(entry.expiresAt);\n\t\tif (remaining <= 0) {\n\t\t\tawait this.withLock(async (current) => {\n\t\t\t\tdelete current[key];\n\t\t\t\treturn current;\n\t\t\t});\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn entry.value as T;\n\t}\n\n\tasync set<T>(key: string, value: T, ttl?: number): Promise<void> {\n\t\tconst seconds = ttl ?? this.defaultTtl;\n\t\tconst expiresAt = addSeconds(new Date(), seconds).toISOString();\n\n\t\tawait this.withLock(async (data) => {\n\t\t\tdata[key] = { value, expiresAt };\n\t\t\treturn data;\n\t\t});\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tawait this.withLock(async (data) => {\n\t\t\tdelete data[key];\n\t\t\treturn data;\n\t\t});\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst data = await this.readData();\n\t\tconst entry = data[key];\n\t\tif (!entry) return 0;\n\n\t\treturn getExpirationInSeconds(entry.expiresAt);\n\t}\n\n\tprivate async readData(): Promise<FileCacheData> {\n\t\ttry {\n\t\t\tconst content = await readFile(this.path, 'utf-8');\n\t\t\treturn JSON.parse(content) as FileCacheData;\n\t\t} catch {\n\t\t\treturn {};\n\t\t}\n\t}\n\n\tprivate async ensureDir(): Promise<void> {\n\t\tconst dir = dirname(this.path);\n\t\tif (!existsSync(dir)) {\n\t\t\tawait mkdir(dir, { recursive: true });\n\t\t}\n\t}\n\n\tprivate async withLock(\n\t\tfn: (data: FileCacheData) => Promise<FileCacheData>,\n\t): Promise<void> {\n\t\t// Queue behind any pending in-process operations\n\t\tconst prev = this.mutex;\n\t\tlet resolve: () => void;\n\t\tthis.mutex = new Promise<void>((r) => {\n\t\t\tresolve = r;\n\t\t});\n\n\t\ttry {\n\t\t\tawait prev;\n\t\t\tawait this.ensureDir();\n\n\t\t\t// Ensure file exists before locking (proper-lockfile requires it)\n\t\t\tif (!existsSync(this.path)) {\n\t\t\t\tawait writeFile(this.path, '{}');\n\t\t\t}\n\n\t\t\tconst release = await lockfile.lock(this.path, {\n\t\t\t\tretries: { retries: 3, minTimeout: 100, maxTimeout: 1000 },\n\t\t\t\tstale: 10000,\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tconst data = await this.readData();\n\t\t\t\tconst updated = await fn(data);\n\t\t\t\tawait writeFile(this.path, JSON.stringify(updated, null, 2));\n\t\t\t} finally {\n\t\t\t\tawait release();\n\t\t\t}\n\t\t} finally {\n\t\t\tresolve!();\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;AAqBA,IAAa,YAAb,MAAwC;CACvC;CACA;;CAEA,QAA+B,QAAQ,QAAQ;CAE/C,YAAY,UAA4B,CAAC,GAAG;EAC3C,KAAK,OAAO,QAAQ,QAAQ,KAAK,QAAQ,IAAI,GAAG,QAAQ,YAAY;EACpE,KAAK,aAAa,QAAQ,OAAO;CAClC;CAEA,MAAM,IAAO,KAAqC;EAEjD,MAAM,SAAQ,MADK,KAAK,SAAS,EAAA,CACd;EACnB,IAAI,CAAC,OAAO,OAAO,KAAA;EAGnB,IADkB,uBAAuB,MAAM,SACnC,KAAK,GAAG;GACnB,MAAM,KAAK,SAAS,OAAO,YAAY;IACtC,OAAO,QAAQ;IACf,OAAO;GACR,CAAC;GACD;EACD;EAEA,OAAO,MAAM;CACd;CAEA,MAAM,IAAO,KAAa,OAAU,KAA6B;EAChE,MAAM,UAAU,OAAO,KAAK;EAC5B,MAAM,YAAY,2BAAW,IAAI,KAAK,GAAG,OAAO,CAAC,CAAC,YAAY;EAE9D,MAAM,KAAK,SAAS,OAAO,SAAS;GACnC,KAAK,OAAO;IAAE;IAAO;GAAU;GAC/B,OAAO;EACR,CAAC;CACF;CAEA,MAAM,OAAO,KAA4B;EACxC,MAAM,KAAK,SAAS,OAAO,SAAS;GACnC,OAAO,KAAK;GACZ,OAAO;EACR,CAAC;CACF;CAEA,MAAM,IAAI,KAA8B;EAEvC,MAAM,SAAQ,MADK,KAAK,SAAS,EAAA,CACd;EACnB,IAAI,CAAC,OAAO,OAAO;EAEnB,OAAO,uBAAuB,MAAM,SAAS;CAC9C;CAEA,MAAc,WAAmC;EAChD,IAAI;GACH,MAAM,UAAU,MAAM,SAAS,KAAK,MAAM,OAAO;GACjD,OAAO,KAAK,MAAM,OAAO;EAC1B,QAAQ;GACP,OAAO,CAAC;EACT;CACD;CAEA,MAAc,YAA2B;EACxC,MAAM,MAAM,QAAQ,KAAK,IAAI;EAC7B,IAAI,CAAC,WAAW,GAAG,GAClB,MAAM,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;CAEtC;CAEA,MAAc,SACb,IACgB;EAEhB,MAAM,OAAO,KAAK;EAClB,IAAI;EACJ,KAAK,QAAQ,IAAI,SAAe,MAAM;GACrC,UAAU;EACX,CAAC;EAED,IAAI;GACH,MAAM;GACN,MAAM,KAAK,UAAU;GAGrB,IAAI,CAAC,WAAW,KAAK,IAAI,GACxB,MAAM,UAAU,KAAK,MAAM,IAAI;GAGhC,MAAM,UAAU,MAAM,SAAS,KAAK,KAAK,MAAM;IAC9C,SAAS;KAAE,SAAS;KAAG,YAAY;KAAK,YAAY;IAAK;IACzD,OAAO;GACR,CAAC;GAED,IAAI;IAEH,MAAM,UAAU,MAAM,GAAG,MADN,KAAK,SAAS,CACJ;IAC7B,MAAM,UAAU,KAAK,MAAM,KAAK,UAAU,SAAS,MAAM,CAAC,CAAC;GAC5D,UAAU;IACT,MAAM,QAAQ;GACf;EACD,UAAU;GACT,QAAS;EACV;CACD;AACD"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
//#region src/registry.d.ts
|
|
2
|
-
|
|
3
2
|
/** What a driver has to supply: a scheme it answers to, and a client for a URL. */
|
|
4
3
|
interface CacheDriver {
|
|
5
4
|
/** Including the colon, as `URL.protocol` reports it — `redis:`, `https:`. */
|
|
@@ -25,7 +24,6 @@ declare class UnregisteredCacheScheme extends Error {
|
|
|
25
24
|
readonly registered: readonly string[];
|
|
26
25
|
constructor(url: string, scheme: string, registered: readonly string[]);
|
|
27
26
|
}
|
|
28
|
-
//# sourceMappingURL=registry.d.ts.map
|
|
29
27
|
//#endregion
|
|
30
28
|
//#region src/index.d.ts
|
|
31
29
|
declare const getExpirationInSeconds: (expiresAt: string | number | Date | undefined | null) => number;
|
|
@@ -60,5 +58,5 @@ interface Cache {
|
|
|
60
58
|
ttl(key: string): Promise<number>;
|
|
61
59
|
}
|
|
62
60
|
//#endregion
|
|
63
|
-
export {
|
|
64
|
-
//# sourceMappingURL=index-
|
|
61
|
+
export { createCacheClient as a, UnregisteredCacheScheme as i, getExpirationInSeconds as n, registerCacheDriver as o, CacheDriver as r, registeredCacheSchemes as s, Cache as t };
|
|
62
|
+
//# sourceMappingURL=index-BbdGhmWP.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-BbdGhmWP.d.cts","names":[],"sources":["../src/registry.ts","../src/index.ts"],"mappings":";;UAgBiB;;EAEhB;EACA,OAAO,cAAc;;;iBAMN,oBAAoB,QAAQ;;iBAK5B;;;;;;;;iBAWA,kBAAkB,cAAc;;cAYnC,gCAAgC;WAElC;WACA;WACA;EAHV,YACU,aACA,gBACA;;;;cCvDE,yBAAsB,6BACL;UAcb;;;;;;;EAOhB,IAAI,GAAG,cAAc,QAAQ;;;;;;;;EAQ7B,IAAI,GAAG,aAAa,OAAO,GAAG,eAAe;;;;;;EAM7C,OAAO,cAAc;;;;;;;EAQrB,IAAI,cAAc"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
//#region src/registry.d.ts
|
|
2
|
-
|
|
3
2
|
/** What a driver has to supply: a scheme it answers to, and a client for a URL. */
|
|
4
3
|
interface CacheDriver {
|
|
5
4
|
/** Including the colon, as `URL.protocol` reports it — `redis:`, `https:`. */
|
|
@@ -25,7 +24,6 @@ declare class UnregisteredCacheScheme extends Error {
|
|
|
25
24
|
readonly registered: readonly string[];
|
|
26
25
|
constructor(url: string, scheme: string, registered: readonly string[]);
|
|
27
26
|
}
|
|
28
|
-
//# sourceMappingURL=registry.d.ts.map
|
|
29
27
|
//#endregion
|
|
30
28
|
//#region src/index.d.ts
|
|
31
29
|
declare const getExpirationInSeconds: (expiresAt: string | number | Date | undefined | null) => number;
|
|
@@ -60,5 +58,5 @@ interface Cache {
|
|
|
60
58
|
ttl(key: string): Promise<number>;
|
|
61
59
|
}
|
|
62
60
|
//#endregion
|
|
63
|
-
export {
|
|
64
|
-
//# sourceMappingURL=index-
|
|
61
|
+
export { createCacheClient as a, UnregisteredCacheScheme as i, getExpirationInSeconds as n, registerCacheDriver as o, CacheDriver as r, registeredCacheSchemes as s, Cache as t };
|
|
62
|
+
//# sourceMappingURL=index-BbdGhmWP.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-BbdGhmWP.d.mts","names":[],"sources":["../src/registry.ts","../src/index.ts"],"mappings":";;UAgBiB;;EAEhB;EACA,OAAO,cAAc;;;iBAMN,oBAAoB,QAAQ;;iBAK5B;;;;;;;;iBAWA,kBAAkB,cAAc;;cAYnC,gCAAgC;WAElC;WACA;WACA;EAHV,YACU,aACA,gBACA;;;;cCvDE,yBAAsB,6BACL;UAcb;;;;;;;EAOhB,IAAI,GAAG,cAAc,QAAQ;;;;;;;;EAQ7B,IAAI,GAAG,aAAa,OAAO,GAAG,eAAe;;;;;;EAM7C,OAAO,cAAc;;;;;;;EAQrB,IAAI,cAAc"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_registry = require("./registry.cjs");
|
|
3
|
+
let date_fns = require("date-fns");
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
const getExpirationInSeconds = (expiresAt) => {
|
|
6
|
+
if (!expiresAt) return 0;
|
|
7
|
+
const expirationDate = new Date(expiresAt);
|
|
8
|
+
const secondsLeft = (0, date_fns.differenceInSeconds)(expirationDate, /* @__PURE__ */ new Date());
|
|
9
|
+
return Math.max(secondsLeft, 0);
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
4
12
|
exports.UnregisteredCacheScheme = require_registry.UnregisteredCacheScheme;
|
|
5
13
|
exports.createCacheClient = require_registry.createCacheClient;
|
|
6
|
-
exports.getExpirationInSeconds =
|
|
14
|
+
exports.getExpirationInSeconds = getExpirationInSeconds;
|
|
7
15
|
exports.registerCacheDriver = require_registry.registerCacheDriver;
|
|
8
|
-
exports.registeredCacheSchemes = require_registry.registeredCacheSchemes;
|
|
16
|
+
exports.registeredCacheSchemes = require_registry.registeredCacheSchemes;
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["differenceInSeconds"],"sources":["../src/index.ts"],"sourcesContent":["import { differenceInSeconds } from 'date-fns';\n\nexport const getExpirationInSeconds = (\n\texpiresAt: string | number | Date | undefined | null,\n): number => {\n\tif (!expiresAt) {\n\t\treturn 0;\n\t}\n\n\tconst expirationDate = new Date(expiresAt);\n\tconst now = new Date();\n\n\tconst secondsLeft = differenceInSeconds(expirationDate, now);\n\n\treturn Math.max(secondsLeft, 0);\n};\n\nexport interface Cache {\n\t/**\n\t * Retrieves a value from the cache.\n\t *\n\t * @param key The key to retrieve the value for.\n\t * @returns The cached value, or undefined if not found.\n\t */\n\tget<T>(key: string): Promise<T | undefined>;\n\t/**\n\t * Sets a value in the cache.\n\t *\n\t * @param key The key to set the value for.\n\t * @param value The value to cache.\n\t * @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.\n\t */\n\tset<T>(key: string, value: T, ttl?: number): Promise<void>;\n\t/**\n\t * Deletes a value from the cache.\n\t *\n\t * @param key The key to delete from the cache.\n\t */\n\tdelete(key: string): Promise<void>;\n\n\t/**\n\t * Retrieves the time-to-live (TTL) for a cached value.\n\t *\n\t * @param key The key to retrieve the TTL for.\n\t * @returns The TTL in seconds, or 0 if the key does not exist.\n\t */\n\tttl(key: string): Promise<number>;\n}\n\nexport type { CacheDriver } from './registry';\nexport {\n\tcreateCacheClient,\n\tregisterCacheDriver,\n\tregisteredCacheSchemes,\n\tUnregisteredCacheScheme,\n} from './registry';\n"],"mappings":";;;;AAEA,MAAa,0BACZ,cACY;CACZ,IAAI,CAAC,WACJ,OAAO;CAGR,MAAM,iBAAiB,IAAI,KAAK,SAAS;CAGzC,MAAM,eAAA,GAAcA,SAAAA,oBAAAA,CAAoB,gCAAgB,IAFxC,KAE0C,CAAC;CAE3D,OAAO,KAAK,IAAI,aAAa,CAAC;AAC/B"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { Cache, CacheDriver, UnregisteredCacheScheme, createCacheClient, getExpirationInSeconds, registerCacheDriver, registeredCacheSchemes };
|
|
1
|
+
import { a as createCacheClient, i as UnregisteredCacheScheme, n as getExpirationInSeconds, o as registerCacheDriver, r as CacheDriver, s as registeredCacheSchemes, t as Cache } from "./index-BbdGhmWP.cjs";
|
|
2
|
+
export { Cache, type CacheDriver, UnregisteredCacheScheme, createCacheClient, getExpirationInSeconds, registerCacheDriver, registeredCacheSchemes };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { Cache, CacheDriver, UnregisteredCacheScheme, createCacheClient, getExpirationInSeconds, registerCacheDriver, registeredCacheSchemes };
|
|
1
|
+
import { a as createCacheClient, i as UnregisteredCacheScheme, n as getExpirationInSeconds, o as registerCacheDriver, r as CacheDriver, s as registeredCacheSchemes, t as Cache } from "./index-BbdGhmWP.mjs";
|
|
2
|
+
export { Cache, type CacheDriver, UnregisteredCacheScheme, createCacheClient, getExpirationInSeconds, registerCacheDriver, registeredCacheSchemes };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import { UnregisteredCacheScheme, createCacheClient, registerCacheDriver, registeredCacheSchemes } from "./registry
|
|
2
|
-
import {
|
|
1
|
+
import { UnregisteredCacheScheme, createCacheClient, registerCacheDriver, registeredCacheSchemes } from "./registry.mjs";
|
|
2
|
+
import { differenceInSeconds } from "date-fns";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
const getExpirationInSeconds = (expiresAt) => {
|
|
5
|
+
if (!expiresAt) return 0;
|
|
6
|
+
const expirationDate = new Date(expiresAt);
|
|
7
|
+
const secondsLeft = differenceInSeconds(expirationDate, /* @__PURE__ */ new Date());
|
|
8
|
+
return Math.max(secondsLeft, 0);
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { UnregisteredCacheScheme, createCacheClient, getExpirationInSeconds, registerCacheDriver, registeredCacheSchemes };
|
|
3
12
|
|
|
4
|
-
|
|
13
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { differenceInSeconds } from 'date-fns';\n\nexport const getExpirationInSeconds = (\n\texpiresAt: string | number | Date | undefined | null,\n): number => {\n\tif (!expiresAt) {\n\t\treturn 0;\n\t}\n\n\tconst expirationDate = new Date(expiresAt);\n\tconst now = new Date();\n\n\tconst secondsLeft = differenceInSeconds(expirationDate, now);\n\n\treturn Math.max(secondsLeft, 0);\n};\n\nexport interface Cache {\n\t/**\n\t * Retrieves a value from the cache.\n\t *\n\t * @param key The key to retrieve the value for.\n\t * @returns The cached value, or undefined if not found.\n\t */\n\tget<T>(key: string): Promise<T | undefined>;\n\t/**\n\t * Sets a value in the cache.\n\t *\n\t * @param key The key to set the value for.\n\t * @param value The value to cache.\n\t * @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.\n\t */\n\tset<T>(key: string, value: T, ttl?: number): Promise<void>;\n\t/**\n\t * Deletes a value from the cache.\n\t *\n\t * @param key The key to delete from the cache.\n\t */\n\tdelete(key: string): Promise<void>;\n\n\t/**\n\t * Retrieves the time-to-live (TTL) for a cached value.\n\t *\n\t * @param key The key to retrieve the TTL for.\n\t * @returns The TTL in seconds, or 0 if the key does not exist.\n\t */\n\tttl(key: string): Promise<number>;\n}\n\nexport type { CacheDriver } from './registry';\nexport {\n\tcreateCacheClient,\n\tregisterCacheDriver,\n\tregisteredCacheSchemes,\n\tUnregisteredCacheScheme,\n} from './registry';\n"],"mappings":";;;AAEA,MAAa,0BACZ,cACY;CACZ,IAAI,CAAC,WACJ,OAAO;CAGR,MAAM,iBAAiB,IAAI,KAAK,SAAS;CAGzC,MAAM,cAAc,oBAAoB,gCAAgB,IAFxC,KAE0C,CAAC;CAE3D,OAAO,KAAK,IAAI,aAAa,CAAC;AAC/B"}
|
package/dist/memory.cjs
CHANGED
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
require(
|
|
3
|
-
|
|
4
|
-
const date_fns = require_chunk.__toESM(require("date-fns"));
|
|
5
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_index = require("./index.cjs");
|
|
3
|
+
let date_fns = require("date-fns");
|
|
6
4
|
//#region src/memory.ts
|
|
7
5
|
var InMemoryCache = class {
|
|
8
6
|
store = /* @__PURE__ */ new Map();
|
|
9
7
|
expirations = /* @__PURE__ */ new Map();
|
|
10
8
|
async get(key) {
|
|
11
|
-
|
|
12
|
-
if (!expiration) {
|
|
9
|
+
if (!await this.ttl(key)) {
|
|
13
10
|
await this.delete(key);
|
|
14
|
-
return
|
|
11
|
+
return;
|
|
15
12
|
}
|
|
16
13
|
return this.store.get(key);
|
|
17
14
|
}
|
|
18
15
|
async ttl(key) {
|
|
19
16
|
const expiration = this.expirations.get(key);
|
|
20
17
|
if (!expiration) return 0;
|
|
21
|
-
return
|
|
18
|
+
return require_index.getExpirationInSeconds(expiration);
|
|
22
19
|
}
|
|
23
20
|
async set(key, value, ttl = 600) {
|
|
24
21
|
this.store.set(key, value);
|
|
25
|
-
const
|
|
26
|
-
const expiresAt = (0, date_fns.addSeconds)(now, ttl);
|
|
22
|
+
const expiresAt = (0, date_fns.addSeconds)(/* @__PURE__ */ new Date(), ttl);
|
|
27
23
|
this.expirations.set(key, expiresAt);
|
|
28
24
|
}
|
|
29
25
|
async delete(key) {
|
|
@@ -31,7 +27,7 @@ var InMemoryCache = class {
|
|
|
31
27
|
this.expirations.delete(key);
|
|
32
28
|
}
|
|
33
29
|
};
|
|
34
|
-
|
|
35
30
|
//#endregion
|
|
36
31
|
exports.InMemoryCache = InMemoryCache;
|
|
32
|
+
|
|
37
33
|
//# sourceMappingURL=memory.cjs.map
|
package/dist/memory.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.cjs","names":["
|
|
1
|
+
{"version":3,"file":"memory.cjs","names":["getExpirationInSeconds","addSeconds"],"sources":["../src/memory.ts"],"sourcesContent":["import { addSeconds } from 'date-fns';\nimport { type Cache, getExpirationInSeconds } from './';\n\nexport class InMemoryCache implements Cache {\n\tprivate store: Map<string, unknown> = new Map();\n\tprivate expirations: Map<string, Date> = new Map();\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst expiration = await this.ttl(key);\n\t\tif (!expiration) {\n\t\t\tawait this.delete(key);\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn this.store.get(key) as T | undefined;\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst expiration = this.expirations.get(key);\n\t\tif (!expiration) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn getExpirationInSeconds(expiration);\n\t}\n\n\tasync set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n\t\tthis.store.set(key, value);\n\t\tconst now = new Date();\n\t\tconst expiresAt = addSeconds(now, ttl);\n\t\tthis.expirations.set(key, expiresAt);\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tthis.store.delete(key);\n\t\tthis.expirations.delete(key);\n\t}\n}\n"],"mappings":";;;;AAGA,IAAa,gBAAb,MAA4C;CAC3C,wBAAsC,IAAI,IAAI;CAC9C,8BAAyC,IAAI,IAAI;CAEjD,MAAM,IAAO,KAAqC;EAEjD,IAAI,CAAC,MADoB,KAAK,IAAI,GAAG,GACpB;GAChB,MAAM,KAAK,OAAO,GAAG;GACrB;EACD;EAEA,OAAO,KAAK,MAAM,IAAI,GAAG;CAC1B;CAEA,MAAM,IAAI,KAA8B;EACvC,MAAM,aAAa,KAAK,YAAY,IAAI,GAAG;EAC3C,IAAI,CAAC,YACJ,OAAO;EAGR,OAAOA,cAAAA,uBAAuB,UAAU;CACzC;CAEA,MAAM,IAAO,KAAa,OAAU,MAAc,KAAoB;EACrE,KAAK,MAAM,IAAI,KAAK,KAAK;EAEzB,MAAM,aAAA,GAAYC,SAAAA,WAAAA,iBAAW,IADb,KACe,GAAG,GAAG;EACrC,KAAK,YAAY,IAAI,KAAK,SAAS;CACpC;CAEA,MAAM,OAAO,KAA4B;EACxC,KAAK,MAAM,OAAO,GAAG;EACrB,KAAK,YAAY,OAAO,GAAG;CAC5B;AACD"}
|