@wxt-dev/storage 1.2.7 → 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +8 -3
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { dequal } from "dequal/lite";
|
|
2
|
-
import { Mutex } from "async-mutex";
|
|
3
1
|
import { browser } from "@wxt-dev/browser";
|
|
2
|
+
import { Mutex } from "async-mutex";
|
|
3
|
+
import { dequal } from "dequal/lite";
|
|
4
4
|
|
|
5
5
|
//#region src/index.ts
|
|
6
6
|
/**
|
|
@@ -256,9 +256,11 @@ function createStorage() {
|
|
|
256
256
|
const { driver, driverKey } = resolveKey(key);
|
|
257
257
|
const { version: targetVersion = 1, migrations = {}, onMigrationComplete, debug = false } = opts ?? {};
|
|
258
258
|
if (targetVersion < 1) throw Error("Storage item version cannot be less than 1. Initial versions should be set to 1, not 0.");
|
|
259
|
+
let needsVersionSet = false;
|
|
259
260
|
const migrate = async () => {
|
|
260
261
|
const driverMetaKey = getMetaKey(driverKey);
|
|
261
262
|
const [{ value }, { value: meta }] = await driver.getItems([driverKey, driverMetaKey]);
|
|
263
|
+
needsVersionSet = value == null && meta?.v == null && !!targetVersion;
|
|
262
264
|
if (value == null) return;
|
|
263
265
|
const currentVersion = meta?.v ?? 1;
|
|
264
266
|
if (currentVersion > targetVersion) throw Error(`Version downgrade detected (v${currentVersion} -> v${targetVersion}) for "${key}"`);
|
|
@@ -318,7 +320,10 @@ function createStorage() {
|
|
|
318
320
|
},
|
|
319
321
|
setValue: async (value) => {
|
|
320
322
|
await migrationsDone;
|
|
321
|
-
|
|
323
|
+
if (needsVersionSet) {
|
|
324
|
+
needsVersionSet = false;
|
|
325
|
+
await Promise.all([setItem(driver, driverKey, value), setMeta(driver, driverKey, { v: targetVersion })]);
|
|
326
|
+
} else await setItem(driver, driverKey, value);
|
|
322
327
|
},
|
|
323
328
|
setMeta: async (properties) => {
|
|
324
329
|
await migrationsDone;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxt-dev/storage",
|
|
3
3
|
"description": "Web extension storage API provided by WXT, supports all browsers.",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.8",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"async-mutex": "^0.5.0",
|
|
29
29
|
"dequal": "^2.0.3",
|
|
30
|
-
"@wxt-dev/browser": "^0.1.
|
|
30
|
+
"@wxt-dev/browser": "^0.1.37"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@webext-core/fake-browser": "^1.3.4",
|