@geekmidas/cache 0.1.0 → 0.2.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/dist/expo.cjs.map CHANGED
@@ -1 +1 @@
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 static getExpiryKey(key: string): string {\n return `${key}:expiresAt`;\n }\n\n async ttl(key: string): Promise<number> {\n const result = await SecureStore.getItemAsync(\n ExpoSecureCache.getExpiryKey(key),\n );\n if (!result) {\n return 0;\n }\n\n const secondsLeft = getExpirationInSeconds(result);\n\n return Math.max(secondsLeft, 0);\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n const result = await SecureStore.getItemAsync(key);\n if (!result) {\n return undefined;\n }\n\n const expiresAt = await this.ttl(key);\n if (expiresAt === 0) {\n return undefined;\n }\n\n return JSON.parse(result) as T;\n }\n\n async set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n const expiresAt = addSeconds(new Date(), ttl).toISOString();\n await SecureStore.setItemAsync(key, JSON.stringify(value));\n await SecureStore.setItemAsync(\n ExpoSecureCache.getExpiryKey(key),\n expiresAt,\n );\n }\n\n async delete(key: string): Promise<void> {\n await SecureStore.deleteItemAsync(key);\n await SecureStore.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));\n }\n}\n"],"mappings":";;;;;;AAIA,IAAa,kBAAb,MAAa,gBAAiC;CAC5C,OAAO,aAAaA,KAAqB;AACvC,UAAQ,EAAE,IAAI;CACf;CAED,MAAM,IAAIA,KAA8B;EACtC,MAAM,SAAS,MAAM,kBAAY,aAC/B,gBAAgB,aAAa,IAAI,CAClC;AACD,OAAK,OACH,QAAO;EAGT,MAAM,cAAc,mCAAuB,OAAO;AAElD,SAAO,KAAK,IAAI,aAAa,EAAE;CAChC;CAED,MAAM,IAAOA,KAAqC;EAChD,MAAM,SAAS,MAAM,kBAAY,aAAa,IAAI;AAClD,OAAK,OACH;EAGF,MAAM,YAAY,MAAM,KAAK,IAAI,IAAI;AACrC,MAAI,cAAc,EAChB;AAGF,SAAO,KAAK,MAAM,OAAO;CAC1B;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;EACpE,MAAM,YAAY,yCAAW,IAAI,QAAQ,IAAI,CAAC,aAAa;AAC3D,QAAM,kBAAY,aAAa,KAAK,KAAK,UAAU,MAAM,CAAC;AAC1D,QAAM,kBAAY,aAChB,gBAAgB,aAAa,IAAI,EACjC,UACD;CACF;CAED,MAAM,OAAOF,KAA4B;AACvC,QAAM,kBAAY,gBAAgB,IAAI;AACtC,QAAM,kBAAY,gBAAgB,gBAAgB,aAAa,IAAI,CAAC;CACrE;AACF"}
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,4 +1,4 @@
1
- import { Cache } from "./index-CExVL1mV.cjs";
1
+ import { Cache } from "./index-BSYYdwRm.cjs";
2
2
 
3
3
  //#region src/expo.d.ts
4
4
  declare class ExpoSecureCache implements Cache {
@@ -8,6 +8,8 @@ declare class ExpoSecureCache implements Cache {
8
8
  set<T>(key: string, value: T, ttl?: number): Promise<void>;
9
9
  delete(key: string): Promise<void>;
10
10
  }
11
+ //# sourceMappingURL=expo.d.ts.map
12
+
11
13
  //#endregion
12
14
  export { ExpoSecureCache };
13
15
  //# sourceMappingURL=expo.d.cts.map
@@ -0,0 +1 @@
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,4 +1,4 @@
1
- import { Cache } from "./index-M02PehQA.mjs";
1
+ import { Cache } from "./index-Dx96gr-9.mjs";
2
2
 
3
3
  //#region src/expo.d.ts
4
4
  declare class ExpoSecureCache implements Cache {
@@ -8,6 +8,8 @@ declare class ExpoSecureCache implements Cache {
8
8
  set<T>(key: string, value: T, ttl?: number): Promise<void>;
9
9
  delete(key: string): Promise<void>;
10
10
  }
11
+ //# sourceMappingURL=expo.d.ts.map
12
+
11
13
  //#endregion
12
14
  export { ExpoSecureCache };
13
15
  //# sourceMappingURL=expo.d.mts.map
@@ -0,0 +1 @@
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.map CHANGED
@@ -1 +1 @@
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 static getExpiryKey(key: string): string {\n return `${key}:expiresAt`;\n }\n\n async ttl(key: string): Promise<number> {\n const result = await SecureStore.getItemAsync(\n ExpoSecureCache.getExpiryKey(key),\n );\n if (!result) {\n return 0;\n }\n\n const secondsLeft = getExpirationInSeconds(result);\n\n return Math.max(secondsLeft, 0);\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n const result = await SecureStore.getItemAsync(key);\n if (!result) {\n return undefined;\n }\n\n const expiresAt = await this.ttl(key);\n if (expiresAt === 0) {\n return undefined;\n }\n\n return JSON.parse(result) as T;\n }\n\n async set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n const expiresAt = addSeconds(new Date(), ttl).toISOString();\n await SecureStore.setItemAsync(key, JSON.stringify(value));\n await SecureStore.setItemAsync(\n ExpoSecureCache.getExpiryKey(key),\n expiresAt,\n );\n }\n\n async delete(key: string): Promise<void> {\n await SecureStore.deleteItemAsync(key);\n await SecureStore.deleteItemAsync(ExpoSecureCache.getExpiryKey(key));\n }\n}\n"],"mappings":";;;;;AAIA,IAAa,kBAAb,MAAa,gBAAiC;CAC5C,OAAO,aAAaA,KAAqB;AACvC,UAAQ,EAAE,IAAI;CACf;CAED,MAAM,IAAIA,KAA8B;EACtC,MAAM,SAAS,MAAM,YAAY,aAC/B,gBAAgB,aAAa,IAAI,CAClC;AACD,OAAK,OACH,QAAO;EAGT,MAAM,cAAc,uBAAuB,OAAO;AAElD,SAAO,KAAK,IAAI,aAAa,EAAE;CAChC;CAED,MAAM,IAAOA,KAAqC;EAChD,MAAM,SAAS,MAAM,YAAY,aAAa,IAAI;AAClD,OAAK,OACH;EAGF,MAAM,YAAY,MAAM,KAAK,IAAI,IAAI;AACrC,MAAI,cAAc,EAChB;AAGF,SAAO,KAAK,MAAM,OAAO;CAC1B;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;EACpE,MAAM,YAAY,2BAAW,IAAI,QAAQ,IAAI,CAAC,aAAa;AAC3D,QAAM,YAAY,aAAa,KAAK,KAAK,UAAU,MAAM,CAAC;AAC1D,QAAM,YAAY,aAChB,gBAAgB,aAAa,IAAI,EACjC,UACD;CACF;CAED,MAAM,OAAOF,KAA4B;AACvC,QAAM,YAAY,gBAAgB,IAAI;AACtC,QAAM,YAAY,gBAAgB,gBAAgB,aAAa,IAAI,CAAC;CACrE;AACF"}
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"}
@@ -30,6 +30,7 @@ interface Cache {
30
30
  */
31
31
  ttl(key: string): Promise<number>;
32
32
  }
