Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: configurable storage key #225

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading