indexeddbshim 12.0.0 → 13.0.0-pre.1

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.
Files changed (97) hide show
  1. package/dist/CFG.d.ts +80 -0
  2. package/dist/CFG.d.ts.map +1 -0
  3. package/dist/DOMException.d.ts +71 -0
  4. package/dist/DOMException.d.ts.map +1 -0
  5. package/dist/DOMStringList.d.ts +20 -0
  6. package/dist/DOMStringList.d.ts.map +1 -0
  7. package/dist/Event.d.ts +21 -0
  8. package/dist/Event.d.ts.map +1 -0
  9. package/dist/IDBCursor.d.ts +288 -0
  10. package/dist/IDBCursor.d.ts.map +1 -0
  11. package/dist/IDBDatabase.d.ts +143 -0
  12. package/dist/IDBDatabase.d.ts.map +1 -0
  13. package/dist/IDBFactory.d.ts +96 -0
  14. package/dist/IDBFactory.d.ts.map +1 -0
  15. package/dist/IDBIndex.d.ts +243 -0
  16. package/dist/IDBIndex.d.ts.map +1 -0
  17. package/dist/IDBKeyRange.d.ts +79 -0
  18. package/dist/IDBKeyRange.d.ts.map +1 -0
  19. package/dist/IDBObjectStore.d.ts +273 -0
  20. package/dist/IDBObjectStore.d.ts.map +1 -0
  21. package/dist/IDBRequest.d.ts +88 -0
  22. package/dist/IDBRequest.d.ts.map +1 -0
  23. package/dist/IDBTransaction.d.ts +270 -0
  24. package/dist/IDBTransaction.d.ts.map +1 -0
  25. package/dist/IDBVersionChangeEvent.d.ts +22 -0
  26. package/dist/IDBVersionChangeEvent.d.ts.map +1 -0
  27. package/dist/Key.d.ts +214 -0
  28. package/dist/Key.d.ts.map +1 -0
  29. package/dist/Sca.d.ts +31 -0
  30. package/dist/Sca.d.ts.map +1 -0
  31. package/dist/UnicodeIdentifiers.d.ts +3 -0
  32. package/dist/UnicodeIdentifiers.d.ts.map +1 -0
  33. package/dist/browser-UnicodeIdentifiers.d.ts +2 -0
  34. package/dist/browser-UnicodeIdentifiers.d.ts.map +1 -0
  35. package/dist/browser-noninvasive.d.ts +3 -0
  36. package/dist/browser-noninvasive.d.ts.map +1 -0
  37. package/dist/browser.d.ts +2 -0
  38. package/dist/browser.d.ts.map +1 -0
  39. package/dist/cmp.d.ts +9 -0
  40. package/dist/cmp.d.ts.map +1 -0
  41. package/dist/indexeddbshim-Key.js +482 -189
  42. package/dist/indexeddbshim-Key.js.map +1 -1
  43. package/dist/indexeddbshim-Key.min.js +2 -2
  44. package/dist/indexeddbshim-Key.min.js.map +1 -1
  45. package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs +17256 -1335
  46. package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
  47. package/dist/indexeddbshim-UnicodeIdentifiers.js +3870 -1280
  48. package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
  49. package/dist/indexeddbshim-UnicodeIdentifiers.min.js +2 -2
  50. package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
  51. package/dist/indexeddbshim-node.cjs +17252 -1335
  52. package/dist/indexeddbshim-node.cjs.map +1 -1
  53. package/dist/indexeddbshim-noninvasive.js +3864 -1279
  54. package/dist/indexeddbshim-noninvasive.js.map +1 -1
  55. package/dist/indexeddbshim-noninvasive.min.js +2 -2
  56. package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
  57. package/dist/indexeddbshim.js +3864 -1279
  58. package/dist/indexeddbshim.js.map +1 -1
  59. package/dist/indexeddbshim.min.js +2 -2
  60. package/dist/indexeddbshim.min.js.map +1 -1
  61. package/dist/node-UnicodeIdentifiers.d.ts +8 -0
  62. package/dist/node-UnicodeIdentifiers.d.ts.map +1 -0
  63. package/dist/node.d.ts +8 -0
  64. package/dist/node.d.ts.map +1 -0
  65. package/dist/nodeWebSQL.d.ts +3 -0
  66. package/dist/nodeWebSQL.d.ts.map +1 -0
  67. package/dist/setGlobalVars.d.ts +79 -0
  68. package/dist/setGlobalVars.d.ts.map +1 -0
  69. package/dist/unicode-regex.d.ts +3 -0
  70. package/dist/unicode-regex.d.ts.map +1 -0
  71. package/dist/util.d.ts +174 -0
  72. package/dist/util.d.ts.map +1 -0
  73. package/package.json +38 -25
  74. package/src/CFG.js +89 -11
  75. package/src/DOMException.js +116 -29
  76. package/src/DOMStringList.js +92 -2
  77. package/src/Event.js +19 -4
  78. package/src/IDBCursor.js +339 -67
  79. package/src/IDBDatabase.js +87 -10
  80. package/src/IDBFactory.js +319 -56
  81. package/src/IDBIndex.js +385 -96
  82. package/src/IDBKeyRange.js +86 -13
  83. package/src/IDBObjectStore.js +326 -68
  84. package/src/IDBRequest.js +59 -1
  85. package/src/IDBTransaction.js +247 -38
  86. package/src/IDBVersionChangeEvent.js +28 -3
  87. package/src/Key.js +267 -156
  88. package/src/Sca.js +29 -4
  89. package/src/browser-UnicodeIdentifiers.js +5 -1
  90. package/src/cmp.js +5 -5
  91. package/src/node-UnicodeIdentifiers.js +9 -0
  92. package/src/node.js +5 -0
  93. package/src/nodeWebSQL.js +11 -5
  94. package/src/setGlobalVars.js +156 -21
  95. package/src/unicode-regex.js +2 -0
  96. package/src/util.js +228 -40
  97. package/typings/shimIndexedDB.d.ts +9 -0
