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