Skip to content

Commit

Permalink
refactor: added memory storage type
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Jan 19, 2022
1 parent d14750e commit 7dc15be
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/storage/memory.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AxiosStorage } from '..';
import { buildStorage } from './build';
import type { StorageValue } from './types';

Expand All @@ -24,15 +25,21 @@ import type { StorageValue } from './types';
* ```
*/
export function buildMemoryStorage() {
const data: Record<string, StorageValue> = {};
const storage = buildStorage({
find: (key) => data[key],
find: (key) => storage.data[key],
set: (key, value) => {
data[key] = value;
storage.data[key] = value;
},
remove: (key) => {
delete data[key];
delete storage.data[key];
}
});
return { ...storage, data };
}) as MemoryStorage;

storage.data = Object.create(null) as Record<string, StorageValue>;

return storage;
}

export type MemoryStorage = AxiosStorage & {
data: Record<string, StorageValue>;
};

0 comments on commit 7dc15be

Please sign in to comment.