package/src/Key.js CHANGED
@@ -4,12 +4,57 @@ import cmp from './cmp.js';
4
4
  import CFG from './CFG.js';
5
5
 
6
6
  /**
7
- * @module Key
7
+ * @typedef {NodeJS.TypedArray|DataView} ArrayBufferView
8
+ */
9
+
10
+ /**
11
+ * @typedef {ArrayBufferView|ArrayBuffer} BufferSource
12
+ */
13
+
14
+ /**
15
+ * @typedef {"number"|"date"|"string"|"binary"|"array"} KeyType
16
+ */
17
+
18
+ /**
19
+ * @typedef {any} Value
20
+ */
21
+
22
+ /**
23
+ * @typedef {any} Key
24
+ * @todo Specify possible value more precisely
25
+ */
26
+
27
+ /**
28
+ * @typedef {KeyPath[]} KeyPathArray
29
+ */
30
+ /**
31
+ * @typedef {string|KeyPathArray} KeyPath
32
+ */
33
+
34
+ /**
35
+ * @typedef {object} KeyValueObject
36
+ * @property {KeyType|"NaN"|"null"|"undefined"|"boolean"|"object"|"symbol"|
37
+ * "function"|"bigint"} type If not `KeyType`, indicates invalid value
38
+ * @property {Value} [value]
39
+ * @property {boolean} [invalid]
40
+ * @property {string} [message]
41
+ * @todo Specify acceptable `value` more precisely
42
+ */
43
+
44
+ /**
45
+ * @typedef {number|string|Date|ArrayBuffer} ValueTypePrimitive
46
+ */
47
+ /**
48
+ * @typedef {ValueType[]} ValueTypeArray
49
+ */
50
+ /**
51
+ * @typedef {ValueTypePrimitive|ValueTypeArray} ValueType
8
52
  */
9
53
 
10
54
  /**
11
55
  * Encodes the keys based on their types. This is required to maintain collations
12
56
  * We leave space for future keys.
57
+ * @type {{[key: string]: Integer|string}}
13
58
  */
14
59
  const keyTypeToEncodedChar = {
15
60
  invalid: 100,
@@ -19,15 +64,17 @@ const keyTypeToEncodedChar = {
19
64
  binary: 500,
20
65
  array: 600
21
66
  };
22
- const keyTypes = Object.keys(keyTypeToEncodedChar);
67
+ const keyTypes = /** @type {(KeyType|"invalid")[]} */ (Object.keys(keyTypeToEncodedChar));
23
68
  keyTypes.forEach((k) => {
24
- keyTypeToEncodedChar[k] = String.fromCodePoint(keyTypeToEncodedChar[k]);
69
+ keyTypeToEncodedChar[k] = String.fromCodePoint(
70
+ /** @type {number} */ (keyTypeToEncodedChar[k])
71
+ );
25
72
  });
26
73
 
27
74
  const encodedCharToKeyType = keyTypes.reduce((o, k) => {
28
75
  o[keyTypeToEncodedChar[k]] = k;
29
76
  return o;
30
- }, {});
77
+ }, /** @type {{[key: string]: KeyType|"invalid"}} */ ({}));
31
78
 
32
79
  /**
33
80
  * The sign values for numbers, ordered from least to greatest.
@@ -40,12 +87,24 @@ const encodedCharToKeyType = keyTypes.reduce((o, k) => {
40
87
  */
41
88
  const signValues = ['negativeInfinity', 'bigNegative', 'smallNegative', 'smallPositive', 'bigPositive', 'positiveInfinity'];
42
89
 