33
+ //# sourceMappingURL=index.d.ts.map
33
34
  //#endregion
34
35
  export { Cache, getExpirationInSeconds };
35
- //# sourceMappingURL=index-CExVL1mV.d.cts.map
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"}
@@ -30,6 +30,7 @@ interface Cache {
30
30
  */
31
31
  ttl(key: string): Promise<number>;
32
32
  }
33
+ //# sourceMappingURL=index.d.ts.map
33
34
  //#endregion
34
35
  export { Cache, getExpirationInSeconds };
35
- //# sourceMappingURL=index-M02PehQA.d.mts.map
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.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { Cache, getExpirationInSeconds } from "./index-CExVL1mV.cjs";
1
+ import { Cache, getExpirationInSeconds } from "./index-BSYYdwRm.cjs";
2
2
  export { Cache, getExpirationInSeconds };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { Cache, getExpirationInSeconds } from "./index-M02PehQA.mjs";
1
+ import { Cache, getExpirationInSeconds } from "./index-Dx96gr-9.mjs";
2
2
  export { Cache, getExpirationInSeconds };
@@ -1 +1 @@
1
- {"version":3,"file":"memory.cjs","names":["key: string","value: T","ttl: number"],"sources":["../src/memory.ts"],"sourcesContent":["import { addSeconds } from 'date-fns';\nimport { type Cache, getExpirationInSeconds } from './';\n\nexport class InMemoryCache implements Cache {\n private store: Map<string, unknown> = new Map();\n private expirations: Map<string, Date> = new Map();\n\n async get<T>(key: string): Promise<T | undefined> {\n const expiration = await this.ttl(key);\n if (!expiration) {\n await this.delete(key);\n return undefined;\n }\n\n return this.store.get(key) as T | undefined;\n }\n\n async ttl(key: string): Promise<number> {\n const expiration = this.expirations.get(key);\n if (!expiration) {\n return 0;\n }\n\n return getExpirationInSeconds(expiration);\n }\n\n async set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n this.store.set(key, value);\n const now = new Date();\n const expiresAt = addSeconds(now, ttl);\n this.expirations.set(key, expiresAt);\n }\n\n async delete(key: string): Promise<void> {\n this.store.delete(key);\n this.expirations.delete(key);\n }\n}\n"],"mappings":";;;;;AAGA,IAAa,gBAAb,MAA4C;CAC1C,AAAQ,wBAA8B,IAAI;CAC1C,AAAQ,8BAAiC,IAAI;CAE7C,MAAM,IAAOA,KAAqC;EAChD,MAAM,aAAa,MAAM,KAAK,IAAI,IAAI;AACtC,OAAK,YAAY;AACf,SAAM,KAAK,OAAO,IAAI;AACtB;EACD;AAED,SAAO,KAAK,MAAM,IAAI,IAAI;CAC3B;CAED,MAAM,IAAIA,KAA8B;EACtC,MAAM,aAAa,KAAK,YAAY,IAAI,IAAI;AAC5C,OAAK,WACH,QAAO;AAGT,SAAO,mCAAuB,WAAW;CAC1C;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;AACpE,OAAK,MAAM,IAAI,KAAK,MAAM;EAC1B,MAAM,sBAAM,IAAI;EAChB,MAAM,YAAY,yBAAW,KAAK,IAAI;AACtC,OAAK,YAAY,IAAI,KAAK,UAAU;CACrC;CAED,MAAM,OAAOF,KAA4B;AACvC,OAAK,MAAM,OAAO,IAAI;AACtB,OAAK,YAAY,OAAO,IAAI;CAC7B;AACF"}
1
+ {"version":3,"file":"memory.cjs","names":["key: string","value: T","ttl: number"],"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,AAAQ,wBAA8B,IAAI;CAC1C,AAAQ,8BAAiC,IAAI;CAE7C,MAAM,IAAOA,KAAqC;EACjD,MAAM,aAAa,MAAM,KAAK,IAAI,IAAI;AACtC,OAAK,YAAY;AAChB,SAAM,KAAK,OAAO,IAAI;AACtB;EACA;AAED,SAAO,KAAK,MAAM,IAAI,IAAI;CAC1B;CAED,MAAM,IAAIA,KAA8B;EACvC,MAAM,aAAa,KAAK,YAAY,IAAI,IAAI;AAC5C,OAAK,WACJ,QAAO;AAGR,SAAO,mCAAuB,WAAW;CACzC;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;AACrE,OAAK,MAAM,IAAI,KAAK,MAAM;EAC1B,MAAM,sBAAM,IAAI;EAChB,MAAM,YAAY,yBAAW,KAAK,IAAI;AACtC,OAAK,YAAY,IAAI,KAAK,UAAU;CACpC;CAED,MAAM,OAAOF,KAA4B;AACxC,OAAK,MAAM,OAAO,IAAI;AACtB,OAAK,YAAY,OAAO,IAAI;CAC5B;AACD"}
package/dist/memory.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { Cache } from "./index-CExVL1mV.cjs";
1
+ import { Cache } from "./index-BSYYdwRm.cjs";
2
2
 
