Skip to content

Commit

Permalink
feat: configurable storage key (#225)
Browse files Browse the repository at this point in the history
Co-authored-by: Tymoteusz Czech <[email protected]>
  • Loading branch information
kwasniew and Tymek authored Aug 6, 2024
1 parent c2b4145 commit 8300c98
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/storage-provider-local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ describe('LocalStorageProvider', () => {
expect(await store.get('key4')).toBe(true);
});

it('should support custom storage key', async () => {
const store1 = new LocalStorageProvider('custom-storage-key');
const store2 = new LocalStorageProvider('custom-storage-key');
const store3 = new LocalStorageProvider('another-custom-storage-key');

await store1.save('key1', 'value1');

expect(await store1.get('key1')).toBe('value1');
expect(await store2.get('key1')).toBe('value1');
expect(await store3.get('key1')).toBe(undefined);
});

it('should return undefined for empty value', async () => {
const store = new LocalStorageProvider();
expect(await store.get('notDefinedKey')).toBe(undefined);
Expand Down
6 changes: 5 additions & 1 deletion src/storage-provider-local.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type IStorageProvider from './storage-provider';

export default class LocalStorageProvider implements IStorageProvider {
private prefix = 'unleash:repository';
private prefix: string;

constructor(name = 'unleash:repository') {
this.prefix = name;
}

public async save(name: string, data: any) {
const repo = JSON.stringify(data);
Expand Down

0 comments on commit 8300c98

Please sign in to comment.