90
+ /**
91
+ * @typedef {any} AnyValue
92
+ */
93
+
43
94
  const types = {
44
95
  invalid: {
45
- encode (key) {
96
+ /**
97
+ * @param {AnyValue} _key
98
+ * @returns {string}
99
+ */
100
+ encode (_key) {
46
101
  return keyTypeToEncodedChar.invalid + '-';
47
102
  },
48
- decode (key) {
103
+ /**
104
+ * @param {string} _key
105
+ * @returns {undefined}
106
+ */
107
+ decode (_key) {
49
108
  return undefined;
50
109
  }
51
110
  },
@@ -63,6 +122,10 @@ const types = {
63
122
  number: {
64
123
  // The encode step checks for six numeric cases and generates 14-digit encoded
65
124
  // sign-exponent-mantissa strings.
125
+ /**
126
+ * @param {number} key
127
+ * @returns {string}
128
+ */
66
129
  encode (key) {
67
130
  let key32 = key === Number.MIN_VALUE
68
131
  // Mocha test `IDBFactory/cmp-spec.js` exposed problem for some
@@ -128,6 +191,10 @@ const types = {
128
191
  // The decode step must interpret the sign, reflip values encoded as the 32's complements,
129
192
  // apply signs to the exponent and mantissa, do the base-32 power operation, and return
130
193
  // the original JavaScript number values.
194
+ /**
195
+ * @param {string} key
196
+ * @returns {number}
197
+ */
131
198
  decode (key) {
132
199
  const sign = Number(key.slice(2, 3));
133
200
  let exponent = key.slice(3, 5);
@@ -166,18 +233,28 @@ const types = {
166
233
  // This effectively doubles the size of every string, but it ensures that when two arrays of strings are compared,
167
234
  // the indexes of each string's characters line up with each other.
168
235
  string: {
236
+ /**
237
+ * @param {string} key
238
+ * @param {boolean} [inArray]
239
+ * @returns {string}
240
+ */
169
241
  encode (key, inArray) {
170
242
  if (inArray) {
171
243
  // prepend each character with a dash, and append a space to the end
172
- key = key.replace(/(.)/gu, '-$1') + ' ';
244
+ key = key.replaceAll(/(.)/gu, '-$1') + ' ';
173
245
  }
174
246
  return keyTypeToEncodedChar.string + '-' + key;
175
247
  },
248
+ /**
249
+ * @param {string} key
250
+ * @param {boolean} [inArray]
251
+ * @returns {string}
252
+ */
176
253
  decode (key, inArray) {
177
254
  key = key.slice(2);
178
255
  if (inArray) {
179
256
  // remove the space at the end, and the dash before each character
180
- key = key.slice(0, -1).replace(/-(.)/gu, '$1');
257
+ key = key.slice(0, -1).replaceAll(/-(.)/gu, '$1');
181
258
  }
182
259
  return key;
183
260
  }
@@ -187,6 +264,10 @@ const types = {
187
264
  // An extra, value is added to each array during encoding to make
188
265
  // empty arrays sort correctly.
189
266
  array: {
267
+ /**
268
+ * @param {ValueTypeArray} key
269
+ * @returns {string}
270
+ */
190
271
  encode (key) {
191
272
  const encoded = [];
192
273
  for (const [i, item] of key.entries()) {
@@ -196,6 +277,10 @@ const types = {
196
277
  encoded.push(keyTypeToEncodedChar.invalid + '-'); // append an extra item, so empty arrays sort correctly
197
278
  return keyTypeToEncodedChar.array + '-' + JSON.stringify(encoded);
198
279
  },
280
+ /**
281
+ * @param {string} key
282
+ * @returns {ValueTypeArray}
283
+ */
199
284
  decode (key) {
200
285
  const decoded = JSON.parse(key.slice(2));
201
286
  decoded.pop(); // remove the extra item
@@ -210,15 +295,27 @@ const types = {
210
295
 
211
296
  // Dates are encoded as ISO 8601 strings, in UTC time zone.
212
297
  date: {
298
+ /**
299
+ * @param {Date} key
300
+ * @returns {string}
301
+ */
213
302
  encode (key) {
214
303
  return keyTypeToEncodedChar.date + '-' + key.toJSON();
215
304
  },
305
+ /**
306
+ * @param {string} key
307
+ * @returns {Date}
308
+ */
216
309
  decode (key) {
217
310
  return new Date(key.slice(2));
218
311
  }
219
312
  },
220
313
  binary: {
221
314
  // `ArrayBuffer`/Views on buffers (`TypedArray` or `DataView`)
315
+ /**
316
+ * @param {BufferSource} key
317
+ * @returns {string}
318
+ */
222
319
  encode (key) {
223
320
  return keyTypeToEncodedChar.binary + '-' + (key.byteLength
224
321
  ? [...getCopyBytesHeldByBufferSource(key)].map(
@@ -226,6 +323,10 @@ const types = {
226
323
  ) // e.g., '255,005,254,000,001,033'
227
324
  : '');
228
325
  },
326
+ /**
327
+ * @param {string} key
328
+ * @returns {ArrayBuffer}
329
+ */
229
330
  decode (key) {
230
331
  // Set the entries in buffer's [[ArrayBufferData]] to those in `value`
231
332
  const k = key.slice(2);
@@ -244,8 +345,8 @@ const types = {
244
345
  * @returns {string}
245
346
  */
246
347
  function padBase32Exponent (n) {
247
- n = n.toString(32);
248
- return (n.length === 1) ? '0' + n : n;
348
+ const exp = n.toString(32);
349
+ return (exp.length === 1) ? '0' + exp : exp;
249
350
  }
250
351
 
251
352
  /**
@@ -283,26 +384,30 @@ function flipBase32 (encoded) {
283
384
  * @returns {number}
284
385
  */
285
386
  function pow32 (mantissa, exponent) {
286
- exponent = Number.parseInt(exponent, 32);
287
- if (exponent < 0) {
387
+ const exp = Number.parseInt(exponent, 32);
388
+ if (exp < 0) {
288
389
  return roundToPrecision(
289
- Number.parseInt(mantissa, 32) * (32 ** (exponent - 10))
390
+ Number.parseInt(mantissa, 32) * (32 ** (exp - 10))
290
391
  );
291
392
  }
292
- if (exponent < 11) {
293
- let whole = mantissa.slice(0, exponent);
294
- whole = Number.parseInt(whole, 32);
295
- let fraction = mantissa.slice(exponent);
296
- fraction = Number.parseInt(fraction, 32) * (32 ** (exponent - 11));
297
- return roundToPrecision(whole + fraction);
393
+ if (exp < 11) {
394
+ const whole = mantissa.slice(0, exp);
395
+ const wholeNum = Number.parseInt(whole, 32);
396
+ const fraction = mantissa.slice(exp);
397
+ const fractionNum = Number.parseInt(fraction, 32) * (32 ** (exp - 11));
398
+ return roundToPrecision(wholeNum + fractionNum);
298
399
  }
299
- const expansion = mantissa + zeros(exponent - 11);
400
+ const expansion = mantissa + zeros(exp - 11);
300
401
  return Number.parseInt(expansion, 32);
301
402
  }
302
403
 
404
+ /**
405
+ * @typedef {number} Float
406
+ */
407
+
303
408
  /**
304
409
  * @param {Float} num
305
- * @param {Float} [precision=16]
410
+ * @param {Float} [precision]
306
411
  * @returns {Float}
307
412
  */
308
413
  function roundToPrecision (num, precision = 16) {
@@ -328,27 +433,25 @@ function negate (s) {
328
433
  }
329
434
 
330
435
  /**
331
- * @typedef {"number"|"date"|"string"|"binary"|"array"} module:Key.KeyType
332
- */
333
-
334
- /**
335
- * @param key
336
- * @returns {module:Key.KeyType}
436
+ * @param {Key} key
437
+ * @returns {KeyType|"invalid"}
337
438
  */
338
439
  function getKeyType (key) {
339
440
  if (Array.isArray(key)) return 'array';
340
441
  if (util.isDate(key)) return 'date';
341
442
  if (util.isBinary(key)) return 'binary';
342
443
  const keyType = typeof key;
343
- return ['string', 'number'].includes(keyType) ? keyType : 'invalid';
444
+ return ['string', 'number'].includes(keyType)
445
+ ? /** @type {"string"|"number"} */ (keyType)
446
+ : 'invalid';
344
447
  }
345
448
 
346
449
  /**
347
450
  * Keys must be strings, numbers (besides `NaN`), Dates (if value is not
348
451
  * `NaN`), binary objects or Arrays.
349
- * @param input The key input
350
- * @param {?(Array)} [seen] An array of already seen keys
351
- * @returns {module:Key.keyValueObject}
452
+ * @param {Value} input The key input
453
+ * @param {Value[]|null|undefined} [seen] An array of already seen keys
454
+ * @returns {KeyValueObject}
352
455
  */
353
456
  function convertValueToKey (input, seen) {
354
457
  return convertValueToKeyValueDecoded(input, seen, false, true);
@@ -356,8 +459,8 @@ function convertValueToKey (input, seen) {
356
459
 
357
460
  /**
358
461
  * Currently not in use.
359
- * @param input
360
- * @returns {module:Key.keyValueObject}
462
+ * @param {Value} input
463
+ * @returns {KeyValueObject}
361
464
  */
362
465
  function convertValueToMultiEntryKey (input) {
363
466
  return convertValueToKeyValueDecoded(input, null, true, true);
@@ -365,7 +468,7 @@ function convertValueToMultiEntryKey (input) {
365
468
 
366
469
  /**
367
470
  *
368
- * @param O
471
+ * @param {BufferSource} O
369
472
  * @throws {TypeError}
370
473
  * @see https://heycam.github.io/webidl/#ref-for-dfn-get-buffer-source-copy-2
371
474
  * @returns {Uint8Array}
@@ -387,29 +490,26 @@ function getCopyBytesHeldByBufferSource (O) {
387
490
  }
388
491
  // const octets = new Uint8Array(input);
389
492
  // const octets = types.binary.decode(types.binary.encode(input));
390
- return new Uint8Array(O.buffer || O, offset, length);
493
+ return new Uint8Array(
494
+ // Should allow DataView
495
+ /** @type {ArrayBuffer} */
496
+ (('buffer' in O && O.buffer) || O),
497
+ offset,
498
+ length
499
+ );
391
500
  }
392
501
 
393
- /**
394
- * @typedef {PlainObject} module:Key.keyValueObject
395
- * @property {module:Key.KeyType|"NaN"} type
396
- * @property {*} [value]
397
- * @property {boolean} [invalid]
398
- * @property {string} [message]
399
- * @todo Specify acceptable `value` more precisely
400
- */
401
-
402
502
  /**
403
503
  * Shortcut utility to avoid returning full keys from `convertValueToKey`
404
504
  * and subsequent need to process in calling code unless `fullKeys` is
405
505
  * set; may throw.
406
- * @param {module:Key.Key} input
407
- * @param {?(Array)} [seen]
506
+ * @param {Value} input
507
+ * @param {Value[]|null} [seen]
408
508
  * @param {boolean} [multiEntry]
409
509
  * @param {boolean} [fullKeys]
410
510
  * @throws {TypeError} See `getCopyBytesHeldByBufferSource`
411
511
  * @todo Document other allowable `input`
412
- * @returns {module:Key.keyValueObject}
512
+ * @returns {KeyValueObject}
413
513
  */
414
514
  function convertValueToKeyValueDecoded (input, seen, multiEntry, fullKeys) {
415
515
  seen = seen || [];
@@ -434,24 +534,29 @@ function convertValueToKeyValueDecoded (input, seen, multiEntry, fullKeys) {
434
534
  if (Object.is(input, -0)) {
435
535
  return {type, value: 0};
436
536
  }
437
- return ret;
537
+ return /** @type {{type: KeyType; value: Value}} */ (ret);
438
538
  } case 'string': {
439
- return ret;
539
+ return /** @type {{type: KeyType; value: Value}} */ (ret);
440
540
  } case 'binary': { // May throw (if detached)
441
541
  // Get a copy of the bytes held by the buffer source
442
542
  // https://heycam.github.io/webidl/#ref-for-dfn-get-buffer-source-copy-2
443
- const octets = getCopyBytesHeldByBufferSource(input);
543
+ const octets = getCopyBytesHeldByBufferSource(
544
+ /** @type {BufferSource} */ (input)
545
+ );
444
546
  return {type: 'binary', value: octets};
445
547
  } case 'array': { // May throw (from binary)
446
- const len = input.length;
548
+ const arr = /** @type {Array<any>} */ (input);
549
+ const len = arr.length;
447
550
  seen.push(input);
551
+
552
+ /** @type {(KeyValueObject|Value)[]} */
448
553
  const keys = [];
449
554
  for (let i = 0; i < len; i++) { // We cannot iterate here with array extras as we must ensure sparse arrays are invalidated
450
- if (!multiEntry && !Object.prototype.hasOwnProperty.call(input, i)) {
555
+ if (!multiEntry && !Object.hasOwn(arr, i)) {
451
556
  return {type, invalid: true, message: 'Does not have own index property'};
452
557
  }
453
558
  try {
454
- const entry = input[i];
559
+ const entry = arr[i];
455
560
  const key = convertValueToKeyValueDecoded(entry, seen, false, fullKeys); // Though steps do not list rethrowing, the next is returnifabrupt when not multiEntry
456
561
  if (key.invalid) {
457
562
  if (multiEntry) {
@@ -473,32 +578,28 @@ function convertValueToKeyValueDecoded (input, seen, multiEntry, fullKeys) {
473
578
  }
474
579
  return {type, value: keys};
475
580
  } case 'date': {
476
- if (!Number.isNaN(input.getTime())) {
581
+ const date = /** @type {Date} */ (input);
582
+ if (!Number.isNaN(date.getTime())) {
477
583
  return fullKeys
478
- ? {type, value: input.getTime()}
479
- : {type, value: new Date(input.getTime())};
584
+ ? {type, value: date.getTime()}
585
+ : {type, value: new Date(date.getTime())};
480
586
  }
481
587
  return {type, invalid: true, message: 'Not a valid date'};
482
588
  // Falls through
483
589
  } case 'invalid': default: {
484
590
  // Other `typeof` types which are not valid keys:
485
- // 'undefined', 'boolean', 'object' (including `null`), 'symbol', 'function
591
+ // 'undefined', 'boolean', 'object' (including `null`), 'symbol', 'function'
486
592
  const type = input === null ? 'null' : typeof input; // Convert `null` for convenience of consumers in reporting errors
487
593
  return {type, invalid: true, message: 'Not a valid key; type ' + type};
488
594
  }
489
595
  }
490
596
  }
491
597
 
492
- /**
493
- * @typedef {*} module:Key.Key
494
- * @todo Specify possible value more precisely
495
- */
496
-
497
598
  /**
498
599
  *
499
- * @param {module:Key.Key} key
500
- * @param {boolean} fullKeys
501
- * @returns {module:Key.keyValueObject}
600
+ * @param {Key} key
601
+ * @param {boolean} [fullKeys]
602
+ * @returns {KeyValueObject}
502
603
  * @todo Document other allowable `key`?
503
604
  */
504
605
  function convertValueToMultiEntryKeyDecoded (key, fullKeys) {
@@ -507,10 +608,10 @@ function convertValueToMultiEntryKeyDecoded (key, fullKeys) {
507
608
 
508
609
  /**
509
610
  * An internal utility.
510
- * @param input
511
- * @param {boolean} seen
611
+ * @param {Value} input
612
+ * @param {Value[]|null|undefined} [seen]
512
613
  * @throws {DOMException} `DataError`
513
- * @returns {module:Key.keyValueObject}
614
+ * @returns {KeyValueObject}
514
615
  */
515
616
  function convertValueToKeyRethrowingAndIfInvalid (input, seen) {
516
617
  const key = convertValueToKey(input, seen);
@@ -522,10 +623,10 @@ function convertValueToKeyRethrowingAndIfInvalid (input, seen) {
522
623
 
523
624
  /**
524
625
  *
525
- * @param value
526
- * @param keyPath
626
+ * @param {Value} value
627
+ * @param {KeyPath} keyPath
527
628
  * @param {boolean} multiEntry
528
- * @returns {module:Key.keyValueObject|module:Key.KeyPathEvaluateValue}
629
+ * @returns {KeyValueObject|KeyPathEvaluateValue}
529
630
  * @todo Document other possible return?
530
631
  */
531
632
  function extractKeyFromValueUsingKeyPath (value, keyPath, multiEntry) {
@@ -533,10 +634,10 @@ function extractKeyFromValueUsingKeyPath (value, keyPath, multiEntry) {
533
634
  }
534
635
  /**
535
636
  * Not currently in use.
536
- * @param value
537
- * @param keyPath
637
+ * @param {Value} value
638
+ * @param {KeyPath} keyPath
538
639
  * @param {boolean} multiEntry
539
- * @returns {module:Key.KeyPathEvaluateValue}
640
+ * @returns {KeyPathEvaluateValue}
540
641
  */
541
642
  function evaluateKeyPathOnValue (value, keyPath, multiEntry) {
542
643
  return evaluateKeyPathOnValueToDecodedValue(value, keyPath, multiEntry, true);
@@ -545,11 +646,11 @@ function evaluateKeyPathOnValue (value, keyPath, multiEntry) {
545
646
  /**
546
647
  * May throw, return `{failure: true}` (e.g., non-object on keyPath resolution)
547
648
  * or `{invalid: true}` (e.g., `NaN`).
548
- * @param value
549
- * @param keyPath
550
- * @param {boolean} multiEntry
551
- * @param {boolean} fullKeys
552
- * @returns {module:Key.keyValueObject|module:Key.KeyPathEvaluateValue}
649
+ * @param {Value} value
650
+ * @param {KeyPath} keyPath
651
+ * @param {boolean} [multiEntry]
652
+ * @param {boolean} [fullKeys]
653
+ * @returns {KeyValueObject|KeyPathEvaluateValue}
553
654
  * @todo Document other possible return?
554
655
  */
555
656
  function extractKeyValueDecodedFromValueUsingKeyPath (value, keyPath, multiEntry, fullKeys) {
@@ -564,26 +665,37 @@ function extractKeyValueDecodedFromValueUsingKeyPath (value, keyPath, multiEntry
564
665
  }
565
666
 
566
667
  /**
567
- * @typedef {PlainObject} module:Key.KeyPathEvaluateFailure
568
- * @property {boolean} failure
569
- */
668
+ * Unused?
669
+ * @typedef {object} KeyPathEvaluateFailure
670
+ * @property {boolean} failure
671
+ */
570
672
 
571
673
  /**
572
- * @typedef {PlainObject} module:Key.KeyPathEvaluateValue
573
- * @property {undefined|array|string} value
574
- */
674
+ * @typedef {KeyPathEvaluateValueValue[]} KeyPathEvaluateValueValueArray
675
+ */
676
+
677
+ /**
678
+ * @typedef {undefined|number|string|Date|object|KeyPathEvaluateValueValueArray} KeyPathEvaluateValueValue
679
+ */
680
+
681
+ /**
682
+ * @typedef {object} KeyPathEvaluateValue
683
+ * @property {KeyPathEvaluateValueValue} [value]
684
+ * @property {boolean} [failure]
685
+ */
575
686
 
576
687
  /**
577
688
  * Returns the value of an inline key based on a key path (wrapped in an
578
689
  * object with key `value`) or `{failure: true}`
579
- * @param {object} value
580
- * @param {string|array} keyPath
581
- * @param {boolean} multiEntry
690
+ * @param {Value} value
691
+ * @param {KeyPath} keyPath
692
+ * @param {boolean} [multiEntry]
582
693
  * @param {boolean} [fullKeys]
583
- * @returns {module:Key.KeyPathEvaluateValue}
694
+ * @returns {KeyPathEvaluateValue}
584
695
  */
585
696
  function evaluateKeyPathOnValueToDecodedValue (value, keyPath, multiEntry, fullKeys) {
586
697
  if (Array.isArray(keyPath)) {
698
+ /** @type {KeyPathEvaluateValueValueArray} */
587
699
  const result = [];
588
700
  return keyPath.some((item) => {
589
701
  const key = evaluateKeyPathOnValueToDecodedValue(value, item, multiEntry, fullKeys);
@@ -608,22 +720,24 @@ function evaluateKeyPathOnValueToDecodedValue (value, keyPath, multiEntry, fullK
608
720
  } else if (util.isBlob(value)) {
609
721
  switch (idntfr) {
610
722
  case 'size': case 'type':
611
- value = value[idntfr];
723
+ value = /** @type {Blob} */ (value)[idntfr];
612
724
  break;
613
725
  }
614
726
  } else if (util.isFile(value)) {
615
727
  switch (idntfr) {
616
728
  case 'name': case 'lastModified':
617
- value = value[idntfr];
729
+ value = /** @type {File} */ (value)[idntfr];
618
730
  break;
619
731
  case 'lastModifiedDate':
620
- value = new Date(value.lastModified);
732
+ value = new Date(/** @type {File} */ (value).lastModified);
621
733
  break;
622
734
  }
623
- } else if (!util.isObj(value) || !Object.prototype.hasOwnProperty.call(value, idntfr)) {
735
+ } else if (!util.isObj(value) || !Object.hasOwn(value, idntfr)) {
624
736
  return true;
625
737
  } else {
626
- value = value[idntfr];
738
+ value = /** @type {{[key: string]: KeyPathEvaluateValueValue}} */ (
739
+ value
740
+ )[idntfr];
627
741
  return value === undefined;
628
742
  }
629
743
  return false;
@@ -634,8 +748,8 @@ function evaluateKeyPathOnValueToDecodedValue (value, keyPath, multiEntry, fullK
634
748
 
635
749
  /**
636
750
  * Sets the inline key value.
637
- * @param {object} value
638
- * @param {*} key
751
+ * @param {{[key: string]: AnyValue}} value
752
+ * @param {Key} key
639
753
  * @param {string} keyPath
640
754
  * @returns {void}
641
755
  */
@@ -643,19 +757,19 @@ function injectKeyIntoValueUsingKeyPath (value, key, keyPath) {
643
757
  const identifiers = keyPath.split('.');
644
758
  const last = identifiers.pop();
645
759
  identifiers.forEach((identifier) => {
646
- const hop = Object.prototype.hasOwnProperty.call(value, identifier);
760
+ const hop = Object.hasOwn(value, identifier);
647
761
  if (!hop) {
648
762
  value[identifier] = {};
649
763
  }
650
764
  value = value[identifier];
651
765
  });
652
- value[last] = key; // key is already a `keyValue` in our processing so no need to convert
766
+ value[/** @type {string} */ (last)] = key; // key is already a `keyValue` in our processing so no need to convert
653
767
  }
654
768
 
655
769
  /**
656
770
  *
657
- * @param value
658
- * @param keyPath
771
+ * @param {Value} value
772
+ * @param {string} keyPath
659
773
  * @see https://github.com/w3c/IndexedDB/pull/146
660
774
  * @returns {boolean}
661
775
  */
@@ -666,20 +780,20 @@ function checkKeyCouldBeInjectedIntoValue (value, keyPath) {
666
780
  if (!util.isObj(value)) {
667
781
  return false;
668
782
  }
669
- const hop = Object.prototype.hasOwnProperty.call(value, identifier);
783
+ const hop = Object.hasOwn(value, identifier);
670
784
  if (!hop) {
671
785
  return true;
672
786
  }
673
- value = value[identifier];
787
+ value = /** @type {{[key: string]: Value}} */ (value)[identifier];
674
788
  }
675
789
  return util.isObj(value);
676
790
  }
677
791
 
678
792
  /**
679
793
  *
680
- * @param {module:Key.Key} key
681
- * @param {IDBKeyRange} range
682
- * @param {boolean} checkCached
794
+ * @param {Key} key
795
+ * @param {import('./IDBKeyRange.js').IDBKeyRangeFull} range
796
+ * @param {boolean} [checkCached]
683
797
  * @returns {boolean}
684
798
  */
685
799
  function isKeyInRange (key, range, checkCached) {
@@ -689,21 +803,25 @@ function isKeyInRange (key, range, checkCached) {
689
803
  const lower = checkCached ? range.__lowerCached : encode(range.lower, true);
690
804
  const upper = checkCached ? range.__upperCached : encode(range.upper, true);
691
805
 
692
- if (range.lower !== undefined) {
693
- if (range.lowerOpen && encodedKey > lower) {
694
- lowerMatch = true;
695
- }
696
- if (!range.lowerOpen && encodedKey >= lower) {
697
- lowerMatch = true;
698
- }
806
+ if (!lowerMatch && (
807
+ (range.lowerOpen &&
808
+ encodedKey !== null && lower !== null && encodedKey > lower) ||
809
+ (!range.lowerOpen && (
810
+ (!encodedKey && !lower) ||
811
+ (encodedKey !== null && lower !== null && encodedKey >= lower))
812
+ )
813
+ )) {
814
+ lowerMatch = true;
699
815
  }
700
- if (range.upper !== undefined) {
701
- if (range.upperOpen && encodedKey < upper) {
702
- upperMatch = true;
703
- }
704
- if (!range.upperOpen && encodedKey <= upper) {
705
- upperMatch = true;
706
- }
816
+ if (!upperMatch && (
817
+ (range.upperOpen &&
818
+ encodedKey !== null && upper !== null && encodedKey < upper) ||
819
+ (!range.upperOpen && (
820
+ (!encodedKey && !upper) ||
821
+ (encodedKey !== null && upper !== null && encodedKey <= upper))
822
+ )
823
+ )) {
824
+ upperMatch = true;
707
825
  }
708
826
 
709
827
  return lowerMatch && upperMatch;
@@ -726,9 +844,9 @@ function isMultiEntryMatch (encodedEntry, encodedKey) {
726
844
 
727
845
  /**
728
846
  *
729
- * @param {module:Key.Key} keyEntry
730
- * @param {IDBKeyRange} range
731
- * @returns {module:Key.Key[]}
847
+ * @param {Key} keyEntry
848
+ * @param {import('./IDBKeyRange.js').IDBKeyRangeFull|undefined} range
849
+ * @returns {Key[]}
732
850
  */
733
851
  function findMultiEntryMatches (keyEntry, range) {
734
852
  const matches = [];
@@ -760,15 +878,11 @@ function findMultiEntryMatches (keyEntry, range) {
760
878
  return matches;
761
879
  }
762
880
 
763
- /**
764
- * @typedef {number|string|Date|ArrayBuffer|module:Key.ValueTypes[]} module:Key.ValueTypes
765
- */
766
-
767
881
  /**
768
882
  * Not currently in use but keeping for spec parity.
769
- * @param {module:Key.Key} key
883
+ * @param {Key} key
770
884
  * @throws {Error} Upon a "bad key"
771
- * @returns {module:Key.ValueTypes}
885
+ * @returns {ValueType}
772
886
  */
773
887
  function convertKeyToValue (key) {
774
888
  const {type, value} = key;
@@ -801,8 +915,8 @@ function convertKeyToValue (key) {
801
915
 
802
916
  /**
803
917
  *
804
- * @param {module:Key.Key} key
805
- * @param {boolean} inArray
918
+ * @param {Key} key
919
+ * @param {boolean} [inArray]
806
920
  * @returns {string|null}
807
921
  */
808
922
  function encode (key, inArray) {
@@ -816,10 +930,10 @@ function encode (key, inArray) {
816
930
 
817
931
  /**
818
932
  *
819
- * @param {module:Key.Key} key
820
- * @param {boolean} inArray
933
+ * @param {Key} key
934
+ * @param {boolean} [inArray]
821
935
  * @throws {Error} Invalid number
822
- * @returns {undefined|module:Key.ValueTypes}
936
+ * @returns {undefined|ValueType}
823
937
  */
824
938
  function decode (key, inArray) {
825
939
  if (typeof key !== 'string') {
@@ -830,9 +944,9 @@ function decode (key, inArray) {
830
944
 
831
945
  /**
832
946
  *
833
- * @param {module:Key.Key} key
834
- * @param {boolean} inArray
835
- * @returns {undefined|module:Key.ValueTypes}
947
+ * @param {Key} key
948
+ * @param {boolean} [inArray]
949
+ * @returns {undefined|ValueType}
836
950
  */
837
951
  function roundTrip (key, inArray) {
838
952
  return decode(encode(key, inArray), inArray);
@@ -841,30 +955,25 @@ function roundTrip (key, inArray) {
841
955
  const MAX_ALLOWED_CURRENT_NUMBER = 9007199254740992; // 2 ^ 53 (Also equal to `Number.MAX_SAFE_INTEGER + 1`)
842
956
 
843
957
  /**
844
- * @external WebSQLTransaction
958
+ * @typedef {number} Integer
845
959
  */
846
960
 
847
- /**
848
- * @typedef {IDBObjectStore} IDBObjectStoreWithCurrentName
849
- * @property {string} __currentName
850
- */
851
-
852
961
  /**
853
962
  * @callback CurrentNumberCallback
854
- * @param {Integer} The current number
963
+ * @param {Integer} cn The current number
855
964
  * @returns {void}
856
965
  */
857
966
 
858
967
  /**
859
968
  * @callback SQLFailureCallback
860
- * @param {DOMException} exception
969
+ * @param {DOMException|Error} exception
861
970
  * @returns {void}
862
971
  */
863
972
 
864
973
  /**
865
974
  *
866
- * @param {external:WebSQLTransaction} tx
867
- * @param {IDBObjectStoreWithCurrentName} store
975
+ * @param {SQLTransaction} tx
976
+ * @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
868
977
  * @param {CurrentNumberCallback} func
869
978
  * @param {SQLFailureCallback} sqlFailCb
870
979
  * @returns {void}
@@ -884,13 +993,14 @@ function getCurrentNumber (tx, store, func, sqlFailCb) {
884
993
  'Could not get the auto increment value for key',
885
994
  error
886
995
  ));
996
+ return true;
887
997
  });
888
998
  }
889
999
 
890
1000
  /**
891
1001
  *
892
- * @param {external:WebSQLTransaction} tx
893
- * @param {IDBObjectStoreWithCurrentName} store
1002
+ * @param {SQLTransaction} tx
1003
+ * @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
894
1004
  * @param {Integer} num
895
1005
  * @param {CurrentNumberCallback} successCb
896
1006
  * @param {SQLFailureCallback} failCb
@@ -904,6 +1014,7 @@ function assignCurrentNumber (tx, store, num, successCb, failCb) {
904
1014
  successCb(num);
905
1015
  }, function (tx, err) {
906
1016
  failCb(createDOMException('UnknownError', 'Could not set the auto increment value for key', err));
1017
+ return true;
907
1018
  });
908
1019
  }
909
1020
 
@@ -911,8 +1022,8 @@ function assignCurrentNumber (tx, store, num, successCb, failCb) {
911
1022
  * Bump up the auto-inc counter if the key path-resolved value is valid
912
1023
  * (greater than old value and >=1) OR if a manually passed in key is
913
1024
  * valid (numeric and >= 1) and >= any primaryKey.
914
- * @param {external:WebSQLTransaction} tx
915
- * @param {IDBObjectStoreWithCurrentName} store
1025
+ * @param {SQLTransaction} tx
1026
+ * @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
916
1027
  * @param {Integer} num
917
1028
  * @param {CurrentNumberCallback} successCb
918
1029
  * @param {SQLFailureCallback} failCb
@@ -935,8 +1046,8 @@ function setCurrentNumber (tx, store, num, successCb, failCb) {
935
1046
 
936
1047
  /**
937
1048
  *
938
- * @param {external:WebSQLTransaction} tx
939
- * @param {IDBObjectStoreWithCurrentName} store
1049
+ * @param {SQLTransaction} tx
1050
+ * @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
940
1051
  * @param {KeyForStoreCallback} cb
941
1052
  * @param {SQLFailureCallback} sqlFailCb
942
1053
  * @returns {void}
@@ -965,10 +1076,10 @@ function generateKeyForStore (tx, store, cb, sqlFailCb) {
965
1076
  // so we do not return a key
966
1077
  /**
967
1078
  *
968
- * @param {external:WebSQLTransaction} tx
969
- * @param {IDBObjectStoreWithCurrentName} store
970
- * @param {*|Integer} key
971
- * @param {CurrentNumberCallback|void} successCb
1079
+ * @param {SQLTransaction} tx
1080
+ * @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
1081
+ * @param {import('./Key.js').Key} key
1082
+ * @param {(num?: Integer) => void} successCb
972
1083
  * @param {SQLFailureCallback} sqlFailCb
973
1084
  * @returns {void}
974
1085
  */