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: fix typo in removeMeta option for removeItem #281

Merged
merged 4 commits into from
Aug 7, 2023
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: 3 additions & 2 deletions docs/content/2.usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ If value is `undefined`, it is same as calling `removeItem(key)`.
await storage.setItemRaw("data/test.bin", new Uint8Array([1, 2, 3]));
```

### `removeItem(key, opts = { removeMeta = true })`
### `removeItem(key, opts = { removeMeta = false })`

Remove a value (and it's meta) from storage.

```js
await storage.removeItem("foo:bar");
await storage.removeItem("foo:bar", { removeMeta: true });
// same as await storage.removeItem("foo:bar", true);
```

### `getMeta(key, opts = { nativeOnly? })`
Expand Down
4 changes: 2 additions & 2 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ export function createStorage<T extends StorageValue>(
async removeItem(key, opts = {}) {
// TODO: Remove in next major version
if (typeof opts === "boolean") {
opts = { removeMata: opts };
opts = { removeMeta: opts };
}
key = normalizeKey(key);
const { relativeKey, driver } = getMount(key);
if (!driver.removeItem) {
return; // Readonly
}
await asyncCall(driver.removeItem, relativeKey, opts);
if (opts.removeMata) {
if (opts.removeMeta || opts.removeMata /* #281 */) {
await asyncCall(driver.removeItem, relativeKey + "$", opts);
}
if (!driver.watch) {
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export interface Storage<T extends StorageValue = StorageValue> {
removeItem: (
key: string,
opts?:
| (TransactionOptions & { removeMata?: boolean })
| boolean /* legacy: removeMata */
| (TransactionOptions & { removeMeta?: boolean })
| boolean /* legacy: removeMeta */
) => Promise<void>;
// Meta
getMeta: (
Expand Down