@wxt-dev/storage 1.2.6 → 1.2.7

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/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.6",
4
+ "version": "1.2.7",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -27,19 +27,17 @@
27
27
  "dependencies": {
28
28
  "async-mutex": "^0.5.0",
29
29
  "dequal": "^2.0.3",
30
- "@wxt-dev/browser": "^0.1.4"
30
+ "@wxt-dev/browser": "^0.1.36"
31
31
  },
32
32
  "devDependencies": {
33
- "@aklinker1/check": "^2.1.0",
34
- "@webext-core/fake-browser": "^1.3.2",
35
- "oxlint": "^1.14.0",
36
- "publint": "^0.3.12",
37
- "typescript": "^5.9.2",
38
- "unbuild": "^3.6.1",
39
- "vitest": "^3.2.4"
33
+ "@webext-core/fake-browser": "^1.3.4",
34
+ "oxlint": "^1.43.0",
35
+ "publint": "^0.3.17",
36
+ "typescript": "^5.9.3",
37
+ "vitest": "^4.0.18"
40
38
  },
41
39
  "module": "./dist/index.mjs",
42
- "types": "./dist/index.d.ts",
40
+ "types": "./dist/index.d.mts",
43
41
  "exports": {
44
42
  ".": {
45
43
  "types": "./dist/index.d.mts",
@@ -50,7 +48,7 @@
50
48
  "dist"
51
49
  ],
52
50
  "scripts": {
53
- "build": "buildc -- unbuild",
51
+ "build": "buildc -- tsdown",
54
52
  "check": "buildc --deps-only -- check",
55
53
  "test": "buildc --deps-only -- vitest"
56
54
  }
package/dist/index.d.ts DELETED
@@ -1,290 +0,0 @@
1
- import { Browser } from '@wxt-dev/browser';
2
-
3
- declare const storage: WxtStorage;
4
- interface WxtStorage {
5
- /**
6
- * Get an item from storage, or return `null` if it doesn't exist.
7
- *
8
- * @example
9
- * await storage.getItem<number>("local:installDate");
10
- */
11
- getItem<TValue>(key: StorageItemKey, opts: GetItemOptions<TValue> & {
12
- fallback: TValue;
13
- }): Promise<TValue>;
14
- getItem<TValue>(key: StorageItemKey, opts?: GetItemOptions<TValue>): Promise<TValue | null>;
15
- /**
16
- * Get multiple items from storage. The return order is guaranteed to be the same as the order
17
- * requested.
18
- *
19
- * @example
20
- * await storage.getItems(["local:installDate", "session:someCounter"]);
21
- */
22
- getItems(keys: Array<StorageItemKey | WxtStorageItem<any, any> | {
23
- key: StorageItemKey;
24
- options?: GetItemOptions<any>;
25
- }>): Promise<Array<{
26
- key: StorageItemKey;
27
- value: any;
28
- }>>;
29
- /**
30
- * Return an object containing metadata about the key. Object is stored at `key + "$"`. If value
31
- * is not an object, it returns an empty object.
32
- *
33
- * @example
34
- * await storage.getMeta("local:installDate");
35
- */
36
- getMeta<T extends Record<string, unknown>>(key: StorageItemKey): Promise<T>;
37
- /**
38
- * Get the metadata of multiple storage items.
39
- *
40
- * @param items List of keys or items to get the metadata of.
41
- * @returns An array containing storage keys and their metadata.
42
- */
43
- getMetas(keys: Array<StorageItemKey | WxtStorageItem<any, any>>): Promise<Array<{
44
- key: StorageItemKey;
45
- meta: any;
46
- }>>;
47
- /**
48
- * Set a value in storage. Setting a value to `null` or `undefined` is equivalent to calling
49
- * `removeItem`.
50
- *
51
- * @example
52
- * await storage.setItem<number>("local:installDate", Date.now());
53
- */
54
- setItem<T>(key: StorageItemKey, value: T | null): Promise<void>;
55
- /**
56
- * Set multiple values in storage. If a value is set to `null` or `undefined`, the key is removed.
57
- *
58
- * @example
59
- * await storage.setItem([
60
- * { key: "local:installDate", value: Date.now() },
61
- * { key: "session:someCounter, value: 5 },
62
- * ]);
63
- */
64
- setItems(values: Array<{
65
- key: StorageItemKey;
66
- value: any;
67
- } | {
68
- item: WxtStorageItem<any, any>;
69
- value: any;
70
- }>): Promise<void>;
71
- /**
72
- * Sets metadata properties. If some properties are already set, but are not included in the
73
- * `properties` parameter, they will not be removed.
74
- *
75
- * @example
76
- * await storage.setMeta("local:installDate", { appVersion });
77
- */
78
- setMeta<T extends Record<string, unknown>>(key: StorageItemKey, properties: T | null): Promise<void>;
79
- /**
80
- * Set the metadata of multiple storage items.
81
- *
82
- * @param items List of storage keys or items and metadata to set for each.
83
- */
84
- setMetas(metas: Array<{
85
- key: StorageItemKey;
86
- meta: Record<string, any>;
87
- } | {
88
- item: WxtStorageItem<any, any>;
89
- meta: Record<string, any>;
90
- }>): Promise<void>;
91
- /**
92
- * Removes an item from storage.
93
- *
94
- * @example
95
- * await storage.removeItem("local:installDate");
96
- */
97
- removeItem(key: StorageItemKey, opts?: RemoveItemOptions): Promise<void>;
98
- /**
99
- * Remove a list of keys from storage.
100
- */
101
- removeItems(keys: Array<StorageItemKey | WxtStorageItem<any, any> | {
102
- key: StorageItemKey;
103
- options?: RemoveItemOptions;
104
- } | {
105
- item: WxtStorageItem<any, any>;
106
- options?: RemoveItemOptions;
107
- }>): Promise<void>;
108
- /**
109
- * Removes all items from the provided storage area.
110
- */
111
- clear(base: StorageArea): Promise<void>;
112
- /**
113
- * Remove the entire metadata for a key, or specific properties by name.
114
- *
115
- * @example
116
- * // Remove all metadata properties from the item
117
- * await storage.removeMeta("local:installDate");
118
- *
119
- * // Remove only specific the "v" field
120
- * await storage.removeMeta("local:installDate", "v")
121
- */
122
- removeMeta(key: StorageItemKey, properties?: string | string[]): Promise<void>;
123
- /**
124
- * Return all the items in storage.
125
- */
126
- snapshot(base: StorageArea, opts?: SnapshotOptions): Promise<Record<string, unknown>>;
127
- /**
128
- * Restores the results of `snapshot`. If new properties have been saved since the snapshot, they are
129
- * not overridden. Only values existing in the snapshot are overridden.
130
- */
131
- restoreSnapshot(base: StorageArea, data: any): Promise<void>;
132
- /**
133
- * Watch for changes to a specific key in storage.
134
- */
135
- watch<T>(key: StorageItemKey, cb: WatchCallback<T | null>): Unwatch;
136
- /**
137
- * Remove all watch listeners.
138
- */
139
- unwatch(): void;
140
- /**
141
- * Define a storage item with a default value, type, or versioning.
142
- *
143
- * Read full docs: https://wxt.dev/storage.html#defining-storage-items
144
- */
145
- defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: StorageItemKey): WxtStorageItem<TValue | null, TMetadata>;
146
- defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: StorageItemKey, options: WxtStorageItemOptions<TValue> & {
147
- fallback: TValue;
148
- }): WxtStorageItem<TValue, TMetadata>;
149
- defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: StorageItemKey, options: WxtStorageItemOptions<TValue> & {
150
- defaultValue: TValue;
151
- }): WxtStorageItem<TValue, TMetadata>;
152
- defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: StorageItemKey, options: WxtStorageItemOptions<TValue>): WxtStorageItem<TValue | null, TMetadata>;
153
- }
154
- interface WxtStorageItem<TValue, TMetadata extends Record<string, unknown>> {
155
- /**
156
- * The storage key passed when creating the storage item.
157
- */
158
- key: StorageItemKey;
159
- /**
160
- * @deprecated Renamed to fallback, use it instead.
161
- */
162
- defaultValue: TValue;
163
- /**
164
- * The value provided by the `fallback` option.
165
- */
166
- fallback: TValue;
167
- /**
168
- * Get the latest value from storage.
169
- */
170
- getValue(): Promise<TValue>;
171
- /**
172
- * Get metadata.
173
- */
174
- getMeta(): Promise<NullablePartial<TMetadata>>;
175
- /**
176
- * Set the value in storage.
177
- */
178
- setValue(value: TValue): Promise<void>;
179
- /**
180
- * Set metadata properties.
181
- */
182
- setMeta(properties: NullablePartial<TMetadata>): Promise<void>;
183
- /**
184
- * Remove the value from storage.
185
- */
186
- removeValue(opts?: RemoveItemOptions): Promise<void>;
187
- /**
188
- * Remove all metadata or certain properties from metadata.
189
- */
190
- removeMeta(properties?: string[]): Promise<void>;
191
- /**
192
- * Listen for changes to the value in storage.
193
- */
194
- watch(cb: WatchCallback<TValue>): Unwatch;
195
- /**
196
- * If there are migrations defined on the storage item, migrate to the latest version.
197
- *
198
- * **This function is ran automatically whenever the extension updates**, so you don't have to call it
199
- * manually.
200
- */
201
- migrate(): Promise<void>;
202
- }
203
- type StorageArea = 'local' | 'session' | 'sync' | 'managed';
204
- type StorageItemKey = `${StorageArea}:${string}`;
205
- interface GetItemOptions<T> {
206
- /**
207
- * @deprecated Renamed to `fallback`, use it instead.
208
- */
209
- defaultValue?: T;
210
- /**
211
- * Default value returned when `getItem` would otherwise return `null`.
212
- */
213
- fallback?: T;
214
- }
215
- interface RemoveItemOptions {
216
- /**
217
- * Optionally remove metadata when deleting a key.
218
- *
219
- * @default false
220
- */
221
- removeMeta?: boolean;
222
- }
223
- interface SnapshotOptions {
224
- /**
225
- * Exclude a list of keys. The storage area prefix should be removed since the snapshot is for a
226
- * specific storage area already.
227
- */
228
- excludeKeys?: string[];
229
- }
230
- interface WxtStorageItemOptions<T> {
231
- /**
232
- * @deprecated Renamed to `fallback`, use it instead.
233
- */
234
- defaultValue?: T;
235
- /**
236
- * Default value returned when `getValue` would otherwise return `null`.
237
- */
238
- fallback?: T;
239
- /**
240
- * If passed, a value in storage will be initialized immediately after
241
- * defining the storage item. This function returns the value that will be
242
- * saved to storage during the initialization process if a value doesn't
243
- * already exist.
244
- */
245
- init?: () => T | Promise<T>;
246
- /**
247
- * Provide a version number for the storage item to enable migrations. When changing the version
248
- * in the future, migration functions will be ran on application startup.
249
- */
250
- version?: number;
251
- /**
252
- * A map of version numbers to the functions used to migrate the data to that version.
253
- */
254
- migrations?: Record<number, (oldValue: any) => any>;
255
- /**
256
- * Print debug logs, such as migration process.
257
- * @default false
258
- */
259
- debug?: boolean;
260
- /**
261
- * A callback function that runs on migration complete.
262
- */
263
- onMigrationComplete?: (migratedValue: T, targetVersion: number) => void;
264
- }
265
- type StorageAreaChanges = {
266
- [key: string]: Browser.storage.StorageChange;
267
- };
268
- /**
269
- * Same as `Partial`, but includes `| null`. It makes all the properties of an object optional and
270
- * nullable.
271
- */
272
- type NullablePartial<T> = {
273
- [key in keyof T]+?: T[key] | undefined | null;
274
- };
275
- /**
276
- * Callback called when a value in storage is changed.
277
- */
278
- type WatchCallback<T> = (newValue: T, oldValue: T) => void;
279
- /**
280
- * Call to remove a watch listener
281
- */
282
- type Unwatch = () => void;
283
- declare class MigrationError extends Error {
284
- key: string;
285
- version: number;
286
- constructor(key: string, version: number, options?: ErrorOptions);
287
- }
288
-
289
- export { MigrationError, storage };
290
- export type { GetItemOptions, RemoveItemOptions, SnapshotOptions, StorageArea, StorageAreaChanges, StorageItemKey, Unwatch, WatchCallback, WxtStorage, WxtStorageItem, WxtStorageItemOptions };