@ureq/lib-cache-store 0.0.1-alpha.1
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/index.d.mts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +19 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare class MemoryStore {
|
|
2
|
+
private store;
|
|
3
|
+
set<T>(key: string, value: T, ttl?: number): void;
|
|
4
|
+
get<T>(key: string): T | undefined;
|
|
5
|
+
has(key: string): boolean;
|
|
6
|
+
delete(key: string): void;
|
|
7
|
+
clear(): void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare class StorageStore {
|
|
11
|
+
private storage;
|
|
12
|
+
constructor(storage?: Storage);
|
|
13
|
+
private getKey;
|
|
14
|
+
set<T>(key: string, value: T, ttl?: number): void;
|
|
15
|
+
get<T>(key: string): T | undefined;
|
|
16
|
+
has(key: string): boolean;
|
|
17
|
+
delete(key: string): void;
|
|
18
|
+
clear(): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { MemoryStore, StorageStore };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare class MemoryStore {
|
|
2
|
+
private store;
|
|
3
|
+
set<T>(key: string, value: T, ttl?: number): void;
|
|
4
|
+
get<T>(key: string): T | undefined;
|
|
5
|
+
has(key: string): boolean;
|
|
6
|
+
delete(key: string): void;
|
|
7
|
+
clear(): void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare class StorageStore {
|
|
11
|
+
private storage;
|
|
12
|
+
constructor(storage?: Storage);
|
|
13
|
+
private getKey;
|
|
14
|
+
set<T>(key: string, value: T, ttl?: number): void;
|
|
15
|
+
get<T>(key: string): T | undefined;
|
|
16
|
+
has(key: string): boolean;
|
|
17
|
+
delete(key: string): void;
|
|
18
|
+
clear(): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { MemoryStore, StorageStore };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var r=class{store=new Map;set(t,e,s=0){this.store.set(t,{value:e,timestamp:Date.now(),ttl:s});}get(t){let e=this.store.get(t);if(e){if(e.ttl&&Date.now()-e.timestamp>e.ttl){this.store.delete(t);return}return e.value}}has(t){return this.store.has(t)}delete(t){this.store.delete(t);}clear(){this.store.clear();}};var i=class{constructor(t=localStorage){this.storage=t;}getKey(t){return `cache:${t}`}set(t,e,s=0){let a={value:e,timestamp:Date.now(),ttl:s};this.storage.setItem(this.getKey(t),JSON.stringify(a));}get(t){let e=this.storage.getItem(this.getKey(t));if(!e)return;let s=JSON.parse(e);if(s.ttl&&Date.now()-s.timestamp>s.ttl){this.delete(t);return}return s.value}has(t){return this.storage.getItem(this.getKey(t))!==null}delete(t){this.storage.removeItem(this.getKey(t));}clear(){Object.keys(this.storage).forEach(t=>{t.startsWith("cache:")&&this.storage.removeItem(t);});}};exports.MemoryStore=r;exports.StorageStore=i;//# sourceMappingURL=index.js.map
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/memory.ts","../src/storage.ts"],"names":["MemoryStore","key","value","ttl","item","StorageStore","storage","data"],"mappings":"aAMaA,IAAAA,CAAAA,CAAN,KAAkB,CACf,KAAQ,CAAA,IAAI,IAEpB,GAAOC,CAAAA,CAAAA,CAAaC,CAAUC,CAAAA,CAAAA,CAAc,CAAS,CAAA,CACnD,KAAK,KAAM,CAAA,GAAA,CAAIF,CAAK,CAAA,CAClB,KAAAC,CAAAA,CAAAA,CACA,SAAW,CAAA,IAAA,CAAK,GAAI,EAAA,CACpB,GAAAC,CAAAA,CACF,CAAC,EACH,CAEA,GAAOF,CAAAA,CAAAA,CAA4B,CACjC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AAK,KAAMG,CAAAA,CAAI,CAC5B,CAAA,GAAIH,CAAK,CAAA,GAAA,EAAO,IAAK,CAAA,GAAA,EAAQA,CAAAA,CAAAA,CAAK,SAAYA,CAAAA,CAAAA,CAAK,GAAK,CAAA,CACtD,KAAK,MAAOH,CAAAA,CAAG,CACf,CAAA,MACF,CAEA,OAAOG,EAAK,KACd,CAEA,GAAIH,CAAAA,CAAAA,CAAsB,CACxB,OAAO,KAAK,OAAQ,CAAA,OAAA,CAAQ,IAAK,CAAA,MAAA,CAAOA,CAAG,CAAC,CAAM,GAAA,IACpD,CAEA,MAAA,CAAOA,CAAmB,CAAA,CACxB,IAAK,CAAA,OAAA,CAAQ,WAAW,IAAK,CAAA,MAAA,CAAOA,CAAG,CAAC,EAC1C,CAEA,KAAc,EAAA,CACZ,MAAO,CAAA,IAAA,CAAK,IAAK,CAAA,OAAO,CAAE,CAAA,OAAA,CAAQA,GAAO,CACnCA,CAAAA,CAAI,UAAW,CAAA,QAAQ,CACzB,EAAA,IAAA,CAAK,OAAQ,CAAA,UAAA,CAAWA,CAAG,EAE/B,CAAC,EACH,CACF","file":"index.js","sourcesContent":["interface CacheItem<T> {\n value: T;\n timestamp: number;\n ttl: number;\n}\n\nexport class MemoryStore {\n private store = new Map<string, CacheItem<any>>();\n\n set<T>(key: string, value: T, ttl: number = 0): void {\n this.store.set(key, {\n value,\n timestamp: Date.now(),\n ttl,\n });\n }\n\n get<T>(key: string): T | undefined {\n const item = this.store.get(key);\n if (!item) return undefined;\n\n if (item.ttl && Date.now() - item.timestamp > item.ttl) {\n this.store.delete(key);\n return undefined;\n }\n\n return item.value as T;\n }\n\n has(key: string): boolean {\n return this.store.has(key);\n }\n\n delete(key: string): void {\n this.store.delete(key);\n }\n\n clear(): void {\n this.store.clear();\n }\n} ","export class StorageStore {\n constructor(private storage: Storage = localStorage) {}\n\n private getKey(key: string): string {\n return `cache:${key}`;\n }\n\n set<T>(key: string, value: T, ttl: number = 0): void {\n const item = {\n value,\n timestamp: Date.now(),\n ttl,\n };\n this.storage.setItem(this.getKey(key), JSON.stringify(item));\n }\n\n get<T>(key: string): T | undefined {\n const data = this.storage.getItem(this.getKey(key));\n if (!data) return undefined;\n\n const item = JSON.parse(data);\n if (item.ttl && Date.now() - item.timestamp > item.ttl) {\n this.delete(key);\n return undefined;\n }\n\n return item.value as T;\n }\n\n has(key: string): boolean {\n return this.storage.getItem(this.getKey(key)) !== null;\n }\n\n delete(key: string): void {\n this.storage.removeItem(this.getKey(key));\n }\n\n clear(): void {\n Object.keys(this.storage).forEach(key => {\n if (key.startsWith('cache:')) {\n this.storage.removeItem(key);\n }\n });\n }\n} "]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=class{store=new Map;set(t,e,s=0){this.store.set(t,{value:e,timestamp:Date.now(),ttl:s});}get(t){let e=this.store.get(t);if(e){if(e.ttl&&Date.now()-e.timestamp>e.ttl){this.store.delete(t);return}return e.value}}has(t){return this.store.has(t)}delete(t){this.store.delete(t);}clear(){this.store.clear();}};var i=class{constructor(t=localStorage){this.storage=t;}getKey(t){return `cache:${t}`}set(t,e,s=0){let a={value:e,timestamp:Date.now(),ttl:s};this.storage.setItem(this.getKey(t),JSON.stringify(a));}get(t){let e=this.storage.getItem(this.getKey(t));if(!e)return;let s=JSON.parse(e);if(s.ttl&&Date.now()-s.timestamp>s.ttl){this.delete(t);return}return s.value}has(t){return this.storage.getItem(this.getKey(t))!==null}delete(t){this.storage.removeItem(this.getKey(t));}clear(){Object.keys(this.storage).forEach(t=>{t.startsWith("cache:")&&this.storage.removeItem(t);});}};export{r as MemoryStore,i as StorageStore};//# sourceMappingURL=index.mjs.map
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/memory.ts","../src/storage.ts"],"names":["MemoryStore","key","value","ttl","item","StorageStore","storage","data"],"mappings":"AAMaA,IAAAA,CAAAA,CAAN,KAA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,OAAQ,CAAA,OAAA,CAAQ,KAAK,MAAOF,CAAAA,CAAG,CAAG,CAAA,IAAA,CAAK,SAAUG,CAAAA,CAAI,CAAC,EAC7D,CAEA,GAAA,CAAOH,CAA4B,CAAA,CACjC,IAAMM,CAAAA,CAAO,KAAK,OAAQ,CAAA,OAAA,CAAQ,IAAK,CAAA,MAAA,CAAON,CAAG,CAAC,EAClD,GAAI,CAACM,CAAM,CAAA,OAEX,IAAMH,CAAAA,CAAO,KAAK,KAAMG,CAAAA,CAAI,CAC5B,CAAA,GAAIH,CAAK,CAAA,GAAA,EAAO,IAAK,CAAA,GAAA,EAAQA,CAAAA,CAAAA,CAAK,SAAYA,CAAAA,CAAAA,CAAK,GAAK,CAAA,CACtD,KAAK,MAAOH,CAAAA,CAAG,CACf,CAAA,MACF,CAEA,OAAOG,EAAK,KACd,CAEA,GAAIH,CAAAA,CAAAA,CAAsB,CACxB,OAAO,KAAK,OAAQ,CAAA,OAAA,CAAQ,IAAK,CAAA,MAAA,CAAOA,CAAG,CAAC,CAAM,GAAA,IACpD,CAEA,MAAA,CAAOA,CAAmB,CAAA,CACxB,IAAK,CAAA,OAAA,CAAQ,WAAW,IAAK,CAAA,MAAA,CAAOA,CAAG,CAAC,EAC1C,CAEA,KAAc,EAAA,CACZ,MAAO,CAAA,IAAA,CAAK,IAAK,CAAA,OAAO,CAAE,CAAA,OAAA,CAAQA,GAAO,CACnCA,CAAAA,CAAI,UAAW,CAAA,QAAQ,CACzB,EAAA,IAAA,CAAK,OAAQ,CAAA,UAAA,CAAWA,CAAG,EAE/B,CAAC,EACH,CACF","file":"index.mjs","sourcesContent":["interface CacheItem<T> {\n value: T;\n timestamp: number;\n ttl: number;\n}\n\nexport class MemoryStore {\n private store = new Map<string, CacheItem<any>>();\n\n set<T>(key: string, value: T, ttl: number = 0): void {\n this.store.set(key, {\n value,\n timestamp: Date.now(),\n ttl,\n });\n }\n\n get<T>(key: string): T | undefined {\n const item = this.store.get(key);\n if (!item) return undefined;\n\n if (item.ttl && Date.now() - item.timestamp > item.ttl) {\n this.store.delete(key);\n return undefined;\n }\n\n return item.value as T;\n }\n\n has(key: string): boolean {\n return this.store.has(key);\n }\n\n delete(key: string): void {\n this.store.delete(key);\n }\n\n clear(): void {\n this.store.clear();\n }\n} ","export class StorageStore {\n constructor(private storage: Storage = localStorage) {}\n\n private getKey(key: string): string {\n return `cache:${key}`;\n }\n\n set<T>(key: string, value: T, ttl: number = 0): void {\n const item = {\n value,\n timestamp: Date.now(),\n ttl,\n };\n this.storage.setItem(this.getKey(key), JSON.stringify(item));\n }\n\n get<T>(key: string): T | undefined {\n const data = this.storage.getItem(this.getKey(key));\n if (!data) return undefined;\n\n const item = JSON.parse(data);\n if (item.ttl && Date.now() - item.timestamp > item.ttl) {\n this.delete(key);\n return undefined;\n }\n\n return item.value as T;\n }\n\n has(key: string): boolean {\n return this.storage.getItem(this.getKey(key)) !== null;\n }\n\n delete(key: string): void {\n this.storage.removeItem(this.getKey(key));\n }\n\n clear(): void {\n Object.keys(this.storage).forEach(key => {\n if (key.startsWith('cache:')) {\n this.storage.removeItem(key);\n }\n });\n }\n} "]}
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ureq/lib-cache-store",
|
|
3
|
+
"version": "0.0.1-alpha.1",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"tsup": "8.3.6",
|
|
12
|
+
"typescript": "5.7.3"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsup --config tsup.config.ts",
|
|
16
|
+
"dev": "tsup --config tsup.config.ts --watch",
|
|
17
|
+
"test": "vitest"
|
|
18
|
+
}
|
|
19
|
+
}
|