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

refactor: rename PrefixedStorage to Storage #307

Merged
merged 1 commit into from
Nov 3, 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
5 changes: 5 additions & 0 deletions .changeset/real-moons-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@reactive-dot/core": patch
---

Renamed `PrefixedStorage` to `Storage`.
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export { defineConfig, type ChainConfig, type Config } from "./config.js";
export { MutationError, QueryError, ReactiveDotError } from "./errors.js";
export { Query } from "./query-builder.js";
export type { Register } from "./register.js";
export { PrefixedStorage } from "./storage.js";
export { Storage } from "./storage.js";
export { idle, pending } from "./symbols.js";
1 change: 1 addition & 0 deletions packages/core/src/simple-storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type SimpleStorage = Pick<Storage, "getItem" | "removeItem" | "setItem">;
22 changes: 9 additions & 13 deletions packages/core/src/storage.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
export type SimpleStorage = Pick<Storage, "getItem" | "removeItem" | "setItem">;
import type { SimpleStorage } from "./simple-storage.js";

export type PrefixedStorageOptions = {
export type StorageOptions = {
prefix: string;
storage: SimpleStorage;
};

export class PrefixedStorage<TKey extends string = string>
implements SimpleStorage
{
export class Storage<TKey extends string = string> implements SimpleStorage {
readonly prefix: string;

#storage: SimpleStorage;

constructor(options: PrefixedStorageOptions) {
constructor(options: StorageOptions) {
this.prefix = options.prefix;
this.#storage = options.storage;
}
Expand All @@ -30,20 +28,18 @@ export class PrefixedStorage<TKey extends string = string>
}

join<TKeyOverride extends string | void = void>(path: string) {
return new PrefixedStorage<TKeyOverride extends void ? TKey : TKeyOverride>(
{
prefix: `${this.prefix}/${path}`,
storage: this.#storage,
},
);
return new Storage<TKeyOverride extends void ? TKey : TKeyOverride>({
prefix: `${this.prefix}/${path}`,
storage: this.#storage,
});
}

#prefixKey(key: string) {
return `${this.prefix}/${key}`;
}
}

export const defaultStorage = new PrefixedStorage({
export const defaultStorage = new Storage({
prefix: "@reactive-dot",
storage: globalThis.localStorage,
});
6 changes: 3 additions & 3 deletions packages/core/src/wallets/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { type PrefixedStorage, defaultStorage } from "../storage.js";
import { type Storage, defaultStorage } from "../storage.js";
import type { PolkadotSignerAccount } from "./account.js";
import { firstValueFrom, type Observable } from "rxjs";

export type WalletOptions = {
storage?: PrefixedStorage | undefined;
storage?: Storage | undefined;
};

export abstract class Wallet<
Expand All @@ -14,7 +14,7 @@ export abstract class Wallet<

abstract readonly name: string;

readonly #storage: PrefixedStorage;
readonly #storage: Storage;

protected get storage() {
return this.#storage.join<TStorageKey>(this.id);
Expand Down