indexeddbshim 12.0.0 → 13.0.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/badges/licenses-badge-dev.svg +1 -1
- package/dist/CFG.d.ts +80 -0
- package/dist/CFG.d.ts.map +1 -0
- package/dist/DOMException.d.ts +71 -0
- package/dist/DOMException.d.ts.map +1 -0
- package/dist/DOMStringList.d.ts +20 -0
- package/dist/DOMStringList.d.ts.map +1 -0
- package/dist/Event.d.ts +21 -0
- package/dist/Event.d.ts.map +1 -0
- package/dist/IDBCursor.d.ts +288 -0
- package/dist/IDBCursor.d.ts.map +1 -0
- package/dist/IDBDatabase.d.ts +143 -0
- package/dist/IDBDatabase.d.ts.map +1 -0
- package/dist/IDBFactory.d.ts +96 -0
- package/dist/IDBFactory.d.ts.map +1 -0
- package/dist/IDBIndex.d.ts +243 -0
- package/dist/IDBIndex.d.ts.map +1 -0
- package/dist/IDBKeyRange.d.ts +79 -0
- package/dist/IDBKeyRange.d.ts.map +1 -0
- package/dist/IDBObjectStore.d.ts +273 -0
- package/dist/IDBObjectStore.d.ts.map +1 -0
- package/dist/IDBRequest.d.ts +88 -0
- package/dist/IDBRequest.d.ts.map +1 -0
- package/dist/IDBTransaction.d.ts +270 -0
- package/dist/IDBTransaction.d.ts.map +1 -0
- package/dist/IDBVersionChangeEvent.d.ts +22 -0
- package/dist/IDBVersionChangeEvent.d.ts.map +1 -0
- package/dist/Key.d.ts +214 -0
- package/dist/Key.d.ts.map +1 -0
- package/dist/Sca.d.ts +31 -0
- package/dist/Sca.d.ts.map +1 -0
- package/dist/UnicodeIdentifiers.d.ts +3 -0
- package/dist/UnicodeIdentifiers.d.ts.map +1 -0
- package/dist/browser-UnicodeIdentifiers.d.ts +2 -0
- package/dist/browser-UnicodeIdentifiers.d.ts.map +1 -0
- package/dist/browser-noninvasive.d.ts +3 -0
- package/dist/browser-noninvasive.d.ts.map +1 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/cmp.d.ts +9 -0
- package/dist/cmp.d.ts.map +1 -0
- package/dist/indexeddbshim-Key.js +553 -252
- 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.cjs +17560 -1302
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.js +4367 -1604
- package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js +2 -2
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
- package/dist/indexeddbshim-node.cjs +17556 -1302
- package/dist/indexeddbshim-node.cjs.map +1 -1
- package/dist/indexeddbshim-noninvasive.js +4362 -1604
- package/dist/indexeddbshim-noninvasive.js.map +1 -1
- package/dist/indexeddbshim-noninvasive.min.js +2 -2
- package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
- package/dist/indexeddbshim.js +4362 -1604
- package/dist/indexeddbshim.js.map +1 -1
- package/dist/indexeddbshim.min.js +2 -2
- package/dist/indexeddbshim.min.js.map +1 -1
- package/dist/node-UnicodeIdentifiers.d.ts +8 -0
- package/dist/node-UnicodeIdentifiers.d.ts.map +1 -0
- package/dist/node.d.ts +8 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/nodeWebSQL.d.ts +3 -0
- package/dist/nodeWebSQL.d.ts.map +1 -0
- package/dist/setGlobalVars.d.ts +79 -0
- package/dist/setGlobalVars.d.ts.map +1 -0
- package/dist/unicode-regex.d.ts +3 -0
- package/dist/unicode-regex.d.ts.map +1 -0
- package/dist/util.d.ts +174 -0
- package/dist/util.d.ts.map +1 -0
- package/index.html +1 -1
- package/package.json +51 -37
- package/src/CFG.js +89 -11
- package/src/DOMException.js +117 -31
- package/src/DOMStringList.js +93 -3
- package/src/Event.js +19 -4
- package/src/IDBCursor.js +350 -76
- package/src/IDBDatabase.js +88 -10
- package/src/IDBFactory.js +331 -61
- package/src/IDBIndex.js +393 -110
- package/src/IDBKeyRange.js +90 -17
- package/src/IDBObjectStore.js +347 -86
- package/src/IDBRequest.js +59 -1
- package/src/IDBTransaction.js +254 -46
- package/src/IDBVersionChangeEvent.js +28 -3
- package/src/Key.d.ts +1 -0
- package/src/Key.js +272 -162
- package/src/Sca.js +29 -4
- package/src/browser-UnicodeIdentifiers.js +5 -1
- package/src/cmp.js +5 -5
- package/src/node-UnicodeIdentifiers.js +9 -0
- package/src/node.js +5 -0
- package/src/nodeWebSQL.js +11 -5
- package/src/setGlobalVars.js +159 -22
- package/src/unicode-regex.js +2 -0
- package/src/util.js +229 -40
- package/typings/shimIndexedDB.d.ts +9 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! indexeddbshim -
|
|
1
|
+
/*! indexeddbshim - v13.0.0 - 12/7/2023 */
|
|
2
2
|
|
|
3
3
|
(function (global, factory) {
|
|
4
4
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
@@ -6,41 +6,41 @@
|
|
|
6
6
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.IDBKeyUtils = {}));
|
|
7
7
|
})(this, (function (exports) { 'use strict';
|
|
8
8
|
|
|
9
|
-
function _iterableToArrayLimit(
|
|
10
|
-
var
|
|
11
|
-
if (null !=
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
function _iterableToArrayLimit(r, l) {
|
|
10
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
11
|
+
if (null != t) {
|
|
12
|
+
var e,
|
|
13
|
+
n,
|
|
14
|
+
i,
|
|
15
|
+
u,
|
|
16
|
+
a = [],
|
|
17
|
+
f = !0,
|
|
18
|
+
o = !1;
|
|
19
19
|
try {
|
|
20
|
-
if (
|
|
21
|
-
if (Object(
|
|
22
|
-
|
|
23
|
-
} else for (; !(
|
|
24
|
-
} catch (
|
|
25
|
-
|
|
20
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
21
|
+
if (Object(t) !== t) return;
|
|
22
|
+
f = !1;
|
|
23
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
24
|
+
} catch (r) {
|
|
25
|
+
o = !0, n = r;
|
|
26
26
|
} finally {
|
|
27
27
|
try {
|
|
28
|
-
if (!
|
|
28
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
29
29
|
} finally {
|
|
30
|
-
if (
|
|
30
|
+
if (o) throw n;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
return
|
|
33
|
+
return a;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
function _typeof(
|
|
36
|
+
function _typeof(o) {
|
|
37
37
|
"@babel/helpers - typeof";
|
|
38
38
|
|
|
39
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (
|
|
40
|
-
return typeof
|
|
41
|
-
} : function (
|
|
42
|
-
return
|
|
43
|
-
}, _typeof(
|
|
39
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
40
|
+
return typeof o;
|
|
41
|
+
} : function (o) {
|
|
42
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
43
|
+
}, _typeof(o);
|
|
44
44
|
}
|
|
45
45
|
function _slicedToArray(arr, i) {
|
|
46
46
|
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
@@ -128,8 +128,73 @@
|
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
/* eslint-disable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/147 */
|
|
132
|
+
/**
|
|
133
|
+
* @typedef {T[keyof T]} ValueOf<T>
|
|
134
|
+
* @template T
|
|
135
|
+
*/
|
|
136
|
+
/* eslint-enable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/147 */
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @typedef {{unlink: (path: string, cb: import('fs').NoParamCallback) => void}} FSApi
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @typedef {{
|
|
144
|
+
* DEBUG: boolean,
|
|
145
|
+
* cacheDatabaseInstances: boolean,
|
|
146
|
+
* autoName: boolean,
|
|
147
|
+
* fullIDLSupport: boolean,
|
|
148
|
+
* checkOrigin: boolean,
|
|
149
|
+
* cursorPreloadPackSize: number,
|
|
150
|
+
* UnicodeIDStart: string,
|
|
151
|
+
* UnicodeIDContinue: string,
|
|
152
|
+
* registerSCA: (
|
|
153
|
+
* preset: import('typeson').Preset
|
|
154
|
+
* ) => import('typeson').Preset,
|
|
155
|
+
* avoidAutoShim: boolean,
|
|
156
|
+
* win: {
|
|
157
|
+
* openDatabase: (name: string, version: string, displayName: string, estimatedSize: number) => import('websql-configurable').default
|
|
158
|
+
* },
|
|
159
|
+
* DEFAULT_DB_SIZE: number,
|
|
160
|
+
* useSQLiteIndexes: boolean,
|
|
161
|
+
* fs: FSApi,
|
|
162
|
+
* addNonIDBGlobals: boolean,
|
|
163
|
+
* replaceNonIDBGlobals: boolean,
|
|
164
|
+
* escapeDatabaseName: (name: string) => string,
|
|
165
|
+
* unescapeDatabaseName: (name: string) => string,
|
|
166
|
+
* databaseCharacterEscapeList: string|false,
|
|
167
|
+
* databaseNameLengthLimit: number|false,
|
|
168
|
+
* escapeNFDForDatabaseNames: boolean,
|
|
169
|
+
* addSQLiteExtension: boolean,
|
|
170
|
+
* memoryDatabase: string,
|
|
171
|
+
* deleteDatabaseFiles: boolean,
|
|
172
|
+
* databaseBasePath: string,
|
|
173
|
+
* sysDatabaseBasePath: string,
|
|
174
|
+
* sqlBusyTimeout: number,
|
|
175
|
+
* sqlTrace: () => void,
|
|
176
|
+
* sqlProfile: () => void,
|
|
177
|
+
* createIndexes: boolean
|
|
178
|
+
* }} ConfigValues
|
|
179
|
+
*/
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @typedef {ValueOf<ConfigValues>} ConfigValue
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
/** @type {{[key: string]: ConfigValue}} */
|
|
131
186
|
var map = {};
|
|
132
|
-
var CFG = {};
|
|
187
|
+
var CFG = /** @type {ConfigValues} */{};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* @typedef {keyof ConfigValues} KeyofConfigValues
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @typedef {KeyofConfigValues[]} Config
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
/** @type {Config} */
|
|
133
198
|
[
|
|
134
199
|
// Boolean for verbose reporting
|
|
135
200
|
'DEBUG',
|
|
@@ -240,8 +305,14 @@
|
|
|
240
305
|
// defaults to `true`
|
|
241
306
|
'addSQLiteExtension',
|
|
242
307
|
// Various types of in-memory databases that can auto-delete
|
|
243
|
-
['memoryDatabase',
|
|
244
|
-
|
|
308
|
+
['memoryDatabase',
|
|
309
|
+
/**
|
|
310
|
+
* @param {string} val
|
|
311
|
+
* @throws {TypeError}
|
|
312
|
+
* @returns {void}
|
|
313
|
+
*/
|
|
314
|
+
function (val) {
|
|
315
|
+
if (!/^(?::memory:|file::memory:(\?(?:[\0-"\$-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?(#(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?)?$/.test( /** @type {string} */val)) {
|
|
245
316
|
throw new TypeError('`memoryDatabase` must be the empty string, ":memory:", or a ' + '"file::memory:[?queryString][#hash] URL".');
|
|
246
317
|
}
|
|
247
318
|
}],
|
|
@@ -254,8 +325,11 @@
|
|
|
254
325
|
// Defaults to 1000
|
|
255
326
|
'sqlTrace',
|
|
256
327
|
// Callback not used by default
|
|
257
|
-
'sqlProfile'
|
|
258
|
-
|
|
328
|
+
'sqlProfile',
|
|
329
|
+
// Callback not used by default
|
|
330
|
+
|
|
331
|
+
'createIndexes'].forEach(function (prop) {
|
|
332
|
+
/** @type {(val: any) => void} */
|
|
259
333
|
var validator;
|
|
260
334
|
if (Array.isArray(prop)) {
|
|
261
335
|
var _prop = prop;
|
|
@@ -283,10 +357,25 @@
|
|
|
283
357
|
* @returns {DOMException}
|
|
284
358
|
*/
|
|
285
359
|
function createNativeDOMException(name, message) {
|
|
360
|
+
// @ts-expect-error It's ok
|
|
286
361
|
return new DOMException.prototype.constructor(message, name || 'DOMException');
|
|
287
362
|
}
|
|
288
363
|
|
|
289
364
|
// From web-platform-tests testharness.js name_code_map (though not in new spec)
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* @typedef {"IndexSizeError"|"HierarchyRequestError"|"WrongDocumentError"|
|
|
368
|
+
* "InvalidCharacterError"|"NoModificationAllowedError"|"NotFoundError"|
|
|
369
|
+
* "NotSupportedError"|"InUseAttributeError"|"InvalidStateError"|
|
|
370
|
+
* "SyntaxError"|"InvalidModificationError"|"NamespaceError"|
|
|
371
|
+
* "InvalidAccessError"|"TypeMismatchError"|"SecurityError"|
|
|
372
|
+
* "NetworkError"|"AbortError"|"URLMismatchError"|"QuotaExceededError"|
|
|
373
|
+
* "TimeoutError"|"InvalidNodeTypeError"|"DataCloneError"|"EncodingError"|
|
|
374
|
+
* "NotReadableError"|"UnknownError"|"ConstraintError"|"DataError"|
|
|
375
|
+
* "TransactionInactiveError"|"ReadOnlyError"|"VersionError"|
|
|
376
|
+
* "OperationError"|"NotAllowedError"} Code
|
|
377
|
+
*/
|
|
378
|
+
|
|
290
379
|
var codes = {
|
|
291
380
|
IndexSizeError: 1,
|
|
292
381
|
HierarchyRequestError: 3,
|
|
@@ -321,6 +410,18 @@
|
|
|
321
410
|
OperationError: 0,
|
|
322
411
|
NotAllowedError: 0
|
|
323
412
|
};
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* @typedef {"INDEX_SIZE_ERR"|"DOMSTRING_SIZE_ERR"|"HIERARCHY_REQUEST_ERR"|
|
|
416
|
+
* "WRONG_DOCUMENT_ERR"|"INVALID_CHARACTER_ERR"|"NO_DATA_ALLOWED_ERR"|
|
|
417
|
+
* "NO_MODIFICATION_ALLOWED_ERR"|"NOT_FOUND_ERR"|"NOT_SUPPORTED_ERR"|
|
|
418
|
+
* "INUSE_ATTRIBUTE_ERR"|"INVALID_STATE_ERR"|"SYNTAX_ERR"|
|
|
419
|
+
* "INVALID_MODIFICATION_ERR"|"NAMESPACE_ERR"|"INVALID_ACCESS_ERR"|
|
|
420
|
+
* "VALIDATION_ERR"|"TYPE_MISMATCH_ERR"|"SECURITY_ERR"|"NETWORK_ERR"|
|
|
421
|
+
* "ABORT_ERR"|"URL_MISMATCH_ERR"|"QUOTA_EXCEEDED_ERR"|"TIMEOUT_ERR"|
|
|
422
|
+
* "INVALID_NODE_TYPE_ERR"|"DATA_CLONE_ERR"} LegacyCode
|
|
423
|
+
*/
|
|
424
|
+
|
|
324
425
|
var legacyCodes = {
|
|
325
426
|
INDEX_SIZE_ERR: 1,
|
|
326
427
|
DOMSTRING_SIZE_ERR: 2,
|
|
@@ -351,13 +452,18 @@
|
|
|
351
452
|
|
|
352
453
|
/**
|
|
353
454
|
*
|
|
354
|
-
* @returns {DOMException}
|
|
455
|
+
* @returns {typeof DOMException}
|
|
355
456
|
*/
|
|
356
457
|
function createNonNativeDOMExceptionClass() {
|
|
458
|
+
/**
|
|
459
|
+
* @param {string|undefined} message
|
|
460
|
+
* @param {Code|LegacyCode} name
|
|
461
|
+
* @returns {void}
|
|
462
|
+
*/
|
|
357
463
|
function DOMException(message, name) {
|
|
358
464
|
// const err = Error.prototype.constructor.call(this, message); // Any use to this? Won't set this.message
|
|
359
465
|
this[Symbol.toStringTag] = 'DOMException';
|
|
360
|
-
this._code = name in codes ? codes[name] : legacyCodes[name] || 0;
|
|
466
|
+
this._code = name in codes ? codes[( /** @type {Code} */name)] : legacyCodes[( /** @type {LegacyCode} */name)] || 0;
|
|
361
467
|
this._name = name || 'Error';
|
|
362
468
|
// We avoid `String()` in this next line as it converts Symbols
|
|
363
469
|
this._message = message === undefined ? '' : '' + message; // eslint-disable-line no-implicit-coercion
|
|
@@ -388,17 +494,30 @@
|
|
|
388
494
|
// Necessary for W3C tests which complains if `DOMException` has properties on its "own" prototype
|
|
389
495
|
|
|
390
496
|
// class DummyDOMException extends Error {}; // Sometimes causing problems in Node
|
|
391
|
-
|
|
497
|
+
/* eslint-disable func-name-matching */
|
|
498
|
+
/**
|
|
499
|
+
* @class
|
|
500
|
+
*/
|
|
392
501
|
var DummyDOMException = function DOMException() {/* */};
|
|
502
|
+
/* eslint-enable func-name-matching */
|
|
393
503
|
DummyDOMException.prototype = Object.create(Error.prototype); // Intended for subclassing
|
|
504
|
+
/** @type {const} */
|
|
394
505
|
['name', 'message'].forEach(function (prop) {
|
|
395
506
|
Object.defineProperty(DummyDOMException.prototype, prop, {
|
|
396
507
|
enumerable: true,
|
|
508
|
+
/**
|
|
509
|
+
* @this {DOMException}
|
|
510
|
+
* @returns {string}
|
|
511
|
+
*/
|
|
397
512
|
get: function get() {
|
|
398
|
-
if (!(this instanceof DOMException ||
|
|
513
|
+
if (!(this instanceof DOMException ||
|
|
514
|
+
// @ts-expect-error Just checking
|
|
515
|
+
this instanceof DummyDOMException ||
|
|
516
|
+
// @ts-expect-error Just checking
|
|
517
|
+
this instanceof Error)) {
|
|
399
518
|
throw new TypeError('Illegal invocation');
|
|
400
519
|
}
|
|
401
|
-
return this['
|
|
520
|
+
return this[prop === 'name' ? '_name' : '_message'];
|
|
402
521
|
}
|
|
403
522
|
});
|
|
404
523
|
});
|
|
@@ -410,12 +529,16 @@
|
|
|
410
529
|
throw new TypeError('Illegal invocation');
|
|
411
530
|
}
|
|
412
531
|
});
|
|
532
|
+
// @ts-expect-error It's ok
|
|
413
533
|
DOMException.prototype = new DummyDOMException();
|
|
414
534
|
DOMException.prototype[Symbol.toStringTag] = 'DOMExceptionPrototype';
|
|
415
535
|
Object.defineProperty(DOMException, 'prototype', {
|
|
416
536
|
writable: false
|
|
417
537
|
});
|
|
418
|
-
Object.keys(codes)
|
|
538
|
+
var keys = Object.keys(codes);
|
|
539
|
+
|
|
540
|
+
/** @type {(keyof codes)[]} */
|
|
541
|
+
keys.forEach(function (codeName) {
|
|
419
542
|
Object.defineProperty(DOMException.prototype, codeName, {
|
|
420
543
|
enumerable: true,
|
|
421
544
|
configurable: false,
|
|
@@ -427,6 +550,7 @@
|
|
|
427
550
|
value: codes[codeName]
|
|
428
551
|
});
|
|
429
552
|
});
|
|
553
|
+
/** @type {(keyof legacyCodes)[]} */
|
|
430
554
|
Object.keys(legacyCodes).forEach(function (codeName) {
|
|
431
555
|
Object.defineProperty(DOMException.prototype, codeName, {
|
|
432
556
|
enumerable: true,
|
|
@@ -445,6 +569,8 @@
|
|
|
445
569
|
enumerable: false,
|
|
446
570
|
value: DOMException
|
|
447
571
|
});
|
|
572
|
+
|
|
573
|
+
// @ts-expect-error We don't need all its properties
|
|
448
574
|
return DOMException;
|
|
449
575
|
}
|
|
450
576
|
var ShimNonNativeDOMException = createNonNativeDOMExceptionClass();
|
|
@@ -459,23 +585,38 @@
|
|
|
459
585
|
return new ShimNonNativeDOMException(message, name);
|
|
460
586
|
}
|
|
461
587
|
|
|
588
|
+
/**
|
|
589
|
+
* @typedef {{
|
|
590
|
+
* message: string|DOMString
|
|
591
|
+
* }} ErrorLike
|
|
592
|
+
*/
|
|
593
|
+
|
|
462
594
|
/**
|
|
463
595
|
* Logs detailed error information to the console.
|
|
464
596
|
* @param {string} name
|
|
465
597
|
* @param {string} message
|
|
466
|
-
* @param {string|
|
|
598
|
+
* @param {string|ErrorLike|boolean|null} [error]
|
|
467
599
|
* @returns {void}
|
|
468
600
|
*/
|
|
469
601
|
function logError(name, message, error) {
|
|
470
602
|
if (CFG.DEBUG) {
|
|
471
|
-
|
|
472
|
-
error = error.message;
|
|
473
|
-
}
|
|
603
|
+
var msg = error && _typeof(error) === 'object' && error.message ? error.message : ( /** @type {string} */error);
|
|
474
604
|
var method = typeof console.error === 'function' ? 'error' : 'log';
|
|
475
|
-
console[method](name + ': ' + message + '. ' + (
|
|
476
|
-
|
|
605
|
+
console[method](name + ': ' + message + '. ' + (msg || ''));
|
|
606
|
+
if (console.trace) {
|
|
607
|
+
console.trace();
|
|
608
|
+
}
|
|
477
609
|
}
|
|
478
610
|
}
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* @typedef {any} ArbitraryValue
|
|
614
|
+
*/
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* @param {ArbitraryValue} obj
|
|
618
|
+
* @returns {boolean}
|
|
619
|
+
*/
|
|
479
620
|
function isErrorOrDOMErrorOrDOMException(obj) {
|
|
480
621
|
return obj && _typeof(obj) === 'object' &&
|
|
481
622
|
// We don't use util.isObj here as mutual dependency causing problems in Babel with browser
|
|
@@ -492,17 +633,43 @@
|
|
|
492
633
|
useNativeDOMException = true;
|
|
493
634
|
}
|
|
494
635
|
} catch (e) {}
|
|
495
|
-
var createDOMException = useNativeDOMException
|
|
636
|
+
var createDOMException = useNativeDOMException
|
|
637
|
+
// eslint-disable-next-line @stylistic/operator-linebreak -- Need JSDoc
|
|
638
|
+
?
|
|
639
|
+
/**
|
|
640
|
+
* @param {string} name
|
|
641
|
+
* @param {string} message
|
|
642
|
+
* @param {ErrorLike} [error]
|
|
643
|
+
* @returns {DOMException}
|
|
644
|
+
*/
|
|
645
|
+
function (name, message, error) {
|
|
496
646
|
logError(name, message, error);
|
|
497
647
|
return createNativeDOMException(name, message);
|
|
498
|
-
}
|
|
648
|
+
}
|
|
649
|
+
// eslint-disable-next-line @stylistic/operator-linebreak -- Need JSDoc
|
|
650
|
+
:
|
|
651
|
+
/**
|
|
652
|
+
* @param {string} name
|
|
653
|
+
* @param {string} message
|
|
654
|
+
* @param {ErrorLike} [error]
|
|
655
|
+
* @returns {Error}
|
|
656
|
+
*/
|
|
657
|
+
function (name, message, error) {
|
|
499
658
|
logError(name, message, error);
|
|
500
659
|
return createNonNativeDOMException(name, message);
|
|
501
660
|
};
|
|
502
661
|
|
|
662
|
+
/**
|
|
663
|
+
* @typedef {number} Integer
|
|
664
|
+
*/
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* @param {string} arg
|
|
668
|
+
* @returns {string}
|
|
669
|
+
*/
|
|
503
670
|
function escapeUnmatchedSurrogates(arg) {
|
|
504
671
|
// http://stackoverflow.com/a/6701665/271577
|
|
505
|
-
return arg.
|
|
672
|
+
return arg.replaceAll(/((?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])))(?!(?:(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))|(^|(?:[\0-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))((?:(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/g, function (_, unmatchedHighSurrogate, precedingLow, unmatchedLowSurrogate) {
|
|
506
673
|
// Could add a corresponding surrogate for compatibility with `node-sqlite3`: http://bugs.python.org/issue12569 and http://stackoverflow.com/a/6701665/271577
|
|
507
674
|
// but Chrome having problems
|
|
508
675
|
if (unmatchedHighSurrogate) {
|
|
@@ -512,41 +679,80 @@
|
|
|
512
679
|
});
|
|
513
680
|
}
|
|
514
681
|
|
|
515
|
-
|
|
682
|
+
/**
|
|
683
|
+
* The escaping of unmatched surrogates was needed by Chrome but not Node.
|
|
684
|
+
* @param {string} arg
|
|
685
|
+
* @returns {string}
|
|
686
|
+
*/
|
|
516
687
|
function escapeSQLiteStatement(arg) {
|
|
517
|
-
return escapeUnmatchedSurrogates(arg.
|
|
688
|
+
return escapeUnmatchedSurrogates(arg.replaceAll('^', '^^').replaceAll('\0', '^0'));
|
|
518
689
|
}
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
*
|
|
693
|
+
* @param {AnyValue} obj
|
|
694
|
+
* @returns {obj is object}
|
|
695
|
+
*/
|
|
519
696
|
function isObj(obj) {
|
|
520
|
-
return obj && _typeof(obj) === 'object';
|
|
697
|
+
return obj !== null && _typeof(obj) === 'object';
|
|
521
698
|
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
*
|
|
702
|
+
* @param {object} obj
|
|
703
|
+
* @returns {boolean}
|
|
704
|
+
*/
|
|
522
705
|
function isDate(obj) {
|
|
523
|
-
return isObj(obj) && typeof obj.getDate === 'function';
|
|
706
|
+
return isObj(obj) && 'getDate' in obj && typeof obj.getDate === 'function';
|
|
524
707
|
}
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
*
|
|
711
|
+
* @param {object} obj
|
|
712
|
+
* @returns {boolean}
|
|
713
|
+
*/
|
|
525
714
|
function isBlob(obj) {
|
|
526
|
-
return isObj(obj) && typeof obj.size === 'number' && typeof obj.slice === 'function' && !('lastModified' in obj);
|
|
715
|
+
return isObj(obj) && 'size' in obj && typeof obj.size === 'number' && 'slice' in obj && typeof obj.slice === 'function' && !('lastModified' in obj);
|
|
527
716
|
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
*
|
|
720
|
+
* @param {object} obj
|
|
721
|
+
* @returns {boolean}
|
|
722
|
+
*/
|
|
528
723
|
function isFile(obj) {
|
|
529
|
-
return isObj(obj) && typeof obj.name === 'string' && typeof obj.slice === 'function' && 'lastModified' in obj;
|
|
724
|
+
return isObj(obj) && 'name' in obj && typeof obj.name === 'string' && 'slice' in obj && typeof obj.slice === 'function' && 'lastModified' in obj;
|
|
530
725
|
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
*
|
|
729
|
+
* @param {AnyValue} obj
|
|
730
|
+
* @returns {boolean}
|
|
731
|
+
*/
|
|
531
732
|
function isBinary(obj) {
|
|
532
|
-
return isObj(obj) && typeof obj.byteLength === 'number' && (typeof obj.slice === 'function' ||
|
|
733
|
+
return isObj(obj) && 'byteLength' in obj && typeof obj.byteLength === 'number' && ('slice' in obj && typeof obj.slice === 'function' ||
|
|
533
734
|
// `TypedArray` (view on buffer) or `ArrayBuffer`
|
|
534
|
-
typeof obj.getFloat64 === 'function' // `DataView` (view on buffer)
|
|
735
|
+
'getFloat64' in obj && typeof obj.getFloat64 === 'function' // `DataView` (view on buffer)
|
|
535
736
|
);
|
|
536
737
|
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* @param {AnyValue} v
|
|
741
|
+
* @returns {v is null|undefined}
|
|
742
|
+
*/
|
|
537
743
|
function isNullish(v) {
|
|
538
744
|
return v === null || v === undefined;
|
|
539
745
|
}
|
|
540
746
|
|
|
541
747
|
/**
|
|
542
748
|
* Compares two keys.
|
|
543
|
-
* @param first
|
|
544
|
-
* @param second
|
|
545
|
-
* @returns {
|
|
749
|
+
* @param {import('./Key.js').Key} first
|
|
750
|
+
* @param {import('./Key.js').Key} second
|
|
751
|
+
* @returns {0|1|-1}
|
|
546
752
|
*/
|
|
547
753
|
function cmp(first, second) {
|
|
548
|
-
var encodedKey1 = _encode(first);
|
|
549
|
-
var encodedKey2 = _encode(second);
|
|
754
|
+
var encodedKey1 = /** @type {string} */_encode(first);
|
|
755
|
+
var encodedKey2 = /** @type {string} */_encode(second);
|
|
550
756
|
var result = encodedKey1 > encodedKey2 ? 1 : encodedKey1 === encodedKey2 ? 0 : -1;
|
|
551
757
|
if (CFG.DEBUG) {
|
|
552
758
|
// verify that the keys encoded correctly
|
|
@@ -574,12 +780,57 @@
|
|
|
574
780
|
}
|
|
575
781
|
|
|
576
782
|
/**
|
|
577
|
-
* @
|
|
783
|
+
* @typedef {NodeJS.TypedArray|DataView} ArrayBufferView
|
|
784
|
+
*/
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* @typedef {ArrayBufferView|ArrayBuffer} BufferSource
|
|
788
|
+
*/
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* @typedef {"number"|"date"|"string"|"binary"|"array"} KeyType
|
|
792
|
+
*/
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* @typedef {any} Value
|
|
796
|
+
*/
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* @typedef {any} Key
|
|
800
|
+
* @todo Specify possible value more precisely
|
|
801
|
+
*/
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* @typedef {KeyPath[]} KeyPathArray
|
|
805
|
+
*/
|
|
806
|
+
/**
|
|
807
|
+
* @typedef {string|KeyPathArray} KeyPath
|
|
808
|
+
*/
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* @typedef {object} KeyValueObject
|
|
812
|
+
* @property {KeyType|"NaN"|"null"|"undefined"|"boolean"|"object"|"symbol"|
|
|
813
|
+
* "function"|"bigint"} type If not `KeyType`, indicates invalid value
|
|
814
|
+
* @property {Value} [value]
|
|
815
|
+
* @property {boolean} [invalid]
|
|
816
|
+
* @property {string} [message]
|
|
817
|
+
* @todo Specify acceptable `value` more precisely
|
|
818
|
+
*/
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* @typedef {number|string|Date|ArrayBuffer} ValueTypePrimitive
|
|
822
|
+
*/
|
|
823
|
+
/**
|
|
824
|
+
* @typedef {ValueType[]} ValueTypeArray
|
|
825
|
+
*/
|
|
826
|
+
/**
|
|
827
|
+
* @typedef {ValueTypePrimitive|ValueTypeArray} ValueType
|
|
578
828
|
*/
|
|
579
829
|
|
|
580
830
|
/**
|
|
581
831
|
* Encodes the keys based on their types. This is required to maintain collations
|
|
582
832
|
* We leave space for future keys.
|
|
833
|
+
* @type {{[key: string]: Integer|string}}
|
|
583
834
|
*/
|
|
584
835
|
var keyTypeToEncodedChar = {
|
|
585
836
|
invalid: 100,
|
|
@@ -589,14 +840,14 @@
|
|
|
589
840
|
binary: 500,
|
|
590
841
|
array: 600
|
|
591
842
|
};
|
|
592
|
-
var keyTypes = Object.keys(keyTypeToEncodedChar);
|
|
843
|
+
var keyTypes = /** @type {(KeyType|"invalid")[]} */Object.keys(keyTypeToEncodedChar);
|
|
593
844
|
keyTypes.forEach(function (k) {
|
|
594
|
-
keyTypeToEncodedChar[k] = String.fromCodePoint(keyTypeToEncodedChar[k]);
|
|
845
|
+
keyTypeToEncodedChar[k] = String.fromCodePoint( /** @type {number} */keyTypeToEncodedChar[k]);
|
|
595
846
|
});
|
|
596
847
|
var encodedCharToKeyType = keyTypes.reduce(function (o, k) {
|
|
597
848
|
o[keyTypeToEncodedChar[k]] = k;
|
|
598
849
|
return o;
|
|
599
|
-
}, {});
|
|
850
|
+
}, /** @type {{[key: string]: KeyType|"invalid"}} */{});
|
|
600
851
|
|
|
601
852
|
/**
|
|
602
853
|
* The sign values for numbers, ordered from least to greatest.
|
|
@@ -608,12 +859,23 @@
|
|
|
608
859
|
* - "positiveInfinity": Sorts above all other values.
|
|
609
860
|
*/
|
|
610
861
|
var signValues = ['negativeInfinity', 'bigNegative', 'smallNegative', 'smallPositive', 'bigPositive', 'positiveInfinity'];
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
* @typedef {any} AnyValue
|
|
865
|
+
*/
|
|
866
|
+
|
|
611
867
|
var types = {
|
|
612
868
|
invalid: {
|
|
613
|
-
|
|
869
|
+
/**
|
|
870
|
+
* @returns {string}
|
|
871
|
+
*/
|
|
872
|
+
encode: function encode() {
|
|
614
873
|
return keyTypeToEncodedChar.invalid + '-';
|
|
615
874
|
},
|
|
616
|
-
|
|
875
|
+
/**
|
|
876
|
+
* @returns {undefined}
|
|
877
|
+
*/
|
|
878
|
+
decode: function decode() {
|
|
617
879
|
return undefined;
|
|
618
880
|
}
|
|
619
881
|
},
|
|
@@ -630,6 +892,10 @@
|
|
|
630
892
|
number: {
|
|
631
893
|
// The encode step checks for six numeric cases and generates 14-digit encoded
|
|
632
894
|
// sign-exponent-mantissa strings.
|
|
895
|
+
/**
|
|
896
|
+
* @param {number} key
|
|
897
|
+
* @returns {string}
|
|
898
|
+
*/
|
|
633
899
|
encode: function encode(key) {
|
|
634
900
|
var key32 = key === Number.MIN_VALUE
|
|
635
901
|
// Mocha test `IDBFactory/cmp-spec.js` exposed problem for some
|
|
@@ -685,6 +951,10 @@
|
|
|
685
951
|
// The decode step must interpret the sign, reflip values encoded as the 32's complements,
|
|
686
952
|
// apply signs to the exponent and mantissa, do the base-32 power operation, and return
|
|
687
953
|
// the original JavaScript number values.
|
|
954
|
+
/**
|
|
955
|
+
* @param {string} key
|
|
956
|
+
* @returns {number}
|
|
957
|
+
*/
|
|
688
958
|
decode: function decode(key) {
|
|
689
959
|
var sign = Number(key.slice(2, 3));
|
|
690
960
|
var exponent = key.slice(3, 5);
|
|
@@ -721,18 +991,28 @@
|
|
|
721
991
|
// This effectively doubles the size of every string, but it ensures that when two arrays of strings are compared,
|
|
722
992
|
// the indexes of each string's characters line up with each other.
|
|
723
993
|
string: {
|
|
994
|
+
/**
|
|
995
|
+
* @param {string} key
|
|
996
|
+
* @param {boolean} [inArray]
|
|
997
|
+
* @returns {string}
|
|
998
|
+
*/
|
|
724
999
|
encode: function encode(key, inArray) {
|
|
725
1000
|
if (inArray) {
|
|
726
1001
|
// prepend each character with a dash, and append a space to the end
|
|
727
|
-
key = key.
|
|
1002
|
+
key = key.replaceAll(/((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/g, '-$1') + ' ';
|
|
728
1003
|
}
|
|
729
1004
|
return keyTypeToEncodedChar.string + '-' + key;
|
|
730
1005
|
},
|
|
1006
|
+
/**
|
|
1007
|
+
* @param {string} key
|
|
1008
|
+
* @param {boolean} [inArray]
|
|
1009
|
+
* @returns {string}
|
|
1010
|
+
*/
|
|
731
1011
|
decode: function decode(key, inArray) {
|
|
732
1012
|
key = key.slice(2);
|
|
733
1013
|
if (inArray) {
|
|
734
1014
|
// remove the space at the end, and the dash before each character
|
|
735
|
-
key = key.slice(0, -1).
|
|
1015
|
+
key = key.slice(0, -1).replaceAll(/\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');
|
|
736
1016
|
}
|
|
737
1017
|
return key;
|
|
738
1018
|
}
|
|
@@ -741,6 +1021,10 @@
|
|
|
741
1021
|
// An extra, value is added to each array during encoding to make
|
|
742
1022
|
// empty arrays sort correctly.
|
|
743
1023
|
array: {
|
|
1024
|
+
/**
|
|
1025
|
+
* @param {ValueTypeArray} key
|
|
1026
|
+
* @returns {string}
|
|
1027
|
+
*/
|
|
744
1028
|
encode: function encode(key) {
|
|
745
1029
|
var encoded = [];
|
|
746
1030
|
var _iterator = _createForOfIteratorHelper(key.entries()),
|
|
@@ -761,6 +1045,10 @@
|
|
|
761
1045
|
encoded.push(keyTypeToEncodedChar.invalid + '-'); // append an extra item, so empty arrays sort correctly
|
|
762
1046
|
return keyTypeToEncodedChar.array + '-' + JSON.stringify(encoded);
|
|
763
1047
|
},
|
|
1048
|
+
/**
|
|
1049
|
+
* @param {string} key
|
|
1050
|
+
* @returns {ValueTypeArray}
|
|
1051
|
+
*/
|
|
764
1052
|
decode: function decode(key) {
|
|
765
1053
|
var decoded = JSON.parse(key.slice(2));
|
|
766
1054
|
decoded.pop(); // remove the extra item
|
|
@@ -774,21 +1062,37 @@
|
|
|
774
1062
|
},
|
|
775
1063
|
// Dates are encoded as ISO 8601 strings, in UTC time zone.
|
|
776
1064
|
date: {
|
|
1065
|
+
/**
|
|
1066
|
+
* @param {Date} key
|
|
1067
|
+
* @returns {string}
|
|
1068
|
+
*/
|
|
777
1069
|
encode: function encode(key) {
|
|
778
1070
|
return keyTypeToEncodedChar.date + '-' + key.toJSON();
|
|
779
1071
|
},
|
|
1072
|
+
/**
|
|
1073
|
+
* @param {string} key
|
|
1074
|
+
* @returns {Date}
|
|
1075
|
+
*/
|
|
780
1076
|
decode: function decode(key) {
|
|
781
1077
|
return new Date(key.slice(2));
|
|
782
1078
|
}
|
|
783
1079
|
},
|
|
784
1080
|
binary: {
|
|
785
1081
|
// `ArrayBuffer`/Views on buffers (`TypedArray` or `DataView`)
|
|
1082
|
+
/**
|
|
1083
|
+
* @param {BufferSource} key
|
|
1084
|
+
* @returns {string}
|
|
1085
|
+
*/
|
|
786
1086
|
encode: function encode(key) {
|
|
787
1087
|
return keyTypeToEncodedChar.binary + '-' + (key.byteLength ? _toConsumableArray(getCopyBytesHeldByBufferSource(key)).map(function (b) {
|
|
788
1088
|
return String(b).padStart(3, '0');
|
|
789
1089
|
}) // e.g., '255,005,254,000,001,033'
|
|
790
1090
|
: '');
|
|
791
1091
|
},
|
|
1092
|
+
/**
|
|
1093
|
+
* @param {string} key
|
|
1094
|
+
* @returns {ArrayBuffer}
|
|
1095
|
+
*/
|
|
792
1096
|
decode: function decode(key) {
|
|
793
1097
|
// Set the entries in buffer's [[ArrayBufferData]] to those in `value`
|
|
794
1098
|
var k = key.slice(2);
|
|
@@ -809,8 +1113,8 @@
|
|
|
809
1113
|
* @returns {string}
|
|
810
1114
|
*/
|
|
811
1115
|
function padBase32Exponent(n) {
|
|
812
|
-
|
|
813
|
-
return
|
|
1116
|
+
var exp = n.toString(32);
|
|
1117
|
+
return exp.length === 1 ? '0' + exp : exp;
|
|
814
1118
|
}
|
|
815
1119
|
|
|
816
1120
|
/**
|
|
@@ -857,24 +1161,28 @@
|
|
|
857
1161
|
* @returns {number}
|
|
858
1162
|
*/
|
|
859
1163
|
function pow32(mantissa, exponent) {
|
|
860
|
-
|
|
861
|
-
if (
|
|
862
|
-
return roundToPrecision(Number.parseInt(mantissa, 32) * Math.pow(32,
|
|
1164
|
+
var exp = Number.parseInt(exponent, 32);
|
|
1165
|
+
if (exp < 0) {
|
|
1166
|
+
return roundToPrecision(Number.parseInt(mantissa, 32) * Math.pow(32, exp - 10));
|
|
863
1167
|
}
|
|
864
|
-
if (
|
|
865
|
-
var whole = mantissa.slice(0,
|
|
866
|
-
|
|
867
|
-
var fraction = mantissa.slice(
|
|
868
|
-
|
|
869
|
-
return roundToPrecision(
|
|
1168
|
+
if (exp < 11) {
|
|
1169
|
+
var whole = mantissa.slice(0, exp);
|
|
1170
|
+
var wholeNum = Number.parseInt(whole, 32);
|
|
1171
|
+
var fraction = mantissa.slice(exp);
|
|
1172
|
+
var fractionNum = Number.parseInt(fraction, 32) * Math.pow(32, exp - 11);
|
|
1173
|
+
return roundToPrecision(wholeNum + fractionNum);
|
|
870
1174
|
}
|
|
871
|
-
var expansion = mantissa + zeros(
|
|
1175
|
+
var expansion = mantissa + zeros(exp - 11);
|
|
872
1176
|
return Number.parseInt(expansion, 32);
|
|
873
1177
|
}
|
|
874
1178
|
|
|
1179
|
+
/**
|
|
1180
|
+
* @typedef {number} Float
|
|
1181
|
+
*/
|
|
1182
|
+
|
|
875
1183
|
/**
|
|
876
1184
|
* @param {Float} num
|
|
877
|
-
* @param {Float} [precision
|
|
1185
|
+
* @param {Float} [precision]
|
|
878
1186
|
* @returns {Float}
|
|
879
1187
|
*/
|
|
880
1188
|
function roundToPrecision(num) {
|
|
@@ -901,27 +1209,29 @@
|
|
|
901
1209
|
}
|
|
902
1210
|
|
|
903
1211
|
/**
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
/**
|
|
908
|
-
* @param key
|
|
909
|
-
* @returns {module:Key.KeyType}
|
|
1212
|
+
* @param {Key} key
|
|
1213
|
+
* @returns {KeyType|"invalid"}
|
|
910
1214
|
*/
|
|
911
1215
|
function getKeyType(key) {
|
|
912
|
-
if (Array.isArray(key))
|
|
913
|
-
|
|
914
|
-
|
|
1216
|
+
if (Array.isArray(key)) {
|
|
1217
|
+
return 'array';
|
|
1218
|
+
}
|
|
1219
|
+
if (isDate(key)) {
|
|
1220
|
+
return 'date';
|
|
1221
|
+
}
|
|
1222
|
+
if (isBinary(key)) {
|
|
1223
|
+
return 'binary';
|
|
1224
|
+
}
|
|
915
1225
|
var keyType = _typeof(key);
|
|
916
|
-
return ['string', 'number'].includes(keyType) ? keyType : 'invalid';
|
|
1226
|
+
return ['string', 'number'].includes(keyType) ? ( /** @type {"string"|"number"} */keyType) : 'invalid';
|
|
917
1227
|
}
|
|
918
1228
|
|
|
919
1229
|
/**
|
|
920
1230
|
* Keys must be strings, numbers (besides `NaN`), Dates (if value is not
|
|
921
1231
|
* `NaN`), binary objects or Arrays.
|
|
922
|
-
* @param input The key input
|
|
923
|
-
* @param {
|
|
924
|
-
* @returns {
|
|
1232
|
+
* @param {Value} input The key input
|
|
1233
|
+
* @param {Value[]|null|undefined} [seen] An array of already seen keys
|
|
1234
|
+
* @returns {KeyValueObject}
|
|
925
1235
|
*/
|
|
926
1236
|
function convertValueToKey(input, seen) {
|
|
927
1237
|
return convertValueToKeyValueDecoded(input, seen, false, true);
|
|
@@ -929,8 +1239,8 @@
|
|
|
929
1239
|
|
|
930
1240
|
/**
|
|
931
1241
|
* Currently not in use.
|
|
932
|
-
* @param input
|
|
933
|
-
* @returns {
|
|
1242
|
+
* @param {Value} input
|
|
1243
|
+
* @returns {KeyValueObject}
|
|
934
1244
|
*/
|
|
935
1245
|
function convertValueToMultiEntryKey(input) {
|
|
936
1246
|
return convertValueToKeyValueDecoded(input, null, true, true);
|
|
@@ -938,7 +1248,7 @@
|
|
|
938
1248
|
|
|
939
1249
|
/**
|
|
940
1250
|
*
|
|
941
|
-
* @param O
|
|
1251
|
+
* @param {BufferSource} O
|
|
942
1252
|
* @throws {TypeError}
|
|
943
1253
|
* @see https://heycam.github.io/webidl/#ref-for-dfn-get-buffer-source-copy-2
|
|
944
1254
|
* @returns {Uint8Array}
|
|
@@ -959,29 +1269,23 @@
|
|
|
959
1269
|
}
|
|
960
1270
|
// const octets = new Uint8Array(input);
|
|
961
1271
|
// const octets = types.binary.decode(types.binary.encode(input));
|
|
962
|
-
return new Uint8Array(
|
|
1272
|
+
return new Uint8Array(
|
|
1273
|
+
// Should allow DataView
|
|
1274
|
+
/** @type {ArrayBuffer} */
|
|
1275
|
+
'buffer' in O && O.buffer || O, offset, length);
|
|
963
1276
|
}
|
|
964
1277
|
|
|
965
|
-
/**
|
|
966
|
-
* @typedef {PlainObject} module:Key.keyValueObject
|
|
967
|
-
* @property {module:Key.KeyType|"NaN"} type
|
|
968
|
-
* @property {*} [value]
|
|
969
|
-
* @property {boolean} [invalid]
|
|
970
|
-
* @property {string} [message]
|
|
971
|
-
* @todo Specify acceptable `value` more precisely
|
|
972
|
-
*/
|
|
973
|
-
|
|
974
1278
|
/**
|
|
975
1279
|
* Shortcut utility to avoid returning full keys from `convertValueToKey`
|
|
976
1280
|
* and subsequent need to process in calling code unless `fullKeys` is
|
|
977
1281
|
* set; may throw.
|
|
978
|
-
* @param {
|
|
979
|
-
* @param {
|
|
1282
|
+
* @param {Value} input
|
|
1283
|
+
* @param {Value[]|null} [seen]
|
|
980
1284
|
* @param {boolean} [multiEntry]
|
|
981
1285
|
* @param {boolean} [fullKeys]
|
|
982
1286
|
* @throws {TypeError} See `getCopyBytesHeldByBufferSource`
|
|
983
1287
|
* @todo Document other allowable `input`
|
|
984
|
-
* @returns {
|
|
1288
|
+
* @returns {KeyValueObject}
|
|
985
1289
|
*/
|
|
986
1290
|
function convertValueToKeyValueDecoded(input, seen, multiEntry, fullKeys) {
|
|
987
1291
|
seen = seen || [];
|
|
@@ -1016,18 +1320,18 @@
|
|
|
1016
1320
|
value: 0
|
|
1017
1321
|
};
|
|
1018
1322
|
}
|
|
1019
|
-
return ret;
|
|
1323
|
+
return /** @type {{type: KeyType; value: Value}} */ret;
|
|
1020
1324
|
}
|
|
1021
1325
|
case 'string':
|
|
1022
1326
|
{
|
|
1023
|
-
return ret;
|
|
1327
|
+
return /** @type {{type: KeyType; value: Value}} */ret;
|
|
1024
1328
|
}
|
|
1025
1329
|
case 'binary':
|
|
1026
1330
|
{
|
|
1027
1331
|
// May throw (if detached)
|
|
1028
1332
|
// Get a copy of the bytes held by the buffer source
|
|
1029
1333
|
// https://heycam.github.io/webidl/#ref-for-dfn-get-buffer-source-copy-2
|
|
1030
|
-
var octets = getCopyBytesHeldByBufferSource(input);
|
|
1334
|
+
var octets = getCopyBytesHeldByBufferSource( /** @type {BufferSource} */input);
|
|
1031
1335
|
return {
|
|
1032
1336
|
type: 'binary',
|
|
1033
1337
|
value: octets
|
|
@@ -1036,52 +1340,56 @@
|
|
|
1036
1340
|
case 'array':
|
|
1037
1341
|
{
|
|
1038
1342
|
// May throw (from binary)
|
|
1039
|
-
var
|
|
1343
|
+
var arr = /** @type {Array<any>} */input;
|
|
1344
|
+
var len = arr.length;
|
|
1040
1345
|
seen.push(input);
|
|
1346
|
+
|
|
1347
|
+
/** @type {(KeyValueObject|Value)[]} */
|
|
1041
1348
|
var keys = [];
|
|
1042
1349
|
var _loop = function _loop() {
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
return {
|
|
1046
|
-
v: {
|
|
1047
|
-
type: type,
|
|
1048
|
-
invalid: true,
|
|
1049
|
-
message: 'Does not have own index property'
|
|
1050
|
-
}
|
|
1051
|
-
};
|
|
1052
|
-
}
|
|
1053
|
-
try {
|
|
1054
|
-
var entry = input[i];
|
|
1055
|
-
var key = convertValueToKeyValueDecoded(entry, seen, false, fullKeys); // Though steps do not list rethrowing, the next is returnifabrupt when not multiEntry
|
|
1056
|
-
if (key.invalid) {
|
|
1057
|
-
if (multiEntry) {
|
|
1058
|
-
return "continue";
|
|
1059
|
-
}
|
|
1350
|
+
// We cannot iterate here with array extras as we must ensure sparse arrays are invalidated
|
|
1351
|
+
if (!multiEntry && !Object.hasOwn(arr, i)) {
|
|
1060
1352
|
return {
|
|
1061
1353
|
v: {
|
|
1062
1354
|
type: type,
|
|
1063
1355
|
invalid: true,
|
|
1064
|
-
message: '
|
|
1356
|
+
message: 'Does not have own index property'
|
|
1065
1357
|
}
|
|
1066
1358
|
};
|
|
1067
1359
|
}
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1360
|
+
try {
|
|
1361
|
+
var entry = arr[i];
|
|
1362
|
+
var key = convertValueToKeyValueDecoded(entry, seen, false, fullKeys); // Though steps do not list rethrowing, the next is returnifabrupt when not multiEntry
|
|
1363
|
+
if (key.invalid) {
|
|
1364
|
+
if (multiEntry) {
|
|
1365
|
+
return 0; // continue
|
|
1366
|
+
}
|
|
1367
|
+
return {
|
|
1368
|
+
v: {
|
|
1369
|
+
type: type,
|
|
1370
|
+
invalid: true,
|
|
1371
|
+
message: 'Bad array entry value-to-key conversion'
|
|
1372
|
+
}
|
|
1373
|
+
};
|
|
1374
|
+
}
|
|
1375
|
+
if (!multiEntry || !fullKeys && keys.every(function (k) {
|
|
1376
|
+
return cmp(k, key.value) !== 0;
|
|
1377
|
+
}) || fullKeys && keys.every(function (k) {
|
|
1378
|
+
return cmp(k, key) !== 0;
|
|
1379
|
+
})) {
|
|
1380
|
+
keys.push(fullKeys ? key : key.value);
|
|
1381
|
+
}
|
|
1382
|
+
} catch (err) {
|
|
1383
|
+
if (!multiEntry) {
|
|
1384
|
+
throw err;
|
|
1385
|
+
}
|
|
1078
1386
|
}
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1387
|
+
},
|
|
1388
|
+
_ret;
|
|
1081
1389
|
for (var i = 0; i < len; i++) {
|
|
1082
|
-
|
|
1083
|
-
if (_ret ===
|
|
1084
|
-
if (
|
|
1390
|
+
_ret = _loop();
|
|
1391
|
+
if (_ret === 0) continue;
|
|
1392
|
+
if (_ret) return _ret.v;
|
|
1085
1393
|
}
|
|
1086
1394
|
return {
|
|
1087
1395
|
type: type,
|
|
@@ -1090,13 +1398,14 @@
|
|
|
1090
1398
|
}
|
|
1091
1399
|
case 'date':
|
|
1092
1400
|
{
|
|
1093
|
-
|
|
1401
|
+
var date = /** @type {Date} */input;
|
|
1402
|
+
if (!Number.isNaN(date.getTime())) {
|
|
1094
1403
|
return fullKeys ? {
|
|
1095
1404
|
type: type,
|
|
1096
|
-
value:
|
|
1405
|
+
value: date.getTime()
|
|
1097
1406
|
} : {
|
|
1098
1407
|
type: type,
|
|
1099
|
-
value: new Date(
|
|
1408
|
+
value: new Date(date.getTime())
|
|
1100
1409
|
};
|
|
1101
1410
|
}
|
|
1102
1411
|
return {
|
|
@@ -1110,7 +1419,7 @@
|
|
|
1110
1419
|
default:
|
|
1111
1420
|
{
|
|
1112
1421
|
// Other `typeof` types which are not valid keys:
|
|
1113
|
-
// 'undefined', 'boolean', 'object' (including `null`), 'symbol', 'function
|
|
1422
|
+
// 'undefined', 'boolean', 'object' (including `null`), 'symbol', 'function'
|
|
1114
1423
|
var _type = input === null ? 'null' : _typeof(input); // Convert `null` for convenience of consumers in reporting errors
|
|
1115
1424
|
return {
|
|
1116
1425
|
type: _type,
|
|
@@ -1121,16 +1430,11 @@
|
|
|
1121
1430
|
}
|
|
1122
1431
|
}
|
|
1123
1432
|
|
|
1124
|
-
/**
|
|
1125
|
-
* @typedef {*} module:Key.Key
|
|
1126
|
-
* @todo Specify possible value more precisely
|
|
1127
|
-
*/
|
|
1128
|
-
|
|
1129
1433
|
/**
|
|
1130
1434
|
*
|
|
1131
|
-
* @param {
|
|
1132
|
-
* @param {boolean} fullKeys
|
|
1133
|
-
* @returns {
|
|
1435
|
+
* @param {Key} key
|
|
1436
|
+
* @param {boolean} [fullKeys]
|
|
1437
|
+
* @returns {KeyValueObject}
|
|
1134
1438
|
* @todo Document other allowable `key`?
|
|
1135
1439
|
*/
|
|
1136
1440
|
function convertValueToMultiEntryKeyDecoded(key, fullKeys) {
|
|
@@ -1139,10 +1443,10 @@
|
|
|
1139
1443
|
|
|
1140
1444
|
/**
|
|
1141
1445
|
* An internal utility.
|
|
1142
|
-
* @param input
|
|
1143
|
-
* @param {
|
|
1446
|
+
* @param {Value} input
|
|
1447
|
+
* @param {Value[]|null|undefined} [seen]
|
|
1144
1448
|
* @throws {DOMException} `DataError`
|
|
1145
|
-
* @returns {
|
|
1449
|
+
* @returns {KeyValueObject}
|
|
1146
1450
|
*/
|
|
1147
1451
|
function convertValueToKeyRethrowingAndIfInvalid(input, seen) {
|
|
1148
1452
|
var key = convertValueToKey(input, seen);
|
|
@@ -1154,10 +1458,10 @@
|
|
|
1154
1458
|
|
|
1155
1459
|
/**
|
|
1156
1460
|
*
|
|
1157
|
-
* @param value
|
|
1158
|
-
* @param keyPath
|
|
1461
|
+
* @param {Value} value
|
|
1462
|
+
* @param {KeyPath} keyPath
|
|
1159
1463
|
* @param {boolean} multiEntry
|
|
1160
|
-
* @returns {
|
|
1464
|
+
* @returns {KeyValueObject|KeyPathEvaluateValue}
|
|
1161
1465
|
* @todo Document other possible return?
|
|
1162
1466
|
*/
|
|
1163
1467
|
function extractKeyFromValueUsingKeyPath(value, keyPath, multiEntry) {
|
|
@@ -1165,10 +1469,10 @@
|
|
|
1165
1469
|
}
|
|
1166
1470
|
/**
|
|
1167
1471
|
* Not currently in use.
|
|
1168
|
-
* @param value
|
|
1169
|
-
* @param keyPath
|
|
1472
|
+
* @param {Value} value
|
|
1473
|
+
* @param {KeyPath} keyPath
|
|
1170
1474
|
* @param {boolean} multiEntry
|
|
1171
|
-
* @returns {
|
|
1475
|
+
* @returns {KeyPathEvaluateValue}
|
|
1172
1476
|
*/
|
|
1173
1477
|
function evaluateKeyPathOnValue(value, keyPath, multiEntry) {
|
|
1174
1478
|
return evaluateKeyPathOnValueToDecodedValue(value, keyPath);
|
|
@@ -1177,11 +1481,11 @@
|
|
|
1177
1481
|
/**
|
|
1178
1482
|
* May throw, return `{failure: true}` (e.g., non-object on keyPath resolution)
|
|
1179
1483
|
* or `{invalid: true}` (e.g., `NaN`).
|
|
1180
|
-
* @param value
|
|
1181
|
-
* @param keyPath
|
|
1182
|
-
* @param {boolean} multiEntry
|
|
1183
|
-
* @param {boolean} fullKeys
|
|
1184
|
-
* @returns {
|
|
1484
|
+
* @param {Value} value
|
|
1485
|
+
* @param {KeyPath} keyPath
|
|
1486
|
+
* @param {boolean} [multiEntry]
|
|
1487
|
+
* @param {boolean} [fullKeys]
|
|
1488
|
+
* @returns {KeyValueObject|KeyPathEvaluateValue}
|
|
1185
1489
|
* @todo Document other possible return?
|
|
1186
1490
|
*/
|
|
1187
1491
|
function extractKeyValueDecodedFromValueUsingKeyPath(value, keyPath, multiEntry, fullKeys) {
|
|
@@ -1196,26 +1500,37 @@
|
|
|
1196
1500
|
}
|
|
1197
1501
|
|
|
1198
1502
|
/**
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1503
|
+
* Unused?
|
|
1504
|
+
* @typedef {object} KeyPathEvaluateFailure
|
|
1505
|
+
* @property {boolean} failure
|
|
1506
|
+
*/
|
|
1202
1507
|
|
|
1203
1508
|
/**
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1509
|
+
* @typedef {KeyPathEvaluateValueValue[]} KeyPathEvaluateValueValueArray
|
|
1510
|
+
*/
|
|
1511
|
+
|
|
1512
|
+
/**
|
|
1513
|
+
* @typedef {undefined|number|string|Date|object|KeyPathEvaluateValueValueArray} KeyPathEvaluateValueValue
|
|
1514
|
+
*/
|
|
1515
|
+
|
|
1516
|
+
/**
|
|
1517
|
+
* @typedef {object} KeyPathEvaluateValue
|
|
1518
|
+
* @property {KeyPathEvaluateValueValue} [value]
|
|
1519
|
+
* @property {boolean} [failure]
|
|
1520
|
+
*/
|
|
1207
1521
|
|
|
1208
1522
|
/**
|
|
1209
1523
|
* Returns the value of an inline key based on a key path (wrapped in an
|
|
1210
1524
|
* object with key `value`) or `{failure: true}`
|
|
1211
|
-
* @param {
|
|
1212
|
-
* @param {
|
|
1213
|
-
* @param {boolean} multiEntry
|
|
1525
|
+
* @param {Value} value
|
|
1526
|
+
* @param {KeyPath} keyPath
|
|
1527
|
+
* @param {boolean} [multiEntry]
|
|
1214
1528
|
* @param {boolean} [fullKeys]
|
|
1215
|
-
* @returns {
|
|
1529
|
+
* @returns {KeyPathEvaluateValue}
|
|
1216
1530
|
*/
|
|
1217
1531
|
function evaluateKeyPathOnValueToDecodedValue(value, keyPath, multiEntry, fullKeys) {
|
|
1218
1532
|
if (Array.isArray(keyPath)) {
|
|
1533
|
+
/** @type {KeyPathEvaluateValueValueArray} */
|
|
1219
1534
|
var result = [];
|
|
1220
1535
|
return keyPath.some(function (item) {
|
|
1221
1536
|
var key = evaluateKeyPathOnValueToDecodedValue(value, item);
|
|
@@ -1236,30 +1551,30 @@
|
|
|
1236
1551
|
};
|
|
1237
1552
|
}
|
|
1238
1553
|
var identifiers = keyPath.split('.');
|
|
1239
|
-
return identifiers.some(function (idntfr
|
|
1554
|
+
return identifiers.some(function (idntfr) {
|
|
1240
1555
|
if (idntfr === 'length' && (typeof value === 'string' || Array.isArray(value))) {
|
|
1241
1556
|
value = value.length;
|
|
1242
1557
|
} else if (isBlob(value)) {
|
|
1243
1558
|
switch (idntfr) {
|
|
1244
1559
|
case 'size':
|
|
1245
1560
|
case 'type':
|
|
1246
|
-
value = value[idntfr];
|
|
1561
|
+
value = /** @type {Blob} */value[idntfr];
|
|
1247
1562
|
break;
|
|
1248
1563
|
}
|
|
1249
1564
|
} else if (isFile(value)) {
|
|
1250
1565
|
switch (idntfr) {
|
|
1251
1566
|
case 'name':
|
|
1252
1567
|
case 'lastModified':
|
|
1253
|
-
value = value[idntfr];
|
|
1568
|
+
value = /** @type {File} */value[idntfr];
|
|
1254
1569
|
break;
|
|
1255
1570
|
case 'lastModifiedDate':
|
|
1256
|
-
value = new Date(value.lastModified);
|
|
1571
|
+
value = new Date( /** @type {File} */value.lastModified);
|
|
1257
1572
|
break;
|
|
1258
1573
|
}
|
|
1259
|
-
} else if (!isObj(value) || !Object.
|
|
1574
|
+
} else if (!isObj(value) || !Object.hasOwn(value, idntfr)) {
|
|
1260
1575
|
return true;
|
|
1261
1576
|
} else {
|
|
1262
|
-
value = value[idntfr];
|
|
1577
|
+
value = /** @type {{[key: string]: KeyPathEvaluateValueValue}} */value[idntfr];
|
|
1263
1578
|
return value === undefined;
|
|
1264
1579
|
}
|
|
1265
1580
|
return false;
|
|
@@ -1272,8 +1587,8 @@
|
|
|
1272
1587
|
|
|
1273
1588
|
/**
|
|
1274
1589
|
* Sets the inline key value.
|
|
1275
|
-
* @param {
|
|
1276
|
-
* @param {
|
|
1590
|
+
* @param {{[key: string]: AnyValue}} value
|
|
1591
|
+
* @param {Key} key
|
|
1277
1592
|
* @param {string} keyPath
|
|
1278
1593
|
* @returns {void}
|
|
1279
1594
|
*/
|
|
@@ -1281,19 +1596,19 @@
|
|
|
1281
1596
|
var identifiers = keyPath.split('.');
|
|
1282
1597
|
var last = identifiers.pop();
|
|
1283
1598
|
identifiers.forEach(function (identifier) {
|
|
1284
|
-
var hop = Object.
|
|
1599
|
+
var hop = Object.hasOwn(value, identifier);
|
|
1285
1600
|
if (!hop) {
|
|
1286
1601
|
value[identifier] = {};
|
|
1287
1602
|
}
|
|
1288
1603
|
value = value[identifier];
|
|
1289
1604
|
});
|
|
1290
|
-
value[last] = key; // key is already a `keyValue` in our processing so no need to convert
|
|
1605
|
+
value[( /** @type {string} */last)] = key; // key is already a `keyValue` in our processing so no need to convert
|
|
1291
1606
|
}
|
|
1292
1607
|
|
|
1293
1608
|
/**
|
|
1294
1609
|
*
|
|
1295
|
-
* @param value
|
|
1296
|
-
* @param keyPath
|
|
1610
|
+
* @param {Value} value
|
|
1611
|
+
* @param {string} keyPath
|
|
1297
1612
|
* @see https://github.com/w3c/IndexedDB/pull/146
|
|
1298
1613
|
* @returns {boolean}
|
|
1299
1614
|
*/
|
|
@@ -1308,11 +1623,11 @@
|
|
|
1308
1623
|
if (!isObj(value)) {
|
|
1309
1624
|
return false;
|
|
1310
1625
|
}
|
|
1311
|
-
var hop = Object.
|
|
1626
|
+
var hop = Object.hasOwn(value, identifier);
|
|
1312
1627
|
if (!hop) {
|
|
1313
1628
|
return true;
|
|
1314
1629
|
}
|
|
1315
|
-
value = value[identifier];
|
|
1630
|
+
value = /** @type {{[key: string]: Value}} */value[identifier];
|
|
1316
1631
|
}
|
|
1317
1632
|
} catch (err) {
|
|
1318
1633
|
_iterator3.e(err);
|
|
@@ -1324,9 +1639,9 @@
|
|
|
1324
1639
|
|
|
1325
1640
|
/**
|
|
1326
1641
|
*
|
|
1327
|
-
* @param {
|
|
1328
|
-
* @param {IDBKeyRange} range
|
|
1329
|
-
* @param {boolean} checkCached
|
|
1642
|
+
* @param {Key} key
|
|
1643
|
+
* @param {import('./IDBKeyRange.js').IDBKeyRangeFull} range
|
|
1644
|
+
* @param {boolean} [checkCached]
|
|
1330
1645
|
* @returns {boolean}
|
|
1331
1646
|
*/
|
|
1332
1647
|
function isKeyInRange(key, range, checkCached) {
|
|
@@ -1335,21 +1650,11 @@
|
|
|
1335
1650
|
var encodedKey = _encode(key, true);
|
|
1336
1651
|
var lower = checkCached ? range.__lowerCached : _encode(range.lower, true);
|
|
1337
1652
|
var upper = checkCached ? range.__upperCached : _encode(range.upper, true);
|
|
1338
|
-
if (range.lower !==
|
|
1339
|
-
|
|
1340
|
-
lowerMatch = true;
|
|
1341
|
-
}
|
|
1342
|
-
if (!range.lowerOpen && encodedKey >= lower) {
|
|
1343
|
-
lowerMatch = true;
|
|
1344
|
-
}
|
|
1653
|
+
if (!lowerMatch && (range.lowerOpen && encodedKey !== null && lower !== null && encodedKey > lower || !range.lowerOpen && (!encodedKey && !lower || encodedKey !== null && lower !== null && encodedKey >= lower))) {
|
|
1654
|
+
lowerMatch = true;
|
|
1345
1655
|
}
|
|
1346
|
-
if (range.upper !==
|
|
1347
|
-
|
|
1348
|
-
upperMatch = true;
|
|
1349
|
-
}
|
|
1350
|
-
if (!range.upperOpen && encodedKey <= upper) {
|
|
1351
|
-
upperMatch = true;
|
|
1352
|
-
}
|
|
1656
|
+
if (!upperMatch && (range.upperOpen && encodedKey !== null && upper !== null && encodedKey < upper || !range.upperOpen && (!encodedKey && !upper || encodedKey !== null && upper !== null && encodedKey <= upper))) {
|
|
1657
|
+
upperMatch = true;
|
|
1353
1658
|
}
|
|
1354
1659
|
return lowerMatch && upperMatch;
|
|
1355
1660
|
}
|
|
@@ -1370,9 +1675,9 @@
|
|
|
1370
1675
|
|
|
1371
1676
|
/**
|
|
1372
1677
|
*
|
|
1373
|
-
* @param {
|
|
1374
|
-
* @param {IDBKeyRange} range
|
|
1375
|
-
* @returns {
|
|
1678
|
+
* @param {Key} keyEntry
|
|
1679
|
+
* @param {import('./IDBKeyRange.js').IDBKeyRangeFull|undefined} range
|
|
1680
|
+
* @returns {Key[]}
|
|
1376
1681
|
*/
|
|
1377
1682
|
function findMultiEntryMatches(keyEntry, range) {
|
|
1378
1683
|
var matches = [];
|
|
@@ -1411,15 +1716,11 @@
|
|
|
1411
1716
|
return matches;
|
|
1412
1717
|
}
|
|
1413
1718
|
|
|
1414
|
-
/**
|
|
1415
|
-
* @typedef {number|string|Date|ArrayBuffer|module:Key.ValueTypes[]} module:Key.ValueTypes
|
|
1416
|
-
*/
|
|
1417
|
-
|
|
1418
1719
|
/**
|
|
1419
1720
|
* Not currently in use but keeping for spec parity.
|
|
1420
|
-
* @param {
|
|
1721
|
+
* @param {Key} key
|
|
1421
1722
|
* @throws {Error} Upon a "bad key"
|
|
1422
|
-
* @returns {
|
|
1723
|
+
* @returns {ValueType}
|
|
1423
1724
|
*/
|
|
1424
1725
|
function convertKeyToValue(key) {
|
|
1425
1726
|
var type = key.type,
|
|
@@ -1463,8 +1764,8 @@
|
|
|
1463
1764
|
|
|
1464
1765
|
/**
|
|
1465
1766
|
*
|
|
1466
|
-
* @param {
|
|
1467
|
-
* @param {boolean} inArray
|
|
1767
|
+
* @param {Key} key
|
|
1768
|
+
* @param {boolean} [inArray]
|
|
1468
1769
|
* @returns {string|null}
|
|
1469
1770
|
*/
|
|
1470
1771
|
function _encode(key, inArray) {
|
|
@@ -1473,15 +1774,16 @@
|
|
|
1473
1774
|
return null;
|
|
1474
1775
|
}
|
|
1475
1776
|
// array, date, number, string, binary (should already have detected "invalid")
|
|
1777
|
+
// @ts-expect-error Argument may be ignored
|
|
1476
1778
|
return types[getKeyType(key)].encode(key, inArray);
|
|
1477
1779
|
}
|
|
1478
1780
|
|
|
1479
1781
|
/**
|
|
1480
1782
|
*
|
|
1481
|
-
* @param {
|
|
1482
|
-
* @param {boolean} inArray
|
|
1783
|
+
* @param {Key} key
|
|
1784
|
+
* @param {boolean} [inArray]
|
|
1483
1785
|
* @throws {Error} Invalid number
|
|
1484
|
-
* @returns {undefined|
|
|
1786
|
+
* @returns {undefined|ValueType}
|
|
1485
1787
|
*/
|
|
1486
1788
|
function _decode(key, inArray) {
|
|
1487
1789
|
if (typeof key !== 'string') {
|
|
@@ -1492,9 +1794,9 @@
|
|
|
1492
1794
|
|
|
1493
1795
|
/**
|
|
1494
1796
|
*
|
|
1495
|
-
* @param {
|
|
1496
|
-
* @param {boolean} inArray
|
|
1497
|
-
* @returns {undefined|
|
|
1797
|
+
* @param {Key} key
|
|
1798
|
+
* @param {boolean} [inArray]
|
|
1799
|
+
* @returns {undefined|ValueType}
|
|
1498
1800
|
*/
|
|
1499
1801
|
function roundTrip(key, inArray) {
|
|
1500
1802
|
return _decode(_encode(key, inArray), inArray);
|
|
@@ -1502,30 +1804,25 @@
|
|
|
1502
1804
|
var MAX_ALLOWED_CURRENT_NUMBER = 9007199254740992; // 2 ^ 53 (Also equal to `Number.MAX_SAFE_INTEGER + 1`)
|
|
1503
1805
|
|
|
1504
1806
|
/**
|
|
1505
|
-
* @
|
|
1807
|
+
* @typedef {number} Integer
|
|
1506
1808
|
*/
|
|
1507
1809
|
|
|
1508
|
-
/**
|
|
1509
|
-
* @typedef {IDBObjectStore} IDBObjectStoreWithCurrentName
|
|
1510
|
-
* @property {string} __currentName
|
|
1511
|
-
*/
|
|
1512
|
-
|
|
1513
1810
|
/**
|
|
1514
1811
|
* @callback CurrentNumberCallback
|
|
1515
|
-
* @param {Integer} The current number
|
|
1812
|
+
* @param {Integer} cn The current number
|
|
1516
1813
|
* @returns {void}
|
|
1517
1814
|
*/
|
|
1518
1815
|
|
|
1519
1816
|
/**
|
|
1520
1817
|
* @callback SQLFailureCallback
|
|
1521
|
-
* @param {DOMException} exception
|
|
1818
|
+
* @param {DOMException|Error} exception
|
|
1522
1819
|
* @returns {void}
|
|
1523
1820
|
*/
|
|
1524
1821
|
|
|
1525
1822
|
/**
|
|
1526
1823
|
*
|
|
1527
|
-
* @param {
|
|
1528
|
-
* @param {
|
|
1824
|
+
* @param {SQLTransaction} tx
|
|
1825
|
+
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
|
|
1529
1826
|
* @param {CurrentNumberCallback} func
|
|
1530
1827
|
* @param {SQLFailureCallback} sqlFailCb
|
|
1531
1828
|
* @returns {void}
|
|
@@ -1539,13 +1836,14 @@
|
|
|
1539
1836
|
}
|
|
1540
1837
|
}, function (tx, error) {
|
|
1541
1838
|
sqlFailCb(createDOMException('DataError', 'Could not get the auto increment value for key', error));
|
|
1839
|
+
return false;
|
|
1542
1840
|
});
|
|
1543
1841
|
}
|
|
1544
1842
|
|
|
1545
1843
|
/**
|
|
1546
1844
|
*
|
|
1547
|
-
* @param {
|
|
1548
|
-
* @param {
|
|
1845
|
+
* @param {SQLTransaction} tx
|
|
1846
|
+
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
|
|
1549
1847
|
* @param {Integer} num
|
|
1550
1848
|
* @param {CurrentNumberCallback} successCb
|
|
1551
1849
|
* @param {SQLFailureCallback} failCb
|
|
@@ -1554,11 +1852,14 @@
|
|
|
1554
1852
|
function assignCurrentNumber(tx, store, num, successCb, failCb) {
|
|
1555
1853
|
var sql = 'UPDATE __sys__ SET "currNum" = ? WHERE "name" = ?';
|
|
1556
1854
|
var sqlValues = [num, escapeSQLiteStatement(store.__currentName)];
|
|
1557
|
-
CFG.DEBUG
|
|
1558
|
-
|
|
1855
|
+
if (CFG.DEBUG) {
|
|
1856
|
+
console.log(sql, sqlValues);
|
|
1857
|
+
}
|
|
1858
|
+
tx.executeSql(sql, sqlValues, function () {
|
|
1559
1859
|
successCb(num);
|
|
1560
1860
|
}, function (tx, err) {
|
|
1561
1861
|
failCb(createDOMException('UnknownError', 'Could not set the auto increment value for key', err));
|
|
1862
|
+
return false;
|
|
1562
1863
|
});
|
|
1563
1864
|
}
|
|
1564
1865
|
|
|
@@ -1566,8 +1867,8 @@
|
|
|
1566
1867
|
* Bump up the auto-inc counter if the key path-resolved value is valid
|
|
1567
1868
|
* (greater than old value and >=1) OR if a manually passed in key is
|
|
1568
1869
|
* valid (numeric and >= 1) and >= any primaryKey.
|
|
1569
|
-
* @param {
|
|
1570
|
-
* @param {
|
|
1870
|
+
* @param {SQLTransaction} tx
|
|
1871
|
+
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
|
|
1571
1872
|
* @param {Integer} num
|
|
1572
1873
|
* @param {CurrentNumberCallback} successCb
|
|
1573
1874
|
* @param {SQLFailureCallback} failCb
|
|
@@ -1589,8 +1890,8 @@
|
|
|
1589
1890
|
|
|
1590
1891
|
/**
|
|
1591
1892
|
*
|
|
1592
|
-
* @param {
|
|
1593
|
-
* @param {
|
|
1893
|
+
* @param {SQLTransaction} tx
|
|
1894
|
+
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
|
|
1594
1895
|
* @param {KeyForStoreCallback} cb
|
|
1595
1896
|
* @param {SQLFailureCallback} sqlFailCb
|
|
1596
1897
|
* @returns {void}
|
|
@@ -1616,10 +1917,10 @@
|
|
|
1616
1917
|
// so we do not return a key
|
|
1617
1918
|
/**
|
|
1618
1919
|
*
|
|
1619
|
-
* @param {
|
|
1620
|
-
* @param {
|
|
1621
|
-
* @param {
|
|
1622
|
-
* @param {
|
|
1920
|
+
* @param {SQLTransaction} tx
|
|
1921
|
+
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
|
|
1922
|
+
* @param {import('./Key.js').Key} key
|
|
1923
|
+
* @param {(num?: Integer) => void} successCb
|
|
1623
1924
|
* @param {SQLFailureCallback} sqlFailCb
|
|
1624
1925
|
* @returns {void}
|
|
1625
1926
|
*/
|