wxt 0.18.15 → 0.19.0
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/bin/wxt.mjs +1 -1
- package/dist/browser/chrome.d.ts +17 -0
- package/dist/browser/chrome.mjs +7 -0
- package/dist/browser/index.d.ts +18 -0
- package/dist/browser/index.mjs +2 -0
- package/dist/builtin-modules/index.d.ts +2 -0
- package/dist/builtin-modules/index.mjs +2 -0
- package/dist/builtin-modules/unimport.d.ts +8 -0
- package/dist/builtin-modules/unimport.mjs +99 -0
- package/dist/cli/cli-utils.d.ts +25 -0
- package/dist/cli/cli-utils.mjs +58 -0
- package/dist/cli/commands.d.ts +2 -0
- package/dist/cli/commands.mjs +104 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.mjs +11 -0
- package/dist/client/app-config.d.ts +2 -0
- package/dist/client/app-config.mjs +4 -0
- package/dist/client/content-scripts/content-script-context.d.ts +114 -0
- package/dist/client/content-scripts/content-script-context.mjs +169 -0
- package/dist/client/content-scripts/custom-events.d.ts +10 -0
- package/dist/client/content-scripts/custom-events.mjs +13 -0
- package/dist/client/content-scripts/index.d.ts +2 -0
- package/dist/client/content-scripts/index.mjs +2 -0
- package/dist/client/content-scripts/location-watcher.d.ts +12 -0
- package/dist/client/content-scripts/location-watcher.mjs +22 -0
- package/dist/client/content-scripts/ui/index.d.ts +23 -0
- package/dist/client/content-scripts/ui/index.mjs +188 -0
- package/dist/{client.d.ts → client/content-scripts/ui/types.d.ts} +17 -45
- package/dist/client/content-scripts/ui/types.mjs +0 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.mjs +2 -0
- package/dist/core/build.d.ts +15 -0
- package/dist/core/build.mjs +6 -0
- package/dist/core/builders/vite/index.d.ts +3 -0
- package/dist/core/builders/vite/index.mjs +285 -0
- package/dist/core/builders/vite/plugins/bundleAnalysis.d.ts +7 -0
- package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +15 -0
- package/dist/core/builders/vite/plugins/cssEntrypoints.d.ts +13 -0
- package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +22 -0
- package/dist/core/builders/vite/plugins/defineImportMeta.d.ts +14 -0
- package/dist/core/builders/vite/plugins/defineImportMeta.mjs +13 -0
- package/dist/core/builders/vite/plugins/devHtmlPrerender.d.ts +7 -0
- package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +140 -0
- package/dist/core/builders/vite/plugins/devServerGlobals.d.ts +6 -0
- package/dist/core/builders/vite/plugins/devServerGlobals.mjs +15 -0
- package/dist/core/builders/vite/plugins/download.d.ts +10 -0
- package/dist/core/builders/vite/plugins/download.mjs +14 -0
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.d.ts +6 -0
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +16 -0
- package/dist/core/builders/vite/plugins/extensionApiMock.d.ts +11 -0
- package/dist/core/builders/vite/plugins/extensionApiMock.mjs +26 -0
- package/dist/core/builders/vite/plugins/globals.d.ts +3 -0
- package/dist/core/builders/vite/plugins/globals.mjs +15 -0
- package/dist/core/builders/vite/plugins/index.d.ts +17 -0
- package/dist/core/builders/vite/plugins/index.mjs +17 -0
- package/dist/core/builders/vite/plugins/multipageMove.d.ts +20 -0
- package/dist/core/builders/vite/plugins/multipageMove.mjs +59 -0
- package/dist/core/builders/vite/plugins/noopBackground.d.ts +6 -0
- package/dist/core/builders/vite/plugins/noopBackground.mjs +17 -0
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.d.ts +6 -0
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +12 -0
- package/dist/core/builders/vite/plugins/resolveAppConfig.d.ts +6 -0
- package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +26 -0
- package/dist/core/builders/vite/plugins/resolveExtensionApi.d.ts +10 -0
- package/dist/core/builders/vite/plugins/resolveExtensionApi.mjs +15 -0
- package/dist/core/builders/vite/plugins/resolveVirtualModules.d.ts +6 -0
- package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +30 -0
- package/dist/core/builders/vite/plugins/tsconfigPaths.d.ts +3 -0
- package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +12 -0
- package/dist/core/builders/vite/plugins/wxtPluginLoader.d.ts +6 -0
- package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +56 -0
- package/dist/core/clean.d.ts +21 -0
- package/dist/core/clean.mjs +38 -0
- package/dist/core/create-server.d.ts +11 -0
- package/dist/core/create-server.mjs +206 -0
- package/dist/core/define-config.d.ts +2 -0
- package/dist/core/define-config.mjs +3 -0
- package/dist/core/define-runner-config.d.ts +2 -0
- package/dist/core/define-runner-config.mjs +3 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.mjs +8 -0
- package/dist/core/initialize.d.ts +5 -0
- package/dist/core/initialize.mjs +128 -0
- package/dist/core/package-managers/bun.d.ts +2 -0
- package/dist/core/package-managers/bun.mjs +19 -0
- package/dist/core/package-managers/index.d.ts +2 -0
- package/dist/core/package-managers/index.mjs +65 -0
- package/dist/core/package-managers/npm.d.ts +17 -0
- package/dist/core/package-managers/npm.mjs +58 -0
- package/dist/core/package-managers/pnpm.d.ts +2 -0
- package/dist/core/package-managers/pnpm.mjs +21 -0
- package/dist/core/package-managers/types.d.ts +2 -0
- package/dist/core/package-managers/types.mjs +0 -0
- package/dist/core/package-managers/yarn.d.ts +2 -0
- package/dist/core/package-managers/yarn.mjs +31 -0
- package/dist/core/prepare.d.ts +2 -0
- package/dist/core/prepare.mjs +8 -0
- package/dist/core/runners/index.d.ts +2 -0
- package/dist/core/runners/index.mjs +12 -0
- package/dist/core/runners/manual.d.ts +5 -0
- package/dist/core/runners/manual.mjs +16 -0
- package/dist/core/runners/safari.d.ts +5 -0
- package/dist/core/runners/safari.mjs +16 -0
- package/dist/core/runners/web-ext.d.ts +5 -0
- package/dist/core/runners/web-ext.mjs +78 -0
- package/dist/core/runners/wsl.d.ts +5 -0
- package/dist/core/runners/wsl.mjs +16 -0
- package/dist/core/utils/arrays.d.ts +13 -0
- package/dist/{chunk-BERPNPEZ.js → core/utils/arrays.mjs} +6 -10
- package/dist/core/utils/building/build-entrypoints.d.ts +3 -0
- package/dist/core/utils/building/build-entrypoints.mjs +47 -0
- package/dist/core/utils/building/detect-dev-changes.d.ts +57 -0
- package/dist/core/utils/building/detect-dev-changes.mjs +93 -0
- package/dist/core/utils/building/find-entrypoints.d.ts +5 -0
- package/dist/core/utils/building/find-entrypoints.mjs +385 -0
- package/dist/core/utils/building/generate-wxt-dir.d.ts +5 -0
- package/dist/core/utils/building/generate-wxt-dir.mjs +192 -0
- package/dist/core/utils/building/group-entrypoints.d.ts +8 -0
- package/dist/core/utils/building/group-entrypoints.mjs +37 -0
- package/dist/core/utils/building/import-entrypoint.d.ts +16 -0
- package/dist/core/utils/building/import-entrypoint.mjs +97 -0
- package/dist/core/utils/building/index.d.ts +9 -0
- package/dist/core/utils/building/index.mjs +9 -0
- package/dist/core/utils/building/internal-build.d.ts +12 -0
- package/dist/core/utils/building/internal-build.mjs +112 -0
- package/dist/core/utils/building/rebuild.d.ts +23 -0
- package/dist/core/utils/building/rebuild.mjs +39 -0
- package/dist/core/utils/building/resolve-config.d.ts +11 -0
- package/dist/core/utils/building/resolve-config.mjs +364 -0
- package/dist/core/utils/cache.d.ts +8 -0
- package/dist/core/utils/cache.mjs +21 -0
- package/dist/core/utils/cli.d.ts +3 -0
- package/dist/core/utils/cli.mjs +26 -0
- package/dist/core/utils/constants.d.ts +5 -0
- package/dist/core/utils/constants.mjs +1 -0
- package/dist/core/utils/content-scripts.d.ts +11 -0
- package/dist/core/utils/content-scripts.mjs +60 -0
- package/dist/core/utils/content-security-policy.d.ts +14 -0
- package/dist/core/utils/content-security-policy.mjs +39 -0
- package/dist/core/utils/entrypoints.d.ts +25 -0
- package/dist/core/utils/entrypoints.mjs +31 -0
- package/dist/core/utils/eslint.d.ts +1 -0
- package/dist/core/utils/eslint.mjs +11 -0
- package/dist/core/utils/fs.d.ts +13 -0
- package/dist/core/utils/fs.mjs +15 -0
- package/dist/core/utils/globals.d.ts +11 -0
- package/dist/core/utils/globals.mjs +53 -0
- package/dist/core/utils/i18n.d.ts +11 -0
- package/dist/core/utils/i18n.mjs +35 -0
- package/dist/core/utils/log/index.d.ts +4 -0
- package/dist/core/utils/log/index.mjs +4 -0
- package/dist/core/utils/log/printBuildSummary.d.ts +2 -0
- package/dist/core/utils/log/printBuildSummary.mjs +32 -0
- package/dist/core/utils/log/printFileList.d.ts +1 -0
- package/dist/core/utils/log/printFileList.mjs +42 -0
- package/dist/core/utils/log/printHeader.d.ts +1 -0
- package/dist/core/utils/log/printHeader.mjs +7 -0
- package/dist/core/utils/log/printTable.d.ts +1 -0
- package/dist/core/utils/log/printTable.mjs +22 -0
- package/dist/core/utils/manifest.d.ts +44 -0
- package/dist/core/utils/manifest.mjs +512 -0
- package/dist/core/utils/network.d.ts +7 -0
- package/dist/core/utils/network.mjs +38 -0
- package/dist/core/utils/package.d.ts +6 -0
- package/dist/core/utils/package.mjs +14 -0
- package/dist/core/utils/paths.d.ts +11 -0
- package/dist/core/utils/paths.mjs +10 -0
- package/dist/core/utils/strings.d.ts +14 -0
- package/dist/core/utils/strings.mjs +18 -0
- package/dist/core/utils/testing/fake-objects.d.ts +4556 -0
- package/dist/core/utils/testing/fake-objects.mjs +322 -0
- package/dist/core/utils/time.d.ts +9 -0
- package/dist/core/utils/time.mjs +17 -0
- package/dist/core/utils/transform.d.ts +9 -0
- package/dist/core/utils/transform.mjs +17 -0
- package/dist/core/utils/types.d.ts +10 -0
- package/dist/core/utils/types.mjs +0 -0
- package/dist/core/utils/validation.d.ts +15 -0
- package/dist/core/utils/validation.mjs +55 -0
- package/dist/core/utils/virtual-modules.d.ts +22 -0
- package/dist/core/utils/virtual-modules.mjs +14 -0
- package/dist/core/utils/wsl.d.ts +4 -0
- package/dist/core/utils/wsl.mjs +4 -0
- package/dist/core/wxt.d.ts +19 -0
- package/dist/core/wxt.mjs +41 -0
- package/dist/core/zip.d.ts +7 -0
- package/dist/core/zip.mjs +137 -0
- package/dist/index.d.ts +4 -79
- package/dist/index.mjs +3 -0
- package/dist/modules.d.ts +10 -20
- package/dist/{chunk-6XSIWUWF.js → modules.mjs} +7 -16
- package/dist/sandbox/define-app-config.d.ts +19 -0
- package/dist/sandbox/define-app-config.mjs +3 -0
- package/dist/sandbox/define-background.d.ts +3 -0
- package/dist/sandbox/define-background.mjs +4 -0
- package/dist/sandbox/define-content-script.d.ts +2 -0
- package/dist/sandbox/define-content-script.mjs +3 -0
- package/dist/sandbox/define-unlisted-script.d.ts +3 -0
- package/dist/sandbox/define-unlisted-script.mjs +4 -0
- package/dist/sandbox/define-wxt-plugin.d.ts +2 -0
- package/dist/sandbox/define-wxt-plugin.mjs +3 -0
- package/dist/sandbox/dev-server-websocket.d.ts +21 -0
- package/dist/sandbox/dev-server-websocket.mjs +37 -0
- package/dist/sandbox/index.d.ts +11 -0
- package/dist/sandbox/index.mjs +6 -0
- package/dist/sandbox/utils/logger.d.ts +9 -0
- package/dist/sandbox/utils/logger.mjs +15 -0
- package/dist/storage.d.ts +39 -16
- package/dist/{storage.js → storage.mjs} +30 -41
- package/dist/testing/fake-browser.d.ts +1 -0
- package/dist/testing/fake-browser.mjs +1 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.mjs +2 -0
- package/dist/{testing.d.ts → testing/wxt-vitest-plugin.d.ts} +3 -15
- package/dist/testing/wxt-vitest-plugin.mjs +26 -0
- package/dist/{index-nWRfwAJi.d.cts → types.d.ts} +150 -264
- package/dist/types.mjs +0 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.mjs +1 -0
- package/dist/virtual/{background-entrypoint.js → background-entrypoint.mjs} +31 -40
- package/dist/virtual/{content-script-isolated-world-entrypoint.js → content-script-isolated-world-entrypoint.mjs} +9 -13
- package/dist/virtual/{content-script-main-world-entrypoint.js → content-script-main-world-entrypoint.mjs} +9 -14
- package/dist/virtual/mock-browser.mjs +6 -0
- package/dist/virtual/{reload-html.js → reload-html.mjs} +8 -9
- package/dist/virtual/{unlisted-script-entrypoint.js → unlisted-script-entrypoint.mjs} +8 -12
- package/package.json +47 -57
- package/dist/browser.d.ts +0 -18
- package/dist/browser.js +0 -6
- package/dist/chunk-BM6QYGAW.js +0 -1063
- package/dist/chunk-FNTE2L27.js +0 -7
- package/dist/chunk-FP7RYLVL.js +0 -3617
- package/dist/chunk-KPD5J7PZ.js +0 -1065
- package/dist/chunk-QGM4M3NI.js +0 -37
- package/dist/chunk-SGKCDMVR.js +0 -38
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -4438
- package/dist/client.js +0 -424
- package/dist/define-app-config-bg54F_lV.d.ts +0 -294
- package/dist/execa-4UBDUBJZ.js +0 -7244
- package/dist/execa-QLUM2B3W.js +0 -7245
- package/dist/index-nWRfwAJi.d.ts +0 -1401
- package/dist/index.cjs +0 -14473
- package/dist/index.d.cts +0 -81
- package/dist/index.js +0 -696
- package/dist/modules.cjs +0 -96
- package/dist/modules.d.cts +0 -119
- package/dist/modules.js +0 -17
- package/dist/prompt-25QIVJDC.js +0 -755
- package/dist/prompt-7BMKNSWS.js +0 -754
- package/dist/sandbox.d.ts +0 -16
- package/dist/sandbox.js +0 -36
- package/dist/storage.cjs +0 -439
- package/dist/storage.d.cts +0 -200
- package/dist/testing.cjs +0 -2815
- package/dist/testing.d.cts +0 -30
- package/dist/testing.js +0 -40
- package/dist/virtual/mock-browser.js +0 -6
package/dist/sandbox.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { U as UnlistedScriptDefinition, B as BackgroundDefinition, C as ContentScriptDefinition, W as WxtPlugin } from './define-app-config-bg54F_lV.js';
|
|
2
|
-
export { a as WxtAppConfig, d as defineAppConfig } from './define-app-config-bg54F_lV.js';
|
|
3
|
-
export * from '@webext-core/match-patterns';
|
|
4
|
-
import 'webextension-polyfill';
|
|
5
|
-
|
|
6
|
-
declare function defineUnlistedScript(main: () => void): UnlistedScriptDefinition;
|
|
7
|
-
declare function defineUnlistedScript(definition: UnlistedScriptDefinition): UnlistedScriptDefinition;
|
|
8
|
-
|
|
9
|
-
declare function defineBackground(main: () => void): BackgroundDefinition;
|
|
10
|
-
declare function defineBackground(definition: BackgroundDefinition): BackgroundDefinition;
|
|
11
|
-
|
|
12
|
-
declare function defineContentScript(definition: ContentScriptDefinition): ContentScriptDefinition;
|
|
13
|
-
|
|
14
|
-
declare function defineWxtPlugin(plugin: WxtPlugin): WxtPlugin;
|
|
15
|
-
|
|
16
|
-
export { defineBackground, defineContentScript, defineUnlistedScript, defineWxtPlugin };
|
package/dist/sandbox.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// src/sandbox/define-unlisted-script.ts
|
|
2
|
-
function defineUnlistedScript(arg) {
|
|
3
|
-
if (typeof arg === "function") return { main: arg };
|
|
4
|
-
return arg;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
// src/sandbox/define-background.ts
|
|
8
|
-
function defineBackground(arg) {
|
|
9
|
-
if (typeof arg === "function") return { main: arg };
|
|
10
|
-
return arg;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// src/sandbox/define-content-script.ts
|
|
14
|
-
function defineContentScript(definition) {
|
|
15
|
-
return definition;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// src/sandbox/define-wxt-plugin.ts
|
|
19
|
-
function defineWxtPlugin(plugin) {
|
|
20
|
-
return plugin;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// src/sandbox/define-app-config.ts
|
|
24
|
-
function defineAppConfig(config) {
|
|
25
|
-
return config;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// src/sandbox/index.ts
|
|
29
|
-
export * from "@webext-core/match-patterns";
|
|
30
|
-
export {
|
|
31
|
-
defineAppConfig,
|
|
32
|
-
defineBackground,
|
|
33
|
-
defineContentScript,
|
|
34
|
-
defineUnlistedScript,
|
|
35
|
-
defineWxtPlugin
|
|
36
|
-
};
|
package/dist/storage.cjs
DELETED
|
@@ -1,439 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/storage.ts
|
|
31
|
-
var storage_exports = {};
|
|
32
|
-
__export(storage_exports, {
|
|
33
|
-
storage: () => storage
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(storage_exports);
|
|
36
|
-
|
|
37
|
-
// src/browser.ts
|
|
38
|
-
var import_webextension_polyfill = __toESM(require("webextension-polyfill"), 1);
|
|
39
|
-
var browser = import_webextension_polyfill.default;
|
|
40
|
-
|
|
41
|
-
// src/storage.ts
|
|
42
|
-
var import_lite = require("dequal/lite");
|
|
43
|
-
|
|
44
|
-
// src/sandbox/utils/logger.ts
|
|
45
|
-
var import_meta = {};
|
|
46
|
-
function print(method, ...args) {
|
|
47
|
-
if (import_meta.env.MODE === "production") return;
|
|
48
|
-
if (typeof args[0] === "string") {
|
|
49
|
-
const message = args.shift();
|
|
50
|
-
method(`[wxt] ${message}`, ...args);
|
|
51
|
-
} else {
|
|
52
|
-
method("[wxt]", ...args);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
var logger = {
|
|
56
|
-
debug: (...args) => print(console.debug, ...args),
|
|
57
|
-
log: (...args) => print(console.log, ...args),
|
|
58
|
-
warn: (...args) => print(console.warn, ...args),
|
|
59
|
-
error: (...args) => print(console.error, ...args)
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// src/core/utils/arrays.ts
|
|
63
|
-
function toArray(a) {
|
|
64
|
-
return Array.isArray(a) ? a : [a];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// src/storage.ts
|
|
68
|
-
var storage = createStorage();
|
|
69
|
-
function createStorage() {
|
|
70
|
-
const drivers = {
|
|
71
|
-
local: createDriver("local"),
|
|
72
|
-
session: createDriver("session"),
|
|
73
|
-
sync: createDriver("sync"),
|
|
74
|
-
managed: createDriver("managed")
|
|
75
|
-
};
|
|
76
|
-
const getDriver = (area) => {
|
|
77
|
-
const driver = drivers[area];
|
|
78
|
-
if (driver == null) {
|
|
79
|
-
const areaNames = Object.keys(drivers).join(", ");
|
|
80
|
-
throw Error(`Invalid area "${area}". Options: ${areaNames}`);
|
|
81
|
-
}
|
|
82
|
-
return driver;
|
|
83
|
-
};
|
|
84
|
-
const resolveKey = (key) => {
|
|
85
|
-
const deliminatorIndex = key.indexOf(":");
|
|
86
|
-
const driverArea = key.substring(0, deliminatorIndex);
|
|
87
|
-
const driverKey = key.substring(deliminatorIndex + 1);
|
|
88
|
-
if (driverKey == null)
|
|
89
|
-
throw Error(
|
|
90
|
-
`Storage key should be in the form of "area:key", but received "${key}"`
|
|
91
|
-
);
|
|
92
|
-
return {
|
|
93
|
-
driverArea,
|
|
94
|
-
driverKey,
|
|
95
|
-
driver: getDriver(driverArea)
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
const getMetaKey = (key) => key + "$";
|
|
99
|
-
const getValueOrDefault = (value, defaultValue) => value ?? defaultValue ?? null;
|
|
100
|
-
const getMetaValue = (properties) => typeof properties === "object" && !Array.isArray(properties) ? properties : {};
|
|
101
|
-
const getItem = async (driver, driverKey, opts) => {
|
|
102
|
-
const res = await driver.getItem(driverKey);
|
|
103
|
-
return getValueOrDefault(res, opts?.defaultValue);
|
|
104
|
-
};
|
|
105
|
-
const getMeta = async (driver, driverKey) => {
|
|
106
|
-
const metaKey = getMetaKey(driverKey);
|
|
107
|
-
const res = await driver.getItem(metaKey);
|
|
108
|
-
return getMetaValue(res);
|
|
109
|
-
};
|
|
110
|
-
const setItem = async (driver, driverKey, value) => {
|
|
111
|
-
await driver.setItem(driverKey, value ?? null);
|
|
112
|
-
};
|
|
113
|
-
const setMeta = async (driver, driverKey, properties) => {
|
|
114
|
-
const metaKey = getMetaKey(driverKey);
|
|
115
|
-
const existingFields = getMetaValue(await driver.getItem(metaKey));
|
|
116
|
-
const newFields = { ...existingFields };
|
|
117
|
-
Object.entries(properties).forEach(([key, value]) => {
|
|
118
|
-
if (value == null) {
|
|
119
|
-
delete newFields[key];
|
|
120
|
-
} else {
|
|
121
|
-
newFields[key] = value;
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
await driver.setItem(metaKey, newFields);
|
|
125
|
-
};
|
|
126
|
-
const removeItem = async (driver, driverKey, opts) => {
|
|
127
|
-
await driver.removeItem(driverKey);
|
|
128
|
-
if (opts?.removeMeta) {
|
|
129
|
-
const metaKey = getMetaKey(driverKey);
|
|
130
|
-
await driver.removeItem(metaKey);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
const removeMeta = async (driver, driverKey, properties) => {
|
|
134
|
-
const metaKey = getMetaKey(driverKey);
|
|
135
|
-
if (properties == null) {
|
|
136
|
-
await driver.removeItem(metaKey);
|
|
137
|
-
} else {
|
|
138
|
-
const newFields = getMetaValue(await driver.getItem(metaKey));
|
|
139
|
-
toArray(properties).forEach((field) => delete newFields[field]);
|
|
140
|
-
await driver.setItem(metaKey, newFields);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
const watch = (driver, driverKey, cb) => {
|
|
144
|
-
return driver.watch(driverKey, cb);
|
|
145
|
-
};
|
|
146
|
-
const storage2 = {
|
|
147
|
-
getItem: async (key, opts) => {
|
|
148
|
-
const { driver, driverKey } = resolveKey(key);
|
|
149
|
-
return await getItem(driver, driverKey, opts);
|
|
150
|
-
},
|
|
151
|
-
getItems: async (keys) => {
|
|
152
|
-
const areaToKeyMap = /* @__PURE__ */ new Map();
|
|
153
|
-
const keyToOptsMap = /* @__PURE__ */ new Map();
|
|
154
|
-
keys.forEach((key) => {
|
|
155
|
-
let keyStr;
|
|
156
|
-
let opts;
|
|
157
|
-
if (typeof key === "string") {
|
|
158
|
-
keyStr = key;
|
|
159
|
-
} else {
|
|
160
|
-
keyStr = key.key;
|
|
161
|
-
opts = key.options;
|
|
162
|
-
}
|
|
163
|
-
const { driverArea, driverKey } = resolveKey(keyStr);
|
|
164
|
-
const keys2 = areaToKeyMap.get(driverArea) ?? [];
|
|
165
|
-
areaToKeyMap.set(driverArea, keys2.concat(driverKey));
|
|
166
|
-
keyToOptsMap.set(keyStr, opts);
|
|
167
|
-
});
|
|
168
|
-
const results = await Promise.all(
|
|
169
|
-
Array.from(areaToKeyMap.entries()).map(async ([driverArea, keys2]) => {
|
|
170
|
-
const driverResults = await drivers[driverArea].getItems(keys2);
|
|
171
|
-
return driverResults.map((driverResult) => {
|
|
172
|
-
const key = `${driverArea}:${driverResult.key}`;
|
|
173
|
-
const value = getValueOrDefault(
|
|
174
|
-
driverResult.value,
|
|
175
|
-
keyToOptsMap.get(key)?.defaultValue
|
|
176
|
-
);
|
|
177
|
-
return { key, value };
|
|
178
|
-
});
|
|
179
|
-
})
|
|
180
|
-
);
|
|
181
|
-
return results.flat();
|
|
182
|
-
},
|
|
183
|
-
getMeta: async (key) => {
|
|
184
|
-
const { driver, driverKey } = resolveKey(key);
|
|
185
|
-
return await getMeta(driver, driverKey);
|
|
186
|
-
},
|
|
187
|
-
setItem: async (key, value) => {
|
|
188
|
-
const { driver, driverKey } = resolveKey(key);
|
|
189
|
-
await setItem(driver, driverKey, value);
|
|
190
|
-
},
|
|
191
|
-
setItems: async (values) => {
|
|
192
|
-
const areaToKeyValueMap = /* @__PURE__ */ new Map();
|
|
193
|
-
values.forEach(({ key, value }) => {
|
|
194
|
-
const { driverArea, driverKey } = resolveKey(key);
|
|
195
|
-
const values2 = areaToKeyValueMap.get(driverArea) ?? [];
|
|
196
|
-
areaToKeyValueMap.set(
|
|
197
|
-
driverArea,
|
|
198
|
-
values2.concat({ key: driverKey, value })
|
|
199
|
-
);
|
|
200
|
-
});
|
|
201
|
-
await Promise.all(
|
|
202
|
-
Array.from(areaToKeyValueMap.entries()).map(
|
|
203
|
-
async ([driverArea, values2]) => {
|
|
204
|
-
const driver = getDriver(driverArea);
|
|
205
|
-
await driver.setItems(values2);
|
|
206
|
-
}
|
|
207
|
-
)
|
|
208
|
-
);
|
|
209
|
-
},
|
|
210
|
-
setMeta: async (key, properties) => {
|
|
211
|
-
const { driver, driverKey } = resolveKey(key);
|
|
212
|
-
await setMeta(driver, driverKey, properties);
|
|
213
|
-
},
|
|
214
|
-
removeItem: async (key, opts) => {
|
|
215
|
-
const { driver, driverKey } = resolveKey(key);
|
|
216
|
-
await removeItem(driver, driverKey, opts);
|
|
217
|
-
},
|
|
218
|
-
removeItems: async (keys) => {
|
|
219
|
-
const areaToKeysMap = /* @__PURE__ */ new Map();
|
|
220
|
-
keys.forEach((key) => {
|
|
221
|
-
let keyStr;
|
|
222
|
-
let opts;
|
|
223
|
-
if (typeof key === "string") {
|
|
224
|
-
keyStr = key;
|
|
225
|
-
} else {
|
|
226
|
-
keyStr = key.key;
|
|
227
|
-
opts = key.options;
|
|
228
|
-
}
|
|
229
|
-
const { driverArea, driverKey } = resolveKey(keyStr);
|
|
230
|
-
const areaKeys = areaToKeysMap.get(driverArea) ?? [];
|
|
231
|
-
areaKeys.push(driverKey);
|
|
232
|
-
if (opts?.removeMeta) {
|
|
233
|
-
areaKeys.push(getMetaKey(driverKey));
|
|
234
|
-
}
|
|
235
|
-
areaToKeysMap.set(driverArea, areaKeys);
|
|
236
|
-
});
|
|
237
|
-
await Promise.all(
|
|
238
|
-
Array.from(areaToKeysMap.entries()).map(async ([driverArea, keys2]) => {
|
|
239
|
-
const driver = getDriver(driverArea);
|
|
240
|
-
await driver.removeItems(keys2);
|
|
241
|
-
})
|
|
242
|
-
);
|
|
243
|
-
},
|
|
244
|
-
removeMeta: async (key, properties) => {
|
|
245
|
-
const { driver, driverKey } = resolveKey(key);
|
|
246
|
-
await removeMeta(driver, driverKey, properties);
|
|
247
|
-
},
|
|
248
|
-
snapshot: async (base, opts) => {
|
|
249
|
-
const driver = getDriver(base);
|
|
250
|
-
const data = await driver.snapshot();
|
|
251
|
-
opts?.excludeKeys?.forEach((key) => {
|
|
252
|
-
delete data[key];
|
|
253
|
-
delete data[getMetaKey(key)];
|
|
254
|
-
});
|
|
255
|
-
return data;
|
|
256
|
-
},
|
|
257
|
-
restoreSnapshot: async (base, data) => {
|
|
258
|
-
const driver = getDriver(base);
|
|
259
|
-
await driver.restoreSnapshot(data);
|
|
260
|
-
},
|
|
261
|
-
watch: (key, cb) => {
|
|
262
|
-
const { driver, driverKey } = resolveKey(key);
|
|
263
|
-
return watch(driver, driverKey, cb);
|
|
264
|
-
},
|
|
265
|
-
unwatch() {
|
|
266
|
-
Object.values(drivers).forEach((driver) => {
|
|
267
|
-
driver.unwatch();
|
|
268
|
-
});
|
|
269
|
-
},
|
|
270
|
-
defineItem: (key, opts) => {
|
|
271
|
-
const { driver, driverKey } = resolveKey(key);
|
|
272
|
-
const { version: targetVersion = 1, migrations = {} } = opts ?? {};
|
|
273
|
-
if (targetVersion < 1) {
|
|
274
|
-
throw Error(
|
|
275
|
-
"Storage item version cannot be less than 1. Initial versions should be set to 1, not 0."
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
const migrate = async () => {
|
|
279
|
-
const driverMetaKey = getMetaKey(driverKey);
|
|
280
|
-
const [{ value }, { value: meta }] = await driver.getItems([
|
|
281
|
-
driverKey,
|
|
282
|
-
driverMetaKey
|
|
283
|
-
]);
|
|
284
|
-
if (value == null) return;
|
|
285
|
-
const currentVersion = meta?.v ?? 1;
|
|
286
|
-
if (currentVersion > targetVersion) {
|
|
287
|
-
throw Error(
|
|
288
|
-
`Version downgrade detected (v${currentVersion} -> v${targetVersion}) for "${key}"`
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
logger.debug(
|
|
292
|
-
`Running storage migration for ${key}: v${currentVersion} -> v${targetVersion}`
|
|
293
|
-
);
|
|
294
|
-
const migrationsToRun = Array.from(
|
|
295
|
-
{ length: targetVersion - currentVersion },
|
|
296
|
-
(_, i) => currentVersion + i + 1
|
|
297
|
-
);
|
|
298
|
-
let migratedValue = value;
|
|
299
|
-
for (const migrateToVersion of migrationsToRun) {
|
|
300
|
-
migratedValue = await migrations?.[migrateToVersion]?.(migratedValue) ?? migratedValue;
|
|
301
|
-
}
|
|
302
|
-
await driver.setItems([
|
|
303
|
-
{ key: driverKey, value: migratedValue },
|
|
304
|
-
{ key: driverMetaKey, value: { ...meta, v: targetVersion } }
|
|
305
|
-
]);
|
|
306
|
-
logger.debug(
|
|
307
|
-
`Storage migration completed for ${key} v${targetVersion}`,
|
|
308
|
-
{ migratedValue }
|
|
309
|
-
);
|
|
310
|
-
};
|
|
311
|
-
const migrationsDone = opts?.migrations == null ? Promise.resolve() : migrate().catch((err) => {
|
|
312
|
-
logger.error(`Migration failed for ${key}`, err);
|
|
313
|
-
});
|
|
314
|
-
const getDefaultValue = () => opts?.defaultValue ?? null;
|
|
315
|
-
return {
|
|
316
|
-
get defaultValue() {
|
|
317
|
-
return getDefaultValue();
|
|
318
|
-
},
|
|
319
|
-
getValue: async () => {
|
|
320
|
-
await migrationsDone;
|
|
321
|
-
return await getItem(driver, driverKey, opts);
|
|
322
|
-
},
|
|
323
|
-
getMeta: async () => {
|
|
324
|
-
await migrationsDone;
|
|
325
|
-
return await getMeta(driver, driverKey);
|
|
326
|
-
},
|
|
327
|
-
setValue: async (value) => {
|
|
328
|
-
await migrationsDone;
|
|
329
|
-
return await setItem(driver, driverKey, value);
|
|
330
|
-
},
|
|
331
|
-
setMeta: async (properties) => {
|
|
332
|
-
await migrationsDone;
|
|
333
|
-
return await setMeta(driver, driverKey, properties);
|
|
334
|
-
},
|
|
335
|
-
removeValue: async (opts2) => {
|
|
336
|
-
await migrationsDone;
|
|
337
|
-
return await removeItem(driver, driverKey, opts2);
|
|
338
|
-
},
|
|
339
|
-
removeMeta: async (properties) => {
|
|
340
|
-
await migrationsDone;
|
|
341
|
-
return await removeMeta(driver, driverKey, properties);
|
|
342
|
-
},
|
|
343
|
-
watch: (cb) => watch(
|
|
344
|
-
driver,
|
|
345
|
-
driverKey,
|
|
346
|
-
(newValue, oldValue) => cb(newValue ?? getDefaultValue(), oldValue ?? getDefaultValue())
|
|
347
|
-
),
|
|
348
|
-
migrate
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
|
-
return storage2;
|
|
353
|
-
}
|
|
354
|
-
function createDriver(storageArea) {
|
|
355
|
-
const getStorageArea = () => {
|
|
356
|
-
if (browser.runtime == null) {
|
|
357
|
-
throw Error(
|
|
358
|
-
[
|
|
359
|
-
"'wxt/storage' must be loaded in a web extension environment",
|
|
360
|
-
"\n - If thrown during a build, see https://github.com/wxt-dev/wxt/issues/371",
|
|
361
|
-
" - If thrown during tests, mock 'wxt/browser' correctly. See https://wxt.dev/guide/go-further/testing.html\n"
|
|
362
|
-
].join("\n")
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
if (browser.storage == null) {
|
|
366
|
-
throw Error(
|
|
367
|
-
"You must add the 'storage' permission to your manifest to use 'wxt/storage'"
|
|
368
|
-
);
|
|
369
|
-
}
|
|
370
|
-
const area = browser.storage[storageArea];
|
|
371
|
-
if (area == null)
|
|
372
|
-
throw Error(`"browser.storage.${storageArea}" is undefined`);
|
|
373
|
-
return area;
|
|
374
|
-
};
|
|
375
|
-
const watchListeners = /* @__PURE__ */ new Set();
|
|
376
|
-
return {
|
|
377
|
-
getItem: async (key) => {
|
|
378
|
-
const res = await getStorageArea().get(key);
|
|
379
|
-
return res[key];
|
|
380
|
-
},
|
|
381
|
-
getItems: async (keys) => {
|
|
382
|
-
const result = await getStorageArea().get(keys);
|
|
383
|
-
return keys.map((key) => ({ key, value: result[key] ?? null }));
|
|
384
|
-
},
|
|
385
|
-
setItem: async (key, value) => {
|
|
386
|
-
if (value == null) {
|
|
387
|
-
await getStorageArea().remove(key);
|
|
388
|
-
} else {
|
|
389
|
-
await getStorageArea().set({ [key]: value });
|
|
390
|
-
}
|
|
391
|
-
},
|
|
392
|
-
setItems: async (values) => {
|
|
393
|
-
const map = values.reduce(
|
|
394
|
-
(map2, { key, value }) => {
|
|
395
|
-
map2[key] = value;
|
|
396
|
-
return map2;
|
|
397
|
-
},
|
|
398
|
-
{}
|
|
399
|
-
);
|
|
400
|
-
await getStorageArea().set(map);
|
|
401
|
-
},
|
|
402
|
-
removeItem: async (key) => {
|
|
403
|
-
await getStorageArea().remove(key);
|
|
404
|
-
},
|
|
405
|
-
removeItems: async (keys) => {
|
|
406
|
-
await getStorageArea().remove(keys);
|
|
407
|
-
},
|
|
408
|
-
snapshot: async () => {
|
|
409
|
-
return await getStorageArea().get();
|
|
410
|
-
},
|
|
411
|
-
restoreSnapshot: async (data) => {
|
|
412
|
-
await getStorageArea().set(data);
|
|
413
|
-
},
|
|
414
|
-
watch(key, cb) {
|
|
415
|
-
const listener = (changes) => {
|
|
416
|
-
const change = changes[key];
|
|
417
|
-
if (change == null) return;
|
|
418
|
-
if ((0, import_lite.dequal)(change.newValue, change.oldValue)) return;
|
|
419
|
-
cb(change.newValue ?? null, change.oldValue ?? null);
|
|
420
|
-
};
|
|
421
|
-
getStorageArea().onChanged.addListener(listener);
|
|
422
|
-
watchListeners.add(listener);
|
|
423
|
-
return () => {
|
|
424
|
-
getStorageArea().onChanged.removeListener(listener);
|
|
425
|
-
watchListeners.delete(listener);
|
|
426
|
-
};
|
|
427
|
-
},
|
|
428
|
-
unwatch() {
|
|
429
|
-
watchListeners.forEach((listener) => {
|
|
430
|
-
getStorageArea().onChanged.removeListener(listener);
|
|
431
|
-
});
|
|
432
|
-
watchListeners.clear();
|
|
433
|
-
}
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
437
|
-
0 && (module.exports = {
|
|
438
|
-
storage
|
|
439
|
-
});
|
package/dist/storage.d.cts
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
declare const storage: WxtStorage;
|
|
2
|
-
interface WxtStorage {
|
|
3
|
-
/**
|
|
4
|
-
* Get an item from storage, or return `null` if it doesn't exist.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* await storage.getItem<number>("local:installDate");
|
|
8
|
-
*/
|
|
9
|
-
getItem<T>(key: StorageItemKey, opts?: GetItemOptions<T>): Promise<T | null>;
|
|
10
|
-
/**
|
|
11
|
-
* Get multiple items from storage. The return order is guaranteed to be the same as the order
|
|
12
|
-
* requested.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* await storage.getItems(["local:installDate", "session:someCounter"]);
|
|
16
|
-
*/
|
|
17
|
-
getItems(keys: Array<StorageItemKey | {
|
|
18
|
-
key: StorageItemKey;
|
|
19
|
-
options?: GetItemOptions<any>;
|
|
20
|
-
}>): Promise<Array<{
|
|
21
|
-
key: StorageItemKey;
|
|
22
|
-
value: any;
|
|
23
|
-
}>>;
|
|
24
|
-
/**
|
|
25
|
-
* Return an object containing metadata about the key. Object is stored at `key + "$"`. If value
|
|
26
|
-
* is not an object, it returns an empty object.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* await storage.getMeta("local:installDate");
|
|
30
|
-
*/
|
|
31
|
-
getMeta<T extends Record<string, unknown>>(key: StorageItemKey): Promise<T>;
|
|
32
|
-
/**
|
|
33
|
-
* Set a value in storage. Setting a value to `null` or `undefined` is equivalent to calling
|
|
34
|
-
* `removeItem`.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* await storage.setItem<number>("local:installDate", Date.now());
|
|
38
|
-
*/
|
|
39
|
-
setItem<T>(key: StorageItemKey, value: T | null): Promise<void>;
|
|
40
|
-
/**
|
|
41
|
-
* Set multiple values in storage. If a value is set to `null` or `undefined`, the key is removed.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* await storage.setItem([
|
|
45
|
-
* { key: "local:installDate", value: Date.now() },
|
|
46
|
-
* { key: "session:someCounter, value: 5 },
|
|
47
|
-
* ]);
|
|
48
|
-
*/
|
|
49
|
-
setItems(values: Array<{
|
|
50
|
-
key: StorageItemKey;
|
|
51
|
-
value: any;
|
|
52
|
-
}>): Promise<void>;
|
|
53
|
-
/**
|
|
54
|
-
* Sets metadata properties. If some properties are already set, but are not included in the
|
|
55
|
-
* `properties` parameter, they will not be removed.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* await storage.setMeta("local:installDate", { appVersion });
|
|
59
|
-
*/
|
|
60
|
-
setMeta<T extends Record<string, unknown>>(key: StorageItemKey, properties: T | null): Promise<void>;
|
|
61
|
-
/**
|
|
62
|
-
* Removes an item from storage.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* await storage.removeItem("local:installDate");
|
|
66
|
-
*/
|
|
67
|
-
removeItem(key: StorageItemKey, opts?: RemoveItemOptions): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* Remove a list of keys from storage.
|
|
70
|
-
*/
|
|
71
|
-
removeItems(keys: Array<StorageItemKey | {
|
|
72
|
-
key: StorageItemKey;
|
|
73
|
-
options?: RemoveItemOptions;
|
|
74
|
-
}>): Promise<void>;
|
|
75
|
-
/**
|
|
76
|
-
* Remove the entire metadata for a key, or specific properties by name.
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* // Remove all metadata properties from the item
|
|
80
|
-
* await storage.removeMeta("local:installDate");
|
|
81
|
-
*
|
|
82
|
-
* // Remove only specific the "v" field
|
|
83
|
-
* await storage.removeMeta("local:installDate", "v")
|
|
84
|
-
*/
|
|
85
|
-
removeMeta(key: StorageItemKey, properties?: string | string[]): Promise<void>;
|
|
86
|
-
/**
|
|
87
|
-
* Return all the items in storage.
|
|
88
|
-
*/
|
|
89
|
-
snapshot(base: StorageArea, opts?: SnapshotOptions): Promise<Record<string, unknown>>;
|
|
90
|
-
/**
|
|
91
|
-
* Restores the results of `snapshot`. If new properties have been saved since the snapshot, they are
|
|
92
|
-
* not overridden. Only values existing in the snapshot are overridden.
|
|
93
|
-
*/
|
|
94
|
-
restoreSnapshot(base: StorageArea, data: any): Promise<void>;
|
|
95
|
-
/**
|
|
96
|
-
* Watch for changes to a specific key in storage.
|
|
97
|
-
*/
|
|
98
|
-
watch<T>(key: StorageItemKey, cb: WatchCallback<T | null>): Unwatch;
|
|
99
|
-
/**
|
|
100
|
-
* Remove all watch listeners.
|
|
101
|
-
*/
|
|
102
|
-
unwatch(): void;
|
|
103
|
-
/**
|
|
104
|
-
* Define a storage item with a default value, type, or versioning.
|
|
105
|
-
*
|
|
106
|
-
* Read full docs: https://wxt.dev/guide/extension-apis/storage.html#defining-storage-items
|
|
107
|
-
*/
|
|
108
|
-
defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: StorageItemKey): WxtStorageItem<TValue | null, TMetadata>;
|
|
109
|
-
defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: StorageItemKey, options: WxtStorageItemOptions<TValue>): WxtStorageItem<TValue, TMetadata>;
|
|
110
|
-
}
|
|
111
|
-
interface WxtStorageItem<TValue, TMetadata extends Record<string, unknown>> {
|
|
112
|
-
defaultValue: TValue;
|
|
113
|
-
/**
|
|
114
|
-
* Get the latest value from storage.
|
|
115
|
-
*/
|
|
116
|
-
getValue(): Promise<TValue>;
|
|
117
|
-
/**
|
|
118
|
-
* Get metadata.
|
|
119
|
-
*/
|
|
120
|
-
getMeta(): Promise<NullablePartial<TMetadata>>;
|
|
121
|
-
/**
|
|
122
|
-
* Set the value in storage.
|
|
123
|
-
*/
|
|
124
|
-
setValue(value: TValue): Promise<void>;
|
|
125
|
-
/**
|
|
126
|
-
* Set metadata properties.
|
|
127
|
-
*/
|
|
128
|
-
setMeta(properties: NullablePartial<TMetadata>): Promise<void>;
|
|
129
|
-
/**
|
|
130
|
-
* Remove the value from storage.
|
|
131
|
-
*/
|
|
132
|
-
removeValue(opts?: RemoveItemOptions): Promise<void>;
|
|
133
|
-
/**
|
|
134
|
-
* Remove all metadata or certain properties from metadata.
|
|
135
|
-
*/
|
|
136
|
-
removeMeta(properties?: string[]): Promise<void>;
|
|
137
|
-
/**
|
|
138
|
-
* Listen for changes to the value in storage.
|
|
139
|
-
*/
|
|
140
|
-
watch(cb: WatchCallback<TValue>): Unwatch;
|
|
141
|
-
/**
|
|
142
|
-
* If there are migrations defined on the storage item, migrate to the latest version.
|
|
143
|
-
*
|
|
144
|
-
* **This function is ran automatically whenever the extension updates**, so you don't have to call it
|
|
145
|
-
* manually.
|
|
146
|
-
*/
|
|
147
|
-
migrate(): Promise<void>;
|
|
148
|
-
}
|
|
149
|
-
type StorageArea = 'local' | 'session' | 'sync' | 'managed';
|
|
150
|
-
type StorageItemKey = `${StorageArea}:${string}`;
|
|
151
|
-
interface GetItemOptions<T> {
|
|
152
|
-
/**
|
|
153
|
-
* Value returned from `getValue` when it would otherwise return null.
|
|
154
|
-
*/
|
|
155
|
-
defaultValue?: T;
|
|
156
|
-
}
|
|
157
|
-
interface RemoveItemOptions {
|
|
158
|
-
/**
|
|
159
|
-
* Optionally remove metadata when deleting a key.
|
|
160
|
-
*
|
|
161
|
-
* @default false
|
|
162
|
-
*/
|
|
163
|
-
removeMeta?: boolean;
|
|
164
|
-
}
|
|
165
|
-
interface SnapshotOptions {
|
|
166
|
-
/**
|
|
167
|
-
* Exclude a list of keys. The storage area prefix should be removed since the snapshot is for a
|
|
168
|
-
* specific storage area already.
|
|
169
|
-
*/
|
|
170
|
-
excludeKeys?: string[];
|
|
171
|
-
}
|
|
172
|
-
interface WxtStorageItemOptions<T> {
|
|
173
|
-
defaultValue: T;
|
|
174
|
-
/**
|
|
175
|
-
* Provide a version number for the storage item to enable migrations. When changing the version
|
|
176
|
-
* in the future, migration functions will be ran on application startup.
|
|
177
|
-
*/
|
|
178
|
-
version?: number;
|
|
179
|
-
/**
|
|
180
|
-
* A map of version numbers to the functions used to migrate the data to that version.
|
|
181
|
-
*/
|
|
182
|
-
migrations?: Record<number, (oldValue: any) => any>;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Same as `Partial`, but includes `| null`. It makes all the properties of an object optional and
|
|
186
|
-
* nullable.
|
|
187
|
-
*/
|
|
188
|
-
type NullablePartial<T> = {
|
|
189
|
-
[key in keyof T]+?: T[key] | undefined | null;
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* Callback called when a value in storage is changed.
|
|
193
|
-
*/
|
|
194
|
-
type WatchCallback<T> = (newValue: T, oldValue: T) => void;
|
|
195
|
-
/**
|
|
196
|
-
* Call to remove a watch listener
|
|
197
|
-
*/
|
|
198
|
-
type Unwatch = () => void;
|
|
199
|
-
|
|
200
|
-
export { type GetItemOptions, type NullablePartial, type RemoveItemOptions, type SnapshotOptions, type StorageArea, type StorageItemKey, type Unwatch, type WatchCallback, type WxtStorage, type WxtStorageItem, type WxtStorageItemOptions, storage };
|