indexeddbshim 10.0.0 → 11.0.0-beta.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/README.md +1 -1
- package/dist/indexeddbshim-Key.js +214 -365
- package/dist/indexeddbshim-Key.js.map +1 -1
- package/dist/indexeddbshim-Key.min.js +2 -2
- package/dist/indexeddbshim-Key.min.js.map +1 -1
- package/dist/{indexeddbshim-UnicodeIdentifiers-node.js → indexeddbshim-UnicodeIdentifiers-node.cjs} +1370 -2646
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -0
- package/dist/indexeddbshim-UnicodeIdentifiers.js +1968 -2980
- package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js +2 -8
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
- package/dist/{indexeddbshim-node.js → indexeddbshim-node.cjs} +1365 -2640
- package/dist/indexeddbshim-node.cjs.map +1 -0
- package/dist/indexeddbshim-noninvasive.js +1963 -2974
- package/dist/indexeddbshim-noninvasive.js.map +1 -1
- package/dist/indexeddbshim-noninvasive.min.js +2 -8
- package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
- package/dist/indexeddbshim.js +1963 -2976
- package/dist/indexeddbshim.js.map +1 -1
- package/dist/indexeddbshim.min.js +2 -8
- package/dist/indexeddbshim.min.js.map +1 -1
- package/package.json +127 -113
- package/src/IDBTransaction.js +1 -0
- package/src/node-UnicodeIdentifiers.js +2 -3
- package/src/node.js +2 -3
- package/dist/indexeddbshim-UnicodeIdentifiers-node.js.map +0 -1
- package/dist/indexeddbshim-node.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! indexeddbshim -
|
|
1
|
+
/*! indexeddbshim - v10.1.0 - 1/7/2023 */
|
|
2
2
|
|
|
3
3
|
(function (global, factory) {
|
|
4
4
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
@@ -6,6 +6,33 @@
|
|
|
6
6
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.IDBKeyUtils = {}));
|
|
7
7
|
})(this, (function (exports) { 'use strict';
|
|
8
8
|
|
|
9
|
+
function _iterableToArrayLimit(arr, i) {
|
|
10
|
+
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
|
|
11
|
+
if (null != _i) {
|
|
12
|
+
var _s,
|
|
13
|
+
_e,
|
|
14
|
+
_x,
|
|
15
|
+
_r,
|
|
16
|
+
_arr = [],
|
|
17
|
+
_n = !0,
|
|
18
|
+
_d = !1;
|
|
19
|
+
try {
|
|
20
|
+
if (_x = (_i = _i.call(arr)).next, 0 === i) {
|
|
21
|
+
if (Object(_i) !== _i) return;
|
|
22
|
+
_n = !1;
|
|
23
|
+
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
|
|
24
|
+
} catch (err) {
|
|
25
|
+
_d = !0, _e = err;
|
|
26
|
+
} finally {
|
|
27
|
+
try {
|
|
28
|
+
if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
|
|
29
|
+
} finally {
|
|
30
|
+
if (_d) throw _e;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return _arr;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
9
36
|
function _typeof(obj) {
|
|
10
37
|
"@babel/helpers - typeof";
|
|
11
38
|
|
|
@@ -15,57 +42,21 @@
|
|
|
15
42
|
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
16
43
|
}, _typeof(obj);
|
|
17
44
|
}
|
|
18
|
-
|
|
19
45
|
function _slicedToArray(arr, i) {
|
|
20
46
|
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
21
47
|
}
|
|
22
|
-
|
|
23
48
|
function _toConsumableArray(arr) {
|
|
24
49
|
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
25
50
|
}
|
|
26
|
-
|
|
27
51
|
function _arrayWithoutHoles(arr) {
|
|
28
52
|
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
29
53
|
}
|
|
30
|
-
|
|
31
54
|
function _arrayWithHoles(arr) {
|
|
32
55
|
if (Array.isArray(arr)) return arr;
|
|
33
56
|
}
|
|
34
|
-
|
|
35
57
|
function _iterableToArray(iter) {
|
|
36
58
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
37
59
|
}
|
|
38
|
-
|
|
39
|
-
function _iterableToArrayLimit(arr, i) {
|
|
40
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
41
|
-
|
|
42
|
-
if (_i == null) return;
|
|
43
|
-
var _arr = [];
|
|
44
|
-
var _n = true;
|
|
45
|
-
var _d = false;
|
|
46
|
-
|
|
47
|
-
var _s, _e;
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
51
|
-
_arr.push(_s.value);
|
|
52
|
-
|
|
53
|
-
if (i && _arr.length === i) break;
|
|
54
|
-
}
|
|
55
|
-
} catch (err) {
|
|
56
|
-
_d = true;
|
|
57
|
-
_e = err;
|
|
58
|
-
} finally {
|
|
59
|
-
try {
|
|
60
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
61
|
-
} finally {
|
|
62
|
-
if (_d) throw _e;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return _arr;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
60
|
function _unsupportedIterableToArray(o, minLen) {
|
|
70
61
|
if (!o) return;
|
|
71
62
|
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
@@ -74,33 +65,24 @@
|
|
|
74
65
|
if (n === "Map" || n === "Set") return Array.from(o);
|
|
75
66
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
76
67
|
}
|
|
77
|
-
|
|
78
68
|
function _arrayLikeToArray(arr, len) {
|
|
79
69
|
if (len == null || len > arr.length) len = arr.length;
|
|
80
|
-
|
|
81
70
|
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
82
|
-
|
|
83
71
|
return arr2;
|
|
84
72
|
}
|
|
85
|
-
|
|
86
73
|
function _nonIterableSpread() {
|
|
87
74
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
88
75
|
}
|
|
89
|
-
|
|
90
76
|
function _nonIterableRest() {
|
|
91
77
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
92
78
|
}
|
|
93
|
-
|
|
94
79
|
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
95
80
|
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
96
|
-
|
|
97
81
|
if (!it) {
|
|
98
82
|
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
99
83
|
if (it) o = it;
|
|
100
84
|
var i = 0;
|
|
101
|
-
|
|
102
85
|
var F = function () {};
|
|
103
|
-
|
|
104
86
|
return {
|
|
105
87
|
s: F,
|
|
106
88
|
n: function () {
|
|
@@ -118,13 +100,11 @@
|
|
|
118
100
|
f: F
|
|
119
101
|
};
|
|
120
102
|
}
|
|
121
|
-
|
|
122
103
|
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
123
104
|
}
|
|
124
|
-
|
|
125
105
|
var normalCompletion = true,
|
|
126
|
-
|
|
127
|
-
|
|
106
|
+
didErr = false,
|
|
107
|
+
err;
|
|
128
108
|
return {
|
|
129
109
|
s: function () {
|
|
130
110
|
it = it.call(o);
|
|
@@ -150,40 +130,54 @@
|
|
|
150
130
|
|
|
151
131
|
var map = {};
|
|
152
132
|
var CFG = {};
|
|
153
|
-
[
|
|
154
|
-
|
|
133
|
+
[
|
|
134
|
+
// Boolean for verbose reporting
|
|
135
|
+
'DEBUG',
|
|
136
|
+
// Effectively defaults to false (ignored unless `true`)
|
|
137
|
+
|
|
155
138
|
// Boolean (effectively defaults to true) on whether to cache WebSQL
|
|
156
139
|
// `openDatabase` instances
|
|
157
|
-
'cacheDatabaseInstances',
|
|
140
|
+
'cacheDatabaseInstances',
|
|
141
|
+
// Boolean on whether to auto-name databases (based on an
|
|
158
142
|
// auto-increment) when the empty string is supplied; useful with
|
|
159
143
|
// `memoryDatabase`; defaults to `false` which means the empty string
|
|
160
144
|
// will be used as the (valid) database name
|
|
161
|
-
'autoName',
|
|
145
|
+
'autoName',
|
|
146
|
+
// Determines whether the slow-performing `Object.setPrototypeOf`
|
|
162
147
|
// calls required for full WebIDL compliance will be used. Probably
|
|
163
148
|
// only needed for testing or environments where full introspection
|
|
164
149
|
// on class relationships is required; see
|
|
165
150
|
// http://stackoverflow.com/questions/41927589/rationales-consequences-of-webidl-class-inheritance-requirements
|
|
166
|
-
'fullIDLSupport',
|
|
151
|
+
'fullIDLSupport',
|
|
152
|
+
// Effectively defaults to false (ignored unless `true`)
|
|
153
|
+
|
|
167
154
|
// Boolean on whether to perform origin checks in `IDBFactory` methods
|
|
168
155
|
// Effectively defaults to `true` (must be set to `false` to cancel checks)
|
|
169
|
-
'checkOrigin',
|
|
156
|
+
'checkOrigin',
|
|
157
|
+
// Used by `IDBCursor` continue methods for number of records to cache;
|
|
170
158
|
// Defaults to 100
|
|
171
|
-
'cursorPreloadPackSize',
|
|
159
|
+
'cursorPreloadPackSize',
|
|
160
|
+
// See optional API (`shimIndexedDB.__setUnicodeIdentifiers`);
|
|
172
161
|
// or just use the Unicode builds which invoke this method
|
|
173
162
|
// automatically using the large, fully spec-compliant, regular
|
|
174
163
|
// expression strings of `src/UnicodeIdentifiers.js`)
|
|
175
164
|
// In the non-Unicode builds, defaults to /[$A-Z_a-z]/
|
|
176
|
-
'UnicodeIDStart',
|
|
177
|
-
|
|
165
|
+
'UnicodeIDStart',
|
|
166
|
+
// In the non-Unicode builds, defaults to /[$0-9A-Z_a-z]/
|
|
167
|
+
'UnicodeIDContinue',
|
|
168
|
+
// Used by SCA.js for optional restructuring of typeson-registry
|
|
178
169
|
// Structured Cloning Algorithm; should only be needed for ensuring data
|
|
179
170
|
// created in 3.* versions of IndexedDBShim continue to work; see the
|
|
180
171
|
// library `typeson-registry-sca-reverter` to get a function to do this
|
|
181
|
-
'registerSCA',
|
|
182
|
-
|
|
172
|
+
'registerSCA',
|
|
173
|
+
// BROWSER-SPECIFIC CONFIG
|
|
174
|
+
'avoidAutoShim',
|
|
175
|
+
// Where WebSQL is detected but where `indexedDB` is
|
|
183
176
|
// missing or poor support is known (non-Chrome Android or
|
|
184
177
|
// non-Safari iOS9), the shim will be auto-applied without
|
|
185
178
|
// `shimIndexedDB.__useShim()`. Set this to `true` to avoid forcing
|
|
186
179
|
// the shim for such cases.
|
|
180
|
+
|
|
187
181
|
// -----------SQL CONFIG----------
|
|
188
182
|
// Object (`window` in the browser) on which there may be an
|
|
189
183
|
// `openDatabase` method (if any) for WebSQL. (The browser
|
|
@@ -192,7 +186,8 @@
|
|
|
192
186
|
// Defaults to `window` or `self` in browser builds or
|
|
193
187
|
// a singleton object with the `openDatabase` method set to
|
|
194
188
|
// the "websql" package in Node.
|
|
195
|
-
'win',
|
|
189
|
+
'win',
|
|
190
|
+
// For internal `openDatabase` calls made by `IDBFactory` methods;
|
|
196
191
|
// per the WebSQL spec, "User agents are expected to use the display name
|
|
197
192
|
// and the estimated database size to optimize the user experience.
|
|
198
193
|
// For example, a user agent could use the estimated size to suggest an
|
|
@@ -201,61 +196,73 @@
|
|
|
201
196
|
// of the user agent prompting the user for permission to increase the
|
|
202
197
|
// quota every five megabytes."
|
|
203
198
|
// Defaults to (4 * 1024 * 1024) or (25 * 1024 * 1024) in Safari
|
|
204
|
-
'DEFAULT_DB_SIZE',
|
|
199
|
+
'DEFAULT_DB_SIZE',
|
|
200
|
+
// Whether to create indexes on SQLite tables (and also whether to try
|
|
205
201
|
// dropping)
|
|
206
202
|
// Effectively defaults to `false` (ignored unless `true`)
|
|
207
|
-
'useSQLiteIndexes',
|
|
203
|
+
'useSQLiteIndexes',
|
|
204
|
+
// NODE-IMPINGING SETTINGS (created for sake of limitations in Node
|
|
208
205
|
// or desktop file system implementation but applied by default in
|
|
209
206
|
// browser for parity)
|
|
207
|
+
|
|
210
208
|
// File system module with `unlink` to remove deleted database files
|
|
211
|
-
'fs',
|
|
209
|
+
'fs',
|
|
210
|
+
// Used when setting global shims to determine whether to try to add
|
|
212
211
|
// other globals shimmed by the library (`ShimDOMException`,
|
|
213
212
|
// `ShimDOMStringList`, `ShimEvent`, `ShimCustomEvent`, `ShimEventTarget`)
|
|
214
213
|
// Effectively defaults to `false` (ignored unless `true`)
|
|
215
|
-
'addNonIDBGlobals',
|
|
214
|
+
'addNonIDBGlobals',
|
|
215
|
+
// Used when setting global shims to determine whether to try to overwrite
|
|
216
216
|
// other globals shimmed by the library (`DOMException`, `DOMStringList`,
|
|
217
217
|
// `Event`, `CustomEvent`, `EventTarget`)
|
|
218
218
|
// Effectively defaults to `false` (ignored unless `true`)
|
|
219
|
-
'replaceNonIDBGlobals',
|
|
219
|
+
'replaceNonIDBGlobals',
|
|
220
|
+
// Overcoming limitations with node-sqlite3/storing database name on
|
|
220
221
|
// file systems
|
|
221
222
|
// https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
|
222
223
|
// Defaults to prefixing database with `D_`, escaping
|
|
223
224
|
// `databaseCharacterEscapeList`, escaping NUL, and
|
|
224
225
|
// escaping upper case letters, as well as enforcing
|
|
225
226
|
// `databaseNameLengthLimit`
|
|
226
|
-
'escapeDatabaseName',
|
|
227
|
-
|
|
227
|
+
'escapeDatabaseName',
|
|
228
|
+
// Not used internally; usable as a convenience method
|
|
229
|
+
'unescapeDatabaseName',
|
|
230
|
+
// Defaults to global regex representing the following
|
|
228
231
|
// (characters nevertheless commonly reserved in modern,
|
|
229
232
|
// Unicode-supporting systems): 0x00-0x1F 0x7F " * / : < > ? \ |
|
|
230
|
-
'databaseCharacterEscapeList',
|
|
231
|
-
|
|
233
|
+
'databaseCharacterEscapeList',
|
|
234
|
+
// Defaults to 254 (shortest typical modern file length limit)
|
|
235
|
+
'databaseNameLengthLimit',
|
|
236
|
+
// Boolean defaulting to true on whether to escape NFD-escaping
|
|
232
237
|
// characters to avoid clashes on MacOS which performs NFD on files
|
|
233
|
-
'escapeNFDForDatabaseNames',
|
|
238
|
+
'escapeNFDForDatabaseNames',
|
|
239
|
+
// Boolean on whether to add the `.sqlite` extension to file names;
|
|
234
240
|
// defaults to `true`
|
|
235
|
-
'addSQLiteExtension',
|
|
241
|
+
'addSQLiteExtension',
|
|
242
|
+
// Various types of in-memory databases that can auto-delete
|
|
236
243
|
['memoryDatabase', function (val) {
|
|
237
244
|
if (!/^(?::memory:|file::memory:(\?(?:(?!#)[\s\S])*)?(#(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?)?$/.test(val)) {
|
|
238
245
|
throw new TypeError('`memoryDatabase` must be the empty string, ":memory:", or a ' + '"file::memory:[?queryString][#hash] URL".');
|
|
239
246
|
}
|
|
240
|
-
}],
|
|
247
|
+
}],
|
|
248
|
+
// NODE-SPECIFIC CONFIG
|
|
241
249
|
// Boolean on whether to delete the database file itself after
|
|
242
250
|
// `deleteDatabase`; defaults to `true` as the database will be empty
|
|
243
|
-
'deleteDatabaseFiles', 'databaseBasePath', 'sysDatabaseBasePath',
|
|
244
|
-
|
|
245
|
-
'
|
|
251
|
+
'deleteDatabaseFiles', 'databaseBasePath', 'sysDatabaseBasePath',
|
|
252
|
+
// NODE-SPECIFIC WEBSQL CONFIG
|
|
253
|
+
'sqlBusyTimeout',
|
|
254
|
+
// Defaults to 1000
|
|
255
|
+
'sqlTrace',
|
|
256
|
+
// Callback not used by default
|
|
246
257
|
'sqlProfile' // Callback not used by default
|
|
247
258
|
].forEach(function (prop) {
|
|
248
259
|
var validator;
|
|
249
|
-
|
|
250
260
|
if (Array.isArray(prop)) {
|
|
251
261
|
var _prop = prop;
|
|
252
|
-
|
|
253
262
|
var _prop2 = _slicedToArray(_prop, 2);
|
|
254
|
-
|
|
255
263
|
prop = _prop2[0];
|
|
256
264
|
validator = _prop2[1];
|
|
257
265
|
}
|
|
258
|
-
|
|
259
266
|
Object.defineProperty(CFG, prop, {
|
|
260
267
|
get: function get() {
|
|
261
268
|
return map[prop];
|
|
@@ -264,7 +271,6 @@
|
|
|
264
271
|
if (validator) {
|
|
265
272
|
validator(val);
|
|
266
273
|
}
|
|
267
|
-
|
|
268
274
|
map[prop] = val;
|
|
269
275
|
}
|
|
270
276
|
});
|
|
@@ -276,12 +282,11 @@
|
|
|
276
282
|
* @param {string} message
|
|
277
283
|
* @returns {DOMException}
|
|
278
284
|
*/
|
|
279
|
-
|
|
280
285
|
function createNativeDOMException(name, message) {
|
|
281
286
|
return new DOMException.prototype.constructor(message, name || 'DOMException');
|
|
282
|
-
}
|
|
283
|
-
|
|
287
|
+
}
|
|
284
288
|
|
|
289
|
+
// From web-platform-tests testharness.js name_code_map (though not in new spec)
|
|
285
290
|
var codes = {
|
|
286
291
|
IndexSizeError: 1,
|
|
287
292
|
HierarchyRequestError: 3,
|
|
@@ -343,27 +348,25 @@
|
|
|
343
348
|
INVALID_NODE_TYPE_ERR: 24,
|
|
344
349
|
DATA_CLONE_ERR: 25
|
|
345
350
|
};
|
|
351
|
+
|
|
346
352
|
/**
|
|
347
353
|
*
|
|
348
354
|
* @returns {DOMException}
|
|
349
355
|
*/
|
|
350
|
-
|
|
351
356
|
function createNonNativeDOMExceptionClass() {
|
|
352
357
|
function DOMException(message, name) {
|
|
353
358
|
// const err = Error.prototype.constructor.call(this, message); // Any use to this? Won't set this.message
|
|
354
359
|
this[Symbol.toStringTag] = 'DOMException';
|
|
355
360
|
this._code = name in codes ? codes[name] : legacyCodes[name] || 0;
|
|
356
|
-
this._name = name || 'Error';
|
|
357
|
-
|
|
361
|
+
this._name = name || 'Error';
|
|
362
|
+
// We avoid `String()` in this next line as it converts Symbols
|
|
358
363
|
this._message = message === undefined ? '' : '' + message; // eslint-disable-line no-implicit-coercion
|
|
359
|
-
|
|
360
364
|
Object.defineProperty(this, 'code', {
|
|
361
365
|
configurable: true,
|
|
362
366
|
enumerable: true,
|
|
363
367
|
writable: true,
|
|
364
368
|
value: this._code
|
|
365
369
|
});
|
|
366
|
-
|
|
367
370
|
if (name !== undefined) {
|
|
368
371
|
Object.defineProperty(this, 'name', {
|
|
369
372
|
configurable: true,
|
|
@@ -372,7 +375,6 @@
|
|
|
372
375
|
value: this._name
|
|
373
376
|
});
|
|
374
377
|
}
|
|
375
|
-
|
|
376
378
|
if (message !== undefined) {
|
|
377
379
|
Object.defineProperty(this, 'message', {
|
|
378
380
|
configurable: true,
|
|
@@ -381,17 +383,14 @@
|
|
|
381
383
|
value: this._message
|
|
382
384
|
});
|
|
383
385
|
}
|
|
384
|
-
}
|
|
385
|
-
// class DummyDOMException extends Error {}; // Sometimes causing problems in Node
|
|
386
|
-
// eslint-disable-next-line func-name-matching
|
|
387
|
-
|
|
386
|
+
}
|
|
388
387
|
|
|
389
|
-
|
|
390
|
-
/* */
|
|
391
|
-
};
|
|
388
|
+
// Necessary for W3C tests which complains if `DOMException` has properties on its "own" prototype
|
|
392
389
|
|
|
390
|
+
// class DummyDOMException extends Error {}; // Sometimes causing problems in Node
|
|
391
|
+
// eslint-disable-next-line func-name-matching
|
|
392
|
+
var DummyDOMException = function DOMException() {/* */};
|
|
393
393
|
DummyDOMException.prototype = Object.create(Error.prototype); // Intended for subclassing
|
|
394
|
-
|
|
395
394
|
['name', 'message'].forEach(function (prop) {
|
|
396
395
|
Object.defineProperty(DummyDOMException.prototype, prop, {
|
|
397
396
|
enumerable: true,
|
|
@@ -399,12 +398,11 @@
|
|
|
399
398
|
if (!(this instanceof DOMException || this instanceof DummyDOMException || this instanceof Error)) {
|
|
400
399
|
throw new TypeError('Illegal invocation');
|
|
401
400
|
}
|
|
402
|
-
|
|
403
401
|
return this['_' + prop];
|
|
404
402
|
}
|
|
405
403
|
});
|
|
406
|
-
});
|
|
407
|
-
|
|
404
|
+
});
|
|
405
|
+
// DOMException uses the same `toString` as `Error`
|
|
408
406
|
Object.defineProperty(DummyDOMException.prototype, 'code', {
|
|
409
407
|
configurable: true,
|
|
410
408
|
enumerable: true,
|
|
@@ -449,18 +447,18 @@
|
|
|
449
447
|
});
|
|
450
448
|
return DOMException;
|
|
451
449
|
}
|
|
452
|
-
|
|
453
450
|
var ShimNonNativeDOMException = createNonNativeDOMExceptionClass();
|
|
451
|
+
|
|
454
452
|
/**
|
|
455
453
|
* Creates a generic Error object.
|
|
456
454
|
* @param {string} name
|
|
457
455
|
* @param {string} message
|
|
458
456
|
* @returns {Error}
|
|
459
457
|
*/
|
|
460
|
-
|
|
461
458
|
function createNonNativeDOMException(name, message) {
|
|
462
459
|
return new ShimNonNativeDOMException(message, name);
|
|
463
460
|
}
|
|
461
|
+
|
|
464
462
|
/**
|
|
465
463
|
* Logs detailed error information to the console.
|
|
466
464
|
* @param {string} name
|
|
@@ -468,37 +466,32 @@
|
|
|
468
466
|
* @param {string|Error|null} error
|
|
469
467
|
* @returns {void}
|
|
470
468
|
*/
|
|
471
|
-
|
|
472
|
-
|
|
473
469
|
function logError(name, message, error) {
|
|
474
470
|
if (CFG.DEBUG) {
|
|
475
471
|
if (error && error.message) {
|
|
476
472
|
error = error.message;
|
|
477
473
|
}
|
|
478
|
-
|
|
479
474
|
var method = typeof console.error === 'function' ? 'error' : 'log';
|
|
480
475
|
console[method](name + ': ' + message + '. ' + (error || ''));
|
|
481
476
|
console.trace && console.trace();
|
|
482
477
|
}
|
|
483
478
|
}
|
|
484
|
-
|
|
485
479
|
function isErrorOrDOMErrorOrDOMException(obj) {
|
|
486
|
-
return obj && _typeof(obj) === 'object' &&
|
|
480
|
+
return obj && _typeof(obj) === 'object' &&
|
|
481
|
+
// We don't use util.isObj here as mutual dependency causing problems in Babel with browser
|
|
487
482
|
typeof obj.name === 'string';
|
|
488
483
|
}
|
|
489
|
-
|
|
490
484
|
var test,
|
|
491
|
-
|
|
485
|
+
useNativeDOMException = false;
|
|
492
486
|
|
|
487
|
+
// Test whether we can use the browser's native DOMException class
|
|
493
488
|
try {
|
|
494
489
|
test = createNativeDOMException('test name', 'test message');
|
|
495
|
-
|
|
496
490
|
if (isErrorOrDOMErrorOrDOMException(test) && test.name === 'test name' && test.message === 'test message') {
|
|
497
491
|
// Native DOMException works as expected
|
|
498
492
|
useNativeDOMException = true;
|
|
499
493
|
}
|
|
500
494
|
} catch (e) {}
|
|
501
|
-
|
|
502
495
|
var createDOMException = useNativeDOMException ? function (name, message, error) {
|
|
503
496
|
logError(name, message, error);
|
|
504
497
|
return createNativeDOMException(name, message);
|
|
@@ -515,38 +508,32 @@
|
|
|
515
508
|
if (unmatchedHighSurrogate) {
|
|
516
509
|
return '^2' + unmatchedHighSurrogate.codePointAt().toString(16).padStart(4, '0');
|
|
517
510
|
}
|
|
518
|
-
|
|
519
511
|
return (precedingLow || '') + '^3' + unmatchedLowSurrogate.codePointAt().toString(16).padStart(4, '0');
|
|
520
512
|
});
|
|
521
513
|
}
|
|
522
514
|
|
|
523
|
-
|
|
515
|
+
// The escaping of unmatched surrogates was needed by Chrome but not Node
|
|
524
516
|
function escapeSQLiteStatement(arg) {
|
|
525
517
|
return escapeUnmatchedSurrogates(arg.replace(/\^/g, '^^').replace(/\0/g, '^0'));
|
|
526
518
|
}
|
|
527
|
-
|
|
528
519
|
function isObj(obj) {
|
|
529
520
|
return obj && _typeof(obj) === 'object';
|
|
530
521
|
}
|
|
531
|
-
|
|
532
522
|
function isDate(obj) {
|
|
533
523
|
return isObj(obj) && typeof obj.getDate === 'function';
|
|
534
524
|
}
|
|
535
|
-
|
|
536
525
|
function isBlob(obj) {
|
|
537
526
|
return isObj(obj) && typeof obj.size === 'number' && typeof obj.slice === 'function' && !('lastModified' in obj);
|
|
538
527
|
}
|
|
539
|
-
|
|
540
528
|
function isFile(obj) {
|
|
541
529
|
return isObj(obj) && typeof obj.name === 'string' && typeof obj.slice === 'function' && 'lastModified' in obj;
|
|
542
530
|
}
|
|
543
|
-
|
|
544
531
|
function isBinary(obj) {
|
|
545
|
-
return isObj(obj) && typeof obj.byteLength === 'number' && (typeof obj.slice === 'function' ||
|
|
532
|
+
return isObj(obj) && typeof obj.byteLength === 'number' && (typeof obj.slice === 'function' ||
|
|
533
|
+
// `TypedArray` (view on buffer) or `ArrayBuffer`
|
|
546
534
|
typeof obj.getFloat64 === 'function' // `DataView` (view on buffer)
|
|
547
535
|
);
|
|
548
536
|
}
|
|
549
|
-
|
|
550
537
|
function isNullish(v) {
|
|
551
538
|
return v === null || v === undefined;
|
|
552
539
|
}
|
|
@@ -557,38 +544,32 @@
|
|
|
557
544
|
* @param second
|
|
558
545
|
* @returns {number}
|
|
559
546
|
*/
|
|
560
|
-
|
|
561
547
|
function cmp(first, second) {
|
|
562
548
|
var encodedKey1 = _encode(first);
|
|
563
549
|
var encodedKey2 = _encode(second);
|
|
564
550
|
var result = encodedKey1 > encodedKey2 ? 1 : encodedKey1 === encodedKey2 ? 0 : -1;
|
|
565
|
-
|
|
566
551
|
if (CFG.DEBUG) {
|
|
567
552
|
// verify that the keys encoded correctly
|
|
568
553
|
var decodedKey1 = _decode(encodedKey1);
|
|
569
554
|
var decodedKey2 = _decode(encodedKey2);
|
|
570
|
-
|
|
571
555
|
if (_typeof(first) === 'object') {
|
|
572
556
|
first = JSON.stringify(first);
|
|
573
557
|
decodedKey1 = JSON.stringify(decodedKey1);
|
|
574
558
|
}
|
|
575
|
-
|
|
576
559
|
if (_typeof(second) === 'object') {
|
|
577
560
|
second = JSON.stringify(second);
|
|
578
561
|
decodedKey2 = JSON.stringify(decodedKey2);
|
|
579
|
-
}
|
|
580
|
-
// floating-point precision
|
|
581
|
-
|
|
562
|
+
}
|
|
582
563
|
|
|
564
|
+
// Encoding/decoding mismatches are usually due to a loss of
|
|
565
|
+
// floating-point precision
|
|
583
566
|
if (decodedKey1 !== first) {
|
|
584
567
|
console.warn(first + ' was incorrectly encoded as ' + decodedKey1);
|
|
585
568
|
}
|
|
586
|
-
|
|
587
569
|
if (decodedKey2 !== second) {
|
|
588
570
|
console.warn(second + ' was incorrectly encoded as ' + decodedKey2);
|
|
589
571
|
}
|
|
590
572
|
}
|
|
591
|
-
|
|
592
573
|
return result;
|
|
593
574
|
}
|
|
594
575
|
|
|
@@ -600,7 +581,6 @@
|
|
|
600
581
|
* Encodes the keys based on their types. This is required to maintain collations
|
|
601
582
|
* We leave space for future keys.
|
|
602
583
|
*/
|
|
603
|
-
|
|
604
584
|
var keyTypeToEncodedChar = {
|
|
605
585
|
invalid: 100,
|
|
606
586
|
number: 200,
|
|
@@ -617,6 +597,7 @@
|
|
|
617
597
|
o[keyTypeToEncodedChar[k]] = k;
|
|
618
598
|
return o;
|
|
619
599
|
}, {});
|
|
600
|
+
|
|
620
601
|
/**
|
|
621
602
|
* The sign values for numbers, ordered from least to greatest.
|
|
622
603
|
* - "negativeInfinity": Sorts below all other values.
|
|
@@ -626,7 +607,6 @@
|
|
|
626
607
|
* - "largePositive": Positive values greater than or equal to one.
|
|
627
608
|
* - "positiveInfinity": Sorts above all other values.
|
|
628
609
|
*/
|
|
629
|
-
|
|
630
610
|
var signValues = ['negativeInfinity', 'bigNegative', 'smallNegative', 'smallPositive', 'bigPositive', 'positiveInfinity'];
|
|
631
611
|
var types = {
|
|
632
612
|
invalid: {
|
|
@@ -651,21 +631,23 @@
|
|
|
651
631
|
// The encode step checks for six numeric cases and generates 14-digit encoded
|
|
652
632
|
// sign-exponent-mantissa strings.
|
|
653
633
|
encode: function encode(key) {
|
|
654
|
-
var key32 = key === Number.MIN_VALUE
|
|
634
|
+
var key32 = key === Number.MIN_VALUE
|
|
635
|
+
// Mocha test `IDBFactory/cmp-spec.js` exposed problem for some
|
|
655
636
|
// Node (and Chrome) versions with `Number.MIN_VALUE` being treated
|
|
656
637
|
// as 0
|
|
657
638
|
// https://stackoverflow.com/questions/43305403/number-min-value-and-tostring
|
|
658
|
-
? '0.' + '0'.repeat(214) + '2' : Math.abs(key).toString(32);
|
|
659
|
-
|
|
660
|
-
var decimalIndex = key32.indexOf('.');
|
|
661
|
-
|
|
662
|
-
key32 = decimalIndex !== -1 ? key32.replace('.', '') : key32;
|
|
663
|
-
|
|
664
|
-
var significantDigitIndex = key32.search(/(?:(?!0)[\s\S])/);
|
|
665
|
-
|
|
639
|
+
? '0.' + '0'.repeat(214) + '2' : Math.abs(key).toString(32);
|
|
640
|
+
// Get the index of the decimal.
|
|
641
|
+
var decimalIndex = key32.indexOf('.');
|
|
642
|
+
// Remove the decimal.
|
|
643
|
+
key32 = decimalIndex !== -1 ? key32.replace('.', '') : key32;
|
|
644
|
+
// Get the index of the first significant digit.
|
|
645
|
+
var significantDigitIndex = key32.search(/(?:(?!0)[\s\S])/);
|
|
646
|
+
// Truncate leading zeros.
|
|
666
647
|
key32 = key32.slice(significantDigitIndex);
|
|
667
|
-
var sign, exponent, mantissa;
|
|
648
|
+
var sign, exponent, mantissa;
|
|
668
649
|
|
|
650
|
+
// Finite cases:
|
|
669
651
|
if (Number.isFinite(Number(key))) {
|
|
670
652
|
// Negative cases:
|
|
671
653
|
if (key < 0) {
|
|
@@ -673,30 +655,31 @@
|
|
|
673
655
|
if (key > -1) {
|
|
674
656
|
sign = signValues.indexOf('smallNegative');
|
|
675
657
|
exponent = padBase32Exponent(significantDigitIndex);
|
|
676
|
-
mantissa = flipBase32(padBase32Mantissa(key32));
|
|
658
|
+
mantissa = flipBase32(padBase32Mantissa(key32));
|
|
659
|
+
// Non-negative exponent case:
|
|
677
660
|
} else {
|
|
678
661
|
sign = signValues.indexOf('bigNegative');
|
|
679
662
|
exponent = flipBase32(padBase32Exponent(decimalIndex !== -1 ? decimalIndex : key32.length));
|
|
680
663
|
mantissa = flipBase32(padBase32Mantissa(key32));
|
|
681
|
-
}
|
|
664
|
+
}
|
|
665
|
+
// Non-negative cases:
|
|
682
666
|
// Negative exponent case:
|
|
683
|
-
|
|
684
667
|
} else if (key < 1) {
|
|
685
668
|
sign = signValues.indexOf('smallPositive');
|
|
686
669
|
exponent = flipBase32(padBase32Exponent(significantDigitIndex));
|
|
687
|
-
mantissa = padBase32Mantissa(key32);
|
|
670
|
+
mantissa = padBase32Mantissa(key32);
|
|
671
|
+
// Non-negative exponent case:
|
|
688
672
|
} else {
|
|
689
673
|
sign = signValues.indexOf('bigPositive');
|
|
690
674
|
exponent = padBase32Exponent(decimalIndex !== -1 ? decimalIndex : key32.length);
|
|
691
675
|
mantissa = padBase32Mantissa(key32);
|
|
692
|
-
}
|
|
693
|
-
|
|
676
|
+
}
|
|
677
|
+
// Infinite cases:
|
|
694
678
|
} else {
|
|
695
679
|
exponent = zeros(2);
|
|
696
680
|
mantissa = zeros(11);
|
|
697
681
|
sign = signValues.indexOf(key > 0 ? 'positiveInfinity' : 'negativeInfinity');
|
|
698
682
|
}
|
|
699
|
-
|
|
700
683
|
return keyTypeToEncodedChar.number + '-' + sign + exponent + mantissa;
|
|
701
684
|
},
|
|
702
685
|
// The decode step must interpret the sign, reflip values encoded as the 32's complements,
|
|
@@ -706,31 +689,24 @@
|
|
|
706
689
|
var sign = Number(key.slice(2, 3));
|
|
707
690
|
var exponent = key.slice(3, 5);
|
|
708
691
|
var mantissa = key.slice(5, 16);
|
|
709
|
-
|
|
710
692
|
switch (signValues[sign]) {
|
|
711
693
|
case 'negativeInfinity':
|
|
712
694
|
return Number.NEGATIVE_INFINITY;
|
|
713
|
-
|
|
714
695
|
case 'positiveInfinity':
|
|
715
696
|
return Number.POSITIVE_INFINITY;
|
|
716
|
-
|
|
717
697
|
case 'bigPositive':
|
|
718
698
|
return pow32(mantissa, exponent);
|
|
719
|
-
|
|
720
699
|
case 'smallPositive':
|
|
721
700
|
exponent = negate(flipBase32(exponent));
|
|
722
701
|
return pow32(mantissa, exponent);
|
|
723
|
-
|
|
724
702
|
case 'smallNegative':
|
|
725
703
|
exponent = negate(exponent);
|
|
726
704
|
mantissa = flipBase32(mantissa);
|
|
727
705
|
return -pow32(mantissa, exponent);
|
|
728
|
-
|
|
729
706
|
case 'bigNegative':
|
|
730
707
|
exponent = flipBase32(exponent);
|
|
731
708
|
mantissa = flipBase32(mantissa);
|
|
732
709
|
return -pow32(mantissa, exponent);
|
|
733
|
-
|
|
734
710
|
default:
|
|
735
711
|
throw new Error('Invalid number.');
|
|
736
712
|
}
|
|
@@ -750,17 +726,14 @@
|
|
|
750
726
|
// prepend each character with a dash, and append a space to the end
|
|
751
727
|
key = key.replace(/((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/g, '-$1') + ' ';
|
|
752
728
|
}
|
|
753
|
-
|
|
754
729
|
return keyTypeToEncodedChar.string + '-' + key;
|
|
755
730
|
},
|
|
756
731
|
decode: function decode(key, inArray) {
|
|
757
732
|
key = key.slice(2);
|
|
758
|
-
|
|
759
733
|
if (inArray) {
|
|
760
734
|
// remove the space at the end, and the dash before each character
|
|
761
735
|
key = key.slice(0, -1).replace(/\x2D((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/g, '$1');
|
|
762
736
|
}
|
|
763
|
-
|
|
764
737
|
return key;
|
|
765
738
|
}
|
|
766
739
|
},
|
|
@@ -770,19 +743,14 @@
|
|
|
770
743
|
array: {
|
|
771
744
|
encode: function encode(key) {
|
|
772
745
|
var encoded = [];
|
|
773
|
-
|
|
774
746
|
var _iterator = _createForOfIteratorHelper(key.entries()),
|
|
775
|
-
|
|
776
|
-
|
|
747
|
+
_step;
|
|
777
748
|
try {
|
|
778
749
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
779
750
|
var _step$value = _slicedToArray(_step.value, 2),
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
751
|
+
i = _step$value[0],
|
|
752
|
+
item = _step$value[1];
|
|
783
753
|
var encodedItem = _encode(item, true); // encode the array item
|
|
784
|
-
|
|
785
|
-
|
|
786
754
|
encoded[i] = encodedItem;
|
|
787
755
|
}
|
|
788
756
|
} catch (err) {
|
|
@@ -790,24 +758,17 @@
|
|
|
790
758
|
} finally {
|
|
791
759
|
_iterator.f();
|
|
792
760
|
}
|
|
793
|
-
|
|
794
761
|
encoded.push(keyTypeToEncodedChar.invalid + '-'); // append an extra item, so empty arrays sort correctly
|
|
795
|
-
|
|
796
762
|
return keyTypeToEncodedChar.array + '-' + JSON.stringify(encoded);
|
|
797
763
|
},
|
|
798
764
|
decode: function decode(key) {
|
|
799
765
|
var decoded = JSON.parse(key.slice(2));
|
|
800
766
|
decoded.pop(); // remove the extra item
|
|
801
|
-
|
|
802
767
|
for (var i = 0; i < decoded.length; i++) {
|
|
803
768
|
var item = decoded[i];
|
|
804
|
-
|
|
805
769
|
var decodedItem = _decode(item, true); // decode the item
|
|
806
|
-
|
|
807
|
-
|
|
808
770
|
decoded[i] = decodedItem;
|
|
809
771
|
}
|
|
810
|
-
|
|
811
772
|
return decoded;
|
|
812
773
|
}
|
|
813
774
|
},
|
|
@@ -841,39 +802,35 @@
|
|
|
841
802
|
}
|
|
842
803
|
}
|
|
843
804
|
};
|
|
805
|
+
|
|
844
806
|
/**
|
|
845
807
|
* Return a padded base-32 exponent value.
|
|
846
808
|
* @param {number} n
|
|
847
809
|
* @returns {string}
|
|
848
810
|
*/
|
|
849
|
-
|
|
850
811
|
function padBase32Exponent(n) {
|
|
851
812
|
n = n.toString(32);
|
|
852
813
|
return n.length === 1 ? '0' + n : n;
|
|
853
814
|
}
|
|
815
|
+
|
|
854
816
|
/**
|
|
855
817
|
* Return a padded base-32 mantissa.
|
|
856
818
|
* @param {string} s
|
|
857
819
|
* @returns {string}
|
|
858
820
|
*/
|
|
859
|
-
|
|
860
|
-
|
|
861
821
|
function padBase32Mantissa(s) {
|
|
862
822
|
return (s + zeros(11)).slice(0, 11);
|
|
863
823
|
}
|
|
824
|
+
|
|
864
825
|
/**
|
|
865
826
|
* Flips each digit of a base-32 encoded string.
|
|
866
827
|
* @param {string} encoded
|
|
867
828
|
* @returns {string}
|
|
868
829
|
*/
|
|
869
|
-
|
|
870
|
-
|
|
871
830
|
function flipBase32(encoded) {
|
|
872
831
|
var flipped = '';
|
|
873
|
-
|
|
874
832
|
var _iterator2 = _createForOfIteratorHelper(encoded),
|
|
875
|
-
|
|
876
|
-
|
|
833
|
+
_step2;
|
|
877
834
|
try {
|
|
878
835
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
879
836
|
var ch = _step2.value;
|
|
@@ -884,9 +841,9 @@
|
|
|
884
841
|
} finally {
|
|
885
842
|
_iterator2.f();
|
|
886
843
|
}
|
|
887
|
-
|
|
888
844
|
return flipped;
|
|
889
845
|
}
|
|
846
|
+
|
|
890
847
|
/**
|
|
891
848
|
* Base-32 power function.
|
|
892
849
|
* RESEARCH: This function does not precisely decode floats because it performs
|
|
@@ -899,15 +856,11 @@
|
|
|
899
856
|
* @param {string} exponent
|
|
900
857
|
* @returns {number}
|
|
901
858
|
*/
|
|
902
|
-
|
|
903
|
-
|
|
904
859
|
function pow32(mantissa, exponent) {
|
|
905
860
|
exponent = Number.parseInt(exponent, 32);
|
|
906
|
-
|
|
907
861
|
if (exponent < 0) {
|
|
908
862
|
return roundToPrecision(Number.parseInt(mantissa, 32) * Math.pow(32, exponent - 10));
|
|
909
863
|
}
|
|
910
|
-
|
|
911
864
|
if (exponent < 11) {
|
|
912
865
|
var whole = mantissa.slice(0, exponent);
|
|
913
866
|
whole = Number.parseInt(whole, 32);
|
|
@@ -915,41 +868,38 @@
|
|
|
915
868
|
fraction = Number.parseInt(fraction, 32) * Math.pow(32, exponent - 11);
|
|
916
869
|
return roundToPrecision(whole + fraction);
|
|
917
870
|
}
|
|
918
|
-
|
|
919
871
|
var expansion = mantissa + zeros(exponent - 11);
|
|
920
872
|
return Number.parseInt(expansion, 32);
|
|
921
873
|
}
|
|
874
|
+
|
|
922
875
|
/**
|
|
923
876
|
* @param {Float} num
|
|
924
877
|
* @param {Float} [precision=16]
|
|
925
878
|
* @returns {Float}
|
|
926
879
|
*/
|
|
927
|
-
|
|
928
|
-
|
|
929
880
|
function roundToPrecision(num) {
|
|
930
881
|
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 16;
|
|
931
882
|
return Number.parseFloat(num.toPrecision(precision));
|
|
932
883
|
}
|
|
884
|
+
|
|
933
885
|
/**
|
|
934
886
|
* Returns a string of n zeros.
|
|
935
887
|
* @param {number} n
|
|
936
888
|
* @returns {string}
|
|
937
889
|
*/
|
|
938
|
-
|
|
939
|
-
|
|
940
890
|
function zeros(n) {
|
|
941
891
|
return '0'.repeat(n);
|
|
942
892
|
}
|
|
893
|
+
|
|
943
894
|
/**
|
|
944
895
|
* Negates numeric strings.
|
|
945
896
|
* @param {string} s
|
|
946
897
|
* @returns {string}
|
|
947
898
|
*/
|
|
948
|
-
|
|
949
|
-
|
|
950
899
|
function negate(s) {
|
|
951
900
|
return '-' + s;
|
|
952
901
|
}
|
|
902
|
+
|
|
953
903
|
/**
|
|
954
904
|
* @typedef {"number"|"date"|"string"|"binary"|"array"} module:Key.KeyType
|
|
955
905
|
*/
|
|
@@ -958,17 +908,14 @@
|
|
|
958
908
|
* @param key
|
|
959
909
|
* @returns {module:Key.KeyType}
|
|
960
910
|
*/
|
|
961
|
-
|
|
962
|
-
|
|
963
911
|
function getKeyType(key) {
|
|
964
912
|
if (Array.isArray(key)) return 'array';
|
|
965
913
|
if (isDate(key)) return 'date';
|
|
966
914
|
if (isBinary(key)) return 'binary';
|
|
967
|
-
|
|
968
915
|
var keyType = _typeof(key);
|
|
969
|
-
|
|
970
916
|
return ['string', 'number'].includes(keyType) ? keyType : 'invalid';
|
|
971
917
|
}
|
|
918
|
+
|
|
972
919
|
/**
|
|
973
920
|
* Keys must be strings, numbers (besides `NaN`), Dates (if value is not
|
|
974
921
|
* `NaN`), binary objects or Arrays.
|
|
@@ -976,21 +923,19 @@
|
|
|
976
923
|
* @param {?(Array)} [seen] An array of already seen keys
|
|
977
924
|
* @returns {module:Key.keyValueObject}
|
|
978
925
|
*/
|
|
979
|
-
|
|
980
|
-
|
|
981
926
|
function convertValueToKey(input, seen) {
|
|
982
927
|
return convertValueToKeyValueDecoded(input, seen, false, true);
|
|
983
928
|
}
|
|
929
|
+
|
|
984
930
|
/**
|
|
985
931
|
* Currently not in use.
|
|
986
932
|
* @param input
|
|
987
933
|
* @returns {module:Key.keyValueObject}
|
|
988
934
|
*/
|
|
989
|
-
|
|
990
|
-
|
|
991
935
|
function convertValueToMultiEntryKey(input) {
|
|
992
936
|
return convertValueToKeyValueDecoded(input, null, true, true);
|
|
993
937
|
}
|
|
938
|
+
|
|
994
939
|
/**
|
|
995
940
|
*
|
|
996
941
|
* @param O
|
|
@@ -998,31 +943,25 @@
|
|
|
998
943
|
* @see https://heycam.github.io/webidl/#ref-for-dfn-get-buffer-source-copy-2
|
|
999
944
|
* @returns {Uint8Array}
|
|
1000
945
|
*/
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
946
|
function getCopyBytesHeldByBufferSource(O) {
|
|
1004
947
|
var offset = 0;
|
|
1005
948
|
var length = 0;
|
|
1006
|
-
|
|
1007
949
|
if (ArrayBuffer.isView(O)) {
|
|
1008
950
|
// Has [[ViewedArrayBuffer]] internal slot
|
|
1009
951
|
var arrayBuffer = O.buffer;
|
|
1010
|
-
|
|
1011
952
|
if (arrayBuffer === undefined) {
|
|
1012
953
|
throw new TypeError('Could not copy the bytes held by a buffer source as the buffer was undefined.');
|
|
1013
954
|
}
|
|
1014
|
-
|
|
1015
955
|
offset = O.byteOffset; // [[ByteOffset]] (will also throw as desired if detached)
|
|
1016
|
-
|
|
1017
956
|
length = O.byteLength; // [[ByteLength]] (will also throw as desired if detached)
|
|
1018
957
|
} else {
|
|
1019
958
|
length = O.byteLength; // [[ArrayBufferByteLength]] on ArrayBuffer (will also throw as desired if detached)
|
|
1020
|
-
}
|
|
959
|
+
}
|
|
960
|
+
// const octets = new Uint8Array(input);
|
|
1021
961
|
// const octets = types.binary.decode(types.binary.encode(input));
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
962
|
return new Uint8Array(O.buffer || O, offset, length);
|
|
1025
963
|
}
|
|
964
|
+
|
|
1026
965
|
/**
|
|
1027
966
|
* @typedef {PlainObject} module:Key.keyValueObject
|
|
1028
967
|
* @property {module:Key.KeyType|"NaN"} type
|
|
@@ -1044,11 +983,8 @@
|
|
|
1044
983
|
* @todo Document other allowable `input`
|
|
1045
984
|
* @returns {module:Key.keyValueObject}
|
|
1046
985
|
*/
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
986
|
function convertValueToKeyValueDecoded(input, seen, multiEntry, fullKeys) {
|
|
1050
987
|
seen = seen || [];
|
|
1051
|
-
|
|
1052
988
|
if (seen.includes(input)) {
|
|
1053
989
|
return {
|
|
1054
990
|
type: 'array',
|
|
@@ -1056,13 +992,11 @@
|
|
|
1056
992
|
message: 'An array key cannot be circular'
|
|
1057
993
|
};
|
|
1058
994
|
}
|
|
1059
|
-
|
|
1060
995
|
var type = getKeyType(input);
|
|
1061
996
|
var ret = {
|
|
1062
997
|
type: type,
|
|
1063
998
|
value: input
|
|
1064
999
|
};
|
|
1065
|
-
|
|
1066
1000
|
switch (type) {
|
|
1067
1001
|
case 'number':
|
|
1068
1002
|
{
|
|
@@ -1073,15 +1007,12 @@
|
|
|
1073
1007
|
invalid: true
|
|
1074
1008
|
};
|
|
1075
1009
|
}
|
|
1076
|
-
|
|
1077
1010
|
return ret;
|
|
1078
1011
|
}
|
|
1079
|
-
|
|
1080
1012
|
case 'string':
|
|
1081
1013
|
{
|
|
1082
1014
|
return ret;
|
|
1083
1015
|
}
|
|
1084
|
-
|
|
1085
1016
|
case 'binary':
|
|
1086
1017
|
{
|
|
1087
1018
|
// May throw (if detached)
|
|
@@ -1093,67 +1024,61 @@
|
|
|
1093
1024
|
value: octets
|
|
1094
1025
|
};
|
|
1095
1026
|
}
|
|
1096
|
-
|
|
1097
1027
|
case 'array':
|
|
1098
1028
|
{
|
|
1099
1029
|
// May throw (from binary)
|
|
1100
1030
|
var len = input.length;
|
|
1101
1031
|
seen.push(input);
|
|
1102
1032
|
var keys = [];
|
|
1103
|
-
|
|
1104
|
-
for (var i = 0; i < len; i++) {
|
|
1033
|
+
var _loop = function _loop() {
|
|
1105
1034
|
// We cannot iterate here with array extras as we must ensure sparse arrays are invalidated
|
|
1106
1035
|
if (!multiEntry && !Object.prototype.hasOwnProperty.call(input, i)) {
|
|
1107
1036
|
return {
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1037
|
+
v: {
|
|
1038
|
+
type: type,
|
|
1039
|
+
invalid: true,
|
|
1040
|
+
message: 'Does not have own index property'
|
|
1041
|
+
}
|
|
1111
1042
|
};
|
|
1112
1043
|
}
|
|
1113
|
-
|
|
1114
1044
|
try {
|
|
1115
|
-
var
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
if (multiEntry) {
|
|
1121
|
-
return "continue";
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
return {
|
|
1125
|
-
v: {
|
|
1126
|
-
type: type,
|
|
1127
|
-
invalid: true,
|
|
1128
|
-
message: 'Bad array entry value-to-key conversion'
|
|
1129
|
-
}
|
|
1130
|
-
};
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
if (!multiEntry || !fullKeys && keys.every(function (k) {
|
|
1134
|
-
return cmp(k, key.value) !== 0;
|
|
1135
|
-
}) || fullKeys && keys.every(function (k) {
|
|
1136
|
-
return cmp(k, key) !== 0;
|
|
1137
|
-
})) {
|
|
1138
|
-
keys.push(fullKeys ? key : key.value);
|
|
1045
|
+
var entry = input[i];
|
|
1046
|
+
var key = convertValueToKeyValueDecoded(entry, seen, false, fullKeys); // Though steps do not list rethrowing, the next is returnifabrupt when not multiEntry
|
|
1047
|
+
if (key.invalid) {
|
|
1048
|
+
if (multiEntry) {
|
|
1049
|
+
return "continue";
|
|
1139
1050
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1051
|
+
return {
|
|
1052
|
+
v: {
|
|
1053
|
+
type: type,
|
|
1054
|
+
invalid: true,
|
|
1055
|
+
message: 'Bad array entry value-to-key conversion'
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
if (!multiEntry || !fullKeys && keys.every(function (k) {
|
|
1060
|
+
return cmp(k, key.value) !== 0;
|
|
1061
|
+
}) || fullKeys && keys.every(function (k) {
|
|
1062
|
+
return cmp(k, key) !== 0;
|
|
1063
|
+
})) {
|
|
1064
|
+
keys.push(fullKeys ? key : key.value);
|
|
1065
|
+
}
|
|
1144
1066
|
} catch (err) {
|
|
1145
1067
|
if (!multiEntry) {
|
|
1146
1068
|
throw err;
|
|
1147
1069
|
}
|
|
1148
1070
|
}
|
|
1071
|
+
};
|
|
1072
|
+
for (var i = 0; i < len; i++) {
|
|
1073
|
+
var _ret = _loop();
|
|
1074
|
+
if (_ret === "continue") continue;
|
|
1075
|
+
if (_typeof(_ret) === "object") return _ret.v;
|
|
1149
1076
|
}
|
|
1150
|
-
|
|
1151
1077
|
return {
|
|
1152
1078
|
type: type,
|
|
1153
1079
|
value: keys
|
|
1154
1080
|
};
|
|
1155
1081
|
}
|
|
1156
|
-
|
|
1157
1082
|
case 'date':
|
|
1158
1083
|
{
|
|
1159
1084
|
if (!Number.isNaN(input.getTime())) {
|
|
@@ -1165,22 +1090,19 @@
|
|
|
1165
1090
|
value: new Date(input.getTime())
|
|
1166
1091
|
};
|
|
1167
1092
|
}
|
|
1168
|
-
|
|
1169
1093
|
return {
|
|
1170
1094
|
type: type,
|
|
1171
1095
|
invalid: true,
|
|
1172
1096
|
message: 'Not a valid date'
|
|
1173
|
-
};
|
|
1097
|
+
};
|
|
1098
|
+
// Falls through
|
|
1174
1099
|
}
|
|
1175
|
-
|
|
1176
1100
|
case 'invalid':
|
|
1177
1101
|
default:
|
|
1178
1102
|
{
|
|
1179
1103
|
// Other `typeof` types which are not valid keys:
|
|
1180
1104
|
// 'undefined', 'boolean', 'object' (including `null`), 'symbol', 'function
|
|
1181
1105
|
var _type = input === null ? 'null' : _typeof(input); // Convert `null` for convenience of consumers in reporting errors
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
1106
|
return {
|
|
1185
1107
|
type: _type,
|
|
1186
1108
|
invalid: true,
|
|
@@ -1189,6 +1111,7 @@
|
|
|
1189
1111
|
}
|
|
1190
1112
|
}
|
|
1191
1113
|
}
|
|
1114
|
+
|
|
1192
1115
|
/**
|
|
1193
1116
|
* @typedef {*} module:Key.Key
|
|
1194
1117
|
* @todo Specify possible value more precisely
|
|
@@ -1201,11 +1124,10 @@
|
|
|
1201
1124
|
* @returns {module:Key.keyValueObject}
|
|
1202
1125
|
* @todo Document other allowable `key`?
|
|
1203
1126
|
*/
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
1127
|
function convertValueToMultiEntryKeyDecoded(key, fullKeys) {
|
|
1207
1128
|
return convertValueToKeyValueDecoded(key, null, true, fullKeys);
|
|
1208
1129
|
}
|
|
1130
|
+
|
|
1209
1131
|
/**
|
|
1210
1132
|
* An internal utility.
|
|
1211
1133
|
* @param input
|
|
@@ -1213,17 +1135,14 @@
|
|
|
1213
1135
|
* @throws {DOMException} `DataError`
|
|
1214
1136
|
* @returns {module:Key.keyValueObject}
|
|
1215
1137
|
*/
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
1138
|
function convertValueToKeyRethrowingAndIfInvalid(input, seen) {
|
|
1219
1139
|
var key = convertValueToKey(input, seen);
|
|
1220
|
-
|
|
1221
1140
|
if (key.invalid) {
|
|
1222
1141
|
throw createDOMException('DataError', key.message || 'Not a valid key; type: ' + key.type);
|
|
1223
1142
|
}
|
|
1224
|
-
|
|
1225
1143
|
return key;
|
|
1226
1144
|
}
|
|
1145
|
+
|
|
1227
1146
|
/**
|
|
1228
1147
|
*
|
|
1229
1148
|
* @param value
|
|
@@ -1232,8 +1151,6 @@
|
|
|
1232
1151
|
* @returns {module:Key.keyValueObject|module:Key.KeyPathEvaluateValue}
|
|
1233
1152
|
* @todo Document other possible return?
|
|
1234
1153
|
*/
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
1154
|
function extractKeyFromValueUsingKeyPath(value, keyPath, multiEntry) {
|
|
1238
1155
|
return extractKeyValueDecodedFromValueUsingKeyPath(value, keyPath, multiEntry, true);
|
|
1239
1156
|
}
|
|
@@ -1244,11 +1161,10 @@
|
|
|
1244
1161
|
* @param {boolean} multiEntry
|
|
1245
1162
|
* @returns {module:Key.KeyPathEvaluateValue}
|
|
1246
1163
|
*/
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
1164
|
function evaluateKeyPathOnValue(value, keyPath, multiEntry) {
|
|
1250
1165
|
return evaluateKeyPathOnValueToDecodedValue(value, keyPath);
|
|
1251
1166
|
}
|
|
1167
|
+
|
|
1252
1168
|
/**
|
|
1253
1169
|
* May throw, return `{failure: true}` (e.g., non-object on keyPath resolution)
|
|
1254
1170
|
* or `{invalid: true}` (e.g., `NaN`).
|
|
@@ -1259,21 +1175,17 @@
|
|
|
1259
1175
|
* @returns {module:Key.keyValueObject|module:Key.KeyPathEvaluateValue}
|
|
1260
1176
|
* @todo Document other possible return?
|
|
1261
1177
|
*/
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
1178
|
function extractKeyValueDecodedFromValueUsingKeyPath(value, keyPath, multiEntry, fullKeys) {
|
|
1265
1179
|
var r = evaluateKeyPathOnValueToDecodedValue(value, keyPath);
|
|
1266
|
-
|
|
1267
1180
|
if (r.failure) {
|
|
1268
1181
|
return r;
|
|
1269
1182
|
}
|
|
1270
|
-
|
|
1271
1183
|
if (!multiEntry) {
|
|
1272
1184
|
return convertValueToKeyValueDecoded(r.value, null, false, fullKeys);
|
|
1273
1185
|
}
|
|
1274
|
-
|
|
1275
1186
|
return convertValueToMultiEntryKeyDecoded(r.value, fullKeys);
|
|
1276
1187
|
}
|
|
1188
|
+
|
|
1277
1189
|
/**
|
|
1278
1190
|
* @typedef {PlainObject} module:Key.KeyPathEvaluateFailure
|
|
1279
1191
|
* @property {boolean} failure
|
|
@@ -1293,18 +1205,14 @@
|
|
|
1293
1205
|
* @param {boolean} [fullKeys]
|
|
1294
1206
|
* @returns {module:Key.KeyPathEvaluateValue}
|
|
1295
1207
|
*/
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
1208
|
function evaluateKeyPathOnValueToDecodedValue(value, keyPath, multiEntry, fullKeys) {
|
|
1299
1209
|
if (Array.isArray(keyPath)) {
|
|
1300
1210
|
var result = [];
|
|
1301
1211
|
return keyPath.some(function (item) {
|
|
1302
1212
|
var key = evaluateKeyPathOnValueToDecodedValue(value, item);
|
|
1303
|
-
|
|
1304
1213
|
if (key.failure) {
|
|
1305
1214
|
return true;
|
|
1306
1215
|
}
|
|
1307
|
-
|
|
1308
1216
|
result.push(key.value);
|
|
1309
1217
|
return false;
|
|
1310
1218
|
}) ? {
|
|
@@ -1313,13 +1221,11 @@
|
|
|
1313
1221
|
value: result
|
|
1314
1222
|
};
|
|
1315
1223
|
}
|
|
1316
|
-
|
|
1317
1224
|
if (keyPath === '') {
|
|
1318
1225
|
return {
|
|
1319
1226
|
value: value
|
|
1320
1227
|
};
|
|
1321
1228
|
}
|
|
1322
|
-
|
|
1323
1229
|
var identifiers = keyPath.split('.');
|
|
1324
1230
|
return identifiers.some(function (idntfr, i) {
|
|
1325
1231
|
if (idntfr === 'length' && (typeof value === 'string' || Array.isArray(value))) {
|
|
@@ -1337,7 +1243,6 @@
|
|
|
1337
1243
|
case 'lastModified':
|
|
1338
1244
|
value = value[idntfr];
|
|
1339
1245
|
break;
|
|
1340
|
-
|
|
1341
1246
|
case 'lastModifiedDate':
|
|
1342
1247
|
value = new Date(value.lastModified);
|
|
1343
1248
|
break;
|
|
@@ -1348,7 +1253,6 @@
|
|
|
1348
1253
|
value = value[idntfr];
|
|
1349
1254
|
return value === undefined;
|
|
1350
1255
|
}
|
|
1351
|
-
|
|
1352
1256
|
return false;
|
|
1353
1257
|
}) ? {
|
|
1354
1258
|
failure: true
|
|
@@ -1356,6 +1260,7 @@
|
|
|
1356
1260
|
value: value
|
|
1357
1261
|
};
|
|
1358
1262
|
}
|
|
1263
|
+
|
|
1359
1264
|
/**
|
|
1360
1265
|
* Sets the inline key value.
|
|
1361
1266
|
* @param {object} value
|
|
@@ -1363,22 +1268,19 @@
|
|
|
1363
1268
|
* @param {string} keyPath
|
|
1364
1269
|
* @returns {void}
|
|
1365
1270
|
*/
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
1271
|
function injectKeyIntoValueUsingKeyPath(value, key, keyPath) {
|
|
1369
1272
|
var identifiers = keyPath.split('.');
|
|
1370
1273
|
var last = identifiers.pop();
|
|
1371
1274
|
identifiers.forEach(function (identifier) {
|
|
1372
1275
|
var hop = Object.prototype.hasOwnProperty.call(value, identifier);
|
|
1373
|
-
|
|
1374
1276
|
if (!hop) {
|
|
1375
1277
|
value[identifier] = {};
|
|
1376
1278
|
}
|
|
1377
|
-
|
|
1378
1279
|
value = value[identifier];
|
|
1379
1280
|
});
|
|
1380
1281
|
value[last] = key; // key is already a `keyValue` in our processing so no need to convert
|
|
1381
1282
|
}
|
|
1283
|
+
|
|
1382
1284
|
/**
|
|
1383
1285
|
*
|
|
1384
1286
|
* @param value
|
|
@@ -1386,29 +1288,21 @@
|
|
|
1386
1288
|
* @see https://github.com/w3c/IndexedDB/pull/146
|
|
1387
1289
|
* @returns {boolean}
|
|
1388
1290
|
*/
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
1291
|
function checkKeyCouldBeInjectedIntoValue(value, keyPath) {
|
|
1392
1292
|
var identifiers = keyPath.split('.');
|
|
1393
1293
|
identifiers.pop();
|
|
1394
|
-
|
|
1395
1294
|
var _iterator3 = _createForOfIteratorHelper(identifiers),
|
|
1396
|
-
|
|
1397
|
-
|
|
1295
|
+
_step3;
|
|
1398
1296
|
try {
|
|
1399
1297
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
1400
1298
|
var identifier = _step3.value;
|
|
1401
|
-
|
|
1402
1299
|
if (!isObj(value)) {
|
|
1403
1300
|
return false;
|
|
1404
1301
|
}
|
|
1405
|
-
|
|
1406
1302
|
var hop = Object.prototype.hasOwnProperty.call(value, identifier);
|
|
1407
|
-
|
|
1408
1303
|
if (!hop) {
|
|
1409
1304
|
return true;
|
|
1410
1305
|
}
|
|
1411
|
-
|
|
1412
1306
|
value = value[identifier];
|
|
1413
1307
|
}
|
|
1414
1308
|
} catch (err) {
|
|
@@ -1416,9 +1310,9 @@
|
|
|
1416
1310
|
} finally {
|
|
1417
1311
|
_iterator3.f();
|
|
1418
1312
|
}
|
|
1419
|
-
|
|
1420
1313
|
return isObj(value);
|
|
1421
1314
|
}
|
|
1315
|
+
|
|
1422
1316
|
/**
|
|
1423
1317
|
*
|
|
1424
1318
|
* @param {module:Key.Key} key
|
|
@@ -1426,93 +1320,73 @@
|
|
|
1426
1320
|
* @param {boolean} checkCached
|
|
1427
1321
|
* @returns {boolean}
|
|
1428
1322
|
*/
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
1323
|
function isKeyInRange(key, range, checkCached) {
|
|
1432
1324
|
var lowerMatch = range.lower === undefined;
|
|
1433
1325
|
var upperMatch = range.upper === undefined;
|
|
1434
|
-
|
|
1435
1326
|
var encodedKey = _encode(key, true);
|
|
1436
|
-
|
|
1437
1327
|
var lower = checkCached ? range.__lowerCached : _encode(range.lower, true);
|
|
1438
1328
|
var upper = checkCached ? range.__upperCached : _encode(range.upper, true);
|
|
1439
|
-
|
|
1440
1329
|
if (range.lower !== undefined) {
|
|
1441
1330
|
if (range.lowerOpen && encodedKey > lower) {
|
|
1442
1331
|
lowerMatch = true;
|
|
1443
1332
|
}
|
|
1444
|
-
|
|
1445
1333
|
if (!range.lowerOpen && encodedKey >= lower) {
|
|
1446
1334
|
lowerMatch = true;
|
|
1447
1335
|
}
|
|
1448
1336
|
}
|
|
1449
|
-
|
|
1450
1337
|
if (range.upper !== undefined) {
|
|
1451
1338
|
if (range.upperOpen && encodedKey < upper) {
|
|
1452
1339
|
upperMatch = true;
|
|
1453
1340
|
}
|
|
1454
|
-
|
|
1455
1341
|
if (!range.upperOpen && encodedKey <= upper) {
|
|
1456
1342
|
upperMatch = true;
|
|
1457
1343
|
}
|
|
1458
1344
|
}
|
|
1459
|
-
|
|
1460
1345
|
return lowerMatch && upperMatch;
|
|
1461
1346
|
}
|
|
1347
|
+
|
|
1462
1348
|
/**
|
|
1463
1349
|
* Determines whether an index entry matches a multi-entry key value.
|
|
1464
1350
|
* @param {string} encodedEntry The entry value (already encoded)
|
|
1465
1351
|
* @param {string} encodedKey The full index key (already encoded)
|
|
1466
1352
|
* @returns {boolean}
|
|
1467
1353
|
*/
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
1354
|
function isMultiEntryMatch(encodedEntry, encodedKey) {
|
|
1471
1355
|
var keyType = encodedCharToKeyType[encodedKey.slice(0, 1)];
|
|
1472
|
-
|
|
1473
1356
|
if (keyType === 'array') {
|
|
1474
1357
|
return encodedKey.indexOf(encodedEntry) > 1;
|
|
1475
1358
|
}
|
|
1476
|
-
|
|
1477
1359
|
return encodedKey === encodedEntry;
|
|
1478
1360
|
}
|
|
1361
|
+
|
|
1479
1362
|
/**
|
|
1480
1363
|
*
|
|
1481
1364
|
* @param {module:Key.Key} keyEntry
|
|
1482
1365
|
* @param {IDBKeyRange} range
|
|
1483
1366
|
* @returns {module:Key.Key[]}
|
|
1484
1367
|
*/
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
1368
|
function findMultiEntryMatches(keyEntry, range) {
|
|
1488
1369
|
var matches = [];
|
|
1489
|
-
|
|
1490
1370
|
if (Array.isArray(keyEntry)) {
|
|
1491
1371
|
var _iterator4 = _createForOfIteratorHelper(keyEntry),
|
|
1492
|
-
|
|
1493
|
-
|
|
1372
|
+
_step4;
|
|
1494
1373
|
try {
|
|
1495
1374
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
1496
1375
|
var key = _step4.value;
|
|
1497
|
-
|
|
1498
1376
|
if (Array.isArray(key)) {
|
|
1499
1377
|
if (range && range.lower === range.upper) {
|
|
1500
1378
|
continue;
|
|
1501
1379
|
}
|
|
1502
|
-
|
|
1503
1380
|
if (key.length === 1) {
|
|
1504
1381
|
key = key[0];
|
|
1505
1382
|
} else {
|
|
1506
1383
|
var nested = findMultiEntryMatches(key, range);
|
|
1507
|
-
|
|
1508
1384
|
if (nested.length > 0) {
|
|
1509
1385
|
matches.push(key);
|
|
1510
1386
|
}
|
|
1511
|
-
|
|
1512
1387
|
continue;
|
|
1513
1388
|
}
|
|
1514
1389
|
}
|
|
1515
|
-
|
|
1516
1390
|
if (isNullish(range) || isKeyInRange(key, range, true)) {
|
|
1517
1391
|
matches.push(key);
|
|
1518
1392
|
}
|
|
@@ -1525,9 +1399,9 @@
|
|
|
1525
1399
|
} else if (isNullish(range) || isKeyInRange(keyEntry, range, true)) {
|
|
1526
1400
|
matches.push(keyEntry);
|
|
1527
1401
|
}
|
|
1528
|
-
|
|
1529
1402
|
return matches;
|
|
1530
1403
|
}
|
|
1404
|
+
|
|
1531
1405
|
/**
|
|
1532
1406
|
* @typedef {number|string|Date|ArrayBuffer|module:Key.ValueTypes[]} module:Key.ValueTypes
|
|
1533
1407
|
*/
|
|
@@ -1538,71 +1412,61 @@
|
|
|
1538
1412
|
* @throws {Error} Upon a "bad key"
|
|
1539
1413
|
* @returns {module:Key.ValueTypes}
|
|
1540
1414
|
*/
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
1415
|
function convertKeyToValue(key) {
|
|
1544
1416
|
var type = key.type,
|
|
1545
|
-
|
|
1546
|
-
|
|
1417
|
+
value = key.value;
|
|
1547
1418
|
switch (type) {
|
|
1548
1419
|
case 'number':
|
|
1549
1420
|
case 'string':
|
|
1550
1421
|
{
|
|
1551
1422
|
return value;
|
|
1552
1423
|
}
|
|
1553
|
-
|
|
1554
1424
|
case 'array':
|
|
1555
1425
|
{
|
|
1556
1426
|
var array = [];
|
|
1557
1427
|
var len = value.length;
|
|
1558
1428
|
var index = 0;
|
|
1559
|
-
|
|
1560
1429
|
while (index < len) {
|
|
1561
1430
|
var entry = convertKeyToValue(value[index]);
|
|
1562
1431
|
array[index] = entry;
|
|
1563
1432
|
index++;
|
|
1564
1433
|
}
|
|
1565
|
-
|
|
1566
1434
|
return array;
|
|
1567
1435
|
}
|
|
1568
|
-
|
|
1569
1436
|
case 'date':
|
|
1570
1437
|
{
|
|
1571
1438
|
return new Date(value);
|
|
1572
1439
|
}
|
|
1573
|
-
|
|
1574
1440
|
case 'binary':
|
|
1575
1441
|
{
|
|
1576
1442
|
var _len = value.length;
|
|
1577
|
-
var buffer = new ArrayBuffer(_len);
|
|
1578
|
-
|
|
1443
|
+
var buffer = new ArrayBuffer(_len);
|
|
1444
|
+
// Set the entries in buffer's [[ArrayBufferData]] to those in `value`
|
|
1579
1445
|
var uint8 = new Uint8Array(buffer, value.byteOffset || 0, value.byteLength);
|
|
1580
1446
|
uint8.set(value);
|
|
1581
1447
|
return buffer;
|
|
1582
1448
|
}
|
|
1583
|
-
|
|
1584
1449
|
case 'invalid':
|
|
1585
1450
|
default:
|
|
1586
1451
|
throw new Error('Bad key');
|
|
1587
1452
|
}
|
|
1588
1453
|
}
|
|
1454
|
+
|
|
1589
1455
|
/**
|
|
1590
1456
|
*
|
|
1591
1457
|
* @param {module:Key.Key} key
|
|
1592
1458
|
* @param {boolean} inArray
|
|
1593
1459
|
* @returns {string|null}
|
|
1594
1460
|
*/
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
1461
|
function _encode(key, inArray) {
|
|
1598
1462
|
// Bad keys like `null`, `object`, `boolean`, 'function', 'symbol' should not be passed here due to prior validation
|
|
1599
1463
|
if (key === undefined) {
|
|
1600
1464
|
return null;
|
|
1601
|
-
}
|
|
1602
|
-
|
|
1603
|
-
|
|
1465
|
+
}
|
|
1466
|
+
// array, date, number, string, binary (should already have detected "invalid")
|
|
1604
1467
|
return types[getKeyType(key)].encode(key, inArray);
|
|
1605
1468
|
}
|
|
1469
|
+
|
|
1606
1470
|
/**
|
|
1607
1471
|
*
|
|
1608
1472
|
* @param {module:Key.Key} key
|
|
@@ -1610,27 +1474,22 @@
|
|
|
1610
1474
|
* @throws {Error} Invalid number
|
|
1611
1475
|
* @returns {undefined|module:Key.ValueTypes}
|
|
1612
1476
|
*/
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
1477
|
function _decode(key, inArray) {
|
|
1616
1478
|
if (typeof key !== 'string') {
|
|
1617
1479
|
return undefined;
|
|
1618
1480
|
}
|
|
1619
|
-
|
|
1620
1481
|
return types[encodedCharToKeyType[key.slice(0, 1)]].decode(key, inArray);
|
|
1621
1482
|
}
|
|
1483
|
+
|
|
1622
1484
|
/**
|
|
1623
1485
|
*
|
|
1624
1486
|
* @param {module:Key.Key} key
|
|
1625
1487
|
* @param {boolean} inArray
|
|
1626
1488
|
* @returns {undefined|module:Key.ValueTypes}
|
|
1627
1489
|
*/
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
1490
|
function roundTrip(key, inArray) {
|
|
1631
1491
|
return _decode(_encode(key, inArray), inArray);
|
|
1632
1492
|
}
|
|
1633
|
-
|
|
1634
1493
|
var MAX_ALLOWED_CURRENT_NUMBER = 9007199254740992; // 2 ^ 53 (Also equal to `Number.MAX_SAFE_INTEGER + 1`)
|
|
1635
1494
|
|
|
1636
1495
|
/**
|
|
@@ -1662,7 +1521,6 @@
|
|
|
1662
1521
|
* @param {SQLFailureCallback} sqlFailCb
|
|
1663
1522
|
* @returns {void}
|
|
1664
1523
|
*/
|
|
1665
|
-
|
|
1666
1524
|
function getCurrentNumber(tx, store, func, sqlFailCb) {
|
|
1667
1525
|
tx.executeSql('SELECT "currNum" FROM __sys__ WHERE "name" = ?', [escapeSQLiteStatement(store.__currentName)], function (tx, data) {
|
|
1668
1526
|
if (data.rows.length !== 1) {
|
|
@@ -1674,6 +1532,7 @@
|
|
|
1674
1532
|
sqlFailCb(createDOMException('DataError', 'Could not get the auto increment value for key', error));
|
|
1675
1533
|
});
|
|
1676
1534
|
}
|
|
1535
|
+
|
|
1677
1536
|
/**
|
|
1678
1537
|
*
|
|
1679
1538
|
* @param {external:WebSQLTransaction} tx
|
|
@@ -1683,8 +1542,6 @@
|
|
|
1683
1542
|
* @param {SQLFailureCallback} failCb
|
|
1684
1543
|
* @returns {void}
|
|
1685
1544
|
*/
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
1545
|
function assignCurrentNumber(tx, store, num, successCb, failCb) {
|
|
1689
1546
|
var sql = 'UPDATE __sys__ SET "currNum" = ? WHERE "name" = ?';
|
|
1690
1547
|
var sqlValues = [num, escapeSQLiteStatement(store.__currentName)];
|
|
@@ -1695,6 +1552,7 @@
|
|
|
1695
1552
|
failCb(createDOMException('UnknownError', 'Could not set the auto increment value for key', err));
|
|
1696
1553
|
});
|
|
1697
1554
|
}
|
|
1555
|
+
|
|
1698
1556
|
/**
|
|
1699
1557
|
* Bump up the auto-inc counter if the key path-resolved value is valid
|
|
1700
1558
|
* (greater than old value and >=1) OR if a manually passed in key is
|
|
@@ -1706,13 +1564,12 @@
|
|
|
1706
1564
|
* @param {SQLFailureCallback} failCb
|
|
1707
1565
|
* @returns {void}
|
|
1708
1566
|
*/
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
1567
|
function setCurrentNumber(tx, store, num, successCb, failCb) {
|
|
1712
1568
|
num = num === MAX_ALLOWED_CURRENT_NUMBER ? num + 2 // Since incrementing by one will have no effect in JavaScript on this unsafe max, we represent the max as a number incremented by two. The getting of the current number is never returned to the user and is only used in safe comparisons, so it is safe for us to represent it in this manner
|
|
1713
1569
|
: num + 1;
|
|
1714
1570
|
return assignCurrentNumber(tx, store, num, successCb, failCb);
|
|
1715
1571
|
}
|
|
1572
|
+
|
|
1716
1573
|
/**
|
|
1717
1574
|
* @callback KeyForStoreCallback
|
|
1718
1575
|
* @param {"failure"|null} arg1
|
|
@@ -1729,28 +1586,25 @@
|
|
|
1729
1586
|
* @param {SQLFailureCallback} sqlFailCb
|
|
1730
1587
|
* @returns {void}
|
|
1731
1588
|
*/
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
1589
|
function generateKeyForStore(tx, store, cb, sqlFailCb) {
|
|
1735
1590
|
getCurrentNumber(tx, store, function (key) {
|
|
1736
1591
|
if (key > MAX_ALLOWED_CURRENT_NUMBER) {
|
|
1737
1592
|
// 2 ^ 53 (See <https://github.com/w3c/IndexedDB/issues/147>)
|
|
1738
|
-
cb('failure'); // eslint-disable-line
|
|
1739
|
-
|
|
1593
|
+
cb('failure'); // eslint-disable-line n/no-callback-literal
|
|
1740
1594
|
return;
|
|
1741
|
-
}
|
|
1595
|
+
}
|
|
1596
|
+
// Increment current number by 1 (we cannot leverage SQLite's
|
|
1742
1597
|
// autoincrement (and decrement when not needed), as decrementing
|
|
1743
1598
|
// will be overwritten/ignored upon the next insert)
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
1599
|
setCurrentNumber(tx, store, key, function () {
|
|
1747
1600
|
cb(null, key, key);
|
|
1748
1601
|
}, sqlFailCb);
|
|
1749
1602
|
}, sqlFailCb);
|
|
1750
|
-
}
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
// Fractional or numbers exceeding the max do not get changed in the result
|
|
1751
1606
|
// per https://github.com/w3c/IndexedDB/issues/147
|
|
1752
1607
|
// so we do not return a key
|
|
1753
|
-
|
|
1754
1608
|
/**
|
|
1755
1609
|
*
|
|
1756
1610
|
* @param {external:WebSQLTransaction} tx
|
|
@@ -1760,8 +1614,6 @@
|
|
|
1760
1614
|
* @param {SQLFailureCallback} sqlFailCb
|
|
1761
1615
|
* @returns {void}
|
|
1762
1616
|
*/
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
1617
|
function possiblyUpdateKeyGenerator(tx, store, key, successCb, sqlFailCb) {
|
|
1766
1618
|
// Per https://github.com/w3c/IndexedDB/issues/147 , non-finite numbers
|
|
1767
1619
|
// (or numbers larger than the max) are now to have the explicit effect of
|
|
@@ -1779,7 +1631,6 @@
|
|
|
1779
1631
|
getCurrentNumber(tx, store, function (cn) {
|
|
1780
1632
|
var value = Math.floor(Math.min(key, MAX_ALLOWED_CURRENT_NUMBER));
|
|
1781
1633
|
var useNewKeyForAutoInc = value >= cn;
|
|
1782
|
-
|
|
1783
1634
|
if (useNewKeyForAutoInc) {
|
|
1784
1635
|
setCurrentNumber(tx, store, value, function () {
|
|
1785
1636
|
successCb(cn); // Supply old current number in case needs to be reverted
|
|
@@ -1813,7 +1664,5 @@
|
|
|
1813
1664
|
exports.possiblyUpdateKeyGenerator = possiblyUpdateKeyGenerator;
|
|
1814
1665
|
exports.roundTrip = roundTrip;
|
|
1815
1666
|
|
|
1816
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1817
|
-
|
|
1818
1667
|
}));
|
|
1819
1668
|
//# sourceMappingURL=indexeddbshim-Key.js.map
|