From 1ad0de5e6d2ed3107d79ff00f946c8dc60c0ad12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Mon, 4 Nov 2024 02:14:54 +1300 Subject: [PATCH] refactor: rename `PrefixedStorage` to `Storage` --- .changeset/real-moons-invent.md | 5 +++++ packages/core/src/index.ts | 2 +- packages/core/src/simple-storage.ts | 1 + packages/core/src/storage.ts | 22 +++++++++------------- packages/core/src/wallets/wallet.ts | 6 +++--- 5 files changed, 19 insertions(+), 17 deletions(-) create mode 100644 .changeset/real-moons-invent.md create mode 100644 packages/core/src/simple-storage.ts diff --git a/.changeset/real-moons-invent.md b/.changeset/real-moons-invent.md new file mode 100644 index 00000000..2dc25760 --- /dev/null +++ b/.changeset/real-moons-invent.md @@ -0,0 +1,5 @@ +--- +"@reactive-dot/core": patch +--- + +Renamed `PrefixedStorage` to `Storage`. diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 32958d48..cf749d20 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -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"; diff --git a/packages/core/src/simple-storage.ts b/packages/core/src/simple-storage.ts new file mode 100644 index 00000000..5740f349 --- /dev/null +++ b/packages/core/src/simple-storage.ts @@ -0,0 +1 @@ +export type SimpleStorage = Pick; diff --git a/packages/core/src/storage.ts b/packages/core/src/storage.ts index 4a018d61..06b2eccd 100644 --- a/packages/core/src/storage.ts +++ b/packages/core/src/storage.ts @@ -1,18 +1,16 @@ -export type SimpleStorage = Pick; +import type { SimpleStorage } from "./simple-storage.js"; -export type PrefixedStorageOptions = { +export type StorageOptions = { prefix: string; storage: SimpleStorage; }; -export class PrefixedStorage - implements SimpleStorage -{ +export class Storage implements SimpleStorage { readonly prefix: string; #storage: SimpleStorage; - constructor(options: PrefixedStorageOptions) { + constructor(options: StorageOptions) { this.prefix = options.prefix; this.#storage = options.storage; } @@ -30,12 +28,10 @@ export class PrefixedStorage } join(path: string) { - return new PrefixedStorage( - { - prefix: `${this.prefix}/${path}`, - storage: this.#storage, - }, - ); + return new Storage({ + prefix: `${this.prefix}/${path}`, + storage: this.#storage, + }); } #prefixKey(key: string) { @@ -43,7 +39,7 @@ export class PrefixedStorage } } -export const defaultStorage = new PrefixedStorage({ +export const defaultStorage = new Storage({ prefix: "@reactive-dot", storage: globalThis.localStorage, }); diff --git a/packages/core/src/wallets/wallet.ts b/packages/core/src/wallets/wallet.ts index 0663c726..f5a93f94 100644 --- a/packages/core/src/wallets/wallet.ts +++ b/packages/core/src/wallets/wallet.ts @@ -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< @@ -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(this.id);