@webex/storage-adapter-local-forage 3.0.0-beta.9 → 3.0.0-bnr.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/dist/index.js +14 -36
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +35 -0
- package/package.json +6 -6
- package/src/index.js +26 -28
package/dist/index.js
CHANGED
|
@@ -1,44 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = void 0;
|
|
12
|
-
|
|
13
9
|
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/applyDecoratedDescriptor"));
|
|
14
|
-
|
|
15
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
|
|
16
|
-
|
|
17
11
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
|
|
18
|
-
|
|
19
12
|
var _weakMap = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/weak-map"));
|
|
20
|
-
|
|
21
13
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
22
|
-
|
|
23
14
|
var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor"));
|
|
24
|
-
|
|
25
15
|
var _localforage = _interopRequireDefault(require("localforage"));
|
|
26
|
-
|
|
27
16
|
var _common = require("@webex/common");
|
|
28
|
-
|
|
29
17
|
var _webexCore = require("@webex/webex-core");
|
|
30
|
-
|
|
31
18
|
/*!
|
|
32
19
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
33
20
|
*/
|
|
34
21
|
|
|
35
22
|
/* eslint-env browser */
|
|
23
|
+
|
|
36
24
|
var namespaces = new _weakMap.default();
|
|
37
25
|
var loggers = new _weakMap.default();
|
|
38
|
-
/**
|
|
39
|
-
* IndexedDB adapter for webex-core storage layer
|
|
40
|
-
*/
|
|
41
26
|
|
|
27
|
+
/**
|
|
28
|
+
* IndexedDB adapter for webex-core storage layer
|
|
29
|
+
*/
|
|
42
30
|
var StorageAdapterLocalForage = /*#__PURE__*/function () {
|
|
43
31
|
/**
|
|
44
32
|
* @constructs {StorageAdapterLocalForage}
|
|
@@ -47,9 +35,7 @@ var StorageAdapterLocalForage = /*#__PURE__*/function () {
|
|
|
47
35
|
*/
|
|
48
36
|
function StorageAdapterLocalForage() {
|
|
49
37
|
var _dec, _dec2, _class;
|
|
50
|
-
|
|
51
38
|
(0, _classCallCheck2.default)(this, StorageAdapterLocalForage);
|
|
52
|
-
|
|
53
39
|
/**
|
|
54
40
|
* localforage binding
|
|
55
41
|
*/
|
|
@@ -72,13 +58,12 @@ var StorageAdapterLocalForage = /*#__PURE__*/function () {
|
|
|
72
58
|
namespaces.set(this, namespace);
|
|
73
59
|
loggers.set(this, options.logger);
|
|
74
60
|
}
|
|
61
|
+
|
|
75
62
|
/**
|
|
76
63
|
* Clears the localforage
|
|
77
64
|
* @param {string} key
|
|
78
65
|
* @returns {Promise}
|
|
79
66
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
67
|
(0, _createClass2.default)(_class, [{
|
|
83
68
|
key: "clear",
|
|
84
69
|
value: function clear() {
|
|
@@ -106,15 +91,15 @@ var StorageAdapterLocalForage = /*#__PURE__*/function () {
|
|
|
106
91
|
if (keys.includes(key_)) {
|
|
107
92
|
return _promise.default.resolve(value);
|
|
108
93
|
}
|
|
109
|
-
|
|
110
94
|
return _promise.default.reject(new _webexCore.NotFoundError("No value found for ".concat(key_)));
|
|
111
95
|
});
|
|
112
|
-
}
|
|
113
|
-
|
|
96
|
+
}
|
|
114
97
|
|
|
98
|
+
// even if undefined is saved, null will be returned by getItem()
|
|
115
99
|
return _promise.default.resolve(value);
|
|
116
100
|
});
|
|
117
101
|
}
|
|
102
|
+
|
|
118
103
|
/**
|
|
119
104
|
* Stores the specified value at the specified key.
|
|
120
105
|
* If key is undefined, removes the specified key.
|
|
@@ -122,14 +107,12 @@ var StorageAdapterLocalForage = /*#__PURE__*/function () {
|
|
|
122
107
|
* @param {mixed} value
|
|
123
108
|
* @returns {Promise}
|
|
124
109
|
*/
|
|
125
|
-
|
|
126
110
|
}, {
|
|
127
111
|
key: "put",
|
|
128
112
|
value: function put(key, value) {
|
|
129
113
|
if (typeof value === 'undefined') {
|
|
130
114
|
return this.del(key);
|
|
131
115
|
}
|
|
132
|
-
|
|
133
116
|
var key_ = "".concat(namespaces.get(this), "/").concat(key);
|
|
134
117
|
loggers.get(this).debug("storage-adapter-local-forage: writing `".concat(key_, "`"));
|
|
135
118
|
return _localforage.default.setItem(key_, value);
|
|
@@ -138,33 +121,28 @@ var StorageAdapterLocalForage = /*#__PURE__*/function () {
|
|
|
138
121
|
return _class;
|
|
139
122
|
}(), ((0, _applyDecoratedDescriptor2.default)(_class.prototype, "del", [_dec], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "del"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "get", [_dec2], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "get"), _class.prototype)), _class));
|
|
140
123
|
}
|
|
141
|
-
/**
|
|
142
|
-
* Returns an adapter bound to the specified namespace
|
|
143
|
-
* @param {string} namespace
|
|
144
|
-
* @param {Object} options
|
|
145
|
-
* @returns {Promise<Bound>}
|
|
146
|
-
*/
|
|
147
|
-
|
|
148
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Returns an adapter bound to the specified namespace
|
|
127
|
+
* @param {string} namespace
|
|
128
|
+
* @param {Object} options
|
|
129
|
+
* @returns {Promise<Bound>}
|
|
130
|
+
*/
|
|
149
131
|
(0, _createClass2.default)(StorageAdapterLocalForage, [{
|
|
150
132
|
key: "bind",
|
|
151
133
|
value: function bind(namespace, options) {
|
|
152
134
|
options = options || {};
|
|
153
|
-
|
|
154
135
|
if (!namespace) {
|
|
155
136
|
return _promise.default.reject(new Error('`namespace` is required'));
|
|
156
137
|
}
|
|
157
|
-
|
|
158
138
|
if (!options.logger) {
|
|
159
139
|
return _promise.default.reject(new Error('`options.logger` is required'));
|
|
160
140
|
}
|
|
161
|
-
|
|
162
141
|
options.logger.info('storage-adapter-local-forage: returning binding');
|
|
163
142
|
return _promise.default.resolve(new this.Bound(namespace, options));
|
|
164
143
|
}
|
|
165
144
|
}]);
|
|
166
145
|
return StorageAdapterLocalForage;
|
|
167
146
|
}();
|
|
168
|
-
|
|
169
147
|
exports.default = StorageAdapterLocalForage;
|
|
170
148
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["namespaces","loggers","StorageAdapterLocalForage","Bound","oneFlight","keyFactory","key","namespace","options","set","logger","get","debug","resolve","localforage","clear","key_","removeItem","getItem","then","value","keys","includes","reject","NotFoundError","del","setItem","Error","info"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint-env browser */\n\nimport localforage from 'localforage';\nimport {oneFlight} from '@webex/common';\nimport {NotFoundError} from '@webex/webex-core';\n\nconst namespaces = new WeakMap();\nconst loggers = new WeakMap();\n\n/**\n* IndexedDB adapter for webex-core storage layer\n*/\nexport default class StorageAdapterLocalForage {\n /**\n * @constructs {StorageAdapterLocalForage}\n * @param {string} basekey localforage key under which\n * all namespaces will be stored\n */\n constructor() {\n /**\n * localforage binding\n */\n this.Bound = class {\n /**\n * @constructs {Bound}\n * @param {string} namespace\n * @param {Object} options\n */\n constructor(namespace, options) {\n namespaces.set(this, namespace);\n loggers.set(this, options.logger);\n }\n\n /**\n * Clears the localforage\n * @param {string} key\n * @returns {Promise}\n */\n clear() {\n loggers.get(this).debug('storage-adapter-local-forage: clearing localforage');\n\n return Promise.resolve(localforage.clear());\n }\n\n @oneFlight({\n keyFactory: (key) => key
|
|
1
|
+
{"version":3,"names":["namespaces","loggers","StorageAdapterLocalForage","Bound","oneFlight","keyFactory","key","namespace","options","set","logger","get","debug","resolve","localforage","clear","key_","removeItem","getItem","then","value","keys","includes","reject","NotFoundError","del","setItem","Error","info"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint-env browser */\n\nimport localforage from 'localforage';\nimport {oneFlight} from '@webex/common';\nimport {NotFoundError} from '@webex/webex-core';\n\nconst namespaces = new WeakMap();\nconst loggers = new WeakMap();\n\n/**\n * IndexedDB adapter for webex-core storage layer\n */\nexport default class StorageAdapterLocalForage {\n /**\n * @constructs {StorageAdapterLocalForage}\n * @param {string} basekey localforage key under which\n * all namespaces will be stored\n */\n constructor() {\n /**\n * localforage binding\n */\n this.Bound = class {\n /**\n * @constructs {Bound}\n * @param {string} namespace\n * @param {Object} options\n */\n constructor(namespace, options) {\n namespaces.set(this, namespace);\n loggers.set(this, options.logger);\n }\n\n /**\n * Clears the localforage\n * @param {string} key\n * @returns {Promise}\n */\n clear() {\n loggers.get(this).debug('storage-adapter-local-forage: clearing localforage');\n\n return Promise.resolve(localforage.clear());\n }\n\n @oneFlight({\n keyFactory: (key) => key,\n })\n /**\n * Removes the specified key\n * @param {string} key\n * @returns {Promise}\n */\n // suppress doc warning because decorators confuse eslint\n // eslint-disable-next-line require-jsdoc\n del(key) {\n const key_ = `${namespaces.get(this)}/${key}`;\n\n loggers.get(this).debug(`storage-adapter-local-forage: deleting \\`${key_}\\``);\n\n return localforage.removeItem(key_);\n }\n\n @oneFlight({\n keyFactory: (key) => key,\n })\n /**\n * Retrieves the data at the specified key\n * @param {string} key\n * @see https://localforage.github.io/localForage/#data-api-getitem\n * @returns {Promise<mixed>}\n */\n // suppress doc warning because decorators confuse eslint\n // eslint-disable-next-line require-jsdoc\n get(key) {\n const key_ = `${namespaces.get(this)}/${key}`;\n\n loggers.get(this).debug(`storage-adapter-local-forage: reading \\`${key_}\\``);\n\n return localforage.getItem(key_).then((value) => {\n // if the key does not exist, getItem() will return null\n if (value === null) {\n // If we got null, we need to check if it's because the key\n // doesn't exist or because it has a saved value of null.\n return localforage.keys().then((keys) => {\n if (keys.includes(key_)) {\n return Promise.resolve(value);\n }\n\n return Promise.reject(new NotFoundError(`No value found for ${key_}`));\n });\n }\n\n // even if undefined is saved, null will be returned by getItem()\n return Promise.resolve(value);\n });\n }\n\n /**\n * Stores the specified value at the specified key.\n * If key is undefined, removes the specified key.\n * @param {string} key\n * @param {mixed} value\n * @returns {Promise}\n */\n put(key, value) {\n if (typeof value === 'undefined') {\n return this.del(key);\n }\n const key_ = `${namespaces.get(this)}/${key}`;\n\n loggers.get(this).debug(`storage-adapter-local-forage: writing \\`${key_}\\``);\n\n return localforage.setItem(key_, value);\n }\n };\n }\n\n /**\n * Returns an adapter bound to the specified namespace\n * @param {string} namespace\n * @param {Object} options\n * @returns {Promise<Bound>}\n */\n bind(namespace, options) {\n options = options || {};\n if (!namespace) {\n return Promise.reject(new Error('`namespace` is required'));\n }\n\n if (!options.logger) {\n return Promise.reject(new Error('`options.logger` is required'));\n }\n\n options.logger.info('storage-adapter-local-forage: returning binding');\n\n return Promise.resolve(new this.Bound(namespace, options));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAMA;AACA;AACA;AARA;AACA;AACA;;AAEA;;AAMA,IAAMA,UAAU,GAAG,sBAAa;AAChC,IAAMC,OAAO,GAAG,sBAAa;;AAE7B;AACA;AACA;AAFA,IAGqBC,yBAAyB;EAC5C;AACF;AACA;AACA;AACA;EACE,qCAAc;IAAA;IAAA;IACZ;AACJ;AACA;IACI,IAAI,CAACC,KAAK,WAsBP,IAAAC,iBAAS,EAA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AAI,CAACV,KAAK,CAACI,SAAS,EAAEC,OAAO,CAAC,CAAC;IAC5D;EAAC;EAAA;AAAA;AAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IndexedDB adapter for webex-core storage layer
|
|
3
|
+
*/
|
|
4
|
+
export default class StorageAdapterLocalForage {
|
|
5
|
+
/**
|
|
6
|
+
* localforage binding
|
|
7
|
+
*/
|
|
8
|
+
Bound: {
|
|
9
|
+
new (namespace: string, options: any): {
|
|
10
|
+
/**
|
|
11
|
+
* Clears the localforage
|
|
12
|
+
* @param {string} key
|
|
13
|
+
* @returns {Promise}
|
|
14
|
+
*/
|
|
15
|
+
clear(): Promise<any>;
|
|
16
|
+
del(key: any): Promise<void>;
|
|
17
|
+
get(key: any): Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* Stores the specified value at the specified key.
|
|
20
|
+
* If key is undefined, removes the specified key.
|
|
21
|
+
* @param {string} key
|
|
22
|
+
* @param {mixed} value
|
|
23
|
+
* @returns {Promise}
|
|
24
|
+
*/
|
|
25
|
+
put(key: string, value: mixed): Promise<any>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Returns an adapter bound to the specified namespace
|
|
30
|
+
* @param {string} namespace
|
|
31
|
+
* @param {Object} options
|
|
32
|
+
* @returns {Promise<Bound>}
|
|
33
|
+
*/
|
|
34
|
+
bind(namespace: string, options: any): Promise<Bound>;
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/storage-adapter-local-forage",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-bnr.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Matt Norris <matthew.g.norris@gmail.com>",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
]
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@webex/test-helper-mocha": "3.0.0-
|
|
24
|
+
"@webex/test-helper-mocha": "3.0.0-bnr.0"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@webex/common": "3.0.0-
|
|
28
|
-
"@webex/storage-adapter-local-forage": "3.0.0-
|
|
29
|
-
"@webex/storage-adapter-spec": "3.0.0-
|
|
30
|
-
"@webex/webex-core": "3.0.0-
|
|
27
|
+
"@webex/common": "3.0.0-bnr.0",
|
|
28
|
+
"@webex/storage-adapter-local-forage": "3.0.0-bnr.0",
|
|
29
|
+
"@webex/storage-adapter-spec": "3.0.0-bnr.0",
|
|
30
|
+
"@webex/webex-core": "3.0.0-bnr.0",
|
|
31
31
|
"localforage": "^1.7.3"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/index.js
CHANGED
|
@@ -12,8 +12,8 @@ const namespaces = new WeakMap();
|
|
|
12
12
|
const loggers = new WeakMap();
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* IndexedDB adapter for webex-core storage layer
|
|
16
|
-
*/
|
|
15
|
+
* IndexedDB adapter for webex-core storage layer
|
|
16
|
+
*/
|
|
17
17
|
export default class StorageAdapterLocalForage {
|
|
18
18
|
/**
|
|
19
19
|
* @constructs {StorageAdapterLocalForage}
|
|
@@ -47,7 +47,7 @@ export default class StorageAdapterLocalForage {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
@oneFlight({
|
|
50
|
-
keyFactory: (key) => key
|
|
50
|
+
keyFactory: (key) => key,
|
|
51
51
|
})
|
|
52
52
|
/**
|
|
53
53
|
* Removes the specified key
|
|
@@ -65,7 +65,7 @@ export default class StorageAdapterLocalForage {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
@oneFlight({
|
|
68
|
-
keyFactory: (key) => key
|
|
68
|
+
keyFactory: (key) => key,
|
|
69
69
|
})
|
|
70
70
|
/**
|
|
71
71
|
* Retrieves the data at the specified key
|
|
@@ -80,25 +80,23 @@ export default class StorageAdapterLocalForage {
|
|
|
80
80
|
|
|
81
81
|
loggers.get(this).debug(`storage-adapter-local-forage: reading \`${key_}\``);
|
|
82
82
|
|
|
83
|
-
return localforage.getItem(key_)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return Promise.resolve(value);
|
|
101
|
-
});
|
|
83
|
+
return localforage.getItem(key_).then((value) => {
|
|
84
|
+
// if the key does not exist, getItem() will return null
|
|
85
|
+
if (value === null) {
|
|
86
|
+
// If we got null, we need to check if it's because the key
|
|
87
|
+
// doesn't exist or because it has a saved value of null.
|
|
88
|
+
return localforage.keys().then((keys) => {
|
|
89
|
+
if (keys.includes(key_)) {
|
|
90
|
+
return Promise.resolve(value);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return Promise.reject(new NotFoundError(`No value found for ${key_}`));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// even if undefined is saved, null will be returned by getItem()
|
|
98
|
+
return Promise.resolve(value);
|
|
99
|
+
});
|
|
102
100
|
}
|
|
103
101
|
|
|
104
102
|
/**
|
|
@@ -122,11 +120,11 @@ export default class StorageAdapterLocalForage {
|
|
|
122
120
|
}
|
|
123
121
|
|
|
124
122
|
/**
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
* Returns an adapter bound to the specified namespace
|
|
124
|
+
* @param {string} namespace
|
|
125
|
+
* @param {Object} options
|
|
126
|
+
* @returns {Promise<Bound>}
|
|
127
|
+
*/
|
|
130
128
|
bind(namespace, options) {
|
|
131
129
|
options = options || {};
|
|
132
130
|
if (!namespace) {
|