indexeddbshim 9.0.0 → 10.1.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 +183 -337
- 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 +1670 -4969
- package/dist/indexeddbshim-UnicodeIdentifiers-node.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.js +2222 -4947
- package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js +5 -15
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
- package/dist/indexeddbshim-node.js +1637 -4935
- package/dist/indexeddbshim-node.js.map +1 -1
- package/dist/indexeddbshim-noninvasive.js +2227 -4951
- package/dist/indexeddbshim-noninvasive.js.map +1 -1
- package/dist/indexeddbshim-noninvasive.min.js +5 -15
- package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
- package/dist/indexeddbshim.js +2229 -4955
- package/dist/indexeddbshim.js.map +1 -1
- package/dist/indexeddbshim.min.js +5 -15
- package/dist/indexeddbshim.min.js.map +1 -1
- package/package.json +46 -46
- package/src/IDBFactory.js +1 -3
- package/src/Key.js +1 -1
- package/src/Sca.js +8 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! indexeddbshim -
|
|
1
|
+
/*! indexeddbshim - v10.0.0 - 12/8/2022 */
|
|
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,14 +1024,12 @@
|
|
|
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
1033
|
for (var i = 0; i < len; i++) {
|
|
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)) {
|
|
@@ -1110,17 +1039,14 @@
|
|
|
1110
1039
|
message: 'Does not have own index property'
|
|
1111
1040
|
};
|
|
1112
1041
|
}
|
|
1113
|
-
|
|
1114
1042
|
try {
|
|
1115
1043
|
var _ret = function () {
|
|
1116
1044
|
var entry = input[i];
|
|
1117
1045
|
var key = convertValueToKeyValueDecoded(entry, seen, false, fullKeys); // Though steps do not list rethrowing, the next is returnifabrupt when not multiEntry
|
|
1118
|
-
|
|
1119
1046
|
if (key.invalid) {
|
|
1120
1047
|
if (multiEntry) {
|
|
1121
1048
|
return "continue";
|
|
1122
1049
|
}
|
|
1123
|
-
|
|
1124
1050
|
return {
|
|
1125
1051
|
v: {
|
|
1126
1052
|
type: type,
|
|
@@ -1129,7 +1055,6 @@
|
|
|
1129
1055
|
}
|
|
1130
1056
|
};
|
|
1131
1057
|
}
|
|
1132
|
-
|
|
1133
1058
|
if (!multiEntry || !fullKeys && keys.every(function (k) {
|
|
1134
1059
|
return cmp(k, key.value) !== 0;
|
|
1135
1060
|
}) || fullKeys && keys.every(function (k) {
|
|
@@ -1138,7 +1063,6 @@
|
|
|
1138
1063
|
keys.push(fullKeys ? key : key.value);
|
|
1139
1064
|
}
|
|
1140
1065
|
}();
|
|
1141
|
-
|
|
1142
1066
|
if (_ret === "continue") continue;
|
|
1143
1067
|
if (_typeof(_ret) === "object") return _ret.v;
|
|
1144
1068
|
} catch (err) {
|
|
@@ -1147,13 +1071,11 @@
|
|
|
1147
1071
|
}
|
|
1148
1072
|
}
|
|
1149
1073
|
}
|
|
1150
|
-
|
|
1151
1074
|
return {
|
|
1152
1075
|
type: type,
|
|
1153
1076
|
value: keys
|
|
1154
1077
|
};
|
|
1155
1078
|
}
|
|
1156
|
-
|
|
1157
1079
|
case 'date':
|
|
1158
1080
|
{
|
|
1159
1081
|
if (!Number.isNaN(input.getTime())) {
|
|
@@ -1165,22 +1087,19 @@
|
|
|
1165
1087
|
value: new Date(input.getTime())
|
|
1166
1088
|
};
|
|
1167
1089
|
}
|
|
1168
|
-
|
|
1169
1090
|
return {
|
|
1170
1091
|
type: type,
|
|
1171
1092
|
invalid: true,
|
|
1172
1093
|
message: 'Not a valid date'
|
|
1173
|
-
};
|
|
1094
|
+
};
|
|
1095
|
+
// Falls through
|
|
1174
1096
|
}
|
|
1175
|
-
|
|
1176
1097
|
case 'invalid':
|
|
1177
1098
|
default:
|
|
1178
1099
|
{
|
|
1179
1100
|
// Other `typeof` types which are not valid keys:
|
|
1180
1101
|
// 'undefined', 'boolean', 'object' (including `null`), 'symbol', 'function
|
|
1181
1102
|
var _type = input === null ? 'null' : _typeof(input); // Convert `null` for convenience of consumers in reporting errors
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
1103
|
return {
|
|
1185
1104
|
type: _type,
|
|
1186
1105
|
invalid: true,
|
|
@@ -1189,6 +1108,7 @@
|
|
|
1189
1108
|
}
|
|
1190
1109
|
}
|
|
1191
1110
|
}
|
|
1111
|
+
|
|
1192
1112
|
/**
|
|
1193
1113
|
* @typedef {*} module:Key.Key
|
|
1194
1114
|
* @todo Specify possible value more precisely
|
|
@@ -1201,11 +1121,10 @@
|
|
|
1201
1121
|
* @returns {module:Key.keyValueObject}
|
|
1202
1122
|
* @todo Document other allowable `key`?
|
|
1203
1123
|
*/
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
1124
|
function convertValueToMultiEntryKeyDecoded(key, fullKeys) {
|
|
1207
1125
|
return convertValueToKeyValueDecoded(key, null, true, fullKeys);
|
|
1208
1126
|
}
|
|
1127
|
+
|
|
1209
1128
|
/**
|
|
1210
1129
|
* An internal utility.
|
|
1211
1130
|
* @param input
|
|
@@ -1213,17 +1132,14 @@
|
|
|
1213
1132
|
* @throws {DOMException} `DataError`
|
|
1214
1133
|
* @returns {module:Key.keyValueObject}
|
|
1215
1134
|
*/
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
1135
|
function convertValueToKeyRethrowingAndIfInvalid(input, seen) {
|
|
1219
1136
|
var key = convertValueToKey(input, seen);
|
|
1220
|
-
|
|
1221
1137
|
if (key.invalid) {
|
|
1222
1138
|
throw createDOMException('DataError', key.message || 'Not a valid key; type: ' + key.type);
|
|
1223
1139
|
}
|
|
1224
|
-
|
|
1225
1140
|
return key;
|
|
1226
1141
|
}
|
|
1142
|
+
|
|
1227
1143
|
/**
|
|
1228
1144
|
*
|
|
1229
1145
|
* @param value
|
|
@@ -1232,8 +1148,6 @@
|
|
|
1232
1148
|
* @returns {module:Key.keyValueObject|module:Key.KeyPathEvaluateValue}
|
|
1233
1149
|
* @todo Document other possible return?
|
|
1234
1150
|
*/
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
1151
|
function extractKeyFromValueUsingKeyPath(value, keyPath, multiEntry) {
|
|
1238
1152
|
return extractKeyValueDecodedFromValueUsingKeyPath(value, keyPath, multiEntry, true);
|
|
1239
1153
|
}
|
|
@@ -1244,11 +1158,10 @@
|
|
|
1244
1158
|
* @param {boolean} multiEntry
|
|
1245
1159
|
* @returns {module:Key.KeyPathEvaluateValue}
|
|
1246
1160
|
*/
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
1161
|
function evaluateKeyPathOnValue(value, keyPath, multiEntry) {
|
|
1250
1162
|
return evaluateKeyPathOnValueToDecodedValue(value, keyPath);
|
|
1251
1163
|
}
|
|
1164
|
+
|
|
1252
1165
|
/**
|
|
1253
1166
|
* May throw, return `{failure: true}` (e.g., non-object on keyPath resolution)
|
|
1254
1167
|
* or `{invalid: true}` (e.g., `NaN`).
|
|
@@ -1259,21 +1172,17 @@
|
|
|
1259
1172
|
* @returns {module:Key.keyValueObject|module:Key.KeyPathEvaluateValue}
|
|
1260
1173
|
* @todo Document other possible return?
|
|
1261
1174
|
*/
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
1175
|
function extractKeyValueDecodedFromValueUsingKeyPath(value, keyPath, multiEntry, fullKeys) {
|
|
1265
1176
|
var r = evaluateKeyPathOnValueToDecodedValue(value, keyPath);
|
|
1266
|
-
|
|
1267
1177
|
if (r.failure) {
|
|
1268
1178
|
return r;
|
|
1269
1179
|
}
|
|
1270
|
-
|
|
1271
1180
|
if (!multiEntry) {
|
|
1272
1181
|
return convertValueToKeyValueDecoded(r.value, null, false, fullKeys);
|
|
1273
1182
|
}
|
|
1274
|
-
|
|
1275
1183
|
return convertValueToMultiEntryKeyDecoded(r.value, fullKeys);
|
|
1276
1184
|
}
|
|
1185
|
+
|
|
1277
1186
|
/**
|
|
1278
1187
|
* @typedef {PlainObject} module:Key.KeyPathEvaluateFailure
|
|
1279
1188
|
* @property {boolean} failure
|
|
@@ -1293,18 +1202,14 @@
|
|
|
1293
1202
|
* @param {boolean} [fullKeys]
|
|
1294
1203
|
* @returns {module:Key.KeyPathEvaluateValue}
|
|
1295
1204
|
*/
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
1205
|
function evaluateKeyPathOnValueToDecodedValue(value, keyPath, multiEntry, fullKeys) {
|
|
1299
1206
|
if (Array.isArray(keyPath)) {
|
|
1300
1207
|
var result = [];
|
|
1301
1208
|
return keyPath.some(function (item) {
|
|
1302
1209
|
var key = evaluateKeyPathOnValueToDecodedValue(value, item);
|
|
1303
|
-
|
|
1304
1210
|
if (key.failure) {
|
|
1305
1211
|
return true;
|
|
1306
1212
|
}
|
|
1307
|
-
|
|
1308
1213
|
result.push(key.value);
|
|
1309
1214
|
return false;
|
|
1310
1215
|
}) ? {
|
|
@@ -1313,13 +1218,11 @@
|
|
|
1313
1218
|
value: result
|
|
1314
1219
|
};
|
|
1315
1220
|
}
|
|
1316
|
-
|
|
1317
1221
|
if (keyPath === '') {
|
|
1318
1222
|
return {
|
|
1319
1223
|
value: value
|
|
1320
1224
|
};
|
|
1321
1225
|
}
|
|
1322
|
-
|
|
1323
1226
|
var identifiers = keyPath.split('.');
|
|
1324
1227
|
return identifiers.some(function (idntfr, i) {
|
|
1325
1228
|
if (idntfr === 'length' && (typeof value === 'string' || Array.isArray(value))) {
|
|
@@ -1337,7 +1240,6 @@
|
|
|
1337
1240
|
case 'lastModified':
|
|
1338
1241
|
value = value[idntfr];
|
|
1339
1242
|
break;
|
|
1340
|
-
|
|
1341
1243
|
case 'lastModifiedDate':
|
|
1342
1244
|
value = new Date(value.lastModified);
|
|
1343
1245
|
break;
|
|
@@ -1348,7 +1250,6 @@
|
|
|
1348
1250
|
value = value[idntfr];
|
|
1349
1251
|
return value === undefined;
|
|
1350
1252
|
}
|
|
1351
|
-
|
|
1352
1253
|
return false;
|
|
1353
1254
|
}) ? {
|
|
1354
1255
|
failure: true
|
|
@@ -1356,6 +1257,7 @@
|
|
|
1356
1257
|
value: value
|
|
1357
1258
|
};
|
|
1358
1259
|
}
|
|
1260
|
+
|
|
1359
1261
|
/**
|
|
1360
1262
|
* Sets the inline key value.
|
|
1361
1263
|
* @param {object} value
|
|
@@ -1363,22 +1265,19 @@
|
|
|
1363
1265
|
* @param {string} keyPath
|
|
1364
1266
|
* @returns {void}
|
|
1365
1267
|
*/
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
1268
|
function injectKeyIntoValueUsingKeyPath(value, key, keyPath) {
|
|
1369
1269
|
var identifiers = keyPath.split('.');
|
|
1370
1270
|
var last = identifiers.pop();
|
|
1371
1271
|
identifiers.forEach(function (identifier) {
|
|
1372
1272
|
var hop = Object.prototype.hasOwnProperty.call(value, identifier);
|
|
1373
|
-
|
|
1374
1273
|
if (!hop) {
|
|
1375
1274
|
value[identifier] = {};
|
|
1376
1275
|
}
|
|
1377
|
-
|
|
1378
1276
|
value = value[identifier];
|
|
1379
1277
|
});
|
|
1380
1278
|
value[last] = key; // key is already a `keyValue` in our processing so no need to convert
|
|
1381
1279
|
}
|
|
1280
|
+
|
|
1382
1281
|
/**
|
|
1383
1282
|
*
|
|
1384
1283
|
* @param value
|
|
@@ -1386,29 +1285,21 @@
|
|
|
1386
1285
|
* @see https://github.com/w3c/IndexedDB/pull/146
|
|
1387
1286
|
* @returns {boolean}
|
|
1388
1287
|
*/
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
1288
|
function checkKeyCouldBeInjectedIntoValue(value, keyPath) {
|
|
1392
1289
|
var identifiers = keyPath.split('.');
|
|
1393
1290
|
identifiers.pop();
|
|
1394
|
-
|
|
1395
1291
|
var _iterator3 = _createForOfIteratorHelper(identifiers),
|
|
1396
|
-
|
|
1397
|
-
|
|
1292
|
+
_step3;
|
|
1398
1293
|
try {
|
|
1399
1294
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
1400
1295
|
var identifier = _step3.value;
|
|
1401
|
-
|
|
1402
1296
|
if (!isObj(value)) {
|
|
1403
1297
|
return false;
|
|
1404
1298
|
}
|
|
1405
|
-
|
|
1406
1299
|
var hop = Object.prototype.hasOwnProperty.call(value, identifier);
|
|
1407
|
-
|
|
1408
1300
|
if (!hop) {
|
|
1409
1301
|
return true;
|
|
1410
1302
|
}
|
|
1411
|
-
|
|
1412
1303
|
value = value[identifier];
|
|
1413
1304
|
}
|
|
1414
1305
|
} catch (err) {
|
|
@@ -1416,9 +1307,9 @@
|
|
|
1416
1307
|
} finally {
|
|
1417
1308
|
_iterator3.f();
|
|
1418
1309
|
}
|
|
1419
|
-
|
|
1420
1310
|
return isObj(value);
|
|
1421
1311
|
}
|
|
1312
|
+
|
|
1422
1313
|
/**
|
|
1423
1314
|
*
|
|
1424
1315
|
* @param {module:Key.Key} key
|
|
@@ -1426,93 +1317,73 @@
|
|
|
1426
1317
|
* @param {boolean} checkCached
|
|
1427
1318
|
* @returns {boolean}
|
|
1428
1319
|
*/
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
1320
|
function isKeyInRange(key, range, checkCached) {
|
|
1432
1321
|
var lowerMatch = range.lower === undefined;
|
|
1433
1322
|
var upperMatch = range.upper === undefined;
|
|
1434
|
-
|
|
1435
1323
|
var encodedKey = _encode(key, true);
|
|
1436
|
-
|
|
1437
1324
|
var lower = checkCached ? range.__lowerCached : _encode(range.lower, true);
|
|
1438
1325
|
var upper = checkCached ? range.__upperCached : _encode(range.upper, true);
|
|
1439
|
-
|
|
1440
1326
|
if (range.lower !== undefined) {
|
|
1441
1327
|
if (range.lowerOpen && encodedKey > lower) {
|
|
1442
1328
|
lowerMatch = true;
|
|
1443
1329
|
}
|
|
1444
|
-
|
|
1445
1330
|
if (!range.lowerOpen && encodedKey >= lower) {
|
|
1446
1331
|
lowerMatch = true;
|
|
1447
1332
|
}
|
|
1448
1333
|
}
|
|
1449
|
-
|
|
1450
1334
|
if (range.upper !== undefined) {
|
|
1451
1335
|
if (range.upperOpen && encodedKey < upper) {
|
|
1452
1336
|
upperMatch = true;
|
|
1453
1337
|
}
|
|
1454
|
-
|
|
1455
1338
|
if (!range.upperOpen && encodedKey <= upper) {
|
|
1456
1339
|
upperMatch = true;
|
|
1457
1340
|
}
|
|
1458
1341
|
}
|
|
1459
|
-
|
|
1460
1342
|
return lowerMatch && upperMatch;
|
|
1461
1343
|
}
|
|
1344
|
+
|
|
1462
1345
|
/**
|
|
1463
1346
|
* Determines whether an index entry matches a multi-entry key value.
|
|
1464
1347
|
* @param {string} encodedEntry The entry value (already encoded)
|
|
1465
1348
|
* @param {string} encodedKey The full index key (already encoded)
|
|
1466
1349
|
* @returns {boolean}
|
|
1467
1350
|
*/
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
1351
|
function isMultiEntryMatch(encodedEntry, encodedKey) {
|
|
1471
1352
|
var keyType = encodedCharToKeyType[encodedKey.slice(0, 1)];
|
|
1472
|
-
|
|
1473
1353
|
if (keyType === 'array') {
|
|
1474
1354
|
return encodedKey.indexOf(encodedEntry) > 1;
|
|
1475
1355
|
}
|
|
1476
|
-
|
|
1477
1356
|
return encodedKey === encodedEntry;
|
|
1478
1357
|
}
|
|
1358
|
+
|
|
1479
1359
|
/**
|
|
1480
1360
|
*
|
|
1481
1361
|
* @param {module:Key.Key} keyEntry
|
|
1482
1362
|
* @param {IDBKeyRange} range
|
|
1483
1363
|
* @returns {module:Key.Key[]}
|
|
1484
1364
|
*/
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
1365
|
function findMultiEntryMatches(keyEntry, range) {
|
|
1488
1366
|
var matches = [];
|
|
1489
|
-
|
|
1490
1367
|
if (Array.isArray(keyEntry)) {
|
|
1491
1368
|
var _iterator4 = _createForOfIteratorHelper(keyEntry),
|
|
1492
|
-
|
|
1493
|
-
|
|
1369
|
+
_step4;
|
|
1494
1370
|
try {
|
|
1495
1371
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
1496
1372
|
var key = _step4.value;
|
|
1497
|
-
|
|
1498
1373
|
if (Array.isArray(key)) {
|
|
1499
1374
|
if (range && range.lower === range.upper) {
|
|
1500
1375
|
continue;
|
|
1501
1376
|
}
|
|
1502
|
-
|
|
1503
1377
|
if (key.length === 1) {
|
|
1504
1378
|
key = key[0];
|
|
1505
1379
|
} else {
|
|
1506
1380
|
var nested = findMultiEntryMatches(key, range);
|
|
1507
|
-
|
|
1508
1381
|
if (nested.length > 0) {
|
|
1509
1382
|
matches.push(key);
|
|
1510
1383
|
}
|
|
1511
|
-
|
|
1512
1384
|
continue;
|
|
1513
1385
|
}
|
|
1514
1386
|
}
|
|
1515
|
-
|
|
1516
1387
|
if (isNullish(range) || isKeyInRange(key, range, true)) {
|
|
1517
1388
|
matches.push(key);
|
|
1518
1389
|
}
|
|
@@ -1525,9 +1396,9 @@
|
|
|
1525
1396
|
} else if (isNullish(range) || isKeyInRange(keyEntry, range, true)) {
|
|
1526
1397
|
matches.push(keyEntry);
|
|
1527
1398
|
}
|
|
1528
|
-
|
|
1529
1399
|
return matches;
|
|
1530
1400
|
}
|
|
1401
|
+
|
|
1531
1402
|
/**
|
|
1532
1403
|
* @typedef {number|string|Date|ArrayBuffer|module:Key.ValueTypes[]} module:Key.ValueTypes
|
|
1533
1404
|
*/
|
|
@@ -1538,71 +1409,61 @@
|
|
|
1538
1409
|
* @throws {Error} Upon a "bad key"
|
|
1539
1410
|
* @returns {module:Key.ValueTypes}
|
|
1540
1411
|
*/
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
1412
|
function convertKeyToValue(key) {
|
|
1544
1413
|
var type = key.type,
|
|
1545
|
-
|
|
1546
|
-
|
|
1414
|
+
value = key.value;
|
|
1547
1415
|
switch (type) {
|
|
1548
1416
|
case 'number':
|
|
1549
1417
|
case 'string':
|
|
1550
1418
|
{
|
|
1551
1419
|
return value;
|
|
1552
1420
|
}
|
|
1553
|
-
|
|
1554
1421
|
case 'array':
|
|
1555
1422
|
{
|
|
1556
1423
|
var array = [];
|
|
1557
1424
|
var len = value.length;
|
|
1558
1425
|
var index = 0;
|
|
1559
|
-
|
|
1560
1426
|
while (index < len) {
|
|
1561
1427
|
var entry = convertKeyToValue(value[index]);
|
|
1562
1428
|
array[index] = entry;
|
|
1563
1429
|
index++;
|
|
1564
1430
|
}
|
|
1565
|
-
|
|
1566
1431
|
return array;
|
|
1567
1432
|
}
|
|
1568
|
-
|
|
1569
1433
|
case 'date':
|
|
1570
1434
|
{
|
|
1571
1435
|
return new Date(value);
|
|
1572
1436
|
}
|
|
1573
|
-
|
|
1574
1437
|
case 'binary':
|
|
1575
1438
|
{
|
|
1576
1439
|
var _len = value.length;
|
|
1577
|
-
var buffer = new ArrayBuffer(_len);
|
|
1578
|
-
|
|
1440
|
+
var buffer = new ArrayBuffer(_len);
|
|
1441
|
+
// Set the entries in buffer's [[ArrayBufferData]] to those in `value`
|
|
1579
1442
|
var uint8 = new Uint8Array(buffer, value.byteOffset || 0, value.byteLength);
|
|
1580
1443
|
uint8.set(value);
|
|
1581
1444
|
return buffer;
|
|
1582
1445
|
}
|
|
1583
|
-
|
|
1584
1446
|
case 'invalid':
|
|
1585
1447
|
default:
|
|
1586
1448
|
throw new Error('Bad key');
|
|
1587
1449
|
}
|
|
1588
1450
|
}
|
|
1451
|
+
|
|
1589
1452
|
/**
|
|
1590
1453
|
*
|
|
1591
1454
|
* @param {module:Key.Key} key
|
|
1592
1455
|
* @param {boolean} inArray
|
|
1593
1456
|
* @returns {string|null}
|
|
1594
1457
|
*/
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
1458
|
function _encode(key, inArray) {
|
|
1598
1459
|
// Bad keys like `null`, `object`, `boolean`, 'function', 'symbol' should not be passed here due to prior validation
|
|
1599
1460
|
if (key === undefined) {
|
|
1600
1461
|
return null;
|
|
1601
|
-
}
|
|
1602
|
-
|
|
1603
|
-
|
|
1462
|
+
}
|
|
1463
|
+
// array, date, number, string, binary (should already have detected "invalid")
|
|
1604
1464
|
return types[getKeyType(key)].encode(key, inArray);
|
|
1605
1465
|
}
|
|
1466
|
+
|
|
1606
1467
|
/**
|
|
1607
1468
|
*
|
|
1608
1469
|
* @param {module:Key.Key} key
|
|
@@ -1610,27 +1471,22 @@
|
|
|
1610
1471
|
* @throws {Error} Invalid number
|
|
1611
1472
|
* @returns {undefined|module:Key.ValueTypes}
|
|
1612
1473
|
*/
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
1474
|
function _decode(key, inArray) {
|
|
1616
1475
|
if (typeof key !== 'string') {
|
|
1617
1476
|
return undefined;
|
|
1618
1477
|
}
|
|
1619
|
-
|
|
1620
1478
|
return types[encodedCharToKeyType[key.slice(0, 1)]].decode(key, inArray);
|
|
1621
1479
|
}
|
|
1480
|
+
|
|
1622
1481
|
/**
|
|
1623
1482
|
*
|
|
1624
1483
|
* @param {module:Key.Key} key
|
|
1625
1484
|
* @param {boolean} inArray
|
|
1626
1485
|
* @returns {undefined|module:Key.ValueTypes}
|
|
1627
1486
|
*/
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
1487
|
function roundTrip(key, inArray) {
|
|
1631
1488
|
return _decode(_encode(key, inArray), inArray);
|
|
1632
1489
|
}
|
|
1633
|
-
|
|
1634
1490
|
var MAX_ALLOWED_CURRENT_NUMBER = 9007199254740992; // 2 ^ 53 (Also equal to `Number.MAX_SAFE_INTEGER + 1`)
|
|
1635
1491
|
|
|
1636
1492
|
/**
|
|
@@ -1662,7 +1518,6 @@
|
|
|
1662
1518
|
* @param {SQLFailureCallback} sqlFailCb
|
|
1663
1519
|
* @returns {void}
|
|
1664
1520
|
*/
|
|
1665
|
-
|
|
1666
1521
|
function getCurrentNumber(tx, store, func, sqlFailCb) {
|
|
1667
1522
|
tx.executeSql('SELECT "currNum" FROM __sys__ WHERE "name" = ?', [escapeSQLiteStatement(store.__currentName)], function (tx, data) {
|
|
1668
1523
|
if (data.rows.length !== 1) {
|
|
@@ -1674,6 +1529,7 @@
|
|
|
1674
1529
|
sqlFailCb(createDOMException('DataError', 'Could not get the auto increment value for key', error));
|
|
1675
1530
|
});
|
|
1676
1531
|
}
|
|
1532
|
+
|
|
1677
1533
|
/**
|
|
1678
1534
|
*
|
|
1679
1535
|
* @param {external:WebSQLTransaction} tx
|
|
@@ -1683,8 +1539,6 @@
|
|
|
1683
1539
|
* @param {SQLFailureCallback} failCb
|
|
1684
1540
|
* @returns {void}
|
|
1685
1541
|
*/
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
1542
|
function assignCurrentNumber(tx, store, num, successCb, failCb) {
|
|
1689
1543
|
var sql = 'UPDATE __sys__ SET "currNum" = ? WHERE "name" = ?';
|
|
1690
1544
|
var sqlValues = [num, escapeSQLiteStatement(store.__currentName)];
|
|
@@ -1695,6 +1549,7 @@
|
|
|
1695
1549
|
failCb(createDOMException('UnknownError', 'Could not set the auto increment value for key', err));
|
|
1696
1550
|
});
|
|
1697
1551
|
}
|
|
1552
|
+
|
|
1698
1553
|
/**
|
|
1699
1554
|
* Bump up the auto-inc counter if the key path-resolved value is valid
|
|
1700
1555
|
* (greater than old value and >=1) OR if a manually passed in key is
|
|
@@ -1706,13 +1561,12 @@
|
|
|
1706
1561
|
* @param {SQLFailureCallback} failCb
|
|
1707
1562
|
* @returns {void}
|
|
1708
1563
|
*/
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
1564
|
function setCurrentNumber(tx, store, num, successCb, failCb) {
|
|
1712
1565
|
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
1566
|
: num + 1;
|
|
1714
1567
|
return assignCurrentNumber(tx, store, num, successCb, failCb);
|
|
1715
1568
|
}
|
|
1569
|
+
|
|
1716
1570
|
/**
|
|
1717
1571
|
* @callback KeyForStoreCallback
|
|
1718
1572
|
* @param {"failure"|null} arg1
|
|
@@ -1729,28 +1583,25 @@
|
|
|
1729
1583
|
* @param {SQLFailureCallback} sqlFailCb
|
|
1730
1584
|
* @returns {void}
|
|
1731
1585
|
*/
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
1586
|
function generateKeyForStore(tx, store, cb, sqlFailCb) {
|
|
1735
1587
|
getCurrentNumber(tx, store, function (key) {
|
|
1736
1588
|
if (key > MAX_ALLOWED_CURRENT_NUMBER) {
|
|
1737
1589
|
// 2 ^ 53 (See <https://github.com/w3c/IndexedDB/issues/147>)
|
|
1738
|
-
cb('failure'); // eslint-disable-line
|
|
1739
|
-
|
|
1590
|
+
cb('failure'); // eslint-disable-line n/no-callback-literal
|
|
1740
1591
|
return;
|
|
1741
|
-
}
|
|
1592
|
+
}
|
|
1593
|
+
// Increment current number by 1 (we cannot leverage SQLite's
|
|
1742
1594
|
// autoincrement (and decrement when not needed), as decrementing
|
|
1743
1595
|
// will be overwritten/ignored upon the next insert)
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
1596
|
setCurrentNumber(tx, store, key, function () {
|
|
1747
1597
|
cb(null, key, key);
|
|
1748
1598
|
}, sqlFailCb);
|
|
1749
1599
|
}, sqlFailCb);
|
|
1750
|
-
}
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
// Fractional or numbers exceeding the max do not get changed in the result
|
|
1751
1603
|
// per https://github.com/w3c/IndexedDB/issues/147
|
|
1752
1604
|
// so we do not return a key
|
|
1753
|
-
|
|
1754
1605
|
/**
|
|
1755
1606
|
*
|
|
1756
1607
|
* @param {external:WebSQLTransaction} tx
|
|
@@ -1760,8 +1611,6 @@
|
|
|
1760
1611
|
* @param {SQLFailureCallback} sqlFailCb
|
|
1761
1612
|
* @returns {void}
|
|
1762
1613
|
*/
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
1614
|
function possiblyUpdateKeyGenerator(tx, store, key, successCb, sqlFailCb) {
|
|
1766
1615
|
// Per https://github.com/w3c/IndexedDB/issues/147 , non-finite numbers
|
|
1767
1616
|
// (or numbers larger than the max) are now to have the explicit effect of
|
|
@@ -1779,7 +1628,6 @@
|
|
|
1779
1628
|
getCurrentNumber(tx, store, function (cn) {
|
|
1780
1629
|
var value = Math.floor(Math.min(key, MAX_ALLOWED_CURRENT_NUMBER));
|
|
1781
1630
|
var useNewKeyForAutoInc = value >= cn;
|
|
1782
|
-
|
|
1783
1631
|
if (useNewKeyForAutoInc) {
|
|
1784
1632
|
setCurrentNumber(tx, store, value, function () {
|
|
1785
1633
|
successCb(cn); // Supply old current number in case needs to be reverted
|
|
@@ -1813,7 +1661,5 @@
|
|
|
1813
1661
|
exports.possiblyUpdateKeyGenerator = possiblyUpdateKeyGenerator;
|
|
1814
1662
|
exports.roundTrip = roundTrip;
|
|
1815
1663
|
|
|
1816
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1817
|
-
|
|
1818
1664
|
}));
|
|
1819
1665
|
//# sourceMappingURL=indexeddbshim-Key.js.map
|