@geekmidas/cache 10.0.0-alpha.99 → 10.0.0
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/CHANGELOG.md +52 -0
- package/dist/{rolldown-runtime-VH7oDXx4.cjs → chunk-CUT6urMc.cjs} +10 -8
- package/dist/expo.cjs +10 -10
- package/dist/expo.cjs.map +1 -1
- package/dist/expo.d.cts +6 -2
- package/dist/expo.d.cts.map +1 -1
- package/dist/expo.d.mts +6 -2
- package/dist/expo.d.mts.map +1 -1
- package/dist/expo.mjs +6 -4
- package/dist/expo.mjs.map +1 -1
- package/dist/file.cjs +19 -16
- package/dist/file.cjs.map +1 -1
- package/dist/file.d.cts +6 -3
- package/dist/file.d.cts.map +1 -1
- package/dist/file.d.mts +6 -3
- package/dist/file.d.mts.map +1 -1
- package/dist/file.mjs +12 -7
- package/dist/file.mjs.map +1 -1
- package/dist/index-BSYYdwRm.d.cts +36 -0
- package/dist/index-BSYYdwRm.d.cts.map +1 -0
- package/dist/index-Dx96gr-9.d.mts +36 -0
- package/dist/index-Dx96gr-9.d.mts.map +1 -0
- package/dist/index.cjs +2 -17
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -12
- package/dist/memory.cjs +11 -8
- package/dist/memory.cjs.map +1 -1
- package/dist/memory.d.cts +6 -2
- package/dist/memory.d.cts.map +1 -1
- package/dist/memory.d.mts +6 -2
- package/dist/memory.d.mts.map +1 -1
- package/dist/memory.mjs +8 -5
- package/dist/memory.mjs.map +1 -1
- package/dist/src-CrE4Nl5T.mjs +14 -0
- package/dist/src-CrE4Nl5T.mjs.map +1 -0
- package/dist/src-zfYb7mdS.cjs +20 -0
- package/dist/src-zfYb7mdS.cjs.map +1 -0
- package/dist/upstash.cjs +6 -46
- package/dist/upstash.cjs.map +1 -1
- package/dist/upstash.d.cts +6 -27
- package/dist/upstash.d.cts.map +1 -1
- package/dist/upstash.d.mts +6 -27
- package/dist/upstash.d.mts.map +1 -1
- package/dist/upstash.mjs +4 -41
- package/dist/upstash.mjs.map +1 -1
- package/package.json +6 -53
- package/src/__benchmarks__/memory.bench.ts +51 -0
- package/src/__tests__/cache.spec.ts +144 -0
- package/src/__tests__/file.spec.ts +192 -0
- package/src/__tests__/integration.spec.ts +282 -0
- package/src/__tests__/memory.spec.ts +134 -0
- package/src/__tests__/upstash.spec.ts +276 -0
- package/src/expo.ts +50 -0
- package/src/file.ts +126 -0
- package/src/index.ts +48 -0
- package/src/memory.ts +38 -0
- package/src/upstash.ts +41 -0
- package/tsconfig.json +9 -0
- package/tsdown.config.ts +5 -0
- package/dist/index-BbdGhmWP.d.cts +0 -62
- package/dist/index-BbdGhmWP.d.cts.map +0 -1
- package/dist/index-BbdGhmWP.d.mts +0 -62
- package/dist/index-BbdGhmWP.d.mts.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/postgres.cjs +0 -185
- package/dist/postgres.cjs.map +0 -1
- package/dist/postgres.d.cts +0 -71
- package/dist/postgres.d.cts.map +0 -1
- package/dist/postgres.d.mts +0 -71
- package/dist/postgres.d.mts.map +0 -1
- package/dist/postgres.mjs +0 -180
- package/dist/postgres.mjs.map +0 -1
- package/dist/redis.cjs +0 -88
- package/dist/redis.cjs.map +0 -1
- package/dist/redis.d.cts +0 -27
- package/dist/redis.d.cts.map +0 -1
- package/dist/redis.d.mts +0 -27
- package/dist/redis.d.mts.map +0 -1
- package/dist/redis.mjs +0 -85
- package/dist/redis.mjs.map +0 -1
- package/dist/registry.cjs +0 -48
- package/dist/registry.cjs.map +0 -1
- package/dist/registry.d.cts +0 -2
- package/dist/registry.d.mts +0 -2
- package/dist/registry.mjs +0 -44
- package/dist/registry.mjs.map +0 -1
- package/dist/telemetry.cjs +0 -38
- package/dist/telemetry.cjs.map +0 -1
- package/dist/telemetry.d.cts +0 -6
- package/dist/telemetry.d.cts.map +0 -1
- package/dist/telemetry.d.mts +0 -6
- package/dist/telemetry.d.mts.map +0 -1
- package/dist/telemetry.mjs +0 -37
- package/dist/telemetry.mjs.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @geekmidas/cache
|
|
2
|
+
|
|
3
|
+
## 10.0.0
|
|
4
|
+
|
|
5
|
+
## 9.0.2
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- [#12](https://github.com/geekmidas/toolbox/pull/12) [`d53863a`](https://github.com/geekmidas/toolbox/commit/d53863a84db2e4ab5420e08f79128b637043fc42) Thanks [@geekmidas](https://github.com/geekmidas)! - Align every published package on a single version and keep them in step.
|
|
10
|
+
|
|
11
|
+
All packages now share one version, enforced by a changesets `fixed` group. The
|
|
12
|
+
baseline is 9.0.1 — @geekmidas/client's published version — so nothing moves
|
|
13
|
+
backwards; this release takes the whole set to 9.0.2 together.
|
|
14
|
+
|
|
15
|
+
Independent versions made "which version of the docs applies to me"
|
|
16
|
+
unanswerable: a reader on constructs@7 and cli@2 was on no version at all. One
|
|
17
|
+
number per release makes versioned documentation possible, and lets 9 freeze as
|
|
18
|
+
the current paradigm while the constructs rework is developed against it.
|
|
19
|
+
|
|
20
|
+
Every release now publishes every package, and a major anywhere is a major
|
|
21
|
+
everywhere. Peer ranges get simpler in return.
|
|
22
|
+
|
|
23
|
+
## 1.1.2
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 🐛 [#11](https://github.com/geekmidas/toolbox/pull/11) [`40f4dc0`](https://github.com/geekmidas/toolbox/commit/40f4dc095911b2223a255029d8f776caf7781309) Thanks [@geekmidas](https://github.com/geekmidas)! - Patch release across all packages to realign published versions with the
|
|
28
|
+
registry. The previous release only published the four packages that had
|
|
29
|
+
version bumps; the remaining packages failed with "cannot publish over the
|
|
30
|
+
previously published versions" because their versions were unchanged.
|
|
31
|
+
|
|
32
|
+
## 1.1.1
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- 🐛 [`d70c6c0`](https://github.com/geekmidas/toolbox/commit/d70c6c0aeb8a79da2473ac77dbd8255a4a2f5651) Thanks [@geekmidas](https://github.com/geekmidas)! - Fix `package.json` exports so TypeScript declarations resolve correctly under NodeNext/Bundler module resolution. Each subpath export now nests `types` inside its `import`/`require` condition, pointing at the `.d.mts` and `.d.cts` files that `tsdown` actually emits (previously the exports referenced non-existent `.d.ts` files, causing type-resolution failures for consumers). Both ESM (`.mjs`) and CJS (`.cjs`) runtime entry points are preserved. Additionally, `@geekmidas/ui` had `import` paths pointing at `.js` files that were never emitted — those are corrected to `.mjs`.
|
|
37
|
+
|
|
38
|
+
## 1.1.0
|
|
39
|
+
|
|
40
|
+
### Minor Changes
|
|
41
|
+
|
|
42
|
+
- ✨ [`be4f7a9`](https://github.com/geekmidas/toolbox/commit/be4f7a9bd5de7f08adbca582916d6902e0c24de2) Thanks [@geekmidas](https://github.com/geekmidas)! - Add partition support for manifest generation. Users can now group constructs (routes, functions, crons, subscribers) into named partitions by providing a `partition` callback per construct type in the config. Manifests output partitioned fields as `Record<string, T[]>` while remaining flat `T[]` arrays when no partitions are configured.
|
|
43
|
+
|
|
44
|
+
Fix mutation type inference in endpoint hooks by using `UseMutationResult` and `UseQueryResult` types directly instead of `ReturnType<typeof useMutation>`, which could resolve to `never` for complex path definitions.
|
|
45
|
+
|
|
46
|
+
Add `FileCache` implementation that persists cache entries to a JSON file on disk. Default location is `process.cwd()/.gkm/cache.json`. Uses an in-process mutex combined with `proper-lockfile` for safe concurrent and cross-process writes.
|
|
47
|
+
|
|
48
|
+
## 1.0.0
|
|
49
|
+
|
|
50
|
+
### Major Changes
|
|
51
|
+
|
|
52
|
+
- [`ff7b115`](https://github.com/geekmidas/toolbox/commit/ff7b11599f60f84ac6cdc73714c853ecf786b2e8) Thanks [@geekmidas](https://github.com/geekmidas)! - Version 1 Stable release
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region rolldown:runtime
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -15,14 +15,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
19
|
value: mod,
|
|
20
20
|
enumerable: true
|
|
21
21
|
}) : target, mod));
|
|
22
|
+
|
|
22
23
|
//#endregion
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(exports, '__toESM', {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return __toESM;
|
|
29
|
+
}
|
|
30
|
+
});
|
package/dist/expo.cjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
expo_secure_store = require_rolldown_runtime.__toESM(expo_secure_store, 1);
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_src = require('./src-zfYb7mdS.cjs');
|
|
3
|
+
const date_fns = require_chunk.__toESM(require("date-fns"));
|
|
4
|
+
const expo_secure_store = require_chunk.__toESM(require("expo-secure-store"));
|
|
5
|
+
|
|
7
6
|
//#region src/expo.ts
|
|
8
7
|
var ExpoSecureCache = class ExpoSecureCache {
|
|
9
8
|
static getExpiryKey(key) {
|
|
@@ -12,13 +11,14 @@ var ExpoSecureCache = class ExpoSecureCache {
|
|
|
12
11
|
async ttl(key) {
|
|
13
12
|
const result = await expo_secure_store.getItemAsync(ExpoSecureCache.getExpiryKey(key));
|
|
14
13
|
if (!result) return 0;
|
|
15
|
-
const secondsLeft =
|
|
14
|
+
const secondsLeft = require_src.getExpirationInSeconds(result);
|
|
16
15
|
return Math.max(secondsLeft, 0);
|
|
17
16
|
}
|
|
18
17
|
async get(key) {
|
|
19
18
|
const result = await expo_secure_store.getItemAsync(key);
|
|
20
|
-
if (!result) return;
|
|
21
|
-
|
|
19
|
+
if (!result) return void 0;
|
|
20
|
+
const expiresAt = await this.ttl(key);
|
|
21
|
+
if (expiresAt === 0) return void 0;
|
|
22
22
|
return JSON.parse(result);
|
|
23
23
|
}
|
|
24
24
|
async set(key, value, ttl = 600) {
|
|
@@ -31,7 +31,7 @@ var ExpoSecureCache = class ExpoSecureCache {
|
|
|
31
31
|
await expo_secure_store.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
+
|
|
34
35
|
//#endregion
|
|
35
36
|
exports.ExpoSecureCache = ExpoSecureCache;
|
|
36
|
-
|
|
37
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":["key: string","value: T","ttl: number"],"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,aAAaA,KAAqB;AACxC,UAAQ,EAAE,IAAI;CACd;CAED,MAAM,IAAIA,KAA8B;EACvC,MAAM,SAAS,MAAM,kBAAY,aAChC,gBAAgB,aAAa,IAAI,CACjC;AACD,OAAK,OACJ,QAAO;EAGR,MAAM,cAAc,mCAAuB,OAAO;AAElD,SAAO,KAAK,IAAI,aAAa,EAAE;CAC/B;CAED,MAAM,IAAOA,KAAqC;EACjD,MAAM,SAAS,MAAM,kBAAY,aAAa,IAAI;AAClD,OAAK,OACJ;EAGD,MAAM,YAAY,MAAM,KAAK,IAAI,IAAI;AACrC,MAAI,cAAc,EACjB;AAGD,SAAO,KAAK,MAAM,OAAO;CACzB;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;EACrE,MAAM,YAAY,yCAAW,IAAI,QAAQ,IAAI,CAAC,aAAa;AAC3D,QAAM,kBAAY,aAAa,KAAK,KAAK,UAAU,MAAM,CAAC;AAC1D,QAAM,kBAAY,aACjB,gBAAgB,aAAa,IAAI,EACjC,UACA;CACD;CAED,MAAM,OAAOF,KAA4B;AACxC,QAAM,kBAAY,gBAAgB,IAAI;AACtC,QAAM,kBAAY,gBAAgB,gBAAgB,aAAa,IAAI,CAAC;CACpE;AACD"}
|
package/dist/expo.d.cts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Cache } from "./index-BSYYdwRm.cjs";
|
|
2
|
+
|
|
2
3
|
//#region src/expo.d.ts
|
|
3
|
-
|
|
4
|
+
declare class ExpoSecureCache implements Cache {
|
|
4
5
|
static getExpiryKey(key: string): string;
|
|
5
6
|
ttl(key: string): Promise<number>;
|
|
6
7
|
get<T>(key: string): Promise<T | undefined>;
|
|
7
8
|
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
8
9
|
delete(key: string): Promise<void>;
|
|
9
10
|
}
|
|
11
|
+
//# sourceMappingURL=expo.d.ts.map
|
|
12
|
+
|
|
10
13
|
//#endregion
|
|
14
|
+
export { ExpoSecureCache };
|
|
11
15
|
//# 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"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"expo.d.cts","names":[],"sources":["../src/expo.ts"],"sourcesContent":[],"mappings":";;;cAIa,eAAA,YAA2B;;EAA3B,GAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAKY,OALI,CAAA,MAAA,CAAA;EAAA,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAkBD,OAlBC,CAkBO,CAlBP,GAAA,SAAA,CAAA;EAAA,GAKJ,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EA2BS,CA3BT,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EA2BgC,OA3BhC,CAAA,IAAA,CAAA;EAAO,MAaI,CAAA,GAAA,EAAA,MAAA,CAAA,EAuBR,OAvBQ,CAAA,IAAA,CAAA"}
|
package/dist/expo.d.mts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Cache } from "./index-Dx96gr-9.mjs";
|
|
2
|
+
|
|
2
3
|
//#region src/expo.d.ts
|
|
3
|
-
|
|
4
|
+
declare class ExpoSecureCache implements Cache {
|
|
4
5
|
static getExpiryKey(key: string): string;
|
|
5
6
|
ttl(key: string): Promise<number>;
|
|
6
7
|
get<T>(key: string): Promise<T | undefined>;
|
|
7
8
|
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
8
9
|
delete(key: string): Promise<void>;
|
|
9
10
|
}
|
|
11
|
+
//# sourceMappingURL=expo.d.ts.map
|
|
12
|
+
|
|
10
13
|
//#endregion
|
|
14
|
+
export { ExpoSecureCache };
|
|
11
15
|
//# 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"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"expo.d.mts","names":[],"sources":["../src/expo.ts"],"sourcesContent":[],"mappings":";;;cAIa,eAAA,YAA2B;;EAA3B,GAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAKY,OALI,CAAA,MAAA,CAAA;EAAA,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAkBD,OAlBC,CAkBO,CAlBP,GAAA,SAAA,CAAA;EAAA,GAKJ,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EA2BS,CA3BT,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EA2BgC,OA3BhC,CAAA,IAAA,CAAA;EAAO,MAaI,CAAA,GAAA,EAAA,MAAA,CAAA,EAuBR,OAvBQ,CAAA,IAAA,CAAA"}
|
package/dist/expo.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { getExpirationInSeconds } from "./
|
|
1
|
+
import { getExpirationInSeconds } from "./src-CrE4Nl5T.mjs";
|
|
2
2
|
import { addSeconds } from "date-fns";
|
|
3
3
|
import * as SecureStore from "expo-secure-store";
|
|
4
|
+
|
|
4
5
|
//#region src/expo.ts
|
|
5
6
|
var ExpoSecureCache = class ExpoSecureCache {
|
|
6
7
|
static getExpiryKey(key) {
|
|
@@ -14,8 +15,9 @@ var ExpoSecureCache = class ExpoSecureCache {
|
|
|
14
15
|
}
|
|
15
16
|
async get(key) {
|
|
16
17
|
const result = await SecureStore.getItemAsync(key);
|
|
17
|
-
if (!result) return;
|
|
18
|
-
|
|
18
|
+
if (!result) return void 0;
|
|
19
|
+
const expiresAt = await this.ttl(key);
|
|
20
|
+
if (expiresAt === 0) return void 0;
|
|
19
21
|
return JSON.parse(result);
|
|
20
22
|
}
|
|
21
23
|
async set(key, value, ttl = 600) {
|
|
@@ -28,7 +30,7 @@ var ExpoSecureCache = class ExpoSecureCache {
|
|
|
28
30
|
await SecureStore.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));
|
|
29
31
|
}
|
|
30
32
|
};
|
|
33
|
+
|
|
31
34
|
//#endregion
|
|
32
35
|
export { ExpoSecureCache };
|
|
33
|
-
|
|
34
36
|
//# sourceMappingURL=expo.mjs.map
|
package/dist/expo.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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":"
|
|
1
|
+
{"version":3,"file":"expo.mjs","names":["key: string","value: T","ttl: number"],"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,aAAaA,KAAqB;AACxC,UAAQ,EAAE,IAAI;CACd;CAED,MAAM,IAAIA,KAA8B;EACvC,MAAM,SAAS,MAAM,YAAY,aAChC,gBAAgB,aAAa,IAAI,CACjC;AACD,OAAK,OACJ,QAAO;EAGR,MAAM,cAAc,uBAAuB,OAAO;AAElD,SAAO,KAAK,IAAI,aAAa,EAAE;CAC/B;CAED,MAAM,IAAOA,KAAqC;EACjD,MAAM,SAAS,MAAM,YAAY,aAAa,IAAI;AAClD,OAAK,OACJ;EAGD,MAAM,YAAY,MAAM,KAAK,IAAI,IAAI;AACrC,MAAI,cAAc,EACjB;AAGD,SAAO,KAAK,MAAM,OAAO;CACzB;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;EACrE,MAAM,YAAY,2BAAW,IAAI,QAAQ,IAAI,CAAC,aAAa;AAC3D,QAAM,YAAY,aAAa,KAAK,KAAK,UAAU,MAAM,CAAC;AAC1D,QAAM,YAAY,aACjB,gBAAgB,aAAa,IAAI,EACjC,UACA;CACD;CAED,MAAM,OAAOF,KAA4B;AACxC,QAAM,YAAY,gBAAgB,IAAI;AACtC,QAAM,YAAY,gBAAgB,gBAAgB,aAAa,IAAI,CAAC;CACpE;AACD"}
|
package/dist/file.cjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
proper_lockfile = require_rolldown_runtime.__toESM(proper_lockfile, 1);
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_src = require('./src-zfYb7mdS.cjs');
|
|
3
|
+
const date_fns = require_chunk.__toESM(require("date-fns"));
|
|
4
|
+
const node_fs = require_chunk.__toESM(require("node:fs"));
|
|
5
|
+
const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
|
|
6
|
+
const node_path = require_chunk.__toESM(require("node:path"));
|
|
7
|
+
const proper_lockfile = require_chunk.__toESM(require("proper-lockfile"));
|
|
8
|
+
|
|
10
9
|
//#region src/file.ts
|
|
11
10
|
var FileCache = class {
|
|
12
11
|
path;
|
|
@@ -18,14 +17,16 @@ var FileCache = class {
|
|
|
18
17
|
this.defaultTtl = options.ttl ?? 600;
|
|
19
18
|
}
|
|
20
19
|
async get(key) {
|
|
21
|
-
const
|
|
20
|
+
const data = await this.readData();
|
|
21
|
+
const entry = data[key];
|
|
22
22
|
if (!entry) return void 0;
|
|
23
|
-
|
|
23
|
+
const remaining = require_src.getExpirationInSeconds(entry.expiresAt);
|
|
24
|
+
if (remaining <= 0) {
|
|
24
25
|
await this.withLock(async (current) => {
|
|
25
26
|
delete current[key];
|
|
26
27
|
return current;
|
|
27
28
|
});
|
|
28
|
-
return;
|
|
29
|
+
return void 0;
|
|
29
30
|
}
|
|
30
31
|
return entry.value;
|
|
31
32
|
}
|
|
@@ -47,9 +48,10 @@ var FileCache = class {
|
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
50
|
async ttl(key) {
|
|
50
|
-
const
|
|
51
|
+
const data = await this.readData();
|
|
52
|
+
const entry = data[key];
|
|
51
53
|
if (!entry) return 0;
|
|
52
|
-
return
|
|
54
|
+
return require_src.getExpirationInSeconds(entry.expiresAt);
|
|
53
55
|
}
|
|
54
56
|
async readData() {
|
|
55
57
|
try {
|
|
@@ -82,7 +84,8 @@ var FileCache = class {
|
|
|
82
84
|
stale: 1e4
|
|
83
85
|
});
|
|
84
86
|
try {
|
|
85
|
-
const
|
|
87
|
+
const data = await this.readData();
|
|
88
|
+
const updated = await fn(data);
|
|
86
89
|
await (0, node_fs_promises.writeFile)(this.path, JSON.stringify(updated, null, 2));
|
|
87
90
|
} finally {
|
|
88
91
|
await release();
|
|
@@ -92,7 +95,7 @@ var FileCache = class {
|
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
97
|
};
|
|
98
|
+
|
|
95
99
|
//#endregion
|
|
96
100
|
exports.FileCache = FileCache;
|
|
97
|
-
|
|
98
101
|
//# 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":["options: FileCacheOptions","key: string","value: T","ttl?: number","fn: (data: FileCacheData) => Promise<FileCacheData>","resolve: () => void"],"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,AAAiB;CACjB,AAAiB;;CAEjB,AAAQ,QAAuB,QAAQ,SAAS;CAEhD,YAAYA,UAA4B,CAAE,GAAE;AAC3C,OAAK,OAAO,QAAQ,QAAQ,oBAAK,QAAQ,KAAK,EAAE,QAAQ,aAAa;AACrE,OAAK,aAAa,QAAQ,OAAO;CACjC;CAED,MAAM,IAAOC,KAAqC;EACjD,MAAM,OAAO,MAAM,KAAK,UAAU;EAClC,MAAM,QAAQ,KAAK;AACnB,OAAK,MAAO;EAEZ,MAAM,YAAY,mCAAuB,MAAM,UAAU;AACzD,MAAI,aAAa,GAAG;AACnB,SAAM,KAAK,SAAS,OAAO,YAAY;AACtC,WAAO,QAAQ;AACf,WAAO;GACP,EAAC;AACF;EACA;AAED,SAAO,MAAM;CACb;CAED,MAAM,IAAOA,KAAaC,OAAUC,KAA6B;EAChE,MAAM,UAAU,OAAO,KAAK;EAC5B,MAAM,YAAY,yCAAW,IAAI,QAAQ,QAAQ,CAAC,aAAa;AAE/D,QAAM,KAAK,SAAS,OAAO,SAAS;AACnC,QAAK,OAAO;IAAE;IAAO;GAAW;AAChC,UAAO;EACP,EAAC;CACF;CAED,MAAM,OAAOF,KAA4B;AACxC,QAAM,KAAK,SAAS,OAAO,SAAS;AACnC,UAAO,KAAK;AACZ,UAAO;EACP,EAAC;CACF;CAED,MAAM,IAAIA,KAA8B;EACvC,MAAM,OAAO,MAAM,KAAK,UAAU;EAClC,MAAM,QAAQ,KAAK;AACnB,OAAK,MAAO,QAAO;AAEnB,SAAO,mCAAuB,MAAM,UAAU;CAC9C;CAED,MAAc,WAAmC;AAChD,MAAI;GACH,MAAM,UAAU,MAAM,+BAAS,KAAK,MAAM,QAAQ;AAClD,UAAO,KAAK,MAAM,QAAQ;EAC1B,QAAO;AACP,UAAO,CAAE;EACT;CACD;CAED,MAAc,YAA2B;EACxC,MAAM,MAAM,uBAAQ,KAAK,KAAK;AAC9B,OAAK,wBAAW,IAAI,CACnB,OAAM,4BAAM,KAAK,EAAE,WAAW,KAAM,EAAC;CAEtC;CAED,MAAc,SACbG,IACgB;EAEhB,MAAM,OAAO,KAAK;EAClB,IAAIC;AACJ,OAAK,QAAQ,IAAI,QAAc,CAAC,MAAM;AACrC,aAAU;EACV;AAED,MAAI;AACH,SAAM;AACN,SAAM,KAAK,WAAW;AAGtB,QAAK,wBAAW,KAAK,KAAK,CACzB,OAAM,gCAAU,KAAK,MAAM,KAAK;GAGjC,MAAM,UAAU,MAAM,wBAAS,KAAK,KAAK,MAAM;IAC9C,SAAS;KAAE,SAAS;KAAG,YAAY;KAAK,YAAY;IAAM;IAC1D,OAAO;GACP,EAAC;AAEF,OAAI;IACH,MAAM,OAAO,MAAM,KAAK,UAAU;IAClC,MAAM,UAAU,MAAM,GAAG,KAAK;AAC9B,UAAM,gCAAU,KAAK,MAAM,KAAK,UAAU,SAAS,MAAM,EAAE,CAAC;GAC5D,UAAS;AACT,UAAM,SAAS;GACf;EACD,UAAS;AACT,YAAU;EACV;CACD;AACD"}
|
package/dist/file.d.cts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Cache } from "./index-BSYYdwRm.cjs";
|
|
2
|
+
|
|
2
3
|
//#region src/file.d.ts
|
|
3
|
-
|
|
4
|
+
interface FileCacheOptions {
|
|
4
5
|
/** Path to the cache JSON file. Default: `process.cwd()/.gkm/cache.json` */
|
|
5
6
|
path?: string;
|
|
6
7
|
/** Default TTL in seconds. Default: 600 */
|
|
7
8
|
ttl?: number;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
+
declare class FileCache implements Cache {
|
|
10
11
|
private readonly path;
|
|
11
12
|
private readonly defaultTtl;
|
|
12
13
|
/** In-process mutex to serialize concurrent writes within the same process. */
|
|
@@ -20,5 +21,7 @@ export declare class FileCache implements Cache {
|
|
|
20
21
|
private ensureDir;
|
|
21
22
|
private withLock;
|
|
22
23
|
}
|
|
24
|
+
//# sourceMappingURL=file.d.ts.map
|
|
23
25
|
//#endregion
|
|
26
|
+
export { FileCache, FileCacheOptions };
|
|
24
27
|
//# 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"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"file.d.cts","names":[],"sources":["../src/file.ts"],"sourcesContent":[],"mappings":";;;UAciB,gBAAA;;EAAA,IAAA,CAAA,EAAA,MAAA;EAOJ;EAAU,GAAA,CAAA,EAAA,MAAA;;AAWa,cAXvB,SAAA,YAAqB,KAWE,CAAA;EAAC,iBAAT,IAAA;EAAO,iBAiBD,UAAA;EAAC;EAAwB,QAU/B,KAAA;EAAO,WAOV,CAAA,OAAA,CAAA,EAvCH,gBAuCG;EAAO,GA7CE,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAWN,OAXM,CAWE,CAXF,GAAA,SAAA,CAAA;EAAK,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EA4BL,CA5BK,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EA4Ba,OA5Bb,CAAA,IAAA,CAAA;uBAsCX;oBAOH"}
|
package/dist/file.d.mts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Cache } from "./index-Dx96gr-9.mjs";
|
|
2
|
+
|
|
2
3
|
//#region src/file.d.ts
|
|
3
|
-
|
|
4
|
+
interface FileCacheOptions {
|
|
4
5
|
/** Path to the cache JSON file. Default: `process.cwd()/.gkm/cache.json` */
|
|
5
6
|
path?: string;
|
|
6
7
|
/** Default TTL in seconds. Default: 600 */
|
|
7
8
|
ttl?: number;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
+
declare class FileCache implements Cache {
|
|
10
11
|
private readonly path;
|
|
11
12
|
private readonly defaultTtl;
|
|
12
13
|
/** In-process mutex to serialize concurrent writes within the same process. */
|
|
@@ -20,5 +21,7 @@ export declare class FileCache implements Cache {
|
|
|
20
21
|
private ensureDir;
|
|
21
22
|
private withLock;
|
|
22
23
|
}
|
|
24
|
+
//# sourceMappingURL=file.d.ts.map
|
|
23
25
|
//#endregion
|
|
26
|
+
export { FileCache, FileCacheOptions };
|
|
24
27
|
//# 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"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"file.d.mts","names":[],"sources":["../src/file.ts"],"sourcesContent":[],"mappings":";;;UAciB,gBAAA;;EAAA,IAAA,CAAA,EAAA,MAAA;EAOJ;EAAU,GAAA,CAAA,EAAA,MAAA;;AAWa,cAXvB,SAAA,YAAqB,KAWE,CAAA;EAAC,iBAAT,IAAA;EAAO,iBAiBD,UAAA;EAAC;EAAwB,QAU/B,KAAA;EAAO,WAOV,CAAA,OAAA,CAAA,EAvCH,gBAuCG;EAAO,GA7CE,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAWN,OAXM,CAWE,CAXF,GAAA,SAAA,CAAA;EAAK,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EA4BL,CA5BK,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EA4Ba,OA5Bb,CAAA,IAAA,CAAA;uBAsCX;oBAOH"}
|
package/dist/file.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { getExpirationInSeconds } from "./
|
|
1
|
+
import { getExpirationInSeconds } from "./src-CrE4Nl5T.mjs";
|
|
2
2
|
import { addSeconds } from "date-fns";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
import lockfile from "proper-lockfile";
|
|
7
|
+
|
|
7
8
|
//#region src/file.ts
|
|
8
9
|
var FileCache = class {
|
|
9
10
|
path;
|
|
@@ -15,14 +16,16 @@ var FileCache = class {
|
|
|
15
16
|
this.defaultTtl = options.ttl ?? 600;
|
|
16
17
|
}
|
|
17
18
|
async get(key) {
|
|
18
|
-
const
|
|
19
|
+
const data = await this.readData();
|
|
20
|
+
const entry = data[key];
|
|
19
21
|
if (!entry) return void 0;
|
|
20
|
-
|
|
22
|
+
const remaining = getExpirationInSeconds(entry.expiresAt);
|
|
23
|
+
if (remaining <= 0) {
|
|
21
24
|
await this.withLock(async (current) => {
|
|
22
25
|
delete current[key];
|
|
23
26
|
return current;
|
|
24
27
|
});
|
|
25
|
-
return;
|
|
28
|
+
return void 0;
|
|
26
29
|
}
|
|
27
30
|
return entry.value;
|
|
28
31
|
}
|
|
@@ -44,7 +47,8 @@ var FileCache = class {
|
|
|
44
47
|
});
|
|
45
48
|
}
|
|
46
49
|
async ttl(key) {
|
|
47
|
-
const
|
|
50
|
+
const data = await this.readData();
|
|
51
|
+
const entry = data[key];
|
|
48
52
|
if (!entry) return 0;
|
|
49
53
|
return getExpirationInSeconds(entry.expiresAt);
|
|
50
54
|
}
|
|
@@ -79,7 +83,8 @@ var FileCache = class {
|
|
|
79
83
|
stale: 1e4
|
|
80
84
|
});
|
|
81
85
|
try {
|
|
82
|
-
const
|
|
86
|
+
const data = await this.readData();
|
|
87
|
+
const updated = await fn(data);
|
|
83
88
|
await writeFile(this.path, JSON.stringify(updated, null, 2));
|
|
84
89
|
} finally {
|
|
85
90
|
await release();
|
|
@@ -89,7 +94,7 @@ var FileCache = class {
|
|
|
89
94
|
}
|
|
90
95
|
}
|
|
91
96
|
};
|
|
97
|
+
|
|
92
98
|
//#endregion
|
|
93
99
|
export { FileCache };
|
|
94
|
-
|
|
95
100
|
//# sourceMappingURL=file.mjs.map
|
package/dist/file.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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":"
|
|
1
|
+
{"version":3,"file":"file.mjs","names":["options: FileCacheOptions","key: string","value: T","ttl?: number","fn: (data: FileCacheData) => Promise<FileCacheData>","resolve: () => void"],"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,AAAiB;CACjB,AAAiB;;CAEjB,AAAQ,QAAuB,QAAQ,SAAS;CAEhD,YAAYA,UAA4B,CAAE,GAAE;AAC3C,OAAK,OAAO,QAAQ,QAAQ,KAAK,QAAQ,KAAK,EAAE,QAAQ,aAAa;AACrE,OAAK,aAAa,QAAQ,OAAO;CACjC;CAED,MAAM,IAAOC,KAAqC;EACjD,MAAM,OAAO,MAAM,KAAK,UAAU;EAClC,MAAM,QAAQ,KAAK;AACnB,OAAK,MAAO;EAEZ,MAAM,YAAY,uBAAuB,MAAM,UAAU;AACzD,MAAI,aAAa,GAAG;AACnB,SAAM,KAAK,SAAS,OAAO,YAAY;AACtC,WAAO,QAAQ;AACf,WAAO;GACP,EAAC;AACF;EACA;AAED,SAAO,MAAM;CACb;CAED,MAAM,IAAOA,KAAaC,OAAUC,KAA6B;EAChE,MAAM,UAAU,OAAO,KAAK;EAC5B,MAAM,YAAY,2BAAW,IAAI,QAAQ,QAAQ,CAAC,aAAa;AAE/D,QAAM,KAAK,SAAS,OAAO,SAAS;AACnC,QAAK,OAAO;IAAE;IAAO;GAAW;AAChC,UAAO;EACP,EAAC;CACF;CAED,MAAM,OAAOF,KAA4B;AACxC,QAAM,KAAK,SAAS,OAAO,SAAS;AACnC,UAAO,KAAK;AACZ,UAAO;EACP,EAAC;CACF;CAED,MAAM,IAAIA,KAA8B;EACvC,MAAM,OAAO,MAAM,KAAK,UAAU;EAClC,MAAM,QAAQ,KAAK;AACnB,OAAK,MAAO,QAAO;AAEnB,SAAO,uBAAuB,MAAM,UAAU;CAC9C;CAED,MAAc,WAAmC;AAChD,MAAI;GACH,MAAM,UAAU,MAAM,SAAS,KAAK,MAAM,QAAQ;AAClD,UAAO,KAAK,MAAM,QAAQ;EAC1B,QAAO;AACP,UAAO,CAAE;EACT;CACD;CAED,MAAc,YAA2B;EACxC,MAAM,MAAM,QAAQ,KAAK,KAAK;AAC9B,OAAK,WAAW,IAAI,CACnB,OAAM,MAAM,KAAK,EAAE,WAAW,KAAM,EAAC;CAEtC;CAED,MAAc,SACbG,IACgB;EAEhB,MAAM,OAAO,KAAK;EAClB,IAAIC;AACJ,OAAK,QAAQ,IAAI,QAAc,CAAC,MAAM;AACrC,aAAU;EACV;AAED,MAAI;AACH,SAAM;AACN,SAAM,KAAK,WAAW;AAGtB,QAAK,WAAW,KAAK,KAAK,CACzB,OAAM,UAAU,KAAK,MAAM,KAAK;GAGjC,MAAM,UAAU,MAAM,SAAS,KAAK,KAAK,MAAM;IAC9C,SAAS;KAAE,SAAS;KAAG,YAAY;KAAK,YAAY;IAAM;IAC1D,OAAO;GACP,EAAC;AAEF,OAAI;IACH,MAAM,OAAO,MAAM,KAAK,UAAU;IAClC,MAAM,UAAU,MAAM,GAAG,KAAK;AAC9B,UAAM,UAAU,KAAK,MAAM,KAAK,UAAU,SAAS,MAAM,EAAE,CAAC;GAC5D,UAAS;AACT,UAAM,SAAS;GACf;EACD,UAAS;AACT,YAAU;EACV;CACD;AACD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
declare const getExpirationInSeconds: (expiresAt: string | number | Date | undefined | null) => number;
|
|
3
|
+
interface Cache {
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves a value from the cache.
|
|
6
|
+
*
|
|
7
|
+
* @param key The key to retrieve the value for.
|
|
8
|
+
* @returns The cached value, or undefined if not found.
|
|
9
|
+
*/
|
|
10
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
11
|
+
/**
|
|
12
|
+
* Sets a value in the cache.
|
|
13
|
+
*
|
|
14
|
+
* @param key The key to set the value for.
|
|
15
|
+
* @param value The value to cache.
|
|
16
|
+
* @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.
|
|
17
|
+
*/
|
|
18
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Deletes a value from the cache.
|
|
21
|
+
*
|
|
22
|
+
* @param key The key to delete from the cache.
|
|
23
|
+
*/
|
|
24
|
+
delete(key: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the time-to-live (TTL) for a cached value.
|
|
27
|
+
*
|
|
28
|
+
* @param key The key to retrieve the TTL for.
|
|
29
|
+
* @returns The TTL in seconds, or 0 if the key does not exist.
|
|
30
|
+
*/
|
|
31
|
+
ttl(key: string): Promise<number>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
34
|
+
//#endregion
|
|
35
|
+
export { Cache, getExpirationInSeconds };
|
|
36
|
+
//# sourceMappingURL=index-BSYYdwRm.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-BSYYdwRm.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";cAEa,sDACiB;AADjB,UAeI,KAAA,CAfJ;EAeI;;;;;;EAeoC,GAM/B,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAdA,OAcA,CAdQ,CAcR,GAAA,SAAA,CAAA;EAAO;AAQH;;;;;;6BAdE,kBAAkB;;;;;;uBAMxB;;;;;;;oBAQH"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
declare const getExpirationInSeconds: (expiresAt: string | number | Date | undefined | null) => number;
|
|
3
|
+
interface Cache {
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves a value from the cache.
|
|
6
|
+
*
|
|
7
|
+
* @param key The key to retrieve the value for.
|
|
8
|
+
* @returns The cached value, or undefined if not found.
|
|
9
|
+
*/
|
|
10
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
11
|
+
/**
|
|
12
|
+
* Sets a value in the cache.
|
|
13
|
+
*
|
|
14
|
+
* @param key The key to set the value for.
|
|
15
|
+
* @param value The value to cache.
|
|
16
|
+
* @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.
|
|
17
|
+
*/
|
|
18
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Deletes a value from the cache.
|
|
21
|
+
*
|
|
22
|
+
* @param key The key to delete from the cache.
|
|
23
|
+
*/
|
|
24
|
+
delete(key: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the time-to-live (TTL) for a cached value.
|
|
27
|
+
*
|
|
28
|
+
* @param key The key to retrieve the TTL for.
|
|
29
|
+
* @returns The TTL in seconds, or 0 if the key does not exist.
|
|
30
|
+
*/
|
|
31
|
+
ttl(key: string): Promise<number>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
34
|
+
//#endregion
|
|
35
|
+
export { Cache, getExpirationInSeconds };
|
|
36
|
+
//# sourceMappingURL=index-Dx96gr-9.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-Dx96gr-9.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";cAEa,sDACiB;AADjB,UAeI,KAAA,CAfJ;EAeI;;;;;;EAeoC,GAM/B,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAdA,OAcA,CAdQ,CAcR,GAAA,SAAA,CAAA;EAAO;AAQH;;;;;;6BAdE,kBAAkB;;;;;;uBAMxB;;;;;;;oBAQH"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
|
|
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
|
|
12
|
-
exports.UnregisteredCacheScheme = require_registry.UnregisteredCacheScheme;
|
|
13
|
-
exports.createCacheClient = require_registry.createCacheClient;
|
|
14
|
-
exports.getExpirationInSeconds = getExpirationInSeconds;
|
|
15
|
-
exports.registerCacheDriver = require_registry.registerCacheDriver;
|
|
16
|
-
exports.registeredCacheSchemes = require_registry.registeredCacheSchemes;
|
|
1
|
+
const require_src = require('./src-zfYb7mdS.cjs');
|
|
17
2
|
|
|
18
|
-
|
|
3
|
+
exports.getExpirationInSeconds = require_src.getExpirationInSeconds;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { Cache,
|
|
1
|
+
import { Cache, getExpirationInSeconds } from "./index-BSYYdwRm.cjs";
|
|
2
|
+
export { Cache, getExpirationInSeconds };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { Cache,
|
|
1
|
+
import { Cache, getExpirationInSeconds } from "./index-Dx96gr-9.mjs";
|
|
2
|
+
export { Cache, getExpirationInSeconds };
|