@wxt-dev/storage 1.1.0 → 1.1.1

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.
Files changed (2) hide show
  1. package/dist/index.mjs +14 -18
  2. package/package.json +8 -7
package/dist/index.mjs CHANGED
@@ -42,10 +42,8 @@ function createStorage() {
42
42
  const mergeMeta = (oldMeta, newMeta) => {
43
43
  const newFields = { ...oldMeta };
44
44
  Object.entries(newMeta).forEach(([key, value]) => {
45
- if (value == null)
46
- delete newFields[key];
47
- else
48
- newFields[key] = value;
45
+ if (value == null) delete newFields[key];
46
+ else newFields[key] = value;
49
47
  });
50
48
  return newFields;
51
49
  };
@@ -151,8 +149,7 @@ function createStorage() {
151
149
  };
152
150
  });
153
151
  const areaToDriverMetaKeysMap = keys.reduce((map, key) => {
154
- var _a;
155
- map[_a = key.driverArea] ?? (map[_a] = []);
152
+ map[key.driverArea] ??= [];
156
153
  map[key.driverArea].push(key);
157
154
  return map;
158
155
  }, {});
@@ -182,7 +179,7 @@ function createStorage() {
182
179
  const { driverArea, driverKey } = resolveKey(
183
180
  "key" in item ? item.key : item.item.key
184
181
  );
185
- areaToKeyValueMap[driverArea] ?? (areaToKeyValueMap[driverArea] = []);
182
+ areaToKeyValueMap[driverArea] ??= [];
186
183
  areaToKeyValueMap[driverArea].push({
187
184
  key: driverKey,
188
185
  value: item.value
@@ -205,7 +202,7 @@ function createStorage() {
205
202
  const { driverArea, driverKey } = resolveKey(
206
203
  "key" in item ? item.key : item.item.key
207
204
  );
208
- areaToMetaUpdatesMap[driverArea] ?? (areaToMetaUpdatesMap[driverArea] = []);
205
+ areaToMetaUpdatesMap[driverArea] ??= [];
209
206
  areaToMetaUpdatesMap[driverArea].push({
210
207
  key: driverKey,
211
208
  properties: item.meta
@@ -254,7 +251,7 @@ function createStorage() {
254
251
  opts = key.options;
255
252
  }
256
253
  const { driverArea, driverKey } = resolveKey(keyStr);
257
- areaToKeysMap[driverArea] ?? (areaToKeysMap[driverArea] = []);
254
+ areaToKeysMap[driverArea] ??= [];
258
255
  areaToKeysMap[driverArea].push(driverKey);
259
256
  if (opts?.removeMeta) {
260
257
  areaToKeysMap[driverArea].push(getMetaKey(driverKey));
@@ -311,14 +308,16 @@ function createStorage() {
311
308
  driverKey,
312
309
  driverMetaKey
313
310
  ]);
314
- if (value == null)
315
- return;
311
+ if (value == null) return;
316
312
  const currentVersion = meta?.v ?? 1;
317
313
  if (currentVersion > targetVersion) {
318
314
  throw Error(
319
315
  `Version downgrade detected (v${currentVersion} -> v${targetVersion}) for "${key}"`
320
316
  );
321
317
  }
318
+ if (currentVersion === targetVersion) {
319
+ return;
320
+ }
322
321
  console.debug(
323
322
  `[@wxt-dev/storage] Running storage migration for ${key}: v${currentVersion} -> v${targetVersion}`
324
323
  );
@@ -331,7 +330,7 @@ function createStorage() {
331
330
  try {
332
331
  migratedValue = await migrations?.[migrateToVersion]?.(migratedValue) ?? migratedValue;
333
332
  } catch (err) {
334
- throw Error(`v${migrateToVersion} migration failed for "${key}"`, {
333
+ throw new MigrationError(key, migrateToVersion, {
335
334
  cause: err
336
335
  });
337
336
  }
@@ -355,8 +354,7 @@ function createStorage() {
355
354
  const getFallback = () => opts?.fallback ?? opts?.defaultValue ?? null;
356
355
  const getOrInitValue = () => initMutex.runExclusive(async () => {
357
356
  const value = await driver.getItem(driverKey);
358
- if (value != null || opts?.init == null)
359
- return value;
357
+ if (value != null || opts?.init == null) return value;
360
358
  const newValue = await opts.init();
361
359
  await driver.setItem(driverKey, newValue);
362
360
  return newValue;
@@ -475,10 +473,8 @@ function createDriver(storageArea) {
475
473
  watch(key, cb) {
476
474
  const listener = (changes) => {
477
475
  const change = changes[key];
478
- if (change == null)
479
- return;
480
- if (dequal(change.newValue, change.oldValue))
481
- return;
476
+ if (change == null) return;
477
+ if (dequal(change.newValue, change.oldValue)) return;
482
478
  cb(change.newValue ?? null, change.oldValue ?? null);
483
479
  };
484
480
  getStorageArea().onChanged.addListener(listener);
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.1.0",
4
+ "version": "1.1.1",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -23,19 +23,20 @@
23
23
  "email": "aaronklinker1+wxt@gmail.com"
24
24
  },
25
25
  "license": "MIT",
26
+ "funding": "https://github.com/sponsors/wxt-dev",
26
27
  "dependencies": {
27
28
  "async-mutex": "^0.5.0",
28
29
  "dequal": "^2.0.3"
29
30
  },
30
31
  "devDependencies": {
31
32
  "@aklinker1/check": "^1.4.5",
32
- "@types/chrome": "^0.0.268",
33
+ "@types/chrome": "^0.0.280",
33
34
  "@webext-core/fake-browser": "^1.3.1",
34
- "oxlint": "^0.9.9",
35
- "publint": "^0.2.11",
36
- "typescript": "^5.6.2",
37
- "unbuild": "^2.0.0",
38
- "vitest": "^2.0.0"
35
+ "oxlint": "^0.11.1",
36
+ "publint": "^0.2.12",
37
+ "typescript": "^5.6.3",
38
+ "unbuild": "^3.5.0",
39
+ "vitest": "^3.0.7"
39
40
  },
40
41
  "module": "./dist/index.mjs",
41
42
  "types": "./dist/index.d.ts",