This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
storage.mjs
65 lines (56 loc) · 1.93 KB
/
storage.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* notion-enhancer: api
* (c) 2021 dragonwocky <[email protected]> (https://dragonwocky.me/)
* (https://notion-enhancer.github.io/) under the MIT license
*/
'use strict';
/**
* environment-specific data persistence
* @namespace storage
*/
import * as storage from '../env/storage.mjs';
/**
* get persisted data
* @type {function}
* @param {string[]} path - the path of keys to the value being fetched
* @param {unknown=} fallback - a default value if the path is not matched
* @returns {Promise} value ?? fallback
*/
export const get = storage.get;
/**
* persist data
* @type {function}
* @param {string[]} path - the path of keys to the value being set
* @param {unknown} value - the data to save
* @returns {Promise} resolves when data has been saved
*/
export const set = storage.set;
/**
* create a wrapper for accessing a partition of the storage
* @type {function}
* @param {string[]} namespace - the path of keys to prefix all storage requests with
* @param {function=} get - the storage get function to be wrapped
* @param {function=} set - the storage set function to be wrapped
* @returns {object} an object with the wrapped get/set functions
*/
export const db = storage.db;
/**
* add an event listener for changes in storage
* @type {function}
* @param {onStorageChangeCallback} callback - called whenever a change in
* storage is initiated from the current process
*/
export const addChangeListener = storage.addChangeListener;
/**
* remove a listener added with storage.addChangeListener
* @type {function}
* @param {onStorageChangeCallback} callback
*/
export const removeChangeListener = storage.removeChangeListener;
/**
* @callback onStorageChangeCallback
* @param {object} event
* @param {string} event.path- the path of keys to the changed value
* @param {string=} event.new - the new value being persisted to the store
* @param {string=} event.old - the previous value associated with the key
*/