Compare commits

..

2 Commits

Author SHA1 Message Date
8b84d170a6 Fixed test
Some checks failed
Build / Build NPM Project (push) Successful in 1m11s
Build / Tag Version (push) Successful in 17s
Build / Publish Documentation (push) Failing after 19s
2025-07-07 10:42:40 -04:00
37df7e6090 Fixed an unreliable caching backend check
Some checks failed
Build / Build NPM Project (push) Failing after 45s
Build / Publish Documentation (push) Has been skipped
Build / Tag Version (push) Has been skipped
2025-07-07 10:36:47 -04:00
3 changed files with 5 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@ztimson/utils",
"version": "0.25.26",
"version": "0.25.27",
"description": "Utility library",
"author": "Zak Timson",
"license": "MIT",

View File

@ -39,7 +39,7 @@ export class Cache<K extends string | number | symbol, T> {
if(typeof this.options.persistentStorage == 'string')
this.options.persistentStorage = {storage: localStorage, key: this.options.persistentStorage};
if(this.options.persistentStorage?.storage instanceof Database) {
if(this.options.persistentStorage?.storage?.constructor.name == 'Database') {
(async () => {
const persists: any = this.options.persistentStorage;
const table: Table<any, any> = await persists.storage.createTable({name: persists.key, key: this.key});
@ -47,8 +47,8 @@ export class Cache<K extends string | number | symbol, T> {
Object.assign(this.store, rows.reduce((acc, row) => ({...acc, [this.getKey(row)]: row}), {}));
done();
})();
} else {
const stored = this.options.persistentStorage.storage.getItem(this.options.persistentStorage.key);
} else if(this.options.persistentStorage?.storage?.constructor.name == 'Storage') {
const stored = (<Storage>this.options.persistentStorage.storage).getItem(this.options.persistentStorage.key);
if(stored != null) try { Object.assign(this.store, JSON.parse(stored)); } catch { }
done();
}

View File

@ -10,6 +10,7 @@ describe('Cache', () => {
beforeEach(() => {
storageMock = {
constructor: {name: 'Storage' as any},
getItem: jest.fn(),
setItem: jest.fn(),
removeItem: jest.fn(),