3
3
  //#region src/memory.d.ts
4
4
  declare class InMemoryCache implements Cache {
@@ -9,6 +9,8 @@ declare class InMemoryCache implements Cache {
9
9
  set<T>(key: string, value: T, ttl?: number): Promise<void>;
10
10
  delete(key: string): Promise<void>;
11
11
  }
12
+ //# sourceMappingURL=memory.d.ts.map
13
+
12
14
  //#endregion
13
15
  export { InMemoryCache };
14
16
  //# sourceMappingURL=memory.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.cts","names":[],"sources":["../src/memory.ts"],"sourcesContent":[],"mappings":";;;cAGa,aAAA,YAAyB;;EAAzB,QAAA,WAAc;EAAA,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAIC,OAJD,CAIS,CAJT,GAAA,SAAA,CAAA;EAAA,GAIS,CAAA,GAAA,EAAA,MAAA,CAAA,EAUX,OAVW,CAAA,MAAA,CAAA;EAAC,GAAT,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAmBM,CAnBN,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAmB6B,OAnB7B,CAAA,IAAA,CAAA;EAAO,MAUV,CAAA,GAAA,EAAA,MAAA,CAAA,EAgBG,OAhBH,CAAA,IAAA,CAAA"}
package/dist/memory.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { Cache } from "./index-M02PehQA.mjs";
1
+ import { Cache } from "./index-Dx96gr-9.mjs";
2
2
 
3
3
  //#region src/memory.d.ts
4
4
  declare class InMemoryCache implements Cache {
@@ -9,6 +9,8 @@ declare class InMemoryCache implements Cache {
9
9
  set<T>(key: string, value: T, ttl?: number): Promise<void>;
10
10
  delete(key: string): Promise<void>;
11
11
  }
12
+ //# sourceMappingURL=memory.d.ts.map
13
+
12
14
  //#endregion
13
15
  export { InMemoryCache };
14
16
  //# sourceMappingURL=memory.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.mts","names":[],"sources":["../src/memory.ts"],"sourcesContent":[],"mappings":";;;cAGa,aAAA,YAAyB;;EAAzB,QAAA,WAAc;EAAA,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAIC,OAJD,CAIS,CAJT,GAAA,SAAA,CAAA;EAAA,GAIS,CAAA,GAAA,EAAA,MAAA,CAAA,EAUX,OAVW,CAAA,MAAA,CAAA;EAAC,GAAT,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAmBM,CAnBN,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAmB6B,OAnB7B,CAAA,IAAA,CAAA;EAAO,MAUV,CAAA,GAAA,EAAA,MAAA,CAAA,EAgBG,OAhBH,CAAA,IAAA,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"memory.mjs","names":["key: string","value: T","ttl: number"],"sources":["../src/memory.ts"],"sourcesContent":["import { addSeconds } from 'date-fns';\nimport { type Cache, getExpirationInSeconds } from './';\n\nexport class InMemoryCache implements Cache {\n private store: Map<string, unknown> = new Map();\n private expirations: Map<string, Date> = new Map();\n\n async get<T>(key: string): Promise<T | undefined> {\n const expiration = await this.ttl(key);\n if (!expiration) {\n await this.delete(key);\n return undefined;\n }\n\n return this.store.get(key) as T | undefined;\n }\n\n async ttl(key: string): Promise<number> {\n const expiration = this.expirations.get(key);\n if (!expiration) {\n return 0;\n }\n\n return getExpirationInSeconds(expiration);\n }\n\n async set<T>(key: string, value: T, ttl: number = 600): Promise<void> {\n this.store.set(key, value);\n const now = new Date();\n const expiresAt = addSeconds(now, ttl);\n this.expirations.set(key, expiresAt);\n }\n\n async delete(key: string): Promise<void> {\n this.store.delete(key);\n this.expirations.delete(key);\n }\n}\n"],"mappings":";;;;AAGA,IAAa,gBAAb,MAA4C;CAC1C,AAAQ,wBAA8B,IAAI;CAC1C,AAAQ,8BAAiC,IAAI;CAE7C,MAAM,IAAOA,KAAqC;EAChD,MAAM,aAAa,MAAM,KAAK,IAAI,IAAI;AACtC,OAAK,YAAY;AACf,SAAM,KAAK,OAAO,IAAI;AACtB;EACD;AAED,SAAO,KAAK,MAAM,IAAI,IAAI;CAC3B;CAED,MAAM,IAAIA,KAA8B;EACtC,MAAM,aAAa,KAAK,YAAY,IAAI,IAAI;AAC5C,OAAK,WACH,QAAO;AAGT,SAAO,uBAAuB,WAAW;CAC1C;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;AACpE,OAAK,MAAM,IAAI,KAAK,MAAM;EAC1B,MAAM,sBAAM,IAAI;EAChB,MAAM,YAAY,WAAW,KAAK,IAAI;AACtC,OAAK,YAAY,IAAI,KAAK,UAAU;CACrC;CAED,MAAM,OAAOF,KAA4B;AACvC,OAAK,MAAM,OAAO,IAAI;AACtB,OAAK,YAAY,OAAO,IAAI;CAC7B;AACF"}
1
+ {"version":3,"file":"memory.mjs","names":["key: string","value: T","ttl: number"],"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,AAAQ,wBAA8B,IAAI;CAC1C,AAAQ,8BAAiC,IAAI;CAE7C,MAAM,IAAOA,KAAqC;EACjD,MAAM,aAAa,MAAM,KAAK,IAAI,IAAI;AACtC,OAAK,YAAY;AAChB,SAAM,KAAK,OAAO,IAAI;AACtB;EACA;AAED,SAAO,KAAK,MAAM,IAAI,IAAI;CAC1B;CAED,MAAM,IAAIA,KAA8B;EACvC,MAAM,aAAa,KAAK,YAAY,IAAI,IAAI;AAC5C,OAAK,WACJ,QAAO;AAGR,SAAO,uBAAuB,WAAW;CACzC;CAED,MAAM,IAAOA,KAAaC,OAAUC,MAAc,KAAoB;AACrE,OAAK,MAAM,IAAI,KAAK,MAAM;EAC1B,MAAM,sBAAM,IAAI;EAChB,MAAM,YAAY,WAAW,KAAK,IAAI;AACtC,OAAK,YAAY,IAAI,KAAK,UAAU;CACpC;CAED,MAAM,OAAOF,KAA4B;AACxC,OAAK,MAAM,OAAO,IAAI;AACtB,OAAK,YAAY,OAAO,IAAI;CAC5B;AACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"src-CrE4Nl5T.mjs","names":["expiresAt: string | number | Date | undefined | null"],"sources":["../src/index.ts"],"sourcesContent":["import { differenceInSeconds } from 'date-fns';\n\nexport const getExpirationInSeconds = (\n expiresAt: string | number | Date | undefined | null,\n): number => {\n if (!expiresAt) {\n return 0;\n }\n\n const expirationDate = new Date(expiresAt);\n const now = new Date();\n\n const secondsLeft = differenceInSeconds(expirationDate, now);\n\n return Math.max(secondsLeft, 0);\n};\n\nexport interface Cache {\n /**\n * Retrieves a value from the cache.\n *\n * @param key The key to retrieve the value for.\n * @returns The cached value, or undefined if not found.\n */\n get<T>(key: string): Promise<T | undefined>;\n /**\n * Sets a value in the cache.\n *\n * @param key The key to set the value for.\n * @param value The value to cache.\n * @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.\n */\n set<T>(key: string, value: T, ttl?: number): Promise<void>;\n /**\n * Deletes a value from the cache.\n *\n * @param key The key to delete from the cache.\n */\n delete(key: string): Promise<void>;\n\n /**\n * Retrieves the time-to-live (TTL) for a cached value.\n *\n * @param key The key to retrieve the TTL for.\n * @returns The TTL in seconds, or 0 if the key does not exist.\n */\n ttl(key: string): Promise<number>;\n}\n"],"mappings":";;;AAEA,MAAa,yBAAyB,CACpCA,cACW;AACX,MAAK,UACH,QAAO;CAGT,MAAM,iBAAiB,IAAI,KAAK;CAChC,MAAM,sBAAM,IAAI;CAEhB,MAAM,cAAc,oBAAoB,gBAAgB,IAAI;AAE5D,QAAO,KAAK,IAAI,aAAa,EAAE;AAChC"}
1
+ {"version":3,"file":"src-CrE4Nl5T.mjs","names":["expiresAt: string | number | Date | undefined | null"],"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"],"mappings":";;;AAEA,MAAa,yBAAyB,CACrCA,cACY;AACZ,MAAK,UACJ,QAAO;CAGR,MAAM,iBAAiB,IAAI,KAAK;CAChC,MAAM,sBAAM,IAAI;CAEhB,MAAM,cAAc,oBAAoB,gBAAgB,IAAI;AAE5D,QAAO,KAAK,IAAI,aAAa,EAAE;AAC/B"}
@@ -1 +1 @@
1
- {"version":3,"file":"src-zfYb7mdS.cjs","names":["expiresAt: string | number | Date | undefined | null"],"sources":["../src/index.ts"],"sourcesContent":["import { differenceInSeconds } from 'date-fns';\n\nexport const getExpirationInSeconds = (\n expiresAt: string | number | Date | undefined | null,\n): number => {\n if (!expiresAt) {\n return 0;\n }\n\n const expirationDate = new Date(expiresAt);\n const now = new Date();\n\n const secondsLeft = differenceInSeconds(expirationDate, now);\n\n return Math.max(secondsLeft, 0);\n};\n\nexport interface Cache {\n /**\n * Retrieves a value from the cache.\n *\n * @param key The key to retrieve the value for.\n * @returns The cached value, or undefined if not found.\n */\n get<T>(key: string): Promise<T | undefined>;\n /**\n * Sets a value in the cache.\n *\n * @param key The key to set the value for.\n * @param value The value to cache.\n * @param ttl Optional time-to-live in seconds. If not provided, the value will not expire.\n */\n set<T>(key: string, value: T, ttl?: number): Promise<void>;\n /**\n * Deletes a value from the cache.\n *\n * @param key The key to delete from the cache.\n */\n delete(key: string): Promise<void>;\n\n /**\n * Retrieves the time-to-live (TTL) for a cached value.\n *\n * @param key The key to retrieve the TTL for.\n * @returns The TTL in seconds, or 0 if the key does not exist.\n */\n ttl(key: string): Promise<number>;\n}\n"],"mappings":";;;;AAEA,MAAa,yBAAyB,CACpCA,cACW;AACX,MAAK,UACH,QAAO;CAGT,MAAM,iBAAiB,IAAI,KAAK;CAChC,MAAM,sBAAM,IAAI;CAEhB,MAAM,cAAc,kCAAoB,gBAAgB,IAAI;AAE5D,QAAO,KAAK,IAAI,aAAa,EAAE;AAChC"}
1
+ {"version":3,"file":"src-zfYb7mdS.cjs","names":["expiresAt: string | number | Date | undefined | null"],"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"],"mappings":";;;;AAEA,MAAa,yBAAyB,CACrCA,cACY;AACZ,MAAK,UACJ,QAAO;CAGR,MAAM,iBAAiB,IAAI,KAAK;CAChC,MAAM,sBAAM,IAAI;CAEhB,MAAM,cAAc,kCAAoB,gBAAgB,IAAI;AAE5D,QAAO,KAAK,IAAI,aAAa,EAAE;AAC/B"}
@@ -1 +1 @@
1
- {"version":3,"file":"upstash.cjs","names":["url: string","token: string","Redis","key: string","value: T"],"sources":["../src/upstash.ts"],"sourcesContent":["import { Redis } from '@upstash/redis';\nimport type { Cache } from './';\n\nexport class UpstashCache implements Cache {\n private client: Redis;\n\n constructor(url: string, token: string) {\n this.client = new Redis({\n url,\n token,\n });\n }\n\n async ttl(key: string): Promise<number> {\n const ttl = await this.client.ttl(key);\n\n if (ttl === -2) {\n return 0; // Key does not exist\n }\n\n return ttl; // Returns TTL in seconds\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n const v = await this.client.get(key);\n\n if (v === null) {\n return undefined;\n }\n\n return v as T;\n }\n\n async set<T>(key: string, value: T, ttl = 3600): Promise<void> {\n await this.client.set(key, value, { ex: ttl });\n }\n\n async delete(key: string): Promise<void> {\n await this.client.del(key);\n }\n}\n"],"mappings":";;;;AAGA,IAAa,eAAb,MAA2C;CACzC,AAAQ;CAER,YAAYA,KAAaC,OAAe;AACtC,OAAK,SAAS,IAAIC,sBAAM;GACtB;GACA;EACD;CACF;CAED,MAAM,IAAIC,KAA8B;EACtC,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,IAAI;AAEtC,MAAI,QAAQ,GACV,QAAO;AAGT,SAAO;CACR;CAED,MAAM,IAAOA,KAAqC;EAChD,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,IAAI;AAEpC,MAAI,MAAM,KACR;AAGF,SAAO;CACR;CAED,MAAM,IAAOA,KAAaC,OAAU,MAAM,MAAqB;AAC7D,QAAM,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,IAAK,EAAC;CAC/C;CAED,MAAM,OAAOD,KAA4B;AACvC,QAAM,KAAK,OAAO,IAAI,IAAI;CAC3B;AACF"}
1
+ {"version":3,"file":"upstash.cjs","names":["url: string","token: string","Redis","key: string","value: T"],"sources":["../src/upstash.ts"],"sourcesContent":["import { Redis } from '@upstash/redis';\nimport type { Cache } from './';\n\nexport class UpstashCache implements Cache {\n\tprivate client: Redis;\n\n\tconstructor(url: string, token: string) {\n\t\tthis.client = new Redis({\n\t\t\turl,\n\t\t\ttoken,\n\t\t});\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst ttl = await this.client.ttl(key);\n\n\t\tif (ttl === -2) {\n\t\t\treturn 0; // Key does not exist\n\t\t}\n\n\t\treturn ttl; // Returns TTL in seconds\n\t}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst v = await this.client.get(key);\n\n\t\tif (v === null) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn v as T;\n\t}\n\n\tasync set<T>(key: string, value: T, ttl = 3600): Promise<void> {\n\t\tawait this.client.set(key, value, { ex: ttl });\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tawait this.client.del(key);\n\t}\n}\n"],"mappings":";;;;AAGA,IAAa,eAAb,MAA2C;CAC1C,AAAQ;CAER,YAAYA,KAAaC,OAAe;AACvC,OAAK,SAAS,IAAIC,sBAAM;GACvB;GACA;EACA;CACD;CAED,MAAM,IAAIC,KAA8B;EACvC,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,IAAI;AAEtC,MAAI,QAAQ,GACX,QAAO;AAGR,SAAO;CACP;CAED,MAAM,IAAOA,KAAqC;EACjD,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,IAAI;AAEpC,MAAI,MAAM,KACT;AAGD,SAAO;CACP;CAED,MAAM,IAAOA,KAAaC,OAAU,MAAM,MAAqB;AAC9D,QAAM,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,IAAK,EAAC;CAC9C;CAED,MAAM,OAAOD,KAA4B;AACxC,QAAM,KAAK,OAAO,IAAI,IAAI;CAC1B;AACD"}
@@ -1,4 +1,4 @@
1
- import { Cache } from "./index-CExVL1mV.cjs";
1
+ import { Cache } from "./index-BSYYdwRm.cjs";
2
2
 
3
3
  //#region src/upstash.d.ts
4
4
  declare class UpstashCache implements Cache {
@@ -9,6 +9,8 @@ declare class UpstashCache implements Cache {
9
9
  set<T>(key: string, value: T, ttl?: number): Promise<void>;
10
10
  delete(key: string): Promise<void>;
11
11
  }
12
+ //# sourceMappingURL=upstash.d.ts.map
13
+
12
14
  //#endregion
13
15
  export { UpstashCache };
14
16
  //# sourceMappingURL=upstash.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upstash.d.cts","names":[],"sources":["../src/upstash.ts"],"sourcesContent":[],"mappings":";;;cAGa,YAAA,YAAwB;;EAAxB,WAAA,CAAA,GAAa,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA;EAAA,GAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAUD,OAVC,CAAA,MAAA,CAAA;EAAA,GAUD,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAUG,OAVH,CAUW,CAVX,GAAA,SAAA,CAAA;EAAO,GAUI,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAUF,CAVE,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAUc,OAVd,CAAA,IAAA,CAAA;EAAC,MAAT,CAAA,GAAA,EAAA,MAAA,CAAA,EAcA,OAdA,CAAA,IAAA,CAAA"}
@@ -1,4 +1,4 @@
1
- import { Cache } from "./index-M02PehQA.mjs";
1
+ import { Cache } from "./index-Dx96gr-9.mjs";
2
2
 
3
3
  //#region src/upstash.d.ts
4
4
  declare class UpstashCache implements Cache {
@@ -9,6 +9,8 @@ declare class UpstashCache implements Cache {
9
9
  set<T>(key: string, value: T, ttl?: number): Promise<void>;
10
10
  delete(key: string): Promise<void>;
11
11
  }
12
+ //# sourceMappingURL=upstash.d.ts.map
13
+
12
14
  //#endregion
13
15
  export { UpstashCache };
14
16
  //# sourceMappingURL=upstash.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upstash.d.mts","names":[],"sources":["../src/upstash.ts"],"sourcesContent":[],"mappings":";;;cAGa,YAAA,YAAwB;;EAAxB,WAAA,CAAA,GAAa,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA;EAAA,GAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAUD,OAVC,CAAA,MAAA,CAAA;EAAA,GAUD,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAUG,OAVH,CAUW,CAVX,GAAA,SAAA,CAAA;EAAO,GAUI,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,KAAA,EAUF,CAVE,EAAA,GAAA,CAAA,EAAA,MAAA,CAAA,EAUc,OAVd,CAAA,IAAA,CAAA;EAAC,MAAT,CAAA,GAAA,EAAA,MAAA,CAAA,EAcA,OAdA,CAAA,IAAA,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"upstash.mjs","names":["url: string","token: string","key: string","value: T"],"sources":["../src/upstash.ts"],"sourcesContent":["import { Redis } from '@upstash/redis';\nimport type { Cache } from './';\n\nexport class UpstashCache implements Cache {\n private client: Redis;\n\n constructor(url: string, token: string) {\n this.client = new Redis({\n url,\n token,\n });\n }\n\n async ttl(key: string): Promise<number> {\n const ttl = await this.client.ttl(key);\n\n if (ttl === -2) {\n return 0; // Key does not exist\n }\n\n return ttl; // Returns TTL in seconds\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n const v = await this.client.get(key);\n\n if (v === null) {\n return undefined;\n }\n\n return v as T;\n }\n\n async set<T>(key: string, value: T, ttl = 3600): Promise<void> {\n await this.client.set(key, value, { ex: ttl });\n }\n\n async delete(key: string): Promise<void> {\n await this.client.del(key);\n }\n}\n"],"mappings":";;;AAGA,IAAa,eAAb,MAA2C;CACzC,AAAQ;CAER,YAAYA,KAAaC,OAAe;AACtC,OAAK,SAAS,IAAI,MAAM;GACtB;GACA;EACD;CACF;CAED,MAAM,IAAIC,KAA8B;EACtC,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,IAAI;AAEtC,MAAI,QAAQ,GACV,QAAO;AAGT,SAAO;CACR;CAED,MAAM,IAAOA,KAAqC;EAChD,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,IAAI;AAEpC,MAAI,MAAM,KACR;AAGF,SAAO;CACR;CAED,MAAM,IAAOA,KAAaC,OAAU,MAAM,MAAqB;AAC7D,QAAM,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,IAAK,EAAC;CAC/C;CAED,MAAM,OAAOD,KAA4B;AACvC,QAAM,KAAK,OAAO,IAAI,IAAI;CAC3B;AACF"}
1
+ {"version":3,"file":"upstash.mjs","names":["url: string","token: string","key: string","value: T"],"sources":["../src/upstash.ts"],"sourcesContent":["import { Redis } from '@upstash/redis';\nimport type { Cache } from './';\n\nexport class UpstashCache implements Cache {\n\tprivate client: Redis;\n\n\tconstructor(url: string, token: string) {\n\t\tthis.client = new Redis({\n\t\t\turl,\n\t\t\ttoken,\n\t\t});\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\tconst ttl = await this.client.ttl(key);\n\n\t\tif (ttl === -2) {\n\t\t\treturn 0; // Key does not exist\n\t\t}\n\n\t\treturn ttl; // Returns TTL in seconds\n\t}\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\tconst v = await this.client.get(key);\n\n\t\tif (v === null) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn v as T;\n\t}\n\n\tasync set<T>(key: string, value: T, ttl = 3600): Promise<void> {\n\t\tawait this.client.set(key, value, { ex: ttl });\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tawait this.client.del(key);\n\t}\n}\n"],"mappings":";;;AAGA,IAAa,eAAb,MAA2C;CAC1C,AAAQ;CAER,YAAYA,KAAaC,OAAe;AACvC,OAAK,SAAS,IAAI,MAAM;GACvB;GACA;EACA;CACD;CAED,MAAM,IAAIC,KAA8B;EACvC,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,IAAI;AAEtC,MAAI,QAAQ,GACX,QAAO;AAGR,SAAO;CACP;CAED,MAAM,IAAOA,KAAqC;EACjD,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,IAAI;AAEpC,MAAI,MAAM,KACT;AAGD,SAAO;CACP;CAED,MAAM,IAAOA,KAAaC,OAAU,MAAM,MAAqB;AAC9D,QAAM,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,IAAK,EAAC;CAC9C;CAED,MAAM,OAAOD,KAA4B;AACxC,QAAM,KAAK,OAAO,IAAI,IAAI;CAC1B;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/cache",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Unified cache interface with multiple storage implementations",
5
5
  "private": false,
6
6
  "type": "module",
@@ -2,50 +2,50 @@ import { bench, describe } from 'vitest';
2
2
  import { InMemoryCache } from '../memory';
3
3
 
4
4
  describe('InMemoryCache', () => {
5
- const cache = new InMemoryCache<string>();
6
-
7
- bench('set with TTL', async () => {
8
- await cache.set('key', 'value', 3600);
9
- });
10
-
11
- bench('get (cache hit)', async () => {
12
- await cache.set('hit-key', 'value', 3600);
13
- await cache.get('hit-key');
14
- });
15
-
16
- bench('get (cache miss)', async () => {
17
- await cache.get('nonexistent-key');
18
- });
19
-
20
- bench('delete', async () => {
21
- await cache.set('delete-key', 'value', 3600);
22
- await cache.delete('delete-key');
23
- });
24
-
25
- bench('set + get cycle', async () => {
26
- const key = `cycle-${Math.random()}`;
27
- await cache.set(key, 'value', 3600);
28
- await cache.get(key);
29
- });
5
+ const cache = new InMemoryCache();
6
+
7
+ bench('set with TTL', async () => {
8
+ await cache.set('key', 'value', 3600);
9
+ });
10
+
11
+ bench('get (cache hit)', async () => {
12
+ await cache.set('hit-key', 'value', 3600);
13
+ await cache.get('hit-key');
14
+ });
15
+
16
+ bench('get (cache miss)', async () => {
17
+ await cache.get('nonexistent-key');
18
+ });
19
+
20
+ bench('delete', async () => {
21
+ await cache.set('delete-key', 'value', 3600);
22
+ await cache.delete('delete-key');
23
+ });
24
+
25
+ bench('set + get cycle', async () => {
26
+ const key = `cycle-${Math.random()}`;
27
+ await cache.set(key, 'value', 3600);
28
+ await cache.get(key);
29
+ });
30
30
  });
31
31
 
32
32
  describe('InMemoryCache - Large Scale', () => {
33
- bench('1000 sequential sets', async () => {
34
- const cache = new InMemoryCache<string>();
35
- for (let i = 0; i < 1000; i++) {
36
- await cache.set(`key-${i}`, `value-${i}`, 3600);
37
- }
38
- });
39
-
40
- bench('1000 sequential gets', async () => {
41
- const cache = new InMemoryCache<string>();
42
- // Pre-populate
43
- for (let i = 0; i < 1000; i++) {
44
- await cache.set(`key-${i}`, `value-${i}`, 3600);
45
- }
46
- // Benchmark gets
47
- for (let i = 0; i < 1000; i++) {
48
- await cache.get(`key-${i}`);
49
- }
50
- });
33
+ bench('1000 sequential sets', async () => {
34
+ const cache = new InMemoryCache();
35
+ for (let i = 0; i < 1000; i++) {
36
+ await cache.set(`key-${i}`, `value-${i}`, 3600);
37
+ }
38
+ });
39
+
40
+ bench('1000 sequential gets', async () => {
41
+ const cache = new InMemoryCache();
42
+ // Pre-populate
43
+ for (let i = 0; i < 1000; i++) {
44
+ await cache.set(`key-${i}`, `value-${i}`, 3600);
45
+ }
46
+ // Benchmark gets
47
+ for (let i = 0; i < 1000; i++) {
48
+ await cache.get(`key-${i}`);
49
+ }
50
+ });
51
51
  });
@@ -1,107 +1,144 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
  import type { Cache } from '../';
3
+ import { getExpirationInSeconds } from '../';
3
4
  import { InMemoryCache } from '../memory';
4
5
  import { UpstashCache } from '../upstash';
5
6
 
6
7
  describe('Cache Interface', () => {
7
- describe('interface compliance', () => {
8
- it('InMemoryCache should implement Cache interface', () => {
9
- const cache: Cache = new InMemoryCache();
10
-
11
- expect(typeof cache.get).toBe('function');
12
- expect(typeof cache.set).toBe('function');
13
- expect(typeof cache.delete).toBe('function');
14
- });
15
-
16
- it('UpstashCache should implement Cache interface', () => {
17
- const cache: Cache = new UpstashCache(
18
- 'http://localhost:8079',
19
- 'example_token',
20
- );
21
-
22
- expect(typeof cache.get).toBe('function');
23
- expect(typeof cache.set).toBe('function');
24
- expect(typeof cache.delete).toBe('function');
25
- });
26
- });
27
-
28
- describe('method signatures', () => {
29
- it('should have correct get method signature', () => {
30
- const cache: Cache = new InMemoryCache();
31
-
32
- // These should compile without errors
33
- const getResult: Promise<unknown> = cache.get('test');
34
- expect(getResult).toBeInstanceOf(Promise);
35
- });
36
-
37
- it('should have correct set method signature', () => {
38
- const cache: Cache = new InMemoryCache();
39
-
40
- // These should compile without errors
41
- const setResult: Promise<void> = cache.set('test', 'value');
42
- expect(setResult).toBeInstanceOf(Promise);
43
- });
44
-
45
- it('should have correct delete method signature', () => {
46
- const cache: Cache = new InMemoryCache();
47
-
48
- // These should compile without errors
49
- const deleteResult: Promise<void> = cache.delete('test');
50
- expect(deleteResult).toBeInstanceOf(Promise);
51
- });
52
- });
53
-
54
- describe('function-level generic type support', () => {
55
- it('should support string types with function-level generics', async () => {
56
- const cache: Cache = new InMemoryCache();
57
-
58
- await cache.set<string>('key', 'value');
59
- const result = await cache.get<string>('key');
60
-
61
- expect(typeof result === 'string' || result === undefined).toBe(true);
62
- });
63
-
64
- it('should support number types with function-level generics', async () => {
65
- const cache: Cache = new InMemoryCache();
66
-
67
- await cache.set<number>('key', 42);
68
- const result = await cache.get<number>('key');
69
-
70
- expect(typeof result === 'number' || result === undefined).toBe(true);
71
- });
72
-
73
- it('should support object types with function-level generics', async () => {
74
- interface User {
75
- id: number;
76
- name: string;
77
- }
78
-
79
- const cache: Cache = new InMemoryCache();
80
- const user: User = { id: 1, name: 'John' };
81
-
82
- await cache.set<User>('user', user);
83
- const result = await cache.get<User>('user');
84
-
85
- expect(
86
- result === undefined ||
87
- (typeof result === 'object' && 'id' in result && 'name' in result),
88
- ).toBe(true);
89
- });
90
-
91
- it('should support mixed types in same cache instance', async () => {
92
- const cache: Cache = new InMemoryCache();
93
-
94
- await cache.set<string>('string', 'text');
95
- await cache.set<number>('number', 42);
96
- await cache.set<boolean>('boolean', true);
97
-
98
- const stringResult = await cache.get<string>('string');
99
- const numberResult = await cache.get<number>('number');
100
- const booleanResult = await cache.get<boolean>('boolean');
101
-
102
- expect(stringResult).toBe('text');
103
- expect(numberResult).toBe(42);
104
- expect(booleanResult).toBe(true);
105
- });
106
- });
8
+ describe('interface compliance', () => {
9
+ it('InMemoryCache should implement Cache interface', () => {
10
+ const cache: Cache = new InMemoryCache();
11
+
12
+ expect(typeof cache.get).toBe('function');
13
+ expect(typeof cache.set).toBe('function');
14
+ expect(typeof cache.delete).toBe('function');
15
+ });
16
+
17
+ it('UpstashCache should implement Cache interface', () => {
18
+ const cache: Cache = new UpstashCache(
19
+ 'http://localhost:8079',
20
+ 'example_token',
21
+ );
22
+
23
+ expect(typeof cache.get).toBe('function');
24
+ expect(typeof cache.set).toBe('function');
25
+ expect(typeof cache.delete).toBe('function');
26
+ });
27
+ });
28
+
29
+ describe('method signatures', () => {
30
+ it('should have correct get method signature', () => {
31
+ const cache: Cache = new InMemoryCache();
32
+
33
+ // These should compile without errors
34
+ const getResult: Promise<unknown> = cache.get('test');
35
+ expect(getResult).toBeInstanceOf(Promise);
36
+ });
37
+
38
+ it('should have correct set method signature', () => {
39
+ const cache: Cache = new InMemoryCache();
40
+
41
+ // These should compile without errors
42
+ const setResult: Promise<void> = cache.set('test', 'value');
43
+ expect(setResult).toBeInstanceOf(Promise);
44
+ });
45
+
46
+ it('should have correct delete method signature', () => {
47
+ const cache: Cache = new InMemoryCache();
48
+
49
+ // These should compile without errors
50
+ const deleteResult: Promise<void> = cache.delete('test');
51
+ expect(deleteResult).toBeInstanceOf(Promise);
52
+ });
53
+ });
54
+
55
+ describe('function-level generic type support', () => {
56
+ it('should support string types with function-level generics', async () => {
57
+ const cache: Cache = new InMemoryCache();
58
+
59
+ await cache.set<string>('key', 'value');
60
+ const result = await cache.get<string>('key');
61
+
62
+ expect(typeof result === 'string' || result === undefined).toBe(true);
63
+ });
64
+
65
+ it('should support number types with function-level generics', async () => {
66
+ const cache: Cache = new InMemoryCache();
67
+
68
+ await cache.set<number>('key', 42);
69
+ const result = await cache.get<number>('key');
70
+
71
+ expect(typeof result === 'number' || result === undefined).toBe(true);
72
+ });
73
+
74
+ it('should support object types with function-level generics', async () => {
75
+ interface User {
76
+ id: number;
77
+ name: string;
78
+ }
79
+
80
+ const cache: Cache = new InMemoryCache();
81
+ const user: User = { id: 1, name: 'John' };
82
+
83
+ await cache.set<User>('user', user);
84
+ const result = await cache.get<User>('user');
85
+
86
+ expect(
87
+ result === undefined ||
88
+ (typeof result === 'object' && 'id' in result && 'name' in result),
89
+ ).toBe(true);
90
+ });
91
+
92
+ it('should support mixed types in same cache instance', async () => {
93
+ const cache: Cache = new InMemoryCache();
94
+
95
+ await cache.set<string>('string', 'text');
96
+ await cache.set<number>('number', 42);
97
+ await cache.set<boolean>('boolean', true);
98
+
99
+ const stringResult = await cache.get<string>('string');
100
+ const numberResult = await cache.get<number>('number');
101
+ const booleanResult = await cache.get<boolean>('boolean');
102
+
103
+ expect(stringResult).toBe('text');
104
+ expect(numberResult).toBe(42);
105
+ expect(booleanResult).toBe(true);
106
+ });
107
+ });
108
+ });
109
+
110
+ describe('getExpirationInSeconds', () => {
111
+ it('should return 0 for null', () => {
112
+ expect(getExpirationInSeconds(null)).toBe(0);
113
+ });
114
+
115
+ it('should return 0 for undefined', () => {
116
+ expect(getExpirationInSeconds(undefined)).toBe(0);
117
+ });
118
+
119
+ it('should return positive seconds for future date', () => {
120
+ const futureDate = new Date(Date.now() + 60000); // 1 minute in the future
121
+ const seconds = getExpirationInSeconds(futureDate);
122
+ expect(seconds).toBeGreaterThan(0);
123
+ expect(seconds).toBeLessThanOrEqual(60);
124
+ });
125
+
126
+ it('should return 0 for past date', () => {
127
+ const pastDate = new Date(Date.now() - 60000); // 1 minute in the past
128
+ expect(getExpirationInSeconds(pastDate)).toBe(0);
129
+ });
130
+
131
+ it('should handle ISO string dates', () => {
132
+ const futureDate = new Date(Date.now() + 120000).toISOString(); // 2 minutes in the future
133
+ const seconds = getExpirationInSeconds(futureDate);
134
+ expect(seconds).toBeGreaterThan(0);
135
+ expect(seconds).toBeLessThanOrEqual(120);
136
+ });
137
+
138
+ it('should handle timestamp numbers', () => {
139
+ const futureTimestamp = Date.now() + 30000; // 30 seconds in the future
140
+ const seconds = getExpirationInSeconds(futureTimestamp);
141
+ expect(seconds).toBeGreaterThan(0);
142
+ expect(seconds).toBeLessThanOrEqual(30);
143
+ });
107
144
  });